From 18defaca0b10d132908aa214b85a7c57ca748ba2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Tue, 14 Jan 2014 10:48:13 +0100 Subject: [PATCH] Unix newlines. --- Examples/Generic/BatchLoad.cpp | 428 +- Examples/Generic/CloneMultiPage.cpp | 224 +- Examples/Generic/CreateAlpha.cpp | 362 +- Examples/Generic/FIFImportExport.cpp | 298 +- Examples/Generic/FIIO_Mem.cpp | 292 +- Examples/Generic/LoadFromHandle.cpp | 290 +- Examples/Generic/LoadFromMemory-classified.cpp | 200 +- Examples/Generic/LoadFromMemory.cpp | 224 +- Examples/Generic/ShowMetadata.cpp | 634 +- Examples/Linux/Makefile | 48 +- Examples/Linux/linux-gtk.c | 200 +- Examples/Linux/linux-svgalib.c | 192 +- Examples/OpenGL/TextureManager/TextureManager.cpp | 288 +- Examples/OpenGL/TextureManager/readme.txt | 60 +- Examples/Plugin/PluginCradle.cpp | 506 +- Makefile | 68 +- Makefile.cygwin | 146 +- Makefile.fip | 146 +- Makefile.gnu | 148 +- Makefile.iphone | 186 +- Makefile.mingw | 272 +- Makefile.osx | 228 +- Makefile.solaris | 130 +- README.iphone | 22 +- README.linux | 100 +- README.minGW | 472 +- README.osx | 88 +- README.solaris | 134 +- Source/FreeImage.h | 2208 +- Source/FreeImage/BitmapAccess.cpp | 2536 +- Source/FreeImage/Conversion24.cpp | 504 +- Source/FreeImage/Conversion32.cpp | 690 +- Source/FreeImage/Conversion8.cpp | 610 +- Source/FreeImage/ConversionFloat.cpp | 384 +- Source/FreeImage/ConversionRGB16.cpp | 288 +- Source/FreeImage/ConversionRGBF.cpp | 482 +- Source/FreeImage/ConversionUINT16.cpp | 268 +- Source/FreeImage/J2KHelper.cpp | 1000 +- Source/FreeImage/MultiPage.cpp | 1948 +- Source/FreeImage/PixelAccess.cpp | 420 +- Source/FreeImage/PluginJ2K.cpp | 678 +- Source/FreeImage/PluginJP2.cpp | 678 +- Source/FreeImage/tmoColorConvert.cpp | 958 +- Source/FreeImage/tmoDrago03.cpp | 590 +- Source/FreeImage/tmoFattal02.cpp | 1378 +- Source/FreeImageToolkit/Rescale.cpp | 338 +- Source/FreeImageToolkit/Resize.cpp | 3984 +- Source/FreeImageToolkit/Resize.h | 390 +- Source/LibJPEG/README | 702 +- Source/LibJPEG/ansi2knr.c | 1478 +- Source/LibJPEG/cdjpeg.c | 362 +- Source/LibJPEG/change.log | 692 +- Source/LibJPEG/cjpeg.c | 1286 +- Source/LibJPEG/ckconfig.c | 804 +- Source/LibJPEG/coderules.txt | 236 +- Source/LibJPEG/djpeg.c | 1234 +- Source/LibJPEG/example.c | 866 +- Source/LibJPEG/filelist.txt | 430 +- Source/LibJPEG/install.txt | 2192 +- Source/LibJPEG/jconfig.txt | 328 +- Source/LibJPEG/jmemansi.c | 334 +- Source/LibJPEG/jmemdos.c | 1276 +- Source/LibJPEG/jmemdosa.asm | 758 +- Source/LibJPEG/jmemmac.c | 578 +- Source/LibJPEG/jmemname.c | 552 +- Source/LibJPEG/jpegtran.c | 1120 +- Source/LibJPEG/libjpeg.txt | 6170 +- Source/LibJPEG/rdbmp.c | 960 +- Source/LibJPEG/rdcolmap.c | 506 +- Source/LibJPEG/rdgif.c | 76 +- Source/LibJPEG/rdjpgcom.c | 1030 +- Source/LibJPEG/rdppm.c | 918 +- Source/LibJPEG/rdrle.c | 774 +- Source/LibJPEG/rdswitch.c | 730 +- Source/LibJPEG/rdtarga.c | 1000 +- Source/LibJPEG/structure.txt | 1882 +- Source/LibJPEG/usage.txt | 1274 +- Source/LibJPEG/wizard.txt | 422 +- Source/LibJPEG/wrbmp.c | 884 +- Source/LibJPEG/wrgif.c | 798 +- Source/LibJPEG/wrjpgcom.c | 1166 +- Source/LibJPEG/wrppm.c | 538 +- Source/LibJPEG/wrrle.c | 610 +- Source/LibJPEG/wrtarga.c | 506 +- Source/LibMNG/Changes | 2894 +- Source/LibMNG/LICENSE | 114 +- Source/LibMNG/README | 72 +- Source/LibMNG/README.autoconf | 426 +- Source/LibMNG/README.config | 208 +- Source/LibMNG/README.contrib | 190 +- Source/LibMNG/README.examples | 96 +- Source/LibMNG/README.footprint | 92 +- Source/LibMNG/README.packaging | 48 +- Source/LibMNG/_FI_3151_PluginMNG.cpp | 624 +- Source/LibMNG/libmng_callback_xs.c | 2478 +- Source/LibMNG/libmng_chunk_descr.c | 12180 ++-- Source/LibMNG/libmng_chunk_io.c | 21480 +++---- Source/LibMNG/libmng_chunk_prc.c | 8904 +-- Source/LibMNG/libmng_chunk_xs.c | 14032 ++--- Source/LibMNG/libmng_cms.c | 1516 +- Source/LibMNG/libmng_display.c | 14270 ++--- Source/LibMNG/libmng_dither.c | 116 +- Source/LibMNG/libmng_error.c | 652 +- Source/LibMNG/libmng_filter.c | 1956 +- Source/LibMNG/libmng_hlapi.c | 5990 +- Source/LibMNG/libmng_jpeg.c | 2176 +- Source/LibMNG/libmng_object_prc.c | 13996 ++--- Source/LibMNG/libmng_pixels.c | 49220 +++++++-------- Source/LibMNG/libmng_prop_xs.c | 5598 +- Source/LibMNG/libmng_read.c | 2738 +- Source/LibMNG/libmng_trace.c | 3366 +- Source/LibMNG/libmng_write.c | 396 +- Source/LibMNG/libmng_zlib.c | 1214 +- Source/LibOpenJPEG/LICENSE | 62 +- Source/LibOpenJPEG/bio.c | 374 +- Source/LibOpenJPEG/bio.h | 250 +- Source/LibOpenJPEG/cidx_manager.c | 422 +- Source/LibOpenJPEG/cidx_manager.h | 112 +- Source/LibOpenJPEG/cio.c | 382 +- Source/LibOpenJPEG/cio.h | 186 +- Source/LibOpenJPEG/dwt.c | 1716 +- Source/LibOpenJPEG/dwt.h | 226 +- Source/LibOpenJPEG/event.c | 244 +- Source/LibOpenJPEG/event.h | 116 +- Source/LibOpenJPEG/fix.h | 128 +- Source/LibOpenJPEG/image.c | 178 +- Source/LibOpenJPEG/image.h | 96 +- Source/LibOpenJPEG/indexbox_manager.h | 236 +- Source/LibOpenJPEG/int.h | 238 +- Source/LibOpenJPEG/j2k.c | 5232 +- Source/LibOpenJPEG/j2k.h | 892 +- Source/LibOpenJPEG/j2k_lib.c | 118 +- Source/LibOpenJPEG/j2k_lib.h | 108 +- Source/LibOpenJPEG/jp2.c | 2446 +- Source/LibOpenJPEG/jp2.h | 468 +- Source/LibOpenJPEG/jpt.c | 310 +- Source/LibOpenJPEG/jpt.h | 150 +- Source/LibOpenJPEG/mct.c | 380 +- Source/LibOpenJPEG/mct.h | 196 +- Source/LibOpenJPEG/mqc.c | 1184 +- Source/LibOpenJPEG/mqc.h | 400 +- Source/LibOpenJPEG/openjpeg.c | 686 +- Source/LibOpenJPEG/openjpeg.h | 1828 +- Source/LibOpenJPEG/opj_includes.h | 280 +- Source/LibOpenJPEG/opj_malloc.h | 330 +- Source/LibOpenJPEG/phix_manager.c | 340 +- Source/LibOpenJPEG/pi.c | 1926 +- Source/LibOpenJPEG/pi.h | 312 +- Source/LibOpenJPEG/ppix_manager.c | 346 +- Source/LibOpenJPEG/raw.c | 174 +- Source/LibOpenJPEG/raw.h | 200 +- Source/LibOpenJPEG/t1.c | 3170 +- Source/LibOpenJPEG/t1.h | 294 +- Source/LibOpenJPEG/t2.c | 1644 +- Source/LibOpenJPEG/t2.h | 210 +- Source/LibOpenJPEG/tcd.c | 3148 +- Source/LibOpenJPEG/tcd.h | 572 +- Source/LibOpenJPEG/tgt.c | 426 +- Source/LibOpenJPEG/tgt.h | 228 +- Source/LibOpenJPEG/thix_manager.c | 240 +- Source/LibOpenJPEG/tpix_manager.c | 306 +- Source/LibPNG/ANNOUNCE | 94 +- Source/LibPNG/CHANGES | 7858 +-- Source/LibPNG/INSTALL | 270 +- Source/LibPNG/LICENSE | 222 +- Source/LibPNG/README | 404 +- Source/LibPNG/TODO | 54 +- Source/LibPNG/configure | 38 +- Source/LibPNG/example.c | 1758 +- Source/LibPNG/libpng-manual.txt | 9334 +-- Source/LibPNG/libpng.3 | 11992 ++-- Source/LibPNG/libpngpf.3 | 56 +- Source/LibPNG/png.5 | 148 +- Source/LibPNG/png.c | 5748 +- Source/LibPNG/png.h | 5348 +- Source/LibPNG/pngconf.h | 1196 +- Source/LibPNG/pngdebug.h | 314 +- Source/LibPNG/pngerror.c | 1370 +- Source/LibPNG/pngget.c | 2248 +- Source/LibPNG/pnginfo.h | 538 +- Source/LibPNG/pngmem.c | 1334 +- Source/LibPNG/pngpread.c | 2630 +- Source/LibPNG/pngpriv.h | 3350 +- Source/LibPNG/pngread.c | 2610 +- Source/LibPNG/pngrio.c | 352 +- Source/LibPNG/pngrtran.c | 10108 +-- Source/LibPNG/pngrutil.c | 8318 +-- Source/LibPNG/pngset.c | 2622 +- Source/LibPNG/pngstruct.h | 716 +- Source/LibPNG/pngtest.c | 3640 +- Source/LibPNG/pngtrans.c | 1562 +- Source/LibPNG/pngwio.c | 508 +- Source/LibPNG/pngwrite.c | 3336 +- Source/LibPNG/pngwtran.c | 1290 +- Source/LibPNG/pngwutil.c | 6360 +- Source/LibRawLite/COPYRIGHT | 46 +- Source/LibRawLite/Changelog.txt | 2590 +- Source/LibRawLite/LICENSE.CDDL | 680 +- Source/LibRawLite/LICENSE.LGPL | 916 +- Source/LibRawLite/README | 56 +- Source/LibRawLite/README.demosaic-packs | 92 +- Source/LibRawLite/dcraw/dcraw.c | 18928 +++--- Source/LibRawLite/internal/dcb_demosaicing.c | 1420 +- Source/LibRawLite/internal/dcraw_common.cpp | 18890 +++--- Source/LibRawLite/internal/dcraw_fileio.cpp | 480 +- Source/LibRawLite/internal/defines.h | 306 +- Source/LibRawLite/internal/demosaic_packs.cpp | 194 +- Source/LibRawLite/internal/libraw_bytebuffer.h | 280 +- Source/LibRawLite/internal/libraw_internal_funcs.h | 482 +- Source/LibRawLite/internal/var_defines.h | 412 +- Source/LibRawLite/libraw/libraw.h | 538 +- Source/LibRawLite/libraw/libraw_alloc.h | 198 +- Source/LibRawLite/libraw/libraw_const.h | 324 +- Source/LibRawLite/libraw/libraw_datastream.h | 410 +- Source/LibRawLite/libraw/libraw_internal.h | 436 +- Source/LibRawLite/libraw/libraw_types.h | 704 +- Source/LibRawLite/libraw/libraw_version.h | 124 +- Source/LibRawLite/src/libraw_c_api.cpp | 402 +- Source/LibRawLite/src/libraw_cxx.cpp | 5628 +- Source/LibRawLite/src/libraw_datastream.cpp | 1052 +- Source/LibTIFF/ChangeLog | 9698 +-- Source/LibTIFF/Makefile.am | 286 +- Source/LibTIFF/Makefile.in | 1768 +- Source/LibTIFF/SConstruct | 146 +- Source/LibTIFF/_FI_3151_PluginG3.cpp | 866 +- Source/LibTIFF/_FI_3151_PluginTIFF.cpp | 5256 +- Source/LibTIFF/_FI_3151_XTIFF.cpp | 1328 +- Source/LibTIFF/makefile.vc | 204 +- Source/LibTIFF/mkg3states.c | 902 +- Source/LibTIFF/mkspans.c | 164 +- Source/LibTIFF/tif_acorn.c | 1052 +- Source/LibTIFF/tif_apple.c | 562 +- Source/LibTIFF/tif_atari.c | 500 +- Source/LibTIFF/tif_config.h-vms | 92 +- Source/LibTIFF/tif_config.h.in | 618 +- Source/LibTIFF/tif_jbig.c | 770 +- Source/LibTIFF/tif_msdos.c | 386 +- Source/LibTIFF/tif_stream.cxx | 590 +- Source/LibTIFF/tif_unix.c | 600 +- Source/LibTIFF/tif_vms.c | 1190 +- Source/LibTIFF/tif_win3.c | 464 +- Source/LibTIFF/tif_win32.c | 816 +- Source/LibTIFF/tif_wince.c | 576 +- Source/LibTIFF/tiffconf.h-vms | 198 +- Source/LibTIFF/tiffconf.h.in | 206 +- Source/LibTIFF/tiffio.hxx | 98 +- Source/LibTIFF/tiffvers.h.in | 18 +- Source/LibTIFF4/ChangeLog | 11670 ++-- Source/LibTIFF4/mkg3states.c | 902 +- Source/LibTIFF4/mkspans.c | 164 +- Source/LibTIFF4/t4.h | 584 +- Source/LibTIFF4/tif_aux.c | 716 +- Source/LibTIFF4/tif_close.c | 280 +- Source/LibTIFF4/tif_codec.c | 330 +- Source/LibTIFF4/tif_color.c | 574 +- Source/LibTIFF4/tif_compress.c | 608 +- Source/LibTIFF4/tif_config.h | 194 +- Source/LibTIFF4/tif_config.h-vms | 92 +- Source/LibTIFF4/tif_config.h.in | 790 +- Source/LibTIFF4/tif_config.vc.h | 142 +- Source/LibTIFF4/tif_config.wince.h | 142 +- Source/LibTIFF4/tif_dir.c | 3318 +- Source/LibTIFF4/tif_dir.h | 616 +- Source/LibTIFF4/tif_dirinfo.c | 1914 +- Source/LibTIFF4/tif_dirread.c | 11226 ++-- Source/LibTIFF4/tif_dirwrite.c | 5820 +- Source/LibTIFF4/tif_dumpmode.c | 286 +- Source/LibTIFF4/tif_error.c | 160 +- Source/LibTIFF4/tif_extension.c | 236 +- Source/LibTIFF4/tif_fax3.c | 3190 +- Source/LibTIFF4/tif_fax3.h | 1076 +- Source/LibTIFF4/tif_fax3sm.c | 2520 +- Source/LibTIFF4/tif_flush.c | 236 +- Source/LibTIFF4/tif_getimage.c | 5734 +- Source/LibTIFF4/tif_jbig.c | 426 +- Source/LibTIFF4/tif_jpeg.c | 4608 +- Source/LibTIFF4/tif_jpeg_12.c | 130 +- Source/LibTIFF4/tif_luv.c | 3366 +- Source/LibTIFF4/tif_lzma.c | 990 +- Source/LibTIFF4/tif_lzw.c | 2334 +- Source/LibTIFF4/tif_next.c | 320 +- Source/LibTIFF4/tif_ojpeg.c | 4992 +- Source/LibTIFF4/tif_open.c | 1450 +- Source/LibTIFF4/tif_packbits.c | 600 +- Source/LibTIFF4/tif_pixarlog.c | 2852 +- Source/LibTIFF4/tif_predict.c | 1528 +- Source/LibTIFF4/tif_predict.h | 154 +- Source/LibTIFF4/tif_print.c | 1432 +- Source/LibTIFF4/tif_read.c | 2166 +- Source/LibTIFF4/tif_stream.cxx | 850 +- Source/LibTIFF4/tif_strip.c | 766 +- Source/LibTIFF4/tif_swab.c | 620 +- Source/LibTIFF4/tif_thunder.c | 414 +- Source/LibTIFF4/tif_tile.c | 598 +- Source/LibTIFF4/tif_unix.c | 644 +- Source/LibTIFF4/tif_version.c | 80 +- Source/LibTIFF4/tif_vms.c | 1200 +- Source/LibTIFF4/tif_warning.c | 162 +- Source/LibTIFF4/tif_win32.c | 880 +- Source/LibTIFF4/tif_wince.c | 586 +- Source/LibTIFF4/tif_write.c | 1542 +- Source/LibTIFF4/tif_zip.c | 938 +- Source/LibTIFF4/tiff.h | 1356 +- Source/LibTIFF4/tiffconf.h | 348 +- Source/LibTIFF4/tiffconf.h-vms | 198 +- Source/LibTIFF4/tiffconf.h.in | 254 +- Source/LibTIFF4/tiffconf.vc.h | 320 +- Source/LibTIFF4/tiffconf.wince.h | 242 +- Source/LibTIFF4/tiffio.h | 1114 +- Source/LibTIFF4/tiffio.hxx | 98 +- Source/LibTIFF4/tiffiop.h | 734 +- Source/LibTIFF4/tiffvers.h | 18 +- Source/LibTIFF4/tiffvers.h.in | 18 +- Source/LibTIFF4/uvcode.h | 360 +- Source/Metadata/FreeImageTag.cpp | 6 +- Source/Metadata/FreeImageTag.h | 18 +- Source/Metadata/TagConversion.cpp | 2188 +- Source/Metadata/XTIFF.cpp | 1330 +- Source/OpenEXR/Copyrights/ilmbase/README.win32 | 392 +- Source/OpenEXR/Copyrights/openexr/README.win32 | 394 +- Source/Utilities.h | 6 +- Source/ZLib/ChangeLog | 2818 +- Source/ZLib/adler32.c | 358 +- Source/ZLib/compress.c | 160 +- Source/ZLib/crc32.c | 850 +- Source/ZLib/deflate.c | 3930 +- Source/ZLib/deflate.h | 692 +- Source/ZLib/trees.c | 2448 +- Source/ZLib/uncompr.c | 118 +- Source/ZLib/zconf.h | 1012 +- Source/ZLib/zconf.h.in | 1012 +- Source/ZLib/zutil.c | 648 +- Source/ZLib/zutil.h | 504 +- TestAPI/MainTestSuite.cpp | 214 +- TestAPI/Makefile | 16 +- TestAPI/testChannels.cpp | 254 +- TestAPI/testHeaderOnly.cpp | 514 +- TestAPI/testImageType.cpp | 996 +- TestAPI/testJPEG.cpp | 176 +- TestAPI/testMPage.cpp | 386 +- TestAPI/testMPageMemory.cpp | 542 +- TestAPI/testMPageStream.cpp | 432 +- TestAPI/testMemIO.cpp | 294 +- TestAPI/testPlugins.cpp | 76 +- TestAPI/testThumbnail.cpp | 278 +- TestAPI/testTools.cpp | 164 +- Whatsnew.txt | 2344 +- Wrapper/Delphi/WhatsNew_Delphi.txt | 218 +- Wrapper/Delphi/demo/ImagePreview/MainFrm.pas | 1048 +- Wrapper/Delphi/demo/ImagePreview/Readme.txt | 16 +- Wrapper/Delphi/demo/MultiBitmap/MultiBitmap.stat | 20 +- Wrapper/Delphi/demo/MultiBitmap/mbMainForm.pas | 300 +- Wrapper/Delphi/demo/TargaUnit/Readme.txt | 44 +- Wrapper/Delphi/demo/TargaUnit/TargaImage.pas | 424 +- Wrapper/Delphi/demo/WinBitmap/MainForm.pas | 454 +- Wrapper/Delphi/license.txt | 4 +- Wrapper/Delphi/src/FreeBitmap.pas | 4368 +- Wrapper/Delphi/src/FreeImage.pas | 2922 +- Wrapper/Delphi/src/FreeUtils.pas | 372 +- Wrapper/Delphi/src/Version.inc | 410 +- .../FreeImage.NET/cpp/FreeImageIO/AssemblyInfo.cpp | 116 +- .../cpp/FreeImageIO/FreeImageIO.Net.cpp | 138 +- Wrapper/FreeImage.NET/cpp/FreeImageIO/ReadMe.txt | 54 +- Wrapper/FreeImage.NET/cpp/FreeImageIO/Stdafx.cpp | 10 +- Wrapper/FreeImage.NET/cs/Bin/delete.me | 2 +- Wrapper/FreeImage.NET/cs/Content.txt | 84 +- Wrapper/FreeImage.NET/cs/Doc/SHFB.txt | 18 +- Wrapper/FreeImage.NET/cs/FreeImage.NET.nunit | 16 +- .../cs/Library/Classes/FreeImageBitmap.cs | 8754 +-- .../cs/Library/Classes/FreeImageEngine.cs | 200 +- .../cs/Library/Classes/FreeImagePlugin.cs | 404 +- .../cs/Library/Classes/FreeImageStreamIO.cs | 332 +- .../cs/Library/Classes/GifInformation.cs | 260 +- .../cs/Library/Classes/ImageMetadata.cs | 570 +- .../cs/Library/Classes/LocalPlugin.cs | 930 +- .../cs/Library/Classes/MemoryArray.cs | 1654 +- .../cs/Library/Classes/MetadataModel.cs | 1880 +- .../cs/Library/Classes/MetadataModels.cs | 13446 ++-- .../cs/Library/Classes/MetadataTag.cs | 1512 +- .../FreeImage.NET/cs/Library/Classes/Palette.cs | 842 +- .../cs/Library/Classes/PluginRepository.cs | 896 +- .../FreeImage.NET/cs/Library/Classes/Scanline.cs | 98 +- .../cs/Library/Classes/StreamWrapper.cs | 622 +- Wrapper/FreeImage.NET/cs/Library/Delegates.cs | 380 +- .../cs/Library/Enumerations/DisposalMethodType.cs | 66 +- .../Enumerations/FREE_IMAGE_COLOR_CHANNEL.cs | 166 +- .../Library/Enumerations/FREE_IMAGE_COLOR_DEPTH.cs | 208 +- .../Enumerations/FREE_IMAGE_COLOR_OPTIONS.cs | 134 +- .../Library/Enumerations/FREE_IMAGE_COLOR_TYPE.cs | 134 +- .../Enumerations/FREE_IMAGE_COMPARE_FLAGS.cs | 128 +- .../cs/Library/Enumerations/FREE_IMAGE_DITHER.cs | 144 +- .../cs/Library/Enumerations/FREE_IMAGE_FILTER.cs | 134 +- .../cs/Library/Enumerations/FREE_IMAGE_FORMAT.cs | 382 +- .../Enumerations/FREE_IMAGE_JPEG_OPERATION.cs | 150 +- .../Library/Enumerations/FREE_IMAGE_LOAD_FLAGS.cs | 220 +- .../cs/Library/Enumerations/FREE_IMAGE_MDMODEL.cs | 182 +- .../cs/Library/Enumerations/FREE_IMAGE_MDTYPE.cs | 208 +- .../Enumerations/FREE_IMAGE_METADATA_COPY.cs | 110 +- .../cs/Library/Enumerations/FREE_IMAGE_QUANTIZE.cs | 104 +- .../Library/Enumerations/FREE_IMAGE_SAVE_FLAGS.cs | 380 +- .../cs/Library/Enumerations/FREE_IMAGE_TMO.cs | 110 +- .../cs/Library/Enumerations/FREE_IMAGE_TYPE.cs | 190 +- .../cs/Library/Enumerations/ICC_FLAGS.cs | 104 +- .../cs/Library/Enumerations/MD_SEARCH_FLAGS.cs | 112 +- .../cs/Library/FreeImageStaticImports.cs | 4736 +- .../FreeImage.NET/cs/Library/FreeImageWrapper.cs | 10656 ++-- .../cs/Library/Properties/AssemblyInfo.cs | 40 +- Wrapper/FreeImage.NET/cs/Library/Structs/BITMAP.cs | 206 +- .../FreeImage.NET/cs/Library/Structs/BITMAPINFO.cs | 404 +- .../cs/Library/Structs/BITMAPINFOHEADER.cs | 702 +- .../FreeImage.NET/cs/Library/Structs/FI16RGB555.cs | 552 +- .../FreeImage.NET/cs/Library/Structs/FI16RGB565.cs | 552 +- Wrapper/FreeImage.NET/cs/Library/Structs/FI1BIT.cs | 140 +- Wrapper/FreeImage.NET/cs/Library/Structs/FI4BIT.cs | 138 +- .../FreeImage.NET/cs/Library/Structs/FIBITMAP.cs | 348 +- .../FreeImage.NET/cs/Library/Structs/FICOMPLEX.cs | 290 +- .../cs/Library/Structs/FIICCPROFILE.cs | 264 +- .../FreeImage.NET/cs/Library/Structs/FIMEMORY.cs | 338 +- .../FreeImage.NET/cs/Library/Structs/FIMETADATA.cs | 354 +- .../cs/Library/Structs/FIMULTIBITMAP.cs | 338 +- .../FreeImage.NET/cs/Library/Structs/FIRGB16.cs | 532 +- .../FreeImage.NET/cs/Library/Structs/FIRGBA16.cs | 540 +- .../FreeImage.NET/cs/Library/Structs/FIRGBAF.cs | 550 +- Wrapper/FreeImage.NET/cs/Library/Structs/FIRGBF.cs | 542 +- .../FreeImage.NET/cs/Library/Structs/FIRational.cs | 2020 +- Wrapper/FreeImage.NET/cs/Library/Structs/FITAG.cs | 338 +- .../cs/Library/Structs/FIURational.cs | 2018 +- .../cs/Library/Structs/FreeImageIO.cs | 130 +- Wrapper/FreeImage.NET/cs/Library/Structs/Plugin.cs | 262 +- .../FreeImage.NET/cs/Library/Structs/RGBQUAD.cs | 682 +- .../FreeImage.NET/cs/Library/Structs/RGBTRIPLE.cs | 588 +- .../FreeImage.NET/cs/Library/Structs/fi_handle.cs | 510 +- .../Sample 01 - Loading and saving/Program.cs | 356 +- .../Properties/AssemblyInfo.cs | 32 +- .../Sample 02 - Multipaged bitmaps/Program.cs | 280 +- .../Properties/AssemblyInfo.cs | 32 +- .../cs/Samples/Sample 03 - Allocating/Program.cs | 148 +- .../Properties/AssemblyInfo.cs | 32 +- .../MainForm.Designer.cs | 408 +- .../MainForm.cs | 238 +- .../Properties/AssemblyInfo.cs | 32 +- .../Sample 05 - Working with pixels/Program.cs | 424 +- .../Properties/AssemblyInfo.cs | 32 +- .../Sample 06 - Converting/MainForm.Designer.cs | 238 +- .../cs/Samples/Sample 06 - Converting/MainForm.cs | 352 +- .../Properties/AssemblyInfo.cs | 32 +- .../cs/Samples/Sample 07 - ICC Profiles/Program.cs | 146 +- .../Properties/AssemblyInfo.cs | 32 +- .../Properties/AssemblyInfo.cs | 32 +- .../SampleForm.Designer.cs | 238 +- .../Sample 08 - Creating a plugin/SampleForm.cs | 432 +- .../SerializationPlugin.cs | 444 +- .../Properties/AssemblyInfo.cs | 32 +- .../SampleForm.Designer.cs | 228 +- .../Sample 09 - Working with streams/SampleForm.cs | 292 +- .../Sample 10 - Metadata/MainForm.Designer.cs | 172 +- .../cs/Samples/Sample 10 - Metadata/MainForm.cs | 208 +- .../Properties/AssemblyInfo.cs | 32 +- .../MainForm.Designer.cs | 764 +- .../MainForm.cs | 822 +- .../MetaDataFrame.Designer.cs | 124 +- .../MetaDataFrame.cs | 96 +- .../Properties/AssemblyInfo.cs | 32 +- .../cs/SourceFileMerger/FreeImage.cs.template | 436 +- .../FreeImage.NET/cs/SourceFileMerger/Program.cs | 242 +- .../cs/SourceFileMerger/Properties/AssemblyInfo.cs | 32 +- Wrapper/FreeImage.NET/cs/UnitTest/FreeImage.cs | 61168 +++++++++---------- Wrapper/FreeImage.NET/cs/UnitTest/ImageManager.cs | 310 +- Wrapper/FreeImage.NET/cs/UnitTest/NUnit.txt | 26 +- .../cs/UnitTest/Properties/AssemblyInfo.cs | 32 +- Wrapper/FreeImage.NET/cs/UnitTest/UnitTest.cs | 11108 ++-- Wrapper/FreeImage.NET/cs/Whats_New.NET.txt | 248 +- Wrapper/FreeImagePlus/WhatsNew_FIP.txt | 356 +- Wrapper/FreeImagePlus/doc/footer.html | 14 +- Wrapper/FreeImagePlus/src/FreeImagePlus.cpp | 92 +- Wrapper/FreeImagePlus/src/fipImage.cpp | 1908 +- Wrapper/FreeImagePlus/src/fipMemoryIO.cpp | 190 +- Wrapper/FreeImagePlus/src/fipMetadataFind.cpp | 108 +- Wrapper/FreeImagePlus/src/fipMultiPage.cpp | 280 +- Wrapper/FreeImagePlus/src/fipTag.cpp | 268 +- Wrapper/FreeImagePlus/src/fipWinImage.cpp | 976 +- Wrapper/FreeImagePlus/test/fipTest.cpp | 152 +- Wrapper/FreeImagePlus/test/fipTestMPage.cpp | 164 +- Wrapper/FreeImagePlus/test/fipTestMPageMemory.cpp | 552 +- Wrapper/FreeImagePlus/test/fipTestMPageStream.cpp | 444 +- Wrapper/FreeImagePlus/test/fipTestMemIO.cpp | 342 +- Wrapper/VB6/mfreeimage/MFreeImage.bas | 25332 ++++---- Wrapper/VB6/mfreeimage/WhatsNew_VB.txt | 1298 +- clean.sh | 96 +- license-fi.txt | 282 +- license-gplv2.txt | 252 +- license-gplv3.txt | 456 +- 492 files changed, 378034 insertions(+), 378034 deletions(-) diff --git a/Examples/Generic/BatchLoad.cpp b/Examples/Generic/BatchLoad.cpp index d1c80b4..1612050 100644 --- a/Examples/Generic/BatchLoad.cpp +++ b/Examples/Generic/BatchLoad.cpp @@ -1,214 +1,214 @@ -// ========================================================== -// Batch loader -// -// Design and implementation by -// - Floris van den Berg -// - Hervé Drolon -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at own risk! -// ========================================================== - -// -// This example shows how to easily batch load a directory -// full of images. Because not all formats can be identified -// by their header (some images don't have a header or one -// at the end of the file) we make use of the -// FreeImage_GetFIFFromFilename function. This function -// receives a file name, for example 'myfile.bmp', and returns -// a FREE_IMAGE_TYPE enum which identifies that bitmap. -// -// Functions used in this sample : -// FreeImage_GetFileType, FreeImage_GetFIFFromFilename, FreeImage_FIFSupportsReading, -// FreeImage_Load, FreeImage_GetBPP, FreeImage_FIFSupportsWriting, FreeImage_GetFormatFromFIF -// FreeImage_FIFSupportsExportBPP, FreeImage_Save, FreeImage_Unload, -// FreeImage_SetOutputMessage, FreeImage_GetVersion, FreeImage_GetCopyrightMessage -// -// ========================================================== - -#include -#include -#include -#include -#include - -#include "FreeImage.h" - -// ---------------------------------------------------------- - -/** Generic image loader - @param lpszPathName Pointer to the full file name - @param flag Optional load flag constant - @return Returns the loaded dib if successful, returns NULL otherwise -*/ -FIBITMAP* GenericLoader(const char* lpszPathName, int flag) { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - - // check the file signature and deduce its format - // (the second argument is currently not used by FreeImage) - fif = FreeImage_GetFileType(lpszPathName, 0); - if(fif == FIF_UNKNOWN) { - // no signature ? - // try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilename(lpszPathName); - } - // check that the plugin has reading capabilities ... - if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { - // ok, let's load the file - FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, flag); - // unless a bad file format, we are done ! - return dib; - } - return NULL; -} - -/** Generic image writer - @param dib Pointer to the dib to be saved - @param lpszPathName Pointer to the full file name - @param flag Optional save flag constant - @return Returns true if successful, returns false otherwise -*/ -bool GenericWriter(FIBITMAP* dib, const char* lpszPathName, int flag) { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - BOOL bSuccess = FALSE; - - if(dib) { - // try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilename(lpszPathName); - if(fif != FIF_UNKNOWN ) { - // check that the plugin has sufficient writing and export capabilities ... - WORD bpp = FreeImage_GetBPP(dib); - if(FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)) { - // ok, we can save the file - bSuccess = FreeImage_Save(fif, dib, lpszPathName, flag); - // unless an abnormal bug, we are done ! - } - } - } - return (bSuccess == TRUE) ? true : false; -} - -// ---------------------------------------------------------- - -/** - FreeImage error handler - @param fif Format / Plugin responsible for the error - @param message Error message -*/ -void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) { - printf("\n*** "); - if(fif != FIF_UNKNOWN) { - printf("%s Format\n", FreeImage_GetFormatFromFIF(fif)); - } - printf(message); - printf(" ***\n"); -} - -// ---------------------------------------------------------- - -#ifndef MAX_PATH -#define MAX_PATH 260 -#endif - -int -main(int argc, char *argv[]) { - - const char *input_dir = "d:\\images\\"; - FIBITMAP *dib = NULL; - int id = 1; - - // call this ONLY when linking with FreeImage as a static library -#ifdef FREEIMAGE_LIB - FreeImage_Initialise(); -#endif // FREEIMAGE_LIB - - // initialize your own FreeImage error handler - - FreeImage_SetOutputMessage(FreeImageErrorHandler); - - // print version & copyright infos - - printf(FreeImage_GetVersion()); - printf("\n"); - printf(FreeImage_GetCopyrightMessage()); - printf("\n"); - - // open the log file - - FILE *log_file = fopen("log_file.txt", "w"); - - // batch convert all supported bitmaps - - _finddata_t finddata; - long handle; - char image_path[MAX_PATH]; - - // scan all files - strcpy(image_path, input_dir); - strcat(image_path, "*.*"); - - if ((handle = _findfirst(image_path, &finddata)) != -1) { - do { - // make a path to a directory - - char *directory = new char[MAX_PATH]; - strcpy(directory, input_dir); - strcat(directory, finddata.name); - - // make a unique filename - - char *unique = new char[128]; - itoa(id, unique, 10); - strcat(unique, ".png"); - - // open and load the file using the default load option - dib = GenericLoader(directory, 0); - - if (dib != NULL) { - // save the file as PNG - bool bSuccess = GenericWriter(dib, unique, PNG_DEFAULT); - - // free the dib - FreeImage_Unload(dib); - - if(bSuccess) { - fwrite(unique, strlen(unique), 1, log_file); - } else { - strcpy(unique, "FAILED"); - fwrite(unique, strlen(unique), 1, log_file); - } - fwrite(" >> ", 4, 1, log_file); - fwrite(directory, strlen(directory), 1, log_file); - fwrite("\n", 1, 1, log_file); - - id++; - } - - delete [] unique; - delete [] directory; - - } while (_findnext(handle, &finddata) == 0); - - _findclose(handle); - } - - fclose(log_file); - - // call this ONLY when linking with FreeImage as a static library -#ifdef FREEIMAGE_LIB - FreeImage_DeInitialise(); -#endif // FREEIMAGE_LIB - - return 0; -} +// ========================================================== +// Batch loader +// +// Design and implementation by +// - Floris van den Berg +// - Hervé Drolon +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at own risk! +// ========================================================== + +// +// This example shows how to easily batch load a directory +// full of images. Because not all formats can be identified +// by their header (some images don't have a header or one +// at the end of the file) we make use of the +// FreeImage_GetFIFFromFilename function. This function +// receives a file name, for example 'myfile.bmp', and returns +// a FREE_IMAGE_TYPE enum which identifies that bitmap. +// +// Functions used in this sample : +// FreeImage_GetFileType, FreeImage_GetFIFFromFilename, FreeImage_FIFSupportsReading, +// FreeImage_Load, FreeImage_GetBPP, FreeImage_FIFSupportsWriting, FreeImage_GetFormatFromFIF +// FreeImage_FIFSupportsExportBPP, FreeImage_Save, FreeImage_Unload, +// FreeImage_SetOutputMessage, FreeImage_GetVersion, FreeImage_GetCopyrightMessage +// +// ========================================================== + +#include +#include +#include +#include +#include + +#include "FreeImage.h" + +// ---------------------------------------------------------- + +/** Generic image loader + @param lpszPathName Pointer to the full file name + @param flag Optional load flag constant + @return Returns the loaded dib if successful, returns NULL otherwise +*/ +FIBITMAP* GenericLoader(const char* lpszPathName, int flag) { + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + + // check the file signature and deduce its format + // (the second argument is currently not used by FreeImage) + fif = FreeImage_GetFileType(lpszPathName, 0); + if(fif == FIF_UNKNOWN) { + // no signature ? + // try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilename(lpszPathName); + } + // check that the plugin has reading capabilities ... + if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { + // ok, let's load the file + FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, flag); + // unless a bad file format, we are done ! + return dib; + } + return NULL; +} + +/** Generic image writer + @param dib Pointer to the dib to be saved + @param lpszPathName Pointer to the full file name + @param flag Optional save flag constant + @return Returns true if successful, returns false otherwise +*/ +bool GenericWriter(FIBITMAP* dib, const char* lpszPathName, int flag) { + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + BOOL bSuccess = FALSE; + + if(dib) { + // try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilename(lpszPathName); + if(fif != FIF_UNKNOWN ) { + // check that the plugin has sufficient writing and export capabilities ... + WORD bpp = FreeImage_GetBPP(dib); + if(FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)) { + // ok, we can save the file + bSuccess = FreeImage_Save(fif, dib, lpszPathName, flag); + // unless an abnormal bug, we are done ! + } + } + } + return (bSuccess == TRUE) ? true : false; +} + +// ---------------------------------------------------------- + +/** + FreeImage error handler + @param fif Format / Plugin responsible for the error + @param message Error message +*/ +void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) { + printf("\n*** "); + if(fif != FIF_UNKNOWN) { + printf("%s Format\n", FreeImage_GetFormatFromFIF(fif)); + } + printf(message); + printf(" ***\n"); +} + +// ---------------------------------------------------------- + +#ifndef MAX_PATH +#define MAX_PATH 260 +#endif + +int +main(int argc, char *argv[]) { + + const char *input_dir = "d:\\images\\"; + FIBITMAP *dib = NULL; + int id = 1; + + // call this ONLY when linking with FreeImage as a static library +#ifdef FREEIMAGE_LIB + FreeImage_Initialise(); +#endif // FREEIMAGE_LIB + + // initialize your own FreeImage error handler + + FreeImage_SetOutputMessage(FreeImageErrorHandler); + + // print version & copyright infos + + printf(FreeImage_GetVersion()); + printf("\n"); + printf(FreeImage_GetCopyrightMessage()); + printf("\n"); + + // open the log file + + FILE *log_file = fopen("log_file.txt", "w"); + + // batch convert all supported bitmaps + + _finddata_t finddata; + long handle; + char image_path[MAX_PATH]; + + // scan all files + strcpy(image_path, input_dir); + strcat(image_path, "*.*"); + + if ((handle = _findfirst(image_path, &finddata)) != -1) { + do { + // make a path to a directory + + char *directory = new char[MAX_PATH]; + strcpy(directory, input_dir); + strcat(directory, finddata.name); + + // make a unique filename + + char *unique = new char[128]; + itoa(id, unique, 10); + strcat(unique, ".png"); + + // open and load the file using the default load option + dib = GenericLoader(directory, 0); + + if (dib != NULL) { + // save the file as PNG + bool bSuccess = GenericWriter(dib, unique, PNG_DEFAULT); + + // free the dib + FreeImage_Unload(dib); + + if(bSuccess) { + fwrite(unique, strlen(unique), 1, log_file); + } else { + strcpy(unique, "FAILED"); + fwrite(unique, strlen(unique), 1, log_file); + } + fwrite(" >> ", 4, 1, log_file); + fwrite(directory, strlen(directory), 1, log_file); + fwrite("\n", 1, 1, log_file); + + id++; + } + + delete [] unique; + delete [] directory; + + } while (_findnext(handle, &finddata) == 0); + + _findclose(handle); + } + + fclose(log_file); + + // call this ONLY when linking with FreeImage as a static library +#ifdef FREEIMAGE_LIB + FreeImage_DeInitialise(); +#endif // FREEIMAGE_LIB + + return 0; +} diff --git a/Examples/Generic/CloneMultiPage.cpp b/Examples/Generic/CloneMultiPage.cpp index bbeef58..2124998 100644 --- a/Examples/Generic/CloneMultiPage.cpp +++ b/Examples/Generic/CloneMultiPage.cpp @@ -1,112 +1,112 @@ -// ========================================================== -// Multipage functions demonstration -// -// Design and implementation by -// - Hervé Drolon -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at own risk! -// ========================================================== - -// This sample shows how to clone a multipage TIFF -// -// Functions used in this sample : -// FreeImage_OpenMultiBitmap, FreeImage_GetPageCount, FreeImage_LockPage, -// FreeImage_AppendPage, FreeImage_UnlockPage, FreeImage_CloseMultiBitmap; -// FreeImage_SetOutputMessage -// -// ========================================================== - -#include -#include -#include - -#include "FreeImage.h" - -// ---------------------------------------------------------- - -/** - FreeImage error handler -*/ -void MyMessageFunc(FREE_IMAGE_FORMAT fif, const char *message) { - cout << "\n*** " << message << " ***\n"; - cout.flush(); -} - -// ---------------------------------------------------------- - -bool CloneMultiPage(FREE_IMAGE_FORMAT fif, char *input, char *output, int output_flag) { - - BOOL bMemoryCache = TRUE; - - // Open src file (read-only, use memory cache) - FIMULTIBITMAP *src = FreeImage_OpenMultiBitmap(fif, input, FALSE, TRUE, bMemoryCache); - - if(src) { - // Open dst file (creation, use memory cache) - FIMULTIBITMAP *dst = FreeImage_OpenMultiBitmap(fif, output, TRUE, FALSE, bMemoryCache); - - // Get src page count - int count = FreeImage_GetPageCount(src); - - // Clone src to dst - for(int page = 0; page < count; page++) { - // Load the bitmap at position 'page' - FIBITMAP *dib = FreeImage_LockPage(src, page); - if(dib) { - // add a new bitmap to dst - FreeImage_AppendPage(dst, dib); - // Unload the bitmap (do not apply any change to src) - FreeImage_UnlockPage(src, dib, FALSE); - } - } - - // Close src - FreeImage_CloseMultiBitmap(src, 0); - // Save and close dst - FreeImage_CloseMultiBitmap(dst, output_flag); - - return true; - } - - return false; -} - - -int -main(int argc, char *argv[]) { - - char *input_filename = "images\\input.tif"; - char *output_filename = "images\\clone.tif"; - - // call this ONLY when linking with FreeImage as a static library -#ifdef FREEIMAGE_LIB - FreeImage_Initialise(); -#endif // FREEIMAGE_LIB - - // initialize our own FreeImage error handler - - FreeImage_SetOutputMessage(MyMessageFunc); - - // Copy 'input.tif' to 'clone.tif' - - CloneMultiPage(FIF_TIFF, input_filename, output_filename, 0); - - // call this ONLY when linking with FreeImage as a static library -#ifdef FREEIMAGE_LIB - FreeImage_DeInitialise(); -#endif // FREEIMAGE_LIB - - return 0; -} +// ========================================================== +// Multipage functions demonstration +// +// Design and implementation by +// - Hervé Drolon +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at own risk! +// ========================================================== + +// This sample shows how to clone a multipage TIFF +// +// Functions used in this sample : +// FreeImage_OpenMultiBitmap, FreeImage_GetPageCount, FreeImage_LockPage, +// FreeImage_AppendPage, FreeImage_UnlockPage, FreeImage_CloseMultiBitmap; +// FreeImage_SetOutputMessage +// +// ========================================================== + +#include +#include +#include + +#include "FreeImage.h" + +// ---------------------------------------------------------- + +/** + FreeImage error handler +*/ +void MyMessageFunc(FREE_IMAGE_FORMAT fif, const char *message) { + cout << "\n*** " << message << " ***\n"; + cout.flush(); +} + +// ---------------------------------------------------------- + +bool CloneMultiPage(FREE_IMAGE_FORMAT fif, char *input, char *output, int output_flag) { + + BOOL bMemoryCache = TRUE; + + // Open src file (read-only, use memory cache) + FIMULTIBITMAP *src = FreeImage_OpenMultiBitmap(fif, input, FALSE, TRUE, bMemoryCache); + + if(src) { + // Open dst file (creation, use memory cache) + FIMULTIBITMAP *dst = FreeImage_OpenMultiBitmap(fif, output, TRUE, FALSE, bMemoryCache); + + // Get src page count + int count = FreeImage_GetPageCount(src); + + // Clone src to dst + for(int page = 0; page < count; page++) { + // Load the bitmap at position 'page' + FIBITMAP *dib = FreeImage_LockPage(src, page); + if(dib) { + // add a new bitmap to dst + FreeImage_AppendPage(dst, dib); + // Unload the bitmap (do not apply any change to src) + FreeImage_UnlockPage(src, dib, FALSE); + } + } + + // Close src + FreeImage_CloseMultiBitmap(src, 0); + // Save and close dst + FreeImage_CloseMultiBitmap(dst, output_flag); + + return true; + } + + return false; +} + + +int +main(int argc, char *argv[]) { + + char *input_filename = "images\\input.tif"; + char *output_filename = "images\\clone.tif"; + + // call this ONLY when linking with FreeImage as a static library +#ifdef FREEIMAGE_LIB + FreeImage_Initialise(); +#endif // FREEIMAGE_LIB + + // initialize our own FreeImage error handler + + FreeImage_SetOutputMessage(MyMessageFunc); + + // Copy 'input.tif' to 'clone.tif' + + CloneMultiPage(FIF_TIFF, input_filename, output_filename, 0); + + // call this ONLY when linking with FreeImage as a static library +#ifdef FREEIMAGE_LIB + FreeImage_DeInitialise(); +#endif // FREEIMAGE_LIB + + return 0; +} diff --git a/Examples/Generic/CreateAlpha.cpp b/Examples/Generic/CreateAlpha.cpp index 48b3e29..77bb2a2 100644 --- a/Examples/Generic/CreateAlpha.cpp +++ b/Examples/Generic/CreateAlpha.cpp @@ -1,181 +1,181 @@ -// ========================================================== -// Alpha channel manipulation example -// -// Design and implementation by -// - Hervé Drolon -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at own risk! -// ========================================================== - -// This example shows how to create a transparent image from any input image -// using the greyscale version of the input image as the alpha channel mask. -// The alpha channel is set using the FreeImage_SetChannel function. -// -// -// ========================================================== - -#include -#include "FreeImage.h" - -// ---------------------------------------------------------- - -/** Generic image loader - @param lpszPathName Pointer to the full file name - @param flag Optional load flag constant - @return Returns the loaded dib if successful, returns NULL otherwise -*/ -FIBITMAP* GenericLoader(const char* lpszPathName, int flag) { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - - // check the file signature and deduce its format - // (the second argument is currently not used by FreeImage) - fif = FreeImage_GetFileType(lpszPathName, 0); - if(fif == FIF_UNKNOWN) { - // no signature ? - // try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilename(lpszPathName); - } - // check that the plugin has reading capabilities ... - if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { - // ok, let's load the file - FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, flag); - // unless a bad file format, we are done ! - return dib; - } - return NULL; -} - -/** Generic image writer - @param dib Pointer to the dib to be saved - @param lpszPathName Pointer to the full file name - @param flag Optional save flag constant - @return Returns true if successful, returns false otherwise -*/ -bool GenericWriter(FIBITMAP* dib, const char* lpszPathName, int flag) { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - BOOL bSuccess = FALSE; - - if(dib) { - // try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilename(lpszPathName); - if(fif != FIF_UNKNOWN ) { - // check that the plugin has sufficient writing and export capabilities ... - WORD bpp = FreeImage_GetBPP(dib); - if(FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)) { - // ok, we can save the file - bSuccess = FreeImage_Save(fif, dib, lpszPathName, flag); - // unless an abnormal bug, we are done ! - } - } - } - return (bSuccess == TRUE) ? true : false; -} - -// ---------------------------------------------------------- - -/** - FreeImage error handler - @param fif Format / Plugin responsible for the error - @param message Error message -*/ -void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) { - printf("\n*** "); - if(fif != FIF_UNKNOWN) { - printf("%s Format\n", FreeImage_GetFormatFromFIF(fif)); - } - printf(message); - printf(" ***\n"); -} - -// ---------------------------------------------------------- - - -/** - Creates a 32-bit transparent image using the black channel of the source image - @param src Source image - @return Returns a 32-bit transparent image -*/ -FIBITMAP* CreateAlphaFromLightness(FIBITMAP *src) { - // create a 32-bit image from the source - FIBITMAP *dst = FreeImage_ConvertTo32Bits(src); - - // create a 8-bit mask - FreeImage_Invert(src); - FIBITMAP *mask = FreeImage_ConvertTo8Bits(src); - FreeImage_Invert(src); - - // insert the mask as an alpha channel - FreeImage_SetChannel(dst, mask, FICC_ALPHA); - - // free the mask and return - FreeImage_Unload(mask); - - return dst; -} - -int -main(int argc, char *argv[]) { - - // call this ONLY when linking with FreeImage as a static library -#ifdef FREEIMAGE_LIB - FreeImage_Initialise(); -#endif // FREEIMAGE_LIB - - // initialize your own FreeImage error handler - - FreeImage_SetOutputMessage(FreeImageErrorHandler); - - // print version & copyright infos - - printf("FreeImage version : %s", FreeImage_GetVersion()); - printf("\n"); - printf(FreeImage_GetCopyrightMessage()); - printf("\n"); - - - if(argc != 3) { - printf("Usage : CreateAlpha \n"); - return 0; - } - - // Load the source image - FIBITMAP *src = GenericLoader(argv[1], 0); - if(src) { - // Create a transparent image from the lightness image of src - FIBITMAP *dst = CreateAlphaFromLightness(src); - - if(dst) { - // Save the destination image - bool bSuccess = GenericWriter(dst, argv[2], 0); - if(!bSuccess) { - printf("\nUnable to save %s file", argv[2]); - printf("\nThis format does not support 32-bit images"); - } - - // Free dst - FreeImage_Unload(dst); - } - - // Free src - FreeImage_Unload(src); - } - - // call this ONLY when linking with FreeImage as a static library -#ifdef FREEIMAGE_LIB - FreeImage_DeInitialise(); -#endif // FREEIMAGE_LIB - - return 0; -} +// ========================================================== +// Alpha channel manipulation example +// +// Design and implementation by +// - Hervé Drolon +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at own risk! +// ========================================================== + +// This example shows how to create a transparent image from any input image +// using the greyscale version of the input image as the alpha channel mask. +// The alpha channel is set using the FreeImage_SetChannel function. +// +// +// ========================================================== + +#include +#include "FreeImage.h" + +// ---------------------------------------------------------- + +/** Generic image loader + @param lpszPathName Pointer to the full file name + @param flag Optional load flag constant + @return Returns the loaded dib if successful, returns NULL otherwise +*/ +FIBITMAP* GenericLoader(const char* lpszPathName, int flag) { + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + + // check the file signature and deduce its format + // (the second argument is currently not used by FreeImage) + fif = FreeImage_GetFileType(lpszPathName, 0); + if(fif == FIF_UNKNOWN) { + // no signature ? + // try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilename(lpszPathName); + } + // check that the plugin has reading capabilities ... + if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { + // ok, let's load the file + FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, flag); + // unless a bad file format, we are done ! + return dib; + } + return NULL; +} + +/** Generic image writer + @param dib Pointer to the dib to be saved + @param lpszPathName Pointer to the full file name + @param flag Optional save flag constant + @return Returns true if successful, returns false otherwise +*/ +bool GenericWriter(FIBITMAP* dib, const char* lpszPathName, int flag) { + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + BOOL bSuccess = FALSE; + + if(dib) { + // try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilename(lpszPathName); + if(fif != FIF_UNKNOWN ) { + // check that the plugin has sufficient writing and export capabilities ... + WORD bpp = FreeImage_GetBPP(dib); + if(FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)) { + // ok, we can save the file + bSuccess = FreeImage_Save(fif, dib, lpszPathName, flag); + // unless an abnormal bug, we are done ! + } + } + } + return (bSuccess == TRUE) ? true : false; +} + +// ---------------------------------------------------------- + +/** + FreeImage error handler + @param fif Format / Plugin responsible for the error + @param message Error message +*/ +void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) { + printf("\n*** "); + if(fif != FIF_UNKNOWN) { + printf("%s Format\n", FreeImage_GetFormatFromFIF(fif)); + } + printf(message); + printf(" ***\n"); +} + +// ---------------------------------------------------------- + + +/** + Creates a 32-bit transparent image using the black channel of the source image + @param src Source image + @return Returns a 32-bit transparent image +*/ +FIBITMAP* CreateAlphaFromLightness(FIBITMAP *src) { + // create a 32-bit image from the source + FIBITMAP *dst = FreeImage_ConvertTo32Bits(src); + + // create a 8-bit mask + FreeImage_Invert(src); + FIBITMAP *mask = FreeImage_ConvertTo8Bits(src); + FreeImage_Invert(src); + + // insert the mask as an alpha channel + FreeImage_SetChannel(dst, mask, FICC_ALPHA); + + // free the mask and return + FreeImage_Unload(mask); + + return dst; +} + +int +main(int argc, char *argv[]) { + + // call this ONLY when linking with FreeImage as a static library +#ifdef FREEIMAGE_LIB + FreeImage_Initialise(); +#endif // FREEIMAGE_LIB + + // initialize your own FreeImage error handler + + FreeImage_SetOutputMessage(FreeImageErrorHandler); + + // print version & copyright infos + + printf("FreeImage version : %s", FreeImage_GetVersion()); + printf("\n"); + printf(FreeImage_GetCopyrightMessage()); + printf("\n"); + + + if(argc != 3) { + printf("Usage : CreateAlpha \n"); + return 0; + } + + // Load the source image + FIBITMAP *src = GenericLoader(argv[1], 0); + if(src) { + // Create a transparent image from the lightness image of src + FIBITMAP *dst = CreateAlphaFromLightness(src); + + if(dst) { + // Save the destination image + bool bSuccess = GenericWriter(dst, argv[2], 0); + if(!bSuccess) { + printf("\nUnable to save %s file", argv[2]); + printf("\nThis format does not support 32-bit images"); + } + + // Free dst + FreeImage_Unload(dst); + } + + // Free src + FreeImage_Unload(src); + } + + // call this ONLY when linking with FreeImage as a static library +#ifdef FREEIMAGE_LIB + FreeImage_DeInitialise(); +#endif // FREEIMAGE_LIB + + return 0; +} diff --git a/Examples/Generic/FIFImportExport.cpp b/Examples/Generic/FIFImportExport.cpp index f78c054..ec791b2 100644 --- a/Examples/Generic/FIFImportExport.cpp +++ b/Examples/Generic/FIFImportExport.cpp @@ -1,149 +1,149 @@ -// ========================================================== -// Plugin functions demonstration -// -// Design and implementation by -// - Hervé Drolon -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at own risk! -// ========================================================== - -// This example shows how to use Plugin functions to explore FreeImage capabilities. -// Whenever an external plugin is added to the library, it is automatically loaded -// with FreeImage and can be asked for its capabilities via the plugin functions. -// -// Functions used in this sample : -// FreeImage_FIFSupportsExportBPP, FreeImage_FIFSupportsICCProfiles, FreeImage_FIFSupportsReading, -// FreeImage_FIFSupportsWriting, FreeImage_GetFIFCount, FreeImage_GetFIFDescription, -// FreeImage_GetFIFExtensionList, FreeImage_GetFormatFromFIF, -// FreeImage_GetVersion, FreeImage_GetCopyrightMessage, FreeImage_SetOutputMessage -// -// ========================================================== - -#include -#include -#include -#include - -#include "FreeImage.h" - -// ---------------------------------------------------------- - -/** - FreeImage error handler -*/ -void MyMessageFunc(FREE_IMAGE_FORMAT fif, const char *message) { - cout << "\n*** " << message << " ***\n"; -} - -// ---------------------------------------------------------- - -/** - Print plugins import capabilities -*/ -void PrintImportFormats(iostream& ios) { - int count = FreeImage_GetFIFCount(); - if(count) - ios << "FORMAT;DESCRIPTION;EXTENSIONS;ICC PROFILES\n"; - for(int i = 0; i < count; i++) { - FREE_IMAGE_FORMAT fif = (FREE_IMAGE_FORMAT)i; - - if(FreeImage_FIFSupportsReading(fif)) { - const char * format = FreeImage_GetFormatFromFIF(fif); - const char * description = FreeImage_GetFIFDescription(fif); - const char * ext = FreeImage_GetFIFExtensionList(fif); - const char * icc = "*"; - if(FreeImage_FIFSupportsICCProfiles(fif)) { - ios << format << ";" << description << ";" << ext << ";" << icc << "\n"; - } else { - ios << format << ";" << description << ";" << ext << "; \n"; - } - } - } -} - -/** - Print plugins export capabilities -*/ -void PrintExportFormats(iostream& ios) { - int count = FreeImage_GetFIFCount(); - if(count) - ios << "FORMAT;DESCRIPTION;EXTENSIONS;BITDEPTH;ICC PROFILES\n"; - for(int i = 0; i < count; i++) { - FREE_IMAGE_FORMAT fif = (FREE_IMAGE_FORMAT)i; - - if(FreeImage_FIFSupportsWriting(fif)) { - const char * format = FreeImage_GetFormatFromFIF(fif); - const char * description = FreeImage_GetFIFDescription(fif); - const char * ext = FreeImage_GetFIFExtensionList(fif); - const char * icc = "*"; - - ios << format << ";" << description << ";" << ext << ";"; - if(FreeImage_FIFSupportsExportBPP(fif, 1)) - ios << "1 "; - if(FreeImage_FIFSupportsExportBPP(fif, 4)) - ios << "4 "; - if(FreeImage_FIFSupportsExportBPP(fif, 8)) - ios << "8 "; - if(FreeImage_FIFSupportsExportBPP(fif, 16)) - ios << "16 "; - if(FreeImage_FIFSupportsExportBPP(fif, 24)) - ios << "24 "; - if(FreeImage_FIFSupportsExportBPP(fif, 32)) - ios << "32 "; - if(FreeImage_FIFSupportsICCProfiles(fif)) { - ios << ";" << icc; - } else { - ios << "; "; - } - ios << "\n"; - } - } -} - -int -main(int argc, char *argv[]) { - // call this ONLY when linking with FreeImage as a static library -#ifdef FREEIMAGE_LIB - FreeImage_Initialise(); -#endif // FREEIMAGE_LIB - - // initialize FreeImage error handler - - FreeImage_SetOutputMessage(MyMessageFunc); - - // print version & copyright infos - - cout << "FreeImage " << FreeImage_GetVersion() << "\n"; - cout << FreeImage_GetCopyrightMessage() << "\n\n"; - - // Print input formats (including external plugins) known by the library - fstream importFile("fif_import.csv", ios::out); - PrintImportFormats(importFile); - importFile.close(); - - // Print output formats (including plugins) known by the library - // for each export format, supported bitdepths are given - fstream exportFile("fif_export.csv", ios::out); - PrintExportFormats(exportFile); - exportFile.close(); - - // call this ONLY when linking with FreeImage as a static library -#ifdef FREEIMAGE_LIB - FreeImage_DeInitialise(); -#endif // FREEIMAGE_LIB - - return 0; - -} +// ========================================================== +// Plugin functions demonstration +// +// Design and implementation by +// - Hervé Drolon +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at own risk! +// ========================================================== + +// This example shows how to use Plugin functions to explore FreeImage capabilities. +// Whenever an external plugin is added to the library, it is automatically loaded +// with FreeImage and can be asked for its capabilities via the plugin functions. +// +// Functions used in this sample : +// FreeImage_FIFSupportsExportBPP, FreeImage_FIFSupportsICCProfiles, FreeImage_FIFSupportsReading, +// FreeImage_FIFSupportsWriting, FreeImage_GetFIFCount, FreeImage_GetFIFDescription, +// FreeImage_GetFIFExtensionList, FreeImage_GetFormatFromFIF, +// FreeImage_GetVersion, FreeImage_GetCopyrightMessage, FreeImage_SetOutputMessage +// +// ========================================================== + +#include +#include +#include +#include + +#include "FreeImage.h" + +// ---------------------------------------------------------- + +/** + FreeImage error handler +*/ +void MyMessageFunc(FREE_IMAGE_FORMAT fif, const char *message) { + cout << "\n*** " << message << " ***\n"; +} + +// ---------------------------------------------------------- + +/** + Print plugins import capabilities +*/ +void PrintImportFormats(iostream& ios) { + int count = FreeImage_GetFIFCount(); + if(count) + ios << "FORMAT;DESCRIPTION;EXTENSIONS;ICC PROFILES\n"; + for(int i = 0; i < count; i++) { + FREE_IMAGE_FORMAT fif = (FREE_IMAGE_FORMAT)i; + + if(FreeImage_FIFSupportsReading(fif)) { + const char * format = FreeImage_GetFormatFromFIF(fif); + const char * description = FreeImage_GetFIFDescription(fif); + const char * ext = FreeImage_GetFIFExtensionList(fif); + const char * icc = "*"; + if(FreeImage_FIFSupportsICCProfiles(fif)) { + ios << format << ";" << description << ";" << ext << ";" << icc << "\n"; + } else { + ios << format << ";" << description << ";" << ext << "; \n"; + } + } + } +} + +/** + Print plugins export capabilities +*/ +void PrintExportFormats(iostream& ios) { + int count = FreeImage_GetFIFCount(); + if(count) + ios << "FORMAT;DESCRIPTION;EXTENSIONS;BITDEPTH;ICC PROFILES\n"; + for(int i = 0; i < count; i++) { + FREE_IMAGE_FORMAT fif = (FREE_IMAGE_FORMAT)i; + + if(FreeImage_FIFSupportsWriting(fif)) { + const char * format = FreeImage_GetFormatFromFIF(fif); + const char * description = FreeImage_GetFIFDescription(fif); + const char * ext = FreeImage_GetFIFExtensionList(fif); + const char * icc = "*"; + + ios << format << ";" << description << ";" << ext << ";"; + if(FreeImage_FIFSupportsExportBPP(fif, 1)) + ios << "1 "; + if(FreeImage_FIFSupportsExportBPP(fif, 4)) + ios << "4 "; + if(FreeImage_FIFSupportsExportBPP(fif, 8)) + ios << "8 "; + if(FreeImage_FIFSupportsExportBPP(fif, 16)) + ios << "16 "; + if(FreeImage_FIFSupportsExportBPP(fif, 24)) + ios << "24 "; + if(FreeImage_FIFSupportsExportBPP(fif, 32)) + ios << "32 "; + if(FreeImage_FIFSupportsICCProfiles(fif)) { + ios << ";" << icc; + } else { + ios << "; "; + } + ios << "\n"; + } + } +} + +int +main(int argc, char *argv[]) { + // call this ONLY when linking with FreeImage as a static library +#ifdef FREEIMAGE_LIB + FreeImage_Initialise(); +#endif // FREEIMAGE_LIB + + // initialize FreeImage error handler + + FreeImage_SetOutputMessage(MyMessageFunc); + + // print version & copyright infos + + cout << "FreeImage " << FreeImage_GetVersion() << "\n"; + cout << FreeImage_GetCopyrightMessage() << "\n\n"; + + // Print input formats (including external plugins) known by the library + fstream importFile("fif_import.csv", ios::out); + PrintImportFormats(importFile); + importFile.close(); + + // Print output formats (including plugins) known by the library + // for each export format, supported bitdepths are given + fstream exportFile("fif_export.csv", ios::out); + PrintExportFormats(exportFile); + exportFile.close(); + + // call this ONLY when linking with FreeImage as a static library +#ifdef FREEIMAGE_LIB + FreeImage_DeInitialise(); +#endif // FREEIMAGE_LIB + + return 0; + +} diff --git a/Examples/Generic/FIIO_Mem.cpp b/Examples/Generic/FIIO_Mem.cpp index 33eea8a..703acb1 100644 --- a/Examples/Generic/FIIO_Mem.cpp +++ b/Examples/Generic/FIIO_Mem.cpp @@ -1,146 +1,146 @@ -/*--------------------------------------------------------------------------*\ -|| fiio_mem.cpp by Ryan Rubley || -|| || -|| (v1.02) 4-28-2004 || -|| FreeImageIO to memory || -|| || -\*--------------------------------------------------------------------------*/ - -#include -#include -#include "fiio_mem.h" - -#ifdef __cplusplus -extern "C" { -#endif - -FIBITMAP * -FreeImage_LoadFromMem(FREE_IMAGE_FORMAT fif, fiio_mem_handle *handle, int flags) { - FreeImageIO io; - SetMemIO(&io); - - if (handle && handle->data) { - handle->curpos = 0; - return FreeImage_LoadFromHandle(fif, &io, (fi_handle)handle, flags); - } - - return NULL; -} - -BOOL -FreeImage_SaveToMem(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, fiio_mem_handle *handle, int flags) { - FreeImageIO io; - SetMemIO(&io); - - if (handle) { - handle->filelen = 0; - handle->curpos = 0; - return FreeImage_SaveToHandle(fif, dib, &io, (fi_handle)handle, flags); - } - - return FALSE; -} - -// ---------------------------------------------------------- - -void -SetMemIO(FreeImageIO *io) { - io->read_proc = fiio_mem_ReadProc; - io->seek_proc = fiio_mem_SeekProc; - io->tell_proc = fiio_mem_TellProc; - io->write_proc = fiio_mem_WriteProc; -} - -// ---------------------------------------------------------- - -#define FIIOMEM(member) (((fiio_mem_handle *)handle)->member) - -unsigned -fiio_mem_ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { - unsigned x; - for( x=0; x= FIIOMEM(datalen) ) { - //if we are at or above 1G, we cant double without going negative - if( FIIOMEM(datalen) & 0x40000000 ) { - //max 2G - if( FIIOMEM(datalen) == 0x7FFFFFFF ) { - return 0; - } - newdatalen = 0x7FFFFFFF; - } else if( FIIOMEM(datalen) == 0 ) { - //default to 4K if nothing yet - newdatalen = 4096; - } else { - //double size - newdatalen = FIIOMEM(datalen) << 1; - } - newdata = realloc( FIIOMEM(data), newdatalen ); - if( !newdata ) { - return 0; - } - FIIOMEM(data) = newdata; - FIIOMEM(datalen) = newdatalen; - } - memcpy( (char *)FIIOMEM(data) + FIIOMEM(curpos), buffer, size*count ); - FIIOMEM(curpos) += size*count; - if( FIIOMEM(curpos) > FIIOMEM(filelen) ) { - FIIOMEM(filelen) = FIIOMEM(curpos); - } - return count; -} - -int -fiio_mem_SeekProc(fi_handle handle, long offset, int origin) { - switch(origin) { //0 to filelen-1 are 'inside' the file - default: - case SEEK_SET: //can fseek() to 0-7FFFFFFF always - if( offset >= 0 ) { - FIIOMEM(curpos) = offset; - return 0; - } - break; - - case SEEK_CUR: - if( FIIOMEM(curpos)+offset >= 0 ) { - FIIOMEM(curpos) += offset; - return 0; - } - break; - - case SEEK_END: - if( FIIOMEM(filelen)+offset >= 0 ) { - FIIOMEM(curpos) = FIIOMEM(filelen)+offset; - return 0; - } - break; - } - - return -1; -} - -long -fiio_mem_TellProc(fi_handle handle) { - return FIIOMEM(curpos); -} - -#ifdef __cplusplus -} -#endif +/*--------------------------------------------------------------------------*\ +|| fiio_mem.cpp by Ryan Rubley || +|| || +|| (v1.02) 4-28-2004 || +|| FreeImageIO to memory || +|| || +\*--------------------------------------------------------------------------*/ + +#include +#include +#include "fiio_mem.h" + +#ifdef __cplusplus +extern "C" { +#endif + +FIBITMAP * +FreeImage_LoadFromMem(FREE_IMAGE_FORMAT fif, fiio_mem_handle *handle, int flags) { + FreeImageIO io; + SetMemIO(&io); + + if (handle && handle->data) { + handle->curpos = 0; + return FreeImage_LoadFromHandle(fif, &io, (fi_handle)handle, flags); + } + + return NULL; +} + +BOOL +FreeImage_SaveToMem(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, fiio_mem_handle *handle, int flags) { + FreeImageIO io; + SetMemIO(&io); + + if (handle) { + handle->filelen = 0; + handle->curpos = 0; + return FreeImage_SaveToHandle(fif, dib, &io, (fi_handle)handle, flags); + } + + return FALSE; +} + +// ---------------------------------------------------------- + +void +SetMemIO(FreeImageIO *io) { + io->read_proc = fiio_mem_ReadProc; + io->seek_proc = fiio_mem_SeekProc; + io->tell_proc = fiio_mem_TellProc; + io->write_proc = fiio_mem_WriteProc; +} + +// ---------------------------------------------------------- + +#define FIIOMEM(member) (((fiio_mem_handle *)handle)->member) + +unsigned +fiio_mem_ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { + unsigned x; + for( x=0; x= FIIOMEM(datalen) ) { + //if we are at or above 1G, we cant double without going negative + if( FIIOMEM(datalen) & 0x40000000 ) { + //max 2G + if( FIIOMEM(datalen) == 0x7FFFFFFF ) { + return 0; + } + newdatalen = 0x7FFFFFFF; + } else if( FIIOMEM(datalen) == 0 ) { + //default to 4K if nothing yet + newdatalen = 4096; + } else { + //double size + newdatalen = FIIOMEM(datalen) << 1; + } + newdata = realloc( FIIOMEM(data), newdatalen ); + if( !newdata ) { + return 0; + } + FIIOMEM(data) = newdata; + FIIOMEM(datalen) = newdatalen; + } + memcpy( (char *)FIIOMEM(data) + FIIOMEM(curpos), buffer, size*count ); + FIIOMEM(curpos) += size*count; + if( FIIOMEM(curpos) > FIIOMEM(filelen) ) { + FIIOMEM(filelen) = FIIOMEM(curpos); + } + return count; +} + +int +fiio_mem_SeekProc(fi_handle handle, long offset, int origin) { + switch(origin) { //0 to filelen-1 are 'inside' the file + default: + case SEEK_SET: //can fseek() to 0-7FFFFFFF always + if( offset >= 0 ) { + FIIOMEM(curpos) = offset; + return 0; + } + break; + + case SEEK_CUR: + if( FIIOMEM(curpos)+offset >= 0 ) { + FIIOMEM(curpos) += offset; + return 0; + } + break; + + case SEEK_END: + if( FIIOMEM(filelen)+offset >= 0 ) { + FIIOMEM(curpos) = FIIOMEM(filelen)+offset; + return 0; + } + break; + } + + return -1; +} + +long +fiio_mem_TellProc(fi_handle handle) { + return FIIOMEM(curpos); +} + +#ifdef __cplusplus +} +#endif diff --git a/Examples/Generic/LoadFromHandle.cpp b/Examples/Generic/LoadFromHandle.cpp index d8e14e8..45afb46 100644 --- a/Examples/Generic/LoadFromHandle.cpp +++ b/Examples/Generic/LoadFromHandle.cpp @@ -1,145 +1,145 @@ -// ========================================================== -// Load From Handle Example -// -// Design and implementation by -// - Hervé Drolon -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at own risk! -// ========================================================== - -// This example shows how to load a bitmap from a -// user allocated FILE pointer. -// -// Functions used in this sample : -// FreeImage_GetFormatFromFIF, FreeImage_GetFileTypeFromHandle, FreeImage_LoadFromHandle, -// FreeImage_GetFIFFromFilename, FreeImage_Save, FreeImage_Unload -// FreeImage_GetVersion, FreeImage_GetCopyrightMessage, FreeImage_SetOutputMessage -// -// ========================================================== - -#include -#include -#include - -#include "FreeImage.h" - -// ---------------------------------------------------------- - -/** - FreeImage error handler - @param fif Format / Plugin responsible for the error - @param message Error message -*/ -void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) { - printf("\n*** "); - if(fif != FIF_UNKNOWN) { - printf("%s Format\n", FreeImage_GetFormatFromFIF(fif)); - } - printf(message); - printf(" ***\n"); -} - -// ---------------------------------------------------------- - -unsigned DLL_CALLCONV -myReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { - return fread(buffer, size, count, (FILE *)handle); -} - -unsigned DLL_CALLCONV -myWriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { - return fwrite(buffer, size, count, (FILE *)handle); -} - -int DLL_CALLCONV -mySeekProc(fi_handle handle, long offset, int origin) { - return fseek((FILE *)handle, offset, origin); -} - -long DLL_CALLCONV -myTellProc(fi_handle handle) { - return ftell((FILE *)handle); -} - -// ---------------------------------------------------------- - -int -main(int argc, char *argv[]) { - - // call this ONLY when linking with FreeImage as a static library -#ifdef FREEIMAGE_LIB - FreeImage_Initialise(); -#endif // FREEIMAGE_LIB - - // initialize your own FreeImage error handler - - FreeImage_SetOutputMessage(FreeImageErrorHandler); - - // print version & copyright infos - - printf(FreeImage_GetVersion()); - printf("\n"); - printf(FreeImage_GetCopyrightMessage()); - printf("\n"); - - - if(argc != 2) { - printf("Usage : LoadFromHandle \n"); - return 0; - } - - // initialize your own IO functions - - FreeImageIO io; - - io.read_proc = myReadProc; - io.write_proc = myWriteProc; - io.seek_proc = mySeekProc; - io.tell_proc = myTellProc; - - FILE *file = fopen(argv[1], "rb"); - - if (file != NULL) { - // find the buffer format - FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromHandle(&io, (fi_handle)file, 0); - - if(fif != FIF_UNKNOWN) { - // load from the file handle - FIBITMAP *dib = FreeImage_LoadFromHandle(fif, &io, (fi_handle)file, 0); - - // save the bitmap as a PNG ... - const char *output_filename = "test.png"; - - // first, check the output format from the file name or file extension - FREE_IMAGE_FORMAT out_fif = FreeImage_GetFIFFromFilename(output_filename); - - if(out_fif != FIF_UNKNOWN) { - // then save the file - FreeImage_Save(out_fif, dib, output_filename, 0); - } - - // free the loaded FIBITMAP - FreeImage_Unload(dib); - } - fclose(file); - } - - // call this ONLY when linking with FreeImage as a static library -#ifdef FREEIMAGE_LIB - FreeImage_DeInitialise(); -#endif // FREEIMAGE_LIB - - return 0; -} +// ========================================================== +// Load From Handle Example +// +// Design and implementation by +// - Hervé Drolon +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at own risk! +// ========================================================== + +// This example shows how to load a bitmap from a +// user allocated FILE pointer. +// +// Functions used in this sample : +// FreeImage_GetFormatFromFIF, FreeImage_GetFileTypeFromHandle, FreeImage_LoadFromHandle, +// FreeImage_GetFIFFromFilename, FreeImage_Save, FreeImage_Unload +// FreeImage_GetVersion, FreeImage_GetCopyrightMessage, FreeImage_SetOutputMessage +// +// ========================================================== + +#include +#include +#include + +#include "FreeImage.h" + +// ---------------------------------------------------------- + +/** + FreeImage error handler + @param fif Format / Plugin responsible for the error + @param message Error message +*/ +void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) { + printf("\n*** "); + if(fif != FIF_UNKNOWN) { + printf("%s Format\n", FreeImage_GetFormatFromFIF(fif)); + } + printf(message); + printf(" ***\n"); +} + +// ---------------------------------------------------------- + +unsigned DLL_CALLCONV +myReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { + return fread(buffer, size, count, (FILE *)handle); +} + +unsigned DLL_CALLCONV +myWriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { + return fwrite(buffer, size, count, (FILE *)handle); +} + +int DLL_CALLCONV +mySeekProc(fi_handle handle, long offset, int origin) { + return fseek((FILE *)handle, offset, origin); +} + +long DLL_CALLCONV +myTellProc(fi_handle handle) { + return ftell((FILE *)handle); +} + +// ---------------------------------------------------------- + +int +main(int argc, char *argv[]) { + + // call this ONLY when linking with FreeImage as a static library +#ifdef FREEIMAGE_LIB + FreeImage_Initialise(); +#endif // FREEIMAGE_LIB + + // initialize your own FreeImage error handler + + FreeImage_SetOutputMessage(FreeImageErrorHandler); + + // print version & copyright infos + + printf(FreeImage_GetVersion()); + printf("\n"); + printf(FreeImage_GetCopyrightMessage()); + printf("\n"); + + + if(argc != 2) { + printf("Usage : LoadFromHandle \n"); + return 0; + } + + // initialize your own IO functions + + FreeImageIO io; + + io.read_proc = myReadProc; + io.write_proc = myWriteProc; + io.seek_proc = mySeekProc; + io.tell_proc = myTellProc; + + FILE *file = fopen(argv[1], "rb"); + + if (file != NULL) { + // find the buffer format + FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromHandle(&io, (fi_handle)file, 0); + + if(fif != FIF_UNKNOWN) { + // load from the file handle + FIBITMAP *dib = FreeImage_LoadFromHandle(fif, &io, (fi_handle)file, 0); + + // save the bitmap as a PNG ... + const char *output_filename = "test.png"; + + // first, check the output format from the file name or file extension + FREE_IMAGE_FORMAT out_fif = FreeImage_GetFIFFromFilename(output_filename); + + if(out_fif != FIF_UNKNOWN) { + // then save the file + FreeImage_Save(out_fif, dib, output_filename, 0); + } + + // free the loaded FIBITMAP + FreeImage_Unload(dib); + } + fclose(file); + } + + // call this ONLY when linking with FreeImage as a static library +#ifdef FREEIMAGE_LIB + FreeImage_DeInitialise(); +#endif // FREEIMAGE_LIB + + return 0; +} diff --git a/Examples/Generic/LoadFromMemory-classified.cpp b/Examples/Generic/LoadFromMemory-classified.cpp index 7494ba9..5466f48 100644 --- a/Examples/Generic/LoadFromMemory-classified.cpp +++ b/Examples/Generic/LoadFromMemory-classified.cpp @@ -1,101 +1,101 @@ -// ========================================================== -// Classified FreeImageIO handler -// -// Design and implementation by -// - schickb (schickb@hotmail.com) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -class MemIO : public FreeImageIO { -public : - MemIO( BYTE *data ) : _start(data), _cp(data) { - read_proc = _ReadProc; - write_proc = _WriteProc; - tell_proc = _TellProc; - seek_proc = _SeekProc; - } - - void Reset() { - _cp = _start; - } - - static unsigned _ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle); - static unsigned _WriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle); - static int _SeekProc(fi_handle handle, long offset, int origin); - static long _TellProc(fi_handle handle); - -private: - BYTE * const _start; - BYTE *_cp; -}; - - -unsigned -MemIO::_ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { - MemIO *memIO = (MemIO*)handle; - - BYTE *tmp = (BYTE *)buffer; - - for (unsigned c = 0; c < count; c++) { - memcpy(tmp, memIO->_cp, size); - - memIO->_cp = memIO->_cp + size; - - tmp += size; - } - - return count; -} - -unsigned -MemIO::_WriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { - ASSERT( false ); - return size; -} - -int -MemIO::_SeekProc(fi_handle handle, long offset, int origin) { - ASSERT(origin != SEEK_END); - - MemIO *memIO = (MemIO*)handle; - - if (origin == SEEK_SET) - memIO->_cp = memIO->_start + offset; - else - memIO->_cp = memIO->_cp + offset; - - return 0; -} - -long -MemIO::_TellProc(fi_handle handle) { - MemIO *memIO = (MemIO*)handle; - - return memIO->_cp - memIO->_start; -} - -// ---------------------------------------------------------- -// PSEUDOCODE... HELPS TO UNDERSTAND HOW THE MEMIO CLASS WORKS -// ---------------------------------------------------------- - -int -main(int argc, char *argv[]) { - BYTE *data = loadimagesomehow(); - - MemIO memIO(data); - - FIBITMAP *fbmp = FreeImage_LoadFromHandle( fif, &memIO, (fi_handle)&memIO ); +// ========================================================== +// Classified FreeImageIO handler +// +// Design and implementation by +// - schickb (schickb@hotmail.com) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +class MemIO : public FreeImageIO { +public : + MemIO( BYTE *data ) : _start(data), _cp(data) { + read_proc = _ReadProc; + write_proc = _WriteProc; + tell_proc = _TellProc; + seek_proc = _SeekProc; + } + + void Reset() { + _cp = _start; + } + + static unsigned _ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle); + static unsigned _WriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle); + static int _SeekProc(fi_handle handle, long offset, int origin); + static long _TellProc(fi_handle handle); + +private: + BYTE * const _start; + BYTE *_cp; +}; + + +unsigned +MemIO::_ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { + MemIO *memIO = (MemIO*)handle; + + BYTE *tmp = (BYTE *)buffer; + + for (unsigned c = 0; c < count; c++) { + memcpy(tmp, memIO->_cp, size); + + memIO->_cp = memIO->_cp + size; + + tmp += size; + } + + return count; +} + +unsigned +MemIO::_WriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { + ASSERT( false ); + return size; +} + +int +MemIO::_SeekProc(fi_handle handle, long offset, int origin) { + ASSERT(origin != SEEK_END); + + MemIO *memIO = (MemIO*)handle; + + if (origin == SEEK_SET) + memIO->_cp = memIO->_start + offset; + else + memIO->_cp = memIO->_cp + offset; + + return 0; +} + +long +MemIO::_TellProc(fi_handle handle) { + MemIO *memIO = (MemIO*)handle; + + return memIO->_cp - memIO->_start; +} + +// ---------------------------------------------------------- +// PSEUDOCODE... HELPS TO UNDERSTAND HOW THE MEMIO CLASS WORKS +// ---------------------------------------------------------- + +int +main(int argc, char *argv[]) { + BYTE *data = loadimagesomehow(); + + MemIO memIO(data); + + FIBITMAP *fbmp = FreeImage_LoadFromHandle( fif, &memIO, (fi_handle)&memIO ); } \ No newline at end of file diff --git a/Examples/Generic/LoadFromMemory.cpp b/Examples/Generic/LoadFromMemory.cpp index f62e0b5..026ebff 100644 --- a/Examples/Generic/LoadFromMemory.cpp +++ b/Examples/Generic/LoadFromMemory.cpp @@ -1,113 +1,113 @@ -// ========================================================== -// Load From Memory Example -// -// Design and implementation by Floris van den Berg -// -// This file is part of FreeImage 3 -// -// Use at own risk! -// ========================================================== -// -// This example shows how to load a bitmap from memory -// rather than from a file. To do this we make use of the -// FreeImage_LoadFromHandle functions where we override -// the i/o functions to simulate FILE* access in memory. -// -// For seeking purposes the fi_handle passed to the i/o -// functions contain the start of the data block where the -// bitmap is stored. -// -// ========================================================== - -#include -#include -#include - -#include "FreeImage.h" - -// ---------------------------------------------------------- - -fi_handle g_load_address; - -// ---------------------------------------------------------- - -inline unsigned _stdcall -_ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { - BYTE *tmp = (BYTE *)buffer; - - for (unsigned c = 0; c < count; c++) { - memcpy(tmp, g_load_address, size); - - g_load_address = (BYTE *)g_load_address + size; - - tmp += size; - } - - return count; -} - -inline unsigned _stdcall -_WriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { - // there's not much use for saving the bitmap into memory now, is there? - - return size; -} - -inline int _stdcall -_SeekProc(fi_handle handle, long offset, int origin) { - assert(origin != SEEK_END); - - if (origin == SEEK_SET) { - g_load_address = (BYTE *)handle + offset; - } else { - g_load_address = (BYTE *)g_load_address + offset; - } - - return 0; -} - -inline long _stdcall -_TellProc(fi_handle handle) { - assert((int)handle > (int)g_load_address); - - return ((int)g_load_address - (int)handle); -} - -// ---------------------------------------------------------- - -int -main(int argc, char *argv[]) { - FreeImageIO io; - - io.read_proc = _ReadProc; - io.write_proc = _WriteProc; - io.tell_proc = _TellProc; - io.seek_proc = _SeekProc; - - // allocate some memory for the bitmap - - BYTE *test = new BYTE[159744]; - - if (test != NULL) { - // load the bitmap into memory. ofcourse you can do this any way you want - - FILE *file = fopen("e:\\projects\\images\\money-256.tif", "rb"); - fread(test, 159744, 1, file); - fclose(file); - - // we store the load address of the bitmap for internal reasons - - g_load_address = test; - - // convert the bitmap - - FIBITMAP *dib = FreeImage_LoadFromHandle(FIF_TIFF, &io, (fi_handle)test); - - // don't forget to free the dib ! - FreeImage_Unload(dib); - - delete [] test; - } - - return 0; +// ========================================================== +// Load From Memory Example +// +// Design and implementation by Floris van den Berg +// +// This file is part of FreeImage 3 +// +// Use at own risk! +// ========================================================== +// +// This example shows how to load a bitmap from memory +// rather than from a file. To do this we make use of the +// FreeImage_LoadFromHandle functions where we override +// the i/o functions to simulate FILE* access in memory. +// +// For seeking purposes the fi_handle passed to the i/o +// functions contain the start of the data block where the +// bitmap is stored. +// +// ========================================================== + +#include +#include +#include + +#include "FreeImage.h" + +// ---------------------------------------------------------- + +fi_handle g_load_address; + +// ---------------------------------------------------------- + +inline unsigned _stdcall +_ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { + BYTE *tmp = (BYTE *)buffer; + + for (unsigned c = 0; c < count; c++) { + memcpy(tmp, g_load_address, size); + + g_load_address = (BYTE *)g_load_address + size; + + tmp += size; + } + + return count; +} + +inline unsigned _stdcall +_WriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { + // there's not much use for saving the bitmap into memory now, is there? + + return size; +} + +inline int _stdcall +_SeekProc(fi_handle handle, long offset, int origin) { + assert(origin != SEEK_END); + + if (origin == SEEK_SET) { + g_load_address = (BYTE *)handle + offset; + } else { + g_load_address = (BYTE *)g_load_address + offset; + } + + return 0; +} + +inline long _stdcall +_TellProc(fi_handle handle) { + assert((int)handle > (int)g_load_address); + + return ((int)g_load_address - (int)handle); +} + +// ---------------------------------------------------------- + +int +main(int argc, char *argv[]) { + FreeImageIO io; + + io.read_proc = _ReadProc; + io.write_proc = _WriteProc; + io.tell_proc = _TellProc; + io.seek_proc = _SeekProc; + + // allocate some memory for the bitmap + + BYTE *test = new BYTE[159744]; + + if (test != NULL) { + // load the bitmap into memory. ofcourse you can do this any way you want + + FILE *file = fopen("e:\\projects\\images\\money-256.tif", "rb"); + fread(test, 159744, 1, file); + fclose(file); + + // we store the load address of the bitmap for internal reasons + + g_load_address = test; + + // convert the bitmap + + FIBITMAP *dib = FreeImage_LoadFromHandle(FIF_TIFF, &io, (fi_handle)test); + + // don't forget to free the dib ! + FreeImage_Unload(dib); + + delete [] test; + } + + return 0; } \ No newline at end of file diff --git a/Examples/Generic/ShowMetadata.cpp b/Examples/Generic/ShowMetadata.cpp index 1df0af8..95d8be1 100644 --- a/Examples/Generic/ShowMetadata.cpp +++ b/Examples/Generic/ShowMetadata.cpp @@ -1,317 +1,317 @@ -// ========================================================== -// Simple metadata reader -// -// Design and implementation by -// - Hervé Drolon -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at own risk! -// ========================================================== - -// -// This example shows how to easily parse all metadata -// contained in a JPEG, TIFF or PNG image. -// Comments, Exif and IPTC/NAA metadata tags are written to a HTML file -// for later reading, and Adobe XMP XML packets are written -// in a file whose extension is '.xmp'. This file can be later -// processed using a XML parser. -// -// Metadata functions showed in this sample : -// FreeImage_GetMetadataCount, FreeImage_FindFirstMetadata, FreeImage_FindNextMetadata, -// FreeImage_FindCloseMetadata, FreeImage_TagToString, FreeImage_GetMetadata -// -// ========================================================== - -#include -#include -#include - -using namespace std; - -#include "FreeImage.h" - -// ---------------------------------------------------------- - -/** Generic image loader - @param lpszPathName Pointer to the full file name - @param flag Optional load flag constant - @return Returns the loaded dib if successful, returns NULL otherwise -*/ -FIBITMAP* GenericLoader(const char* lpszPathName, int flag) { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - - // check the file signature and deduce its format - // (the second argument is currently not used by FreeImage) - fif = FreeImage_GetFileType(lpszPathName, 0); - if(fif == FIF_UNKNOWN) { - // no signature ? - // try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilename(lpszPathName); - } - // check that the plugin has reading capabilities ... - if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { - // ok, let's load the file - FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, flag); - // unless a bad file format, we are done ! - return dib; - } - return NULL; -} - -/** Generic image writer - @param dib Pointer to the dib to be saved - @param lpszPathName Pointer to the full file name - @param flag Optional save flag constant - @return Returns true if successful, returns false otherwise -*/ -bool GenericWriter(FIBITMAP* dib, const char* lpszPathName, int flag) { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - BOOL bSuccess = FALSE; - - if(dib) { - // try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilename(lpszPathName); - if(fif != FIF_UNKNOWN ) { - // check that the plugin has sufficient writing and export capabilities ... - WORD bpp = FreeImage_GetBPP(dib); - if(FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)) { - // ok, we can save the file - bSuccess = FreeImage_Save(fif, dib, lpszPathName, flag); - // unless an abnormal bug, we are done ! - } - } - } - return (bSuccess == TRUE) ? true : false; -} - -// ---------------------------------------------------------- - -/** - FreeImage error handler - @param fif Format / Plugin responsible for the error - @param message Error message -*/ -void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) { - cout << "\n*** "; - if(fif != FIF_UNKNOWN) { - cout << FreeImage_GetFormatFromFIF(fif) << " Format\n"; - } - cout << message; - cout << " ***\n"; -} - -// ---------------------------------------------------------- - -/** -Print a basic HTML header -*/ -void PrintHTMLHeader(iostream& ios) { - ios << "\n\n
\n"; - ios << "\n"; -} - -/** -Print a HTML footer -*/ -void PrintHTMLFooter(iostream& ios) { - ios << "
\n\n\n\n"; -} - -/** -Print a table header -*/ -void PrintTableHeader(iostream& ios, const char *title) { - ios << "\n"; - ios << "\n"; -} - -/** -Print a table section -*/ -void PrintTableSection(iostream& ios, const char *title) { - ios << "\n"; - ios << ""; -} - -/** -Print a table footer -*/ -void PrintTableFooter(iostream& ios) { - ios << "
" << title << "
" << title << "
Tag nameTag valueDescription
\n"; -} - - -/** -Print the metadata tags to a HTML file -*/ -void PrintMetadata(iostream& ios, const char *sectionTitle, FIBITMAP *dib, FREE_IMAGE_MDMODEL model) { - FITAG *tag = NULL; - FIMETADATA *mdhandle = NULL; - - mdhandle = FreeImage_FindFirstMetadata(model, dib, &tag); - - if(mdhandle) { - // Print a table section - PrintTableSection(ios, sectionTitle); - - do { - // convert the tag value to a string - const char *value = FreeImage_TagToString(model, tag); - - // print the tag - // note that most tags do not have a description, - // especially when the metadata specifications are not available - if(FreeImage_GetTagDescription(tag)) { - ios << "" << FreeImage_GetTagKey(tag) << "" << value << "" << FreeImage_GetTagDescription(tag) << "\n"; - } else { - ios << "" << FreeImage_GetTagKey(tag) << "" << value << "" << " " << "\n"; - } - - } while(FreeImage_FindNextMetadata(mdhandle, &tag)); - } - - FreeImage_FindCloseMetadata(mdhandle); -} - -int -main(int argc, char *argv[]) { - unsigned count; - - // call this ONLY when linking with FreeImage as a static library -#ifdef FREEIMAGE_LIB - FreeImage_Initialise(); -#endif // FREEIMAGE_LIB - - // initialize your own FreeImage error handler - - FreeImage_SetOutputMessage(FreeImageErrorHandler); - - // print version & copyright infos - - cout << "FreeImage " << FreeImage_GetVersion() << "\n"; - cout << FreeImage_GetCopyrightMessage() << "\n\n"; - - if(argc != 2) { - cout << "Usage : ShowMetadata \n"; - return 0; - } - - // Load the bitmap - - FIBITMAP *dib = GenericLoader(argv[1], 0); - if(!dib) - return 0; - - // Create a HTML file - std::string html_file(strtok(argv[1], ".") + std::string(".html")); - - fstream metadataFile(html_file.c_str(), ios::out); - - // Print the header - - PrintHTMLHeader(metadataFile); - PrintTableHeader(metadataFile, argv[1]); - - // Parse and print metadata - - if(count = FreeImage_GetMetadataCount(FIMD_COMMENTS, dib)) { - cout << "\nFIMD_COMMENTS (" << count << " data)\n-----------------------------------------\n"; - - PrintMetadata(metadataFile, "Comments", dib, FIMD_COMMENTS); - } - if(count = FreeImage_GetMetadataCount(FIMD_EXIF_MAIN, dib)) { - cout << "\nFIMD_EXIF_MAIN (" << count << " data)\n-----------------------------------------\n"; - - PrintMetadata(metadataFile, "Exif - main info", dib, FIMD_EXIF_MAIN); - } - if(count = FreeImage_GetMetadataCount(FIMD_EXIF_EXIF, dib)) { - cout << "\nFIMD_EXIF_EXIF (" << count << " data)\n-----------------------------------------\n"; - - PrintMetadata(metadataFile, "Exif - advanced info", dib, FIMD_EXIF_EXIF); - } - if(count = FreeImage_GetMetadataCount(FIMD_EXIF_GPS, dib)) { - cout << "\nFIMD_EXIF_GPS (" << count << " data)\n-----------------------------------------\n"; - - PrintMetadata(metadataFile, "Exif GPS", dib, FIMD_EXIF_GPS); - } - if(count = FreeImage_GetMetadataCount(FIMD_EXIF_INTEROP, dib)) { - cout << "\nFIMD_EXIF_INTEROP (" << count << " data)\n-----------------------------------------\n"; - - PrintMetadata(metadataFile, "Exif interoperability", dib, FIMD_EXIF_INTEROP); - } - if(count = FreeImage_GetMetadataCount(FIMD_EXIF_MAKERNOTE, dib)) { - cout << "\nFIMD_EXIF_MAKERNOTE (" << count << " data)\n-----------------------------------------\n"; - - // Get the camera model - FITAG *tagMake = NULL; - FreeImage_GetMetadata(FIMD_EXIF_MAIN, dib, "Make", &tagMake); - - std::string buffer((char*)FreeImage_GetTagValue(tagMake)); - buffer += " Makernote"; - - PrintMetadata(metadataFile, buffer.c_str(), dib, FIMD_EXIF_MAKERNOTE); - } - if(count = FreeImage_GetMetadataCount(FIMD_IPTC, dib)) { - cout << "\nFIMD_IPTC (" << count << " data)\n-----------------------------------------\n"; - - PrintMetadata(metadataFile, "IPTC/NAA", dib, FIMD_IPTC); - } - if(count = FreeImage_GetMetadataCount(FIMD_GEOTIFF, dib)) { - cout << "\nFIMD_GEOTIFF (" << count << " data)\n-----------------------------------------\n"; - - PrintMetadata(metadataFile, "GEOTIFF", dib, FIMD_GEOTIFF); - } - - // Print the footer - - PrintTableFooter(metadataFile); - PrintHTMLFooter(metadataFile); - - // close the HTML file - - metadataFile.close(); - - // print XMP data - - if(count = FreeImage_GetMetadataCount(FIMD_XMP, dib)) { - cout << "\nFIMD_XMP (" << count << " packet)\n-----------------------------------------\n"; - - std::string xmp_file(strtok(argv[1], ".") + std::string(".xmp")); - metadataFile.open(xmp_file.c_str(), ios::out); - - FITAG *tag = NULL; - FreeImage_GetMetadata(FIMD_XMP, dib, "XMLPacket", &tag); - if(tag) { - metadataFile << (char*)FreeImage_GetTagValue(tag); - } - - metadataFile.close(); - } - - - // Unload the bitmap - - FreeImage_Unload(dib); - - - // call this ONLY when linking with FreeImage as a static library -#ifdef FREEIMAGE_LIB - FreeImage_DeInitialise(); -#endif // FREEIMAGE_LIB - - return 0; -} - - - +// ========================================================== +// Simple metadata reader +// +// Design and implementation by +// - Hervé Drolon +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at own risk! +// ========================================================== + +// +// This example shows how to easily parse all metadata +// contained in a JPEG, TIFF or PNG image. +// Comments, Exif and IPTC/NAA metadata tags are written to a HTML file +// for later reading, and Adobe XMP XML packets are written +// in a file whose extension is '.xmp'. This file can be later +// processed using a XML parser. +// +// Metadata functions showed in this sample : +// FreeImage_GetMetadataCount, FreeImage_FindFirstMetadata, FreeImage_FindNextMetadata, +// FreeImage_FindCloseMetadata, FreeImage_TagToString, FreeImage_GetMetadata +// +// ========================================================== + +#include +#include +#include + +using namespace std; + +#include "FreeImage.h" + +// ---------------------------------------------------------- + +/** Generic image loader + @param lpszPathName Pointer to the full file name + @param flag Optional load flag constant + @return Returns the loaded dib if successful, returns NULL otherwise +*/ +FIBITMAP* GenericLoader(const char* lpszPathName, int flag) { + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + + // check the file signature and deduce its format + // (the second argument is currently not used by FreeImage) + fif = FreeImage_GetFileType(lpszPathName, 0); + if(fif == FIF_UNKNOWN) { + // no signature ? + // try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilename(lpszPathName); + } + // check that the plugin has reading capabilities ... + if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { + // ok, let's load the file + FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, flag); + // unless a bad file format, we are done ! + return dib; + } + return NULL; +} + +/** Generic image writer + @param dib Pointer to the dib to be saved + @param lpszPathName Pointer to the full file name + @param flag Optional save flag constant + @return Returns true if successful, returns false otherwise +*/ +bool GenericWriter(FIBITMAP* dib, const char* lpszPathName, int flag) { + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + BOOL bSuccess = FALSE; + + if(dib) { + // try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilename(lpszPathName); + if(fif != FIF_UNKNOWN ) { + // check that the plugin has sufficient writing and export capabilities ... + WORD bpp = FreeImage_GetBPP(dib); + if(FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)) { + // ok, we can save the file + bSuccess = FreeImage_Save(fif, dib, lpszPathName, flag); + // unless an abnormal bug, we are done ! + } + } + } + return (bSuccess == TRUE) ? true : false; +} + +// ---------------------------------------------------------- + +/** + FreeImage error handler + @param fif Format / Plugin responsible for the error + @param message Error message +*/ +void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) { + cout << "\n*** "; + if(fif != FIF_UNKNOWN) { + cout << FreeImage_GetFormatFromFIF(fif) << " Format\n"; + } + cout << message; + cout << " ***\n"; +} + +// ---------------------------------------------------------- + +/** +Print a basic HTML header +*/ +void PrintHTMLHeader(iostream& ios) { + ios << "\n\n
\n"; + ios << "\n"; +} + +/** +Print a HTML footer +*/ +void PrintHTMLFooter(iostream& ios) { + ios << "
\n\n\n\n"; +} + +/** +Print a table header +*/ +void PrintTableHeader(iostream& ios, const char *title) { + ios << "\n"; + ios << "\n"; +} + +/** +Print a table section +*/ +void PrintTableSection(iostream& ios, const char *title) { + ios << "\n"; + ios << ""; +} + +/** +Print a table footer +*/ +void PrintTableFooter(iostream& ios) { + ios << "
" << title << "
" << title << "
Tag nameTag valueDescription
\n"; +} + + +/** +Print the metadata tags to a HTML file +*/ +void PrintMetadata(iostream& ios, const char *sectionTitle, FIBITMAP *dib, FREE_IMAGE_MDMODEL model) { + FITAG *tag = NULL; + FIMETADATA *mdhandle = NULL; + + mdhandle = FreeImage_FindFirstMetadata(model, dib, &tag); + + if(mdhandle) { + // Print a table section + PrintTableSection(ios, sectionTitle); + + do { + // convert the tag value to a string + const char *value = FreeImage_TagToString(model, tag); + + // print the tag + // note that most tags do not have a description, + // especially when the metadata specifications are not available + if(FreeImage_GetTagDescription(tag)) { + ios << "" << FreeImage_GetTagKey(tag) << "" << value << "" << FreeImage_GetTagDescription(tag) << "\n"; + } else { + ios << "" << FreeImage_GetTagKey(tag) << "" << value << "" << " " << "\n"; + } + + } while(FreeImage_FindNextMetadata(mdhandle, &tag)); + } + + FreeImage_FindCloseMetadata(mdhandle); +} + +int +main(int argc, char *argv[]) { + unsigned count; + + // call this ONLY when linking with FreeImage as a static library +#ifdef FREEIMAGE_LIB + FreeImage_Initialise(); +#endif // FREEIMAGE_LIB + + // initialize your own FreeImage error handler + + FreeImage_SetOutputMessage(FreeImageErrorHandler); + + // print version & copyright infos + + cout << "FreeImage " << FreeImage_GetVersion() << "\n"; + cout << FreeImage_GetCopyrightMessage() << "\n\n"; + + if(argc != 2) { + cout << "Usage : ShowMetadata \n"; + return 0; + } + + // Load the bitmap + + FIBITMAP *dib = GenericLoader(argv[1], 0); + if(!dib) + return 0; + + // Create a HTML file + std::string html_file(strtok(argv[1], ".") + std::string(".html")); + + fstream metadataFile(html_file.c_str(), ios::out); + + // Print the header + + PrintHTMLHeader(metadataFile); + PrintTableHeader(metadataFile, argv[1]); + + // Parse and print metadata + + if(count = FreeImage_GetMetadataCount(FIMD_COMMENTS, dib)) { + cout << "\nFIMD_COMMENTS (" << count << " data)\n-----------------------------------------\n"; + + PrintMetadata(metadataFile, "Comments", dib, FIMD_COMMENTS); + } + if(count = FreeImage_GetMetadataCount(FIMD_EXIF_MAIN, dib)) { + cout << "\nFIMD_EXIF_MAIN (" << count << " data)\n-----------------------------------------\n"; + + PrintMetadata(metadataFile, "Exif - main info", dib, FIMD_EXIF_MAIN); + } + if(count = FreeImage_GetMetadataCount(FIMD_EXIF_EXIF, dib)) { + cout << "\nFIMD_EXIF_EXIF (" << count << " data)\n-----------------------------------------\n"; + + PrintMetadata(metadataFile, "Exif - advanced info", dib, FIMD_EXIF_EXIF); + } + if(count = FreeImage_GetMetadataCount(FIMD_EXIF_GPS, dib)) { + cout << "\nFIMD_EXIF_GPS (" << count << " data)\n-----------------------------------------\n"; + + PrintMetadata(metadataFile, "Exif GPS", dib, FIMD_EXIF_GPS); + } + if(count = FreeImage_GetMetadataCount(FIMD_EXIF_INTEROP, dib)) { + cout << "\nFIMD_EXIF_INTEROP (" << count << " data)\n-----------------------------------------\n"; + + PrintMetadata(metadataFile, "Exif interoperability", dib, FIMD_EXIF_INTEROP); + } + if(count = FreeImage_GetMetadataCount(FIMD_EXIF_MAKERNOTE, dib)) { + cout << "\nFIMD_EXIF_MAKERNOTE (" << count << " data)\n-----------------------------------------\n"; + + // Get the camera model + FITAG *tagMake = NULL; + FreeImage_GetMetadata(FIMD_EXIF_MAIN, dib, "Make", &tagMake); + + std::string buffer((char*)FreeImage_GetTagValue(tagMake)); + buffer += " Makernote"; + + PrintMetadata(metadataFile, buffer.c_str(), dib, FIMD_EXIF_MAKERNOTE); + } + if(count = FreeImage_GetMetadataCount(FIMD_IPTC, dib)) { + cout << "\nFIMD_IPTC (" << count << " data)\n-----------------------------------------\n"; + + PrintMetadata(metadataFile, "IPTC/NAA", dib, FIMD_IPTC); + } + if(count = FreeImage_GetMetadataCount(FIMD_GEOTIFF, dib)) { + cout << "\nFIMD_GEOTIFF (" << count << " data)\n-----------------------------------------\n"; + + PrintMetadata(metadataFile, "GEOTIFF", dib, FIMD_GEOTIFF); + } + + // Print the footer + + PrintTableFooter(metadataFile); + PrintHTMLFooter(metadataFile); + + // close the HTML file + + metadataFile.close(); + + // print XMP data + + if(count = FreeImage_GetMetadataCount(FIMD_XMP, dib)) { + cout << "\nFIMD_XMP (" << count << " packet)\n-----------------------------------------\n"; + + std::string xmp_file(strtok(argv[1], ".") + std::string(".xmp")); + metadataFile.open(xmp_file.c_str(), ios::out); + + FITAG *tag = NULL; + FreeImage_GetMetadata(FIMD_XMP, dib, "XMLPacket", &tag); + if(tag) { + metadataFile << (char*)FreeImage_GetTagValue(tag); + } + + metadataFile.close(); + } + + + // Unload the bitmap + + FreeImage_Unload(dib); + + + // call this ONLY when linking with FreeImage as a static library +#ifdef FREEIMAGE_LIB + FreeImage_DeInitialise(); +#endif // FREEIMAGE_LIB + + return 0; +} + + + diff --git a/Examples/Linux/Makefile b/Examples/Linux/Makefile index 768e784..3a9a26f 100644 --- a/Examples/Linux/Makefile +++ b/Examples/Linux/Makefile @@ -1,24 +1,24 @@ -CC = gcc -CPP = g++ -COMPILERFLAGS = -O3 -INCLUDE = -I../../Dist -VGALIBRARIES = -lfreeimage -lvga -VGAINCLUDE = -I/usr/include/asm -GTKLIBRARIES = -lfreeimage `pkg-config --libs gtk+-2.0` -GTKINCLUDE = `pkg-config --cflags gtk+-2.0` -CFLAGS = $(COMPILERFLAGS) $(INCLUDE) - -all: default - -default: linux-svgalib linux-gtk - -linux-svgalib: linux-svgalib.c - $(CC) $(CFLAGS) $< -o $@ $(VGALIBRARIES) $(VGAINCLUDE) - strip $@ - -linux-gtk: linux-gtk.c - $(CC) $(CFLAGS) $< -o $@ $(GTKLIBRARIES) $(GTKINCLUDE) - strip $@ - -clean: - rm -f core linux-svgalib linux-gtk +CC = gcc +CPP = g++ +COMPILERFLAGS = -O3 +INCLUDE = -I../../Dist +VGALIBRARIES = -lfreeimage -lvga +VGAINCLUDE = -I/usr/include/asm +GTKLIBRARIES = -lfreeimage `pkg-config --libs gtk+-2.0` +GTKINCLUDE = `pkg-config --cflags gtk+-2.0` +CFLAGS = $(COMPILERFLAGS) $(INCLUDE) + +all: default + +default: linux-svgalib linux-gtk + +linux-svgalib: linux-svgalib.c + $(CC) $(CFLAGS) $< -o $@ $(VGALIBRARIES) $(VGAINCLUDE) + strip $@ + +linux-gtk: linux-gtk.c + $(CC) $(CFLAGS) $< -o $@ $(GTKLIBRARIES) $(GTKINCLUDE) + strip $@ + +clean: + rm -f core linux-svgalib linux-gtk diff --git a/Examples/Linux/linux-gtk.c b/Examples/Linux/linux-gtk.c index e5cf51f..a8336fb 100644 --- a/Examples/Linux/linux-gtk.c +++ b/Examples/Linux/linux-gtk.c @@ -1,100 +1,100 @@ -#include -#include -#include - -void destroy(GtkWidget * widget, gpointer data) { - gtk_main_quit(); -} - -int main(int argc, char *argv[]) -{ - GtkWidget *window, *imagebox; - GdkVisual *visual; - GdkImage *image; - FIBITMAP *dib; - int y; - - // initialize the FreeImage library - FreeImage_Initialise(TRUE); - - dib = FreeImage_Load(FIF_PNG, "freeimage.png", PNG_DEFAULT); - - gtk_init(&argc, &argv); - - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - gtk_signal_connect(GTK_OBJECT(window), "destroy", - GTK_SIGNAL_FUNC(destroy), NULL); - - visual = gdk_visual_get_system(); - - image = gdk_image_new(GDK_IMAGE_NORMAL,visual, - FreeImage_GetWidth(dib),FreeImage_GetHeight(dib)); - - g_print("picture: %d bpp\n" - "system: %d bpp byteorder: %d\n" - " redbits: %d greenbits: %d bluebits: %d\n" - "image: %d bpp %d bytes/pixel\n", - FreeImage_GetBPP(dib), - visual->depth,visual->byte_order, - visual->red_prec,visual->green_prec,visual->blue_prec, - image->depth,image->bpp ); - - if (FreeImage_GetBPP(dib) != (image->bpp << 3)) { - FIBITMAP *ptr; - - switch (image->bpp) { - case 1: - ptr = FreeImage_ConvertTo8Bits(dib); - break; - - case 2: - if (image->depth == 15) { - ptr = FreeImage_ConvertTo16Bits555(dib); - } else { - ptr = FreeImage_ConvertTo16Bits565(dib); - } - - break; - case 3: - ptr = FreeImage_ConvertTo24Bits(dib); - break; - - default: - case 4: - ptr = FreeImage_ConvertTo32Bits(dib); - break; - } - - FreeImage_Unload(dib); - dib = ptr; - } - -//makes it upside down :( -// memcpy(image->mem, FreeImage_GetBits(dib), image->bpl * image->height); - - BYTE *ptr = FreeImage_GetBits(dib); - - for (y = 0; y < image->height; y++) { - memcpy(image->mem + (y * image->bpl), - ptr + ((image->height - y - 1) * image->bpl), - image->bpl); - } - - FreeImage_Unload(dib); - - imagebox = gtk_image_new_from_image(image, NULL); - gtk_container_add(GTK_CONTAINER(window), imagebox); - - gtk_widget_show(imagebox); - gtk_widget_show(window); - - gtk_main(); - - // release the FreeImage library - FreeImage_DeInitialise(); - - return 0; -} - - +#include +#include +#include + +void destroy(GtkWidget * widget, gpointer data) { + gtk_main_quit(); +} + +int main(int argc, char *argv[]) +{ + GtkWidget *window, *imagebox; + GdkVisual *visual; + GdkImage *image; + FIBITMAP *dib; + int y; + + // initialize the FreeImage library + FreeImage_Initialise(TRUE); + + dib = FreeImage_Load(FIF_PNG, "freeimage.png", PNG_DEFAULT); + + gtk_init(&argc, &argv); + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + gtk_signal_connect(GTK_OBJECT(window), "destroy", + GTK_SIGNAL_FUNC(destroy), NULL); + + visual = gdk_visual_get_system(); + + image = gdk_image_new(GDK_IMAGE_NORMAL,visual, + FreeImage_GetWidth(dib),FreeImage_GetHeight(dib)); + + g_print("picture: %d bpp\n" + "system: %d bpp byteorder: %d\n" + " redbits: %d greenbits: %d bluebits: %d\n" + "image: %d bpp %d bytes/pixel\n", + FreeImage_GetBPP(dib), + visual->depth,visual->byte_order, + visual->red_prec,visual->green_prec,visual->blue_prec, + image->depth,image->bpp ); + + if (FreeImage_GetBPP(dib) != (image->bpp << 3)) { + FIBITMAP *ptr; + + switch (image->bpp) { + case 1: + ptr = FreeImage_ConvertTo8Bits(dib); + break; + + case 2: + if (image->depth == 15) { + ptr = FreeImage_ConvertTo16Bits555(dib); + } else { + ptr = FreeImage_ConvertTo16Bits565(dib); + } + + break; + case 3: + ptr = FreeImage_ConvertTo24Bits(dib); + break; + + default: + case 4: + ptr = FreeImage_ConvertTo32Bits(dib); + break; + } + + FreeImage_Unload(dib); + dib = ptr; + } + +//makes it upside down :( +// memcpy(image->mem, FreeImage_GetBits(dib), image->bpl * image->height); + + BYTE *ptr = FreeImage_GetBits(dib); + + for (y = 0; y < image->height; y++) { + memcpy(image->mem + (y * image->bpl), + ptr + ((image->height - y - 1) * image->bpl), + image->bpl); + } + + FreeImage_Unload(dib); + + imagebox = gtk_image_new_from_image(image, NULL); + gtk_container_add(GTK_CONTAINER(window), imagebox); + + gtk_widget_show(imagebox); + gtk_widget_show(window); + + gtk_main(); + + // release the FreeImage library + FreeImage_DeInitialise(); + + return 0; +} + + diff --git a/Examples/Linux/linux-svgalib.c b/Examples/Linux/linux-svgalib.c index 159a238..f0eb68c 100644 --- a/Examples/Linux/linux-svgalib.c +++ b/Examples/Linux/linux-svgalib.c @@ -1,96 +1,96 @@ -#include -#include "FreeImage.h" - -int main(void) -{ - FIBITMAP *dib,*ptr; - vga_modeinfo *inf; - int length,height,bpp,y; - - // initialize the FreeImage library - FreeImage_Initialise(); - - dib = FreeImage_Load(FIF_PNG, "freeimage.png", PNG_DEFAULT); - - vga_init(); - vga_setmode(vga_getdefaultmode()); - - inf = vga_getmodeinfo(vga_getcurrentmode()); - - switch(inf->colors) { - default: - printf("Must be at least 256 color mode!\n"); - return; - - case 1 << 8: - bpp = 8; - break; - - case 1 << 15: - bpp = 15; - break; - - case 1 << 16: - bpp = 16; - break; - - case 1 << 24: - if( inf->bytesperpixel == 3 ) { - bpp = 24; - } else { - bpp = 32; - } - break; - } - - if(FreeImage_GetBPP(dib) != bpp) { - switch(bpp) { - case 8: - ptr = FreeImage_ConvertTo8Bits(dib); - break; - - case 15: - ptr = FreeImage_ConvertTo16Bits555(dib); - break; - - case 16: - ptr = FreeImage_ConvertTo16Bits565(dib); - break; - - case 24: - ptr = FreeImage_ConvertTo24Bits(dib); - break; - - default: - case 32: - ptr = FreeImage_ConvertTo32Bits(dib); - break; - } - - FreeImage_Unload(dib); - dib = ptr; - } - - length = FreeImage_GetWidth(dib); - if( inf->width < length ) { - length = inf->width; - } - height = FreeImage_GetHeight(dib); - if( inf->height < height ) { - height = inf->height; - } - - for(y = 0; y < height; y++) { - vga_drawscansegment(FreeImage_GetScanLine(dib, y), 0, y, length); - } - - FreeImage_Unload(dib); - - vga_getch(); - vga_setmode(TEXT); - - // release the FreeImage library - FreeImage_DeInitialise(); - - return 0; -} +#include +#include "FreeImage.h" + +int main(void) +{ + FIBITMAP *dib,*ptr; + vga_modeinfo *inf; + int length,height,bpp,y; + + // initialize the FreeImage library + FreeImage_Initialise(); + + dib = FreeImage_Load(FIF_PNG, "freeimage.png", PNG_DEFAULT); + + vga_init(); + vga_setmode(vga_getdefaultmode()); + + inf = vga_getmodeinfo(vga_getcurrentmode()); + + switch(inf->colors) { + default: + printf("Must be at least 256 color mode!\n"); + return; + + case 1 << 8: + bpp = 8; + break; + + case 1 << 15: + bpp = 15; + break; + + case 1 << 16: + bpp = 16; + break; + + case 1 << 24: + if( inf->bytesperpixel == 3 ) { + bpp = 24; + } else { + bpp = 32; + } + break; + } + + if(FreeImage_GetBPP(dib) != bpp) { + switch(bpp) { + case 8: + ptr = FreeImage_ConvertTo8Bits(dib); + break; + + case 15: + ptr = FreeImage_ConvertTo16Bits555(dib); + break; + + case 16: + ptr = FreeImage_ConvertTo16Bits565(dib); + break; + + case 24: + ptr = FreeImage_ConvertTo24Bits(dib); + break; + + default: + case 32: + ptr = FreeImage_ConvertTo32Bits(dib); + break; + } + + FreeImage_Unload(dib); + dib = ptr; + } + + length = FreeImage_GetWidth(dib); + if( inf->width < length ) { + length = inf->width; + } + height = FreeImage_GetHeight(dib); + if( inf->height < height ) { + height = inf->height; + } + + for(y = 0; y < height; y++) { + vga_drawscansegment(FreeImage_GetScanLine(dib, y), 0, y, length); + } + + FreeImage_Unload(dib); + + vga_getch(); + vga_setmode(TEXT); + + // release the FreeImage library + FreeImage_DeInitialise(); + + return 0; +} diff --git a/Examples/OpenGL/TextureManager/TextureManager.cpp b/Examples/OpenGL/TextureManager/TextureManager.cpp index dfc0ed9..cbd69a0 100644 --- a/Examples/OpenGL/TextureManager/TextureManager.cpp +++ b/Examples/OpenGL/TextureManager/TextureManager.cpp @@ -1,145 +1,145 @@ -//********************************************** -//Singleton Texture Manager class -//Written by Ben English -//benjamin.english@oit.edu -// -//For use with OpenGL and the FreeImage library -//********************************************** - -#include "TextureManager.h" - -TextureManager* TextureManager::m_inst(0); - -TextureManager* TextureManager::Inst() -{ - if(!m_inst) - m_inst = new TextureManager(); - - return m_inst; -} - -TextureManager::TextureManager() -{ - // call this ONLY when linking with FreeImage as a static library - #ifdef FREEIMAGE_LIB - FreeImage_Initialise(); - #endif -} - -//these should never be called -//TextureManager::TextureManager(const TextureManager& tm){} -//TextureManager& TextureManager::operator=(const TextureManager& tm){} - -TextureManager::~TextureManager() -{ - // call this ONLY when linking with FreeImage as a static library - #ifdef FREEIMAGE_LIB - FreeImage_DeInitialise(); - #endif - - UnloadAllTextures(); - m_inst = 0; -} - -bool TextureManager::LoadTexture(const char* filename, const unsigned int texID, GLenum image_format, GLint internal_format, GLint level, GLint border) -{ - //image format - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - //pointer to the image, once loaded - FIBITMAP *dib(0); - //pointer to the image data - BYTE* bits(0); - //image width and height - unsigned int width(0), height(0); - //OpenGL's image ID to map to - GLuint gl_texID; - - //check the file signature and deduce its format - fif = FreeImage_GetFileType(filename, 0); - //if still unknown, try to guess the file format from the file extension - if(fif == FIF_UNKNOWN) - fif = FreeImage_GetFIFFromFilename(filename); - //if still unkown, return failure - if(fif == FIF_UNKNOWN) - return false; - - //check that the plugin has reading capabilities and load the file - if(FreeImage_FIFSupportsReading(fif)) - dib = FreeImage_Load(fif, filename); - //if the image failed to load, return failure - if(!dib) - return false; - - //retrieve the image data - bits = FreeImage_GetBits(dib); - //get the image width and height - width = FreeImage_GetWidth(dib); - height = FreeImage_GetHeight(dib); - //if this somehow one of these failed (they shouldn't), return failure - if((bits == 0) || (width == 0) || (height == 0)) - return false; - - //if this texture ID is in use, unload the current texture - if(m_texID.find(texID) != m_texID.end()) - glDeleteTextures(1, &(m_texID[texID])); - - //generate an OpenGL texture ID for this texture - glGenTextures(1, &gl_texID); - //store the texture ID mapping - m_texID[texID] = gl_texID; - //bind to the new texture ID - glBindTexture(GL_TEXTURE_2D, gl_texID); - //store the texture data for OpenGL use - glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height, - border, image_format, GL_UNSIGNED_BYTE, bits); - - //Free FreeImage's copy of the data - FreeImage_Unload(dib); - - //return success - return true; -} - -bool TextureManager::UnloadTexture(const unsigned int texID) -{ - bool result(true); - //if this texture ID mapped, unload it's texture, and remove it from the map - if(m_texID.find(texID) != m_texID.end()) - { - glDeleteTextures(1, &(m_texID[texID])); - m_texID.erase(texID); - } - //otherwise, unload failed - else - { - result = false; - } - - return result; -} - -bool TextureManager::BindTexture(const unsigned int texID) -{ - bool result(true); - //if this texture ID mapped, bind it's texture as current - if(m_texID.find(texID) != m_texID.end()) - glBindTexture(GL_TEXTURE_2D, m_texID[texID]); - //otherwise, binding failed - else - result = false; - - return result; -} - -void TextureManager::UnloadAllTextures() -{ - //start at the begginning of the texture map - std::map::iterator i = m_texID.begin(); - - //Unload the textures untill the end of the texture map is found - while(i != m_texID.end()) - UnloadTexture(i->first); - - //clear the texture map - m_texID.clear(); +//********************************************** +//Singleton Texture Manager class +//Written by Ben English +//benjamin.english@oit.edu +// +//For use with OpenGL and the FreeImage library +//********************************************** + +#include "TextureManager.h" + +TextureManager* TextureManager::m_inst(0); + +TextureManager* TextureManager::Inst() +{ + if(!m_inst) + m_inst = new TextureManager(); + + return m_inst; +} + +TextureManager::TextureManager() +{ + // call this ONLY when linking with FreeImage as a static library + #ifdef FREEIMAGE_LIB + FreeImage_Initialise(); + #endif +} + +//these should never be called +//TextureManager::TextureManager(const TextureManager& tm){} +//TextureManager& TextureManager::operator=(const TextureManager& tm){} + +TextureManager::~TextureManager() +{ + // call this ONLY when linking with FreeImage as a static library + #ifdef FREEIMAGE_LIB + FreeImage_DeInitialise(); + #endif + + UnloadAllTextures(); + m_inst = 0; +} + +bool TextureManager::LoadTexture(const char* filename, const unsigned int texID, GLenum image_format, GLint internal_format, GLint level, GLint border) +{ + //image format + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + //pointer to the image, once loaded + FIBITMAP *dib(0); + //pointer to the image data + BYTE* bits(0); + //image width and height + unsigned int width(0), height(0); + //OpenGL's image ID to map to + GLuint gl_texID; + + //check the file signature and deduce its format + fif = FreeImage_GetFileType(filename, 0); + //if still unknown, try to guess the file format from the file extension + if(fif == FIF_UNKNOWN) + fif = FreeImage_GetFIFFromFilename(filename); + //if still unkown, return failure + if(fif == FIF_UNKNOWN) + return false; + + //check that the plugin has reading capabilities and load the file + if(FreeImage_FIFSupportsReading(fif)) + dib = FreeImage_Load(fif, filename); + //if the image failed to load, return failure + if(!dib) + return false; + + //retrieve the image data + bits = FreeImage_GetBits(dib); + //get the image width and height + width = FreeImage_GetWidth(dib); + height = FreeImage_GetHeight(dib); + //if this somehow one of these failed (they shouldn't), return failure + if((bits == 0) || (width == 0) || (height == 0)) + return false; + + //if this texture ID is in use, unload the current texture + if(m_texID.find(texID) != m_texID.end()) + glDeleteTextures(1, &(m_texID[texID])); + + //generate an OpenGL texture ID for this texture + glGenTextures(1, &gl_texID); + //store the texture ID mapping + m_texID[texID] = gl_texID; + //bind to the new texture ID + glBindTexture(GL_TEXTURE_2D, gl_texID); + //store the texture data for OpenGL use + glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height, + border, image_format, GL_UNSIGNED_BYTE, bits); + + //Free FreeImage's copy of the data + FreeImage_Unload(dib); + + //return success + return true; +} + +bool TextureManager::UnloadTexture(const unsigned int texID) +{ + bool result(true); + //if this texture ID mapped, unload it's texture, and remove it from the map + if(m_texID.find(texID) != m_texID.end()) + { + glDeleteTextures(1, &(m_texID[texID])); + m_texID.erase(texID); + } + //otherwise, unload failed + else + { + result = false; + } + + return result; +} + +bool TextureManager::BindTexture(const unsigned int texID) +{ + bool result(true); + //if this texture ID mapped, bind it's texture as current + if(m_texID.find(texID) != m_texID.end()) + glBindTexture(GL_TEXTURE_2D, m_texID[texID]); + //otherwise, binding failed + else + result = false; + + return result; +} + +void TextureManager::UnloadAllTextures() +{ + //start at the begginning of the texture map + std::map::iterator i = m_texID.begin(); + + //Unload the textures untill the end of the texture map is found + while(i != m_texID.end()) + UnloadTexture(i->first); + + //clear the texture map + m_texID.clear(); } \ No newline at end of file diff --git a/Examples/OpenGL/TextureManager/readme.txt b/Examples/OpenGL/TextureManager/readme.txt index 7930599..9cbd7f7 100644 --- a/Examples/OpenGL/TextureManager/readme.txt +++ b/Examples/OpenGL/TextureManager/readme.txt @@ -1,31 +1,31 @@ -Hello everyone, this is my 2D texture manager class for OpenGL using the FreeImage Library. - -Requirements: --------------------- -OpenGL -STL map class -FreeImage (included) - - -Usage --------------------- -To load a texture, simply call the LoadTexture function: - -TextureManager::Inst()->LoadTexture("img\\bg.jpg", BACKGROUND_IMAGE_ID); - -This also binds the loaded texture as the current texture, so after calling it you may make any calls to glTexParameter you may need to specify the properties of the texture. - -When you are rendering, just call the TextureManager's BindImage function instead of glBindImage: - -TextureManager::Inst()->BindImage(BACKGROUND_IMAGE_ID); - -and then do your rendering as normal. --------------------- - - -Feel free to distribute this as you like, but mind the FreeImage licence included in license-fi.txt, and please don't take credit for my code. If you modify it, be sure to mention me (Ben English) somewhere. - -Please send any comments or suggestions to me at benjamin.english@oit.edu - - +Hello everyone, this is my 2D texture manager class for OpenGL using the FreeImage Library. + +Requirements: +-------------------- +OpenGL +STL map class +FreeImage (included) + + +Usage +-------------------- +To load a texture, simply call the LoadTexture function: + +TextureManager::Inst()->LoadTexture("img\\bg.jpg", BACKGROUND_IMAGE_ID); + +This also binds the loaded texture as the current texture, so after calling it you may make any calls to glTexParameter you may need to specify the properties of the texture. + +When you are rendering, just call the TextureManager's BindImage function instead of glBindImage: + +TextureManager::Inst()->BindImage(BACKGROUND_IMAGE_ID); + +and then do your rendering as normal. +-------------------- + + +Feel free to distribute this as you like, but mind the FreeImage licence included in license-fi.txt, and please don't take credit for my code. If you modify it, be sure to mention me (Ben English) somewhere. + +Please send any comments or suggestions to me at benjamin.english@oit.edu + + Thanks to Herve Drolon for the FreeImage library, I've found it to be very useful! \ No newline at end of file diff --git a/Examples/Plugin/PluginCradle.cpp b/Examples/Plugin/PluginCradle.cpp index 10c363d..5dcdbd0 100644 --- a/Examples/Plugin/PluginCradle.cpp +++ b/Examples/Plugin/PluginCradle.cpp @@ -1,253 +1,253 @@ -// ========================================================== -// Loader/Saver Plugin Cradle -// -// Design and implementation by -// - Floris van den Berg (flvdberg@wxs.nl) -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include -#include - -#include "FreeImage.h" -#include "Utilities.h" - -// ========================================================== - -BOOL APIENTRY -DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { - switch (ul_reason_for_call) { - case DLL_PROCESS_ATTACH : - case DLL_PROCESS_DETACH : - case DLL_THREAD_ATTACH : - case DLL_THREAD_DETACH : - break; - } - - return TRUE; -} - -// ========================================================== -// Plugin Interface -// ========================================================== - -static int s_format_id; - -// ========================================================== -// Plugin Implementation -// ========================================================== - -/** - Returns the format string for the plugin. Each plugin, - both internal in the DLL and external in a .fip file, must have - a unique format string to be addressable. -*/ - -static const char * DLL_CALLCONV -Format() { - return "CRADLE"; -} - -/** - Returns a description string for the plugin. Though a - description is not necessary per-se, - it is advised to return an unique string in order to tell the - user what type of bitmaps this plugin will read and/or write. -*/ - -static const char * DLL_CALLCONV -Description() { - return "Here comes the description for your image loader/saver"; -} - -/** - Returns a comma separated list of file extensions indicating - what files this plugin can open. no spaces or whatsoever are allowed. - The list, being used by FreeImage_GetFIFFromFilename, is usually - used as a last resort in finding the type of the bitmap we - are dealing with. Best is to check the first few bytes on - the low-level bits level first and compare them with a known - signature . If this fails, FreeImage_GetFIFFromFilename can be - used. -*/ - -static const char * DLL_CALLCONV -Extension() { - return "ext1,ext2"; -} - -/** - RegExpr is only needed for the Qt wrapper - It allows the Qt mechanism for loading bitmaps to identify the bitmap -*/ -static const char * DLL_CALLCONV -RegExpr() { - return NULL; -} - -/** - Returns a MIME content type string for that format (MIME stands - for Multipurpose Internet Mail Extension). -*/ -static const char * DLL_CALLCONV -MimeType() { - return "image/myformat"; -} - -/** - FreeImage's internal way of seeing if a bitmap is of the desired type. - When the type of a bitmap is to be retrieved, FreeImage runs Validate - for each registered plugin until one returns true. If a plugin doesn't - have a validate function, a return value of false is assumed. - - You can always force to use a particular plugin by directly specifying - it on the command line, but this can result in a dead DLL if the plugin - was not made for the bitmap. -*/ -static BOOL DLL_CALLCONV -Validate(FreeImageIO &io, fi_handle handle) { - return FALSE; -} - -/** - SupportsExportDepth is the first in a possible range of new plugin functions - to ask specific information to that plugin. This function returns TRUE if it - can save a bitmap in the required bitdepth. If it can't the bitmap has to be - converted by the user or another plugin has to be chosen. -*/ -static BOOL DLL_CALLCONV -SupportsExportDepth(int depth) { - return FALSE; -} - -/** - Returns TRUE if the plugin belonging to the given FREE_IMAGE_FORMAT can save a - bitmap in the desired data type, returns FALSE otherwise. Currently, TIFF is the only plugin - able to save all non-standard images. The PNG plugin is able to save unsigned 16-bit - images. -*/ -static BOOL DLL_CALLCONV -SupportsExportType(FREE_IMAGE_TYPE type) { - return (type == FIT_BITMAP) ? TRUE : FALSE; -} - -/** - SupportsICCProfiles informs FreeImage that a plugin supports ICC profiles. - This function returns TRUE if the plugin can load and save a profile. - ICC profile information is accessed via freeimage->get_icc_profile_proc(dib) -*/ -static BOOL DLL_CALLCONV -SupportsICCProfiles() { - return FALSE; -} - - -// ---------------------------------------------------------- - -/** - Loads a bitmap into memory. On entry it is assumed that - the bitmap to be loaded is of the correct type. If the bitmap - is of an incorrect type, the plugin might not gracefully fail but - crash or enter an endless loop. It is also assumed that all - the bitmap data is available at one time. If the bitmap is not complete, - for example because it is being downloaded while loaded, the plugin - might also not gracefully fail. - - The Load function has the following parameters: - - The first parameter (FreeImageIO *io) is a structure providing - function pointers in order to make use of FreeImage's IO redirection. Using - FreeImage's file i/o functions instead of standard ones it is garantueed - that all bitmap types, both current and future ones, can be loaded from - memory, file cabinets, the internet and more. The second parameter (fi_handle handle) - is a companion of FreeImageIO and can be best compared with the standard FILE* type, - in a generalized form. - - The third parameter (int page) indicates wether we will be loading a certain page - in the bitmap or if we will load the default one. This parameter is only used if - the plugin supports multi-paged bitmaps, e.g. cabinet bitmaps that contain a series - of images or pages. If the plugin does support multi-paging, the page parameter - can contain either a number higher or equal to 0 to load a certain page, or -1 to - load the default page. If the plugin does not support multi-paging, - the page parameter is always -1. - - The fourth parameter (int flags) manipulates the load function to load a bitmap - in a certain way. Every plugin has a different flag parameter with different meanings. - - The last parameter (void *data) can contain a special data block used when - the file is read multi-paged. Because not every plugin supports multi-paging - not every plugin will use the data parameter and it will be set to NULL.However, - when the plugin does support multi-paging the parameter contains a pointer to a - block of data allocated by the Open function. -*/ - -static FIBITMAP * DLL_CALLCONV -Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { - return NULL; -} - -static BOOL DLL_CALLCONV -Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) { - return FALSE; -} - -// ========================================================== -// Init -// ========================================================== - -/** - Initialises the plugin. The first parameter (Plugin *plugin) - contains a pointer to a pre-allocated Plugin structure - wherein pointers to the available plugin functions - has to be stored. The second parameter (int format_id) is an identification - number that the plugin may use to show plugin specific warning messages - or other information to the user. The plugin number - is generated by FreeImage and can differ everytime the plugin is - initialised. - - If you want to create your own plugin you have to take some - rules into account. Plugin functions have to be compiled - __stdcall using the multithreaded c runtime libraries. Throwing - exceptions in plugin functions is allowed, as long as those exceptions - are being caught inside the same plugin. It is forbidden for a plugin - function to directly call FreeImage functions or to allocate memory - and pass it to the main DLL. Exception to this rule is the special file data - block that may be allocated the Open function. Allocating a FIBITMAP inside a - plugin can be using the function allocate_proc in the FreeImage structure, - which will allocate the memory using the DLL's c runtime library. -*/ - -void DLL_CALLCONV -Init(Plugin *plugin, int format_id) { - s_format_id = format_id; - - plugin->format_proc = Format; - plugin->description_proc = Description; - plugin->extension_proc = Extension; - plugin->regexpr_proc = RegExpr; - plugin->open_proc = NULL; - plugin->close_proc = NULL; - plugin->pagecount_proc = NULL; - plugin->pagecapability_proc = NULL; - plugin->load_proc = Load; - plugin->save_proc = Save; - plugin->validate_proc = Validate; - plugin->mime_proc = MimeType; - plugin->supports_export_bpp_proc = SupportsExportDepth; - plugin->supports_export_type_proc = SupportsExportType; - plugin->supports_icc_profiles_proc = SupportsICCProfiles; -} +// ========================================================== +// Loader/Saver Plugin Cradle +// +// Design and implementation by +// - Floris van den Berg (flvdberg@wxs.nl) +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include +#include + +#include "FreeImage.h" +#include "Utilities.h" + +// ========================================================== + +BOOL APIENTRY +DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { + switch (ul_reason_for_call) { + case DLL_PROCESS_ATTACH : + case DLL_PROCESS_DETACH : + case DLL_THREAD_ATTACH : + case DLL_THREAD_DETACH : + break; + } + + return TRUE; +} + +// ========================================================== +// Plugin Interface +// ========================================================== + +static int s_format_id; + +// ========================================================== +// Plugin Implementation +// ========================================================== + +/** + Returns the format string for the plugin. Each plugin, + both internal in the DLL and external in a .fip file, must have + a unique format string to be addressable. +*/ + +static const char * DLL_CALLCONV +Format() { + return "CRADLE"; +} + +/** + Returns a description string for the plugin. Though a + description is not necessary per-se, + it is advised to return an unique string in order to tell the + user what type of bitmaps this plugin will read and/or write. +*/ + +static const char * DLL_CALLCONV +Description() { + return "Here comes the description for your image loader/saver"; +} + +/** + Returns a comma separated list of file extensions indicating + what files this plugin can open. no spaces or whatsoever are allowed. + The list, being used by FreeImage_GetFIFFromFilename, is usually + used as a last resort in finding the type of the bitmap we + are dealing with. Best is to check the first few bytes on + the low-level bits level first and compare them with a known + signature . If this fails, FreeImage_GetFIFFromFilename can be + used. +*/ + +static const char * DLL_CALLCONV +Extension() { + return "ext1,ext2"; +} + +/** + RegExpr is only needed for the Qt wrapper + It allows the Qt mechanism for loading bitmaps to identify the bitmap +*/ +static const char * DLL_CALLCONV +RegExpr() { + return NULL; +} + +/** + Returns a MIME content type string for that format (MIME stands + for Multipurpose Internet Mail Extension). +*/ +static const char * DLL_CALLCONV +MimeType() { + return "image/myformat"; +} + +/** + FreeImage's internal way of seeing if a bitmap is of the desired type. + When the type of a bitmap is to be retrieved, FreeImage runs Validate + for each registered plugin until one returns true. If a plugin doesn't + have a validate function, a return value of false is assumed. + + You can always force to use a particular plugin by directly specifying + it on the command line, but this can result in a dead DLL if the plugin + was not made for the bitmap. +*/ +static BOOL DLL_CALLCONV +Validate(FreeImageIO &io, fi_handle handle) { + return FALSE; +} + +/** + SupportsExportDepth is the first in a possible range of new plugin functions + to ask specific information to that plugin. This function returns TRUE if it + can save a bitmap in the required bitdepth. If it can't the bitmap has to be + converted by the user or another plugin has to be chosen. +*/ +static BOOL DLL_CALLCONV +SupportsExportDepth(int depth) { + return FALSE; +} + +/** + Returns TRUE if the plugin belonging to the given FREE_IMAGE_FORMAT can save a + bitmap in the desired data type, returns FALSE otherwise. Currently, TIFF is the only plugin + able to save all non-standard images. The PNG plugin is able to save unsigned 16-bit + images. +*/ +static BOOL DLL_CALLCONV +SupportsExportType(FREE_IMAGE_TYPE type) { + return (type == FIT_BITMAP) ? TRUE : FALSE; +} + +/** + SupportsICCProfiles informs FreeImage that a plugin supports ICC profiles. + This function returns TRUE if the plugin can load and save a profile. + ICC profile information is accessed via freeimage->get_icc_profile_proc(dib) +*/ +static BOOL DLL_CALLCONV +SupportsICCProfiles() { + return FALSE; +} + + +// ---------------------------------------------------------- + +/** + Loads a bitmap into memory. On entry it is assumed that + the bitmap to be loaded is of the correct type. If the bitmap + is of an incorrect type, the plugin might not gracefully fail but + crash or enter an endless loop. It is also assumed that all + the bitmap data is available at one time. If the bitmap is not complete, + for example because it is being downloaded while loaded, the plugin + might also not gracefully fail. + + The Load function has the following parameters: + + The first parameter (FreeImageIO *io) is a structure providing + function pointers in order to make use of FreeImage's IO redirection. Using + FreeImage's file i/o functions instead of standard ones it is garantueed + that all bitmap types, both current and future ones, can be loaded from + memory, file cabinets, the internet and more. The second parameter (fi_handle handle) + is a companion of FreeImageIO and can be best compared with the standard FILE* type, + in a generalized form. + + The third parameter (int page) indicates wether we will be loading a certain page + in the bitmap or if we will load the default one. This parameter is only used if + the plugin supports multi-paged bitmaps, e.g. cabinet bitmaps that contain a series + of images or pages. If the plugin does support multi-paging, the page parameter + can contain either a number higher or equal to 0 to load a certain page, or -1 to + load the default page. If the plugin does not support multi-paging, + the page parameter is always -1. + + The fourth parameter (int flags) manipulates the load function to load a bitmap + in a certain way. Every plugin has a different flag parameter with different meanings. + + The last parameter (void *data) can contain a special data block used when + the file is read multi-paged. Because not every plugin supports multi-paging + not every plugin will use the data parameter and it will be set to NULL.However, + when the plugin does support multi-paging the parameter contains a pointer to a + block of data allocated by the Open function. +*/ + +static FIBITMAP * DLL_CALLCONV +Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { + return NULL; +} + +static BOOL DLL_CALLCONV +Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) { + return FALSE; +} + +// ========================================================== +// Init +// ========================================================== + +/** + Initialises the plugin. The first parameter (Plugin *plugin) + contains a pointer to a pre-allocated Plugin structure + wherein pointers to the available plugin functions + has to be stored. The second parameter (int format_id) is an identification + number that the plugin may use to show plugin specific warning messages + or other information to the user. The plugin number + is generated by FreeImage and can differ everytime the plugin is + initialised. + + If you want to create your own plugin you have to take some + rules into account. Plugin functions have to be compiled + __stdcall using the multithreaded c runtime libraries. Throwing + exceptions in plugin functions is allowed, as long as those exceptions + are being caught inside the same plugin. It is forbidden for a plugin + function to directly call FreeImage functions or to allocate memory + and pass it to the main DLL. Exception to this rule is the special file data + block that may be allocated the Open function. Allocating a FIBITMAP inside a + plugin can be using the function allocate_proc in the FreeImage structure, + which will allocate the memory using the DLL's c runtime library. +*/ + +void DLL_CALLCONV +Init(Plugin *plugin, int format_id) { + s_format_id = format_id; + + plugin->format_proc = Format; + plugin->description_proc = Description; + plugin->extension_proc = Extension; + plugin->regexpr_proc = RegExpr; + plugin->open_proc = NULL; + plugin->close_proc = NULL; + plugin->pagecount_proc = NULL; + plugin->pagecapability_proc = NULL; + plugin->load_proc = Load; + plugin->save_proc = Save; + plugin->validate_proc = Validate; + plugin->mime_proc = MimeType; + plugin->supports_export_bpp_proc = SupportsExportDepth; + plugin->supports_export_type_proc = SupportsExportType; + plugin->supports_icc_profiles_proc = SupportsICCProfiles; +} diff --git a/Makefile b/Makefile index f441168..4e11423 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +1,34 @@ -# Entry point for FreeImage makefiles -# Default to 'make -f Makefile.gnu' for Linux and for unknown OS. -# -OS = $(shell uname) -MAKEFILE = gnu - -ifeq ($(OS), Darwin) - MAKEFILE = osx -endif -ifeq ($(OS), Cygwin) - MAKEFILE = cygwin -endif -ifeq ($(OS), Solaris) - MAKEFILE = solaris -endif -ifeq ($(OS), windows32) - MAKEFILE = mingw -endif - -default: - $(MAKE) -f Makefile.$(MAKEFILE) - -all: - $(MAKE) -f Makefile.$(MAKEFILE) all - -dist: - $(MAKE) -f Makefile.$(MAKEFILE) dist - -install: - $(MAKE) -f Makefile.$(MAKEFILE) install - -clean: - $(MAKE) -f Makefile.$(MAKEFILE) clean - +# Entry point for FreeImage makefiles +# Default to 'make -f Makefile.gnu' for Linux and for unknown OS. +# +OS = $(shell uname) +MAKEFILE = gnu + +ifeq ($(OS), Darwin) + MAKEFILE = osx +endif +ifeq ($(OS), Cygwin) + MAKEFILE = cygwin +endif +ifeq ($(OS), Solaris) + MAKEFILE = solaris +endif +ifeq ($(OS), windows32) + MAKEFILE = mingw +endif + +default: + $(MAKE) -f Makefile.$(MAKEFILE) + +all: + $(MAKE) -f Makefile.$(MAKEFILE) all + +dist: + $(MAKE) -f Makefile.$(MAKEFILE) dist + +install: + $(MAKE) -f Makefile.$(MAKEFILE) install + +clean: + $(MAKE) -f Makefile.$(MAKEFILE) clean + diff --git a/Makefile.cygwin b/Makefile.cygwin index 124f612..4b3c03a 100644 --- a/Makefile.cygwin +++ b/Makefile.cygwin @@ -1,73 +1,73 @@ -# Cygwin makefile for FreeImage - -# This file can be generated by ./gensrclist.sh -include Makefile.srcs - -# General configuration variables: -CC = gcc -CXX = g++ -AR = ar - -INSTALLDIR = /usr - -# Converts cr/lf to just lf -DOS2UNIX = dos2unix - -COMPILERFLAGS = -O3 -DNO_LCMS -LIBRARIES = -lstdc++ - -MODULES = $(SRCS:.c=.o) -MODULES := $(MODULES:.cpp=.o) -CFLAGS = $(COMPILERFLAGS) $(INCLUDE) -CXXFLAGS = $(COMPILERFLAGS) -Wno-ctor-dtor-privacy $(INCLUDE) - -TARGET = freeimage -STATICLIB = lib$(TARGET).a -SHAREDLIB = cyg$(TARGET)-$(VER_MAJOR).$(VER_MINOR).dll -LIBNAME = lib$(TARGET).dll.a -HEADER = Source/FreeImage.h - - -default: all - -all: dist - -dist: FreeImage - cp *.a Dist - cp *.dll Dist - cp *.dll.a Dist - cp $(HEADER) Dist - -dos2unix: - @$(DOS2UNIX) $(SRCS) $(INCLS) - -FreeImage: $(STATICLIB) $(SHAREDLIB) - -.c.o: - $(CC) $(CFLAGS) -c $< -o $@ - -.cpp.o: - $(CXX) $(CXXFLAGS) -c $< -o $@ - -$(STATICLIB): $(MODULES) - $(AR) r $@ $(MODULES) - -$(SHAREDLIB): $(MODULES) - $(CC) -s -shared -o $@ \ - -Wl,--out-implib=$(LIBNAME) \ - -Wl,--export-all-symbols \ - -Wl,--enable-auto-import \ - -Wl,--enable-auto-image-base \ - -Wl,--whole-archive $(STATICLIB) \ - -Wl,--no-whole-archive $(LIBRARIES) - - -install: - install -m 644 $(STATICLIB) $(INSTALLDIR)/lib - install -m 644 $(LIBNAME) $(INSTALLDIR)/lib - install -m 755 $(SHAREDLIB) $(INSTALLDIR)/bin - install -m 644 $(HEADER) $(INSTALLDIR)/include - -clean: - rm -f core Dist/*.* u2dtmp* $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME) - +# Cygwin makefile for FreeImage + +# This file can be generated by ./gensrclist.sh +include Makefile.srcs + +# General configuration variables: +CC = gcc +CXX = g++ +AR = ar + +INSTALLDIR = /usr + +# Converts cr/lf to just lf +DOS2UNIX = dos2unix + +COMPILERFLAGS = -O3 -DNO_LCMS +LIBRARIES = -lstdc++ + +MODULES = $(SRCS:.c=.o) +MODULES := $(MODULES:.cpp=.o) +CFLAGS = $(COMPILERFLAGS) $(INCLUDE) +CXXFLAGS = $(COMPILERFLAGS) -Wno-ctor-dtor-privacy $(INCLUDE) + +TARGET = freeimage +STATICLIB = lib$(TARGET).a +SHAREDLIB = cyg$(TARGET)-$(VER_MAJOR).$(VER_MINOR).dll +LIBNAME = lib$(TARGET).dll.a +HEADER = Source/FreeImage.h + + +default: all + +all: dist + +dist: FreeImage + cp *.a Dist + cp *.dll Dist + cp *.dll.a Dist + cp $(HEADER) Dist + +dos2unix: + @$(DOS2UNIX) $(SRCS) $(INCLS) + +FreeImage: $(STATICLIB) $(SHAREDLIB) + +.c.o: + $(CC) $(CFLAGS) -c $< -o $@ + +.cpp.o: + $(CXX) $(CXXFLAGS) -c $< -o $@ + +$(STATICLIB): $(MODULES) + $(AR) r $@ $(MODULES) + +$(SHAREDLIB): $(MODULES) + $(CC) -s -shared -o $@ \ + -Wl,--out-implib=$(LIBNAME) \ + -Wl,--export-all-symbols \ + -Wl,--enable-auto-import \ + -Wl,--enable-auto-image-base \ + -Wl,--whole-archive $(STATICLIB) \ + -Wl,--no-whole-archive $(LIBRARIES) + + +install: + install -m 644 $(STATICLIB) $(INSTALLDIR)/lib + install -m 644 $(LIBNAME) $(INSTALLDIR)/lib + install -m 755 $(SHAREDLIB) $(INSTALLDIR)/bin + install -m 644 $(HEADER) $(INSTALLDIR)/include + +clean: + rm -f core Dist/*.* u2dtmp* $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME) + diff --git a/Makefile.fip b/Makefile.fip index 1c2dee4..f4336d2 100644 --- a/Makefile.fip +++ b/Makefile.fip @@ -1,73 +1,73 @@ -# Linux makefile for FreeImagePlus - -# This file can be generated by ./genfipsrclist.sh -include fipMakefile.srcs - -# General configuration variables: -DESTDIR ?= / -INCDIR ?= $(DESTDIR)/usr/include -INSTALLDIR ?= $(DESTDIR)/usr/lib - -# Converts cr/lf to just lf -DOS2UNIX = dos2unix - -LIBRARIES = -lstdc++ - -MODULES = $(SRCS:.c=.o) -MODULES := $(MODULES:.cpp=.o) -CFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden -DNO_LCMS -CFLAGS += $(INCLUDE) -CXXFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden -Wno-ctor-dtor-privacy -CXXFLAGS += $(INCLUDE) - -ifeq ($(shell sh -c 'uname -m 2>/dev/null || echo not'),x86_64) - CFLAGS += -fPIC - CXXFLAGS += -fPIC -endif - -TARGET = freeimageplus -STATICLIB = lib$(TARGET).a -SHAREDLIB = lib$(TARGET)-$(VER_MAJOR).$(VER_MINOR).so -LIBNAME = lib$(TARGET).so -VERLIBNAME = $(LIBNAME).$(VER_MAJOR) -HEADER = Source/FreeImage.h -HEADERFIP = Wrapper/FreeImagePlus/FreeImagePlus.h - - -default: all - -all: dist - -dist: FreeImage - cp *.a Dist - cp *.so Dist - cp Source/FreeImage.h Dist - cp Wrapper/FreeImagePlus/FreeImagePlus.h Dist - -dos2unix: - @$(DOS2UNIX) $(SRCS) - -FreeImage: $(STATICLIB) $(SHAREDLIB) - -.c.o: - $(CC) $(CFLAGS) -c $< -o $@ - -.cpp.o: - $(CXX) $(CXXFLAGS) -c $< -o $@ - -$(STATICLIB): $(MODULES) - $(AR) r $@ $(MODULES) - -$(SHAREDLIB): $(MODULES) - $(CC) -s -shared -Wl,-soname,$(VERLIBNAME) $(LDFLAGS) -o $@ $(MODULES) $(LIBRARIES) - -install: - install -d $(INCDIR) $(INSTALLDIR) - install -m 644 -o root -g root $(HEADER) $(INCDIR) - install -m 644 -o root -g root $(HEADERFIP) $(INCDIR) - install -m 644 -o root -g root $(STATICLIB) $(INSTALLDIR) - install -m 755 -o root -g root $(SHAREDLIB) $(INSTALLDIR) - -clean: - rm -f core Dist/*.* u2dtmp* $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME) - +# Linux makefile for FreeImagePlus + +# This file can be generated by ./genfipsrclist.sh +include fipMakefile.srcs + +# General configuration variables: +DESTDIR ?= / +INCDIR ?= $(DESTDIR)/usr/include +INSTALLDIR ?= $(DESTDIR)/usr/lib + +# Converts cr/lf to just lf +DOS2UNIX = dos2unix + +LIBRARIES = -lstdc++ + +MODULES = $(SRCS:.c=.o) +MODULES := $(MODULES:.cpp=.o) +CFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden -DNO_LCMS +CFLAGS += $(INCLUDE) +CXXFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden -Wno-ctor-dtor-privacy +CXXFLAGS += $(INCLUDE) + +ifeq ($(shell sh -c 'uname -m 2>/dev/null || echo not'),x86_64) + CFLAGS += -fPIC + CXXFLAGS += -fPIC +endif + +TARGET = freeimageplus +STATICLIB = lib$(TARGET).a +SHAREDLIB = lib$(TARGET)-$(VER_MAJOR).$(VER_MINOR).so +LIBNAME = lib$(TARGET).so +VERLIBNAME = $(LIBNAME).$(VER_MAJOR) +HEADER = Source/FreeImage.h +HEADERFIP = Wrapper/FreeImagePlus/FreeImagePlus.h + + +default: all + +all: dist + +dist: FreeImage + cp *.a Dist + cp *.so Dist + cp Source/FreeImage.h Dist + cp Wrapper/FreeImagePlus/FreeImagePlus.h Dist + +dos2unix: + @$(DOS2UNIX) $(SRCS) + +FreeImage: $(STATICLIB) $(SHAREDLIB) + +.c.o: + $(CC) $(CFLAGS) -c $< -o $@ + +.cpp.o: + $(CXX) $(CXXFLAGS) -c $< -o $@ + +$(STATICLIB): $(MODULES) + $(AR) r $@ $(MODULES) + +$(SHAREDLIB): $(MODULES) + $(CC) -s -shared -Wl,-soname,$(VERLIBNAME) $(LDFLAGS) -o $@ $(MODULES) $(LIBRARIES) + +install: + install -d $(INCDIR) $(INSTALLDIR) + install -m 644 -o root -g root $(HEADER) $(INCDIR) + install -m 644 -o root -g root $(HEADERFIP) $(INCDIR) + install -m 644 -o root -g root $(STATICLIB) $(INSTALLDIR) + install -m 755 -o root -g root $(SHAREDLIB) $(INSTALLDIR) + +clean: + rm -f core Dist/*.* u2dtmp* $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME) + diff --git a/Makefile.gnu b/Makefile.gnu index e6007ae..0c967b8 100644 --- a/Makefile.gnu +++ b/Makefile.gnu @@ -1,74 +1,74 @@ -# Linux makefile for FreeImage - -# This file can be generated by ./gensrclist.sh -include Makefile.srcs - -# General configuration variables: -DESTDIR ?= / -INCDIR ?= $(DESTDIR)/usr/include -INSTALLDIR ?= $(DESTDIR)/usr/lib - -# Converts cr/lf to just lf -DOS2UNIX = dos2unix - -LIBRARIES = -lstdc++ - -MODULES = $(SRCS:.c=.o) -MODULES := $(MODULES:.cpp=.o) -CFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden -DNO_LCMS -CFLAGS += $(INCLUDE) -CXXFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden -Wno-ctor-dtor-privacy -CXXFLAGS += $(INCLUDE) - -ifeq ($(shell sh -c 'uname -m 2>/dev/null || echo not'),x86_64) - CFLAGS += -fPIC - CXXFLAGS += -fPIC -endif - -TARGET = freeimage -STATICLIB = lib$(TARGET).a -SHAREDLIB = lib$(TARGET)-$(VER_MAJOR).$(VER_MINOR).so -LIBNAME = lib$(TARGET).so -VERLIBNAME = $(LIBNAME).$(VER_MAJOR) -HEADER = Source/FreeImage.h - - - -default: all - -all: dist - -dist: FreeImage - cp *.a Dist - cp *.so Dist - cp Source/FreeImage.h Dist - -dos2unix: - @$(DOS2UNIX) $(SRCS) $(INCLS) - -FreeImage: $(STATICLIB) $(SHAREDLIB) - -.c.o: - $(CC) $(CFLAGS) -c $< -o $@ - -.cpp.o: - $(CXX) $(CXXFLAGS) -c $< -o $@ - -$(STATICLIB): $(MODULES) - $(AR) r $@ $(MODULES) - -$(SHAREDLIB): $(MODULES) - $(CC) -s -shared -Wl,-soname,$(VERLIBNAME) $(LDFLAGS) -o $@ $(MODULES) $(LIBRARIES) - -install: - install -d $(INCDIR) $(INSTALLDIR) - install -m 644 -o root -g root $(HEADER) $(INCDIR) - install -m 644 -o root -g root $(STATICLIB) $(INSTALLDIR) - install -m 755 -o root -g root $(SHAREDLIB) $(INSTALLDIR) - ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(VERLIBNAME) - ln -sf $(VERLIBNAME) $(INSTALLDIR)/$(LIBNAME) -# ldconfig - -clean: - rm -f core Dist/*.* u2dtmp* $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME) - +# Linux makefile for FreeImage + +# This file can be generated by ./gensrclist.sh +include Makefile.srcs + +# General configuration variables: +DESTDIR ?= / +INCDIR ?= $(DESTDIR)/usr/include +INSTALLDIR ?= $(DESTDIR)/usr/lib + +# Converts cr/lf to just lf +DOS2UNIX = dos2unix + +LIBRARIES = -lstdc++ + +MODULES = $(SRCS:.c=.o) +MODULES := $(MODULES:.cpp=.o) +CFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden -DNO_LCMS +CFLAGS += $(INCLUDE) +CXXFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden -Wno-ctor-dtor-privacy +CXXFLAGS += $(INCLUDE) + +ifeq ($(shell sh -c 'uname -m 2>/dev/null || echo not'),x86_64) + CFLAGS += -fPIC + CXXFLAGS += -fPIC +endif + +TARGET = freeimage +STATICLIB = lib$(TARGET).a +SHAREDLIB = lib$(TARGET)-$(VER_MAJOR).$(VER_MINOR).so +LIBNAME = lib$(TARGET).so +VERLIBNAME = $(LIBNAME).$(VER_MAJOR) +HEADER = Source/FreeImage.h + + + +default: all + +all: dist + +dist: FreeImage + cp *.a Dist + cp *.so Dist + cp Source/FreeImage.h Dist + +dos2unix: + @$(DOS2UNIX) $(SRCS) $(INCLS) + +FreeImage: $(STATICLIB) $(SHAREDLIB) + +.c.o: + $(CC) $(CFLAGS) -c $< -o $@ + +.cpp.o: + $(CXX) $(CXXFLAGS) -c $< -o $@ + +$(STATICLIB): $(MODULES) + $(AR) r $@ $(MODULES) + +$(SHAREDLIB): $(MODULES) + $(CC) -s -shared -Wl,-soname,$(VERLIBNAME) $(LDFLAGS) -o $@ $(MODULES) $(LIBRARIES) + +install: + install -d $(INCDIR) $(INSTALLDIR) + install -m 644 -o root -g root $(HEADER) $(INCDIR) + install -m 644 -o root -g root $(STATICLIB) $(INSTALLDIR) + install -m 755 -o root -g root $(SHAREDLIB) $(INSTALLDIR) + ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(VERLIBNAME) + ln -sf $(VERLIBNAME) $(INSTALLDIR)/$(LIBNAME) +# ldconfig + +clean: + rm -f core Dist/*.* u2dtmp* $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME) + diff --git a/Makefile.iphone b/Makefile.iphone index b99a630..c55cddf 100644 --- a/Makefile.iphone +++ b/Makefile.iphone @@ -1,93 +1,93 @@ -# Configuration for iPhone OS, making static libs -# this will generate both iPhone (arm) and iPhoneSimulator (i686) libs - -include Makefile.srcs - -CFLAGS = -g -O2 -Wall -Wmissing-prototypes -std=c99 -ffast-math -fno-strict-aliasing -CXXFLAGS = -g -O2 -Wall -fno-strict-aliasing - -GCC_VERSION = 4.2 -IPHONEOS_DEPLOYMENT_TARGET = 4.0 -MACOSX_DEPLOYMENT_TARGET = 10.6 - -PLATFORM_SIM = iPhoneSimulator -PLATFORM_PHONE = iPhoneOS - -ARCH_SIM = i686 -ARCH_PHONE = armv6 - -PLATFORM_SIM_DEVELOPER_BIN_DIR = /Developer/Platforms/$(PLATFORM_SIM).platform/Developer/usr/bin -PLATFORM_PHONE_DEVELOPER_BIN_DIR = /Developer/Platforms/$(PLATFORM_PHONE).platform/Developer/usr/bin - -SDKROOT_SIM = /Developer/Platforms/$(PLATFORM_SIM).platform/Developer/SDKs/$(PLATFORM_SIM)$(IPHONEOS_DEPLOYMENT_TARGET).sdk -SDKROOT_PHONE = /Developer/Platforms/$(PLATFORM_PHONE).platform/Developer/SDKs/$(PLATFORM_PHONE)$(IPHONEOS_DEPLOYMENT_TARGET).sdk - -EXTRA_CFLAGS_SIM += -arch $(ARCH_SIM) -pipe -mdynamic-no-pic -fvisibility=hidden $(INCLUDE) -isysroot $(SDKROOT_SIM) -EXTRA_LDFLAGS_SIM += -arch $(ARCH_SIM) -isysroot $(SDKROOT_SIM) -Wl,-dead_strip -EXTRA_CFLAGS_SIM += -D__IPHONE_OS_VERSION_MIN_REQUIRED=20000 -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET) -EXTRA_LDFLAGS_SIM += -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET) - -EXTRA_CFLAGS_PHONE += -arch $(ARCH_PHONE) -pipe -mdynamic-no-pic -fvisibility=hidden $(INCLUDE) -isysroot $(SDKROOT_PHONE) -EXTRA_LDFLAGS_PHONE += -arch $(ARCH_PHONE) -isysroot $(SDKROOT_PHONE) -Wl,-dead_strip -EXTRA_CFLAGS_PHONE += -miphoneos-version-min=$(IPHONEOS_DEPLOYMENT_TARGET) -EXTRA_LDFLAGS_PHONE += -miphoneos-version-min=$(IPHONEOS_DEPLOYMENT_TARGET) - -AR_SIM = $(PLATFORM_SIM_DEVELOPER_BIN_DIR)/ar -AR_PHONE = $(PLATFORM_PHONE_DEVELOPER_BIN_DIR)/ar - -CC_SIM = $(PLATFORM_SIM_DEVELOPER_BIN_DIR)/gcc-$(GCC_VERSION) -CC_PHONE = $(PLATFORM_PHONE_DEVELOPER_BIN_DIR)/gcc-$(GCC_VERSION) - -CFLAGS_SIM = $(CFLAGS) $(EXTRA_CFLAGS_SIM) -LDFLAGS_SIM = $(EXTRA_LDFLAGS_SIM) -CXX_SIM = $(PLATFORM_SIM_DEVELOPER_BIN_DIR)/g++-$(GCC_VERSION) -CXXFLAGS_SIM += $(EXTRA_CFLAGS_SIM) -fvisibility-inlines-hidden -LIBTOOL_SIM = /Developer/Platforms/$(PLATFORM_SIM).platform/Developer/usr/bin/libtool - -CFLAGS_PHONE = $(CFLAGS) $(EXTRA_CFLAGS_PHONE) -LDFLAGS_PHONE += $(EXTRA_LDFLAGS_PHONE) -CXX_PHONE = $(PLATFORM_PHONE_DEVELOPER_BIN_DIR)/g++-$(GCC_VERSION) -CXXFLAGS_PHONE += $(EXTRA_CFLAGS_PHONE) -fvisibility-inlines-hidden -LIBTOOL_PHONE = /Developer/Platforms/$(PLATFORM_PHONE).platform/Developer/usr/bin/libtool - -TARGET = freeimage -STATICLIB_SIM = lib$(TARGET)-iphonesimulator.a -STATICLIB_PHONE = lib$(TARGET)-iphone.a -HEADER = Source/FreeImage.h - -.SUFFIXES: .o-i686 .o-arm -MODULES_ARM = $(SRCS:.c=.o-arm) -MODULES_ARM := $(MODULES_ARM:.cpp=.o-arm) -MODULES_i686 = $(SRCS:.c=.o-i686) -MODULES_i686 := $(MODULES_i686:.cpp=.o-i686) - -default: all - -all: dist - -dist: FreeImage - cp *.a Dist - cp Source/FreeImage.h Dist - -FreeImage: $(STATICLIB_SIM) $(STATICLIB_PHONE) - -$(STATICLIB_SIM): $(MODULES_i686) - $(LIBTOOL_SIM) -arch_only i686 -o $@ $(MODULES_i686) - -.c.o-i686: - $(CC_SIM) $(CFLAGS_SIM) -c $< -o $@ - -.cpp.o-i686: - $(CXX_SIM) $(CXXFLAGS_SIM) -c $< -o $@ - -$(STATICLIB_PHONE): $(MODULES_ARM) - $(LIBTOOL_PHONE) -arch_only armv6 -o $@ $(MODULES_ARM) - -.c.o-arm: - $(CC_PHONE) $(CFLAGS_PHONE) -c $< -o $@ - -.cpp.o-arm: - $(CXX_PHONE) $(CXXFLAGS_PHONE) -c $< -o $@ - -clean: - rm -f core Dist/*.* u2dtmp* $(MODULES_i686) $(MODULES_ARM) $(STATICLIB_SIM) $(STATICLIB_PHONE) +# Configuration for iPhone OS, making static libs +# this will generate both iPhone (arm) and iPhoneSimulator (i686) libs + +include Makefile.srcs + +CFLAGS = -g -O2 -Wall -Wmissing-prototypes -std=c99 -ffast-math -fno-strict-aliasing +CXXFLAGS = -g -O2 -Wall -fno-strict-aliasing + +GCC_VERSION = 4.2 +IPHONEOS_DEPLOYMENT_TARGET = 4.0 +MACOSX_DEPLOYMENT_TARGET = 10.6 + +PLATFORM_SIM = iPhoneSimulator +PLATFORM_PHONE = iPhoneOS + +ARCH_SIM = i686 +ARCH_PHONE = armv6 + +PLATFORM_SIM_DEVELOPER_BIN_DIR = /Developer/Platforms/$(PLATFORM_SIM).platform/Developer/usr/bin +PLATFORM_PHONE_DEVELOPER_BIN_DIR = /Developer/Platforms/$(PLATFORM_PHONE).platform/Developer/usr/bin + +SDKROOT_SIM = /Developer/Platforms/$(PLATFORM_SIM).platform/Developer/SDKs/$(PLATFORM_SIM)$(IPHONEOS_DEPLOYMENT_TARGET).sdk +SDKROOT_PHONE = /Developer/Platforms/$(PLATFORM_PHONE).platform/Developer/SDKs/$(PLATFORM_PHONE)$(IPHONEOS_DEPLOYMENT_TARGET).sdk + +EXTRA_CFLAGS_SIM += -arch $(ARCH_SIM) -pipe -mdynamic-no-pic -fvisibility=hidden $(INCLUDE) -isysroot $(SDKROOT_SIM) +EXTRA_LDFLAGS_SIM += -arch $(ARCH_SIM) -isysroot $(SDKROOT_SIM) -Wl,-dead_strip +EXTRA_CFLAGS_SIM += -D__IPHONE_OS_VERSION_MIN_REQUIRED=20000 -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET) +EXTRA_LDFLAGS_SIM += -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET) + +EXTRA_CFLAGS_PHONE += -arch $(ARCH_PHONE) -pipe -mdynamic-no-pic -fvisibility=hidden $(INCLUDE) -isysroot $(SDKROOT_PHONE) +EXTRA_LDFLAGS_PHONE += -arch $(ARCH_PHONE) -isysroot $(SDKROOT_PHONE) -Wl,-dead_strip +EXTRA_CFLAGS_PHONE += -miphoneos-version-min=$(IPHONEOS_DEPLOYMENT_TARGET) +EXTRA_LDFLAGS_PHONE += -miphoneos-version-min=$(IPHONEOS_DEPLOYMENT_TARGET) + +AR_SIM = $(PLATFORM_SIM_DEVELOPER_BIN_DIR)/ar +AR_PHONE = $(PLATFORM_PHONE_DEVELOPER_BIN_DIR)/ar + +CC_SIM = $(PLATFORM_SIM_DEVELOPER_BIN_DIR)/gcc-$(GCC_VERSION) +CC_PHONE = $(PLATFORM_PHONE_DEVELOPER_BIN_DIR)/gcc-$(GCC_VERSION) + +CFLAGS_SIM = $(CFLAGS) $(EXTRA_CFLAGS_SIM) +LDFLAGS_SIM = $(EXTRA_LDFLAGS_SIM) +CXX_SIM = $(PLATFORM_SIM_DEVELOPER_BIN_DIR)/g++-$(GCC_VERSION) +CXXFLAGS_SIM += $(EXTRA_CFLAGS_SIM) -fvisibility-inlines-hidden +LIBTOOL_SIM = /Developer/Platforms/$(PLATFORM_SIM).platform/Developer/usr/bin/libtool + +CFLAGS_PHONE = $(CFLAGS) $(EXTRA_CFLAGS_PHONE) +LDFLAGS_PHONE += $(EXTRA_LDFLAGS_PHONE) +CXX_PHONE = $(PLATFORM_PHONE_DEVELOPER_BIN_DIR)/g++-$(GCC_VERSION) +CXXFLAGS_PHONE += $(EXTRA_CFLAGS_PHONE) -fvisibility-inlines-hidden +LIBTOOL_PHONE = /Developer/Platforms/$(PLATFORM_PHONE).platform/Developer/usr/bin/libtool + +TARGET = freeimage +STATICLIB_SIM = lib$(TARGET)-iphonesimulator.a +STATICLIB_PHONE = lib$(TARGET)-iphone.a +HEADER = Source/FreeImage.h + +.SUFFIXES: .o-i686 .o-arm +MODULES_ARM = $(SRCS:.c=.o-arm) +MODULES_ARM := $(MODULES_ARM:.cpp=.o-arm) +MODULES_i686 = $(SRCS:.c=.o-i686) +MODULES_i686 := $(MODULES_i686:.cpp=.o-i686) + +default: all + +all: dist + +dist: FreeImage + cp *.a Dist + cp Source/FreeImage.h Dist + +FreeImage: $(STATICLIB_SIM) $(STATICLIB_PHONE) + +$(STATICLIB_SIM): $(MODULES_i686) + $(LIBTOOL_SIM) -arch_only i686 -o $@ $(MODULES_i686) + +.c.o-i686: + $(CC_SIM) $(CFLAGS_SIM) -c $< -o $@ + +.cpp.o-i686: + $(CXX_SIM) $(CXXFLAGS_SIM) -c $< -o $@ + +$(STATICLIB_PHONE): $(MODULES_ARM) + $(LIBTOOL_PHONE) -arch_only armv6 -o $@ $(MODULES_ARM) + +.c.o-arm: + $(CC_PHONE) $(CFLAGS_PHONE) -c $< -o $@ + +.cpp.o-arm: + $(CXX_PHONE) $(CXXFLAGS_PHONE) -c $< -o $@ + +clean: + rm -f core Dist/*.* u2dtmp* $(MODULES_i686) $(MODULES_ARM) $(STATICLIB_SIM) $(STATICLIB_PHONE) diff --git a/Makefile.mingw b/Makefile.mingw index 06a3462..74f8af9 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -1,136 +1,136 @@ -# MinGW makefile for FreeImage - -# This file can be generated by ./gensrclist.sh -include Makefile.srcs - -# General configuration variables. -DESTDIR ?= $(SystemRoot) -INSTALLDIR ?= $(DESTDIR)/system32 -DISTDIR ?= Dist -SRCDIR ?= Source -HEADER = FreeImage.h -RCFILE = FreeImage.rc - -# Uncomment this variable to make a static library. This may -# also be specified as an environment variable and can hold -# any of STATIC and SHARED and must be in uppercase letters. -# Default: SHARED -#FREEIMAGE_LIBRARY_TYPE = STATIC - -# Redefine the compiler (CC defaults to ´cc´ for MinGW's make, -# however there's only ´gcc´ available with MinGW). -CC = gcc - -# Redefine the linker (we use ´g++´ for linking, since MinGW's -# command ´ld´ comes with wrong (Linux) standard library search -# paths). -LD = g++ - -#Define the ´dlltool´ command. -DLLTOOL = dlltool - -#Define the resource compiler. -RC = windres - -# Define the ´copy´ command. -CP = cp - -# Define the ´mkdir´ command. -MD = mkdir - -# Define the ´remove´ command. -RM = rm - -# Define additional libraries needed. -# libstdc++ is included by default with MinGW, however for -# WIN32 based builds, LibRawLite needs the winsock libraries. -LIBRARIES = -lwsock32 -lws2_32 - -# Define some additional symboles needed for WIN32 based builds. -WIN32_CFLAGS = -DWINVER=0x0500 $(LIB_TYPE_FLAGS) -DOPJ_STATIC -WIN32_CXXFLAGS = $(WIN32_CFLAGS) -DLIBRAW_NODLL - -# Workaround for LibRawLite, which does not include C++ header -# file stdexcept, which is casually included with MSVC but not -# with MinGW. This can be removed after LibRawLite got control -# over its includes again. -WIN32_CXXFLAGS += -include stdexcept - -# Define DLL image header information flags for the linker. -WIN32_LDFLAGS = -Wl,--subsystem,windows:5.0,--major-os-version,5 - -WIN32_STATIC_FLAGS = -DFREEIMAGE_LIB -WIN32_SHARED_FLAGS = -DFREEIMAGE_EXPORTS - -MODULES = $(SRCS:.c=.o) -MODULES := $(MODULES:.cpp=.o) -RESOURCE = $(RCFILE:.rc=.coff) -CFLAGS ?= -O3 -fexceptions -DNDEBUG $(WIN32_CFLAGS) -CFLAGS += $(INCLUDE) -CXXFLAGS ?= -O3 -fexceptions -Wno-ctor-dtor-privacy -DNDEBUG $(WIN32_CXXFLAGS) -CXXFLAGS += $(INCLUDE) -RCFLAGS ?= -DNDEBUG -LDFLAGS ?= -s -shared -static -Wl,-soname,$(SOLIBNAME) $(WIN32_LDFLAGS) -DLLTOOLFLAGS ?= --add-stdcall-underscore - -TARGET = FreeImage -STATICLIB = lib$(TARGET).a -SHAREDLIB = $(TARGET).dll -IMPORTLIB = $(TARGET).lib -EXPORTLIB = $(TARGET).exp -SOLIBNAME = $(SHAREDLIB).$(VER_MAJOR) - -DISTSHARED = $(addprefix $(DISTDIR)/, $(SHAREDLIB) $(IMPORTLIB) $(HEADER)) -DISTSTATIC = $(addprefix $(DISTDIR)/, $(STATICLIB) $(HEADER)) - -# The FreeImage library type defaults to SHARED. -FREEIMAGE_LIBRARY_TYPE ?= SHARED - -TARGETLIB = $($(FREEIMAGE_LIBRARY_TYPE)LIB) -TARGETDIST = $(DIST$(FREEIMAGE_LIBRARY_TYPE)) -LIB_TYPE_FLAGS = $(WIN32_$(FREEIMAGE_LIBRARY_TYPE)_FLAGS) - -default: all - -all: mkdist - -rebuild: clean all - -mkdist: FreeImage $(TARGETDIST) - -FreeImage: $(TARGETLIB) - -%.o: %.c - $(CC) $(CFLAGS) -c $< -o $@ - -%.o: %.cpp - $(CXX) $(CXXFLAGS) -c $< -o $@ - -%.coff: %.rc - $(RC) $(RCFLAGS) -o $@ $< - -$(DISTDIR)/%: % - $(CP) $< $@ - -$(DISTDIR)/%: $(SRCDIR)/% - $(CP) $< $@ - -$(STATICLIB): $(MODULES) - $(AR) rs $@ $(MODULES) - -$(IMPORTLIB) $(EXPORTLIB): $(MODULES) - $(DLLTOOL) -e $(EXPORTLIB) -l $(IMPORTLIB) -D $(SHAREDLIB) $(DLLTOOLFLAGS) $(MODULES) - -$(SHAREDLIB): $(EXPORTLIB) $(RESOURCE) - $(LD) $(LDFLAGS) -o $@ $(EXPORTLIB) $(MODULES) $(RESOURCE) $(LIBRARIES) - -$(DISTDIR): - $(MD) $(DISTDIR) - -$(TARGETDIST): $(DISTDIR) - -install: - $(CP) $(SHAREDLIB) $(INSTALLDIR) - -clean: - $(RM) -f core $(DISTDIR)/*.* $(MODULES) $(RESOURCE) $(STATICLIB) $(SHAREDLIB) $(IMPORTLIB) $(EXPORTLIB) +# MinGW makefile for FreeImage + +# This file can be generated by ./gensrclist.sh +include Makefile.srcs + +# General configuration variables. +DESTDIR ?= $(SystemRoot) +INSTALLDIR ?= $(DESTDIR)/system32 +DISTDIR ?= Dist +SRCDIR ?= Source +HEADER = FreeImage.h +RCFILE = FreeImage.rc + +# Uncomment this variable to make a static library. This may +# also be specified as an environment variable and can hold +# any of STATIC and SHARED and must be in uppercase letters. +# Default: SHARED +#FREEIMAGE_LIBRARY_TYPE = STATIC + +# Redefine the compiler (CC defaults to ´cc´ for MinGW's make, +# however there's only ´gcc´ available with MinGW). +CC = gcc + +# Redefine the linker (we use ´g++´ for linking, since MinGW's +# command ´ld´ comes with wrong (Linux) standard library search +# paths). +LD = g++ + +#Define the ´dlltool´ command. +DLLTOOL = dlltool + +#Define the resource compiler. +RC = windres + +# Define the ´copy´ command. +CP = cp + +# Define the ´mkdir´ command. +MD = mkdir + +# Define the ´remove´ command. +RM = rm + +# Define additional libraries needed. +# libstdc++ is included by default with MinGW, however for +# WIN32 based builds, LibRawLite needs the winsock libraries. +LIBRARIES = -lwsock32 -lws2_32 + +# Define some additional symboles needed for WIN32 based builds. +WIN32_CFLAGS = -DWINVER=0x0500 $(LIB_TYPE_FLAGS) -DOPJ_STATIC +WIN32_CXXFLAGS = $(WIN32_CFLAGS) -DLIBRAW_NODLL + +# Workaround for LibRawLite, which does not include C++ header +# file stdexcept, which is casually included with MSVC but not +# with MinGW. This can be removed after LibRawLite got control +# over its includes again. +WIN32_CXXFLAGS += -include stdexcept + +# Define DLL image header information flags for the linker. +WIN32_LDFLAGS = -Wl,--subsystem,windows:5.0,--major-os-version,5 + +WIN32_STATIC_FLAGS = -DFREEIMAGE_LIB +WIN32_SHARED_FLAGS = -DFREEIMAGE_EXPORTS + +MODULES = $(SRCS:.c=.o) +MODULES := $(MODULES:.cpp=.o) +RESOURCE = $(RCFILE:.rc=.coff) +CFLAGS ?= -O3 -fexceptions -DNDEBUG $(WIN32_CFLAGS) +CFLAGS += $(INCLUDE) +CXXFLAGS ?= -O3 -fexceptions -Wno-ctor-dtor-privacy -DNDEBUG $(WIN32_CXXFLAGS) +CXXFLAGS += $(INCLUDE) +RCFLAGS ?= -DNDEBUG +LDFLAGS ?= -s -shared -static -Wl,-soname,$(SOLIBNAME) $(WIN32_LDFLAGS) +DLLTOOLFLAGS ?= --add-stdcall-underscore + +TARGET = FreeImage +STATICLIB = lib$(TARGET).a +SHAREDLIB = $(TARGET).dll +IMPORTLIB = $(TARGET).lib +EXPORTLIB = $(TARGET).exp +SOLIBNAME = $(SHAREDLIB).$(VER_MAJOR) + +DISTSHARED = $(addprefix $(DISTDIR)/, $(SHAREDLIB) $(IMPORTLIB) $(HEADER)) +DISTSTATIC = $(addprefix $(DISTDIR)/, $(STATICLIB) $(HEADER)) + +# The FreeImage library type defaults to SHARED. +FREEIMAGE_LIBRARY_TYPE ?= SHARED + +TARGETLIB = $($(FREEIMAGE_LIBRARY_TYPE)LIB) +TARGETDIST = $(DIST$(FREEIMAGE_LIBRARY_TYPE)) +LIB_TYPE_FLAGS = $(WIN32_$(FREEIMAGE_LIBRARY_TYPE)_FLAGS) + +default: all + +all: mkdist + +rebuild: clean all + +mkdist: FreeImage $(TARGETDIST) + +FreeImage: $(TARGETLIB) + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +%.coff: %.rc + $(RC) $(RCFLAGS) -o $@ $< + +$(DISTDIR)/%: % + $(CP) $< $@ + +$(DISTDIR)/%: $(SRCDIR)/% + $(CP) $< $@ + +$(STATICLIB): $(MODULES) + $(AR) rs $@ $(MODULES) + +$(IMPORTLIB) $(EXPORTLIB): $(MODULES) + $(DLLTOOL) -e $(EXPORTLIB) -l $(IMPORTLIB) -D $(SHAREDLIB) $(DLLTOOLFLAGS) $(MODULES) + +$(SHAREDLIB): $(EXPORTLIB) $(RESOURCE) + $(LD) $(LDFLAGS) -o $@ $(EXPORTLIB) $(MODULES) $(RESOURCE) $(LIBRARIES) + +$(DISTDIR): + $(MD) $(DISTDIR) + +$(TARGETDIST): $(DISTDIR) + +install: + $(CP) $(SHAREDLIB) $(INSTALLDIR) + +clean: + $(RM) -f core $(DISTDIR)/*.* $(MODULES) $(RESOURCE) $(STATICLIB) $(SHAREDLIB) $(IMPORTLIB) $(EXPORTLIB) diff --git a/Makefile.osx b/Makefile.osx index d8e5a2d..a93448b 100644 --- a/Makefile.osx +++ b/Makefile.osx @@ -1,114 +1,114 @@ -# -*- Makefile -*- -# Mac OSX makefile for FreeImage - -# This file can be generated by ./gensrclist.sh -include Makefile.srcs - -# General configuration variables: -CC_PPC = gcc-4.0 -CC_I386 = gcc-4.0 -CC_X86_64 = gcc-4.0 -CPP_PPC = g++-4.0 -CPP_I386 = g++-4.0 -CPP_X86_64 = g++-4.0 -COMPILERFLAGS = -Os -fexceptions -fvisibility=hidden -DNO_LCMS -COMPILERFLAGS_PPC = -arch ppc -COMPILERFLAGS_I386 = -arch i386 -COMPILERFLAGS_X86_64 = -arch x86_64 -COMPILERPPFLAGS = -Wno-ctor-dtor-privacy -INCLUDE += -INCLUDE_PPC = -isysroot /Developer/SDKs/MacOSX10.5.sdk -INCLUDE_I386 = -isysroot /Developer/SDKs/MacOSX10.5.sdk -INCLUDE_X86_64 = -isysroot /Developer/SDKs/MacOSX10.6.sdk -CFLAGS_PPC = $(COMPILERFLAGS) $(COMPILERFLAGS_PPC) $(INCLUDE) $(INCLUDE_PPC) -CFLAGS_I386 = $(COMPILERFLAGS) $(COMPILERFLAGS_I386) $(INCLUDE) $(INCLUDE_I386) -CFLAGS_X86_64 = $(COMPILERFLAGS) $(COMPILERFLAGS_X86_64) $(INCLUDE) $(INCLUDE_X86_64) -CPPFLAGS_PPC = $(COMPILERPPFLAGS) $(CFLAGS_PPC) -CPPFLAGS_I386 = $(COMPILERPPFLAGS) $(CFLAGS_I386) -CPPFLAGS_X86_64 = $(COMPILERPPFLAGS) $(CFLAGS_X86_64) -LIBRARIES_PPC = -Wl,-syslibroot /Developer/SDKs/MacOSX10.5.sdk -LIBRARIES_I386 = -Wl,-syslibroot /Developer/SDKs/MacOSX10.5.sdk -LIBRARIES_X86_64 = -Wl,-syslibroot /Developer/SDKs/MacOSX10.6.sdk -LIBTOOL = libtool -LIPO = lipo - -TARGET = freeimage -STATICLIB = lib$(TARGET).a -SHAREDLIB = lib$(TARGET)-$(VER_MAJOR).$(VER_MINOR).dylib -LIBNAME = lib$(TARGET).$(VER_MAJOR).dylib -HEADER = Source/FreeImage.h - -.SUFFIXES: .o-ppc .o-i386 .o-x86_64 -MODULES_PPC = $(SRCS:.c=.o-ppc) -MODULES_I386 = $(SRCS:.c=.o-i386) -MODULES_X86_64 = $(SRCS:.c=.o-x86_64) -MODULES_PPC := $(MODULES_PPC:.cpp=.o-ppc) -MODULES_I386 := $(MODULES_I386:.cpp=.o-i386) -MODULES_X86_64 := $(MODULES_X86_64:.cpp=.o-x86_64) - -PREFIX = /usr/local -INSTALLDIR = $(PREFIX)/lib -INCDIR = $(PREFIX)/include - -default: all - -all: dist - -dist: FreeImage - cp *.a Dist - cp *.dylib Dist - cp Source/FreeImage.h Dist - -FreeImage: $(STATICLIB) $(SHAREDLIB) - -$(STATICLIB): $(STATICLIB)-ppc $(STATICLIB)-i386 $(STATICLIB)-x86_64 - $(LIPO) -create $(STATICLIB)-ppc $(STATICLIB)-i386 $(STATICLIB)-x86_64 -output $(STATICLIB) - -$(STATICLIB)-ppc: $(MODULES_PPC) - $(LIBTOOL) -arch_only ppc -o $@ $(MODULES_PPC) - -$(STATICLIB)-i386: $(MODULES_I386) - $(LIBTOOL) -arch_only i386 -o $@ $(MODULES_I386) - -$(STATICLIB)-x86_64: $(MODULES_X86_64) - $(LIBTOOL) -arch_only x86_64 -o $@ $(MODULES_X86_64) - -$(SHAREDLIB): $(SHAREDLIB)-ppc $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64 - $(LIPO) -create $(SHAREDLIB)-ppc $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64 -output $(SHAREDLIB) - -$(SHAREDLIB)-ppc: $(MODULES_PPC) - $(CPP_PPC) -arch ppc -dynamiclib $(LIBRARIES_PPC) -o $@ $(MODULES_PPC) - -$(SHAREDLIB)-i386: $(MODULES_I386) - $(CPP_I386) -arch i386 -dynamiclib $(LIBRARIES_I386) -o $@ $(MODULES_I386) - -$(SHAREDLIB)-x86_64: $(MODULES_X86_64) - $(CPP_X86_64) -arch x86_64 -dynamiclib $(LIBRARIES_X86_64) -o $@ $(MODULES_X86_64) - -.c.o-ppc: - $(CC_PPC) $(CFLAGS_PPC) -c $< -o $@ - -.c.o-i386: - $(CC_I386) $(CFLAGS_I386) -c $< -o $@ - -.c.o-x86_64: - $(CC_X86_64) $(CFLAGS_X86_64) -c $< -o $@ - -.cpp.o-ppc: - $(CPP_PPC) $(CPPFLAGS_PPC) -c $< -o $@ - -.cpp.o-i386: - $(CPP_I386) $(CPPFLAGS_I386) -c $< -o $@ - -.cpp.o-x86_64: - $(CPP_X86_64) $(CPPFLAGS_X86_64) -c $< -o $@ - -install: - install -d -m 755 -o root -g wheel $(INCDIR) $(INSTALLDIR) - install -m 644 -o root -g wheel $(HEADER) $(INCDIR) - install -m 644 -o root -g wheel $(SHAREDLIB) $(STATICLIB) $(INSTALLDIR) - ranlib -sf $(INSTALLDIR)/$(STATICLIB) - ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(LIBNAME) - -clean: - rm -f core Dist/*.* u2dtmp* $(MODULES_PPC) $(MODULES_I386) $(MODULES_X86_64) $(STATICLIB) $(STATICLIB)-ppc $(STATICLIB)-i386 $(SHAREDLIB) $(SHAREDLIB)-ppc $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64 +# -*- Makefile -*- +# Mac OSX makefile for FreeImage + +# This file can be generated by ./gensrclist.sh +include Makefile.srcs + +# General configuration variables: +CC_PPC = gcc-4.0 +CC_I386 = gcc-4.0 +CC_X86_64 = gcc-4.0 +CPP_PPC = g++-4.0 +CPP_I386 = g++-4.0 +CPP_X86_64 = g++-4.0 +COMPILERFLAGS = -Os -fexceptions -fvisibility=hidden -DNO_LCMS +COMPILERFLAGS_PPC = -arch ppc +COMPILERFLAGS_I386 = -arch i386 +COMPILERFLAGS_X86_64 = -arch x86_64 +COMPILERPPFLAGS = -Wno-ctor-dtor-privacy +INCLUDE += +INCLUDE_PPC = -isysroot /Developer/SDKs/MacOSX10.5.sdk +INCLUDE_I386 = -isysroot /Developer/SDKs/MacOSX10.5.sdk +INCLUDE_X86_64 = -isysroot /Developer/SDKs/MacOSX10.6.sdk +CFLAGS_PPC = $(COMPILERFLAGS) $(COMPILERFLAGS_PPC) $(INCLUDE) $(INCLUDE_PPC) +CFLAGS_I386 = $(COMPILERFLAGS) $(COMPILERFLAGS_I386) $(INCLUDE) $(INCLUDE_I386) +CFLAGS_X86_64 = $(COMPILERFLAGS) $(COMPILERFLAGS_X86_64) $(INCLUDE) $(INCLUDE_X86_64) +CPPFLAGS_PPC = $(COMPILERPPFLAGS) $(CFLAGS_PPC) +CPPFLAGS_I386 = $(COMPILERPPFLAGS) $(CFLAGS_I386) +CPPFLAGS_X86_64 = $(COMPILERPPFLAGS) $(CFLAGS_X86_64) +LIBRARIES_PPC = -Wl,-syslibroot /Developer/SDKs/MacOSX10.5.sdk +LIBRARIES_I386 = -Wl,-syslibroot /Developer/SDKs/MacOSX10.5.sdk +LIBRARIES_X86_64 = -Wl,-syslibroot /Developer/SDKs/MacOSX10.6.sdk +LIBTOOL = libtool +LIPO = lipo + +TARGET = freeimage +STATICLIB = lib$(TARGET).a +SHAREDLIB = lib$(TARGET)-$(VER_MAJOR).$(VER_MINOR).dylib +LIBNAME = lib$(TARGET).$(VER_MAJOR).dylib +HEADER = Source/FreeImage.h + +.SUFFIXES: .o-ppc .o-i386 .o-x86_64 +MODULES_PPC = $(SRCS:.c=.o-ppc) +MODULES_I386 = $(SRCS:.c=.o-i386) +MODULES_X86_64 = $(SRCS:.c=.o-x86_64) +MODULES_PPC := $(MODULES_PPC:.cpp=.o-ppc) +MODULES_I386 := $(MODULES_I386:.cpp=.o-i386) +MODULES_X86_64 := $(MODULES_X86_64:.cpp=.o-x86_64) + +PREFIX = /usr/local +INSTALLDIR = $(PREFIX)/lib +INCDIR = $(PREFIX)/include + +default: all + +all: dist + +dist: FreeImage + cp *.a Dist + cp *.dylib Dist + cp Source/FreeImage.h Dist + +FreeImage: $(STATICLIB) $(SHAREDLIB) + +$(STATICLIB): $(STATICLIB)-ppc $(STATICLIB)-i386 $(STATICLIB)-x86_64 + $(LIPO) -create $(STATICLIB)-ppc $(STATICLIB)-i386 $(STATICLIB)-x86_64 -output $(STATICLIB) + +$(STATICLIB)-ppc: $(MODULES_PPC) + $(LIBTOOL) -arch_only ppc -o $@ $(MODULES_PPC) + +$(STATICLIB)-i386: $(MODULES_I386) + $(LIBTOOL) -arch_only i386 -o $@ $(MODULES_I386) + +$(STATICLIB)-x86_64: $(MODULES_X86_64) + $(LIBTOOL) -arch_only x86_64 -o $@ $(MODULES_X86_64) + +$(SHAREDLIB): $(SHAREDLIB)-ppc $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64 + $(LIPO) -create $(SHAREDLIB)-ppc $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64 -output $(SHAREDLIB) + +$(SHAREDLIB)-ppc: $(MODULES_PPC) + $(CPP_PPC) -arch ppc -dynamiclib $(LIBRARIES_PPC) -o $@ $(MODULES_PPC) + +$(SHAREDLIB)-i386: $(MODULES_I386) + $(CPP_I386) -arch i386 -dynamiclib $(LIBRARIES_I386) -o $@ $(MODULES_I386) + +$(SHAREDLIB)-x86_64: $(MODULES_X86_64) + $(CPP_X86_64) -arch x86_64 -dynamiclib $(LIBRARIES_X86_64) -o $@ $(MODULES_X86_64) + +.c.o-ppc: + $(CC_PPC) $(CFLAGS_PPC) -c $< -o $@ + +.c.o-i386: + $(CC_I386) $(CFLAGS_I386) -c $< -o $@ + +.c.o-x86_64: + $(CC_X86_64) $(CFLAGS_X86_64) -c $< -o $@ + +.cpp.o-ppc: + $(CPP_PPC) $(CPPFLAGS_PPC) -c $< -o $@ + +.cpp.o-i386: + $(CPP_I386) $(CPPFLAGS_I386) -c $< -o $@ + +.cpp.o-x86_64: + $(CPP_X86_64) $(CPPFLAGS_X86_64) -c $< -o $@ + +install: + install -d -m 755 -o root -g wheel $(INCDIR) $(INSTALLDIR) + install -m 644 -o root -g wheel $(HEADER) $(INCDIR) + install -m 644 -o root -g wheel $(SHAREDLIB) $(STATICLIB) $(INSTALLDIR) + ranlib -sf $(INSTALLDIR)/$(STATICLIB) + ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(LIBNAME) + +clean: + rm -f core Dist/*.* u2dtmp* $(MODULES_PPC) $(MODULES_I386) $(MODULES_X86_64) $(STATICLIB) $(STATICLIB)-ppc $(STATICLIB)-i386 $(SHAREDLIB) $(SHAREDLIB)-ppc $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64 diff --git a/Makefile.solaris b/Makefile.solaris index a17c68e..ab987ba 100644 --- a/Makefile.solaris +++ b/Makefile.solaris @@ -1,65 +1,65 @@ -# Solaris9 makefile for FreeImage. Tested on Solaris9 with tools from -# Sunfreeware.com. - -# This file can be generated by ./gensrclist.sh -include Makefile.srcs - -# General configuration variables: -CC = gcc -CPP = g++ -AR = ar - -INSTALLDIR = /usr/local - -# Converts cr/lf to just lf -DOS2UNIX = dos2unix - -COMPILERFLAGS = -O3 -LIBRARIES = -lstdc++ - -MODULES = $(SRCS:.c=.o) -MODULES := $(MODULES:.cpp=.o) -CFLAGS = $(COMPILERFLAGS) $(INCLUDE) -CPPFLAGS = $(COMPILERFLAGS) -Wno-ctor-dtor-privacy $(INCLUDE) - -TARGET = freeimage -STATICLIB = lib$(TARGET).a -SHAREDLIB = lib$(TARGET)-$(VER_MAJOR).$(VER_MINOR).so -LIBNAME = lib$(TARGET).so.$(VER_MAJOR) - - - -default: all - -all: dist - -dist: FreeImage - cp *.a Dist - cp *.so Dist - cp Source/FreeImage.h Dist - -dos2unix: - @$(DOS2UNIX) $(SRCS) $(INCLS) - -FreeImage: $(STATICLIB) $(SHAREDLIB) - -.c.o: - $(CC) $(CFLAGS) -c $< -o $@ - -.cpp.o: - $(CPP) $(CPPFLAGS) -c $< -o $@ - -$(STATICLIB): $(MODULES) - $(AR) r $@ $(MODULES) - -$(SHAREDLIB): $(MODULES) - $(CC) -s -G -Wl,-soname=$(LIBNAME) -o $@ $(MODULES) $(LIBRARIES) - -install: - install -m 644 -o root -g root Source/FreeImage.h $(INSTALLDIR)/include - install -m 644 -o root -g root $(STATICLIB) $(INSTALLDIR)/lib - install -m 755 -o root -g root $(SHAREDLIB) $(INSTALLDIR)/lib - ln -sf $(SHAREDLIB) $(INSTALLDIR)/lib/$(LIBNAME) - -clean: - rm -rf core Dist/*.* u2dtmp* $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME) +# Solaris9 makefile for FreeImage. Tested on Solaris9 with tools from +# Sunfreeware.com. + +# This file can be generated by ./gensrclist.sh +include Makefile.srcs + +# General configuration variables: +CC = gcc +CPP = g++ +AR = ar + +INSTALLDIR = /usr/local + +# Converts cr/lf to just lf +DOS2UNIX = dos2unix + +COMPILERFLAGS = -O3 +LIBRARIES = -lstdc++ + +MODULES = $(SRCS:.c=.o) +MODULES := $(MODULES:.cpp=.o) +CFLAGS = $(COMPILERFLAGS) $(INCLUDE) +CPPFLAGS = $(COMPILERFLAGS) -Wno-ctor-dtor-privacy $(INCLUDE) + +TARGET = freeimage +STATICLIB = lib$(TARGET).a +SHAREDLIB = lib$(TARGET)-$(VER_MAJOR).$(VER_MINOR).so +LIBNAME = lib$(TARGET).so.$(VER_MAJOR) + + + +default: all + +all: dist + +dist: FreeImage + cp *.a Dist + cp *.so Dist + cp Source/FreeImage.h Dist + +dos2unix: + @$(DOS2UNIX) $(SRCS) $(INCLS) + +FreeImage: $(STATICLIB) $(SHAREDLIB) + +.c.o: + $(CC) $(CFLAGS) -c $< -o $@ + +.cpp.o: + $(CPP) $(CPPFLAGS) -c $< -o $@ + +$(STATICLIB): $(MODULES) + $(AR) r $@ $(MODULES) + +$(SHAREDLIB): $(MODULES) + $(CC) -s -G -Wl,-soname=$(LIBNAME) -o $@ $(MODULES) $(LIBRARIES) + +install: + install -m 644 -o root -g root Source/FreeImage.h $(INSTALLDIR)/include + install -m 644 -o root -g root $(STATICLIB) $(INSTALLDIR)/lib + install -m 755 -o root -g root $(SHAREDLIB) $(INSTALLDIR)/lib + ln -sf $(SHAREDLIB) $(INSTALLDIR)/lib/$(LIBNAME) + +clean: + rm -rf core Dist/*.* u2dtmp* $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME) diff --git a/README.iphone b/README.iphone index 32d41db..0228ac0 100644 --- a/README.iphone +++ b/README.iphone @@ -1,11 +1,11 @@ -Makefile for iPhone - -found on the web, see -http://robertcarlsen.net/2009/03/16/openframeworks-iphone-586 -http://robertcarlsen.net/2009/03/25/openframeworks-iphone-libs-593 -http://4u.jeffcrouse.info/of/ - ------------------------------------------------------------------------------ - -Run "make -f Makefile.iphone". -This should build both the iPhone and iPhone Simulator libraries into the "Dist" folder. +Makefile for iPhone + +found on the web, see +http://robertcarlsen.net/2009/03/16/openframeworks-iphone-586 +http://robertcarlsen.net/2009/03/25/openframeworks-iphone-libs-593 +http://4u.jeffcrouse.info/of/ + +----------------------------------------------------------------------------- + +Run "make -f Makefile.iphone". +This should build both the iPhone and iPhone Simulator libraries into the "Dist" folder. diff --git a/README.linux b/README.linux index 0e8659e..3a38e38 100644 --- a/README.linux +++ b/README.linux @@ -1,50 +1,50 @@ -Release Notes --------------- -This version of the library has been tested under the following OS: -- RedHat Linux 7.3, 8.0 and 9.0 -- Fedora Core 2 -- SuSE Linux Enterprise 8 and SuSE 9.0. -- Debian 4 - -You *do not* need to have any other third party library (libjpeg, libpng, libtiff, libmng and zlib) -installed on your /usr/lib directory in order to compile and use the library. -FreeImage uses its own versions of these libraries. This way, you can be sure that FreeImage will -always use the latest version of each third party library. - -The FreeImage makefile makes use of the gcc "-fvisibility=hidden" in order to avoid incompatibilities between -internal third party libraries and the OS libraries. You may have to remove this option if you're running an -old version of gcc. See also http://gcc.gnu.org/wiki/Visibility - -You should be able to link progams with the -lfreeimage option after the library is compiled and installed. -You can also statically link with libfreeimage.a. -If you use a really old version of gcc and it chokes on the CRs in the file, you can type 'make dos2unix' -to run all of the files through dos2unix which converts CRLF to LF. This no longer appears to be required -for RedHat 7.3 or 9. - -Please let me know how this works for you under other Linux distributions or any other *nix. - -Herve Drolon -FreeImage Project Manager - -Installation ------------- -Note: You will need to have root privileges in order to install the library in the /usr/lib directory. -The installation process is as simple as this : -1) Enter the FreeImage directory -2) Build the distribution : -make -make install -3) Clean all files produced during the build process -make clean - -Compiling FreeImagePlus ------------------------ -FreeImagePlus is a C++ wrapper for FreeImage. -To compile FreeImage as a C++ library, follow these steps : -1) Enter the FreeImage directory -2) Build the distribution : -make -f Makefile.fip -make -f Makefile.fip install -3) Clean all files produced during the build process -make -f Makefile.fip clean - +Release Notes +-------------- +This version of the library has been tested under the following OS: +- RedHat Linux 7.3, 8.0 and 9.0 +- Fedora Core 2 +- SuSE Linux Enterprise 8 and SuSE 9.0. +- Debian 4 + +You *do not* need to have any other third party library (libjpeg, libpng, libtiff, libmng and zlib) +installed on your /usr/lib directory in order to compile and use the library. +FreeImage uses its own versions of these libraries. This way, you can be sure that FreeImage will +always use the latest version of each third party library. + +The FreeImage makefile makes use of the gcc "-fvisibility=hidden" in order to avoid incompatibilities between +internal third party libraries and the OS libraries. You may have to remove this option if you're running an +old version of gcc. See also http://gcc.gnu.org/wiki/Visibility + +You should be able to link progams with the -lfreeimage option after the library is compiled and installed. +You can also statically link with libfreeimage.a. +If you use a really old version of gcc and it chokes on the CRs in the file, you can type 'make dos2unix' +to run all of the files through dos2unix which converts CRLF to LF. This no longer appears to be required +for RedHat 7.3 or 9. + +Please let me know how this works for you under other Linux distributions or any other *nix. + +Herve Drolon +FreeImage Project Manager + +Installation +------------ +Note: You will need to have root privileges in order to install the library in the /usr/lib directory. +The installation process is as simple as this : +1) Enter the FreeImage directory +2) Build the distribution : +make +make install +3) Clean all files produced during the build process +make clean + +Compiling FreeImagePlus +----------------------- +FreeImagePlus is a C++ wrapper for FreeImage. +To compile FreeImage as a C++ library, follow these steps : +1) Enter the FreeImage directory +2) Build the distribution : +make -f Makefile.fip +make -f Makefile.fip install +3) Clean all files produced during the build process +make -f Makefile.fip clean + diff --git a/README.minGW b/README.minGW index 30195c3..df5351e 100644 --- a/README.minGW +++ b/README.minGW @@ -1,236 +1,236 @@ -===================================================================== -Using the FreeImage library with the MinGW Compiler Suite -===================================================================== - -This file describes how to use the precompiled FreeImage library -FreeImage.dll with the MinGW port of the GNU Compiler Collection -(GCC), how to build this library from source using MinGW and how -to use this MinGW-built library with Microsoft Visual Studio. - -Contents: - -I. Prerequisites - -1. Using the precompiled FreeImage library with MinGW - -2. Building the FreeImage library with MinGW - -3. Using the MinGW FreeImage library with Microsoft Visual Studio - -4. Useful links - - ---------------------------------------------------------------------- -I. Prerequisites -===================================================================== - -The procedures described in this document have been developed and -tested using the following free tools: - -1. MinGW GCC Version 4.4.0 (Core and C++ including required libs) -2. MinGW GNU Binutils Version 2.19.1 -3. MinGW GNU Make Version 3.81-20080326-3 -4. MinGW Runtime Version 3.15.2 -5. MinGW API for MS-Windows Version 3.13 -6. GnuWin32 Package CoreUtils Version 5.3.0 (only for building) -7. GnuWin32 Package Sed Version 4.2 (only for creating the GCC - import library)* - -* Sed is only needed to create a GCC-native import library from - the MSVC import library FreeImage.lib. However, since MinGW now - supports linking against MSVC lib files, this process seems to - be obsolete. See section 1. - -Basically, no version dependent capabilities are used so, this -should also work with older versions of the tools mentioned above. -Similarly, the GnuWin32 packages (which I just prefer over MSYS) -could likely be replaced by a properly installed MSYS environment. - -Furthermore, the following preconditions should be met: - -1. The folders 'bin' under both the MinGW and the GnuWin32 - installation directory should have been added to the PATH - environment variable. Likely it is best adding these - directories permanently to PATH through the System - Properties dialog on the Control Panel. - -2. The MinGW Make package only provides a 'mingw32-make.exe' - executable. There is no alias 'make.exe'. However, make is - preconfigured to use 'make' as the default $(MAKE) command. - This seems to be a bug in the MinGW GNU Make distribution. - Thus, a copy of 'mingw32-make.exe' named 'make.exe' should - be placed into MinGW's 'bin' directory. - - - ---------------------------------------------------------------------- -1. Using the precompiled FreeImage library with MinGW -===================================================================== - -When using functions from C/C++, that reside in a DLL, the linker -needs a so called import library, which specifies, how to -dynamically link these external functions during runtime. However, -different linkers use different types or formats of these import -libraries. - -Since the precompiled FreeImage library was build with Microsoft -Visual Studio, in the past, some extra work was required to use it -from MinGW. An import library, that was compatible with GNU ld, -must have been created first. - -However, for several MinGW versions, the GNU linker ld also -supports linking against Microsoft Visual C++ import libraries -directly. So, this effectively makes any circulating HOWTO's on -how to create a GCC-compatible import library from a MSVC lib file -more or less obsolete. Additionally, MinGW does not require the -GCC/Linux usual lib prefix for libraries, so linking with MinGW -against the precompiled FreeImage DLL is as easy as with MSVC: - -1.) Open a DOS shell (run application cmd.exe) - -2.) Ensure, that the 'bin' folder of MinGW is added to the PATH - environment variable (see Prerequisites). - -3.) Link directly against the supplied lib file: - - C:\>gcc -oFreeImageTest.exe FreeImageTest.c -lFreeImage - -Nonetheless, for the sake of completeness, the following steps -describe how to create a native GCC import library: - -1.) Open a DOS shell (run application cmd.exe) - -2.) Ensure, that the 'bin' folders of both MinGW and GnuWin32 are - added to the PATH environment variable (see Prerequisites). - -3.) Create a .def file 'libfreeimage.def', that contains all symbols - exported by the FreeImage library: - - C:\>pexports FreeImage.dll | sed "s/^_//" > libfreeimage.def - -4.) Create the GCC compatible import library 'libfreeimage.a': - - C:\>dlltool --add-underscore -d libfreeimage.def -l libfreeimage.a - -5.) Use this library to link against with GCC: - - C:\>gcc -oFreeImageTest.exe FreeImageTest.c -lfreeimage - - - ---------------------------------------------------------------------- -2. Building the FreeImage library with MinGW -===================================================================== - -You *do not* need to have any other third party library (like -libjpeg, libpng, libtiff, libmng and zlib and others) installed on -your system in order to compile and use the library. FreeImage uses -its own versions of these libraries. This way, you can be sure that -FreeImage will always use the latest and properly tested versions -of of these third party libraries. - -In order to build the FreeImage library under Windows with MinGW -(GCC), ensure that all the prerequisites mentioned above are met. -The MinGW makefile aims to build a Windows DLL, that differs as -least as possible from the precompiled library that comes with the -FreeImage distribution. Thus, the build process also includes the -DLL version resource as well as the __stdcall attribute for all the -exported functions, including the MSVC-like function decorations -_FuncName@nn. - -When building the FreeImage DLL, of course, an import library is -generated, too. However, this input library is not in GCC's native -format, but in MSVC lib format, which makes it usable from both -MinGW and Microsoft Visual Studio with no further processing. - -The MinGW makefile can also be used to build a static library. -However, due to the different function export attributes needed -for both the dynamic and the shared library (DLL), this requires -a separate invocation of make, which in turn needs to rebuild every -source file after switching from dynamic to static and vice versa. -So, a 'make clean' is required each time, the library type is -changed. - -The type of library to build is specified by a variable named -FREEIMAGE_LIBRARY_TYPE, which may either be set directly in the -Makefile.mingw near line 18 or may be specified as an environment -variable. This variable may either take SHARED or STATIC to build -a dynamic link library (DLL) or a static library respectively. -Since this value is used to dynamically form the actual make target -internally, only uppercase values are valid. Defaults to SHARED. - -The MinGW makefile also supports the 'install' target. However, -this only copies the FreeImage dynamic link library (DLL) from the -Dist folder into the %SystemRoot%\system32 folder. So, invoking this -target only makes sense, if the DLL has been built before. - -Since there is neither a common system wide 'include' nor a 'lib' -directory available under Windows, the FreeImage header file -FreeImage.h as well as both the static library and the DLL import -library FreeImage.lib just remain in the 'Dist' folder. - -The following procedure creates the FreeImage dynamic link library -(DLL) from the sources, installs it and also creates a static -FreeImage library: - -1.) Open a DOS shell (run application cmd.exe) - -2.) Ensure, that the 'bin' folders of both MinGW and GnuWin32 are - added to the PATH environment variable (see Prerequisites). - -3.) Create the FreeImage dynamic link library (DLL): - - C:\>make - -4.) Install the FreeImage dynamic link library (DLL): - - C:\>make install - -5.) Clean all files produced by the recent build process: - - C:\>make clean - -6.) Create a static FreeImage library: - - C:\>set FREEIMAGE_LIBRARY_TYPE=STATIC - C:\>make - -You should be able to link progams with the -lFreeImage option -after the shared library is compiled and installed. You can also -link statically against FreeImage.a from MinGW. - - - ---------------------------------------------------------------------- -3. Using the MinGW FreeImage library with Microsoft Visual Studio -===================================================================== - -Since the MinGW makefile creates an import library in MSVC's lib -format, the produced shared library (DLL) can be used from both -MinGW and Microsoft Visual Studio with no further adaption. Just -link to the import library FreeImage.lib from either MinGW or -Microsoft Visual Studio. - - - ---------------------------------------------------------------------- -4. Useful links -===================================================================== - -- The MinGW homepage: - http://www.mingw.org/ - -- The GnuWin32 homepage: - http://gnuwin32.sourceforge.net/ - -- The GCC homepage and online documentation: - http://gcc.gnu.org/ - http://gcc.gnu.org/onlinedocs/ - -- The GNU Binutils homepage and online documentation: - http://www.gnu.org/software/binutils/ - http://sourceware.org/binutils/docs-2.19/ - -- The GNU Make homepage and online documentation: - http://www.gnu.org/software/make/ - http://www.gnu.org/software/make/manual/make.html +===================================================================== +Using the FreeImage library with the MinGW Compiler Suite +===================================================================== + +This file describes how to use the precompiled FreeImage library +FreeImage.dll with the MinGW port of the GNU Compiler Collection +(GCC), how to build this library from source using MinGW and how +to use this MinGW-built library with Microsoft Visual Studio. + +Contents: + +I. Prerequisites + +1. Using the precompiled FreeImage library with MinGW + +2. Building the FreeImage library with MinGW + +3. Using the MinGW FreeImage library with Microsoft Visual Studio + +4. Useful links + + +--------------------------------------------------------------------- +I. Prerequisites +===================================================================== + +The procedures described in this document have been developed and +tested using the following free tools: + +1. MinGW GCC Version 4.4.0 (Core and C++ including required libs) +2. MinGW GNU Binutils Version 2.19.1 +3. MinGW GNU Make Version 3.81-20080326-3 +4. MinGW Runtime Version 3.15.2 +5. MinGW API for MS-Windows Version 3.13 +6. GnuWin32 Package CoreUtils Version 5.3.0 (only for building) +7. GnuWin32 Package Sed Version 4.2 (only for creating the GCC + import library)* + +* Sed is only needed to create a GCC-native import library from + the MSVC import library FreeImage.lib. However, since MinGW now + supports linking against MSVC lib files, this process seems to + be obsolete. See section 1. + +Basically, no version dependent capabilities are used so, this +should also work with older versions of the tools mentioned above. +Similarly, the GnuWin32 packages (which I just prefer over MSYS) +could likely be replaced by a properly installed MSYS environment. + +Furthermore, the following preconditions should be met: + +1. The folders 'bin' under both the MinGW and the GnuWin32 + installation directory should have been added to the PATH + environment variable. Likely it is best adding these + directories permanently to PATH through the System + Properties dialog on the Control Panel. + +2. The MinGW Make package only provides a 'mingw32-make.exe' + executable. There is no alias 'make.exe'. However, make is + preconfigured to use 'make' as the default $(MAKE) command. + This seems to be a bug in the MinGW GNU Make distribution. + Thus, a copy of 'mingw32-make.exe' named 'make.exe' should + be placed into MinGW's 'bin' directory. + + + +--------------------------------------------------------------------- +1. Using the precompiled FreeImage library with MinGW +===================================================================== + +When using functions from C/C++, that reside in a DLL, the linker +needs a so called import library, which specifies, how to +dynamically link these external functions during runtime. However, +different linkers use different types or formats of these import +libraries. + +Since the precompiled FreeImage library was build with Microsoft +Visual Studio, in the past, some extra work was required to use it +from MinGW. An import library, that was compatible with GNU ld, +must have been created first. + +However, for several MinGW versions, the GNU linker ld also +supports linking against Microsoft Visual C++ import libraries +directly. So, this effectively makes any circulating HOWTO's on +how to create a GCC-compatible import library from a MSVC lib file +more or less obsolete. Additionally, MinGW does not require the +GCC/Linux usual lib prefix for libraries, so linking with MinGW +against the precompiled FreeImage DLL is as easy as with MSVC: + +1.) Open a DOS shell (run application cmd.exe) + +2.) Ensure, that the 'bin' folder of MinGW is added to the PATH + environment variable (see Prerequisites). + +3.) Link directly against the supplied lib file: + + C:\>gcc -oFreeImageTest.exe FreeImageTest.c -lFreeImage + +Nonetheless, for the sake of completeness, the following steps +describe how to create a native GCC import library: + +1.) Open a DOS shell (run application cmd.exe) + +2.) Ensure, that the 'bin' folders of both MinGW and GnuWin32 are + added to the PATH environment variable (see Prerequisites). + +3.) Create a .def file 'libfreeimage.def', that contains all symbols + exported by the FreeImage library: + + C:\>pexports FreeImage.dll | sed "s/^_//" > libfreeimage.def + +4.) Create the GCC compatible import library 'libfreeimage.a': + + C:\>dlltool --add-underscore -d libfreeimage.def -l libfreeimage.a + +5.) Use this library to link against with GCC: + + C:\>gcc -oFreeImageTest.exe FreeImageTest.c -lfreeimage + + + +--------------------------------------------------------------------- +2. Building the FreeImage library with MinGW +===================================================================== + +You *do not* need to have any other third party library (like +libjpeg, libpng, libtiff, libmng and zlib and others) installed on +your system in order to compile and use the library. FreeImage uses +its own versions of these libraries. This way, you can be sure that +FreeImage will always use the latest and properly tested versions +of of these third party libraries. + +In order to build the FreeImage library under Windows with MinGW +(GCC), ensure that all the prerequisites mentioned above are met. +The MinGW makefile aims to build a Windows DLL, that differs as +least as possible from the precompiled library that comes with the +FreeImage distribution. Thus, the build process also includes the +DLL version resource as well as the __stdcall attribute for all the +exported functions, including the MSVC-like function decorations +_FuncName@nn. + +When building the FreeImage DLL, of course, an import library is +generated, too. However, this input library is not in GCC's native +format, but in MSVC lib format, which makes it usable from both +MinGW and Microsoft Visual Studio with no further processing. + +The MinGW makefile can also be used to build a static library. +However, due to the different function export attributes needed +for both the dynamic and the shared library (DLL), this requires +a separate invocation of make, which in turn needs to rebuild every +source file after switching from dynamic to static and vice versa. +So, a 'make clean' is required each time, the library type is +changed. + +The type of library to build is specified by a variable named +FREEIMAGE_LIBRARY_TYPE, which may either be set directly in the +Makefile.mingw near line 18 or may be specified as an environment +variable. This variable may either take SHARED or STATIC to build +a dynamic link library (DLL) or a static library respectively. +Since this value is used to dynamically form the actual make target +internally, only uppercase values are valid. Defaults to SHARED. + +The MinGW makefile also supports the 'install' target. However, +this only copies the FreeImage dynamic link library (DLL) from the +Dist folder into the %SystemRoot%\system32 folder. So, invoking this +target only makes sense, if the DLL has been built before. + +Since there is neither a common system wide 'include' nor a 'lib' +directory available under Windows, the FreeImage header file +FreeImage.h as well as both the static library and the DLL import +library FreeImage.lib just remain in the 'Dist' folder. + +The following procedure creates the FreeImage dynamic link library +(DLL) from the sources, installs it and also creates a static +FreeImage library: + +1.) Open a DOS shell (run application cmd.exe) + +2.) Ensure, that the 'bin' folders of both MinGW and GnuWin32 are + added to the PATH environment variable (see Prerequisites). + +3.) Create the FreeImage dynamic link library (DLL): + + C:\>make + +4.) Install the FreeImage dynamic link library (DLL): + + C:\>make install + +5.) Clean all files produced by the recent build process: + + C:\>make clean + +6.) Create a static FreeImage library: + + C:\>set FREEIMAGE_LIBRARY_TYPE=STATIC + C:\>make + +You should be able to link progams with the -lFreeImage option +after the shared library is compiled and installed. You can also +link statically against FreeImage.a from MinGW. + + + +--------------------------------------------------------------------- +3. Using the MinGW FreeImage library with Microsoft Visual Studio +===================================================================== + +Since the MinGW makefile creates an import library in MSVC's lib +format, the produced shared library (DLL) can be used from both +MinGW and Microsoft Visual Studio with no further adaption. Just +link to the import library FreeImage.lib from either MinGW or +Microsoft Visual Studio. + + + +--------------------------------------------------------------------- +4. Useful links +===================================================================== + +- The MinGW homepage: + http://www.mingw.org/ + +- The GnuWin32 homepage: + http://gnuwin32.sourceforge.net/ + +- The GCC homepage and online documentation: + http://gcc.gnu.org/ + http://gcc.gnu.org/onlinedocs/ + +- The GNU Binutils homepage and online documentation: + http://www.gnu.org/software/binutils/ + http://sourceware.org/binutils/docs-2.19/ + +- The GNU Make homepage and online documentation: + http://www.gnu.org/software/make/ + http://www.gnu.org/software/make/manual/make.html diff --git a/README.osx b/README.osx index 16aba34..4f44e6f 100644 --- a/README.osx +++ b/README.osx @@ -1,44 +1,44 @@ -Release Notes --------------- -This version of the library has been tested under OSX 10.3.9 PPC and OSX 10.4.8 Intel. - -While the makefiles will make a .dylib and a .a, it is recommended to simply staticly link with the .a file. - -FreeImage is now built as a Universal Binary and targets the 10.3.9 SDK for PPC and the 10.4u SDK for i386. -This means that you must have both of these SDKs installed and that you must be running on OSX 10.4+ to build FreeImage. -The library will run on 10.3 PPC, but probably not 10.2 or below anymore. wchar.h did not exist on 10.2. - -FreeImage is now built with gcc 4.0 and will thus only run on 10.3.9 or above (some libraries may not exist on 10.3.8 and below). - -The FreeImage makefile makes use of the gcc "-fvisibility=hidden" in order to avoid incompatibilities between -internal third party libraries and the OS libraries. This feature is available with gcc 4 or greater. - - -Ryan Rubley - -Building the Library --------------------- -Makefile detects the environment by calling 'uname'. Assuming this reports 'Darwin' on your system, Makefile will automatically -defer commands to Makefile.osx. If this doesn't work, type 'make -f Makefile.osx' in place of just 'make' - -The build process is as simple as this: -1) Enter the FreeImage directory -2) Build the distribution: -make -3) The libraries and header will be in the Dist directory when the build is finished - -To install FreeImage in the /usr/local/lib and /usr/local/include directories (not recommended): -make install - -To clean all files produced during the build process: -make clean - - -Additional notes ----------------- - -Building on Mac OS X Leopard : - -Install the xcode dev tools from the Leopard disk. -When installing the dev tools make sure to have installed 10.3.9 SDK (it's not selected by default). - +Release Notes +-------------- +This version of the library has been tested under OSX 10.3.9 PPC and OSX 10.4.8 Intel. + +While the makefiles will make a .dylib and a .a, it is recommended to simply staticly link with the .a file. + +FreeImage is now built as a Universal Binary and targets the 10.3.9 SDK for PPC and the 10.4u SDK for i386. +This means that you must have both of these SDKs installed and that you must be running on OSX 10.4+ to build FreeImage. +The library will run on 10.3 PPC, but probably not 10.2 or below anymore. wchar.h did not exist on 10.2. + +FreeImage is now built with gcc 4.0 and will thus only run on 10.3.9 or above (some libraries may not exist on 10.3.8 and below). + +The FreeImage makefile makes use of the gcc "-fvisibility=hidden" in order to avoid incompatibilities between +internal third party libraries and the OS libraries. This feature is available with gcc 4 or greater. + + +Ryan Rubley + +Building the Library +-------------------- +Makefile detects the environment by calling 'uname'. Assuming this reports 'Darwin' on your system, Makefile will automatically +defer commands to Makefile.osx. If this doesn't work, type 'make -f Makefile.osx' in place of just 'make' + +The build process is as simple as this: +1) Enter the FreeImage directory +2) Build the distribution: +make +3) The libraries and header will be in the Dist directory when the build is finished + +To install FreeImage in the /usr/local/lib and /usr/local/include directories (not recommended): +make install + +To clean all files produced during the build process: +make clean + + +Additional notes +---------------- + +Building on Mac OS X Leopard : + +Install the xcode dev tools from the Leopard disk. +When installing the dev tools make sure to have installed 10.3.9 SDK (it's not selected by default). + diff --git a/README.solaris b/README.solaris index bf6431c..bdd1010 100644 --- a/README.solaris +++ b/README.solaris @@ -1,67 +1,67 @@ -Release Notes --------------- -Hey folks, - -I just went through the process of building and using the freeimage library -on Solaris 9. Things don't work out of the box so I thought I would share my -experiences in case someone else wants to do the same. - -I'm using Solaris 9, and I have installed all the development libraries, make, -and the gcc 3.3.2 found on sunfreeware.com. - -You have to use the make from sunfreeware because the Solaris 9 make program -chokes hard on FreeImages makefiles. - -First thing I had to do was modify the main FreeImage makefile: - -1. go to the $(SHAREDLIB): line and replace the $(CC) line with the following. -(there are 2 corrections) - -$(CC) -s -G -Wl,-soname=$(LIBNAME) -o $@ $(MODULES) $(LIBRARIES) - -The two changes are -G instead of -shared, and the = sign instead of a comma -after the -soname. - -2. change INSTALLDIR = /usr/lib to INSTALLDIR = /usr/local/lib - -This is because the sunfreeware tools assume the libs being built will reside -in /usr/local/lib and thus set the default linker search paths to that. Another -solution for this would be to use the -R and -L linker options, but I chose -the easy way :) - -That's it! You can now use freeimage. - -Also, if you have an autoconf/automake project that links against FreeImage, -you can use the following in your configure.in, it works rather well for me: - -AC_CHECK_LIB(freeimage-3.5.0, FreeImage_Initialise, [], - [AC_MSG_ERROR([libfreeimage-3.5.0.so required and missing. See -http://freeimage.sourceforge.net.]) ]) - -the AC_CHECK_LIB macro will not only find the library, it will automatically -link against it as well so you dont have to add it to your Makefile.am. - -I hope this helps someone! - ---- -ogtharox at users.sourceforge.net - - -Installation ------------- -Note: You will need to have root privileges in order to install the library in the /usr/local/lib directory. -The installation process is as simple as this : -1) Enter the FreeImage directory -2) Build the distribution : -make -f Makefile.solaris -make -f Makefile.solaris install -3) Clean all files produced during the build process -make -f Makefile.solaris clean - -Release Notes for Solaris/Sparc --------------------------------- -Under Solaris/Sparc, you will need to modify the following line : -COMPILERFLAGS = -O3 -modified into -COMPILERFLAGS = -O3 -DBYTE_ORDER=BIG_ENDIAN -D__BIG_ENDIAN__ - +Release Notes +-------------- +Hey folks, + +I just went through the process of building and using the freeimage library +on Solaris 9. Things don't work out of the box so I thought I would share my +experiences in case someone else wants to do the same. + +I'm using Solaris 9, and I have installed all the development libraries, make, +and the gcc 3.3.2 found on sunfreeware.com. + +You have to use the make from sunfreeware because the Solaris 9 make program +chokes hard on FreeImages makefiles. + +First thing I had to do was modify the main FreeImage makefile: + +1. go to the $(SHAREDLIB): line and replace the $(CC) line with the following. +(there are 2 corrections) + +$(CC) -s -G -Wl,-soname=$(LIBNAME) -o $@ $(MODULES) $(LIBRARIES) + +The two changes are -G instead of -shared, and the = sign instead of a comma +after the -soname. + +2. change INSTALLDIR = /usr/lib to INSTALLDIR = /usr/local/lib + +This is because the sunfreeware tools assume the libs being built will reside +in /usr/local/lib and thus set the default linker search paths to that. Another +solution for this would be to use the -R and -L linker options, but I chose +the easy way :) + +That's it! You can now use freeimage. + +Also, if you have an autoconf/automake project that links against FreeImage, +you can use the following in your configure.in, it works rather well for me: + +AC_CHECK_LIB(freeimage-3.5.0, FreeImage_Initialise, [], + [AC_MSG_ERROR([libfreeimage-3.5.0.so required and missing. See +http://freeimage.sourceforge.net.]) ]) + +the AC_CHECK_LIB macro will not only find the library, it will automatically +link against it as well so you dont have to add it to your Makefile.am. + +I hope this helps someone! + +--- +ogtharox at users.sourceforge.net + + +Installation +------------ +Note: You will need to have root privileges in order to install the library in the /usr/local/lib directory. +The installation process is as simple as this : +1) Enter the FreeImage directory +2) Build the distribution : +make -f Makefile.solaris +make -f Makefile.solaris install +3) Clean all files produced during the build process +make -f Makefile.solaris clean + +Release Notes for Solaris/Sparc +-------------------------------- +Under Solaris/Sparc, you will need to modify the following line : +COMPILERFLAGS = -O3 +modified into +COMPILERFLAGS = -O3 -DBYTE_ORDER=BIG_ENDIAN -D__BIG_ENDIAN__ + diff --git a/Source/FreeImage.h b/Source/FreeImage.h index fd2092e..ef4581f 100644 --- a/Source/FreeImage.h +++ b/Source/FreeImage.h @@ -1,1104 +1,1104 @@ -// ========================================================== -// FreeImage 3 -// -// Design and implementation by -// - Floris van den Berg (flvdberg@wxs.nl) -// - Hervé Drolon (drolon@infonie.fr) -// -// Contributors: -// - see changes log named 'Whatsnew.txt', see header of each .h and .cpp file -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#ifndef FREEIMAGE_H -#define FREEIMAGE_H - -// Version information ------------------------------------------------------ - -#define FREEIMAGE_MAJOR_VERSION 3 -#define FREEIMAGE_MINOR_VERSION 15 -#define FREEIMAGE_RELEASE_SERIAL 4 - -// Compiler options --------------------------------------------------------- - -#include // needed for UNICODE functions - -#if defined(FREEIMAGE_LIB) - #define DLL_API - #define DLL_CALLCONV -#else - #if defined(_WIN32) || defined(__WIN32__) - #define DLL_CALLCONV __stdcall - // The following ifdef block is the standard way of creating macros which make exporting - // from a DLL simpler. All files within this DLL are compiled with the FREEIMAGE_EXPORTS - // symbol defined on the command line. this symbol should not be defined on any project - // that uses this DLL. This way any other project whose source files include this file see - // DLL_API functions as being imported from a DLL, wheras this DLL sees symbols - // defined with this macro as being exported. - #ifdef FREEIMAGE_EXPORTS - #define DLL_API __declspec(dllexport) - #else - #define DLL_API __declspec(dllimport) - #endif // FREEIMAGE_EXPORTS - #else - // try the gcc visibility support (see http://gcc.gnu.org/wiki/Visibility) - #if defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) - #ifndef GCC_HASCLASSVISIBILITY - #define GCC_HASCLASSVISIBILITY - #endif - #endif // __GNUC__ - #define DLL_CALLCONV - #if defined(GCC_HASCLASSVISIBILITY) - #define DLL_API __attribute__ ((visibility("default"))) - #else - #define DLL_API - #endif - #endif // WIN32 / !WIN32 -#endif // FREEIMAGE_LIB - -// Some versions of gcc may have BYTE_ORDER or __BYTE_ORDER defined -// If your big endian system isn't being detected, add an OS specific check -#if (defined(BYTE_ORDER) && BYTE_ORDER==BIG_ENDIAN) || \ - (defined(__BYTE_ORDER) && __BYTE_ORDER==__BIG_ENDIAN) || \ - defined(__BIG_ENDIAN__) -#define FREEIMAGE_BIGENDIAN -#endif // BYTE_ORDER - -// This really only affects 24 and 32 bit formats, the rest are always RGB order. -#define FREEIMAGE_COLORORDER_BGR 0 -#define FREEIMAGE_COLORORDER_RGB 1 -#if defined(FREEIMAGE_BIGENDIAN) -#define FREEIMAGE_COLORORDER FREEIMAGE_COLORORDER_RGB -#else -#define FREEIMAGE_COLORORDER FREEIMAGE_COLORORDER_BGR -#endif - -// Ensure 4-byte enums if we're using Borland C++ compilers -#if defined(__BORLANDC__) -#pragma option push -b -#endif - -// For C compatibility -------------------------------------------------------- - -#ifdef __cplusplus -#define FI_DEFAULT(x) = x -#define FI_ENUM(x) enum x -#define FI_STRUCT(x) struct x -#else -#define FI_DEFAULT(x) -#define FI_ENUM(x) typedef int x; enum x -#define FI_STRUCT(x) typedef struct x x; struct x -#endif - -// Bitmap types ------------------------------------------------------------- - -FI_STRUCT (FIBITMAP) { void *data; }; -FI_STRUCT (FIMULTIBITMAP) { void *data; }; - -// Types used in the library (directly copied from Windows) ----------------- - -#if defined(__MINGW32__) && defined(_WINDOWS_H) -#define _WINDOWS_ // prevent a bug in MinGW32 -#endif // __MINGW32__ - -#ifndef _WINDOWS_ -#define _WINDOWS_ - -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef NULL -#define NULL 0 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 -#endif - -#ifndef _MSC_VER -// define portable types for 32-bit / 64-bit OS -#include -typedef int32_t BOOL; -typedef uint8_t BYTE; -typedef uint16_t WORD; -typedef uint32_t DWORD; -typedef int32_t LONG; -typedef int64_t INT64; -typedef uint64_t UINT64; -#else -// MS is not C99 ISO compliant -typedef long BOOL; -typedef unsigned char BYTE; -typedef unsigned short WORD; -typedef unsigned long DWORD; -typedef long LONG; -typedef signed __int64 INT64; -typedef unsigned __int64 UINT64; -#endif // _MSC_VER - -#if (defined(_WIN32) || defined(__WIN32__)) -#pragma pack(push, 1) -#else -#pragma pack(1) -#endif // WIN32 - -typedef struct tagRGBQUAD { -#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR - BYTE rgbBlue; - BYTE rgbGreen; - BYTE rgbRed; -#else - BYTE rgbRed; - BYTE rgbGreen; - BYTE rgbBlue; -#endif // FREEIMAGE_COLORORDER - BYTE rgbReserved; -} RGBQUAD; - -typedef struct tagRGBTRIPLE { -#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR - BYTE rgbtBlue; - BYTE rgbtGreen; - BYTE rgbtRed; -#else - BYTE rgbtRed; - BYTE rgbtGreen; - BYTE rgbtBlue; -#endif // FREEIMAGE_COLORORDER -} RGBTRIPLE; - -#if (defined(_WIN32) || defined(__WIN32__)) -#pragma pack(pop) -#else -#pragma pack() -#endif // WIN32 - -typedef struct tagBITMAPINFOHEADER{ - DWORD biSize; - LONG biWidth; - LONG biHeight; - WORD biPlanes; - WORD biBitCount; - DWORD biCompression; - DWORD biSizeImage; - LONG biXPelsPerMeter; - LONG biYPelsPerMeter; - DWORD biClrUsed; - DWORD biClrImportant; -} BITMAPINFOHEADER, *PBITMAPINFOHEADER; - -typedef struct tagBITMAPINFO { - BITMAPINFOHEADER bmiHeader; - RGBQUAD bmiColors[1]; -} BITMAPINFO, *PBITMAPINFO; - -#endif // _WINDOWS_ - -// Types used in the library (specific to FreeImage) ------------------------ - -#if (defined(_WIN32) || defined(__WIN32__)) -#pragma pack(push, 1) -#else -#pragma pack(1) -#endif // WIN32 - -/** 48-bit RGB -*/ -typedef struct tagFIRGB16 { - WORD red; - WORD green; - WORD blue; -} FIRGB16; - -/** 64-bit RGBA -*/ -typedef struct tagFIRGBA16 { - WORD red; - WORD green; - WORD blue; - WORD alpha; -} FIRGBA16; - -/** 96-bit RGB Float -*/ -typedef struct tagFIRGBF { - float red; - float green; - float blue; -} FIRGBF; - -/** 128-bit RGBA Float -*/ -typedef struct tagFIRGBAF { - float red; - float green; - float blue; - float alpha; -} FIRGBAF; - -/** Data structure for COMPLEX type (complex number) -*/ -typedef struct tagFICOMPLEX { - /// real part - double r; - /// imaginary part - double i; -} FICOMPLEX; - -#if (defined(_WIN32) || defined(__WIN32__)) -#pragma pack(pop) -#else -#pragma pack() -#endif // WIN32 - -// Indexes for byte arrays, masks and shifts for treating pixels as words --- -// These coincide with the order of RGBQUAD and RGBTRIPLE ------------------- - -#ifndef FREEIMAGE_BIGENDIAN -#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR -// Little Endian (x86 / MS Windows, Linux) : BGR(A) order -#define FI_RGBA_RED 2 -#define FI_RGBA_GREEN 1 -#define FI_RGBA_BLUE 0 -#define FI_RGBA_ALPHA 3 -#define FI_RGBA_RED_MASK 0x00FF0000 -#define FI_RGBA_GREEN_MASK 0x0000FF00 -#define FI_RGBA_BLUE_MASK 0x000000FF -#define FI_RGBA_ALPHA_MASK 0xFF000000 -#define FI_RGBA_RED_SHIFT 16 -#define FI_RGBA_GREEN_SHIFT 8 -#define FI_RGBA_BLUE_SHIFT 0 -#define FI_RGBA_ALPHA_SHIFT 24 -#else -// Little Endian (x86 / MaxOSX) : RGB(A) order -#define FI_RGBA_RED 0 -#define FI_RGBA_GREEN 1 -#define FI_RGBA_BLUE 2 -#define FI_RGBA_ALPHA 3 -#define FI_RGBA_RED_MASK 0x000000FF -#define FI_RGBA_GREEN_MASK 0x0000FF00 -#define FI_RGBA_BLUE_MASK 0x00FF0000 -#define FI_RGBA_ALPHA_MASK 0xFF000000 -#define FI_RGBA_RED_SHIFT 0 -#define FI_RGBA_GREEN_SHIFT 8 -#define FI_RGBA_BLUE_SHIFT 16 -#define FI_RGBA_ALPHA_SHIFT 24 -#endif // FREEIMAGE_COLORORDER -#else -#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR -// Big Endian (PPC / none) : BGR(A) order -#define FI_RGBA_RED 2 -#define FI_RGBA_GREEN 1 -#define FI_RGBA_BLUE 0 -#define FI_RGBA_ALPHA 3 -#define FI_RGBA_RED_MASK 0x0000FF00 -#define FI_RGBA_GREEN_MASK 0x00FF0000 -#define FI_RGBA_BLUE_MASK 0xFF000000 -#define FI_RGBA_ALPHA_MASK 0x000000FF -#define FI_RGBA_RED_SHIFT 8 -#define FI_RGBA_GREEN_SHIFT 16 -#define FI_RGBA_BLUE_SHIFT 24 -#define FI_RGBA_ALPHA_SHIFT 0 -#else -// Big Endian (PPC / Linux, MaxOSX) : RGB(A) order -#define FI_RGBA_RED 0 -#define FI_RGBA_GREEN 1 -#define FI_RGBA_BLUE 2 -#define FI_RGBA_ALPHA 3 -#define FI_RGBA_RED_MASK 0xFF000000 -#define FI_RGBA_GREEN_MASK 0x00FF0000 -#define FI_RGBA_BLUE_MASK 0x0000FF00 -#define FI_RGBA_ALPHA_MASK 0x000000FF -#define FI_RGBA_RED_SHIFT 24 -#define FI_RGBA_GREEN_SHIFT 16 -#define FI_RGBA_BLUE_SHIFT 8 -#define FI_RGBA_ALPHA_SHIFT 0 -#endif // FREEIMAGE_COLORORDER -#endif // FREEIMAGE_BIGENDIAN - -#define FI_RGBA_RGB_MASK (FI_RGBA_RED_MASK|FI_RGBA_GREEN_MASK|FI_RGBA_BLUE_MASK) - -// The 16bit macros only include masks and shifts, since each color element is not byte aligned - -#define FI16_555_RED_MASK 0x7C00 -#define FI16_555_GREEN_MASK 0x03E0 -#define FI16_555_BLUE_MASK 0x001F -#define FI16_555_RED_SHIFT 10 -#define FI16_555_GREEN_SHIFT 5 -#define FI16_555_BLUE_SHIFT 0 -#define FI16_565_RED_MASK 0xF800 -#define FI16_565_GREEN_MASK 0x07E0 -#define FI16_565_BLUE_MASK 0x001F -#define FI16_565_RED_SHIFT 11 -#define FI16_565_GREEN_SHIFT 5 -#define FI16_565_BLUE_SHIFT 0 - -// ICC profile support ------------------------------------------------------ - -#define FIICC_DEFAULT 0x00 -#define FIICC_COLOR_IS_CMYK 0x01 - -FI_STRUCT (FIICCPROFILE) { - WORD flags; // info flag - DWORD size; // profile's size measured in bytes - void *data; // points to a block of contiguous memory containing the profile -}; - -// Important enums ---------------------------------------------------------- - -/** I/O image format identifiers. -*/ -FI_ENUM(FREE_IMAGE_FORMAT) { - FIF_UNKNOWN = -1, - FIF_BMP = 0, - FIF_ICO = 1, - FIF_JPEG = 2, - FIF_JNG = 3, - FIF_KOALA = 4, - FIF_LBM = 5, - FIF_IFF = FIF_LBM, - FIF_MNG = 6, - FIF_PBM = 7, - FIF_PBMRAW = 8, - FIF_PCD = 9, - FIF_PCX = 10, - FIF_PGM = 11, - FIF_PGMRAW = 12, - FIF_PNG = 13, - FIF_PPM = 14, - FIF_PPMRAW = 15, - FIF_RAS = 16, - FIF_TARGA = 17, - FIF_TIFF = 18, - FIF_WBMP = 19, - FIF_PSD = 20, - FIF_CUT = 21, - FIF_XBM = 22, - FIF_XPM = 23, - FIF_DDS = 24, - FIF_GIF = 25, - FIF_HDR = 26, - FIF_FAXG3 = 27, - FIF_SGI = 28, - FIF_EXR = 29, - FIF_J2K = 30, - FIF_JP2 = 31, - FIF_PFM = 32, - FIF_PICT = 33, - FIF_RAW = 34 -}; - -/** Image type used in FreeImage. -*/ -FI_ENUM(FREE_IMAGE_TYPE) { - FIT_UNKNOWN = 0, // unknown type - FIT_BITMAP = 1, // standard image : 1-, 4-, 8-, 16-, 24-, 32-bit - FIT_UINT16 = 2, // array of unsigned short : unsigned 16-bit - FIT_INT16 = 3, // array of short : signed 16-bit - FIT_UINT32 = 4, // array of unsigned long : unsigned 32-bit - FIT_INT32 = 5, // array of long : signed 32-bit - FIT_FLOAT = 6, // array of float : 32-bit IEEE floating point - FIT_DOUBLE = 7, // array of double : 64-bit IEEE floating point - FIT_COMPLEX = 8, // array of FICOMPLEX : 2 x 64-bit IEEE floating point - FIT_RGB16 = 9, // 48-bit RGB image : 3 x 16-bit - FIT_RGBA16 = 10, // 64-bit RGBA image : 4 x 16-bit - FIT_RGBF = 11, // 96-bit RGB float image : 3 x 32-bit IEEE floating point - FIT_RGBAF = 12 // 128-bit RGBA float image : 4 x 32-bit IEEE floating point -}; - -/** Image color type used in FreeImage. -*/ -FI_ENUM(FREE_IMAGE_COLOR_TYPE) { - FIC_MINISWHITE = 0, // min value is white - FIC_MINISBLACK = 1, // min value is black - FIC_RGB = 2, // RGB color model - FIC_PALETTE = 3, // color map indexed - FIC_RGBALPHA = 4, // RGB color model with alpha channel - FIC_CMYK = 5 // CMYK color model -}; - -/** Color quantization algorithms. -Constants used in FreeImage_ColorQuantize. -*/ -FI_ENUM(FREE_IMAGE_QUANTIZE) { - FIQ_WUQUANT = 0, // Xiaolin Wu color quantization algorithm - FIQ_NNQUANT = 1 // NeuQuant neural-net quantization algorithm by Anthony Dekker -}; - -/** Dithering algorithms. -Constants used in FreeImage_Dither. -*/ -FI_ENUM(FREE_IMAGE_DITHER) { - FID_FS = 0, // Floyd & Steinberg error diffusion - FID_BAYER4x4 = 1, // Bayer ordered dispersed dot dithering (order 2 dithering matrix) - FID_BAYER8x8 = 2, // Bayer ordered dispersed dot dithering (order 3 dithering matrix) - FID_CLUSTER6x6 = 3, // Ordered clustered dot dithering (order 3 - 6x6 matrix) - FID_CLUSTER8x8 = 4, // Ordered clustered dot dithering (order 4 - 8x8 matrix) - FID_CLUSTER16x16= 5, // Ordered clustered dot dithering (order 8 - 16x16 matrix) - FID_BAYER16x16 = 6 // Bayer ordered dispersed dot dithering (order 4 dithering matrix) -}; - -/** Lossless JPEG transformations -Constants used in FreeImage_JPEGTransform -*/ -FI_ENUM(FREE_IMAGE_JPEG_OPERATION) { - FIJPEG_OP_NONE = 0, // no transformation - FIJPEG_OP_FLIP_H = 1, // horizontal flip - FIJPEG_OP_FLIP_V = 2, // vertical flip - FIJPEG_OP_TRANSPOSE = 3, // transpose across UL-to-LR axis - FIJPEG_OP_TRANSVERSE = 4, // transpose across UR-to-LL axis - FIJPEG_OP_ROTATE_90 = 5, // 90-degree clockwise rotation - FIJPEG_OP_ROTATE_180 = 6, // 180-degree rotation - FIJPEG_OP_ROTATE_270 = 7 // 270-degree clockwise (or 90 ccw) -}; - -/** Tone mapping operators. -Constants used in FreeImage_ToneMapping. -*/ -FI_ENUM(FREE_IMAGE_TMO) { - FITMO_DRAGO03 = 0, // Adaptive logarithmic mapping (F. Drago, 2003) - FITMO_REINHARD05 = 1, // Dynamic range reduction inspired by photoreceptor physiology (E. Reinhard, 2005) - FITMO_FATTAL02 = 2 // Gradient domain high dynamic range compression (R. Fattal, 2002) -}; - -/** Upsampling / downsampling filters. -Constants used in FreeImage_Rescale. -*/ -FI_ENUM(FREE_IMAGE_FILTER) { - FILTER_BOX = 0, // Box, pulse, Fourier window, 1st order (constant) b-spline - FILTER_BICUBIC = 1, // Mitchell & Netravali's two-param cubic filter - FILTER_BILINEAR = 2, // Bilinear filter - FILTER_BSPLINE = 3, // 4th order (cubic) b-spline - FILTER_CATMULLROM = 4, // Catmull-Rom spline, Overhauser spline - FILTER_LANCZOS3 = 5 // Lanczos3 filter -}; - -/** Color channels. -Constants used in color manipulation routines. -*/ -FI_ENUM(FREE_IMAGE_COLOR_CHANNEL) { - FICC_RGB = 0, // Use red, green and blue channels - FICC_RED = 1, // Use red channel - FICC_GREEN = 2, // Use green channel - FICC_BLUE = 3, // Use blue channel - FICC_ALPHA = 4, // Use alpha channel - FICC_BLACK = 5, // Use black channel - FICC_REAL = 6, // Complex images: use real part - FICC_IMAG = 7, // Complex images: use imaginary part - FICC_MAG = 8, // Complex images: use magnitude - FICC_PHASE = 9 // Complex images: use phase -}; - -// Metadata support --------------------------------------------------------- - -/** - Tag data type information (based on TIFF specifications) - - Note: RATIONALs are the ratio of two 32-bit integer values. -*/ -FI_ENUM(FREE_IMAGE_MDTYPE) { - FIDT_NOTYPE = 0, // placeholder - FIDT_BYTE = 1, // 8-bit unsigned integer - FIDT_ASCII = 2, // 8-bit bytes w/ last byte null - FIDT_SHORT = 3, // 16-bit unsigned integer - FIDT_LONG = 4, // 32-bit unsigned integer - FIDT_RATIONAL = 5, // 64-bit unsigned fraction - FIDT_SBYTE = 6, // 8-bit signed integer - FIDT_UNDEFINED = 7, // 8-bit untyped data - FIDT_SSHORT = 8, // 16-bit signed integer - FIDT_SLONG = 9, // 32-bit signed integer - FIDT_SRATIONAL = 10, // 64-bit signed fraction - FIDT_FLOAT = 11, // 32-bit IEEE floating point - FIDT_DOUBLE = 12, // 64-bit IEEE floating point - FIDT_IFD = 13, // 32-bit unsigned integer (offset) - FIDT_PALETTE = 14, // 32-bit RGBQUAD - FIDT_LONG8 = 16, // 64-bit unsigned integer - FIDT_SLONG8 = 17, // 64-bit signed integer - FIDT_IFD8 = 18 // 64-bit unsigned integer (offset) -}; - -/** - Metadata models supported by FreeImage -*/ -FI_ENUM(FREE_IMAGE_MDMODEL) { - FIMD_NODATA = -1, - FIMD_COMMENTS = 0, // single comment or keywords - FIMD_EXIF_MAIN = 1, // Exif-TIFF metadata - FIMD_EXIF_EXIF = 2, // Exif-specific metadata - FIMD_EXIF_GPS = 3, // Exif GPS metadata - FIMD_EXIF_MAKERNOTE = 4, // Exif maker note metadata - FIMD_EXIF_INTEROP = 5, // Exif interoperability metadata - FIMD_IPTC = 6, // IPTC/NAA metadata - FIMD_XMP = 7, // Abobe XMP metadata - FIMD_GEOTIFF = 8, // GeoTIFF metadata - FIMD_ANIMATION = 9, // Animation metadata - FIMD_CUSTOM = 10, // Used to attach other metadata types to a dib - FIMD_EXIF_RAW = 11 // Exif metadata as a raw buffer -}; - -/** - Handle to a metadata model -*/ -FI_STRUCT (FIMETADATA) { void *data; }; - -/** - Handle to a FreeImage tag -*/ -FI_STRUCT (FITAG) { void *data; }; - -// File IO routines --------------------------------------------------------- - -#ifndef FREEIMAGE_IO -#define FREEIMAGE_IO - -typedef void* fi_handle; -typedef unsigned (DLL_CALLCONV *FI_ReadProc) (void *buffer, unsigned size, unsigned count, fi_handle handle); -typedef unsigned (DLL_CALLCONV *FI_WriteProc) (void *buffer, unsigned size, unsigned count, fi_handle handle); -typedef int (DLL_CALLCONV *FI_SeekProc) (fi_handle handle, long offset, int origin); -typedef long (DLL_CALLCONV *FI_TellProc) (fi_handle handle); - -#if (defined(_WIN32) || defined(__WIN32__)) -#pragma pack(push, 1) -#else -#pragma pack(1) -#endif // WIN32 - -FI_STRUCT(FreeImageIO) { - FI_ReadProc read_proc; // pointer to the function used to read data - FI_WriteProc write_proc; // pointer to the function used to write data - FI_SeekProc seek_proc; // pointer to the function used to seek - FI_TellProc tell_proc; // pointer to the function used to aquire the current position -}; - -#if (defined(_WIN32) || defined(__WIN32__)) -#pragma pack(pop) -#else -#pragma pack() -#endif // WIN32 - -/** -Handle to a memory I/O stream -*/ -FI_STRUCT (FIMEMORY) { void *data; }; - -#endif // FREEIMAGE_IO - -// Plugin routines ---------------------------------------------------------- - -#ifndef PLUGINS -#define PLUGINS - -typedef const char *(DLL_CALLCONV *FI_FormatProc)(void); -typedef const char *(DLL_CALLCONV *FI_DescriptionProc)(void); -typedef const char *(DLL_CALLCONV *FI_ExtensionListProc)(void); -typedef const char *(DLL_CALLCONV *FI_RegExprProc)(void); -typedef void *(DLL_CALLCONV *FI_OpenProc)(FreeImageIO *io, fi_handle handle, BOOL read); -typedef void (DLL_CALLCONV *FI_CloseProc)(FreeImageIO *io, fi_handle handle, void *data); -typedef int (DLL_CALLCONV *FI_PageCountProc)(FreeImageIO *io, fi_handle handle, void *data); -typedef int (DLL_CALLCONV *FI_PageCapabilityProc)(FreeImageIO *io, fi_handle handle, void *data); -typedef FIBITMAP *(DLL_CALLCONV *FI_LoadProc)(FreeImageIO *io, fi_handle handle, int page, int flags, void *data); -typedef BOOL (DLL_CALLCONV *FI_SaveProc)(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data); -typedef BOOL (DLL_CALLCONV *FI_ValidateProc)(FreeImageIO *io, fi_handle handle); -typedef const char *(DLL_CALLCONV *FI_MimeProc)(void); -typedef BOOL (DLL_CALLCONV *FI_SupportsExportBPPProc)(int bpp); -typedef BOOL (DLL_CALLCONV *FI_SupportsExportTypeProc)(FREE_IMAGE_TYPE type); -typedef BOOL (DLL_CALLCONV *FI_SupportsICCProfilesProc)(void); -typedef BOOL (DLL_CALLCONV *FI_SupportsNoPixelsProc)(void); - -FI_STRUCT (Plugin) { - FI_FormatProc format_proc; - FI_DescriptionProc description_proc; - FI_ExtensionListProc extension_proc; - FI_RegExprProc regexpr_proc; - FI_OpenProc open_proc; - FI_CloseProc close_proc; - FI_PageCountProc pagecount_proc; - FI_PageCapabilityProc pagecapability_proc; - FI_LoadProc load_proc; - FI_SaveProc save_proc; - FI_ValidateProc validate_proc; - FI_MimeProc mime_proc; - FI_SupportsExportBPPProc supports_export_bpp_proc; - FI_SupportsExportTypeProc supports_export_type_proc; - FI_SupportsICCProfilesProc supports_icc_profiles_proc; - FI_SupportsNoPixelsProc supports_no_pixels_proc; -}; - -typedef void (DLL_CALLCONV *FI_InitProc)(Plugin *plugin, int format_id); - -#endif // PLUGINS - - -// Load / Save flag constants ----------------------------------------------- - -#define FIF_LOAD_NOPIXELS 0x8000 // loading: load the image header only (not supported by all plugins, default to full loading) - -#define BMP_DEFAULT 0 -#define BMP_SAVE_RLE 1 -#define CUT_DEFAULT 0 -#define DDS_DEFAULT 0 -#define EXR_DEFAULT 0 // save data as half with piz-based wavelet compression -#define EXR_FLOAT 0x0001 // save data as float instead of as half (not recommended) -#define EXR_NONE 0x0002 // save with no compression -#define EXR_ZIP 0x0004 // save with zlib compression, in blocks of 16 scan lines -#define EXR_PIZ 0x0008 // save with piz-based wavelet compression -#define EXR_PXR24 0x0010 // save with lossy 24-bit float compression -#define EXR_B44 0x0020 // save with lossy 44% float compression - goes to 22% when combined with EXR_LC -#define EXR_LC 0x0040 // save images with one luminance and two chroma channels, rather than as RGB (lossy compression) -#define FAXG3_DEFAULT 0 -#define GIF_DEFAULT 0 -#define GIF_LOAD256 1 // Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color -#define GIF_PLAYBACK 2 // 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading -#define HDR_DEFAULT 0 -#define ICO_DEFAULT 0 -#define ICO_MAKEALPHA 1 // convert to 32bpp and create an alpha channel from the AND-mask when loading -#define IFF_DEFAULT 0 -#define J2K_DEFAULT 0 // save with a 16:1 rate -#define JP2_DEFAULT 0 // save with a 16:1 rate -#define JPEG_DEFAULT 0 // loading (see JPEG_FAST); saving (see JPEG_QUALITYGOOD|JPEG_SUBSAMPLING_420) -#define JPEG_FAST 0x0001 // load the file as fast as possible, sacrificing some quality -#define JPEG_ACCURATE 0x0002 // load the file with the best quality, sacrificing some speed -#define JPEG_CMYK 0x0004 // load separated CMYK "as is" (use | to combine with other load flags) -#define JPEG_EXIFROTATE 0x0008 // load and rotate according to Exif 'Orientation' tag if available -#define JPEG_GREYSCALE 0x0010 // load and convert to a 8-bit greyscale image -#define JPEG_QUALITYSUPERB 0x80 // save with superb quality (100:1) -#define JPEG_QUALITYGOOD 0x0100 // save with good quality (75:1) -#define JPEG_QUALITYNORMAL 0x0200 // save with normal quality (50:1) -#define JPEG_QUALITYAVERAGE 0x0400 // save with average quality (25:1) -#define JPEG_QUALITYBAD 0x0800 // save with bad quality (10:1) -#define JPEG_PROGRESSIVE 0x2000 // save as a progressive-JPEG (use | to combine with other save flags) -#define JPEG_SUBSAMPLING_411 0x1000 // save with high 4x1 chroma subsampling (4:1:1) -#define JPEG_SUBSAMPLING_420 0x4000 // save with medium 2x2 medium chroma subsampling (4:2:0) - default value -#define JPEG_SUBSAMPLING_422 0x8000 // save with low 2x1 chroma subsampling (4:2:2) -#define JPEG_SUBSAMPLING_444 0x10000 // save with no chroma subsampling (4:4:4) -#define JPEG_OPTIMIZE 0x20000 // on saving, compute optimal Huffman coding tables (can reduce a few percent of file size) -#define JPEG_BASELINE 0x40000 // save basic JPEG, without metadata or any markers -#define KOALA_DEFAULT 0 -#define LBM_DEFAULT 0 -#define MNG_DEFAULT 0 -#define PCD_DEFAULT 0 -#define PCD_BASE 1 // load the bitmap sized 768 x 512 -#define PCD_BASEDIV4 2 // load the bitmap sized 384 x 256 -#define PCD_BASEDIV16 3 // load the bitmap sized 192 x 128 -#define PCX_DEFAULT 0 -#define PFM_DEFAULT 0 -#define PICT_DEFAULT 0 -#define PNG_DEFAULT 0 -#define PNG_IGNOREGAMMA 1 // loading: avoid gamma correction -#define PNG_Z_BEST_SPEED 0x0001 // save using ZLib level 1 compression flag (default value is 6) -#define PNG_Z_DEFAULT_COMPRESSION 0x0006 // save using ZLib level 6 compression flag (default recommended value) -#define PNG_Z_BEST_COMPRESSION 0x0009 // save using ZLib level 9 compression flag (default value is 6) -#define PNG_Z_NO_COMPRESSION 0x0100 // save without ZLib compression -#define PNG_INTERLACED 0x0200 // save using Adam7 interlacing (use | to combine with other save flags) -#define PNM_DEFAULT 0 -#define PNM_SAVE_RAW 0 // If set the writer saves in RAW format (i.e. P4, P5 or P6) -#define PNM_SAVE_ASCII 1 // If set the writer saves in ASCII format (i.e. P1, P2 or P3) -#define PSD_DEFAULT 0 -#define PSD_CMYK 1 // reads tags for separated CMYK (default is conversion to RGB) -#define PSD_LAB 2 // reads tags for CIELab (default is conversion to RGB) -#define RAS_DEFAULT 0 -#define RAW_DEFAULT 0 // load the file as linear RGB 48-bit -#define RAW_PREVIEW 1 // try to load the embedded JPEG preview with included Exif Data or default to RGB 24-bit -#define RAW_DISPLAY 2 // load the file as RGB 24-bit -#define RAW_HALFSIZE 4 // output a half-size color image -#define SGI_DEFAULT 0 -#define TARGA_DEFAULT 0 -#define TARGA_LOAD_RGB888 1 // If set the loader converts RGB555 and ARGB8888 -> RGB888. -#define TARGA_SAVE_RLE 2 // If set, the writer saves with RLE compression -#define TIFF_DEFAULT 0 -#define TIFF_CMYK 0x0001 // reads/stores tags for separated CMYK (use | to combine with compression flags) -#define TIFF_PACKBITS 0x0100 // save using PACKBITS compression -#define TIFF_DEFLATE 0x0200 // save using DEFLATE compression (a.k.a. ZLIB compression) -#define TIFF_ADOBE_DEFLATE 0x0400 // save using ADOBE DEFLATE compression -#define TIFF_NONE 0x0800 // save without any compression -#define TIFF_CCITTFAX3 0x1000 // save using CCITT Group 3 fax encoding -#define TIFF_CCITTFAX4 0x2000 // save using CCITT Group 4 fax encoding -#define TIFF_LZW 0x4000 // save using LZW compression -#define TIFF_JPEG 0x8000 // save using JPEG compression -#define TIFF_LOGLUV 0x10000 // save using LogLuv compression -#define WBMP_DEFAULT 0 -#define XBM_DEFAULT 0 -#define XPM_DEFAULT 0 - -// Background filling options --------------------------------------------------------- -// Constants used in FreeImage_FillBackground and FreeImage_EnlargeCanvas - -#define FI_COLOR_IS_RGB_COLOR 0x00 // RGBQUAD color is a RGB color (contains no valid alpha channel) -#define FI_COLOR_IS_RGBA_COLOR 0x01 // RGBQUAD color is a RGBA color (contains a valid alpha channel) -#define FI_COLOR_FIND_EQUAL_COLOR 0x02 // For palettized images: lookup equal RGB color from palette -#define FI_COLOR_ALPHA_IS_INDEX 0x04 // The color's rgbReserved member (alpha) contains the palette index to be used -#define FI_COLOR_PALETTE_SEARCH_MASK (FI_COLOR_FIND_EQUAL_COLOR | FI_COLOR_ALPHA_IS_INDEX) // No color lookup is performed - - -#ifdef __cplusplus -extern "C" { -#endif - -// Init / Error routines ---------------------------------------------------- - -DLL_API void DLL_CALLCONV FreeImage_Initialise(BOOL load_local_plugins_only FI_DEFAULT(FALSE)); -DLL_API void DLL_CALLCONV FreeImage_DeInitialise(void); - -// Version routines --------------------------------------------------------- - -DLL_API const char *DLL_CALLCONV FreeImage_GetVersion(void); -DLL_API const char *DLL_CALLCONV FreeImage_GetCopyrightMessage(void); - -// Message output functions ------------------------------------------------- - -typedef void (*FreeImage_OutputMessageFunction)(FREE_IMAGE_FORMAT fif, const char *msg); -typedef void (DLL_CALLCONV *FreeImage_OutputMessageFunctionStdCall)(FREE_IMAGE_FORMAT fif, const char *msg); - -DLL_API void DLL_CALLCONV FreeImage_SetOutputMessageStdCall(FreeImage_OutputMessageFunctionStdCall omf); -DLL_API void DLL_CALLCONV FreeImage_SetOutputMessage(FreeImage_OutputMessageFunction omf); -DLL_API void DLL_CALLCONV FreeImage_OutputMessageProc(int fif, const char *fmt, ...); - -// Allocate / Clone / Unload routines --------------------------------------- - -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Allocate(int width, int height, int bpp, unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0)); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp FI_DEFAULT(8), unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0)); -DLL_API FIBITMAP * DLL_CALLCONV FreeImage_Clone(FIBITMAP *dib); -DLL_API void DLL_CALLCONV FreeImage_Unload(FIBITMAP *dib); - -// Header loading routines -DLL_API BOOL DLL_CALLCONV FreeImage_HasPixels(FIBITMAP *dib); - -// Load / Save routines ----------------------------------------------------- - -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Load(FREE_IMAGE_FORMAT fif, const char *filename, int flags FI_DEFAULT(0)); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_LoadU(FREE_IMAGE_FORMAT fif, const wchar_t *filename, int flags FI_DEFAULT(0)); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_LoadFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags FI_DEFAULT(0)); -DLL_API BOOL DLL_CALLCONV FreeImage_Save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, const char *filename, int flags FI_DEFAULT(0)); -DLL_API BOOL DLL_CALLCONV FreeImage_SaveU(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, const wchar_t *filename, int flags FI_DEFAULT(0)); -DLL_API BOOL DLL_CALLCONV FreeImage_SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FreeImageIO *io, fi_handle handle, int flags FI_DEFAULT(0)); - -// Memory I/O stream routines ----------------------------------------------- - -DLL_API FIMEMORY *DLL_CALLCONV FreeImage_OpenMemory(BYTE *data FI_DEFAULT(0), DWORD size_in_bytes FI_DEFAULT(0)); -DLL_API void DLL_CALLCONV FreeImage_CloseMemory(FIMEMORY *stream); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_LoadFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream, int flags FI_DEFAULT(0)); -DLL_API BOOL DLL_CALLCONV FreeImage_SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FIMEMORY *stream, int flags FI_DEFAULT(0)); -DLL_API long DLL_CALLCONV FreeImage_TellMemory(FIMEMORY *stream); -DLL_API BOOL DLL_CALLCONV FreeImage_SeekMemory(FIMEMORY *stream, long offset, int origin); -DLL_API BOOL DLL_CALLCONV FreeImage_AcquireMemory(FIMEMORY *stream, BYTE **data, DWORD *size_in_bytes); -DLL_API unsigned DLL_CALLCONV FreeImage_ReadMemory(void *buffer, unsigned size, unsigned count, FIMEMORY *stream); -DLL_API unsigned DLL_CALLCONV FreeImage_WriteMemory(const void *buffer, unsigned size, unsigned count, FIMEMORY *stream); - -DLL_API FIMULTIBITMAP *DLL_CALLCONV FreeImage_LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream, int flags FI_DEFAULT(0)); -DLL_API BOOL DLL_CALLCONV FreeImage_SaveMultiBitmapToMemory(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, FIMEMORY *stream, int flags); - -// Plugin Interface --------------------------------------------------------- - -DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_RegisterLocalPlugin(FI_InitProc proc_address, const char *format FI_DEFAULT(0), const char *description FI_DEFAULT(0), const char *extension FI_DEFAULT(0), const char *regexpr FI_DEFAULT(0)); -DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_RegisterExternalPlugin(const char *path, const char *format FI_DEFAULT(0), const char *description FI_DEFAULT(0), const char *extension FI_DEFAULT(0), const char *regexpr FI_DEFAULT(0)); -DLL_API int DLL_CALLCONV FreeImage_GetFIFCount(void); -DLL_API int DLL_CALLCONV FreeImage_SetPluginEnabled(FREE_IMAGE_FORMAT fif, BOOL enable); -DLL_API int DLL_CALLCONV FreeImage_IsPluginEnabled(FREE_IMAGE_FORMAT fif); -DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromFormat(const char *format); -DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromMime(const char *mime); -DLL_API const char *DLL_CALLCONV FreeImage_GetFormatFromFIF(FREE_IMAGE_FORMAT fif); -DLL_API const char *DLL_CALLCONV FreeImage_GetFIFExtensionList(FREE_IMAGE_FORMAT fif); -DLL_API const char *DLL_CALLCONV FreeImage_GetFIFDescription(FREE_IMAGE_FORMAT fif); -DLL_API const char *DLL_CALLCONV FreeImage_GetFIFRegExpr(FREE_IMAGE_FORMAT fif); -DLL_API const char *DLL_CALLCONV FreeImage_GetFIFMimeType(FREE_IMAGE_FORMAT fif); -DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromFilename(const char *filename); -DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromFilenameU(const wchar_t *filename); -DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsReading(FREE_IMAGE_FORMAT fif); -DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsWriting(FREE_IMAGE_FORMAT fif); -DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsExportBPP(FREE_IMAGE_FORMAT fif, int bpp); -DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsExportType(FREE_IMAGE_FORMAT fif, FREE_IMAGE_TYPE type); -DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsICCProfiles(FREE_IMAGE_FORMAT fif); -DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsNoPixels(FREE_IMAGE_FORMAT fif); - -// Multipaging interface ---------------------------------------------------- - -DLL_API FIMULTIBITMAP * DLL_CALLCONV FreeImage_OpenMultiBitmap(FREE_IMAGE_FORMAT fif, const char *filename, BOOL create_new, BOOL read_only, BOOL keep_cache_in_memory FI_DEFAULT(FALSE), int flags FI_DEFAULT(0)); -DLL_API FIMULTIBITMAP * DLL_CALLCONV FreeImage_OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags FI_DEFAULT(0)); -DLL_API BOOL DLL_CALLCONV FreeImage_SaveMultiBitmapToHandle(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, FreeImageIO *io, fi_handle handle, int flags FI_DEFAULT(0)); -DLL_API BOOL DLL_CALLCONV FreeImage_CloseMultiBitmap(FIMULTIBITMAP *bitmap, int flags FI_DEFAULT(0)); -DLL_API int DLL_CALLCONV FreeImage_GetPageCount(FIMULTIBITMAP *bitmap); -DLL_API void DLL_CALLCONV FreeImage_AppendPage(FIMULTIBITMAP *bitmap, FIBITMAP *data); -DLL_API void DLL_CALLCONV FreeImage_InsertPage(FIMULTIBITMAP *bitmap, int page, FIBITMAP *data); -DLL_API void DLL_CALLCONV FreeImage_DeletePage(FIMULTIBITMAP *bitmap, int page); -DLL_API FIBITMAP * DLL_CALLCONV FreeImage_LockPage(FIMULTIBITMAP *bitmap, int page); -DLL_API void DLL_CALLCONV FreeImage_UnlockPage(FIMULTIBITMAP *bitmap, FIBITMAP *data, BOOL changed); -DLL_API BOOL DLL_CALLCONV FreeImage_MovePage(FIMULTIBITMAP *bitmap, int target, int source); -DLL_API BOOL DLL_CALLCONV FreeImage_GetLockedPageNumbers(FIMULTIBITMAP *bitmap, int *pages, int *count); - -// Filetype request routines ------------------------------------------------ - -DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFileType(const char *filename, int size FI_DEFAULT(0)); -DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFileTypeU(const wchar_t *filename, int size FI_DEFAULT(0)); -DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFileTypeFromHandle(FreeImageIO *io, fi_handle handle, int size FI_DEFAULT(0)); -DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFileTypeFromMemory(FIMEMORY *stream, int size FI_DEFAULT(0)); - -// Image type request routine ----------------------------------------------- - -DLL_API FREE_IMAGE_TYPE DLL_CALLCONV FreeImage_GetImageType(FIBITMAP *dib); - -// FreeImage helper routines ------------------------------------------------ - -DLL_API BOOL DLL_CALLCONV FreeImage_IsLittleEndian(void); -DLL_API BOOL DLL_CALLCONV FreeImage_LookupX11Color(const char *szColor, BYTE *nRed, BYTE *nGreen, BYTE *nBlue); -DLL_API BOOL DLL_CALLCONV FreeImage_LookupSVGColor(const char *szColor, BYTE *nRed, BYTE *nGreen, BYTE *nBlue); - -// Pixel access routines ---------------------------------------------------- - -DLL_API BYTE *DLL_CALLCONV FreeImage_GetBits(FIBITMAP *dib); -DLL_API BYTE *DLL_CALLCONV FreeImage_GetScanLine(FIBITMAP *dib, int scanline); - -DLL_API BOOL DLL_CALLCONV FreeImage_GetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value); -DLL_API BOOL DLL_CALLCONV FreeImage_GetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value); -DLL_API BOOL DLL_CALLCONV FreeImage_SetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value); -DLL_API BOOL DLL_CALLCONV FreeImage_SetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value); - -// DIB info routines -------------------------------------------------------- - -DLL_API unsigned DLL_CALLCONV FreeImage_GetColorsUsed(FIBITMAP *dib); -DLL_API unsigned DLL_CALLCONV FreeImage_GetBPP(FIBITMAP *dib); -DLL_API unsigned DLL_CALLCONV FreeImage_GetWidth(FIBITMAP *dib); -DLL_API unsigned DLL_CALLCONV FreeImage_GetHeight(FIBITMAP *dib); -DLL_API unsigned DLL_CALLCONV FreeImage_GetLine(FIBITMAP *dib); -DLL_API unsigned DLL_CALLCONV FreeImage_GetPitch(FIBITMAP *dib); -DLL_API unsigned DLL_CALLCONV FreeImage_GetDIBSize(FIBITMAP *dib); -DLL_API RGBQUAD *DLL_CALLCONV FreeImage_GetPalette(FIBITMAP *dib); - -DLL_API unsigned DLL_CALLCONV FreeImage_GetDotsPerMeterX(FIBITMAP *dib); -DLL_API unsigned DLL_CALLCONV FreeImage_GetDotsPerMeterY(FIBITMAP *dib); -DLL_API void DLL_CALLCONV FreeImage_SetDotsPerMeterX(FIBITMAP *dib, unsigned res); -DLL_API void DLL_CALLCONV FreeImage_SetDotsPerMeterY(FIBITMAP *dib, unsigned res); - -DLL_API BITMAPINFOHEADER *DLL_CALLCONV FreeImage_GetInfoHeader(FIBITMAP *dib); -DLL_API BITMAPINFO *DLL_CALLCONV FreeImage_GetInfo(FIBITMAP *dib); -DLL_API FREE_IMAGE_COLOR_TYPE DLL_CALLCONV FreeImage_GetColorType(FIBITMAP *dib); - -DLL_API unsigned DLL_CALLCONV FreeImage_GetRedMask(FIBITMAP *dib); -DLL_API unsigned DLL_CALLCONV FreeImage_GetGreenMask(FIBITMAP *dib); -DLL_API unsigned DLL_CALLCONV FreeImage_GetBlueMask(FIBITMAP *dib); - -DLL_API unsigned DLL_CALLCONV FreeImage_GetTransparencyCount(FIBITMAP *dib); -DLL_API BYTE * DLL_CALLCONV FreeImage_GetTransparencyTable(FIBITMAP *dib); -DLL_API void DLL_CALLCONV FreeImage_SetTransparent(FIBITMAP *dib, BOOL enabled); -DLL_API void DLL_CALLCONV FreeImage_SetTransparencyTable(FIBITMAP *dib, BYTE *table, int count); -DLL_API BOOL DLL_CALLCONV FreeImage_IsTransparent(FIBITMAP *dib); -DLL_API void DLL_CALLCONV FreeImage_SetTransparentIndex(FIBITMAP *dib, int index); -DLL_API int DLL_CALLCONV FreeImage_GetTransparentIndex(FIBITMAP *dib); - -DLL_API BOOL DLL_CALLCONV FreeImage_HasBackgroundColor(FIBITMAP *dib); -DLL_API BOOL DLL_CALLCONV FreeImage_GetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor); -DLL_API BOOL DLL_CALLCONV FreeImage_SetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor); - -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_GetThumbnail(FIBITMAP *dib); -DLL_API BOOL DLL_CALLCONV FreeImage_SetThumbnail(FIBITMAP *dib, FIBITMAP *thumbnail); - -// ICC profile routines ----------------------------------------------------- - -DLL_API FIICCPROFILE *DLL_CALLCONV FreeImage_GetICCProfile(FIBITMAP *dib); -DLL_API FIICCPROFILE *DLL_CALLCONV FreeImage_CreateICCProfile(FIBITMAP *dib, void *data, long size); -DLL_API void DLL_CALLCONV FreeImage_DestroyICCProfile(FIBITMAP *dib); - -// Line conversion routines ------------------------------------------------- - -DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To4(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To4(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To4_555(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To4_565(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To4(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To4(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To8(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To8(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To8_555(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To8_565(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To8(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To8(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To16_555(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To16_555(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To16_555(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine16_565_To16_555(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To16_555(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To16_555(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To16_565(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To16_565(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To16_565(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine16_555_To16_565(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To16_565(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To16_565(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To24_555(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To24_565(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To24(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To32_555(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To32_565(BYTE *target, BYTE *source, int width_in_pixels); -DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To32(BYTE *target, BYTE *source, int width_in_pixels); - -// Smart conversion routines ------------------------------------------------ - -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo4Bits(FIBITMAP *dib); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo8Bits(FIBITMAP *dib); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToGreyscale(FIBITMAP *dib); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo16Bits555(FIBITMAP *dib); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo16Bits565(FIBITMAP *dib); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo24Bits(FIBITMAP *dib); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo32Bits(FIBITMAP *dib); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ColorQuantize(FIBITMAP *dib, FREE_IMAGE_QUANTIZE quantize); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ColorQuantizeEx(FIBITMAP *dib, FREE_IMAGE_QUANTIZE quantize FI_DEFAULT(FIQ_WUQUANT), int PaletteSize FI_DEFAULT(256), int ReserveSize FI_DEFAULT(0), RGBQUAD *ReservePalette FI_DEFAULT(NULL)); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Threshold(FIBITMAP *dib, BYTE T); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Dither(FIBITMAP *dib, FREE_IMAGE_DITHER algorithm); - -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertFromRawBits(BYTE *bits, int width, int height, int pitch, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask, BOOL topdown FI_DEFAULT(FALSE)); -DLL_API void DLL_CALLCONV FreeImage_ConvertToRawBits(BYTE *bits, FIBITMAP *dib, int pitch, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask, BOOL topdown FI_DEFAULT(FALSE)); - -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToFloat(FIBITMAP *dib); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToRGBF(FIBITMAP *dib); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToUINT16(FIBITMAP *dib); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToRGB16(FIBITMAP *dib); - -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToStandardType(FIBITMAP *src, BOOL scale_linear FI_DEFAULT(TRUE)); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToType(FIBITMAP *src, FREE_IMAGE_TYPE dst_type, BOOL scale_linear FI_DEFAULT(TRUE)); - -// tone mapping operators -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ToneMapping(FIBITMAP *dib, FREE_IMAGE_TMO tmo, double first_param FI_DEFAULT(0), double second_param FI_DEFAULT(0)); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_TmoDrago03(FIBITMAP *src, double gamma FI_DEFAULT(2.2), double exposure FI_DEFAULT(0)); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_TmoReinhard05(FIBITMAP *src, double intensity FI_DEFAULT(0), double contrast FI_DEFAULT(0)); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_TmoReinhard05Ex(FIBITMAP *src, double intensity FI_DEFAULT(0), double contrast FI_DEFAULT(0), double adaptation FI_DEFAULT(1), double color_correction FI_DEFAULT(0)); - -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_TmoFattal02(FIBITMAP *src, double color_saturation FI_DEFAULT(0.5), double attenuation FI_DEFAULT(0.85)); - -// ZLib interface ----------------------------------------------------------- - -DLL_API DWORD DLL_CALLCONV FreeImage_ZLibCompress(BYTE *target, DWORD target_size, BYTE *source, DWORD source_size); -DLL_API DWORD DLL_CALLCONV FreeImage_ZLibUncompress(BYTE *target, DWORD target_size, BYTE *source, DWORD source_size); -DLL_API DWORD DLL_CALLCONV FreeImage_ZLibGZip(BYTE *target, DWORD target_size, BYTE *source, DWORD source_size); -DLL_API DWORD DLL_CALLCONV FreeImage_ZLibGUnzip(BYTE *target, DWORD target_size, BYTE *source, DWORD source_size); -DLL_API DWORD DLL_CALLCONV FreeImage_ZLibCRC32(DWORD crc, BYTE *source, DWORD source_size); - -// -------------------------------------------------------------------------- -// Metadata routines -------------------------------------------------------- -// -------------------------------------------------------------------------- - -// tag creation / destruction -DLL_API FITAG *DLL_CALLCONV FreeImage_CreateTag(void); -DLL_API void DLL_CALLCONV FreeImage_DeleteTag(FITAG *tag); -DLL_API FITAG *DLL_CALLCONV FreeImage_CloneTag(FITAG *tag); - -// tag getters and setters -DLL_API const char *DLL_CALLCONV FreeImage_GetTagKey(FITAG *tag); -DLL_API const char *DLL_CALLCONV FreeImage_GetTagDescription(FITAG *tag); -DLL_API WORD DLL_CALLCONV FreeImage_GetTagID(FITAG *tag); -DLL_API FREE_IMAGE_MDTYPE DLL_CALLCONV FreeImage_GetTagType(FITAG *tag); -DLL_API DWORD DLL_CALLCONV FreeImage_GetTagCount(FITAG *tag); -DLL_API DWORD DLL_CALLCONV FreeImage_GetTagLength(FITAG *tag); -DLL_API const void *DLL_CALLCONV FreeImage_GetTagValue(FITAG *tag); - -DLL_API BOOL DLL_CALLCONV FreeImage_SetTagKey(FITAG *tag, const char *key); -DLL_API BOOL DLL_CALLCONV FreeImage_SetTagDescription(FITAG *tag, const char *description); -DLL_API BOOL DLL_CALLCONV FreeImage_SetTagID(FITAG *tag, WORD id); -DLL_API BOOL DLL_CALLCONV FreeImage_SetTagType(FITAG *tag, FREE_IMAGE_MDTYPE type); -DLL_API BOOL DLL_CALLCONV FreeImage_SetTagCount(FITAG *tag, DWORD count); -DLL_API BOOL DLL_CALLCONV FreeImage_SetTagLength(FITAG *tag, DWORD length); -DLL_API BOOL DLL_CALLCONV FreeImage_SetTagValue(FITAG *tag, const void *value); - -// iterator -DLL_API FIMETADATA *DLL_CALLCONV FreeImage_FindFirstMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, FITAG **tag); -DLL_API BOOL DLL_CALLCONV FreeImage_FindNextMetadata(FIMETADATA *mdhandle, FITAG **tag); -DLL_API void DLL_CALLCONV FreeImage_FindCloseMetadata(FIMETADATA *mdhandle); - -// metadata setter and getter -DLL_API BOOL DLL_CALLCONV FreeImage_SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, FITAG *tag); -DLL_API BOOL DLL_CALLCONV FreeImage_GetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, FITAG **tag); - -// helpers -DLL_API unsigned DLL_CALLCONV FreeImage_GetMetadataCount(FREE_IMAGE_MDMODEL model, FIBITMAP *dib); -DLL_API BOOL DLL_CALLCONV FreeImage_CloneMetadata(FIBITMAP *dst, FIBITMAP *src); - -// tag to C string conversion -DLL_API const char* DLL_CALLCONV FreeImage_TagToString(FREE_IMAGE_MDMODEL model, FITAG *tag, char *Make FI_DEFAULT(NULL)); - -// -------------------------------------------------------------------------- -// Image manipulation toolkit ----------------------------------------------- -// -------------------------------------------------------------------------- - -// rotation and flipping -/// @deprecated see FreeImage_Rotate -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_RotateClassic(FIBITMAP *dib, double angle); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Rotate(FIBITMAP *dib, double angle, const void *bkcolor FI_DEFAULT(NULL)); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_RotateEx(FIBITMAP *dib, double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask); -DLL_API BOOL DLL_CALLCONV FreeImage_FlipHorizontal(FIBITMAP *dib); -DLL_API BOOL DLL_CALLCONV FreeImage_FlipVertical(FIBITMAP *dib); -DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransform(const char *src_file, const char *dst_file, FREE_IMAGE_JPEG_OPERATION operation, BOOL perfect FI_DEFAULT(FALSE)); -DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransformU(const wchar_t *src_file, const wchar_t *dst_file, FREE_IMAGE_JPEG_OPERATION operation, BOOL perfect FI_DEFAULT(FALSE)); - -// upsampling / downsampling -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Rescale(FIBITMAP *dib, int dst_width, int dst_height, FREE_IMAGE_FILTER filter); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_MakeThumbnail(FIBITMAP *dib, int max_pixel_size, BOOL convert FI_DEFAULT(TRUE)); - -// color manipulation routines (point operations) -DLL_API BOOL DLL_CALLCONV FreeImage_AdjustCurve(FIBITMAP *dib, BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel); -DLL_API BOOL DLL_CALLCONV FreeImage_AdjustGamma(FIBITMAP *dib, double gamma); -DLL_API BOOL DLL_CALLCONV FreeImage_AdjustBrightness(FIBITMAP *dib, double percentage); -DLL_API BOOL DLL_CALLCONV FreeImage_AdjustContrast(FIBITMAP *dib, double percentage); -DLL_API BOOL DLL_CALLCONV FreeImage_Invert(FIBITMAP *dib); -DLL_API BOOL DLL_CALLCONV FreeImage_GetHistogram(FIBITMAP *dib, DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel FI_DEFAULT(FICC_BLACK)); -DLL_API int DLL_CALLCONV FreeImage_GetAdjustColorsLookupTable(BYTE *LUT, double brightness, double contrast, double gamma, BOOL invert); -DLL_API BOOL DLL_CALLCONV FreeImage_AdjustColors(FIBITMAP *dib, double brightness, double contrast, double gamma, BOOL invert FI_DEFAULT(FALSE)); -DLL_API unsigned DLL_CALLCONV FreeImage_ApplyColorMapping(FIBITMAP *dib, RGBQUAD *srccolors, RGBQUAD *dstcolors, unsigned count, BOOL ignore_alpha, BOOL swap); -DLL_API unsigned DLL_CALLCONV FreeImage_SwapColors(FIBITMAP *dib, RGBQUAD *color_a, RGBQUAD *color_b, BOOL ignore_alpha); -DLL_API unsigned DLL_CALLCONV FreeImage_ApplyPaletteIndexMapping(FIBITMAP *dib, BYTE *srcindices, BYTE *dstindices, unsigned count, BOOL swap); -DLL_API unsigned DLL_CALLCONV FreeImage_SwapPaletteIndices(FIBITMAP *dib, BYTE *index_a, BYTE *index_b); - -// channel processing routines -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_GetChannel(FIBITMAP *dib, FREE_IMAGE_COLOR_CHANNEL channel); -DLL_API BOOL DLL_CALLCONV FreeImage_SetChannel(FIBITMAP *dst, FIBITMAP *src, FREE_IMAGE_COLOR_CHANNEL channel); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_GetComplexChannel(FIBITMAP *src, FREE_IMAGE_COLOR_CHANNEL channel); -DLL_API BOOL DLL_CALLCONV FreeImage_SetComplexChannel(FIBITMAP *dst, FIBITMAP *src, FREE_IMAGE_COLOR_CHANNEL channel); - -// copy / paste / composite routines -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Copy(FIBITMAP *dib, int left, int top, int right, int bottom); -DLL_API BOOL DLL_CALLCONV FreeImage_Paste(FIBITMAP *dst, FIBITMAP *src, int left, int top, int alpha); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Composite(FIBITMAP *fg, BOOL useFileBkg FI_DEFAULT(FALSE), RGBQUAD *appBkColor FI_DEFAULT(NULL), FIBITMAP *bg FI_DEFAULT(NULL)); -DLL_API BOOL DLL_CALLCONV FreeImage_JPEGCrop(const char *src_file, const char *dst_file, int left, int top, int right, int bottom); -DLL_API BOOL DLL_CALLCONV FreeImage_JPEGCropU(const wchar_t *src_file, const wchar_t *dst_file, int left, int top, int right, int bottom); -DLL_API BOOL DLL_CALLCONV FreeImage_PreMultiplyWithAlpha(FIBITMAP *dib); - -// background filling routines -DLL_API BOOL DLL_CALLCONV FreeImage_FillBackground(FIBITMAP *dib, const void *color, int options FI_DEFAULT(0)); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_EnlargeCanvas(FIBITMAP *src, int left, int top, int right, int bottom, const void *color, int options FI_DEFAULT(0)); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_AllocateEx(int width, int height, int bpp, const RGBQUAD *color, int options FI_DEFAULT(0), const RGBQUAD *palette FI_DEFAULT(NULL), unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0)); -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp, const void *color, int options FI_DEFAULT(0), const RGBQUAD *palette FI_DEFAULT(NULL), unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0)); - -// miscellaneous algorithms -DLL_API FIBITMAP *DLL_CALLCONV FreeImage_MultigridPoissonSolver(FIBITMAP *Laplacian, int ncycle FI_DEFAULT(3)); - -// restore the borland-specific enum size option -#if defined(__BORLANDC__) -#pragma option pop -#endif - -#ifdef __cplusplus -} -#endif - -#endif // FREEIMAGE_H +// ========================================================== +// FreeImage 3 +// +// Design and implementation by +// - Floris van den Berg (flvdberg@wxs.nl) +// - Hervé Drolon (drolon@infonie.fr) +// +// Contributors: +// - see changes log named 'Whatsnew.txt', see header of each .h and .cpp file +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#ifndef FREEIMAGE_H +#define FREEIMAGE_H + +// Version information ------------------------------------------------------ + +#define FREEIMAGE_MAJOR_VERSION 3 +#define FREEIMAGE_MINOR_VERSION 15 +#define FREEIMAGE_RELEASE_SERIAL 4 + +// Compiler options --------------------------------------------------------- + +#include // needed for UNICODE functions + +#if defined(FREEIMAGE_LIB) + #define DLL_API + #define DLL_CALLCONV +#else + #if defined(_WIN32) || defined(__WIN32__) + #define DLL_CALLCONV __stdcall + // The following ifdef block is the standard way of creating macros which make exporting + // from a DLL simpler. All files within this DLL are compiled with the FREEIMAGE_EXPORTS + // symbol defined on the command line. this symbol should not be defined on any project + // that uses this DLL. This way any other project whose source files include this file see + // DLL_API functions as being imported from a DLL, wheras this DLL sees symbols + // defined with this macro as being exported. + #ifdef FREEIMAGE_EXPORTS + #define DLL_API __declspec(dllexport) + #else + #define DLL_API __declspec(dllimport) + #endif // FREEIMAGE_EXPORTS + #else + // try the gcc visibility support (see http://gcc.gnu.org/wiki/Visibility) + #if defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) + #ifndef GCC_HASCLASSVISIBILITY + #define GCC_HASCLASSVISIBILITY + #endif + #endif // __GNUC__ + #define DLL_CALLCONV + #if defined(GCC_HASCLASSVISIBILITY) + #define DLL_API __attribute__ ((visibility("default"))) + #else + #define DLL_API + #endif + #endif // WIN32 / !WIN32 +#endif // FREEIMAGE_LIB + +// Some versions of gcc may have BYTE_ORDER or __BYTE_ORDER defined +// If your big endian system isn't being detected, add an OS specific check +#if (defined(BYTE_ORDER) && BYTE_ORDER==BIG_ENDIAN) || \ + (defined(__BYTE_ORDER) && __BYTE_ORDER==__BIG_ENDIAN) || \ + defined(__BIG_ENDIAN__) +#define FREEIMAGE_BIGENDIAN +#endif // BYTE_ORDER + +// This really only affects 24 and 32 bit formats, the rest are always RGB order. +#define FREEIMAGE_COLORORDER_BGR 0 +#define FREEIMAGE_COLORORDER_RGB 1 +#if defined(FREEIMAGE_BIGENDIAN) +#define FREEIMAGE_COLORORDER FREEIMAGE_COLORORDER_RGB +#else +#define FREEIMAGE_COLORORDER FREEIMAGE_COLORORDER_BGR +#endif + +// Ensure 4-byte enums if we're using Borland C++ compilers +#if defined(__BORLANDC__) +#pragma option push -b +#endif + +// For C compatibility -------------------------------------------------------- + +#ifdef __cplusplus +#define FI_DEFAULT(x) = x +#define FI_ENUM(x) enum x +#define FI_STRUCT(x) struct x +#else +#define FI_DEFAULT(x) +#define FI_ENUM(x) typedef int x; enum x +#define FI_STRUCT(x) typedef struct x x; struct x +#endif + +// Bitmap types ------------------------------------------------------------- + +FI_STRUCT (FIBITMAP) { void *data; }; +FI_STRUCT (FIMULTIBITMAP) { void *data; }; + +// Types used in the library (directly copied from Windows) ----------------- + +#if defined(__MINGW32__) && defined(_WINDOWS_H) +#define _WINDOWS_ // prevent a bug in MinGW32 +#endif // __MINGW32__ + +#ifndef _WINDOWS_ +#define _WINDOWS_ + +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef NULL +#define NULL 0 +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 +#endif + +#ifndef _MSC_VER +// define portable types for 32-bit / 64-bit OS +#include +typedef int32_t BOOL; +typedef uint8_t BYTE; +typedef uint16_t WORD; +typedef uint32_t DWORD; +typedef int32_t LONG; +typedef int64_t INT64; +typedef uint64_t UINT64; +#else +// MS is not C99 ISO compliant +typedef long BOOL; +typedef unsigned char BYTE; +typedef unsigned short WORD; +typedef unsigned long DWORD; +typedef long LONG; +typedef signed __int64 INT64; +typedef unsigned __int64 UINT64; +#endif // _MSC_VER + +#if (defined(_WIN32) || defined(__WIN32__)) +#pragma pack(push, 1) +#else +#pragma pack(1) +#endif // WIN32 + +typedef struct tagRGBQUAD { +#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR + BYTE rgbBlue; + BYTE rgbGreen; + BYTE rgbRed; +#else + BYTE rgbRed; + BYTE rgbGreen; + BYTE rgbBlue; +#endif // FREEIMAGE_COLORORDER + BYTE rgbReserved; +} RGBQUAD; + +typedef struct tagRGBTRIPLE { +#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR + BYTE rgbtBlue; + BYTE rgbtGreen; + BYTE rgbtRed; +#else + BYTE rgbtRed; + BYTE rgbtGreen; + BYTE rgbtBlue; +#endif // FREEIMAGE_COLORORDER +} RGBTRIPLE; + +#if (defined(_WIN32) || defined(__WIN32__)) +#pragma pack(pop) +#else +#pragma pack() +#endif // WIN32 + +typedef struct tagBITMAPINFOHEADER{ + DWORD biSize; + LONG biWidth; + LONG biHeight; + WORD biPlanes; + WORD biBitCount; + DWORD biCompression; + DWORD biSizeImage; + LONG biXPelsPerMeter; + LONG biYPelsPerMeter; + DWORD biClrUsed; + DWORD biClrImportant; +} BITMAPINFOHEADER, *PBITMAPINFOHEADER; + +typedef struct tagBITMAPINFO { + BITMAPINFOHEADER bmiHeader; + RGBQUAD bmiColors[1]; +} BITMAPINFO, *PBITMAPINFO; + +#endif // _WINDOWS_ + +// Types used in the library (specific to FreeImage) ------------------------ + +#if (defined(_WIN32) || defined(__WIN32__)) +#pragma pack(push, 1) +#else +#pragma pack(1) +#endif // WIN32 + +/** 48-bit RGB +*/ +typedef struct tagFIRGB16 { + WORD red; + WORD green; + WORD blue; +} FIRGB16; + +/** 64-bit RGBA +*/ +typedef struct tagFIRGBA16 { + WORD red; + WORD green; + WORD blue; + WORD alpha; +} FIRGBA16; + +/** 96-bit RGB Float +*/ +typedef struct tagFIRGBF { + float red; + float green; + float blue; +} FIRGBF; + +/** 128-bit RGBA Float +*/ +typedef struct tagFIRGBAF { + float red; + float green; + float blue; + float alpha; +} FIRGBAF; + +/** Data structure for COMPLEX type (complex number) +*/ +typedef struct tagFICOMPLEX { + /// real part + double r; + /// imaginary part + double i; +} FICOMPLEX; + +#if (defined(_WIN32) || defined(__WIN32__)) +#pragma pack(pop) +#else +#pragma pack() +#endif // WIN32 + +// Indexes for byte arrays, masks and shifts for treating pixels as words --- +// These coincide with the order of RGBQUAD and RGBTRIPLE ------------------- + +#ifndef FREEIMAGE_BIGENDIAN +#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR +// Little Endian (x86 / MS Windows, Linux) : BGR(A) order +#define FI_RGBA_RED 2 +#define FI_RGBA_GREEN 1 +#define FI_RGBA_BLUE 0 +#define FI_RGBA_ALPHA 3 +#define FI_RGBA_RED_MASK 0x00FF0000 +#define FI_RGBA_GREEN_MASK 0x0000FF00 +#define FI_RGBA_BLUE_MASK 0x000000FF +#define FI_RGBA_ALPHA_MASK 0xFF000000 +#define FI_RGBA_RED_SHIFT 16 +#define FI_RGBA_GREEN_SHIFT 8 +#define FI_RGBA_BLUE_SHIFT 0 +#define FI_RGBA_ALPHA_SHIFT 24 +#else +// Little Endian (x86 / MaxOSX) : RGB(A) order +#define FI_RGBA_RED 0 +#define FI_RGBA_GREEN 1 +#define FI_RGBA_BLUE 2 +#define FI_RGBA_ALPHA 3 +#define FI_RGBA_RED_MASK 0x000000FF +#define FI_RGBA_GREEN_MASK 0x0000FF00 +#define FI_RGBA_BLUE_MASK 0x00FF0000 +#define FI_RGBA_ALPHA_MASK 0xFF000000 +#define FI_RGBA_RED_SHIFT 0 +#define FI_RGBA_GREEN_SHIFT 8 +#define FI_RGBA_BLUE_SHIFT 16 +#define FI_RGBA_ALPHA_SHIFT 24 +#endif // FREEIMAGE_COLORORDER +#else +#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR +// Big Endian (PPC / none) : BGR(A) order +#define FI_RGBA_RED 2 +#define FI_RGBA_GREEN 1 +#define FI_RGBA_BLUE 0 +#define FI_RGBA_ALPHA 3 +#define FI_RGBA_RED_MASK 0x0000FF00 +#define FI_RGBA_GREEN_MASK 0x00FF0000 +#define FI_RGBA_BLUE_MASK 0xFF000000 +#define FI_RGBA_ALPHA_MASK 0x000000FF +#define FI_RGBA_RED_SHIFT 8 +#define FI_RGBA_GREEN_SHIFT 16 +#define FI_RGBA_BLUE_SHIFT 24 +#define FI_RGBA_ALPHA_SHIFT 0 +#else +// Big Endian (PPC / Linux, MaxOSX) : RGB(A) order +#define FI_RGBA_RED 0 +#define FI_RGBA_GREEN 1 +#define FI_RGBA_BLUE 2 +#define FI_RGBA_ALPHA 3 +#define FI_RGBA_RED_MASK 0xFF000000 +#define FI_RGBA_GREEN_MASK 0x00FF0000 +#define FI_RGBA_BLUE_MASK 0x0000FF00 +#define FI_RGBA_ALPHA_MASK 0x000000FF +#define FI_RGBA_RED_SHIFT 24 +#define FI_RGBA_GREEN_SHIFT 16 +#define FI_RGBA_BLUE_SHIFT 8 +#define FI_RGBA_ALPHA_SHIFT 0 +#endif // FREEIMAGE_COLORORDER +#endif // FREEIMAGE_BIGENDIAN + +#define FI_RGBA_RGB_MASK (FI_RGBA_RED_MASK|FI_RGBA_GREEN_MASK|FI_RGBA_BLUE_MASK) + +// The 16bit macros only include masks and shifts, since each color element is not byte aligned + +#define FI16_555_RED_MASK 0x7C00 +#define FI16_555_GREEN_MASK 0x03E0 +#define FI16_555_BLUE_MASK 0x001F +#define FI16_555_RED_SHIFT 10 +#define FI16_555_GREEN_SHIFT 5 +#define FI16_555_BLUE_SHIFT 0 +#define FI16_565_RED_MASK 0xF800 +#define FI16_565_GREEN_MASK 0x07E0 +#define FI16_565_BLUE_MASK 0x001F +#define FI16_565_RED_SHIFT 11 +#define FI16_565_GREEN_SHIFT 5 +#define FI16_565_BLUE_SHIFT 0 + +// ICC profile support ------------------------------------------------------ + +#define FIICC_DEFAULT 0x00 +#define FIICC_COLOR_IS_CMYK 0x01 + +FI_STRUCT (FIICCPROFILE) { + WORD flags; // info flag + DWORD size; // profile's size measured in bytes + void *data; // points to a block of contiguous memory containing the profile +}; + +// Important enums ---------------------------------------------------------- + +/** I/O image format identifiers. +*/ +FI_ENUM(FREE_IMAGE_FORMAT) { + FIF_UNKNOWN = -1, + FIF_BMP = 0, + FIF_ICO = 1, + FIF_JPEG = 2, + FIF_JNG = 3, + FIF_KOALA = 4, + FIF_LBM = 5, + FIF_IFF = FIF_LBM, + FIF_MNG = 6, + FIF_PBM = 7, + FIF_PBMRAW = 8, + FIF_PCD = 9, + FIF_PCX = 10, + FIF_PGM = 11, + FIF_PGMRAW = 12, + FIF_PNG = 13, + FIF_PPM = 14, + FIF_PPMRAW = 15, + FIF_RAS = 16, + FIF_TARGA = 17, + FIF_TIFF = 18, + FIF_WBMP = 19, + FIF_PSD = 20, + FIF_CUT = 21, + FIF_XBM = 22, + FIF_XPM = 23, + FIF_DDS = 24, + FIF_GIF = 25, + FIF_HDR = 26, + FIF_FAXG3 = 27, + FIF_SGI = 28, + FIF_EXR = 29, + FIF_J2K = 30, + FIF_JP2 = 31, + FIF_PFM = 32, + FIF_PICT = 33, + FIF_RAW = 34 +}; + +/** Image type used in FreeImage. +*/ +FI_ENUM(FREE_IMAGE_TYPE) { + FIT_UNKNOWN = 0, // unknown type + FIT_BITMAP = 1, // standard image : 1-, 4-, 8-, 16-, 24-, 32-bit + FIT_UINT16 = 2, // array of unsigned short : unsigned 16-bit + FIT_INT16 = 3, // array of short : signed 16-bit + FIT_UINT32 = 4, // array of unsigned long : unsigned 32-bit + FIT_INT32 = 5, // array of long : signed 32-bit + FIT_FLOAT = 6, // array of float : 32-bit IEEE floating point + FIT_DOUBLE = 7, // array of double : 64-bit IEEE floating point + FIT_COMPLEX = 8, // array of FICOMPLEX : 2 x 64-bit IEEE floating point + FIT_RGB16 = 9, // 48-bit RGB image : 3 x 16-bit + FIT_RGBA16 = 10, // 64-bit RGBA image : 4 x 16-bit + FIT_RGBF = 11, // 96-bit RGB float image : 3 x 32-bit IEEE floating point + FIT_RGBAF = 12 // 128-bit RGBA float image : 4 x 32-bit IEEE floating point +}; + +/** Image color type used in FreeImage. +*/ +FI_ENUM(FREE_IMAGE_COLOR_TYPE) { + FIC_MINISWHITE = 0, // min value is white + FIC_MINISBLACK = 1, // min value is black + FIC_RGB = 2, // RGB color model + FIC_PALETTE = 3, // color map indexed + FIC_RGBALPHA = 4, // RGB color model with alpha channel + FIC_CMYK = 5 // CMYK color model +}; + +/** Color quantization algorithms. +Constants used in FreeImage_ColorQuantize. +*/ +FI_ENUM(FREE_IMAGE_QUANTIZE) { + FIQ_WUQUANT = 0, // Xiaolin Wu color quantization algorithm + FIQ_NNQUANT = 1 // NeuQuant neural-net quantization algorithm by Anthony Dekker +}; + +/** Dithering algorithms. +Constants used in FreeImage_Dither. +*/ +FI_ENUM(FREE_IMAGE_DITHER) { + FID_FS = 0, // Floyd & Steinberg error diffusion + FID_BAYER4x4 = 1, // Bayer ordered dispersed dot dithering (order 2 dithering matrix) + FID_BAYER8x8 = 2, // Bayer ordered dispersed dot dithering (order 3 dithering matrix) + FID_CLUSTER6x6 = 3, // Ordered clustered dot dithering (order 3 - 6x6 matrix) + FID_CLUSTER8x8 = 4, // Ordered clustered dot dithering (order 4 - 8x8 matrix) + FID_CLUSTER16x16= 5, // Ordered clustered dot dithering (order 8 - 16x16 matrix) + FID_BAYER16x16 = 6 // Bayer ordered dispersed dot dithering (order 4 dithering matrix) +}; + +/** Lossless JPEG transformations +Constants used in FreeImage_JPEGTransform +*/ +FI_ENUM(FREE_IMAGE_JPEG_OPERATION) { + FIJPEG_OP_NONE = 0, // no transformation + FIJPEG_OP_FLIP_H = 1, // horizontal flip + FIJPEG_OP_FLIP_V = 2, // vertical flip + FIJPEG_OP_TRANSPOSE = 3, // transpose across UL-to-LR axis + FIJPEG_OP_TRANSVERSE = 4, // transpose across UR-to-LL axis + FIJPEG_OP_ROTATE_90 = 5, // 90-degree clockwise rotation + FIJPEG_OP_ROTATE_180 = 6, // 180-degree rotation + FIJPEG_OP_ROTATE_270 = 7 // 270-degree clockwise (or 90 ccw) +}; + +/** Tone mapping operators. +Constants used in FreeImage_ToneMapping. +*/ +FI_ENUM(FREE_IMAGE_TMO) { + FITMO_DRAGO03 = 0, // Adaptive logarithmic mapping (F. Drago, 2003) + FITMO_REINHARD05 = 1, // Dynamic range reduction inspired by photoreceptor physiology (E. Reinhard, 2005) + FITMO_FATTAL02 = 2 // Gradient domain high dynamic range compression (R. Fattal, 2002) +}; + +/** Upsampling / downsampling filters. +Constants used in FreeImage_Rescale. +*/ +FI_ENUM(FREE_IMAGE_FILTER) { + FILTER_BOX = 0, // Box, pulse, Fourier window, 1st order (constant) b-spline + FILTER_BICUBIC = 1, // Mitchell & Netravali's two-param cubic filter + FILTER_BILINEAR = 2, // Bilinear filter + FILTER_BSPLINE = 3, // 4th order (cubic) b-spline + FILTER_CATMULLROM = 4, // Catmull-Rom spline, Overhauser spline + FILTER_LANCZOS3 = 5 // Lanczos3 filter +}; + +/** Color channels. +Constants used in color manipulation routines. +*/ +FI_ENUM(FREE_IMAGE_COLOR_CHANNEL) { + FICC_RGB = 0, // Use red, green and blue channels + FICC_RED = 1, // Use red channel + FICC_GREEN = 2, // Use green channel + FICC_BLUE = 3, // Use blue channel + FICC_ALPHA = 4, // Use alpha channel + FICC_BLACK = 5, // Use black channel + FICC_REAL = 6, // Complex images: use real part + FICC_IMAG = 7, // Complex images: use imaginary part + FICC_MAG = 8, // Complex images: use magnitude + FICC_PHASE = 9 // Complex images: use phase +}; + +// Metadata support --------------------------------------------------------- + +/** + Tag data type information (based on TIFF specifications) + + Note: RATIONALs are the ratio of two 32-bit integer values. +*/ +FI_ENUM(FREE_IMAGE_MDTYPE) { + FIDT_NOTYPE = 0, // placeholder + FIDT_BYTE = 1, // 8-bit unsigned integer + FIDT_ASCII = 2, // 8-bit bytes w/ last byte null + FIDT_SHORT = 3, // 16-bit unsigned integer + FIDT_LONG = 4, // 32-bit unsigned integer + FIDT_RATIONAL = 5, // 64-bit unsigned fraction + FIDT_SBYTE = 6, // 8-bit signed integer + FIDT_UNDEFINED = 7, // 8-bit untyped data + FIDT_SSHORT = 8, // 16-bit signed integer + FIDT_SLONG = 9, // 32-bit signed integer + FIDT_SRATIONAL = 10, // 64-bit signed fraction + FIDT_FLOAT = 11, // 32-bit IEEE floating point + FIDT_DOUBLE = 12, // 64-bit IEEE floating point + FIDT_IFD = 13, // 32-bit unsigned integer (offset) + FIDT_PALETTE = 14, // 32-bit RGBQUAD + FIDT_LONG8 = 16, // 64-bit unsigned integer + FIDT_SLONG8 = 17, // 64-bit signed integer + FIDT_IFD8 = 18 // 64-bit unsigned integer (offset) +}; + +/** + Metadata models supported by FreeImage +*/ +FI_ENUM(FREE_IMAGE_MDMODEL) { + FIMD_NODATA = -1, + FIMD_COMMENTS = 0, // single comment or keywords + FIMD_EXIF_MAIN = 1, // Exif-TIFF metadata + FIMD_EXIF_EXIF = 2, // Exif-specific metadata + FIMD_EXIF_GPS = 3, // Exif GPS metadata + FIMD_EXIF_MAKERNOTE = 4, // Exif maker note metadata + FIMD_EXIF_INTEROP = 5, // Exif interoperability metadata + FIMD_IPTC = 6, // IPTC/NAA metadata + FIMD_XMP = 7, // Abobe XMP metadata + FIMD_GEOTIFF = 8, // GeoTIFF metadata + FIMD_ANIMATION = 9, // Animation metadata + FIMD_CUSTOM = 10, // Used to attach other metadata types to a dib + FIMD_EXIF_RAW = 11 // Exif metadata as a raw buffer +}; + +/** + Handle to a metadata model +*/ +FI_STRUCT (FIMETADATA) { void *data; }; + +/** + Handle to a FreeImage tag +*/ +FI_STRUCT (FITAG) { void *data; }; + +// File IO routines --------------------------------------------------------- + +#ifndef FREEIMAGE_IO +#define FREEIMAGE_IO + +typedef void* fi_handle; +typedef unsigned (DLL_CALLCONV *FI_ReadProc) (void *buffer, unsigned size, unsigned count, fi_handle handle); +typedef unsigned (DLL_CALLCONV *FI_WriteProc) (void *buffer, unsigned size, unsigned count, fi_handle handle); +typedef int (DLL_CALLCONV *FI_SeekProc) (fi_handle handle, long offset, int origin); +typedef long (DLL_CALLCONV *FI_TellProc) (fi_handle handle); + +#if (defined(_WIN32) || defined(__WIN32__)) +#pragma pack(push, 1) +#else +#pragma pack(1) +#endif // WIN32 + +FI_STRUCT(FreeImageIO) { + FI_ReadProc read_proc; // pointer to the function used to read data + FI_WriteProc write_proc; // pointer to the function used to write data + FI_SeekProc seek_proc; // pointer to the function used to seek + FI_TellProc tell_proc; // pointer to the function used to aquire the current position +}; + +#if (defined(_WIN32) || defined(__WIN32__)) +#pragma pack(pop) +#else +#pragma pack() +#endif // WIN32 + +/** +Handle to a memory I/O stream +*/ +FI_STRUCT (FIMEMORY) { void *data; }; + +#endif // FREEIMAGE_IO + +// Plugin routines ---------------------------------------------------------- + +#ifndef PLUGINS +#define PLUGINS + +typedef const char *(DLL_CALLCONV *FI_FormatProc)(void); +typedef const char *(DLL_CALLCONV *FI_DescriptionProc)(void); +typedef const char *(DLL_CALLCONV *FI_ExtensionListProc)(void); +typedef const char *(DLL_CALLCONV *FI_RegExprProc)(void); +typedef void *(DLL_CALLCONV *FI_OpenProc)(FreeImageIO *io, fi_handle handle, BOOL read); +typedef void (DLL_CALLCONV *FI_CloseProc)(FreeImageIO *io, fi_handle handle, void *data); +typedef int (DLL_CALLCONV *FI_PageCountProc)(FreeImageIO *io, fi_handle handle, void *data); +typedef int (DLL_CALLCONV *FI_PageCapabilityProc)(FreeImageIO *io, fi_handle handle, void *data); +typedef FIBITMAP *(DLL_CALLCONV *FI_LoadProc)(FreeImageIO *io, fi_handle handle, int page, int flags, void *data); +typedef BOOL (DLL_CALLCONV *FI_SaveProc)(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data); +typedef BOOL (DLL_CALLCONV *FI_ValidateProc)(FreeImageIO *io, fi_handle handle); +typedef const char *(DLL_CALLCONV *FI_MimeProc)(void); +typedef BOOL (DLL_CALLCONV *FI_SupportsExportBPPProc)(int bpp); +typedef BOOL (DLL_CALLCONV *FI_SupportsExportTypeProc)(FREE_IMAGE_TYPE type); +typedef BOOL (DLL_CALLCONV *FI_SupportsICCProfilesProc)(void); +typedef BOOL (DLL_CALLCONV *FI_SupportsNoPixelsProc)(void); + +FI_STRUCT (Plugin) { + FI_FormatProc format_proc; + FI_DescriptionProc description_proc; + FI_ExtensionListProc extension_proc; + FI_RegExprProc regexpr_proc; + FI_OpenProc open_proc; + FI_CloseProc close_proc; + FI_PageCountProc pagecount_proc; + FI_PageCapabilityProc pagecapability_proc; + FI_LoadProc load_proc; + FI_SaveProc save_proc; + FI_ValidateProc validate_proc; + FI_MimeProc mime_proc; + FI_SupportsExportBPPProc supports_export_bpp_proc; + FI_SupportsExportTypeProc supports_export_type_proc; + FI_SupportsICCProfilesProc supports_icc_profiles_proc; + FI_SupportsNoPixelsProc supports_no_pixels_proc; +}; + +typedef void (DLL_CALLCONV *FI_InitProc)(Plugin *plugin, int format_id); + +#endif // PLUGINS + + +// Load / Save flag constants ----------------------------------------------- + +#define FIF_LOAD_NOPIXELS 0x8000 // loading: load the image header only (not supported by all plugins, default to full loading) + +#define BMP_DEFAULT 0 +#define BMP_SAVE_RLE 1 +#define CUT_DEFAULT 0 +#define DDS_DEFAULT 0 +#define EXR_DEFAULT 0 // save data as half with piz-based wavelet compression +#define EXR_FLOAT 0x0001 // save data as float instead of as half (not recommended) +#define EXR_NONE 0x0002 // save with no compression +#define EXR_ZIP 0x0004 // save with zlib compression, in blocks of 16 scan lines +#define EXR_PIZ 0x0008 // save with piz-based wavelet compression +#define EXR_PXR24 0x0010 // save with lossy 24-bit float compression +#define EXR_B44 0x0020 // save with lossy 44% float compression - goes to 22% when combined with EXR_LC +#define EXR_LC 0x0040 // save images with one luminance and two chroma channels, rather than as RGB (lossy compression) +#define FAXG3_DEFAULT 0 +#define GIF_DEFAULT 0 +#define GIF_LOAD256 1 // Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color +#define GIF_PLAYBACK 2 // 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading +#define HDR_DEFAULT 0 +#define ICO_DEFAULT 0 +#define ICO_MAKEALPHA 1 // convert to 32bpp and create an alpha channel from the AND-mask when loading +#define IFF_DEFAULT 0 +#define J2K_DEFAULT 0 // save with a 16:1 rate +#define JP2_DEFAULT 0 // save with a 16:1 rate +#define JPEG_DEFAULT 0 // loading (see JPEG_FAST); saving (see JPEG_QUALITYGOOD|JPEG_SUBSAMPLING_420) +#define JPEG_FAST 0x0001 // load the file as fast as possible, sacrificing some quality +#define JPEG_ACCURATE 0x0002 // load the file with the best quality, sacrificing some speed +#define JPEG_CMYK 0x0004 // load separated CMYK "as is" (use | to combine with other load flags) +#define JPEG_EXIFROTATE 0x0008 // load and rotate according to Exif 'Orientation' tag if available +#define JPEG_GREYSCALE 0x0010 // load and convert to a 8-bit greyscale image +#define JPEG_QUALITYSUPERB 0x80 // save with superb quality (100:1) +#define JPEG_QUALITYGOOD 0x0100 // save with good quality (75:1) +#define JPEG_QUALITYNORMAL 0x0200 // save with normal quality (50:1) +#define JPEG_QUALITYAVERAGE 0x0400 // save with average quality (25:1) +#define JPEG_QUALITYBAD 0x0800 // save with bad quality (10:1) +#define JPEG_PROGRESSIVE 0x2000 // save as a progressive-JPEG (use | to combine with other save flags) +#define JPEG_SUBSAMPLING_411 0x1000 // save with high 4x1 chroma subsampling (4:1:1) +#define JPEG_SUBSAMPLING_420 0x4000 // save with medium 2x2 medium chroma subsampling (4:2:0) - default value +#define JPEG_SUBSAMPLING_422 0x8000 // save with low 2x1 chroma subsampling (4:2:2) +#define JPEG_SUBSAMPLING_444 0x10000 // save with no chroma subsampling (4:4:4) +#define JPEG_OPTIMIZE 0x20000 // on saving, compute optimal Huffman coding tables (can reduce a few percent of file size) +#define JPEG_BASELINE 0x40000 // save basic JPEG, without metadata or any markers +#define KOALA_DEFAULT 0 +#define LBM_DEFAULT 0 +#define MNG_DEFAULT 0 +#define PCD_DEFAULT 0 +#define PCD_BASE 1 // load the bitmap sized 768 x 512 +#define PCD_BASEDIV4 2 // load the bitmap sized 384 x 256 +#define PCD_BASEDIV16 3 // load the bitmap sized 192 x 128 +#define PCX_DEFAULT 0 +#define PFM_DEFAULT 0 +#define PICT_DEFAULT 0 +#define PNG_DEFAULT 0 +#define PNG_IGNOREGAMMA 1 // loading: avoid gamma correction +#define PNG_Z_BEST_SPEED 0x0001 // save using ZLib level 1 compression flag (default value is 6) +#define PNG_Z_DEFAULT_COMPRESSION 0x0006 // save using ZLib level 6 compression flag (default recommended value) +#define PNG_Z_BEST_COMPRESSION 0x0009 // save using ZLib level 9 compression flag (default value is 6) +#define PNG_Z_NO_COMPRESSION 0x0100 // save without ZLib compression +#define PNG_INTERLACED 0x0200 // save using Adam7 interlacing (use | to combine with other save flags) +#define PNM_DEFAULT 0 +#define PNM_SAVE_RAW 0 // If set the writer saves in RAW format (i.e. P4, P5 or P6) +#define PNM_SAVE_ASCII 1 // If set the writer saves in ASCII format (i.e. P1, P2 or P3) +#define PSD_DEFAULT 0 +#define PSD_CMYK 1 // reads tags for separated CMYK (default is conversion to RGB) +#define PSD_LAB 2 // reads tags for CIELab (default is conversion to RGB) +#define RAS_DEFAULT 0 +#define RAW_DEFAULT 0 // load the file as linear RGB 48-bit +#define RAW_PREVIEW 1 // try to load the embedded JPEG preview with included Exif Data or default to RGB 24-bit +#define RAW_DISPLAY 2 // load the file as RGB 24-bit +#define RAW_HALFSIZE 4 // output a half-size color image +#define SGI_DEFAULT 0 +#define TARGA_DEFAULT 0 +#define TARGA_LOAD_RGB888 1 // If set the loader converts RGB555 and ARGB8888 -> RGB888. +#define TARGA_SAVE_RLE 2 // If set, the writer saves with RLE compression +#define TIFF_DEFAULT 0 +#define TIFF_CMYK 0x0001 // reads/stores tags for separated CMYK (use | to combine with compression flags) +#define TIFF_PACKBITS 0x0100 // save using PACKBITS compression +#define TIFF_DEFLATE 0x0200 // save using DEFLATE compression (a.k.a. ZLIB compression) +#define TIFF_ADOBE_DEFLATE 0x0400 // save using ADOBE DEFLATE compression +#define TIFF_NONE 0x0800 // save without any compression +#define TIFF_CCITTFAX3 0x1000 // save using CCITT Group 3 fax encoding +#define TIFF_CCITTFAX4 0x2000 // save using CCITT Group 4 fax encoding +#define TIFF_LZW 0x4000 // save using LZW compression +#define TIFF_JPEG 0x8000 // save using JPEG compression +#define TIFF_LOGLUV 0x10000 // save using LogLuv compression +#define WBMP_DEFAULT 0 +#define XBM_DEFAULT 0 +#define XPM_DEFAULT 0 + +// Background filling options --------------------------------------------------------- +// Constants used in FreeImage_FillBackground and FreeImage_EnlargeCanvas + +#define FI_COLOR_IS_RGB_COLOR 0x00 // RGBQUAD color is a RGB color (contains no valid alpha channel) +#define FI_COLOR_IS_RGBA_COLOR 0x01 // RGBQUAD color is a RGBA color (contains a valid alpha channel) +#define FI_COLOR_FIND_EQUAL_COLOR 0x02 // For palettized images: lookup equal RGB color from palette +#define FI_COLOR_ALPHA_IS_INDEX 0x04 // The color's rgbReserved member (alpha) contains the palette index to be used +#define FI_COLOR_PALETTE_SEARCH_MASK (FI_COLOR_FIND_EQUAL_COLOR | FI_COLOR_ALPHA_IS_INDEX) // No color lookup is performed + + +#ifdef __cplusplus +extern "C" { +#endif + +// Init / Error routines ---------------------------------------------------- + +DLL_API void DLL_CALLCONV FreeImage_Initialise(BOOL load_local_plugins_only FI_DEFAULT(FALSE)); +DLL_API void DLL_CALLCONV FreeImage_DeInitialise(void); + +// Version routines --------------------------------------------------------- + +DLL_API const char *DLL_CALLCONV FreeImage_GetVersion(void); +DLL_API const char *DLL_CALLCONV FreeImage_GetCopyrightMessage(void); + +// Message output functions ------------------------------------------------- + +typedef void (*FreeImage_OutputMessageFunction)(FREE_IMAGE_FORMAT fif, const char *msg); +typedef void (DLL_CALLCONV *FreeImage_OutputMessageFunctionStdCall)(FREE_IMAGE_FORMAT fif, const char *msg); + +DLL_API void DLL_CALLCONV FreeImage_SetOutputMessageStdCall(FreeImage_OutputMessageFunctionStdCall omf); +DLL_API void DLL_CALLCONV FreeImage_SetOutputMessage(FreeImage_OutputMessageFunction omf); +DLL_API void DLL_CALLCONV FreeImage_OutputMessageProc(int fif, const char *fmt, ...); + +// Allocate / Clone / Unload routines --------------------------------------- + +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Allocate(int width, int height, int bpp, unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0)); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp FI_DEFAULT(8), unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0)); +DLL_API FIBITMAP * DLL_CALLCONV FreeImage_Clone(FIBITMAP *dib); +DLL_API void DLL_CALLCONV FreeImage_Unload(FIBITMAP *dib); + +// Header loading routines +DLL_API BOOL DLL_CALLCONV FreeImage_HasPixels(FIBITMAP *dib); + +// Load / Save routines ----------------------------------------------------- + +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Load(FREE_IMAGE_FORMAT fif, const char *filename, int flags FI_DEFAULT(0)); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_LoadU(FREE_IMAGE_FORMAT fif, const wchar_t *filename, int flags FI_DEFAULT(0)); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_LoadFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags FI_DEFAULT(0)); +DLL_API BOOL DLL_CALLCONV FreeImage_Save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, const char *filename, int flags FI_DEFAULT(0)); +DLL_API BOOL DLL_CALLCONV FreeImage_SaveU(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, const wchar_t *filename, int flags FI_DEFAULT(0)); +DLL_API BOOL DLL_CALLCONV FreeImage_SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FreeImageIO *io, fi_handle handle, int flags FI_DEFAULT(0)); + +// Memory I/O stream routines ----------------------------------------------- + +DLL_API FIMEMORY *DLL_CALLCONV FreeImage_OpenMemory(BYTE *data FI_DEFAULT(0), DWORD size_in_bytes FI_DEFAULT(0)); +DLL_API void DLL_CALLCONV FreeImage_CloseMemory(FIMEMORY *stream); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_LoadFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream, int flags FI_DEFAULT(0)); +DLL_API BOOL DLL_CALLCONV FreeImage_SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FIMEMORY *stream, int flags FI_DEFAULT(0)); +DLL_API long DLL_CALLCONV FreeImage_TellMemory(FIMEMORY *stream); +DLL_API BOOL DLL_CALLCONV FreeImage_SeekMemory(FIMEMORY *stream, long offset, int origin); +DLL_API BOOL DLL_CALLCONV FreeImage_AcquireMemory(FIMEMORY *stream, BYTE **data, DWORD *size_in_bytes); +DLL_API unsigned DLL_CALLCONV FreeImage_ReadMemory(void *buffer, unsigned size, unsigned count, FIMEMORY *stream); +DLL_API unsigned DLL_CALLCONV FreeImage_WriteMemory(const void *buffer, unsigned size, unsigned count, FIMEMORY *stream); + +DLL_API FIMULTIBITMAP *DLL_CALLCONV FreeImage_LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream, int flags FI_DEFAULT(0)); +DLL_API BOOL DLL_CALLCONV FreeImage_SaveMultiBitmapToMemory(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, FIMEMORY *stream, int flags); + +// Plugin Interface --------------------------------------------------------- + +DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_RegisterLocalPlugin(FI_InitProc proc_address, const char *format FI_DEFAULT(0), const char *description FI_DEFAULT(0), const char *extension FI_DEFAULT(0), const char *regexpr FI_DEFAULT(0)); +DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_RegisterExternalPlugin(const char *path, const char *format FI_DEFAULT(0), const char *description FI_DEFAULT(0), const char *extension FI_DEFAULT(0), const char *regexpr FI_DEFAULT(0)); +DLL_API int DLL_CALLCONV FreeImage_GetFIFCount(void); +DLL_API int DLL_CALLCONV FreeImage_SetPluginEnabled(FREE_IMAGE_FORMAT fif, BOOL enable); +DLL_API int DLL_CALLCONV FreeImage_IsPluginEnabled(FREE_IMAGE_FORMAT fif); +DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromFormat(const char *format); +DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromMime(const char *mime); +DLL_API const char *DLL_CALLCONV FreeImage_GetFormatFromFIF(FREE_IMAGE_FORMAT fif); +DLL_API const char *DLL_CALLCONV FreeImage_GetFIFExtensionList(FREE_IMAGE_FORMAT fif); +DLL_API const char *DLL_CALLCONV FreeImage_GetFIFDescription(FREE_IMAGE_FORMAT fif); +DLL_API const char *DLL_CALLCONV FreeImage_GetFIFRegExpr(FREE_IMAGE_FORMAT fif); +DLL_API const char *DLL_CALLCONV FreeImage_GetFIFMimeType(FREE_IMAGE_FORMAT fif); +DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromFilename(const char *filename); +DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromFilenameU(const wchar_t *filename); +DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsReading(FREE_IMAGE_FORMAT fif); +DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsWriting(FREE_IMAGE_FORMAT fif); +DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsExportBPP(FREE_IMAGE_FORMAT fif, int bpp); +DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsExportType(FREE_IMAGE_FORMAT fif, FREE_IMAGE_TYPE type); +DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsICCProfiles(FREE_IMAGE_FORMAT fif); +DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsNoPixels(FREE_IMAGE_FORMAT fif); + +// Multipaging interface ---------------------------------------------------- + +DLL_API FIMULTIBITMAP * DLL_CALLCONV FreeImage_OpenMultiBitmap(FREE_IMAGE_FORMAT fif, const char *filename, BOOL create_new, BOOL read_only, BOOL keep_cache_in_memory FI_DEFAULT(FALSE), int flags FI_DEFAULT(0)); +DLL_API FIMULTIBITMAP * DLL_CALLCONV FreeImage_OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags FI_DEFAULT(0)); +DLL_API BOOL DLL_CALLCONV FreeImage_SaveMultiBitmapToHandle(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, FreeImageIO *io, fi_handle handle, int flags FI_DEFAULT(0)); +DLL_API BOOL DLL_CALLCONV FreeImage_CloseMultiBitmap(FIMULTIBITMAP *bitmap, int flags FI_DEFAULT(0)); +DLL_API int DLL_CALLCONV FreeImage_GetPageCount(FIMULTIBITMAP *bitmap); +DLL_API void DLL_CALLCONV FreeImage_AppendPage(FIMULTIBITMAP *bitmap, FIBITMAP *data); +DLL_API void DLL_CALLCONV FreeImage_InsertPage(FIMULTIBITMAP *bitmap, int page, FIBITMAP *data); +DLL_API void DLL_CALLCONV FreeImage_DeletePage(FIMULTIBITMAP *bitmap, int page); +DLL_API FIBITMAP * DLL_CALLCONV FreeImage_LockPage(FIMULTIBITMAP *bitmap, int page); +DLL_API void DLL_CALLCONV FreeImage_UnlockPage(FIMULTIBITMAP *bitmap, FIBITMAP *data, BOOL changed); +DLL_API BOOL DLL_CALLCONV FreeImage_MovePage(FIMULTIBITMAP *bitmap, int target, int source); +DLL_API BOOL DLL_CALLCONV FreeImage_GetLockedPageNumbers(FIMULTIBITMAP *bitmap, int *pages, int *count); + +// Filetype request routines ------------------------------------------------ + +DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFileType(const char *filename, int size FI_DEFAULT(0)); +DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFileTypeU(const wchar_t *filename, int size FI_DEFAULT(0)); +DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFileTypeFromHandle(FreeImageIO *io, fi_handle handle, int size FI_DEFAULT(0)); +DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFileTypeFromMemory(FIMEMORY *stream, int size FI_DEFAULT(0)); + +// Image type request routine ----------------------------------------------- + +DLL_API FREE_IMAGE_TYPE DLL_CALLCONV FreeImage_GetImageType(FIBITMAP *dib); + +// FreeImage helper routines ------------------------------------------------ + +DLL_API BOOL DLL_CALLCONV FreeImage_IsLittleEndian(void); +DLL_API BOOL DLL_CALLCONV FreeImage_LookupX11Color(const char *szColor, BYTE *nRed, BYTE *nGreen, BYTE *nBlue); +DLL_API BOOL DLL_CALLCONV FreeImage_LookupSVGColor(const char *szColor, BYTE *nRed, BYTE *nGreen, BYTE *nBlue); + +// Pixel access routines ---------------------------------------------------- + +DLL_API BYTE *DLL_CALLCONV FreeImage_GetBits(FIBITMAP *dib); +DLL_API BYTE *DLL_CALLCONV FreeImage_GetScanLine(FIBITMAP *dib, int scanline); + +DLL_API BOOL DLL_CALLCONV FreeImage_GetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value); +DLL_API BOOL DLL_CALLCONV FreeImage_GetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value); +DLL_API BOOL DLL_CALLCONV FreeImage_SetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value); +DLL_API BOOL DLL_CALLCONV FreeImage_SetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value); + +// DIB info routines -------------------------------------------------------- + +DLL_API unsigned DLL_CALLCONV FreeImage_GetColorsUsed(FIBITMAP *dib); +DLL_API unsigned DLL_CALLCONV FreeImage_GetBPP(FIBITMAP *dib); +DLL_API unsigned DLL_CALLCONV FreeImage_GetWidth(FIBITMAP *dib); +DLL_API unsigned DLL_CALLCONV FreeImage_GetHeight(FIBITMAP *dib); +DLL_API unsigned DLL_CALLCONV FreeImage_GetLine(FIBITMAP *dib); +DLL_API unsigned DLL_CALLCONV FreeImage_GetPitch(FIBITMAP *dib); +DLL_API unsigned DLL_CALLCONV FreeImage_GetDIBSize(FIBITMAP *dib); +DLL_API RGBQUAD *DLL_CALLCONV FreeImage_GetPalette(FIBITMAP *dib); + +DLL_API unsigned DLL_CALLCONV FreeImage_GetDotsPerMeterX(FIBITMAP *dib); +DLL_API unsigned DLL_CALLCONV FreeImage_GetDotsPerMeterY(FIBITMAP *dib); +DLL_API void DLL_CALLCONV FreeImage_SetDotsPerMeterX(FIBITMAP *dib, unsigned res); +DLL_API void DLL_CALLCONV FreeImage_SetDotsPerMeterY(FIBITMAP *dib, unsigned res); + +DLL_API BITMAPINFOHEADER *DLL_CALLCONV FreeImage_GetInfoHeader(FIBITMAP *dib); +DLL_API BITMAPINFO *DLL_CALLCONV FreeImage_GetInfo(FIBITMAP *dib); +DLL_API FREE_IMAGE_COLOR_TYPE DLL_CALLCONV FreeImage_GetColorType(FIBITMAP *dib); + +DLL_API unsigned DLL_CALLCONV FreeImage_GetRedMask(FIBITMAP *dib); +DLL_API unsigned DLL_CALLCONV FreeImage_GetGreenMask(FIBITMAP *dib); +DLL_API unsigned DLL_CALLCONV FreeImage_GetBlueMask(FIBITMAP *dib); + +DLL_API unsigned DLL_CALLCONV FreeImage_GetTransparencyCount(FIBITMAP *dib); +DLL_API BYTE * DLL_CALLCONV FreeImage_GetTransparencyTable(FIBITMAP *dib); +DLL_API void DLL_CALLCONV FreeImage_SetTransparent(FIBITMAP *dib, BOOL enabled); +DLL_API void DLL_CALLCONV FreeImage_SetTransparencyTable(FIBITMAP *dib, BYTE *table, int count); +DLL_API BOOL DLL_CALLCONV FreeImage_IsTransparent(FIBITMAP *dib); +DLL_API void DLL_CALLCONV FreeImage_SetTransparentIndex(FIBITMAP *dib, int index); +DLL_API int DLL_CALLCONV FreeImage_GetTransparentIndex(FIBITMAP *dib); + +DLL_API BOOL DLL_CALLCONV FreeImage_HasBackgroundColor(FIBITMAP *dib); +DLL_API BOOL DLL_CALLCONV FreeImage_GetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor); +DLL_API BOOL DLL_CALLCONV FreeImage_SetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor); + +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_GetThumbnail(FIBITMAP *dib); +DLL_API BOOL DLL_CALLCONV FreeImage_SetThumbnail(FIBITMAP *dib, FIBITMAP *thumbnail); + +// ICC profile routines ----------------------------------------------------- + +DLL_API FIICCPROFILE *DLL_CALLCONV FreeImage_GetICCProfile(FIBITMAP *dib); +DLL_API FIICCPROFILE *DLL_CALLCONV FreeImage_CreateICCProfile(FIBITMAP *dib, void *data, long size); +DLL_API void DLL_CALLCONV FreeImage_DestroyICCProfile(FIBITMAP *dib); + +// Line conversion routines ------------------------------------------------- + +DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To4(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To4(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To4_555(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To4_565(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To4(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To4(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To8(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To8(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To8_555(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To8_565(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To8(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To8(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To16_555(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To16_555(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To16_555(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine16_565_To16_555(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To16_555(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To16_555(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To16_565(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To16_565(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To16_565(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine16_555_To16_565(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To16_565(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To16_565(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To24_555(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To24_565(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine32To24(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine1To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine4To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine8To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To32_555(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine16To32_565(BYTE *target, BYTE *source, int width_in_pixels); +DLL_API void DLL_CALLCONV FreeImage_ConvertLine24To32(BYTE *target, BYTE *source, int width_in_pixels); + +// Smart conversion routines ------------------------------------------------ + +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo4Bits(FIBITMAP *dib); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo8Bits(FIBITMAP *dib); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToGreyscale(FIBITMAP *dib); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo16Bits555(FIBITMAP *dib); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo16Bits565(FIBITMAP *dib); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo24Bits(FIBITMAP *dib); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertTo32Bits(FIBITMAP *dib); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ColorQuantize(FIBITMAP *dib, FREE_IMAGE_QUANTIZE quantize); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ColorQuantizeEx(FIBITMAP *dib, FREE_IMAGE_QUANTIZE quantize FI_DEFAULT(FIQ_WUQUANT), int PaletteSize FI_DEFAULT(256), int ReserveSize FI_DEFAULT(0), RGBQUAD *ReservePalette FI_DEFAULT(NULL)); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Threshold(FIBITMAP *dib, BYTE T); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Dither(FIBITMAP *dib, FREE_IMAGE_DITHER algorithm); + +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertFromRawBits(BYTE *bits, int width, int height, int pitch, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask, BOOL topdown FI_DEFAULT(FALSE)); +DLL_API void DLL_CALLCONV FreeImage_ConvertToRawBits(BYTE *bits, FIBITMAP *dib, int pitch, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask, BOOL topdown FI_DEFAULT(FALSE)); + +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToFloat(FIBITMAP *dib); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToRGBF(FIBITMAP *dib); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToUINT16(FIBITMAP *dib); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToRGB16(FIBITMAP *dib); + +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToStandardType(FIBITMAP *src, BOOL scale_linear FI_DEFAULT(TRUE)); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ConvertToType(FIBITMAP *src, FREE_IMAGE_TYPE dst_type, BOOL scale_linear FI_DEFAULT(TRUE)); + +// tone mapping operators +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_ToneMapping(FIBITMAP *dib, FREE_IMAGE_TMO tmo, double first_param FI_DEFAULT(0), double second_param FI_DEFAULT(0)); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_TmoDrago03(FIBITMAP *src, double gamma FI_DEFAULT(2.2), double exposure FI_DEFAULT(0)); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_TmoReinhard05(FIBITMAP *src, double intensity FI_DEFAULT(0), double contrast FI_DEFAULT(0)); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_TmoReinhard05Ex(FIBITMAP *src, double intensity FI_DEFAULT(0), double contrast FI_DEFAULT(0), double adaptation FI_DEFAULT(1), double color_correction FI_DEFAULT(0)); + +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_TmoFattal02(FIBITMAP *src, double color_saturation FI_DEFAULT(0.5), double attenuation FI_DEFAULT(0.85)); + +// ZLib interface ----------------------------------------------------------- + +DLL_API DWORD DLL_CALLCONV FreeImage_ZLibCompress(BYTE *target, DWORD target_size, BYTE *source, DWORD source_size); +DLL_API DWORD DLL_CALLCONV FreeImage_ZLibUncompress(BYTE *target, DWORD target_size, BYTE *source, DWORD source_size); +DLL_API DWORD DLL_CALLCONV FreeImage_ZLibGZip(BYTE *target, DWORD target_size, BYTE *source, DWORD source_size); +DLL_API DWORD DLL_CALLCONV FreeImage_ZLibGUnzip(BYTE *target, DWORD target_size, BYTE *source, DWORD source_size); +DLL_API DWORD DLL_CALLCONV FreeImage_ZLibCRC32(DWORD crc, BYTE *source, DWORD source_size); + +// -------------------------------------------------------------------------- +// Metadata routines -------------------------------------------------------- +// -------------------------------------------------------------------------- + +// tag creation / destruction +DLL_API FITAG *DLL_CALLCONV FreeImage_CreateTag(void); +DLL_API void DLL_CALLCONV FreeImage_DeleteTag(FITAG *tag); +DLL_API FITAG *DLL_CALLCONV FreeImage_CloneTag(FITAG *tag); + +// tag getters and setters +DLL_API const char *DLL_CALLCONV FreeImage_GetTagKey(FITAG *tag); +DLL_API const char *DLL_CALLCONV FreeImage_GetTagDescription(FITAG *tag); +DLL_API WORD DLL_CALLCONV FreeImage_GetTagID(FITAG *tag); +DLL_API FREE_IMAGE_MDTYPE DLL_CALLCONV FreeImage_GetTagType(FITAG *tag); +DLL_API DWORD DLL_CALLCONV FreeImage_GetTagCount(FITAG *tag); +DLL_API DWORD DLL_CALLCONV FreeImage_GetTagLength(FITAG *tag); +DLL_API const void *DLL_CALLCONV FreeImage_GetTagValue(FITAG *tag); + +DLL_API BOOL DLL_CALLCONV FreeImage_SetTagKey(FITAG *tag, const char *key); +DLL_API BOOL DLL_CALLCONV FreeImage_SetTagDescription(FITAG *tag, const char *description); +DLL_API BOOL DLL_CALLCONV FreeImage_SetTagID(FITAG *tag, WORD id); +DLL_API BOOL DLL_CALLCONV FreeImage_SetTagType(FITAG *tag, FREE_IMAGE_MDTYPE type); +DLL_API BOOL DLL_CALLCONV FreeImage_SetTagCount(FITAG *tag, DWORD count); +DLL_API BOOL DLL_CALLCONV FreeImage_SetTagLength(FITAG *tag, DWORD length); +DLL_API BOOL DLL_CALLCONV FreeImage_SetTagValue(FITAG *tag, const void *value); + +// iterator +DLL_API FIMETADATA *DLL_CALLCONV FreeImage_FindFirstMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, FITAG **tag); +DLL_API BOOL DLL_CALLCONV FreeImage_FindNextMetadata(FIMETADATA *mdhandle, FITAG **tag); +DLL_API void DLL_CALLCONV FreeImage_FindCloseMetadata(FIMETADATA *mdhandle); + +// metadata setter and getter +DLL_API BOOL DLL_CALLCONV FreeImage_SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, FITAG *tag); +DLL_API BOOL DLL_CALLCONV FreeImage_GetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, FITAG **tag); + +// helpers +DLL_API unsigned DLL_CALLCONV FreeImage_GetMetadataCount(FREE_IMAGE_MDMODEL model, FIBITMAP *dib); +DLL_API BOOL DLL_CALLCONV FreeImage_CloneMetadata(FIBITMAP *dst, FIBITMAP *src); + +// tag to C string conversion +DLL_API const char* DLL_CALLCONV FreeImage_TagToString(FREE_IMAGE_MDMODEL model, FITAG *tag, char *Make FI_DEFAULT(NULL)); + +// -------------------------------------------------------------------------- +// Image manipulation toolkit ----------------------------------------------- +// -------------------------------------------------------------------------- + +// rotation and flipping +/// @deprecated see FreeImage_Rotate +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_RotateClassic(FIBITMAP *dib, double angle); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Rotate(FIBITMAP *dib, double angle, const void *bkcolor FI_DEFAULT(NULL)); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_RotateEx(FIBITMAP *dib, double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask); +DLL_API BOOL DLL_CALLCONV FreeImage_FlipHorizontal(FIBITMAP *dib); +DLL_API BOOL DLL_CALLCONV FreeImage_FlipVertical(FIBITMAP *dib); +DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransform(const char *src_file, const char *dst_file, FREE_IMAGE_JPEG_OPERATION operation, BOOL perfect FI_DEFAULT(FALSE)); +DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransformU(const wchar_t *src_file, const wchar_t *dst_file, FREE_IMAGE_JPEG_OPERATION operation, BOOL perfect FI_DEFAULT(FALSE)); + +// upsampling / downsampling +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Rescale(FIBITMAP *dib, int dst_width, int dst_height, FREE_IMAGE_FILTER filter); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_MakeThumbnail(FIBITMAP *dib, int max_pixel_size, BOOL convert FI_DEFAULT(TRUE)); + +// color manipulation routines (point operations) +DLL_API BOOL DLL_CALLCONV FreeImage_AdjustCurve(FIBITMAP *dib, BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel); +DLL_API BOOL DLL_CALLCONV FreeImage_AdjustGamma(FIBITMAP *dib, double gamma); +DLL_API BOOL DLL_CALLCONV FreeImage_AdjustBrightness(FIBITMAP *dib, double percentage); +DLL_API BOOL DLL_CALLCONV FreeImage_AdjustContrast(FIBITMAP *dib, double percentage); +DLL_API BOOL DLL_CALLCONV FreeImage_Invert(FIBITMAP *dib); +DLL_API BOOL DLL_CALLCONV FreeImage_GetHistogram(FIBITMAP *dib, DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel FI_DEFAULT(FICC_BLACK)); +DLL_API int DLL_CALLCONV FreeImage_GetAdjustColorsLookupTable(BYTE *LUT, double brightness, double contrast, double gamma, BOOL invert); +DLL_API BOOL DLL_CALLCONV FreeImage_AdjustColors(FIBITMAP *dib, double brightness, double contrast, double gamma, BOOL invert FI_DEFAULT(FALSE)); +DLL_API unsigned DLL_CALLCONV FreeImage_ApplyColorMapping(FIBITMAP *dib, RGBQUAD *srccolors, RGBQUAD *dstcolors, unsigned count, BOOL ignore_alpha, BOOL swap); +DLL_API unsigned DLL_CALLCONV FreeImage_SwapColors(FIBITMAP *dib, RGBQUAD *color_a, RGBQUAD *color_b, BOOL ignore_alpha); +DLL_API unsigned DLL_CALLCONV FreeImage_ApplyPaletteIndexMapping(FIBITMAP *dib, BYTE *srcindices, BYTE *dstindices, unsigned count, BOOL swap); +DLL_API unsigned DLL_CALLCONV FreeImage_SwapPaletteIndices(FIBITMAP *dib, BYTE *index_a, BYTE *index_b); + +// channel processing routines +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_GetChannel(FIBITMAP *dib, FREE_IMAGE_COLOR_CHANNEL channel); +DLL_API BOOL DLL_CALLCONV FreeImage_SetChannel(FIBITMAP *dst, FIBITMAP *src, FREE_IMAGE_COLOR_CHANNEL channel); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_GetComplexChannel(FIBITMAP *src, FREE_IMAGE_COLOR_CHANNEL channel); +DLL_API BOOL DLL_CALLCONV FreeImage_SetComplexChannel(FIBITMAP *dst, FIBITMAP *src, FREE_IMAGE_COLOR_CHANNEL channel); + +// copy / paste / composite routines +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Copy(FIBITMAP *dib, int left, int top, int right, int bottom); +DLL_API BOOL DLL_CALLCONV FreeImage_Paste(FIBITMAP *dst, FIBITMAP *src, int left, int top, int alpha); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Composite(FIBITMAP *fg, BOOL useFileBkg FI_DEFAULT(FALSE), RGBQUAD *appBkColor FI_DEFAULT(NULL), FIBITMAP *bg FI_DEFAULT(NULL)); +DLL_API BOOL DLL_CALLCONV FreeImage_JPEGCrop(const char *src_file, const char *dst_file, int left, int top, int right, int bottom); +DLL_API BOOL DLL_CALLCONV FreeImage_JPEGCropU(const wchar_t *src_file, const wchar_t *dst_file, int left, int top, int right, int bottom); +DLL_API BOOL DLL_CALLCONV FreeImage_PreMultiplyWithAlpha(FIBITMAP *dib); + +// background filling routines +DLL_API BOOL DLL_CALLCONV FreeImage_FillBackground(FIBITMAP *dib, const void *color, int options FI_DEFAULT(0)); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_EnlargeCanvas(FIBITMAP *src, int left, int top, int right, int bottom, const void *color, int options FI_DEFAULT(0)); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_AllocateEx(int width, int height, int bpp, const RGBQUAD *color, int options FI_DEFAULT(0), const RGBQUAD *palette FI_DEFAULT(NULL), unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0)); +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp, const void *color, int options FI_DEFAULT(0), const RGBQUAD *palette FI_DEFAULT(NULL), unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0)); + +// miscellaneous algorithms +DLL_API FIBITMAP *DLL_CALLCONV FreeImage_MultigridPoissonSolver(FIBITMAP *Laplacian, int ncycle FI_DEFAULT(3)); + +// restore the borland-specific enum size option +#if defined(__BORLANDC__) +#pragma option pop +#endif + +#ifdef __cplusplus +} +#endif + +#endif // FREEIMAGE_H diff --git a/Source/FreeImage/BitmapAccess.cpp b/Source/FreeImage/BitmapAccess.cpp index 5b90ed8..b9097d1 100644 --- a/Source/FreeImage/BitmapAccess.cpp +++ b/Source/FreeImage/BitmapAccess.cpp @@ -1,1269 +1,1269 @@ -// ========================================================== -// FreeImage implementation -// -// Design and implementation by -// - Floris van den Berg (flvdberg@wxs.nl) -// - Hervé Drolon (drolon@infonie.fr) -// - Detlev Vendt (detlev.vendt@brillit.de) -// - Petr Supina (psup@centrum.cz) -// - Carsten Klein (c.klein@datagis.com) -// - Mihail Naydenov (mnaydenov@users.sourceforge.net) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#ifdef _MSC_VER -#pragma warning (disable : 4786) // identifier was truncated to 'number' characters -#endif - -#include -#if defined(_WIN32) || defined(_WIN64) || defined(__MINGW32__) -#include -#endif // _WIN32 || _WIN64 || __MINGW32__ - -#include "FreeImage.h" -#include "FreeImageIO.h" -#include "Utilities.h" - -#include "../Metadata/FreeImageTag.h" - -/** Constants for the BITMAPINFOHEADER::biCompression field */ -#ifndef _WINGDI_ -#define BI_RGB 0L -#define BI_BITFIELDS 3L -#endif // _WINGDI_ - -// ---------------------------------------------------------- -// Metadata definitions -// ---------------------------------------------------------- - -// helper for map where value is a pointer to a FreeImage tag -typedef std::map TAGMAP; - -// helper for map -typedef std::map METADATAMAP; - -// helper for metadata iterator -FI_STRUCT (METADATAHEADER) { - long pos; // current position when iterating the map - TAGMAP *tagmap; // pointer to the tag map -}; - -// ---------------------------------------------------------- -// FIBITMAP definition -// ---------------------------------------------------------- - -FI_STRUCT (FREEIMAGEHEADER) { - FREE_IMAGE_TYPE type; // data type - bitmap, array of long, double, complex, etc - - RGBQUAD bkgnd_color; // background color used for RGB transparency - - BOOL transparent; // why another table? for easy transparency table retrieval! - int transparency_count; // transparency could be stored in the palette, which is better - BYTE transparent_table[256];// overall, but it requires quite some changes and it will render - // FreeImage_GetTransparencyTable obsolete in its current form; - FIICCPROFILE iccProfile; // space to hold ICC profile - - METADATAMAP *metadata; // contains a list of metadata models attached to the bitmap - - BOOL has_pixels; // FALSE if the FIBITMAP only contains the header and no pixel data - - FIBITMAP *thumbnail; // optionally contains a thumbnail attached to the bitmap - - //BYTE filler[1]; // fill to 32-bit alignment -}; - -// ---------------------------------------------------------- -// FREEIMAGERGBMASKS definition -// ---------------------------------------------------------- - -FI_STRUCT (FREEIMAGERGBMASKS) { - unsigned red_mask; // bit layout of the red components - unsigned green_mask; // bit layout of the green components - unsigned blue_mask; // bit layout of the blue components -}; - -// ---------------------------------------------------------- -// Memory allocation on a specified alignment boundary -// ---------------------------------------------------------- - -#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) - -void* FreeImage_Aligned_Malloc(size_t amount, size_t alignment) { - assert(alignment == FIBITMAP_ALIGNMENT); - return _aligned_malloc(amount, alignment); -} - -void FreeImage_Aligned_Free(void* mem) { - _aligned_free(mem); -} - -#elif defined (__MINGW32__) - -void* FreeImage_Aligned_Malloc(size_t amount, size_t alignment) { - assert(alignment == FIBITMAP_ALIGNMENT); - return __mingw_aligned_malloc (amount, alignment); -} - -void FreeImage_Aligned_Free(void* mem) { - __mingw_aligned_free (mem); -} - -#else - -void* FreeImage_Aligned_Malloc(size_t amount, size_t alignment) { - assert(alignment == FIBITMAP_ALIGNMENT); - /* - In some rare situations, the malloc routines can return misaligned memory. - The routine FreeImage_Aligned_Malloc allocates a bit more memory to do - aligned writes. Normally, it *should* allocate "alignment" extra memory and then writes - one dword back the true pointer. But if the memory manager returns a - misaligned block that is less than a dword from the next alignment, - then the writing back one dword will corrupt memory. - - For example, suppose that alignment is 16 and malloc returns the address 0xFFFF. - - 16 - 0xFFFF % 16 + 0xFFFF = 16 - 15 + 0xFFFF = 0x10000. - - Now, you subtract one dword from that and write and that will corrupt memory. - - That's why the code below allocates *two* alignments instead of one. - */ - void* mem_real = malloc(amount + 2 * alignment); - if(!mem_real) return NULL; - char* mem_align = (char*)((unsigned long)(2 * alignment - (unsigned long)mem_real % (unsigned long)alignment) + (unsigned long)mem_real); - *((long*)mem_align - 1) = (long)mem_real; - return mem_align; -} - -void FreeImage_Aligned_Free(void* mem) { - free((void*)*((long*)mem - 1)); -} - -#endif // _WIN32 || _WIN64 - -// ---------------------------------------------------------- -// DIB information functions -// ---------------------------------------------------------- - -/** -Calculate the size of a FreeImage image. -Align the palette and the pixels on a FIBITMAP_ALIGNMENT bytes alignment boundary. - -@param header_only If TRUE, calculate a 'header only' FIBITMAP size, otherwise calculate a full FIBITMAP size -@param width -@param height -@param bpp -@param need_masks -@see FreeImage_AllocateHeaderT -*/ -static size_t -FreeImage_GetImageSizeHeader(BOOL header_only, unsigned width, unsigned height, unsigned bpp, BOOL need_masks) { - size_t dib_size = sizeof(FREEIMAGEHEADER); - dib_size += (dib_size % FIBITMAP_ALIGNMENT ? FIBITMAP_ALIGNMENT - dib_size % FIBITMAP_ALIGNMENT : 0); - dib_size += FIBITMAP_ALIGNMENT - sizeof(BITMAPINFOHEADER) % FIBITMAP_ALIGNMENT; - dib_size += sizeof(BITMAPINFOHEADER); - // palette is aligned on a 16 bytes boundary - dib_size += sizeof(RGBQUAD) * CalculateUsedPaletteEntries(bpp); - // we both add palette size and masks size if need_masks is true, since CalculateUsedPaletteEntries - // always returns 0 if need_masks is true (which is only true for 16 bit images). - dib_size += need_masks ? sizeof(DWORD) * 3 : 0; - dib_size += (dib_size % FIBITMAP_ALIGNMENT ? FIBITMAP_ALIGNMENT - dib_size % FIBITMAP_ALIGNMENT : 0); - if(!header_only) { - const size_t header_size = dib_size; - - // pixels are aligned on a 16 bytes boundary - dib_size += (size_t)CalculatePitch(CalculateLine(width, bpp)) * (size_t)height; - - // check for possible malloc overflow using a KISS integer overflow detection mechanism - { - /* - The following constant take into account the additionnal memory used by - aligned malloc functions as well as debug malloc functions. - It is supposed here that using a (8 * FIBITMAP_ALIGNMENT) risk margin will be enough - for the target compiler. - */ - const double FIBITMAP_MAX_MEMORY = (double)((size_t)-1) - 8 * FIBITMAP_ALIGNMENT; - const double dPitch = floor( ((double)bpp * width + 31.0) / 32.0 ) * 4.0; - const double dImageSize = (double)header_size + dPitch * height; - if(dImageSize != (double)dib_size) { - // here, we are sure to encounter a malloc overflow: try to avoid it ... - return 0; - } - if(dImageSize > FIBITMAP_MAX_MEMORY) { - // avoid possible overflow inside C allocation functions - return 0; - } - } - } - - return dib_size; -} - -/** +// ========================================================== +// FreeImage implementation +// +// Design and implementation by +// - Floris van den Berg (flvdberg@wxs.nl) +// - Hervé Drolon (drolon@infonie.fr) +// - Detlev Vendt (detlev.vendt@brillit.de) +// - Petr Supina (psup@centrum.cz) +// - Carsten Klein (c.klein@datagis.com) +// - Mihail Naydenov (mnaydenov@users.sourceforge.net) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#ifdef _MSC_VER +#pragma warning (disable : 4786) // identifier was truncated to 'number' characters +#endif + +#include +#if defined(_WIN32) || defined(_WIN64) || defined(__MINGW32__) +#include +#endif // _WIN32 || _WIN64 || __MINGW32__ + +#include "FreeImage.h" +#include "FreeImageIO.h" +#include "Utilities.h" + +#include "../Metadata/FreeImageTag.h" + +/** Constants for the BITMAPINFOHEADER::biCompression field */ +#ifndef _WINGDI_ +#define BI_RGB 0L +#define BI_BITFIELDS 3L +#endif // _WINGDI_ + +// ---------------------------------------------------------- +// Metadata definitions +// ---------------------------------------------------------- + +// helper for map where value is a pointer to a FreeImage tag +typedef std::map TAGMAP; + +// helper for map +typedef std::map METADATAMAP; + +// helper for metadata iterator +FI_STRUCT (METADATAHEADER) { + long pos; // current position when iterating the map + TAGMAP *tagmap; // pointer to the tag map +}; + +// ---------------------------------------------------------- +// FIBITMAP definition +// ---------------------------------------------------------- + +FI_STRUCT (FREEIMAGEHEADER) { + FREE_IMAGE_TYPE type; // data type - bitmap, array of long, double, complex, etc + + RGBQUAD bkgnd_color; // background color used for RGB transparency + + BOOL transparent; // why another table? for easy transparency table retrieval! + int transparency_count; // transparency could be stored in the palette, which is better + BYTE transparent_table[256];// overall, but it requires quite some changes and it will render + // FreeImage_GetTransparencyTable obsolete in its current form; + FIICCPROFILE iccProfile; // space to hold ICC profile + + METADATAMAP *metadata; // contains a list of metadata models attached to the bitmap + + BOOL has_pixels; // FALSE if the FIBITMAP only contains the header and no pixel data + + FIBITMAP *thumbnail; // optionally contains a thumbnail attached to the bitmap + + //BYTE filler[1]; // fill to 32-bit alignment +}; + +// ---------------------------------------------------------- +// FREEIMAGERGBMASKS definition +// ---------------------------------------------------------- + +FI_STRUCT (FREEIMAGERGBMASKS) { + unsigned red_mask; // bit layout of the red components + unsigned green_mask; // bit layout of the green components + unsigned blue_mask; // bit layout of the blue components +}; + +// ---------------------------------------------------------- +// Memory allocation on a specified alignment boundary +// ---------------------------------------------------------- + +#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) + +void* FreeImage_Aligned_Malloc(size_t amount, size_t alignment) { + assert(alignment == FIBITMAP_ALIGNMENT); + return _aligned_malloc(amount, alignment); +} + +void FreeImage_Aligned_Free(void* mem) { + _aligned_free(mem); +} + +#elif defined (__MINGW32__) + +void* FreeImage_Aligned_Malloc(size_t amount, size_t alignment) { + assert(alignment == FIBITMAP_ALIGNMENT); + return __mingw_aligned_malloc (amount, alignment); +} + +void FreeImage_Aligned_Free(void* mem) { + __mingw_aligned_free (mem); +} + +#else + +void* FreeImage_Aligned_Malloc(size_t amount, size_t alignment) { + assert(alignment == FIBITMAP_ALIGNMENT); + /* + In some rare situations, the malloc routines can return misaligned memory. + The routine FreeImage_Aligned_Malloc allocates a bit more memory to do + aligned writes. Normally, it *should* allocate "alignment" extra memory and then writes + one dword back the true pointer. But if the memory manager returns a + misaligned block that is less than a dword from the next alignment, + then the writing back one dword will corrupt memory. + + For example, suppose that alignment is 16 and malloc returns the address 0xFFFF. + + 16 - 0xFFFF % 16 + 0xFFFF = 16 - 15 + 0xFFFF = 0x10000. + + Now, you subtract one dword from that and write and that will corrupt memory. + + That's why the code below allocates *two* alignments instead of one. + */ + void* mem_real = malloc(amount + 2 * alignment); + if(!mem_real) return NULL; + char* mem_align = (char*)((unsigned long)(2 * alignment - (unsigned long)mem_real % (unsigned long)alignment) + (unsigned long)mem_real); + *((long*)mem_align - 1) = (long)mem_real; + return mem_align; +} + +void FreeImage_Aligned_Free(void* mem) { + free((void*)*((long*)mem - 1)); +} + +#endif // _WIN32 || _WIN64 + +// ---------------------------------------------------------- +// DIB information functions +// ---------------------------------------------------------- + +/** +Calculate the size of a FreeImage image. +Align the palette and the pixels on a FIBITMAP_ALIGNMENT bytes alignment boundary. + +@param header_only If TRUE, calculate a 'header only' FIBITMAP size, otherwise calculate a full FIBITMAP size +@param width +@param height +@param bpp +@param need_masks +@see FreeImage_AllocateHeaderT +*/ +static size_t +FreeImage_GetImageSizeHeader(BOOL header_only, unsigned width, unsigned height, unsigned bpp, BOOL need_masks) { + size_t dib_size = sizeof(FREEIMAGEHEADER); + dib_size += (dib_size % FIBITMAP_ALIGNMENT ? FIBITMAP_ALIGNMENT - dib_size % FIBITMAP_ALIGNMENT : 0); + dib_size += FIBITMAP_ALIGNMENT - sizeof(BITMAPINFOHEADER) % FIBITMAP_ALIGNMENT; + dib_size += sizeof(BITMAPINFOHEADER); + // palette is aligned on a 16 bytes boundary + dib_size += sizeof(RGBQUAD) * CalculateUsedPaletteEntries(bpp); + // we both add palette size and masks size if need_masks is true, since CalculateUsedPaletteEntries + // always returns 0 if need_masks is true (which is only true for 16 bit images). + dib_size += need_masks ? sizeof(DWORD) * 3 : 0; + dib_size += (dib_size % FIBITMAP_ALIGNMENT ? FIBITMAP_ALIGNMENT - dib_size % FIBITMAP_ALIGNMENT : 0); + if(!header_only) { + const size_t header_size = dib_size; + + // pixels are aligned on a 16 bytes boundary + dib_size += (size_t)CalculatePitch(CalculateLine(width, bpp)) * (size_t)height; + + // check for possible malloc overflow using a KISS integer overflow detection mechanism + { + /* + The following constant take into account the additionnal memory used by + aligned malloc functions as well as debug malloc functions. + It is supposed here that using a (8 * FIBITMAP_ALIGNMENT) risk margin will be enough + for the target compiler. + */ + const double FIBITMAP_MAX_MEMORY = (double)((size_t)-1) - 8 * FIBITMAP_ALIGNMENT; + const double dPitch = floor( ((double)bpp * width + 31.0) / 32.0 ) * 4.0; + const double dImageSize = (double)header_size + dPitch * height; + if(dImageSize != (double)dib_size) { + // here, we are sure to encounter a malloc overflow: try to avoid it ... + return 0; + } + if(dImageSize > FIBITMAP_MAX_MEMORY) { + // avoid possible overflow inside C allocation functions + return 0; + } + } + } + + return dib_size; +} + +/** Helper for 16-bit FIT_BITMAP -Returns a pointer to the bitmap's red-, green- and blue masks. -@param dib The bitmap to obtain masks from. -@return Returns a pointer to the bitmap's red-, green- and blue masks -or NULL, if no masks are present (e.g. for 24 bit images). -*/ -static FREEIMAGERGBMASKS * -FreeImage_GetRGBMasks(FIBITMAP *dib) { - return FreeImage_HasRGBMasks(dib) ? (FREEIMAGERGBMASKS *)(((BYTE *)FreeImage_GetInfoHeader(dib)) + sizeof(BITMAPINFOHEADER)) : NULL; -} - -FIBITMAP * DLL_CALLCONV -FreeImage_AllocateHeaderT(BOOL header_only, FREE_IMAGE_TYPE type, int width, int height, int bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask) { - - // check input variables - width = abs(width); - height = abs(height); - if(!((width > 0) && (height > 0))) { - return NULL; - } - - // we only store the masks (and allocate memory for - // them) for 16 images of type FIT_BITMAP - BOOL need_masks = FALSE; - - // check pixel bit depth - switch(type) { - case FIT_BITMAP: - switch(bpp) { - case 1: - case 4: - case 8: - break; - case 16: - need_masks = TRUE; - break; - case 24: - case 32: - break; - default: - bpp = 8; - break; - } - break; - case FIT_UINT16: - bpp = 8 * sizeof(unsigned short); - break; - case FIT_INT16: - bpp = 8 * sizeof(short); - break; - case FIT_UINT32: - bpp = 8 * sizeof(DWORD); - break; - case FIT_INT32: - bpp = 8 * sizeof(LONG); - break; - case FIT_FLOAT: - bpp = 8 * sizeof(float); - break; - case FIT_DOUBLE: - bpp = 8 * sizeof(double); - break; - case FIT_COMPLEX: - bpp = 8 * sizeof(FICOMPLEX); - break; - case FIT_RGB16: - bpp = 8 * sizeof(FIRGB16); - break; - case FIT_RGBA16: - bpp = 8 * sizeof(FIRGBA16); - break; - case FIT_RGBF: - bpp = 8 * sizeof(FIRGBF); - break; - case FIT_RGBAF: - bpp = 8 * sizeof(FIRGBAF); - break; - default: - return NULL; - } - - FIBITMAP *bitmap = (FIBITMAP *)malloc(sizeof(FIBITMAP)); - - if (bitmap != NULL) { - - // calculate the size of a FreeImage image - // align the palette and the pixels on a FIBITMAP_ALIGNMENT bytes alignment boundary - // palette is aligned on a 16 bytes boundary - // pixels are aligned on a 16 bytes boundary - - size_t dib_size = FreeImage_GetImageSizeHeader(header_only, width, height, bpp, need_masks); - - if(dib_size == 0) { - // memory allocation will fail (probably a malloc overflow) - free(bitmap); - return NULL; - } - - bitmap->data = (BYTE *)FreeImage_Aligned_Malloc(dib_size * sizeof(BYTE), FIBITMAP_ALIGNMENT); - - if (bitmap->data != NULL) { - memset(bitmap->data, 0, dib_size); - - // write out the FREEIMAGEHEADER - - FREEIMAGEHEADER *fih = (FREEIMAGEHEADER *)bitmap->data; - fih->type = type; - - memset(&fih->bkgnd_color, 0, sizeof(RGBQUAD)); - - fih->transparent = FALSE; - fih->transparency_count = 0; - memset(fih->transparent_table, 0xff, 256); - - fih->has_pixels = header_only ? FALSE : TRUE; - - // initialize FIICCPROFILE link - - FIICCPROFILE *iccProfile = FreeImage_GetICCProfile(bitmap); - iccProfile->size = 0; - iccProfile->data = 0; - iccProfile->flags = 0; - - // initialize metadata models list - - fih->metadata = new(std::nothrow) METADATAMAP; - - // initialize attached thumbnail - - fih->thumbnail = NULL; - - // write out the BITMAPINFOHEADER - - BITMAPINFOHEADER *bih = FreeImage_GetInfoHeader(bitmap); - bih->biSize = sizeof(BITMAPINFOHEADER); - bih->biWidth = width; - bih->biHeight = height; - bih->biPlanes = 1; - bih->biCompression = need_masks ? BI_BITFIELDS : BI_RGB; - bih->biBitCount = (WORD)bpp; - bih->biClrUsed = CalculateUsedPaletteEntries(bpp); - bih->biClrImportant = bih->biClrUsed; - bih->biXPelsPerMeter = 2835; // 72 dpi - bih->biYPelsPerMeter = 2835; // 72 dpi - - if(bpp == 8) { - // build a default greyscale palette (very useful for image processing) - RGBQUAD *pal = FreeImage_GetPalette(bitmap); - for(int i = 0; i < 256; i++) { - pal[i].rgbRed = (BYTE)i; - pal[i].rgbGreen = (BYTE)i; - pal[i].rgbBlue = (BYTE)i; - } - } - - // just setting the masks (only if needed) just like the palette. - if (need_masks) { - FREEIMAGERGBMASKS *masks = FreeImage_GetRGBMasks(bitmap); - masks->red_mask = red_mask; - masks->green_mask = green_mask; - masks->blue_mask = blue_mask; - } - - return bitmap; - } - - free(bitmap); - } - - return NULL; -} - -FIBITMAP * DLL_CALLCONV -FreeImage_AllocateHeader(BOOL header_only, int width, int height, int bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask) { - return FreeImage_AllocateHeaderT(header_only, FIT_BITMAP, width, height, bpp, red_mask, green_mask, blue_mask); -} - -FIBITMAP * DLL_CALLCONV -FreeImage_Allocate(int width, int height, int bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask) { - return FreeImage_AllocateHeaderT(FALSE, FIT_BITMAP, width, height, bpp, red_mask, green_mask, blue_mask); -} - -FIBITMAP * DLL_CALLCONV -FreeImage_AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask) { - return FreeImage_AllocateHeaderT(FALSE, type, width, height, bpp, red_mask, green_mask, blue_mask); -} - -void DLL_CALLCONV -FreeImage_Unload(FIBITMAP *dib) { - if (NULL != dib) { - if (NULL != dib->data) { - // delete possible icc profile ... - if (FreeImage_GetICCProfile(dib)->data) - free(FreeImage_GetICCProfile(dib)->data); - - // delete metadata models - METADATAMAP *metadata = ((FREEIMAGEHEADER *)dib->data)->metadata; - - for(METADATAMAP::iterator i = (*metadata).begin(); i != (*metadata).end(); i++) { - TAGMAP *tagmap = (*i).second; - - if(tagmap) { - for(TAGMAP::iterator j = tagmap->begin(); j != tagmap->end(); j++) { - FITAG *tag = (*j).second; - FreeImage_DeleteTag(tag); - } - - delete tagmap; - } - } - - delete metadata; - - // delete embedded thumbnail - FreeImage_Unload(FreeImage_GetThumbnail(dib)); - - // delete bitmap ... - FreeImage_Aligned_Free(dib->data); - } - free(dib); // ... and the wrapper - } -} - -// ---------------------------------------------------------- - -FIBITMAP * DLL_CALLCONV -FreeImage_Clone(FIBITMAP *dib) { - if(!dib) return NULL; - - FREE_IMAGE_TYPE type = FreeImage_GetImageType(dib); - unsigned width = FreeImage_GetWidth(dib); - unsigned height = FreeImage_GetHeight(dib); - unsigned bpp = FreeImage_GetBPP(dib); - - // check for pixel availability ... - BOOL header_only = FreeImage_HasPixels(dib) ? FALSE : TRUE; - // check whether this image has masks defined ... - BOOL need_masks = (bpp == 16 && type == FIT_BITMAP) ? TRUE : FALSE; - - // allocate a new dib - FIBITMAP *new_dib = FreeImage_AllocateHeaderT(header_only, type, width, height, bpp, - FreeImage_GetRedMask(dib), FreeImage_GetGreenMask(dib), FreeImage_GetBlueMask(dib)); - - if (new_dib) { - // save ICC profile links - FIICCPROFILE *src_iccProfile = FreeImage_GetICCProfile(dib); - FIICCPROFILE *dst_iccProfile = FreeImage_GetICCProfile(new_dib); - - // save metadata links - METADATAMAP *src_metadata = ((FREEIMAGEHEADER *)dib->data)->metadata; - METADATAMAP *dst_metadata = ((FREEIMAGEHEADER *)new_dib->data)->metadata; - - // calculate the size of a FreeImage image - // align the palette and the pixels on a FIBITMAP_ALIGNMENT bytes alignment boundary - // palette is aligned on a 16 bytes boundary - // pixels are aligned on a 16 bytes boundary - - size_t dib_size = FreeImage_GetImageSizeHeader(header_only, width, height, bpp, need_masks); - - // copy the bitmap + internal pointers (remember to restore new_dib internal pointers later) - memcpy(new_dib->data, dib->data, dib_size); - - // reset ICC profile link for new_dib - memset(dst_iccProfile, 0, sizeof(FIICCPROFILE)); - - // restore metadata link for new_dib - ((FREEIMAGEHEADER *)new_dib->data)->metadata = dst_metadata; - - // reset thumbnail link for new_dib - ((FREEIMAGEHEADER *)new_dib->data)->thumbnail = NULL; - - // copy possible ICC profile - FreeImage_CreateICCProfile(new_dib, src_iccProfile->data, src_iccProfile->size); - dst_iccProfile->flags = src_iccProfile->flags; - - // copy metadata models - for(METADATAMAP::iterator i = (*src_metadata).begin(); i != (*src_metadata).end(); i++) { - int model = (*i).first; - TAGMAP *src_tagmap = (*i).second; - - if(src_tagmap) { - // create a metadata model - TAGMAP *dst_tagmap = new(std::nothrow) TAGMAP(); - - if(dst_tagmap) { - // fill the model - for(TAGMAP::iterator j = src_tagmap->begin(); j != src_tagmap->end(); j++) { - std::string dst_key = (*j).first; - FITAG *dst_tag = FreeImage_CloneTag( (*j).second ); - - // assign key and tag value - (*dst_tagmap)[dst_key] = dst_tag; - } - - // assign model and tagmap - (*dst_metadata)[model] = dst_tagmap; - } - } - } - - // copy the thumbnail - FreeImage_SetThumbnail(new_dib, FreeImage_GetThumbnail(dib)); - - return new_dib; - } - - return NULL; -} - -// ---------------------------------------------------------- - -FIBITMAP* DLL_CALLCONV -FreeImage_GetThumbnail(FIBITMAP *dib) { - return (dib != NULL) ? ((FREEIMAGEHEADER *)dib->data)->thumbnail : NULL; -} - -BOOL DLL_CALLCONV -FreeImage_SetThumbnail(FIBITMAP *dib, FIBITMAP *thumbnail) { - if(dib == NULL) { - return FALSE; - } - FIBITMAP *currentThumbnail = ((FREEIMAGEHEADER *)dib->data)->thumbnail; - if(currentThumbnail == thumbnail) { - return TRUE; - } - FreeImage_Unload(currentThumbnail); - - ((FREEIMAGEHEADER *)dib->data)->thumbnail = FreeImage_HasPixels(thumbnail) ? FreeImage_Clone(thumbnail) : NULL; - - return TRUE; -} - -// ---------------------------------------------------------- - -FREE_IMAGE_COLOR_TYPE DLL_CALLCONV -FreeImage_GetColorType(FIBITMAP *dib) { - RGBQUAD *rgb; - - const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); - - // special bitmap type - if(image_type != FIT_BITMAP) { - switch(image_type) { - case FIT_RGB16: - case FIT_RGBF: - return FIC_RGB; - case FIT_RGBA16: - case FIT_RGBAF: - return FIC_RGBALPHA; - } - - return FIC_MINISBLACK; - } - - // standard image type - switch (FreeImage_GetBPP(dib)) { - case 1: - { - rgb = FreeImage_GetPalette(dib); - - if ((rgb->rgbRed == 0) && (rgb->rgbGreen == 0) && (rgb->rgbBlue == 0)) { - rgb++; - - if ((rgb->rgbRed == 255) && (rgb->rgbGreen == 255) && (rgb->rgbBlue == 255)) - return FIC_MINISBLACK; - } - - if ((rgb->rgbRed == 255) && (rgb->rgbGreen == 255) && (rgb->rgbBlue == 255)) { - rgb++; - - if ((rgb->rgbRed == 0) && (rgb->rgbGreen == 0) && (rgb->rgbBlue == 0)) - return FIC_MINISWHITE; - } - - return FIC_PALETTE; - } - - case 4: - case 8: // Check if the DIB has a color or a greyscale palette - { - int ncolors = FreeImage_GetColorsUsed(dib); - int minisblack = 1; - rgb = FreeImage_GetPalette(dib); - - for (int i = 0; i < ncolors; i++) { - if ((rgb->rgbRed != rgb->rgbGreen) || (rgb->rgbRed != rgb->rgbBlue)) - return FIC_PALETTE; - - // The DIB has a color palette if the greyscale isn't a linear ramp - // Take care of reversed grey images - if (rgb->rgbRed != i) { - if ((ncolors-i-1) != rgb->rgbRed) - return FIC_PALETTE; - else - minisblack = 0; - } - - rgb++; - } - - return minisblack ? FIC_MINISBLACK : FIC_MINISWHITE; - } - - case 16: - case 24: - return FIC_RGB; - - case 32: - { - if (FreeImage_GetICCProfile(dib)->flags & FIICC_COLOR_IS_CMYK) - return FIC_CMYK; - - if( FreeImage_HasPixels(dib) ) { - // check for fully opaque alpha layer - for (unsigned y = 0; y < FreeImage_GetHeight(dib); y++) { - rgb = (RGBQUAD *)FreeImage_GetScanLine(dib, y); - - for (unsigned x = 0; x < FreeImage_GetWidth(dib); x++) - if (rgb[x].rgbReserved != 0xFF) - return FIC_RGBALPHA; - } - return FIC_RGB; - } - - return FIC_RGBALPHA; - } - - default : - return FIC_MINISBLACK; - } -} - -// ---------------------------------------------------------- - -FREE_IMAGE_TYPE DLL_CALLCONV -FreeImage_GetImageType(FIBITMAP *dib) { - return (dib != NULL) ? ((FREEIMAGEHEADER *)dib->data)->type : FIT_UNKNOWN; -} - -// ---------------------------------------------------------- - -BOOL DLL_CALLCONV -FreeImage_HasPixels(FIBITMAP *dib) { - return (dib != NULL) ? ((FREEIMAGEHEADER *)dib->data)->has_pixels : FALSE; -} - -// ---------------------------------------------------------- - -BOOL DLL_CALLCONV -FreeImage_HasRGBMasks(FIBITMAP *dib) { - return dib && FreeImage_GetInfoHeader(dib)->biCompression == BI_BITFIELDS; -} - -unsigned DLL_CALLCONV -FreeImage_GetRedMask(FIBITMAP *dib) { - FREEIMAGERGBMASKS *masks = FreeImage_GetRGBMasks(dib); - return masks ? masks->red_mask : 0; -} - -unsigned DLL_CALLCONV -FreeImage_GetGreenMask(FIBITMAP *dib) { - FREEIMAGERGBMASKS *masks = FreeImage_GetRGBMasks(dib); - return masks ? masks->green_mask : 0; -} - -unsigned DLL_CALLCONV -FreeImage_GetBlueMask(FIBITMAP *dib) { - FREEIMAGERGBMASKS *masks = FreeImage_GetRGBMasks(dib); - return masks ? masks->blue_mask : 0; -} - -// ---------------------------------------------------------- - -BOOL DLL_CALLCONV -FreeImage_HasBackgroundColor(FIBITMAP *dib) { - if(dib) { - RGBQUAD *bkgnd_color = &((FREEIMAGEHEADER *)dib->data)->bkgnd_color; - return (bkgnd_color->rgbReserved != 0) ? TRUE : FALSE; - } - return FALSE; -} - -BOOL DLL_CALLCONV -FreeImage_GetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor) { - if(dib && bkcolor) { - if(FreeImage_HasBackgroundColor(dib)) { - // get the background color - RGBQUAD *bkgnd_color = &((FREEIMAGEHEADER *)dib->data)->bkgnd_color; - memcpy(bkcolor, bkgnd_color, sizeof(RGBQUAD)); - // get the background index - if(FreeImage_GetBPP(dib) == 8) { - RGBQUAD *pal = FreeImage_GetPalette(dib); - for(unsigned i = 0; i < FreeImage_GetColorsUsed(dib); i++) { - if(bkgnd_color->rgbRed == pal[i].rgbRed) { - if(bkgnd_color->rgbGreen == pal[i].rgbGreen) { - if(bkgnd_color->rgbBlue == pal[i].rgbBlue) { - bkcolor->rgbReserved = (BYTE)i; - return TRUE; - } - } - } - } - } - - bkcolor->rgbReserved = 0; - - return TRUE; - } - } - - return FALSE; -} - -BOOL DLL_CALLCONV -FreeImage_SetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor) { - if(dib) { - RGBQUAD *bkgnd_color = &((FREEIMAGEHEADER *)dib->data)->bkgnd_color; - if(bkcolor) { - // set the background color - memcpy(bkgnd_color, bkcolor, sizeof(RGBQUAD)); - // enable the file background color - bkgnd_color->rgbReserved = 1; - } else { - // clear and disable the file background color - memset(bkgnd_color, 0, sizeof(RGBQUAD)); - } - return TRUE; - } - - return FALSE; -} - -// ---------------------------------------------------------- - -BOOL DLL_CALLCONV -FreeImage_IsTransparent(FIBITMAP *dib) { - if(dib) { - FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); - switch(image_type) { - case FIT_BITMAP: - if(FreeImage_GetBPP(dib) == 32) { - if(FreeImage_GetColorType(dib) == FIC_RGBALPHA) { - return TRUE; - } - } else { - return ((FREEIMAGEHEADER *)dib->data)->transparent ? TRUE : FALSE; - } - break; - case FIT_RGBA16: - case FIT_RGBAF: - return TRUE; - default: - break; - } - } - return FALSE; -} - -BYTE * DLL_CALLCONV -FreeImage_GetTransparencyTable(FIBITMAP *dib) { - return dib ? ((FREEIMAGEHEADER *)dib->data)->transparent_table : NULL; -} - -void DLL_CALLCONV -FreeImage_SetTransparent(FIBITMAP *dib, BOOL enabled) { - if (dib) { - if ((FreeImage_GetBPP(dib) <= 8) || (FreeImage_GetBPP(dib) == 32)) { - ((FREEIMAGEHEADER *)dib->data)->transparent = enabled; - } else { - ((FREEIMAGEHEADER *)dib->data)->transparent = FALSE; - } - } -} - -unsigned DLL_CALLCONV -FreeImage_GetTransparencyCount(FIBITMAP *dib) { - return dib ? ((FREEIMAGEHEADER *)dib->data)->transparency_count : 0; -} - -void DLL_CALLCONV -FreeImage_SetTransparencyTable(FIBITMAP *dib, BYTE *table, int count) { - if (dib) { - count = MAX(0, MIN(count, 256)); - if (FreeImage_GetBPP(dib) <= 8) { - ((FREEIMAGEHEADER *)dib->data)->transparent = (count > 0) ? TRUE : FALSE; - ((FREEIMAGEHEADER *)dib->data)->transparency_count = count; - - if (table) { - memcpy(((FREEIMAGEHEADER *)dib->data)->transparent_table, table, count); - } else { - memset(((FREEIMAGEHEADER *)dib->data)->transparent_table, 0xff, count); - } - } - } -} - -/** @brief Sets the index of the palette entry to be used as transparent color - for the image specified. Does nothing on high color images. - - This method sets the index of the palette entry to be used as single transparent - color for the image specified. This works on palletised images only and does - nothing for high color images. - - Although it is possible for palletised images to have more than one transparent - color, this method sets the palette entry specified as the single transparent - color for the image. All other colors will be set to be non-transparent by this - method. - - As with FreeImage_SetTransparencyTable(), this method also sets the image's - transparency property to TRUE (as it is set and obtained by - FreeImage_SetTransparent() and FreeImage_IsTransparent() respectively) for - palletised images. - - @param dib Input image, whose transparent color is to be set. - @param index The index of the palette entry to be set as transparent color. - */ -void DLL_CALLCONV -FreeImage_SetTransparentIndex(FIBITMAP *dib, int index) { - if (dib) { - int count = FreeImage_GetColorsUsed(dib); - if (count) { - BYTE *new_tt = (BYTE *)malloc(count * sizeof(BYTE)); - memset(new_tt, 0xFF, count); - if ((index >= 0) && (index < count)) { - new_tt[index] = 0x00; - } - FreeImage_SetTransparencyTable(dib, new_tt, count); - free(new_tt); - } - } -} - -/** @brief Returns the palette entry used as transparent color for the image - specified. Works for palletised images only and returns -1 for high color - images or if the image has no color set to be transparent. - - Although it is possible for palletised images to have more than one transparent - color, this function always returns the index of the first palette entry, set - to be transparent. - - @param dib Input image, whose transparent color is to be returned. - @return Returns the index of the palette entry used as transparent color for - the image specified or -1 if there is no transparent color found (e.g. the image - is a high color image). - */ -int DLL_CALLCONV -FreeImage_GetTransparentIndex(FIBITMAP *dib) { - int count = FreeImage_GetTransparencyCount(dib); - BYTE *tt = FreeImage_GetTransparencyTable(dib); - for (int i = 0; i < count; i++) { - if (tt[i] == 0) { - return i; - } - } - return -1; -} - -// ---------------------------------------------------------- - -FIICCPROFILE * DLL_CALLCONV -FreeImage_GetICCProfile(FIBITMAP *dib) { - FIICCPROFILE *profile = (dib) ? (FIICCPROFILE *)&((FREEIMAGEHEADER *)dib->data)->iccProfile : NULL; - return profile; -} - -FIICCPROFILE * DLL_CALLCONV -FreeImage_CreateICCProfile(FIBITMAP *dib, void *data, long size) { - // clear the profile but preserve profile->flags - FreeImage_DestroyICCProfile(dib); - // create the new profile - FIICCPROFILE *profile = FreeImage_GetICCProfile(dib); - if(size && profile) { - profile->data = malloc(size); - if(profile->data) { - memcpy(profile->data, data, profile->size = size); - } - } - return profile; -} - -void DLL_CALLCONV -FreeImage_DestroyICCProfile(FIBITMAP *dib) { - FIICCPROFILE *profile = FreeImage_GetICCProfile(dib); - if(profile) { - if (profile->data) { - free (profile->data); - } - // clear the profile but preserve profile->flags - profile->data = NULL; - profile->size = 0; - } -} - -// ---------------------------------------------------------- - -unsigned DLL_CALLCONV -FreeImage_GetWidth(FIBITMAP *dib) { - return dib ? FreeImage_GetInfoHeader(dib)->biWidth : 0; -} - -unsigned DLL_CALLCONV -FreeImage_GetHeight(FIBITMAP *dib) { - return (dib) ? FreeImage_GetInfoHeader(dib)->biHeight : 0; -} - -unsigned DLL_CALLCONV -FreeImage_GetBPP(FIBITMAP *dib) { - return dib ? FreeImage_GetInfoHeader(dib)->biBitCount : 0; -} - -unsigned DLL_CALLCONV -FreeImage_GetLine(FIBITMAP *dib) { - return dib ? ((FreeImage_GetWidth(dib) * FreeImage_GetBPP(dib)) + 7) / 8 : 0; -} - -unsigned DLL_CALLCONV -FreeImage_GetPitch(FIBITMAP *dib) { - return dib ? FreeImage_GetLine(dib) + 3 & ~3 : 0; -} - -unsigned DLL_CALLCONV -FreeImage_GetColorsUsed(FIBITMAP *dib) { - return dib ? FreeImage_GetInfoHeader(dib)->biClrUsed : 0; -} - -unsigned DLL_CALLCONV -FreeImage_GetDIBSize(FIBITMAP *dib) { - return (dib) ? sizeof(BITMAPINFOHEADER) + (FreeImage_GetColorsUsed(dib) * sizeof(RGBQUAD)) + (FreeImage_GetPitch(dib) * FreeImage_GetHeight(dib)) : 0; -} - -RGBQUAD * DLL_CALLCONV -FreeImage_GetPalette(FIBITMAP *dib) { - return (dib && FreeImage_GetBPP(dib) < 16) ? (RGBQUAD *)(((BYTE *)FreeImage_GetInfoHeader(dib)) + sizeof(BITMAPINFOHEADER)) : NULL; -} - -unsigned DLL_CALLCONV -FreeImage_GetDotsPerMeterX(FIBITMAP *dib) { - return (dib) ? FreeImage_GetInfoHeader(dib)->biXPelsPerMeter : 0; -} - -unsigned DLL_CALLCONV -FreeImage_GetDotsPerMeterY(FIBITMAP *dib) { - return (dib) ? FreeImage_GetInfoHeader(dib)->biYPelsPerMeter : 0; -} - -void DLL_CALLCONV -FreeImage_SetDotsPerMeterX(FIBITMAP *dib, unsigned res) { - if(dib) { - FreeImage_GetInfoHeader(dib)->biXPelsPerMeter = res; - } -} - -void DLL_CALLCONV -FreeImage_SetDotsPerMeterY(FIBITMAP *dib, unsigned res) { - if(dib) { - FreeImage_GetInfoHeader(dib)->biYPelsPerMeter = res; - } -} - -BITMAPINFOHEADER * DLL_CALLCONV -FreeImage_GetInfoHeader(FIBITMAP *dib) { - if(!dib) return NULL; - size_t lp = (size_t)dib->data + sizeof(FREEIMAGEHEADER); - lp += (lp % FIBITMAP_ALIGNMENT ? FIBITMAP_ALIGNMENT - lp % FIBITMAP_ALIGNMENT : 0); - lp += FIBITMAP_ALIGNMENT - sizeof(BITMAPINFOHEADER) % FIBITMAP_ALIGNMENT; - return (BITMAPINFOHEADER *)lp; -} - -BITMAPINFO * DLL_CALLCONV -FreeImage_GetInfo(FIBITMAP *dib) { - return (BITMAPINFO *)FreeImage_GetInfoHeader(dib); -} - -// ---------------------------------------------------------- -// Metadata routines -// ---------------------------------------------------------- - -FIMETADATA * DLL_CALLCONV -FreeImage_FindFirstMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, FITAG **tag) { - if(!dib) - return NULL; - - // get the metadata model - METADATAMAP *metadata = ((FREEIMAGEHEADER *)dib->data)->metadata; - TAGMAP *tagmap = NULL; - if( (*metadata).find(model) != (*metadata).end() ) { - tagmap = (*metadata)[model]; - } - if(tagmap) { - // allocate a handle - FIMETADATA *handle = (FIMETADATA *)malloc(sizeof(FIMETADATA)); - if(handle) { - // calculate the size of a METADATAHEADER - int header_size = sizeof(METADATAHEADER); - - handle->data = (BYTE *)malloc(header_size * sizeof(BYTE)); - - if(handle->data) { - memset(handle->data, 0, header_size * sizeof(BYTE)); - - // write out the METADATAHEADER - METADATAHEADER *mdh = (METADATAHEADER *)handle->data; - - mdh->pos = 1; - mdh->tagmap = tagmap; - - // get the first element - TAGMAP::iterator i = tagmap->begin(); - *tag = (*i).second; - - return handle; - } - - free(handle); - } - } - - return NULL; -} - -BOOL DLL_CALLCONV -FreeImage_FindNextMetadata(FIMETADATA *mdhandle, FITAG **tag) { - if(!mdhandle) - return FALSE; - - METADATAHEADER *mdh = (METADATAHEADER *)mdhandle->data; - TAGMAP *tagmap = mdh->tagmap; - - int current_pos = mdh->pos; - int mapsize = (int)tagmap->size(); - - if(current_pos < mapsize) { - // get the tag element at position pos - int count = 0; - - for(TAGMAP::iterator i = tagmap->begin(); i != tagmap->end(); i++) { - if(count == current_pos) { - *tag = (*i).second; - mdh->pos++; - break; - } - count++; - } - - return TRUE; - } - - return FALSE; -} - -void DLL_CALLCONV -FreeImage_FindCloseMetadata(FIMETADATA *mdhandle) { - if (NULL != mdhandle) { // delete the handle - if (NULL != mdhandle->data) { - free(mdhandle->data); - } - free(mdhandle); // ... and the wrapper - } -} - - -// ---------------------------------------------------------- - -BOOL DLL_CALLCONV -FreeImage_CloneMetadata(FIBITMAP *dst, FIBITMAP *src) { - if(!src || !dst) return FALSE; - - // get metadata links - METADATAMAP *src_metadata = ((FREEIMAGEHEADER *)src->data)->metadata; - METADATAMAP *dst_metadata = ((FREEIMAGEHEADER *)dst->data)->metadata; - - // copy metadata models, *except* the FIMD_ANIMATION model - for(METADATAMAP::iterator i = (*src_metadata).begin(); i != (*src_metadata).end(); i++) { - int model = (*i).first; - if(model == (int)FIMD_ANIMATION) { - continue; - } - TAGMAP *src_tagmap = (*i).second; - - if(src_tagmap) { - if( dst_metadata->find(model) != dst_metadata->end() ) { - // destroy dst model - FreeImage_SetMetadata((FREE_IMAGE_MDMODEL)model, dst, NULL, NULL); - } - - // create a metadata model - TAGMAP *dst_tagmap = new(std::nothrow) TAGMAP(); - - if(dst_tagmap) { - // fill the model - for(TAGMAP::iterator j = src_tagmap->begin(); j != src_tagmap->end(); j++) { - std::string dst_key = (*j).first; - FITAG *dst_tag = FreeImage_CloneTag( (*j).second ); - - // assign key and tag value - (*dst_tagmap)[dst_key] = dst_tag; - } - - // assign model and tagmap - (*dst_metadata)[model] = dst_tagmap; - } - } - } - - // clone resolution - FreeImage_SetDotsPerMeterX(dst, FreeImage_GetDotsPerMeterX(src)); - FreeImage_SetDotsPerMeterY(dst, FreeImage_GetDotsPerMeterY(src)); - - return TRUE; -} - -// ---------------------------------------------------------- - -BOOL DLL_CALLCONV -FreeImage_SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, FITAG *tag) { - if(!dib) - return FALSE; - - TAGMAP *tagmap = NULL; - - // get the metadata model - METADATAMAP *metadata = ((FREEIMAGEHEADER *)dib->data)->metadata; - METADATAMAP::iterator model_iterator = metadata->find(model); - if (model_iterator != metadata->end()) { - tagmap = model_iterator->second; - } - - if(key != NULL) { - - if(!tagmap) { - // this model, doesn't exist: create it - tagmap = new(std::nothrow) TAGMAP(); - (*metadata)[model] = tagmap; - } - - if(tag) { - // first check the tag - if(FreeImage_GetTagKey(tag) == NULL) { - FreeImage_SetTagKey(tag, key); - } else if(strcmp(key, FreeImage_GetTagKey(tag)) != 0) { - // set the tag key - FreeImage_SetTagKey(tag, key); - } - if(FreeImage_GetTagCount(tag) * FreeImage_TagDataWidth(FreeImage_GetTagType(tag)) != FreeImage_GetTagLength(tag)) { - FreeImage_OutputMessageProc(FIF_UNKNOWN, "Invalid data count for tag '%s'", key); - return FALSE; - } - - // fill the tag ID if possible and if it's needed - TagLib& tag_lib = TagLib::instance(); - switch(model) { - case FIMD_IPTC: - { - int id = tag_lib.getTagID(TagLib::IPTC, key); - /* - if(id == -1) { - FreeImage_OutputMessageProc(FIF_UNKNOWN, "IPTC: Invalid key '%s'", key); - } - */ - FreeImage_SetTagID(tag, (WORD)id); - } - break; - - default: - break; - } - - // delete existing tag - FITAG *old_tag = (*tagmap)[key]; - if(old_tag) { - FreeImage_DeleteTag(old_tag); - } - - // create a new tag - (*tagmap)[key] = FreeImage_CloneTag(tag); - } - else { - // delete existing tag - TAGMAP::iterator i = tagmap->find(key); - if(i != tagmap->end()) { - FITAG *old_tag = (*i).second; - FreeImage_DeleteTag(old_tag); - tagmap->erase(key); - } - } - } - else { - // destroy the metadata model - if(tagmap) { - for(TAGMAP::iterator i = tagmap->begin(); i != tagmap->end(); i++) { - FITAG *tag = (*i).second; - FreeImage_DeleteTag(tag); - } - - delete tagmap; - metadata->erase(model_iterator); - } - } - - return TRUE; -} - -BOOL DLL_CALLCONV -FreeImage_GetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, FITAG **tag) { - if(!dib || !key || !tag) - return FALSE; - - TAGMAP *tagmap = NULL; - *tag = NULL; - - // get the metadata model - METADATAMAP *metadata = ((FREEIMAGEHEADER *)dib->data)->metadata; - if(!(*metadata).empty()) { - METADATAMAP::iterator model_iterator = metadata->find(model); - if (model_iterator != metadata->end() ) { - // this model exists : try to get the requested tag - tagmap = model_iterator->second; - TAGMAP::iterator tag_iterator = tagmap->find(key); - if (tag_iterator != tagmap->end() ) { - // get the requested tag - *tag = tag_iterator->second; - } - } - } - - return (*tag != NULL) ? TRUE : FALSE; -} - -// ---------------------------------------------------------- - -unsigned DLL_CALLCONV -FreeImage_GetMetadataCount(FREE_IMAGE_MDMODEL model, FIBITMAP *dib) { - if(!dib) - return FALSE; - - TAGMAP *tagmap = NULL; - - // get the metadata model - METADATAMAP *metadata = ((FREEIMAGEHEADER *)dib->data)->metadata; - if( (*metadata).find(model) != (*metadata).end() ) { - tagmap = (*metadata)[model]; - } - if(!tagmap) { - // this model, doesn't exist: return - return 0; - } - - // get the tag count - return (unsigned)tagmap->size(); -} - -// ---------------------------------------------------------- - - +Returns a pointer to the bitmap's red-, green- and blue masks. +@param dib The bitmap to obtain masks from. +@return Returns a pointer to the bitmap's red-, green- and blue masks +or NULL, if no masks are present (e.g. for 24 bit images). +*/ +static FREEIMAGERGBMASKS * +FreeImage_GetRGBMasks(FIBITMAP *dib) { + return FreeImage_HasRGBMasks(dib) ? (FREEIMAGERGBMASKS *)(((BYTE *)FreeImage_GetInfoHeader(dib)) + sizeof(BITMAPINFOHEADER)) : NULL; +} + +FIBITMAP * DLL_CALLCONV +FreeImage_AllocateHeaderT(BOOL header_only, FREE_IMAGE_TYPE type, int width, int height, int bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask) { + + // check input variables + width = abs(width); + height = abs(height); + if(!((width > 0) && (height > 0))) { + return NULL; + } + + // we only store the masks (and allocate memory for + // them) for 16 images of type FIT_BITMAP + BOOL need_masks = FALSE; + + // check pixel bit depth + switch(type) { + case FIT_BITMAP: + switch(bpp) { + case 1: + case 4: + case 8: + break; + case 16: + need_masks = TRUE; + break; + case 24: + case 32: + break; + default: + bpp = 8; + break; + } + break; + case FIT_UINT16: + bpp = 8 * sizeof(unsigned short); + break; + case FIT_INT16: + bpp = 8 * sizeof(short); + break; + case FIT_UINT32: + bpp = 8 * sizeof(DWORD); + break; + case FIT_INT32: + bpp = 8 * sizeof(LONG); + break; + case FIT_FLOAT: + bpp = 8 * sizeof(float); + break; + case FIT_DOUBLE: + bpp = 8 * sizeof(double); + break; + case FIT_COMPLEX: + bpp = 8 * sizeof(FICOMPLEX); + break; + case FIT_RGB16: + bpp = 8 * sizeof(FIRGB16); + break; + case FIT_RGBA16: + bpp = 8 * sizeof(FIRGBA16); + break; + case FIT_RGBF: + bpp = 8 * sizeof(FIRGBF); + break; + case FIT_RGBAF: + bpp = 8 * sizeof(FIRGBAF); + break; + default: + return NULL; + } + + FIBITMAP *bitmap = (FIBITMAP *)malloc(sizeof(FIBITMAP)); + + if (bitmap != NULL) { + + // calculate the size of a FreeImage image + // align the palette and the pixels on a FIBITMAP_ALIGNMENT bytes alignment boundary + // palette is aligned on a 16 bytes boundary + // pixels are aligned on a 16 bytes boundary + + size_t dib_size = FreeImage_GetImageSizeHeader(header_only, width, height, bpp, need_masks); + + if(dib_size == 0) { + // memory allocation will fail (probably a malloc overflow) + free(bitmap); + return NULL; + } + + bitmap->data = (BYTE *)FreeImage_Aligned_Malloc(dib_size * sizeof(BYTE), FIBITMAP_ALIGNMENT); + + if (bitmap->data != NULL) { + memset(bitmap->data, 0, dib_size); + + // write out the FREEIMAGEHEADER + + FREEIMAGEHEADER *fih = (FREEIMAGEHEADER *)bitmap->data; + fih->type = type; + + memset(&fih->bkgnd_color, 0, sizeof(RGBQUAD)); + + fih->transparent = FALSE; + fih->transparency_count = 0; + memset(fih->transparent_table, 0xff, 256); + + fih->has_pixels = header_only ? FALSE : TRUE; + + // initialize FIICCPROFILE link + + FIICCPROFILE *iccProfile = FreeImage_GetICCProfile(bitmap); + iccProfile->size = 0; + iccProfile->data = 0; + iccProfile->flags = 0; + + // initialize metadata models list + + fih->metadata = new(std::nothrow) METADATAMAP; + + // initialize attached thumbnail + + fih->thumbnail = NULL; + + // write out the BITMAPINFOHEADER + + BITMAPINFOHEADER *bih = FreeImage_GetInfoHeader(bitmap); + bih->biSize = sizeof(BITMAPINFOHEADER); + bih->biWidth = width; + bih->biHeight = height; + bih->biPlanes = 1; + bih->biCompression = need_masks ? BI_BITFIELDS : BI_RGB; + bih->biBitCount = (WORD)bpp; + bih->biClrUsed = CalculateUsedPaletteEntries(bpp); + bih->biClrImportant = bih->biClrUsed; + bih->biXPelsPerMeter = 2835; // 72 dpi + bih->biYPelsPerMeter = 2835; // 72 dpi + + if(bpp == 8) { + // build a default greyscale palette (very useful for image processing) + RGBQUAD *pal = FreeImage_GetPalette(bitmap); + for(int i = 0; i < 256; i++) { + pal[i].rgbRed = (BYTE)i; + pal[i].rgbGreen = (BYTE)i; + pal[i].rgbBlue = (BYTE)i; + } + } + + // just setting the masks (only if needed) just like the palette. + if (need_masks) { + FREEIMAGERGBMASKS *masks = FreeImage_GetRGBMasks(bitmap); + masks->red_mask = red_mask; + masks->green_mask = green_mask; + masks->blue_mask = blue_mask; + } + + return bitmap; + } + + free(bitmap); + } + + return NULL; +} + +FIBITMAP * DLL_CALLCONV +FreeImage_AllocateHeader(BOOL header_only, int width, int height, int bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask) { + return FreeImage_AllocateHeaderT(header_only, FIT_BITMAP, width, height, bpp, red_mask, green_mask, blue_mask); +} + +FIBITMAP * DLL_CALLCONV +FreeImage_Allocate(int width, int height, int bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask) { + return FreeImage_AllocateHeaderT(FALSE, FIT_BITMAP, width, height, bpp, red_mask, green_mask, blue_mask); +} + +FIBITMAP * DLL_CALLCONV +FreeImage_AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask) { + return FreeImage_AllocateHeaderT(FALSE, type, width, height, bpp, red_mask, green_mask, blue_mask); +} + +void DLL_CALLCONV +FreeImage_Unload(FIBITMAP *dib) { + if (NULL != dib) { + if (NULL != dib->data) { + // delete possible icc profile ... + if (FreeImage_GetICCProfile(dib)->data) + free(FreeImage_GetICCProfile(dib)->data); + + // delete metadata models + METADATAMAP *metadata = ((FREEIMAGEHEADER *)dib->data)->metadata; + + for(METADATAMAP::iterator i = (*metadata).begin(); i != (*metadata).end(); i++) { + TAGMAP *tagmap = (*i).second; + + if(tagmap) { + for(TAGMAP::iterator j = tagmap->begin(); j != tagmap->end(); j++) { + FITAG *tag = (*j).second; + FreeImage_DeleteTag(tag); + } + + delete tagmap; + } + } + + delete metadata; + + // delete embedded thumbnail + FreeImage_Unload(FreeImage_GetThumbnail(dib)); + + // delete bitmap ... + FreeImage_Aligned_Free(dib->data); + } + free(dib); // ... and the wrapper + } +} + +// ---------------------------------------------------------- + +FIBITMAP * DLL_CALLCONV +FreeImage_Clone(FIBITMAP *dib) { + if(!dib) return NULL; + + FREE_IMAGE_TYPE type = FreeImage_GetImageType(dib); + unsigned width = FreeImage_GetWidth(dib); + unsigned height = FreeImage_GetHeight(dib); + unsigned bpp = FreeImage_GetBPP(dib); + + // check for pixel availability ... + BOOL header_only = FreeImage_HasPixels(dib) ? FALSE : TRUE; + // check whether this image has masks defined ... + BOOL need_masks = (bpp == 16 && type == FIT_BITMAP) ? TRUE : FALSE; + + // allocate a new dib + FIBITMAP *new_dib = FreeImage_AllocateHeaderT(header_only, type, width, height, bpp, + FreeImage_GetRedMask(dib), FreeImage_GetGreenMask(dib), FreeImage_GetBlueMask(dib)); + + if (new_dib) { + // save ICC profile links + FIICCPROFILE *src_iccProfile = FreeImage_GetICCProfile(dib); + FIICCPROFILE *dst_iccProfile = FreeImage_GetICCProfile(new_dib); + + // save metadata links + METADATAMAP *src_metadata = ((FREEIMAGEHEADER *)dib->data)->metadata; + METADATAMAP *dst_metadata = ((FREEIMAGEHEADER *)new_dib->data)->metadata; + + // calculate the size of a FreeImage image + // align the palette and the pixels on a FIBITMAP_ALIGNMENT bytes alignment boundary + // palette is aligned on a 16 bytes boundary + // pixels are aligned on a 16 bytes boundary + + size_t dib_size = FreeImage_GetImageSizeHeader(header_only, width, height, bpp, need_masks); + + // copy the bitmap + internal pointers (remember to restore new_dib internal pointers later) + memcpy(new_dib->data, dib->data, dib_size); + + // reset ICC profile link for new_dib + memset(dst_iccProfile, 0, sizeof(FIICCPROFILE)); + + // restore metadata link for new_dib + ((FREEIMAGEHEADER *)new_dib->data)->metadata = dst_metadata; + + // reset thumbnail link for new_dib + ((FREEIMAGEHEADER *)new_dib->data)->thumbnail = NULL; + + // copy possible ICC profile + FreeImage_CreateICCProfile(new_dib, src_iccProfile->data, src_iccProfile->size); + dst_iccProfile->flags = src_iccProfile->flags; + + // copy metadata models + for(METADATAMAP::iterator i = (*src_metadata).begin(); i != (*src_metadata).end(); i++) { + int model = (*i).first; + TAGMAP *src_tagmap = (*i).second; + + if(src_tagmap) { + // create a metadata model + TAGMAP *dst_tagmap = new(std::nothrow) TAGMAP(); + + if(dst_tagmap) { + // fill the model + for(TAGMAP::iterator j = src_tagmap->begin(); j != src_tagmap->end(); j++) { + std::string dst_key = (*j).first; + FITAG *dst_tag = FreeImage_CloneTag( (*j).second ); + + // assign key and tag value + (*dst_tagmap)[dst_key] = dst_tag; + } + + // assign model and tagmap + (*dst_metadata)[model] = dst_tagmap; + } + } + } + + // copy the thumbnail + FreeImage_SetThumbnail(new_dib, FreeImage_GetThumbnail(dib)); + + return new_dib; + } + + return NULL; +} + +// ---------------------------------------------------------- + +FIBITMAP* DLL_CALLCONV +FreeImage_GetThumbnail(FIBITMAP *dib) { + return (dib != NULL) ? ((FREEIMAGEHEADER *)dib->data)->thumbnail : NULL; +} + +BOOL DLL_CALLCONV +FreeImage_SetThumbnail(FIBITMAP *dib, FIBITMAP *thumbnail) { + if(dib == NULL) { + return FALSE; + } + FIBITMAP *currentThumbnail = ((FREEIMAGEHEADER *)dib->data)->thumbnail; + if(currentThumbnail == thumbnail) { + return TRUE; + } + FreeImage_Unload(currentThumbnail); + + ((FREEIMAGEHEADER *)dib->data)->thumbnail = FreeImage_HasPixels(thumbnail) ? FreeImage_Clone(thumbnail) : NULL; + + return TRUE; +} + +// ---------------------------------------------------------- + +FREE_IMAGE_COLOR_TYPE DLL_CALLCONV +FreeImage_GetColorType(FIBITMAP *dib) { + RGBQUAD *rgb; + + const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); + + // special bitmap type + if(image_type != FIT_BITMAP) { + switch(image_type) { + case FIT_RGB16: + case FIT_RGBF: + return FIC_RGB; + case FIT_RGBA16: + case FIT_RGBAF: + return FIC_RGBALPHA; + } + + return FIC_MINISBLACK; + } + + // standard image type + switch (FreeImage_GetBPP(dib)) { + case 1: + { + rgb = FreeImage_GetPalette(dib); + + if ((rgb->rgbRed == 0) && (rgb->rgbGreen == 0) && (rgb->rgbBlue == 0)) { + rgb++; + + if ((rgb->rgbRed == 255) && (rgb->rgbGreen == 255) && (rgb->rgbBlue == 255)) + return FIC_MINISBLACK; + } + + if ((rgb->rgbRed == 255) && (rgb->rgbGreen == 255) && (rgb->rgbBlue == 255)) { + rgb++; + + if ((rgb->rgbRed == 0) && (rgb->rgbGreen == 0) && (rgb->rgbBlue == 0)) + return FIC_MINISWHITE; + } + + return FIC_PALETTE; + } + + case 4: + case 8: // Check if the DIB has a color or a greyscale palette + { + int ncolors = FreeImage_GetColorsUsed(dib); + int minisblack = 1; + rgb = FreeImage_GetPalette(dib); + + for (int i = 0; i < ncolors; i++) { + if ((rgb->rgbRed != rgb->rgbGreen) || (rgb->rgbRed != rgb->rgbBlue)) + return FIC_PALETTE; + + // The DIB has a color palette if the greyscale isn't a linear ramp + // Take care of reversed grey images + if (rgb->rgbRed != i) { + if ((ncolors-i-1) != rgb->rgbRed) + return FIC_PALETTE; + else + minisblack = 0; + } + + rgb++; + } + + return minisblack ? FIC_MINISBLACK : FIC_MINISWHITE; + } + + case 16: + case 24: + return FIC_RGB; + + case 32: + { + if (FreeImage_GetICCProfile(dib)->flags & FIICC_COLOR_IS_CMYK) + return FIC_CMYK; + + if( FreeImage_HasPixels(dib) ) { + // check for fully opaque alpha layer + for (unsigned y = 0; y < FreeImage_GetHeight(dib); y++) { + rgb = (RGBQUAD *)FreeImage_GetScanLine(dib, y); + + for (unsigned x = 0; x < FreeImage_GetWidth(dib); x++) + if (rgb[x].rgbReserved != 0xFF) + return FIC_RGBALPHA; + } + return FIC_RGB; + } + + return FIC_RGBALPHA; + } + + default : + return FIC_MINISBLACK; + } +} + +// ---------------------------------------------------------- + +FREE_IMAGE_TYPE DLL_CALLCONV +FreeImage_GetImageType(FIBITMAP *dib) { + return (dib != NULL) ? ((FREEIMAGEHEADER *)dib->data)->type : FIT_UNKNOWN; +} + +// ---------------------------------------------------------- + +BOOL DLL_CALLCONV +FreeImage_HasPixels(FIBITMAP *dib) { + return (dib != NULL) ? ((FREEIMAGEHEADER *)dib->data)->has_pixels : FALSE; +} + +// ---------------------------------------------------------- + +BOOL DLL_CALLCONV +FreeImage_HasRGBMasks(FIBITMAP *dib) { + return dib && FreeImage_GetInfoHeader(dib)->biCompression == BI_BITFIELDS; +} + +unsigned DLL_CALLCONV +FreeImage_GetRedMask(FIBITMAP *dib) { + FREEIMAGERGBMASKS *masks = FreeImage_GetRGBMasks(dib); + return masks ? masks->red_mask : 0; +} + +unsigned DLL_CALLCONV +FreeImage_GetGreenMask(FIBITMAP *dib) { + FREEIMAGERGBMASKS *masks = FreeImage_GetRGBMasks(dib); + return masks ? masks->green_mask : 0; +} + +unsigned DLL_CALLCONV +FreeImage_GetBlueMask(FIBITMAP *dib) { + FREEIMAGERGBMASKS *masks = FreeImage_GetRGBMasks(dib); + return masks ? masks->blue_mask : 0; +} + +// ---------------------------------------------------------- + +BOOL DLL_CALLCONV +FreeImage_HasBackgroundColor(FIBITMAP *dib) { + if(dib) { + RGBQUAD *bkgnd_color = &((FREEIMAGEHEADER *)dib->data)->bkgnd_color; + return (bkgnd_color->rgbReserved != 0) ? TRUE : FALSE; + } + return FALSE; +} + +BOOL DLL_CALLCONV +FreeImage_GetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor) { + if(dib && bkcolor) { + if(FreeImage_HasBackgroundColor(dib)) { + // get the background color + RGBQUAD *bkgnd_color = &((FREEIMAGEHEADER *)dib->data)->bkgnd_color; + memcpy(bkcolor, bkgnd_color, sizeof(RGBQUAD)); + // get the background index + if(FreeImage_GetBPP(dib) == 8) { + RGBQUAD *pal = FreeImage_GetPalette(dib); + for(unsigned i = 0; i < FreeImage_GetColorsUsed(dib); i++) { + if(bkgnd_color->rgbRed == pal[i].rgbRed) { + if(bkgnd_color->rgbGreen == pal[i].rgbGreen) { + if(bkgnd_color->rgbBlue == pal[i].rgbBlue) { + bkcolor->rgbReserved = (BYTE)i; + return TRUE; + } + } + } + } + } + + bkcolor->rgbReserved = 0; + + return TRUE; + } + } + + return FALSE; +} + +BOOL DLL_CALLCONV +FreeImage_SetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor) { + if(dib) { + RGBQUAD *bkgnd_color = &((FREEIMAGEHEADER *)dib->data)->bkgnd_color; + if(bkcolor) { + // set the background color + memcpy(bkgnd_color, bkcolor, sizeof(RGBQUAD)); + // enable the file background color + bkgnd_color->rgbReserved = 1; + } else { + // clear and disable the file background color + memset(bkgnd_color, 0, sizeof(RGBQUAD)); + } + return TRUE; + } + + return FALSE; +} + +// ---------------------------------------------------------- + +BOOL DLL_CALLCONV +FreeImage_IsTransparent(FIBITMAP *dib) { + if(dib) { + FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); + switch(image_type) { + case FIT_BITMAP: + if(FreeImage_GetBPP(dib) == 32) { + if(FreeImage_GetColorType(dib) == FIC_RGBALPHA) { + return TRUE; + } + } else { + return ((FREEIMAGEHEADER *)dib->data)->transparent ? TRUE : FALSE; + } + break; + case FIT_RGBA16: + case FIT_RGBAF: + return TRUE; + default: + break; + } + } + return FALSE; +} + +BYTE * DLL_CALLCONV +FreeImage_GetTransparencyTable(FIBITMAP *dib) { + return dib ? ((FREEIMAGEHEADER *)dib->data)->transparent_table : NULL; +} + +void DLL_CALLCONV +FreeImage_SetTransparent(FIBITMAP *dib, BOOL enabled) { + if (dib) { + if ((FreeImage_GetBPP(dib) <= 8) || (FreeImage_GetBPP(dib) == 32)) { + ((FREEIMAGEHEADER *)dib->data)->transparent = enabled; + } else { + ((FREEIMAGEHEADER *)dib->data)->transparent = FALSE; + } + } +} + +unsigned DLL_CALLCONV +FreeImage_GetTransparencyCount(FIBITMAP *dib) { + return dib ? ((FREEIMAGEHEADER *)dib->data)->transparency_count : 0; +} + +void DLL_CALLCONV +FreeImage_SetTransparencyTable(FIBITMAP *dib, BYTE *table, int count) { + if (dib) { + count = MAX(0, MIN(count, 256)); + if (FreeImage_GetBPP(dib) <= 8) { + ((FREEIMAGEHEADER *)dib->data)->transparent = (count > 0) ? TRUE : FALSE; + ((FREEIMAGEHEADER *)dib->data)->transparency_count = count; + + if (table) { + memcpy(((FREEIMAGEHEADER *)dib->data)->transparent_table, table, count); + } else { + memset(((FREEIMAGEHEADER *)dib->data)->transparent_table, 0xff, count); + } + } + } +} + +/** @brief Sets the index of the palette entry to be used as transparent color + for the image specified. Does nothing on high color images. + + This method sets the index of the palette entry to be used as single transparent + color for the image specified. This works on palletised images only and does + nothing for high color images. + + Although it is possible for palletised images to have more than one transparent + color, this method sets the palette entry specified as the single transparent + color for the image. All other colors will be set to be non-transparent by this + method. + + As with FreeImage_SetTransparencyTable(), this method also sets the image's + transparency property to TRUE (as it is set and obtained by + FreeImage_SetTransparent() and FreeImage_IsTransparent() respectively) for + palletised images. + + @param dib Input image, whose transparent color is to be set. + @param index The index of the palette entry to be set as transparent color. + */ +void DLL_CALLCONV +FreeImage_SetTransparentIndex(FIBITMAP *dib, int index) { + if (dib) { + int count = FreeImage_GetColorsUsed(dib); + if (count) { + BYTE *new_tt = (BYTE *)malloc(count * sizeof(BYTE)); + memset(new_tt, 0xFF, count); + if ((index >= 0) && (index < count)) { + new_tt[index] = 0x00; + } + FreeImage_SetTransparencyTable(dib, new_tt, count); + free(new_tt); + } + } +} + +/** @brief Returns the palette entry used as transparent color for the image + specified. Works for palletised images only and returns -1 for high color + images or if the image has no color set to be transparent. + + Although it is possible for palletised images to have more than one transparent + color, this function always returns the index of the first palette entry, set + to be transparent. + + @param dib Input image, whose transparent color is to be returned. + @return Returns the index of the palette entry used as transparent color for + the image specified or -1 if there is no transparent color found (e.g. the image + is a high color image). + */ +int DLL_CALLCONV +FreeImage_GetTransparentIndex(FIBITMAP *dib) { + int count = FreeImage_GetTransparencyCount(dib); + BYTE *tt = FreeImage_GetTransparencyTable(dib); + for (int i = 0; i < count; i++) { + if (tt[i] == 0) { + return i; + } + } + return -1; +} + +// ---------------------------------------------------------- + +FIICCPROFILE * DLL_CALLCONV +FreeImage_GetICCProfile(FIBITMAP *dib) { + FIICCPROFILE *profile = (dib) ? (FIICCPROFILE *)&((FREEIMAGEHEADER *)dib->data)->iccProfile : NULL; + return profile; +} + +FIICCPROFILE * DLL_CALLCONV +FreeImage_CreateICCProfile(FIBITMAP *dib, void *data, long size) { + // clear the profile but preserve profile->flags + FreeImage_DestroyICCProfile(dib); + // create the new profile + FIICCPROFILE *profile = FreeImage_GetICCProfile(dib); + if(size && profile) { + profile->data = malloc(size); + if(profile->data) { + memcpy(profile->data, data, profile->size = size); + } + } + return profile; +} + +void DLL_CALLCONV +FreeImage_DestroyICCProfile(FIBITMAP *dib) { + FIICCPROFILE *profile = FreeImage_GetICCProfile(dib); + if(profile) { + if (profile->data) { + free (profile->data); + } + // clear the profile but preserve profile->flags + profile->data = NULL; + profile->size = 0; + } +} + +// ---------------------------------------------------------- + +unsigned DLL_CALLCONV +FreeImage_GetWidth(FIBITMAP *dib) { + return dib ? FreeImage_GetInfoHeader(dib)->biWidth : 0; +} + +unsigned DLL_CALLCONV +FreeImage_GetHeight(FIBITMAP *dib) { + return (dib) ? FreeImage_GetInfoHeader(dib)->biHeight : 0; +} + +unsigned DLL_CALLCONV +FreeImage_GetBPP(FIBITMAP *dib) { + return dib ? FreeImage_GetInfoHeader(dib)->biBitCount : 0; +} + +unsigned DLL_CALLCONV +FreeImage_GetLine(FIBITMAP *dib) { + return dib ? ((FreeImage_GetWidth(dib) * FreeImage_GetBPP(dib)) + 7) / 8 : 0; +} + +unsigned DLL_CALLCONV +FreeImage_GetPitch(FIBITMAP *dib) { + return dib ? FreeImage_GetLine(dib) + 3 & ~3 : 0; +} + +unsigned DLL_CALLCONV +FreeImage_GetColorsUsed(FIBITMAP *dib) { + return dib ? FreeImage_GetInfoHeader(dib)->biClrUsed : 0; +} + +unsigned DLL_CALLCONV +FreeImage_GetDIBSize(FIBITMAP *dib) { + return (dib) ? sizeof(BITMAPINFOHEADER) + (FreeImage_GetColorsUsed(dib) * sizeof(RGBQUAD)) + (FreeImage_GetPitch(dib) * FreeImage_GetHeight(dib)) : 0; +} + +RGBQUAD * DLL_CALLCONV +FreeImage_GetPalette(FIBITMAP *dib) { + return (dib && FreeImage_GetBPP(dib) < 16) ? (RGBQUAD *)(((BYTE *)FreeImage_GetInfoHeader(dib)) + sizeof(BITMAPINFOHEADER)) : NULL; +} + +unsigned DLL_CALLCONV +FreeImage_GetDotsPerMeterX(FIBITMAP *dib) { + return (dib) ? FreeImage_GetInfoHeader(dib)->biXPelsPerMeter : 0; +} + +unsigned DLL_CALLCONV +FreeImage_GetDotsPerMeterY(FIBITMAP *dib) { + return (dib) ? FreeImage_GetInfoHeader(dib)->biYPelsPerMeter : 0; +} + +void DLL_CALLCONV +FreeImage_SetDotsPerMeterX(FIBITMAP *dib, unsigned res) { + if(dib) { + FreeImage_GetInfoHeader(dib)->biXPelsPerMeter = res; + } +} + +void DLL_CALLCONV +FreeImage_SetDotsPerMeterY(FIBITMAP *dib, unsigned res) { + if(dib) { + FreeImage_GetInfoHeader(dib)->biYPelsPerMeter = res; + } +} + +BITMAPINFOHEADER * DLL_CALLCONV +FreeImage_GetInfoHeader(FIBITMAP *dib) { + if(!dib) return NULL; + size_t lp = (size_t)dib->data + sizeof(FREEIMAGEHEADER); + lp += (lp % FIBITMAP_ALIGNMENT ? FIBITMAP_ALIGNMENT - lp % FIBITMAP_ALIGNMENT : 0); + lp += FIBITMAP_ALIGNMENT - sizeof(BITMAPINFOHEADER) % FIBITMAP_ALIGNMENT; + return (BITMAPINFOHEADER *)lp; +} + +BITMAPINFO * DLL_CALLCONV +FreeImage_GetInfo(FIBITMAP *dib) { + return (BITMAPINFO *)FreeImage_GetInfoHeader(dib); +} + +// ---------------------------------------------------------- +// Metadata routines +// ---------------------------------------------------------- + +FIMETADATA * DLL_CALLCONV +FreeImage_FindFirstMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, FITAG **tag) { + if(!dib) + return NULL; + + // get the metadata model + METADATAMAP *metadata = ((FREEIMAGEHEADER *)dib->data)->metadata; + TAGMAP *tagmap = NULL; + if( (*metadata).find(model) != (*metadata).end() ) { + tagmap = (*metadata)[model]; + } + if(tagmap) { + // allocate a handle + FIMETADATA *handle = (FIMETADATA *)malloc(sizeof(FIMETADATA)); + if(handle) { + // calculate the size of a METADATAHEADER + int header_size = sizeof(METADATAHEADER); + + handle->data = (BYTE *)malloc(header_size * sizeof(BYTE)); + + if(handle->data) { + memset(handle->data, 0, header_size * sizeof(BYTE)); + + // write out the METADATAHEADER + METADATAHEADER *mdh = (METADATAHEADER *)handle->data; + + mdh->pos = 1; + mdh->tagmap = tagmap; + + // get the first element + TAGMAP::iterator i = tagmap->begin(); + *tag = (*i).second; + + return handle; + } + + free(handle); + } + } + + return NULL; +} + +BOOL DLL_CALLCONV +FreeImage_FindNextMetadata(FIMETADATA *mdhandle, FITAG **tag) { + if(!mdhandle) + return FALSE; + + METADATAHEADER *mdh = (METADATAHEADER *)mdhandle->data; + TAGMAP *tagmap = mdh->tagmap; + + int current_pos = mdh->pos; + int mapsize = (int)tagmap->size(); + + if(current_pos < mapsize) { + // get the tag element at position pos + int count = 0; + + for(TAGMAP::iterator i = tagmap->begin(); i != tagmap->end(); i++) { + if(count == current_pos) { + *tag = (*i).second; + mdh->pos++; + break; + } + count++; + } + + return TRUE; + } + + return FALSE; +} + +void DLL_CALLCONV +FreeImage_FindCloseMetadata(FIMETADATA *mdhandle) { + if (NULL != mdhandle) { // delete the handle + if (NULL != mdhandle->data) { + free(mdhandle->data); + } + free(mdhandle); // ... and the wrapper + } +} + + +// ---------------------------------------------------------- + +BOOL DLL_CALLCONV +FreeImage_CloneMetadata(FIBITMAP *dst, FIBITMAP *src) { + if(!src || !dst) return FALSE; + + // get metadata links + METADATAMAP *src_metadata = ((FREEIMAGEHEADER *)src->data)->metadata; + METADATAMAP *dst_metadata = ((FREEIMAGEHEADER *)dst->data)->metadata; + + // copy metadata models, *except* the FIMD_ANIMATION model + for(METADATAMAP::iterator i = (*src_metadata).begin(); i != (*src_metadata).end(); i++) { + int model = (*i).first; + if(model == (int)FIMD_ANIMATION) { + continue; + } + TAGMAP *src_tagmap = (*i).second; + + if(src_tagmap) { + if( dst_metadata->find(model) != dst_metadata->end() ) { + // destroy dst model + FreeImage_SetMetadata((FREE_IMAGE_MDMODEL)model, dst, NULL, NULL); + } + + // create a metadata model + TAGMAP *dst_tagmap = new(std::nothrow) TAGMAP(); + + if(dst_tagmap) { + // fill the model + for(TAGMAP::iterator j = src_tagmap->begin(); j != src_tagmap->end(); j++) { + std::string dst_key = (*j).first; + FITAG *dst_tag = FreeImage_CloneTag( (*j).second ); + + // assign key and tag value + (*dst_tagmap)[dst_key] = dst_tag; + } + + // assign model and tagmap + (*dst_metadata)[model] = dst_tagmap; + } + } + } + + // clone resolution + FreeImage_SetDotsPerMeterX(dst, FreeImage_GetDotsPerMeterX(src)); + FreeImage_SetDotsPerMeterY(dst, FreeImage_GetDotsPerMeterY(src)); + + return TRUE; +} + +// ---------------------------------------------------------- + +BOOL DLL_CALLCONV +FreeImage_SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, FITAG *tag) { + if(!dib) + return FALSE; + + TAGMAP *tagmap = NULL; + + // get the metadata model + METADATAMAP *metadata = ((FREEIMAGEHEADER *)dib->data)->metadata; + METADATAMAP::iterator model_iterator = metadata->find(model); + if (model_iterator != metadata->end()) { + tagmap = model_iterator->second; + } + + if(key != NULL) { + + if(!tagmap) { + // this model, doesn't exist: create it + tagmap = new(std::nothrow) TAGMAP(); + (*metadata)[model] = tagmap; + } + + if(tag) { + // first check the tag + if(FreeImage_GetTagKey(tag) == NULL) { + FreeImage_SetTagKey(tag, key); + } else if(strcmp(key, FreeImage_GetTagKey(tag)) != 0) { + // set the tag key + FreeImage_SetTagKey(tag, key); + } + if(FreeImage_GetTagCount(tag) * FreeImage_TagDataWidth(FreeImage_GetTagType(tag)) != FreeImage_GetTagLength(tag)) { + FreeImage_OutputMessageProc(FIF_UNKNOWN, "Invalid data count for tag '%s'", key); + return FALSE; + } + + // fill the tag ID if possible and if it's needed + TagLib& tag_lib = TagLib::instance(); + switch(model) { + case FIMD_IPTC: + { + int id = tag_lib.getTagID(TagLib::IPTC, key); + /* + if(id == -1) { + FreeImage_OutputMessageProc(FIF_UNKNOWN, "IPTC: Invalid key '%s'", key); + } + */ + FreeImage_SetTagID(tag, (WORD)id); + } + break; + + default: + break; + } + + // delete existing tag + FITAG *old_tag = (*tagmap)[key]; + if(old_tag) { + FreeImage_DeleteTag(old_tag); + } + + // create a new tag + (*tagmap)[key] = FreeImage_CloneTag(tag); + } + else { + // delete existing tag + TAGMAP::iterator i = tagmap->find(key); + if(i != tagmap->end()) { + FITAG *old_tag = (*i).second; + FreeImage_DeleteTag(old_tag); + tagmap->erase(key); + } + } + } + else { + // destroy the metadata model + if(tagmap) { + for(TAGMAP::iterator i = tagmap->begin(); i != tagmap->end(); i++) { + FITAG *tag = (*i).second; + FreeImage_DeleteTag(tag); + } + + delete tagmap; + metadata->erase(model_iterator); + } + } + + return TRUE; +} + +BOOL DLL_CALLCONV +FreeImage_GetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, FITAG **tag) { + if(!dib || !key || !tag) + return FALSE; + + TAGMAP *tagmap = NULL; + *tag = NULL; + + // get the metadata model + METADATAMAP *metadata = ((FREEIMAGEHEADER *)dib->data)->metadata; + if(!(*metadata).empty()) { + METADATAMAP::iterator model_iterator = metadata->find(model); + if (model_iterator != metadata->end() ) { + // this model exists : try to get the requested tag + tagmap = model_iterator->second; + TAGMAP::iterator tag_iterator = tagmap->find(key); + if (tag_iterator != tagmap->end() ) { + // get the requested tag + *tag = tag_iterator->second; + } + } + } + + return (*tag != NULL) ? TRUE : FALSE; +} + +// ---------------------------------------------------------- + +unsigned DLL_CALLCONV +FreeImage_GetMetadataCount(FREE_IMAGE_MDMODEL model, FIBITMAP *dib) { + if(!dib) + return FALSE; + + TAGMAP *tagmap = NULL; + + // get the metadata model + METADATAMAP *metadata = ((FREEIMAGEHEADER *)dib->data)->metadata; + if( (*metadata).find(model) != (*metadata).end() ) { + tagmap = (*metadata)[model]; + } + if(!tagmap) { + // this model, doesn't exist: return + return 0; + } + + // get the tag count + return (unsigned)tagmap->size(); +} + +// ---------------------------------------------------------- + + diff --git a/Source/FreeImage/Conversion24.cpp b/Source/FreeImage/Conversion24.cpp index 1d5bba7..3b7a800 100644 --- a/Source/FreeImage/Conversion24.cpp +++ b/Source/FreeImage/Conversion24.cpp @@ -1,252 +1,252 @@ -// ========================================================== -// Bitmap conversion routines -// -// Design and implementation by -// - Floris van den Berg (flvdberg@wxs.nl) -// - Dale Larson (dlarson@norsesoft.com) -// - Hervé Drolon (drolon@infonie.fr) -// - Jani Kajala (janik@remedy.fi) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" - -// ---------------------------------------------------------- -// internal conversions X to 24 bits -// ---------------------------------------------------------- - -void DLL_CALLCONV -FreeImage_ConvertLine1To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette) { - for (int cols = 0; cols < width_in_pixels; cols++) { - BYTE index = (source[cols >> 3] & (0x80 >> (cols & 0x07))) != 0 ? 1 : 0; - - target[FI_RGBA_BLUE] = palette[index].rgbBlue; - target[FI_RGBA_GREEN] = palette[index].rgbGreen; - target[FI_RGBA_RED] = palette[index].rgbRed; - - target += 3; - } -} - -void DLL_CALLCONV -FreeImage_ConvertLine4To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette) { - BOOL low_nibble = FALSE; - int x = 0; - - for (int cols = 0; cols < width_in_pixels; ++cols ) { - if (low_nibble) { - target[FI_RGBA_BLUE] = palette[LOWNIBBLE(source[x])].rgbBlue; - target[FI_RGBA_GREEN] = palette[LOWNIBBLE(source[x])].rgbGreen; - target[FI_RGBA_RED] = palette[LOWNIBBLE(source[x])].rgbRed; - - x++; - } else { - target[FI_RGBA_BLUE] = palette[HINIBBLE(source[x]) >> 4].rgbBlue; - target[FI_RGBA_GREEN] = palette[HINIBBLE(source[x]) >> 4].rgbGreen; - target[FI_RGBA_RED] = palette[HINIBBLE(source[x]) >> 4].rgbRed; - } - - low_nibble = !low_nibble; - - target += 3; - } -} - -void DLL_CALLCONV -FreeImage_ConvertLine8To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette) { - for (int cols = 0; cols < width_in_pixels; cols++) { - target[FI_RGBA_BLUE] = palette[source[cols]].rgbBlue; - target[FI_RGBA_GREEN] = palette[source[cols]].rgbGreen; - target[FI_RGBA_RED] = palette[source[cols]].rgbRed; - - target += 3; - } -} - -void DLL_CALLCONV -FreeImage_ConvertLine16To24_555(BYTE *target, BYTE *source, int width_in_pixels) { - WORD *bits = (WORD *)source; - - for (int cols = 0; cols < width_in_pixels; cols++) { - target[FI_RGBA_RED] = (BYTE)((((bits[cols] & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT) * 0xFF) / 0x1F); - target[FI_RGBA_GREEN] = (BYTE)((((bits[cols] & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT) * 0xFF) / 0x1F); - target[FI_RGBA_BLUE] = (BYTE)((((bits[cols] & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT) * 0xFF) / 0x1F); - - target += 3; - } -} - -void DLL_CALLCONV -FreeImage_ConvertLine16To24_565(BYTE *target, BYTE *source, int width_in_pixels) { - WORD *bits = (WORD *)source; - - for (int cols = 0; cols < width_in_pixels; cols++) { - target[FI_RGBA_RED] = (BYTE)((((bits[cols] & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT) * 0xFF) / 0x1F); - target[FI_RGBA_GREEN] = (BYTE)((((bits[cols] & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT) * 0xFF) / 0x3F); - target[FI_RGBA_BLUE] = (BYTE)((((bits[cols] & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT) * 0xFF) / 0x1F); - - target += 3; - } -} - -void DLL_CALLCONV -FreeImage_ConvertLine32To24(BYTE *target, BYTE *source, int width_in_pixels) { - for (int cols = 0; cols < width_in_pixels; cols++) { - target[FI_RGBA_BLUE] = source[FI_RGBA_BLUE]; - target[FI_RGBA_GREEN] = source[FI_RGBA_GREEN]; - target[FI_RGBA_RED] = source[FI_RGBA_RED]; - - target += 3; - source += 4; - } -} - -// ---------------------------------------------------------- -// smart convert X to 24 bits -// ---------------------------------------------------------- - -FIBITMAP * DLL_CALLCONV -FreeImage_ConvertTo24Bits(FIBITMAP *dib) { - if(!FreeImage_HasPixels(dib)) return NULL; - - const unsigned bpp = FreeImage_GetBPP(dib); - const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); - - if((image_type != FIT_BITMAP) && (image_type != FIT_RGB16) && (image_type != FIT_RGBA16)) { - return NULL; - } - - const int width = FreeImage_GetWidth(dib); - const int height = FreeImage_GetHeight(dib); - - if(image_type == FIT_BITMAP) { - if(bpp == 24) { - return FreeImage_Clone(dib); - } - - FIBITMAP *new_dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - if(new_dib == NULL) { - return NULL; - } - - // copy metadata from src to dst - FreeImage_CloneMetadata(new_dib, dib); - - switch(bpp) { - case 1 : - { - for (int rows = 0; rows < height; rows++) { - FreeImage_ConvertLine1To24(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib)); - } - return new_dib; - } - - case 4 : - { - for (int rows = 0; rows < height; rows++) { - FreeImage_ConvertLine4To24(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib)); - } - return new_dib; - } - - case 8 : - { - for (int rows = 0; rows < height; rows++) { - FreeImage_ConvertLine8To24(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib)); - } - return new_dib; - } - - case 16 : - { - for (int rows = 0; rows < height; rows++) { - if ((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) { - FreeImage_ConvertLine16To24_565(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); - } else { - // includes case where all the masks are 0 - FreeImage_ConvertLine16To24_555(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); - } - } - return new_dib; - } - - case 32 : - { - for (int rows = 0; rows < height; rows++) { - FreeImage_ConvertLine32To24(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); - } - return new_dib; - } - } - - } else if(image_type == FIT_RGB16) { - FIBITMAP *new_dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - if(new_dib == NULL) { - return NULL; - } - - // copy metadata from src to dst - FreeImage_CloneMetadata(new_dib, dib); - - const unsigned src_pitch = FreeImage_GetPitch(dib); - const unsigned dst_pitch = FreeImage_GetPitch(new_dib); - const BYTE *src_bits = FreeImage_GetBits(dib); - BYTE *dst_bits = FreeImage_GetBits(new_dib); - for (int rows = 0; rows < height; rows++) { - const FIRGB16 *src_pixel = (FIRGB16*)src_bits; - RGBTRIPLE *dst_pixel = (RGBTRIPLE*)dst_bits; - for(int cols = 0; cols < width; cols++) { - dst_pixel[cols].rgbtRed = (BYTE)(src_pixel[cols].red >> 8); - dst_pixel[cols].rgbtGreen = (BYTE)(src_pixel[cols].green >> 8); - dst_pixel[cols].rgbtBlue = (BYTE)(src_pixel[cols].blue >> 8); - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - - return new_dib; - - } else if(image_type == FIT_RGBA16) { - FIBITMAP *new_dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - if(new_dib == NULL) { - return NULL; - } - - // copy metadata from src to dst - FreeImage_CloneMetadata(new_dib, dib); - - const unsigned src_pitch = FreeImage_GetPitch(dib); - const unsigned dst_pitch = FreeImage_GetPitch(new_dib); - const BYTE *src_bits = FreeImage_GetBits(dib); - BYTE *dst_bits = FreeImage_GetBits(new_dib); - for (int rows = 0; rows < height; rows++) { - const FIRGBA16 *src_pixel = (FIRGBA16*)src_bits; - RGBTRIPLE *dst_pixel = (RGBTRIPLE*)dst_bits; - for(int cols = 0; cols < width; cols++) { - dst_pixel[cols].rgbtRed = (BYTE)(src_pixel[cols].red >> 8); - dst_pixel[cols].rgbtGreen = (BYTE)(src_pixel[cols].green >> 8); - dst_pixel[cols].rgbtBlue = (BYTE)(src_pixel[cols].blue >> 8); - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - - return new_dib; - } - - return NULL; -} +// ========================================================== +// Bitmap conversion routines +// +// Design and implementation by +// - Floris van den Berg (flvdberg@wxs.nl) +// - Dale Larson (dlarson@norsesoft.com) +// - Hervé Drolon (drolon@infonie.fr) +// - Jani Kajala (janik@remedy.fi) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" + +// ---------------------------------------------------------- +// internal conversions X to 24 bits +// ---------------------------------------------------------- + +void DLL_CALLCONV +FreeImage_ConvertLine1To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette) { + for (int cols = 0; cols < width_in_pixels; cols++) { + BYTE index = (source[cols >> 3] & (0x80 >> (cols & 0x07))) != 0 ? 1 : 0; + + target[FI_RGBA_BLUE] = palette[index].rgbBlue; + target[FI_RGBA_GREEN] = palette[index].rgbGreen; + target[FI_RGBA_RED] = palette[index].rgbRed; + + target += 3; + } +} + +void DLL_CALLCONV +FreeImage_ConvertLine4To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette) { + BOOL low_nibble = FALSE; + int x = 0; + + for (int cols = 0; cols < width_in_pixels; ++cols ) { + if (low_nibble) { + target[FI_RGBA_BLUE] = palette[LOWNIBBLE(source[x])].rgbBlue; + target[FI_RGBA_GREEN] = palette[LOWNIBBLE(source[x])].rgbGreen; + target[FI_RGBA_RED] = palette[LOWNIBBLE(source[x])].rgbRed; + + x++; + } else { + target[FI_RGBA_BLUE] = palette[HINIBBLE(source[x]) >> 4].rgbBlue; + target[FI_RGBA_GREEN] = palette[HINIBBLE(source[x]) >> 4].rgbGreen; + target[FI_RGBA_RED] = palette[HINIBBLE(source[x]) >> 4].rgbRed; + } + + low_nibble = !low_nibble; + + target += 3; + } +} + +void DLL_CALLCONV +FreeImage_ConvertLine8To24(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette) { + for (int cols = 0; cols < width_in_pixels; cols++) { + target[FI_RGBA_BLUE] = palette[source[cols]].rgbBlue; + target[FI_RGBA_GREEN] = palette[source[cols]].rgbGreen; + target[FI_RGBA_RED] = palette[source[cols]].rgbRed; + + target += 3; + } +} + +void DLL_CALLCONV +FreeImage_ConvertLine16To24_555(BYTE *target, BYTE *source, int width_in_pixels) { + WORD *bits = (WORD *)source; + + for (int cols = 0; cols < width_in_pixels; cols++) { + target[FI_RGBA_RED] = (BYTE)((((bits[cols] & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT) * 0xFF) / 0x1F); + target[FI_RGBA_GREEN] = (BYTE)((((bits[cols] & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT) * 0xFF) / 0x1F); + target[FI_RGBA_BLUE] = (BYTE)((((bits[cols] & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT) * 0xFF) / 0x1F); + + target += 3; + } +} + +void DLL_CALLCONV +FreeImage_ConvertLine16To24_565(BYTE *target, BYTE *source, int width_in_pixels) { + WORD *bits = (WORD *)source; + + for (int cols = 0; cols < width_in_pixels; cols++) { + target[FI_RGBA_RED] = (BYTE)((((bits[cols] & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT) * 0xFF) / 0x1F); + target[FI_RGBA_GREEN] = (BYTE)((((bits[cols] & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT) * 0xFF) / 0x3F); + target[FI_RGBA_BLUE] = (BYTE)((((bits[cols] & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT) * 0xFF) / 0x1F); + + target += 3; + } +} + +void DLL_CALLCONV +FreeImage_ConvertLine32To24(BYTE *target, BYTE *source, int width_in_pixels) { + for (int cols = 0; cols < width_in_pixels; cols++) { + target[FI_RGBA_BLUE] = source[FI_RGBA_BLUE]; + target[FI_RGBA_GREEN] = source[FI_RGBA_GREEN]; + target[FI_RGBA_RED] = source[FI_RGBA_RED]; + + target += 3; + source += 4; + } +} + +// ---------------------------------------------------------- +// smart convert X to 24 bits +// ---------------------------------------------------------- + +FIBITMAP * DLL_CALLCONV +FreeImage_ConvertTo24Bits(FIBITMAP *dib) { + if(!FreeImage_HasPixels(dib)) return NULL; + + const unsigned bpp = FreeImage_GetBPP(dib); + const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); + + if((image_type != FIT_BITMAP) && (image_type != FIT_RGB16) && (image_type != FIT_RGBA16)) { + return NULL; + } + + const int width = FreeImage_GetWidth(dib); + const int height = FreeImage_GetHeight(dib); + + if(image_type == FIT_BITMAP) { + if(bpp == 24) { + return FreeImage_Clone(dib); + } + + FIBITMAP *new_dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + if(new_dib == NULL) { + return NULL; + } + + // copy metadata from src to dst + FreeImage_CloneMetadata(new_dib, dib); + + switch(bpp) { + case 1 : + { + for (int rows = 0; rows < height; rows++) { + FreeImage_ConvertLine1To24(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib)); + } + return new_dib; + } + + case 4 : + { + for (int rows = 0; rows < height; rows++) { + FreeImage_ConvertLine4To24(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib)); + } + return new_dib; + } + + case 8 : + { + for (int rows = 0; rows < height; rows++) { + FreeImage_ConvertLine8To24(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib)); + } + return new_dib; + } + + case 16 : + { + for (int rows = 0; rows < height; rows++) { + if ((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) { + FreeImage_ConvertLine16To24_565(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); + } else { + // includes case where all the masks are 0 + FreeImage_ConvertLine16To24_555(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); + } + } + return new_dib; + } + + case 32 : + { + for (int rows = 0; rows < height; rows++) { + FreeImage_ConvertLine32To24(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); + } + return new_dib; + } + } + + } else if(image_type == FIT_RGB16) { + FIBITMAP *new_dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + if(new_dib == NULL) { + return NULL; + } + + // copy metadata from src to dst + FreeImage_CloneMetadata(new_dib, dib); + + const unsigned src_pitch = FreeImage_GetPitch(dib); + const unsigned dst_pitch = FreeImage_GetPitch(new_dib); + const BYTE *src_bits = FreeImage_GetBits(dib); + BYTE *dst_bits = FreeImage_GetBits(new_dib); + for (int rows = 0; rows < height; rows++) { + const FIRGB16 *src_pixel = (FIRGB16*)src_bits; + RGBTRIPLE *dst_pixel = (RGBTRIPLE*)dst_bits; + for(int cols = 0; cols < width; cols++) { + dst_pixel[cols].rgbtRed = (BYTE)(src_pixel[cols].red >> 8); + dst_pixel[cols].rgbtGreen = (BYTE)(src_pixel[cols].green >> 8); + dst_pixel[cols].rgbtBlue = (BYTE)(src_pixel[cols].blue >> 8); + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + + return new_dib; + + } else if(image_type == FIT_RGBA16) { + FIBITMAP *new_dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + if(new_dib == NULL) { + return NULL; + } + + // copy metadata from src to dst + FreeImage_CloneMetadata(new_dib, dib); + + const unsigned src_pitch = FreeImage_GetPitch(dib); + const unsigned dst_pitch = FreeImage_GetPitch(new_dib); + const BYTE *src_bits = FreeImage_GetBits(dib); + BYTE *dst_bits = FreeImage_GetBits(new_dib); + for (int rows = 0; rows < height; rows++) { + const FIRGBA16 *src_pixel = (FIRGBA16*)src_bits; + RGBTRIPLE *dst_pixel = (RGBTRIPLE*)dst_bits; + for(int cols = 0; cols < width; cols++) { + dst_pixel[cols].rgbtRed = (BYTE)(src_pixel[cols].red >> 8); + dst_pixel[cols].rgbtGreen = (BYTE)(src_pixel[cols].green >> 8); + dst_pixel[cols].rgbtBlue = (BYTE)(src_pixel[cols].blue >> 8); + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + + return new_dib; + } + + return NULL; +} diff --git a/Source/FreeImage/Conversion32.cpp b/Source/FreeImage/Conversion32.cpp index b8bd518..4874dcf 100644 --- a/Source/FreeImage/Conversion32.cpp +++ b/Source/FreeImage/Conversion32.cpp @@ -1,345 +1,345 @@ -// ========================================================== -// Bitmap conversion routines -// -// Design and implementation by -// - Floris van den Berg (flvdberg@wxs.nl) -// - Hervé Drolon (drolon@infonie.fr) -// - Jani Kajala (janik@remedy.fi) -// - Detlev Vendt (detlev.vendt@brillit.de) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" - -// ---------------------------------------------------------- -// internal conversions X to 32 bits -// ---------------------------------------------------------- - -void DLL_CALLCONV -FreeImage_ConvertLine1To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette) { - for (int cols = 0; cols < width_in_pixels; cols++) { - int index = (source[cols>>3] & (0x80 >> (cols & 0x07))) != 0 ? 1 : 0; - - target[FI_RGBA_BLUE] = palette[index].rgbBlue; - target[FI_RGBA_GREEN] = palette[index].rgbGreen; - target[FI_RGBA_RED] = palette[index].rgbRed; - target[FI_RGBA_ALPHA] = 0xFF; - target += 4; - } -} - -void DLL_CALLCONV -FreeImage_ConvertLine4To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette) { - BOOL low_nibble = FALSE; - int x = 0; - - for (int cols = 0 ; cols < width_in_pixels ; ++cols) { - if (low_nibble) { - target[FI_RGBA_BLUE] = palette[LOWNIBBLE(source[x])].rgbBlue; - target[FI_RGBA_GREEN] = palette[LOWNIBBLE(source[x])].rgbGreen; - target[FI_RGBA_RED] = palette[LOWNIBBLE(source[x])].rgbRed; - - x++; - } else { - target[FI_RGBA_BLUE] = palette[HINIBBLE(source[x]) >> 4].rgbBlue; - target[FI_RGBA_GREEN] = palette[HINIBBLE(source[x]) >> 4].rgbGreen; - target[FI_RGBA_RED] = palette[HINIBBLE(source[x]) >> 4].rgbRed; - } - - low_nibble = !low_nibble; - - target[FI_RGBA_ALPHA] = 0xFF; - target += 4; - } -} - -void DLL_CALLCONV -FreeImage_ConvertLine8To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette) { - for (int cols = 0; cols < width_in_pixels; cols++) { - target[FI_RGBA_BLUE] = palette[source[cols]].rgbBlue; - target[FI_RGBA_GREEN] = palette[source[cols]].rgbGreen; - target[FI_RGBA_RED] = palette[source[cols]].rgbRed; - target[FI_RGBA_ALPHA] = 0xFF; - target += 4; - } -} - -void DLL_CALLCONV -FreeImage_ConvertLine16To32_555(BYTE *target, BYTE *source, int width_in_pixels) { - WORD *bits = (WORD *)source; - - for (int cols = 0; cols < width_in_pixels; cols++) { - target[FI_RGBA_RED] = (BYTE)((((bits[cols] & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT) * 0xFF) / 0x1F); - target[FI_RGBA_GREEN] = (BYTE)((((bits[cols] & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT) * 0xFF) / 0x1F); - target[FI_RGBA_BLUE] = (BYTE)((((bits[cols] & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT) * 0xFF) / 0x1F); - target[FI_RGBA_ALPHA] = 0xFF; - target += 4; - } -} - -void DLL_CALLCONV -FreeImage_ConvertLine16To32_565(BYTE *target, BYTE *source, int width_in_pixels) { - WORD *bits = (WORD *)source; - - for (int cols = 0; cols < width_in_pixels; cols++) { - target[FI_RGBA_RED] = (BYTE)((((bits[cols] & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT) * 0xFF) / 0x1F); - target[FI_RGBA_GREEN] = (BYTE)((((bits[cols] & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT) * 0xFF) / 0x3F); - target[FI_RGBA_BLUE] = (BYTE)((((bits[cols] & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT) * 0xFF) / 0x1F); - target[FI_RGBA_ALPHA] = 0xFF; - target += 4; - } -} -/* -void DLL_CALLCONV -FreeImage_ConvertLine24To32(BYTE *target, BYTE *source, int width_in_pixels) { - for (int cols = 0; cols < width_in_pixels; cols++) { - *(DWORD *)target = (*(DWORD *) source & FI_RGBA_RGB_MASK) | FI_RGBA_ALPHA_MASK; - target += 4; - source += 3; - } -} -*/ -/** -This unoptimized version of the conversion function avoid an undetermined bug with VC++ SP6. -The bug occurs in release mode only, when the image height is equal to 537 -(try e.g. a size of 432x537 to reproduce the bug with the optimized function). -*/ -void DLL_CALLCONV -FreeImage_ConvertLine24To32(BYTE *target, BYTE *source, int width_in_pixels) { - for (int cols = 0; cols < width_in_pixels; cols++) { - target[FI_RGBA_RED] = source[FI_RGBA_RED]; - target[FI_RGBA_GREEN] = source[FI_RGBA_GREEN]; - target[FI_RGBA_BLUE] = source[FI_RGBA_BLUE]; - target[FI_RGBA_ALPHA] = 0xFF; - target += 4; - source += 3; - } -} - -// ---------------------------------------------------------- - -inline void -FreeImage_ConvertLine1To32MapTransparency(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette, BYTE *table, int transparent_pixels) { - for (int cols = 0; cols < width_in_pixels; cols++) { - int index = (source[cols>>3] & (0x80 >> (cols & 0x07))) != 0 ? 1 : 0; - - target[FI_RGBA_BLUE] = palette[index].rgbBlue; - target[FI_RGBA_GREEN] = palette[index].rgbGreen; - target[FI_RGBA_RED] = palette[index].rgbRed; - target[FI_RGBA_ALPHA] = (index < transparent_pixels) ? table[index] : 255; - target += 4; - } -} - -inline void -FreeImage_ConvertLine4To32MapTransparency(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette, BYTE *table, int transparent_pixels) { - BOOL low_nibble = FALSE; - int x = 0; - - for (int cols = 0 ; cols < width_in_pixels ; ++cols) { - if (low_nibble) { - target[FI_RGBA_BLUE] = palette[LOWNIBBLE(source[x])].rgbBlue; - target[FI_RGBA_GREEN] = palette[LOWNIBBLE(source[x])].rgbGreen; - target[FI_RGBA_RED] = palette[LOWNIBBLE(source[x])].rgbRed; - target[FI_RGBA_ALPHA] = (LOWNIBBLE(source[x]) < transparent_pixels) ? table[LOWNIBBLE(source[x])] : 255; - - x++; - } else { - target[FI_RGBA_BLUE] = palette[HINIBBLE(source[x]) >> 4].rgbBlue; - target[FI_RGBA_GREEN] = palette[HINIBBLE(source[x]) >> 4].rgbGreen; - target[FI_RGBA_RED] = palette[HINIBBLE(source[x]) >> 4].rgbRed; - target[FI_RGBA_ALPHA] = (HINIBBLE(source[x] >> 4) < transparent_pixels) ? table[HINIBBLE(source[x]) >> 4] : 255; - } - - low_nibble = !low_nibble; - - target += 4; - } -} - -inline void -FreeImage_ConvertLine8To32MapTransparency(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette, BYTE *table, int transparent_pixels) { - for (int cols = 0; cols < width_in_pixels; cols++) { - target[FI_RGBA_BLUE] = palette[source[cols]].rgbBlue; - target[FI_RGBA_GREEN] = palette[source[cols]].rgbGreen; - target[FI_RGBA_RED] = palette[source[cols]].rgbRed; - target[FI_RGBA_ALPHA] = (source[cols] < transparent_pixels) ? table[source[cols]] : 255; - target += 4; - } -} - -// ---------------------------------------------------------- - -FIBITMAP * DLL_CALLCONV -FreeImage_ConvertTo32Bits(FIBITMAP *dib) { - if(!FreeImage_HasPixels(dib)) return NULL; - - const int bpp = FreeImage_GetBPP(dib); - const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); - - if((image_type != FIT_BITMAP) && (image_type != FIT_RGB16) && (image_type != FIT_RGBA16)) { - return NULL; - } - - const int width = FreeImage_GetWidth(dib); - const int height = FreeImage_GetHeight(dib); - - if(image_type == FIT_BITMAP) { - - if(bpp == 32) { - return FreeImage_Clone(dib); - } - - FIBITMAP *new_dib = FreeImage_Allocate(width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - if(new_dib == NULL) { - return NULL; - } - - // copy metadata from src to dst - FreeImage_CloneMetadata(new_dib, dib); - - BOOL bIsTransparent = FreeImage_IsTransparent(dib); - - switch(bpp) { - case 1: - { - if(bIsTransparent) { - for (int rows = 0; rows < height; rows++) { - FreeImage_ConvertLine1To32MapTransparency(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib), FreeImage_GetTransparencyTable(dib), FreeImage_GetTransparencyCount(dib)); - } - } else { - for (int rows = 0; rows < height; rows++) { - FreeImage_ConvertLine1To32(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib)); - } - } - - return new_dib; - } - - case 4: - { - if(bIsTransparent) { - for (int rows = 0; rows < height; rows++) { - FreeImage_ConvertLine4To32MapTransparency(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib), FreeImage_GetTransparencyTable(dib), FreeImage_GetTransparencyCount(dib)); - } - } else { - for (int rows = 0; rows < height; rows++) { - FreeImage_ConvertLine4To32(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib)); - } - } - - return new_dib; - } - - case 8: - { - if(bIsTransparent) { - for (int rows = 0; rows < height; rows++) { - FreeImage_ConvertLine8To32MapTransparency(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib), FreeImage_GetTransparencyTable(dib), FreeImage_GetTransparencyCount(dib)); - } - } else { - for (int rows = 0; rows < height; rows++) { - FreeImage_ConvertLine8To32(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib)); - } - } - - return new_dib; - } - - case 16: - { - for (int rows = 0; rows < height; rows++) { - if ((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) { - FreeImage_ConvertLine16To32_565(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); - } else { - // includes case where all the masks are 0 - FreeImage_ConvertLine16To32_555(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); - } - } - - return new_dib; - } - - case 24: - { - for (int rows = 0; rows < height; rows++) { - FreeImage_ConvertLine24To32(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); - } - - return new_dib; - } - } - - } else if(image_type == FIT_RGB16) { - FIBITMAP *new_dib = FreeImage_Allocate(width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - if(new_dib == NULL) { - return NULL; - } - - // copy metadata from src to dst - FreeImage_CloneMetadata(new_dib, dib); - - const unsigned src_pitch = FreeImage_GetPitch(dib); - const unsigned dst_pitch = FreeImage_GetPitch(new_dib); - const BYTE *src_bits = FreeImage_GetBits(dib); - BYTE *dst_bits = FreeImage_GetBits(new_dib); - for (int rows = 0; rows < height; rows++) { - const FIRGB16 *src_pixel = (FIRGB16*)src_bits; - RGBQUAD *dst_pixel = (RGBQUAD*)dst_bits; - for(int cols = 0; cols < width; cols++) { - dst_pixel[cols].rgbRed = (BYTE)(src_pixel[cols].red >> 8); - dst_pixel[cols].rgbGreen = (BYTE)(src_pixel[cols].green >> 8); - dst_pixel[cols].rgbBlue = (BYTE)(src_pixel[cols].blue >> 8); - dst_pixel[cols].rgbReserved = (BYTE)0xFF; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - - return new_dib; - - } else if(image_type == FIT_RGBA16) { - FIBITMAP *new_dib = FreeImage_Allocate(width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - if(new_dib == NULL) { - return NULL; - } - - // copy metadata from src to dst - FreeImage_CloneMetadata(new_dib, dib); - - const unsigned src_pitch = FreeImage_GetPitch(dib); - const unsigned dst_pitch = FreeImage_GetPitch(new_dib); - const BYTE *src_bits = FreeImage_GetBits(dib); - BYTE *dst_bits = FreeImage_GetBits(new_dib); - for (int rows = 0; rows < height; rows++) { - const FIRGBA16 *src_pixel = (FIRGBA16*)src_bits; - RGBQUAD *dst_pixel = (RGBQUAD*)dst_bits; - for(int cols = 0; cols < width; cols++) { - dst_pixel[cols].rgbRed = (BYTE)(src_pixel[cols].red >> 8); - dst_pixel[cols].rgbGreen = (BYTE)(src_pixel[cols].green >> 8); - dst_pixel[cols].rgbBlue = (BYTE)(src_pixel[cols].blue >> 8); - dst_pixel[cols].rgbReserved = (BYTE)(src_pixel[cols].alpha >> 8); - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - - return new_dib; - } - - return NULL; -} +// ========================================================== +// Bitmap conversion routines +// +// Design and implementation by +// - Floris van den Berg (flvdberg@wxs.nl) +// - Hervé Drolon (drolon@infonie.fr) +// - Jani Kajala (janik@remedy.fi) +// - Detlev Vendt (detlev.vendt@brillit.de) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" + +// ---------------------------------------------------------- +// internal conversions X to 32 bits +// ---------------------------------------------------------- + +void DLL_CALLCONV +FreeImage_ConvertLine1To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette) { + for (int cols = 0; cols < width_in_pixels; cols++) { + int index = (source[cols>>3] & (0x80 >> (cols & 0x07))) != 0 ? 1 : 0; + + target[FI_RGBA_BLUE] = palette[index].rgbBlue; + target[FI_RGBA_GREEN] = palette[index].rgbGreen; + target[FI_RGBA_RED] = palette[index].rgbRed; + target[FI_RGBA_ALPHA] = 0xFF; + target += 4; + } +} + +void DLL_CALLCONV +FreeImage_ConvertLine4To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette) { + BOOL low_nibble = FALSE; + int x = 0; + + for (int cols = 0 ; cols < width_in_pixels ; ++cols) { + if (low_nibble) { + target[FI_RGBA_BLUE] = palette[LOWNIBBLE(source[x])].rgbBlue; + target[FI_RGBA_GREEN] = palette[LOWNIBBLE(source[x])].rgbGreen; + target[FI_RGBA_RED] = palette[LOWNIBBLE(source[x])].rgbRed; + + x++; + } else { + target[FI_RGBA_BLUE] = palette[HINIBBLE(source[x]) >> 4].rgbBlue; + target[FI_RGBA_GREEN] = palette[HINIBBLE(source[x]) >> 4].rgbGreen; + target[FI_RGBA_RED] = palette[HINIBBLE(source[x]) >> 4].rgbRed; + } + + low_nibble = !low_nibble; + + target[FI_RGBA_ALPHA] = 0xFF; + target += 4; + } +} + +void DLL_CALLCONV +FreeImage_ConvertLine8To32(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette) { + for (int cols = 0; cols < width_in_pixels; cols++) { + target[FI_RGBA_BLUE] = palette[source[cols]].rgbBlue; + target[FI_RGBA_GREEN] = palette[source[cols]].rgbGreen; + target[FI_RGBA_RED] = palette[source[cols]].rgbRed; + target[FI_RGBA_ALPHA] = 0xFF; + target += 4; + } +} + +void DLL_CALLCONV +FreeImage_ConvertLine16To32_555(BYTE *target, BYTE *source, int width_in_pixels) { + WORD *bits = (WORD *)source; + + for (int cols = 0; cols < width_in_pixels; cols++) { + target[FI_RGBA_RED] = (BYTE)((((bits[cols] & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT) * 0xFF) / 0x1F); + target[FI_RGBA_GREEN] = (BYTE)((((bits[cols] & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT) * 0xFF) / 0x1F); + target[FI_RGBA_BLUE] = (BYTE)((((bits[cols] & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT) * 0xFF) / 0x1F); + target[FI_RGBA_ALPHA] = 0xFF; + target += 4; + } +} + +void DLL_CALLCONV +FreeImage_ConvertLine16To32_565(BYTE *target, BYTE *source, int width_in_pixels) { + WORD *bits = (WORD *)source; + + for (int cols = 0; cols < width_in_pixels; cols++) { + target[FI_RGBA_RED] = (BYTE)((((bits[cols] & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT) * 0xFF) / 0x1F); + target[FI_RGBA_GREEN] = (BYTE)((((bits[cols] & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT) * 0xFF) / 0x3F); + target[FI_RGBA_BLUE] = (BYTE)((((bits[cols] & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT) * 0xFF) / 0x1F); + target[FI_RGBA_ALPHA] = 0xFF; + target += 4; + } +} +/* +void DLL_CALLCONV +FreeImage_ConvertLine24To32(BYTE *target, BYTE *source, int width_in_pixels) { + for (int cols = 0; cols < width_in_pixels; cols++) { + *(DWORD *)target = (*(DWORD *) source & FI_RGBA_RGB_MASK) | FI_RGBA_ALPHA_MASK; + target += 4; + source += 3; + } +} +*/ +/** +This unoptimized version of the conversion function avoid an undetermined bug with VC++ SP6. +The bug occurs in release mode only, when the image height is equal to 537 +(try e.g. a size of 432x537 to reproduce the bug with the optimized function). +*/ +void DLL_CALLCONV +FreeImage_ConvertLine24To32(BYTE *target, BYTE *source, int width_in_pixels) { + for (int cols = 0; cols < width_in_pixels; cols++) { + target[FI_RGBA_RED] = source[FI_RGBA_RED]; + target[FI_RGBA_GREEN] = source[FI_RGBA_GREEN]; + target[FI_RGBA_BLUE] = source[FI_RGBA_BLUE]; + target[FI_RGBA_ALPHA] = 0xFF; + target += 4; + source += 3; + } +} + +// ---------------------------------------------------------- + +inline void +FreeImage_ConvertLine1To32MapTransparency(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette, BYTE *table, int transparent_pixels) { + for (int cols = 0; cols < width_in_pixels; cols++) { + int index = (source[cols>>3] & (0x80 >> (cols & 0x07))) != 0 ? 1 : 0; + + target[FI_RGBA_BLUE] = palette[index].rgbBlue; + target[FI_RGBA_GREEN] = palette[index].rgbGreen; + target[FI_RGBA_RED] = palette[index].rgbRed; + target[FI_RGBA_ALPHA] = (index < transparent_pixels) ? table[index] : 255; + target += 4; + } +} + +inline void +FreeImage_ConvertLine4To32MapTransparency(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette, BYTE *table, int transparent_pixels) { + BOOL low_nibble = FALSE; + int x = 0; + + for (int cols = 0 ; cols < width_in_pixels ; ++cols) { + if (low_nibble) { + target[FI_RGBA_BLUE] = palette[LOWNIBBLE(source[x])].rgbBlue; + target[FI_RGBA_GREEN] = palette[LOWNIBBLE(source[x])].rgbGreen; + target[FI_RGBA_RED] = palette[LOWNIBBLE(source[x])].rgbRed; + target[FI_RGBA_ALPHA] = (LOWNIBBLE(source[x]) < transparent_pixels) ? table[LOWNIBBLE(source[x])] : 255; + + x++; + } else { + target[FI_RGBA_BLUE] = palette[HINIBBLE(source[x]) >> 4].rgbBlue; + target[FI_RGBA_GREEN] = palette[HINIBBLE(source[x]) >> 4].rgbGreen; + target[FI_RGBA_RED] = palette[HINIBBLE(source[x]) >> 4].rgbRed; + target[FI_RGBA_ALPHA] = (HINIBBLE(source[x] >> 4) < transparent_pixels) ? table[HINIBBLE(source[x]) >> 4] : 255; + } + + low_nibble = !low_nibble; + + target += 4; + } +} + +inline void +FreeImage_ConvertLine8To32MapTransparency(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette, BYTE *table, int transparent_pixels) { + for (int cols = 0; cols < width_in_pixels; cols++) { + target[FI_RGBA_BLUE] = palette[source[cols]].rgbBlue; + target[FI_RGBA_GREEN] = palette[source[cols]].rgbGreen; + target[FI_RGBA_RED] = palette[source[cols]].rgbRed; + target[FI_RGBA_ALPHA] = (source[cols] < transparent_pixels) ? table[source[cols]] : 255; + target += 4; + } +} + +// ---------------------------------------------------------- + +FIBITMAP * DLL_CALLCONV +FreeImage_ConvertTo32Bits(FIBITMAP *dib) { + if(!FreeImage_HasPixels(dib)) return NULL; + + const int bpp = FreeImage_GetBPP(dib); + const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); + + if((image_type != FIT_BITMAP) && (image_type != FIT_RGB16) && (image_type != FIT_RGBA16)) { + return NULL; + } + + const int width = FreeImage_GetWidth(dib); + const int height = FreeImage_GetHeight(dib); + + if(image_type == FIT_BITMAP) { + + if(bpp == 32) { + return FreeImage_Clone(dib); + } + + FIBITMAP *new_dib = FreeImage_Allocate(width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + if(new_dib == NULL) { + return NULL; + } + + // copy metadata from src to dst + FreeImage_CloneMetadata(new_dib, dib); + + BOOL bIsTransparent = FreeImage_IsTransparent(dib); + + switch(bpp) { + case 1: + { + if(bIsTransparent) { + for (int rows = 0; rows < height; rows++) { + FreeImage_ConvertLine1To32MapTransparency(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib), FreeImage_GetTransparencyTable(dib), FreeImage_GetTransparencyCount(dib)); + } + } else { + for (int rows = 0; rows < height; rows++) { + FreeImage_ConvertLine1To32(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib)); + } + } + + return new_dib; + } + + case 4: + { + if(bIsTransparent) { + for (int rows = 0; rows < height; rows++) { + FreeImage_ConvertLine4To32MapTransparency(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib), FreeImage_GetTransparencyTable(dib), FreeImage_GetTransparencyCount(dib)); + } + } else { + for (int rows = 0; rows < height; rows++) { + FreeImage_ConvertLine4To32(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib)); + } + } + + return new_dib; + } + + case 8: + { + if(bIsTransparent) { + for (int rows = 0; rows < height; rows++) { + FreeImage_ConvertLine8To32MapTransparency(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib), FreeImage_GetTransparencyTable(dib), FreeImage_GetTransparencyCount(dib)); + } + } else { + for (int rows = 0; rows < height; rows++) { + FreeImage_ConvertLine8To32(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib)); + } + } + + return new_dib; + } + + case 16: + { + for (int rows = 0; rows < height; rows++) { + if ((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) { + FreeImage_ConvertLine16To32_565(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); + } else { + // includes case where all the masks are 0 + FreeImage_ConvertLine16To32_555(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); + } + } + + return new_dib; + } + + case 24: + { + for (int rows = 0; rows < height; rows++) { + FreeImage_ConvertLine24To32(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); + } + + return new_dib; + } + } + + } else if(image_type == FIT_RGB16) { + FIBITMAP *new_dib = FreeImage_Allocate(width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + if(new_dib == NULL) { + return NULL; + } + + // copy metadata from src to dst + FreeImage_CloneMetadata(new_dib, dib); + + const unsigned src_pitch = FreeImage_GetPitch(dib); + const unsigned dst_pitch = FreeImage_GetPitch(new_dib); + const BYTE *src_bits = FreeImage_GetBits(dib); + BYTE *dst_bits = FreeImage_GetBits(new_dib); + for (int rows = 0; rows < height; rows++) { + const FIRGB16 *src_pixel = (FIRGB16*)src_bits; + RGBQUAD *dst_pixel = (RGBQUAD*)dst_bits; + for(int cols = 0; cols < width; cols++) { + dst_pixel[cols].rgbRed = (BYTE)(src_pixel[cols].red >> 8); + dst_pixel[cols].rgbGreen = (BYTE)(src_pixel[cols].green >> 8); + dst_pixel[cols].rgbBlue = (BYTE)(src_pixel[cols].blue >> 8); + dst_pixel[cols].rgbReserved = (BYTE)0xFF; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + + return new_dib; + + } else if(image_type == FIT_RGBA16) { + FIBITMAP *new_dib = FreeImage_Allocate(width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + if(new_dib == NULL) { + return NULL; + } + + // copy metadata from src to dst + FreeImage_CloneMetadata(new_dib, dib); + + const unsigned src_pitch = FreeImage_GetPitch(dib); + const unsigned dst_pitch = FreeImage_GetPitch(new_dib); + const BYTE *src_bits = FreeImage_GetBits(dib); + BYTE *dst_bits = FreeImage_GetBits(new_dib); + for (int rows = 0; rows < height; rows++) { + const FIRGBA16 *src_pixel = (FIRGBA16*)src_bits; + RGBQUAD *dst_pixel = (RGBQUAD*)dst_bits; + for(int cols = 0; cols < width; cols++) { + dst_pixel[cols].rgbRed = (BYTE)(src_pixel[cols].red >> 8); + dst_pixel[cols].rgbGreen = (BYTE)(src_pixel[cols].green >> 8); + dst_pixel[cols].rgbBlue = (BYTE)(src_pixel[cols].blue >> 8); + dst_pixel[cols].rgbReserved = (BYTE)(src_pixel[cols].alpha >> 8); + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + + return new_dib; + } + + return NULL; +} diff --git a/Source/FreeImage/Conversion8.cpp b/Source/FreeImage/Conversion8.cpp index 1c331a6..c4f9b22 100644 --- a/Source/FreeImage/Conversion8.cpp +++ b/Source/FreeImage/Conversion8.cpp @@ -1,305 +1,305 @@ -// ========================================================== -// Bitmap conversion routines -// -// Design and implementation by -// - Floris van den Berg (flvdberg@wxs.nl) -// - Hervé Drolon (drolon@infonie.fr) -// - Jani Kajala (janik@remedy.fi) -// - Karl-Heinz Bussian (khbussian@moss.de) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" - -// ---------------------------------------------------------- -// internal conversions X to 8 bits -// ---------------------------------------------------------- - -void DLL_CALLCONV -FreeImage_ConvertLine1To8(BYTE *target, BYTE *source, int width_in_pixels) { - for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) - target[cols] = (source[cols >> 3] & (0x80 >> (cols & 0x07))) != 0 ? 255 : 0; -} - -void DLL_CALLCONV -FreeImage_ConvertLine4To8(BYTE *target, BYTE *source, int width_in_pixels) { - unsigned count_new = 0; - unsigned count_org = 0; - BOOL hinibble = TRUE; - - while (count_new < (unsigned)width_in_pixels) { - if (hinibble) { - target[count_new] = (source[count_org] >> 4); - } else { - target[count_new] = (source[count_org] & 0x0F); - count_org++; - } - hinibble = !hinibble; - count_new++; - } -} - -void DLL_CALLCONV -FreeImage_ConvertLine16To8_555(BYTE *target, BYTE *source, int width_in_pixels) { - const WORD *const bits = (WORD *)source; - for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) { - target[cols] = GREY((((bits[cols] & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT) * 0xFF) / 0x1F, - (((bits[cols] & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT) * 0xFF) / 0x1F, - (((bits[cols] & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT) * 0xFF) / 0x1F); - } -} - -void DLL_CALLCONV -FreeImage_ConvertLine16To8_565(BYTE *target, BYTE *source, int width_in_pixels) { - const WORD *const bits = (WORD *)source; - for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) { - target[cols] = GREY((((bits[cols] & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT) * 0xFF) / 0x1F, - (((bits[cols] & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT) * 0xFF) / 0x3F, - (((bits[cols] & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT) * 0xFF) / 0x1F); - } -} - -void DLL_CALLCONV -FreeImage_ConvertLine24To8(BYTE *target, BYTE *source, int width_in_pixels) { - for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) { - target[cols] = GREY(source[FI_RGBA_RED], source[FI_RGBA_GREEN], source[FI_RGBA_BLUE]); - source += 3; - } -} - -void DLL_CALLCONV -FreeImage_ConvertLine32To8(BYTE *target, BYTE *source, int width_in_pixels) { - for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) { - target[cols] = GREY(source[FI_RGBA_RED], source[FI_RGBA_GREEN], source[FI_RGBA_BLUE]); - source += 4; - } -} - -// ---------------------------------------------------------- -// smart convert X to 8 bits -// ---------------------------------------------------------- - -FIBITMAP * DLL_CALLCONV -FreeImage_ConvertTo8Bits(FIBITMAP *dib) { - if (!FreeImage_HasPixels(dib)) { - return NULL; - } - - const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); - if (image_type != FIT_BITMAP && image_type != FIT_UINT16) { - return NULL; - } - - const unsigned bpp = FreeImage_GetBPP(dib); - - if (bpp != 8) { - - const unsigned width = FreeImage_GetWidth(dib); - const unsigned height = FreeImage_GetHeight(dib); - - // Allocate a destination image - FIBITMAP *new_dib = FreeImage_Allocate(width, height, 8); - if (new_dib == NULL) { - return NULL; - } - - // Copy metadata from src to dst - FreeImage_CloneMetadata(new_dib, dib); - - // Palette of destination image has already been initialized - RGBQUAD *new_pal = FreeImage_GetPalette(new_dib); - - const FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib); - - if (image_type == FIT_BITMAP) { - - switch(bpp) { - case 1: - { - if (color_type == FIC_PALETTE) { - // Copy the palette - RGBQUAD *old_pal = FreeImage_GetPalette(dib); - new_pal[0] = old_pal[0]; - new_pal[255] = old_pal[1]; - - } else if (color_type == FIC_MINISWHITE) { - // Create a reverse grayscale palette - CREATE_GREYSCALE_PALETTE_REVERSE(new_pal, 256); - } - - // Expand and copy the bitmap data - for (unsigned rows = 0; rows < height; rows++) { - FreeImage_ConvertLine1To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); - } - return new_dib; - } - - case 4 : - { - if (color_type == FIC_PALETTE) { - // Copy the palette - memcpy(new_pal, FreeImage_GetPalette(dib), 16 * sizeof(RGBQUAD)); - } - - // Expand and copy the bitmap data - for (unsigned rows = 0; rows < height; rows++) { - FreeImage_ConvertLine4To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); - } - return new_dib; - } - - case 16 : - { - // Expand and copy the bitmap data - if (IS_FORMAT_RGB565(dib)) { - for (unsigned rows = 0; rows < height; rows++) { - FreeImage_ConvertLine16To8_565(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); - } - } else { - for (unsigned rows = 0; rows < height; rows++) { - FreeImage_ConvertLine16To8_555(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); - } - } - return new_dib; - } - - case 24 : - { - // Expand and copy the bitmap data - for (unsigned rows = 0; rows < height; rows++) { - FreeImage_ConvertLine24To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); - } - return new_dib; - } - - case 32 : - { - // Expand and copy the bitmap data - for (unsigned rows = 0; rows < height; rows++) { - FreeImage_ConvertLine32To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); - } - return new_dib; - } - } - - } else if (image_type == FIT_UINT16) { - - const unsigned src_pitch = FreeImage_GetPitch(dib); - const unsigned dst_pitch = FreeImage_GetPitch(new_dib); - const BYTE *src_bits = FreeImage_GetBits(dib); - BYTE *dst_bits = FreeImage_GetBits(new_dib); - - for (unsigned rows = 0; rows < height; rows++) { - const WORD *const src_pixel = (WORD*)src_bits; - BYTE *dst_pixel = (BYTE*)dst_bits; - for(unsigned cols = 0; cols < width; cols++) { - dst_pixel[cols] = (BYTE)(src_pixel[cols] >> 8); - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - return new_dib; - } - - } // bpp != 8 - - return FreeImage_Clone(dib); -} - -FIBITMAP * DLL_CALLCONV -FreeImage_ConvertToGreyscale(FIBITMAP *dib) { - if (!FreeImage_HasPixels(dib)) { - return NULL; - } - - const FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib); - - if (color_type == FIC_PALETTE || color_type == FIC_MINISWHITE) { - - const unsigned bpp = FreeImage_GetBPP(dib); - const unsigned width = FreeImage_GetWidth(dib); - const unsigned height = FreeImage_GetHeight(dib); - - FIBITMAP *new_dib = FreeImage_Allocate(width, height, 8); - if (new_dib == NULL) { - return NULL; - } - - // Copy metadata from src to dst - FreeImage_CloneMetadata(new_dib, dib); - - // Create a greyscale palette - BYTE grey_pal[256]; - const RGBQUAD *pal = FreeImage_GetPalette(dib); - const unsigned size = CalculateUsedPaletteEntries(bpp); - for (unsigned i = 0; i < size; i++) { - grey_pal[i] = GREY(pal->rgbRed, pal->rgbGreen, pal->rgbBlue); - pal++; - } - - const BYTE *src_bits = FreeImage_GetBits(dib); - BYTE *dst_bits = FreeImage_GetBits(new_dib); - - const unsigned src_pitch = FreeImage_GetPitch(dib); - const unsigned dst_pitch = FreeImage_GetPitch(new_dib); - - switch(bpp) { - case 1: - { - for (unsigned y = 0; y < height; y++) { - for (unsigned x = 0; x < width; x++) { - const unsigned pixel = (src_bits[x >> 3] & (0x80 >> (x & 0x07))) != 0; - dst_bits[x] = grey_pal[pixel]; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - - case 4: - { - for (unsigned y = 0; y < height; y++) { - for (unsigned x = 0; x < width; x++) { - const unsigned pixel = x & 0x01 ? src_bits[x >> 1] & 0x0F : src_bits[x >> 1] >> 4; - dst_bits[x] = grey_pal[pixel]; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - - case 8: - { - for (unsigned y = 0; y < height; y++) { - for (unsigned x = 0; x < width; x++) { - dst_bits[x] = grey_pal[src_bits[x]]; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - } - return new_dib; - } - - // Convert the bitmap to 8-bit greyscale - return FreeImage_ConvertTo8Bits(dib); -} +// ========================================================== +// Bitmap conversion routines +// +// Design and implementation by +// - Floris van den Berg (flvdberg@wxs.nl) +// - Hervé Drolon (drolon@infonie.fr) +// - Jani Kajala (janik@remedy.fi) +// - Karl-Heinz Bussian (khbussian@moss.de) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" + +// ---------------------------------------------------------- +// internal conversions X to 8 bits +// ---------------------------------------------------------- + +void DLL_CALLCONV +FreeImage_ConvertLine1To8(BYTE *target, BYTE *source, int width_in_pixels) { + for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) + target[cols] = (source[cols >> 3] & (0x80 >> (cols & 0x07))) != 0 ? 255 : 0; +} + +void DLL_CALLCONV +FreeImage_ConvertLine4To8(BYTE *target, BYTE *source, int width_in_pixels) { + unsigned count_new = 0; + unsigned count_org = 0; + BOOL hinibble = TRUE; + + while (count_new < (unsigned)width_in_pixels) { + if (hinibble) { + target[count_new] = (source[count_org] >> 4); + } else { + target[count_new] = (source[count_org] & 0x0F); + count_org++; + } + hinibble = !hinibble; + count_new++; + } +} + +void DLL_CALLCONV +FreeImage_ConvertLine16To8_555(BYTE *target, BYTE *source, int width_in_pixels) { + const WORD *const bits = (WORD *)source; + for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) { + target[cols] = GREY((((bits[cols] & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT) * 0xFF) / 0x1F, + (((bits[cols] & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT) * 0xFF) / 0x1F, + (((bits[cols] & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT) * 0xFF) / 0x1F); + } +} + +void DLL_CALLCONV +FreeImage_ConvertLine16To8_565(BYTE *target, BYTE *source, int width_in_pixels) { + const WORD *const bits = (WORD *)source; + for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) { + target[cols] = GREY((((bits[cols] & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT) * 0xFF) / 0x1F, + (((bits[cols] & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT) * 0xFF) / 0x3F, + (((bits[cols] & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT) * 0xFF) / 0x1F); + } +} + +void DLL_CALLCONV +FreeImage_ConvertLine24To8(BYTE *target, BYTE *source, int width_in_pixels) { + for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) { + target[cols] = GREY(source[FI_RGBA_RED], source[FI_RGBA_GREEN], source[FI_RGBA_BLUE]); + source += 3; + } +} + +void DLL_CALLCONV +FreeImage_ConvertLine32To8(BYTE *target, BYTE *source, int width_in_pixels) { + for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) { + target[cols] = GREY(source[FI_RGBA_RED], source[FI_RGBA_GREEN], source[FI_RGBA_BLUE]); + source += 4; + } +} + +// ---------------------------------------------------------- +// smart convert X to 8 bits +// ---------------------------------------------------------- + +FIBITMAP * DLL_CALLCONV +FreeImage_ConvertTo8Bits(FIBITMAP *dib) { + if (!FreeImage_HasPixels(dib)) { + return NULL; + } + + const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); + if (image_type != FIT_BITMAP && image_type != FIT_UINT16) { + return NULL; + } + + const unsigned bpp = FreeImage_GetBPP(dib); + + if (bpp != 8) { + + const unsigned width = FreeImage_GetWidth(dib); + const unsigned height = FreeImage_GetHeight(dib); + + // Allocate a destination image + FIBITMAP *new_dib = FreeImage_Allocate(width, height, 8); + if (new_dib == NULL) { + return NULL; + } + + // Copy metadata from src to dst + FreeImage_CloneMetadata(new_dib, dib); + + // Palette of destination image has already been initialized + RGBQUAD *new_pal = FreeImage_GetPalette(new_dib); + + const FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib); + + if (image_type == FIT_BITMAP) { + + switch(bpp) { + case 1: + { + if (color_type == FIC_PALETTE) { + // Copy the palette + RGBQUAD *old_pal = FreeImage_GetPalette(dib); + new_pal[0] = old_pal[0]; + new_pal[255] = old_pal[1]; + + } else if (color_type == FIC_MINISWHITE) { + // Create a reverse grayscale palette + CREATE_GREYSCALE_PALETTE_REVERSE(new_pal, 256); + } + + // Expand and copy the bitmap data + for (unsigned rows = 0; rows < height; rows++) { + FreeImage_ConvertLine1To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); + } + return new_dib; + } + + case 4 : + { + if (color_type == FIC_PALETTE) { + // Copy the palette + memcpy(new_pal, FreeImage_GetPalette(dib), 16 * sizeof(RGBQUAD)); + } + + // Expand and copy the bitmap data + for (unsigned rows = 0; rows < height; rows++) { + FreeImage_ConvertLine4To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); + } + return new_dib; + } + + case 16 : + { + // Expand and copy the bitmap data + if (IS_FORMAT_RGB565(dib)) { + for (unsigned rows = 0; rows < height; rows++) { + FreeImage_ConvertLine16To8_565(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); + } + } else { + for (unsigned rows = 0; rows < height; rows++) { + FreeImage_ConvertLine16To8_555(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); + } + } + return new_dib; + } + + case 24 : + { + // Expand and copy the bitmap data + for (unsigned rows = 0; rows < height; rows++) { + FreeImage_ConvertLine24To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); + } + return new_dib; + } + + case 32 : + { + // Expand and copy the bitmap data + for (unsigned rows = 0; rows < height; rows++) { + FreeImage_ConvertLine32To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width); + } + return new_dib; + } + } + + } else if (image_type == FIT_UINT16) { + + const unsigned src_pitch = FreeImage_GetPitch(dib); + const unsigned dst_pitch = FreeImage_GetPitch(new_dib); + const BYTE *src_bits = FreeImage_GetBits(dib); + BYTE *dst_bits = FreeImage_GetBits(new_dib); + + for (unsigned rows = 0; rows < height; rows++) { + const WORD *const src_pixel = (WORD*)src_bits; + BYTE *dst_pixel = (BYTE*)dst_bits; + for(unsigned cols = 0; cols < width; cols++) { + dst_pixel[cols] = (BYTE)(src_pixel[cols] >> 8); + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + return new_dib; + } + + } // bpp != 8 + + return FreeImage_Clone(dib); +} + +FIBITMAP * DLL_CALLCONV +FreeImage_ConvertToGreyscale(FIBITMAP *dib) { + if (!FreeImage_HasPixels(dib)) { + return NULL; + } + + const FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib); + + if (color_type == FIC_PALETTE || color_type == FIC_MINISWHITE) { + + const unsigned bpp = FreeImage_GetBPP(dib); + const unsigned width = FreeImage_GetWidth(dib); + const unsigned height = FreeImage_GetHeight(dib); + + FIBITMAP *new_dib = FreeImage_Allocate(width, height, 8); + if (new_dib == NULL) { + return NULL; + } + + // Copy metadata from src to dst + FreeImage_CloneMetadata(new_dib, dib); + + // Create a greyscale palette + BYTE grey_pal[256]; + const RGBQUAD *pal = FreeImage_GetPalette(dib); + const unsigned size = CalculateUsedPaletteEntries(bpp); + for (unsigned i = 0; i < size; i++) { + grey_pal[i] = GREY(pal->rgbRed, pal->rgbGreen, pal->rgbBlue); + pal++; + } + + const BYTE *src_bits = FreeImage_GetBits(dib); + BYTE *dst_bits = FreeImage_GetBits(new_dib); + + const unsigned src_pitch = FreeImage_GetPitch(dib); + const unsigned dst_pitch = FreeImage_GetPitch(new_dib); + + switch(bpp) { + case 1: + { + for (unsigned y = 0; y < height; y++) { + for (unsigned x = 0; x < width; x++) { + const unsigned pixel = (src_bits[x >> 3] & (0x80 >> (x & 0x07))) != 0; + dst_bits[x] = grey_pal[pixel]; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + + case 4: + { + for (unsigned y = 0; y < height; y++) { + for (unsigned x = 0; x < width; x++) { + const unsigned pixel = x & 0x01 ? src_bits[x >> 1] & 0x0F : src_bits[x >> 1] >> 4; + dst_bits[x] = grey_pal[pixel]; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + + case 8: + { + for (unsigned y = 0; y < height; y++) { + for (unsigned x = 0; x < width; x++) { + dst_bits[x] = grey_pal[src_bits[x]]; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + } + return new_dib; + } + + // Convert the bitmap to 8-bit greyscale + return FreeImage_ConvertTo8Bits(dib); +} diff --git a/Source/FreeImage/ConversionFloat.cpp b/Source/FreeImage/ConversionFloat.cpp index e72d14c..fb696ac 100644 --- a/Source/FreeImage/ConversionFloat.cpp +++ b/Source/FreeImage/ConversionFloat.cpp @@ -1,192 +1,192 @@ -// ========================================================== -// Bitmap conversion routines -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" - -// ---------------------------------------------------------- -// smart convert X to Float -// ---------------------------------------------------------- - -FIBITMAP * DLL_CALLCONV -FreeImage_ConvertToFloat(FIBITMAP *dib) { - FIBITMAP *src = NULL; - FIBITMAP *dst = NULL; - - if(!FreeImage_HasPixels(dib)) return NULL; - - FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib); - - // check for allowed conversions - switch(src_type) { - case FIT_BITMAP: - { - // allow conversion from 8-bit - if((FreeImage_GetBPP(dib) == 8) && (FreeImage_GetColorType(dib) == FIC_MINISBLACK)) { - src = dib; - } else { - src = FreeImage_ConvertToGreyscale(dib); - if(!src) return NULL; - } - break; - } - case FIT_UINT16: - case FIT_RGB16: - case FIT_RGBA16: - case FIT_RGBF: - case FIT_RGBAF: - src = dib; - break; - case FIT_FLOAT: - // float type : clone the src - return FreeImage_Clone(dib); - default: - return NULL; - } - - // allocate dst image - - const unsigned width = FreeImage_GetWidth(src); - const unsigned height = FreeImage_GetHeight(src); - - dst = FreeImage_AllocateT(FIT_FLOAT, width, height); - if(!dst) { - if(src != dib) { - FreeImage_Unload(src); - } - return NULL; - } - - // copy metadata from src to dst - FreeImage_CloneMetadata(dst, src); - - // convert from src type to float - - const unsigned src_pitch = FreeImage_GetPitch(src); - const unsigned dst_pitch = FreeImage_GetPitch(dst); - - const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); - BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); - - switch(src_type) { - case FIT_BITMAP: - { - for(unsigned y = 0; y < height; y++) { - const BYTE *src_pixel = (BYTE*)src_bits; - float *dst_pixel = (float*)dst_bits; - for(unsigned x = 0; x < width; x++) { - // convert and scale to the range [0..1] - dst_pixel[x] = (float)(src_pixel[x]) / 255; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - - case FIT_UINT16: - { - for(unsigned y = 0; y < height; y++) { - const WORD *src_pixel = (WORD*)src_bits; - float *dst_pixel = (float*)dst_bits; - - for(unsigned x = 0; x < width; x++) { - // convert and scale to the range [0..1] - dst_pixel[x] = (float)(src_pixel[x]) / 65535; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - - case FIT_RGB16: - { - for(unsigned y = 0; y < height; y++) { - const FIRGB16 *src_pixel = (FIRGB16*)src_bits; - float *dst_pixel = (float*)dst_bits; - - for(unsigned x = 0; x < width; x++) { - // convert and scale to the range [0..1] - dst_pixel[x] = LUMA_REC709(src_pixel[x].red, src_pixel[x].green, src_pixel[x].blue) / 65535.0F; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - - case FIT_RGBA16: - { - for(unsigned y = 0; y < height; y++) { - const FIRGBA16 *src_pixel = (FIRGBA16*)src_bits; - float *dst_pixel = (float*)dst_bits; - - for(unsigned x = 0; x < width; x++) { - // convert and scale to the range [0..1] - dst_pixel[x] = LUMA_REC709(src_pixel[x].red, src_pixel[x].green, src_pixel[x].blue) / 65535.0F; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - - case FIT_RGBF: - { - for(unsigned y = 0; y < height; y++) { - const FIRGBF *src_pixel = (FIRGBF*)src_bits; - float *dst_pixel = (float*)dst_bits; - - for(unsigned x = 0; x < width; x++) { - // convert (assume pixel values are in the range [0..1]) - dst_pixel[x] = LUMA_REC709(src_pixel[x].red, src_pixel[x].green, src_pixel[x].blue); - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - - case FIT_RGBAF: - { - for(unsigned y = 0; y < height; y++) { - const FIRGBAF *src_pixel = (FIRGBAF*)src_bits; - float *dst_pixel = (float*)dst_bits; - - for(unsigned x = 0; x < width; x++) { - // convert (assume pixel values are in the range [0..1]) - dst_pixel[x] = LUMA_REC709(src_pixel[x].red, src_pixel[x].green, src_pixel[x].blue); - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - } - - if(src != dib) { - FreeImage_Unload(src); - } - - return dst; -} - +// ========================================================== +// Bitmap conversion routines +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" + +// ---------------------------------------------------------- +// smart convert X to Float +// ---------------------------------------------------------- + +FIBITMAP * DLL_CALLCONV +FreeImage_ConvertToFloat(FIBITMAP *dib) { + FIBITMAP *src = NULL; + FIBITMAP *dst = NULL; + + if(!FreeImage_HasPixels(dib)) return NULL; + + FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib); + + // check for allowed conversions + switch(src_type) { + case FIT_BITMAP: + { + // allow conversion from 8-bit + if((FreeImage_GetBPP(dib) == 8) && (FreeImage_GetColorType(dib) == FIC_MINISBLACK)) { + src = dib; + } else { + src = FreeImage_ConvertToGreyscale(dib); + if(!src) return NULL; + } + break; + } + case FIT_UINT16: + case FIT_RGB16: + case FIT_RGBA16: + case FIT_RGBF: + case FIT_RGBAF: + src = dib; + break; + case FIT_FLOAT: + // float type : clone the src + return FreeImage_Clone(dib); + default: + return NULL; + } + + // allocate dst image + + const unsigned width = FreeImage_GetWidth(src); + const unsigned height = FreeImage_GetHeight(src); + + dst = FreeImage_AllocateT(FIT_FLOAT, width, height); + if(!dst) { + if(src != dib) { + FreeImage_Unload(src); + } + return NULL; + } + + // copy metadata from src to dst + FreeImage_CloneMetadata(dst, src); + + // convert from src type to float + + const unsigned src_pitch = FreeImage_GetPitch(src); + const unsigned dst_pitch = FreeImage_GetPitch(dst); + + const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); + BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); + + switch(src_type) { + case FIT_BITMAP: + { + for(unsigned y = 0; y < height; y++) { + const BYTE *src_pixel = (BYTE*)src_bits; + float *dst_pixel = (float*)dst_bits; + for(unsigned x = 0; x < width; x++) { + // convert and scale to the range [0..1] + dst_pixel[x] = (float)(src_pixel[x]) / 255; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + + case FIT_UINT16: + { + for(unsigned y = 0; y < height; y++) { + const WORD *src_pixel = (WORD*)src_bits; + float *dst_pixel = (float*)dst_bits; + + for(unsigned x = 0; x < width; x++) { + // convert and scale to the range [0..1] + dst_pixel[x] = (float)(src_pixel[x]) / 65535; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + + case FIT_RGB16: + { + for(unsigned y = 0; y < height; y++) { + const FIRGB16 *src_pixel = (FIRGB16*)src_bits; + float *dst_pixel = (float*)dst_bits; + + for(unsigned x = 0; x < width; x++) { + // convert and scale to the range [0..1] + dst_pixel[x] = LUMA_REC709(src_pixel[x].red, src_pixel[x].green, src_pixel[x].blue) / 65535.0F; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + + case FIT_RGBA16: + { + for(unsigned y = 0; y < height; y++) { + const FIRGBA16 *src_pixel = (FIRGBA16*)src_bits; + float *dst_pixel = (float*)dst_bits; + + for(unsigned x = 0; x < width; x++) { + // convert and scale to the range [0..1] + dst_pixel[x] = LUMA_REC709(src_pixel[x].red, src_pixel[x].green, src_pixel[x].blue) / 65535.0F; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + + case FIT_RGBF: + { + for(unsigned y = 0; y < height; y++) { + const FIRGBF *src_pixel = (FIRGBF*)src_bits; + float *dst_pixel = (float*)dst_bits; + + for(unsigned x = 0; x < width; x++) { + // convert (assume pixel values are in the range [0..1]) + dst_pixel[x] = LUMA_REC709(src_pixel[x].red, src_pixel[x].green, src_pixel[x].blue); + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + + case FIT_RGBAF: + { + for(unsigned y = 0; y < height; y++) { + const FIRGBAF *src_pixel = (FIRGBAF*)src_bits; + float *dst_pixel = (float*)dst_bits; + + for(unsigned x = 0; x < width; x++) { + // convert (assume pixel values are in the range [0..1]) + dst_pixel[x] = LUMA_REC709(src_pixel[x].red, src_pixel[x].green, src_pixel[x].blue); + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + } + + if(src != dib) { + FreeImage_Unload(src); + } + + return dst; +} + diff --git a/Source/FreeImage/ConversionRGB16.cpp b/Source/FreeImage/ConversionRGB16.cpp index bd38504..9e28205 100644 --- a/Source/FreeImage/ConversionRGB16.cpp +++ b/Source/FreeImage/ConversionRGB16.cpp @@ -1,144 +1,144 @@ -// ========================================================== -// Bitmap conversion routines -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" - -// ---------------------------------------------------------- -// smart convert X to RGB16 -// ---------------------------------------------------------- - -FIBITMAP * DLL_CALLCONV -FreeImage_ConvertToRGB16(FIBITMAP *dib) { - FIBITMAP *src = NULL; - FIBITMAP *dst = NULL; - - if(!FreeImage_HasPixels(dib)) return NULL; - - const FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib); - - // check for allowed conversions - switch(src_type) { - case FIT_BITMAP: - { - // convert to 24-bit if needed - if((FreeImage_GetBPP(dib) == 24) || (FreeImage_GetBPP(dib) == 32)) { - src = dib; - } else { - src = FreeImage_ConvertTo24Bits(dib); - if(!src) return NULL; - } - break; - } - case FIT_UINT16: - // allow conversion from unsigned 16-bit - src = dib; - break; - case FIT_RGB16: - // RGB16 type : clone the src - return FreeImage_Clone(dib); - break; - case FIT_RGBA16: - // allow conversion from 64-bit RGBA (ignore the alpha channel) - src = dib; - break; - default: - return NULL; - } - - // allocate dst image - - const unsigned width = FreeImage_GetWidth(src); - const unsigned height = FreeImage_GetHeight(src); - - dst = FreeImage_AllocateT(FIT_RGB16, width, height); - if(!dst) { - if(src != dib) { - FreeImage_Unload(src); - } - return NULL; - } - - // copy metadata from src to dst - FreeImage_CloneMetadata(dst, src); - - // convert from src type to RGB16 - - switch(src_type) { - case FIT_BITMAP: - { - // Calculate the number of bytes per pixel (1 for 8-bit, 3 for 24-bit or 4 for 32-bit) - const unsigned bytespp = FreeImage_GetLine(src) / FreeImage_GetWidth(src); - - for(unsigned y = 0; y < height; y++) { - const BYTE *src_bits = (BYTE*)FreeImage_GetScanLine(src, y); - FIRGB16 *dst_bits = (FIRGB16*)FreeImage_GetScanLine(dst, y); - for(unsigned x = 0; x < width; x++) { - dst_bits[x].red = src_bits[FI_RGBA_RED] << 8; - dst_bits[x].green = src_bits[FI_RGBA_GREEN] << 8; - dst_bits[x].blue = src_bits[FI_RGBA_BLUE] << 8; - src_bits += bytespp; - } - } - } - break; - - case FIT_UINT16: - { - for(unsigned y = 0; y < height; y++) { - const WORD *src_bits = (WORD*)FreeImage_GetScanLine(src, y); - FIRGB16 *dst_bits = (FIRGB16*)FreeImage_GetScanLine(dst, y); - for(unsigned x = 0; x < width; x++) { - // convert by copying greyscale channel to each R, G, B channels - dst_bits[x].red = src_bits[x]; - dst_bits[x].green = src_bits[x]; - dst_bits[x].blue = src_bits[x]; - } - } - } - break; - - case FIT_RGBA16: - { - for(unsigned y = 0; y < height; y++) { - const FIRGBA16 *src_bits = (FIRGBA16*)FreeImage_GetScanLine(src, y); - FIRGB16 *dst_bits = (FIRGB16*)FreeImage_GetScanLine(dst, y); - for(unsigned x = 0; x < width; x++) { - // convert and skip alpha channel - dst_bits[x].red = src_bits[x].red; - dst_bits[x].green = src_bits[x].green; - dst_bits[x].blue = src_bits[x].blue; - } - } - } - break; - - default: - break; - } - - if(src != dib) { - FreeImage_Unload(src); - } - - return dst; -} - +// ========================================================== +// Bitmap conversion routines +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" + +// ---------------------------------------------------------- +// smart convert X to RGB16 +// ---------------------------------------------------------- + +FIBITMAP * DLL_CALLCONV +FreeImage_ConvertToRGB16(FIBITMAP *dib) { + FIBITMAP *src = NULL; + FIBITMAP *dst = NULL; + + if(!FreeImage_HasPixels(dib)) return NULL; + + const FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib); + + // check for allowed conversions + switch(src_type) { + case FIT_BITMAP: + { + // convert to 24-bit if needed + if((FreeImage_GetBPP(dib) == 24) || (FreeImage_GetBPP(dib) == 32)) { + src = dib; + } else { + src = FreeImage_ConvertTo24Bits(dib); + if(!src) return NULL; + } + break; + } + case FIT_UINT16: + // allow conversion from unsigned 16-bit + src = dib; + break; + case FIT_RGB16: + // RGB16 type : clone the src + return FreeImage_Clone(dib); + break; + case FIT_RGBA16: + // allow conversion from 64-bit RGBA (ignore the alpha channel) + src = dib; + break; + default: + return NULL; + } + + // allocate dst image + + const unsigned width = FreeImage_GetWidth(src); + const unsigned height = FreeImage_GetHeight(src); + + dst = FreeImage_AllocateT(FIT_RGB16, width, height); + if(!dst) { + if(src != dib) { + FreeImage_Unload(src); + } + return NULL; + } + + // copy metadata from src to dst + FreeImage_CloneMetadata(dst, src); + + // convert from src type to RGB16 + + switch(src_type) { + case FIT_BITMAP: + { + // Calculate the number of bytes per pixel (1 for 8-bit, 3 for 24-bit or 4 for 32-bit) + const unsigned bytespp = FreeImage_GetLine(src) / FreeImage_GetWidth(src); + + for(unsigned y = 0; y < height; y++) { + const BYTE *src_bits = (BYTE*)FreeImage_GetScanLine(src, y); + FIRGB16 *dst_bits = (FIRGB16*)FreeImage_GetScanLine(dst, y); + for(unsigned x = 0; x < width; x++) { + dst_bits[x].red = src_bits[FI_RGBA_RED] << 8; + dst_bits[x].green = src_bits[FI_RGBA_GREEN] << 8; + dst_bits[x].blue = src_bits[FI_RGBA_BLUE] << 8; + src_bits += bytespp; + } + } + } + break; + + case FIT_UINT16: + { + for(unsigned y = 0; y < height; y++) { + const WORD *src_bits = (WORD*)FreeImage_GetScanLine(src, y); + FIRGB16 *dst_bits = (FIRGB16*)FreeImage_GetScanLine(dst, y); + for(unsigned x = 0; x < width; x++) { + // convert by copying greyscale channel to each R, G, B channels + dst_bits[x].red = src_bits[x]; + dst_bits[x].green = src_bits[x]; + dst_bits[x].blue = src_bits[x]; + } + } + } + break; + + case FIT_RGBA16: + { + for(unsigned y = 0; y < height; y++) { + const FIRGBA16 *src_bits = (FIRGBA16*)FreeImage_GetScanLine(src, y); + FIRGB16 *dst_bits = (FIRGB16*)FreeImage_GetScanLine(dst, y); + for(unsigned x = 0; x < width; x++) { + // convert and skip alpha channel + dst_bits[x].red = src_bits[x].red; + dst_bits[x].green = src_bits[x].green; + dst_bits[x].blue = src_bits[x].blue; + } + } + } + break; + + default: + break; + } + + if(src != dib) { + FreeImage_Unload(src); + } + + return dst; +} + diff --git a/Source/FreeImage/ConversionRGBF.cpp b/Source/FreeImage/ConversionRGBF.cpp index b5161d5..d3c9987 100644 --- a/Source/FreeImage/ConversionRGBF.cpp +++ b/Source/FreeImage/ConversionRGBF.cpp @@ -1,241 +1,241 @@ -// ========================================================== -// Bitmap conversion routines -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" - -// ---------------------------------------------------------- -// smart convert X to RGBF -// ---------------------------------------------------------- - -FIBITMAP * DLL_CALLCONV -FreeImage_ConvertToRGBF(FIBITMAP *dib) { - FIBITMAP *src = NULL; - FIBITMAP *dst = NULL; - - if(!FreeImage_HasPixels(dib)) return NULL; - - const FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib); - - // check for allowed conversions - switch(src_type) { - case FIT_BITMAP: - { - // allow conversion from 24- and 32-bit - const FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib); - if((color_type != FIC_RGB) && (color_type != FIC_RGBALPHA)) { - src = FreeImage_ConvertTo24Bits(dib); - if(!src) return NULL; - } else { - src = dib; - } - break; - } - case FIT_UINT16: - // allow conversion from 16-bit - src = dib; - break; - case FIT_RGB16: - // allow conversion from 48-bit RGB - src = dib; - break; - case FIT_RGBA16: - // allow conversion from 64-bit RGBA (ignore the alpha channel) - src = dib; - break; - case FIT_FLOAT: - // allow conversion from 32-bit float - src = dib; - break; - case FIT_RGBAF: - // allow conversion from 128-bit RGBAF - src = dib; - break; - case FIT_RGBF: - // RGBF type : clone the src - return FreeImage_Clone(dib); - break; - default: - return NULL; - } - - // allocate dst image - - const unsigned width = FreeImage_GetWidth(src); - const unsigned height = FreeImage_GetHeight(src); - - dst = FreeImage_AllocateT(FIT_RGBF, width, height); - if(!dst) { - if(src != dib) { - FreeImage_Unload(src); - } - return NULL; - } - - // copy metadata from src to dst - FreeImage_CloneMetadata(dst, src); - - // convert from src type to RGBF - - const unsigned src_pitch = FreeImage_GetPitch(src); - const unsigned dst_pitch = FreeImage_GetPitch(dst); - - switch(src_type) { - case FIT_BITMAP: - { - // calculate the number of bytes per pixel (3 for 24-bit or 4 for 32-bit) - const unsigned bytespp = FreeImage_GetLine(src) / FreeImage_GetWidth(src); - - const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); - BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); - - for(unsigned y = 0; y < height; y++) { - const BYTE *src_pixel = (BYTE*)src_bits; - FIRGBF *dst_pixel = (FIRGBF*)dst_bits; - for(unsigned x = 0; x < width; x++) { - // convert and scale to the range [0..1] - dst_pixel->red = (float)(src_pixel[FI_RGBA_RED]) / 255.0F; - dst_pixel->green = (float)(src_pixel[FI_RGBA_GREEN]) / 255.0F; - dst_pixel->blue = (float)(src_pixel[FI_RGBA_BLUE]) / 255.0F; - - src_pixel += bytespp; - dst_pixel ++; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - - case FIT_UINT16: - { - const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); - BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); - - for(unsigned y = 0; y < height; y++) { - const WORD *src_pixel = (WORD*)src_bits; - FIRGBF *dst_pixel = (FIRGBF*)dst_bits; - - for(unsigned x = 0; x < width; x++) { - // convert and scale to the range [0..1] - const float dst_value = (float)src_pixel[x] / 65535.0F; - dst_pixel[x].red = dst_value; - dst_pixel[x].green = dst_value; - dst_pixel[x].blue = dst_value; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - - case FIT_RGB16: - { - const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); - BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); - - for(unsigned y = 0; y < height; y++) { - const FIRGB16 *src_pixel = (FIRGB16*) src_bits; - FIRGBF *dst_pixel = (FIRGBF*) dst_bits; - - for(unsigned x = 0; x < width; x++) { - // convert and scale to the range [0..1] - dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.0F; - dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.0F; - dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.0F; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - - case FIT_RGBA16: - { - const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); - BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); - - for(unsigned y = 0; y < height; y++) { - const FIRGBA16 *src_pixel = (FIRGBA16*) src_bits; - FIRGBF *dst_pixel = (FIRGBF*) dst_bits; - - for(unsigned x = 0; x < width; x++) { - // convert and scale to the range [0..1] - dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.0F; - dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.0F; - dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.0F; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - - case FIT_FLOAT: - { - const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); - BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); - - for(unsigned y = 0; y < height; y++) { - const float *src_pixel = (float*) src_bits; - FIRGBF *dst_pixel = (FIRGBF*) dst_bits; - - for(unsigned x = 0; x < width; x++) { - // convert by copying greyscale channel to each R, G, B channels - dst_pixel[x].red = src_pixel[x]; - dst_pixel[x].green = src_pixel[x]; - dst_pixel[x].blue = src_pixel[x]; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - - case FIT_RGBAF: - { - const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); - BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); - - for(unsigned y = 0; y < height; y++) { - const FIRGBAF *src_pixel = (FIRGBAF*) src_bits; - FIRGBF *dst_pixel = (FIRGBF*) dst_bits; - - for(unsigned x = 0; x < width; x++) { - // convert and skip alpha channel - dst_pixel[x].red = src_pixel[x].red; - dst_pixel[x].green = src_pixel[x].green; - dst_pixel[x].blue = src_pixel[x].blue; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - } - break; - } - - if(src != dib) { - FreeImage_Unload(src); - } - - return dst; -} - +// ========================================================== +// Bitmap conversion routines +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" + +// ---------------------------------------------------------- +// smart convert X to RGBF +// ---------------------------------------------------------- + +FIBITMAP * DLL_CALLCONV +FreeImage_ConvertToRGBF(FIBITMAP *dib) { + FIBITMAP *src = NULL; + FIBITMAP *dst = NULL; + + if(!FreeImage_HasPixels(dib)) return NULL; + + const FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib); + + // check for allowed conversions + switch(src_type) { + case FIT_BITMAP: + { + // allow conversion from 24- and 32-bit + const FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib); + if((color_type != FIC_RGB) && (color_type != FIC_RGBALPHA)) { + src = FreeImage_ConvertTo24Bits(dib); + if(!src) return NULL; + } else { + src = dib; + } + break; + } + case FIT_UINT16: + // allow conversion from 16-bit + src = dib; + break; + case FIT_RGB16: + // allow conversion from 48-bit RGB + src = dib; + break; + case FIT_RGBA16: + // allow conversion from 64-bit RGBA (ignore the alpha channel) + src = dib; + break; + case FIT_FLOAT: + // allow conversion from 32-bit float + src = dib; + break; + case FIT_RGBAF: + // allow conversion from 128-bit RGBAF + src = dib; + break; + case FIT_RGBF: + // RGBF type : clone the src + return FreeImage_Clone(dib); + break; + default: + return NULL; + } + + // allocate dst image + + const unsigned width = FreeImage_GetWidth(src); + const unsigned height = FreeImage_GetHeight(src); + + dst = FreeImage_AllocateT(FIT_RGBF, width, height); + if(!dst) { + if(src != dib) { + FreeImage_Unload(src); + } + return NULL; + } + + // copy metadata from src to dst + FreeImage_CloneMetadata(dst, src); + + // convert from src type to RGBF + + const unsigned src_pitch = FreeImage_GetPitch(src); + const unsigned dst_pitch = FreeImage_GetPitch(dst); + + switch(src_type) { + case FIT_BITMAP: + { + // calculate the number of bytes per pixel (3 for 24-bit or 4 for 32-bit) + const unsigned bytespp = FreeImage_GetLine(src) / FreeImage_GetWidth(src); + + const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); + BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); + + for(unsigned y = 0; y < height; y++) { + const BYTE *src_pixel = (BYTE*)src_bits; + FIRGBF *dst_pixel = (FIRGBF*)dst_bits; + for(unsigned x = 0; x < width; x++) { + // convert and scale to the range [0..1] + dst_pixel->red = (float)(src_pixel[FI_RGBA_RED]) / 255.0F; + dst_pixel->green = (float)(src_pixel[FI_RGBA_GREEN]) / 255.0F; + dst_pixel->blue = (float)(src_pixel[FI_RGBA_BLUE]) / 255.0F; + + src_pixel += bytespp; + dst_pixel ++; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + + case FIT_UINT16: + { + const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); + BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); + + for(unsigned y = 0; y < height; y++) { + const WORD *src_pixel = (WORD*)src_bits; + FIRGBF *dst_pixel = (FIRGBF*)dst_bits; + + for(unsigned x = 0; x < width; x++) { + // convert and scale to the range [0..1] + const float dst_value = (float)src_pixel[x] / 65535.0F; + dst_pixel[x].red = dst_value; + dst_pixel[x].green = dst_value; + dst_pixel[x].blue = dst_value; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + + case FIT_RGB16: + { + const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); + BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); + + for(unsigned y = 0; y < height; y++) { + const FIRGB16 *src_pixel = (FIRGB16*) src_bits; + FIRGBF *dst_pixel = (FIRGBF*) dst_bits; + + for(unsigned x = 0; x < width; x++) { + // convert and scale to the range [0..1] + dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.0F; + dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.0F; + dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.0F; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + + case FIT_RGBA16: + { + const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); + BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); + + for(unsigned y = 0; y < height; y++) { + const FIRGBA16 *src_pixel = (FIRGBA16*) src_bits; + FIRGBF *dst_pixel = (FIRGBF*) dst_bits; + + for(unsigned x = 0; x < width; x++) { + // convert and scale to the range [0..1] + dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.0F; + dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.0F; + dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.0F; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + + case FIT_FLOAT: + { + const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); + BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); + + for(unsigned y = 0; y < height; y++) { + const float *src_pixel = (float*) src_bits; + FIRGBF *dst_pixel = (FIRGBF*) dst_bits; + + for(unsigned x = 0; x < width; x++) { + // convert by copying greyscale channel to each R, G, B channels + dst_pixel[x].red = src_pixel[x]; + dst_pixel[x].green = src_pixel[x]; + dst_pixel[x].blue = src_pixel[x]; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + + case FIT_RGBAF: + { + const BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); + BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); + + for(unsigned y = 0; y < height; y++) { + const FIRGBAF *src_pixel = (FIRGBAF*) src_bits; + FIRGBF *dst_pixel = (FIRGBF*) dst_bits; + + for(unsigned x = 0; x < width; x++) { + // convert and skip alpha channel + dst_pixel[x].red = src_pixel[x].red; + dst_pixel[x].green = src_pixel[x].green; + dst_pixel[x].blue = src_pixel[x].blue; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + } + break; + } + + if(src != dib) { + FreeImage_Unload(src); + } + + return dst; +} + diff --git a/Source/FreeImage/ConversionUINT16.cpp b/Source/FreeImage/ConversionUINT16.cpp index ed4691f..e6492aa 100644 --- a/Source/FreeImage/ConversionUINT16.cpp +++ b/Source/FreeImage/ConversionUINT16.cpp @@ -1,134 +1,134 @@ -// ========================================================== -// Bitmap conversion routines -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" - -// ---------------------------------------------------------- -// smart convert X to UINT16 -// ---------------------------------------------------------- - -FIBITMAP * DLL_CALLCONV -FreeImage_ConvertToUINT16(FIBITMAP *dib) { - FIBITMAP *src = NULL; - FIBITMAP *dst = NULL; - - if(!FreeImage_HasPixels(dib)) return NULL; - - const FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib); - - // check for allowed conversions - switch(src_type) { - case FIT_BITMAP: - { - // convert to greyscale if needed - if((FreeImage_GetBPP(dib) == 8) && (FreeImage_GetColorType(dib) == FIC_MINISBLACK)) { - src = dib; - } else { - src = FreeImage_ConvertToGreyscale(dib); - if(!src) return NULL; - } - break; - } - case FIT_UINT16: - // UINT16 type : clone the src - return FreeImage_Clone(dib); - break; - case FIT_RGB16: - // allow conversion from 48-bit RGB - src = dib; - break; - case FIT_RGBA16: - // allow conversion from 64-bit RGBA (ignore the alpha channel) - src = dib; - break; - default: - return NULL; - } - - // allocate dst image - - const unsigned width = FreeImage_GetWidth(src); - const unsigned height = FreeImage_GetHeight(src); - - dst = FreeImage_AllocateT(FIT_UINT16, width, height); - if(!dst) { - if(src != dib) { - FreeImage_Unload(src); - } - return NULL; - } - - // copy metadata from src to dst - FreeImage_CloneMetadata(dst, src); - - // convert from src type to UINT16 - - switch(src_type) { - case FIT_BITMAP: - { - for(unsigned y = 0; y < height; y++) { - const BYTE *src_bits = (BYTE*)FreeImage_GetScanLine(src, y); - WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y); - for(unsigned x = 0; x < width; x++) { - dst_bits[x] = src_bits[x] << 8; - } - } - } - break; - - case FIT_RGB16: - { - for(unsigned y = 0; y < height; y++) { - const FIRGB16 *src_bits = (FIRGB16*)FreeImage_GetScanLine(src, y); - WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y); - for(unsigned x = 0; x < width; x++) { - // convert to grey - dst_bits[x] = (WORD)LUMA_REC709(src_bits[x].red, src_bits[x].green, src_bits[x].blue); - } - } - } - break; - - case FIT_RGBA16: - { - for(unsigned y = 0; y < height; y++) { - const FIRGBA16 *src_bits = (FIRGBA16*)FreeImage_GetScanLine(src, y); - WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y); - for(unsigned x = 0; x < width; x++) { - // convert to grey - dst_bits[x] = (WORD)LUMA_REC709(src_bits[x].red, src_bits[x].green, src_bits[x].blue); - } - } - } - break; - - default: - break; - } - - if(src != dib) { - FreeImage_Unload(src); - } - - return dst; -} - +// ========================================================== +// Bitmap conversion routines +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" + +// ---------------------------------------------------------- +// smart convert X to UINT16 +// ---------------------------------------------------------- + +FIBITMAP * DLL_CALLCONV +FreeImage_ConvertToUINT16(FIBITMAP *dib) { + FIBITMAP *src = NULL; + FIBITMAP *dst = NULL; + + if(!FreeImage_HasPixels(dib)) return NULL; + + const FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib); + + // check for allowed conversions + switch(src_type) { + case FIT_BITMAP: + { + // convert to greyscale if needed + if((FreeImage_GetBPP(dib) == 8) && (FreeImage_GetColorType(dib) == FIC_MINISBLACK)) { + src = dib; + } else { + src = FreeImage_ConvertToGreyscale(dib); + if(!src) return NULL; + } + break; + } + case FIT_UINT16: + // UINT16 type : clone the src + return FreeImage_Clone(dib); + break; + case FIT_RGB16: + // allow conversion from 48-bit RGB + src = dib; + break; + case FIT_RGBA16: + // allow conversion from 64-bit RGBA (ignore the alpha channel) + src = dib; + break; + default: + return NULL; + } + + // allocate dst image + + const unsigned width = FreeImage_GetWidth(src); + const unsigned height = FreeImage_GetHeight(src); + + dst = FreeImage_AllocateT(FIT_UINT16, width, height); + if(!dst) { + if(src != dib) { + FreeImage_Unload(src); + } + return NULL; + } + + // copy metadata from src to dst + FreeImage_CloneMetadata(dst, src); + + // convert from src type to UINT16 + + switch(src_type) { + case FIT_BITMAP: + { + for(unsigned y = 0; y < height; y++) { + const BYTE *src_bits = (BYTE*)FreeImage_GetScanLine(src, y); + WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y); + for(unsigned x = 0; x < width; x++) { + dst_bits[x] = src_bits[x] << 8; + } + } + } + break; + + case FIT_RGB16: + { + for(unsigned y = 0; y < height; y++) { + const FIRGB16 *src_bits = (FIRGB16*)FreeImage_GetScanLine(src, y); + WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y); + for(unsigned x = 0; x < width; x++) { + // convert to grey + dst_bits[x] = (WORD)LUMA_REC709(src_bits[x].red, src_bits[x].green, src_bits[x].blue); + } + } + } + break; + + case FIT_RGBA16: + { + for(unsigned y = 0; y < height; y++) { + const FIRGBA16 *src_bits = (FIRGBA16*)FreeImage_GetScanLine(src, y); + WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y); + for(unsigned x = 0; x < width; x++) { + // convert to grey + dst_bits[x] = (WORD)LUMA_REC709(src_bits[x].red, src_bits[x].green, src_bits[x].blue); + } + } + } + break; + + default: + break; + } + + if(src != dib) { + FreeImage_Unload(src); + } + + return dst; +} + diff --git a/Source/FreeImage/J2KHelper.cpp b/Source/FreeImage/J2KHelper.cpp index c9f8fa5..d0abd79 100644 --- a/Source/FreeImage/J2KHelper.cpp +++ b/Source/FreeImage/J2KHelper.cpp @@ -1,500 +1,500 @@ -// ========================================================== -// JPEG2000 helpers -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" -#include "../LibOpenJPEG/openjpeg.h" - -/** -Divide an integer by a power of 2 and round upwards -@return Returns a divided by 2^b -*/ -static int int_ceildivpow2(int a, int b) { - return (a + (1 << b) - 1) >> b; -} - -/** -Convert a OpenJPEG image to a FIBITMAP -@param format_id Plugin ID -@param image OpenJPEG image -@return Returns the converted image if successful, returns NULL otherwise -*/ -FIBITMAP* J2KImageToFIBITMAP(int format_id, const opj_image_t *image) { - FIBITMAP *dib = NULL; - - try { - // compute image width and height - - //int w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx); - int wr = image->comps[0].w; - int wrr = int_ceildivpow2(image->comps[0].w, image->comps[0].factor); - - //int h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy); - //int hr = image->comps[0].h; - int hrr = int_ceildivpow2(image->comps[0].h, image->comps[0].factor); - - // check the number of components - - int numcomps = image->numcomps; - - BOOL bIsValid = TRUE; - for(int c = 0; c < numcomps - 1; c++) { - if( (image->comps[c].dx == image->comps[c+1].dx) && - (image->comps[c].dy == image->comps[c+1].dy) && - (image->comps[c].prec == image->comps[c+1].prec) ) { - continue; - } else { - bIsValid = FALSE; - break; - } - } - bIsValid &= ((numcomps == 1) || (numcomps == 3) || (numcomps == 4)); - if(!bIsValid) { - if(numcomps) { - FreeImage_OutputMessageProc(format_id, "Warning: image contains %d greyscale components. Only the first will be loaded.\n", numcomps); - numcomps = 1; - } else { - // unknown type - throw FI_MSG_ERROR_UNSUPPORTED_FORMAT; - } - } - - // create a new DIB - - if(image->comps[0].prec <= 8) { - switch(numcomps) { - case 1: - dib = FreeImage_Allocate(wrr, hrr, 8); - break; - case 3: - dib = FreeImage_Allocate(wrr, hrr, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - break; - case 4: - dib = FreeImage_Allocate(wrr, hrr, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - break; - } - } else if(image->comps[0].prec <= 16) { - switch(numcomps) { - case 1: - dib = FreeImage_AllocateT(FIT_UINT16, wrr, hrr); - break; - case 3: - dib = FreeImage_AllocateT(FIT_RGB16, wrr, hrr); - break; - case 4: - dib = FreeImage_AllocateT(FIT_RGBA16, wrr, hrr); - break; - } - } else { - throw FI_MSG_ERROR_UNSUPPORTED_FORMAT; - } - if(!dib) { - throw FI_MSG_ERROR_DIB_MEMORY; - } - - if(image->comps[0].prec <= 8) { - if(numcomps == 1) { - // 8-bit greyscale - // ---------------------------------------------------------- - - // build a greyscale palette - - RGBQUAD *pal = FreeImage_GetPalette(dib); - for (int i = 0; i < 256; i++) { - pal[i].rgbRed = (BYTE)i; - pal[i].rgbGreen = (BYTE)i; - pal[i].rgbBlue = (BYTE)i; - } - - // load pixel data - - unsigned pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - BYTE *bits = FreeImage_GetScanLine(dib, hrr - 1 - y); - - for(int x = 0; x < wrr; x++) { - const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; - - int index = image->comps[0].data[pixel_pos]; - index += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - - bits[x] = (BYTE)index; - - pixel_count++; - } - } - } - else if(numcomps == 3) { - - // 24-bit RGB - // ---------------------------------------------------------- - - // load pixel data - - unsigned pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - BYTE *bits = FreeImage_GetScanLine(dib, hrr - 1 - y); - - for(int x = 0; x < wrr; x++) { - const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; - - int r = image->comps[0].data[pixel_pos]; - r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - - int g = image->comps[1].data[pixel_pos]; - g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - - int b = image->comps[2].data[pixel_pos]; - b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - - bits[FI_RGBA_RED] = (BYTE)r; - bits[FI_RGBA_GREEN] = (BYTE)g; - bits[FI_RGBA_BLUE] = (BYTE)b; - bits += 3; - - pixel_count++; - } - } - } - else if(numcomps == 4) { - - // 32-bit RGBA - // ---------------------------------------------------------- - - // load pixel data - - unsigned pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - BYTE *bits = FreeImage_GetScanLine(dib, hrr - 1 - y); - - for(int x = 0; x < wrr; x++) { - const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; - - int r = image->comps[0].data[pixel_pos]; - r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - - int g = image->comps[1].data[pixel_pos]; - g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - - int b = image->comps[2].data[pixel_pos]; - b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - - int a = image->comps[3].data[pixel_pos]; - a += (image->comps[3].sgnd ? 1 << (image->comps[3].prec - 1) : 0); - - bits[FI_RGBA_RED] = (BYTE)r; - bits[FI_RGBA_GREEN] = (BYTE)g; - bits[FI_RGBA_BLUE] = (BYTE)b; - bits[FI_RGBA_ALPHA] = (BYTE)a; - bits += 4; - - pixel_count++; - } - } - } - } - else if(image->comps[0].prec <= 16) { - if(numcomps == 1) { - // 16-bit greyscale - // ---------------------------------------------------------- - - // load pixel data - - unsigned pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - unsigned short *bits = (unsigned short*)FreeImage_GetScanLine(dib, hrr - 1 - y); - - for(int x = 0; x < wrr; x++) { - const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; - - int index = image->comps[0].data[pixel_pos]; - index += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - - bits[x] = (unsigned short)index; - - pixel_count++; - } - } - } - else if(numcomps == 3) { - - // 48-bit RGB - // ---------------------------------------------------------- - - // load pixel data - - unsigned pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - FIRGB16 *bits = (FIRGB16*)FreeImage_GetScanLine(dib, hrr - 1 - y); - - for(int x = 0; x < wrr; x++) { - const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; - - int r = image->comps[0].data[pixel_pos]; - r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - - int g = image->comps[1].data[pixel_pos]; - g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - - int b = image->comps[2].data[pixel_pos]; - b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - - bits[x].red = (WORD)r; - bits[x].green = (WORD)g; - bits[x].blue = (WORD)b; - - pixel_count++; - } - } - } - else if(numcomps == 4) { - - // 64-bit RGBA - // ---------------------------------------------------------- - - // load pixel data - - unsigned pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - FIRGBA16 *bits = (FIRGBA16*)FreeImage_GetScanLine(dib, hrr - 1 - y); - - for(int x = 0; x < wrr; x++) { - const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; - - int r = image->comps[0].data[pixel_pos]; - r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - - int g = image->comps[1].data[pixel_pos]; - g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - - int b = image->comps[2].data[pixel_pos]; - b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - - int a = image->comps[3].data[pixel_pos]; - a += (image->comps[3].sgnd ? 1 << (image->comps[3].prec - 1) : 0); - - bits[x].red = (WORD)r; - bits[x].green = (WORD)g; - bits[x].blue = (WORD)b; - bits[x].alpha = (WORD)a; - - pixel_count++; - } - } - } - } - - return dib; - - } catch(const char *text) { - if(dib) FreeImage_Unload(dib); - FreeImage_OutputMessageProc(format_id, text); - return NULL; - } - -} - -/** -Convert a FIBITMAP to a OpenJPEG image -@param format_id Plugin ID -@param dib FreeImage image -@param parameters Compression parameters -@return Returns the converted image if successful, returns NULL otherwise -*/ -opj_image_t* FIBITMAPToJ2KImage(int format_id, FIBITMAP *dib, const opj_cparameters_t *parameters) { - int prec, numcomps, x, y, index; - OPJ_COLOR_SPACE color_space; - opj_image_cmptparm_t cmptparm[4]; // maximum of 4 components - opj_image_t *image = NULL; // image to encode - - try { - int w = FreeImage_GetWidth(dib); - int h = FreeImage_GetHeight(dib); - - // get image characteristics - FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); - - if(image_type == FIT_BITMAP) { - // standard image ... - prec = 8; - switch(FreeImage_GetColorType(dib)) { - case FIC_MINISBLACK: - numcomps = 1; - color_space = CLRSPC_GRAY; - break; - case FIC_RGB: - if(FreeImage_GetBPP(dib) == 32) { - // 32-bit image with a fully opaque layer - numcomps = 4; - color_space = CLRSPC_SRGB; - } else { - // 24-bit image - numcomps = 3; - color_space = CLRSPC_SRGB; - } - break; - case FIC_RGBALPHA: - numcomps = 4; - color_space = CLRSPC_SRGB; - break; - default: - return NULL; - } - } else { - // HDR image ... - prec = 16; - switch(image_type) { - case FIT_UINT16: - numcomps = 1; - color_space = CLRSPC_GRAY; - break; - case FIT_RGB16: - numcomps = 3; - color_space = CLRSPC_SRGB; - break; - case FIT_RGBA16: - numcomps = 4; - color_space = CLRSPC_SRGB; - break; - default: - return NULL; - } - } - - // initialize image components - memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); - for(int i = 0; i < numcomps; i++) { - cmptparm[i].dx = parameters->subsampling_dx; - cmptparm[i].dy = parameters->subsampling_dy; - cmptparm[i].w = w; - cmptparm[i].h = h; - cmptparm[i].prec = prec; - cmptparm[i].bpp = prec; - cmptparm[i].sgnd = 0; - } - // create the image - image = opj_image_create(numcomps, &cmptparm[0], color_space); - if(!image) { - throw FI_MSG_ERROR_DIB_MEMORY; - } - - // set image offset and reference grid - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = parameters->image_offset_x0 + (w - 1) * parameters->subsampling_dx + 1; - image->y1 = parameters->image_offset_y0 + (h - 1) * parameters->subsampling_dy + 1; - - // set image data - if(prec == 8) { - switch(numcomps) { - case 1: - index = 0; - for(y = 0; y < h; y++) { - BYTE *bits = FreeImage_GetScanLine(dib, h - 1 - y); - for(x = 0; x < w; x++) { - image->comps[0].data[index] = bits[x]; - index++; - } - } - break; - case 3: - index = 0; - for(y = 0; y < h; y++) { - BYTE *bits = FreeImage_GetScanLine(dib, h - 1 - y); - for(x = 0; x < w; x++) { - image->comps[0].data[index] = bits[FI_RGBA_RED]; - image->comps[1].data[index] = bits[FI_RGBA_GREEN]; - image->comps[2].data[index] = bits[FI_RGBA_BLUE]; - bits += 3; - index++; - } - } - break; - case 4: - index = 0; - for(y = 0; y < h; y++) { - BYTE *bits = FreeImage_GetScanLine(dib, h - 1 - y); - for(x = 0; x < w; x++) { - image->comps[0].data[index] = bits[FI_RGBA_RED]; - image->comps[1].data[index] = bits[FI_RGBA_GREEN]; - image->comps[2].data[index] = bits[FI_RGBA_BLUE]; - image->comps[3].data[index] = bits[FI_RGBA_ALPHA]; - bits += 4; - index++; - } - } - break; - } - } - else if(prec == 16) { - switch(numcomps) { - case 1: - index = 0; - for(y = 0; y < h; y++) { - WORD *bits = (WORD*)FreeImage_GetScanLine(dib, h - 1 - y); - for(x = 0; x < w; x++) { - image->comps[0].data[index] = bits[x]; - index++; - } - } - break; - case 3: - index = 0; - for(y = 0; y < h; y++) { - FIRGB16 *bits = (FIRGB16*)FreeImage_GetScanLine(dib, h - 1 - y); - for(x = 0; x < w; x++) { - image->comps[0].data[index] = bits[x].red; - image->comps[1].data[index] = bits[x].green; - image->comps[2].data[index] = bits[x].blue; - index++; - } - } - break; - case 4: - index = 0; - for(y = 0; y < h; y++) { - FIRGBA16 *bits = (FIRGBA16*)FreeImage_GetScanLine(dib, h - 1 - y); - for(x = 0; x < w; x++) { - image->comps[0].data[index] = bits[x].red; - image->comps[1].data[index] = bits[x].green; - image->comps[2].data[index] = bits[x].blue; - image->comps[3].data[index] = bits[x].alpha; - index++; - } - } - break; - } - } - - return image; - - } catch (const char *text) { - if(image) opj_image_destroy(image); - FreeImage_OutputMessageProc(format_id, text); - return NULL; - } -} +// ========================================================== +// JPEG2000 helpers +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" +#include "../LibOpenJPEG/openjpeg.h" + +/** +Divide an integer by a power of 2 and round upwards +@return Returns a divided by 2^b +*/ +static int int_ceildivpow2(int a, int b) { + return (a + (1 << b) - 1) >> b; +} + +/** +Convert a OpenJPEG image to a FIBITMAP +@param format_id Plugin ID +@param image OpenJPEG image +@return Returns the converted image if successful, returns NULL otherwise +*/ +FIBITMAP* J2KImageToFIBITMAP(int format_id, const opj_image_t *image) { + FIBITMAP *dib = NULL; + + try { + // compute image width and height + + //int w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx); + int wr = image->comps[0].w; + int wrr = int_ceildivpow2(image->comps[0].w, image->comps[0].factor); + + //int h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy); + //int hr = image->comps[0].h; + int hrr = int_ceildivpow2(image->comps[0].h, image->comps[0].factor); + + // check the number of components + + int numcomps = image->numcomps; + + BOOL bIsValid = TRUE; + for(int c = 0; c < numcomps - 1; c++) { + if( (image->comps[c].dx == image->comps[c+1].dx) && + (image->comps[c].dy == image->comps[c+1].dy) && + (image->comps[c].prec == image->comps[c+1].prec) ) { + continue; + } else { + bIsValid = FALSE; + break; + } + } + bIsValid &= ((numcomps == 1) || (numcomps == 3) || (numcomps == 4)); + if(!bIsValid) { + if(numcomps) { + FreeImage_OutputMessageProc(format_id, "Warning: image contains %d greyscale components. Only the first will be loaded.\n", numcomps); + numcomps = 1; + } else { + // unknown type + throw FI_MSG_ERROR_UNSUPPORTED_FORMAT; + } + } + + // create a new DIB + + if(image->comps[0].prec <= 8) { + switch(numcomps) { + case 1: + dib = FreeImage_Allocate(wrr, hrr, 8); + break; + case 3: + dib = FreeImage_Allocate(wrr, hrr, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + break; + case 4: + dib = FreeImage_Allocate(wrr, hrr, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + break; + } + } else if(image->comps[0].prec <= 16) { + switch(numcomps) { + case 1: + dib = FreeImage_AllocateT(FIT_UINT16, wrr, hrr); + break; + case 3: + dib = FreeImage_AllocateT(FIT_RGB16, wrr, hrr); + break; + case 4: + dib = FreeImage_AllocateT(FIT_RGBA16, wrr, hrr); + break; + } + } else { + throw FI_MSG_ERROR_UNSUPPORTED_FORMAT; + } + if(!dib) { + throw FI_MSG_ERROR_DIB_MEMORY; + } + + if(image->comps[0].prec <= 8) { + if(numcomps == 1) { + // 8-bit greyscale + // ---------------------------------------------------------- + + // build a greyscale palette + + RGBQUAD *pal = FreeImage_GetPalette(dib); + for (int i = 0; i < 256; i++) { + pal[i].rgbRed = (BYTE)i; + pal[i].rgbGreen = (BYTE)i; + pal[i].rgbBlue = (BYTE)i; + } + + // load pixel data + + unsigned pixel_count = 0; + + for(int y = 0; y < hrr; y++) { + BYTE *bits = FreeImage_GetScanLine(dib, hrr - 1 - y); + + for(int x = 0; x < wrr; x++) { + const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; + + int index = image->comps[0].data[pixel_pos]; + index += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + + bits[x] = (BYTE)index; + + pixel_count++; + } + } + } + else if(numcomps == 3) { + + // 24-bit RGB + // ---------------------------------------------------------- + + // load pixel data + + unsigned pixel_count = 0; + + for(int y = 0; y < hrr; y++) { + BYTE *bits = FreeImage_GetScanLine(dib, hrr - 1 - y); + + for(int x = 0; x < wrr; x++) { + const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; + + int r = image->comps[0].data[pixel_pos]; + r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + + int g = image->comps[1].data[pixel_pos]; + g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + + int b = image->comps[2].data[pixel_pos]; + b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); + + bits[FI_RGBA_RED] = (BYTE)r; + bits[FI_RGBA_GREEN] = (BYTE)g; + bits[FI_RGBA_BLUE] = (BYTE)b; + bits += 3; + + pixel_count++; + } + } + } + else if(numcomps == 4) { + + // 32-bit RGBA + // ---------------------------------------------------------- + + // load pixel data + + unsigned pixel_count = 0; + + for(int y = 0; y < hrr; y++) { + BYTE *bits = FreeImage_GetScanLine(dib, hrr - 1 - y); + + for(int x = 0; x < wrr; x++) { + const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; + + int r = image->comps[0].data[pixel_pos]; + r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + + int g = image->comps[1].data[pixel_pos]; + g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + + int b = image->comps[2].data[pixel_pos]; + b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); + + int a = image->comps[3].data[pixel_pos]; + a += (image->comps[3].sgnd ? 1 << (image->comps[3].prec - 1) : 0); + + bits[FI_RGBA_RED] = (BYTE)r; + bits[FI_RGBA_GREEN] = (BYTE)g; + bits[FI_RGBA_BLUE] = (BYTE)b; + bits[FI_RGBA_ALPHA] = (BYTE)a; + bits += 4; + + pixel_count++; + } + } + } + } + else if(image->comps[0].prec <= 16) { + if(numcomps == 1) { + // 16-bit greyscale + // ---------------------------------------------------------- + + // load pixel data + + unsigned pixel_count = 0; + + for(int y = 0; y < hrr; y++) { + unsigned short *bits = (unsigned short*)FreeImage_GetScanLine(dib, hrr - 1 - y); + + for(int x = 0; x < wrr; x++) { + const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; + + int index = image->comps[0].data[pixel_pos]; + index += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + + bits[x] = (unsigned short)index; + + pixel_count++; + } + } + } + else if(numcomps == 3) { + + // 48-bit RGB + // ---------------------------------------------------------- + + // load pixel data + + unsigned pixel_count = 0; + + for(int y = 0; y < hrr; y++) { + FIRGB16 *bits = (FIRGB16*)FreeImage_GetScanLine(dib, hrr - 1 - y); + + for(int x = 0; x < wrr; x++) { + const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; + + int r = image->comps[0].data[pixel_pos]; + r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + + int g = image->comps[1].data[pixel_pos]; + g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + + int b = image->comps[2].data[pixel_pos]; + b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); + + bits[x].red = (WORD)r; + bits[x].green = (WORD)g; + bits[x].blue = (WORD)b; + + pixel_count++; + } + } + } + else if(numcomps == 4) { + + // 64-bit RGBA + // ---------------------------------------------------------- + + // load pixel data + + unsigned pixel_count = 0; + + for(int y = 0; y < hrr; y++) { + FIRGBA16 *bits = (FIRGBA16*)FreeImage_GetScanLine(dib, hrr - 1 - y); + + for(int x = 0; x < wrr; x++) { + const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; + + int r = image->comps[0].data[pixel_pos]; + r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + + int g = image->comps[1].data[pixel_pos]; + g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + + int b = image->comps[2].data[pixel_pos]; + b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); + + int a = image->comps[3].data[pixel_pos]; + a += (image->comps[3].sgnd ? 1 << (image->comps[3].prec - 1) : 0); + + bits[x].red = (WORD)r; + bits[x].green = (WORD)g; + bits[x].blue = (WORD)b; + bits[x].alpha = (WORD)a; + + pixel_count++; + } + } + } + } + + return dib; + + } catch(const char *text) { + if(dib) FreeImage_Unload(dib); + FreeImage_OutputMessageProc(format_id, text); + return NULL; + } + +} + +/** +Convert a FIBITMAP to a OpenJPEG image +@param format_id Plugin ID +@param dib FreeImage image +@param parameters Compression parameters +@return Returns the converted image if successful, returns NULL otherwise +*/ +opj_image_t* FIBITMAPToJ2KImage(int format_id, FIBITMAP *dib, const opj_cparameters_t *parameters) { + int prec, numcomps, x, y, index; + OPJ_COLOR_SPACE color_space; + opj_image_cmptparm_t cmptparm[4]; // maximum of 4 components + opj_image_t *image = NULL; // image to encode + + try { + int w = FreeImage_GetWidth(dib); + int h = FreeImage_GetHeight(dib); + + // get image characteristics + FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); + + if(image_type == FIT_BITMAP) { + // standard image ... + prec = 8; + switch(FreeImage_GetColorType(dib)) { + case FIC_MINISBLACK: + numcomps = 1; + color_space = CLRSPC_GRAY; + break; + case FIC_RGB: + if(FreeImage_GetBPP(dib) == 32) { + // 32-bit image with a fully opaque layer + numcomps = 4; + color_space = CLRSPC_SRGB; + } else { + // 24-bit image + numcomps = 3; + color_space = CLRSPC_SRGB; + } + break; + case FIC_RGBALPHA: + numcomps = 4; + color_space = CLRSPC_SRGB; + break; + default: + return NULL; + } + } else { + // HDR image ... + prec = 16; + switch(image_type) { + case FIT_UINT16: + numcomps = 1; + color_space = CLRSPC_GRAY; + break; + case FIT_RGB16: + numcomps = 3; + color_space = CLRSPC_SRGB; + break; + case FIT_RGBA16: + numcomps = 4; + color_space = CLRSPC_SRGB; + break; + default: + return NULL; + } + } + + // initialize image components + memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); + for(int i = 0; i < numcomps; i++) { + cmptparm[i].dx = parameters->subsampling_dx; + cmptparm[i].dy = parameters->subsampling_dy; + cmptparm[i].w = w; + cmptparm[i].h = h; + cmptparm[i].prec = prec; + cmptparm[i].bpp = prec; + cmptparm[i].sgnd = 0; + } + // create the image + image = opj_image_create(numcomps, &cmptparm[0], color_space); + if(!image) { + throw FI_MSG_ERROR_DIB_MEMORY; + } + + // set image offset and reference grid + image->x0 = parameters->image_offset_x0; + image->y0 = parameters->image_offset_y0; + image->x1 = parameters->image_offset_x0 + (w - 1) * parameters->subsampling_dx + 1; + image->y1 = parameters->image_offset_y0 + (h - 1) * parameters->subsampling_dy + 1; + + // set image data + if(prec == 8) { + switch(numcomps) { + case 1: + index = 0; + for(y = 0; y < h; y++) { + BYTE *bits = FreeImage_GetScanLine(dib, h - 1 - y); + for(x = 0; x < w; x++) { + image->comps[0].data[index] = bits[x]; + index++; + } + } + break; + case 3: + index = 0; + for(y = 0; y < h; y++) { + BYTE *bits = FreeImage_GetScanLine(dib, h - 1 - y); + for(x = 0; x < w; x++) { + image->comps[0].data[index] = bits[FI_RGBA_RED]; + image->comps[1].data[index] = bits[FI_RGBA_GREEN]; + image->comps[2].data[index] = bits[FI_RGBA_BLUE]; + bits += 3; + index++; + } + } + break; + case 4: + index = 0; + for(y = 0; y < h; y++) { + BYTE *bits = FreeImage_GetScanLine(dib, h - 1 - y); + for(x = 0; x < w; x++) { + image->comps[0].data[index] = bits[FI_RGBA_RED]; + image->comps[1].data[index] = bits[FI_RGBA_GREEN]; + image->comps[2].data[index] = bits[FI_RGBA_BLUE]; + image->comps[3].data[index] = bits[FI_RGBA_ALPHA]; + bits += 4; + index++; + } + } + break; + } + } + else if(prec == 16) { + switch(numcomps) { + case 1: + index = 0; + for(y = 0; y < h; y++) { + WORD *bits = (WORD*)FreeImage_GetScanLine(dib, h - 1 - y); + for(x = 0; x < w; x++) { + image->comps[0].data[index] = bits[x]; + index++; + } + } + break; + case 3: + index = 0; + for(y = 0; y < h; y++) { + FIRGB16 *bits = (FIRGB16*)FreeImage_GetScanLine(dib, h - 1 - y); + for(x = 0; x < w; x++) { + image->comps[0].data[index] = bits[x].red; + image->comps[1].data[index] = bits[x].green; + image->comps[2].data[index] = bits[x].blue; + index++; + } + } + break; + case 4: + index = 0; + for(y = 0; y < h; y++) { + FIRGBA16 *bits = (FIRGBA16*)FreeImage_GetScanLine(dib, h - 1 - y); + for(x = 0; x < w; x++) { + image->comps[0].data[index] = bits[x].red; + image->comps[1].data[index] = bits[x].green; + image->comps[2].data[index] = bits[x].blue; + image->comps[3].data[index] = bits[x].alpha; + index++; + } + } + break; + } + } + + return image; + + } catch (const char *text) { + if(image) opj_image_destroy(image); + FreeImage_OutputMessageProc(format_id, text); + return NULL; + } +} diff --git a/Source/FreeImage/MultiPage.cpp b/Source/FreeImage/MultiPage.cpp index 3bc7b70..6db64be 100644 --- a/Source/FreeImage/MultiPage.cpp +++ b/Source/FreeImage/MultiPage.cpp @@ -1,974 +1,974 @@ -// ========================================================== -// Multi-Page functions -// -// Design and implementation by -// - Floris van den Berg (flvdberg@wxs.nl) -// - Laurent Rocher (rocherl@club-internet.fr) -// - Steve Johnson (steve@parisgroup.net) -// - Petr Pytelka (pyta@lightcomp.com) -// - Hervé Drolon (drolon@infonie.fr) -// - Vadim Alexandrov (vadimalexandrov@users.sourceforge.net -// - Martin Dyring-Andersen (mda@spamfighter.com) -// - Volodymyr Goncharov (volodymyr.goncharov@gmail.com) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#ifdef _MSC_VER -#pragma warning (disable : 4786) // identifier was truncated to 'number' characters -#endif - -#include "CacheFile.h" -#include "FreeImageIO.h" -#include "Plugin.h" -#include "Utilities.h" -#include "FreeImage.h" - -// ---------------------------------------------------------- - -enum BlockType { BLOCK_CONTINUEUS, BLOCK_REFERENCE }; - -// ---------------------------------------------------------- - -struct BlockTypeS { - BlockType m_type; - - BlockTypeS(BlockType type) : m_type(type) { - } - virtual ~BlockTypeS() {} -}; - -struct BlockContinueus : public BlockTypeS { - int m_start; - int m_end; - - BlockContinueus(int s, int e) : BlockTypeS(BLOCK_CONTINUEUS), - m_start(s), - m_end(e) { - } -}; - -struct BlockReference : public BlockTypeS { - int m_reference; - int m_size; - - BlockReference(int r, int size) : BlockTypeS(BLOCK_REFERENCE), - m_reference(r), - m_size(size) { - } -}; - -// ---------------------------------------------------------- - -typedef std::list BlockList; -typedef std::list::iterator BlockListIterator; - -// ---------------------------------------------------------- - -FI_STRUCT (MULTIBITMAPHEADER) { - PluginNode *node; - FREE_IMAGE_FORMAT fif; - FreeImageIO *io; - fi_handle handle; - CacheFile *m_cachefile; - std::map locked_pages; - BOOL changed; - int page_count; - BlockList m_blocks; - char *m_filename; - BOOL read_only; - FREE_IMAGE_FORMAT cache_fif; - int load_flags; -}; - -// ===================================================================== -// Helper functions -// ===================================================================== - -inline void -ReplaceExtension(std::string& dst_filename, const std::string& src_filename, const std::string& dst_extension) { - size_t lastDot = src_filename.find_last_of('.'); - if (lastDot == std::string::npos) { - dst_filename = src_filename; - dst_filename += "."; - dst_filename += dst_extension; - } - else { - dst_filename = src_filename.substr(0, lastDot + 1); - dst_filename += dst_extension; - } -} - -// ===================================================================== -// Internal Multipage functions -// ===================================================================== - -inline MULTIBITMAPHEADER * -FreeImage_GetMultiBitmapHeader(FIMULTIBITMAP *bitmap) { - return (MULTIBITMAPHEADER *)bitmap->data; -} - -static BlockListIterator DLL_CALLCONV -FreeImage_FindBlock(FIMULTIBITMAP *bitmap, int position) { - assert(NULL != bitmap); - - MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); - - // step 1: find the block that matches the given position - - int prev_count = 0; - int count = 0; - BlockListIterator i; - BlockTypeS *current_block = NULL; - - for (i = header->m_blocks.begin(); i != header->m_blocks.end(); ++i) { - prev_count = count; - - switch((*i)->m_type) { - case BLOCK_CONTINUEUS : - count += ((BlockContinueus *)(*i))->m_end - ((BlockContinueus *)(*i))->m_start + 1; - break; - - case BLOCK_REFERENCE : - count++; - break; - } - - current_block = *i; - - if (count > position) - break; - } - - // step 2: make sure we found the node. from here it gets a little complicated: - // * if the block is there, just return it - // * if the block is a series of blocks, split it in max 3 new blocks - // and return the splitted block - - if ((current_block) && (count > position)) { - switch(current_block->m_type) { - case BLOCK_REFERENCE : - return i; - - case BLOCK_CONTINUEUS : - { - BlockContinueus *block = (BlockContinueus *)current_block; - - if (block->m_start != block->m_end) { - int item = block->m_start + (position - prev_count); - - // left part - - if (item != block->m_start) { - BlockContinueus *block_a = new BlockContinueus(block->m_start, item - 1); - header->m_blocks.insert(i, (BlockTypeS *)block_a); - } - - // middle part - - BlockContinueus *block_b = new BlockContinueus(item, item); - BlockListIterator block_target = header->m_blocks.insert(i, (BlockTypeS *)block_b); - - // right part - - if (item != block->m_end) { - BlockContinueus *block_c = new BlockContinueus(item + 1, block->m_end); - header->m_blocks.insert(i, (BlockTypeS *)block_c); - } - - // remove the old block that was just splitted - - header->m_blocks.remove((BlockTypeS *)block); - delete block; - - // return the splitted block - - return block_target; - } - - return i; - } - } - } - // we should never go here ... - assert(false); - return header->m_blocks.end(); -} - -int DLL_CALLCONV -FreeImage_InternalGetPageCount(FIMULTIBITMAP *bitmap) { - if (bitmap) { - if (((MULTIBITMAPHEADER *)bitmap->data)->handle) { - MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); - - header->io->seek_proc(header->handle, 0, SEEK_SET); - - void *data = FreeImage_Open(header->node, header->io, header->handle, TRUE); - - int page_count = (header->node->m_plugin->pagecount_proc != NULL) ? header->node->m_plugin->pagecount_proc(header->io, header->handle, data) : 1; - - FreeImage_Close(header->node, header->io, header->handle, data); - - return page_count; - } - } - - return 0; -} - -// ===================================================================== -// Multipage functions -// ===================================================================== - -FIMULTIBITMAP * DLL_CALLCONV -FreeImage_OpenMultiBitmap(FREE_IMAGE_FORMAT fif, const char *filename, BOOL create_new, BOOL read_only, BOOL keep_cache_in_memory, int flags) { - - FILE *handle = NULL; - try { - // sanity check on the parameters - - if (create_new) { - read_only = FALSE; - } - - // retrieve the plugin list to find the node belonging to this plugin - - PluginList *list = FreeImage_GetPluginList(); - - if (list) { - PluginNode *node = list->FindNodeFromFIF(fif); - - if (node) { - std::auto_ptr io (new FreeImageIO); - - SetDefaultIO(io.get()); - - if (!create_new) { - handle = fopen(filename, "rb"); - if (handle == NULL) { - return NULL; - } - } - - std::auto_ptr bitmap (new FIMULTIBITMAP); - std::auto_ptr header (new MULTIBITMAPHEADER); - header->m_filename = new char[strlen(filename) + 1]; - strcpy(header->m_filename, filename); - header->node = node; - header->fif = fif; - header->io = io.get (); - header->handle = handle; - header->changed = FALSE; - header->read_only = read_only; - header->m_cachefile = NULL; - header->cache_fif = fif; - header->load_flags = flags; - - // store the MULTIBITMAPHEADER in the surrounding FIMULTIBITMAP structure - - bitmap->data = header.get(); - - // cache the page count - - header->page_count = FreeImage_InternalGetPageCount(bitmap.get()); - - // allocate a continueus block to describe the bitmap - - if (!create_new) { - header->m_blocks.push_back((BlockTypeS *)new BlockContinueus(0, header->page_count - 1)); - } - - // set up the cache - - if (!read_only) { - std::string cache_name; - ReplaceExtension(cache_name, filename, "ficache"); - - std::auto_ptr cache_file (new CacheFile(cache_name, keep_cache_in_memory)); - - if (cache_file->open()) { - // we can use release() as std::bad_alloc won't be thrown from here on - header->m_cachefile = cache_file.release(); - } else { - // an error occured ... - fclose(handle); - return NULL; - } - } - // return the multibitmap - // std::bad_alloc won't be thrown from here on - header.release(); // now owned by bitmap - io.release(); // now owned by bitmap - return bitmap.release(); // now owned by caller - } - } - } catch (std::bad_alloc &) { - /** @todo report error */ - } - if (handle) - fclose(handle); - return NULL; -} - -FIMULTIBITMAP * DLL_CALLCONV -FreeImage_OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags) { - try { - BOOL read_only = FALSE; // modifications (if any) will be stored into the memory cache - - if (io && handle) { - - // retrieve the plugin list to find the node belonging to this plugin - PluginList *list = FreeImage_GetPluginList(); - - if (list) { - PluginNode *node = list->FindNodeFromFIF(fif); - - if (node) { - std::auto_ptr bitmap (new FIMULTIBITMAP); - std::auto_ptr header (new MULTIBITMAPHEADER); - std::auto_ptr tmp_io (new FreeImageIO (*io)); - header->io = tmp_io.get(); - header->m_filename = NULL; - header->node = node; - header->fif = fif; - header->handle = handle; - header->changed = FALSE; - header->read_only = read_only; - header->m_cachefile = NULL; - header->cache_fif = fif; - header->load_flags = flags; - - // store the MULTIBITMAPHEADER in the surrounding FIMULTIBITMAP structure - - bitmap->data = header.get(); - - // cache the page count - - header->page_count = FreeImage_InternalGetPageCount(bitmap.get()); - - // allocate a continueus block to describe the bitmap - - header->m_blocks.push_back((BlockTypeS *)new BlockContinueus(0, header->page_count - 1)); - - if (!read_only) { - // set up the cache - std::auto_ptr cache_file (new CacheFile("", TRUE)); - - if (cache_file->open()) { - header->m_cachefile = cache_file.release(); - } - } - tmp_io.release(); - header.release(); - return bitmap.release(); - } - } - } - } catch (std::bad_alloc &) { - /** @todo report error */ - } - return NULL; -} - -BOOL DLL_CALLCONV -FreeImage_SaveMultiBitmapToHandle(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, FreeImageIO *io, fi_handle handle, int flags) { - if(!bitmap || !bitmap->data || !io || !handle) { - return FALSE; - } - - BOOL success = TRUE; - - // retrieve the plugin list to find the node belonging to this plugin - PluginList *list = FreeImage_GetPluginList(); - - if (list) { - PluginNode *node = list->FindNodeFromFIF(fif); - - if(node) { - MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); - - // dst data - void *data = FreeImage_Open(node, io, handle, FALSE); - // src data - void *data_read = NULL; - - if(header->handle) { - // open src - header->io->seek_proc(header->handle, 0, SEEK_SET); - data_read = FreeImage_Open(header->node, header->io, header->handle, TRUE); - } - - // write all the pages to the file using handle and io - - int count = 0; - - for (BlockListIterator i = header->m_blocks.begin(); i != header->m_blocks.end(); i++) { - if (success) { - switch((*i)->m_type) { - case BLOCK_CONTINUEUS: - { - BlockContinueus *block = (BlockContinueus *)(*i); - - for (int j = block->m_start; j <= block->m_end; j++) { - - // load the original source data - FIBITMAP *dib = header->node->m_plugin->load_proc(header->io, header->handle, j, header->load_flags, data_read); - - // save the data - success = node->m_plugin->save_proc(io, dib, handle, count, flags, data); - count++; - - FreeImage_Unload(dib); - } - - break; - } - - case BLOCK_REFERENCE: - { - BlockReference *ref = (BlockReference *)(*i); - - // read the compressed data - - BYTE *compressed_data = (BYTE*)malloc(ref->m_size * sizeof(BYTE)); - - header->m_cachefile->readFile((BYTE *)compressed_data, ref->m_reference, ref->m_size); - - // uncompress the data - - FIMEMORY *hmem = FreeImage_OpenMemory(compressed_data, ref->m_size); - FIBITMAP *dib = FreeImage_LoadFromMemory(header->cache_fif, hmem, 0); - FreeImage_CloseMemory(hmem); - - // get rid of the buffer - free(compressed_data); - - // save the data - - success = node->m_plugin->save_proc(io, dib, handle, count, flags, data); - count++; - - // unload the dib - - FreeImage_Unload(dib); - - break; - } - } - } else { - break; - } - } - - // close the files - - FreeImage_Close(header->node, header->io, header->handle, data_read); - - FreeImage_Close(node, io, handle, data); - - return success; - } - } - - return FALSE; -} - - -BOOL DLL_CALLCONV -FreeImage_CloseMultiBitmap(FIMULTIBITMAP *bitmap, int flags) { - if (bitmap) { - BOOL success = TRUE; - - if (bitmap->data) { - MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); - - // saves changes only of images loaded directly from a file - if (header->changed && header->m_filename) { - try { - // open a temp file - - std::string spool_name; - - ReplaceExtension(spool_name, header->m_filename, "fispool"); - - // open the spool file and the source file - - FILE *f = fopen(spool_name.c_str(), "w+b"); - - // saves changes - if (f == NULL) { - FreeImage_OutputMessageProc(header->fif, "Failed to open %s, %s", spool_name.c_str(), strerror(errno)); - success = FALSE; - } else { - success = FreeImage_SaveMultiBitmapToHandle(header->fif, bitmap, header->io, (fi_handle)f, flags); - - // close the files - - if (fclose(f) != 0) { - success = FALSE; - FreeImage_OutputMessageProc(header->fif, "Failed to close %s, %s", spool_name.c_str(), strerror(errno)); - } - } - if (header->handle) { - fclose((FILE *)header->handle); - } - - // applies changes to the destination file - - if (success) { - remove(header->m_filename); - success = (rename(spool_name.c_str(), header->m_filename) == 0) ? TRUE:FALSE; - if(!success) { - FreeImage_OutputMessageProc(header->fif, "Failed to rename %s to %s", spool_name.c_str(), header->m_filename); - } - } else { - remove(spool_name.c_str()); - } - } catch (std::bad_alloc &) { - success = FALSE; - } - - } else { - if (header->handle && header->m_filename) { - fclose((FILE *)header->handle); - } - } - - // clear the blocks list - - for (BlockListIterator i = header->m_blocks.begin(); i != header->m_blocks.end(); ++i) { - delete *i; - } - - // flush and dispose the cache - - if (header->m_cachefile) { - header->m_cachefile->close(); - delete header->m_cachefile; - } - - // delete the last open bitmaps - - while (!header->locked_pages.empty()) { - FreeImage_Unload(header->locked_pages.begin()->first); - - header->locked_pages.erase(header->locked_pages.begin()->first); - } - - // get rid of the IO structure - - delete header->io; - - // delete the filename - - if(header->m_filename) { - delete[] header->m_filename; - } - - // delete the FIMULTIBITMAPHEADER - - delete header; - } - - delete bitmap; - - return success; - } - - return FALSE; -} - -int DLL_CALLCONV -FreeImage_GetPageCount(FIMULTIBITMAP *bitmap) { - if (bitmap) { - MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); - - if (header->page_count == -1) { - header->page_count = 0; - - for (BlockListIterator i = header->m_blocks.begin(); i != header->m_blocks.end(); ++i) { - switch((*i)->m_type) { - case BLOCK_CONTINUEUS : - header->page_count += ((BlockContinueus *)(*i))->m_end - ((BlockContinueus *)(*i))->m_start + 1; - break; - - case BLOCK_REFERENCE : - header->page_count++; - break; - } - } - } - - return header->page_count; - } - - return 0; -} - -static BlockReference* -FreeImage_SavePageToBlock(MULTIBITMAPHEADER *header, FIBITMAP *data) { - if (header->read_only || !header->locked_pages.empty()) - return NULL; - - DWORD compressed_size = 0; - BYTE *compressed_data = NULL; - - // compress the bitmap data - - // open a memory handle - FIMEMORY *hmem = FreeImage_OpenMemory(); - if(hmem==NULL) return NULL; - // save the file to memory - if(!FreeImage_SaveToMemory(header->cache_fif, data, hmem, 0)) { - FreeImage_CloseMemory(hmem); - return NULL; - } - // get the buffer from the memory stream - if(!FreeImage_AcquireMemory(hmem, &compressed_data, &compressed_size)) { - FreeImage_CloseMemory(hmem); - return NULL; - } - - // write the compressed data to the cache - int ref = header->m_cachefile->writeFile(compressed_data, compressed_size); - // get rid of the compressed data - FreeImage_CloseMemory(hmem); - - return new(std::nothrow) BlockReference(ref, compressed_size); -} - -void DLL_CALLCONV -FreeImage_AppendPage(FIMULTIBITMAP *bitmap, FIBITMAP *data) { - if (!bitmap || !data) - return; - - MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); - - BlockReference *block = FreeImage_SavePageToBlock(header, data); - if(block==NULL) return; - - // add the block - header->m_blocks.push_back((BlockTypeS *)block); - header->changed = TRUE; - header->page_count = -1; -} - -void DLL_CALLCONV -FreeImage_InsertPage(FIMULTIBITMAP *bitmap, int page, FIBITMAP *data) { - if (!bitmap || !data) - return; - - if (page >= FreeImage_GetPageCount(bitmap)) - return; - - MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); - - BlockReference *block = FreeImage_SavePageToBlock(header, data); - if(block==NULL) return; - - // add a block - if (page > 0) { - BlockListIterator block_source = FreeImage_FindBlock(bitmap, page); - - header->m_blocks.insert(block_source, (BlockTypeS *)block); - } else { - header->m_blocks.push_front((BlockTypeS *)block); - } - - header->changed = TRUE; - header->page_count = -1; -} - -void DLL_CALLCONV -FreeImage_DeletePage(FIMULTIBITMAP *bitmap, int page) { - if (bitmap) { - MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); - - if ((!header->read_only) && (header->locked_pages.empty())) { - if (FreeImage_GetPageCount(bitmap) > 1) { - BlockListIterator i = FreeImage_FindBlock(bitmap, page); - - if (i != header->m_blocks.end()) { - switch((*i)->m_type) { - case BLOCK_CONTINUEUS : - delete *i; - header->m_blocks.erase(i); - break; - - case BLOCK_REFERENCE : - header->m_cachefile->deleteFile(((BlockReference *)(*i))->m_reference); - delete *i; - header->m_blocks.erase(i); - break; - } - - header->changed = TRUE; - header->page_count = -1; - } - } - } - } -} - - -FIBITMAP * DLL_CALLCONV -FreeImage_LockPage(FIMULTIBITMAP *bitmap, int page) { - if (bitmap) { - MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); - - // only lock if the page wasn't locked before... - - for (std::map::iterator i = header->locked_pages.begin(); i != header->locked_pages.end(); ++i) { - if (i->second == page) { - return NULL; - } - } - - // open the bitmap - - header->io->seek_proc(header->handle, 0, SEEK_SET); - - void *data = FreeImage_Open(header->node, header->io, header->handle, TRUE); - - // load the bitmap data - - if (data != NULL) { - FIBITMAP *dib = (header->node->m_plugin->load_proc != NULL) ? header->node->m_plugin->load_proc(header->io, header->handle, page, header->load_flags, data) : NULL; - - // close the file - - FreeImage_Close(header->node, header->io, header->handle, data); - - // if there was still another bitmap open, get rid of it - - if (dib) { - header->locked_pages[dib] = page; - - return dib; - } - - return NULL; - } - } - - return NULL; -} - -void DLL_CALLCONV -FreeImage_UnlockPage(FIMULTIBITMAP *bitmap, FIBITMAP *page, BOOL changed) { - if ((bitmap) && (page)) { - MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); - - // find out if the page we try to unlock is actually locked... - - if (header->locked_pages.find(page) != header->locked_pages.end()) { - // store the bitmap compressed in the cache for later writing - - if (changed && !header->read_only) { - header->changed = TRUE; - - // cut loose the block from the rest - - BlockListIterator i = FreeImage_FindBlock(bitmap, header->locked_pages[page]); - - // compress the data - - DWORD compressed_size = 0; - BYTE *compressed_data = NULL; - - // open a memory handle - FIMEMORY *hmem = FreeImage_OpenMemory(); - // save the page to memory - FreeImage_SaveToMemory(header->cache_fif, page, hmem, 0); - // get the buffer from the memory stream - FreeImage_AcquireMemory(hmem, &compressed_data, &compressed_size); - - // write the data to the cache - - switch ((*i)->m_type) { - case BLOCK_CONTINUEUS : - { - int iPage = header->m_cachefile->writeFile(compressed_data, compressed_size); - - delete (*i); - - *i = (BlockTypeS *)new BlockReference(iPage, compressed_size); - - break; - } - - case BLOCK_REFERENCE : - { - BlockReference *reference = (BlockReference *)(*i); - - header->m_cachefile->deleteFile(reference->m_reference); - - delete (*i); - - int iPage = header->m_cachefile->writeFile(compressed_data, compressed_size); - - *i = (BlockTypeS *)new BlockReference(iPage, compressed_size); - - break; - } - } - - // get rid of the compressed data - - FreeImage_CloseMemory(hmem); - } - - // reset the locked page so that another page can be locked - - FreeImage_Unload(page); - - header->locked_pages.erase(page); - } - } -} - -BOOL DLL_CALLCONV -FreeImage_MovePage(FIMULTIBITMAP *bitmap, int target, int source) { - if (bitmap) { - MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); - - if ((!header->read_only) && (header->locked_pages.empty())) { - if ((target != source) && ((target >= 0) && (target < FreeImage_GetPageCount(bitmap))) && ((source >= 0) && (source < FreeImage_GetPageCount(bitmap)))) { - BlockListIterator block_source = FreeImage_FindBlock(bitmap, target); - BlockListIterator block_target = FreeImage_FindBlock(bitmap, source); - - header->m_blocks.insert(block_target, *block_source); - header->m_blocks.erase(block_source); - - header->changed = TRUE; - - return TRUE; - } - } - } - - return FALSE; -} - -BOOL DLL_CALLCONV -FreeImage_GetLockedPageNumbers(FIMULTIBITMAP *bitmap, int *pages, int *count) { - if ((bitmap) && (count)) { - MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); - - if ((pages == NULL) || (*count == 0)) { - *count = (int)header->locked_pages.size(); - } else { - int c = 0; - - for (std::map::iterator i = header->locked_pages.begin(); i != header->locked_pages.end(); ++i) { - pages[c] = i->second; - - c++; - - if (c == *count) - break; - } - } - - return TRUE; - } - - return FALSE; -} - -// ===================================================================== -// Memory IO Multipage functions -// ===================================================================== - -FIMULTIBITMAP * DLL_CALLCONV -FreeImage_LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream, int flags) { - BOOL read_only = FALSE; // modifications (if any) will be stored into the memory cache - - // retrieve the plugin list to find the node belonging to this plugin - - PluginList *list = FreeImage_GetPluginList(); - - if (list) { - PluginNode *node = list->FindNodeFromFIF(fif); - - if (node) { - FreeImageIO *io = new(std::nothrow) FreeImageIO; - - if (io) { - SetMemoryIO(io); - - FIMULTIBITMAP *bitmap = new(std::nothrow) FIMULTIBITMAP; - - if (bitmap) { - MULTIBITMAPHEADER *header = new(std::nothrow) MULTIBITMAPHEADER; - - if (header) { - header->m_filename = NULL; - header->node = node; - header->fif = fif; - header->io = io; - header->handle = (fi_handle)stream; - header->changed = FALSE; - header->read_only = read_only; - header->m_cachefile = NULL; - header->cache_fif = fif; - header->load_flags = flags; - - // store the MULTIBITMAPHEADER in the surrounding FIMULTIBITMAP structure - - bitmap->data = header; - - // cache the page count - - header->page_count = FreeImage_InternalGetPageCount(bitmap); - - // allocate a continueus block to describe the bitmap - - header->m_blocks.push_back((BlockTypeS *)new BlockContinueus(0, header->page_count - 1)); - - if (!read_only) { - // set up the cache - CacheFile *cache_file = new(std::nothrow) CacheFile("", TRUE); - - if (cache_file && cache_file->open()) { - header->m_cachefile = cache_file; - } - } - - return bitmap; - } - - delete bitmap; - } - - delete io; - } - } - } - - return NULL; -} - -BOOL DLL_CALLCONV -FreeImage_SaveMultiBitmapToMemory(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, FIMEMORY *stream, int flags) { - if (stream && stream->data) { - FreeImageIO io; - SetMemoryIO(&io); - - return FreeImage_SaveMultiBitmapToHandle(fif, bitmap, &io, (fi_handle)stream, flags); - } - - return FALSE; -} +// ========================================================== +// Multi-Page functions +// +// Design and implementation by +// - Floris van den Berg (flvdberg@wxs.nl) +// - Laurent Rocher (rocherl@club-internet.fr) +// - Steve Johnson (steve@parisgroup.net) +// - Petr Pytelka (pyta@lightcomp.com) +// - Hervé Drolon (drolon@infonie.fr) +// - Vadim Alexandrov (vadimalexandrov@users.sourceforge.net +// - Martin Dyring-Andersen (mda@spamfighter.com) +// - Volodymyr Goncharov (volodymyr.goncharov@gmail.com) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#ifdef _MSC_VER +#pragma warning (disable : 4786) // identifier was truncated to 'number' characters +#endif + +#include "CacheFile.h" +#include "FreeImageIO.h" +#include "Plugin.h" +#include "Utilities.h" +#include "FreeImage.h" + +// ---------------------------------------------------------- + +enum BlockType { BLOCK_CONTINUEUS, BLOCK_REFERENCE }; + +// ---------------------------------------------------------- + +struct BlockTypeS { + BlockType m_type; + + BlockTypeS(BlockType type) : m_type(type) { + } + virtual ~BlockTypeS() {} +}; + +struct BlockContinueus : public BlockTypeS { + int m_start; + int m_end; + + BlockContinueus(int s, int e) : BlockTypeS(BLOCK_CONTINUEUS), + m_start(s), + m_end(e) { + } +}; + +struct BlockReference : public BlockTypeS { + int m_reference; + int m_size; + + BlockReference(int r, int size) : BlockTypeS(BLOCK_REFERENCE), + m_reference(r), + m_size(size) { + } +}; + +// ---------------------------------------------------------- + +typedef std::list BlockList; +typedef std::list::iterator BlockListIterator; + +// ---------------------------------------------------------- + +FI_STRUCT (MULTIBITMAPHEADER) { + PluginNode *node; + FREE_IMAGE_FORMAT fif; + FreeImageIO *io; + fi_handle handle; + CacheFile *m_cachefile; + std::map locked_pages; + BOOL changed; + int page_count; + BlockList m_blocks; + char *m_filename; + BOOL read_only; + FREE_IMAGE_FORMAT cache_fif; + int load_flags; +}; + +// ===================================================================== +// Helper functions +// ===================================================================== + +inline void +ReplaceExtension(std::string& dst_filename, const std::string& src_filename, const std::string& dst_extension) { + size_t lastDot = src_filename.find_last_of('.'); + if (lastDot == std::string::npos) { + dst_filename = src_filename; + dst_filename += "."; + dst_filename += dst_extension; + } + else { + dst_filename = src_filename.substr(0, lastDot + 1); + dst_filename += dst_extension; + } +} + +// ===================================================================== +// Internal Multipage functions +// ===================================================================== + +inline MULTIBITMAPHEADER * +FreeImage_GetMultiBitmapHeader(FIMULTIBITMAP *bitmap) { + return (MULTIBITMAPHEADER *)bitmap->data; +} + +static BlockListIterator DLL_CALLCONV +FreeImage_FindBlock(FIMULTIBITMAP *bitmap, int position) { + assert(NULL != bitmap); + + MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); + + // step 1: find the block that matches the given position + + int prev_count = 0; + int count = 0; + BlockListIterator i; + BlockTypeS *current_block = NULL; + + for (i = header->m_blocks.begin(); i != header->m_blocks.end(); ++i) { + prev_count = count; + + switch((*i)->m_type) { + case BLOCK_CONTINUEUS : + count += ((BlockContinueus *)(*i))->m_end - ((BlockContinueus *)(*i))->m_start + 1; + break; + + case BLOCK_REFERENCE : + count++; + break; + } + + current_block = *i; + + if (count > position) + break; + } + + // step 2: make sure we found the node. from here it gets a little complicated: + // * if the block is there, just return it + // * if the block is a series of blocks, split it in max 3 new blocks + // and return the splitted block + + if ((current_block) && (count > position)) { + switch(current_block->m_type) { + case BLOCK_REFERENCE : + return i; + + case BLOCK_CONTINUEUS : + { + BlockContinueus *block = (BlockContinueus *)current_block; + + if (block->m_start != block->m_end) { + int item = block->m_start + (position - prev_count); + + // left part + + if (item != block->m_start) { + BlockContinueus *block_a = new BlockContinueus(block->m_start, item - 1); + header->m_blocks.insert(i, (BlockTypeS *)block_a); + } + + // middle part + + BlockContinueus *block_b = new BlockContinueus(item, item); + BlockListIterator block_target = header->m_blocks.insert(i, (BlockTypeS *)block_b); + + // right part + + if (item != block->m_end) { + BlockContinueus *block_c = new BlockContinueus(item + 1, block->m_end); + header->m_blocks.insert(i, (BlockTypeS *)block_c); + } + + // remove the old block that was just splitted + + header->m_blocks.remove((BlockTypeS *)block); + delete block; + + // return the splitted block + + return block_target; + } + + return i; + } + } + } + // we should never go here ... + assert(false); + return header->m_blocks.end(); +} + +int DLL_CALLCONV +FreeImage_InternalGetPageCount(FIMULTIBITMAP *bitmap) { + if (bitmap) { + if (((MULTIBITMAPHEADER *)bitmap->data)->handle) { + MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); + + header->io->seek_proc(header->handle, 0, SEEK_SET); + + void *data = FreeImage_Open(header->node, header->io, header->handle, TRUE); + + int page_count = (header->node->m_plugin->pagecount_proc != NULL) ? header->node->m_plugin->pagecount_proc(header->io, header->handle, data) : 1; + + FreeImage_Close(header->node, header->io, header->handle, data); + + return page_count; + } + } + + return 0; +} + +// ===================================================================== +// Multipage functions +// ===================================================================== + +FIMULTIBITMAP * DLL_CALLCONV +FreeImage_OpenMultiBitmap(FREE_IMAGE_FORMAT fif, const char *filename, BOOL create_new, BOOL read_only, BOOL keep_cache_in_memory, int flags) { + + FILE *handle = NULL; + try { + // sanity check on the parameters + + if (create_new) { + read_only = FALSE; + } + + // retrieve the plugin list to find the node belonging to this plugin + + PluginList *list = FreeImage_GetPluginList(); + + if (list) { + PluginNode *node = list->FindNodeFromFIF(fif); + + if (node) { + std::auto_ptr io (new FreeImageIO); + + SetDefaultIO(io.get()); + + if (!create_new) { + handle = fopen(filename, "rb"); + if (handle == NULL) { + return NULL; + } + } + + std::auto_ptr bitmap (new FIMULTIBITMAP); + std::auto_ptr header (new MULTIBITMAPHEADER); + header->m_filename = new char[strlen(filename) + 1]; + strcpy(header->m_filename, filename); + header->node = node; + header->fif = fif; + header->io = io.get (); + header->handle = handle; + header->changed = FALSE; + header->read_only = read_only; + header->m_cachefile = NULL; + header->cache_fif = fif; + header->load_flags = flags; + + // store the MULTIBITMAPHEADER in the surrounding FIMULTIBITMAP structure + + bitmap->data = header.get(); + + // cache the page count + + header->page_count = FreeImage_InternalGetPageCount(bitmap.get()); + + // allocate a continueus block to describe the bitmap + + if (!create_new) { + header->m_blocks.push_back((BlockTypeS *)new BlockContinueus(0, header->page_count - 1)); + } + + // set up the cache + + if (!read_only) { + std::string cache_name; + ReplaceExtension(cache_name, filename, "ficache"); + + std::auto_ptr cache_file (new CacheFile(cache_name, keep_cache_in_memory)); + + if (cache_file->open()) { + // we can use release() as std::bad_alloc won't be thrown from here on + header->m_cachefile = cache_file.release(); + } else { + // an error occured ... + fclose(handle); + return NULL; + } + } + // return the multibitmap + // std::bad_alloc won't be thrown from here on + header.release(); // now owned by bitmap + io.release(); // now owned by bitmap + return bitmap.release(); // now owned by caller + } + } + } catch (std::bad_alloc &) { + /** @todo report error */ + } + if (handle) + fclose(handle); + return NULL; +} + +FIMULTIBITMAP * DLL_CALLCONV +FreeImage_OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags) { + try { + BOOL read_only = FALSE; // modifications (if any) will be stored into the memory cache + + if (io && handle) { + + // retrieve the plugin list to find the node belonging to this plugin + PluginList *list = FreeImage_GetPluginList(); + + if (list) { + PluginNode *node = list->FindNodeFromFIF(fif); + + if (node) { + std::auto_ptr bitmap (new FIMULTIBITMAP); + std::auto_ptr header (new MULTIBITMAPHEADER); + std::auto_ptr tmp_io (new FreeImageIO (*io)); + header->io = tmp_io.get(); + header->m_filename = NULL; + header->node = node; + header->fif = fif; + header->handle = handle; + header->changed = FALSE; + header->read_only = read_only; + header->m_cachefile = NULL; + header->cache_fif = fif; + header->load_flags = flags; + + // store the MULTIBITMAPHEADER in the surrounding FIMULTIBITMAP structure + + bitmap->data = header.get(); + + // cache the page count + + header->page_count = FreeImage_InternalGetPageCount(bitmap.get()); + + // allocate a continueus block to describe the bitmap + + header->m_blocks.push_back((BlockTypeS *)new BlockContinueus(0, header->page_count - 1)); + + if (!read_only) { + // set up the cache + std::auto_ptr cache_file (new CacheFile("", TRUE)); + + if (cache_file->open()) { + header->m_cachefile = cache_file.release(); + } + } + tmp_io.release(); + header.release(); + return bitmap.release(); + } + } + } + } catch (std::bad_alloc &) { + /** @todo report error */ + } + return NULL; +} + +BOOL DLL_CALLCONV +FreeImage_SaveMultiBitmapToHandle(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, FreeImageIO *io, fi_handle handle, int flags) { + if(!bitmap || !bitmap->data || !io || !handle) { + return FALSE; + } + + BOOL success = TRUE; + + // retrieve the plugin list to find the node belonging to this plugin + PluginList *list = FreeImage_GetPluginList(); + + if (list) { + PluginNode *node = list->FindNodeFromFIF(fif); + + if(node) { + MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); + + // dst data + void *data = FreeImage_Open(node, io, handle, FALSE); + // src data + void *data_read = NULL; + + if(header->handle) { + // open src + header->io->seek_proc(header->handle, 0, SEEK_SET); + data_read = FreeImage_Open(header->node, header->io, header->handle, TRUE); + } + + // write all the pages to the file using handle and io + + int count = 0; + + for (BlockListIterator i = header->m_blocks.begin(); i != header->m_blocks.end(); i++) { + if (success) { + switch((*i)->m_type) { + case BLOCK_CONTINUEUS: + { + BlockContinueus *block = (BlockContinueus *)(*i); + + for (int j = block->m_start; j <= block->m_end; j++) { + + // load the original source data + FIBITMAP *dib = header->node->m_plugin->load_proc(header->io, header->handle, j, header->load_flags, data_read); + + // save the data + success = node->m_plugin->save_proc(io, dib, handle, count, flags, data); + count++; + + FreeImage_Unload(dib); + } + + break; + } + + case BLOCK_REFERENCE: + { + BlockReference *ref = (BlockReference *)(*i); + + // read the compressed data + + BYTE *compressed_data = (BYTE*)malloc(ref->m_size * sizeof(BYTE)); + + header->m_cachefile->readFile((BYTE *)compressed_data, ref->m_reference, ref->m_size); + + // uncompress the data + + FIMEMORY *hmem = FreeImage_OpenMemory(compressed_data, ref->m_size); + FIBITMAP *dib = FreeImage_LoadFromMemory(header->cache_fif, hmem, 0); + FreeImage_CloseMemory(hmem); + + // get rid of the buffer + free(compressed_data); + + // save the data + + success = node->m_plugin->save_proc(io, dib, handle, count, flags, data); + count++; + + // unload the dib + + FreeImage_Unload(dib); + + break; + } + } + } else { + break; + } + } + + // close the files + + FreeImage_Close(header->node, header->io, header->handle, data_read); + + FreeImage_Close(node, io, handle, data); + + return success; + } + } + + return FALSE; +} + + +BOOL DLL_CALLCONV +FreeImage_CloseMultiBitmap(FIMULTIBITMAP *bitmap, int flags) { + if (bitmap) { + BOOL success = TRUE; + + if (bitmap->data) { + MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); + + // saves changes only of images loaded directly from a file + if (header->changed && header->m_filename) { + try { + // open a temp file + + std::string spool_name; + + ReplaceExtension(spool_name, header->m_filename, "fispool"); + + // open the spool file and the source file + + FILE *f = fopen(spool_name.c_str(), "w+b"); + + // saves changes + if (f == NULL) { + FreeImage_OutputMessageProc(header->fif, "Failed to open %s, %s", spool_name.c_str(), strerror(errno)); + success = FALSE; + } else { + success = FreeImage_SaveMultiBitmapToHandle(header->fif, bitmap, header->io, (fi_handle)f, flags); + + // close the files + + if (fclose(f) != 0) { + success = FALSE; + FreeImage_OutputMessageProc(header->fif, "Failed to close %s, %s", spool_name.c_str(), strerror(errno)); + } + } + if (header->handle) { + fclose((FILE *)header->handle); + } + + // applies changes to the destination file + + if (success) { + remove(header->m_filename); + success = (rename(spool_name.c_str(), header->m_filename) == 0) ? TRUE:FALSE; + if(!success) { + FreeImage_OutputMessageProc(header->fif, "Failed to rename %s to %s", spool_name.c_str(), header->m_filename); + } + } else { + remove(spool_name.c_str()); + } + } catch (std::bad_alloc &) { + success = FALSE; + } + + } else { + if (header->handle && header->m_filename) { + fclose((FILE *)header->handle); + } + } + + // clear the blocks list + + for (BlockListIterator i = header->m_blocks.begin(); i != header->m_blocks.end(); ++i) { + delete *i; + } + + // flush and dispose the cache + + if (header->m_cachefile) { + header->m_cachefile->close(); + delete header->m_cachefile; + } + + // delete the last open bitmaps + + while (!header->locked_pages.empty()) { + FreeImage_Unload(header->locked_pages.begin()->first); + + header->locked_pages.erase(header->locked_pages.begin()->first); + } + + // get rid of the IO structure + + delete header->io; + + // delete the filename + + if(header->m_filename) { + delete[] header->m_filename; + } + + // delete the FIMULTIBITMAPHEADER + + delete header; + } + + delete bitmap; + + return success; + } + + return FALSE; +} + +int DLL_CALLCONV +FreeImage_GetPageCount(FIMULTIBITMAP *bitmap) { + if (bitmap) { + MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); + + if (header->page_count == -1) { + header->page_count = 0; + + for (BlockListIterator i = header->m_blocks.begin(); i != header->m_blocks.end(); ++i) { + switch((*i)->m_type) { + case BLOCK_CONTINUEUS : + header->page_count += ((BlockContinueus *)(*i))->m_end - ((BlockContinueus *)(*i))->m_start + 1; + break; + + case BLOCK_REFERENCE : + header->page_count++; + break; + } + } + } + + return header->page_count; + } + + return 0; +} + +static BlockReference* +FreeImage_SavePageToBlock(MULTIBITMAPHEADER *header, FIBITMAP *data) { + if (header->read_only || !header->locked_pages.empty()) + return NULL; + + DWORD compressed_size = 0; + BYTE *compressed_data = NULL; + + // compress the bitmap data + + // open a memory handle + FIMEMORY *hmem = FreeImage_OpenMemory(); + if(hmem==NULL) return NULL; + // save the file to memory + if(!FreeImage_SaveToMemory(header->cache_fif, data, hmem, 0)) { + FreeImage_CloseMemory(hmem); + return NULL; + } + // get the buffer from the memory stream + if(!FreeImage_AcquireMemory(hmem, &compressed_data, &compressed_size)) { + FreeImage_CloseMemory(hmem); + return NULL; + } + + // write the compressed data to the cache + int ref = header->m_cachefile->writeFile(compressed_data, compressed_size); + // get rid of the compressed data + FreeImage_CloseMemory(hmem); + + return new(std::nothrow) BlockReference(ref, compressed_size); +} + +void DLL_CALLCONV +FreeImage_AppendPage(FIMULTIBITMAP *bitmap, FIBITMAP *data) { + if (!bitmap || !data) + return; + + MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); + + BlockReference *block = FreeImage_SavePageToBlock(header, data); + if(block==NULL) return; + + // add the block + header->m_blocks.push_back((BlockTypeS *)block); + header->changed = TRUE; + header->page_count = -1; +} + +void DLL_CALLCONV +FreeImage_InsertPage(FIMULTIBITMAP *bitmap, int page, FIBITMAP *data) { + if (!bitmap || !data) + return; + + if (page >= FreeImage_GetPageCount(bitmap)) + return; + + MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); + + BlockReference *block = FreeImage_SavePageToBlock(header, data); + if(block==NULL) return; + + // add a block + if (page > 0) { + BlockListIterator block_source = FreeImage_FindBlock(bitmap, page); + + header->m_blocks.insert(block_source, (BlockTypeS *)block); + } else { + header->m_blocks.push_front((BlockTypeS *)block); + } + + header->changed = TRUE; + header->page_count = -1; +} + +void DLL_CALLCONV +FreeImage_DeletePage(FIMULTIBITMAP *bitmap, int page) { + if (bitmap) { + MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); + + if ((!header->read_only) && (header->locked_pages.empty())) { + if (FreeImage_GetPageCount(bitmap) > 1) { + BlockListIterator i = FreeImage_FindBlock(bitmap, page); + + if (i != header->m_blocks.end()) { + switch((*i)->m_type) { + case BLOCK_CONTINUEUS : + delete *i; + header->m_blocks.erase(i); + break; + + case BLOCK_REFERENCE : + header->m_cachefile->deleteFile(((BlockReference *)(*i))->m_reference); + delete *i; + header->m_blocks.erase(i); + break; + } + + header->changed = TRUE; + header->page_count = -1; + } + } + } + } +} + + +FIBITMAP * DLL_CALLCONV +FreeImage_LockPage(FIMULTIBITMAP *bitmap, int page) { + if (bitmap) { + MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); + + // only lock if the page wasn't locked before... + + for (std::map::iterator i = header->locked_pages.begin(); i != header->locked_pages.end(); ++i) { + if (i->second == page) { + return NULL; + } + } + + // open the bitmap + + header->io->seek_proc(header->handle, 0, SEEK_SET); + + void *data = FreeImage_Open(header->node, header->io, header->handle, TRUE); + + // load the bitmap data + + if (data != NULL) { + FIBITMAP *dib = (header->node->m_plugin->load_proc != NULL) ? header->node->m_plugin->load_proc(header->io, header->handle, page, header->load_flags, data) : NULL; + + // close the file + + FreeImage_Close(header->node, header->io, header->handle, data); + + // if there was still another bitmap open, get rid of it + + if (dib) { + header->locked_pages[dib] = page; + + return dib; + } + + return NULL; + } + } + + return NULL; +} + +void DLL_CALLCONV +FreeImage_UnlockPage(FIMULTIBITMAP *bitmap, FIBITMAP *page, BOOL changed) { + if ((bitmap) && (page)) { + MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); + + // find out if the page we try to unlock is actually locked... + + if (header->locked_pages.find(page) != header->locked_pages.end()) { + // store the bitmap compressed in the cache for later writing + + if (changed && !header->read_only) { + header->changed = TRUE; + + // cut loose the block from the rest + + BlockListIterator i = FreeImage_FindBlock(bitmap, header->locked_pages[page]); + + // compress the data + + DWORD compressed_size = 0; + BYTE *compressed_data = NULL; + + // open a memory handle + FIMEMORY *hmem = FreeImage_OpenMemory(); + // save the page to memory + FreeImage_SaveToMemory(header->cache_fif, page, hmem, 0); + // get the buffer from the memory stream + FreeImage_AcquireMemory(hmem, &compressed_data, &compressed_size); + + // write the data to the cache + + switch ((*i)->m_type) { + case BLOCK_CONTINUEUS : + { + int iPage = header->m_cachefile->writeFile(compressed_data, compressed_size); + + delete (*i); + + *i = (BlockTypeS *)new BlockReference(iPage, compressed_size); + + break; + } + + case BLOCK_REFERENCE : + { + BlockReference *reference = (BlockReference *)(*i); + + header->m_cachefile->deleteFile(reference->m_reference); + + delete (*i); + + int iPage = header->m_cachefile->writeFile(compressed_data, compressed_size); + + *i = (BlockTypeS *)new BlockReference(iPage, compressed_size); + + break; + } + } + + // get rid of the compressed data + + FreeImage_CloseMemory(hmem); + } + + // reset the locked page so that another page can be locked + + FreeImage_Unload(page); + + header->locked_pages.erase(page); + } + } +} + +BOOL DLL_CALLCONV +FreeImage_MovePage(FIMULTIBITMAP *bitmap, int target, int source) { + if (bitmap) { + MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); + + if ((!header->read_only) && (header->locked_pages.empty())) { + if ((target != source) && ((target >= 0) && (target < FreeImage_GetPageCount(bitmap))) && ((source >= 0) && (source < FreeImage_GetPageCount(bitmap)))) { + BlockListIterator block_source = FreeImage_FindBlock(bitmap, target); + BlockListIterator block_target = FreeImage_FindBlock(bitmap, source); + + header->m_blocks.insert(block_target, *block_source); + header->m_blocks.erase(block_source); + + header->changed = TRUE; + + return TRUE; + } + } + } + + return FALSE; +} + +BOOL DLL_CALLCONV +FreeImage_GetLockedPageNumbers(FIMULTIBITMAP *bitmap, int *pages, int *count) { + if ((bitmap) && (count)) { + MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap); + + if ((pages == NULL) || (*count == 0)) { + *count = (int)header->locked_pages.size(); + } else { + int c = 0; + + for (std::map::iterator i = header->locked_pages.begin(); i != header->locked_pages.end(); ++i) { + pages[c] = i->second; + + c++; + + if (c == *count) + break; + } + } + + return TRUE; + } + + return FALSE; +} + +// ===================================================================== +// Memory IO Multipage functions +// ===================================================================== + +FIMULTIBITMAP * DLL_CALLCONV +FreeImage_LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream, int flags) { + BOOL read_only = FALSE; // modifications (if any) will be stored into the memory cache + + // retrieve the plugin list to find the node belonging to this plugin + + PluginList *list = FreeImage_GetPluginList(); + + if (list) { + PluginNode *node = list->FindNodeFromFIF(fif); + + if (node) { + FreeImageIO *io = new(std::nothrow) FreeImageIO; + + if (io) { + SetMemoryIO(io); + + FIMULTIBITMAP *bitmap = new(std::nothrow) FIMULTIBITMAP; + + if (bitmap) { + MULTIBITMAPHEADER *header = new(std::nothrow) MULTIBITMAPHEADER; + + if (header) { + header->m_filename = NULL; + header->node = node; + header->fif = fif; + header->io = io; + header->handle = (fi_handle)stream; + header->changed = FALSE; + header->read_only = read_only; + header->m_cachefile = NULL; + header->cache_fif = fif; + header->load_flags = flags; + + // store the MULTIBITMAPHEADER in the surrounding FIMULTIBITMAP structure + + bitmap->data = header; + + // cache the page count + + header->page_count = FreeImage_InternalGetPageCount(bitmap); + + // allocate a continueus block to describe the bitmap + + header->m_blocks.push_back((BlockTypeS *)new BlockContinueus(0, header->page_count - 1)); + + if (!read_only) { + // set up the cache + CacheFile *cache_file = new(std::nothrow) CacheFile("", TRUE); + + if (cache_file && cache_file->open()) { + header->m_cachefile = cache_file; + } + } + + return bitmap; + } + + delete bitmap; + } + + delete io; + } + } + } + + return NULL; +} + +BOOL DLL_CALLCONV +FreeImage_SaveMultiBitmapToMemory(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, FIMEMORY *stream, int flags) { + if (stream && stream->data) { + FreeImageIO io; + SetMemoryIO(&io); + + return FreeImage_SaveMultiBitmapToHandle(fif, bitmap, &io, (fi_handle)stream, flags); + } + + return FALSE; +} diff --git a/Source/FreeImage/PixelAccess.cpp b/Source/FreeImage/PixelAccess.cpp index e3dccfe..c69463c 100644 --- a/Source/FreeImage/PixelAccess.cpp +++ b/Source/FreeImage/PixelAccess.cpp @@ -1,210 +1,210 @@ -// ========================================================== -// Pixel access functions -// -// Design and implementation by -// - Floris van den Berg (flvdberg@wxs.nl) -// - Hervé Drolon (drolon@infonie.fr) -// - Ryan Rubley (ryan@lostreality.org) -// - Riley McNiff (rmcniff@marexgroup.com) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" - -// ---------------------------------------------------------- - -BYTE * DLL_CALLCONV -FreeImage_GetBits(FIBITMAP *dib) { - if(!FreeImage_HasPixels(dib)) { - return NULL; - } - // returns the pixels aligned on a FIBITMAP_ALIGNMENT bytes alignment boundary - size_t lp = (size_t)FreeImage_GetInfoHeader(dib); - lp += sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * FreeImage_GetColorsUsed(dib); - lp += FreeImage_HasRGBMasks(dib) ? sizeof(DWORD) * 3 : 0; - lp += (lp % FIBITMAP_ALIGNMENT ? FIBITMAP_ALIGNMENT - lp % FIBITMAP_ALIGNMENT : 0); - return (BYTE *)lp; -} - -BYTE * DLL_CALLCONV -FreeImage_GetScanLine(FIBITMAP *dib, int scanline) { - if(!FreeImage_HasPixels(dib)) { - return NULL; - } - return CalculateScanLine(FreeImage_GetBits(dib), FreeImage_GetPitch(dib), scanline); -} - -BOOL DLL_CALLCONV -FreeImage_GetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value) { - BYTE shift; - - if(!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP)) - return FALSE; - - if((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) { - BYTE *bits = FreeImage_GetScanLine(dib, y); - - switch(FreeImage_GetBPP(dib)) { - case 1: - *value = (bits[x >> 3] & (0x80 >> (x & 0x07))) != 0; - break; - case 4: - shift = (BYTE)((1 - x % 2) << 2); - *value = (bits[x >> 1] & (0x0F << shift)) >> shift; - break; - case 8: - *value = bits[x]; - break; - default: - return FALSE; - } - - return TRUE; - } - - return FALSE; -} - -BOOL DLL_CALLCONV -FreeImage_GetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value) { - if(!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP)) - return FALSE; - - if((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) { - BYTE *bits = FreeImage_GetScanLine(dib, y); - - switch(FreeImage_GetBPP(dib)) { - case 16: - { - bits += 2*x; - WORD *pixel = (WORD *)bits; - if((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) { - value->rgbBlue = (BYTE)((((*pixel & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT) * 0xFF) / 0x1F); - value->rgbGreen = (BYTE)((((*pixel & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT) * 0xFF) / 0x3F); - value->rgbRed = (BYTE)((((*pixel & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT) * 0xFF) / 0x1F); - value->rgbReserved = 0; - } else { - value->rgbBlue = (BYTE)((((*pixel & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT) * 0xFF) / 0x1F); - value->rgbGreen = (BYTE)((((*pixel & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT) * 0xFF) / 0x1F); - value->rgbRed = (BYTE)((((*pixel & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT) * 0xFF) / 0x1F); - value->rgbReserved = 0; - } - break; - } - case 24: - bits += 3*x; - value->rgbBlue = bits[FI_RGBA_BLUE]; // B - value->rgbGreen = bits[FI_RGBA_GREEN]; // G - value->rgbRed = bits[FI_RGBA_RED]; // R - value->rgbReserved = 0; - break; - case 32: - bits += 4*x; - value->rgbBlue = bits[FI_RGBA_BLUE]; // B - value->rgbGreen = bits[FI_RGBA_GREEN]; // G - value->rgbRed = bits[FI_RGBA_RED]; // R - value->rgbReserved = bits[FI_RGBA_ALPHA]; // A - break; - default: - return FALSE; - } - - return TRUE; - } - - return FALSE; -} - -BOOL DLL_CALLCONV -FreeImage_SetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value) { - BYTE shift; - - if(!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP)) - return FALSE; - - if((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) { - BYTE *bits = FreeImage_GetScanLine(dib, y); - - switch(FreeImage_GetBPP(dib)) { - case 1: - *value ? bits[x >> 3] |= (0x80 >> (x & 0x7)) : bits[x >> 3] &= (0xFF7F >> (x & 0x7)); - break; - case 4: - shift = (BYTE)((1 - x % 2) << 2); - bits[x >> 1] &= ~(0x0F << shift); - bits[x >> 1] |= ((*value & 0x0F) << shift); - break; - case 8: - bits[x] = *value; - break; - default: - return FALSE; - } - - return TRUE; - } - - return FALSE; -} - -BOOL DLL_CALLCONV -FreeImage_SetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value) { - if(!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP)) - return FALSE; - - if((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) { - BYTE *bits = FreeImage_GetScanLine(dib, y); - - switch(FreeImage_GetBPP(dib)) { - case 16: - { - bits += 2*x; - WORD *pixel = (WORD *)bits; - if((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) { - *pixel = ((value->rgbBlue >> 3) << FI16_565_BLUE_SHIFT) | - ((value->rgbGreen >> 2) << FI16_565_GREEN_SHIFT) | - ((value->rgbRed >> 3) << FI16_565_RED_SHIFT); - } else { - *pixel = ((value->rgbBlue >> 3) << FI16_555_BLUE_SHIFT) | - ((value->rgbGreen >> 3) << FI16_555_GREEN_SHIFT) | - ((value->rgbRed >> 3) << FI16_555_RED_SHIFT); - } - break; - } - case 24: - bits += 3*x; - bits[FI_RGBA_BLUE] = value->rgbBlue; // B - bits[FI_RGBA_GREEN] = value->rgbGreen; // G - bits[FI_RGBA_RED] = value->rgbRed; // R - break; - case 32: - bits += 4*x; - bits[FI_RGBA_BLUE] = value->rgbBlue; // B - bits[FI_RGBA_GREEN] = value->rgbGreen; // G - bits[FI_RGBA_RED] = value->rgbRed; // R - bits[FI_RGBA_ALPHA] = value->rgbReserved; // A - break; - default: - return FALSE; - } - - return TRUE; - } - - return FALSE; -} - +// ========================================================== +// Pixel access functions +// +// Design and implementation by +// - Floris van den Berg (flvdberg@wxs.nl) +// - Hervé Drolon (drolon@infonie.fr) +// - Ryan Rubley (ryan@lostreality.org) +// - Riley McNiff (rmcniff@marexgroup.com) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" + +// ---------------------------------------------------------- + +BYTE * DLL_CALLCONV +FreeImage_GetBits(FIBITMAP *dib) { + if(!FreeImage_HasPixels(dib)) { + return NULL; + } + // returns the pixels aligned on a FIBITMAP_ALIGNMENT bytes alignment boundary + size_t lp = (size_t)FreeImage_GetInfoHeader(dib); + lp += sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * FreeImage_GetColorsUsed(dib); + lp += FreeImage_HasRGBMasks(dib) ? sizeof(DWORD) * 3 : 0; + lp += (lp % FIBITMAP_ALIGNMENT ? FIBITMAP_ALIGNMENT - lp % FIBITMAP_ALIGNMENT : 0); + return (BYTE *)lp; +} + +BYTE * DLL_CALLCONV +FreeImage_GetScanLine(FIBITMAP *dib, int scanline) { + if(!FreeImage_HasPixels(dib)) { + return NULL; + } + return CalculateScanLine(FreeImage_GetBits(dib), FreeImage_GetPitch(dib), scanline); +} + +BOOL DLL_CALLCONV +FreeImage_GetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value) { + BYTE shift; + + if(!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP)) + return FALSE; + + if((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) { + BYTE *bits = FreeImage_GetScanLine(dib, y); + + switch(FreeImage_GetBPP(dib)) { + case 1: + *value = (bits[x >> 3] & (0x80 >> (x & 0x07))) != 0; + break; + case 4: + shift = (BYTE)((1 - x % 2) << 2); + *value = (bits[x >> 1] & (0x0F << shift)) >> shift; + break; + case 8: + *value = bits[x]; + break; + default: + return FALSE; + } + + return TRUE; + } + + return FALSE; +} + +BOOL DLL_CALLCONV +FreeImage_GetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value) { + if(!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP)) + return FALSE; + + if((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) { + BYTE *bits = FreeImage_GetScanLine(dib, y); + + switch(FreeImage_GetBPP(dib)) { + case 16: + { + bits += 2*x; + WORD *pixel = (WORD *)bits; + if((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) { + value->rgbBlue = (BYTE)((((*pixel & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT) * 0xFF) / 0x1F); + value->rgbGreen = (BYTE)((((*pixel & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT) * 0xFF) / 0x3F); + value->rgbRed = (BYTE)((((*pixel & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT) * 0xFF) / 0x1F); + value->rgbReserved = 0; + } else { + value->rgbBlue = (BYTE)((((*pixel & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT) * 0xFF) / 0x1F); + value->rgbGreen = (BYTE)((((*pixel & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT) * 0xFF) / 0x1F); + value->rgbRed = (BYTE)((((*pixel & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT) * 0xFF) / 0x1F); + value->rgbReserved = 0; + } + break; + } + case 24: + bits += 3*x; + value->rgbBlue = bits[FI_RGBA_BLUE]; // B + value->rgbGreen = bits[FI_RGBA_GREEN]; // G + value->rgbRed = bits[FI_RGBA_RED]; // R + value->rgbReserved = 0; + break; + case 32: + bits += 4*x; + value->rgbBlue = bits[FI_RGBA_BLUE]; // B + value->rgbGreen = bits[FI_RGBA_GREEN]; // G + value->rgbRed = bits[FI_RGBA_RED]; // R + value->rgbReserved = bits[FI_RGBA_ALPHA]; // A + break; + default: + return FALSE; + } + + return TRUE; + } + + return FALSE; +} + +BOOL DLL_CALLCONV +FreeImage_SetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value) { + BYTE shift; + + if(!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP)) + return FALSE; + + if((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) { + BYTE *bits = FreeImage_GetScanLine(dib, y); + + switch(FreeImage_GetBPP(dib)) { + case 1: + *value ? bits[x >> 3] |= (0x80 >> (x & 0x7)) : bits[x >> 3] &= (0xFF7F >> (x & 0x7)); + break; + case 4: + shift = (BYTE)((1 - x % 2) << 2); + bits[x >> 1] &= ~(0x0F << shift); + bits[x >> 1] |= ((*value & 0x0F) << shift); + break; + case 8: + bits[x] = *value; + break; + default: + return FALSE; + } + + return TRUE; + } + + return FALSE; +} + +BOOL DLL_CALLCONV +FreeImage_SetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value) { + if(!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP)) + return FALSE; + + if((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) { + BYTE *bits = FreeImage_GetScanLine(dib, y); + + switch(FreeImage_GetBPP(dib)) { + case 16: + { + bits += 2*x; + WORD *pixel = (WORD *)bits; + if((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) { + *pixel = ((value->rgbBlue >> 3) << FI16_565_BLUE_SHIFT) | + ((value->rgbGreen >> 2) << FI16_565_GREEN_SHIFT) | + ((value->rgbRed >> 3) << FI16_565_RED_SHIFT); + } else { + *pixel = ((value->rgbBlue >> 3) << FI16_555_BLUE_SHIFT) | + ((value->rgbGreen >> 3) << FI16_555_GREEN_SHIFT) | + ((value->rgbRed >> 3) << FI16_555_RED_SHIFT); + } + break; + } + case 24: + bits += 3*x; + bits[FI_RGBA_BLUE] = value->rgbBlue; // B + bits[FI_RGBA_GREEN] = value->rgbGreen; // G + bits[FI_RGBA_RED] = value->rgbRed; // R + break; + case 32: + bits += 4*x; + bits[FI_RGBA_BLUE] = value->rgbBlue; // B + bits[FI_RGBA_GREEN] = value->rgbGreen; // G + bits[FI_RGBA_RED] = value->rgbRed; // R + bits[FI_RGBA_ALPHA] = value->rgbReserved; // A + break; + default: + return FALSE; + } + + return TRUE; + } + + return FALSE; +} + diff --git a/Source/FreeImage/PluginJ2K.cpp b/Source/FreeImage/PluginJ2K.cpp index ae8a6ae..c868ce2 100644 --- a/Source/FreeImage/PluginJ2K.cpp +++ b/Source/FreeImage/PluginJ2K.cpp @@ -1,339 +1,339 @@ -// ========================================================== -// JPEG2000 J2K codestream Loader and Writer -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" -#include "../LibOpenJPEG/openjpeg.h" - -// ========================================================== -// Plugin Interface -// ========================================================== - -static int s_format_id; - -// ========================================================== -// Helper functions (see J2KHelper.cpp) -// ========================================================== - -FIBITMAP* J2KImageToFIBITMAP(int format_id, const opj_image_t *image); -opj_image_t* FIBITMAPToJ2KImage(int format_id, FIBITMAP *dib, const opj_cparameters_t *parameters); - -// ========================================================== -// Internal functions -// ========================================================== - -/** -OpenJPEG Error callback -*/ -static void j2k_error_callback(const char *msg, void *client_data) { - FreeImage_OutputMessageProc(s_format_id, "Error: %s", msg); -} -/** -OpenJPEG Warning callback -*/ -static void j2k_warning_callback(const char *msg, void *client_data) { - FreeImage_OutputMessageProc(s_format_id, "Warning: %s", msg); -} - -// ========================================================== -// Plugin Implementation -// ========================================================== - -static const char * DLL_CALLCONV -Format() { - return "J2K"; -} - -static const char * DLL_CALLCONV -Description() { - return "JPEG-2000 codestream"; -} - -static const char * DLL_CALLCONV -Extension() { - return "j2k,j2c"; -} - -static const char * DLL_CALLCONV -RegExpr() { - return NULL; -} - -static const char * DLL_CALLCONV -MimeType() { - return "image/j2k"; -} - -static BOOL DLL_CALLCONV -Validate(FreeImageIO *io, fi_handle handle) { - BYTE jpc_signature[] = { 0xFF, 0x4F }; - BYTE signature[2] = { 0, 0 }; - - long tell = io->tell_proc(handle); - io->read_proc(signature, 1, sizeof(jpc_signature), handle); - io->seek_proc(handle, tell, SEEK_SET); - - return (memcmp(jpc_signature, signature, sizeof(jpc_signature)) == 0); -} - -static BOOL DLL_CALLCONV -SupportsExportDepth(int depth) { - return ( - (depth == 8) || - (depth == 24) || - (depth == 32) - ); -} - -static BOOL DLL_CALLCONV -SupportsExportType(FREE_IMAGE_TYPE type) { - return ( - (type == FIT_BITMAP) || - (type == FIT_UINT16) || - (type == FIT_RGB16) || - (type == FIT_RGBA16) - ); -} - -// ---------------------------------------------------------- - -static void * DLL_CALLCONV -Open(FreeImageIO *io, fi_handle handle, BOOL read) { - return NULL; -} - -static void DLL_CALLCONV -Close(FreeImageIO *io, fi_handle handle, void *data) { -} - -// ---------------------------------------------------------- - -static FIBITMAP * DLL_CALLCONV -Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { - if (handle) { - opj_dparameters_t parameters; // decompression parameters - opj_event_mgr_t event_mgr; // event manager - opj_image_t *image = NULL; // decoded image - - BYTE *src = NULL; - long file_length; - - opj_dinfo_t* dinfo = NULL; // handle to a decompressor - opj_cio_t *cio = NULL; - - FIBITMAP *dib = NULL; - - // check the file format - if(!Validate(io, handle)) { - return NULL; - } - - // configure the event callbacks - memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); - event_mgr.error_handler = j2k_error_callback; - event_mgr.warning_handler = j2k_warning_callback; - event_mgr.info_handler = NULL; - - // set decoding parameters to default values - opj_set_default_decoder_parameters(¶meters); - - try { - // read the input file and put it in memory - - long start_pos = io->tell_proc(handle); - io->seek_proc(handle, 0, SEEK_END); - file_length = io->tell_proc(handle) - start_pos; - io->seek_proc(handle, start_pos, SEEK_SET); - src = (BYTE*)malloc(file_length * sizeof(BYTE)); - if(!src) { - throw FI_MSG_ERROR_MEMORY; - } - if(io->read_proc(src, 1, file_length, handle) < 1) { - throw "Error while reading input stream"; - } - - // decode the JPEG-2000 codestream - - // get a decoder handle - dinfo = opj_create_decompress(CODEC_J2K); - - // catch events using our callbacks - opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, NULL); - - // setup the decoder decoding parameters using user parameters - opj_setup_decoder(dinfo, ¶meters); - - // open a byte stream - cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); - - // decode the stream and fill the image structure - image = opj_decode(dinfo, cio); - if(!image) { - throw "Failed to decode image!\n"; - } - - // close the byte stream - opj_cio_close(cio); - cio = NULL; - - // free the memory containing the code-stream - free(src); - src = NULL; - - // free the codec context - opj_destroy_decompress(dinfo); - - // create output image - dib = J2KImageToFIBITMAP(s_format_id, image); - if(!dib) throw "Failed to import JPEG2000 image"; - - // free image data structure - opj_image_destroy(image); - - return dib; - - } catch (const char *text) { - if(src) free(src); - if(dib) FreeImage_Unload(dib); - // free remaining structures - opj_destroy_decompress(dinfo); - opj_image_destroy(image); - // close the byte stream - if(cio) opj_cio_close(cio); - - FreeImage_OutputMessageProc(s_format_id, text); - - return NULL; - } - } - - return NULL; -} - -static BOOL DLL_CALLCONV -Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) { - if ((dib) && (handle)) { - BOOL bSuccess; - opj_cparameters_t parameters; // compression parameters - opj_event_mgr_t event_mgr; // event manager - opj_image_t *image = NULL; // image to encode - opj_cinfo_t* cinfo = NULL; // codec context - opj_cio_t *cio = NULL; // memory byte stream - - // configure the event callbacks - memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); - event_mgr.error_handler = j2k_error_callback; - event_mgr.warning_handler = j2k_warning_callback; - event_mgr.info_handler = NULL; - - // set encoding parameters to default values - opj_set_default_encoder_parameters(¶meters); - - parameters.tcp_numlayers = 0; - // if no rate entered, apply a 16:1 rate by default - if(flags == J2K_DEFAULT) { - parameters.tcp_rates[0] = (float)16; - } else { - // for now, the flags parameter is only used to specify the rate - parameters.tcp_rates[0] = (float)flags; - } - parameters.tcp_numlayers++; - parameters.cp_disto_alloc = 1; - - try { - // convert the dib to a OpenJPEG image - image = FIBITMAPToJ2KImage(s_format_id, dib, ¶meters); - if(!image) return FALSE; - - // decide if MCT should be used - parameters.tcp_mct = (image->numcomps == 3) ? 1 : 0; - - // encode the destination image - - // get a J2K compressor handle - cinfo = opj_create_compress(CODEC_J2K); - - // catch events using our callbacks - opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, NULL); - - // setup the encoder parameters using the current image and using user parameters - opj_setup_encoder(cinfo, ¶meters, image); - - // open a byte stream for writing, allocate memory for all tiles - cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0); - - // encode the image - bSuccess = opj_encode(cinfo, cio, image, NULL/*parameters.index*/); - if (!bSuccess) { - throw "Failed to encode image"; - } - int codestream_length = cio_tell(cio); - - // write the buffer to user's IO handle - io->write_proc(cio->buffer, 1, codestream_length, handle); - - // close and free the byte stream - opj_cio_close(cio); - - // free remaining compression structures - opj_destroy_compress(cinfo); - - // free image data - opj_image_destroy(image); - - return TRUE; - - } catch (const char *text) { - if(cio) opj_cio_close(cio); - if(cinfo) opj_destroy_compress(cinfo); - if(image) opj_image_destroy(image); - FreeImage_OutputMessageProc(s_format_id, text); - return FALSE; - } - } - - return FALSE; -} - -// ========================================================== -// Init -// ========================================================== - -void DLL_CALLCONV -InitJ2K(Plugin *plugin, int format_id) { - s_format_id = format_id; - - plugin->format_proc = Format; - plugin->description_proc = Description; - plugin->extension_proc = Extension; - plugin->regexpr_proc = RegExpr; - plugin->open_proc = Open; - plugin->close_proc = Close; - plugin->pagecount_proc = NULL; - plugin->pagecapability_proc = NULL; - plugin->load_proc = Load; - plugin->save_proc = Save; - plugin->validate_proc = Validate; - plugin->mime_proc = MimeType; - plugin->supports_export_bpp_proc = SupportsExportDepth; - plugin->supports_export_type_proc = SupportsExportType; - plugin->supports_icc_profiles_proc = NULL; -} +// ========================================================== +// JPEG2000 J2K codestream Loader and Writer +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" +#include "../LibOpenJPEG/openjpeg.h" + +// ========================================================== +// Plugin Interface +// ========================================================== + +static int s_format_id; + +// ========================================================== +// Helper functions (see J2KHelper.cpp) +// ========================================================== + +FIBITMAP* J2KImageToFIBITMAP(int format_id, const opj_image_t *image); +opj_image_t* FIBITMAPToJ2KImage(int format_id, FIBITMAP *dib, const opj_cparameters_t *parameters); + +// ========================================================== +// Internal functions +// ========================================================== + +/** +OpenJPEG Error callback +*/ +static void j2k_error_callback(const char *msg, void *client_data) { + FreeImage_OutputMessageProc(s_format_id, "Error: %s", msg); +} +/** +OpenJPEG Warning callback +*/ +static void j2k_warning_callback(const char *msg, void *client_data) { + FreeImage_OutputMessageProc(s_format_id, "Warning: %s", msg); +} + +// ========================================================== +// Plugin Implementation +// ========================================================== + +static const char * DLL_CALLCONV +Format() { + return "J2K"; +} + +static const char * DLL_CALLCONV +Description() { + return "JPEG-2000 codestream"; +} + +static const char * DLL_CALLCONV +Extension() { + return "j2k,j2c"; +} + +static const char * DLL_CALLCONV +RegExpr() { + return NULL; +} + +static const char * DLL_CALLCONV +MimeType() { + return "image/j2k"; +} + +static BOOL DLL_CALLCONV +Validate(FreeImageIO *io, fi_handle handle) { + BYTE jpc_signature[] = { 0xFF, 0x4F }; + BYTE signature[2] = { 0, 0 }; + + long tell = io->tell_proc(handle); + io->read_proc(signature, 1, sizeof(jpc_signature), handle); + io->seek_proc(handle, tell, SEEK_SET); + + return (memcmp(jpc_signature, signature, sizeof(jpc_signature)) == 0); +} + +static BOOL DLL_CALLCONV +SupportsExportDepth(int depth) { + return ( + (depth == 8) || + (depth == 24) || + (depth == 32) + ); +} + +static BOOL DLL_CALLCONV +SupportsExportType(FREE_IMAGE_TYPE type) { + return ( + (type == FIT_BITMAP) || + (type == FIT_UINT16) || + (type == FIT_RGB16) || + (type == FIT_RGBA16) + ); +} + +// ---------------------------------------------------------- + +static void * DLL_CALLCONV +Open(FreeImageIO *io, fi_handle handle, BOOL read) { + return NULL; +} + +static void DLL_CALLCONV +Close(FreeImageIO *io, fi_handle handle, void *data) { +} + +// ---------------------------------------------------------- + +static FIBITMAP * DLL_CALLCONV +Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { + if (handle) { + opj_dparameters_t parameters; // decompression parameters + opj_event_mgr_t event_mgr; // event manager + opj_image_t *image = NULL; // decoded image + + BYTE *src = NULL; + long file_length; + + opj_dinfo_t* dinfo = NULL; // handle to a decompressor + opj_cio_t *cio = NULL; + + FIBITMAP *dib = NULL; + + // check the file format + if(!Validate(io, handle)) { + return NULL; + } + + // configure the event callbacks + memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); + event_mgr.error_handler = j2k_error_callback; + event_mgr.warning_handler = j2k_warning_callback; + event_mgr.info_handler = NULL; + + // set decoding parameters to default values + opj_set_default_decoder_parameters(¶meters); + + try { + // read the input file and put it in memory + + long start_pos = io->tell_proc(handle); + io->seek_proc(handle, 0, SEEK_END); + file_length = io->tell_proc(handle) - start_pos; + io->seek_proc(handle, start_pos, SEEK_SET); + src = (BYTE*)malloc(file_length * sizeof(BYTE)); + if(!src) { + throw FI_MSG_ERROR_MEMORY; + } + if(io->read_proc(src, 1, file_length, handle) < 1) { + throw "Error while reading input stream"; + } + + // decode the JPEG-2000 codestream + + // get a decoder handle + dinfo = opj_create_decompress(CODEC_J2K); + + // catch events using our callbacks + opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, NULL); + + // setup the decoder decoding parameters using user parameters + opj_setup_decoder(dinfo, ¶meters); + + // open a byte stream + cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); + + // decode the stream and fill the image structure + image = opj_decode(dinfo, cio); + if(!image) { + throw "Failed to decode image!\n"; + } + + // close the byte stream + opj_cio_close(cio); + cio = NULL; + + // free the memory containing the code-stream + free(src); + src = NULL; + + // free the codec context + opj_destroy_decompress(dinfo); + + // create output image + dib = J2KImageToFIBITMAP(s_format_id, image); + if(!dib) throw "Failed to import JPEG2000 image"; + + // free image data structure + opj_image_destroy(image); + + return dib; + + } catch (const char *text) { + if(src) free(src); + if(dib) FreeImage_Unload(dib); + // free remaining structures + opj_destroy_decompress(dinfo); + opj_image_destroy(image); + // close the byte stream + if(cio) opj_cio_close(cio); + + FreeImage_OutputMessageProc(s_format_id, text); + + return NULL; + } + } + + return NULL; +} + +static BOOL DLL_CALLCONV +Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) { + if ((dib) && (handle)) { + BOOL bSuccess; + opj_cparameters_t parameters; // compression parameters + opj_event_mgr_t event_mgr; // event manager + opj_image_t *image = NULL; // image to encode + opj_cinfo_t* cinfo = NULL; // codec context + opj_cio_t *cio = NULL; // memory byte stream + + // configure the event callbacks + memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); + event_mgr.error_handler = j2k_error_callback; + event_mgr.warning_handler = j2k_warning_callback; + event_mgr.info_handler = NULL; + + // set encoding parameters to default values + opj_set_default_encoder_parameters(¶meters); + + parameters.tcp_numlayers = 0; + // if no rate entered, apply a 16:1 rate by default + if(flags == J2K_DEFAULT) { + parameters.tcp_rates[0] = (float)16; + } else { + // for now, the flags parameter is only used to specify the rate + parameters.tcp_rates[0] = (float)flags; + } + parameters.tcp_numlayers++; + parameters.cp_disto_alloc = 1; + + try { + // convert the dib to a OpenJPEG image + image = FIBITMAPToJ2KImage(s_format_id, dib, ¶meters); + if(!image) return FALSE; + + // decide if MCT should be used + parameters.tcp_mct = (image->numcomps == 3) ? 1 : 0; + + // encode the destination image + + // get a J2K compressor handle + cinfo = opj_create_compress(CODEC_J2K); + + // catch events using our callbacks + opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, NULL); + + // setup the encoder parameters using the current image and using user parameters + opj_setup_encoder(cinfo, ¶meters, image); + + // open a byte stream for writing, allocate memory for all tiles + cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0); + + // encode the image + bSuccess = opj_encode(cinfo, cio, image, NULL/*parameters.index*/); + if (!bSuccess) { + throw "Failed to encode image"; + } + int codestream_length = cio_tell(cio); + + // write the buffer to user's IO handle + io->write_proc(cio->buffer, 1, codestream_length, handle); + + // close and free the byte stream + opj_cio_close(cio); + + // free remaining compression structures + opj_destroy_compress(cinfo); + + // free image data + opj_image_destroy(image); + + return TRUE; + + } catch (const char *text) { + if(cio) opj_cio_close(cio); + if(cinfo) opj_destroy_compress(cinfo); + if(image) opj_image_destroy(image); + FreeImage_OutputMessageProc(s_format_id, text); + return FALSE; + } + } + + return FALSE; +} + +// ========================================================== +// Init +// ========================================================== + +void DLL_CALLCONV +InitJ2K(Plugin *plugin, int format_id) { + s_format_id = format_id; + + plugin->format_proc = Format; + plugin->description_proc = Description; + plugin->extension_proc = Extension; + plugin->regexpr_proc = RegExpr; + plugin->open_proc = Open; + plugin->close_proc = Close; + plugin->pagecount_proc = NULL; + plugin->pagecapability_proc = NULL; + plugin->load_proc = Load; + plugin->save_proc = Save; + plugin->validate_proc = Validate; + plugin->mime_proc = MimeType; + plugin->supports_export_bpp_proc = SupportsExportDepth; + plugin->supports_export_type_proc = SupportsExportType; + plugin->supports_icc_profiles_proc = NULL; +} diff --git a/Source/FreeImage/PluginJP2.cpp b/Source/FreeImage/PluginJP2.cpp index 261697f..df41218 100644 --- a/Source/FreeImage/PluginJP2.cpp +++ b/Source/FreeImage/PluginJP2.cpp @@ -1,339 +1,339 @@ -// ========================================================== -// JPEG2000 JP2 file format Loader and Writer -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" -#include "../LibOpenJPEG/openjpeg.h" - -// ========================================================== -// Plugin Interface -// ========================================================== - -static int s_format_id; - -// ========================================================== -// Helper functions (see J2KHelper.cpp) -// ========================================================== - -FIBITMAP* J2KImageToFIBITMAP(int format_id, const opj_image_t *image); -opj_image_t* FIBITMAPToJ2KImage(int format_id, FIBITMAP *dib, const opj_cparameters_t *parameters); - -// ========================================================== -// Internal functions -// ========================================================== - -/** -OpenJPEG Error callback -*/ -static void jp2_error_callback(const char *msg, void *client_data) { - FreeImage_OutputMessageProc(s_format_id, "Error: %s", msg); -} -/** -OpenJPEG Warning callback -*/ -static void jp2_warning_callback(const char *msg, void *client_data) { - FreeImage_OutputMessageProc(s_format_id, "Warning: %s", msg); -} - -// ========================================================== -// Plugin Implementation -// ========================================================== - -static const char * DLL_CALLCONV -Format() { - return "JP2"; -} - -static const char * DLL_CALLCONV -Description() { - return "JPEG-2000 File Format"; -} - -static const char * DLL_CALLCONV -Extension() { - return "jp2"; -} - -static const char * DLL_CALLCONV -RegExpr() { - return NULL; -} - -static const char * DLL_CALLCONV -MimeType() { - return "image/jp2"; -} - -static BOOL DLL_CALLCONV -Validate(FreeImageIO *io, fi_handle handle) { - BYTE jp2_signature[] = { 0x00, 0x00, 0x00, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A }; - BYTE signature[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - - long tell = io->tell_proc(handle); - io->read_proc(signature, 1, sizeof(jp2_signature), handle); - io->seek_proc(handle, tell, SEEK_SET); - - return (memcmp(jp2_signature, signature, sizeof(jp2_signature)) == 0); -} - -static BOOL DLL_CALLCONV -SupportsExportDepth(int depth) { - return ( - (depth == 8) || - (depth == 24) || - (depth == 32) - ); -} - -static BOOL DLL_CALLCONV -SupportsExportType(FREE_IMAGE_TYPE type) { - return ( - (type == FIT_BITMAP) || - (type == FIT_UINT16) || - (type == FIT_RGB16) || - (type == FIT_RGBA16) - ); -} - -// ---------------------------------------------------------- - -static void * DLL_CALLCONV -Open(FreeImageIO *io, fi_handle handle, BOOL read) { - return NULL; -} - -static void DLL_CALLCONV -Close(FreeImageIO *io, fi_handle handle, void *data) { -} - -// ---------------------------------------------------------- - -static FIBITMAP * DLL_CALLCONV -Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { - if (handle) { - opj_dparameters_t parameters; // decompression parameters - opj_event_mgr_t event_mgr; // event manager - opj_image_t *image = NULL; // decoded image - - BYTE *src = NULL; - long file_length; - - opj_dinfo_t* dinfo = NULL; // handle to a decompressor - opj_cio_t *cio = NULL; - - FIBITMAP *dib = NULL; - - // check the file format - if(!Validate(io, handle)) { - return NULL; - } - - // configure the event callbacks - memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); - event_mgr.error_handler = jp2_error_callback; - event_mgr.warning_handler = jp2_warning_callback; - event_mgr.info_handler = NULL; - - // set decoding parameters to default values - opj_set_default_decoder_parameters(¶meters); - - try { - // read the input file and put it in memory - - long start_pos = io->tell_proc(handle); - io->seek_proc(handle, 0, SEEK_END); - file_length = io->tell_proc(handle) - start_pos; - io->seek_proc(handle, start_pos, SEEK_SET); - src = (BYTE*)malloc(file_length * sizeof(BYTE)); - if(!src) { - throw FI_MSG_ERROR_MEMORY; - } - if(io->read_proc(src, 1, file_length, handle) < 1) { - throw "Error while reading input stream"; - } - - // decode the JPEG-2000 file - - // get a decoder handle - dinfo = opj_create_decompress(CODEC_JP2); - - // catch events using our callbacks - opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, NULL); - - // setup the decoder decoding parameters using user parameters - opj_setup_decoder(dinfo, ¶meters); - - // open a byte stream - cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); - - // decode the stream and fill the image structure - image = opj_decode(dinfo, cio); - if(!image) { - throw "Failed to decode image!\n"; - } - - // close the byte stream - opj_cio_close(cio); - cio = NULL; - - // free the memory containing the code-stream - free(src); - src = NULL; - - // free the codec context - opj_destroy_decompress(dinfo); - - // create output image - dib = J2KImageToFIBITMAP(s_format_id, image); - if(!dib) throw "Failed to import JPEG2000 image"; - - // free image data structure - opj_image_destroy(image); - - return dib; - - } catch (const char *text) { - if(src) free(src); - if(dib) FreeImage_Unload(dib); - // free remaining structures - opj_destroy_decompress(dinfo); - opj_image_destroy(image); - // close the byte stream - if(cio) opj_cio_close(cio); - - FreeImage_OutputMessageProc(s_format_id, text); - - return NULL; - } - } - - return NULL; -} - -static BOOL DLL_CALLCONV -Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) { - if ((dib) && (handle)) { - BOOL bSuccess; - opj_cparameters_t parameters; // compression parameters - opj_event_mgr_t event_mgr; // event manager - opj_image_t *image = NULL; // image to encode - opj_cinfo_t* cinfo = NULL; // codec context - opj_cio_t *cio = NULL; // memory byte stream - - // configure the event callbacks - memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); - event_mgr.error_handler = jp2_error_callback; - event_mgr.warning_handler = jp2_warning_callback; - event_mgr.info_handler = NULL; - - // set encoding parameters to default values - opj_set_default_encoder_parameters(¶meters); - - parameters.tcp_numlayers = 0; - // if no rate entered, apply a 16:1 rate by default - if(flags == JP2_DEFAULT) { - parameters.tcp_rates[0] = (float)16; - } else { - // for now, the flags parameter is only used to specify the rate - parameters.tcp_rates[0] = (float)flags; - } - parameters.tcp_numlayers++; - parameters.cp_disto_alloc = 1; - - try { - // convert the dib to a OpenJPEG image - image = FIBITMAPToJ2KImage(s_format_id, dib, ¶meters); - if(!image) return FALSE; - - // decide if MCT should be used - parameters.tcp_mct = (image->numcomps == 3) ? 1 : 0; - - // encode the destination image - - // get a J2K compressor handle - cinfo = opj_create_compress(CODEC_JP2); - - // catch events using our callbacks - opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, NULL); - - // setup the encoder parameters using the current image and using user parameters - opj_setup_encoder(cinfo, ¶meters, image); - - // open a byte stream for writing, allocate memory for all tiles - cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0); - - // encode the image - bSuccess = opj_encode(cinfo, cio, image, NULL/*parameters.index*/); - if (!bSuccess) { - throw "Failed to encode image"; - } - int codestream_length = cio_tell(cio); - - // write the buffer to user's IO handle - io->write_proc(cio->buffer, 1, codestream_length, handle); - - // close and free the byte stream - opj_cio_close(cio); - - // free remaining compression structures - opj_destroy_compress(cinfo); - - // free image data - opj_image_destroy(image); - - return TRUE; - - } catch (const char *text) { - if(cio) opj_cio_close(cio); - if(cinfo) opj_destroy_compress(cinfo); - if(image) opj_image_destroy(image); - FreeImage_OutputMessageProc(s_format_id, text); - return FALSE; - } - } - - return FALSE; -} - -// ========================================================== -// Init -// ========================================================== - -void DLL_CALLCONV -InitJP2(Plugin *plugin, int format_id) { - s_format_id = format_id; - - plugin->format_proc = Format; - plugin->description_proc = Description; - plugin->extension_proc = Extension; - plugin->regexpr_proc = RegExpr; - plugin->open_proc = Open; - plugin->close_proc = Close; - plugin->pagecount_proc = NULL; - plugin->pagecapability_proc = NULL; - plugin->load_proc = Load; - plugin->save_proc = Save; - plugin->validate_proc = Validate; - plugin->mime_proc = MimeType; - plugin->supports_export_bpp_proc = SupportsExportDepth; - plugin->supports_export_type_proc = SupportsExportType; - plugin->supports_icc_profiles_proc = NULL; -} +// ========================================================== +// JPEG2000 JP2 file format Loader and Writer +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" +#include "../LibOpenJPEG/openjpeg.h" + +// ========================================================== +// Plugin Interface +// ========================================================== + +static int s_format_id; + +// ========================================================== +// Helper functions (see J2KHelper.cpp) +// ========================================================== + +FIBITMAP* J2KImageToFIBITMAP(int format_id, const opj_image_t *image); +opj_image_t* FIBITMAPToJ2KImage(int format_id, FIBITMAP *dib, const opj_cparameters_t *parameters); + +// ========================================================== +// Internal functions +// ========================================================== + +/** +OpenJPEG Error callback +*/ +static void jp2_error_callback(const char *msg, void *client_data) { + FreeImage_OutputMessageProc(s_format_id, "Error: %s", msg); +} +/** +OpenJPEG Warning callback +*/ +static void jp2_warning_callback(const char *msg, void *client_data) { + FreeImage_OutputMessageProc(s_format_id, "Warning: %s", msg); +} + +// ========================================================== +// Plugin Implementation +// ========================================================== + +static const char * DLL_CALLCONV +Format() { + return "JP2"; +} + +static const char * DLL_CALLCONV +Description() { + return "JPEG-2000 File Format"; +} + +static const char * DLL_CALLCONV +Extension() { + return "jp2"; +} + +static const char * DLL_CALLCONV +RegExpr() { + return NULL; +} + +static const char * DLL_CALLCONV +MimeType() { + return "image/jp2"; +} + +static BOOL DLL_CALLCONV +Validate(FreeImageIO *io, fi_handle handle) { + BYTE jp2_signature[] = { 0x00, 0x00, 0x00, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A }; + BYTE signature[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + long tell = io->tell_proc(handle); + io->read_proc(signature, 1, sizeof(jp2_signature), handle); + io->seek_proc(handle, tell, SEEK_SET); + + return (memcmp(jp2_signature, signature, sizeof(jp2_signature)) == 0); +} + +static BOOL DLL_CALLCONV +SupportsExportDepth(int depth) { + return ( + (depth == 8) || + (depth == 24) || + (depth == 32) + ); +} + +static BOOL DLL_CALLCONV +SupportsExportType(FREE_IMAGE_TYPE type) { + return ( + (type == FIT_BITMAP) || + (type == FIT_UINT16) || + (type == FIT_RGB16) || + (type == FIT_RGBA16) + ); +} + +// ---------------------------------------------------------- + +static void * DLL_CALLCONV +Open(FreeImageIO *io, fi_handle handle, BOOL read) { + return NULL; +} + +static void DLL_CALLCONV +Close(FreeImageIO *io, fi_handle handle, void *data) { +} + +// ---------------------------------------------------------- + +static FIBITMAP * DLL_CALLCONV +Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { + if (handle) { + opj_dparameters_t parameters; // decompression parameters + opj_event_mgr_t event_mgr; // event manager + opj_image_t *image = NULL; // decoded image + + BYTE *src = NULL; + long file_length; + + opj_dinfo_t* dinfo = NULL; // handle to a decompressor + opj_cio_t *cio = NULL; + + FIBITMAP *dib = NULL; + + // check the file format + if(!Validate(io, handle)) { + return NULL; + } + + // configure the event callbacks + memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); + event_mgr.error_handler = jp2_error_callback; + event_mgr.warning_handler = jp2_warning_callback; + event_mgr.info_handler = NULL; + + // set decoding parameters to default values + opj_set_default_decoder_parameters(¶meters); + + try { + // read the input file and put it in memory + + long start_pos = io->tell_proc(handle); + io->seek_proc(handle, 0, SEEK_END); + file_length = io->tell_proc(handle) - start_pos; + io->seek_proc(handle, start_pos, SEEK_SET); + src = (BYTE*)malloc(file_length * sizeof(BYTE)); + if(!src) { + throw FI_MSG_ERROR_MEMORY; + } + if(io->read_proc(src, 1, file_length, handle) < 1) { + throw "Error while reading input stream"; + } + + // decode the JPEG-2000 file + + // get a decoder handle + dinfo = opj_create_decompress(CODEC_JP2); + + // catch events using our callbacks + opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, NULL); + + // setup the decoder decoding parameters using user parameters + opj_setup_decoder(dinfo, ¶meters); + + // open a byte stream + cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); + + // decode the stream and fill the image structure + image = opj_decode(dinfo, cio); + if(!image) { + throw "Failed to decode image!\n"; + } + + // close the byte stream + opj_cio_close(cio); + cio = NULL; + + // free the memory containing the code-stream + free(src); + src = NULL; + + // free the codec context + opj_destroy_decompress(dinfo); + + // create output image + dib = J2KImageToFIBITMAP(s_format_id, image); + if(!dib) throw "Failed to import JPEG2000 image"; + + // free image data structure + opj_image_destroy(image); + + return dib; + + } catch (const char *text) { + if(src) free(src); + if(dib) FreeImage_Unload(dib); + // free remaining structures + opj_destroy_decompress(dinfo); + opj_image_destroy(image); + // close the byte stream + if(cio) opj_cio_close(cio); + + FreeImage_OutputMessageProc(s_format_id, text); + + return NULL; + } + } + + return NULL; +} + +static BOOL DLL_CALLCONV +Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) { + if ((dib) && (handle)) { + BOOL bSuccess; + opj_cparameters_t parameters; // compression parameters + opj_event_mgr_t event_mgr; // event manager + opj_image_t *image = NULL; // image to encode + opj_cinfo_t* cinfo = NULL; // codec context + opj_cio_t *cio = NULL; // memory byte stream + + // configure the event callbacks + memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); + event_mgr.error_handler = jp2_error_callback; + event_mgr.warning_handler = jp2_warning_callback; + event_mgr.info_handler = NULL; + + // set encoding parameters to default values + opj_set_default_encoder_parameters(¶meters); + + parameters.tcp_numlayers = 0; + // if no rate entered, apply a 16:1 rate by default + if(flags == JP2_DEFAULT) { + parameters.tcp_rates[0] = (float)16; + } else { + // for now, the flags parameter is only used to specify the rate + parameters.tcp_rates[0] = (float)flags; + } + parameters.tcp_numlayers++; + parameters.cp_disto_alloc = 1; + + try { + // convert the dib to a OpenJPEG image + image = FIBITMAPToJ2KImage(s_format_id, dib, ¶meters); + if(!image) return FALSE; + + // decide if MCT should be used + parameters.tcp_mct = (image->numcomps == 3) ? 1 : 0; + + // encode the destination image + + // get a J2K compressor handle + cinfo = opj_create_compress(CODEC_JP2); + + // catch events using our callbacks + opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, NULL); + + // setup the encoder parameters using the current image and using user parameters + opj_setup_encoder(cinfo, ¶meters, image); + + // open a byte stream for writing, allocate memory for all tiles + cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0); + + // encode the image + bSuccess = opj_encode(cinfo, cio, image, NULL/*parameters.index*/); + if (!bSuccess) { + throw "Failed to encode image"; + } + int codestream_length = cio_tell(cio); + + // write the buffer to user's IO handle + io->write_proc(cio->buffer, 1, codestream_length, handle); + + // close and free the byte stream + opj_cio_close(cio); + + // free remaining compression structures + opj_destroy_compress(cinfo); + + // free image data + opj_image_destroy(image); + + return TRUE; + + } catch (const char *text) { + if(cio) opj_cio_close(cio); + if(cinfo) opj_destroy_compress(cinfo); + if(image) opj_image_destroy(image); + FreeImage_OutputMessageProc(s_format_id, text); + return FALSE; + } + } + + return FALSE; +} + +// ========================================================== +// Init +// ========================================================== + +void DLL_CALLCONV +InitJP2(Plugin *plugin, int format_id) { + s_format_id = format_id; + + plugin->format_proc = Format; + plugin->description_proc = Description; + plugin->extension_proc = Extension; + plugin->regexpr_proc = RegExpr; + plugin->open_proc = Open; + plugin->close_proc = Close; + plugin->pagecount_proc = NULL; + plugin->pagecapability_proc = NULL; + plugin->load_proc = Load; + plugin->save_proc = Save; + plugin->validate_proc = Validate; + plugin->mime_proc = MimeType; + plugin->supports_export_bpp_proc = SupportsExportDepth; + plugin->supports_export_type_proc = SupportsExportType; + plugin->supports_icc_profiles_proc = NULL; +} diff --git a/Source/FreeImage/tmoColorConvert.cpp b/Source/FreeImage/tmoColorConvert.cpp index 66869b2..99dee54 100644 --- a/Source/FreeImage/tmoColorConvert.cpp +++ b/Source/FreeImage/tmoColorConvert.cpp @@ -1,479 +1,479 @@ -// ========================================================== -// High Dynamic Range bitmap conversion routines -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// - Mihail Naydenov (mnaydenov@users.sourceforge.net) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" -#include "ToneMapping.h" - -// ---------------------------------------------------------- -// Convert RGB to and from Yxy, same as in Reinhard et al. SIGGRAPH 2002 -// References : -// [1] Radiance Home Page [Online] http://radsite.lbl.gov/radiance/HOME.html -// [2] E. Reinhard, M. Stark, P. Shirley, and J. Ferwerda, -// Photographic Tone Reproduction for Digital Images, ACM Transactions on Graphics, -// 21(3):267-276, 2002 (Proceedings of SIGGRAPH 2002). -// [3] J. Tumblin and H.E. Rushmeier, -// Tone Reproduction for Realistic Images. IEEE Computer Graphics and Applications, -// 13(6):42-48, 1993. -// ---------------------------------------------------------- - -/** -nominal CRT primaries -*/ -/* -static const float CIE_x_r = 0.640F; -static const float CIE_y_r = 0.330F; -static const float CIE_x_g = 0.290F; -static const float CIE_y_g = 0.600F; -static const float CIE_x_b = 0.150F; -static const float CIE_y_b = 0.060F; -static const float CIE_x_w = 0.3333F; // use true white -static const float CIE_y_w = 0.3333F; -*/ -/** -sRGB primaries -*/ -static const float CIE_x_r = 0.640F; -static const float CIE_y_r = 0.330F; -static const float CIE_x_g = 0.300F; -static const float CIE_y_g = 0.600F; -static const float CIE_x_b = 0.150F; -static const float CIE_y_b = 0.060F; -static const float CIE_x_w = 0.3127F; // Illuminant D65 -static const float CIE_y_w = 0.3290F; - -static const float CIE_D = ( CIE_x_r*(CIE_y_g - CIE_y_b) + CIE_x_g*(CIE_y_b - CIE_y_r) + CIE_x_b*(CIE_y_r - CIE_y_g) ); -static const float CIE_C_rD = ( (1/CIE_y_w) * ( CIE_x_w*(CIE_y_g - CIE_y_b) - CIE_y_w*(CIE_x_g - CIE_x_b) + CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g) ); -static const float CIE_C_gD = ( (1/CIE_y_w) * ( CIE_x_w*(CIE_y_b - CIE_y_r) - CIE_y_w*(CIE_x_b - CIE_x_r) - CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r) ); -static const float CIE_C_bD = ( (1/CIE_y_w) * ( CIE_x_w*(CIE_y_r - CIE_y_g) - CIE_y_w*(CIE_x_r - CIE_x_g) + CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r) ); - -/** -RGB to XYZ (no white balance) -*/ -static const float RGB2XYZ[3][3] = { - { CIE_x_r*CIE_C_rD / CIE_D, - CIE_x_g*CIE_C_gD / CIE_D, - CIE_x_b*CIE_C_bD / CIE_D - }, - { CIE_y_r*CIE_C_rD / CIE_D, - CIE_y_g*CIE_C_gD / CIE_D, - CIE_y_b*CIE_C_bD / CIE_D - }, - { (1 - CIE_x_r-CIE_y_r)*CIE_C_rD / CIE_D, - (1 - CIE_x_g-CIE_y_g)*CIE_C_gD / CIE_D, - (1 - CIE_x_b-CIE_y_b)*CIE_C_bD / CIE_D - } -}; - -/** -XYZ to RGB (no white balance) -*/ -static const float XYZ2RGB[3][3] = { - {(CIE_y_g - CIE_y_b - CIE_x_b*CIE_y_g + CIE_y_b*CIE_x_g) / CIE_C_rD, - (CIE_x_b - CIE_x_g - CIE_x_b*CIE_y_g + CIE_x_g*CIE_y_b) / CIE_C_rD, - (CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g) / CIE_C_rD - }, - {(CIE_y_b - CIE_y_r - CIE_y_b*CIE_x_r + CIE_y_r*CIE_x_b) / CIE_C_gD, - (CIE_x_r - CIE_x_b - CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r) / CIE_C_gD, - (CIE_x_b*CIE_y_r - CIE_x_r*CIE_y_b) / CIE_C_gD - }, - {(CIE_y_r - CIE_y_g - CIE_y_r*CIE_x_g + CIE_y_g*CIE_x_r) / CIE_C_bD, - (CIE_x_g - CIE_x_r - CIE_x_g*CIE_y_r + CIE_x_r*CIE_y_g) / CIE_C_bD, - (CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r) / CIE_C_bD - } -}; - -/** -This gives approximately the following matrices : - -static const float RGB2XYZ[3][3] = { - { 0.41239083F, 0.35758433F, 0.18048081F }, - { 0.21263903F, 0.71516865F, 0.072192319F }, - { 0.019330820F, 0.11919473F, 0.95053220F } -}; -static const float XYZ2RGB[3][3] = { - { 3.2409699F, -1.5373832F, -0.49861079F }, - { -0.96924376F, 1.8759676F, 0.041555084F }, - { 0.055630036F, -0.20397687F, 1.0569715F } -}; -*/ - -// ---------------------------------------------------------- - -static const float EPSILON = 1e-06F; -static const float INF = 1e+10F; - -/** -Convert in-place floating point RGB data to Yxy.
-On output, pixel->red == Y, pixel->green == x, pixel->blue == y -@param dib Input RGBF / Output Yxy image -@return Returns TRUE if successful, returns FALSE otherwise -*/ -BOOL -ConvertInPlaceRGBFToYxy(FIBITMAP *dib) { - float result[3]; - - if(FreeImage_GetImageType(dib) != FIT_RGBF) - return FALSE; - - const unsigned width = FreeImage_GetWidth(dib); - const unsigned height = FreeImage_GetHeight(dib); - const unsigned pitch = FreeImage_GetPitch(dib); - - BYTE *bits = (BYTE*)FreeImage_GetBits(dib); - for(unsigned y = 0; y < height; y++) { - FIRGBF *pixel = (FIRGBF*)bits; - for(unsigned x = 0; x < width; x++) { - result[0] = result[1] = result[2] = 0; - for (int i = 0; i < 3; i++) { - result[i] += RGB2XYZ[i][0] * pixel[x].red; - result[i] += RGB2XYZ[i][1] * pixel[x].green; - result[i] += RGB2XYZ[i][2] * pixel[x].blue; - } - const float W = result[0] + result[1] + result[2]; - const float Y = result[1]; - if(W > 0) { - pixel[x].red = Y; // Y - pixel[x].green = result[0] / W; // x - pixel[x].blue = result[1] / W; // y - } else { - pixel[x].red = pixel[x].green = pixel[x].blue = 0; - } - } - // next line - bits += pitch; - } - - return TRUE; -} - -/** -Convert in-place Yxy image to floating point RGB data.
-On input, pixel->red == Y, pixel->green == x, pixel->blue == y -@param dib Input Yxy / Output RGBF image -@return Returns TRUE if successful, returns FALSE otherwise -*/ -BOOL -ConvertInPlaceYxyToRGBF(FIBITMAP *dib) { - float result[3]; - float X, Y, Z; - - if(FreeImage_GetImageType(dib) != FIT_RGBF) - return FALSE; - - const unsigned width = FreeImage_GetWidth(dib); - const unsigned height = FreeImage_GetHeight(dib); - const unsigned pitch = FreeImage_GetPitch(dib); - - BYTE *bits = (BYTE*)FreeImage_GetBits(dib); - for(unsigned y = 0; y < height; y++) { - FIRGBF *pixel = (FIRGBF*)bits; - for(unsigned x = 0; x < width; x++) { - Y = pixel[x].red; // Y - result[1] = pixel[x].green; // x - result[2] = pixel[x].blue; // y - if ((Y > EPSILON) && (result[1] > EPSILON) && (result[2] > EPSILON)) { - X = (result[1] * Y) / result[2]; - Z = (X / result[1]) - X - Y; - } else { - X = Z = EPSILON; - } - pixel[x].red = X; - pixel[x].green = Y; - pixel[x].blue = Z; - result[0] = result[1] = result[2] = 0; - for (int i = 0; i < 3; i++) { - result[i] += XYZ2RGB[i][0] * pixel[x].red; - result[i] += XYZ2RGB[i][1] * pixel[x].green; - result[i] += XYZ2RGB[i][2] * pixel[x].blue; - } - pixel[x].red = result[0]; // R - pixel[x].green = result[1]; // G - pixel[x].blue = result[2]; // B - } - // next line - bits += pitch; - } - - return TRUE; -} - -/** -Get the maximum, minimum and average luminance.
-On input, pixel->red == Y, pixel->green == x, pixel->blue == y -@param Yxy Source Yxy image to analyze -@param maxLum Maximum luminance -@param minLum Minimum luminance -@param worldLum Average luminance (world adaptation luminance) -@return Returns TRUE if successful, returns FALSE otherwise -*/ -BOOL -LuminanceFromYxy(FIBITMAP *Yxy, float *maxLum, float *minLum, float *worldLum) { - if(FreeImage_GetImageType(Yxy) != FIT_RGBF) - return FALSE; - - const unsigned width = FreeImage_GetWidth(Yxy); - const unsigned height = FreeImage_GetHeight(Yxy); - const unsigned pitch = FreeImage_GetPitch(Yxy); - - float max_lum = 0, min_lum = 0; - double sum = 0; - - BYTE *bits = (BYTE*)FreeImage_GetBits(Yxy); - for(unsigned y = 0; y < height; y++) { - const FIRGBF *pixel = (FIRGBF*)bits; - for(unsigned x = 0; x < width; x++) { - const float Y = pixel[x].red; - max_lum = (max_lum < Y) ? Y : max_lum; // max Luminance in the scene - min_lum = (min_lum < Y) ? min_lum : Y; // min Luminance in the scene - sum += log(2.3e-5F + Y); // contrast constant in Tumblin paper - } - // next line - bits += pitch; - } - // maximum luminance - *maxLum = max_lum; - // minimum luminance - *minLum = min_lum; - // average log luminance - double avgLogLum = (sum / (width * height)); - // world adaptation luminance - *worldLum = (float)exp(avgLogLum); - - return TRUE; -} - -/** -Clamp RGBF image highest values to display white, -then convert to 24-bit RGB -*/ -FIBITMAP* -ClampConvertRGBFTo24(FIBITMAP *src) { - if(FreeImage_GetImageType(src) != FIT_RGBF) - return FALSE; - - const unsigned width = FreeImage_GetWidth(src); - const unsigned height = FreeImage_GetHeight(src); - - FIBITMAP *dst = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - if(!dst) return NULL; - - const unsigned src_pitch = FreeImage_GetPitch(src); - const unsigned dst_pitch = FreeImage_GetPitch(dst); - - BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); - BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); - - for(unsigned y = 0; y < height; y++) { - const FIRGBF *src_pixel = (FIRGBF*)src_bits; - BYTE *dst_pixel = (BYTE*)dst_bits; - for(unsigned x = 0; x < width; x++) { - const float red = (src_pixel[x].red > 1) ? 1 : src_pixel[x].red; - const float green = (src_pixel[x].green > 1) ? 1 : src_pixel[x].green; - const float blue = (src_pixel[x].blue > 1) ? 1 : src_pixel[x].blue; - - dst_pixel[FI_RGBA_RED] = (BYTE)(255.0F * red + 0.5F); - dst_pixel[FI_RGBA_GREEN] = (BYTE)(255.0F * green + 0.5F); - dst_pixel[FI_RGBA_BLUE] = (BYTE)(255.0F * blue + 0.5F); - dst_pixel += 3; - } - src_bits += src_pitch; - dst_bits += dst_pitch; - } - - return dst; -} - -/** -Extract the luminance channel L from a RGBF image. -Luminance is calculated from the sRGB model (RGB2XYZ matrix) -using a D65 white point : -L = ( 0.2126 * r ) + ( 0.7152 * g ) + ( 0.0722 * b ) -Reference : -A Standard Default Color Space for the Internet - sRGB. -[online] http://www.w3.org/Graphics/Color/sRGB -*/ -FIBITMAP* -ConvertRGBFToY(FIBITMAP *src) { - if(FreeImage_GetImageType(src) != FIT_RGBF) - return FALSE; - - const unsigned width = FreeImage_GetWidth(src); - const unsigned height = FreeImage_GetHeight(src); - - FIBITMAP *dst = FreeImage_AllocateT(FIT_FLOAT, width, height); - if(!dst) return NULL; - - const unsigned src_pitch = FreeImage_GetPitch(src); - const unsigned dst_pitch = FreeImage_GetPitch(dst); - - - BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); - BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); - - for(unsigned y = 0; y < height; y++) { - const FIRGBF *src_pixel = (FIRGBF*)src_bits; - float *dst_pixel = (float*)dst_bits; - for(unsigned x = 0; x < width; x++) { - const float L = LUMA_REC709(src_pixel[x].red, src_pixel[x].green, src_pixel[x].blue); - dst_pixel[x] = (L > 0) ? L : 0; - } - // next line - src_bits += src_pitch; - dst_bits += dst_pitch; - } - - return dst; -} - -/** -Get the maximum, minimum, average luminance and log average luminance from a Y image -@param dib Source Y image to analyze -@param maxLum Maximum luminance -@param minLum Minimum luminance -@param Lav Average luminance -@param Llav Log average luminance (also known as 'world adaptation luminance') -@return Returns TRUE if successful, returns FALSE otherwise -@see ConvertRGBFToY, FreeImage_TmoReinhard05Ex -*/ -BOOL -LuminanceFromY(FIBITMAP *dib, float *maxLum, float *minLum, float *Lav, float *Llav) { - if(FreeImage_GetImageType(dib) != FIT_FLOAT) - return FALSE; - - unsigned width = FreeImage_GetWidth(dib); - unsigned height = FreeImage_GetHeight(dib); - unsigned pitch = FreeImage_GetPitch(dib); - - float max_lum = -1e20F, min_lum = 1e20F; - double sumLum = 0, sumLogLum = 0; - - BYTE *bits = (BYTE*)FreeImage_GetBits(dib); - for(unsigned y = 0; y < height; y++) { - const float *pixel = (float*)bits; - for(unsigned x = 0; x < width; x++) { - const float Y = pixel[x]; - max_lum = (max_lum < Y) ? Y : max_lum; // max Luminance in the scene - min_lum = ((Y > 0) && (min_lum < Y)) ? min_lum : Y; // min Luminance in the scene - sumLum += Y; // average luminance - sumLogLum += log(2.3e-5F + Y); // contrast constant in Tumblin paper - } - // next line - bits += pitch; - } - - // maximum luminance - *maxLum = max_lum; - // minimum luminance - *minLum = min_lum; - // average luminance - *Lav = (float)(sumLum / (width * height)); - // average log luminance, a.k.a. world adaptation luminance - *Llav = (float)exp(sumLogLum / (width * height)); - - return TRUE; -} -// -------------------------------------------------------------------------- - -static void findMaxMinPercentile(FIBITMAP *Y, float minPrct, float *minLum, float maxPrct, float *maxLum) { - int x, y; - int width = FreeImage_GetWidth(Y); - int height = FreeImage_GetHeight(Y); - int pitch = FreeImage_GetPitch(Y); - - std::vector vY(width * height); - - BYTE *bits = (BYTE*)FreeImage_GetBits(Y); - for(y = 0; y < height; y++) { - float *pixel = (float*)bits; - for(x = 0; x < width; x++) { - if(pixel[x] != 0) { - vY.push_back(pixel[x]); - } - } - bits += pitch; - } - - std::sort(vY.begin(), vY.end()); - - *minLum = vY.at( int(minPrct * vY.size()) ); - *maxLum = vY.at( int(maxPrct * vY.size()) ); -} - -/** -Clipping function
-Remove any extremely bright and/or extremely dark pixels -and normalize between 0 and 1. -@param Y Input/Output image -@param minPrct Minimum percentile -@param maxPrct Maximum percentile -*/ -void -NormalizeY(FIBITMAP *Y, float minPrct, float maxPrct) { - int x, y; - float maxLum, minLum; - - if(minPrct > maxPrct) { - // swap values - float t = minPrct; minPrct = maxPrct; maxPrct = t; - } - if(minPrct < 0) minPrct = 0; - if(maxPrct > 1) maxPrct = 1; - - int width = FreeImage_GetWidth(Y); - int height = FreeImage_GetHeight(Y); - int pitch = FreeImage_GetPitch(Y); - - // find max & min luminance values - if((minPrct > 0) || (maxPrct < 1)) { - maxLum = 0, minLum = 0; - findMaxMinPercentile(Y, minPrct, &minLum, maxPrct, &maxLum); - } else { - maxLum = -1e20F, minLum = 1e20F; - BYTE *bits = (BYTE*)FreeImage_GetBits(Y); - for(y = 0; y < height; y++) { - const float *pixel = (float*)bits; - for(x = 0; x < width; x++) { - const float value = pixel[x]; - maxLum = (maxLum < value) ? value : maxLum; // max Luminance in the scene - minLum = (minLum < value) ? minLum : value; // min Luminance in the scene - } - // next line - bits += pitch; - } - } - if(maxLum == minLum) return; - - // normalize to range 0..1 - const float divider = maxLum - minLum; - BYTE *bits = (BYTE*)FreeImage_GetBits(Y); - for(y = 0; y < height; y++) { - float *pixel = (float*)bits; - for(x = 0; x < width; x++) { - pixel[x] = (pixel[x] - minLum) / divider; - if(pixel[x] <= 0) pixel[x] = EPSILON; - if(pixel[x] > 1) pixel[x] = 1; - } - // next line - bits += pitch; - } -} +// ========================================================== +// High Dynamic Range bitmap conversion routines +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// - Mihail Naydenov (mnaydenov@users.sourceforge.net) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" +#include "ToneMapping.h" + +// ---------------------------------------------------------- +// Convert RGB to and from Yxy, same as in Reinhard et al. SIGGRAPH 2002 +// References : +// [1] Radiance Home Page [Online] http://radsite.lbl.gov/radiance/HOME.html +// [2] E. Reinhard, M. Stark, P. Shirley, and J. Ferwerda, +// Photographic Tone Reproduction for Digital Images, ACM Transactions on Graphics, +// 21(3):267-276, 2002 (Proceedings of SIGGRAPH 2002). +// [3] J. Tumblin and H.E. Rushmeier, +// Tone Reproduction for Realistic Images. IEEE Computer Graphics and Applications, +// 13(6):42-48, 1993. +// ---------------------------------------------------------- + +/** +nominal CRT primaries +*/ +/* +static const float CIE_x_r = 0.640F; +static const float CIE_y_r = 0.330F; +static const float CIE_x_g = 0.290F; +static const float CIE_y_g = 0.600F; +static const float CIE_x_b = 0.150F; +static const float CIE_y_b = 0.060F; +static const float CIE_x_w = 0.3333F; // use true white +static const float CIE_y_w = 0.3333F; +*/ +/** +sRGB primaries +*/ +static const float CIE_x_r = 0.640F; +static const float CIE_y_r = 0.330F; +static const float CIE_x_g = 0.300F; +static const float CIE_y_g = 0.600F; +static const float CIE_x_b = 0.150F; +static const float CIE_y_b = 0.060F; +static const float CIE_x_w = 0.3127F; // Illuminant D65 +static const float CIE_y_w = 0.3290F; + +static const float CIE_D = ( CIE_x_r*(CIE_y_g - CIE_y_b) + CIE_x_g*(CIE_y_b - CIE_y_r) + CIE_x_b*(CIE_y_r - CIE_y_g) ); +static const float CIE_C_rD = ( (1/CIE_y_w) * ( CIE_x_w*(CIE_y_g - CIE_y_b) - CIE_y_w*(CIE_x_g - CIE_x_b) + CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g) ); +static const float CIE_C_gD = ( (1/CIE_y_w) * ( CIE_x_w*(CIE_y_b - CIE_y_r) - CIE_y_w*(CIE_x_b - CIE_x_r) - CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r) ); +static const float CIE_C_bD = ( (1/CIE_y_w) * ( CIE_x_w*(CIE_y_r - CIE_y_g) - CIE_y_w*(CIE_x_r - CIE_x_g) + CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r) ); + +/** +RGB to XYZ (no white balance) +*/ +static const float RGB2XYZ[3][3] = { + { CIE_x_r*CIE_C_rD / CIE_D, + CIE_x_g*CIE_C_gD / CIE_D, + CIE_x_b*CIE_C_bD / CIE_D + }, + { CIE_y_r*CIE_C_rD / CIE_D, + CIE_y_g*CIE_C_gD / CIE_D, + CIE_y_b*CIE_C_bD / CIE_D + }, + { (1 - CIE_x_r-CIE_y_r)*CIE_C_rD / CIE_D, + (1 - CIE_x_g-CIE_y_g)*CIE_C_gD / CIE_D, + (1 - CIE_x_b-CIE_y_b)*CIE_C_bD / CIE_D + } +}; + +/** +XYZ to RGB (no white balance) +*/ +static const float XYZ2RGB[3][3] = { + {(CIE_y_g - CIE_y_b - CIE_x_b*CIE_y_g + CIE_y_b*CIE_x_g) / CIE_C_rD, + (CIE_x_b - CIE_x_g - CIE_x_b*CIE_y_g + CIE_x_g*CIE_y_b) / CIE_C_rD, + (CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g) / CIE_C_rD + }, + {(CIE_y_b - CIE_y_r - CIE_y_b*CIE_x_r + CIE_y_r*CIE_x_b) / CIE_C_gD, + (CIE_x_r - CIE_x_b - CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r) / CIE_C_gD, + (CIE_x_b*CIE_y_r - CIE_x_r*CIE_y_b) / CIE_C_gD + }, + {(CIE_y_r - CIE_y_g - CIE_y_r*CIE_x_g + CIE_y_g*CIE_x_r) / CIE_C_bD, + (CIE_x_g - CIE_x_r - CIE_x_g*CIE_y_r + CIE_x_r*CIE_y_g) / CIE_C_bD, + (CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r) / CIE_C_bD + } +}; + +/** +This gives approximately the following matrices : + +static const float RGB2XYZ[3][3] = { + { 0.41239083F, 0.35758433F, 0.18048081F }, + { 0.21263903F, 0.71516865F, 0.072192319F }, + { 0.019330820F, 0.11919473F, 0.95053220F } +}; +static const float XYZ2RGB[3][3] = { + { 3.2409699F, -1.5373832F, -0.49861079F }, + { -0.96924376F, 1.8759676F, 0.041555084F }, + { 0.055630036F, -0.20397687F, 1.0569715F } +}; +*/ + +// ---------------------------------------------------------- + +static const float EPSILON = 1e-06F; +static const float INF = 1e+10F; + +/** +Convert in-place floating point RGB data to Yxy.
+On output, pixel->red == Y, pixel->green == x, pixel->blue == y +@param dib Input RGBF / Output Yxy image +@return Returns TRUE if successful, returns FALSE otherwise +*/ +BOOL +ConvertInPlaceRGBFToYxy(FIBITMAP *dib) { + float result[3]; + + if(FreeImage_GetImageType(dib) != FIT_RGBF) + return FALSE; + + const unsigned width = FreeImage_GetWidth(dib); + const unsigned height = FreeImage_GetHeight(dib); + const unsigned pitch = FreeImage_GetPitch(dib); + + BYTE *bits = (BYTE*)FreeImage_GetBits(dib); + for(unsigned y = 0; y < height; y++) { + FIRGBF *pixel = (FIRGBF*)bits; + for(unsigned x = 0; x < width; x++) { + result[0] = result[1] = result[2] = 0; + for (int i = 0; i < 3; i++) { + result[i] += RGB2XYZ[i][0] * pixel[x].red; + result[i] += RGB2XYZ[i][1] * pixel[x].green; + result[i] += RGB2XYZ[i][2] * pixel[x].blue; + } + const float W = result[0] + result[1] + result[2]; + const float Y = result[1]; + if(W > 0) { + pixel[x].red = Y; // Y + pixel[x].green = result[0] / W; // x + pixel[x].blue = result[1] / W; // y + } else { + pixel[x].red = pixel[x].green = pixel[x].blue = 0; + } + } + // next line + bits += pitch; + } + + return TRUE; +} + +/** +Convert in-place Yxy image to floating point RGB data.
+On input, pixel->red == Y, pixel->green == x, pixel->blue == y +@param dib Input Yxy / Output RGBF image +@return Returns TRUE if successful, returns FALSE otherwise +*/ +BOOL +ConvertInPlaceYxyToRGBF(FIBITMAP *dib) { + float result[3]; + float X, Y, Z; + + if(FreeImage_GetImageType(dib) != FIT_RGBF) + return FALSE; + + const unsigned width = FreeImage_GetWidth(dib); + const unsigned height = FreeImage_GetHeight(dib); + const unsigned pitch = FreeImage_GetPitch(dib); + + BYTE *bits = (BYTE*)FreeImage_GetBits(dib); + for(unsigned y = 0; y < height; y++) { + FIRGBF *pixel = (FIRGBF*)bits; + for(unsigned x = 0; x < width; x++) { + Y = pixel[x].red; // Y + result[1] = pixel[x].green; // x + result[2] = pixel[x].blue; // y + if ((Y > EPSILON) && (result[1] > EPSILON) && (result[2] > EPSILON)) { + X = (result[1] * Y) / result[2]; + Z = (X / result[1]) - X - Y; + } else { + X = Z = EPSILON; + } + pixel[x].red = X; + pixel[x].green = Y; + pixel[x].blue = Z; + result[0] = result[1] = result[2] = 0; + for (int i = 0; i < 3; i++) { + result[i] += XYZ2RGB[i][0] * pixel[x].red; + result[i] += XYZ2RGB[i][1] * pixel[x].green; + result[i] += XYZ2RGB[i][2] * pixel[x].blue; + } + pixel[x].red = result[0]; // R + pixel[x].green = result[1]; // G + pixel[x].blue = result[2]; // B + } + // next line + bits += pitch; + } + + return TRUE; +} + +/** +Get the maximum, minimum and average luminance.
+On input, pixel->red == Y, pixel->green == x, pixel->blue == y +@param Yxy Source Yxy image to analyze +@param maxLum Maximum luminance +@param minLum Minimum luminance +@param worldLum Average luminance (world adaptation luminance) +@return Returns TRUE if successful, returns FALSE otherwise +*/ +BOOL +LuminanceFromYxy(FIBITMAP *Yxy, float *maxLum, float *minLum, float *worldLum) { + if(FreeImage_GetImageType(Yxy) != FIT_RGBF) + return FALSE; + + const unsigned width = FreeImage_GetWidth(Yxy); + const unsigned height = FreeImage_GetHeight(Yxy); + const unsigned pitch = FreeImage_GetPitch(Yxy); + + float max_lum = 0, min_lum = 0; + double sum = 0; + + BYTE *bits = (BYTE*)FreeImage_GetBits(Yxy); + for(unsigned y = 0; y < height; y++) { + const FIRGBF *pixel = (FIRGBF*)bits; + for(unsigned x = 0; x < width; x++) { + const float Y = pixel[x].red; + max_lum = (max_lum < Y) ? Y : max_lum; // max Luminance in the scene + min_lum = (min_lum < Y) ? min_lum : Y; // min Luminance in the scene + sum += log(2.3e-5F + Y); // contrast constant in Tumblin paper + } + // next line + bits += pitch; + } + // maximum luminance + *maxLum = max_lum; + // minimum luminance + *minLum = min_lum; + // average log luminance + double avgLogLum = (sum / (width * height)); + // world adaptation luminance + *worldLum = (float)exp(avgLogLum); + + return TRUE; +} + +/** +Clamp RGBF image highest values to display white, +then convert to 24-bit RGB +*/ +FIBITMAP* +ClampConvertRGBFTo24(FIBITMAP *src) { + if(FreeImage_GetImageType(src) != FIT_RGBF) + return FALSE; + + const unsigned width = FreeImage_GetWidth(src); + const unsigned height = FreeImage_GetHeight(src); + + FIBITMAP *dst = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + if(!dst) return NULL; + + const unsigned src_pitch = FreeImage_GetPitch(src); + const unsigned dst_pitch = FreeImage_GetPitch(dst); + + BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); + BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); + + for(unsigned y = 0; y < height; y++) { + const FIRGBF *src_pixel = (FIRGBF*)src_bits; + BYTE *dst_pixel = (BYTE*)dst_bits; + for(unsigned x = 0; x < width; x++) { + const float red = (src_pixel[x].red > 1) ? 1 : src_pixel[x].red; + const float green = (src_pixel[x].green > 1) ? 1 : src_pixel[x].green; + const float blue = (src_pixel[x].blue > 1) ? 1 : src_pixel[x].blue; + + dst_pixel[FI_RGBA_RED] = (BYTE)(255.0F * red + 0.5F); + dst_pixel[FI_RGBA_GREEN] = (BYTE)(255.0F * green + 0.5F); + dst_pixel[FI_RGBA_BLUE] = (BYTE)(255.0F * blue + 0.5F); + dst_pixel += 3; + } + src_bits += src_pitch; + dst_bits += dst_pitch; + } + + return dst; +} + +/** +Extract the luminance channel L from a RGBF image. +Luminance is calculated from the sRGB model (RGB2XYZ matrix) +using a D65 white point : +L = ( 0.2126 * r ) + ( 0.7152 * g ) + ( 0.0722 * b ) +Reference : +A Standard Default Color Space for the Internet - sRGB. +[online] http://www.w3.org/Graphics/Color/sRGB +*/ +FIBITMAP* +ConvertRGBFToY(FIBITMAP *src) { + if(FreeImage_GetImageType(src) != FIT_RGBF) + return FALSE; + + const unsigned width = FreeImage_GetWidth(src); + const unsigned height = FreeImage_GetHeight(src); + + FIBITMAP *dst = FreeImage_AllocateT(FIT_FLOAT, width, height); + if(!dst) return NULL; + + const unsigned src_pitch = FreeImage_GetPitch(src); + const unsigned dst_pitch = FreeImage_GetPitch(dst); + + + BYTE *src_bits = (BYTE*)FreeImage_GetBits(src); + BYTE *dst_bits = (BYTE*)FreeImage_GetBits(dst); + + for(unsigned y = 0; y < height; y++) { + const FIRGBF *src_pixel = (FIRGBF*)src_bits; + float *dst_pixel = (float*)dst_bits; + for(unsigned x = 0; x < width; x++) { + const float L = LUMA_REC709(src_pixel[x].red, src_pixel[x].green, src_pixel[x].blue); + dst_pixel[x] = (L > 0) ? L : 0; + } + // next line + src_bits += src_pitch; + dst_bits += dst_pitch; + } + + return dst; +} + +/** +Get the maximum, minimum, average luminance and log average luminance from a Y image +@param dib Source Y image to analyze +@param maxLum Maximum luminance +@param minLum Minimum luminance +@param Lav Average luminance +@param Llav Log average luminance (also known as 'world adaptation luminance') +@return Returns TRUE if successful, returns FALSE otherwise +@see ConvertRGBFToY, FreeImage_TmoReinhard05Ex +*/ +BOOL +LuminanceFromY(FIBITMAP *dib, float *maxLum, float *minLum, float *Lav, float *Llav) { + if(FreeImage_GetImageType(dib) != FIT_FLOAT) + return FALSE; + + unsigned width = FreeImage_GetWidth(dib); + unsigned height = FreeImage_GetHeight(dib); + unsigned pitch = FreeImage_GetPitch(dib); + + float max_lum = -1e20F, min_lum = 1e20F; + double sumLum = 0, sumLogLum = 0; + + BYTE *bits = (BYTE*)FreeImage_GetBits(dib); + for(unsigned y = 0; y < height; y++) { + const float *pixel = (float*)bits; + for(unsigned x = 0; x < width; x++) { + const float Y = pixel[x]; + max_lum = (max_lum < Y) ? Y : max_lum; // max Luminance in the scene + min_lum = ((Y > 0) && (min_lum < Y)) ? min_lum : Y; // min Luminance in the scene + sumLum += Y; // average luminance + sumLogLum += log(2.3e-5F + Y); // contrast constant in Tumblin paper + } + // next line + bits += pitch; + } + + // maximum luminance + *maxLum = max_lum; + // minimum luminance + *minLum = min_lum; + // average luminance + *Lav = (float)(sumLum / (width * height)); + // average log luminance, a.k.a. world adaptation luminance + *Llav = (float)exp(sumLogLum / (width * height)); + + return TRUE; +} +// -------------------------------------------------------------------------- + +static void findMaxMinPercentile(FIBITMAP *Y, float minPrct, float *minLum, float maxPrct, float *maxLum) { + int x, y; + int width = FreeImage_GetWidth(Y); + int height = FreeImage_GetHeight(Y); + int pitch = FreeImage_GetPitch(Y); + + std::vector vY(width * height); + + BYTE *bits = (BYTE*)FreeImage_GetBits(Y); + for(y = 0; y < height; y++) { + float *pixel = (float*)bits; + for(x = 0; x < width; x++) { + if(pixel[x] != 0) { + vY.push_back(pixel[x]); + } + } + bits += pitch; + } + + std::sort(vY.begin(), vY.end()); + + *minLum = vY.at( int(minPrct * vY.size()) ); + *maxLum = vY.at( int(maxPrct * vY.size()) ); +} + +/** +Clipping function
+Remove any extremely bright and/or extremely dark pixels +and normalize between 0 and 1. +@param Y Input/Output image +@param minPrct Minimum percentile +@param maxPrct Maximum percentile +*/ +void +NormalizeY(FIBITMAP *Y, float minPrct, float maxPrct) { + int x, y; + float maxLum, minLum; + + if(minPrct > maxPrct) { + // swap values + float t = minPrct; minPrct = maxPrct; maxPrct = t; + } + if(minPrct < 0) minPrct = 0; + if(maxPrct > 1) maxPrct = 1; + + int width = FreeImage_GetWidth(Y); + int height = FreeImage_GetHeight(Y); + int pitch = FreeImage_GetPitch(Y); + + // find max & min luminance values + if((minPrct > 0) || (maxPrct < 1)) { + maxLum = 0, minLum = 0; + findMaxMinPercentile(Y, minPrct, &minLum, maxPrct, &maxLum); + } else { + maxLum = -1e20F, minLum = 1e20F; + BYTE *bits = (BYTE*)FreeImage_GetBits(Y); + for(y = 0; y < height; y++) { + const float *pixel = (float*)bits; + for(x = 0; x < width; x++) { + const float value = pixel[x]; + maxLum = (maxLum < value) ? value : maxLum; // max Luminance in the scene + minLum = (minLum < value) ? minLum : value; // min Luminance in the scene + } + // next line + bits += pitch; + } + } + if(maxLum == minLum) return; + + // normalize to range 0..1 + const float divider = maxLum - minLum; + BYTE *bits = (BYTE*)FreeImage_GetBits(Y); + for(y = 0; y < height; y++) { + float *pixel = (float*)bits; + for(x = 0; x < width; x++) { + pixel[x] = (pixel[x] - minLum) / divider; + if(pixel[x] <= 0) pixel[x] = EPSILON; + if(pixel[x] > 1) pixel[x] = 1; + } + // next line + bits += pitch; + } +} diff --git a/Source/FreeImage/tmoDrago03.cpp b/Source/FreeImage/tmoDrago03.cpp index a615344..d46a8c8 100644 --- a/Source/FreeImage/tmoDrago03.cpp +++ b/Source/FreeImage/tmoDrago03.cpp @@ -1,295 +1,295 @@ -// ========================================================== -// Tone mapping operator (Drago, 2003) -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" -#include "ToneMapping.h" - -// ---------------------------------------------------------- -// Logarithmic mapping operator -// Reference: -// [1] F. Drago, K. Myszkowski, T. Annen, and N. Chiba, -// Adaptive Logarithmic Mapping for Displaying High Contrast Scenes, -// Eurographics 2003. -// ---------------------------------------------------------- - -/** -Bias function -*/ -static inline double -biasFunction(const double b, const double x) { - return pow (x, b); // pow(x, log(bias)/log(0.5) -} - -/** -Padé approximation of log(x + 1) -x(6+x)/(6+4x) good if x < 1 -x*(6 + 0.7662x)/(5.9897 + 3.7658x) between 1 and 2 -See http://www.nezumi.demon.co.uk/consult/logx.htm -*/ -static inline double -pade_log(const double x) { - if(x < 1) { - return (x * (6 + x) / (6 + 4 * x)); - } else if(x < 2) { - return (x * (6 + 0.7662 * x) / (5.9897 + 3.7658 * x)); - } - return log(x + 1); -} - -/** -Log mapping operator -@param dib Input / Output Yxy image -@param maxLum Maximum luminance -@param avgLum Average luminance (world adaptation luminance) -@param biasParam Bias parameter (a zero value default to 0.85) -@param exposure Exposure parameter (default to 0) -@return Returns TRUE if successful, returns FALSE otherwise -*/ -static BOOL -ToneMappingDrago03(FIBITMAP *dib, const float maxLum, const float avgLum, float biasParam, const float exposure) { - const float LOG05 = -0.693147F; // log(0.5) - - double Lmax, divider, interpol, biasP; - unsigned x, y; - double L; - - if(FreeImage_GetImageType(dib) != FIT_RGBF) - return FALSE; - - const unsigned width = FreeImage_GetWidth(dib); - const unsigned height = FreeImage_GetHeight(dib); - const unsigned pitch = FreeImage_GetPitch(dib); - - - // arbitrary Bias Parameter - if(biasParam == 0) - biasParam = 0.85F; - - // normalize maximum luminance by average luminance - Lmax = maxLum / avgLum; - - divider = log10(Lmax+1); - biasP = log(biasParam)/LOG05; - -#if !defined(DRAGO03_FAST) - - /** - Normal tone mapping of every pixel - further acceleration is obtained by a Padé approximation of log(x + 1) - */ - BYTE *bits = (BYTE*)FreeImage_GetBits(dib); - for(y = 0; y < height; y++) { - FIRGBF *pixel = (FIRGBF*)bits; - for(x = 0; x < width; x++) { - double Yw = pixel[x].red / avgLum; - Yw *= exposure; - interpol = log(2 + biasFunction(biasP, Yw / Lmax) * 8); - L = pade_log(Yw);// log(Yw + 1) - pixel[x].red = (float)((L / interpol) / divider); - } - // next line - bits += pitch; - } - -#else - unsigned index; - int i, j; - - unsigned max_width = width - (width % 3); - unsigned max_height = height - (height % 3); - unsigned fpitch = pitch / sizeof(FIRGBF); - - /** - fast tone mapping - split the image into 3x3 pixel tiles and perform the computation for each group of 9 pixels - further acceleration is obtained by a Padé approximation of log(x + 1) - => produce artifacts and not so faster, so the code has been disabled - */ -#define PIXEL(x, y) image[y*fpitch + x].red - - FIRGBF *image = (FIRGBF*)FreeImage_GetBits(dib); - for(y = 0; y < max_height; y += 3) { - for(x = 0; x < max_width; x += 3) { - double average = 0; - for(i = 0; i < 3; i++) { - for(j = 0; j < 3; j++) { - index = (y + i)*fpitch + (x + j); - image[index].red /= (float)avgLum; - image[index].red *= exposure; - average += image[index].red; - } - } - average = average / 9 - PIXEL(x, y); - if(average > -1 && average < 1) { - interpol = log(2 + pow(PIXEL(x + 1, y + 1) / Lmax, biasP) * 8); - for(i = 0; i < 3; i++) { - for(j = 0; j < 3; j++) { - index = (y + i)*fpitch + (x + j); - L = pade_log(image[index].red);// log(image[index].red + 1) - image[index].red = (float)((L / interpol) / divider); - } - } - } - else { - for(i = 0; i < 3; i++) { - for(j = 0; j < 3; j++) { - index = (y + i)*fpitch + (x + j); - interpol = log(2 + pow(image[index].red / Lmax, biasP) * 8); - L = pade_log(image[index].red);// log(image[index].red + 1) - image[index].red = (float)((L / interpol) / divider); - } - } - } - } //x - } // y - - /** - Normal tone mapping of every pixel for the remaining right and bottom bands - */ - BYTE *bits; - - // right band - bits = (BYTE*)FreeImage_GetBits(dib); - for(y = 0; y < height; y++) { - FIRGBF *pixel = (FIRGBF*)bits; - for(x = max_width; x < width; x++) { - double Yw = pixel[x].red / avgLum; - Yw *= exposure; - interpol = log(2 + biasFunction(biasP, Yw / Lmax) * 8); - L = pade_log(Yw);// log(Yw + 1) - pixel[x].red = (float)((L / interpol) / divider); - } - // next line - bits += pitch; - } - // bottom band - bits = (BYTE*)FreeImage_GetBits(dib); - for(y = max_height; y < height; y++) { - FIRGBF *pixel = (FIRGBF*)bits; - for(x = 0; x < max_width; x++) { - double Yw = pixel[x].red / avgLum; - Yw *= exposure; - interpol = log(2 + biasFunction(biasP, Yw / Lmax) * 8); - L = pade_log(Yw);// log(Yw + 1) - pixel[x].red = (float)((L / interpol) / divider); - } - // next line - bits += pitch; - } - -#endif // DRAGO03_FAST - - return TRUE; -} - -/** -Custom gamma correction based on the ITU-R BT.709 standard -@param dib RGBF image to be corrected -@param gammaval Gamma value (2.2 is a good default value) -@return Returns TRUE if successful, returns FALSE otherwise -*/ -static BOOL -REC709GammaCorrection(FIBITMAP *dib, const float gammaval) { - if(FreeImage_GetImageType(dib) != FIT_RGBF) - return FALSE; - - float slope = 4.5F; - float start = 0.018F; - - const float fgamma = (float)((0.45 / gammaval) * 2); - if(gammaval >= 2.1F) { - start = (float)(0.018 / ((gammaval - 2) * 7.5)); - slope = (float)(4.5 * ((gammaval - 2) * 7.5)); - } else if (gammaval <= 1.9F) { - start = (float)(0.018 * ((2 - gammaval) * 7.5)); - slope = (float)(4.5 / ((2 - gammaval) * 7.5)); - } - - const unsigned width = FreeImage_GetWidth(dib); - const unsigned height = FreeImage_GetHeight(dib); - const unsigned pitch = FreeImage_GetPitch(dib); - - BYTE *bits = (BYTE*)FreeImage_GetBits(dib); - for(unsigned y = 0; y < height; y++) { - float *pixel = (float*)bits; - for(unsigned x = 0; x < width; x++) { - for(int i = 0; i < 3; i++) { - *pixel = (*pixel <= start) ? *pixel * slope : (1.099F * pow(*pixel, fgamma) - 0.099F); - pixel++; - } - } - bits += pitch; - } - - return TRUE; -} - -// ---------------------------------------------------------- -// Main algorithm -// ---------------------------------------------------------- - -/** -Apply the Adaptive Logarithmic Mapping operator to a HDR image and convert to 24-bit RGB -@param src Input RGB16 or RGB[A]F image -@param gamma Gamma correction (gamma > 0). 1 means no correction, 2.2 in the original paper. -@param exposure Exposure parameter (0 means no correction, 0 in the original paper) -@return Returns a 24-bit RGB image if successful, returns NULL otherwise -*/ -FIBITMAP* DLL_CALLCONV -FreeImage_TmoDrago03(FIBITMAP *src, double gamma, double exposure) { - float maxLum, minLum, avgLum; - - if(!FreeImage_HasPixels(src)) return NULL; - - // working RGBF variable - FIBITMAP *dib = NULL; - - dib = FreeImage_ConvertToRGBF(src); - if(!dib) return NULL; - - // default algorithm parameters - const float biasParam = 0.85F; - const float expoParam = (float)pow(2.0, exposure); //default exposure is 1, 2^0 - - // convert to Yxy - ConvertInPlaceRGBFToYxy(dib); - // get the luminance - LuminanceFromYxy(dib, &maxLum, &minLum, &avgLum); - // perform the tone mapping - ToneMappingDrago03(dib, maxLum, avgLum, biasParam, expoParam); - // convert back to RGBF - ConvertInPlaceYxyToRGBF(dib); - if(gamma != 1) { - // perform gamma correction - REC709GammaCorrection(dib, (float)gamma); - } - // clamp image highest values to display white, then convert to 24-bit RGB - FIBITMAP *dst = ClampConvertRGBFTo24(dib); - - // clean-up and return - FreeImage_Unload(dib); - - // copy metadata from src to dst - FreeImage_CloneMetadata(dst, src); - - return dst; -} +// ========================================================== +// Tone mapping operator (Drago, 2003) +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" +#include "ToneMapping.h" + +// ---------------------------------------------------------- +// Logarithmic mapping operator +// Reference: +// [1] F. Drago, K. Myszkowski, T. Annen, and N. Chiba, +// Adaptive Logarithmic Mapping for Displaying High Contrast Scenes, +// Eurographics 2003. +// ---------------------------------------------------------- + +/** +Bias function +*/ +static inline double +biasFunction(const double b, const double x) { + return pow (x, b); // pow(x, log(bias)/log(0.5) +} + +/** +Padé approximation of log(x + 1) +x(6+x)/(6+4x) good if x < 1 +x*(6 + 0.7662x)/(5.9897 + 3.7658x) between 1 and 2 +See http://www.nezumi.demon.co.uk/consult/logx.htm +*/ +static inline double +pade_log(const double x) { + if(x < 1) { + return (x * (6 + x) / (6 + 4 * x)); + } else if(x < 2) { + return (x * (6 + 0.7662 * x) / (5.9897 + 3.7658 * x)); + } + return log(x + 1); +} + +/** +Log mapping operator +@param dib Input / Output Yxy image +@param maxLum Maximum luminance +@param avgLum Average luminance (world adaptation luminance) +@param biasParam Bias parameter (a zero value default to 0.85) +@param exposure Exposure parameter (default to 0) +@return Returns TRUE if successful, returns FALSE otherwise +*/ +static BOOL +ToneMappingDrago03(FIBITMAP *dib, const float maxLum, const float avgLum, float biasParam, const float exposure) { + const float LOG05 = -0.693147F; // log(0.5) + + double Lmax, divider, interpol, biasP; + unsigned x, y; + double L; + + if(FreeImage_GetImageType(dib) != FIT_RGBF) + return FALSE; + + const unsigned width = FreeImage_GetWidth(dib); + const unsigned height = FreeImage_GetHeight(dib); + const unsigned pitch = FreeImage_GetPitch(dib); + + + // arbitrary Bias Parameter + if(biasParam == 0) + biasParam = 0.85F; + + // normalize maximum luminance by average luminance + Lmax = maxLum / avgLum; + + divider = log10(Lmax+1); + biasP = log(biasParam)/LOG05; + +#if !defined(DRAGO03_FAST) + + /** + Normal tone mapping of every pixel + further acceleration is obtained by a Padé approximation of log(x + 1) + */ + BYTE *bits = (BYTE*)FreeImage_GetBits(dib); + for(y = 0; y < height; y++) { + FIRGBF *pixel = (FIRGBF*)bits; + for(x = 0; x < width; x++) { + double Yw = pixel[x].red / avgLum; + Yw *= exposure; + interpol = log(2 + biasFunction(biasP, Yw / Lmax) * 8); + L = pade_log(Yw);// log(Yw + 1) + pixel[x].red = (float)((L / interpol) / divider); + } + // next line + bits += pitch; + } + +#else + unsigned index; + int i, j; + + unsigned max_width = width - (width % 3); + unsigned max_height = height - (height % 3); + unsigned fpitch = pitch / sizeof(FIRGBF); + + /** + fast tone mapping + split the image into 3x3 pixel tiles and perform the computation for each group of 9 pixels + further acceleration is obtained by a Padé approximation of log(x + 1) + => produce artifacts and not so faster, so the code has been disabled + */ +#define PIXEL(x, y) image[y*fpitch + x].red + + FIRGBF *image = (FIRGBF*)FreeImage_GetBits(dib); + for(y = 0; y < max_height; y += 3) { + for(x = 0; x < max_width; x += 3) { + double average = 0; + for(i = 0; i < 3; i++) { + for(j = 0; j < 3; j++) { + index = (y + i)*fpitch + (x + j); + image[index].red /= (float)avgLum; + image[index].red *= exposure; + average += image[index].red; + } + } + average = average / 9 - PIXEL(x, y); + if(average > -1 && average < 1) { + interpol = log(2 + pow(PIXEL(x + 1, y + 1) / Lmax, biasP) * 8); + for(i = 0; i < 3; i++) { + for(j = 0; j < 3; j++) { + index = (y + i)*fpitch + (x + j); + L = pade_log(image[index].red);// log(image[index].red + 1) + image[index].red = (float)((L / interpol) / divider); + } + } + } + else { + for(i = 0; i < 3; i++) { + for(j = 0; j < 3; j++) { + index = (y + i)*fpitch + (x + j); + interpol = log(2 + pow(image[index].red / Lmax, biasP) * 8); + L = pade_log(image[index].red);// log(image[index].red + 1) + image[index].red = (float)((L / interpol) / divider); + } + } + } + } //x + } // y + + /** + Normal tone mapping of every pixel for the remaining right and bottom bands + */ + BYTE *bits; + + // right band + bits = (BYTE*)FreeImage_GetBits(dib); + for(y = 0; y < height; y++) { + FIRGBF *pixel = (FIRGBF*)bits; + for(x = max_width; x < width; x++) { + double Yw = pixel[x].red / avgLum; + Yw *= exposure; + interpol = log(2 + biasFunction(biasP, Yw / Lmax) * 8); + L = pade_log(Yw);// log(Yw + 1) + pixel[x].red = (float)((L / interpol) / divider); + } + // next line + bits += pitch; + } + // bottom band + bits = (BYTE*)FreeImage_GetBits(dib); + for(y = max_height; y < height; y++) { + FIRGBF *pixel = (FIRGBF*)bits; + for(x = 0; x < max_width; x++) { + double Yw = pixel[x].red / avgLum; + Yw *= exposure; + interpol = log(2 + biasFunction(biasP, Yw / Lmax) * 8); + L = pade_log(Yw);// log(Yw + 1) + pixel[x].red = (float)((L / interpol) / divider); + } + // next line + bits += pitch; + } + +#endif // DRAGO03_FAST + + return TRUE; +} + +/** +Custom gamma correction based on the ITU-R BT.709 standard +@param dib RGBF image to be corrected +@param gammaval Gamma value (2.2 is a good default value) +@return Returns TRUE if successful, returns FALSE otherwise +*/ +static BOOL +REC709GammaCorrection(FIBITMAP *dib, const float gammaval) { + if(FreeImage_GetImageType(dib) != FIT_RGBF) + return FALSE; + + float slope = 4.5F; + float start = 0.018F; + + const float fgamma = (float)((0.45 / gammaval) * 2); + if(gammaval >= 2.1F) { + start = (float)(0.018 / ((gammaval - 2) * 7.5)); + slope = (float)(4.5 * ((gammaval - 2) * 7.5)); + } else if (gammaval <= 1.9F) { + start = (float)(0.018 * ((2 - gammaval) * 7.5)); + slope = (float)(4.5 / ((2 - gammaval) * 7.5)); + } + + const unsigned width = FreeImage_GetWidth(dib); + const unsigned height = FreeImage_GetHeight(dib); + const unsigned pitch = FreeImage_GetPitch(dib); + + BYTE *bits = (BYTE*)FreeImage_GetBits(dib); + for(unsigned y = 0; y < height; y++) { + float *pixel = (float*)bits; + for(unsigned x = 0; x < width; x++) { + for(int i = 0; i < 3; i++) { + *pixel = (*pixel <= start) ? *pixel * slope : (1.099F * pow(*pixel, fgamma) - 0.099F); + pixel++; + } + } + bits += pitch; + } + + return TRUE; +} + +// ---------------------------------------------------------- +// Main algorithm +// ---------------------------------------------------------- + +/** +Apply the Adaptive Logarithmic Mapping operator to a HDR image and convert to 24-bit RGB +@param src Input RGB16 or RGB[A]F image +@param gamma Gamma correction (gamma > 0). 1 means no correction, 2.2 in the original paper. +@param exposure Exposure parameter (0 means no correction, 0 in the original paper) +@return Returns a 24-bit RGB image if successful, returns NULL otherwise +*/ +FIBITMAP* DLL_CALLCONV +FreeImage_TmoDrago03(FIBITMAP *src, double gamma, double exposure) { + float maxLum, minLum, avgLum; + + if(!FreeImage_HasPixels(src)) return NULL; + + // working RGBF variable + FIBITMAP *dib = NULL; + + dib = FreeImage_ConvertToRGBF(src); + if(!dib) return NULL; + + // default algorithm parameters + const float biasParam = 0.85F; + const float expoParam = (float)pow(2.0, exposure); //default exposure is 1, 2^0 + + // convert to Yxy + ConvertInPlaceRGBFToYxy(dib); + // get the luminance + LuminanceFromYxy(dib, &maxLum, &minLum, &avgLum); + // perform the tone mapping + ToneMappingDrago03(dib, maxLum, avgLum, biasParam, expoParam); + // convert back to RGBF + ConvertInPlaceYxyToRGBF(dib); + if(gamma != 1) { + // perform gamma correction + REC709GammaCorrection(dib, (float)gamma); + } + // clamp image highest values to display white, then convert to 24-bit RGB + FIBITMAP *dst = ClampConvertRGBFTo24(dib); + + // clean-up and return + FreeImage_Unload(dib); + + // copy metadata from src to dst + FreeImage_CloneMetadata(dst, src); + + return dst; +} diff --git a/Source/FreeImage/tmoFattal02.cpp b/Source/FreeImage/tmoFattal02.cpp index 88f0544..c63f91f 100644 --- a/Source/FreeImage/tmoFattal02.cpp +++ b/Source/FreeImage/tmoFattal02.cpp @@ -1,689 +1,689 @@ -// ========================================================== -// Tone mapping operator (Fattal, 2002) -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" -#include "ToneMapping.h" - -// ---------------------------------------------------------- -// Gradient domain HDR compression -// Reference: -// [1] R. Fattal, D. Lischinski, and M.Werman, -// Gradient domain high dynamic range compression, -// ACM Transactions on Graphics, special issue on Proc. of ACM SIGGRAPH 2002, -// San Antonio, Texas, vol. 21(3), pp. 257-266, 2002. -// ---------------------------------------------------------- - -static const float EPSILON = 1e-4F; - -/** -Performs a 5 by 5 gaussian filtering using two 1D convolutions, -followed by a subsampling by 2. -@param dib Input image -@return Returns a blurred image of size SIZE(dib)/2 -@see GaussianPyramid -*/ -static FIBITMAP* GaussianLevel5x5(FIBITMAP *dib) { - FIBITMAP *h_dib = NULL, *v_dib = NULL, *dst = NULL; - float *src_pixel, *dst_pixel; - - try { - const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); - if(image_type != FIT_FLOAT) throw(1); - - const unsigned width = FreeImage_GetWidth(dib); - const unsigned height = FreeImage_GetHeight(dib); - - h_dib = FreeImage_AllocateT(image_type, width, height); - v_dib = FreeImage_AllocateT(image_type, width, height); - if(!h_dib || !v_dib) throw(1); - - const unsigned pitch = FreeImage_GetPitch(dib) / sizeof(float); - - // horizontal convolution dib -> h_dib - - src_pixel = (float*)FreeImage_GetBits(dib); - dst_pixel = (float*)FreeImage_GetBits(h_dib); - - for(unsigned y = 0; y < height; y++) { - // work on line y - for(unsigned x = 2; x < width - 2; x++) { - dst_pixel[x] = src_pixel[x-2] + src_pixel[x+2] + 4 * (src_pixel[x-1] + src_pixel[x+1]) + 6 * src_pixel[x]; - dst_pixel[x] /= 16; - } - // boundary mirroring - dst_pixel[0] = (2 * src_pixel[2] + 8 * src_pixel[1] + 6 * src_pixel[0]) / 16; - dst_pixel[1] = (src_pixel[3] + 4 * (src_pixel[0] + src_pixel[2]) + 7 * src_pixel[1]) / 16; - dst_pixel[width-2] = (src_pixel[width-4] + 5 * src_pixel[width-1] + 4 * src_pixel[width-3] + 6 * src_pixel[width-2]) / 16; - dst_pixel[width-1] = (src_pixel[width-3] + 5 * src_pixel[width-2] + 10 * src_pixel[width-1]) / 16; - - // next line - src_pixel += pitch; - dst_pixel += pitch; - } - - // vertical convolution h_dib -> v_dib - - src_pixel = (float*)FreeImage_GetBits(h_dib); - dst_pixel = (float*)FreeImage_GetBits(v_dib); - - for(unsigned x = 0; x < width; x++) { - // work on column x - for(unsigned y = 2; y < height - 2; y++) { - const unsigned index = y*pitch + x; - dst_pixel[index] = src_pixel[index-2*pitch] + src_pixel[index+2*pitch] + 4 * (src_pixel[index-pitch] + src_pixel[index+pitch]) + 6 * src_pixel[index]; - dst_pixel[index] /= 16; - } - // boundary mirroring - dst_pixel[x] = (2 * src_pixel[x+2*pitch] + 8 * src_pixel[x+pitch] + 6 * src_pixel[x]) / 16; - dst_pixel[x+pitch] = (src_pixel[x+3*pitch] + 4 * (src_pixel[x] + src_pixel[x+2*pitch]) + 7 * src_pixel[x+pitch]) / 16; - dst_pixel[(height-2)*pitch+x] = (src_pixel[(height-4)*pitch+x] + 5 * src_pixel[(height-1)*pitch+x] + 4 * src_pixel[(height-3)*pitch+x] + 6 * src_pixel[(height-2)*pitch+x]) / 16; - dst_pixel[(height-1)*pitch+x] = (src_pixel[(height-3)*pitch+x] + 5 * src_pixel[(height-2)*pitch+x] + 10 * src_pixel[(height-1)*pitch+x]) / 16; - } - - FreeImage_Unload(h_dib); h_dib = NULL; - - // perform downsampling - - dst = FreeImage_Rescale(v_dib, width/2, height/2, FILTER_BILINEAR); - - FreeImage_Unload(v_dib); - - return dst; - - } catch(int) { - if(h_dib) FreeImage_Unload(h_dib); - if(v_dib) FreeImage_Unload(v_dib); - if(dst) FreeImage_Unload(dst); - return NULL; - } -} - -/** -Compute a Gaussian pyramid using the specified number of levels. -@param H Original bitmap -@param pyramid Resulting pyramid array -@param nlevels Number of resolution levels -@return Returns TRUE if successful, returns FALSE otherwise -*/ -static BOOL GaussianPyramid(FIBITMAP *H, FIBITMAP **pyramid, int nlevels) { - try { - // first level is the original image - pyramid[0] = FreeImage_Clone(H); - if(pyramid[0] == NULL) throw(1); - // compute next levels - for(int k = 1; k < nlevels; k++) { - pyramid[k] = GaussianLevel5x5(pyramid[k-1]); - if(pyramid[k] == NULL) throw(1); - } - return TRUE; - } catch(int) { - for(int k = 0; k < nlevels; k++) { - if(pyramid[k] != NULL) { - FreeImage_Unload(pyramid[k]); - pyramid[k] = NULL; - } - } - return FALSE; - } -} - -/** -Compute the gradient magnitude of an input image H using central differences, -and returns the average gradient. -@param H Input image -@param avgGrad [out] Average gradient -@param k Level number -@return Returns the gradient magnitude if successful, returns NULL otherwise -@see GradientPyramid -*/ -static FIBITMAP* GradientLevel(FIBITMAP *H, float *avgGrad, int k) { - FIBITMAP *G = NULL; - - try { - const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(H); - if(image_type != FIT_FLOAT) throw(1); - - const unsigned width = FreeImage_GetWidth(H); - const unsigned height = FreeImage_GetHeight(H); - - G = FreeImage_AllocateT(image_type, width, height); - if(!G) throw(1); - - const unsigned pitch = FreeImage_GetPitch(H) / sizeof(float); - - const float divider = (float)(1 << (k + 1)); - float average = 0; - - float *src_pixel = (float*)FreeImage_GetBits(H); - float *dst_pixel = (float*)FreeImage_GetBits(G); - - for(unsigned y = 0; y < height; y++) { - const unsigned n = (y == 0 ? 0 : y-1); - const unsigned s = (y+1 == height ? y : y+1); - for(unsigned x = 0; x < width; x++) { - const unsigned w = (x == 0 ? 0 : x-1); - const unsigned e = (x+1 == width ? x : x+1); - // central difference - const float gx = (src_pixel[y*pitch+e] - src_pixel[y*pitch+w]) / divider; // [Hk(x+1, y) - Hk(x-1, y)] / 2**(k+1) - const float gy = (src_pixel[s*pitch+x] - src_pixel[n*pitch+x]) / divider; // [Hk(x, y+1) - Hk(x, y-1)] / 2**(k+1) - // gradient - dst_pixel[x] = sqrt(gx*gx + gy*gy); - // average gradient - average += dst_pixel[x]; - } - // next line - dst_pixel += pitch; - } - - *avgGrad = average / (width * height); - - return G; - - } catch(int) { - if(G) FreeImage_Unload(G); - return NULL; - } -} - -/** -Calculate gradient magnitude and its average value on each pyramid level -@param pyramid Gaussian pyramid (nlevels levels) -@param nlevels Number of levels -@param gradients [out] Gradient pyramid (nlevels levels) -@param avgGrad [out] Average gradient on each level (array of size nlevels) -@return Returns TRUE if successful, returns FALSE otherwise -*/ -static BOOL GradientPyramid(FIBITMAP **pyramid, int nlevels, FIBITMAP **gradients, float *avgGrad) { - try { - for(int k = 0; k < nlevels; k++) { - FIBITMAP *Hk = pyramid[k]; - gradients[k] = GradientLevel(Hk, &avgGrad[k], k); - if(gradients[k] == NULL) throw(1); - } - return TRUE; - } catch(int) { - for(int k = 0; k < nlevels; k++) { - if(gradients[k] != NULL) { - FreeImage_Unload(gradients[k]); - gradients[k] = NULL; - } - } - return FALSE; - } -} - -/** -Compute the gradient attenuation function PHI(x, y) -@param gradients Gradient pyramid (nlevels levels) -@param avgGrad Average gradient on each level (array of size nlevels) -@param nlevels Number of levels -@param alpha Parameter alpha in the paper -@param beta Parameter beta in the paper -@return Returns the attenuation matrix Phi if successful, returns NULL otherwise -*/ -static FIBITMAP* PhiMatrix(FIBITMAP **gradients, float *avgGrad, int nlevels, float alpha, float beta) { - float *src_pixel, *dst_pixel; - FIBITMAP **phi = NULL; - - try { - phi = (FIBITMAP**)malloc(nlevels * sizeof(FIBITMAP*)); - if(!phi) throw(1); - memset(phi, 0, nlevels * sizeof(FIBITMAP*)); - - for(int k = nlevels-1; k >= 0; k--) { - // compute phi(k) - - FIBITMAP *Gk = gradients[k]; - - const unsigned width = FreeImage_GetWidth(Gk); - const unsigned height = FreeImage_GetHeight(Gk); - const unsigned pitch = FreeImage_GetPitch(Gk) / sizeof(float); - - // parameter alpha is 0.1 times the average gradient magnitude - // also, note the factor of 2**k in the denominator; - // that is there to correct for the fact that an average gradient avgGrad(H) over 2**k pixels - // in the original image will appear as a gradient grad(Hk) = 2**k*avgGrad(H) over a single pixel in Hk. - float ALPHA = alpha * avgGrad[k] * (float)((int)1 << k); - if(ALPHA == 0) ALPHA = EPSILON; - - phi[k] = FreeImage_AllocateT(FIT_FLOAT, width, height); - if(!phi[k]) throw(1); - - src_pixel = (float*)FreeImage_GetBits(Gk); - dst_pixel = (float*)FreeImage_GetBits(phi[k]); - for(unsigned y = 0; y < height; y++) { - for(unsigned x = 0; x < width; x++) { - // compute (alpha / grad) * (grad / alpha) ** beta - const float v = src_pixel[x] / ALPHA; - const float value = (float)pow((float)v, (float)(beta-1)); - dst_pixel[x] = (value > 1) ? 1 : value; - } - // next line - src_pixel += pitch; - dst_pixel += pitch; - } - - if(k < nlevels-1) { - // compute PHI(k) = L( PHI(k+1) ) * phi(k) - FIBITMAP *L = FreeImage_Rescale(phi[k+1], width, height, FILTER_BILINEAR); - if(!L) throw(1); - - src_pixel = (float*)FreeImage_GetBits(L); - dst_pixel = (float*)FreeImage_GetBits(phi[k]); - for(unsigned y = 0; y < height; y++) { - for(unsigned x = 0; x < width; x++) { - dst_pixel[x] *= src_pixel[x]; - } - // next line - src_pixel += pitch; - dst_pixel += pitch; - } - - FreeImage_Unload(L); - - // PHI(k+1) is no longer needed - FreeImage_Unload(phi[k+1]); - phi[k+1] = NULL; - } - - // next level - } - - // get the final result and return - FIBITMAP *dst = phi[0]; - - free(phi); - - return dst; - - } catch(int) { - if(phi) { - for(int k = nlevels-1; k >= 0; k--) { - if(phi[k]) FreeImage_Unload(phi[k]); - } - free(phi); - } - return NULL; - } -} - -/** -Compute gradients in x and y directions, attenuate them with the attenuation matrix, -then compute the divergence div G from the attenuated gradient. -@param H Normalized luminance -@param PHI Attenuation matrix -@return Returns the divergence matrix if successful, returns NULL otherwise -*/ -static FIBITMAP* Divergence(FIBITMAP *H, FIBITMAP *PHI) { - FIBITMAP *Gx = NULL, *Gy = NULL, *divG = NULL; - float *phi, *h, *gx, *gy, *divg; - - try { - const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(H); - if(image_type != FIT_FLOAT) throw(1); - - const unsigned width = FreeImage_GetWidth(H); - const unsigned height = FreeImage_GetHeight(H); - - Gx = FreeImage_AllocateT(image_type, width, height); - if(!Gx) throw(1); - Gy = FreeImage_AllocateT(image_type, width, height); - if(!Gy) throw(1); - - const unsigned pitch = FreeImage_GetPitch(H) / sizeof(float); - - // perform gradient attenuation - - phi = (float*)FreeImage_GetBits(PHI); - h = (float*)FreeImage_GetBits(H); - gx = (float*)FreeImage_GetBits(Gx); - gy = (float*)FreeImage_GetBits(Gy); - - for(unsigned y = 0; y < height; y++) { - const unsigned s = (y+1 == height ? y : y+1); - for(unsigned x = 0; x < width; x++) { - const unsigned e = (x+1 == width ? x : x+1); - // forward difference - const unsigned index = y*pitch + x; - const float phi_xy = phi[index]; - const float h_xy = h[index]; - gx[x] = (h[y*pitch+e] - h_xy) * phi_xy; // [H(x+1, y) - H(x, y)] * PHI(x, y) - gy[x] = (h[s*pitch+x] - h_xy) * phi_xy; // [H(x, y+1) - H(x, y)] * PHI(x, y) - } - // next line - gx += pitch; - gy += pitch; - } - - // calculate the divergence - - divG = FreeImage_AllocateT(image_type, width, height); - if(!divG) throw(1); - - gx = (float*)FreeImage_GetBits(Gx); - gy = (float*)FreeImage_GetBits(Gy); - divg = (float*)FreeImage_GetBits(divG); - - for(unsigned y = 0; y < height; y++) { - for(unsigned x = 0; x < width; x++) { - // backward difference approximation - // divG = Gx(x, y) - Gx(x-1, y) + Gy(x, y) - Gy(x, y-1) - const unsigned index = y*pitch + x; - divg[index] = gx[index] + gy[index]; - if(x > 0) divg[index] -= gx[index-1]; - if(y > 0) divg[index] -= gy[index-pitch]; - } - } - - // no longer needed ... - FreeImage_Unload(Gx); - FreeImage_Unload(Gy); - - // return the divergence - return divG; - - } catch(int) { - if(Gx) FreeImage_Unload(Gx); - if(Gy) FreeImage_Unload(Gy); - if(divG) FreeImage_Unload(divG); - return NULL; - } -} - -/** -Given the luminance channel, find max & min luminance values, -normalize to range 0..100 and take the logarithm. -@param Y Image luminance -@return Returns the normalized luminance H if successful, returns NULL otherwise -*/ -static FIBITMAP* LogLuminance(FIBITMAP *Y) { - FIBITMAP *H = NULL; - - try { - // get the luminance channel - FIBITMAP *H = FreeImage_Clone(Y); - if(!H) throw(1); - - const unsigned width = FreeImage_GetWidth(H); - const unsigned height = FreeImage_GetHeight(H); - const unsigned pitch = FreeImage_GetPitch(H); - - // find max & min luminance values - float maxLum = -1e20F, minLum = 1e20F; - - BYTE *bits = (BYTE*)FreeImage_GetBits(H); - for(unsigned y = 0; y < height; y++) { - const float *pixel = (float*)bits; - for(unsigned x = 0; x < width; x++) { - const float value = pixel[x]; - maxLum = (maxLum < value) ? value : maxLum; // max Luminance in the scene - minLum = (minLum < value) ? minLum : value; // min Luminance in the scene - } - // next line - bits += pitch; - } - if(maxLum == minLum) throw(1); - - // normalize to range 0..100 and take the logarithm - const float scale = 100.F / (maxLum - minLum); - bits = (BYTE*)FreeImage_GetBits(H); - for(unsigned y = 0; y < height; y++) { - float *pixel = (float*)bits; - for(unsigned x = 0; x < width; x++) { - const float value = (pixel[x] - minLum) * scale; - pixel[x] = log(value + EPSILON); - } - // next line - bits += pitch; - } - - return H; - - } catch(int) { - if(H) FreeImage_Unload(H); - return NULL; - } -} - -/** -Given a normalized luminance, perform exponentiation and recover the log compressed image -@param Y Input/Output luminance image -*/ -static void ExpLuminance(FIBITMAP *Y) { - const unsigned width = FreeImage_GetWidth(Y); - const unsigned height = FreeImage_GetHeight(Y); - const unsigned pitch = FreeImage_GetPitch(Y); - - BYTE *bits = (BYTE*)FreeImage_GetBits(Y); - for(unsigned y = 0; y < height; y++) { - float *pixel = (float*)bits; - for(unsigned x = 0; x < width; x++) { - pixel[x] = exp(pixel[x]) - EPSILON; - } - bits += pitch; - } -} - -// -------------------------------------------------------------------------- - -/** -Gradient Domain HDR tone mapping operator -@param Y Image luminance values -@param alpha Parameter alpha of the paper (suggested value is 0.1) -@param beta Parameter beta of the paper (suggested value is between 0.8 and 0.9) -@return returns the tone mapped luminance -*/ -static FIBITMAP* tmoFattal02(FIBITMAP *Y, float alpha, float beta) { - const unsigned MIN_PYRAMID_SIZE = 32; // minimun size (width or height) of the coarsest level of the pyramid - - FIBITMAP *H = NULL; - FIBITMAP **pyramid = NULL; - FIBITMAP **gradients = NULL; - FIBITMAP *phy = NULL; - FIBITMAP *divG = NULL; - FIBITMAP *U = NULL; - float *avgGrad = NULL; - - int k; - int nlevels = 0; - - try { - // get the normalized luminance - FIBITMAP *H = LogLuminance(Y); - if(!H) throw(1); - - // get the number of levels for the pyramid - const unsigned width = FreeImage_GetWidth(H); - const unsigned height = FreeImage_GetHeight(H); - unsigned minsize = MIN(width, height); - while(minsize >= MIN_PYRAMID_SIZE) { - nlevels++; - minsize /= 2; - } - - // create the Gaussian pyramid - pyramid = (FIBITMAP**)malloc(nlevels * sizeof(FIBITMAP*)); - if(!pyramid) throw(1); - memset(pyramid, 0, nlevels * sizeof(FIBITMAP*)); - - if(!GaussianPyramid(H, pyramid, nlevels)) throw(1); - - // calculate gradient magnitude and its average value on each pyramid level - gradients = (FIBITMAP**)malloc(nlevels * sizeof(FIBITMAP*)); - if(!gradients) throw(1); - memset(gradients, 0, nlevels * sizeof(FIBITMAP*)); - avgGrad = (float*)malloc(nlevels * sizeof(float)); - if(!avgGrad) throw(1); - - if(!GradientPyramid(pyramid, nlevels, gradients, avgGrad)) throw(1); - - // free the Gaussian pyramid - for(k = 0; k < nlevels; k++) { - if(pyramid[k]) FreeImage_Unload(pyramid[k]); - } - free(pyramid); pyramid = NULL; - - // compute the gradient attenuation function PHI(x, y) - phy = PhiMatrix(gradients, avgGrad, nlevels, alpha, beta); - if(!phy) throw(1); - - // free the gradient pyramid - for(k = 0; k < nlevels; k++) { - if(gradients[k]) FreeImage_Unload(gradients[k]); - } - free(gradients); gradients = NULL; - free(avgGrad); avgGrad = NULL; - - // compute gradients in x and y directions, attenuate them with the attenuation matrix, - // then compute the divergence div G from the attenuated gradient. - divG = Divergence(H, phy); - if(!divG) throw(1); - - // H & phy no longer needed - FreeImage_Unload(H); H = NULL; - FreeImage_Unload(phy); phy = NULL; - - // solve the PDE (Poisson equation) using a multigrid solver and 3 cycles - FIBITMAP *U = FreeImage_MultigridPoissonSolver(divG, 3); - if(!U) throw(1); - - FreeImage_Unload(divG); - - // perform exponentiation and recover the log compressed image - ExpLuminance(U); - - return U; - - } catch(int) { - if(H) FreeImage_Unload(H); - if(pyramid) { - for(int i = 0; i < nlevels; i++) { - if(pyramid[i]) FreeImage_Unload(pyramid[i]); - } - free(pyramid); - } - if(gradients) { - for(int i = 0; i < nlevels; i++) { - if(gradients[i]) FreeImage_Unload(gradients[i]); - } - free(gradients); - } - if(avgGrad) free(avgGrad); - if(phy) FreeImage_Unload(phy); - if(divG) FreeImage_Unload(divG); - if(U) FreeImage_Unload(U); - - return NULL; - } -} - -// ---------------------------------------------------------- -// Main algorithm -// ---------------------------------------------------------- - -/** -Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and convert to 24-bit RGB -@param dib Input RGBF / RGB16 image -@param color_saturation Color saturation (s parameter in the paper) in [0.4..0.6] -@param attenuation Atenuation factor (beta parameter in the paper) in [0.8..0.9] -@return Returns a 24-bit RGB image if successful, returns NULL otherwise -*/ -FIBITMAP* DLL_CALLCONV -FreeImage_TmoFattal02(FIBITMAP *dib, double color_saturation, double attenuation) { - const float alpha = 0.1F; // parameter alpha = 0.1 - const float beta = (float)MAX(0.8, MIN(0.9, attenuation)); // parameter beta = [0.8..0.9] - const float s = (float)MAX(0.4, MIN(0.6, color_saturation));// exponent s controls color saturation = [0.4..0.6] - - FIBITMAP *src = NULL; - FIBITMAP *Yin = NULL; - FIBITMAP *Yout = NULL; - FIBITMAP *dst = NULL; - - if(!FreeImage_HasPixels(dib)) return NULL; - - try { - - // convert to RGBF - src = FreeImage_ConvertToRGBF(dib); - if(!src) throw(1); - - // get the luminance channel - Yin = ConvertRGBFToY(src); - if(!Yin) throw(1); - - // perform the tone mapping - Yout = tmoFattal02(Yin, alpha, beta); - if(!Yout) throw(1); - - // clip low and high values and normalize to [0..1] - //NormalizeY(Yout, 0.001F, 0.995F); - NormalizeY(Yout, 0, 1); - - // compress the dynamic range - - const unsigned width = FreeImage_GetWidth(src); - const unsigned height = FreeImage_GetHeight(src); - - const unsigned rgb_pitch = FreeImage_GetPitch(src); - const unsigned y_pitch = FreeImage_GetPitch(Yin); - - BYTE *bits = (BYTE*)FreeImage_GetBits(src); - BYTE *bits_yin = (BYTE*)FreeImage_GetBits(Yin); - BYTE *bits_yout = (BYTE*)FreeImage_GetBits(Yout); - - for(unsigned y = 0; y < height; y++) { - float *Lin = (float*)bits_yin; - float *Lout = (float*)bits_yout; - float *color = (float*)bits; - for(unsigned x = 0; x < width; x++) { - for(unsigned c = 0; c < 3; c++) { - *color = (Lin[x] > 0) ? pow(*color/Lin[x], s) * Lout[x] : 0; - color++; - } - } - bits += rgb_pitch; - bits_yin += y_pitch; - bits_yout += y_pitch; - } - - // not needed anymore - FreeImage_Unload(Yin); Yin = NULL; - FreeImage_Unload(Yout); Yout = NULL; - - // clamp image highest values to display white, then convert to 24-bit RGB - dst = ClampConvertRGBFTo24(src); - - // clean-up and return - FreeImage_Unload(src); src = NULL; - - // copy metadata from src to dst - FreeImage_CloneMetadata(dst, dib); - - return dst; - - } catch(int) { - if(src) FreeImage_Unload(src); - if(Yin) FreeImage_Unload(Yin); - if(Yout) FreeImage_Unload(Yout); - return NULL; - } -} +// ========================================================== +// Tone mapping operator (Fattal, 2002) +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" +#include "ToneMapping.h" + +// ---------------------------------------------------------- +// Gradient domain HDR compression +// Reference: +// [1] R. Fattal, D. Lischinski, and M.Werman, +// Gradient domain high dynamic range compression, +// ACM Transactions on Graphics, special issue on Proc. of ACM SIGGRAPH 2002, +// San Antonio, Texas, vol. 21(3), pp. 257-266, 2002. +// ---------------------------------------------------------- + +static const float EPSILON = 1e-4F; + +/** +Performs a 5 by 5 gaussian filtering using two 1D convolutions, +followed by a subsampling by 2. +@param dib Input image +@return Returns a blurred image of size SIZE(dib)/2 +@see GaussianPyramid +*/ +static FIBITMAP* GaussianLevel5x5(FIBITMAP *dib) { + FIBITMAP *h_dib = NULL, *v_dib = NULL, *dst = NULL; + float *src_pixel, *dst_pixel; + + try { + const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); + if(image_type != FIT_FLOAT) throw(1); + + const unsigned width = FreeImage_GetWidth(dib); + const unsigned height = FreeImage_GetHeight(dib); + + h_dib = FreeImage_AllocateT(image_type, width, height); + v_dib = FreeImage_AllocateT(image_type, width, height); + if(!h_dib || !v_dib) throw(1); + + const unsigned pitch = FreeImage_GetPitch(dib) / sizeof(float); + + // horizontal convolution dib -> h_dib + + src_pixel = (float*)FreeImage_GetBits(dib); + dst_pixel = (float*)FreeImage_GetBits(h_dib); + + for(unsigned y = 0; y < height; y++) { + // work on line y + for(unsigned x = 2; x < width - 2; x++) { + dst_pixel[x] = src_pixel[x-2] + src_pixel[x+2] + 4 * (src_pixel[x-1] + src_pixel[x+1]) + 6 * src_pixel[x]; + dst_pixel[x] /= 16; + } + // boundary mirroring + dst_pixel[0] = (2 * src_pixel[2] + 8 * src_pixel[1] + 6 * src_pixel[0]) / 16; + dst_pixel[1] = (src_pixel[3] + 4 * (src_pixel[0] + src_pixel[2]) + 7 * src_pixel[1]) / 16; + dst_pixel[width-2] = (src_pixel[width-4] + 5 * src_pixel[width-1] + 4 * src_pixel[width-3] + 6 * src_pixel[width-2]) / 16; + dst_pixel[width-1] = (src_pixel[width-3] + 5 * src_pixel[width-2] + 10 * src_pixel[width-1]) / 16; + + // next line + src_pixel += pitch; + dst_pixel += pitch; + } + + // vertical convolution h_dib -> v_dib + + src_pixel = (float*)FreeImage_GetBits(h_dib); + dst_pixel = (float*)FreeImage_GetBits(v_dib); + + for(unsigned x = 0; x < width; x++) { + // work on column x + for(unsigned y = 2; y < height - 2; y++) { + const unsigned index = y*pitch + x; + dst_pixel[index] = src_pixel[index-2*pitch] + src_pixel[index+2*pitch] + 4 * (src_pixel[index-pitch] + src_pixel[index+pitch]) + 6 * src_pixel[index]; + dst_pixel[index] /= 16; + } + // boundary mirroring + dst_pixel[x] = (2 * src_pixel[x+2*pitch] + 8 * src_pixel[x+pitch] + 6 * src_pixel[x]) / 16; + dst_pixel[x+pitch] = (src_pixel[x+3*pitch] + 4 * (src_pixel[x] + src_pixel[x+2*pitch]) + 7 * src_pixel[x+pitch]) / 16; + dst_pixel[(height-2)*pitch+x] = (src_pixel[(height-4)*pitch+x] + 5 * src_pixel[(height-1)*pitch+x] + 4 * src_pixel[(height-3)*pitch+x] + 6 * src_pixel[(height-2)*pitch+x]) / 16; + dst_pixel[(height-1)*pitch+x] = (src_pixel[(height-3)*pitch+x] + 5 * src_pixel[(height-2)*pitch+x] + 10 * src_pixel[(height-1)*pitch+x]) / 16; + } + + FreeImage_Unload(h_dib); h_dib = NULL; + + // perform downsampling + + dst = FreeImage_Rescale(v_dib, width/2, height/2, FILTER_BILINEAR); + + FreeImage_Unload(v_dib); + + return dst; + + } catch(int) { + if(h_dib) FreeImage_Unload(h_dib); + if(v_dib) FreeImage_Unload(v_dib); + if(dst) FreeImage_Unload(dst); + return NULL; + } +} + +/** +Compute a Gaussian pyramid using the specified number of levels. +@param H Original bitmap +@param pyramid Resulting pyramid array +@param nlevels Number of resolution levels +@return Returns TRUE if successful, returns FALSE otherwise +*/ +static BOOL GaussianPyramid(FIBITMAP *H, FIBITMAP **pyramid, int nlevels) { + try { + // first level is the original image + pyramid[0] = FreeImage_Clone(H); + if(pyramid[0] == NULL) throw(1); + // compute next levels + for(int k = 1; k < nlevels; k++) { + pyramid[k] = GaussianLevel5x5(pyramid[k-1]); + if(pyramid[k] == NULL) throw(1); + } + return TRUE; + } catch(int) { + for(int k = 0; k < nlevels; k++) { + if(pyramid[k] != NULL) { + FreeImage_Unload(pyramid[k]); + pyramid[k] = NULL; + } + } + return FALSE; + } +} + +/** +Compute the gradient magnitude of an input image H using central differences, +and returns the average gradient. +@param H Input image +@param avgGrad [out] Average gradient +@param k Level number +@return Returns the gradient magnitude if successful, returns NULL otherwise +@see GradientPyramid +*/ +static FIBITMAP* GradientLevel(FIBITMAP *H, float *avgGrad, int k) { + FIBITMAP *G = NULL; + + try { + const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(H); + if(image_type != FIT_FLOAT) throw(1); + + const unsigned width = FreeImage_GetWidth(H); + const unsigned height = FreeImage_GetHeight(H); + + G = FreeImage_AllocateT(image_type, width, height); + if(!G) throw(1); + + const unsigned pitch = FreeImage_GetPitch(H) / sizeof(float); + + const float divider = (float)(1 << (k + 1)); + float average = 0; + + float *src_pixel = (float*)FreeImage_GetBits(H); + float *dst_pixel = (float*)FreeImage_GetBits(G); + + for(unsigned y = 0; y < height; y++) { + const unsigned n = (y == 0 ? 0 : y-1); + const unsigned s = (y+1 == height ? y : y+1); + for(unsigned x = 0; x < width; x++) { + const unsigned w = (x == 0 ? 0 : x-1); + const unsigned e = (x+1 == width ? x : x+1); + // central difference + const float gx = (src_pixel[y*pitch+e] - src_pixel[y*pitch+w]) / divider; // [Hk(x+1, y) - Hk(x-1, y)] / 2**(k+1) + const float gy = (src_pixel[s*pitch+x] - src_pixel[n*pitch+x]) / divider; // [Hk(x, y+1) - Hk(x, y-1)] / 2**(k+1) + // gradient + dst_pixel[x] = sqrt(gx*gx + gy*gy); + // average gradient + average += dst_pixel[x]; + } + // next line + dst_pixel += pitch; + } + + *avgGrad = average / (width * height); + + return G; + + } catch(int) { + if(G) FreeImage_Unload(G); + return NULL; + } +} + +/** +Calculate gradient magnitude and its average value on each pyramid level +@param pyramid Gaussian pyramid (nlevels levels) +@param nlevels Number of levels +@param gradients [out] Gradient pyramid (nlevels levels) +@param avgGrad [out] Average gradient on each level (array of size nlevels) +@return Returns TRUE if successful, returns FALSE otherwise +*/ +static BOOL GradientPyramid(FIBITMAP **pyramid, int nlevels, FIBITMAP **gradients, float *avgGrad) { + try { + for(int k = 0; k < nlevels; k++) { + FIBITMAP *Hk = pyramid[k]; + gradients[k] = GradientLevel(Hk, &avgGrad[k], k); + if(gradients[k] == NULL) throw(1); + } + return TRUE; + } catch(int) { + for(int k = 0; k < nlevels; k++) { + if(gradients[k] != NULL) { + FreeImage_Unload(gradients[k]); + gradients[k] = NULL; + } + } + return FALSE; + } +} + +/** +Compute the gradient attenuation function PHI(x, y) +@param gradients Gradient pyramid (nlevels levels) +@param avgGrad Average gradient on each level (array of size nlevels) +@param nlevels Number of levels +@param alpha Parameter alpha in the paper +@param beta Parameter beta in the paper +@return Returns the attenuation matrix Phi if successful, returns NULL otherwise +*/ +static FIBITMAP* PhiMatrix(FIBITMAP **gradients, float *avgGrad, int nlevels, float alpha, float beta) { + float *src_pixel, *dst_pixel; + FIBITMAP **phi = NULL; + + try { + phi = (FIBITMAP**)malloc(nlevels * sizeof(FIBITMAP*)); + if(!phi) throw(1); + memset(phi, 0, nlevels * sizeof(FIBITMAP*)); + + for(int k = nlevels-1; k >= 0; k--) { + // compute phi(k) + + FIBITMAP *Gk = gradients[k]; + + const unsigned width = FreeImage_GetWidth(Gk); + const unsigned height = FreeImage_GetHeight(Gk); + const unsigned pitch = FreeImage_GetPitch(Gk) / sizeof(float); + + // parameter alpha is 0.1 times the average gradient magnitude + // also, note the factor of 2**k in the denominator; + // that is there to correct for the fact that an average gradient avgGrad(H) over 2**k pixels + // in the original image will appear as a gradient grad(Hk) = 2**k*avgGrad(H) over a single pixel in Hk. + float ALPHA = alpha * avgGrad[k] * (float)((int)1 << k); + if(ALPHA == 0) ALPHA = EPSILON; + + phi[k] = FreeImage_AllocateT(FIT_FLOAT, width, height); + if(!phi[k]) throw(1); + + src_pixel = (float*)FreeImage_GetBits(Gk); + dst_pixel = (float*)FreeImage_GetBits(phi[k]); + for(unsigned y = 0; y < height; y++) { + for(unsigned x = 0; x < width; x++) { + // compute (alpha / grad) * (grad / alpha) ** beta + const float v = src_pixel[x] / ALPHA; + const float value = (float)pow((float)v, (float)(beta-1)); + dst_pixel[x] = (value > 1) ? 1 : value; + } + // next line + src_pixel += pitch; + dst_pixel += pitch; + } + + if(k < nlevels-1) { + // compute PHI(k) = L( PHI(k+1) ) * phi(k) + FIBITMAP *L = FreeImage_Rescale(phi[k+1], width, height, FILTER_BILINEAR); + if(!L) throw(1); + + src_pixel = (float*)FreeImage_GetBits(L); + dst_pixel = (float*)FreeImage_GetBits(phi[k]); + for(unsigned y = 0; y < height; y++) { + for(unsigned x = 0; x < width; x++) { + dst_pixel[x] *= src_pixel[x]; + } + // next line + src_pixel += pitch; + dst_pixel += pitch; + } + + FreeImage_Unload(L); + + // PHI(k+1) is no longer needed + FreeImage_Unload(phi[k+1]); + phi[k+1] = NULL; + } + + // next level + } + + // get the final result and return + FIBITMAP *dst = phi[0]; + + free(phi); + + return dst; + + } catch(int) { + if(phi) { + for(int k = nlevels-1; k >= 0; k--) { + if(phi[k]) FreeImage_Unload(phi[k]); + } + free(phi); + } + return NULL; + } +} + +/** +Compute gradients in x and y directions, attenuate them with the attenuation matrix, +then compute the divergence div G from the attenuated gradient. +@param H Normalized luminance +@param PHI Attenuation matrix +@return Returns the divergence matrix if successful, returns NULL otherwise +*/ +static FIBITMAP* Divergence(FIBITMAP *H, FIBITMAP *PHI) { + FIBITMAP *Gx = NULL, *Gy = NULL, *divG = NULL; + float *phi, *h, *gx, *gy, *divg; + + try { + const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(H); + if(image_type != FIT_FLOAT) throw(1); + + const unsigned width = FreeImage_GetWidth(H); + const unsigned height = FreeImage_GetHeight(H); + + Gx = FreeImage_AllocateT(image_type, width, height); + if(!Gx) throw(1); + Gy = FreeImage_AllocateT(image_type, width, height); + if(!Gy) throw(1); + + const unsigned pitch = FreeImage_GetPitch(H) / sizeof(float); + + // perform gradient attenuation + + phi = (float*)FreeImage_GetBits(PHI); + h = (float*)FreeImage_GetBits(H); + gx = (float*)FreeImage_GetBits(Gx); + gy = (float*)FreeImage_GetBits(Gy); + + for(unsigned y = 0; y < height; y++) { + const unsigned s = (y+1 == height ? y : y+1); + for(unsigned x = 0; x < width; x++) { + const unsigned e = (x+1 == width ? x : x+1); + // forward difference + const unsigned index = y*pitch + x; + const float phi_xy = phi[index]; + const float h_xy = h[index]; + gx[x] = (h[y*pitch+e] - h_xy) * phi_xy; // [H(x+1, y) - H(x, y)] * PHI(x, y) + gy[x] = (h[s*pitch+x] - h_xy) * phi_xy; // [H(x, y+1) - H(x, y)] * PHI(x, y) + } + // next line + gx += pitch; + gy += pitch; + } + + // calculate the divergence + + divG = FreeImage_AllocateT(image_type, width, height); + if(!divG) throw(1); + + gx = (float*)FreeImage_GetBits(Gx); + gy = (float*)FreeImage_GetBits(Gy); + divg = (float*)FreeImage_GetBits(divG); + + for(unsigned y = 0; y < height; y++) { + for(unsigned x = 0; x < width; x++) { + // backward difference approximation + // divG = Gx(x, y) - Gx(x-1, y) + Gy(x, y) - Gy(x, y-1) + const unsigned index = y*pitch + x; + divg[index] = gx[index] + gy[index]; + if(x > 0) divg[index] -= gx[index-1]; + if(y > 0) divg[index] -= gy[index-pitch]; + } + } + + // no longer needed ... + FreeImage_Unload(Gx); + FreeImage_Unload(Gy); + + // return the divergence + return divG; + + } catch(int) { + if(Gx) FreeImage_Unload(Gx); + if(Gy) FreeImage_Unload(Gy); + if(divG) FreeImage_Unload(divG); + return NULL; + } +} + +/** +Given the luminance channel, find max & min luminance values, +normalize to range 0..100 and take the logarithm. +@param Y Image luminance +@return Returns the normalized luminance H if successful, returns NULL otherwise +*/ +static FIBITMAP* LogLuminance(FIBITMAP *Y) { + FIBITMAP *H = NULL; + + try { + // get the luminance channel + FIBITMAP *H = FreeImage_Clone(Y); + if(!H) throw(1); + + const unsigned width = FreeImage_GetWidth(H); + const unsigned height = FreeImage_GetHeight(H); + const unsigned pitch = FreeImage_GetPitch(H); + + // find max & min luminance values + float maxLum = -1e20F, minLum = 1e20F; + + BYTE *bits = (BYTE*)FreeImage_GetBits(H); + for(unsigned y = 0; y < height; y++) { + const float *pixel = (float*)bits; + for(unsigned x = 0; x < width; x++) { + const float value = pixel[x]; + maxLum = (maxLum < value) ? value : maxLum; // max Luminance in the scene + minLum = (minLum < value) ? minLum : value; // min Luminance in the scene + } + // next line + bits += pitch; + } + if(maxLum == minLum) throw(1); + + // normalize to range 0..100 and take the logarithm + const float scale = 100.F / (maxLum - minLum); + bits = (BYTE*)FreeImage_GetBits(H); + for(unsigned y = 0; y < height; y++) { + float *pixel = (float*)bits; + for(unsigned x = 0; x < width; x++) { + const float value = (pixel[x] - minLum) * scale; + pixel[x] = log(value + EPSILON); + } + // next line + bits += pitch; + } + + return H; + + } catch(int) { + if(H) FreeImage_Unload(H); + return NULL; + } +} + +/** +Given a normalized luminance, perform exponentiation and recover the log compressed image +@param Y Input/Output luminance image +*/ +static void ExpLuminance(FIBITMAP *Y) { + const unsigned width = FreeImage_GetWidth(Y); + const unsigned height = FreeImage_GetHeight(Y); + const unsigned pitch = FreeImage_GetPitch(Y); + + BYTE *bits = (BYTE*)FreeImage_GetBits(Y); + for(unsigned y = 0; y < height; y++) { + float *pixel = (float*)bits; + for(unsigned x = 0; x < width; x++) { + pixel[x] = exp(pixel[x]) - EPSILON; + } + bits += pitch; + } +} + +// -------------------------------------------------------------------------- + +/** +Gradient Domain HDR tone mapping operator +@param Y Image luminance values +@param alpha Parameter alpha of the paper (suggested value is 0.1) +@param beta Parameter beta of the paper (suggested value is between 0.8 and 0.9) +@return returns the tone mapped luminance +*/ +static FIBITMAP* tmoFattal02(FIBITMAP *Y, float alpha, float beta) { + const unsigned MIN_PYRAMID_SIZE = 32; // minimun size (width or height) of the coarsest level of the pyramid + + FIBITMAP *H = NULL; + FIBITMAP **pyramid = NULL; + FIBITMAP **gradients = NULL; + FIBITMAP *phy = NULL; + FIBITMAP *divG = NULL; + FIBITMAP *U = NULL; + float *avgGrad = NULL; + + int k; + int nlevels = 0; + + try { + // get the normalized luminance + FIBITMAP *H = LogLuminance(Y); + if(!H) throw(1); + + // get the number of levels for the pyramid + const unsigned width = FreeImage_GetWidth(H); + const unsigned height = FreeImage_GetHeight(H); + unsigned minsize = MIN(width, height); + while(minsize >= MIN_PYRAMID_SIZE) { + nlevels++; + minsize /= 2; + } + + // create the Gaussian pyramid + pyramid = (FIBITMAP**)malloc(nlevels * sizeof(FIBITMAP*)); + if(!pyramid) throw(1); + memset(pyramid, 0, nlevels * sizeof(FIBITMAP*)); + + if(!GaussianPyramid(H, pyramid, nlevels)) throw(1); + + // calculate gradient magnitude and its average value on each pyramid level + gradients = (FIBITMAP**)malloc(nlevels * sizeof(FIBITMAP*)); + if(!gradients) throw(1); + memset(gradients, 0, nlevels * sizeof(FIBITMAP*)); + avgGrad = (float*)malloc(nlevels * sizeof(float)); + if(!avgGrad) throw(1); + + if(!GradientPyramid(pyramid, nlevels, gradients, avgGrad)) throw(1); + + // free the Gaussian pyramid + for(k = 0; k < nlevels; k++) { + if(pyramid[k]) FreeImage_Unload(pyramid[k]); + } + free(pyramid); pyramid = NULL; + + // compute the gradient attenuation function PHI(x, y) + phy = PhiMatrix(gradients, avgGrad, nlevels, alpha, beta); + if(!phy) throw(1); + + // free the gradient pyramid + for(k = 0; k < nlevels; k++) { + if(gradients[k]) FreeImage_Unload(gradients[k]); + } + free(gradients); gradients = NULL; + free(avgGrad); avgGrad = NULL; + + // compute gradients in x and y directions, attenuate them with the attenuation matrix, + // then compute the divergence div G from the attenuated gradient. + divG = Divergence(H, phy); + if(!divG) throw(1); + + // H & phy no longer needed + FreeImage_Unload(H); H = NULL; + FreeImage_Unload(phy); phy = NULL; + + // solve the PDE (Poisson equation) using a multigrid solver and 3 cycles + FIBITMAP *U = FreeImage_MultigridPoissonSolver(divG, 3); + if(!U) throw(1); + + FreeImage_Unload(divG); + + // perform exponentiation and recover the log compressed image + ExpLuminance(U); + + return U; + + } catch(int) { + if(H) FreeImage_Unload(H); + if(pyramid) { + for(int i = 0; i < nlevels; i++) { + if(pyramid[i]) FreeImage_Unload(pyramid[i]); + } + free(pyramid); + } + if(gradients) { + for(int i = 0; i < nlevels; i++) { + if(gradients[i]) FreeImage_Unload(gradients[i]); + } + free(gradients); + } + if(avgGrad) free(avgGrad); + if(phy) FreeImage_Unload(phy); + if(divG) FreeImage_Unload(divG); + if(U) FreeImage_Unload(U); + + return NULL; + } +} + +// ---------------------------------------------------------- +// Main algorithm +// ---------------------------------------------------------- + +/** +Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and convert to 24-bit RGB +@param dib Input RGBF / RGB16 image +@param color_saturation Color saturation (s parameter in the paper) in [0.4..0.6] +@param attenuation Atenuation factor (beta parameter in the paper) in [0.8..0.9] +@return Returns a 24-bit RGB image if successful, returns NULL otherwise +*/ +FIBITMAP* DLL_CALLCONV +FreeImage_TmoFattal02(FIBITMAP *dib, double color_saturation, double attenuation) { + const float alpha = 0.1F; // parameter alpha = 0.1 + const float beta = (float)MAX(0.8, MIN(0.9, attenuation)); // parameter beta = [0.8..0.9] + const float s = (float)MAX(0.4, MIN(0.6, color_saturation));// exponent s controls color saturation = [0.4..0.6] + + FIBITMAP *src = NULL; + FIBITMAP *Yin = NULL; + FIBITMAP *Yout = NULL; + FIBITMAP *dst = NULL; + + if(!FreeImage_HasPixels(dib)) return NULL; + + try { + + // convert to RGBF + src = FreeImage_ConvertToRGBF(dib); + if(!src) throw(1); + + // get the luminance channel + Yin = ConvertRGBFToY(src); + if(!Yin) throw(1); + + // perform the tone mapping + Yout = tmoFattal02(Yin, alpha, beta); + if(!Yout) throw(1); + + // clip low and high values and normalize to [0..1] + //NormalizeY(Yout, 0.001F, 0.995F); + NormalizeY(Yout, 0, 1); + + // compress the dynamic range + + const unsigned width = FreeImage_GetWidth(src); + const unsigned height = FreeImage_GetHeight(src); + + const unsigned rgb_pitch = FreeImage_GetPitch(src); + const unsigned y_pitch = FreeImage_GetPitch(Yin); + + BYTE *bits = (BYTE*)FreeImage_GetBits(src); + BYTE *bits_yin = (BYTE*)FreeImage_GetBits(Yin); + BYTE *bits_yout = (BYTE*)FreeImage_GetBits(Yout); + + for(unsigned y = 0; y < height; y++) { + float *Lin = (float*)bits_yin; + float *Lout = (float*)bits_yout; + float *color = (float*)bits; + for(unsigned x = 0; x < width; x++) { + for(unsigned c = 0; c < 3; c++) { + *color = (Lin[x] > 0) ? pow(*color/Lin[x], s) * Lout[x] : 0; + color++; + } + } + bits += rgb_pitch; + bits_yin += y_pitch; + bits_yout += y_pitch; + } + + // not needed anymore + FreeImage_Unload(Yin); Yin = NULL; + FreeImage_Unload(Yout); Yout = NULL; + + // clamp image highest values to display white, then convert to 24-bit RGB + dst = ClampConvertRGBFTo24(src); + + // clean-up and return + FreeImage_Unload(src); src = NULL; + + // copy metadata from src to dst + FreeImage_CloneMetadata(dst, dib); + + return dst; + + } catch(int) { + if(src) FreeImage_Unload(src); + if(Yin) FreeImage_Unload(Yin); + if(Yout) FreeImage_Unload(Yout); + return NULL; + } +} diff --git a/Source/FreeImageToolkit/Rescale.cpp b/Source/FreeImageToolkit/Rescale.cpp index ffe667e..0c8bbc2 100644 --- a/Source/FreeImageToolkit/Rescale.cpp +++ b/Source/FreeImageToolkit/Rescale.cpp @@ -1,169 +1,169 @@ -// ========================================================== -// Upsampling / downsampling routine -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "Resize.h" - -FIBITMAP * DLL_CALLCONV -FreeImage_Rescale(FIBITMAP *src, int dst_width, int dst_height, FREE_IMAGE_FILTER filter) { - FIBITMAP *dst = NULL; - - if (!FreeImage_HasPixels(src) || (dst_width <= 0) || (dst_height <= 0) || (FreeImage_GetWidth(src) <= 0) || (FreeImage_GetHeight(src) <= 0)) { - return NULL; - } - - // select the filter - CGenericFilter *pFilter = NULL; - switch (filter) { - case FILTER_BOX: - pFilter = new(std::nothrow) CBoxFilter(); - break; - case FILTER_BICUBIC: - pFilter = new(std::nothrow) CBicubicFilter(); - break; - case FILTER_BILINEAR: - pFilter = new(std::nothrow) CBilinearFilter(); - break; - case FILTER_BSPLINE: - pFilter = new(std::nothrow) CBSplineFilter(); - break; - case FILTER_CATMULLROM: - pFilter = new(std::nothrow) CCatmullRomFilter(); - break; - case FILTER_LANCZOS3: - pFilter = new(std::nothrow) CLanczos3Filter(); - break; - } - - if (!pFilter) { - return NULL; - } - - CResizeEngine Engine(pFilter); - - dst = Engine.scale(src, dst_width, dst_height, 0, 0, - FreeImage_GetWidth(src), FreeImage_GetHeight(src)); - - delete pFilter; - - // copy metadata from src to dst - FreeImage_CloneMetadata(dst, src); - - return dst; -} - -FIBITMAP * DLL_CALLCONV -FreeImage_MakeThumbnail(FIBITMAP *dib, int max_pixel_size, BOOL convert) { - FIBITMAP *thumbnail = NULL; - int new_width, new_height; - - if(!FreeImage_HasPixels(dib) || (max_pixel_size <= 0)) return NULL; - - int width = FreeImage_GetWidth(dib); - int height = FreeImage_GetHeight(dib); - - if(max_pixel_size == 0) max_pixel_size = 1; - - if((width < max_pixel_size) && (height < max_pixel_size)) { - // image is smaller than the requested thumbnail - return FreeImage_Clone(dib); - } - - if(width > height) { - new_width = max_pixel_size; - // change image height with the same ratio - double ratio = ((double)new_width / (double)width); - new_height = (int)(height * ratio + 0.5); - if(new_height == 0) new_height = 1; - } else { - new_height = max_pixel_size; - // change image width with the same ratio - double ratio = ((double)new_height / (double)height); - new_width = (int)(width * ratio + 0.5); - if(new_width == 0) new_width = 1; - } - - const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); - - // perform downsampling using a bilinear interpolation - - switch(image_type) { - case FIT_BITMAP: - case FIT_UINT16: - case FIT_RGB16: - case FIT_RGBA16: - case FIT_FLOAT: - case FIT_RGBF: - case FIT_RGBAF: - { - FREE_IMAGE_FILTER filter = FILTER_BILINEAR; - thumbnail = FreeImage_Rescale(dib, new_width, new_height, filter); - } - break; - - case FIT_INT16: - case FIT_UINT32: - case FIT_INT32: - case FIT_DOUBLE: - case FIT_COMPLEX: - default: - // cannot rescale this kind of image - thumbnail = NULL; - break; - } - - if((thumbnail != NULL) && (image_type != FIT_BITMAP) && convert) { - // convert to a standard bitmap - FIBITMAP *bitmap = NULL; - switch(image_type) { - case FIT_UINT16: - bitmap = FreeImage_ConvertTo8Bits(thumbnail); - break; - case FIT_RGB16: - bitmap = FreeImage_ConvertTo24Bits(thumbnail); - break; - case FIT_RGBA16: - bitmap = FreeImage_ConvertTo32Bits(thumbnail); - break; - case FIT_FLOAT: - bitmap = FreeImage_ConvertToStandardType(thumbnail, TRUE); - break; - case FIT_RGBF: - bitmap = FreeImage_ToneMapping(thumbnail, FITMO_DRAGO03); - break; - case FIT_RGBAF: - // no way to keep the transparency yet ... - FIBITMAP *rgbf = FreeImage_ConvertToRGBF(thumbnail); - bitmap = FreeImage_ToneMapping(rgbf, FITMO_DRAGO03); - FreeImage_Unload(rgbf); - break; - } - if(bitmap != NULL) { - FreeImage_Unload(thumbnail); - thumbnail = bitmap; - } - } - - // copy metadata from src to dst - FreeImage_CloneMetadata(thumbnail, dib); - - return thumbnail; -} +// ========================================================== +// Upsampling / downsampling routine +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "Resize.h" + +FIBITMAP * DLL_CALLCONV +FreeImage_Rescale(FIBITMAP *src, int dst_width, int dst_height, FREE_IMAGE_FILTER filter) { + FIBITMAP *dst = NULL; + + if (!FreeImage_HasPixels(src) || (dst_width <= 0) || (dst_height <= 0) || (FreeImage_GetWidth(src) <= 0) || (FreeImage_GetHeight(src) <= 0)) { + return NULL; + } + + // select the filter + CGenericFilter *pFilter = NULL; + switch (filter) { + case FILTER_BOX: + pFilter = new(std::nothrow) CBoxFilter(); + break; + case FILTER_BICUBIC: + pFilter = new(std::nothrow) CBicubicFilter(); + break; + case FILTER_BILINEAR: + pFilter = new(std::nothrow) CBilinearFilter(); + break; + case FILTER_BSPLINE: + pFilter = new(std::nothrow) CBSplineFilter(); + break; + case FILTER_CATMULLROM: + pFilter = new(std::nothrow) CCatmullRomFilter(); + break; + case FILTER_LANCZOS3: + pFilter = new(std::nothrow) CLanczos3Filter(); + break; + } + + if (!pFilter) { + return NULL; + } + + CResizeEngine Engine(pFilter); + + dst = Engine.scale(src, dst_width, dst_height, 0, 0, + FreeImage_GetWidth(src), FreeImage_GetHeight(src)); + + delete pFilter; + + // copy metadata from src to dst + FreeImage_CloneMetadata(dst, src); + + return dst; +} + +FIBITMAP * DLL_CALLCONV +FreeImage_MakeThumbnail(FIBITMAP *dib, int max_pixel_size, BOOL convert) { + FIBITMAP *thumbnail = NULL; + int new_width, new_height; + + if(!FreeImage_HasPixels(dib) || (max_pixel_size <= 0)) return NULL; + + int width = FreeImage_GetWidth(dib); + int height = FreeImage_GetHeight(dib); + + if(max_pixel_size == 0) max_pixel_size = 1; + + if((width < max_pixel_size) && (height < max_pixel_size)) { + // image is smaller than the requested thumbnail + return FreeImage_Clone(dib); + } + + if(width > height) { + new_width = max_pixel_size; + // change image height with the same ratio + double ratio = ((double)new_width / (double)width); + new_height = (int)(height * ratio + 0.5); + if(new_height == 0) new_height = 1; + } else { + new_height = max_pixel_size; + // change image width with the same ratio + double ratio = ((double)new_height / (double)height); + new_width = (int)(width * ratio + 0.5); + if(new_width == 0) new_width = 1; + } + + const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); + + // perform downsampling using a bilinear interpolation + + switch(image_type) { + case FIT_BITMAP: + case FIT_UINT16: + case FIT_RGB16: + case FIT_RGBA16: + case FIT_FLOAT: + case FIT_RGBF: + case FIT_RGBAF: + { + FREE_IMAGE_FILTER filter = FILTER_BILINEAR; + thumbnail = FreeImage_Rescale(dib, new_width, new_height, filter); + } + break; + + case FIT_INT16: + case FIT_UINT32: + case FIT_INT32: + case FIT_DOUBLE: + case FIT_COMPLEX: + default: + // cannot rescale this kind of image + thumbnail = NULL; + break; + } + + if((thumbnail != NULL) && (image_type != FIT_BITMAP) && convert) { + // convert to a standard bitmap + FIBITMAP *bitmap = NULL; + switch(image_type) { + case FIT_UINT16: + bitmap = FreeImage_ConvertTo8Bits(thumbnail); + break; + case FIT_RGB16: + bitmap = FreeImage_ConvertTo24Bits(thumbnail); + break; + case FIT_RGBA16: + bitmap = FreeImage_ConvertTo32Bits(thumbnail); + break; + case FIT_FLOAT: + bitmap = FreeImage_ConvertToStandardType(thumbnail, TRUE); + break; + case FIT_RGBF: + bitmap = FreeImage_ToneMapping(thumbnail, FITMO_DRAGO03); + break; + case FIT_RGBAF: + // no way to keep the transparency yet ... + FIBITMAP *rgbf = FreeImage_ConvertToRGBF(thumbnail); + bitmap = FreeImage_ToneMapping(rgbf, FITMO_DRAGO03); + FreeImage_Unload(rgbf); + break; + } + if(bitmap != NULL) { + FreeImage_Unload(thumbnail); + thumbnail = bitmap; + } + } + + // copy metadata from src to dst + FreeImage_CloneMetadata(thumbnail, dib); + + return thumbnail; +} diff --git a/Source/FreeImageToolkit/Resize.cpp b/Source/FreeImageToolkit/Resize.cpp index f342bb7..4138d73 100644 --- a/Source/FreeImageToolkit/Resize.cpp +++ b/Source/FreeImageToolkit/Resize.cpp @@ -1,1992 +1,1992 @@ -// ========================================================== -// Upsampling / downsampling classes -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// - Detlev Vendt (detlev.vendt@brillit.de) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "Resize.h" - -/** -Returns the color type of a bitmap. In contrast to FreeImage_GetColorType, -this function optionally supports a boolean OUT parameter, that receives TRUE, -if the specified bitmap is greyscale, that is, it consists of grey colors only. -Although it returns the same value as returned by FreeImage_GetColorType for all -image types, this extended function primarily is intended for palletized images, -since the boolean pointed to by 'bIsGreyscale' remains unchanged for RGB(A/F) -images. However, the outgoing boolean is properly maintained for palletized images, -as well as for any non-RGB image type, like FIT_UINTxx and FIT_DOUBLE, for example. -@param dib A pointer to a FreeImage bitmap to calculate the extended color type for -@param bIsGreyscale A pointer to a boolean, that receives TRUE, if the specified bitmap -is greyscale, that is, it consists of grey colors only. This parameter can be NULL. -@return the color type of the specified bitmap -*/ -static FREE_IMAGE_COLOR_TYPE -GetExtendedColorType(FIBITMAP *dib, BOOL *bIsGreyscale) { - const unsigned bpp = FreeImage_GetBPP(dib); - const unsigned size = CalculateUsedPaletteEntries(bpp); - const RGBQUAD * const pal = FreeImage_GetPalette(dib); - FREE_IMAGE_COLOR_TYPE color_type = FIC_MINISBLACK; - BOOL bIsGrey = TRUE; - - switch (bpp) { - case 1: - { - for (unsigned i = 0; i < size; i++) { - if ((pal[i].rgbRed != pal[i].rgbGreen) || (pal[i].rgbRed != pal[i].rgbBlue)) { - color_type = FIC_PALETTE; - bIsGrey = FALSE; - break; - } - } - if (bIsGrey) { - if (pal[0].rgbBlue == 255 && pal[1].rgbBlue == 0) { - color_type = FIC_MINISWHITE; - } else if (pal[0].rgbBlue != 0 || pal[1].rgbBlue != 255) { - color_type = FIC_PALETTE; - } - } - break; - } - - case 4: - case 8: - { - for (unsigned i = 0; i < size; i++) { - if ((pal[i].rgbRed != pal[i].rgbGreen) || (pal[i].rgbRed != pal[i].rgbBlue)) { - color_type = FIC_PALETTE; - bIsGrey = FALSE; - break; - } - if (color_type != FIC_PALETTE && pal[i].rgbBlue != i) { - if ((size - i - 1) != pal[i].rgbBlue) { - color_type = FIC_PALETTE; - if (!bIsGreyscale) { - // exit loop if we're not setting - // bIsGreyscale parameter - break; - } - } else { - color_type = FIC_MINISWHITE; - } - } - } - break; - } - - default: - { - color_type = FreeImage_GetColorType(dib); - bIsGrey = (color_type == FIC_MINISBLACK) ? TRUE : FALSE; - break; - } - - } - if (bIsGreyscale) { - *bIsGreyscale = bIsGrey; - } - - return color_type; -} - -/** -Returns a pointer to an RGBA palette, created from the specified bitmap. -The RGBA palette is a copy of the specified bitmap's palette, that, additionally -contains the bitmap's transparency information in the rgbReserved member -of the palette's RGBQUAD elements. -@param dib A pointer to a FreeImage bitmap to create the RGBA palette from. -@param buffer A pointer to the buffer to store the RGBA palette. -@return A pointer to the newly created RGBA palette or NULL, if the specified -bitmap is no palletized standard bitmap. If non-NULL, the returned value is -actually the pointer passed in parameter 'buffer'. -*/ -static inline RGBQUAD * -GetRGBAPalette(FIBITMAP *dib, RGBQUAD * const buffer) { - // clone the palette - const unsigned ncolors = FreeImage_GetColorsUsed(dib); - if (ncolors == 0) { - return NULL; - } - memcpy(buffer, FreeImage_GetPalette(dib), ncolors * sizeof(RGBQUAD)); - // merge the transparency table - const unsigned ntransp = MIN(ncolors, FreeImage_GetTransparencyCount(dib)); - const BYTE * const tt = FreeImage_GetTransparencyTable(dib); - for (unsigned i = 0; i < ntransp; i++) { - buffer[i].rgbReserved = tt[i]; - } - for (unsigned i = ntransp; i < ncolors; i++) { - buffer[i].rgbReserved = 255; - } - return buffer; -} - -// -------------------------------------------------------------------------- - -CWeightsTable::CWeightsTable(CGenericFilter *pFilter, unsigned uDstSize, unsigned uSrcSize) { - unsigned u; - double dWidth; - double dFScale = 1.0; - const double dFilterWidth = pFilter->GetWidth(); - - // scale factor - const double dScale = double(uDstSize) / double(uSrcSize); - - if(dScale < 1.0) { - // minification - dWidth = dFilterWidth / dScale; - dFScale = dScale; - } else { - // magnification - dWidth= dFilterWidth; - } - - // allocate a new line contributions structure - // - // window size is the number of sampled pixels - m_WindowSize = 2 * (int)ceil(dWidth) + 1; - m_LineLength = uDstSize; - // allocate list of contributions - m_WeightTable = (Contribution*)malloc(m_LineLength * sizeof(Contribution)); - for(u = 0 ; u < m_LineLength ; u++) { - // allocate contributions for every pixel - m_WeightTable[u].Weights = (double*)malloc(m_WindowSize * sizeof(double)); - } - - // offset for discrete to continuous coordinate conversion - const double dOffset = (0.5 / dScale) - 0.5; - - for(u = 0; u < m_LineLength; u++) { - // scan through line of contributions - const double dCenter = (double)u / dScale + dOffset; // reverse mapping - // find the significant edge points that affect the pixel - int iLeft = MAX (0, (int)floor (dCenter - dWidth)); - int iRight = MIN ((int)ceil (dCenter + dWidth), int(uSrcSize) - 1); - - // cut edge points to fit in filter window in case of spill-off - if((iRight - iLeft + 1) > int(m_WindowSize)) { - if(iLeft < (int(uSrcSize) - 1 / 2)) { - iLeft++; - } else { - iRight--; - } - } - - m_WeightTable[u].Left = iLeft; - m_WeightTable[u].Right = iRight; - - int iSrc = 0; - double dTotalWeight = 0; // zero sum of weights - for(iSrc = iLeft; iSrc <= iRight; iSrc++) { - // calculate weights - const double weight = dFScale * pFilter->Filter(dFScale * (dCenter - (double)iSrc)); - m_WeightTable[u].Weights[iSrc-iLeft] = weight; - dTotalWeight += weight; - } - if((dTotalWeight > 0) && (dTotalWeight != 1)) { - // normalize weight of neighbouring points - for(iSrc = iLeft; iSrc <= iRight; iSrc++) { - // normalize point - m_WeightTable[u].Weights[iSrc-iLeft] /= dTotalWeight; - } - // simplify the filter, discarding null weights at the right - iSrc = iRight - iLeft; - while(m_WeightTable[u].Weights[iSrc] == 0) { - m_WeightTable[u].Right--; - iSrc--; - if(m_WeightTable[u].Right == m_WeightTable[u].Left) { - break; - } - } - - } - } -} - -CWeightsTable::~CWeightsTable() { - for(unsigned u = 0; u < m_LineLength; u++) { - // free contributions for every pixel - free(m_WeightTable[u].Weights); - } - // free list of pixels contributions - free(m_WeightTable); -} - -// -------------------------------------------------------------------------- - -FIBITMAP* CResizeEngine::scale(FIBITMAP *src, unsigned dst_width, unsigned dst_height, unsigned src_left, unsigned src_top, unsigned src_width, unsigned src_height) { - - const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(src); - const unsigned src_bpp = FreeImage_GetBPP(src); - - // determine the image's color type - BOOL bIsGreyscale = FALSE; - FREE_IMAGE_COLOR_TYPE color_type; - if (src_bpp <= 8) { - color_type = GetExtendedColorType(src, &bIsGreyscale); - } else { - color_type = FIC_RGB; - } - - // determine the required bit depth of the destination image - unsigned dst_bpp; - if (color_type == FIC_PALETTE && !bIsGreyscale) { - // non greyscale FIC_PALETTE images require a high-color destination - // image (24- or 32-bits depending on the image's transparent state) - dst_bpp = FreeImage_IsTransparent(src) ? 32 : 24; - } else if (src_bpp <= 8) { - // greyscale images require an 8-bit destination image - // (or a 32-bit image if the image is transparent) - dst_bpp = FreeImage_IsTransparent(src) ? 32 : 8; - } else if (src_bpp == 16 && image_type == FIT_BITMAP) { - // 16-bit 555 and 565 RGB images require a high-color destination image - // (fixed to 24 bits, since 16-bit RGBs don't support transparency in FreeImage) - dst_bpp = 24; - } else { - // bit depth remains unchanged for all other images - dst_bpp = src_bpp; - } - - // early exit if destination size is equal to source size - if ((src_width == dst_width) && (src_height == dst_height)) { - FIBITMAP *out = src; - FIBITMAP *tmp = src; - if ((src_width != FreeImage_GetWidth(src)) || (src_height != FreeImage_GetHeight(src))) { - out = FreeImage_Copy(tmp, src_left, src_top, src_left + src_width, src_top + src_height); - tmp = out; - } - if (src_bpp != dst_bpp) { - switch (dst_bpp) { - case 8: - out = FreeImage_ConvertToGreyscale(tmp); - if (tmp != src) { - FreeImage_Unload(tmp); - } - break; - - case 24: - out = FreeImage_ConvertTo24Bits(tmp); - if (tmp != src) { - FreeImage_Unload(tmp); - } - break; - - case 32: - out = FreeImage_ConvertTo32Bits(tmp); - if (tmp != src) { - FreeImage_Unload(tmp); - } - break; - } - } - - return (out != src) ? out : FreeImage_Clone(src); - } - - RGBQUAD pal_buffer[256]; - RGBQUAD *src_pal = NULL; - - // provide the source image's palette to the rescaler for - // FIC_PALETTE type images (this includes palletized greyscale - // images with an unordered palette) - if (color_type == FIC_PALETTE) { - if (dst_bpp == 32) { - // a 32 bit destination image signals transparency, so - // create an RGBA palette from the source palette - src_pal = GetRGBAPalette(src, pal_buffer); - } else { - src_pal = FreeImage_GetPalette(src); - } - } - - // allocate the dst image - FIBITMAP *dst = FreeImage_AllocateT(image_type, dst_width, dst_height, dst_bpp, 0, 0, 0); - if (!dst) { - return NULL; - } - - if (dst_bpp == 8) { - RGBQUAD * const dst_pal = FreeImage_GetPalette(dst); - if (color_type == FIC_MINISWHITE) { - // build an inverted greyscale palette - CREATE_GREYSCALE_PALETTE_REVERSE(dst_pal, 256); - } - /* - else { - // build a default greyscale palette - // Currently, FreeImage_AllocateT already creates a default - // greyscale palette for 8 bpp images, so we can skip this here. - CREATE_GREYSCALE_PALETTE(dst_pal, 256); - } - */ - } - - // calculate x and y offsets; since FreeImage uses bottom-up bitmaps, the - // value of src_offset_y is measured from the bottom of the image - unsigned src_offset_x = src_left; - unsigned src_offset_y; - if (src_top > 0) { - src_offset_y = FreeImage_GetHeight(src) - src_height - src_top; - } else { - src_offset_y = 0; - } - - /* - Decide which filtering order (xy or yx) is faster for this mapping. - --- The theory --- - Try to minimize calculations by counting the number of convolution multiplies - if(dst_width*src_height <= src_width*dst_height) { - // xy filtering - } else { - // yx filtering - } - --- The practice --- - Try to minimize calculations by counting the number of vertical convolutions (the most time consuming task) - if(dst_width*dst_height <= src_width*dst_height) { - // xy filtering - } else { - // yx filtering - } - */ - - if (dst_width <= src_width) { - // xy filtering - // ------------- - - FIBITMAP *tmp = NULL; - - if (src_width != dst_width) { - // source and destination widths are different so, we must - // filter horizontally - if (src_height != dst_height) { - // source and destination heights are also different so, we need - // a temporary image - tmp = FreeImage_AllocateT(image_type, dst_width, src_height, dst_bpp, 0, 0, 0); - if (!tmp) { - FreeImage_Unload(dst); - return NULL; - } - } else { - // source and destination heights are equal so, we can directly - // scale into destination image (second filter method will not - // be invoked) - tmp = dst; - } - - // scale source image horizontally into temporary (or destination) image - horizontalFilter(src, src_height, src_width, src_offset_x, src_offset_y, src_pal, tmp, dst_width); - - // set x and y offsets to zero for the second filter method - // invocation (the temporary image only contains the portion of - // the image to be rescaled with no offsets) - src_offset_x = 0; - src_offset_y = 0; - - // also ensure, that the second filter method gets no source - // palette (the temporary image is palletized only, if it is - // greyscale; in that case, it is an 8-bit image with a linear - // palette so, the source palette is not needed or will even be - // mismatching, if the source palette is unordered) - src_pal = NULL; - } else { - // source and destination widths are equal so, just copy the - // image pointer - tmp = src; - } - - if (src_height != dst_height) { - // source and destination heights are different so, scale - // temporary (or source) image vertically into destination image - verticalFilter(tmp, dst_width, src_height, src_offset_x, src_offset_y, src_pal, dst, dst_height); - } - - // free temporary image, if not pointing to either src or dst - if (tmp != src && tmp != dst) { - FreeImage_Unload(tmp); - } - - } else { - // yx filtering - // ------------- - - // Remark: - // The yx filtering branch could be more optimized by taking into, - // account that (src_width != dst_width) is always true, which - // follows from the above condition, which selects filtering order. - // Since (dst_width <= src_width) == TRUE selects xy filtering, - // both widths must be different when performing yx filtering. - // However, to make the code more robust, not depending on that - // condition and more symmetric to the xy filtering case, these - // (src_width != dst_width) conditions are still in place. - - FIBITMAP *tmp = NULL; - - if (src_height != dst_height) { - // source and destination heights are different so, we must - // filter vertically - if (src_width != dst_width) { - // source and destination widths are also different so, we need - // a temporary image - tmp = FreeImage_AllocateT(image_type, src_width, dst_height, dst_bpp, 0, 0, 0); - if (!tmp) { - FreeImage_Unload(dst); - return NULL; - } - } else { - // source and destination widths are equal so, we can directly - // scale into destination image (second filter method will not - // be invoked) - tmp = dst; - } - - // scale source image vertically into temporary (or destination) image - verticalFilter(src, src_width, src_height, src_offset_x, src_offset_y, src_pal, tmp, dst_height); - - // set x and y offsets to zero for the second filter method - // invocation (the temporary image only contains the portion of - // the image to be rescaled with no offsets) - src_offset_x = 0; - src_offset_y = 0; - - // also ensure, that the second filter method gets no source - // palette (the temporary image is palletized only, if it is - // greyscale; in that case, it is an 8-bit image with a linear - // palette so, the source palette is not needed or will even be - // mismatching, if the source palette is unordered) - src_pal = NULL; - - } else { - // source and destination heights are equal so, just copy the - // image pointer - tmp = src; - } - - if (src_width != dst_width) { - // source and destination heights are different so, scale - // temporary (or source) image horizontally into destination image - horizontalFilter(tmp, dst_height, src_width, src_offset_x, src_offset_y, src_pal, dst, dst_width); - } - - // free temporary image, if not pointing to either src or dst - if (tmp != src && tmp != dst) { - FreeImage_Unload(tmp); - } - } - - return dst; -} - -void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsigned src_width, unsigned src_offset_x, unsigned src_offset_y, const RGBQUAD *const src_pal, FIBITMAP *const dst, unsigned dst_width) { - - // allocate and calculate the contributions - CWeightsTable weightsTable(m_pFilter, dst_width, src_width); - - // step through rows - switch(FreeImage_GetImageType(src)) { - case FIT_BITMAP: - { - switch(FreeImage_GetBPP(src)) { - case 1: - { - switch(FreeImage_GetBPP(dst)) { - case 8: - { - // transparently convert the 1-bit non-transparent greyscale - // image to 8 bpp - src_offset_x >>= 3; - if (src_pal) { - // we have got a palette - for (unsigned y = 0; y < height; y++) { - // scale each row - const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; - BYTE * const dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary - double value = 0; - - for (unsigned i = iLeft; i <= iRight; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const unsigned pixel = (src_bits[i >> 3] & (0x80 >> (i & 0x07))) != 0; - value += (weightsTable.getWeight(x, i - iLeft) * (double)*(BYTE *)&src_pal[pixel]); - } - - // clamp and place result in destination pixel - dst_bits[x] = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); - } - } - } else { - // we do not have a palette - for (unsigned y = 0; y < height; y++) { - // scale each row - const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; - BYTE * const dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary - double value = 0; - - for (unsigned i = iLeft; i <= iRight; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const unsigned pixel = (src_bits[i >> 3] & (0x80 >> (i & 0x07))) != 0; - value += (weightsTable.getWeight(x, i - iLeft) * (double)pixel); - } - value *= 0xFF; - - // clamp and place result in destination pixel - dst_bits[x] = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); - } - } - } - } - break; - - case 24: - { - // transparently convert the non-transparent 1-bit image - // to 24 bpp; we always have got a palette here - src_offset_x >>= 3; - - for (unsigned y = 0; y < height; y++) { - // scale each row - const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; - BYTE *dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary - double r = 0, g = 0, b = 0; - - for (unsigned i = iLeft; i <= iRight; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(x, i - iLeft); - const unsigned pixel = (src_bits[i >> 3] & (0x80 >> (i & 0x07))) != 0; - const BYTE * const entry = (BYTE *)&src_pal[pixel]; - r += (weight * (double)entry[FI_RGBA_RED]); - g += (weight * (double)entry[FI_RGBA_GREEN]); - b += (weight * (double)entry[FI_RGBA_BLUE]); - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits += 3; - } - } - } - break; - - case 32: - { - // transparently convert the transparent 1-bit image - // to 32 bpp; we always have got a palette here - src_offset_x >>= 3; - - for (unsigned y = 0; y < height; y++) { - // scale each row - const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; - BYTE *dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary - double r = 0, g = 0, b = 0, a = 0; - - for (unsigned i = iLeft; i <= iRight; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(x, i - iLeft); - const unsigned pixel = (src_bits[i >> 3] & (0x80 >> (i & 0x07))) != 0; - const BYTE * const entry = (BYTE *)&src_pal[pixel]; - r += (weight * (double)entry[FI_RGBA_RED]); - g += (weight * (double)entry[FI_RGBA_GREEN]); - b += (weight * (double)entry[FI_RGBA_BLUE]); - a += (weight * (double)entry[FI_RGBA_ALPHA]); - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int)(a + 0.5), 0, 0xFF); - dst_bits += 4; - } - } - } - break; - } - } - break; - - case 4: - { - switch(FreeImage_GetBPP(dst)) { - case 8: - { - // transparently convert the non-transparent 4-bit greyscale image - // to 8 bpp; we always have got a palette for 4-bit images - src_offset_x >>= 1; - - for (unsigned y = 0; y < height; y++) { - // scale each row - const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; - BYTE * const dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary - double value = 0; - - for (unsigned i = iLeft; i <= iRight; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const unsigned pixel = i & 0x01 ? src_bits[i >> 1] & 0x0F : src_bits[i >> 1] >> 4; - value += (weightsTable.getWeight(x, i - iLeft) - * (double)*(BYTE *)&src_pal[pixel]); - } - - // clamp and place result in destination pixel - dst_bits[x] = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); - } - } - } - break; - - case 24: - { - // transparently convert the non-transparent 4-bit image - // to 24 bpp; we always have got a palette for 4-bit images - src_offset_x >>= 1; - - for (unsigned y = 0; y < height; y++) { - // scale each row - const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; - BYTE *dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary - double r = 0, g = 0, b = 0; - - for (unsigned i = iLeft; i <= iRight; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(x, i - iLeft); - const unsigned pixel = i & 0x01 ? src_bits[i >> 1] & 0x0F : src_bits[i >> 1] >> 4; - const BYTE * const entry = (BYTE *)&src_pal[pixel]; - r += (weight * (double)entry[FI_RGBA_RED]); - g += (weight * (double)entry[FI_RGBA_GREEN]); - b += (weight * (double)entry[FI_RGBA_BLUE]); - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits += 3; - } - } - } - break; - - case 32: - { - // transparently convert the transparent 4-bit image - // to 32 bpp; we always have got a palette for 4-bit images - src_offset_x >>= 1; - - for (unsigned y = 0; y < height; y++) { - // scale each row - const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; - BYTE *dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary - double r = 0, g = 0, b = 0, a = 0; - - for (unsigned i = iLeft; i <= iRight; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(x, i - iLeft); - const unsigned pixel = i & 0x01 ? src_bits[i >> 1] & 0x0F : src_bits[i >> 1] >> 4; - const BYTE * const entry = (BYTE *)&src_pal[pixel]; - r += (weight * (double)entry[FI_RGBA_RED]); - g += (weight * (double)entry[FI_RGBA_GREEN]); - b += (weight * (double)entry[FI_RGBA_BLUE]); - a += (weight * (double)entry[FI_RGBA_ALPHA]); - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int)(a + 0.5), 0, 0xFF); - dst_bits += 4; - } - } - } - break; - } - } - break; - - case 8: - { - switch(FreeImage_GetBPP(dst)) { - case 8: - { - // scale the 8-bit non-transparent greyscale image - // into an 8 bpp destination image - if (src_pal) { - // we have got a palette - for (unsigned y = 0; y < height; y++) { - // scale each row - const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; - BYTE * const dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary - const BYTE * const pixel = src_bits + iLeft; - double value = 0; - - // for(i = iLeft to iRight) - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - value += (weightsTable.getWeight(x, i) - * (double)*(BYTE *)&src_pal[pixel[i]]); - } - - // clamp and place result in destination pixel - dst_bits[x] = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); - } - } - } else { - // we do not have a palette - for (unsigned y = 0; y < height; y++) { - // scale each row - const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; - BYTE * const dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary - const BYTE * const pixel = src_bits + iLeft; - double value = 0; - - // for(i = iLeft to iRight) - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - value += (weightsTable.getWeight(x, i) * (double)pixel[i]); - } - - // clamp and place result in destination pixel - dst_bits[x] = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); - } - } - } - } - break; - - case 24: - { - // transparently convert the non-transparent 8-bit image - // to 24 bpp; we always have got a palette here - for (unsigned y = 0; y < height; y++) { - // scale each row - const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; - BYTE *dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary - const BYTE * const pixel = src_bits + iLeft; - double r = 0, g = 0, b = 0; - - // for(i = iLeft to iRight) - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(x, i); - const BYTE *const entry = (BYTE *)&src_pal[pixel[i]]; - r += (weight * (double)entry[FI_RGBA_RED]); - g += (weight * (double)entry[FI_RGBA_GREEN]); - b += (weight * (double)entry[FI_RGBA_BLUE]); - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits += 3; - } - } - } - break; - - case 32: - { - // transparently convert the transparent 8-bit image - // to 32 bpp; we always have got a palette here - for (unsigned y = 0; y < height; y++) { - // scale each row - const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; - BYTE *dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary - const BYTE * const pixel = src_bits + iLeft; - double r = 0, g = 0, b = 0, a = 0; - - // for(i = iLeft to iRight) - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(x, i); - const BYTE * const entry = (BYTE *)&src_pal[pixel[i]]; - r += (weight * (double)entry[FI_RGBA_RED]); - g += (weight * (double)entry[FI_RGBA_GREEN]); - b += (weight * (double)entry[FI_RGBA_BLUE]); - a += (weight * (double)entry[FI_RGBA_ALPHA]); - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int)(a + 0.5), 0, 0xFF); - dst_bits += 4; - } - } - } - break; - } - } - break; - - case 16: - { - // transparently convert the 16-bit non-transparent image - // to 24 bpp - if (IS_FORMAT_RGB565(src)) { - // image has 565 format - for (unsigned y = 0; y < height; y++) { - // scale each row - const WORD * const src_bits = (WORD *)FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x / sizeof(WORD); - BYTE *dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary - const WORD *pixel = src_bits + iLeft; - double r = 0, g = 0, b = 0; - - // for(i = iLeft to iRight) - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(x, i); - r += (weight * (double)((*pixel & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT)); - g += (weight * (double)((*pixel & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT)); - b += (weight * (double)((*pixel & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT)); - pixel++; - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(((g * 0xFF) / 0x3F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits += 3; - } - } - } else { - // image has 555 format - for (unsigned y = 0; y < height; y++) { - // scale each row - const WORD * const src_bits = (WORD *)FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; - BYTE *dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary - const WORD *pixel = src_bits + iLeft; - double r = 0, g = 0, b = 0; - - // for(i = iLeft to iRight) - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(x, i); - r += (weight * (double)((*pixel & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT)); - g += (weight * (double)((*pixel & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT)); - b += (weight * (double)((*pixel & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT)); - pixel++; - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(((g * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits += 3; - } - } - } - } - break; - - case 24: - { - // scale the 24-bit non-transparent image - // into a 24 bpp destination image - for (unsigned y = 0; y < height; y++) { - // scale each row - const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x * 3; - BYTE *dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary - const BYTE * pixel = src_bits + iLeft * 3; - double r = 0, g = 0, b = 0; - - // for(i = iLeft to iRight) - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(x, i); - r += (weight * (double)pixel[FI_RGBA_RED]); - g += (weight * (double)pixel[FI_RGBA_GREEN]); - b += (weight * (double)pixel[FI_RGBA_BLUE]); - pixel += 3; - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits += 3; - } - } - } - break; - - case 32: - { - // scale the 32-bit transparent image - // into a 32 bpp destination image - for (unsigned y = 0; y < height; y++) { - // scale each row - const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x * 4; - BYTE *dst_bits = FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary - const BYTE *pixel = src_bits + iLeft * 4; - double r = 0, g = 0, b = 0, a = 0; - - // for(i = iLeft to iRight) - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(x, i); - r += (weight * (double)pixel[FI_RGBA_RED]); - g += (weight * (double)pixel[FI_RGBA_GREEN]); - b += (weight * (double)pixel[FI_RGBA_BLUE]); - a += (weight * (double)pixel[FI_RGBA_ALPHA]); - pixel += 4; - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int)(a + 0.5), 0, 0xFF); - dst_bits += 4; - } - } - } - break; - } - } - break; - - case FIT_UINT16: - { - // Calculate the number of words per pixel (1 for 16-bit, 3 for 48-bit or 4 for 64-bit) - const unsigned wordspp = (FreeImage_GetLine(src) / src_width) / sizeof(WORD); - - for (unsigned y = 0; y < height; y++) { - // scale each row - const WORD *src_bits = (WORD*)FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x / sizeof(WORD); - WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary - const WORD *pixel = src_bits + iLeft * wordspp; - double value = 0; - - // for(i = iLeft to iRight) - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(x, i); - value += (weight * (double)pixel[0]); - pixel++; - } - - // clamp and place result in destination pixel - dst_bits[0] = (WORD)CLAMP((int)(value + 0.5), 0, 0xFFFF); - dst_bits += wordspp; - } - } - } - break; - - case FIT_RGB16: - { - // Calculate the number of words per pixel (1 for 16-bit, 3 for 48-bit or 4 for 64-bit) - const unsigned wordspp = (FreeImage_GetLine(src) / src_width) / sizeof(WORD); - - for (unsigned y = 0; y < height; y++) { - // scale each row - const WORD *src_bits = (WORD*)FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x / sizeof(WORD); - WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary - const WORD *pixel = src_bits + iLeft * wordspp; - double r = 0, g = 0, b = 0; - - // for(i = iLeft to iRight) - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(x, i); - r += (weight * (double)pixel[0]); - g += (weight * (double)pixel[1]); - b += (weight * (double)pixel[2]); - pixel += wordspp; - } - - // clamp and place result in destination pixel - dst_bits[0] = (WORD)CLAMP((int)(r + 0.5), 0, 0xFFFF); - dst_bits[1] = (WORD)CLAMP((int)(g + 0.5), 0, 0xFFFF); - dst_bits[2] = (WORD)CLAMP((int)(b + 0.5), 0, 0xFFFF); - dst_bits += wordspp; - } - } - } - break; - - case FIT_RGBA16: - { - // Calculate the number of words per pixel (1 for 16-bit, 3 for 48-bit or 4 for 64-bit) - const unsigned wordspp = (FreeImage_GetLine(src) / src_width) / sizeof(WORD); - - for (unsigned y = 0; y < height; y++) { - // scale each row - const WORD *src_bits = (WORD*)FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x / sizeof(WORD); - WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y); - - for (unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary - const WORD *pixel = src_bits + iLeft * wordspp; - double r = 0, g = 0, b = 0, a = 0; - - // for(i = iLeft to iRight) - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(x, i); - r += (weight * (double)pixel[0]); - g += (weight * (double)pixel[1]); - b += (weight * (double)pixel[2]); - a += (weight * (double)pixel[3]); - pixel += wordspp; - } - - // clamp and place result in destination pixel - dst_bits[0] = (WORD)CLAMP((int)(r + 0.5), 0, 0xFFFF); - dst_bits[1] = (WORD)CLAMP((int)(g + 0.5), 0, 0xFFFF); - dst_bits[2] = (WORD)CLAMP((int)(b + 0.5), 0, 0xFFFF); - dst_bits[3] = (WORD)CLAMP((int)(a + 0.5), 0, 0xFFFF); - dst_bits += wordspp; - } - } - } - break; - - case FIT_FLOAT: - case FIT_RGBF: - case FIT_RGBAF: - { - // Calculate the number of floats per pixel (1 for 32-bit, 3 for 96-bit or 4 for 128-bit) - const unsigned floatspp = (FreeImage_GetLine(src) / src_width) / sizeof(float); - - for(unsigned y = 0; y < height; y++) { - // scale each row - const float *src_bits = (float*)FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x / sizeof(float); - float *dst_bits = (float*)FreeImage_GetScanLine(dst, y); - - for(unsigned x = 0; x < dst_width; x++) { - // loop through row - const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary - const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary - double value[4] = {0, 0, 0, 0}; // 4 = 128 bpp max - - for(unsigned i = iLeft; i <= iRight; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(x, i-iLeft); - - unsigned index = i * floatspp; // pixel index - for (unsigned j = 0; j < floatspp; j++) { - value[j] += (weight * (double)src_bits[index++]); - } - } - - // place result in destination pixel - for (unsigned j = 0; j < floatspp; j++) { - dst_bits[j] = (float)value[j]; - } - - dst_bits += floatspp; - } - } - } - break; - } -} - -/// Performs vertical image filtering -void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned src_height, unsigned src_offset_x, unsigned src_offset_y, const RGBQUAD *const src_pal, FIBITMAP *const dst, unsigned dst_height) { - - // allocate and calculate the contributions - CWeightsTable weightsTable(m_pFilter, dst_height, src_height); - - // step through columns - switch(FreeImage_GetImageType(src)) { - case FIT_BITMAP: - { - const unsigned dst_pitch = FreeImage_GetPitch(dst); - BYTE * const dst_base = FreeImage_GetBits(dst); - - switch(FreeImage_GetBPP(src)) { - case 1: - { - const unsigned src_pitch = FreeImage_GetPitch(src); - const BYTE * const src_base = FreeImage_GetBits(src) - + src_offset_y * src_pitch + (src_offset_x >> 3); - - switch(FreeImage_GetBPP(dst)) { - case 8: - { - // transparently convert the 1-bit non-transparent greyscale - // image to 8 bpp - if (src_pal) { - // we have got a palette - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - BYTE *dst_bits = dst_base + x; - const unsigned index = x >> 3; - const unsigned mask = 0x80 >> (x & 0x07); - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const BYTE *src_bits = src_base + iLeft * src_pitch + index; - double value = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const unsigned pixel = (*src_bits & mask) != 0; - value += (weightsTable.getWeight(y, i) - * (double)*(BYTE *)&src_pal[pixel]); - src_bits += src_pitch; - } - value *= 0xFF; - - // clamp and place result in destination pixel - *dst_bits = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } else { - // we do not have a palette - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - BYTE *dst_bits = dst_base + x; - const unsigned index = x >> 3; - const unsigned mask = 0x80 >> (x & 0x07); - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const BYTE *src_bits = src_base + iLeft * src_pitch + index; - double value = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - value += (weightsTable.getWeight(y, i) - * (double)((*src_bits & mask) != 0)); - src_bits += src_pitch; - } - value *= 0xFF; - - // clamp and place result in destination pixel - *dst_bits = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } - } - break; - - case 24: - { - // transparently convert the non-transparent 1-bit image - // to 24 bpp; we always have got a palette here - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - BYTE *dst_bits = dst_base + x * 3; - const unsigned index = x >> 3; - const unsigned mask = 0x80 >> (x & 0x07); - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const BYTE *src_bits = src_base + iLeft * src_pitch + index; - double r = 0, g = 0, b = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(y, i); - const unsigned pixel = (*src_bits & mask) != 0; - const BYTE * const entry = (BYTE *)&src_pal[pixel]; - r += (weight * (double)entry[FI_RGBA_RED]); - g += (weight * (double)entry[FI_RGBA_GREEN]); - b += (weight * (double)entry[FI_RGBA_BLUE]); - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } - break; - - case 32: - { - // transparently convert the transparent 1-bit image - // to 32 bpp; we always have got a palette here - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - BYTE *dst_bits = dst_base + x * 4; - const unsigned index = x >> 3; - const unsigned mask = 0x80 >> (x & 0x07); - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const BYTE *src_bits = src_base + iLeft * src_pitch + index; - double r = 0, g = 0, b = 0, a = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(y, i); - const unsigned pixel = (*src_bits & mask) != 0; - const BYTE * const entry = (BYTE *)&src_pal[pixel]; - r += (weight * (double)entry[FI_RGBA_RED]); - g += (weight * (double)entry[FI_RGBA_GREEN]); - b += (weight * (double)entry[FI_RGBA_BLUE]); - a += (weight * (double)entry[FI_RGBA_ALPHA]); - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int)(a + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } - break; - } - } - break; - - case 4: - { - const unsigned src_pitch = FreeImage_GetPitch(src); - const BYTE *const src_base = FreeImage_GetBits(src) + src_offset_y * src_pitch + (src_offset_x >> 1); - - switch(FreeImage_GetBPP(dst)) { - case 8: - { - // transparently convert the non-transparent 4-bit greyscale image - // to 8 bpp; we always have got a palette for 4-bit images - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - BYTE *dst_bits = dst_base + x; - const unsigned index = x >> 1; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const BYTE *src_bits = src_base + iLeft * src_pitch + index; - double value = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const unsigned pixel = x & 0x01 ? *src_bits & 0x0F : *src_bits >> 4; - value += (weightsTable.getWeight(y, i) - * (double)*(BYTE *)&src_pal[pixel]); - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - *dst_bits = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } - break; - - case 24: - { - // transparently convert the non-transparent 4-bit image - // to 24 bpp; we always have got a palette for 4-bit images - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - BYTE *dst_bits = dst_base + x * 3; - const unsigned index = x >> 1; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const BYTE *src_bits = src_base + iLeft * src_pitch + index; - double r = 0, g = 0, b = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(y, i); - const unsigned pixel = x & 0x01 ? *src_bits & 0x0F : *src_bits >> 4; - const BYTE *const entry = (BYTE *)&src_pal[pixel]; - r += (weight * (double)entry[FI_RGBA_RED]); - g += (weight * (double)entry[FI_RGBA_GREEN]); - b += (weight * (double)entry[FI_RGBA_BLUE]); - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } - break; - - case 32: - { - // transparently convert the transparent 4-bit image - // to 32 bpp; we always have got a palette for 4-bit images - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - BYTE *dst_bits = dst_base + x * 4; - const unsigned index = x >> 1; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const BYTE *src_bits = src_base + iLeft * src_pitch + index; - double r = 0, g = 0, b = 0, a = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(y, i); - const unsigned pixel = x & 0x01 ? *src_bits & 0x0F : *src_bits >> 4; - const BYTE *const entry = (BYTE *)&src_pal[pixel]; - r += (weight * (double)entry[FI_RGBA_RED]); - g += (weight * (double)entry[FI_RGBA_GREEN]); - b += (weight * (double)entry[FI_RGBA_BLUE]); - a += (weight * (double)entry[FI_RGBA_ALPHA]); - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int)(a + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } - break; - } - } - break; - - case 8: - { - const unsigned src_pitch = FreeImage_GetPitch(src); - const BYTE *const src_base = FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x; - - switch(FreeImage_GetBPP(dst)) { - case 8: - { - // scale the 8-bit non-transparent greyscale image - // into an 8 bpp destination image - if (src_pal) { - // we have got a palette - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - BYTE *dst_bits = dst_base + x; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const BYTE *src_bits = src_base + iLeft * src_pitch + x; - double value = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - value += (weightsTable.getWeight(y, i) - * (double)*(BYTE *)&src_pal[*src_bits]); - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - *dst_bits = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } else { - // we do not have a palette - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - BYTE *dst_bits = dst_base + x; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const BYTE *src_bits = src_base + iLeft * src_pitch + x; - double value = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - value += (weightsTable.getWeight(y, i) - * (double)*src_bits); - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - *dst_bits = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } - } - break; - - case 24: - { - // transparently convert the non-transparent 8-bit image - // to 24 bpp; we always have got a palette here - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - BYTE *dst_bits = dst_base + x * 3; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const BYTE *src_bits = src_base + iLeft * src_pitch + x; - double r = 0, g = 0, b = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(y, i); - const BYTE * const entry = (BYTE *)&src_pal[*src_bits]; - r += (weight * (double)entry[FI_RGBA_RED]); - g += (weight * (double)entry[FI_RGBA_GREEN]); - b += (weight * (double)entry[FI_RGBA_BLUE]); - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } - break; - - case 32: - { - // transparently convert the transparent 8-bit image - // to 32 bpp; we always have got a palette here - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - BYTE *dst_bits = dst_base + x * 4; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const BYTE *src_bits = src_base + iLeft * src_pitch + x; - double r = 0, g = 0, b = 0, a = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(y, i); - const BYTE * const entry = (BYTE *)&src_pal[*src_bits]; - r += (weight * (double)entry[FI_RGBA_RED]); - g += (weight * (double)entry[FI_RGBA_GREEN]); - b += (weight * (double)entry[FI_RGBA_BLUE]); - a += (weight * (double)entry[FI_RGBA_ALPHA]); - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int)(a + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } - break; - } - } - break; - - case 16: - { - // transparently convert the 16-bit non-transparent image - // to 24 bpp - const unsigned src_pitch = FreeImage_GetPitch(src) / sizeof(WORD); - const WORD *const src_base = (WORD *)FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x; - - if (IS_FORMAT_RGB565(src)) { - // image has 565 format - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - BYTE *dst_bits = dst_base + x * 3; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const WORD *src_bits = src_base + iLeft * src_pitch + x; - double r = 0, g = 0, b = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(y, i); - r += (weight * (double)((*src_bits & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT)); - g += (weight * (double)((*src_bits & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT)); - b += (weight * (double)((*src_bits & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT)); - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(((g * 0xFF) / 0x3F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } else { - // image has 555 format - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - BYTE *dst_bits = dst_base + x * 3; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const WORD *src_bits = src_base + iLeft * src_pitch + x; - double r = 0, g = 0, b = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(y, i); - r += (weight * (double)((*src_bits & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT)); - g += (weight * (double)((*src_bits & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT)); - b += (weight * (double)((*src_bits & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT)); - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(((g * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } - } - break; - - case 24: - { - // scale the 24-bit transparent image - // into a 24 bpp destination image - const unsigned src_pitch = FreeImage_GetPitch(src); - const BYTE *const src_base = FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x * 3; - - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - const unsigned index = x * 3; - BYTE *dst_bits = dst_base + index; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const BYTE *src_bits = src_base + iLeft * src_pitch + index; - double r = 0, g = 0, b = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(y, i); - r += (weight * (double)src_bits[FI_RGBA_RED]); - g += (weight * (double)src_bits[FI_RGBA_GREEN]); - b += (weight * (double)src_bits[FI_RGBA_BLUE]); - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int) (r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int) (g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int) (b + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } - break; - - case 32: - { - // scale the 32-bit transparent image - // into a 32 bpp destination image - const unsigned src_pitch = FreeImage_GetPitch(src); - const BYTE *const src_base = FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x * 4; - - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - const unsigned index = x * 4; - BYTE *dst_bits = dst_base + index; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const BYTE *src_bits = src_base + iLeft * src_pitch + index; - double r = 0, g = 0, b = 0, a = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(y, i); - r += (weight * (double)src_bits[FI_RGBA_RED]); - g += (weight * (double)src_bits[FI_RGBA_GREEN]); - b += (weight * (double)src_bits[FI_RGBA_BLUE]); - a += (weight * (double)src_bits[FI_RGBA_ALPHA]); - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int) (r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int) (g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int) (b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int) (a + 0.5), 0, 0xFF); - dst_bits += dst_pitch; - } - } - } - break; - } - } - break; - - case FIT_UINT16: - { - // Calculate the number of words per pixel (1 for 16-bit, 3 for 48-bit or 4 for 64-bit) - const unsigned wordspp = (FreeImage_GetLine(src) / width) / sizeof(WORD); - - const unsigned dst_pitch = FreeImage_GetPitch(dst) / sizeof(WORD); - WORD *const dst_base = (WORD *)FreeImage_GetBits(dst); - - const unsigned src_pitch = FreeImage_GetPitch(src) / sizeof(WORD); - const WORD *const src_base = (WORD *)FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x * wordspp; - - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - const unsigned index = x * wordspp; // pixel index - WORD *dst_bits = dst_base + index; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const WORD *src_bits = src_base + iLeft * src_pitch + index; - double value = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(y, i); - value += (weight * (double)src_bits[0]); - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - dst_bits[0] = (WORD)CLAMP((int)(value + 0.5), 0, 0xFFFF); - - dst_bits += dst_pitch; - } - } - } - break; - - case FIT_RGB16: - { - // Calculate the number of words per pixel (1 for 16-bit, 3 for 48-bit or 4 for 64-bit) - const unsigned wordspp = (FreeImage_GetLine(src) / width) / sizeof(WORD); - - const unsigned dst_pitch = FreeImage_GetPitch(dst) / sizeof(WORD); - WORD *const dst_base = (WORD *)FreeImage_GetBits(dst); - - const unsigned src_pitch = FreeImage_GetPitch(src) / sizeof(WORD); - const WORD *const src_base = (WORD *)FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x * wordspp; - - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - const unsigned index = x * wordspp; // pixel index - WORD *dst_bits = dst_base + index; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const WORD *src_bits = src_base + iLeft * src_pitch + index; - double r = 0, g = 0, b = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(y, i); - r += (weight * (double)src_bits[0]); - g += (weight * (double)src_bits[1]); - b += (weight * (double)src_bits[2]); - - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - dst_bits[0] = (WORD)CLAMP((int)(r + 0.5), 0, 0xFFFF); - dst_bits[1] = (WORD)CLAMP((int)(g + 0.5), 0, 0xFFFF); - dst_bits[2] = (WORD)CLAMP((int)(b + 0.5), 0, 0xFFFF); - - dst_bits += dst_pitch; - } - } - } - break; - - case FIT_RGBA16: - { - // Calculate the number of words per pixel (1 for 16-bit, 3 for 48-bit or 4 for 64-bit) - const unsigned wordspp = (FreeImage_GetLine(src) / width) / sizeof(WORD); - - const unsigned dst_pitch = FreeImage_GetPitch(dst) / sizeof(WORD); - WORD *const dst_base = (WORD *)FreeImage_GetBits(dst); - - const unsigned src_pitch = FreeImage_GetPitch(src) / sizeof(WORD); - const WORD *const src_base = (WORD *)FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x * wordspp; - - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - const unsigned index = x * wordspp; // pixel index - WORD *dst_bits = dst_base + index; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary - const WORD *src_bits = src_base + iLeft * src_pitch + index; - double r = 0, g = 0, b = 0, a = 0; - - for (unsigned i = 0; i <= iLimit; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(y, i); - r += (weight * (double)src_bits[0]); - g += (weight * (double)src_bits[1]); - b += (weight * (double)src_bits[2]); - a += (weight * (double)src_bits[3]); - - src_bits += src_pitch; - } - - // clamp and place result in destination pixel - dst_bits[0] = (WORD)CLAMP((int)(r + 0.5), 0, 0xFFFF); - dst_bits[1] = (WORD)CLAMP((int)(g + 0.5), 0, 0xFFFF); - dst_bits[2] = (WORD)CLAMP((int)(b + 0.5), 0, 0xFFFF); - dst_bits[3] = (WORD)CLAMP((int)(a + 0.5), 0, 0xFFFF); - - dst_bits += dst_pitch; - } - } - } - break; - - case FIT_FLOAT: - case FIT_RGBF: - case FIT_RGBAF: - { - // Calculate the number of floats per pixel (1 for 32-bit, 3 for 96-bit or 4 for 128-bit) - const unsigned floatspp = (FreeImage_GetLine(src) / width) / sizeof(float); - - const unsigned dst_pitch = FreeImage_GetPitch(dst) / sizeof(float); - float *const dst_base = (float *)FreeImage_GetBits(dst); - - const unsigned src_pitch = FreeImage_GetPitch(src) / sizeof(float); - const float *const src_base = (float *)FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x * floatspp; - - for (unsigned x = 0; x < width; x++) { - // work on column x in dst - const unsigned index = x * floatspp; // pixel index - float *dst_bits = (float *)dst_base + index; - - // scale each column - for (unsigned y = 0; y < dst_height; y++) { - // loop through column - const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary - const unsigned iRight = weightsTable.getRightBoundary(y); // retrieve right boundary - const float *src_bits = src_base + iLeft * src_pitch + index; - double value[4] = {0, 0, 0, 0}; // 4 = 128 bpp max - - for (unsigned i = iLeft; i <= iRight; i++) { - // scan between boundaries - // accumulate weighted effect of each neighboring pixel - const double weight = weightsTable.getWeight(y, i - iLeft); - for (unsigned j = 0; j < floatspp; j++) { - value[j] += (weight * (double)src_bits[j]); - } - src_bits += src_pitch; - } - - // place result in destination pixel - for (unsigned j = 0; j < floatspp; j++) { - dst_bits[j] = (float)value[j]; - } - dst_bits += dst_pitch; - } - } - } - break; - } -} +// ========================================================== +// Upsampling / downsampling classes +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// - Detlev Vendt (detlev.vendt@brillit.de) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "Resize.h" + +/** +Returns the color type of a bitmap. In contrast to FreeImage_GetColorType, +this function optionally supports a boolean OUT parameter, that receives TRUE, +if the specified bitmap is greyscale, that is, it consists of grey colors only. +Although it returns the same value as returned by FreeImage_GetColorType for all +image types, this extended function primarily is intended for palletized images, +since the boolean pointed to by 'bIsGreyscale' remains unchanged for RGB(A/F) +images. However, the outgoing boolean is properly maintained for palletized images, +as well as for any non-RGB image type, like FIT_UINTxx and FIT_DOUBLE, for example. +@param dib A pointer to a FreeImage bitmap to calculate the extended color type for +@param bIsGreyscale A pointer to a boolean, that receives TRUE, if the specified bitmap +is greyscale, that is, it consists of grey colors only. This parameter can be NULL. +@return the color type of the specified bitmap +*/ +static FREE_IMAGE_COLOR_TYPE +GetExtendedColorType(FIBITMAP *dib, BOOL *bIsGreyscale) { + const unsigned bpp = FreeImage_GetBPP(dib); + const unsigned size = CalculateUsedPaletteEntries(bpp); + const RGBQUAD * const pal = FreeImage_GetPalette(dib); + FREE_IMAGE_COLOR_TYPE color_type = FIC_MINISBLACK; + BOOL bIsGrey = TRUE; + + switch (bpp) { + case 1: + { + for (unsigned i = 0; i < size; i++) { + if ((pal[i].rgbRed != pal[i].rgbGreen) || (pal[i].rgbRed != pal[i].rgbBlue)) { + color_type = FIC_PALETTE; + bIsGrey = FALSE; + break; + } + } + if (bIsGrey) { + if (pal[0].rgbBlue == 255 && pal[1].rgbBlue == 0) { + color_type = FIC_MINISWHITE; + } else if (pal[0].rgbBlue != 0 || pal[1].rgbBlue != 255) { + color_type = FIC_PALETTE; + } + } + break; + } + + case 4: + case 8: + { + for (unsigned i = 0; i < size; i++) { + if ((pal[i].rgbRed != pal[i].rgbGreen) || (pal[i].rgbRed != pal[i].rgbBlue)) { + color_type = FIC_PALETTE; + bIsGrey = FALSE; + break; + } + if (color_type != FIC_PALETTE && pal[i].rgbBlue != i) { + if ((size - i - 1) != pal[i].rgbBlue) { + color_type = FIC_PALETTE; + if (!bIsGreyscale) { + // exit loop if we're not setting + // bIsGreyscale parameter + break; + } + } else { + color_type = FIC_MINISWHITE; + } + } + } + break; + } + + default: + { + color_type = FreeImage_GetColorType(dib); + bIsGrey = (color_type == FIC_MINISBLACK) ? TRUE : FALSE; + break; + } + + } + if (bIsGreyscale) { + *bIsGreyscale = bIsGrey; + } + + return color_type; +} + +/** +Returns a pointer to an RGBA palette, created from the specified bitmap. +The RGBA palette is a copy of the specified bitmap's palette, that, additionally +contains the bitmap's transparency information in the rgbReserved member +of the palette's RGBQUAD elements. +@param dib A pointer to a FreeImage bitmap to create the RGBA palette from. +@param buffer A pointer to the buffer to store the RGBA palette. +@return A pointer to the newly created RGBA palette or NULL, if the specified +bitmap is no palletized standard bitmap. If non-NULL, the returned value is +actually the pointer passed in parameter 'buffer'. +*/ +static inline RGBQUAD * +GetRGBAPalette(FIBITMAP *dib, RGBQUAD * const buffer) { + // clone the palette + const unsigned ncolors = FreeImage_GetColorsUsed(dib); + if (ncolors == 0) { + return NULL; + } + memcpy(buffer, FreeImage_GetPalette(dib), ncolors * sizeof(RGBQUAD)); + // merge the transparency table + const unsigned ntransp = MIN(ncolors, FreeImage_GetTransparencyCount(dib)); + const BYTE * const tt = FreeImage_GetTransparencyTable(dib); + for (unsigned i = 0; i < ntransp; i++) { + buffer[i].rgbReserved = tt[i]; + } + for (unsigned i = ntransp; i < ncolors; i++) { + buffer[i].rgbReserved = 255; + } + return buffer; +} + +// -------------------------------------------------------------------------- + +CWeightsTable::CWeightsTable(CGenericFilter *pFilter, unsigned uDstSize, unsigned uSrcSize) { + unsigned u; + double dWidth; + double dFScale = 1.0; + const double dFilterWidth = pFilter->GetWidth(); + + // scale factor + const double dScale = double(uDstSize) / double(uSrcSize); + + if(dScale < 1.0) { + // minification + dWidth = dFilterWidth / dScale; + dFScale = dScale; + } else { + // magnification + dWidth= dFilterWidth; + } + + // allocate a new line contributions structure + // + // window size is the number of sampled pixels + m_WindowSize = 2 * (int)ceil(dWidth) + 1; + m_LineLength = uDstSize; + // allocate list of contributions + m_WeightTable = (Contribution*)malloc(m_LineLength * sizeof(Contribution)); + for(u = 0 ; u < m_LineLength ; u++) { + // allocate contributions for every pixel + m_WeightTable[u].Weights = (double*)malloc(m_WindowSize * sizeof(double)); + } + + // offset for discrete to continuous coordinate conversion + const double dOffset = (0.5 / dScale) - 0.5; + + for(u = 0; u < m_LineLength; u++) { + // scan through line of contributions + const double dCenter = (double)u / dScale + dOffset; // reverse mapping + // find the significant edge points that affect the pixel + int iLeft = MAX (0, (int)floor (dCenter - dWidth)); + int iRight = MIN ((int)ceil (dCenter + dWidth), int(uSrcSize) - 1); + + // cut edge points to fit in filter window in case of spill-off + if((iRight - iLeft + 1) > int(m_WindowSize)) { + if(iLeft < (int(uSrcSize) - 1 / 2)) { + iLeft++; + } else { + iRight--; + } + } + + m_WeightTable[u].Left = iLeft; + m_WeightTable[u].Right = iRight; + + int iSrc = 0; + double dTotalWeight = 0; // zero sum of weights + for(iSrc = iLeft; iSrc <= iRight; iSrc++) { + // calculate weights + const double weight = dFScale * pFilter->Filter(dFScale * (dCenter - (double)iSrc)); + m_WeightTable[u].Weights[iSrc-iLeft] = weight; + dTotalWeight += weight; + } + if((dTotalWeight > 0) && (dTotalWeight != 1)) { + // normalize weight of neighbouring points + for(iSrc = iLeft; iSrc <= iRight; iSrc++) { + // normalize point + m_WeightTable[u].Weights[iSrc-iLeft] /= dTotalWeight; + } + // simplify the filter, discarding null weights at the right + iSrc = iRight - iLeft; + while(m_WeightTable[u].Weights[iSrc] == 0) { + m_WeightTable[u].Right--; + iSrc--; + if(m_WeightTable[u].Right == m_WeightTable[u].Left) { + break; + } + } + + } + } +} + +CWeightsTable::~CWeightsTable() { + for(unsigned u = 0; u < m_LineLength; u++) { + // free contributions for every pixel + free(m_WeightTable[u].Weights); + } + // free list of pixels contributions + free(m_WeightTable); +} + +// -------------------------------------------------------------------------- + +FIBITMAP* CResizeEngine::scale(FIBITMAP *src, unsigned dst_width, unsigned dst_height, unsigned src_left, unsigned src_top, unsigned src_width, unsigned src_height) { + + const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(src); + const unsigned src_bpp = FreeImage_GetBPP(src); + + // determine the image's color type + BOOL bIsGreyscale = FALSE; + FREE_IMAGE_COLOR_TYPE color_type; + if (src_bpp <= 8) { + color_type = GetExtendedColorType(src, &bIsGreyscale); + } else { + color_type = FIC_RGB; + } + + // determine the required bit depth of the destination image + unsigned dst_bpp; + if (color_type == FIC_PALETTE && !bIsGreyscale) { + // non greyscale FIC_PALETTE images require a high-color destination + // image (24- or 32-bits depending on the image's transparent state) + dst_bpp = FreeImage_IsTransparent(src) ? 32 : 24; + } else if (src_bpp <= 8) { + // greyscale images require an 8-bit destination image + // (or a 32-bit image if the image is transparent) + dst_bpp = FreeImage_IsTransparent(src) ? 32 : 8; + } else if (src_bpp == 16 && image_type == FIT_BITMAP) { + // 16-bit 555 and 565 RGB images require a high-color destination image + // (fixed to 24 bits, since 16-bit RGBs don't support transparency in FreeImage) + dst_bpp = 24; + } else { + // bit depth remains unchanged for all other images + dst_bpp = src_bpp; + } + + // early exit if destination size is equal to source size + if ((src_width == dst_width) && (src_height == dst_height)) { + FIBITMAP *out = src; + FIBITMAP *tmp = src; + if ((src_width != FreeImage_GetWidth(src)) || (src_height != FreeImage_GetHeight(src))) { + out = FreeImage_Copy(tmp, src_left, src_top, src_left + src_width, src_top + src_height); + tmp = out; + } + if (src_bpp != dst_bpp) { + switch (dst_bpp) { + case 8: + out = FreeImage_ConvertToGreyscale(tmp); + if (tmp != src) { + FreeImage_Unload(tmp); + } + break; + + case 24: + out = FreeImage_ConvertTo24Bits(tmp); + if (tmp != src) { + FreeImage_Unload(tmp); + } + break; + + case 32: + out = FreeImage_ConvertTo32Bits(tmp); + if (tmp != src) { + FreeImage_Unload(tmp); + } + break; + } + } + + return (out != src) ? out : FreeImage_Clone(src); + } + + RGBQUAD pal_buffer[256]; + RGBQUAD *src_pal = NULL; + + // provide the source image's palette to the rescaler for + // FIC_PALETTE type images (this includes palletized greyscale + // images with an unordered palette) + if (color_type == FIC_PALETTE) { + if (dst_bpp == 32) { + // a 32 bit destination image signals transparency, so + // create an RGBA palette from the source palette + src_pal = GetRGBAPalette(src, pal_buffer); + } else { + src_pal = FreeImage_GetPalette(src); + } + } + + // allocate the dst image + FIBITMAP *dst = FreeImage_AllocateT(image_type, dst_width, dst_height, dst_bpp, 0, 0, 0); + if (!dst) { + return NULL; + } + + if (dst_bpp == 8) { + RGBQUAD * const dst_pal = FreeImage_GetPalette(dst); + if (color_type == FIC_MINISWHITE) { + // build an inverted greyscale palette + CREATE_GREYSCALE_PALETTE_REVERSE(dst_pal, 256); + } + /* + else { + // build a default greyscale palette + // Currently, FreeImage_AllocateT already creates a default + // greyscale palette for 8 bpp images, so we can skip this here. + CREATE_GREYSCALE_PALETTE(dst_pal, 256); + } + */ + } + + // calculate x and y offsets; since FreeImage uses bottom-up bitmaps, the + // value of src_offset_y is measured from the bottom of the image + unsigned src_offset_x = src_left; + unsigned src_offset_y; + if (src_top > 0) { + src_offset_y = FreeImage_GetHeight(src) - src_height - src_top; + } else { + src_offset_y = 0; + } + + /* + Decide which filtering order (xy or yx) is faster for this mapping. + --- The theory --- + Try to minimize calculations by counting the number of convolution multiplies + if(dst_width*src_height <= src_width*dst_height) { + // xy filtering + } else { + // yx filtering + } + --- The practice --- + Try to minimize calculations by counting the number of vertical convolutions (the most time consuming task) + if(dst_width*dst_height <= src_width*dst_height) { + // xy filtering + } else { + // yx filtering + } + */ + + if (dst_width <= src_width) { + // xy filtering + // ------------- + + FIBITMAP *tmp = NULL; + + if (src_width != dst_width) { + // source and destination widths are different so, we must + // filter horizontally + if (src_height != dst_height) { + // source and destination heights are also different so, we need + // a temporary image + tmp = FreeImage_AllocateT(image_type, dst_width, src_height, dst_bpp, 0, 0, 0); + if (!tmp) { + FreeImage_Unload(dst); + return NULL; + } + } else { + // source and destination heights are equal so, we can directly + // scale into destination image (second filter method will not + // be invoked) + tmp = dst; + } + + // scale source image horizontally into temporary (or destination) image + horizontalFilter(src, src_height, src_width, src_offset_x, src_offset_y, src_pal, tmp, dst_width); + + // set x and y offsets to zero for the second filter method + // invocation (the temporary image only contains the portion of + // the image to be rescaled with no offsets) + src_offset_x = 0; + src_offset_y = 0; + + // also ensure, that the second filter method gets no source + // palette (the temporary image is palletized only, if it is + // greyscale; in that case, it is an 8-bit image with a linear + // palette so, the source palette is not needed or will even be + // mismatching, if the source palette is unordered) + src_pal = NULL; + } else { + // source and destination widths are equal so, just copy the + // image pointer + tmp = src; + } + + if (src_height != dst_height) { + // source and destination heights are different so, scale + // temporary (or source) image vertically into destination image + verticalFilter(tmp, dst_width, src_height, src_offset_x, src_offset_y, src_pal, dst, dst_height); + } + + // free temporary image, if not pointing to either src or dst + if (tmp != src && tmp != dst) { + FreeImage_Unload(tmp); + } + + } else { + // yx filtering + // ------------- + + // Remark: + // The yx filtering branch could be more optimized by taking into, + // account that (src_width != dst_width) is always true, which + // follows from the above condition, which selects filtering order. + // Since (dst_width <= src_width) == TRUE selects xy filtering, + // both widths must be different when performing yx filtering. + // However, to make the code more robust, not depending on that + // condition and more symmetric to the xy filtering case, these + // (src_width != dst_width) conditions are still in place. + + FIBITMAP *tmp = NULL; + + if (src_height != dst_height) { + // source and destination heights are different so, we must + // filter vertically + if (src_width != dst_width) { + // source and destination widths are also different so, we need + // a temporary image + tmp = FreeImage_AllocateT(image_type, src_width, dst_height, dst_bpp, 0, 0, 0); + if (!tmp) { + FreeImage_Unload(dst); + return NULL; + } + } else { + // source and destination widths are equal so, we can directly + // scale into destination image (second filter method will not + // be invoked) + tmp = dst; + } + + // scale source image vertically into temporary (or destination) image + verticalFilter(src, src_width, src_height, src_offset_x, src_offset_y, src_pal, tmp, dst_height); + + // set x and y offsets to zero for the second filter method + // invocation (the temporary image only contains the portion of + // the image to be rescaled with no offsets) + src_offset_x = 0; + src_offset_y = 0; + + // also ensure, that the second filter method gets no source + // palette (the temporary image is palletized only, if it is + // greyscale; in that case, it is an 8-bit image with a linear + // palette so, the source palette is not needed or will even be + // mismatching, if the source palette is unordered) + src_pal = NULL; + + } else { + // source and destination heights are equal so, just copy the + // image pointer + tmp = src; + } + + if (src_width != dst_width) { + // source and destination heights are different so, scale + // temporary (or source) image horizontally into destination image + horizontalFilter(tmp, dst_height, src_width, src_offset_x, src_offset_y, src_pal, dst, dst_width); + } + + // free temporary image, if not pointing to either src or dst + if (tmp != src && tmp != dst) { + FreeImage_Unload(tmp); + } + } + + return dst; +} + +void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsigned src_width, unsigned src_offset_x, unsigned src_offset_y, const RGBQUAD *const src_pal, FIBITMAP *const dst, unsigned dst_width) { + + // allocate and calculate the contributions + CWeightsTable weightsTable(m_pFilter, dst_width, src_width); + + // step through rows + switch(FreeImage_GetImageType(src)) { + case FIT_BITMAP: + { + switch(FreeImage_GetBPP(src)) { + case 1: + { + switch(FreeImage_GetBPP(dst)) { + case 8: + { + // transparently convert the 1-bit non-transparent greyscale + // image to 8 bpp + src_offset_x >>= 3; + if (src_pal) { + // we have got a palette + for (unsigned y = 0; y < height; y++) { + // scale each row + const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; + BYTE * const dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary + double value = 0; + + for (unsigned i = iLeft; i <= iRight; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const unsigned pixel = (src_bits[i >> 3] & (0x80 >> (i & 0x07))) != 0; + value += (weightsTable.getWeight(x, i - iLeft) * (double)*(BYTE *)&src_pal[pixel]); + } + + // clamp and place result in destination pixel + dst_bits[x] = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); + } + } + } else { + // we do not have a palette + for (unsigned y = 0; y < height; y++) { + // scale each row + const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; + BYTE * const dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary + double value = 0; + + for (unsigned i = iLeft; i <= iRight; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const unsigned pixel = (src_bits[i >> 3] & (0x80 >> (i & 0x07))) != 0; + value += (weightsTable.getWeight(x, i - iLeft) * (double)pixel); + } + value *= 0xFF; + + // clamp and place result in destination pixel + dst_bits[x] = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); + } + } + } + } + break; + + case 24: + { + // transparently convert the non-transparent 1-bit image + // to 24 bpp; we always have got a palette here + src_offset_x >>= 3; + + for (unsigned y = 0; y < height; y++) { + // scale each row + const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; + BYTE *dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary + double r = 0, g = 0, b = 0; + + for (unsigned i = iLeft; i <= iRight; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(x, i - iLeft); + const unsigned pixel = (src_bits[i >> 3] & (0x80 >> (i & 0x07))) != 0; + const BYTE * const entry = (BYTE *)&src_pal[pixel]; + r += (weight * (double)entry[FI_RGBA_RED]); + g += (weight * (double)entry[FI_RGBA_GREEN]); + b += (weight * (double)entry[FI_RGBA_BLUE]); + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits += 3; + } + } + } + break; + + case 32: + { + // transparently convert the transparent 1-bit image + // to 32 bpp; we always have got a palette here + src_offset_x >>= 3; + + for (unsigned y = 0; y < height; y++) { + // scale each row + const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; + BYTE *dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary + double r = 0, g = 0, b = 0, a = 0; + + for (unsigned i = iLeft; i <= iRight; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(x, i - iLeft); + const unsigned pixel = (src_bits[i >> 3] & (0x80 >> (i & 0x07))) != 0; + const BYTE * const entry = (BYTE *)&src_pal[pixel]; + r += (weight * (double)entry[FI_RGBA_RED]); + g += (weight * (double)entry[FI_RGBA_GREEN]); + b += (weight * (double)entry[FI_RGBA_BLUE]); + a += (weight * (double)entry[FI_RGBA_ALPHA]); + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int)(a + 0.5), 0, 0xFF); + dst_bits += 4; + } + } + } + break; + } + } + break; + + case 4: + { + switch(FreeImage_GetBPP(dst)) { + case 8: + { + // transparently convert the non-transparent 4-bit greyscale image + // to 8 bpp; we always have got a palette for 4-bit images + src_offset_x >>= 1; + + for (unsigned y = 0; y < height; y++) { + // scale each row + const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; + BYTE * const dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary + double value = 0; + + for (unsigned i = iLeft; i <= iRight; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const unsigned pixel = i & 0x01 ? src_bits[i >> 1] & 0x0F : src_bits[i >> 1] >> 4; + value += (weightsTable.getWeight(x, i - iLeft) + * (double)*(BYTE *)&src_pal[pixel]); + } + + // clamp and place result in destination pixel + dst_bits[x] = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); + } + } + } + break; + + case 24: + { + // transparently convert the non-transparent 4-bit image + // to 24 bpp; we always have got a palette for 4-bit images + src_offset_x >>= 1; + + for (unsigned y = 0; y < height; y++) { + // scale each row + const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; + BYTE *dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary + double r = 0, g = 0, b = 0; + + for (unsigned i = iLeft; i <= iRight; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(x, i - iLeft); + const unsigned pixel = i & 0x01 ? src_bits[i >> 1] & 0x0F : src_bits[i >> 1] >> 4; + const BYTE * const entry = (BYTE *)&src_pal[pixel]; + r += (weight * (double)entry[FI_RGBA_RED]); + g += (weight * (double)entry[FI_RGBA_GREEN]); + b += (weight * (double)entry[FI_RGBA_BLUE]); + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits += 3; + } + } + } + break; + + case 32: + { + // transparently convert the transparent 4-bit image + // to 32 bpp; we always have got a palette for 4-bit images + src_offset_x >>= 1; + + for (unsigned y = 0; y < height; y++) { + // scale each row + const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; + BYTE *dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary + double r = 0, g = 0, b = 0, a = 0; + + for (unsigned i = iLeft; i <= iRight; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(x, i - iLeft); + const unsigned pixel = i & 0x01 ? src_bits[i >> 1] & 0x0F : src_bits[i >> 1] >> 4; + const BYTE * const entry = (BYTE *)&src_pal[pixel]; + r += (weight * (double)entry[FI_RGBA_RED]); + g += (weight * (double)entry[FI_RGBA_GREEN]); + b += (weight * (double)entry[FI_RGBA_BLUE]); + a += (weight * (double)entry[FI_RGBA_ALPHA]); + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int)(a + 0.5), 0, 0xFF); + dst_bits += 4; + } + } + } + break; + } + } + break; + + case 8: + { + switch(FreeImage_GetBPP(dst)) { + case 8: + { + // scale the 8-bit non-transparent greyscale image + // into an 8 bpp destination image + if (src_pal) { + // we have got a palette + for (unsigned y = 0; y < height; y++) { + // scale each row + const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; + BYTE * const dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary + const BYTE * const pixel = src_bits + iLeft; + double value = 0; + + // for(i = iLeft to iRight) + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + value += (weightsTable.getWeight(x, i) + * (double)*(BYTE *)&src_pal[pixel[i]]); + } + + // clamp and place result in destination pixel + dst_bits[x] = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); + } + } + } else { + // we do not have a palette + for (unsigned y = 0; y < height; y++) { + // scale each row + const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; + BYTE * const dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary + const BYTE * const pixel = src_bits + iLeft; + double value = 0; + + // for(i = iLeft to iRight) + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + value += (weightsTable.getWeight(x, i) * (double)pixel[i]); + } + + // clamp and place result in destination pixel + dst_bits[x] = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); + } + } + } + } + break; + + case 24: + { + // transparently convert the non-transparent 8-bit image + // to 24 bpp; we always have got a palette here + for (unsigned y = 0; y < height; y++) { + // scale each row + const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; + BYTE *dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary + const BYTE * const pixel = src_bits + iLeft; + double r = 0, g = 0, b = 0; + + // for(i = iLeft to iRight) + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(x, i); + const BYTE *const entry = (BYTE *)&src_pal[pixel[i]]; + r += (weight * (double)entry[FI_RGBA_RED]); + g += (weight * (double)entry[FI_RGBA_GREEN]); + b += (weight * (double)entry[FI_RGBA_BLUE]); + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits += 3; + } + } + } + break; + + case 32: + { + // transparently convert the transparent 8-bit image + // to 32 bpp; we always have got a palette here + for (unsigned y = 0; y < height; y++) { + // scale each row + const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; + BYTE *dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary + const BYTE * const pixel = src_bits + iLeft; + double r = 0, g = 0, b = 0, a = 0; + + // for(i = iLeft to iRight) + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(x, i); + const BYTE * const entry = (BYTE *)&src_pal[pixel[i]]; + r += (weight * (double)entry[FI_RGBA_RED]); + g += (weight * (double)entry[FI_RGBA_GREEN]); + b += (weight * (double)entry[FI_RGBA_BLUE]); + a += (weight * (double)entry[FI_RGBA_ALPHA]); + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int)(a + 0.5), 0, 0xFF); + dst_bits += 4; + } + } + } + break; + } + } + break; + + case 16: + { + // transparently convert the 16-bit non-transparent image + // to 24 bpp + if (IS_FORMAT_RGB565(src)) { + // image has 565 format + for (unsigned y = 0; y < height; y++) { + // scale each row + const WORD * const src_bits = (WORD *)FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x / sizeof(WORD); + BYTE *dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary + const WORD *pixel = src_bits + iLeft; + double r = 0, g = 0, b = 0; + + // for(i = iLeft to iRight) + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(x, i); + r += (weight * (double)((*pixel & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT)); + g += (weight * (double)((*pixel & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT)); + b += (weight * (double)((*pixel & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT)); + pixel++; + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(((g * 0xFF) / 0x3F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits += 3; + } + } + } else { + // image has 555 format + for (unsigned y = 0; y < height; y++) { + // scale each row + const WORD * const src_bits = (WORD *)FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x; + BYTE *dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary + const WORD *pixel = src_bits + iLeft; + double r = 0, g = 0, b = 0; + + // for(i = iLeft to iRight) + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(x, i); + r += (weight * (double)((*pixel & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT)); + g += (weight * (double)((*pixel & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT)); + b += (weight * (double)((*pixel & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT)); + pixel++; + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(((g * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits += 3; + } + } + } + } + break; + + case 24: + { + // scale the 24-bit non-transparent image + // into a 24 bpp destination image + for (unsigned y = 0; y < height; y++) { + // scale each row + const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x * 3; + BYTE *dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary + const BYTE * pixel = src_bits + iLeft * 3; + double r = 0, g = 0, b = 0; + + // for(i = iLeft to iRight) + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(x, i); + r += (weight * (double)pixel[FI_RGBA_RED]); + g += (weight * (double)pixel[FI_RGBA_GREEN]); + b += (weight * (double)pixel[FI_RGBA_BLUE]); + pixel += 3; + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits += 3; + } + } + } + break; + + case 32: + { + // scale the 32-bit transparent image + // into a 32 bpp destination image + for (unsigned y = 0; y < height; y++) { + // scale each row + const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x * 4; + BYTE *dst_bits = FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary + const BYTE *pixel = src_bits + iLeft * 4; + double r = 0, g = 0, b = 0, a = 0; + + // for(i = iLeft to iRight) + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(x, i); + r += (weight * (double)pixel[FI_RGBA_RED]); + g += (weight * (double)pixel[FI_RGBA_GREEN]); + b += (weight * (double)pixel[FI_RGBA_BLUE]); + a += (weight * (double)pixel[FI_RGBA_ALPHA]); + pixel += 4; + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int)(a + 0.5), 0, 0xFF); + dst_bits += 4; + } + } + } + break; + } + } + break; + + case FIT_UINT16: + { + // Calculate the number of words per pixel (1 for 16-bit, 3 for 48-bit or 4 for 64-bit) + const unsigned wordspp = (FreeImage_GetLine(src) / src_width) / sizeof(WORD); + + for (unsigned y = 0; y < height; y++) { + // scale each row + const WORD *src_bits = (WORD*)FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x / sizeof(WORD); + WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary + const WORD *pixel = src_bits + iLeft * wordspp; + double value = 0; + + // for(i = iLeft to iRight) + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(x, i); + value += (weight * (double)pixel[0]); + pixel++; + } + + // clamp and place result in destination pixel + dst_bits[0] = (WORD)CLAMP((int)(value + 0.5), 0, 0xFFFF); + dst_bits += wordspp; + } + } + } + break; + + case FIT_RGB16: + { + // Calculate the number of words per pixel (1 for 16-bit, 3 for 48-bit or 4 for 64-bit) + const unsigned wordspp = (FreeImage_GetLine(src) / src_width) / sizeof(WORD); + + for (unsigned y = 0; y < height; y++) { + // scale each row + const WORD *src_bits = (WORD*)FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x / sizeof(WORD); + WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary + const WORD *pixel = src_bits + iLeft * wordspp; + double r = 0, g = 0, b = 0; + + // for(i = iLeft to iRight) + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(x, i); + r += (weight * (double)pixel[0]); + g += (weight * (double)pixel[1]); + b += (weight * (double)pixel[2]); + pixel += wordspp; + } + + // clamp and place result in destination pixel + dst_bits[0] = (WORD)CLAMP((int)(r + 0.5), 0, 0xFFFF); + dst_bits[1] = (WORD)CLAMP((int)(g + 0.5), 0, 0xFFFF); + dst_bits[2] = (WORD)CLAMP((int)(b + 0.5), 0, 0xFFFF); + dst_bits += wordspp; + } + } + } + break; + + case FIT_RGBA16: + { + // Calculate the number of words per pixel (1 for 16-bit, 3 for 48-bit or 4 for 64-bit) + const unsigned wordspp = (FreeImage_GetLine(src) / src_width) / sizeof(WORD); + + for (unsigned y = 0; y < height; y++) { + // scale each row + const WORD *src_bits = (WORD*)FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x / sizeof(WORD); + WORD *dst_bits = (WORD*)FreeImage_GetScanLine(dst, y); + + for (unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft; // retrieve right boundary + const WORD *pixel = src_bits + iLeft * wordspp; + double r = 0, g = 0, b = 0, a = 0; + + // for(i = iLeft to iRight) + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(x, i); + r += (weight * (double)pixel[0]); + g += (weight * (double)pixel[1]); + b += (weight * (double)pixel[2]); + a += (weight * (double)pixel[3]); + pixel += wordspp; + } + + // clamp and place result in destination pixel + dst_bits[0] = (WORD)CLAMP((int)(r + 0.5), 0, 0xFFFF); + dst_bits[1] = (WORD)CLAMP((int)(g + 0.5), 0, 0xFFFF); + dst_bits[2] = (WORD)CLAMP((int)(b + 0.5), 0, 0xFFFF); + dst_bits[3] = (WORD)CLAMP((int)(a + 0.5), 0, 0xFFFF); + dst_bits += wordspp; + } + } + } + break; + + case FIT_FLOAT: + case FIT_RGBF: + case FIT_RGBAF: + { + // Calculate the number of floats per pixel (1 for 32-bit, 3 for 96-bit or 4 for 128-bit) + const unsigned floatspp = (FreeImage_GetLine(src) / src_width) / sizeof(float); + + for(unsigned y = 0; y < height; y++) { + // scale each row + const float *src_bits = (float*)FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x / sizeof(float); + float *dst_bits = (float*)FreeImage_GetScanLine(dst, y); + + for(unsigned x = 0; x < dst_width; x++) { + // loop through row + const unsigned iLeft = weightsTable.getLeftBoundary(x); // retrieve left boundary + const unsigned iRight = weightsTable.getRightBoundary(x); // retrieve right boundary + double value[4] = {0, 0, 0, 0}; // 4 = 128 bpp max + + for(unsigned i = iLeft; i <= iRight; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(x, i-iLeft); + + unsigned index = i * floatspp; // pixel index + for (unsigned j = 0; j < floatspp; j++) { + value[j] += (weight * (double)src_bits[index++]); + } + } + + // place result in destination pixel + for (unsigned j = 0; j < floatspp; j++) { + dst_bits[j] = (float)value[j]; + } + + dst_bits += floatspp; + } + } + } + break; + } +} + +/// Performs vertical image filtering +void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned src_height, unsigned src_offset_x, unsigned src_offset_y, const RGBQUAD *const src_pal, FIBITMAP *const dst, unsigned dst_height) { + + // allocate and calculate the contributions + CWeightsTable weightsTable(m_pFilter, dst_height, src_height); + + // step through columns + switch(FreeImage_GetImageType(src)) { + case FIT_BITMAP: + { + const unsigned dst_pitch = FreeImage_GetPitch(dst); + BYTE * const dst_base = FreeImage_GetBits(dst); + + switch(FreeImage_GetBPP(src)) { + case 1: + { + const unsigned src_pitch = FreeImage_GetPitch(src); + const BYTE * const src_base = FreeImage_GetBits(src) + + src_offset_y * src_pitch + (src_offset_x >> 3); + + switch(FreeImage_GetBPP(dst)) { + case 8: + { + // transparently convert the 1-bit non-transparent greyscale + // image to 8 bpp + if (src_pal) { + // we have got a palette + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + BYTE *dst_bits = dst_base + x; + const unsigned index = x >> 3; + const unsigned mask = 0x80 >> (x & 0x07); + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const BYTE *src_bits = src_base + iLeft * src_pitch + index; + double value = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const unsigned pixel = (*src_bits & mask) != 0; + value += (weightsTable.getWeight(y, i) + * (double)*(BYTE *)&src_pal[pixel]); + src_bits += src_pitch; + } + value *= 0xFF; + + // clamp and place result in destination pixel + *dst_bits = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } else { + // we do not have a palette + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + BYTE *dst_bits = dst_base + x; + const unsigned index = x >> 3; + const unsigned mask = 0x80 >> (x & 0x07); + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const BYTE *src_bits = src_base + iLeft * src_pitch + index; + double value = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + value += (weightsTable.getWeight(y, i) + * (double)((*src_bits & mask) != 0)); + src_bits += src_pitch; + } + value *= 0xFF; + + // clamp and place result in destination pixel + *dst_bits = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } + } + break; + + case 24: + { + // transparently convert the non-transparent 1-bit image + // to 24 bpp; we always have got a palette here + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + BYTE *dst_bits = dst_base + x * 3; + const unsigned index = x >> 3; + const unsigned mask = 0x80 >> (x & 0x07); + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const BYTE *src_bits = src_base + iLeft * src_pitch + index; + double r = 0, g = 0, b = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(y, i); + const unsigned pixel = (*src_bits & mask) != 0; + const BYTE * const entry = (BYTE *)&src_pal[pixel]; + r += (weight * (double)entry[FI_RGBA_RED]); + g += (weight * (double)entry[FI_RGBA_GREEN]); + b += (weight * (double)entry[FI_RGBA_BLUE]); + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } + break; + + case 32: + { + // transparently convert the transparent 1-bit image + // to 32 bpp; we always have got a palette here + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + BYTE *dst_bits = dst_base + x * 4; + const unsigned index = x >> 3; + const unsigned mask = 0x80 >> (x & 0x07); + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const BYTE *src_bits = src_base + iLeft * src_pitch + index; + double r = 0, g = 0, b = 0, a = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(y, i); + const unsigned pixel = (*src_bits & mask) != 0; + const BYTE * const entry = (BYTE *)&src_pal[pixel]; + r += (weight * (double)entry[FI_RGBA_RED]); + g += (weight * (double)entry[FI_RGBA_GREEN]); + b += (weight * (double)entry[FI_RGBA_BLUE]); + a += (weight * (double)entry[FI_RGBA_ALPHA]); + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int)(a + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } + break; + } + } + break; + + case 4: + { + const unsigned src_pitch = FreeImage_GetPitch(src); + const BYTE *const src_base = FreeImage_GetBits(src) + src_offset_y * src_pitch + (src_offset_x >> 1); + + switch(FreeImage_GetBPP(dst)) { + case 8: + { + // transparently convert the non-transparent 4-bit greyscale image + // to 8 bpp; we always have got a palette for 4-bit images + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + BYTE *dst_bits = dst_base + x; + const unsigned index = x >> 1; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const BYTE *src_bits = src_base + iLeft * src_pitch + index; + double value = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const unsigned pixel = x & 0x01 ? *src_bits & 0x0F : *src_bits >> 4; + value += (weightsTable.getWeight(y, i) + * (double)*(BYTE *)&src_pal[pixel]); + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + *dst_bits = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } + break; + + case 24: + { + // transparently convert the non-transparent 4-bit image + // to 24 bpp; we always have got a palette for 4-bit images + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + BYTE *dst_bits = dst_base + x * 3; + const unsigned index = x >> 1; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const BYTE *src_bits = src_base + iLeft * src_pitch + index; + double r = 0, g = 0, b = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(y, i); + const unsigned pixel = x & 0x01 ? *src_bits & 0x0F : *src_bits >> 4; + const BYTE *const entry = (BYTE *)&src_pal[pixel]; + r += (weight * (double)entry[FI_RGBA_RED]); + g += (weight * (double)entry[FI_RGBA_GREEN]); + b += (weight * (double)entry[FI_RGBA_BLUE]); + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } + break; + + case 32: + { + // transparently convert the transparent 4-bit image + // to 32 bpp; we always have got a palette for 4-bit images + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + BYTE *dst_bits = dst_base + x * 4; + const unsigned index = x >> 1; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const BYTE *src_bits = src_base + iLeft * src_pitch + index; + double r = 0, g = 0, b = 0, a = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(y, i); + const unsigned pixel = x & 0x01 ? *src_bits & 0x0F : *src_bits >> 4; + const BYTE *const entry = (BYTE *)&src_pal[pixel]; + r += (weight * (double)entry[FI_RGBA_RED]); + g += (weight * (double)entry[FI_RGBA_GREEN]); + b += (weight * (double)entry[FI_RGBA_BLUE]); + a += (weight * (double)entry[FI_RGBA_ALPHA]); + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int)(a + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } + break; + } + } + break; + + case 8: + { + const unsigned src_pitch = FreeImage_GetPitch(src); + const BYTE *const src_base = FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x; + + switch(FreeImage_GetBPP(dst)) { + case 8: + { + // scale the 8-bit non-transparent greyscale image + // into an 8 bpp destination image + if (src_pal) { + // we have got a palette + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + BYTE *dst_bits = dst_base + x; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const BYTE *src_bits = src_base + iLeft * src_pitch + x; + double value = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + value += (weightsTable.getWeight(y, i) + * (double)*(BYTE *)&src_pal[*src_bits]); + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + *dst_bits = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } else { + // we do not have a palette + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + BYTE *dst_bits = dst_base + x; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const BYTE *src_bits = src_base + iLeft * src_pitch + x; + double value = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + value += (weightsTable.getWeight(y, i) + * (double)*src_bits); + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + *dst_bits = (BYTE)CLAMP((int)(value + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } + } + break; + + case 24: + { + // transparently convert the non-transparent 8-bit image + // to 24 bpp; we always have got a palette here + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + BYTE *dst_bits = dst_base + x * 3; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const BYTE *src_bits = src_base + iLeft * src_pitch + x; + double r = 0, g = 0, b = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(y, i); + const BYTE * const entry = (BYTE *)&src_pal[*src_bits]; + r += (weight * (double)entry[FI_RGBA_RED]); + g += (weight * (double)entry[FI_RGBA_GREEN]); + b += (weight * (double)entry[FI_RGBA_BLUE]); + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } + break; + + case 32: + { + // transparently convert the transparent 8-bit image + // to 32 bpp; we always have got a palette here + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + BYTE *dst_bits = dst_base + x * 4; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const BYTE *src_bits = src_base + iLeft * src_pitch + x; + double r = 0, g = 0, b = 0, a = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(y, i); + const BYTE * const entry = (BYTE *)&src_pal[*src_bits]; + r += (weight * (double)entry[FI_RGBA_RED]); + g += (weight * (double)entry[FI_RGBA_GREEN]); + b += (weight * (double)entry[FI_RGBA_BLUE]); + a += (weight * (double)entry[FI_RGBA_ALPHA]); + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int)(a + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } + break; + } + } + break; + + case 16: + { + // transparently convert the 16-bit non-transparent image + // to 24 bpp + const unsigned src_pitch = FreeImage_GetPitch(src) / sizeof(WORD); + const WORD *const src_base = (WORD *)FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x; + + if (IS_FORMAT_RGB565(src)) { + // image has 565 format + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + BYTE *dst_bits = dst_base + x * 3; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const WORD *src_bits = src_base + iLeft * src_pitch + x; + double r = 0, g = 0, b = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(y, i); + r += (weight * (double)((*src_bits & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT)); + g += (weight * (double)((*src_bits & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT)); + b += (weight * (double)((*src_bits & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT)); + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(((g * 0xFF) / 0x3F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } else { + // image has 555 format + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + BYTE *dst_bits = dst_base + x * 3; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const WORD *src_bits = src_base + iLeft * src_pitch + x; + double r = 0, g = 0, b = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(y, i); + r += (weight * (double)((*src_bits & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT)); + g += (weight * (double)((*src_bits & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT)); + b += (weight * (double)((*src_bits & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT)); + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int)(((g * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } + } + break; + + case 24: + { + // scale the 24-bit transparent image + // into a 24 bpp destination image + const unsigned src_pitch = FreeImage_GetPitch(src); + const BYTE *const src_base = FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x * 3; + + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + const unsigned index = x * 3; + BYTE *dst_bits = dst_base + index; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const BYTE *src_bits = src_base + iLeft * src_pitch + index; + double r = 0, g = 0, b = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(y, i); + r += (weight * (double)src_bits[FI_RGBA_RED]); + g += (weight * (double)src_bits[FI_RGBA_GREEN]); + b += (weight * (double)src_bits[FI_RGBA_BLUE]); + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int) (r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int) (g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int) (b + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } + break; + + case 32: + { + // scale the 32-bit transparent image + // into a 32 bpp destination image + const unsigned src_pitch = FreeImage_GetPitch(src); + const BYTE *const src_base = FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x * 4; + + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + const unsigned index = x * 4; + BYTE *dst_bits = dst_base + index; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const BYTE *src_bits = src_base + iLeft * src_pitch + index; + double r = 0, g = 0, b = 0, a = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(y, i); + r += (weight * (double)src_bits[FI_RGBA_RED]); + g += (weight * (double)src_bits[FI_RGBA_GREEN]); + b += (weight * (double)src_bits[FI_RGBA_BLUE]); + a += (weight * (double)src_bits[FI_RGBA_ALPHA]); + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + dst_bits[FI_RGBA_RED] = (BYTE)CLAMP((int) (r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (BYTE)CLAMP((int) (g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (BYTE)CLAMP((int) (b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (BYTE)CLAMP((int) (a + 0.5), 0, 0xFF); + dst_bits += dst_pitch; + } + } + } + break; + } + } + break; + + case FIT_UINT16: + { + // Calculate the number of words per pixel (1 for 16-bit, 3 for 48-bit or 4 for 64-bit) + const unsigned wordspp = (FreeImage_GetLine(src) / width) / sizeof(WORD); + + const unsigned dst_pitch = FreeImage_GetPitch(dst) / sizeof(WORD); + WORD *const dst_base = (WORD *)FreeImage_GetBits(dst); + + const unsigned src_pitch = FreeImage_GetPitch(src) / sizeof(WORD); + const WORD *const src_base = (WORD *)FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x * wordspp; + + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + const unsigned index = x * wordspp; // pixel index + WORD *dst_bits = dst_base + index; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const WORD *src_bits = src_base + iLeft * src_pitch + index; + double value = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(y, i); + value += (weight * (double)src_bits[0]); + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + dst_bits[0] = (WORD)CLAMP((int)(value + 0.5), 0, 0xFFFF); + + dst_bits += dst_pitch; + } + } + } + break; + + case FIT_RGB16: + { + // Calculate the number of words per pixel (1 for 16-bit, 3 for 48-bit or 4 for 64-bit) + const unsigned wordspp = (FreeImage_GetLine(src) / width) / sizeof(WORD); + + const unsigned dst_pitch = FreeImage_GetPitch(dst) / sizeof(WORD); + WORD *const dst_base = (WORD *)FreeImage_GetBits(dst); + + const unsigned src_pitch = FreeImage_GetPitch(src) / sizeof(WORD); + const WORD *const src_base = (WORD *)FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x * wordspp; + + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + const unsigned index = x * wordspp; // pixel index + WORD *dst_bits = dst_base + index; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const WORD *src_bits = src_base + iLeft * src_pitch + index; + double r = 0, g = 0, b = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(y, i); + r += (weight * (double)src_bits[0]); + g += (weight * (double)src_bits[1]); + b += (weight * (double)src_bits[2]); + + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + dst_bits[0] = (WORD)CLAMP((int)(r + 0.5), 0, 0xFFFF); + dst_bits[1] = (WORD)CLAMP((int)(g + 0.5), 0, 0xFFFF); + dst_bits[2] = (WORD)CLAMP((int)(b + 0.5), 0, 0xFFFF); + + dst_bits += dst_pitch; + } + } + } + break; + + case FIT_RGBA16: + { + // Calculate the number of words per pixel (1 for 16-bit, 3 for 48-bit or 4 for 64-bit) + const unsigned wordspp = (FreeImage_GetLine(src) / width) / sizeof(WORD); + + const unsigned dst_pitch = FreeImage_GetPitch(dst) / sizeof(WORD); + WORD *const dst_base = (WORD *)FreeImage_GetBits(dst); + + const unsigned src_pitch = FreeImage_GetPitch(src) / sizeof(WORD); + const WORD *const src_base = (WORD *)FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x * wordspp; + + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + const unsigned index = x * wordspp; // pixel index + WORD *dst_bits = dst_base + index; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft; // retrieve right boundary + const WORD *src_bits = src_base + iLeft * src_pitch + index; + double r = 0, g = 0, b = 0, a = 0; + + for (unsigned i = 0; i <= iLimit; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(y, i); + r += (weight * (double)src_bits[0]); + g += (weight * (double)src_bits[1]); + b += (weight * (double)src_bits[2]); + a += (weight * (double)src_bits[3]); + + src_bits += src_pitch; + } + + // clamp and place result in destination pixel + dst_bits[0] = (WORD)CLAMP((int)(r + 0.5), 0, 0xFFFF); + dst_bits[1] = (WORD)CLAMP((int)(g + 0.5), 0, 0xFFFF); + dst_bits[2] = (WORD)CLAMP((int)(b + 0.5), 0, 0xFFFF); + dst_bits[3] = (WORD)CLAMP((int)(a + 0.5), 0, 0xFFFF); + + dst_bits += dst_pitch; + } + } + } + break; + + case FIT_FLOAT: + case FIT_RGBF: + case FIT_RGBAF: + { + // Calculate the number of floats per pixel (1 for 32-bit, 3 for 96-bit or 4 for 128-bit) + const unsigned floatspp = (FreeImage_GetLine(src) / width) / sizeof(float); + + const unsigned dst_pitch = FreeImage_GetPitch(dst) / sizeof(float); + float *const dst_base = (float *)FreeImage_GetBits(dst); + + const unsigned src_pitch = FreeImage_GetPitch(src) / sizeof(float); + const float *const src_base = (float *)FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x * floatspp; + + for (unsigned x = 0; x < width; x++) { + // work on column x in dst + const unsigned index = x * floatspp; // pixel index + float *dst_bits = (float *)dst_base + index; + + // scale each column + for (unsigned y = 0; y < dst_height; y++) { + // loop through column + const unsigned iLeft = weightsTable.getLeftBoundary(y); // retrieve left boundary + const unsigned iRight = weightsTable.getRightBoundary(y); // retrieve right boundary + const float *src_bits = src_base + iLeft * src_pitch + index; + double value[4] = {0, 0, 0, 0}; // 4 = 128 bpp max + + for (unsigned i = iLeft; i <= iRight; i++) { + // scan between boundaries + // accumulate weighted effect of each neighboring pixel + const double weight = weightsTable.getWeight(y, i - iLeft); + for (unsigned j = 0; j < floatspp; j++) { + value[j] += (weight * (double)src_bits[j]); + } + src_bits += src_pitch; + } + + // place result in destination pixel + for (unsigned j = 0; j < floatspp; j++) { + dst_bits[j] = (float)value[j]; + } + dst_bits += dst_pitch; + } + } + } + break; + } +} diff --git a/Source/FreeImageToolkit/Resize.h b/Source/FreeImageToolkit/Resize.h index 7fe1cdb..6e1ab02 100644 --- a/Source/FreeImageToolkit/Resize.h +++ b/Source/FreeImageToolkit/Resize.h @@ -1,195 +1,195 @@ -// ========================================================== -// Upsampling / downsampling classes -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// - Detlev Vendt (detlev.vendt@brillit.de) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#ifndef _RESIZE_H_ -#define _RESIZE_H_ - -#include "FreeImage.h" -#include "Utilities.h" -#include "Filters.h" - -/** - Filter weights table.
- This class stores contribution information for an entire line (row or column). -*/ -class CWeightsTable -{ -/** - Sampled filter weight table.
- Contribution information for a single pixel -*/ -typedef struct { - /// Normalized weights of neighboring pixels - double *Weights; - /// Bounds of source pixels window - unsigned Left, Right; -} Contribution; - -private: - /// Row (or column) of contribution weights - Contribution *m_WeightTable; - /// Filter window size (of affecting source pixels) - unsigned m_WindowSize; - /// Length of line (no. of rows / cols) - unsigned m_LineLength; - -public: - /** - Constructor
- Allocate and compute the weights table - @param pFilter Filter used for upsampling or downsampling - @param uDstSize Length (in pixels) of the destination line buffer - @param uSrcSize Length (in pixels) of the source line buffer - */ - CWeightsTable(CGenericFilter *pFilter, unsigned uDstSize, unsigned uSrcSize); - - /** - Destructor
- Destroy the weights table - */ - ~CWeightsTable(); - - /** Retrieve a filter weight, given source and destination positions - @param dst_pos Pixel position in destination line buffer - @param src_pos Pixel position in source line buffer - @return Returns the filter weight - */ - double getWeight(unsigned dst_pos, unsigned src_pos) { - return m_WeightTable[dst_pos].Weights[src_pos]; - } - - /** Retrieve left boundary of source line buffer - @param dst_pos Pixel position in destination line buffer - @return Returns the left boundary of source line buffer - */ - unsigned getLeftBoundary(unsigned dst_pos) { - return m_WeightTable[dst_pos].Left; - } - - /** Retrieve right boundary of source line buffer - @param dst_pos Pixel position in destination line buffer - @return Returns the right boundary of source line buffer - */ - unsigned getRightBoundary(unsigned dst_pos) { - return m_WeightTable[dst_pos].Right; - } -}; - -// --------------------------------------------- - -/** - CResizeEngine
- This class performs filtered zoom. It scales an image to the desired dimensions with - any of the CGenericFilter derived filter class.
- It works with FIT_BITMAP buffers, WORD buffers (FIT_UINT16, FIT_RGB16, FIT_RGBA16) - and float buffers (FIT_FLOAT, FIT_RGBF, FIT_RGBAF).

- - References :
- [1] Paul Heckbert, C code to zoom raster images up or down, with nice filtering. - UC Berkeley, August 1989. [online] http://www-2.cs.cmu.edu/afs/cs.cmu.edu/Web/People/ph/heckbert.html - [2] Eran Yariv, Two Pass Scaling using Filters. The Code Project, December 1999. - [online] http://www.codeproject.com/bitmap/2_pass_scaling.asp - -*/ -class CResizeEngine -{ -private: - /// Pointer to the FIR / IIR filter - CGenericFilter* m_pFilter; - -public: - - /** - Constructor - @param filter FIR /IIR filter to be used - */ - CResizeEngine(CGenericFilter* filter):m_pFilter(filter) {} - - /// Destructor - virtual ~CResizeEngine() {} - - /** Scale an image to the desired dimensions. - - Method CResizeEngine::scale, as well as the two filtering methods - CResizeEngine::horizontalFilter and CResizeEngine::verticalFilter take - four additional parameters, that define a rectangle in the source - image to be rescaled. - - These are src_left, src_top, src_width and src_height and should work - like these of function FreeImage_Copy. However, src_left and src_top are - actually named src_offset_x and src_offset_y in the filtering methods. - - Additionally, since src_height and dst_height are always the same for - method horizontalFilter as src_width and dst_width are always the same - for verticalFilter, these have been stripped down to a single parameter - height and width for horizontalFilter and verticalFilter respectively. - - Currently, method scale is called with the actual size of the source - image. However, in a future version, we could provide a new function - called FreeImage_RescaleRect that rescales only part of an image. - - @param src Pointer to the source image - @param dst_width Destination image width - @param dst_height Destination image height - @param src_left Left boundary of the source rectangle to be scaled - @param src_top Top boundary of the source rectangle to be scaled - @param src_width Width of the source rectangle to be scaled - @param src_height Height of the source rectangle to be scaled - @return Returns the scaled image if successful, returns NULL otherwise - */ - FIBITMAP* scale(FIBITMAP *src, unsigned dst_width, unsigned dst_height, unsigned src_left, unsigned src_top, unsigned src_width, unsigned src_height); - -private: - - /** - Performs horizontal image filtering - @param src - @param height - @param src_width - @param src_offset_x - @param src_offset_y - @param src_pal - @param dst - @param dst_width - */ - void horizontalFilter(FIBITMAP * const src, const unsigned height, const unsigned src_width, - const unsigned src_offset_x, const unsigned src_offset_y, const RGBQUAD * const src_pal, - FIBITMAP * const dst, const unsigned dst_width); - - /** - Performs vertical image filtering - @param src - @param width - @param src_height - @param src_offset_x - @param src_offset_y - @param src_pal - @param dst - @param dst_height - */ - void verticalFilter(FIBITMAP * const src, const unsigned width, const unsigned src_height, - const unsigned src_offset_x, const unsigned src_offset_y, const RGBQUAD * const src_pal, - FIBITMAP * const dst, const unsigned dst_height); -}; - -#endif // _RESIZE_H_ +// ========================================================== +// Upsampling / downsampling classes +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// - Detlev Vendt (detlev.vendt@brillit.de) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#ifndef _RESIZE_H_ +#define _RESIZE_H_ + +#include "FreeImage.h" +#include "Utilities.h" +#include "Filters.h" + +/** + Filter weights table.
+ This class stores contribution information for an entire line (row or column). +*/ +class CWeightsTable +{ +/** + Sampled filter weight table.
+ Contribution information for a single pixel +*/ +typedef struct { + /// Normalized weights of neighboring pixels + double *Weights; + /// Bounds of source pixels window + unsigned Left, Right; +} Contribution; + +private: + /// Row (or column) of contribution weights + Contribution *m_WeightTable; + /// Filter window size (of affecting source pixels) + unsigned m_WindowSize; + /// Length of line (no. of rows / cols) + unsigned m_LineLength; + +public: + /** + Constructor
+ Allocate and compute the weights table + @param pFilter Filter used for upsampling or downsampling + @param uDstSize Length (in pixels) of the destination line buffer + @param uSrcSize Length (in pixels) of the source line buffer + */ + CWeightsTable(CGenericFilter *pFilter, unsigned uDstSize, unsigned uSrcSize); + + /** + Destructor
+ Destroy the weights table + */ + ~CWeightsTable(); + + /** Retrieve a filter weight, given source and destination positions + @param dst_pos Pixel position in destination line buffer + @param src_pos Pixel position in source line buffer + @return Returns the filter weight + */ + double getWeight(unsigned dst_pos, unsigned src_pos) { + return m_WeightTable[dst_pos].Weights[src_pos]; + } + + /** Retrieve left boundary of source line buffer + @param dst_pos Pixel position in destination line buffer + @return Returns the left boundary of source line buffer + */ + unsigned getLeftBoundary(unsigned dst_pos) { + return m_WeightTable[dst_pos].Left; + } + + /** Retrieve right boundary of source line buffer + @param dst_pos Pixel position in destination line buffer + @return Returns the right boundary of source line buffer + */ + unsigned getRightBoundary(unsigned dst_pos) { + return m_WeightTable[dst_pos].Right; + } +}; + +// --------------------------------------------- + +/** + CResizeEngine
+ This class performs filtered zoom. It scales an image to the desired dimensions with + any of the CGenericFilter derived filter class.
+ It works with FIT_BITMAP buffers, WORD buffers (FIT_UINT16, FIT_RGB16, FIT_RGBA16) + and float buffers (FIT_FLOAT, FIT_RGBF, FIT_RGBAF).

+ + References :
+ [1] Paul Heckbert, C code to zoom raster images up or down, with nice filtering. + UC Berkeley, August 1989. [online] http://www-2.cs.cmu.edu/afs/cs.cmu.edu/Web/People/ph/heckbert.html + [2] Eran Yariv, Two Pass Scaling using Filters. The Code Project, December 1999. + [online] http://www.codeproject.com/bitmap/2_pass_scaling.asp + +*/ +class CResizeEngine +{ +private: + /// Pointer to the FIR / IIR filter + CGenericFilter* m_pFilter; + +public: + + /** + Constructor + @param filter FIR /IIR filter to be used + */ + CResizeEngine(CGenericFilter* filter):m_pFilter(filter) {} + + /// Destructor + virtual ~CResizeEngine() {} + + /** Scale an image to the desired dimensions. + + Method CResizeEngine::scale, as well as the two filtering methods + CResizeEngine::horizontalFilter and CResizeEngine::verticalFilter take + four additional parameters, that define a rectangle in the source + image to be rescaled. + + These are src_left, src_top, src_width and src_height and should work + like these of function FreeImage_Copy. However, src_left and src_top are + actually named src_offset_x and src_offset_y in the filtering methods. + + Additionally, since src_height and dst_height are always the same for + method horizontalFilter as src_width and dst_width are always the same + for verticalFilter, these have been stripped down to a single parameter + height and width for horizontalFilter and verticalFilter respectively. + + Currently, method scale is called with the actual size of the source + image. However, in a future version, we could provide a new function + called FreeImage_RescaleRect that rescales only part of an image. + + @param src Pointer to the source image + @param dst_width Destination image width + @param dst_height Destination image height + @param src_left Left boundary of the source rectangle to be scaled + @param src_top Top boundary of the source rectangle to be scaled + @param src_width Width of the source rectangle to be scaled + @param src_height Height of the source rectangle to be scaled + @return Returns the scaled image if successful, returns NULL otherwise + */ + FIBITMAP* scale(FIBITMAP *src, unsigned dst_width, unsigned dst_height, unsigned src_left, unsigned src_top, unsigned src_width, unsigned src_height); + +private: + + /** + Performs horizontal image filtering + @param src + @param height + @param src_width + @param src_offset_x + @param src_offset_y + @param src_pal + @param dst + @param dst_width + */ + void horizontalFilter(FIBITMAP * const src, const unsigned height, const unsigned src_width, + const unsigned src_offset_x, const unsigned src_offset_y, const RGBQUAD * const src_pal, + FIBITMAP * const dst, const unsigned dst_width); + + /** + Performs vertical image filtering + @param src + @param width + @param src_height + @param src_offset_x + @param src_offset_y + @param src_pal + @param dst + @param dst_height + */ + void verticalFilter(FIBITMAP * const src, const unsigned width, const unsigned src_height, + const unsigned src_offset_x, const unsigned src_offset_y, const RGBQUAD * const src_pal, + FIBITMAP * const dst, const unsigned dst_height); +}; + +#endif // _RESIZE_H_ diff --git a/Source/LibJPEG/README b/Source/LibJPEG/README index 07bb50b..0a23c19 100644 --- a/Source/LibJPEG/README +++ b/Source/LibJPEG/README @@ -1,351 +1,351 @@ -The Independent JPEG Group's JPEG software -========================================== - -README for release 8d of 15-Jan-2012 -==================================== - -This distribution contains the eighth public release of the Independent JPEG -Group's free JPEG software. You are welcome to redistribute this software and -to use it for any purpose, subject to the conditions under LEGAL ISSUES, below. - -This software is the work of Tom Lane, Guido Vollbeding, Philip Gladstone, -Bill Allombert, Jim Boucher, Lee Crocker, Bob Friesenhahn, Ben Jackson, -Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi, Ge' Weijers, -and other members of the Independent JPEG Group. - -IJG is not affiliated with the ISO/IEC JTC1/SC29/WG1 standards committee -(also known as JPEG, together with ITU-T SG16). - - -DOCUMENTATION ROADMAP -===================== - -This file contains the following sections: - -OVERVIEW General description of JPEG and the IJG software. -LEGAL ISSUES Copyright, lack of warranty, terms of distribution. -REFERENCES Where to learn more about JPEG. -ARCHIVE LOCATIONS Where to find newer versions of this software. -ACKNOWLEDGMENTS Special thanks. -FILE FORMAT WARS Software *not* to get. -TO DO Plans for future IJG releases. - -Other documentation files in the distribution are: - -User documentation: - install.txt How to configure and install the IJG software. - usage.txt Usage instructions for cjpeg, djpeg, jpegtran, - rdjpgcom, and wrjpgcom. - *.1 Unix-style man pages for programs (same info as usage.txt). - wizard.txt Advanced usage instructions for JPEG wizards only. - change.log Version-to-version change highlights. -Programmer and internal documentation: - libjpeg.txt How to use the JPEG library in your own programs. - example.c Sample code for calling the JPEG library. - structure.txt Overview of the JPEG library's internal structure. - filelist.txt Road map of IJG files. - coderules.txt Coding style rules --- please read if you contribute code. - -Please read at least the files install.txt and usage.txt. Some information -can also be found in the JPEG FAQ (Frequently Asked Questions) article. See -ARCHIVE LOCATIONS below to find out where to obtain the FAQ article. - -If you want to understand how the JPEG code works, we suggest reading one or -more of the REFERENCES, then looking at the documentation files (in roughly -the order listed) before diving into the code. - - -OVERVIEW -======== - -This package contains C software to implement JPEG image encoding, decoding, -and transcoding. JPEG (pronounced "jay-peg") is a standardized compression -method for full-color and gray-scale images. - -This software implements JPEG baseline, extended-sequential, and progressive -compression processes. Provision is made for supporting all variants of these -processes, although some uncommon parameter settings aren't implemented yet. -We have made no provision for supporting the hierarchical or lossless -processes defined in the standard. - -We provide a set of library routines for reading and writing JPEG image files, -plus two sample applications "cjpeg" and "djpeg", which use the library to -perform conversion between JPEG and some other popular image file formats. -The library is intended to be reused in other applications. - -In order to support file conversion and viewing software, we have included -considerable functionality beyond the bare JPEG coding/decoding capability; -for example, the color quantization modules are not strictly part of JPEG -decoding, but they are essential for output to colormapped file formats or -colormapped displays. These extra functions can be compiled out of the -library if not required for a particular application. - -We have also included "jpegtran", a utility for lossless transcoding between -different JPEG processes, and "rdjpgcom" and "wrjpgcom", two simple -applications for inserting and extracting textual comments in JFIF files. - -The emphasis in designing this software has been on achieving portability and -flexibility, while also making it fast enough to be useful. In particular, -the software is not intended to be read as a tutorial on JPEG. (See the -REFERENCES section for introductory material.) Rather, it is intended to -be reliable, portable, industrial-strength code. We do not claim to have -achieved that goal in every aspect of the software, but we strive for it. - -We welcome the use of this software as a component of commercial products. -No royalty is required, but we do ask for an acknowledgement in product -documentation, as described under LEGAL ISSUES. - - -LEGAL ISSUES -============ - -In plain English: - -1. We don't promise that this software works. (But if you find any bugs, - please let us know!) -2. You can use this software for whatever you want. You don't have to pay us. -3. You may not pretend that you wrote this software. If you use it in a - program, you must acknowledge somewhere in your documentation that - you've used the IJG code. - -In legalese: - -The authors make NO WARRANTY or representation, either express or implied, -with respect to this software, its quality, accuracy, merchantability, or -fitness for a particular purpose. This software is provided "AS IS", and you, -its user, assume the entire risk as to its quality and accuracy. - -This software is copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding. -All Rights Reserved except as specified below. - -Permission is hereby granted to use, copy, modify, and distribute this -software (or portions thereof) for any purpose, without fee, subject to these -conditions: -(1) If any part of the source code for this software is distributed, then this -README file must be included, with this copyright and no-warranty notice -unaltered; and any additions, deletions, or changes to the original files -must be clearly indicated in accompanying documentation. -(2) If only executable code is distributed, then the accompanying -documentation must state that "this software is based in part on the work of -the Independent JPEG Group". -(3) Permission for use of this software is granted only if the user accepts -full responsibility for any undesirable consequences; the authors accept -NO LIABILITY for damages of any kind. - -These conditions apply to any software derived from or based on the IJG code, -not just to the unmodified library. If you use our work, you ought to -acknowledge us. - -Permission is NOT granted for the use of any IJG author's name or company name -in advertising or publicity relating to this software or products derived from -it. This software may be referred to only as "the Independent JPEG Group's -software". - -We specifically permit and encourage the use of this software as the basis of -commercial products, provided that all warranty or liability claims are -assumed by the product vendor. - - -ansi2knr.c is included in this distribution by permission of L. Peter Deutsch, -sole proprietor of its copyright holder, Aladdin Enterprises of Menlo Park, CA. -ansi2knr.c is NOT covered by the above copyright and conditions, but instead -by the usual distribution terms of the Free Software Foundation; principally, -that you must include source code if you redistribute it. (See the file -ansi2knr.c for full details.) However, since ansi2knr.c is not needed as part -of any program generated from the IJG code, this does not limit you more than -the foregoing paragraphs do. - -The Unix configuration script "configure" was produced with GNU Autoconf. -It is copyright by the Free Software Foundation but is freely distributable. -The same holds for its supporting scripts (config.guess, config.sub, -ltmain.sh). Another support script, install-sh, is copyright by X Consortium -but is also freely distributable. - -The IJG distribution formerly included code to read and write GIF files. -To avoid entanglement with the Unisys LZW patent, GIF reading support has -been removed altogether, and the GIF writer has been simplified to produce -"uncompressed GIFs". This technique does not use the LZW algorithm; the -resulting GIF files are larger than usual, but are readable by all standard -GIF decoders. - -We are required to state that - "The Graphics Interchange Format(c) is the Copyright property of - CompuServe Incorporated. GIF(sm) is a Service Mark property of - CompuServe Incorporated." - - -REFERENCES -========== - -We recommend reading one or more of these references before trying to -understand the innards of the JPEG software. - -The best short technical introduction to the JPEG compression algorithm is - Wallace, Gregory K. "The JPEG Still Picture Compression Standard", - Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44. -(Adjacent articles in that issue discuss MPEG motion picture compression, -applications of JPEG, and related topics.) If you don't have the CACM issue -handy, a PostScript file containing a revised version of Wallace's article is -available at http://www.ijg.org/files/wallace.ps.gz. The file (actually -a preprint for an article that appeared in IEEE Trans. Consumer Electronics) -omits the sample images that appeared in CACM, but it includes corrections -and some added material. Note: the Wallace article is copyright ACM and IEEE, -and it may not be used for commercial purposes. - -A somewhat less technical, more leisurely introduction to JPEG can be found in -"The Data Compression Book" by Mark Nelson and Jean-loup Gailly, published by -M&T Books (New York), 2nd ed. 1996, ISBN 1-55851-434-1. This book provides -good explanations and example C code for a multitude of compression methods -including JPEG. It is an excellent source if you are comfortable reading C -code but don't know much about data compression in general. The book's JPEG -sample code is far from industrial-strength, but when you are ready to look -at a full implementation, you've got one here... - -The best currently available description of JPEG is the textbook "JPEG Still -Image Data Compression Standard" by William B. Pennebaker and Joan L. -Mitchell, published by Van Nostrand Reinhold, 1993, ISBN 0-442-01272-1. -Price US$59.95, 638 pp. The book includes the complete text of the ISO JPEG -standards (DIS 10918-1 and draft DIS 10918-2). -Although this is by far the most detailed and comprehensive exposition of -JPEG publicly available, we point out that it is still missing an explanation -of the most essential properties and algorithms of the underlying DCT -technology. -If you think that you know about DCT-based JPEG after reading this book, -then you are in delusion. The real fundamentals and corresponding potential -of DCT-based JPEG are not publicly known so far, and that is the reason for -all the mistaken developments taking place in the image coding domain. - -The original JPEG standard is divided into two parts, Part 1 being the actual -specification, while Part 2 covers compliance testing methods. Part 1 is -titled "Digital Compression and Coding of Continuous-tone Still Images, -Part 1: Requirements and guidelines" and has document numbers ISO/IEC IS -10918-1, ITU-T T.81. Part 2 is titled "Digital Compression and Coding of -Continuous-tone Still Images, Part 2: Compliance testing" and has document -numbers ISO/IEC IS 10918-2, ITU-T T.83. -IJG JPEG 8 introduces an implementation of the JPEG SmartScale extension -which is specified in two documents: A contributed document at ITU and ISO -with title "ITU-T JPEG-Plus Proposal for Extending ITU-T T.81 for Advanced -Image Coding", April 2006, Geneva, Switzerland. The latest version of this -document is Revision 3. And a contributed document ISO/IEC JTC1/SC29/WG1 N -5799 with title "Evolution of JPEG", June/July 2011, Berlin, Germany. - -The JPEG standard does not specify all details of an interchangeable file -format. For the omitted details we follow the "JFIF" conventions, revision -1.02. JFIF 1.02 has been adopted as an Ecma International Technical Report -and thus received a formal publication status. It is available as a free -download in PDF format from -http://www.ecma-international.org/publications/techreports/E-TR-098.htm. -A PostScript version of the JFIF document is available at -http://www.ijg.org/files/jfif.ps.gz. There is also a plain text version at -http://www.ijg.org/files/jfif.txt.gz, but it is missing the figures. - -The TIFF 6.0 file format specification can be obtained by FTP from -ftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz. The JPEG incorporation scheme -found in the TIFF 6.0 spec of 3-June-92 has a number of serious problems. -IJG does not recommend use of the TIFF 6.0 design (TIFF Compression tag 6). -Instead, we recommend the JPEG design proposed by TIFF Technical Note #2 -(Compression tag 7). Copies of this Note can be obtained from -http://www.ijg.org/files/. It is expected that the next revision -of the TIFF spec will replace the 6.0 JPEG design with the Note's design. -Although IJG's own code does not support TIFF/JPEG, the free libtiff library -uses our library to implement TIFF/JPEG per the Note. - - -ARCHIVE LOCATIONS -================= - -The "official" archive site for this software is www.ijg.org. -The most recent released version can always be found there in -directory "files". This particular version will be archived as -http://www.ijg.org/files/jpegsrc.v8d.tar.gz, and in Windows-compatible -"zip" archive format as http://www.ijg.org/files/jpegsr8d.zip. - -The JPEG FAQ (Frequently Asked Questions) article is a source of some -general information about JPEG. -It is available on the World Wide Web at http://www.faqs.org/faqs/jpeg-faq/ -and other news.answers archive sites, including the official news.answers -archive at rtfm.mit.edu: ftp://rtfm.mit.edu/pub/usenet/news.answers/jpeg-faq/. -If you don't have Web or FTP access, send e-mail to mail-server@rtfm.mit.edu -with body - send usenet/news.answers/jpeg-faq/part1 - send usenet/news.answers/jpeg-faq/part2 - - -ACKNOWLEDGMENTS -=============== - -Thank to Juergen Bruder for providing me with a copy of the common DCT -algorithm article, only to find out that I had come to the same result -in a more direct and comprehensible way with a more generative approach. - -Thank to Istvan Sebestyen and Joan L. Mitchell for inviting me to the -ITU JPEG (Study Group 16) meeting in Geneva, Switzerland. - -Thank to Thomas Wiegand and Gary Sullivan for inviting me to the -Joint Video Team (MPEG & ITU) meeting in Geneva, Switzerland. - -Thank to Thomas Richter and Daniel Lee for inviting me to the -ISO/IEC JTC1/SC29/WG1 (also known as JPEG, together with ITU-T SG16) -meeting in Berlin, Germany. - -Thank to John Korejwa and Massimo Ballerini for inviting me to -fruitful consultations in Boston, MA and Milan, Italy. - -Thank to Hendrik Elstner, Roland Fassauer, Simone Zuck, Guenther -Maier-Gerber, Walter Stoeber, Fred Schmitz, and Norbert Braunagel -for corresponding business development. - -Thank to Nico Zschach and Dirk Stelling of the technical support team -at the Digital Images company in Halle for providing me with extra -equipment for configuration tests. - -Thank to Richard F. Lyon (then of Foveon Inc.) for fruitful -communication about JPEG configuration in Sigma Photo Pro software. - -Thank to Andrew Finkenstadt for hosting the ijg.org site. - -Last but not least special thank to Thomas G. Lane for the original -design and development of this singular software package. - - -FILE FORMAT WARS -================ - -The ISO/IEC JTC1/SC29/WG1 standards committee (also known as JPEG, together -with ITU-T SG16) currently promotes different formats containing the name -"JPEG" which is misleading because these formats are incompatible with -original DCT-based JPEG and are based on faulty technologies. -IJG therefore does not and will not support such momentary mistakes -(see REFERENCES). -There exist also distributions under the name "OpenJPEG" promoting such -kind of formats which is misleading because they don't support original -JPEG images. -We have no sympathy for the promotion of inferior formats. Indeed, one of -the original reasons for developing this free software was to help force -convergence on common, interoperable format standards for JPEG files. -Don't use an incompatible file format! -(In any case, our decoder will remain capable of reading existing JPEG -image files indefinitely.) - -Furthermore, the ISO committee pretends to be "responsible for the popular -JPEG" in their public reports which is not true because they don't respond to -actual requirements for the maintenance of the original JPEG specification. - -There are currently distributions in circulation containing the name -"libjpeg" which claim to be a "derivative" or "fork" of the original -libjpeg, but don't have the features and are incompatible with formats -supported by actual IJG libjpeg distributions. Furthermore, they -violate the license conditions as described under LEGAL ISSUES above. -We have no sympathy for the release of misleading and illegal -distributions derived from obsolete code bases. -Don't use an obsolete code base! - - -TO DO -===== - -Version 8 is the first release of a new generation JPEG standard -to overcome the limitations of the original JPEG specification. -More features are being prepared for coming releases... - -Please send bug reports, offers of help, etc. to jpeg-info@jpegclub.org. +The Independent JPEG Group's JPEG software +========================================== + +README for release 8d of 15-Jan-2012 +==================================== + +This distribution contains the eighth public release of the Independent JPEG +Group's free JPEG software. You are welcome to redistribute this software and +to use it for any purpose, subject to the conditions under LEGAL ISSUES, below. + +This software is the work of Tom Lane, Guido Vollbeding, Philip Gladstone, +Bill Allombert, Jim Boucher, Lee Crocker, Bob Friesenhahn, Ben Jackson, +Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi, Ge' Weijers, +and other members of the Independent JPEG Group. + +IJG is not affiliated with the ISO/IEC JTC1/SC29/WG1 standards committee +(also known as JPEG, together with ITU-T SG16). + + +DOCUMENTATION ROADMAP +===================== + +This file contains the following sections: + +OVERVIEW General description of JPEG and the IJG software. +LEGAL ISSUES Copyright, lack of warranty, terms of distribution. +REFERENCES Where to learn more about JPEG. +ARCHIVE LOCATIONS Where to find newer versions of this software. +ACKNOWLEDGMENTS Special thanks. +FILE FORMAT WARS Software *not* to get. +TO DO Plans for future IJG releases. + +Other documentation files in the distribution are: + +User documentation: + install.txt How to configure and install the IJG software. + usage.txt Usage instructions for cjpeg, djpeg, jpegtran, + rdjpgcom, and wrjpgcom. + *.1 Unix-style man pages for programs (same info as usage.txt). + wizard.txt Advanced usage instructions for JPEG wizards only. + change.log Version-to-version change highlights. +Programmer and internal documentation: + libjpeg.txt How to use the JPEG library in your own programs. + example.c Sample code for calling the JPEG library. + structure.txt Overview of the JPEG library's internal structure. + filelist.txt Road map of IJG files. + coderules.txt Coding style rules --- please read if you contribute code. + +Please read at least the files install.txt and usage.txt. Some information +can also be found in the JPEG FAQ (Frequently Asked Questions) article. See +ARCHIVE LOCATIONS below to find out where to obtain the FAQ article. + +If you want to understand how the JPEG code works, we suggest reading one or +more of the REFERENCES, then looking at the documentation files (in roughly +the order listed) before diving into the code. + + +OVERVIEW +======== + +This package contains C software to implement JPEG image encoding, decoding, +and transcoding. JPEG (pronounced "jay-peg") is a standardized compression +method for full-color and gray-scale images. + +This software implements JPEG baseline, extended-sequential, and progressive +compression processes. Provision is made for supporting all variants of these +processes, although some uncommon parameter settings aren't implemented yet. +We have made no provision for supporting the hierarchical or lossless +processes defined in the standard. + +We provide a set of library routines for reading and writing JPEG image files, +plus two sample applications "cjpeg" and "djpeg", which use the library to +perform conversion between JPEG and some other popular image file formats. +The library is intended to be reused in other applications. + +In order to support file conversion and viewing software, we have included +considerable functionality beyond the bare JPEG coding/decoding capability; +for example, the color quantization modules are not strictly part of JPEG +decoding, but they are essential for output to colormapped file formats or +colormapped displays. These extra functions can be compiled out of the +library if not required for a particular application. + +We have also included "jpegtran", a utility for lossless transcoding between +different JPEG processes, and "rdjpgcom" and "wrjpgcom", two simple +applications for inserting and extracting textual comments in JFIF files. + +The emphasis in designing this software has been on achieving portability and +flexibility, while also making it fast enough to be useful. In particular, +the software is not intended to be read as a tutorial on JPEG. (See the +REFERENCES section for introductory material.) Rather, it is intended to +be reliable, portable, industrial-strength code. We do not claim to have +achieved that goal in every aspect of the software, but we strive for it. + +We welcome the use of this software as a component of commercial products. +No royalty is required, but we do ask for an acknowledgement in product +documentation, as described under LEGAL ISSUES. + + +LEGAL ISSUES +============ + +In plain English: + +1. We don't promise that this software works. (But if you find any bugs, + please let us know!) +2. You can use this software for whatever you want. You don't have to pay us. +3. You may not pretend that you wrote this software. If you use it in a + program, you must acknowledge somewhere in your documentation that + you've used the IJG code. + +In legalese: + +The authors make NO WARRANTY or representation, either express or implied, +with respect to this software, its quality, accuracy, merchantability, or +fitness for a particular purpose. This software is provided "AS IS", and you, +its user, assume the entire risk as to its quality and accuracy. + +This software is copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding. +All Rights Reserved except as specified below. + +Permission is hereby granted to use, copy, modify, and distribute this +software (or portions thereof) for any purpose, without fee, subject to these +conditions: +(1) If any part of the source code for this software is distributed, then this +README file must be included, with this copyright and no-warranty notice +unaltered; and any additions, deletions, or changes to the original files +must be clearly indicated in accompanying documentation. +(2) If only executable code is distributed, then the accompanying +documentation must state that "this software is based in part on the work of +the Independent JPEG Group". +(3) Permission for use of this software is granted only if the user accepts +full responsibility for any undesirable consequences; the authors accept +NO LIABILITY for damages of any kind. + +These conditions apply to any software derived from or based on the IJG code, +not just to the unmodified library. If you use our work, you ought to +acknowledge us. + +Permission is NOT granted for the use of any IJG author's name or company name +in advertising or publicity relating to this software or products derived from +it. This software may be referred to only as "the Independent JPEG Group's +software". + +We specifically permit and encourage the use of this software as the basis of +commercial products, provided that all warranty or liability claims are +assumed by the product vendor. + + +ansi2knr.c is included in this distribution by permission of L. Peter Deutsch, +sole proprietor of its copyright holder, Aladdin Enterprises of Menlo Park, CA. +ansi2knr.c is NOT covered by the above copyright and conditions, but instead +by the usual distribution terms of the Free Software Foundation; principally, +that you must include source code if you redistribute it. (See the file +ansi2knr.c for full details.) However, since ansi2knr.c is not needed as part +of any program generated from the IJG code, this does not limit you more than +the foregoing paragraphs do. + +The Unix configuration script "configure" was produced with GNU Autoconf. +It is copyright by the Free Software Foundation but is freely distributable. +The same holds for its supporting scripts (config.guess, config.sub, +ltmain.sh). Another support script, install-sh, is copyright by X Consortium +but is also freely distributable. + +The IJG distribution formerly included code to read and write GIF files. +To avoid entanglement with the Unisys LZW patent, GIF reading support has +been removed altogether, and the GIF writer has been simplified to produce +"uncompressed GIFs". This technique does not use the LZW algorithm; the +resulting GIF files are larger than usual, but are readable by all standard +GIF decoders. + +We are required to state that + "The Graphics Interchange Format(c) is the Copyright property of + CompuServe Incorporated. GIF(sm) is a Service Mark property of + CompuServe Incorporated." + + +REFERENCES +========== + +We recommend reading one or more of these references before trying to +understand the innards of the JPEG software. + +The best short technical introduction to the JPEG compression algorithm is + Wallace, Gregory K. "The JPEG Still Picture Compression Standard", + Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44. +(Adjacent articles in that issue discuss MPEG motion picture compression, +applications of JPEG, and related topics.) If you don't have the CACM issue +handy, a PostScript file containing a revised version of Wallace's article is +available at http://www.ijg.org/files/wallace.ps.gz. The file (actually +a preprint for an article that appeared in IEEE Trans. Consumer Electronics) +omits the sample images that appeared in CACM, but it includes corrections +and some added material. Note: the Wallace article is copyright ACM and IEEE, +and it may not be used for commercial purposes. + +A somewhat less technical, more leisurely introduction to JPEG can be found in +"The Data Compression Book" by Mark Nelson and Jean-loup Gailly, published by +M&T Books (New York), 2nd ed. 1996, ISBN 1-55851-434-1. This book provides +good explanations and example C code for a multitude of compression methods +including JPEG. It is an excellent source if you are comfortable reading C +code but don't know much about data compression in general. The book's JPEG +sample code is far from industrial-strength, but when you are ready to look +at a full implementation, you've got one here... + +The best currently available description of JPEG is the textbook "JPEG Still +Image Data Compression Standard" by William B. Pennebaker and Joan L. +Mitchell, published by Van Nostrand Reinhold, 1993, ISBN 0-442-01272-1. +Price US$59.95, 638 pp. The book includes the complete text of the ISO JPEG +standards (DIS 10918-1 and draft DIS 10918-2). +Although this is by far the most detailed and comprehensive exposition of +JPEG publicly available, we point out that it is still missing an explanation +of the most essential properties and algorithms of the underlying DCT +technology. +If you think that you know about DCT-based JPEG after reading this book, +then you are in delusion. The real fundamentals and corresponding potential +of DCT-based JPEG are not publicly known so far, and that is the reason for +all the mistaken developments taking place in the image coding domain. + +The original JPEG standard is divided into two parts, Part 1 being the actual +specification, while Part 2 covers compliance testing methods. Part 1 is +titled "Digital Compression and Coding of Continuous-tone Still Images, +Part 1: Requirements and guidelines" and has document numbers ISO/IEC IS +10918-1, ITU-T T.81. Part 2 is titled "Digital Compression and Coding of +Continuous-tone Still Images, Part 2: Compliance testing" and has document +numbers ISO/IEC IS 10918-2, ITU-T T.83. +IJG JPEG 8 introduces an implementation of the JPEG SmartScale extension +which is specified in two documents: A contributed document at ITU and ISO +with title "ITU-T JPEG-Plus Proposal for Extending ITU-T T.81 for Advanced +Image Coding", April 2006, Geneva, Switzerland. The latest version of this +document is Revision 3. And a contributed document ISO/IEC JTC1/SC29/WG1 N +5799 with title "Evolution of JPEG", June/July 2011, Berlin, Germany. + +The JPEG standard does not specify all details of an interchangeable file +format. For the omitted details we follow the "JFIF" conventions, revision +1.02. JFIF 1.02 has been adopted as an Ecma International Technical Report +and thus received a formal publication status. It is available as a free +download in PDF format from +http://www.ecma-international.org/publications/techreports/E-TR-098.htm. +A PostScript version of the JFIF document is available at +http://www.ijg.org/files/jfif.ps.gz. There is also a plain text version at +http://www.ijg.org/files/jfif.txt.gz, but it is missing the figures. + +The TIFF 6.0 file format specification can be obtained by FTP from +ftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz. The JPEG incorporation scheme +found in the TIFF 6.0 spec of 3-June-92 has a number of serious problems. +IJG does not recommend use of the TIFF 6.0 design (TIFF Compression tag 6). +Instead, we recommend the JPEG design proposed by TIFF Technical Note #2 +(Compression tag 7). Copies of this Note can be obtained from +http://www.ijg.org/files/. It is expected that the next revision +of the TIFF spec will replace the 6.0 JPEG design with the Note's design. +Although IJG's own code does not support TIFF/JPEG, the free libtiff library +uses our library to implement TIFF/JPEG per the Note. + + +ARCHIVE LOCATIONS +================= + +The "official" archive site for this software is www.ijg.org. +The most recent released version can always be found there in +directory "files". This particular version will be archived as +http://www.ijg.org/files/jpegsrc.v8d.tar.gz, and in Windows-compatible +"zip" archive format as http://www.ijg.org/files/jpegsr8d.zip. + +The JPEG FAQ (Frequently Asked Questions) article is a source of some +general information about JPEG. +It is available on the World Wide Web at http://www.faqs.org/faqs/jpeg-faq/ +and other news.answers archive sites, including the official news.answers +archive at rtfm.mit.edu: ftp://rtfm.mit.edu/pub/usenet/news.answers/jpeg-faq/. +If you don't have Web or FTP access, send e-mail to mail-server@rtfm.mit.edu +with body + send usenet/news.answers/jpeg-faq/part1 + send usenet/news.answers/jpeg-faq/part2 + + +ACKNOWLEDGMENTS +=============== + +Thank to Juergen Bruder for providing me with a copy of the common DCT +algorithm article, only to find out that I had come to the same result +in a more direct and comprehensible way with a more generative approach. + +Thank to Istvan Sebestyen and Joan L. Mitchell for inviting me to the +ITU JPEG (Study Group 16) meeting in Geneva, Switzerland. + +Thank to Thomas Wiegand and Gary Sullivan for inviting me to the +Joint Video Team (MPEG & ITU) meeting in Geneva, Switzerland. + +Thank to Thomas Richter and Daniel Lee for inviting me to the +ISO/IEC JTC1/SC29/WG1 (also known as JPEG, together with ITU-T SG16) +meeting in Berlin, Germany. + +Thank to John Korejwa and Massimo Ballerini for inviting me to +fruitful consultations in Boston, MA and Milan, Italy. + +Thank to Hendrik Elstner, Roland Fassauer, Simone Zuck, Guenther +Maier-Gerber, Walter Stoeber, Fred Schmitz, and Norbert Braunagel +for corresponding business development. + +Thank to Nico Zschach and Dirk Stelling of the technical support team +at the Digital Images company in Halle for providing me with extra +equipment for configuration tests. + +Thank to Richard F. Lyon (then of Foveon Inc.) for fruitful +communication about JPEG configuration in Sigma Photo Pro software. + +Thank to Andrew Finkenstadt for hosting the ijg.org site. + +Last but not least special thank to Thomas G. Lane for the original +design and development of this singular software package. + + +FILE FORMAT WARS +================ + +The ISO/IEC JTC1/SC29/WG1 standards committee (also known as JPEG, together +with ITU-T SG16) currently promotes different formats containing the name +"JPEG" which is misleading because these formats are incompatible with +original DCT-based JPEG and are based on faulty technologies. +IJG therefore does not and will not support such momentary mistakes +(see REFERENCES). +There exist also distributions under the name "OpenJPEG" promoting such +kind of formats which is misleading because they don't support original +JPEG images. +We have no sympathy for the promotion of inferior formats. Indeed, one of +the original reasons for developing this free software was to help force +convergence on common, interoperable format standards for JPEG files. +Don't use an incompatible file format! +(In any case, our decoder will remain capable of reading existing JPEG +image files indefinitely.) + +Furthermore, the ISO committee pretends to be "responsible for the popular +JPEG" in their public reports which is not true because they don't respond to +actual requirements for the maintenance of the original JPEG specification. + +There are currently distributions in circulation containing the name +"libjpeg" which claim to be a "derivative" or "fork" of the original +libjpeg, but don't have the features and are incompatible with formats +supported by actual IJG libjpeg distributions. Furthermore, they +violate the license conditions as described under LEGAL ISSUES above. +We have no sympathy for the release of misleading and illegal +distributions derived from obsolete code bases. +Don't use an obsolete code base! + + +TO DO +===== + +Version 8 is the first release of a new generation JPEG standard +to overcome the limitations of the original JPEG specification. +More features are being prepared for coming releases... + +Please send bug reports, offers of help, etc. to jpeg-info@jpegclub.org. diff --git a/Source/LibJPEG/ansi2knr.c b/Source/LibJPEG/ansi2knr.c index dcfb5d9..a83ae21 100644 --- a/Source/LibJPEG/ansi2knr.c +++ b/Source/LibJPEG/ansi2knr.c @@ -1,739 +1,739 @@ -/* Copyright (C) 1989, 2000 Aladdin Enterprises. All rights reserved. */ - -/*$Id: ansi2knr.c,v 1.6 2012/01/29 12:23:24 drolon Exp $*/ -/* Convert ANSI C function definitions to K&R ("traditional C") syntax */ - -/* -ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY. No author or distributor accepts responsibility to anyone for the -consequences of using it or for whether it serves any particular purpose or -works at all, unless he says so in writing. Refer to the GNU General Public -License (the "GPL") for full details. - -Everyone is granted permission to copy, modify and redistribute ansi2knr, -but only under the conditions described in the GPL. A copy of this license -is supposed to have been given to you along with ansi2knr so you can know -your rights and responsibilities. It should be in a file named COPYLEFT, -or, if there is no file named COPYLEFT, a file named COPYING. Among other -things, the copyright notice and this notice must be preserved on all -copies. - -We explicitly state here what we believe is already implied by the GPL: if -the ansi2knr program is distributed as a separate set of sources and a -separate executable file which are aggregated on a storage medium together -with another program, this in itself does not bring the other program under -the GPL, nor does the mere fact that such a program or the procedures for -constructing it invoke the ansi2knr executable bring any other part of the -program under the GPL. -*/ - -/* - * Usage: - ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]] - * --filename provides the file name for the #line directive in the output, - * overriding input_file (if present). - * If no input_file is supplied, input is read from stdin. - * If no output_file is supplied, output goes to stdout. - * There are no error messages. - * - * ansi2knr recognizes function definitions by seeing a non-keyword - * identifier at the left margin, followed by a left parenthesis, with a - * right parenthesis as the last character on the line, and with a left - * brace as the first token on the following line (ignoring possible - * intervening comments and/or preprocessor directives), except that a line - * consisting of only - * identifier1(identifier2) - * will not be considered a function definition unless identifier2 is - * the word "void", and a line consisting of - * identifier1(identifier2, <>) - * will not be considered a function definition. - * ansi2knr will recognize a multi-line header provided that no intervening - * line ends with a left or right brace or a semicolon. These algorithms - * ignore whitespace, comments, and preprocessor directives, except that - * the function name must be the first thing on the line. The following - * constructs will confuse it: - * - Any other construct that starts at the left margin and - * follows the above syntax (such as a macro or function call). - * - Some macros that tinker with the syntax of function headers. - */ - -/* - * The original and principal author of ansi2knr is L. Peter Deutsch - * . Other authors are noted in the change history - * that follows (in reverse chronological order): - - lpd 2000-04-12 backs out Eggert's changes because of bugs: - - concatlits didn't declare the type of its bufend argument; - - concatlits didn't recognize when it was inside a comment; - - scanstring could scan backward past the beginning of the string; when - - the check for \ + newline in scanstring was unnecessary. - - 2000-03-05 Paul Eggert - - Add support for concatenated string literals. - * ansi2knr.c (concatlits): New decl. - (main): Invoke concatlits to concatenate string literals. - (scanstring): Handle backslash-newline correctly. Work with - character constants. Fix bug when scanning backwards through - backslash-quote. Check for unterminated strings. - (convert1): Parse character constants, too. - (appendline, concatlits): New functions. - * ansi2knr.1: Document this. - - lpd 1999-08-17 added code to allow preprocessor directives - wherever comments are allowed - lpd 1999-04-12 added minor fixes from Pavel Roskin - for clean compilation with - gcc -W -Wall - lpd 1999-03-22 added hack to recognize lines consisting of - identifier1(identifier2, xxx) as *not* being procedures - lpd 1999-02-03 made indentation of preprocessor commands consistent - lpd 1999-01-28 fixed two bugs: a '/' in an argument list caused an - endless loop; quoted strings within an argument list - confused the parser - lpd 1999-01-24 added a check for write errors on the output, - suggested by Jim Meyering - lpd 1998-11-09 added further hack to recognize identifier(void) - as being a procedure - lpd 1998-10-23 added hack to recognize lines consisting of - identifier1(identifier2) as *not* being procedures - lpd 1997-12-08 made input_file optional; only closes input and/or - output file if not stdin or stdout respectively; prints - usage message on stderr rather than stdout; adds - --filename switch (changes suggested by - ) - lpd 1996-01-21 added code to cope with not HAVE_CONFIG_H and with - compilers that don't understand void, as suggested by - Tom Lane - lpd 1996-01-15 changed to require that the first non-comment token - on the line following a function header be a left brace, - to reduce sensitivity to macros, as suggested by Tom Lane - - lpd 1995-06-22 removed #ifndefs whose sole purpose was to define - undefined preprocessor symbols as 0; changed all #ifdefs - for configuration symbols to #ifs - lpd 1995-04-05 changed copyright notice to make it clear that - including ansi2knr in a program does not bring the entire - program under the GPL - lpd 1994-12-18 added conditionals for systems where ctype macros - don't handle 8-bit characters properly, suggested by - Francois Pinard ; - removed --varargs switch (this is now the default) - lpd 1994-10-10 removed CONFIG_BROKETS conditional - lpd 1994-07-16 added some conditionals to help GNU `configure', - suggested by Francois Pinard ; - properly erase prototype args in function parameters, - contributed by Jim Avera ; - correct error in writeblanks (it shouldn't erase EOLs) - lpd 1989-xx-xx original version - */ - -/* Most of the conditionals here are to make ansi2knr work with */ -/* or without the GNU configure machinery. */ - -#if HAVE_CONFIG_H -# include -#endif - -#include -#include - -#if HAVE_CONFIG_H - -/* - For properly autoconfiguring ansi2knr, use AC_CONFIG_HEADER(config.h). - This will define HAVE_CONFIG_H and so, activate the following lines. - */ - -# if STDC_HEADERS || HAVE_STRING_H -# include -# else -# include -# endif - -#else /* not HAVE_CONFIG_H */ - -/* Otherwise do it the hard way */ - -# ifdef BSD -# include -# else -# ifdef VMS - extern int strlen(), strncmp(); -# else -# include -# endif -# endif - -#endif /* not HAVE_CONFIG_H */ - -#if STDC_HEADERS -# include -#else -/* - malloc and free should be declared in stdlib.h, - but if you've got a K&R compiler, they probably aren't. - */ -# ifdef MSDOS -# include -# else -# ifdef VMS - extern char *malloc(); - extern void free(); -# else - extern char *malloc(); - extern int free(); -# endif -# endif - -#endif - -/* Define NULL (for *very* old compilers). */ -#ifndef NULL -# define NULL (0) -#endif - -/* - * The ctype macros don't always handle 8-bit characters correctly. - * Compensate for this here. - */ -#ifdef isascii -# undef HAVE_ISASCII /* just in case */ -# define HAVE_ISASCII 1 -#else -#endif -#if STDC_HEADERS || !HAVE_ISASCII -# define is_ascii(c) 1 -#else -# define is_ascii(c) isascii(c) -#endif - -#define is_space(c) (is_ascii(c) && isspace(c)) -#define is_alpha(c) (is_ascii(c) && isalpha(c)) -#define is_alnum(c) (is_ascii(c) && isalnum(c)) - -/* Scanning macros */ -#define isidchar(ch) (is_alnum(ch) || (ch) == '_') -#define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_') - -/* Forward references */ -char *ppdirforward(); -char *ppdirbackward(); -char *skipspace(); -char *scanstring(); -int writeblanks(); -int test1(); -int convert1(); - -/* The main program */ -int -main(argc, argv) - int argc; - char *argv[]; -{ FILE *in = stdin; - FILE *out = stdout; - char *filename = 0; - char *program_name = argv[0]; - char *output_name = 0; -#define bufsize 5000 /* arbitrary size */ - char *buf; - char *line; - char *more; - char *usage = - "Usage: ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]\n"; - /* - * In previous versions, ansi2knr recognized a --varargs switch. - * If this switch was supplied, ansi2knr would attempt to convert - * a ... argument to va_alist and va_dcl; if this switch was not - * supplied, ansi2knr would simply drop any such arguments. - * Now, ansi2knr always does this conversion, and we only - * check for this switch for backward compatibility. - */ - int convert_varargs = 1; - int output_error; - - while ( argc > 1 && argv[1][0] == '-' ) { - if ( !strcmp(argv[1], "--varargs") ) { - convert_varargs = 1; - argc--; - argv++; - continue; - } - if ( !strcmp(argv[1], "--filename") && argc > 2 ) { - filename = argv[2]; - argc -= 2; - argv += 2; - continue; - } - fprintf(stderr, "%s: Unrecognized switch: %s\n", program_name, - argv[1]); - fprintf(stderr, usage); - exit(1); - } - switch ( argc ) - { - default: - fprintf(stderr, usage); - exit(0); - case 3: - output_name = argv[2]; - out = fopen(output_name, "w"); - if ( out == NULL ) { - fprintf(stderr, "%s: Cannot open output file %s\n", - program_name, output_name); - exit(1); - } - /* falls through */ - case 2: - in = fopen(argv[1], "r"); - if ( in == NULL ) { - fprintf(stderr, "%s: Cannot open input file %s\n", - program_name, argv[1]); - exit(1); - } - if ( filename == 0 ) - filename = argv[1]; - /* falls through */ - case 1: - break; - } - if ( filename ) - fprintf(out, "#line 1 \"%s\"\n", filename); - buf = malloc(bufsize); - if ( buf == NULL ) - { - fprintf(stderr, "Unable to allocate read buffer!\n"); - exit(1); - } - line = buf; - while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL ) - { -test: line += strlen(line); - switch ( test1(buf) ) - { - case 2: /* a function header */ - convert1(buf, out, 1, convert_varargs); - break; - case 1: /* a function */ - /* Check for a { at the start of the next line. */ - more = ++line; -f: if ( line >= buf + (bufsize - 1) ) /* overflow check */ - goto wl; - if ( fgets(line, (unsigned)(buf + bufsize - line), in) == NULL ) - goto wl; - switch ( *skipspace(ppdirforward(more), 1) ) - { - case '{': - /* Definitely a function header. */ - convert1(buf, out, 0, convert_varargs); - fputs(more, out); - break; - case 0: - /* The next line was blank or a comment: */ - /* keep scanning for a non-comment. */ - line += strlen(line); - goto f; - default: - /* buf isn't a function header, but */ - /* more might be. */ - fputs(buf, out); - strcpy(buf, more); - line = buf; - goto test; - } - break; - case -1: /* maybe the start of a function */ - if ( line != buf + (bufsize - 1) ) /* overflow check */ - continue; - /* falls through */ - default: /* not a function */ -wl: fputs(buf, out); - break; - } - line = buf; - } - if ( line != buf ) - fputs(buf, out); - free(buf); - if ( output_name ) { - output_error = ferror(out); - output_error |= fclose(out); - } else { /* out == stdout */ - fflush(out); - output_error = ferror(out); - } - if ( output_error ) { - fprintf(stderr, "%s: error writing to %s\n", program_name, - (output_name ? output_name : "stdout")); - exit(1); - } - if ( in != stdin ) - fclose(in); - return 0; -} - -/* - * Skip forward or backward over one or more preprocessor directives. - */ -char * -ppdirforward(p) - char *p; -{ - for (; *p == '#'; ++p) { - for (; *p != '\r' && *p != '\n'; ++p) - if (*p == 0) - return p; - if (*p == '\r' && p[1] == '\n') - ++p; - } - return p; -} -char * -ppdirbackward(p, limit) - char *p; - char *limit; -{ - char *np = p; - - for (;; p = --np) { - if (*np == '\n' && np[-1] == '\r') - --np; - for (; np > limit && np[-1] != '\r' && np[-1] != '\n'; --np) - if (np[-1] == 0) - return np; - if (*np != '#') - return p; - } -} - -/* - * Skip over whitespace, comments, and preprocessor directives, - * in either direction. - */ -char * -skipspace(p, dir) - char *p; - int dir; /* 1 for forward, -1 for backward */ -{ - for ( ; ; ) { - while ( is_space(*p) ) - p += dir; - if ( !(*p == '/' && p[dir] == '*') ) - break; - p += dir; p += dir; - while ( !(*p == '*' && p[dir] == '/') ) { - if ( *p == 0 ) - return p; /* multi-line comment?? */ - p += dir; - } - p += dir; p += dir; - } - return p; -} - -/* Scan over a quoted string, in either direction. */ -char * -scanstring(p, dir) - char *p; - int dir; -{ - for (p += dir; ; p += dir) - if (*p == '"' && p[-dir] != '\\') - return p + dir; -} - -/* - * Write blanks over part of a string. - * Don't overwrite end-of-line characters. - */ -int -writeblanks(start, end) - char *start; - char *end; -{ char *p; - for ( p = start; p < end; p++ ) - if ( *p != '\r' && *p != '\n' ) - *p = ' '; - return 0; -} - -/* - * Test whether the string in buf is a function definition. - * The string may contain and/or end with a newline. - * Return as follows: - * 0 - definitely not a function definition; - * 1 - definitely a function definition; - * 2 - definitely a function prototype (NOT USED); - * -1 - may be the beginning of a function definition, - * append another line and look again. - * The reason we don't attempt to convert function prototypes is that - * Ghostscript's declaration-generating macros look too much like - * prototypes, and confuse the algorithms. - */ -int -test1(buf) - char *buf; -{ char *p = buf; - char *bend; - char *endfn; - int contin; - - if ( !isidfirstchar(*p) ) - return 0; /* no name at left margin */ - bend = skipspace(ppdirbackward(buf + strlen(buf) - 1, buf), -1); - switch ( *bend ) - { - case ';': contin = 0 /*2*/; break; - case ')': contin = 1; break; - case '{': return 0; /* not a function */ - case '}': return 0; /* not a function */ - default: contin = -1; - } - while ( isidchar(*p) ) - p++; - endfn = p; - p = skipspace(p, 1); - if ( *p++ != '(' ) - return 0; /* not a function */ - p = skipspace(p, 1); - if ( *p == ')' ) - return 0; /* no parameters */ - /* Check that the apparent function name isn't a keyword. */ - /* We only need to check for keywords that could be followed */ - /* by a left parenthesis (which, unfortunately, is most of them). */ - { static char *words[] = - { "asm", "auto", "case", "char", "const", "double", - "extern", "float", "for", "if", "int", "long", - "register", "return", "short", "signed", "sizeof", - "static", "switch", "typedef", "unsigned", - "void", "volatile", "while", 0 - }; - char **key = words; - char *kp; - unsigned len = endfn - buf; - - while ( (kp = *key) != 0 ) - { if ( strlen(kp) == len && !strncmp(kp, buf, len) ) - return 0; /* name is a keyword */ - key++; - } - } - { - char *id = p; - int len; - /* - * Check for identifier1(identifier2) and not - * identifier1(void), or identifier1(identifier2, xxxx). - */ - - while ( isidchar(*p) ) - p++; - len = p - id; - p = skipspace(p, 1); - if (*p == ',' || - (*p == ')' && (len != 4 || strncmp(id, "void", 4))) - ) - return 0; /* not a function */ - } - /* - * If the last significant character was a ), we need to count - * parentheses, because it might be part of a formal parameter - * that is a procedure. - */ - if (contin > 0) { - int level = 0; - - for (p = skipspace(buf, 1); *p; p = skipspace(p + 1, 1)) - level += (*p == '(' ? 1 : *p == ')' ? -1 : 0); - if (level > 0) - contin = -1; - } - return contin; -} - -/* Convert a recognized function definition or header to K&R syntax. */ -int -convert1(buf, out, header, convert_varargs) - char *buf; - FILE *out; - int header; /* Boolean */ - int convert_varargs; /* Boolean */ -{ char *endfn; - char *p; - /* - * The breaks table contains pointers to the beginning and end - * of each argument. - */ - char **breaks; - unsigned num_breaks = 2; /* for testing */ - char **btop; - char **bp; - char **ap; - char *vararg = 0; - - /* Pre-ANSI implementations don't agree on whether strchr */ - /* is called strchr or index, so we open-code it here. */ - for ( endfn = buf; *(endfn++) != '('; ) - ; -top: p = endfn; - breaks = (char **)malloc(sizeof(char *) * num_breaks * 2); - if ( breaks == NULL ) - { /* Couldn't allocate break table, give up */ - fprintf(stderr, "Unable to allocate break table!\n"); - fputs(buf, out); - return -1; - } - btop = breaks + num_breaks * 2 - 2; - bp = breaks; - /* Parse the argument list */ - do - { int level = 0; - char *lp = NULL; - char *rp = NULL; - char *end = NULL; - - if ( bp >= btop ) - { /* Filled up break table. */ - /* Allocate a bigger one and start over. */ - free((char *)breaks); - num_breaks <<= 1; - goto top; - } - *bp++ = p; - /* Find the end of the argument */ - for ( ; end == NULL; p++ ) - { switch(*p) - { - case ',': - if ( !level ) end = p; - break; - case '(': - if ( !level ) lp = p; - level++; - break; - case ')': - if ( --level < 0 ) end = p; - else rp = p; - break; - case '/': - if (p[1] == '*') - p = skipspace(p, 1) - 1; - break; - case '"': - p = scanstring(p, 1) - 1; - break; - default: - ; - } - } - /* Erase any embedded prototype parameters. */ - if ( lp && rp ) - writeblanks(lp + 1, rp); - p--; /* back up over terminator */ - /* Find the name being declared. */ - /* This is complicated because of procedure and */ - /* array modifiers. */ - for ( ; ; ) - { p = skipspace(p - 1, -1); - switch ( *p ) - { - case ']': /* skip array dimension(s) */ - case ')': /* skip procedure args OR name */ - { int level = 1; - while ( level ) - switch ( *--p ) - { - case ']': case ')': - level++; - break; - case '[': case '(': - level--; - break; - case '/': - if (p > buf && p[-1] == '*') - p = skipspace(p, -1) + 1; - break; - case '"': - p = scanstring(p, -1) + 1; - break; - default: ; - } - } - if ( *p == '(' && *skipspace(p + 1, 1) == '*' ) - { /* We found the name being declared */ - while ( !isidfirstchar(*p) ) - p = skipspace(p, 1) + 1; - goto found; - } - break; - default: - goto found; - } - } -found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' ) - { if ( convert_varargs ) - { *bp++ = "va_alist"; - vararg = p-2; - } - else - { p++; - if ( bp == breaks + 1 ) /* sole argument */ - writeblanks(breaks[0], p); - else - writeblanks(bp[-1] - 1, p); - bp--; - } - } - else - { while ( isidchar(*p) ) p--; - *bp++ = p+1; - } - p = end; - } - while ( *p++ == ',' ); - *bp = p; - /* Make a special check for 'void' arglist */ - if ( bp == breaks+2 ) - { p = skipspace(breaks[0], 1); - if ( !strncmp(p, "void", 4) ) - { p = skipspace(p+4, 1); - if ( p == breaks[2] - 1 ) - { bp = breaks; /* yup, pretend arglist is empty */ - writeblanks(breaks[0], p + 1); - } - } - } - /* Put out the function name and left parenthesis. */ - p = buf; - while ( p != endfn ) putc(*p, out), p++; - /* Put out the declaration. */ - if ( header ) - { fputs(");", out); - for ( p = breaks[0]; *p; p++ ) - if ( *p == '\r' || *p == '\n' ) - putc(*p, out); - } - else - { for ( ap = breaks+1; ap < bp; ap += 2 ) - { p = *ap; - while ( isidchar(*p) ) - putc(*p, out), p++; - if ( ap < bp - 1 ) - fputs(", ", out); - } - fputs(") ", out); - /* Put out the argument declarations */ - for ( ap = breaks+2; ap <= bp; ap += 2 ) - (*ap)[-1] = ';'; - if ( vararg != 0 ) - { *vararg = 0; - fputs(breaks[0], out); /* any prior args */ - fputs("va_dcl", out); /* the final arg */ - fputs(bp[0], out); - } - else - fputs(breaks[0], out); - } - free((char *)breaks); - return 0; -} +/* Copyright (C) 1989, 2000 Aladdin Enterprises. All rights reserved. */ + +/*$Id: ansi2knr.c,v 1.6 2012/01/29 12:23:24 drolon Exp $*/ +/* Convert ANSI C function definitions to K&R ("traditional C") syntax */ + +/* +ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY. No author or distributor accepts responsibility to anyone for the +consequences of using it or for whether it serves any particular purpose or +works at all, unless he says so in writing. Refer to the GNU General Public +License (the "GPL") for full details. + +Everyone is granted permission to copy, modify and redistribute ansi2knr, +but only under the conditions described in the GPL. A copy of this license +is supposed to have been given to you along with ansi2knr so you can know +your rights and responsibilities. It should be in a file named COPYLEFT, +or, if there is no file named COPYLEFT, a file named COPYING. Among other +things, the copyright notice and this notice must be preserved on all +copies. + +We explicitly state here what we believe is already implied by the GPL: if +the ansi2knr program is distributed as a separate set of sources and a +separate executable file which are aggregated on a storage medium together +with another program, this in itself does not bring the other program under +the GPL, nor does the mere fact that such a program or the procedures for +constructing it invoke the ansi2knr executable bring any other part of the +program under the GPL. +*/ + +/* + * Usage: + ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]] + * --filename provides the file name for the #line directive in the output, + * overriding input_file (if present). + * If no input_file is supplied, input is read from stdin. + * If no output_file is supplied, output goes to stdout. + * There are no error messages. + * + * ansi2knr recognizes function definitions by seeing a non-keyword + * identifier at the left margin, followed by a left parenthesis, with a + * right parenthesis as the last character on the line, and with a left + * brace as the first token on the following line (ignoring possible + * intervening comments and/or preprocessor directives), except that a line + * consisting of only + * identifier1(identifier2) + * will not be considered a function definition unless identifier2 is + * the word "void", and a line consisting of + * identifier1(identifier2, <>) + * will not be considered a function definition. + * ansi2knr will recognize a multi-line header provided that no intervening + * line ends with a left or right brace or a semicolon. These algorithms + * ignore whitespace, comments, and preprocessor directives, except that + * the function name must be the first thing on the line. The following + * constructs will confuse it: + * - Any other construct that starts at the left margin and + * follows the above syntax (such as a macro or function call). + * - Some macros that tinker with the syntax of function headers. + */ + +/* + * The original and principal author of ansi2knr is L. Peter Deutsch + * . Other authors are noted in the change history + * that follows (in reverse chronological order): + + lpd 2000-04-12 backs out Eggert's changes because of bugs: + - concatlits didn't declare the type of its bufend argument; + - concatlits didn't recognize when it was inside a comment; + - scanstring could scan backward past the beginning of the string; when + - the check for \ + newline in scanstring was unnecessary. + + 2000-03-05 Paul Eggert + + Add support for concatenated string literals. + * ansi2knr.c (concatlits): New decl. + (main): Invoke concatlits to concatenate string literals. + (scanstring): Handle backslash-newline correctly. Work with + character constants. Fix bug when scanning backwards through + backslash-quote. Check for unterminated strings. + (convert1): Parse character constants, too. + (appendline, concatlits): New functions. + * ansi2knr.1: Document this. + + lpd 1999-08-17 added code to allow preprocessor directives + wherever comments are allowed + lpd 1999-04-12 added minor fixes from Pavel Roskin + for clean compilation with + gcc -W -Wall + lpd 1999-03-22 added hack to recognize lines consisting of + identifier1(identifier2, xxx) as *not* being procedures + lpd 1999-02-03 made indentation of preprocessor commands consistent + lpd 1999-01-28 fixed two bugs: a '/' in an argument list caused an + endless loop; quoted strings within an argument list + confused the parser + lpd 1999-01-24 added a check for write errors on the output, + suggested by Jim Meyering + lpd 1998-11-09 added further hack to recognize identifier(void) + as being a procedure + lpd 1998-10-23 added hack to recognize lines consisting of + identifier1(identifier2) as *not* being procedures + lpd 1997-12-08 made input_file optional; only closes input and/or + output file if not stdin or stdout respectively; prints + usage message on stderr rather than stdout; adds + --filename switch (changes suggested by + ) + lpd 1996-01-21 added code to cope with not HAVE_CONFIG_H and with + compilers that don't understand void, as suggested by + Tom Lane + lpd 1996-01-15 changed to require that the first non-comment token + on the line following a function header be a left brace, + to reduce sensitivity to macros, as suggested by Tom Lane + + lpd 1995-06-22 removed #ifndefs whose sole purpose was to define + undefined preprocessor symbols as 0; changed all #ifdefs + for configuration symbols to #ifs + lpd 1995-04-05 changed copyright notice to make it clear that + including ansi2knr in a program does not bring the entire + program under the GPL + lpd 1994-12-18 added conditionals for systems where ctype macros + don't handle 8-bit characters properly, suggested by + Francois Pinard ; + removed --varargs switch (this is now the default) + lpd 1994-10-10 removed CONFIG_BROKETS conditional + lpd 1994-07-16 added some conditionals to help GNU `configure', + suggested by Francois Pinard ; + properly erase prototype args in function parameters, + contributed by Jim Avera ; + correct error in writeblanks (it shouldn't erase EOLs) + lpd 1989-xx-xx original version + */ + +/* Most of the conditionals here are to make ansi2knr work with */ +/* or without the GNU configure machinery. */ + +#if HAVE_CONFIG_H +# include +#endif + +#include +#include + +#if HAVE_CONFIG_H + +/* + For properly autoconfiguring ansi2knr, use AC_CONFIG_HEADER(config.h). + This will define HAVE_CONFIG_H and so, activate the following lines. + */ + +# if STDC_HEADERS || HAVE_STRING_H +# include +# else +# include +# endif + +#else /* not HAVE_CONFIG_H */ + +/* Otherwise do it the hard way */ + +# ifdef BSD +# include +# else +# ifdef VMS + extern int strlen(), strncmp(); +# else +# include +# endif +# endif + +#endif /* not HAVE_CONFIG_H */ + +#if STDC_HEADERS +# include +#else +/* + malloc and free should be declared in stdlib.h, + but if you've got a K&R compiler, they probably aren't. + */ +# ifdef MSDOS +# include +# else +# ifdef VMS + extern char *malloc(); + extern void free(); +# else + extern char *malloc(); + extern int free(); +# endif +# endif + +#endif + +/* Define NULL (for *very* old compilers). */ +#ifndef NULL +# define NULL (0) +#endif + +/* + * The ctype macros don't always handle 8-bit characters correctly. + * Compensate for this here. + */ +#ifdef isascii +# undef HAVE_ISASCII /* just in case */ +# define HAVE_ISASCII 1 +#else +#endif +#if STDC_HEADERS || !HAVE_ISASCII +# define is_ascii(c) 1 +#else +# define is_ascii(c) isascii(c) +#endif + +#define is_space(c) (is_ascii(c) && isspace(c)) +#define is_alpha(c) (is_ascii(c) && isalpha(c)) +#define is_alnum(c) (is_ascii(c) && isalnum(c)) + +/* Scanning macros */ +#define isidchar(ch) (is_alnum(ch) || (ch) == '_') +#define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_') + +/* Forward references */ +char *ppdirforward(); +char *ppdirbackward(); +char *skipspace(); +char *scanstring(); +int writeblanks(); +int test1(); +int convert1(); + +/* The main program */ +int +main(argc, argv) + int argc; + char *argv[]; +{ FILE *in = stdin; + FILE *out = stdout; + char *filename = 0; + char *program_name = argv[0]; + char *output_name = 0; +#define bufsize 5000 /* arbitrary size */ + char *buf; + char *line; + char *more; + char *usage = + "Usage: ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]\n"; + /* + * In previous versions, ansi2knr recognized a --varargs switch. + * If this switch was supplied, ansi2knr would attempt to convert + * a ... argument to va_alist and va_dcl; if this switch was not + * supplied, ansi2knr would simply drop any such arguments. + * Now, ansi2knr always does this conversion, and we only + * check for this switch for backward compatibility. + */ + int convert_varargs = 1; + int output_error; + + while ( argc > 1 && argv[1][0] == '-' ) { + if ( !strcmp(argv[1], "--varargs") ) { + convert_varargs = 1; + argc--; + argv++; + continue; + } + if ( !strcmp(argv[1], "--filename") && argc > 2 ) { + filename = argv[2]; + argc -= 2; + argv += 2; + continue; + } + fprintf(stderr, "%s: Unrecognized switch: %s\n", program_name, + argv[1]); + fprintf(stderr, usage); + exit(1); + } + switch ( argc ) + { + default: + fprintf(stderr, usage); + exit(0); + case 3: + output_name = argv[2]; + out = fopen(output_name, "w"); + if ( out == NULL ) { + fprintf(stderr, "%s: Cannot open output file %s\n", + program_name, output_name); + exit(1); + } + /* falls through */ + case 2: + in = fopen(argv[1], "r"); + if ( in == NULL ) { + fprintf(stderr, "%s: Cannot open input file %s\n", + program_name, argv[1]); + exit(1); + } + if ( filename == 0 ) + filename = argv[1]; + /* falls through */ + case 1: + break; + } + if ( filename ) + fprintf(out, "#line 1 \"%s\"\n", filename); + buf = malloc(bufsize); + if ( buf == NULL ) + { + fprintf(stderr, "Unable to allocate read buffer!\n"); + exit(1); + } + line = buf; + while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL ) + { +test: line += strlen(line); + switch ( test1(buf) ) + { + case 2: /* a function header */ + convert1(buf, out, 1, convert_varargs); + break; + case 1: /* a function */ + /* Check for a { at the start of the next line. */ + more = ++line; +f: if ( line >= buf + (bufsize - 1) ) /* overflow check */ + goto wl; + if ( fgets(line, (unsigned)(buf + bufsize - line), in) == NULL ) + goto wl; + switch ( *skipspace(ppdirforward(more), 1) ) + { + case '{': + /* Definitely a function header. */ + convert1(buf, out, 0, convert_varargs); + fputs(more, out); + break; + case 0: + /* The next line was blank or a comment: */ + /* keep scanning for a non-comment. */ + line += strlen(line); + goto f; + default: + /* buf isn't a function header, but */ + /* more might be. */ + fputs(buf, out); + strcpy(buf, more); + line = buf; + goto test; + } + break; + case -1: /* maybe the start of a function */ + if ( line != buf + (bufsize - 1) ) /* overflow check */ + continue; + /* falls through */ + default: /* not a function */ +wl: fputs(buf, out); + break; + } + line = buf; + } + if ( line != buf ) + fputs(buf, out); + free(buf); + if ( output_name ) { + output_error = ferror(out); + output_error |= fclose(out); + } else { /* out == stdout */ + fflush(out); + output_error = ferror(out); + } + if ( output_error ) { + fprintf(stderr, "%s: error writing to %s\n", program_name, + (output_name ? output_name : "stdout")); + exit(1); + } + if ( in != stdin ) + fclose(in); + return 0; +} + +/* + * Skip forward or backward over one or more preprocessor directives. + */ +char * +ppdirforward(p) + char *p; +{ + for (; *p == '#'; ++p) { + for (; *p != '\r' && *p != '\n'; ++p) + if (*p == 0) + return p; + if (*p == '\r' && p[1] == '\n') + ++p; + } + return p; +} +char * +ppdirbackward(p, limit) + char *p; + char *limit; +{ + char *np = p; + + for (;; p = --np) { + if (*np == '\n' && np[-1] == '\r') + --np; + for (; np > limit && np[-1] != '\r' && np[-1] != '\n'; --np) + if (np[-1] == 0) + return np; + if (*np != '#') + return p; + } +} + +/* + * Skip over whitespace, comments, and preprocessor directives, + * in either direction. + */ +char * +skipspace(p, dir) + char *p; + int dir; /* 1 for forward, -1 for backward */ +{ + for ( ; ; ) { + while ( is_space(*p) ) + p += dir; + if ( !(*p == '/' && p[dir] == '*') ) + break; + p += dir; p += dir; + while ( !(*p == '*' && p[dir] == '/') ) { + if ( *p == 0 ) + return p; /* multi-line comment?? */ + p += dir; + } + p += dir; p += dir; + } + return p; +} + +/* Scan over a quoted string, in either direction. */ +char * +scanstring(p, dir) + char *p; + int dir; +{ + for (p += dir; ; p += dir) + if (*p == '"' && p[-dir] != '\\') + return p + dir; +} + +/* + * Write blanks over part of a string. + * Don't overwrite end-of-line characters. + */ +int +writeblanks(start, end) + char *start; + char *end; +{ char *p; + for ( p = start; p < end; p++ ) + if ( *p != '\r' && *p != '\n' ) + *p = ' '; + return 0; +} + +/* + * Test whether the string in buf is a function definition. + * The string may contain and/or end with a newline. + * Return as follows: + * 0 - definitely not a function definition; + * 1 - definitely a function definition; + * 2 - definitely a function prototype (NOT USED); + * -1 - may be the beginning of a function definition, + * append another line and look again. + * The reason we don't attempt to convert function prototypes is that + * Ghostscript's declaration-generating macros look too much like + * prototypes, and confuse the algorithms. + */ +int +test1(buf) + char *buf; +{ char *p = buf; + char *bend; + char *endfn; + int contin; + + if ( !isidfirstchar(*p) ) + return 0; /* no name at left margin */ + bend = skipspace(ppdirbackward(buf + strlen(buf) - 1, buf), -1); + switch ( *bend ) + { + case ';': contin = 0 /*2*/; break; + case ')': contin = 1; break; + case '{': return 0; /* not a function */ + case '}': return 0; /* not a function */ + default: contin = -1; + } + while ( isidchar(*p) ) + p++; + endfn = p; + p = skipspace(p, 1); + if ( *p++ != '(' ) + return 0; /* not a function */ + p = skipspace(p, 1); + if ( *p == ')' ) + return 0; /* no parameters */ + /* Check that the apparent function name isn't a keyword. */ + /* We only need to check for keywords that could be followed */ + /* by a left parenthesis (which, unfortunately, is most of them). */ + { static char *words[] = + { "asm", "auto", "case", "char", "const", "double", + "extern", "float", "for", "if", "int", "long", + "register", "return", "short", "signed", "sizeof", + "static", "switch", "typedef", "unsigned", + "void", "volatile", "while", 0 + }; + char **key = words; + char *kp; + unsigned len = endfn - buf; + + while ( (kp = *key) != 0 ) + { if ( strlen(kp) == len && !strncmp(kp, buf, len) ) + return 0; /* name is a keyword */ + key++; + } + } + { + char *id = p; + int len; + /* + * Check for identifier1(identifier2) and not + * identifier1(void), or identifier1(identifier2, xxxx). + */ + + while ( isidchar(*p) ) + p++; + len = p - id; + p = skipspace(p, 1); + if (*p == ',' || + (*p == ')' && (len != 4 || strncmp(id, "void", 4))) + ) + return 0; /* not a function */ + } + /* + * If the last significant character was a ), we need to count + * parentheses, because it might be part of a formal parameter + * that is a procedure. + */ + if (contin > 0) { + int level = 0; + + for (p = skipspace(buf, 1); *p; p = skipspace(p + 1, 1)) + level += (*p == '(' ? 1 : *p == ')' ? -1 : 0); + if (level > 0) + contin = -1; + } + return contin; +} + +/* Convert a recognized function definition or header to K&R syntax. */ +int +convert1(buf, out, header, convert_varargs) + char *buf; + FILE *out; + int header; /* Boolean */ + int convert_varargs; /* Boolean */ +{ char *endfn; + char *p; + /* + * The breaks table contains pointers to the beginning and end + * of each argument. + */ + char **breaks; + unsigned num_breaks = 2; /* for testing */ + char **btop; + char **bp; + char **ap; + char *vararg = 0; + + /* Pre-ANSI implementations don't agree on whether strchr */ + /* is called strchr or index, so we open-code it here. */ + for ( endfn = buf; *(endfn++) != '('; ) + ; +top: p = endfn; + breaks = (char **)malloc(sizeof(char *) * num_breaks * 2); + if ( breaks == NULL ) + { /* Couldn't allocate break table, give up */ + fprintf(stderr, "Unable to allocate break table!\n"); + fputs(buf, out); + return -1; + } + btop = breaks + num_breaks * 2 - 2; + bp = breaks; + /* Parse the argument list */ + do + { int level = 0; + char *lp = NULL; + char *rp = NULL; + char *end = NULL; + + if ( bp >= btop ) + { /* Filled up break table. */ + /* Allocate a bigger one and start over. */ + free((char *)breaks); + num_breaks <<= 1; + goto top; + } + *bp++ = p; + /* Find the end of the argument */ + for ( ; end == NULL; p++ ) + { switch(*p) + { + case ',': + if ( !level ) end = p; + break; + case '(': + if ( !level ) lp = p; + level++; + break; + case ')': + if ( --level < 0 ) end = p; + else rp = p; + break; + case '/': + if (p[1] == '*') + p = skipspace(p, 1) - 1; + break; + case '"': + p = scanstring(p, 1) - 1; + break; + default: + ; + } + } + /* Erase any embedded prototype parameters. */ + if ( lp && rp ) + writeblanks(lp + 1, rp); + p--; /* back up over terminator */ + /* Find the name being declared. */ + /* This is complicated because of procedure and */ + /* array modifiers. */ + for ( ; ; ) + { p = skipspace(p - 1, -1); + switch ( *p ) + { + case ']': /* skip array dimension(s) */ + case ')': /* skip procedure args OR name */ + { int level = 1; + while ( level ) + switch ( *--p ) + { + case ']': case ')': + level++; + break; + case '[': case '(': + level--; + break; + case '/': + if (p > buf && p[-1] == '*') + p = skipspace(p, -1) + 1; + break; + case '"': + p = scanstring(p, -1) + 1; + break; + default: ; + } + } + if ( *p == '(' && *skipspace(p + 1, 1) == '*' ) + { /* We found the name being declared */ + while ( !isidfirstchar(*p) ) + p = skipspace(p, 1) + 1; + goto found; + } + break; + default: + goto found; + } + } +found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' ) + { if ( convert_varargs ) + { *bp++ = "va_alist"; + vararg = p-2; + } + else + { p++; + if ( bp == breaks + 1 ) /* sole argument */ + writeblanks(breaks[0], p); + else + writeblanks(bp[-1] - 1, p); + bp--; + } + } + else + { while ( isidchar(*p) ) p--; + *bp++ = p+1; + } + p = end; + } + while ( *p++ == ',' ); + *bp = p; + /* Make a special check for 'void' arglist */ + if ( bp == breaks+2 ) + { p = skipspace(breaks[0], 1); + if ( !strncmp(p, "void", 4) ) + { p = skipspace(p+4, 1); + if ( p == breaks[2] - 1 ) + { bp = breaks; /* yup, pretend arglist is empty */ + writeblanks(breaks[0], p + 1); + } + } + } + /* Put out the function name and left parenthesis. */ + p = buf; + while ( p != endfn ) putc(*p, out), p++; + /* Put out the declaration. */ + if ( header ) + { fputs(");", out); + for ( p = breaks[0]; *p; p++ ) + if ( *p == '\r' || *p == '\n' ) + putc(*p, out); + } + else + { for ( ap = breaks+1; ap < bp; ap += 2 ) + { p = *ap; + while ( isidchar(*p) ) + putc(*p, out), p++; + if ( ap < bp - 1 ) + fputs(", ", out); + } + fputs(") ", out); + /* Put out the argument declarations */ + for ( ap = breaks+2; ap <= bp; ap += 2 ) + (*ap)[-1] = ';'; + if ( vararg != 0 ) + { *vararg = 0; + fputs(breaks[0], out); /* any prior args */ + fputs("va_dcl", out); /* the final arg */ + fputs(bp[0], out); + } + else + fputs(breaks[0], out); + } + free((char *)breaks); + return 0; +} diff --git a/Source/LibJPEG/cdjpeg.c b/Source/LibJPEG/cdjpeg.c index 89fe633..b6250ff 100644 --- a/Source/LibJPEG/cdjpeg.c +++ b/Source/LibJPEG/cdjpeg.c @@ -1,181 +1,181 @@ -/* - * cdjpeg.c - * - * Copyright (C) 1991-1997, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains common support routines used by the IJG application - * programs (cjpeg, djpeg, jpegtran). - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ -#include /* to declare isupper(), tolower() */ -#ifdef NEED_SIGNAL_CATCHER -#include /* to declare signal() */ -#endif -#ifdef USE_SETMODE -#include /* to declare setmode()'s parameter macros */ -/* If you have setmode() but not , just delete this line: */ -#include /* to declare setmode() */ -#endif - - -/* - * Signal catcher to ensure that temporary files are removed before aborting. - * NB: for Amiga Manx C this is actually a global routine named _abort(); - * we put "#define signal_catcher _abort" in jconfig.h. Talk about bogus... - */ - -#ifdef NEED_SIGNAL_CATCHER - -static j_common_ptr sig_cinfo; - -void /* must be global for Manx C */ -signal_catcher (int signum) -{ - if (sig_cinfo != NULL) { - if (sig_cinfo->err != NULL) /* turn off trace output */ - sig_cinfo->err->trace_level = 0; - jpeg_destroy(sig_cinfo); /* clean up memory allocation & temp files */ - } - exit(EXIT_FAILURE); -} - - -GLOBAL(void) -enable_signal_catcher (j_common_ptr cinfo) -{ - sig_cinfo = cinfo; -#ifdef SIGINT /* not all systems have SIGINT */ - signal(SIGINT, signal_catcher); -#endif -#ifdef SIGTERM /* not all systems have SIGTERM */ - signal(SIGTERM, signal_catcher); -#endif -} - -#endif - - -/* - * Optional progress monitor: display a percent-done figure on stderr. - */ - -#ifdef PROGRESS_REPORT - -METHODDEF(void) -progress_monitor (j_common_ptr cinfo) -{ - cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress; - int total_passes = prog->pub.total_passes + prog->total_extra_passes; - int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit); - - if (percent_done != prog->percent_done) { - prog->percent_done = percent_done; - if (total_passes > 1) { - fprintf(stderr, "\rPass %d/%d: %3d%% ", - prog->pub.completed_passes + prog->completed_extra_passes + 1, - total_passes, percent_done); - } else { - fprintf(stderr, "\r %3d%% ", percent_done); - } - fflush(stderr); - } -} - - -GLOBAL(void) -start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress) -{ - /* Enable progress display, unless trace output is on */ - if (cinfo->err->trace_level == 0) { - progress->pub.progress_monitor = progress_monitor; - progress->completed_extra_passes = 0; - progress->total_extra_passes = 0; - progress->percent_done = -1; - cinfo->progress = &progress->pub; - } -} - - -GLOBAL(void) -end_progress_monitor (j_common_ptr cinfo) -{ - /* Clear away progress display */ - if (cinfo->err->trace_level == 0) { - fprintf(stderr, "\r \r"); - fflush(stderr); - } -} - -#endif - - -/* - * Case-insensitive matching of possibly-abbreviated keyword switches. - * keyword is the constant keyword (must be lower case already), - * minchars is length of minimum legal abbreviation. - */ - -GLOBAL(boolean) -keymatch (char * arg, const char * keyword, int minchars) -{ - register int ca, ck; - register int nmatched = 0; - - while ((ca = *arg++) != '\0') { - if ((ck = *keyword++) == '\0') - return FALSE; /* arg longer than keyword, no good */ - if (isupper(ca)) /* force arg to lcase (assume ck is already) */ - ca = tolower(ca); - if (ca != ck) - return FALSE; /* no good */ - nmatched++; /* count matched characters */ - } - /* reached end of argument; fail if it's too short for unique abbrev */ - if (nmatched < minchars) - return FALSE; - return TRUE; /* A-OK */ -} - - -/* - * Routines to establish binary I/O mode for stdin and stdout. - * Non-Unix systems often require some hacking to get out of text mode. - */ - -GLOBAL(FILE *) -read_stdin (void) -{ - FILE * input_file = stdin; - -#ifdef USE_SETMODE /* need to hack file mode? */ - setmode(fileno(stdin), O_BINARY); -#endif -#ifdef USE_FDOPEN /* need to re-open in binary mode? */ - if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) { - fprintf(stderr, "Cannot reopen stdin\n"); - exit(EXIT_FAILURE); - } -#endif - return input_file; -} - - -GLOBAL(FILE *) -write_stdout (void) -{ - FILE * output_file = stdout; - -#ifdef USE_SETMODE /* need to hack file mode? */ - setmode(fileno(stdout), O_BINARY); -#endif -#ifdef USE_FDOPEN /* need to re-open in binary mode? */ - if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) { - fprintf(stderr, "Cannot reopen stdout\n"); - exit(EXIT_FAILURE); - } -#endif - return output_file; -} +/* + * cdjpeg.c + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains common support routines used by the IJG application + * programs (cjpeg, djpeg, jpegtran). + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ +#include /* to declare isupper(), tolower() */ +#ifdef NEED_SIGNAL_CATCHER +#include /* to declare signal() */ +#endif +#ifdef USE_SETMODE +#include /* to declare setmode()'s parameter macros */ +/* If you have setmode() but not , just delete this line: */ +#include /* to declare setmode() */ +#endif + + +/* + * Signal catcher to ensure that temporary files are removed before aborting. + * NB: for Amiga Manx C this is actually a global routine named _abort(); + * we put "#define signal_catcher _abort" in jconfig.h. Talk about bogus... + */ + +#ifdef NEED_SIGNAL_CATCHER + +static j_common_ptr sig_cinfo; + +void /* must be global for Manx C */ +signal_catcher (int signum) +{ + if (sig_cinfo != NULL) { + if (sig_cinfo->err != NULL) /* turn off trace output */ + sig_cinfo->err->trace_level = 0; + jpeg_destroy(sig_cinfo); /* clean up memory allocation & temp files */ + } + exit(EXIT_FAILURE); +} + + +GLOBAL(void) +enable_signal_catcher (j_common_ptr cinfo) +{ + sig_cinfo = cinfo; +#ifdef SIGINT /* not all systems have SIGINT */ + signal(SIGINT, signal_catcher); +#endif +#ifdef SIGTERM /* not all systems have SIGTERM */ + signal(SIGTERM, signal_catcher); +#endif +} + +#endif + + +/* + * Optional progress monitor: display a percent-done figure on stderr. + */ + +#ifdef PROGRESS_REPORT + +METHODDEF(void) +progress_monitor (j_common_ptr cinfo) +{ + cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress; + int total_passes = prog->pub.total_passes + prog->total_extra_passes; + int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit); + + if (percent_done != prog->percent_done) { + prog->percent_done = percent_done; + if (total_passes > 1) { + fprintf(stderr, "\rPass %d/%d: %3d%% ", + prog->pub.completed_passes + prog->completed_extra_passes + 1, + total_passes, percent_done); + } else { + fprintf(stderr, "\r %3d%% ", percent_done); + } + fflush(stderr); + } +} + + +GLOBAL(void) +start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress) +{ + /* Enable progress display, unless trace output is on */ + if (cinfo->err->trace_level == 0) { + progress->pub.progress_monitor = progress_monitor; + progress->completed_extra_passes = 0; + progress->total_extra_passes = 0; + progress->percent_done = -1; + cinfo->progress = &progress->pub; + } +} + + +GLOBAL(void) +end_progress_monitor (j_common_ptr cinfo) +{ + /* Clear away progress display */ + if (cinfo->err->trace_level == 0) { + fprintf(stderr, "\r \r"); + fflush(stderr); + } +} + +#endif + + +/* + * Case-insensitive matching of possibly-abbreviated keyword switches. + * keyword is the constant keyword (must be lower case already), + * minchars is length of minimum legal abbreviation. + */ + +GLOBAL(boolean) +keymatch (char * arg, const char * keyword, int minchars) +{ + register int ca, ck; + register int nmatched = 0; + + while ((ca = *arg++) != '\0') { + if ((ck = *keyword++) == '\0') + return FALSE; /* arg longer than keyword, no good */ + if (isupper(ca)) /* force arg to lcase (assume ck is already) */ + ca = tolower(ca); + if (ca != ck) + return FALSE; /* no good */ + nmatched++; /* count matched characters */ + } + /* reached end of argument; fail if it's too short for unique abbrev */ + if (nmatched < minchars) + return FALSE; + return TRUE; /* A-OK */ +} + + +/* + * Routines to establish binary I/O mode for stdin and stdout. + * Non-Unix systems often require some hacking to get out of text mode. + */ + +GLOBAL(FILE *) +read_stdin (void) +{ + FILE * input_file = stdin; + +#ifdef USE_SETMODE /* need to hack file mode? */ + setmode(fileno(stdin), O_BINARY); +#endif +#ifdef USE_FDOPEN /* need to re-open in binary mode? */ + if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) { + fprintf(stderr, "Cannot reopen stdin\n"); + exit(EXIT_FAILURE); + } +#endif + return input_file; +} + + +GLOBAL(FILE *) +write_stdout (void) +{ + FILE * output_file = stdout; + +#ifdef USE_SETMODE /* need to hack file mode? */ + setmode(fileno(stdout), O_BINARY); +#endif +#ifdef USE_FDOPEN /* need to re-open in binary mode? */ + if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) { + fprintf(stderr, "Cannot reopen stdout\n"); + exit(EXIT_FAILURE); + } +#endif + return output_file; +} diff --git a/Source/LibJPEG/change.log b/Source/LibJPEG/change.log index ce71abd..729bca6 100644 --- a/Source/LibJPEG/change.log +++ b/Source/LibJPEG/change.log @@ -1,346 +1,346 @@ -CHANGE LOG for Independent JPEG Group's JPEG software - - -Version 8d 15-Jan-2012 ------------------------ - -Add cjpeg -rgb option to create RGB JPEG files. -Using this switch suppresses the conversion from RGB -colorspace input to the default YCbCr JPEG colorspace. -This feature allows true lossless JPEG coding of RGB color images. -The recommended command for this purpose is currently -cjpeg -rgb -block 1 -arithmetic. -SmartScale capable decoder (introduced with IJG JPEG 8) required. -Thank to Michael Koch for the initial suggestion. - -Add option to disable the region adjustment in the transupp crop code. -Thank to Jeffrey Friedl for the suggestion. - -Thank to Richard Jones and Edd Dawson for various minor corrections. - -Thank to Akim Demaille for configure.ac cleanup. - - -Version 8c 16-Jan-2011 ------------------------ - -Add option to compression library and cjpeg (-block N) to use -different DCT block size. -All N from 1 to 16 are possible. Default is 8 (baseline format). -Larger values produce higher compression, -smaller values produce higher quality. -SmartScale capable decoder (introduced with IJG JPEG 8) required. - - -Version 8b 16-May-2010 ------------------------ - -Repair problem in new memory source manager with corrupt JPEG data. -Thank to Ted Campbell and Samuel Chun for the report. - -Repair problem in Makefile.am test target. -Thank to anonymous user for the report. - -Support MinGW installation with automatic configure. -Thank to Volker Grabsch for the suggestion. - - -Version 8a 28-Feb-2010 ------------------------ - -Writing tables-only datastreams via jpeg_write_tables works again. - -Support 32-bit BMPs (RGB image with Alpha channel) for read in cjpeg. -Thank to Brett Blackham for the suggestion. - -Improve accuracy in floating point IDCT calculation. -Thank to Robert Hooke for the hint. - - -Version 8 10-Jan-2010 ----------------------- - -jpegtran now supports the same -scale option as djpeg for "lossless" resize. -An implementation of the JPEG SmartScale extension is required for this -feature. A (draft) specification of the JPEG SmartScale extension is -available as a contributed document at ITU and ISO. Revision 2 or later -of the document is required (latest document version is Revision 3). -The SmartScale extension will enable more features beside lossless resize -in future implementations, as described in the document (new compression -options). - -Add sanity check in BMP reader module to avoid cjpeg crash for empty input -image (thank to Isaev Ildar of ISP RAS, Moscow, RU for reporting this error). - -Add data source and destination managers for read from and write to -memory buffers. New API functions jpeg_mem_src and jpeg_mem_dest. -Thank to Roberto Boni from Italy for the suggestion. - - -Version 7 27-Jun-2009 ----------------------- - -New scaled DCTs implemented. -djpeg now supports scalings N/8 with all N from 1 to 16. -cjpeg now supports scalings 8/N with all N from 1 to 16. -Scaled DCTs with size larger than 8 are now also used for resolving the -common 2x2 chroma subsampling case without additional spatial resampling. -Separate spatial resampling for those kind of files is now only necessary -for N>8 scaling cases. -Furthermore, separate scaled DCT functions are provided for direct resolving -of the common asymmetric subsampling cases (2x1 and 1x2) without additional -spatial resampling. - -cjpeg -quality option has been extended for support of separate quality -settings for luminance and chrominance (or in general, for every provided -quantization table slot). -New API function jpeg_default_qtables() and q_scale_factor array in library. - -Added -nosmooth option to cjpeg, complementary to djpeg. -New variable "do_fancy_downsampling" in library, complement to fancy -upsampling. Fancy upsampling now uses direct DCT scaling with sizes -larger than 8. The old method is not reversible and has been removed. - -Support arithmetic entropy encoding and decoding. -Added files jaricom.c, jcarith.c, jdarith.c. - -Straighten the file structure: -Removed files jidctred.c, jcphuff.c, jchuff.h, jdphuff.c, jdhuff.h. - -jpegtran has a new "lossless" cropping feature. - -Implement -perfect option in jpegtran, new API function -jtransform_perfect_transform() in transupp. (DP 204_perfect.dpatch) - -Better error messages for jpegtran fopen failure. -(DP 203_jpegtran_errmsg.dpatch) - -Fix byte order issue with 16bit PPM/PGM files in rdppm.c/wrppm.c: -according to Netpbm, the de facto standard implementation of the PNM formats, -the most significant byte is first. (DP 203_rdppm.dpatch) - -Add -raw option to rdjpgcom not to mangle the output. -(DP 205_rdjpgcom_raw.dpatch) - -Make rdjpgcom locale aware. (DP 201_rdjpgcom_locale.dpatch) - -Add extern "C" to jpeglib.h. -This avoids the need to put extern "C" { ... } around #include "jpeglib.h" -in your C++ application. Defining the symbol DONT_USE_EXTERN_C in the -configuration prevents this. (DP 202_jpeglib.h_c++.dpatch) - - -Version 6b 27-Mar-1998 ------------------------ - -jpegtran has new features for lossless image transformations (rotation -and flipping) as well as "lossless" reduction to grayscale. - -jpegtran now copies comments by default; it has a -copy switch to enable -copying all APPn blocks as well, or to suppress comments. (Formerly it -always suppressed comments and APPn blocks.) jpegtran now also preserves -JFIF version and resolution information. - -New decompressor library feature: COM and APPn markers found in the input -file can be saved in memory for later use by the application. (Before, -you had to code this up yourself with a custom marker processor.) - -There is an unused field "void * client_data" now in compress and decompress -parameter structs; this may be useful in some applications. - -JFIF version number information is now saved by the decoder and accepted by -the encoder. jpegtran uses this to copy the source file's version number, -to ensure "jpegtran -copy all" won't create bogus files that contain JFXX -extensions but claim to be version 1.01. Applications that generate their -own JFXX extension markers also (finally) have a supported way to cause the -encoder to emit JFIF version number 1.02. - -djpeg's trace mode reports JFIF 1.02 thumbnail images as such, rather -than as unknown APP0 markers. - -In -verbose mode, djpeg and rdjpgcom will try to print the contents of -APP12 markers as text. Some digital cameras store useful text information -in APP12 markers. - -Handling of truncated data streams is more robust: blocks beyond the one in -which the error occurs will be output as uniform gray, or left unchanged -if decoding a progressive JPEG. The appearance no longer depends on the -Huffman tables being used. - -Huffman tables are checked for validity much more carefully than before. - -To avoid the Unisys LZW patent, djpeg's GIF output capability has been -changed to produce "uncompressed GIFs", and cjpeg's GIF input capability -has been removed altogether. We're not happy about it either, but there -seems to be no good alternative. - -The configure script now supports building libjpeg as a shared library -on many flavors of Unix (all the ones that GNU libtool knows how to -build shared libraries for). Use "./configure --enable-shared" to -try this out. - -New jconfig file and makefiles for Microsoft Visual C++ and Developer Studio. -Also, a jconfig file and a build script for Metrowerks CodeWarrior -on Apple Macintosh. makefile.dj has been updated for DJGPP v2, and there -are miscellaneous other minor improvements in the makefiles. - -jmemmac.c now knows how to create temporary files following Mac System 7 -conventions. - -djpeg's -map switch is now able to read raw-format PPM files reliably. - -cjpeg -progressive -restart no longer generates any unnecessary DRI markers. - -Multiple calls to jpeg_simple_progression for a single JPEG object -no longer leak memory. - - -Version 6a 7-Feb-96 --------------------- - -Library initialization sequence modified to detect version mismatches -and struct field packing mismatches between library and calling application. -This change requires applications to be recompiled, but does not require -any application source code change. - -All routine declarations changed to the style "GLOBAL(type) name ...", -that is, GLOBAL, LOCAL, METHODDEF, EXTERN are now macros taking the -routine's return type as an argument. This makes it possible to add -Microsoft-style linkage keywords to all the routines by changing just -these macros. Note that any application code that was using these macros -will have to be changed. - -DCT coefficient quantization tables are now stored in normal array order -rather than zigzag order. Application code that calls jpeg_add_quant_table, -or otherwise manipulates quantization tables directly, will need to be -changed. If you need to make such code work with either older or newer -versions of the library, a test like "#if JPEG_LIB_VERSION >= 61" is -recommended. - -djpeg's trace capability now dumps DQT tables in natural order, not zigzag -order. This allows the trace output to be made into a "-qtables" file -more easily. - -New system-dependent memory manager module for use on Apple Macintosh. - -Fix bug in cjpeg's -smooth option: last one or two scanlines would be -duplicates of the prior line unless the image height mod 16 was 1 or 2. - -Repair minor problems in VMS, BCC, MC6 makefiles. - -New configure script based on latest GNU Autoconf. - -Correct the list of include files needed by MetroWerks C for ccommand(). - -Numerous small documentation updates. - - -Version 6 2-Aug-95 -------------------- - -Progressive JPEG support: library can read and write full progressive JPEG -files. A "buffered image" mode supports incremental decoding for on-the-fly -display of progressive images. Simply recompiling an existing IJG-v5-based -decoder with v6 should allow it to read progressive files, though of course -without any special progressive display. - -New "jpegtran" application performs lossless transcoding between different -JPEG formats; primarily, it can be used to convert baseline to progressive -JPEG and vice versa. In support of jpegtran, the library now allows lossless -reading and writing of JPEG files as DCT coefficient arrays. This ability -may be of use in other applications. - -Notes for programmers: -* We changed jpeg_start_decompress() to be able to suspend; this makes all -decoding modes available to suspending-input applications. However, -existing applications that use suspending input will need to be changed -to check the return value from jpeg_start_decompress(). You don't need to -do anything if you don't use a suspending data source. -* We changed the interface to the virtual array routines: access_virt_array -routines now take a count of the number of rows to access this time. The -last parameter to request_virt_array routines is now interpreted as the -maximum number of rows that may be accessed at once, but not necessarily -the height of every access. - - -Version 5b 15-Mar-95 ---------------------- - -Correct bugs with grayscale images having v_samp_factor > 1. - -jpeg_write_raw_data() now supports output suspension. - -Correct bugs in "configure" script for case of compiling in -a directory other than the one containing the source files. - -Repair bug in jquant1.c: sometimes didn't use as many colors as it could. - -Borland C makefile and jconfig file work under either MS-DOS or OS/2. - -Miscellaneous improvements to documentation. - - -Version 5a 7-Dec-94 --------------------- - -Changed color conversion roundoff behavior so that grayscale values are -represented exactly. (This causes test image files to change.) - -Make ordered dither use 16x16 instead of 4x4 pattern for a small quality -improvement. - -New configure script based on latest GNU Autoconf. -Fix configure script to handle CFLAGS correctly. -Rename *.auto files to *.cfg, so that configure script still works if -file names have been truncated for DOS. - -Fix bug in rdbmp.c: didn't allow for extra data between header and image. - -Modify rdppm.c/wrppm.c to handle 2-byte raw PPM/PGM formats for 12-bit data. - -Fix several bugs in rdrle.c. - -NEED_SHORT_EXTERNAL_NAMES option was broken. - -Revise jerror.h/jerror.c for more flexibility in message table. - -Repair oversight in jmemname.c NO_MKTEMP case: file could be there -but unreadable. - - -Version 5 24-Sep-94 --------------------- - -Version 5 represents a nearly complete redesign and rewrite of the IJG -software. Major user-visible changes include: - * Automatic configuration simplifies installation for most Unix systems. - * A range of speed vs. image quality tradeoffs are supported. - This includes resizing of an image during decompression: scaling down - by a factor of 1/2, 1/4, or 1/8 is handled very efficiently. - * New programs rdjpgcom and wrjpgcom allow insertion and extraction - of text comments in a JPEG file. - -The application programmer's interface to the library has changed completely. -Notable improvements include: - * We have eliminated the use of callback routines for handling the - uncompressed image data. The application now sees the library as a - set of routines that it calls to read or write image data on a - scanline-by-scanline basis. - * The application image data is represented in a conventional interleaved- - pixel format, rather than as a separate array for each color channel. - This can save a copying step in many programs. - * The handling of compressed data has been cleaned up: the application can - supply routines to source or sink the compressed data. It is possible to - suspend processing on source/sink buffer overrun, although this is not - supported in all operating modes. - * All static state has been eliminated from the library, so that multiple - instances of compression or decompression can be active concurrently. - * JPEG abbreviated datastream formats are supported, ie, quantization and - Huffman tables can be stored separately from the image data. - * And not only that, but the documentation of the library has improved - considerably! - - -The last widely used release before the version 5 rewrite was version 4A of -18-Feb-93. Change logs before that point have been discarded, since they -are not of much interest after the rewrite. +CHANGE LOG for Independent JPEG Group's JPEG software + + +Version 8d 15-Jan-2012 +----------------------- + +Add cjpeg -rgb option to create RGB JPEG files. +Using this switch suppresses the conversion from RGB +colorspace input to the default YCbCr JPEG colorspace. +This feature allows true lossless JPEG coding of RGB color images. +The recommended command for this purpose is currently +cjpeg -rgb -block 1 -arithmetic. +SmartScale capable decoder (introduced with IJG JPEG 8) required. +Thank to Michael Koch for the initial suggestion. + +Add option to disable the region adjustment in the transupp crop code. +Thank to Jeffrey Friedl for the suggestion. + +Thank to Richard Jones and Edd Dawson for various minor corrections. + +Thank to Akim Demaille for configure.ac cleanup. + + +Version 8c 16-Jan-2011 +----------------------- + +Add option to compression library and cjpeg (-block N) to use +different DCT block size. +All N from 1 to 16 are possible. Default is 8 (baseline format). +Larger values produce higher compression, +smaller values produce higher quality. +SmartScale capable decoder (introduced with IJG JPEG 8) required. + + +Version 8b 16-May-2010 +----------------------- + +Repair problem in new memory source manager with corrupt JPEG data. +Thank to Ted Campbell and Samuel Chun for the report. + +Repair problem in Makefile.am test target. +Thank to anonymous user for the report. + +Support MinGW installation with automatic configure. +Thank to Volker Grabsch for the suggestion. + + +Version 8a 28-Feb-2010 +----------------------- + +Writing tables-only datastreams via jpeg_write_tables works again. + +Support 32-bit BMPs (RGB image with Alpha channel) for read in cjpeg. +Thank to Brett Blackham for the suggestion. + +Improve accuracy in floating point IDCT calculation. +Thank to Robert Hooke for the hint. + + +Version 8 10-Jan-2010 +---------------------- + +jpegtran now supports the same -scale option as djpeg for "lossless" resize. +An implementation of the JPEG SmartScale extension is required for this +feature. A (draft) specification of the JPEG SmartScale extension is +available as a contributed document at ITU and ISO. Revision 2 or later +of the document is required (latest document version is Revision 3). +The SmartScale extension will enable more features beside lossless resize +in future implementations, as described in the document (new compression +options). + +Add sanity check in BMP reader module to avoid cjpeg crash for empty input +image (thank to Isaev Ildar of ISP RAS, Moscow, RU for reporting this error). + +Add data source and destination managers for read from and write to +memory buffers. New API functions jpeg_mem_src and jpeg_mem_dest. +Thank to Roberto Boni from Italy for the suggestion. + + +Version 7 27-Jun-2009 +---------------------- + +New scaled DCTs implemented. +djpeg now supports scalings N/8 with all N from 1 to 16. +cjpeg now supports scalings 8/N with all N from 1 to 16. +Scaled DCTs with size larger than 8 are now also used for resolving the +common 2x2 chroma subsampling case without additional spatial resampling. +Separate spatial resampling for those kind of files is now only necessary +for N>8 scaling cases. +Furthermore, separate scaled DCT functions are provided for direct resolving +of the common asymmetric subsampling cases (2x1 and 1x2) without additional +spatial resampling. + +cjpeg -quality option has been extended for support of separate quality +settings for luminance and chrominance (or in general, for every provided +quantization table slot). +New API function jpeg_default_qtables() and q_scale_factor array in library. + +Added -nosmooth option to cjpeg, complementary to djpeg. +New variable "do_fancy_downsampling" in library, complement to fancy +upsampling. Fancy upsampling now uses direct DCT scaling with sizes +larger than 8. The old method is not reversible and has been removed. + +Support arithmetic entropy encoding and decoding. +Added files jaricom.c, jcarith.c, jdarith.c. + +Straighten the file structure: +Removed files jidctred.c, jcphuff.c, jchuff.h, jdphuff.c, jdhuff.h. + +jpegtran has a new "lossless" cropping feature. + +Implement -perfect option in jpegtran, new API function +jtransform_perfect_transform() in transupp. (DP 204_perfect.dpatch) + +Better error messages for jpegtran fopen failure. +(DP 203_jpegtran_errmsg.dpatch) + +Fix byte order issue with 16bit PPM/PGM files in rdppm.c/wrppm.c: +according to Netpbm, the de facto standard implementation of the PNM formats, +the most significant byte is first. (DP 203_rdppm.dpatch) + +Add -raw option to rdjpgcom not to mangle the output. +(DP 205_rdjpgcom_raw.dpatch) + +Make rdjpgcom locale aware. (DP 201_rdjpgcom_locale.dpatch) + +Add extern "C" to jpeglib.h. +This avoids the need to put extern "C" { ... } around #include "jpeglib.h" +in your C++ application. Defining the symbol DONT_USE_EXTERN_C in the +configuration prevents this. (DP 202_jpeglib.h_c++.dpatch) + + +Version 6b 27-Mar-1998 +----------------------- + +jpegtran has new features for lossless image transformations (rotation +and flipping) as well as "lossless" reduction to grayscale. + +jpegtran now copies comments by default; it has a -copy switch to enable +copying all APPn blocks as well, or to suppress comments. (Formerly it +always suppressed comments and APPn blocks.) jpegtran now also preserves +JFIF version and resolution information. + +New decompressor library feature: COM and APPn markers found in the input +file can be saved in memory for later use by the application. (Before, +you had to code this up yourself with a custom marker processor.) + +There is an unused field "void * client_data" now in compress and decompress +parameter structs; this may be useful in some applications. + +JFIF version number information is now saved by the decoder and accepted by +the encoder. jpegtran uses this to copy the source file's version number, +to ensure "jpegtran -copy all" won't create bogus files that contain JFXX +extensions but claim to be version 1.01. Applications that generate their +own JFXX extension markers also (finally) have a supported way to cause the +encoder to emit JFIF version number 1.02. + +djpeg's trace mode reports JFIF 1.02 thumbnail images as such, rather +than as unknown APP0 markers. + +In -verbose mode, djpeg and rdjpgcom will try to print the contents of +APP12 markers as text. Some digital cameras store useful text information +in APP12 markers. + +Handling of truncated data streams is more robust: blocks beyond the one in +which the error occurs will be output as uniform gray, or left unchanged +if decoding a progressive JPEG. The appearance no longer depends on the +Huffman tables being used. + +Huffman tables are checked for validity much more carefully than before. + +To avoid the Unisys LZW patent, djpeg's GIF output capability has been +changed to produce "uncompressed GIFs", and cjpeg's GIF input capability +has been removed altogether. We're not happy about it either, but there +seems to be no good alternative. + +The configure script now supports building libjpeg as a shared library +on many flavors of Unix (all the ones that GNU libtool knows how to +build shared libraries for). Use "./configure --enable-shared" to +try this out. + +New jconfig file and makefiles for Microsoft Visual C++ and Developer Studio. +Also, a jconfig file and a build script for Metrowerks CodeWarrior +on Apple Macintosh. makefile.dj has been updated for DJGPP v2, and there +are miscellaneous other minor improvements in the makefiles. + +jmemmac.c now knows how to create temporary files following Mac System 7 +conventions. + +djpeg's -map switch is now able to read raw-format PPM files reliably. + +cjpeg -progressive -restart no longer generates any unnecessary DRI markers. + +Multiple calls to jpeg_simple_progression for a single JPEG object +no longer leak memory. + + +Version 6a 7-Feb-96 +-------------------- + +Library initialization sequence modified to detect version mismatches +and struct field packing mismatches between library and calling application. +This change requires applications to be recompiled, but does not require +any application source code change. + +All routine declarations changed to the style "GLOBAL(type) name ...", +that is, GLOBAL, LOCAL, METHODDEF, EXTERN are now macros taking the +routine's return type as an argument. This makes it possible to add +Microsoft-style linkage keywords to all the routines by changing just +these macros. Note that any application code that was using these macros +will have to be changed. + +DCT coefficient quantization tables are now stored in normal array order +rather than zigzag order. Application code that calls jpeg_add_quant_table, +or otherwise manipulates quantization tables directly, will need to be +changed. If you need to make such code work with either older or newer +versions of the library, a test like "#if JPEG_LIB_VERSION >= 61" is +recommended. + +djpeg's trace capability now dumps DQT tables in natural order, not zigzag +order. This allows the trace output to be made into a "-qtables" file +more easily. + +New system-dependent memory manager module for use on Apple Macintosh. + +Fix bug in cjpeg's -smooth option: last one or two scanlines would be +duplicates of the prior line unless the image height mod 16 was 1 or 2. + +Repair minor problems in VMS, BCC, MC6 makefiles. + +New configure script based on latest GNU Autoconf. + +Correct the list of include files needed by MetroWerks C for ccommand(). + +Numerous small documentation updates. + + +Version 6 2-Aug-95 +------------------- + +Progressive JPEG support: library can read and write full progressive JPEG +files. A "buffered image" mode supports incremental decoding for on-the-fly +display of progressive images. Simply recompiling an existing IJG-v5-based +decoder with v6 should allow it to read progressive files, though of course +without any special progressive display. + +New "jpegtran" application performs lossless transcoding between different +JPEG formats; primarily, it can be used to convert baseline to progressive +JPEG and vice versa. In support of jpegtran, the library now allows lossless +reading and writing of JPEG files as DCT coefficient arrays. This ability +may be of use in other applications. + +Notes for programmers: +* We changed jpeg_start_decompress() to be able to suspend; this makes all +decoding modes available to suspending-input applications. However, +existing applications that use suspending input will need to be changed +to check the return value from jpeg_start_decompress(). You don't need to +do anything if you don't use a suspending data source. +* We changed the interface to the virtual array routines: access_virt_array +routines now take a count of the number of rows to access this time. The +last parameter to request_virt_array routines is now interpreted as the +maximum number of rows that may be accessed at once, but not necessarily +the height of every access. + + +Version 5b 15-Mar-95 +--------------------- + +Correct bugs with grayscale images having v_samp_factor > 1. + +jpeg_write_raw_data() now supports output suspension. + +Correct bugs in "configure" script for case of compiling in +a directory other than the one containing the source files. + +Repair bug in jquant1.c: sometimes didn't use as many colors as it could. + +Borland C makefile and jconfig file work under either MS-DOS or OS/2. + +Miscellaneous improvements to documentation. + + +Version 5a 7-Dec-94 +-------------------- + +Changed color conversion roundoff behavior so that grayscale values are +represented exactly. (This causes test image files to change.) + +Make ordered dither use 16x16 instead of 4x4 pattern for a small quality +improvement. + +New configure script based on latest GNU Autoconf. +Fix configure script to handle CFLAGS correctly. +Rename *.auto files to *.cfg, so that configure script still works if +file names have been truncated for DOS. + +Fix bug in rdbmp.c: didn't allow for extra data between header and image. + +Modify rdppm.c/wrppm.c to handle 2-byte raw PPM/PGM formats for 12-bit data. + +Fix several bugs in rdrle.c. + +NEED_SHORT_EXTERNAL_NAMES option was broken. + +Revise jerror.h/jerror.c for more flexibility in message table. + +Repair oversight in jmemname.c NO_MKTEMP case: file could be there +but unreadable. + + +Version 5 24-Sep-94 +-------------------- + +Version 5 represents a nearly complete redesign and rewrite of the IJG +software. Major user-visible changes include: + * Automatic configuration simplifies installation for most Unix systems. + * A range of speed vs. image quality tradeoffs are supported. + This includes resizing of an image during decompression: scaling down + by a factor of 1/2, 1/4, or 1/8 is handled very efficiently. + * New programs rdjpgcom and wrjpgcom allow insertion and extraction + of text comments in a JPEG file. + +The application programmer's interface to the library has changed completely. +Notable improvements include: + * We have eliminated the use of callback routines for handling the + uncompressed image data. The application now sees the library as a + set of routines that it calls to read or write image data on a + scanline-by-scanline basis. + * The application image data is represented in a conventional interleaved- + pixel format, rather than as a separate array for each color channel. + This can save a copying step in many programs. + * The handling of compressed data has been cleaned up: the application can + supply routines to source or sink the compressed data. It is possible to + suspend processing on source/sink buffer overrun, although this is not + supported in all operating modes. + * All static state has been eliminated from the library, so that multiple + instances of compression or decompression can be active concurrently. + * JPEG abbreviated datastream formats are supported, ie, quantization and + Huffman tables can be stored separately from the image data. + * And not only that, but the documentation of the library has improved + considerably! + + +The last widely used release before the version 5 rewrite was version 4A of +18-Feb-93. Change logs before that point have been discarded, since they +are not of much interest after the rewrite. diff --git a/Source/LibJPEG/cjpeg.c b/Source/LibJPEG/cjpeg.c index a999eee..9a9a09a 100644 --- a/Source/LibJPEG/cjpeg.c +++ b/Source/LibJPEG/cjpeg.c @@ -1,643 +1,643 @@ -/* - * cjpeg.c - * - * Copyright (C) 1991-1998, Thomas G. Lane. - * Modified 2003-2011 by Guido Vollbeding. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains a command-line user interface for the JPEG compressor. - * It should work on any system with Unix- or MS-DOS-style command lines. - * - * Two different command line styles are permitted, depending on the - * compile-time switch TWO_FILE_COMMANDLINE: - * cjpeg [options] inputfile outputfile - * cjpeg [options] [inputfile] - * In the second style, output is always to standard output, which you'd - * normally redirect to a file or pipe to some other program. Input is - * either from a named file or from standard input (typically redirected). - * The second style is convenient on Unix but is unhelpful on systems that - * don't support pipes. Also, you MUST use the first style if your system - * doesn't do binary I/O to stdin/stdout. - * To simplify script writing, the "-outfile" switch is provided. The syntax - * cjpeg [options] -outfile outputfile inputfile - * works regardless of which command line style is used. - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ -#include "jversion.h" /* for version message */ - -#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ -#ifdef __MWERKS__ -#include /* Metrowerks needs this */ -#include /* ... and this */ -#endif -#ifdef THINK_C -#include /* Think declares it here */ -#endif -#endif - - -/* Create the add-on message string table. */ - -#define JMESSAGE(code,string) string , - -static const char * const cdjpeg_message_table[] = { -#include "cderror.h" - NULL -}; - - -/* - * This routine determines what format the input file is, - * and selects the appropriate input-reading module. - * - * To determine which family of input formats the file belongs to, - * we may look only at the first byte of the file, since C does not - * guarantee that more than one character can be pushed back with ungetc. - * Looking at additional bytes would require one of these approaches: - * 1) assume we can fseek() the input file (fails for piped input); - * 2) assume we can push back more than one character (works in - * some C implementations, but unportable); - * 3) provide our own buffering (breaks input readers that want to use - * stdio directly, such as the RLE library); - * or 4) don't put back the data, and modify the input_init methods to assume - * they start reading after the start of file (also breaks RLE library). - * #1 is attractive for MS-DOS but is untenable on Unix. - * - * The most portable solution for file types that can't be identified by their - * first byte is to make the user tell us what they are. This is also the - * only approach for "raw" file types that contain only arbitrary values. - * We presently apply this method for Targa files. Most of the time Targa - * files start with 0x00, so we recognize that case. Potentially, however, - * a Targa file could start with any byte value (byte 0 is the length of the - * seldom-used ID field), so we provide a switch to force Targa input mode. - */ - -static boolean is_targa; /* records user -targa switch */ - - -LOCAL(cjpeg_source_ptr) -select_file_type (j_compress_ptr cinfo, FILE * infile) -{ - int c; - - if (is_targa) { -#ifdef TARGA_SUPPORTED - return jinit_read_targa(cinfo); -#else - ERREXIT(cinfo, JERR_TGA_NOTCOMP); -#endif - } - - if ((c = getc(infile)) == EOF) - ERREXIT(cinfo, JERR_INPUT_EMPTY); - if (ungetc(c, infile) == EOF) - ERREXIT(cinfo, JERR_UNGETC_FAILED); - - switch (c) { -#ifdef BMP_SUPPORTED - case 'B': - return jinit_read_bmp(cinfo); -#endif -#ifdef GIF_SUPPORTED - case 'G': - return jinit_read_gif(cinfo); -#endif -#ifdef PPM_SUPPORTED - case 'P': - return jinit_read_ppm(cinfo); -#endif -#ifdef RLE_SUPPORTED - case 'R': - return jinit_read_rle(cinfo); -#endif -#ifdef TARGA_SUPPORTED - case 0x00: - return jinit_read_targa(cinfo); -#endif - default: - ERREXIT(cinfo, JERR_UNKNOWN_FORMAT); - break; - } - - return NULL; /* suppress compiler warnings */ -} - - -/* - * Argument-parsing code. - * The switch parser is designed to be useful with DOS-style command line - * syntax, ie, intermixed switches and file names, where only the switches - * to the left of a given file name affect processing of that file. - * The main program in this file doesn't actually use this capability... - */ - - -static const char * progname; /* program name for error messages */ -static char * outfilename; /* for -outfile switch */ - - -LOCAL(void) -usage (void) -/* complain about bad command line */ -{ - fprintf(stderr, "usage: %s [switches] ", progname); -#ifdef TWO_FILE_COMMANDLINE - fprintf(stderr, "inputfile outputfile\n"); -#else - fprintf(stderr, "[inputfile]\n"); -#endif - - fprintf(stderr, "Switches (names may be abbreviated):\n"); - fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is useful range)\n"); - fprintf(stderr, " -grayscale Create monochrome JPEG file\n"); - fprintf(stderr, " -rgb Create RGB JPEG file\n"); -#ifdef ENTROPY_OPT_SUPPORTED - fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n"); -#endif -#ifdef C_PROGRESSIVE_SUPPORTED - fprintf(stderr, " -progressive Create progressive JPEG file\n"); -#endif -#ifdef DCT_SCALING_SUPPORTED - fprintf(stderr, " -scale M/N Scale image by fraction M/N, eg, 1/2\n"); -#endif -#ifdef TARGA_SUPPORTED - fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n"); -#endif - fprintf(stderr, "Switches for advanced users:\n"); -#ifdef C_ARITH_CODING_SUPPORTED - fprintf(stderr, " -arithmetic Use arithmetic coding\n"); -#endif -#ifdef DCT_SCALING_SUPPORTED - fprintf(stderr, " -block N DCT block size (1..16; default is 8)\n"); -#endif -#ifdef DCT_ISLOW_SUPPORTED - fprintf(stderr, " -dct int Use integer DCT method%s\n", - (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); -#endif -#ifdef DCT_IFAST_SUPPORTED - fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n", - (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); -#endif -#ifdef DCT_FLOAT_SUPPORTED - fprintf(stderr, " -dct float Use floating-point DCT method%s\n", - (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); -#endif - fprintf(stderr, " -nosmooth Don't use high-quality downsampling\n"); - fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n"); -#ifdef INPUT_SMOOTHING_SUPPORTED - fprintf(stderr, " -smooth N Smooth dithered input (N=1..100 is strength)\n"); -#endif - fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); - fprintf(stderr, " -outfile name Specify name for output file\n"); - fprintf(stderr, " -verbose or -debug Emit debug output\n"); - fprintf(stderr, "Switches for wizards:\n"); - fprintf(stderr, " -baseline Force baseline quantization tables\n"); - fprintf(stderr, " -qtables file Use quantization tables given in file\n"); - fprintf(stderr, " -qslots N[,...] Set component quantization tables\n"); - fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n"); -#ifdef C_MULTISCAN_FILES_SUPPORTED - fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n"); -#endif - exit(EXIT_FAILURE); -} - - -LOCAL(int) -parse_switches (j_compress_ptr cinfo, int argc, char **argv, - int last_file_arg_seen, boolean for_real) -/* Parse optional switches. - * Returns argv[] index of first file-name argument (== argc if none). - * Any file names with indexes <= last_file_arg_seen are ignored; - * they have presumably been processed in a previous iteration. - * (Pass 0 for last_file_arg_seen on the first or only iteration.) - * for_real is FALSE on the first (dummy) pass; we may skip any expensive - * processing. - */ -{ - int argn; - char * arg; - boolean force_baseline; - boolean simple_progressive; - char * qualityarg = NULL; /* saves -quality parm if any */ - char * qtablefile = NULL; /* saves -qtables filename if any */ - char * qslotsarg = NULL; /* saves -qslots parm if any */ - char * samplearg = NULL; /* saves -sample parm if any */ - char * scansarg = NULL; /* saves -scans parm if any */ - - /* Set up default JPEG parameters. */ - - force_baseline = FALSE; /* by default, allow 16-bit quantizers */ - simple_progressive = FALSE; - is_targa = FALSE; - outfilename = NULL; - cinfo->err->trace_level = 0; - - /* Scan command line options, adjust parameters */ - - for (argn = 1; argn < argc; argn++) { - arg = argv[argn]; - if (*arg != '-') { - /* Not a switch, must be a file name argument */ - if (argn <= last_file_arg_seen) { - outfilename = NULL; /* -outfile applies to just one input file */ - continue; /* ignore this name if previously processed */ - } - break; /* else done parsing switches */ - } - arg++; /* advance past switch marker character */ - - if (keymatch(arg, "arithmetic", 1)) { - /* Use arithmetic coding. */ -#ifdef C_ARITH_CODING_SUPPORTED - cinfo->arith_code = TRUE; -#else - fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", - progname); - exit(EXIT_FAILURE); -#endif - - } else if (keymatch(arg, "baseline", 2)) { - /* Force baseline-compatible output (8-bit quantizer values). */ - force_baseline = TRUE; - - } else if (keymatch(arg, "block", 2)) { - /* Set DCT block size. */ -#if defined DCT_SCALING_SUPPORTED && JPEG_LIB_VERSION_MAJOR >= 8 && \ - (JPEG_LIB_VERSION_MAJOR > 8 || JPEG_LIB_VERSION_MINOR >= 3) - int val; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%d", &val) != 1) - usage(); - if (val < 1 || val > 16) - usage(); - cinfo->block_size = val; -#else - fprintf(stderr, "%s: sorry, block size setting not supported\n", - progname); - exit(EXIT_FAILURE); -#endif - - } else if (keymatch(arg, "dct", 2)) { - /* Select DCT algorithm. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - if (keymatch(argv[argn], "int", 1)) { - cinfo->dct_method = JDCT_ISLOW; - } else if (keymatch(argv[argn], "fast", 2)) { - cinfo->dct_method = JDCT_IFAST; - } else if (keymatch(argv[argn], "float", 2)) { - cinfo->dct_method = JDCT_FLOAT; - } else - usage(); - - } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { - /* Enable debug printouts. */ - /* On first -d, print version identification */ - static boolean printed_version = FALSE; - - if (! printed_version) { - fprintf(stderr, "Independent JPEG Group's CJPEG, version %s\n%s\n", - JVERSION, JCOPYRIGHT); - printed_version = TRUE; - } - cinfo->err->trace_level++; - - } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) { - /* Force a monochrome JPEG file to be generated. */ - jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); - - } else if (keymatch(arg, "rgb", 3)) { - /* Force an RGB JPEG file to be generated. */ - jpeg_set_colorspace(cinfo, JCS_RGB); - - } else if (keymatch(arg, "maxmemory", 3)) { - /* Maximum memory in Kb (or Mb with 'm'). */ - long lval; - char ch = 'x'; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) - usage(); - if (ch == 'm' || ch == 'M') - lval *= 1000L; - cinfo->mem->max_memory_to_use = lval * 1000L; - - } else if (keymatch(arg, "nosmooth", 3)) { - /* Suppress fancy downsampling */ - cinfo->do_fancy_downsampling = FALSE; - - } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { - /* Enable entropy parm optimization. */ -#ifdef ENTROPY_OPT_SUPPORTED - cinfo->optimize_coding = TRUE; -#else - fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n", - progname); - exit(EXIT_FAILURE); -#endif - - } else if (keymatch(arg, "outfile", 4)) { - /* Set output file name. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - outfilename = argv[argn]; /* save it away for later use */ - - } else if (keymatch(arg, "progressive", 1)) { - /* Select simple progressive mode. */ -#ifdef C_PROGRESSIVE_SUPPORTED - simple_progressive = TRUE; - /* We must postpone execution until num_components is known. */ -#else - fprintf(stderr, "%s: sorry, progressive output was not compiled\n", - progname); - exit(EXIT_FAILURE); -#endif - - } else if (keymatch(arg, "quality", 1)) { - /* Quality ratings (quantization table scaling factors). */ - if (++argn >= argc) /* advance to next argument */ - usage(); - qualityarg = argv[argn]; - - } else if (keymatch(arg, "qslots", 2)) { - /* Quantization table slot numbers. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - qslotsarg = argv[argn]; - /* Must delay setting qslots until after we have processed any - * colorspace-determining switches, since jpeg_set_colorspace sets - * default quant table numbers. - */ - - } else if (keymatch(arg, "qtables", 2)) { - /* Quantization tables fetched from file. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - qtablefile = argv[argn]; - /* We postpone actually reading the file in case -quality comes later. */ - - } else if (keymatch(arg, "restart", 1)) { - /* Restart interval in MCU rows (or in MCUs with 'b'). */ - long lval; - char ch = 'x'; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) - usage(); - if (lval < 0 || lval > 65535L) - usage(); - if (ch == 'b' || ch == 'B') { - cinfo->restart_interval = (unsigned int) lval; - cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ - } else { - cinfo->restart_in_rows = (int) lval; - /* restart_interval will be computed during startup */ - } - - } else if (keymatch(arg, "sample", 2)) { - /* Set sampling factors. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - samplearg = argv[argn]; - /* Must delay setting sample factors until after we have processed any - * colorspace-determining switches, since jpeg_set_colorspace sets - * default sampling factors. - */ - - } else if (keymatch(arg, "scale", 4)) { - /* Scale the image by a fraction M/N. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%d/%d", - &cinfo->scale_num, &cinfo->scale_denom) != 2) - usage(); - - } else if (keymatch(arg, "scans", 4)) { - /* Set scan script. */ -#ifdef C_MULTISCAN_FILES_SUPPORTED - if (++argn >= argc) /* advance to next argument */ - usage(); - scansarg = argv[argn]; - /* We must postpone reading the file in case -progressive appears. */ -#else - fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n", - progname); - exit(EXIT_FAILURE); -#endif - - } else if (keymatch(arg, "smooth", 2)) { - /* Set input smoothing factor. */ - int val; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%d", &val) != 1) - usage(); - if (val < 0 || val > 100) - usage(); - cinfo->smoothing_factor = val; - - } else if (keymatch(arg, "targa", 1)) { - /* Input file is Targa format. */ - is_targa = TRUE; - - } else { - usage(); /* bogus switch */ - } - } - - /* Post-switch-scanning cleanup */ - - if (for_real) { - - /* Set quantization tables for selected quality. */ - /* Some or all may be overridden if -qtables is present. */ - if (qualityarg != NULL) /* process -quality if it was present */ - if (! set_quality_ratings(cinfo, qualityarg, force_baseline)) - usage(); - - if (qtablefile != NULL) /* process -qtables if it was present */ - if (! read_quant_tables(cinfo, qtablefile, force_baseline)) - usage(); - - if (qslotsarg != NULL) /* process -qslots if it was present */ - if (! set_quant_slots(cinfo, qslotsarg)) - usage(); - - if (samplearg != NULL) /* process -sample if it was present */ - if (! set_sample_factors(cinfo, samplearg)) - usage(); - -#ifdef C_PROGRESSIVE_SUPPORTED - if (simple_progressive) /* process -progressive; -scans can override */ - jpeg_simple_progression(cinfo); -#endif - -#ifdef C_MULTISCAN_FILES_SUPPORTED - if (scansarg != NULL) /* process -scans if it was present */ - if (! read_scan_script(cinfo, scansarg)) - usage(); -#endif - } - - return argn; /* return index of next arg (file name) */ -} - - -/* - * The main program. - */ - -int -main (int argc, char **argv) -{ - struct jpeg_compress_struct cinfo; - struct jpeg_error_mgr jerr; -#ifdef PROGRESS_REPORT - struct cdjpeg_progress_mgr progress; -#endif - int file_index; - cjpeg_source_ptr src_mgr; - FILE * input_file; - FILE * output_file; - JDIMENSION num_scanlines; - - /* On Mac, fetch a command line. */ -#ifdef USE_CCOMMAND - argc = ccommand(&argv); -#endif - - progname = argv[0]; - if (progname == NULL || progname[0] == 0) - progname = "cjpeg"; /* in case C library doesn't provide it */ - - /* Initialize the JPEG compression object with default error handling. */ - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_compress(&cinfo); - /* Add some application-specific error messages (from cderror.h) */ - jerr.addon_message_table = cdjpeg_message_table; - jerr.first_addon_message = JMSG_FIRSTADDONCODE; - jerr.last_addon_message = JMSG_LASTADDONCODE; - - /* Now safe to enable signal catcher. */ -#ifdef NEED_SIGNAL_CATCHER - enable_signal_catcher((j_common_ptr) &cinfo); -#endif - - /* Initialize JPEG parameters. - * Much of this may be overridden later. - * In particular, we don't yet know the input file's color space, - * but we need to provide some value for jpeg_set_defaults() to work. - */ - - cinfo.in_color_space = JCS_RGB; /* arbitrary guess */ - jpeg_set_defaults(&cinfo); - - /* Scan command line to find file names. - * It is convenient to use just one switch-parsing routine, but the switch - * values read here are ignored; we will rescan the switches after opening - * the input file. - */ - - file_index = parse_switches(&cinfo, argc, argv, 0, FALSE); - -#ifdef TWO_FILE_COMMANDLINE - /* Must have either -outfile switch or explicit output file name */ - if (outfilename == NULL) { - if (file_index != argc-2) { - fprintf(stderr, "%s: must name one input and one output file\n", - progname); - usage(); - } - outfilename = argv[file_index+1]; - } else { - if (file_index != argc-1) { - fprintf(stderr, "%s: must name one input and one output file\n", - progname); - usage(); - } - } -#else - /* Unix style: expect zero or one file name */ - if (file_index < argc-1) { - fprintf(stderr, "%s: only one input file\n", progname); - usage(); - } -#endif /* TWO_FILE_COMMANDLINE */ - - /* Open the input file. */ - if (file_index < argc) { - if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); - exit(EXIT_FAILURE); - } - } else { - /* default input file is stdin */ - input_file = read_stdin(); - } - - /* Open the output file. */ - if (outfilename != NULL) { - if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, outfilename); - exit(EXIT_FAILURE); - } - } else { - /* default output file is stdout */ - output_file = write_stdout(); - } - -#ifdef PROGRESS_REPORT - start_progress_monitor((j_common_ptr) &cinfo, &progress); -#endif - - /* Figure out the input file format, and set up to read it. */ - src_mgr = select_file_type(&cinfo, input_file); - src_mgr->input_file = input_file; - - /* Read the input file header to obtain file size & colorspace. */ - (*src_mgr->start_input) (&cinfo, src_mgr); - - /* Now that we know input colorspace, fix colorspace-dependent defaults */ - jpeg_default_colorspace(&cinfo); - - /* Adjust default compression parameters by re-parsing the options */ - file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); - - /* Specify data destination for compression */ - jpeg_stdio_dest(&cinfo, output_file); - - /* Start compressor */ - jpeg_start_compress(&cinfo, TRUE); - - /* Process data */ - while (cinfo.next_scanline < cinfo.image_height) { - num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr); - (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines); - } - - /* Finish compression and release memory */ - (*src_mgr->finish_input) (&cinfo, src_mgr); - jpeg_finish_compress(&cinfo); - jpeg_destroy_compress(&cinfo); - - /* Close files, if we opened them */ - if (input_file != stdin) - fclose(input_file); - if (output_file != stdout) - fclose(output_file); - -#ifdef PROGRESS_REPORT - end_progress_monitor((j_common_ptr) &cinfo); -#endif - - /* All done. */ - exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); - return 0; /* suppress no-return-value warnings */ -} +/* + * cjpeg.c + * + * Copyright (C) 1991-1998, Thomas G. Lane. + * Modified 2003-2011 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a command-line user interface for the JPEG compressor. + * It should work on any system with Unix- or MS-DOS-style command lines. + * + * Two different command line styles are permitted, depending on the + * compile-time switch TWO_FILE_COMMANDLINE: + * cjpeg [options] inputfile outputfile + * cjpeg [options] [inputfile] + * In the second style, output is always to standard output, which you'd + * normally redirect to a file or pipe to some other program. Input is + * either from a named file or from standard input (typically redirected). + * The second style is convenient on Unix but is unhelpful on systems that + * don't support pipes. Also, you MUST use the first style if your system + * doesn't do binary I/O to stdin/stdout. + * To simplify script writing, the "-outfile" switch is provided. The syntax + * cjpeg [options] -outfile outputfile inputfile + * works regardless of which command line style is used. + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ +#include "jversion.h" /* for version message */ + +#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ +#ifdef __MWERKS__ +#include /* Metrowerks needs this */ +#include /* ... and this */ +#endif +#ifdef THINK_C +#include /* Think declares it here */ +#endif +#endif + + +/* Create the add-on message string table. */ + +#define JMESSAGE(code,string) string , + +static const char * const cdjpeg_message_table[] = { +#include "cderror.h" + NULL +}; + + +/* + * This routine determines what format the input file is, + * and selects the appropriate input-reading module. + * + * To determine which family of input formats the file belongs to, + * we may look only at the first byte of the file, since C does not + * guarantee that more than one character can be pushed back with ungetc. + * Looking at additional bytes would require one of these approaches: + * 1) assume we can fseek() the input file (fails for piped input); + * 2) assume we can push back more than one character (works in + * some C implementations, but unportable); + * 3) provide our own buffering (breaks input readers that want to use + * stdio directly, such as the RLE library); + * or 4) don't put back the data, and modify the input_init methods to assume + * they start reading after the start of file (also breaks RLE library). + * #1 is attractive for MS-DOS but is untenable on Unix. + * + * The most portable solution for file types that can't be identified by their + * first byte is to make the user tell us what they are. This is also the + * only approach for "raw" file types that contain only arbitrary values. + * We presently apply this method for Targa files. Most of the time Targa + * files start with 0x00, so we recognize that case. Potentially, however, + * a Targa file could start with any byte value (byte 0 is the length of the + * seldom-used ID field), so we provide a switch to force Targa input mode. + */ + +static boolean is_targa; /* records user -targa switch */ + + +LOCAL(cjpeg_source_ptr) +select_file_type (j_compress_ptr cinfo, FILE * infile) +{ + int c; + + if (is_targa) { +#ifdef TARGA_SUPPORTED + return jinit_read_targa(cinfo); +#else + ERREXIT(cinfo, JERR_TGA_NOTCOMP); +#endif + } + + if ((c = getc(infile)) == EOF) + ERREXIT(cinfo, JERR_INPUT_EMPTY); + if (ungetc(c, infile) == EOF) + ERREXIT(cinfo, JERR_UNGETC_FAILED); + + switch (c) { +#ifdef BMP_SUPPORTED + case 'B': + return jinit_read_bmp(cinfo); +#endif +#ifdef GIF_SUPPORTED + case 'G': + return jinit_read_gif(cinfo); +#endif +#ifdef PPM_SUPPORTED + case 'P': + return jinit_read_ppm(cinfo); +#endif +#ifdef RLE_SUPPORTED + case 'R': + return jinit_read_rle(cinfo); +#endif +#ifdef TARGA_SUPPORTED + case 0x00: + return jinit_read_targa(cinfo); +#endif + default: + ERREXIT(cinfo, JERR_UNKNOWN_FORMAT); + break; + } + + return NULL; /* suppress compiler warnings */ +} + + +/* + * Argument-parsing code. + * The switch parser is designed to be useful with DOS-style command line + * syntax, ie, intermixed switches and file names, where only the switches + * to the left of a given file name affect processing of that file. + * The main program in this file doesn't actually use this capability... + */ + + +static const char * progname; /* program name for error messages */ +static char * outfilename; /* for -outfile switch */ + + +LOCAL(void) +usage (void) +/* complain about bad command line */ +{ + fprintf(stderr, "usage: %s [switches] ", progname); +#ifdef TWO_FILE_COMMANDLINE + fprintf(stderr, "inputfile outputfile\n"); +#else + fprintf(stderr, "[inputfile]\n"); +#endif + + fprintf(stderr, "Switches (names may be abbreviated):\n"); + fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is useful range)\n"); + fprintf(stderr, " -grayscale Create monochrome JPEG file\n"); + fprintf(stderr, " -rgb Create RGB JPEG file\n"); +#ifdef ENTROPY_OPT_SUPPORTED + fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n"); +#endif +#ifdef C_PROGRESSIVE_SUPPORTED + fprintf(stderr, " -progressive Create progressive JPEG file\n"); +#endif +#ifdef DCT_SCALING_SUPPORTED + fprintf(stderr, " -scale M/N Scale image by fraction M/N, eg, 1/2\n"); +#endif +#ifdef TARGA_SUPPORTED + fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n"); +#endif + fprintf(stderr, "Switches for advanced users:\n"); +#ifdef C_ARITH_CODING_SUPPORTED + fprintf(stderr, " -arithmetic Use arithmetic coding\n"); +#endif +#ifdef DCT_SCALING_SUPPORTED + fprintf(stderr, " -block N DCT block size (1..16; default is 8)\n"); +#endif +#ifdef DCT_ISLOW_SUPPORTED + fprintf(stderr, " -dct int Use integer DCT method%s\n", + (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); +#endif +#ifdef DCT_IFAST_SUPPORTED + fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n", + (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); +#endif +#ifdef DCT_FLOAT_SUPPORTED + fprintf(stderr, " -dct float Use floating-point DCT method%s\n", + (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); +#endif + fprintf(stderr, " -nosmooth Don't use high-quality downsampling\n"); + fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n"); +#ifdef INPUT_SMOOTHING_SUPPORTED + fprintf(stderr, " -smooth N Smooth dithered input (N=1..100 is strength)\n"); +#endif + fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); + fprintf(stderr, " -outfile name Specify name for output file\n"); + fprintf(stderr, " -verbose or -debug Emit debug output\n"); + fprintf(stderr, "Switches for wizards:\n"); + fprintf(stderr, " -baseline Force baseline quantization tables\n"); + fprintf(stderr, " -qtables file Use quantization tables given in file\n"); + fprintf(stderr, " -qslots N[,...] Set component quantization tables\n"); + fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n"); +#ifdef C_MULTISCAN_FILES_SUPPORTED + fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n"); +#endif + exit(EXIT_FAILURE); +} + + +LOCAL(int) +parse_switches (j_compress_ptr cinfo, int argc, char **argv, + int last_file_arg_seen, boolean for_real) +/* Parse optional switches. + * Returns argv[] index of first file-name argument (== argc if none). + * Any file names with indexes <= last_file_arg_seen are ignored; + * they have presumably been processed in a previous iteration. + * (Pass 0 for last_file_arg_seen on the first or only iteration.) + * for_real is FALSE on the first (dummy) pass; we may skip any expensive + * processing. + */ +{ + int argn; + char * arg; + boolean force_baseline; + boolean simple_progressive; + char * qualityarg = NULL; /* saves -quality parm if any */ + char * qtablefile = NULL; /* saves -qtables filename if any */ + char * qslotsarg = NULL; /* saves -qslots parm if any */ + char * samplearg = NULL; /* saves -sample parm if any */ + char * scansarg = NULL; /* saves -scans parm if any */ + + /* Set up default JPEG parameters. */ + + force_baseline = FALSE; /* by default, allow 16-bit quantizers */ + simple_progressive = FALSE; + is_targa = FALSE; + outfilename = NULL; + cinfo->err->trace_level = 0; + + /* Scan command line options, adjust parameters */ + + for (argn = 1; argn < argc; argn++) { + arg = argv[argn]; + if (*arg != '-') { + /* Not a switch, must be a file name argument */ + if (argn <= last_file_arg_seen) { + outfilename = NULL; /* -outfile applies to just one input file */ + continue; /* ignore this name if previously processed */ + } + break; /* else done parsing switches */ + } + arg++; /* advance past switch marker character */ + + if (keymatch(arg, "arithmetic", 1)) { + /* Use arithmetic coding. */ +#ifdef C_ARITH_CODING_SUPPORTED + cinfo->arith_code = TRUE; +#else + fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", + progname); + exit(EXIT_FAILURE); +#endif + + } else if (keymatch(arg, "baseline", 2)) { + /* Force baseline-compatible output (8-bit quantizer values). */ + force_baseline = TRUE; + + } else if (keymatch(arg, "block", 2)) { + /* Set DCT block size. */ +#if defined DCT_SCALING_SUPPORTED && JPEG_LIB_VERSION_MAJOR >= 8 && \ + (JPEG_LIB_VERSION_MAJOR > 8 || JPEG_LIB_VERSION_MINOR >= 3) + int val; + + if (++argn >= argc) /* advance to next argument */ + usage(); + if (sscanf(argv[argn], "%d", &val) != 1) + usage(); + if (val < 1 || val > 16) + usage(); + cinfo->block_size = val; +#else + fprintf(stderr, "%s: sorry, block size setting not supported\n", + progname); + exit(EXIT_FAILURE); +#endif + + } else if (keymatch(arg, "dct", 2)) { + /* Select DCT algorithm. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + if (keymatch(argv[argn], "int", 1)) { + cinfo->dct_method = JDCT_ISLOW; + } else if (keymatch(argv[argn], "fast", 2)) { + cinfo->dct_method = JDCT_IFAST; + } else if (keymatch(argv[argn], "float", 2)) { + cinfo->dct_method = JDCT_FLOAT; + } else + usage(); + + } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { + /* Enable debug printouts. */ + /* On first -d, print version identification */ + static boolean printed_version = FALSE; + + if (! printed_version) { + fprintf(stderr, "Independent JPEG Group's CJPEG, version %s\n%s\n", + JVERSION, JCOPYRIGHT); + printed_version = TRUE; + } + cinfo->err->trace_level++; + + } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) { + /* Force a monochrome JPEG file to be generated. */ + jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); + + } else if (keymatch(arg, "rgb", 3)) { + /* Force an RGB JPEG file to be generated. */ + jpeg_set_colorspace(cinfo, JCS_RGB); + + } else if (keymatch(arg, "maxmemory", 3)) { + /* Maximum memory in Kb (or Mb with 'm'). */ + long lval; + char ch = 'x'; + + if (++argn >= argc) /* advance to next argument */ + usage(); + if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) + usage(); + if (ch == 'm' || ch == 'M') + lval *= 1000L; + cinfo->mem->max_memory_to_use = lval * 1000L; + + } else if (keymatch(arg, "nosmooth", 3)) { + /* Suppress fancy downsampling */ + cinfo->do_fancy_downsampling = FALSE; + + } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { + /* Enable entropy parm optimization. */ +#ifdef ENTROPY_OPT_SUPPORTED + cinfo->optimize_coding = TRUE; +#else + fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n", + progname); + exit(EXIT_FAILURE); +#endif + + } else if (keymatch(arg, "outfile", 4)) { + /* Set output file name. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + outfilename = argv[argn]; /* save it away for later use */ + + } else if (keymatch(arg, "progressive", 1)) { + /* Select simple progressive mode. */ +#ifdef C_PROGRESSIVE_SUPPORTED + simple_progressive = TRUE; + /* We must postpone execution until num_components is known. */ +#else + fprintf(stderr, "%s: sorry, progressive output was not compiled\n", + progname); + exit(EXIT_FAILURE); +#endif + + } else if (keymatch(arg, "quality", 1)) { + /* Quality ratings (quantization table scaling factors). */ + if (++argn >= argc) /* advance to next argument */ + usage(); + qualityarg = argv[argn]; + + } else if (keymatch(arg, "qslots", 2)) { + /* Quantization table slot numbers. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + qslotsarg = argv[argn]; + /* Must delay setting qslots until after we have processed any + * colorspace-determining switches, since jpeg_set_colorspace sets + * default quant table numbers. + */ + + } else if (keymatch(arg, "qtables", 2)) { + /* Quantization tables fetched from file. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + qtablefile = argv[argn]; + /* We postpone actually reading the file in case -quality comes later. */ + + } else if (keymatch(arg, "restart", 1)) { + /* Restart interval in MCU rows (or in MCUs with 'b'). */ + long lval; + char ch = 'x'; + + if (++argn >= argc) /* advance to next argument */ + usage(); + if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) + usage(); + if (lval < 0 || lval > 65535L) + usage(); + if (ch == 'b' || ch == 'B') { + cinfo->restart_interval = (unsigned int) lval; + cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ + } else { + cinfo->restart_in_rows = (int) lval; + /* restart_interval will be computed during startup */ + } + + } else if (keymatch(arg, "sample", 2)) { + /* Set sampling factors. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + samplearg = argv[argn]; + /* Must delay setting sample factors until after we have processed any + * colorspace-determining switches, since jpeg_set_colorspace sets + * default sampling factors. + */ + + } else if (keymatch(arg, "scale", 4)) { + /* Scale the image by a fraction M/N. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + if (sscanf(argv[argn], "%d/%d", + &cinfo->scale_num, &cinfo->scale_denom) != 2) + usage(); + + } else if (keymatch(arg, "scans", 4)) { + /* Set scan script. */ +#ifdef C_MULTISCAN_FILES_SUPPORTED + if (++argn >= argc) /* advance to next argument */ + usage(); + scansarg = argv[argn]; + /* We must postpone reading the file in case -progressive appears. */ +#else + fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n", + progname); + exit(EXIT_FAILURE); +#endif + + } else if (keymatch(arg, "smooth", 2)) { + /* Set input smoothing factor. */ + int val; + + if (++argn >= argc) /* advance to next argument */ + usage(); + if (sscanf(argv[argn], "%d", &val) != 1) + usage(); + if (val < 0 || val > 100) + usage(); + cinfo->smoothing_factor = val; + + } else if (keymatch(arg, "targa", 1)) { + /* Input file is Targa format. */ + is_targa = TRUE; + + } else { + usage(); /* bogus switch */ + } + } + + /* Post-switch-scanning cleanup */ + + if (for_real) { + + /* Set quantization tables for selected quality. */ + /* Some or all may be overridden if -qtables is present. */ + if (qualityarg != NULL) /* process -quality if it was present */ + if (! set_quality_ratings(cinfo, qualityarg, force_baseline)) + usage(); + + if (qtablefile != NULL) /* process -qtables if it was present */ + if (! read_quant_tables(cinfo, qtablefile, force_baseline)) + usage(); + + if (qslotsarg != NULL) /* process -qslots if it was present */ + if (! set_quant_slots(cinfo, qslotsarg)) + usage(); + + if (samplearg != NULL) /* process -sample if it was present */ + if (! set_sample_factors(cinfo, samplearg)) + usage(); + +#ifdef C_PROGRESSIVE_SUPPORTED + if (simple_progressive) /* process -progressive; -scans can override */ + jpeg_simple_progression(cinfo); +#endif + +#ifdef C_MULTISCAN_FILES_SUPPORTED + if (scansarg != NULL) /* process -scans if it was present */ + if (! read_scan_script(cinfo, scansarg)) + usage(); +#endif + } + + return argn; /* return index of next arg (file name) */ +} + + +/* + * The main program. + */ + +int +main (int argc, char **argv) +{ + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; +#ifdef PROGRESS_REPORT + struct cdjpeg_progress_mgr progress; +#endif + int file_index; + cjpeg_source_ptr src_mgr; + FILE * input_file; + FILE * output_file; + JDIMENSION num_scanlines; + + /* On Mac, fetch a command line. */ +#ifdef USE_CCOMMAND + argc = ccommand(&argv); +#endif + + progname = argv[0]; + if (progname == NULL || progname[0] == 0) + progname = "cjpeg"; /* in case C library doesn't provide it */ + + /* Initialize the JPEG compression object with default error handling. */ + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_compress(&cinfo); + /* Add some application-specific error messages (from cderror.h) */ + jerr.addon_message_table = cdjpeg_message_table; + jerr.first_addon_message = JMSG_FIRSTADDONCODE; + jerr.last_addon_message = JMSG_LASTADDONCODE; + + /* Now safe to enable signal catcher. */ +#ifdef NEED_SIGNAL_CATCHER + enable_signal_catcher((j_common_ptr) &cinfo); +#endif + + /* Initialize JPEG parameters. + * Much of this may be overridden later. + * In particular, we don't yet know the input file's color space, + * but we need to provide some value for jpeg_set_defaults() to work. + */ + + cinfo.in_color_space = JCS_RGB; /* arbitrary guess */ + jpeg_set_defaults(&cinfo); + + /* Scan command line to find file names. + * It is convenient to use just one switch-parsing routine, but the switch + * values read here are ignored; we will rescan the switches after opening + * the input file. + */ + + file_index = parse_switches(&cinfo, argc, argv, 0, FALSE); + +#ifdef TWO_FILE_COMMANDLINE + /* Must have either -outfile switch or explicit output file name */ + if (outfilename == NULL) { + if (file_index != argc-2) { + fprintf(stderr, "%s: must name one input and one output file\n", + progname); + usage(); + } + outfilename = argv[file_index+1]; + } else { + if (file_index != argc-1) { + fprintf(stderr, "%s: must name one input and one output file\n", + progname); + usage(); + } + } +#else + /* Unix style: expect zero or one file name */ + if (file_index < argc-1) { + fprintf(stderr, "%s: only one input file\n", progname); + usage(); + } +#endif /* TWO_FILE_COMMANDLINE */ + + /* Open the input file. */ + if (file_index < argc) { + if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); + exit(EXIT_FAILURE); + } + } else { + /* default input file is stdin */ + input_file = read_stdin(); + } + + /* Open the output file. */ + if (outfilename != NULL) { + if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open %s\n", progname, outfilename); + exit(EXIT_FAILURE); + } + } else { + /* default output file is stdout */ + output_file = write_stdout(); + } + +#ifdef PROGRESS_REPORT + start_progress_monitor((j_common_ptr) &cinfo, &progress); +#endif + + /* Figure out the input file format, and set up to read it. */ + src_mgr = select_file_type(&cinfo, input_file); + src_mgr->input_file = input_file; + + /* Read the input file header to obtain file size & colorspace. */ + (*src_mgr->start_input) (&cinfo, src_mgr); + + /* Now that we know input colorspace, fix colorspace-dependent defaults */ + jpeg_default_colorspace(&cinfo); + + /* Adjust default compression parameters by re-parsing the options */ + file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); + + /* Specify data destination for compression */ + jpeg_stdio_dest(&cinfo, output_file); + + /* Start compressor */ + jpeg_start_compress(&cinfo, TRUE); + + /* Process data */ + while (cinfo.next_scanline < cinfo.image_height) { + num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr); + (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines); + } + + /* Finish compression and release memory */ + (*src_mgr->finish_input) (&cinfo, src_mgr); + jpeg_finish_compress(&cinfo); + jpeg_destroy_compress(&cinfo); + + /* Close files, if we opened them */ + if (input_file != stdin) + fclose(input_file); + if (output_file != stdout) + fclose(output_file); + +#ifdef PROGRESS_REPORT + end_progress_monitor((j_common_ptr) &cinfo); +#endif + + /* All done. */ + exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); + return 0; /* suppress no-return-value warnings */ +} diff --git a/Source/LibJPEG/ckconfig.c b/Source/LibJPEG/ckconfig.c index fb9429a..e658623 100644 --- a/Source/LibJPEG/ckconfig.c +++ b/Source/LibJPEG/ckconfig.c @@ -1,402 +1,402 @@ -/* - * ckconfig.c - * - * Copyright (C) 1991-1994, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - */ - -/* - * This program is intended to help you determine how to configure the JPEG - * software for installation on a particular system. The idea is to try to - * compile and execute this program. If your compiler fails to compile the - * program, make changes as indicated in the comments below. Once you can - * compile the program, run it, and it will produce a "jconfig.h" file for - * your system. - * - * As a general rule, each time you try to compile this program, - * pay attention only to the *first* error message you get from the compiler. - * Many C compilers will issue lots of spurious error messages once they - * have gotten confused. Go to the line indicated in the first error message, - * and read the comments preceding that line to see what to change. - * - * Almost all of the edits you may need to make to this program consist of - * changing a line that reads "#define SOME_SYMBOL" to "#undef SOME_SYMBOL", - * or vice versa. This is called defining or undefining that symbol. - */ - - -/* First we must see if your system has the include files we need. - * We start out with the assumption that your system has all the ANSI-standard - * include files. If you get any error trying to include one of these files, - * undefine the corresponding HAVE_xxx symbol. - */ - -#define HAVE_STDDEF_H /* replace 'define' by 'undef' if error here */ -#ifdef HAVE_STDDEF_H /* next line will be skipped if you undef... */ -#include -#endif - -#define HAVE_STDLIB_H /* same thing for stdlib.h */ -#ifdef HAVE_STDLIB_H -#include -#endif - -#include /* If you ain't got this, you ain't got C. */ - -/* We have to see if your string functions are defined by - * strings.h (old BSD convention) or string.h (everybody else). - * We try the non-BSD convention first; define NEED_BSD_STRINGS - * if the compiler says it can't find string.h. - */ - -#undef NEED_BSD_STRINGS - -#ifdef NEED_BSD_STRINGS -#include -#else -#include -#endif - -/* On some systems (especially older Unix machines), type size_t is - * defined only in the include file . If you get a failure - * on the size_t test below, try defining NEED_SYS_TYPES_H. - */ - -#undef NEED_SYS_TYPES_H /* start by assuming we don't need it */ -#ifdef NEED_SYS_TYPES_H -#include -#endif - - -/* Usually type size_t is defined in one of the include files we've included - * above. If not, you'll get an error on the "typedef size_t my_size_t;" line. - * In that case, first try defining NEED_SYS_TYPES_H just above. - * If that doesn't work, you'll have to search through your system library - * to figure out which include file defines "size_t". Look for a line that - * says "typedef something-or-other size_t;". Then, change the line below - * that says "#include " to instead include the file - * you found size_t in, and define NEED_SPECIAL_INCLUDE. If you can't find - * type size_t anywhere, try replacing "#include " with - * "typedef unsigned int size_t;". - */ - -#undef NEED_SPECIAL_INCLUDE /* assume we DON'T need it, for starters */ - -#ifdef NEED_SPECIAL_INCLUDE -#include -#endif - -typedef size_t my_size_t; /* The payoff: do we have size_t now? */ - - -/* The next question is whether your compiler supports ANSI-style function - * prototypes. You need to know this in order to choose between using - * makefile.ansi and using makefile.unix. - * The #define line below is set to assume you have ANSI function prototypes. - * If you get an error in this group of lines, undefine HAVE_PROTOTYPES. - */ - -#define HAVE_PROTOTYPES - -#ifdef HAVE_PROTOTYPES -int testfunction (int arg1, int * arg2); /* check prototypes */ - -struct methods_struct { /* check method-pointer declarations */ - int (*error_exit) (char *msgtext); - int (*trace_message) (char *msgtext); - int (*another_method) (void); -}; - -int testfunction (int arg1, int * arg2) /* check definitions */ -{ - return arg2[arg1]; -} - -int test2function (void) /* check void arg list */ -{ - return 0; -} -#endif - - -/* Now we want to find out if your compiler knows what "unsigned char" means. - * If you get an error on the "unsigned char un_char;" line, - * then undefine HAVE_UNSIGNED_CHAR. - */ - -#define HAVE_UNSIGNED_CHAR - -#ifdef HAVE_UNSIGNED_CHAR -unsigned char un_char; -#endif - - -/* Now we want to find out if your compiler knows what "unsigned short" means. - * If you get an error on the "unsigned short un_short;" line, - * then undefine HAVE_UNSIGNED_SHORT. - */ - -#define HAVE_UNSIGNED_SHORT - -#ifdef HAVE_UNSIGNED_SHORT -unsigned short un_short; -#endif - - -/* Now we want to find out if your compiler understands type "void". - * If you get an error anywhere in here, undefine HAVE_VOID. - */ - -#define HAVE_VOID - -#ifdef HAVE_VOID -/* Caution: a C++ compiler will insist on complete prototypes */ -typedef void * void_ptr; /* check void * */ -#ifdef HAVE_PROTOTYPES /* check ptr to function returning void */ -typedef void (*void_func) (int a, int b); -#else -typedef void (*void_func) (); -#endif - -#ifdef HAVE_PROTOTYPES /* check void function result */ -void test3function (void_ptr arg1, void_func arg2) -#else -void test3function (arg1, arg2) - void_ptr arg1; - void_func arg2; -#endif -{ - char * locptr = (char *) arg1; /* check casting to and from void * */ - arg1 = (void *) locptr; - (*arg2) (1, 2); /* check call of fcn returning void */ -} -#endif - - -/* Now we want to find out if your compiler knows what "const" means. - * If you get an error here, undefine HAVE_CONST. - */ - -#define HAVE_CONST - -#ifdef HAVE_CONST -static const int carray[3] = {1, 2, 3}; - -#ifdef HAVE_PROTOTYPES -int test4function (const int arg1) -#else -int test4function (arg1) - const int arg1; -#endif -{ - return carray[arg1]; -} -#endif - - -/* If you get an error or warning about this structure definition, - * define INCOMPLETE_TYPES_BROKEN. - */ - -#undef INCOMPLETE_TYPES_BROKEN - -#ifndef INCOMPLETE_TYPES_BROKEN -typedef struct undefined_structure * undef_struct_ptr; -#endif - - -/* If you get an error about duplicate names, - * define NEED_SHORT_EXTERNAL_NAMES. - */ - -#undef NEED_SHORT_EXTERNAL_NAMES - -#ifndef NEED_SHORT_EXTERNAL_NAMES - -int possibly_duplicate_function () -{ - return 0; -} - -int possibly_dupli_function () -{ - return 1; -} - -#endif - - - -/************************************************************************ - * OK, that's it. You should not have to change anything beyond this - * point in order to compile and execute this program. (You might get - * some warnings, but you can ignore them.) - * When you run the program, it will make a couple more tests that it - * can do automatically, and then it will create jconfig.h and print out - * any additional suggestions it has. - ************************************************************************ - */ - - -#ifdef HAVE_PROTOTYPES -int is_char_signed (int arg) -#else -int is_char_signed (arg) - int arg; -#endif -{ - if (arg == 189) { /* expected result for unsigned char */ - return 0; /* type char is unsigned */ - } - else if (arg != -67) { /* expected result for signed char */ - printf("Hmm, it seems 'char' is not eight bits wide on your machine.\n"); - printf("I fear the JPEG software will not work at all.\n\n"); - } - return 1; /* assume char is signed otherwise */ -} - - -#ifdef HAVE_PROTOTYPES -int is_shifting_signed (long arg) -#else -int is_shifting_signed (arg) - long arg; -#endif -/* See whether right-shift on a long is signed or not. */ -{ - long res = arg >> 4; - - if (res == -0x7F7E80CL) { /* expected result for signed shift */ - return 1; /* right shift is signed */ - } - /* see if unsigned-shift hack will fix it. */ - /* we can't just test exact value since it depends on width of long... */ - res |= (~0L) << (32-4); - if (res == -0x7F7E80CL) { /* expected result now? */ - return 0; /* right shift is unsigned */ - } - printf("Right shift isn't acting as I expect it to.\n"); - printf("I fear the JPEG software will not work at all.\n\n"); - return 0; /* try it with unsigned anyway */ -} - - -#ifdef HAVE_PROTOTYPES -int main (int argc, char ** argv) -#else -int main (argc, argv) - int argc; - char ** argv; -#endif -{ - char signed_char_check = (char) (-67); - FILE *outfile; - - /* Attempt to write jconfig.h */ - if ((outfile = fopen("jconfig.h", "w")) == NULL) { - printf("Failed to write jconfig.h\n"); - return 1; - } - - /* Write out all the info */ - fprintf(outfile, "/* jconfig.h --- generated by ckconfig.c */\n"); - fprintf(outfile, "/* see jconfig.txt for explanations */\n\n"); -#ifdef HAVE_PROTOTYPES - fprintf(outfile, "#define HAVE_PROTOTYPES\n"); -#else - fprintf(outfile, "#undef HAVE_PROTOTYPES\n"); -#endif -#ifdef HAVE_UNSIGNED_CHAR - fprintf(outfile, "#define HAVE_UNSIGNED_CHAR\n"); -#else - fprintf(outfile, "#undef HAVE_UNSIGNED_CHAR\n"); -#endif -#ifdef HAVE_UNSIGNED_SHORT - fprintf(outfile, "#define HAVE_UNSIGNED_SHORT\n"); -#else - fprintf(outfile, "#undef HAVE_UNSIGNED_SHORT\n"); -#endif -#ifdef HAVE_VOID - fprintf(outfile, "/* #define void char */\n"); -#else - fprintf(outfile, "#define void char\n"); -#endif -#ifdef HAVE_CONST - fprintf(outfile, "/* #define const */\n"); -#else - fprintf(outfile, "#define const\n"); -#endif - if (is_char_signed((int) signed_char_check)) - fprintf(outfile, "#undef CHAR_IS_UNSIGNED\n"); - else - fprintf(outfile, "#define CHAR_IS_UNSIGNED\n"); -#ifdef HAVE_STDDEF_H - fprintf(outfile, "#define HAVE_STDDEF_H\n"); -#else - fprintf(outfile, "#undef HAVE_STDDEF_H\n"); -#endif -#ifdef HAVE_STDLIB_H - fprintf(outfile, "#define HAVE_STDLIB_H\n"); -#else - fprintf(outfile, "#undef HAVE_STDLIB_H\n"); -#endif -#ifdef NEED_BSD_STRINGS - fprintf(outfile, "#define NEED_BSD_STRINGS\n"); -#else - fprintf(outfile, "#undef NEED_BSD_STRINGS\n"); -#endif -#ifdef NEED_SYS_TYPES_H - fprintf(outfile, "#define NEED_SYS_TYPES_H\n"); -#else - fprintf(outfile, "#undef NEED_SYS_TYPES_H\n"); -#endif - fprintf(outfile, "#undef NEED_FAR_POINTERS\n"); -#ifdef NEED_SHORT_EXTERNAL_NAMES - fprintf(outfile, "#define NEED_SHORT_EXTERNAL_NAMES\n"); -#else - fprintf(outfile, "#undef NEED_SHORT_EXTERNAL_NAMES\n"); -#endif -#ifdef INCOMPLETE_TYPES_BROKEN - fprintf(outfile, "#define INCOMPLETE_TYPES_BROKEN\n"); -#else - fprintf(outfile, "#undef INCOMPLETE_TYPES_BROKEN\n"); -#endif - fprintf(outfile, "\n#ifdef JPEG_INTERNALS\n\n"); - if (is_shifting_signed(-0x7F7E80B1L)) - fprintf(outfile, "#undef RIGHT_SHIFT_IS_UNSIGNED\n"); - else - fprintf(outfile, "#define RIGHT_SHIFT_IS_UNSIGNED\n"); - fprintf(outfile, "\n#endif /* JPEG_INTERNALS */\n"); - fprintf(outfile, "\n#ifdef JPEG_CJPEG_DJPEG\n\n"); - fprintf(outfile, "#define BMP_SUPPORTED /* BMP image file format */\n"); - fprintf(outfile, "#define GIF_SUPPORTED /* GIF image file format */\n"); - fprintf(outfile, "#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */\n"); - fprintf(outfile, "#undef RLE_SUPPORTED /* Utah RLE image file format */\n"); - fprintf(outfile, "#define TARGA_SUPPORTED /* Targa image file format */\n\n"); - fprintf(outfile, "#undef TWO_FILE_COMMANDLINE /* You may need this on non-Unix systems */\n"); - fprintf(outfile, "#undef NEED_SIGNAL_CATCHER /* Define this if you use jmemname.c */\n"); - fprintf(outfile, "#undef DONT_USE_B_MODE\n"); - fprintf(outfile, "/* #define PROGRESS_REPORT */ /* optional */\n"); - fprintf(outfile, "\n#endif /* JPEG_CJPEG_DJPEG */\n"); - - /* Close the jconfig.h file */ - fclose(outfile); - - /* User report */ - printf("Configuration check for Independent JPEG Group's software done.\n"); - printf("\nI have written the jconfig.h file for you.\n\n"); -#ifdef HAVE_PROTOTYPES - printf("You should use makefile.ansi as the starting point for your Makefile.\n"); -#else - printf("You should use makefile.unix as the starting point for your Makefile.\n"); -#endif - -#ifdef NEED_SPECIAL_INCLUDE - printf("\nYou'll need to change jconfig.h to include the system include file\n"); - printf("that you found type size_t in, or add a direct definition of type\n"); - printf("size_t if that's what you used. Just add it to the end.\n"); -#endif - - return 0; -} +/* + * ckconfig.c + * + * Copyright (C) 1991-1994, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + */ + +/* + * This program is intended to help you determine how to configure the JPEG + * software for installation on a particular system. The idea is to try to + * compile and execute this program. If your compiler fails to compile the + * program, make changes as indicated in the comments below. Once you can + * compile the program, run it, and it will produce a "jconfig.h" file for + * your system. + * + * As a general rule, each time you try to compile this program, + * pay attention only to the *first* error message you get from the compiler. + * Many C compilers will issue lots of spurious error messages once they + * have gotten confused. Go to the line indicated in the first error message, + * and read the comments preceding that line to see what to change. + * + * Almost all of the edits you may need to make to this program consist of + * changing a line that reads "#define SOME_SYMBOL" to "#undef SOME_SYMBOL", + * or vice versa. This is called defining or undefining that symbol. + */ + + +/* First we must see if your system has the include files we need. + * We start out with the assumption that your system has all the ANSI-standard + * include files. If you get any error trying to include one of these files, + * undefine the corresponding HAVE_xxx symbol. + */ + +#define HAVE_STDDEF_H /* replace 'define' by 'undef' if error here */ +#ifdef HAVE_STDDEF_H /* next line will be skipped if you undef... */ +#include +#endif + +#define HAVE_STDLIB_H /* same thing for stdlib.h */ +#ifdef HAVE_STDLIB_H +#include +#endif + +#include /* If you ain't got this, you ain't got C. */ + +/* We have to see if your string functions are defined by + * strings.h (old BSD convention) or string.h (everybody else). + * We try the non-BSD convention first; define NEED_BSD_STRINGS + * if the compiler says it can't find string.h. + */ + +#undef NEED_BSD_STRINGS + +#ifdef NEED_BSD_STRINGS +#include +#else +#include +#endif + +/* On some systems (especially older Unix machines), type size_t is + * defined only in the include file . If you get a failure + * on the size_t test below, try defining NEED_SYS_TYPES_H. + */ + +#undef NEED_SYS_TYPES_H /* start by assuming we don't need it */ +#ifdef NEED_SYS_TYPES_H +#include +#endif + + +/* Usually type size_t is defined in one of the include files we've included + * above. If not, you'll get an error on the "typedef size_t my_size_t;" line. + * In that case, first try defining NEED_SYS_TYPES_H just above. + * If that doesn't work, you'll have to search through your system library + * to figure out which include file defines "size_t". Look for a line that + * says "typedef something-or-other size_t;". Then, change the line below + * that says "#include " to instead include the file + * you found size_t in, and define NEED_SPECIAL_INCLUDE. If you can't find + * type size_t anywhere, try replacing "#include " with + * "typedef unsigned int size_t;". + */ + +#undef NEED_SPECIAL_INCLUDE /* assume we DON'T need it, for starters */ + +#ifdef NEED_SPECIAL_INCLUDE +#include +#endif + +typedef size_t my_size_t; /* The payoff: do we have size_t now? */ + + +/* The next question is whether your compiler supports ANSI-style function + * prototypes. You need to know this in order to choose between using + * makefile.ansi and using makefile.unix. + * The #define line below is set to assume you have ANSI function prototypes. + * If you get an error in this group of lines, undefine HAVE_PROTOTYPES. + */ + +#define HAVE_PROTOTYPES + +#ifdef HAVE_PROTOTYPES +int testfunction (int arg1, int * arg2); /* check prototypes */ + +struct methods_struct { /* check method-pointer declarations */ + int (*error_exit) (char *msgtext); + int (*trace_message) (char *msgtext); + int (*another_method) (void); +}; + +int testfunction (int arg1, int * arg2) /* check definitions */ +{ + return arg2[arg1]; +} + +int test2function (void) /* check void arg list */ +{ + return 0; +} +#endif + + +/* Now we want to find out if your compiler knows what "unsigned char" means. + * If you get an error on the "unsigned char un_char;" line, + * then undefine HAVE_UNSIGNED_CHAR. + */ + +#define HAVE_UNSIGNED_CHAR + +#ifdef HAVE_UNSIGNED_CHAR +unsigned char un_char; +#endif + + +/* Now we want to find out if your compiler knows what "unsigned short" means. + * If you get an error on the "unsigned short un_short;" line, + * then undefine HAVE_UNSIGNED_SHORT. + */ + +#define HAVE_UNSIGNED_SHORT + +#ifdef HAVE_UNSIGNED_SHORT +unsigned short un_short; +#endif + + +/* Now we want to find out if your compiler understands type "void". + * If you get an error anywhere in here, undefine HAVE_VOID. + */ + +#define HAVE_VOID + +#ifdef HAVE_VOID +/* Caution: a C++ compiler will insist on complete prototypes */ +typedef void * void_ptr; /* check void * */ +#ifdef HAVE_PROTOTYPES /* check ptr to function returning void */ +typedef void (*void_func) (int a, int b); +#else +typedef void (*void_func) (); +#endif + +#ifdef HAVE_PROTOTYPES /* check void function result */ +void test3function (void_ptr arg1, void_func arg2) +#else +void test3function (arg1, arg2) + void_ptr arg1; + void_func arg2; +#endif +{ + char * locptr = (char *) arg1; /* check casting to and from void * */ + arg1 = (void *) locptr; + (*arg2) (1, 2); /* check call of fcn returning void */ +} +#endif + + +/* Now we want to find out if your compiler knows what "const" means. + * If you get an error here, undefine HAVE_CONST. + */ + +#define HAVE_CONST + +#ifdef HAVE_CONST +static const int carray[3] = {1, 2, 3}; + +#ifdef HAVE_PROTOTYPES +int test4function (const int arg1) +#else +int test4function (arg1) + const int arg1; +#endif +{ + return carray[arg1]; +} +#endif + + +/* If you get an error or warning about this structure definition, + * define INCOMPLETE_TYPES_BROKEN. + */ + +#undef INCOMPLETE_TYPES_BROKEN + +#ifndef INCOMPLETE_TYPES_BROKEN +typedef struct undefined_structure * undef_struct_ptr; +#endif + + +/* If you get an error about duplicate names, + * define NEED_SHORT_EXTERNAL_NAMES. + */ + +#undef NEED_SHORT_EXTERNAL_NAMES + +#ifndef NEED_SHORT_EXTERNAL_NAMES + +int possibly_duplicate_function () +{ + return 0; +} + +int possibly_dupli_function () +{ + return 1; +} + +#endif + + + +/************************************************************************ + * OK, that's it. You should not have to change anything beyond this + * point in order to compile and execute this program. (You might get + * some warnings, but you can ignore them.) + * When you run the program, it will make a couple more tests that it + * can do automatically, and then it will create jconfig.h and print out + * any additional suggestions it has. + ************************************************************************ + */ + + +#ifdef HAVE_PROTOTYPES +int is_char_signed (int arg) +#else +int is_char_signed (arg) + int arg; +#endif +{ + if (arg == 189) { /* expected result for unsigned char */ + return 0; /* type char is unsigned */ + } + else if (arg != -67) { /* expected result for signed char */ + printf("Hmm, it seems 'char' is not eight bits wide on your machine.\n"); + printf("I fear the JPEG software will not work at all.\n\n"); + } + return 1; /* assume char is signed otherwise */ +} + + +#ifdef HAVE_PROTOTYPES +int is_shifting_signed (long arg) +#else +int is_shifting_signed (arg) + long arg; +#endif +/* See whether right-shift on a long is signed or not. */ +{ + long res = arg >> 4; + + if (res == -0x7F7E80CL) { /* expected result for signed shift */ + return 1; /* right shift is signed */ + } + /* see if unsigned-shift hack will fix it. */ + /* we can't just test exact value since it depends on width of long... */ + res |= (~0L) << (32-4); + if (res == -0x7F7E80CL) { /* expected result now? */ + return 0; /* right shift is unsigned */ + } + printf("Right shift isn't acting as I expect it to.\n"); + printf("I fear the JPEG software will not work at all.\n\n"); + return 0; /* try it with unsigned anyway */ +} + + +#ifdef HAVE_PROTOTYPES +int main (int argc, char ** argv) +#else +int main (argc, argv) + int argc; + char ** argv; +#endif +{ + char signed_char_check = (char) (-67); + FILE *outfile; + + /* Attempt to write jconfig.h */ + if ((outfile = fopen("jconfig.h", "w")) == NULL) { + printf("Failed to write jconfig.h\n"); + return 1; + } + + /* Write out all the info */ + fprintf(outfile, "/* jconfig.h --- generated by ckconfig.c */\n"); + fprintf(outfile, "/* see jconfig.txt for explanations */\n\n"); +#ifdef HAVE_PROTOTYPES + fprintf(outfile, "#define HAVE_PROTOTYPES\n"); +#else + fprintf(outfile, "#undef HAVE_PROTOTYPES\n"); +#endif +#ifdef HAVE_UNSIGNED_CHAR + fprintf(outfile, "#define HAVE_UNSIGNED_CHAR\n"); +#else + fprintf(outfile, "#undef HAVE_UNSIGNED_CHAR\n"); +#endif +#ifdef HAVE_UNSIGNED_SHORT + fprintf(outfile, "#define HAVE_UNSIGNED_SHORT\n"); +#else + fprintf(outfile, "#undef HAVE_UNSIGNED_SHORT\n"); +#endif +#ifdef HAVE_VOID + fprintf(outfile, "/* #define void char */\n"); +#else + fprintf(outfile, "#define void char\n"); +#endif +#ifdef HAVE_CONST + fprintf(outfile, "/* #define const */\n"); +#else + fprintf(outfile, "#define const\n"); +#endif + if (is_char_signed((int) signed_char_check)) + fprintf(outfile, "#undef CHAR_IS_UNSIGNED\n"); + else + fprintf(outfile, "#define CHAR_IS_UNSIGNED\n"); +#ifdef HAVE_STDDEF_H + fprintf(outfile, "#define HAVE_STDDEF_H\n"); +#else + fprintf(outfile, "#undef HAVE_STDDEF_H\n"); +#endif +#ifdef HAVE_STDLIB_H + fprintf(outfile, "#define HAVE_STDLIB_H\n"); +#else + fprintf(outfile, "#undef HAVE_STDLIB_H\n"); +#endif +#ifdef NEED_BSD_STRINGS + fprintf(outfile, "#define NEED_BSD_STRINGS\n"); +#else + fprintf(outfile, "#undef NEED_BSD_STRINGS\n"); +#endif +#ifdef NEED_SYS_TYPES_H + fprintf(outfile, "#define NEED_SYS_TYPES_H\n"); +#else + fprintf(outfile, "#undef NEED_SYS_TYPES_H\n"); +#endif + fprintf(outfile, "#undef NEED_FAR_POINTERS\n"); +#ifdef NEED_SHORT_EXTERNAL_NAMES + fprintf(outfile, "#define NEED_SHORT_EXTERNAL_NAMES\n"); +#else + fprintf(outfile, "#undef NEED_SHORT_EXTERNAL_NAMES\n"); +#endif +#ifdef INCOMPLETE_TYPES_BROKEN + fprintf(outfile, "#define INCOMPLETE_TYPES_BROKEN\n"); +#else + fprintf(outfile, "#undef INCOMPLETE_TYPES_BROKEN\n"); +#endif + fprintf(outfile, "\n#ifdef JPEG_INTERNALS\n\n"); + if (is_shifting_signed(-0x7F7E80B1L)) + fprintf(outfile, "#undef RIGHT_SHIFT_IS_UNSIGNED\n"); + else + fprintf(outfile, "#define RIGHT_SHIFT_IS_UNSIGNED\n"); + fprintf(outfile, "\n#endif /* JPEG_INTERNALS */\n"); + fprintf(outfile, "\n#ifdef JPEG_CJPEG_DJPEG\n\n"); + fprintf(outfile, "#define BMP_SUPPORTED /* BMP image file format */\n"); + fprintf(outfile, "#define GIF_SUPPORTED /* GIF image file format */\n"); + fprintf(outfile, "#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */\n"); + fprintf(outfile, "#undef RLE_SUPPORTED /* Utah RLE image file format */\n"); + fprintf(outfile, "#define TARGA_SUPPORTED /* Targa image file format */\n\n"); + fprintf(outfile, "#undef TWO_FILE_COMMANDLINE /* You may need this on non-Unix systems */\n"); + fprintf(outfile, "#undef NEED_SIGNAL_CATCHER /* Define this if you use jmemname.c */\n"); + fprintf(outfile, "#undef DONT_USE_B_MODE\n"); + fprintf(outfile, "/* #define PROGRESS_REPORT */ /* optional */\n"); + fprintf(outfile, "\n#endif /* JPEG_CJPEG_DJPEG */\n"); + + /* Close the jconfig.h file */ + fclose(outfile); + + /* User report */ + printf("Configuration check for Independent JPEG Group's software done.\n"); + printf("\nI have written the jconfig.h file for you.\n\n"); +#ifdef HAVE_PROTOTYPES + printf("You should use makefile.ansi as the starting point for your Makefile.\n"); +#else + printf("You should use makefile.unix as the starting point for your Makefile.\n"); +#endif + +#ifdef NEED_SPECIAL_INCLUDE + printf("\nYou'll need to change jconfig.h to include the system include file\n"); + printf("that you found type size_t in, or add a direct definition of type\n"); + printf("size_t if that's what you used. Just add it to the end.\n"); +#endif + + return 0; +} diff --git a/Source/LibJPEG/coderules.txt b/Source/LibJPEG/coderules.txt index 382efad..357929f 100644 --- a/Source/LibJPEG/coderules.txt +++ b/Source/LibJPEG/coderules.txt @@ -1,118 +1,118 @@ -IJG JPEG LIBRARY: CODING RULES - -Copyright (C) 1991-1996, Thomas G. Lane. -This file is part of the Independent JPEG Group's software. -For conditions of distribution and use, see the accompanying README file. - - -Since numerous people will be contributing code and bug fixes, it's important -to establish a common coding style. The goal of using similar coding styles -is much more important than the details of just what that style is. - -In general we follow the recommendations of "Recommended C Style and Coding -Standards" revision 6.1 (Cannon et al. as modified by Spencer, Keppel and -Brader). This document is available in the IJG FTP archive (see -jpeg/doc/cstyle.ms.tbl.Z, or cstyle.txt.Z for those without nroff/tbl). - -Block comments should be laid out thusly: - -/* - * Block comments in this style. - */ - -We indent statements in K&R style, e.g., - if (test) { - then-part; - } else { - else-part; - } -with two spaces per indentation level. (This indentation convention is -handled automatically by GNU Emacs and many other text editors.) - -Multi-word names should be written in lower case with underscores, e.g., -multi_word_name (not multiWordName). Preprocessor symbols and enum constants -are similar but upper case (MULTI_WORD_NAME). Names should be unique within -the first fifteen characters. (On some older systems, global names must be -unique within six characters. We accommodate this without cluttering the -source code by using macros to substitute shorter names.) - -We use function prototypes everywhere; we rely on automatic source code -transformation to feed prototype-less C compilers. Transformation is done -by the simple and portable tool 'ansi2knr.c' (courtesy of Ghostscript). -ansi2knr is not very bright, so it imposes a format requirement on function -declarations: the function name MUST BEGIN IN COLUMN 1. Thus all functions -should be written in the following style: - -LOCAL(int *) -function_name (int a, char *b) -{ - code... -} - -Note that each function definition must begin with GLOBAL(type), LOCAL(type), -or METHODDEF(type). These macros expand to "static type" or just "type" as -appropriate. They provide a readable indication of the routine's usage and -can readily be changed for special needs. (For instance, special linkage -keywords can be inserted for use in Windows DLLs.) - -ansi2knr does not transform method declarations (function pointers in -structs). We handle these with a macro JMETHOD, defined as - #ifdef HAVE_PROTOTYPES - #define JMETHOD(type,methodname,arglist) type (*methodname) arglist - #else - #define JMETHOD(type,methodname,arglist) type (*methodname) () - #endif -which is used like this: - struct function_pointers { - JMETHOD(void, init_entropy_encoder, (int somearg, jparms *jp)); - JMETHOD(void, term_entropy_encoder, (void)); - }; -Note the set of parentheses surrounding the parameter list. - -A similar solution is used for forward and external function declarations -(see the EXTERN and JPP macros). - -If the code is to work on non-ANSI compilers, we cannot rely on a prototype -declaration to coerce actual parameters into the right types. Therefore, use -explicit casts on actual parameters whenever the actual parameter type is not -identical to the formal parameter. Beware of implicit conversions to "int". - -It seems there are some non-ANSI compilers in which the sizeof() operator -is defined to return int, yet size_t is defined as long. Needless to say, -this is brain-damaged. Always use the SIZEOF() macro in place of sizeof(), -so that the result is guaranteed to be of type size_t. - - -The JPEG library is intended to be used within larger programs. Furthermore, -we want it to be reentrant so that it can be used by applications that process -multiple images concurrently. The following rules support these requirements: - -1. Avoid direct use of file I/O, "malloc", error report printouts, etc; -pass these through the common routines provided. - -2. Minimize global namespace pollution. Functions should be declared static -wherever possible. (Note that our method-based calling conventions help this -a lot: in many modules only the initialization function will ever need to be -called directly, so only that function need be externally visible.) All -global function names should begin with "jpeg_", and should have an -abbreviated name (unique in the first six characters) substituted by macro -when NEED_SHORT_EXTERNAL_NAMES is set. - -3. Don't use global variables; anything that must be used in another module -should be in the common data structures. - -4. Don't use static variables except for read-only constant tables. Variables -that should be private to a module can be placed into private structures (see -the system architecture document, structure.txt). - -5. Source file names should begin with "j" for files that are part of the -library proper; source files that are not part of the library, such as cjpeg.c -and djpeg.c, do not begin with "j". Keep source file names to eight -characters (plus ".c" or ".h", etc) to make life easy for MS-DOSers. Keep -compression and decompression code in separate source files --- some -applications may want only one half of the library. - -Note: these rules (particularly #4) are not followed religiously in the -modules that are used in cjpeg/djpeg but are not part of the JPEG library -proper. Those modules are not really intended to be used in other -applications. +IJG JPEG LIBRARY: CODING RULES + +Copyright (C) 1991-1996, Thomas G. Lane. +This file is part of the Independent JPEG Group's software. +For conditions of distribution and use, see the accompanying README file. + + +Since numerous people will be contributing code and bug fixes, it's important +to establish a common coding style. The goal of using similar coding styles +is much more important than the details of just what that style is. + +In general we follow the recommendations of "Recommended C Style and Coding +Standards" revision 6.1 (Cannon et al. as modified by Spencer, Keppel and +Brader). This document is available in the IJG FTP archive (see +jpeg/doc/cstyle.ms.tbl.Z, or cstyle.txt.Z for those without nroff/tbl). + +Block comments should be laid out thusly: + +/* + * Block comments in this style. + */ + +We indent statements in K&R style, e.g., + if (test) { + then-part; + } else { + else-part; + } +with two spaces per indentation level. (This indentation convention is +handled automatically by GNU Emacs and many other text editors.) + +Multi-word names should be written in lower case with underscores, e.g., +multi_word_name (not multiWordName). Preprocessor symbols and enum constants +are similar but upper case (MULTI_WORD_NAME). Names should be unique within +the first fifteen characters. (On some older systems, global names must be +unique within six characters. We accommodate this without cluttering the +source code by using macros to substitute shorter names.) + +We use function prototypes everywhere; we rely on automatic source code +transformation to feed prototype-less C compilers. Transformation is done +by the simple and portable tool 'ansi2knr.c' (courtesy of Ghostscript). +ansi2knr is not very bright, so it imposes a format requirement on function +declarations: the function name MUST BEGIN IN COLUMN 1. Thus all functions +should be written in the following style: + +LOCAL(int *) +function_name (int a, char *b) +{ + code... +} + +Note that each function definition must begin with GLOBAL(type), LOCAL(type), +or METHODDEF(type). These macros expand to "static type" or just "type" as +appropriate. They provide a readable indication of the routine's usage and +can readily be changed for special needs. (For instance, special linkage +keywords can be inserted for use in Windows DLLs.) + +ansi2knr does not transform method declarations (function pointers in +structs). We handle these with a macro JMETHOD, defined as + #ifdef HAVE_PROTOTYPES + #define JMETHOD(type,methodname,arglist) type (*methodname) arglist + #else + #define JMETHOD(type,methodname,arglist) type (*methodname) () + #endif +which is used like this: + struct function_pointers { + JMETHOD(void, init_entropy_encoder, (int somearg, jparms *jp)); + JMETHOD(void, term_entropy_encoder, (void)); + }; +Note the set of parentheses surrounding the parameter list. + +A similar solution is used for forward and external function declarations +(see the EXTERN and JPP macros). + +If the code is to work on non-ANSI compilers, we cannot rely on a prototype +declaration to coerce actual parameters into the right types. Therefore, use +explicit casts on actual parameters whenever the actual parameter type is not +identical to the formal parameter. Beware of implicit conversions to "int". + +It seems there are some non-ANSI compilers in which the sizeof() operator +is defined to return int, yet size_t is defined as long. Needless to say, +this is brain-damaged. Always use the SIZEOF() macro in place of sizeof(), +so that the result is guaranteed to be of type size_t. + + +The JPEG library is intended to be used within larger programs. Furthermore, +we want it to be reentrant so that it can be used by applications that process +multiple images concurrently. The following rules support these requirements: + +1. Avoid direct use of file I/O, "malloc", error report printouts, etc; +pass these through the common routines provided. + +2. Minimize global namespace pollution. Functions should be declared static +wherever possible. (Note that our method-based calling conventions help this +a lot: in many modules only the initialization function will ever need to be +called directly, so only that function need be externally visible.) All +global function names should begin with "jpeg_", and should have an +abbreviated name (unique in the first six characters) substituted by macro +when NEED_SHORT_EXTERNAL_NAMES is set. + +3. Don't use global variables; anything that must be used in another module +should be in the common data structures. + +4. Don't use static variables except for read-only constant tables. Variables +that should be private to a module can be placed into private structures (see +the system architecture document, structure.txt). + +5. Source file names should begin with "j" for files that are part of the +library proper; source files that are not part of the library, such as cjpeg.c +and djpeg.c, do not begin with "j". Keep source file names to eight +characters (plus ".c" or ".h", etc) to make life easy for MS-DOSers. Keep +compression and decompression code in separate source files --- some +applications may want only one half of the library. + +Note: these rules (particularly #4) are not followed religiously in the +modules that are used in cjpeg/djpeg but are not part of the JPEG library +proper. Those modules are not really intended to be used in other +applications. diff --git a/Source/LibJPEG/djpeg.c b/Source/LibJPEG/djpeg.c index 363c628..bc544dc 100644 --- a/Source/LibJPEG/djpeg.c +++ b/Source/LibJPEG/djpeg.c @@ -1,617 +1,617 @@ -/* - * djpeg.c - * - * Copyright (C) 1991-1997, Thomas G. Lane. - * Modified 2009 by Guido Vollbeding. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains a command-line user interface for the JPEG decompressor. - * It should work on any system with Unix- or MS-DOS-style command lines. - * - * Two different command line styles are permitted, depending on the - * compile-time switch TWO_FILE_COMMANDLINE: - * djpeg [options] inputfile outputfile - * djpeg [options] [inputfile] - * In the second style, output is always to standard output, which you'd - * normally redirect to a file or pipe to some other program. Input is - * either from a named file or from standard input (typically redirected). - * The second style is convenient on Unix but is unhelpful on systems that - * don't support pipes. Also, you MUST use the first style if your system - * doesn't do binary I/O to stdin/stdout. - * To simplify script writing, the "-outfile" switch is provided. The syntax - * djpeg [options] -outfile outputfile inputfile - * works regardless of which command line style is used. - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ -#include "jversion.h" /* for version message */ - -#include /* to declare isprint() */ - -#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ -#ifdef __MWERKS__ -#include /* Metrowerks needs this */ -#include /* ... and this */ -#endif -#ifdef THINK_C -#include /* Think declares it here */ -#endif -#endif - - -/* Create the add-on message string table. */ - -#define JMESSAGE(code,string) string , - -static const char * const cdjpeg_message_table[] = { -#include "cderror.h" - NULL -}; - - -/* - * This list defines the known output image formats - * (not all of which need be supported by a given version). - * You can change the default output format by defining DEFAULT_FMT; - * indeed, you had better do so if you undefine PPM_SUPPORTED. - */ - -typedef enum { - FMT_BMP, /* BMP format (Windows flavor) */ - FMT_GIF, /* GIF format */ - FMT_OS2, /* BMP format (OS/2 flavor) */ - FMT_PPM, /* PPM/PGM (PBMPLUS formats) */ - FMT_RLE, /* RLE format */ - FMT_TARGA, /* Targa format */ - FMT_TIFF /* TIFF format */ -} IMAGE_FORMATS; - -#ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */ -#define DEFAULT_FMT FMT_PPM -#endif - -static IMAGE_FORMATS requested_fmt; - - -/* - * Argument-parsing code. - * The switch parser is designed to be useful with DOS-style command line - * syntax, ie, intermixed switches and file names, where only the switches - * to the left of a given file name affect processing of that file. - * The main program in this file doesn't actually use this capability... - */ - - -static const char * progname; /* program name for error messages */ -static char * outfilename; /* for -outfile switch */ - - -LOCAL(void) -usage (void) -/* complain about bad command line */ -{ - fprintf(stderr, "usage: %s [switches] ", progname); -#ifdef TWO_FILE_COMMANDLINE - fprintf(stderr, "inputfile outputfile\n"); -#else - fprintf(stderr, "[inputfile]\n"); -#endif - - fprintf(stderr, "Switches (names may be abbreviated):\n"); - fprintf(stderr, " -colors N Reduce image to no more than N colors\n"); - fprintf(stderr, " -fast Fast, low-quality processing\n"); - fprintf(stderr, " -grayscale Force grayscale output\n"); -#ifdef IDCT_SCALING_SUPPORTED - fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n"); -#endif -#ifdef BMP_SUPPORTED - fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n", - (DEFAULT_FMT == FMT_BMP ? " (default)" : "")); -#endif -#ifdef GIF_SUPPORTED - fprintf(stderr, " -gif Select GIF output format%s\n", - (DEFAULT_FMT == FMT_GIF ? " (default)" : "")); -#endif -#ifdef BMP_SUPPORTED - fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n", - (DEFAULT_FMT == FMT_OS2 ? " (default)" : "")); -#endif -#ifdef PPM_SUPPORTED - fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n", - (DEFAULT_FMT == FMT_PPM ? " (default)" : "")); -#endif -#ifdef RLE_SUPPORTED - fprintf(stderr, " -rle Select Utah RLE output format%s\n", - (DEFAULT_FMT == FMT_RLE ? " (default)" : "")); -#endif -#ifdef TARGA_SUPPORTED - fprintf(stderr, " -targa Select Targa output format%s\n", - (DEFAULT_FMT == FMT_TARGA ? " (default)" : "")); -#endif - fprintf(stderr, "Switches for advanced users:\n"); -#ifdef DCT_ISLOW_SUPPORTED - fprintf(stderr, " -dct int Use integer DCT method%s\n", - (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); -#endif -#ifdef DCT_IFAST_SUPPORTED - fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n", - (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); -#endif -#ifdef DCT_FLOAT_SUPPORTED - fprintf(stderr, " -dct float Use floating-point DCT method%s\n", - (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); -#endif - fprintf(stderr, " -dither fs Use F-S dithering (default)\n"); - fprintf(stderr, " -dither none Don't use dithering in quantization\n"); - fprintf(stderr, " -dither ordered Use ordered dither (medium speed, quality)\n"); -#ifdef QUANT_2PASS_SUPPORTED - fprintf(stderr, " -map FILE Map to colors used in named image file\n"); -#endif - fprintf(stderr, " -nosmooth Don't use high-quality upsampling\n"); -#ifdef QUANT_1PASS_SUPPORTED - fprintf(stderr, " -onepass Use 1-pass quantization (fast, low quality)\n"); -#endif - fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); - fprintf(stderr, " -outfile name Specify name for output file\n"); - fprintf(stderr, " -verbose or -debug Emit debug output\n"); - exit(EXIT_FAILURE); -} - - -LOCAL(int) -parse_switches (j_decompress_ptr cinfo, int argc, char **argv, - int last_file_arg_seen, boolean for_real) -/* Parse optional switches. - * Returns argv[] index of first file-name argument (== argc if none). - * Any file names with indexes <= last_file_arg_seen are ignored; - * they have presumably been processed in a previous iteration. - * (Pass 0 for last_file_arg_seen on the first or only iteration.) - * for_real is FALSE on the first (dummy) pass; we may skip any expensive - * processing. - */ -{ - int argn; - char * arg; - - /* Set up default JPEG parameters. */ - requested_fmt = DEFAULT_FMT; /* set default output file format */ - outfilename = NULL; - cinfo->err->trace_level = 0; - - /* Scan command line options, adjust parameters */ - - for (argn = 1; argn < argc; argn++) { - arg = argv[argn]; - if (*arg != '-') { - /* Not a switch, must be a file name argument */ - if (argn <= last_file_arg_seen) { - outfilename = NULL; /* -outfile applies to just one input file */ - continue; /* ignore this name if previously processed */ - } - break; /* else done parsing switches */ - } - arg++; /* advance past switch marker character */ - - if (keymatch(arg, "bmp", 1)) { - /* BMP output format. */ - requested_fmt = FMT_BMP; - - } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) || - keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) { - /* Do color quantization. */ - int val; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%d", &val) != 1) - usage(); - cinfo->desired_number_of_colors = val; - cinfo->quantize_colors = TRUE; - - } else if (keymatch(arg, "dct", 2)) { - /* Select IDCT algorithm. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - if (keymatch(argv[argn], "int", 1)) { - cinfo->dct_method = JDCT_ISLOW; - } else if (keymatch(argv[argn], "fast", 2)) { - cinfo->dct_method = JDCT_IFAST; - } else if (keymatch(argv[argn], "float", 2)) { - cinfo->dct_method = JDCT_FLOAT; - } else - usage(); - - } else if (keymatch(arg, "dither", 2)) { - /* Select dithering algorithm. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - if (keymatch(argv[argn], "fs", 2)) { - cinfo->dither_mode = JDITHER_FS; - } else if (keymatch(argv[argn], "none", 2)) { - cinfo->dither_mode = JDITHER_NONE; - } else if (keymatch(argv[argn], "ordered", 2)) { - cinfo->dither_mode = JDITHER_ORDERED; - } else - usage(); - - } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { - /* Enable debug printouts. */ - /* On first -d, print version identification */ - static boolean printed_version = FALSE; - - if (! printed_version) { - fprintf(stderr, "Independent JPEG Group's DJPEG, version %s\n%s\n", - JVERSION, JCOPYRIGHT); - printed_version = TRUE; - } - cinfo->err->trace_level++; - - } else if (keymatch(arg, "fast", 1)) { - /* Select recommended processing options for quick-and-dirty output. */ - cinfo->two_pass_quantize = FALSE; - cinfo->dither_mode = JDITHER_ORDERED; - if (! cinfo->quantize_colors) /* don't override an earlier -colors */ - cinfo->desired_number_of_colors = 216; - cinfo->dct_method = JDCT_FASTEST; - cinfo->do_fancy_upsampling = FALSE; - - } else if (keymatch(arg, "gif", 1)) { - /* GIF output format. */ - requested_fmt = FMT_GIF; - - } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) { - /* Force monochrome output. */ - cinfo->out_color_space = JCS_GRAYSCALE; - - } else if (keymatch(arg, "map", 3)) { - /* Quantize to a color map taken from an input file. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - if (for_real) { /* too expensive to do twice! */ -#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ - FILE * mapfile; - - if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); - exit(EXIT_FAILURE); - } - read_color_map(cinfo, mapfile); - fclose(mapfile); - cinfo->quantize_colors = TRUE; -#else - ERREXIT(cinfo, JERR_NOT_COMPILED); -#endif - } - - } else if (keymatch(arg, "maxmemory", 3)) { - /* Maximum memory in Kb (or Mb with 'm'). */ - long lval; - char ch = 'x'; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) - usage(); - if (ch == 'm' || ch == 'M') - lval *= 1000L; - cinfo->mem->max_memory_to_use = lval * 1000L; - - } else if (keymatch(arg, "nosmooth", 3)) { - /* Suppress fancy upsampling */ - cinfo->do_fancy_upsampling = FALSE; - - } else if (keymatch(arg, "onepass", 3)) { - /* Use fast one-pass quantization. */ - cinfo->two_pass_quantize = FALSE; - - } else if (keymatch(arg, "os2", 3)) { - /* BMP output format (OS/2 flavor). */ - requested_fmt = FMT_OS2; - - } else if (keymatch(arg, "outfile", 4)) { - /* Set output file name. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - outfilename = argv[argn]; /* save it away for later use */ - - } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) { - /* PPM/PGM output format. */ - requested_fmt = FMT_PPM; - - } else if (keymatch(arg, "rle", 1)) { - /* RLE output format. */ - requested_fmt = FMT_RLE; - - } else if (keymatch(arg, "scale", 1)) { - /* Scale the output image by a fraction M/N. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%d/%d", - &cinfo->scale_num, &cinfo->scale_denom) < 1) - usage(); - - } else if (keymatch(arg, "targa", 1)) { - /* Targa output format. */ - requested_fmt = FMT_TARGA; - - } else { - usage(); /* bogus switch */ - } - } - - return argn; /* return index of next arg (file name) */ -} - - -/* - * Marker processor for COM and interesting APPn markers. - * This replaces the library's built-in processor, which just skips the marker. - * We want to print out the marker as text, to the extent possible. - * Note this code relies on a non-suspending data source. - */ - -LOCAL(unsigned int) -jpeg_getc (j_decompress_ptr cinfo) -/* Read next byte */ -{ - struct jpeg_source_mgr * datasrc = cinfo->src; - - if (datasrc->bytes_in_buffer == 0) { - if (! (*datasrc->fill_input_buffer) (cinfo)) - ERREXIT(cinfo, JERR_CANT_SUSPEND); - } - datasrc->bytes_in_buffer--; - return GETJOCTET(*datasrc->next_input_byte++); -} - - -METHODDEF(boolean) -print_text_marker (j_decompress_ptr cinfo) -{ - boolean traceit = (cinfo->err->trace_level >= 1); - INT32 length; - unsigned int ch; - unsigned int lastch = 0; - - length = jpeg_getc(cinfo) << 8; - length += jpeg_getc(cinfo); - length -= 2; /* discount the length word itself */ - - if (traceit) { - if (cinfo->unread_marker == JPEG_COM) - fprintf(stderr, "Comment, length %ld:\n", (long) length); - else /* assume it is an APPn otherwise */ - fprintf(stderr, "APP%d, length %ld:\n", - cinfo->unread_marker - JPEG_APP0, (long) length); - } - - while (--length >= 0) { - ch = jpeg_getc(cinfo); - if (traceit) { - /* Emit the character in a readable form. - * Nonprintables are converted to \nnn form, - * while \ is converted to \\. - * Newlines in CR, CR/LF, or LF form will be printed as one newline. - */ - if (ch == '\r') { - fprintf(stderr, "\n"); - } else if (ch == '\n') { - if (lastch != '\r') - fprintf(stderr, "\n"); - } else if (ch == '\\') { - fprintf(stderr, "\\\\"); - } else if (isprint(ch)) { - putc(ch, stderr); - } else { - fprintf(stderr, "\\%03o", ch); - } - lastch = ch; - } - } - - if (traceit) - fprintf(stderr, "\n"); - - return TRUE; -} - - -/* - * The main program. - */ - -int -main (int argc, char **argv) -{ - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; -#ifdef PROGRESS_REPORT - struct cdjpeg_progress_mgr progress; -#endif - int file_index; - djpeg_dest_ptr dest_mgr = NULL; - FILE * input_file; - FILE * output_file; - JDIMENSION num_scanlines; - - /* On Mac, fetch a command line. */ -#ifdef USE_CCOMMAND - argc = ccommand(&argv); -#endif - - progname = argv[0]; - if (progname == NULL || progname[0] == 0) - progname = "djpeg"; /* in case C library doesn't provide it */ - - /* Initialize the JPEG decompression object with default error handling. */ - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress(&cinfo); - /* Add some application-specific error messages (from cderror.h) */ - jerr.addon_message_table = cdjpeg_message_table; - jerr.first_addon_message = JMSG_FIRSTADDONCODE; - jerr.last_addon_message = JMSG_LASTADDONCODE; - - /* Insert custom marker processor for COM and APP12. - * APP12 is used by some digital camera makers for textual info, - * so we provide the ability to display it as text. - * If you like, additional APPn marker types can be selected for display, - * but don't try to override APP0 or APP14 this way (see libjpeg.doc). - */ - jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker); - jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker); - - /* Now safe to enable signal catcher. */ -#ifdef NEED_SIGNAL_CATCHER - enable_signal_catcher((j_common_ptr) &cinfo); -#endif - - /* Scan command line to find file names. */ - /* It is convenient to use just one switch-parsing routine, but the switch - * values read here are ignored; we will rescan the switches after opening - * the input file. - * (Exception: tracing level set here controls verbosity for COM markers - * found during jpeg_read_header...) - */ - - file_index = parse_switches(&cinfo, argc, argv, 0, FALSE); - -#ifdef TWO_FILE_COMMANDLINE - /* Must have either -outfile switch or explicit output file name */ - if (outfilename == NULL) { - if (file_index != argc-2) { - fprintf(stderr, "%s: must name one input and one output file\n", - progname); - usage(); - } - outfilename = argv[file_index+1]; - } else { - if (file_index != argc-1) { - fprintf(stderr, "%s: must name one input and one output file\n", - progname); - usage(); - } - } -#else - /* Unix style: expect zero or one file name */ - if (file_index < argc-1) { - fprintf(stderr, "%s: only one input file\n", progname); - usage(); - } -#endif /* TWO_FILE_COMMANDLINE */ - - /* Open the input file. */ - if (file_index < argc) { - if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); - exit(EXIT_FAILURE); - } - } else { - /* default input file is stdin */ - input_file = read_stdin(); - } - - /* Open the output file. */ - if (outfilename != NULL) { - if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, outfilename); - exit(EXIT_FAILURE); - } - } else { - /* default output file is stdout */ - output_file = write_stdout(); - } - -#ifdef PROGRESS_REPORT - start_progress_monitor((j_common_ptr) &cinfo, &progress); -#endif - - /* Specify data source for decompression */ - jpeg_stdio_src(&cinfo, input_file); - - /* Read file header, set default decompression parameters */ - (void) jpeg_read_header(&cinfo, TRUE); - - /* Adjust default decompression parameters by re-parsing the options */ - file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); - - /* Initialize the output module now to let it override any crucial - * option settings (for instance, GIF wants to force color quantization). - */ - switch (requested_fmt) { -#ifdef BMP_SUPPORTED - case FMT_BMP: - dest_mgr = jinit_write_bmp(&cinfo, FALSE); - break; - case FMT_OS2: - dest_mgr = jinit_write_bmp(&cinfo, TRUE); - break; -#endif -#ifdef GIF_SUPPORTED - case FMT_GIF: - dest_mgr = jinit_write_gif(&cinfo); - break; -#endif -#ifdef PPM_SUPPORTED - case FMT_PPM: - dest_mgr = jinit_write_ppm(&cinfo); - break; -#endif -#ifdef RLE_SUPPORTED - case FMT_RLE: - dest_mgr = jinit_write_rle(&cinfo); - break; -#endif -#ifdef TARGA_SUPPORTED - case FMT_TARGA: - dest_mgr = jinit_write_targa(&cinfo); - break; -#endif - default: - ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT); - break; - } - dest_mgr->output_file = output_file; - - /* Start decompressor */ - (void) jpeg_start_decompress(&cinfo); - - /* Write output file header */ - (*dest_mgr->start_output) (&cinfo, dest_mgr); - - /* Process data */ - while (cinfo.output_scanline < cinfo.output_height) { - num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer, - dest_mgr->buffer_height); - (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); - } - -#ifdef PROGRESS_REPORT - /* Hack: count final pass as done in case finish_output does an extra pass. - * The library won't have updated completed_passes. - */ - progress.pub.completed_passes = progress.pub.total_passes; -#endif - - /* Finish decompression and release memory. - * I must do it in this order because output module has allocated memory - * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory. - */ - (*dest_mgr->finish_output) (&cinfo, dest_mgr); - (void) jpeg_finish_decompress(&cinfo); - jpeg_destroy_decompress(&cinfo); - - /* Close files, if we opened them */ - if (input_file != stdin) - fclose(input_file); - if (output_file != stdout) - fclose(output_file); - -#ifdef PROGRESS_REPORT - end_progress_monitor((j_common_ptr) &cinfo); -#endif - - /* All done. */ - exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); - return 0; /* suppress no-return-value warnings */ -} +/* + * djpeg.c + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * Modified 2009 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a command-line user interface for the JPEG decompressor. + * It should work on any system with Unix- or MS-DOS-style command lines. + * + * Two different command line styles are permitted, depending on the + * compile-time switch TWO_FILE_COMMANDLINE: + * djpeg [options] inputfile outputfile + * djpeg [options] [inputfile] + * In the second style, output is always to standard output, which you'd + * normally redirect to a file or pipe to some other program. Input is + * either from a named file or from standard input (typically redirected). + * The second style is convenient on Unix but is unhelpful on systems that + * don't support pipes. Also, you MUST use the first style if your system + * doesn't do binary I/O to stdin/stdout. + * To simplify script writing, the "-outfile" switch is provided. The syntax + * djpeg [options] -outfile outputfile inputfile + * works regardless of which command line style is used. + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ +#include "jversion.h" /* for version message */ + +#include /* to declare isprint() */ + +#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ +#ifdef __MWERKS__ +#include /* Metrowerks needs this */ +#include /* ... and this */ +#endif +#ifdef THINK_C +#include /* Think declares it here */ +#endif +#endif + + +/* Create the add-on message string table. */ + +#define JMESSAGE(code,string) string , + +static const char * const cdjpeg_message_table[] = { +#include "cderror.h" + NULL +}; + + +/* + * This list defines the known output image formats + * (not all of which need be supported by a given version). + * You can change the default output format by defining DEFAULT_FMT; + * indeed, you had better do so if you undefine PPM_SUPPORTED. + */ + +typedef enum { + FMT_BMP, /* BMP format (Windows flavor) */ + FMT_GIF, /* GIF format */ + FMT_OS2, /* BMP format (OS/2 flavor) */ + FMT_PPM, /* PPM/PGM (PBMPLUS formats) */ + FMT_RLE, /* RLE format */ + FMT_TARGA, /* Targa format */ + FMT_TIFF /* TIFF format */ +} IMAGE_FORMATS; + +#ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */ +#define DEFAULT_FMT FMT_PPM +#endif + +static IMAGE_FORMATS requested_fmt; + + +/* + * Argument-parsing code. + * The switch parser is designed to be useful with DOS-style command line + * syntax, ie, intermixed switches and file names, where only the switches + * to the left of a given file name affect processing of that file. + * The main program in this file doesn't actually use this capability... + */ + + +static const char * progname; /* program name for error messages */ +static char * outfilename; /* for -outfile switch */ + + +LOCAL(void) +usage (void) +/* complain about bad command line */ +{ + fprintf(stderr, "usage: %s [switches] ", progname); +#ifdef TWO_FILE_COMMANDLINE + fprintf(stderr, "inputfile outputfile\n"); +#else + fprintf(stderr, "[inputfile]\n"); +#endif + + fprintf(stderr, "Switches (names may be abbreviated):\n"); + fprintf(stderr, " -colors N Reduce image to no more than N colors\n"); + fprintf(stderr, " -fast Fast, low-quality processing\n"); + fprintf(stderr, " -grayscale Force grayscale output\n"); +#ifdef IDCT_SCALING_SUPPORTED + fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n"); +#endif +#ifdef BMP_SUPPORTED + fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n", + (DEFAULT_FMT == FMT_BMP ? " (default)" : "")); +#endif +#ifdef GIF_SUPPORTED + fprintf(stderr, " -gif Select GIF output format%s\n", + (DEFAULT_FMT == FMT_GIF ? " (default)" : "")); +#endif +#ifdef BMP_SUPPORTED + fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n", + (DEFAULT_FMT == FMT_OS2 ? " (default)" : "")); +#endif +#ifdef PPM_SUPPORTED + fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n", + (DEFAULT_FMT == FMT_PPM ? " (default)" : "")); +#endif +#ifdef RLE_SUPPORTED + fprintf(stderr, " -rle Select Utah RLE output format%s\n", + (DEFAULT_FMT == FMT_RLE ? " (default)" : "")); +#endif +#ifdef TARGA_SUPPORTED + fprintf(stderr, " -targa Select Targa output format%s\n", + (DEFAULT_FMT == FMT_TARGA ? " (default)" : "")); +#endif + fprintf(stderr, "Switches for advanced users:\n"); +#ifdef DCT_ISLOW_SUPPORTED + fprintf(stderr, " -dct int Use integer DCT method%s\n", + (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); +#endif +#ifdef DCT_IFAST_SUPPORTED + fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n", + (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); +#endif +#ifdef DCT_FLOAT_SUPPORTED + fprintf(stderr, " -dct float Use floating-point DCT method%s\n", + (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); +#endif + fprintf(stderr, " -dither fs Use F-S dithering (default)\n"); + fprintf(stderr, " -dither none Don't use dithering in quantization\n"); + fprintf(stderr, " -dither ordered Use ordered dither (medium speed, quality)\n"); +#ifdef QUANT_2PASS_SUPPORTED + fprintf(stderr, " -map FILE Map to colors used in named image file\n"); +#endif + fprintf(stderr, " -nosmooth Don't use high-quality upsampling\n"); +#ifdef QUANT_1PASS_SUPPORTED + fprintf(stderr, " -onepass Use 1-pass quantization (fast, low quality)\n"); +#endif + fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); + fprintf(stderr, " -outfile name Specify name for output file\n"); + fprintf(stderr, " -verbose or -debug Emit debug output\n"); + exit(EXIT_FAILURE); +} + + +LOCAL(int) +parse_switches (j_decompress_ptr cinfo, int argc, char **argv, + int last_file_arg_seen, boolean for_real) +/* Parse optional switches. + * Returns argv[] index of first file-name argument (== argc if none). + * Any file names with indexes <= last_file_arg_seen are ignored; + * they have presumably been processed in a previous iteration. + * (Pass 0 for last_file_arg_seen on the first or only iteration.) + * for_real is FALSE on the first (dummy) pass; we may skip any expensive + * processing. + */ +{ + int argn; + char * arg; + + /* Set up default JPEG parameters. */ + requested_fmt = DEFAULT_FMT; /* set default output file format */ + outfilename = NULL; + cinfo->err->trace_level = 0; + + /* Scan command line options, adjust parameters */ + + for (argn = 1; argn < argc; argn++) { + arg = argv[argn]; + if (*arg != '-') { + /* Not a switch, must be a file name argument */ + if (argn <= last_file_arg_seen) { + outfilename = NULL; /* -outfile applies to just one input file */ + continue; /* ignore this name if previously processed */ + } + break; /* else done parsing switches */ + } + arg++; /* advance past switch marker character */ + + if (keymatch(arg, "bmp", 1)) { + /* BMP output format. */ + requested_fmt = FMT_BMP; + + } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) || + keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) { + /* Do color quantization. */ + int val; + + if (++argn >= argc) /* advance to next argument */ + usage(); + if (sscanf(argv[argn], "%d", &val) != 1) + usage(); + cinfo->desired_number_of_colors = val; + cinfo->quantize_colors = TRUE; + + } else if (keymatch(arg, "dct", 2)) { + /* Select IDCT algorithm. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + if (keymatch(argv[argn], "int", 1)) { + cinfo->dct_method = JDCT_ISLOW; + } else if (keymatch(argv[argn], "fast", 2)) { + cinfo->dct_method = JDCT_IFAST; + } else if (keymatch(argv[argn], "float", 2)) { + cinfo->dct_method = JDCT_FLOAT; + } else + usage(); + + } else if (keymatch(arg, "dither", 2)) { + /* Select dithering algorithm. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + if (keymatch(argv[argn], "fs", 2)) { + cinfo->dither_mode = JDITHER_FS; + } else if (keymatch(argv[argn], "none", 2)) { + cinfo->dither_mode = JDITHER_NONE; + } else if (keymatch(argv[argn], "ordered", 2)) { + cinfo->dither_mode = JDITHER_ORDERED; + } else + usage(); + + } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { + /* Enable debug printouts. */ + /* On first -d, print version identification */ + static boolean printed_version = FALSE; + + if (! printed_version) { + fprintf(stderr, "Independent JPEG Group's DJPEG, version %s\n%s\n", + JVERSION, JCOPYRIGHT); + printed_version = TRUE; + } + cinfo->err->trace_level++; + + } else if (keymatch(arg, "fast", 1)) { + /* Select recommended processing options for quick-and-dirty output. */ + cinfo->two_pass_quantize = FALSE; + cinfo->dither_mode = JDITHER_ORDERED; + if (! cinfo->quantize_colors) /* don't override an earlier -colors */ + cinfo->desired_number_of_colors = 216; + cinfo->dct_method = JDCT_FASTEST; + cinfo->do_fancy_upsampling = FALSE; + + } else if (keymatch(arg, "gif", 1)) { + /* GIF output format. */ + requested_fmt = FMT_GIF; + + } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) { + /* Force monochrome output. */ + cinfo->out_color_space = JCS_GRAYSCALE; + + } else if (keymatch(arg, "map", 3)) { + /* Quantize to a color map taken from an input file. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + if (for_real) { /* too expensive to do twice! */ +#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ + FILE * mapfile; + + if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); + exit(EXIT_FAILURE); + } + read_color_map(cinfo, mapfile); + fclose(mapfile); + cinfo->quantize_colors = TRUE; +#else + ERREXIT(cinfo, JERR_NOT_COMPILED); +#endif + } + + } else if (keymatch(arg, "maxmemory", 3)) { + /* Maximum memory in Kb (or Mb with 'm'). */ + long lval; + char ch = 'x'; + + if (++argn >= argc) /* advance to next argument */ + usage(); + if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) + usage(); + if (ch == 'm' || ch == 'M') + lval *= 1000L; + cinfo->mem->max_memory_to_use = lval * 1000L; + + } else if (keymatch(arg, "nosmooth", 3)) { + /* Suppress fancy upsampling */ + cinfo->do_fancy_upsampling = FALSE; + + } else if (keymatch(arg, "onepass", 3)) { + /* Use fast one-pass quantization. */ + cinfo->two_pass_quantize = FALSE; + + } else if (keymatch(arg, "os2", 3)) { + /* BMP output format (OS/2 flavor). */ + requested_fmt = FMT_OS2; + + } else if (keymatch(arg, "outfile", 4)) { + /* Set output file name. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + outfilename = argv[argn]; /* save it away for later use */ + + } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) { + /* PPM/PGM output format. */ + requested_fmt = FMT_PPM; + + } else if (keymatch(arg, "rle", 1)) { + /* RLE output format. */ + requested_fmt = FMT_RLE; + + } else if (keymatch(arg, "scale", 1)) { + /* Scale the output image by a fraction M/N. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + if (sscanf(argv[argn], "%d/%d", + &cinfo->scale_num, &cinfo->scale_denom) < 1) + usage(); + + } else if (keymatch(arg, "targa", 1)) { + /* Targa output format. */ + requested_fmt = FMT_TARGA; + + } else { + usage(); /* bogus switch */ + } + } + + return argn; /* return index of next arg (file name) */ +} + + +/* + * Marker processor for COM and interesting APPn markers. + * This replaces the library's built-in processor, which just skips the marker. + * We want to print out the marker as text, to the extent possible. + * Note this code relies on a non-suspending data source. + */ + +LOCAL(unsigned int) +jpeg_getc (j_decompress_ptr cinfo) +/* Read next byte */ +{ + struct jpeg_source_mgr * datasrc = cinfo->src; + + if (datasrc->bytes_in_buffer == 0) { + if (! (*datasrc->fill_input_buffer) (cinfo)) + ERREXIT(cinfo, JERR_CANT_SUSPEND); + } + datasrc->bytes_in_buffer--; + return GETJOCTET(*datasrc->next_input_byte++); +} + + +METHODDEF(boolean) +print_text_marker (j_decompress_ptr cinfo) +{ + boolean traceit = (cinfo->err->trace_level >= 1); + INT32 length; + unsigned int ch; + unsigned int lastch = 0; + + length = jpeg_getc(cinfo) << 8; + length += jpeg_getc(cinfo); + length -= 2; /* discount the length word itself */ + + if (traceit) { + if (cinfo->unread_marker == JPEG_COM) + fprintf(stderr, "Comment, length %ld:\n", (long) length); + else /* assume it is an APPn otherwise */ + fprintf(stderr, "APP%d, length %ld:\n", + cinfo->unread_marker - JPEG_APP0, (long) length); + } + + while (--length >= 0) { + ch = jpeg_getc(cinfo); + if (traceit) { + /* Emit the character in a readable form. + * Nonprintables are converted to \nnn form, + * while \ is converted to \\. + * Newlines in CR, CR/LF, or LF form will be printed as one newline. + */ + if (ch == '\r') { + fprintf(stderr, "\n"); + } else if (ch == '\n') { + if (lastch != '\r') + fprintf(stderr, "\n"); + } else if (ch == '\\') { + fprintf(stderr, "\\\\"); + } else if (isprint(ch)) { + putc(ch, stderr); + } else { + fprintf(stderr, "\\%03o", ch); + } + lastch = ch; + } + } + + if (traceit) + fprintf(stderr, "\n"); + + return TRUE; +} + + +/* + * The main program. + */ + +int +main (int argc, char **argv) +{ + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; +#ifdef PROGRESS_REPORT + struct cdjpeg_progress_mgr progress; +#endif + int file_index; + djpeg_dest_ptr dest_mgr = NULL; + FILE * input_file; + FILE * output_file; + JDIMENSION num_scanlines; + + /* On Mac, fetch a command line. */ +#ifdef USE_CCOMMAND + argc = ccommand(&argv); +#endif + + progname = argv[0]; + if (progname == NULL || progname[0] == 0) + progname = "djpeg"; /* in case C library doesn't provide it */ + + /* Initialize the JPEG decompression object with default error handling. */ + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + /* Add some application-specific error messages (from cderror.h) */ + jerr.addon_message_table = cdjpeg_message_table; + jerr.first_addon_message = JMSG_FIRSTADDONCODE; + jerr.last_addon_message = JMSG_LASTADDONCODE; + + /* Insert custom marker processor for COM and APP12. + * APP12 is used by some digital camera makers for textual info, + * so we provide the ability to display it as text. + * If you like, additional APPn marker types can be selected for display, + * but don't try to override APP0 or APP14 this way (see libjpeg.doc). + */ + jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker); + jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker); + + /* Now safe to enable signal catcher. */ +#ifdef NEED_SIGNAL_CATCHER + enable_signal_catcher((j_common_ptr) &cinfo); +#endif + + /* Scan command line to find file names. */ + /* It is convenient to use just one switch-parsing routine, but the switch + * values read here are ignored; we will rescan the switches after opening + * the input file. + * (Exception: tracing level set here controls verbosity for COM markers + * found during jpeg_read_header...) + */ + + file_index = parse_switches(&cinfo, argc, argv, 0, FALSE); + +#ifdef TWO_FILE_COMMANDLINE + /* Must have either -outfile switch or explicit output file name */ + if (outfilename == NULL) { + if (file_index != argc-2) { + fprintf(stderr, "%s: must name one input and one output file\n", + progname); + usage(); + } + outfilename = argv[file_index+1]; + } else { + if (file_index != argc-1) { + fprintf(stderr, "%s: must name one input and one output file\n", + progname); + usage(); + } + } +#else + /* Unix style: expect zero or one file name */ + if (file_index < argc-1) { + fprintf(stderr, "%s: only one input file\n", progname); + usage(); + } +#endif /* TWO_FILE_COMMANDLINE */ + + /* Open the input file. */ + if (file_index < argc) { + if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); + exit(EXIT_FAILURE); + } + } else { + /* default input file is stdin */ + input_file = read_stdin(); + } + + /* Open the output file. */ + if (outfilename != NULL) { + if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open %s\n", progname, outfilename); + exit(EXIT_FAILURE); + } + } else { + /* default output file is stdout */ + output_file = write_stdout(); + } + +#ifdef PROGRESS_REPORT + start_progress_monitor((j_common_ptr) &cinfo, &progress); +#endif + + /* Specify data source for decompression */ + jpeg_stdio_src(&cinfo, input_file); + + /* Read file header, set default decompression parameters */ + (void) jpeg_read_header(&cinfo, TRUE); + + /* Adjust default decompression parameters by re-parsing the options */ + file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); + + /* Initialize the output module now to let it override any crucial + * option settings (for instance, GIF wants to force color quantization). + */ + switch (requested_fmt) { +#ifdef BMP_SUPPORTED + case FMT_BMP: + dest_mgr = jinit_write_bmp(&cinfo, FALSE); + break; + case FMT_OS2: + dest_mgr = jinit_write_bmp(&cinfo, TRUE); + break; +#endif +#ifdef GIF_SUPPORTED + case FMT_GIF: + dest_mgr = jinit_write_gif(&cinfo); + break; +#endif +#ifdef PPM_SUPPORTED + case FMT_PPM: + dest_mgr = jinit_write_ppm(&cinfo); + break; +#endif +#ifdef RLE_SUPPORTED + case FMT_RLE: + dest_mgr = jinit_write_rle(&cinfo); + break; +#endif +#ifdef TARGA_SUPPORTED + case FMT_TARGA: + dest_mgr = jinit_write_targa(&cinfo); + break; +#endif + default: + ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT); + break; + } + dest_mgr->output_file = output_file; + + /* Start decompressor */ + (void) jpeg_start_decompress(&cinfo); + + /* Write output file header */ + (*dest_mgr->start_output) (&cinfo, dest_mgr); + + /* Process data */ + while (cinfo.output_scanline < cinfo.output_height) { + num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer, + dest_mgr->buffer_height); + (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); + } + +#ifdef PROGRESS_REPORT + /* Hack: count final pass as done in case finish_output does an extra pass. + * The library won't have updated completed_passes. + */ + progress.pub.completed_passes = progress.pub.total_passes; +#endif + + /* Finish decompression and release memory. + * I must do it in this order because output module has allocated memory + * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory. + */ + (*dest_mgr->finish_output) (&cinfo, dest_mgr); + (void) jpeg_finish_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); + + /* Close files, if we opened them */ + if (input_file != stdin) + fclose(input_file); + if (output_file != stdout) + fclose(output_file); + +#ifdef PROGRESS_REPORT + end_progress_monitor((j_common_ptr) &cinfo); +#endif + + /* All done. */ + exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); + return 0; /* suppress no-return-value warnings */ +} diff --git a/Source/LibJPEG/example.c b/Source/LibJPEG/example.c index e21cf12..1d6f6cc 100644 --- a/Source/LibJPEG/example.c +++ b/Source/LibJPEG/example.c @@ -1,433 +1,433 @@ -/* - * example.c - * - * This file illustrates how to use the IJG code as a subroutine library - * to read or write JPEG image files. You should look at this code in - * conjunction with the documentation file libjpeg.txt. - * - * This code will not do anything useful as-is, but it may be helpful as a - * skeleton for constructing routines that call the JPEG library. - * - * We present these routines in the same coding style used in the JPEG code - * (ANSI function definitions, etc); but you are of course free to code your - * routines in a different style if you prefer. - */ - -#include - -/* - * Include file for users of JPEG library. - * You will need to have included system headers that define at least - * the typedefs FILE and size_t before you can include jpeglib.h. - * (stdio.h is sufficient on ANSI-conforming systems.) - * You may also wish to include "jerror.h". - */ - -#include "jpeglib.h" - -/* - * is used for the optional error recovery mechanism shown in - * the second part of the example. - */ - -#include - - - -/******************** JPEG COMPRESSION SAMPLE INTERFACE *******************/ - -/* This half of the example shows how to feed data into the JPEG compressor. - * We present a minimal version that does not worry about refinements such - * as error recovery (the JPEG code will just exit() if it gets an error). - */ - - -/* - * IMAGE DATA FORMATS: - * - * The standard input image format is a rectangular array of pixels, with - * each pixel having the same number of "component" values (color channels). - * Each pixel row is an array of JSAMPLEs (which typically are unsigned chars). - * If you are working with color data, then the color values for each pixel - * must be adjacent in the row; for example, R,G,B,R,G,B,R,G,B,... for 24-bit - * RGB color. - * - * For this example, we'll assume that this data structure matches the way - * our application has stored the image in memory, so we can just pass a - * pointer to our image buffer. In particular, let's say that the image is - * RGB color and is described by: - */ - -extern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */ -extern int image_height; /* Number of rows in image */ -extern int image_width; /* Number of columns in image */ - - -/* - * Sample routine for JPEG compression. We assume that the target file name - * and a compression quality factor are passed in. - */ - -GLOBAL(void) -write_JPEG_file (char * filename, int quality) -{ - /* This struct contains the JPEG compression parameters and pointers to - * working space (which is allocated as needed by the JPEG library). - * It is possible to have several such structures, representing multiple - * compression/decompression processes, in existence at once. We refer - * to any one struct (and its associated working data) as a "JPEG object". - */ - struct jpeg_compress_struct cinfo; - /* This struct represents a JPEG error handler. It is declared separately - * because applications often want to supply a specialized error handler - * (see the second half of this file for an example). But here we just - * take the easy way out and use the standard error handler, which will - * print a message on stderr and call exit() if compression fails. - * Note that this struct must live as long as the main JPEG parameter - * struct, to avoid dangling-pointer problems. - */ - struct jpeg_error_mgr jerr; - /* More stuff */ - FILE * outfile; /* target file */ - JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ - int row_stride; /* physical row width in image buffer */ - - /* Step 1: allocate and initialize JPEG compression object */ - - /* We have to set up the error handler first, in case the initialization - * step fails. (Unlikely, but it could happen if you are out of memory.) - * This routine fills in the contents of struct jerr, and returns jerr's - * address which we place into the link field in cinfo. - */ - cinfo.err = jpeg_std_error(&jerr); - /* Now we can initialize the JPEG compression object. */ - jpeg_create_compress(&cinfo); - - /* Step 2: specify data destination (eg, a file) */ - /* Note: steps 2 and 3 can be done in either order. */ - - /* Here we use the library-supplied code to send compressed data to a - * stdio stream. You can also write your own code to do something else. - * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that - * requires it in order to write binary files. - */ - if ((outfile = fopen(filename, "wb")) == NULL) { - fprintf(stderr, "can't open %s\n", filename); - exit(1); - } - jpeg_stdio_dest(&cinfo, outfile); - - /* Step 3: set parameters for compression */ - - /* First we supply a description of the input image. - * Four fields of the cinfo struct must be filled in: - */ - cinfo.image_width = image_width; /* image width and height, in pixels */ - cinfo.image_height = image_height; - cinfo.input_components = 3; /* # of color components per pixel */ - cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ - /* Now use the library's routine to set default compression parameters. - * (You must set at least cinfo.in_color_space before calling this, - * since the defaults depend on the source color space.) - */ - jpeg_set_defaults(&cinfo); - /* Now you can set any non-default parameters you wish to. - * Here we just illustrate the use of quality (quantization table) scaling: - */ - jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */); - - /* Step 4: Start compressor */ - - /* TRUE ensures that we will write a complete interchange-JPEG file. - * Pass TRUE unless you are very sure of what you're doing. - */ - jpeg_start_compress(&cinfo, TRUE); - - /* Step 5: while (scan lines remain to be written) */ - /* jpeg_write_scanlines(...); */ - - /* Here we use the library's state variable cinfo.next_scanline as the - * loop counter, so that we don't have to keep track ourselves. - * To keep things simple, we pass one scanline per call; you can pass - * more if you wish, though. - */ - row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */ - - while (cinfo.next_scanline < cinfo.image_height) { - /* jpeg_write_scanlines expects an array of pointers to scanlines. - * Here the array is only one element long, but you could pass - * more than one scanline at a time if that's more convenient. - */ - row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride]; - (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); - } - - /* Step 6: Finish compression */ - - jpeg_finish_compress(&cinfo); - /* After finish_compress, we can close the output file. */ - fclose(outfile); - - /* Step 7: release JPEG compression object */ - - /* This is an important step since it will release a good deal of memory. */ - jpeg_destroy_compress(&cinfo); - - /* And we're done! */ -} - - -/* - * SOME FINE POINTS: - * - * In the above loop, we ignored the return value of jpeg_write_scanlines, - * which is the number of scanlines actually written. We could get away - * with this because we were only relying on the value of cinfo.next_scanline, - * which will be incremented correctly. If you maintain additional loop - * variables then you should be careful to increment them properly. - * Actually, for output to a stdio stream you needn't worry, because - * then jpeg_write_scanlines will write all the lines passed (or else exit - * with a fatal error). Partial writes can only occur if you use a data - * destination module that can demand suspension of the compressor. - * (If you don't know what that's for, you don't need it.) - * - * If the compressor requires full-image buffers (for entropy-coding - * optimization or a multi-scan JPEG file), it will create temporary - * files for anything that doesn't fit within the maximum-memory setting. - * (Note that temp files are NOT needed if you use the default parameters.) - * On some systems you may need to set up a signal handler to ensure that - * temporary files are deleted if the program is interrupted. See libjpeg.txt. - * - * Scanlines MUST be supplied in top-to-bottom order if you want your JPEG - * files to be compatible with everyone else's. If you cannot readily read - * your data in that order, you'll need an intermediate array to hold the - * image. See rdtarga.c or rdbmp.c for examples of handling bottom-to-top - * source data using the JPEG code's internal virtual-array mechanisms. - */ - - - -/******************** JPEG DECOMPRESSION SAMPLE INTERFACE *******************/ - -/* This half of the example shows how to read data from the JPEG decompressor. - * It's a bit more refined than the above, in that we show: - * (a) how to modify the JPEG library's standard error-reporting behavior; - * (b) how to allocate workspace using the library's memory manager. - * - * Just to make this example a little different from the first one, we'll - * assume that we do not intend to put the whole image into an in-memory - * buffer, but to send it line-by-line someplace else. We need a one- - * scanline-high JSAMPLE array as a work buffer, and we will let the JPEG - * memory manager allocate it for us. This approach is actually quite useful - * because we don't need to remember to deallocate the buffer separately: it - * will go away automatically when the JPEG object is cleaned up. - */ - - -/* - * ERROR HANDLING: - * - * The JPEG library's standard error handler (jerror.c) is divided into - * several "methods" which you can override individually. This lets you - * adjust the behavior without duplicating a lot of code, which you might - * have to update with each future release. - * - * Our example here shows how to override the "error_exit" method so that - * control is returned to the library's caller when a fatal error occurs, - * rather than calling exit() as the standard error_exit method does. - * - * We use C's setjmp/longjmp facility to return control. This means that the - * routine which calls the JPEG library must first execute a setjmp() call to - * establish the return point. We want the replacement error_exit to do a - * longjmp(). But we need to make the setjmp buffer accessible to the - * error_exit routine. To do this, we make a private extension of the - * standard JPEG error handler object. (If we were using C++, we'd say we - * were making a subclass of the regular error handler.) - * - * Here's the extended error handler struct: - */ - -struct my_error_mgr { - struct jpeg_error_mgr pub; /* "public" fields */ - - jmp_buf setjmp_buffer; /* for return to caller */ -}; - -typedef struct my_error_mgr * my_error_ptr; - -/* - * Here's the routine that will replace the standard error_exit method: - */ - -METHODDEF(void) -my_error_exit (j_common_ptr cinfo) -{ - /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */ - my_error_ptr myerr = (my_error_ptr) cinfo->err; - - /* Always display the message. */ - /* We could postpone this until after returning, if we chose. */ - (*cinfo->err->output_message) (cinfo); - - /* Return control to the setjmp point */ - longjmp(myerr->setjmp_buffer, 1); -} - - -/* - * Sample routine for JPEG decompression. We assume that the source file name - * is passed in. We want to return 1 on success, 0 on error. - */ - - -GLOBAL(int) -read_JPEG_file (char * filename) -{ - /* This struct contains the JPEG decompression parameters and pointers to - * working space (which is allocated as needed by the JPEG library). - */ - struct jpeg_decompress_struct cinfo; - /* We use our private extension JPEG error handler. - * Note that this struct must live as long as the main JPEG parameter - * struct, to avoid dangling-pointer problems. - */ - struct my_error_mgr jerr; - /* More stuff */ - FILE * infile; /* source file */ - JSAMPARRAY buffer; /* Output row buffer */ - int row_stride; /* physical row width in output buffer */ - - /* In this example we want to open the input file before doing anything else, - * so that the setjmp() error recovery below can assume the file is open. - * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that - * requires it in order to read binary files. - */ - - if ((infile = fopen(filename, "rb")) == NULL) { - fprintf(stderr, "can't open %s\n", filename); - return 0; - } - - /* Step 1: allocate and initialize JPEG decompression object */ - - /* We set up the normal JPEG error routines, then override error_exit. */ - cinfo.err = jpeg_std_error(&jerr.pub); - jerr.pub.error_exit = my_error_exit; - /* Establish the setjmp return context for my_error_exit to use. */ - if (setjmp(jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. - * We need to clean up the JPEG object, close the input file, and return. - */ - jpeg_destroy_decompress(&cinfo); - fclose(infile); - return 0; - } - /* Now we can initialize the JPEG decompression object. */ - jpeg_create_decompress(&cinfo); - - /* Step 2: specify data source (eg, a file) */ - - jpeg_stdio_src(&cinfo, infile); - - /* Step 3: read file parameters with jpeg_read_header() */ - - (void) jpeg_read_header(&cinfo, TRUE); - /* We can ignore the return value from jpeg_read_header since - * (a) suspension is not possible with the stdio data source, and - * (b) we passed TRUE to reject a tables-only JPEG file as an error. - * See libjpeg.txt for more info. - */ - - /* Step 4: set parameters for decompression */ - - /* In this example, we don't need to change any of the defaults set by - * jpeg_read_header(), so we do nothing here. - */ - - /* Step 5: Start decompressor */ - - (void) jpeg_start_decompress(&cinfo); - /* We can ignore the return value since suspension is not possible - * with the stdio data source. - */ - - /* We may need to do some setup of our own at this point before reading - * the data. After jpeg_start_decompress() we have the correct scaled - * output image dimensions available, as well as the output colormap - * if we asked for color quantization. - * In this example, we need to make an output work buffer of the right size. - */ - /* JSAMPLEs per row in output buffer */ - row_stride = cinfo.output_width * cinfo.output_components; - /* Make a one-row-high sample array that will go away when done with image */ - buffer = (*cinfo.mem->alloc_sarray) - ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); - - /* Step 6: while (scan lines remain to be read) */ - /* jpeg_read_scanlines(...); */ - - /* Here we use the library's state variable cinfo.output_scanline as the - * loop counter, so that we don't have to keep track ourselves. - */ - while (cinfo.output_scanline < cinfo.output_height) { - /* jpeg_read_scanlines expects an array of pointers to scanlines. - * Here the array is only one element long, but you could ask for - * more than one scanline at a time if that's more convenient. - */ - (void) jpeg_read_scanlines(&cinfo, buffer, 1); - /* Assume put_scanline_someplace wants a pointer and sample count. */ - put_scanline_someplace(buffer[0], row_stride); - } - - /* Step 7: Finish decompression */ - - (void) jpeg_finish_decompress(&cinfo); - /* We can ignore the return value since suspension is not possible - * with the stdio data source. - */ - - /* Step 8: Release JPEG decompression object */ - - /* This is an important step since it will release a good deal of memory. */ - jpeg_destroy_decompress(&cinfo); - - /* After finish_decompress, we can close the input file. - * Here we postpone it until after no more JPEG errors are possible, - * so as to simplify the setjmp error logic above. (Actually, I don't - * think that jpeg_destroy can do an error exit, but why assume anything...) - */ - fclose(infile); - - /* At this point you may want to check to see whether any corrupt-data - * warnings occurred (test whether jerr.pub.num_warnings is nonzero). - */ - - /* And we're done! */ - return 1; -} - - -/* - * SOME FINE POINTS: - * - * In the above code, we ignored the return value of jpeg_read_scanlines, - * which is the number of scanlines actually read. We could get away with - * this because we asked for only one line at a time and we weren't using - * a suspending data source. See libjpeg.txt for more info. - * - * We cheated a bit by calling alloc_sarray() after jpeg_start_decompress(); - * we should have done it beforehand to ensure that the space would be - * counted against the JPEG max_memory setting. In some systems the above - * code would risk an out-of-memory error. However, in general we don't - * know the output image dimensions before jpeg_start_decompress(), unless we - * call jpeg_calc_output_dimensions(). See libjpeg.txt for more about this. - * - * Scanlines are returned in the same order as they appear in the JPEG file, - * which is standardly top-to-bottom. If you must emit data bottom-to-top, - * you can use one of the virtual arrays provided by the JPEG memory manager - * to invert the data. See wrbmp.c for an example. - * - * As with compression, some operating modes may require temporary files. - * On some systems you may need to set up a signal handler to ensure that - * temporary files are deleted if the program is interrupted. See libjpeg.txt. - */ +/* + * example.c + * + * This file illustrates how to use the IJG code as a subroutine library + * to read or write JPEG image files. You should look at this code in + * conjunction with the documentation file libjpeg.txt. + * + * This code will not do anything useful as-is, but it may be helpful as a + * skeleton for constructing routines that call the JPEG library. + * + * We present these routines in the same coding style used in the JPEG code + * (ANSI function definitions, etc); but you are of course free to code your + * routines in a different style if you prefer. + */ + +#include + +/* + * Include file for users of JPEG library. + * You will need to have included system headers that define at least + * the typedefs FILE and size_t before you can include jpeglib.h. + * (stdio.h is sufficient on ANSI-conforming systems.) + * You may also wish to include "jerror.h". + */ + +#include "jpeglib.h" + +/* + * is used for the optional error recovery mechanism shown in + * the second part of the example. + */ + +#include + + + +/******************** JPEG COMPRESSION SAMPLE INTERFACE *******************/ + +/* This half of the example shows how to feed data into the JPEG compressor. + * We present a minimal version that does not worry about refinements such + * as error recovery (the JPEG code will just exit() if it gets an error). + */ + + +/* + * IMAGE DATA FORMATS: + * + * The standard input image format is a rectangular array of pixels, with + * each pixel having the same number of "component" values (color channels). + * Each pixel row is an array of JSAMPLEs (which typically are unsigned chars). + * If you are working with color data, then the color values for each pixel + * must be adjacent in the row; for example, R,G,B,R,G,B,R,G,B,... for 24-bit + * RGB color. + * + * For this example, we'll assume that this data structure matches the way + * our application has stored the image in memory, so we can just pass a + * pointer to our image buffer. In particular, let's say that the image is + * RGB color and is described by: + */ + +extern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */ +extern int image_height; /* Number of rows in image */ +extern int image_width; /* Number of columns in image */ + + +/* + * Sample routine for JPEG compression. We assume that the target file name + * and a compression quality factor are passed in. + */ + +GLOBAL(void) +write_JPEG_file (char * filename, int quality) +{ + /* This struct contains the JPEG compression parameters and pointers to + * working space (which is allocated as needed by the JPEG library). + * It is possible to have several such structures, representing multiple + * compression/decompression processes, in existence at once. We refer + * to any one struct (and its associated working data) as a "JPEG object". + */ + struct jpeg_compress_struct cinfo; + /* This struct represents a JPEG error handler. It is declared separately + * because applications often want to supply a specialized error handler + * (see the second half of this file for an example). But here we just + * take the easy way out and use the standard error handler, which will + * print a message on stderr and call exit() if compression fails. + * Note that this struct must live as long as the main JPEG parameter + * struct, to avoid dangling-pointer problems. + */ + struct jpeg_error_mgr jerr; + /* More stuff */ + FILE * outfile; /* target file */ + JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ + int row_stride; /* physical row width in image buffer */ + + /* Step 1: allocate and initialize JPEG compression object */ + + /* We have to set up the error handler first, in case the initialization + * step fails. (Unlikely, but it could happen if you are out of memory.) + * This routine fills in the contents of struct jerr, and returns jerr's + * address which we place into the link field in cinfo. + */ + cinfo.err = jpeg_std_error(&jerr); + /* Now we can initialize the JPEG compression object. */ + jpeg_create_compress(&cinfo); + + /* Step 2: specify data destination (eg, a file) */ + /* Note: steps 2 and 3 can be done in either order. */ + + /* Here we use the library-supplied code to send compressed data to a + * stdio stream. You can also write your own code to do something else. + * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that + * requires it in order to write binary files. + */ + if ((outfile = fopen(filename, "wb")) == NULL) { + fprintf(stderr, "can't open %s\n", filename); + exit(1); + } + jpeg_stdio_dest(&cinfo, outfile); + + /* Step 3: set parameters for compression */ + + /* First we supply a description of the input image. + * Four fields of the cinfo struct must be filled in: + */ + cinfo.image_width = image_width; /* image width and height, in pixels */ + cinfo.image_height = image_height; + cinfo.input_components = 3; /* # of color components per pixel */ + cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ + /* Now use the library's routine to set default compression parameters. + * (You must set at least cinfo.in_color_space before calling this, + * since the defaults depend on the source color space.) + */ + jpeg_set_defaults(&cinfo); + /* Now you can set any non-default parameters you wish to. + * Here we just illustrate the use of quality (quantization table) scaling: + */ + jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */); + + /* Step 4: Start compressor */ + + /* TRUE ensures that we will write a complete interchange-JPEG file. + * Pass TRUE unless you are very sure of what you're doing. + */ + jpeg_start_compress(&cinfo, TRUE); + + /* Step 5: while (scan lines remain to be written) */ + /* jpeg_write_scanlines(...); */ + + /* Here we use the library's state variable cinfo.next_scanline as the + * loop counter, so that we don't have to keep track ourselves. + * To keep things simple, we pass one scanline per call; you can pass + * more if you wish, though. + */ + row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */ + + while (cinfo.next_scanline < cinfo.image_height) { + /* jpeg_write_scanlines expects an array of pointers to scanlines. + * Here the array is only one element long, but you could pass + * more than one scanline at a time if that's more convenient. + */ + row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride]; + (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); + } + + /* Step 6: Finish compression */ + + jpeg_finish_compress(&cinfo); + /* After finish_compress, we can close the output file. */ + fclose(outfile); + + /* Step 7: release JPEG compression object */ + + /* This is an important step since it will release a good deal of memory. */ + jpeg_destroy_compress(&cinfo); + + /* And we're done! */ +} + + +/* + * SOME FINE POINTS: + * + * In the above loop, we ignored the return value of jpeg_write_scanlines, + * which is the number of scanlines actually written. We could get away + * with this because we were only relying on the value of cinfo.next_scanline, + * which will be incremented correctly. If you maintain additional loop + * variables then you should be careful to increment them properly. + * Actually, for output to a stdio stream you needn't worry, because + * then jpeg_write_scanlines will write all the lines passed (or else exit + * with a fatal error). Partial writes can only occur if you use a data + * destination module that can demand suspension of the compressor. + * (If you don't know what that's for, you don't need it.) + * + * If the compressor requires full-image buffers (for entropy-coding + * optimization or a multi-scan JPEG file), it will create temporary + * files for anything that doesn't fit within the maximum-memory setting. + * (Note that temp files are NOT needed if you use the default parameters.) + * On some systems you may need to set up a signal handler to ensure that + * temporary files are deleted if the program is interrupted. See libjpeg.txt. + * + * Scanlines MUST be supplied in top-to-bottom order if you want your JPEG + * files to be compatible with everyone else's. If you cannot readily read + * your data in that order, you'll need an intermediate array to hold the + * image. See rdtarga.c or rdbmp.c for examples of handling bottom-to-top + * source data using the JPEG code's internal virtual-array mechanisms. + */ + + + +/******************** JPEG DECOMPRESSION SAMPLE INTERFACE *******************/ + +/* This half of the example shows how to read data from the JPEG decompressor. + * It's a bit more refined than the above, in that we show: + * (a) how to modify the JPEG library's standard error-reporting behavior; + * (b) how to allocate workspace using the library's memory manager. + * + * Just to make this example a little different from the first one, we'll + * assume that we do not intend to put the whole image into an in-memory + * buffer, but to send it line-by-line someplace else. We need a one- + * scanline-high JSAMPLE array as a work buffer, and we will let the JPEG + * memory manager allocate it for us. This approach is actually quite useful + * because we don't need to remember to deallocate the buffer separately: it + * will go away automatically when the JPEG object is cleaned up. + */ + + +/* + * ERROR HANDLING: + * + * The JPEG library's standard error handler (jerror.c) is divided into + * several "methods" which you can override individually. This lets you + * adjust the behavior without duplicating a lot of code, which you might + * have to update with each future release. + * + * Our example here shows how to override the "error_exit" method so that + * control is returned to the library's caller when a fatal error occurs, + * rather than calling exit() as the standard error_exit method does. + * + * We use C's setjmp/longjmp facility to return control. This means that the + * routine which calls the JPEG library must first execute a setjmp() call to + * establish the return point. We want the replacement error_exit to do a + * longjmp(). But we need to make the setjmp buffer accessible to the + * error_exit routine. To do this, we make a private extension of the + * standard JPEG error handler object. (If we were using C++, we'd say we + * were making a subclass of the regular error handler.) + * + * Here's the extended error handler struct: + */ + +struct my_error_mgr { + struct jpeg_error_mgr pub; /* "public" fields */ + + jmp_buf setjmp_buffer; /* for return to caller */ +}; + +typedef struct my_error_mgr * my_error_ptr; + +/* + * Here's the routine that will replace the standard error_exit method: + */ + +METHODDEF(void) +my_error_exit (j_common_ptr cinfo) +{ + /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */ + my_error_ptr myerr = (my_error_ptr) cinfo->err; + + /* Always display the message. */ + /* We could postpone this until after returning, if we chose. */ + (*cinfo->err->output_message) (cinfo); + + /* Return control to the setjmp point */ + longjmp(myerr->setjmp_buffer, 1); +} + + +/* + * Sample routine for JPEG decompression. We assume that the source file name + * is passed in. We want to return 1 on success, 0 on error. + */ + + +GLOBAL(int) +read_JPEG_file (char * filename) +{ + /* This struct contains the JPEG decompression parameters and pointers to + * working space (which is allocated as needed by the JPEG library). + */ + struct jpeg_decompress_struct cinfo; + /* We use our private extension JPEG error handler. + * Note that this struct must live as long as the main JPEG parameter + * struct, to avoid dangling-pointer problems. + */ + struct my_error_mgr jerr; + /* More stuff */ + FILE * infile; /* source file */ + JSAMPARRAY buffer; /* Output row buffer */ + int row_stride; /* physical row width in output buffer */ + + /* In this example we want to open the input file before doing anything else, + * so that the setjmp() error recovery below can assume the file is open. + * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that + * requires it in order to read binary files. + */ + + if ((infile = fopen(filename, "rb")) == NULL) { + fprintf(stderr, "can't open %s\n", filename); + return 0; + } + + /* Step 1: allocate and initialize JPEG decompression object */ + + /* We set up the normal JPEG error routines, then override error_exit. */ + cinfo.err = jpeg_std_error(&jerr.pub); + jerr.pub.error_exit = my_error_exit; + /* Establish the setjmp return context for my_error_exit to use. */ + if (setjmp(jerr.setjmp_buffer)) { + /* If we get here, the JPEG code has signaled an error. + * We need to clean up the JPEG object, close the input file, and return. + */ + jpeg_destroy_decompress(&cinfo); + fclose(infile); + return 0; + } + /* Now we can initialize the JPEG decompression object. */ + jpeg_create_decompress(&cinfo); + + /* Step 2: specify data source (eg, a file) */ + + jpeg_stdio_src(&cinfo, infile); + + /* Step 3: read file parameters with jpeg_read_header() */ + + (void) jpeg_read_header(&cinfo, TRUE); + /* We can ignore the return value from jpeg_read_header since + * (a) suspension is not possible with the stdio data source, and + * (b) we passed TRUE to reject a tables-only JPEG file as an error. + * See libjpeg.txt for more info. + */ + + /* Step 4: set parameters for decompression */ + + /* In this example, we don't need to change any of the defaults set by + * jpeg_read_header(), so we do nothing here. + */ + + /* Step 5: Start decompressor */ + + (void) jpeg_start_decompress(&cinfo); + /* We can ignore the return value since suspension is not possible + * with the stdio data source. + */ + + /* We may need to do some setup of our own at this point before reading + * the data. After jpeg_start_decompress() we have the correct scaled + * output image dimensions available, as well as the output colormap + * if we asked for color quantization. + * In this example, we need to make an output work buffer of the right size. + */ + /* JSAMPLEs per row in output buffer */ + row_stride = cinfo.output_width * cinfo.output_components; + /* Make a one-row-high sample array that will go away when done with image */ + buffer = (*cinfo.mem->alloc_sarray) + ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); + + /* Step 6: while (scan lines remain to be read) */ + /* jpeg_read_scanlines(...); */ + + /* Here we use the library's state variable cinfo.output_scanline as the + * loop counter, so that we don't have to keep track ourselves. + */ + while (cinfo.output_scanline < cinfo.output_height) { + /* jpeg_read_scanlines expects an array of pointers to scanlines. + * Here the array is only one element long, but you could ask for + * more than one scanline at a time if that's more convenient. + */ + (void) jpeg_read_scanlines(&cinfo, buffer, 1); + /* Assume put_scanline_someplace wants a pointer and sample count. */ + put_scanline_someplace(buffer[0], row_stride); + } + + /* Step 7: Finish decompression */ + + (void) jpeg_finish_decompress(&cinfo); + /* We can ignore the return value since suspension is not possible + * with the stdio data source. + */ + + /* Step 8: Release JPEG decompression object */ + + /* This is an important step since it will release a good deal of memory. */ + jpeg_destroy_decompress(&cinfo); + + /* After finish_decompress, we can close the input file. + * Here we postpone it until after no more JPEG errors are possible, + * so as to simplify the setjmp error logic above. (Actually, I don't + * think that jpeg_destroy can do an error exit, but why assume anything...) + */ + fclose(infile); + + /* At this point you may want to check to see whether any corrupt-data + * warnings occurred (test whether jerr.pub.num_warnings is nonzero). + */ + + /* And we're done! */ + return 1; +} + + +/* + * SOME FINE POINTS: + * + * In the above code, we ignored the return value of jpeg_read_scanlines, + * which is the number of scanlines actually read. We could get away with + * this because we asked for only one line at a time and we weren't using + * a suspending data source. See libjpeg.txt for more info. + * + * We cheated a bit by calling alloc_sarray() after jpeg_start_decompress(); + * we should have done it beforehand to ensure that the space would be + * counted against the JPEG max_memory setting. In some systems the above + * code would risk an out-of-memory error. However, in general we don't + * know the output image dimensions before jpeg_start_decompress(), unless we + * call jpeg_calc_output_dimensions(). See libjpeg.txt for more about this. + * + * Scanlines are returned in the same order as they appear in the JPEG file, + * which is standardly top-to-bottom. If you must emit data bottom-to-top, + * you can use one of the virtual arrays provided by the JPEG memory manager + * to invert the data. See wrbmp.c for an example. + * + * As with compression, some operating modes may require temporary files. + * On some systems you may need to set up a signal handler to ensure that + * temporary files are deleted if the program is interrupted. See libjpeg.txt. + */ diff --git a/Source/LibJPEG/filelist.txt b/Source/LibJPEG/filelist.txt index 040abff..7e05386 100644 --- a/Source/LibJPEG/filelist.txt +++ b/Source/LibJPEG/filelist.txt @@ -1,215 +1,215 @@ -IJG JPEG LIBRARY: FILE LIST - -Copyright (C) 1994-2009, Thomas G. Lane, Guido Vollbeding. -This file is part of the Independent JPEG Group's software. -For conditions of distribution and use, see the accompanying README file. - - -Here is a road map to the files in the IJG JPEG distribution. The -distribution includes the JPEG library proper, plus two application -programs ("cjpeg" and "djpeg") which use the library to convert JPEG -files to and from some other popular image formats. A third application -"jpegtran" uses the library to do lossless conversion between different -variants of JPEG. There are also two stand-alone applications, -"rdjpgcom" and "wrjpgcom". - - -THE JPEG LIBRARY -================ - -Include files: - -jpeglib.h JPEG library's exported data and function declarations. -jconfig.h Configuration declarations. Note: this file is not present - in the distribution; it is generated during installation. -jmorecfg.h Additional configuration declarations; need not be changed - for a standard installation. -jerror.h Declares JPEG library's error and trace message codes. -jinclude.h Central include file used by all IJG .c files to reference - system include files. -jpegint.h JPEG library's internal data structures. -jdct.h Private declarations for forward & reverse DCT subsystems. -jmemsys.h Private declarations for memory management subsystem. -jversion.h Version information. - -Applications using the library should include jpeglib.h (which in turn -includes jconfig.h and jmorecfg.h). Optionally, jerror.h may be included -if the application needs to reference individual JPEG error codes. The -other include files are intended for internal use and would not normally -be included by an application program. (cjpeg/djpeg/etc do use jinclude.h, -since its function is to improve portability of the whole IJG distribution. -Most other applications will directly include the system include files they -want, and hence won't need jinclude.h.) - - -C source code files: - -These files contain most of the functions intended to be called directly by -an application program: - -jcapimin.c Application program interface: core routines for compression. -jcapistd.c Application program interface: standard compression. -jdapimin.c Application program interface: core routines for decompression. -jdapistd.c Application program interface: standard decompression. -jcomapi.c Application program interface routines common to compression - and decompression. -jcparam.c Compression parameter setting helper routines. -jctrans.c API and library routines for transcoding compression. -jdtrans.c API and library routines for transcoding decompression. - -Compression side of the library: - -jcinit.c Initialization: determines which other modules to use. -jcmaster.c Master control: setup and inter-pass sequencing logic. -jcmainct.c Main buffer controller (preprocessor => JPEG compressor). -jcprepct.c Preprocessor buffer controller. -jccoefct.c Buffer controller for DCT coefficient buffer. -jccolor.c Color space conversion. -jcsample.c Downsampling. -jcdctmgr.c DCT manager (DCT implementation selection & control). -jfdctint.c Forward DCT using slow-but-accurate integer method. -jfdctfst.c Forward DCT using faster, less accurate integer method. -jfdctflt.c Forward DCT using floating-point arithmetic. -jchuff.c Huffman entropy coding. -jcarith.c Arithmetic entropy coding. -jcmarker.c JPEG marker writing. -jdatadst.c Data destination managers for memory and stdio output. - -Decompression side of the library: - -jdmaster.c Master control: determines which other modules to use. -jdinput.c Input controller: controls input processing modules. -jdmainct.c Main buffer controller (JPEG decompressor => postprocessor). -jdcoefct.c Buffer controller for DCT coefficient buffer. -jdpostct.c Postprocessor buffer controller. -jdmarker.c JPEG marker reading. -jdhuff.c Huffman entropy decoding. -jdarith.c Arithmetic entropy decoding. -jddctmgr.c IDCT manager (IDCT implementation selection & control). -jidctint.c Inverse DCT using slow-but-accurate integer method. -jidctfst.c Inverse DCT using faster, less accurate integer method. -jidctflt.c Inverse DCT using floating-point arithmetic. -jdsample.c Upsampling. -jdcolor.c Color space conversion. -jdmerge.c Merged upsampling/color conversion (faster, lower quality). -jquant1.c One-pass color quantization using a fixed-spacing colormap. -jquant2.c Two-pass color quantization using a custom-generated colormap. - Also handles one-pass quantization to an externally given map. -jdatasrc.c Data source managers for memory and stdio input. - -Support files for both compression and decompression: - -jaricom.c Tables for common use in arithmetic entropy encoding and - decoding routines. -jerror.c Standard error handling routines (application replaceable). -jmemmgr.c System-independent (more or less) memory management code. -jutils.c Miscellaneous utility routines. - -jmemmgr.c relies on a system-dependent memory management module. The IJG -distribution includes the following implementations of the system-dependent -module: - -jmemnobs.c "No backing store": assumes adequate virtual memory exists. -jmemansi.c Makes temporary files with ANSI-standard routine tmpfile(). -jmemname.c Makes temporary files with program-generated file names. -jmemdos.c Custom implementation for MS-DOS (16-bit environment only): - can use extended and expanded memory as well as temp files. -jmemmac.c Custom implementation for Apple Macintosh. - -Exactly one of the system-dependent modules should be configured into an -installed JPEG library (see install.txt for hints about which one to use). -On unusual systems you may find it worthwhile to make a special -system-dependent memory manager. - - -Non-C source code files: - -jmemdosa.asm 80x86 assembly code support for jmemdos.c; used only in - MS-DOS-specific configurations of the JPEG library. - - -CJPEG/DJPEG/JPEGTRAN -==================== - -Include files: - -cdjpeg.h Declarations shared by cjpeg/djpeg/jpegtran modules. -cderror.h Additional error and trace message codes for cjpeg et al. -transupp.h Declarations for jpegtran support routines in transupp.c. - -C source code files: - -cjpeg.c Main program for cjpeg. -djpeg.c Main program for djpeg. -jpegtran.c Main program for jpegtran. -cdjpeg.c Utility routines used by all three programs. -rdcolmap.c Code to read a colormap file for djpeg's "-map" switch. -rdswitch.c Code to process some of cjpeg's more complex switches. - Also used by jpegtran. -transupp.c Support code for jpegtran: lossless image manipulations. - -Image file reader modules for cjpeg: - -rdbmp.c BMP file input. -rdgif.c GIF file input (now just a stub). -rdppm.c PPM/PGM file input. -rdrle.c Utah RLE file input. -rdtarga.c Targa file input. - -Image file writer modules for djpeg: - -wrbmp.c BMP file output. -wrgif.c GIF file output (a mere shadow of its former self). -wrppm.c PPM/PGM file output. -wrrle.c Utah RLE file output. -wrtarga.c Targa file output. - - -RDJPGCOM/WRJPGCOM -================= - -C source code files: - -rdjpgcom.c Stand-alone rdjpgcom application. -wrjpgcom.c Stand-alone wrjpgcom application. - -These programs do not depend on the IJG library. They do use -jconfig.h and jinclude.h, only to improve portability. - - -ADDITIONAL FILES -================ - -Documentation (see README for a guide to the documentation files): - -README Master documentation file. -*.txt Other documentation files. -*.1 Documentation in Unix man page format. -change.log Version-to-version change highlights. -example.c Sample code for calling JPEG library. - -Configuration/installation files and programs (see install.txt for more info): - -configure Unix shell script to perform automatic configuration. -configure.ac Source file for use with Autoconf to generate configure. -ltmain.sh Support scripts for configure (from GNU libtool). -config.guess -config.sub -depcomp -missing -install-sh Install shell script for those Unix systems lacking one. -Makefile.in Makefile input for configure. -Makefile.am Source file for use with Automake to generate Makefile.in. -ckconfig.c Program to generate jconfig.h on non-Unix systems. -jconfig.txt Template for making jconfig.h by hand. -mak*.* Sample makefiles for particular systems. -jconfig.* Sample jconfig.h for particular systems. -libjpeg.map Script to generate shared library with versioned symbols. -aclocal.m4 M4 macro definitions for use with Autoconf. -ansi2knr.c De-ANSIfier for pre-ANSI C compilers (courtesy of - L. Peter Deutsch and Aladdin Enterprises). - -Test files (see install.txt for test procedure): - -test*.* Source and comparison files for confidence test. - These are binary image files, NOT text files. +IJG JPEG LIBRARY: FILE LIST + +Copyright (C) 1994-2009, Thomas G. Lane, Guido Vollbeding. +This file is part of the Independent JPEG Group's software. +For conditions of distribution and use, see the accompanying README file. + + +Here is a road map to the files in the IJG JPEG distribution. The +distribution includes the JPEG library proper, plus two application +programs ("cjpeg" and "djpeg") which use the library to convert JPEG +files to and from some other popular image formats. A third application +"jpegtran" uses the library to do lossless conversion between different +variants of JPEG. There are also two stand-alone applications, +"rdjpgcom" and "wrjpgcom". + + +THE JPEG LIBRARY +================ + +Include files: + +jpeglib.h JPEG library's exported data and function declarations. +jconfig.h Configuration declarations. Note: this file is not present + in the distribution; it is generated during installation. +jmorecfg.h Additional configuration declarations; need not be changed + for a standard installation. +jerror.h Declares JPEG library's error and trace message codes. +jinclude.h Central include file used by all IJG .c files to reference + system include files. +jpegint.h JPEG library's internal data structures. +jdct.h Private declarations for forward & reverse DCT subsystems. +jmemsys.h Private declarations for memory management subsystem. +jversion.h Version information. + +Applications using the library should include jpeglib.h (which in turn +includes jconfig.h and jmorecfg.h). Optionally, jerror.h may be included +if the application needs to reference individual JPEG error codes. The +other include files are intended for internal use and would not normally +be included by an application program. (cjpeg/djpeg/etc do use jinclude.h, +since its function is to improve portability of the whole IJG distribution. +Most other applications will directly include the system include files they +want, and hence won't need jinclude.h.) + + +C source code files: + +These files contain most of the functions intended to be called directly by +an application program: + +jcapimin.c Application program interface: core routines for compression. +jcapistd.c Application program interface: standard compression. +jdapimin.c Application program interface: core routines for decompression. +jdapistd.c Application program interface: standard decompression. +jcomapi.c Application program interface routines common to compression + and decompression. +jcparam.c Compression parameter setting helper routines. +jctrans.c API and library routines for transcoding compression. +jdtrans.c API and library routines for transcoding decompression. + +Compression side of the library: + +jcinit.c Initialization: determines which other modules to use. +jcmaster.c Master control: setup and inter-pass sequencing logic. +jcmainct.c Main buffer controller (preprocessor => JPEG compressor). +jcprepct.c Preprocessor buffer controller. +jccoefct.c Buffer controller for DCT coefficient buffer. +jccolor.c Color space conversion. +jcsample.c Downsampling. +jcdctmgr.c DCT manager (DCT implementation selection & control). +jfdctint.c Forward DCT using slow-but-accurate integer method. +jfdctfst.c Forward DCT using faster, less accurate integer method. +jfdctflt.c Forward DCT using floating-point arithmetic. +jchuff.c Huffman entropy coding. +jcarith.c Arithmetic entropy coding. +jcmarker.c JPEG marker writing. +jdatadst.c Data destination managers for memory and stdio output. + +Decompression side of the library: + +jdmaster.c Master control: determines which other modules to use. +jdinput.c Input controller: controls input processing modules. +jdmainct.c Main buffer controller (JPEG decompressor => postprocessor). +jdcoefct.c Buffer controller for DCT coefficient buffer. +jdpostct.c Postprocessor buffer controller. +jdmarker.c JPEG marker reading. +jdhuff.c Huffman entropy decoding. +jdarith.c Arithmetic entropy decoding. +jddctmgr.c IDCT manager (IDCT implementation selection & control). +jidctint.c Inverse DCT using slow-but-accurate integer method. +jidctfst.c Inverse DCT using faster, less accurate integer method. +jidctflt.c Inverse DCT using floating-point arithmetic. +jdsample.c Upsampling. +jdcolor.c Color space conversion. +jdmerge.c Merged upsampling/color conversion (faster, lower quality). +jquant1.c One-pass color quantization using a fixed-spacing colormap. +jquant2.c Two-pass color quantization using a custom-generated colormap. + Also handles one-pass quantization to an externally given map. +jdatasrc.c Data source managers for memory and stdio input. + +Support files for both compression and decompression: + +jaricom.c Tables for common use in arithmetic entropy encoding and + decoding routines. +jerror.c Standard error handling routines (application replaceable). +jmemmgr.c System-independent (more or less) memory management code. +jutils.c Miscellaneous utility routines. + +jmemmgr.c relies on a system-dependent memory management module. The IJG +distribution includes the following implementations of the system-dependent +module: + +jmemnobs.c "No backing store": assumes adequate virtual memory exists. +jmemansi.c Makes temporary files with ANSI-standard routine tmpfile(). +jmemname.c Makes temporary files with program-generated file names. +jmemdos.c Custom implementation for MS-DOS (16-bit environment only): + can use extended and expanded memory as well as temp files. +jmemmac.c Custom implementation for Apple Macintosh. + +Exactly one of the system-dependent modules should be configured into an +installed JPEG library (see install.txt for hints about which one to use). +On unusual systems you may find it worthwhile to make a special +system-dependent memory manager. + + +Non-C source code files: + +jmemdosa.asm 80x86 assembly code support for jmemdos.c; used only in + MS-DOS-specific configurations of the JPEG library. + + +CJPEG/DJPEG/JPEGTRAN +==================== + +Include files: + +cdjpeg.h Declarations shared by cjpeg/djpeg/jpegtran modules. +cderror.h Additional error and trace message codes for cjpeg et al. +transupp.h Declarations for jpegtran support routines in transupp.c. + +C source code files: + +cjpeg.c Main program for cjpeg. +djpeg.c Main program for djpeg. +jpegtran.c Main program for jpegtran. +cdjpeg.c Utility routines used by all three programs. +rdcolmap.c Code to read a colormap file for djpeg's "-map" switch. +rdswitch.c Code to process some of cjpeg's more complex switches. + Also used by jpegtran. +transupp.c Support code for jpegtran: lossless image manipulations. + +Image file reader modules for cjpeg: + +rdbmp.c BMP file input. +rdgif.c GIF file input (now just a stub). +rdppm.c PPM/PGM file input. +rdrle.c Utah RLE file input. +rdtarga.c Targa file input. + +Image file writer modules for djpeg: + +wrbmp.c BMP file output. +wrgif.c GIF file output (a mere shadow of its former self). +wrppm.c PPM/PGM file output. +wrrle.c Utah RLE file output. +wrtarga.c Targa file output. + + +RDJPGCOM/WRJPGCOM +================= + +C source code files: + +rdjpgcom.c Stand-alone rdjpgcom application. +wrjpgcom.c Stand-alone wrjpgcom application. + +These programs do not depend on the IJG library. They do use +jconfig.h and jinclude.h, only to improve portability. + + +ADDITIONAL FILES +================ + +Documentation (see README for a guide to the documentation files): + +README Master documentation file. +*.txt Other documentation files. +*.1 Documentation in Unix man page format. +change.log Version-to-version change highlights. +example.c Sample code for calling JPEG library. + +Configuration/installation files and programs (see install.txt for more info): + +configure Unix shell script to perform automatic configuration. +configure.ac Source file for use with Autoconf to generate configure. +ltmain.sh Support scripts for configure (from GNU libtool). +config.guess +config.sub +depcomp +missing +install-sh Install shell script for those Unix systems lacking one. +Makefile.in Makefile input for configure. +Makefile.am Source file for use with Automake to generate Makefile.in. +ckconfig.c Program to generate jconfig.h on non-Unix systems. +jconfig.txt Template for making jconfig.h by hand. +mak*.* Sample makefiles for particular systems. +jconfig.* Sample jconfig.h for particular systems. +libjpeg.map Script to generate shared library with versioned symbols. +aclocal.m4 M4 macro definitions for use with Autoconf. +ansi2knr.c De-ANSIfier for pre-ANSI C compilers (courtesy of + L. Peter Deutsch and Aladdin Enterprises). + +Test files (see install.txt for test procedure): + +test*.* Source and comparison files for confidence test. + These are binary image files, NOT text files. diff --git a/Source/LibJPEG/install.txt b/Source/LibJPEG/install.txt index d8f2495..04bed91 100644 --- a/Source/LibJPEG/install.txt +++ b/Source/LibJPEG/install.txt @@ -1,1096 +1,1096 @@ -INSTALLATION INSTRUCTIONS for the Independent JPEG Group's JPEG software - -Copyright (C) 1991-2011, Thomas G. Lane, Guido Vollbeding. -This file is part of the Independent JPEG Group's software. -For conditions of distribution and use, see the accompanying README file. - - -This file explains how to configure and install the IJG software. We have -tried to make this software extremely portable and flexible, so that it can be -adapted to almost any environment. The downside of this decision is that the -installation process is complicated. We have provided shortcuts to simplify -the task on common systems. But in any case, you will need at least a little -familiarity with C programming and program build procedures for your system. - -If you are only using this software as part of a larger program, the larger -program's installation procedure may take care of configuring the IJG code. -For example, Ghostscript's installation script will configure the IJG code. -You don't need to read this file if you just want to compile Ghostscript. - -If you are on a Unix machine, you may not need to read this file at all. -Try doing - ./configure - make - make test -If that doesn't complain, do - make install -(better do "make -n install" first to see if the makefile will put the files -where you want them). Read further if you run into snags or want to customize -the code for your system. - - -TABLE OF CONTENTS ------------------ - -Before you start -Configuring the software: - using the automatic "configure" script - using one of the supplied jconfig and makefile files - by hand -Building the software -Testing the software -Installing the software -Optional stuff -Optimization -Hints for specific systems - - -BEFORE YOU START -================ - -Before installing the software you must unpack the distributed source code. -Since you are reading this file, you have probably already succeeded in this -task. However, there is a potential for error if you needed to convert the -files to the local standard text file format (for example, if you are on -MS-DOS you may have converted LF end-of-line to CR/LF). You must apply -such conversion to all the files EXCEPT those whose names begin with "test". -The test files contain binary data; if you change them in any way then the -self-test will give bad results. - -Please check the last section of this file to see if there are hints for the -specific machine or compiler you are using. - - -CONFIGURING THE SOFTWARE -======================== - -To configure the IJG code for your system, you need to create two files: - * jconfig.h: contains values for system-dependent #define symbols. - * Makefile: controls the compilation process. -(On a non-Unix machine, you may create "project files" or some other -substitute for a Makefile. jconfig.h is needed in any environment.) - -We provide three different ways to generate these files: - * On a Unix system, you can just run the "configure" script. - * We provide sample jconfig files and makefiles for popular machines; - if your machine matches one of the samples, just copy the right sample - files to jconfig.h and Makefile. - * If all else fails, read the instructions below and make your own files. - - -Configuring the software using the automatic "configure" script ---------------------------------------------------------------- - -If you are on a Unix machine, you can just type - ./configure -and let the configure script construct appropriate configuration files. -If you're using "csh" on an old version of System V, you might need to type - sh configure -instead to prevent csh from trying to execute configure itself. -Expect configure to run for a few minutes, particularly on slower machines; -it works by compiling a series of test programs. - -Configure was created with GNU Autoconf and it follows the usual conventions -for GNU configure scripts. It makes a few assumptions that you may want to -override. You can do this by providing optional switches to configure: - -* Configure will build both static and shared libraries, if possible. -If you want to build libjpeg only as a static library, say - ./configure --disable-shared -If you want to build libjpeg only as a shared library, say - ./configure --disable-static -Configure uses GNU libtool to take care of system-dependent shared library -building methods. - -* Configure will use gcc (GNU C compiler) if it's available, otherwise cc. -To force a particular compiler to be selected, use the CC option, for example - ./configure CC='cc' -The same method can be used to include any unusual compiler switches. -For example, on HP-UX you probably want to say - ./configure CC='cc -Aa' -to get HP's compiler to run in ANSI mode. - -* The default CFLAGS setting is "-g" for non-gcc compilers, "-g -O2" for gcc. -You can override this by saying, for example, - ./configure CFLAGS='-O2' -if you want to compile without debugging support. - -* Configure will set up the makefile so that "make install" will install files -into /usr/local/bin, /usr/local/man, etc. You can specify an installation -prefix other than "/usr/local" by giving configure the option "--prefix=PATH". - -* If you don't have a lot of swap space, you may need to enable the IJG -software's internal virtual memory mechanism. To do this, give the option -"--enable-maxmem=N" where N is the default maxmemory limit in megabytes. -This is discussed in more detail under "Selecting a memory manager", below. -You probably don't need to worry about this on reasonably-sized Unix machines, -unless you plan to process very large images. - -Configure has some other features that are useful if you are cross-compiling -or working in a network of multiple machine types; but if you need those -features, you probably already know how to use them. - - -Configuring the software using one of the supplied jconfig and makefile files ------------------------------------------------------------------------------ - -If you have one of these systems, you can just use the provided configuration -files: - -Makefile jconfig file System and/or compiler - -makefile.manx jconfig.manx Amiga, Manx Aztec C -makefile.sas jconfig.sas Amiga, SAS C -makeproj.mac jconfig.mac Apple Macintosh, Metrowerks CodeWarrior -mak*jpeg.st jconfig.st Atari ST/STE/TT, Pure C or Turbo C -makefile.bcc jconfig.bcc MS-DOS or OS/2, Borland C -makefile.dj jconfig.dj MS-DOS, DJGPP (Delorie's port of GNU C) -makefile.mc6 jconfig.mc6 MS-DOS, Microsoft C (16-bit only) -makefile.wat jconfig.wat MS-DOS, OS/2, or Windows NT, Watcom C -makefile.vc jconfig.vc Windows NT/95, MS Visual C++ -make*.vc6 jconfig.vc Windows NT/95, MS Visual C++ 6 -make*.v10 jconfig.vc Windows NT/95, MS Visual C++ 2010 (v10) -makefile.mms jconfig.vms Digital VMS, with MMS software -makefile.vms jconfig.vms Digital VMS, without MMS software - -Copy the proper jconfig file to jconfig.h and the makefile to Makefile (or -whatever your system uses as the standard makefile name). For more info see -the appropriate system-specific hints section near the end of this file. - - -Configuring the software by hand --------------------------------- - -First, generate a jconfig.h file. If you are moderately familiar with C, -the comments in jconfig.txt should be enough information to do this; just -copy jconfig.txt to jconfig.h and edit it appropriately. Otherwise, you may -prefer to use the ckconfig.c program. You will need to compile and execute -ckconfig.c by hand --- we hope you know at least enough to do that. -ckconfig.c may not compile the first try (in fact, the whole idea is for it -to fail if anything is going to). If you get compile errors, fix them by -editing ckconfig.c according to the directions given in ckconfig.c. Once -you get it to run, it will write a suitable jconfig.h file, and will also -print out some advice about which makefile to use. - -You may also want to look at the canned jconfig files, if there is one for a -system similar to yours. - -Second, select a makefile and copy it to Makefile (or whatever your system -uses as the standard makefile name). The most generic makefiles we provide -are - makefile.ansi: if your C compiler supports function prototypes - makefile.unix: if not. -(You have function prototypes if ckconfig.c put "#define HAVE_PROTOTYPES" -in jconfig.h.) You may want to start from one of the other makefiles if -there is one for a system similar to yours. - -Look over the selected Makefile and adjust options as needed. In particular -you may want to change the CC and CFLAGS definitions. For instance, if you -are using GCC, set CC=gcc. If you had to use any compiler switches to get -ckconfig.c to work, make sure the same switches are in CFLAGS. - -If you are on a system that doesn't use makefiles, you'll need to set up -project files (or whatever you do use) to compile all the source files and -link them into executable files cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom. -See the file lists in any of the makefiles to find out which files go into -each program. Note that the provided makefiles all make a "library" file -libjpeg first, but you don't have to do that if you don't want to; the file -lists identify which source files are actually needed for compression, -decompression, or both. As a last resort, you can make a batch script that -just compiles everything and links it all together; makefile.vms is an example -of this (it's for VMS systems that have no make-like utility). - -Here are comments about some specific configuration decisions you'll -need to make: - -Command line style ------------------- - -These programs can use a Unix-like command line style which supports -redirection and piping, like this: - cjpeg inputfile >outputfile - cjpeg outputfile - source program | cjpeg >outputfile -The simpler "two file" command line style is just - cjpeg inputfile outputfile -You may prefer the two-file style, particularly if you don't have pipes. - -You MUST use two-file style on any system that doesn't cope well with binary -data fed through stdin/stdout; this is true for some MS-DOS compilers, for -example. If you're not on a Unix system, it's safest to assume you need -two-file style. (But if your compiler provides either the Posix-standard -fdopen() library routine or a Microsoft-compatible setmode() routine, you -can safely use the Unix command line style, by defining USE_FDOPEN or -USE_SETMODE respectively.) - -To use the two-file style, make jconfig.h say "#define TWO_FILE_COMMANDLINE". - -Selecting a memory manager --------------------------- - -The IJG code is capable of working on images that are too big to fit in main -memory; data is swapped out to temporary files as necessary. However, the -code to do this is rather system-dependent. We provide five different -memory managers: - -* jmemansi.c This version uses the ANSI-standard library routine tmpfile(), - which not all non-ANSI systems have. On some systems - tmpfile() may put the temporary file in a non-optimal - location; if you don't like what it does, use jmemname.c. - -* jmemname.c This version creates named temporary files. For anything - except a Unix machine, you'll need to configure the - select_file_name() routine appropriately; see the comments - near the head of jmemname.c. If you use this version, define - NEED_SIGNAL_CATCHER in jconfig.h to make sure the temp files - are removed if the program is aborted. - -* jmemnobs.c (That stands for No Backing Store :-).) This will compile on - almost any system, but it assumes you have enough main memory - or virtual memory to hold the biggest images you work with. - -* jmemdos.c This should be used with most 16-bit MS-DOS compilers. - See the system-specific notes about MS-DOS for more info. - IMPORTANT: if you use this, define USE_MSDOS_MEMMGR in - jconfig.h, and include the assembly file jmemdosa.asm in the - programs. The supplied makefiles and jconfig files for - 16-bit MS-DOS compilers already do both. - -* jmemmac.c Custom version for Apple Macintosh; see the system-specific - notes for Macintosh for more info. - -To use a particular memory manager, change the SYSDEPMEM variable in your -makefile to equal the corresponding object file name (for example, jmemansi.o -or jmemansi.obj for jmemansi.c). - -If you have plenty of (real or virtual) main memory, just use jmemnobs.c. -"Plenty" means about ten bytes for every pixel in the largest images -you plan to process, so a lot of systems don't meet this criterion. -If yours doesn't, try jmemansi.c first. If that doesn't compile, you'll have -to use jmemname.c; be sure to adjust select_file_name() for local conditions. -You may also need to change unlink() to remove() in close_backing_store(). - -Except with jmemnobs.c or jmemmac.c, you need to adjust the DEFAULT_MAX_MEM -setting to a reasonable value for your system (either by adding a #define for -DEFAULT_MAX_MEM to jconfig.h, or by adding a -D switch to the Makefile). -This value limits the amount of data space the program will attempt to -allocate. Code and static data space isn't counted, so the actual memory -needs for cjpeg or djpeg are typically 100 to 150Kb more than the max-memory -setting. Larger max-memory settings reduce the amount of I/O needed to -process a large image, but too large a value can result in "insufficient -memory" failures. On most Unix machines (and other systems with virtual -memory), just set DEFAULT_MAX_MEM to several million and forget it. At the -other end of the spectrum, for MS-DOS machines you probably can't go much -above 300K to 400K. (On MS-DOS the value refers to conventional memory only. -Extended/expanded memory is handled separately by jmemdos.c.) - - -BUILDING THE SOFTWARE -===================== - -Now you should be able to compile the software. Just say "make" (or -whatever's necessary to start the compilation). Have a cup of coffee. - -Here are some things that could go wrong: - -If your compiler complains about undefined structures, you should be able to -shut it up by putting "#define INCOMPLETE_TYPES_BROKEN" in jconfig.h. - -If you have trouble with missing system include files or inclusion of the -wrong ones, read jinclude.h. This shouldn't happen if you used configure -or ckconfig.c to set up jconfig.h. - -There are a fair number of routines that do not use all of their parameters; -some compilers will issue warnings about this, which you can ignore. There -are also a few configuration checks that may give "unreachable code" warnings. -Any other warning deserves investigation. - -If you don't have a getenv() library routine, define NO_GETENV. - -Also see the system-specific hints, below. - - -TESTING THE SOFTWARE -==================== - -As a quick test of functionality we've included a small sample image in -several forms: - testorig.jpg Starting point for the djpeg tests. - testimg.ppm The output of djpeg testorig.jpg - testimg.bmp The output of djpeg -bmp -colors 256 testorig.jpg - testimg.jpg The output of cjpeg testimg.ppm - testprog.jpg Progressive-mode equivalent of testorig.jpg. - testimgp.jpg The output of cjpeg -progressive -optimize testimg.ppm -(The first- and second-generation .jpg files aren't identical since the -default compression parameters are lossy.) If you can generate duplicates -of the testimg* files then you probably have working programs. - -With most of the makefiles, "make test" will perform the necessary -comparisons. - -If you're using a makefile that doesn't provide the test option, run djpeg -and cjpeg by hand and compare the output files to testimg* with whatever -binary file comparison tool you have. The files should be bit-for-bit -identical. - -If the programs complain "MAX_ALLOC_CHUNK is wrong, please fix", then you -need to reduce MAX_ALLOC_CHUNK to a value that fits in type size_t. -Try adding "#define MAX_ALLOC_CHUNK 65520L" to jconfig.h. A less likely -configuration error is "ALIGN_TYPE is wrong, please fix": defining ALIGN_TYPE -as long should take care of that one. - -If the cjpeg test run fails with "Missing Huffman code table entry", it's a -good bet that you needed to define RIGHT_SHIFT_IS_UNSIGNED. Go back to the -configuration step and run ckconfig.c. (This is a good plan for any other -test failure, too.) - -If you are using Unix (one-file) command line style on a non-Unix system, -it's a good idea to check that binary I/O through stdin/stdout actually -works. You should get the same results from "djpeg out.ppm" -as from "djpeg -outfile out.ppm testorig.jpg". Note that the makefiles all -use the latter style and therefore do not exercise stdin/stdout! If this -check fails, try recompiling with USE_SETMODE or USE_FDOPEN defined. -If it still doesn't work, better use two-file style. - -If you chose a memory manager other than jmemnobs.c, you should test that -temporary-file usage works. Try "djpeg -bmp -colors 256 -max 0 testorig.jpg" -and make sure its output matches testimg.bmp. If you have any really large -images handy, try compressing them with -optimize and/or decompressing with --colors 256 to make sure your DEFAULT_MAX_MEM setting is not too large. - -NOTE: this is far from an exhaustive test of the JPEG software; some modules, -such as 1-pass color quantization, are not exercised at all. It's just a -quick test to give you some confidence that you haven't missed something -major. - - -INSTALLING THE SOFTWARE -======================= - -Once you're done with the above steps, you can install the software by -copying the executable files (cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom) -to wherever you normally install programs. On Unix systems, you'll also want -to put the man pages (cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1) -in the man-page directory. The pre-fab makefiles don't support this step -since there's such a wide variety of installation procedures on different -systems. - -If you generated a Makefile with the "configure" script, you can just say - make install -to install the programs and their man pages into the standard places. -(You'll probably need to be root to do this.) We recommend first saying - make -n install -to see where configure thought the files should go. You may need to edit -the Makefile, particularly if your system's conventions for man page -filenames don't match what configure expects. - -If you want to install the IJG library itself, for use in compiling other -programs besides ours, then you need to put the four include files - jpeglib.h jerror.h jconfig.h jmorecfg.h -into your include-file directory, and put the library file libjpeg.a -(extension may vary depending on system) wherever library files go. -If you generated a Makefile with "configure", it will do what it thinks -is the right thing if you say - make install-lib - - -OPTIONAL STUFF -============== - -Progress monitor: - -If you like, you can #define PROGRESS_REPORT (in jconfig.h) to enable display -of percent-done progress reports. The routine provided in cdjpeg.c merely -prints percentages to stderr, but you can customize it to do something -fancier. - -Utah RLE file format support: - -We distribute the software with support for RLE image files (Utah Raster -Toolkit format) disabled, because the RLE support won't compile without the -Utah library. If you have URT version 3.1 or later, you can enable RLE -support as follows: - 1. #define RLE_SUPPORTED in jconfig.h. - 2. Add a -I option to CFLAGS in the Makefile for the directory - containing the URT .h files (typically the "include" - subdirectory of the URT distribution). - 3. Add -L... -lrle to LDLIBS in the Makefile, where ... specifies - the directory containing the URT "librle.a" file (typically the - "lib" subdirectory of the URT distribution). - -Support for 12-bit-deep pixel data: - -The JPEG standard allows either 8-bit or 12-bit data precision. (For color, -this means 8 or 12 bits per channel, of course.) If you need to work with -deeper than 8-bit data, you can compile the IJG code for 12-bit operation. -To do so: - 1. In jmorecfg.h, define BITS_IN_JSAMPLE as 12 rather than 8. - 2. In jconfig.h, undefine BMP_SUPPORTED, RLE_SUPPORTED, and TARGA_SUPPORTED, - because the code for those formats doesn't handle 12-bit data and won't - even compile. (The PPM code does work, as explained below. The GIF - code works too; it scales 8-bit GIF data to and from 12-bit depth - automatically.) - 3. Compile. Don't expect "make test" to pass, since the supplied test - files are for 8-bit data. - -Currently, 12-bit support does not work on 16-bit-int machines. - -Note that a 12-bit version will not read 8-bit JPEG files, nor vice versa; -so you'll want to keep around a regular 8-bit compilation as well. -(Run-time selection of data depth, to allow a single copy that does both, -is possible but would probably slow things down considerably; it's very low -on our to-do list.) - -The PPM reader (rdppm.c) can read 12-bit data from either text-format or -binary-format PPM and PGM files. Binary-format PPM/PGM files which have a -maxval greater than 255 are assumed to use 2 bytes per sample, MSB first -(big-endian order). As of early 1995, 2-byte binary format is not -officially supported by the PBMPLUS library, but it is expected that a -future release of PBMPLUS will support it. Note that the PPM reader will -read files of any maxval regardless of the BITS_IN_JSAMPLE setting; incoming -data is automatically rescaled to either maxval=255 or maxval=4095 as -appropriate for the cjpeg bit depth. - -The PPM writer (wrppm.c) will normally write 2-byte binary PPM or PGM -format, maxval 4095, when compiled with BITS_IN_JSAMPLE=12. Since this -format is not yet widely supported, you can disable it by compiling wrppm.c -with PPM_NORAWWORD defined; then the data is scaled down to 8 bits to make a -standard 1-byte/sample PPM or PGM file. (Yes, this means still another copy -of djpeg to keep around. But hopefully you won't need it for very long. -Poskanzer's supposed to get that new PBMPLUS release out Real Soon Now.) - -Of course, if you are working with 12-bit data, you probably have it stored -in some other, nonstandard format. In that case you'll probably want to -write your own I/O modules to read and write your format. - -Note that a 12-bit version of cjpeg always runs in "-optimize" mode, in -order to generate valid Huffman tables. This is necessary because our -default Huffman tables only cover 8-bit data. - -Removing code: - -If you need to make a smaller version of the JPEG software, some optional -functions can be removed at compile time. See the xxx_SUPPORTED #defines in -jconfig.h and jmorecfg.h. If at all possible, we recommend that you leave in -decoder support for all valid JPEG files, to ensure that you can read anyone's -output. Taking out support for image file formats that you don't use is the -most painless way to make the programs smaller. Another possibility is to -remove some of the DCT methods: in particular, the "IFAST" method may not be -enough faster than the others to be worth keeping on your machine. (If you -do remove ISLOW or IFAST, be sure to redefine JDCT_DEFAULT or JDCT_FASTEST -to a supported method, by adding a #define in jconfig.h.) - - -OPTIMIZATION -============ - -Unless you own a Cray, you'll probably be interested in making the JPEG -software go as fast as possible. This section covers some machine-dependent -optimizations you may want to try. We suggest that before trying any of -this, you first get the basic installation to pass the self-test step. -Repeat the self-test after any optimization to make sure that you haven't -broken anything. - -The integer DCT routines perform a lot of multiplications. These -multiplications must yield 32-bit results, but none of their input values -are more than 16 bits wide. On many machines, notably the 680x0 and 80x86 -CPUs, a 16x16=>32 bit multiply instruction is faster than a full 32x32=>32 -bit multiply. Unfortunately there is no portable way to specify such a -multiplication in C, but some compilers can generate one when you use the -right combination of casts. See the MULTIPLYxxx macro definitions in -jdct.h. If your compiler makes "int" be 32 bits and "short" be 16 bits, -defining SHORTxSHORT_32 is fairly likely to work. When experimenting with -alternate definitions, be sure to test not only whether the code still works -(use the self-test), but also whether it is actually faster --- on some -compilers, alternate definitions may compute the right answer, yet be slower -than the default. Timing cjpeg on a large PGM (grayscale) input file is the -best way to check this, as the DCT will be the largest fraction of the runtime -in that mode. (Note: some of the distributed compiler-specific jconfig files -already contain #define switches to select appropriate MULTIPLYxxx -definitions.) - -If your machine has sufficiently fast floating point hardware, you may find -that the float DCT method is faster than the integer DCT methods, even -after tweaking the integer multiply macros. In that case you may want to -make the float DCT be the default method. (The only objection to this is -that float DCT results may vary slightly across machines.) To do that, add -"#define JDCT_DEFAULT JDCT_FLOAT" to jconfig.h. Even if you don't change -the default, you should redefine JDCT_FASTEST, which is the method selected -by djpeg's -fast switch. Don't forget to update the documentation files -(usage.txt and/or cjpeg.1, djpeg.1) to agree with what you've done. - -If access to "short" arrays is slow on your machine, it may be a win to -define type JCOEF as int rather than short. This will cost a good deal of -memory though, particularly in some multi-pass modes, so don't do it unless -you have memory to burn and short is REALLY slow. - -If your compiler can compile function calls in-line, make sure the INLINE -macro in jmorecfg.h is defined as the keyword that marks a function -inline-able. Some compilers have a switch that tells the compiler to inline -any function it thinks is profitable (e.g., -finline-functions for gcc). -Enabling such a switch is likely to make the compiled code bigger but faster. - -In general, it's worth trying the maximum optimization level of your compiler, -and experimenting with any optional optimizations such as loop unrolling. -(Unfortunately, far too many compilers have optimizer bugs ... be prepared to -back off if the code fails self-test.) If you do any experimentation along -these lines, please report the optimal settings to jpeg-info@jpegclub.org so -we can mention them in future releases. Be sure to specify your machine and -compiler version. - - -HINTS FOR SPECIFIC SYSTEMS -========================== - -We welcome reports on changes needed for systems not mentioned here. Submit -'em to jpeg-info@jpegclub.org. Also, if configure or ckconfig.c is wrong -about how to configure the JPEG software for your system, please let us know. - - -Acorn RISC OS: - -(Thanks to Simon Middleton for these hints on compiling with Desktop C.) -After renaming the files according to Acorn conventions, take a copy of -makefile.ansi, change all occurrences of 'libjpeg.a' to 'libjpeg.o' and -change these definitions as indicated: - -CFLAGS= -throwback -IC: -Wn -LDLIBS=C:o.Stubs -SYSDEPMEM=jmemansi.o -LN=Link -AR=LibFile -c -o - -Also add a new line '.c.o:; $(cc) $< $(cflags) -c -o $@'. Remove the -lines '$(RM) libjpeg.o' and '$(AR2) libjpeg.o' and the 'jconfig.h' -dependency section. - -Copy jconfig.txt to jconfig.h. Edit jconfig.h to define TWO_FILE_COMMANDLINE -and CHAR_IS_UNSIGNED. - -Run the makefile using !AMU not !Make. If you want to use the 'clean' and -'test' makefile entries then you will have to fiddle with the syntax a bit -and rename the test files. - - -Amiga: - -SAS C 6.50 reportedly is too buggy to compile the IJG code properly. -A patch to update to 6.51 is available from SAS or AmiNet FTP sites. - -The supplied config files are set up to use jmemname.c as the memory -manager, with temporary files being created on the device named by -"JPEGTMP:". - - -Atari ST/STE/TT: - -Copy the project files makcjpeg.st, makdjpeg.st, maktjpeg.st, and makljpeg.st -to cjpeg.prj, djpeg.prj, jpegtran.prj, and libjpeg.prj respectively. The -project files should work as-is with Pure C. For Turbo C, change library -filenames "pc..." to "tc..." in each project file. Note that libjpeg.prj -selects jmemansi.c as the recommended memory manager. You'll probably want to -adjust the DEFAULT_MAX_MEM setting --- you want it to be a couple hundred K -less than your normal free memory. Put "#define DEFAULT_MAX_MEM nnnn" into -jconfig.h to do this. - -To use the 68881/68882 coprocessor for the floating point DCT, add the -compiler option "-8" to the project files and replace pcfltlib.lib with -pc881lib.lib in cjpeg.prj and djpeg.prj. Or if you don't have a -coprocessor, you may prefer to remove the float DCT code by undefining -DCT_FLOAT_SUPPORTED in jmorecfg.h (since without a coprocessor, the float -code will be too slow to be useful). In that case, you can delete -pcfltlib.lib from the project files. - -Note that you must make libjpeg.lib before making cjpeg.ttp, djpeg.ttp, -or jpegtran.ttp. You'll have to perform the self-test by hand. - -We haven't bothered to include project files for rdjpgcom and wrjpgcom. -Those source files should just be compiled by themselves; they don't -depend on the JPEG library. You can use the default.prj project file -of the Pure C distribution to make the programs. - -There is a bug in some older versions of the Turbo C library which causes the -space used by temporary files created with "tmpfile()" not to be freed after -an abnormal program exit. If you check your disk afterwards, you will find -cluster chains that are allocated but not used by a file. This should not -happen in cjpeg/djpeg/jpegtran, since we enable a signal catcher to explicitly -close temp files before exiting. But if you use the JPEG library with your -own code, be sure to supply a signal catcher, or else use a different -system-dependent memory manager. - - -Cray: - -Should you be so fortunate as to be running JPEG on a Cray YMP, there is a -compiler bug in old versions of Cray's Standard C (prior to 3.1). If you -still have an old compiler, you'll need to insert a line reading -"#pragma novector" just before the loop - for (i = 1; i <= (int) htbl->bits[l]; i++) - huffsize[p++] = (char) l; -in fix_huff_tbl (in V5beta1, line 204 of jchuff.c and line 176 of jdhuff.c). -[This bug may or may not still occur with the current IJG code, but it's -probably a dead issue anyway...] - - -HP-UX: - -If you have HP-UX 7.05 or later with the "software development" C compiler, -you should run the compiler in ANSI mode. If using the configure script, -say - ./configure CC='cc -Aa' -(or -Ae if you prefer). If configuring by hand, use makefile.ansi and add -"-Aa" to the CFLAGS line in the makefile. - -If you have a pre-7.05 system, or if you are using the non-ANSI C compiler -delivered with a minimum HP-UX system, then you must use makefile.unix -(and do NOT add -Aa); or just run configure without the CC option. - -On HP 9000 series 800 machines, the HP C compiler is buggy in revisions prior -to A.08.07. If you get complaints about "not a typedef name", you'll have to -use makefile.unix, or run configure without the CC option. - - -Macintosh, generic comments: - -The supplied user-interface files (cjpeg.c, djpeg.c, etc) are set up to -provide a Unix-style command line interface. You can use this interface on -the Mac by means of the ccommand() library routine provided by Metrowerks -CodeWarrior or Think C. This is only appropriate for testing the library, -however; to make a user-friendly equivalent of cjpeg/djpeg you'd really want -to develop a Mac-style user interface. There isn't a complete example -available at the moment, but there are some helpful starting points: -1. Sam Bushell's free "To JPEG" applet provides drag-and-drop conversion to -JPEG under System 7 and later. This only illustrates how to use the -compression half of the library, but it does a very nice job of that part. -The CodeWarrior source code is available from http://www.pobox.com/~jsam. -2. Jim Brunner prepared a Mac-style user interface for both compression and -decompression. Unfortunately, it hasn't been updated since IJG v4, and -the library's API has changed considerably since then. Still it may be of -some help, particularly as a guide to compiling the IJG code under Think C. -Jim's code is available from the Info-Mac archives, at sumex-aim.stanford.edu -or mirrors thereof; see file /info-mac/dev/src/jpeg-convert-c.hqx. - -jmemmac.c is the recommended memory manager back end for Macintosh. It uses -NewPtr/DisposePtr instead of malloc/free, and has a Mac-specific -implementation of jpeg_mem_available(). It also creates temporary files that -follow Mac conventions. (That part of the code relies on System-7-or-later OS -functions. See the comments in jmemmac.c if you need to run it on System 6.) -NOTE that USE_MAC_MEMMGR must be defined in jconfig.h to use jmemmac.c. - -You can also use jmemnobs.c, if you don't care about handling images larger -than available memory. If you use any memory manager back end other than -jmemmac.c, we recommend replacing "malloc" and "free" by "NewPtr" and -"DisposePtr", because Mac C libraries often have peculiar implementations of -malloc/free. (For instance, free() may not return the freed space to the -Mac Memory Manager. This is undesirable for the IJG code because jmemmgr.c -already clumps space requests.) - - -Macintosh, Metrowerks CodeWarrior: - -The Unix-command-line-style interface can be used by defining USE_CCOMMAND. -You'll also need to define TWO_FILE_COMMANDLINE to avoid stdin/stdout. -This means that when using the cjpeg/djpeg programs, you'll have to type the -input and output file names in the "Arguments" text-edit box, rather than -using the file radio buttons. (Perhaps USE_FDOPEN or USE_SETMODE would -eliminate the problem, but I haven't heard from anyone who's tried it.) - -On 680x0 Macs, Metrowerks defines type "double" as a 10-byte IEEE extended -float. jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power -of 2. Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint. - -The supplied configuration file jconfig.mac can be used for your jconfig.h; -it includes all the recommended symbol definitions. If you have AppleScript -installed, you can run the supplied script makeproj.mac to create CodeWarrior -project files for the library and the testbed applications, then build the -library and applications. (Thanks to Dan Sears and Don Agro for this nifty -hack, which saves us from trying to maintain CodeWarrior project files as part -of the IJG distribution...) - - -Macintosh, Think C: - -The documentation in Jim Brunner's "JPEG Convert" source code (see above) -includes detailed build instructions for Think C; it's probably somewhat -out of date for the current release, but may be helpful. - -If you want to build the minimal command line version, proceed as follows. -You'll have to prepare project files for the programs; we don't include any -in the distribution since they are not text files. Use the file lists in -any of the supplied makefiles as a guide. Also add the ANSI and Unix C -libraries in a separate segment. You may need to divide the JPEG files into -more than one segment; we recommend dividing compression and decompression -modules. Define USE_CCOMMAND in jconfig.h so that the ccommand() routine is -called. You must also define TWO_FILE_COMMANDLINE because stdin/stdout -don't handle binary data correctly. - -On 680x0 Macs, Think C defines type "double" as a 12-byte IEEE extended float. -jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power of 2. -Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint. - -jconfig.mac should work as a jconfig.h configuration file for Think C, -but the makeproj.mac AppleScript script is specific to CodeWarrior. Sorry. - - -MIPS R3000: - -MIPS's cc version 1.31 has a rather nasty optimization bug. Don't use -O -if you have that compiler version. (Use "cc -V" to check the version.) -Note that the R3000 chip is found in workstations from DEC and others. - - -MS-DOS, generic comments for 16-bit compilers: - -The IJG code is designed to work well in 80x86 "small" or "medium" memory -models (i.e., data pointers are 16 bits unless explicitly declared "far"; -code pointers can be either size). You may be able to use small model to -compile cjpeg or djpeg by itself, but you will probably have to use medium -model for any larger application. This won't make much difference in -performance. You *will* take a noticeable performance hit if you use a -large-data memory model, and you should avoid "huge" model if at all -possible. Be sure that NEED_FAR_POINTERS is defined in jconfig.h if you use -a small-data memory model; be sure it is NOT defined if you use a large-data -model. (The supplied makefiles and jconfig files for Borland and Microsoft C -compile in medium model and define NEED_FAR_POINTERS.) - -The DOS-specific memory manager, jmemdos.c, should be used if possible. -It needs some assembly-code routines which are in jmemdosa.asm; make sure -your makefile assembles that file and includes it in the library. If you -don't have a suitable assembler, you can get pre-assembled object files for -jmemdosa by FTP from ftp.uu.net:/graphics/jpeg/jdosaobj.zip. (DOS-oriented -distributions of the IJG source code often include these object files.) - -When using jmemdos.c, jconfig.h must define USE_MSDOS_MEMMGR and must set -MAX_ALLOC_CHUNK to less than 64K (65520L is a typical value). If your -C library's far-heap malloc() can't allocate blocks that large, reduce -MAX_ALLOC_CHUNK to whatever it can handle. - -If you can't use jmemdos.c for some reason --- for example, because you -don't have an assembler to assemble jmemdosa.asm --- you'll have to fall -back to jmemansi.c or jmemname.c. You'll probably still need to set -MAX_ALLOC_CHUNK in jconfig.h, because most DOS C libraries won't malloc() -more than 64K at a time. IMPORTANT: if you use jmemansi.c or jmemname.c, -you will have to compile in a large-data memory model in order to get the -right stdio library. Too bad. - -wrjpgcom needs to be compiled in large model, because it malloc()s a 64KB -work area to hold the comment text. If your C library's malloc can't -handle that, reduce MAX_COM_LENGTH as necessary in wrjpgcom.c. - -Most MS-DOS compilers treat stdin/stdout as text files, so you must use -two-file command line style. But if your compiler has either fdopen() or -setmode(), you can use one-file style if you like. To do this, define -USE_SETMODE or USE_FDOPEN so that stdin/stdout will be set to binary mode. -(USE_SETMODE seems to work with more DOS compilers than USE_FDOPEN.) You -should test that I/O through stdin/stdout produces the same results as I/O -to explicitly named files... the "make test" procedures in the supplied -makefiles do NOT use stdin/stdout. - - -MS-DOS, generic comments for 32-bit compilers: - -None of the above comments about memory models apply if you are using a -32-bit flat-memory-space environment, such as DJGPP or Watcom C. (And you -should use one if you have it, as performance will be much better than -8086-compatible code!) For flat-memory-space compilers, do NOT define -NEED_FAR_POINTERS, and do NOT use jmemdos.c. Use jmemnobs.c if the -environment supplies adequate virtual memory, otherwise use jmemansi.c or -jmemname.c. - -You'll still need to be careful about binary I/O through stdin/stdout. -See the last paragraph of the previous section. - - -MS-DOS, Borland C: - -Be sure to convert all the source files to DOS text format (CR/LF newlines). -Although Borland C will often work OK with unmodified Unix (LF newlines) -source files, sometimes it will give bogus compile errors. -"Illegal character '#'" is the most common such error. (This is true with -Borland C 3.1, but perhaps is fixed in newer releases.) - -If you want one-file command line style, just undefine TWO_FILE_COMMANDLINE. -jconfig.bcc already includes #define USE_SETMODE to make this work. -(fdopen does not work correctly.) - - -MS-DOS, Microsoft C: - -makefile.mc6 works with Microsoft C, DOS Visual C++, etc. It should only -be used if you want to build a 16-bit (small or medium memory model) program. - -If you want one-file command line style, just undefine TWO_FILE_COMMANDLINE. -jconfig.mc6 already includes #define USE_SETMODE to make this work. -(fdopen does not work correctly.) - -Note that this makefile assumes that the working copy of itself is called -"makefile". If you want to call it something else, say "makefile.mak", -be sure to adjust the dependency line that reads "$(RFILE) : makefile". -Otherwise the make will fail because it doesn't know how to create "makefile". -Worse, some releases of Microsoft's make utilities give an incorrect error -message in this situation. - -Old versions of MS C fail with an "out of macro expansion space" error -because they can't cope with the macro TRACEMS8 (defined in jerror.h). -If this happens to you, the easiest solution is to change TRACEMS8 to -expand to nothing. You'll lose the ability to dump out JPEG coefficient -tables with djpeg -debug -debug, but at least you can compile. - -Original MS C 6.0 is very buggy; it compiles incorrect code unless you turn -off optimization entirely (remove -O from CFLAGS). 6.00A is better, but it -still generates bad code if you enable loop optimizations (-Ol or -Ox). - -MS C 8.0 crashes when compiling jquant1.c with optimization switch /Oo ... -which is on by default. To work around this bug, compile that one file -with /Oo-. - - -Microsoft Windows (all versions), generic comments: - -Some Windows system include files define typedef boolean as "unsigned char". -The IJG code also defines typedef boolean, but we make it "int" by default. -This doesn't affect the IJG programs because we don't import those Windows -include files. But if you use the JPEG library in your own program, and some -of your program's files import one definition of boolean while some import the -other, you can get all sorts of mysterious problems. A good preventive step -is to make the IJG library use "unsigned char" for boolean. To do that, -add something like this to your jconfig.h file: - /* Define "boolean" as unsigned char, not int, per Windows custom */ - #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ - typedef unsigned char boolean; - #endif - #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ -(This is already in jconfig.vc, by the way.) - -windef.h contains the declarations - #define far - #define FAR far -Since jmorecfg.h tries to define FAR as empty, you may get a compiler -warning if you include both jpeglib.h and windef.h (which windows.h -includes). To suppress the warning, you can put "#ifndef FAR"/"#endif" -around the line "#define FAR" in jmorecfg.h. -(Something like this is already in jmorecfg.h, by the way.) - -When using the library in a Windows application, you will almost certainly -want to modify or replace the error handler module jerror.c, since our -default error handler does a couple of inappropriate things: - 1. it tries to write error and warning messages on stderr; - 2. in event of a fatal error, it exits by calling exit(). - -A simple stopgap solution for problem 1 is to replace the line - fprintf(stderr, "%s\n", buffer); -(in output_message in jerror.c) with - MessageBox(GetActiveWindow(),buffer,"JPEG Error",MB_OK|MB_ICONERROR); -It's highly recommended that you at least do that much, since otherwise -error messages will disappear into nowhere. (Beginning with IJG v6b, this -code is already present in jerror.c; just define USE_WINDOWS_MESSAGEBOX in -jconfig.h to enable it.) - -The proper solution for problem 2 is to return control to your calling -application after a library error. This can be done with the setjmp/longjmp -technique discussed in libjpeg.txt and illustrated in example.c. (NOTE: -some older Windows C compilers provide versions of setjmp/longjmp that -don't actually work under Windows. You may need to use the Windows system -functions Catch and Throw instead.) - -The recommended memory manager under Windows is jmemnobs.c; in other words, -let Windows do any virtual memory management needed. You should NOT use -jmemdos.c nor jmemdosa.asm under Windows. - -For Windows 3.1, we recommend compiling in medium or large memory model; -for newer Windows versions, use a 32-bit flat memory model. (See the MS-DOS -sections above for more info about memory models.) In the 16-bit memory -models only, you'll need to put - #define MAX_ALLOC_CHUNK 65520L /* Maximum request to malloc() */ -into jconfig.h to limit allocation chunks to 64Kb. (Without that, you'd -have to use huge memory model, which slows things down unnecessarily.) -jmemnobs.c works without modification in large or flat memory models, but to -use medium model, you need to modify its jpeg_get_large and jpeg_free_large -routines to allocate far memory. In any case, you might like to replace -its calls to malloc and free with direct calls on Windows memory allocation -functions. - -You may also want to modify jdatasrc.c and jdatadst.c to use Windows file -operations rather than fread/fwrite. This is only necessary if your C -compiler doesn't provide a competent implementation of C stdio functions. - -You might want to tweak the RGB_xxx macros in jmorecfg.h so that the library -will accept or deliver color pixels in BGR sample order, not RGB; BGR order -is usually more convenient under Windows. Note that this change will break -the sample applications cjpeg/djpeg, but the library itself works fine. - - -Many people want to convert the IJG library into a DLL. This is reasonably -straightforward, but watch out for the following: - - 1. Don't try to compile as a DLL in small or medium memory model; use -large model, or even better, 32-bit flat model. Many places in the IJG code -assume the address of a local variable is an ordinary (not FAR) pointer; -that isn't true in a medium-model DLL. - - 2. Microsoft C cannot pass file pointers between applications and DLLs. -(See Microsoft Knowledge Base, PSS ID Number Q50336.) So jdatasrc.c and -jdatadst.c don't work if you open a file in your application and then pass -the pointer to the DLL. One workaround is to make jdatasrc.c/jdatadst.c -part of your main application rather than part of the DLL. - - 3. You'll probably need to modify the macros GLOBAL() and EXTERN() to -attach suitable linkage keywords to the exported routine names. Similarly, -you'll want to modify METHODDEF() and JMETHOD() to ensure function pointers -are declared in a way that lets application routines be called back through -the function pointers. These macros are in jmorecfg.h. Typical definitions -for a 16-bit DLL are: - #define GLOBAL(type) type _far _pascal _loadds _export - #define EXTERN(type) extern type _far _pascal _loadds - #define METHODDEF(type) static type _far _pascal - #define JMETHOD(type,methodname,arglist) \ - type (_far _pascal *methodname) arglist -For a 32-bit DLL you may want something like - #define GLOBAL(type) __declspec(dllexport) type - #define EXTERN(type) extern __declspec(dllexport) type -Although not all the GLOBAL routines are actually intended to be called by -the application, the performance cost of making them all DLL entry points is -negligible. - -The unmodified IJG library presents a very C-specific application interface, -so the resulting DLL is only usable from C or C++ applications. There has -been some talk of writing wrapper code that would present a simpler interface -usable from other languages, such as Visual Basic. This is on our to-do list -but hasn't been very high priority --- any volunteers out there? - - -Microsoft Windows, Borland C: - -The provided jconfig.bcc should work OK in a 32-bit Windows environment, -but you'll need to tweak it in a 16-bit environment (you'd need to define -NEED_FAR_POINTERS and MAX_ALLOC_CHUNK). Beware that makefile.bcc will need -alteration if you want to use it for Windows --- in particular, you should -use jmemnobs.c not jmemdos.c under Windows. - -Borland C++ 4.5 fails with an internal compiler error when trying to compile -jdmerge.c in 32-bit mode. If enough people complain, perhaps Borland will fix -it. In the meantime, the simplest known workaround is to add a redundant -definition of the variable range_limit in h2v1_merged_upsample(), at the head -of the block that handles odd image width (about line 268 in v6 jdmerge.c): - /* If image width is odd, do the last output column separately */ - if (cinfo->output_width & 1) { - register JSAMPLE * range_limit = cinfo->sample_range_limit; /* ADD THIS */ - cb = GETJSAMPLE(*inptr1); -Pretty bizarre, especially since the very similar routine h2v2_merged_upsample -doesn't trigger the bug. -Recent reports suggest that this bug does not occur with "bcc32a" (the -Pentium-optimized version of the compiler). - -Another report from a user of Borland C 4.5 was that incorrect code (leading -to a color shift in processed images) was produced if any of the following -optimization switch combinations were used: - -Ot -Og - -Ot -Op - -Ot -Om -So try backing off on optimization if you see such a problem. (Are there -several different releases all numbered "4.5"??) - - -Microsoft Windows, Microsoft Visual C++: - -jconfig.vc should work OK with any Microsoft compiler for a 32-bit memory -model. makefile.vc is intended for command-line use. (If you are using -the Developer Studio environment, you may prefer the DevStudio project -files; see below.) - -IJG JPEG 7 adds extern "C" to jpeglib.h. This avoids the need to put -extern "C" { ... } around #include "jpeglib.h" in your C++ application. -You can also force VC++ to treat the library as C++ code by renaming -all the *.c files to *.cpp (and adjusting the makefile to match). -In this case you also need to define the symbol DONT_USE_EXTERN_C in -the configuration to prevent jpeglib.h from using extern "C". - - -Microsoft Windows, Microsoft Visual C++ 6 Developer Studio: - -We include makefiles that should work as project files in DevStudio 6.0 or -later. There is a library makefile that builds the IJG library as a static -Win32 library, and application makefiles that build the sample applications -as Win32 console applications. (Even if you only want the library, we -recommend building the applications so that you can run the self-test.) - -To use: -1. Open the command prompt, change to the main directory and execute the - command line - NMAKE /f makefile.vc setup-vc6 - This will move jconfig.vc to jconfig.h and makefiles to project files. - (Note that the renaming is critical!) -2. Open the workspace file jpeg.dsw, build the library project. - (If you are using DevStudio more recent than 6.0, you'll probably - get a message saying that the project files are being updated.) -3. Open the workspace file apps.dsw, build the application projects. -4. To perform the self-test, execute the command line - NMAKE /f makefile.vc test-build -5. Move the application .exe files from `app`\Release to an - appropriate location on your path. - - -Microsoft Windows, Microsoft Visual C++ 2010 Developer Studio (v10): - -We include makefiles that should work as project files in Visual Studio -2010 or later. There is a library makefile that builds the IJG library -as a static Win32 library, and application makefiles that build the sample -applications as Win32 console applications. (Even if you only want the -library, we recommend building the applications so that you can run the -self-test.) - -To use: -1. Open the command prompt, change to the main directory and execute the - command line - NMAKE /f makefile.vc setup-v10 - This will move jconfig.vc to jconfig.h and makefiles to project files. - (Note that the renaming is critical!) -2. Open the solution file jpeg.sln, build the library project. - (If you are using Visual Studio more recent than 2010 (v10), you'll - probably get a message saying that the project files are being updated.) -3. Open the solution file apps.sln, build the application projects. -4. To perform the self-test, execute the command line - NMAKE /f makefile.vc test-build -5. Move the application .exe files from `app`\Release to an - appropriate location on your path. - -Note: -There seems to be an optimization bug in the compiler which causes the -self-test to fail with the color quantization option. -We have disabled optimization for the file jquant2.c in the library -project file which causes the self-test to pass properly. - - -OS/2, Borland C++: - -Watch out for optimization bugs in older Borland compilers; you may need -to back off the optimization switch settings. See the comments in -makefile.bcc. - - -SGI: - -On some SGI systems, you may need to set "AR2= ar -ts" in the Makefile. -If you are using configure, you can do this by saying - ./configure RANLIB='ar -ts' -This change is not needed on all SGIs. Use it only if the make fails at the -stage of linking the completed programs. - -On the MIPS R4000 architecture (Indy, etc.), the compiler option "-mips2" -reportedly speeds up the float DCT method substantially, enough to make it -faster than the default int method (but still slower than the fast int -method). If you use -mips2, you may want to alter the default DCT method to -be float. To do this, put "#define JDCT_DEFAULT JDCT_FLOAT" in jconfig.h. - - -VMS: - -On an Alpha/VMS system with MMS, be sure to use the "/Marco=Alpha=1" -qualifier with MMS when building the JPEG package. - -VAX/VMS v5.5-1 may have problems with the test step of the build procedure -reporting differences when it compares the original and test images. If the -error points to the last block of the files, it is most likely bogus and may -be safely ignored. It seems to be because the files are Stream_LF and -Backup/Compare has difficulty with the (presumably) null padded files. -This problem was not observed on VAX/VMS v6.1 or AXP/VMS v6.1. +INSTALLATION INSTRUCTIONS for the Independent JPEG Group's JPEG software + +Copyright (C) 1991-2011, Thomas G. Lane, Guido Vollbeding. +This file is part of the Independent JPEG Group's software. +For conditions of distribution and use, see the accompanying README file. + + +This file explains how to configure and install the IJG software. We have +tried to make this software extremely portable and flexible, so that it can be +adapted to almost any environment. The downside of this decision is that the +installation process is complicated. We have provided shortcuts to simplify +the task on common systems. But in any case, you will need at least a little +familiarity with C programming and program build procedures for your system. + +If you are only using this software as part of a larger program, the larger +program's installation procedure may take care of configuring the IJG code. +For example, Ghostscript's installation script will configure the IJG code. +You don't need to read this file if you just want to compile Ghostscript. + +If you are on a Unix machine, you may not need to read this file at all. +Try doing + ./configure + make + make test +If that doesn't complain, do + make install +(better do "make -n install" first to see if the makefile will put the files +where you want them). Read further if you run into snags or want to customize +the code for your system. + + +TABLE OF CONTENTS +----------------- + +Before you start +Configuring the software: + using the automatic "configure" script + using one of the supplied jconfig and makefile files + by hand +Building the software +Testing the software +Installing the software +Optional stuff +Optimization +Hints for specific systems + + +BEFORE YOU START +================ + +Before installing the software you must unpack the distributed source code. +Since you are reading this file, you have probably already succeeded in this +task. However, there is a potential for error if you needed to convert the +files to the local standard text file format (for example, if you are on +MS-DOS you may have converted LF end-of-line to CR/LF). You must apply +such conversion to all the files EXCEPT those whose names begin with "test". +The test files contain binary data; if you change them in any way then the +self-test will give bad results. + +Please check the last section of this file to see if there are hints for the +specific machine or compiler you are using. + + +CONFIGURING THE SOFTWARE +======================== + +To configure the IJG code for your system, you need to create two files: + * jconfig.h: contains values for system-dependent #define symbols. + * Makefile: controls the compilation process. +(On a non-Unix machine, you may create "project files" or some other +substitute for a Makefile. jconfig.h is needed in any environment.) + +We provide three different ways to generate these files: + * On a Unix system, you can just run the "configure" script. + * We provide sample jconfig files and makefiles for popular machines; + if your machine matches one of the samples, just copy the right sample + files to jconfig.h and Makefile. + * If all else fails, read the instructions below and make your own files. + + +Configuring the software using the automatic "configure" script +--------------------------------------------------------------- + +If you are on a Unix machine, you can just type + ./configure +and let the configure script construct appropriate configuration files. +If you're using "csh" on an old version of System V, you might need to type + sh configure +instead to prevent csh from trying to execute configure itself. +Expect configure to run for a few minutes, particularly on slower machines; +it works by compiling a series of test programs. + +Configure was created with GNU Autoconf and it follows the usual conventions +for GNU configure scripts. It makes a few assumptions that you may want to +override. You can do this by providing optional switches to configure: + +* Configure will build both static and shared libraries, if possible. +If you want to build libjpeg only as a static library, say + ./configure --disable-shared +If you want to build libjpeg only as a shared library, say + ./configure --disable-static +Configure uses GNU libtool to take care of system-dependent shared library +building methods. + +* Configure will use gcc (GNU C compiler) if it's available, otherwise cc. +To force a particular compiler to be selected, use the CC option, for example + ./configure CC='cc' +The same method can be used to include any unusual compiler switches. +For example, on HP-UX you probably want to say + ./configure CC='cc -Aa' +to get HP's compiler to run in ANSI mode. + +* The default CFLAGS setting is "-g" for non-gcc compilers, "-g -O2" for gcc. +You can override this by saying, for example, + ./configure CFLAGS='-O2' +if you want to compile without debugging support. + +* Configure will set up the makefile so that "make install" will install files +into /usr/local/bin, /usr/local/man, etc. You can specify an installation +prefix other than "/usr/local" by giving configure the option "--prefix=PATH". + +* If you don't have a lot of swap space, you may need to enable the IJG +software's internal virtual memory mechanism. To do this, give the option +"--enable-maxmem=N" where N is the default maxmemory limit in megabytes. +This is discussed in more detail under "Selecting a memory manager", below. +You probably don't need to worry about this on reasonably-sized Unix machines, +unless you plan to process very large images. + +Configure has some other features that are useful if you are cross-compiling +or working in a network of multiple machine types; but if you need those +features, you probably already know how to use them. + + +Configuring the software using one of the supplied jconfig and makefile files +----------------------------------------------------------------------------- + +If you have one of these systems, you can just use the provided configuration +files: + +Makefile jconfig file System and/or compiler + +makefile.manx jconfig.manx Amiga, Manx Aztec C +makefile.sas jconfig.sas Amiga, SAS C +makeproj.mac jconfig.mac Apple Macintosh, Metrowerks CodeWarrior +mak*jpeg.st jconfig.st Atari ST/STE/TT, Pure C or Turbo C +makefile.bcc jconfig.bcc MS-DOS or OS/2, Borland C +makefile.dj jconfig.dj MS-DOS, DJGPP (Delorie's port of GNU C) +makefile.mc6 jconfig.mc6 MS-DOS, Microsoft C (16-bit only) +makefile.wat jconfig.wat MS-DOS, OS/2, or Windows NT, Watcom C +makefile.vc jconfig.vc Windows NT/95, MS Visual C++ +make*.vc6 jconfig.vc Windows NT/95, MS Visual C++ 6 +make*.v10 jconfig.vc Windows NT/95, MS Visual C++ 2010 (v10) +makefile.mms jconfig.vms Digital VMS, with MMS software +makefile.vms jconfig.vms Digital VMS, without MMS software + +Copy the proper jconfig file to jconfig.h and the makefile to Makefile (or +whatever your system uses as the standard makefile name). For more info see +the appropriate system-specific hints section near the end of this file. + + +Configuring the software by hand +-------------------------------- + +First, generate a jconfig.h file. If you are moderately familiar with C, +the comments in jconfig.txt should be enough information to do this; just +copy jconfig.txt to jconfig.h and edit it appropriately. Otherwise, you may +prefer to use the ckconfig.c program. You will need to compile and execute +ckconfig.c by hand --- we hope you know at least enough to do that. +ckconfig.c may not compile the first try (in fact, the whole idea is for it +to fail if anything is going to). If you get compile errors, fix them by +editing ckconfig.c according to the directions given in ckconfig.c. Once +you get it to run, it will write a suitable jconfig.h file, and will also +print out some advice about which makefile to use. + +You may also want to look at the canned jconfig files, if there is one for a +system similar to yours. + +Second, select a makefile and copy it to Makefile (or whatever your system +uses as the standard makefile name). The most generic makefiles we provide +are + makefile.ansi: if your C compiler supports function prototypes + makefile.unix: if not. +(You have function prototypes if ckconfig.c put "#define HAVE_PROTOTYPES" +in jconfig.h.) You may want to start from one of the other makefiles if +there is one for a system similar to yours. + +Look over the selected Makefile and adjust options as needed. In particular +you may want to change the CC and CFLAGS definitions. For instance, if you +are using GCC, set CC=gcc. If you had to use any compiler switches to get +ckconfig.c to work, make sure the same switches are in CFLAGS. + +If you are on a system that doesn't use makefiles, you'll need to set up +project files (or whatever you do use) to compile all the source files and +link them into executable files cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom. +See the file lists in any of the makefiles to find out which files go into +each program. Note that the provided makefiles all make a "library" file +libjpeg first, but you don't have to do that if you don't want to; the file +lists identify which source files are actually needed for compression, +decompression, or both. As a last resort, you can make a batch script that +just compiles everything and links it all together; makefile.vms is an example +of this (it's for VMS systems that have no make-like utility). + +Here are comments about some specific configuration decisions you'll +need to make: + +Command line style +------------------ + +These programs can use a Unix-like command line style which supports +redirection and piping, like this: + cjpeg inputfile >outputfile + cjpeg outputfile + source program | cjpeg >outputfile +The simpler "two file" command line style is just + cjpeg inputfile outputfile +You may prefer the two-file style, particularly if you don't have pipes. + +You MUST use two-file style on any system that doesn't cope well with binary +data fed through stdin/stdout; this is true for some MS-DOS compilers, for +example. If you're not on a Unix system, it's safest to assume you need +two-file style. (But if your compiler provides either the Posix-standard +fdopen() library routine or a Microsoft-compatible setmode() routine, you +can safely use the Unix command line style, by defining USE_FDOPEN or +USE_SETMODE respectively.) + +To use the two-file style, make jconfig.h say "#define TWO_FILE_COMMANDLINE". + +Selecting a memory manager +-------------------------- + +The IJG code is capable of working on images that are too big to fit in main +memory; data is swapped out to temporary files as necessary. However, the +code to do this is rather system-dependent. We provide five different +memory managers: + +* jmemansi.c This version uses the ANSI-standard library routine tmpfile(), + which not all non-ANSI systems have. On some systems + tmpfile() may put the temporary file in a non-optimal + location; if you don't like what it does, use jmemname.c. + +* jmemname.c This version creates named temporary files. For anything + except a Unix machine, you'll need to configure the + select_file_name() routine appropriately; see the comments + near the head of jmemname.c. If you use this version, define + NEED_SIGNAL_CATCHER in jconfig.h to make sure the temp files + are removed if the program is aborted. + +* jmemnobs.c (That stands for No Backing Store :-).) This will compile on + almost any system, but it assumes you have enough main memory + or virtual memory to hold the biggest images you work with. + +* jmemdos.c This should be used with most 16-bit MS-DOS compilers. + See the system-specific notes about MS-DOS for more info. + IMPORTANT: if you use this, define USE_MSDOS_MEMMGR in + jconfig.h, and include the assembly file jmemdosa.asm in the + programs. The supplied makefiles and jconfig files for + 16-bit MS-DOS compilers already do both. + +* jmemmac.c Custom version for Apple Macintosh; see the system-specific + notes for Macintosh for more info. + +To use a particular memory manager, change the SYSDEPMEM variable in your +makefile to equal the corresponding object file name (for example, jmemansi.o +or jmemansi.obj for jmemansi.c). + +If you have plenty of (real or virtual) main memory, just use jmemnobs.c. +"Plenty" means about ten bytes for every pixel in the largest images +you plan to process, so a lot of systems don't meet this criterion. +If yours doesn't, try jmemansi.c first. If that doesn't compile, you'll have +to use jmemname.c; be sure to adjust select_file_name() for local conditions. +You may also need to change unlink() to remove() in close_backing_store(). + +Except with jmemnobs.c or jmemmac.c, you need to adjust the DEFAULT_MAX_MEM +setting to a reasonable value for your system (either by adding a #define for +DEFAULT_MAX_MEM to jconfig.h, or by adding a -D switch to the Makefile). +This value limits the amount of data space the program will attempt to +allocate. Code and static data space isn't counted, so the actual memory +needs for cjpeg or djpeg are typically 100 to 150Kb more than the max-memory +setting. Larger max-memory settings reduce the amount of I/O needed to +process a large image, but too large a value can result in "insufficient +memory" failures. On most Unix machines (and other systems with virtual +memory), just set DEFAULT_MAX_MEM to several million and forget it. At the +other end of the spectrum, for MS-DOS machines you probably can't go much +above 300K to 400K. (On MS-DOS the value refers to conventional memory only. +Extended/expanded memory is handled separately by jmemdos.c.) + + +BUILDING THE SOFTWARE +===================== + +Now you should be able to compile the software. Just say "make" (or +whatever's necessary to start the compilation). Have a cup of coffee. + +Here are some things that could go wrong: + +If your compiler complains about undefined structures, you should be able to +shut it up by putting "#define INCOMPLETE_TYPES_BROKEN" in jconfig.h. + +If you have trouble with missing system include files or inclusion of the +wrong ones, read jinclude.h. This shouldn't happen if you used configure +or ckconfig.c to set up jconfig.h. + +There are a fair number of routines that do not use all of their parameters; +some compilers will issue warnings about this, which you can ignore. There +are also a few configuration checks that may give "unreachable code" warnings. +Any other warning deserves investigation. + +If you don't have a getenv() library routine, define NO_GETENV. + +Also see the system-specific hints, below. + + +TESTING THE SOFTWARE +==================== + +As a quick test of functionality we've included a small sample image in +several forms: + testorig.jpg Starting point for the djpeg tests. + testimg.ppm The output of djpeg testorig.jpg + testimg.bmp The output of djpeg -bmp -colors 256 testorig.jpg + testimg.jpg The output of cjpeg testimg.ppm + testprog.jpg Progressive-mode equivalent of testorig.jpg. + testimgp.jpg The output of cjpeg -progressive -optimize testimg.ppm +(The first- and second-generation .jpg files aren't identical since the +default compression parameters are lossy.) If you can generate duplicates +of the testimg* files then you probably have working programs. + +With most of the makefiles, "make test" will perform the necessary +comparisons. + +If you're using a makefile that doesn't provide the test option, run djpeg +and cjpeg by hand and compare the output files to testimg* with whatever +binary file comparison tool you have. The files should be bit-for-bit +identical. + +If the programs complain "MAX_ALLOC_CHUNK is wrong, please fix", then you +need to reduce MAX_ALLOC_CHUNK to a value that fits in type size_t. +Try adding "#define MAX_ALLOC_CHUNK 65520L" to jconfig.h. A less likely +configuration error is "ALIGN_TYPE is wrong, please fix": defining ALIGN_TYPE +as long should take care of that one. + +If the cjpeg test run fails with "Missing Huffman code table entry", it's a +good bet that you needed to define RIGHT_SHIFT_IS_UNSIGNED. Go back to the +configuration step and run ckconfig.c. (This is a good plan for any other +test failure, too.) + +If you are using Unix (one-file) command line style on a non-Unix system, +it's a good idea to check that binary I/O through stdin/stdout actually +works. You should get the same results from "djpeg out.ppm" +as from "djpeg -outfile out.ppm testorig.jpg". Note that the makefiles all +use the latter style and therefore do not exercise stdin/stdout! If this +check fails, try recompiling with USE_SETMODE or USE_FDOPEN defined. +If it still doesn't work, better use two-file style. + +If you chose a memory manager other than jmemnobs.c, you should test that +temporary-file usage works. Try "djpeg -bmp -colors 256 -max 0 testorig.jpg" +and make sure its output matches testimg.bmp. If you have any really large +images handy, try compressing them with -optimize and/or decompressing with +-colors 256 to make sure your DEFAULT_MAX_MEM setting is not too large. + +NOTE: this is far from an exhaustive test of the JPEG software; some modules, +such as 1-pass color quantization, are not exercised at all. It's just a +quick test to give you some confidence that you haven't missed something +major. + + +INSTALLING THE SOFTWARE +======================= + +Once you're done with the above steps, you can install the software by +copying the executable files (cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom) +to wherever you normally install programs. On Unix systems, you'll also want +to put the man pages (cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1) +in the man-page directory. The pre-fab makefiles don't support this step +since there's such a wide variety of installation procedures on different +systems. + +If you generated a Makefile with the "configure" script, you can just say + make install +to install the programs and their man pages into the standard places. +(You'll probably need to be root to do this.) We recommend first saying + make -n install +to see where configure thought the files should go. You may need to edit +the Makefile, particularly if your system's conventions for man page +filenames don't match what configure expects. + +If you want to install the IJG library itself, for use in compiling other +programs besides ours, then you need to put the four include files + jpeglib.h jerror.h jconfig.h jmorecfg.h +into your include-file directory, and put the library file libjpeg.a +(extension may vary depending on system) wherever library files go. +If you generated a Makefile with "configure", it will do what it thinks +is the right thing if you say + make install-lib + + +OPTIONAL STUFF +============== + +Progress monitor: + +If you like, you can #define PROGRESS_REPORT (in jconfig.h) to enable display +of percent-done progress reports. The routine provided in cdjpeg.c merely +prints percentages to stderr, but you can customize it to do something +fancier. + +Utah RLE file format support: + +We distribute the software with support for RLE image files (Utah Raster +Toolkit format) disabled, because the RLE support won't compile without the +Utah library. If you have URT version 3.1 or later, you can enable RLE +support as follows: + 1. #define RLE_SUPPORTED in jconfig.h. + 2. Add a -I option to CFLAGS in the Makefile for the directory + containing the URT .h files (typically the "include" + subdirectory of the URT distribution). + 3. Add -L... -lrle to LDLIBS in the Makefile, where ... specifies + the directory containing the URT "librle.a" file (typically the + "lib" subdirectory of the URT distribution). + +Support for 12-bit-deep pixel data: + +The JPEG standard allows either 8-bit or 12-bit data precision. (For color, +this means 8 or 12 bits per channel, of course.) If you need to work with +deeper than 8-bit data, you can compile the IJG code for 12-bit operation. +To do so: + 1. In jmorecfg.h, define BITS_IN_JSAMPLE as 12 rather than 8. + 2. In jconfig.h, undefine BMP_SUPPORTED, RLE_SUPPORTED, and TARGA_SUPPORTED, + because the code for those formats doesn't handle 12-bit data and won't + even compile. (The PPM code does work, as explained below. The GIF + code works too; it scales 8-bit GIF data to and from 12-bit depth + automatically.) + 3. Compile. Don't expect "make test" to pass, since the supplied test + files are for 8-bit data. + +Currently, 12-bit support does not work on 16-bit-int machines. + +Note that a 12-bit version will not read 8-bit JPEG files, nor vice versa; +so you'll want to keep around a regular 8-bit compilation as well. +(Run-time selection of data depth, to allow a single copy that does both, +is possible but would probably slow things down considerably; it's very low +on our to-do list.) + +The PPM reader (rdppm.c) can read 12-bit data from either text-format or +binary-format PPM and PGM files. Binary-format PPM/PGM files which have a +maxval greater than 255 are assumed to use 2 bytes per sample, MSB first +(big-endian order). As of early 1995, 2-byte binary format is not +officially supported by the PBMPLUS library, but it is expected that a +future release of PBMPLUS will support it. Note that the PPM reader will +read files of any maxval regardless of the BITS_IN_JSAMPLE setting; incoming +data is automatically rescaled to either maxval=255 or maxval=4095 as +appropriate for the cjpeg bit depth. + +The PPM writer (wrppm.c) will normally write 2-byte binary PPM or PGM +format, maxval 4095, when compiled with BITS_IN_JSAMPLE=12. Since this +format is not yet widely supported, you can disable it by compiling wrppm.c +with PPM_NORAWWORD defined; then the data is scaled down to 8 bits to make a +standard 1-byte/sample PPM or PGM file. (Yes, this means still another copy +of djpeg to keep around. But hopefully you won't need it for very long. +Poskanzer's supposed to get that new PBMPLUS release out Real Soon Now.) + +Of course, if you are working with 12-bit data, you probably have it stored +in some other, nonstandard format. In that case you'll probably want to +write your own I/O modules to read and write your format. + +Note that a 12-bit version of cjpeg always runs in "-optimize" mode, in +order to generate valid Huffman tables. This is necessary because our +default Huffman tables only cover 8-bit data. + +Removing code: + +If you need to make a smaller version of the JPEG software, some optional +functions can be removed at compile time. See the xxx_SUPPORTED #defines in +jconfig.h and jmorecfg.h. If at all possible, we recommend that you leave in +decoder support for all valid JPEG files, to ensure that you can read anyone's +output. Taking out support for image file formats that you don't use is the +most painless way to make the programs smaller. Another possibility is to +remove some of the DCT methods: in particular, the "IFAST" method may not be +enough faster than the others to be worth keeping on your machine. (If you +do remove ISLOW or IFAST, be sure to redefine JDCT_DEFAULT or JDCT_FASTEST +to a supported method, by adding a #define in jconfig.h.) + + +OPTIMIZATION +============ + +Unless you own a Cray, you'll probably be interested in making the JPEG +software go as fast as possible. This section covers some machine-dependent +optimizations you may want to try. We suggest that before trying any of +this, you first get the basic installation to pass the self-test step. +Repeat the self-test after any optimization to make sure that you haven't +broken anything. + +The integer DCT routines perform a lot of multiplications. These +multiplications must yield 32-bit results, but none of their input values +are more than 16 bits wide. On many machines, notably the 680x0 and 80x86 +CPUs, a 16x16=>32 bit multiply instruction is faster than a full 32x32=>32 +bit multiply. Unfortunately there is no portable way to specify such a +multiplication in C, but some compilers can generate one when you use the +right combination of casts. See the MULTIPLYxxx macro definitions in +jdct.h. If your compiler makes "int" be 32 bits and "short" be 16 bits, +defining SHORTxSHORT_32 is fairly likely to work. When experimenting with +alternate definitions, be sure to test not only whether the code still works +(use the self-test), but also whether it is actually faster --- on some +compilers, alternate definitions may compute the right answer, yet be slower +than the default. Timing cjpeg on a large PGM (grayscale) input file is the +best way to check this, as the DCT will be the largest fraction of the runtime +in that mode. (Note: some of the distributed compiler-specific jconfig files +already contain #define switches to select appropriate MULTIPLYxxx +definitions.) + +If your machine has sufficiently fast floating point hardware, you may find +that the float DCT method is faster than the integer DCT methods, even +after tweaking the integer multiply macros. In that case you may want to +make the float DCT be the default method. (The only objection to this is +that float DCT results may vary slightly across machines.) To do that, add +"#define JDCT_DEFAULT JDCT_FLOAT" to jconfig.h. Even if you don't change +the default, you should redefine JDCT_FASTEST, which is the method selected +by djpeg's -fast switch. Don't forget to update the documentation files +(usage.txt and/or cjpeg.1, djpeg.1) to agree with what you've done. + +If access to "short" arrays is slow on your machine, it may be a win to +define type JCOEF as int rather than short. This will cost a good deal of +memory though, particularly in some multi-pass modes, so don't do it unless +you have memory to burn and short is REALLY slow. + +If your compiler can compile function calls in-line, make sure the INLINE +macro in jmorecfg.h is defined as the keyword that marks a function +inline-able. Some compilers have a switch that tells the compiler to inline +any function it thinks is profitable (e.g., -finline-functions for gcc). +Enabling such a switch is likely to make the compiled code bigger but faster. + +In general, it's worth trying the maximum optimization level of your compiler, +and experimenting with any optional optimizations such as loop unrolling. +(Unfortunately, far too many compilers have optimizer bugs ... be prepared to +back off if the code fails self-test.) If you do any experimentation along +these lines, please report the optimal settings to jpeg-info@jpegclub.org so +we can mention them in future releases. Be sure to specify your machine and +compiler version. + + +HINTS FOR SPECIFIC SYSTEMS +========================== + +We welcome reports on changes needed for systems not mentioned here. Submit +'em to jpeg-info@jpegclub.org. Also, if configure or ckconfig.c is wrong +about how to configure the JPEG software for your system, please let us know. + + +Acorn RISC OS: + +(Thanks to Simon Middleton for these hints on compiling with Desktop C.) +After renaming the files according to Acorn conventions, take a copy of +makefile.ansi, change all occurrences of 'libjpeg.a' to 'libjpeg.o' and +change these definitions as indicated: + +CFLAGS= -throwback -IC: -Wn +LDLIBS=C:o.Stubs +SYSDEPMEM=jmemansi.o +LN=Link +AR=LibFile -c -o + +Also add a new line '.c.o:; $(cc) $< $(cflags) -c -o $@'. Remove the +lines '$(RM) libjpeg.o' and '$(AR2) libjpeg.o' and the 'jconfig.h' +dependency section. + +Copy jconfig.txt to jconfig.h. Edit jconfig.h to define TWO_FILE_COMMANDLINE +and CHAR_IS_UNSIGNED. + +Run the makefile using !AMU not !Make. If you want to use the 'clean' and +'test' makefile entries then you will have to fiddle with the syntax a bit +and rename the test files. + + +Amiga: + +SAS C 6.50 reportedly is too buggy to compile the IJG code properly. +A patch to update to 6.51 is available from SAS or AmiNet FTP sites. + +The supplied config files are set up to use jmemname.c as the memory +manager, with temporary files being created on the device named by +"JPEGTMP:". + + +Atari ST/STE/TT: + +Copy the project files makcjpeg.st, makdjpeg.st, maktjpeg.st, and makljpeg.st +to cjpeg.prj, djpeg.prj, jpegtran.prj, and libjpeg.prj respectively. The +project files should work as-is with Pure C. For Turbo C, change library +filenames "pc..." to "tc..." in each project file. Note that libjpeg.prj +selects jmemansi.c as the recommended memory manager. You'll probably want to +adjust the DEFAULT_MAX_MEM setting --- you want it to be a couple hundred K +less than your normal free memory. Put "#define DEFAULT_MAX_MEM nnnn" into +jconfig.h to do this. + +To use the 68881/68882 coprocessor for the floating point DCT, add the +compiler option "-8" to the project files and replace pcfltlib.lib with +pc881lib.lib in cjpeg.prj and djpeg.prj. Or if you don't have a +coprocessor, you may prefer to remove the float DCT code by undefining +DCT_FLOAT_SUPPORTED in jmorecfg.h (since without a coprocessor, the float +code will be too slow to be useful). In that case, you can delete +pcfltlib.lib from the project files. + +Note that you must make libjpeg.lib before making cjpeg.ttp, djpeg.ttp, +or jpegtran.ttp. You'll have to perform the self-test by hand. + +We haven't bothered to include project files for rdjpgcom and wrjpgcom. +Those source files should just be compiled by themselves; they don't +depend on the JPEG library. You can use the default.prj project file +of the Pure C distribution to make the programs. + +There is a bug in some older versions of the Turbo C library which causes the +space used by temporary files created with "tmpfile()" not to be freed after +an abnormal program exit. If you check your disk afterwards, you will find +cluster chains that are allocated but not used by a file. This should not +happen in cjpeg/djpeg/jpegtran, since we enable a signal catcher to explicitly +close temp files before exiting. But if you use the JPEG library with your +own code, be sure to supply a signal catcher, or else use a different +system-dependent memory manager. + + +Cray: + +Should you be so fortunate as to be running JPEG on a Cray YMP, there is a +compiler bug in old versions of Cray's Standard C (prior to 3.1). If you +still have an old compiler, you'll need to insert a line reading +"#pragma novector" just before the loop + for (i = 1; i <= (int) htbl->bits[l]; i++) + huffsize[p++] = (char) l; +in fix_huff_tbl (in V5beta1, line 204 of jchuff.c and line 176 of jdhuff.c). +[This bug may or may not still occur with the current IJG code, but it's +probably a dead issue anyway...] + + +HP-UX: + +If you have HP-UX 7.05 or later with the "software development" C compiler, +you should run the compiler in ANSI mode. If using the configure script, +say + ./configure CC='cc -Aa' +(or -Ae if you prefer). If configuring by hand, use makefile.ansi and add +"-Aa" to the CFLAGS line in the makefile. + +If you have a pre-7.05 system, or if you are using the non-ANSI C compiler +delivered with a minimum HP-UX system, then you must use makefile.unix +(and do NOT add -Aa); or just run configure without the CC option. + +On HP 9000 series 800 machines, the HP C compiler is buggy in revisions prior +to A.08.07. If you get complaints about "not a typedef name", you'll have to +use makefile.unix, or run configure without the CC option. + + +Macintosh, generic comments: + +The supplied user-interface files (cjpeg.c, djpeg.c, etc) are set up to +provide a Unix-style command line interface. You can use this interface on +the Mac by means of the ccommand() library routine provided by Metrowerks +CodeWarrior or Think C. This is only appropriate for testing the library, +however; to make a user-friendly equivalent of cjpeg/djpeg you'd really want +to develop a Mac-style user interface. There isn't a complete example +available at the moment, but there are some helpful starting points: +1. Sam Bushell's free "To JPEG" applet provides drag-and-drop conversion to +JPEG under System 7 and later. This only illustrates how to use the +compression half of the library, but it does a very nice job of that part. +The CodeWarrior source code is available from http://www.pobox.com/~jsam. +2. Jim Brunner prepared a Mac-style user interface for both compression and +decompression. Unfortunately, it hasn't been updated since IJG v4, and +the library's API has changed considerably since then. Still it may be of +some help, particularly as a guide to compiling the IJG code under Think C. +Jim's code is available from the Info-Mac archives, at sumex-aim.stanford.edu +or mirrors thereof; see file /info-mac/dev/src/jpeg-convert-c.hqx. + +jmemmac.c is the recommended memory manager back end for Macintosh. It uses +NewPtr/DisposePtr instead of malloc/free, and has a Mac-specific +implementation of jpeg_mem_available(). It also creates temporary files that +follow Mac conventions. (That part of the code relies on System-7-or-later OS +functions. See the comments in jmemmac.c if you need to run it on System 6.) +NOTE that USE_MAC_MEMMGR must be defined in jconfig.h to use jmemmac.c. + +You can also use jmemnobs.c, if you don't care about handling images larger +than available memory. If you use any memory manager back end other than +jmemmac.c, we recommend replacing "malloc" and "free" by "NewPtr" and +"DisposePtr", because Mac C libraries often have peculiar implementations of +malloc/free. (For instance, free() may not return the freed space to the +Mac Memory Manager. This is undesirable for the IJG code because jmemmgr.c +already clumps space requests.) + + +Macintosh, Metrowerks CodeWarrior: + +The Unix-command-line-style interface can be used by defining USE_CCOMMAND. +You'll also need to define TWO_FILE_COMMANDLINE to avoid stdin/stdout. +This means that when using the cjpeg/djpeg programs, you'll have to type the +input and output file names in the "Arguments" text-edit box, rather than +using the file radio buttons. (Perhaps USE_FDOPEN or USE_SETMODE would +eliminate the problem, but I haven't heard from anyone who's tried it.) + +On 680x0 Macs, Metrowerks defines type "double" as a 10-byte IEEE extended +float. jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power +of 2. Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint. + +The supplied configuration file jconfig.mac can be used for your jconfig.h; +it includes all the recommended symbol definitions. If you have AppleScript +installed, you can run the supplied script makeproj.mac to create CodeWarrior +project files for the library and the testbed applications, then build the +library and applications. (Thanks to Dan Sears and Don Agro for this nifty +hack, which saves us from trying to maintain CodeWarrior project files as part +of the IJG distribution...) + + +Macintosh, Think C: + +The documentation in Jim Brunner's "JPEG Convert" source code (see above) +includes detailed build instructions for Think C; it's probably somewhat +out of date for the current release, but may be helpful. + +If you want to build the minimal command line version, proceed as follows. +You'll have to prepare project files for the programs; we don't include any +in the distribution since they are not text files. Use the file lists in +any of the supplied makefiles as a guide. Also add the ANSI and Unix C +libraries in a separate segment. You may need to divide the JPEG files into +more than one segment; we recommend dividing compression and decompression +modules. Define USE_CCOMMAND in jconfig.h so that the ccommand() routine is +called. You must also define TWO_FILE_COMMANDLINE because stdin/stdout +don't handle binary data correctly. + +On 680x0 Macs, Think C defines type "double" as a 12-byte IEEE extended float. +jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power of 2. +Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint. + +jconfig.mac should work as a jconfig.h configuration file for Think C, +but the makeproj.mac AppleScript script is specific to CodeWarrior. Sorry. + + +MIPS R3000: + +MIPS's cc version 1.31 has a rather nasty optimization bug. Don't use -O +if you have that compiler version. (Use "cc -V" to check the version.) +Note that the R3000 chip is found in workstations from DEC and others. + + +MS-DOS, generic comments for 16-bit compilers: + +The IJG code is designed to work well in 80x86 "small" or "medium" memory +models (i.e., data pointers are 16 bits unless explicitly declared "far"; +code pointers can be either size). You may be able to use small model to +compile cjpeg or djpeg by itself, but you will probably have to use medium +model for any larger application. This won't make much difference in +performance. You *will* take a noticeable performance hit if you use a +large-data memory model, and you should avoid "huge" model if at all +possible. Be sure that NEED_FAR_POINTERS is defined in jconfig.h if you use +a small-data memory model; be sure it is NOT defined if you use a large-data +model. (The supplied makefiles and jconfig files for Borland and Microsoft C +compile in medium model and define NEED_FAR_POINTERS.) + +The DOS-specific memory manager, jmemdos.c, should be used if possible. +It needs some assembly-code routines which are in jmemdosa.asm; make sure +your makefile assembles that file and includes it in the library. If you +don't have a suitable assembler, you can get pre-assembled object files for +jmemdosa by FTP from ftp.uu.net:/graphics/jpeg/jdosaobj.zip. (DOS-oriented +distributions of the IJG source code often include these object files.) + +When using jmemdos.c, jconfig.h must define USE_MSDOS_MEMMGR and must set +MAX_ALLOC_CHUNK to less than 64K (65520L is a typical value). If your +C library's far-heap malloc() can't allocate blocks that large, reduce +MAX_ALLOC_CHUNK to whatever it can handle. + +If you can't use jmemdos.c for some reason --- for example, because you +don't have an assembler to assemble jmemdosa.asm --- you'll have to fall +back to jmemansi.c or jmemname.c. You'll probably still need to set +MAX_ALLOC_CHUNK in jconfig.h, because most DOS C libraries won't malloc() +more than 64K at a time. IMPORTANT: if you use jmemansi.c or jmemname.c, +you will have to compile in a large-data memory model in order to get the +right stdio library. Too bad. + +wrjpgcom needs to be compiled in large model, because it malloc()s a 64KB +work area to hold the comment text. If your C library's malloc can't +handle that, reduce MAX_COM_LENGTH as necessary in wrjpgcom.c. + +Most MS-DOS compilers treat stdin/stdout as text files, so you must use +two-file command line style. But if your compiler has either fdopen() or +setmode(), you can use one-file style if you like. To do this, define +USE_SETMODE or USE_FDOPEN so that stdin/stdout will be set to binary mode. +(USE_SETMODE seems to work with more DOS compilers than USE_FDOPEN.) You +should test that I/O through stdin/stdout produces the same results as I/O +to explicitly named files... the "make test" procedures in the supplied +makefiles do NOT use stdin/stdout. + + +MS-DOS, generic comments for 32-bit compilers: + +None of the above comments about memory models apply if you are using a +32-bit flat-memory-space environment, such as DJGPP or Watcom C. (And you +should use one if you have it, as performance will be much better than +8086-compatible code!) For flat-memory-space compilers, do NOT define +NEED_FAR_POINTERS, and do NOT use jmemdos.c. Use jmemnobs.c if the +environment supplies adequate virtual memory, otherwise use jmemansi.c or +jmemname.c. + +You'll still need to be careful about binary I/O through stdin/stdout. +See the last paragraph of the previous section. + + +MS-DOS, Borland C: + +Be sure to convert all the source files to DOS text format (CR/LF newlines). +Although Borland C will often work OK with unmodified Unix (LF newlines) +source files, sometimes it will give bogus compile errors. +"Illegal character '#'" is the most common such error. (This is true with +Borland C 3.1, but perhaps is fixed in newer releases.) + +If you want one-file command line style, just undefine TWO_FILE_COMMANDLINE. +jconfig.bcc already includes #define USE_SETMODE to make this work. +(fdopen does not work correctly.) + + +MS-DOS, Microsoft C: + +makefile.mc6 works with Microsoft C, DOS Visual C++, etc. It should only +be used if you want to build a 16-bit (small or medium memory model) program. + +If you want one-file command line style, just undefine TWO_FILE_COMMANDLINE. +jconfig.mc6 already includes #define USE_SETMODE to make this work. +(fdopen does not work correctly.) + +Note that this makefile assumes that the working copy of itself is called +"makefile". If you want to call it something else, say "makefile.mak", +be sure to adjust the dependency line that reads "$(RFILE) : makefile". +Otherwise the make will fail because it doesn't know how to create "makefile". +Worse, some releases of Microsoft's make utilities give an incorrect error +message in this situation. + +Old versions of MS C fail with an "out of macro expansion space" error +because they can't cope with the macro TRACEMS8 (defined in jerror.h). +If this happens to you, the easiest solution is to change TRACEMS8 to +expand to nothing. You'll lose the ability to dump out JPEG coefficient +tables with djpeg -debug -debug, but at least you can compile. + +Original MS C 6.0 is very buggy; it compiles incorrect code unless you turn +off optimization entirely (remove -O from CFLAGS). 6.00A is better, but it +still generates bad code if you enable loop optimizations (-Ol or -Ox). + +MS C 8.0 crashes when compiling jquant1.c with optimization switch /Oo ... +which is on by default. To work around this bug, compile that one file +with /Oo-. + + +Microsoft Windows (all versions), generic comments: + +Some Windows system include files define typedef boolean as "unsigned char". +The IJG code also defines typedef boolean, but we make it "int" by default. +This doesn't affect the IJG programs because we don't import those Windows +include files. But if you use the JPEG library in your own program, and some +of your program's files import one definition of boolean while some import the +other, you can get all sorts of mysterious problems. A good preventive step +is to make the IJG library use "unsigned char" for boolean. To do that, +add something like this to your jconfig.h file: + /* Define "boolean" as unsigned char, not int, per Windows custom */ + #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ + typedef unsigned char boolean; + #endif + #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ +(This is already in jconfig.vc, by the way.) + +windef.h contains the declarations + #define far + #define FAR far +Since jmorecfg.h tries to define FAR as empty, you may get a compiler +warning if you include both jpeglib.h and windef.h (which windows.h +includes). To suppress the warning, you can put "#ifndef FAR"/"#endif" +around the line "#define FAR" in jmorecfg.h. +(Something like this is already in jmorecfg.h, by the way.) + +When using the library in a Windows application, you will almost certainly +want to modify or replace the error handler module jerror.c, since our +default error handler does a couple of inappropriate things: + 1. it tries to write error and warning messages on stderr; + 2. in event of a fatal error, it exits by calling exit(). + +A simple stopgap solution for problem 1 is to replace the line + fprintf(stderr, "%s\n", buffer); +(in output_message in jerror.c) with + MessageBox(GetActiveWindow(),buffer,"JPEG Error",MB_OK|MB_ICONERROR); +It's highly recommended that you at least do that much, since otherwise +error messages will disappear into nowhere. (Beginning with IJG v6b, this +code is already present in jerror.c; just define USE_WINDOWS_MESSAGEBOX in +jconfig.h to enable it.) + +The proper solution for problem 2 is to return control to your calling +application after a library error. This can be done with the setjmp/longjmp +technique discussed in libjpeg.txt and illustrated in example.c. (NOTE: +some older Windows C compilers provide versions of setjmp/longjmp that +don't actually work under Windows. You may need to use the Windows system +functions Catch and Throw instead.) + +The recommended memory manager under Windows is jmemnobs.c; in other words, +let Windows do any virtual memory management needed. You should NOT use +jmemdos.c nor jmemdosa.asm under Windows. + +For Windows 3.1, we recommend compiling in medium or large memory model; +for newer Windows versions, use a 32-bit flat memory model. (See the MS-DOS +sections above for more info about memory models.) In the 16-bit memory +models only, you'll need to put + #define MAX_ALLOC_CHUNK 65520L /* Maximum request to malloc() */ +into jconfig.h to limit allocation chunks to 64Kb. (Without that, you'd +have to use huge memory model, which slows things down unnecessarily.) +jmemnobs.c works without modification in large or flat memory models, but to +use medium model, you need to modify its jpeg_get_large and jpeg_free_large +routines to allocate far memory. In any case, you might like to replace +its calls to malloc and free with direct calls on Windows memory allocation +functions. + +You may also want to modify jdatasrc.c and jdatadst.c to use Windows file +operations rather than fread/fwrite. This is only necessary if your C +compiler doesn't provide a competent implementation of C stdio functions. + +You might want to tweak the RGB_xxx macros in jmorecfg.h so that the library +will accept or deliver color pixels in BGR sample order, not RGB; BGR order +is usually more convenient under Windows. Note that this change will break +the sample applications cjpeg/djpeg, but the library itself works fine. + + +Many people want to convert the IJG library into a DLL. This is reasonably +straightforward, but watch out for the following: + + 1. Don't try to compile as a DLL in small or medium memory model; use +large model, or even better, 32-bit flat model. Many places in the IJG code +assume the address of a local variable is an ordinary (not FAR) pointer; +that isn't true in a medium-model DLL. + + 2. Microsoft C cannot pass file pointers between applications and DLLs. +(See Microsoft Knowledge Base, PSS ID Number Q50336.) So jdatasrc.c and +jdatadst.c don't work if you open a file in your application and then pass +the pointer to the DLL. One workaround is to make jdatasrc.c/jdatadst.c +part of your main application rather than part of the DLL. + + 3. You'll probably need to modify the macros GLOBAL() and EXTERN() to +attach suitable linkage keywords to the exported routine names. Similarly, +you'll want to modify METHODDEF() and JMETHOD() to ensure function pointers +are declared in a way that lets application routines be called back through +the function pointers. These macros are in jmorecfg.h. Typical definitions +for a 16-bit DLL are: + #define GLOBAL(type) type _far _pascal _loadds _export + #define EXTERN(type) extern type _far _pascal _loadds + #define METHODDEF(type) static type _far _pascal + #define JMETHOD(type,methodname,arglist) \ + type (_far _pascal *methodname) arglist +For a 32-bit DLL you may want something like + #define GLOBAL(type) __declspec(dllexport) type + #define EXTERN(type) extern __declspec(dllexport) type +Although not all the GLOBAL routines are actually intended to be called by +the application, the performance cost of making them all DLL entry points is +negligible. + +The unmodified IJG library presents a very C-specific application interface, +so the resulting DLL is only usable from C or C++ applications. There has +been some talk of writing wrapper code that would present a simpler interface +usable from other languages, such as Visual Basic. This is on our to-do list +but hasn't been very high priority --- any volunteers out there? + + +Microsoft Windows, Borland C: + +The provided jconfig.bcc should work OK in a 32-bit Windows environment, +but you'll need to tweak it in a 16-bit environment (you'd need to define +NEED_FAR_POINTERS and MAX_ALLOC_CHUNK). Beware that makefile.bcc will need +alteration if you want to use it for Windows --- in particular, you should +use jmemnobs.c not jmemdos.c under Windows. + +Borland C++ 4.5 fails with an internal compiler error when trying to compile +jdmerge.c in 32-bit mode. If enough people complain, perhaps Borland will fix +it. In the meantime, the simplest known workaround is to add a redundant +definition of the variable range_limit in h2v1_merged_upsample(), at the head +of the block that handles odd image width (about line 268 in v6 jdmerge.c): + /* If image width is odd, do the last output column separately */ + if (cinfo->output_width & 1) { + register JSAMPLE * range_limit = cinfo->sample_range_limit; /* ADD THIS */ + cb = GETJSAMPLE(*inptr1); +Pretty bizarre, especially since the very similar routine h2v2_merged_upsample +doesn't trigger the bug. +Recent reports suggest that this bug does not occur with "bcc32a" (the +Pentium-optimized version of the compiler). + +Another report from a user of Borland C 4.5 was that incorrect code (leading +to a color shift in processed images) was produced if any of the following +optimization switch combinations were used: + -Ot -Og + -Ot -Op + -Ot -Om +So try backing off on optimization if you see such a problem. (Are there +several different releases all numbered "4.5"??) + + +Microsoft Windows, Microsoft Visual C++: + +jconfig.vc should work OK with any Microsoft compiler for a 32-bit memory +model. makefile.vc is intended for command-line use. (If you are using +the Developer Studio environment, you may prefer the DevStudio project +files; see below.) + +IJG JPEG 7 adds extern "C" to jpeglib.h. This avoids the need to put +extern "C" { ... } around #include "jpeglib.h" in your C++ application. +You can also force VC++ to treat the library as C++ code by renaming +all the *.c files to *.cpp (and adjusting the makefile to match). +In this case you also need to define the symbol DONT_USE_EXTERN_C in +the configuration to prevent jpeglib.h from using extern "C". + + +Microsoft Windows, Microsoft Visual C++ 6 Developer Studio: + +We include makefiles that should work as project files in DevStudio 6.0 or +later. There is a library makefile that builds the IJG library as a static +Win32 library, and application makefiles that build the sample applications +as Win32 console applications. (Even if you only want the library, we +recommend building the applications so that you can run the self-test.) + +To use: +1. Open the command prompt, change to the main directory and execute the + command line + NMAKE /f makefile.vc setup-vc6 + This will move jconfig.vc to jconfig.h and makefiles to project files. + (Note that the renaming is critical!) +2. Open the workspace file jpeg.dsw, build the library project. + (If you are using DevStudio more recent than 6.0, you'll probably + get a message saying that the project files are being updated.) +3. Open the workspace file apps.dsw, build the application projects. +4. To perform the self-test, execute the command line + NMAKE /f makefile.vc test-build +5. Move the application .exe files from `app`\Release to an + appropriate location on your path. + + +Microsoft Windows, Microsoft Visual C++ 2010 Developer Studio (v10): + +We include makefiles that should work as project files in Visual Studio +2010 or later. There is a library makefile that builds the IJG library +as a static Win32 library, and application makefiles that build the sample +applications as Win32 console applications. (Even if you only want the +library, we recommend building the applications so that you can run the +self-test.) + +To use: +1. Open the command prompt, change to the main directory and execute the + command line + NMAKE /f makefile.vc setup-v10 + This will move jconfig.vc to jconfig.h and makefiles to project files. + (Note that the renaming is critical!) +2. Open the solution file jpeg.sln, build the library project. + (If you are using Visual Studio more recent than 2010 (v10), you'll + probably get a message saying that the project files are being updated.) +3. Open the solution file apps.sln, build the application projects. +4. To perform the self-test, execute the command line + NMAKE /f makefile.vc test-build +5. Move the application .exe files from `app`\Release to an + appropriate location on your path. + +Note: +There seems to be an optimization bug in the compiler which causes the +self-test to fail with the color quantization option. +We have disabled optimization for the file jquant2.c in the library +project file which causes the self-test to pass properly. + + +OS/2, Borland C++: + +Watch out for optimization bugs in older Borland compilers; you may need +to back off the optimization switch settings. See the comments in +makefile.bcc. + + +SGI: + +On some SGI systems, you may need to set "AR2= ar -ts" in the Makefile. +If you are using configure, you can do this by saying + ./configure RANLIB='ar -ts' +This change is not needed on all SGIs. Use it only if the make fails at the +stage of linking the completed programs. + +On the MIPS R4000 architecture (Indy, etc.), the compiler option "-mips2" +reportedly speeds up the float DCT method substantially, enough to make it +faster than the default int method (but still slower than the fast int +method). If you use -mips2, you may want to alter the default DCT method to +be float. To do this, put "#define JDCT_DEFAULT JDCT_FLOAT" in jconfig.h. + + +VMS: + +On an Alpha/VMS system with MMS, be sure to use the "/Marco=Alpha=1" +qualifier with MMS when building the JPEG package. + +VAX/VMS v5.5-1 may have problems with the test step of the build procedure +reporting differences when it compares the original and test images. If the +error points to the last block of the files, it is most likely bogus and may +be safely ignored. It seems to be because the files are Stream_LF and +Backup/Compare has difficulty with the (presumably) null padded files. +This problem was not observed on VAX/VMS v6.1 or AXP/VMS v6.1. diff --git a/Source/LibJPEG/jconfig.txt b/Source/LibJPEG/jconfig.txt index 27086a3..b96d312 100644 --- a/Source/LibJPEG/jconfig.txt +++ b/Source/LibJPEG/jconfig.txt @@ -1,164 +1,164 @@ -/* - * jconfig.txt - * - * Copyright (C) 1991-1994, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file documents the configuration options that are required to - * customize the JPEG software for a particular system. - * - * The actual configuration options for a particular installation are stored - * in jconfig.h. On many machines, jconfig.h can be generated automatically - * or copied from one of the "canned" jconfig files that we supply. But if - * you need to generate a jconfig.h file by hand, this file tells you how. - * - * DO NOT EDIT THIS FILE --- IT WON'T ACCOMPLISH ANYTHING. - * EDIT A COPY NAMED JCONFIG.H. - */ - - -/* - * These symbols indicate the properties of your machine or compiler. - * #define the symbol if yes, #undef it if no. - */ - -/* Does your compiler support function prototypes? - * (If not, you also need to use ansi2knr, see install.txt) - */ -#define HAVE_PROTOTYPES - -/* Does your compiler support the declaration "unsigned char" ? - * How about "unsigned short" ? - */ -#define HAVE_UNSIGNED_CHAR -#define HAVE_UNSIGNED_SHORT - -/* Define "void" as "char" if your compiler doesn't know about type void. - * NOTE: be sure to define void such that "void *" represents the most general - * pointer type, e.g., that returned by malloc(). - */ -/* #define void char */ - -/* Define "const" as empty if your compiler doesn't know the "const" keyword. - */ -/* #define const */ - -/* Define this if an ordinary "char" type is unsigned. - * If you're not sure, leaving it undefined will work at some cost in speed. - * If you defined HAVE_UNSIGNED_CHAR then the speed difference is minimal. - */ -#undef CHAR_IS_UNSIGNED - -/* Define this if your system has an ANSI-conforming file. - */ -#define HAVE_STDDEF_H - -/* Define this if your system has an ANSI-conforming file. - */ -#define HAVE_STDLIB_H - -/* Define this if your system does not have an ANSI/SysV , - * but does have a BSD-style . - */ -#undef NEED_BSD_STRINGS - -/* Define this if your system does not provide typedef size_t in any of the - * ANSI-standard places (stddef.h, stdlib.h, or stdio.h), but places it in - * instead. - */ -#undef NEED_SYS_TYPES_H - -/* For 80x86 machines, you need to define NEED_FAR_POINTERS, - * unless you are using a large-data memory model or 80386 flat-memory mode. - * On less brain-damaged CPUs this symbol must not be defined. - * (Defining this symbol causes large data structures to be referenced through - * "far" pointers and to be allocated with a special version of malloc.) - */ -#undef NEED_FAR_POINTERS - -/* Define this if your linker needs global names to be unique in less - * than the first 15 characters. - */ -#undef NEED_SHORT_EXTERNAL_NAMES - -/* Although a real ANSI C compiler can deal perfectly well with pointers to - * unspecified structures (see "incomplete types" in the spec), a few pre-ANSI - * and pseudo-ANSI compilers get confused. To keep one of these bozos happy, - * define INCOMPLETE_TYPES_BROKEN. This is not recommended unless you - * actually get "missing structure definition" warnings or errors while - * compiling the JPEG code. - */ -#undef INCOMPLETE_TYPES_BROKEN - -/* Define "boolean" as unsigned char, not int, on Windows systems. - */ -#ifdef _WIN32 -#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ -typedef unsigned char boolean; -#endif -#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ -#endif - - -/* - * The following options affect code selection within the JPEG library, - * but they don't need to be visible to applications using the library. - * To minimize application namespace pollution, the symbols won't be - * defined unless JPEG_INTERNALS has been defined. - */ - -#ifdef JPEG_INTERNALS - -/* Define this if your compiler implements ">>" on signed values as a logical - * (unsigned) shift; leave it undefined if ">>" is a signed (arithmetic) shift, - * which is the normal and rational definition. - */ -#undef RIGHT_SHIFT_IS_UNSIGNED - - -#endif /* JPEG_INTERNALS */ - - -/* - * The remaining options do not affect the JPEG library proper, - * but only the sample applications cjpeg/djpeg (see cjpeg.c, djpeg.c). - * Other applications can ignore these. - */ - -#ifdef JPEG_CJPEG_DJPEG - -/* These defines indicate which image (non-JPEG) file formats are allowed. */ - -#define BMP_SUPPORTED /* BMP image file format */ -#define GIF_SUPPORTED /* GIF image file format */ -#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ -#undef RLE_SUPPORTED /* Utah RLE image file format */ -#define TARGA_SUPPORTED /* Targa image file format */ - -/* Define this if you want to name both input and output files on the command - * line, rather than using stdout and optionally stdin. You MUST do this if - * your system can't cope with binary I/O to stdin/stdout. See comments at - * head of cjpeg.c or djpeg.c. - */ -#undef TWO_FILE_COMMANDLINE - -/* Define this if your system needs explicit cleanup of temporary files. - * This is crucial under MS-DOS, where the temporary "files" may be areas - * of extended memory; on most other systems it's not as important. - */ -#undef NEED_SIGNAL_CATCHER - -/* By default, we open image files with fopen(...,"rb") or fopen(...,"wb"). - * This is necessary on systems that distinguish text files from binary files, - * and is harmless on most systems that don't. If you have one of the rare - * systems that complains about the "b" spec, define this symbol. - */ -#undef DONT_USE_B_MODE - -/* Define this if you want percent-done progress reports from cjpeg/djpeg. - */ -#undef PROGRESS_REPORT - - -#endif /* JPEG_CJPEG_DJPEG */ +/* + * jconfig.txt + * + * Copyright (C) 1991-1994, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file documents the configuration options that are required to + * customize the JPEG software for a particular system. + * + * The actual configuration options for a particular installation are stored + * in jconfig.h. On many machines, jconfig.h can be generated automatically + * or copied from one of the "canned" jconfig files that we supply. But if + * you need to generate a jconfig.h file by hand, this file tells you how. + * + * DO NOT EDIT THIS FILE --- IT WON'T ACCOMPLISH ANYTHING. + * EDIT A COPY NAMED JCONFIG.H. + */ + + +/* + * These symbols indicate the properties of your machine or compiler. + * #define the symbol if yes, #undef it if no. + */ + +/* Does your compiler support function prototypes? + * (If not, you also need to use ansi2knr, see install.txt) + */ +#define HAVE_PROTOTYPES + +/* Does your compiler support the declaration "unsigned char" ? + * How about "unsigned short" ? + */ +#define HAVE_UNSIGNED_CHAR +#define HAVE_UNSIGNED_SHORT + +/* Define "void" as "char" if your compiler doesn't know about type void. + * NOTE: be sure to define void such that "void *" represents the most general + * pointer type, e.g., that returned by malloc(). + */ +/* #define void char */ + +/* Define "const" as empty if your compiler doesn't know the "const" keyword. + */ +/* #define const */ + +/* Define this if an ordinary "char" type is unsigned. + * If you're not sure, leaving it undefined will work at some cost in speed. + * If you defined HAVE_UNSIGNED_CHAR then the speed difference is minimal. + */ +#undef CHAR_IS_UNSIGNED + +/* Define this if your system has an ANSI-conforming file. + */ +#define HAVE_STDDEF_H + +/* Define this if your system has an ANSI-conforming file. + */ +#define HAVE_STDLIB_H + +/* Define this if your system does not have an ANSI/SysV , + * but does have a BSD-style . + */ +#undef NEED_BSD_STRINGS + +/* Define this if your system does not provide typedef size_t in any of the + * ANSI-standard places (stddef.h, stdlib.h, or stdio.h), but places it in + * instead. + */ +#undef NEED_SYS_TYPES_H + +/* For 80x86 machines, you need to define NEED_FAR_POINTERS, + * unless you are using a large-data memory model or 80386 flat-memory mode. + * On less brain-damaged CPUs this symbol must not be defined. + * (Defining this symbol causes large data structures to be referenced through + * "far" pointers and to be allocated with a special version of malloc.) + */ +#undef NEED_FAR_POINTERS + +/* Define this if your linker needs global names to be unique in less + * than the first 15 characters. + */ +#undef NEED_SHORT_EXTERNAL_NAMES + +/* Although a real ANSI C compiler can deal perfectly well with pointers to + * unspecified structures (see "incomplete types" in the spec), a few pre-ANSI + * and pseudo-ANSI compilers get confused. To keep one of these bozos happy, + * define INCOMPLETE_TYPES_BROKEN. This is not recommended unless you + * actually get "missing structure definition" warnings or errors while + * compiling the JPEG code. + */ +#undef INCOMPLETE_TYPES_BROKEN + +/* Define "boolean" as unsigned char, not int, on Windows systems. + */ +#ifdef _WIN32 +#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ +typedef unsigned char boolean; +#endif +#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ +#endif + + +/* + * The following options affect code selection within the JPEG library, + * but they don't need to be visible to applications using the library. + * To minimize application namespace pollution, the symbols won't be + * defined unless JPEG_INTERNALS has been defined. + */ + +#ifdef JPEG_INTERNALS + +/* Define this if your compiler implements ">>" on signed values as a logical + * (unsigned) shift; leave it undefined if ">>" is a signed (arithmetic) shift, + * which is the normal and rational definition. + */ +#undef RIGHT_SHIFT_IS_UNSIGNED + + +#endif /* JPEG_INTERNALS */ + + +/* + * The remaining options do not affect the JPEG library proper, + * but only the sample applications cjpeg/djpeg (see cjpeg.c, djpeg.c). + * Other applications can ignore these. + */ + +#ifdef JPEG_CJPEG_DJPEG + +/* These defines indicate which image (non-JPEG) file formats are allowed. */ + +#define BMP_SUPPORTED /* BMP image file format */ +#define GIF_SUPPORTED /* GIF image file format */ +#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ +#undef RLE_SUPPORTED /* Utah RLE image file format */ +#define TARGA_SUPPORTED /* Targa image file format */ + +/* Define this if you want to name both input and output files on the command + * line, rather than using stdout and optionally stdin. You MUST do this if + * your system can't cope with binary I/O to stdin/stdout. See comments at + * head of cjpeg.c or djpeg.c. + */ +#undef TWO_FILE_COMMANDLINE + +/* Define this if your system needs explicit cleanup of temporary files. + * This is crucial under MS-DOS, where the temporary "files" may be areas + * of extended memory; on most other systems it's not as important. + */ +#undef NEED_SIGNAL_CATCHER + +/* By default, we open image files with fopen(...,"rb") or fopen(...,"wb"). + * This is necessary on systems that distinguish text files from binary files, + * and is harmless on most systems that don't. If you have one of the rare + * systems that complains about the "b" spec, define this symbol. + */ +#undef DONT_USE_B_MODE + +/* Define this if you want percent-done progress reports from cjpeg/djpeg. + */ +#undef PROGRESS_REPORT + + +#endif /* JPEG_CJPEG_DJPEG */ diff --git a/Source/LibJPEG/jmemansi.c b/Source/LibJPEG/jmemansi.c index b5da474..2d93e49 100644 --- a/Source/LibJPEG/jmemansi.c +++ b/Source/LibJPEG/jmemansi.c @@ -1,167 +1,167 @@ -/* - * jmemansi.c - * - * Copyright (C) 1992-1996, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file provides a simple generic implementation of the system- - * dependent portion of the JPEG memory manager. This implementation - * assumes that you have the ANSI-standard library routine tmpfile(). - * Also, the problem of determining the amount of memory available - * is shoved onto the user. - */ - -#define JPEG_INTERNALS -#include "jinclude.h" -#include "jpeglib.h" -#include "jmemsys.h" /* import the system-dependent declarations */ - -#ifndef HAVE_STDLIB_H /* should declare malloc(),free() */ -extern void * malloc JPP((size_t size)); -extern void free JPP((void *ptr)); -#endif - -#ifndef SEEK_SET /* pre-ANSI systems may not define this; */ -#define SEEK_SET 0 /* if not, assume 0 is correct */ -#endif - - -/* - * Memory allocation and freeing are controlled by the regular library - * routines malloc() and free(). - */ - -GLOBAL(void *) -jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) -{ - return (void *) malloc(sizeofobject); -} - -GLOBAL(void) -jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) -{ - free(object); -} - - -/* - * "Large" objects are treated the same as "small" ones. - * NB: although we include FAR keywords in the routine declarations, - * this file won't actually work in 80x86 small/medium model; at least, - * you probably won't be able to process useful-size images in only 64KB. - */ - -GLOBAL(void FAR *) -jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) -{ - return (void FAR *) malloc(sizeofobject); -} - -GLOBAL(void) -jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) -{ - free(object); -} - - -/* - * This routine computes the total memory space available for allocation. - * It's impossible to do this in a portable way; our current solution is - * to make the user tell us (with a default value set at compile time). - * If you can actually get the available space, it's a good idea to subtract - * a slop factor of 5% or so. - */ - -#ifndef DEFAULT_MAX_MEM /* so can override from makefile */ -#define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */ -#endif - -GLOBAL(long) -jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, - long max_bytes_needed, long already_allocated) -{ - return cinfo->mem->max_memory_to_use - already_allocated; -} - - -/* - * Backing store (temporary file) management. - * Backing store objects are only used when the value returned by - * jpeg_mem_available is less than the total space needed. You can dispense - * with these routines if you have plenty of virtual memory; see jmemnobs.c. - */ - - -METHODDEF(void) -read_backing_store (j_common_ptr cinfo, backing_store_ptr info, - void FAR * buffer_address, - long file_offset, long byte_count) -{ - if (fseek(info->temp_file, file_offset, SEEK_SET)) - ERREXIT(cinfo, JERR_TFILE_SEEK); - if (JFREAD(info->temp_file, buffer_address, byte_count) - != (size_t) byte_count) - ERREXIT(cinfo, JERR_TFILE_READ); -} - - -METHODDEF(void) -write_backing_store (j_common_ptr cinfo, backing_store_ptr info, - void FAR * buffer_address, - long file_offset, long byte_count) -{ - if (fseek(info->temp_file, file_offset, SEEK_SET)) - ERREXIT(cinfo, JERR_TFILE_SEEK); - if (JFWRITE(info->temp_file, buffer_address, byte_count) - != (size_t) byte_count) - ERREXIT(cinfo, JERR_TFILE_WRITE); -} - - -METHODDEF(void) -close_backing_store (j_common_ptr cinfo, backing_store_ptr info) -{ - fclose(info->temp_file); - /* Since this implementation uses tmpfile() to create the file, - * no explicit file deletion is needed. - */ -} - - -/* - * Initial opening of a backing-store object. - * - * This version uses tmpfile(), which constructs a suitable file name - * behind the scenes. We don't have to use info->temp_name[] at all; - * indeed, we can't even find out the actual name of the temp file. - */ - -GLOBAL(void) -jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, - long total_bytes_needed) -{ - if ((info->temp_file = tmpfile()) == NULL) - ERREXITS(cinfo, JERR_TFILE_CREATE, ""); - info->read_backing_store = read_backing_store; - info->write_backing_store = write_backing_store; - info->close_backing_store = close_backing_store; -} - - -/* - * These routines take care of any system-dependent initialization and - * cleanup required. - */ - -GLOBAL(long) -jpeg_mem_init (j_common_ptr cinfo) -{ - return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ -} - -GLOBAL(void) -jpeg_mem_term (j_common_ptr cinfo) -{ - /* no work */ -} +/* + * jmemansi.c + * + * Copyright (C) 1992-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file provides a simple generic implementation of the system- + * dependent portion of the JPEG memory manager. This implementation + * assumes that you have the ANSI-standard library routine tmpfile(). + * Also, the problem of determining the amount of memory available + * is shoved onto the user. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jmemsys.h" /* import the system-dependent declarations */ + +#ifndef HAVE_STDLIB_H /* should declare malloc(),free() */ +extern void * malloc JPP((size_t size)); +extern void free JPP((void *ptr)); +#endif + +#ifndef SEEK_SET /* pre-ANSI systems may not define this; */ +#define SEEK_SET 0 /* if not, assume 0 is correct */ +#endif + + +/* + * Memory allocation and freeing are controlled by the regular library + * routines malloc() and free(). + */ + +GLOBAL(void *) +jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) +{ + return (void *) malloc(sizeofobject); +} + +GLOBAL(void) +jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) +{ + free(object); +} + + +/* + * "Large" objects are treated the same as "small" ones. + * NB: although we include FAR keywords in the routine declarations, + * this file won't actually work in 80x86 small/medium model; at least, + * you probably won't be able to process useful-size images in only 64KB. + */ + +GLOBAL(void FAR *) +jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) +{ + return (void FAR *) malloc(sizeofobject); +} + +GLOBAL(void) +jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) +{ + free(object); +} + + +/* + * This routine computes the total memory space available for allocation. + * It's impossible to do this in a portable way; our current solution is + * to make the user tell us (with a default value set at compile time). + * If you can actually get the available space, it's a good idea to subtract + * a slop factor of 5% or so. + */ + +#ifndef DEFAULT_MAX_MEM /* so can override from makefile */ +#define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */ +#endif + +GLOBAL(long) +jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, + long max_bytes_needed, long already_allocated) +{ + return cinfo->mem->max_memory_to_use - already_allocated; +} + + +/* + * Backing store (temporary file) management. + * Backing store objects are only used when the value returned by + * jpeg_mem_available is less than the total space needed. You can dispense + * with these routines if you have plenty of virtual memory; see jmemnobs.c. + */ + + +METHODDEF(void) +read_backing_store (j_common_ptr cinfo, backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count) +{ + if (fseek(info->temp_file, file_offset, SEEK_SET)) + ERREXIT(cinfo, JERR_TFILE_SEEK); + if (JFREAD(info->temp_file, buffer_address, byte_count) + != (size_t) byte_count) + ERREXIT(cinfo, JERR_TFILE_READ); +} + + +METHODDEF(void) +write_backing_store (j_common_ptr cinfo, backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count) +{ + if (fseek(info->temp_file, file_offset, SEEK_SET)) + ERREXIT(cinfo, JERR_TFILE_SEEK); + if (JFWRITE(info->temp_file, buffer_address, byte_count) + != (size_t) byte_count) + ERREXIT(cinfo, JERR_TFILE_WRITE); +} + + +METHODDEF(void) +close_backing_store (j_common_ptr cinfo, backing_store_ptr info) +{ + fclose(info->temp_file); + /* Since this implementation uses tmpfile() to create the file, + * no explicit file deletion is needed. + */ +} + + +/* + * Initial opening of a backing-store object. + * + * This version uses tmpfile(), which constructs a suitable file name + * behind the scenes. We don't have to use info->temp_name[] at all; + * indeed, we can't even find out the actual name of the temp file. + */ + +GLOBAL(void) +jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, + long total_bytes_needed) +{ + if ((info->temp_file = tmpfile()) == NULL) + ERREXITS(cinfo, JERR_TFILE_CREATE, ""); + info->read_backing_store = read_backing_store; + info->write_backing_store = write_backing_store; + info->close_backing_store = close_backing_store; +} + + +/* + * These routines take care of any system-dependent initialization and + * cleanup required. + */ + +GLOBAL(long) +jpeg_mem_init (j_common_ptr cinfo) +{ + return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ +} + +GLOBAL(void) +jpeg_mem_term (j_common_ptr cinfo) +{ + /* no work */ +} diff --git a/Source/LibJPEG/jmemdos.c b/Source/LibJPEG/jmemdos.c index 0955047..60b45c6 100644 --- a/Source/LibJPEG/jmemdos.c +++ b/Source/LibJPEG/jmemdos.c @@ -1,638 +1,638 @@ -/* - * jmemdos.c - * - * Copyright (C) 1992-1997, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file provides an MS-DOS-compatible implementation of the system- - * dependent portion of the JPEG memory manager. Temporary data can be - * stored in extended or expanded memory as well as in regular DOS files. - * - * If you use this file, you must be sure that NEED_FAR_POINTERS is defined - * if you compile in a small-data memory model; it should NOT be defined if - * you use a large-data memory model. This file is not recommended if you - * are using a flat-memory-space 386 environment such as DJGCC or Watcom C. - * Also, this code will NOT work if struct fields are aligned on greater than - * 2-byte boundaries. - * - * Based on code contributed by Ge' Weijers. - */ - -/* - * If you have both extended and expanded memory, you may want to change the - * order in which they are tried in jopen_backing_store. On a 286 machine - * expanded memory is usually faster, since extended memory access involves - * an expensive protected-mode-and-back switch. On 386 and better, extended - * memory is usually faster. As distributed, the code tries extended memory - * first (what? not everyone has a 386? :-). - * - * You can disable use of extended/expanded memory entirely by altering these - * definitions or overriding them from the Makefile (eg, -DEMS_SUPPORTED=0). - */ - -#ifndef XMS_SUPPORTED -#define XMS_SUPPORTED 1 -#endif -#ifndef EMS_SUPPORTED -#define EMS_SUPPORTED 1 -#endif - - -#define JPEG_INTERNALS -#include "jinclude.h" -#include "jpeglib.h" -#include "jmemsys.h" /* import the system-dependent declarations */ - -#ifndef HAVE_STDLIB_H /* should declare these */ -extern void * malloc JPP((size_t size)); -extern void free JPP((void *ptr)); -extern char * getenv JPP((const char * name)); -#endif - -#ifdef NEED_FAR_POINTERS - -#ifdef __TURBOC__ -/* These definitions work for Borland C (Turbo C) */ -#include /* need farmalloc(), farfree() */ -#define far_malloc(x) farmalloc(x) -#define far_free(x) farfree(x) -#else -/* These definitions work for Microsoft C and compatible compilers */ -#include /* need _fmalloc(), _ffree() */ -#define far_malloc(x) _fmalloc(x) -#define far_free(x) _ffree(x) -#endif - -#else /* not NEED_FAR_POINTERS */ - -#define far_malloc(x) malloc(x) -#define far_free(x) free(x) - -#endif /* NEED_FAR_POINTERS */ - -#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ -#define READ_BINARY "r" -#else -#define READ_BINARY "rb" -#endif - -#ifndef USE_MSDOS_MEMMGR /* make sure user got configuration right */ - You forgot to define USE_MSDOS_MEMMGR in jconfig.h. /* deliberate syntax error */ -#endif - -#if MAX_ALLOC_CHUNK >= 65535L /* make sure jconfig.h got this right */ - MAX_ALLOC_CHUNK should be less than 64K. /* deliberate syntax error */ -#endif - - -/* - * Declarations for assembly-language support routines (see jmemdosa.asm). - * - * The functions are declared "far" as are all their pointer arguments; - * this ensures the assembly source code will work regardless of the - * compiler memory model. We assume "short" is 16 bits, "long" is 32. - */ - -typedef void far * XMSDRIVER; /* actually a pointer to code */ -typedef struct { /* registers for calling XMS driver */ - unsigned short ax, dx, bx; - void far * ds_si; - } XMScontext; -typedef struct { /* registers for calling EMS driver */ - unsigned short ax, dx, bx; - void far * ds_si; - } EMScontext; - -extern short far jdos_open JPP((short far * handle, char far * filename)); -extern short far jdos_close JPP((short handle)); -extern short far jdos_seek JPP((short handle, long offset)); -extern short far jdos_read JPP((short handle, void far * buffer, - unsigned short count)); -extern short far jdos_write JPP((short handle, void far * buffer, - unsigned short count)); -extern void far jxms_getdriver JPP((XMSDRIVER far *)); -extern void far jxms_calldriver JPP((XMSDRIVER, XMScontext far *)); -extern short far jems_available JPP((void)); -extern void far jems_calldriver JPP((EMScontext far *)); - - -/* - * Selection of a file name for a temporary file. - * This is highly system-dependent, and you may want to customize it. - */ - -static int next_file_num; /* to distinguish among several temp files */ - -LOCAL(void) -select_file_name (char * fname) -{ - const char * env; - char * ptr; - FILE * tfile; - - /* Keep generating file names till we find one that's not in use */ - for (;;) { - /* Get temp directory name from environment TMP or TEMP variable; - * if none, use "." - */ - if ((env = (const char *) getenv("TMP")) == NULL) - if ((env = (const char *) getenv("TEMP")) == NULL) - env = "."; - if (*env == '\0') /* null string means "." */ - env = "."; - ptr = fname; /* copy name to fname */ - while (*env != '\0') - *ptr++ = *env++; - if (ptr[-1] != '\\' && ptr[-1] != '/') - *ptr++ = '\\'; /* append backslash if not in env variable */ - /* Append a suitable file name */ - next_file_num++; /* advance counter */ - sprintf(ptr, "JPG%03d.TMP", next_file_num); - /* Probe to see if file name is already in use */ - if ((tfile = fopen(fname, READ_BINARY)) == NULL) - break; - fclose(tfile); /* oops, it's there; close tfile & try again */ - } -} - - -/* - * Near-memory allocation and freeing are controlled by the regular library - * routines malloc() and free(). - */ - -GLOBAL(void *) -jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) -{ - return (void *) malloc(sizeofobject); -} - -GLOBAL(void) -jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) -{ - free(object); -} - - -/* - * "Large" objects are allocated in far memory, if possible - */ - -GLOBAL(void FAR *) -jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) -{ - return (void FAR *) far_malloc(sizeofobject); -} - -GLOBAL(void) -jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) -{ - far_free(object); -} - - -/* - * This routine computes the total memory space available for allocation. - * It's impossible to do this in a portable way; our current solution is - * to make the user tell us (with a default value set at compile time). - * If you can actually get the available space, it's a good idea to subtract - * a slop factor of 5% or so. - */ - -#ifndef DEFAULT_MAX_MEM /* so can override from makefile */ -#define DEFAULT_MAX_MEM 300000L /* for total usage about 450K */ -#endif - -GLOBAL(long) -jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, - long max_bytes_needed, long already_allocated) -{ - return cinfo->mem->max_memory_to_use - already_allocated; -} - - -/* - * Backing store (temporary file) management. - * Backing store objects are only used when the value returned by - * jpeg_mem_available is less than the total space needed. You can dispense - * with these routines if you have plenty of virtual memory; see jmemnobs.c. - */ - -/* - * For MS-DOS we support three types of backing storage: - * 1. Conventional DOS files. We access these by direct DOS calls rather - * than via the stdio package. This provides a bit better performance, - * but the real reason is that the buffers to be read or written are FAR. - * The stdio library for small-data memory models can't cope with that. - * 2. Extended memory, accessed per the XMS V2.0 specification. - * 3. Expanded memory, accessed per the LIM/EMS 4.0 specification. - * You'll need copies of those specs to make sense of the related code. - * The specs are available by Internet FTP from the SIMTEL archives - * (oak.oakland.edu and its various mirror sites). See files - * pub/msdos/microsoft/xms20.arc and pub/msdos/info/limems41.zip. - */ - - -/* - * Access methods for a DOS file. - */ - - -METHODDEF(void) -read_file_store (j_common_ptr cinfo, backing_store_ptr info, - void FAR * buffer_address, - long file_offset, long byte_count) -{ - if (jdos_seek(info->handle.file_handle, file_offset)) - ERREXIT(cinfo, JERR_TFILE_SEEK); - /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */ - if (byte_count > 65535L) /* safety check */ - ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK); - if (jdos_read(info->handle.file_handle, buffer_address, - (unsigned short) byte_count)) - ERREXIT(cinfo, JERR_TFILE_READ); -} - - -METHODDEF(void) -write_file_store (j_common_ptr cinfo, backing_store_ptr info, - void FAR * buffer_address, - long file_offset, long byte_count) -{ - if (jdos_seek(info->handle.file_handle, file_offset)) - ERREXIT(cinfo, JERR_TFILE_SEEK); - /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */ - if (byte_count > 65535L) /* safety check */ - ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK); - if (jdos_write(info->handle.file_handle, buffer_address, - (unsigned short) byte_count)) - ERREXIT(cinfo, JERR_TFILE_WRITE); -} - - -METHODDEF(void) -close_file_store (j_common_ptr cinfo, backing_store_ptr info) -{ - jdos_close(info->handle.file_handle); /* close the file */ - remove(info->temp_name); /* delete the file */ -/* If your system doesn't have remove(), try unlink() instead. - * remove() is the ANSI-standard name for this function, but - * unlink() was more common in pre-ANSI systems. - */ - TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name); -} - - -LOCAL(boolean) -open_file_store (j_common_ptr cinfo, backing_store_ptr info, - long total_bytes_needed) -{ - short handle; - - select_file_name(info->temp_name); - if (jdos_open((short far *) & handle, (char far *) info->temp_name)) { - /* might as well exit since jpeg_open_backing_store will fail anyway */ - ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); - return FALSE; - } - info->handle.file_handle = handle; - info->read_backing_store = read_file_store; - info->write_backing_store = write_file_store; - info->close_backing_store = close_file_store; - TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); - return TRUE; /* succeeded */ -} - - -/* - * Access methods for extended memory. - */ - -#if XMS_SUPPORTED - -static XMSDRIVER xms_driver; /* saved address of XMS driver */ - -typedef union { /* either long offset or real-mode pointer */ - long offset; - void far * ptr; - } XMSPTR; - -typedef struct { /* XMS move specification structure */ - long length; - XMSH src_handle; - XMSPTR src; - XMSH dst_handle; - XMSPTR dst; - } XMSspec; - -#define ODD(X) (((X) & 1L) != 0) - - -METHODDEF(void) -read_xms_store (j_common_ptr cinfo, backing_store_ptr info, - void FAR * buffer_address, - long file_offset, long byte_count) -{ - XMScontext ctx; - XMSspec spec; - char endbuffer[2]; - - /* The XMS driver can't cope with an odd length, so handle the last byte - * specially if byte_count is odd. We don't expect this to be common. - */ - - spec.length = byte_count & (~ 1L); - spec.src_handle = info->handle.xms_handle; - spec.src.offset = file_offset; - spec.dst_handle = 0; - spec.dst.ptr = buffer_address; - - ctx.ds_si = (void far *) & spec; - ctx.ax = 0x0b00; /* EMB move */ - jxms_calldriver(xms_driver, (XMScontext far *) & ctx); - if (ctx.ax != 1) - ERREXIT(cinfo, JERR_XMS_READ); - - if (ODD(byte_count)) { - read_xms_store(cinfo, info, (void FAR *) endbuffer, - file_offset + byte_count - 1L, 2L); - ((char FAR *) buffer_address)[byte_count - 1L] = endbuffer[0]; - } -} - - -METHODDEF(void) -write_xms_store (j_common_ptr cinfo, backing_store_ptr info, - void FAR * buffer_address, - long file_offset, long byte_count) -{ - XMScontext ctx; - XMSspec spec; - char endbuffer[2]; - - /* The XMS driver can't cope with an odd length, so handle the last byte - * specially if byte_count is odd. We don't expect this to be common. - */ - - spec.length = byte_count & (~ 1L); - spec.src_handle = 0; - spec.src.ptr = buffer_address; - spec.dst_handle = info->handle.xms_handle; - spec.dst.offset = file_offset; - - ctx.ds_si = (void far *) & spec; - ctx.ax = 0x0b00; /* EMB move */ - jxms_calldriver(xms_driver, (XMScontext far *) & ctx); - if (ctx.ax != 1) - ERREXIT(cinfo, JERR_XMS_WRITE); - - if (ODD(byte_count)) { - read_xms_store(cinfo, info, (void FAR *) endbuffer, - file_offset + byte_count - 1L, 2L); - endbuffer[0] = ((char FAR *) buffer_address)[byte_count - 1L]; - write_xms_store(cinfo, info, (void FAR *) endbuffer, - file_offset + byte_count - 1L, 2L); - } -} - - -METHODDEF(void) -close_xms_store (j_common_ptr cinfo, backing_store_ptr info) -{ - XMScontext ctx; - - ctx.dx = info->handle.xms_handle; - ctx.ax = 0x0a00; - jxms_calldriver(xms_driver, (XMScontext far *) & ctx); - TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info->handle.xms_handle); - /* we ignore any error return from the driver */ -} - - -LOCAL(boolean) -open_xms_store (j_common_ptr cinfo, backing_store_ptr info, - long total_bytes_needed) -{ - XMScontext ctx; - - /* Get address of XMS driver */ - jxms_getdriver((XMSDRIVER far *) & xms_driver); - if (xms_driver == NULL) - return FALSE; /* no driver to be had */ - - /* Get version number, must be >= 2.00 */ - ctx.ax = 0x0000; - jxms_calldriver(xms_driver, (XMScontext far *) & ctx); - if (ctx.ax < (unsigned short) 0x0200) - return FALSE; - - /* Try to get space (expressed in kilobytes) */ - ctx.dx = (unsigned short) ((total_bytes_needed + 1023L) >> 10); - ctx.ax = 0x0900; - jxms_calldriver(xms_driver, (XMScontext far *) & ctx); - if (ctx.ax != 1) - return FALSE; - - /* Succeeded, save the handle and away we go */ - info->handle.xms_handle = ctx.dx; - info->read_backing_store = read_xms_store; - info->write_backing_store = write_xms_store; - info->close_backing_store = close_xms_store; - TRACEMS1(cinfo, 1, JTRC_XMS_OPEN, ctx.dx); - return TRUE; /* succeeded */ -} - -#endif /* XMS_SUPPORTED */ - - -/* - * Access methods for expanded memory. - */ - -#if EMS_SUPPORTED - -/* The EMS move specification structure requires word and long fields aligned - * at odd byte boundaries. Some compilers will align struct fields at even - * byte boundaries. While it's usually possible to force byte alignment, - * that causes an overall performance penalty and may pose problems in merging - * JPEG into a larger application. Instead we accept some rather dirty code - * here. Note this code would fail if the hardware did not allow odd-byte - * word & long accesses, but all 80x86 CPUs do. - */ - -typedef void far * EMSPTR; - -typedef union { /* EMS move specification structure */ - long length; /* It's easy to access first 4 bytes */ - char bytes[18]; /* Misaligned fields in here! */ - } EMSspec; - -/* Macros for accessing misaligned fields */ -#define FIELD_AT(spec,offset,type) (*((type *) &(spec.bytes[offset]))) -#define SRC_TYPE(spec) FIELD_AT(spec,4,char) -#define SRC_HANDLE(spec) FIELD_AT(spec,5,EMSH) -#define SRC_OFFSET(spec) FIELD_AT(spec,7,unsigned short) -#define SRC_PAGE(spec) FIELD_AT(spec,9,unsigned short) -#define SRC_PTR(spec) FIELD_AT(spec,7,EMSPTR) -#define DST_TYPE(spec) FIELD_AT(spec,11,char) -#define DST_HANDLE(spec) FIELD_AT(spec,12,EMSH) -#define DST_OFFSET(spec) FIELD_AT(spec,14,unsigned short) -#define DST_PAGE(spec) FIELD_AT(spec,16,unsigned short) -#define DST_PTR(spec) FIELD_AT(spec,14,EMSPTR) - -#define EMSPAGESIZE 16384L /* gospel, see the EMS specs */ - -#define HIBYTE(W) (((W) >> 8) & 0xFF) -#define LOBYTE(W) ((W) & 0xFF) - - -METHODDEF(void) -read_ems_store (j_common_ptr cinfo, backing_store_ptr info, - void FAR * buffer_address, - long file_offset, long byte_count) -{ - EMScontext ctx; - EMSspec spec; - - spec.length = byte_count; - SRC_TYPE(spec) = 1; - SRC_HANDLE(spec) = info->handle.ems_handle; - SRC_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE); - SRC_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE); - DST_TYPE(spec) = 0; - DST_HANDLE(spec) = 0; - DST_PTR(spec) = buffer_address; - - ctx.ds_si = (void far *) & spec; - ctx.ax = 0x5700; /* move memory region */ - jems_calldriver((EMScontext far *) & ctx); - if (HIBYTE(ctx.ax) != 0) - ERREXIT(cinfo, JERR_EMS_READ); -} - - -METHODDEF(void) -write_ems_store (j_common_ptr cinfo, backing_store_ptr info, - void FAR * buffer_address, - long file_offset, long byte_count) -{ - EMScontext ctx; - EMSspec spec; - - spec.length = byte_count; - SRC_TYPE(spec) = 0; - SRC_HANDLE(spec) = 0; - SRC_PTR(spec) = buffer_address; - DST_TYPE(spec) = 1; - DST_HANDLE(spec) = info->handle.ems_handle; - DST_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE); - DST_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE); - - ctx.ds_si = (void far *) & spec; - ctx.ax = 0x5700; /* move memory region */ - jems_calldriver((EMScontext far *) & ctx); - if (HIBYTE(ctx.ax) != 0) - ERREXIT(cinfo, JERR_EMS_WRITE); -} - - -METHODDEF(void) -close_ems_store (j_common_ptr cinfo, backing_store_ptr info) -{ - EMScontext ctx; - - ctx.ax = 0x4500; - ctx.dx = info->handle.ems_handle; - jems_calldriver((EMScontext far *) & ctx); - TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info->handle.ems_handle); - /* we ignore any error return from the driver */ -} - - -LOCAL(boolean) -open_ems_store (j_common_ptr cinfo, backing_store_ptr info, - long total_bytes_needed) -{ - EMScontext ctx; - - /* Is EMS driver there? */ - if (! jems_available()) - return FALSE; - - /* Get status, make sure EMS is OK */ - ctx.ax = 0x4000; - jems_calldriver((EMScontext far *) & ctx); - if (HIBYTE(ctx.ax) != 0) - return FALSE; - - /* Get version, must be >= 4.0 */ - ctx.ax = 0x4600; - jems_calldriver((EMScontext far *) & ctx); - if (HIBYTE(ctx.ax) != 0 || LOBYTE(ctx.ax) < 0x40) - return FALSE; - - /* Try to allocate requested space */ - ctx.ax = 0x4300; - ctx.bx = (unsigned short) ((total_bytes_needed + EMSPAGESIZE-1L) / EMSPAGESIZE); - jems_calldriver((EMScontext far *) & ctx); - if (HIBYTE(ctx.ax) != 0) - return FALSE; - - /* Succeeded, save the handle and away we go */ - info->handle.ems_handle = ctx.dx; - info->read_backing_store = read_ems_store; - info->write_backing_store = write_ems_store; - info->close_backing_store = close_ems_store; - TRACEMS1(cinfo, 1, JTRC_EMS_OPEN, ctx.dx); - return TRUE; /* succeeded */ -} - -#endif /* EMS_SUPPORTED */ - - -/* - * Initial opening of a backing-store object. - */ - -GLOBAL(void) -jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, - long total_bytes_needed) -{ - /* Try extended memory, then expanded memory, then regular file. */ -#if XMS_SUPPORTED - if (open_xms_store(cinfo, info, total_bytes_needed)) - return; -#endif -#if EMS_SUPPORTED - if (open_ems_store(cinfo, info, total_bytes_needed)) - return; -#endif - if (open_file_store(cinfo, info, total_bytes_needed)) - return; - ERREXITS(cinfo, JERR_TFILE_CREATE, ""); -} - - -/* - * These routines take care of any system-dependent initialization and - * cleanup required. - */ - -GLOBAL(long) -jpeg_mem_init (j_common_ptr cinfo) -{ - next_file_num = 0; /* initialize temp file name generator */ - return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ -} - -GLOBAL(void) -jpeg_mem_term (j_common_ptr cinfo) -{ - /* Microsoft C, at least in v6.00A, will not successfully reclaim freed - * blocks of size > 32Kbytes unless we give it a kick in the rear, like so: - */ -#ifdef NEED_FHEAPMIN - _fheapmin(); -#endif -} +/* + * jmemdos.c + * + * Copyright (C) 1992-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file provides an MS-DOS-compatible implementation of the system- + * dependent portion of the JPEG memory manager. Temporary data can be + * stored in extended or expanded memory as well as in regular DOS files. + * + * If you use this file, you must be sure that NEED_FAR_POINTERS is defined + * if you compile in a small-data memory model; it should NOT be defined if + * you use a large-data memory model. This file is not recommended if you + * are using a flat-memory-space 386 environment such as DJGCC or Watcom C. + * Also, this code will NOT work if struct fields are aligned on greater than + * 2-byte boundaries. + * + * Based on code contributed by Ge' Weijers. + */ + +/* + * If you have both extended and expanded memory, you may want to change the + * order in which they are tried in jopen_backing_store. On a 286 machine + * expanded memory is usually faster, since extended memory access involves + * an expensive protected-mode-and-back switch. On 386 and better, extended + * memory is usually faster. As distributed, the code tries extended memory + * first (what? not everyone has a 386? :-). + * + * You can disable use of extended/expanded memory entirely by altering these + * definitions or overriding them from the Makefile (eg, -DEMS_SUPPORTED=0). + */ + +#ifndef XMS_SUPPORTED +#define XMS_SUPPORTED 1 +#endif +#ifndef EMS_SUPPORTED +#define EMS_SUPPORTED 1 +#endif + + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jmemsys.h" /* import the system-dependent declarations */ + +#ifndef HAVE_STDLIB_H /* should declare these */ +extern void * malloc JPP((size_t size)); +extern void free JPP((void *ptr)); +extern char * getenv JPP((const char * name)); +#endif + +#ifdef NEED_FAR_POINTERS + +#ifdef __TURBOC__ +/* These definitions work for Borland C (Turbo C) */ +#include /* need farmalloc(), farfree() */ +#define far_malloc(x) farmalloc(x) +#define far_free(x) farfree(x) +#else +/* These definitions work for Microsoft C and compatible compilers */ +#include /* need _fmalloc(), _ffree() */ +#define far_malloc(x) _fmalloc(x) +#define far_free(x) _ffree(x) +#endif + +#else /* not NEED_FAR_POINTERS */ + +#define far_malloc(x) malloc(x) +#define far_free(x) free(x) + +#endif /* NEED_FAR_POINTERS */ + +#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ +#define READ_BINARY "r" +#else +#define READ_BINARY "rb" +#endif + +#ifndef USE_MSDOS_MEMMGR /* make sure user got configuration right */ + You forgot to define USE_MSDOS_MEMMGR in jconfig.h. /* deliberate syntax error */ +#endif + +#if MAX_ALLOC_CHUNK >= 65535L /* make sure jconfig.h got this right */ + MAX_ALLOC_CHUNK should be less than 64K. /* deliberate syntax error */ +#endif + + +/* + * Declarations for assembly-language support routines (see jmemdosa.asm). + * + * The functions are declared "far" as are all their pointer arguments; + * this ensures the assembly source code will work regardless of the + * compiler memory model. We assume "short" is 16 bits, "long" is 32. + */ + +typedef void far * XMSDRIVER; /* actually a pointer to code */ +typedef struct { /* registers for calling XMS driver */ + unsigned short ax, dx, bx; + void far * ds_si; + } XMScontext; +typedef struct { /* registers for calling EMS driver */ + unsigned short ax, dx, bx; + void far * ds_si; + } EMScontext; + +extern short far jdos_open JPP((short far * handle, char far * filename)); +extern short far jdos_close JPP((short handle)); +extern short far jdos_seek JPP((short handle, long offset)); +extern short far jdos_read JPP((short handle, void far * buffer, + unsigned short count)); +extern short far jdos_write JPP((short handle, void far * buffer, + unsigned short count)); +extern void far jxms_getdriver JPP((XMSDRIVER far *)); +extern void far jxms_calldriver JPP((XMSDRIVER, XMScontext far *)); +extern short far jems_available JPP((void)); +extern void far jems_calldriver JPP((EMScontext far *)); + + +/* + * Selection of a file name for a temporary file. + * This is highly system-dependent, and you may want to customize it. + */ + +static int next_file_num; /* to distinguish among several temp files */ + +LOCAL(void) +select_file_name (char * fname) +{ + const char * env; + char * ptr; + FILE * tfile; + + /* Keep generating file names till we find one that's not in use */ + for (;;) { + /* Get temp directory name from environment TMP or TEMP variable; + * if none, use "." + */ + if ((env = (const char *) getenv("TMP")) == NULL) + if ((env = (const char *) getenv("TEMP")) == NULL) + env = "."; + if (*env == '\0') /* null string means "." */ + env = "."; + ptr = fname; /* copy name to fname */ + while (*env != '\0') + *ptr++ = *env++; + if (ptr[-1] != '\\' && ptr[-1] != '/') + *ptr++ = '\\'; /* append backslash if not in env variable */ + /* Append a suitable file name */ + next_file_num++; /* advance counter */ + sprintf(ptr, "JPG%03d.TMP", next_file_num); + /* Probe to see if file name is already in use */ + if ((tfile = fopen(fname, READ_BINARY)) == NULL) + break; + fclose(tfile); /* oops, it's there; close tfile & try again */ + } +} + + +/* + * Near-memory allocation and freeing are controlled by the regular library + * routines malloc() and free(). + */ + +GLOBAL(void *) +jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) +{ + return (void *) malloc(sizeofobject); +} + +GLOBAL(void) +jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) +{ + free(object); +} + + +/* + * "Large" objects are allocated in far memory, if possible + */ + +GLOBAL(void FAR *) +jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) +{ + return (void FAR *) far_malloc(sizeofobject); +} + +GLOBAL(void) +jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) +{ + far_free(object); +} + + +/* + * This routine computes the total memory space available for allocation. + * It's impossible to do this in a portable way; our current solution is + * to make the user tell us (with a default value set at compile time). + * If you can actually get the available space, it's a good idea to subtract + * a slop factor of 5% or so. + */ + +#ifndef DEFAULT_MAX_MEM /* so can override from makefile */ +#define DEFAULT_MAX_MEM 300000L /* for total usage about 450K */ +#endif + +GLOBAL(long) +jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, + long max_bytes_needed, long already_allocated) +{ + return cinfo->mem->max_memory_to_use - already_allocated; +} + + +/* + * Backing store (temporary file) management. + * Backing store objects are only used when the value returned by + * jpeg_mem_available is less than the total space needed. You can dispense + * with these routines if you have plenty of virtual memory; see jmemnobs.c. + */ + +/* + * For MS-DOS we support three types of backing storage: + * 1. Conventional DOS files. We access these by direct DOS calls rather + * than via the stdio package. This provides a bit better performance, + * but the real reason is that the buffers to be read or written are FAR. + * The stdio library for small-data memory models can't cope with that. + * 2. Extended memory, accessed per the XMS V2.0 specification. + * 3. Expanded memory, accessed per the LIM/EMS 4.0 specification. + * You'll need copies of those specs to make sense of the related code. + * The specs are available by Internet FTP from the SIMTEL archives + * (oak.oakland.edu and its various mirror sites). See files + * pub/msdos/microsoft/xms20.arc and pub/msdos/info/limems41.zip. + */ + + +/* + * Access methods for a DOS file. + */ + + +METHODDEF(void) +read_file_store (j_common_ptr cinfo, backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count) +{ + if (jdos_seek(info->handle.file_handle, file_offset)) + ERREXIT(cinfo, JERR_TFILE_SEEK); + /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */ + if (byte_count > 65535L) /* safety check */ + ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK); + if (jdos_read(info->handle.file_handle, buffer_address, + (unsigned short) byte_count)) + ERREXIT(cinfo, JERR_TFILE_READ); +} + + +METHODDEF(void) +write_file_store (j_common_ptr cinfo, backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count) +{ + if (jdos_seek(info->handle.file_handle, file_offset)) + ERREXIT(cinfo, JERR_TFILE_SEEK); + /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */ + if (byte_count > 65535L) /* safety check */ + ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK); + if (jdos_write(info->handle.file_handle, buffer_address, + (unsigned short) byte_count)) + ERREXIT(cinfo, JERR_TFILE_WRITE); +} + + +METHODDEF(void) +close_file_store (j_common_ptr cinfo, backing_store_ptr info) +{ + jdos_close(info->handle.file_handle); /* close the file */ + remove(info->temp_name); /* delete the file */ +/* If your system doesn't have remove(), try unlink() instead. + * remove() is the ANSI-standard name for this function, but + * unlink() was more common in pre-ANSI systems. + */ + TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name); +} + + +LOCAL(boolean) +open_file_store (j_common_ptr cinfo, backing_store_ptr info, + long total_bytes_needed) +{ + short handle; + + select_file_name(info->temp_name); + if (jdos_open((short far *) & handle, (char far *) info->temp_name)) { + /* might as well exit since jpeg_open_backing_store will fail anyway */ + ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); + return FALSE; + } + info->handle.file_handle = handle; + info->read_backing_store = read_file_store; + info->write_backing_store = write_file_store; + info->close_backing_store = close_file_store; + TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); + return TRUE; /* succeeded */ +} + + +/* + * Access methods for extended memory. + */ + +#if XMS_SUPPORTED + +static XMSDRIVER xms_driver; /* saved address of XMS driver */ + +typedef union { /* either long offset or real-mode pointer */ + long offset; + void far * ptr; + } XMSPTR; + +typedef struct { /* XMS move specification structure */ + long length; + XMSH src_handle; + XMSPTR src; + XMSH dst_handle; + XMSPTR dst; + } XMSspec; + +#define ODD(X) (((X) & 1L) != 0) + + +METHODDEF(void) +read_xms_store (j_common_ptr cinfo, backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count) +{ + XMScontext ctx; + XMSspec spec; + char endbuffer[2]; + + /* The XMS driver can't cope with an odd length, so handle the last byte + * specially if byte_count is odd. We don't expect this to be common. + */ + + spec.length = byte_count & (~ 1L); + spec.src_handle = info->handle.xms_handle; + spec.src.offset = file_offset; + spec.dst_handle = 0; + spec.dst.ptr = buffer_address; + + ctx.ds_si = (void far *) & spec; + ctx.ax = 0x0b00; /* EMB move */ + jxms_calldriver(xms_driver, (XMScontext far *) & ctx); + if (ctx.ax != 1) + ERREXIT(cinfo, JERR_XMS_READ); + + if (ODD(byte_count)) { + read_xms_store(cinfo, info, (void FAR *) endbuffer, + file_offset + byte_count - 1L, 2L); + ((char FAR *) buffer_address)[byte_count - 1L] = endbuffer[0]; + } +} + + +METHODDEF(void) +write_xms_store (j_common_ptr cinfo, backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count) +{ + XMScontext ctx; + XMSspec spec; + char endbuffer[2]; + + /* The XMS driver can't cope with an odd length, so handle the last byte + * specially if byte_count is odd. We don't expect this to be common. + */ + + spec.length = byte_count & (~ 1L); + spec.src_handle = 0; + spec.src.ptr = buffer_address; + spec.dst_handle = info->handle.xms_handle; + spec.dst.offset = file_offset; + + ctx.ds_si = (void far *) & spec; + ctx.ax = 0x0b00; /* EMB move */ + jxms_calldriver(xms_driver, (XMScontext far *) & ctx); + if (ctx.ax != 1) + ERREXIT(cinfo, JERR_XMS_WRITE); + + if (ODD(byte_count)) { + read_xms_store(cinfo, info, (void FAR *) endbuffer, + file_offset + byte_count - 1L, 2L); + endbuffer[0] = ((char FAR *) buffer_address)[byte_count - 1L]; + write_xms_store(cinfo, info, (void FAR *) endbuffer, + file_offset + byte_count - 1L, 2L); + } +} + + +METHODDEF(void) +close_xms_store (j_common_ptr cinfo, backing_store_ptr info) +{ + XMScontext ctx; + + ctx.dx = info->handle.xms_handle; + ctx.ax = 0x0a00; + jxms_calldriver(xms_driver, (XMScontext far *) & ctx); + TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info->handle.xms_handle); + /* we ignore any error return from the driver */ +} + + +LOCAL(boolean) +open_xms_store (j_common_ptr cinfo, backing_store_ptr info, + long total_bytes_needed) +{ + XMScontext ctx; + + /* Get address of XMS driver */ + jxms_getdriver((XMSDRIVER far *) & xms_driver); + if (xms_driver == NULL) + return FALSE; /* no driver to be had */ + + /* Get version number, must be >= 2.00 */ + ctx.ax = 0x0000; + jxms_calldriver(xms_driver, (XMScontext far *) & ctx); + if (ctx.ax < (unsigned short) 0x0200) + return FALSE; + + /* Try to get space (expressed in kilobytes) */ + ctx.dx = (unsigned short) ((total_bytes_needed + 1023L) >> 10); + ctx.ax = 0x0900; + jxms_calldriver(xms_driver, (XMScontext far *) & ctx); + if (ctx.ax != 1) + return FALSE; + + /* Succeeded, save the handle and away we go */ + info->handle.xms_handle = ctx.dx; + info->read_backing_store = read_xms_store; + info->write_backing_store = write_xms_store; + info->close_backing_store = close_xms_store; + TRACEMS1(cinfo, 1, JTRC_XMS_OPEN, ctx.dx); + return TRUE; /* succeeded */ +} + +#endif /* XMS_SUPPORTED */ + + +/* + * Access methods for expanded memory. + */ + +#if EMS_SUPPORTED + +/* The EMS move specification structure requires word and long fields aligned + * at odd byte boundaries. Some compilers will align struct fields at even + * byte boundaries. While it's usually possible to force byte alignment, + * that causes an overall performance penalty and may pose problems in merging + * JPEG into a larger application. Instead we accept some rather dirty code + * here. Note this code would fail if the hardware did not allow odd-byte + * word & long accesses, but all 80x86 CPUs do. + */ + +typedef void far * EMSPTR; + +typedef union { /* EMS move specification structure */ + long length; /* It's easy to access first 4 bytes */ + char bytes[18]; /* Misaligned fields in here! */ + } EMSspec; + +/* Macros for accessing misaligned fields */ +#define FIELD_AT(spec,offset,type) (*((type *) &(spec.bytes[offset]))) +#define SRC_TYPE(spec) FIELD_AT(spec,4,char) +#define SRC_HANDLE(spec) FIELD_AT(spec,5,EMSH) +#define SRC_OFFSET(spec) FIELD_AT(spec,7,unsigned short) +#define SRC_PAGE(spec) FIELD_AT(spec,9,unsigned short) +#define SRC_PTR(spec) FIELD_AT(spec,7,EMSPTR) +#define DST_TYPE(spec) FIELD_AT(spec,11,char) +#define DST_HANDLE(spec) FIELD_AT(spec,12,EMSH) +#define DST_OFFSET(spec) FIELD_AT(spec,14,unsigned short) +#define DST_PAGE(spec) FIELD_AT(spec,16,unsigned short) +#define DST_PTR(spec) FIELD_AT(spec,14,EMSPTR) + +#define EMSPAGESIZE 16384L /* gospel, see the EMS specs */ + +#define HIBYTE(W) (((W) >> 8) & 0xFF) +#define LOBYTE(W) ((W) & 0xFF) + + +METHODDEF(void) +read_ems_store (j_common_ptr cinfo, backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count) +{ + EMScontext ctx; + EMSspec spec; + + spec.length = byte_count; + SRC_TYPE(spec) = 1; + SRC_HANDLE(spec) = info->handle.ems_handle; + SRC_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE); + SRC_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE); + DST_TYPE(spec) = 0; + DST_HANDLE(spec) = 0; + DST_PTR(spec) = buffer_address; + + ctx.ds_si = (void far *) & spec; + ctx.ax = 0x5700; /* move memory region */ + jems_calldriver((EMScontext far *) & ctx); + if (HIBYTE(ctx.ax) != 0) + ERREXIT(cinfo, JERR_EMS_READ); +} + + +METHODDEF(void) +write_ems_store (j_common_ptr cinfo, backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count) +{ + EMScontext ctx; + EMSspec spec; + + spec.length = byte_count; + SRC_TYPE(spec) = 0; + SRC_HANDLE(spec) = 0; + SRC_PTR(spec) = buffer_address; + DST_TYPE(spec) = 1; + DST_HANDLE(spec) = info->handle.ems_handle; + DST_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE); + DST_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE); + + ctx.ds_si = (void far *) & spec; + ctx.ax = 0x5700; /* move memory region */ + jems_calldriver((EMScontext far *) & ctx); + if (HIBYTE(ctx.ax) != 0) + ERREXIT(cinfo, JERR_EMS_WRITE); +} + + +METHODDEF(void) +close_ems_store (j_common_ptr cinfo, backing_store_ptr info) +{ + EMScontext ctx; + + ctx.ax = 0x4500; + ctx.dx = info->handle.ems_handle; + jems_calldriver((EMScontext far *) & ctx); + TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info->handle.ems_handle); + /* we ignore any error return from the driver */ +} + + +LOCAL(boolean) +open_ems_store (j_common_ptr cinfo, backing_store_ptr info, + long total_bytes_needed) +{ + EMScontext ctx; + + /* Is EMS driver there? */ + if (! jems_available()) + return FALSE; + + /* Get status, make sure EMS is OK */ + ctx.ax = 0x4000; + jems_calldriver((EMScontext far *) & ctx); + if (HIBYTE(ctx.ax) != 0) + return FALSE; + + /* Get version, must be >= 4.0 */ + ctx.ax = 0x4600; + jems_calldriver((EMScontext far *) & ctx); + if (HIBYTE(ctx.ax) != 0 || LOBYTE(ctx.ax) < 0x40) + return FALSE; + + /* Try to allocate requested space */ + ctx.ax = 0x4300; + ctx.bx = (unsigned short) ((total_bytes_needed + EMSPAGESIZE-1L) / EMSPAGESIZE); + jems_calldriver((EMScontext far *) & ctx); + if (HIBYTE(ctx.ax) != 0) + return FALSE; + + /* Succeeded, save the handle and away we go */ + info->handle.ems_handle = ctx.dx; + info->read_backing_store = read_ems_store; + info->write_backing_store = write_ems_store; + info->close_backing_store = close_ems_store; + TRACEMS1(cinfo, 1, JTRC_EMS_OPEN, ctx.dx); + return TRUE; /* succeeded */ +} + +#endif /* EMS_SUPPORTED */ + + +/* + * Initial opening of a backing-store object. + */ + +GLOBAL(void) +jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, + long total_bytes_needed) +{ + /* Try extended memory, then expanded memory, then regular file. */ +#if XMS_SUPPORTED + if (open_xms_store(cinfo, info, total_bytes_needed)) + return; +#endif +#if EMS_SUPPORTED + if (open_ems_store(cinfo, info, total_bytes_needed)) + return; +#endif + if (open_file_store(cinfo, info, total_bytes_needed)) + return; + ERREXITS(cinfo, JERR_TFILE_CREATE, ""); +} + + +/* + * These routines take care of any system-dependent initialization and + * cleanup required. + */ + +GLOBAL(long) +jpeg_mem_init (j_common_ptr cinfo) +{ + next_file_num = 0; /* initialize temp file name generator */ + return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ +} + +GLOBAL(void) +jpeg_mem_term (j_common_ptr cinfo) +{ + /* Microsoft C, at least in v6.00A, will not successfully reclaim freed + * blocks of size > 32Kbytes unless we give it a kick in the rear, like so: + */ +#ifdef NEED_FHEAPMIN + _fheapmin(); +#endif +} diff --git a/Source/LibJPEG/jmemdosa.asm b/Source/LibJPEG/jmemdosa.asm index c6ec48b..ecd4372 100644 --- a/Source/LibJPEG/jmemdosa.asm +++ b/Source/LibJPEG/jmemdosa.asm @@ -1,379 +1,379 @@ -; -; jmemdosa.asm -; -; Copyright (C) 1992, Thomas G. Lane. -; This file is part of the Independent JPEG Group's software. -; For conditions of distribution and use, see the accompanying README file. -; -; This file contains low-level interface routines to support the MS-DOS -; backing store manager (jmemdos.c). Routines are provided to access disk -; files through direct DOS calls, and to access XMS and EMS drivers. -; -; This file should assemble with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). If you haven't got -; a compatible assembler, better fall back to jmemansi.c or jmemname.c. -; -; To minimize dependence on the C compiler's register usage conventions, -; we save and restore all 8086 registers, even though most compilers only -; require SI,DI,DS to be preserved. Also, we use only 16-bit-wide return -; values, which everybody returns in AX. -; -; Based on code contributed by Ge' Weijers. -; - -JMEMDOSA_TXT segment byte public 'CODE' - - assume cs:JMEMDOSA_TXT - - public _jdos_open - public _jdos_close - public _jdos_seek - public _jdos_read - public _jdos_write - public _jxms_getdriver - public _jxms_calldriver - public _jems_available - public _jems_calldriver - -; -; short far jdos_open (short far * handle, char far * filename) -; -; Create and open a temporary file -; -_jdos_open proc far - push bp ; linkage - mov bp,sp - push si ; save all registers for safety - push di - push bx - push cx - push dx - push es - push ds - mov cx,0 ; normal file attributes - lds dx,dword ptr [bp+10] ; get filename pointer - mov ah,3ch ; create file - int 21h - jc open_err ; if failed, return error code - lds bx,dword ptr [bp+6] ; get handle pointer - mov word ptr [bx],ax ; save the handle - xor ax,ax ; return zero for OK -open_err: pop ds ; restore registers and exit - pop es - pop dx - pop cx - pop bx - pop di - pop si - pop bp - ret -_jdos_open endp - - -; -; short far jdos_close (short handle) -; -; Close the file handle -; -_jdos_close proc far - push bp ; linkage - mov bp,sp - push si ; save all registers for safety - push di - push bx - push cx - push dx - push es - push ds - mov bx,word ptr [bp+6] ; file handle - mov ah,3eh ; close file - int 21h - jc close_err ; if failed, return error code - xor ax,ax ; return zero for OK -close_err: pop ds ; restore registers and exit - pop es - pop dx - pop cx - pop bx - pop di - pop si - pop bp - ret -_jdos_close endp - - -; -; short far jdos_seek (short handle, long offset) -; -; Set file position -; -_jdos_seek proc far - push bp ; linkage - mov bp,sp - push si ; save all registers for safety - push di - push bx - push cx - push dx - push es - push ds - mov bx,word ptr [bp+6] ; file handle - mov dx,word ptr [bp+8] ; LS offset - mov cx,word ptr [bp+10] ; MS offset - mov ax,4200h ; absolute seek - int 21h - jc seek_err ; if failed, return error code - xor ax,ax ; return zero for OK -seek_err: pop ds ; restore registers and exit - pop es - pop dx - pop cx - pop bx - pop di - pop si - pop bp - ret -_jdos_seek endp - - -; -; short far jdos_read (short handle, void far * buffer, unsigned short count) -; -; Read from file -; -_jdos_read proc far - push bp ; linkage - mov bp,sp - push si ; save all registers for safety - push di - push bx - push cx - push dx - push es - push ds - mov bx,word ptr [bp+6] ; file handle - lds dx,dword ptr [bp+8] ; buffer address - mov cx,word ptr [bp+12] ; number of bytes - mov ah,3fh ; read file - int 21h - jc read_err ; if failed, return error code - cmp ax,word ptr [bp+12] ; make sure all bytes were read - je read_ok - mov ax,1 ; else return 1 for not OK - jmp short read_err -read_ok: xor ax,ax ; return zero for OK -read_err: pop ds ; restore registers and exit - pop es - pop dx - pop cx - pop bx - pop di - pop si - pop bp - ret -_jdos_read endp - - -; -; short far jdos_write (short handle, void far * buffer, unsigned short count) -; -; Write to file -; -_jdos_write proc far - push bp ; linkage - mov bp,sp - push si ; save all registers for safety - push di - push bx - push cx - push dx - push es - push ds - mov bx,word ptr [bp+6] ; file handle - lds dx,dword ptr [bp+8] ; buffer address - mov cx,word ptr [bp+12] ; number of bytes - mov ah,40h ; write file - int 21h - jc write_err ; if failed, return error code - cmp ax,word ptr [bp+12] ; make sure all bytes written - je write_ok - mov ax,1 ; else return 1 for not OK - jmp short write_err -write_ok: xor ax,ax ; return zero for OK -write_err: pop ds ; restore registers and exit - pop es - pop dx - pop cx - pop bx - pop di - pop si - pop bp - ret -_jdos_write endp - - -; -; void far jxms_getdriver (XMSDRIVER far *) -; -; Get the address of the XMS driver, or NULL if not available -; -_jxms_getdriver proc far - push bp ; linkage - mov bp,sp - push si ; save all registers for safety - push di - push bx - push cx - push dx - push es - push ds - mov ax,4300h ; call multiplex interrupt with - int 2fh ; a magic cookie, hex 4300 - cmp al,80h ; AL should contain hex 80 - je xmsavail - xor dx,dx ; no XMS driver available - xor ax,ax ; return a nil pointer - jmp short xmsavail_done -xmsavail: mov ax,4310h ; fetch driver address with - int 2fh ; another magic cookie - mov dx,es ; copy address to dx:ax - mov ax,bx -xmsavail_done: les bx,dword ptr [bp+6] ; get pointer to return value - mov word ptr es:[bx],ax - mov word ptr es:[bx+2],dx - pop ds ; restore registers and exit - pop es - pop dx - pop cx - pop bx - pop di - pop si - pop bp - ret -_jxms_getdriver endp - - -; -; void far jxms_calldriver (XMSDRIVER, XMScontext far *) -; -; The XMScontext structure contains values for the AX,DX,BX,SI,DS registers. -; These are loaded, the XMS call is performed, and the new values of the -; AX,DX,BX registers are written back to the context structure. -; -_jxms_calldriver proc far - push bp ; linkage - mov bp,sp - push si ; save all registers for safety - push di - push bx - push cx - push dx - push es - push ds - les bx,dword ptr [bp+10] ; get XMScontext pointer - mov ax,word ptr es:[bx] ; load registers - mov dx,word ptr es:[bx+2] - mov si,word ptr es:[bx+6] - mov ds,word ptr es:[bx+8] - mov bx,word ptr es:[bx+4] - call dword ptr [bp+6] ; call the driver - mov cx,bx ; save returned BX for a sec - les bx,dword ptr [bp+10] ; get XMScontext pointer - mov word ptr es:[bx],ax ; put back ax,dx,bx - mov word ptr es:[bx+2],dx - mov word ptr es:[bx+4],cx - pop ds ; restore registers and exit - pop es - pop dx - pop cx - pop bx - pop di - pop si - pop bp - ret -_jxms_calldriver endp - - -; -; short far jems_available (void) -; -; Have we got an EMS driver? (this comes straight from the EMS 4.0 specs) -; -_jems_available proc far - push si ; save all registers for safety - push di - push bx - push cx - push dx - push es - push ds - mov ax,3567h ; get interrupt vector 67h - int 21h - push cs - pop ds - mov di,000ah ; check offs 10 in returned seg - lea si,ASCII_device_name ; against literal string - mov cx,8 - cld - repe cmpsb - jne no_ems - mov ax,1 ; match, it's there - jmp short avail_done -no_ems: xor ax,ax ; it's not there -avail_done: pop ds ; restore registers and exit - pop es - pop dx - pop cx - pop bx - pop di - pop si - ret - -ASCII_device_name db "EMMXXXX0" - -_jems_available endp - - -; -; void far jems_calldriver (EMScontext far *) -; -; The EMScontext structure contains values for the AX,DX,BX,SI,DS registers. -; These are loaded, the EMS trap is performed, and the new values of the -; AX,DX,BX registers are written back to the context structure. -; -_jems_calldriver proc far - push bp ; linkage - mov bp,sp - push si ; save all registers for safety - push di - push bx - push cx - push dx - push es - push ds - les bx,dword ptr [bp+6] ; get EMScontext pointer - mov ax,word ptr es:[bx] ; load registers - mov dx,word ptr es:[bx+2] - mov si,word ptr es:[bx+6] - mov ds,word ptr es:[bx+8] - mov bx,word ptr es:[bx+4] - int 67h ; call the EMS driver - mov cx,bx ; save returned BX for a sec - les bx,dword ptr [bp+6] ; get EMScontext pointer - mov word ptr es:[bx],ax ; put back ax,dx,bx - mov word ptr es:[bx+2],dx - mov word ptr es:[bx+4],cx - pop ds ; restore registers and exit - pop es - pop dx - pop cx - pop bx - pop di - pop si - pop bp - ret -_jems_calldriver endp - -JMEMDOSA_TXT ends - - end +; +; jmemdosa.asm +; +; Copyright (C) 1992, Thomas G. Lane. +; This file is part of the Independent JPEG Group's software. +; For conditions of distribution and use, see the accompanying README file. +; +; This file contains low-level interface routines to support the MS-DOS +; backing store manager (jmemdos.c). Routines are provided to access disk +; files through direct DOS calls, and to access XMS and EMS drivers. +; +; This file should assemble with Microsoft's MASM or any compatible +; assembler (including Borland's Turbo Assembler). If you haven't got +; a compatible assembler, better fall back to jmemansi.c or jmemname.c. +; +; To minimize dependence on the C compiler's register usage conventions, +; we save and restore all 8086 registers, even though most compilers only +; require SI,DI,DS to be preserved. Also, we use only 16-bit-wide return +; values, which everybody returns in AX. +; +; Based on code contributed by Ge' Weijers. +; + +JMEMDOSA_TXT segment byte public 'CODE' + + assume cs:JMEMDOSA_TXT + + public _jdos_open + public _jdos_close + public _jdos_seek + public _jdos_read + public _jdos_write + public _jxms_getdriver + public _jxms_calldriver + public _jems_available + public _jems_calldriver + +; +; short far jdos_open (short far * handle, char far * filename) +; +; Create and open a temporary file +; +_jdos_open proc far + push bp ; linkage + mov bp,sp + push si ; save all registers for safety + push di + push bx + push cx + push dx + push es + push ds + mov cx,0 ; normal file attributes + lds dx,dword ptr [bp+10] ; get filename pointer + mov ah,3ch ; create file + int 21h + jc open_err ; if failed, return error code + lds bx,dword ptr [bp+6] ; get handle pointer + mov word ptr [bx],ax ; save the handle + xor ax,ax ; return zero for OK +open_err: pop ds ; restore registers and exit + pop es + pop dx + pop cx + pop bx + pop di + pop si + pop bp + ret +_jdos_open endp + + +; +; short far jdos_close (short handle) +; +; Close the file handle +; +_jdos_close proc far + push bp ; linkage + mov bp,sp + push si ; save all registers for safety + push di + push bx + push cx + push dx + push es + push ds + mov bx,word ptr [bp+6] ; file handle + mov ah,3eh ; close file + int 21h + jc close_err ; if failed, return error code + xor ax,ax ; return zero for OK +close_err: pop ds ; restore registers and exit + pop es + pop dx + pop cx + pop bx + pop di + pop si + pop bp + ret +_jdos_close endp + + +; +; short far jdos_seek (short handle, long offset) +; +; Set file position +; +_jdos_seek proc far + push bp ; linkage + mov bp,sp + push si ; save all registers for safety + push di + push bx + push cx + push dx + push es + push ds + mov bx,word ptr [bp+6] ; file handle + mov dx,word ptr [bp+8] ; LS offset + mov cx,word ptr [bp+10] ; MS offset + mov ax,4200h ; absolute seek + int 21h + jc seek_err ; if failed, return error code + xor ax,ax ; return zero for OK +seek_err: pop ds ; restore registers and exit + pop es + pop dx + pop cx + pop bx + pop di + pop si + pop bp + ret +_jdos_seek endp + + +; +; short far jdos_read (short handle, void far * buffer, unsigned short count) +; +; Read from file +; +_jdos_read proc far + push bp ; linkage + mov bp,sp + push si ; save all registers for safety + push di + push bx + push cx + push dx + push es + push ds + mov bx,word ptr [bp+6] ; file handle + lds dx,dword ptr [bp+8] ; buffer address + mov cx,word ptr [bp+12] ; number of bytes + mov ah,3fh ; read file + int 21h + jc read_err ; if failed, return error code + cmp ax,word ptr [bp+12] ; make sure all bytes were read + je read_ok + mov ax,1 ; else return 1 for not OK + jmp short read_err +read_ok: xor ax,ax ; return zero for OK +read_err: pop ds ; restore registers and exit + pop es + pop dx + pop cx + pop bx + pop di + pop si + pop bp + ret +_jdos_read endp + + +; +; short far jdos_write (short handle, void far * buffer, unsigned short count) +; +; Write to file +; +_jdos_write proc far + push bp ; linkage + mov bp,sp + push si ; save all registers for safety + push di + push bx + push cx + push dx + push es + push ds + mov bx,word ptr [bp+6] ; file handle + lds dx,dword ptr [bp+8] ; buffer address + mov cx,word ptr [bp+12] ; number of bytes + mov ah,40h ; write file + int 21h + jc write_err ; if failed, return error code + cmp ax,word ptr [bp+12] ; make sure all bytes written + je write_ok + mov ax,1 ; else return 1 for not OK + jmp short write_err +write_ok: xor ax,ax ; return zero for OK +write_err: pop ds ; restore registers and exit + pop es + pop dx + pop cx + pop bx + pop di + pop si + pop bp + ret +_jdos_write endp + + +; +; void far jxms_getdriver (XMSDRIVER far *) +; +; Get the address of the XMS driver, or NULL if not available +; +_jxms_getdriver proc far + push bp ; linkage + mov bp,sp + push si ; save all registers for safety + push di + push bx + push cx + push dx + push es + push ds + mov ax,4300h ; call multiplex interrupt with + int 2fh ; a magic cookie, hex 4300 + cmp al,80h ; AL should contain hex 80 + je xmsavail + xor dx,dx ; no XMS driver available + xor ax,ax ; return a nil pointer + jmp short xmsavail_done +xmsavail: mov ax,4310h ; fetch driver address with + int 2fh ; another magic cookie + mov dx,es ; copy address to dx:ax + mov ax,bx +xmsavail_done: les bx,dword ptr [bp+6] ; get pointer to return value + mov word ptr es:[bx],ax + mov word ptr es:[bx+2],dx + pop ds ; restore registers and exit + pop es + pop dx + pop cx + pop bx + pop di + pop si + pop bp + ret +_jxms_getdriver endp + + +; +; void far jxms_calldriver (XMSDRIVER, XMScontext far *) +; +; The XMScontext structure contains values for the AX,DX,BX,SI,DS registers. +; These are loaded, the XMS call is performed, and the new values of the +; AX,DX,BX registers are written back to the context structure. +; +_jxms_calldriver proc far + push bp ; linkage + mov bp,sp + push si ; save all registers for safety + push di + push bx + push cx + push dx + push es + push ds + les bx,dword ptr [bp+10] ; get XMScontext pointer + mov ax,word ptr es:[bx] ; load registers + mov dx,word ptr es:[bx+2] + mov si,word ptr es:[bx+6] + mov ds,word ptr es:[bx+8] + mov bx,word ptr es:[bx+4] + call dword ptr [bp+6] ; call the driver + mov cx,bx ; save returned BX for a sec + les bx,dword ptr [bp+10] ; get XMScontext pointer + mov word ptr es:[bx],ax ; put back ax,dx,bx + mov word ptr es:[bx+2],dx + mov word ptr es:[bx+4],cx + pop ds ; restore registers and exit + pop es + pop dx + pop cx + pop bx + pop di + pop si + pop bp + ret +_jxms_calldriver endp + + +; +; short far jems_available (void) +; +; Have we got an EMS driver? (this comes straight from the EMS 4.0 specs) +; +_jems_available proc far + push si ; save all registers for safety + push di + push bx + push cx + push dx + push es + push ds + mov ax,3567h ; get interrupt vector 67h + int 21h + push cs + pop ds + mov di,000ah ; check offs 10 in returned seg + lea si,ASCII_device_name ; against literal string + mov cx,8 + cld + repe cmpsb + jne no_ems + mov ax,1 ; match, it's there + jmp short avail_done +no_ems: xor ax,ax ; it's not there +avail_done: pop ds ; restore registers and exit + pop es + pop dx + pop cx + pop bx + pop di + pop si + ret + +ASCII_device_name db "EMMXXXX0" + +_jems_available endp + + +; +; void far jems_calldriver (EMScontext far *) +; +; The EMScontext structure contains values for the AX,DX,BX,SI,DS registers. +; These are loaded, the EMS trap is performed, and the new values of the +; AX,DX,BX registers are written back to the context structure. +; +_jems_calldriver proc far + push bp ; linkage + mov bp,sp + push si ; save all registers for safety + push di + push bx + push cx + push dx + push es + push ds + les bx,dword ptr [bp+6] ; get EMScontext pointer + mov ax,word ptr es:[bx] ; load registers + mov dx,word ptr es:[bx+2] + mov si,word ptr es:[bx+6] + mov ds,word ptr es:[bx+8] + mov bx,word ptr es:[bx+4] + int 67h ; call the EMS driver + mov cx,bx ; save returned BX for a sec + les bx,dword ptr [bp+6] ; get EMScontext pointer + mov word ptr es:[bx],ax ; put back ax,dx,bx + mov word ptr es:[bx+2],dx + mov word ptr es:[bx+4],cx + pop ds ; restore registers and exit + pop es + pop dx + pop cx + pop bx + pop di + pop si + pop bp + ret +_jems_calldriver endp + +JMEMDOSA_TXT ends + + end diff --git a/Source/LibJPEG/jmemmac.c b/Source/LibJPEG/jmemmac.c index a6f043e..106f9be 100644 --- a/Source/LibJPEG/jmemmac.c +++ b/Source/LibJPEG/jmemmac.c @@ -1,289 +1,289 @@ -/* - * jmemmac.c - * - * Copyright (C) 1992-1997, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * jmemmac.c provides an Apple Macintosh implementation of the system- - * dependent portion of the JPEG memory manager. - * - * If you use jmemmac.c, then you must define USE_MAC_MEMMGR in the - * JPEG_INTERNALS part of jconfig.h. - * - * jmemmac.c uses the Macintosh toolbox routines NewPtr and DisposePtr - * instead of malloc and free. It accurately determines the amount of - * memory available by using CompactMem. Notice that if left to its - * own devices, this code can chew up all available space in the - * application's zone, with the exception of the rather small "slop" - * factor computed in jpeg_mem_available(). The application can ensure - * that more space is left over by reducing max_memory_to_use. - * - * Large images are swapped to disk using temporary files and System 7.0+'s - * temporary folder functionality. - * - * Note that jmemmac.c depends on two features of MacOS that were first - * introduced in System 7: FindFolder and the FSSpec-based calls. - * If your application uses jmemmac.c and is run under System 6 or earlier, - * and the jpeg library decides it needs a temporary file, it will abort, - * printing error messages about requiring System 7. (If no temporary files - * are created, it will run fine.) - * - * If you want to use jmemmac.c in an application that might be used with - * System 6 or earlier, then you should remove dependencies on FindFolder - * and the FSSpec calls. You will need to replace FindFolder with some - * other mechanism for finding a place to put temporary files, and you - * should replace the FSSpec calls with their HFS equivalents: - * - * FSpDelete -> HDelete - * FSpGetFInfo -> HGetFInfo - * FSpCreate -> HCreate - * FSpOpenDF -> HOpen *** Note: not HOpenDF *** - * FSMakeFSSpec -> (fill in spec by hand.) - * - * (Use HOpen instead of HOpenDF. HOpen is just a glue-interface to PBHOpen, - * which is on all HFS macs. HOpenDF is a System 7 addition which avoids the - * ages-old problem of names starting with a period.) - * - * Contributed by Sam Bushell (jsam@iagu.on.net) and - * Dan Gildor (gyld@in-touch.com). - */ - -#define JPEG_INTERNALS -#include "jinclude.h" -#include "jpeglib.h" -#include "jmemsys.h" /* import the system-dependent declarations */ - -#ifndef USE_MAC_MEMMGR /* make sure user got configuration right */ - You forgot to define USE_MAC_MEMMGR in jconfig.h. /* deliberate syntax error */ -#endif - -#include /* we use the MacOS memory manager */ -#include /* we use the MacOS File stuff */ -#include /* we use the MacOS HFS stuff */ -#include /* for smSystemScript */ -#include /* we use Gestalt to test for specific functionality */ - -#ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */ -#define TEMP_FILE_NAME "JPG%03d.TMP" -#endif - -static int next_file_num; /* to distinguish among several temp files */ - - -/* - * Memory allocation and freeing are controlled by the MacOS library - * routines NewPtr() and DisposePtr(), which allocate fixed-address - * storage. Unfortunately, the IJG library isn't smart enough to cope - * with relocatable storage. - */ - -GLOBAL(void *) -jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) -{ - return (void *) NewPtr(sizeofobject); -} - -GLOBAL(void) -jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) -{ - DisposePtr((Ptr) object); -} - - -/* - * "Large" objects are treated the same as "small" ones. - * NB: we include FAR keywords in the routine declarations simply for - * consistency with the rest of the IJG code; FAR should expand to empty - * on rational architectures like the Mac. - */ - -GLOBAL(void FAR *) -jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) -{ - return (void FAR *) NewPtr(sizeofobject); -} - -GLOBAL(void) -jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) -{ - DisposePtr((Ptr) object); -} - - -/* - * This routine computes the total memory space available for allocation. - */ - -GLOBAL(long) -jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, - long max_bytes_needed, long already_allocated) -{ - long limit = cinfo->mem->max_memory_to_use - already_allocated; - long slop, mem; - - /* Don't ask for more than what application has told us we may use */ - if (max_bytes_needed > limit && limit > 0) - max_bytes_needed = limit; - /* Find whether there's a big enough free block in the heap. - * CompactMem tries to create a contiguous block of the requested size, - * and then returns the size of the largest free block (which could be - * much more or much less than we asked for). - * We add some slop to ensure we don't use up all available memory. - */ - slop = max_bytes_needed / 16 + 32768L; - mem = CompactMem(max_bytes_needed + slop) - slop; - if (mem < 0) - mem = 0; /* sigh, couldn't even get the slop */ - /* Don't take more than the application says we can have */ - if (mem > limit && limit > 0) - mem = limit; - return mem; -} - - -/* - * Backing store (temporary file) management. - * Backing store objects are only used when the value returned by - * jpeg_mem_available is less than the total space needed. You can dispense - * with these routines if you have plenty of virtual memory; see jmemnobs.c. - */ - - -METHODDEF(void) -read_backing_store (j_common_ptr cinfo, backing_store_ptr info, - void FAR * buffer_address, - long file_offset, long byte_count) -{ - long bytes = byte_count; - long retVal; - - if ( SetFPos ( info->temp_file, fsFromStart, file_offset ) != noErr ) - ERREXIT(cinfo, JERR_TFILE_SEEK); - - retVal = FSRead ( info->temp_file, &bytes, - (unsigned char *) buffer_address ); - if ( retVal != noErr || bytes != byte_count ) - ERREXIT(cinfo, JERR_TFILE_READ); -} - - -METHODDEF(void) -write_backing_store (j_common_ptr cinfo, backing_store_ptr info, - void FAR * buffer_address, - long file_offset, long byte_count) -{ - long bytes = byte_count; - long retVal; - - if ( SetFPos ( info->temp_file, fsFromStart, file_offset ) != noErr ) - ERREXIT(cinfo, JERR_TFILE_SEEK); - - retVal = FSWrite ( info->temp_file, &bytes, - (unsigned char *) buffer_address ); - if ( retVal != noErr || bytes != byte_count ) - ERREXIT(cinfo, JERR_TFILE_WRITE); -} - - -METHODDEF(void) -close_backing_store (j_common_ptr cinfo, backing_store_ptr info) -{ - FSClose ( info->temp_file ); - FSpDelete ( &(info->tempSpec) ); -} - - -/* - * Initial opening of a backing-store object. - * - * This version uses FindFolder to find the Temporary Items folder, - * and puts the temporary file in there. - */ - -GLOBAL(void) -jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, - long total_bytes_needed) -{ - short tmpRef, vRefNum; - long dirID; - FInfo finderInfo; - FSSpec theSpec; - Str255 fName; - OSErr osErr; - long gestaltResponse = 0; - - /* Check that FSSpec calls are available. */ - osErr = Gestalt( gestaltFSAttr, &gestaltResponse ); - if ( ( osErr != noErr ) - || !( gestaltResponse & (1<temp_name, TEMP_FILE_NAME, next_file_num); - strcpy ( (Ptr)fName+1, info->temp_name ); - *fName = strlen (info->temp_name); - osErr = FSMakeFSSpec ( vRefNum, dirID, fName, &theSpec ); - - if ( (osErr = FSpGetFInfo ( &theSpec, &finderInfo ) ) != noErr ) - break; - } - - osErr = FSpCreate ( &theSpec, '????', '????', smSystemScript ); - if ( osErr != noErr ) - ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); - - osErr = FSpOpenDF ( &theSpec, fsRdWrPerm, &(info->temp_file) ); - if ( osErr != noErr ) - ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); - - info->tempSpec = theSpec; - - info->read_backing_store = read_backing_store; - info->write_backing_store = write_backing_store; - info->close_backing_store = close_backing_store; - TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); -} - - -/* - * These routines take care of any system-dependent initialization and - * cleanup required. - */ - -GLOBAL(long) -jpeg_mem_init (j_common_ptr cinfo) -{ - next_file_num = 0; - - /* max_memory_to_use will be initialized to FreeMem()'s result; - * the calling application might later reduce it, for example - * to leave room to invoke multiple JPEG objects. - * Note that FreeMem returns the total number of free bytes; - * it may not be possible to allocate a single block of this size. - */ - return FreeMem(); -} - -GLOBAL(void) -jpeg_mem_term (j_common_ptr cinfo) -{ - /* no work */ -} +/* + * jmemmac.c + * + * Copyright (C) 1992-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * jmemmac.c provides an Apple Macintosh implementation of the system- + * dependent portion of the JPEG memory manager. + * + * If you use jmemmac.c, then you must define USE_MAC_MEMMGR in the + * JPEG_INTERNALS part of jconfig.h. + * + * jmemmac.c uses the Macintosh toolbox routines NewPtr and DisposePtr + * instead of malloc and free. It accurately determines the amount of + * memory available by using CompactMem. Notice that if left to its + * own devices, this code can chew up all available space in the + * application's zone, with the exception of the rather small "slop" + * factor computed in jpeg_mem_available(). The application can ensure + * that more space is left over by reducing max_memory_to_use. + * + * Large images are swapped to disk using temporary files and System 7.0+'s + * temporary folder functionality. + * + * Note that jmemmac.c depends on two features of MacOS that were first + * introduced in System 7: FindFolder and the FSSpec-based calls. + * If your application uses jmemmac.c and is run under System 6 or earlier, + * and the jpeg library decides it needs a temporary file, it will abort, + * printing error messages about requiring System 7. (If no temporary files + * are created, it will run fine.) + * + * If you want to use jmemmac.c in an application that might be used with + * System 6 or earlier, then you should remove dependencies on FindFolder + * and the FSSpec calls. You will need to replace FindFolder with some + * other mechanism for finding a place to put temporary files, and you + * should replace the FSSpec calls with their HFS equivalents: + * + * FSpDelete -> HDelete + * FSpGetFInfo -> HGetFInfo + * FSpCreate -> HCreate + * FSpOpenDF -> HOpen *** Note: not HOpenDF *** + * FSMakeFSSpec -> (fill in spec by hand.) + * + * (Use HOpen instead of HOpenDF. HOpen is just a glue-interface to PBHOpen, + * which is on all HFS macs. HOpenDF is a System 7 addition which avoids the + * ages-old problem of names starting with a period.) + * + * Contributed by Sam Bushell (jsam@iagu.on.net) and + * Dan Gildor (gyld@in-touch.com). + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jmemsys.h" /* import the system-dependent declarations */ + +#ifndef USE_MAC_MEMMGR /* make sure user got configuration right */ + You forgot to define USE_MAC_MEMMGR in jconfig.h. /* deliberate syntax error */ +#endif + +#include /* we use the MacOS memory manager */ +#include /* we use the MacOS File stuff */ +#include /* we use the MacOS HFS stuff */ +#include /* for smSystemScript */ +#include /* we use Gestalt to test for specific functionality */ + +#ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */ +#define TEMP_FILE_NAME "JPG%03d.TMP" +#endif + +static int next_file_num; /* to distinguish among several temp files */ + + +/* + * Memory allocation and freeing are controlled by the MacOS library + * routines NewPtr() and DisposePtr(), which allocate fixed-address + * storage. Unfortunately, the IJG library isn't smart enough to cope + * with relocatable storage. + */ + +GLOBAL(void *) +jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) +{ + return (void *) NewPtr(sizeofobject); +} + +GLOBAL(void) +jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) +{ + DisposePtr((Ptr) object); +} + + +/* + * "Large" objects are treated the same as "small" ones. + * NB: we include FAR keywords in the routine declarations simply for + * consistency with the rest of the IJG code; FAR should expand to empty + * on rational architectures like the Mac. + */ + +GLOBAL(void FAR *) +jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) +{ + return (void FAR *) NewPtr(sizeofobject); +} + +GLOBAL(void) +jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) +{ + DisposePtr((Ptr) object); +} + + +/* + * This routine computes the total memory space available for allocation. + */ + +GLOBAL(long) +jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, + long max_bytes_needed, long already_allocated) +{ + long limit = cinfo->mem->max_memory_to_use - already_allocated; + long slop, mem; + + /* Don't ask for more than what application has told us we may use */ + if (max_bytes_needed > limit && limit > 0) + max_bytes_needed = limit; + /* Find whether there's a big enough free block in the heap. + * CompactMem tries to create a contiguous block of the requested size, + * and then returns the size of the largest free block (which could be + * much more or much less than we asked for). + * We add some slop to ensure we don't use up all available memory. + */ + slop = max_bytes_needed / 16 + 32768L; + mem = CompactMem(max_bytes_needed + slop) - slop; + if (mem < 0) + mem = 0; /* sigh, couldn't even get the slop */ + /* Don't take more than the application says we can have */ + if (mem > limit && limit > 0) + mem = limit; + return mem; +} + + +/* + * Backing store (temporary file) management. + * Backing store objects are only used when the value returned by + * jpeg_mem_available is less than the total space needed. You can dispense + * with these routines if you have plenty of virtual memory; see jmemnobs.c. + */ + + +METHODDEF(void) +read_backing_store (j_common_ptr cinfo, backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count) +{ + long bytes = byte_count; + long retVal; + + if ( SetFPos ( info->temp_file, fsFromStart, file_offset ) != noErr ) + ERREXIT(cinfo, JERR_TFILE_SEEK); + + retVal = FSRead ( info->temp_file, &bytes, + (unsigned char *) buffer_address ); + if ( retVal != noErr || bytes != byte_count ) + ERREXIT(cinfo, JERR_TFILE_READ); +} + + +METHODDEF(void) +write_backing_store (j_common_ptr cinfo, backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count) +{ + long bytes = byte_count; + long retVal; + + if ( SetFPos ( info->temp_file, fsFromStart, file_offset ) != noErr ) + ERREXIT(cinfo, JERR_TFILE_SEEK); + + retVal = FSWrite ( info->temp_file, &bytes, + (unsigned char *) buffer_address ); + if ( retVal != noErr || bytes != byte_count ) + ERREXIT(cinfo, JERR_TFILE_WRITE); +} + + +METHODDEF(void) +close_backing_store (j_common_ptr cinfo, backing_store_ptr info) +{ + FSClose ( info->temp_file ); + FSpDelete ( &(info->tempSpec) ); +} + + +/* + * Initial opening of a backing-store object. + * + * This version uses FindFolder to find the Temporary Items folder, + * and puts the temporary file in there. + */ + +GLOBAL(void) +jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, + long total_bytes_needed) +{ + short tmpRef, vRefNum; + long dirID; + FInfo finderInfo; + FSSpec theSpec; + Str255 fName; + OSErr osErr; + long gestaltResponse = 0; + + /* Check that FSSpec calls are available. */ + osErr = Gestalt( gestaltFSAttr, &gestaltResponse ); + if ( ( osErr != noErr ) + || !( gestaltResponse & (1<temp_name, TEMP_FILE_NAME, next_file_num); + strcpy ( (Ptr)fName+1, info->temp_name ); + *fName = strlen (info->temp_name); + osErr = FSMakeFSSpec ( vRefNum, dirID, fName, &theSpec ); + + if ( (osErr = FSpGetFInfo ( &theSpec, &finderInfo ) ) != noErr ) + break; + } + + osErr = FSpCreate ( &theSpec, '????', '????', smSystemScript ); + if ( osErr != noErr ) + ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); + + osErr = FSpOpenDF ( &theSpec, fsRdWrPerm, &(info->temp_file) ); + if ( osErr != noErr ) + ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); + + info->tempSpec = theSpec; + + info->read_backing_store = read_backing_store; + info->write_backing_store = write_backing_store; + info->close_backing_store = close_backing_store; + TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); +} + + +/* + * These routines take care of any system-dependent initialization and + * cleanup required. + */ + +GLOBAL(long) +jpeg_mem_init (j_common_ptr cinfo) +{ + next_file_num = 0; + + /* max_memory_to_use will be initialized to FreeMem()'s result; + * the calling application might later reduce it, for example + * to leave room to invoke multiple JPEG objects. + * Note that FreeMem returns the total number of free bytes; + * it may not be possible to allocate a single block of this size. + */ + return FreeMem(); +} + +GLOBAL(void) +jpeg_mem_term (j_common_ptr cinfo) +{ + /* no work */ +} diff --git a/Source/LibJPEG/jmemname.c b/Source/LibJPEG/jmemname.c index e28b212..ed96dee 100644 --- a/Source/LibJPEG/jmemname.c +++ b/Source/LibJPEG/jmemname.c @@ -1,276 +1,276 @@ -/* - * jmemname.c - * - * Copyright (C) 1992-1997, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file provides a generic implementation of the system-dependent - * portion of the JPEG memory manager. This implementation assumes that - * you must explicitly construct a name for each temp file. - * Also, the problem of determining the amount of memory available - * is shoved onto the user. - */ - -#define JPEG_INTERNALS -#include "jinclude.h" -#include "jpeglib.h" -#include "jmemsys.h" /* import the system-dependent declarations */ - -#ifndef HAVE_STDLIB_H /* should declare malloc(),free() */ -extern void * malloc JPP((size_t size)); -extern void free JPP((void *ptr)); -#endif - -#ifndef SEEK_SET /* pre-ANSI systems may not define this; */ -#define SEEK_SET 0 /* if not, assume 0 is correct */ -#endif - -#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ -#define READ_BINARY "r" -#define RW_BINARY "w+" -#else -#ifdef VMS /* VMS is very nonstandard */ -#define READ_BINARY "rb", "ctx=stm" -#define RW_BINARY "w+b", "ctx=stm" -#else /* standard ANSI-compliant case */ -#define READ_BINARY "rb" -#define RW_BINARY "w+b" -#endif -#endif - - -/* - * Selection of a file name for a temporary file. - * This is system-dependent! - * - * The code as given is suitable for most Unix systems, and it is easily - * modified for most non-Unix systems. Some notes: - * 1. The temp file is created in the directory named by TEMP_DIRECTORY. - * The default value is /usr/tmp, which is the conventional place for - * creating large temp files on Unix. On other systems you'll probably - * want to change the file location. You can do this by editing the - * #define, or (preferred) by defining TEMP_DIRECTORY in jconfig.h. - * - * 2. If you need to change the file name as well as its location, - * you can override the TEMP_FILE_NAME macro. (Note that this is - * actually a printf format string; it must contain %s and %d.) - * Few people should need to do this. - * - * 3. mktemp() is used to ensure that multiple processes running - * simultaneously won't select the same file names. If your system - * doesn't have mktemp(), define NO_MKTEMP to do it the hard way. - * (If you don't have , also define NO_ERRNO_H.) - * - * 4. You probably want to define NEED_SIGNAL_CATCHER so that cjpeg.c/djpeg.c - * will cause the temp files to be removed if you stop the program early. - */ - -#ifndef TEMP_DIRECTORY /* can override from jconfig.h or Makefile */ -#define TEMP_DIRECTORY "/usr/tmp/" /* recommended setting for Unix */ -#endif - -static int next_file_num; /* to distinguish among several temp files */ - -#ifdef NO_MKTEMP - -#ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */ -#define TEMP_FILE_NAME "%sJPG%03d.TMP" -#endif - -#ifndef NO_ERRNO_H -#include /* to define ENOENT */ -#endif - -/* ANSI C specifies that errno is a macro, but on older systems it's more - * likely to be a plain int variable. And not all versions of errno.h - * bother to declare it, so we have to in order to be most portable. Thus: - */ -#ifndef errno -extern int errno; -#endif - - -LOCAL(void) -select_file_name (char * fname) -{ - FILE * tfile; - - /* Keep generating file names till we find one that's not in use */ - for (;;) { - next_file_num++; /* advance counter */ - sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num); - if ((tfile = fopen(fname, READ_BINARY)) == NULL) { - /* fopen could have failed for a reason other than the file not - * being there; for example, file there but unreadable. - * If isn't available, then we cannot test the cause. - */ -#ifdef ENOENT - if (errno != ENOENT) - continue; -#endif - break; - } - fclose(tfile); /* oops, it's there; close tfile & try again */ - } -} - -#else /* ! NO_MKTEMP */ - -/* Note that mktemp() requires the initial filename to end in six X's */ -#ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */ -#define TEMP_FILE_NAME "%sJPG%dXXXXXX" -#endif - -LOCAL(void) -select_file_name (char * fname) -{ - next_file_num++; /* advance counter */ - sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num); - mktemp(fname); /* make sure file name is unique */ - /* mktemp replaces the trailing XXXXXX with a unique string of characters */ -} - -#endif /* NO_MKTEMP */ - - -/* - * Memory allocation and freeing are controlled by the regular library - * routines malloc() and free(). - */ - -GLOBAL(void *) -jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) -{ - return (void *) malloc(sizeofobject); -} - -GLOBAL(void) -jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) -{ - free(object); -} - - -/* - * "Large" objects are treated the same as "small" ones. - * NB: although we include FAR keywords in the routine declarations, - * this file won't actually work in 80x86 small/medium model; at least, - * you probably won't be able to process useful-size images in only 64KB. - */ - -GLOBAL(void FAR *) -jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) -{ - return (void FAR *) malloc(sizeofobject); -} - -GLOBAL(void) -jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) -{ - free(object); -} - - -/* - * This routine computes the total memory space available for allocation. - * It's impossible to do this in a portable way; our current solution is - * to make the user tell us (with a default value set at compile time). - * If you can actually get the available space, it's a good idea to subtract - * a slop factor of 5% or so. - */ - -#ifndef DEFAULT_MAX_MEM /* so can override from makefile */ -#define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */ -#endif - -GLOBAL(long) -jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, - long max_bytes_needed, long already_allocated) -{ - return cinfo->mem->max_memory_to_use - already_allocated; -} - - -/* - * Backing store (temporary file) management. - * Backing store objects are only used when the value returned by - * jpeg_mem_available is less than the total space needed. You can dispense - * with these routines if you have plenty of virtual memory; see jmemnobs.c. - */ - - -METHODDEF(void) -read_backing_store (j_common_ptr cinfo, backing_store_ptr info, - void FAR * buffer_address, - long file_offset, long byte_count) -{ - if (fseek(info->temp_file, file_offset, SEEK_SET)) - ERREXIT(cinfo, JERR_TFILE_SEEK); - if (JFREAD(info->temp_file, buffer_address, byte_count) - != (size_t) byte_count) - ERREXIT(cinfo, JERR_TFILE_READ); -} - - -METHODDEF(void) -write_backing_store (j_common_ptr cinfo, backing_store_ptr info, - void FAR * buffer_address, - long file_offset, long byte_count) -{ - if (fseek(info->temp_file, file_offset, SEEK_SET)) - ERREXIT(cinfo, JERR_TFILE_SEEK); - if (JFWRITE(info->temp_file, buffer_address, byte_count) - != (size_t) byte_count) - ERREXIT(cinfo, JERR_TFILE_WRITE); -} - - -METHODDEF(void) -close_backing_store (j_common_ptr cinfo, backing_store_ptr info) -{ - fclose(info->temp_file); /* close the file */ - unlink(info->temp_name); /* delete the file */ -/* If your system doesn't have unlink(), use remove() instead. - * remove() is the ANSI-standard name for this function, but if - * your system was ANSI you'd be using jmemansi.c, right? - */ - TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name); -} - - -/* - * Initial opening of a backing-store object. - */ - -GLOBAL(void) -jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, - long total_bytes_needed) -{ - select_file_name(info->temp_name); - if ((info->temp_file = fopen(info->temp_name, RW_BINARY)) == NULL) - ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); - info->read_backing_store = read_backing_store; - info->write_backing_store = write_backing_store; - info->close_backing_store = close_backing_store; - TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); -} - - -/* - * These routines take care of any system-dependent initialization and - * cleanup required. - */ - -GLOBAL(long) -jpeg_mem_init (j_common_ptr cinfo) -{ - next_file_num = 0; /* initialize temp file name generator */ - return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ -} - -GLOBAL(void) -jpeg_mem_term (j_common_ptr cinfo) -{ - /* no work */ -} +/* + * jmemname.c + * + * Copyright (C) 1992-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file provides a generic implementation of the system-dependent + * portion of the JPEG memory manager. This implementation assumes that + * you must explicitly construct a name for each temp file. + * Also, the problem of determining the amount of memory available + * is shoved onto the user. + */ + +#define JPEG_INTERNALS +#include "jinclude.h" +#include "jpeglib.h" +#include "jmemsys.h" /* import the system-dependent declarations */ + +#ifndef HAVE_STDLIB_H /* should declare malloc(),free() */ +extern void * malloc JPP((size_t size)); +extern void free JPP((void *ptr)); +#endif + +#ifndef SEEK_SET /* pre-ANSI systems may not define this; */ +#define SEEK_SET 0 /* if not, assume 0 is correct */ +#endif + +#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ +#define READ_BINARY "r" +#define RW_BINARY "w+" +#else +#ifdef VMS /* VMS is very nonstandard */ +#define READ_BINARY "rb", "ctx=stm" +#define RW_BINARY "w+b", "ctx=stm" +#else /* standard ANSI-compliant case */ +#define READ_BINARY "rb" +#define RW_BINARY "w+b" +#endif +#endif + + +/* + * Selection of a file name for a temporary file. + * This is system-dependent! + * + * The code as given is suitable for most Unix systems, and it is easily + * modified for most non-Unix systems. Some notes: + * 1. The temp file is created in the directory named by TEMP_DIRECTORY. + * The default value is /usr/tmp, which is the conventional place for + * creating large temp files on Unix. On other systems you'll probably + * want to change the file location. You can do this by editing the + * #define, or (preferred) by defining TEMP_DIRECTORY in jconfig.h. + * + * 2. If you need to change the file name as well as its location, + * you can override the TEMP_FILE_NAME macro. (Note that this is + * actually a printf format string; it must contain %s and %d.) + * Few people should need to do this. + * + * 3. mktemp() is used to ensure that multiple processes running + * simultaneously won't select the same file names. If your system + * doesn't have mktemp(), define NO_MKTEMP to do it the hard way. + * (If you don't have , also define NO_ERRNO_H.) + * + * 4. You probably want to define NEED_SIGNAL_CATCHER so that cjpeg.c/djpeg.c + * will cause the temp files to be removed if you stop the program early. + */ + +#ifndef TEMP_DIRECTORY /* can override from jconfig.h or Makefile */ +#define TEMP_DIRECTORY "/usr/tmp/" /* recommended setting for Unix */ +#endif + +static int next_file_num; /* to distinguish among several temp files */ + +#ifdef NO_MKTEMP + +#ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */ +#define TEMP_FILE_NAME "%sJPG%03d.TMP" +#endif + +#ifndef NO_ERRNO_H +#include /* to define ENOENT */ +#endif + +/* ANSI C specifies that errno is a macro, but on older systems it's more + * likely to be a plain int variable. And not all versions of errno.h + * bother to declare it, so we have to in order to be most portable. Thus: + */ +#ifndef errno +extern int errno; +#endif + + +LOCAL(void) +select_file_name (char * fname) +{ + FILE * tfile; + + /* Keep generating file names till we find one that's not in use */ + for (;;) { + next_file_num++; /* advance counter */ + sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num); + if ((tfile = fopen(fname, READ_BINARY)) == NULL) { + /* fopen could have failed for a reason other than the file not + * being there; for example, file there but unreadable. + * If isn't available, then we cannot test the cause. + */ +#ifdef ENOENT + if (errno != ENOENT) + continue; +#endif + break; + } + fclose(tfile); /* oops, it's there; close tfile & try again */ + } +} + +#else /* ! NO_MKTEMP */ + +/* Note that mktemp() requires the initial filename to end in six X's */ +#ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */ +#define TEMP_FILE_NAME "%sJPG%dXXXXXX" +#endif + +LOCAL(void) +select_file_name (char * fname) +{ + next_file_num++; /* advance counter */ + sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num); + mktemp(fname); /* make sure file name is unique */ + /* mktemp replaces the trailing XXXXXX with a unique string of characters */ +} + +#endif /* NO_MKTEMP */ + + +/* + * Memory allocation and freeing are controlled by the regular library + * routines malloc() and free(). + */ + +GLOBAL(void *) +jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) +{ + return (void *) malloc(sizeofobject); +} + +GLOBAL(void) +jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) +{ + free(object); +} + + +/* + * "Large" objects are treated the same as "small" ones. + * NB: although we include FAR keywords in the routine declarations, + * this file won't actually work in 80x86 small/medium model; at least, + * you probably won't be able to process useful-size images in only 64KB. + */ + +GLOBAL(void FAR *) +jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) +{ + return (void FAR *) malloc(sizeofobject); +} + +GLOBAL(void) +jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) +{ + free(object); +} + + +/* + * This routine computes the total memory space available for allocation. + * It's impossible to do this in a portable way; our current solution is + * to make the user tell us (with a default value set at compile time). + * If you can actually get the available space, it's a good idea to subtract + * a slop factor of 5% or so. + */ + +#ifndef DEFAULT_MAX_MEM /* so can override from makefile */ +#define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */ +#endif + +GLOBAL(long) +jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, + long max_bytes_needed, long already_allocated) +{ + return cinfo->mem->max_memory_to_use - already_allocated; +} + + +/* + * Backing store (temporary file) management. + * Backing store objects are only used when the value returned by + * jpeg_mem_available is less than the total space needed. You can dispense + * with these routines if you have plenty of virtual memory; see jmemnobs.c. + */ + + +METHODDEF(void) +read_backing_store (j_common_ptr cinfo, backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count) +{ + if (fseek(info->temp_file, file_offset, SEEK_SET)) + ERREXIT(cinfo, JERR_TFILE_SEEK); + if (JFREAD(info->temp_file, buffer_address, byte_count) + != (size_t) byte_count) + ERREXIT(cinfo, JERR_TFILE_READ); +} + + +METHODDEF(void) +write_backing_store (j_common_ptr cinfo, backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count) +{ + if (fseek(info->temp_file, file_offset, SEEK_SET)) + ERREXIT(cinfo, JERR_TFILE_SEEK); + if (JFWRITE(info->temp_file, buffer_address, byte_count) + != (size_t) byte_count) + ERREXIT(cinfo, JERR_TFILE_WRITE); +} + + +METHODDEF(void) +close_backing_store (j_common_ptr cinfo, backing_store_ptr info) +{ + fclose(info->temp_file); /* close the file */ + unlink(info->temp_name); /* delete the file */ +/* If your system doesn't have unlink(), use remove() instead. + * remove() is the ANSI-standard name for this function, but if + * your system was ANSI you'd be using jmemansi.c, right? + */ + TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name); +} + + +/* + * Initial opening of a backing-store object. + */ + +GLOBAL(void) +jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, + long total_bytes_needed) +{ + select_file_name(info->temp_name); + if ((info->temp_file = fopen(info->temp_name, RW_BINARY)) == NULL) + ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); + info->read_backing_store = read_backing_store; + info->write_backing_store = write_backing_store; + info->close_backing_store = close_backing_store; + TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); +} + + +/* + * These routines take care of any system-dependent initialization and + * cleanup required. + */ + +GLOBAL(long) +jpeg_mem_init (j_common_ptr cinfo) +{ + next_file_num = 0; /* initialize temp file name generator */ + return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ +} + +GLOBAL(void) +jpeg_mem_term (j_common_ptr cinfo) +{ + /* no work */ +} diff --git a/Source/LibJPEG/jpegtran.c b/Source/LibJPEG/jpegtran.c index 2193ffe..e539e91 100644 --- a/Source/LibJPEG/jpegtran.c +++ b/Source/LibJPEG/jpegtran.c @@ -1,560 +1,560 @@ -/* - * jpegtran.c - * - * Copyright (C) 1995-2011, Thomas G. Lane, Guido Vollbeding. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains a command-line user interface for JPEG transcoding. - * It is very similar to cjpeg.c, and partly to djpeg.c, but provides - * lossless transcoding between different JPEG file formats. It also - * provides some lossless and sort-of-lossless transformations of JPEG data. - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ -#include "transupp.h" /* Support routines for jpegtran */ -#include "jversion.h" /* for version message */ - -#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ -#ifdef __MWERKS__ -#include /* Metrowerks needs this */ -#include /* ... and this */ -#endif -#ifdef THINK_C -#include /* Think declares it here */ -#endif -#endif - - -/* - * Argument-parsing code. - * The switch parser is designed to be useful with DOS-style command line - * syntax, ie, intermixed switches and file names, where only the switches - * to the left of a given file name affect processing of that file. - * The main program in this file doesn't actually use this capability... - */ - - -static const char * progname; /* program name for error messages */ -static char * outfilename; /* for -outfile switch */ -static char * scaleoption; /* -scale switch */ -static JCOPY_OPTION copyoption; /* -copy switch */ -static jpeg_transform_info transformoption; /* image transformation options */ - - -LOCAL(void) -usage (void) -/* complain about bad command line */ -{ - fprintf(stderr, "usage: %s [switches] ", progname); -#ifdef TWO_FILE_COMMANDLINE - fprintf(stderr, "inputfile outputfile\n"); -#else - fprintf(stderr, "[inputfile]\n"); -#endif - - fprintf(stderr, "Switches (names may be abbreviated):\n"); - fprintf(stderr, " -copy none Copy no extra markers from source file\n"); - fprintf(stderr, " -copy comments Copy only comment markers (default)\n"); - fprintf(stderr, " -copy all Copy all extra markers\n"); -#ifdef ENTROPY_OPT_SUPPORTED - fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n"); -#endif -#ifdef C_PROGRESSIVE_SUPPORTED - fprintf(stderr, " -progressive Create progressive JPEG file\n"); -#endif - fprintf(stderr, "Switches for modifying the image:\n"); -#if TRANSFORMS_SUPPORTED - fprintf(stderr, " -crop WxH+X+Y Crop to a rectangular subarea\n"); - fprintf(stderr, " -grayscale Reduce to grayscale (omit color data)\n"); - fprintf(stderr, " -flip [horizontal|vertical] Mirror image (left-right or top-bottom)\n"); - fprintf(stderr, " -perfect Fail if there is non-transformable edge blocks\n"); - fprintf(stderr, " -rotate [90|180|270] Rotate image (degrees clockwise)\n"); -#endif - fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n"); -#if TRANSFORMS_SUPPORTED - fprintf(stderr, " -transpose Transpose image\n"); - fprintf(stderr, " -transverse Transverse transpose image\n"); - fprintf(stderr, " -trim Drop non-transformable edge blocks\n"); -#endif - fprintf(stderr, "Switches for advanced users:\n"); -#ifdef C_ARITH_CODING_SUPPORTED - fprintf(stderr, " -arithmetic Use arithmetic coding\n"); -#endif - fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n"); - fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); - fprintf(stderr, " -outfile name Specify name for output file\n"); - fprintf(stderr, " -verbose or -debug Emit debug output\n"); - fprintf(stderr, "Switches for wizards:\n"); -#ifdef C_MULTISCAN_FILES_SUPPORTED - fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n"); -#endif - exit(EXIT_FAILURE); -} - - -LOCAL(void) -select_transform (JXFORM_CODE transform) -/* Silly little routine to detect multiple transform options, - * which we can't handle. - */ -{ -#if TRANSFORMS_SUPPORTED - if (transformoption.transform == JXFORM_NONE || - transformoption.transform == transform) { - transformoption.transform = transform; - } else { - fprintf(stderr, "%s: can only do one image transformation at a time\n", - progname); - usage(); - } -#else - fprintf(stderr, "%s: sorry, image transformation was not compiled\n", - progname); - exit(EXIT_FAILURE); -#endif -} - - -LOCAL(int) -parse_switches (j_compress_ptr cinfo, int argc, char **argv, - int last_file_arg_seen, boolean for_real) -/* Parse optional switches. - * Returns argv[] index of first file-name argument (== argc if none). - * Any file names with indexes <= last_file_arg_seen are ignored; - * they have presumably been processed in a previous iteration. - * (Pass 0 for last_file_arg_seen on the first or only iteration.) - * for_real is FALSE on the first (dummy) pass; we may skip any expensive - * processing. - */ -{ - int argn; - char * arg; - boolean simple_progressive; - char * scansarg = NULL; /* saves -scans parm if any */ - - /* Set up default JPEG parameters. */ - simple_progressive = FALSE; - outfilename = NULL; - scaleoption = NULL; - copyoption = JCOPYOPT_DEFAULT; - transformoption.transform = JXFORM_NONE; - transformoption.perfect = FALSE; - transformoption.trim = FALSE; - transformoption.force_grayscale = FALSE; - transformoption.crop = FALSE; - cinfo->err->trace_level = 0; - - /* Scan command line options, adjust parameters */ - - for (argn = 1; argn < argc; argn++) { - arg = argv[argn]; - if (*arg != '-') { - /* Not a switch, must be a file name argument */ - if (argn <= last_file_arg_seen) { - outfilename = NULL; /* -outfile applies to just one input file */ - continue; /* ignore this name if previously processed */ - } - break; /* else done parsing switches */ - } - arg++; /* advance past switch marker character */ - - if (keymatch(arg, "arithmetic", 1)) { - /* Use arithmetic coding. */ -#ifdef C_ARITH_CODING_SUPPORTED - cinfo->arith_code = TRUE; -#else - fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", - progname); - exit(EXIT_FAILURE); -#endif - - } else if (keymatch(arg, "copy", 2)) { - /* Select which extra markers to copy. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - if (keymatch(argv[argn], "none", 1)) { - copyoption = JCOPYOPT_NONE; - } else if (keymatch(argv[argn], "comments", 1)) { - copyoption = JCOPYOPT_COMMENTS; - } else if (keymatch(argv[argn], "all", 1)) { - copyoption = JCOPYOPT_ALL; - } else - usage(); - - } else if (keymatch(arg, "crop", 2)) { - /* Perform lossless cropping. */ -#if TRANSFORMS_SUPPORTED - if (++argn >= argc) /* advance to next argument */ - usage(); - if (! jtransform_parse_crop_spec(&transformoption, argv[argn])) { - fprintf(stderr, "%s: bogus -crop argument '%s'\n", - progname, argv[argn]); - exit(EXIT_FAILURE); - } -#else - select_transform(JXFORM_NONE); /* force an error */ -#endif - - } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { - /* Enable debug printouts. */ - /* On first -d, print version identification */ - static boolean printed_version = FALSE; - - if (! printed_version) { - fprintf(stderr, "Independent JPEG Group's JPEGTRAN, version %s\n%s\n", - JVERSION, JCOPYRIGHT); - printed_version = TRUE; - } - cinfo->err->trace_level++; - - } else if (keymatch(arg, "flip", 1)) { - /* Mirror left-right or top-bottom. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - if (keymatch(argv[argn], "horizontal", 1)) - select_transform(JXFORM_FLIP_H); - else if (keymatch(argv[argn], "vertical", 1)) - select_transform(JXFORM_FLIP_V); - else - usage(); - - } else if (keymatch(arg, "grayscale", 1) || keymatch(arg, "greyscale",1)) { - /* Force to grayscale. */ -#if TRANSFORMS_SUPPORTED - transformoption.force_grayscale = TRUE; -#else - select_transform(JXFORM_NONE); /* force an error */ -#endif - - } else if (keymatch(arg, "maxmemory", 3)) { - /* Maximum memory in Kb (or Mb with 'm'). */ - long lval; - char ch = 'x'; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) - usage(); - if (ch == 'm' || ch == 'M') - lval *= 1000L; - cinfo->mem->max_memory_to_use = lval * 1000L; - - } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { - /* Enable entropy parm optimization. */ -#ifdef ENTROPY_OPT_SUPPORTED - cinfo->optimize_coding = TRUE; -#else - fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n", - progname); - exit(EXIT_FAILURE); -#endif - - } else if (keymatch(arg, "outfile", 4)) { - /* Set output file name. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - outfilename = argv[argn]; /* save it away for later use */ - - } else if (keymatch(arg, "perfect", 2)) { - /* Fail if there is any partial edge MCUs that the transform can't - * handle. */ - transformoption.perfect = TRUE; - - } else if (keymatch(arg, "progressive", 2)) { - /* Select simple progressive mode. */ -#ifdef C_PROGRESSIVE_SUPPORTED - simple_progressive = TRUE; - /* We must postpone execution until num_components is known. */ -#else - fprintf(stderr, "%s: sorry, progressive output was not compiled\n", - progname); - exit(EXIT_FAILURE); -#endif - - } else if (keymatch(arg, "restart", 1)) { - /* Restart interval in MCU rows (or in MCUs with 'b'). */ - long lval; - char ch = 'x'; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) - usage(); - if (lval < 0 || lval > 65535L) - usage(); - if (ch == 'b' || ch == 'B') { - cinfo->restart_interval = (unsigned int) lval; - cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ - } else { - cinfo->restart_in_rows = (int) lval; - /* restart_interval will be computed during startup */ - } - - } else if (keymatch(arg, "rotate", 2)) { - /* Rotate 90, 180, or 270 degrees (measured clockwise). */ - if (++argn >= argc) /* advance to next argument */ - usage(); - if (keymatch(argv[argn], "90", 2)) - select_transform(JXFORM_ROT_90); - else if (keymatch(argv[argn], "180", 3)) - select_transform(JXFORM_ROT_180); - else if (keymatch(argv[argn], "270", 3)) - select_transform(JXFORM_ROT_270); - else - usage(); - - } else if (keymatch(arg, "scale", 4)) { - /* Scale the output image by a fraction M/N. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - scaleoption = argv[argn]; - /* We must postpone processing until decompression startup. */ - - } else if (keymatch(arg, "scans", 1)) { - /* Set scan script. */ -#ifdef C_MULTISCAN_FILES_SUPPORTED - if (++argn >= argc) /* advance to next argument */ - usage(); - scansarg = argv[argn]; - /* We must postpone reading the file in case -progressive appears. */ -#else - fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n", - progname); - exit(EXIT_FAILURE); -#endif - - } else if (keymatch(arg, "transpose", 1)) { - /* Transpose (across UL-to-LR axis). */ - select_transform(JXFORM_TRANSPOSE); - - } else if (keymatch(arg, "transverse", 6)) { - /* Transverse transpose (across UR-to-LL axis). */ - select_transform(JXFORM_TRANSVERSE); - - } else if (keymatch(arg, "trim", 3)) { - /* Trim off any partial edge MCUs that the transform can't handle. */ - transformoption.trim = TRUE; - - } else { - usage(); /* bogus switch */ - } - } - - /* Post-switch-scanning cleanup */ - - if (for_real) { - -#ifdef C_PROGRESSIVE_SUPPORTED - if (simple_progressive) /* process -progressive; -scans can override */ - jpeg_simple_progression(cinfo); -#endif - -#ifdef C_MULTISCAN_FILES_SUPPORTED - if (scansarg != NULL) /* process -scans if it was present */ - if (! read_scan_script(cinfo, scansarg)) - usage(); -#endif - } - - return argn; /* return index of next arg (file name) */ -} - - -/* - * The main program. - */ - -int -main (int argc, char **argv) -{ - struct jpeg_decompress_struct srcinfo; - struct jpeg_compress_struct dstinfo; - struct jpeg_error_mgr jsrcerr, jdsterr; -#ifdef PROGRESS_REPORT - struct cdjpeg_progress_mgr progress; -#endif - jvirt_barray_ptr * src_coef_arrays; - jvirt_barray_ptr * dst_coef_arrays; - int file_index; - /* We assume all-in-memory processing and can therefore use only a - * single file pointer for sequential input and output operation. - */ - FILE * fp; - - /* On Mac, fetch a command line. */ -#ifdef USE_CCOMMAND - argc = ccommand(&argv); -#endif - - progname = argv[0]; - if (progname == NULL || progname[0] == 0) - progname = "jpegtran"; /* in case C library doesn't provide it */ - - /* Initialize the JPEG decompression object with default error handling. */ - srcinfo.err = jpeg_std_error(&jsrcerr); - jpeg_create_decompress(&srcinfo); - /* Initialize the JPEG compression object with default error handling. */ - dstinfo.err = jpeg_std_error(&jdsterr); - jpeg_create_compress(&dstinfo); - - /* Now safe to enable signal catcher. - * Note: we assume only the decompression object will have virtual arrays. - */ -#ifdef NEED_SIGNAL_CATCHER - enable_signal_catcher((j_common_ptr) &srcinfo); -#endif - - /* Scan command line to find file names. - * It is convenient to use just one switch-parsing routine, but the switch - * values read here are mostly ignored; we will rescan the switches after - * opening the input file. Also note that most of the switches affect the - * destination JPEG object, so we parse into that and then copy over what - * needs to affects the source too. - */ - - file_index = parse_switches(&dstinfo, argc, argv, 0, FALSE); - jsrcerr.trace_level = jdsterr.trace_level; - srcinfo.mem->max_memory_to_use = dstinfo.mem->max_memory_to_use; - -#ifdef TWO_FILE_COMMANDLINE - /* Must have either -outfile switch or explicit output file name */ - if (outfilename == NULL) { - if (file_index != argc-2) { - fprintf(stderr, "%s: must name one input and one output file\n", - progname); - usage(); - } - outfilename = argv[file_index+1]; - } else { - if (file_index != argc-1) { - fprintf(stderr, "%s: must name one input and one output file\n", - progname); - usage(); - } - } -#else - /* Unix style: expect zero or one file name */ - if (file_index < argc-1) { - fprintf(stderr, "%s: only one input file\n", progname); - usage(); - } -#endif /* TWO_FILE_COMMANDLINE */ - - /* Open the input file. */ - if (file_index < argc) { - if ((fp = fopen(argv[file_index], READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s for reading\n", progname, argv[file_index]); - exit(EXIT_FAILURE); - } - } else { - /* default input file is stdin */ - fp = read_stdin(); - } - -#ifdef PROGRESS_REPORT - start_progress_monitor((j_common_ptr) &dstinfo, &progress); -#endif - - /* Specify data source for decompression */ - jpeg_stdio_src(&srcinfo, fp); - - /* Enable saving of extra markers that we want to copy */ - jcopy_markers_setup(&srcinfo, copyoption); - - /* Read file header */ - (void) jpeg_read_header(&srcinfo, TRUE); - - /* Adjust default decompression parameters */ - if (scaleoption != NULL) - if (sscanf(scaleoption, "%d/%d", - &srcinfo.scale_num, &srcinfo.scale_denom) < 1) - usage(); - - /* Any space needed by a transform option must be requested before - * jpeg_read_coefficients so that memory allocation will be done right. - */ -#if TRANSFORMS_SUPPORTED - /* Fail right away if -perfect is given and transformation is not perfect. - */ - if (!jtransform_request_workspace(&srcinfo, &transformoption)) { - fprintf(stderr, "%s: transformation is not perfect\n", progname); - exit(EXIT_FAILURE); - } -#endif - - /* Read source file as DCT coefficients */ - src_coef_arrays = jpeg_read_coefficients(&srcinfo); - - /* Initialize destination compression parameters from source values */ - jpeg_copy_critical_parameters(&srcinfo, &dstinfo); - - /* Adjust destination parameters if required by transform options; - * also find out which set of coefficient arrays will hold the output. - */ -#if TRANSFORMS_SUPPORTED - dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo, - src_coef_arrays, - &transformoption); -#else - dst_coef_arrays = src_coef_arrays; -#endif - - /* Close input file, if we opened it. - * Note: we assume that jpeg_read_coefficients consumed all input - * until JPEG_REACHED_EOI, and that jpeg_finish_decompress will - * only consume more while (! cinfo->inputctl->eoi_reached). - * We cannot call jpeg_finish_decompress here since we still need the - * virtual arrays allocated from the source object for processing. - */ - if (fp != stdin) - fclose(fp); - - /* Open the output file. */ - if (outfilename != NULL) { - if ((fp = fopen(outfilename, WRITE_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s for writing\n", progname, outfilename); - exit(EXIT_FAILURE); - } - } else { - /* default output file is stdout */ - fp = write_stdout(); - } - - /* Adjust default compression parameters by re-parsing the options */ - file_index = parse_switches(&dstinfo, argc, argv, 0, TRUE); - - /* Specify data destination for compression */ - jpeg_stdio_dest(&dstinfo, fp); - - /* Start compressor (note no image data is actually written here) */ - jpeg_write_coefficients(&dstinfo, dst_coef_arrays); - - /* Copy to the output file any extra markers that we want to preserve */ - jcopy_markers_execute(&srcinfo, &dstinfo, copyoption); - - /* Execute image transformation, if any */ -#if TRANSFORMS_SUPPORTED - jtransform_execute_transformation(&srcinfo, &dstinfo, - src_coef_arrays, - &transformoption); -#endif - - /* Finish compression and release memory */ - jpeg_finish_compress(&dstinfo); - jpeg_destroy_compress(&dstinfo); - (void) jpeg_finish_decompress(&srcinfo); - jpeg_destroy_decompress(&srcinfo); - - /* Close output file, if we opened it */ - if (fp != stdout) - fclose(fp); - -#ifdef PROGRESS_REPORT - end_progress_monitor((j_common_ptr) &dstinfo); -#endif - - /* All done. */ - exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS); - return 0; /* suppress no-return-value warnings */ -} +/* + * jpegtran.c + * + * Copyright (C) 1995-2011, Thomas G. Lane, Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a command-line user interface for JPEG transcoding. + * It is very similar to cjpeg.c, and partly to djpeg.c, but provides + * lossless transcoding between different JPEG file formats. It also + * provides some lossless and sort-of-lossless transformations of JPEG data. + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ +#include "transupp.h" /* Support routines for jpegtran */ +#include "jversion.h" /* for version message */ + +#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ +#ifdef __MWERKS__ +#include /* Metrowerks needs this */ +#include /* ... and this */ +#endif +#ifdef THINK_C +#include /* Think declares it here */ +#endif +#endif + + +/* + * Argument-parsing code. + * The switch parser is designed to be useful with DOS-style command line + * syntax, ie, intermixed switches and file names, where only the switches + * to the left of a given file name affect processing of that file. + * The main program in this file doesn't actually use this capability... + */ + + +static const char * progname; /* program name for error messages */ +static char * outfilename; /* for -outfile switch */ +static char * scaleoption; /* -scale switch */ +static JCOPY_OPTION copyoption; /* -copy switch */ +static jpeg_transform_info transformoption; /* image transformation options */ + + +LOCAL(void) +usage (void) +/* complain about bad command line */ +{ + fprintf(stderr, "usage: %s [switches] ", progname); +#ifdef TWO_FILE_COMMANDLINE + fprintf(stderr, "inputfile outputfile\n"); +#else + fprintf(stderr, "[inputfile]\n"); +#endif + + fprintf(stderr, "Switches (names may be abbreviated):\n"); + fprintf(stderr, " -copy none Copy no extra markers from source file\n"); + fprintf(stderr, " -copy comments Copy only comment markers (default)\n"); + fprintf(stderr, " -copy all Copy all extra markers\n"); +#ifdef ENTROPY_OPT_SUPPORTED + fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n"); +#endif +#ifdef C_PROGRESSIVE_SUPPORTED + fprintf(stderr, " -progressive Create progressive JPEG file\n"); +#endif + fprintf(stderr, "Switches for modifying the image:\n"); +#if TRANSFORMS_SUPPORTED + fprintf(stderr, " -crop WxH+X+Y Crop to a rectangular subarea\n"); + fprintf(stderr, " -grayscale Reduce to grayscale (omit color data)\n"); + fprintf(stderr, " -flip [horizontal|vertical] Mirror image (left-right or top-bottom)\n"); + fprintf(stderr, " -perfect Fail if there is non-transformable edge blocks\n"); + fprintf(stderr, " -rotate [90|180|270] Rotate image (degrees clockwise)\n"); +#endif + fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n"); +#if TRANSFORMS_SUPPORTED + fprintf(stderr, " -transpose Transpose image\n"); + fprintf(stderr, " -transverse Transverse transpose image\n"); + fprintf(stderr, " -trim Drop non-transformable edge blocks\n"); +#endif + fprintf(stderr, "Switches for advanced users:\n"); +#ifdef C_ARITH_CODING_SUPPORTED + fprintf(stderr, " -arithmetic Use arithmetic coding\n"); +#endif + fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n"); + fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); + fprintf(stderr, " -outfile name Specify name for output file\n"); + fprintf(stderr, " -verbose or -debug Emit debug output\n"); + fprintf(stderr, "Switches for wizards:\n"); +#ifdef C_MULTISCAN_FILES_SUPPORTED + fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n"); +#endif + exit(EXIT_FAILURE); +} + + +LOCAL(void) +select_transform (JXFORM_CODE transform) +/* Silly little routine to detect multiple transform options, + * which we can't handle. + */ +{ +#if TRANSFORMS_SUPPORTED + if (transformoption.transform == JXFORM_NONE || + transformoption.transform == transform) { + transformoption.transform = transform; + } else { + fprintf(stderr, "%s: can only do one image transformation at a time\n", + progname); + usage(); + } +#else + fprintf(stderr, "%s: sorry, image transformation was not compiled\n", + progname); + exit(EXIT_FAILURE); +#endif +} + + +LOCAL(int) +parse_switches (j_compress_ptr cinfo, int argc, char **argv, + int last_file_arg_seen, boolean for_real) +/* Parse optional switches. + * Returns argv[] index of first file-name argument (== argc if none). + * Any file names with indexes <= last_file_arg_seen are ignored; + * they have presumably been processed in a previous iteration. + * (Pass 0 for last_file_arg_seen on the first or only iteration.) + * for_real is FALSE on the first (dummy) pass; we may skip any expensive + * processing. + */ +{ + int argn; + char * arg; + boolean simple_progressive; + char * scansarg = NULL; /* saves -scans parm if any */ + + /* Set up default JPEG parameters. */ + simple_progressive = FALSE; + outfilename = NULL; + scaleoption = NULL; + copyoption = JCOPYOPT_DEFAULT; + transformoption.transform = JXFORM_NONE; + transformoption.perfect = FALSE; + transformoption.trim = FALSE; + transformoption.force_grayscale = FALSE; + transformoption.crop = FALSE; + cinfo->err->trace_level = 0; + + /* Scan command line options, adjust parameters */ + + for (argn = 1; argn < argc; argn++) { + arg = argv[argn]; + if (*arg != '-') { + /* Not a switch, must be a file name argument */ + if (argn <= last_file_arg_seen) { + outfilename = NULL; /* -outfile applies to just one input file */ + continue; /* ignore this name if previously processed */ + } + break; /* else done parsing switches */ + } + arg++; /* advance past switch marker character */ + + if (keymatch(arg, "arithmetic", 1)) { + /* Use arithmetic coding. */ +#ifdef C_ARITH_CODING_SUPPORTED + cinfo->arith_code = TRUE; +#else + fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", + progname); + exit(EXIT_FAILURE); +#endif + + } else if (keymatch(arg, "copy", 2)) { + /* Select which extra markers to copy. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + if (keymatch(argv[argn], "none", 1)) { + copyoption = JCOPYOPT_NONE; + } else if (keymatch(argv[argn], "comments", 1)) { + copyoption = JCOPYOPT_COMMENTS; + } else if (keymatch(argv[argn], "all", 1)) { + copyoption = JCOPYOPT_ALL; + } else + usage(); + + } else if (keymatch(arg, "crop", 2)) { + /* Perform lossless cropping. */ +#if TRANSFORMS_SUPPORTED + if (++argn >= argc) /* advance to next argument */ + usage(); + if (! jtransform_parse_crop_spec(&transformoption, argv[argn])) { + fprintf(stderr, "%s: bogus -crop argument '%s'\n", + progname, argv[argn]); + exit(EXIT_FAILURE); + } +#else + select_transform(JXFORM_NONE); /* force an error */ +#endif + + } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { + /* Enable debug printouts. */ + /* On first -d, print version identification */ + static boolean printed_version = FALSE; + + if (! printed_version) { + fprintf(stderr, "Independent JPEG Group's JPEGTRAN, version %s\n%s\n", + JVERSION, JCOPYRIGHT); + printed_version = TRUE; + } + cinfo->err->trace_level++; + + } else if (keymatch(arg, "flip", 1)) { + /* Mirror left-right or top-bottom. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + if (keymatch(argv[argn], "horizontal", 1)) + select_transform(JXFORM_FLIP_H); + else if (keymatch(argv[argn], "vertical", 1)) + select_transform(JXFORM_FLIP_V); + else + usage(); + + } else if (keymatch(arg, "grayscale", 1) || keymatch(arg, "greyscale",1)) { + /* Force to grayscale. */ +#if TRANSFORMS_SUPPORTED + transformoption.force_grayscale = TRUE; +#else + select_transform(JXFORM_NONE); /* force an error */ +#endif + + } else if (keymatch(arg, "maxmemory", 3)) { + /* Maximum memory in Kb (or Mb with 'm'). */ + long lval; + char ch = 'x'; + + if (++argn >= argc) /* advance to next argument */ + usage(); + if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) + usage(); + if (ch == 'm' || ch == 'M') + lval *= 1000L; + cinfo->mem->max_memory_to_use = lval * 1000L; + + } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { + /* Enable entropy parm optimization. */ +#ifdef ENTROPY_OPT_SUPPORTED + cinfo->optimize_coding = TRUE; +#else + fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n", + progname); + exit(EXIT_FAILURE); +#endif + + } else if (keymatch(arg, "outfile", 4)) { + /* Set output file name. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + outfilename = argv[argn]; /* save it away for later use */ + + } else if (keymatch(arg, "perfect", 2)) { + /* Fail if there is any partial edge MCUs that the transform can't + * handle. */ + transformoption.perfect = TRUE; + + } else if (keymatch(arg, "progressive", 2)) { + /* Select simple progressive mode. */ +#ifdef C_PROGRESSIVE_SUPPORTED + simple_progressive = TRUE; + /* We must postpone execution until num_components is known. */ +#else + fprintf(stderr, "%s: sorry, progressive output was not compiled\n", + progname); + exit(EXIT_FAILURE); +#endif + + } else if (keymatch(arg, "restart", 1)) { + /* Restart interval in MCU rows (or in MCUs with 'b'). */ + long lval; + char ch = 'x'; + + if (++argn >= argc) /* advance to next argument */ + usage(); + if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) + usage(); + if (lval < 0 || lval > 65535L) + usage(); + if (ch == 'b' || ch == 'B') { + cinfo->restart_interval = (unsigned int) lval; + cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ + } else { + cinfo->restart_in_rows = (int) lval; + /* restart_interval will be computed during startup */ + } + + } else if (keymatch(arg, "rotate", 2)) { + /* Rotate 90, 180, or 270 degrees (measured clockwise). */ + if (++argn >= argc) /* advance to next argument */ + usage(); + if (keymatch(argv[argn], "90", 2)) + select_transform(JXFORM_ROT_90); + else if (keymatch(argv[argn], "180", 3)) + select_transform(JXFORM_ROT_180); + else if (keymatch(argv[argn], "270", 3)) + select_transform(JXFORM_ROT_270); + else + usage(); + + } else if (keymatch(arg, "scale", 4)) { + /* Scale the output image by a fraction M/N. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + scaleoption = argv[argn]; + /* We must postpone processing until decompression startup. */ + + } else if (keymatch(arg, "scans", 1)) { + /* Set scan script. */ +#ifdef C_MULTISCAN_FILES_SUPPORTED + if (++argn >= argc) /* advance to next argument */ + usage(); + scansarg = argv[argn]; + /* We must postpone reading the file in case -progressive appears. */ +#else + fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n", + progname); + exit(EXIT_FAILURE); +#endif + + } else if (keymatch(arg, "transpose", 1)) { + /* Transpose (across UL-to-LR axis). */ + select_transform(JXFORM_TRANSPOSE); + + } else if (keymatch(arg, "transverse", 6)) { + /* Transverse transpose (across UR-to-LL axis). */ + select_transform(JXFORM_TRANSVERSE); + + } else if (keymatch(arg, "trim", 3)) { + /* Trim off any partial edge MCUs that the transform can't handle. */ + transformoption.trim = TRUE; + + } else { + usage(); /* bogus switch */ + } + } + + /* Post-switch-scanning cleanup */ + + if (for_real) { + +#ifdef C_PROGRESSIVE_SUPPORTED + if (simple_progressive) /* process -progressive; -scans can override */ + jpeg_simple_progression(cinfo); +#endif + +#ifdef C_MULTISCAN_FILES_SUPPORTED + if (scansarg != NULL) /* process -scans if it was present */ + if (! read_scan_script(cinfo, scansarg)) + usage(); +#endif + } + + return argn; /* return index of next arg (file name) */ +} + + +/* + * The main program. + */ + +int +main (int argc, char **argv) +{ + struct jpeg_decompress_struct srcinfo; + struct jpeg_compress_struct dstinfo; + struct jpeg_error_mgr jsrcerr, jdsterr; +#ifdef PROGRESS_REPORT + struct cdjpeg_progress_mgr progress; +#endif + jvirt_barray_ptr * src_coef_arrays; + jvirt_barray_ptr * dst_coef_arrays; + int file_index; + /* We assume all-in-memory processing and can therefore use only a + * single file pointer for sequential input and output operation. + */ + FILE * fp; + + /* On Mac, fetch a command line. */ +#ifdef USE_CCOMMAND + argc = ccommand(&argv); +#endif + + progname = argv[0]; + if (progname == NULL || progname[0] == 0) + progname = "jpegtran"; /* in case C library doesn't provide it */ + + /* Initialize the JPEG decompression object with default error handling. */ + srcinfo.err = jpeg_std_error(&jsrcerr); + jpeg_create_decompress(&srcinfo); + /* Initialize the JPEG compression object with default error handling. */ + dstinfo.err = jpeg_std_error(&jdsterr); + jpeg_create_compress(&dstinfo); + + /* Now safe to enable signal catcher. + * Note: we assume only the decompression object will have virtual arrays. + */ +#ifdef NEED_SIGNAL_CATCHER + enable_signal_catcher((j_common_ptr) &srcinfo); +#endif + + /* Scan command line to find file names. + * It is convenient to use just one switch-parsing routine, but the switch + * values read here are mostly ignored; we will rescan the switches after + * opening the input file. Also note that most of the switches affect the + * destination JPEG object, so we parse into that and then copy over what + * needs to affects the source too. + */ + + file_index = parse_switches(&dstinfo, argc, argv, 0, FALSE); + jsrcerr.trace_level = jdsterr.trace_level; + srcinfo.mem->max_memory_to_use = dstinfo.mem->max_memory_to_use; + +#ifdef TWO_FILE_COMMANDLINE + /* Must have either -outfile switch or explicit output file name */ + if (outfilename == NULL) { + if (file_index != argc-2) { + fprintf(stderr, "%s: must name one input and one output file\n", + progname); + usage(); + } + outfilename = argv[file_index+1]; + } else { + if (file_index != argc-1) { + fprintf(stderr, "%s: must name one input and one output file\n", + progname); + usage(); + } + } +#else + /* Unix style: expect zero or one file name */ + if (file_index < argc-1) { + fprintf(stderr, "%s: only one input file\n", progname); + usage(); + } +#endif /* TWO_FILE_COMMANDLINE */ + + /* Open the input file. */ + if (file_index < argc) { + if ((fp = fopen(argv[file_index], READ_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open %s for reading\n", progname, argv[file_index]); + exit(EXIT_FAILURE); + } + } else { + /* default input file is stdin */ + fp = read_stdin(); + } + +#ifdef PROGRESS_REPORT + start_progress_monitor((j_common_ptr) &dstinfo, &progress); +#endif + + /* Specify data source for decompression */ + jpeg_stdio_src(&srcinfo, fp); + + /* Enable saving of extra markers that we want to copy */ + jcopy_markers_setup(&srcinfo, copyoption); + + /* Read file header */ + (void) jpeg_read_header(&srcinfo, TRUE); + + /* Adjust default decompression parameters */ + if (scaleoption != NULL) + if (sscanf(scaleoption, "%d/%d", + &srcinfo.scale_num, &srcinfo.scale_denom) < 1) + usage(); + + /* Any space needed by a transform option must be requested before + * jpeg_read_coefficients so that memory allocation will be done right. + */ +#if TRANSFORMS_SUPPORTED + /* Fail right away if -perfect is given and transformation is not perfect. + */ + if (!jtransform_request_workspace(&srcinfo, &transformoption)) { + fprintf(stderr, "%s: transformation is not perfect\n", progname); + exit(EXIT_FAILURE); + } +#endif + + /* Read source file as DCT coefficients */ + src_coef_arrays = jpeg_read_coefficients(&srcinfo); + + /* Initialize destination compression parameters from source values */ + jpeg_copy_critical_parameters(&srcinfo, &dstinfo); + + /* Adjust destination parameters if required by transform options; + * also find out which set of coefficient arrays will hold the output. + */ +#if TRANSFORMS_SUPPORTED + dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo, + src_coef_arrays, + &transformoption); +#else + dst_coef_arrays = src_coef_arrays; +#endif + + /* Close input file, if we opened it. + * Note: we assume that jpeg_read_coefficients consumed all input + * until JPEG_REACHED_EOI, and that jpeg_finish_decompress will + * only consume more while (! cinfo->inputctl->eoi_reached). + * We cannot call jpeg_finish_decompress here since we still need the + * virtual arrays allocated from the source object for processing. + */ + if (fp != stdin) + fclose(fp); + + /* Open the output file. */ + if (outfilename != NULL) { + if ((fp = fopen(outfilename, WRITE_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open %s for writing\n", progname, outfilename); + exit(EXIT_FAILURE); + } + } else { + /* default output file is stdout */ + fp = write_stdout(); + } + + /* Adjust default compression parameters by re-parsing the options */ + file_index = parse_switches(&dstinfo, argc, argv, 0, TRUE); + + /* Specify data destination for compression */ + jpeg_stdio_dest(&dstinfo, fp); + + /* Start compressor (note no image data is actually written here) */ + jpeg_write_coefficients(&dstinfo, dst_coef_arrays); + + /* Copy to the output file any extra markers that we want to preserve */ + jcopy_markers_execute(&srcinfo, &dstinfo, copyoption); + + /* Execute image transformation, if any */ +#if TRANSFORMS_SUPPORTED + jtransform_execute_transformation(&srcinfo, &dstinfo, + src_coef_arrays, + &transformoption); +#endif + + /* Finish compression and release memory */ + jpeg_finish_compress(&dstinfo); + jpeg_destroy_compress(&dstinfo); + (void) jpeg_finish_decompress(&srcinfo); + jpeg_destroy_decompress(&srcinfo); + + /* Close output file, if we opened it */ + if (fp != stdout) + fclose(fp); + +#ifdef PROGRESS_REPORT + end_progress_monitor((j_common_ptr) &dstinfo); +#endif + + /* All done. */ + exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS); + return 0; /* suppress no-return-value warnings */ +} diff --git a/Source/LibJPEG/libjpeg.txt b/Source/LibJPEG/libjpeg.txt index 98394c8..9702669 100644 --- a/Source/LibJPEG/libjpeg.txt +++ b/Source/LibJPEG/libjpeg.txt @@ -1,3085 +1,3085 @@ -USING THE IJG JPEG LIBRARY - -Copyright (C) 1994-2011, Thomas G. Lane, Guido Vollbeding. -This file is part of the Independent JPEG Group's software. -For conditions of distribution and use, see the accompanying README file. - - -This file describes how to use the IJG JPEG library within an application -program. Read it if you want to write a program that uses the library. - -The file example.c provides heavily commented skeleton code for calling the -JPEG library. Also see jpeglib.h (the include file to be used by application -programs) for full details about data structures and function parameter lists. -The library source code, of course, is the ultimate reference. - -Note that there have been *major* changes from the application interface -presented by IJG version 4 and earlier versions. The old design had several -inherent limitations, and it had accumulated a lot of cruft as we added -features while trying to minimize application-interface changes. We have -sacrificed backward compatibility in the version 5 rewrite, but we think the -improvements justify this. - - -TABLE OF CONTENTS ------------------ - -Overview: - Functions provided by the library - Outline of typical usage -Basic library usage: - Data formats - Compression details - Decompression details - Mechanics of usage: include files, linking, etc -Advanced features: - Compression parameter selection - Decompression parameter selection - Special color spaces - Error handling - Compressed data handling (source and destination managers) - I/O suspension - Progressive JPEG support - Buffered-image mode - Abbreviated datastreams and multiple images - Special markers - Raw (downsampled) image data - Really raw data: DCT coefficients - Progress monitoring - Memory management - Memory usage - Library compile-time options - Portability considerations - Notes for MS-DOS implementors - -You should read at least the overview and basic usage sections before trying -to program with the library. The sections on advanced features can be read -if and when you need them. - - -OVERVIEW -======== - -Functions provided by the library ---------------------------------- - -The IJG JPEG library provides C code to read and write JPEG-compressed image -files. The surrounding application program receives or supplies image data a -scanline at a time, using a straightforward uncompressed image format. All -details of color conversion and other preprocessing/postprocessing can be -handled by the library. - -The library includes a substantial amount of code that is not covered by the -JPEG standard but is necessary for typical applications of JPEG. These -functions preprocess the image before JPEG compression or postprocess it after -decompression. They include colorspace conversion, downsampling/upsampling, -and color quantization. The application indirectly selects use of this code -by specifying the format in which it wishes to supply or receive image data. -For example, if colormapped output is requested, then the decompression -library automatically invokes color quantization. - -A wide range of quality vs. speed tradeoffs are possible in JPEG processing, -and even more so in decompression postprocessing. The decompression library -provides multiple implementations that cover most of the useful tradeoffs, -ranging from very-high-quality down to fast-preview operation. On the -compression side we have generally not provided low-quality choices, since -compression is normally less time-critical. It should be understood that the -low-quality modes may not meet the JPEG standard's accuracy requirements; -nonetheless, they are useful for viewers. - -A word about functions *not* provided by the library. We handle a subset of -the ISO JPEG standard; most baseline, extended-sequential, and progressive -JPEG processes are supported. (Our subset includes all features now in common -use.) Unsupported ISO options include: - * Hierarchical storage - * Lossless JPEG - * DNL marker - * Nonintegral subsampling ratios -We support both 8- and 12-bit data precision, but this is a compile-time -choice rather than a run-time choice; hence it is difficult to use both -precisions in a single application. - -By itself, the library handles only interchange JPEG datastreams --- in -particular the widely used JFIF file format. The library can be used by -surrounding code to process interchange or abbreviated JPEG datastreams that -are embedded in more complex file formats. (For example, this library is -used by the free LIBTIFF library to support JPEG compression in TIFF.) - - -Outline of typical usage ------------------------- - -The rough outline of a JPEG compression operation is: - - Allocate and initialize a JPEG compression object - Specify the destination for the compressed data (eg, a file) - Set parameters for compression, including image size & colorspace - jpeg_start_compress(...); - while (scan lines remain to be written) - jpeg_write_scanlines(...); - jpeg_finish_compress(...); - Release the JPEG compression object - -A JPEG compression object holds parameters and working state for the JPEG -library. We make creation/destruction of the object separate from starting -or finishing compression of an image; the same object can be re-used for a -series of image compression operations. This makes it easy to re-use the -same parameter settings for a sequence of images. Re-use of a JPEG object -also has important implications for processing abbreviated JPEG datastreams, -as discussed later. - -The image data to be compressed is supplied to jpeg_write_scanlines() from -in-memory buffers. If the application is doing file-to-file compression, -reading image data from the source file is the application's responsibility. -The library emits compressed data by calling a "data destination manager", -which typically will write the data into a file; but the application can -provide its own destination manager to do something else. - -Similarly, the rough outline of a JPEG decompression operation is: - - Allocate and initialize a JPEG decompression object - Specify the source of the compressed data (eg, a file) - Call jpeg_read_header() to obtain image info - Set parameters for decompression - jpeg_start_decompress(...); - while (scan lines remain to be read) - jpeg_read_scanlines(...); - jpeg_finish_decompress(...); - Release the JPEG decompression object - -This is comparable to the compression outline except that reading the -datastream header is a separate step. This is helpful because information -about the image's size, colorspace, etc is available when the application -selects decompression parameters. For example, the application can choose an -output scaling ratio that will fit the image into the available screen size. - -The decompression library obtains compressed data by calling a data source -manager, which typically will read the data from a file; but other behaviors -can be obtained with a custom source manager. Decompressed data is delivered -into in-memory buffers passed to jpeg_read_scanlines(). - -It is possible to abort an incomplete compression or decompression operation -by calling jpeg_abort(); or, if you do not need to retain the JPEG object, -simply release it by calling jpeg_destroy(). - -JPEG compression and decompression objects are two separate struct types. -However, they share some common fields, and certain routines such as -jpeg_destroy() can work on either type of object. - -The JPEG library has no static variables: all state is in the compression -or decompression object. Therefore it is possible to process multiple -compression and decompression operations concurrently, using multiple JPEG -objects. - -Both compression and decompression can be done in an incremental memory-to- -memory fashion, if suitable source/destination managers are used. See the -section on "I/O suspension" for more details. - - -BASIC LIBRARY USAGE -=================== - -Data formats ------------- - -Before diving into procedural details, it is helpful to understand the -image data format that the JPEG library expects or returns. - -The standard input image format is a rectangular array of pixels, with each -pixel having the same number of "component" or "sample" values (color -channels). You must specify how many components there are and the colorspace -interpretation of the components. Most applications will use RGB data -(three components per pixel) or grayscale data (one component per pixel). -PLEASE NOTE THAT RGB DATA IS THREE SAMPLES PER PIXEL, GRAYSCALE ONLY ONE. -A remarkable number of people manage to miss this, only to find that their -programs don't work with grayscale JPEG files. - -There is no provision for colormapped input. JPEG files are always full-color -or full grayscale (or sometimes another colorspace such as CMYK). You can -feed in a colormapped image by expanding it to full-color format. However -JPEG often doesn't work very well with source data that has been colormapped, -because of dithering noise. This is discussed in more detail in the JPEG FAQ -and the other references mentioned in the README file. - -Pixels are stored by scanlines, with each scanline running from left to -right. The component values for each pixel are adjacent in the row; for -example, R,G,B,R,G,B,R,G,B,... for 24-bit RGB color. Each scanline is an -array of data type JSAMPLE --- which is typically "unsigned char", unless -you've changed jmorecfg.h. (You can also change the RGB pixel layout, say -to B,G,R order, by modifying jmorecfg.h. But see the restrictions listed in -that file before doing so.) - -A 2-D array of pixels is formed by making a list of pointers to the starts of -scanlines; so the scanlines need not be physically adjacent in memory. Even -if you process just one scanline at a time, you must make a one-element -pointer array to conform to this structure. Pointers to JSAMPLE rows are of -type JSAMPROW, and the pointer to the pointer array is of type JSAMPARRAY. - -The library accepts or supplies one or more complete scanlines per call. -It is not possible to process part of a row at a time. Scanlines are always -processed top-to-bottom. You can process an entire image in one call if you -have it all in memory, but usually it's simplest to process one scanline at -a time. - -For best results, source data values should have the precision specified by -BITS_IN_JSAMPLE (normally 8 bits). For instance, if you choose to compress -data that's only 6 bits/channel, you should left-justify each value in a -byte before passing it to the compressor. If you need to compress data -that has more than 8 bits/channel, compile with BITS_IN_JSAMPLE = 12. -(See "Library compile-time options", later.) - - -The data format returned by the decompressor is the same in all details, -except that colormapped output is supported. (Again, a JPEG file is never -colormapped. But you can ask the decompressor to perform on-the-fly color -quantization to deliver colormapped output.) If you request colormapped -output then the returned data array contains a single JSAMPLE per pixel; -its value is an index into a color map. The color map is represented as -a 2-D JSAMPARRAY in which each row holds the values of one color component, -that is, colormap[i][j] is the value of the i'th color component for pixel -value (map index) j. Note that since the colormap indexes are stored in -JSAMPLEs, the maximum number of colors is limited by the size of JSAMPLE -(ie, at most 256 colors for an 8-bit JPEG library). - - -Compression details -------------------- - -Here we revisit the JPEG compression outline given in the overview. - -1. Allocate and initialize a JPEG compression object. - -A JPEG compression object is a "struct jpeg_compress_struct". (It also has -a bunch of subsidiary structures which are allocated via malloc(), but the -application doesn't control those directly.) This struct can be just a local -variable in the calling routine, if a single routine is going to execute the -whole JPEG compression sequence. Otherwise it can be static or allocated -from malloc(). - -You will also need a structure representing a JPEG error handler. The part -of this that the library cares about is a "struct jpeg_error_mgr". If you -are providing your own error handler, you'll typically want to embed the -jpeg_error_mgr struct in a larger structure; this is discussed later under -"Error handling". For now we'll assume you are just using the default error -handler. The default error handler will print JPEG error/warning messages -on stderr, and it will call exit() if a fatal error occurs. - -You must initialize the error handler structure, store a pointer to it into -the JPEG object's "err" field, and then call jpeg_create_compress() to -initialize the rest of the JPEG object. - -Typical code for this step, if you are using the default error handler, is - - struct jpeg_compress_struct cinfo; - struct jpeg_error_mgr jerr; - ... - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_compress(&cinfo); - -jpeg_create_compress allocates a small amount of memory, so it could fail -if you are out of memory. In that case it will exit via the error handler; -that's why the error handler must be initialized first. - - -2. Specify the destination for the compressed data (eg, a file). - -As previously mentioned, the JPEG library delivers compressed data to a -"data destination" module. The library includes one data destination -module which knows how to write to a stdio stream. You can use your own -destination module if you want to do something else, as discussed later. - -If you use the standard destination module, you must open the target stdio -stream beforehand. Typical code for this step looks like: - - FILE * outfile; - ... - if ((outfile = fopen(filename, "wb")) == NULL) { - fprintf(stderr, "can't open %s\n", filename); - exit(1); - } - jpeg_stdio_dest(&cinfo, outfile); - -where the last line invokes the standard destination module. - -WARNING: it is critical that the binary compressed data be delivered to the -output file unchanged. On non-Unix systems the stdio library may perform -newline translation or otherwise corrupt binary data. To suppress this -behavior, you may need to use a "b" option to fopen (as shown above), or use -setmode() or another routine to put the stdio stream in binary mode. See -cjpeg.c and djpeg.c for code that has been found to work on many systems. - -You can select the data destination after setting other parameters (step 3), -if that's more convenient. You may not change the destination between -calling jpeg_start_compress() and jpeg_finish_compress(). - - -3. Set parameters for compression, including image size & colorspace. - -You must supply information about the source image by setting the following -fields in the JPEG object (cinfo structure): - - image_width Width of image, in pixels - image_height Height of image, in pixels - input_components Number of color channels (samples per pixel) - in_color_space Color space of source image - -The image dimensions are, hopefully, obvious. JPEG supports image dimensions -of 1 to 64K pixels in either direction. The input color space is typically -RGB or grayscale, and input_components is 3 or 1 accordingly. (See "Special -color spaces", later, for more info.) The in_color_space field must be -assigned one of the J_COLOR_SPACE enum constants, typically JCS_RGB or -JCS_GRAYSCALE. - -JPEG has a large number of compression parameters that determine how the -image is encoded. Most applications don't need or want to know about all -these parameters. You can set all the parameters to reasonable defaults by -calling jpeg_set_defaults(); then, if there are particular values you want -to change, you can do so after that. The "Compression parameter selection" -section tells about all the parameters. - -You must set in_color_space correctly before calling jpeg_set_defaults(), -because the defaults depend on the source image colorspace. However the -other three source image parameters need not be valid until you call -jpeg_start_compress(). There's no harm in calling jpeg_set_defaults() more -than once, if that happens to be convenient. - -Typical code for a 24-bit RGB source image is - - cinfo.image_width = Width; /* image width and height, in pixels */ - cinfo.image_height = Height; - cinfo.input_components = 3; /* # of color components per pixel */ - cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ - - jpeg_set_defaults(&cinfo); - /* Make optional parameter settings here */ - - -4. jpeg_start_compress(...); - -After you have established the data destination and set all the necessary -source image info and other parameters, call jpeg_start_compress() to begin -a compression cycle. This will initialize internal state, allocate working -storage, and emit the first few bytes of the JPEG datastream header. - -Typical code: - - jpeg_start_compress(&cinfo, TRUE); - -The "TRUE" parameter ensures that a complete JPEG interchange datastream -will be written. This is appropriate in most cases. If you think you might -want to use an abbreviated datastream, read the section on abbreviated -datastreams, below. - -Once you have called jpeg_start_compress(), you may not alter any JPEG -parameters or other fields of the JPEG object until you have completed -the compression cycle. - - -5. while (scan lines remain to be written) - jpeg_write_scanlines(...); - -Now write all the required image data by calling jpeg_write_scanlines() -one or more times. You can pass one or more scanlines in each call, up -to the total image height. In most applications it is convenient to pass -just one or a few scanlines at a time. The expected format for the passed -data is discussed under "Data formats", above. - -Image data should be written in top-to-bottom scanline order. The JPEG spec -contains some weasel wording about how top and bottom are application-defined -terms (a curious interpretation of the English language...) but if you want -your files to be compatible with everyone else's, you WILL use top-to-bottom -order. If the source data must be read in bottom-to-top order, you can use -the JPEG library's virtual array mechanism to invert the data efficiently. -Examples of this can be found in the sample application cjpeg. - -The library maintains a count of the number of scanlines written so far -in the next_scanline field of the JPEG object. Usually you can just use -this variable as the loop counter, so that the loop test looks like -"while (cinfo.next_scanline < cinfo.image_height)". - -Code for this step depends heavily on the way that you store the source data. -example.c shows the following code for the case of a full-size 2-D source -array containing 3-byte RGB pixels: - - JSAMPROW row_pointer[1]; /* pointer to a single row */ - int row_stride; /* physical row width in buffer */ - - row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */ - - while (cinfo.next_scanline < cinfo.image_height) { - row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride]; - jpeg_write_scanlines(&cinfo, row_pointer, 1); - } - -jpeg_write_scanlines() returns the number of scanlines actually written. -This will normally be equal to the number passed in, so you can usually -ignore the return value. It is different in just two cases: - * If you try to write more scanlines than the declared image height, - the additional scanlines are ignored. - * If you use a suspending data destination manager, output buffer overrun - will cause the compressor to return before accepting all the passed lines. - This feature is discussed under "I/O suspension", below. The normal - stdio destination manager will NOT cause this to happen. -In any case, the return value is the same as the change in the value of -next_scanline. - - -6. jpeg_finish_compress(...); - -After all the image data has been written, call jpeg_finish_compress() to -complete the compression cycle. This step is ESSENTIAL to ensure that the -last bufferload of data is written to the data destination. -jpeg_finish_compress() also releases working memory associated with the JPEG -object. - -Typical code: - - jpeg_finish_compress(&cinfo); - -If using the stdio destination manager, don't forget to close the output -stdio stream (if necessary) afterwards. - -If you have requested a multi-pass operating mode, such as Huffman code -optimization, jpeg_finish_compress() will perform the additional passes using -data buffered by the first pass. In this case jpeg_finish_compress() may take -quite a while to complete. With the default compression parameters, this will -not happen. - -It is an error to call jpeg_finish_compress() before writing the necessary -total number of scanlines. If you wish to abort compression, call -jpeg_abort() as discussed below. - -After completing a compression cycle, you may dispose of the JPEG object -as discussed next, or you may use it to compress another image. In that case -return to step 2, 3, or 4 as appropriate. If you do not change the -destination manager, the new datastream will be written to the same target. -If you do not change any JPEG parameters, the new datastream will be written -with the same parameters as before. Note that you can change the input image -dimensions freely between cycles, but if you change the input colorspace, you -should call jpeg_set_defaults() to adjust for the new colorspace; and then -you'll need to repeat all of step 3. - - -7. Release the JPEG compression object. - -When you are done with a JPEG compression object, destroy it by calling -jpeg_destroy_compress(). This will free all subsidiary memory (regardless of -the previous state of the object). Or you can call jpeg_destroy(), which -works for either compression or decompression objects --- this may be more -convenient if you are sharing code between compression and decompression -cases. (Actually, these routines are equivalent except for the declared type -of the passed pointer. To avoid gripes from ANSI C compilers, jpeg_destroy() -should be passed a j_common_ptr.) - -If you allocated the jpeg_compress_struct structure from malloc(), freeing -it is your responsibility --- jpeg_destroy() won't. Ditto for the error -handler structure. - -Typical code: - - jpeg_destroy_compress(&cinfo); - - -8. Aborting. - -If you decide to abort a compression cycle before finishing, you can clean up -in either of two ways: - -* If you don't need the JPEG object any more, just call - jpeg_destroy_compress() or jpeg_destroy() to release memory. This is - legitimate at any point after calling jpeg_create_compress() --- in fact, - it's safe even if jpeg_create_compress() fails. - -* If you want to re-use the JPEG object, call jpeg_abort_compress(), or call - jpeg_abort() which works on both compression and decompression objects. - This will return the object to an idle state, releasing any working memory. - jpeg_abort() is allowed at any time after successful object creation. - -Note that cleaning up the data destination, if required, is your -responsibility; neither of these routines will call term_destination(). -(See "Compressed data handling", below, for more about that.) - -jpeg_destroy() and jpeg_abort() are the only safe calls to make on a JPEG -object that has reported an error by calling error_exit (see "Error handling" -for more info). The internal state of such an object is likely to be out of -whack. Either of these two routines will return the object to a known state. - - -Decompression details ---------------------- - -Here we revisit the JPEG decompression outline given in the overview. - -1. Allocate and initialize a JPEG decompression object. - -This is just like initialization for compression, as discussed above, -except that the object is a "struct jpeg_decompress_struct" and you -call jpeg_create_decompress(). Error handling is exactly the same. - -Typical code: - - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - ... - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress(&cinfo); - -(Both here and in the IJG code, we usually use variable name "cinfo" for -both compression and decompression objects.) - - -2. Specify the source of the compressed data (eg, a file). - -As previously mentioned, the JPEG library reads compressed data from a "data -source" module. The library includes one data source module which knows how -to read from a stdio stream. You can use your own source module if you want -to do something else, as discussed later. - -If you use the standard source module, you must open the source stdio stream -beforehand. Typical code for this step looks like: - - FILE * infile; - ... - if ((infile = fopen(filename, "rb")) == NULL) { - fprintf(stderr, "can't open %s\n", filename); - exit(1); - } - jpeg_stdio_src(&cinfo, infile); - -where the last line invokes the standard source module. - -WARNING: it is critical that the binary compressed data be read unchanged. -On non-Unix systems the stdio library may perform newline translation or -otherwise corrupt binary data. To suppress this behavior, you may need to use -a "b" option to fopen (as shown above), or use setmode() or another routine to -put the stdio stream in binary mode. See cjpeg.c and djpeg.c for code that -has been found to work on many systems. - -You may not change the data source between calling jpeg_read_header() and -jpeg_finish_decompress(). If you wish to read a series of JPEG images from -a single source file, you should repeat the jpeg_read_header() to -jpeg_finish_decompress() sequence without reinitializing either the JPEG -object or the data source module; this prevents buffered input data from -being discarded. - - -3. Call jpeg_read_header() to obtain image info. - -Typical code for this step is just - - jpeg_read_header(&cinfo, TRUE); - -This will read the source datastream header markers, up to the beginning -of the compressed data proper. On return, the image dimensions and other -info have been stored in the JPEG object. The application may wish to -consult this information before selecting decompression parameters. - -More complex code is necessary if - * A suspending data source is used --- in that case jpeg_read_header() - may return before it has read all the header data. See "I/O suspension", - below. The normal stdio source manager will NOT cause this to happen. - * Abbreviated JPEG files are to be processed --- see the section on - abbreviated datastreams. Standard applications that deal only in - interchange JPEG files need not be concerned with this case either. - -It is permissible to stop at this point if you just wanted to find out the -image dimensions and other header info for a JPEG file. In that case, -call jpeg_destroy() when you are done with the JPEG object, or call -jpeg_abort() to return it to an idle state before selecting a new data -source and reading another header. - - -4. Set parameters for decompression. - -jpeg_read_header() sets appropriate default decompression parameters based on -the properties of the image (in particular, its colorspace). However, you -may well want to alter these defaults before beginning the decompression. -For example, the default is to produce full color output from a color file. -If you want colormapped output you must ask for it. Other options allow the -returned image to be scaled and allow various speed/quality tradeoffs to be -selected. "Decompression parameter selection", below, gives details. - -If the defaults are appropriate, nothing need be done at this step. - -Note that all default values are set by each call to jpeg_read_header(). -If you reuse a decompression object, you cannot expect your parameter -settings to be preserved across cycles, as you can for compression. -You must set desired parameter values each time. - - -5. jpeg_start_decompress(...); - -Once the parameter values are satisfactory, call jpeg_start_decompress() to -begin decompression. This will initialize internal state, allocate working -memory, and prepare for returning data. - -Typical code is just - - jpeg_start_decompress(&cinfo); - -If you have requested a multi-pass operating mode, such as 2-pass color -quantization, jpeg_start_decompress() will do everything needed before data -output can begin. In this case jpeg_start_decompress() may take quite a while -to complete. With a single-scan (non progressive) JPEG file and default -decompression parameters, this will not happen; jpeg_start_decompress() will -return quickly. - -After this call, the final output image dimensions, including any requested -scaling, are available in the JPEG object; so is the selected colormap, if -colormapped output has been requested. Useful fields include - - output_width image width and height, as scaled - output_height - out_color_components # of color components in out_color_space - output_components # of color components returned per pixel - colormap the selected colormap, if any - actual_number_of_colors number of entries in colormap - -output_components is 1 (a colormap index) when quantizing colors; otherwise it -equals out_color_components. It is the number of JSAMPLE values that will be -emitted per pixel in the output arrays. - -Typically you will need to allocate data buffers to hold the incoming image. -You will need output_width * output_components JSAMPLEs per scanline in your -output buffer, and a total of output_height scanlines will be returned. - -Note: if you are using the JPEG library's internal memory manager to allocate -data buffers (as djpeg does), then the manager's protocol requires that you -request large buffers *before* calling jpeg_start_decompress(). This is a -little tricky since the output_XXX fields are not normally valid then. You -can make them valid by calling jpeg_calc_output_dimensions() after setting the -relevant parameters (scaling, output color space, and quantization flag). - - -6. while (scan lines remain to be read) - jpeg_read_scanlines(...); - -Now you can read the decompressed image data by calling jpeg_read_scanlines() -one or more times. At each call, you pass in the maximum number of scanlines -to be read (ie, the height of your working buffer); jpeg_read_scanlines() -will return up to that many lines. The return value is the number of lines -actually read. The format of the returned data is discussed under "Data -formats", above. Don't forget that grayscale and color JPEGs will return -different data formats! - -Image data is returned in top-to-bottom scanline order. If you must write -out the image in bottom-to-top order, you can use the JPEG library's virtual -array mechanism to invert the data efficiently. Examples of this can be -found in the sample application djpeg. - -The library maintains a count of the number of scanlines returned so far -in the output_scanline field of the JPEG object. Usually you can just use -this variable as the loop counter, so that the loop test looks like -"while (cinfo.output_scanline < cinfo.output_height)". (Note that the test -should NOT be against image_height, unless you never use scaling. The -image_height field is the height of the original unscaled image.) -The return value always equals the change in the value of output_scanline. - -If you don't use a suspending data source, it is safe to assume that -jpeg_read_scanlines() reads at least one scanline per call, until the -bottom of the image has been reached. - -If you use a buffer larger than one scanline, it is NOT safe to assume that -jpeg_read_scanlines() fills it. (The current implementation returns only a -few scanlines per call, no matter how large a buffer you pass.) So you must -always provide a loop that calls jpeg_read_scanlines() repeatedly until the -whole image has been read. - - -7. jpeg_finish_decompress(...); - -After all the image data has been read, call jpeg_finish_decompress() to -complete the decompression cycle. This causes working memory associated -with the JPEG object to be released. - -Typical code: - - jpeg_finish_decompress(&cinfo); - -If using the stdio source manager, don't forget to close the source stdio -stream if necessary. - -It is an error to call jpeg_finish_decompress() before reading the correct -total number of scanlines. If you wish to abort decompression, call -jpeg_abort() as discussed below. - -After completing a decompression cycle, you may dispose of the JPEG object as -discussed next, or you may use it to decompress another image. In that case -return to step 2 or 3 as appropriate. If you do not change the source -manager, the next image will be read from the same source. - - -8. Release the JPEG decompression object. - -When you are done with a JPEG decompression object, destroy it by calling -jpeg_destroy_decompress() or jpeg_destroy(). The previous discussion of -destroying compression objects applies here too. - -Typical code: - - jpeg_destroy_decompress(&cinfo); - - -9. Aborting. - -You can abort a decompression cycle by calling jpeg_destroy_decompress() or -jpeg_destroy() if you don't need the JPEG object any more, or -jpeg_abort_decompress() or jpeg_abort() if you want to reuse the object. -The previous discussion of aborting compression cycles applies here too. - - -Mechanics of usage: include files, linking, etc ------------------------------------------------ - -Applications using the JPEG library should include the header file jpeglib.h -to obtain declarations of data types and routines. Before including -jpeglib.h, include system headers that define at least the typedefs FILE and -size_t. On ANSI-conforming systems, including is sufficient; on -older Unix systems, you may need to define size_t. - -If the application needs to refer to individual JPEG library error codes, also -include jerror.h to define those symbols. - -jpeglib.h indirectly includes the files jconfig.h and jmorecfg.h. If you are -installing the JPEG header files in a system directory, you will want to -install all four files: jpeglib.h, jerror.h, jconfig.h, jmorecfg.h. - -The most convenient way to include the JPEG code into your executable program -is to prepare a library file ("libjpeg.a", or a corresponding name on non-Unix -machines) and reference it at your link step. If you use only half of the -library (only compression or only decompression), only that much code will be -included from the library, unless your linker is hopelessly brain-damaged. -The supplied makefiles build libjpeg.a automatically (see install.txt). - -While you can build the JPEG library as a shared library if the whim strikes -you, we don't really recommend it. The trouble with shared libraries is that -at some point you'll probably try to substitute a new version of the library -without recompiling the calling applications. That generally doesn't work -because the parameter struct declarations usually change with each new -version. In other words, the library's API is *not* guaranteed binary -compatible across versions; we only try to ensure source-code compatibility. -(In hindsight, it might have been smarter to hide the parameter structs from -applications and introduce a ton of access functions instead. Too late now, -however.) - -On some systems your application may need to set up a signal handler to ensure -that temporary files are deleted if the program is interrupted. This is most -critical if you are on MS-DOS and use the jmemdos.c memory manager back end; -it will try to grab extended memory for temp files, and that space will NOT be -freed automatically. See cjpeg.c or djpeg.c for an example signal handler. - -It may be worth pointing out that the core JPEG library does not actually -require the stdio library: only the default source/destination managers and -error handler need it. You can use the library in a stdio-less environment -if you replace those modules and use jmemnobs.c (or another memory manager of -your own devising). More info about the minimum system library requirements -may be found in jinclude.h. - - -ADVANCED FEATURES -================= - -Compression parameter selection -------------------------------- - -This section describes all the optional parameters you can set for JPEG -compression, as well as the "helper" routines provided to assist in this -task. Proper setting of some parameters requires detailed understanding -of the JPEG standard; if you don't know what a parameter is for, it's best -not to mess with it! See REFERENCES in the README file for pointers to -more info about JPEG. - -It's a good idea to call jpeg_set_defaults() first, even if you plan to set -all the parameters; that way your code is more likely to work with future JPEG -libraries that have additional parameters. For the same reason, we recommend -you use a helper routine where one is provided, in preference to twiddling -cinfo fields directly. - -The helper routines are: - -jpeg_set_defaults (j_compress_ptr cinfo) - This routine sets all JPEG parameters to reasonable defaults, using - only the input image's color space (field in_color_space, which must - already be set in cinfo). Many applications will only need to use - this routine and perhaps jpeg_set_quality(). - -jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace) - Sets the JPEG file's colorspace (field jpeg_color_space) as specified, - and sets other color-space-dependent parameters appropriately. See - "Special color spaces", below, before using this. A large number of - parameters, including all per-component parameters, are set by this - routine; if you want to twiddle individual parameters you should call - jpeg_set_colorspace() before rather than after. - -jpeg_default_colorspace (j_compress_ptr cinfo) - Selects an appropriate JPEG colorspace based on cinfo->in_color_space, - and calls jpeg_set_colorspace(). This is actually a subroutine of - jpeg_set_defaults(). It's broken out in case you want to change - just the colorspace-dependent JPEG parameters. - -jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline) - Constructs JPEG quantization tables appropriate for the indicated - quality setting. The quality value is expressed on the 0..100 scale - recommended by IJG (cjpeg's "-quality" switch uses this routine). - Note that the exact mapping from quality values to tables may change - in future IJG releases as more is learned about DCT quantization. - If the force_baseline parameter is TRUE, then the quantization table - entries are constrained to the range 1..255 for full JPEG baseline - compatibility. In the current implementation, this only makes a - difference for quality settings below 25, and it effectively prevents - very small/low quality files from being generated. The IJG decoder - is capable of reading the non-baseline files generated at low quality - settings when force_baseline is FALSE, but other decoders may not be. - -jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, - boolean force_baseline) - Same as jpeg_set_quality() except that the generated tables are the - sample tables given in the JPEC spec section K.1, multiplied by the - specified scale factor (which is expressed as a percentage; thus - scale_factor = 100 reproduces the spec's tables). Note that larger - scale factors give lower quality. This entry point is useful for - conforming to the Adobe PostScript DCT conventions, but we do not - recommend linear scaling as a user-visible quality scale otherwise. - force_baseline again constrains the computed table entries to 1..255. - -int jpeg_quality_scaling (int quality) - Converts a value on the IJG-recommended quality scale to a linear - scaling percentage. Note that this routine may change or go away - in future releases --- IJG may choose to adopt a scaling method that - can't be expressed as a simple scalar multiplier, in which case the - premise of this routine collapses. Caveat user. - -jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline) - Set default quantization tables with linear q_scale_factor[] values - (see below). - -jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl, - const unsigned int *basic_table, - int scale_factor, boolean force_baseline) - Allows an arbitrary quantization table to be created. which_tbl - indicates which table slot to fill. basic_table points to an array - of 64 unsigned ints given in normal array order. These values are - multiplied by scale_factor/100 and then clamped to the range 1..65535 - (or to 1..255 if force_baseline is TRUE). - CAUTION: prior to library version 6a, jpeg_add_quant_table expected - the basic table to be given in JPEG zigzag order. If you need to - write code that works with either older or newer versions of this - routine, you must check the library version number. Something like - "#if JPEG_LIB_VERSION >= 61" is the right test. - -jpeg_simple_progression (j_compress_ptr cinfo) - Generates a default scan script for writing a progressive-JPEG file. - This is the recommended method of creating a progressive file, - unless you want to make a custom scan sequence. You must ensure that - the JPEG color space is set correctly before calling this routine. - - -Compression parameters (cinfo fields) include: - -int block_size - Set DCT block size. All N from 1 to 16 are possible. - Default is 8 (baseline format). - Larger values produce higher compression, - smaller values produce higher quality. - An exact DCT stage is possible with 1 or 2. - With the default quality of 75 and default Luminance qtable - the DCT+Quantization stage is lossless for value 1. - Note that values other than 8 require a SmartScale capable decoder, - introduced with IJG JPEG 8. Setting the block_size parameter for - compression works with version 8c and later. - -J_DCT_METHOD dct_method - Selects the algorithm used for the DCT step. Choices are: - JDCT_ISLOW: slow but accurate integer algorithm - JDCT_IFAST: faster, less accurate integer method - JDCT_FLOAT: floating-point method - JDCT_DEFAULT: default method (normally JDCT_ISLOW) - JDCT_FASTEST: fastest method (normally JDCT_IFAST) - The FLOAT method is very slightly more accurate than the ISLOW method, - but may give different results on different machines due to varying - roundoff behavior. The integer methods should give the same results - on all machines. On machines with sufficiently fast FP hardware, the - floating-point method may also be the fastest. The IFAST method is - considerably less accurate than the other two; its use is not - recommended if high quality is a concern. JDCT_DEFAULT and - JDCT_FASTEST are macros configurable by each installation. - -unsigned int scale_num, scale_denom - Scale the image by the fraction scale_num/scale_denom. Default is - 1/1, or no scaling. Currently, the supported scaling ratios are - M/N with all N from 1 to 16, where M is the destination DCT size, - which is 8 by default (see block_size parameter above). - (The library design allows for arbitrary scaling ratios but this - is not likely to be implemented any time soon.) - -J_COLOR_SPACE jpeg_color_space -int num_components - The JPEG color space and corresponding number of components; see - "Special color spaces", below, for more info. We recommend using - jpeg_set_color_space() if you want to change these. - -boolean optimize_coding - TRUE causes the compressor to compute optimal Huffman coding tables - for the image. This requires an extra pass over the data and - therefore costs a good deal of space and time. The default is - FALSE, which tells the compressor to use the supplied or default - Huffman tables. In most cases optimal tables save only a few percent - of file size compared to the default tables. Note that when this is - TRUE, you need not supply Huffman tables at all, and any you do - supply will be overwritten. - -unsigned int restart_interval -int restart_in_rows - To emit restart markers in the JPEG file, set one of these nonzero. - Set restart_interval to specify the exact interval in MCU blocks. - Set restart_in_rows to specify the interval in MCU rows. (If - restart_in_rows is not 0, then restart_interval is set after the - image width in MCUs is computed.) Defaults are zero (no restarts). - One restart marker per MCU row is often a good choice. - NOTE: the overhead of restart markers is higher in grayscale JPEG - files than in color files, and MUCH higher in progressive JPEGs. - If you use restarts, you may want to use larger intervals in those - cases. - -const jpeg_scan_info * scan_info -int num_scans - By default, scan_info is NULL; this causes the compressor to write a - single-scan sequential JPEG file. If not NULL, scan_info points to - an array of scan definition records of length num_scans. The - compressor will then write a JPEG file having one scan for each scan - definition record. This is used to generate noninterleaved or - progressive JPEG files. The library checks that the scan array - defines a valid JPEG scan sequence. (jpeg_simple_progression creates - a suitable scan definition array for progressive JPEG.) This is - discussed further under "Progressive JPEG support". - -boolean do_fancy_downsampling - If TRUE, use direct DCT scaling with DCT size > 8 for downsampling - of chroma components. - If FALSE, use only DCT size <= 8 and simple separate downsampling. - Default is TRUE. - For better image stability in multiple generation compression cycles - it is preferable that this value matches the corresponding - do_fancy_upsampling value in decompression. - -int smoothing_factor - If non-zero, the input image is smoothed; the value should be 1 for - minimal smoothing to 100 for maximum smoothing. Consult jcsample.c - for details of the smoothing algorithm. The default is zero. - -boolean write_JFIF_header - If TRUE, a JFIF APP0 marker is emitted. jpeg_set_defaults() and - jpeg_set_colorspace() set this TRUE if a JFIF-legal JPEG color space - (ie, YCbCr or grayscale) is selected, otherwise FALSE. - -UINT8 JFIF_major_version -UINT8 JFIF_minor_version - The version number to be written into the JFIF marker. - jpeg_set_defaults() initializes the version to 1.01 (major=minor=1). - You should set it to 1.02 (major=1, minor=2) if you plan to write - any JFIF 1.02 extension markers. - -UINT8 density_unit -UINT16 X_density -UINT16 Y_density - The resolution information to be written into the JFIF marker; - not used otherwise. density_unit may be 0 for unknown, - 1 for dots/inch, or 2 for dots/cm. The default values are 0,1,1 - indicating square pixels of unknown size. - -boolean write_Adobe_marker - If TRUE, an Adobe APP14 marker is emitted. jpeg_set_defaults() and - jpeg_set_colorspace() set this TRUE if JPEG color space RGB, CMYK, - or YCCK is selected, otherwise FALSE. It is generally a bad idea - to set both write_JFIF_header and write_Adobe_marker. In fact, - you probably shouldn't change the default settings at all --- the - default behavior ensures that the JPEG file's color space can be - recognized by the decoder. - -JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS] - Pointers to coefficient quantization tables, one per table slot, - or NULL if no table is defined for a slot. Usually these should - be set via one of the above helper routines; jpeg_add_quant_table() - is general enough to define any quantization table. The other - routines will set up table slot 0 for luminance quality and table - slot 1 for chrominance. - -int q_scale_factor[NUM_QUANT_TBLS] - Linear quantization scaling factors (percentage, initialized 100) - for use with jpeg_default_qtables(). - See rdswitch.c and cjpeg.c for an example of usage. - Note that the q_scale_factor[] fields are the "linear" scales, so you - have to convert from user-defined ratings via jpeg_quality_scaling(). - Here is an example code which corresponds to cjpeg -quality 90,70: - - jpeg_set_defaults(cinfo); - - /* Set luminance quality 90. */ - cinfo->q_scale_factor[0] = jpeg_quality_scaling(90); - /* Set chrominance quality 70. */ - cinfo->q_scale_factor[1] = jpeg_quality_scaling(70); - - jpeg_default_qtables(cinfo, force_baseline); - - CAUTION: You must also set 1x1 subsampling for efficient separate - color quality selection, since the default value used by library - is 2x2: - - cinfo->comp_info[0].v_samp_factor = 1; - cinfo->comp_info[0].h_samp_factor = 1; - -JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS] -JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS] - Pointers to Huffman coding tables, one per table slot, or NULL if - no table is defined for a slot. Slots 0 and 1 are filled with the - JPEG sample tables by jpeg_set_defaults(). If you need to allocate - more table structures, jpeg_alloc_huff_table() may be used. - Note that optimal Huffman tables can be computed for an image - by setting optimize_coding, as discussed above; there's seldom - any need to mess with providing your own Huffman tables. - - -The actual dimensions of the JPEG image that will be written to the file are -given by the following fields. These are computed from the input image -dimensions and the compression parameters by jpeg_start_compress(). You can -also call jpeg_calc_jpeg_dimensions() to obtain the values that will result -from the current parameter settings. This can be useful if you are trying -to pick a scaling ratio that will get close to a desired target size. - -JDIMENSION jpeg_width Actual dimensions of output image. -JDIMENSION jpeg_height - - -Per-component parameters are stored in the struct cinfo.comp_info[i] for -component number i. Note that components here refer to components of the -JPEG color space, *not* the source image color space. A suitably large -comp_info[] array is allocated by jpeg_set_defaults(); if you choose not -to use that routine, it's up to you to allocate the array. - -int component_id - The one-byte identifier code to be recorded in the JPEG file for - this component. For the standard color spaces, we recommend you - leave the default values alone. - -int h_samp_factor -int v_samp_factor - Horizontal and vertical sampling factors for the component; must - be 1..4 according to the JPEG standard. Note that larger sampling - factors indicate a higher-resolution component; many people find - this behavior quite unintuitive. The default values are 2,2 for - luminance components and 1,1 for chrominance components, except - for grayscale where 1,1 is used. - -int quant_tbl_no - Quantization table number for component. The default value is - 0 for luminance components and 1 for chrominance components. - -int dc_tbl_no -int ac_tbl_no - DC and AC entropy coding table numbers. The default values are - 0 for luminance components and 1 for chrominance components. - -int component_index - Must equal the component's index in comp_info[]. (Beginning in - release v6, the compressor library will fill this in automatically; - you don't have to.) - - -Decompression parameter selection ---------------------------------- - -Decompression parameter selection is somewhat simpler than compression -parameter selection, since all of the JPEG internal parameters are -recorded in the source file and need not be supplied by the application. -(Unless you are working with abbreviated files, in which case see -"Abbreviated datastreams", below.) Decompression parameters control -the postprocessing done on the image to deliver it in a format suitable -for the application's use. Many of the parameters control speed/quality -tradeoffs, in which faster decompression may be obtained at the price of -a poorer-quality image. The defaults select the highest quality (slowest) -processing. - -The following fields in the JPEG object are set by jpeg_read_header() and -may be useful to the application in choosing decompression parameters: - -JDIMENSION image_width Width and height of image -JDIMENSION image_height -int num_components Number of color components -J_COLOR_SPACE jpeg_color_space Colorspace of image -boolean saw_JFIF_marker TRUE if a JFIF APP0 marker was seen - UINT8 JFIF_major_version Version information from JFIF marker - UINT8 JFIF_minor_version - UINT8 density_unit Resolution data from JFIF marker - UINT16 X_density - UINT16 Y_density -boolean saw_Adobe_marker TRUE if an Adobe APP14 marker was seen - UINT8 Adobe_transform Color transform code from Adobe marker - -The JPEG color space, unfortunately, is something of a guess since the JPEG -standard proper does not provide a way to record it. In practice most files -adhere to the JFIF or Adobe conventions, and the decoder will recognize these -correctly. See "Special color spaces", below, for more info. - - -The decompression parameters that determine the basic properties of the -returned image are: - -J_COLOR_SPACE out_color_space - Output color space. jpeg_read_header() sets an appropriate default - based on jpeg_color_space; typically it will be RGB or grayscale. - The application can change this field to request output in a different - colorspace. For example, set it to JCS_GRAYSCALE to get grayscale - output from a color file. (This is useful for previewing: grayscale - output is faster than full color since the color components need not - be processed.) Note that not all possible color space transforms are - currently implemented; you may need to extend jdcolor.c if you want an - unusual conversion. - -unsigned int scale_num, scale_denom - Scale the image by the fraction scale_num/scale_denom. Currently, - the supported scaling ratios are M/N with all M from 1 to 16, where - N is the source DCT size, which is 8 for baseline JPEG. (The library - design allows for arbitrary scaling ratios but this is not likely - to be implemented any time soon.) The values are initialized by - jpeg_read_header() with the source DCT size. For baseline JPEG - this is 8/8. If you change only the scale_num value while leaving - the other unchanged, then this specifies the DCT scaled size to be - applied on the given input. For baseline JPEG this is equivalent - to M/8 scaling, since the source DCT size for baseline JPEG is 8. - Smaller scaling ratios permit significantly faster decoding since - fewer pixels need be processed and a simpler IDCT method can be used. - -boolean quantize_colors - If set TRUE, colormapped output will be delivered. Default is FALSE, - meaning that full-color output will be delivered. - -The next three parameters are relevant only if quantize_colors is TRUE. - -int desired_number_of_colors - Maximum number of colors to use in generating a library-supplied color - map (the actual number of colors is returned in a different field). - Default 256. Ignored when the application supplies its own color map. - -boolean two_pass_quantize - If TRUE, an extra pass over the image is made to select a custom color - map for the image. This usually looks a lot better than the one-size- - fits-all colormap that is used otherwise. Default is TRUE. Ignored - when the application supplies its own color map. - -J_DITHER_MODE dither_mode - Selects color dithering method. Supported values are: - JDITHER_NONE no dithering: fast, very low quality - JDITHER_ORDERED ordered dither: moderate speed and quality - JDITHER_FS Floyd-Steinberg dither: slow, high quality - Default is JDITHER_FS. (At present, ordered dither is implemented - only in the single-pass, standard-colormap case. If you ask for - ordered dither when two_pass_quantize is TRUE or when you supply - an external color map, you'll get F-S dithering.) - -When quantize_colors is TRUE, the target color map is described by the next -two fields. colormap is set to NULL by jpeg_read_header(). The application -can supply a color map by setting colormap non-NULL and setting -actual_number_of_colors to the map size. Otherwise, jpeg_start_decompress() -selects a suitable color map and sets these two fields itself. -[Implementation restriction: at present, an externally supplied colormap is -only accepted for 3-component output color spaces.] - -JSAMPARRAY colormap - The color map, represented as a 2-D pixel array of out_color_components - rows and actual_number_of_colors columns. Ignored if not quantizing. - CAUTION: if the JPEG library creates its own colormap, the storage - pointed to by this field is released by jpeg_finish_decompress(). - Copy the colormap somewhere else first, if you want to save it. - -int actual_number_of_colors - The number of colors in the color map. - -Additional decompression parameters that the application may set include: - -J_DCT_METHOD dct_method - Selects the algorithm used for the DCT step. Choices are the same - as described above for compression. - -boolean do_fancy_upsampling - If TRUE, use direct DCT scaling with DCT size > 8 for upsampling - of chroma components. - If FALSE, use only DCT size <= 8 and simple separate upsampling. - Default is TRUE. - For better image stability in multiple generation compression cycles - it is preferable that this value matches the corresponding - do_fancy_downsampling value in compression. - -boolean do_block_smoothing - If TRUE, interblock smoothing is applied in early stages of decoding - progressive JPEG files; if FALSE, not. Default is TRUE. Early - progression stages look "fuzzy" with smoothing, "blocky" without. - In any case, block smoothing ceases to be applied after the first few - AC coefficients are known to full accuracy, so it is relevant only - when using buffered-image mode for progressive images. - -boolean enable_1pass_quant -boolean enable_external_quant -boolean enable_2pass_quant - These are significant only in buffered-image mode, which is - described in its own section below. - - -The output image dimensions are given by the following fields. These are -computed from the source image dimensions and the decompression parameters -by jpeg_start_decompress(). You can also call jpeg_calc_output_dimensions() -to obtain the values that will result from the current parameter settings. -This can be useful if you are trying to pick a scaling ratio that will get -close to a desired target size. It's also important if you are using the -JPEG library's memory manager to allocate output buffer space, because you -are supposed to request such buffers *before* jpeg_start_decompress(). - -JDIMENSION output_width Actual dimensions of output image. -JDIMENSION output_height -int out_color_components Number of color components in out_color_space. -int output_components Number of color components returned. -int rec_outbuf_height Recommended height of scanline buffer. - -When quantizing colors, output_components is 1, indicating a single color map -index per pixel. Otherwise it equals out_color_components. The output arrays -are required to be output_width * output_components JSAMPLEs wide. - -rec_outbuf_height is the recommended minimum height (in scanlines) of the -buffer passed to jpeg_read_scanlines(). If the buffer is smaller, the -library will still work, but time will be wasted due to unnecessary data -copying. In high-quality modes, rec_outbuf_height is always 1, but some -faster, lower-quality modes set it to larger values (typically 2 to 4). -If you are going to ask for a high-speed processing mode, you may as well -go to the trouble of honoring rec_outbuf_height so as to avoid data copying. -(An output buffer larger than rec_outbuf_height lines is OK, but won't -provide any material speed improvement over that height.) - - -Special color spaces --------------------- - -The JPEG standard itself is "color blind" and doesn't specify any particular -color space. It is customary to convert color data to a luminance/chrominance -color space before compressing, since this permits greater compression. The -existing de-facto JPEG file format standards specify YCbCr or grayscale data -(JFIF), or grayscale, RGB, YCbCr, CMYK, or YCCK (Adobe). For special -applications such as multispectral images, other color spaces can be used, -but it must be understood that such files will be unportable. - -The JPEG library can handle the most common colorspace conversions (namely -RGB <=> YCbCr and CMYK <=> YCCK). It can also deal with data of an unknown -color space, passing it through without conversion. If you deal extensively -with an unusual color space, you can easily extend the library to understand -additional color spaces and perform appropriate conversions. - -For compression, the source data's color space is specified by field -in_color_space. This is transformed to the JPEG file's color space given -by jpeg_color_space. jpeg_set_defaults() chooses a reasonable JPEG color -space depending on in_color_space, but you can override this by calling -jpeg_set_colorspace(). Of course you must select a supported transformation. -jccolor.c currently supports the following transformations: - RGB => YCbCr - RGB => GRAYSCALE - YCbCr => GRAYSCALE - CMYK => YCCK -plus the null transforms: GRAYSCALE => GRAYSCALE, RGB => RGB, -YCbCr => YCbCr, CMYK => CMYK, YCCK => YCCK, and UNKNOWN => UNKNOWN. - -The de-facto file format standards (JFIF and Adobe) specify APPn markers that -indicate the color space of the JPEG file. It is important to ensure that -these are written correctly, or omitted if the JPEG file's color space is not -one of the ones supported by the de-facto standards. jpeg_set_colorspace() -will set the compression parameters to include or omit the APPn markers -properly, so long as it is told the truth about the JPEG color space. -For example, if you are writing some random 3-component color space without -conversion, don't try to fake out the library by setting in_color_space and -jpeg_color_space to JCS_YCbCr; use JCS_UNKNOWN. You may want to write an -APPn marker of your own devising to identify the colorspace --- see "Special -markers", below. - -When told that the color space is UNKNOWN, the library will default to using -luminance-quality compression parameters for all color components. You may -well want to change these parameters. See the source code for -jpeg_set_colorspace(), in jcparam.c, for details. - -For decompression, the JPEG file's color space is given in jpeg_color_space, -and this is transformed to the output color space out_color_space. -jpeg_read_header's setting of jpeg_color_space can be relied on if the file -conforms to JFIF or Adobe conventions, but otherwise it is no better than a -guess. If you know the JPEG file's color space for certain, you can override -jpeg_read_header's guess by setting jpeg_color_space. jpeg_read_header also -selects a default output color space based on (its guess of) jpeg_color_space; -set out_color_space to override this. Again, you must select a supported -transformation. jdcolor.c currently supports - YCbCr => RGB - YCbCr => GRAYSCALE - RGB => GRAYSCALE - GRAYSCALE => RGB - YCCK => CMYK -as well as the null transforms. (Since GRAYSCALE=>RGB is provided, an -application can force grayscale JPEGs to look like color JPEGs if it only -wants to handle one case.) - -The two-pass color quantizer, jquant2.c, is specialized to handle RGB data -(it weights distances appropriately for RGB colors). You'll need to modify -the code if you want to use it for non-RGB output color spaces. Note that -jquant2.c is used to map to an application-supplied colormap as well as for -the normal two-pass colormap selection process. - -CAUTION: it appears that Adobe Photoshop writes inverted data in CMYK JPEG -files: 0 represents 100% ink coverage, rather than 0% ink as you'd expect. -This is arguably a bug in Photoshop, but if you need to work with Photoshop -CMYK files, you will have to deal with it in your application. We cannot -"fix" this in the library by inverting the data during the CMYK<=>YCCK -transform, because that would break other applications, notably Ghostscript. -Photoshop versions prior to 3.0 write EPS files containing JPEG-encoded CMYK -data in the same inverted-YCCK representation used in bare JPEG files, but -the surrounding PostScript code performs an inversion using the PS image -operator. I am told that Photoshop 3.0 will write uninverted YCCK in -EPS/JPEG files, and will omit the PS-level inversion. (But the data -polarity used in bare JPEG files will not change in 3.0.) In either case, -the JPEG library must not invert the data itself, or else Ghostscript would -read these EPS files incorrectly. - - -Error handling --------------- - -When the default error handler is used, any error detected inside the JPEG -routines will cause a message to be printed on stderr, followed by exit(). -You can supply your own error handling routines to override this behavior -and to control the treatment of nonfatal warnings and trace/debug messages. -The file example.c illustrates the most common case, which is to have the -application regain control after an error rather than exiting. - -The JPEG library never writes any message directly; it always goes through -the error handling routines. Three classes of messages are recognized: - * Fatal errors: the library cannot continue. - * Warnings: the library can continue, but the data is corrupt, and a - damaged output image is likely to result. - * Trace/informational messages. These come with a trace level indicating - the importance of the message; you can control the verbosity of the - program by adjusting the maximum trace level that will be displayed. - -You may, if you wish, simply replace the entire JPEG error handling module -(jerror.c) with your own code. However, you can avoid code duplication by -only replacing some of the routines depending on the behavior you need. -This is accomplished by calling jpeg_std_error() as usual, but then overriding -some of the method pointers in the jpeg_error_mgr struct, as illustrated by -example.c. - -All of the error handling routines will receive a pointer to the JPEG object -(a j_common_ptr which points to either a jpeg_compress_struct or a -jpeg_decompress_struct; if you need to tell which, test the is_decompressor -field). This struct includes a pointer to the error manager struct in its -"err" field. Frequently, custom error handler routines will need to access -additional data which is not known to the JPEG library or the standard error -handler. The most convenient way to do this is to embed either the JPEG -object or the jpeg_error_mgr struct in a larger structure that contains -additional fields; then casting the passed pointer provides access to the -additional fields. Again, see example.c for one way to do it. (Beginning -with IJG version 6b, there is also a void pointer "client_data" in each -JPEG object, which the application can also use to find related data. -The library does not touch client_data at all.) - -The individual methods that you might wish to override are: - -error_exit (j_common_ptr cinfo) - Receives control for a fatal error. Information sufficient to - generate the error message has been stored in cinfo->err; call - output_message to display it. Control must NOT return to the caller; - generally this routine will exit() or longjmp() somewhere. - Typically you would override this routine to get rid of the exit() - default behavior. Note that if you continue processing, you should - clean up the JPEG object with jpeg_abort() or jpeg_destroy(). - -output_message (j_common_ptr cinfo) - Actual output of any JPEG message. Override this to send messages - somewhere other than stderr. Note that this method does not know - how to generate a message, only where to send it. - -format_message (j_common_ptr cinfo, char * buffer) - Constructs a readable error message string based on the error info - stored in cinfo->err. This method is called by output_message. Few - applications should need to override this method. One possible - reason for doing so is to implement dynamic switching of error message - language. - -emit_message (j_common_ptr cinfo, int msg_level) - Decide whether or not to emit a warning or trace message; if so, - calls output_message. The main reason for overriding this method - would be to abort on warnings. msg_level is -1 for warnings, - 0 and up for trace messages. - -Only error_exit() and emit_message() are called from the rest of the JPEG -library; the other two are internal to the error handler. - -The actual message texts are stored in an array of strings which is pointed to -by the field err->jpeg_message_table. The messages are numbered from 0 to -err->last_jpeg_message, and it is these code numbers that are used in the -JPEG library code. You could replace the message texts (for instance, with -messages in French or German) by changing the message table pointer. See -jerror.h for the default texts. CAUTION: this table will almost certainly -change or grow from one library version to the next. - -It may be useful for an application to add its own message texts that are -handled by the same mechanism. The error handler supports a second "add-on" -message table for this purpose. To define an addon table, set the pointer -err->addon_message_table and the message numbers err->first_addon_message and -err->last_addon_message. If you number the addon messages beginning at 1000 -or so, you won't have to worry about conflicts with the library's built-in -messages. See the sample applications cjpeg/djpeg for an example of using -addon messages (the addon messages are defined in cderror.h). - -Actual invocation of the error handler is done via macros defined in jerror.h: - ERREXITn(...) for fatal errors - WARNMSn(...) for corrupt-data warnings - TRACEMSn(...) for trace and informational messages. -These macros store the message code and any additional parameters into the -error handler struct, then invoke the error_exit() or emit_message() method. -The variants of each macro are for varying numbers of additional parameters. -The additional parameters are inserted into the generated message using -standard printf() format codes. - -See jerror.h and jerror.c for further details. - - -Compressed data handling (source and destination managers) ----------------------------------------------------------- - -The JPEG compression library sends its compressed data to a "destination -manager" module. The default destination manager just writes the data to a -memory buffer or to a stdio stream, but you can provide your own manager to -do something else. Similarly, the decompression library calls a "source -manager" to obtain the compressed data; you can provide your own source -manager if you want the data to come from somewhere other than a memory -buffer or a stdio stream. - -In both cases, compressed data is processed a bufferload at a time: the -destination or source manager provides a work buffer, and the library invokes -the manager only when the buffer is filled or emptied. (You could define a -one-character buffer to force the manager to be invoked for each byte, but -that would be rather inefficient.) The buffer's size and location are -controlled by the manager, not by the library. For example, the memory -source manager just makes the buffer pointer and length point to the original -data in memory. In this case the buffer-reload procedure will be invoked -only if the decompressor ran off the end of the datastream, which would -indicate an erroneous datastream. - -The work buffer is defined as an array of datatype JOCTET, which is generally -"char" or "unsigned char". On a machine where char is not exactly 8 bits -wide, you must define JOCTET as a wider data type and then modify the data -source and destination modules to transcribe the work arrays into 8-bit units -on external storage. - -A data destination manager struct contains a pointer and count defining the -next byte to write in the work buffer and the remaining free space: - - JOCTET * next_output_byte; /* => next byte to write in buffer */ - size_t free_in_buffer; /* # of byte spaces remaining in buffer */ - -The library increments the pointer and decrements the count until the buffer -is filled. The manager's empty_output_buffer method must reset the pointer -and count. The manager is expected to remember the buffer's starting address -and total size in private fields not visible to the library. - -A data destination manager provides three methods: - -init_destination (j_compress_ptr cinfo) - Initialize destination. This is called by jpeg_start_compress() - before any data is actually written. It must initialize - next_output_byte and free_in_buffer. free_in_buffer must be - initialized to a positive value. - -empty_output_buffer (j_compress_ptr cinfo) - This is called whenever the buffer has filled (free_in_buffer - reaches zero). In typical applications, it should write out the - *entire* buffer (use the saved start address and buffer length; - ignore the current state of next_output_byte and free_in_buffer). - Then reset the pointer & count to the start of the buffer, and - return TRUE indicating that the buffer has been dumped. - free_in_buffer must be set to a positive value when TRUE is - returned. A FALSE return should only be used when I/O suspension is - desired (this operating mode is discussed in the next section). - -term_destination (j_compress_ptr cinfo) - Terminate destination --- called by jpeg_finish_compress() after all - data has been written. In most applications, this must flush any - data remaining in the buffer. Use either next_output_byte or - free_in_buffer to determine how much data is in the buffer. - -term_destination() is NOT called by jpeg_abort() or jpeg_destroy(). If you -want the destination manager to be cleaned up during an abort, you must do it -yourself. - -You will also need code to create a jpeg_destination_mgr struct, fill in its -method pointers, and insert a pointer to the struct into the "dest" field of -the JPEG compression object. This can be done in-line in your setup code if -you like, but it's probably cleaner to provide a separate routine similar to -the jpeg_stdio_dest() or jpeg_mem_dest() routines of the supplied destination -managers. - -Decompression source managers follow a parallel design, but with some -additional frammishes. The source manager struct contains a pointer and count -defining the next byte to read from the work buffer and the number of bytes -remaining: - - const JOCTET * next_input_byte; /* => next byte to read from buffer */ - size_t bytes_in_buffer; /* # of bytes remaining in buffer */ - -The library increments the pointer and decrements the count until the buffer -is emptied. The manager's fill_input_buffer method must reset the pointer and -count. In most applications, the manager must remember the buffer's starting -address and total size in private fields not visible to the library. - -A data source manager provides five methods: - -init_source (j_decompress_ptr cinfo) - Initialize source. This is called by jpeg_read_header() before any - data is actually read. Unlike init_destination(), it may leave - bytes_in_buffer set to 0 (in which case a fill_input_buffer() call - will occur immediately). - -fill_input_buffer (j_decompress_ptr cinfo) - This is called whenever bytes_in_buffer has reached zero and more - data is wanted. In typical applications, it should read fresh data - into the buffer (ignoring the current state of next_input_byte and - bytes_in_buffer), reset the pointer & count to the start of the - buffer, and return TRUE indicating that the buffer has been reloaded. - It is not necessary to fill the buffer entirely, only to obtain at - least one more byte. bytes_in_buffer MUST be set to a positive value - if TRUE is returned. A FALSE return should only be used when I/O - suspension is desired (this mode is discussed in the next section). - -skip_input_data (j_decompress_ptr cinfo, long num_bytes) - Skip num_bytes worth of data. The buffer pointer and count should - be advanced over num_bytes input bytes, refilling the buffer as - needed. This is used to skip over a potentially large amount of - uninteresting data (such as an APPn marker). In some applications - it may be possible to optimize away the reading of the skipped data, - but it's not clear that being smart is worth much trouble; large - skips are uncommon. bytes_in_buffer may be zero on return. - A zero or negative skip count should be treated as a no-op. - -resync_to_restart (j_decompress_ptr cinfo, int desired) - This routine is called only when the decompressor has failed to find - a restart (RSTn) marker where one is expected. Its mission is to - find a suitable point for resuming decompression. For most - applications, we recommend that you just use the default resync - procedure, jpeg_resync_to_restart(). However, if you are able to back - up in the input data stream, or if you have a-priori knowledge about - the likely location of restart markers, you may be able to do better. - Read the read_restart_marker() and jpeg_resync_to_restart() routines - in jdmarker.c if you think you'd like to implement your own resync - procedure. - -term_source (j_decompress_ptr cinfo) - Terminate source --- called by jpeg_finish_decompress() after all - data has been read. Often a no-op. - -For both fill_input_buffer() and skip_input_data(), there is no such thing -as an EOF return. If the end of the file has been reached, the routine has -a choice of exiting via ERREXIT() or inserting fake data into the buffer. -In most cases, generating a warning message and inserting a fake EOI marker -is the best course of action --- this will allow the decompressor to output -however much of the image is there. In pathological cases, the decompressor -may swallow the EOI and again demand data ... just keep feeding it fake EOIs. -jdatasrc.c illustrates the recommended error recovery behavior. - -term_source() is NOT called by jpeg_abort() or jpeg_destroy(). If you want -the source manager to be cleaned up during an abort, you must do it yourself. - -You will also need code to create a jpeg_source_mgr struct, fill in its method -pointers, and insert a pointer to the struct into the "src" field of the JPEG -decompression object. This can be done in-line in your setup code if you -like, but it's probably cleaner to provide a separate routine similar to the -jpeg_stdio_src() or jpeg_mem_src() routines of the supplied source managers. - -For more information, consult the memory and stdio source and destination -managers in jdatasrc.c and jdatadst.c. - - -I/O suspension --------------- - -Some applications need to use the JPEG library as an incremental memory-to- -memory filter: when the compressed data buffer is filled or emptied, they want -control to return to the outer loop, rather than expecting that the buffer can -be emptied or reloaded within the data source/destination manager subroutine. -The library supports this need by providing an "I/O suspension" mode, which we -describe in this section. - -The I/O suspension mode is not a panacea: nothing is guaranteed about the -maximum amount of time spent in any one call to the library, so it will not -eliminate response-time problems in single-threaded applications. If you -need guaranteed response time, we suggest you "bite the bullet" and implement -a real multi-tasking capability. - -To use I/O suspension, cooperation is needed between the calling application -and the data source or destination manager; you will always need a custom -source/destination manager. (Please read the previous section if you haven't -already.) The basic idea is that the empty_output_buffer() or -fill_input_buffer() routine is a no-op, merely returning FALSE to indicate -that it has done nothing. Upon seeing this, the JPEG library suspends -operation and returns to its caller. The surrounding application is -responsible for emptying or refilling the work buffer before calling the -JPEG library again. - -Compression suspension: - -For compression suspension, use an empty_output_buffer() routine that returns -FALSE; typically it will not do anything else. This will cause the -compressor to return to the caller of jpeg_write_scanlines(), with the return -value indicating that not all the supplied scanlines have been accepted. -The application must make more room in the output buffer, adjust the output -buffer pointer/count appropriately, and then call jpeg_write_scanlines() -again, pointing to the first unconsumed scanline. - -When forced to suspend, the compressor will backtrack to a convenient stopping -point (usually the start of the current MCU); it will regenerate some output -data when restarted. Therefore, although empty_output_buffer() is only -called when the buffer is filled, you should NOT write out the entire buffer -after a suspension. Write only the data up to the current position of -next_output_byte/free_in_buffer. The data beyond that point will be -regenerated after resumption. - -Because of the backtracking behavior, a good-size output buffer is essential -for efficiency; you don't want the compressor to suspend often. (In fact, an -overly small buffer could lead to infinite looping, if a single MCU required -more data than would fit in the buffer.) We recommend a buffer of at least -several Kbytes. You may want to insert explicit code to ensure that you don't -call jpeg_write_scanlines() unless there is a reasonable amount of space in -the output buffer; in other words, flush the buffer before trying to compress -more data. - -The compressor does not allow suspension while it is trying to write JPEG -markers at the beginning and end of the file. This means that: - * At the beginning of a compression operation, there must be enough free - space in the output buffer to hold the header markers (typically 600 or - so bytes). The recommended buffer size is bigger than this anyway, so - this is not a problem as long as you start with an empty buffer. However, - this restriction might catch you if you insert large special markers, such - as a JFIF thumbnail image, without flushing the buffer afterwards. - * When you call jpeg_finish_compress(), there must be enough space in the - output buffer to emit any buffered data and the final EOI marker. In the - current implementation, half a dozen bytes should suffice for this, but - for safety's sake we recommend ensuring that at least 100 bytes are free - before calling jpeg_finish_compress(). - -A more significant restriction is that jpeg_finish_compress() cannot suspend. -This means you cannot use suspension with multi-pass operating modes, namely -Huffman code optimization and multiple-scan output. Those modes write the -whole file during jpeg_finish_compress(), which will certainly result in -buffer overrun. (Note that this restriction applies only to compression, -not decompression. The decompressor supports input suspension in all of its -operating modes.) - -Decompression suspension: - -For decompression suspension, use a fill_input_buffer() routine that simply -returns FALSE (except perhaps during error recovery, as discussed below). -This will cause the decompressor to return to its caller with an indication -that suspension has occurred. This can happen at four places: - * jpeg_read_header(): will return JPEG_SUSPENDED. - * jpeg_start_decompress(): will return FALSE, rather than its usual TRUE. - * jpeg_read_scanlines(): will return the number of scanlines already - completed (possibly 0). - * jpeg_finish_decompress(): will return FALSE, rather than its usual TRUE. -The surrounding application must recognize these cases, load more data into -the input buffer, and repeat the call. In the case of jpeg_read_scanlines(), -increment the passed pointers past any scanlines successfully read. - -Just as with compression, the decompressor will typically backtrack to a -convenient restart point before suspending. When fill_input_buffer() is -called, next_input_byte/bytes_in_buffer point to the current restart point, -which is where the decompressor will backtrack to if FALSE is returned. -The data beyond that position must NOT be discarded if you suspend; it needs -to be re-read upon resumption. In most implementations, you'll need to shift -this data down to the start of your work buffer and then load more data after -it. Again, this behavior means that a several-Kbyte work buffer is essential -for decent performance; furthermore, you should load a reasonable amount of -new data before resuming decompression. (If you loaded, say, only one new -byte each time around, you could waste a LOT of cycles.) - -The skip_input_data() source manager routine requires special care in a -suspension scenario. This routine is NOT granted the ability to suspend the -decompressor; it can decrement bytes_in_buffer to zero, but no more. If the -requested skip distance exceeds the amount of data currently in the input -buffer, then skip_input_data() must set bytes_in_buffer to zero and record the -additional skip distance somewhere else. The decompressor will immediately -call fill_input_buffer(), which should return FALSE, which will cause a -suspension return. The surrounding application must then arrange to discard -the recorded number of bytes before it resumes loading the input buffer. -(Yes, this design is rather baroque, but it avoids complexity in the far more -common case where a non-suspending source manager is used.) - -If the input data has been exhausted, we recommend that you emit a warning -and insert dummy EOI markers just as a non-suspending data source manager -would do. This can be handled either in the surrounding application logic or -within fill_input_buffer(); the latter is probably more efficient. If -fill_input_buffer() knows that no more data is available, it can set the -pointer/count to point to a dummy EOI marker and then return TRUE just as -though it had read more data in a non-suspending situation. - -The decompressor does not attempt to suspend within standard JPEG markers; -instead it will backtrack to the start of the marker and reprocess the whole -marker next time. Hence the input buffer must be large enough to hold the -longest standard marker in the file. Standard JPEG markers should normally -not exceed a few hundred bytes each (DHT tables are typically the longest). -We recommend at least a 2K buffer for performance reasons, which is much -larger than any correct marker is likely to be. For robustness against -damaged marker length counts, you may wish to insert a test in your -application for the case that the input buffer is completely full and yet -the decoder has suspended without consuming any data --- otherwise, if this -situation did occur, it would lead to an endless loop. (The library can't -provide this test since it has no idea whether "the buffer is full", or -even whether there is a fixed-size input buffer.) - -The input buffer would need to be 64K to allow for arbitrary COM or APPn -markers, but these are handled specially: they are either saved into allocated -memory, or skipped over by calling skip_input_data(). In the former case, -suspension is handled correctly, and in the latter case, the problem of -buffer overrun is placed on skip_input_data's shoulders, as explained above. -Note that if you provide your own marker handling routine for large markers, -you should consider how to deal with buffer overflow. - -Multiple-buffer management: - -In some applications it is desirable to store the compressed data in a linked -list of buffer areas, so as to avoid data copying. This can be handled by -having empty_output_buffer() or fill_input_buffer() set the pointer and count -to reference the next available buffer; FALSE is returned only if no more -buffers are available. Although seemingly straightforward, there is a -pitfall in this approach: the backtrack that occurs when FALSE is returned -could back up into an earlier buffer. For example, when fill_input_buffer() -is called, the current pointer & count indicate the backtrack restart point. -Since fill_input_buffer() will set the pointer and count to refer to a new -buffer, the restart position must be saved somewhere else. Suppose a second -call to fill_input_buffer() occurs in the same library call, and no -additional input data is available, so fill_input_buffer must return FALSE. -If the JPEG library has not moved the pointer/count forward in the current -buffer, then *the correct restart point is the saved position in the prior -buffer*. Prior buffers may be discarded only after the library establishes -a restart point within a later buffer. Similar remarks apply for output into -a chain of buffers. - -The library will never attempt to backtrack over a skip_input_data() call, -so any skipped data can be permanently discarded. You still have to deal -with the case of skipping not-yet-received data, however. - -It's much simpler to use only a single buffer; when fill_input_buffer() is -called, move any unconsumed data (beyond the current pointer/count) down to -the beginning of this buffer and then load new data into the remaining buffer -space. This approach requires a little more data copying but is far easier -to get right. - - -Progressive JPEG support ------------------------- - -Progressive JPEG rearranges the stored data into a series of scans of -increasing quality. In situations where a JPEG file is transmitted across a -slow communications link, a decoder can generate a low-quality image very -quickly from the first scan, then gradually improve the displayed quality as -more scans are received. The final image after all scans are complete is -identical to that of a regular (sequential) JPEG file of the same quality -setting. Progressive JPEG files are often slightly smaller than equivalent -sequential JPEG files, but the possibility of incremental display is the main -reason for using progressive JPEG. - -The IJG encoder library generates progressive JPEG files when given a -suitable "scan script" defining how to divide the data into scans. -Creation of progressive JPEG files is otherwise transparent to the encoder. -Progressive JPEG files can also be read transparently by the decoder library. -If the decoding application simply uses the library as defined above, it -will receive a final decoded image without any indication that the file was -progressive. Of course, this approach does not allow incremental display. -To perform incremental display, an application needs to use the decoder -library's "buffered-image" mode, in which it receives a decoded image -multiple times. - -Each displayed scan requires about as much work to decode as a full JPEG -image of the same size, so the decoder must be fairly fast in relation to the -data transmission rate in order to make incremental display useful. However, -it is possible to skip displaying the image and simply add the incoming bits -to the decoder's coefficient buffer. This is fast because only Huffman -decoding need be done, not IDCT, upsampling, colorspace conversion, etc. -The IJG decoder library allows the application to switch dynamically between -displaying the image and simply absorbing the incoming bits. A properly -coded application can automatically adapt the number of display passes to -suit the time available as the image is received. Also, a final -higher-quality display cycle can be performed from the buffered data after -the end of the file is reached. - -Progressive compression: - -To create a progressive JPEG file (or a multiple-scan sequential JPEG file), -set the scan_info cinfo field to point to an array of scan descriptors, and -perform compression as usual. Instead of constructing your own scan list, -you can call the jpeg_simple_progression() helper routine to create a -recommended progression sequence; this method should be used by all -applications that don't want to get involved in the nitty-gritty of -progressive scan sequence design. (If you want to provide user control of -scan sequences, you may wish to borrow the scan script reading code found -in rdswitch.c, so that you can read scan script files just like cjpeg's.) -When scan_info is not NULL, the compression library will store DCT'd data -into a buffer array as jpeg_write_scanlines() is called, and will emit all -the requested scans during jpeg_finish_compress(). This implies that -multiple-scan output cannot be created with a suspending data destination -manager, since jpeg_finish_compress() does not support suspension. We -should also note that the compressor currently forces Huffman optimization -mode when creating a progressive JPEG file, because the default Huffman -tables are unsuitable for progressive files. - -Progressive decompression: - -When buffered-image mode is not used, the decoder library will read all of -a multi-scan file during jpeg_start_decompress(), so that it can provide a -final decoded image. (Here "multi-scan" means either progressive or -multi-scan sequential.) This makes multi-scan files transparent to the -decoding application. However, existing applications that used suspending -input with version 5 of the IJG library will need to be modified to check -for a suspension return from jpeg_start_decompress(). - -To perform incremental display, an application must use the library's -buffered-image mode. This is described in the next section. - - -Buffered-image mode -------------------- - -In buffered-image mode, the library stores the partially decoded image in a -coefficient buffer, from which it can be read out as many times as desired. -This mode is typically used for incremental display of progressive JPEG files, -but it can be used with any JPEG file. Each scan of a progressive JPEG file -adds more data (more detail) to the buffered image. The application can -display in lockstep with the source file (one display pass per input scan), -or it can allow input processing to outrun display processing. By making -input and display processing run independently, it is possible for the -application to adapt progressive display to a wide range of data transmission -rates. - -The basic control flow for buffered-image decoding is - - jpeg_create_decompress() - set data source - jpeg_read_header() - set overall decompression parameters - cinfo.buffered_image = TRUE; /* select buffered-image mode */ - jpeg_start_decompress() - for (each output pass) { - adjust output decompression parameters if required - jpeg_start_output() /* start a new output pass */ - for (all scanlines in image) { - jpeg_read_scanlines() - display scanlines - } - jpeg_finish_output() /* terminate output pass */ - } - jpeg_finish_decompress() - jpeg_destroy_decompress() - -This differs from ordinary unbuffered decoding in that there is an additional -level of looping. The application can choose how many output passes to make -and how to display each pass. - -The simplest approach to displaying progressive images is to do one display -pass for each scan appearing in the input file. In this case the outer loop -condition is typically - while (! jpeg_input_complete(&cinfo)) -and the start-output call should read - jpeg_start_output(&cinfo, cinfo.input_scan_number); -The second parameter to jpeg_start_output() indicates which scan of the input -file is to be displayed; the scans are numbered starting at 1 for this -purpose. (You can use a loop counter starting at 1 if you like, but using -the library's input scan counter is easier.) The library automatically reads -data as necessary to complete each requested scan, and jpeg_finish_output() -advances to the next scan or end-of-image marker (hence input_scan_number -will be incremented by the time control arrives back at jpeg_start_output()). -With this technique, data is read from the input file only as needed, and -input and output processing run in lockstep. - -After reading the final scan and reaching the end of the input file, the -buffered image remains available; it can be read additional times by -repeating the jpeg_start_output()/jpeg_read_scanlines()/jpeg_finish_output() -sequence. For example, a useful technique is to use fast one-pass color -quantization for display passes made while the image is arriving, followed by -a final display pass using two-pass quantization for highest quality. This -is done by changing the library parameters before the final output pass. -Changing parameters between passes is discussed in detail below. - -In general the last scan of a progressive file cannot be recognized as such -until after it is read, so a post-input display pass is the best approach if -you want special processing in the final pass. - -When done with the image, be sure to call jpeg_finish_decompress() to release -the buffered image (or just use jpeg_destroy_decompress()). - -If input data arrives faster than it can be displayed, the application can -cause the library to decode input data in advance of what's needed to produce -output. This is done by calling the routine jpeg_consume_input(). -The return value is one of the following: - JPEG_REACHED_SOS: reached an SOS marker (the start of a new scan) - JPEG_REACHED_EOI: reached the EOI marker (end of image) - JPEG_ROW_COMPLETED: completed reading one MCU row of compressed data - JPEG_SCAN_COMPLETED: completed reading last MCU row of current scan - JPEG_SUSPENDED: suspended before completing any of the above -(JPEG_SUSPENDED can occur only if a suspending data source is used.) This -routine can be called at any time after initializing the JPEG object. It -reads some additional data and returns when one of the indicated significant -events occurs. (If called after the EOI marker is reached, it will -immediately return JPEG_REACHED_EOI without attempting to read more data.) - -The library's output processing will automatically call jpeg_consume_input() -whenever the output processing overtakes the input; thus, simple lockstep -display requires no direct calls to jpeg_consume_input(). But by adding -calls to jpeg_consume_input(), you can absorb data in advance of what is -being displayed. This has two benefits: - * You can limit buildup of unprocessed data in your input buffer. - * You can eliminate extra display passes by paying attention to the - state of the library's input processing. - -The first of these benefits only requires interspersing calls to -jpeg_consume_input() with your display operations and any other processing -you may be doing. To avoid wasting cycles due to backtracking, it's best to -call jpeg_consume_input() only after a hundred or so new bytes have arrived. -This is discussed further under "I/O suspension", above. (Note: the JPEG -library currently is not thread-safe. You must not call jpeg_consume_input() -from one thread of control if a different library routine is working on the -same JPEG object in another thread.) - -When input arrives fast enough that more than one new scan is available -before you start a new output pass, you may as well skip the output pass -corresponding to the completed scan. This occurs for free if you pass -cinfo.input_scan_number as the target scan number to jpeg_start_output(). -The input_scan_number field is simply the index of the scan currently being -consumed by the input processor. You can ensure that this is up-to-date by -emptying the input buffer just before calling jpeg_start_output(): call -jpeg_consume_input() repeatedly until it returns JPEG_SUSPENDED or -JPEG_REACHED_EOI. - -The target scan number passed to jpeg_start_output() is saved in the -cinfo.output_scan_number field. The library's output processing calls -jpeg_consume_input() whenever the current input scan number and row within -that scan is less than or equal to the current output scan number and row. -Thus, input processing can "get ahead" of the output processing but is not -allowed to "fall behind". You can achieve several different effects by -manipulating this interlock rule. For example, if you pass a target scan -number greater than the current input scan number, the output processor will -wait until that scan starts to arrive before producing any output. (To avoid -an infinite loop, the target scan number is automatically reset to the last -scan number when the end of image is reached. Thus, if you specify a large -target scan number, the library will just absorb the entire input file and -then perform an output pass. This is effectively the same as what -jpeg_start_decompress() does when you don't select buffered-image mode.) -When you pass a target scan number equal to the current input scan number, -the image is displayed no faster than the current input scan arrives. The -final possibility is to pass a target scan number less than the current input -scan number; this disables the input/output interlock and causes the output -processor to simply display whatever it finds in the image buffer, without -waiting for input. (However, the library will not accept a target scan -number less than one, so you can't avoid waiting for the first scan.) - -When data is arriving faster than the output display processing can advance -through the image, jpeg_consume_input() will store data into the buffered -image beyond the point at which the output processing is reading data out -again. If the input arrives fast enough, it may "wrap around" the buffer to -the point where the input is more than one whole scan ahead of the output. -If the output processing simply proceeds through its display pass without -paying attention to the input, the effect seen on-screen is that the lower -part of the image is one or more scans better in quality than the upper part. -Then, when the next output scan is started, you have a choice of what target -scan number to use. The recommended choice is to use the current input scan -number at that time, which implies that you've skipped the output scans -corresponding to the input scans that were completed while you processed the -previous output scan. In this way, the decoder automatically adapts its -speed to the arriving data, by skipping output scans as necessary to keep up -with the arriving data. - -When using this strategy, you'll want to be sure that you perform a final -output pass after receiving all the data; otherwise your last display may not -be full quality across the whole screen. So the right outer loop logic is -something like this: - do { - absorb any waiting input by calling jpeg_consume_input() - final_pass = jpeg_input_complete(&cinfo); - adjust output decompression parameters if required - jpeg_start_output(&cinfo, cinfo.input_scan_number); - ... - jpeg_finish_output() - } while (! final_pass); -rather than quitting as soon as jpeg_input_complete() returns TRUE. This -arrangement makes it simple to use higher-quality decoding parameters -for the final pass. But if you don't want to use special parameters for -the final pass, the right loop logic is like this: - for (;;) { - absorb any waiting input by calling jpeg_consume_input() - jpeg_start_output(&cinfo, cinfo.input_scan_number); - ... - jpeg_finish_output() - if (jpeg_input_complete(&cinfo) && - cinfo.input_scan_number == cinfo.output_scan_number) - break; - } -In this case you don't need to know in advance whether an output pass is to -be the last one, so it's not necessary to have reached EOF before starting -the final output pass; rather, what you want to test is whether the output -pass was performed in sync with the final input scan. This form of the loop -will avoid an extra output pass whenever the decoder is able (or nearly able) -to keep up with the incoming data. - -When the data transmission speed is high, you might begin a display pass, -then find that much or all of the file has arrived before you can complete -the pass. (You can detect this by noting the JPEG_REACHED_EOI return code -from jpeg_consume_input(), or equivalently by testing jpeg_input_complete().) -In this situation you may wish to abort the current display pass and start a -new one using the newly arrived information. To do so, just call -jpeg_finish_output() and then start a new pass with jpeg_start_output(). - -A variant strategy is to abort and restart display if more than one complete -scan arrives during an output pass; this can be detected by noting -JPEG_REACHED_SOS returns and/or examining cinfo.input_scan_number. This -idea should be employed with caution, however, since the display process -might never get to the bottom of the image before being aborted, resulting -in the lower part of the screen being several passes worse than the upper. -In most cases it's probably best to abort an output pass only if the whole -file has arrived and you want to begin the final output pass immediately. - -When receiving data across a communication link, we recommend always using -the current input scan number for the output target scan number; if a -higher-quality final pass is to be done, it should be started (aborting any -incomplete output pass) as soon as the end of file is received. However, -many other strategies are possible. For example, the application can examine -the parameters of the current input scan and decide whether to display it or -not. If the scan contains only chroma data, one might choose not to use it -as the target scan, expecting that the scan will be small and will arrive -quickly. To skip to the next scan, call jpeg_consume_input() until it -returns JPEG_REACHED_SOS or JPEG_REACHED_EOI. Or just use the next higher -number as the target scan for jpeg_start_output(); but that method doesn't -let you inspect the next scan's parameters before deciding to display it. - - -In buffered-image mode, jpeg_start_decompress() never performs input and -thus never suspends. An application that uses input suspension with -buffered-image mode must be prepared for suspension returns from these -routines: -* jpeg_start_output() performs input only if you request 2-pass quantization - and the target scan isn't fully read yet. (This is discussed below.) -* jpeg_read_scanlines(), as always, returns the number of scanlines that it - was able to produce before suspending. -* jpeg_finish_output() will read any markers following the target scan, - up to the end of the file or the SOS marker that begins another scan. - (But it reads no input if jpeg_consume_input() has already reached the - end of the file or a SOS marker beyond the target output scan.) -* jpeg_finish_decompress() will read until the end of file, and thus can - suspend if the end hasn't already been reached (as can be tested by - calling jpeg_input_complete()). -jpeg_start_output(), jpeg_finish_output(), and jpeg_finish_decompress() -all return TRUE if they completed their tasks, FALSE if they had to suspend. -In the event of a FALSE return, the application must load more input data -and repeat the call. Applications that use non-suspending data sources need -not check the return values of these three routines. - - -It is possible to change decoding parameters between output passes in the -buffered-image mode. The decoder library currently supports only very -limited changes of parameters. ONLY THE FOLLOWING parameter changes are -allowed after jpeg_start_decompress() is called: -* dct_method can be changed before each call to jpeg_start_output(). - For example, one could use a fast DCT method for early scans, changing - to a higher quality method for the final scan. -* dither_mode can be changed before each call to jpeg_start_output(); - of course this has no impact if not using color quantization. Typically - one would use ordered dither for initial passes, then switch to - Floyd-Steinberg dither for the final pass. Caution: changing dither mode - can cause more memory to be allocated by the library. Although the amount - of memory involved is not large (a scanline or so), it may cause the - initial max_memory_to_use specification to be exceeded, which in the worst - case would result in an out-of-memory failure. -* do_block_smoothing can be changed before each call to jpeg_start_output(). - This setting is relevant only when decoding a progressive JPEG image. - During the first DC-only scan, block smoothing provides a very "fuzzy" look - instead of the very "blocky" look seen without it; which is better seems a - matter of personal taste. But block smoothing is nearly always a win - during later stages, especially when decoding a successive-approximation - image: smoothing helps to hide the slight blockiness that otherwise shows - up on smooth gradients until the lowest coefficient bits are sent. -* Color quantization mode can be changed under the rules described below. - You *cannot* change between full-color and quantized output (because that - would alter the required I/O buffer sizes), but you can change which - quantization method is used. - -When generating color-quantized output, changing quantization method is a -very useful way of switching between high-speed and high-quality display. -The library allows you to change among its three quantization methods: -1. Single-pass quantization to a fixed color cube. - Selected by cinfo.two_pass_quantize = FALSE and cinfo.colormap = NULL. -2. Single-pass quantization to an application-supplied colormap. - Selected by setting cinfo.colormap to point to the colormap (the value of - two_pass_quantize is ignored); also set cinfo.actual_number_of_colors. -3. Two-pass quantization to a colormap chosen specifically for the image. - Selected by cinfo.two_pass_quantize = TRUE and cinfo.colormap = NULL. - (This is the default setting selected by jpeg_read_header, but it is - probably NOT what you want for the first pass of progressive display!) -These methods offer successively better quality and lesser speed. However, -only the first method is available for quantizing in non-RGB color spaces. - -IMPORTANT: because the different quantizer methods have very different -working-storage requirements, the library requires you to indicate which -one(s) you intend to use before you call jpeg_start_decompress(). (If we did -not require this, the max_memory_to_use setting would be a complete fiction.) -You do this by setting one or more of these three cinfo fields to TRUE: - enable_1pass_quant Fixed color cube colormap - enable_external_quant Externally-supplied colormap - enable_2pass_quant Two-pass custom colormap -All three are initialized FALSE by jpeg_read_header(). But -jpeg_start_decompress() automatically sets TRUE the one selected by the -current two_pass_quantize and colormap settings, so you only need to set the -enable flags for any other quantization methods you plan to change to later. - -After setting the enable flags correctly at jpeg_start_decompress() time, you -can change to any enabled quantization method by setting two_pass_quantize -and colormap properly just before calling jpeg_start_output(). The following -special rules apply: -1. You must explicitly set cinfo.colormap to NULL when switching to 1-pass - or 2-pass mode from a different mode, or when you want the 2-pass - quantizer to be re-run to generate a new colormap. -2. To switch to an external colormap, or to change to a different external - colormap than was used on the prior pass, you must call - jpeg_new_colormap() after setting cinfo.colormap. -NOTE: if you want to use the same colormap as was used in the prior pass, -you should not do either of these things. This will save some nontrivial -switchover costs. -(These requirements exist because cinfo.colormap will always be non-NULL -after completing a prior output pass, since both the 1-pass and 2-pass -quantizers set it to point to their output colormaps. Thus you have to -do one of these two things to notify the library that something has changed. -Yup, it's a bit klugy, but it's necessary to do it this way for backwards -compatibility.) - -Note that in buffered-image mode, the library generates any requested colormap -during jpeg_start_output(), not during jpeg_start_decompress(). - -When using two-pass quantization, jpeg_start_output() makes a pass over the -buffered image to determine the optimum color map; it therefore may take a -significant amount of time, whereas ordinarily it does little work. The -progress monitor hook is called during this pass, if defined. It is also -important to realize that if the specified target scan number is greater than -or equal to the current input scan number, jpeg_start_output() will attempt -to consume input as it makes this pass. If you use a suspending data source, -you need to check for a FALSE return from jpeg_start_output() under these -conditions. The combination of 2-pass quantization and a not-yet-fully-read -target scan is the only case in which jpeg_start_output() will consume input. - - -Application authors who support buffered-image mode may be tempted to use it -for all JPEG images, even single-scan ones. This will work, but it is -inefficient: there is no need to create an image-sized coefficient buffer for -single-scan images. Requesting buffered-image mode for such an image wastes -memory. Worse, it can cost time on large images, since the buffered data has -to be swapped out or written to a temporary file. If you are concerned about -maximum performance on baseline JPEG files, you should use buffered-image -mode only when the incoming file actually has multiple scans. This can be -tested by calling jpeg_has_multiple_scans(), which will return a correct -result at any time after jpeg_read_header() completes. - -It is also worth noting that when you use jpeg_consume_input() to let input -processing get ahead of output processing, the resulting pattern of access to -the coefficient buffer is quite nonsequential. It's best to use the memory -manager jmemnobs.c if you can (ie, if you have enough real or virtual main -memory). If not, at least make sure that max_memory_to_use is set as high as -possible. If the JPEG memory manager has to use a temporary file, you will -probably see a lot of disk traffic and poor performance. (This could be -improved with additional work on the memory manager, but we haven't gotten -around to it yet.) - -In some applications it may be convenient to use jpeg_consume_input() for all -input processing, including reading the initial markers; that is, you may -wish to call jpeg_consume_input() instead of jpeg_read_header() during -startup. This works, but note that you must check for JPEG_REACHED_SOS and -JPEG_REACHED_EOI return codes as the equivalent of jpeg_read_header's codes. -Once the first SOS marker has been reached, you must call -jpeg_start_decompress() before jpeg_consume_input() will consume more input; -it'll just keep returning JPEG_REACHED_SOS until you do. If you read a -tables-only file this way, jpeg_consume_input() will return JPEG_REACHED_EOI -without ever returning JPEG_REACHED_SOS; be sure to check for this case. -If this happens, the decompressor will not read any more input until you call -jpeg_abort() to reset it. It is OK to call jpeg_consume_input() even when not -using buffered-image mode, but in that case it's basically a no-op after the -initial markers have been read: it will just return JPEG_SUSPENDED. - - -Abbreviated datastreams and multiple images -------------------------------------------- - -A JPEG compression or decompression object can be reused to process multiple -images. This saves a small amount of time per image by eliminating the -"create" and "destroy" operations, but that isn't the real purpose of the -feature. Rather, reuse of an object provides support for abbreviated JPEG -datastreams. Object reuse can also simplify processing a series of images in -a single input or output file. This section explains these features. - -A JPEG file normally contains several hundred bytes worth of quantization -and Huffman tables. In a situation where many images will be stored or -transmitted with identical tables, this may represent an annoying overhead. -The JPEG standard therefore permits tables to be omitted. The standard -defines three classes of JPEG datastreams: - * "Interchange" datastreams contain an image and all tables needed to decode - the image. These are the usual kind of JPEG file. - * "Abbreviated image" datastreams contain an image, but are missing some or - all of the tables needed to decode that image. - * "Abbreviated table specification" (henceforth "tables-only") datastreams - contain only table specifications. -To decode an abbreviated image, it is necessary to load the missing table(s) -into the decoder beforehand. This can be accomplished by reading a separate -tables-only file. A variant scheme uses a series of images in which the first -image is an interchange (complete) datastream, while subsequent ones are -abbreviated and rely on the tables loaded by the first image. It is assumed -that once the decoder has read a table, it will remember that table until a -new definition for the same table number is encountered. - -It is the application designer's responsibility to figure out how to associate -the correct tables with an abbreviated image. While abbreviated datastreams -can be useful in a closed environment, their use is strongly discouraged in -any situation where data exchange with other applications might be needed. -Caveat designer. - -The JPEG library provides support for reading and writing any combination of -tables-only datastreams and abbreviated images. In both compression and -decompression objects, a quantization or Huffman table will be retained for -the lifetime of the object, unless it is overwritten by a new table definition. - - -To create abbreviated image datastreams, it is only necessary to tell the -compressor not to emit some or all of the tables it is using. Each -quantization and Huffman table struct contains a boolean field "sent_table", -which normally is initialized to FALSE. For each table used by the image, the -header-writing process emits the table and sets sent_table = TRUE unless it is -already TRUE. (In normal usage, this prevents outputting the same table -definition multiple times, as would otherwise occur because the chroma -components typically share tables.) Thus, setting this field to TRUE before -calling jpeg_start_compress() will prevent the table from being written at -all. - -If you want to create a "pure" abbreviated image file containing no tables, -just call "jpeg_suppress_tables(&cinfo, TRUE)" after constructing all the -tables. If you want to emit some but not all tables, you'll need to set the -individual sent_table fields directly. - -To create an abbreviated image, you must also call jpeg_start_compress() -with a second parameter of FALSE, not TRUE. Otherwise jpeg_start_compress() -will force all the sent_table fields to FALSE. (This is a safety feature to -prevent abbreviated images from being created accidentally.) - -To create a tables-only file, perform the same parameter setup that you -normally would, but instead of calling jpeg_start_compress() and so on, call -jpeg_write_tables(&cinfo). This will write an abbreviated datastream -containing only SOI, DQT and/or DHT markers, and EOI. All the quantization -and Huffman tables that are currently defined in the compression object will -be emitted unless their sent_tables flag is already TRUE, and then all the -sent_tables flags will be set TRUE. - -A sure-fire way to create matching tables-only and abbreviated image files -is to proceed as follows: - - create JPEG compression object - set JPEG parameters - set destination to tables-only file - jpeg_write_tables(&cinfo); - set destination to image file - jpeg_start_compress(&cinfo, FALSE); - write data... - jpeg_finish_compress(&cinfo); - -Since the JPEG parameters are not altered between writing the table file and -the abbreviated image file, the same tables are sure to be used. Of course, -you can repeat the jpeg_start_compress() ... jpeg_finish_compress() sequence -many times to produce many abbreviated image files matching the table file. - -You cannot suppress output of the computed Huffman tables when Huffman -optimization is selected. (If you could, there'd be no way to decode the -image...) Generally, you don't want to set optimize_coding = TRUE when -you are trying to produce abbreviated files. - -In some cases you might want to compress an image using tables which are -not stored in the application, but are defined in an interchange or -tables-only file readable by the application. This can be done by setting up -a JPEG decompression object to read the specification file, then copying the -tables into your compression object. See jpeg_copy_critical_parameters() -for an example of copying quantization tables. - - -To read abbreviated image files, you simply need to load the proper tables -into the decompression object before trying to read the abbreviated image. -If the proper tables are stored in the application program, you can just -allocate the table structs and fill in their contents directly. For example, -to load a fixed quantization table into table slot "n": - - if (cinfo.quant_tbl_ptrs[n] == NULL) - cinfo.quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) &cinfo); - quant_ptr = cinfo.quant_tbl_ptrs[n]; /* quant_ptr is JQUANT_TBL* */ - for (i = 0; i < 64; i++) { - /* Qtable[] is desired quantization table, in natural array order */ - quant_ptr->quantval[i] = Qtable[i]; - } - -Code to load a fixed Huffman table is typically (for AC table "n"): - - if (cinfo.ac_huff_tbl_ptrs[n] == NULL) - cinfo.ac_huff_tbl_ptrs[n] = jpeg_alloc_huff_table((j_common_ptr) &cinfo); - huff_ptr = cinfo.ac_huff_tbl_ptrs[n]; /* huff_ptr is JHUFF_TBL* */ - for (i = 1; i <= 16; i++) { - /* counts[i] is number of Huffman codes of length i bits, i=1..16 */ - huff_ptr->bits[i] = counts[i]; - } - for (i = 0; i < 256; i++) { - /* symbols[] is the list of Huffman symbols, in code-length order */ - huff_ptr->huffval[i] = symbols[i]; - } - -(Note that trying to set cinfo.quant_tbl_ptrs[n] to point directly at a -constant JQUANT_TBL object is not safe. If the incoming file happened to -contain a quantization table definition, your master table would get -overwritten! Instead allocate a working table copy and copy the master table -into it, as illustrated above. Ditto for Huffman tables, of course.) - -You might want to read the tables from a tables-only file, rather than -hard-wiring them into your application. The jpeg_read_header() call is -sufficient to read a tables-only file. You must pass a second parameter of -FALSE to indicate that you do not require an image to be present. Thus, the -typical scenario is - - create JPEG decompression object - set source to tables-only file - jpeg_read_header(&cinfo, FALSE); - set source to abbreviated image file - jpeg_read_header(&cinfo, TRUE); - set decompression parameters - jpeg_start_decompress(&cinfo); - read data... - jpeg_finish_decompress(&cinfo); - -In some cases, you may want to read a file without knowing whether it contains -an image or just tables. In that case, pass FALSE and check the return value -from jpeg_read_header(): it will be JPEG_HEADER_OK if an image was found, -JPEG_HEADER_TABLES_ONLY if only tables were found. (A third return value, -JPEG_SUSPENDED, is possible when using a suspending data source manager.) -Note that jpeg_read_header() will not complain if you read an abbreviated -image for which you haven't loaded the missing tables; the missing-table check -occurs later, in jpeg_start_decompress(). - - -It is possible to read a series of images from a single source file by -repeating the jpeg_read_header() ... jpeg_finish_decompress() sequence, -without releasing/recreating the JPEG object or the data source module. -(If you did reinitialize, any partial bufferload left in the data source -buffer at the end of one image would be discarded, causing you to lose the -start of the next image.) When you use this method, stored tables are -automatically carried forward, so some of the images can be abbreviated images -that depend on tables from earlier images. - -If you intend to write a series of images into a single destination file, -you might want to make a specialized data destination module that doesn't -flush the output buffer at term_destination() time. This would speed things -up by some trifling amount. Of course, you'd need to remember to flush the -buffer after the last image. You can make the later images be abbreviated -ones by passing FALSE to jpeg_start_compress(). - - -Special markers ---------------- - -Some applications may need to insert or extract special data in the JPEG -datastream. The JPEG standard provides marker types "COM" (comment) and -"APP0" through "APP15" (application) to hold application-specific data. -Unfortunately, the use of these markers is not specified by the standard. -COM markers are fairly widely used to hold user-supplied text. The JFIF file -format spec uses APP0 markers with specified initial strings to hold certain -data. Adobe applications use APP14 markers beginning with the string "Adobe" -for miscellaneous data. Other APPn markers are rarely seen, but might -contain almost anything. - -If you wish to store user-supplied text, we recommend you use COM markers -and place readable 7-bit ASCII text in them. Newline conventions are not -standardized --- expect to find LF (Unix style), CR/LF (DOS style), or CR -(Mac style). A robust COM reader should be able to cope with random binary -garbage, including nulls, since some applications generate COM markers -containing non-ASCII junk. (But yours should not be one of them.) - -For program-supplied data, use an APPn marker, and be sure to begin it with an -identifying string so that you can tell whether the marker is actually yours. -It's probably best to avoid using APP0 or APP14 for any private markers. -(NOTE: the upcoming SPIFF standard will use APP8 markers; we recommend you -not use APP8 markers for any private purposes, either.) - -Keep in mind that at most 65533 bytes can be put into one marker, but you -can have as many markers as you like. - -By default, the IJG compression library will write a JFIF APP0 marker if the -selected JPEG colorspace is grayscale or YCbCr, or an Adobe APP14 marker if -the selected colorspace is RGB, CMYK, or YCCK. You can disable this, but -we don't recommend it. The decompression library will recognize JFIF and -Adobe markers and will set the JPEG colorspace properly when one is found. - - -You can write special markers immediately following the datastream header by -calling jpeg_write_marker() after jpeg_start_compress() and before the first -call to jpeg_write_scanlines(). When you do this, the markers appear after -the SOI and the JFIF APP0 and Adobe APP14 markers (if written), but before -all else. Specify the marker type parameter as "JPEG_COM" for COM or -"JPEG_APP0 + n" for APPn. (Actually, jpeg_write_marker will let you write -any marker type, but we don't recommend writing any other kinds of marker.) -For example, to write a user comment string pointed to by comment_text: - jpeg_write_marker(cinfo, JPEG_COM, comment_text, strlen(comment_text)); - -If it's not convenient to store all the marker data in memory at once, -you can instead call jpeg_write_m_header() followed by multiple calls to -jpeg_write_m_byte(). If you do it this way, it's your responsibility to -call jpeg_write_m_byte() exactly the number of times given in the length -parameter to jpeg_write_m_header(). (This method lets you empty the -output buffer partway through a marker, which might be important when -using a suspending data destination module. In any case, if you are using -a suspending destination, you should flush its buffer after inserting -any special markers. See "I/O suspension".) - -Or, if you prefer to synthesize the marker byte sequence yourself, -you can just cram it straight into the data destination module. - -If you are writing JFIF 1.02 extension markers (thumbnail images), don't -forget to set cinfo.JFIF_minor_version = 2 so that the encoder will write the -correct JFIF version number in the JFIF header marker. The library's default -is to write version 1.01, but that's wrong if you insert any 1.02 extension -markers. (We could probably get away with just defaulting to 1.02, but there -used to be broken decoders that would complain about unknown minor version -numbers. To reduce compatibility risks it's safest not to write 1.02 unless -you are actually using 1.02 extensions.) - - -When reading, two methods of handling special markers are available: -1. You can ask the library to save the contents of COM and/or APPn markers -into memory, and then examine them at your leisure afterwards. -2. You can supply your own routine to process COM and/or APPn markers -on-the-fly as they are read. -The first method is simpler to use, especially if you are using a suspending -data source; writing a marker processor that copes with input suspension is -not easy (consider what happens if the marker is longer than your available -input buffer). However, the second method conserves memory since the marker -data need not be kept around after it's been processed. - -For either method, you'd normally set up marker handling after creating a -decompression object and before calling jpeg_read_header(), because the -markers of interest will typically be near the head of the file and so will -be scanned by jpeg_read_header. Once you've established a marker handling -method, it will be used for the life of that decompression object -(potentially many datastreams), unless you change it. Marker handling is -determined separately for COM markers and for each APPn marker code. - - -To save the contents of special markers in memory, call - jpeg_save_markers(cinfo, marker_code, length_limit) -where marker_code is the marker type to save, JPEG_COM or JPEG_APP0+n. -(To arrange to save all the special marker types, you need to call this -routine 17 times, for COM and APP0-APP15.) If the incoming marker is longer -than length_limit data bytes, only length_limit bytes will be saved; this -parameter allows you to avoid chewing up memory when you only need to see the -first few bytes of a potentially large marker. If you want to save all the -data, set length_limit to 0xFFFF; that is enough since marker lengths are only -16 bits. As a special case, setting length_limit to 0 prevents that marker -type from being saved at all. (That is the default behavior, in fact.) - -After jpeg_read_header() completes, you can examine the special markers by -following the cinfo->marker_list pointer chain. All the special markers in -the file appear in this list, in order of their occurrence in the file (but -omitting any markers of types you didn't ask for). Both the original data -length and the saved data length are recorded for each list entry; the latter -will not exceed length_limit for the particular marker type. Note that these -lengths exclude the marker length word, whereas the stored representation -within the JPEG file includes it. (Hence the maximum data length is really -only 65533.) - -It is possible that additional special markers appear in the file beyond the -SOS marker at which jpeg_read_header stops; if so, the marker list will be -extended during reading of the rest of the file. This is not expected to be -common, however. If you are short on memory you may want to reset the length -limit to zero for all marker types after finishing jpeg_read_header, to -ensure that the max_memory_to_use setting cannot be exceeded due to addition -of later markers. - -The marker list remains stored until you call jpeg_finish_decompress or -jpeg_abort, at which point the memory is freed and the list is set to empty. -(jpeg_destroy also releases the storage, of course.) - -Note that the library is internally interested in APP0 and APP14 markers; -if you try to set a small nonzero length limit on these types, the library -will silently force the length up to the minimum it wants. (But you can set -a zero length limit to prevent them from being saved at all.) Also, in a -16-bit environment, the maximum length limit may be constrained to less than -65533 by malloc() limitations. It is therefore best not to assume that the -effective length limit is exactly what you set it to be. - - -If you want to supply your own marker-reading routine, you do it by calling -jpeg_set_marker_processor(). A marker processor routine must have the -signature - boolean jpeg_marker_parser_method (j_decompress_ptr cinfo) -Although the marker code is not explicitly passed, the routine can find it -in cinfo->unread_marker. At the time of call, the marker proper has been -read from the data source module. The processor routine is responsible for -reading the marker length word and the remaining parameter bytes, if any. -Return TRUE to indicate success. (FALSE should be returned only if you are -using a suspending data source and it tells you to suspend. See the standard -marker processors in jdmarker.c for appropriate coding methods if you need to -use a suspending data source.) - -If you override the default APP0 or APP14 processors, it is up to you to -recognize JFIF and Adobe markers if you want colorspace recognition to occur -properly. We recommend copying and extending the default processors if you -want to do that. (A better idea is to save these marker types for later -examination by calling jpeg_save_markers(); that method doesn't interfere -with the library's own processing of these markers.) - -jpeg_set_marker_processor() and jpeg_save_markers() are mutually exclusive ---- if you call one it overrides any previous call to the other, for the -particular marker type specified. - -A simple example of an external COM processor can be found in djpeg.c. -Also, see jpegtran.c for an example of using jpeg_save_markers. - - -Raw (downsampled) image data ----------------------------- - -Some applications need to supply already-downsampled image data to the JPEG -compressor, or to receive raw downsampled data from the decompressor. The -library supports this requirement by allowing the application to write or -read raw data, bypassing the normal preprocessing or postprocessing steps. -The interface is different from the standard one and is somewhat harder to -use. If your interest is merely in bypassing color conversion, we recommend -that you use the standard interface and simply set jpeg_color_space = -in_color_space (or jpeg_color_space = out_color_space for decompression). -The mechanism described in this section is necessary only to supply or -receive downsampled image data, in which not all components have the same -dimensions. - - -To compress raw data, you must supply the data in the colorspace to be used -in the JPEG file (please read the earlier section on Special color spaces) -and downsampled to the sampling factors specified in the JPEG parameters. -You must supply the data in the format used internally by the JPEG library, -namely a JSAMPIMAGE array. This is an array of pointers to two-dimensional -arrays, each of type JSAMPARRAY. Each 2-D array holds the values for one -color component. This structure is necessary since the components are of -different sizes. If the image dimensions are not a multiple of the MCU size, -you must also pad the data correctly (usually, this is done by replicating -the last column and/or row). The data must be padded to a multiple of a DCT -block in each component: that is, each downsampled row must contain a -multiple of 8 valid samples, and there must be a multiple of 8 sample rows -for each component. (For applications such as conversion of digital TV -images, the standard image size is usually a multiple of the DCT block size, -so that no padding need actually be done.) - -The procedure for compression of raw data is basically the same as normal -compression, except that you call jpeg_write_raw_data() in place of -jpeg_write_scanlines(). Before calling jpeg_start_compress(), you must do -the following: - * Set cinfo->raw_data_in to TRUE. (It is set FALSE by jpeg_set_defaults().) - This notifies the library that you will be supplying raw data. - Furthermore, set cinfo->do_fancy_downsampling to FALSE if you want to use - real downsampled data. (It is set TRUE by jpeg_set_defaults().) - * Ensure jpeg_color_space is correct --- an explicit jpeg_set_colorspace() - call is a good idea. Note that since color conversion is bypassed, - in_color_space is ignored, except that jpeg_set_defaults() uses it to - choose the default jpeg_color_space setting. - * Ensure the sampling factors, cinfo->comp_info[i].h_samp_factor and - cinfo->comp_info[i].v_samp_factor, are correct. Since these indicate the - dimensions of the data you are supplying, it's wise to set them - explicitly, rather than assuming the library's defaults are what you want. - -To pass raw data to the library, call jpeg_write_raw_data() in place of -jpeg_write_scanlines(). The two routines work similarly except that -jpeg_write_raw_data takes a JSAMPIMAGE data array rather than JSAMPARRAY. -The scanlines count passed to and returned from jpeg_write_raw_data is -measured in terms of the component with the largest v_samp_factor. - -jpeg_write_raw_data() processes one MCU row per call, which is to say -v_samp_factor*DCTSIZE sample rows of each component. The passed num_lines -value must be at least max_v_samp_factor*DCTSIZE, and the return value will -be exactly that amount (or possibly some multiple of that amount, in future -library versions). This is true even on the last call at the bottom of the -image; don't forget to pad your data as necessary. - -The required dimensions of the supplied data can be computed for each -component as - cinfo->comp_info[i].width_in_blocks*DCTSIZE samples per row - cinfo->comp_info[i].height_in_blocks*DCTSIZE rows in image -after jpeg_start_compress() has initialized those fields. If the valid data -is smaller than this, it must be padded appropriately. For some sampling -factors and image sizes, additional dummy DCT blocks are inserted to make -the image a multiple of the MCU dimensions. The library creates such dummy -blocks itself; it does not read them from your supplied data. Therefore you -need never pad by more than DCTSIZE samples. An example may help here. -Assume 2h2v downsampling of YCbCr data, that is - cinfo->comp_info[0].h_samp_factor = 2 for Y - cinfo->comp_info[0].v_samp_factor = 2 - cinfo->comp_info[1].h_samp_factor = 1 for Cb - cinfo->comp_info[1].v_samp_factor = 1 - cinfo->comp_info[2].h_samp_factor = 1 for Cr - cinfo->comp_info[2].v_samp_factor = 1 -and suppose that the nominal image dimensions (cinfo->image_width and -cinfo->image_height) are 101x101 pixels. Then jpeg_start_compress() will -compute downsampled_width = 101 and width_in_blocks = 13 for Y, -downsampled_width = 51 and width_in_blocks = 7 for Cb and Cr (and the same -for the height fields). You must pad the Y data to at least 13*8 = 104 -columns and rows, the Cb/Cr data to at least 7*8 = 56 columns and rows. The -MCU height is max_v_samp_factor = 2 DCT rows so you must pass at least 16 -scanlines on each call to jpeg_write_raw_data(), which is to say 16 actual -sample rows of Y and 8 each of Cb and Cr. A total of 7 MCU rows are needed, -so you must pass a total of 7*16 = 112 "scanlines". The last DCT block row -of Y data is dummy, so it doesn't matter what you pass for it in the data -arrays, but the scanlines count must total up to 112 so that all of the Cb -and Cr data gets passed. - -Output suspension is supported with raw-data compression: if the data -destination module suspends, jpeg_write_raw_data() will return 0. -In this case the same data rows must be passed again on the next call. - - -Decompression with raw data output implies bypassing all postprocessing. -You must deal with the color space and sampling factors present in the -incoming file. If your application only handles, say, 2h1v YCbCr data, -you must check for and fail on other color spaces or other sampling factors. -The library will not convert to a different color space for you. - -To obtain raw data output, set cinfo->raw_data_out = TRUE before -jpeg_start_decompress() (it is set FALSE by jpeg_read_header()). Be sure to -verify that the color space and sampling factors are ones you can handle. -Furthermore, set cinfo->do_fancy_upsampling = FALSE if you want to get real -downsampled data (it is set TRUE by jpeg_read_header()). -Then call jpeg_read_raw_data() in place of jpeg_read_scanlines(). The -decompression process is otherwise the same as usual. - -jpeg_read_raw_data() returns one MCU row per call, and thus you must pass a -buffer of at least max_v_samp_factor*DCTSIZE scanlines (scanline counting is -the same as for raw-data compression). The buffer you pass must be large -enough to hold the actual data plus padding to DCT-block boundaries. As with -compression, any entirely dummy DCT blocks are not processed so you need not -allocate space for them, but the total scanline count includes them. The -above example of computing buffer dimensions for raw-data compression is -equally valid for decompression. - -Input suspension is supported with raw-data decompression: if the data source -module suspends, jpeg_read_raw_data() will return 0. You can also use -buffered-image mode to read raw data in multiple passes. - - -Really raw data: DCT coefficients ---------------------------------- - -It is possible to read or write the contents of a JPEG file as raw DCT -coefficients. This facility is mainly intended for use in lossless -transcoding between different JPEG file formats. Other possible applications -include lossless cropping of a JPEG image, lossless reassembly of a -multi-strip or multi-tile TIFF/JPEG file into a single JPEG datastream, etc. - -To read the contents of a JPEG file as DCT coefficients, open the file and do -jpeg_read_header() as usual. But instead of calling jpeg_start_decompress() -and jpeg_read_scanlines(), call jpeg_read_coefficients(). This will read the -entire image into a set of virtual coefficient-block arrays, one array per -component. The return value is a pointer to an array of virtual-array -descriptors. Each virtual array can be accessed directly using the JPEG -memory manager's access_virt_barray method (see Memory management, below, -and also read structure.txt's discussion of virtual array handling). Or, -for simple transcoding to a different JPEG file format, the array list can -just be handed directly to jpeg_write_coefficients(). - -Each block in the block arrays contains quantized coefficient values in -normal array order (not JPEG zigzag order). The block arrays contain only -DCT blocks containing real data; any entirely-dummy blocks added to fill out -interleaved MCUs at the right or bottom edges of the image are discarded -during reading and are not stored in the block arrays. (The size of each -block array can be determined from the width_in_blocks and height_in_blocks -fields of the component's comp_info entry.) This is also the data format -expected by jpeg_write_coefficients(). - -When you are done using the virtual arrays, call jpeg_finish_decompress() -to release the array storage and return the decompression object to an idle -state; or just call jpeg_destroy() if you don't need to reuse the object. - -If you use a suspending data source, jpeg_read_coefficients() will return -NULL if it is forced to suspend; a non-NULL return value indicates successful -completion. You need not test for a NULL return value when using a -non-suspending data source. - -It is also possible to call jpeg_read_coefficients() to obtain access to the -decoder's coefficient arrays during a normal decode cycle in buffered-image -mode. This frammish might be useful for progressively displaying an incoming -image and then re-encoding it without loss. To do this, decode in buffered- -image mode as discussed previously, then call jpeg_read_coefficients() after -the last jpeg_finish_output() call. The arrays will be available for your use -until you call jpeg_finish_decompress(). - - -To write the contents of a JPEG file as DCT coefficients, you must provide -the DCT coefficients stored in virtual block arrays. You can either pass -block arrays read from an input JPEG file by jpeg_read_coefficients(), or -allocate virtual arrays from the JPEG compression object and fill them -yourself. In either case, jpeg_write_coefficients() is substituted for -jpeg_start_compress() and jpeg_write_scanlines(). Thus the sequence is - * Create compression object - * Set all compression parameters as necessary - * Request virtual arrays if needed - * jpeg_write_coefficients() - * jpeg_finish_compress() - * Destroy or re-use compression object -jpeg_write_coefficients() is passed a pointer to an array of virtual block -array descriptors; the number of arrays is equal to cinfo.num_components. - -The virtual arrays need only have been requested, not realized, before -jpeg_write_coefficients() is called. A side-effect of -jpeg_write_coefficients() is to realize any virtual arrays that have been -requested from the compression object's memory manager. Thus, when obtaining -the virtual arrays from the compression object, you should fill the arrays -after calling jpeg_write_coefficients(). The data is actually written out -when you call jpeg_finish_compress(); jpeg_write_coefficients() only writes -the file header. - -When writing raw DCT coefficients, it is crucial that the JPEG quantization -tables and sampling factors match the way the data was encoded, or the -resulting file will be invalid. For transcoding from an existing JPEG file, -we recommend using jpeg_copy_critical_parameters(). This routine initializes -all the compression parameters to default values (like jpeg_set_defaults()), -then copies the critical information from a source decompression object. -The decompression object should have just been used to read the entire -JPEG input file --- that is, it should be awaiting jpeg_finish_decompress(). - -jpeg_write_coefficients() marks all tables stored in the compression object -as needing to be written to the output file (thus, it acts like -jpeg_start_compress(cinfo, TRUE)). This is for safety's sake, to avoid -emitting abbreviated JPEG files by accident. If you really want to emit an -abbreviated JPEG file, call jpeg_suppress_tables(), or set the tables' -individual sent_table flags, between calling jpeg_write_coefficients() and -jpeg_finish_compress(). - - -Progress monitoring -------------------- - -Some applications may need to regain control from the JPEG library every so -often. The typical use of this feature is to produce a percent-done bar or -other progress display. (For a simple example, see cjpeg.c or djpeg.c.) -Although you do get control back frequently during the data-transferring pass -(the jpeg_read_scanlines or jpeg_write_scanlines loop), any additional passes -will occur inside jpeg_finish_compress or jpeg_start_decompress; those -routines may take a long time to execute, and you don't get control back -until they are done. - -You can define a progress-monitor routine which will be called periodically -by the library. No guarantees are made about how often this call will occur, -so we don't recommend you use it for mouse tracking or anything like that. -At present, a call will occur once per MCU row, scanline, or sample row -group, whichever unit is convenient for the current processing mode; so the -wider the image, the longer the time between calls. During the data -transferring pass, only one call occurs per call of jpeg_read_scanlines or -jpeg_write_scanlines, so don't pass a large number of scanlines at once if -you want fine resolution in the progress count. (If you really need to use -the callback mechanism for time-critical tasks like mouse tracking, you could -insert additional calls inside some of the library's inner loops.) - -To establish a progress-monitor callback, create a struct jpeg_progress_mgr, -fill in its progress_monitor field with a pointer to your callback routine, -and set cinfo->progress to point to the struct. The callback will be called -whenever cinfo->progress is non-NULL. (This pointer is set to NULL by -jpeg_create_compress or jpeg_create_decompress; the library will not change -it thereafter. So if you allocate dynamic storage for the progress struct, -make sure it will live as long as the JPEG object does. Allocating from the -JPEG memory manager with lifetime JPOOL_PERMANENT will work nicely.) You -can use the same callback routine for both compression and decompression. - -The jpeg_progress_mgr struct contains four fields which are set by the library: - long pass_counter; /* work units completed in this pass */ - long pass_limit; /* total number of work units in this pass */ - int completed_passes; /* passes completed so far */ - int total_passes; /* total number of passes expected */ -During any one pass, pass_counter increases from 0 up to (not including) -pass_limit; the step size is usually but not necessarily 1. The pass_limit -value may change from one pass to another. The expected total number of -passes is in total_passes, and the number of passes already completed is in -completed_passes. Thus the fraction of work completed may be estimated as - completed_passes + (pass_counter/pass_limit) - -------------------------------------------- - total_passes -ignoring the fact that the passes may not be equal amounts of work. - -When decompressing, pass_limit can even change within a pass, because it -depends on the number of scans in the JPEG file, which isn't always known in -advance. The computed fraction-of-work-done may jump suddenly (if the library -discovers it has overestimated the number of scans) or even decrease (in the -opposite case). It is not wise to put great faith in the work estimate. - -When using the decompressor's buffered-image mode, the progress monitor work -estimate is likely to be completely unhelpful, because the library has no way -to know how many output passes will be demanded of it. Currently, the library -sets total_passes based on the assumption that there will be one more output -pass if the input file end hasn't yet been read (jpeg_input_complete() isn't -TRUE), but no more output passes if the file end has been reached when the -output pass is started. This means that total_passes will rise as additional -output passes are requested. If you have a way of determining the input file -size, estimating progress based on the fraction of the file that's been read -will probably be more useful than using the library's value. - - -Memory management ------------------ - -This section covers some key facts about the JPEG library's built-in memory -manager. For more info, please read structure.txt's section about the memory -manager, and consult the source code if necessary. - -All memory and temporary file allocation within the library is done via the -memory manager. If necessary, you can replace the "back end" of the memory -manager to control allocation yourself (for example, if you don't want the -library to use malloc() and free() for some reason). - -Some data is allocated "permanently" and will not be freed until the JPEG -object is destroyed. Most data is allocated "per image" and is freed by -jpeg_finish_compress, jpeg_finish_decompress, or jpeg_abort. You can call the -memory manager yourself to allocate structures that will automatically be -freed at these times. Typical code for this is - ptr = (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, size); -Use JPOOL_PERMANENT to get storage that lasts as long as the JPEG object. -Use alloc_large instead of alloc_small for anything bigger than a few Kbytes. -There are also alloc_sarray and alloc_barray routines that automatically -build 2-D sample or block arrays. - -The library's minimum space requirements to process an image depend on the -image's width, but not on its height, because the library ordinarily works -with "strip" buffers that are as wide as the image but just a few rows high. -Some operating modes (eg, two-pass color quantization) require full-image -buffers. Such buffers are treated as "virtual arrays": only the current strip -need be in memory, and the rest can be swapped out to a temporary file. - -If you use the simplest memory manager back end (jmemnobs.c), then no -temporary files are used; virtual arrays are simply malloc()'d. Images bigger -than memory can be processed only if your system supports virtual memory. -The other memory manager back ends support temporary files of various flavors -and thus work in machines without virtual memory. They may also be useful on -Unix machines if you need to process images that exceed available swap space. - -When using temporary files, the library will make the in-memory buffers for -its virtual arrays just big enough to stay within a "maximum memory" setting. -Your application can set this limit by setting cinfo->mem->max_memory_to_use -after creating the JPEG object. (Of course, there is still a minimum size for -the buffers, so the max-memory setting is effective only if it is bigger than -the minimum space needed.) If you allocate any large structures yourself, you -must allocate them before jpeg_start_compress() or jpeg_start_decompress() in -order to have them counted against the max memory limit. Also keep in mind -that space allocated with alloc_small() is ignored, on the assumption that -it's too small to be worth worrying about; so a reasonable safety margin -should be left when setting max_memory_to_use. - -If you use the jmemname.c or jmemdos.c memory manager back end, it is -important to clean up the JPEG object properly to ensure that the temporary -files get deleted. (This is especially crucial with jmemdos.c, where the -"temporary files" may be extended-memory segments; if they are not freed, -DOS will require a reboot to recover the memory.) Thus, with these memory -managers, it's a good idea to provide a signal handler that will trap any -early exit from your program. The handler should call either jpeg_abort() -or jpeg_destroy() for any active JPEG objects. A handler is not needed with -jmemnobs.c, and shouldn't be necessary with jmemansi.c or jmemmac.c either, -since the C library is supposed to take care of deleting files made with -tmpfile(). - - -Memory usage ------------- - -Working memory requirements while performing compression or decompression -depend on image dimensions, image characteristics (such as colorspace and -JPEG process), and operating mode (application-selected options). - -As of v6b, the decompressor requires: - 1. About 24K in more-or-less-fixed-size data. This varies a bit depending - on operating mode and image characteristics (particularly color vs. - grayscale), but it doesn't depend on image dimensions. - 2. Strip buffers (of size proportional to the image width) for IDCT and - upsampling results. The worst case for commonly used sampling factors - is about 34 bytes * width in pixels for a color image. A grayscale image - only needs about 8 bytes per pixel column. - 3. A full-image DCT coefficient buffer is needed to decode a multi-scan JPEG - file (including progressive JPEGs), or whenever you select buffered-image - mode. This takes 2 bytes/coefficient. At typical 2x2 sampling, that's - 3 bytes per pixel for a color image. Worst case (1x1 sampling) requires - 6 bytes/pixel. For grayscale, figure 2 bytes/pixel. - 4. To perform 2-pass color quantization, the decompressor also needs a - 128K color lookup table and a full-image pixel buffer (3 bytes/pixel). -This does not count any memory allocated by the application, such as a -buffer to hold the final output image. - -The above figures are valid for 8-bit JPEG data precision and a machine with -32-bit ints. For 12-bit JPEG data, double the size of the strip buffers and -quantization pixel buffer. The "fixed-size" data will be somewhat smaller -with 16-bit ints, larger with 64-bit ints. Also, CMYK or other unusual -color spaces will require different amounts of space. - -The full-image coefficient and pixel buffers, if needed at all, do not -have to be fully RAM resident; you can have the library use temporary -files instead when the total memory usage would exceed a limit you set. -(But if your OS supports virtual memory, it's probably better to just use -jmemnobs and let the OS do the swapping.) - -The compressor's memory requirements are similar, except that it has no need -for color quantization. Also, it needs a full-image DCT coefficient buffer -if Huffman-table optimization is asked for, even if progressive mode is not -requested. - -If you need more detailed information about memory usage in a particular -situation, you can enable the MEM_STATS code in jmemmgr.c. - - -Library compile-time options ----------------------------- - -A number of compile-time options are available by modifying jmorecfg.h. - -The JPEG standard provides for both the baseline 8-bit DCT process and -a 12-bit DCT process. The IJG code supports 12-bit JPEG if you define -BITS_IN_JSAMPLE as 12 rather than 8. Note that this causes JSAMPLE to be -larger than a char, so it affects the surrounding application's image data. -The sample applications cjpeg and djpeg can support 12-bit mode only for PPM -and GIF file formats; you must disable the other file formats to compile a -12-bit cjpeg or djpeg. (install.txt has more information about that.) -At present, a 12-bit library can handle *only* 12-bit images, not both -precisions. (If you need to include both 8- and 12-bit libraries in a single -application, you could probably do it by defining NEED_SHORT_EXTERNAL_NAMES -for just one of the copies. You'd have to access the 8-bit and 12-bit copies -from separate application source files. This is untested ... if you try it, -we'd like to hear whether it works!) - -Note that a 12-bit library always compresses in Huffman optimization mode, -in order to generate valid Huffman tables. This is necessary because our -default Huffman tables only cover 8-bit data. If you need to output 12-bit -files in one pass, you'll have to supply suitable default Huffman tables. -You may also want to supply your own DCT quantization tables; the existing -quality-scaling code has been developed for 8-bit use, and probably doesn't -generate especially good tables for 12-bit. - -The maximum number of components (color channels) in the image is determined -by MAX_COMPONENTS. The JPEG standard allows up to 255 components, but we -expect that few applications will need more than four or so. - -On machines with unusual data type sizes, you may be able to improve -performance or reduce memory space by tweaking the various typedefs in -jmorecfg.h. In particular, on some RISC CPUs, access to arrays of "short"s -is quite slow; consider trading memory for speed by making JCOEF, INT16, and -UINT16 be "int" or "unsigned int". UINT8 is also a candidate to become int. -You probably don't want to make JSAMPLE be int unless you have lots of memory -to burn. - -You can reduce the size of the library by compiling out various optional -functions. To do this, undefine xxx_SUPPORTED symbols as necessary. - -You can also save a few K by not having text error messages in the library; -the standard error message table occupies about 5Kb. This is particularly -reasonable for embedded applications where there's no good way to display -a message anyway. To do this, remove the creation of the message table -(jpeg_std_message_table[]) from jerror.c, and alter format_message to do -something reasonable without it. You could output the numeric value of the -message code number, for example. If you do this, you can also save a couple -more K by modifying the TRACEMSn() macros in jerror.h to expand to nothing; -you don't need trace capability anyway, right? - - -Portability considerations --------------------------- - -The JPEG library has been written to be extremely portable; the sample -applications cjpeg and djpeg are slightly less so. This section summarizes -the design goals in this area. (If you encounter any bugs that cause the -library to be less portable than is claimed here, we'd appreciate hearing -about them.) - -The code works fine on ANSI C, C++, and pre-ANSI C compilers, using any of -the popular system include file setups, and some not-so-popular ones too. -See install.txt for configuration procedures. - -The code is not dependent on the exact sizes of the C data types. As -distributed, we make the assumptions that - char is at least 8 bits wide - short is at least 16 bits wide - int is at least 16 bits wide - long is at least 32 bits wide -(These are the minimum requirements of the ANSI C standard.) Wider types will -work fine, although memory may be used inefficiently if char is much larger -than 8 bits or short is much bigger than 16 bits. The code should work -equally well with 16- or 32-bit ints. - -In a system where these assumptions are not met, you may be able to make the -code work by modifying the typedefs in jmorecfg.h. However, you will probably -have difficulty if int is less than 16 bits wide, since references to plain -int abound in the code. - -char can be either signed or unsigned, although the code runs faster if an -unsigned char type is available. If char is wider than 8 bits, you will need -to redefine JOCTET and/or provide custom data source/destination managers so -that JOCTET represents exactly 8 bits of data on external storage. - -The JPEG library proper does not assume ASCII representation of characters. -But some of the image file I/O modules in cjpeg/djpeg do have ASCII -dependencies in file-header manipulation; so does cjpeg's select_file_type() -routine. - -The JPEG library does not rely heavily on the C library. In particular, C -stdio is used only by the data source/destination modules and the error -handler, all of which are application-replaceable. (cjpeg/djpeg are more -heavily dependent on stdio.) malloc and free are called only from the memory -manager "back end" module, so you can use a different memory allocator by -replacing that one file. - -The code generally assumes that C names must be unique in the first 15 -characters. However, global function names can be made unique in the -first 6 characters by defining NEED_SHORT_EXTERNAL_NAMES. - -More info about porting the code may be gleaned by reading jconfig.txt, -jmorecfg.h, and jinclude.h. - - -Notes for MS-DOS implementors ------------------------------ - -The IJG code is designed to work efficiently in 80x86 "small" or "medium" -memory models (i.e., data pointers are 16 bits unless explicitly declared -"far"; code pointers can be either size). You may be able to use small -model to compile cjpeg or djpeg by itself, but you will probably have to use -medium model for any larger application. This won't make much difference in -performance. You *will* take a noticeable performance hit if you use a -large-data memory model (perhaps 10%-25%), and you should avoid "huge" model -if at all possible. - -The JPEG library typically needs 2Kb-3Kb of stack space. It will also -malloc about 20K-30K of near heap space while executing (and lots of far -heap, but that doesn't count in this calculation). This figure will vary -depending on selected operating mode, and to a lesser extent on image size. -There is also about 5Kb-6Kb of constant data which will be allocated in the -near data segment (about 4Kb of this is the error message table). -Thus you have perhaps 20K available for other modules' static data and near -heap space before you need to go to a larger memory model. The C library's -static data will account for several K of this, but that still leaves a good -deal for your needs. (If you are tight on space, you could reduce the sizes -of the I/O buffers allocated by jdatasrc.c and jdatadst.c, say from 4K to -1K. Another possibility is to move the error message table to far memory; -this should be doable with only localized hacking on jerror.c.) - -About 2K of the near heap space is "permanent" memory that will not be -released until you destroy the JPEG object. This is only an issue if you -save a JPEG object between compression or decompression operations. - -Far data space may also be a tight resource when you are dealing with large -images. The most memory-intensive case is decompression with two-pass color -quantization, or single-pass quantization to an externally supplied color -map. This requires a 128Kb color lookup table plus strip buffers amounting -to about 40 bytes per column for typical sampling ratios (eg, about 25600 -bytes for a 640-pixel-wide image). You may not be able to process wide -images if you have large data structures of your own. - -Of course, all of these concerns vanish if you use a 32-bit flat-memory-model -compiler, such as DJGPP or Watcom C. We highly recommend flat model if you -can use it; the JPEG library is significantly faster in flat model. +USING THE IJG JPEG LIBRARY + +Copyright (C) 1994-2011, Thomas G. Lane, Guido Vollbeding. +This file is part of the Independent JPEG Group's software. +For conditions of distribution and use, see the accompanying README file. + + +This file describes how to use the IJG JPEG library within an application +program. Read it if you want to write a program that uses the library. + +The file example.c provides heavily commented skeleton code for calling the +JPEG library. Also see jpeglib.h (the include file to be used by application +programs) for full details about data structures and function parameter lists. +The library source code, of course, is the ultimate reference. + +Note that there have been *major* changes from the application interface +presented by IJG version 4 and earlier versions. The old design had several +inherent limitations, and it had accumulated a lot of cruft as we added +features while trying to minimize application-interface changes. We have +sacrificed backward compatibility in the version 5 rewrite, but we think the +improvements justify this. + + +TABLE OF CONTENTS +----------------- + +Overview: + Functions provided by the library + Outline of typical usage +Basic library usage: + Data formats + Compression details + Decompression details + Mechanics of usage: include files, linking, etc +Advanced features: + Compression parameter selection + Decompression parameter selection + Special color spaces + Error handling + Compressed data handling (source and destination managers) + I/O suspension + Progressive JPEG support + Buffered-image mode + Abbreviated datastreams and multiple images + Special markers + Raw (downsampled) image data + Really raw data: DCT coefficients + Progress monitoring + Memory management + Memory usage + Library compile-time options + Portability considerations + Notes for MS-DOS implementors + +You should read at least the overview and basic usage sections before trying +to program with the library. The sections on advanced features can be read +if and when you need them. + + +OVERVIEW +======== + +Functions provided by the library +--------------------------------- + +The IJG JPEG library provides C code to read and write JPEG-compressed image +files. The surrounding application program receives or supplies image data a +scanline at a time, using a straightforward uncompressed image format. All +details of color conversion and other preprocessing/postprocessing can be +handled by the library. + +The library includes a substantial amount of code that is not covered by the +JPEG standard but is necessary for typical applications of JPEG. These +functions preprocess the image before JPEG compression or postprocess it after +decompression. They include colorspace conversion, downsampling/upsampling, +and color quantization. The application indirectly selects use of this code +by specifying the format in which it wishes to supply or receive image data. +For example, if colormapped output is requested, then the decompression +library automatically invokes color quantization. + +A wide range of quality vs. speed tradeoffs are possible in JPEG processing, +and even more so in decompression postprocessing. The decompression library +provides multiple implementations that cover most of the useful tradeoffs, +ranging from very-high-quality down to fast-preview operation. On the +compression side we have generally not provided low-quality choices, since +compression is normally less time-critical. It should be understood that the +low-quality modes may not meet the JPEG standard's accuracy requirements; +nonetheless, they are useful for viewers. + +A word about functions *not* provided by the library. We handle a subset of +the ISO JPEG standard; most baseline, extended-sequential, and progressive +JPEG processes are supported. (Our subset includes all features now in common +use.) Unsupported ISO options include: + * Hierarchical storage + * Lossless JPEG + * DNL marker + * Nonintegral subsampling ratios +We support both 8- and 12-bit data precision, but this is a compile-time +choice rather than a run-time choice; hence it is difficult to use both +precisions in a single application. + +By itself, the library handles only interchange JPEG datastreams --- in +particular the widely used JFIF file format. The library can be used by +surrounding code to process interchange or abbreviated JPEG datastreams that +are embedded in more complex file formats. (For example, this library is +used by the free LIBTIFF library to support JPEG compression in TIFF.) + + +Outline of typical usage +------------------------ + +The rough outline of a JPEG compression operation is: + + Allocate and initialize a JPEG compression object + Specify the destination for the compressed data (eg, a file) + Set parameters for compression, including image size & colorspace + jpeg_start_compress(...); + while (scan lines remain to be written) + jpeg_write_scanlines(...); + jpeg_finish_compress(...); + Release the JPEG compression object + +A JPEG compression object holds parameters and working state for the JPEG +library. We make creation/destruction of the object separate from starting +or finishing compression of an image; the same object can be re-used for a +series of image compression operations. This makes it easy to re-use the +same parameter settings for a sequence of images. Re-use of a JPEG object +also has important implications for processing abbreviated JPEG datastreams, +as discussed later. + +The image data to be compressed is supplied to jpeg_write_scanlines() from +in-memory buffers. If the application is doing file-to-file compression, +reading image data from the source file is the application's responsibility. +The library emits compressed data by calling a "data destination manager", +which typically will write the data into a file; but the application can +provide its own destination manager to do something else. + +Similarly, the rough outline of a JPEG decompression operation is: + + Allocate and initialize a JPEG decompression object + Specify the source of the compressed data (eg, a file) + Call jpeg_read_header() to obtain image info + Set parameters for decompression + jpeg_start_decompress(...); + while (scan lines remain to be read) + jpeg_read_scanlines(...); + jpeg_finish_decompress(...); + Release the JPEG decompression object + +This is comparable to the compression outline except that reading the +datastream header is a separate step. This is helpful because information +about the image's size, colorspace, etc is available when the application +selects decompression parameters. For example, the application can choose an +output scaling ratio that will fit the image into the available screen size. + +The decompression library obtains compressed data by calling a data source +manager, which typically will read the data from a file; but other behaviors +can be obtained with a custom source manager. Decompressed data is delivered +into in-memory buffers passed to jpeg_read_scanlines(). + +It is possible to abort an incomplete compression or decompression operation +by calling jpeg_abort(); or, if you do not need to retain the JPEG object, +simply release it by calling jpeg_destroy(). + +JPEG compression and decompression objects are two separate struct types. +However, they share some common fields, and certain routines such as +jpeg_destroy() can work on either type of object. + +The JPEG library has no static variables: all state is in the compression +or decompression object. Therefore it is possible to process multiple +compression and decompression operations concurrently, using multiple JPEG +objects. + +Both compression and decompression can be done in an incremental memory-to- +memory fashion, if suitable source/destination managers are used. See the +section on "I/O suspension" for more details. + + +BASIC LIBRARY USAGE +=================== + +Data formats +------------ + +Before diving into procedural details, it is helpful to understand the +image data format that the JPEG library expects or returns. + +The standard input image format is a rectangular array of pixels, with each +pixel having the same number of "component" or "sample" values (color +channels). You must specify how many components there are and the colorspace +interpretation of the components. Most applications will use RGB data +(three components per pixel) or grayscale data (one component per pixel). +PLEASE NOTE THAT RGB DATA IS THREE SAMPLES PER PIXEL, GRAYSCALE ONLY ONE. +A remarkable number of people manage to miss this, only to find that their +programs don't work with grayscale JPEG files. + +There is no provision for colormapped input. JPEG files are always full-color +or full grayscale (or sometimes another colorspace such as CMYK). You can +feed in a colormapped image by expanding it to full-color format. However +JPEG often doesn't work very well with source data that has been colormapped, +because of dithering noise. This is discussed in more detail in the JPEG FAQ +and the other references mentioned in the README file. + +Pixels are stored by scanlines, with each scanline running from left to +right. The component values for each pixel are adjacent in the row; for +example, R,G,B,R,G,B,R,G,B,... for 24-bit RGB color. Each scanline is an +array of data type JSAMPLE --- which is typically "unsigned char", unless +you've changed jmorecfg.h. (You can also change the RGB pixel layout, say +to B,G,R order, by modifying jmorecfg.h. But see the restrictions listed in +that file before doing so.) + +A 2-D array of pixels is formed by making a list of pointers to the starts of +scanlines; so the scanlines need not be physically adjacent in memory. Even +if you process just one scanline at a time, you must make a one-element +pointer array to conform to this structure. Pointers to JSAMPLE rows are of +type JSAMPROW, and the pointer to the pointer array is of type JSAMPARRAY. + +The library accepts or supplies one or more complete scanlines per call. +It is not possible to process part of a row at a time. Scanlines are always +processed top-to-bottom. You can process an entire image in one call if you +have it all in memory, but usually it's simplest to process one scanline at +a time. + +For best results, source data values should have the precision specified by +BITS_IN_JSAMPLE (normally 8 bits). For instance, if you choose to compress +data that's only 6 bits/channel, you should left-justify each value in a +byte before passing it to the compressor. If you need to compress data +that has more than 8 bits/channel, compile with BITS_IN_JSAMPLE = 12. +(See "Library compile-time options", later.) + + +The data format returned by the decompressor is the same in all details, +except that colormapped output is supported. (Again, a JPEG file is never +colormapped. But you can ask the decompressor to perform on-the-fly color +quantization to deliver colormapped output.) If you request colormapped +output then the returned data array contains a single JSAMPLE per pixel; +its value is an index into a color map. The color map is represented as +a 2-D JSAMPARRAY in which each row holds the values of one color component, +that is, colormap[i][j] is the value of the i'th color component for pixel +value (map index) j. Note that since the colormap indexes are stored in +JSAMPLEs, the maximum number of colors is limited by the size of JSAMPLE +(ie, at most 256 colors for an 8-bit JPEG library). + + +Compression details +------------------- + +Here we revisit the JPEG compression outline given in the overview. + +1. Allocate and initialize a JPEG compression object. + +A JPEG compression object is a "struct jpeg_compress_struct". (It also has +a bunch of subsidiary structures which are allocated via malloc(), but the +application doesn't control those directly.) This struct can be just a local +variable in the calling routine, if a single routine is going to execute the +whole JPEG compression sequence. Otherwise it can be static or allocated +from malloc(). + +You will also need a structure representing a JPEG error handler. The part +of this that the library cares about is a "struct jpeg_error_mgr". If you +are providing your own error handler, you'll typically want to embed the +jpeg_error_mgr struct in a larger structure; this is discussed later under +"Error handling". For now we'll assume you are just using the default error +handler. The default error handler will print JPEG error/warning messages +on stderr, and it will call exit() if a fatal error occurs. + +You must initialize the error handler structure, store a pointer to it into +the JPEG object's "err" field, and then call jpeg_create_compress() to +initialize the rest of the JPEG object. + +Typical code for this step, if you are using the default error handler, is + + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; + ... + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_compress(&cinfo); + +jpeg_create_compress allocates a small amount of memory, so it could fail +if you are out of memory. In that case it will exit via the error handler; +that's why the error handler must be initialized first. + + +2. Specify the destination for the compressed data (eg, a file). + +As previously mentioned, the JPEG library delivers compressed data to a +"data destination" module. The library includes one data destination +module which knows how to write to a stdio stream. You can use your own +destination module if you want to do something else, as discussed later. + +If you use the standard destination module, you must open the target stdio +stream beforehand. Typical code for this step looks like: + + FILE * outfile; + ... + if ((outfile = fopen(filename, "wb")) == NULL) { + fprintf(stderr, "can't open %s\n", filename); + exit(1); + } + jpeg_stdio_dest(&cinfo, outfile); + +where the last line invokes the standard destination module. + +WARNING: it is critical that the binary compressed data be delivered to the +output file unchanged. On non-Unix systems the stdio library may perform +newline translation or otherwise corrupt binary data. To suppress this +behavior, you may need to use a "b" option to fopen (as shown above), or use +setmode() or another routine to put the stdio stream in binary mode. See +cjpeg.c and djpeg.c for code that has been found to work on many systems. + +You can select the data destination after setting other parameters (step 3), +if that's more convenient. You may not change the destination between +calling jpeg_start_compress() and jpeg_finish_compress(). + + +3. Set parameters for compression, including image size & colorspace. + +You must supply information about the source image by setting the following +fields in the JPEG object (cinfo structure): + + image_width Width of image, in pixels + image_height Height of image, in pixels + input_components Number of color channels (samples per pixel) + in_color_space Color space of source image + +The image dimensions are, hopefully, obvious. JPEG supports image dimensions +of 1 to 64K pixels in either direction. The input color space is typically +RGB or grayscale, and input_components is 3 or 1 accordingly. (See "Special +color spaces", later, for more info.) The in_color_space field must be +assigned one of the J_COLOR_SPACE enum constants, typically JCS_RGB or +JCS_GRAYSCALE. + +JPEG has a large number of compression parameters that determine how the +image is encoded. Most applications don't need or want to know about all +these parameters. You can set all the parameters to reasonable defaults by +calling jpeg_set_defaults(); then, if there are particular values you want +to change, you can do so after that. The "Compression parameter selection" +section tells about all the parameters. + +You must set in_color_space correctly before calling jpeg_set_defaults(), +because the defaults depend on the source image colorspace. However the +other three source image parameters need not be valid until you call +jpeg_start_compress(). There's no harm in calling jpeg_set_defaults() more +than once, if that happens to be convenient. + +Typical code for a 24-bit RGB source image is + + cinfo.image_width = Width; /* image width and height, in pixels */ + cinfo.image_height = Height; + cinfo.input_components = 3; /* # of color components per pixel */ + cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ + + jpeg_set_defaults(&cinfo); + /* Make optional parameter settings here */ + + +4. jpeg_start_compress(...); + +After you have established the data destination and set all the necessary +source image info and other parameters, call jpeg_start_compress() to begin +a compression cycle. This will initialize internal state, allocate working +storage, and emit the first few bytes of the JPEG datastream header. + +Typical code: + + jpeg_start_compress(&cinfo, TRUE); + +The "TRUE" parameter ensures that a complete JPEG interchange datastream +will be written. This is appropriate in most cases. If you think you might +want to use an abbreviated datastream, read the section on abbreviated +datastreams, below. + +Once you have called jpeg_start_compress(), you may not alter any JPEG +parameters or other fields of the JPEG object until you have completed +the compression cycle. + + +5. while (scan lines remain to be written) + jpeg_write_scanlines(...); + +Now write all the required image data by calling jpeg_write_scanlines() +one or more times. You can pass one or more scanlines in each call, up +to the total image height. In most applications it is convenient to pass +just one or a few scanlines at a time. The expected format for the passed +data is discussed under "Data formats", above. + +Image data should be written in top-to-bottom scanline order. The JPEG spec +contains some weasel wording about how top and bottom are application-defined +terms (a curious interpretation of the English language...) but if you want +your files to be compatible with everyone else's, you WILL use top-to-bottom +order. If the source data must be read in bottom-to-top order, you can use +the JPEG library's virtual array mechanism to invert the data efficiently. +Examples of this can be found in the sample application cjpeg. + +The library maintains a count of the number of scanlines written so far +in the next_scanline field of the JPEG object. Usually you can just use +this variable as the loop counter, so that the loop test looks like +"while (cinfo.next_scanline < cinfo.image_height)". + +Code for this step depends heavily on the way that you store the source data. +example.c shows the following code for the case of a full-size 2-D source +array containing 3-byte RGB pixels: + + JSAMPROW row_pointer[1]; /* pointer to a single row */ + int row_stride; /* physical row width in buffer */ + + row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */ + + while (cinfo.next_scanline < cinfo.image_height) { + row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride]; + jpeg_write_scanlines(&cinfo, row_pointer, 1); + } + +jpeg_write_scanlines() returns the number of scanlines actually written. +This will normally be equal to the number passed in, so you can usually +ignore the return value. It is different in just two cases: + * If you try to write more scanlines than the declared image height, + the additional scanlines are ignored. + * If you use a suspending data destination manager, output buffer overrun + will cause the compressor to return before accepting all the passed lines. + This feature is discussed under "I/O suspension", below. The normal + stdio destination manager will NOT cause this to happen. +In any case, the return value is the same as the change in the value of +next_scanline. + + +6. jpeg_finish_compress(...); + +After all the image data has been written, call jpeg_finish_compress() to +complete the compression cycle. This step is ESSENTIAL to ensure that the +last bufferload of data is written to the data destination. +jpeg_finish_compress() also releases working memory associated with the JPEG +object. + +Typical code: + + jpeg_finish_compress(&cinfo); + +If using the stdio destination manager, don't forget to close the output +stdio stream (if necessary) afterwards. + +If you have requested a multi-pass operating mode, such as Huffman code +optimization, jpeg_finish_compress() will perform the additional passes using +data buffered by the first pass. In this case jpeg_finish_compress() may take +quite a while to complete. With the default compression parameters, this will +not happen. + +It is an error to call jpeg_finish_compress() before writing the necessary +total number of scanlines. If you wish to abort compression, call +jpeg_abort() as discussed below. + +After completing a compression cycle, you may dispose of the JPEG object +as discussed next, or you may use it to compress another image. In that case +return to step 2, 3, or 4 as appropriate. If you do not change the +destination manager, the new datastream will be written to the same target. +If you do not change any JPEG parameters, the new datastream will be written +with the same parameters as before. Note that you can change the input image +dimensions freely between cycles, but if you change the input colorspace, you +should call jpeg_set_defaults() to adjust for the new colorspace; and then +you'll need to repeat all of step 3. + + +7. Release the JPEG compression object. + +When you are done with a JPEG compression object, destroy it by calling +jpeg_destroy_compress(). This will free all subsidiary memory (regardless of +the previous state of the object). Or you can call jpeg_destroy(), which +works for either compression or decompression objects --- this may be more +convenient if you are sharing code between compression and decompression +cases. (Actually, these routines are equivalent except for the declared type +of the passed pointer. To avoid gripes from ANSI C compilers, jpeg_destroy() +should be passed a j_common_ptr.) + +If you allocated the jpeg_compress_struct structure from malloc(), freeing +it is your responsibility --- jpeg_destroy() won't. Ditto for the error +handler structure. + +Typical code: + + jpeg_destroy_compress(&cinfo); + + +8. Aborting. + +If you decide to abort a compression cycle before finishing, you can clean up +in either of two ways: + +* If you don't need the JPEG object any more, just call + jpeg_destroy_compress() or jpeg_destroy() to release memory. This is + legitimate at any point after calling jpeg_create_compress() --- in fact, + it's safe even if jpeg_create_compress() fails. + +* If you want to re-use the JPEG object, call jpeg_abort_compress(), or call + jpeg_abort() which works on both compression and decompression objects. + This will return the object to an idle state, releasing any working memory. + jpeg_abort() is allowed at any time after successful object creation. + +Note that cleaning up the data destination, if required, is your +responsibility; neither of these routines will call term_destination(). +(See "Compressed data handling", below, for more about that.) + +jpeg_destroy() and jpeg_abort() are the only safe calls to make on a JPEG +object that has reported an error by calling error_exit (see "Error handling" +for more info). The internal state of such an object is likely to be out of +whack. Either of these two routines will return the object to a known state. + + +Decompression details +--------------------- + +Here we revisit the JPEG decompression outline given in the overview. + +1. Allocate and initialize a JPEG decompression object. + +This is just like initialization for compression, as discussed above, +except that the object is a "struct jpeg_decompress_struct" and you +call jpeg_create_decompress(). Error handling is exactly the same. + +Typical code: + + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + ... + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + +(Both here and in the IJG code, we usually use variable name "cinfo" for +both compression and decompression objects.) + + +2. Specify the source of the compressed data (eg, a file). + +As previously mentioned, the JPEG library reads compressed data from a "data +source" module. The library includes one data source module which knows how +to read from a stdio stream. You can use your own source module if you want +to do something else, as discussed later. + +If you use the standard source module, you must open the source stdio stream +beforehand. Typical code for this step looks like: + + FILE * infile; + ... + if ((infile = fopen(filename, "rb")) == NULL) { + fprintf(stderr, "can't open %s\n", filename); + exit(1); + } + jpeg_stdio_src(&cinfo, infile); + +where the last line invokes the standard source module. + +WARNING: it is critical that the binary compressed data be read unchanged. +On non-Unix systems the stdio library may perform newline translation or +otherwise corrupt binary data. To suppress this behavior, you may need to use +a "b" option to fopen (as shown above), or use setmode() or another routine to +put the stdio stream in binary mode. See cjpeg.c and djpeg.c for code that +has been found to work on many systems. + +You may not change the data source between calling jpeg_read_header() and +jpeg_finish_decompress(). If you wish to read a series of JPEG images from +a single source file, you should repeat the jpeg_read_header() to +jpeg_finish_decompress() sequence without reinitializing either the JPEG +object or the data source module; this prevents buffered input data from +being discarded. + + +3. Call jpeg_read_header() to obtain image info. + +Typical code for this step is just + + jpeg_read_header(&cinfo, TRUE); + +This will read the source datastream header markers, up to the beginning +of the compressed data proper. On return, the image dimensions and other +info have been stored in the JPEG object. The application may wish to +consult this information before selecting decompression parameters. + +More complex code is necessary if + * A suspending data source is used --- in that case jpeg_read_header() + may return before it has read all the header data. See "I/O suspension", + below. The normal stdio source manager will NOT cause this to happen. + * Abbreviated JPEG files are to be processed --- see the section on + abbreviated datastreams. Standard applications that deal only in + interchange JPEG files need not be concerned with this case either. + +It is permissible to stop at this point if you just wanted to find out the +image dimensions and other header info for a JPEG file. In that case, +call jpeg_destroy() when you are done with the JPEG object, or call +jpeg_abort() to return it to an idle state before selecting a new data +source and reading another header. + + +4. Set parameters for decompression. + +jpeg_read_header() sets appropriate default decompression parameters based on +the properties of the image (in particular, its colorspace). However, you +may well want to alter these defaults before beginning the decompression. +For example, the default is to produce full color output from a color file. +If you want colormapped output you must ask for it. Other options allow the +returned image to be scaled and allow various speed/quality tradeoffs to be +selected. "Decompression parameter selection", below, gives details. + +If the defaults are appropriate, nothing need be done at this step. + +Note that all default values are set by each call to jpeg_read_header(). +If you reuse a decompression object, you cannot expect your parameter +settings to be preserved across cycles, as you can for compression. +You must set desired parameter values each time. + + +5. jpeg_start_decompress(...); + +Once the parameter values are satisfactory, call jpeg_start_decompress() to +begin decompression. This will initialize internal state, allocate working +memory, and prepare for returning data. + +Typical code is just + + jpeg_start_decompress(&cinfo); + +If you have requested a multi-pass operating mode, such as 2-pass color +quantization, jpeg_start_decompress() will do everything needed before data +output can begin. In this case jpeg_start_decompress() may take quite a while +to complete. With a single-scan (non progressive) JPEG file and default +decompression parameters, this will not happen; jpeg_start_decompress() will +return quickly. + +After this call, the final output image dimensions, including any requested +scaling, are available in the JPEG object; so is the selected colormap, if +colormapped output has been requested. Useful fields include + + output_width image width and height, as scaled + output_height + out_color_components # of color components in out_color_space + output_components # of color components returned per pixel + colormap the selected colormap, if any + actual_number_of_colors number of entries in colormap + +output_components is 1 (a colormap index) when quantizing colors; otherwise it +equals out_color_components. It is the number of JSAMPLE values that will be +emitted per pixel in the output arrays. + +Typically you will need to allocate data buffers to hold the incoming image. +You will need output_width * output_components JSAMPLEs per scanline in your +output buffer, and a total of output_height scanlines will be returned. + +Note: if you are using the JPEG library's internal memory manager to allocate +data buffers (as djpeg does), then the manager's protocol requires that you +request large buffers *before* calling jpeg_start_decompress(). This is a +little tricky since the output_XXX fields are not normally valid then. You +can make them valid by calling jpeg_calc_output_dimensions() after setting the +relevant parameters (scaling, output color space, and quantization flag). + + +6. while (scan lines remain to be read) + jpeg_read_scanlines(...); + +Now you can read the decompressed image data by calling jpeg_read_scanlines() +one or more times. At each call, you pass in the maximum number of scanlines +to be read (ie, the height of your working buffer); jpeg_read_scanlines() +will return up to that many lines. The return value is the number of lines +actually read. The format of the returned data is discussed under "Data +formats", above. Don't forget that grayscale and color JPEGs will return +different data formats! + +Image data is returned in top-to-bottom scanline order. If you must write +out the image in bottom-to-top order, you can use the JPEG library's virtual +array mechanism to invert the data efficiently. Examples of this can be +found in the sample application djpeg. + +The library maintains a count of the number of scanlines returned so far +in the output_scanline field of the JPEG object. Usually you can just use +this variable as the loop counter, so that the loop test looks like +"while (cinfo.output_scanline < cinfo.output_height)". (Note that the test +should NOT be against image_height, unless you never use scaling. The +image_height field is the height of the original unscaled image.) +The return value always equals the change in the value of output_scanline. + +If you don't use a suspending data source, it is safe to assume that +jpeg_read_scanlines() reads at least one scanline per call, until the +bottom of the image has been reached. + +If you use a buffer larger than one scanline, it is NOT safe to assume that +jpeg_read_scanlines() fills it. (The current implementation returns only a +few scanlines per call, no matter how large a buffer you pass.) So you must +always provide a loop that calls jpeg_read_scanlines() repeatedly until the +whole image has been read. + + +7. jpeg_finish_decompress(...); + +After all the image data has been read, call jpeg_finish_decompress() to +complete the decompression cycle. This causes working memory associated +with the JPEG object to be released. + +Typical code: + + jpeg_finish_decompress(&cinfo); + +If using the stdio source manager, don't forget to close the source stdio +stream if necessary. + +It is an error to call jpeg_finish_decompress() before reading the correct +total number of scanlines. If you wish to abort decompression, call +jpeg_abort() as discussed below. + +After completing a decompression cycle, you may dispose of the JPEG object as +discussed next, or you may use it to decompress another image. In that case +return to step 2 or 3 as appropriate. If you do not change the source +manager, the next image will be read from the same source. + + +8. Release the JPEG decompression object. + +When you are done with a JPEG decompression object, destroy it by calling +jpeg_destroy_decompress() or jpeg_destroy(). The previous discussion of +destroying compression objects applies here too. + +Typical code: + + jpeg_destroy_decompress(&cinfo); + + +9. Aborting. + +You can abort a decompression cycle by calling jpeg_destroy_decompress() or +jpeg_destroy() if you don't need the JPEG object any more, or +jpeg_abort_decompress() or jpeg_abort() if you want to reuse the object. +The previous discussion of aborting compression cycles applies here too. + + +Mechanics of usage: include files, linking, etc +----------------------------------------------- + +Applications using the JPEG library should include the header file jpeglib.h +to obtain declarations of data types and routines. Before including +jpeglib.h, include system headers that define at least the typedefs FILE and +size_t. On ANSI-conforming systems, including is sufficient; on +older Unix systems, you may need to define size_t. + +If the application needs to refer to individual JPEG library error codes, also +include jerror.h to define those symbols. + +jpeglib.h indirectly includes the files jconfig.h and jmorecfg.h. If you are +installing the JPEG header files in a system directory, you will want to +install all four files: jpeglib.h, jerror.h, jconfig.h, jmorecfg.h. + +The most convenient way to include the JPEG code into your executable program +is to prepare a library file ("libjpeg.a", or a corresponding name on non-Unix +machines) and reference it at your link step. If you use only half of the +library (only compression or only decompression), only that much code will be +included from the library, unless your linker is hopelessly brain-damaged. +The supplied makefiles build libjpeg.a automatically (see install.txt). + +While you can build the JPEG library as a shared library if the whim strikes +you, we don't really recommend it. The trouble with shared libraries is that +at some point you'll probably try to substitute a new version of the library +without recompiling the calling applications. That generally doesn't work +because the parameter struct declarations usually change with each new +version. In other words, the library's API is *not* guaranteed binary +compatible across versions; we only try to ensure source-code compatibility. +(In hindsight, it might have been smarter to hide the parameter structs from +applications and introduce a ton of access functions instead. Too late now, +however.) + +On some systems your application may need to set up a signal handler to ensure +that temporary files are deleted if the program is interrupted. This is most +critical if you are on MS-DOS and use the jmemdos.c memory manager back end; +it will try to grab extended memory for temp files, and that space will NOT be +freed automatically. See cjpeg.c or djpeg.c for an example signal handler. + +It may be worth pointing out that the core JPEG library does not actually +require the stdio library: only the default source/destination managers and +error handler need it. You can use the library in a stdio-less environment +if you replace those modules and use jmemnobs.c (or another memory manager of +your own devising). More info about the minimum system library requirements +may be found in jinclude.h. + + +ADVANCED FEATURES +================= + +Compression parameter selection +------------------------------- + +This section describes all the optional parameters you can set for JPEG +compression, as well as the "helper" routines provided to assist in this +task. Proper setting of some parameters requires detailed understanding +of the JPEG standard; if you don't know what a parameter is for, it's best +not to mess with it! See REFERENCES in the README file for pointers to +more info about JPEG. + +It's a good idea to call jpeg_set_defaults() first, even if you plan to set +all the parameters; that way your code is more likely to work with future JPEG +libraries that have additional parameters. For the same reason, we recommend +you use a helper routine where one is provided, in preference to twiddling +cinfo fields directly. + +The helper routines are: + +jpeg_set_defaults (j_compress_ptr cinfo) + This routine sets all JPEG parameters to reasonable defaults, using + only the input image's color space (field in_color_space, which must + already be set in cinfo). Many applications will only need to use + this routine and perhaps jpeg_set_quality(). + +jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace) + Sets the JPEG file's colorspace (field jpeg_color_space) as specified, + and sets other color-space-dependent parameters appropriately. See + "Special color spaces", below, before using this. A large number of + parameters, including all per-component parameters, are set by this + routine; if you want to twiddle individual parameters you should call + jpeg_set_colorspace() before rather than after. + +jpeg_default_colorspace (j_compress_ptr cinfo) + Selects an appropriate JPEG colorspace based on cinfo->in_color_space, + and calls jpeg_set_colorspace(). This is actually a subroutine of + jpeg_set_defaults(). It's broken out in case you want to change + just the colorspace-dependent JPEG parameters. + +jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline) + Constructs JPEG quantization tables appropriate for the indicated + quality setting. The quality value is expressed on the 0..100 scale + recommended by IJG (cjpeg's "-quality" switch uses this routine). + Note that the exact mapping from quality values to tables may change + in future IJG releases as more is learned about DCT quantization. + If the force_baseline parameter is TRUE, then the quantization table + entries are constrained to the range 1..255 for full JPEG baseline + compatibility. In the current implementation, this only makes a + difference for quality settings below 25, and it effectively prevents + very small/low quality files from being generated. The IJG decoder + is capable of reading the non-baseline files generated at low quality + settings when force_baseline is FALSE, but other decoders may not be. + +jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, + boolean force_baseline) + Same as jpeg_set_quality() except that the generated tables are the + sample tables given in the JPEC spec section K.1, multiplied by the + specified scale factor (which is expressed as a percentage; thus + scale_factor = 100 reproduces the spec's tables). Note that larger + scale factors give lower quality. This entry point is useful for + conforming to the Adobe PostScript DCT conventions, but we do not + recommend linear scaling as a user-visible quality scale otherwise. + force_baseline again constrains the computed table entries to 1..255. + +int jpeg_quality_scaling (int quality) + Converts a value on the IJG-recommended quality scale to a linear + scaling percentage. Note that this routine may change or go away + in future releases --- IJG may choose to adopt a scaling method that + can't be expressed as a simple scalar multiplier, in which case the + premise of this routine collapses. Caveat user. + +jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline) + Set default quantization tables with linear q_scale_factor[] values + (see below). + +jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl, + const unsigned int *basic_table, + int scale_factor, boolean force_baseline) + Allows an arbitrary quantization table to be created. which_tbl + indicates which table slot to fill. basic_table points to an array + of 64 unsigned ints given in normal array order. These values are + multiplied by scale_factor/100 and then clamped to the range 1..65535 + (or to 1..255 if force_baseline is TRUE). + CAUTION: prior to library version 6a, jpeg_add_quant_table expected + the basic table to be given in JPEG zigzag order. If you need to + write code that works with either older or newer versions of this + routine, you must check the library version number. Something like + "#if JPEG_LIB_VERSION >= 61" is the right test. + +jpeg_simple_progression (j_compress_ptr cinfo) + Generates a default scan script for writing a progressive-JPEG file. + This is the recommended method of creating a progressive file, + unless you want to make a custom scan sequence. You must ensure that + the JPEG color space is set correctly before calling this routine. + + +Compression parameters (cinfo fields) include: + +int block_size + Set DCT block size. All N from 1 to 16 are possible. + Default is 8 (baseline format). + Larger values produce higher compression, + smaller values produce higher quality. + An exact DCT stage is possible with 1 or 2. + With the default quality of 75 and default Luminance qtable + the DCT+Quantization stage is lossless for value 1. + Note that values other than 8 require a SmartScale capable decoder, + introduced with IJG JPEG 8. Setting the block_size parameter for + compression works with version 8c and later. + +J_DCT_METHOD dct_method + Selects the algorithm used for the DCT step. Choices are: + JDCT_ISLOW: slow but accurate integer algorithm + JDCT_IFAST: faster, less accurate integer method + JDCT_FLOAT: floating-point method + JDCT_DEFAULT: default method (normally JDCT_ISLOW) + JDCT_FASTEST: fastest method (normally JDCT_IFAST) + The FLOAT method is very slightly more accurate than the ISLOW method, + but may give different results on different machines due to varying + roundoff behavior. The integer methods should give the same results + on all machines. On machines with sufficiently fast FP hardware, the + floating-point method may also be the fastest. The IFAST method is + considerably less accurate than the other two; its use is not + recommended if high quality is a concern. JDCT_DEFAULT and + JDCT_FASTEST are macros configurable by each installation. + +unsigned int scale_num, scale_denom + Scale the image by the fraction scale_num/scale_denom. Default is + 1/1, or no scaling. Currently, the supported scaling ratios are + M/N with all N from 1 to 16, where M is the destination DCT size, + which is 8 by default (see block_size parameter above). + (The library design allows for arbitrary scaling ratios but this + is not likely to be implemented any time soon.) + +J_COLOR_SPACE jpeg_color_space +int num_components + The JPEG color space and corresponding number of components; see + "Special color spaces", below, for more info. We recommend using + jpeg_set_color_space() if you want to change these. + +boolean optimize_coding + TRUE causes the compressor to compute optimal Huffman coding tables + for the image. This requires an extra pass over the data and + therefore costs a good deal of space and time. The default is + FALSE, which tells the compressor to use the supplied or default + Huffman tables. In most cases optimal tables save only a few percent + of file size compared to the default tables. Note that when this is + TRUE, you need not supply Huffman tables at all, and any you do + supply will be overwritten. + +unsigned int restart_interval +int restart_in_rows + To emit restart markers in the JPEG file, set one of these nonzero. + Set restart_interval to specify the exact interval in MCU blocks. + Set restart_in_rows to specify the interval in MCU rows. (If + restart_in_rows is not 0, then restart_interval is set after the + image width in MCUs is computed.) Defaults are zero (no restarts). + One restart marker per MCU row is often a good choice. + NOTE: the overhead of restart markers is higher in grayscale JPEG + files than in color files, and MUCH higher in progressive JPEGs. + If you use restarts, you may want to use larger intervals in those + cases. + +const jpeg_scan_info * scan_info +int num_scans + By default, scan_info is NULL; this causes the compressor to write a + single-scan sequential JPEG file. If not NULL, scan_info points to + an array of scan definition records of length num_scans. The + compressor will then write a JPEG file having one scan for each scan + definition record. This is used to generate noninterleaved or + progressive JPEG files. The library checks that the scan array + defines a valid JPEG scan sequence. (jpeg_simple_progression creates + a suitable scan definition array for progressive JPEG.) This is + discussed further under "Progressive JPEG support". + +boolean do_fancy_downsampling + If TRUE, use direct DCT scaling with DCT size > 8 for downsampling + of chroma components. + If FALSE, use only DCT size <= 8 and simple separate downsampling. + Default is TRUE. + For better image stability in multiple generation compression cycles + it is preferable that this value matches the corresponding + do_fancy_upsampling value in decompression. + +int smoothing_factor + If non-zero, the input image is smoothed; the value should be 1 for + minimal smoothing to 100 for maximum smoothing. Consult jcsample.c + for details of the smoothing algorithm. The default is zero. + +boolean write_JFIF_header + If TRUE, a JFIF APP0 marker is emitted. jpeg_set_defaults() and + jpeg_set_colorspace() set this TRUE if a JFIF-legal JPEG color space + (ie, YCbCr or grayscale) is selected, otherwise FALSE. + +UINT8 JFIF_major_version +UINT8 JFIF_minor_version + The version number to be written into the JFIF marker. + jpeg_set_defaults() initializes the version to 1.01 (major=minor=1). + You should set it to 1.02 (major=1, minor=2) if you plan to write + any JFIF 1.02 extension markers. + +UINT8 density_unit +UINT16 X_density +UINT16 Y_density + The resolution information to be written into the JFIF marker; + not used otherwise. density_unit may be 0 for unknown, + 1 for dots/inch, or 2 for dots/cm. The default values are 0,1,1 + indicating square pixels of unknown size. + +boolean write_Adobe_marker + If TRUE, an Adobe APP14 marker is emitted. jpeg_set_defaults() and + jpeg_set_colorspace() set this TRUE if JPEG color space RGB, CMYK, + or YCCK is selected, otherwise FALSE. It is generally a bad idea + to set both write_JFIF_header and write_Adobe_marker. In fact, + you probably shouldn't change the default settings at all --- the + default behavior ensures that the JPEG file's color space can be + recognized by the decoder. + +JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS] + Pointers to coefficient quantization tables, one per table slot, + or NULL if no table is defined for a slot. Usually these should + be set via one of the above helper routines; jpeg_add_quant_table() + is general enough to define any quantization table. The other + routines will set up table slot 0 for luminance quality and table + slot 1 for chrominance. + +int q_scale_factor[NUM_QUANT_TBLS] + Linear quantization scaling factors (percentage, initialized 100) + for use with jpeg_default_qtables(). + See rdswitch.c and cjpeg.c for an example of usage. + Note that the q_scale_factor[] fields are the "linear" scales, so you + have to convert from user-defined ratings via jpeg_quality_scaling(). + Here is an example code which corresponds to cjpeg -quality 90,70: + + jpeg_set_defaults(cinfo); + + /* Set luminance quality 90. */ + cinfo->q_scale_factor[0] = jpeg_quality_scaling(90); + /* Set chrominance quality 70. */ + cinfo->q_scale_factor[1] = jpeg_quality_scaling(70); + + jpeg_default_qtables(cinfo, force_baseline); + + CAUTION: You must also set 1x1 subsampling for efficient separate + color quality selection, since the default value used by library + is 2x2: + + cinfo->comp_info[0].v_samp_factor = 1; + cinfo->comp_info[0].h_samp_factor = 1; + +JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS] +JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS] + Pointers to Huffman coding tables, one per table slot, or NULL if + no table is defined for a slot. Slots 0 and 1 are filled with the + JPEG sample tables by jpeg_set_defaults(). If you need to allocate + more table structures, jpeg_alloc_huff_table() may be used. + Note that optimal Huffman tables can be computed for an image + by setting optimize_coding, as discussed above; there's seldom + any need to mess with providing your own Huffman tables. + + +The actual dimensions of the JPEG image that will be written to the file are +given by the following fields. These are computed from the input image +dimensions and the compression parameters by jpeg_start_compress(). You can +also call jpeg_calc_jpeg_dimensions() to obtain the values that will result +from the current parameter settings. This can be useful if you are trying +to pick a scaling ratio that will get close to a desired target size. + +JDIMENSION jpeg_width Actual dimensions of output image. +JDIMENSION jpeg_height + + +Per-component parameters are stored in the struct cinfo.comp_info[i] for +component number i. Note that components here refer to components of the +JPEG color space, *not* the source image color space. A suitably large +comp_info[] array is allocated by jpeg_set_defaults(); if you choose not +to use that routine, it's up to you to allocate the array. + +int component_id + The one-byte identifier code to be recorded in the JPEG file for + this component. For the standard color spaces, we recommend you + leave the default values alone. + +int h_samp_factor +int v_samp_factor + Horizontal and vertical sampling factors for the component; must + be 1..4 according to the JPEG standard. Note that larger sampling + factors indicate a higher-resolution component; many people find + this behavior quite unintuitive. The default values are 2,2 for + luminance components and 1,1 for chrominance components, except + for grayscale where 1,1 is used. + +int quant_tbl_no + Quantization table number for component. The default value is + 0 for luminance components and 1 for chrominance components. + +int dc_tbl_no +int ac_tbl_no + DC and AC entropy coding table numbers. The default values are + 0 for luminance components and 1 for chrominance components. + +int component_index + Must equal the component's index in comp_info[]. (Beginning in + release v6, the compressor library will fill this in automatically; + you don't have to.) + + +Decompression parameter selection +--------------------------------- + +Decompression parameter selection is somewhat simpler than compression +parameter selection, since all of the JPEG internal parameters are +recorded in the source file and need not be supplied by the application. +(Unless you are working with abbreviated files, in which case see +"Abbreviated datastreams", below.) Decompression parameters control +the postprocessing done on the image to deliver it in a format suitable +for the application's use. Many of the parameters control speed/quality +tradeoffs, in which faster decompression may be obtained at the price of +a poorer-quality image. The defaults select the highest quality (slowest) +processing. + +The following fields in the JPEG object are set by jpeg_read_header() and +may be useful to the application in choosing decompression parameters: + +JDIMENSION image_width Width and height of image +JDIMENSION image_height +int num_components Number of color components +J_COLOR_SPACE jpeg_color_space Colorspace of image +boolean saw_JFIF_marker TRUE if a JFIF APP0 marker was seen + UINT8 JFIF_major_version Version information from JFIF marker + UINT8 JFIF_minor_version + UINT8 density_unit Resolution data from JFIF marker + UINT16 X_density + UINT16 Y_density +boolean saw_Adobe_marker TRUE if an Adobe APP14 marker was seen + UINT8 Adobe_transform Color transform code from Adobe marker + +The JPEG color space, unfortunately, is something of a guess since the JPEG +standard proper does not provide a way to record it. In practice most files +adhere to the JFIF or Adobe conventions, and the decoder will recognize these +correctly. See "Special color spaces", below, for more info. + + +The decompression parameters that determine the basic properties of the +returned image are: + +J_COLOR_SPACE out_color_space + Output color space. jpeg_read_header() sets an appropriate default + based on jpeg_color_space; typically it will be RGB or grayscale. + The application can change this field to request output in a different + colorspace. For example, set it to JCS_GRAYSCALE to get grayscale + output from a color file. (This is useful for previewing: grayscale + output is faster than full color since the color components need not + be processed.) Note that not all possible color space transforms are + currently implemented; you may need to extend jdcolor.c if you want an + unusual conversion. + +unsigned int scale_num, scale_denom + Scale the image by the fraction scale_num/scale_denom. Currently, + the supported scaling ratios are M/N with all M from 1 to 16, where + N is the source DCT size, which is 8 for baseline JPEG. (The library + design allows for arbitrary scaling ratios but this is not likely + to be implemented any time soon.) The values are initialized by + jpeg_read_header() with the source DCT size. For baseline JPEG + this is 8/8. If you change only the scale_num value while leaving + the other unchanged, then this specifies the DCT scaled size to be + applied on the given input. For baseline JPEG this is equivalent + to M/8 scaling, since the source DCT size for baseline JPEG is 8. + Smaller scaling ratios permit significantly faster decoding since + fewer pixels need be processed and a simpler IDCT method can be used. + +boolean quantize_colors + If set TRUE, colormapped output will be delivered. Default is FALSE, + meaning that full-color output will be delivered. + +The next three parameters are relevant only if quantize_colors is TRUE. + +int desired_number_of_colors + Maximum number of colors to use in generating a library-supplied color + map (the actual number of colors is returned in a different field). + Default 256. Ignored when the application supplies its own color map. + +boolean two_pass_quantize + If TRUE, an extra pass over the image is made to select a custom color + map for the image. This usually looks a lot better than the one-size- + fits-all colormap that is used otherwise. Default is TRUE. Ignored + when the application supplies its own color map. + +J_DITHER_MODE dither_mode + Selects color dithering method. Supported values are: + JDITHER_NONE no dithering: fast, very low quality + JDITHER_ORDERED ordered dither: moderate speed and quality + JDITHER_FS Floyd-Steinberg dither: slow, high quality + Default is JDITHER_FS. (At present, ordered dither is implemented + only in the single-pass, standard-colormap case. If you ask for + ordered dither when two_pass_quantize is TRUE or when you supply + an external color map, you'll get F-S dithering.) + +When quantize_colors is TRUE, the target color map is described by the next +two fields. colormap is set to NULL by jpeg_read_header(). The application +can supply a color map by setting colormap non-NULL and setting +actual_number_of_colors to the map size. Otherwise, jpeg_start_decompress() +selects a suitable color map and sets these two fields itself. +[Implementation restriction: at present, an externally supplied colormap is +only accepted for 3-component output color spaces.] + +JSAMPARRAY colormap + The color map, represented as a 2-D pixel array of out_color_components + rows and actual_number_of_colors columns. Ignored if not quantizing. + CAUTION: if the JPEG library creates its own colormap, the storage + pointed to by this field is released by jpeg_finish_decompress(). + Copy the colormap somewhere else first, if you want to save it. + +int actual_number_of_colors + The number of colors in the color map. + +Additional decompression parameters that the application may set include: + +J_DCT_METHOD dct_method + Selects the algorithm used for the DCT step. Choices are the same + as described above for compression. + +boolean do_fancy_upsampling + If TRUE, use direct DCT scaling with DCT size > 8 for upsampling + of chroma components. + If FALSE, use only DCT size <= 8 and simple separate upsampling. + Default is TRUE. + For better image stability in multiple generation compression cycles + it is preferable that this value matches the corresponding + do_fancy_downsampling value in compression. + +boolean do_block_smoothing + If TRUE, interblock smoothing is applied in early stages of decoding + progressive JPEG files; if FALSE, not. Default is TRUE. Early + progression stages look "fuzzy" with smoothing, "blocky" without. + In any case, block smoothing ceases to be applied after the first few + AC coefficients are known to full accuracy, so it is relevant only + when using buffered-image mode for progressive images. + +boolean enable_1pass_quant +boolean enable_external_quant +boolean enable_2pass_quant + These are significant only in buffered-image mode, which is + described in its own section below. + + +The output image dimensions are given by the following fields. These are +computed from the source image dimensions and the decompression parameters +by jpeg_start_decompress(). You can also call jpeg_calc_output_dimensions() +to obtain the values that will result from the current parameter settings. +This can be useful if you are trying to pick a scaling ratio that will get +close to a desired target size. It's also important if you are using the +JPEG library's memory manager to allocate output buffer space, because you +are supposed to request such buffers *before* jpeg_start_decompress(). + +JDIMENSION output_width Actual dimensions of output image. +JDIMENSION output_height +int out_color_components Number of color components in out_color_space. +int output_components Number of color components returned. +int rec_outbuf_height Recommended height of scanline buffer. + +When quantizing colors, output_components is 1, indicating a single color map +index per pixel. Otherwise it equals out_color_components. The output arrays +are required to be output_width * output_components JSAMPLEs wide. + +rec_outbuf_height is the recommended minimum height (in scanlines) of the +buffer passed to jpeg_read_scanlines(). If the buffer is smaller, the +library will still work, but time will be wasted due to unnecessary data +copying. In high-quality modes, rec_outbuf_height is always 1, but some +faster, lower-quality modes set it to larger values (typically 2 to 4). +If you are going to ask for a high-speed processing mode, you may as well +go to the trouble of honoring rec_outbuf_height so as to avoid data copying. +(An output buffer larger than rec_outbuf_height lines is OK, but won't +provide any material speed improvement over that height.) + + +Special color spaces +-------------------- + +The JPEG standard itself is "color blind" and doesn't specify any particular +color space. It is customary to convert color data to a luminance/chrominance +color space before compressing, since this permits greater compression. The +existing de-facto JPEG file format standards specify YCbCr or grayscale data +(JFIF), or grayscale, RGB, YCbCr, CMYK, or YCCK (Adobe). For special +applications such as multispectral images, other color spaces can be used, +but it must be understood that such files will be unportable. + +The JPEG library can handle the most common colorspace conversions (namely +RGB <=> YCbCr and CMYK <=> YCCK). It can also deal with data of an unknown +color space, passing it through without conversion. If you deal extensively +with an unusual color space, you can easily extend the library to understand +additional color spaces and perform appropriate conversions. + +For compression, the source data's color space is specified by field +in_color_space. This is transformed to the JPEG file's color space given +by jpeg_color_space. jpeg_set_defaults() chooses a reasonable JPEG color +space depending on in_color_space, but you can override this by calling +jpeg_set_colorspace(). Of course you must select a supported transformation. +jccolor.c currently supports the following transformations: + RGB => YCbCr + RGB => GRAYSCALE + YCbCr => GRAYSCALE + CMYK => YCCK +plus the null transforms: GRAYSCALE => GRAYSCALE, RGB => RGB, +YCbCr => YCbCr, CMYK => CMYK, YCCK => YCCK, and UNKNOWN => UNKNOWN. + +The de-facto file format standards (JFIF and Adobe) specify APPn markers that +indicate the color space of the JPEG file. It is important to ensure that +these are written correctly, or omitted if the JPEG file's color space is not +one of the ones supported by the de-facto standards. jpeg_set_colorspace() +will set the compression parameters to include or omit the APPn markers +properly, so long as it is told the truth about the JPEG color space. +For example, if you are writing some random 3-component color space without +conversion, don't try to fake out the library by setting in_color_space and +jpeg_color_space to JCS_YCbCr; use JCS_UNKNOWN. You may want to write an +APPn marker of your own devising to identify the colorspace --- see "Special +markers", below. + +When told that the color space is UNKNOWN, the library will default to using +luminance-quality compression parameters for all color components. You may +well want to change these parameters. See the source code for +jpeg_set_colorspace(), in jcparam.c, for details. + +For decompression, the JPEG file's color space is given in jpeg_color_space, +and this is transformed to the output color space out_color_space. +jpeg_read_header's setting of jpeg_color_space can be relied on if the file +conforms to JFIF or Adobe conventions, but otherwise it is no better than a +guess. If you know the JPEG file's color space for certain, you can override +jpeg_read_header's guess by setting jpeg_color_space. jpeg_read_header also +selects a default output color space based on (its guess of) jpeg_color_space; +set out_color_space to override this. Again, you must select a supported +transformation. jdcolor.c currently supports + YCbCr => RGB + YCbCr => GRAYSCALE + RGB => GRAYSCALE + GRAYSCALE => RGB + YCCK => CMYK +as well as the null transforms. (Since GRAYSCALE=>RGB is provided, an +application can force grayscale JPEGs to look like color JPEGs if it only +wants to handle one case.) + +The two-pass color quantizer, jquant2.c, is specialized to handle RGB data +(it weights distances appropriately for RGB colors). You'll need to modify +the code if you want to use it for non-RGB output color spaces. Note that +jquant2.c is used to map to an application-supplied colormap as well as for +the normal two-pass colormap selection process. + +CAUTION: it appears that Adobe Photoshop writes inverted data in CMYK JPEG +files: 0 represents 100% ink coverage, rather than 0% ink as you'd expect. +This is arguably a bug in Photoshop, but if you need to work with Photoshop +CMYK files, you will have to deal with it in your application. We cannot +"fix" this in the library by inverting the data during the CMYK<=>YCCK +transform, because that would break other applications, notably Ghostscript. +Photoshop versions prior to 3.0 write EPS files containing JPEG-encoded CMYK +data in the same inverted-YCCK representation used in bare JPEG files, but +the surrounding PostScript code performs an inversion using the PS image +operator. I am told that Photoshop 3.0 will write uninverted YCCK in +EPS/JPEG files, and will omit the PS-level inversion. (But the data +polarity used in bare JPEG files will not change in 3.0.) In either case, +the JPEG library must not invert the data itself, or else Ghostscript would +read these EPS files incorrectly. + + +Error handling +-------------- + +When the default error handler is used, any error detected inside the JPEG +routines will cause a message to be printed on stderr, followed by exit(). +You can supply your own error handling routines to override this behavior +and to control the treatment of nonfatal warnings and trace/debug messages. +The file example.c illustrates the most common case, which is to have the +application regain control after an error rather than exiting. + +The JPEG library never writes any message directly; it always goes through +the error handling routines. Three classes of messages are recognized: + * Fatal errors: the library cannot continue. + * Warnings: the library can continue, but the data is corrupt, and a + damaged output image is likely to result. + * Trace/informational messages. These come with a trace level indicating + the importance of the message; you can control the verbosity of the + program by adjusting the maximum trace level that will be displayed. + +You may, if you wish, simply replace the entire JPEG error handling module +(jerror.c) with your own code. However, you can avoid code duplication by +only replacing some of the routines depending on the behavior you need. +This is accomplished by calling jpeg_std_error() as usual, but then overriding +some of the method pointers in the jpeg_error_mgr struct, as illustrated by +example.c. + +All of the error handling routines will receive a pointer to the JPEG object +(a j_common_ptr which points to either a jpeg_compress_struct or a +jpeg_decompress_struct; if you need to tell which, test the is_decompressor +field). This struct includes a pointer to the error manager struct in its +"err" field. Frequently, custom error handler routines will need to access +additional data which is not known to the JPEG library or the standard error +handler. The most convenient way to do this is to embed either the JPEG +object or the jpeg_error_mgr struct in a larger structure that contains +additional fields; then casting the passed pointer provides access to the +additional fields. Again, see example.c for one way to do it. (Beginning +with IJG version 6b, there is also a void pointer "client_data" in each +JPEG object, which the application can also use to find related data. +The library does not touch client_data at all.) + +The individual methods that you might wish to override are: + +error_exit (j_common_ptr cinfo) + Receives control for a fatal error. Information sufficient to + generate the error message has been stored in cinfo->err; call + output_message to display it. Control must NOT return to the caller; + generally this routine will exit() or longjmp() somewhere. + Typically you would override this routine to get rid of the exit() + default behavior. Note that if you continue processing, you should + clean up the JPEG object with jpeg_abort() or jpeg_destroy(). + +output_message (j_common_ptr cinfo) + Actual output of any JPEG message. Override this to send messages + somewhere other than stderr. Note that this method does not know + how to generate a message, only where to send it. + +format_message (j_common_ptr cinfo, char * buffer) + Constructs a readable error message string based on the error info + stored in cinfo->err. This method is called by output_message. Few + applications should need to override this method. One possible + reason for doing so is to implement dynamic switching of error message + language. + +emit_message (j_common_ptr cinfo, int msg_level) + Decide whether or not to emit a warning or trace message; if so, + calls output_message. The main reason for overriding this method + would be to abort on warnings. msg_level is -1 for warnings, + 0 and up for trace messages. + +Only error_exit() and emit_message() are called from the rest of the JPEG +library; the other two are internal to the error handler. + +The actual message texts are stored in an array of strings which is pointed to +by the field err->jpeg_message_table. The messages are numbered from 0 to +err->last_jpeg_message, and it is these code numbers that are used in the +JPEG library code. You could replace the message texts (for instance, with +messages in French or German) by changing the message table pointer. See +jerror.h for the default texts. CAUTION: this table will almost certainly +change or grow from one library version to the next. + +It may be useful for an application to add its own message texts that are +handled by the same mechanism. The error handler supports a second "add-on" +message table for this purpose. To define an addon table, set the pointer +err->addon_message_table and the message numbers err->first_addon_message and +err->last_addon_message. If you number the addon messages beginning at 1000 +or so, you won't have to worry about conflicts with the library's built-in +messages. See the sample applications cjpeg/djpeg for an example of using +addon messages (the addon messages are defined in cderror.h). + +Actual invocation of the error handler is done via macros defined in jerror.h: + ERREXITn(...) for fatal errors + WARNMSn(...) for corrupt-data warnings + TRACEMSn(...) for trace and informational messages. +These macros store the message code and any additional parameters into the +error handler struct, then invoke the error_exit() or emit_message() method. +The variants of each macro are for varying numbers of additional parameters. +The additional parameters are inserted into the generated message using +standard printf() format codes. + +See jerror.h and jerror.c for further details. + + +Compressed data handling (source and destination managers) +---------------------------------------------------------- + +The JPEG compression library sends its compressed data to a "destination +manager" module. The default destination manager just writes the data to a +memory buffer or to a stdio stream, but you can provide your own manager to +do something else. Similarly, the decompression library calls a "source +manager" to obtain the compressed data; you can provide your own source +manager if you want the data to come from somewhere other than a memory +buffer or a stdio stream. + +In both cases, compressed data is processed a bufferload at a time: the +destination or source manager provides a work buffer, and the library invokes +the manager only when the buffer is filled or emptied. (You could define a +one-character buffer to force the manager to be invoked for each byte, but +that would be rather inefficient.) The buffer's size and location are +controlled by the manager, not by the library. For example, the memory +source manager just makes the buffer pointer and length point to the original +data in memory. In this case the buffer-reload procedure will be invoked +only if the decompressor ran off the end of the datastream, which would +indicate an erroneous datastream. + +The work buffer is defined as an array of datatype JOCTET, which is generally +"char" or "unsigned char". On a machine where char is not exactly 8 bits +wide, you must define JOCTET as a wider data type and then modify the data +source and destination modules to transcribe the work arrays into 8-bit units +on external storage. + +A data destination manager struct contains a pointer and count defining the +next byte to write in the work buffer and the remaining free space: + + JOCTET * next_output_byte; /* => next byte to write in buffer */ + size_t free_in_buffer; /* # of byte spaces remaining in buffer */ + +The library increments the pointer and decrements the count until the buffer +is filled. The manager's empty_output_buffer method must reset the pointer +and count. The manager is expected to remember the buffer's starting address +and total size in private fields not visible to the library. + +A data destination manager provides three methods: + +init_destination (j_compress_ptr cinfo) + Initialize destination. This is called by jpeg_start_compress() + before any data is actually written. It must initialize + next_output_byte and free_in_buffer. free_in_buffer must be + initialized to a positive value. + +empty_output_buffer (j_compress_ptr cinfo) + This is called whenever the buffer has filled (free_in_buffer + reaches zero). In typical applications, it should write out the + *entire* buffer (use the saved start address and buffer length; + ignore the current state of next_output_byte and free_in_buffer). + Then reset the pointer & count to the start of the buffer, and + return TRUE indicating that the buffer has been dumped. + free_in_buffer must be set to a positive value when TRUE is + returned. A FALSE return should only be used when I/O suspension is + desired (this operating mode is discussed in the next section). + +term_destination (j_compress_ptr cinfo) + Terminate destination --- called by jpeg_finish_compress() after all + data has been written. In most applications, this must flush any + data remaining in the buffer. Use either next_output_byte or + free_in_buffer to determine how much data is in the buffer. + +term_destination() is NOT called by jpeg_abort() or jpeg_destroy(). If you +want the destination manager to be cleaned up during an abort, you must do it +yourself. + +You will also need code to create a jpeg_destination_mgr struct, fill in its +method pointers, and insert a pointer to the struct into the "dest" field of +the JPEG compression object. This can be done in-line in your setup code if +you like, but it's probably cleaner to provide a separate routine similar to +the jpeg_stdio_dest() or jpeg_mem_dest() routines of the supplied destination +managers. + +Decompression source managers follow a parallel design, but with some +additional frammishes. The source manager struct contains a pointer and count +defining the next byte to read from the work buffer and the number of bytes +remaining: + + const JOCTET * next_input_byte; /* => next byte to read from buffer */ + size_t bytes_in_buffer; /* # of bytes remaining in buffer */ + +The library increments the pointer and decrements the count until the buffer +is emptied. The manager's fill_input_buffer method must reset the pointer and +count. In most applications, the manager must remember the buffer's starting +address and total size in private fields not visible to the library. + +A data source manager provides five methods: + +init_source (j_decompress_ptr cinfo) + Initialize source. This is called by jpeg_read_header() before any + data is actually read. Unlike init_destination(), it may leave + bytes_in_buffer set to 0 (in which case a fill_input_buffer() call + will occur immediately). + +fill_input_buffer (j_decompress_ptr cinfo) + This is called whenever bytes_in_buffer has reached zero and more + data is wanted. In typical applications, it should read fresh data + into the buffer (ignoring the current state of next_input_byte and + bytes_in_buffer), reset the pointer & count to the start of the + buffer, and return TRUE indicating that the buffer has been reloaded. + It is not necessary to fill the buffer entirely, only to obtain at + least one more byte. bytes_in_buffer MUST be set to a positive value + if TRUE is returned. A FALSE return should only be used when I/O + suspension is desired (this mode is discussed in the next section). + +skip_input_data (j_decompress_ptr cinfo, long num_bytes) + Skip num_bytes worth of data. The buffer pointer and count should + be advanced over num_bytes input bytes, refilling the buffer as + needed. This is used to skip over a potentially large amount of + uninteresting data (such as an APPn marker). In some applications + it may be possible to optimize away the reading of the skipped data, + but it's not clear that being smart is worth much trouble; large + skips are uncommon. bytes_in_buffer may be zero on return. + A zero or negative skip count should be treated as a no-op. + +resync_to_restart (j_decompress_ptr cinfo, int desired) + This routine is called only when the decompressor has failed to find + a restart (RSTn) marker where one is expected. Its mission is to + find a suitable point for resuming decompression. For most + applications, we recommend that you just use the default resync + procedure, jpeg_resync_to_restart(). However, if you are able to back + up in the input data stream, or if you have a-priori knowledge about + the likely location of restart markers, you may be able to do better. + Read the read_restart_marker() and jpeg_resync_to_restart() routines + in jdmarker.c if you think you'd like to implement your own resync + procedure. + +term_source (j_decompress_ptr cinfo) + Terminate source --- called by jpeg_finish_decompress() after all + data has been read. Often a no-op. + +For both fill_input_buffer() and skip_input_data(), there is no such thing +as an EOF return. If the end of the file has been reached, the routine has +a choice of exiting via ERREXIT() or inserting fake data into the buffer. +In most cases, generating a warning message and inserting a fake EOI marker +is the best course of action --- this will allow the decompressor to output +however much of the image is there. In pathological cases, the decompressor +may swallow the EOI and again demand data ... just keep feeding it fake EOIs. +jdatasrc.c illustrates the recommended error recovery behavior. + +term_source() is NOT called by jpeg_abort() or jpeg_destroy(). If you want +the source manager to be cleaned up during an abort, you must do it yourself. + +You will also need code to create a jpeg_source_mgr struct, fill in its method +pointers, and insert a pointer to the struct into the "src" field of the JPEG +decompression object. This can be done in-line in your setup code if you +like, but it's probably cleaner to provide a separate routine similar to the +jpeg_stdio_src() or jpeg_mem_src() routines of the supplied source managers. + +For more information, consult the memory and stdio source and destination +managers in jdatasrc.c and jdatadst.c. + + +I/O suspension +-------------- + +Some applications need to use the JPEG library as an incremental memory-to- +memory filter: when the compressed data buffer is filled or emptied, they want +control to return to the outer loop, rather than expecting that the buffer can +be emptied or reloaded within the data source/destination manager subroutine. +The library supports this need by providing an "I/O suspension" mode, which we +describe in this section. + +The I/O suspension mode is not a panacea: nothing is guaranteed about the +maximum amount of time spent in any one call to the library, so it will not +eliminate response-time problems in single-threaded applications. If you +need guaranteed response time, we suggest you "bite the bullet" and implement +a real multi-tasking capability. + +To use I/O suspension, cooperation is needed between the calling application +and the data source or destination manager; you will always need a custom +source/destination manager. (Please read the previous section if you haven't +already.) The basic idea is that the empty_output_buffer() or +fill_input_buffer() routine is a no-op, merely returning FALSE to indicate +that it has done nothing. Upon seeing this, the JPEG library suspends +operation and returns to its caller. The surrounding application is +responsible for emptying or refilling the work buffer before calling the +JPEG library again. + +Compression suspension: + +For compression suspension, use an empty_output_buffer() routine that returns +FALSE; typically it will not do anything else. This will cause the +compressor to return to the caller of jpeg_write_scanlines(), with the return +value indicating that not all the supplied scanlines have been accepted. +The application must make more room in the output buffer, adjust the output +buffer pointer/count appropriately, and then call jpeg_write_scanlines() +again, pointing to the first unconsumed scanline. + +When forced to suspend, the compressor will backtrack to a convenient stopping +point (usually the start of the current MCU); it will regenerate some output +data when restarted. Therefore, although empty_output_buffer() is only +called when the buffer is filled, you should NOT write out the entire buffer +after a suspension. Write only the data up to the current position of +next_output_byte/free_in_buffer. The data beyond that point will be +regenerated after resumption. + +Because of the backtracking behavior, a good-size output buffer is essential +for efficiency; you don't want the compressor to suspend often. (In fact, an +overly small buffer could lead to infinite looping, if a single MCU required +more data than would fit in the buffer.) We recommend a buffer of at least +several Kbytes. You may want to insert explicit code to ensure that you don't +call jpeg_write_scanlines() unless there is a reasonable amount of space in +the output buffer; in other words, flush the buffer before trying to compress +more data. + +The compressor does not allow suspension while it is trying to write JPEG +markers at the beginning and end of the file. This means that: + * At the beginning of a compression operation, there must be enough free + space in the output buffer to hold the header markers (typically 600 or + so bytes). The recommended buffer size is bigger than this anyway, so + this is not a problem as long as you start with an empty buffer. However, + this restriction might catch you if you insert large special markers, such + as a JFIF thumbnail image, without flushing the buffer afterwards. + * When you call jpeg_finish_compress(), there must be enough space in the + output buffer to emit any buffered data and the final EOI marker. In the + current implementation, half a dozen bytes should suffice for this, but + for safety's sake we recommend ensuring that at least 100 bytes are free + before calling jpeg_finish_compress(). + +A more significant restriction is that jpeg_finish_compress() cannot suspend. +This means you cannot use suspension with multi-pass operating modes, namely +Huffman code optimization and multiple-scan output. Those modes write the +whole file during jpeg_finish_compress(), which will certainly result in +buffer overrun. (Note that this restriction applies only to compression, +not decompression. The decompressor supports input suspension in all of its +operating modes.) + +Decompression suspension: + +For decompression suspension, use a fill_input_buffer() routine that simply +returns FALSE (except perhaps during error recovery, as discussed below). +This will cause the decompressor to return to its caller with an indication +that suspension has occurred. This can happen at four places: + * jpeg_read_header(): will return JPEG_SUSPENDED. + * jpeg_start_decompress(): will return FALSE, rather than its usual TRUE. + * jpeg_read_scanlines(): will return the number of scanlines already + completed (possibly 0). + * jpeg_finish_decompress(): will return FALSE, rather than its usual TRUE. +The surrounding application must recognize these cases, load more data into +the input buffer, and repeat the call. In the case of jpeg_read_scanlines(), +increment the passed pointers past any scanlines successfully read. + +Just as with compression, the decompressor will typically backtrack to a +convenient restart point before suspending. When fill_input_buffer() is +called, next_input_byte/bytes_in_buffer point to the current restart point, +which is where the decompressor will backtrack to if FALSE is returned. +The data beyond that position must NOT be discarded if you suspend; it needs +to be re-read upon resumption. In most implementations, you'll need to shift +this data down to the start of your work buffer and then load more data after +it. Again, this behavior means that a several-Kbyte work buffer is essential +for decent performance; furthermore, you should load a reasonable amount of +new data before resuming decompression. (If you loaded, say, only one new +byte each time around, you could waste a LOT of cycles.) + +The skip_input_data() source manager routine requires special care in a +suspension scenario. This routine is NOT granted the ability to suspend the +decompressor; it can decrement bytes_in_buffer to zero, but no more. If the +requested skip distance exceeds the amount of data currently in the input +buffer, then skip_input_data() must set bytes_in_buffer to zero and record the +additional skip distance somewhere else. The decompressor will immediately +call fill_input_buffer(), which should return FALSE, which will cause a +suspension return. The surrounding application must then arrange to discard +the recorded number of bytes before it resumes loading the input buffer. +(Yes, this design is rather baroque, but it avoids complexity in the far more +common case where a non-suspending source manager is used.) + +If the input data has been exhausted, we recommend that you emit a warning +and insert dummy EOI markers just as a non-suspending data source manager +would do. This can be handled either in the surrounding application logic or +within fill_input_buffer(); the latter is probably more efficient. If +fill_input_buffer() knows that no more data is available, it can set the +pointer/count to point to a dummy EOI marker and then return TRUE just as +though it had read more data in a non-suspending situation. + +The decompressor does not attempt to suspend within standard JPEG markers; +instead it will backtrack to the start of the marker and reprocess the whole +marker next time. Hence the input buffer must be large enough to hold the +longest standard marker in the file. Standard JPEG markers should normally +not exceed a few hundred bytes each (DHT tables are typically the longest). +We recommend at least a 2K buffer for performance reasons, which is much +larger than any correct marker is likely to be. For robustness against +damaged marker length counts, you may wish to insert a test in your +application for the case that the input buffer is completely full and yet +the decoder has suspended without consuming any data --- otherwise, if this +situation did occur, it would lead to an endless loop. (The library can't +provide this test since it has no idea whether "the buffer is full", or +even whether there is a fixed-size input buffer.) + +The input buffer would need to be 64K to allow for arbitrary COM or APPn +markers, but these are handled specially: they are either saved into allocated +memory, or skipped over by calling skip_input_data(). In the former case, +suspension is handled correctly, and in the latter case, the problem of +buffer overrun is placed on skip_input_data's shoulders, as explained above. +Note that if you provide your own marker handling routine for large markers, +you should consider how to deal with buffer overflow. + +Multiple-buffer management: + +In some applications it is desirable to store the compressed data in a linked +list of buffer areas, so as to avoid data copying. This can be handled by +having empty_output_buffer() or fill_input_buffer() set the pointer and count +to reference the next available buffer; FALSE is returned only if no more +buffers are available. Although seemingly straightforward, there is a +pitfall in this approach: the backtrack that occurs when FALSE is returned +could back up into an earlier buffer. For example, when fill_input_buffer() +is called, the current pointer & count indicate the backtrack restart point. +Since fill_input_buffer() will set the pointer and count to refer to a new +buffer, the restart position must be saved somewhere else. Suppose a second +call to fill_input_buffer() occurs in the same library call, and no +additional input data is available, so fill_input_buffer must return FALSE. +If the JPEG library has not moved the pointer/count forward in the current +buffer, then *the correct restart point is the saved position in the prior +buffer*. Prior buffers may be discarded only after the library establishes +a restart point within a later buffer. Similar remarks apply for output into +a chain of buffers. + +The library will never attempt to backtrack over a skip_input_data() call, +so any skipped data can be permanently discarded. You still have to deal +with the case of skipping not-yet-received data, however. + +It's much simpler to use only a single buffer; when fill_input_buffer() is +called, move any unconsumed data (beyond the current pointer/count) down to +the beginning of this buffer and then load new data into the remaining buffer +space. This approach requires a little more data copying but is far easier +to get right. + + +Progressive JPEG support +------------------------ + +Progressive JPEG rearranges the stored data into a series of scans of +increasing quality. In situations where a JPEG file is transmitted across a +slow communications link, a decoder can generate a low-quality image very +quickly from the first scan, then gradually improve the displayed quality as +more scans are received. The final image after all scans are complete is +identical to that of a regular (sequential) JPEG file of the same quality +setting. Progressive JPEG files are often slightly smaller than equivalent +sequential JPEG files, but the possibility of incremental display is the main +reason for using progressive JPEG. + +The IJG encoder library generates progressive JPEG files when given a +suitable "scan script" defining how to divide the data into scans. +Creation of progressive JPEG files is otherwise transparent to the encoder. +Progressive JPEG files can also be read transparently by the decoder library. +If the decoding application simply uses the library as defined above, it +will receive a final decoded image without any indication that the file was +progressive. Of course, this approach does not allow incremental display. +To perform incremental display, an application needs to use the decoder +library's "buffered-image" mode, in which it receives a decoded image +multiple times. + +Each displayed scan requires about as much work to decode as a full JPEG +image of the same size, so the decoder must be fairly fast in relation to the +data transmission rate in order to make incremental display useful. However, +it is possible to skip displaying the image and simply add the incoming bits +to the decoder's coefficient buffer. This is fast because only Huffman +decoding need be done, not IDCT, upsampling, colorspace conversion, etc. +The IJG decoder library allows the application to switch dynamically between +displaying the image and simply absorbing the incoming bits. A properly +coded application can automatically adapt the number of display passes to +suit the time available as the image is received. Also, a final +higher-quality display cycle can be performed from the buffered data after +the end of the file is reached. + +Progressive compression: + +To create a progressive JPEG file (or a multiple-scan sequential JPEG file), +set the scan_info cinfo field to point to an array of scan descriptors, and +perform compression as usual. Instead of constructing your own scan list, +you can call the jpeg_simple_progression() helper routine to create a +recommended progression sequence; this method should be used by all +applications that don't want to get involved in the nitty-gritty of +progressive scan sequence design. (If you want to provide user control of +scan sequences, you may wish to borrow the scan script reading code found +in rdswitch.c, so that you can read scan script files just like cjpeg's.) +When scan_info is not NULL, the compression library will store DCT'd data +into a buffer array as jpeg_write_scanlines() is called, and will emit all +the requested scans during jpeg_finish_compress(). This implies that +multiple-scan output cannot be created with a suspending data destination +manager, since jpeg_finish_compress() does not support suspension. We +should also note that the compressor currently forces Huffman optimization +mode when creating a progressive JPEG file, because the default Huffman +tables are unsuitable for progressive files. + +Progressive decompression: + +When buffered-image mode is not used, the decoder library will read all of +a multi-scan file during jpeg_start_decompress(), so that it can provide a +final decoded image. (Here "multi-scan" means either progressive or +multi-scan sequential.) This makes multi-scan files transparent to the +decoding application. However, existing applications that used suspending +input with version 5 of the IJG library will need to be modified to check +for a suspension return from jpeg_start_decompress(). + +To perform incremental display, an application must use the library's +buffered-image mode. This is described in the next section. + + +Buffered-image mode +------------------- + +In buffered-image mode, the library stores the partially decoded image in a +coefficient buffer, from which it can be read out as many times as desired. +This mode is typically used for incremental display of progressive JPEG files, +but it can be used with any JPEG file. Each scan of a progressive JPEG file +adds more data (more detail) to the buffered image. The application can +display in lockstep with the source file (one display pass per input scan), +or it can allow input processing to outrun display processing. By making +input and display processing run independently, it is possible for the +application to adapt progressive display to a wide range of data transmission +rates. + +The basic control flow for buffered-image decoding is + + jpeg_create_decompress() + set data source + jpeg_read_header() + set overall decompression parameters + cinfo.buffered_image = TRUE; /* select buffered-image mode */ + jpeg_start_decompress() + for (each output pass) { + adjust output decompression parameters if required + jpeg_start_output() /* start a new output pass */ + for (all scanlines in image) { + jpeg_read_scanlines() + display scanlines + } + jpeg_finish_output() /* terminate output pass */ + } + jpeg_finish_decompress() + jpeg_destroy_decompress() + +This differs from ordinary unbuffered decoding in that there is an additional +level of looping. The application can choose how many output passes to make +and how to display each pass. + +The simplest approach to displaying progressive images is to do one display +pass for each scan appearing in the input file. In this case the outer loop +condition is typically + while (! jpeg_input_complete(&cinfo)) +and the start-output call should read + jpeg_start_output(&cinfo, cinfo.input_scan_number); +The second parameter to jpeg_start_output() indicates which scan of the input +file is to be displayed; the scans are numbered starting at 1 for this +purpose. (You can use a loop counter starting at 1 if you like, but using +the library's input scan counter is easier.) The library automatically reads +data as necessary to complete each requested scan, and jpeg_finish_output() +advances to the next scan or end-of-image marker (hence input_scan_number +will be incremented by the time control arrives back at jpeg_start_output()). +With this technique, data is read from the input file only as needed, and +input and output processing run in lockstep. + +After reading the final scan and reaching the end of the input file, the +buffered image remains available; it can be read additional times by +repeating the jpeg_start_output()/jpeg_read_scanlines()/jpeg_finish_output() +sequence. For example, a useful technique is to use fast one-pass color +quantization for display passes made while the image is arriving, followed by +a final display pass using two-pass quantization for highest quality. This +is done by changing the library parameters before the final output pass. +Changing parameters between passes is discussed in detail below. + +In general the last scan of a progressive file cannot be recognized as such +until after it is read, so a post-input display pass is the best approach if +you want special processing in the final pass. + +When done with the image, be sure to call jpeg_finish_decompress() to release +the buffered image (or just use jpeg_destroy_decompress()). + +If input data arrives faster than it can be displayed, the application can +cause the library to decode input data in advance of what's needed to produce +output. This is done by calling the routine jpeg_consume_input(). +The return value is one of the following: + JPEG_REACHED_SOS: reached an SOS marker (the start of a new scan) + JPEG_REACHED_EOI: reached the EOI marker (end of image) + JPEG_ROW_COMPLETED: completed reading one MCU row of compressed data + JPEG_SCAN_COMPLETED: completed reading last MCU row of current scan + JPEG_SUSPENDED: suspended before completing any of the above +(JPEG_SUSPENDED can occur only if a suspending data source is used.) This +routine can be called at any time after initializing the JPEG object. It +reads some additional data and returns when one of the indicated significant +events occurs. (If called after the EOI marker is reached, it will +immediately return JPEG_REACHED_EOI without attempting to read more data.) + +The library's output processing will automatically call jpeg_consume_input() +whenever the output processing overtakes the input; thus, simple lockstep +display requires no direct calls to jpeg_consume_input(). But by adding +calls to jpeg_consume_input(), you can absorb data in advance of what is +being displayed. This has two benefits: + * You can limit buildup of unprocessed data in your input buffer. + * You can eliminate extra display passes by paying attention to the + state of the library's input processing. + +The first of these benefits only requires interspersing calls to +jpeg_consume_input() with your display operations and any other processing +you may be doing. To avoid wasting cycles due to backtracking, it's best to +call jpeg_consume_input() only after a hundred or so new bytes have arrived. +This is discussed further under "I/O suspension", above. (Note: the JPEG +library currently is not thread-safe. You must not call jpeg_consume_input() +from one thread of control if a different library routine is working on the +same JPEG object in another thread.) + +When input arrives fast enough that more than one new scan is available +before you start a new output pass, you may as well skip the output pass +corresponding to the completed scan. This occurs for free if you pass +cinfo.input_scan_number as the target scan number to jpeg_start_output(). +The input_scan_number field is simply the index of the scan currently being +consumed by the input processor. You can ensure that this is up-to-date by +emptying the input buffer just before calling jpeg_start_output(): call +jpeg_consume_input() repeatedly until it returns JPEG_SUSPENDED or +JPEG_REACHED_EOI. + +The target scan number passed to jpeg_start_output() is saved in the +cinfo.output_scan_number field. The library's output processing calls +jpeg_consume_input() whenever the current input scan number and row within +that scan is less than or equal to the current output scan number and row. +Thus, input processing can "get ahead" of the output processing but is not +allowed to "fall behind". You can achieve several different effects by +manipulating this interlock rule. For example, if you pass a target scan +number greater than the current input scan number, the output processor will +wait until that scan starts to arrive before producing any output. (To avoid +an infinite loop, the target scan number is automatically reset to the last +scan number when the end of image is reached. Thus, if you specify a large +target scan number, the library will just absorb the entire input file and +then perform an output pass. This is effectively the same as what +jpeg_start_decompress() does when you don't select buffered-image mode.) +When you pass a target scan number equal to the current input scan number, +the image is displayed no faster than the current input scan arrives. The +final possibility is to pass a target scan number less than the current input +scan number; this disables the input/output interlock and causes the output +processor to simply display whatever it finds in the image buffer, without +waiting for input. (However, the library will not accept a target scan +number less than one, so you can't avoid waiting for the first scan.) + +When data is arriving faster than the output display processing can advance +through the image, jpeg_consume_input() will store data into the buffered +image beyond the point at which the output processing is reading data out +again. If the input arrives fast enough, it may "wrap around" the buffer to +the point where the input is more than one whole scan ahead of the output. +If the output processing simply proceeds through its display pass without +paying attention to the input, the effect seen on-screen is that the lower +part of the image is one or more scans better in quality than the upper part. +Then, when the next output scan is started, you have a choice of what target +scan number to use. The recommended choice is to use the current input scan +number at that time, which implies that you've skipped the output scans +corresponding to the input scans that were completed while you processed the +previous output scan. In this way, the decoder automatically adapts its +speed to the arriving data, by skipping output scans as necessary to keep up +with the arriving data. + +When using this strategy, you'll want to be sure that you perform a final +output pass after receiving all the data; otherwise your last display may not +be full quality across the whole screen. So the right outer loop logic is +something like this: + do { + absorb any waiting input by calling jpeg_consume_input() + final_pass = jpeg_input_complete(&cinfo); + adjust output decompression parameters if required + jpeg_start_output(&cinfo, cinfo.input_scan_number); + ... + jpeg_finish_output() + } while (! final_pass); +rather than quitting as soon as jpeg_input_complete() returns TRUE. This +arrangement makes it simple to use higher-quality decoding parameters +for the final pass. But if you don't want to use special parameters for +the final pass, the right loop logic is like this: + for (;;) { + absorb any waiting input by calling jpeg_consume_input() + jpeg_start_output(&cinfo, cinfo.input_scan_number); + ... + jpeg_finish_output() + if (jpeg_input_complete(&cinfo) && + cinfo.input_scan_number == cinfo.output_scan_number) + break; + } +In this case you don't need to know in advance whether an output pass is to +be the last one, so it's not necessary to have reached EOF before starting +the final output pass; rather, what you want to test is whether the output +pass was performed in sync with the final input scan. This form of the loop +will avoid an extra output pass whenever the decoder is able (or nearly able) +to keep up with the incoming data. + +When the data transmission speed is high, you might begin a display pass, +then find that much or all of the file has arrived before you can complete +the pass. (You can detect this by noting the JPEG_REACHED_EOI return code +from jpeg_consume_input(), or equivalently by testing jpeg_input_complete().) +In this situation you may wish to abort the current display pass and start a +new one using the newly arrived information. To do so, just call +jpeg_finish_output() and then start a new pass with jpeg_start_output(). + +A variant strategy is to abort and restart display if more than one complete +scan arrives during an output pass; this can be detected by noting +JPEG_REACHED_SOS returns and/or examining cinfo.input_scan_number. This +idea should be employed with caution, however, since the display process +might never get to the bottom of the image before being aborted, resulting +in the lower part of the screen being several passes worse than the upper. +In most cases it's probably best to abort an output pass only if the whole +file has arrived and you want to begin the final output pass immediately. + +When receiving data across a communication link, we recommend always using +the current input scan number for the output target scan number; if a +higher-quality final pass is to be done, it should be started (aborting any +incomplete output pass) as soon as the end of file is received. However, +many other strategies are possible. For example, the application can examine +the parameters of the current input scan and decide whether to display it or +not. If the scan contains only chroma data, one might choose not to use it +as the target scan, expecting that the scan will be small and will arrive +quickly. To skip to the next scan, call jpeg_consume_input() until it +returns JPEG_REACHED_SOS or JPEG_REACHED_EOI. Or just use the next higher +number as the target scan for jpeg_start_output(); but that method doesn't +let you inspect the next scan's parameters before deciding to display it. + + +In buffered-image mode, jpeg_start_decompress() never performs input and +thus never suspends. An application that uses input suspension with +buffered-image mode must be prepared for suspension returns from these +routines: +* jpeg_start_output() performs input only if you request 2-pass quantization + and the target scan isn't fully read yet. (This is discussed below.) +* jpeg_read_scanlines(), as always, returns the number of scanlines that it + was able to produce before suspending. +* jpeg_finish_output() will read any markers following the target scan, + up to the end of the file or the SOS marker that begins another scan. + (But it reads no input if jpeg_consume_input() has already reached the + end of the file or a SOS marker beyond the target output scan.) +* jpeg_finish_decompress() will read until the end of file, and thus can + suspend if the end hasn't already been reached (as can be tested by + calling jpeg_input_complete()). +jpeg_start_output(), jpeg_finish_output(), and jpeg_finish_decompress() +all return TRUE if they completed their tasks, FALSE if they had to suspend. +In the event of a FALSE return, the application must load more input data +and repeat the call. Applications that use non-suspending data sources need +not check the return values of these three routines. + + +It is possible to change decoding parameters between output passes in the +buffered-image mode. The decoder library currently supports only very +limited changes of parameters. ONLY THE FOLLOWING parameter changes are +allowed after jpeg_start_decompress() is called: +* dct_method can be changed before each call to jpeg_start_output(). + For example, one could use a fast DCT method for early scans, changing + to a higher quality method for the final scan. +* dither_mode can be changed before each call to jpeg_start_output(); + of course this has no impact if not using color quantization. Typically + one would use ordered dither for initial passes, then switch to + Floyd-Steinberg dither for the final pass. Caution: changing dither mode + can cause more memory to be allocated by the library. Although the amount + of memory involved is not large (a scanline or so), it may cause the + initial max_memory_to_use specification to be exceeded, which in the worst + case would result in an out-of-memory failure. +* do_block_smoothing can be changed before each call to jpeg_start_output(). + This setting is relevant only when decoding a progressive JPEG image. + During the first DC-only scan, block smoothing provides a very "fuzzy" look + instead of the very "blocky" look seen without it; which is better seems a + matter of personal taste. But block smoothing is nearly always a win + during later stages, especially when decoding a successive-approximation + image: smoothing helps to hide the slight blockiness that otherwise shows + up on smooth gradients until the lowest coefficient bits are sent. +* Color quantization mode can be changed under the rules described below. + You *cannot* change between full-color and quantized output (because that + would alter the required I/O buffer sizes), but you can change which + quantization method is used. + +When generating color-quantized output, changing quantization method is a +very useful way of switching between high-speed and high-quality display. +The library allows you to change among its three quantization methods: +1. Single-pass quantization to a fixed color cube. + Selected by cinfo.two_pass_quantize = FALSE and cinfo.colormap = NULL. +2. Single-pass quantization to an application-supplied colormap. + Selected by setting cinfo.colormap to point to the colormap (the value of + two_pass_quantize is ignored); also set cinfo.actual_number_of_colors. +3. Two-pass quantization to a colormap chosen specifically for the image. + Selected by cinfo.two_pass_quantize = TRUE and cinfo.colormap = NULL. + (This is the default setting selected by jpeg_read_header, but it is + probably NOT what you want for the first pass of progressive display!) +These methods offer successively better quality and lesser speed. However, +only the first method is available for quantizing in non-RGB color spaces. + +IMPORTANT: because the different quantizer methods have very different +working-storage requirements, the library requires you to indicate which +one(s) you intend to use before you call jpeg_start_decompress(). (If we did +not require this, the max_memory_to_use setting would be a complete fiction.) +You do this by setting one or more of these three cinfo fields to TRUE: + enable_1pass_quant Fixed color cube colormap + enable_external_quant Externally-supplied colormap + enable_2pass_quant Two-pass custom colormap +All three are initialized FALSE by jpeg_read_header(). But +jpeg_start_decompress() automatically sets TRUE the one selected by the +current two_pass_quantize and colormap settings, so you only need to set the +enable flags for any other quantization methods you plan to change to later. + +After setting the enable flags correctly at jpeg_start_decompress() time, you +can change to any enabled quantization method by setting two_pass_quantize +and colormap properly just before calling jpeg_start_output(). The following +special rules apply: +1. You must explicitly set cinfo.colormap to NULL when switching to 1-pass + or 2-pass mode from a different mode, or when you want the 2-pass + quantizer to be re-run to generate a new colormap. +2. To switch to an external colormap, or to change to a different external + colormap than was used on the prior pass, you must call + jpeg_new_colormap() after setting cinfo.colormap. +NOTE: if you want to use the same colormap as was used in the prior pass, +you should not do either of these things. This will save some nontrivial +switchover costs. +(These requirements exist because cinfo.colormap will always be non-NULL +after completing a prior output pass, since both the 1-pass and 2-pass +quantizers set it to point to their output colormaps. Thus you have to +do one of these two things to notify the library that something has changed. +Yup, it's a bit klugy, but it's necessary to do it this way for backwards +compatibility.) + +Note that in buffered-image mode, the library generates any requested colormap +during jpeg_start_output(), not during jpeg_start_decompress(). + +When using two-pass quantization, jpeg_start_output() makes a pass over the +buffered image to determine the optimum color map; it therefore may take a +significant amount of time, whereas ordinarily it does little work. The +progress monitor hook is called during this pass, if defined. It is also +important to realize that if the specified target scan number is greater than +or equal to the current input scan number, jpeg_start_output() will attempt +to consume input as it makes this pass. If you use a suspending data source, +you need to check for a FALSE return from jpeg_start_output() under these +conditions. The combination of 2-pass quantization and a not-yet-fully-read +target scan is the only case in which jpeg_start_output() will consume input. + + +Application authors who support buffered-image mode may be tempted to use it +for all JPEG images, even single-scan ones. This will work, but it is +inefficient: there is no need to create an image-sized coefficient buffer for +single-scan images. Requesting buffered-image mode for such an image wastes +memory. Worse, it can cost time on large images, since the buffered data has +to be swapped out or written to a temporary file. If you are concerned about +maximum performance on baseline JPEG files, you should use buffered-image +mode only when the incoming file actually has multiple scans. This can be +tested by calling jpeg_has_multiple_scans(), which will return a correct +result at any time after jpeg_read_header() completes. + +It is also worth noting that when you use jpeg_consume_input() to let input +processing get ahead of output processing, the resulting pattern of access to +the coefficient buffer is quite nonsequential. It's best to use the memory +manager jmemnobs.c if you can (ie, if you have enough real or virtual main +memory). If not, at least make sure that max_memory_to_use is set as high as +possible. If the JPEG memory manager has to use a temporary file, you will +probably see a lot of disk traffic and poor performance. (This could be +improved with additional work on the memory manager, but we haven't gotten +around to it yet.) + +In some applications it may be convenient to use jpeg_consume_input() for all +input processing, including reading the initial markers; that is, you may +wish to call jpeg_consume_input() instead of jpeg_read_header() during +startup. This works, but note that you must check for JPEG_REACHED_SOS and +JPEG_REACHED_EOI return codes as the equivalent of jpeg_read_header's codes. +Once the first SOS marker has been reached, you must call +jpeg_start_decompress() before jpeg_consume_input() will consume more input; +it'll just keep returning JPEG_REACHED_SOS until you do. If you read a +tables-only file this way, jpeg_consume_input() will return JPEG_REACHED_EOI +without ever returning JPEG_REACHED_SOS; be sure to check for this case. +If this happens, the decompressor will not read any more input until you call +jpeg_abort() to reset it. It is OK to call jpeg_consume_input() even when not +using buffered-image mode, but in that case it's basically a no-op after the +initial markers have been read: it will just return JPEG_SUSPENDED. + + +Abbreviated datastreams and multiple images +------------------------------------------- + +A JPEG compression or decompression object can be reused to process multiple +images. This saves a small amount of time per image by eliminating the +"create" and "destroy" operations, but that isn't the real purpose of the +feature. Rather, reuse of an object provides support for abbreviated JPEG +datastreams. Object reuse can also simplify processing a series of images in +a single input or output file. This section explains these features. + +A JPEG file normally contains several hundred bytes worth of quantization +and Huffman tables. In a situation where many images will be stored or +transmitted with identical tables, this may represent an annoying overhead. +The JPEG standard therefore permits tables to be omitted. The standard +defines three classes of JPEG datastreams: + * "Interchange" datastreams contain an image and all tables needed to decode + the image. These are the usual kind of JPEG file. + * "Abbreviated image" datastreams contain an image, but are missing some or + all of the tables needed to decode that image. + * "Abbreviated table specification" (henceforth "tables-only") datastreams + contain only table specifications. +To decode an abbreviated image, it is necessary to load the missing table(s) +into the decoder beforehand. This can be accomplished by reading a separate +tables-only file. A variant scheme uses a series of images in which the first +image is an interchange (complete) datastream, while subsequent ones are +abbreviated and rely on the tables loaded by the first image. It is assumed +that once the decoder has read a table, it will remember that table until a +new definition for the same table number is encountered. + +It is the application designer's responsibility to figure out how to associate +the correct tables with an abbreviated image. While abbreviated datastreams +can be useful in a closed environment, their use is strongly discouraged in +any situation where data exchange with other applications might be needed. +Caveat designer. + +The JPEG library provides support for reading and writing any combination of +tables-only datastreams and abbreviated images. In both compression and +decompression objects, a quantization or Huffman table will be retained for +the lifetime of the object, unless it is overwritten by a new table definition. + + +To create abbreviated image datastreams, it is only necessary to tell the +compressor not to emit some or all of the tables it is using. Each +quantization and Huffman table struct contains a boolean field "sent_table", +which normally is initialized to FALSE. For each table used by the image, the +header-writing process emits the table and sets sent_table = TRUE unless it is +already TRUE. (In normal usage, this prevents outputting the same table +definition multiple times, as would otherwise occur because the chroma +components typically share tables.) Thus, setting this field to TRUE before +calling jpeg_start_compress() will prevent the table from being written at +all. + +If you want to create a "pure" abbreviated image file containing no tables, +just call "jpeg_suppress_tables(&cinfo, TRUE)" after constructing all the +tables. If you want to emit some but not all tables, you'll need to set the +individual sent_table fields directly. + +To create an abbreviated image, you must also call jpeg_start_compress() +with a second parameter of FALSE, not TRUE. Otherwise jpeg_start_compress() +will force all the sent_table fields to FALSE. (This is a safety feature to +prevent abbreviated images from being created accidentally.) + +To create a tables-only file, perform the same parameter setup that you +normally would, but instead of calling jpeg_start_compress() and so on, call +jpeg_write_tables(&cinfo). This will write an abbreviated datastream +containing only SOI, DQT and/or DHT markers, and EOI. All the quantization +and Huffman tables that are currently defined in the compression object will +be emitted unless their sent_tables flag is already TRUE, and then all the +sent_tables flags will be set TRUE. + +A sure-fire way to create matching tables-only and abbreviated image files +is to proceed as follows: + + create JPEG compression object + set JPEG parameters + set destination to tables-only file + jpeg_write_tables(&cinfo); + set destination to image file + jpeg_start_compress(&cinfo, FALSE); + write data... + jpeg_finish_compress(&cinfo); + +Since the JPEG parameters are not altered between writing the table file and +the abbreviated image file, the same tables are sure to be used. Of course, +you can repeat the jpeg_start_compress() ... jpeg_finish_compress() sequence +many times to produce many abbreviated image files matching the table file. + +You cannot suppress output of the computed Huffman tables when Huffman +optimization is selected. (If you could, there'd be no way to decode the +image...) Generally, you don't want to set optimize_coding = TRUE when +you are trying to produce abbreviated files. + +In some cases you might want to compress an image using tables which are +not stored in the application, but are defined in an interchange or +tables-only file readable by the application. This can be done by setting up +a JPEG decompression object to read the specification file, then copying the +tables into your compression object. See jpeg_copy_critical_parameters() +for an example of copying quantization tables. + + +To read abbreviated image files, you simply need to load the proper tables +into the decompression object before trying to read the abbreviated image. +If the proper tables are stored in the application program, you can just +allocate the table structs and fill in their contents directly. For example, +to load a fixed quantization table into table slot "n": + + if (cinfo.quant_tbl_ptrs[n] == NULL) + cinfo.quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) &cinfo); + quant_ptr = cinfo.quant_tbl_ptrs[n]; /* quant_ptr is JQUANT_TBL* */ + for (i = 0; i < 64; i++) { + /* Qtable[] is desired quantization table, in natural array order */ + quant_ptr->quantval[i] = Qtable[i]; + } + +Code to load a fixed Huffman table is typically (for AC table "n"): + + if (cinfo.ac_huff_tbl_ptrs[n] == NULL) + cinfo.ac_huff_tbl_ptrs[n] = jpeg_alloc_huff_table((j_common_ptr) &cinfo); + huff_ptr = cinfo.ac_huff_tbl_ptrs[n]; /* huff_ptr is JHUFF_TBL* */ + for (i = 1; i <= 16; i++) { + /* counts[i] is number of Huffman codes of length i bits, i=1..16 */ + huff_ptr->bits[i] = counts[i]; + } + for (i = 0; i < 256; i++) { + /* symbols[] is the list of Huffman symbols, in code-length order */ + huff_ptr->huffval[i] = symbols[i]; + } + +(Note that trying to set cinfo.quant_tbl_ptrs[n] to point directly at a +constant JQUANT_TBL object is not safe. If the incoming file happened to +contain a quantization table definition, your master table would get +overwritten! Instead allocate a working table copy and copy the master table +into it, as illustrated above. Ditto for Huffman tables, of course.) + +You might want to read the tables from a tables-only file, rather than +hard-wiring them into your application. The jpeg_read_header() call is +sufficient to read a tables-only file. You must pass a second parameter of +FALSE to indicate that you do not require an image to be present. Thus, the +typical scenario is + + create JPEG decompression object + set source to tables-only file + jpeg_read_header(&cinfo, FALSE); + set source to abbreviated image file + jpeg_read_header(&cinfo, TRUE); + set decompression parameters + jpeg_start_decompress(&cinfo); + read data... + jpeg_finish_decompress(&cinfo); + +In some cases, you may want to read a file without knowing whether it contains +an image or just tables. In that case, pass FALSE and check the return value +from jpeg_read_header(): it will be JPEG_HEADER_OK if an image was found, +JPEG_HEADER_TABLES_ONLY if only tables were found. (A third return value, +JPEG_SUSPENDED, is possible when using a suspending data source manager.) +Note that jpeg_read_header() will not complain if you read an abbreviated +image for which you haven't loaded the missing tables; the missing-table check +occurs later, in jpeg_start_decompress(). + + +It is possible to read a series of images from a single source file by +repeating the jpeg_read_header() ... jpeg_finish_decompress() sequence, +without releasing/recreating the JPEG object or the data source module. +(If you did reinitialize, any partial bufferload left in the data source +buffer at the end of one image would be discarded, causing you to lose the +start of the next image.) When you use this method, stored tables are +automatically carried forward, so some of the images can be abbreviated images +that depend on tables from earlier images. + +If you intend to write a series of images into a single destination file, +you might want to make a specialized data destination module that doesn't +flush the output buffer at term_destination() time. This would speed things +up by some trifling amount. Of course, you'd need to remember to flush the +buffer after the last image. You can make the later images be abbreviated +ones by passing FALSE to jpeg_start_compress(). + + +Special markers +--------------- + +Some applications may need to insert or extract special data in the JPEG +datastream. The JPEG standard provides marker types "COM" (comment) and +"APP0" through "APP15" (application) to hold application-specific data. +Unfortunately, the use of these markers is not specified by the standard. +COM markers are fairly widely used to hold user-supplied text. The JFIF file +format spec uses APP0 markers with specified initial strings to hold certain +data. Adobe applications use APP14 markers beginning with the string "Adobe" +for miscellaneous data. Other APPn markers are rarely seen, but might +contain almost anything. + +If you wish to store user-supplied text, we recommend you use COM markers +and place readable 7-bit ASCII text in them. Newline conventions are not +standardized --- expect to find LF (Unix style), CR/LF (DOS style), or CR +(Mac style). A robust COM reader should be able to cope with random binary +garbage, including nulls, since some applications generate COM markers +containing non-ASCII junk. (But yours should not be one of them.) + +For program-supplied data, use an APPn marker, and be sure to begin it with an +identifying string so that you can tell whether the marker is actually yours. +It's probably best to avoid using APP0 or APP14 for any private markers. +(NOTE: the upcoming SPIFF standard will use APP8 markers; we recommend you +not use APP8 markers for any private purposes, either.) + +Keep in mind that at most 65533 bytes can be put into one marker, but you +can have as many markers as you like. + +By default, the IJG compression library will write a JFIF APP0 marker if the +selected JPEG colorspace is grayscale or YCbCr, or an Adobe APP14 marker if +the selected colorspace is RGB, CMYK, or YCCK. You can disable this, but +we don't recommend it. The decompression library will recognize JFIF and +Adobe markers and will set the JPEG colorspace properly when one is found. + + +You can write special markers immediately following the datastream header by +calling jpeg_write_marker() after jpeg_start_compress() and before the first +call to jpeg_write_scanlines(). When you do this, the markers appear after +the SOI and the JFIF APP0 and Adobe APP14 markers (if written), but before +all else. Specify the marker type parameter as "JPEG_COM" for COM or +"JPEG_APP0 + n" for APPn. (Actually, jpeg_write_marker will let you write +any marker type, but we don't recommend writing any other kinds of marker.) +For example, to write a user comment string pointed to by comment_text: + jpeg_write_marker(cinfo, JPEG_COM, comment_text, strlen(comment_text)); + +If it's not convenient to store all the marker data in memory at once, +you can instead call jpeg_write_m_header() followed by multiple calls to +jpeg_write_m_byte(). If you do it this way, it's your responsibility to +call jpeg_write_m_byte() exactly the number of times given in the length +parameter to jpeg_write_m_header(). (This method lets you empty the +output buffer partway through a marker, which might be important when +using a suspending data destination module. In any case, if you are using +a suspending destination, you should flush its buffer after inserting +any special markers. See "I/O suspension".) + +Or, if you prefer to synthesize the marker byte sequence yourself, +you can just cram it straight into the data destination module. + +If you are writing JFIF 1.02 extension markers (thumbnail images), don't +forget to set cinfo.JFIF_minor_version = 2 so that the encoder will write the +correct JFIF version number in the JFIF header marker. The library's default +is to write version 1.01, but that's wrong if you insert any 1.02 extension +markers. (We could probably get away with just defaulting to 1.02, but there +used to be broken decoders that would complain about unknown minor version +numbers. To reduce compatibility risks it's safest not to write 1.02 unless +you are actually using 1.02 extensions.) + + +When reading, two methods of handling special markers are available: +1. You can ask the library to save the contents of COM and/or APPn markers +into memory, and then examine them at your leisure afterwards. +2. You can supply your own routine to process COM and/or APPn markers +on-the-fly as they are read. +The first method is simpler to use, especially if you are using a suspending +data source; writing a marker processor that copes with input suspension is +not easy (consider what happens if the marker is longer than your available +input buffer). However, the second method conserves memory since the marker +data need not be kept around after it's been processed. + +For either method, you'd normally set up marker handling after creating a +decompression object and before calling jpeg_read_header(), because the +markers of interest will typically be near the head of the file and so will +be scanned by jpeg_read_header. Once you've established a marker handling +method, it will be used for the life of that decompression object +(potentially many datastreams), unless you change it. Marker handling is +determined separately for COM markers and for each APPn marker code. + + +To save the contents of special markers in memory, call + jpeg_save_markers(cinfo, marker_code, length_limit) +where marker_code is the marker type to save, JPEG_COM or JPEG_APP0+n. +(To arrange to save all the special marker types, you need to call this +routine 17 times, for COM and APP0-APP15.) If the incoming marker is longer +than length_limit data bytes, only length_limit bytes will be saved; this +parameter allows you to avoid chewing up memory when you only need to see the +first few bytes of a potentially large marker. If you want to save all the +data, set length_limit to 0xFFFF; that is enough since marker lengths are only +16 bits. As a special case, setting length_limit to 0 prevents that marker +type from being saved at all. (That is the default behavior, in fact.) + +After jpeg_read_header() completes, you can examine the special markers by +following the cinfo->marker_list pointer chain. All the special markers in +the file appear in this list, in order of their occurrence in the file (but +omitting any markers of types you didn't ask for). Both the original data +length and the saved data length are recorded for each list entry; the latter +will not exceed length_limit for the particular marker type. Note that these +lengths exclude the marker length word, whereas the stored representation +within the JPEG file includes it. (Hence the maximum data length is really +only 65533.) + +It is possible that additional special markers appear in the file beyond the +SOS marker at which jpeg_read_header stops; if so, the marker list will be +extended during reading of the rest of the file. This is not expected to be +common, however. If you are short on memory you may want to reset the length +limit to zero for all marker types after finishing jpeg_read_header, to +ensure that the max_memory_to_use setting cannot be exceeded due to addition +of later markers. + +The marker list remains stored until you call jpeg_finish_decompress or +jpeg_abort, at which point the memory is freed and the list is set to empty. +(jpeg_destroy also releases the storage, of course.) + +Note that the library is internally interested in APP0 and APP14 markers; +if you try to set a small nonzero length limit on these types, the library +will silently force the length up to the minimum it wants. (But you can set +a zero length limit to prevent them from being saved at all.) Also, in a +16-bit environment, the maximum length limit may be constrained to less than +65533 by malloc() limitations. It is therefore best not to assume that the +effective length limit is exactly what you set it to be. + + +If you want to supply your own marker-reading routine, you do it by calling +jpeg_set_marker_processor(). A marker processor routine must have the +signature + boolean jpeg_marker_parser_method (j_decompress_ptr cinfo) +Although the marker code is not explicitly passed, the routine can find it +in cinfo->unread_marker. At the time of call, the marker proper has been +read from the data source module. The processor routine is responsible for +reading the marker length word and the remaining parameter bytes, if any. +Return TRUE to indicate success. (FALSE should be returned only if you are +using a suspending data source and it tells you to suspend. See the standard +marker processors in jdmarker.c for appropriate coding methods if you need to +use a suspending data source.) + +If you override the default APP0 or APP14 processors, it is up to you to +recognize JFIF and Adobe markers if you want colorspace recognition to occur +properly. We recommend copying and extending the default processors if you +want to do that. (A better idea is to save these marker types for later +examination by calling jpeg_save_markers(); that method doesn't interfere +with the library's own processing of these markers.) + +jpeg_set_marker_processor() and jpeg_save_markers() are mutually exclusive +--- if you call one it overrides any previous call to the other, for the +particular marker type specified. + +A simple example of an external COM processor can be found in djpeg.c. +Also, see jpegtran.c for an example of using jpeg_save_markers. + + +Raw (downsampled) image data +---------------------------- + +Some applications need to supply already-downsampled image data to the JPEG +compressor, or to receive raw downsampled data from the decompressor. The +library supports this requirement by allowing the application to write or +read raw data, bypassing the normal preprocessing or postprocessing steps. +The interface is different from the standard one and is somewhat harder to +use. If your interest is merely in bypassing color conversion, we recommend +that you use the standard interface and simply set jpeg_color_space = +in_color_space (or jpeg_color_space = out_color_space for decompression). +The mechanism described in this section is necessary only to supply or +receive downsampled image data, in which not all components have the same +dimensions. + + +To compress raw data, you must supply the data in the colorspace to be used +in the JPEG file (please read the earlier section on Special color spaces) +and downsampled to the sampling factors specified in the JPEG parameters. +You must supply the data in the format used internally by the JPEG library, +namely a JSAMPIMAGE array. This is an array of pointers to two-dimensional +arrays, each of type JSAMPARRAY. Each 2-D array holds the values for one +color component. This structure is necessary since the components are of +different sizes. If the image dimensions are not a multiple of the MCU size, +you must also pad the data correctly (usually, this is done by replicating +the last column and/or row). The data must be padded to a multiple of a DCT +block in each component: that is, each downsampled row must contain a +multiple of 8 valid samples, and there must be a multiple of 8 sample rows +for each component. (For applications such as conversion of digital TV +images, the standard image size is usually a multiple of the DCT block size, +so that no padding need actually be done.) + +The procedure for compression of raw data is basically the same as normal +compression, except that you call jpeg_write_raw_data() in place of +jpeg_write_scanlines(). Before calling jpeg_start_compress(), you must do +the following: + * Set cinfo->raw_data_in to TRUE. (It is set FALSE by jpeg_set_defaults().) + This notifies the library that you will be supplying raw data. + Furthermore, set cinfo->do_fancy_downsampling to FALSE if you want to use + real downsampled data. (It is set TRUE by jpeg_set_defaults().) + * Ensure jpeg_color_space is correct --- an explicit jpeg_set_colorspace() + call is a good idea. Note that since color conversion is bypassed, + in_color_space is ignored, except that jpeg_set_defaults() uses it to + choose the default jpeg_color_space setting. + * Ensure the sampling factors, cinfo->comp_info[i].h_samp_factor and + cinfo->comp_info[i].v_samp_factor, are correct. Since these indicate the + dimensions of the data you are supplying, it's wise to set them + explicitly, rather than assuming the library's defaults are what you want. + +To pass raw data to the library, call jpeg_write_raw_data() in place of +jpeg_write_scanlines(). The two routines work similarly except that +jpeg_write_raw_data takes a JSAMPIMAGE data array rather than JSAMPARRAY. +The scanlines count passed to and returned from jpeg_write_raw_data is +measured in terms of the component with the largest v_samp_factor. + +jpeg_write_raw_data() processes one MCU row per call, which is to say +v_samp_factor*DCTSIZE sample rows of each component. The passed num_lines +value must be at least max_v_samp_factor*DCTSIZE, and the return value will +be exactly that amount (or possibly some multiple of that amount, in future +library versions). This is true even on the last call at the bottom of the +image; don't forget to pad your data as necessary. + +The required dimensions of the supplied data can be computed for each +component as + cinfo->comp_info[i].width_in_blocks*DCTSIZE samples per row + cinfo->comp_info[i].height_in_blocks*DCTSIZE rows in image +after jpeg_start_compress() has initialized those fields. If the valid data +is smaller than this, it must be padded appropriately. For some sampling +factors and image sizes, additional dummy DCT blocks are inserted to make +the image a multiple of the MCU dimensions. The library creates such dummy +blocks itself; it does not read them from your supplied data. Therefore you +need never pad by more than DCTSIZE samples. An example may help here. +Assume 2h2v downsampling of YCbCr data, that is + cinfo->comp_info[0].h_samp_factor = 2 for Y + cinfo->comp_info[0].v_samp_factor = 2 + cinfo->comp_info[1].h_samp_factor = 1 for Cb + cinfo->comp_info[1].v_samp_factor = 1 + cinfo->comp_info[2].h_samp_factor = 1 for Cr + cinfo->comp_info[2].v_samp_factor = 1 +and suppose that the nominal image dimensions (cinfo->image_width and +cinfo->image_height) are 101x101 pixels. Then jpeg_start_compress() will +compute downsampled_width = 101 and width_in_blocks = 13 for Y, +downsampled_width = 51 and width_in_blocks = 7 for Cb and Cr (and the same +for the height fields). You must pad the Y data to at least 13*8 = 104 +columns and rows, the Cb/Cr data to at least 7*8 = 56 columns and rows. The +MCU height is max_v_samp_factor = 2 DCT rows so you must pass at least 16 +scanlines on each call to jpeg_write_raw_data(), which is to say 16 actual +sample rows of Y and 8 each of Cb and Cr. A total of 7 MCU rows are needed, +so you must pass a total of 7*16 = 112 "scanlines". The last DCT block row +of Y data is dummy, so it doesn't matter what you pass for it in the data +arrays, but the scanlines count must total up to 112 so that all of the Cb +and Cr data gets passed. + +Output suspension is supported with raw-data compression: if the data +destination module suspends, jpeg_write_raw_data() will return 0. +In this case the same data rows must be passed again on the next call. + + +Decompression with raw data output implies bypassing all postprocessing. +You must deal with the color space and sampling factors present in the +incoming file. If your application only handles, say, 2h1v YCbCr data, +you must check for and fail on other color spaces or other sampling factors. +The library will not convert to a different color space for you. + +To obtain raw data output, set cinfo->raw_data_out = TRUE before +jpeg_start_decompress() (it is set FALSE by jpeg_read_header()). Be sure to +verify that the color space and sampling factors are ones you can handle. +Furthermore, set cinfo->do_fancy_upsampling = FALSE if you want to get real +downsampled data (it is set TRUE by jpeg_read_header()). +Then call jpeg_read_raw_data() in place of jpeg_read_scanlines(). The +decompression process is otherwise the same as usual. + +jpeg_read_raw_data() returns one MCU row per call, and thus you must pass a +buffer of at least max_v_samp_factor*DCTSIZE scanlines (scanline counting is +the same as for raw-data compression). The buffer you pass must be large +enough to hold the actual data plus padding to DCT-block boundaries. As with +compression, any entirely dummy DCT blocks are not processed so you need not +allocate space for them, but the total scanline count includes them. The +above example of computing buffer dimensions for raw-data compression is +equally valid for decompression. + +Input suspension is supported with raw-data decompression: if the data source +module suspends, jpeg_read_raw_data() will return 0. You can also use +buffered-image mode to read raw data in multiple passes. + + +Really raw data: DCT coefficients +--------------------------------- + +It is possible to read or write the contents of a JPEG file as raw DCT +coefficients. This facility is mainly intended for use in lossless +transcoding between different JPEG file formats. Other possible applications +include lossless cropping of a JPEG image, lossless reassembly of a +multi-strip or multi-tile TIFF/JPEG file into a single JPEG datastream, etc. + +To read the contents of a JPEG file as DCT coefficients, open the file and do +jpeg_read_header() as usual. But instead of calling jpeg_start_decompress() +and jpeg_read_scanlines(), call jpeg_read_coefficients(). This will read the +entire image into a set of virtual coefficient-block arrays, one array per +component. The return value is a pointer to an array of virtual-array +descriptors. Each virtual array can be accessed directly using the JPEG +memory manager's access_virt_barray method (see Memory management, below, +and also read structure.txt's discussion of virtual array handling). Or, +for simple transcoding to a different JPEG file format, the array list can +just be handed directly to jpeg_write_coefficients(). + +Each block in the block arrays contains quantized coefficient values in +normal array order (not JPEG zigzag order). The block arrays contain only +DCT blocks containing real data; any entirely-dummy blocks added to fill out +interleaved MCUs at the right or bottom edges of the image are discarded +during reading and are not stored in the block arrays. (The size of each +block array can be determined from the width_in_blocks and height_in_blocks +fields of the component's comp_info entry.) This is also the data format +expected by jpeg_write_coefficients(). + +When you are done using the virtual arrays, call jpeg_finish_decompress() +to release the array storage and return the decompression object to an idle +state; or just call jpeg_destroy() if you don't need to reuse the object. + +If you use a suspending data source, jpeg_read_coefficients() will return +NULL if it is forced to suspend; a non-NULL return value indicates successful +completion. You need not test for a NULL return value when using a +non-suspending data source. + +It is also possible to call jpeg_read_coefficients() to obtain access to the +decoder's coefficient arrays during a normal decode cycle in buffered-image +mode. This frammish might be useful for progressively displaying an incoming +image and then re-encoding it without loss. To do this, decode in buffered- +image mode as discussed previously, then call jpeg_read_coefficients() after +the last jpeg_finish_output() call. The arrays will be available for your use +until you call jpeg_finish_decompress(). + + +To write the contents of a JPEG file as DCT coefficients, you must provide +the DCT coefficients stored in virtual block arrays. You can either pass +block arrays read from an input JPEG file by jpeg_read_coefficients(), or +allocate virtual arrays from the JPEG compression object and fill them +yourself. In either case, jpeg_write_coefficients() is substituted for +jpeg_start_compress() and jpeg_write_scanlines(). Thus the sequence is + * Create compression object + * Set all compression parameters as necessary + * Request virtual arrays if needed + * jpeg_write_coefficients() + * jpeg_finish_compress() + * Destroy or re-use compression object +jpeg_write_coefficients() is passed a pointer to an array of virtual block +array descriptors; the number of arrays is equal to cinfo.num_components. + +The virtual arrays need only have been requested, not realized, before +jpeg_write_coefficients() is called. A side-effect of +jpeg_write_coefficients() is to realize any virtual arrays that have been +requested from the compression object's memory manager. Thus, when obtaining +the virtual arrays from the compression object, you should fill the arrays +after calling jpeg_write_coefficients(). The data is actually written out +when you call jpeg_finish_compress(); jpeg_write_coefficients() only writes +the file header. + +When writing raw DCT coefficients, it is crucial that the JPEG quantization +tables and sampling factors match the way the data was encoded, or the +resulting file will be invalid. For transcoding from an existing JPEG file, +we recommend using jpeg_copy_critical_parameters(). This routine initializes +all the compression parameters to default values (like jpeg_set_defaults()), +then copies the critical information from a source decompression object. +The decompression object should have just been used to read the entire +JPEG input file --- that is, it should be awaiting jpeg_finish_decompress(). + +jpeg_write_coefficients() marks all tables stored in the compression object +as needing to be written to the output file (thus, it acts like +jpeg_start_compress(cinfo, TRUE)). This is for safety's sake, to avoid +emitting abbreviated JPEG files by accident. If you really want to emit an +abbreviated JPEG file, call jpeg_suppress_tables(), or set the tables' +individual sent_table flags, between calling jpeg_write_coefficients() and +jpeg_finish_compress(). + + +Progress monitoring +------------------- + +Some applications may need to regain control from the JPEG library every so +often. The typical use of this feature is to produce a percent-done bar or +other progress display. (For a simple example, see cjpeg.c or djpeg.c.) +Although you do get control back frequently during the data-transferring pass +(the jpeg_read_scanlines or jpeg_write_scanlines loop), any additional passes +will occur inside jpeg_finish_compress or jpeg_start_decompress; those +routines may take a long time to execute, and you don't get control back +until they are done. + +You can define a progress-monitor routine which will be called periodically +by the library. No guarantees are made about how often this call will occur, +so we don't recommend you use it for mouse tracking or anything like that. +At present, a call will occur once per MCU row, scanline, or sample row +group, whichever unit is convenient for the current processing mode; so the +wider the image, the longer the time between calls. During the data +transferring pass, only one call occurs per call of jpeg_read_scanlines or +jpeg_write_scanlines, so don't pass a large number of scanlines at once if +you want fine resolution in the progress count. (If you really need to use +the callback mechanism for time-critical tasks like mouse tracking, you could +insert additional calls inside some of the library's inner loops.) + +To establish a progress-monitor callback, create a struct jpeg_progress_mgr, +fill in its progress_monitor field with a pointer to your callback routine, +and set cinfo->progress to point to the struct. The callback will be called +whenever cinfo->progress is non-NULL. (This pointer is set to NULL by +jpeg_create_compress or jpeg_create_decompress; the library will not change +it thereafter. So if you allocate dynamic storage for the progress struct, +make sure it will live as long as the JPEG object does. Allocating from the +JPEG memory manager with lifetime JPOOL_PERMANENT will work nicely.) You +can use the same callback routine for both compression and decompression. + +The jpeg_progress_mgr struct contains four fields which are set by the library: + long pass_counter; /* work units completed in this pass */ + long pass_limit; /* total number of work units in this pass */ + int completed_passes; /* passes completed so far */ + int total_passes; /* total number of passes expected */ +During any one pass, pass_counter increases from 0 up to (not including) +pass_limit; the step size is usually but not necessarily 1. The pass_limit +value may change from one pass to another. The expected total number of +passes is in total_passes, and the number of passes already completed is in +completed_passes. Thus the fraction of work completed may be estimated as + completed_passes + (pass_counter/pass_limit) + -------------------------------------------- + total_passes +ignoring the fact that the passes may not be equal amounts of work. + +When decompressing, pass_limit can even change within a pass, because it +depends on the number of scans in the JPEG file, which isn't always known in +advance. The computed fraction-of-work-done may jump suddenly (if the library +discovers it has overestimated the number of scans) or even decrease (in the +opposite case). It is not wise to put great faith in the work estimate. + +When using the decompressor's buffered-image mode, the progress monitor work +estimate is likely to be completely unhelpful, because the library has no way +to know how many output passes will be demanded of it. Currently, the library +sets total_passes based on the assumption that there will be one more output +pass if the input file end hasn't yet been read (jpeg_input_complete() isn't +TRUE), but no more output passes if the file end has been reached when the +output pass is started. This means that total_passes will rise as additional +output passes are requested. If you have a way of determining the input file +size, estimating progress based on the fraction of the file that's been read +will probably be more useful than using the library's value. + + +Memory management +----------------- + +This section covers some key facts about the JPEG library's built-in memory +manager. For more info, please read structure.txt's section about the memory +manager, and consult the source code if necessary. + +All memory and temporary file allocation within the library is done via the +memory manager. If necessary, you can replace the "back end" of the memory +manager to control allocation yourself (for example, if you don't want the +library to use malloc() and free() for some reason). + +Some data is allocated "permanently" and will not be freed until the JPEG +object is destroyed. Most data is allocated "per image" and is freed by +jpeg_finish_compress, jpeg_finish_decompress, or jpeg_abort. You can call the +memory manager yourself to allocate structures that will automatically be +freed at these times. Typical code for this is + ptr = (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, size); +Use JPOOL_PERMANENT to get storage that lasts as long as the JPEG object. +Use alloc_large instead of alloc_small for anything bigger than a few Kbytes. +There are also alloc_sarray and alloc_barray routines that automatically +build 2-D sample or block arrays. + +The library's minimum space requirements to process an image depend on the +image's width, but not on its height, because the library ordinarily works +with "strip" buffers that are as wide as the image but just a few rows high. +Some operating modes (eg, two-pass color quantization) require full-image +buffers. Such buffers are treated as "virtual arrays": only the current strip +need be in memory, and the rest can be swapped out to a temporary file. + +If you use the simplest memory manager back end (jmemnobs.c), then no +temporary files are used; virtual arrays are simply malloc()'d. Images bigger +than memory can be processed only if your system supports virtual memory. +The other memory manager back ends support temporary files of various flavors +and thus work in machines without virtual memory. They may also be useful on +Unix machines if you need to process images that exceed available swap space. + +When using temporary files, the library will make the in-memory buffers for +its virtual arrays just big enough to stay within a "maximum memory" setting. +Your application can set this limit by setting cinfo->mem->max_memory_to_use +after creating the JPEG object. (Of course, there is still a minimum size for +the buffers, so the max-memory setting is effective only if it is bigger than +the minimum space needed.) If you allocate any large structures yourself, you +must allocate them before jpeg_start_compress() or jpeg_start_decompress() in +order to have them counted against the max memory limit. Also keep in mind +that space allocated with alloc_small() is ignored, on the assumption that +it's too small to be worth worrying about; so a reasonable safety margin +should be left when setting max_memory_to_use. + +If you use the jmemname.c or jmemdos.c memory manager back end, it is +important to clean up the JPEG object properly to ensure that the temporary +files get deleted. (This is especially crucial with jmemdos.c, where the +"temporary files" may be extended-memory segments; if they are not freed, +DOS will require a reboot to recover the memory.) Thus, with these memory +managers, it's a good idea to provide a signal handler that will trap any +early exit from your program. The handler should call either jpeg_abort() +or jpeg_destroy() for any active JPEG objects. A handler is not needed with +jmemnobs.c, and shouldn't be necessary with jmemansi.c or jmemmac.c either, +since the C library is supposed to take care of deleting files made with +tmpfile(). + + +Memory usage +------------ + +Working memory requirements while performing compression or decompression +depend on image dimensions, image characteristics (such as colorspace and +JPEG process), and operating mode (application-selected options). + +As of v6b, the decompressor requires: + 1. About 24K in more-or-less-fixed-size data. This varies a bit depending + on operating mode and image characteristics (particularly color vs. + grayscale), but it doesn't depend on image dimensions. + 2. Strip buffers (of size proportional to the image width) for IDCT and + upsampling results. The worst case for commonly used sampling factors + is about 34 bytes * width in pixels for a color image. A grayscale image + only needs about 8 bytes per pixel column. + 3. A full-image DCT coefficient buffer is needed to decode a multi-scan JPEG + file (including progressive JPEGs), or whenever you select buffered-image + mode. This takes 2 bytes/coefficient. At typical 2x2 sampling, that's + 3 bytes per pixel for a color image. Worst case (1x1 sampling) requires + 6 bytes/pixel. For grayscale, figure 2 bytes/pixel. + 4. To perform 2-pass color quantization, the decompressor also needs a + 128K color lookup table and a full-image pixel buffer (3 bytes/pixel). +This does not count any memory allocated by the application, such as a +buffer to hold the final output image. + +The above figures are valid for 8-bit JPEG data precision and a machine with +32-bit ints. For 12-bit JPEG data, double the size of the strip buffers and +quantization pixel buffer. The "fixed-size" data will be somewhat smaller +with 16-bit ints, larger with 64-bit ints. Also, CMYK or other unusual +color spaces will require different amounts of space. + +The full-image coefficient and pixel buffers, if needed at all, do not +have to be fully RAM resident; you can have the library use temporary +files instead when the total memory usage would exceed a limit you set. +(But if your OS supports virtual memory, it's probably better to just use +jmemnobs and let the OS do the swapping.) + +The compressor's memory requirements are similar, except that it has no need +for color quantization. Also, it needs a full-image DCT coefficient buffer +if Huffman-table optimization is asked for, even if progressive mode is not +requested. + +If you need more detailed information about memory usage in a particular +situation, you can enable the MEM_STATS code in jmemmgr.c. + + +Library compile-time options +---------------------------- + +A number of compile-time options are available by modifying jmorecfg.h. + +The JPEG standard provides for both the baseline 8-bit DCT process and +a 12-bit DCT process. The IJG code supports 12-bit JPEG if you define +BITS_IN_JSAMPLE as 12 rather than 8. Note that this causes JSAMPLE to be +larger than a char, so it affects the surrounding application's image data. +The sample applications cjpeg and djpeg can support 12-bit mode only for PPM +and GIF file formats; you must disable the other file formats to compile a +12-bit cjpeg or djpeg. (install.txt has more information about that.) +At present, a 12-bit library can handle *only* 12-bit images, not both +precisions. (If you need to include both 8- and 12-bit libraries in a single +application, you could probably do it by defining NEED_SHORT_EXTERNAL_NAMES +for just one of the copies. You'd have to access the 8-bit and 12-bit copies +from separate application source files. This is untested ... if you try it, +we'd like to hear whether it works!) + +Note that a 12-bit library always compresses in Huffman optimization mode, +in order to generate valid Huffman tables. This is necessary because our +default Huffman tables only cover 8-bit data. If you need to output 12-bit +files in one pass, you'll have to supply suitable default Huffman tables. +You may also want to supply your own DCT quantization tables; the existing +quality-scaling code has been developed for 8-bit use, and probably doesn't +generate especially good tables for 12-bit. + +The maximum number of components (color channels) in the image is determined +by MAX_COMPONENTS. The JPEG standard allows up to 255 components, but we +expect that few applications will need more than four or so. + +On machines with unusual data type sizes, you may be able to improve +performance or reduce memory space by tweaking the various typedefs in +jmorecfg.h. In particular, on some RISC CPUs, access to arrays of "short"s +is quite slow; consider trading memory for speed by making JCOEF, INT16, and +UINT16 be "int" or "unsigned int". UINT8 is also a candidate to become int. +You probably don't want to make JSAMPLE be int unless you have lots of memory +to burn. + +You can reduce the size of the library by compiling out various optional +functions. To do this, undefine xxx_SUPPORTED symbols as necessary. + +You can also save a few K by not having text error messages in the library; +the standard error message table occupies about 5Kb. This is particularly +reasonable for embedded applications where there's no good way to display +a message anyway. To do this, remove the creation of the message table +(jpeg_std_message_table[]) from jerror.c, and alter format_message to do +something reasonable without it. You could output the numeric value of the +message code number, for example. If you do this, you can also save a couple +more K by modifying the TRACEMSn() macros in jerror.h to expand to nothing; +you don't need trace capability anyway, right? + + +Portability considerations +-------------------------- + +The JPEG library has been written to be extremely portable; the sample +applications cjpeg and djpeg are slightly less so. This section summarizes +the design goals in this area. (If you encounter any bugs that cause the +library to be less portable than is claimed here, we'd appreciate hearing +about them.) + +The code works fine on ANSI C, C++, and pre-ANSI C compilers, using any of +the popular system include file setups, and some not-so-popular ones too. +See install.txt for configuration procedures. + +The code is not dependent on the exact sizes of the C data types. As +distributed, we make the assumptions that + char is at least 8 bits wide + short is at least 16 bits wide + int is at least 16 bits wide + long is at least 32 bits wide +(These are the minimum requirements of the ANSI C standard.) Wider types will +work fine, although memory may be used inefficiently if char is much larger +than 8 bits or short is much bigger than 16 bits. The code should work +equally well with 16- or 32-bit ints. + +In a system where these assumptions are not met, you may be able to make the +code work by modifying the typedefs in jmorecfg.h. However, you will probably +have difficulty if int is less than 16 bits wide, since references to plain +int abound in the code. + +char can be either signed or unsigned, although the code runs faster if an +unsigned char type is available. If char is wider than 8 bits, you will need +to redefine JOCTET and/or provide custom data source/destination managers so +that JOCTET represents exactly 8 bits of data on external storage. + +The JPEG library proper does not assume ASCII representation of characters. +But some of the image file I/O modules in cjpeg/djpeg do have ASCII +dependencies in file-header manipulation; so does cjpeg's select_file_type() +routine. + +The JPEG library does not rely heavily on the C library. In particular, C +stdio is used only by the data source/destination modules and the error +handler, all of which are application-replaceable. (cjpeg/djpeg are more +heavily dependent on stdio.) malloc and free are called only from the memory +manager "back end" module, so you can use a different memory allocator by +replacing that one file. + +The code generally assumes that C names must be unique in the first 15 +characters. However, global function names can be made unique in the +first 6 characters by defining NEED_SHORT_EXTERNAL_NAMES. + +More info about porting the code may be gleaned by reading jconfig.txt, +jmorecfg.h, and jinclude.h. + + +Notes for MS-DOS implementors +----------------------------- + +The IJG code is designed to work efficiently in 80x86 "small" or "medium" +memory models (i.e., data pointers are 16 bits unless explicitly declared +"far"; code pointers can be either size). You may be able to use small +model to compile cjpeg or djpeg by itself, but you will probably have to use +medium model for any larger application. This won't make much difference in +performance. You *will* take a noticeable performance hit if you use a +large-data memory model (perhaps 10%-25%), and you should avoid "huge" model +if at all possible. + +The JPEG library typically needs 2Kb-3Kb of stack space. It will also +malloc about 20K-30K of near heap space while executing (and lots of far +heap, but that doesn't count in this calculation). This figure will vary +depending on selected operating mode, and to a lesser extent on image size. +There is also about 5Kb-6Kb of constant data which will be allocated in the +near data segment (about 4Kb of this is the error message table). +Thus you have perhaps 20K available for other modules' static data and near +heap space before you need to go to a larger memory model. The C library's +static data will account for several K of this, but that still leaves a good +deal for your needs. (If you are tight on space, you could reduce the sizes +of the I/O buffers allocated by jdatasrc.c and jdatadst.c, say from 4K to +1K. Another possibility is to move the error message table to far memory; +this should be doable with only localized hacking on jerror.c.) + +About 2K of the near heap space is "permanent" memory that will not be +released until you destroy the JPEG object. This is only an issue if you +save a JPEG object between compression or decompression operations. + +Far data space may also be a tight resource when you are dealing with large +images. The most memory-intensive case is decompression with two-pass color +quantization, or single-pass quantization to an externally supplied color +map. This requires a 128Kb color lookup table plus strip buffers amounting +to about 40 bytes per column for typical sampling ratios (eg, about 25600 +bytes for a 640-pixel-wide image). You may not be able to process wide +images if you have large data structures of your own. + +Of course, all of these concerns vanish if you use a 32-bit flat-memory-model +compiler, such as DJGPP or Watcom C. We highly recommend flat model if you +can use it; the JPEG library is significantly faster in flat model. diff --git a/Source/LibJPEG/rdbmp.c b/Source/LibJPEG/rdbmp.c index dfdf96f..fd773d4 100644 --- a/Source/LibJPEG/rdbmp.c +++ b/Source/LibJPEG/rdbmp.c @@ -1,480 +1,480 @@ -/* - * rdbmp.c - * - * Copyright (C) 1994-1996, Thomas G. Lane. - * Modified 2009-2010 by Guido Vollbeding. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains routines to read input images in Microsoft "BMP" - * format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors). - * Currently, only 8-bit and 24-bit images are supported, not 1-bit or - * 4-bit (feeding such low-depth images into JPEG would be silly anyway). - * Also, we don't support RLE-compressed files. - * - * These routines may need modification for non-Unix environments or - * specialized applications. As they stand, they assume input from - * an ordinary stdio stream. They further assume that reading begins - * at the start of the file; start_input may need work if the - * user interface has already read some data (e.g., to determine that - * the file is indeed BMP format). - * - * This code contributed by James Arthur Boucher. - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ - -#ifdef BMP_SUPPORTED - - -/* Macros to deal with unsigned chars as efficiently as compiler allows */ - -#ifdef HAVE_UNSIGNED_CHAR -typedef unsigned char U_CHAR; -#define UCH(x) ((int) (x)) -#else /* !HAVE_UNSIGNED_CHAR */ -#ifdef CHAR_IS_UNSIGNED -typedef char U_CHAR; -#define UCH(x) ((int) (x)) -#else -typedef char U_CHAR; -#define UCH(x) ((int) (x) & 0xFF) -#endif -#endif /* HAVE_UNSIGNED_CHAR */ - - -#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) - - -/* Private version of data source object */ - -typedef struct _bmp_source_struct * bmp_source_ptr; - -typedef struct _bmp_source_struct { - struct cjpeg_source_struct pub; /* public fields */ - - j_compress_ptr cinfo; /* back link saves passing separate parm */ - - JSAMPARRAY colormap; /* BMP colormap (converted to my format) */ - - jvirt_sarray_ptr whole_image; /* Needed to reverse row order */ - JDIMENSION source_row; /* Current source row number */ - JDIMENSION row_width; /* Physical width of scanlines in file */ - - int bits_per_pixel; /* remembers 8- or 24-bit format */ -} bmp_source_struct; - - -LOCAL(int) -read_byte (bmp_source_ptr sinfo) -/* Read next byte from BMP file */ -{ - register FILE *infile = sinfo->pub.input_file; - register int c; - - if ((c = getc(infile)) == EOF) - ERREXIT(sinfo->cinfo, JERR_INPUT_EOF); - return c; -} - - -LOCAL(void) -read_colormap (bmp_source_ptr sinfo, int cmaplen, int mapentrysize) -/* Read the colormap from a BMP file */ -{ - int i; - - switch (mapentrysize) { - case 3: - /* BGR format (occurs in OS/2 files) */ - for (i = 0; i < cmaplen; i++) { - sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo); - sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo); - sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo); - } - break; - case 4: - /* BGR0 format (occurs in MS Windows files) */ - for (i = 0; i < cmaplen; i++) { - sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo); - sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo); - sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo); - (void) read_byte(sinfo); - } - break; - default: - ERREXIT(sinfo->cinfo, JERR_BMP_BADCMAP); - break; - } -} - - -/* - * Read one row of pixels. - * The image has been read into the whole_image array, but is otherwise - * unprocessed. We must read it out in top-to-bottom row order, and if - * it is an 8-bit image, we must expand colormapped pixels to 24bit format. - */ - -METHODDEF(JDIMENSION) -get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading 8-bit colormap indexes */ -{ - bmp_source_ptr source = (bmp_source_ptr) sinfo; - register JSAMPARRAY colormap = source->colormap; - JSAMPARRAY image_ptr; - register int t; - register JSAMPROW inptr, outptr; - register JDIMENSION col; - - /* Fetch next row from virtual array */ - source->source_row--; - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->whole_image, - source->source_row, (JDIMENSION) 1, FALSE); - - /* Expand the colormap indexes to real data */ - inptr = image_ptr[0]; - outptr = source->pub.buffer[0]; - for (col = cinfo->image_width; col > 0; col--) { - t = GETJSAMPLE(*inptr++); - *outptr++ = colormap[0][t]; /* can omit GETJSAMPLE() safely */ - *outptr++ = colormap[1][t]; - *outptr++ = colormap[2][t]; - } - - return 1; -} - - -METHODDEF(JDIMENSION) -get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading 24-bit pixels */ -{ - bmp_source_ptr source = (bmp_source_ptr) sinfo; - JSAMPARRAY image_ptr; - register JSAMPROW inptr, outptr; - register JDIMENSION col; - - /* Fetch next row from virtual array */ - source->source_row--; - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->whole_image, - source->source_row, (JDIMENSION) 1, FALSE); - - /* Transfer data. Note source values are in BGR order - * (even though Microsoft's own documents say the opposite). - */ - inptr = image_ptr[0]; - outptr = source->pub.buffer[0]; - for (col = cinfo->image_width; col > 0; col--) { - outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ - outptr[1] = *inptr++; - outptr[0] = *inptr++; - outptr += 3; - } - - return 1; -} - - -METHODDEF(JDIMENSION) -get_32bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading 32-bit pixels */ -{ - bmp_source_ptr source = (bmp_source_ptr) sinfo; - JSAMPARRAY image_ptr; - register JSAMPROW inptr, outptr; - register JDIMENSION col; - - /* Fetch next row from virtual array */ - source->source_row--; - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->whole_image, - source->source_row, (JDIMENSION) 1, FALSE); - /* Transfer data. Note source values are in BGR order - * (even though Microsoft's own documents say the opposite). - */ - inptr = image_ptr[0]; - outptr = source->pub.buffer[0]; - for (col = cinfo->image_width; col > 0; col--) { - outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ - outptr[1] = *inptr++; - outptr[0] = *inptr++; - inptr++; /* skip the 4th byte (Alpha channel) */ - outptr += 3; - } - - return 1; -} - - -/* - * This method loads the image into whole_image during the first call on - * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call - * get_8bit_row, get_24bit_row, or get_32bit_row on subsequent calls. - */ - -METHODDEF(JDIMENSION) -preload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - bmp_source_ptr source = (bmp_source_ptr) sinfo; - register FILE *infile = source->pub.input_file; - register int c; - register JSAMPROW out_ptr; - JSAMPARRAY image_ptr; - JDIMENSION row, col; - cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; - - /* Read the data into a virtual array in input-file row order. */ - for (row = 0; row < cinfo->image_height; row++) { - if (progress != NULL) { - progress->pub.pass_counter = (long) row; - progress->pub.pass_limit = (long) cinfo->image_height; - (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); - } - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->whole_image, - row, (JDIMENSION) 1, TRUE); - out_ptr = image_ptr[0]; - for (col = source->row_width; col > 0; col--) { - /* inline copy of read_byte() for speed */ - if ((c = getc(infile)) == EOF) - ERREXIT(cinfo, JERR_INPUT_EOF); - *out_ptr++ = (JSAMPLE) c; - } - } - if (progress != NULL) - progress->completed_extra_passes++; - - /* Set up to read from the virtual array in top-to-bottom order */ - switch (source->bits_per_pixel) { - case 8: - source->pub.get_pixel_rows = get_8bit_row; - break; - case 24: - source->pub.get_pixel_rows = get_24bit_row; - break; - case 32: - source->pub.get_pixel_rows = get_32bit_row; - break; - default: - ERREXIT(cinfo, JERR_BMP_BADDEPTH); - } - source->source_row = cinfo->image_height; - - /* And read the first row */ - return (*source->pub.get_pixel_rows) (cinfo, sinfo); -} - - -/* - * Read the file header; return image size and component count. - */ - -METHODDEF(void) -start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - bmp_source_ptr source = (bmp_source_ptr) sinfo; - U_CHAR bmpfileheader[14]; - U_CHAR bmpinfoheader[64]; -#define GET_2B(array,offset) ((unsigned int) UCH(array[offset]) + \ - (((unsigned int) UCH(array[offset+1])) << 8)) -#define GET_4B(array,offset) ((INT32) UCH(array[offset]) + \ - (((INT32) UCH(array[offset+1])) << 8) + \ - (((INT32) UCH(array[offset+2])) << 16) + \ - (((INT32) UCH(array[offset+3])) << 24)) - INT32 bfOffBits; - INT32 headerSize; - INT32 biWidth; - INT32 biHeight; - unsigned int biPlanes; - INT32 biCompression; - INT32 biXPelsPerMeter,biYPelsPerMeter; - INT32 biClrUsed = 0; - int mapentrysize = 0; /* 0 indicates no colormap */ - INT32 bPad; - JDIMENSION row_width; - - /* Read and verify the bitmap file header */ - if (! ReadOK(source->pub.input_file, bmpfileheader, 14)) - ERREXIT(cinfo, JERR_INPUT_EOF); - if (GET_2B(bmpfileheader,0) != 0x4D42) /* 'BM' */ - ERREXIT(cinfo, JERR_BMP_NOT); - bfOffBits = (INT32) GET_4B(bmpfileheader,10); - /* We ignore the remaining fileheader fields */ - - /* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows), - * or 64 bytes (OS/2 2.x). Check the first 4 bytes to find out which. - */ - if (! ReadOK(source->pub.input_file, bmpinfoheader, 4)) - ERREXIT(cinfo, JERR_INPUT_EOF); - headerSize = (INT32) GET_4B(bmpinfoheader,0); - if (headerSize < 12 || headerSize > 64) - ERREXIT(cinfo, JERR_BMP_BADHEADER); - if (! ReadOK(source->pub.input_file, bmpinfoheader+4, headerSize-4)) - ERREXIT(cinfo, JERR_INPUT_EOF); - - switch ((int) headerSize) { - case 12: - /* Decode OS/2 1.x header (Microsoft calls this a BITMAPCOREHEADER) */ - biWidth = (INT32) GET_2B(bmpinfoheader,4); - biHeight = (INT32) GET_2B(bmpinfoheader,6); - biPlanes = GET_2B(bmpinfoheader,8); - source->bits_per_pixel = (int) GET_2B(bmpinfoheader,10); - - switch (source->bits_per_pixel) { - case 8: /* colormapped image */ - mapentrysize = 3; /* OS/2 uses RGBTRIPLE colormap */ - TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (int) biWidth, (int) biHeight); - break; - case 24: /* RGB image */ - TRACEMS2(cinfo, 1, JTRC_BMP_OS2, (int) biWidth, (int) biHeight); - break; - default: - ERREXIT(cinfo, JERR_BMP_BADDEPTH); - break; - } - break; - case 40: - case 64: - /* Decode Windows 3.x header (Microsoft calls this a BITMAPINFOHEADER) */ - /* or OS/2 2.x header, which has additional fields that we ignore */ - biWidth = GET_4B(bmpinfoheader,4); - biHeight = GET_4B(bmpinfoheader,8); - biPlanes = GET_2B(bmpinfoheader,12); - source->bits_per_pixel = (int) GET_2B(bmpinfoheader,14); - biCompression = GET_4B(bmpinfoheader,16); - biXPelsPerMeter = GET_4B(bmpinfoheader,24); - biYPelsPerMeter = GET_4B(bmpinfoheader,28); - biClrUsed = GET_4B(bmpinfoheader,32); - /* biSizeImage, biClrImportant fields are ignored */ - - switch (source->bits_per_pixel) { - case 8: /* colormapped image */ - mapentrysize = 4; /* Windows uses RGBQUAD colormap */ - TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (int) biWidth, (int) biHeight); - break; - case 24: /* RGB image */ - TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight); - break; - case 32: /* RGB image + Alpha channel */ - TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight); - break; - default: - ERREXIT(cinfo, JERR_BMP_BADDEPTH); - break; - } - if (biCompression != 0) - ERREXIT(cinfo, JERR_BMP_COMPRESSED); - - if (biXPelsPerMeter > 0 && biYPelsPerMeter > 0) { - /* Set JFIF density parameters from the BMP data */ - cinfo->X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */ - cinfo->Y_density = (UINT16) (biYPelsPerMeter/100); - cinfo->density_unit = 2; /* dots/cm */ - } - break; - default: - ERREXIT(cinfo, JERR_BMP_BADHEADER); - return; - } - - if (biWidth <= 0 || biHeight <= 0) - ERREXIT(cinfo, JERR_BMP_EMPTY); - if (biPlanes != 1) - ERREXIT(cinfo, JERR_BMP_BADPLANES); - - /* Compute distance to bitmap data --- will adjust for colormap below */ - bPad = bfOffBits - (headerSize + 14); - - /* Read the colormap, if any */ - if (mapentrysize > 0) { - if (biClrUsed <= 0) - biClrUsed = 256; /* assume it's 256 */ - else if (biClrUsed > 256) - ERREXIT(cinfo, JERR_BMP_BADCMAP); - /* Allocate space to store the colormap */ - source->colormap = (*cinfo->mem->alloc_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, - (JDIMENSION) biClrUsed, (JDIMENSION) 3); - /* and read it from the file */ - read_colormap(source, (int) biClrUsed, mapentrysize); - /* account for size of colormap */ - bPad -= biClrUsed * mapentrysize; - } - - /* Skip any remaining pad bytes */ - if (bPad < 0) /* incorrect bfOffBits value? */ - ERREXIT(cinfo, JERR_BMP_BADHEADER); - while (--bPad >= 0) { - (void) read_byte(source); - } - - /* Compute row width in file, including padding to 4-byte boundary */ - if (source->bits_per_pixel == 24) - row_width = (JDIMENSION) (biWidth * 3); - else if (source->bits_per_pixel == 32) - row_width = (JDIMENSION) (biWidth * 4); - else - row_width = (JDIMENSION) biWidth; - while ((row_width & 3) != 0) row_width++; - source->row_width = row_width; - - /* Allocate space for inversion array, prepare for preload pass */ - source->whole_image = (*cinfo->mem->request_virt_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, - row_width, (JDIMENSION) biHeight, (JDIMENSION) 1); - source->pub.get_pixel_rows = preload_image; - if (cinfo->progress != NULL) { - cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; - progress->total_extra_passes++; /* count file input as separate pass */ - } - - /* Allocate one-row buffer for returned data */ - source->pub.buffer = (*cinfo->mem->alloc_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, - (JDIMENSION) (biWidth * 3), (JDIMENSION) 1); - source->pub.buffer_height = 1; - - cinfo->in_color_space = JCS_RGB; - cinfo->input_components = 3; - cinfo->data_precision = 8; - cinfo->image_width = (JDIMENSION) biWidth; - cinfo->image_height = (JDIMENSION) biHeight; -} - - -/* - * Finish up at the end of the file. - */ - -METHODDEF(void) -finish_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - /* no work */ -} - - -/* - * The module selection routine for BMP format input. - */ - -GLOBAL(cjpeg_source_ptr) -jinit_read_bmp (j_compress_ptr cinfo) -{ - bmp_source_ptr source; - - /* Create module interface object */ - source = (bmp_source_ptr) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - SIZEOF(bmp_source_struct)); - source->cinfo = cinfo; /* make back link for subroutines */ - /* Fill in method ptrs, except get_pixel_rows which start_input sets */ - source->pub.start_input = start_input_bmp; - source->pub.finish_input = finish_input_bmp; - - return (cjpeg_source_ptr) source; -} - -#endif /* BMP_SUPPORTED */ +/* + * rdbmp.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * Modified 2009-2010 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to read input images in Microsoft "BMP" + * format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors). + * Currently, only 8-bit and 24-bit images are supported, not 1-bit or + * 4-bit (feeding such low-depth images into JPEG would be silly anyway). + * Also, we don't support RLE-compressed files. + * + * These routines may need modification for non-Unix environments or + * specialized applications. As they stand, they assume input from + * an ordinary stdio stream. They further assume that reading begins + * at the start of the file; start_input may need work if the + * user interface has already read some data (e.g., to determine that + * the file is indeed BMP format). + * + * This code contributed by James Arthur Boucher. + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + +#ifdef BMP_SUPPORTED + + +/* Macros to deal with unsigned chars as efficiently as compiler allows */ + +#ifdef HAVE_UNSIGNED_CHAR +typedef unsigned char U_CHAR; +#define UCH(x) ((int) (x)) +#else /* !HAVE_UNSIGNED_CHAR */ +#ifdef CHAR_IS_UNSIGNED +typedef char U_CHAR; +#define UCH(x) ((int) (x)) +#else +typedef char U_CHAR; +#define UCH(x) ((int) (x) & 0xFF) +#endif +#endif /* HAVE_UNSIGNED_CHAR */ + + +#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) + + +/* Private version of data source object */ + +typedef struct _bmp_source_struct * bmp_source_ptr; + +typedef struct _bmp_source_struct { + struct cjpeg_source_struct pub; /* public fields */ + + j_compress_ptr cinfo; /* back link saves passing separate parm */ + + JSAMPARRAY colormap; /* BMP colormap (converted to my format) */ + + jvirt_sarray_ptr whole_image; /* Needed to reverse row order */ + JDIMENSION source_row; /* Current source row number */ + JDIMENSION row_width; /* Physical width of scanlines in file */ + + int bits_per_pixel; /* remembers 8- or 24-bit format */ +} bmp_source_struct; + + +LOCAL(int) +read_byte (bmp_source_ptr sinfo) +/* Read next byte from BMP file */ +{ + register FILE *infile = sinfo->pub.input_file; + register int c; + + if ((c = getc(infile)) == EOF) + ERREXIT(sinfo->cinfo, JERR_INPUT_EOF); + return c; +} + + +LOCAL(void) +read_colormap (bmp_source_ptr sinfo, int cmaplen, int mapentrysize) +/* Read the colormap from a BMP file */ +{ + int i; + + switch (mapentrysize) { + case 3: + /* BGR format (occurs in OS/2 files) */ + for (i = 0; i < cmaplen; i++) { + sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo); + sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo); + sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo); + } + break; + case 4: + /* BGR0 format (occurs in MS Windows files) */ + for (i = 0; i < cmaplen; i++) { + sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo); + sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo); + sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo); + (void) read_byte(sinfo); + } + break; + default: + ERREXIT(sinfo->cinfo, JERR_BMP_BADCMAP); + break; + } +} + + +/* + * Read one row of pixels. + * The image has been read into the whole_image array, but is otherwise + * unprocessed. We must read it out in top-to-bottom row order, and if + * it is an 8-bit image, we must expand colormapped pixels to 24bit format. + */ + +METHODDEF(JDIMENSION) +get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +/* This version is for reading 8-bit colormap indexes */ +{ + bmp_source_ptr source = (bmp_source_ptr) sinfo; + register JSAMPARRAY colormap = source->colormap; + JSAMPARRAY image_ptr; + register int t; + register JSAMPROW inptr, outptr; + register JDIMENSION col; + + /* Fetch next row from virtual array */ + source->source_row--; + image_ptr = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, source->whole_image, + source->source_row, (JDIMENSION) 1, FALSE); + + /* Expand the colormap indexes to real data */ + inptr = image_ptr[0]; + outptr = source->pub.buffer[0]; + for (col = cinfo->image_width; col > 0; col--) { + t = GETJSAMPLE(*inptr++); + *outptr++ = colormap[0][t]; /* can omit GETJSAMPLE() safely */ + *outptr++ = colormap[1][t]; + *outptr++ = colormap[2][t]; + } + + return 1; +} + + +METHODDEF(JDIMENSION) +get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +/* This version is for reading 24-bit pixels */ +{ + bmp_source_ptr source = (bmp_source_ptr) sinfo; + JSAMPARRAY image_ptr; + register JSAMPROW inptr, outptr; + register JDIMENSION col; + + /* Fetch next row from virtual array */ + source->source_row--; + image_ptr = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, source->whole_image, + source->source_row, (JDIMENSION) 1, FALSE); + + /* Transfer data. Note source values are in BGR order + * (even though Microsoft's own documents say the opposite). + */ + inptr = image_ptr[0]; + outptr = source->pub.buffer[0]; + for (col = cinfo->image_width; col > 0; col--) { + outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ + outptr[1] = *inptr++; + outptr[0] = *inptr++; + outptr += 3; + } + + return 1; +} + + +METHODDEF(JDIMENSION) +get_32bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +/* This version is for reading 32-bit pixels */ +{ + bmp_source_ptr source = (bmp_source_ptr) sinfo; + JSAMPARRAY image_ptr; + register JSAMPROW inptr, outptr; + register JDIMENSION col; + + /* Fetch next row from virtual array */ + source->source_row--; + image_ptr = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, source->whole_image, + source->source_row, (JDIMENSION) 1, FALSE); + /* Transfer data. Note source values are in BGR order + * (even though Microsoft's own documents say the opposite). + */ + inptr = image_ptr[0]; + outptr = source->pub.buffer[0]; + for (col = cinfo->image_width; col > 0; col--) { + outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ + outptr[1] = *inptr++; + outptr[0] = *inptr++; + inptr++; /* skip the 4th byte (Alpha channel) */ + outptr += 3; + } + + return 1; +} + + +/* + * This method loads the image into whole_image during the first call on + * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call + * get_8bit_row, get_24bit_row, or get_32bit_row on subsequent calls. + */ + +METHODDEF(JDIMENSION) +preload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +{ + bmp_source_ptr source = (bmp_source_ptr) sinfo; + register FILE *infile = source->pub.input_file; + register int c; + register JSAMPROW out_ptr; + JSAMPARRAY image_ptr; + JDIMENSION row, col; + cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; + + /* Read the data into a virtual array in input-file row order. */ + for (row = 0; row < cinfo->image_height; row++) { + if (progress != NULL) { + progress->pub.pass_counter = (long) row; + progress->pub.pass_limit = (long) cinfo->image_height; + (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); + } + image_ptr = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, source->whole_image, + row, (JDIMENSION) 1, TRUE); + out_ptr = image_ptr[0]; + for (col = source->row_width; col > 0; col--) { + /* inline copy of read_byte() for speed */ + if ((c = getc(infile)) == EOF) + ERREXIT(cinfo, JERR_INPUT_EOF); + *out_ptr++ = (JSAMPLE) c; + } + } + if (progress != NULL) + progress->completed_extra_passes++; + + /* Set up to read from the virtual array in top-to-bottom order */ + switch (source->bits_per_pixel) { + case 8: + source->pub.get_pixel_rows = get_8bit_row; + break; + case 24: + source->pub.get_pixel_rows = get_24bit_row; + break; + case 32: + source->pub.get_pixel_rows = get_32bit_row; + break; + default: + ERREXIT(cinfo, JERR_BMP_BADDEPTH); + } + source->source_row = cinfo->image_height; + + /* And read the first row */ + return (*source->pub.get_pixel_rows) (cinfo, sinfo); +} + + +/* + * Read the file header; return image size and component count. + */ + +METHODDEF(void) +start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +{ + bmp_source_ptr source = (bmp_source_ptr) sinfo; + U_CHAR bmpfileheader[14]; + U_CHAR bmpinfoheader[64]; +#define GET_2B(array,offset) ((unsigned int) UCH(array[offset]) + \ + (((unsigned int) UCH(array[offset+1])) << 8)) +#define GET_4B(array,offset) ((INT32) UCH(array[offset]) + \ + (((INT32) UCH(array[offset+1])) << 8) + \ + (((INT32) UCH(array[offset+2])) << 16) + \ + (((INT32) UCH(array[offset+3])) << 24)) + INT32 bfOffBits; + INT32 headerSize; + INT32 biWidth; + INT32 biHeight; + unsigned int biPlanes; + INT32 biCompression; + INT32 biXPelsPerMeter,biYPelsPerMeter; + INT32 biClrUsed = 0; + int mapentrysize = 0; /* 0 indicates no colormap */ + INT32 bPad; + JDIMENSION row_width; + + /* Read and verify the bitmap file header */ + if (! ReadOK(source->pub.input_file, bmpfileheader, 14)) + ERREXIT(cinfo, JERR_INPUT_EOF); + if (GET_2B(bmpfileheader,0) != 0x4D42) /* 'BM' */ + ERREXIT(cinfo, JERR_BMP_NOT); + bfOffBits = (INT32) GET_4B(bmpfileheader,10); + /* We ignore the remaining fileheader fields */ + + /* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows), + * or 64 bytes (OS/2 2.x). Check the first 4 bytes to find out which. + */ + if (! ReadOK(source->pub.input_file, bmpinfoheader, 4)) + ERREXIT(cinfo, JERR_INPUT_EOF); + headerSize = (INT32) GET_4B(bmpinfoheader,0); + if (headerSize < 12 || headerSize > 64) + ERREXIT(cinfo, JERR_BMP_BADHEADER); + if (! ReadOK(source->pub.input_file, bmpinfoheader+4, headerSize-4)) + ERREXIT(cinfo, JERR_INPUT_EOF); + + switch ((int) headerSize) { + case 12: + /* Decode OS/2 1.x header (Microsoft calls this a BITMAPCOREHEADER) */ + biWidth = (INT32) GET_2B(bmpinfoheader,4); + biHeight = (INT32) GET_2B(bmpinfoheader,6); + biPlanes = GET_2B(bmpinfoheader,8); + source->bits_per_pixel = (int) GET_2B(bmpinfoheader,10); + + switch (source->bits_per_pixel) { + case 8: /* colormapped image */ + mapentrysize = 3; /* OS/2 uses RGBTRIPLE colormap */ + TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (int) biWidth, (int) biHeight); + break; + case 24: /* RGB image */ + TRACEMS2(cinfo, 1, JTRC_BMP_OS2, (int) biWidth, (int) biHeight); + break; + default: + ERREXIT(cinfo, JERR_BMP_BADDEPTH); + break; + } + break; + case 40: + case 64: + /* Decode Windows 3.x header (Microsoft calls this a BITMAPINFOHEADER) */ + /* or OS/2 2.x header, which has additional fields that we ignore */ + biWidth = GET_4B(bmpinfoheader,4); + biHeight = GET_4B(bmpinfoheader,8); + biPlanes = GET_2B(bmpinfoheader,12); + source->bits_per_pixel = (int) GET_2B(bmpinfoheader,14); + biCompression = GET_4B(bmpinfoheader,16); + biXPelsPerMeter = GET_4B(bmpinfoheader,24); + biYPelsPerMeter = GET_4B(bmpinfoheader,28); + biClrUsed = GET_4B(bmpinfoheader,32); + /* biSizeImage, biClrImportant fields are ignored */ + + switch (source->bits_per_pixel) { + case 8: /* colormapped image */ + mapentrysize = 4; /* Windows uses RGBQUAD colormap */ + TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (int) biWidth, (int) biHeight); + break; + case 24: /* RGB image */ + TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight); + break; + case 32: /* RGB image + Alpha channel */ + TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight); + break; + default: + ERREXIT(cinfo, JERR_BMP_BADDEPTH); + break; + } + if (biCompression != 0) + ERREXIT(cinfo, JERR_BMP_COMPRESSED); + + if (biXPelsPerMeter > 0 && biYPelsPerMeter > 0) { + /* Set JFIF density parameters from the BMP data */ + cinfo->X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */ + cinfo->Y_density = (UINT16) (biYPelsPerMeter/100); + cinfo->density_unit = 2; /* dots/cm */ + } + break; + default: + ERREXIT(cinfo, JERR_BMP_BADHEADER); + return; + } + + if (biWidth <= 0 || biHeight <= 0) + ERREXIT(cinfo, JERR_BMP_EMPTY); + if (biPlanes != 1) + ERREXIT(cinfo, JERR_BMP_BADPLANES); + + /* Compute distance to bitmap data --- will adjust for colormap below */ + bPad = bfOffBits - (headerSize + 14); + + /* Read the colormap, if any */ + if (mapentrysize > 0) { + if (biClrUsed <= 0) + biClrUsed = 256; /* assume it's 256 */ + else if (biClrUsed > 256) + ERREXIT(cinfo, JERR_BMP_BADCMAP); + /* Allocate space to store the colormap */ + source->colormap = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) biClrUsed, (JDIMENSION) 3); + /* and read it from the file */ + read_colormap(source, (int) biClrUsed, mapentrysize); + /* account for size of colormap */ + bPad -= biClrUsed * mapentrysize; + } + + /* Skip any remaining pad bytes */ + if (bPad < 0) /* incorrect bfOffBits value? */ + ERREXIT(cinfo, JERR_BMP_BADHEADER); + while (--bPad >= 0) { + (void) read_byte(source); + } + + /* Compute row width in file, including padding to 4-byte boundary */ + if (source->bits_per_pixel == 24) + row_width = (JDIMENSION) (biWidth * 3); + else if (source->bits_per_pixel == 32) + row_width = (JDIMENSION) (biWidth * 4); + else + row_width = (JDIMENSION) biWidth; + while ((row_width & 3) != 0) row_width++; + source->row_width = row_width; + + /* Allocate space for inversion array, prepare for preload pass */ + source->whole_image = (*cinfo->mem->request_virt_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, + row_width, (JDIMENSION) biHeight, (JDIMENSION) 1); + source->pub.get_pixel_rows = preload_image; + if (cinfo->progress != NULL) { + cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; + progress->total_extra_passes++; /* count file input as separate pass */ + } + + /* Allocate one-row buffer for returned data */ + source->pub.buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) (biWidth * 3), (JDIMENSION) 1); + source->pub.buffer_height = 1; + + cinfo->in_color_space = JCS_RGB; + cinfo->input_components = 3; + cinfo->data_precision = 8; + cinfo->image_width = (JDIMENSION) biWidth; + cinfo->image_height = (JDIMENSION) biHeight; +} + + +/* + * Finish up at the end of the file. + */ + +METHODDEF(void) +finish_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +{ + /* no work */ +} + + +/* + * The module selection routine for BMP format input. + */ + +GLOBAL(cjpeg_source_ptr) +jinit_read_bmp (j_compress_ptr cinfo) +{ + bmp_source_ptr source; + + /* Create module interface object */ + source = (bmp_source_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(bmp_source_struct)); + source->cinfo = cinfo; /* make back link for subroutines */ + /* Fill in method ptrs, except get_pixel_rows which start_input sets */ + source->pub.start_input = start_input_bmp; + source->pub.finish_input = finish_input_bmp; + + return (cjpeg_source_ptr) source; +} + +#endif /* BMP_SUPPORTED */ diff --git a/Source/LibJPEG/rdcolmap.c b/Source/LibJPEG/rdcolmap.c index eebf834..42b3437 100644 --- a/Source/LibJPEG/rdcolmap.c +++ b/Source/LibJPEG/rdcolmap.c @@ -1,253 +1,253 @@ -/* - * rdcolmap.c - * - * Copyright (C) 1994-1996, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file implements djpeg's "-map file" switch. It reads a source image - * and constructs a colormap to be supplied to the JPEG decompressor. - * - * Currently, these file formats are supported for the map file: - * GIF: the contents of the GIF's global colormap are used. - * PPM (either text or raw flavor): the entire file is read and - * each unique pixel value is entered in the map. - * Note that reading a large PPM file will be horrendously slow. - * Typically, a PPM-format map file should contain just one pixel - * of each desired color. Such a file can be extracted from an - * ordinary image PPM file with ppmtomap(1). - * - * Rescaling a PPM that has a maxval unequal to MAXJSAMPLE is not - * currently implemented. - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ - -#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ - -/* Portions of this code are based on the PBMPLUS library, which is: -** -** Copyright (C) 1988 by Jef Poskanzer. -** -** Permission to use, copy, modify, and distribute this software and its -** documentation for any purpose and without fee is hereby granted, provided -** that the above copyright notice appear in all copies and that both that -** copyright notice and this permission notice appear in supporting -** documentation. This software is provided "as is" without express or -** implied warranty. -*/ - - -/* - * Add a (potentially) new color to the color map. - */ - -LOCAL(void) -add_map_entry (j_decompress_ptr cinfo, int R, int G, int B) -{ - JSAMPROW colormap0 = cinfo->colormap[0]; - JSAMPROW colormap1 = cinfo->colormap[1]; - JSAMPROW colormap2 = cinfo->colormap[2]; - int ncolors = cinfo->actual_number_of_colors; - int index; - - /* Check for duplicate color. */ - for (index = 0; index < ncolors; index++) { - if (GETJSAMPLE(colormap0[index]) == R && - GETJSAMPLE(colormap1[index]) == G && - GETJSAMPLE(colormap2[index]) == B) - return; /* color is already in map */ - } - - /* Check for map overflow. */ - if (ncolors >= (MAXJSAMPLE+1)) - ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (MAXJSAMPLE+1)); - - /* OK, add color to map. */ - colormap0[ncolors] = (JSAMPLE) R; - colormap1[ncolors] = (JSAMPLE) G; - colormap2[ncolors] = (JSAMPLE) B; - cinfo->actual_number_of_colors++; -} - - -/* - * Extract color map from a GIF file. - */ - -LOCAL(void) -read_gif_map (j_decompress_ptr cinfo, FILE * infile) -{ - int header[13]; - int i, colormaplen; - int R, G, B; - - /* Initial 'G' has already been read by read_color_map */ - /* Read the rest of the GIF header and logical screen descriptor */ - for (i = 1; i < 13; i++) { - if ((header[i] = getc(infile)) == EOF) - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - } - - /* Verify GIF Header */ - if (header[1] != 'I' || header[2] != 'F') - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - - /* There must be a global color map. */ - if ((header[10] & 0x80) == 0) - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - - /* OK, fetch it. */ - colormaplen = 2 << (header[10] & 0x07); - - for (i = 0; i < colormaplen; i++) { - R = getc(infile); - G = getc(infile); - B = getc(infile); - if (R == EOF || G == EOF || B == EOF) - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - add_map_entry(cinfo, - R << (BITS_IN_JSAMPLE-8), - G << (BITS_IN_JSAMPLE-8), - B << (BITS_IN_JSAMPLE-8)); - } -} - - -/* Support routines for reading PPM */ - - -LOCAL(int) -pbm_getc (FILE * infile) -/* Read next char, skipping over any comments */ -/* A comment/newline sequence is returned as a newline */ -{ - register int ch; - - ch = getc(infile); - if (ch == '#') { - do { - ch = getc(infile); - } while (ch != '\n' && ch != EOF); - } - return ch; -} - - -LOCAL(unsigned int) -read_pbm_integer (j_decompress_ptr cinfo, FILE * infile) -/* Read an unsigned decimal integer from the PPM file */ -/* Swallows one trailing character after the integer */ -/* Note that on a 16-bit-int machine, only values up to 64k can be read. */ -/* This should not be a problem in practice. */ -{ - register int ch; - register unsigned int val; - - /* Skip any leading whitespace */ - do { - ch = pbm_getc(infile); - if (ch == EOF) - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); - - if (ch < '0' || ch > '9') - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - - val = ch - '0'; - while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { - val *= 10; - val += ch - '0'; - } - return val; -} - - -/* - * Extract color map from a PPM file. - */ - -LOCAL(void) -read_ppm_map (j_decompress_ptr cinfo, FILE * infile) -{ - int c; - unsigned int w, h, maxval, row, col; - int R, G, B; - - /* Initial 'P' has already been read by read_color_map */ - c = getc(infile); /* save format discriminator for a sec */ - - /* while we fetch the remaining header info */ - w = read_pbm_integer(cinfo, infile); - h = read_pbm_integer(cinfo, infile); - maxval = read_pbm_integer(cinfo, infile); - - if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - - /* For now, we don't support rescaling from an unusual maxval. */ - if (maxval != (unsigned int) MAXJSAMPLE) - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - - switch (c) { - case '3': /* it's a text-format PPM file */ - for (row = 0; row < h; row++) { - for (col = 0; col < w; col++) { - R = read_pbm_integer(cinfo, infile); - G = read_pbm_integer(cinfo, infile); - B = read_pbm_integer(cinfo, infile); - add_map_entry(cinfo, R, G, B); - } - } - break; - - case '6': /* it's a raw-format PPM file */ - for (row = 0; row < h; row++) { - for (col = 0; col < w; col++) { - R = getc(infile); - G = getc(infile); - B = getc(infile); - if (R == EOF || G == EOF || B == EOF) - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - add_map_entry(cinfo, R, G, B); - } - } - break; - - default: - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - break; - } -} - - -/* - * Main entry point from djpeg.c. - * Input: opened input file (from file name argument on command line). - * Output: colormap and actual_number_of_colors fields are set in cinfo. - */ - -GLOBAL(void) -read_color_map (j_decompress_ptr cinfo, FILE * infile) -{ - /* Allocate space for a color map of maximum supported size. */ - cinfo->colormap = (*cinfo->mem->alloc_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, - (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3); - cinfo->actual_number_of_colors = 0; /* initialize map to empty */ - - /* Read first byte to determine file format */ - switch (getc(infile)) { - case 'G': - read_gif_map(cinfo, infile); - break; - case 'P': - read_ppm_map(cinfo, infile); - break; - default: - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - break; - } -} - -#endif /* QUANT_2PASS_SUPPORTED */ +/* + * rdcolmap.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file implements djpeg's "-map file" switch. It reads a source image + * and constructs a colormap to be supplied to the JPEG decompressor. + * + * Currently, these file formats are supported for the map file: + * GIF: the contents of the GIF's global colormap are used. + * PPM (either text or raw flavor): the entire file is read and + * each unique pixel value is entered in the map. + * Note that reading a large PPM file will be horrendously slow. + * Typically, a PPM-format map file should contain just one pixel + * of each desired color. Such a file can be extracted from an + * ordinary image PPM file with ppmtomap(1). + * + * Rescaling a PPM that has a maxval unequal to MAXJSAMPLE is not + * currently implemented. + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + +#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ + +/* Portions of this code are based on the PBMPLUS library, which is: +** +** Copyright (C) 1988 by Jef Poskanzer. +** +** Permission to use, copy, modify, and distribute this software and its +** documentation for any purpose and without fee is hereby granted, provided +** that the above copyright notice appear in all copies and that both that +** copyright notice and this permission notice appear in supporting +** documentation. This software is provided "as is" without express or +** implied warranty. +*/ + + +/* + * Add a (potentially) new color to the color map. + */ + +LOCAL(void) +add_map_entry (j_decompress_ptr cinfo, int R, int G, int B) +{ + JSAMPROW colormap0 = cinfo->colormap[0]; + JSAMPROW colormap1 = cinfo->colormap[1]; + JSAMPROW colormap2 = cinfo->colormap[2]; + int ncolors = cinfo->actual_number_of_colors; + int index; + + /* Check for duplicate color. */ + for (index = 0; index < ncolors; index++) { + if (GETJSAMPLE(colormap0[index]) == R && + GETJSAMPLE(colormap1[index]) == G && + GETJSAMPLE(colormap2[index]) == B) + return; /* color is already in map */ + } + + /* Check for map overflow. */ + if (ncolors >= (MAXJSAMPLE+1)) + ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (MAXJSAMPLE+1)); + + /* OK, add color to map. */ + colormap0[ncolors] = (JSAMPLE) R; + colormap1[ncolors] = (JSAMPLE) G; + colormap2[ncolors] = (JSAMPLE) B; + cinfo->actual_number_of_colors++; +} + + +/* + * Extract color map from a GIF file. + */ + +LOCAL(void) +read_gif_map (j_decompress_ptr cinfo, FILE * infile) +{ + int header[13]; + int i, colormaplen; + int R, G, B; + + /* Initial 'G' has already been read by read_color_map */ + /* Read the rest of the GIF header and logical screen descriptor */ + for (i = 1; i < 13; i++) { + if ((header[i] = getc(infile)) == EOF) + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + } + + /* Verify GIF Header */ + if (header[1] != 'I' || header[2] != 'F') + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + + /* There must be a global color map. */ + if ((header[10] & 0x80) == 0) + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + + /* OK, fetch it. */ + colormaplen = 2 << (header[10] & 0x07); + + for (i = 0; i < colormaplen; i++) { + R = getc(infile); + G = getc(infile); + B = getc(infile); + if (R == EOF || G == EOF || B == EOF) + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + add_map_entry(cinfo, + R << (BITS_IN_JSAMPLE-8), + G << (BITS_IN_JSAMPLE-8), + B << (BITS_IN_JSAMPLE-8)); + } +} + + +/* Support routines for reading PPM */ + + +LOCAL(int) +pbm_getc (FILE * infile) +/* Read next char, skipping over any comments */ +/* A comment/newline sequence is returned as a newline */ +{ + register int ch; + + ch = getc(infile); + if (ch == '#') { + do { + ch = getc(infile); + } while (ch != '\n' && ch != EOF); + } + return ch; +} + + +LOCAL(unsigned int) +read_pbm_integer (j_decompress_ptr cinfo, FILE * infile) +/* Read an unsigned decimal integer from the PPM file */ +/* Swallows one trailing character after the integer */ +/* Note that on a 16-bit-int machine, only values up to 64k can be read. */ +/* This should not be a problem in practice. */ +{ + register int ch; + register unsigned int val; + + /* Skip any leading whitespace */ + do { + ch = pbm_getc(infile); + if (ch == EOF) + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); + + if (ch < '0' || ch > '9') + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + + val = ch - '0'; + while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { + val *= 10; + val += ch - '0'; + } + return val; +} + + +/* + * Extract color map from a PPM file. + */ + +LOCAL(void) +read_ppm_map (j_decompress_ptr cinfo, FILE * infile) +{ + int c; + unsigned int w, h, maxval, row, col; + int R, G, B; + + /* Initial 'P' has already been read by read_color_map */ + c = getc(infile); /* save format discriminator for a sec */ + + /* while we fetch the remaining header info */ + w = read_pbm_integer(cinfo, infile); + h = read_pbm_integer(cinfo, infile); + maxval = read_pbm_integer(cinfo, infile); + + if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + + /* For now, we don't support rescaling from an unusual maxval. */ + if (maxval != (unsigned int) MAXJSAMPLE) + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + + switch (c) { + case '3': /* it's a text-format PPM file */ + for (row = 0; row < h; row++) { + for (col = 0; col < w; col++) { + R = read_pbm_integer(cinfo, infile); + G = read_pbm_integer(cinfo, infile); + B = read_pbm_integer(cinfo, infile); + add_map_entry(cinfo, R, G, B); + } + } + break; + + case '6': /* it's a raw-format PPM file */ + for (row = 0; row < h; row++) { + for (col = 0; col < w; col++) { + R = getc(infile); + G = getc(infile); + B = getc(infile); + if (R == EOF || G == EOF || B == EOF) + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + add_map_entry(cinfo, R, G, B); + } + } + break; + + default: + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + break; + } +} + + +/* + * Main entry point from djpeg.c. + * Input: opened input file (from file name argument on command line). + * Output: colormap and actual_number_of_colors fields are set in cinfo. + */ + +GLOBAL(void) +read_color_map (j_decompress_ptr cinfo, FILE * infile) +{ + /* Allocate space for a color map of maximum supported size. */ + cinfo->colormap = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3); + cinfo->actual_number_of_colors = 0; /* initialize map to empty */ + + /* Read first byte to determine file format */ + switch (getc(infile)) { + case 'G': + read_gif_map(cinfo, infile); + break; + case 'P': + read_ppm_map(cinfo, infile); + break; + default: + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + break; + } +} + +#endif /* QUANT_2PASS_SUPPORTED */ diff --git a/Source/LibJPEG/rdgif.c b/Source/LibJPEG/rdgif.c index b0757e7..b27c167 100644 --- a/Source/LibJPEG/rdgif.c +++ b/Source/LibJPEG/rdgif.c @@ -1,38 +1,38 @@ -/* - * rdgif.c - * - * Copyright (C) 1991-1997, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains routines to read input images in GIF format. - * - ***************************************************************************** - * NOTE: to avoid entanglements with Unisys' patent on LZW compression, * - * the ability to read GIF files has been removed from the IJG distribution. * - * Sorry about that. * - ***************************************************************************** - * - * We are required to state that - * "The Graphics Interchange Format(c) is the Copyright property of - * CompuServe Incorporated. GIF(sm) is a Service Mark property of - * CompuServe Incorporated." - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ - -#ifdef GIF_SUPPORTED - -/* - * The module selection routine for GIF format input. - */ - -GLOBAL(cjpeg_source_ptr) -jinit_read_gif (j_compress_ptr cinfo) -{ - fprintf(stderr, "GIF input is unsupported for legal reasons. Sorry.\n"); - exit(EXIT_FAILURE); - return NULL; /* keep compiler happy */ -} - -#endif /* GIF_SUPPORTED */ +/* + * rdgif.c + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to read input images in GIF format. + * + ***************************************************************************** + * NOTE: to avoid entanglements with Unisys' patent on LZW compression, * + * the ability to read GIF files has been removed from the IJG distribution. * + * Sorry about that. * + ***************************************************************************** + * + * We are required to state that + * "The Graphics Interchange Format(c) is the Copyright property of + * CompuServe Incorporated. GIF(sm) is a Service Mark property of + * CompuServe Incorporated." + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + +#ifdef GIF_SUPPORTED + +/* + * The module selection routine for GIF format input. + */ + +GLOBAL(cjpeg_source_ptr) +jinit_read_gif (j_compress_ptr cinfo) +{ + fprintf(stderr, "GIF input is unsupported for legal reasons. Sorry.\n"); + exit(EXIT_FAILURE); + return NULL; /* keep compiler happy */ +} + +#endif /* GIF_SUPPORTED */ diff --git a/Source/LibJPEG/rdjpgcom.c b/Source/LibJPEG/rdjpgcom.c index ab09b44..3719154 100644 --- a/Source/LibJPEG/rdjpgcom.c +++ b/Source/LibJPEG/rdjpgcom.c @@ -1,515 +1,515 @@ -/* - * rdjpgcom.c - * - * Copyright (C) 1994-1997, Thomas G. Lane. - * Modified 2009 by Bill Allombert, Guido Vollbeding. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains a very simple stand-alone application that displays - * the text in COM (comment) markers in a JFIF file. - * This may be useful as an example of the minimum logic needed to parse - * JPEG markers. - */ - -#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */ -#include "jinclude.h" /* get auto-config symbols, */ - -#ifdef HAVE_LOCALE_H -#include /* Bill Allombert: use locale for isprint */ -#endif -#include /* to declare isupper(), tolower() */ -#ifdef USE_SETMODE -#include /* to declare setmode()'s parameter macros */ -/* If you have setmode() but not , just delete this line: */ -#include /* to declare setmode() */ -#endif - -#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ -#ifdef __MWERKS__ -#include /* Metrowerks needs this */ -#include /* ... and this */ -#endif -#ifdef THINK_C -#include /* Think declares it here */ -#endif -#endif - -#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ -#define READ_BINARY "r" -#else -#ifdef VMS /* VMS is very nonstandard */ -#define READ_BINARY "rb", "ctx=stm" -#else /* standard ANSI-compliant case */ -#define READ_BINARY "rb" -#endif -#endif - -#ifndef EXIT_FAILURE /* define exit() codes if not provided */ -#define EXIT_FAILURE 1 -#endif -#ifndef EXIT_SUCCESS -#ifdef VMS -#define EXIT_SUCCESS 1 /* VMS is very nonstandard */ -#else -#define EXIT_SUCCESS 0 -#endif -#endif - - -/* - * These macros are used to read the input file. - * To reuse this code in another application, you might need to change these. - */ - -static FILE * infile; /* input JPEG file */ - -/* Return next input byte, or EOF if no more */ -#define NEXTBYTE() getc(infile) - - -/* Error exit handler */ -#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE)) - - -/* Read one byte, testing for EOF */ -static int -read_1_byte (void) -{ - int c; - - c = NEXTBYTE(); - if (c == EOF) - ERREXIT("Premature EOF in JPEG file"); - return c; -} - -/* Read 2 bytes, convert to unsigned int */ -/* All 2-byte quantities in JPEG markers are MSB first */ -static unsigned int -read_2_bytes (void) -{ - int c1, c2; - - c1 = NEXTBYTE(); - if (c1 == EOF) - ERREXIT("Premature EOF in JPEG file"); - c2 = NEXTBYTE(); - if (c2 == EOF) - ERREXIT("Premature EOF in JPEG file"); - return (((unsigned int) c1) << 8) + ((unsigned int) c2); -} - - -/* - * JPEG markers consist of one or more 0xFF bytes, followed by a marker - * code byte (which is not an FF). Here are the marker codes of interest - * in this program. (See jdmarker.c for a more complete list.) - */ - -#define M_SOF0 0xC0 /* Start Of Frame N */ -#define M_SOF1 0xC1 /* N indicates which compression process */ -#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */ -#define M_SOF3 0xC3 -#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */ -#define M_SOF6 0xC6 -#define M_SOF7 0xC7 -#define M_SOF9 0xC9 -#define M_SOF10 0xCA -#define M_SOF11 0xCB -#define M_SOF13 0xCD -#define M_SOF14 0xCE -#define M_SOF15 0xCF -#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */ -#define M_EOI 0xD9 /* End Of Image (end of datastream) */ -#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ -#define M_APP0 0xE0 /* Application-specific marker, type N */ -#define M_APP12 0xEC /* (we don't bother to list all 16 APPn's) */ -#define M_COM 0xFE /* COMment */ - - -/* - * Find the next JPEG marker and return its marker code. - * We expect at least one FF byte, possibly more if the compressor used FFs - * to pad the file. - * There could also be non-FF garbage between markers. The treatment of such - * garbage is unspecified; we choose to skip over it but emit a warning msg. - * NB: this routine must not be used after seeing SOS marker, since it will - * not deal correctly with FF/00 sequences in the compressed image data... - */ - -static int -next_marker (void) -{ - int c; - int discarded_bytes = 0; - - /* Find 0xFF byte; count and skip any non-FFs. */ - c = read_1_byte(); - while (c != 0xFF) { - discarded_bytes++; - c = read_1_byte(); - } - /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs - * are legal as pad bytes, so don't count them in discarded_bytes. - */ - do { - c = read_1_byte(); - } while (c == 0xFF); - - if (discarded_bytes != 0) { - fprintf(stderr, "Warning: garbage data found in JPEG file\n"); - } - - return c; -} - - -/* - * Read the initial marker, which should be SOI. - * For a JFIF file, the first two bytes of the file should be literally - * 0xFF M_SOI. To be more general, we could use next_marker, but if the - * input file weren't actually JPEG at all, next_marker might read the whole - * file and then return a misleading error message... - */ - -static int -first_marker (void) -{ - int c1, c2; - - c1 = NEXTBYTE(); - c2 = NEXTBYTE(); - if (c1 != 0xFF || c2 != M_SOI) - ERREXIT("Not a JPEG file"); - return c2; -} - - -/* - * Most types of marker are followed by a variable-length parameter segment. - * This routine skips over the parameters for any marker we don't otherwise - * want to process. - * Note that we MUST skip the parameter segment explicitly in order not to - * be fooled by 0xFF bytes that might appear within the parameter segment; - * such bytes do NOT introduce new markers. - */ - -static void -skip_variable (void) -/* Skip over an unknown or uninteresting variable-length marker */ -{ - unsigned int length; - - /* Get the marker parameter length count */ - length = read_2_bytes(); - /* Length includes itself, so must be at least 2 */ - if (length < 2) - ERREXIT("Erroneous JPEG marker length"); - length -= 2; - /* Skip over the remaining bytes */ - while (length > 0) { - (void) read_1_byte(); - length--; - } -} - - -/* - * Process a COM marker. - * We want to print out the marker contents as legible text; - * we must guard against non-text junk and varying newline representations. - */ - -static void -process_COM (int raw) -{ - unsigned int length; - int ch; - int lastch = 0; - - /* Bill Allombert: set locale properly for isprint */ -#ifdef HAVE_LOCALE_H - setlocale(LC_CTYPE, ""); -#endif - - /* Get the marker parameter length count */ - length = read_2_bytes(); - /* Length includes itself, so must be at least 2 */ - if (length < 2) - ERREXIT("Erroneous JPEG marker length"); - length -= 2; - - while (length > 0) { - ch = read_1_byte(); - if (raw) { - putc(ch, stdout); - /* Emit the character in a readable form. - * Nonprintables are converted to \nnn form, - * while \ is converted to \\. - * Newlines in CR, CR/LF, or LF form will be printed as one newline. - */ - } else if (ch == '\r') { - printf("\n"); - } else if (ch == '\n') { - if (lastch != '\r') - printf("\n"); - } else if (ch == '\\') { - printf("\\\\"); - } else if (isprint(ch)) { - putc(ch, stdout); - } else { - printf("\\%03o", ch); - } - lastch = ch; - length--; - } - printf("\n"); - - /* Bill Allombert: revert to C locale */ -#ifdef HAVE_LOCALE_H - setlocale(LC_CTYPE, "C"); -#endif -} - - -/* - * Process a SOFn marker. - * This code is only needed if you want to know the image dimensions... - */ - -static void -process_SOFn (int marker) -{ - unsigned int length; - unsigned int image_height, image_width; - int data_precision, num_components; - const char * process; - int ci; - - length = read_2_bytes(); /* usual parameter length count */ - - data_precision = read_1_byte(); - image_height = read_2_bytes(); - image_width = read_2_bytes(); - num_components = read_1_byte(); - - switch (marker) { - case M_SOF0: process = "Baseline"; break; - case M_SOF1: process = "Extended sequential"; break; - case M_SOF2: process = "Progressive"; break; - case M_SOF3: process = "Lossless"; break; - case M_SOF5: process = "Differential sequential"; break; - case M_SOF6: process = "Differential progressive"; break; - case M_SOF7: process = "Differential lossless"; break; - case M_SOF9: process = "Extended sequential, arithmetic coding"; break; - case M_SOF10: process = "Progressive, arithmetic coding"; break; - case M_SOF11: process = "Lossless, arithmetic coding"; break; - case M_SOF13: process = "Differential sequential, arithmetic coding"; break; - case M_SOF14: process = "Differential progressive, arithmetic coding"; break; - case M_SOF15: process = "Differential lossless, arithmetic coding"; break; - default: process = "Unknown"; break; - } - - printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n", - image_width, image_height, num_components, data_precision); - printf("JPEG process: %s\n", process); - - if (length != (unsigned int) (8 + num_components * 3)) - ERREXIT("Bogus SOF marker length"); - - for (ci = 0; ci < num_components; ci++) { - (void) read_1_byte(); /* Component ID code */ - (void) read_1_byte(); /* H, V sampling factors */ - (void) read_1_byte(); /* Quantization table number */ - } -} - - -/* - * Parse the marker stream until SOS or EOI is seen; - * display any COM markers. - * While the companion program wrjpgcom will always insert COM markers before - * SOFn, other implementations might not, so we scan to SOS before stopping. - * If we were only interested in the image dimensions, we would stop at SOFn. - * (Conversely, if we only cared about COM markers, there would be no need - * for special code to handle SOFn; we could treat it like other markers.) - */ - -static int -scan_JPEG_header (int verbose, int raw) -{ - int marker; - - /* Expect SOI at start of file */ - if (first_marker() != M_SOI) - ERREXIT("Expected SOI marker first"); - - /* Scan miscellaneous markers until we reach SOS. */ - for (;;) { - marker = next_marker(); - switch (marker) { - /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be, - * treated as SOFn. C4 in particular is actually DHT. - */ - case M_SOF0: /* Baseline */ - case M_SOF1: /* Extended sequential, Huffman */ - case M_SOF2: /* Progressive, Huffman */ - case M_SOF3: /* Lossless, Huffman */ - case M_SOF5: /* Differential sequential, Huffman */ - case M_SOF6: /* Differential progressive, Huffman */ - case M_SOF7: /* Differential lossless, Huffman */ - case M_SOF9: /* Extended sequential, arithmetic */ - case M_SOF10: /* Progressive, arithmetic */ - case M_SOF11: /* Lossless, arithmetic */ - case M_SOF13: /* Differential sequential, arithmetic */ - case M_SOF14: /* Differential progressive, arithmetic */ - case M_SOF15: /* Differential lossless, arithmetic */ - if (verbose) - process_SOFn(marker); - else - skip_variable(); - break; - - case M_SOS: /* stop before hitting compressed data */ - return marker; - - case M_EOI: /* in case it's a tables-only JPEG stream */ - return marker; - - case M_COM: - process_COM(raw); - break; - - case M_APP12: - /* Some digital camera makers put useful textual information into - * APP12 markers, so we print those out too when in -verbose mode. - */ - if (verbose) { - printf("APP12 contains:\n"); - process_COM(raw); - } else - skip_variable(); - break; - - default: /* Anything else just gets skipped */ - skip_variable(); /* we assume it has a parameter count... */ - break; - } - } /* end loop */ -} - - -/* Command line parsing code */ - -static const char * progname; /* program name for error messages */ - - -static void -usage (void) -/* complain about bad command line */ -{ - fprintf(stderr, "rdjpgcom displays any textual comments in a JPEG file.\n"); - - fprintf(stderr, "Usage: %s [switches] [inputfile]\n", progname); - - fprintf(stderr, "Switches (names may be abbreviated):\n"); - fprintf(stderr, " -raw Display non-printable characters in comments (unsafe)\n"); - fprintf(stderr, " -verbose Also display dimensions of JPEG image\n"); - - exit(EXIT_FAILURE); -} - - -static int -keymatch (char * arg, const char * keyword, int minchars) -/* Case-insensitive matching of (possibly abbreviated) keyword switches. */ -/* keyword is the constant keyword (must be lower case already), */ -/* minchars is length of minimum legal abbreviation. */ -{ - register int ca, ck; - register int nmatched = 0; - - while ((ca = *arg++) != '\0') { - if ((ck = *keyword++) == '\0') - return 0; /* arg longer than keyword, no good */ - if (isupper(ca)) /* force arg to lcase (assume ck is already) */ - ca = tolower(ca); - if (ca != ck) - return 0; /* no good */ - nmatched++; /* count matched characters */ - } - /* reached end of argument; fail if it's too short for unique abbrev */ - if (nmatched < minchars) - return 0; - return 1; /* A-OK */ -} - - -/* - * The main program. - */ - -int -main (int argc, char **argv) -{ - int argn; - char * arg; - int verbose = 0, raw = 0; - - /* On Mac, fetch a command line. */ -#ifdef USE_CCOMMAND - argc = ccommand(&argv); -#endif - - progname = argv[0]; - if (progname == NULL || progname[0] == 0) - progname = "rdjpgcom"; /* in case C library doesn't provide it */ - - /* Parse switches, if any */ - for (argn = 1; argn < argc; argn++) { - arg = argv[argn]; - if (arg[0] != '-') - break; /* not switch, must be file name */ - arg++; /* advance over '-' */ - if (keymatch(arg, "verbose", 1)) { - verbose++; - } else if (keymatch(arg, "raw", 1)) { - raw = 1; - } else - usage(); - } - - /* Open the input file. */ - /* Unix style: expect zero or one file name */ - if (argn < argc-1) { - fprintf(stderr, "%s: only one input file\n", progname); - usage(); - } - if (argn < argc) { - if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); - exit(EXIT_FAILURE); - } - } else { - /* default input file is stdin */ -#ifdef USE_SETMODE /* need to hack file mode? */ - setmode(fileno(stdin), O_BINARY); -#endif -#ifdef USE_FDOPEN /* need to re-open in binary mode? */ - if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open stdin\n", progname); - exit(EXIT_FAILURE); - } -#else - infile = stdin; -#endif - } - - /* Scan the JPEG headers. */ - (void) scan_JPEG_header(verbose, raw); - - /* All done. */ - exit(EXIT_SUCCESS); - return 0; /* suppress no-return-value warnings */ -} +/* + * rdjpgcom.c + * + * Copyright (C) 1994-1997, Thomas G. Lane. + * Modified 2009 by Bill Allombert, Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a very simple stand-alone application that displays + * the text in COM (comment) markers in a JFIF file. + * This may be useful as an example of the minimum logic needed to parse + * JPEG markers. + */ + +#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */ +#include "jinclude.h" /* get auto-config symbols, */ + +#ifdef HAVE_LOCALE_H +#include /* Bill Allombert: use locale for isprint */ +#endif +#include /* to declare isupper(), tolower() */ +#ifdef USE_SETMODE +#include /* to declare setmode()'s parameter macros */ +/* If you have setmode() but not , just delete this line: */ +#include /* to declare setmode() */ +#endif + +#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ +#ifdef __MWERKS__ +#include /* Metrowerks needs this */ +#include /* ... and this */ +#endif +#ifdef THINK_C +#include /* Think declares it here */ +#endif +#endif + +#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ +#define READ_BINARY "r" +#else +#ifdef VMS /* VMS is very nonstandard */ +#define READ_BINARY "rb", "ctx=stm" +#else /* standard ANSI-compliant case */ +#define READ_BINARY "rb" +#endif +#endif + +#ifndef EXIT_FAILURE /* define exit() codes if not provided */ +#define EXIT_FAILURE 1 +#endif +#ifndef EXIT_SUCCESS +#ifdef VMS +#define EXIT_SUCCESS 1 /* VMS is very nonstandard */ +#else +#define EXIT_SUCCESS 0 +#endif +#endif + + +/* + * These macros are used to read the input file. + * To reuse this code in another application, you might need to change these. + */ + +static FILE * infile; /* input JPEG file */ + +/* Return next input byte, or EOF if no more */ +#define NEXTBYTE() getc(infile) + + +/* Error exit handler */ +#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE)) + + +/* Read one byte, testing for EOF */ +static int +read_1_byte (void) +{ + int c; + + c = NEXTBYTE(); + if (c == EOF) + ERREXIT("Premature EOF in JPEG file"); + return c; +} + +/* Read 2 bytes, convert to unsigned int */ +/* All 2-byte quantities in JPEG markers are MSB first */ +static unsigned int +read_2_bytes (void) +{ + int c1, c2; + + c1 = NEXTBYTE(); + if (c1 == EOF) + ERREXIT("Premature EOF in JPEG file"); + c2 = NEXTBYTE(); + if (c2 == EOF) + ERREXIT("Premature EOF in JPEG file"); + return (((unsigned int) c1) << 8) + ((unsigned int) c2); +} + + +/* + * JPEG markers consist of one or more 0xFF bytes, followed by a marker + * code byte (which is not an FF). Here are the marker codes of interest + * in this program. (See jdmarker.c for a more complete list.) + */ + +#define M_SOF0 0xC0 /* Start Of Frame N */ +#define M_SOF1 0xC1 /* N indicates which compression process */ +#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */ +#define M_SOF3 0xC3 +#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */ +#define M_SOF6 0xC6 +#define M_SOF7 0xC7 +#define M_SOF9 0xC9 +#define M_SOF10 0xCA +#define M_SOF11 0xCB +#define M_SOF13 0xCD +#define M_SOF14 0xCE +#define M_SOF15 0xCF +#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */ +#define M_EOI 0xD9 /* End Of Image (end of datastream) */ +#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ +#define M_APP0 0xE0 /* Application-specific marker, type N */ +#define M_APP12 0xEC /* (we don't bother to list all 16 APPn's) */ +#define M_COM 0xFE /* COMment */ + + +/* + * Find the next JPEG marker and return its marker code. + * We expect at least one FF byte, possibly more if the compressor used FFs + * to pad the file. + * There could also be non-FF garbage between markers. The treatment of such + * garbage is unspecified; we choose to skip over it but emit a warning msg. + * NB: this routine must not be used after seeing SOS marker, since it will + * not deal correctly with FF/00 sequences in the compressed image data... + */ + +static int +next_marker (void) +{ + int c; + int discarded_bytes = 0; + + /* Find 0xFF byte; count and skip any non-FFs. */ + c = read_1_byte(); + while (c != 0xFF) { + discarded_bytes++; + c = read_1_byte(); + } + /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs + * are legal as pad bytes, so don't count them in discarded_bytes. + */ + do { + c = read_1_byte(); + } while (c == 0xFF); + + if (discarded_bytes != 0) { + fprintf(stderr, "Warning: garbage data found in JPEG file\n"); + } + + return c; +} + + +/* + * Read the initial marker, which should be SOI. + * For a JFIF file, the first two bytes of the file should be literally + * 0xFF M_SOI. To be more general, we could use next_marker, but if the + * input file weren't actually JPEG at all, next_marker might read the whole + * file and then return a misleading error message... + */ + +static int +first_marker (void) +{ + int c1, c2; + + c1 = NEXTBYTE(); + c2 = NEXTBYTE(); + if (c1 != 0xFF || c2 != M_SOI) + ERREXIT("Not a JPEG file"); + return c2; +} + + +/* + * Most types of marker are followed by a variable-length parameter segment. + * This routine skips over the parameters for any marker we don't otherwise + * want to process. + * Note that we MUST skip the parameter segment explicitly in order not to + * be fooled by 0xFF bytes that might appear within the parameter segment; + * such bytes do NOT introduce new markers. + */ + +static void +skip_variable (void) +/* Skip over an unknown or uninteresting variable-length marker */ +{ + unsigned int length; + + /* Get the marker parameter length count */ + length = read_2_bytes(); + /* Length includes itself, so must be at least 2 */ + if (length < 2) + ERREXIT("Erroneous JPEG marker length"); + length -= 2; + /* Skip over the remaining bytes */ + while (length > 0) { + (void) read_1_byte(); + length--; + } +} + + +/* + * Process a COM marker. + * We want to print out the marker contents as legible text; + * we must guard against non-text junk and varying newline representations. + */ + +static void +process_COM (int raw) +{ + unsigned int length; + int ch; + int lastch = 0; + + /* Bill Allombert: set locale properly for isprint */ +#ifdef HAVE_LOCALE_H + setlocale(LC_CTYPE, ""); +#endif + + /* Get the marker parameter length count */ + length = read_2_bytes(); + /* Length includes itself, so must be at least 2 */ + if (length < 2) + ERREXIT("Erroneous JPEG marker length"); + length -= 2; + + while (length > 0) { + ch = read_1_byte(); + if (raw) { + putc(ch, stdout); + /* Emit the character in a readable form. + * Nonprintables are converted to \nnn form, + * while \ is converted to \\. + * Newlines in CR, CR/LF, or LF form will be printed as one newline. + */ + } else if (ch == '\r') { + printf("\n"); + } else if (ch == '\n') { + if (lastch != '\r') + printf("\n"); + } else if (ch == '\\') { + printf("\\\\"); + } else if (isprint(ch)) { + putc(ch, stdout); + } else { + printf("\\%03o", ch); + } + lastch = ch; + length--; + } + printf("\n"); + + /* Bill Allombert: revert to C locale */ +#ifdef HAVE_LOCALE_H + setlocale(LC_CTYPE, "C"); +#endif +} + + +/* + * Process a SOFn marker. + * This code is only needed if you want to know the image dimensions... + */ + +static void +process_SOFn (int marker) +{ + unsigned int length; + unsigned int image_height, image_width; + int data_precision, num_components; + const char * process; + int ci; + + length = read_2_bytes(); /* usual parameter length count */ + + data_precision = read_1_byte(); + image_height = read_2_bytes(); + image_width = read_2_bytes(); + num_components = read_1_byte(); + + switch (marker) { + case M_SOF0: process = "Baseline"; break; + case M_SOF1: process = "Extended sequential"; break; + case M_SOF2: process = "Progressive"; break; + case M_SOF3: process = "Lossless"; break; + case M_SOF5: process = "Differential sequential"; break; + case M_SOF6: process = "Differential progressive"; break; + case M_SOF7: process = "Differential lossless"; break; + case M_SOF9: process = "Extended sequential, arithmetic coding"; break; + case M_SOF10: process = "Progressive, arithmetic coding"; break; + case M_SOF11: process = "Lossless, arithmetic coding"; break; + case M_SOF13: process = "Differential sequential, arithmetic coding"; break; + case M_SOF14: process = "Differential progressive, arithmetic coding"; break; + case M_SOF15: process = "Differential lossless, arithmetic coding"; break; + default: process = "Unknown"; break; + } + + printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n", + image_width, image_height, num_components, data_precision); + printf("JPEG process: %s\n", process); + + if (length != (unsigned int) (8 + num_components * 3)) + ERREXIT("Bogus SOF marker length"); + + for (ci = 0; ci < num_components; ci++) { + (void) read_1_byte(); /* Component ID code */ + (void) read_1_byte(); /* H, V sampling factors */ + (void) read_1_byte(); /* Quantization table number */ + } +} + + +/* + * Parse the marker stream until SOS or EOI is seen; + * display any COM markers. + * While the companion program wrjpgcom will always insert COM markers before + * SOFn, other implementations might not, so we scan to SOS before stopping. + * If we were only interested in the image dimensions, we would stop at SOFn. + * (Conversely, if we only cared about COM markers, there would be no need + * for special code to handle SOFn; we could treat it like other markers.) + */ + +static int +scan_JPEG_header (int verbose, int raw) +{ + int marker; + + /* Expect SOI at start of file */ + if (first_marker() != M_SOI) + ERREXIT("Expected SOI marker first"); + + /* Scan miscellaneous markers until we reach SOS. */ + for (;;) { + marker = next_marker(); + switch (marker) { + /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be, + * treated as SOFn. C4 in particular is actually DHT. + */ + case M_SOF0: /* Baseline */ + case M_SOF1: /* Extended sequential, Huffman */ + case M_SOF2: /* Progressive, Huffman */ + case M_SOF3: /* Lossless, Huffman */ + case M_SOF5: /* Differential sequential, Huffman */ + case M_SOF6: /* Differential progressive, Huffman */ + case M_SOF7: /* Differential lossless, Huffman */ + case M_SOF9: /* Extended sequential, arithmetic */ + case M_SOF10: /* Progressive, arithmetic */ + case M_SOF11: /* Lossless, arithmetic */ + case M_SOF13: /* Differential sequential, arithmetic */ + case M_SOF14: /* Differential progressive, arithmetic */ + case M_SOF15: /* Differential lossless, arithmetic */ + if (verbose) + process_SOFn(marker); + else + skip_variable(); + break; + + case M_SOS: /* stop before hitting compressed data */ + return marker; + + case M_EOI: /* in case it's a tables-only JPEG stream */ + return marker; + + case M_COM: + process_COM(raw); + break; + + case M_APP12: + /* Some digital camera makers put useful textual information into + * APP12 markers, so we print those out too when in -verbose mode. + */ + if (verbose) { + printf("APP12 contains:\n"); + process_COM(raw); + } else + skip_variable(); + break; + + default: /* Anything else just gets skipped */ + skip_variable(); /* we assume it has a parameter count... */ + break; + } + } /* end loop */ +} + + +/* Command line parsing code */ + +static const char * progname; /* program name for error messages */ + + +static void +usage (void) +/* complain about bad command line */ +{ + fprintf(stderr, "rdjpgcom displays any textual comments in a JPEG file.\n"); + + fprintf(stderr, "Usage: %s [switches] [inputfile]\n", progname); + + fprintf(stderr, "Switches (names may be abbreviated):\n"); + fprintf(stderr, " -raw Display non-printable characters in comments (unsafe)\n"); + fprintf(stderr, " -verbose Also display dimensions of JPEG image\n"); + + exit(EXIT_FAILURE); +} + + +static int +keymatch (char * arg, const char * keyword, int minchars) +/* Case-insensitive matching of (possibly abbreviated) keyword switches. */ +/* keyword is the constant keyword (must be lower case already), */ +/* minchars is length of minimum legal abbreviation. */ +{ + register int ca, ck; + register int nmatched = 0; + + while ((ca = *arg++) != '\0') { + if ((ck = *keyword++) == '\0') + return 0; /* arg longer than keyword, no good */ + if (isupper(ca)) /* force arg to lcase (assume ck is already) */ + ca = tolower(ca); + if (ca != ck) + return 0; /* no good */ + nmatched++; /* count matched characters */ + } + /* reached end of argument; fail if it's too short for unique abbrev */ + if (nmatched < minchars) + return 0; + return 1; /* A-OK */ +} + + +/* + * The main program. + */ + +int +main (int argc, char **argv) +{ + int argn; + char * arg; + int verbose = 0, raw = 0; + + /* On Mac, fetch a command line. */ +#ifdef USE_CCOMMAND + argc = ccommand(&argv); +#endif + + progname = argv[0]; + if (progname == NULL || progname[0] == 0) + progname = "rdjpgcom"; /* in case C library doesn't provide it */ + + /* Parse switches, if any */ + for (argn = 1; argn < argc; argn++) { + arg = argv[argn]; + if (arg[0] != '-') + break; /* not switch, must be file name */ + arg++; /* advance over '-' */ + if (keymatch(arg, "verbose", 1)) { + verbose++; + } else if (keymatch(arg, "raw", 1)) { + raw = 1; + } else + usage(); + } + + /* Open the input file. */ + /* Unix style: expect zero or one file name */ + if (argn < argc-1) { + fprintf(stderr, "%s: only one input file\n", progname); + usage(); + } + if (argn < argc) { + if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); + exit(EXIT_FAILURE); + } + } else { + /* default input file is stdin */ +#ifdef USE_SETMODE /* need to hack file mode? */ + setmode(fileno(stdin), O_BINARY); +#endif +#ifdef USE_FDOPEN /* need to re-open in binary mode? */ + if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open stdin\n", progname); + exit(EXIT_FAILURE); + } +#else + infile = stdin; +#endif + } + + /* Scan the JPEG headers. */ + (void) scan_JPEG_header(verbose, raw); + + /* All done. */ + exit(EXIT_SUCCESS); + return 0; /* suppress no-return-value warnings */ +} diff --git a/Source/LibJPEG/rdppm.c b/Source/LibJPEG/rdppm.c index 9dcd2dc..a757022 100644 --- a/Source/LibJPEG/rdppm.c +++ b/Source/LibJPEG/rdppm.c @@ -1,459 +1,459 @@ -/* - * rdppm.c - * - * Copyright (C) 1991-1997, Thomas G. Lane. - * Modified 2009 by Bill Allombert, Guido Vollbeding. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains routines to read input images in PPM/PGM format. - * The extended 2-byte-per-sample raw PPM/PGM formats are supported. - * The PBMPLUS library is NOT required to compile this software - * (but it is highly useful as a set of PPM image manipulation programs). - * - * These routines may need modification for non-Unix environments or - * specialized applications. As they stand, they assume input from - * an ordinary stdio stream. They further assume that reading begins - * at the start of the file; start_input may need work if the - * user interface has already read some data (e.g., to determine that - * the file is indeed PPM format). - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ - -#ifdef PPM_SUPPORTED - - -/* Portions of this code are based on the PBMPLUS library, which is: -** -** Copyright (C) 1988 by Jef Poskanzer. -** -** Permission to use, copy, modify, and distribute this software and its -** documentation for any purpose and without fee is hereby granted, provided -** that the above copyright notice appear in all copies and that both that -** copyright notice and this permission notice appear in supporting -** documentation. This software is provided "as is" without express or -** implied warranty. -*/ - - -/* Macros to deal with unsigned chars as efficiently as compiler allows */ - -#ifdef HAVE_UNSIGNED_CHAR -typedef unsigned char U_CHAR; -#define UCH(x) ((int) (x)) -#else /* !HAVE_UNSIGNED_CHAR */ -#ifdef CHAR_IS_UNSIGNED -typedef char U_CHAR; -#define UCH(x) ((int) (x)) -#else -typedef char U_CHAR; -#define UCH(x) ((int) (x) & 0xFF) -#endif -#endif /* HAVE_UNSIGNED_CHAR */ - - -#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) - - -/* - * On most systems, reading individual bytes with getc() is drastically less - * efficient than buffering a row at a time with fread(). On PCs, we must - * allocate the buffer in near data space, because we are assuming small-data - * memory model, wherein fread() can't reach far memory. If you need to - * process very wide images on a PC, you might have to compile in large-memory - * model, or else replace fread() with a getc() loop --- which will be much - * slower. - */ - - -/* Private version of data source object */ - -typedef struct { - struct cjpeg_source_struct pub; /* public fields */ - - U_CHAR *iobuffer; /* non-FAR pointer to I/O buffer */ - JSAMPROW pixrow; /* FAR pointer to same */ - size_t buffer_width; /* width of I/O buffer */ - JSAMPLE *rescale; /* => maxval-remapping array, or NULL */ -} ppm_source_struct; - -typedef ppm_source_struct * ppm_source_ptr; - - -LOCAL(int) -pbm_getc (FILE * infile) -/* Read next char, skipping over any comments */ -/* A comment/newline sequence is returned as a newline */ -{ - register int ch; - - ch = getc(infile); - if (ch == '#') { - do { - ch = getc(infile); - } while (ch != '\n' && ch != EOF); - } - return ch; -} - - -LOCAL(unsigned int) -read_pbm_integer (j_compress_ptr cinfo, FILE * infile) -/* Read an unsigned decimal integer from the PPM file */ -/* Swallows one trailing character after the integer */ -/* Note that on a 16-bit-int machine, only values up to 64k can be read. */ -/* This should not be a problem in practice. */ -{ - register int ch; - register unsigned int val; - - /* Skip any leading whitespace */ - do { - ch = pbm_getc(infile); - if (ch == EOF) - ERREXIT(cinfo, JERR_INPUT_EOF); - } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); - - if (ch < '0' || ch > '9') - ERREXIT(cinfo, JERR_PPM_NONNUMERIC); - - val = ch - '0'; - while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { - val *= 10; - val += ch - '0'; - } - return val; -} - - -/* - * Read one row of pixels. - * - * We provide several different versions depending on input file format. - * In all cases, input is scaled to the size of JSAMPLE. - * - * A really fast path is provided for reading byte/sample raw files with - * maxval = MAXJSAMPLE, which is the normal case for 8-bit data. - */ - - -METHODDEF(JDIMENSION) -get_text_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading text-format PGM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr) sinfo; - FILE * infile = source->pub.input_file; - register JSAMPROW ptr; - register JSAMPLE *rescale = source->rescale; - JDIMENSION col; - - ptr = source->pub.buffer[0]; - for (col = cinfo->image_width; col > 0; col--) { - *ptr++ = rescale[read_pbm_integer(cinfo, infile)]; - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_text_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading text-format PPM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr) sinfo; - FILE * infile = source->pub.input_file; - register JSAMPROW ptr; - register JSAMPLE *rescale = source->rescale; - JDIMENSION col; - - ptr = source->pub.buffer[0]; - for (col = cinfo->image_width; col > 0; col--) { - *ptr++ = rescale[read_pbm_integer(cinfo, infile)]; - *ptr++ = rescale[read_pbm_integer(cinfo, infile)]; - *ptr++ = rescale[read_pbm_integer(cinfo, infile)]; - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_scaled_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-byte-format PGM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr) sinfo; - register JSAMPROW ptr; - register U_CHAR * bufferptr; - register JSAMPLE *rescale = source->rescale; - JDIMENSION col; - - if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - ptr = source->pub.buffer[0]; - bufferptr = source->iobuffer; - for (col = cinfo->image_width; col > 0; col--) { - *ptr++ = rescale[UCH(*bufferptr++)]; - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_scaled_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-byte-format PPM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr) sinfo; - register JSAMPROW ptr; - register U_CHAR * bufferptr; - register JSAMPLE *rescale = source->rescale; - JDIMENSION col; - - if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - ptr = source->pub.buffer[0]; - bufferptr = source->iobuffer; - for (col = cinfo->image_width; col > 0; col--) { - *ptr++ = rescale[UCH(*bufferptr++)]; - *ptr++ = rescale[UCH(*bufferptr++)]; - *ptr++ = rescale[UCH(*bufferptr++)]; - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_raw_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-byte-format files with maxval = MAXJSAMPLE. - * In this case we just read right into the JSAMPLE buffer! - * Note that same code works for PPM and PGM files. - */ -{ - ppm_source_ptr source = (ppm_source_ptr) sinfo; - - if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - return 1; -} - - -METHODDEF(JDIMENSION) -get_word_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-word-format PGM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr) sinfo; - register JSAMPROW ptr; - register U_CHAR * bufferptr; - register JSAMPLE *rescale = source->rescale; - JDIMENSION col; - - if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - ptr = source->pub.buffer[0]; - bufferptr = source->iobuffer; - for (col = cinfo->image_width; col > 0; col--) { - register int temp; - temp = UCH(*bufferptr++) << 8; - temp |= UCH(*bufferptr++); - *ptr++ = rescale[temp]; - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_word_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-word-format PPM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr) sinfo; - register JSAMPROW ptr; - register U_CHAR * bufferptr; - register JSAMPLE *rescale = source->rescale; - JDIMENSION col; - - if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - ptr = source->pub.buffer[0]; - bufferptr = source->iobuffer; - for (col = cinfo->image_width; col > 0; col--) { - register int temp; - temp = UCH(*bufferptr++) << 8; - temp |= UCH(*bufferptr++); - *ptr++ = rescale[temp]; - temp = UCH(*bufferptr++) << 8; - temp |= UCH(*bufferptr++); - *ptr++ = rescale[temp]; - temp = UCH(*bufferptr++) << 8; - temp |= UCH(*bufferptr++); - *ptr++ = rescale[temp]; - } - return 1; -} - - -/* - * Read the file header; return image size and component count. - */ - -METHODDEF(void) -start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - ppm_source_ptr source = (ppm_source_ptr) sinfo; - int c; - unsigned int w, h, maxval; - boolean need_iobuffer, use_raw_buffer, need_rescale; - - if (getc(source->pub.input_file) != 'P') - ERREXIT(cinfo, JERR_PPM_NOT); - - c = getc(source->pub.input_file); /* subformat discriminator character */ - - /* detect unsupported variants (ie, PBM) before trying to read header */ - switch (c) { - case '2': /* it's a text-format PGM file */ - case '3': /* it's a text-format PPM file */ - case '5': /* it's a raw-format PGM file */ - case '6': /* it's a raw-format PPM file */ - break; - default: - ERREXIT(cinfo, JERR_PPM_NOT); - break; - } - - /* fetch the remaining header info */ - w = read_pbm_integer(cinfo, source->pub.input_file); - h = read_pbm_integer(cinfo, source->pub.input_file); - maxval = read_pbm_integer(cinfo, source->pub.input_file); - - if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ - ERREXIT(cinfo, JERR_PPM_NOT); - - cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */ - cinfo->image_width = (JDIMENSION) w; - cinfo->image_height = (JDIMENSION) h; - - /* initialize flags to most common settings */ - need_iobuffer = TRUE; /* do we need an I/O buffer? */ - use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ - need_rescale = TRUE; /* do we need a rescale array? */ - - switch (c) { - case '2': /* it's a text-format PGM file */ - cinfo->input_components = 1; - cinfo->in_color_space = JCS_GRAYSCALE; - TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h); - source->pub.get_pixel_rows = get_text_gray_row; - need_iobuffer = FALSE; - break; - - case '3': /* it's a text-format PPM file */ - cinfo->input_components = 3; - cinfo->in_color_space = JCS_RGB; - TRACEMS2(cinfo, 1, JTRC_PPM_TEXT, w, h); - source->pub.get_pixel_rows = get_text_rgb_row; - need_iobuffer = FALSE; - break; - - case '5': /* it's a raw-format PGM file */ - cinfo->input_components = 1; - cinfo->in_color_space = JCS_GRAYSCALE; - TRACEMS2(cinfo, 1, JTRC_PGM, w, h); - if (maxval > 255) { - source->pub.get_pixel_rows = get_word_gray_row; - } else if (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR)) { - source->pub.get_pixel_rows = get_raw_row; - use_raw_buffer = TRUE; - need_rescale = FALSE; - } else { - source->pub.get_pixel_rows = get_scaled_gray_row; - } - break; - - case '6': /* it's a raw-format PPM file */ - cinfo->input_components = 3; - cinfo->in_color_space = JCS_RGB; - TRACEMS2(cinfo, 1, JTRC_PPM, w, h); - if (maxval > 255) { - source->pub.get_pixel_rows = get_word_rgb_row; - } else if (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR)) { - source->pub.get_pixel_rows = get_raw_row; - use_raw_buffer = TRUE; - need_rescale = FALSE; - } else { - source->pub.get_pixel_rows = get_scaled_rgb_row; - } - break; - } - - /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ - if (need_iobuffer) { - source->buffer_width = (size_t) w * cinfo->input_components * - ((maxval<=255) ? SIZEOF(U_CHAR) : (2*SIZEOF(U_CHAR))); - source->iobuffer = (U_CHAR *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - source->buffer_width); - } - - /* Create compressor input buffer. */ - if (use_raw_buffer) { - /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ - /* Synthesize a JSAMPARRAY pointer structure */ - /* Cast here implies near->far pointer conversion on PCs */ - source->pixrow = (JSAMPROW) source->iobuffer; - source->pub.buffer = & source->pixrow; - source->pub.buffer_height = 1; - } else { - /* Need to translate anyway, so make a separate sample buffer. */ - source->pub.buffer = (*cinfo->mem->alloc_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, - (JDIMENSION) w * cinfo->input_components, (JDIMENSION) 1); - source->pub.buffer_height = 1; - } - - /* Compute the rescaling array if required. */ - if (need_rescale) { - INT32 val, half_maxval; - - /* On 16-bit-int machines we have to be careful of maxval = 65535 */ - source->rescale = (JSAMPLE *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - (size_t) (((long) maxval + 1L) * SIZEOF(JSAMPLE))); - half_maxval = maxval / 2; - for (val = 0; val <= (INT32) maxval; val++) { - /* The multiplication here must be done in 32 bits to avoid overflow */ - source->rescale[val] = (JSAMPLE) ((val*MAXJSAMPLE + half_maxval)/maxval); - } - } -} - - -/* - * Finish up at the end of the file. - */ - -METHODDEF(void) -finish_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - /* no work */ -} - - -/* - * The module selection routine for PPM format input. - */ - -GLOBAL(cjpeg_source_ptr) -jinit_read_ppm (j_compress_ptr cinfo) -{ - ppm_source_ptr source; - - /* Create module interface object */ - source = (ppm_source_ptr) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - SIZEOF(ppm_source_struct)); - /* Fill in method ptrs, except get_pixel_rows which start_input sets */ - source->pub.start_input = start_input_ppm; - source->pub.finish_input = finish_input_ppm; - - return (cjpeg_source_ptr) source; -} - -#endif /* PPM_SUPPORTED */ +/* + * rdppm.c + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * Modified 2009 by Bill Allombert, Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to read input images in PPM/PGM format. + * The extended 2-byte-per-sample raw PPM/PGM formats are supported. + * The PBMPLUS library is NOT required to compile this software + * (but it is highly useful as a set of PPM image manipulation programs). + * + * These routines may need modification for non-Unix environments or + * specialized applications. As they stand, they assume input from + * an ordinary stdio stream. They further assume that reading begins + * at the start of the file; start_input may need work if the + * user interface has already read some data (e.g., to determine that + * the file is indeed PPM format). + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + +#ifdef PPM_SUPPORTED + + +/* Portions of this code are based on the PBMPLUS library, which is: +** +** Copyright (C) 1988 by Jef Poskanzer. +** +** Permission to use, copy, modify, and distribute this software and its +** documentation for any purpose and without fee is hereby granted, provided +** that the above copyright notice appear in all copies and that both that +** copyright notice and this permission notice appear in supporting +** documentation. This software is provided "as is" without express or +** implied warranty. +*/ + + +/* Macros to deal with unsigned chars as efficiently as compiler allows */ + +#ifdef HAVE_UNSIGNED_CHAR +typedef unsigned char U_CHAR; +#define UCH(x) ((int) (x)) +#else /* !HAVE_UNSIGNED_CHAR */ +#ifdef CHAR_IS_UNSIGNED +typedef char U_CHAR; +#define UCH(x) ((int) (x)) +#else +typedef char U_CHAR; +#define UCH(x) ((int) (x) & 0xFF) +#endif +#endif /* HAVE_UNSIGNED_CHAR */ + + +#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) + + +/* + * On most systems, reading individual bytes with getc() is drastically less + * efficient than buffering a row at a time with fread(). On PCs, we must + * allocate the buffer in near data space, because we are assuming small-data + * memory model, wherein fread() can't reach far memory. If you need to + * process very wide images on a PC, you might have to compile in large-memory + * model, or else replace fread() with a getc() loop --- which will be much + * slower. + */ + + +/* Private version of data source object */ + +typedef struct { + struct cjpeg_source_struct pub; /* public fields */ + + U_CHAR *iobuffer; /* non-FAR pointer to I/O buffer */ + JSAMPROW pixrow; /* FAR pointer to same */ + size_t buffer_width; /* width of I/O buffer */ + JSAMPLE *rescale; /* => maxval-remapping array, or NULL */ +} ppm_source_struct; + +typedef ppm_source_struct * ppm_source_ptr; + + +LOCAL(int) +pbm_getc (FILE * infile) +/* Read next char, skipping over any comments */ +/* A comment/newline sequence is returned as a newline */ +{ + register int ch; + + ch = getc(infile); + if (ch == '#') { + do { + ch = getc(infile); + } while (ch != '\n' && ch != EOF); + } + return ch; +} + + +LOCAL(unsigned int) +read_pbm_integer (j_compress_ptr cinfo, FILE * infile) +/* Read an unsigned decimal integer from the PPM file */ +/* Swallows one trailing character after the integer */ +/* Note that on a 16-bit-int machine, only values up to 64k can be read. */ +/* This should not be a problem in practice. */ +{ + register int ch; + register unsigned int val; + + /* Skip any leading whitespace */ + do { + ch = pbm_getc(infile); + if (ch == EOF) + ERREXIT(cinfo, JERR_INPUT_EOF); + } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); + + if (ch < '0' || ch > '9') + ERREXIT(cinfo, JERR_PPM_NONNUMERIC); + + val = ch - '0'; + while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { + val *= 10; + val += ch - '0'; + } + return val; +} + + +/* + * Read one row of pixels. + * + * We provide several different versions depending on input file format. + * In all cases, input is scaled to the size of JSAMPLE. + * + * A really fast path is provided for reading byte/sample raw files with + * maxval = MAXJSAMPLE, which is the normal case for 8-bit data. + */ + + +METHODDEF(JDIMENSION) +get_text_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +/* This version is for reading text-format PGM files with any maxval */ +{ + ppm_source_ptr source = (ppm_source_ptr) sinfo; + FILE * infile = source->pub.input_file; + register JSAMPROW ptr; + register JSAMPLE *rescale = source->rescale; + JDIMENSION col; + + ptr = source->pub.buffer[0]; + for (col = cinfo->image_width; col > 0; col--) { + *ptr++ = rescale[read_pbm_integer(cinfo, infile)]; + } + return 1; +} + + +METHODDEF(JDIMENSION) +get_text_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +/* This version is for reading text-format PPM files with any maxval */ +{ + ppm_source_ptr source = (ppm_source_ptr) sinfo; + FILE * infile = source->pub.input_file; + register JSAMPROW ptr; + register JSAMPLE *rescale = source->rescale; + JDIMENSION col; + + ptr = source->pub.buffer[0]; + for (col = cinfo->image_width; col > 0; col--) { + *ptr++ = rescale[read_pbm_integer(cinfo, infile)]; + *ptr++ = rescale[read_pbm_integer(cinfo, infile)]; + *ptr++ = rescale[read_pbm_integer(cinfo, infile)]; + } + return 1; +} + + +METHODDEF(JDIMENSION) +get_scaled_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +/* This version is for reading raw-byte-format PGM files with any maxval */ +{ + ppm_source_ptr source = (ppm_source_ptr) sinfo; + register JSAMPROW ptr; + register U_CHAR * bufferptr; + register JSAMPLE *rescale = source->rescale; + JDIMENSION col; + + if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) + ERREXIT(cinfo, JERR_INPUT_EOF); + ptr = source->pub.buffer[0]; + bufferptr = source->iobuffer; + for (col = cinfo->image_width; col > 0; col--) { + *ptr++ = rescale[UCH(*bufferptr++)]; + } + return 1; +} + + +METHODDEF(JDIMENSION) +get_scaled_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +/* This version is for reading raw-byte-format PPM files with any maxval */ +{ + ppm_source_ptr source = (ppm_source_ptr) sinfo; + register JSAMPROW ptr; + register U_CHAR * bufferptr; + register JSAMPLE *rescale = source->rescale; + JDIMENSION col; + + if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) + ERREXIT(cinfo, JERR_INPUT_EOF); + ptr = source->pub.buffer[0]; + bufferptr = source->iobuffer; + for (col = cinfo->image_width; col > 0; col--) { + *ptr++ = rescale[UCH(*bufferptr++)]; + *ptr++ = rescale[UCH(*bufferptr++)]; + *ptr++ = rescale[UCH(*bufferptr++)]; + } + return 1; +} + + +METHODDEF(JDIMENSION) +get_raw_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +/* This version is for reading raw-byte-format files with maxval = MAXJSAMPLE. + * In this case we just read right into the JSAMPLE buffer! + * Note that same code works for PPM and PGM files. + */ +{ + ppm_source_ptr source = (ppm_source_ptr) sinfo; + + if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) + ERREXIT(cinfo, JERR_INPUT_EOF); + return 1; +} + + +METHODDEF(JDIMENSION) +get_word_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +/* This version is for reading raw-word-format PGM files with any maxval */ +{ + ppm_source_ptr source = (ppm_source_ptr) sinfo; + register JSAMPROW ptr; + register U_CHAR * bufferptr; + register JSAMPLE *rescale = source->rescale; + JDIMENSION col; + + if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) + ERREXIT(cinfo, JERR_INPUT_EOF); + ptr = source->pub.buffer[0]; + bufferptr = source->iobuffer; + for (col = cinfo->image_width; col > 0; col--) { + register int temp; + temp = UCH(*bufferptr++) << 8; + temp |= UCH(*bufferptr++); + *ptr++ = rescale[temp]; + } + return 1; +} + + +METHODDEF(JDIMENSION) +get_word_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +/* This version is for reading raw-word-format PPM files with any maxval */ +{ + ppm_source_ptr source = (ppm_source_ptr) sinfo; + register JSAMPROW ptr; + register U_CHAR * bufferptr; + register JSAMPLE *rescale = source->rescale; + JDIMENSION col; + + if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) + ERREXIT(cinfo, JERR_INPUT_EOF); + ptr = source->pub.buffer[0]; + bufferptr = source->iobuffer; + for (col = cinfo->image_width; col > 0; col--) { + register int temp; + temp = UCH(*bufferptr++) << 8; + temp |= UCH(*bufferptr++); + *ptr++ = rescale[temp]; + temp = UCH(*bufferptr++) << 8; + temp |= UCH(*bufferptr++); + *ptr++ = rescale[temp]; + temp = UCH(*bufferptr++) << 8; + temp |= UCH(*bufferptr++); + *ptr++ = rescale[temp]; + } + return 1; +} + + +/* + * Read the file header; return image size and component count. + */ + +METHODDEF(void) +start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +{ + ppm_source_ptr source = (ppm_source_ptr) sinfo; + int c; + unsigned int w, h, maxval; + boolean need_iobuffer, use_raw_buffer, need_rescale; + + if (getc(source->pub.input_file) != 'P') + ERREXIT(cinfo, JERR_PPM_NOT); + + c = getc(source->pub.input_file); /* subformat discriminator character */ + + /* detect unsupported variants (ie, PBM) before trying to read header */ + switch (c) { + case '2': /* it's a text-format PGM file */ + case '3': /* it's a text-format PPM file */ + case '5': /* it's a raw-format PGM file */ + case '6': /* it's a raw-format PPM file */ + break; + default: + ERREXIT(cinfo, JERR_PPM_NOT); + break; + } + + /* fetch the remaining header info */ + w = read_pbm_integer(cinfo, source->pub.input_file); + h = read_pbm_integer(cinfo, source->pub.input_file); + maxval = read_pbm_integer(cinfo, source->pub.input_file); + + if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ + ERREXIT(cinfo, JERR_PPM_NOT); + + cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */ + cinfo->image_width = (JDIMENSION) w; + cinfo->image_height = (JDIMENSION) h; + + /* initialize flags to most common settings */ + need_iobuffer = TRUE; /* do we need an I/O buffer? */ + use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ + need_rescale = TRUE; /* do we need a rescale array? */ + + switch (c) { + case '2': /* it's a text-format PGM file */ + cinfo->input_components = 1; + cinfo->in_color_space = JCS_GRAYSCALE; + TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h); + source->pub.get_pixel_rows = get_text_gray_row; + need_iobuffer = FALSE; + break; + + case '3': /* it's a text-format PPM file */ + cinfo->input_components = 3; + cinfo->in_color_space = JCS_RGB; + TRACEMS2(cinfo, 1, JTRC_PPM_TEXT, w, h); + source->pub.get_pixel_rows = get_text_rgb_row; + need_iobuffer = FALSE; + break; + + case '5': /* it's a raw-format PGM file */ + cinfo->input_components = 1; + cinfo->in_color_space = JCS_GRAYSCALE; + TRACEMS2(cinfo, 1, JTRC_PGM, w, h); + if (maxval > 255) { + source->pub.get_pixel_rows = get_word_gray_row; + } else if (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR)) { + source->pub.get_pixel_rows = get_raw_row; + use_raw_buffer = TRUE; + need_rescale = FALSE; + } else { + source->pub.get_pixel_rows = get_scaled_gray_row; + } + break; + + case '6': /* it's a raw-format PPM file */ + cinfo->input_components = 3; + cinfo->in_color_space = JCS_RGB; + TRACEMS2(cinfo, 1, JTRC_PPM, w, h); + if (maxval > 255) { + source->pub.get_pixel_rows = get_word_rgb_row; + } else if (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR)) { + source->pub.get_pixel_rows = get_raw_row; + use_raw_buffer = TRUE; + need_rescale = FALSE; + } else { + source->pub.get_pixel_rows = get_scaled_rgb_row; + } + break; + } + + /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ + if (need_iobuffer) { + source->buffer_width = (size_t) w * cinfo->input_components * + ((maxval<=255) ? SIZEOF(U_CHAR) : (2*SIZEOF(U_CHAR))); + source->iobuffer = (U_CHAR *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + source->buffer_width); + } + + /* Create compressor input buffer. */ + if (use_raw_buffer) { + /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ + /* Synthesize a JSAMPARRAY pointer structure */ + /* Cast here implies near->far pointer conversion on PCs */ + source->pixrow = (JSAMPROW) source->iobuffer; + source->pub.buffer = & source->pixrow; + source->pub.buffer_height = 1; + } else { + /* Need to translate anyway, so make a separate sample buffer. */ + source->pub.buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) w * cinfo->input_components, (JDIMENSION) 1); + source->pub.buffer_height = 1; + } + + /* Compute the rescaling array if required. */ + if (need_rescale) { + INT32 val, half_maxval; + + /* On 16-bit-int machines we have to be careful of maxval = 65535 */ + source->rescale = (JSAMPLE *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (size_t) (((long) maxval + 1L) * SIZEOF(JSAMPLE))); + half_maxval = maxval / 2; + for (val = 0; val <= (INT32) maxval; val++) { + /* The multiplication here must be done in 32 bits to avoid overflow */ + source->rescale[val] = (JSAMPLE) ((val*MAXJSAMPLE + half_maxval)/maxval); + } + } +} + + +/* + * Finish up at the end of the file. + */ + +METHODDEF(void) +finish_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +{ + /* no work */ +} + + +/* + * The module selection routine for PPM format input. + */ + +GLOBAL(cjpeg_source_ptr) +jinit_read_ppm (j_compress_ptr cinfo) +{ + ppm_source_ptr source; + + /* Create module interface object */ + source = (ppm_source_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(ppm_source_struct)); + /* Fill in method ptrs, except get_pixel_rows which start_input sets */ + source->pub.start_input = start_input_ppm; + source->pub.finish_input = finish_input_ppm; + + return (cjpeg_source_ptr) source; +} + +#endif /* PPM_SUPPORTED */ diff --git a/Source/LibJPEG/rdrle.c b/Source/LibJPEG/rdrle.c index df871e0..542bc37 100644 --- a/Source/LibJPEG/rdrle.c +++ b/Source/LibJPEG/rdrle.c @@ -1,387 +1,387 @@ -/* - * rdrle.c - * - * Copyright (C) 1991-1996, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains routines to read input images in Utah RLE format. - * The Utah Raster Toolkit library is required (version 3.1 or later). - * - * These routines may need modification for non-Unix environments or - * specialized applications. As they stand, they assume input from - * an ordinary stdio stream. They further assume that reading begins - * at the start of the file; start_input may need work if the - * user interface has already read some data (e.g., to determine that - * the file is indeed RLE format). - * - * Based on code contributed by Mike Lijewski, - * with updates from Robert Hutchinson. - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ - -#ifdef RLE_SUPPORTED - -/* rle.h is provided by the Utah Raster Toolkit. */ - -#include - -/* - * We assume that JSAMPLE has the same representation as rle_pixel, - * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples. - */ - -#if BITS_IN_JSAMPLE != 8 - Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ -#endif - -/* - * We support the following types of RLE files: - * - * GRAYSCALE - 8 bits, no colormap - * MAPPEDGRAY - 8 bits, 1 channel colomap - * PSEUDOCOLOR - 8 bits, 3 channel colormap - * TRUECOLOR - 24 bits, 3 channel colormap - * DIRECTCOLOR - 24 bits, no colormap - * - * For now, we ignore any alpha channel in the image. - */ - -typedef enum - { GRAYSCALE, MAPPEDGRAY, PSEUDOCOLOR, TRUECOLOR, DIRECTCOLOR } rle_kind; - - -/* - * Since RLE stores scanlines bottom-to-top, we have to invert the image - * to conform to JPEG's top-to-bottom order. To do this, we read the - * incoming image into a virtual array on the first get_pixel_rows call, - * then fetch the required row from the virtual array on subsequent calls. - */ - -typedef struct _rle_source_struct * rle_source_ptr; - -typedef struct _rle_source_struct { - struct cjpeg_source_struct pub; /* public fields */ - - rle_kind visual; /* actual type of input file */ - jvirt_sarray_ptr image; /* virtual array to hold the image */ - JDIMENSION row; /* current row # in the virtual array */ - rle_hdr header; /* Input file information */ - rle_pixel** rle_row; /* holds a row returned by rle_getrow() */ - -} rle_source_struct; - - -/* - * Read the file header; return image size and component count. - */ - -METHODDEF(void) -start_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - rle_source_ptr source = (rle_source_ptr) sinfo; - JDIMENSION width, height; -#ifdef PROGRESS_REPORT - cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; -#endif - - /* Use RLE library routine to get the header info */ - source->header = *rle_hdr_init(NULL); - source->header.rle_file = source->pub.input_file; - switch (rle_get_setup(&(source->header))) { - case RLE_SUCCESS: - /* A-OK */ - break; - case RLE_NOT_RLE: - ERREXIT(cinfo, JERR_RLE_NOT); - break; - case RLE_NO_SPACE: - ERREXIT(cinfo, JERR_RLE_MEM); - break; - case RLE_EMPTY: - ERREXIT(cinfo, JERR_RLE_EMPTY); - break; - case RLE_EOF: - ERREXIT(cinfo, JERR_RLE_EOF); - break; - default: - ERREXIT(cinfo, JERR_RLE_BADERROR); - break; - } - - /* Figure out what we have, set private vars and return values accordingly */ - - width = source->header.xmax - source->header.xmin + 1; - height = source->header.ymax - source->header.ymin + 1; - source->header.xmin = 0; /* realign horizontally */ - source->header.xmax = width-1; - - cinfo->image_width = width; - cinfo->image_height = height; - cinfo->data_precision = 8; /* we can only handle 8 bit data */ - - if (source->header.ncolors == 1 && source->header.ncmap == 0) { - source->visual = GRAYSCALE; - TRACEMS2(cinfo, 1, JTRC_RLE_GRAY, width, height); - } else if (source->header.ncolors == 1 && source->header.ncmap == 1) { - source->visual = MAPPEDGRAY; - TRACEMS3(cinfo, 1, JTRC_RLE_MAPGRAY, width, height, - 1 << source->header.cmaplen); - } else if (source->header.ncolors == 1 && source->header.ncmap == 3) { - source->visual = PSEUDOCOLOR; - TRACEMS3(cinfo, 1, JTRC_RLE_MAPPED, width, height, - 1 << source->header.cmaplen); - } else if (source->header.ncolors == 3 && source->header.ncmap == 3) { - source->visual = TRUECOLOR; - TRACEMS3(cinfo, 1, JTRC_RLE_FULLMAP, width, height, - 1 << source->header.cmaplen); - } else if (source->header.ncolors == 3 && source->header.ncmap == 0) { - source->visual = DIRECTCOLOR; - TRACEMS2(cinfo, 1, JTRC_RLE, width, height); - } else - ERREXIT(cinfo, JERR_RLE_UNSUPPORTED); - - if (source->visual == GRAYSCALE || source->visual == MAPPEDGRAY) { - cinfo->in_color_space = JCS_GRAYSCALE; - cinfo->input_components = 1; - } else { - cinfo->in_color_space = JCS_RGB; - cinfo->input_components = 3; - } - - /* - * A place to hold each scanline while it's converted. - * (GRAYSCALE scanlines don't need converting) - */ - if (source->visual != GRAYSCALE) { - source->rle_row = (rle_pixel**) (*cinfo->mem->alloc_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, - (JDIMENSION) width, (JDIMENSION) cinfo->input_components); - } - - /* request a virtual array to hold the image */ - source->image = (*cinfo->mem->request_virt_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, - (JDIMENSION) (width * source->header.ncolors), - (JDIMENSION) height, (JDIMENSION) 1); - -#ifdef PROGRESS_REPORT - if (progress != NULL) { - /* count file input as separate pass */ - progress->total_extra_passes++; - } -#endif - - source->pub.buffer_height = 1; -} - - -/* - * Read one row of pixels. - * Called only after load_image has read the image into the virtual array. - * Used for GRAYSCALE, MAPPEDGRAY, TRUECOLOR, and DIRECTCOLOR images. - */ - -METHODDEF(JDIMENSION) -get_rle_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - rle_source_ptr source = (rle_source_ptr) sinfo; - - source->row--; - source->pub.buffer = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE); - - return 1; -} - -/* - * Read one row of pixels. - * Called only after load_image has read the image into the virtual array. - * Used for PSEUDOCOLOR images. - */ - -METHODDEF(JDIMENSION) -get_pseudocolor_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - rle_source_ptr source = (rle_source_ptr) sinfo; - JSAMPROW src_row, dest_row; - JDIMENSION col; - rle_map *colormap; - int val; - - colormap = source->header.cmap; - dest_row = source->pub.buffer[0]; - source->row--; - src_row = * (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE); - - for (col = cinfo->image_width; col > 0; col--) { - val = GETJSAMPLE(*src_row++); - *dest_row++ = (JSAMPLE) (colormap[val ] >> 8); - *dest_row++ = (JSAMPLE) (colormap[val + 256] >> 8); - *dest_row++ = (JSAMPLE) (colormap[val + 512] >> 8); - } - - return 1; -} - - -/* - * Load the image into a virtual array. We have to do this because RLE - * files start at the lower left while the JPEG standard has them starting - * in the upper left. This is called the first time we want to get a row - * of input. What we do is load the RLE data into the array and then call - * the appropriate routine to read one row from the array. Before returning, - * we set source->pub.get_pixel_rows so that subsequent calls go straight to - * the appropriate row-reading routine. - */ - -METHODDEF(JDIMENSION) -load_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - rle_source_ptr source = (rle_source_ptr) sinfo; - JDIMENSION row, col; - JSAMPROW scanline, red_ptr, green_ptr, blue_ptr; - rle_pixel **rle_row; - rle_map *colormap; - char channel; -#ifdef PROGRESS_REPORT - cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; -#endif - - colormap = source->header.cmap; - rle_row = source->rle_row; - - /* Read the RLE data into our virtual array. - * We assume here that (a) rle_pixel is represented the same as JSAMPLE, - * and (b) we are not on a machine where FAR pointers differ from regular. - */ - RLE_CLR_BIT(source->header, RLE_ALPHA); /* don't read the alpha channel */ - -#ifdef PROGRESS_REPORT - if (progress != NULL) { - progress->pub.pass_limit = cinfo->image_height; - progress->pub.pass_counter = 0; - (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); - } -#endif - - switch (source->visual) { - - case GRAYSCALE: - case PSEUDOCOLOR: - for (row = 0; row < cinfo->image_height; row++) { - rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE); - rle_getrow(&source->header, rle_row); -#ifdef PROGRESS_REPORT - if (progress != NULL) { - progress->pub.pass_counter++; - (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); - } -#endif - } - break; - - case MAPPEDGRAY: - case TRUECOLOR: - for (row = 0; row < cinfo->image_height; row++) { - scanline = * (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE); - rle_row = source->rle_row; - rle_getrow(&source->header, rle_row); - - for (col = 0; col < cinfo->image_width; col++) { - for (channel = 0; channel < source->header.ncolors; channel++) { - *scanline++ = (JSAMPLE) - (colormap[GETJSAMPLE(rle_row[channel][col]) + 256 * channel] >> 8); - } - } - -#ifdef PROGRESS_REPORT - if (progress != NULL) { - progress->pub.pass_counter++; - (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); - } -#endif - } - break; - - case DIRECTCOLOR: - for (row = 0; row < cinfo->image_height; row++) { - scanline = * (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE); - rle_getrow(&source->header, rle_row); - - red_ptr = rle_row[0]; - green_ptr = rle_row[1]; - blue_ptr = rle_row[2]; - - for (col = cinfo->image_width; col > 0; col--) { - *scanline++ = *red_ptr++; - *scanline++ = *green_ptr++; - *scanline++ = *blue_ptr++; - } - -#ifdef PROGRESS_REPORT - if (progress != NULL) { - progress->pub.pass_counter++; - (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); - } -#endif - } - } - -#ifdef PROGRESS_REPORT - if (progress != NULL) - progress->completed_extra_passes++; -#endif - - /* Set up to call proper row-extraction routine in future */ - if (source->visual == PSEUDOCOLOR) { - source->pub.buffer = source->rle_row; - source->pub.get_pixel_rows = get_pseudocolor_row; - } else { - source->pub.get_pixel_rows = get_rle_row; - } - source->row = cinfo->image_height; - - /* And fetch the topmost (bottommost) row */ - return (*source->pub.get_pixel_rows) (cinfo, sinfo); -} - - -/* - * Finish up at the end of the file. - */ - -METHODDEF(void) -finish_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - /* no work */ -} - - -/* - * The module selection routine for RLE format input. - */ - -GLOBAL(cjpeg_source_ptr) -jinit_read_rle (j_compress_ptr cinfo) -{ - rle_source_ptr source; - - /* Create module interface object */ - source = (rle_source_ptr) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - SIZEOF(rle_source_struct)); - /* Fill in method ptrs */ - source->pub.start_input = start_input_rle; - source->pub.finish_input = finish_input_rle; - source->pub.get_pixel_rows = load_image; - - return (cjpeg_source_ptr) source; -} - -#endif /* RLE_SUPPORTED */ +/* + * rdrle.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to read input images in Utah RLE format. + * The Utah Raster Toolkit library is required (version 3.1 or later). + * + * These routines may need modification for non-Unix environments or + * specialized applications. As they stand, they assume input from + * an ordinary stdio stream. They further assume that reading begins + * at the start of the file; start_input may need work if the + * user interface has already read some data (e.g., to determine that + * the file is indeed RLE format). + * + * Based on code contributed by Mike Lijewski, + * with updates from Robert Hutchinson. + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + +#ifdef RLE_SUPPORTED + +/* rle.h is provided by the Utah Raster Toolkit. */ + +#include + +/* + * We assume that JSAMPLE has the same representation as rle_pixel, + * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples. + */ + +#if BITS_IN_JSAMPLE != 8 + Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ +#endif + +/* + * We support the following types of RLE files: + * + * GRAYSCALE - 8 bits, no colormap + * MAPPEDGRAY - 8 bits, 1 channel colomap + * PSEUDOCOLOR - 8 bits, 3 channel colormap + * TRUECOLOR - 24 bits, 3 channel colormap + * DIRECTCOLOR - 24 bits, no colormap + * + * For now, we ignore any alpha channel in the image. + */ + +typedef enum + { GRAYSCALE, MAPPEDGRAY, PSEUDOCOLOR, TRUECOLOR, DIRECTCOLOR } rle_kind; + + +/* + * Since RLE stores scanlines bottom-to-top, we have to invert the image + * to conform to JPEG's top-to-bottom order. To do this, we read the + * incoming image into a virtual array on the first get_pixel_rows call, + * then fetch the required row from the virtual array on subsequent calls. + */ + +typedef struct _rle_source_struct * rle_source_ptr; + +typedef struct _rle_source_struct { + struct cjpeg_source_struct pub; /* public fields */ + + rle_kind visual; /* actual type of input file */ + jvirt_sarray_ptr image; /* virtual array to hold the image */ + JDIMENSION row; /* current row # in the virtual array */ + rle_hdr header; /* Input file information */ + rle_pixel** rle_row; /* holds a row returned by rle_getrow() */ + +} rle_source_struct; + + +/* + * Read the file header; return image size and component count. + */ + +METHODDEF(void) +start_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +{ + rle_source_ptr source = (rle_source_ptr) sinfo; + JDIMENSION width, height; +#ifdef PROGRESS_REPORT + cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; +#endif + + /* Use RLE library routine to get the header info */ + source->header = *rle_hdr_init(NULL); + source->header.rle_file = source->pub.input_file; + switch (rle_get_setup(&(source->header))) { + case RLE_SUCCESS: + /* A-OK */ + break; + case RLE_NOT_RLE: + ERREXIT(cinfo, JERR_RLE_NOT); + break; + case RLE_NO_SPACE: + ERREXIT(cinfo, JERR_RLE_MEM); + break; + case RLE_EMPTY: + ERREXIT(cinfo, JERR_RLE_EMPTY); + break; + case RLE_EOF: + ERREXIT(cinfo, JERR_RLE_EOF); + break; + default: + ERREXIT(cinfo, JERR_RLE_BADERROR); + break; + } + + /* Figure out what we have, set private vars and return values accordingly */ + + width = source->header.xmax - source->header.xmin + 1; + height = source->header.ymax - source->header.ymin + 1; + source->header.xmin = 0; /* realign horizontally */ + source->header.xmax = width-1; + + cinfo->image_width = width; + cinfo->image_height = height; + cinfo->data_precision = 8; /* we can only handle 8 bit data */ + + if (source->header.ncolors == 1 && source->header.ncmap == 0) { + source->visual = GRAYSCALE; + TRACEMS2(cinfo, 1, JTRC_RLE_GRAY, width, height); + } else if (source->header.ncolors == 1 && source->header.ncmap == 1) { + source->visual = MAPPEDGRAY; + TRACEMS3(cinfo, 1, JTRC_RLE_MAPGRAY, width, height, + 1 << source->header.cmaplen); + } else if (source->header.ncolors == 1 && source->header.ncmap == 3) { + source->visual = PSEUDOCOLOR; + TRACEMS3(cinfo, 1, JTRC_RLE_MAPPED, width, height, + 1 << source->header.cmaplen); + } else if (source->header.ncolors == 3 && source->header.ncmap == 3) { + source->visual = TRUECOLOR; + TRACEMS3(cinfo, 1, JTRC_RLE_FULLMAP, width, height, + 1 << source->header.cmaplen); + } else if (source->header.ncolors == 3 && source->header.ncmap == 0) { + source->visual = DIRECTCOLOR; + TRACEMS2(cinfo, 1, JTRC_RLE, width, height); + } else + ERREXIT(cinfo, JERR_RLE_UNSUPPORTED); + + if (source->visual == GRAYSCALE || source->visual == MAPPEDGRAY) { + cinfo->in_color_space = JCS_GRAYSCALE; + cinfo->input_components = 1; + } else { + cinfo->in_color_space = JCS_RGB; + cinfo->input_components = 3; + } + + /* + * A place to hold each scanline while it's converted. + * (GRAYSCALE scanlines don't need converting) + */ + if (source->visual != GRAYSCALE) { + source->rle_row = (rle_pixel**) (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) width, (JDIMENSION) cinfo->input_components); + } + + /* request a virtual array to hold the image */ + source->image = (*cinfo->mem->request_virt_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, + (JDIMENSION) (width * source->header.ncolors), + (JDIMENSION) height, (JDIMENSION) 1); + +#ifdef PROGRESS_REPORT + if (progress != NULL) { + /* count file input as separate pass */ + progress->total_extra_passes++; + } +#endif + + source->pub.buffer_height = 1; +} + + +/* + * Read one row of pixels. + * Called only after load_image has read the image into the virtual array. + * Used for GRAYSCALE, MAPPEDGRAY, TRUECOLOR, and DIRECTCOLOR images. + */ + +METHODDEF(JDIMENSION) +get_rle_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +{ + rle_source_ptr source = (rle_source_ptr) sinfo; + + source->row--; + source->pub.buffer = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE); + + return 1; +} + +/* + * Read one row of pixels. + * Called only after load_image has read the image into the virtual array. + * Used for PSEUDOCOLOR images. + */ + +METHODDEF(JDIMENSION) +get_pseudocolor_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +{ + rle_source_ptr source = (rle_source_ptr) sinfo; + JSAMPROW src_row, dest_row; + JDIMENSION col; + rle_map *colormap; + int val; + + colormap = source->header.cmap; + dest_row = source->pub.buffer[0]; + source->row--; + src_row = * (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE); + + for (col = cinfo->image_width; col > 0; col--) { + val = GETJSAMPLE(*src_row++); + *dest_row++ = (JSAMPLE) (colormap[val ] >> 8); + *dest_row++ = (JSAMPLE) (colormap[val + 256] >> 8); + *dest_row++ = (JSAMPLE) (colormap[val + 512] >> 8); + } + + return 1; +} + + +/* + * Load the image into a virtual array. We have to do this because RLE + * files start at the lower left while the JPEG standard has them starting + * in the upper left. This is called the first time we want to get a row + * of input. What we do is load the RLE data into the array and then call + * the appropriate routine to read one row from the array. Before returning, + * we set source->pub.get_pixel_rows so that subsequent calls go straight to + * the appropriate row-reading routine. + */ + +METHODDEF(JDIMENSION) +load_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +{ + rle_source_ptr source = (rle_source_ptr) sinfo; + JDIMENSION row, col; + JSAMPROW scanline, red_ptr, green_ptr, blue_ptr; + rle_pixel **rle_row; + rle_map *colormap; + char channel; +#ifdef PROGRESS_REPORT + cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; +#endif + + colormap = source->header.cmap; + rle_row = source->rle_row; + + /* Read the RLE data into our virtual array. + * We assume here that (a) rle_pixel is represented the same as JSAMPLE, + * and (b) we are not on a machine where FAR pointers differ from regular. + */ + RLE_CLR_BIT(source->header, RLE_ALPHA); /* don't read the alpha channel */ + +#ifdef PROGRESS_REPORT + if (progress != NULL) { + progress->pub.pass_limit = cinfo->image_height; + progress->pub.pass_counter = 0; + (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); + } +#endif + + switch (source->visual) { + + case GRAYSCALE: + case PSEUDOCOLOR: + for (row = 0; row < cinfo->image_height; row++) { + rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE); + rle_getrow(&source->header, rle_row); +#ifdef PROGRESS_REPORT + if (progress != NULL) { + progress->pub.pass_counter++; + (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); + } +#endif + } + break; + + case MAPPEDGRAY: + case TRUECOLOR: + for (row = 0; row < cinfo->image_height; row++) { + scanline = * (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE); + rle_row = source->rle_row; + rle_getrow(&source->header, rle_row); + + for (col = 0; col < cinfo->image_width; col++) { + for (channel = 0; channel < source->header.ncolors; channel++) { + *scanline++ = (JSAMPLE) + (colormap[GETJSAMPLE(rle_row[channel][col]) + 256 * channel] >> 8); + } + } + +#ifdef PROGRESS_REPORT + if (progress != NULL) { + progress->pub.pass_counter++; + (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); + } +#endif + } + break; + + case DIRECTCOLOR: + for (row = 0; row < cinfo->image_height; row++) { + scanline = * (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE); + rle_getrow(&source->header, rle_row); + + red_ptr = rle_row[0]; + green_ptr = rle_row[1]; + blue_ptr = rle_row[2]; + + for (col = cinfo->image_width; col > 0; col--) { + *scanline++ = *red_ptr++; + *scanline++ = *green_ptr++; + *scanline++ = *blue_ptr++; + } + +#ifdef PROGRESS_REPORT + if (progress != NULL) { + progress->pub.pass_counter++; + (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); + } +#endif + } + } + +#ifdef PROGRESS_REPORT + if (progress != NULL) + progress->completed_extra_passes++; +#endif + + /* Set up to call proper row-extraction routine in future */ + if (source->visual == PSEUDOCOLOR) { + source->pub.buffer = source->rle_row; + source->pub.get_pixel_rows = get_pseudocolor_row; + } else { + source->pub.get_pixel_rows = get_rle_row; + } + source->row = cinfo->image_height; + + /* And fetch the topmost (bottommost) row */ + return (*source->pub.get_pixel_rows) (cinfo, sinfo); +} + + +/* + * Finish up at the end of the file. + */ + +METHODDEF(void) +finish_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +{ + /* no work */ +} + + +/* + * The module selection routine for RLE format input. + */ + +GLOBAL(cjpeg_source_ptr) +jinit_read_rle (j_compress_ptr cinfo) +{ + rle_source_ptr source; + + /* Create module interface object */ + source = (rle_source_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(rle_source_struct)); + /* Fill in method ptrs */ + source->pub.start_input = start_input_rle; + source->pub.finish_input = finish_input_rle; + source->pub.get_pixel_rows = load_image; + + return (cjpeg_source_ptr) source; +} + +#endif /* RLE_SUPPORTED */ diff --git a/Source/LibJPEG/rdswitch.c b/Source/LibJPEG/rdswitch.c index 5eebcc1..7a839af 100644 --- a/Source/LibJPEG/rdswitch.c +++ b/Source/LibJPEG/rdswitch.c @@ -1,365 +1,365 @@ -/* - * rdswitch.c - * - * Copyright (C) 1991-1996, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains routines to process some of cjpeg's more complicated - * command-line switches. Switches processed here are: - * -qtables file Read quantization tables from text file - * -scans file Read scan script from text file - * -quality N[,N,...] Set quality ratings - * -qslots N[,N,...] Set component quantization table selectors - * -sample HxV[,HxV,...] Set component sampling factors - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ -#include /* to declare isdigit(), isspace() */ - - -LOCAL(int) -text_getc (FILE * file) -/* Read next char, skipping over any comments (# to end of line) */ -/* A comment/newline sequence is returned as a newline */ -{ - register int ch; - - ch = getc(file); - if (ch == '#') { - do { - ch = getc(file); - } while (ch != '\n' && ch != EOF); - } - return ch; -} - - -LOCAL(boolean) -read_text_integer (FILE * file, long * result, int * termchar) -/* Read an unsigned decimal integer from a file, store it in result */ -/* Reads one trailing character after the integer; returns it in termchar */ -{ - register int ch; - register long val; - - /* Skip any leading whitespace, detect EOF */ - do { - ch = text_getc(file); - if (ch == EOF) { - *termchar = ch; - return FALSE; - } - } while (isspace(ch)); - - if (! isdigit(ch)) { - *termchar = ch; - return FALSE; - } - - val = ch - '0'; - while ((ch = text_getc(file)) != EOF) { - if (! isdigit(ch)) - break; - val *= 10; - val += ch - '0'; - } - *result = val; - *termchar = ch; - return TRUE; -} - - -GLOBAL(boolean) -read_quant_tables (j_compress_ptr cinfo, char * filename, boolean force_baseline) -/* Read a set of quantization tables from the specified file. - * The file is plain ASCII text: decimal numbers with whitespace between. - * Comments preceded by '#' may be included in the file. - * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values. - * The tables are implicitly numbered 0,1,etc. - * NOTE: does not affect the qslots mapping, which will default to selecting - * table 0 for luminance (or primary) components, 1 for chrominance components. - * You must use -qslots if you want a different component->table mapping. - */ -{ - FILE * fp; - int tblno, i, termchar; - long val; - unsigned int table[DCTSIZE2]; - - if ((fp = fopen(filename, "r")) == NULL) { - fprintf(stderr, "Can't open table file %s\n", filename); - return FALSE; - } - tblno = 0; - - while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */ - if (tblno >= NUM_QUANT_TBLS) { - fprintf(stderr, "Too many tables in file %s\n", filename); - fclose(fp); - return FALSE; - } - table[0] = (unsigned int) val; - for (i = 1; i < DCTSIZE2; i++) { - if (! read_text_integer(fp, &val, &termchar)) { - fprintf(stderr, "Invalid table data in file %s\n", filename); - fclose(fp); - return FALSE; - } - table[i] = (unsigned int) val; - } - jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno], - force_baseline); - tblno++; - } - - if (termchar != EOF) { - fprintf(stderr, "Non-numeric data in file %s\n", filename); - fclose(fp); - return FALSE; - } - - fclose(fp); - return TRUE; -} - - -#ifdef C_MULTISCAN_FILES_SUPPORTED - -LOCAL(boolean) -read_scan_integer (FILE * file, long * result, int * termchar) -/* Variant of read_text_integer that always looks for a non-space termchar; - * this simplifies parsing of punctuation in scan scripts. - */ -{ - register int ch; - - if (! read_text_integer(file, result, termchar)) - return FALSE; - ch = *termchar; - while (ch != EOF && isspace(ch)) - ch = text_getc(file); - if (isdigit(ch)) { /* oops, put it back */ - if (ungetc(ch, file) == EOF) - return FALSE; - ch = ' '; - } else { - /* Any separators other than ';' and ':' are ignored; - * this allows user to insert commas, etc, if desired. - */ - if (ch != EOF && ch != ';' && ch != ':') - ch = ' '; - } - *termchar = ch; - return TRUE; -} - - -GLOBAL(boolean) -read_scan_script (j_compress_ptr cinfo, char * filename) -/* Read a scan script from the specified text file. - * Each entry in the file defines one scan to be emitted. - * Entries are separated by semicolons ';'. - * An entry contains one to four component indexes, - * optionally followed by a colon ':' and four progressive-JPEG parameters. - * The component indexes denote which component(s) are to be transmitted - * in the current scan. The first component has index 0. - * Sequential JPEG is used if the progressive-JPEG parameters are omitted. - * The file is free format text: any whitespace may appear between numbers - * and the ':' and ';' punctuation marks. Also, other punctuation (such - * as commas or dashes) can be placed between numbers if desired. - * Comments preceded by '#' may be included in the file. - * Note: we do very little validity checking here; - * jcmaster.c will validate the script parameters. - */ -{ - FILE * fp; - int scanno, ncomps, termchar; - long val; - jpeg_scan_info * scanptr; -#define MAX_SCANS 100 /* quite arbitrary limit */ - jpeg_scan_info scans[MAX_SCANS]; - - if ((fp = fopen(filename, "r")) == NULL) { - fprintf(stderr, "Can't open scan definition file %s\n", filename); - return FALSE; - } - scanptr = scans; - scanno = 0; - - while (read_scan_integer(fp, &val, &termchar)) { - if (scanno >= MAX_SCANS) { - fprintf(stderr, "Too many scans defined in file %s\n", filename); - fclose(fp); - return FALSE; - } - scanptr->component_index[0] = (int) val; - ncomps = 1; - while (termchar == ' ') { - if (ncomps >= MAX_COMPS_IN_SCAN) { - fprintf(stderr, "Too many components in one scan in file %s\n", - filename); - fclose(fp); - return FALSE; - } - if (! read_scan_integer(fp, &val, &termchar)) - goto bogus; - scanptr->component_index[ncomps] = (int) val; - ncomps++; - } - scanptr->comps_in_scan = ncomps; - if (termchar == ':') { - if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') - goto bogus; - scanptr->Ss = (int) val; - if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') - goto bogus; - scanptr->Se = (int) val; - if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') - goto bogus; - scanptr->Ah = (int) val; - if (! read_scan_integer(fp, &val, &termchar)) - goto bogus; - scanptr->Al = (int) val; - } else { - /* set non-progressive parameters */ - scanptr->Ss = 0; - scanptr->Se = DCTSIZE2-1; - scanptr->Ah = 0; - scanptr->Al = 0; - } - if (termchar != ';' && termchar != EOF) { -bogus: - fprintf(stderr, "Invalid scan entry format in file %s\n", filename); - fclose(fp); - return FALSE; - } - scanptr++, scanno++; - } - - if (termchar != EOF) { - fprintf(stderr, "Non-numeric data in file %s\n", filename); - fclose(fp); - return FALSE; - } - - if (scanno > 0) { - /* Stash completed scan list in cinfo structure. - * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data, - * but if you want to compress multiple images you'd want JPOOL_PERMANENT. - */ - scanptr = (jpeg_scan_info *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - scanno * SIZEOF(jpeg_scan_info)); - MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info)); - cinfo->scan_info = scanptr; - cinfo->num_scans = scanno; - } - - fclose(fp); - return TRUE; -} - -#endif /* C_MULTISCAN_FILES_SUPPORTED */ - - -GLOBAL(boolean) -set_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline) -/* Process a quality-ratings parameter string, of the form - * N[,N,...] - * If there are more q-table slots than parameters, the last value is replicated. - */ -{ - int val = 75; /* default value */ - int tblno; - char ch; - - for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { - if (*arg) { - ch = ','; /* if not set by sscanf, will be ',' */ - if (sscanf(arg, "%d%c", &val, &ch) < 1) - return FALSE; - if (ch != ',') /* syntax check */ - return FALSE; - /* Convert user 0-100 rating to percentage scaling */ - cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); - while (*arg && *arg++ != ',') /* advance to next segment of arg string */ - ; - } else { - /* reached end of parameter, set remaining factors to last value */ - cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); - } - } - jpeg_default_qtables(cinfo, force_baseline); - return TRUE; -} - - -GLOBAL(boolean) -set_quant_slots (j_compress_ptr cinfo, char *arg) -/* Process a quantization-table-selectors parameter string, of the form - * N[,N,...] - * If there are more components than parameters, the last value is replicated. - */ -{ - int val = 0; /* default table # */ - int ci; - char ch; - - for (ci = 0; ci < MAX_COMPONENTS; ci++) { - if (*arg) { - ch = ','; /* if not set by sscanf, will be ',' */ - if (sscanf(arg, "%d%c", &val, &ch) < 1) - return FALSE; - if (ch != ',') /* syntax check */ - return FALSE; - if (val < 0 || val >= NUM_QUANT_TBLS) { - fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n", - NUM_QUANT_TBLS-1); - return FALSE; - } - cinfo->comp_info[ci].quant_tbl_no = val; - while (*arg && *arg++ != ',') /* advance to next segment of arg string */ - ; - } else { - /* reached end of parameter, set remaining components to last table */ - cinfo->comp_info[ci].quant_tbl_no = val; - } - } - return TRUE; -} - - -GLOBAL(boolean) -set_sample_factors (j_compress_ptr cinfo, char *arg) -/* Process a sample-factors parameter string, of the form - * HxV[,HxV,...] - * If there are more components than parameters, "1x1" is assumed for the rest. - */ -{ - int ci, val1, val2; - char ch1, ch2; - - for (ci = 0; ci < MAX_COMPONENTS; ci++) { - if (*arg) { - ch2 = ','; /* if not set by sscanf, will be ',' */ - if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3) - return FALSE; - if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */ - return FALSE; - if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) { - fprintf(stderr, "JPEG sampling factors must be 1..4\n"); - return FALSE; - } - cinfo->comp_info[ci].h_samp_factor = val1; - cinfo->comp_info[ci].v_samp_factor = val2; - while (*arg && *arg++ != ',') /* advance to next segment of arg string */ - ; - } else { - /* reached end of parameter, set remaining components to 1x1 sampling */ - cinfo->comp_info[ci].h_samp_factor = 1; - cinfo->comp_info[ci].v_samp_factor = 1; - } - } - return TRUE; -} +/* + * rdswitch.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to process some of cjpeg's more complicated + * command-line switches. Switches processed here are: + * -qtables file Read quantization tables from text file + * -scans file Read scan script from text file + * -quality N[,N,...] Set quality ratings + * -qslots N[,N,...] Set component quantization table selectors + * -sample HxV[,HxV,...] Set component sampling factors + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ +#include /* to declare isdigit(), isspace() */ + + +LOCAL(int) +text_getc (FILE * file) +/* Read next char, skipping over any comments (# to end of line) */ +/* A comment/newline sequence is returned as a newline */ +{ + register int ch; + + ch = getc(file); + if (ch == '#') { + do { + ch = getc(file); + } while (ch != '\n' && ch != EOF); + } + return ch; +} + + +LOCAL(boolean) +read_text_integer (FILE * file, long * result, int * termchar) +/* Read an unsigned decimal integer from a file, store it in result */ +/* Reads one trailing character after the integer; returns it in termchar */ +{ + register int ch; + register long val; + + /* Skip any leading whitespace, detect EOF */ + do { + ch = text_getc(file); + if (ch == EOF) { + *termchar = ch; + return FALSE; + } + } while (isspace(ch)); + + if (! isdigit(ch)) { + *termchar = ch; + return FALSE; + } + + val = ch - '0'; + while ((ch = text_getc(file)) != EOF) { + if (! isdigit(ch)) + break; + val *= 10; + val += ch - '0'; + } + *result = val; + *termchar = ch; + return TRUE; +} + + +GLOBAL(boolean) +read_quant_tables (j_compress_ptr cinfo, char * filename, boolean force_baseline) +/* Read a set of quantization tables from the specified file. + * The file is plain ASCII text: decimal numbers with whitespace between. + * Comments preceded by '#' may be included in the file. + * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values. + * The tables are implicitly numbered 0,1,etc. + * NOTE: does not affect the qslots mapping, which will default to selecting + * table 0 for luminance (or primary) components, 1 for chrominance components. + * You must use -qslots if you want a different component->table mapping. + */ +{ + FILE * fp; + int tblno, i, termchar; + long val; + unsigned int table[DCTSIZE2]; + + if ((fp = fopen(filename, "r")) == NULL) { + fprintf(stderr, "Can't open table file %s\n", filename); + return FALSE; + } + tblno = 0; + + while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */ + if (tblno >= NUM_QUANT_TBLS) { + fprintf(stderr, "Too many tables in file %s\n", filename); + fclose(fp); + return FALSE; + } + table[0] = (unsigned int) val; + for (i = 1; i < DCTSIZE2; i++) { + if (! read_text_integer(fp, &val, &termchar)) { + fprintf(stderr, "Invalid table data in file %s\n", filename); + fclose(fp); + return FALSE; + } + table[i] = (unsigned int) val; + } + jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno], + force_baseline); + tblno++; + } + + if (termchar != EOF) { + fprintf(stderr, "Non-numeric data in file %s\n", filename); + fclose(fp); + return FALSE; + } + + fclose(fp); + return TRUE; +} + + +#ifdef C_MULTISCAN_FILES_SUPPORTED + +LOCAL(boolean) +read_scan_integer (FILE * file, long * result, int * termchar) +/* Variant of read_text_integer that always looks for a non-space termchar; + * this simplifies parsing of punctuation in scan scripts. + */ +{ + register int ch; + + if (! read_text_integer(file, result, termchar)) + return FALSE; + ch = *termchar; + while (ch != EOF && isspace(ch)) + ch = text_getc(file); + if (isdigit(ch)) { /* oops, put it back */ + if (ungetc(ch, file) == EOF) + return FALSE; + ch = ' '; + } else { + /* Any separators other than ';' and ':' are ignored; + * this allows user to insert commas, etc, if desired. + */ + if (ch != EOF && ch != ';' && ch != ':') + ch = ' '; + } + *termchar = ch; + return TRUE; +} + + +GLOBAL(boolean) +read_scan_script (j_compress_ptr cinfo, char * filename) +/* Read a scan script from the specified text file. + * Each entry in the file defines one scan to be emitted. + * Entries are separated by semicolons ';'. + * An entry contains one to four component indexes, + * optionally followed by a colon ':' and four progressive-JPEG parameters. + * The component indexes denote which component(s) are to be transmitted + * in the current scan. The first component has index 0. + * Sequential JPEG is used if the progressive-JPEG parameters are omitted. + * The file is free format text: any whitespace may appear between numbers + * and the ':' and ';' punctuation marks. Also, other punctuation (such + * as commas or dashes) can be placed between numbers if desired. + * Comments preceded by '#' may be included in the file. + * Note: we do very little validity checking here; + * jcmaster.c will validate the script parameters. + */ +{ + FILE * fp; + int scanno, ncomps, termchar; + long val; + jpeg_scan_info * scanptr; +#define MAX_SCANS 100 /* quite arbitrary limit */ + jpeg_scan_info scans[MAX_SCANS]; + + if ((fp = fopen(filename, "r")) == NULL) { + fprintf(stderr, "Can't open scan definition file %s\n", filename); + return FALSE; + } + scanptr = scans; + scanno = 0; + + while (read_scan_integer(fp, &val, &termchar)) { + if (scanno >= MAX_SCANS) { + fprintf(stderr, "Too many scans defined in file %s\n", filename); + fclose(fp); + return FALSE; + } + scanptr->component_index[0] = (int) val; + ncomps = 1; + while (termchar == ' ') { + if (ncomps >= MAX_COMPS_IN_SCAN) { + fprintf(stderr, "Too many components in one scan in file %s\n", + filename); + fclose(fp); + return FALSE; + } + if (! read_scan_integer(fp, &val, &termchar)) + goto bogus; + scanptr->component_index[ncomps] = (int) val; + ncomps++; + } + scanptr->comps_in_scan = ncomps; + if (termchar == ':') { + if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') + goto bogus; + scanptr->Ss = (int) val; + if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') + goto bogus; + scanptr->Se = (int) val; + if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') + goto bogus; + scanptr->Ah = (int) val; + if (! read_scan_integer(fp, &val, &termchar)) + goto bogus; + scanptr->Al = (int) val; + } else { + /* set non-progressive parameters */ + scanptr->Ss = 0; + scanptr->Se = DCTSIZE2-1; + scanptr->Ah = 0; + scanptr->Al = 0; + } + if (termchar != ';' && termchar != EOF) { +bogus: + fprintf(stderr, "Invalid scan entry format in file %s\n", filename); + fclose(fp); + return FALSE; + } + scanptr++, scanno++; + } + + if (termchar != EOF) { + fprintf(stderr, "Non-numeric data in file %s\n", filename); + fclose(fp); + return FALSE; + } + + if (scanno > 0) { + /* Stash completed scan list in cinfo structure. + * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data, + * but if you want to compress multiple images you'd want JPOOL_PERMANENT. + */ + scanptr = (jpeg_scan_info *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + scanno * SIZEOF(jpeg_scan_info)); + MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info)); + cinfo->scan_info = scanptr; + cinfo->num_scans = scanno; + } + + fclose(fp); + return TRUE; +} + +#endif /* C_MULTISCAN_FILES_SUPPORTED */ + + +GLOBAL(boolean) +set_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline) +/* Process a quality-ratings parameter string, of the form + * N[,N,...] + * If there are more q-table slots than parameters, the last value is replicated. + */ +{ + int val = 75; /* default value */ + int tblno; + char ch; + + for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { + if (*arg) { + ch = ','; /* if not set by sscanf, will be ',' */ + if (sscanf(arg, "%d%c", &val, &ch) < 1) + return FALSE; + if (ch != ',') /* syntax check */ + return FALSE; + /* Convert user 0-100 rating to percentage scaling */ + cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); + while (*arg && *arg++ != ',') /* advance to next segment of arg string */ + ; + } else { + /* reached end of parameter, set remaining factors to last value */ + cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); + } + } + jpeg_default_qtables(cinfo, force_baseline); + return TRUE; +} + + +GLOBAL(boolean) +set_quant_slots (j_compress_ptr cinfo, char *arg) +/* Process a quantization-table-selectors parameter string, of the form + * N[,N,...] + * If there are more components than parameters, the last value is replicated. + */ +{ + int val = 0; /* default table # */ + int ci; + char ch; + + for (ci = 0; ci < MAX_COMPONENTS; ci++) { + if (*arg) { + ch = ','; /* if not set by sscanf, will be ',' */ + if (sscanf(arg, "%d%c", &val, &ch) < 1) + return FALSE; + if (ch != ',') /* syntax check */ + return FALSE; + if (val < 0 || val >= NUM_QUANT_TBLS) { + fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n", + NUM_QUANT_TBLS-1); + return FALSE; + } + cinfo->comp_info[ci].quant_tbl_no = val; + while (*arg && *arg++ != ',') /* advance to next segment of arg string */ + ; + } else { + /* reached end of parameter, set remaining components to last table */ + cinfo->comp_info[ci].quant_tbl_no = val; + } + } + return TRUE; +} + + +GLOBAL(boolean) +set_sample_factors (j_compress_ptr cinfo, char *arg) +/* Process a sample-factors parameter string, of the form + * HxV[,HxV,...] + * If there are more components than parameters, "1x1" is assumed for the rest. + */ +{ + int ci, val1, val2; + char ch1, ch2; + + for (ci = 0; ci < MAX_COMPONENTS; ci++) { + if (*arg) { + ch2 = ','; /* if not set by sscanf, will be ',' */ + if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3) + return FALSE; + if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */ + return FALSE; + if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) { + fprintf(stderr, "JPEG sampling factors must be 1..4\n"); + return FALSE; + } + cinfo->comp_info[ci].h_samp_factor = val1; + cinfo->comp_info[ci].v_samp_factor = val2; + while (*arg && *arg++ != ',') /* advance to next segment of arg string */ + ; + } else { + /* reached end of parameter, set remaining components to 1x1 sampling */ + cinfo->comp_info[ci].h_samp_factor = 1; + cinfo->comp_info[ci].v_samp_factor = 1; + } + } + return TRUE; +} diff --git a/Source/LibJPEG/rdtarga.c b/Source/LibJPEG/rdtarga.c index d7ffc33..4c2cd26 100644 --- a/Source/LibJPEG/rdtarga.c +++ b/Source/LibJPEG/rdtarga.c @@ -1,500 +1,500 @@ -/* - * rdtarga.c - * - * Copyright (C) 1991-1996, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains routines to read input images in Targa format. - * - * These routines may need modification for non-Unix environments or - * specialized applications. As they stand, they assume input from - * an ordinary stdio stream. They further assume that reading begins - * at the start of the file; start_input may need work if the - * user interface has already read some data (e.g., to determine that - * the file is indeed Targa format). - * - * Based on code contributed by Lee Daniel Crocker. - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ - -#ifdef TARGA_SUPPORTED - - -/* Macros to deal with unsigned chars as efficiently as compiler allows */ - -#ifdef HAVE_UNSIGNED_CHAR -typedef unsigned char U_CHAR; -#define UCH(x) ((int) (x)) -#else /* !HAVE_UNSIGNED_CHAR */ -#ifdef CHAR_IS_UNSIGNED -typedef char U_CHAR; -#define UCH(x) ((int) (x)) -#else -typedef char U_CHAR; -#define UCH(x) ((int) (x) & 0xFF) -#endif -#endif /* HAVE_UNSIGNED_CHAR */ - - -#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) - - -/* Private version of data source object */ - -typedef struct _tga_source_struct * tga_source_ptr; - -typedef struct _tga_source_struct { - struct cjpeg_source_struct pub; /* public fields */ - - j_compress_ptr cinfo; /* back link saves passing separate parm */ - - JSAMPARRAY colormap; /* Targa colormap (converted to my format) */ - - jvirt_sarray_ptr whole_image; /* Needed if funny input row order */ - JDIMENSION current_row; /* Current logical row number to read */ - - /* Pointer to routine to extract next Targa pixel from input file */ - JMETHOD(void, read_pixel, (tga_source_ptr sinfo)); - - /* Result of read_pixel is delivered here: */ - U_CHAR tga_pixel[4]; - - int pixel_size; /* Bytes per Targa pixel (1 to 4) */ - - /* State info for reading RLE-coded pixels; both counts must be init to 0 */ - int block_count; /* # of pixels remaining in RLE block */ - int dup_pixel_count; /* # of times to duplicate previous pixel */ - - /* This saves the correct pixel-row-expansion method for preload_image */ - JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo, - cjpeg_source_ptr sinfo)); -} tga_source_struct; - - -/* For expanding 5-bit pixel values to 8-bit with best rounding */ - -static const UINT8 c5to8bits[32] = { - 0, 8, 16, 25, 33, 41, 49, 58, - 66, 74, 82, 90, 99, 107, 115, 123, - 132, 140, 148, 156, 165, 173, 181, 189, - 197, 206, 214, 222, 230, 239, 247, 255 -}; - - - -LOCAL(int) -read_byte (tga_source_ptr sinfo) -/* Read next byte from Targa file */ -{ - register FILE *infile = sinfo->pub.input_file; - register int c; - - if ((c = getc(infile)) == EOF) - ERREXIT(sinfo->cinfo, JERR_INPUT_EOF); - return c; -} - - -LOCAL(void) -read_colormap (tga_source_ptr sinfo, int cmaplen, int mapentrysize) -/* Read the colormap from a Targa file */ -{ - int i; - - /* Presently only handles 24-bit BGR format */ - if (mapentrysize != 24) - ERREXIT(sinfo->cinfo, JERR_TGA_BADCMAP); - - for (i = 0; i < cmaplen; i++) { - sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo); - sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo); - sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo); - } -} - - -/* - * read_pixel methods: get a single pixel from Targa file into tga_pixel[] - */ - -METHODDEF(void) -read_non_rle_pixel (tga_source_ptr sinfo) -/* Read one Targa pixel from the input file; no RLE expansion */ -{ - register FILE *infile = sinfo->pub.input_file; - register int i; - - for (i = 0; i < sinfo->pixel_size; i++) { - sinfo->tga_pixel[i] = (U_CHAR) getc(infile); - } -} - - -METHODDEF(void) -read_rle_pixel (tga_source_ptr sinfo) -/* Read one Targa pixel from the input file, expanding RLE data as needed */ -{ - register FILE *infile = sinfo->pub.input_file; - register int i; - - /* Duplicate previously read pixel? */ - if (sinfo->dup_pixel_count > 0) { - sinfo->dup_pixel_count--; - return; - } - - /* Time to read RLE block header? */ - if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */ - i = read_byte(sinfo); - if (i & 0x80) { /* Start of duplicate-pixel block? */ - sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */ - sinfo->block_count = 0; /* then read new block header */ - } else { - sinfo->block_count = i & 0x7F; /* number of pixels after this one */ - } - } - - /* Read next pixel */ - for (i = 0; i < sinfo->pixel_size; i++) { - sinfo->tga_pixel[i] = (U_CHAR) getc(infile); - } -} - - -/* - * Read one row of pixels. - * - * We provide several different versions depending on input file format. - */ - - -METHODDEF(JDIMENSION) -get_8bit_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading 8-bit grayscale pixels */ -{ - tga_source_ptr source = (tga_source_ptr) sinfo; - register JSAMPROW ptr; - register JDIMENSION col; - - ptr = source->pub.buffer[0]; - for (col = cinfo->image_width; col > 0; col--) { - (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ - *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]); - } - return 1; -} - -METHODDEF(JDIMENSION) -get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading 8-bit colormap indexes */ -{ - tga_source_ptr source = (tga_source_ptr) sinfo; - register int t; - register JSAMPROW ptr; - register JDIMENSION col; - register JSAMPARRAY colormap = source->colormap; - - ptr = source->pub.buffer[0]; - for (col = cinfo->image_width; col > 0; col--) { - (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ - t = UCH(source->tga_pixel[0]); - *ptr++ = colormap[0][t]; - *ptr++ = colormap[1][t]; - *ptr++ = colormap[2][t]; - } - return 1; -} - -METHODDEF(JDIMENSION) -get_16bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading 16-bit pixels */ -{ - tga_source_ptr source = (tga_source_ptr) sinfo; - register int t; - register JSAMPROW ptr; - register JDIMENSION col; - - ptr = source->pub.buffer[0]; - for (col = cinfo->image_width; col > 0; col--) { - (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ - t = UCH(source->tga_pixel[0]); - t += UCH(source->tga_pixel[1]) << 8; - /* We expand 5 bit data to 8 bit sample width. - * The format of the 16-bit (LSB first) input word is - * xRRRRRGGGGGBBBBB - */ - ptr[2] = (JSAMPLE) c5to8bits[t & 0x1F]; - t >>= 5; - ptr[1] = (JSAMPLE) c5to8bits[t & 0x1F]; - t >>= 5; - ptr[0] = (JSAMPLE) c5to8bits[t & 0x1F]; - ptr += 3; - } - return 1; -} - -METHODDEF(JDIMENSION) -get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading 24-bit pixels */ -{ - tga_source_ptr source = (tga_source_ptr) sinfo; - register JSAMPROW ptr; - register JDIMENSION col; - - ptr = source->pub.buffer[0]; - for (col = cinfo->image_width; col > 0; col--) { - (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ - *ptr++ = (JSAMPLE) UCH(source->tga_pixel[2]); /* change BGR to RGB order */ - *ptr++ = (JSAMPLE) UCH(source->tga_pixel[1]); - *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]); - } - return 1; -} - -/* - * Targa also defines a 32-bit pixel format with order B,G,R,A. - * We presently ignore the attribute byte, so the code for reading - * these pixels is identical to the 24-bit routine above. - * This works because the actual pixel length is only known to read_pixel. - */ - -#define get_32bit_row get_24bit_row - - -/* - * This method is for re-reading the input data in standard top-down - * row order. The entire image has already been read into whole_image - * with proper conversion of pixel format, but it's in a funny row order. - */ - -METHODDEF(JDIMENSION) -get_memory_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - tga_source_ptr source = (tga_source_ptr) sinfo; - JDIMENSION source_row; - - /* Compute row of source that maps to current_row of normal order */ - /* For now, assume image is bottom-up and not interlaced. */ - /* NEEDS WORK to support interlaced images! */ - source_row = cinfo->image_height - source->current_row - 1; - - /* Fetch that row from virtual array */ - source->pub.buffer = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->whole_image, - source_row, (JDIMENSION) 1, FALSE); - - source->current_row++; - return 1; -} - - -/* - * This method loads the image into whole_image during the first call on - * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call - * get_memory_row on subsequent calls. - */ - -METHODDEF(JDIMENSION) -preload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - tga_source_ptr source = (tga_source_ptr) sinfo; - JDIMENSION row; - cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; - - /* Read the data into a virtual array in input-file row order. */ - for (row = 0; row < cinfo->image_height; row++) { - if (progress != NULL) { - progress->pub.pass_counter = (long) row; - progress->pub.pass_limit = (long) cinfo->image_height; - (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); - } - source->pub.buffer = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->whole_image, row, (JDIMENSION) 1, TRUE); - (*source->get_pixel_rows) (cinfo, sinfo); - } - if (progress != NULL) - progress->completed_extra_passes++; - - /* Set up to read from the virtual array in unscrambled order */ - source->pub.get_pixel_rows = get_memory_row; - source->current_row = 0; - /* And read the first row */ - return get_memory_row(cinfo, sinfo); -} - - -/* - * Read the file header; return image size and component count. - */ - -METHODDEF(void) -start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - tga_source_ptr source = (tga_source_ptr) sinfo; - U_CHAR targaheader[18]; - int idlen, cmaptype, subtype, flags, interlace_type, components; - unsigned int width, height, maplen; - boolean is_bottom_up; - -#define GET_2B(offset) ((unsigned int) UCH(targaheader[offset]) + \ - (((unsigned int) UCH(targaheader[offset+1])) << 8)) - - if (! ReadOK(source->pub.input_file, targaheader, 18)) - ERREXIT(cinfo, JERR_INPUT_EOF); - - /* Pretend "15-bit" pixels are 16-bit --- we ignore attribute bit anyway */ - if (targaheader[16] == 15) - targaheader[16] = 16; - - idlen = UCH(targaheader[0]); - cmaptype = UCH(targaheader[1]); - subtype = UCH(targaheader[2]); - maplen = GET_2B(5); - width = GET_2B(12); - height = GET_2B(14); - source->pixel_size = UCH(targaheader[16]) >> 3; - flags = UCH(targaheader[17]); /* Image Descriptor byte */ - - is_bottom_up = ((flags & 0x20) == 0); /* bit 5 set => top-down */ - interlace_type = flags >> 6; /* bits 6/7 are interlace code */ - - if (cmaptype > 1 || /* cmaptype must be 0 or 1 */ - source->pixel_size < 1 || source->pixel_size > 4 || - (UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */ - interlace_type != 0) /* currently don't allow interlaced image */ - ERREXIT(cinfo, JERR_TGA_BADPARMS); - - if (subtype > 8) { - /* It's an RLE-coded file */ - source->read_pixel = read_rle_pixel; - source->block_count = source->dup_pixel_count = 0; - subtype -= 8; - } else { - /* Non-RLE file */ - source->read_pixel = read_non_rle_pixel; - } - - /* Now should have subtype 1, 2, or 3 */ - components = 3; /* until proven different */ - cinfo->in_color_space = JCS_RGB; - - switch (subtype) { - case 1: /* Colormapped image */ - if (source->pixel_size == 1 && cmaptype == 1) - source->get_pixel_rows = get_8bit_row; - else - ERREXIT(cinfo, JERR_TGA_BADPARMS); - TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height); - break; - case 2: /* RGB image */ - switch (source->pixel_size) { - case 2: - source->get_pixel_rows = get_16bit_row; - break; - case 3: - source->get_pixel_rows = get_24bit_row; - break; - case 4: - source->get_pixel_rows = get_32bit_row; - break; - default: - ERREXIT(cinfo, JERR_TGA_BADPARMS); - break; - } - TRACEMS2(cinfo, 1, JTRC_TGA, width, height); - break; - case 3: /* Grayscale image */ - components = 1; - cinfo->in_color_space = JCS_GRAYSCALE; - if (source->pixel_size == 1) - source->get_pixel_rows = get_8bit_gray_row; - else - ERREXIT(cinfo, JERR_TGA_BADPARMS); - TRACEMS2(cinfo, 1, JTRC_TGA_GRAY, width, height); - break; - default: - ERREXIT(cinfo, JERR_TGA_BADPARMS); - break; - } - - if (is_bottom_up) { - /* Create a virtual array to buffer the upside-down image. */ - source->whole_image = (*cinfo->mem->request_virt_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, - (JDIMENSION) width * components, (JDIMENSION) height, (JDIMENSION) 1); - if (cinfo->progress != NULL) { - cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; - progress->total_extra_passes++; /* count file input as separate pass */ - } - /* source->pub.buffer will point to the virtual array. */ - source->pub.buffer_height = 1; /* in case anyone looks at it */ - source->pub.get_pixel_rows = preload_image; - } else { - /* Don't need a virtual array, but do need a one-row input buffer. */ - source->whole_image = NULL; - source->pub.buffer = (*cinfo->mem->alloc_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, - (JDIMENSION) width * components, (JDIMENSION) 1); - source->pub.buffer_height = 1; - source->pub.get_pixel_rows = source->get_pixel_rows; - } - - while (idlen--) /* Throw away ID field */ - (void) read_byte(source); - - if (maplen > 0) { - if (maplen > 256 || GET_2B(3) != 0) - ERREXIT(cinfo, JERR_TGA_BADCMAP); - /* Allocate space to store the colormap */ - source->colormap = (*cinfo->mem->alloc_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, (JDIMENSION) maplen, (JDIMENSION) 3); - /* and read it from the file */ - read_colormap(source, (int) maplen, UCH(targaheader[7])); - } else { - if (cmaptype) /* but you promised a cmap! */ - ERREXIT(cinfo, JERR_TGA_BADPARMS); - source->colormap = NULL; - } - - cinfo->input_components = components; - cinfo->data_precision = 8; - cinfo->image_width = width; - cinfo->image_height = height; -} - - -/* - * Finish up at the end of the file. - */ - -METHODDEF(void) -finish_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - /* no work */ -} - - -/* - * The module selection routine for Targa format input. - */ - -GLOBAL(cjpeg_source_ptr) -jinit_read_targa (j_compress_ptr cinfo) -{ - tga_source_ptr source; - - /* Create module interface object */ - source = (tga_source_ptr) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - SIZEOF(tga_source_struct)); - source->cinfo = cinfo; /* make back link for subroutines */ - /* Fill in method ptrs, except get_pixel_rows which start_input sets */ - source->pub.start_input = start_input_tga; - source->pub.finish_input = finish_input_tga; - - return (cjpeg_source_ptr) source; -} - -#endif /* TARGA_SUPPORTED */ +/* + * rdtarga.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to read input images in Targa format. + * + * These routines may need modification for non-Unix environments or + * specialized applications. As they stand, they assume input from + * an ordinary stdio stream. They further assume that reading begins + * at the start of the file; start_input may need work if the + * user interface has already read some data (e.g., to determine that + * the file is indeed Targa format). + * + * Based on code contributed by Lee Daniel Crocker. + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + +#ifdef TARGA_SUPPORTED + + +/* Macros to deal with unsigned chars as efficiently as compiler allows */ + +#ifdef HAVE_UNSIGNED_CHAR +typedef unsigned char U_CHAR; +#define UCH(x) ((int) (x)) +#else /* !HAVE_UNSIGNED_CHAR */ +#ifdef CHAR_IS_UNSIGNED +typedef char U_CHAR; +#define UCH(x) ((int) (x)) +#else +typedef char U_CHAR; +#define UCH(x) ((int) (x) & 0xFF) +#endif +#endif /* HAVE_UNSIGNED_CHAR */ + + +#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) + + +/* Private version of data source object */ + +typedef struct _tga_source_struct * tga_source_ptr; + +typedef struct _tga_source_struct { + struct cjpeg_source_struct pub; /* public fields */ + + j_compress_ptr cinfo; /* back link saves passing separate parm */ + + JSAMPARRAY colormap; /* Targa colormap (converted to my format) */ + + jvirt_sarray_ptr whole_image; /* Needed if funny input row order */ + JDIMENSION current_row; /* Current logical row number to read */ + + /* Pointer to routine to extract next Targa pixel from input file */ + JMETHOD(void, read_pixel, (tga_source_ptr sinfo)); + + /* Result of read_pixel is delivered here: */ + U_CHAR tga_pixel[4]; + + int pixel_size; /* Bytes per Targa pixel (1 to 4) */ + + /* State info for reading RLE-coded pixels; both counts must be init to 0 */ + int block_count; /* # of pixels remaining in RLE block */ + int dup_pixel_count; /* # of times to duplicate previous pixel */ + + /* This saves the correct pixel-row-expansion method for preload_image */ + JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo, + cjpeg_source_ptr sinfo)); +} tga_source_struct; + + +/* For expanding 5-bit pixel values to 8-bit with best rounding */ + +static const UINT8 c5to8bits[32] = { + 0, 8, 16, 25, 33, 41, 49, 58, + 66, 74, 82, 90, 99, 107, 115, 123, + 132, 140, 148, 156, 165, 173, 181, 189, + 197, 206, 214, 222, 230, 239, 247, 255 +}; + + + +LOCAL(int) +read_byte (tga_source_ptr sinfo) +/* Read next byte from Targa file */ +{ + register FILE *infile = sinfo->pub.input_file; + register int c; + + if ((c = getc(infile)) == EOF) + ERREXIT(sinfo->cinfo, JERR_INPUT_EOF); + return c; +} + + +LOCAL(void) +read_colormap (tga_source_ptr sinfo, int cmaplen, int mapentrysize) +/* Read the colormap from a Targa file */ +{ + int i; + + /* Presently only handles 24-bit BGR format */ + if (mapentrysize != 24) + ERREXIT(sinfo->cinfo, JERR_TGA_BADCMAP); + + for (i = 0; i < cmaplen; i++) { + sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo); + sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo); + sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo); + } +} + + +/* + * read_pixel methods: get a single pixel from Targa file into tga_pixel[] + */ + +METHODDEF(void) +read_non_rle_pixel (tga_source_ptr sinfo) +/* Read one Targa pixel from the input file; no RLE expansion */ +{ + register FILE *infile = sinfo->pub.input_file; + register int i; + + for (i = 0; i < sinfo->pixel_size; i++) { + sinfo->tga_pixel[i] = (U_CHAR) getc(infile); + } +} + + +METHODDEF(void) +read_rle_pixel (tga_source_ptr sinfo) +/* Read one Targa pixel from the input file, expanding RLE data as needed */ +{ + register FILE *infile = sinfo->pub.input_file; + register int i; + + /* Duplicate previously read pixel? */ + if (sinfo->dup_pixel_count > 0) { + sinfo->dup_pixel_count--; + return; + } + + /* Time to read RLE block header? */ + if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */ + i = read_byte(sinfo); + if (i & 0x80) { /* Start of duplicate-pixel block? */ + sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */ + sinfo->block_count = 0; /* then read new block header */ + } else { + sinfo->block_count = i & 0x7F; /* number of pixels after this one */ + } + } + + /* Read next pixel */ + for (i = 0; i < sinfo->pixel_size; i++) { + sinfo->tga_pixel[i] = (U_CHAR) getc(infile); + } +} + + +/* + * Read one row of pixels. + * + * We provide several different versions depending on input file format. + */ + + +METHODDEF(JDIMENSION) +get_8bit_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +/* This version is for reading 8-bit grayscale pixels */ +{ + tga_source_ptr source = (tga_source_ptr) sinfo; + register JSAMPROW ptr; + register JDIMENSION col; + + ptr = source->pub.buffer[0]; + for (col = cinfo->image_width; col > 0; col--) { + (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ + *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]); + } + return 1; +} + +METHODDEF(JDIMENSION) +get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +/* This version is for reading 8-bit colormap indexes */ +{ + tga_source_ptr source = (tga_source_ptr) sinfo; + register int t; + register JSAMPROW ptr; + register JDIMENSION col; + register JSAMPARRAY colormap = source->colormap; + + ptr = source->pub.buffer[0]; + for (col = cinfo->image_width; col > 0; col--) { + (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ + t = UCH(source->tga_pixel[0]); + *ptr++ = colormap[0][t]; + *ptr++ = colormap[1][t]; + *ptr++ = colormap[2][t]; + } + return 1; +} + +METHODDEF(JDIMENSION) +get_16bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +/* This version is for reading 16-bit pixels */ +{ + tga_source_ptr source = (tga_source_ptr) sinfo; + register int t; + register JSAMPROW ptr; + register JDIMENSION col; + + ptr = source->pub.buffer[0]; + for (col = cinfo->image_width; col > 0; col--) { + (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ + t = UCH(source->tga_pixel[0]); + t += UCH(source->tga_pixel[1]) << 8; + /* We expand 5 bit data to 8 bit sample width. + * The format of the 16-bit (LSB first) input word is + * xRRRRRGGGGGBBBBB + */ + ptr[2] = (JSAMPLE) c5to8bits[t & 0x1F]; + t >>= 5; + ptr[1] = (JSAMPLE) c5to8bits[t & 0x1F]; + t >>= 5; + ptr[0] = (JSAMPLE) c5to8bits[t & 0x1F]; + ptr += 3; + } + return 1; +} + +METHODDEF(JDIMENSION) +get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +/* This version is for reading 24-bit pixels */ +{ + tga_source_ptr source = (tga_source_ptr) sinfo; + register JSAMPROW ptr; + register JDIMENSION col; + + ptr = source->pub.buffer[0]; + for (col = cinfo->image_width; col > 0; col--) { + (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ + *ptr++ = (JSAMPLE) UCH(source->tga_pixel[2]); /* change BGR to RGB order */ + *ptr++ = (JSAMPLE) UCH(source->tga_pixel[1]); + *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]); + } + return 1; +} + +/* + * Targa also defines a 32-bit pixel format with order B,G,R,A. + * We presently ignore the attribute byte, so the code for reading + * these pixels is identical to the 24-bit routine above. + * This works because the actual pixel length is only known to read_pixel. + */ + +#define get_32bit_row get_24bit_row + + +/* + * This method is for re-reading the input data in standard top-down + * row order. The entire image has already been read into whole_image + * with proper conversion of pixel format, but it's in a funny row order. + */ + +METHODDEF(JDIMENSION) +get_memory_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +{ + tga_source_ptr source = (tga_source_ptr) sinfo; + JDIMENSION source_row; + + /* Compute row of source that maps to current_row of normal order */ + /* For now, assume image is bottom-up and not interlaced. */ + /* NEEDS WORK to support interlaced images! */ + source_row = cinfo->image_height - source->current_row - 1; + + /* Fetch that row from virtual array */ + source->pub.buffer = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, source->whole_image, + source_row, (JDIMENSION) 1, FALSE); + + source->current_row++; + return 1; +} + + +/* + * This method loads the image into whole_image during the first call on + * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call + * get_memory_row on subsequent calls. + */ + +METHODDEF(JDIMENSION) +preload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +{ + tga_source_ptr source = (tga_source_ptr) sinfo; + JDIMENSION row; + cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; + + /* Read the data into a virtual array in input-file row order. */ + for (row = 0; row < cinfo->image_height; row++) { + if (progress != NULL) { + progress->pub.pass_counter = (long) row; + progress->pub.pass_limit = (long) cinfo->image_height; + (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); + } + source->pub.buffer = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, source->whole_image, row, (JDIMENSION) 1, TRUE); + (*source->get_pixel_rows) (cinfo, sinfo); + } + if (progress != NULL) + progress->completed_extra_passes++; + + /* Set up to read from the virtual array in unscrambled order */ + source->pub.get_pixel_rows = get_memory_row; + source->current_row = 0; + /* And read the first row */ + return get_memory_row(cinfo, sinfo); +} + + +/* + * Read the file header; return image size and component count. + */ + +METHODDEF(void) +start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +{ + tga_source_ptr source = (tga_source_ptr) sinfo; + U_CHAR targaheader[18]; + int idlen, cmaptype, subtype, flags, interlace_type, components; + unsigned int width, height, maplen; + boolean is_bottom_up; + +#define GET_2B(offset) ((unsigned int) UCH(targaheader[offset]) + \ + (((unsigned int) UCH(targaheader[offset+1])) << 8)) + + if (! ReadOK(source->pub.input_file, targaheader, 18)) + ERREXIT(cinfo, JERR_INPUT_EOF); + + /* Pretend "15-bit" pixels are 16-bit --- we ignore attribute bit anyway */ + if (targaheader[16] == 15) + targaheader[16] = 16; + + idlen = UCH(targaheader[0]); + cmaptype = UCH(targaheader[1]); + subtype = UCH(targaheader[2]); + maplen = GET_2B(5); + width = GET_2B(12); + height = GET_2B(14); + source->pixel_size = UCH(targaheader[16]) >> 3; + flags = UCH(targaheader[17]); /* Image Descriptor byte */ + + is_bottom_up = ((flags & 0x20) == 0); /* bit 5 set => top-down */ + interlace_type = flags >> 6; /* bits 6/7 are interlace code */ + + if (cmaptype > 1 || /* cmaptype must be 0 or 1 */ + source->pixel_size < 1 || source->pixel_size > 4 || + (UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */ + interlace_type != 0) /* currently don't allow interlaced image */ + ERREXIT(cinfo, JERR_TGA_BADPARMS); + + if (subtype > 8) { + /* It's an RLE-coded file */ + source->read_pixel = read_rle_pixel; + source->block_count = source->dup_pixel_count = 0; + subtype -= 8; + } else { + /* Non-RLE file */ + source->read_pixel = read_non_rle_pixel; + } + + /* Now should have subtype 1, 2, or 3 */ + components = 3; /* until proven different */ + cinfo->in_color_space = JCS_RGB; + + switch (subtype) { + case 1: /* Colormapped image */ + if (source->pixel_size == 1 && cmaptype == 1) + source->get_pixel_rows = get_8bit_row; + else + ERREXIT(cinfo, JERR_TGA_BADPARMS); + TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height); + break; + case 2: /* RGB image */ + switch (source->pixel_size) { + case 2: + source->get_pixel_rows = get_16bit_row; + break; + case 3: + source->get_pixel_rows = get_24bit_row; + break; + case 4: + source->get_pixel_rows = get_32bit_row; + break; + default: + ERREXIT(cinfo, JERR_TGA_BADPARMS); + break; + } + TRACEMS2(cinfo, 1, JTRC_TGA, width, height); + break; + case 3: /* Grayscale image */ + components = 1; + cinfo->in_color_space = JCS_GRAYSCALE; + if (source->pixel_size == 1) + source->get_pixel_rows = get_8bit_gray_row; + else + ERREXIT(cinfo, JERR_TGA_BADPARMS); + TRACEMS2(cinfo, 1, JTRC_TGA_GRAY, width, height); + break; + default: + ERREXIT(cinfo, JERR_TGA_BADPARMS); + break; + } + + if (is_bottom_up) { + /* Create a virtual array to buffer the upside-down image. */ + source->whole_image = (*cinfo->mem->request_virt_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, + (JDIMENSION) width * components, (JDIMENSION) height, (JDIMENSION) 1); + if (cinfo->progress != NULL) { + cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; + progress->total_extra_passes++; /* count file input as separate pass */ + } + /* source->pub.buffer will point to the virtual array. */ + source->pub.buffer_height = 1; /* in case anyone looks at it */ + source->pub.get_pixel_rows = preload_image; + } else { + /* Don't need a virtual array, but do need a one-row input buffer. */ + source->whole_image = NULL; + source->pub.buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) width * components, (JDIMENSION) 1); + source->pub.buffer_height = 1; + source->pub.get_pixel_rows = source->get_pixel_rows; + } + + while (idlen--) /* Throw away ID field */ + (void) read_byte(source); + + if (maplen > 0) { + if (maplen > 256 || GET_2B(3) != 0) + ERREXIT(cinfo, JERR_TGA_BADCMAP); + /* Allocate space to store the colormap */ + source->colormap = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, (JDIMENSION) maplen, (JDIMENSION) 3); + /* and read it from the file */ + read_colormap(source, (int) maplen, UCH(targaheader[7])); + } else { + if (cmaptype) /* but you promised a cmap! */ + ERREXIT(cinfo, JERR_TGA_BADPARMS); + source->colormap = NULL; + } + + cinfo->input_components = components; + cinfo->data_precision = 8; + cinfo->image_width = width; + cinfo->image_height = height; +} + + +/* + * Finish up at the end of the file. + */ + +METHODDEF(void) +finish_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) +{ + /* no work */ +} + + +/* + * The module selection routine for Targa format input. + */ + +GLOBAL(cjpeg_source_ptr) +jinit_read_targa (j_compress_ptr cinfo) +{ + tga_source_ptr source; + + /* Create module interface object */ + source = (tga_source_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(tga_source_struct)); + source->cinfo = cinfo; /* make back link for subroutines */ + /* Fill in method ptrs, except get_pixel_rows which start_input sets */ + source->pub.start_input = start_input_tga; + source->pub.finish_input = finish_input_tga; + + return (cjpeg_source_ptr) source; +} + +#endif /* TARGA_SUPPORTED */ diff --git a/Source/LibJPEG/structure.txt b/Source/LibJPEG/structure.txt index ae9f89f..44e48ca 100644 --- a/Source/LibJPEG/structure.txt +++ b/Source/LibJPEG/structure.txt @@ -1,941 +1,941 @@ -IJG JPEG LIBRARY: SYSTEM ARCHITECTURE - -Copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding. -This file is part of the Independent JPEG Group's software. -For conditions of distribution and use, see the accompanying README file. - - -This file provides an overview of the architecture of the IJG JPEG software; -that is, the functions of the various modules in the system and the interfaces -between modules. For more precise details about any data structure or calling -convention, see the include files and comments in the source code. - -We assume that the reader is already somewhat familiar with the JPEG standard. -The README file includes references for learning about JPEG. The file -libjpeg.txt describes the library from the viewpoint of an application -programmer using the library; it's best to read that file before this one. -Also, the file coderules.txt describes the coding style conventions we use. - -In this document, JPEG-specific terminology follows the JPEG standard: - A "component" means a color channel, e.g., Red or Luminance. - A "sample" is a single component value (i.e., one number in the image data). - A "coefficient" is a frequency coefficient (a DCT transform output number). - A "block" is an array of samples or coefficients. - An "MCU" (minimum coded unit) is an interleaved set of blocks of size - determined by the sampling factors, or a single block in a - noninterleaved scan. -We do not use the terms "pixel" and "sample" interchangeably. When we say -pixel, we mean an element of the full-size image, while a sample is an element -of the downsampled image. Thus the number of samples may vary across -components while the number of pixels does not. (This terminology is not used -rigorously throughout the code, but it is used in places where confusion would -otherwise result.) - - -*** System features *** - -The IJG distribution contains two parts: - * A subroutine library for JPEG compression and decompression. - * cjpeg/djpeg, two sample applications that use the library to transform - JFIF JPEG files to and from several other image formats. -cjpeg/djpeg are of no great intellectual complexity: they merely add a simple -command-line user interface and I/O routines for several uncompressed image -formats. This document concentrates on the library itself. - -We desire the library to be capable of supporting all JPEG baseline, extended -sequential, and progressive DCT processes. The library does not support the -hierarchical or lossless processes defined in the standard. - -Within these limits, any set of compression parameters allowed by the JPEG -spec should be readable for decompression. (We can be more restrictive about -what formats we can generate.) Although the system design allows for all -parameter values, some uncommon settings are not yet implemented and may -never be; nonintegral sampling ratios are the prime example. Furthermore, -we treat 8-bit vs. 12-bit data precision as a compile-time switch, not a -run-time option, because most machines can store 8-bit pixels much more -compactly than 12-bit. - -By itself, the library handles only interchange JPEG datastreams --- in -particular the widely used JFIF file format. The library can be used by -surrounding code to process interchange or abbreviated JPEG datastreams that -are embedded in more complex file formats. (For example, libtiff uses this -library to implement JPEG compression within the TIFF file format.) - -The library includes a substantial amount of code that is not covered by the -JPEG standard but is necessary for typical applications of JPEG. These -functions preprocess the image before JPEG compression or postprocess it after -decompression. They include colorspace conversion, downsampling/upsampling, -and color quantization. This code can be omitted if not needed. - -A wide range of quality vs. speed tradeoffs are possible in JPEG processing, -and even more so in decompression postprocessing. The decompression library -provides multiple implementations that cover most of the useful tradeoffs, -ranging from very-high-quality down to fast-preview operation. On the -compression side we have generally not provided low-quality choices, since -compression is normally less time-critical. It should be understood that the -low-quality modes may not meet the JPEG standard's accuracy requirements; -nonetheless, they are useful for viewers. - - -*** Portability issues *** - -Portability is an essential requirement for the library. The key portability -issues that show up at the level of system architecture are: - -1. Memory usage. We want the code to be able to run on PC-class machines -with limited memory. Images should therefore be processed sequentially (in -strips), to avoid holding the whole image in memory at once. Where a -full-image buffer is necessary, we should be able to use either virtual memory -or temporary files. - -2. Near/far pointer distinction. To run efficiently on 80x86 machines, the -code should distinguish "small" objects (kept in near data space) from -"large" ones (kept in far data space). This is an annoying restriction, but -fortunately it does not impact code quality for less brain-damaged machines, -and the source code clutter turns out to be minimal with sufficient use of -pointer typedefs. - -3. Data precision. We assume that "char" is at least 8 bits, "short" and -"int" at least 16, "long" at least 32. The code will work fine with larger -data sizes, although memory may be used inefficiently in some cases. However, -the JPEG compressed datastream must ultimately appear on external storage as a -sequence of 8-bit bytes if it is to conform to the standard. This may pose a -problem on machines where char is wider than 8 bits. The library represents -compressed data as an array of values of typedef JOCTET. If no data type -exactly 8 bits wide is available, custom data source and data destination -modules must be written to unpack and pack the chosen JOCTET datatype into -8-bit external representation. - - -*** System overview *** - -The compressor and decompressor are each divided into two main sections: -the JPEG compressor or decompressor proper, and the preprocessing or -postprocessing functions. The interface between these two sections is the -image data that the official JPEG spec regards as its input or output: this -data is in the colorspace to be used for compression, and it is downsampled -to the sampling factors to be used. The preprocessing and postprocessing -steps are responsible for converting a normal image representation to or from -this form. (Those few applications that want to deal with YCbCr downsampled -data can skip the preprocessing or postprocessing step.) - -Looking more closely, the compressor library contains the following main -elements: - - Preprocessing: - * Color space conversion (e.g., RGB to YCbCr). - * Edge expansion and downsampling. Optionally, this step can do simple - smoothing --- this is often helpful for low-quality source data. - JPEG proper: - * MCU assembly, DCT, quantization. - * Entropy coding (sequential or progressive, Huffman or arithmetic). - -In addition to these modules we need overall control, marker generation, -and support code (memory management & error handling). There is also a -module responsible for physically writing the output data --- typically -this is just an interface to fwrite(), but some applications may need to -do something else with the data. - -The decompressor library contains the following main elements: - - JPEG proper: - * Entropy decoding (sequential or progressive, Huffman or arithmetic). - * Dequantization, inverse DCT, MCU disassembly. - Postprocessing: - * Upsampling. Optionally, this step may be able to do more general - rescaling of the image. - * Color space conversion (e.g., YCbCr to RGB). This step may also - provide gamma adjustment [ currently it does not ]. - * Optional color quantization (e.g., reduction to 256 colors). - * Optional color precision reduction (e.g., 24-bit to 15-bit color). - [This feature is not currently implemented.] - -We also need overall control, marker parsing, and a data source module. -The support code (memory management & error handling) can be shared with -the compression half of the library. - -There may be several implementations of each of these elements, particularly -in the decompressor, where a wide range of speed/quality tradeoffs is very -useful. It must be understood that some of the best speedups involve -merging adjacent steps in the pipeline. For example, upsampling, color space -conversion, and color quantization might all be done at once when using a -low-quality ordered-dither technique. The system architecture is designed to -allow such merging where appropriate. - - -Note: it is convenient to regard edge expansion (padding to block boundaries) -as a preprocessing/postprocessing function, even though the JPEG spec includes -it in compression/decompression. We do this because downsampling/upsampling -can be simplified a little if they work on padded data: it's not necessary to -have special cases at the right and bottom edges. Therefore the interface -buffer is always an integral number of blocks wide and high, and we expect -compression preprocessing to pad the source data properly. Padding will occur -only to the next block (N-sample) boundary. In an interleaved-scan situation, -additional dummy blocks may be used to fill out MCUs, but the MCU assembly and -disassembly logic will create or discard these blocks internally. (This is -advantageous for speed reasons, since we avoid DCTing the dummy blocks. -It also permits a small reduction in file size, because the compressor can -choose dummy block contents so as to minimize their size in compressed form. -Finally, it makes the interface buffer specification independent of whether -the file is actually interleaved or not.) Applications that wish to deal -directly with the downsampled data must provide similar buffering and padding -for odd-sized images. - - -*** Poor man's object-oriented programming *** - -It should be clear by now that we have a lot of quasi-independent processing -steps, many of which have several possible behaviors. To avoid cluttering the -code with lots of switch statements, we use a simple form of object-style -programming to separate out the different possibilities. - -For example, two different color quantization algorithms could be implemented -as two separate modules that present the same external interface; at runtime, -the calling code will access the proper module indirectly through an "object". - -We can get the limited features we need while staying within portable C. -The basic tool is a function pointer. An "object" is just a struct -containing one or more function pointer fields, each of which corresponds to -a method name in real object-oriented languages. During initialization we -fill in the function pointers with references to whichever module we have -determined we need to use in this run. Then invocation of the module is done -by indirecting through a function pointer; on most machines this is no more -expensive than a switch statement, which would be the only other way of -making the required run-time choice. The really significant benefit, of -course, is keeping the source code clean and well structured. - -We can also arrange to have private storage that varies between different -implementations of the same kind of object. We do this by making all the -module-specific object structs be separately allocated entities, which will -be accessed via pointers in the master compression or decompression struct. -The "public" fields or methods for a given kind of object are specified by -a commonly known struct. But a module's initialization code can allocate -a larger struct that contains the common struct as its first member, plus -additional private fields. With appropriate pointer casting, the module's -internal functions can access these private fields. (For a simple example, -see jdatadst.c, which implements the external interface specified by struct -jpeg_destination_mgr, but adds extra fields.) - -(Of course this would all be a lot easier if we were using C++, but we are -not yet prepared to assume that everyone has a C++ compiler.) - -An important benefit of this scheme is that it is easy to provide multiple -versions of any method, each tuned to a particular case. While a lot of -precalculation might be done to select an optimal implementation of a method, -the cost per invocation is constant. For example, the upsampling step might -have a "generic" method, plus one or more "hardwired" methods for the most -popular sampling factors; the hardwired methods would be faster because they'd -use straight-line code instead of for-loops. The cost to determine which -method to use is paid only once, at startup, and the selection criteria are -hidden from the callers of the method. - -This plan differs a little bit from usual object-oriented structures, in that -only one instance of each object class will exist during execution. The -reason for having the class structure is that on different runs we may create -different instances (choose to execute different modules). You can think of -the term "method" as denoting the common interface presented by a particular -set of interchangeable functions, and "object" as denoting a group of related -methods, or the total shared interface behavior of a group of modules. - - -*** Overall control structure *** - -We previously mentioned the need for overall control logic in the compression -and decompression libraries. In IJG implementations prior to v5, overall -control was mostly provided by "pipeline control" modules, which proved to be -large, unwieldy, and hard to understand. To improve the situation, the -control logic has been subdivided into multiple modules. The control modules -consist of: - -1. Master control for module selection and initialization. This has two -responsibilities: - - 1A. Startup initialization at the beginning of image processing. - The individual processing modules to be used in this run are selected - and given initialization calls. - - 1B. Per-pass control. This determines how many passes will be performed - and calls each active processing module to configure itself - appropriately at the beginning of each pass. End-of-pass processing, - where necessary, is also invoked from the master control module. - - Method selection is partially distributed, in that a particular processing - module may contain several possible implementations of a particular method, - which it will select among when given its initialization call. The master - control code need only be concerned with decisions that affect more than - one module. - -2. Data buffering control. A separate control module exists for each - inter-processing-step data buffer. This module is responsible for - invoking the processing steps that write or read that data buffer. - -Each buffer controller sees the world as follows: - -input data => processing step A => buffer => processing step B => output data - | | | - ------------------ controller ------------------ - -The controller knows the dataflow requirements of steps A and B: how much data -they want to accept in one chunk and how much they output in one chunk. Its -function is to manage its buffer and call A and B at the proper times. - -A data buffer control module may itself be viewed as a processing step by a -higher-level control module; thus the control modules form a binary tree with -elementary processing steps at the leaves of the tree. - -The control modules are objects. A considerable amount of flexibility can -be had by replacing implementations of a control module. For example: -* Merging of adjacent steps in the pipeline is done by replacing a control - module and its pair of processing-step modules with a single processing- - step module. (Hence the possible merges are determined by the tree of - control modules.) -* In some processing modes, a given interstep buffer need only be a "strip" - buffer large enough to accommodate the desired data chunk sizes. In other - modes, a full-image buffer is needed and several passes are required. - The control module determines which kind of buffer is used and manipulates - virtual array buffers as needed. One or both processing steps may be - unaware of the multi-pass behavior. - -In theory, we might be able to make all of the data buffer controllers -interchangeable and provide just one set of implementations for all. In -practice, each one contains considerable special-case processing for its -particular job. The buffer controller concept should be regarded as an -overall system structuring principle, not as a complete description of the -task performed by any one controller. - - -*** Compression object structure *** - -Here is a sketch of the logical structure of the JPEG compression library: - - |-- Colorspace conversion - |-- Preprocessing controller --| - | |-- Downsampling -Main controller --| - | |-- Forward DCT, quantize - |-- Coefficient controller --| - |-- Entropy encoding - -This sketch also describes the flow of control (subroutine calls) during -typical image data processing. Each of the components shown in the diagram is -an "object" which may have several different implementations available. One -or more source code files contain the actual implementation(s) of each object. - -The objects shown above are: - -* Main controller: buffer controller for the subsampled-data buffer, which - holds the preprocessed input data. This controller invokes preprocessing to - fill the subsampled-data buffer, and JPEG compression to empty it. There is - usually no need for a full-image buffer here; a strip buffer is adequate. - -* Preprocessing controller: buffer controller for the downsampling input data - buffer, which lies between colorspace conversion and downsampling. Note - that a unified conversion/downsampling module would probably replace this - controller entirely. - -* Colorspace conversion: converts application image data into the desired - JPEG color space; also changes the data from pixel-interleaved layout to - separate component planes. Processes one pixel row at a time. - -* Downsampling: performs reduction of chroma components as required. - Optionally may perform pixel-level smoothing as well. Processes a "row - group" at a time, where a row group is defined as Vmax pixel rows of each - component before downsampling, and Vk sample rows afterwards (remember Vk - differs across components). Some downsampling or smoothing algorithms may - require context rows above and below the current row group; the - preprocessing controller is responsible for supplying these rows via proper - buffering. The downsampler is responsible for edge expansion at the right - edge (i.e., extending each sample row to a multiple of N samples); but the - preprocessing controller is responsible for vertical edge expansion (i.e., - duplicating the bottom sample row as needed to make a multiple of N rows). - -* Coefficient controller: buffer controller for the DCT-coefficient data. - This controller handles MCU assembly, including insertion of dummy DCT - blocks when needed at the right or bottom edge. When performing - Huffman-code optimization or emitting a multiscan JPEG file, this - controller is responsible for buffering the full image. The equivalent of - one fully interleaved MCU row of subsampled data is processed per call, - even when the JPEG file is noninterleaved. - -* Forward DCT and quantization: Perform DCT, quantize, and emit coefficients. - Works on one or more DCT blocks at a time. (Note: the coefficients are now - emitted in normal array order, which the entropy encoder is expected to - convert to zigzag order as necessary. Prior versions of the IJG code did - the conversion to zigzag order within the quantization step.) - -* Entropy encoding: Perform Huffman or arithmetic entropy coding and emit the - coded data to the data destination module. Works on one MCU per call. - For progressive JPEG, the same DCT blocks are fed to the entropy coder - during each pass, and the coder must emit the appropriate subset of - coefficients. - -In addition to the above objects, the compression library includes these -objects: - -* Master control: determines the number of passes required, controls overall - and per-pass initialization of the other modules. - -* Marker writing: generates JPEG markers (except for RSTn, which is emitted - by the entropy encoder when needed). - -* Data destination manager: writes the output JPEG datastream to its final - destination (e.g., a file). The destination manager supplied with the - library knows how to write to a stdio stream or to a memory buffer; - for other behaviors, the surrounding application may provide its own - destination manager. - -* Memory manager: allocates and releases memory, controls virtual arrays - (with backing store management, where required). - -* Error handler: performs formatting and output of error and trace messages; - determines handling of nonfatal errors. The surrounding application may - override some or all of this object's methods to change error handling. - -* Progress monitor: supports output of "percent-done" progress reports. - This object represents an optional callback to the surrounding application: - if wanted, it must be supplied by the application. - -The error handler, destination manager, and progress monitor objects are -defined as separate objects in order to simplify application-specific -customization of the JPEG library. A surrounding application may override -individual methods or supply its own all-new implementation of one of these -objects. The object interfaces for these objects are therefore treated as -part of the application interface of the library, whereas the other objects -are internal to the library. - -The error handler and memory manager are shared by JPEG compression and -decompression; the progress monitor, if used, may be shared as well. - - -*** Decompression object structure *** - -Here is a sketch of the logical structure of the JPEG decompression library: - - |-- Entropy decoding - |-- Coefficient controller --| - | |-- Dequantize, Inverse DCT -Main controller --| - | |-- Upsampling - |-- Postprocessing controller --| |-- Colorspace conversion - |-- Color quantization - |-- Color precision reduction - -As before, this diagram also represents typical control flow. The objects -shown are: - -* Main controller: buffer controller for the subsampled-data buffer, which - holds the output of JPEG decompression proper. This controller's primary - task is to feed the postprocessing procedure. Some upsampling algorithms - may require context rows above and below the current row group; when this - is true, the main controller is responsible for managing its buffer so as - to make context rows available. In the current design, the main buffer is - always a strip buffer; a full-image buffer is never required. - -* Coefficient controller: buffer controller for the DCT-coefficient data. - This controller handles MCU disassembly, including deletion of any dummy - DCT blocks at the right or bottom edge. When reading a multiscan JPEG - file, this controller is responsible for buffering the full image. - (Buffering DCT coefficients, rather than samples, is necessary to support - progressive JPEG.) The equivalent of one fully interleaved MCU row of - subsampled data is processed per call, even when the source JPEG file is - noninterleaved. - -* Entropy decoding: Read coded data from the data source module and perform - Huffman or arithmetic entropy decoding. Works on one MCU per call. - For progressive JPEG decoding, the coefficient controller supplies the prior - coefficients of each MCU (initially all zeroes), which the entropy decoder - modifies in each scan. - -* Dequantization and inverse DCT: like it says. Note that the coefficients - buffered by the coefficient controller have NOT been dequantized; we - merge dequantization and inverse DCT into a single step for speed reasons. - When scaled-down output is asked for, simplified DCT algorithms may be used - that need fewer coefficients and emit fewer samples per DCT block, not the - full 8x8. Works on one DCT block at a time. - -* Postprocessing controller: buffer controller for the color quantization - input buffer, when quantization is in use. (Without quantization, this - controller just calls the upsampler.) For two-pass quantization, this - controller is responsible for buffering the full-image data. - -* Upsampling: restores chroma components to full size. (May support more - general output rescaling, too. Note that if undersized DCT outputs have - been emitted by the DCT module, this module must adjust so that properly - sized outputs are created.) Works on one row group at a time. This module - also calls the color conversion module, so its top level is effectively a - buffer controller for the upsampling->color conversion buffer. However, in - all but the highest-quality operating modes, upsampling and color - conversion are likely to be merged into a single step. - -* Colorspace conversion: convert from JPEG color space to output color space, - and change data layout from separate component planes to pixel-interleaved. - Works on one pixel row at a time. - -* Color quantization: reduce the data to colormapped form, using either an - externally specified colormap or an internally generated one. This module - is not used for full-color output. Works on one pixel row at a time; may - require two passes to generate a color map. Note that the output will - always be a single component representing colormap indexes. In the current - design, the output values are JSAMPLEs, so an 8-bit compilation cannot - quantize to more than 256 colors. This is unlikely to be a problem in - practice. - -* Color reduction: this module handles color precision reduction, e.g., - generating 15-bit color (5 bits/primary) from JPEG's 24-bit output. - Not quite clear yet how this should be handled... should we merge it with - colorspace conversion??? - -Note that some high-speed operating modes might condense the entire -postprocessing sequence to a single module (upsample, color convert, and -quantize in one step). - -In addition to the above objects, the decompression library includes these -objects: - -* Master control: determines the number of passes required, controls overall - and per-pass initialization of the other modules. This is subdivided into - input and output control: jdinput.c controls only input-side processing, - while jdmaster.c handles overall initialization and output-side control. - -* Marker reading: decodes JPEG markers (except for RSTn). - -* Data source manager: supplies the input JPEG datastream. The source - manager supplied with the library knows how to read from a stdio stream - or from a memory buffer; for other behaviors, the surrounding application - may provide its own source manager. - -* Memory manager: same as for compression library. - -* Error handler: same as for compression library. - -* Progress monitor: same as for compression library. - -As with compression, the data source manager, error handler, and progress -monitor are candidates for replacement by a surrounding application. - - -*** Decompression input and output separation *** - -To support efficient incremental display of progressive JPEG files, the -decompressor is divided into two sections that can run independently: - -1. Data input includes marker parsing, entropy decoding, and input into the - coefficient controller's DCT coefficient buffer. Note that this - processing is relatively cheap and fast. - -2. Data output reads from the DCT coefficient buffer and performs the IDCT - and all postprocessing steps. - -For a progressive JPEG file, the data input processing is allowed to get -arbitrarily far ahead of the data output processing. (This occurs only -if the application calls jpeg_consume_input(); otherwise input and output -run in lockstep, since the input section is called only when the output -section needs more data.) In this way the application can avoid making -extra display passes when data is arriving faster than the display pass -can run. Furthermore, it is possible to abort an output pass without -losing anything, since the coefficient buffer is read-only as far as the -output section is concerned. See libjpeg.txt for more detail. - -A full-image coefficient array is only created if the JPEG file has multiple -scans (or if the application specifies buffered-image mode anyway). When -reading a single-scan file, the coefficient controller normally creates only -a one-MCU buffer, so input and output processing must run in lockstep in this -case. jpeg_consume_input() is effectively a no-op in this situation. - -The main impact of dividing the decompressor in this fashion is that we must -be very careful with shared variables in the cinfo data structure. Each -variable that can change during the course of decompression must be -classified as belonging to data input or data output, and each section must -look only at its own variables. For example, the data output section may not -depend on any of the variables that describe the current scan in the JPEG -file, because these may change as the data input section advances into a new -scan. - -The progress monitor is (somewhat arbitrarily) defined to treat input of the -file as one pass when buffered-image mode is not used, and to ignore data -input work completely when buffered-image mode is used. Note that the -library has no reliable way to predict the number of passes when dealing -with a progressive JPEG file, nor can it predict the number of output passes -in buffered-image mode. So the work estimate is inherently bogus anyway. - -No comparable division is currently made in the compression library, because -there isn't any real need for it. - - -*** Data formats *** - -Arrays of pixel sample values use the following data structure: - - typedef something JSAMPLE; a pixel component value, 0..MAXJSAMPLE - typedef JSAMPLE *JSAMPROW; ptr to a row of samples - typedef JSAMPROW *JSAMPARRAY; ptr to a list of rows - typedef JSAMPARRAY *JSAMPIMAGE; ptr to a list of color-component arrays - -The basic element type JSAMPLE will typically be one of unsigned char, -(signed) char, or short. Short will be used if samples wider than 8 bits are -to be supported (this is a compile-time option). Otherwise, unsigned char is -used if possible. If the compiler only supports signed chars, then it is -necessary to mask off the value when reading. Thus, all reads of JSAMPLE -values must be coded as "GETJSAMPLE(value)", where the macro will be defined -as "((value) & 0xFF)" on signed-char machines and "((int) (value))" elsewhere. - -With these conventions, JSAMPLE values can be assumed to be >= 0. This helps -simplify correct rounding during downsampling, etc. The JPEG standard's -specification that sample values run from -128..127 is accommodated by -subtracting 128 from the sample value in the DCT step. Similarly, during -decompression the output of the IDCT step will be immediately shifted back to -0..255. (NB: different values are required when 12-bit samples are in use. -The code is written in terms of MAXJSAMPLE and CENTERJSAMPLE, which will be -defined as 255 and 128 respectively in an 8-bit implementation, and as 4095 -and 2048 in a 12-bit implementation.) - -We use a pointer per row, rather than a two-dimensional JSAMPLE array. This -choice costs only a small amount of memory and has several benefits: -* Code using the data structure doesn't need to know the allocated width of - the rows. This simplifies edge expansion/compression, since we can work - in an array that's wider than the logical picture width. -* Indexing doesn't require multiplication; this is a performance win on many - machines. -* Arrays with more than 64K total elements can be supported even on machines - where malloc() cannot allocate chunks larger than 64K. -* The rows forming a component array may be allocated at different times - without extra copying. This trick allows some speedups in smoothing steps - that need access to the previous and next rows. - -Note that each color component is stored in a separate array; we don't use the -traditional layout in which the components of a pixel are stored together. -This simplifies coding of modules that work on each component independently, -because they don't need to know how many components there are. Furthermore, -we can read or write each component to a temporary file independently, which -is helpful when dealing with noninterleaved JPEG files. - -In general, a specific sample value is accessed by code such as - GETJSAMPLE(image[colorcomponent][row][col]) -where col is measured from the image left edge, but row is measured from the -first sample row currently in memory. Either of the first two indexings can -be precomputed by copying the relevant pointer. - - -Since most image-processing applications prefer to work on images in which -the components of a pixel are stored together, the data passed to or from the -surrounding application uses the traditional convention: a single pixel is -represented by N consecutive JSAMPLE values, and an image row is an array of -(# of color components)*(image width) JSAMPLEs. One or more rows of data can -be represented by a pointer of type JSAMPARRAY in this scheme. This scheme is -converted to component-wise storage inside the JPEG library. (Applications -that want to skip JPEG preprocessing or postprocessing will have to contend -with component-wise storage.) - - -Arrays of DCT-coefficient values use the following data structure: - - typedef short JCOEF; a 16-bit signed integer - typedef JCOEF JBLOCK[DCTSIZE2]; an 8x8 block of coefficients - typedef JBLOCK *JBLOCKROW; ptr to one horizontal row of 8x8 blocks - typedef JBLOCKROW *JBLOCKARRAY; ptr to a list of such rows - typedef JBLOCKARRAY *JBLOCKIMAGE; ptr to a list of color component arrays - -The underlying type is at least a 16-bit signed integer; while "short" is big -enough on all machines of interest, on some machines it is preferable to use -"int" for speed reasons, despite the storage cost. Coefficients are grouped -into 8x8 blocks (but we always use #defines DCTSIZE and DCTSIZE2 rather than -"8" and "64"). - -The contents of a coefficient block may be in either "natural" or zigzagged -order, and may be true values or divided by the quantization coefficients, -depending on where the block is in the processing pipeline. In the current -library, coefficient blocks are kept in natural order everywhere; the entropy -codecs zigzag or dezigzag the data as it is written or read. The blocks -contain quantized coefficients everywhere outside the DCT/IDCT subsystems. -(This latter decision may need to be revisited to support variable -quantization a la JPEG Part 3.) - -Notice that the allocation unit is now a row of 8x8 coefficient blocks, -corresponding to N rows of samples. Otherwise the structure is much the same -as for samples, and for the same reasons. - -On machines where malloc() can't handle a request bigger than 64Kb, this data -structure limits us to rows of less than 512 JBLOCKs, or a picture width of -4000+ pixels. This seems an acceptable restriction. - - -On 80x86 machines, the bottom-level pointer types (JSAMPROW and JBLOCKROW) -must be declared as "far" pointers, but the upper levels can be "near" -(implying that the pointer lists are allocated in the DS segment). -We use a #define symbol FAR, which expands to the "far" keyword when -compiling on 80x86 machines and to nothing elsewhere. - - -*** Suspendable processing *** - -In some applications it is desirable to use the JPEG library as an -incremental, memory-to-memory filter. In this situation the data source or -destination may be a limited-size buffer, and we can't rely on being able to -empty or refill the buffer at arbitrary times. Instead the application would -like to have control return from the library at buffer overflow/underrun, and -then resume compression or decompression at a later time. - -This scenario is supported for simple cases. (For anything more complex, we -recommend that the application "bite the bullet" and develop real multitasking -capability.) The libjpeg.txt file goes into more detail about the usage and -limitations of this capability; here we address the implications for library -structure. - -The essence of the problem is that the entropy codec (coder or decoder) must -be prepared to stop at arbitrary times. In turn, the controllers that call -the entropy codec must be able to stop before having produced or consumed all -the data that they normally would handle in one call. That part is reasonably -straightforward: we make the controller call interfaces include "progress -counters" which indicate the number of data chunks successfully processed, and -we require callers to test the counter rather than just assume all of the data -was processed. - -Rather than trying to restart at an arbitrary point, the current Huffman -codecs are designed to restart at the beginning of the current MCU after a -suspension due to buffer overflow/underrun. At the start of each call, the -codec's internal state is loaded from permanent storage (in the JPEG object -structures) into local variables. On successful completion of the MCU, the -permanent state is updated. (This copying is not very expensive, and may even -lead to *improved* performance if the local variables can be registerized.) -If a suspension occurs, the codec simply returns without updating the state, -thus effectively reverting to the start of the MCU. Note that this implies -leaving some data unprocessed in the source/destination buffer (ie, the -compressed partial MCU). The data source/destination module interfaces are -specified so as to make this possible. This also implies that the data buffer -must be large enough to hold a worst-case compressed MCU; a couple thousand -bytes should be enough. - -In a successive-approximation AC refinement scan, the progressive Huffman -decoder has to be able to undo assignments of newly nonzero coefficients if it -suspends before the MCU is complete, since decoding requires distinguishing -previously-zero and previously-nonzero coefficients. This is a bit tedious -but probably won't have much effect on performance. Other variants of Huffman -decoding need not worry about this, since they will just store the same values -again if forced to repeat the MCU. - -This approach would probably not work for an arithmetic codec, since its -modifiable state is quite large and couldn't be copied cheaply. Instead it -would have to suspend and resume exactly at the point of the buffer end. - -The JPEG marker reader is designed to cope with suspension at an arbitrary -point. It does so by backing up to the start of the marker parameter segment, -so the data buffer must be big enough to hold the largest marker of interest. -Again, a couple KB should be adequate. (A special "skip" convention is used -to bypass COM and APPn markers, so these can be larger than the buffer size -without causing problems; otherwise a 64K buffer would be needed in the worst -case.) - -The JPEG marker writer currently does *not* cope with suspension. -We feel that this is not necessary; it is much easier simply to require -the application to ensure there is enough buffer space before starting. (An -empty 2K buffer is more than sufficient for the header markers; and ensuring -there are a dozen or two bytes available before calling jpeg_finish_compress() -will suffice for the trailer.) This would not work for writing multi-scan -JPEG files, but we simply do not intend to support that capability with -suspension. - - -*** Memory manager services *** - -The JPEG library's memory manager controls allocation and deallocation of -memory, and it manages large "virtual" data arrays on machines where the -operating system does not provide virtual memory. Note that the same -memory manager serves both compression and decompression operations. - -In all cases, allocated objects are tied to a particular compression or -decompression master record, and they will be released when that master -record is destroyed. - -The memory manager does not provide explicit deallocation of objects. -Instead, objects are created in "pools" of free storage, and a whole pool -can be freed at once. This approach helps prevent storage-leak bugs, and -it speeds up operations whenever malloc/free are slow (as they often are). -The pools can be regarded as lifetime identifiers for objects. Two -pools/lifetimes are defined: - * JPOOL_PERMANENT lasts until master record is destroyed - * JPOOL_IMAGE lasts until done with image (JPEG datastream) -Permanent lifetime is used for parameters and tables that should be carried -across from one datastream to another; this includes all application-visible -parameters. Image lifetime is used for everything else. (A third lifetime, -JPOOL_PASS = one processing pass, was originally planned. However it was -dropped as not being worthwhile. The actual usage patterns are such that the -peak memory usage would be about the same anyway; and having per-pass storage -substantially complicates the virtual memory allocation rules --- see below.) - -The memory manager deals with three kinds of object: -1. "Small" objects. Typically these require no more than 10K-20K total. -2. "Large" objects. These may require tens to hundreds of K depending on - image size. Semantically they behave the same as small objects, but we - distinguish them for two reasons: - * On MS-DOS machines, large objects are referenced by FAR pointers, - small objects by NEAR pointers. - * Pool allocation heuristics may differ for large and small objects. - Note that individual "large" objects cannot exceed the size allowed by - type size_t, which may be 64K or less on some machines. -3. "Virtual" objects. These are large 2-D arrays of JSAMPLEs or JBLOCKs - (typically large enough for the entire image being processed). The - memory manager provides stripwise access to these arrays. On machines - without virtual memory, the rest of the array may be swapped out to a - temporary file. - -(Note: JSAMPARRAY and JBLOCKARRAY data structures are a combination of large -objects for the data proper and small objects for the row pointers. For -convenience and speed, the memory manager provides single routines to create -these structures. Similarly, virtual arrays include a small control block -and a JSAMPARRAY or JBLOCKARRAY working buffer, all created with one call.) - -In the present implementation, virtual arrays are only permitted to have image -lifespan. (Permanent lifespan would not be reasonable, and pass lifespan is -not very useful since a virtual array's raison d'etre is to store data for -multiple passes through the image.) We also expect that only "small" objects -will be given permanent lifespan, though this restriction is not required by -the memory manager. - -In a non-virtual-memory machine, some performance benefit can be gained by -making the in-memory buffers for virtual arrays be as large as possible. -(For small images, the buffers might fit entirely in memory, so blind -swapping would be very wasteful.) The memory manager will adjust the height -of the buffers to fit within a prespecified maximum memory usage. In order -to do this in a reasonably optimal fashion, the manager needs to allocate all -of the virtual arrays at once. Therefore, there isn't a one-step allocation -routine for virtual arrays; instead, there is a "request" routine that simply -allocates the control block, and a "realize" routine (called just once) that -determines space allocation and creates all of the actual buffers. The -realize routine must allow for space occupied by non-virtual large objects. -(We don't bother to factor in the space needed for small objects, on the -grounds that it isn't worth the trouble.) - -To support all this, we establish the following protocol for doing business -with the memory manager: - 1. Modules must request virtual arrays (which may have only image lifespan) - during the initial setup phase, i.e., in their jinit_xxx routines. - 2. All "large" objects (including JSAMPARRAYs and JBLOCKARRAYs) must also be - allocated during initial setup. - 3. realize_virt_arrays will be called at the completion of initial setup. - The above conventions ensure that sufficient information is available - for it to choose a good size for virtual array buffers. -Small objects of any lifespan may be allocated at any time. We expect that -the total space used for small objects will be small enough to be negligible -in the realize_virt_arrays computation. - -In a virtual-memory machine, we simply pretend that the available space is -infinite, thus causing realize_virt_arrays to decide that it can allocate all -the virtual arrays as full-size in-memory buffers. The overhead of the -virtual-array access protocol is very small when no swapping occurs. - -A virtual array can be specified to be "pre-zeroed"; when this flag is set, -never-yet-written sections of the array are set to zero before being made -available to the caller. If this flag is not set, never-written sections -of the array contain garbage. (This feature exists primarily because the -equivalent logic would otherwise be needed in jdcoefct.c for progressive -JPEG mode; we may as well make it available for possible other uses.) - -The first write pass on a virtual array is required to occur in top-to-bottom -order; read passes, as well as any write passes after the first one, may -access the array in any order. This restriction exists partly to simplify -the virtual array control logic, and partly because some file systems may not -support seeking beyond the current end-of-file in a temporary file. The main -implication of this restriction is that rearrangement of rows (such as -converting top-to-bottom data order to bottom-to-top) must be handled while -reading data out of the virtual array, not while putting it in. - - -*** Memory manager internal structure *** - -To isolate system dependencies as much as possible, we have broken the -memory manager into two parts. There is a reasonably system-independent -"front end" (jmemmgr.c) and a "back end" that contains only the code -likely to change across systems. All of the memory management methods -outlined above are implemented by the front end. The back end provides -the following routines for use by the front end (none of these routines -are known to the rest of the JPEG code): - -jpeg_mem_init, jpeg_mem_term system-dependent initialization/shutdown - -jpeg_get_small, jpeg_free_small interface to malloc and free library routines - (or their equivalents) - -jpeg_get_large, jpeg_free_large interface to FAR malloc/free in MSDOS machines; - else usually the same as - jpeg_get_small/jpeg_free_small - -jpeg_mem_available estimate available memory - -jpeg_open_backing_store create a backing-store object - -read_backing_store, manipulate a backing-store object -write_backing_store, -close_backing_store - -On some systems there will be more than one type of backing-store object -(specifically, in MS-DOS a backing store file might be an area of extended -memory as well as a disk file). jpeg_open_backing_store is responsible for -choosing how to implement a given object. The read/write/close routines -are method pointers in the structure that describes a given object; this -lets them be different for different object types. - -It may be necessary to ensure that backing store objects are explicitly -released upon abnormal program termination. For example, MS-DOS won't free -extended memory by itself. To support this, we will expect the main program -or surrounding application to arrange to call self_destruct (typically via -jpeg_destroy) upon abnormal termination. This may require a SIGINT signal -handler or equivalent. We don't want to have the back end module install its -own signal handler, because that would pre-empt the surrounding application's -ability to control signal handling. - -The IJG distribution includes several memory manager back end implementations. -Usually the same back end should be suitable for all applications on a given -system, but it is possible for an application to supply its own back end at -need. - - -*** Implications of DNL marker *** - -Some JPEG files may use a DNL marker to postpone definition of the image -height (this would be useful for a fax-like scanner's output, for instance). -In these files the SOF marker claims the image height is 0, and you only -find out the true image height at the end of the first scan. - -We could read these files as follows: -1. Upon seeing zero image height, replace it by 65535 (the maximum allowed). -2. When the DNL is found, update the image height in the global image - descriptor. -This implies that control modules must avoid making copies of the image -height, and must re-test for termination after each MCU row. This would -be easy enough to do. - -In cases where image-size data structures are allocated, this approach will -result in very inefficient use of virtual memory or much-larger-than-necessary -temporary files. This seems acceptable for something that probably won't be a -mainstream usage. People might have to forgo use of memory-hogging options -(such as two-pass color quantization or noninterleaved JPEG files) if they -want efficient conversion of such files. (One could improve efficiency by -demanding a user-supplied upper bound for the height, less than 65536; in most -cases it could be much less.) - -The standard also permits the SOF marker to overestimate the image height, -with a DNL to give the true, smaller height at the end of the first scan. -This would solve the space problems if the overestimate wasn't too great. -However, it implies that you don't even know whether DNL will be used. - -This leads to a couple of very serious objections: -1. Testing for a DNL marker must occur in the inner loop of the decompressor's - Huffman decoder; this implies a speed penalty whether the feature is used - or not. -2. There is no way to hide the last-minute change in image height from an - application using the decoder. Thus *every* application using the IJG - library would suffer a complexity penalty whether it cared about DNL or - not. -We currently do not support DNL because of these problems. - -A different approach is to insist that DNL-using files be preprocessed by a -separate program that reads ahead to the DNL, then goes back and fixes the SOF -marker. This is a much simpler solution and is probably far more efficient. -Even if one wants piped input, buffering the first scan of the JPEG file needs -a lot smaller temp file than is implied by the maximum-height method. For -this approach we'd simply treat DNL as a no-op in the decompressor (at most, -check that it matches the SOF image height). - -We will not worry about making the compressor capable of outputting DNL. -Something similar to the first scheme above could be applied if anyone ever -wants to make that work. +IJG JPEG LIBRARY: SYSTEM ARCHITECTURE + +Copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding. +This file is part of the Independent JPEG Group's software. +For conditions of distribution and use, see the accompanying README file. + + +This file provides an overview of the architecture of the IJG JPEG software; +that is, the functions of the various modules in the system and the interfaces +between modules. For more precise details about any data structure or calling +convention, see the include files and comments in the source code. + +We assume that the reader is already somewhat familiar with the JPEG standard. +The README file includes references for learning about JPEG. The file +libjpeg.txt describes the library from the viewpoint of an application +programmer using the library; it's best to read that file before this one. +Also, the file coderules.txt describes the coding style conventions we use. + +In this document, JPEG-specific terminology follows the JPEG standard: + A "component" means a color channel, e.g., Red or Luminance. + A "sample" is a single component value (i.e., one number in the image data). + A "coefficient" is a frequency coefficient (a DCT transform output number). + A "block" is an array of samples or coefficients. + An "MCU" (minimum coded unit) is an interleaved set of blocks of size + determined by the sampling factors, or a single block in a + noninterleaved scan. +We do not use the terms "pixel" and "sample" interchangeably. When we say +pixel, we mean an element of the full-size image, while a sample is an element +of the downsampled image. Thus the number of samples may vary across +components while the number of pixels does not. (This terminology is not used +rigorously throughout the code, but it is used in places where confusion would +otherwise result.) + + +*** System features *** + +The IJG distribution contains two parts: + * A subroutine library for JPEG compression and decompression. + * cjpeg/djpeg, two sample applications that use the library to transform + JFIF JPEG files to and from several other image formats. +cjpeg/djpeg are of no great intellectual complexity: they merely add a simple +command-line user interface and I/O routines for several uncompressed image +formats. This document concentrates on the library itself. + +We desire the library to be capable of supporting all JPEG baseline, extended +sequential, and progressive DCT processes. The library does not support the +hierarchical or lossless processes defined in the standard. + +Within these limits, any set of compression parameters allowed by the JPEG +spec should be readable for decompression. (We can be more restrictive about +what formats we can generate.) Although the system design allows for all +parameter values, some uncommon settings are not yet implemented and may +never be; nonintegral sampling ratios are the prime example. Furthermore, +we treat 8-bit vs. 12-bit data precision as a compile-time switch, not a +run-time option, because most machines can store 8-bit pixels much more +compactly than 12-bit. + +By itself, the library handles only interchange JPEG datastreams --- in +particular the widely used JFIF file format. The library can be used by +surrounding code to process interchange or abbreviated JPEG datastreams that +are embedded in more complex file formats. (For example, libtiff uses this +library to implement JPEG compression within the TIFF file format.) + +The library includes a substantial amount of code that is not covered by the +JPEG standard but is necessary for typical applications of JPEG. These +functions preprocess the image before JPEG compression or postprocess it after +decompression. They include colorspace conversion, downsampling/upsampling, +and color quantization. This code can be omitted if not needed. + +A wide range of quality vs. speed tradeoffs are possible in JPEG processing, +and even more so in decompression postprocessing. The decompression library +provides multiple implementations that cover most of the useful tradeoffs, +ranging from very-high-quality down to fast-preview operation. On the +compression side we have generally not provided low-quality choices, since +compression is normally less time-critical. It should be understood that the +low-quality modes may not meet the JPEG standard's accuracy requirements; +nonetheless, they are useful for viewers. + + +*** Portability issues *** + +Portability is an essential requirement for the library. The key portability +issues that show up at the level of system architecture are: + +1. Memory usage. We want the code to be able to run on PC-class machines +with limited memory. Images should therefore be processed sequentially (in +strips), to avoid holding the whole image in memory at once. Where a +full-image buffer is necessary, we should be able to use either virtual memory +or temporary files. + +2. Near/far pointer distinction. To run efficiently on 80x86 machines, the +code should distinguish "small" objects (kept in near data space) from +"large" ones (kept in far data space). This is an annoying restriction, but +fortunately it does not impact code quality for less brain-damaged machines, +and the source code clutter turns out to be minimal with sufficient use of +pointer typedefs. + +3. Data precision. We assume that "char" is at least 8 bits, "short" and +"int" at least 16, "long" at least 32. The code will work fine with larger +data sizes, although memory may be used inefficiently in some cases. However, +the JPEG compressed datastream must ultimately appear on external storage as a +sequence of 8-bit bytes if it is to conform to the standard. This may pose a +problem on machines where char is wider than 8 bits. The library represents +compressed data as an array of values of typedef JOCTET. If no data type +exactly 8 bits wide is available, custom data source and data destination +modules must be written to unpack and pack the chosen JOCTET datatype into +8-bit external representation. + + +*** System overview *** + +The compressor and decompressor are each divided into two main sections: +the JPEG compressor or decompressor proper, and the preprocessing or +postprocessing functions. The interface between these two sections is the +image data that the official JPEG spec regards as its input or output: this +data is in the colorspace to be used for compression, and it is downsampled +to the sampling factors to be used. The preprocessing and postprocessing +steps are responsible for converting a normal image representation to or from +this form. (Those few applications that want to deal with YCbCr downsampled +data can skip the preprocessing or postprocessing step.) + +Looking more closely, the compressor library contains the following main +elements: + + Preprocessing: + * Color space conversion (e.g., RGB to YCbCr). + * Edge expansion and downsampling. Optionally, this step can do simple + smoothing --- this is often helpful for low-quality source data. + JPEG proper: + * MCU assembly, DCT, quantization. + * Entropy coding (sequential or progressive, Huffman or arithmetic). + +In addition to these modules we need overall control, marker generation, +and support code (memory management & error handling). There is also a +module responsible for physically writing the output data --- typically +this is just an interface to fwrite(), but some applications may need to +do something else with the data. + +The decompressor library contains the following main elements: + + JPEG proper: + * Entropy decoding (sequential or progressive, Huffman or arithmetic). + * Dequantization, inverse DCT, MCU disassembly. + Postprocessing: + * Upsampling. Optionally, this step may be able to do more general + rescaling of the image. + * Color space conversion (e.g., YCbCr to RGB). This step may also + provide gamma adjustment [ currently it does not ]. + * Optional color quantization (e.g., reduction to 256 colors). + * Optional color precision reduction (e.g., 24-bit to 15-bit color). + [This feature is not currently implemented.] + +We also need overall control, marker parsing, and a data source module. +The support code (memory management & error handling) can be shared with +the compression half of the library. + +There may be several implementations of each of these elements, particularly +in the decompressor, where a wide range of speed/quality tradeoffs is very +useful. It must be understood that some of the best speedups involve +merging adjacent steps in the pipeline. For example, upsampling, color space +conversion, and color quantization might all be done at once when using a +low-quality ordered-dither technique. The system architecture is designed to +allow such merging where appropriate. + + +Note: it is convenient to regard edge expansion (padding to block boundaries) +as a preprocessing/postprocessing function, even though the JPEG spec includes +it in compression/decompression. We do this because downsampling/upsampling +can be simplified a little if they work on padded data: it's not necessary to +have special cases at the right and bottom edges. Therefore the interface +buffer is always an integral number of blocks wide and high, and we expect +compression preprocessing to pad the source data properly. Padding will occur +only to the next block (N-sample) boundary. In an interleaved-scan situation, +additional dummy blocks may be used to fill out MCUs, but the MCU assembly and +disassembly logic will create or discard these blocks internally. (This is +advantageous for speed reasons, since we avoid DCTing the dummy blocks. +It also permits a small reduction in file size, because the compressor can +choose dummy block contents so as to minimize their size in compressed form. +Finally, it makes the interface buffer specification independent of whether +the file is actually interleaved or not.) Applications that wish to deal +directly with the downsampled data must provide similar buffering and padding +for odd-sized images. + + +*** Poor man's object-oriented programming *** + +It should be clear by now that we have a lot of quasi-independent processing +steps, many of which have several possible behaviors. To avoid cluttering the +code with lots of switch statements, we use a simple form of object-style +programming to separate out the different possibilities. + +For example, two different color quantization algorithms could be implemented +as two separate modules that present the same external interface; at runtime, +the calling code will access the proper module indirectly through an "object". + +We can get the limited features we need while staying within portable C. +The basic tool is a function pointer. An "object" is just a struct +containing one or more function pointer fields, each of which corresponds to +a method name in real object-oriented languages. During initialization we +fill in the function pointers with references to whichever module we have +determined we need to use in this run. Then invocation of the module is done +by indirecting through a function pointer; on most machines this is no more +expensive than a switch statement, which would be the only other way of +making the required run-time choice. The really significant benefit, of +course, is keeping the source code clean and well structured. + +We can also arrange to have private storage that varies between different +implementations of the same kind of object. We do this by making all the +module-specific object structs be separately allocated entities, which will +be accessed via pointers in the master compression or decompression struct. +The "public" fields or methods for a given kind of object are specified by +a commonly known struct. But a module's initialization code can allocate +a larger struct that contains the common struct as its first member, plus +additional private fields. With appropriate pointer casting, the module's +internal functions can access these private fields. (For a simple example, +see jdatadst.c, which implements the external interface specified by struct +jpeg_destination_mgr, but adds extra fields.) + +(Of course this would all be a lot easier if we were using C++, but we are +not yet prepared to assume that everyone has a C++ compiler.) + +An important benefit of this scheme is that it is easy to provide multiple +versions of any method, each tuned to a particular case. While a lot of +precalculation might be done to select an optimal implementation of a method, +the cost per invocation is constant. For example, the upsampling step might +have a "generic" method, plus one or more "hardwired" methods for the most +popular sampling factors; the hardwired methods would be faster because they'd +use straight-line code instead of for-loops. The cost to determine which +method to use is paid only once, at startup, and the selection criteria are +hidden from the callers of the method. + +This plan differs a little bit from usual object-oriented structures, in that +only one instance of each object class will exist during execution. The +reason for having the class structure is that on different runs we may create +different instances (choose to execute different modules). You can think of +the term "method" as denoting the common interface presented by a particular +set of interchangeable functions, and "object" as denoting a group of related +methods, or the total shared interface behavior of a group of modules. + + +*** Overall control structure *** + +We previously mentioned the need for overall control logic in the compression +and decompression libraries. In IJG implementations prior to v5, overall +control was mostly provided by "pipeline control" modules, which proved to be +large, unwieldy, and hard to understand. To improve the situation, the +control logic has been subdivided into multiple modules. The control modules +consist of: + +1. Master control for module selection and initialization. This has two +responsibilities: + + 1A. Startup initialization at the beginning of image processing. + The individual processing modules to be used in this run are selected + and given initialization calls. + + 1B. Per-pass control. This determines how many passes will be performed + and calls each active processing module to configure itself + appropriately at the beginning of each pass. End-of-pass processing, + where necessary, is also invoked from the master control module. + + Method selection is partially distributed, in that a particular processing + module may contain several possible implementations of a particular method, + which it will select among when given its initialization call. The master + control code need only be concerned with decisions that affect more than + one module. + +2. Data buffering control. A separate control module exists for each + inter-processing-step data buffer. This module is responsible for + invoking the processing steps that write or read that data buffer. + +Each buffer controller sees the world as follows: + +input data => processing step A => buffer => processing step B => output data + | | | + ------------------ controller ------------------ + +The controller knows the dataflow requirements of steps A and B: how much data +they want to accept in one chunk and how much they output in one chunk. Its +function is to manage its buffer and call A and B at the proper times. + +A data buffer control module may itself be viewed as a processing step by a +higher-level control module; thus the control modules form a binary tree with +elementary processing steps at the leaves of the tree. + +The control modules are objects. A considerable amount of flexibility can +be had by replacing implementations of a control module. For example: +* Merging of adjacent steps in the pipeline is done by replacing a control + module and its pair of processing-step modules with a single processing- + step module. (Hence the possible merges are determined by the tree of + control modules.) +* In some processing modes, a given interstep buffer need only be a "strip" + buffer large enough to accommodate the desired data chunk sizes. In other + modes, a full-image buffer is needed and several passes are required. + The control module determines which kind of buffer is used and manipulates + virtual array buffers as needed. One or both processing steps may be + unaware of the multi-pass behavior. + +In theory, we might be able to make all of the data buffer controllers +interchangeable and provide just one set of implementations for all. In +practice, each one contains considerable special-case processing for its +particular job. The buffer controller concept should be regarded as an +overall system structuring principle, not as a complete description of the +task performed by any one controller. + + +*** Compression object structure *** + +Here is a sketch of the logical structure of the JPEG compression library: + + |-- Colorspace conversion + |-- Preprocessing controller --| + | |-- Downsampling +Main controller --| + | |-- Forward DCT, quantize + |-- Coefficient controller --| + |-- Entropy encoding + +This sketch also describes the flow of control (subroutine calls) during +typical image data processing. Each of the components shown in the diagram is +an "object" which may have several different implementations available. One +or more source code files contain the actual implementation(s) of each object. + +The objects shown above are: + +* Main controller: buffer controller for the subsampled-data buffer, which + holds the preprocessed input data. This controller invokes preprocessing to + fill the subsampled-data buffer, and JPEG compression to empty it. There is + usually no need for a full-image buffer here; a strip buffer is adequate. + +* Preprocessing controller: buffer controller for the downsampling input data + buffer, which lies between colorspace conversion and downsampling. Note + that a unified conversion/downsampling module would probably replace this + controller entirely. + +* Colorspace conversion: converts application image data into the desired + JPEG color space; also changes the data from pixel-interleaved layout to + separate component planes. Processes one pixel row at a time. + +* Downsampling: performs reduction of chroma components as required. + Optionally may perform pixel-level smoothing as well. Processes a "row + group" at a time, where a row group is defined as Vmax pixel rows of each + component before downsampling, and Vk sample rows afterwards (remember Vk + differs across components). Some downsampling or smoothing algorithms may + require context rows above and below the current row group; the + preprocessing controller is responsible for supplying these rows via proper + buffering. The downsampler is responsible for edge expansion at the right + edge (i.e., extending each sample row to a multiple of N samples); but the + preprocessing controller is responsible for vertical edge expansion (i.e., + duplicating the bottom sample row as needed to make a multiple of N rows). + +* Coefficient controller: buffer controller for the DCT-coefficient data. + This controller handles MCU assembly, including insertion of dummy DCT + blocks when needed at the right or bottom edge. When performing + Huffman-code optimization or emitting a multiscan JPEG file, this + controller is responsible for buffering the full image. The equivalent of + one fully interleaved MCU row of subsampled data is processed per call, + even when the JPEG file is noninterleaved. + +* Forward DCT and quantization: Perform DCT, quantize, and emit coefficients. + Works on one or more DCT blocks at a time. (Note: the coefficients are now + emitted in normal array order, which the entropy encoder is expected to + convert to zigzag order as necessary. Prior versions of the IJG code did + the conversion to zigzag order within the quantization step.) + +* Entropy encoding: Perform Huffman or arithmetic entropy coding and emit the + coded data to the data destination module. Works on one MCU per call. + For progressive JPEG, the same DCT blocks are fed to the entropy coder + during each pass, and the coder must emit the appropriate subset of + coefficients. + +In addition to the above objects, the compression library includes these +objects: + +* Master control: determines the number of passes required, controls overall + and per-pass initialization of the other modules. + +* Marker writing: generates JPEG markers (except for RSTn, which is emitted + by the entropy encoder when needed). + +* Data destination manager: writes the output JPEG datastream to its final + destination (e.g., a file). The destination manager supplied with the + library knows how to write to a stdio stream or to a memory buffer; + for other behaviors, the surrounding application may provide its own + destination manager. + +* Memory manager: allocates and releases memory, controls virtual arrays + (with backing store management, where required). + +* Error handler: performs formatting and output of error and trace messages; + determines handling of nonfatal errors. The surrounding application may + override some or all of this object's methods to change error handling. + +* Progress monitor: supports output of "percent-done" progress reports. + This object represents an optional callback to the surrounding application: + if wanted, it must be supplied by the application. + +The error handler, destination manager, and progress monitor objects are +defined as separate objects in order to simplify application-specific +customization of the JPEG library. A surrounding application may override +individual methods or supply its own all-new implementation of one of these +objects. The object interfaces for these objects are therefore treated as +part of the application interface of the library, whereas the other objects +are internal to the library. + +The error handler and memory manager are shared by JPEG compression and +decompression; the progress monitor, if used, may be shared as well. + + +*** Decompression object structure *** + +Here is a sketch of the logical structure of the JPEG decompression library: + + |-- Entropy decoding + |-- Coefficient controller --| + | |-- Dequantize, Inverse DCT +Main controller --| + | |-- Upsampling + |-- Postprocessing controller --| |-- Colorspace conversion + |-- Color quantization + |-- Color precision reduction + +As before, this diagram also represents typical control flow. The objects +shown are: + +* Main controller: buffer controller for the subsampled-data buffer, which + holds the output of JPEG decompression proper. This controller's primary + task is to feed the postprocessing procedure. Some upsampling algorithms + may require context rows above and below the current row group; when this + is true, the main controller is responsible for managing its buffer so as + to make context rows available. In the current design, the main buffer is + always a strip buffer; a full-image buffer is never required. + +* Coefficient controller: buffer controller for the DCT-coefficient data. + This controller handles MCU disassembly, including deletion of any dummy + DCT blocks at the right or bottom edge. When reading a multiscan JPEG + file, this controller is responsible for buffering the full image. + (Buffering DCT coefficients, rather than samples, is necessary to support + progressive JPEG.) The equivalent of one fully interleaved MCU row of + subsampled data is processed per call, even when the source JPEG file is + noninterleaved. + +* Entropy decoding: Read coded data from the data source module and perform + Huffman or arithmetic entropy decoding. Works on one MCU per call. + For progressive JPEG decoding, the coefficient controller supplies the prior + coefficients of each MCU (initially all zeroes), which the entropy decoder + modifies in each scan. + +* Dequantization and inverse DCT: like it says. Note that the coefficients + buffered by the coefficient controller have NOT been dequantized; we + merge dequantization and inverse DCT into a single step for speed reasons. + When scaled-down output is asked for, simplified DCT algorithms may be used + that need fewer coefficients and emit fewer samples per DCT block, not the + full 8x8. Works on one DCT block at a time. + +* Postprocessing controller: buffer controller for the color quantization + input buffer, when quantization is in use. (Without quantization, this + controller just calls the upsampler.) For two-pass quantization, this + controller is responsible for buffering the full-image data. + +* Upsampling: restores chroma components to full size. (May support more + general output rescaling, too. Note that if undersized DCT outputs have + been emitted by the DCT module, this module must adjust so that properly + sized outputs are created.) Works on one row group at a time. This module + also calls the color conversion module, so its top level is effectively a + buffer controller for the upsampling->color conversion buffer. However, in + all but the highest-quality operating modes, upsampling and color + conversion are likely to be merged into a single step. + +* Colorspace conversion: convert from JPEG color space to output color space, + and change data layout from separate component planes to pixel-interleaved. + Works on one pixel row at a time. + +* Color quantization: reduce the data to colormapped form, using either an + externally specified colormap or an internally generated one. This module + is not used for full-color output. Works on one pixel row at a time; may + require two passes to generate a color map. Note that the output will + always be a single component representing colormap indexes. In the current + design, the output values are JSAMPLEs, so an 8-bit compilation cannot + quantize to more than 256 colors. This is unlikely to be a problem in + practice. + +* Color reduction: this module handles color precision reduction, e.g., + generating 15-bit color (5 bits/primary) from JPEG's 24-bit output. + Not quite clear yet how this should be handled... should we merge it with + colorspace conversion??? + +Note that some high-speed operating modes might condense the entire +postprocessing sequence to a single module (upsample, color convert, and +quantize in one step). + +In addition to the above objects, the decompression library includes these +objects: + +* Master control: determines the number of passes required, controls overall + and per-pass initialization of the other modules. This is subdivided into + input and output control: jdinput.c controls only input-side processing, + while jdmaster.c handles overall initialization and output-side control. + +* Marker reading: decodes JPEG markers (except for RSTn). + +* Data source manager: supplies the input JPEG datastream. The source + manager supplied with the library knows how to read from a stdio stream + or from a memory buffer; for other behaviors, the surrounding application + may provide its own source manager. + +* Memory manager: same as for compression library. + +* Error handler: same as for compression library. + +* Progress monitor: same as for compression library. + +As with compression, the data source manager, error handler, and progress +monitor are candidates for replacement by a surrounding application. + + +*** Decompression input and output separation *** + +To support efficient incremental display of progressive JPEG files, the +decompressor is divided into two sections that can run independently: + +1. Data input includes marker parsing, entropy decoding, and input into the + coefficient controller's DCT coefficient buffer. Note that this + processing is relatively cheap and fast. + +2. Data output reads from the DCT coefficient buffer and performs the IDCT + and all postprocessing steps. + +For a progressive JPEG file, the data input processing is allowed to get +arbitrarily far ahead of the data output processing. (This occurs only +if the application calls jpeg_consume_input(); otherwise input and output +run in lockstep, since the input section is called only when the output +section needs more data.) In this way the application can avoid making +extra display passes when data is arriving faster than the display pass +can run. Furthermore, it is possible to abort an output pass without +losing anything, since the coefficient buffer is read-only as far as the +output section is concerned. See libjpeg.txt for more detail. + +A full-image coefficient array is only created if the JPEG file has multiple +scans (or if the application specifies buffered-image mode anyway). When +reading a single-scan file, the coefficient controller normally creates only +a one-MCU buffer, so input and output processing must run in lockstep in this +case. jpeg_consume_input() is effectively a no-op in this situation. + +The main impact of dividing the decompressor in this fashion is that we must +be very careful with shared variables in the cinfo data structure. Each +variable that can change during the course of decompression must be +classified as belonging to data input or data output, and each section must +look only at its own variables. For example, the data output section may not +depend on any of the variables that describe the current scan in the JPEG +file, because these may change as the data input section advances into a new +scan. + +The progress monitor is (somewhat arbitrarily) defined to treat input of the +file as one pass when buffered-image mode is not used, and to ignore data +input work completely when buffered-image mode is used. Note that the +library has no reliable way to predict the number of passes when dealing +with a progressive JPEG file, nor can it predict the number of output passes +in buffered-image mode. So the work estimate is inherently bogus anyway. + +No comparable division is currently made in the compression library, because +there isn't any real need for it. + + +*** Data formats *** + +Arrays of pixel sample values use the following data structure: + + typedef something JSAMPLE; a pixel component value, 0..MAXJSAMPLE + typedef JSAMPLE *JSAMPROW; ptr to a row of samples + typedef JSAMPROW *JSAMPARRAY; ptr to a list of rows + typedef JSAMPARRAY *JSAMPIMAGE; ptr to a list of color-component arrays + +The basic element type JSAMPLE will typically be one of unsigned char, +(signed) char, or short. Short will be used if samples wider than 8 bits are +to be supported (this is a compile-time option). Otherwise, unsigned char is +used if possible. If the compiler only supports signed chars, then it is +necessary to mask off the value when reading. Thus, all reads of JSAMPLE +values must be coded as "GETJSAMPLE(value)", where the macro will be defined +as "((value) & 0xFF)" on signed-char machines and "((int) (value))" elsewhere. + +With these conventions, JSAMPLE values can be assumed to be >= 0. This helps +simplify correct rounding during downsampling, etc. The JPEG standard's +specification that sample values run from -128..127 is accommodated by +subtracting 128 from the sample value in the DCT step. Similarly, during +decompression the output of the IDCT step will be immediately shifted back to +0..255. (NB: different values are required when 12-bit samples are in use. +The code is written in terms of MAXJSAMPLE and CENTERJSAMPLE, which will be +defined as 255 and 128 respectively in an 8-bit implementation, and as 4095 +and 2048 in a 12-bit implementation.) + +We use a pointer per row, rather than a two-dimensional JSAMPLE array. This +choice costs only a small amount of memory and has several benefits: +* Code using the data structure doesn't need to know the allocated width of + the rows. This simplifies edge expansion/compression, since we can work + in an array that's wider than the logical picture width. +* Indexing doesn't require multiplication; this is a performance win on many + machines. +* Arrays with more than 64K total elements can be supported even on machines + where malloc() cannot allocate chunks larger than 64K. +* The rows forming a component array may be allocated at different times + without extra copying. This trick allows some speedups in smoothing steps + that need access to the previous and next rows. + +Note that each color component is stored in a separate array; we don't use the +traditional layout in which the components of a pixel are stored together. +This simplifies coding of modules that work on each component independently, +because they don't need to know how many components there are. Furthermore, +we can read or write each component to a temporary file independently, which +is helpful when dealing with noninterleaved JPEG files. + +In general, a specific sample value is accessed by code such as + GETJSAMPLE(image[colorcomponent][row][col]) +where col is measured from the image left edge, but row is measured from the +first sample row currently in memory. Either of the first two indexings can +be precomputed by copying the relevant pointer. + + +Since most image-processing applications prefer to work on images in which +the components of a pixel are stored together, the data passed to or from the +surrounding application uses the traditional convention: a single pixel is +represented by N consecutive JSAMPLE values, and an image row is an array of +(# of color components)*(image width) JSAMPLEs. One or more rows of data can +be represented by a pointer of type JSAMPARRAY in this scheme. This scheme is +converted to component-wise storage inside the JPEG library. (Applications +that want to skip JPEG preprocessing or postprocessing will have to contend +with component-wise storage.) + + +Arrays of DCT-coefficient values use the following data structure: + + typedef short JCOEF; a 16-bit signed integer + typedef JCOEF JBLOCK[DCTSIZE2]; an 8x8 block of coefficients + typedef JBLOCK *JBLOCKROW; ptr to one horizontal row of 8x8 blocks + typedef JBLOCKROW *JBLOCKARRAY; ptr to a list of such rows + typedef JBLOCKARRAY *JBLOCKIMAGE; ptr to a list of color component arrays + +The underlying type is at least a 16-bit signed integer; while "short" is big +enough on all machines of interest, on some machines it is preferable to use +"int" for speed reasons, despite the storage cost. Coefficients are grouped +into 8x8 blocks (but we always use #defines DCTSIZE and DCTSIZE2 rather than +"8" and "64"). + +The contents of a coefficient block may be in either "natural" or zigzagged +order, and may be true values or divided by the quantization coefficients, +depending on where the block is in the processing pipeline. In the current +library, coefficient blocks are kept in natural order everywhere; the entropy +codecs zigzag or dezigzag the data as it is written or read. The blocks +contain quantized coefficients everywhere outside the DCT/IDCT subsystems. +(This latter decision may need to be revisited to support variable +quantization a la JPEG Part 3.) + +Notice that the allocation unit is now a row of 8x8 coefficient blocks, +corresponding to N rows of samples. Otherwise the structure is much the same +as for samples, and for the same reasons. + +On machines where malloc() can't handle a request bigger than 64Kb, this data +structure limits us to rows of less than 512 JBLOCKs, or a picture width of +4000+ pixels. This seems an acceptable restriction. + + +On 80x86 machines, the bottom-level pointer types (JSAMPROW and JBLOCKROW) +must be declared as "far" pointers, but the upper levels can be "near" +(implying that the pointer lists are allocated in the DS segment). +We use a #define symbol FAR, which expands to the "far" keyword when +compiling on 80x86 machines and to nothing elsewhere. + + +*** Suspendable processing *** + +In some applications it is desirable to use the JPEG library as an +incremental, memory-to-memory filter. In this situation the data source or +destination may be a limited-size buffer, and we can't rely on being able to +empty or refill the buffer at arbitrary times. Instead the application would +like to have control return from the library at buffer overflow/underrun, and +then resume compression or decompression at a later time. + +This scenario is supported for simple cases. (For anything more complex, we +recommend that the application "bite the bullet" and develop real multitasking +capability.) The libjpeg.txt file goes into more detail about the usage and +limitations of this capability; here we address the implications for library +structure. + +The essence of the problem is that the entropy codec (coder or decoder) must +be prepared to stop at arbitrary times. In turn, the controllers that call +the entropy codec must be able to stop before having produced or consumed all +the data that they normally would handle in one call. That part is reasonably +straightforward: we make the controller call interfaces include "progress +counters" which indicate the number of data chunks successfully processed, and +we require callers to test the counter rather than just assume all of the data +was processed. + +Rather than trying to restart at an arbitrary point, the current Huffman +codecs are designed to restart at the beginning of the current MCU after a +suspension due to buffer overflow/underrun. At the start of each call, the +codec's internal state is loaded from permanent storage (in the JPEG object +structures) into local variables. On successful completion of the MCU, the +permanent state is updated. (This copying is not very expensive, and may even +lead to *improved* performance if the local variables can be registerized.) +If a suspension occurs, the codec simply returns without updating the state, +thus effectively reverting to the start of the MCU. Note that this implies +leaving some data unprocessed in the source/destination buffer (ie, the +compressed partial MCU). The data source/destination module interfaces are +specified so as to make this possible. This also implies that the data buffer +must be large enough to hold a worst-case compressed MCU; a couple thousand +bytes should be enough. + +In a successive-approximation AC refinement scan, the progressive Huffman +decoder has to be able to undo assignments of newly nonzero coefficients if it +suspends before the MCU is complete, since decoding requires distinguishing +previously-zero and previously-nonzero coefficients. This is a bit tedious +but probably won't have much effect on performance. Other variants of Huffman +decoding need not worry about this, since they will just store the same values +again if forced to repeat the MCU. + +This approach would probably not work for an arithmetic codec, since its +modifiable state is quite large and couldn't be copied cheaply. Instead it +would have to suspend and resume exactly at the point of the buffer end. + +The JPEG marker reader is designed to cope with suspension at an arbitrary +point. It does so by backing up to the start of the marker parameter segment, +so the data buffer must be big enough to hold the largest marker of interest. +Again, a couple KB should be adequate. (A special "skip" convention is used +to bypass COM and APPn markers, so these can be larger than the buffer size +without causing problems; otherwise a 64K buffer would be needed in the worst +case.) + +The JPEG marker writer currently does *not* cope with suspension. +We feel that this is not necessary; it is much easier simply to require +the application to ensure there is enough buffer space before starting. (An +empty 2K buffer is more than sufficient for the header markers; and ensuring +there are a dozen or two bytes available before calling jpeg_finish_compress() +will suffice for the trailer.) This would not work for writing multi-scan +JPEG files, but we simply do not intend to support that capability with +suspension. + + +*** Memory manager services *** + +The JPEG library's memory manager controls allocation and deallocation of +memory, and it manages large "virtual" data arrays on machines where the +operating system does not provide virtual memory. Note that the same +memory manager serves both compression and decompression operations. + +In all cases, allocated objects are tied to a particular compression or +decompression master record, and they will be released when that master +record is destroyed. + +The memory manager does not provide explicit deallocation of objects. +Instead, objects are created in "pools" of free storage, and a whole pool +can be freed at once. This approach helps prevent storage-leak bugs, and +it speeds up operations whenever malloc/free are slow (as they often are). +The pools can be regarded as lifetime identifiers for objects. Two +pools/lifetimes are defined: + * JPOOL_PERMANENT lasts until master record is destroyed + * JPOOL_IMAGE lasts until done with image (JPEG datastream) +Permanent lifetime is used for parameters and tables that should be carried +across from one datastream to another; this includes all application-visible +parameters. Image lifetime is used for everything else. (A third lifetime, +JPOOL_PASS = one processing pass, was originally planned. However it was +dropped as not being worthwhile. The actual usage patterns are such that the +peak memory usage would be about the same anyway; and having per-pass storage +substantially complicates the virtual memory allocation rules --- see below.) + +The memory manager deals with three kinds of object: +1. "Small" objects. Typically these require no more than 10K-20K total. +2. "Large" objects. These may require tens to hundreds of K depending on + image size. Semantically they behave the same as small objects, but we + distinguish them for two reasons: + * On MS-DOS machines, large objects are referenced by FAR pointers, + small objects by NEAR pointers. + * Pool allocation heuristics may differ for large and small objects. + Note that individual "large" objects cannot exceed the size allowed by + type size_t, which may be 64K or less on some machines. +3. "Virtual" objects. These are large 2-D arrays of JSAMPLEs or JBLOCKs + (typically large enough for the entire image being processed). The + memory manager provides stripwise access to these arrays. On machines + without virtual memory, the rest of the array may be swapped out to a + temporary file. + +(Note: JSAMPARRAY and JBLOCKARRAY data structures are a combination of large +objects for the data proper and small objects for the row pointers. For +convenience and speed, the memory manager provides single routines to create +these structures. Similarly, virtual arrays include a small control block +and a JSAMPARRAY or JBLOCKARRAY working buffer, all created with one call.) + +In the present implementation, virtual arrays are only permitted to have image +lifespan. (Permanent lifespan would not be reasonable, and pass lifespan is +not very useful since a virtual array's raison d'etre is to store data for +multiple passes through the image.) We also expect that only "small" objects +will be given permanent lifespan, though this restriction is not required by +the memory manager. + +In a non-virtual-memory machine, some performance benefit can be gained by +making the in-memory buffers for virtual arrays be as large as possible. +(For small images, the buffers might fit entirely in memory, so blind +swapping would be very wasteful.) The memory manager will adjust the height +of the buffers to fit within a prespecified maximum memory usage. In order +to do this in a reasonably optimal fashion, the manager needs to allocate all +of the virtual arrays at once. Therefore, there isn't a one-step allocation +routine for virtual arrays; instead, there is a "request" routine that simply +allocates the control block, and a "realize" routine (called just once) that +determines space allocation and creates all of the actual buffers. The +realize routine must allow for space occupied by non-virtual large objects. +(We don't bother to factor in the space needed for small objects, on the +grounds that it isn't worth the trouble.) + +To support all this, we establish the following protocol for doing business +with the memory manager: + 1. Modules must request virtual arrays (which may have only image lifespan) + during the initial setup phase, i.e., in their jinit_xxx routines. + 2. All "large" objects (including JSAMPARRAYs and JBLOCKARRAYs) must also be + allocated during initial setup. + 3. realize_virt_arrays will be called at the completion of initial setup. + The above conventions ensure that sufficient information is available + for it to choose a good size for virtual array buffers. +Small objects of any lifespan may be allocated at any time. We expect that +the total space used for small objects will be small enough to be negligible +in the realize_virt_arrays computation. + +In a virtual-memory machine, we simply pretend that the available space is +infinite, thus causing realize_virt_arrays to decide that it can allocate all +the virtual arrays as full-size in-memory buffers. The overhead of the +virtual-array access protocol is very small when no swapping occurs. + +A virtual array can be specified to be "pre-zeroed"; when this flag is set, +never-yet-written sections of the array are set to zero before being made +available to the caller. If this flag is not set, never-written sections +of the array contain garbage. (This feature exists primarily because the +equivalent logic would otherwise be needed in jdcoefct.c for progressive +JPEG mode; we may as well make it available for possible other uses.) + +The first write pass on a virtual array is required to occur in top-to-bottom +order; read passes, as well as any write passes after the first one, may +access the array in any order. This restriction exists partly to simplify +the virtual array control logic, and partly because some file systems may not +support seeking beyond the current end-of-file in a temporary file. The main +implication of this restriction is that rearrangement of rows (such as +converting top-to-bottom data order to bottom-to-top) must be handled while +reading data out of the virtual array, not while putting it in. + + +*** Memory manager internal structure *** + +To isolate system dependencies as much as possible, we have broken the +memory manager into two parts. There is a reasonably system-independent +"front end" (jmemmgr.c) and a "back end" that contains only the code +likely to change across systems. All of the memory management methods +outlined above are implemented by the front end. The back end provides +the following routines for use by the front end (none of these routines +are known to the rest of the JPEG code): + +jpeg_mem_init, jpeg_mem_term system-dependent initialization/shutdown + +jpeg_get_small, jpeg_free_small interface to malloc and free library routines + (or their equivalents) + +jpeg_get_large, jpeg_free_large interface to FAR malloc/free in MSDOS machines; + else usually the same as + jpeg_get_small/jpeg_free_small + +jpeg_mem_available estimate available memory + +jpeg_open_backing_store create a backing-store object + +read_backing_store, manipulate a backing-store object +write_backing_store, +close_backing_store + +On some systems there will be more than one type of backing-store object +(specifically, in MS-DOS a backing store file might be an area of extended +memory as well as a disk file). jpeg_open_backing_store is responsible for +choosing how to implement a given object. The read/write/close routines +are method pointers in the structure that describes a given object; this +lets them be different for different object types. + +It may be necessary to ensure that backing store objects are explicitly +released upon abnormal program termination. For example, MS-DOS won't free +extended memory by itself. To support this, we will expect the main program +or surrounding application to arrange to call self_destruct (typically via +jpeg_destroy) upon abnormal termination. This may require a SIGINT signal +handler or equivalent. We don't want to have the back end module install its +own signal handler, because that would pre-empt the surrounding application's +ability to control signal handling. + +The IJG distribution includes several memory manager back end implementations. +Usually the same back end should be suitable for all applications on a given +system, but it is possible for an application to supply its own back end at +need. + + +*** Implications of DNL marker *** + +Some JPEG files may use a DNL marker to postpone definition of the image +height (this would be useful for a fax-like scanner's output, for instance). +In these files the SOF marker claims the image height is 0, and you only +find out the true image height at the end of the first scan. + +We could read these files as follows: +1. Upon seeing zero image height, replace it by 65535 (the maximum allowed). +2. When the DNL is found, update the image height in the global image + descriptor. +This implies that control modules must avoid making copies of the image +height, and must re-test for termination after each MCU row. This would +be easy enough to do. + +In cases where image-size data structures are allocated, this approach will +result in very inefficient use of virtual memory or much-larger-than-necessary +temporary files. This seems acceptable for something that probably won't be a +mainstream usage. People might have to forgo use of memory-hogging options +(such as two-pass color quantization or noninterleaved JPEG files) if they +want efficient conversion of such files. (One could improve efficiency by +demanding a user-supplied upper bound for the height, less than 65536; in most +cases it could be much less.) + +The standard also permits the SOF marker to overestimate the image height, +with a DNL to give the true, smaller height at the end of the first scan. +This would solve the space problems if the overestimate wasn't too great. +However, it implies that you don't even know whether DNL will be used. + +This leads to a couple of very serious objections: +1. Testing for a DNL marker must occur in the inner loop of the decompressor's + Huffman decoder; this implies a speed penalty whether the feature is used + or not. +2. There is no way to hide the last-minute change in image height from an + application using the decoder. Thus *every* application using the IJG + library would suffer a complexity penalty whether it cared about DNL or + not. +We currently do not support DNL because of these problems. + +A different approach is to insist that DNL-using files be preprocessed by a +separate program that reads ahead to the DNL, then goes back and fixes the SOF +marker. This is a much simpler solution and is probably far more efficient. +Even if one wants piped input, buffering the first scan of the JPEG file needs +a lot smaller temp file than is implied by the maximum-height method. For +this approach we'd simply treat DNL as a no-op in the decompressor (at most, +check that it matches the SOF image height). + +We will not worry about making the compressor capable of outputting DNL. +Something similar to the first scheme above could be applied if anyone ever +wants to make that work. diff --git a/Source/LibJPEG/usage.txt b/Source/LibJPEG/usage.txt index c91ddff..de9def7 100644 --- a/Source/LibJPEG/usage.txt +++ b/Source/LibJPEG/usage.txt @@ -1,637 +1,637 @@ -USAGE instructions for the Independent JPEG Group's JPEG software -================================================================= - -This file describes usage of the JPEG conversion programs cjpeg and djpeg, -as well as the utility programs jpegtran, rdjpgcom and wrjpgcom. (See -the other documentation files if you wish to use the JPEG library within -your own programs.) - -If you are on a Unix machine you may prefer to read the Unix-style manual -pages in files cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1. - - -INTRODUCTION - -These programs implement JPEG image encoding, decoding, and transcoding. -JPEG (pronounced "jay-peg") is a standardized compression method for -full-color and gray-scale images. - - -GENERAL USAGE - -We provide two programs, cjpeg to compress an image file into JPEG format, -and djpeg to decompress a JPEG file back into a conventional image format. - -On Unix-like systems, you say: - cjpeg [switches] [imagefile] >jpegfile -or - djpeg [switches] [jpegfile] >imagefile -The programs read the specified input file, or standard input if none is -named. They always write to standard output (with trace/error messages to -standard error). These conventions are handy for piping images between -programs. - -On most non-Unix systems, you say: - cjpeg [switches] imagefile jpegfile -or - djpeg [switches] jpegfile imagefile -i.e., both the input and output files are named on the command line. This -style is a little more foolproof, and it loses no functionality if you don't -have pipes. (You can get this style on Unix too, if you prefer, by defining -TWO_FILE_COMMANDLINE when you compile the programs; see install.txt.) - -You can also say: - cjpeg [switches] -outfile jpegfile imagefile -or - djpeg [switches] -outfile imagefile jpegfile -This syntax works on all systems, so it is useful for scripts. - -The currently supported image file formats are: PPM (PBMPLUS color format), -PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster Toolkit -format). (RLE is supported only if the URT library is available.) -cjpeg recognizes the input image format automatically, with the exception -of some Targa-format files. You have to tell djpeg which format to generate. - -JPEG files are in the defacto standard JFIF file format. There are other, -less widely used JPEG-based file formats, but we don't support them. - -All switch names may be abbreviated; for example, -grayscale may be written --gray or -gr. Most of the "basic" switches can be abbreviated to as little as -one letter. Upper and lower case are equivalent (-BMP is the same as -bmp). -British spellings are also accepted (e.g., -greyscale), though for brevity -these are not mentioned below. - - -CJPEG DETAILS - -The basic command line switches for cjpeg are: - - -quality N[,...] Scale quantization tables to adjust image quality. - Quality is 0 (worst) to 100 (best); default is 75. - (See below for more info.) - - -grayscale Create monochrome JPEG file from color input. - Be sure to use this switch when compressing a grayscale - BMP file, because cjpeg isn't bright enough to notice - whether a BMP file uses only shades of gray. By - saying -grayscale, you'll get a smaller JPEG file that - takes less time to process. - - -rgb Create RGB JPEG file. - Using this switch suppresses the conversion from RGB - colorspace input to the default YCbCr JPEG colorspace. - Use this switch in combination with the -block N - switch (see below) for lossless JPEG coding. - - -optimize Perform optimization of entropy encoding parameters. - Without this, default encoding parameters are used. - -optimize usually makes the JPEG file a little smaller, - but cjpeg runs somewhat slower and needs much more - memory. Image quality and speed of decompression are - unaffected by -optimize. - - -progressive Create progressive JPEG file (see below). - - -scale M/N Scale the output image by a factor M/N. Currently - supported scale factors are M/N with all N from 1 to - 16, where M is the destination DCT size, which is 8 by - default (see -block N switch below). - - -targa Input file is Targa format. Targa files that contain - an "identification" field will not be automatically - recognized by cjpeg; for such files you must specify - -targa to make cjpeg treat the input as Targa format. - For most Targa files, you won't need this switch. - -The -quality switch lets you trade off compressed file size against quality of -the reconstructed image: the higher the quality setting, the larger the JPEG -file, and the closer the output image will be to the original input. Normally -you want to use the lowest quality setting (smallest file) that decompresses -into something visually indistinguishable from the original image. For this -purpose the quality setting should be between 50 and 95; the default of 75 is -often about right. If you see defects at -quality 75, then go up 5 or 10 -counts at a time until you are happy with the output image. (The optimal -setting will vary from one image to another.) - --quality 100 will generate a quantization table of all 1's, minimizing loss -in the quantization step (but there is still information loss in subsampling, -as well as roundoff error). This setting is mainly of interest for -experimental purposes. Quality values above about 95 are NOT recommended for -normal use; the compressed file size goes up dramatically for hardly any gain -in output image quality. - -In the other direction, quality values below 50 will produce very small files -of low image quality. Settings around 5 to 10 might be useful in preparing an -index of a large image library, for example. Try -quality 2 (or so) for some -amusing Cubist effects. (Note: quality values below about 25 generate 2-byte -quantization tables, which are considered optional in the JPEG standard. -cjpeg emits a warning message when you give such a quality value, because some -other JPEG programs may be unable to decode the resulting file. Use -baseline -if you need to ensure compatibility at low quality values.) - -The -quality option has been extended in IJG version 7 for support of separate -quality settings for luminance and chrominance (or in general, for every -provided quantization table slot). This feature is useful for high-quality -applications which cannot accept the damage of color data by coarse -subsampling settings. You can now easily reduce the color data amount more -smoothly with finer control without separate subsampling. The resulting file -is fully compliant with standard JPEG decoders. -Note that the -quality ratings refer to the quantization table slots, and that -the last value is replicated if there are more q-table slots than parameters. -The default q-table slots are 0 for luminance and 1 for chrominance with -default tables as given in the JPEG standard. This is compatible with the old -behaviour in case that only one parameter is given, which is then used for -both luminance and chrominance (slots 0 and 1). More or custom quantization -tables can be set with -qtables and assigned to components with -qslots -parameter (see the "wizard" switches below). -CAUTION: You must explicitly add -sample 1x1 for efficient separate color -quality selection, since the default value used by library is 2x2! - -The -progressive switch creates a "progressive JPEG" file. In this type of -JPEG file, the data is stored in multiple scans of increasing quality. If the -file is being transmitted over a slow communications link, the decoder can use -the first scan to display a low-quality image very quickly, and can then -improve the display with each subsequent scan. The final image is exactly -equivalent to a standard JPEG file of the same quality setting, and the total -file size is about the same --- often a little smaller. - -Switches for advanced users: - - -arithmetic Use arithmetic coding. CAUTION: arithmetic coded JPEG - is not yet widely implemented, so many decoders will - be unable to view an arithmetic coded JPEG file at - all. - - -block N Set DCT block size. All N from 1 to 16 are possible. - Default is 8 (baseline format). - Larger values produce higher compression, - smaller values produce higher quality - (exact DCT stage possible with 1 or 2; with the - default quality of 75 and default Luminance qtable - the DCT+Quantization stage is lossless for N=1). - CAUTION: An implementation of the JPEG SmartScale - extension is required for this feature. SmartScale - enabled JPEG is not yet widely implemented, so many - decoders will be unable to view a SmartScale extended - JPEG file at all. - - -dct int Use integer DCT method (default). - -dct fast Use fast integer DCT (less accurate). - -dct float Use floating-point DCT method. - The float method is very slightly more accurate than - the int method, but is much slower unless your machine - has very fast floating-point hardware. Also note that - results of the floating-point method may vary slightly - across machines, while the integer methods should give - the same results everywhere. The fast integer method - is much less accurate than the other two. - - -nosmooth Don't use high-quality downsampling. - - -restart N Emit a JPEG restart marker every N MCU rows, or every - N MCU blocks if "B" is attached to the number. - -restart 0 (the default) means no restart markers. - - -smooth N Smooth the input image to eliminate dithering noise. - N, ranging from 1 to 100, indicates the strength of - smoothing. 0 (the default) means no smoothing. - - -maxmemory N Set limit for amount of memory to use in processing - large images. Value is in thousands of bytes, or - millions of bytes if "M" is attached to the number. - For example, -max 4m selects 4000000 bytes. If more - space is needed, temporary files will be used. - - -verbose Enable debug printout. More -v's give more printout. - or -debug Also, version information is printed at startup. - -The -restart option inserts extra markers that allow a JPEG decoder to -resynchronize after a transmission error. Without restart markers, any damage -to a compressed file will usually ruin the image from the point of the error -to the end of the image; with restart markers, the damage is usually confined -to the portion of the image up to the next restart marker. Of course, the -restart markers occupy extra space. We recommend -restart 1 for images that -will be transmitted across unreliable networks such as Usenet. - -The -smooth option filters the input to eliminate fine-scale noise. This is -often useful when converting dithered images to JPEG: a moderate smoothing -factor of 10 to 50 gets rid of dithering patterns in the input file, resulting -in a smaller JPEG file and a better-looking image. Too large a smoothing -factor will visibly blur the image, however. - -Switches for wizards: - - -baseline Force baseline-compatible quantization tables to be - generated. This clamps quantization values to 8 bits - even at low quality settings. (This switch is poorly - named, since it does not ensure that the output is - actually baseline JPEG. For example, you can use - -baseline and -progressive together.) - - -qtables file Use the quantization tables given in the specified - text file. - - -qslots N[,...] Select which quantization table to use for each color - component. - - -sample HxV[,...] Set JPEG sampling factors for each color component. - - -scans file Use the scan script given in the specified text file. - -The "wizard" switches are intended for experimentation with JPEG. If you -don't know what you are doing, DON'T USE THEM. These switches are documented -further in the file wizard.txt. - - -DJPEG DETAILS - -The basic command line switches for djpeg are: - - -colors N Reduce image to at most N colors. This reduces the - or -quantize N number of colors used in the output image, so that it - can be displayed on a colormapped display or stored in - a colormapped file format. For example, if you have - an 8-bit display, you'd need to reduce to 256 or fewer - colors. (-colors is the recommended name, -quantize - is provided only for backwards compatibility.) - - -fast Select recommended processing options for fast, low - quality output. (The default options are chosen for - highest quality output.) Currently, this is equivalent - to "-dct fast -nosmooth -onepass -dither ordered". - - -grayscale Force gray-scale output even if JPEG file is color. - Useful for viewing on monochrome displays; also, - djpeg runs noticeably faster in this mode. - - -scale M/N Scale the output image by a factor M/N. Currently - supported scale factors are M/N with all M from 1 to - 16, where N is the source DCT size, which is 8 for - baseline JPEG. If the /N part is omitted, then M - specifies the DCT scaled size to be applied on the - given input. For baseline JPEG this is equivalent to - M/8 scaling, since the source DCT size for baseline - JPEG is 8. Scaling is handy if the image is larger - than your screen; also, djpeg runs much faster when - scaling down the output. - - -bmp Select BMP output format (Windows flavor). 8-bit - colormapped format is emitted if -colors or -grayscale - is specified, or if the JPEG file is gray-scale; - otherwise, 24-bit full-color format is emitted. - - -gif Select GIF output format. Since GIF does not support - more than 256 colors, -colors 256 is assumed (unless - you specify a smaller number of colors). If you - specify -fast, the default number of colors is 216. - - -os2 Select BMP output format (OS/2 1.x flavor). 8-bit - colormapped format is emitted if -colors or -grayscale - is specified, or if the JPEG file is gray-scale; - otherwise, 24-bit full-color format is emitted. - - -pnm Select PBMPLUS (PPM/PGM) output format (this is the - default format). PGM is emitted if the JPEG file is - gray-scale or if -grayscale is specified; otherwise - PPM is emitted. - - -rle Select RLE output format. (Requires URT library.) - - -targa Select Targa output format. Gray-scale format is - emitted if the JPEG file is gray-scale or if - -grayscale is specified; otherwise, colormapped format - is emitted if -colors is specified; otherwise, 24-bit - full-color format is emitted. - -Switches for advanced users: - - -dct int Use integer DCT method (default). - -dct fast Use fast integer DCT (less accurate). - -dct float Use floating-point DCT method. - The float method is very slightly more accurate than - the int method, but is much slower unless your machine - has very fast floating-point hardware. Also note that - results of the floating-point method may vary slightly - across machines, while the integer methods should give - the same results everywhere. The fast integer method - is much less accurate than the other two. - - -dither fs Use Floyd-Steinberg dithering in color quantization. - -dither ordered Use ordered dithering in color quantization. - -dither none Do not use dithering in color quantization. - By default, Floyd-Steinberg dithering is applied when - quantizing colors; this is slow but usually produces - the best results. Ordered dither is a compromise - between speed and quality; no dithering is fast but - usually looks awful. Note that these switches have - no effect unless color quantization is being done. - Ordered dither is only available in -onepass mode. - - -map FILE Quantize to the colors used in the specified image - file. This is useful for producing multiple files - with identical color maps, or for forcing a predefined - set of colors to be used. The FILE must be a GIF - or PPM file. This option overrides -colors and - -onepass. - - -nosmooth Don't use high-quality upsampling. - - -onepass Use one-pass instead of two-pass color quantization. - The one-pass method is faster and needs less memory, - but it produces a lower-quality image. -onepass is - ignored unless you also say -colors N. Also, - the one-pass method is always used for gray-scale - output (the two-pass method is no improvement then). - - -maxmemory N Set limit for amount of memory to use in processing - large images. Value is in thousands of bytes, or - millions of bytes if "M" is attached to the number. - For example, -max 4m selects 4000000 bytes. If more - space is needed, temporary files will be used. - - -verbose Enable debug printout. More -v's give more printout. - or -debug Also, version information is printed at startup. - - -HINTS FOR CJPEG - -Color GIF files are not the ideal input for JPEG; JPEG is really intended for -compressing full-color (24-bit) images. In particular, don't try to convert -cartoons, line drawings, and other images that have only a few distinct -colors. GIF works great on these, JPEG does not. If you want to convert a -GIF to JPEG, you should experiment with cjpeg's -quality and -smooth options -to get a satisfactory conversion. -smooth 10 or so is often helpful. - -Avoid running an image through a series of JPEG compression/decompression -cycles. Image quality loss will accumulate; after ten or so cycles the image -may be noticeably worse than it was after one cycle. It's best to use a -lossless format while manipulating an image, then convert to JPEG format when -you are ready to file the image away. - -The -optimize option to cjpeg is worth using when you are making a "final" -version for posting or archiving. It's also a win when you are using low -quality settings to make very small JPEG files; the percentage improvement -is often a lot more than it is on larger files. (At present, -optimize -mode is always selected when generating progressive JPEG files.) - -GIF input files are no longer supported, to avoid the Unisys LZW patent. -(Conversion of GIF files to JPEG is usually a bad idea anyway.) - - -HINTS FOR DJPEG - -To get a quick preview of an image, use the -grayscale and/or -scale switches. -"-grayscale -scale 1/8" is the fastest case. - -Several options are available that trade off image quality to gain speed. -"-fast" turns on the recommended settings. - -"-dct fast" and/or "-nosmooth" gain speed at a small sacrifice in quality. -When producing a color-quantized image, "-onepass -dither ordered" is fast but -much lower quality than the default behavior. "-dither none" may give -acceptable results in two-pass mode, but is seldom tolerable in one-pass mode. - -If you are fortunate enough to have very fast floating point hardware, -"-dct float" may be even faster than "-dct fast". But on most machines -"-dct float" is slower than "-dct int"; in this case it is not worth using, -because its theoretical accuracy advantage is too small to be significant -in practice. - -Two-pass color quantization requires a good deal of memory; on MS-DOS machines -it may run out of memory even with -maxmemory 0. In that case you can still -decompress, with some loss of image quality, by specifying -onepass for -one-pass quantization. - -To avoid the Unisys LZW patent, djpeg produces uncompressed GIF files. These -are larger than they should be, but are readable by standard GIF decoders. - - -HINTS FOR BOTH PROGRAMS - -If more space is needed than will fit in the available main memory (as -determined by -maxmemory), temporary files will be used. (MS-DOS versions -will try to get extended or expanded memory first.) The temporary files are -often rather large: in typical cases they occupy three bytes per pixel, for -example 3*800*600 = 1.44Mb for an 800x600 image. If you don't have enough -free disk space, leave out -progressive and -optimize (for cjpeg) or specify --onepass (for djpeg). - -On MS-DOS, the temporary files are created in the directory named by the TMP -or TEMP environment variable, or in the current directory if neither of those -exist. Amiga implementations put the temp files in the directory named by -JPEGTMP:, so be sure to assign JPEGTMP: to a disk partition with adequate free -space. - -The default memory usage limit (-maxmemory) is set when the software is -compiled. If you get an "insufficient memory" error, try specifying a smaller --maxmemory value, even -maxmemory 0 to use the absolute minimum space. You -may want to recompile with a smaller default value if this happens often. - -On machines that have "environment" variables, you can define the environment -variable JPEGMEM to set the default memory limit. The value is specified as -described for the -maxmemory switch. JPEGMEM overrides the default value -specified when the program was compiled, and itself is overridden by an -explicit -maxmemory switch. - -On MS-DOS machines, -maxmemory is the amount of main (conventional) memory to -use. (Extended or expanded memory is also used if available.) Most -DOS-specific versions of this software do their own memory space estimation -and do not need you to specify -maxmemory. - - -JPEGTRAN - -jpegtran performs various useful transformations of JPEG files. -It can translate the coded representation from one variant of JPEG to another, -for example from baseline JPEG to progressive JPEG or vice versa. It can also -perform some rearrangements of the image data, for example turning an image -from landscape to portrait format by rotation. - -jpegtran works by rearranging the compressed data (DCT coefficients), without -ever fully decoding the image. Therefore, its transformations are lossless: -there is no image degradation at all, which would not be true if you used -djpeg followed by cjpeg to accomplish the same conversion. But by the same -token, jpegtran cannot perform lossy operations such as changing the image -quality. - -jpegtran uses a command line syntax similar to cjpeg or djpeg. -On Unix-like systems, you say: - jpegtran [switches] [inputfile] >outputfile -On most non-Unix systems, you say: - jpegtran [switches] inputfile outputfile -where both the input and output files are JPEG files. - -To specify the coded JPEG representation used in the output file, -jpegtran accepts a subset of the switches recognized by cjpeg: - -optimize Perform optimization of entropy encoding parameters. - -progressive Create progressive JPEG file. - -arithmetic Use arithmetic coding. - -restart N Emit a JPEG restart marker every N MCU rows, or every - N MCU blocks if "B" is attached to the number. - -scans file Use the scan script given in the specified text file. -See the previous discussion of cjpeg for more details about these switches. -If you specify none of these switches, you get a plain baseline-JPEG output -file. The quality setting and so forth are determined by the input file. - -The image can be losslessly transformed by giving one of these switches: - -flip horizontal Mirror image horizontally (left-right). - -flip vertical Mirror image vertically (top-bottom). - -rotate 90 Rotate image 90 degrees clockwise. - -rotate 180 Rotate image 180 degrees. - -rotate 270 Rotate image 270 degrees clockwise (or 90 ccw). - -transpose Transpose image (across UL-to-LR axis). - -transverse Transverse transpose (across UR-to-LL axis). - -The transpose transformation has no restrictions regarding image dimensions. -The other transformations operate rather oddly if the image dimensions are not -a multiple of the iMCU size (usually 8 or 16 pixels), because they can only -transform complete blocks of DCT coefficient data in the desired way. - -jpegtran's default behavior when transforming an odd-size image is designed -to preserve exact reversibility and mathematical consistency of the -transformation set. As stated, transpose is able to flip the entire image -area. Horizontal mirroring leaves any partial iMCU column at the right edge -untouched, but is able to flip all rows of the image. Similarly, vertical -mirroring leaves any partial iMCU row at the bottom edge untouched, but is -able to flip all columns. The other transforms can be built up as sequences -of transpose and flip operations; for consistency, their actions on edge -pixels are defined to be the same as the end result of the corresponding -transpose-and-flip sequence. - -For practical use, you may prefer to discard any untransformable edge pixels -rather than having a strange-looking strip along the right and/or bottom edges -of a transformed image. To do this, add the -trim switch: - -trim Drop non-transformable edge blocks. -Obviously, a transformation with -trim is not reversible, so strictly speaking -jpegtran with this switch is not lossless. Also, the expected mathematical -equivalences between the transformations no longer hold. For example, -"-rot 270 -trim" trims only the bottom edge, but "-rot 90 -trim" followed by -"-rot 180 -trim" trims both edges. - -If you are only interested in perfect transformation, add the -perfect switch: - -perfect Fails with an error if the transformation is not - perfect. -For example you may want to do - jpegtran -rot 90 -perfect foo.jpg || djpeg foo.jpg | pnmflip -r90 | cjpeg -to do a perfect rotation if available or an approximated one if not. - -We also offer a lossless-crop option, which discards data outside a given -image region but losslessly preserves what is inside. Like the rotate and -flip transforms, lossless crop is restricted by the current JPEG format: the -upper left corner of the selected region must fall on an iMCU boundary. If -this does not hold for the given crop parameters, we silently move the upper -left corner up and/or left to make it so, simultaneously increasing the region -dimensions to keep the lower right crop corner unchanged. (Thus, the output -image covers at least the requested region, but may cover more.) - -The image can be losslessly cropped by giving the switch: - -crop WxH+X+Y Crop to a rectangular subarea of width W, height H - starting at point X,Y. - -Other not-strictly-lossless transformation switches are: - - -grayscale Force grayscale output. -This option discards the chrominance channels if the input image is YCbCr -(ie, a standard color JPEG), resulting in a grayscale JPEG file. The -luminance channel is preserved exactly, so this is a better method of reducing -to grayscale than decompression, conversion, and recompression. This switch -is particularly handy for fixing a monochrome picture that was mistakenly -encoded as a color JPEG. (In such a case, the space savings from getting rid -of the near-empty chroma channels won't be large; but the decoding time for -a grayscale JPEG is substantially less than that for a color JPEG.) - - -scale M/N Scale the output image by a factor M/N. -Currently supported scale factors are M/N with all M from 1 to 16, where N is -the source DCT size, which is 8 for baseline JPEG. If the /N part is omitted, -then M specifies the DCT scaled size to be applied on the given input. For -baseline JPEG this is equivalent to M/8 scaling, since the source DCT size -for baseline JPEG is 8. CAUTION: An implementation of the JPEG SmartScale -extension is required for this feature. SmartScale enabled JPEG is not yet -widely implemented, so many decoders will be unable to view a SmartScale -extended JPEG file at all. - -jpegtran also recognizes these switches that control what to do with "extra" -markers, such as comment blocks: - -copy none Copy no extra markers from source file. This setting - suppresses all comments and other excess baggage - present in the source file. - -copy comments Copy only comment markers. This setting copies - comments from the source file, but discards - any other inessential (for image display) data. - -copy all Copy all extra markers. This setting preserves - miscellaneous markers found in the source file, such - as JFIF thumbnails, Exif data, and Photoshop settings. - In some files these extra markers can be sizable. -The default behavior is -copy comments. (Note: in IJG releases v6 and v6a, -jpegtran always did the equivalent of -copy none.) - -Additional switches recognized by jpegtran are: - -outfile filename - -maxmemory N - -verbose - -debug -These work the same as in cjpeg or djpeg. - - -THE COMMENT UTILITIES - -The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file. -Although the standard doesn't actually define what COM blocks are for, they -are widely used to hold user-supplied text strings. This lets you add -annotations, titles, index terms, etc to your JPEG files, and later retrieve -them as text. COM blocks do not interfere with the image stored in the JPEG -file. The maximum size of a COM block is 64K, but you can have as many of -them as you like in one JPEG file. - -We provide two utility programs to display COM block contents and add COM -blocks to a JPEG file. - -rdjpgcom searches a JPEG file and prints the contents of any COM blocks on -standard output. The command line syntax is - rdjpgcom [-raw] [-verbose] [inputfilename] -The switch "-raw" (or just "-r") causes rdjpgcom to also output non-printable -characters in comments, which are normally escaped for security reasons. -The switch "-verbose" (or just "-v") causes rdjpgcom to also display the JPEG -image dimensions. If you omit the input file name from the command line, -the JPEG file is read from standard input. (This may not work on some -operating systems, if binary data can't be read from stdin.) - -wrjpgcom adds a COM block, containing text you provide, to a JPEG file. -Ordinarily, the COM block is added after any existing COM blocks, but you -can delete the old COM blocks if you wish. wrjpgcom produces a new JPEG -file; it does not modify the input file. DO NOT try to overwrite the input -file by directing wrjpgcom's output back into it; on most systems this will -just destroy your file. - -The command line syntax for wrjpgcom is similar to cjpeg's. On Unix-like -systems, it is - wrjpgcom [switches] [inputfilename] -The output file is written to standard output. The input file comes from -the named file, or from standard input if no input file is named. - -On most non-Unix systems, the syntax is - wrjpgcom [switches] inputfilename outputfilename -where both input and output file names must be given explicitly. - -wrjpgcom understands three switches: - -replace Delete any existing COM blocks from the file. - -comment "Comment text" Supply new COM text on command line. - -cfile name Read text for new COM block from named file. -(Switch names can be abbreviated.) If you have only one line of comment text -to add, you can provide it on the command line with -comment. The comment -text must be surrounded with quotes so that it is treated as a single -argument. Longer comments can be read from a text file. - -If you give neither -comment nor -cfile, then wrjpgcom will read the comment -text from standard input. (In this case an input image file name MUST be -supplied, so that the source JPEG file comes from somewhere else.) You can -enter multiple lines, up to 64KB worth. Type an end-of-file indicator -(usually control-D or control-Z) to terminate the comment text entry. - -wrjpgcom will not add a COM block if the provided comment string is empty. -Therefore -replace -comment "" can be used to delete all COM blocks from a -file. - -These utility programs do not depend on the IJG JPEG library. In -particular, the source code for rdjpgcom is intended as an illustration of -the minimum amount of code required to parse a JPEG file header correctly. +USAGE instructions for the Independent JPEG Group's JPEG software +================================================================= + +This file describes usage of the JPEG conversion programs cjpeg and djpeg, +as well as the utility programs jpegtran, rdjpgcom and wrjpgcom. (See +the other documentation files if you wish to use the JPEG library within +your own programs.) + +If you are on a Unix machine you may prefer to read the Unix-style manual +pages in files cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1. + + +INTRODUCTION + +These programs implement JPEG image encoding, decoding, and transcoding. +JPEG (pronounced "jay-peg") is a standardized compression method for +full-color and gray-scale images. + + +GENERAL USAGE + +We provide two programs, cjpeg to compress an image file into JPEG format, +and djpeg to decompress a JPEG file back into a conventional image format. + +On Unix-like systems, you say: + cjpeg [switches] [imagefile] >jpegfile +or + djpeg [switches] [jpegfile] >imagefile +The programs read the specified input file, or standard input if none is +named. They always write to standard output (with trace/error messages to +standard error). These conventions are handy for piping images between +programs. + +On most non-Unix systems, you say: + cjpeg [switches] imagefile jpegfile +or + djpeg [switches] jpegfile imagefile +i.e., both the input and output files are named on the command line. This +style is a little more foolproof, and it loses no functionality if you don't +have pipes. (You can get this style on Unix too, if you prefer, by defining +TWO_FILE_COMMANDLINE when you compile the programs; see install.txt.) + +You can also say: + cjpeg [switches] -outfile jpegfile imagefile +or + djpeg [switches] -outfile imagefile jpegfile +This syntax works on all systems, so it is useful for scripts. + +The currently supported image file formats are: PPM (PBMPLUS color format), +PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster Toolkit +format). (RLE is supported only if the URT library is available.) +cjpeg recognizes the input image format automatically, with the exception +of some Targa-format files. You have to tell djpeg which format to generate. + +JPEG files are in the defacto standard JFIF file format. There are other, +less widely used JPEG-based file formats, but we don't support them. + +All switch names may be abbreviated; for example, -grayscale may be written +-gray or -gr. Most of the "basic" switches can be abbreviated to as little as +one letter. Upper and lower case are equivalent (-BMP is the same as -bmp). +British spellings are also accepted (e.g., -greyscale), though for brevity +these are not mentioned below. + + +CJPEG DETAILS + +The basic command line switches for cjpeg are: + + -quality N[,...] Scale quantization tables to adjust image quality. + Quality is 0 (worst) to 100 (best); default is 75. + (See below for more info.) + + -grayscale Create monochrome JPEG file from color input. + Be sure to use this switch when compressing a grayscale + BMP file, because cjpeg isn't bright enough to notice + whether a BMP file uses only shades of gray. By + saying -grayscale, you'll get a smaller JPEG file that + takes less time to process. + + -rgb Create RGB JPEG file. + Using this switch suppresses the conversion from RGB + colorspace input to the default YCbCr JPEG colorspace. + Use this switch in combination with the -block N + switch (see below) for lossless JPEG coding. + + -optimize Perform optimization of entropy encoding parameters. + Without this, default encoding parameters are used. + -optimize usually makes the JPEG file a little smaller, + but cjpeg runs somewhat slower and needs much more + memory. Image quality and speed of decompression are + unaffected by -optimize. + + -progressive Create progressive JPEG file (see below). + + -scale M/N Scale the output image by a factor M/N. Currently + supported scale factors are M/N with all N from 1 to + 16, where M is the destination DCT size, which is 8 by + default (see -block N switch below). + + -targa Input file is Targa format. Targa files that contain + an "identification" field will not be automatically + recognized by cjpeg; for such files you must specify + -targa to make cjpeg treat the input as Targa format. + For most Targa files, you won't need this switch. + +The -quality switch lets you trade off compressed file size against quality of +the reconstructed image: the higher the quality setting, the larger the JPEG +file, and the closer the output image will be to the original input. Normally +you want to use the lowest quality setting (smallest file) that decompresses +into something visually indistinguishable from the original image. For this +purpose the quality setting should be between 50 and 95; the default of 75 is +often about right. If you see defects at -quality 75, then go up 5 or 10 +counts at a time until you are happy with the output image. (The optimal +setting will vary from one image to another.) + +-quality 100 will generate a quantization table of all 1's, minimizing loss +in the quantization step (but there is still information loss in subsampling, +as well as roundoff error). This setting is mainly of interest for +experimental purposes. Quality values above about 95 are NOT recommended for +normal use; the compressed file size goes up dramatically for hardly any gain +in output image quality. + +In the other direction, quality values below 50 will produce very small files +of low image quality. Settings around 5 to 10 might be useful in preparing an +index of a large image library, for example. Try -quality 2 (or so) for some +amusing Cubist effects. (Note: quality values below about 25 generate 2-byte +quantization tables, which are considered optional in the JPEG standard. +cjpeg emits a warning message when you give such a quality value, because some +other JPEG programs may be unable to decode the resulting file. Use -baseline +if you need to ensure compatibility at low quality values.) + +The -quality option has been extended in IJG version 7 for support of separate +quality settings for luminance and chrominance (or in general, for every +provided quantization table slot). This feature is useful for high-quality +applications which cannot accept the damage of color data by coarse +subsampling settings. You can now easily reduce the color data amount more +smoothly with finer control without separate subsampling. The resulting file +is fully compliant with standard JPEG decoders. +Note that the -quality ratings refer to the quantization table slots, and that +the last value is replicated if there are more q-table slots than parameters. +The default q-table slots are 0 for luminance and 1 for chrominance with +default tables as given in the JPEG standard. This is compatible with the old +behaviour in case that only one parameter is given, which is then used for +both luminance and chrominance (slots 0 and 1). More or custom quantization +tables can be set with -qtables and assigned to components with -qslots +parameter (see the "wizard" switches below). +CAUTION: You must explicitly add -sample 1x1 for efficient separate color +quality selection, since the default value used by library is 2x2! + +The -progressive switch creates a "progressive JPEG" file. In this type of +JPEG file, the data is stored in multiple scans of increasing quality. If the +file is being transmitted over a slow communications link, the decoder can use +the first scan to display a low-quality image very quickly, and can then +improve the display with each subsequent scan. The final image is exactly +equivalent to a standard JPEG file of the same quality setting, and the total +file size is about the same --- often a little smaller. + +Switches for advanced users: + + -arithmetic Use arithmetic coding. CAUTION: arithmetic coded JPEG + is not yet widely implemented, so many decoders will + be unable to view an arithmetic coded JPEG file at + all. + + -block N Set DCT block size. All N from 1 to 16 are possible. + Default is 8 (baseline format). + Larger values produce higher compression, + smaller values produce higher quality + (exact DCT stage possible with 1 or 2; with the + default quality of 75 and default Luminance qtable + the DCT+Quantization stage is lossless for N=1). + CAUTION: An implementation of the JPEG SmartScale + extension is required for this feature. SmartScale + enabled JPEG is not yet widely implemented, so many + decoders will be unable to view a SmartScale extended + JPEG file at all. + + -dct int Use integer DCT method (default). + -dct fast Use fast integer DCT (less accurate). + -dct float Use floating-point DCT method. + The float method is very slightly more accurate than + the int method, but is much slower unless your machine + has very fast floating-point hardware. Also note that + results of the floating-point method may vary slightly + across machines, while the integer methods should give + the same results everywhere. The fast integer method + is much less accurate than the other two. + + -nosmooth Don't use high-quality downsampling. + + -restart N Emit a JPEG restart marker every N MCU rows, or every + N MCU blocks if "B" is attached to the number. + -restart 0 (the default) means no restart markers. + + -smooth N Smooth the input image to eliminate dithering noise. + N, ranging from 1 to 100, indicates the strength of + smoothing. 0 (the default) means no smoothing. + + -maxmemory N Set limit for amount of memory to use in processing + large images. Value is in thousands of bytes, or + millions of bytes if "M" is attached to the number. + For example, -max 4m selects 4000000 bytes. If more + space is needed, temporary files will be used. + + -verbose Enable debug printout. More -v's give more printout. + or -debug Also, version information is printed at startup. + +The -restart option inserts extra markers that allow a JPEG decoder to +resynchronize after a transmission error. Without restart markers, any damage +to a compressed file will usually ruin the image from the point of the error +to the end of the image; with restart markers, the damage is usually confined +to the portion of the image up to the next restart marker. Of course, the +restart markers occupy extra space. We recommend -restart 1 for images that +will be transmitted across unreliable networks such as Usenet. + +The -smooth option filters the input to eliminate fine-scale noise. This is +often useful when converting dithered images to JPEG: a moderate smoothing +factor of 10 to 50 gets rid of dithering patterns in the input file, resulting +in a smaller JPEG file and a better-looking image. Too large a smoothing +factor will visibly blur the image, however. + +Switches for wizards: + + -baseline Force baseline-compatible quantization tables to be + generated. This clamps quantization values to 8 bits + even at low quality settings. (This switch is poorly + named, since it does not ensure that the output is + actually baseline JPEG. For example, you can use + -baseline and -progressive together.) + + -qtables file Use the quantization tables given in the specified + text file. + + -qslots N[,...] Select which quantization table to use for each color + component. + + -sample HxV[,...] Set JPEG sampling factors for each color component. + + -scans file Use the scan script given in the specified text file. + +The "wizard" switches are intended for experimentation with JPEG. If you +don't know what you are doing, DON'T USE THEM. These switches are documented +further in the file wizard.txt. + + +DJPEG DETAILS + +The basic command line switches for djpeg are: + + -colors N Reduce image to at most N colors. This reduces the + or -quantize N number of colors used in the output image, so that it + can be displayed on a colormapped display or stored in + a colormapped file format. For example, if you have + an 8-bit display, you'd need to reduce to 256 or fewer + colors. (-colors is the recommended name, -quantize + is provided only for backwards compatibility.) + + -fast Select recommended processing options for fast, low + quality output. (The default options are chosen for + highest quality output.) Currently, this is equivalent + to "-dct fast -nosmooth -onepass -dither ordered". + + -grayscale Force gray-scale output even if JPEG file is color. + Useful for viewing on monochrome displays; also, + djpeg runs noticeably faster in this mode. + + -scale M/N Scale the output image by a factor M/N. Currently + supported scale factors are M/N with all M from 1 to + 16, where N is the source DCT size, which is 8 for + baseline JPEG. If the /N part is omitted, then M + specifies the DCT scaled size to be applied on the + given input. For baseline JPEG this is equivalent to + M/8 scaling, since the source DCT size for baseline + JPEG is 8. Scaling is handy if the image is larger + than your screen; also, djpeg runs much faster when + scaling down the output. + + -bmp Select BMP output format (Windows flavor). 8-bit + colormapped format is emitted if -colors or -grayscale + is specified, or if the JPEG file is gray-scale; + otherwise, 24-bit full-color format is emitted. + + -gif Select GIF output format. Since GIF does not support + more than 256 colors, -colors 256 is assumed (unless + you specify a smaller number of colors). If you + specify -fast, the default number of colors is 216. + + -os2 Select BMP output format (OS/2 1.x flavor). 8-bit + colormapped format is emitted if -colors or -grayscale + is specified, or if the JPEG file is gray-scale; + otherwise, 24-bit full-color format is emitted. + + -pnm Select PBMPLUS (PPM/PGM) output format (this is the + default format). PGM is emitted if the JPEG file is + gray-scale or if -grayscale is specified; otherwise + PPM is emitted. + + -rle Select RLE output format. (Requires URT library.) + + -targa Select Targa output format. Gray-scale format is + emitted if the JPEG file is gray-scale or if + -grayscale is specified; otherwise, colormapped format + is emitted if -colors is specified; otherwise, 24-bit + full-color format is emitted. + +Switches for advanced users: + + -dct int Use integer DCT method (default). + -dct fast Use fast integer DCT (less accurate). + -dct float Use floating-point DCT method. + The float method is very slightly more accurate than + the int method, but is much slower unless your machine + has very fast floating-point hardware. Also note that + results of the floating-point method may vary slightly + across machines, while the integer methods should give + the same results everywhere. The fast integer method + is much less accurate than the other two. + + -dither fs Use Floyd-Steinberg dithering in color quantization. + -dither ordered Use ordered dithering in color quantization. + -dither none Do not use dithering in color quantization. + By default, Floyd-Steinberg dithering is applied when + quantizing colors; this is slow but usually produces + the best results. Ordered dither is a compromise + between speed and quality; no dithering is fast but + usually looks awful. Note that these switches have + no effect unless color quantization is being done. + Ordered dither is only available in -onepass mode. + + -map FILE Quantize to the colors used in the specified image + file. This is useful for producing multiple files + with identical color maps, or for forcing a predefined + set of colors to be used. The FILE must be a GIF + or PPM file. This option overrides -colors and + -onepass. + + -nosmooth Don't use high-quality upsampling. + + -onepass Use one-pass instead of two-pass color quantization. + The one-pass method is faster and needs less memory, + but it produces a lower-quality image. -onepass is + ignored unless you also say -colors N. Also, + the one-pass method is always used for gray-scale + output (the two-pass method is no improvement then). + + -maxmemory N Set limit for amount of memory to use in processing + large images. Value is in thousands of bytes, or + millions of bytes if "M" is attached to the number. + For example, -max 4m selects 4000000 bytes. If more + space is needed, temporary files will be used. + + -verbose Enable debug printout. More -v's give more printout. + or -debug Also, version information is printed at startup. + + +HINTS FOR CJPEG + +Color GIF files are not the ideal input for JPEG; JPEG is really intended for +compressing full-color (24-bit) images. In particular, don't try to convert +cartoons, line drawings, and other images that have only a few distinct +colors. GIF works great on these, JPEG does not. If you want to convert a +GIF to JPEG, you should experiment with cjpeg's -quality and -smooth options +to get a satisfactory conversion. -smooth 10 or so is often helpful. + +Avoid running an image through a series of JPEG compression/decompression +cycles. Image quality loss will accumulate; after ten or so cycles the image +may be noticeably worse than it was after one cycle. It's best to use a +lossless format while manipulating an image, then convert to JPEG format when +you are ready to file the image away. + +The -optimize option to cjpeg is worth using when you are making a "final" +version for posting or archiving. It's also a win when you are using low +quality settings to make very small JPEG files; the percentage improvement +is often a lot more than it is on larger files. (At present, -optimize +mode is always selected when generating progressive JPEG files.) + +GIF input files are no longer supported, to avoid the Unisys LZW patent. +(Conversion of GIF files to JPEG is usually a bad idea anyway.) + + +HINTS FOR DJPEG + +To get a quick preview of an image, use the -grayscale and/or -scale switches. +"-grayscale -scale 1/8" is the fastest case. + +Several options are available that trade off image quality to gain speed. +"-fast" turns on the recommended settings. + +"-dct fast" and/or "-nosmooth" gain speed at a small sacrifice in quality. +When producing a color-quantized image, "-onepass -dither ordered" is fast but +much lower quality than the default behavior. "-dither none" may give +acceptable results in two-pass mode, but is seldom tolerable in one-pass mode. + +If you are fortunate enough to have very fast floating point hardware, +"-dct float" may be even faster than "-dct fast". But on most machines +"-dct float" is slower than "-dct int"; in this case it is not worth using, +because its theoretical accuracy advantage is too small to be significant +in practice. + +Two-pass color quantization requires a good deal of memory; on MS-DOS machines +it may run out of memory even with -maxmemory 0. In that case you can still +decompress, with some loss of image quality, by specifying -onepass for +one-pass quantization. + +To avoid the Unisys LZW patent, djpeg produces uncompressed GIF files. These +are larger than they should be, but are readable by standard GIF decoders. + + +HINTS FOR BOTH PROGRAMS + +If more space is needed than will fit in the available main memory (as +determined by -maxmemory), temporary files will be used. (MS-DOS versions +will try to get extended or expanded memory first.) The temporary files are +often rather large: in typical cases they occupy three bytes per pixel, for +example 3*800*600 = 1.44Mb for an 800x600 image. If you don't have enough +free disk space, leave out -progressive and -optimize (for cjpeg) or specify +-onepass (for djpeg). + +On MS-DOS, the temporary files are created in the directory named by the TMP +or TEMP environment variable, or in the current directory if neither of those +exist. Amiga implementations put the temp files in the directory named by +JPEGTMP:, so be sure to assign JPEGTMP: to a disk partition with adequate free +space. + +The default memory usage limit (-maxmemory) is set when the software is +compiled. If you get an "insufficient memory" error, try specifying a smaller +-maxmemory value, even -maxmemory 0 to use the absolute minimum space. You +may want to recompile with a smaller default value if this happens often. + +On machines that have "environment" variables, you can define the environment +variable JPEGMEM to set the default memory limit. The value is specified as +described for the -maxmemory switch. JPEGMEM overrides the default value +specified when the program was compiled, and itself is overridden by an +explicit -maxmemory switch. + +On MS-DOS machines, -maxmemory is the amount of main (conventional) memory to +use. (Extended or expanded memory is also used if available.) Most +DOS-specific versions of this software do their own memory space estimation +and do not need you to specify -maxmemory. + + +JPEGTRAN + +jpegtran performs various useful transformations of JPEG files. +It can translate the coded representation from one variant of JPEG to another, +for example from baseline JPEG to progressive JPEG or vice versa. It can also +perform some rearrangements of the image data, for example turning an image +from landscape to portrait format by rotation. + +jpegtran works by rearranging the compressed data (DCT coefficients), without +ever fully decoding the image. Therefore, its transformations are lossless: +there is no image degradation at all, which would not be true if you used +djpeg followed by cjpeg to accomplish the same conversion. But by the same +token, jpegtran cannot perform lossy operations such as changing the image +quality. + +jpegtran uses a command line syntax similar to cjpeg or djpeg. +On Unix-like systems, you say: + jpegtran [switches] [inputfile] >outputfile +On most non-Unix systems, you say: + jpegtran [switches] inputfile outputfile +where both the input and output files are JPEG files. + +To specify the coded JPEG representation used in the output file, +jpegtran accepts a subset of the switches recognized by cjpeg: + -optimize Perform optimization of entropy encoding parameters. + -progressive Create progressive JPEG file. + -arithmetic Use arithmetic coding. + -restart N Emit a JPEG restart marker every N MCU rows, or every + N MCU blocks if "B" is attached to the number. + -scans file Use the scan script given in the specified text file. +See the previous discussion of cjpeg for more details about these switches. +If you specify none of these switches, you get a plain baseline-JPEG output +file. The quality setting and so forth are determined by the input file. + +The image can be losslessly transformed by giving one of these switches: + -flip horizontal Mirror image horizontally (left-right). + -flip vertical Mirror image vertically (top-bottom). + -rotate 90 Rotate image 90 degrees clockwise. + -rotate 180 Rotate image 180 degrees. + -rotate 270 Rotate image 270 degrees clockwise (or 90 ccw). + -transpose Transpose image (across UL-to-LR axis). + -transverse Transverse transpose (across UR-to-LL axis). + +The transpose transformation has no restrictions regarding image dimensions. +The other transformations operate rather oddly if the image dimensions are not +a multiple of the iMCU size (usually 8 or 16 pixels), because they can only +transform complete blocks of DCT coefficient data in the desired way. + +jpegtran's default behavior when transforming an odd-size image is designed +to preserve exact reversibility and mathematical consistency of the +transformation set. As stated, transpose is able to flip the entire image +area. Horizontal mirroring leaves any partial iMCU column at the right edge +untouched, but is able to flip all rows of the image. Similarly, vertical +mirroring leaves any partial iMCU row at the bottom edge untouched, but is +able to flip all columns. The other transforms can be built up as sequences +of transpose and flip operations; for consistency, their actions on edge +pixels are defined to be the same as the end result of the corresponding +transpose-and-flip sequence. + +For practical use, you may prefer to discard any untransformable edge pixels +rather than having a strange-looking strip along the right and/or bottom edges +of a transformed image. To do this, add the -trim switch: + -trim Drop non-transformable edge blocks. +Obviously, a transformation with -trim is not reversible, so strictly speaking +jpegtran with this switch is not lossless. Also, the expected mathematical +equivalences between the transformations no longer hold. For example, +"-rot 270 -trim" trims only the bottom edge, but "-rot 90 -trim" followed by +"-rot 180 -trim" trims both edges. + +If you are only interested in perfect transformation, add the -perfect switch: + -perfect Fails with an error if the transformation is not + perfect. +For example you may want to do + jpegtran -rot 90 -perfect foo.jpg || djpeg foo.jpg | pnmflip -r90 | cjpeg +to do a perfect rotation if available or an approximated one if not. + +We also offer a lossless-crop option, which discards data outside a given +image region but losslessly preserves what is inside. Like the rotate and +flip transforms, lossless crop is restricted by the current JPEG format: the +upper left corner of the selected region must fall on an iMCU boundary. If +this does not hold for the given crop parameters, we silently move the upper +left corner up and/or left to make it so, simultaneously increasing the region +dimensions to keep the lower right crop corner unchanged. (Thus, the output +image covers at least the requested region, but may cover more.) + +The image can be losslessly cropped by giving the switch: + -crop WxH+X+Y Crop to a rectangular subarea of width W, height H + starting at point X,Y. + +Other not-strictly-lossless transformation switches are: + + -grayscale Force grayscale output. +This option discards the chrominance channels if the input image is YCbCr +(ie, a standard color JPEG), resulting in a grayscale JPEG file. The +luminance channel is preserved exactly, so this is a better method of reducing +to grayscale than decompression, conversion, and recompression. This switch +is particularly handy for fixing a monochrome picture that was mistakenly +encoded as a color JPEG. (In such a case, the space savings from getting rid +of the near-empty chroma channels won't be large; but the decoding time for +a grayscale JPEG is substantially less than that for a color JPEG.) + + -scale M/N Scale the output image by a factor M/N. +Currently supported scale factors are M/N with all M from 1 to 16, where N is +the source DCT size, which is 8 for baseline JPEG. If the /N part is omitted, +then M specifies the DCT scaled size to be applied on the given input. For +baseline JPEG this is equivalent to M/8 scaling, since the source DCT size +for baseline JPEG is 8. CAUTION: An implementation of the JPEG SmartScale +extension is required for this feature. SmartScale enabled JPEG is not yet +widely implemented, so many decoders will be unable to view a SmartScale +extended JPEG file at all. + +jpegtran also recognizes these switches that control what to do with "extra" +markers, such as comment blocks: + -copy none Copy no extra markers from source file. This setting + suppresses all comments and other excess baggage + present in the source file. + -copy comments Copy only comment markers. This setting copies + comments from the source file, but discards + any other inessential (for image display) data. + -copy all Copy all extra markers. This setting preserves + miscellaneous markers found in the source file, such + as JFIF thumbnails, Exif data, and Photoshop settings. + In some files these extra markers can be sizable. +The default behavior is -copy comments. (Note: in IJG releases v6 and v6a, +jpegtran always did the equivalent of -copy none.) + +Additional switches recognized by jpegtran are: + -outfile filename + -maxmemory N + -verbose + -debug +These work the same as in cjpeg or djpeg. + + +THE COMMENT UTILITIES + +The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file. +Although the standard doesn't actually define what COM blocks are for, they +are widely used to hold user-supplied text strings. This lets you add +annotations, titles, index terms, etc to your JPEG files, and later retrieve +them as text. COM blocks do not interfere with the image stored in the JPEG +file. The maximum size of a COM block is 64K, but you can have as many of +them as you like in one JPEG file. + +We provide two utility programs to display COM block contents and add COM +blocks to a JPEG file. + +rdjpgcom searches a JPEG file and prints the contents of any COM blocks on +standard output. The command line syntax is + rdjpgcom [-raw] [-verbose] [inputfilename] +The switch "-raw" (or just "-r") causes rdjpgcom to also output non-printable +characters in comments, which are normally escaped for security reasons. +The switch "-verbose" (or just "-v") causes rdjpgcom to also display the JPEG +image dimensions. If you omit the input file name from the command line, +the JPEG file is read from standard input. (This may not work on some +operating systems, if binary data can't be read from stdin.) + +wrjpgcom adds a COM block, containing text you provide, to a JPEG file. +Ordinarily, the COM block is added after any existing COM blocks, but you +can delete the old COM blocks if you wish. wrjpgcom produces a new JPEG +file; it does not modify the input file. DO NOT try to overwrite the input +file by directing wrjpgcom's output back into it; on most systems this will +just destroy your file. + +The command line syntax for wrjpgcom is similar to cjpeg's. On Unix-like +systems, it is + wrjpgcom [switches] [inputfilename] +The output file is written to standard output. The input file comes from +the named file, or from standard input if no input file is named. + +On most non-Unix systems, the syntax is + wrjpgcom [switches] inputfilename outputfilename +where both input and output file names must be given explicitly. + +wrjpgcom understands three switches: + -replace Delete any existing COM blocks from the file. + -comment "Comment text" Supply new COM text on command line. + -cfile name Read text for new COM block from named file. +(Switch names can be abbreviated.) If you have only one line of comment text +to add, you can provide it on the command line with -comment. The comment +text must be surrounded with quotes so that it is treated as a single +argument. Longer comments can be read from a text file. + +If you give neither -comment nor -cfile, then wrjpgcom will read the comment +text from standard input. (In this case an input image file name MUST be +supplied, so that the source JPEG file comes from somewhere else.) You can +enter multiple lines, up to 64KB worth. Type an end-of-file indicator +(usually control-D or control-Z) to terminate the comment text entry. + +wrjpgcom will not add a COM block if the provided comment string is empty. +Therefore -replace -comment "" can be used to delete all COM blocks from a +file. + +These utility programs do not depend on the IJG JPEG library. In +particular, the source code for rdjpgcom is intended as an illustration of +the minimum amount of code required to parse a JPEG file header correctly. diff --git a/Source/LibJPEG/wizard.txt b/Source/LibJPEG/wizard.txt index 02418ba..54170b2 100644 --- a/Source/LibJPEG/wizard.txt +++ b/Source/LibJPEG/wizard.txt @@ -1,211 +1,211 @@ -Advanced usage instructions for the Independent JPEG Group's JPEG software -========================================================================== - -This file describes cjpeg's "switches for wizards". - -The "wizard" switches are intended for experimentation with JPEG by persons -who are reasonably knowledgeable about the JPEG standard. If you don't know -what you are doing, DON'T USE THESE SWITCHES. You'll likely produce files -with worse image quality and/or poorer compression than you'd get from the -default settings. Furthermore, these switches must be used with caution -when making files intended for general use, because not all JPEG decoders -will support unusual JPEG parameter settings. - - -Quantization Table Adjustment ------------------------------ - -Ordinarily, cjpeg starts with a default set of tables (the same ones given -as examples in the JPEG standard) and scales them up or down according to -the -quality setting. The details of the scaling algorithm can be found in -jcparam.c. At very low quality settings, some quantization table entries -can get scaled up to values exceeding 255. Although 2-byte quantization -values are supported by the IJG software, this feature is not in baseline -JPEG and is not supported by all implementations. If you need to ensure -wide compatibility of low-quality files, you can constrain the scaled -quantization values to no more than 255 by giving the -baseline switch. -Note that use of -baseline will result in poorer quality for the same file -size, since more bits than necessary are expended on higher AC coefficients. - -You can substitute a different set of quantization values by using the --qtables switch: - - -qtables file Use the quantization tables given in the named file. - -The specified file should be a text file containing decimal quantization -values. The file should contain one to four tables, each of 64 elements. -The tables are implicitly numbered 0,1,etc. in order of appearance. Table -entries appear in normal array order (NOT in the zigzag order in which they -will be stored in the JPEG file). - -Quantization table files are free format, in that arbitrary whitespace can -appear between numbers. Also, comments can be included: a comment starts -with '#' and extends to the end of the line. Here is an example file that -duplicates the default quantization tables: - - # Quantization tables given in JPEG spec, section K.1 - - # This is table 0 (the luminance table): - 16 11 10 16 24 40 51 61 - 12 12 14 19 26 58 60 55 - 14 13 16 24 40 57 69 56 - 14 17 22 29 51 87 80 62 - 18 22 37 56 68 109 103 77 - 24 35 55 64 81 104 113 92 - 49 64 78 87 103 121 120 101 - 72 92 95 98 112 100 103 99 - - # This is table 1 (the chrominance table): - 17 18 24 47 99 99 99 99 - 18 21 26 66 99 99 99 99 - 24 26 56 99 99 99 99 99 - 47 66 99 99 99 99 99 99 - 99 99 99 99 99 99 99 99 - 99 99 99 99 99 99 99 99 - 99 99 99 99 99 99 99 99 - 99 99 99 99 99 99 99 99 - -If the -qtables switch is used without -quality, then the specified tables -are used exactly as-is. If both -qtables and -quality are used, then the -tables taken from the file are scaled in the same fashion that the default -tables would be scaled for that quality setting. If -baseline appears, then -the quantization values are constrained to the range 1-255. - -By default, cjpeg will use quantization table 0 for luminance components and -table 1 for chrominance components. To override this choice, use the -qslots -switch: - - -qslots N[,...] Select which quantization table to use for - each color component. - -The -qslots switch specifies a quantization table number for each color -component, in the order in which the components appear in the JPEG SOF marker. -For example, to create a separate table for each of Y,Cb,Cr, you could -provide a -qtables file that defines three quantization tables and say -"-qslots 0,1,2". If -qslots gives fewer table numbers than there are color -components, then the last table number is repeated as necessary. - - -Sampling Factor Adjustment --------------------------- - -By default, cjpeg uses 2:1 horizontal and vertical downsampling when -compressing YCbCr data, and no downsampling for all other color spaces. -You can override this default with the -sample switch: - - -sample HxV[,...] Set JPEG sampling factors for each color - component. - -The -sample switch specifies the JPEG sampling factors for each color -component, in the order in which they appear in the JPEG SOF marker. -If you specify fewer HxV pairs than there are components, the remaining -components are set to 1x1 sampling. For example, the default YCbCr setting -is equivalent to "-sample 2x2,1x1,1x1", which can be abbreviated to -"-sample 2x2". - -There are still some JPEG decoders in existence that support only 2x1 -sampling (also called 4:2:2 sampling). Compatibility with such decoders can -be achieved by specifying "-sample 2x1". This is not recommended unless -really necessary, since it increases file size and encoding/decoding time -with very little quality gain. - - -Multiple Scan / Progression Control ------------------------------------ - -By default, cjpeg emits a single-scan sequential JPEG file. The --progressive switch generates a progressive JPEG file using a default series -of progression parameters. You can create multiple-scan sequential JPEG -files or progressive JPEG files with custom progression parameters by using -the -scans switch: - - -scans file Use the scan sequence given in the named file. - -The specified file should be a text file containing a "scan script". -The script specifies the contents and ordering of the scans to be emitted. -Each entry in the script defines one scan. A scan definition specifies -the components to be included in the scan, and for progressive JPEG it also -specifies the progression parameters Ss,Se,Ah,Al for the scan. Scan -definitions are separated by semicolons (';'). A semicolon after the last -scan definition is optional. - -Each scan definition contains one to four component indexes, optionally -followed by a colon (':') and the four progressive-JPEG parameters. The -component indexes denote which color component(s) are to be transmitted in -the scan. Components are numbered in the order in which they appear in the -JPEG SOF marker, with the first component being numbered 0. (Note that these -indexes are not the "component ID" codes assigned to the components, just -positional indexes.) - -The progression parameters for each scan are: - Ss Zigzag index of first coefficient included in scan - Se Zigzag index of last coefficient included in scan - Ah Zero for first scan of a coefficient, else Al of prior scan - Al Successive approximation low bit position for scan -If the progression parameters are omitted, the values 0,63,0,0 are used, -producing a sequential JPEG file. cjpeg automatically determines whether -the script represents a progressive or sequential file, by observing whether -Ss and Se values other than 0 and 63 appear. (The -progressive switch is -not needed to specify this; in fact, it is ignored when -scans appears.) -The scan script must meet the JPEG restrictions on progression sequences. -(cjpeg checks that the spec's requirements are obeyed.) - -Scan script files are free format, in that arbitrary whitespace can appear -between numbers and around punctuation. Also, comments can be included: a -comment starts with '#' and extends to the end of the line. For additional -legibility, commas or dashes can be placed between values. (Actually, any -single punctuation character other than ':' or ';' can be inserted.) For -example, the following two scan definitions are equivalent: - 0 1 2: 0 63 0 0; - 0,1,2 : 0-63, 0,0 ; - -Here is an example of a scan script that generates a partially interleaved -sequential JPEG file: - - 0; # Y only in first scan - 1 2; # Cb and Cr in second scan - -Here is an example of a progressive scan script using only spectral selection -(no successive approximation): - - # Interleaved DC scan for Y,Cb,Cr: - 0,1,2: 0-0, 0, 0 ; - # AC scans: - 0: 1-2, 0, 0 ; # First two Y AC coefficients - 0: 3-5, 0, 0 ; # Three more - 1: 1-63, 0, 0 ; # All AC coefficients for Cb - 2: 1-63, 0, 0 ; # All AC coefficients for Cr - 0: 6-9, 0, 0 ; # More Y coefficients - 0: 10-63, 0, 0 ; # Remaining Y coefficients - -Here is an example of a successive-approximation script. This is equivalent -to the default script used by "cjpeg -progressive" for YCbCr images: - - # Initial DC scan for Y,Cb,Cr (lowest bit not sent) - 0,1,2: 0-0, 0, 1 ; - # First AC scan: send first 5 Y AC coefficients, minus 2 lowest bits: - 0: 1-5, 0, 2 ; - # Send all Cr,Cb AC coefficients, minus lowest bit: - # (chroma data is usually too small to be worth subdividing further; - # but note we send Cr first since eye is least sensitive to Cb) - 2: 1-63, 0, 1 ; - 1: 1-63, 0, 1 ; - # Send remaining Y AC coefficients, minus 2 lowest bits: - 0: 6-63, 0, 2 ; - # Send next-to-lowest bit of all Y AC coefficients: - 0: 1-63, 2, 1 ; - # At this point we've sent all but the lowest bit of all coefficients. - # Send lowest bit of DC coefficients - 0,1,2: 0-0, 1, 0 ; - # Send lowest bit of AC coefficients - 2: 1-63, 1, 0 ; - 1: 1-63, 1, 0 ; - # Y AC lowest bit scan is last; it's usually the largest scan - 0: 1-63, 1, 0 ; - -It may be worth pointing out that this script is tuned for quality settings -of around 50 to 75. For lower quality settings, you'd probably want to use -a script with fewer stages of successive approximation (otherwise the -initial scans will be really bad). For higher quality settings, you might -want to use more stages of successive approximation (so that the initial -scans are not too large). +Advanced usage instructions for the Independent JPEG Group's JPEG software +========================================================================== + +This file describes cjpeg's "switches for wizards". + +The "wizard" switches are intended for experimentation with JPEG by persons +who are reasonably knowledgeable about the JPEG standard. If you don't know +what you are doing, DON'T USE THESE SWITCHES. You'll likely produce files +with worse image quality and/or poorer compression than you'd get from the +default settings. Furthermore, these switches must be used with caution +when making files intended for general use, because not all JPEG decoders +will support unusual JPEG parameter settings. + + +Quantization Table Adjustment +----------------------------- + +Ordinarily, cjpeg starts with a default set of tables (the same ones given +as examples in the JPEG standard) and scales them up or down according to +the -quality setting. The details of the scaling algorithm can be found in +jcparam.c. At very low quality settings, some quantization table entries +can get scaled up to values exceeding 255. Although 2-byte quantization +values are supported by the IJG software, this feature is not in baseline +JPEG and is not supported by all implementations. If you need to ensure +wide compatibility of low-quality files, you can constrain the scaled +quantization values to no more than 255 by giving the -baseline switch. +Note that use of -baseline will result in poorer quality for the same file +size, since more bits than necessary are expended on higher AC coefficients. + +You can substitute a different set of quantization values by using the +-qtables switch: + + -qtables file Use the quantization tables given in the named file. + +The specified file should be a text file containing decimal quantization +values. The file should contain one to four tables, each of 64 elements. +The tables are implicitly numbered 0,1,etc. in order of appearance. Table +entries appear in normal array order (NOT in the zigzag order in which they +will be stored in the JPEG file). + +Quantization table files are free format, in that arbitrary whitespace can +appear between numbers. Also, comments can be included: a comment starts +with '#' and extends to the end of the line. Here is an example file that +duplicates the default quantization tables: + + # Quantization tables given in JPEG spec, section K.1 + + # This is table 0 (the luminance table): + 16 11 10 16 24 40 51 61 + 12 12 14 19 26 58 60 55 + 14 13 16 24 40 57 69 56 + 14 17 22 29 51 87 80 62 + 18 22 37 56 68 109 103 77 + 24 35 55 64 81 104 113 92 + 49 64 78 87 103 121 120 101 + 72 92 95 98 112 100 103 99 + + # This is table 1 (the chrominance table): + 17 18 24 47 99 99 99 99 + 18 21 26 66 99 99 99 99 + 24 26 56 99 99 99 99 99 + 47 66 99 99 99 99 99 99 + 99 99 99 99 99 99 99 99 + 99 99 99 99 99 99 99 99 + 99 99 99 99 99 99 99 99 + 99 99 99 99 99 99 99 99 + +If the -qtables switch is used without -quality, then the specified tables +are used exactly as-is. If both -qtables and -quality are used, then the +tables taken from the file are scaled in the same fashion that the default +tables would be scaled for that quality setting. If -baseline appears, then +the quantization values are constrained to the range 1-255. + +By default, cjpeg will use quantization table 0 for luminance components and +table 1 for chrominance components. To override this choice, use the -qslots +switch: + + -qslots N[,...] Select which quantization table to use for + each color component. + +The -qslots switch specifies a quantization table number for each color +component, in the order in which the components appear in the JPEG SOF marker. +For example, to create a separate table for each of Y,Cb,Cr, you could +provide a -qtables file that defines three quantization tables and say +"-qslots 0,1,2". If -qslots gives fewer table numbers than there are color +components, then the last table number is repeated as necessary. + + +Sampling Factor Adjustment +-------------------------- + +By default, cjpeg uses 2:1 horizontal and vertical downsampling when +compressing YCbCr data, and no downsampling for all other color spaces. +You can override this default with the -sample switch: + + -sample HxV[,...] Set JPEG sampling factors for each color + component. + +The -sample switch specifies the JPEG sampling factors for each color +component, in the order in which they appear in the JPEG SOF marker. +If you specify fewer HxV pairs than there are components, the remaining +components are set to 1x1 sampling. For example, the default YCbCr setting +is equivalent to "-sample 2x2,1x1,1x1", which can be abbreviated to +"-sample 2x2". + +There are still some JPEG decoders in existence that support only 2x1 +sampling (also called 4:2:2 sampling). Compatibility with such decoders can +be achieved by specifying "-sample 2x1". This is not recommended unless +really necessary, since it increases file size and encoding/decoding time +with very little quality gain. + + +Multiple Scan / Progression Control +----------------------------------- + +By default, cjpeg emits a single-scan sequential JPEG file. The +-progressive switch generates a progressive JPEG file using a default series +of progression parameters. You can create multiple-scan sequential JPEG +files or progressive JPEG files with custom progression parameters by using +the -scans switch: + + -scans file Use the scan sequence given in the named file. + +The specified file should be a text file containing a "scan script". +The script specifies the contents and ordering of the scans to be emitted. +Each entry in the script defines one scan. A scan definition specifies +the components to be included in the scan, and for progressive JPEG it also +specifies the progression parameters Ss,Se,Ah,Al for the scan. Scan +definitions are separated by semicolons (';'). A semicolon after the last +scan definition is optional. + +Each scan definition contains one to four component indexes, optionally +followed by a colon (':') and the four progressive-JPEG parameters. The +component indexes denote which color component(s) are to be transmitted in +the scan. Components are numbered in the order in which they appear in the +JPEG SOF marker, with the first component being numbered 0. (Note that these +indexes are not the "component ID" codes assigned to the components, just +positional indexes.) + +The progression parameters for each scan are: + Ss Zigzag index of first coefficient included in scan + Se Zigzag index of last coefficient included in scan + Ah Zero for first scan of a coefficient, else Al of prior scan + Al Successive approximation low bit position for scan +If the progression parameters are omitted, the values 0,63,0,0 are used, +producing a sequential JPEG file. cjpeg automatically determines whether +the script represents a progressive or sequential file, by observing whether +Ss and Se values other than 0 and 63 appear. (The -progressive switch is +not needed to specify this; in fact, it is ignored when -scans appears.) +The scan script must meet the JPEG restrictions on progression sequences. +(cjpeg checks that the spec's requirements are obeyed.) + +Scan script files are free format, in that arbitrary whitespace can appear +between numbers and around punctuation. Also, comments can be included: a +comment starts with '#' and extends to the end of the line. For additional +legibility, commas or dashes can be placed between values. (Actually, any +single punctuation character other than ':' or ';' can be inserted.) For +example, the following two scan definitions are equivalent: + 0 1 2: 0 63 0 0; + 0,1,2 : 0-63, 0,0 ; + +Here is an example of a scan script that generates a partially interleaved +sequential JPEG file: + + 0; # Y only in first scan + 1 2; # Cb and Cr in second scan + +Here is an example of a progressive scan script using only spectral selection +(no successive approximation): + + # Interleaved DC scan for Y,Cb,Cr: + 0,1,2: 0-0, 0, 0 ; + # AC scans: + 0: 1-2, 0, 0 ; # First two Y AC coefficients + 0: 3-5, 0, 0 ; # Three more + 1: 1-63, 0, 0 ; # All AC coefficients for Cb + 2: 1-63, 0, 0 ; # All AC coefficients for Cr + 0: 6-9, 0, 0 ; # More Y coefficients + 0: 10-63, 0, 0 ; # Remaining Y coefficients + +Here is an example of a successive-approximation script. This is equivalent +to the default script used by "cjpeg -progressive" for YCbCr images: + + # Initial DC scan for Y,Cb,Cr (lowest bit not sent) + 0,1,2: 0-0, 0, 1 ; + # First AC scan: send first 5 Y AC coefficients, minus 2 lowest bits: + 0: 1-5, 0, 2 ; + # Send all Cr,Cb AC coefficients, minus lowest bit: + # (chroma data is usually too small to be worth subdividing further; + # but note we send Cr first since eye is least sensitive to Cb) + 2: 1-63, 0, 1 ; + 1: 1-63, 0, 1 ; + # Send remaining Y AC coefficients, minus 2 lowest bits: + 0: 6-63, 0, 2 ; + # Send next-to-lowest bit of all Y AC coefficients: + 0: 1-63, 2, 1 ; + # At this point we've sent all but the lowest bit of all coefficients. + # Send lowest bit of DC coefficients + 0,1,2: 0-0, 1, 0 ; + # Send lowest bit of AC coefficients + 2: 1-63, 1, 0 ; + 1: 1-63, 1, 0 ; + # Y AC lowest bit scan is last; it's usually the largest scan + 0: 1-63, 1, 0 ; + +It may be worth pointing out that this script is tuned for quality settings +of around 50 to 75. For lower quality settings, you'd probably want to use +a script with fewer stages of successive approximation (otherwise the +initial scans will be really bad). For higher quality settings, you might +want to use more stages of successive approximation (so that the initial +scans are not too large). diff --git a/Source/LibJPEG/wrbmp.c b/Source/LibJPEG/wrbmp.c index 2b8146e..3283b0f 100644 --- a/Source/LibJPEG/wrbmp.c +++ b/Source/LibJPEG/wrbmp.c @@ -1,442 +1,442 @@ -/* - * wrbmp.c - * - * Copyright (C) 1994-1996, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains routines to write output images in Microsoft "BMP" - * format (MS Windows 3.x and OS/2 1.x flavors). - * Either 8-bit colormapped or 24-bit full-color format can be written. - * No compression is supported. - * - * These routines may need modification for non-Unix environments or - * specialized applications. As they stand, they assume output to - * an ordinary stdio stream. - * - * This code contributed by James Arthur Boucher. - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ - -#ifdef BMP_SUPPORTED - - -/* - * To support 12-bit JPEG data, we'd have to scale output down to 8 bits. - * This is not yet implemented. - */ - -#if BITS_IN_JSAMPLE != 8 - Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ -#endif - -/* - * Since BMP stores scanlines bottom-to-top, we have to invert the image - * from JPEG's top-to-bottom order. To do this, we save the outgoing data - * in a virtual array during put_pixel_row calls, then actually emit the - * BMP file during finish_output. The virtual array contains one JSAMPLE per - * pixel if the output is grayscale or colormapped, three if it is full color. - */ - -/* Private version of data destination object */ - -typedef struct { - struct djpeg_dest_struct pub; /* public fields */ - - boolean is_os2; /* saves the OS2 format request flag */ - - jvirt_sarray_ptr whole_image; /* needed to reverse row order */ - JDIMENSION data_width; /* JSAMPLEs per row */ - JDIMENSION row_width; /* physical width of one row in the BMP file */ - int pad_bytes; /* number of padding bytes needed per row */ - JDIMENSION cur_output_row; /* next row# to write to virtual array */ -} bmp_dest_struct; - -typedef bmp_dest_struct * bmp_dest_ptr; - - -/* Forward declarations */ -LOCAL(void) write_colormap - JPP((j_decompress_ptr cinfo, bmp_dest_ptr dest, - int map_colors, int map_entry_size)); - - -/* - * Write some pixel data. - * In this module rows_supplied will always be 1. - */ - -METHODDEF(void) -put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, - JDIMENSION rows_supplied) -/* This version is for writing 24-bit pixels */ -{ - bmp_dest_ptr dest = (bmp_dest_ptr) dinfo; - JSAMPARRAY image_ptr; - register JSAMPROW inptr, outptr; - register JDIMENSION col; - int pad; - - /* Access next row in virtual array */ - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, dest->whole_image, - dest->cur_output_row, (JDIMENSION) 1, TRUE); - dest->cur_output_row++; - - /* Transfer data. Note destination values must be in BGR order - * (even though Microsoft's own documents say the opposite). - */ - inptr = dest->pub.buffer[0]; - outptr = image_ptr[0]; - for (col = cinfo->output_width; col > 0; col--) { - outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ - outptr[1] = *inptr++; - outptr[0] = *inptr++; - outptr += 3; - } - - /* Zero out the pad bytes. */ - pad = dest->pad_bytes; - while (--pad >= 0) - *outptr++ = 0; -} - -METHODDEF(void) -put_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, - JDIMENSION rows_supplied) -/* This version is for grayscale OR quantized color output */ -{ - bmp_dest_ptr dest = (bmp_dest_ptr) dinfo; - JSAMPARRAY image_ptr; - register JSAMPROW inptr, outptr; - register JDIMENSION col; - int pad; - - /* Access next row in virtual array */ - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, dest->whole_image, - dest->cur_output_row, (JDIMENSION) 1, TRUE); - dest->cur_output_row++; - - /* Transfer data. */ - inptr = dest->pub.buffer[0]; - outptr = image_ptr[0]; - for (col = cinfo->output_width; col > 0; col--) { - *outptr++ = *inptr++; /* can omit GETJSAMPLE() safely */ - } - - /* Zero out the pad bytes. */ - pad = dest->pad_bytes; - while (--pad >= 0) - *outptr++ = 0; -} - - -/* - * Startup: normally writes the file header. - * In this module we may as well postpone everything until finish_output. - */ - -METHODDEF(void) -start_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) -{ - /* no work here */ -} - - -/* - * Finish up at the end of the file. - * - * Here is where we really output the BMP file. - * - * First, routines to write the Windows and OS/2 variants of the file header. - */ - -LOCAL(void) -write_bmp_header (j_decompress_ptr cinfo, bmp_dest_ptr dest) -/* Write a Windows-style BMP file header, including colormap if needed */ -{ - char bmpfileheader[14]; - char bmpinfoheader[40]; -#define PUT_2B(array,offset,value) \ - (array[offset] = (char) ((value) & 0xFF), \ - array[offset+1] = (char) (((value) >> 8) & 0xFF)) -#define PUT_4B(array,offset,value) \ - (array[offset] = (char) ((value) & 0xFF), \ - array[offset+1] = (char) (((value) >> 8) & 0xFF), \ - array[offset+2] = (char) (((value) >> 16) & 0xFF), \ - array[offset+3] = (char) (((value) >> 24) & 0xFF)) - INT32 headersize, bfSize; - int bits_per_pixel, cmap_entries; - - /* Compute colormap size and total file size */ - if (cinfo->out_color_space == JCS_RGB) { - if (cinfo->quantize_colors) { - /* Colormapped RGB */ - bits_per_pixel = 8; - cmap_entries = 256; - } else { - /* Unquantized, full color RGB */ - bits_per_pixel = 24; - cmap_entries = 0; - } - } else { - /* Grayscale output. We need to fake a 256-entry colormap. */ - bits_per_pixel = 8; - cmap_entries = 256; - } - /* File size */ - headersize = 14 + 40 + cmap_entries * 4; /* Header and colormap */ - bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height; - - /* Set unused fields of header to 0 */ - MEMZERO(bmpfileheader, SIZEOF(bmpfileheader)); - MEMZERO(bmpinfoheader, SIZEOF(bmpinfoheader)); - - /* Fill the file header */ - bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */ - bmpfileheader[1] = 0x4D; - PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */ - /* we leave bfReserved1 & bfReserved2 = 0 */ - PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */ - - /* Fill the info header (Microsoft calls this a BITMAPINFOHEADER) */ - PUT_2B(bmpinfoheader, 0, 40); /* biSize */ - PUT_4B(bmpinfoheader, 4, cinfo->output_width); /* biWidth */ - PUT_4B(bmpinfoheader, 8, cinfo->output_height); /* biHeight */ - PUT_2B(bmpinfoheader, 12, 1); /* biPlanes - must be 1 */ - PUT_2B(bmpinfoheader, 14, bits_per_pixel); /* biBitCount */ - /* we leave biCompression = 0, for none */ - /* we leave biSizeImage = 0; this is correct for uncompressed data */ - if (cinfo->density_unit == 2) { /* if have density in dots/cm, then */ - PUT_4B(bmpinfoheader, 24, (INT32) (cinfo->X_density*100)); /* XPels/M */ - PUT_4B(bmpinfoheader, 28, (INT32) (cinfo->Y_density*100)); /* XPels/M */ - } - PUT_2B(bmpinfoheader, 32, cmap_entries); /* biClrUsed */ - /* we leave biClrImportant = 0 */ - - if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14) - ERREXIT(cinfo, JERR_FILE_WRITE); - if (JFWRITE(dest->pub.output_file, bmpinfoheader, 40) != (size_t) 40) - ERREXIT(cinfo, JERR_FILE_WRITE); - - if (cmap_entries > 0) - write_colormap(cinfo, dest, cmap_entries, 4); -} - - -LOCAL(void) -write_os2_header (j_decompress_ptr cinfo, bmp_dest_ptr dest) -/* Write an OS2-style BMP file header, including colormap if needed */ -{ - char bmpfileheader[14]; - char bmpcoreheader[12]; - INT32 headersize, bfSize; - int bits_per_pixel, cmap_entries; - - /* Compute colormap size and total file size */ - if (cinfo->out_color_space == JCS_RGB) { - if (cinfo->quantize_colors) { - /* Colormapped RGB */ - bits_per_pixel = 8; - cmap_entries = 256; - } else { - /* Unquantized, full color RGB */ - bits_per_pixel = 24; - cmap_entries = 0; - } - } else { - /* Grayscale output. We need to fake a 256-entry colormap. */ - bits_per_pixel = 8; - cmap_entries = 256; - } - /* File size */ - headersize = 14 + 12 + cmap_entries * 3; /* Header and colormap */ - bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height; - - /* Set unused fields of header to 0 */ - MEMZERO(bmpfileheader, SIZEOF(bmpfileheader)); - MEMZERO(bmpcoreheader, SIZEOF(bmpcoreheader)); - - /* Fill the file header */ - bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */ - bmpfileheader[1] = 0x4D; - PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */ - /* we leave bfReserved1 & bfReserved2 = 0 */ - PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */ - - /* Fill the info header (Microsoft calls this a BITMAPCOREHEADER) */ - PUT_2B(bmpcoreheader, 0, 12); /* bcSize */ - PUT_2B(bmpcoreheader, 4, cinfo->output_width); /* bcWidth */ - PUT_2B(bmpcoreheader, 6, cinfo->output_height); /* bcHeight */ - PUT_2B(bmpcoreheader, 8, 1); /* bcPlanes - must be 1 */ - PUT_2B(bmpcoreheader, 10, bits_per_pixel); /* bcBitCount */ - - if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14) - ERREXIT(cinfo, JERR_FILE_WRITE); - if (JFWRITE(dest->pub.output_file, bmpcoreheader, 12) != (size_t) 12) - ERREXIT(cinfo, JERR_FILE_WRITE); - - if (cmap_entries > 0) - write_colormap(cinfo, dest, cmap_entries, 3); -} - - -/* - * Write the colormap. - * Windows uses BGR0 map entries; OS/2 uses BGR entries. - */ - -LOCAL(void) -write_colormap (j_decompress_ptr cinfo, bmp_dest_ptr dest, - int map_colors, int map_entry_size) -{ - JSAMPARRAY colormap = cinfo->colormap; - int num_colors = cinfo->actual_number_of_colors; - FILE * outfile = dest->pub.output_file; - int i; - - if (colormap != NULL) { - if (cinfo->out_color_components == 3) { - /* Normal case with RGB colormap */ - for (i = 0; i < num_colors; i++) { - putc(GETJSAMPLE(colormap[2][i]), outfile); - putc(GETJSAMPLE(colormap[1][i]), outfile); - putc(GETJSAMPLE(colormap[0][i]), outfile); - if (map_entry_size == 4) - putc(0, outfile); - } - } else { - /* Grayscale colormap (only happens with grayscale quantization) */ - for (i = 0; i < num_colors; i++) { - putc(GETJSAMPLE(colormap[0][i]), outfile); - putc(GETJSAMPLE(colormap[0][i]), outfile); - putc(GETJSAMPLE(colormap[0][i]), outfile); - if (map_entry_size == 4) - putc(0, outfile); - } - } - } else { - /* If no colormap, must be grayscale data. Generate a linear "map". */ - for (i = 0; i < 256; i++) { - putc(i, outfile); - putc(i, outfile); - putc(i, outfile); - if (map_entry_size == 4) - putc(0, outfile); - } - } - /* Pad colormap with zeros to ensure specified number of colormap entries */ - if (i > map_colors) - ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, i); - for (; i < map_colors; i++) { - putc(0, outfile); - putc(0, outfile); - putc(0, outfile); - if (map_entry_size == 4) - putc(0, outfile); - } -} - - -METHODDEF(void) -finish_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) -{ - bmp_dest_ptr dest = (bmp_dest_ptr) dinfo; - register FILE * outfile = dest->pub.output_file; - JSAMPARRAY image_ptr; - register JSAMPROW data_ptr; - JDIMENSION row; - register JDIMENSION col; - cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; - - /* Write the header and colormap */ - if (dest->is_os2) - write_os2_header(cinfo, dest); - else - write_bmp_header(cinfo, dest); - - /* Write the file body from our virtual array */ - for (row = cinfo->output_height; row > 0; row--) { - if (progress != NULL) { - progress->pub.pass_counter = (long) (cinfo->output_height - row); - progress->pub.pass_limit = (long) cinfo->output_height; - (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); - } - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, dest->whole_image, row-1, (JDIMENSION) 1, FALSE); - data_ptr = image_ptr[0]; - for (col = dest->row_width; col > 0; col--) { - putc(GETJSAMPLE(*data_ptr), outfile); - data_ptr++; - } - } - if (progress != NULL) - progress->completed_extra_passes++; - - /* Make sure we wrote the output file OK */ - fflush(outfile); - if (ferror(outfile)) - ERREXIT(cinfo, JERR_FILE_WRITE); -} - - -/* - * The module selection routine for BMP format output. - */ - -GLOBAL(djpeg_dest_ptr) -jinit_write_bmp (j_decompress_ptr cinfo, boolean is_os2) -{ - bmp_dest_ptr dest; - JDIMENSION row_width; - - /* Create module interface object, fill in method pointers */ - dest = (bmp_dest_ptr) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - SIZEOF(bmp_dest_struct)); - dest->pub.start_output = start_output_bmp; - dest->pub.finish_output = finish_output_bmp; - dest->is_os2 = is_os2; - - if (cinfo->out_color_space == JCS_GRAYSCALE) { - dest->pub.put_pixel_rows = put_gray_rows; - } else if (cinfo->out_color_space == JCS_RGB) { - if (cinfo->quantize_colors) - dest->pub.put_pixel_rows = put_gray_rows; - else - dest->pub.put_pixel_rows = put_pixel_rows; - } else { - ERREXIT(cinfo, JERR_BMP_COLORSPACE); - } - - /* Calculate output image dimensions so we can allocate space */ - jpeg_calc_output_dimensions(cinfo); - - /* Determine width of rows in the BMP file (padded to 4-byte boundary). */ - row_width = cinfo->output_width * cinfo->output_components; - dest->data_width = row_width; - while ((row_width & 3) != 0) row_width++; - dest->row_width = row_width; - dest->pad_bytes = (int) (row_width - dest->data_width); - - /* Allocate space for inversion array, prepare for write pass */ - dest->whole_image = (*cinfo->mem->request_virt_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, - row_width, cinfo->output_height, (JDIMENSION) 1); - dest->cur_output_row = 0; - if (cinfo->progress != NULL) { - cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; - progress->total_extra_passes++; /* count file input as separate pass */ - } - - /* Create decompressor output buffer. */ - dest->pub.buffer = (*cinfo->mem->alloc_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, row_width, (JDIMENSION) 1); - dest->pub.buffer_height = 1; - - return (djpeg_dest_ptr) dest; -} - -#endif /* BMP_SUPPORTED */ +/* + * wrbmp.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to write output images in Microsoft "BMP" + * format (MS Windows 3.x and OS/2 1.x flavors). + * Either 8-bit colormapped or 24-bit full-color format can be written. + * No compression is supported. + * + * These routines may need modification for non-Unix environments or + * specialized applications. As they stand, they assume output to + * an ordinary stdio stream. + * + * This code contributed by James Arthur Boucher. + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + +#ifdef BMP_SUPPORTED + + +/* + * To support 12-bit JPEG data, we'd have to scale output down to 8 bits. + * This is not yet implemented. + */ + +#if BITS_IN_JSAMPLE != 8 + Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ +#endif + +/* + * Since BMP stores scanlines bottom-to-top, we have to invert the image + * from JPEG's top-to-bottom order. To do this, we save the outgoing data + * in a virtual array during put_pixel_row calls, then actually emit the + * BMP file during finish_output. The virtual array contains one JSAMPLE per + * pixel if the output is grayscale or colormapped, three if it is full color. + */ + +/* Private version of data destination object */ + +typedef struct { + struct djpeg_dest_struct pub; /* public fields */ + + boolean is_os2; /* saves the OS2 format request flag */ + + jvirt_sarray_ptr whole_image; /* needed to reverse row order */ + JDIMENSION data_width; /* JSAMPLEs per row */ + JDIMENSION row_width; /* physical width of one row in the BMP file */ + int pad_bytes; /* number of padding bytes needed per row */ + JDIMENSION cur_output_row; /* next row# to write to virtual array */ +} bmp_dest_struct; + +typedef bmp_dest_struct * bmp_dest_ptr; + + +/* Forward declarations */ +LOCAL(void) write_colormap + JPP((j_decompress_ptr cinfo, bmp_dest_ptr dest, + int map_colors, int map_entry_size)); + + +/* + * Write some pixel data. + * In this module rows_supplied will always be 1. + */ + +METHODDEF(void) +put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) +/* This version is for writing 24-bit pixels */ +{ + bmp_dest_ptr dest = (bmp_dest_ptr) dinfo; + JSAMPARRAY image_ptr; + register JSAMPROW inptr, outptr; + register JDIMENSION col; + int pad; + + /* Access next row in virtual array */ + image_ptr = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, dest->whole_image, + dest->cur_output_row, (JDIMENSION) 1, TRUE); + dest->cur_output_row++; + + /* Transfer data. Note destination values must be in BGR order + * (even though Microsoft's own documents say the opposite). + */ + inptr = dest->pub.buffer[0]; + outptr = image_ptr[0]; + for (col = cinfo->output_width; col > 0; col--) { + outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ + outptr[1] = *inptr++; + outptr[0] = *inptr++; + outptr += 3; + } + + /* Zero out the pad bytes. */ + pad = dest->pad_bytes; + while (--pad >= 0) + *outptr++ = 0; +} + +METHODDEF(void) +put_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) +/* This version is for grayscale OR quantized color output */ +{ + bmp_dest_ptr dest = (bmp_dest_ptr) dinfo; + JSAMPARRAY image_ptr; + register JSAMPROW inptr, outptr; + register JDIMENSION col; + int pad; + + /* Access next row in virtual array */ + image_ptr = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, dest->whole_image, + dest->cur_output_row, (JDIMENSION) 1, TRUE); + dest->cur_output_row++; + + /* Transfer data. */ + inptr = dest->pub.buffer[0]; + outptr = image_ptr[0]; + for (col = cinfo->output_width; col > 0; col--) { + *outptr++ = *inptr++; /* can omit GETJSAMPLE() safely */ + } + + /* Zero out the pad bytes. */ + pad = dest->pad_bytes; + while (--pad >= 0) + *outptr++ = 0; +} + + +/* + * Startup: normally writes the file header. + * In this module we may as well postpone everything until finish_output. + */ + +METHODDEF(void) +start_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) +{ + /* no work here */ +} + + +/* + * Finish up at the end of the file. + * + * Here is where we really output the BMP file. + * + * First, routines to write the Windows and OS/2 variants of the file header. + */ + +LOCAL(void) +write_bmp_header (j_decompress_ptr cinfo, bmp_dest_ptr dest) +/* Write a Windows-style BMP file header, including colormap if needed */ +{ + char bmpfileheader[14]; + char bmpinfoheader[40]; +#define PUT_2B(array,offset,value) \ + (array[offset] = (char) ((value) & 0xFF), \ + array[offset+1] = (char) (((value) >> 8) & 0xFF)) +#define PUT_4B(array,offset,value) \ + (array[offset] = (char) ((value) & 0xFF), \ + array[offset+1] = (char) (((value) >> 8) & 0xFF), \ + array[offset+2] = (char) (((value) >> 16) & 0xFF), \ + array[offset+3] = (char) (((value) >> 24) & 0xFF)) + INT32 headersize, bfSize; + int bits_per_pixel, cmap_entries; + + /* Compute colormap size and total file size */ + if (cinfo->out_color_space == JCS_RGB) { + if (cinfo->quantize_colors) { + /* Colormapped RGB */ + bits_per_pixel = 8; + cmap_entries = 256; + } else { + /* Unquantized, full color RGB */ + bits_per_pixel = 24; + cmap_entries = 0; + } + } else { + /* Grayscale output. We need to fake a 256-entry colormap. */ + bits_per_pixel = 8; + cmap_entries = 256; + } + /* File size */ + headersize = 14 + 40 + cmap_entries * 4; /* Header and colormap */ + bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height; + + /* Set unused fields of header to 0 */ + MEMZERO(bmpfileheader, SIZEOF(bmpfileheader)); + MEMZERO(bmpinfoheader, SIZEOF(bmpinfoheader)); + + /* Fill the file header */ + bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */ + bmpfileheader[1] = 0x4D; + PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */ + /* we leave bfReserved1 & bfReserved2 = 0 */ + PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */ + + /* Fill the info header (Microsoft calls this a BITMAPINFOHEADER) */ + PUT_2B(bmpinfoheader, 0, 40); /* biSize */ + PUT_4B(bmpinfoheader, 4, cinfo->output_width); /* biWidth */ + PUT_4B(bmpinfoheader, 8, cinfo->output_height); /* biHeight */ + PUT_2B(bmpinfoheader, 12, 1); /* biPlanes - must be 1 */ + PUT_2B(bmpinfoheader, 14, bits_per_pixel); /* biBitCount */ + /* we leave biCompression = 0, for none */ + /* we leave biSizeImage = 0; this is correct for uncompressed data */ + if (cinfo->density_unit == 2) { /* if have density in dots/cm, then */ + PUT_4B(bmpinfoheader, 24, (INT32) (cinfo->X_density*100)); /* XPels/M */ + PUT_4B(bmpinfoheader, 28, (INT32) (cinfo->Y_density*100)); /* XPels/M */ + } + PUT_2B(bmpinfoheader, 32, cmap_entries); /* biClrUsed */ + /* we leave biClrImportant = 0 */ + + if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14) + ERREXIT(cinfo, JERR_FILE_WRITE); + if (JFWRITE(dest->pub.output_file, bmpinfoheader, 40) != (size_t) 40) + ERREXIT(cinfo, JERR_FILE_WRITE); + + if (cmap_entries > 0) + write_colormap(cinfo, dest, cmap_entries, 4); +} + + +LOCAL(void) +write_os2_header (j_decompress_ptr cinfo, bmp_dest_ptr dest) +/* Write an OS2-style BMP file header, including colormap if needed */ +{ + char bmpfileheader[14]; + char bmpcoreheader[12]; + INT32 headersize, bfSize; + int bits_per_pixel, cmap_entries; + + /* Compute colormap size and total file size */ + if (cinfo->out_color_space == JCS_RGB) { + if (cinfo->quantize_colors) { + /* Colormapped RGB */ + bits_per_pixel = 8; + cmap_entries = 256; + } else { + /* Unquantized, full color RGB */ + bits_per_pixel = 24; + cmap_entries = 0; + } + } else { + /* Grayscale output. We need to fake a 256-entry colormap. */ + bits_per_pixel = 8; + cmap_entries = 256; + } + /* File size */ + headersize = 14 + 12 + cmap_entries * 3; /* Header and colormap */ + bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height; + + /* Set unused fields of header to 0 */ + MEMZERO(bmpfileheader, SIZEOF(bmpfileheader)); + MEMZERO(bmpcoreheader, SIZEOF(bmpcoreheader)); + + /* Fill the file header */ + bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */ + bmpfileheader[1] = 0x4D; + PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */ + /* we leave bfReserved1 & bfReserved2 = 0 */ + PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */ + + /* Fill the info header (Microsoft calls this a BITMAPCOREHEADER) */ + PUT_2B(bmpcoreheader, 0, 12); /* bcSize */ + PUT_2B(bmpcoreheader, 4, cinfo->output_width); /* bcWidth */ + PUT_2B(bmpcoreheader, 6, cinfo->output_height); /* bcHeight */ + PUT_2B(bmpcoreheader, 8, 1); /* bcPlanes - must be 1 */ + PUT_2B(bmpcoreheader, 10, bits_per_pixel); /* bcBitCount */ + + if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14) + ERREXIT(cinfo, JERR_FILE_WRITE); + if (JFWRITE(dest->pub.output_file, bmpcoreheader, 12) != (size_t) 12) + ERREXIT(cinfo, JERR_FILE_WRITE); + + if (cmap_entries > 0) + write_colormap(cinfo, dest, cmap_entries, 3); +} + + +/* + * Write the colormap. + * Windows uses BGR0 map entries; OS/2 uses BGR entries. + */ + +LOCAL(void) +write_colormap (j_decompress_ptr cinfo, bmp_dest_ptr dest, + int map_colors, int map_entry_size) +{ + JSAMPARRAY colormap = cinfo->colormap; + int num_colors = cinfo->actual_number_of_colors; + FILE * outfile = dest->pub.output_file; + int i; + + if (colormap != NULL) { + if (cinfo->out_color_components == 3) { + /* Normal case with RGB colormap */ + for (i = 0; i < num_colors; i++) { + putc(GETJSAMPLE(colormap[2][i]), outfile); + putc(GETJSAMPLE(colormap[1][i]), outfile); + putc(GETJSAMPLE(colormap[0][i]), outfile); + if (map_entry_size == 4) + putc(0, outfile); + } + } else { + /* Grayscale colormap (only happens with grayscale quantization) */ + for (i = 0; i < num_colors; i++) { + putc(GETJSAMPLE(colormap[0][i]), outfile); + putc(GETJSAMPLE(colormap[0][i]), outfile); + putc(GETJSAMPLE(colormap[0][i]), outfile); + if (map_entry_size == 4) + putc(0, outfile); + } + } + } else { + /* If no colormap, must be grayscale data. Generate a linear "map". */ + for (i = 0; i < 256; i++) { + putc(i, outfile); + putc(i, outfile); + putc(i, outfile); + if (map_entry_size == 4) + putc(0, outfile); + } + } + /* Pad colormap with zeros to ensure specified number of colormap entries */ + if (i > map_colors) + ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, i); + for (; i < map_colors; i++) { + putc(0, outfile); + putc(0, outfile); + putc(0, outfile); + if (map_entry_size == 4) + putc(0, outfile); + } +} + + +METHODDEF(void) +finish_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) +{ + bmp_dest_ptr dest = (bmp_dest_ptr) dinfo; + register FILE * outfile = dest->pub.output_file; + JSAMPARRAY image_ptr; + register JSAMPROW data_ptr; + JDIMENSION row; + register JDIMENSION col; + cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; + + /* Write the header and colormap */ + if (dest->is_os2) + write_os2_header(cinfo, dest); + else + write_bmp_header(cinfo, dest); + + /* Write the file body from our virtual array */ + for (row = cinfo->output_height; row > 0; row--) { + if (progress != NULL) { + progress->pub.pass_counter = (long) (cinfo->output_height - row); + progress->pub.pass_limit = (long) cinfo->output_height; + (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); + } + image_ptr = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, dest->whole_image, row-1, (JDIMENSION) 1, FALSE); + data_ptr = image_ptr[0]; + for (col = dest->row_width; col > 0; col--) { + putc(GETJSAMPLE(*data_ptr), outfile); + data_ptr++; + } + } + if (progress != NULL) + progress->completed_extra_passes++; + + /* Make sure we wrote the output file OK */ + fflush(outfile); + if (ferror(outfile)) + ERREXIT(cinfo, JERR_FILE_WRITE); +} + + +/* + * The module selection routine for BMP format output. + */ + +GLOBAL(djpeg_dest_ptr) +jinit_write_bmp (j_decompress_ptr cinfo, boolean is_os2) +{ + bmp_dest_ptr dest; + JDIMENSION row_width; + + /* Create module interface object, fill in method pointers */ + dest = (bmp_dest_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(bmp_dest_struct)); + dest->pub.start_output = start_output_bmp; + dest->pub.finish_output = finish_output_bmp; + dest->is_os2 = is_os2; + + if (cinfo->out_color_space == JCS_GRAYSCALE) { + dest->pub.put_pixel_rows = put_gray_rows; + } else if (cinfo->out_color_space == JCS_RGB) { + if (cinfo->quantize_colors) + dest->pub.put_pixel_rows = put_gray_rows; + else + dest->pub.put_pixel_rows = put_pixel_rows; + } else { + ERREXIT(cinfo, JERR_BMP_COLORSPACE); + } + + /* Calculate output image dimensions so we can allocate space */ + jpeg_calc_output_dimensions(cinfo); + + /* Determine width of rows in the BMP file (padded to 4-byte boundary). */ + row_width = cinfo->output_width * cinfo->output_components; + dest->data_width = row_width; + while ((row_width & 3) != 0) row_width++; + dest->row_width = row_width; + dest->pad_bytes = (int) (row_width - dest->data_width); + + /* Allocate space for inversion array, prepare for write pass */ + dest->whole_image = (*cinfo->mem->request_virt_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, + row_width, cinfo->output_height, (JDIMENSION) 1); + dest->cur_output_row = 0; + if (cinfo->progress != NULL) { + cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; + progress->total_extra_passes++; /* count file input as separate pass */ + } + + /* Create decompressor output buffer. */ + dest->pub.buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, row_width, (JDIMENSION) 1); + dest->pub.buffer_height = 1; + + return (djpeg_dest_ptr) dest; +} + +#endif /* BMP_SUPPORTED */ diff --git a/Source/LibJPEG/wrgif.c b/Source/LibJPEG/wrgif.c index 13f953b..5fe8328 100644 --- a/Source/LibJPEG/wrgif.c +++ b/Source/LibJPEG/wrgif.c @@ -1,399 +1,399 @@ -/* - * wrgif.c - * - * Copyright (C) 1991-1997, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains routines to write output images in GIF format. - * - ************************************************************************** - * NOTE: to avoid entanglements with Unisys' patent on LZW compression, * - * this code has been modified to output "uncompressed GIF" files. * - * There is no trace of the LZW algorithm in this file. * - ************************************************************************** - * - * These routines may need modification for non-Unix environments or - * specialized applications. As they stand, they assume output to - * an ordinary stdio stream. - */ - -/* - * This code is loosely based on ppmtogif from the PBMPLUS distribution - * of Feb. 1991. That file contains the following copyright notice: - * Based on GIFENCODE by David Rowley . - * Lempel-Ziv compression based on "compress" by Spencer W. Thomas et al. - * Copyright (C) 1989 by Jef Poskanzer. - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, provided - * that the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation. This software is provided "as is" without express or - * implied warranty. - * - * We are also required to state that - * "The Graphics Interchange Format(c) is the Copyright property of - * CompuServe Incorporated. GIF(sm) is a Service Mark property of - * CompuServe Incorporated." - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ - -#ifdef GIF_SUPPORTED - - -/* Private version of data destination object */ - -typedef struct { - struct djpeg_dest_struct pub; /* public fields */ - - j_decompress_ptr cinfo; /* back link saves passing separate parm */ - - /* State for packing variable-width codes into a bitstream */ - int n_bits; /* current number of bits/code */ - int maxcode; /* maximum code, given n_bits */ - INT32 cur_accum; /* holds bits not yet output */ - int cur_bits; /* # of bits in cur_accum */ - - /* State for GIF code assignment */ - int ClearCode; /* clear code (doesn't change) */ - int EOFCode; /* EOF code (ditto) */ - int code_counter; /* counts output symbols */ - - /* GIF data packet construction buffer */ - int bytesinpkt; /* # of bytes in current packet */ - char packetbuf[256]; /* workspace for accumulating packet */ - -} gif_dest_struct; - -typedef gif_dest_struct * gif_dest_ptr; - -/* Largest value that will fit in N bits */ -#define MAXCODE(n_bits) ((1 << (n_bits)) - 1) - - -/* - * Routines to package finished data bytes into GIF data blocks. - * A data block consists of a count byte (1..255) and that many data bytes. - */ - -LOCAL(void) -flush_packet (gif_dest_ptr dinfo) -/* flush any accumulated data */ -{ - if (dinfo->bytesinpkt > 0) { /* never write zero-length packet */ - dinfo->packetbuf[0] = (char) dinfo->bytesinpkt++; - if (JFWRITE(dinfo->pub.output_file, dinfo->packetbuf, dinfo->bytesinpkt) - != (size_t) dinfo->bytesinpkt) - ERREXIT(dinfo->cinfo, JERR_FILE_WRITE); - dinfo->bytesinpkt = 0; - } -} - - -/* Add a character to current packet; flush to disk if necessary */ -#define CHAR_OUT(dinfo,c) \ - { (dinfo)->packetbuf[++(dinfo)->bytesinpkt] = (char) (c); \ - if ((dinfo)->bytesinpkt >= 255) \ - flush_packet(dinfo); \ - } - - -/* Routine to convert variable-width codes into a byte stream */ - -LOCAL(void) -output (gif_dest_ptr dinfo, int code) -/* Emit a code of n_bits bits */ -/* Uses cur_accum and cur_bits to reblock into 8-bit bytes */ -{ - dinfo->cur_accum |= ((INT32) code) << dinfo->cur_bits; - dinfo->cur_bits += dinfo->n_bits; - - while (dinfo->cur_bits >= 8) { - CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF); - dinfo->cur_accum >>= 8; - dinfo->cur_bits -= 8; - } -} - - -/* The pseudo-compression algorithm. - * - * In this module we simply output each pixel value as a separate symbol; - * thus, no compression occurs. In fact, there is expansion of one bit per - * pixel, because we use a symbol width one bit wider than the pixel width. - * - * GIF ordinarily uses variable-width symbols, and the decoder will expect - * to ratchet up the symbol width after a fixed number of symbols. - * To simplify the logic and keep the expansion penalty down, we emit a - * GIF Clear code to reset the decoder just before the width would ratchet up. - * Thus, all the symbols in the output file will have the same bit width. - * Note that emitting the Clear codes at the right times is a mere matter of - * counting output symbols and is in no way dependent on the LZW patent. - * - * With a small basic pixel width (low color count), Clear codes will be - * needed very frequently, causing the file to expand even more. So this - * simplistic approach wouldn't work too well on bilevel images, for example. - * But for output of JPEG conversions the pixel width will usually be 8 bits - * (129 to 256 colors), so the overhead added by Clear symbols is only about - * one symbol in every 256. - */ - -LOCAL(void) -compress_init (gif_dest_ptr dinfo, int i_bits) -/* Initialize pseudo-compressor */ -{ - /* init all the state variables */ - dinfo->n_bits = i_bits; - dinfo->maxcode = MAXCODE(dinfo->n_bits); - dinfo->ClearCode = (1 << (i_bits - 1)); - dinfo->EOFCode = dinfo->ClearCode + 1; - dinfo->code_counter = dinfo->ClearCode + 2; - /* init output buffering vars */ - dinfo->bytesinpkt = 0; - dinfo->cur_accum = 0; - dinfo->cur_bits = 0; - /* GIF specifies an initial Clear code */ - output(dinfo, dinfo->ClearCode); -} - - -LOCAL(void) -compress_pixel (gif_dest_ptr dinfo, int c) -/* Accept and "compress" one pixel value. - * The given value must be less than n_bits wide. - */ -{ - /* Output the given pixel value as a symbol. */ - output(dinfo, c); - /* Issue Clear codes often enough to keep the reader from ratcheting up - * its symbol size. - */ - if (dinfo->code_counter < dinfo->maxcode) { - dinfo->code_counter++; - } else { - output(dinfo, dinfo->ClearCode); - dinfo->code_counter = dinfo->ClearCode + 2; /* reset the counter */ - } -} - - -LOCAL(void) -compress_term (gif_dest_ptr dinfo) -/* Clean up at end */ -{ - /* Send an EOF code */ - output(dinfo, dinfo->EOFCode); - /* Flush the bit-packing buffer */ - if (dinfo->cur_bits > 0) { - CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF); - } - /* Flush the packet buffer */ - flush_packet(dinfo); -} - - -/* GIF header construction */ - - -LOCAL(void) -put_word (gif_dest_ptr dinfo, unsigned int w) -/* Emit a 16-bit word, LSB first */ -{ - putc(w & 0xFF, dinfo->pub.output_file); - putc((w >> 8) & 0xFF, dinfo->pub.output_file); -} - - -LOCAL(void) -put_3bytes (gif_dest_ptr dinfo, int val) -/* Emit 3 copies of same byte value --- handy subr for colormap construction */ -{ - putc(val, dinfo->pub.output_file); - putc(val, dinfo->pub.output_file); - putc(val, dinfo->pub.output_file); -} - - -LOCAL(void) -emit_header (gif_dest_ptr dinfo, int num_colors, JSAMPARRAY colormap) -/* Output the GIF file header, including color map */ -/* If colormap==NULL, synthesize a gray-scale colormap */ -{ - int BitsPerPixel, ColorMapSize, InitCodeSize, FlagByte; - int cshift = dinfo->cinfo->data_precision - 8; - int i; - - if (num_colors > 256) - ERREXIT1(dinfo->cinfo, JERR_TOO_MANY_COLORS, num_colors); - /* Compute bits/pixel and related values */ - BitsPerPixel = 1; - while (num_colors > (1 << BitsPerPixel)) - BitsPerPixel++; - ColorMapSize = 1 << BitsPerPixel; - if (BitsPerPixel <= 1) - InitCodeSize = 2; - else - InitCodeSize = BitsPerPixel; - /* - * Write the GIF header. - * Note that we generate a plain GIF87 header for maximum compatibility. - */ - putc('G', dinfo->pub.output_file); - putc('I', dinfo->pub.output_file); - putc('F', dinfo->pub.output_file); - putc('8', dinfo->pub.output_file); - putc('7', dinfo->pub.output_file); - putc('a', dinfo->pub.output_file); - /* Write the Logical Screen Descriptor */ - put_word(dinfo, (unsigned int) dinfo->cinfo->output_width); - put_word(dinfo, (unsigned int) dinfo->cinfo->output_height); - FlagByte = 0x80; /* Yes, there is a global color table */ - FlagByte |= (BitsPerPixel-1) << 4; /* color resolution */ - FlagByte |= (BitsPerPixel-1); /* size of global color table */ - putc(FlagByte, dinfo->pub.output_file); - putc(0, dinfo->pub.output_file); /* Background color index */ - putc(0, dinfo->pub.output_file); /* Reserved (aspect ratio in GIF89) */ - /* Write the Global Color Map */ - /* If the color map is more than 8 bits precision, */ - /* we reduce it to 8 bits by shifting */ - for (i=0; i < ColorMapSize; i++) { - if (i < num_colors) { - if (colormap != NULL) { - if (dinfo->cinfo->out_color_space == JCS_RGB) { - /* Normal case: RGB color map */ - putc(GETJSAMPLE(colormap[0][i]) >> cshift, dinfo->pub.output_file); - putc(GETJSAMPLE(colormap[1][i]) >> cshift, dinfo->pub.output_file); - putc(GETJSAMPLE(colormap[2][i]) >> cshift, dinfo->pub.output_file); - } else { - /* Grayscale "color map": possible if quantizing grayscale image */ - put_3bytes(dinfo, GETJSAMPLE(colormap[0][i]) >> cshift); - } - } else { - /* Create a gray-scale map of num_colors values, range 0..255 */ - put_3bytes(dinfo, (i * 255 + (num_colors-1)/2) / (num_colors-1)); - } - } else { - /* fill out the map to a power of 2 */ - put_3bytes(dinfo, 0); - } - } - /* Write image separator and Image Descriptor */ - putc(',', dinfo->pub.output_file); /* separator */ - put_word(dinfo, 0); /* left/top offset */ - put_word(dinfo, 0); - put_word(dinfo, (unsigned int) dinfo->cinfo->output_width); /* image size */ - put_word(dinfo, (unsigned int) dinfo->cinfo->output_height); - /* flag byte: not interlaced, no local color map */ - putc(0x00, dinfo->pub.output_file); - /* Write Initial Code Size byte */ - putc(InitCodeSize, dinfo->pub.output_file); - - /* Initialize for "compression" of image data */ - compress_init(dinfo, InitCodeSize+1); -} - - -/* - * Startup: write the file header. - */ - -METHODDEF(void) -start_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) -{ - gif_dest_ptr dest = (gif_dest_ptr) dinfo; - - if (cinfo->quantize_colors) - emit_header(dest, cinfo->actual_number_of_colors, cinfo->colormap); - else - emit_header(dest, 256, (JSAMPARRAY) NULL); -} - - -/* - * Write some pixel data. - * In this module rows_supplied will always be 1. - */ - -METHODDEF(void) -put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, - JDIMENSION rows_supplied) -{ - gif_dest_ptr dest = (gif_dest_ptr) dinfo; - register JSAMPROW ptr; - register JDIMENSION col; - - ptr = dest->pub.buffer[0]; - for (col = cinfo->output_width; col > 0; col--) { - compress_pixel(dest, GETJSAMPLE(*ptr++)); - } -} - - -/* - * Finish up at the end of the file. - */ - -METHODDEF(void) -finish_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) -{ - gif_dest_ptr dest = (gif_dest_ptr) dinfo; - - /* Flush "compression" mechanism */ - compress_term(dest); - /* Write a zero-length data block to end the series */ - putc(0, dest->pub.output_file); - /* Write the GIF terminator mark */ - putc(';', dest->pub.output_file); - /* Make sure we wrote the output file OK */ - fflush(dest->pub.output_file); - if (ferror(dest->pub.output_file)) - ERREXIT(cinfo, JERR_FILE_WRITE); -} - - -/* - * The module selection routine for GIF format output. - */ - -GLOBAL(djpeg_dest_ptr) -jinit_write_gif (j_decompress_ptr cinfo) -{ - gif_dest_ptr dest; - - /* Create module interface object, fill in method pointers */ - dest = (gif_dest_ptr) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - SIZEOF(gif_dest_struct)); - dest->cinfo = cinfo; /* make back link for subroutines */ - dest->pub.start_output = start_output_gif; - dest->pub.put_pixel_rows = put_pixel_rows; - dest->pub.finish_output = finish_output_gif; - - if (cinfo->out_color_space != JCS_GRAYSCALE && - cinfo->out_color_space != JCS_RGB) - ERREXIT(cinfo, JERR_GIF_COLORSPACE); - - /* Force quantization if color or if > 8 bits input */ - if (cinfo->out_color_space != JCS_GRAYSCALE || cinfo->data_precision > 8) { - /* Force quantization to at most 256 colors */ - cinfo->quantize_colors = TRUE; - if (cinfo->desired_number_of_colors > 256) - cinfo->desired_number_of_colors = 256; - } - - /* Calculate output image dimensions so we can allocate space */ - jpeg_calc_output_dimensions(cinfo); - - if (cinfo->output_components != 1) /* safety check: just one component? */ - ERREXIT(cinfo, JERR_GIF_BUG); - - /* Create decompressor output buffer. */ - dest->pub.buffer = (*cinfo->mem->alloc_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, cinfo->output_width, (JDIMENSION) 1); - dest->pub.buffer_height = 1; - - return (djpeg_dest_ptr) dest; -} - -#endif /* GIF_SUPPORTED */ +/* + * wrgif.c + * + * Copyright (C) 1991-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to write output images in GIF format. + * + ************************************************************************** + * NOTE: to avoid entanglements with Unisys' patent on LZW compression, * + * this code has been modified to output "uncompressed GIF" files. * + * There is no trace of the LZW algorithm in this file. * + ************************************************************************** + * + * These routines may need modification for non-Unix environments or + * specialized applications. As they stand, they assume output to + * an ordinary stdio stream. + */ + +/* + * This code is loosely based on ppmtogif from the PBMPLUS distribution + * of Feb. 1991. That file contains the following copyright notice: + * Based on GIFENCODE by David Rowley . + * Lempel-Ziv compression based on "compress" by Spencer W. Thomas et al. + * Copyright (C) 1989 by Jef Poskanzer. + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. This software is provided "as is" without express or + * implied warranty. + * + * We are also required to state that + * "The Graphics Interchange Format(c) is the Copyright property of + * CompuServe Incorporated. GIF(sm) is a Service Mark property of + * CompuServe Incorporated." + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + +#ifdef GIF_SUPPORTED + + +/* Private version of data destination object */ + +typedef struct { + struct djpeg_dest_struct pub; /* public fields */ + + j_decompress_ptr cinfo; /* back link saves passing separate parm */ + + /* State for packing variable-width codes into a bitstream */ + int n_bits; /* current number of bits/code */ + int maxcode; /* maximum code, given n_bits */ + INT32 cur_accum; /* holds bits not yet output */ + int cur_bits; /* # of bits in cur_accum */ + + /* State for GIF code assignment */ + int ClearCode; /* clear code (doesn't change) */ + int EOFCode; /* EOF code (ditto) */ + int code_counter; /* counts output symbols */ + + /* GIF data packet construction buffer */ + int bytesinpkt; /* # of bytes in current packet */ + char packetbuf[256]; /* workspace for accumulating packet */ + +} gif_dest_struct; + +typedef gif_dest_struct * gif_dest_ptr; + +/* Largest value that will fit in N bits */ +#define MAXCODE(n_bits) ((1 << (n_bits)) - 1) + + +/* + * Routines to package finished data bytes into GIF data blocks. + * A data block consists of a count byte (1..255) and that many data bytes. + */ + +LOCAL(void) +flush_packet (gif_dest_ptr dinfo) +/* flush any accumulated data */ +{ + if (dinfo->bytesinpkt > 0) { /* never write zero-length packet */ + dinfo->packetbuf[0] = (char) dinfo->bytesinpkt++; + if (JFWRITE(dinfo->pub.output_file, dinfo->packetbuf, dinfo->bytesinpkt) + != (size_t) dinfo->bytesinpkt) + ERREXIT(dinfo->cinfo, JERR_FILE_WRITE); + dinfo->bytesinpkt = 0; + } +} + + +/* Add a character to current packet; flush to disk if necessary */ +#define CHAR_OUT(dinfo,c) \ + { (dinfo)->packetbuf[++(dinfo)->bytesinpkt] = (char) (c); \ + if ((dinfo)->bytesinpkt >= 255) \ + flush_packet(dinfo); \ + } + + +/* Routine to convert variable-width codes into a byte stream */ + +LOCAL(void) +output (gif_dest_ptr dinfo, int code) +/* Emit a code of n_bits bits */ +/* Uses cur_accum and cur_bits to reblock into 8-bit bytes */ +{ + dinfo->cur_accum |= ((INT32) code) << dinfo->cur_bits; + dinfo->cur_bits += dinfo->n_bits; + + while (dinfo->cur_bits >= 8) { + CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF); + dinfo->cur_accum >>= 8; + dinfo->cur_bits -= 8; + } +} + + +/* The pseudo-compression algorithm. + * + * In this module we simply output each pixel value as a separate symbol; + * thus, no compression occurs. In fact, there is expansion of one bit per + * pixel, because we use a symbol width one bit wider than the pixel width. + * + * GIF ordinarily uses variable-width symbols, and the decoder will expect + * to ratchet up the symbol width after a fixed number of symbols. + * To simplify the logic and keep the expansion penalty down, we emit a + * GIF Clear code to reset the decoder just before the width would ratchet up. + * Thus, all the symbols in the output file will have the same bit width. + * Note that emitting the Clear codes at the right times is a mere matter of + * counting output symbols and is in no way dependent on the LZW patent. + * + * With a small basic pixel width (low color count), Clear codes will be + * needed very frequently, causing the file to expand even more. So this + * simplistic approach wouldn't work too well on bilevel images, for example. + * But for output of JPEG conversions the pixel width will usually be 8 bits + * (129 to 256 colors), so the overhead added by Clear symbols is only about + * one symbol in every 256. + */ + +LOCAL(void) +compress_init (gif_dest_ptr dinfo, int i_bits) +/* Initialize pseudo-compressor */ +{ + /* init all the state variables */ + dinfo->n_bits = i_bits; + dinfo->maxcode = MAXCODE(dinfo->n_bits); + dinfo->ClearCode = (1 << (i_bits - 1)); + dinfo->EOFCode = dinfo->ClearCode + 1; + dinfo->code_counter = dinfo->ClearCode + 2; + /* init output buffering vars */ + dinfo->bytesinpkt = 0; + dinfo->cur_accum = 0; + dinfo->cur_bits = 0; + /* GIF specifies an initial Clear code */ + output(dinfo, dinfo->ClearCode); +} + + +LOCAL(void) +compress_pixel (gif_dest_ptr dinfo, int c) +/* Accept and "compress" one pixel value. + * The given value must be less than n_bits wide. + */ +{ + /* Output the given pixel value as a symbol. */ + output(dinfo, c); + /* Issue Clear codes often enough to keep the reader from ratcheting up + * its symbol size. + */ + if (dinfo->code_counter < dinfo->maxcode) { + dinfo->code_counter++; + } else { + output(dinfo, dinfo->ClearCode); + dinfo->code_counter = dinfo->ClearCode + 2; /* reset the counter */ + } +} + + +LOCAL(void) +compress_term (gif_dest_ptr dinfo) +/* Clean up at end */ +{ + /* Send an EOF code */ + output(dinfo, dinfo->EOFCode); + /* Flush the bit-packing buffer */ + if (dinfo->cur_bits > 0) { + CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF); + } + /* Flush the packet buffer */ + flush_packet(dinfo); +} + + +/* GIF header construction */ + + +LOCAL(void) +put_word (gif_dest_ptr dinfo, unsigned int w) +/* Emit a 16-bit word, LSB first */ +{ + putc(w & 0xFF, dinfo->pub.output_file); + putc((w >> 8) & 0xFF, dinfo->pub.output_file); +} + + +LOCAL(void) +put_3bytes (gif_dest_ptr dinfo, int val) +/* Emit 3 copies of same byte value --- handy subr for colormap construction */ +{ + putc(val, dinfo->pub.output_file); + putc(val, dinfo->pub.output_file); + putc(val, dinfo->pub.output_file); +} + + +LOCAL(void) +emit_header (gif_dest_ptr dinfo, int num_colors, JSAMPARRAY colormap) +/* Output the GIF file header, including color map */ +/* If colormap==NULL, synthesize a gray-scale colormap */ +{ + int BitsPerPixel, ColorMapSize, InitCodeSize, FlagByte; + int cshift = dinfo->cinfo->data_precision - 8; + int i; + + if (num_colors > 256) + ERREXIT1(dinfo->cinfo, JERR_TOO_MANY_COLORS, num_colors); + /* Compute bits/pixel and related values */ + BitsPerPixel = 1; + while (num_colors > (1 << BitsPerPixel)) + BitsPerPixel++; + ColorMapSize = 1 << BitsPerPixel; + if (BitsPerPixel <= 1) + InitCodeSize = 2; + else + InitCodeSize = BitsPerPixel; + /* + * Write the GIF header. + * Note that we generate a plain GIF87 header for maximum compatibility. + */ + putc('G', dinfo->pub.output_file); + putc('I', dinfo->pub.output_file); + putc('F', dinfo->pub.output_file); + putc('8', dinfo->pub.output_file); + putc('7', dinfo->pub.output_file); + putc('a', dinfo->pub.output_file); + /* Write the Logical Screen Descriptor */ + put_word(dinfo, (unsigned int) dinfo->cinfo->output_width); + put_word(dinfo, (unsigned int) dinfo->cinfo->output_height); + FlagByte = 0x80; /* Yes, there is a global color table */ + FlagByte |= (BitsPerPixel-1) << 4; /* color resolution */ + FlagByte |= (BitsPerPixel-1); /* size of global color table */ + putc(FlagByte, dinfo->pub.output_file); + putc(0, dinfo->pub.output_file); /* Background color index */ + putc(0, dinfo->pub.output_file); /* Reserved (aspect ratio in GIF89) */ + /* Write the Global Color Map */ + /* If the color map is more than 8 bits precision, */ + /* we reduce it to 8 bits by shifting */ + for (i=0; i < ColorMapSize; i++) { + if (i < num_colors) { + if (colormap != NULL) { + if (dinfo->cinfo->out_color_space == JCS_RGB) { + /* Normal case: RGB color map */ + putc(GETJSAMPLE(colormap[0][i]) >> cshift, dinfo->pub.output_file); + putc(GETJSAMPLE(colormap[1][i]) >> cshift, dinfo->pub.output_file); + putc(GETJSAMPLE(colormap[2][i]) >> cshift, dinfo->pub.output_file); + } else { + /* Grayscale "color map": possible if quantizing grayscale image */ + put_3bytes(dinfo, GETJSAMPLE(colormap[0][i]) >> cshift); + } + } else { + /* Create a gray-scale map of num_colors values, range 0..255 */ + put_3bytes(dinfo, (i * 255 + (num_colors-1)/2) / (num_colors-1)); + } + } else { + /* fill out the map to a power of 2 */ + put_3bytes(dinfo, 0); + } + } + /* Write image separator and Image Descriptor */ + putc(',', dinfo->pub.output_file); /* separator */ + put_word(dinfo, 0); /* left/top offset */ + put_word(dinfo, 0); + put_word(dinfo, (unsigned int) dinfo->cinfo->output_width); /* image size */ + put_word(dinfo, (unsigned int) dinfo->cinfo->output_height); + /* flag byte: not interlaced, no local color map */ + putc(0x00, dinfo->pub.output_file); + /* Write Initial Code Size byte */ + putc(InitCodeSize, dinfo->pub.output_file); + + /* Initialize for "compression" of image data */ + compress_init(dinfo, InitCodeSize+1); +} + + +/* + * Startup: write the file header. + */ + +METHODDEF(void) +start_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) +{ + gif_dest_ptr dest = (gif_dest_ptr) dinfo; + + if (cinfo->quantize_colors) + emit_header(dest, cinfo->actual_number_of_colors, cinfo->colormap); + else + emit_header(dest, 256, (JSAMPARRAY) NULL); +} + + +/* + * Write some pixel data. + * In this module rows_supplied will always be 1. + */ + +METHODDEF(void) +put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) +{ + gif_dest_ptr dest = (gif_dest_ptr) dinfo; + register JSAMPROW ptr; + register JDIMENSION col; + + ptr = dest->pub.buffer[0]; + for (col = cinfo->output_width; col > 0; col--) { + compress_pixel(dest, GETJSAMPLE(*ptr++)); + } +} + + +/* + * Finish up at the end of the file. + */ + +METHODDEF(void) +finish_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) +{ + gif_dest_ptr dest = (gif_dest_ptr) dinfo; + + /* Flush "compression" mechanism */ + compress_term(dest); + /* Write a zero-length data block to end the series */ + putc(0, dest->pub.output_file); + /* Write the GIF terminator mark */ + putc(';', dest->pub.output_file); + /* Make sure we wrote the output file OK */ + fflush(dest->pub.output_file); + if (ferror(dest->pub.output_file)) + ERREXIT(cinfo, JERR_FILE_WRITE); +} + + +/* + * The module selection routine for GIF format output. + */ + +GLOBAL(djpeg_dest_ptr) +jinit_write_gif (j_decompress_ptr cinfo) +{ + gif_dest_ptr dest; + + /* Create module interface object, fill in method pointers */ + dest = (gif_dest_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(gif_dest_struct)); + dest->cinfo = cinfo; /* make back link for subroutines */ + dest->pub.start_output = start_output_gif; + dest->pub.put_pixel_rows = put_pixel_rows; + dest->pub.finish_output = finish_output_gif; + + if (cinfo->out_color_space != JCS_GRAYSCALE && + cinfo->out_color_space != JCS_RGB) + ERREXIT(cinfo, JERR_GIF_COLORSPACE); + + /* Force quantization if color or if > 8 bits input */ + if (cinfo->out_color_space != JCS_GRAYSCALE || cinfo->data_precision > 8) { + /* Force quantization to at most 256 colors */ + cinfo->quantize_colors = TRUE; + if (cinfo->desired_number_of_colors > 256) + cinfo->desired_number_of_colors = 256; + } + + /* Calculate output image dimensions so we can allocate space */ + jpeg_calc_output_dimensions(cinfo); + + if (cinfo->output_components != 1) /* safety check: just one component? */ + ERREXIT(cinfo, JERR_GIF_BUG); + + /* Create decompressor output buffer. */ + dest->pub.buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, cinfo->output_width, (JDIMENSION) 1); + dest->pub.buffer_height = 1; + + return (djpeg_dest_ptr) dest; +} + +#endif /* GIF_SUPPORTED */ diff --git a/Source/LibJPEG/wrjpgcom.c b/Source/LibJPEG/wrjpgcom.c index 7d10ee6..8c04b05 100644 --- a/Source/LibJPEG/wrjpgcom.c +++ b/Source/LibJPEG/wrjpgcom.c @@ -1,583 +1,583 @@ -/* - * wrjpgcom.c - * - * Copyright (C) 1994-1997, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains a very simple stand-alone application that inserts - * user-supplied text as a COM (comment) marker in a JFIF file. - * This may be useful as an example of the minimum logic needed to parse - * JPEG markers. - */ - -#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */ -#include "jinclude.h" /* get auto-config symbols, */ - -#ifndef HAVE_STDLIB_H /* should declare malloc() */ -extern void * malloc (); -#endif -#include /* to declare isupper(), tolower() */ -#ifdef USE_SETMODE -#include /* to declare setmode()'s parameter macros */ -/* If you have setmode() but not , just delete this line: */ -#include /* to declare setmode() */ -#endif - -#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ -#ifdef __MWERKS__ -#include /* Metrowerks needs this */ -#include /* ... and this */ -#endif -#ifdef THINK_C -#include /* Think declares it here */ -#endif -#endif - -#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ -#define READ_BINARY "r" -#define WRITE_BINARY "w" -#else -#ifdef VMS /* VMS is very nonstandard */ -#define READ_BINARY "rb", "ctx=stm" -#define WRITE_BINARY "wb", "ctx=stm" -#else /* standard ANSI-compliant case */ -#define READ_BINARY "rb" -#define WRITE_BINARY "wb" -#endif -#endif - -#ifndef EXIT_FAILURE /* define exit() codes if not provided */ -#define EXIT_FAILURE 1 -#endif -#ifndef EXIT_SUCCESS -#ifdef VMS -#define EXIT_SUCCESS 1 /* VMS is very nonstandard */ -#else -#define EXIT_SUCCESS 0 -#endif -#endif - -/* Reduce this value if your malloc() can't allocate blocks up to 64K. - * On DOS, compiling in large model is usually a better solution. - */ - -#ifndef MAX_COM_LENGTH -#define MAX_COM_LENGTH 65000L /* must be <= 65533 in any case */ -#endif - - -/* - * These macros are used to read the input file and write the output file. - * To reuse this code in another application, you might need to change these. - */ - -static FILE * infile; /* input JPEG file */ - -/* Return next input byte, or EOF if no more */ -#define NEXTBYTE() getc(infile) - -static FILE * outfile; /* output JPEG file */ - -/* Emit an output byte */ -#define PUTBYTE(x) putc((x), outfile) - - -/* Error exit handler */ -#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE)) - - -/* Read one byte, testing for EOF */ -static int -read_1_byte (void) -{ - int c; - - c = NEXTBYTE(); - if (c == EOF) - ERREXIT("Premature EOF in JPEG file"); - return c; -} - -/* Read 2 bytes, convert to unsigned int */ -/* All 2-byte quantities in JPEG markers are MSB first */ -static unsigned int -read_2_bytes (void) -{ - int c1, c2; - - c1 = NEXTBYTE(); - if (c1 == EOF) - ERREXIT("Premature EOF in JPEG file"); - c2 = NEXTBYTE(); - if (c2 == EOF) - ERREXIT("Premature EOF in JPEG file"); - return (((unsigned int) c1) << 8) + ((unsigned int) c2); -} - - -/* Routines to write data to output file */ - -static void -write_1_byte (int c) -{ - PUTBYTE(c); -} - -static void -write_2_bytes (unsigned int val) -{ - PUTBYTE((val >> 8) & 0xFF); - PUTBYTE(val & 0xFF); -} - -static void -write_marker (int marker) -{ - PUTBYTE(0xFF); - PUTBYTE(marker); -} - -static void -copy_rest_of_file (void) -{ - int c; - - while ((c = NEXTBYTE()) != EOF) - PUTBYTE(c); -} - - -/* - * JPEG markers consist of one or more 0xFF bytes, followed by a marker - * code byte (which is not an FF). Here are the marker codes of interest - * in this program. (See jdmarker.c for a more complete list.) - */ - -#define M_SOF0 0xC0 /* Start Of Frame N */ -#define M_SOF1 0xC1 /* N indicates which compression process */ -#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */ -#define M_SOF3 0xC3 -#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */ -#define M_SOF6 0xC6 -#define M_SOF7 0xC7 -#define M_SOF9 0xC9 -#define M_SOF10 0xCA -#define M_SOF11 0xCB -#define M_SOF13 0xCD -#define M_SOF14 0xCE -#define M_SOF15 0xCF -#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */ -#define M_EOI 0xD9 /* End Of Image (end of datastream) */ -#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ -#define M_COM 0xFE /* COMment */ - - -/* - * Find the next JPEG marker and return its marker code. - * We expect at least one FF byte, possibly more if the compressor used FFs - * to pad the file. (Padding FFs will NOT be replicated in the output file.) - * There could also be non-FF garbage between markers. The treatment of such - * garbage is unspecified; we choose to skip over it but emit a warning msg. - * NB: this routine must not be used after seeing SOS marker, since it will - * not deal correctly with FF/00 sequences in the compressed image data... - */ - -static int -next_marker (void) -{ - int c; - int discarded_bytes = 0; - - /* Find 0xFF byte; count and skip any non-FFs. */ - c = read_1_byte(); - while (c != 0xFF) { - discarded_bytes++; - c = read_1_byte(); - } - /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs - * are legal as pad bytes, so don't count them in discarded_bytes. - */ - do { - c = read_1_byte(); - } while (c == 0xFF); - - if (discarded_bytes != 0) { - fprintf(stderr, "Warning: garbage data found in JPEG file\n"); - } - - return c; -} - - -/* - * Read the initial marker, which should be SOI. - * For a JFIF file, the first two bytes of the file should be literally - * 0xFF M_SOI. To be more general, we could use next_marker, but if the - * input file weren't actually JPEG at all, next_marker might read the whole - * file and then return a misleading error message... - */ - -static int -first_marker (void) -{ - int c1, c2; - - c1 = NEXTBYTE(); - c2 = NEXTBYTE(); - if (c1 != 0xFF || c2 != M_SOI) - ERREXIT("Not a JPEG file"); - return c2; -} - - -/* - * Most types of marker are followed by a variable-length parameter segment. - * This routine skips over the parameters for any marker we don't otherwise - * want to process. - * Note that we MUST skip the parameter segment explicitly in order not to - * be fooled by 0xFF bytes that might appear within the parameter segment; - * such bytes do NOT introduce new markers. - */ - -static void -copy_variable (void) -/* Copy an unknown or uninteresting variable-length marker */ -{ - unsigned int length; - - /* Get the marker parameter length count */ - length = read_2_bytes(); - write_2_bytes(length); - /* Length includes itself, so must be at least 2 */ - if (length < 2) - ERREXIT("Erroneous JPEG marker length"); - length -= 2; - /* Skip over the remaining bytes */ - while (length > 0) { - write_1_byte(read_1_byte()); - length--; - } -} - -static void -skip_variable (void) -/* Skip over an unknown or uninteresting variable-length marker */ -{ - unsigned int length; - - /* Get the marker parameter length count */ - length = read_2_bytes(); - /* Length includes itself, so must be at least 2 */ - if (length < 2) - ERREXIT("Erroneous JPEG marker length"); - length -= 2; - /* Skip over the remaining bytes */ - while (length > 0) { - (void) read_1_byte(); - length--; - } -} - - -/* - * Parse the marker stream until SOFn or EOI is seen; - * copy data to output, but discard COM markers unless keep_COM is true. - */ - -static int -scan_JPEG_header (int keep_COM) -{ - int marker; - - /* Expect SOI at start of file */ - if (first_marker() != M_SOI) - ERREXIT("Expected SOI marker first"); - write_marker(M_SOI); - - /* Scan miscellaneous markers until we reach SOFn. */ - for (;;) { - marker = next_marker(); - switch (marker) { - /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be, - * treated as SOFn. C4 in particular is actually DHT. - */ - case M_SOF0: /* Baseline */ - case M_SOF1: /* Extended sequential, Huffman */ - case M_SOF2: /* Progressive, Huffman */ - case M_SOF3: /* Lossless, Huffman */ - case M_SOF5: /* Differential sequential, Huffman */ - case M_SOF6: /* Differential progressive, Huffman */ - case M_SOF7: /* Differential lossless, Huffman */ - case M_SOF9: /* Extended sequential, arithmetic */ - case M_SOF10: /* Progressive, arithmetic */ - case M_SOF11: /* Lossless, arithmetic */ - case M_SOF13: /* Differential sequential, arithmetic */ - case M_SOF14: /* Differential progressive, arithmetic */ - case M_SOF15: /* Differential lossless, arithmetic */ - return marker; - - case M_SOS: /* should not see compressed data before SOF */ - ERREXIT("SOS without prior SOFn"); - break; - - case M_EOI: /* in case it's a tables-only JPEG stream */ - return marker; - - case M_COM: /* Existing COM: conditionally discard */ - if (keep_COM) { - write_marker(marker); - copy_variable(); - } else { - skip_variable(); - } - break; - - default: /* Anything else just gets copied */ - write_marker(marker); - copy_variable(); /* we assume it has a parameter count... */ - break; - } - } /* end loop */ -} - - -/* Command line parsing code */ - -static const char * progname; /* program name for error messages */ - - -static void -usage (void) -/* complain about bad command line */ -{ - fprintf(stderr, "wrjpgcom inserts a textual comment in a JPEG file.\n"); - fprintf(stderr, "You can add to or replace any existing comment(s).\n"); - - fprintf(stderr, "Usage: %s [switches] ", progname); -#ifdef TWO_FILE_COMMANDLINE - fprintf(stderr, "inputfile outputfile\n"); -#else - fprintf(stderr, "[inputfile]\n"); -#endif - - fprintf(stderr, "Switches (names may be abbreviated):\n"); - fprintf(stderr, " -replace Delete any existing comments\n"); - fprintf(stderr, " -comment \"text\" Insert comment with given text\n"); - fprintf(stderr, " -cfile name Read comment from named file\n"); - fprintf(stderr, "Notice that you must put quotes around the comment text\n"); - fprintf(stderr, "when you use -comment.\n"); - fprintf(stderr, "If you do not give either -comment or -cfile on the command line,\n"); - fprintf(stderr, "then the comment text is read from standard input.\n"); - fprintf(stderr, "It can be multiple lines, up to %u characters total.\n", - (unsigned int) MAX_COM_LENGTH); -#ifndef TWO_FILE_COMMANDLINE - fprintf(stderr, "You must specify an input JPEG file name when supplying\n"); - fprintf(stderr, "comment text from standard input.\n"); -#endif - - exit(EXIT_FAILURE); -} - - -static int -keymatch (char * arg, const char * keyword, int minchars) -/* Case-insensitive matching of (possibly abbreviated) keyword switches. */ -/* keyword is the constant keyword (must be lower case already), */ -/* minchars is length of minimum legal abbreviation. */ -{ - register int ca, ck; - register int nmatched = 0; - - while ((ca = *arg++) != '\0') { - if ((ck = *keyword++) == '\0') - return 0; /* arg longer than keyword, no good */ - if (isupper(ca)) /* force arg to lcase (assume ck is already) */ - ca = tolower(ca); - if (ca != ck) - return 0; /* no good */ - nmatched++; /* count matched characters */ - } - /* reached end of argument; fail if it's too short for unique abbrev */ - if (nmatched < minchars) - return 0; - return 1; /* A-OK */ -} - - -/* - * The main program. - */ - -int -main (int argc, char **argv) -{ - int argn; - char * arg; - int keep_COM = 1; - char * comment_arg = NULL; - FILE * comment_file = NULL; - unsigned int comment_length = 0; - int marker; - - /* On Mac, fetch a command line. */ -#ifdef USE_CCOMMAND - argc = ccommand(&argv); -#endif - - progname = argv[0]; - if (progname == NULL || progname[0] == 0) - progname = "wrjpgcom"; /* in case C library doesn't provide it */ - - /* Parse switches, if any */ - for (argn = 1; argn < argc; argn++) { - arg = argv[argn]; - if (arg[0] != '-') - break; /* not switch, must be file name */ - arg++; /* advance over '-' */ - if (keymatch(arg, "replace", 1)) { - keep_COM = 0; - } else if (keymatch(arg, "cfile", 2)) { - if (++argn >= argc) usage(); - if ((comment_file = fopen(argv[argn], "r")) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); - exit(EXIT_FAILURE); - } - } else if (keymatch(arg, "comment", 1)) { - if (++argn >= argc) usage(); - comment_arg = argv[argn]; - /* If the comment text starts with '"', then we are probably running - * under MS-DOG and must parse out the quoted string ourselves. Sigh. - */ - if (comment_arg[0] == '"') { - comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH); - if (comment_arg == NULL) - ERREXIT("Insufficient memory"); - strcpy(comment_arg, argv[argn]+1); - for (;;) { - comment_length = (unsigned int) strlen(comment_arg); - if (comment_length > 0 && comment_arg[comment_length-1] == '"') { - comment_arg[comment_length-1] = '\0'; /* zap terminating quote */ - break; - } - if (++argn >= argc) - ERREXIT("Missing ending quote mark"); - strcat(comment_arg, " "); - strcat(comment_arg, argv[argn]); - } - } - comment_length = (unsigned int) strlen(comment_arg); - } else - usage(); - } - - /* Cannot use both -comment and -cfile. */ - if (comment_arg != NULL && comment_file != NULL) - usage(); - /* If there is neither -comment nor -cfile, we will read the comment text - * from stdin; in this case there MUST be an input JPEG file name. - */ - if (comment_arg == NULL && comment_file == NULL && argn >= argc) - usage(); - - /* Open the input file. */ - if (argn < argc) { - if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); - exit(EXIT_FAILURE); - } - } else { - /* default input file is stdin */ -#ifdef USE_SETMODE /* need to hack file mode? */ - setmode(fileno(stdin), O_BINARY); -#endif -#ifdef USE_FDOPEN /* need to re-open in binary mode? */ - if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open stdin\n", progname); - exit(EXIT_FAILURE); - } -#else - infile = stdin; -#endif - } - - /* Open the output file. */ -#ifdef TWO_FILE_COMMANDLINE - /* Must have explicit output file name */ - if (argn != argc-2) { - fprintf(stderr, "%s: must name one input and one output file\n", - progname); - usage(); - } - if ((outfile = fopen(argv[argn+1], WRITE_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, argv[argn+1]); - exit(EXIT_FAILURE); - } -#else - /* Unix style: expect zero or one file name */ - if (argn < argc-1) { - fprintf(stderr, "%s: only one input file\n", progname); - usage(); - } - /* default output file is stdout */ -#ifdef USE_SETMODE /* need to hack file mode? */ - setmode(fileno(stdout), O_BINARY); -#endif -#ifdef USE_FDOPEN /* need to re-open in binary mode? */ - if ((outfile = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open stdout\n", progname); - exit(EXIT_FAILURE); - } -#else - outfile = stdout; -#endif -#endif /* TWO_FILE_COMMANDLINE */ - - /* Collect comment text from comment_file or stdin, if necessary */ - if (comment_arg == NULL) { - FILE * src_file; - int c; - - comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH); - if (comment_arg == NULL) - ERREXIT("Insufficient memory"); - comment_length = 0; - src_file = (comment_file != NULL ? comment_file : stdin); - while ((c = getc(src_file)) != EOF) { - if (comment_length >= (unsigned int) MAX_COM_LENGTH) { - fprintf(stderr, "Comment text may not exceed %u bytes\n", - (unsigned int) MAX_COM_LENGTH); - exit(EXIT_FAILURE); - } - comment_arg[comment_length++] = (char) c; - } - if (comment_file != NULL) - fclose(comment_file); - } - - /* Copy JPEG headers until SOFn marker; - * we will insert the new comment marker just before SOFn. - * This (a) causes the new comment to appear after, rather than before, - * existing comments; and (b) ensures that comments come after any JFIF - * or JFXX markers, as required by the JFIF specification. - */ - marker = scan_JPEG_header(keep_COM); - /* Insert the new COM marker, but only if nonempty text has been supplied */ - if (comment_length > 0) { - write_marker(M_COM); - write_2_bytes(comment_length + 2); - while (comment_length > 0) { - write_1_byte(*comment_arg++); - comment_length--; - } - } - /* Duplicate the remainder of the source file. - * Note that any COM markers occuring after SOF will not be touched. - */ - write_marker(marker); - copy_rest_of_file(); - - /* All done. */ - exit(EXIT_SUCCESS); - return 0; /* suppress no-return-value warnings */ -} +/* + * wrjpgcom.c + * + * Copyright (C) 1994-1997, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a very simple stand-alone application that inserts + * user-supplied text as a COM (comment) marker in a JFIF file. + * This may be useful as an example of the minimum logic needed to parse + * JPEG markers. + */ + +#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */ +#include "jinclude.h" /* get auto-config symbols, */ + +#ifndef HAVE_STDLIB_H /* should declare malloc() */ +extern void * malloc (); +#endif +#include /* to declare isupper(), tolower() */ +#ifdef USE_SETMODE +#include /* to declare setmode()'s parameter macros */ +/* If you have setmode() but not , just delete this line: */ +#include /* to declare setmode() */ +#endif + +#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ +#ifdef __MWERKS__ +#include /* Metrowerks needs this */ +#include /* ... and this */ +#endif +#ifdef THINK_C +#include /* Think declares it here */ +#endif +#endif + +#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ +#define READ_BINARY "r" +#define WRITE_BINARY "w" +#else +#ifdef VMS /* VMS is very nonstandard */ +#define READ_BINARY "rb", "ctx=stm" +#define WRITE_BINARY "wb", "ctx=stm" +#else /* standard ANSI-compliant case */ +#define READ_BINARY "rb" +#define WRITE_BINARY "wb" +#endif +#endif + +#ifndef EXIT_FAILURE /* define exit() codes if not provided */ +#define EXIT_FAILURE 1 +#endif +#ifndef EXIT_SUCCESS +#ifdef VMS +#define EXIT_SUCCESS 1 /* VMS is very nonstandard */ +#else +#define EXIT_SUCCESS 0 +#endif +#endif + +/* Reduce this value if your malloc() can't allocate blocks up to 64K. + * On DOS, compiling in large model is usually a better solution. + */ + +#ifndef MAX_COM_LENGTH +#define MAX_COM_LENGTH 65000L /* must be <= 65533 in any case */ +#endif + + +/* + * These macros are used to read the input file and write the output file. + * To reuse this code in another application, you might need to change these. + */ + +static FILE * infile; /* input JPEG file */ + +/* Return next input byte, or EOF if no more */ +#define NEXTBYTE() getc(infile) + +static FILE * outfile; /* output JPEG file */ + +/* Emit an output byte */ +#define PUTBYTE(x) putc((x), outfile) + + +/* Error exit handler */ +#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE)) + + +/* Read one byte, testing for EOF */ +static int +read_1_byte (void) +{ + int c; + + c = NEXTBYTE(); + if (c == EOF) + ERREXIT("Premature EOF in JPEG file"); + return c; +} + +/* Read 2 bytes, convert to unsigned int */ +/* All 2-byte quantities in JPEG markers are MSB first */ +static unsigned int +read_2_bytes (void) +{ + int c1, c2; + + c1 = NEXTBYTE(); + if (c1 == EOF) + ERREXIT("Premature EOF in JPEG file"); + c2 = NEXTBYTE(); + if (c2 == EOF) + ERREXIT("Premature EOF in JPEG file"); + return (((unsigned int) c1) << 8) + ((unsigned int) c2); +} + + +/* Routines to write data to output file */ + +static void +write_1_byte (int c) +{ + PUTBYTE(c); +} + +static void +write_2_bytes (unsigned int val) +{ + PUTBYTE((val >> 8) & 0xFF); + PUTBYTE(val & 0xFF); +} + +static void +write_marker (int marker) +{ + PUTBYTE(0xFF); + PUTBYTE(marker); +} + +static void +copy_rest_of_file (void) +{ + int c; + + while ((c = NEXTBYTE()) != EOF) + PUTBYTE(c); +} + + +/* + * JPEG markers consist of one or more 0xFF bytes, followed by a marker + * code byte (which is not an FF). Here are the marker codes of interest + * in this program. (See jdmarker.c for a more complete list.) + */ + +#define M_SOF0 0xC0 /* Start Of Frame N */ +#define M_SOF1 0xC1 /* N indicates which compression process */ +#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */ +#define M_SOF3 0xC3 +#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */ +#define M_SOF6 0xC6 +#define M_SOF7 0xC7 +#define M_SOF9 0xC9 +#define M_SOF10 0xCA +#define M_SOF11 0xCB +#define M_SOF13 0xCD +#define M_SOF14 0xCE +#define M_SOF15 0xCF +#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */ +#define M_EOI 0xD9 /* End Of Image (end of datastream) */ +#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ +#define M_COM 0xFE /* COMment */ + + +/* + * Find the next JPEG marker and return its marker code. + * We expect at least one FF byte, possibly more if the compressor used FFs + * to pad the file. (Padding FFs will NOT be replicated in the output file.) + * There could also be non-FF garbage between markers. The treatment of such + * garbage is unspecified; we choose to skip over it but emit a warning msg. + * NB: this routine must not be used after seeing SOS marker, since it will + * not deal correctly with FF/00 sequences in the compressed image data... + */ + +static int +next_marker (void) +{ + int c; + int discarded_bytes = 0; + + /* Find 0xFF byte; count and skip any non-FFs. */ + c = read_1_byte(); + while (c != 0xFF) { + discarded_bytes++; + c = read_1_byte(); + } + /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs + * are legal as pad bytes, so don't count them in discarded_bytes. + */ + do { + c = read_1_byte(); + } while (c == 0xFF); + + if (discarded_bytes != 0) { + fprintf(stderr, "Warning: garbage data found in JPEG file\n"); + } + + return c; +} + + +/* + * Read the initial marker, which should be SOI. + * For a JFIF file, the first two bytes of the file should be literally + * 0xFF M_SOI. To be more general, we could use next_marker, but if the + * input file weren't actually JPEG at all, next_marker might read the whole + * file and then return a misleading error message... + */ + +static int +first_marker (void) +{ + int c1, c2; + + c1 = NEXTBYTE(); + c2 = NEXTBYTE(); + if (c1 != 0xFF || c2 != M_SOI) + ERREXIT("Not a JPEG file"); + return c2; +} + + +/* + * Most types of marker are followed by a variable-length parameter segment. + * This routine skips over the parameters for any marker we don't otherwise + * want to process. + * Note that we MUST skip the parameter segment explicitly in order not to + * be fooled by 0xFF bytes that might appear within the parameter segment; + * such bytes do NOT introduce new markers. + */ + +static void +copy_variable (void) +/* Copy an unknown or uninteresting variable-length marker */ +{ + unsigned int length; + + /* Get the marker parameter length count */ + length = read_2_bytes(); + write_2_bytes(length); + /* Length includes itself, so must be at least 2 */ + if (length < 2) + ERREXIT("Erroneous JPEG marker length"); + length -= 2; + /* Skip over the remaining bytes */ + while (length > 0) { + write_1_byte(read_1_byte()); + length--; + } +} + +static void +skip_variable (void) +/* Skip over an unknown or uninteresting variable-length marker */ +{ + unsigned int length; + + /* Get the marker parameter length count */ + length = read_2_bytes(); + /* Length includes itself, so must be at least 2 */ + if (length < 2) + ERREXIT("Erroneous JPEG marker length"); + length -= 2; + /* Skip over the remaining bytes */ + while (length > 0) { + (void) read_1_byte(); + length--; + } +} + + +/* + * Parse the marker stream until SOFn or EOI is seen; + * copy data to output, but discard COM markers unless keep_COM is true. + */ + +static int +scan_JPEG_header (int keep_COM) +{ + int marker; + + /* Expect SOI at start of file */ + if (first_marker() != M_SOI) + ERREXIT("Expected SOI marker first"); + write_marker(M_SOI); + + /* Scan miscellaneous markers until we reach SOFn. */ + for (;;) { + marker = next_marker(); + switch (marker) { + /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be, + * treated as SOFn. C4 in particular is actually DHT. + */ + case M_SOF0: /* Baseline */ + case M_SOF1: /* Extended sequential, Huffman */ + case M_SOF2: /* Progressive, Huffman */ + case M_SOF3: /* Lossless, Huffman */ + case M_SOF5: /* Differential sequential, Huffman */ + case M_SOF6: /* Differential progressive, Huffman */ + case M_SOF7: /* Differential lossless, Huffman */ + case M_SOF9: /* Extended sequential, arithmetic */ + case M_SOF10: /* Progressive, arithmetic */ + case M_SOF11: /* Lossless, arithmetic */ + case M_SOF13: /* Differential sequential, arithmetic */ + case M_SOF14: /* Differential progressive, arithmetic */ + case M_SOF15: /* Differential lossless, arithmetic */ + return marker; + + case M_SOS: /* should not see compressed data before SOF */ + ERREXIT("SOS without prior SOFn"); + break; + + case M_EOI: /* in case it's a tables-only JPEG stream */ + return marker; + + case M_COM: /* Existing COM: conditionally discard */ + if (keep_COM) { + write_marker(marker); + copy_variable(); + } else { + skip_variable(); + } + break; + + default: /* Anything else just gets copied */ + write_marker(marker); + copy_variable(); /* we assume it has a parameter count... */ + break; + } + } /* end loop */ +} + + +/* Command line parsing code */ + +static const char * progname; /* program name for error messages */ + + +static void +usage (void) +/* complain about bad command line */ +{ + fprintf(stderr, "wrjpgcom inserts a textual comment in a JPEG file.\n"); + fprintf(stderr, "You can add to or replace any existing comment(s).\n"); + + fprintf(stderr, "Usage: %s [switches] ", progname); +#ifdef TWO_FILE_COMMANDLINE + fprintf(stderr, "inputfile outputfile\n"); +#else + fprintf(stderr, "[inputfile]\n"); +#endif + + fprintf(stderr, "Switches (names may be abbreviated):\n"); + fprintf(stderr, " -replace Delete any existing comments\n"); + fprintf(stderr, " -comment \"text\" Insert comment with given text\n"); + fprintf(stderr, " -cfile name Read comment from named file\n"); + fprintf(stderr, "Notice that you must put quotes around the comment text\n"); + fprintf(stderr, "when you use -comment.\n"); + fprintf(stderr, "If you do not give either -comment or -cfile on the command line,\n"); + fprintf(stderr, "then the comment text is read from standard input.\n"); + fprintf(stderr, "It can be multiple lines, up to %u characters total.\n", + (unsigned int) MAX_COM_LENGTH); +#ifndef TWO_FILE_COMMANDLINE + fprintf(stderr, "You must specify an input JPEG file name when supplying\n"); + fprintf(stderr, "comment text from standard input.\n"); +#endif + + exit(EXIT_FAILURE); +} + + +static int +keymatch (char * arg, const char * keyword, int minchars) +/* Case-insensitive matching of (possibly abbreviated) keyword switches. */ +/* keyword is the constant keyword (must be lower case already), */ +/* minchars is length of minimum legal abbreviation. */ +{ + register int ca, ck; + register int nmatched = 0; + + while ((ca = *arg++) != '\0') { + if ((ck = *keyword++) == '\0') + return 0; /* arg longer than keyword, no good */ + if (isupper(ca)) /* force arg to lcase (assume ck is already) */ + ca = tolower(ca); + if (ca != ck) + return 0; /* no good */ + nmatched++; /* count matched characters */ + } + /* reached end of argument; fail if it's too short for unique abbrev */ + if (nmatched < minchars) + return 0; + return 1; /* A-OK */ +} + + +/* + * The main program. + */ + +int +main (int argc, char **argv) +{ + int argn; + char * arg; + int keep_COM = 1; + char * comment_arg = NULL; + FILE * comment_file = NULL; + unsigned int comment_length = 0; + int marker; + + /* On Mac, fetch a command line. */ +#ifdef USE_CCOMMAND + argc = ccommand(&argv); +#endif + + progname = argv[0]; + if (progname == NULL || progname[0] == 0) + progname = "wrjpgcom"; /* in case C library doesn't provide it */ + + /* Parse switches, if any */ + for (argn = 1; argn < argc; argn++) { + arg = argv[argn]; + if (arg[0] != '-') + break; /* not switch, must be file name */ + arg++; /* advance over '-' */ + if (keymatch(arg, "replace", 1)) { + keep_COM = 0; + } else if (keymatch(arg, "cfile", 2)) { + if (++argn >= argc) usage(); + if ((comment_file = fopen(argv[argn], "r")) == NULL) { + fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); + exit(EXIT_FAILURE); + } + } else if (keymatch(arg, "comment", 1)) { + if (++argn >= argc) usage(); + comment_arg = argv[argn]; + /* If the comment text starts with '"', then we are probably running + * under MS-DOG and must parse out the quoted string ourselves. Sigh. + */ + if (comment_arg[0] == '"') { + comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH); + if (comment_arg == NULL) + ERREXIT("Insufficient memory"); + strcpy(comment_arg, argv[argn]+1); + for (;;) { + comment_length = (unsigned int) strlen(comment_arg); + if (comment_length > 0 && comment_arg[comment_length-1] == '"') { + comment_arg[comment_length-1] = '\0'; /* zap terminating quote */ + break; + } + if (++argn >= argc) + ERREXIT("Missing ending quote mark"); + strcat(comment_arg, " "); + strcat(comment_arg, argv[argn]); + } + } + comment_length = (unsigned int) strlen(comment_arg); + } else + usage(); + } + + /* Cannot use both -comment and -cfile. */ + if (comment_arg != NULL && comment_file != NULL) + usage(); + /* If there is neither -comment nor -cfile, we will read the comment text + * from stdin; in this case there MUST be an input JPEG file name. + */ + if (comment_arg == NULL && comment_file == NULL && argn >= argc) + usage(); + + /* Open the input file. */ + if (argn < argc) { + if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); + exit(EXIT_FAILURE); + } + } else { + /* default input file is stdin */ +#ifdef USE_SETMODE /* need to hack file mode? */ + setmode(fileno(stdin), O_BINARY); +#endif +#ifdef USE_FDOPEN /* need to re-open in binary mode? */ + if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open stdin\n", progname); + exit(EXIT_FAILURE); + } +#else + infile = stdin; +#endif + } + + /* Open the output file. */ +#ifdef TWO_FILE_COMMANDLINE + /* Must have explicit output file name */ + if (argn != argc-2) { + fprintf(stderr, "%s: must name one input and one output file\n", + progname); + usage(); + } + if ((outfile = fopen(argv[argn+1], WRITE_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open %s\n", progname, argv[argn+1]); + exit(EXIT_FAILURE); + } +#else + /* Unix style: expect zero or one file name */ + if (argn < argc-1) { + fprintf(stderr, "%s: only one input file\n", progname); + usage(); + } + /* default output file is stdout */ +#ifdef USE_SETMODE /* need to hack file mode? */ + setmode(fileno(stdout), O_BINARY); +#endif +#ifdef USE_FDOPEN /* need to re-open in binary mode? */ + if ((outfile = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open stdout\n", progname); + exit(EXIT_FAILURE); + } +#else + outfile = stdout; +#endif +#endif /* TWO_FILE_COMMANDLINE */ + + /* Collect comment text from comment_file or stdin, if necessary */ + if (comment_arg == NULL) { + FILE * src_file; + int c; + + comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH); + if (comment_arg == NULL) + ERREXIT("Insufficient memory"); + comment_length = 0; + src_file = (comment_file != NULL ? comment_file : stdin); + while ((c = getc(src_file)) != EOF) { + if (comment_length >= (unsigned int) MAX_COM_LENGTH) { + fprintf(stderr, "Comment text may not exceed %u bytes\n", + (unsigned int) MAX_COM_LENGTH); + exit(EXIT_FAILURE); + } + comment_arg[comment_length++] = (char) c; + } + if (comment_file != NULL) + fclose(comment_file); + } + + /* Copy JPEG headers until SOFn marker; + * we will insert the new comment marker just before SOFn. + * This (a) causes the new comment to appear after, rather than before, + * existing comments; and (b) ensures that comments come after any JFIF + * or JFXX markers, as required by the JFIF specification. + */ + marker = scan_JPEG_header(keep_COM); + /* Insert the new COM marker, but only if nonempty text has been supplied */ + if (comment_length > 0) { + write_marker(M_COM); + write_2_bytes(comment_length + 2); + while (comment_length > 0) { + write_1_byte(*comment_arg++); + comment_length--; + } + } + /* Duplicate the remainder of the source file. + * Note that any COM markers occuring after SOF will not be touched. + */ + write_marker(marker); + copy_rest_of_file(); + + /* All done. */ + exit(EXIT_SUCCESS); + return 0; /* suppress no-return-value warnings */ +} diff --git a/Source/LibJPEG/wrppm.c b/Source/LibJPEG/wrppm.c index 1e56d9c..68e0c85 100644 --- a/Source/LibJPEG/wrppm.c +++ b/Source/LibJPEG/wrppm.c @@ -1,269 +1,269 @@ -/* - * wrppm.c - * - * Copyright (C) 1991-1996, Thomas G. Lane. - * Modified 2009 by Guido Vollbeding. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains routines to write output images in PPM/PGM format. - * The extended 2-byte-per-sample raw PPM/PGM formats are supported. - * The PBMPLUS library is NOT required to compile this software - * (but it is highly useful as a set of PPM image manipulation programs). - * - * These routines may need modification for non-Unix environments or - * specialized applications. As they stand, they assume output to - * an ordinary stdio stream. - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ - -#ifdef PPM_SUPPORTED - - -/* - * For 12-bit JPEG data, we either downscale the values to 8 bits - * (to write standard byte-per-sample PPM/PGM files), or output - * nonstandard word-per-sample PPM/PGM files. Downscaling is done - * if PPM_NORAWWORD is defined (this can be done in the Makefile - * or in jconfig.h). - * (When the core library supports data precision reduction, a cleaner - * implementation will be to ask for that instead.) - */ - -#if BITS_IN_JSAMPLE == 8 -#define PUTPPMSAMPLE(ptr,v) *ptr++ = (char) (v) -#define BYTESPERSAMPLE 1 -#define PPM_MAXVAL 255 -#else -#ifdef PPM_NORAWWORD -#define PUTPPMSAMPLE(ptr,v) *ptr++ = (char) ((v) >> (BITS_IN_JSAMPLE-8)) -#define BYTESPERSAMPLE 1 -#define PPM_MAXVAL 255 -#else -/* The word-per-sample format always puts the MSB first. */ -#define PUTPPMSAMPLE(ptr,v) \ - { register int val_ = v; \ - *ptr++ = (char) ((val_ >> 8) & 0xFF); \ - *ptr++ = (char) (val_ & 0xFF); \ - } -#define BYTESPERSAMPLE 2 -#define PPM_MAXVAL ((1<pub.output_file, dest->iobuffer, dest->buffer_width); -} - - -/* - * This code is used when we have to copy the data and apply a pixel - * format translation. Typically this only happens in 12-bit mode. - */ - -METHODDEF(void) -copy_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, - JDIMENSION rows_supplied) -{ - ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; - register char * bufferptr; - register JSAMPROW ptr; - register JDIMENSION col; - - ptr = dest->pub.buffer[0]; - bufferptr = dest->iobuffer; - for (col = dest->samples_per_row; col > 0; col--) { - PUTPPMSAMPLE(bufferptr, GETJSAMPLE(*ptr++)); - } - (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); -} - - -/* - * Write some pixel data when color quantization is in effect. - * We have to demap the color index values to straight data. - */ - -METHODDEF(void) -put_demapped_rgb (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, - JDIMENSION rows_supplied) -{ - ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; - register char * bufferptr; - register int pixval; - register JSAMPROW ptr; - register JSAMPROW color_map0 = cinfo->colormap[0]; - register JSAMPROW color_map1 = cinfo->colormap[1]; - register JSAMPROW color_map2 = cinfo->colormap[2]; - register JDIMENSION col; - - ptr = dest->pub.buffer[0]; - bufferptr = dest->iobuffer; - for (col = cinfo->output_width; col > 0; col--) { - pixval = GETJSAMPLE(*ptr++); - PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map0[pixval])); - PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map1[pixval])); - PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map2[pixval])); - } - (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); -} - - -METHODDEF(void) -put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, - JDIMENSION rows_supplied) -{ - ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; - register char * bufferptr; - register JSAMPROW ptr; - register JSAMPROW color_map = cinfo->colormap[0]; - register JDIMENSION col; - - ptr = dest->pub.buffer[0]; - bufferptr = dest->iobuffer; - for (col = cinfo->output_width; col > 0; col--) { - PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map[GETJSAMPLE(*ptr++)])); - } - (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); -} - - -/* - * Startup: write the file header. - */ - -METHODDEF(void) -start_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) -{ - ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; - - /* Emit file header */ - switch (cinfo->out_color_space) { - case JCS_GRAYSCALE: - /* emit header for raw PGM format */ - fprintf(dest->pub.output_file, "P5\n%ld %ld\n%d\n", - (long) cinfo->output_width, (long) cinfo->output_height, - PPM_MAXVAL); - break; - case JCS_RGB: - /* emit header for raw PPM format */ - fprintf(dest->pub.output_file, "P6\n%ld %ld\n%d\n", - (long) cinfo->output_width, (long) cinfo->output_height, - PPM_MAXVAL); - break; - default: - ERREXIT(cinfo, JERR_PPM_COLORSPACE); - } -} - - -/* - * Finish up at the end of the file. - */ - -METHODDEF(void) -finish_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) -{ - /* Make sure we wrote the output file OK */ - fflush(dinfo->output_file); - if (ferror(dinfo->output_file)) - ERREXIT(cinfo, JERR_FILE_WRITE); -} - - -/* - * The module selection routine for PPM format output. - */ - -GLOBAL(djpeg_dest_ptr) -jinit_write_ppm (j_decompress_ptr cinfo) -{ - ppm_dest_ptr dest; - - /* Create module interface object, fill in method pointers */ - dest = (ppm_dest_ptr) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - SIZEOF(ppm_dest_struct)); - dest->pub.start_output = start_output_ppm; - dest->pub.finish_output = finish_output_ppm; - - /* Calculate output image dimensions so we can allocate space */ - jpeg_calc_output_dimensions(cinfo); - - /* Create physical I/O buffer. Note we make this near on a PC. */ - dest->samples_per_row = cinfo->output_width * cinfo->out_color_components; - dest->buffer_width = dest->samples_per_row * (BYTESPERSAMPLE * SIZEOF(char)); - dest->iobuffer = (char *) (*cinfo->mem->alloc_small) - ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width); - - if (cinfo->quantize_colors || BITS_IN_JSAMPLE != 8 || - SIZEOF(JSAMPLE) != SIZEOF(char)) { - /* When quantizing, we need an output buffer for colormap indexes - * that's separate from the physical I/O buffer. We also need a - * separate buffer if pixel format translation must take place. - */ - dest->pub.buffer = (*cinfo->mem->alloc_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, - cinfo->output_width * cinfo->output_components, (JDIMENSION) 1); - dest->pub.buffer_height = 1; - if (! cinfo->quantize_colors) - dest->pub.put_pixel_rows = copy_pixel_rows; - else if (cinfo->out_color_space == JCS_GRAYSCALE) - dest->pub.put_pixel_rows = put_demapped_gray; - else - dest->pub.put_pixel_rows = put_demapped_rgb; - } else { - /* We will fwrite() directly from decompressor output buffer. */ - /* Synthesize a JSAMPARRAY pointer structure */ - /* Cast here implies near->far pointer conversion on PCs */ - dest->pixrow = (JSAMPROW) dest->iobuffer; - dest->pub.buffer = & dest->pixrow; - dest->pub.buffer_height = 1; - dest->pub.put_pixel_rows = put_pixel_rows; - } - - return (djpeg_dest_ptr) dest; -} - -#endif /* PPM_SUPPORTED */ +/* + * wrppm.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * Modified 2009 by Guido Vollbeding. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to write output images in PPM/PGM format. + * The extended 2-byte-per-sample raw PPM/PGM formats are supported. + * The PBMPLUS library is NOT required to compile this software + * (but it is highly useful as a set of PPM image manipulation programs). + * + * These routines may need modification for non-Unix environments or + * specialized applications. As they stand, they assume output to + * an ordinary stdio stream. + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + +#ifdef PPM_SUPPORTED + + +/* + * For 12-bit JPEG data, we either downscale the values to 8 bits + * (to write standard byte-per-sample PPM/PGM files), or output + * nonstandard word-per-sample PPM/PGM files. Downscaling is done + * if PPM_NORAWWORD is defined (this can be done in the Makefile + * or in jconfig.h). + * (When the core library supports data precision reduction, a cleaner + * implementation will be to ask for that instead.) + */ + +#if BITS_IN_JSAMPLE == 8 +#define PUTPPMSAMPLE(ptr,v) *ptr++ = (char) (v) +#define BYTESPERSAMPLE 1 +#define PPM_MAXVAL 255 +#else +#ifdef PPM_NORAWWORD +#define PUTPPMSAMPLE(ptr,v) *ptr++ = (char) ((v) >> (BITS_IN_JSAMPLE-8)) +#define BYTESPERSAMPLE 1 +#define PPM_MAXVAL 255 +#else +/* The word-per-sample format always puts the MSB first. */ +#define PUTPPMSAMPLE(ptr,v) \ + { register int val_ = v; \ + *ptr++ = (char) ((val_ >> 8) & 0xFF); \ + *ptr++ = (char) (val_ & 0xFF); \ + } +#define BYTESPERSAMPLE 2 +#define PPM_MAXVAL ((1<pub.output_file, dest->iobuffer, dest->buffer_width); +} + + +/* + * This code is used when we have to copy the data and apply a pixel + * format translation. Typically this only happens in 12-bit mode. + */ + +METHODDEF(void) +copy_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) +{ + ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; + register char * bufferptr; + register JSAMPROW ptr; + register JDIMENSION col; + + ptr = dest->pub.buffer[0]; + bufferptr = dest->iobuffer; + for (col = dest->samples_per_row; col > 0; col--) { + PUTPPMSAMPLE(bufferptr, GETJSAMPLE(*ptr++)); + } + (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); +} + + +/* + * Write some pixel data when color quantization is in effect. + * We have to demap the color index values to straight data. + */ + +METHODDEF(void) +put_demapped_rgb (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) +{ + ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; + register char * bufferptr; + register int pixval; + register JSAMPROW ptr; + register JSAMPROW color_map0 = cinfo->colormap[0]; + register JSAMPROW color_map1 = cinfo->colormap[1]; + register JSAMPROW color_map2 = cinfo->colormap[2]; + register JDIMENSION col; + + ptr = dest->pub.buffer[0]; + bufferptr = dest->iobuffer; + for (col = cinfo->output_width; col > 0; col--) { + pixval = GETJSAMPLE(*ptr++); + PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map0[pixval])); + PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map1[pixval])); + PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map2[pixval])); + } + (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); +} + + +METHODDEF(void) +put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) +{ + ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; + register char * bufferptr; + register JSAMPROW ptr; + register JSAMPROW color_map = cinfo->colormap[0]; + register JDIMENSION col; + + ptr = dest->pub.buffer[0]; + bufferptr = dest->iobuffer; + for (col = cinfo->output_width; col > 0; col--) { + PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map[GETJSAMPLE(*ptr++)])); + } + (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); +} + + +/* + * Startup: write the file header. + */ + +METHODDEF(void) +start_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) +{ + ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; + + /* Emit file header */ + switch (cinfo->out_color_space) { + case JCS_GRAYSCALE: + /* emit header for raw PGM format */ + fprintf(dest->pub.output_file, "P5\n%ld %ld\n%d\n", + (long) cinfo->output_width, (long) cinfo->output_height, + PPM_MAXVAL); + break; + case JCS_RGB: + /* emit header for raw PPM format */ + fprintf(dest->pub.output_file, "P6\n%ld %ld\n%d\n", + (long) cinfo->output_width, (long) cinfo->output_height, + PPM_MAXVAL); + break; + default: + ERREXIT(cinfo, JERR_PPM_COLORSPACE); + } +} + + +/* + * Finish up at the end of the file. + */ + +METHODDEF(void) +finish_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) +{ + /* Make sure we wrote the output file OK */ + fflush(dinfo->output_file); + if (ferror(dinfo->output_file)) + ERREXIT(cinfo, JERR_FILE_WRITE); +} + + +/* + * The module selection routine for PPM format output. + */ + +GLOBAL(djpeg_dest_ptr) +jinit_write_ppm (j_decompress_ptr cinfo) +{ + ppm_dest_ptr dest; + + /* Create module interface object, fill in method pointers */ + dest = (ppm_dest_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(ppm_dest_struct)); + dest->pub.start_output = start_output_ppm; + dest->pub.finish_output = finish_output_ppm; + + /* Calculate output image dimensions so we can allocate space */ + jpeg_calc_output_dimensions(cinfo); + + /* Create physical I/O buffer. Note we make this near on a PC. */ + dest->samples_per_row = cinfo->output_width * cinfo->out_color_components; + dest->buffer_width = dest->samples_per_row * (BYTESPERSAMPLE * SIZEOF(char)); + dest->iobuffer = (char *) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width); + + if (cinfo->quantize_colors || BITS_IN_JSAMPLE != 8 || + SIZEOF(JSAMPLE) != SIZEOF(char)) { + /* When quantizing, we need an output buffer for colormap indexes + * that's separate from the physical I/O buffer. We also need a + * separate buffer if pixel format translation must take place. + */ + dest->pub.buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->output_width * cinfo->output_components, (JDIMENSION) 1); + dest->pub.buffer_height = 1; + if (! cinfo->quantize_colors) + dest->pub.put_pixel_rows = copy_pixel_rows; + else if (cinfo->out_color_space == JCS_GRAYSCALE) + dest->pub.put_pixel_rows = put_demapped_gray; + else + dest->pub.put_pixel_rows = put_demapped_rgb; + } else { + /* We will fwrite() directly from decompressor output buffer. */ + /* Synthesize a JSAMPARRAY pointer structure */ + /* Cast here implies near->far pointer conversion on PCs */ + dest->pixrow = (JSAMPROW) dest->iobuffer; + dest->pub.buffer = & dest->pixrow; + dest->pub.buffer_height = 1; + dest->pub.put_pixel_rows = put_pixel_rows; + } + + return (djpeg_dest_ptr) dest; +} + +#endif /* PPM_SUPPORTED */ diff --git a/Source/LibJPEG/wrrle.c b/Source/LibJPEG/wrrle.c index 7a00c0d..a4e7337 100644 --- a/Source/LibJPEG/wrrle.c +++ b/Source/LibJPEG/wrrle.c @@ -1,305 +1,305 @@ -/* - * wrrle.c - * - * Copyright (C) 1991-1996, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains routines to write output images in RLE format. - * The Utah Raster Toolkit library is required (version 3.1 or later). - * - * These routines may need modification for non-Unix environments or - * specialized applications. As they stand, they assume output to - * an ordinary stdio stream. - * - * Based on code contributed by Mike Lijewski, - * with updates from Robert Hutchinson. - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ - -#ifdef RLE_SUPPORTED - -/* rle.h is provided by the Utah Raster Toolkit. */ - -#include - -/* - * We assume that JSAMPLE has the same representation as rle_pixel, - * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples. - */ - -#if BITS_IN_JSAMPLE != 8 - Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ -#endif - - -/* - * Since RLE stores scanlines bottom-to-top, we have to invert the image - * from JPEG's top-to-bottom order. To do this, we save the outgoing data - * in a virtual array during put_pixel_row calls, then actually emit the - * RLE file during finish_output. - */ - - -/* - * For now, if we emit an RLE color map then it is always 256 entries long, - * though not all of the entries need be used. - */ - -#define CMAPBITS 8 -#define CMAPLENGTH (1<<(CMAPBITS)) - -typedef struct { - struct djpeg_dest_struct pub; /* public fields */ - - jvirt_sarray_ptr image; /* virtual array to store the output image */ - rle_map *colormap; /* RLE-style color map, or NULL if none */ - rle_pixel **rle_row; /* To pass rows to rle_putrow() */ - -} rle_dest_struct; - -typedef rle_dest_struct * rle_dest_ptr; - -/* Forward declarations */ -METHODDEF(void) rle_put_pixel_rows - JPP((j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, - JDIMENSION rows_supplied)); - - -/* - * Write the file header. - * - * In this module it's easier to wait till finish_output to write anything. - */ - -METHODDEF(void) -start_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) -{ - rle_dest_ptr dest = (rle_dest_ptr) dinfo; - size_t cmapsize; - int i, ci; -#ifdef PROGRESS_REPORT - cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; -#endif - - /* - * Make sure the image can be stored in RLE format. - * - * - RLE stores image dimensions as *signed* 16 bit integers. JPEG - * uses unsigned, so we have to check the width. - * - * - Colorspace is expected to be grayscale or RGB. - * - * - The number of channels (components) is expected to be 1 (grayscale/ - * pseudocolor) or 3 (truecolor/directcolor). - * (could be 2 or 4 if using an alpha channel, but we aren't) - */ - - if (cinfo->output_width > 32767 || cinfo->output_height > 32767) - ERREXIT2(cinfo, JERR_RLE_DIMENSIONS, cinfo->output_width, - cinfo->output_height); - - if (cinfo->out_color_space != JCS_GRAYSCALE && - cinfo->out_color_space != JCS_RGB) - ERREXIT(cinfo, JERR_RLE_COLORSPACE); - - if (cinfo->output_components != 1 && cinfo->output_components != 3) - ERREXIT1(cinfo, JERR_RLE_TOOMANYCHANNELS, cinfo->num_components); - - /* Convert colormap, if any, to RLE format. */ - - dest->colormap = NULL; - - if (cinfo->quantize_colors) { - /* Allocate storage for RLE-style cmap, zero any extra entries */ - cmapsize = cinfo->out_color_components * CMAPLENGTH * SIZEOF(rle_map); - dest->colormap = (rle_map *) (*cinfo->mem->alloc_small) - ((j_common_ptr) cinfo, JPOOL_IMAGE, cmapsize); - MEMZERO(dest->colormap, cmapsize); - - /* Save away data in RLE format --- note 8-bit left shift! */ - /* Shifting would need adjustment for JSAMPLEs wider than 8 bits. */ - for (ci = 0; ci < cinfo->out_color_components; ci++) { - for (i = 0; i < cinfo->actual_number_of_colors; i++) { - dest->colormap[ci * CMAPLENGTH + i] = - GETJSAMPLE(cinfo->colormap[ci][i]) << 8; - } - } - } - - /* Set the output buffer to the first row */ - dest->pub.buffer = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, dest->image, (JDIMENSION) 0, (JDIMENSION) 1, TRUE); - dest->pub.buffer_height = 1; - - dest->pub.put_pixel_rows = rle_put_pixel_rows; - -#ifdef PROGRESS_REPORT - if (progress != NULL) { - progress->total_extra_passes++; /* count file writing as separate pass */ - } -#endif -} - - -/* - * Write some pixel data. - * - * This routine just saves the data away in a virtual array. - */ - -METHODDEF(void) -rle_put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, - JDIMENSION rows_supplied) -{ - rle_dest_ptr dest = (rle_dest_ptr) dinfo; - - if (cinfo->output_scanline < cinfo->output_height) { - dest->pub.buffer = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, dest->image, - cinfo->output_scanline, (JDIMENSION) 1, TRUE); - } -} - -/* - * Finish up at the end of the file. - * - * Here is where we really output the RLE file. - */ - -METHODDEF(void) -finish_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) -{ - rle_dest_ptr dest = (rle_dest_ptr) dinfo; - rle_hdr header; /* Output file information */ - rle_pixel **rle_row, *red, *green, *blue; - JSAMPROW output_row; - char cmapcomment[80]; - int row, col; - int ci; -#ifdef PROGRESS_REPORT - cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; -#endif - - /* Initialize the header info */ - header = *rle_hdr_init(NULL); - header.rle_file = dest->pub.output_file; - header.xmin = 0; - header.xmax = cinfo->output_width - 1; - header.ymin = 0; - header.ymax = cinfo->output_height - 1; - header.alpha = 0; - header.ncolors = cinfo->output_components; - for (ci = 0; ci < cinfo->output_components; ci++) { - RLE_SET_BIT(header, ci); - } - if (cinfo->quantize_colors) { - header.ncmap = cinfo->out_color_components; - header.cmaplen = CMAPBITS; - header.cmap = dest->colormap; - /* Add a comment to the output image with the true colormap length. */ - sprintf(cmapcomment, "color_map_length=%d", cinfo->actual_number_of_colors); - rle_putcom(cmapcomment, &header); - } - - /* Emit the RLE header and color map (if any) */ - rle_put_setup(&header); - - /* Now output the RLE data from our virtual array. - * We assume here that (a) rle_pixel is represented the same as JSAMPLE, - * and (b) we are not on a machine where FAR pointers differ from regular. - */ - -#ifdef PROGRESS_REPORT - if (progress != NULL) { - progress->pub.pass_limit = cinfo->output_height; - progress->pub.pass_counter = 0; - (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); - } -#endif - - if (cinfo->output_components == 1) { - for (row = cinfo->output_height-1; row >= 0; row--) { - rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, dest->image, - (JDIMENSION) row, (JDIMENSION) 1, FALSE); - rle_putrow(rle_row, (int) cinfo->output_width, &header); -#ifdef PROGRESS_REPORT - if (progress != NULL) { - progress->pub.pass_counter++; - (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); - } -#endif - } - } else { - for (row = cinfo->output_height-1; row >= 0; row--) { - rle_row = (rle_pixel **) dest->rle_row; - output_row = * (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, dest->image, - (JDIMENSION) row, (JDIMENSION) 1, FALSE); - red = rle_row[0]; - green = rle_row[1]; - blue = rle_row[2]; - for (col = cinfo->output_width; col > 0; col--) { - *red++ = GETJSAMPLE(*output_row++); - *green++ = GETJSAMPLE(*output_row++); - *blue++ = GETJSAMPLE(*output_row++); - } - rle_putrow(rle_row, (int) cinfo->output_width, &header); -#ifdef PROGRESS_REPORT - if (progress != NULL) { - progress->pub.pass_counter++; - (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); - } -#endif - } - } - -#ifdef PROGRESS_REPORT - if (progress != NULL) - progress->completed_extra_passes++; -#endif - - /* Emit file trailer */ - rle_puteof(&header); - fflush(dest->pub.output_file); - if (ferror(dest->pub.output_file)) - ERREXIT(cinfo, JERR_FILE_WRITE); -} - - -/* - * The module selection routine for RLE format output. - */ - -GLOBAL(djpeg_dest_ptr) -jinit_write_rle (j_decompress_ptr cinfo) -{ - rle_dest_ptr dest; - - /* Create module interface object, fill in method pointers */ - dest = (rle_dest_ptr) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - SIZEOF(rle_dest_struct)); - dest->pub.start_output = start_output_rle; - dest->pub.finish_output = finish_output_rle; - - /* Calculate output image dimensions so we can allocate space */ - jpeg_calc_output_dimensions(cinfo); - - /* Allocate a work array for output to the RLE library. */ - dest->rle_row = (*cinfo->mem->alloc_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, - cinfo->output_width, (JDIMENSION) cinfo->output_components); - - /* Allocate a virtual array to hold the image. */ - dest->image = (*cinfo->mem->request_virt_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, - (JDIMENSION) (cinfo->output_width * cinfo->output_components), - cinfo->output_height, (JDIMENSION) 1); - - return (djpeg_dest_ptr) dest; -} - -#endif /* RLE_SUPPORTED */ +/* + * wrrle.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to write output images in RLE format. + * The Utah Raster Toolkit library is required (version 3.1 or later). + * + * These routines may need modification for non-Unix environments or + * specialized applications. As they stand, they assume output to + * an ordinary stdio stream. + * + * Based on code contributed by Mike Lijewski, + * with updates from Robert Hutchinson. + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + +#ifdef RLE_SUPPORTED + +/* rle.h is provided by the Utah Raster Toolkit. */ + +#include + +/* + * We assume that JSAMPLE has the same representation as rle_pixel, + * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples. + */ + +#if BITS_IN_JSAMPLE != 8 + Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ +#endif + + +/* + * Since RLE stores scanlines bottom-to-top, we have to invert the image + * from JPEG's top-to-bottom order. To do this, we save the outgoing data + * in a virtual array during put_pixel_row calls, then actually emit the + * RLE file during finish_output. + */ + + +/* + * For now, if we emit an RLE color map then it is always 256 entries long, + * though not all of the entries need be used. + */ + +#define CMAPBITS 8 +#define CMAPLENGTH (1<<(CMAPBITS)) + +typedef struct { + struct djpeg_dest_struct pub; /* public fields */ + + jvirt_sarray_ptr image; /* virtual array to store the output image */ + rle_map *colormap; /* RLE-style color map, or NULL if none */ + rle_pixel **rle_row; /* To pass rows to rle_putrow() */ + +} rle_dest_struct; + +typedef rle_dest_struct * rle_dest_ptr; + +/* Forward declarations */ +METHODDEF(void) rle_put_pixel_rows + JPP((j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied)); + + +/* + * Write the file header. + * + * In this module it's easier to wait till finish_output to write anything. + */ + +METHODDEF(void) +start_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) +{ + rle_dest_ptr dest = (rle_dest_ptr) dinfo; + size_t cmapsize; + int i, ci; +#ifdef PROGRESS_REPORT + cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; +#endif + + /* + * Make sure the image can be stored in RLE format. + * + * - RLE stores image dimensions as *signed* 16 bit integers. JPEG + * uses unsigned, so we have to check the width. + * + * - Colorspace is expected to be grayscale or RGB. + * + * - The number of channels (components) is expected to be 1 (grayscale/ + * pseudocolor) or 3 (truecolor/directcolor). + * (could be 2 or 4 if using an alpha channel, but we aren't) + */ + + if (cinfo->output_width > 32767 || cinfo->output_height > 32767) + ERREXIT2(cinfo, JERR_RLE_DIMENSIONS, cinfo->output_width, + cinfo->output_height); + + if (cinfo->out_color_space != JCS_GRAYSCALE && + cinfo->out_color_space != JCS_RGB) + ERREXIT(cinfo, JERR_RLE_COLORSPACE); + + if (cinfo->output_components != 1 && cinfo->output_components != 3) + ERREXIT1(cinfo, JERR_RLE_TOOMANYCHANNELS, cinfo->num_components); + + /* Convert colormap, if any, to RLE format. */ + + dest->colormap = NULL; + + if (cinfo->quantize_colors) { + /* Allocate storage for RLE-style cmap, zero any extra entries */ + cmapsize = cinfo->out_color_components * CMAPLENGTH * SIZEOF(rle_map); + dest->colormap = (rle_map *) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, cmapsize); + MEMZERO(dest->colormap, cmapsize); + + /* Save away data in RLE format --- note 8-bit left shift! */ + /* Shifting would need adjustment for JSAMPLEs wider than 8 bits. */ + for (ci = 0; ci < cinfo->out_color_components; ci++) { + for (i = 0; i < cinfo->actual_number_of_colors; i++) { + dest->colormap[ci * CMAPLENGTH + i] = + GETJSAMPLE(cinfo->colormap[ci][i]) << 8; + } + } + } + + /* Set the output buffer to the first row */ + dest->pub.buffer = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, dest->image, (JDIMENSION) 0, (JDIMENSION) 1, TRUE); + dest->pub.buffer_height = 1; + + dest->pub.put_pixel_rows = rle_put_pixel_rows; + +#ifdef PROGRESS_REPORT + if (progress != NULL) { + progress->total_extra_passes++; /* count file writing as separate pass */ + } +#endif +} + + +/* + * Write some pixel data. + * + * This routine just saves the data away in a virtual array. + */ + +METHODDEF(void) +rle_put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) +{ + rle_dest_ptr dest = (rle_dest_ptr) dinfo; + + if (cinfo->output_scanline < cinfo->output_height) { + dest->pub.buffer = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, dest->image, + cinfo->output_scanline, (JDIMENSION) 1, TRUE); + } +} + +/* + * Finish up at the end of the file. + * + * Here is where we really output the RLE file. + */ + +METHODDEF(void) +finish_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) +{ + rle_dest_ptr dest = (rle_dest_ptr) dinfo; + rle_hdr header; /* Output file information */ + rle_pixel **rle_row, *red, *green, *blue; + JSAMPROW output_row; + char cmapcomment[80]; + int row, col; + int ci; +#ifdef PROGRESS_REPORT + cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; +#endif + + /* Initialize the header info */ + header = *rle_hdr_init(NULL); + header.rle_file = dest->pub.output_file; + header.xmin = 0; + header.xmax = cinfo->output_width - 1; + header.ymin = 0; + header.ymax = cinfo->output_height - 1; + header.alpha = 0; + header.ncolors = cinfo->output_components; + for (ci = 0; ci < cinfo->output_components; ci++) { + RLE_SET_BIT(header, ci); + } + if (cinfo->quantize_colors) { + header.ncmap = cinfo->out_color_components; + header.cmaplen = CMAPBITS; + header.cmap = dest->colormap; + /* Add a comment to the output image with the true colormap length. */ + sprintf(cmapcomment, "color_map_length=%d", cinfo->actual_number_of_colors); + rle_putcom(cmapcomment, &header); + } + + /* Emit the RLE header and color map (if any) */ + rle_put_setup(&header); + + /* Now output the RLE data from our virtual array. + * We assume here that (a) rle_pixel is represented the same as JSAMPLE, + * and (b) we are not on a machine where FAR pointers differ from regular. + */ + +#ifdef PROGRESS_REPORT + if (progress != NULL) { + progress->pub.pass_limit = cinfo->output_height; + progress->pub.pass_counter = 0; + (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); + } +#endif + + if (cinfo->output_components == 1) { + for (row = cinfo->output_height-1; row >= 0; row--) { + rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, dest->image, + (JDIMENSION) row, (JDIMENSION) 1, FALSE); + rle_putrow(rle_row, (int) cinfo->output_width, &header); +#ifdef PROGRESS_REPORT + if (progress != NULL) { + progress->pub.pass_counter++; + (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); + } +#endif + } + } else { + for (row = cinfo->output_height-1; row >= 0; row--) { + rle_row = (rle_pixel **) dest->rle_row; + output_row = * (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, dest->image, + (JDIMENSION) row, (JDIMENSION) 1, FALSE); + red = rle_row[0]; + green = rle_row[1]; + blue = rle_row[2]; + for (col = cinfo->output_width; col > 0; col--) { + *red++ = GETJSAMPLE(*output_row++); + *green++ = GETJSAMPLE(*output_row++); + *blue++ = GETJSAMPLE(*output_row++); + } + rle_putrow(rle_row, (int) cinfo->output_width, &header); +#ifdef PROGRESS_REPORT + if (progress != NULL) { + progress->pub.pass_counter++; + (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); + } +#endif + } + } + +#ifdef PROGRESS_REPORT + if (progress != NULL) + progress->completed_extra_passes++; +#endif + + /* Emit file trailer */ + rle_puteof(&header); + fflush(dest->pub.output_file); + if (ferror(dest->pub.output_file)) + ERREXIT(cinfo, JERR_FILE_WRITE); +} + + +/* + * The module selection routine for RLE format output. + */ + +GLOBAL(djpeg_dest_ptr) +jinit_write_rle (j_decompress_ptr cinfo) +{ + rle_dest_ptr dest; + + /* Create module interface object, fill in method pointers */ + dest = (rle_dest_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(rle_dest_struct)); + dest->pub.start_output = start_output_rle; + dest->pub.finish_output = finish_output_rle; + + /* Calculate output image dimensions so we can allocate space */ + jpeg_calc_output_dimensions(cinfo); + + /* Allocate a work array for output to the RLE library. */ + dest->rle_row = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->output_width, (JDIMENSION) cinfo->output_components); + + /* Allocate a virtual array to hold the image. */ + dest->image = (*cinfo->mem->request_virt_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, + (JDIMENSION) (cinfo->output_width * cinfo->output_components), + cinfo->output_height, (JDIMENSION) 1); + + return (djpeg_dest_ptr) dest; +} + +#endif /* RLE_SUPPORTED */ diff --git a/Source/LibJPEG/wrtarga.c b/Source/LibJPEG/wrtarga.c index 6566273..cf104d2 100644 --- a/Source/LibJPEG/wrtarga.c +++ b/Source/LibJPEG/wrtarga.c @@ -1,253 +1,253 @@ -/* - * wrtarga.c - * - * Copyright (C) 1991-1996, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains routines to write output images in Targa format. - * - * These routines may need modification for non-Unix environments or - * specialized applications. As they stand, they assume output to - * an ordinary stdio stream. - * - * Based on code contributed by Lee Daniel Crocker. - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ - -#ifdef TARGA_SUPPORTED - - -/* - * To support 12-bit JPEG data, we'd have to scale output down to 8 bits. - * This is not yet implemented. - */ - -#if BITS_IN_JSAMPLE != 8 - Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ -#endif - -/* - * The output buffer needs to be writable by fwrite(). On PCs, we must - * allocate the buffer in near data space, because we are assuming small-data - * memory model, wherein fwrite() can't reach far memory. If you need to - * process very wide images on a PC, you might have to compile in large-memory - * model, or else replace fwrite() with a putc() loop --- which will be much - * slower. - */ - - -/* Private version of data destination object */ - -typedef struct { - struct djpeg_dest_struct pub; /* public fields */ - - char *iobuffer; /* physical I/O buffer */ - JDIMENSION buffer_width; /* width of one row */ -} tga_dest_struct; - -typedef tga_dest_struct * tga_dest_ptr; - - -LOCAL(void) -write_header (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, int num_colors) -/* Create and write a Targa header */ -{ - char targaheader[18]; - - /* Set unused fields of header to 0 */ - MEMZERO(targaheader, SIZEOF(targaheader)); - - if (num_colors > 0) { - targaheader[1] = 1; /* color map type 1 */ - targaheader[5] = (char) (num_colors & 0xFF); - targaheader[6] = (char) (num_colors >> 8); - targaheader[7] = 24; /* 24 bits per cmap entry */ - } - - targaheader[12] = (char) (cinfo->output_width & 0xFF); - targaheader[13] = (char) (cinfo->output_width >> 8); - targaheader[14] = (char) (cinfo->output_height & 0xFF); - targaheader[15] = (char) (cinfo->output_height >> 8); - targaheader[17] = 0x20; /* Top-down, non-interlaced */ - - if (cinfo->out_color_space == JCS_GRAYSCALE) { - targaheader[2] = 3; /* image type = uncompressed gray-scale */ - targaheader[16] = 8; /* bits per pixel */ - } else { /* must be RGB */ - if (num_colors > 0) { - targaheader[2] = 1; /* image type = colormapped RGB */ - targaheader[16] = 8; - } else { - targaheader[2] = 2; /* image type = uncompressed RGB */ - targaheader[16] = 24; - } - } - - if (JFWRITE(dinfo->output_file, targaheader, 18) != (size_t) 18) - ERREXIT(cinfo, JERR_FILE_WRITE); -} - - -/* - * Write some pixel data. - * In this module rows_supplied will always be 1. - */ - -METHODDEF(void) -put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, - JDIMENSION rows_supplied) -/* used for unquantized full-color output */ -{ - tga_dest_ptr dest = (tga_dest_ptr) dinfo; - register JSAMPROW inptr; - register char * outptr; - register JDIMENSION col; - - inptr = dest->pub.buffer[0]; - outptr = dest->iobuffer; - for (col = cinfo->output_width; col > 0; col--) { - outptr[0] = (char) GETJSAMPLE(inptr[2]); /* RGB to BGR order */ - outptr[1] = (char) GETJSAMPLE(inptr[1]); - outptr[2] = (char) GETJSAMPLE(inptr[0]); - inptr += 3, outptr += 3; - } - (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); -} - -METHODDEF(void) -put_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, - JDIMENSION rows_supplied) -/* used for grayscale OR quantized color output */ -{ - tga_dest_ptr dest = (tga_dest_ptr) dinfo; - register JSAMPROW inptr; - register char * outptr; - register JDIMENSION col; - - inptr = dest->pub.buffer[0]; - outptr = dest->iobuffer; - for (col = cinfo->output_width; col > 0; col--) { - *outptr++ = (char) GETJSAMPLE(*inptr++); - } - (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); -} - - -/* - * Write some demapped pixel data when color quantization is in effect. - * For Targa, this is only applied to grayscale data. - */ - -METHODDEF(void) -put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, - JDIMENSION rows_supplied) -{ - tga_dest_ptr dest = (tga_dest_ptr) dinfo; - register JSAMPROW inptr; - register char * outptr; - register JSAMPROW color_map0 = cinfo->colormap[0]; - register JDIMENSION col; - - inptr = dest->pub.buffer[0]; - outptr = dest->iobuffer; - for (col = cinfo->output_width; col > 0; col--) { - *outptr++ = (char) GETJSAMPLE(color_map0[GETJSAMPLE(*inptr++)]); - } - (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); -} - - -/* - * Startup: write the file header. - */ - -METHODDEF(void) -start_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) -{ - tga_dest_ptr dest = (tga_dest_ptr) dinfo; - int num_colors, i; - FILE *outfile; - - if (cinfo->out_color_space == JCS_GRAYSCALE) { - /* Targa doesn't have a mapped grayscale format, so we will */ - /* demap quantized gray output. Never emit a colormap. */ - write_header(cinfo, dinfo, 0); - if (cinfo->quantize_colors) - dest->pub.put_pixel_rows = put_demapped_gray; - else - dest->pub.put_pixel_rows = put_gray_rows; - } else if (cinfo->out_color_space == JCS_RGB) { - if (cinfo->quantize_colors) { - /* We only support 8-bit colormap indexes, so only 256 colors */ - num_colors = cinfo->actual_number_of_colors; - if (num_colors > 256) - ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, num_colors); - write_header(cinfo, dinfo, num_colors); - /* Write the colormap. Note Targa uses BGR byte order */ - outfile = dest->pub.output_file; - for (i = 0; i < num_colors; i++) { - putc(GETJSAMPLE(cinfo->colormap[2][i]), outfile); - putc(GETJSAMPLE(cinfo->colormap[1][i]), outfile); - putc(GETJSAMPLE(cinfo->colormap[0][i]), outfile); - } - dest->pub.put_pixel_rows = put_gray_rows; - } else { - write_header(cinfo, dinfo, 0); - dest->pub.put_pixel_rows = put_pixel_rows; - } - } else { - ERREXIT(cinfo, JERR_TGA_COLORSPACE); - } -} - - -/* - * Finish up at the end of the file. - */ - -METHODDEF(void) -finish_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) -{ - /* Make sure we wrote the output file OK */ - fflush(dinfo->output_file); - if (ferror(dinfo->output_file)) - ERREXIT(cinfo, JERR_FILE_WRITE); -} - - -/* - * The module selection routine for Targa format output. - */ - -GLOBAL(djpeg_dest_ptr) -jinit_write_targa (j_decompress_ptr cinfo) -{ - tga_dest_ptr dest; - - /* Create module interface object, fill in method pointers */ - dest = (tga_dest_ptr) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - SIZEOF(tga_dest_struct)); - dest->pub.start_output = start_output_tga; - dest->pub.finish_output = finish_output_tga; - - /* Calculate output image dimensions so we can allocate space */ - jpeg_calc_output_dimensions(cinfo); - - /* Create I/O buffer. Note we make this near on a PC. */ - dest->buffer_width = cinfo->output_width * cinfo->output_components; - dest->iobuffer = (char *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - (size_t) (dest->buffer_width * SIZEOF(char))); - - /* Create decompressor output buffer. */ - dest->pub.buffer = (*cinfo->mem->alloc_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width, (JDIMENSION) 1); - dest->pub.buffer_height = 1; - - return (djpeg_dest_ptr) dest; -} - -#endif /* TARGA_SUPPORTED */ +/* + * wrtarga.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to write output images in Targa format. + * + * These routines may need modification for non-Unix environments or + * specialized applications. As they stand, they assume output to + * an ordinary stdio stream. + * + * Based on code contributed by Lee Daniel Crocker. + */ + +#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + +#ifdef TARGA_SUPPORTED + + +/* + * To support 12-bit JPEG data, we'd have to scale output down to 8 bits. + * This is not yet implemented. + */ + +#if BITS_IN_JSAMPLE != 8 + Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ +#endif + +/* + * The output buffer needs to be writable by fwrite(). On PCs, we must + * allocate the buffer in near data space, because we are assuming small-data + * memory model, wherein fwrite() can't reach far memory. If you need to + * process very wide images on a PC, you might have to compile in large-memory + * model, or else replace fwrite() with a putc() loop --- which will be much + * slower. + */ + + +/* Private version of data destination object */ + +typedef struct { + struct djpeg_dest_struct pub; /* public fields */ + + char *iobuffer; /* physical I/O buffer */ + JDIMENSION buffer_width; /* width of one row */ +} tga_dest_struct; + +typedef tga_dest_struct * tga_dest_ptr; + + +LOCAL(void) +write_header (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, int num_colors) +/* Create and write a Targa header */ +{ + char targaheader[18]; + + /* Set unused fields of header to 0 */ + MEMZERO(targaheader, SIZEOF(targaheader)); + + if (num_colors > 0) { + targaheader[1] = 1; /* color map type 1 */ + targaheader[5] = (char) (num_colors & 0xFF); + targaheader[6] = (char) (num_colors >> 8); + targaheader[7] = 24; /* 24 bits per cmap entry */ + } + + targaheader[12] = (char) (cinfo->output_width & 0xFF); + targaheader[13] = (char) (cinfo->output_width >> 8); + targaheader[14] = (char) (cinfo->output_height & 0xFF); + targaheader[15] = (char) (cinfo->output_height >> 8); + targaheader[17] = 0x20; /* Top-down, non-interlaced */ + + if (cinfo->out_color_space == JCS_GRAYSCALE) { + targaheader[2] = 3; /* image type = uncompressed gray-scale */ + targaheader[16] = 8; /* bits per pixel */ + } else { /* must be RGB */ + if (num_colors > 0) { + targaheader[2] = 1; /* image type = colormapped RGB */ + targaheader[16] = 8; + } else { + targaheader[2] = 2; /* image type = uncompressed RGB */ + targaheader[16] = 24; + } + } + + if (JFWRITE(dinfo->output_file, targaheader, 18) != (size_t) 18) + ERREXIT(cinfo, JERR_FILE_WRITE); +} + + +/* + * Write some pixel data. + * In this module rows_supplied will always be 1. + */ + +METHODDEF(void) +put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) +/* used for unquantized full-color output */ +{ + tga_dest_ptr dest = (tga_dest_ptr) dinfo; + register JSAMPROW inptr; + register char * outptr; + register JDIMENSION col; + + inptr = dest->pub.buffer[0]; + outptr = dest->iobuffer; + for (col = cinfo->output_width; col > 0; col--) { + outptr[0] = (char) GETJSAMPLE(inptr[2]); /* RGB to BGR order */ + outptr[1] = (char) GETJSAMPLE(inptr[1]); + outptr[2] = (char) GETJSAMPLE(inptr[0]); + inptr += 3, outptr += 3; + } + (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); +} + +METHODDEF(void) +put_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) +/* used for grayscale OR quantized color output */ +{ + tga_dest_ptr dest = (tga_dest_ptr) dinfo; + register JSAMPROW inptr; + register char * outptr; + register JDIMENSION col; + + inptr = dest->pub.buffer[0]; + outptr = dest->iobuffer; + for (col = cinfo->output_width; col > 0; col--) { + *outptr++ = (char) GETJSAMPLE(*inptr++); + } + (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); +} + + +/* + * Write some demapped pixel data when color quantization is in effect. + * For Targa, this is only applied to grayscale data. + */ + +METHODDEF(void) +put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) +{ + tga_dest_ptr dest = (tga_dest_ptr) dinfo; + register JSAMPROW inptr; + register char * outptr; + register JSAMPROW color_map0 = cinfo->colormap[0]; + register JDIMENSION col; + + inptr = dest->pub.buffer[0]; + outptr = dest->iobuffer; + for (col = cinfo->output_width; col > 0; col--) { + *outptr++ = (char) GETJSAMPLE(color_map0[GETJSAMPLE(*inptr++)]); + } + (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); +} + + +/* + * Startup: write the file header. + */ + +METHODDEF(void) +start_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) +{ + tga_dest_ptr dest = (tga_dest_ptr) dinfo; + int num_colors, i; + FILE *outfile; + + if (cinfo->out_color_space == JCS_GRAYSCALE) { + /* Targa doesn't have a mapped grayscale format, so we will */ + /* demap quantized gray output. Never emit a colormap. */ + write_header(cinfo, dinfo, 0); + if (cinfo->quantize_colors) + dest->pub.put_pixel_rows = put_demapped_gray; + else + dest->pub.put_pixel_rows = put_gray_rows; + } else if (cinfo->out_color_space == JCS_RGB) { + if (cinfo->quantize_colors) { + /* We only support 8-bit colormap indexes, so only 256 colors */ + num_colors = cinfo->actual_number_of_colors; + if (num_colors > 256) + ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, num_colors); + write_header(cinfo, dinfo, num_colors); + /* Write the colormap. Note Targa uses BGR byte order */ + outfile = dest->pub.output_file; + for (i = 0; i < num_colors; i++) { + putc(GETJSAMPLE(cinfo->colormap[2][i]), outfile); + putc(GETJSAMPLE(cinfo->colormap[1][i]), outfile); + putc(GETJSAMPLE(cinfo->colormap[0][i]), outfile); + } + dest->pub.put_pixel_rows = put_gray_rows; + } else { + write_header(cinfo, dinfo, 0); + dest->pub.put_pixel_rows = put_pixel_rows; + } + } else { + ERREXIT(cinfo, JERR_TGA_COLORSPACE); + } +} + + +/* + * Finish up at the end of the file. + */ + +METHODDEF(void) +finish_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) +{ + /* Make sure we wrote the output file OK */ + fflush(dinfo->output_file); + if (ferror(dinfo->output_file)) + ERREXIT(cinfo, JERR_FILE_WRITE); +} + + +/* + * The module selection routine for Targa format output. + */ + +GLOBAL(djpeg_dest_ptr) +jinit_write_targa (j_decompress_ptr cinfo) +{ + tga_dest_ptr dest; + + /* Create module interface object, fill in method pointers */ + dest = (tga_dest_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(tga_dest_struct)); + dest->pub.start_output = start_output_tga; + dest->pub.finish_output = finish_output_tga; + + /* Calculate output image dimensions so we can allocate space */ + jpeg_calc_output_dimensions(cinfo); + + /* Create I/O buffer. Note we make this near on a PC. */ + dest->buffer_width = cinfo->output_width * cinfo->output_components; + dest->iobuffer = (char *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (size_t) (dest->buffer_width * SIZEOF(char))); + + /* Create decompressor output buffer. */ + dest->pub.buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width, (JDIMENSION) 1); + dest->pub.buffer_height = 1; + + return (djpeg_dest_ptr) dest; +} + +#endif /* TARGA_SUPPORTED */ diff --git a/Source/LibMNG/Changes b/Source/LibMNG/Changes index fbf2ac5..eeacf33 100644 --- a/Source/LibMNG/Changes +++ b/Source/LibMNG/Changes @@ -1,1447 +1,1447 @@ ------------------------------------------------------------ - -1.0.10 (Jul 13th 2007) ----------------------- - -in short: - -intermediate CVS - -------------------- - -bugfixes: - -core: -- fixed some compiler-warnings -- fixed display routines called twice for FULL_MNG support in mozlibmngconf.h -- standard windows dll upgraded to zlib 1.2.3 -- fixed problem with CLON object during readdisplay() (thanks Winfried!) -- added typecast to appease the compiler (G R-P) -- added more SKIPCHUNK conditionals (G R-P) -- added MORE MNG_NO_1_2_4BIT_SUPPORT (G R-P) -- added provisional support for anIM(mpNG) proposal -- added provisional support for ANG proposal - -samples: -- xmngview upgraded to 0.6 (thanks Winfried!) - -contrib: - -doc: - -makefiles: - -autoconf: - ------------------------------------------------------------ - -1.0.9 (jan 30th 2005) ---------------------- - -in short: - -New optimizations save over 20KB on footprint. -Also a few bugfixes and several patches. - -Thanks to those sending in their additions and for testing! - -To turn on the optimizations do: - -#DEFINE MNG_OPTIMIZE_CHUNKINITFREE -#DEFINE MNG_OPTIMIZE_OBJCLEANUP -#DEFINE MNG_OPTIMIZE_CHUNKASSIGN -#DEFINE MNG_OPTIMIZE_CHUNKREADER - -(eg. they're not on by default (yet) !) - -------------------- - -bugfixes: -- fixed chunk pushing mechanism -- fixed bug in writing sBIT for indexed color -- fixed PPLT getchunk/putchunk routines -- fixed MNG_NO_1_2_4BIT_SUPPORT for TBBN1G04.PNG -- cleaned up macro-invocations (thanks to D. Airlie) - -core: -- added more SKIPCHUNK conditionals -- replaced MNG_TWEAK_LARGE_FILES with permanent solution -- improved handling of cheap transparency when 16-bit support is disabled -- added some MNG_SUPPORT_WRITE conditionals -- added function to retrieve current FRAM delay -- added MNG_NO_1_2_4BIT_SUPPORT -- added bgr565_a8 canvas-style (thanks to J. Elvander) -- standard windows dll upgraded to zlib 1.2.2 -- added LITTLEENDIAN/BIGENDIAN fixtures (thanks J.Stiles) -- inclusion of zlib/lcms/ijgsrc6b with <> instead of "" -- added conditional MNG_OPTIMIZE_CHUNKINITFREE -- added conditional MNG_OPTIMIZE_OBJCLEANUP -- added conditional MNG_OPTIMIZE_CHUNKASSIGN -- added conditional MNG_OPTIMIZE_CHUNKREADER -- fixed problem with global PLTE/tRNS - -samples: - -contrib: - -doc: -- patched jng & mng manual pages (Thanks Peter Breitenlohner) - -makefiles: - -autoconf: -- patched makefile.am & configure.in (Thanks Peter Breitenlohner) - ------------------------------------------------------------ - -1.0.8 (aug 5th 2004) --------------------- - -in short: - -added special data-pushing mechanisms and a few other tid-bits - -------------------- - -bugfixes: -- fixed problem with PAST usage where source > dest - -core: -- added missing get-/put-chunk-jdaa -- added CRC existence & checking flags -- added data-push mechanisms for specialized decoders -- some speed optimizations (thanks to John Stiles) -- defend against using undefined closestream function -- defend against using undefined openstream function -- added check for extreme chunk-lengths -- change worst-case iAlphadepth to 1 for standalone PNGs -- added support for 3+byte pixelsize for JPEG's -- added conditional to allow easier writing of large MNG's - -samples: - -contrib: - -doc: - -makefiles: - -autoconf: - ------------------------------------------------------------ - -1.0.7 (March 21st 2004) ------------------------ - -in short: - -A bunch of new canvas-styles, some bug-fixes, upgraded to latest zlib/lcms -and yet more work to please the Mozilla crowd. -Releasing beta's doesn't seem very responsive, and this one's hardly changed -much anyway. I just wanted to bump to a regular version for Mozilla -re-integration. - -------------------- - -bugfixes: -- fixed inclusion of IJNG chunk for non-JNG use (J.S) -- fixed bug in chunk-storage of SHOW chunk (where from == to) -- fixed bug in promote_g8_g8 with 16bit support off - -core: -- added CANVAS_RGB565 and CANVAS_BGR565 (big thanx to Raphael Assenat!!) -- added CANVAS_RGBA565 and CANVAS_BGRA565 ( -- ditto -- ) -- upgraded to zlib 1.2.1 -- upgraded to lcms 1.11 -- added premultiplied alpha canvas' for RGBA, ARGB, ABGR (thx to John Stiles) -- more optimizations with 16bit support off -- put conditionals around openstream/closestream callbacks. -- fixed typo (MNG_SKIPCHUNK_SAVE -> MNG_SKIPCHUNK_nEED) -- fixed some 64-bit platform compiler warnings - -samples: - -contrib: -- fixed mngtree sample (Raphael) -- added 5-6-5 canvas to SDL sample (Raphael) - -doc: - -makefiles: - -autoconf: - ------------------------------------------------------------ - -1.0.6 (oct 19th 2003) ---------------------- - -in short: - -Final release from beta1. No feedback is good feedback I presume, -so here's 1.0.6-final! - - -------------------- - -bugfixes: - -core: - -samples: - -contrib: - -doc: - -makefiles: - -autoconf: - ------------------------------------------------------------ - -1.0.6-beta1 (sep 14th 2003) ---------------------------- - -in short: - -further footprint-reductions -removing email-addresses - -1.0.6 (final) will be out shortly - -------------------- - -bugfixes: - -core: -- added support for reducing the footprint of libmng by macros that optionally - skip unused chunks, remove 16-bit sample support, remove Delta support, and - remove JNG support, to accomodate Mozilla/Firebird. -- further optional removal of unused functions -- added MNG_NO_SUPPORT_FUNCQUERY conditional -- added iPNGdepth member to pData structure -- added conditionals around MAGN chunk support -- added conditionals around non-VLC chunk support -- added conditionals around "mng_display_go*" and other unused functions -- added more conditionals around "promote" functions -- removed email references as appropriate - -samples: - -contrib: - -doc: - -makefiles: - -autoconf: - ------------------------------------------------------------ - -1.0.6-alpha1 (aug 2nd 2003) ---------------------------- - -in short: - -This is mostly in the light of footprint-reduction to please the Mozilla -crew with a leaner and meaner libmng. See bug 18574 if you're interested: -http://bugzilla.mozilla.org/show_bug.cgi?id=18574 - -------------------- - -bugfixes: -- B719420 - fixed several MNG_APP_CMS problems - -core: -- removed some compiler-warnings -- hiding 12-bit JPEG stuff -- fixed problem with infinite loops during readdisplay() -- added size-optimiation COMPOSE routine usage -- added conditionals around canvas update routines -- added MNG_SKIPCHUNK_cHNK footprint optimizations -- added conditionals around some JNG-supporting code -- added conditionals around 16-bit supporting code -- combined init functions into one function -- replaced nested switches with simple init setup function -- added conditionals zlib and jpeg property accessors -- added size-optimization DIV255B8 routine usage -- added conditionals around 8-bit magn routines -- removed conditionals around 8-bit magn routines -- added MNG_NO_16BIT_SUPPORT and MNG_NO_DELTA_PNG conditionals -- reversed many loops to use decrementing counter -- converted some switches to array references -- removed some redundant checks for iRawlen==0 -- optionally use zlib's crc32 function instead of local mng_update_crc -- bugfix empty "if" statement when 16-bit code is enabled -- restored two misplaced #else/#endif blocks -- added conditionals around "mng_display_go*" and other unused functions -- added MNG_NO_LOOP_SIGNALS_SUPPORTED conditional -- fixed duplicate for-loop -- fixed invalid test in promote_imageobject -- added conditionals around PAST chunk support -- fixed "FOOTPRINT_COMPOSEIV" typo (now "FOOTPRINT_DIV") - -samples: - -contrib: -- updated xmngview -- added MSVC project for creating delta-MNGs: makemng (thanks Alex!) -- added MSVC lib-file for use with the standard libmng.dll (again thanks Alex) - -doc: -- updated readme.contrib - -makefiles: - -autoconf: - ------------------------------------------------------------ - -1.0.5 (mar 1st 2003) --------------------- - -in short: - -Only a small fix for progressive jpeg suspension problem. - -This is the long-awaited final release containing the new 'dynamic MNG' feature -and bringing MNG compliance to near 100%! - -------------------- - -bugfixes: -- B683152 - libjpeg suspension not always honored correctly - -core: - -samples: - -contrib: - -doc: - -makefiles: - -autoconf: - ------------------------------------------------------------ - -1.0.5-rc3 (jan 20th 2003) -------------------------- - -in short: - -Third release-candidate for the upcoming 1.0.5 version. - -Minor bug-fixes and finalizing the accepted proposal (by official vote) for -the TERM/frame_delay changes on mng-list (nov-dec/2002). - -------------------- - -bugfixes: -- B654627 - fixed SEGV when no gettickcount callback (thanks Adam!) -- B664383 - fixed typo (thanks Dimitri) -- B664911 - fixed buffer overflow during init (thanks Alex!) - -core: -- finalized changes in TERM/final_delay to elected proposal (positive vote) - -samples: - -contrib: - -doc: - -makefiles: - -autoconf: - ------------------------------------------------------------ - -1.0.5-rc2 (dec 9th 2002) ------------------------- - -in short: - -Second release-candidate for the upcoming 1.0.5 version. -This contains fixes for a few minor details reported by the loyal testers. -It fixes some issues with the goframe/golayer/gotime processing and related -stuff. And it adds a way to disable playback-caching from within the MNG, -which is very useful for streaming-MNG encoders (such as gserver!). - -------------------- - -bugfixes: - -core: -- fixed layer- & frame-counting during read() -- changed FRAMECOUNT/LAYERCOUNT/PLAYTIME error to warning -- fixed goframe/golayer/gotime processing -- added support for nEED "MNG 1.1" -- added support for nEED "CACHEOFF"; turn playback caching off for streaming MNG -- fixed magnification bug with object 0 -- added support to get totals for frames/layers/playtime after mng_read() -- fixed some issues in init_app_cms() -- fixed goxxxxx() support for zero values - -samples: - -contrib: - -doc: - -makefiles: - -autoconf: - ------------------------------------------------------------ - -1.0.5-rc1 (nov 1st 2002) ------------------------- - -in short: - -First release-candidate for the upcoming 1.0.5 version. -This fixes a few small problems and brings the TERM/MEND processing, with -respect to interframe_delay as per the current discussion on MNG-list, -up-to-date with the latest proposal. - -------------------- - -bugfixes: - -core: -- fixed initialization of pIds in dISC read routine (Thanks Winfried!) -- fixed issue in freeing evNT chunk (Thanks Winfried!) -- fixed clipping-problem with BACK tiling (Thanks Sakura!) -- fixed processing for multiple objects in MAGN (Thanks Sakura!) -- fixed display of visible target of PAST operation (Thanks Sakura!) -- modified TERM/MEND processing for max(1, TERM_delay, interframe_delay) - -samples: - -contrib: -- fixed typo in Makefile for gtk-mng-view sample - -doc: - -makefiles: - -autoconf: - ------------------------------------------------------------ - -1.0.5-b3 (oct 15th 2002) ------------------------- - -in short: - -Fairly quick after beta2, since that introduced a couple of unfortunate -booboo's and wasn't very workable. It also changes the standard configure -script to build a standard shared object similar to what I intended. - -------------------- - -bugfixes: - -core: -- fixed support for condition=2 in TERM chunk -- fixed trace-constants for PAST chunk -- added mng_status_dynamic to supports function - -samples: - -contrib: - -doc: -- small cosmetic changes in man/libmng.3 - -makefiles: - -autoconf: -- fixed configure.in to build a 'standard' SO primarily - ------------------------------------------------------------ - -1.0.5-b2 (oct 9th 2002) ------------------------- - -in short: - -Second beta for next 1.0.5 release. This addresses some minor problems -detected during testing. It adds the proposed change to the MNG spec as -discussed on the "mng-list" recently; eg. Adam's option 4. -And it adds a little function to check at run-time if the lib is a beta or not. - -------------------- - -bugfixes: - -core: -- fixed chunk-storage for evNT chunk -- fixed dropping mix of frozen/unfrozen objects -- fixed problem with cloned objects marked as invalid -- fixed problem cloning frozen object_buffers -- fixed DISC support -- added proposed change in handling of TERM- & interframe-delay -- added another fix for misplaced TERM chunk -- added check for TERM placement during create/write -- completed support for condition=2 in TERM chunk -- added beta version function & constant - -samples: - -contrib: - -doc: - -makefiles: - -autoconf: - ------------------------------------------------------------ - -1.0.5-b1 (sep 24th 2002) ------------------------- - -in short: - -First beta of a large maintenance release. This completes support of the MNG -specification to nearly 100% (PAST, PROM, delta-images, BACK image+tile). -It adds "dynamic" MNG and a few other neat routines as well as fixes several -bugs reported through SourceForge or to me directly. - -------------------- - -bugfixes: -- B575832 - library has wrong patch version number -- B578572 - remove in 1.0.0! -- B578940 - some functions not implemented -- B581625 - large chunks fail with suspension reads -- B597134 - libmng pollutes the linker namespace - -core: -- added sanity check for improbable chunklengths -- removed eMNGma hack (thanks Dimitri!) -- unimplemented functions return an errorcode now -- added test-option for PNG filter method 192 (= levelling) -- added test-option for PNG filter method 193 (= no filtering) - (both are conditional and only for testing purposes!!!) -- completed PROM support -- completed delta-image support -- completed MAGN support (16-bit functions) -- added HLAPI function to copy a chunk from a read MNG to a newly created MNG -- added option for soft-handling of errors (only for repair software!!!) -- fixed some routine inclusion/exclusion for undefined conditionals -- pre-fixed all internal routines with mng_ -- added symbol MNG_LOCAL (= static) to really local functions -- fixed reading of FRAM with just frame_mode and name -- fixed read/write of MAGN chunk -- added event handling for dynamic MNG -- added 'supports' call to check function availability -- fixed copyright notice in the headers of all libmng modules -- fixed LOOP iteration=0 special case -- re-compiled standard Windows dll with lcms-1.0.9 -- added warning for too much IDAT data -- warnings are ignored by default now -- misplaced TERM is now treated as warning -- fixed color-correction for restore-background handling -- optimized restore-background for bKGD cases -- cleaned up some old stuff -- completed support for BACK image & tiling -- completed support for PAST -- added bgrx8 canvas (filler byte) -- fixed reset_object_detail to clear old buffer -- added in-memory color-correction of abstract images -- added compose over/under routines for PAST processing -- added flip & tile routines for PAST processing - -samples: -- Added new BCB sample for fixing invalid JASC Animation Shop files - (shows new copy_chunks function; use of MNG_SOFTERRORS & static linking) - -contrib: -- added xmngview by Winfried Szukalski (Vielen dank!) -- Updated the Delphi mngview sample to handle dynamic MNGs -- Added Kylix example (simplified port of the Delphi mngview sample) - -doc: -- added diff to add MNG&JNG to a systems 'magic' file (Thanks Winfried) -- fixed docs about using mng_display_resume after display_reset - (should read to use mng_display!) - -makefiles: -- added makefile to build a libmng.dll for MingW - (makefile.mingwdll - thanks to Frank Richter!) - -autoconf: -- fixing libtool version-number to be in line with what it should be - ------------------------------------------------------------ - -1.0.4 (Jun 23rd 2002) ---------------------- - -in short: - -Just some small fixes -Standard dll now compiled with zlib 1.1.4 and lcms 1.0.8 - -------------------- - -bugfixes: -- B495442 - invalid returnvalue in mng_get_suspensionmode -- B495443 - incorrect suspend check in read_databuffer -- B526138 - returned IJGSRC6B calling convention to default for MSVC -- B558212 - off by one error -- B557677 - can't find lcms.h - -core: -- fixed possible compile-problem in cleanup_rowproc -- MNG subimage alpha composite wrong for rgba8 images - -samples: - -contrib: - -doc: - -makefiles: -- fixed check for lcms.h in configure.in - -autoconf: - ------------------------------------------------------------ - -1.0.3 (Sep 18th 2001) ---------------------- - -in short: - -Small cosmetic changes. Cleaning up the contributions. -New makefile for mingw32, and new fbcon example. -Major thanks to Greg for helping out with the *nix stuff! -Note that there's also a separate download for ASM programmers now. -Check http://www.libmng.com for details (download/ports&packages page). - -It may be a while for the next release. I'm "off duty" for the next 8 or -so months... - -Gerard - -------------------- - -bugfixes: -- B459058 - wrong include for lcms headers - -core: -- changed inclusion of lcms.h header for Linux platforms (suggested by Greg) -- added get function for last processed BACK chunk - -samples: -- replaced the gtk & sdl viewer apps with updates by Greg Roelofs - -contrib: - -doc: - -makefiles: -- changed makefile.linux & makefile.unix as suggested by Greg Roelofs - (makefile.linux now compiles with lcms by default) -- added makefile.mingw for mingw32 by Benoit Blanchon (thanks Mate!) - -autoconf: - ------------------------------------------------------------ - -1.0.2 (Jul 7th 2001) --------------------- - -in short: - -Another maintenance release with a few added extra's. - -------------------- - -bugfixes: -- B421427 - writes wrong format in bKGD and tRNS -- B434583 - compiler-warning if MNG_STORE_CHUNKS undefined - -core: -- added optimization option for MNG-video playback -- added processterm callback -- added late binding errorcode (not used internally) -- fixed memory-leak with delta-images (Thanks Michael!) -- added option to turn off progressive refresh for large images - -samples: - -contrib: - -doc: - -makefiles: - -autoconf: - ------------------------------------------------------------ - -1.0.1 (May 2nd 2001) --------------------- - -in short: - -Maintenance release. -Fixed several memory-leaks with the help of Gregg Kelly, added/fixed some CMS -handling, exported JPEG functions from standard DLL, and some other minor fixes. - -The CMS fix now makes libmng automagically work in MNG_FULL_CMS mode as a -sRGB compliant system. YOU WILL NEED TO CHANGE THIS IF YOU ARE NOT ON AN sRGB -COMPLIANT SYSTEM AND WANT TO USE CMS!!!! -(look in libmng.h for the proper function-calls) - -------------------- - -bugfixes: - -core: -- added MEND processing callback -- fixed first FRAM_MODE=4 timing problem -- added handle status-copy function (use with care) -- exported JPEG functions from standard DLL -- added BGRA8 canvas with premultiplied alpha (contrib by Gregg Kelly) -- fixed problem with display_reset/display_resume (Thanks Gregg!) -- fixed several memory-leaks (Thanks Gregg!) -- fixed reset_rundata to drop all objects (Thanks again, Gregg!) -- fixed problem with cms profile being created multiple times when both - iCCP & cHRM/gAMA are present (And again... Gregg) -- moved mng_clear_cms to libmng_cms -- added "default" sRGB generation (Thanks Marti!) - -samples: - -contrib: - -doc: - -makefiles: - -autoconf: - ------------------------------------------------------------ - -1.0.0 (Feb 6th 2001) --------------------- - -in short: - -First public release. Finally(!) - -This is the 0.9.5 CVS version, which will never be released, because I feel it -is now ready for a public release. So apart from the version-numbers here and -there, all other changes are listed under 0.9.5. - -This library will work with every MNG/JNG known and available to me. Note that -there are still parts that need to be coded, and that MNG support is around -90-95% (JNG at 100%). It is however compliant with the latest and greatest -MNG 1.0 specification. - -I hope to dedicate a bit more time this year to finish up full support and fill -in the remaining blanks. But this is coming out of my spare time. And extra -help is always appreciated. - -Please enjoy! - -Gerard - ------------------------------------------------------------ - -0.9.5 (no release) ------------------- - -in short: - -intermediate CVS - -------------------- - -bugfixes: -B129681 - fixed compiler warnings SGI/Irix (thanks Dimitri) - -core: -- fixed compiler-warnings Mozilla (thanks Tim) -- fixed timing-problem with switching framing_modes -- fixed some small compiler warnings (thanks Nikki) - -samples: - -contrib: -- fixed library-paths for MSVC DLL project (thanks Chad) - -doc: - -makefiles: -- added makefile for DJGPP (thanks Silvio) - -autoconf: - ------------------------------------------------------------ - -0.9.4 (Jan 19th 2001) ----------------------- - -in short: - -Now that the MNG spec is at 1.0, this should be the last beta. There's a few -small changes to make it inline with the spec, and a couple of bug-fixes. -This is a serious release-candidate for libmng-1.0!! -Please... test test test test!! - -------------------- - -bugfixes: -B123314 - fixed number of TERM related problems -B123322 - fixed unwanted repetition in mng_readdisplay() -B123443 - fixed by Ralph -B124910 - fixed definition for WIN32_LEAN_AND_MEAN (thanks Chad) -B125750 - fixed by Ralph -B125756 - fixed mixup of data- & function-pointers (thanks Dimitri) -B127517 - changed inclusion of the lcms header file for non-windows platforms - -core: -- version numbers -- fixed possible loop in display_resume() (Thanks Vova!) -- fixed unwanted repetition in mng_readdisplay() -- changed inclusion of the lcms header file for non-windows platforms -- changed IHDR filter_method check for PNGs -- moved restore of object 0 to libmng_display -- added restore of object 0 to TERM processing (B123314) -- fixed TERM delay processing (B123314) -- fixed TERM end processing when count = 0 (B123314) -- changed callback convention for MSVC (Thanks Chad) -- fixed mixup of data- & function-pointers (thanks Dimitri) -- added support for "nEED MNG-1.0" -- added errorcode for MAGN methods -- added errorchecking for MAGN methods -- removed "old" MAGN methods 3 & 4 -- added "new" MAGN methods 3, 4 & 5 -- removed test filter-methods 1 & 65 -- set default level-set for filtertype=64 to all zeroes - -samples: - -contrib: -- added GTK mng-view example by Vova Babin -- added MSVC MNGview sample by Nikolaus Brennig -- updated Jason Summer's mngplg to version 0.9.2 - (that's mngplg-0.9.2 based on libmng-0.9.3 !!!) -- rearranged contrib directory slightly -- added MSVC project to build libmng.dll by Chad Austin - -doc: -- added README.dll -- added README.config - -makefiles: -- added a makefile for MS Visual C++ (Thanks to Atsushi Matsuda) - -autoconf: -- fixed configure.in for lcms (FreeBSD port by Mikhail Teterin) -- by default configure includes CMS support if lcms is present - ------------------------------------------------------------ - -0.9.3 (October 29th 2000) -------------------------- - -in short: - -Another beta release. The number of changes in the MNG specification have -resulted in a lot of new code and some changed code. At the same time I saw -no need to withhold some new functionality as it was pretty clear there was -going to be another beta-round. If things go well, I'm going to try to release -libmng 1.0.0 very shortly after this one. - -Many thanks to a lot of people for helping out, sending contributions, making -suggestions and testing this little baby. This would get nowhere without YOU!!! - -- fixed bug 111300/117103 -- added workaround for faulty PhotoShop iCCP chunk -- added MAGN/JDAA chunks -- added support for new filter_types -- added PNG/MNG spec version indicators -- added BCB mngview contribution by Andy Protano -- added BCB mngdump; a GUI-based MNG dumping utility (Andy Protano) -- implemented support for nEED "draft nn" -- implemented app-defined support for bKGD for PNG images -- removed trace-options from default SO/DLL builds (!!!) -- raised initial maximum canvas size to 10000x10000 (!!!) - (an App that wants to protect from overly large images should call - mng_set_maxcanvassize() with appropriate values) -- fixed other assorted stuff - -------------------- - -bugfixes: -B111300 - fixup for improved portability -B117103 - fixed compilation errors on *nix with lcms (thanks Ralph!) - -core: -- fixed compiler-warnings from Mozilla -- added check for simplicity-bits in MHDR -- added workaround for faulty PhotoShop iCCP chunk -- fixed app-supplied background restore -- fixed TERM processing delay of 0 msecs -- fixed write-code for zTXt & iTXt -- fixed read-code for iTXt -- added MAGN chunk -- fixed sRGB precedence for gamma_only corection -- added support for new filter_types -- fixed problem with no refresh after TERM -- fixed DEFI behavior -- fixed inclusion parameters to make the external libs work together -- added export of zlib functions from windows dll -- fixed timing & refresh behavior for single PNG/JNG -- removed trace-options from default SO/DLL builds (!!!) -- fixed MAGN rounding errors (thanks Matthias!) -- fixed small timing problem when FRAM delay = 0 -- fixed simplicity-check in compliance with draft 81/0.98a -- fixed alpha-blending for all alpha-canvasstyles -- added support for alpha-depth prediction -- fixed processing of unknown critical chunks -- removed test-MaGN -- added PNG/MNG spec version indicators -- implemented support for nEED -- added support for JDAA -- added functions to retrieve PNG/JNG specific header-info -- added optional support for bKGD for PNG images -- raised initial maximum canvas size to 10000x10000 -- added support for delta-JNG -- added callback to process non-critical unknown chunks -- fixed support for delta-images during read() / display() -- added closestream() processing for mng_cleanup() -- fixed delta-processing behavior -- added storage for pixel-/alpha-sampledepth for delta's -- implemented delayed delta-processing -- fixed putchunk_plte() to set bEmpty parameter (thanks Ben!) -- added errorcode for delayed delta-processing -- added get/set for bKGD preference setting -- added get function for interlace/progressive display -- fixed bug in empty PLTE handling -- fixed seperate read() & display() processing -- fixed tRNS processing for gray-image < 8-bits - -samples: -- added BCB mngview contribution by Andy Protano - -contrib: -- added BCB mngdump; a GUI-based MNG dumping utility (Andy Protano) - -doc: -- updated RPM spec-file by MATSUURA Takanori -- updated README.contrib - -makefiles: -- fixed some stuff in automake/autoconf/libtool -- fixed auto* for bug B117103 - ------------------------------------------------------------ - -0.9.2 (August 7th 2000) ------------------------ - -in short: - -Third beta release! Last one??? - -!!IMPORTANT!! All file-names are now prefixed with "libmng_" !!IMPORTANT!! - -Many thanks to Albert Chin-A-Young for his contribution of the -autoconf/automake/libtool stuff and to Ralph Giles for helping me -put it in the right places. - -There's a special README.autoconf so please read it! - -- fixed bug 110320/110546/110547/111096 -- added several status retrieval functions -- fixed other small bugs in display processing -- fixed number of small problems and documentation typos -- added autoconf/automake/libtool -- added latest MNG plugin (0.9.0) by Jason Summers - -------------------- - -bugfixes: -B110320 - fixed GCC warning about mix-sized pointer math -B110546 - fixed for improperly returning UNEXPECTEDEOF -B110547 - fixed bug in interlace code -B111096 - fixed large-buffer read-suspension - -core: -- version numbers -- fixed small bugs in display processing -- removed Nextbackxxx fields (no longer used) -- fixed problem with trace-functions improperly wrapped -- put specific code in add_chunk() inside MNG_SUPPORT_WRITE wrapper -- fixed documentation typos -- fixed wrapping of suspension parameters -- added status_xxxx functions -- added trace-codes/-strings for status_xxxxx functions -- changed file-prefixes -- added function to set simplicity field -- added trace-code/-string for updatemngsimplicity -- fixed putchunk_unknown() function - -samples: - -contrib: -- added latest MNG plugin (0.9.0) by Jason Summers - -doc: -- version numbers -- added autoconf readme -- version numbers in RPM stuff - -makefiles: -- fixed for new file-prefix -- added autoconf/automake/libtool - ------------------------------------------------------------ - -0.9.1 (July 26th 2000) ----------------------- - -in short: - -Second beta release. - -Given the enormous amount of bug-reports (not ;-), this will most likely -be one of the last betas. If things remain upright, the first public release -(1.0.0) is fairly eminent in the weeks to come... - -- added SDL mng player by Ralph Giles to contributions -- fixed timing and added internal buffering for I/O-suspension scenarios -- added get routines for internal display-state variables (frame/layer/playtime) -- changed read-processing for improved I/O-suspension (internal buffering) -- fixed several problems with create- & write-support -- added a load of documentation -- lots of small stuff - -------------------- - -bugfixes: - -core: -- fixed mandatory BACK color to be opaque -- changed mng_display_resume to allow to be called after a suspension - return with MNG_NEEDMOREDATA -- changed comments to indicate modified behavior for timer & suspension breaks -- added variables for go_xxxx processing -- implemented support for freeze/reset/resume & go_xxxx -- added trace-codes/-strings for special display processing -- added variables for improved timing support -- added support for improved timing -- added get routines for internal display variables -- added get/set routines for suspensionmode variable -- added trace-code/-string for get/set suspensionmode -- added trace-codes/-strings for get/set display variables -- added support for improved I/O-suspension -- changed read-processing for improved I/O-suspension -- added trace-code/-string for read_databuffer (I/O-suspension) -- added suspendbuffer constants -- changed EOF processing behavior -- fixed TERM delay processing -- changed pre-draft48 frame_mode=3 to frame_mode=1 -- added callbacks for SAVE/SEEK processing -- added trace-codes/-strings for SAVE/SEEK callbacks -- added variable for NEEDSECTIONWAIT breaks -- added trace-codes/-strings for get/set sectionbreaks -- added NEEDSECTIONWAIT error-code/-string -- added macro + routine to set returncode without calling error callback -- added trace-code/-string for special error routine -- changed default readbuffer size from 1024 to 4200 -- added variable for freeze & reset processing -- fixed storage of images during mng_read() -- fixed support for mng_display() after mng_read() -- added error cleanup processing -- fixed support for mng_display_reset() -- fixed suspension-buffering for 32K+ chunks -- added function to set frame-/layer-count & playtime -- added trace-code/-string for updatemngheader -- added error-code/-string for updatemngheader if not a MNG -- fixed creation-code -- fixed writing of signature -- fixed several chunk-writing routines - -samples: -- fixed the libmng.pas module in line with libmng.h - -contrib: -- added the SDL based mngplay viewer by Ralph Giles - -doc: -- extended the RPM contribution by MATSUURA Takanori -- added libmng.txt, a full description of the library and its usage -- added man-pages for mng(5), jng(5) and libmng(3) - -makefiles: - ------------------------------------------------------------ - -0.9.0 (June 30th 2000) ----------------------- - -in short: - -This is the first beta!!! Yippee!!! - -Thanks to all the people who helped to guide me in the right direction. -You know who you are! - -A special thanks to the guys with early implementations, who stood by and -put up with my whims :-) - -changes over 0.5.3: - -- updated mngplg to 0.4.1 (the latest & greatest) -- changed refresh parameters to 'x,y,width,height' - ------------------------------------------------------------ - -0.5.3 (never released) ----------------------- - -in short: - -This is a working version only; the next release will be 0.9.0 (first Beta!) - -There are a few incompatible changes with previous versions. The userdata -variable has been changed from mng_uint32 to mng_ptr to accomodate 64-bit -systems. For the same reason memory allocation size parameters have been -changed to a mng_size_t type which is a typedef of size_t. - -Thanks to Aleks Jakulin for helping to iron out some 64-bit platform issues! - -- implemented the update-region parameters of the refresh callback -- added support for most common delta-image options -- added an animation-speed modifier -- added an image-level parameter for the processtext callback -- updated mngplg to 0.4.0 (supports JNG, full CMS, and other enhancements!) -- fixed a lot of small things -- added support for PPLT chunk -- fixed to support 64-bit platforms - -------------------- - -bugfixes: - -core: -- added processing of color-info on delta-image -- fixed handling of empty SAVE chunk -- fixed display of stored JNG images -- fixed problem with BASI-IEND as object 0 -- changed the version parameters (obviously) -- added update-region parms for refresh calback -- added Needrefresh parameter -- added initialization of update-region for refresh -- added initialization of Needrefresh parameter -- changed progressive-display processing -- added tracecodes for tracing JPEG progression -- added tracing of JPEG calls -- added Deltaimmediate parm for faster delta-processing -- added extra checks for delta-images -- many changes to support delta-images -- optimized some store_xxx routines -- fixed some small things (as precaution) -- fixed possible trouble if IEND display-processing got broken up -- fixed nasty bug with embedded PNG after delta-image -- added processing of PLTE & tRNS for delta-images -- added processing of PLTE/tRNS & color-info for delta-images in the - ani_objects chain -- fixed problem with color-correction for stored images -- added get/set for speedtype to facilitate testing -- added trace-codes & -strings for get/set speedtype -- added speed-modifier to timing routine -- added get-routine of imagelevel for processtext callback -- added trace-code & -string for get imagelevel -- added administration of imagelevel parameter -- added support for PPLT chunk -- added trace-codes & -strings for PPLT chunk processing -- fixed problem with incorrect gamma-correction -- fixed inclusion of IJG read/write code -- fixed problem with 16-bit GA format -- fixed problem with cheap transparency for 4-bit gray -- fixed display_xxxx routines for interlaced images -- added precaution against faulty iCCP chunks from PS -- changed userdata variable to mng_ptr -- added typedef for mng_size_t -- changed size parameter for memory allocation to mng_size_t -- fixed compiler-warning for non-initialized iB variable -- changed definition for 32-bit ints (64-bit platforms) -- changed definition for mng_handle (64-bit platforms) -- swapped refresh parameters -- fixed initialization routine for new mng_handle type -- added inclusion of stdlib.h for abs() -- fixed some 64-bit warnings -- fixed incompatible return-types - -samples: - -contrib: -- updated mngplg to 0.3.0 (supports JNG & full color-correction!) -- updated mngplg to 0.4.0 (Jason is picking up the pace ;-) - -doc: -- added rpm directory with rpm spec-file (contributed by MATSUURA Takanori) - -makefiles: -- changed makefile.linux to reflect versionnr for shared-lib -- changed makefile.linux to depend on mng_conf.h & mng_types.h - ------------------------------------------------------------ - -0.5.2 (June 10th 2000) ----------------------- - -in short: - -This is the third release for developers -Another milestone since JNG is now fully supported -The next release will most likely be numbered 0.9.0 as the first Beta!! - -Fixed bug 106017 & 106019 -Added many constants regarding chunk-property values -Implemented full JNG support -Added all the error- & trace-strings -Added get/set routines for default ZLIB/IJG parameters -Added a generic makefile for Unix platforms (contributed by Tim Rowley) -Added canvasstyle for separate RGB + A canvas (eg. mozilla-style) -Separated configuration-options into a separate file: "mng_conf.h" -Fixed stuff for generic Unix compilation (contributed by Tim Rowley) -Upgraded to lcms1.0.6 (now supports 16-bit endian-peculiarities) -Added a makefile for Linux ELF & fixed some code-issues to go along with gcc -Added support for suspended input-buffer processing -Implemented the display-routines for RGBA/ARGB/BGRA/ABGR canvasstyles -Implemented the application background-restore functionality -Fixed & tested the mngtree Unix-sample (runs on Linux-RH6.2 with libmng.so) -Upgraded mngplg to v0.2.2 (based on the latest code including JNG) -Fixed a lot of other assorted stuff - -------------------- - -bugfixes: -B003(106017) - fixed problem with being proprietary to BCB -B004(106019) - fixed problem when MNG_SUPPORT_WRITE not defined - -core: -- bumped version-numbers up to 0.5.2 (yeah, really) -- fixed support for IJGSRC6B -- cleaned up some code regarding mixed support-options -- complemented constants for chunk-property values -- fixed MNG_UINT_pHYg value -- implemented JNG support -- fixed problem with DEFI clipping -- added error telltale strings & support -- added trace telltale strings & support -- added support for global color-chunks inside TERM/LOOP -- added support for global PLTE,tRNS,bKGD inside TERM/LOOP -- added default IJG compression parameters and such -- moved init of default zlib parms to "mng_hlapi.c" -- added init of default IJG parms -- added support for get/set of zlib/IJG default parms -- added tracestrings for global animation color-chunks -- added tracestrings for get/set of default ZLIB/IJG parms -- added tracestrings for global PLTE,tRNS,bKGD -- added framenr/layernr/playtime to object header -- added initialization of framenr/layernr/playtime -- changed ani_create calls not returning object pointer -- create ani objects always (not just inside TERM/LOOP) -- fixed inconsistancy with freeing global iCCP profile -- fixed minor bugs 16-bit pixel-handling -- added object promotion routine (PROM handling) -- added trace-codes & -strings for image-object promotion -- added trace-codes & -strings for delta-image processing -- added error-codes & -strings for delta-image processing -- added support for delta-image processing -- added ani-object routines for delta-image processing -- added delta-image fields -- added compression/filter/interlace fields to object-buffer for - delta-image processing -- added delta-image row-processing routines -- fixed up punctuation in several files (contributed by Tim Rowley) -- removed useless definition in "mng_chunks.h" (contributed by Tim Rowley) -- fixed pointer confusion in "mng_display.c" (contributed by Tim Rowley) -- fixed inclusion for memcpy (contributed by Tim Rowley) -- added mng_int32p (contributed by Tim Rowley) -- added internal delta-image processing callbacks -- separated configuration-options into "mng_conf.h" -- changed to most likely configuration -- added RGB8_A8 canvasstyle -- added getalphaline callback for RGB8_A8 canvasstyle -- fixed some makeup for Linux gcc compile -- implemented app bkgd restore routines -- implemented RGBA8, ARGB8, BGRA8 & ABGR8 display routines -- added support for RGB8_A8 canvasstyle -- added support for suspended input-buffer processing -- added mng_read_resume HLAPI function to support read-suspension -- fixed timer-handling to run with Mozilla (Tim Rowley) -- fixed alpha-handling for alpha canvasstyles -- fixed some compilation-warnings (contrib Jason Morris) - -samples: -- fixed mngview(delphi) to work with the new core -- synchronized libmng.pas(delphi) with the new libmng.h header -- removed the error- & trace-strings from libmng.pas(delphi) -- fixed mngtree(Unix) to compile on Linux (runs with libmng.so) -- added makefile.linux for mngtree(Unix) (tested on RedHat6.2) - -contrib: -- updated mngplg to 0.2.2 (based on latest code; supports JNG!) - -doc: -- this file obviously -- added Tim Rowley as contributing author -- changed the examples.readme doc -- updated the design-schematics in line with the current code - -makefiles: -- changed the directory to "makefiles" to avoid name-conflicts -- added generic Unix makefile (thanks to Tim Rowley) -- added Linux ELF makefile (tested on RedHat6.2) - ------------------------------------------------------------ - -0.5.1 May 16th 2000 -------------------- - -in short: - -This is the second release for developers -It's a bit of a milestone since all the chunk functionality is in place and -functioning (read, examine, create & write) -This version is incompatible with 0.5.0 since some of the callback prototypes -have changed (should be the last time that happens!) -There are a few more samples and even a real contribution! - -Fixed bug 105795 & 105797 -Fixed a mis-alignment in animation-timing -Added chunk-access functions -Finished all chunk-storage routine-bits -Finished all chunk-write routines -Changed the callback prototypes to allow error-reporting back to the library -Fixed some routines to allow for callback error-reporting -Added version-control functions & constants -Added two functions to set display- & sRGB-profile from memory -Moved CRC table to dynamic structure (for improved thread-safety) -Added SAVE & SEEK save&restore functionality -Finished the application-based CMS-callbacks -Fixed a few BCB specifics -Changed the Win32 DLL and samples to use __stdcall -Did some more assorted little changes -Added 2 BCB samples -Added 1 Unix sample -Added the MNG plugin by Jason Summers in the contrib section -Changed some documents to reflect these changes - -------------------- - -bugfixes: -B001(105795) - fixed wrong lcms call & memory-leak for gammatables -B002(105797) - fixed problem with missing sRGB profile - -core: -- changed chunk iteration function -- added chunk access functions -- added version control constants & functions -- changed strict-ANSI stuff -- added set_outputprofile2 & set_srgbprofile2 -- added empty-chunk put-routines -- added version_dll & VERSION_DLL (for consistency) -- added version control explanatory text & samples -- added iteratechunk callback definition -- improved definitions for DLL support -- added 8-bit palette definition -- added general array definitions -- added MNG_NULL definition -- changed most callback prototypes to allow the app - to report errors during callback processing -- added CRC table to main structure (for thread-safety) -- added iPLTEentries for checking hIST-length -- changed palette definition to exported palette-type -- removed frozen indicator -- added create/write indicators -- added eMNGma hack (will be removed in 1.0.0 !!!) -- added TERM animation object pointer (easier reference) -- added saved-data structure for SAVE/SEEK processing -- added some errorcodes -- added application errorcodes (used with callbacks) -- moved chunk-access errorcodes to severity 5 -- added chunk-access function trace-codes -- changed trace to macro for callback error-reporting -- added save_state & restore_state trace-codes -- put in some extra comments -- fixed layout for sBIT, PPLT -- changed write callback definition -- fixed layout for PPLT again (missed deltatype ?!?) -- cleaned up left-over teststuff in the BACK chunk routine -- changed CRC initialization to use dynamic structure - (wasn't thread-safe the old way !) -- filled in many missing sequence&length checks -- filled in many missing chunk-store snippets -- added checks for running animations -- filled remaining write routines -- fixed read_pplt with regard to deltatype -- added callback error-reporting support -- added pre-draft48 support (short MHDR, frame_mode, LOOP) -- fixed chunk-storage bit in several routines -- supplemented the SAVE & SEEK display processing -- added init of iPLTEcount -- changed calling-convention definition -- changed status-handling of display-routines -- added versioning-control routines -- filled the write routine -- fixed frame_delay misalignment -- added sanity check for frozen status -- changed display_mend to reset state to initial or SAVE -- added save_state and restore_state for SAVE/SEEK/TERM - processing -- added process_save & process_seek routines -- changed and filled iterate-chunk function -- added getchunk functions -- added putchunk functions -- added empty-chunk put-routines -- filled application-based color-management routines -- added creatememprofile -- filled the deflatedata routine -- added cleanup of saved-data (SAVE/SEEK processing) -- moved the actual write_graphic functionality from mng_hlapi.c - to it's appropriate function in the mng_write.c module -- moved standard header includes into mng_types.h - (stdlib/mem for mem-mngmt & math for fp gamma-calc) -- added getimgdata & putimgdata functions - -samples: -- fixed mngview(delphi) to work with the new core -- synchronized libmng.pas(delphi) with the new libmng.h header -- added mngtree(bcb) sample -- added bogus(bcb) sample -- added mngtree(unix) sample - -contrib: -- added mngplg 0.1.0 / a MNG plugin for Win32 by Jason Summers - -doc: -- added this changes.readme file -- changed the samples.readme doc accordingly -- changed the contrib.readme doc accordingly - ------------------------------------------------------------ - -0.5.0 May 1st 2000 ------------------- - -in short: - -This is the first developers release. -It's roughly about 60% done. +----------------------------------------------------------- + +1.0.10 (Jul 13th 2007) +---------------------- + +in short: + +intermediate CVS + +------------------- + +bugfixes: + +core: +- fixed some compiler-warnings +- fixed display routines called twice for FULL_MNG support in mozlibmngconf.h +- standard windows dll upgraded to zlib 1.2.3 +- fixed problem with CLON object during readdisplay() (thanks Winfried!) +- added typecast to appease the compiler (G R-P) +- added more SKIPCHUNK conditionals (G R-P) +- added MORE MNG_NO_1_2_4BIT_SUPPORT (G R-P) +- added provisional support for anIM(mpNG) proposal +- added provisional support for ANG proposal + +samples: +- xmngview upgraded to 0.6 (thanks Winfried!) + +contrib: + +doc: + +makefiles: + +autoconf: + +----------------------------------------------------------- + +1.0.9 (jan 30th 2005) +--------------------- + +in short: + +New optimizations save over 20KB on footprint. +Also a few bugfixes and several patches. + +Thanks to those sending in their additions and for testing! + +To turn on the optimizations do: + +#DEFINE MNG_OPTIMIZE_CHUNKINITFREE +#DEFINE MNG_OPTIMIZE_OBJCLEANUP +#DEFINE MNG_OPTIMIZE_CHUNKASSIGN +#DEFINE MNG_OPTIMIZE_CHUNKREADER + +(eg. they're not on by default (yet) !) + +------------------- + +bugfixes: +- fixed chunk pushing mechanism +- fixed bug in writing sBIT for indexed color +- fixed PPLT getchunk/putchunk routines +- fixed MNG_NO_1_2_4BIT_SUPPORT for TBBN1G04.PNG +- cleaned up macro-invocations (thanks to D. Airlie) + +core: +- added more SKIPCHUNK conditionals +- replaced MNG_TWEAK_LARGE_FILES with permanent solution +- improved handling of cheap transparency when 16-bit support is disabled +- added some MNG_SUPPORT_WRITE conditionals +- added function to retrieve current FRAM delay +- added MNG_NO_1_2_4BIT_SUPPORT +- added bgr565_a8 canvas-style (thanks to J. Elvander) +- standard windows dll upgraded to zlib 1.2.2 +- added LITTLEENDIAN/BIGENDIAN fixtures (thanks J.Stiles) +- inclusion of zlib/lcms/ijgsrc6b with <> instead of "" +- added conditional MNG_OPTIMIZE_CHUNKINITFREE +- added conditional MNG_OPTIMIZE_OBJCLEANUP +- added conditional MNG_OPTIMIZE_CHUNKASSIGN +- added conditional MNG_OPTIMIZE_CHUNKREADER +- fixed problem with global PLTE/tRNS + +samples: + +contrib: + +doc: +- patched jng & mng manual pages (Thanks Peter Breitenlohner) + +makefiles: + +autoconf: +- patched makefile.am & configure.in (Thanks Peter Breitenlohner) + +----------------------------------------------------------- + +1.0.8 (aug 5th 2004) +-------------------- + +in short: + +added special data-pushing mechanisms and a few other tid-bits + +------------------- + +bugfixes: +- fixed problem with PAST usage where source > dest + +core: +- added missing get-/put-chunk-jdaa +- added CRC existence & checking flags +- added data-push mechanisms for specialized decoders +- some speed optimizations (thanks to John Stiles) +- defend against using undefined closestream function +- defend against using undefined openstream function +- added check for extreme chunk-lengths +- change worst-case iAlphadepth to 1 for standalone PNGs +- added support for 3+byte pixelsize for JPEG's +- added conditional to allow easier writing of large MNG's + +samples: + +contrib: + +doc: + +makefiles: + +autoconf: + +----------------------------------------------------------- + +1.0.7 (March 21st 2004) +----------------------- + +in short: + +A bunch of new canvas-styles, some bug-fixes, upgraded to latest zlib/lcms +and yet more work to please the Mozilla crowd. +Releasing beta's doesn't seem very responsive, and this one's hardly changed +much anyway. I just wanted to bump to a regular version for Mozilla +re-integration. + +------------------- + +bugfixes: +- fixed inclusion of IJNG chunk for non-JNG use (J.S) +- fixed bug in chunk-storage of SHOW chunk (where from == to) +- fixed bug in promote_g8_g8 with 16bit support off + +core: +- added CANVAS_RGB565 and CANVAS_BGR565 (big thanx to Raphael Assenat!!) +- added CANVAS_RGBA565 and CANVAS_BGRA565 ( -- ditto -- ) +- upgraded to zlib 1.2.1 +- upgraded to lcms 1.11 +- added premultiplied alpha canvas' for RGBA, ARGB, ABGR (thx to John Stiles) +- more optimizations with 16bit support off +- put conditionals around openstream/closestream callbacks. +- fixed typo (MNG_SKIPCHUNK_SAVE -> MNG_SKIPCHUNK_nEED) +- fixed some 64-bit platform compiler warnings + +samples: + +contrib: +- fixed mngtree sample (Raphael) +- added 5-6-5 canvas to SDL sample (Raphael) + +doc: + +makefiles: + +autoconf: + +----------------------------------------------------------- + +1.0.6 (oct 19th 2003) +--------------------- + +in short: + +Final release from beta1. No feedback is good feedback I presume, +so here's 1.0.6-final! + + +------------------- + +bugfixes: + +core: + +samples: + +contrib: + +doc: + +makefiles: + +autoconf: + +----------------------------------------------------------- + +1.0.6-beta1 (sep 14th 2003) +--------------------------- + +in short: + +further footprint-reductions +removing email-addresses + +1.0.6 (final) will be out shortly + +------------------- + +bugfixes: + +core: +- added support for reducing the footprint of libmng by macros that optionally + skip unused chunks, remove 16-bit sample support, remove Delta support, and + remove JNG support, to accomodate Mozilla/Firebird. +- further optional removal of unused functions +- added MNG_NO_SUPPORT_FUNCQUERY conditional +- added iPNGdepth member to pData structure +- added conditionals around MAGN chunk support +- added conditionals around non-VLC chunk support +- added conditionals around "mng_display_go*" and other unused functions +- added more conditionals around "promote" functions +- removed email references as appropriate + +samples: + +contrib: + +doc: + +makefiles: + +autoconf: + +----------------------------------------------------------- + +1.0.6-alpha1 (aug 2nd 2003) +--------------------------- + +in short: + +This is mostly in the light of footprint-reduction to please the Mozilla +crew with a leaner and meaner libmng. See bug 18574 if you're interested: +http://bugzilla.mozilla.org/show_bug.cgi?id=18574 + +------------------- + +bugfixes: +- B719420 - fixed several MNG_APP_CMS problems + +core: +- removed some compiler-warnings +- hiding 12-bit JPEG stuff +- fixed problem with infinite loops during readdisplay() +- added size-optimiation COMPOSE routine usage +- added conditionals around canvas update routines +- added MNG_SKIPCHUNK_cHNK footprint optimizations +- added conditionals around some JNG-supporting code +- added conditionals around 16-bit supporting code +- combined init functions into one function +- replaced nested switches with simple init setup function +- added conditionals zlib and jpeg property accessors +- added size-optimization DIV255B8 routine usage +- added conditionals around 8-bit magn routines +- removed conditionals around 8-bit magn routines +- added MNG_NO_16BIT_SUPPORT and MNG_NO_DELTA_PNG conditionals +- reversed many loops to use decrementing counter +- converted some switches to array references +- removed some redundant checks for iRawlen==0 +- optionally use zlib's crc32 function instead of local mng_update_crc +- bugfix empty "if" statement when 16-bit code is enabled +- restored two misplaced #else/#endif blocks +- added conditionals around "mng_display_go*" and other unused functions +- added MNG_NO_LOOP_SIGNALS_SUPPORTED conditional +- fixed duplicate for-loop +- fixed invalid test in promote_imageobject +- added conditionals around PAST chunk support +- fixed "FOOTPRINT_COMPOSEIV" typo (now "FOOTPRINT_DIV") + +samples: + +contrib: +- updated xmngview +- added MSVC project for creating delta-MNGs: makemng (thanks Alex!) +- added MSVC lib-file for use with the standard libmng.dll (again thanks Alex) + +doc: +- updated readme.contrib + +makefiles: + +autoconf: + +----------------------------------------------------------- + +1.0.5 (mar 1st 2003) +-------------------- + +in short: + +Only a small fix for progressive jpeg suspension problem. + +This is the long-awaited final release containing the new 'dynamic MNG' feature +and bringing MNG compliance to near 100%! + +------------------- + +bugfixes: +- B683152 - libjpeg suspension not always honored correctly + +core: + +samples: + +contrib: + +doc: + +makefiles: + +autoconf: + +----------------------------------------------------------- + +1.0.5-rc3 (jan 20th 2003) +------------------------- + +in short: + +Third release-candidate for the upcoming 1.0.5 version. + +Minor bug-fixes and finalizing the accepted proposal (by official vote) for +the TERM/frame_delay changes on mng-list (nov-dec/2002). + +------------------- + +bugfixes: +- B654627 - fixed SEGV when no gettickcount callback (thanks Adam!) +- B664383 - fixed typo (thanks Dimitri) +- B664911 - fixed buffer overflow during init (thanks Alex!) + +core: +- finalized changes in TERM/final_delay to elected proposal (positive vote) + +samples: + +contrib: + +doc: + +makefiles: + +autoconf: + +----------------------------------------------------------- + +1.0.5-rc2 (dec 9th 2002) +------------------------ + +in short: + +Second release-candidate for the upcoming 1.0.5 version. +This contains fixes for a few minor details reported by the loyal testers. +It fixes some issues with the goframe/golayer/gotime processing and related +stuff. And it adds a way to disable playback-caching from within the MNG, +which is very useful for streaming-MNG encoders (such as gserver!). + +------------------- + +bugfixes: + +core: +- fixed layer- & frame-counting during read() +- changed FRAMECOUNT/LAYERCOUNT/PLAYTIME error to warning +- fixed goframe/golayer/gotime processing +- added support for nEED "MNG 1.1" +- added support for nEED "CACHEOFF"; turn playback caching off for streaming MNG +- fixed magnification bug with object 0 +- added support to get totals for frames/layers/playtime after mng_read() +- fixed some issues in init_app_cms() +- fixed goxxxxx() support for zero values + +samples: + +contrib: + +doc: + +makefiles: + +autoconf: + +----------------------------------------------------------- + +1.0.5-rc1 (nov 1st 2002) +------------------------ + +in short: + +First release-candidate for the upcoming 1.0.5 version. +This fixes a few small problems and brings the TERM/MEND processing, with +respect to interframe_delay as per the current discussion on MNG-list, +up-to-date with the latest proposal. + +------------------- + +bugfixes: + +core: +- fixed initialization of pIds in dISC read routine (Thanks Winfried!) +- fixed issue in freeing evNT chunk (Thanks Winfried!) +- fixed clipping-problem with BACK tiling (Thanks Sakura!) +- fixed processing for multiple objects in MAGN (Thanks Sakura!) +- fixed display of visible target of PAST operation (Thanks Sakura!) +- modified TERM/MEND processing for max(1, TERM_delay, interframe_delay) + +samples: + +contrib: +- fixed typo in Makefile for gtk-mng-view sample + +doc: + +makefiles: + +autoconf: + +----------------------------------------------------------- + +1.0.5-b3 (oct 15th 2002) +------------------------ + +in short: + +Fairly quick after beta2, since that introduced a couple of unfortunate +booboo's and wasn't very workable. It also changes the standard configure +script to build a standard shared object similar to what I intended. + +------------------- + +bugfixes: + +core: +- fixed support for condition=2 in TERM chunk +- fixed trace-constants for PAST chunk +- added mng_status_dynamic to supports function + +samples: + +contrib: + +doc: +- small cosmetic changes in man/libmng.3 + +makefiles: + +autoconf: +- fixed configure.in to build a 'standard' SO primarily + +----------------------------------------------------------- + +1.0.5-b2 (oct 9th 2002) +------------------------ + +in short: + +Second beta for next 1.0.5 release. This addresses some minor problems +detected during testing. It adds the proposed change to the MNG spec as +discussed on the "mng-list" recently; eg. Adam's option 4. +And it adds a little function to check at run-time if the lib is a beta or not. + +------------------- + +bugfixes: + +core: +- fixed chunk-storage for evNT chunk +- fixed dropping mix of frozen/unfrozen objects +- fixed problem with cloned objects marked as invalid +- fixed problem cloning frozen object_buffers +- fixed DISC support +- added proposed change in handling of TERM- & interframe-delay +- added another fix for misplaced TERM chunk +- added check for TERM placement during create/write +- completed support for condition=2 in TERM chunk +- added beta version function & constant + +samples: + +contrib: + +doc: + +makefiles: + +autoconf: + +----------------------------------------------------------- + +1.0.5-b1 (sep 24th 2002) +------------------------ + +in short: + +First beta of a large maintenance release. This completes support of the MNG +specification to nearly 100% (PAST, PROM, delta-images, BACK image+tile). +It adds "dynamic" MNG and a few other neat routines as well as fixes several +bugs reported through SourceForge or to me directly. + +------------------- + +bugfixes: +- B575832 - library has wrong patch version number +- B578572 - remove in 1.0.0! +- B578940 - some functions not implemented +- B581625 - large chunks fail with suspension reads +- B597134 - libmng pollutes the linker namespace + +core: +- added sanity check for improbable chunklengths +- removed eMNGma hack (thanks Dimitri!) +- unimplemented functions return an errorcode now +- added test-option for PNG filter method 192 (= levelling) +- added test-option for PNG filter method 193 (= no filtering) + (both are conditional and only for testing purposes!!!) +- completed PROM support +- completed delta-image support +- completed MAGN support (16-bit functions) +- added HLAPI function to copy a chunk from a read MNG to a newly created MNG +- added option for soft-handling of errors (only for repair software!!!) +- fixed some routine inclusion/exclusion for undefined conditionals +- pre-fixed all internal routines with mng_ +- added symbol MNG_LOCAL (= static) to really local functions +- fixed reading of FRAM with just frame_mode and name +- fixed read/write of MAGN chunk +- added event handling for dynamic MNG +- added 'supports' call to check function availability +- fixed copyright notice in the headers of all libmng modules +- fixed LOOP iteration=0 special case +- re-compiled standard Windows dll with lcms-1.0.9 +- added warning for too much IDAT data +- warnings are ignored by default now +- misplaced TERM is now treated as warning +- fixed color-correction for restore-background handling +- optimized restore-background for bKGD cases +- cleaned up some old stuff +- completed support for BACK image & tiling +- completed support for PAST +- added bgrx8 canvas (filler byte) +- fixed reset_object_detail to clear old buffer +- added in-memory color-correction of abstract images +- added compose over/under routines for PAST processing +- added flip & tile routines for PAST processing + +samples: +- Added new BCB sample for fixing invalid JASC Animation Shop files + (shows new copy_chunks function; use of MNG_SOFTERRORS & static linking) + +contrib: +- added xmngview by Winfried Szukalski (Vielen dank!) +- Updated the Delphi mngview sample to handle dynamic MNGs +- Added Kylix example (simplified port of the Delphi mngview sample) + +doc: +- added diff to add MNG&JNG to a systems 'magic' file (Thanks Winfried) +- fixed docs about using mng_display_resume after display_reset + (should read to use mng_display!) + +makefiles: +- added makefile to build a libmng.dll for MingW + (makefile.mingwdll - thanks to Frank Richter!) + +autoconf: +- fixing libtool version-number to be in line with what it should be + +----------------------------------------------------------- + +1.0.4 (Jun 23rd 2002) +--------------------- + +in short: + +Just some small fixes +Standard dll now compiled with zlib 1.1.4 and lcms 1.0.8 + +------------------- + +bugfixes: +- B495442 - invalid returnvalue in mng_get_suspensionmode +- B495443 - incorrect suspend check in read_databuffer +- B526138 - returned IJGSRC6B calling convention to default for MSVC +- B558212 - off by one error +- B557677 - can't find lcms.h + +core: +- fixed possible compile-problem in cleanup_rowproc +- MNG subimage alpha composite wrong for rgba8 images + +samples: + +contrib: + +doc: + +makefiles: +- fixed check for lcms.h in configure.in + +autoconf: + +----------------------------------------------------------- + +1.0.3 (Sep 18th 2001) +--------------------- + +in short: + +Small cosmetic changes. Cleaning up the contributions. +New makefile for mingw32, and new fbcon example. +Major thanks to Greg for helping out with the *nix stuff! +Note that there's also a separate download for ASM programmers now. +Check http://www.libmng.com for details (download/ports&packages page). + +It may be a while for the next release. I'm "off duty" for the next 8 or +so months... + +Gerard + +------------------- + +bugfixes: +- B459058 - wrong include for lcms headers + +core: +- changed inclusion of lcms.h header for Linux platforms (suggested by Greg) +- added get function for last processed BACK chunk + +samples: +- replaced the gtk & sdl viewer apps with updates by Greg Roelofs + +contrib: + +doc: + +makefiles: +- changed makefile.linux & makefile.unix as suggested by Greg Roelofs + (makefile.linux now compiles with lcms by default) +- added makefile.mingw for mingw32 by Benoit Blanchon (thanks Mate!) + +autoconf: + +----------------------------------------------------------- + +1.0.2 (Jul 7th 2001) +-------------------- + +in short: + +Another maintenance release with a few added extra's. + +------------------- + +bugfixes: +- B421427 - writes wrong format in bKGD and tRNS +- B434583 - compiler-warning if MNG_STORE_CHUNKS undefined + +core: +- added optimization option for MNG-video playback +- added processterm callback +- added late binding errorcode (not used internally) +- fixed memory-leak with delta-images (Thanks Michael!) +- added option to turn off progressive refresh for large images + +samples: + +contrib: + +doc: + +makefiles: + +autoconf: + +----------------------------------------------------------- + +1.0.1 (May 2nd 2001) +-------------------- + +in short: + +Maintenance release. +Fixed several memory-leaks with the help of Gregg Kelly, added/fixed some CMS +handling, exported JPEG functions from standard DLL, and some other minor fixes. + +The CMS fix now makes libmng automagically work in MNG_FULL_CMS mode as a +sRGB compliant system. YOU WILL NEED TO CHANGE THIS IF YOU ARE NOT ON AN sRGB +COMPLIANT SYSTEM AND WANT TO USE CMS!!!! +(look in libmng.h for the proper function-calls) + +------------------- + +bugfixes: + +core: +- added MEND processing callback +- fixed first FRAM_MODE=4 timing problem +- added handle status-copy function (use with care) +- exported JPEG functions from standard DLL +- added BGRA8 canvas with premultiplied alpha (contrib by Gregg Kelly) +- fixed problem with display_reset/display_resume (Thanks Gregg!) +- fixed several memory-leaks (Thanks Gregg!) +- fixed reset_rundata to drop all objects (Thanks again, Gregg!) +- fixed problem with cms profile being created multiple times when both + iCCP & cHRM/gAMA are present (And again... Gregg) +- moved mng_clear_cms to libmng_cms +- added "default" sRGB generation (Thanks Marti!) + +samples: + +contrib: + +doc: + +makefiles: + +autoconf: + +----------------------------------------------------------- + +1.0.0 (Feb 6th 2001) +-------------------- + +in short: + +First public release. Finally(!) + +This is the 0.9.5 CVS version, which will never be released, because I feel it +is now ready for a public release. So apart from the version-numbers here and +there, all other changes are listed under 0.9.5. + +This library will work with every MNG/JNG known and available to me. Note that +there are still parts that need to be coded, and that MNG support is around +90-95% (JNG at 100%). It is however compliant with the latest and greatest +MNG 1.0 specification. + +I hope to dedicate a bit more time this year to finish up full support and fill +in the remaining blanks. But this is coming out of my spare time. And extra +help is always appreciated. + +Please enjoy! + +Gerard + +----------------------------------------------------------- + +0.9.5 (no release) +------------------ + +in short: + +intermediate CVS + +------------------- + +bugfixes: +B129681 - fixed compiler warnings SGI/Irix (thanks Dimitri) + +core: +- fixed compiler-warnings Mozilla (thanks Tim) +- fixed timing-problem with switching framing_modes +- fixed some small compiler warnings (thanks Nikki) + +samples: + +contrib: +- fixed library-paths for MSVC DLL project (thanks Chad) + +doc: + +makefiles: +- added makefile for DJGPP (thanks Silvio) + +autoconf: + +----------------------------------------------------------- + +0.9.4 (Jan 19th 2001) +---------------------- + +in short: + +Now that the MNG spec is at 1.0, this should be the last beta. There's a few +small changes to make it inline with the spec, and a couple of bug-fixes. +This is a serious release-candidate for libmng-1.0!! +Please... test test test test!! + +------------------- + +bugfixes: +B123314 - fixed number of TERM related problems +B123322 - fixed unwanted repetition in mng_readdisplay() +B123443 - fixed by Ralph +B124910 - fixed definition for WIN32_LEAN_AND_MEAN (thanks Chad) +B125750 - fixed by Ralph +B125756 - fixed mixup of data- & function-pointers (thanks Dimitri) +B127517 - changed inclusion of the lcms header file for non-windows platforms + +core: +- version numbers +- fixed possible loop in display_resume() (Thanks Vova!) +- fixed unwanted repetition in mng_readdisplay() +- changed inclusion of the lcms header file for non-windows platforms +- changed IHDR filter_method check for PNGs +- moved restore of object 0 to libmng_display +- added restore of object 0 to TERM processing (B123314) +- fixed TERM delay processing (B123314) +- fixed TERM end processing when count = 0 (B123314) +- changed callback convention for MSVC (Thanks Chad) +- fixed mixup of data- & function-pointers (thanks Dimitri) +- added support for "nEED MNG-1.0" +- added errorcode for MAGN methods +- added errorchecking for MAGN methods +- removed "old" MAGN methods 3 & 4 +- added "new" MAGN methods 3, 4 & 5 +- removed test filter-methods 1 & 65 +- set default level-set for filtertype=64 to all zeroes + +samples: + +contrib: +- added GTK mng-view example by Vova Babin +- added MSVC MNGview sample by Nikolaus Brennig +- updated Jason Summer's mngplg to version 0.9.2 + (that's mngplg-0.9.2 based on libmng-0.9.3 !!!) +- rearranged contrib directory slightly +- added MSVC project to build libmng.dll by Chad Austin + +doc: +- added README.dll +- added README.config + +makefiles: +- added a makefile for MS Visual C++ (Thanks to Atsushi Matsuda) + +autoconf: +- fixed configure.in for lcms (FreeBSD port by Mikhail Teterin) +- by default configure includes CMS support if lcms is present + +----------------------------------------------------------- + +0.9.3 (October 29th 2000) +------------------------- + +in short: + +Another beta release. The number of changes in the MNG specification have +resulted in a lot of new code and some changed code. At the same time I saw +no need to withhold some new functionality as it was pretty clear there was +going to be another beta-round. If things go well, I'm going to try to release +libmng 1.0.0 very shortly after this one. + +Many thanks to a lot of people for helping out, sending contributions, making +suggestions and testing this little baby. This would get nowhere without YOU!!! + +- fixed bug 111300/117103 +- added workaround for faulty PhotoShop iCCP chunk +- added MAGN/JDAA chunks +- added support for new filter_types +- added PNG/MNG spec version indicators +- added BCB mngview contribution by Andy Protano +- added BCB mngdump; a GUI-based MNG dumping utility (Andy Protano) +- implemented support for nEED "draft nn" +- implemented app-defined support for bKGD for PNG images +- removed trace-options from default SO/DLL builds (!!!) +- raised initial maximum canvas size to 10000x10000 (!!!) + (an App that wants to protect from overly large images should call + mng_set_maxcanvassize() with appropriate values) +- fixed other assorted stuff + +------------------- + +bugfixes: +B111300 - fixup for improved portability +B117103 - fixed compilation errors on *nix with lcms (thanks Ralph!) + +core: +- fixed compiler-warnings from Mozilla +- added check for simplicity-bits in MHDR +- added workaround for faulty PhotoShop iCCP chunk +- fixed app-supplied background restore +- fixed TERM processing delay of 0 msecs +- fixed write-code for zTXt & iTXt +- fixed read-code for iTXt +- added MAGN chunk +- fixed sRGB precedence for gamma_only corection +- added support for new filter_types +- fixed problem with no refresh after TERM +- fixed DEFI behavior +- fixed inclusion parameters to make the external libs work together +- added export of zlib functions from windows dll +- fixed timing & refresh behavior for single PNG/JNG +- removed trace-options from default SO/DLL builds (!!!) +- fixed MAGN rounding errors (thanks Matthias!) +- fixed small timing problem when FRAM delay = 0 +- fixed simplicity-check in compliance with draft 81/0.98a +- fixed alpha-blending for all alpha-canvasstyles +- added support for alpha-depth prediction +- fixed processing of unknown critical chunks +- removed test-MaGN +- added PNG/MNG spec version indicators +- implemented support for nEED +- added support for JDAA +- added functions to retrieve PNG/JNG specific header-info +- added optional support for bKGD for PNG images +- raised initial maximum canvas size to 10000x10000 +- added support for delta-JNG +- added callback to process non-critical unknown chunks +- fixed support for delta-images during read() / display() +- added closestream() processing for mng_cleanup() +- fixed delta-processing behavior +- added storage for pixel-/alpha-sampledepth for delta's +- implemented delayed delta-processing +- fixed putchunk_plte() to set bEmpty parameter (thanks Ben!) +- added errorcode for delayed delta-processing +- added get/set for bKGD preference setting +- added get function for interlace/progressive display +- fixed bug in empty PLTE handling +- fixed seperate read() & display() processing +- fixed tRNS processing for gray-image < 8-bits + +samples: +- added BCB mngview contribution by Andy Protano + +contrib: +- added BCB mngdump; a GUI-based MNG dumping utility (Andy Protano) + +doc: +- updated RPM spec-file by MATSUURA Takanori +- updated README.contrib + +makefiles: +- fixed some stuff in automake/autoconf/libtool +- fixed auto* for bug B117103 + +----------------------------------------------------------- + +0.9.2 (August 7th 2000) +----------------------- + +in short: + +Third beta release! Last one??? + +!!IMPORTANT!! All file-names are now prefixed with "libmng_" !!IMPORTANT!! + +Many thanks to Albert Chin-A-Young for his contribution of the +autoconf/automake/libtool stuff and to Ralph Giles for helping me +put it in the right places. + +There's a special README.autoconf so please read it! + +- fixed bug 110320/110546/110547/111096 +- added several status retrieval functions +- fixed other small bugs in display processing +- fixed number of small problems and documentation typos +- added autoconf/automake/libtool +- added latest MNG plugin (0.9.0) by Jason Summers + +------------------- + +bugfixes: +B110320 - fixed GCC warning about mix-sized pointer math +B110546 - fixed for improperly returning UNEXPECTEDEOF +B110547 - fixed bug in interlace code +B111096 - fixed large-buffer read-suspension + +core: +- version numbers +- fixed small bugs in display processing +- removed Nextbackxxx fields (no longer used) +- fixed problem with trace-functions improperly wrapped +- put specific code in add_chunk() inside MNG_SUPPORT_WRITE wrapper +- fixed documentation typos +- fixed wrapping of suspension parameters +- added status_xxxx functions +- added trace-codes/-strings for status_xxxxx functions +- changed file-prefixes +- added function to set simplicity field +- added trace-code/-string for updatemngsimplicity +- fixed putchunk_unknown() function + +samples: + +contrib: +- added latest MNG plugin (0.9.0) by Jason Summers + +doc: +- version numbers +- added autoconf readme +- version numbers in RPM stuff + +makefiles: +- fixed for new file-prefix +- added autoconf/automake/libtool + +----------------------------------------------------------- + +0.9.1 (July 26th 2000) +---------------------- + +in short: + +Second beta release. + +Given the enormous amount of bug-reports (not ;-), this will most likely +be one of the last betas. If things remain upright, the first public release +(1.0.0) is fairly eminent in the weeks to come... + +- added SDL mng player by Ralph Giles to contributions +- fixed timing and added internal buffering for I/O-suspension scenarios +- added get routines for internal display-state variables (frame/layer/playtime) +- changed read-processing for improved I/O-suspension (internal buffering) +- fixed several problems with create- & write-support +- added a load of documentation +- lots of small stuff + +------------------- + +bugfixes: + +core: +- fixed mandatory BACK color to be opaque +- changed mng_display_resume to allow to be called after a suspension + return with MNG_NEEDMOREDATA +- changed comments to indicate modified behavior for timer & suspension breaks +- added variables for go_xxxx processing +- implemented support for freeze/reset/resume & go_xxxx +- added trace-codes/-strings for special display processing +- added variables for improved timing support +- added support for improved timing +- added get routines for internal display variables +- added get/set routines for suspensionmode variable +- added trace-code/-string for get/set suspensionmode +- added trace-codes/-strings for get/set display variables +- added support for improved I/O-suspension +- changed read-processing for improved I/O-suspension +- added trace-code/-string for read_databuffer (I/O-suspension) +- added suspendbuffer constants +- changed EOF processing behavior +- fixed TERM delay processing +- changed pre-draft48 frame_mode=3 to frame_mode=1 +- added callbacks for SAVE/SEEK processing +- added trace-codes/-strings for SAVE/SEEK callbacks +- added variable for NEEDSECTIONWAIT breaks +- added trace-codes/-strings for get/set sectionbreaks +- added NEEDSECTIONWAIT error-code/-string +- added macro + routine to set returncode without calling error callback +- added trace-code/-string for special error routine +- changed default readbuffer size from 1024 to 4200 +- added variable for freeze & reset processing +- fixed storage of images during mng_read() +- fixed support for mng_display() after mng_read() +- added error cleanup processing +- fixed support for mng_display_reset() +- fixed suspension-buffering for 32K+ chunks +- added function to set frame-/layer-count & playtime +- added trace-code/-string for updatemngheader +- added error-code/-string for updatemngheader if not a MNG +- fixed creation-code +- fixed writing of signature +- fixed several chunk-writing routines + +samples: +- fixed the libmng.pas module in line with libmng.h + +contrib: +- added the SDL based mngplay viewer by Ralph Giles + +doc: +- extended the RPM contribution by MATSUURA Takanori +- added libmng.txt, a full description of the library and its usage +- added man-pages for mng(5), jng(5) and libmng(3) + +makefiles: + +----------------------------------------------------------- + +0.9.0 (June 30th 2000) +---------------------- + +in short: + +This is the first beta!!! Yippee!!! + +Thanks to all the people who helped to guide me in the right direction. +You know who you are! + +A special thanks to the guys with early implementations, who stood by and +put up with my whims :-) + +changes over 0.5.3: + +- updated mngplg to 0.4.1 (the latest & greatest) +- changed refresh parameters to 'x,y,width,height' + +----------------------------------------------------------- + +0.5.3 (never released) +---------------------- + +in short: + +This is a working version only; the next release will be 0.9.0 (first Beta!) + +There are a few incompatible changes with previous versions. The userdata +variable has been changed from mng_uint32 to mng_ptr to accomodate 64-bit +systems. For the same reason memory allocation size parameters have been +changed to a mng_size_t type which is a typedef of size_t. + +Thanks to Aleks Jakulin for helping to iron out some 64-bit platform issues! + +- implemented the update-region parameters of the refresh callback +- added support for most common delta-image options +- added an animation-speed modifier +- added an image-level parameter for the processtext callback +- updated mngplg to 0.4.0 (supports JNG, full CMS, and other enhancements!) +- fixed a lot of small things +- added support for PPLT chunk +- fixed to support 64-bit platforms + +------------------- + +bugfixes: + +core: +- added processing of color-info on delta-image +- fixed handling of empty SAVE chunk +- fixed display of stored JNG images +- fixed problem with BASI-IEND as object 0 +- changed the version parameters (obviously) +- added update-region parms for refresh calback +- added Needrefresh parameter +- added initialization of update-region for refresh +- added initialization of Needrefresh parameter +- changed progressive-display processing +- added tracecodes for tracing JPEG progression +- added tracing of JPEG calls +- added Deltaimmediate parm for faster delta-processing +- added extra checks for delta-images +- many changes to support delta-images +- optimized some store_xxx routines +- fixed some small things (as precaution) +- fixed possible trouble if IEND display-processing got broken up +- fixed nasty bug with embedded PNG after delta-image +- added processing of PLTE & tRNS for delta-images +- added processing of PLTE/tRNS & color-info for delta-images in the + ani_objects chain +- fixed problem with color-correction for stored images +- added get/set for speedtype to facilitate testing +- added trace-codes & -strings for get/set speedtype +- added speed-modifier to timing routine +- added get-routine of imagelevel for processtext callback +- added trace-code & -string for get imagelevel +- added administration of imagelevel parameter +- added support for PPLT chunk +- added trace-codes & -strings for PPLT chunk processing +- fixed problem with incorrect gamma-correction +- fixed inclusion of IJG read/write code +- fixed problem with 16-bit GA format +- fixed problem with cheap transparency for 4-bit gray +- fixed display_xxxx routines for interlaced images +- added precaution against faulty iCCP chunks from PS +- changed userdata variable to mng_ptr +- added typedef for mng_size_t +- changed size parameter for memory allocation to mng_size_t +- fixed compiler-warning for non-initialized iB variable +- changed definition for 32-bit ints (64-bit platforms) +- changed definition for mng_handle (64-bit platforms) +- swapped refresh parameters +- fixed initialization routine for new mng_handle type +- added inclusion of stdlib.h for abs() +- fixed some 64-bit warnings +- fixed incompatible return-types + +samples: + +contrib: +- updated mngplg to 0.3.0 (supports JNG & full color-correction!) +- updated mngplg to 0.4.0 (Jason is picking up the pace ;-) + +doc: +- added rpm directory with rpm spec-file (contributed by MATSUURA Takanori) + +makefiles: +- changed makefile.linux to reflect versionnr for shared-lib +- changed makefile.linux to depend on mng_conf.h & mng_types.h + +----------------------------------------------------------- + +0.5.2 (June 10th 2000) +---------------------- + +in short: + +This is the third release for developers +Another milestone since JNG is now fully supported +The next release will most likely be numbered 0.9.0 as the first Beta!! + +Fixed bug 106017 & 106019 +Added many constants regarding chunk-property values +Implemented full JNG support +Added all the error- & trace-strings +Added get/set routines for default ZLIB/IJG parameters +Added a generic makefile for Unix platforms (contributed by Tim Rowley) +Added canvasstyle for separate RGB + A canvas (eg. mozilla-style) +Separated configuration-options into a separate file: "mng_conf.h" +Fixed stuff for generic Unix compilation (contributed by Tim Rowley) +Upgraded to lcms1.0.6 (now supports 16-bit endian-peculiarities) +Added a makefile for Linux ELF & fixed some code-issues to go along with gcc +Added support for suspended input-buffer processing +Implemented the display-routines for RGBA/ARGB/BGRA/ABGR canvasstyles +Implemented the application background-restore functionality +Fixed & tested the mngtree Unix-sample (runs on Linux-RH6.2 with libmng.so) +Upgraded mngplg to v0.2.2 (based on the latest code including JNG) +Fixed a lot of other assorted stuff + +------------------- + +bugfixes: +B003(106017) - fixed problem with being proprietary to BCB +B004(106019) - fixed problem when MNG_SUPPORT_WRITE not defined + +core: +- bumped version-numbers up to 0.5.2 (yeah, really) +- fixed support for IJGSRC6B +- cleaned up some code regarding mixed support-options +- complemented constants for chunk-property values +- fixed MNG_UINT_pHYg value +- implemented JNG support +- fixed problem with DEFI clipping +- added error telltale strings & support +- added trace telltale strings & support +- added support for global color-chunks inside TERM/LOOP +- added support for global PLTE,tRNS,bKGD inside TERM/LOOP +- added default IJG compression parameters and such +- moved init of default zlib parms to "mng_hlapi.c" +- added init of default IJG parms +- added support for get/set of zlib/IJG default parms +- added tracestrings for global animation color-chunks +- added tracestrings for get/set of default ZLIB/IJG parms +- added tracestrings for global PLTE,tRNS,bKGD +- added framenr/layernr/playtime to object header +- added initialization of framenr/layernr/playtime +- changed ani_create calls not returning object pointer +- create ani objects always (not just inside TERM/LOOP) +- fixed inconsistancy with freeing global iCCP profile +- fixed minor bugs 16-bit pixel-handling +- added object promotion routine (PROM handling) +- added trace-codes & -strings for image-object promotion +- added trace-codes & -strings for delta-image processing +- added error-codes & -strings for delta-image processing +- added support for delta-image processing +- added ani-object routines for delta-image processing +- added delta-image fields +- added compression/filter/interlace fields to object-buffer for + delta-image processing +- added delta-image row-processing routines +- fixed up punctuation in several files (contributed by Tim Rowley) +- removed useless definition in "mng_chunks.h" (contributed by Tim Rowley) +- fixed pointer confusion in "mng_display.c" (contributed by Tim Rowley) +- fixed inclusion for memcpy (contributed by Tim Rowley) +- added mng_int32p (contributed by Tim Rowley) +- added internal delta-image processing callbacks +- separated configuration-options into "mng_conf.h" +- changed to most likely configuration +- added RGB8_A8 canvasstyle +- added getalphaline callback for RGB8_A8 canvasstyle +- fixed some makeup for Linux gcc compile +- implemented app bkgd restore routines +- implemented RGBA8, ARGB8, BGRA8 & ABGR8 display routines +- added support for RGB8_A8 canvasstyle +- added support for suspended input-buffer processing +- added mng_read_resume HLAPI function to support read-suspension +- fixed timer-handling to run with Mozilla (Tim Rowley) +- fixed alpha-handling for alpha canvasstyles +- fixed some compilation-warnings (contrib Jason Morris) + +samples: +- fixed mngview(delphi) to work with the new core +- synchronized libmng.pas(delphi) with the new libmng.h header +- removed the error- & trace-strings from libmng.pas(delphi) +- fixed mngtree(Unix) to compile on Linux (runs with libmng.so) +- added makefile.linux for mngtree(Unix) (tested on RedHat6.2) + +contrib: +- updated mngplg to 0.2.2 (based on latest code; supports JNG!) + +doc: +- this file obviously +- added Tim Rowley as contributing author +- changed the examples.readme doc +- updated the design-schematics in line with the current code + +makefiles: +- changed the directory to "makefiles" to avoid name-conflicts +- added generic Unix makefile (thanks to Tim Rowley) +- added Linux ELF makefile (tested on RedHat6.2) + +----------------------------------------------------------- + +0.5.1 May 16th 2000 +------------------- + +in short: + +This is the second release for developers +It's a bit of a milestone since all the chunk functionality is in place and +functioning (read, examine, create & write) +This version is incompatible with 0.5.0 since some of the callback prototypes +have changed (should be the last time that happens!) +There are a few more samples and even a real contribution! + +Fixed bug 105795 & 105797 +Fixed a mis-alignment in animation-timing +Added chunk-access functions +Finished all chunk-storage routine-bits +Finished all chunk-write routines +Changed the callback prototypes to allow error-reporting back to the library +Fixed some routines to allow for callback error-reporting +Added version-control functions & constants +Added two functions to set display- & sRGB-profile from memory +Moved CRC table to dynamic structure (for improved thread-safety) +Added SAVE & SEEK save&restore functionality +Finished the application-based CMS-callbacks +Fixed a few BCB specifics +Changed the Win32 DLL and samples to use __stdcall +Did some more assorted little changes +Added 2 BCB samples +Added 1 Unix sample +Added the MNG plugin by Jason Summers in the contrib section +Changed some documents to reflect these changes + +------------------- + +bugfixes: +B001(105795) - fixed wrong lcms call & memory-leak for gammatables +B002(105797) - fixed problem with missing sRGB profile + +core: +- changed chunk iteration function +- added chunk access functions +- added version control constants & functions +- changed strict-ANSI stuff +- added set_outputprofile2 & set_srgbprofile2 +- added empty-chunk put-routines +- added version_dll & VERSION_DLL (for consistency) +- added version control explanatory text & samples +- added iteratechunk callback definition +- improved definitions for DLL support +- added 8-bit palette definition +- added general array definitions +- added MNG_NULL definition +- changed most callback prototypes to allow the app + to report errors during callback processing +- added CRC table to main structure (for thread-safety) +- added iPLTEentries for checking hIST-length +- changed palette definition to exported palette-type +- removed frozen indicator +- added create/write indicators +- added eMNGma hack (will be removed in 1.0.0 !!!) +- added TERM animation object pointer (easier reference) +- added saved-data structure for SAVE/SEEK processing +- added some errorcodes +- added application errorcodes (used with callbacks) +- moved chunk-access errorcodes to severity 5 +- added chunk-access function trace-codes +- changed trace to macro for callback error-reporting +- added save_state & restore_state trace-codes +- put in some extra comments +- fixed layout for sBIT, PPLT +- changed write callback definition +- fixed layout for PPLT again (missed deltatype ?!?) +- cleaned up left-over teststuff in the BACK chunk routine +- changed CRC initialization to use dynamic structure + (wasn't thread-safe the old way !) +- filled in many missing sequence&length checks +- filled in many missing chunk-store snippets +- added checks for running animations +- filled remaining write routines +- fixed read_pplt with regard to deltatype +- added callback error-reporting support +- added pre-draft48 support (short MHDR, frame_mode, LOOP) +- fixed chunk-storage bit in several routines +- supplemented the SAVE & SEEK display processing +- added init of iPLTEcount +- changed calling-convention definition +- changed status-handling of display-routines +- added versioning-control routines +- filled the write routine +- fixed frame_delay misalignment +- added sanity check for frozen status +- changed display_mend to reset state to initial or SAVE +- added save_state and restore_state for SAVE/SEEK/TERM + processing +- added process_save & process_seek routines +- changed and filled iterate-chunk function +- added getchunk functions +- added putchunk functions +- added empty-chunk put-routines +- filled application-based color-management routines +- added creatememprofile +- filled the deflatedata routine +- added cleanup of saved-data (SAVE/SEEK processing) +- moved the actual write_graphic functionality from mng_hlapi.c + to it's appropriate function in the mng_write.c module +- moved standard header includes into mng_types.h + (stdlib/mem for mem-mngmt & math for fp gamma-calc) +- added getimgdata & putimgdata functions + +samples: +- fixed mngview(delphi) to work with the new core +- synchronized libmng.pas(delphi) with the new libmng.h header +- added mngtree(bcb) sample +- added bogus(bcb) sample +- added mngtree(unix) sample + +contrib: +- added mngplg 0.1.0 / a MNG plugin for Win32 by Jason Summers + +doc: +- added this changes.readme file +- changed the samples.readme doc accordingly +- changed the contrib.readme doc accordingly + +----------------------------------------------------------- + +0.5.0 May 1st 2000 +------------------ + +in short: + +This is the first developers release. +It's roughly about 60% done. diff --git a/Source/LibMNG/LICENSE b/Source/LibMNG/LICENSE index 5878e32..2b624c0 100644 --- a/Source/LibMNG/LICENSE +++ b/Source/LibMNG/LICENSE @@ -1,57 +1,57 @@ -/* ************************************************************************** */ -/* * * */ -/* * COPYRIGHT NOTICE: * */ -/* * * */ -/* * Copyright (c) 2000-2007 Gerard Juyn (gerard@libmng.com) * */ -/* * [You may insert additional notices after this sentence if you modify * */ -/* * this source] * */ -/* * * */ -/* * For the purposes of this copyright and license, "Contributing Authors" * */ -/* * is defined as the following set of individuals: * */ -/* * * */ -/* * Gerard Juyn * */ -/* * Glenn Randers-Pehrson * */ -/* * * */ -/* * The MNG Library is supplied "AS IS". The Contributing Authors * */ -/* * disclaim all warranties, expressed or implied, including, without * */ -/* * limitation, the warranties of merchantability and of fitness for any * */ -/* * purpose. The Contributing Authors assume no liability for direct, * */ -/* * indirect, incidental, special, exemplary, or consequential damages, * */ -/* * which may result from the use of the MNG Library, even if advised of * */ -/* * the possibility of such damage. * */ -/* * * */ -/* * Permission is hereby granted to use, copy, modify, and distribute this * */ -/* * source code, or portions hereof, for any purpose, without fee, subject * */ -/* * to the following restrictions: * */ -/* * * */ -/* * 1. The origin of this source code must not be misrepresented; * */ -/* * you must not claim that you wrote the original software. * */ -/* * * */ -/* * 2. Altered versions must be plainly marked as such and must not be * */ -/* * misrepresented as being the original source. * */ -/* * * */ -/* * 3. This Copyright notice may not be removed or altered from any source * */ -/* * or altered source distribution. * */ -/* * * */ -/* * The Contributing Authors specifically permit, without fee, and * */ -/* * encourage the use of this source code as a component to supporting * */ -/* * the MNG and JNG file format in commercial products. If you use this * */ -/* * source code in a product, acknowledgment would be highly appreciated. * */ -/* * * */ -/* ************************************************************************** */ -/* * * */ -/* * Parts of this software have been adapted from the libpng package. * */ -/* * Although this library supports all features from the PNG specification * */ -/* * (as MNG descends from it) it does not require the libpng package. * */ -/* * It does require the zlib library and optionally the IJG jpeg library, * */ -/* * and/or the "little-cms" library by Marti Maria (depending on the * */ -/* * inclusion of support for JNG and Full-Color-Management respectively. * */ -/* * * */ -/* * This library's function is primarily to read and display MNG * */ -/* * animations. It is not meant as a full-featured image-editing * */ -/* * component! It does however offer creation and editing functionality * */ -/* * at the chunk level. * */ -/* * (future modifications may include some more support for creation * */ -/* * and or editing) * */ -/* * * */ -/* ************************************************************************** */ +/* ************************************************************************** */ +/* * * */ +/* * COPYRIGHT NOTICE: * */ +/* * * */ +/* * Copyright (c) 2000-2007 Gerard Juyn (gerard@libmng.com) * */ +/* * [You may insert additional notices after this sentence if you modify * */ +/* * this source] * */ +/* * * */ +/* * For the purposes of this copyright and license, "Contributing Authors" * */ +/* * is defined as the following set of individuals: * */ +/* * * */ +/* * Gerard Juyn * */ +/* * Glenn Randers-Pehrson * */ +/* * * */ +/* * The MNG Library is supplied "AS IS". The Contributing Authors * */ +/* * disclaim all warranties, expressed or implied, including, without * */ +/* * limitation, the warranties of merchantability and of fitness for any * */ +/* * purpose. The Contributing Authors assume no liability for direct, * */ +/* * indirect, incidental, special, exemplary, or consequential damages, * */ +/* * which may result from the use of the MNG Library, even if advised of * */ +/* * the possibility of such damage. * */ +/* * * */ +/* * Permission is hereby granted to use, copy, modify, and distribute this * */ +/* * source code, or portions hereof, for any purpose, without fee, subject * */ +/* * to the following restrictions: * */ +/* * * */ +/* * 1. The origin of this source code must not be misrepresented; * */ +/* * you must not claim that you wrote the original software. * */ +/* * * */ +/* * 2. Altered versions must be plainly marked as such and must not be * */ +/* * misrepresented as being the original source. * */ +/* * * */ +/* * 3. This Copyright notice may not be removed or altered from any source * */ +/* * or altered source distribution. * */ +/* * * */ +/* * The Contributing Authors specifically permit, without fee, and * */ +/* * encourage the use of this source code as a component to supporting * */ +/* * the MNG and JNG file format in commercial products. If you use this * */ +/* * source code in a product, acknowledgment would be highly appreciated. * */ +/* * * */ +/* ************************************************************************** */ +/* * * */ +/* * Parts of this software have been adapted from the libpng package. * */ +/* * Although this library supports all features from the PNG specification * */ +/* * (as MNG descends from it) it does not require the libpng package. * */ +/* * It does require the zlib library and optionally the IJG jpeg library, * */ +/* * and/or the "little-cms" library by Marti Maria (depending on the * */ +/* * inclusion of support for JNG and Full-Color-Management respectively. * */ +/* * * */ +/* * This library's function is primarily to read and display MNG * */ +/* * animations. It is not meant as a full-featured image-editing * */ +/* * component! It does however offer creation and editing functionality * */ +/* * at the chunk level. * */ +/* * (future modifications may include some more support for creation * */ +/* * and or editing) * */ +/* * * */ +/* ************************************************************************** */ diff --git a/Source/LibMNG/README b/Source/LibMNG/README index 35b1259..a8e67ca 100644 --- a/Source/LibMNG/README +++ b/Source/LibMNG/README @@ -1,36 +1,36 @@ -libmng 1.0.10 -------------- - -Added provisional ANG and anIM support, and made some minor bugfixes. - -libmng 1.0.9 ------------- - -A number of optimizations in the chunk handling and reader/writer code. -This saves over 20KB on binary footprint! - -Also several bugfixes and a couple of patches bring it another step -closer to perfection.... :-) - -See CHANGELOG for details. - - -Y.T. - -Gerard - - -For more information please visit: - -The official libmng web-site: - http://www.libmng.com/ - -Libmng's community on SourceForge: - https://sourceforge.net/project/?group_id=5635 - -The official MNG homepage: - http://www.libpng.org/pub/mng/ - -The official PNG homepage: - http://www.libpng.org/pub/png/ - +libmng 1.0.10 +------------- + +Added provisional ANG and anIM support, and made some minor bugfixes. + +libmng 1.0.9 +------------ + +A number of optimizations in the chunk handling and reader/writer code. +This saves over 20KB on binary footprint! + +Also several bugfixes and a couple of patches bring it another step +closer to perfection.... :-) + +See CHANGELOG for details. + + +Y.T. + +Gerard + + +For more information please visit: + +The official libmng web-site: + http://www.libmng.com/ + +Libmng's community on SourceForge: + https://sourceforge.net/project/?group_id=5635 + +The official MNG homepage: + http://www.libpng.org/pub/mng/ + +The official PNG homepage: + http://www.libpng.org/pub/png/ + diff --git a/Source/LibMNG/README.autoconf b/Source/LibMNG/README.autoconf index 97167b7..753f7b4 100644 --- a/Source/LibMNG/README.autoconf +++ b/Source/LibMNG/README.autoconf @@ -1,213 +1,213 @@ -********************************************************************** -********************************************************************** - - ***** this is unmaintained ***** - -If you happen to find problems with autoconfiguration and building, -I simply cannot help you. I'm looking for a maintainer that doesn't mind -spending a few minutes every now and then on the next release to make sure -things are still in working order. - -For the moment all autoconf stuff ahs been moved into unmaintained!! - -********************************************************************** -********************************************************************** - - - - -Configuration from CVS -====================== - -If you're using source checked out from CVS, rather than a source -distribution tarball, please be aware that you can use ./autogen.sh in -place of ./configure below. - -Because this is a cross-platform project, the source templates for -the autoconf scripts are sequestered in the 'makefiles' directory. -Running './autogen.sh' will copy them into their conventional places at -the lop level. If you already see the files there, you don't need to -worry about this step. - -Basic Installation -================== - - These are generic installation instructions. - - The `configure' shell script attempts to guess correct values for -various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory of the package. -It may also create one or more `.h' files containing system-dependent -definitions. Finally, it creates a shell script `config.status' that -you can run in the future to recreate the current configuration, a file -`config.cache' that saves the results of its tests to speed up -reconfiguring, and a file `config.log' containing compiler output -(useful mainly for debugging `configure'). - - If you need to do unusual things to compile the package, please try -to figure out how `configure' could check whether to do them, and mail -diffs or instructions to the address given in the `README' so they can -be considered for the next release. If at some point `config.cache' -contains results you don't want to keep, you may remove or edit it. - - The file `configure.in' is used to create `configure' by a program -called `autoconf'. You only need `configure.in' if you want to change -it or regenerate `configure' using a newer version of `autoconf'. - -The simplest way to compile this package is: - - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. If you're - using `csh' on an old version of System V, you might need to type - `sh ./configure' instead to prevent `csh' from trying to execute - `configure' itself. - - Running `configure' takes awhile. While running, it prints some - messages telling which features it is checking for. - - 2. Type `make' to compile the package. - - 3. Optionally, type `make check' to run any self-tests that come with - the package. - - 4. Type `make install' to install the programs and any data files and - documentation. - - 5. You can remove the program binaries and object files from the - source code directory by typing `make clean'. To also remove the - files that `configure' created (so you can compile the package for - a different kind of computer), type `make distclean'. There is - also a `make maintainer-clean' target, but that is intended mainly - for the package's developers. If you use it, you may have to get - all sorts of other programs in order to regenerate files that came - with the distribution. - -Compilers and Options -===================== - - Some systems require unusual options for compilation or linking that -the `configure' script does not know about. You can give `configure' -initial values for variables by setting them in the environment. Using -a Bourne-compatible shell, you can do that on the command line like -this: - CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure - -Or on systems that have the `env' program, you can do it like this: - env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure - -Compiling For Multiple Architectures -==================================== - - You can compile the package for more than one kind of computer at the -same time, by placing the object files for each architecture in their -own directory. To do this, you must use a version of `make' that -supports the `VPATH' variable, such as GNU `make'. `cd' to the -directory where you want the object files and executables to go and run -the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. - - If you have to use a `make' that does not supports the `VPATH' -variable, you have to compile the package for one architecture at a time -in the source code directory. After you have installed the package for -one architecture, use `make distclean' before reconfiguring for another -architecture. - -Installation Names -================== - - By default, `make install' will install the package's files in -`/usr/local/bin', `/usr/local/man', etc. You can specify an -installation prefix other than `/usr/local' by giving `configure' the -option `--prefix=PATH'. - - You can specify separate installation prefixes for -architecture-specific files and architecture-independent files. If you -give `configure' the option `--exec-prefix=PATH', the package will use -PATH as the prefix for installing programs and libraries. -Documentation and other data files will still use the regular prefix. - - In addition, if you use an unusual directory layout you can give -options like `--bindir=PATH' to specify different values for particular -kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. - - If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving `configure' the -option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. - -Optional Features -================= - - Some packages pay attention to `--enable-FEATURE' options to -`configure', where FEATURE indicates an optional part of the package. -They may also pay attention to `--with-PACKAGE' options, where PACKAGE -is something like `gnu-as' or `x' (for the X Window System). The -`README' should mention any `--enable-' and `--with-' options that the -package recognizes. - - For packages that use the X Window System, `configure' can usually -find the X include and library files automatically, but if it doesn't, -you can use the `configure' options `--x-includes=DIR' and -`--x-libraries=DIR' to specify their locations. - -Specifying the System Type -========================== - - There may be some features `configure' can not figure out -automatically, but needs to determine by the type of host the package -will run on. Usually `configure' can figure that out, but if it prints -a message saying it can not guess the host type, give it the -`--host=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name with three fields: - CPU-COMPANY-SYSTEM - -See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't -need to know the host type. - - If you are building compiler tools for cross-compiling, you can also -use the `--target=TYPE' option to select the type of system they will -produce code for and the `--build=TYPE' option to select the type of -system on which you are compiling the package. - -Sharing Defaults -================ - - If you want to set default values for `configure' scripts to share, -you can create a site shell script called `config.site' that gives -default values for variables like `CC', `cache_file', and `prefix'. -`configure' looks for `PREFIX/share/config.site' if it exists, then -`PREFIX/etc/config.site' if it exists. Or, you can set the -`CONFIG_SITE' environment variable to the location of the site script. -A warning: not all `configure' scripts look for a site script. - -Operation Controls -================== - - `configure' recognizes the following options to control how it -operates. - -`--cache-file=FILE' - Use and save the results of the tests in FILE instead of - `./config.cache'. Set FILE to `/dev/null' to disable caching, for - debugging `configure'. - -`--help' - Print a summary of the options to `configure', and exit. - -`--quiet' -`--silent' -`-q' - Do not print messages saying which checks are being made. To - suppress all normal output, redirect it to `/dev/null' (any error - messages will still be shown). - -`--srcdir=DIR' - Look for the package's source code in directory DIR. Usually - `configure' can determine that directory automatically. - -`--version' - Print the version of Autoconf used to generate the `configure' - script, and exit. - -`configure' also accepts some other, not widely useful, options. +********************************************************************** +********************************************************************** + + ***** this is unmaintained ***** + +If you happen to find problems with autoconfiguration and building, +I simply cannot help you. I'm looking for a maintainer that doesn't mind +spending a few minutes every now and then on the next release to make sure +things are still in working order. + +For the moment all autoconf stuff ahs been moved into unmaintained!! + +********************************************************************** +********************************************************************** + + + + +Configuration from CVS +====================== + +If you're using source checked out from CVS, rather than a source +distribution tarball, please be aware that you can use ./autogen.sh in +place of ./configure below. + +Because this is a cross-platform project, the source templates for +the autoconf scripts are sequestered in the 'makefiles' directory. +Running './autogen.sh' will copy them into their conventional places at +the lop level. If you already see the files there, you don't need to +worry about this step. + +Basic Installation +================== + + These are generic installation instructions. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, a file +`config.cache' that saves the results of its tests to speed up +reconfiguring, and a file `config.log' containing compiler output +(useful mainly for debugging `configure'). + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If at some point `config.cache' +contains results you don't want to keep, you may remove or edit it. + + The file `configure.in' is used to create `configure' by a program +called `autoconf'. You only need `configure.in' if you want to change +it or regenerate `configure' using a newer version of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. If you're + using `csh' on an old version of System V, you might need to type + `sh ./configure' instead to prevent `csh' from trying to execute + `configure' itself. + + Running `configure' takes awhile. While running, it prints some + messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + +Compilers and Options +===================== + + Some systems require unusual options for compilation or linking that +the `configure' script does not know about. You can give `configure' +initial values for variables by setting them in the environment. Using +a Bourne-compatible shell, you can do that on the command line like +this: + CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure + +Or on systems that have the `env' program, you can do it like this: + env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure + +Compiling For Multiple Architectures +==================================== + + You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you must use a version of `make' that +supports the `VPATH' variable, such as GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + If you have to use a `make' that does not supports the `VPATH' +variable, you have to compile the package for one architecture at a time +in the source code directory. After you have installed the package for +one architecture, use `make distclean' before reconfiguring for another +architecture. + +Installation Names +================== + + By default, `make install' will install the package's files in +`/usr/local/bin', `/usr/local/man', etc. You can specify an +installation prefix other than `/usr/local' by giving `configure' the +option `--prefix=PATH'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +give `configure' the option `--exec-prefix=PATH', the package will use +PATH as the prefix for installing programs and libraries. +Documentation and other data files will still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=PATH' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + + Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + + There may be some features `configure' can not figure out +automatically, but needs to determine by the type of host the package +will run on. Usually `configure' can figure that out, but if it prints +a message saying it can not guess the host type, give it the +`--host=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name with three fields: + CPU-COMPANY-SYSTEM + +See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the host type. + + If you are building compiler tools for cross-compiling, you can also +use the `--target=TYPE' option to select the type of system they will +produce code for and the `--build=TYPE' option to select the type of +system on which you are compiling the package. + +Sharing Defaults +================ + + If you want to set default values for `configure' scripts to share, +you can create a site shell script called `config.site' that gives +default values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Operation Controls +================== + + `configure' recognizes the following options to control how it +operates. + +`--cache-file=FILE' + Use and save the results of the tests in FILE instead of + `./config.cache'. Set FILE to `/dev/null' to disable caching, for + debugging `configure'. + +`--help' + Print a summary of the options to `configure', and exit. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`--version' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`configure' also accepts some other, not widely useful, options. diff --git a/Source/LibMNG/README.config b/Source/LibMNG/README.config index 97fcb31..d5cd454 100644 --- a/Source/LibMNG/README.config +++ b/Source/LibMNG/README.config @@ -1,104 +1,104 @@ -Configuration options in libmng -=============================== - -The library is fairly configurable through the use of a number of defines. -Please note however that certain defines are for internal use only. -The following list gives a summary of options that can be used externally to -define the functionality of the library: - -======================================== - -#define MNG_BUILD_DLL - -This is used to indicate that a "standard" DLL should result from compiling -the library. Please note the remarks in README.dll if you intend to work -with the library as a DLL. The purpose of this option is to ensure that -DLL builds have the same set of functions. - -#define MNG_BUILD_SO - -This is used to indicate that a "standard" shared library (SO) should result -from a compilation. The purpose of this option is to ensure that all -shared libraries generated this way will have the same set of functions. - -#define MNG_USE_DLL / #define MNG_USE_SO - -These should be used when including the library header in the compilation -of an application to indicate that the compiler/linker must take the -necessary steps to make the binary executable to use the standard DLL -or shared library (SO). - -#define MNG_SKIP_ZLIB / #define MNG_SKIP_LCMS / #define MNG_SKIP_IJG6B - -Use these in conjunction with MNG_USE_DLL / MNG_USE_SO. This is useful if -you only need the external definitions of the MNG library and not the others, -which will speed up the compilation process. - -#define MNG_SUPPORT_FULL / #define MNG_SUPPORT_LC / #define MNG_SUPPORT_VLC - -These can be used to indicate the level of MNG spec compliance required. -Currently only full MNG compliance is supported. - -#define MNG_SUPPORT_IJG6B - -This can be used to indicate if JNG support is required. This option will -include the IJG JPEG-library. Note that MNG_SUPPORT_FULL will automatically -set this option. Use this only if you need JNG support with MNG-(V)LC. - -#define MNG_FULL_CMS / #define MNG_GAMMA_ONLY / #define MNG_NO_CMS / -#define MNG_APP_CMS - -These indicate the color-correction support level of the library. -If you are on a platform that supports lcms (Little CMS by Marti Maria Saguar) -then it is highly recommended to define MNG_FULL_CMS. -If your platform has it's own CMS then select MNG_APP_CMS and be sure to -include the appropriate callbacks in your app. -In all other cases it is recommended to define MNG_GAMMA_ONLY. - -#define MNG_SUPPORT_READ / #define MNG_SUPPORT_WRITE / -#define MNG_SUPPORT_DISPLAY - -These indicate the high-level support for reading, writing and/or -displaying files. Note that in order to display a file, you'll need to read -it first. (yes, really!) - -#define MNG_STORE_CHUNKS - -This indicates that the library should store chunk-information when reading -a file. This information can then be processed through the -MNG_ITERATE_CHUNKS() function. Note that you must specify this option if -you want to create and write a new file. - -#define MNG_ACCESS_CHUNKS - -This is used to indicate that the app may need access to internally stored -chunk information. MNG_STORE_CHUNKS must be defined as well for this option -to function properly. - -#define MNG_INTERNAL_MEMMNGMT - -You can use this to have the library handle it's own memory allocation and -deallocation through the "standard" memory functions. This option is turned -off by default, which means your app must define the memory callbacks. - -#define MNG_ERROR_TELLTALE - -Set this on to allow human-readable error-messages to be included in the -library and the error function and callback. - -#define MNG_BIGENDIAN_SUPPORTED - -This option should be used to indicate the hardware is based on big endian -integers. - -#define MNG_SUPPORT_TRACE / #define MNG_TRACE_TELLTALE - -These two can be used when debugging an app. You'll need to have the trace -callback setup also. This allows for a rather thorough investigation of the -libraries function paths. - -======================================== - -Any other optional defines you may encounter are for internal use only. -please do not specify them externally. In case of doubt, consult the -support email lists. More info can be found on http://www.libmng.com +Configuration options in libmng +=============================== + +The library is fairly configurable through the use of a number of defines. +Please note however that certain defines are for internal use only. +The following list gives a summary of options that can be used externally to +define the functionality of the library: + +======================================== + +#define MNG_BUILD_DLL + +This is used to indicate that a "standard" DLL should result from compiling +the library. Please note the remarks in README.dll if you intend to work +with the library as a DLL. The purpose of this option is to ensure that +DLL builds have the same set of functions. + +#define MNG_BUILD_SO + +This is used to indicate that a "standard" shared library (SO) should result +from a compilation. The purpose of this option is to ensure that all +shared libraries generated this way will have the same set of functions. + +#define MNG_USE_DLL / #define MNG_USE_SO + +These should be used when including the library header in the compilation +of an application to indicate that the compiler/linker must take the +necessary steps to make the binary executable to use the standard DLL +or shared library (SO). + +#define MNG_SKIP_ZLIB / #define MNG_SKIP_LCMS / #define MNG_SKIP_IJG6B + +Use these in conjunction with MNG_USE_DLL / MNG_USE_SO. This is useful if +you only need the external definitions of the MNG library and not the others, +which will speed up the compilation process. + +#define MNG_SUPPORT_FULL / #define MNG_SUPPORT_LC / #define MNG_SUPPORT_VLC + +These can be used to indicate the level of MNG spec compliance required. +Currently only full MNG compliance is supported. + +#define MNG_SUPPORT_IJG6B + +This can be used to indicate if JNG support is required. This option will +include the IJG JPEG-library. Note that MNG_SUPPORT_FULL will automatically +set this option. Use this only if you need JNG support with MNG-(V)LC. + +#define MNG_FULL_CMS / #define MNG_GAMMA_ONLY / #define MNG_NO_CMS / +#define MNG_APP_CMS + +These indicate the color-correction support level of the library. +If you are on a platform that supports lcms (Little CMS by Marti Maria Saguar) +then it is highly recommended to define MNG_FULL_CMS. +If your platform has it's own CMS then select MNG_APP_CMS and be sure to +include the appropriate callbacks in your app. +In all other cases it is recommended to define MNG_GAMMA_ONLY. + +#define MNG_SUPPORT_READ / #define MNG_SUPPORT_WRITE / +#define MNG_SUPPORT_DISPLAY + +These indicate the high-level support for reading, writing and/or +displaying files. Note that in order to display a file, you'll need to read +it first. (yes, really!) + +#define MNG_STORE_CHUNKS + +This indicates that the library should store chunk-information when reading +a file. This information can then be processed through the +MNG_ITERATE_CHUNKS() function. Note that you must specify this option if +you want to create and write a new file. + +#define MNG_ACCESS_CHUNKS + +This is used to indicate that the app may need access to internally stored +chunk information. MNG_STORE_CHUNKS must be defined as well for this option +to function properly. + +#define MNG_INTERNAL_MEMMNGMT + +You can use this to have the library handle it's own memory allocation and +deallocation through the "standard" memory functions. This option is turned +off by default, which means your app must define the memory callbacks. + +#define MNG_ERROR_TELLTALE + +Set this on to allow human-readable error-messages to be included in the +library and the error function and callback. + +#define MNG_BIGENDIAN_SUPPORTED + +This option should be used to indicate the hardware is based on big endian +integers. + +#define MNG_SUPPORT_TRACE / #define MNG_TRACE_TELLTALE + +These two can be used when debugging an app. You'll need to have the trace +callback setup also. This allows for a rather thorough investigation of the +libraries function paths. + +======================================== + +Any other optional defines you may encounter are for internal use only. +please do not specify them externally. In case of doubt, consult the +support email lists. More info can be found on http://www.libmng.com diff --git a/Source/LibMNG/README.contrib b/Source/LibMNG/README.contrib index 2d51ac5..9b28753 100644 --- a/Source/LibMNG/README.contrib +++ b/Source/LibMNG/README.contrib @@ -1,95 +1,95 @@ -The contrib directory contains contributions made by fellow -enthousiasts. (Check respective web-sites for the latest version) - ----------------------------------------------------------------------- - -mngplg - A Netscape plugin for MNG - by Jason Summers - -http://pobox.com/~jason1/imaging/mngplg/ - -The very first contribution, and what a start! -GIF look out, MNG is on the prowl and ready to swat you like a fly! - ----------------------------------------------------------------------- - -mngplay - An SDL based MNG viewer - by Ralph Giles - -http://snow.ashlu.bc.ca/~giles/mng/ - -Another nice contribution. View MNG files on practically any platform -with this standalone viewer. -Source-code only; Requires SDL library and libmng.so - -(Modified by Greg Roelofs) - ----------------------------------------------------------------------- - -mngview - A BCB port of the Delphi sample - by Andy Protano - -I have added this nice little port to the BCB samples directory. -It adds a nifty progressbar while reading a file. Excellent work! -Requires libmng.dll -(note: this is in the BCB samples directory) - ----------------------------------------------------------------------- - -mngdump - A BCB GUI-based dump utility - by Andy Protano - -Andy has sent me this fully functional MNG dump utility, that gives -detailed information of the contents of any MNG file. -Requires libmng.dll - ----------------------------------------------------------------------- - -mng-view - A GTK-based MNG viewer - by Vova Babin - -Vova has been hacking away with the libmng code and has come up with -this nice little sample how to write a MNG viewer using GTK. -Thanks mate! -Source-code only -Requires GTK+ (1.2 or higher) and libmng (0.9.2 or higher) - -(Modified by Greg Roelofs) - ----------------------------------------------------------------------- - -mngview - Another MNG viewer; this one for MSVC - by Nicholaus Brennig - -A welcome contribution from Nicholaus. Author of SlowView. A very nice -image-handling utility for Windows. A welcome contribution since there -have been numerous questions about linking libmng with MSVC. -Well, look no further. Here it is! - ----------------------------------------------------------------------- - -MSVC libmng project - An MSVC project to build libmng.dll - - by Chad Austin - -Chad has contributed some project-files that you could use to build -libmng.dll with MSVC. Please be sure to read the README file included. - ----------------------------------------------------------------------- - -fbmngplay - A simple fbcon based mng player - by Stefan Reinauer - -Stefan has contributed this little example, based on Ralph's -SDL player. It uses the kernel framebuffer device to display mng -animations through the libmng interface. -(currently for 16-bit buffers only) - ----------------------------------------------------------------------- - -xmngview - Lesstif/Motif standalone player for MNG files - - by Winfried Szukalski - -Winfried contributed this MNG player for X-based systems. -(recently updated) - ----------------------------------------------------------------------- - -makemng - A delta-MNG creation utility for MSVC - by Alex Volkov - -Alex sent me this nice utility that will allow you to create highly -optmized MNGs using the delta-PNG capabilities of MNG. - ----------------------------------------------------------------------- +The contrib directory contains contributions made by fellow +enthousiasts. (Check respective web-sites for the latest version) + +---------------------------------------------------------------------- + +mngplg - A Netscape plugin for MNG - by Jason Summers + +http://pobox.com/~jason1/imaging/mngplg/ + +The very first contribution, and what a start! +GIF look out, MNG is on the prowl and ready to swat you like a fly! + +---------------------------------------------------------------------- + +mngplay - An SDL based MNG viewer - by Ralph Giles + +http://snow.ashlu.bc.ca/~giles/mng/ + +Another nice contribution. View MNG files on practically any platform +with this standalone viewer. +Source-code only; Requires SDL library and libmng.so + +(Modified by Greg Roelofs) + +---------------------------------------------------------------------- + +mngview - A BCB port of the Delphi sample - by Andy Protano + +I have added this nice little port to the BCB samples directory. +It adds a nifty progressbar while reading a file. Excellent work! +Requires libmng.dll +(note: this is in the BCB samples directory) + +---------------------------------------------------------------------- + +mngdump - A BCB GUI-based dump utility - by Andy Protano + +Andy has sent me this fully functional MNG dump utility, that gives +detailed information of the contents of any MNG file. +Requires libmng.dll + +---------------------------------------------------------------------- + +mng-view - A GTK-based MNG viewer - by Vova Babin + +Vova has been hacking away with the libmng code and has come up with +this nice little sample how to write a MNG viewer using GTK. +Thanks mate! +Source-code only +Requires GTK+ (1.2 or higher) and libmng (0.9.2 or higher) + +(Modified by Greg Roelofs) + +---------------------------------------------------------------------- + +mngview - Another MNG viewer; this one for MSVC - by Nicholaus Brennig + +A welcome contribution from Nicholaus. Author of SlowView. A very nice +image-handling utility for Windows. A welcome contribution since there +have been numerous questions about linking libmng with MSVC. +Well, look no further. Here it is! + +---------------------------------------------------------------------- + +MSVC libmng project - An MSVC project to build libmng.dll + - by Chad Austin + +Chad has contributed some project-files that you could use to build +libmng.dll with MSVC. Please be sure to read the README file included. + +---------------------------------------------------------------------- + +fbmngplay - A simple fbcon based mng player - by Stefan Reinauer + +Stefan has contributed this little example, based on Ralph's +SDL player. It uses the kernel framebuffer device to display mng +animations through the libmng interface. +(currently for 16-bit buffers only) + +---------------------------------------------------------------------- + +xmngview - Lesstif/Motif standalone player for MNG files + - by Winfried Szukalski + +Winfried contributed this MNG player for X-based systems. +(recently updated) + +---------------------------------------------------------------------- + +makemng - A delta-MNG creation utility for MSVC - by Alex Volkov + +Alex sent me this nice utility that will allow you to create highly +optmized MNGs using the delta-PNG capabilities of MNG. + +---------------------------------------------------------------------- diff --git a/Source/LibMNG/README.examples b/Source/LibMNG/README.examples index 9f23b50..1ba94c1 100644 --- a/Source/LibMNG/README.examples +++ b/Source/LibMNG/README.examples @@ -1,48 +1,48 @@ -The samples are in platform-specific directories. - -!!! contributions are very welcome !!! - - -bcb - Borland C++ Builder (3.0) (found under bcb/xxx) ------------------------------------------------------ - -win32dll - sample project to create a Windows dll. Requires zlib1.2.1, - IJG jpgsrc6b and lcms1.0.14. The directories containing these - libraries must be at the same level as the libmng directory. - So if you're in the directory with this file and the libmng - sources, they should be in ..\zlib , ..\jpgsrc6b and ..\lcms - respectively. - -!!! To run the other Win32 samples you need to copy the libmng.dll - file from here into the sample's directory !!! - -mngtree - sample project to create a little command-line tool that dumps - the chunk-structure of a given file onto stdout. - -bogus - a completely bogus example on how to create a perfectly valid - (though slightly biased) MNG. - -mngview - port of the Delphi mngview sample. contributed by Andy Protano. - see also README.contrib - -mngrepair- an example on how to fix invalid MNG files - uses the new mng_copy_chunks() function and MNG_SOFTERRORS to - 'ignore' certain input-errors. This conditional *MUST* only be used - for exactly this kind of software; eg. repair utilities. - - -delphi - Borland Delphi (3.0+) (found under contrib/delphi/xxx) ---------------------------------------------------------------- - -mngview - sample project for a simple mng-viewer. The general unit in - the delphi directory was translated from libmng.h It can be - used in other projects to access libmng.dll created with the - win32dll example above. - - -unix - Unix (found under contrib/gcc/xxx) ------------------------------------------ - -mngtree - basically a copy of the BCB sample. It includes a makefile for - Linux and it's been tested on RedHat6.2 - +The samples are in platform-specific directories. + +!!! contributions are very welcome !!! + + +bcb - Borland C++ Builder (3.0) (found under bcb/xxx) +----------------------------------------------------- + +win32dll - sample project to create a Windows dll. Requires zlib1.2.1, + IJG jpgsrc6b and lcms1.0.14. The directories containing these + libraries must be at the same level as the libmng directory. + So if you're in the directory with this file and the libmng + sources, they should be in ..\zlib , ..\jpgsrc6b and ..\lcms + respectively. + +!!! To run the other Win32 samples you need to copy the libmng.dll + file from here into the sample's directory !!! + +mngtree - sample project to create a little command-line tool that dumps + the chunk-structure of a given file onto stdout. + +bogus - a completely bogus example on how to create a perfectly valid + (though slightly biased) MNG. + +mngview - port of the Delphi mngview sample. contributed by Andy Protano. + see also README.contrib + +mngrepair- an example on how to fix invalid MNG files + uses the new mng_copy_chunks() function and MNG_SOFTERRORS to + 'ignore' certain input-errors. This conditional *MUST* only be used + for exactly this kind of software; eg. repair utilities. + + +delphi - Borland Delphi (3.0+) (found under contrib/delphi/xxx) +--------------------------------------------------------------- + +mngview - sample project for a simple mng-viewer. The general unit in + the delphi directory was translated from libmng.h It can be + used in other projects to access libmng.dll created with the + win32dll example above. + + +unix - Unix (found under contrib/gcc/xxx) +----------------------------------------- + +mngtree - basically a copy of the BCB sample. It includes a makefile for + Linux and it's been tested on RedHat6.2 + diff --git a/Source/LibMNG/README.footprint b/Source/LibMNG/README.footprint index ae47da2..34dba7f 100644 --- a/Source/LibMNG/README.footprint +++ b/Source/LibMNG/README.footprint @@ -1,46 +1,46 @@ -/* - You can use one or more of the following defines to - reduce the size of the compiled library. Define the - SKIPCANVAS macros for any canvas configurations that - your application doesn't use. Define the SKIPCHUNK - macros for any chunks that your application doesn't - process. Define MNG_OPTIMIZE_FOOTPRINT to choose - smaller code size over faster execution and less memory - usage. These macros became available in version 1.0.6. -*/ - -/* eliminate unused features from libmng */ -#define MNG_OPTIMIZE_FOOTPRINT -#define MNG_OPTIMIZE_OBJCLEANUP -#define MNG_OPTIMIZE_CHUNKINITFREE -#define MNG_OPTIMIZE_CHUNKASSIGN -#define MNG_OPTIMIZE_CHUNKREADER - -#define MNG_SKIPCANVAS_ABGR8 -#define MNG_SKIPCANVAS_ARGB8 -#define MNG_SKIPCANVAS_BGR8 -#define MNG_SKIPCANVAS_BGRA8 -#define MNG_SKIPCANVAS_BGRA8_PM -#define MNG_SKIPCANVAS_BGRX8 -#define MNG_SKIPCANVAS_RGBA8 -#define MNG_SKIPCANVAS_BGR565 -#define MNG_SKIPCANVAS_RGB565 -#define MNG_SKIPCANVAS_BGRA565 -#define MNG_SKIPCANVAS_RGBA565 - -#define MNG_SKIPCHUNK_iCCP -#define MNG_SKIPCHUNK_tEXt -#define MNG_SKIPCHUNK_zTXt -#define MNG_SKIPCHUNK_iTXt -#define MNG_SKIPCHUNK_bKGD -#define MNG_SKIPCHUNK_pHYs -#define MNG_SKIPCHUNK_sBIT -#define MNG_SKIPCHUNK_sPLT -#define MNG_SKIPCHUNK_hIST -#define MNG_SKIPCHUNK_tIME -#define MNG_SKIPCHUNK_eXPI -#define MNG_SKIPCHUNK_fPRI -#define MNG_SKIPCHUNK_nEED -#define MNG_SKIPCHUNK_pHYg - - +/* + You can use one or more of the following defines to + reduce the size of the compiled library. Define the + SKIPCANVAS macros for any canvas configurations that + your application doesn't use. Define the SKIPCHUNK + macros for any chunks that your application doesn't + process. Define MNG_OPTIMIZE_FOOTPRINT to choose + smaller code size over faster execution and less memory + usage. These macros became available in version 1.0.6. +*/ + +/* eliminate unused features from libmng */ +#define MNG_OPTIMIZE_FOOTPRINT +#define MNG_OPTIMIZE_OBJCLEANUP +#define MNG_OPTIMIZE_CHUNKINITFREE +#define MNG_OPTIMIZE_CHUNKASSIGN +#define MNG_OPTIMIZE_CHUNKREADER + +#define MNG_SKIPCANVAS_ABGR8 +#define MNG_SKIPCANVAS_ARGB8 +#define MNG_SKIPCANVAS_BGR8 +#define MNG_SKIPCANVAS_BGRA8 +#define MNG_SKIPCANVAS_BGRA8_PM +#define MNG_SKIPCANVAS_BGRX8 +#define MNG_SKIPCANVAS_RGBA8 +#define MNG_SKIPCANVAS_BGR565 +#define MNG_SKIPCANVAS_RGB565 +#define MNG_SKIPCANVAS_BGRA565 +#define MNG_SKIPCANVAS_RGBA565 + +#define MNG_SKIPCHUNK_iCCP +#define MNG_SKIPCHUNK_tEXt +#define MNG_SKIPCHUNK_zTXt +#define MNG_SKIPCHUNK_iTXt +#define MNG_SKIPCHUNK_bKGD +#define MNG_SKIPCHUNK_pHYs +#define MNG_SKIPCHUNK_sBIT +#define MNG_SKIPCHUNK_sPLT +#define MNG_SKIPCHUNK_hIST +#define MNG_SKIPCHUNK_tIME +#define MNG_SKIPCHUNK_eXPI +#define MNG_SKIPCHUNK_fPRI +#define MNG_SKIPCHUNK_nEED +#define MNG_SKIPCHUNK_pHYg + + diff --git a/Source/LibMNG/README.packaging b/Source/LibMNG/README.packaging index 32fb2da..da0db3e 100644 --- a/Source/LibMNG/README.packaging +++ b/Source/LibMNG/README.packaging @@ -1,24 +1,24 @@ -Packaging Libmng for distribution ---------------------------------- - -These are some notes for those building binaries for distribution. - -We're interested to hear about anywhere libmng is helpful, so let us -know if you're including it with your application or OS. Also, if your -build is publicly accessible, we'd be happy to link to it from -the libmng site. - -However, We respectfully request that you *not* distribute binaries as a -shared library (DLL) with any of the major features disabled. While -there is support for this in terms of #ifdef directives (in -libmng_conf.h) and autoconf switches they are intended for embedded -application and testing. The default compilation options support the -full MNG specification, and we wish to avoid the confusion among -general users that partial support would engender. - - -Platform specific notes: - -We have a basic .spec file for generating rpms. Send us a note if you'd -like to clean it up. - +Packaging Libmng for distribution +--------------------------------- + +These are some notes for those building binaries for distribution. + +We're interested to hear about anywhere libmng is helpful, so let us +know if you're including it with your application or OS. Also, if your +build is publicly accessible, we'd be happy to link to it from +the libmng site. + +However, We respectfully request that you *not* distribute binaries as a +shared library (DLL) with any of the major features disabled. While +there is support for this in terms of #ifdef directives (in +libmng_conf.h) and autoconf switches they are intended for embedded +application and testing. The default compilation options support the +full MNG specification, and we wish to avoid the confusion among +general users that partial support would engender. + + +Platform specific notes: + +We have a basic .spec file for generating rpms. Send us a note if you'd +like to clean it up. + diff --git a/Source/LibMNG/_FI_3151_PluginMNG.cpp b/Source/LibMNG/_FI_3151_PluginMNG.cpp index 775b126..ea48575 100644 --- a/Source/LibMNG/_FI_3151_PluginMNG.cpp +++ b/Source/LibMNG/_FI_3151_PluginMNG.cpp @@ -1,312 +1,312 @@ -// ========================================================== -// MNG Loader -// -// Design and implementation by -// - Floris van den Berg (flvdberg@wxs.nl) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" - -#include "../LibMNG/libmng.h" -//#include "../LibMNG/libmng_data.h" - -// ========================================================== -// Plugin Interface -// ========================================================== - -static int s_format_id; - -// ---------------------------------------------------------- -// Constants + headers -// ---------------------------------------------------------- - -typedef struct { - FIBITMAP *bitmap; // pointer to the bitmap data - FreeImageIO *io; // pointer to the io functions - fi_handle file; // pointer to the file we're decoding -} mngstuff; - -// ---------------------------------------------------------- -// Callbacks for the mng decoder -// ---------------------------------------------------------- - -mng_ptr -mymngalloc(mng_size_t size) { - return (mng_ptr)calloc(1, size); -} - -void -mymngfree(mng_ptr p, mng_size_t size) { - free(p); -} - -mng_bool -mymngopenstream(mng_handle mng) { - // since the user is responsible for opening and closing the file, - // we leave the default implementation open - - return MNG_TRUE; -} - -mng_bool -mymngclosestream(mng_handle mng) { - // since the user is responsible for opening and closing the file, - // we leave the default implementation open - - return MNG_TRUE; -} - -mng_bool -mymngreadstream(mng_handle mng, mng_ptr buffer, mng_uint32 size, mng_uint32 *bytesread) { - mngstuff *mymng = (mngstuff *)mng_get_userdata(mng); - - *bytesread = mymng->io->read_proc(buffer, 1, size, mymng->file); - - return MNG_TRUE; -} - -mng_bool -mymngprocessheader(mng_handle mng, mng_uint32 width, mng_uint32 height) { - mngstuff *client_data = (mngstuff *)mng_get_userdata(mng); - BYTE bHasAlpha = mng_get_alphadepth(mng); - -#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB - if(bHasAlpha) { - // allocate a bitmap with the given dimensions - FIBITMAP *bitmap = FreeImage_Allocate(width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - client_data->bitmap = bitmap; - // tell the mng decoder about our bit-depth choice - mng_set_canvasstyle(mng, MNG_CANVAS_RGBA8); - } else { - // allocate a bitmap with the given dimensions - FIBITMAP *bitmap = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - client_data->bitmap = bitmap; - // tell the mng decoder about our bit-depth choice - mng_set_canvasstyle(mng, MNG_CANVAS_RGB8); - } -#else - if(bHasAlpha) { - // allocate a bitmap with the given dimensions - FIBITMAP *bitmap = FreeImage_Allocate(width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - client_data->bitmap = bitmap; - // tell the mng decoder about our bit-depth choice - mng_set_canvasstyle(mng, MNG_CANVAS_BGRA8); - } else { - // allocate a bitmap with the given dimensions - FIBITMAP *bitmap = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - client_data->bitmap = bitmap; - // tell the mng decoder about our bit-depth choice - mng_set_canvasstyle(mng, MNG_CANVAS_BGR8); - } -#endif // FREEIMAGE_COLORORDER_RGB - - return client_data->bitmap ? MNG_TRUE : MNG_FALSE; -} - -mng_ptr -mymnggetcanvasline(mng_handle mng, mng_uint32 line) { - FIBITMAP *bitmap = ((mngstuff *)mng_get_userdata(mng))->bitmap; - - return FreeImage_GetScanLine(bitmap, FreeImage_GetHeight(bitmap) - line - 1); -} - -mng_bool -mymngrefresh(mng_handle mng, mng_uint32 x, mng_uint32 y, mng_uint32 w, mng_uint32 h) { - return MNG_TRUE; -} - -mng_uint32 -mymnggetticks(mng_handle mng) { - return 0; -} - -mng_bool -mymngsettimer(mng_handle mng, mng_uint32 msecs) { - return MNG_TRUE; -} - -mng_bool -mymngerror(mng_handle mng, mng_int32 code, mng_int8 severity, mng_chunkid chunktype, mng_uint32 chunkseq, mng_int32 extra1, mng_int32 extra2, mng_pchar text) { - char msg[256]; - if((code == MNG_SEQUENCEERROR) && (chunktype == MNG_UINT_TERM)) { - // ignore sequence error for TERM - return MNG_TRUE; - } - if(text) { - // text can be null depending on compiler options - sprintf(msg, "Error reported by libmng (%d)\r\n\r\n%s", code, text); - } else { - sprintf(msg, "Error %d reported by libmng", code); - } - FreeImage_OutputMessageProc(s_format_id, msg); - return MNG_FALSE; -} - -// ========================================================== -// Plugin Implementation -// ========================================================== - -static const char * DLL_CALLCONV -Format() { - return "MNG"; -} - -static const char * DLL_CALLCONV -Description() { - return "Multiple Network Graphics"; -} - -static const char * DLL_CALLCONV -Extension() { - return "mng"; -} - -static const char * DLL_CALLCONV -RegExpr() { - return NULL; -} - -static const char * DLL_CALLCONV -MimeType() { - return "video/x-mng"; -} - -static BOOL DLL_CALLCONV -SupportsExportDepth(int depth) { - return FALSE; -} - -static BOOL DLL_CALLCONV -SupportsExportType(FREE_IMAGE_TYPE type) { - return FALSE; -} - -// ---------------------------------------------------------- - -static void * DLL_CALLCONV -Open(FreeImageIO *io, fi_handle handle, BOOL read) { - mngstuff *mymng = (mngstuff *)calloc(1, sizeof(*mymng)); - mymng->io = io; - mymng->file = handle; - - return mymng; -} - -static void DLL_CALLCONV -Close(FreeImageIO *io, fi_handle handle, void *data) { - free((mngstuff *)data); -} - -// ---------------------------------------------------------- - -static FIBITMAP * DLL_CALLCONV -Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { - mng_handle hmng = NULL; - - if (handle != NULL) { - try { - // allocate our stream data structure - mngstuff *mymng = (mngstuff *)data; - - // set up the mng decoder for our stream - hmng = mng_initialize(mymng, mymngalloc, mymngfree, MNG_NULL); - - if (hmng == MNG_NULL) { - throw "could not initialize libmng"; - } - - // set the colorprofile, lcms uses this - mng_set_srgb(hmng, MNG_TRUE ); - // set white as background color - WORD wRed, wGreen, wBlue; - wRed = wGreen = wBlue = (255 << 8) + 255; - mng_set_bgcolor(hmng, wRed, wGreen, wBlue); - // if PNG Background is available, use it - mng_set_usebkgd(hmng, MNG_TRUE ); - // no need to store chunks - mng_set_storechunks(hmng, MNG_FALSE); - // no need to wait: straight reading - mng_set_suspensionmode(hmng, MNG_FALSE); - - // set the callbacks - mng_setcb_errorproc(hmng, mymngerror); - mng_setcb_openstream(hmng, mymngopenstream); - mng_setcb_closestream(hmng, mymngclosestream); - mng_setcb_readdata(hmng, mymngreadstream); - mng_setcb_processheader(hmng, mymngprocessheader); - mng_setcb_getcanvasline(hmng, mymnggetcanvasline); - mng_setcb_refresh(hmng, mymngrefresh); - mng_setcb_gettickcount(hmng, mymnggetticks); - mng_setcb_settimer(hmng, mymngsettimer); - - // read in the bitmap - mng_readdisplay(hmng); - - // read all bitmaps - int retval = MNG_NOERROR; - while(mng_status_reading(hmng)) { - retval = mng_display_resume(hmng); - if((mng_get_imagetype(hmng) != mng_it_jng) && (retval == MNG_NEEDTIMERWAIT) || (retval == MNG_FUNCTIONINVALID)) - break; - } - - // temp store the newly created bitmap - FIBITMAP *bitmap = mymng->bitmap; - - // cleanup and return the temp stored bitmap - mng_cleanup(&hmng); - - return bitmap; - - } catch (const char *message) { - FIBITMAP *bitmap = ((mngstuff *)mng_get_userdata(hmng))->bitmap; - if(bitmap) { - FreeImage_Unload(bitmap); - } - mng_cleanup(&hmng); - FreeImage_OutputMessageProc(s_format_id, message); - } - } - - return NULL; -} - -// ========================================================== -// Init -// ========================================================== - -void DLL_CALLCONV -InitMNG(Plugin *plugin, int format_id) { - s_format_id = format_id; - - plugin->format_proc = Format; - plugin->description_proc = Description; - plugin->extension_proc = Extension; - plugin->regexpr_proc = RegExpr; - plugin->open_proc = Open; - plugin->close_proc = Close; - plugin->pagecount_proc = NULL; - plugin->pagecapability_proc = NULL; - plugin->load_proc = Load; - plugin->save_proc = NULL; - plugin->validate_proc = NULL; - plugin->mime_proc = MimeType; - plugin->supports_export_bpp_proc = SupportsExportDepth; - plugin->supports_export_type_proc = SupportsExportType; - plugin->supports_icc_profiles_proc = NULL; // not implemented yet; -} +// ========================================================== +// MNG Loader +// +// Design and implementation by +// - Floris van den Berg (flvdberg@wxs.nl) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" + +#include "../LibMNG/libmng.h" +//#include "../LibMNG/libmng_data.h" + +// ========================================================== +// Plugin Interface +// ========================================================== + +static int s_format_id; + +// ---------------------------------------------------------- +// Constants + headers +// ---------------------------------------------------------- + +typedef struct { + FIBITMAP *bitmap; // pointer to the bitmap data + FreeImageIO *io; // pointer to the io functions + fi_handle file; // pointer to the file we're decoding +} mngstuff; + +// ---------------------------------------------------------- +// Callbacks for the mng decoder +// ---------------------------------------------------------- + +mng_ptr +mymngalloc(mng_size_t size) { + return (mng_ptr)calloc(1, size); +} + +void +mymngfree(mng_ptr p, mng_size_t size) { + free(p); +} + +mng_bool +mymngopenstream(mng_handle mng) { + // since the user is responsible for opening and closing the file, + // we leave the default implementation open + + return MNG_TRUE; +} + +mng_bool +mymngclosestream(mng_handle mng) { + // since the user is responsible for opening and closing the file, + // we leave the default implementation open + + return MNG_TRUE; +} + +mng_bool +mymngreadstream(mng_handle mng, mng_ptr buffer, mng_uint32 size, mng_uint32 *bytesread) { + mngstuff *mymng = (mngstuff *)mng_get_userdata(mng); + + *bytesread = mymng->io->read_proc(buffer, 1, size, mymng->file); + + return MNG_TRUE; +} + +mng_bool +mymngprocessheader(mng_handle mng, mng_uint32 width, mng_uint32 height) { + mngstuff *client_data = (mngstuff *)mng_get_userdata(mng); + BYTE bHasAlpha = mng_get_alphadepth(mng); + +#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB + if(bHasAlpha) { + // allocate a bitmap with the given dimensions + FIBITMAP *bitmap = FreeImage_Allocate(width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + client_data->bitmap = bitmap; + // tell the mng decoder about our bit-depth choice + mng_set_canvasstyle(mng, MNG_CANVAS_RGBA8); + } else { + // allocate a bitmap with the given dimensions + FIBITMAP *bitmap = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + client_data->bitmap = bitmap; + // tell the mng decoder about our bit-depth choice + mng_set_canvasstyle(mng, MNG_CANVAS_RGB8); + } +#else + if(bHasAlpha) { + // allocate a bitmap with the given dimensions + FIBITMAP *bitmap = FreeImage_Allocate(width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + client_data->bitmap = bitmap; + // tell the mng decoder about our bit-depth choice + mng_set_canvasstyle(mng, MNG_CANVAS_BGRA8); + } else { + // allocate a bitmap with the given dimensions + FIBITMAP *bitmap = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + client_data->bitmap = bitmap; + // tell the mng decoder about our bit-depth choice + mng_set_canvasstyle(mng, MNG_CANVAS_BGR8); + } +#endif // FREEIMAGE_COLORORDER_RGB + + return client_data->bitmap ? MNG_TRUE : MNG_FALSE; +} + +mng_ptr +mymnggetcanvasline(mng_handle mng, mng_uint32 line) { + FIBITMAP *bitmap = ((mngstuff *)mng_get_userdata(mng))->bitmap; + + return FreeImage_GetScanLine(bitmap, FreeImage_GetHeight(bitmap) - line - 1); +} + +mng_bool +mymngrefresh(mng_handle mng, mng_uint32 x, mng_uint32 y, mng_uint32 w, mng_uint32 h) { + return MNG_TRUE; +} + +mng_uint32 +mymnggetticks(mng_handle mng) { + return 0; +} + +mng_bool +mymngsettimer(mng_handle mng, mng_uint32 msecs) { + return MNG_TRUE; +} + +mng_bool +mymngerror(mng_handle mng, mng_int32 code, mng_int8 severity, mng_chunkid chunktype, mng_uint32 chunkseq, mng_int32 extra1, mng_int32 extra2, mng_pchar text) { + char msg[256]; + if((code == MNG_SEQUENCEERROR) && (chunktype == MNG_UINT_TERM)) { + // ignore sequence error for TERM + return MNG_TRUE; + } + if(text) { + // text can be null depending on compiler options + sprintf(msg, "Error reported by libmng (%d)\r\n\r\n%s", code, text); + } else { + sprintf(msg, "Error %d reported by libmng", code); + } + FreeImage_OutputMessageProc(s_format_id, msg); + return MNG_FALSE; +} + +// ========================================================== +// Plugin Implementation +// ========================================================== + +static const char * DLL_CALLCONV +Format() { + return "MNG"; +} + +static const char * DLL_CALLCONV +Description() { + return "Multiple Network Graphics"; +} + +static const char * DLL_CALLCONV +Extension() { + return "mng"; +} + +static const char * DLL_CALLCONV +RegExpr() { + return NULL; +} + +static const char * DLL_CALLCONV +MimeType() { + return "video/x-mng"; +} + +static BOOL DLL_CALLCONV +SupportsExportDepth(int depth) { + return FALSE; +} + +static BOOL DLL_CALLCONV +SupportsExportType(FREE_IMAGE_TYPE type) { + return FALSE; +} + +// ---------------------------------------------------------- + +static void * DLL_CALLCONV +Open(FreeImageIO *io, fi_handle handle, BOOL read) { + mngstuff *mymng = (mngstuff *)calloc(1, sizeof(*mymng)); + mymng->io = io; + mymng->file = handle; + + return mymng; +} + +static void DLL_CALLCONV +Close(FreeImageIO *io, fi_handle handle, void *data) { + free((mngstuff *)data); +} + +// ---------------------------------------------------------- + +static FIBITMAP * DLL_CALLCONV +Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { + mng_handle hmng = NULL; + + if (handle != NULL) { + try { + // allocate our stream data structure + mngstuff *mymng = (mngstuff *)data; + + // set up the mng decoder for our stream + hmng = mng_initialize(mymng, mymngalloc, mymngfree, MNG_NULL); + + if (hmng == MNG_NULL) { + throw "could not initialize libmng"; + } + + // set the colorprofile, lcms uses this + mng_set_srgb(hmng, MNG_TRUE ); + // set white as background color + WORD wRed, wGreen, wBlue; + wRed = wGreen = wBlue = (255 << 8) + 255; + mng_set_bgcolor(hmng, wRed, wGreen, wBlue); + // if PNG Background is available, use it + mng_set_usebkgd(hmng, MNG_TRUE ); + // no need to store chunks + mng_set_storechunks(hmng, MNG_FALSE); + // no need to wait: straight reading + mng_set_suspensionmode(hmng, MNG_FALSE); + + // set the callbacks + mng_setcb_errorproc(hmng, mymngerror); + mng_setcb_openstream(hmng, mymngopenstream); + mng_setcb_closestream(hmng, mymngclosestream); + mng_setcb_readdata(hmng, mymngreadstream); + mng_setcb_processheader(hmng, mymngprocessheader); + mng_setcb_getcanvasline(hmng, mymnggetcanvasline); + mng_setcb_refresh(hmng, mymngrefresh); + mng_setcb_gettickcount(hmng, mymnggetticks); + mng_setcb_settimer(hmng, mymngsettimer); + + // read in the bitmap + mng_readdisplay(hmng); + + // read all bitmaps + int retval = MNG_NOERROR; + while(mng_status_reading(hmng)) { + retval = mng_display_resume(hmng); + if((mng_get_imagetype(hmng) != mng_it_jng) && (retval == MNG_NEEDTIMERWAIT) || (retval == MNG_FUNCTIONINVALID)) + break; + } + + // temp store the newly created bitmap + FIBITMAP *bitmap = mymng->bitmap; + + // cleanup and return the temp stored bitmap + mng_cleanup(&hmng); + + return bitmap; + + } catch (const char *message) { + FIBITMAP *bitmap = ((mngstuff *)mng_get_userdata(hmng))->bitmap; + if(bitmap) { + FreeImage_Unload(bitmap); + } + mng_cleanup(&hmng); + FreeImage_OutputMessageProc(s_format_id, message); + } + } + + return NULL; +} + +// ========================================================== +// Init +// ========================================================== + +void DLL_CALLCONV +InitMNG(Plugin *plugin, int format_id) { + s_format_id = format_id; + + plugin->format_proc = Format; + plugin->description_proc = Description; + plugin->extension_proc = Extension; + plugin->regexpr_proc = RegExpr; + plugin->open_proc = Open; + plugin->close_proc = Close; + plugin->pagecount_proc = NULL; + plugin->pagecapability_proc = NULL; + plugin->load_proc = Load; + plugin->save_proc = NULL; + plugin->validate_proc = NULL; + plugin->mime_proc = MimeType; + plugin->supports_export_bpp_proc = SupportsExportDepth; + plugin->supports_export_type_proc = SupportsExportType; + plugin->supports_icc_profiles_proc = NULL; // not implemented yet; +} diff --git a/Source/LibMNG/libmng_callback_xs.c b/Source/LibMNG/libmng_callback_xs.c index e8f1efe..ff1a22a 100644 --- a/Source/LibMNG/libmng_callback_xs.c +++ b/Source/LibMNG/libmng_callback_xs.c @@ -1,1239 +1,1239 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_callback_xs.c copyright (c) 2000-2004 G.Juyn * */ -/* * version : 1.0.9 * */ -/* * * */ -/* * purpose : callback get/set interface (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the callback get/set functions * */ -/* * * */ -/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - fixed calling convention * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - changed trace to macro for callback error-reporting * */ -/* * * */ -/* * 0.5.2 - 05/31/2000 - G.Juyn * */ -/* * - fixed up punctuation (contribution by Tim Rowley) * */ -/* * 0.5.2 - 06/02/2000 - G.Juyn * */ -/* * - added getalphaline callback for RGB8_A8 canvasstyle * */ -/* * * */ -/* * 0.9.1 - 07/15/2000 - G.Juyn * */ -/* * - added callbacks for SAVE/SEEK processing * */ -/* * * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 0.9.3 - 10/11/2000 - G.Juyn * */ -/* * - added support for nEED * */ -/* * 0.9.3 - 10/17/2000 - G.Juyn * */ -/* * - added callback to process non-critical unknown chunks * */ -/* * * */ -/* * 1.0.1 - 02/08/2001 - G.Juyn * */ -/* * - added MEND processing callback * */ -/* * * */ -/* * 1.0.2 - 06/23/2001 - G.Juyn * */ -/* * - added processterm callback * */ -/* * * */ -/* * 1.0.6 - 07/07/2003 - G. R-P * */ -/* * - added SKIPCHUNK feature * */ -/* * * */ -/* * 1.0.7 - 03/10/2004 - G.R-P * */ -/* * - added conditionals around openstream/closestream * */ -/* * 1.0.7 - 03/19/2004 - G.R-P * */ -/* * - fixed typo (MNG_SKIPCHUNK_SAVE -> MNG_SKIPCHUNK_nEED * */ -/* * * */ -/* * 1.0.8 - 04/10/2004 - G.Juyn * */ -/* * - added data-push mechanisms for specialized decoders * */ -/* * * */ -/* * 1.0.9 - 09/18/2004 - G.R-P. * */ -/* * - added two SKIPCHUNK_TERM conditionals * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ -/* * * */ -/* * Callback set functions * */ -/* * * */ -/* ************************************************************************** */ - -#ifndef MNG_INTERNAL_MEMMNGMT -mng_retcode MNG_DECL mng_setcb_memalloc (mng_handle hHandle, - mng_memalloc fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_MEMALLOC, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fMemalloc = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_MEMALLOC, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INTERNAL_MEMMNGMT */ - -/* ************************************************************************** */ - -#ifndef MNG_INTERNAL_MEMMNGMT -mng_retcode MNG_DECL mng_setcb_memfree (mng_handle hHandle, - mng_memfree fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_MEMFREE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fMemfree = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_MEMFREE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INTERNAL_MEMMNGMT */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_retcode MNG_DECL mng_setcb_releasedata (mng_handle hHandle, - mng_releasedata fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_RELEASEDATA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fReleasedata = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_RELEASEDATA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) -#ifndef MNG_NO_OPEN_CLOSE_STREAM -mng_retcode MNG_DECL mng_setcb_openstream (mng_handle hHandle, - mng_openstream fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_OPENSTREAM, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fOpenstream = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_OPENSTREAM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) -#ifndef MNG_NO_OPEN_CLOSE_STREAM -mng_retcode MNG_DECL mng_setcb_closestream (mng_handle hHandle, - mng_closestream fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_CLOSESTREAM, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fClosestream = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_CLOSESTREAM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_retcode MNG_DECL mng_setcb_readdata (mng_handle hHandle, - mng_readdata fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_READDATA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fReaddata = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_READDATA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_setcb_writedata (mng_handle hHandle, - mng_writedata fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_WRITEDATA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fWritedata = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_WRITEDATA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_setcb_errorproc (mng_handle hHandle, - mng_errorproc fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_ERRORPROC, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fErrorproc = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_ERRORPROC, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_TRACE -mng_retcode MNG_DECL mng_setcb_traceproc (mng_handle hHandle, - mng_traceproc fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_TRACEPROC, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fTraceproc = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_TRACEPROC, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_TRACE */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_retcode MNG_DECL mng_setcb_processheader (mng_handle hHandle, - mng_processheader fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSHEADER, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fProcessheader = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSHEADER, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -#ifndef MNG_SKIPCHUNK_tEXt -mng_retcode MNG_DECL mng_setcb_processtext (mng_handle hHandle, - mng_processtext fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSTEXT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fProcesstext = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSTEXT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -#ifndef MNG_SKIPCHUNK_SAVE -mng_retcode MNG_DECL mng_setcb_processsave (mng_handle hHandle, - mng_processsave fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSSAVE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fProcesssave = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSSAVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -#ifndef MNG_SKIPCHUNK_SEEK -mng_retcode MNG_DECL mng_setcb_processseek (mng_handle hHandle, - mng_processseek fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSSEEK, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fProcessseek = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSSEEK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -#ifndef MNG_SKIPCHUNK_nEED -mng_retcode MNG_DECL mng_setcb_processneed (mng_handle hHandle, - mng_processneed fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSNEED, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fProcessneed = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSNEED, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_retcode MNG_DECL mng_setcb_processmend (mng_handle hHandle, - mng_processmend fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSMEND, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fProcessmend = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSMEND, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_retcode MNG_DECL mng_setcb_processunknown (mng_handle hHandle, - mng_processunknown fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSUNKNOWN, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fProcessunknown = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSUNKNOWN, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -#ifndef MNG_SKIPCHUNK_TERM -mng_retcode MNG_DECL mng_setcb_processterm (mng_handle hHandle, - mng_processterm fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSTERM, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fProcessterm = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSTERM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_setcb_getcanvasline (mng_handle hHandle, - mng_getcanvasline fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETCANVASLINE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fGetcanvasline = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETCANVASLINE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_setcb_getbkgdline (mng_handle hHandle, - mng_getbkgdline fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETBKGDLINE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fGetbkgdline = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETBKGDLINE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_setcb_getalphaline (mng_handle hHandle, - mng_getalphaline fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETALPHALINE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fGetalphaline = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETALPHALINE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_setcb_refresh (mng_handle hHandle, - mng_refresh fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_REFRESH, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fRefresh = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_REFRESH, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_setcb_gettickcount (mng_handle hHandle, - mng_gettickcount fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETTICKCOUNT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fGettickcount = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETTICKCOUNT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_setcb_settimer (mng_handle hHandle, - mng_settimer fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_SETTIMER, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fSettimer = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_SETTIMER, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) -mng_retcode MNG_DECL mng_setcb_processgamma (mng_handle hHandle, - mng_processgamma fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSGAMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fProcessgamma = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSGAMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) -#ifndef MNG_SKIPCHUNK_cHRM -mng_retcode MNG_DECL mng_setcb_processchroma (mng_handle hHandle, - mng_processchroma fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSCHROMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fProcesschroma = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSCHROMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) -mng_retcode MNG_DECL mng_setcb_processsrgb (mng_handle hHandle, - mng_processsrgb fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSSRGB, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fProcesssrgb = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSSRGB, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) -#ifndef MNG_SKIPCHUNK_iCCP -mng_retcode MNG_DECL mng_setcb_processiccp (mng_handle hHandle, - mng_processiccp fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSICCP, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fProcessiccp = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSICCP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) -mng_retcode MNG_DECL mng_setcb_processarow (mng_handle hHandle, - mng_processarow fProc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSAROW, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->fProcessarow = fProc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSAROW, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ - -/* ************************************************************************** */ -/* * * */ -/* * Callback get functions * */ -/* * * */ -/* ************************************************************************** */ - -#ifndef MNG_INTERNAL_MEMMNGMT -mng_memalloc MNG_DECL mng_getcb_memalloc (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_MEMALLOC, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_MEMALLOC, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fMemalloc; -} -#endif /* MNG_INTERNAL_MEMMNGMT */ - -/* ************************************************************************** */ - -#ifndef MNG_INTERNAL_MEMMNGMT -mng_memfree MNG_DECL mng_getcb_memfree (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_MEMFREE, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_MEMFREE, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fMemfree; -} -#endif /* MNG_INTERNAL_MEMMNGMT */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_releasedata MNG_DECL mng_getcb_releasedata (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_RELEASEDATA, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_RELEASEDATA, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fReleasedata; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_readdata MNG_DECL mng_getcb_readdata (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_READDATA, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_READDATA, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fReaddata; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) -#ifndef MNG_NO_OPEN_CLOSE_STREAM -mng_openstream MNG_DECL mng_getcb_openstream (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_OPENSTREAM, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_OPENSTREAM, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fOpenstream; -} -#endif -#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) -#ifndef MNG_NO_OPEN_CLOSE_STREAM -mng_closestream MNG_DECL mng_getcb_closestream (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_CLOSESTREAM, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_CLOSESTREAM, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fClosestream; -} -#endif -#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_WRITE -mng_writedata MNG_DECL mng_getcb_writedata (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_WRITEDATA, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_WRITEDATA, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fWritedata; -} -#endif /* MNG_SUPPORT_WRITE */ - -/* ************************************************************************** */ - -mng_errorproc MNG_DECL mng_getcb_errorproc (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_ERRORPROC, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_ERRORPROC, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fErrorproc; -} - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_TRACE -mng_traceproc MNG_DECL mng_getcb_traceproc (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_TRACEPROC, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_TRACEPROC, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fTraceproc; -} -#endif /* MNG_SUPPORT_TRACE */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_processheader MNG_DECL mng_getcb_processheader (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSHEADER, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSHEADER, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fProcessheader; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -#ifndef MNG_SKIPCHUNK_tEXt -mng_processtext MNG_DECL mng_getcb_processtext (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSTEXT, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSTEXT, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fProcesstext; -} -#endif -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -#ifndef MNG_SKIPCHUNK_SAVE -mng_processsave MNG_DECL mng_getcb_processsave (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSSAVE, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSSAVE, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fProcesssave; -} -#endif -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -#ifndef MNG_SKIPCHUNK_SEEK -mng_processseek MNG_DECL mng_getcb_processseek (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSSEEK, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSSEEK, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fProcessseek; -} -#endif -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -#ifndef MNG_SKIPCHUNK_nEED -mng_processneed MNG_DECL mng_getcb_processneed (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSNEED, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSNEED, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fProcessneed; -} -#endif -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_processmend MNG_DECL mng_getcb_processmend (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSMEND, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSMEND, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fProcessmend; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_processunknown MNG_DECL mng_getcb_processunknown (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSUNKNOWN, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSUNKNOWN, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fProcessunknown; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -#ifndef MNG_SKIPCHUNK_TERM -mng_processterm MNG_DECL mng_getcb_processterm (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSTERM, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSTERM, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fProcessterm; -} -#endif -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_getcanvasline MNG_DECL mng_getcb_getcanvasline (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETCANVASLINE, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETCANVASLINE, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fGetcanvasline; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_getbkgdline MNG_DECL mng_getcb_getbkgdline (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETBKGDLINE, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETBKGDLINE, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fGetbkgdline; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_getalphaline MNG_DECL mng_getcb_getalphaline (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETALPHALINE, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETALPHALINE, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fGetalphaline; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_refresh MNG_DECL mng_getcb_refresh (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_REFRESH, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_REFRESH, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fRefresh; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_gettickcount MNG_DECL mng_getcb_gettickcount (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETTICKCOUNT, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETTICKCOUNT, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fGettickcount; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_settimer MNG_DECL mng_getcb_settimer (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_SETTIMER, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_SETTIMER, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fSettimer; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) -mng_processgamma MNG_DECL mng_getcb_processgamma (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSGAMMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSGAMMA, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fProcessgamma; -} -#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) -#ifndef MNG_SKIPCHUNK_cHRM -mng_processchroma MNG_DECL mng_getcb_processchroma (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSCHROMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSCHROMA, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fProcesschroma; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) -mng_processsrgb MNG_DECL mng_getcb_processsrgb (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSSRGB, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSSRGB, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fProcesssrgb; -} -#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) -#ifndef MNG_SKIPCHUNK_iCCP -mng_processiccp MNG_DECL mng_getcb_processiccp (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSICCP, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSICCP, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fProcessiccp; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) -mng_processarow MNG_DECL mng_getcb_processarow (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSAROW, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSAROW, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->fProcessarow; -} -#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - - - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_callback_xs.c copyright (c) 2000-2004 G.Juyn * */ +/* * version : 1.0.9 * */ +/* * * */ +/* * purpose : callback get/set interface (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the callback get/set functions * */ +/* * * */ +/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - fixed calling convention * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - changed trace to macro for callback error-reporting * */ +/* * * */ +/* * 0.5.2 - 05/31/2000 - G.Juyn * */ +/* * - fixed up punctuation (contribution by Tim Rowley) * */ +/* * 0.5.2 - 06/02/2000 - G.Juyn * */ +/* * - added getalphaline callback for RGB8_A8 canvasstyle * */ +/* * * */ +/* * 0.9.1 - 07/15/2000 - G.Juyn * */ +/* * - added callbacks for SAVE/SEEK processing * */ +/* * * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 0.9.3 - 10/11/2000 - G.Juyn * */ +/* * - added support for nEED * */ +/* * 0.9.3 - 10/17/2000 - G.Juyn * */ +/* * - added callback to process non-critical unknown chunks * */ +/* * * */ +/* * 1.0.1 - 02/08/2001 - G.Juyn * */ +/* * - added MEND processing callback * */ +/* * * */ +/* * 1.0.2 - 06/23/2001 - G.Juyn * */ +/* * - added processterm callback * */ +/* * * */ +/* * 1.0.6 - 07/07/2003 - G. R-P * */ +/* * - added SKIPCHUNK feature * */ +/* * * */ +/* * 1.0.7 - 03/10/2004 - G.R-P * */ +/* * - added conditionals around openstream/closestream * */ +/* * 1.0.7 - 03/19/2004 - G.R-P * */ +/* * - fixed typo (MNG_SKIPCHUNK_SAVE -> MNG_SKIPCHUNK_nEED * */ +/* * * */ +/* * 1.0.8 - 04/10/2004 - G.Juyn * */ +/* * - added data-push mechanisms for specialized decoders * */ +/* * * */ +/* * 1.0.9 - 09/18/2004 - G.R-P. * */ +/* * - added two SKIPCHUNK_TERM conditionals * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ +/* * * */ +/* * Callback set functions * */ +/* * * */ +/* ************************************************************************** */ + +#ifndef MNG_INTERNAL_MEMMNGMT +mng_retcode MNG_DECL mng_setcb_memalloc (mng_handle hHandle, + mng_memalloc fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_MEMALLOC, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fMemalloc = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_MEMALLOC, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INTERNAL_MEMMNGMT */ + +/* ************************************************************************** */ + +#ifndef MNG_INTERNAL_MEMMNGMT +mng_retcode MNG_DECL mng_setcb_memfree (mng_handle hHandle, + mng_memfree fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_MEMFREE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fMemfree = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_MEMFREE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INTERNAL_MEMMNGMT */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_retcode MNG_DECL mng_setcb_releasedata (mng_handle hHandle, + mng_releasedata fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_RELEASEDATA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fReleasedata = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_RELEASEDATA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) +#ifndef MNG_NO_OPEN_CLOSE_STREAM +mng_retcode MNG_DECL mng_setcb_openstream (mng_handle hHandle, + mng_openstream fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_OPENSTREAM, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fOpenstream = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_OPENSTREAM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) +#ifndef MNG_NO_OPEN_CLOSE_STREAM +mng_retcode MNG_DECL mng_setcb_closestream (mng_handle hHandle, + mng_closestream fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_CLOSESTREAM, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fClosestream = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_CLOSESTREAM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_retcode MNG_DECL mng_setcb_readdata (mng_handle hHandle, + mng_readdata fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_READDATA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fReaddata = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_READDATA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_setcb_writedata (mng_handle hHandle, + mng_writedata fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_WRITEDATA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fWritedata = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_WRITEDATA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_setcb_errorproc (mng_handle hHandle, + mng_errorproc fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_ERRORPROC, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fErrorproc = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_ERRORPROC, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_TRACE +mng_retcode MNG_DECL mng_setcb_traceproc (mng_handle hHandle, + mng_traceproc fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_TRACEPROC, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fTraceproc = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_TRACEPROC, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_TRACE */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_retcode MNG_DECL mng_setcb_processheader (mng_handle hHandle, + mng_processheader fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSHEADER, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fProcessheader = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSHEADER, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +#ifndef MNG_SKIPCHUNK_tEXt +mng_retcode MNG_DECL mng_setcb_processtext (mng_handle hHandle, + mng_processtext fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSTEXT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fProcesstext = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSTEXT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +#ifndef MNG_SKIPCHUNK_SAVE +mng_retcode MNG_DECL mng_setcb_processsave (mng_handle hHandle, + mng_processsave fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSSAVE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fProcesssave = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSSAVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +#ifndef MNG_SKIPCHUNK_SEEK +mng_retcode MNG_DECL mng_setcb_processseek (mng_handle hHandle, + mng_processseek fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSSEEK, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fProcessseek = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSSEEK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +#ifndef MNG_SKIPCHUNK_nEED +mng_retcode MNG_DECL mng_setcb_processneed (mng_handle hHandle, + mng_processneed fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSNEED, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fProcessneed = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSNEED, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_retcode MNG_DECL mng_setcb_processmend (mng_handle hHandle, + mng_processmend fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSMEND, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fProcessmend = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSMEND, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_retcode MNG_DECL mng_setcb_processunknown (mng_handle hHandle, + mng_processunknown fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSUNKNOWN, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fProcessunknown = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSUNKNOWN, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +#ifndef MNG_SKIPCHUNK_TERM +mng_retcode MNG_DECL mng_setcb_processterm (mng_handle hHandle, + mng_processterm fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSTERM, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fProcessterm = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSTERM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_setcb_getcanvasline (mng_handle hHandle, + mng_getcanvasline fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETCANVASLINE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fGetcanvasline = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETCANVASLINE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_setcb_getbkgdline (mng_handle hHandle, + mng_getbkgdline fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETBKGDLINE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fGetbkgdline = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETBKGDLINE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_setcb_getalphaline (mng_handle hHandle, + mng_getalphaline fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETALPHALINE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fGetalphaline = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETALPHALINE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_setcb_refresh (mng_handle hHandle, + mng_refresh fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_REFRESH, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fRefresh = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_REFRESH, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_setcb_gettickcount (mng_handle hHandle, + mng_gettickcount fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETTICKCOUNT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fGettickcount = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_GETTICKCOUNT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_setcb_settimer (mng_handle hHandle, + mng_settimer fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_SETTIMER, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fSettimer = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_SETTIMER, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) +mng_retcode MNG_DECL mng_setcb_processgamma (mng_handle hHandle, + mng_processgamma fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSGAMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fProcessgamma = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSGAMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) +#ifndef MNG_SKIPCHUNK_cHRM +mng_retcode MNG_DECL mng_setcb_processchroma (mng_handle hHandle, + mng_processchroma fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSCHROMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fProcesschroma = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSCHROMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) +mng_retcode MNG_DECL mng_setcb_processsrgb (mng_handle hHandle, + mng_processsrgb fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSSRGB, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fProcesssrgb = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSSRGB, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) +#ifndef MNG_SKIPCHUNK_iCCP +mng_retcode MNG_DECL mng_setcb_processiccp (mng_handle hHandle, + mng_processiccp fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSICCP, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fProcessiccp = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSICCP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) +mng_retcode MNG_DECL mng_setcb_processarow (mng_handle hHandle, + mng_processarow fProc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSAROW, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->fProcessarow = fProc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SETCB_PROCESSAROW, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ + +/* ************************************************************************** */ +/* * * */ +/* * Callback get functions * */ +/* * * */ +/* ************************************************************************** */ + +#ifndef MNG_INTERNAL_MEMMNGMT +mng_memalloc MNG_DECL mng_getcb_memalloc (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_MEMALLOC, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_MEMALLOC, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fMemalloc; +} +#endif /* MNG_INTERNAL_MEMMNGMT */ + +/* ************************************************************************** */ + +#ifndef MNG_INTERNAL_MEMMNGMT +mng_memfree MNG_DECL mng_getcb_memfree (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_MEMFREE, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_MEMFREE, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fMemfree; +} +#endif /* MNG_INTERNAL_MEMMNGMT */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_releasedata MNG_DECL mng_getcb_releasedata (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_RELEASEDATA, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_RELEASEDATA, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fReleasedata; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_readdata MNG_DECL mng_getcb_readdata (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_READDATA, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_READDATA, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fReaddata; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) +#ifndef MNG_NO_OPEN_CLOSE_STREAM +mng_openstream MNG_DECL mng_getcb_openstream (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_OPENSTREAM, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_OPENSTREAM, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fOpenstream; +} +#endif +#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) +#ifndef MNG_NO_OPEN_CLOSE_STREAM +mng_closestream MNG_DECL mng_getcb_closestream (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_CLOSESTREAM, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_CLOSESTREAM, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fClosestream; +} +#endif +#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_WRITE +mng_writedata MNG_DECL mng_getcb_writedata (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_WRITEDATA, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_WRITEDATA, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fWritedata; +} +#endif /* MNG_SUPPORT_WRITE */ + +/* ************************************************************************** */ + +mng_errorproc MNG_DECL mng_getcb_errorproc (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_ERRORPROC, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_ERRORPROC, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fErrorproc; +} + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_TRACE +mng_traceproc MNG_DECL mng_getcb_traceproc (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_TRACEPROC, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_TRACEPROC, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fTraceproc; +} +#endif /* MNG_SUPPORT_TRACE */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_processheader MNG_DECL mng_getcb_processheader (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSHEADER, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSHEADER, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fProcessheader; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +#ifndef MNG_SKIPCHUNK_tEXt +mng_processtext MNG_DECL mng_getcb_processtext (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSTEXT, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSTEXT, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fProcesstext; +} +#endif +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +#ifndef MNG_SKIPCHUNK_SAVE +mng_processsave MNG_DECL mng_getcb_processsave (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSSAVE, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSSAVE, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fProcesssave; +} +#endif +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +#ifndef MNG_SKIPCHUNK_SEEK +mng_processseek MNG_DECL mng_getcb_processseek (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSSEEK, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSSEEK, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fProcessseek; +} +#endif +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +#ifndef MNG_SKIPCHUNK_nEED +mng_processneed MNG_DECL mng_getcb_processneed (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSNEED, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSNEED, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fProcessneed; +} +#endif +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_processmend MNG_DECL mng_getcb_processmend (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSMEND, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSMEND, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fProcessmend; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_processunknown MNG_DECL mng_getcb_processunknown (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSUNKNOWN, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSUNKNOWN, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fProcessunknown; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +#ifndef MNG_SKIPCHUNK_TERM +mng_processterm MNG_DECL mng_getcb_processterm (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSTERM, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSTERM, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fProcessterm; +} +#endif +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_getcanvasline MNG_DECL mng_getcb_getcanvasline (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETCANVASLINE, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETCANVASLINE, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fGetcanvasline; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_getbkgdline MNG_DECL mng_getcb_getbkgdline (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETBKGDLINE, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETBKGDLINE, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fGetbkgdline; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_getalphaline MNG_DECL mng_getcb_getalphaline (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETALPHALINE, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETALPHALINE, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fGetalphaline; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_refresh MNG_DECL mng_getcb_refresh (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_REFRESH, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_REFRESH, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fRefresh; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_gettickcount MNG_DECL mng_getcb_gettickcount (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETTICKCOUNT, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_GETTICKCOUNT, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fGettickcount; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_settimer MNG_DECL mng_getcb_settimer (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_SETTIMER, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_SETTIMER, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fSettimer; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) +mng_processgamma MNG_DECL mng_getcb_processgamma (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSGAMMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSGAMMA, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fProcessgamma; +} +#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) +#ifndef MNG_SKIPCHUNK_cHRM +mng_processchroma MNG_DECL mng_getcb_processchroma (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSCHROMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSCHROMA, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fProcesschroma; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) +mng_processsrgb MNG_DECL mng_getcb_processsrgb (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSSRGB, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSSRGB, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fProcesssrgb; +} +#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) +#ifndef MNG_SKIPCHUNK_iCCP +mng_processiccp MNG_DECL mng_getcb_processiccp (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSICCP, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSICCP, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fProcessiccp; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_APP_CMS) +mng_processarow MNG_DECL mng_getcb_processarow (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSAROW, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GETCB_PROCESSAROW, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->fProcessarow; +} +#endif /* MNG_SUPPORT_DISPLAY && MNG_APP_CMS */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + + + diff --git a/Source/LibMNG/libmng_chunk_descr.c b/Source/LibMNG/libmng_chunk_descr.c index 5a4bfa0..e1004a5 100644 --- a/Source/LibMNG/libmng_chunk_descr.c +++ b/Source/LibMNG/libmng_chunk_descr.c @@ -1,6090 +1,6090 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_chunk_descr.c copyright (c) 2005-2007 G.Juyn * */ -/* * version : 1.0.10 * */ -/* * * */ -/* * purpose : Chunk descriptor functions (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the chunk- anf field-descriptor * */ -/* * routines * */ -/* * * */ -/* * changes : 1.0.9 - 12/06/2004 - G.Juyn * */ -/* * - added conditional MNG_OPTIMIZE_CHUNKREADER * */ -/* * 1.0.9 - 12/11/2004 - G.Juyn * */ -/* * - made all constants 'static' * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * 1.0.9 - 01/17/2005 - G.Juyn * */ -/* * - fixed problem with global PLTE/tRNS * */ -/* * * */ -/* * 1.0.10 - 01/17/2005 - G.R-P. * */ -/* * - added typecast to appease the compiler * */ -/* * 1.0.10 - 04/08/2007 - G.Juyn * */ -/* * - added support for mPNG proposal * */ -/* * 1.0.10 - 04/12/2007 - G.Juyn * */ -/* * - added support for ANG proposal * */ -/* * * */ -/* ************************************************************************** */ - -#include /* needed for offsetof() */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_memory.h" -#include "libmng_objects.h" -#include "libmng_chunks.h" -#include "libmng_chunk_descr.h" -#include "libmng_object_prc.h" -#include "libmng_chunk_prc.h" -#include "libmng_chunk_io.h" -#include "libmng_display.h" - -#ifdef MNG_INCLUDE_ANG_PROPOSAL -#include "libmng_pixels.h" -#include "libmng_filter.h" -#endif - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ - -#ifdef MNG_OPTIMIZE_CHUNKREADER -#if defined(MNG_INCLUDE_READ_PROCS) || defined(MNG_INCLUDE_WRITE_PROCS) - -/* ************************************************************************** */ -/* ************************************************************************** */ -/* PNG chunks */ - -MNG_LOCAL mng_field_descriptor mng_fields_ihdr [] = - { - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_NOHIGHBIT, - 1, 0, 4, 4, - offsetof(mng_ihdr, iWidth), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_NOHIGHBIT, - 1, 0, 4, 4, - offsetof(mng_ihdr, iHeight), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 1, 16, 1, 1, - offsetof(mng_ihdr, iBitdepth), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 6, 1, 1, - offsetof(mng_ihdr, iColortype), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 1, 1, - offsetof(mng_ihdr, iCompression), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 1, 1, - offsetof(mng_ihdr, iFilter), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 1, 1, 1, - offsetof(mng_ihdr, iInterlace), MNG_NULL, MNG_NULL} - }; - -/* ************************************************************************** */ - -MNG_LOCAL mng_field_descriptor mng_fields_plte [] = - { - {mng_debunk_plte, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; - -/* ************************************************************************** */ - -MNG_LOCAL mng_field_descriptor mng_fields_idat [] = - { - {MNG_NULL, - MNG_NULL, - 0, 0, 0, 0, - offsetof(mng_idat, pData), MNG_NULL, offsetof(mng_idat, iDatasize)} - }; - -/* ************************************************************************** */ - -MNG_LOCAL mng_field_descriptor mng_fields_trns [] = - { - {mng_debunk_trns, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_gAMA -MNG_LOCAL mng_field_descriptor mng_fields_gama [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_gama, iGamma), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_cHRM -MNG_LOCAL mng_field_descriptor mng_fields_chrm [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_chrm, iWhitepointx), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_chrm, iWhitepointy), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_chrm, iRedx), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_chrm, iRedy), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_chrm, iGreeny), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_chrm, iGreeny), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_chrm, iBluex), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_chrm, iBluey), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sRGB -MNG_LOCAL mng_field_descriptor mng_fields_srgb [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 4, 1, 1, - offsetof(mng_srgb, iRenderingintent), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iCCP -MNG_LOCAL mng_field_descriptor mng_fields_iccp [] = - { - {MNG_NULL, - MNG_FIELD_TERMINATOR, - 0, 0, 1, 79, - offsetof(mng_iccp, zName), MNG_NULL, offsetof(mng_iccp, iNamesize)}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 1, 1, - offsetof(mng_iccp, iCompression), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_DEFLATED, - 0, 0, 0, 0, - offsetof(mng_iccp, pProfile), MNG_NULL, offsetof(mng_iccp, iProfilesize)} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_tEXt -MNG_LOCAL mng_field_descriptor mng_fields_text [] = - { - {MNG_NULL, - MNG_FIELD_TERMINATOR, - 0, 0, 1, 79, - offsetof(mng_text, zKeyword), MNG_NULL, offsetof(mng_text, iKeywordsize)}, - {MNG_NULL, - MNG_NULL, - 0, 0, 0, 0, - offsetof(mng_text, zText), MNG_NULL, offsetof(mng_text, iTextsize)} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_zTXt -MNG_LOCAL mng_field_descriptor mng_fields_ztxt [] = - { - {MNG_NULL, - MNG_FIELD_TERMINATOR, - 0, 0, 1, 79, - offsetof(mng_ztxt, zKeyword), MNG_NULL, offsetof(mng_ztxt, iKeywordsize)}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 1, 1, - offsetof(mng_ztxt, iCompression), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_DEFLATED, - 0, 0, 0, 0, - offsetof(mng_ztxt, zText), MNG_NULL, offsetof(mng_ztxt, iTextsize)} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iTXt -MNG_LOCAL mng_field_descriptor mng_fields_itxt [] = - { - {MNG_NULL, - MNG_FIELD_TERMINATOR, - 0, 0, 1, 79, - offsetof(mng_itxt, zKeyword), MNG_NULL, offsetof(mng_itxt, iKeywordsize)}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 1, 1, 1, - offsetof(mng_itxt, iCompressionflag), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 1, 1, - offsetof(mng_itxt, iCompressionmethod), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_TERMINATOR, - 0, 0, 0, 0, - offsetof(mng_itxt, zLanguage), MNG_NULL, offsetof(mng_itxt, iLanguagesize)}, - {MNG_NULL, - MNG_FIELD_TERMINATOR, - 0, 0, 0, 0, - offsetof(mng_itxt, zTranslation), MNG_NULL, offsetof(mng_itxt, iTranslationsize)}, - {mng_deflate_itxt, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_bKGD -MNG_LOCAL mng_field_descriptor mng_fields_bkgd [] = - { - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_PUTIMGTYPE, - 0, 0, 0, 0, - offsetof(mng_bkgd, iType), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE3, - 0, 0xFF, 1, 1, - offsetof(mng_bkgd, iIndex), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE0 | MNG_FIELD_IFIMGTYPE4, - 0, 0xFFFF, 2, 2, - offsetof(mng_bkgd, iGray), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE2 | MNG_FIELD_IFIMGTYPE6, - 0, 0xFFFF, 2, 2, - offsetof(mng_bkgd, iRed), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE2 | MNG_FIELD_IFIMGTYPE6, - 0, 0xFFFF, 2, 2, - offsetof(mng_bkgd, iGreen), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE2 | MNG_FIELD_IFIMGTYPE6, - 0, 0xFFFF, 2, 2, - offsetof(mng_bkgd, iBlue), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_pHYs -MNG_LOCAL mng_field_descriptor mng_fields_phys [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_phys, iSizex), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_phys, iSizey), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 1, 1, 1, - offsetof(mng_phys, iUnit), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sBIT -MNG_LOCAL mng_field_descriptor mng_fields_sbit [] = - { - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_PUTIMGTYPE, - 0, 0, 0, 0, - offsetof(mng_sbit, iType), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_IFIMGTYPES, - 0, 0xFF, 1, 1, - offsetof(mng_sbit, aBits[0]), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE2 | MNG_FIELD_IFIMGTYPE3 | MNG_FIELD_IFIMGTYPE4 | MNG_FIELD_IFIMGTYPE6, - 0, 0xFF, 1, 1, - offsetof(mng_sbit, aBits[1]), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE2 | MNG_FIELD_IFIMGTYPE3 | MNG_FIELD_IFIMGTYPE6, - 0, 0xFF, 1, 1, - offsetof(mng_sbit, aBits[2]), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE6, - 0, 0xFF, 1, 1, - offsetof(mng_sbit, aBits[3]), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sPLT -MNG_LOCAL mng_field_descriptor mng_fields_splt [] = - { - {MNG_NULL, - MNG_NULL, - 0, 0, 1, 79, - offsetof(mng_splt, zName), MNG_NULL, offsetof(mng_splt, iNamesize)}, - {MNG_NULL, - MNG_FIELD_INT, - 8, 16, 1, 1, - offsetof(mng_splt, iSampledepth), MNG_NULL, MNG_NULL}, - {mng_splt_entries, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_hIST -MNG_LOCAL mng_field_descriptor mng_fields_hist [] = - { - {mng_hist_entries, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_tIME -MNG_LOCAL mng_field_descriptor mng_fields_time [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFFFF, 2, 2, - offsetof(mng_time, iYear), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 1, 12, 1, 1, - offsetof(mng_time, iMonth), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 1, 31, 1, 1, - offsetof(mng_time, iDay), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 24, 1, 1, - offsetof(mng_time, iHour), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 60, 1, 1, - offsetof(mng_time, iMinute), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 60, 1, 1, - offsetof(mng_time, iSecond), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ -/* ************************************************************************** */ -/* JNG chunks */ - -#ifdef MNG_INCLUDE_JNG -MNG_LOCAL mng_field_descriptor mng_fields_jhdr [] = - { - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_NOHIGHBIT, - 1, 0, 4, 4, - offsetof(mng_jhdr, iWidth), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_NOHIGHBIT, - 1, 0, 4, 4, - offsetof(mng_jhdr, iHeight), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 8, 16, 1, 1, - offsetof(mng_jhdr, iColortype), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 8, 20, 1, 1, - offsetof(mng_jhdr, iImagesampledepth), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 8, 8, 1, 1, - offsetof(mng_jhdr, iImagecompression), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 8, 1, 1, - offsetof(mng_jhdr, iImageinterlace), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 16, 1, 1, - offsetof(mng_jhdr, iAlphasampledepth), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 8, 1, 1, - offsetof(mng_jhdr, iAlphacompression), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 1, 1, - offsetof(mng_jhdr, iAlphafilter), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 1, 1, 1, - offsetof(mng_jhdr, iAlphainterlace), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#define mng_fields_jdaa mng_fields_idat -#define mng_fields_jdat mng_fields_idat -#endif - -/* ************************************************************************** */ -/* ************************************************************************** */ -/* MNG chunks */ - -MNG_LOCAL mng_field_descriptor mng_fields_mhdr [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_mhdr, iWidth), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_mhdr, iHeight), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_mhdr, iTicks), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_mhdr, iLayercount), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_mhdr, iFramecount), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_mhdr, iPlaytime), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_mhdr, iSimplicity), MNG_NULL, MNG_NULL} - }; - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_LOOP -MNG_LOCAL mng_field_descriptor mng_fields_loop [] = - { - {mng_debunk_loop, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_LOOP -MNG_LOCAL mng_field_descriptor mng_fields_endl [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFF, 1, 1, - offsetof(mng_endl, iLevel), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DEFI -MNG_LOCAL mng_field_descriptor mng_fields_defi [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFFFF, 2, 2, - offsetof(mng_defi, iObjectid), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL, - 0, 0xFF, 1, 1, - offsetof(mng_defi, iDonotshow), offsetof(mng_defi, bHasdonotshow), MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL, - 0, 0xFF, 1, 1, - offsetof(mng_defi, iConcrete), offsetof(mng_defi, bHasconcrete), MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, - 0, 0, 4, 4, - offsetof(mng_defi, iXlocation), offsetof(mng_defi, bHasloca), MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, - 0, 0, 4, 4, - offsetof(mng_defi, iYlocation), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP2, - 0, 0, 4, 4, - offsetof(mng_defi, iLeftcb), offsetof(mng_defi, bHasclip), MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP2, - 0, 0, 4, 4, - offsetof(mng_defi, iRightcb), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP2, - 0, 0, 4, 4, - offsetof(mng_defi, iTopcb), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP2, - 0, 0, 4, 4, - offsetof(mng_defi, iBottomcb), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_BASI -MNG_LOCAL mng_field_descriptor mng_fields_basi [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_basi, iWidth), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_basi, iHeight), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 1, 16, 1, 1, - offsetof(mng_basi, iBitdepth), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 6, 1, 1, - offsetof(mng_basi, iColortype), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 1, 1, - offsetof(mng_basi, iCompression), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 1, 1, - offsetof(mng_basi, iFilter), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 1, 1, 1, - offsetof(mng_basi, iInterlace), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, - 0, 0xFFFF, 2, 2, - offsetof(mng_basi, iRed), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, - 0, 0xFFFF, 2, 2, - offsetof(mng_basi, iGreen), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, - 0, 0xFFFF, 2, 2, - offsetof(mng_basi, iBlue), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL, - 0, 0xFFFF, 2, 2, - offsetof(mng_basi, iAlpha), offsetof(mng_basi, bHasalpha), MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL, - 0, 1, 1, 1, - offsetof(mng_basi, iViewable), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_CLON -MNG_LOCAL mng_field_descriptor mng_fields_clon [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFFFF, 2, 2, - offsetof(mng_clon, iSourceid), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFFFF, 2, 2, - offsetof(mng_clon, iCloneid), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL, - 0, 2, 1, 1, - offsetof(mng_clon, iClonetype), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL, - 0, 1, 1, 1, - offsetof(mng_clon, iDonotshow), offsetof(mng_clon, bHasdonotshow), MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL, - 0, 1, 1, 1, - offsetof(mng_clon, iConcrete), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, - 0, 2, 1, 1, - offsetof(mng_clon, iLocationtype), offsetof(mng_clon, bHasloca), MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, - 0, 0, 4, 4, - offsetof(mng_clon, iLocationx), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, - 0, 0, 4, 4, - offsetof(mng_clon, iLocationy), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -MNG_LOCAL mng_field_descriptor mng_fields_past [] = - { - {mng_debunk_past, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DISC -MNG_LOCAL mng_field_descriptor mng_fields_disc [] = - { - {mng_disc_entries, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_BACK -MNG_LOCAL mng_field_descriptor mng_fields_back [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFFFF, 2, 2, - offsetof(mng_back, iRed), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFFFF, 2, 2, - offsetof(mng_back, iGreen), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFFFF, 2, 2, - offsetof(mng_back, iBlue), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL, - 0, 3, 1, 1, - offsetof(mng_back, iMandatory), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL, - 0, 0xFFFF, 2, 2, - offsetof(mng_back, iImageid), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL, - 0, 1, 1, 1, - offsetof(mng_back, iTile), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_FRAM -MNG_LOCAL mng_field_descriptor mng_fields_fram [] = - { - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL, - 0, 4, 1, 1, - offsetof(mng_fram, iMode), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_TERMINATOR | MNG_FIELD_OPTIONAL, - 0, 0, 1, 79, - offsetof(mng_fram, zName), MNG_NULL, offsetof(mng_fram, iNamesize)}, - {mng_fram_remainder, - MNG_FIELD_OPTIONAL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MOVE -MNG_LOCAL mng_field_descriptor mng_fields_move [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFFFF, 2, 2, - offsetof(mng_move, iFirstid), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFFFF, 2, 2, - offsetof(mng_move, iLastid), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 1, 1, 1, - offsetof(mng_move, iMovetype), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_move, iMovex), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_move, iMovey), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_CLIP -MNG_LOCAL mng_field_descriptor mng_fields_clip [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFFFF, 2, 2, - offsetof(mng_clip, iFirstid), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFFFF, 2, 2, - offsetof(mng_clip, iLastid), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 1, 1, 1, - offsetof(mng_clip, iCliptype), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_clip, iClipl), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_clip, iClipr), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_clip, iClipt), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_clip, iClipb), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SHOW -MNG_LOCAL mng_field_descriptor mng_fields_show [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 1, 0xFFFF, 2, 2, - offsetof(mng_show, iFirstid), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL, - 1, 0xFFFF, 2, 2, - offsetof(mng_show, iLastid), offsetof(mng_show, bHaslastid), MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL, - 0, 7, 1, 1, - offsetof(mng_show, iMode), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_TERM -MNG_LOCAL mng_field_descriptor mng_fields_term [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 3, 1, 1, - offsetof(mng_term, iTermaction), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, - 0, 2, 1, 1, - offsetof(mng_term, iIteraction), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, - 0, 0, 4, 4, - offsetof(mng_term, iDelay), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, - 0, 0, 4, 4, - offsetof(mng_term, iItermax), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SAVE -MNG_LOCAL mng_field_descriptor mng_fields_save [] = - { - {mng_save_entries, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SEEK -MNG_LOCAL mng_field_descriptor mng_fields_seek [] = - { - {MNG_NULL, - MNG_NULL, - 0, 0, 1, 79, - offsetof(mng_seek, zName), MNG_NULL, offsetof(mng_seek, iNamesize)} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_eXPI -MNG_LOCAL mng_field_descriptor mng_fields_expi [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFFFF, 2, 2, - offsetof(mng_expi, iSnapshotid), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_NULL, - 0, 0, 1, 79, - offsetof(mng_expi, zName), MNG_NULL, offsetof(mng_expi, iNamesize)} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_fPRI -MNG_LOCAL mng_field_descriptor mng_fields_fpri [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 1, 1, 1, - offsetof(mng_fpri, iDeltatype), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFF, 1, 1, - offsetof(mng_fpri, iPriority), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_nEED -MNG_LOCAL mng_field_descriptor mng_fields_need [] = - { - {MNG_NULL, - MNG_NULL, - 0, 0, 1, 0, - offsetof(mng_need, zKeywords), MNG_NULL, offsetof(mng_need, iKeywordssize)} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_pHYg -#define mng_fields_phyg mng_fields_phys -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -MNG_LOCAL mng_field_descriptor mng_fields_dhdr [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFFFF, 2, 2, - offsetof(mng_dhdr, iObjectid), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 2, 1, 1, - offsetof(mng_dhdr, iImagetype), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 7, 1, 1, - offsetof(mng_dhdr, iDeltatype), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, - 0, 0, 4, 4, - offsetof(mng_dhdr, iBlockwidth), offsetof(mng_dhdr, bHasblocksize), MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, - 0, 0, 4, 4, - offsetof(mng_dhdr, iBlockheight), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP2, - 0, 0, 4, 4, - offsetof(mng_dhdr, iBlockx), offsetof(mng_dhdr, bHasblockloc), MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP2, - 0, 0, 4, 4, - offsetof(mng_dhdr, iBlocky), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -MNG_LOCAL mng_field_descriptor mng_fields_prom [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 14, 1, 1, - offsetof(mng_prom, iColortype), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 16, 1, 1, - offsetof(mng_prom, iSampledepth), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 1, 1, 1, - offsetof(mng_prom, iFilltype), MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -MNG_LOCAL mng_field_descriptor mng_fields_pplt [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 5, 1, 1, - offsetof(mng_pplt, iDeltatype), MNG_NULL, MNG_NULL}, - {mng_pplt_entries, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -MNG_LOCAL mng_field_descriptor mng_fields_drop [] = - { - {mng_drop_entries, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DBYK -MNG_LOCAL mng_field_descriptor mng_fields_dbyk [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_dbyk, iChunkname), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 1, 1, 1, - offsetof(mng_dbyk, iPolarity), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_NULL, - 0, 0, 1, 0, - offsetof(mng_dbyk, zKeywords), MNG_NULL, offsetof(mng_dbyk, iKeywordssize)} - }; -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR -MNG_LOCAL mng_field_descriptor mng_fields_ordr [] = - { - {mng_drop_entries, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MAGN -MNG_LOCAL mng_field_descriptor mng_fields_magn [] = - { - {mng_debunk_magn, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_MPNG_PROPOSAL -MNG_LOCAL mng_field_descriptor mng_fields_mpng [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 1, 0, 4, 4, - offsetof(mng_mpng, iFramewidth), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 1, 0, 4, 4, - offsetof(mng_mpng, iFrameheight), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0xFFFF, 2, 2, - offsetof(mng_mpng, iNumplays), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 1, 0xFFFF, 2, 2, - offsetof(mng_mpng, iTickspersec), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 1, 1, - offsetof(mng_mpng, iCompressionmethod), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_DEFLATED, - 0, 0, 1, 0, - offsetof(mng_mpng, pFrames), MNG_NULL, offsetof(mng_mpng, iFramessize)} - }; -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ANG_PROPOSAL -MNG_LOCAL mng_field_descriptor mng_fields_ahdr [] = - { - {MNG_NULL, - MNG_FIELD_INT, - 1, 0, 4, 4, - offsetof(mng_ahdr, iNumframes), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_ahdr, iTickspersec), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 0, 4, 4, - offsetof(mng_ahdr, iNumplays), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 1, 0, 4, 4, - offsetof(mng_ahdr, iTilewidth), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 1, 0, 4, 4, - offsetof(mng_ahdr, iTileheight), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 1, 1, 1, - offsetof(mng_ahdr, iInterlace), MNG_NULL, MNG_NULL}, - {MNG_NULL, - MNG_FIELD_INT, - 0, 1, 1, 1, - offsetof(mng_ahdr, iStillused), MNG_NULL, MNG_NULL} - }; - -MNG_LOCAL mng_field_descriptor mng_fields_adat [] = - { - {mng_adat_tiles, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_evNT -MNG_LOCAL mng_field_descriptor mng_fields_evnt [] = - { - {mng_evnt_entries, - MNG_NULL, - 0, 0, 0, 0, - MNG_NULL, MNG_NULL, MNG_NULL} - }; -#endif - -/* ************************************************************************** */ - -MNG_LOCAL mng_field_descriptor mng_fields_unknown [] = - { - {MNG_NULL, - MNG_NULL, - 0, 0, 1, 0, - offsetof(mng_unknown_chunk, pData), MNG_NULL, offsetof(mng_unknown_chunk, iDatasize)} - }; - -/* ************************************************************************** */ -/* ************************************************************************** */ -/* PNG chunks */ - -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ihdr = - {mng_it_png, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_ihdr, - mng_fields_ihdr, (sizeof(mng_fields_ihdr) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL, - MNG_NULL, - MNG_DESCR_NOIHDR | MNG_DESCR_NOJHDR | MNG_DESCR_NOBASI | MNG_DESCR_NOIDAT | MNG_DESCR_NOPLTE}; - -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_plte = - {mng_it_png, mng_create_none, 0, offsetof(mng_plte, bEmpty), - MNG_NULL, MNG_NULL, mng_special_plte, - mng_fields_plte, (sizeof(mng_fields_plte) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED, - MNG_DESCR_GenHDR, - MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; - -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_idat = - {mng_it_png, mng_create_none, 0, offsetof(mng_idat, bEmpty), - MNG_NULL, MNG_NULL, mng_special_idat, - mng_fields_idat, (sizeof(mng_fields_idat) / sizeof(mng_field_descriptor)), - MNG_DESCR_EMPTYEMBED, - MNG_DESCR_GenHDR, - MNG_DESCR_NOJSEP}; - -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_iend = - {mng_it_png, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_iend, - MNG_NULL, 0, - MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, - MNG_DESCR_GenHDR, - MNG_NULL}; - -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_trns = - {mng_it_png, mng_create_none, 0, offsetof(mng_trns, bEmpty), - MNG_NULL, MNG_NULL, mng_special_trns, - mng_fields_trns, (sizeof(mng_fields_trns) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED, - MNG_DESCR_GenHDR, - MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; - -#ifndef MNG_SKIPCHUNK_gAMA -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_gama = - {mng_it_png, mng_create_none, 0, offsetof(mng_gama, bEmpty), - MNG_NULL, MNG_NULL, mng_special_gama, - mng_fields_gama, (sizeof(mng_fields_gama) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, - MNG_DESCR_GenHDR, - MNG_DESCR_NOPLTE | MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; -#endif - -#ifndef MNG_SKIPCHUNK_cHRM -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_chrm = - {mng_it_png, mng_create_none, 0, offsetof(mng_chrm, bEmpty), - MNG_NULL, MNG_NULL, mng_special_chrm, - mng_fields_chrm, (sizeof(mng_fields_chrm) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, - MNG_DESCR_GenHDR, - MNG_DESCR_NOPLTE | MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; -#endif - -#ifndef MNG_SKIPCHUNK_sRGB -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_srgb = - {mng_it_png, mng_create_none, 0, offsetof(mng_srgb, bEmpty), - MNG_NULL, MNG_NULL, mng_special_srgb, - mng_fields_srgb, (sizeof(mng_fields_srgb) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, - MNG_DESCR_GenHDR, - MNG_DESCR_NOPLTE | MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; -#endif - -#ifndef MNG_SKIPCHUNK_iCCP -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_iccp = - {mng_it_png, mng_create_none, 0, offsetof(mng_iccp, bEmpty), - MNG_NULL, MNG_NULL, mng_special_iccp, - mng_fields_iccp, (sizeof(mng_fields_iccp) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, - MNG_DESCR_GenHDR, - MNG_DESCR_NOPLTE | MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; -#endif - -#ifndef MNG_SKIPCHUNK_tEXt -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_text = - {mng_it_png, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_text, - mng_fields_text, (sizeof(mng_fields_text) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL, - MNG_DESCR_GenHDR, - MNG_NULL}; -#endif - -#ifndef MNG_SKIPCHUNK_zTXt -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ztxt = - {mng_it_png, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_ztxt, - mng_fields_ztxt, (sizeof(mng_fields_ztxt) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL, - MNG_DESCR_GenHDR, - MNG_NULL}; -#endif - -#ifndef MNG_SKIPCHUNK_iTXt -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_itxt = - {mng_it_png, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_itxt, - mng_fields_itxt, (sizeof(mng_fields_itxt) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL, - MNG_DESCR_GenHDR, - MNG_NULL}; -#endif - -#ifndef MNG_SKIPCHUNK_bKGD -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_bkgd = - {mng_it_png, mng_create_none, 0, offsetof(mng_bkgd, bEmpty), - MNG_NULL, MNG_NULL, mng_special_bkgd, - mng_fields_bkgd, (sizeof(mng_fields_bkgd) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, - MNG_DESCR_GenHDR, - MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; -#endif - -#ifndef MNG_SKIPCHUNK_pHYs -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_phys = - {mng_it_png, mng_create_none, 0, offsetof(mng_phys, bEmpty), - MNG_NULL, MNG_NULL, mng_special_phys, - mng_fields_phys, (sizeof(mng_fields_phys) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, - MNG_DESCR_GenHDR, - MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; -#endif - -#ifndef MNG_SKIPCHUNK_sBIT -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_sbit = - {mng_it_png, mng_create_none, 0, offsetof(mng_sbit, bEmpty), - MNG_NULL, MNG_NULL, mng_special_sbit, - mng_fields_sbit, (sizeof(mng_fields_sbit) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, - MNG_DESCR_GenHDR, - MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; -#endif - -#ifndef MNG_SKIPCHUNK_sPLT -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_splt = - {mng_it_png, mng_create_none, 0, offsetof(mng_splt, bEmpty), - MNG_NULL, MNG_NULL, mng_special_splt, - mng_fields_splt, (sizeof(mng_fields_splt) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, - MNG_DESCR_GenHDR, - MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; -#endif - -#ifndef MNG_SKIPCHUNK_hIST -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_hist = - {mng_it_png, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_hist, - mng_fields_hist, (sizeof(mng_fields_hist) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_GenHDR | MNG_DESCR_PLTE, - MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; -#endif - -#ifndef MNG_SKIPCHUNK_tIME -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_time = - {mng_it_png, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_time, - mng_fields_time, (sizeof(mng_fields_time) / sizeof(mng_field_descriptor)), - MNG_DESCR_GLOBAL, - MNG_DESCR_GenHDR, - MNG_NULL}; -#endif - -/* ************************************************************************** */ -/* JNG chunks */ - -#ifdef MNG_INCLUDE_JNG -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_jhdr = - {mng_it_jng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_jhdr, - mng_fields_jhdr, (sizeof(mng_fields_jhdr) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_NULL, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifdef MNG_INCLUDE_JNG -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_jdaa = - {mng_it_jng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_jdaa, - mng_fields_jdaa, (sizeof(mng_fields_jdaa) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_JngHDR, - MNG_DESCR_NOJSEP}; -#endif - -#ifdef MNG_INCLUDE_JNG -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_jdat = - {mng_it_jng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_jdat, - mng_fields_jdat, (sizeof(mng_fields_jdat) / sizeof(mng_field_descriptor)), - MNG_DESCR_EMPTYEMBED, - MNG_DESCR_JngHDR, - MNG_NULL}; -#endif - -#ifdef MNG_INCLUDE_JNG -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_jsep = - {mng_it_jng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_jsep, - MNG_NULL, 0, - MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, - MNG_DESCR_JngHDR, - MNG_DESCR_NOJSEP}; -#endif - -/* ************************************************************************** */ -/* MNG chunks */ - -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_mhdr = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_mhdr, - mng_fields_mhdr, (sizeof(mng_fields_mhdr) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_NULL, - MNG_DESCR_NOMHDR | MNG_DESCR_NOIHDR | MNG_DESCR_NOJHDR}; - -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_mend = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_mend, - MNG_NULL, 0, - MNG_DESCR_EMPTY | MNG_DESCR_EMPTYGLOBAL, - MNG_DESCR_MHDR, - MNG_NULL}; - -#ifndef MNG_SKIPCHUNK_LOOP -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_loop = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_loop, - mng_fields_loop, (sizeof(mng_fields_loop) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; - -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_endl = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_endl, - mng_fields_endl, (sizeof(mng_fields_endl) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_DEFI -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_defi = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_defi, - mng_fields_defi, (sizeof(mng_fields_defi) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_BASI -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_basi = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_basi, - mng_fields_basi, (sizeof(mng_fields_basi) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_CLON -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_clon = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_clon, - mng_fields_clon, (sizeof(mng_fields_clon) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_PAST -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_past = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_past, - mng_fields_past, (sizeof(mng_fields_past) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_DISC -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_disc = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_disc, - mng_fields_disc, (sizeof(mng_fields_disc) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_BACK -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_back = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_back, - mng_fields_back, (sizeof(mng_fields_back) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_FRAM -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_fram = - {mng_it_mng, mng_create_none, 0, offsetof(mng_fram, bEmpty), - MNG_NULL, MNG_NULL, mng_special_fram, - mng_fields_fram, (sizeof(mng_fields_fram) / sizeof(mng_field_descriptor)), - MNG_DESCR_EMPTY | MNG_DESCR_EMPTYGLOBAL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_MOVE -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_move = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_move, - mng_fields_move, (sizeof(mng_fields_move) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_CLIP -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_clip = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_clip, - mng_fields_clip, (sizeof(mng_fields_clip) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_SHOW -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_show = - {mng_it_mng, mng_create_none, 0, offsetof(mng_show, bEmpty), - MNG_NULL, MNG_NULL, mng_special_show, - mng_fields_show, (sizeof(mng_fields_show) / sizeof(mng_field_descriptor)), - MNG_DESCR_EMPTY | MNG_DESCR_EMPTYGLOBAL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_TERM -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_term = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_term, - mng_fields_term, (sizeof(mng_fields_term) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR | MNG_DESCR_NOTERM | MNG_DESCR_NOLOOP}; -#endif - -#ifndef MNG_SKIPCHUNK_SAVE -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_save = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_save, - mng_fields_save, (sizeof(mng_fields_save) / sizeof(mng_field_descriptor)), - MNG_DESCR_EMPTY | MNG_DESCR_EMPTYGLOBAL, - MNG_DESCR_MHDR, - MNG_DESCR_NOSAVE | MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_SEEK -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_seek = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_seek, - mng_fields_seek, (sizeof(mng_fields_seek) / sizeof(mng_field_descriptor)), - MNG_DESCR_EMPTY | MNG_DESCR_EMPTYGLOBAL, - MNG_DESCR_MHDR | MNG_DESCR_SAVE, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_eXPI -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_expi = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_expi, - mng_fields_expi, (sizeof(mng_fields_expi) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_fPRI -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_fpri = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_fpri, - mng_fields_fpri, (sizeof(mng_fields_fpri) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_nEED -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_need = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_need, - mng_fields_need, (sizeof(mng_fields_need) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_pHYg -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_phyg = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_phyg, - mng_fields_phyg, (sizeof(mng_fields_phyg) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_NO_DELTA_PNG -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_dhdr = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_dhdr, - mng_fields_dhdr, (sizeof(mng_fields_dhdr) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_NO_DELTA_PNG -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_prom = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_prom, - mng_fields_prom, (sizeof(mng_fields_prom) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR | MNG_DESCR_DHDR, - MNG_NULL}; -#endif - -#ifndef MNG_NO_DELTA_PNG -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ipng = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_ipng, - MNG_NULL, 0, - MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, - MNG_DESCR_MHDR | MNG_DESCR_DHDR, - MNG_NULL}; -#endif - -#ifndef MNG_NO_DELTA_PNG -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_pplt = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_pplt, - mng_fields_pplt, (sizeof(mng_fields_pplt) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR | MNG_DESCR_DHDR, - MNG_NULL}; -#endif - -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ijng = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_ijng, - MNG_NULL, 0, - MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, - MNG_DESCR_MHDR | MNG_DESCR_DHDR, - MNG_NULL}; -#endif -#endif - -#ifndef MNG_NO_DELTA_PNG -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_drop = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_drop, - mng_fields_drop, (sizeof(mng_fields_drop) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR | MNG_DESCR_DHDR, - MNG_NULL}; -#endif - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DBYK -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_dbyk = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_dbyk, - mng_fields_dbyk, (sizeof(mng_fields_dbyk) / sizeof(mng_field_descriptor)), - MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, - MNG_DESCR_MHDR | MNG_DESCR_DHDR, - MNG_NULL}; -#endif -#endif - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ordr = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_ordr, - mng_fields_ordr, (sizeof(mng_fields_ordr) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR | MNG_DESCR_DHDR, - MNG_NULL}; -#endif -#endif - -#ifndef MNG_SKIPCHUNK_MAGN -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_magn = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_magn, - mng_fields_magn, (sizeof(mng_fields_magn) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; -#endif - -#ifndef MNG_SKIPCHUNK_evNT -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_evnt = - {mng_it_mng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_evnt, - mng_fields_evnt, (sizeof(mng_fields_evnt) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_MHDR, - MNG_DESCR_NOSAVE}; -#endif - -#ifdef MNG_INCLUDE_MPNG_PROPOSAL -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_mpng = - {mng_it_mpng, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_mpng, - mng_fields_mpng, (sizeof(mng_fields_mpng) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_NULL, - MNG_DESCR_NOMHDR | MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT}; -#endif - -#ifdef MNG_INCLUDE_ANG_PROPOSAL -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ahdr = - {mng_it_ang, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_ahdr, - mng_fields_ahdr, (sizeof(mng_fields_ahdr) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_IHDR, - MNG_DESCR_NOMHDR | MNG_DESCR_NOJHDR | MNG_DESCR_NOIDAT}; - -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_adat = - {mng_it_ang, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_adat, - mng_fields_adat, (sizeof(mng_fields_adat) / sizeof(mng_field_descriptor)), - MNG_NULL, - MNG_DESCR_IHDR, - MNG_DESCR_NOMHDR | MNG_DESCR_NOJHDR}; -#endif - -/* ************************************************************************** */ -/* ************************************************************************** */ -/* the good ol' unknown babe */ - -MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_unknown = - {mng_it_png, mng_create_none, 0, 0, - MNG_NULL, MNG_NULL, mng_special_unknown, - mng_fields_unknown, (sizeof(mng_fields_unknown) / sizeof(mng_field_descriptor)), - MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, - MNG_NULL, - MNG_NULL}; - -/* ************************************************************************** */ -/* ************************************************************************** */ - -MNG_LOCAL mng_chunk_header mng_chunk_unknown = - {MNG_UINT_HUH, mng_init_general, mng_free_unknown, - mng_read_general, mng_write_unknown, mng_assign_unknown, - 0, 0, sizeof(mng_unknown_chunk), &mng_chunk_descr_unknown}; - -/* ************************************************************************** */ - - /* the table-idea & binary search code was adapted from - libpng 1.1.0 (pngread.c) */ - /* NOTE1: the table must remain sorted by chunkname, otherwise the binary - search will break !!! (ps. watch upper-/lower-case chunknames !!) */ - /* NOTE2: the layout must remain equal to the header part of all the - chunk-structures (yes, that means even the pNext and pPrev fields; - it's wasting a bit of space, but hey, the code is a lot easier) */ - -MNG_LOCAL mng_chunk_header mng_chunk_table [] = - { -#ifndef MNG_SKIPCHUNK_BACK - {MNG_UINT_BACK, mng_init_general, mng_free_general, mng_read_general, mng_write_back, mng_assign_general, 0, 0, sizeof(mng_back), &mng_chunk_descr_back}, -#endif -#ifndef MNG_SKIPCHUNK_BASI - {MNG_UINT_BASI, mng_init_general, mng_free_general, mng_read_general, mng_write_basi, mng_assign_general, 0, 0, sizeof(mng_basi), &mng_chunk_descr_basi}, -#endif -#ifndef MNG_SKIPCHUNK_CLIP - {MNG_UINT_CLIP, mng_init_general, mng_free_general, mng_read_general, mng_write_clip, mng_assign_general, 0, 0, sizeof(mng_clip), &mng_chunk_descr_clip}, -#endif -#ifndef MNG_SKIPCHUNK_CLON - {MNG_UINT_CLON, mng_init_general, mng_free_general, mng_read_general, mng_write_clon, mng_assign_general, 0, 0, sizeof(mng_clon), &mng_chunk_descr_clon}, -#endif -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DBYK - {MNG_UINT_DBYK, mng_init_general, mng_free_dbyk, mng_read_general, mng_write_dbyk, mng_assign_dbyk, 0, 0, sizeof(mng_dbyk), &mng_chunk_descr_dbyk}, -#endif -#endif -#ifndef MNG_SKIPCHUNK_DEFI - {MNG_UINT_DEFI, mng_init_general, mng_free_general, mng_read_general, mng_write_defi, mng_assign_general, 0, 0, sizeof(mng_defi), &mng_chunk_descr_defi}, -#endif -#ifndef MNG_NO_DELTA_PNG - {MNG_UINT_DHDR, mng_init_general, mng_free_general, mng_read_general, mng_write_dhdr, mng_assign_general, 0, 0, sizeof(mng_dhdr), &mng_chunk_descr_dhdr}, -#endif -#ifndef MNG_SKIPCHUNK_DISC - {MNG_UINT_DISC, mng_init_general, mng_free_disc, mng_read_general, mng_write_disc, mng_assign_disc, 0, 0, sizeof(mng_disc), &mng_chunk_descr_disc}, -#endif -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DROP - {MNG_UINT_DROP, mng_init_general, mng_free_drop, mng_read_general, mng_write_drop, mng_assign_drop, 0, 0, sizeof(mng_drop), &mng_chunk_descr_drop}, -#endif -#endif -#ifndef MNG_SKIPCHUNK_LOOP - {MNG_UINT_ENDL, mng_init_general, mng_free_general, mng_read_general, mng_write_endl, mng_assign_general, 0, 0, sizeof(mng_endl), &mng_chunk_descr_endl}, -#endif -#ifndef MNG_SKIPCHUNK_FRAM - {MNG_UINT_FRAM, mng_init_general, mng_free_fram, mng_read_general, mng_write_fram, mng_assign_fram, 0, 0, sizeof(mng_fram), &mng_chunk_descr_fram}, -#endif - {MNG_UINT_IDAT, mng_init_general, mng_free_idat, mng_read_general, mng_write_idat, mng_assign_idat, 0, 0, sizeof(mng_idat), &mng_chunk_descr_idat}, /* 12-th element! */ - {MNG_UINT_IEND, mng_init_general, mng_free_general, mng_read_general, mng_write_iend, mng_assign_general, 0, 0, sizeof(mng_iend), &mng_chunk_descr_iend}, - {MNG_UINT_IHDR, mng_init_general, mng_free_general, mng_read_general, mng_write_ihdr, mng_assign_general, 0, 0, sizeof(mng_ihdr), &mng_chunk_descr_ihdr}, -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG - {MNG_UINT_IJNG, mng_init_general, mng_free_general, mng_read_general, mng_write_ijng, mng_assign_general, 0, 0, sizeof(mng_ijng), &mng_chunk_descr_ijng}, -#endif - {MNG_UINT_IPNG, mng_init_general, mng_free_general, mng_read_general, mng_write_ipng, mng_assign_general, 0, 0, sizeof(mng_ipng), &mng_chunk_descr_ipng}, -#endif -#ifdef MNG_INCLUDE_JNG - {MNG_UINT_JDAA, mng_init_general, mng_free_jdaa, mng_read_general, mng_write_jdaa, mng_assign_jdaa, 0, 0, sizeof(mng_jdaa), &mng_chunk_descr_jdaa}, - {MNG_UINT_JDAT, mng_init_general, mng_free_jdat, mng_read_general, mng_write_jdat, mng_assign_jdat, 0, 0, sizeof(mng_jdat), &mng_chunk_descr_jdat}, - {MNG_UINT_JHDR, mng_init_general, mng_free_general, mng_read_general, mng_write_jhdr, mng_assign_general, 0, 0, sizeof(mng_jhdr), &mng_chunk_descr_jhdr}, - {MNG_UINT_JSEP, mng_init_general, mng_free_general, mng_read_general, mng_write_jsep, mng_assign_general, 0, 0, sizeof(mng_jsep), &mng_chunk_descr_jsep}, - {MNG_UINT_JdAA, mng_init_general, mng_free_jdaa, mng_read_general, mng_write_jdaa, mng_assign_jdaa, 0, 0, sizeof(mng_jdaa), &mng_chunk_descr_jdaa}, -#endif -#ifndef MNG_SKIPCHUNK_LOOP - {MNG_UINT_LOOP, mng_init_general, mng_free_loop, mng_read_general, mng_write_loop, mng_assign_loop, 0, 0, sizeof(mng_loop), &mng_chunk_descr_loop}, -#endif -#ifndef MNG_SKIPCHUNK_MAGN - {MNG_UINT_MAGN, mng_init_general, mng_free_general, mng_read_general, mng_write_magn, mng_assign_general, 0, 0, sizeof(mng_magn), &mng_chunk_descr_magn}, -#endif - {MNG_UINT_MEND, mng_init_general, mng_free_general, mng_read_general, mng_write_mend, mng_assign_general, 0, 0, sizeof(mng_mend), &mng_chunk_descr_mend}, - {MNG_UINT_MHDR, mng_init_general, mng_free_general, mng_read_general, mng_write_mhdr, mng_assign_general, 0, 0, sizeof(mng_mhdr), &mng_chunk_descr_mhdr}, -#ifndef MNG_SKIPCHUNK_MOVE - {MNG_UINT_MOVE, mng_init_general, mng_free_general, mng_read_general, mng_write_move, mng_assign_general, 0, 0, sizeof(mng_move), &mng_chunk_descr_move}, -#endif -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR - {MNG_UINT_ORDR, mng_init_general, mng_free_ordr, mng_read_general, mng_write_ordr, mng_assign_ordr, 0, 0, sizeof(mng_ordr), &mng_chunk_descr_ordr}, -#endif -#endif -#ifndef MNG_SKIPCHUNK_PAST - {MNG_UINT_PAST, mng_init_general, mng_free_past, mng_read_general, mng_write_past, mng_assign_past, 0, 0, sizeof(mng_past), &mng_chunk_descr_past}, -#endif - {MNG_UINT_PLTE, mng_init_general, mng_free_general, mng_read_general, mng_write_plte, mng_assign_general, 0, 0, sizeof(mng_plte), &mng_chunk_descr_plte}, -#ifndef MNG_NO_DELTA_PNG - {MNG_UINT_PPLT, mng_init_general, mng_free_general, mng_read_general, mng_write_pplt, mng_assign_general, 0, 0, sizeof(mng_pplt), &mng_chunk_descr_pplt}, - {MNG_UINT_PROM, mng_init_general, mng_free_general, mng_read_general, mng_write_prom, mng_assign_general, 0, 0, sizeof(mng_prom), &mng_chunk_descr_prom}, -#endif -#ifndef MNG_SKIPCHUNK_SAVE - {MNG_UINT_SAVE, mng_init_general, mng_free_save, mng_read_general, mng_write_save, mng_assign_save, 0, 0, sizeof(mng_save), &mng_chunk_descr_save}, -#endif -#ifndef MNG_SKIPCHUNK_SEEK - {MNG_UINT_SEEK, mng_init_general, mng_free_seek, mng_read_general, mng_write_seek, mng_assign_seek, 0, 0, sizeof(mng_seek), &mng_chunk_descr_seek}, -#endif -#ifndef MNG_SKIPCHUNK_SHOW - {MNG_UINT_SHOW, mng_init_general, mng_free_general, mng_read_general, mng_write_show, mng_assign_general, 0, 0, sizeof(mng_show), &mng_chunk_descr_show}, -#endif -#ifndef MNG_SKIPCHUNK_TERM - {MNG_UINT_TERM, mng_init_general, mng_free_general, mng_read_general, mng_write_term, mng_assign_general, 0, 0, sizeof(mng_term), &mng_chunk_descr_term}, -#endif -#ifdef MNG_INCLUDE_ANG_PROPOSAL - {MNG_UINT_adAT, mng_init_general, mng_free_adat, mng_read_general, mng_write_adat, mng_assign_adat, 0, 0, sizeof(mng_adat), &mng_chunk_descr_adat}, - {MNG_UINT_ahDR, mng_init_general, mng_free_general, mng_read_general, mng_write_ahdr, mng_assign_ahdr, 0, 0, sizeof(mng_ahdr), &mng_chunk_descr_ahdr}, -#endif -#ifndef MNG_SKIPCHUNK_bKGD - {MNG_UINT_bKGD, mng_init_general, mng_free_general, mng_read_general, mng_write_bkgd, mng_assign_general, 0, 0, sizeof(mng_bkgd), &mng_chunk_descr_bkgd}, -#endif -#ifndef MNG_SKIPCHUNK_cHRM - {MNG_UINT_cHRM, mng_init_general, mng_free_general, mng_read_general, mng_write_chrm, mng_assign_general, 0, 0, sizeof(mng_chrm), &mng_chunk_descr_chrm}, -#endif -#ifndef MNG_SKIPCHUNK_eXPI - {MNG_UINT_eXPI, mng_init_general, mng_free_expi, mng_read_general, mng_write_expi, mng_assign_expi, 0, 0, sizeof(mng_expi), &mng_chunk_descr_expi}, -#endif -#ifndef MNG_SKIPCHUNK_evNT - {MNG_UINT_evNT, mng_init_general, mng_free_evnt, mng_read_general, mng_write_evnt, mng_assign_evnt, 0, 0, sizeof(mng_evnt), &mng_chunk_descr_evnt}, -#endif -#ifndef MNG_SKIPCHUNK_fPRI - {MNG_UINT_fPRI, mng_init_general, mng_free_general, mng_read_general, mng_write_fpri, mng_assign_general, 0, 0, sizeof(mng_fpri), &mng_chunk_descr_fpri}, -#endif -#ifndef MNG_SKIPCHUNK_gAMA - {MNG_UINT_gAMA, mng_init_general, mng_free_general, mng_read_general, mng_write_gama, mng_assign_general, 0, 0, sizeof(mng_gama), &mng_chunk_descr_gama}, -#endif -#ifndef MNG_SKIPCHUNK_hIST - {MNG_UINT_hIST, mng_init_general, mng_free_general, mng_read_general, mng_write_hist, mng_assign_general, 0, 0, sizeof(mng_hist), &mng_chunk_descr_hist}, -#endif -#ifndef MNG_SKIPCHUNK_iCCP - {MNG_UINT_iCCP, mng_init_general, mng_free_iccp, mng_read_general, mng_write_iccp, mng_assign_iccp, 0, 0, sizeof(mng_iccp), &mng_chunk_descr_iccp}, -#endif -#ifndef MNG_SKIPCHUNK_iTXt - {MNG_UINT_iTXt, mng_init_general, mng_free_itxt, mng_read_general, mng_write_itxt, mng_assign_itxt, 0, 0, sizeof(mng_itxt), &mng_chunk_descr_itxt}, -#endif -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - {MNG_UINT_mpNG, mng_init_general, mng_free_mpng, mng_read_general, mng_write_mpng, mng_assign_mpng, 0, 0, sizeof(mng_mpng), &mng_chunk_descr_mpng}, -#endif -#ifndef MNG_SKIPCHUNK_nEED - {MNG_UINT_nEED, mng_init_general, mng_free_need, mng_read_general, mng_write_need, mng_assign_need, 0, 0, sizeof(mng_need), &mng_chunk_descr_need}, -#endif -/* TODO: {MNG_UINT_oFFs, 0, 0, 0, 0, 0, 0}, */ -/* TODO: {MNG_UINT_pCAL, 0, 0, 0, 0, 0, 0}, */ -#ifndef MNG_SKIPCHUNK_pHYg - {MNG_UINT_pHYg, mng_init_general, mng_free_general, mng_read_general, mng_write_phyg, mng_assign_general, 0, 0, sizeof(mng_phyg), &mng_chunk_descr_phyg}, -#endif -#ifndef MNG_SKIPCHUNK_pHYs - {MNG_UINT_pHYs, mng_init_general, mng_free_general, mng_read_general, mng_write_phys, mng_assign_general, 0, 0, sizeof(mng_phys), &mng_chunk_descr_phys}, -#endif -#ifndef MNG_SKIPCHUNK_sBIT - {MNG_UINT_sBIT, mng_init_general, mng_free_general, mng_read_general, mng_write_sbit, mng_assign_general, 0, 0, sizeof(mng_sbit), &mng_chunk_descr_sbit}, -#endif -/* TODO: {MNG_UINT_sCAL, 0, 0, 0, 0, 0, 0}, */ -#ifndef MNG_SKIPCHUNK_sPLT - {MNG_UINT_sPLT, mng_init_general, mng_free_splt, mng_read_general, mng_write_splt, mng_assign_splt, 0, 0, sizeof(mng_splt), &mng_chunk_descr_splt}, -#endif - {MNG_UINT_sRGB, mng_init_general, mng_free_general, mng_read_general, mng_write_srgb, mng_assign_general, 0, 0, sizeof(mng_srgb), &mng_chunk_descr_srgb}, -#ifndef MNG_SKIPCHUNK_tEXt - {MNG_UINT_tEXt, mng_init_general, mng_free_text, mng_read_general, mng_write_text, mng_assign_text, 0, 0, sizeof(mng_text), &mng_chunk_descr_text}, -#endif -#ifndef MNG_SKIPCHUNK_tIME - {MNG_UINT_tIME, mng_init_general, mng_free_general, mng_read_general, mng_write_time, mng_assign_general, 0, 0, sizeof(mng_time), &mng_chunk_descr_time}, -#endif - {MNG_UINT_tRNS, mng_init_general, mng_free_general, mng_read_general, mng_write_trns, mng_assign_general, 0, 0, sizeof(mng_trns), &mng_chunk_descr_trns}, -#ifndef MNG_SKIPCHUNK_zTXt - {MNG_UINT_zTXt, mng_init_general, mng_free_ztxt, mng_read_general, mng_write_ztxt, mng_assign_ztxt, 0, 0, sizeof(mng_ztxt), &mng_chunk_descr_ztxt}, -#endif - }; - -/* ************************************************************************** */ -/* ************************************************************************** */ - -void mng_get_chunkheader (mng_chunkid iChunkname, - mng_chunk_headerp pResult) -{ - /* binary search variables */ - mng_int32 iTop, iLower, iUpper, iMiddle; - mng_chunk_headerp pEntry; /* pointer to found entry */ - /* determine max index of table */ - iTop = (sizeof (mng_chunk_table) / sizeof (mng_chunk_table [0])) - 1; - - /* binary search; with 54 chunks, worst-case is 7 comparisons */ - iLower = 0; -#ifndef MNG_NO_DELTA_PNG - iMiddle = 11; /* start with the IDAT entry */ -#else - iMiddle = 8; -#endif - iUpper = iTop; - pEntry = 0; /* no goods yet! */ - - do /* the binary search itself */ - { - if (mng_chunk_table [iMiddle].iChunkname < iChunkname) - iLower = iMiddle + 1; - else if (mng_chunk_table [iMiddle].iChunkname > iChunkname) - iUpper = iMiddle - 1; - else - { - pEntry = &mng_chunk_table [iMiddle]; - break; - } - iMiddle = (iLower + iUpper) >> 1; - } - while (iLower <= iUpper); - - if (!pEntry) /* unknown chunk ? */ - pEntry = &mng_chunk_unknown; /* make it so! */ - - MNG_COPY (pResult, pEntry, sizeof(mng_chunk_header)); - - return; -} - -/* ************************************************************************** */ -/* ************************************************************************** */ -/* PNG chunks */ - -MNG_C_SPECIALFUNC (mng_special_ihdr) -{ - pData->bHasIHDR = MNG_TRUE; /* indicate IHDR is present */ - /* and store interesting fields */ - if ((!pData->bHasDHDR) || (pData->iDeltatype == MNG_DELTATYPE_NOCHANGE)) - { - pData->iDatawidth = ((mng_ihdrp)pChunk)->iWidth; - pData->iDataheight = ((mng_ihdrp)pChunk)->iHeight; - } - - pData->iBitdepth = ((mng_ihdrp)pChunk)->iBitdepth; - pData->iColortype = ((mng_ihdrp)pChunk)->iColortype; - pData->iCompression = ((mng_ihdrp)pChunk)->iCompression; - pData->iFilter = ((mng_ihdrp)pChunk)->iFilter; - pData->iInterlace = ((mng_ihdrp)pChunk)->iInterlace; - -#if defined(MNG_NO_1_2_4BIT_SUPPORT) || defined(MNG_NO_16BIT_SUPPORT) - pData->iPNGmult = 1; - pData->iPNGdepth = pData->iBitdepth; -#endif - -#ifdef MNG_NO_1_2_4BIT_SUPPORT - if (pData->iBitdepth < 8) - pData->iBitdepth = 8; -#endif - -#ifdef MNG_NO_16BIT_SUPPORT - if (pData->iBitdepth > 8) - { - pData->iBitdepth = 8; - pData->iPNGmult = 2; - } -#endif - - if ((pData->iBitdepth != 8) /* parameter validity checks */ -#ifndef MNG_NO_1_2_4BIT_SUPPORT - && (pData->iBitdepth != 1) && - (pData->iBitdepth != 2) && - (pData->iBitdepth != 4) -#endif -#ifndef MNG_NO_16BIT_SUPPORT - && (pData->iBitdepth != 16) -#endif - ) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if ((pData->iColortype != MNG_COLORTYPE_GRAY ) && - (pData->iColortype != MNG_COLORTYPE_RGB ) && - (pData->iColortype != MNG_COLORTYPE_INDEXED) && - (pData->iColortype != MNG_COLORTYPE_GRAYA ) && - (pData->iColortype != MNG_COLORTYPE_RGBA ) ) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - - if ((pData->iColortype == MNG_COLORTYPE_INDEXED) && (pData->iBitdepth > 8)) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if (((pData->iColortype == MNG_COLORTYPE_RGB ) || - (pData->iColortype == MNG_COLORTYPE_GRAYA ) || - (pData->iColortype == MNG_COLORTYPE_RGBA ) ) && - (pData->iBitdepth < 8 ) ) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if (pData->iCompression != MNG_COMPRESSION_DEFLATE) - MNG_ERROR (pData, MNG_INVALIDCOMPRESS); - -#if defined(FILTER192) || defined(FILTER193) - if ((pData->iFilter != MNG_FILTER_ADAPTIVE ) && -#if defined(FILTER192) && defined(FILTER193) - (pData->iFilter != MNG_FILTER_DIFFERING) && - (pData->iFilter != MNG_FILTER_NOFILTER ) ) -#else -#ifdef FILTER192 - (pData->iFilter != MNG_FILTER_DIFFERING) ) -#else - (pData->iFilter != MNG_FILTER_NOFILTER ) ) -#endif -#endif - MNG_ERROR (pData, MNG_INVALIDFILTER); -#else - if (pData->iFilter) - MNG_ERROR (pData, MNG_INVALIDFILTER); -#endif - - if ((pData->iInterlace != MNG_INTERLACE_NONE ) && - (pData->iInterlace != MNG_INTERLACE_ADAM7) ) - MNG_ERROR (pData, MNG_INVALIDINTERLACE); - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* check the colortype for delta-images ! */ - { - mng_imagedatap pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; - - if (pData->iColortype != pBuf->iColortype) - { - if ( ( (pData->iColortype != MNG_COLORTYPE_INDEXED) || - (pBuf->iColortype == MNG_COLORTYPE_GRAY ) ) && - ( (pData->iColortype != MNG_COLORTYPE_GRAY ) || - (pBuf->iColortype == MNG_COLORTYPE_INDEXED) ) ) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - } - } -#endif -#endif - - if (!pData->bHasheader) /* first chunk ? */ - { - pData->bHasheader = MNG_TRUE; /* we've got a header */ - pData->eImagetype = mng_it_png; /* then this must be a PNG */ - pData->iWidth = pData->iDatawidth; - pData->iHeight = pData->iDataheight; - /* predict alpha-depth ! */ - if ((pData->iColortype == MNG_COLORTYPE_GRAYA ) || - (pData->iColortype == MNG_COLORTYPE_RGBA ) ) - pData->iAlphadepth = pData->iBitdepth; - else - if (pData->iColortype == MNG_COLORTYPE_INDEXED) - pData->iAlphadepth = 8; /* worst case scenario */ - else - pData->iAlphadepth = 1; /* Possible tRNS cheap binary transparency */ - /* fits on maximum canvas ? */ - if ((pData->iWidth > pData->iMaxwidth) || (pData->iHeight > pData->iMaxheight)) - MNG_WARNING (pData, MNG_IMAGETOOLARGE); - -#if !defined(MNG_INCLUDE_MPNG_PROPOSAL) || !defined(MNG_SUPPORT_DISPLAY) - if (pData->fProcessheader) /* inform the app ? */ - if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) - MNG_ERROR (pData, MNG_APPMISCERROR); -#endif - } - - if (!pData->bHasDHDR) - pData->iImagelevel++; /* one level deeper */ - -#ifdef MNG_SUPPORT_DISPLAY - return mng_process_display_ihdr (pData); -#else - return MNG_NOERROR; -#endif /* MNG_SUPPORT_DISPLAY */ -} - -/* ************************************************************************** */ - -MNG_F_SPECIALFUNC (mng_debunk_plte) -{ - mng_pltep pPLTE = (mng_pltep)pChunk; - mng_uint32 iRawlen = *piRawlen; - mng_uint8p pRawdata = *ppRawdata; - /* length must be multiple of 3 */ - if (((iRawlen % 3) != 0) || (iRawlen > 768)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - /* this is the exact length */ - pPLTE->iEntrycount = iRawlen / 3; - - MNG_COPY (pPLTE->aEntries, pRawdata, iRawlen); - - *piRawlen = 0; - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_C_SPECIALFUNC (mng_special_plte) -{ /* multiple PLTE only inside BASI */ - if ((pData->bHasPLTE) && (!pData->bHasBASI)) - MNG_ERROR (pData, MNG_MULTIPLEERROR); - - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - { /* only allowed for indexed-color or - rgb(a)-color! */ - if ((pData->iColortype != MNG_COLORTYPE_RGB ) && - (pData->iColortype != MNG_COLORTYPE_INDEXED) && - (pData->iColortype != MNG_COLORTYPE_RGBA ) ) - MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); - /* empty only allowed if global present */ - if ((((mng_pltep)pChunk)->bEmpty) && (!pData->bHasglobalPLTE)) - MNG_ERROR (pData, MNG_CANNOTBEEMPTY); - } - else - { - if (((mng_pltep)pChunk)->bEmpty) /* cannot be empty as global! */ - MNG_ERROR (pData, MNG_CANNOTBEEMPTY); - } - - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - pData->bHasPLTE = MNG_TRUE; /* got it! */ - else - pData->bHasglobalPLTE = MNG_TRUE; - - pData->iPLTEcount = ((mng_pltep)pChunk)->iEntrycount; - -#ifdef MNG_SUPPORT_DISPLAY - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - { - mng_imagep pImage; - mng_imagedatap pBuf; - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* processing delta-image ? */ - { /* store in object 0 !!! */ - pImage = (mng_imagep)pData->pObjzero; - pBuf = pImage->pImgbuf; - pBuf->bHasPLTE = MNG_TRUE; /* it's definitely got a PLTE now */ - pBuf->iPLTEcount = ((mng_pltep)pChunk)->iEntrycount; - MNG_COPY (pBuf->aPLTEentries, ((mng_pltep)pChunk)->aEntries, - sizeof (pBuf->aPLTEentries)); - } - else -#endif - { /* get the current object */ - pImage = (mng_imagep)pData->pCurrentobj; - if (!pImage) /* no object then dump it in obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - - pBuf = pImage->pImgbuf; /* address the object buffer */ - pBuf->bHasPLTE = MNG_TRUE; /* and tell it it's got a PLTE now */ - - if (((mng_pltep)pChunk)->bEmpty) /* if empty, inherit from global */ - { - pBuf->iPLTEcount = pData->iGlobalPLTEcount; - MNG_COPY (pBuf->aPLTEentries, pData->aGlobalPLTEentries, - sizeof (pBuf->aPLTEentries)); - - if (pData->bHasglobalTRNS) /* also copy global tRNS ? */ - { - mng_uint32 iRawlen2 = pData->iGlobalTRNSrawlen; - mng_uint8p pRawdata2 = (mng_uint8p)(pData->aGlobalTRNSrawdata); - /* indicate tRNS available */ - pBuf->bHasTRNS = MNG_TRUE; - /* global length oke ? */ - if ((iRawlen2 == 0) || (iRawlen2 > pBuf->iPLTEcount)) - MNG_ERROR (pData, MNG_GLOBALLENGTHERR); - /* copy it */ - pBuf->iTRNScount = iRawlen2; - MNG_COPY (pBuf->aTRNSentries, pRawdata2, iRawlen2); - } - } - else - { /* store fields for future reference */ - pBuf->iPLTEcount = ((mng_pltep)pChunk)->iEntrycount; - MNG_COPY (pBuf->aPLTEentries, ((mng_pltep)pChunk)->aEntries, - sizeof (pBuf->aPLTEentries)); - } - } - } - else /* store as global */ - { - pData->iGlobalPLTEcount = ((mng_pltep)pChunk)->iEntrycount; - MNG_COPY (pData->aGlobalPLTEentries, ((mng_pltep)pChunk)->aEntries, - sizeof (pData->aGlobalPLTEentries)); - /* create an animation object */ - return mng_create_ani_plte (pData); - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -MNG_C_SPECIALFUNC (mng_special_idat) -{ -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasJHDR) && - (pData->iJHDRalphacompression != MNG_COMPRESSION_DEFLATE)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); -#endif - /* not allowed for deltatype NO_CHANGE */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && ((pData->iDeltatype == MNG_DELTATYPE_NOCHANGE))) - MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); -#endif - /* can only be empty in BASI-block! */ - if ((((mng_idatp)pChunk)->bEmpty) && (!pData->bHasBASI)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - /* indexed-color requires PLTE */ - if ((pData->bHasIHDR) && (pData->iColortype == 3) && (!pData->bHasPLTE)) - MNG_ERROR (pData, MNG_PLTEMISSING); - - pData->bHasIDAT = MNG_TRUE; /* got some IDAT now, don't we */ - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -MNG_C_SPECIALFUNC (mng_special_iend) -{ /* IHDR-block requires IDAT */ - if ((pData->bHasIHDR) && (!pData->bHasIDAT)) - MNG_ERROR (pData, MNG_IDATMISSING); - - pData->iImagelevel--; /* one level up */ - -#ifdef MNG_SUPPORT_DISPLAY - { /* create an animation object */ - mng_retcode iRetcode = mng_create_ani_image (pData); - if (iRetcode) /* on error bail out */ - return iRetcode; - /* display processing */ - iRetcode = mng_process_display_iend (pData); - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_SUPPORT_DISPLAY - if (!pData->bTimerset) /* reset only if not broken !!! */ - { -#endif - /* IEND signals the end for most ... */ - pData->bHasIHDR = MNG_FALSE; - pData->bHasBASI = MNG_FALSE; - pData->bHasDHDR = MNG_FALSE; -#ifdef MNG_INCLUDE_JNG - pData->bHasJHDR = MNG_FALSE; - pData->bHasJSEP = MNG_FALSE; - pData->bHasJDAA = MNG_FALSE; - pData->bHasJDAT = MNG_FALSE; -#endif - pData->bHasPLTE = MNG_FALSE; - pData->bHasTRNS = MNG_FALSE; - pData->bHasGAMA = MNG_FALSE; - pData->bHasCHRM = MNG_FALSE; - pData->bHasSRGB = MNG_FALSE; - pData->bHasICCP = MNG_FALSE; - pData->bHasBKGD = MNG_FALSE; - pData->bHasIDAT = MNG_FALSE; -#ifdef MNG_SUPPORT_DISPLAY - } -#endif - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -MNG_F_SPECIALFUNC (mng_debunk_trns) -{ - mng_trnsp pTRNS = (mng_trnsp)pChunk; - mng_uint32 iRawlen = *piRawlen; - mng_uint8p pRawdata = *ppRawdata; - - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - { /* not global! */ - pTRNS->bGlobal = MNG_FALSE; - pTRNS->iType = pData->iColortype; - - if (iRawlen != 0) - { - switch (pData->iColortype) /* store fields */ - { - case 0: { /* gray */ - if (iRawlen != 2) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - pTRNS->iGray = mng_get_uint16 (pRawdata); - break; - } - case 2: { /* rgb */ - if (iRawlen != 6) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - pTRNS->iRed = mng_get_uint16 (pRawdata); - pTRNS->iGreen = mng_get_uint16 (pRawdata+2); - pTRNS->iBlue = mng_get_uint16 (pRawdata+4); - break; - } - case 3: { /* indexed */ - if (iRawlen > 256) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - pTRNS->iCount = iRawlen; - MNG_COPY (pTRNS->aEntries, pRawdata, iRawlen); - break; - } - } - } - } - else /* it's global! */ - { - if (iRawlen == 0) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - pTRNS->bGlobal = MNG_TRUE; - pTRNS->iType = 0; - pTRNS->iRawlen = iRawlen; - MNG_COPY (pTRNS->aRawdata, pRawdata, iRawlen); - - pData->iGlobalTRNSrawlen = iRawlen; - MNG_COPY (pData->aGlobalTRNSrawdata, pRawdata, iRawlen); - } - - *piRawlen = 0; - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_C_SPECIALFUNC (mng_special_trns) -{ /* multiple tRNS only inside BASI */ - if ((pData->bHasTRNS) && (!pData->bHasBASI)) - MNG_ERROR (pData, MNG_MULTIPLEERROR); - - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - { /* not allowed with full alpha-channel */ - if ((pData->iColortype == 4) || (pData->iColortype == 6)) - MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); - - if (!((mng_trnsp)pChunk)->bEmpty) /* filled ? */ - { -#ifdef MNG_SUPPORT_DISPLAY - if (pData->iColortype == 3) - { - mng_imagep pImage = (mng_imagep)pData->pCurrentobj; - mng_imagedatap pBuf; - - if (!pImage) /* no object then check obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - - pBuf = pImage->pImgbuf; /* address object buffer */ - - if (((mng_trnsp)pChunk)->iCount > pBuf->iPLTEcount) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } -#endif - } - else /* if empty there must be global stuff! */ - { - if (!pData->bHasglobalTRNS) - MNG_ERROR (pData, MNG_CANNOTBEEMPTY); - } - } - - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - pData->bHasTRNS = MNG_TRUE; /* indicate tRNS available */ - else - pData->bHasglobalTRNS = MNG_TRUE; - -#ifdef MNG_SUPPORT_DISPLAY - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - { - mng_imagep pImage; - mng_imagedatap pBuf; - mng_uint8p pRawdata2; - mng_uint32 iRawlen2; - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* processing delta-image ? */ - { /* store in object 0 !!! */ -#if defined(MNG_NO_1_2_4BIT_SUPPORT) - mng_uint8 multiplier[]={0,255,85,0,17,0,0,0,1,0,0,0,0,0,0,0,1}; -#endif - pImage = (mng_imagep)pData->pObjzero; - pBuf = pImage->pImgbuf; /* address object buffer */ - pBuf->bHasTRNS = MNG_TRUE; /* tell it it's got a tRNS now */ - pBuf->iTRNSgray = 0; - pBuf->iTRNSred = 0; - pBuf->iTRNSgreen = 0; - pBuf->iTRNSblue = 0; - pBuf->iTRNScount = 0; - - switch (pData->iColortype) /* store fields for future reference */ - { - case 0: { /* gray */ - pBuf->iTRNSgray = ((mng_trnsp)pChunk)->iGray; -#if defined(MNG_NO_1_2_4BIT_SUPPORT) - pBuf->iTRNSgray *= multiplier[pData->iPNGdepth]; -#endif -#if defined(MNG_NO_16BIT_SUPPORT) - if (pData->iPNGmult == 2) - pBuf->iTRNSgray >>= 8; -#endif - break; - } - case 2: { /* rgb */ - pBuf->iTRNSred = ((mng_trnsp)pChunk)->iRed; - pBuf->iTRNSgreen = ((mng_trnsp)pChunk)->iGreen; - pBuf->iTRNSblue = ((mng_trnsp)pChunk)->iBlue; -#if defined(MNG_NO_16BIT_SUPPORT) - if (pData->iPNGmult == 2) - { - pBuf->iTRNSred >>= 8; - pBuf->iTRNSgreen >>= 8; - pBuf->iTRNSblue >>= 8; - } -#endif - break; - } - case 3: { /* indexed */ - pBuf->iTRNScount = ((mng_trnsp)pChunk)->iCount; - MNG_COPY (pBuf->aTRNSentries, - ((mng_trnsp)pChunk)->aEntries, - ((mng_trnsp)pChunk)->iCount); - break; - } - } - } - else -#endif - { /* address current object */ - pImage = (mng_imagep)pData->pCurrentobj; - - if (!pImage) /* no object then dump it in obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - - pBuf = pImage->pImgbuf; /* address object buffer */ - pBuf->bHasTRNS = MNG_TRUE; /* and tell it it's got a tRNS now */ - pBuf->iTRNSgray = 0; - pBuf->iTRNSred = 0; - pBuf->iTRNSgreen = 0; - pBuf->iTRNSblue = 0; - pBuf->iTRNScount = 0; - - if (((mng_trnsp)pChunk)->bEmpty) /* if empty, inherit from global */ - { - iRawlen2 = pData->iGlobalTRNSrawlen; - pRawdata2 = (mng_ptr)(pData->aGlobalTRNSrawdata); - /* global length oke ? */ - if ((pData->iColortype == 0) && (iRawlen2 != 2)) - MNG_ERROR (pData, MNG_GLOBALLENGTHERR); - - if ((pData->iColortype == 2) && (iRawlen2 != 6)) - MNG_ERROR (pData, MNG_GLOBALLENGTHERR); - - if ((pData->iColortype == 3) && ((iRawlen2 == 0) || (iRawlen2 > pBuf->iPLTEcount))) - MNG_ERROR (pData, MNG_GLOBALLENGTHERR); - - switch (pData->iColortype) /* store fields for future reference */ - { - case 0: { /* gray */ - pBuf->iTRNSgray = mng_get_uint16 (pRawdata2); -#if defined(MNG_NO_16BIT_SUPPORT) - if (pData->iPNGmult == 2) - pBuf->iTRNSgray >>= 8; -#endif - break; - } - case 2: { /* rgb */ - pBuf->iTRNSred = mng_get_uint16 (pRawdata2); - pBuf->iTRNSgreen = mng_get_uint16 (pRawdata2+2); - pBuf->iTRNSblue = mng_get_uint16 (pRawdata2+4); -#if defined(MNG_NO_16BIT_SUPPORT) - if (pData->iPNGmult == 2) - { - pBuf->iTRNSred >>= 8; - pBuf->iTRNSgreen >>= 8; - pBuf->iTRNSblue >>= 8; - } -#endif - break; - } - case 3: { /* indexed */ - pBuf->iTRNScount = iRawlen2; - MNG_COPY (pBuf->aTRNSentries, pRawdata2, iRawlen2); - break; - } - } - } - else - { - switch (pData->iColortype) /* store fields for future reference */ - { - case 0: { /* gray */ - pBuf->iTRNSgray = ((mng_trnsp)pChunk)->iGray; -#if defined(MNG_NO_16BIT_SUPPORT) - if (pData->iPNGmult == 2) - pBuf->iTRNSgray >>= 8; -#endif - break; - } - case 2: { /* rgb */ - pBuf->iTRNSred = ((mng_trnsp)pChunk)->iRed; - pBuf->iTRNSgreen = ((mng_trnsp)pChunk)->iGreen; - pBuf->iTRNSblue = ((mng_trnsp)pChunk)->iBlue; -#if defined(MNG_NO_16BIT_SUPPORT) - if (pData->iPNGmult == 2) - { - pBuf->iTRNSred >>= 8; - pBuf->iTRNSgreen >>= 8; - pBuf->iTRNSblue >>= 8; - } -#endif - break; - } - case 3: { /* indexed */ - pBuf->iTRNScount = ((mng_trnsp)pChunk)->iCount; - MNG_COPY (pBuf->aTRNSentries, - ((mng_trnsp)pChunk)->aEntries, - ((mng_trnsp)pChunk)->iCount); - break; - } - } - } - } - } - else - { /* create an animation object */ - return mng_create_ani_trns (pData); - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -MNG_C_SPECIALFUNC (mng_special_gama) -{ -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - pData->bHasGAMA = MNG_TRUE; /* indicate we've got it */ - else - pData->bHasglobalGAMA = (mng_bool)!((mng_gamap)pChunk)->bEmpty; - -#ifdef MNG_SUPPORT_DISPLAY -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - { - mng_imagep pImage; - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* update delta image ? */ - pImage = (mng_imagep)pData->pObjzero; - else -#endif - { - pImage = (mng_imagep)pData->pCurrentobj; - if (!pImage) /* no object then dump it in obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - } - /* store for color-processing routines */ - pImage->pImgbuf->iGamma = ((mng_gamap)pChunk)->iGamma; - pImage->pImgbuf->bHasGAMA = MNG_TRUE; - } - else - { /* store as global */ - if (!((mng_gamap)pChunk)->bEmpty) - pData->iGlobalGamma = ((mng_gamap)pChunk)->iGamma; - /* create an animation object */ - return mng_create_ani_gama (pData, pChunk); - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_cHRM -MNG_C_SPECIALFUNC (mng_special_chrm) -{ -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - pData->bHasCHRM = MNG_TRUE; /* indicate we've got it */ - else - pData->bHasglobalCHRM = (mng_bool)!((mng_chrmp)pChunk)->bEmpty; - -#ifdef MNG_SUPPORT_DISPLAY - { -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - { - mng_imagep pImage; - mng_imagedatap pBuf; - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* update delta image ? */ - pImage = (mng_imagep)pData->pObjzero; - else -#endif - { - pImage = (mng_imagep)pData->pCurrentobj; - if (!pImage) /* no object then dump it in obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - } - - pBuf = pImage->pImgbuf; /* address object buffer */ - pBuf->bHasCHRM = MNG_TRUE; /* and tell it it's got a CHRM now */ - /* store for color-processing routines */ - pBuf->iWhitepointx = ((mng_chrmp)pChunk)->iWhitepointx; - pBuf->iWhitepointy = ((mng_chrmp)pChunk)->iWhitepointy; - pBuf->iPrimaryredx = ((mng_chrmp)pChunk)->iRedx; - pBuf->iPrimaryredy = ((mng_chrmp)pChunk)->iRedy; - pBuf->iPrimarygreenx = ((mng_chrmp)pChunk)->iGreenx; - pBuf->iPrimarygreeny = ((mng_chrmp)pChunk)->iGreeny; - pBuf->iPrimarybluex = ((mng_chrmp)pChunk)->iBluex; - pBuf->iPrimarybluey = ((mng_chrmp)pChunk)->iBluey; - } - else - { /* store as global */ - if (!((mng_chrmp)pChunk)->bEmpty) - { - pData->iGlobalWhitepointx = ((mng_chrmp)pChunk)->iWhitepointx; - pData->iGlobalWhitepointy = ((mng_chrmp)pChunk)->iWhitepointy; - pData->iGlobalPrimaryredx = ((mng_chrmp)pChunk)->iRedx; - pData->iGlobalPrimaryredy = ((mng_chrmp)pChunk)->iRedy; - pData->iGlobalPrimarygreenx = ((mng_chrmp)pChunk)->iGreenx; - pData->iGlobalPrimarygreeny = ((mng_chrmp)pChunk)->iGreeny; - pData->iGlobalPrimarybluex = ((mng_chrmp)pChunk)->iBluex; - pData->iGlobalPrimarybluey = ((mng_chrmp)pChunk)->iBluey; - } - /* create an animation object */ - return mng_create_ani_chrm (pData, pChunk); - } - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -MNG_C_SPECIALFUNC (mng_special_srgb) -{ -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - pData->bHasSRGB = MNG_TRUE; /* indicate we've got it */ - else - pData->bHasglobalSRGB = (mng_bool)!((mng_srgbp)pChunk)->bEmpty; - -#ifdef MNG_SUPPORT_DISPLAY -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - { - mng_imagep pImage; - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* update delta image ? */ - pImage = (mng_imagep)pData->pObjzero; - else -#endif - { - pImage = (mng_imagep)pData->pCurrentobj; - if (!pImage) /* no object then dump it in obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - } - /* store for color-processing routines */ - pImage->pImgbuf->iRenderingintent = ((mng_srgbp)pChunk)->iRenderingintent; - pImage->pImgbuf->bHasSRGB = MNG_TRUE; - } - else - { /* store as global */ - if (!((mng_srgbp)pChunk)->bEmpty) - pData->iGlobalRendintent = ((mng_srgbp)pChunk)->iRenderingintent; - /* create an animation object */ - return mng_create_ani_srgb (pData, pChunk); - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iCCP -MNG_C_SPECIALFUNC (mng_special_iccp) -{ - mng_retcode iRetcode; - mng_chunk_headerp pDummy; - -#ifdef MNG_CHECK_BAD_ICCP /* Check for bad iCCP chunk */ - if (!strncmp (((mng_iccpp)pChunk)->zName, "Photoshop ICC profile", 21)) - { - if (((mng_iccpp)pChunk)->iProfilesize == 2615) /* is it the sRGB profile ? */ - { - mng_chunk_header chunk_srgb; - mng_get_chunkheader (MNG_UINT_sRGB, &chunk_srgb); - /* pretend it's an sRGB chunk then ! */ - iRetcode = mng_read_general (pData, &chunk_srgb, 1, (mng_ptr)"0", &pDummy); - if (iRetcode) /* on error bail out */ - return iRetcode; - - pDummy->fCleanup (pData, pDummy); - } - } - else - { -#endif /* MNG_CHECK_BAD_ICCP */ - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - pData->bHasICCP = MNG_TRUE; /* indicate we've got it */ - else - pData->bHasglobalICCP = (mng_bool)!((mng_iccpp)pChunk)->bEmpty; - -#ifdef MNG_SUPPORT_DISPLAY -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - { - mng_imagep pImage; - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* update delta image ? */ - { /* store in object 0 ! */ - pImage = (mng_imagep)pData->pObjzero; - - if (pImage->pImgbuf->pProfile) /* profile existed ? */ - MNG_FREEX (pData, pImage->pImgbuf->pProfile, pImage->pImgbuf->iProfilesize); - /* allocate a buffer & copy it */ - MNG_ALLOC (pData, pImage->pImgbuf->pProfile, ((mng_iccpp)pChunk)->iProfilesize); - MNG_COPY (pImage->pImgbuf->pProfile, ((mng_iccpp)pChunk)->pProfile, ((mng_iccpp)pChunk)->iProfilesize); - /* store its length as well */ - pImage->pImgbuf->iProfilesize = ((mng_iccpp)pChunk)->iProfilesize; - pImage->pImgbuf->bHasICCP = MNG_TRUE; - } - else -#endif - { - pImage = (mng_imagep)pData->pCurrentobj; - - if (!pImage) /* no object then dump it in obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - - if (pImage->pImgbuf->pProfile) /* profile existed ? */ - MNG_FREEX (pData, pImage->pImgbuf->pProfile, pImage->pImgbuf->iProfilesize); - /* allocate a buffer & copy it */ - MNG_ALLOC (pData, pImage->pImgbuf->pProfile, ((mng_iccpp)pChunk)->iProfilesize); - MNG_COPY (pImage->pImgbuf->pProfile, ((mng_iccpp)pChunk)->pProfile, ((mng_iccpp)pChunk)->iProfilesize); - /* store its length as well */ - pImage->pImgbuf->iProfilesize = ((mng_iccpp)pChunk)->iProfilesize; - pImage->pImgbuf->bHasICCP = MNG_TRUE; - } - } - else - { /* store as global */ - if (pData->pGlobalProfile) /* did we have a global profile ? */ - MNG_FREEX (pData, pData->pGlobalProfile, pData->iGlobalProfilesize); - - if (((mng_iccpp)pChunk)->bEmpty) /* empty chunk ? */ - { - pData->iGlobalProfilesize = 0; /* reset to null */ - pData->pGlobalProfile = MNG_NULL; - } - else - { /* allocate a global buffer & copy it */ - MNG_ALLOC (pData, pData->pGlobalProfile, ((mng_iccpp)pChunk)->iProfilesize); - MNG_COPY (pData->pGlobalProfile, ((mng_iccpp)pChunk)->pProfile, ((mng_iccpp)pChunk)->iProfilesize); - /* store its length as well */ - pData->iGlobalProfilesize = ((mng_iccpp)pChunk)->iProfilesize; - } - /* create an animation object */ - return mng_create_ani_iccp (pData, pChunk); - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_CHECK_BAD_ICCP - } -#endif - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_tEXt -MNG_C_SPECIALFUNC (mng_special_text) -{ - if (pData->fProcesstext) /* inform the application ? */ - { - mng_bool bOke = pData->fProcesstext ((mng_handle)pData, MNG_TYPE_TEXT, - ((mng_textp)pChunk)->zKeyword, - ((mng_textp)pChunk)->zText, 0, 0); - if (!bOke) - MNG_ERROR (pData, MNG_APPMISCERROR); - } - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_zTXt -MNG_C_SPECIALFUNC (mng_special_ztxt) -{ - if (pData->fProcesstext) /* inform the application ? */ - { - mng_bool bOke = pData->fProcesstext ((mng_handle)pData, MNG_TYPE_ZTXT, - ((mng_ztxtp)pChunk)->zKeyword, - ((mng_ztxtp)pChunk)->zText, 0, 0); - if (!bOke) - MNG_ERROR (pData, MNG_APPMISCERROR); - } - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iTXt -MNG_F_SPECIALFUNC (mng_deflate_itxt) -{ - mng_itxtp pITXT = (mng_itxtp)pChunk; - mng_uint32 iBufsize = 0; - mng_uint8p pBuf = 0; - mng_uint32 iTextlen = 0; - - if (pITXT->iCompressionflag) /* decompress the text ? */ - { - mng_retcode iRetcode = mng_inflate_buffer (pData, *ppRawdata, *piRawlen, - &pBuf, &iBufsize, &iTextlen); - - if (iRetcode) /* on error bail out */ - { /* don't forget to drop the temp buffer */ - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - - MNG_ALLOC (pData, pITXT->zText, iTextlen+1); - MNG_COPY (pITXT->zText, pBuf, iTextlen); - - pITXT->iTextsize = iTextlen; - - MNG_FREEX (pData, pBuf, iBufsize); - - } else { - - MNG_ALLOC (pData, pITXT->zText, (*piRawlen)+1); - MNG_COPY (pITXT->zText, *ppRawdata, *piRawlen); - - pITXT->iTextsize = *piRawlen; - } - - *piRawlen = 0; - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iTXt -MNG_C_SPECIALFUNC (mng_special_itxt) -{ - if (pData->fProcesstext) /* inform the application ? */ - { - mng_bool bOke = pData->fProcesstext ((mng_handle)pData, MNG_TYPE_ITXT, - ((mng_itxtp)pChunk)->zKeyword, - ((mng_itxtp)pChunk)->zText, - ((mng_itxtp)pChunk)->zLanguage, - ((mng_itxtp)pChunk)->zTranslation); - if (!bOke) - MNG_ERROR (pData, MNG_APPMISCERROR); - } - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_bKGD -MNG_C_SPECIALFUNC (mng_special_bkgd) -{ -#ifdef MNG_SUPPORT_DISPLAY - mng_imagep pImage = (mng_imagep)pData->pCurrentobj; - mng_imagedatap pBuf; -#endif - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - pData->bHasBKGD = MNG_TRUE; /* indicate bKGD available */ - else - pData->bHasglobalBKGD = (mng_bool)!(((mng_bkgdp)pChunk)->bEmpty); - -#ifdef MNG_SUPPORT_DISPLAY - if (!pImage) /* if no object dump it in obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - pBuf = pImage->pImgbuf; /* address object buffer */ - -#ifdef MNG_INCLUDE_JNG - if (pData->bHasJHDR) - { - pBuf->bHasBKGD = MNG_TRUE; /* tell the object it's got bKGD now */ - - switch (pData->iJHDRcolortype) /* store fields for future reference */ - { - case 8 : ; /* gray */ - case 12 : { /* graya */ - pBuf->iBKGDgray = ((mng_bkgdp)pChunk)->iGray; - break; - } - case 10 : ; /* rgb */ - case 14 : { /* rgba */ - pBuf->iBKGDred = ((mng_bkgdp)pChunk)->iRed; - pBuf->iBKGDgreen = ((mng_bkgdp)pChunk)->iGreen; - pBuf->iBKGDblue = ((mng_bkgdp)pChunk)->iBlue; - break; - } - } - } - else -#endif /* MNG_INCLUDE_JNG */ - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - { - pBuf->bHasBKGD = MNG_TRUE; /* tell the object it's got bKGD now */ - - switch (pData->iColortype) /* store fields for future reference */ - { - case 0 : ; /* gray */ - case 4 : { /* graya */ - pBuf->iBKGDgray = ((mng_bkgdp)pChunk)->iGray; - break; - } - case 2 : ; /* rgb */ - case 6 : { /* rgba */ - pBuf->iBKGDred = ((mng_bkgdp)pChunk)->iRed; - pBuf->iBKGDgreen = ((mng_bkgdp)pChunk)->iGreen; - pBuf->iBKGDblue = ((mng_bkgdp)pChunk)->iBlue; - break; - } - case 3 : { /* indexed */ - pBuf->iBKGDindex = ((mng_bkgdp)pChunk)->iIndex; - break; - } - } - } - else /* store as global */ - { - if (!(((mng_bkgdp)pChunk)->bEmpty)) - { - pData->iGlobalBKGDred = ((mng_bkgdp)pChunk)->iRed; - pData->iGlobalBKGDgreen = ((mng_bkgdp)pChunk)->iGreen; - pData->iGlobalBKGDblue = ((mng_bkgdp)pChunk)->iBlue; - } - /* create an animation object */ - return mng_create_ani_bkgd (pData); - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_pHYs -MNG_C_SPECIALFUNC (mng_special_phys) -{ -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sBIT -MNG_C_SPECIALFUNC (mng_special_sbit) -{ -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sPLT -MNG_F_SPECIALFUNC (mng_splt_entries) -{ - mng_spltp pSPLT = (mng_spltp)pChunk; - mng_uint32 iRawlen = *piRawlen; - mng_uint8p pRawdata = *ppRawdata; - - if ((pSPLT->iSampledepth != MNG_BITDEPTH_8 ) && - (pSPLT->iSampledepth != MNG_BITDEPTH_16) ) - MNG_ERROR (pData, MNG_INVSAMPLEDEPTH); - /* check remaining length */ - if ( ((pSPLT->iSampledepth == MNG_BITDEPTH_8 ) && (iRawlen % 6 != 0)) || - ((pSPLT->iSampledepth == MNG_BITDEPTH_16) && (iRawlen % 10 != 0)) ) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if (pSPLT->iSampledepth == MNG_BITDEPTH_8) - pSPLT->iEntrycount = iRawlen / 6; - else - pSPLT->iEntrycount = iRawlen / 10; - - if (iRawlen) - { - MNG_ALLOC (pData, pSPLT->pEntries, iRawlen); - MNG_COPY (pSPLT->pEntries, pRawdata, iRawlen); - } - - *piRawlen = 0; - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sPLT -MNG_C_SPECIALFUNC (mng_special_splt) -{ -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_hIST -MNG_F_SPECIALFUNC (mng_hist_entries) -{ - mng_histp pHIST = (mng_histp)pChunk; - mng_uint32 iRawlen = *piRawlen; - mng_uint8p pRawdata = *ppRawdata; - mng_uint32 iX; - - if ( ((iRawlen & 0x01) != 0) || ((iRawlen >> 1) != pData->iPLTEcount) ) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - pHIST->iEntrycount = iRawlen >> 1; - - for (iX = 0; iX < pHIST->iEntrycount; iX++) - { - pHIST->aEntries[iX] = mng_get_uint16 (pRawdata); - pRawdata += 2; - } - - *piRawlen = 0; - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_hIST -MNG_C_SPECIALFUNC (mng_special_hist) -{ -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_tIME -MNG_C_SPECIALFUNC (mng_special_time) -{ -/* if (pData->fProcesstime) */ /* inform the application ? */ -/* { - - pData->fProcesstime ((mng_handle)pData, ); - } */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ -/* ************************************************************************** */ -/* JNG chunks */ - -#ifdef MNG_INCLUDE_JNG -MNG_C_SPECIALFUNC (mng_special_jhdr) -{ - if ((pData->eSigtype == mng_it_jng) && (pData->iChunkseq > 1)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* inside a JHDR-IEND block now */ - pData->bHasJHDR = MNG_TRUE; - /* and store interesting fields */ - pData->iDatawidth = ((mng_jhdrp)pChunk)->iWidth; - pData->iDataheight = ((mng_jhdrp)pChunk)->iHeight; - pData->iJHDRcolortype = ((mng_jhdrp)pChunk)->iColortype; - pData->iJHDRimgbitdepth = ((mng_jhdrp)pChunk)->iImagesampledepth; - pData->iJHDRimgcompression = ((mng_jhdrp)pChunk)->iImagecompression; - pData->iJHDRimginterlace = ((mng_jhdrp)pChunk)->iImageinterlace; - pData->iJHDRalphabitdepth = ((mng_jhdrp)pChunk)->iAlphasampledepth; - pData->iJHDRalphacompression = ((mng_jhdrp)pChunk)->iAlphacompression; - pData->iJHDRalphafilter = ((mng_jhdrp)pChunk)->iAlphafilter; - pData->iJHDRalphainterlace = ((mng_jhdrp)pChunk)->iAlphainterlace; - -#if defined(MNG_NO_1_2_4BIT_SUPPORT) || defined(MNG_NO_16BIT_SUPPORT) - pData->iPNGmult = 1; - pData->iPNGdepth = pData->iJHDRalphabitdepth; -#endif - -#ifdef MNG_NO_1_2_4BIT_SUPPORT - if (pData->iJHDRalphabitdepth < 8) - pData->iJHDRalphabitdepth = 8; -#endif - -#ifdef MNG_NO_16BIT_SUPPORT - if (pData->iJHDRalphabitdepth > 8) - { - pData->iPNGmult = 2; - pData->iJHDRalphabitdepth = 8; - } -#endif - /* parameter validity checks */ - if ((pData->iJHDRcolortype != MNG_COLORTYPE_JPEGGRAY ) && - (pData->iJHDRcolortype != MNG_COLORTYPE_JPEGCOLOR ) && - (pData->iJHDRcolortype != MNG_COLORTYPE_JPEGGRAYA ) && - (pData->iJHDRcolortype != MNG_COLORTYPE_JPEGCOLORA) ) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - - if ((pData->iJHDRimgbitdepth != MNG_BITDEPTH_JPEG8 ) && - (pData->iJHDRimgbitdepth != MNG_BITDEPTH_JPEG12 ) && - (pData->iJHDRimgbitdepth != MNG_BITDEPTH_JPEG8AND12) ) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || - (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) - { - if ((pData->iJHDRalphabitdepth != MNG_BITDEPTH_8 ) -#ifndef MNG_NO_1_2_4BIT_SUPPORT - && (pData->iJHDRalphabitdepth != MNG_BITDEPTH_1 ) && - (pData->iJHDRalphabitdepth != MNG_BITDEPTH_2 ) && - (pData->iJHDRalphabitdepth != MNG_BITDEPTH_4 ) -#endif -#ifndef MNG_NO_16BIT_SUPPORT - && (pData->iJHDRalphabitdepth != MNG_BITDEPTH_16) -#endif - ) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if ((pData->iJHDRalphacompression != MNG_COMPRESSION_DEFLATE ) && - (pData->iJHDRalphacompression != MNG_COMPRESSION_BASELINEJPEG) ) - MNG_ERROR (pData, MNG_INVALIDCOMPRESS); - - if ((pData->iJHDRalphacompression == MNG_COMPRESSION_BASELINEJPEG) && - (pData->iJHDRalphabitdepth != MNG_BITDEPTH_8 ) ) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - -#if defined(FILTER192) || defined(FILTER193) - if ((pData->iJHDRalphafilter != MNG_FILTER_ADAPTIVE ) && -#if defined(FILTER192) && defined(FILTER193) - (pData->iJHDRalphafilter != MNG_FILTER_DIFFERING) && - (pData->iJHDRalphafilter != MNG_FILTER_NOFILTER ) ) -#else -#ifdef FILTER192 - (pData->iJHDRalphafilter != MNG_FILTER_DIFFERING) ) -#else - (pData->iJHDRalphafilter != MNG_FILTER_NOFILTER ) ) -#endif -#endif - MNG_ERROR (pData, MNG_INVALIDFILTER); -#else - if (pData->iJHDRalphafilter) - MNG_ERROR (pData, MNG_INVALIDFILTER); -#endif - - } - else - { - if (pData->iJHDRalphabitdepth) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - if (pData->iJHDRalphacompression) - MNG_ERROR (pData, MNG_INVALIDCOMPRESS); - if (pData->iJHDRalphafilter) - MNG_ERROR (pData, MNG_INVALIDFILTER); - if (pData->iJHDRalphainterlace) - MNG_ERROR (pData, MNG_INVALIDINTERLACE); - } - - if (!pData->bHasheader) /* first chunk ? */ - { - pData->bHasheader = MNG_TRUE; /* we've got a header */ - pData->eImagetype = mng_it_jng; /* then this must be a JNG */ - pData->iWidth = ((mng_jhdrp)pChunk)->iWidth; - pData->iHeight = ((mng_jhdrp)pChunk)->iHeight; - /* predict alpha-depth ! */ - if ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || - (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) - pData->iAlphadepth = pData->iJHDRalphabitdepth; - else - pData->iAlphadepth = 0; - /* fits on maximum canvas ? */ - if ((pData->iWidth > pData->iMaxwidth) || (pData->iHeight > pData->iMaxheight)) - MNG_WARNING (pData, MNG_IMAGETOOLARGE); - - if (pData->fProcessheader) /* inform the app ? */ - if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) - MNG_ERROR (pData, MNG_APPMISCERROR); - - } - - pData->iColortype = 0; /* fake grayscale for other routines */ - pData->iImagelevel++; /* one level deeper */ - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode = mng_process_display_jhdr (pData); - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_NO_16BIT_SUPPORT - if (((mng_jhdrp)pChunk)->iAlphasampledepth > 8) - ((mng_jhdrp)pChunk)->iAlphasampledepth = 8; -#endif - - return MNG_NOERROR; /* done */ -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -MNG_C_SPECIALFUNC (mng_special_jdaa) -{ - if (pData->iJHDRalphacompression != MNG_COMPRESSION_BASELINEJPEG) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - pData->bHasJDAA = MNG_TRUE; /* got some JDAA now, don't we */ - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -MNG_C_SPECIALFUNC (mng_special_jdat) -{ - pData->bHasJDAT = MNG_TRUE; /* got some JDAT now, don't we */ - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -MNG_C_SPECIALFUNC (mng_special_jsep) -{ - pData->bHasJSEP = MNG_TRUE; /* indicate we've had the 8-/12-bit separator */ - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ -/* ************************************************************************** */ -/* MNG chunks */ - -MNG_C_SPECIALFUNC (mng_special_mhdr) -{ - if (pData->bHasheader) /* can only be the first chunk! */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - pData->bHasMHDR = MNG_TRUE; /* oh boy, a real MNG */ - pData->bHasheader = MNG_TRUE; /* we've got a header */ - pData->eImagetype = mng_it_mng; /* fill header fields */ - pData->iWidth = ((mng_mhdrp)pChunk)->iWidth; - pData->iHeight = ((mng_mhdrp)pChunk)->iHeight; - pData->iTicks = ((mng_mhdrp)pChunk)->iTicks; - pData->iLayercount = ((mng_mhdrp)pChunk)->iLayercount; - pData->iFramecount = ((mng_mhdrp)pChunk)->iFramecount; - pData->iPlaytime = ((mng_mhdrp)pChunk)->iPlaytime; - pData->iSimplicity = ((mng_mhdrp)pChunk)->iSimplicity; -#ifndef MNG_NO_OLD_VERSIONS - pData->bPreDraft48 = MNG_FALSE; -#endif - /* predict alpha-depth */ - if ((pData->iSimplicity & 0x00000001) == 0) -#ifndef MNG_NO_16BIT_SUPPORT - pData->iAlphadepth = 16; /* no indicators = assume the worst */ -#else - pData->iAlphadepth = 8; /* anything else = assume the worst */ -#endif - else - if ((pData->iSimplicity & 0x00000008) == 0) - pData->iAlphadepth = 0; /* no transparency at all */ - else - if ((pData->iSimplicity & 0x00000140) == 0x00000040) - pData->iAlphadepth = 1; /* no semi-transparency guaranteed */ - else -#ifndef MNG_NO_16BIT_SUPPORT - pData->iAlphadepth = 16; /* anything else = assume the worst */ -#else - pData->iAlphadepth = 8; /* anything else = assume the worst */ -#endif - -#ifdef MNG_INCLUDE_JNG /* can we handle the complexity ? */ - if (pData->iSimplicity & 0x0000FC00) -#else - if (pData->iSimplicity & 0x0000FC10) -#endif - MNG_ERROR (pData, MNG_MNGTOOCOMPLEX); - /* fits on maximum canvas ? */ - if ((pData->iWidth > pData->iMaxwidth) || (pData->iHeight > pData->iMaxheight)) - MNG_WARNING (pData, MNG_IMAGETOOLARGE); - - if (pData->fProcessheader) /* inform the app ? */ - if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) - MNG_ERROR (pData, MNG_APPMISCERROR); - - pData->iImagelevel++; /* one level deeper */ - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -MNG_C_SPECIALFUNC (mng_special_mend) -{ -#ifdef MNG_SUPPORT_DISPLAY - { /* do something */ - mng_retcode iRetcode = mng_process_display_mend (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - if (!pData->iTotalframes) /* save totals */ - pData->iTotalframes = pData->iFrameseq; - if (!pData->iTotallayers) - pData->iTotallayers = pData->iLayerseq; - if (!pData->iTotalplaytime) - pData->iTotalplaytime = pData->iFrametime; - } -#endif /* MNG_SUPPORT_DISPLAY */ - - pData->bHasMHDR = MNG_FALSE; /* end of the line, bro! */ - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_LOOP -MNG_F_SPECIALFUNC (mng_debunk_loop) -{ - mng_loopp pLOOP = (mng_loopp)pChunk; - mng_uint32 iRawlen = *piRawlen; - mng_uint8p pRawdata = *ppRawdata; - - if (iRawlen >= 5) /* length checks */ - { - if (iRawlen >= 6) - { - if ((iRawlen - 6) % 4 != 0) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if (iRawlen >= 5) /* store the fields */ - { - pLOOP->iLevel = *pRawdata; - -#ifndef MNG_NO_OLD_VERSIONS - if (pData->bPreDraft48) - { - pLOOP->iTermination = *(pRawdata+1); - pLOOP->iRepeat = mng_get_uint32 (pRawdata+2); - } - else -#endif - { - pLOOP->iRepeat = mng_get_uint32 (pRawdata+1); - } - - if (iRawlen >= 6) - { -#ifndef MNG_NO_OLD_VERSIONS - if (!pData->bPreDraft48) -#endif - pLOOP->iTermination = *(pRawdata+5); - - if (iRawlen >= 10) - { - pLOOP->iItermin = mng_get_uint32 (pRawdata+6); - -#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED - if (iRawlen >= 14) - { - pLOOP->iItermax = mng_get_uint32 (pRawdata+10); - pLOOP->iCount = (iRawlen - 14) / 4; - - if (pLOOP->iCount) - { - MNG_ALLOC (pData, pLOOP->pSignals, pLOOP->iCount << 2); - -#ifndef MNG_BIGENDIAN_SUPPORTED - { - mng_uint32 iX; - mng_uint8p pIn = pRawdata + 14; - mng_uint32p pOut = (mng_uint32p)pLOOP->pSignals; - - for (iX = 0; iX < pLOOP->iCount; iX++) - { - *pOut++ = mng_get_uint32 (pIn); - pIn += 4; - } - } -#else - MNG_COPY (pLOOP->pSignals, pRawdata + 14, pLOOP->iCount << 2); -#endif /* !MNG_BIGENDIAN_SUPPORTED */ - } - } -#endif - } - } - } - - *piRawlen = 0; - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_LOOP -MNG_C_SPECIALFUNC (mng_special_loop) -{ - if (!pData->bCacheplayback) /* must store playback info to work!! */ - MNG_ERROR (pData, MNG_LOOPWITHCACHEOFF); - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode; - - pData->bHasLOOP = MNG_TRUE; /* indicate we're inside a loop */ - /* create the LOOP ani-object */ - iRetcode = mng_create_ani_loop (pData, pChunk); - if (iRetcode) /* on error bail out */ - return iRetcode; - /* skip till matching ENDL if iteration=0 */ - if ((!pData->bSkipping) && (((mng_loopp)pChunk)->iRepeat == 0)) - pData->bSkipping = MNG_TRUE; - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_LOOP -MNG_C_SPECIALFUNC (mng_special_endl) -{ -#ifdef MNG_SUPPORT_DISPLAY - if (pData->bHasLOOP) /* are we really processing a loop ? */ - { - mng_uint8 iLevel = ((mng_endlp)pChunk)->iLevel; - /* create an ENDL animation object */ - return mng_create_ani_endl (pData, iLevel); - } - else - MNG_ERROR (pData, MNG_NOMATCHINGLOOP); -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DEFI -MNG_C_SPECIALFUNC (mng_special_defi) -{ -#ifdef MNG_SUPPORT_DISPLAY - mng_retcode iRetcode; - - pData->iDEFIobjectid = ((mng_defip)pChunk)->iObjectid; - pData->bDEFIhasdonotshow = ((mng_defip)pChunk)->bHasdonotshow; - pData->iDEFIdonotshow = ((mng_defip)pChunk)->iDonotshow; - pData->bDEFIhasconcrete = ((mng_defip)pChunk)->bHasconcrete; - pData->iDEFIconcrete = ((mng_defip)pChunk)->iConcrete; - pData->bDEFIhasloca = ((mng_defip)pChunk)->bHasloca; - pData->iDEFIlocax = ((mng_defip)pChunk)->iXlocation; - pData->iDEFIlocay = ((mng_defip)pChunk)->iYlocation; - pData->bDEFIhasclip = ((mng_defip)pChunk)->bHasclip; - pData->iDEFIclipl = ((mng_defip)pChunk)->iLeftcb; - pData->iDEFIclipr = ((mng_defip)pChunk)->iRightcb; - pData->iDEFIclipt = ((mng_defip)pChunk)->iTopcb; - pData->iDEFIclipb = ((mng_defip)pChunk)->iBottomcb; - /* create an animation object */ - iRetcode = mng_create_ani_defi (pData); - if (!iRetcode) /* do display processing */ - iRetcode = mng_process_display_defi (pData); - return iRetcode; -#else - return MNG_NOERROR; /* done */ -#endif /* MNG_SUPPORT_DISPLAY */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_BASI -MNG_C_SPECIALFUNC (mng_special_basi) -{ - pData->bHasBASI = MNG_TRUE; /* inside a BASI-IEND block now */ - /* store interesting fields */ - pData->iDatawidth = ((mng_basip)pChunk)->iWidth; - pData->iDataheight = ((mng_basip)pChunk)->iHeight; - pData->iBitdepth = ((mng_basip)pChunk)->iBitdepth; - pData->iColortype = ((mng_basip)pChunk)->iColortype; - pData->iCompression = ((mng_basip)pChunk)->iCompression; - pData->iFilter = ((mng_basip)pChunk)->iFilter; - pData->iInterlace = ((mng_basip)pChunk)->iInterlace; - -#if defined(MNG_NO_1_2_4BIT_SUPPORT) || defined(MNG_NO_16BIT_SUPPORT) - pData->iPNGmult = 1; - pData->iPNGdepth = pData->iBitdepth; -#endif - -#ifdef MNG_NO_1_2_4BIT_SUPPORT - if (pData->iBitdepth < 8) - pData->iBitdepth = 8; -#endif -#ifdef MNG_NO_16BIT_SUPPORT - if (pData->iBitdepth > 8) - { - pData->iBitdepth = 8; - pData->iPNGmult = 2; - } -#endif - - if ((pData->iBitdepth != 8) /* parameter validity checks */ -#ifndef MNG_NO_1_2_4BIT_SUPPORT - && (pData->iBitdepth != 1) && - (pData->iBitdepth != 2) && - (pData->iBitdepth != 4) -#endif -#ifndef MNG_NO_16BIT_SUPPORT - && (pData->iBitdepth != 16) -#endif - ) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if ((pData->iColortype != MNG_COLORTYPE_GRAY ) && - (pData->iColortype != MNG_COLORTYPE_RGB ) && - (pData->iColortype != MNG_COLORTYPE_INDEXED) && - (pData->iColortype != MNG_COLORTYPE_GRAYA ) && - (pData->iColortype != MNG_COLORTYPE_RGBA ) ) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - - if ((pData->iColortype == MNG_COLORTYPE_INDEXED) && (pData->iBitdepth > 8)) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if (((pData->iColortype == MNG_COLORTYPE_RGB ) || - (pData->iColortype == MNG_COLORTYPE_GRAYA ) || - (pData->iColortype == MNG_COLORTYPE_RGBA ) ) && - (pData->iBitdepth < 8 ) ) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - -#if defined(FILTER192) || defined(FILTER193) - if ((pData->iFilter != MNG_FILTER_ADAPTIVE ) && -#if defined(FILTER192) && defined(FILTER193) - (pData->iFilter != MNG_FILTER_DIFFERING) && - (pData->iFilter != MNG_FILTER_NOFILTER ) ) -#else -#ifdef FILTER192 - (pData->iFilter != MNG_FILTER_DIFFERING) ) -#else - (pData->iFilter != MNG_FILTER_NOFILTER ) ) -#endif -#endif - MNG_ERROR (pData, MNG_INVALIDFILTER); -#else - if (pData->iFilter) - MNG_ERROR (pData, MNG_INVALIDFILTER); -#endif - - pData->iImagelevel++; /* one level deeper */ - -#ifdef MNG_SUPPORT_DISPLAY - { /* create an animation object */ - mng_retcode iRetcode = mng_create_ani_basi (pData, pChunk); - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_NO_16BIT_SUPPORT - if (((mng_basip)pChunk)->iBitdepth > 8) - ((mng_basip)pChunk)->iBitdepth = 8; -#endif - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_CLON -MNG_C_SPECIALFUNC (mng_special_clon) -{ -#ifdef MNG_SUPPORT_DISPLAY - return mng_create_ani_clon (pData, pChunk); -#else - return MNG_NOERROR; /* done */ -#endif /* MNG_SUPPORT_DISPLAY */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -MNG_F_SPECIALFUNC (mng_debunk_past) -{ - mng_pastp pPAST = (mng_pastp)pChunk; - mng_uint32 iRawlen = *piRawlen; - mng_uint8p pRawdata = *ppRawdata; - mng_uint32 iSize; - mng_uint32 iX; - mng_past_sourcep pSource; - /* check the length */ - if ((iRawlen < 41) || (((iRawlen - 11) % 30) != 0)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - pPAST->iDestid = mng_get_uint16 (pRawdata); - pPAST->iTargettype = *(pRawdata+2); - pPAST->iTargetx = mng_get_int32 (pRawdata+3); - pPAST->iTargety = mng_get_int32 (pRawdata+7); - pPAST->iCount = ((iRawlen - 11) / 30); /* how many entries again? */ - iSize = pPAST->iCount * sizeof (mng_past_source); - - pRawdata += 11; - /* get a buffer for all the source blocks */ - MNG_ALLOC (pData, pPAST->pSources, iSize); - - pSource = (mng_past_sourcep)(pPAST->pSources); - - for (iX = pPAST->iCount; iX > 0; iX--) - { /* now copy the source blocks */ - pSource->iSourceid = mng_get_uint16 (pRawdata); - pSource->iComposition = *(pRawdata+2); - pSource->iOrientation = *(pRawdata+3); - pSource->iOffsettype = *(pRawdata+4); - pSource->iOffsetx = mng_get_int32 (pRawdata+5); - pSource->iOffsety = mng_get_int32 (pRawdata+9); - pSource->iBoundarytype = *(pRawdata+13); - pSource->iBoundaryl = mng_get_int32 (pRawdata+14); - pSource->iBoundaryr = mng_get_int32 (pRawdata+18); - pSource->iBoundaryt = mng_get_int32 (pRawdata+22); - pSource->iBoundaryb = mng_get_int32 (pRawdata+26); - - pSource++; - pRawdata += 30; - } - - *piRawlen = 0; - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -MNG_C_SPECIALFUNC (mng_special_past) -{ -#ifdef MNG_SUPPORT_DISPLAY - return mng_create_ani_past (pData, pChunk); -#else - return MNG_NOERROR; -#endif /* MNG_SUPPORT_DISPLAY */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DISC -MNG_F_SPECIALFUNC (mng_disc_entries) -{ - mng_discp pDISC = (mng_discp)pChunk; - mng_uint32 iRawlen = *piRawlen; - mng_uint8p pRawdata = *ppRawdata; - - if ((iRawlen % 2) != 0) /* check the length */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - pDISC->iCount = (iRawlen / sizeof (mng_uint16)); - - if (pDISC->iCount) - { - MNG_ALLOC (pData, pDISC->pObjectids, iRawlen); - -#ifndef MNG_BIGENDIAN_SUPPORTED - { - mng_uint32 iX; - mng_uint8p pIn = pRawdata; - mng_uint16p pOut = pDISC->pObjectids; - - for (iX = pDISC->iCount; iX > 0; iX--) - { - *pOut++ = mng_get_uint16 (pIn); - pIn += 2; - } - } -#else - MNG_COPY (pDISC->pObjectids, pRawdata, iRawlen); -#endif /* !MNG_BIGENDIAN_SUPPORTED */ - } - - *piRawlen = 0; - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DISC -MNG_C_SPECIALFUNC (mng_special_disc) -{ -#ifdef MNG_SUPPORT_DISPLAY - return mng_create_ani_disc (pData, pChunk); -#else - return MNG_NOERROR; -#endif /* MNG_SUPPORT_DISPLAY */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_BACK -MNG_C_SPECIALFUNC (mng_special_back) -{ -#ifdef MNG_SUPPORT_DISPLAY - /* retrieve the fields */ - pData->bHasBACK = MNG_TRUE; - pData->iBACKred = ((mng_backp)pChunk)->iRed; - pData->iBACKgreen = ((mng_backp)pChunk)->iGreen; - pData->iBACKblue = ((mng_backp)pChunk)->iBlue; - pData->iBACKmandatory = ((mng_backp)pChunk)->iMandatory; - pData->iBACKimageid = ((mng_backp)pChunk)->iImageid; - pData->iBACKtile = ((mng_backp)pChunk)->iTile; - - return mng_create_ani_back (pData); -#else - return MNG_NOERROR; -#endif /* MNG_SUPPORT_DISPLAY */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_FRAM -MNG_F_SPECIALFUNC (mng_fram_remainder) -{ - mng_framp pFRAM = (mng_framp)pChunk; - mng_uint32 iRawlen = *piRawlen; - mng_uint8p pRawdata = *ppRawdata; - mng_uint32 iRequired = 0; - - if (iRawlen < 4) /* must have at least 4 bytes */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - iRequired = 4; /* calculate and check required remaining length */ - - pFRAM->iChangedelay = *pRawdata; - pFRAM->iChangetimeout = *(pRawdata+1); - pFRAM->iChangeclipping = *(pRawdata+2); - pFRAM->iChangesyncid = *(pRawdata+3); - - if (pFRAM->iChangedelay ) { iRequired += 4; } - if (pFRAM->iChangetimeout ) { iRequired += 4; } - if (pFRAM->iChangeclipping) { iRequired += 17; } - - if (pFRAM->iChangesyncid) - { - if ((iRawlen - iRequired) % 4 != 0) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - else - { - if (iRawlen != iRequired) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - - pRawdata += 4; - - if (pFRAM->iChangedelay) /* delay changed ? */ - { - pFRAM->iDelay = mng_get_uint32 (pRawdata); - pRawdata += 4; - } - - if (pFRAM->iChangetimeout) /* timeout changed ? */ - { - pFRAM->iTimeout = mng_get_uint32 (pRawdata); - pRawdata += 4; - } - - if (pFRAM->iChangeclipping) /* clipping changed ? */ - { - pFRAM->iBoundarytype = *pRawdata; - pFRAM->iBoundaryl = mng_get_int32 (pRawdata+1); - pFRAM->iBoundaryr = mng_get_int32 (pRawdata+5); - pFRAM->iBoundaryt = mng_get_int32 (pRawdata+9); - pFRAM->iBoundaryb = mng_get_int32 (pRawdata+13); - pRawdata += 17; - } - - if (pFRAM->iChangesyncid) - { - pFRAM->iCount = (iRawlen - iRequired) / 4; - - if (pFRAM->iCount) - { - MNG_ALLOC (pData, pFRAM->pSyncids, pFRAM->iCount * 4); - -#ifndef MNG_BIGENDIAN_SUPPORTED - { - mng_uint32 iX; - mng_uint32p pOut = pFRAM->pSyncids; - - for (iX = pFRAM->iCount; iX > 0; iX--) - { - *pOut++ = mng_get_uint32 (pRawdata); - pRawdata += 4; - } - } -#else - MNG_COPY (pFRAM->pSyncids, pRawdata, pFRAM->iCount * 4); -#endif /* !MNG_BIGENDIAN_SUPPORTED */ - } - } - -#ifndef MNG_NO_OLD_VERSIONS - if (pData->bPreDraft48) /* old style input-stream ? */ - { - switch (pFRAM->iMode) /* fix the framing mode then */ - { - case 0: { break; } - case 1: { pFRAM->iMode = 3; break; } - case 2: { pFRAM->iMode = 4; break; } - case 3: { pFRAM->iMode = 1; break; } - case 4: { pFRAM->iMode = 1; break; } - case 5: { pFRAM->iMode = 2; break; } - default: { pFRAM->iMode = 1; break; } - } - } -#endif - - *piRawlen = 0; - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_FRAM -MNG_C_SPECIALFUNC (mng_special_fram) -{ -#ifdef MNG_SUPPORT_DISPLAY - return mng_create_ani_fram (pData, pChunk); -#else - return MNG_NOERROR; -#endif /* MNG_SUPPORT_DISPLAY */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MOVE -MNG_C_SPECIALFUNC (mng_special_move) -{ -#ifdef MNG_SUPPORT_DISPLAY - return mng_create_ani_move (pData, pChunk); -#else - return MNG_NOERROR; -#endif /* MNG_SUPPORT_DISPLAY */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_CLIP -MNG_C_SPECIALFUNC (mng_special_clip) -{ -#ifdef MNG_SUPPORT_DISPLAY - return mng_create_ani_clip (pData, pChunk); -#else - return MNG_NOERROR; -#endif /* MNG_SUPPORT_DISPLAY */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SHOW -MNG_C_SPECIALFUNC (mng_special_show) -{ -#ifdef MNG_SUPPORT_DISPLAY - mng_retcode iRetcode; - - if (!((mng_showp)pChunk)->bEmpty) /* any data ? */ - { - if (!((mng_showp)pChunk)->bHaslastid) - ((mng_showp)pChunk)->iLastid = ((mng_showp)pChunk)->iFirstid; - - pData->iSHOWfromid = ((mng_showp)pChunk)->iFirstid; - pData->iSHOWtoid = ((mng_showp)pChunk)->iLastid; - pData->iSHOWmode = ((mng_showp)pChunk)->iMode; - } - else /* use defaults then */ - { - pData->iSHOWfromid = 1; - pData->iSHOWtoid = 65535; - pData->iSHOWmode = 2; - } - /* create a SHOW animation object */ - iRetcode = mng_create_ani_show (pData); - if (!iRetcode) /* go and do it! */ - iRetcode = mng_process_display_show (pData); - -#endif /* MNG_SUPPORT_DISPLAY */ - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_TERM -MNG_C_SPECIALFUNC (mng_special_term) -{ - /* should be behind MHDR or SAVE !! */ - if ((!pData->bHasSAVE) && (pData->iChunkseq > 2)) - { - pData->bMisplacedTERM = MNG_TRUE; /* indicate we found a misplaced TERM */ - /* and send a warning signal!!! */ - MNG_WARNING (pData, MNG_SEQUENCEERROR); - } - - pData->bHasTERM = MNG_TRUE; - - if (pData->fProcessterm) /* inform the app ? */ - if (!pData->fProcessterm (((mng_handle)pData), - ((mng_termp)pChunk)->iTermaction, - ((mng_termp)pChunk)->iIteraction, - ((mng_termp)pChunk)->iDelay, - ((mng_termp)pChunk)->iItermax)) - MNG_ERROR (pData, MNG_APPMISCERROR); - -#ifdef MNG_SUPPORT_DISPLAY - { /* create the TERM ani-object */ - mng_retcode iRetcode = mng_create_ani_term (pData, pChunk); - if (iRetcode) /* on error bail out */ - return iRetcode; - /* save for future reference */ - pData->pTermaniobj = pData->pLastaniobj; - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SAVE -MNG_F_SPECIALFUNC (mng_save_entries) -{ - mng_savep pSAVE = (mng_savep)pChunk; - mng_uint32 iRawlen = *piRawlen; - mng_uint8p pRawdata = *ppRawdata; - mng_save_entryp pEntry = MNG_NULL; - mng_uint32 iCount = 0; - mng_uint8 iOtype = *pRawdata; - mng_uint8 iEtype; - mng_uint8p pTemp; - mng_uint8p pNull; - mng_uint32 iLen; - mng_uint32 iOffset[2]; - mng_uint32 iStarttime[2]; - mng_uint32 iFramenr; - mng_uint32 iLayernr; - mng_uint32 iX; - mng_uint32 iNamesize; - - if ((iOtype != 4) && (iOtype != 8)) - MNG_ERROR (pData, MNG_INVOFFSETSIZE); - - pSAVE->iOffsettype = iOtype; - - for (iX = 0; iX < 2; iX++) /* do this twice to get the count first ! */ - { - pTemp = pRawdata + 1; - iLen = iRawlen - 1; - - if (iX) /* second run ? */ - { - MNG_ALLOC (pData, pEntry, (iCount * sizeof (mng_save_entry))); - - pSAVE->iCount = iCount; - pSAVE->pEntries = pEntry; - } - - while (iLen) /* anything left ? */ - { - iEtype = *pTemp; /* entrytype */ - - if ((iEtype != 0) && (iEtype != 1) && (iEtype != 2) && (iEtype != 3)) - MNG_ERROR (pData, MNG_INVENTRYTYPE); - - pTemp++; - - if (iEtype > 1) - { - iOffset [0] = 0; - iOffset [1] = 0; - iStarttime [0] = 0; - iStarttime [1] = 0; - iLayernr = 0; - iFramenr = 0; - } - else - { - if (iOtype == 4) - { - iOffset [0] = 0; - iOffset [1] = mng_get_uint32 (pTemp); - - pTemp += 4; - } - else - { - iOffset [0] = mng_get_uint32 (pTemp); - iOffset [1] = mng_get_uint32 (pTemp+4); - - pTemp += 8; - } - - if (iEtype > 0) - { - iStarttime [0] = 0; - iStarttime [1] = 0; - iLayernr = 0; - iFramenr = 0; - } - else - { - if (iOtype == 4) - { - iStarttime [0] = 0; - iStarttime [1] = mng_get_uint32 (pTemp+0); - iLayernr = mng_get_uint32 (pTemp+4); - iFramenr = mng_get_uint32 (pTemp+8); - - pTemp += 12; - } - else - { - iStarttime [0] = mng_get_uint32 (pTemp+0); - iStarttime [1] = mng_get_uint32 (pTemp+4); - iLayernr = mng_get_uint32 (pTemp+8); - iFramenr = mng_get_uint32 (pTemp+12); - - pTemp += 16; - } - } - } - - pNull = pTemp; /* get the name length */ - while (*pNull) - pNull++; - - if ((pNull - pRawdata) > (mng_int32)iRawlen) - { - iNamesize = iLen; /* no null found; so end of SAVE */ - iLen = 0; - } - else - { - iNamesize = pNull - pTemp; /* should be another entry */ - iLen -= iNamesize; - - if (!iLen) /* must not end with a null ! */ - MNG_ERROR (pData, MNG_ENDWITHNULL); - } - - if (!pEntry) - { - iCount++; - } - else - { - pEntry->iEntrytype = iEtype; - pEntry->iOffset [0] = iOffset [0]; - pEntry->iOffset [1] = iOffset [1]; - pEntry->iStarttime [0] = iStarttime [0]; - pEntry->iStarttime [1] = iStarttime [1]; - pEntry->iLayernr = iLayernr; - pEntry->iFramenr = iFramenr; - pEntry->iNamesize = iNamesize; - - if (iNamesize) - { - MNG_ALLOC (pData, pEntry->zName, iNamesize+1); - MNG_COPY (pEntry->zName, pTemp, iNamesize); - } - - pEntry++; - } - - pTemp += iNamesize; - } - } - - *piRawlen = 0; - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SAVE -MNG_C_SPECIALFUNC (mng_special_save) -{ - pData->bHasSAVE = MNG_TRUE; - - if (pData->fProcesssave) /* inform the application ? */ - { - mng_bool bOke = pData->fProcesssave ((mng_handle)pData); - if (!bOke) - MNG_ERROR (pData, MNG_APPMISCERROR); - } - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode; - - /* TODO: something with the parameters */ - - /* create a SAVE animation object */ - iRetcode = mng_create_ani_save (pData); - if (!iRetcode) /* process it */ - iRetcode = mng_process_display_save (pData); - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SEEK -MNG_C_SPECIALFUNC (mng_special_seek) -{ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_DISPLAY - /* create a SEEK animation object */ - iRetcode = mng_create_ani_seek (pData, pChunk); - if (iRetcode) /* on error bail out */ - return iRetcode; - -#endif /* MNG_SUPPORT_DISPLAY */ - - if (pData->fProcessseek) /* inform the app ? */ - if (!pData->fProcessseek ((mng_handle)pData, ((mng_seekp)pChunk)->zName)) - MNG_ERROR (pData, MNG_APPMISCERROR); - -#ifdef MNG_SUPPORT_DISPLAY - return mng_process_display_seek (pData); -#else - return MNG_NOERROR; -#endif /* MNG_SUPPORT_DISPLAY */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_eXPI -MNG_C_SPECIALFUNC (mng_special_expi) -{ -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_fPRI -MNG_C_SPECIALFUNC (mng_special_fpri) -{ -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_nEED -MNG_LOCAL mng_bool CheckKeyword (mng_datap pData, - mng_uint8p pKeyword) -{ - mng_chunkid handled_chunks [] = - { - MNG_UINT_BACK, /* keep it sorted !!!! */ - MNG_UINT_BASI, - MNG_UINT_CLIP, - MNG_UINT_CLON, -#ifndef MNG_NO_DELTA_PNG -/* TODO: MNG_UINT_DBYK, */ -#endif - MNG_UINT_DEFI, -#ifndef MNG_NO_DELTA_PNG - MNG_UINT_DHDR, -#endif - MNG_UINT_DISC, -#ifndef MNG_NO_DELTA_PNG -/* TODO: MNG_UINT_DROP, */ -#endif - MNG_UINT_ENDL, - MNG_UINT_FRAM, - MNG_UINT_IDAT, - MNG_UINT_IEND, - MNG_UINT_IHDR, -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG - MNG_UINT_IJNG, -#endif - MNG_UINT_IPNG, -#endif -#ifdef MNG_INCLUDE_JNG - MNG_UINT_JDAA, - MNG_UINT_JDAT, - MNG_UINT_JHDR, -/* TODO: MNG_UINT_JSEP, */ - MNG_UINT_JdAA, -#endif - MNG_UINT_LOOP, - MNG_UINT_MAGN, - MNG_UINT_MEND, - MNG_UINT_MHDR, - MNG_UINT_MOVE, -/* TODO: MNG_UINT_ORDR, */ - MNG_UINT_PAST, - MNG_UINT_PLTE, -#ifndef MNG_NO_DELTA_PNG - MNG_UINT_PPLT, - MNG_UINT_PROM, -#endif - MNG_UINT_SAVE, - MNG_UINT_SEEK, - MNG_UINT_SHOW, - MNG_UINT_TERM, - MNG_UINT_bKGD, - MNG_UINT_cHRM, -/* TODO: MNG_UINT_eXPI, */ - MNG_UINT_evNT, -/* TODO: MNG_UINT_fPRI, */ - MNG_UINT_gAMA, -/* TODO: MNG_UINT_hIST, */ - MNG_UINT_iCCP, - MNG_UINT_iTXt, - MNG_UINT_nEED, -/* TODO: MNG_UINT_oFFs, */ -/* TODO: MNG_UINT_pCAL, */ -/* TODO: MNG_UINT_pHYg, */ -/* TODO: MNG_UINT_pHYs, */ -/* TODO: MNG_UINT_sBIT, */ -/* TODO: MNG_UINT_sCAL, */ -/* TODO: MNG_UINT_sPLT, */ - MNG_UINT_sRGB, - MNG_UINT_tEXt, - MNG_UINT_tIME, - MNG_UINT_tRNS, - MNG_UINT_zTXt, - }; - - mng_bool bOke = MNG_FALSE; - - if (pData->fProcessneed) /* does the app handle it ? */ - bOke = pData->fProcessneed ((mng_handle)pData, (mng_pchar)pKeyword); - - if (!bOke) - { /* find the keyword length */ - mng_uint8p pNull = pKeyword; - while (*pNull) - pNull++; - - if ((pNull - pKeyword) == 4) /* test a chunk ? */ - { /* get the chunk-id */ - mng_chunkid iChunkid = (*pKeyword << 24) + (*(pKeyword+1) << 16) + - (*(pKeyword+2) << 8) + (*(pKeyword+3) ); - /* binary search variables */ - mng_int32 iTop, iLower, iUpper, iMiddle; - /* determine max index of table */ - iTop = (sizeof (handled_chunks) / sizeof (handled_chunks [0])) - 1; - - /* binary search; with 52 chunks, worst-case is 7 comparisons */ - iLower = 0; - iMiddle = iTop >> 1; - iUpper = iTop; - - do /* the binary search itself */ - { - if (handled_chunks [iMiddle] < iChunkid) - iLower = iMiddle + 1; - else if (handled_chunks [iMiddle] > iChunkid) - iUpper = iMiddle - 1; - else - { - bOke = MNG_TRUE; - break; - } - - iMiddle = (iLower + iUpper) >> 1; - } - while (iLower <= iUpper); - } - /* test draft ? */ - if ((!bOke) && ((pNull - pKeyword) == 8) && - (*pKeyword == 'd') && (*(pKeyword+1) == 'r') && - (*(pKeyword+2) == 'a') && (*(pKeyword+3) == 'f') && - (*(pKeyword+4) == 't') && (*(pKeyword+5) == ' ')) - { - mng_uint32 iDraft; - - iDraft = (*(pKeyword+6) - '0') * 10 + (*(pKeyword+7) - '0'); - bOke = (mng_bool)(iDraft <= MNG_MNG_DRAFT); - } - /* test MNG 1.0/1.1 ? */ - if ((!bOke) && ((pNull - pKeyword) == 7) && - (*pKeyword == 'M') && (*(pKeyword+1) == 'N') && - (*(pKeyword+2) == 'G') && (*(pKeyword+3) == '-') && - (*(pKeyword+4) == '1') && (*(pKeyword+5) == '.') && - ((*(pKeyword+6) == '0') || (*(pKeyword+6) == '1'))) - bOke = MNG_TRUE; - /* test CACHEOFF ? */ - if ((!bOke) && ((pNull - pKeyword) == 8) && - (*pKeyword == 'C') && (*(pKeyword+1) == 'A') && - (*(pKeyword+2) == 'C') && (*(pKeyword+3) == 'H') && - (*(pKeyword+4) == 'E') && (*(pKeyword+5) == 'O') && - (*(pKeyword+6) == 'F') && (*(pKeyword+7) == 'F')) - { - if (!pData->pFirstaniobj) /* only if caching hasn't started yet ! */ - { - bOke = MNG_TRUE; - pData->bCacheplayback = MNG_FALSE; - pData->bStorechunks = MNG_FALSE; - } - } - } - - return bOke; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_nEED -MNG_C_SPECIALFUNC (mng_special_need) -{ - /* let's check it */ - mng_bool bOke = MNG_TRUE; - mng_uint8p pNull, pTemp, pMax; - - pTemp = (mng_uint8p)((mng_needp)pChunk)->zKeywords; - pMax = (mng_uint8p)(pTemp + ((mng_needp)pChunk)->iKeywordssize); - pNull = pTemp; - while (*pNull) - pNull++; - - while ((bOke) && (pNull < pMax)) - { - bOke = CheckKeyword (pData, pTemp); - pTemp = pNull + 1; - pNull = pTemp; - while (*pNull) - pNull++; - } - - if (bOke) - bOke = CheckKeyword (pData, pTemp); - - if (!bOke) - MNG_ERROR (pData, MNG_UNSUPPORTEDNEED); - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_pHYg -MNG_C_SPECIALFUNC (mng_special_phyg) -{ -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -MNG_C_SPECIALFUNC (mng_special_dhdr) -{ - if ((((mng_dhdrp)pChunk)->iDeltatype == MNG_DELTATYPE_REPLACE) && (((mng_dhdrp)pChunk)->bHasblockloc)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - if ((((mng_dhdrp)pChunk)->iDeltatype == MNG_DELTATYPE_NOCHANGE) && (((mng_dhdrp)pChunk)->bHasblocksize)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - pData->bHasDHDR = MNG_TRUE; /* inside a DHDR-IEND block now */ - pData->iDeltatype = ((mng_dhdrp)pChunk)->iDeltatype; - - pData->iImagelevel++; /* one level deeper */ - -#ifdef MNG_SUPPORT_DISPLAY - return mng_create_ani_dhdr (pData, pChunk); -#else - return MNG_NOERROR; -#endif /* MNG_SUPPORT_DISPLAY */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -MNG_C_SPECIALFUNC (mng_special_prom) -{ - if ((((mng_promp)pChunk)->iColortype != MNG_COLORTYPE_GRAY ) && - (((mng_promp)pChunk)->iColortype != MNG_COLORTYPE_RGB ) && - (((mng_promp)pChunk)->iColortype != MNG_COLORTYPE_INDEXED) && - (((mng_promp)pChunk)->iColortype != MNG_COLORTYPE_GRAYA ) && - (((mng_promp)pChunk)->iColortype != MNG_COLORTYPE_RGBA ) ) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - -#ifdef MNG_NO_16BIT_SUPPORT - if (((mng_promp)pChunk)->iSampledepth == MNG_BITDEPTH_16 ) - ((mng_promp)pChunk)->iSampledepth = MNG_BITDEPTH_8; -#endif - - if ((((mng_promp)pChunk)->iSampledepth != MNG_BITDEPTH_1 ) && - (((mng_promp)pChunk)->iSampledepth != MNG_BITDEPTH_2 ) && - (((mng_promp)pChunk)->iSampledepth != MNG_BITDEPTH_4 ) && - (((mng_promp)pChunk)->iSampledepth != MNG_BITDEPTH_8 ) -#ifndef MNG_NO_16BIT_SUPPORT - && (((mng_promp)pChunk)->iSampledepth != MNG_BITDEPTH_16) -#endif - ) - MNG_ERROR (pData, MNG_INVSAMPLEDEPTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode = mng_create_ani_prom (pData, pChunk); - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -MNG_C_SPECIALFUNC (mng_special_ipng) -{ -#ifdef MNG_SUPPORT_DISPLAY - mng_retcode iRetcode = mng_create_ani_ipng (pData); - if (!iRetcode) /* process it */ - iRetcode = mng_process_display_ipng (pData); - if (iRetcode) /* on error bail out */ - return iRetcode; -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -MNG_F_SPECIALFUNC (mng_pplt_entries) -{ - mng_ppltp pPPLT = (mng_ppltp)pChunk; - mng_uint32 iRawlen = *piRawlen; - mng_uint8p pRawdata = *ppRawdata; - mng_uint8 iDeltatype = pPPLT->iDeltatype; - mng_uint32 iMax = 0; - mng_int32 iX, iY, iM; - mng_rgbpaltab aIndexentries; - mng_uint8arr aAlphaentries; - mng_uint8arr aUsedentries; - /* must be indexed color ! */ - if (pData->iColortype != MNG_COLORTYPE_INDEXED) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - - for (iY = 255; iY >= 0; iY--) /* reset arrays */ - { - aIndexentries [iY].iRed = 0; - aIndexentries [iY].iGreen = 0; - aIndexentries [iY].iBlue = 0; - aAlphaentries [iY] = 255; - aUsedentries [iY] = 0; - } - - while (iRawlen) /* as long as there are entries left ... */ - { - mng_uint32 iDiff; - - if (iRawlen < 2) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - iX = (mng_int32)(*pRawdata); /* get start and end index */ - iM = (mng_int32)(*(pRawdata+1)); - - if (iM < iX) - MNG_ERROR (pData, MNG_INVALIDINDEX); - - if (iM >= (mng_int32) iMax) /* determine highest used index */ - iMax = iM + 1; - - pRawdata += 2; - iRawlen -= 2; - iDiff = (iM - iX + 1); - if ((iDeltatype == MNG_DELTATYPE_REPLACERGB ) || - (iDeltatype == MNG_DELTATYPE_DELTARGB ) ) - iDiff = iDiff * 3; - else - if ((iDeltatype == MNG_DELTATYPE_REPLACERGBA) || - (iDeltatype == MNG_DELTATYPE_DELTARGBA ) ) - iDiff = iDiff * 4; - - if (iRawlen < iDiff) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((iDeltatype == MNG_DELTATYPE_REPLACERGB ) || - (iDeltatype == MNG_DELTATYPE_DELTARGB ) ) - { - for (iY = iX; iY <= iM; iY++) - { - aIndexentries [iY].iRed = *pRawdata; - aIndexentries [iY].iGreen = *(pRawdata+1); - aIndexentries [iY].iBlue = *(pRawdata+2); - aUsedentries [iY] = 1; - - pRawdata += 3; - iRawlen -= 3; - } - } - else - if ((iDeltatype == MNG_DELTATYPE_REPLACEALPHA) || - (iDeltatype == MNG_DELTATYPE_DELTAALPHA ) ) - { - for (iY = iX; iY <= iM; iY++) - { - aAlphaentries [iY] = *pRawdata; - aUsedentries [iY] = 1; - - pRawdata++; - iRawlen--; - } - } - else - { - for (iY = iX; iY <= iM; iY++) - { - aIndexentries [iY].iRed = *pRawdata; - aIndexentries [iY].iGreen = *(pRawdata+1); - aIndexentries [iY].iBlue = *(pRawdata+2); - aAlphaentries [iY] = *(pRawdata+3); - aUsedentries [iY] = 1; - - pRawdata += 4; - iRawlen -= 4; - } - } - } - - switch (pData->iBitdepth) /* check maximum allowed entries for bitdepth */ - { - case MNG_BITDEPTH_1 : { - if (iMax > 2) - MNG_ERROR (pData, MNG_INVALIDINDEX); - break; - } - case MNG_BITDEPTH_2 : { - if (iMax > 4) - MNG_ERROR (pData, MNG_INVALIDINDEX); - break; - } - case MNG_BITDEPTH_4 : { - if (iMax > 16) - MNG_ERROR (pData, MNG_INVALIDINDEX); - break; - } - } - - pPPLT->iCount = iMax; - - for (iY = 255; iY >= 0; iY--) - { - pPPLT->aEntries [iY].iRed = aIndexentries [iY].iRed; - pPPLT->aEntries [iY].iGreen = aIndexentries [iY].iGreen; - pPPLT->aEntries [iY].iBlue = aIndexentries [iY].iBlue; - pPPLT->aEntries [iY].iAlpha = aAlphaentries [iY]; - pPPLT->aEntries [iY].bUsed = (mng_bool)(aUsedentries [iY]); - } - - { /* create animation object */ - mng_retcode iRetcode = mng_create_ani_pplt (pData, iDeltatype, iMax, - aIndexentries, aAlphaentries, - aUsedentries); - if (iRetcode) - return iRetcode; - } - - *piRawlen = 0; - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -MNG_C_SPECIALFUNC (mng_special_pplt) -{ - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG -MNG_C_SPECIALFUNC (mng_special_ijng) -{ -#ifdef MNG_SUPPORT_DISPLAY - mng_retcode iRetcode = mng_create_ani_ijng (pData); - if (!iRetcode) /* process it */ - iRetcode = mng_process_display_ijng (pData); - return iRetcode; -#else - return MNG_NOERROR; /* done */ -#endif /* MNG_SUPPORT_DISPLAY */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -MNG_F_SPECIALFUNC (mng_drop_entries) -{ - mng_dropp pDROP = (mng_dropp)pChunk; - mng_uint32 iRawlen = *piRawlen; - mng_uint8p pRawdata = *ppRawdata; - mng_uint32 iX; - mng_uint32p pEntry; - /* check length */ - if ((iRawlen < 4) || ((iRawlen % 4) != 0)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - MNG_ALLOC (pData, pEntry, iRawlen); - pDROP->iCount = iRawlen / 4; - pDROP->pChunknames = (mng_ptr)pEntry; - - for (iX = pDROP->iCount; iX > 0; iX--) - { - *pEntry++ = mng_get_uint32 (pRawdata); - pRawdata += 4; - } - - *piRawlen = 0; - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -MNG_C_SPECIALFUNC (mng_special_drop) -{ -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DBYK -MNG_C_SPECIALFUNC (mng_special_dbyk) -{ -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR -MNG_F_SPECIALFUNC (mng_ordr_entries) -{ - mng_ordrp pORDR = (mng_ordrp)pChunk; - mng_uint32 iRawlen = *piRawlen; - mng_uint8p pRawdata = *ppRawdata; - mng_uint32 iX; - mng_ordr_entryp pEntry; - /* check length */ - if ((iRawlen < 5) || ((iRawlen % 5) != 0)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - MNG_ALLOC (pData, pEntry, iRawlen); - pORDR->iCount = iRawlen / 5; - pORDR->pEntries = (mng_ptr)pEntry; - - for (iX = pORDR->iCount; iX > 0; iX--) - { - pEntry->iChunkname = mng_get_uint32 (pRawdata); - pEntry->iOrdertype = *(pRawdata+4); - pEntry++; - pRawdata += 5; - } - - *piRawlen = 0; - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR -MNG_C_SPECIALFUNC (mng_special_ordr) -{ -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MAGN -MNG_F_SPECIALFUNC (mng_debunk_magn) -{ - mng_magnp pMAGN = (mng_magnp)pChunk; - mng_uint32 iRawlen = *piRawlen; - mng_uint8p pRawdata = *ppRawdata; - mng_bool bFaulty; - /* check length */ - if (iRawlen > 20) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - /* following is an ugly hack to allow faulty layout caused by previous - versions of libmng and MNGeye, which wrote MAGN with a 16-bit - MethodX/MethodY (as opposed to the proper 8-bit as defined in the spec!) */ - - if ((iRawlen == 6) || (iRawlen == 8) || (iRawlen == 10) || (iRawlen == 12) || - (iRawlen == 14) || (iRawlen == 16) || (iRawlen == 20)) - bFaulty = MNG_TRUE; /* these lengths are all wrong */ - else /* length 18 can be right or wrong !!! */ - if ((iRawlen == 18) && (mng_get_uint16 (pRawdata+4) <= 5) && - (mng_get_uint16 (pRawdata+6) < 256) && - (mng_get_uint16 (pRawdata+8) < 256) && - (mng_get_uint16 (pRawdata+10) < 256) && - (mng_get_uint16 (pRawdata+12) < 256) && - (mng_get_uint16 (pRawdata+14) < 256) && - (mng_get_uint16 (pRawdata+16) < 256)) - bFaulty = MNG_TRUE; /* this is very likely the wrong layout */ - else - bFaulty = MNG_FALSE; /* all other cases are handled as right */ - - if (bFaulty) /* wrong layout ? */ - { - if (iRawlen > 0) /* get the fields */ - pMAGN->iFirstid = mng_get_uint16 (pRawdata); - else - pMAGN->iFirstid = 0; - - if (iRawlen > 2) - pMAGN->iLastid = mng_get_uint16 (pRawdata+2); - else - pMAGN->iLastid = pMAGN->iFirstid; - - if (iRawlen > 4) - pMAGN->iMethodX = (mng_uint8)(mng_get_uint16 (pRawdata+4)); - else - pMAGN->iMethodX = 0; - - if (iRawlen > 6) - pMAGN->iMX = mng_get_uint16 (pRawdata+6); - else - pMAGN->iMX = 1; - - if (iRawlen > 8) - pMAGN->iMY = mng_get_uint16 (pRawdata+8); - else - pMAGN->iMY = pMAGN->iMX; - - if (iRawlen > 10) - pMAGN->iML = mng_get_uint16 (pRawdata+10); - else - pMAGN->iML = pMAGN->iMX; - - if (iRawlen > 12) - pMAGN->iMR = mng_get_uint16 (pRawdata+12); - else - pMAGN->iMR = pMAGN->iMX; - - if (iRawlen > 14) - pMAGN->iMT = mng_get_uint16 (pRawdata+14); - else - pMAGN->iMT = pMAGN->iMY; - - if (iRawlen > 16) - pMAGN->iMB = mng_get_uint16 (pRawdata+16); - else - pMAGN->iMB = pMAGN->iMY; - - if (iRawlen > 18) - pMAGN->iMethodY = (mng_uint8)(mng_get_uint16 (pRawdata+18)); - else - pMAGN->iMethodY = pMAGN->iMethodX; - } - else /* proper layout !!!! */ - { - if (iRawlen > 0) /* get the fields */ - pMAGN->iFirstid = mng_get_uint16 (pRawdata); - else - pMAGN->iFirstid = 0; - - if (iRawlen > 2) - pMAGN->iLastid = mng_get_uint16 (pRawdata+2); - else - pMAGN->iLastid = pMAGN->iFirstid; - - if (iRawlen > 4) - pMAGN->iMethodX = *(pRawdata+4); - else - pMAGN->iMethodX = 0; - - if (iRawlen > 5) - pMAGN->iMX = mng_get_uint16 (pRawdata+5); - else - pMAGN->iMX = 1; - - if (iRawlen > 7) - pMAGN->iMY = mng_get_uint16 (pRawdata+7); - else - pMAGN->iMY = pMAGN->iMX; - - if (iRawlen > 9) - pMAGN->iML = mng_get_uint16 (pRawdata+9); - else - pMAGN->iML = pMAGN->iMX; - - if (iRawlen > 11) - pMAGN->iMR = mng_get_uint16 (pRawdata+11); - else - pMAGN->iMR = pMAGN->iMX; - - if (iRawlen > 13) - pMAGN->iMT = mng_get_uint16 (pRawdata+13); - else - pMAGN->iMT = pMAGN->iMY; - - if (iRawlen > 15) - pMAGN->iMB = mng_get_uint16 (pRawdata+15); - else - pMAGN->iMB = pMAGN->iMY; - - if (iRawlen > 17) - pMAGN->iMethodY = *(pRawdata+17); - else - pMAGN->iMethodY = pMAGN->iMethodX; - } - /* check field validity */ - if ((pMAGN->iMethodX > 5) || (pMAGN->iMethodY > 5)) - MNG_ERROR (pData, MNG_INVALIDMETHOD); - - *piRawlen = 0; - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MAGN -MNG_C_SPECIALFUNC (mng_special_magn) -{ -#ifdef MNG_SUPPORT_DISPLAY - return mng_create_ani_magn (pData, pChunk); -#else - return MNG_NOERROR; -#endif /* MNG_SUPPORT_DISPLAY */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_evNT -MNG_F_SPECIALFUNC (mng_evnt_entries) -{ - mng_evntp pEVNT = (mng_evntp)pChunk; - mng_uint32 iRawlen; - mng_uint8p pRawdata; -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_SUPPORT_DYNAMICMNG) - mng_retcode iRetcode; -#endif - mng_uint8p pNull; - mng_uint8 iEventtype; - mng_uint8 iMasktype; - mng_int32 iLeft; - mng_int32 iRight; - mng_int32 iTop; - mng_int32 iBottom; - mng_uint16 iObjectid; - mng_uint8 iIndex; - mng_uint32 iNamesize; - mng_uint32 iCount = 0; - mng_evnt_entryp pEntry = MNG_NULL; - mng_uint32 iX; - - for (iX = 0; iX < 2; iX++) - { - iRawlen = *piRawlen; - pRawdata = *ppRawdata; - - if (iX) /* second run ? */ - { - MNG_ALLOC (pData, pEntry, (iCount * sizeof (mng_evnt_entry))); - pEVNT->iCount = iCount; - pEVNT->pEntries = pEntry; - } - - while (iRawlen) /* anything left ? */ - { - if (iRawlen < 2) /* must have at least 2 bytes ! */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - iEventtype = *pRawdata; /* eventtype */ - if (iEventtype > 5) - MNG_ERROR (pData, MNG_INVALIDEVENT); - - pRawdata++; - - iMasktype = *pRawdata; /* masktype */ - if (iMasktype > 5) - MNG_ERROR (pData, MNG_INVALIDMASK); - - pRawdata++; - iRawlen -= 2; - - iLeft = 0; - iRight = 0; - iTop = 0; - iBottom = 0; - iObjectid = 0; - iIndex = 0; - - switch (iMasktype) - { - case 1 : - { - if (iRawlen > 16) - { - iLeft = mng_get_int32 (pRawdata); - iRight = mng_get_int32 (pRawdata+4); - iTop = mng_get_int32 (pRawdata+8); - iBottom = mng_get_int32 (pRawdata+12); - pRawdata += 16; - iRawlen -= 16; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - case 2 : - { - if (iRawlen > 2) - { - iObjectid = mng_get_uint16 (pRawdata); - pRawdata += 2; - iRawlen -= 2; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - case 3 : - { - if (iRawlen > 3) - { - iObjectid = mng_get_uint16 (pRawdata); - iIndex = *(pRawdata+2); - pRawdata += 3; - iRawlen -= 3; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - case 4 : - { - if (iRawlen > 18) - { - iLeft = mng_get_int32 (pRawdata); - iRight = mng_get_int32 (pRawdata+4); - iTop = mng_get_int32 (pRawdata+8); - iBottom = mng_get_int32 (pRawdata+12); - iObjectid = mng_get_uint16 (pRawdata+16); - pRawdata += 18; - iRawlen -= 18; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - case 5 : - { - if (iRawlen > 19) - { - iLeft = mng_get_int32 (pRawdata); - iRight = mng_get_int32 (pRawdata+4); - iTop = mng_get_int32 (pRawdata+8); - iBottom = mng_get_int32 (pRawdata+12); - iObjectid = mng_get_uint16 (pRawdata+16); - iIndex = *(pRawdata+18); - pRawdata += 19; - iRawlen -= 19; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - } - - pNull = pRawdata; /* get the name length */ - while (*pNull) - pNull++; - - if ((pNull - pRawdata) > (mng_int32)iRawlen) - { - iNamesize = iRawlen; /* no null found; so end of evNT */ - iRawlen = 0; - } - else - { - iNamesize = pNull - pRawdata; /* should be another entry */ - iRawlen = iRawlen - iNamesize - 1; - - if (!iRawlen) /* must not end with a null ! */ - MNG_ERROR (pData, MNG_ENDWITHNULL); - } - - if (!iX) - { - iCount++; - } - else - { - pEntry->iEventtype = iEventtype; - pEntry->iMasktype = iMasktype; - pEntry->iLeft = iLeft; - pEntry->iRight = iRight; - pEntry->iTop = iTop; - pEntry->iBottom = iBottom; - pEntry->iObjectid = iObjectid; - pEntry->iIndex = iIndex; - pEntry->iSegmentnamesize = iNamesize; - - if (iNamesize) - { - MNG_ALLOC (pData, pEntry->zSegmentname, iNamesize+1); - MNG_COPY (pEntry->zSegmentname, pRawdata, iNamesize); - } - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_SUPPORT_DYNAMICMNG) - iRetcode = mng_create_event (pData, (mng_ptr)pEntry); - if (iRetcode) /* on error bail out */ - return iRetcode; -#endif - - pEntry++; - } - - pRawdata = pRawdata + iNamesize + 1; - } - } - - *piRawlen = 0; - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_evNT -MNG_C_SPECIALFUNC (mng_special_evnt) -{ - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_MPNG_PROPOSAL -MNG_C_SPECIALFUNC (mng_special_mpng) -{ - if ((pData->eImagetype != mng_it_png) && (pData->eImagetype != mng_it_jng)) - MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); - -#ifdef MNG_SUPPORT_DISPLAY - return mng_create_mpng_obj (pData, pChunk); -#else - return MNG_NOERROR; -#endif -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ANG_PROPOSAL -MNG_C_SPECIALFUNC (mng_special_ahdr) -{ -#ifdef MNG_SUPPORT_DISPLAY - return mng_create_ang_obj (pData, pChunk); -#else - return MNG_NOERROR; -#endif -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ANG_PROPOSAL -MNG_F_SPECIALFUNC (mng_adat_tiles) -{ - if ((pData->eImagetype != mng_it_ang) || (!pData->pANG)) - MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); - - { - mng_adatp pADAT = (mng_adatp)pChunk; - mng_ang_objp pANG = (mng_ang_objp)pData->pANG; - mng_uint32 iRawlen = *piRawlen; - mng_uint8p pRawdata = *ppRawdata; - mng_retcode iRetcode; - mng_uint8p pBuf; - mng_uint32 iBufsize; - mng_uint32 iRealsize; - mng_uint8p pTemp; - mng_uint8p pTemp2; - mng_int32 iX; - mng_int32 iSize; - -#ifdef MNG_SUPPORT_DISPLAY - mng_imagep pImage; - mng_int32 iTemplen; - mng_uint8p pSwap; - - mng_processobject pProcess; - - mng_uint32 iSavedatawidth; - mng_uint32 iSavedataheight; - - mng_fptr fSaveinitrowproc; - mng_fptr fSavestorerow; - mng_fptr fSaveprocessrow; - mng_fptr fSavedifferrow; - mng_imagep fSavestoreobj; - mng_imagedatap fSavestorebuf; - -#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT - png_imgtype eSavepngimgtype; -#endif - - mng_uint8 iSaveinterlace; - mng_int8 iSavepass; - mng_int32 iSaverow; - mng_int32 iSaverowinc; - mng_int32 iSavecol; - mng_int32 iSavecolinc; - mng_int32 iSaverowsamples; - mng_int32 iSavesamplemul; - mng_int32 iSavesampleofs; - mng_int32 iSavesamplediv; - mng_int32 iSaverowsize; - mng_int32 iSaverowmax; - mng_int32 iSavefilterofs; - mng_int32 iSavepixelofs; - mng_uint32 iSavelevel0; - mng_uint32 iSavelevel1; - mng_uint32 iSavelevel2; - mng_uint32 iSavelevel3; - mng_uint8p pSaveworkrow; - mng_uint8p pSaveprevrow; - mng_uint8p pSaverGBArow; - mng_bool bSaveisRGBA16; - mng_bool bSaveisOpaque; - mng_int32 iSavefilterbpp; - - mng_int32 iSavedestl; - mng_int32 iSavedestt; - mng_int32 iSavedestr; - mng_int32 iSavedestb; - mng_int32 iSavesourcel; - mng_int32 iSavesourcet; - mng_int32 iSavesourcer; - mng_int32 iSavesourceb; -#endif /* MNG_SUPPORT_DISPLAY */ - - iRetcode = mng_inflate_buffer (pData, pRawdata, iRawlen, - &pBuf, &iBufsize, &iRealsize); - if (iRetcode) /* on error bail out */ - { /* don't forget to drop the temp buffer */ - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - /* get buffer for tile info in ADAT chunk */ - pADAT->iTilessize = pANG->iNumframes * sizeof(mng_adat_tile); - MNG_ALLOCX (pData, pADAT->pTiles, pADAT->iTilessize); - if (!pADAT->pTiles) - { - pADAT->iTilessize = 0; - MNG_FREEX (pData, pBuf, iBufsize); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - - pTemp = pBuf; - pTemp2 = (mng_uint8p)pADAT->pTiles; - - if (!pANG->iStillused) - iSize = 12; - else - iSize = 13; - - for (iX = 0; iX < pANG->iNumframes; iX++) - { - MNG_COPY (pTemp2, pTemp, iSize); - pTemp += iSize; - pTemp2 += sizeof(mng_adat_tile); - } - -#ifdef MNG_SUPPORT_DISPLAY - /* get buffer for tile info in ANG object */ - pANG->iTilessize = pADAT->iTilessize; - MNG_ALLOCX (pData, pANG->pTiles, pANG->iTilessize); - if (!pANG->pTiles) - { - pANG->iTilessize = 0; - MNG_FREEX (pData, pBuf, iBufsize); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - /* copy it from the ADAT object */ - MNG_COPY (pANG->pTiles, pADAT->pTiles, pANG->iTilessize); - - /* save IDAT work-parms */ - fSaveinitrowproc = pData->fInitrowproc; - fSavestorerow = pData->fDisplayrow; - fSaveprocessrow = pData->fProcessrow; - fSavedifferrow = pData->fDifferrow; - fSavestoreobj = pData->pStoreobj; - fSavestorebuf = pData->pStorebuf; - -#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT - eSavepngimgtype = pData->ePng_imgtype; -#endif - - iSavedatawidth = pData->iDatawidth; - iSavedataheight = pData->iDataheight; - iSaveinterlace = pData->iInterlace; - iSavepass = pData->iPass; - iSaverow = pData->iRow; - iSaverowinc = pData->iRowinc; - iSavecol = pData->iCol; - iSavecolinc = pData->iColinc; - iSaverowsamples = pData->iRowsamples; - iSavesamplemul = pData->iSamplemul; - iSavesampleofs = pData->iSampleofs; - iSavesamplediv = pData->iSamplediv; - iSaverowsize = pData->iRowsize; - iSaverowmax = pData->iRowmax; - iSavefilterofs = pData->iFilterofs; - iSavepixelofs = pData->iPixelofs; - iSavelevel0 = pData->iLevel0; - iSavelevel1 = pData->iLevel1; - iSavelevel2 = pData->iLevel2; - iSavelevel3 = pData->iLevel3; - pSaveworkrow = pData->pWorkrow; - pSaveprevrow = pData->pPrevrow; - pSaverGBArow = pData->pRGBArow; - bSaveisRGBA16 = pData->bIsRGBA16; - bSaveisOpaque = pData->bIsOpaque; - iSavefilterbpp = pData->iFilterbpp; - iSavedestl = pData->iDestl; - iSavedestt = pData->iDestt; - iSavedestr = pData->iDestr; - iSavedestb = pData->iDestb; - iSavesourcel = pData->iSourcel; - iSavesourcet = pData->iSourcet; - iSavesourcer = pData->iSourcer; - iSavesourceb = pData->iSourceb; - - pData->iDatawidth = pANG->iTilewidth; - pData->iDataheight = pANG->iTileheight; - - pData->iDestl = 0; - pData->iDestt = 0; - pData->iDestr = pANG->iTilewidth; - pData->iDestb = pANG->iTileheight; - pData->iSourcel = 0; - pData->iSourcet = 0; - pData->iSourcer = pANG->iTilewidth; - pData->iSourceb = pANG->iTileheight; - - pData->fInitrowproc = MNG_NULL; - pData->fStorerow = MNG_NULL; - pData->fProcessrow = MNG_NULL; - pData->fDifferrow = MNG_NULL; - - /* clone image object to store the pixel-data from object 0 */ - iRetcode = mng_clone_imageobject (pData, 1, MNG_FALSE, MNG_FALSE, MNG_FALSE, - MNG_FALSE, 0, 0, 0, pData->pObjzero, &pImage); - if (iRetcode) /* on error, drop temp buffer and bail */ - { - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - - /* make sure we got the right dimensions and interlacing */ - iRetcode = mng_reset_object_details (pData, pImage, pANG->iTilewidth, pANG->iTileheight, - pImage->pImgbuf->iBitdepth, pImage->pImgbuf->iColortype, - pImage->pImgbuf->iCompression, pImage->pImgbuf->iFilter, - pANG->iInterlace, MNG_FALSE); - if (iRetcode) /* on error, drop temp buffer and bail */ - { - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - - pData->pStoreobj = pImage; - -#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT - pData->fInitrowproc = (mng_fptr)mng_init_rowproc; - pData->ePng_imgtype = mng_png_imgtype(pData->iColortype,pData->iBitdepth); -#else - switch (pData->iColortype) /* determine row initialization routine */ - { - case 0 : { /* gray */ - switch (pData->iBitdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g1_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g1_i; - - break; - } - case 2 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g2_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g2_i; - - break; - } - case 4 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g4_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g4_i; - break; - } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g8_i; - - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g16_i; - - break; - } -#endif - } - - break; - } - case 2 : { /* rgb */ - switch (pData->iBitdepth) - { - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i; - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i; - - break; - } -#endif - } - - break; - } - case 3 : { /* indexed */ - switch (pData->iBitdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx1_i; - - break; - } - case 2 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx2_i; - - break; - } - case 4 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx4_i; - - break; - } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx8_i; - - break; - } - } - - break; - } - case 4 : { /* gray+alpha */ - switch (pData->iBitdepth) - { - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_ga8_i; - - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_ga16_i; - break; - } -#endif - } - - break; - } - case 6 : { /* rgb+alpha */ - switch (pData->iBitdepth) - { - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i; - - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i; - - break; - } -#endif - } - - break; - } - } -#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ - - pData->iFilterofs = 0; /* determine filter characteristics */ - pData->iLevel0 = 0; /* default levels */ - pData->iLevel1 = 0; - pData->iLevel2 = 0; - pData->iLevel3 = 0; - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - { - switch (pData->iColortype) - { - case 0 : { - if (pData->iBitdepth <= 8) - pData->iFilterofs = 1; - else - pData->iFilterofs = 2; - - break; - } - case 2 : { - if (pData->iBitdepth <= 8) - pData->iFilterofs = 3; - else - pData->iFilterofs = 6; - - break; - } - case 3 : { - pData->iFilterofs = 1; - break; - } - case 4 : { - if (pData->iBitdepth <= 8) - pData->iFilterofs = 2; - else - pData->iFilterofs = 4; - - break; - } - case 6 : { - if (pData->iBitdepth <= 8) - pData->iFilterofs = 4; - else - pData->iFilterofs = 8; - - break; - } - } - } -#endif - -#ifdef FILTER193 /* no adaptive filtering ? */ - if (pData->iFilter == MNG_FILTER_NOFILTER) - pData->iPixelofs = pData->iFilterofs; - else -#endif - pData->iPixelofs = pData->iFilterofs + 1; - - if (pData->fInitrowproc) /* need to initialize row processing? */ - { - iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData); - if (iRetcode) - { - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - } - /* calculate remainder of buffer */ - pTemp = pBuf + (mng_int32)(pANG->iNumframes * iSize); - iTemplen = iRealsize - (mng_int32)(pANG->iNumframes * iSize); - - do - { - if (iTemplen > pData->iRowmax) /* get a pixel-row from the temp buffer */ - { - MNG_COPY (pData->pWorkrow, pTemp, pData->iRowmax); - } - else - { - MNG_COPY (pData->pWorkrow, pTemp, iTemplen); - } - - { /* image not completed yet ? */ - if (pData->iRow < (mng_int32)pData->iDataheight) - { -#ifdef MNG_NO_1_2_4BIT_SUPPORT - if (pData->iPNGdepth == 1) - { - /* Inflate Workrow to 8-bit */ - mng_int32 iX; - mng_uint8p pSrc = pData->pWorkrow+1; - mng_uint8p pDest = pSrc + pData->iRowsize - (pData->iRowsize+7)/8; - - for (iX = ((pData->iRowsize+7)/8) ; iX > 0 ; iX--) - *pDest++ = *pSrc++; - - pDest = pData->pWorkrow+1; - pSrc = pDest + pData->iRowsize - (pData->iRowsize+7)/8; - for (iX = pData->iRowsize; ;) - { - *pDest++ = (((*pSrc)>>7)&1); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>6)&1); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>5)&1); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>4)&1); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>3)&1); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>2)&1); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>1)&1); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc) )&1); - if (iX-- <= 0) - break; - pSrc++; - } - } - else if (pData->iPNGdepth == 2) - { - /* Inflate Workrow to 8-bit */ - mng_int32 iX; - mng_uint8p pSrc = pData->pWorkrow+1; - mng_uint8p pDest = pSrc + pData->iRowsize - (2*pData->iRowsize+7)/8; - - for (iX = ((2*pData->iRowsize+7)/8) ; iX > 0 ; iX--) - *pDest++ = *pSrc++; - - pDest = pData->pWorkrow+1; - pSrc = pDest + pData->iRowsize - (2*pData->iRowsize+7)/8; - for (iX = pData->iRowsize; ;) - { - *pDest++ = (((*pSrc)>>6)&3); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>4)&3); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>2)&3); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc) )&3); - if (iX-- <= 0) - break; - pSrc++; - } - } - else if (pData->iPNGdepth == 4) - { - /* Inflate Workrow to 8-bit */ - mng_int32 iX; - mng_uint8p pSrc = pData->pWorkrow+1; - mng_uint8p pDest = pSrc + pData->iRowsize - (4*pData->iRowsize+7)/8; - - for (iX = ((4*pData->iRowsize+7)/8) ; iX > 0 ; iX--) - *pDest++ = *pSrc++; - - pDest = pData->pWorkrow+1; - pSrc = pDest + pData->iRowsize - (4*pData->iRowsize+7)/8; - for (iX = pData->iRowsize; ;) - { - *pDest++ = (((*pSrc)>>4)&0x0f); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc) )&0x0f); - if (iX-- <= 0) - break; - pSrc++; - } - } - if (pData->iPNGdepth < 8 && pData->iColortype == 0) - { - /* Expand samples to 8-bit by LBR */ - mng_int32 iX; - mng_uint8p pSrc = pData->pWorkrow+1; - mng_uint8 multiplier[]={0,255,85,0,17,0,0,0,1}; - - for (iX = pData->iRowsize; iX > 0; iX--) - *pSrc++ *= multiplier[pData->iPNGdepth]; - } -#endif -#ifdef MNG_NO_16BIT_SUPPORT - if (pData->iPNGdepth > 8) - { - /* Reduce Workrow to 8-bit */ - mng_int32 iX; - mng_uint8p pSrc = pData->pWorkrow+1; - mng_uint8p pDest = pSrc; - - for (iX = pData->iRowsize; iX > 0; iX--) - { - *pDest = *pSrc; - pDest++; - pSrc+=2; - } - } -#endif - -#ifdef FILTER192 /* has leveling info ? */ - if (pData->iFilterofs == MNG_FILTER_DIFFERING) - iRetcode = init_rowdiffering (pData); - else -#endif - iRetcode = MNG_NOERROR; - /* filter the row if necessary */ - if ((!iRetcode) && (pData->iFilterofs < pData->iPixelofs ) && - (*(pData->pWorkrow + pData->iFilterofs)) ) - iRetcode = mng_filter_a_row (pData); - - /* additional leveling/differing ? */ - if ((!iRetcode) && (pData->fDifferrow)) - { - iRetcode = ((mng_differrow)pData->fDifferrow) (pData); - - pSwap = pData->pWorkrow; - pData->pWorkrow = pData->pPrevrow; - pData->pPrevrow = pSwap; /* make sure we're processing the right data */ - } - - if (!iRetcode) - { - { /* process this row */ - if ((!iRetcode) && (pData->fProcessrow)) - iRetcode = ((mng_processrow)pData->fProcessrow) (pData); - /* store in object ? */ - if ((!iRetcode) && (pData->fStorerow)) - iRetcode = ((mng_storerow)pData->fStorerow) (pData); - } - } - - if (iRetcode) /* on error bail out */ - { - MNG_FREEX (pData, pBuf, iBufsize); - MNG_ERROR (pData, iRetcode); - } - - if (!pData->fDifferrow) /* swap row-pointers */ - { - pSwap = pData->pWorkrow; - pData->pWorkrow = pData->pPrevrow; - pData->pPrevrow = pSwap; /* so prev points to the processed row! */ - } - /* adjust variables for next row */ - iRetcode = mng_next_row (pData); - - if (iRetcode) /* on error bail out */ - { - MNG_FREEX (pData, pBuf, iBufsize); - MNG_ERROR (pData, iRetcode); - } - } - } - - pTemp += pData->iRowmax; - iTemplen -= pData->iRowmax; - } /* until some error or EOI - or all pixels received */ - while ( (iTemplen > 0) && - ( (pData->iRow < (mng_int32)pData->iDataheight) || - ( (pData->iPass >= 0) && (pData->iPass < 7) ) ) ); - - mng_cleanup_rowproc (pData); /* cleanup row processing buffers !! */ - - /* restore saved work-parms */ - pData->iDatawidth = iSavedatawidth; - pData->iDataheight = iSavedataheight; - - pData->fInitrowproc = fSaveinitrowproc; - pData->fDisplayrow = fSavestorerow; - pData->fProcessrow = fSaveprocessrow; - pData->fDifferrow = fSavedifferrow; - pData->pStoreobj = fSavestoreobj; - pData->pStorebuf = fSavestorebuf; - -#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT - pData->ePng_imgtype = eSavepngimgtype; -#endif - - pData->iInterlace = iSaveinterlace; - pData->iPass = iSavepass; - pData->iRow = iSaverow; - pData->iRowinc = iSaverowinc; - pData->iCol = iSavecol; - pData->iColinc = iSavecolinc; - pData->iRowsamples = iSaverowsamples; - pData->iSamplemul = iSavesamplemul; - pData->iSampleofs = iSavesampleofs; - pData->iSamplediv = iSavesamplediv; - pData->iRowsize = iSaverowsize; - pData->iRowmax = iSaverowmax; - pData->iFilterofs = iSavefilterofs; - pData->iPixelofs = iSavepixelofs; - pData->iLevel0 = iSavelevel0; - pData->iLevel1 = iSavelevel1; - pData->iLevel2 = iSavelevel2; - pData->iLevel3 = iSavelevel3; - pData->pWorkrow = pSaveworkrow; - pData->pPrevrow = pSaveprevrow; - pData->pRGBArow = pSaverGBArow; - pData->bIsRGBA16 = bSaveisRGBA16; - pData->bIsOpaque = bSaveisOpaque; - pData->iFilterbpp = iSavefilterbpp; - pData->iDestl = iSavedestl; - pData->iDestt = iSavedestt; - pData->iDestr = iSavedestr; - pData->iDestb = iSavedestb; - pData->iSourcel = iSavesourcel; - pData->iSourcet = iSavesourcet; - pData->iSourcer = iSavesourcer; - pData->iSourceb = iSavesourceb; - - /* create the animation directives ! */ - pProcess = (mng_processobject)pANG->sHeader.fProcess; - iRetcode = pProcess (pData, (mng_objectp)pData->pANG); - if (iRetcode) - return iRetcode; - -#endif /* MNG_SUPPORT_DISPLAY */ - - MNG_FREE (pData, pBuf, iBufsize); /* always free the temp buffer ! */ - } - - *piRawlen = 0; - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ANG_PROPOSAL -MNG_C_SPECIALFUNC (mng_special_adat) -{ - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -MNG_C_SPECIALFUNC (mng_special_unknown) -{ - /* critical chunk ? */ - if ((((mng_uint32)pData->iChunkname & 0x20000000) == 0) -#ifdef MNG_SKIPCHUNK_SAVE - && (pData->iChunkname != MNG_UINT_SAVE) -#endif -#ifdef MNG_SKIPCHUNK_SEEK - && (pData->iChunkname != MNG_UINT_SEEK) -#endif -#ifdef MNG_SKIPCHUNK_DBYK - && (pData->iChunkname != MNG_UINT_DBYK) -#endif -#ifdef MNG_SKIPCHUNK_ORDR - && (pData->iChunkname != MNG_UINT_ORDR) -#endif - ) - MNG_ERROR (pData, MNG_UNKNOWNCRITICAL); - - if (pData->fProcessunknown) /* let the app handle it ? */ - { - mng_bool bOke = pData->fProcessunknown ((mng_handle)pData, pData->iChunkname, - ((mng_unknown_chunkp)pChunk)->iDatasize, - ((mng_unknown_chunkp)pChunk)->pData); - if (!bOke) - MNG_ERROR (pData, MNG_APPMISCERROR); - } - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_READ_PROCS || MNG_INCLUDE_WRITE_PROCS */ -#endif /* MNG_OPTIMIZE_CHUNKREADER */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - - - - - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_chunk_descr.c copyright (c) 2005-2007 G.Juyn * */ +/* * version : 1.0.10 * */ +/* * * */ +/* * purpose : Chunk descriptor functions (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the chunk- anf field-descriptor * */ +/* * routines * */ +/* * * */ +/* * changes : 1.0.9 - 12/06/2004 - G.Juyn * */ +/* * - added conditional MNG_OPTIMIZE_CHUNKREADER * */ +/* * 1.0.9 - 12/11/2004 - G.Juyn * */ +/* * - made all constants 'static' * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * 1.0.9 - 01/17/2005 - G.Juyn * */ +/* * - fixed problem with global PLTE/tRNS * */ +/* * * */ +/* * 1.0.10 - 01/17/2005 - G.R-P. * */ +/* * - added typecast to appease the compiler * */ +/* * 1.0.10 - 04/08/2007 - G.Juyn * */ +/* * - added support for mPNG proposal * */ +/* * 1.0.10 - 04/12/2007 - G.Juyn * */ +/* * - added support for ANG proposal * */ +/* * * */ +/* ************************************************************************** */ + +#include /* needed for offsetof() */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_memory.h" +#include "libmng_objects.h" +#include "libmng_chunks.h" +#include "libmng_chunk_descr.h" +#include "libmng_object_prc.h" +#include "libmng_chunk_prc.h" +#include "libmng_chunk_io.h" +#include "libmng_display.h" + +#ifdef MNG_INCLUDE_ANG_PROPOSAL +#include "libmng_pixels.h" +#include "libmng_filter.h" +#endif + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ + +#ifdef MNG_OPTIMIZE_CHUNKREADER +#if defined(MNG_INCLUDE_READ_PROCS) || defined(MNG_INCLUDE_WRITE_PROCS) + +/* ************************************************************************** */ +/* ************************************************************************** */ +/* PNG chunks */ + +MNG_LOCAL mng_field_descriptor mng_fields_ihdr [] = + { + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_NOHIGHBIT, + 1, 0, 4, 4, + offsetof(mng_ihdr, iWidth), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_NOHIGHBIT, + 1, 0, 4, 4, + offsetof(mng_ihdr, iHeight), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 1, 16, 1, 1, + offsetof(mng_ihdr, iBitdepth), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 6, 1, 1, + offsetof(mng_ihdr, iColortype), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 1, 1, + offsetof(mng_ihdr, iCompression), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 1, 1, + offsetof(mng_ihdr, iFilter), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 1, 1, 1, + offsetof(mng_ihdr, iInterlace), MNG_NULL, MNG_NULL} + }; + +/* ************************************************************************** */ + +MNG_LOCAL mng_field_descriptor mng_fields_plte [] = + { + {mng_debunk_plte, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; + +/* ************************************************************************** */ + +MNG_LOCAL mng_field_descriptor mng_fields_idat [] = + { + {MNG_NULL, + MNG_NULL, + 0, 0, 0, 0, + offsetof(mng_idat, pData), MNG_NULL, offsetof(mng_idat, iDatasize)} + }; + +/* ************************************************************************** */ + +MNG_LOCAL mng_field_descriptor mng_fields_trns [] = + { + {mng_debunk_trns, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_gAMA +MNG_LOCAL mng_field_descriptor mng_fields_gama [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_gama, iGamma), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_cHRM +MNG_LOCAL mng_field_descriptor mng_fields_chrm [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_chrm, iWhitepointx), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_chrm, iWhitepointy), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_chrm, iRedx), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_chrm, iRedy), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_chrm, iGreeny), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_chrm, iGreeny), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_chrm, iBluex), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_chrm, iBluey), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sRGB +MNG_LOCAL mng_field_descriptor mng_fields_srgb [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 4, 1, 1, + offsetof(mng_srgb, iRenderingintent), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iCCP +MNG_LOCAL mng_field_descriptor mng_fields_iccp [] = + { + {MNG_NULL, + MNG_FIELD_TERMINATOR, + 0, 0, 1, 79, + offsetof(mng_iccp, zName), MNG_NULL, offsetof(mng_iccp, iNamesize)}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 1, 1, + offsetof(mng_iccp, iCompression), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_DEFLATED, + 0, 0, 0, 0, + offsetof(mng_iccp, pProfile), MNG_NULL, offsetof(mng_iccp, iProfilesize)} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_tEXt +MNG_LOCAL mng_field_descriptor mng_fields_text [] = + { + {MNG_NULL, + MNG_FIELD_TERMINATOR, + 0, 0, 1, 79, + offsetof(mng_text, zKeyword), MNG_NULL, offsetof(mng_text, iKeywordsize)}, + {MNG_NULL, + MNG_NULL, + 0, 0, 0, 0, + offsetof(mng_text, zText), MNG_NULL, offsetof(mng_text, iTextsize)} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_zTXt +MNG_LOCAL mng_field_descriptor mng_fields_ztxt [] = + { + {MNG_NULL, + MNG_FIELD_TERMINATOR, + 0, 0, 1, 79, + offsetof(mng_ztxt, zKeyword), MNG_NULL, offsetof(mng_ztxt, iKeywordsize)}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 1, 1, + offsetof(mng_ztxt, iCompression), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_DEFLATED, + 0, 0, 0, 0, + offsetof(mng_ztxt, zText), MNG_NULL, offsetof(mng_ztxt, iTextsize)} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iTXt +MNG_LOCAL mng_field_descriptor mng_fields_itxt [] = + { + {MNG_NULL, + MNG_FIELD_TERMINATOR, + 0, 0, 1, 79, + offsetof(mng_itxt, zKeyword), MNG_NULL, offsetof(mng_itxt, iKeywordsize)}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 1, 1, 1, + offsetof(mng_itxt, iCompressionflag), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 1, 1, + offsetof(mng_itxt, iCompressionmethod), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_TERMINATOR, + 0, 0, 0, 0, + offsetof(mng_itxt, zLanguage), MNG_NULL, offsetof(mng_itxt, iLanguagesize)}, + {MNG_NULL, + MNG_FIELD_TERMINATOR, + 0, 0, 0, 0, + offsetof(mng_itxt, zTranslation), MNG_NULL, offsetof(mng_itxt, iTranslationsize)}, + {mng_deflate_itxt, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_bKGD +MNG_LOCAL mng_field_descriptor mng_fields_bkgd [] = + { + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_PUTIMGTYPE, + 0, 0, 0, 0, + offsetof(mng_bkgd, iType), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE3, + 0, 0xFF, 1, 1, + offsetof(mng_bkgd, iIndex), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE0 | MNG_FIELD_IFIMGTYPE4, + 0, 0xFFFF, 2, 2, + offsetof(mng_bkgd, iGray), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE2 | MNG_FIELD_IFIMGTYPE6, + 0, 0xFFFF, 2, 2, + offsetof(mng_bkgd, iRed), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE2 | MNG_FIELD_IFIMGTYPE6, + 0, 0xFFFF, 2, 2, + offsetof(mng_bkgd, iGreen), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE2 | MNG_FIELD_IFIMGTYPE6, + 0, 0xFFFF, 2, 2, + offsetof(mng_bkgd, iBlue), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_pHYs +MNG_LOCAL mng_field_descriptor mng_fields_phys [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_phys, iSizex), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_phys, iSizey), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 1, 1, 1, + offsetof(mng_phys, iUnit), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sBIT +MNG_LOCAL mng_field_descriptor mng_fields_sbit [] = + { + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_PUTIMGTYPE, + 0, 0, 0, 0, + offsetof(mng_sbit, iType), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_IFIMGTYPES, + 0, 0xFF, 1, 1, + offsetof(mng_sbit, aBits[0]), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE2 | MNG_FIELD_IFIMGTYPE3 | MNG_FIELD_IFIMGTYPE4 | MNG_FIELD_IFIMGTYPE6, + 0, 0xFF, 1, 1, + offsetof(mng_sbit, aBits[1]), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE2 | MNG_FIELD_IFIMGTYPE3 | MNG_FIELD_IFIMGTYPE6, + 0, 0xFF, 1, 1, + offsetof(mng_sbit, aBits[2]), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_IFIMGTYPE6, + 0, 0xFF, 1, 1, + offsetof(mng_sbit, aBits[3]), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sPLT +MNG_LOCAL mng_field_descriptor mng_fields_splt [] = + { + {MNG_NULL, + MNG_NULL, + 0, 0, 1, 79, + offsetof(mng_splt, zName), MNG_NULL, offsetof(mng_splt, iNamesize)}, + {MNG_NULL, + MNG_FIELD_INT, + 8, 16, 1, 1, + offsetof(mng_splt, iSampledepth), MNG_NULL, MNG_NULL}, + {mng_splt_entries, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_hIST +MNG_LOCAL mng_field_descriptor mng_fields_hist [] = + { + {mng_hist_entries, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_tIME +MNG_LOCAL mng_field_descriptor mng_fields_time [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFFFF, 2, 2, + offsetof(mng_time, iYear), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 1, 12, 1, 1, + offsetof(mng_time, iMonth), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 1, 31, 1, 1, + offsetof(mng_time, iDay), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 24, 1, 1, + offsetof(mng_time, iHour), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 60, 1, 1, + offsetof(mng_time, iMinute), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 60, 1, 1, + offsetof(mng_time, iSecond), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ +/* ************************************************************************** */ +/* JNG chunks */ + +#ifdef MNG_INCLUDE_JNG +MNG_LOCAL mng_field_descriptor mng_fields_jhdr [] = + { + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_NOHIGHBIT, + 1, 0, 4, 4, + offsetof(mng_jhdr, iWidth), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_NOHIGHBIT, + 1, 0, 4, 4, + offsetof(mng_jhdr, iHeight), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 8, 16, 1, 1, + offsetof(mng_jhdr, iColortype), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 8, 20, 1, 1, + offsetof(mng_jhdr, iImagesampledepth), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 8, 8, 1, 1, + offsetof(mng_jhdr, iImagecompression), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 8, 1, 1, + offsetof(mng_jhdr, iImageinterlace), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 16, 1, 1, + offsetof(mng_jhdr, iAlphasampledepth), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 8, 1, 1, + offsetof(mng_jhdr, iAlphacompression), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 1, 1, + offsetof(mng_jhdr, iAlphafilter), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 1, 1, 1, + offsetof(mng_jhdr, iAlphainterlace), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#define mng_fields_jdaa mng_fields_idat +#define mng_fields_jdat mng_fields_idat +#endif + +/* ************************************************************************** */ +/* ************************************************************************** */ +/* MNG chunks */ + +MNG_LOCAL mng_field_descriptor mng_fields_mhdr [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_mhdr, iWidth), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_mhdr, iHeight), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_mhdr, iTicks), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_mhdr, iLayercount), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_mhdr, iFramecount), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_mhdr, iPlaytime), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_mhdr, iSimplicity), MNG_NULL, MNG_NULL} + }; + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_LOOP +MNG_LOCAL mng_field_descriptor mng_fields_loop [] = + { + {mng_debunk_loop, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_LOOP +MNG_LOCAL mng_field_descriptor mng_fields_endl [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFF, 1, 1, + offsetof(mng_endl, iLevel), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DEFI +MNG_LOCAL mng_field_descriptor mng_fields_defi [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFFFF, 2, 2, + offsetof(mng_defi, iObjectid), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL, + 0, 0xFF, 1, 1, + offsetof(mng_defi, iDonotshow), offsetof(mng_defi, bHasdonotshow), MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL, + 0, 0xFF, 1, 1, + offsetof(mng_defi, iConcrete), offsetof(mng_defi, bHasconcrete), MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, + 0, 0, 4, 4, + offsetof(mng_defi, iXlocation), offsetof(mng_defi, bHasloca), MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, + 0, 0, 4, 4, + offsetof(mng_defi, iYlocation), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP2, + 0, 0, 4, 4, + offsetof(mng_defi, iLeftcb), offsetof(mng_defi, bHasclip), MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP2, + 0, 0, 4, 4, + offsetof(mng_defi, iRightcb), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP2, + 0, 0, 4, 4, + offsetof(mng_defi, iTopcb), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP2, + 0, 0, 4, 4, + offsetof(mng_defi, iBottomcb), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_BASI +MNG_LOCAL mng_field_descriptor mng_fields_basi [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_basi, iWidth), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_basi, iHeight), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 1, 16, 1, 1, + offsetof(mng_basi, iBitdepth), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 6, 1, 1, + offsetof(mng_basi, iColortype), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 1, 1, + offsetof(mng_basi, iCompression), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 1, 1, + offsetof(mng_basi, iFilter), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 1, 1, 1, + offsetof(mng_basi, iInterlace), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, + 0, 0xFFFF, 2, 2, + offsetof(mng_basi, iRed), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, + 0, 0xFFFF, 2, 2, + offsetof(mng_basi, iGreen), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, + 0, 0xFFFF, 2, 2, + offsetof(mng_basi, iBlue), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL, + 0, 0xFFFF, 2, 2, + offsetof(mng_basi, iAlpha), offsetof(mng_basi, bHasalpha), MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL, + 0, 1, 1, 1, + offsetof(mng_basi, iViewable), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_CLON +MNG_LOCAL mng_field_descriptor mng_fields_clon [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFFFF, 2, 2, + offsetof(mng_clon, iSourceid), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFFFF, 2, 2, + offsetof(mng_clon, iCloneid), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL, + 0, 2, 1, 1, + offsetof(mng_clon, iClonetype), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL, + 0, 1, 1, 1, + offsetof(mng_clon, iDonotshow), offsetof(mng_clon, bHasdonotshow), MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL, + 0, 1, 1, 1, + offsetof(mng_clon, iConcrete), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, + 0, 2, 1, 1, + offsetof(mng_clon, iLocationtype), offsetof(mng_clon, bHasloca), MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, + 0, 0, 4, 4, + offsetof(mng_clon, iLocationx), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, + 0, 0, 4, 4, + offsetof(mng_clon, iLocationy), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +MNG_LOCAL mng_field_descriptor mng_fields_past [] = + { + {mng_debunk_past, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DISC +MNG_LOCAL mng_field_descriptor mng_fields_disc [] = + { + {mng_disc_entries, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_BACK +MNG_LOCAL mng_field_descriptor mng_fields_back [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFFFF, 2, 2, + offsetof(mng_back, iRed), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFFFF, 2, 2, + offsetof(mng_back, iGreen), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFFFF, 2, 2, + offsetof(mng_back, iBlue), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL, + 0, 3, 1, 1, + offsetof(mng_back, iMandatory), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL, + 0, 0xFFFF, 2, 2, + offsetof(mng_back, iImageid), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL, + 0, 1, 1, 1, + offsetof(mng_back, iTile), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_FRAM +MNG_LOCAL mng_field_descriptor mng_fields_fram [] = + { + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL, + 0, 4, 1, 1, + offsetof(mng_fram, iMode), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_TERMINATOR | MNG_FIELD_OPTIONAL, + 0, 0, 1, 79, + offsetof(mng_fram, zName), MNG_NULL, offsetof(mng_fram, iNamesize)}, + {mng_fram_remainder, + MNG_FIELD_OPTIONAL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MOVE +MNG_LOCAL mng_field_descriptor mng_fields_move [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFFFF, 2, 2, + offsetof(mng_move, iFirstid), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFFFF, 2, 2, + offsetof(mng_move, iLastid), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 1, 1, 1, + offsetof(mng_move, iMovetype), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_move, iMovex), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_move, iMovey), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_CLIP +MNG_LOCAL mng_field_descriptor mng_fields_clip [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFFFF, 2, 2, + offsetof(mng_clip, iFirstid), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFFFF, 2, 2, + offsetof(mng_clip, iLastid), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 1, 1, 1, + offsetof(mng_clip, iCliptype), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_clip, iClipl), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_clip, iClipr), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_clip, iClipt), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_clip, iClipb), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SHOW +MNG_LOCAL mng_field_descriptor mng_fields_show [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 1, 0xFFFF, 2, 2, + offsetof(mng_show, iFirstid), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL, + 1, 0xFFFF, 2, 2, + offsetof(mng_show, iLastid), offsetof(mng_show, bHaslastid), MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL, + 0, 7, 1, 1, + offsetof(mng_show, iMode), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_TERM +MNG_LOCAL mng_field_descriptor mng_fields_term [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 3, 1, 1, + offsetof(mng_term, iTermaction), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, + 0, 2, 1, 1, + offsetof(mng_term, iIteraction), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, + 0, 0, 4, 4, + offsetof(mng_term, iDelay), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, + 0, 0, 4, 4, + offsetof(mng_term, iItermax), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SAVE +MNG_LOCAL mng_field_descriptor mng_fields_save [] = + { + {mng_save_entries, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SEEK +MNG_LOCAL mng_field_descriptor mng_fields_seek [] = + { + {MNG_NULL, + MNG_NULL, + 0, 0, 1, 79, + offsetof(mng_seek, zName), MNG_NULL, offsetof(mng_seek, iNamesize)} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_eXPI +MNG_LOCAL mng_field_descriptor mng_fields_expi [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFFFF, 2, 2, + offsetof(mng_expi, iSnapshotid), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_NULL, + 0, 0, 1, 79, + offsetof(mng_expi, zName), MNG_NULL, offsetof(mng_expi, iNamesize)} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_fPRI +MNG_LOCAL mng_field_descriptor mng_fields_fpri [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 1, 1, 1, + offsetof(mng_fpri, iDeltatype), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFF, 1, 1, + offsetof(mng_fpri, iPriority), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_nEED +MNG_LOCAL mng_field_descriptor mng_fields_need [] = + { + {MNG_NULL, + MNG_NULL, + 0, 0, 1, 0, + offsetof(mng_need, zKeywords), MNG_NULL, offsetof(mng_need, iKeywordssize)} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_pHYg +#define mng_fields_phyg mng_fields_phys +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +MNG_LOCAL mng_field_descriptor mng_fields_dhdr [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFFFF, 2, 2, + offsetof(mng_dhdr, iObjectid), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 2, 1, 1, + offsetof(mng_dhdr, iImagetype), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 7, 1, 1, + offsetof(mng_dhdr, iDeltatype), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, + 0, 0, 4, 4, + offsetof(mng_dhdr, iBlockwidth), offsetof(mng_dhdr, bHasblocksize), MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP1, + 0, 0, 4, 4, + offsetof(mng_dhdr, iBlockheight), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP2, + 0, 0, 4, 4, + offsetof(mng_dhdr, iBlockx), offsetof(mng_dhdr, bHasblockloc), MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT | MNG_FIELD_OPTIONAL | MNG_FIELD_GROUP2, + 0, 0, 4, 4, + offsetof(mng_dhdr, iBlocky), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +MNG_LOCAL mng_field_descriptor mng_fields_prom [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 14, 1, 1, + offsetof(mng_prom, iColortype), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 16, 1, 1, + offsetof(mng_prom, iSampledepth), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 1, 1, 1, + offsetof(mng_prom, iFilltype), MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +MNG_LOCAL mng_field_descriptor mng_fields_pplt [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 5, 1, 1, + offsetof(mng_pplt, iDeltatype), MNG_NULL, MNG_NULL}, + {mng_pplt_entries, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +MNG_LOCAL mng_field_descriptor mng_fields_drop [] = + { + {mng_drop_entries, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DBYK +MNG_LOCAL mng_field_descriptor mng_fields_dbyk [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_dbyk, iChunkname), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 1, 1, 1, + offsetof(mng_dbyk, iPolarity), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_NULL, + 0, 0, 1, 0, + offsetof(mng_dbyk, zKeywords), MNG_NULL, offsetof(mng_dbyk, iKeywordssize)} + }; +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR +MNG_LOCAL mng_field_descriptor mng_fields_ordr [] = + { + {mng_drop_entries, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MAGN +MNG_LOCAL mng_field_descriptor mng_fields_magn [] = + { + {mng_debunk_magn, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_MPNG_PROPOSAL +MNG_LOCAL mng_field_descriptor mng_fields_mpng [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 1, 0, 4, 4, + offsetof(mng_mpng, iFramewidth), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 1, 0, 4, 4, + offsetof(mng_mpng, iFrameheight), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0xFFFF, 2, 2, + offsetof(mng_mpng, iNumplays), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 1, 0xFFFF, 2, 2, + offsetof(mng_mpng, iTickspersec), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 1, 1, + offsetof(mng_mpng, iCompressionmethod), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_DEFLATED, + 0, 0, 1, 0, + offsetof(mng_mpng, pFrames), MNG_NULL, offsetof(mng_mpng, iFramessize)} + }; +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ANG_PROPOSAL +MNG_LOCAL mng_field_descriptor mng_fields_ahdr [] = + { + {MNG_NULL, + MNG_FIELD_INT, + 1, 0, 4, 4, + offsetof(mng_ahdr, iNumframes), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_ahdr, iTickspersec), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 0, 4, 4, + offsetof(mng_ahdr, iNumplays), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 1, 0, 4, 4, + offsetof(mng_ahdr, iTilewidth), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 1, 0, 4, 4, + offsetof(mng_ahdr, iTileheight), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 1, 1, 1, + offsetof(mng_ahdr, iInterlace), MNG_NULL, MNG_NULL}, + {MNG_NULL, + MNG_FIELD_INT, + 0, 1, 1, 1, + offsetof(mng_ahdr, iStillused), MNG_NULL, MNG_NULL} + }; + +MNG_LOCAL mng_field_descriptor mng_fields_adat [] = + { + {mng_adat_tiles, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_evNT +MNG_LOCAL mng_field_descriptor mng_fields_evnt [] = + { + {mng_evnt_entries, + MNG_NULL, + 0, 0, 0, 0, + MNG_NULL, MNG_NULL, MNG_NULL} + }; +#endif + +/* ************************************************************************** */ + +MNG_LOCAL mng_field_descriptor mng_fields_unknown [] = + { + {MNG_NULL, + MNG_NULL, + 0, 0, 1, 0, + offsetof(mng_unknown_chunk, pData), MNG_NULL, offsetof(mng_unknown_chunk, iDatasize)} + }; + +/* ************************************************************************** */ +/* ************************************************************************** */ +/* PNG chunks */ + +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ihdr = + {mng_it_png, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_ihdr, + mng_fields_ihdr, (sizeof(mng_fields_ihdr) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL, + MNG_NULL, + MNG_DESCR_NOIHDR | MNG_DESCR_NOJHDR | MNG_DESCR_NOBASI | MNG_DESCR_NOIDAT | MNG_DESCR_NOPLTE}; + +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_plte = + {mng_it_png, mng_create_none, 0, offsetof(mng_plte, bEmpty), + MNG_NULL, MNG_NULL, mng_special_plte, + mng_fields_plte, (sizeof(mng_fields_plte) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED, + MNG_DESCR_GenHDR, + MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; + +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_idat = + {mng_it_png, mng_create_none, 0, offsetof(mng_idat, bEmpty), + MNG_NULL, MNG_NULL, mng_special_idat, + mng_fields_idat, (sizeof(mng_fields_idat) / sizeof(mng_field_descriptor)), + MNG_DESCR_EMPTYEMBED, + MNG_DESCR_GenHDR, + MNG_DESCR_NOJSEP}; + +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_iend = + {mng_it_png, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_iend, + MNG_NULL, 0, + MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, + MNG_DESCR_GenHDR, + MNG_NULL}; + +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_trns = + {mng_it_png, mng_create_none, 0, offsetof(mng_trns, bEmpty), + MNG_NULL, MNG_NULL, mng_special_trns, + mng_fields_trns, (sizeof(mng_fields_trns) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED, + MNG_DESCR_GenHDR, + MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; + +#ifndef MNG_SKIPCHUNK_gAMA +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_gama = + {mng_it_png, mng_create_none, 0, offsetof(mng_gama, bEmpty), + MNG_NULL, MNG_NULL, mng_special_gama, + mng_fields_gama, (sizeof(mng_fields_gama) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, + MNG_DESCR_GenHDR, + MNG_DESCR_NOPLTE | MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; +#endif + +#ifndef MNG_SKIPCHUNK_cHRM +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_chrm = + {mng_it_png, mng_create_none, 0, offsetof(mng_chrm, bEmpty), + MNG_NULL, MNG_NULL, mng_special_chrm, + mng_fields_chrm, (sizeof(mng_fields_chrm) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, + MNG_DESCR_GenHDR, + MNG_DESCR_NOPLTE | MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; +#endif + +#ifndef MNG_SKIPCHUNK_sRGB +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_srgb = + {mng_it_png, mng_create_none, 0, offsetof(mng_srgb, bEmpty), + MNG_NULL, MNG_NULL, mng_special_srgb, + mng_fields_srgb, (sizeof(mng_fields_srgb) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, + MNG_DESCR_GenHDR, + MNG_DESCR_NOPLTE | MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; +#endif + +#ifndef MNG_SKIPCHUNK_iCCP +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_iccp = + {mng_it_png, mng_create_none, 0, offsetof(mng_iccp, bEmpty), + MNG_NULL, MNG_NULL, mng_special_iccp, + mng_fields_iccp, (sizeof(mng_fields_iccp) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, + MNG_DESCR_GenHDR, + MNG_DESCR_NOPLTE | MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; +#endif + +#ifndef MNG_SKIPCHUNK_tEXt +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_text = + {mng_it_png, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_text, + mng_fields_text, (sizeof(mng_fields_text) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL, + MNG_DESCR_GenHDR, + MNG_NULL}; +#endif + +#ifndef MNG_SKIPCHUNK_zTXt +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ztxt = + {mng_it_png, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_ztxt, + mng_fields_ztxt, (sizeof(mng_fields_ztxt) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL, + MNG_DESCR_GenHDR, + MNG_NULL}; +#endif + +#ifndef MNG_SKIPCHUNK_iTXt +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_itxt = + {mng_it_png, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_itxt, + mng_fields_itxt, (sizeof(mng_fields_itxt) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL, + MNG_DESCR_GenHDR, + MNG_NULL}; +#endif + +#ifndef MNG_SKIPCHUNK_bKGD +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_bkgd = + {mng_it_png, mng_create_none, 0, offsetof(mng_bkgd, bEmpty), + MNG_NULL, MNG_NULL, mng_special_bkgd, + mng_fields_bkgd, (sizeof(mng_fields_bkgd) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, + MNG_DESCR_GenHDR, + MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; +#endif + +#ifndef MNG_SKIPCHUNK_pHYs +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_phys = + {mng_it_png, mng_create_none, 0, offsetof(mng_phys, bEmpty), + MNG_NULL, MNG_NULL, mng_special_phys, + mng_fields_phys, (sizeof(mng_fields_phys) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, + MNG_DESCR_GenHDR, + MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; +#endif + +#ifndef MNG_SKIPCHUNK_sBIT +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_sbit = + {mng_it_png, mng_create_none, 0, offsetof(mng_sbit, bEmpty), + MNG_NULL, MNG_NULL, mng_special_sbit, + mng_fields_sbit, (sizeof(mng_fields_sbit) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, + MNG_DESCR_GenHDR, + MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; +#endif + +#ifndef MNG_SKIPCHUNK_sPLT +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_splt = + {mng_it_png, mng_create_none, 0, offsetof(mng_splt, bEmpty), + MNG_NULL, MNG_NULL, mng_special_splt, + mng_fields_splt, (sizeof(mng_fields_splt) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL | MNG_DESCR_EMPTYEMBED | MNG_DESCR_EMPTYGLOBAL, + MNG_DESCR_GenHDR, + MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; +#endif + +#ifndef MNG_SKIPCHUNK_hIST +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_hist = + {mng_it_png, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_hist, + mng_fields_hist, (sizeof(mng_fields_hist) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_GenHDR | MNG_DESCR_PLTE, + MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT | MNG_DESCR_NOJDAA}; +#endif + +#ifndef MNG_SKIPCHUNK_tIME +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_time = + {mng_it_png, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_time, + mng_fields_time, (sizeof(mng_fields_time) / sizeof(mng_field_descriptor)), + MNG_DESCR_GLOBAL, + MNG_DESCR_GenHDR, + MNG_NULL}; +#endif + +/* ************************************************************************** */ +/* JNG chunks */ + +#ifdef MNG_INCLUDE_JNG +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_jhdr = + {mng_it_jng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_jhdr, + mng_fields_jhdr, (sizeof(mng_fields_jhdr) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_NULL, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifdef MNG_INCLUDE_JNG +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_jdaa = + {mng_it_jng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_jdaa, + mng_fields_jdaa, (sizeof(mng_fields_jdaa) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_JngHDR, + MNG_DESCR_NOJSEP}; +#endif + +#ifdef MNG_INCLUDE_JNG +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_jdat = + {mng_it_jng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_jdat, + mng_fields_jdat, (sizeof(mng_fields_jdat) / sizeof(mng_field_descriptor)), + MNG_DESCR_EMPTYEMBED, + MNG_DESCR_JngHDR, + MNG_NULL}; +#endif + +#ifdef MNG_INCLUDE_JNG +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_jsep = + {mng_it_jng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_jsep, + MNG_NULL, 0, + MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, + MNG_DESCR_JngHDR, + MNG_DESCR_NOJSEP}; +#endif + +/* ************************************************************************** */ +/* MNG chunks */ + +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_mhdr = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_mhdr, + mng_fields_mhdr, (sizeof(mng_fields_mhdr) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_NULL, + MNG_DESCR_NOMHDR | MNG_DESCR_NOIHDR | MNG_DESCR_NOJHDR}; + +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_mend = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_mend, + MNG_NULL, 0, + MNG_DESCR_EMPTY | MNG_DESCR_EMPTYGLOBAL, + MNG_DESCR_MHDR, + MNG_NULL}; + +#ifndef MNG_SKIPCHUNK_LOOP +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_loop = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_loop, + mng_fields_loop, (sizeof(mng_fields_loop) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; + +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_endl = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_endl, + mng_fields_endl, (sizeof(mng_fields_endl) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_DEFI +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_defi = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_defi, + mng_fields_defi, (sizeof(mng_fields_defi) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_BASI +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_basi = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_basi, + mng_fields_basi, (sizeof(mng_fields_basi) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_CLON +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_clon = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_clon, + mng_fields_clon, (sizeof(mng_fields_clon) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_PAST +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_past = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_past, + mng_fields_past, (sizeof(mng_fields_past) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_DISC +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_disc = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_disc, + mng_fields_disc, (sizeof(mng_fields_disc) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_BACK +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_back = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_back, + mng_fields_back, (sizeof(mng_fields_back) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_FRAM +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_fram = + {mng_it_mng, mng_create_none, 0, offsetof(mng_fram, bEmpty), + MNG_NULL, MNG_NULL, mng_special_fram, + mng_fields_fram, (sizeof(mng_fields_fram) / sizeof(mng_field_descriptor)), + MNG_DESCR_EMPTY | MNG_DESCR_EMPTYGLOBAL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_MOVE +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_move = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_move, + mng_fields_move, (sizeof(mng_fields_move) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_CLIP +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_clip = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_clip, + mng_fields_clip, (sizeof(mng_fields_clip) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_SHOW +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_show = + {mng_it_mng, mng_create_none, 0, offsetof(mng_show, bEmpty), + MNG_NULL, MNG_NULL, mng_special_show, + mng_fields_show, (sizeof(mng_fields_show) / sizeof(mng_field_descriptor)), + MNG_DESCR_EMPTY | MNG_DESCR_EMPTYGLOBAL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_TERM +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_term = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_term, + mng_fields_term, (sizeof(mng_fields_term) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR | MNG_DESCR_NOTERM | MNG_DESCR_NOLOOP}; +#endif + +#ifndef MNG_SKIPCHUNK_SAVE +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_save = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_save, + mng_fields_save, (sizeof(mng_fields_save) / sizeof(mng_field_descriptor)), + MNG_DESCR_EMPTY | MNG_DESCR_EMPTYGLOBAL, + MNG_DESCR_MHDR, + MNG_DESCR_NOSAVE | MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_SEEK +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_seek = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_seek, + mng_fields_seek, (sizeof(mng_fields_seek) / sizeof(mng_field_descriptor)), + MNG_DESCR_EMPTY | MNG_DESCR_EMPTYGLOBAL, + MNG_DESCR_MHDR | MNG_DESCR_SAVE, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_eXPI +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_expi = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_expi, + mng_fields_expi, (sizeof(mng_fields_expi) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_fPRI +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_fpri = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_fpri, + mng_fields_fpri, (sizeof(mng_fields_fpri) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_nEED +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_need = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_need, + mng_fields_need, (sizeof(mng_fields_need) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_pHYg +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_phyg = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_phyg, + mng_fields_phyg, (sizeof(mng_fields_phyg) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_NO_DELTA_PNG +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_dhdr = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_dhdr, + mng_fields_dhdr, (sizeof(mng_fields_dhdr) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_NO_DELTA_PNG +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_prom = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_prom, + mng_fields_prom, (sizeof(mng_fields_prom) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR | MNG_DESCR_DHDR, + MNG_NULL}; +#endif + +#ifndef MNG_NO_DELTA_PNG +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ipng = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_ipng, + MNG_NULL, 0, + MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, + MNG_DESCR_MHDR | MNG_DESCR_DHDR, + MNG_NULL}; +#endif + +#ifndef MNG_NO_DELTA_PNG +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_pplt = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_pplt, + mng_fields_pplt, (sizeof(mng_fields_pplt) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR | MNG_DESCR_DHDR, + MNG_NULL}; +#endif + +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ijng = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_ijng, + MNG_NULL, 0, + MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, + MNG_DESCR_MHDR | MNG_DESCR_DHDR, + MNG_NULL}; +#endif +#endif + +#ifndef MNG_NO_DELTA_PNG +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_drop = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_drop, + mng_fields_drop, (sizeof(mng_fields_drop) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR | MNG_DESCR_DHDR, + MNG_NULL}; +#endif + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DBYK +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_dbyk = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_dbyk, + mng_fields_dbyk, (sizeof(mng_fields_dbyk) / sizeof(mng_field_descriptor)), + MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, + MNG_DESCR_MHDR | MNG_DESCR_DHDR, + MNG_NULL}; +#endif +#endif + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ordr = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_ordr, + mng_fields_ordr, (sizeof(mng_fields_ordr) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR | MNG_DESCR_DHDR, + MNG_NULL}; +#endif +#endif + +#ifndef MNG_SKIPCHUNK_MAGN +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_magn = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_magn, + mng_fields_magn, (sizeof(mng_fields_magn) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOIHDR | MNG_DESCR_NOBASI | MNG_DESCR_NODHDR | MNG_DESCR_NOJHDR}; +#endif + +#ifndef MNG_SKIPCHUNK_evNT +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_evnt = + {mng_it_mng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_evnt, + mng_fields_evnt, (sizeof(mng_fields_evnt) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_MHDR, + MNG_DESCR_NOSAVE}; +#endif + +#ifdef MNG_INCLUDE_MPNG_PROPOSAL +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_mpng = + {mng_it_mpng, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_mpng, + mng_fields_mpng, (sizeof(mng_fields_mpng) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_NULL, + MNG_DESCR_NOMHDR | MNG_DESCR_NOIDAT | MNG_DESCR_NOJDAT}; +#endif + +#ifdef MNG_INCLUDE_ANG_PROPOSAL +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_ahdr = + {mng_it_ang, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_ahdr, + mng_fields_ahdr, (sizeof(mng_fields_ahdr) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_IHDR, + MNG_DESCR_NOMHDR | MNG_DESCR_NOJHDR | MNG_DESCR_NOIDAT}; + +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_adat = + {mng_it_ang, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_adat, + mng_fields_adat, (sizeof(mng_fields_adat) / sizeof(mng_field_descriptor)), + MNG_NULL, + MNG_DESCR_IHDR, + MNG_DESCR_NOMHDR | MNG_DESCR_NOJHDR}; +#endif + +/* ************************************************************************** */ +/* ************************************************************************** */ +/* the good ol' unknown babe */ + +MNG_LOCAL mng_chunk_descriptor mng_chunk_descr_unknown = + {mng_it_png, mng_create_none, 0, 0, + MNG_NULL, MNG_NULL, mng_special_unknown, + mng_fields_unknown, (sizeof(mng_fields_unknown) / sizeof(mng_field_descriptor)), + MNG_DESCR_EMPTY | MNG_DESCR_EMPTYEMBED, + MNG_NULL, + MNG_NULL}; + +/* ************************************************************************** */ +/* ************************************************************************** */ + +MNG_LOCAL mng_chunk_header mng_chunk_unknown = + {MNG_UINT_HUH, mng_init_general, mng_free_unknown, + mng_read_general, mng_write_unknown, mng_assign_unknown, + 0, 0, sizeof(mng_unknown_chunk), &mng_chunk_descr_unknown}; + +/* ************************************************************************** */ + + /* the table-idea & binary search code was adapted from + libpng 1.1.0 (pngread.c) */ + /* NOTE1: the table must remain sorted by chunkname, otherwise the binary + search will break !!! (ps. watch upper-/lower-case chunknames !!) */ + /* NOTE2: the layout must remain equal to the header part of all the + chunk-structures (yes, that means even the pNext and pPrev fields; + it's wasting a bit of space, but hey, the code is a lot easier) */ + +MNG_LOCAL mng_chunk_header mng_chunk_table [] = + { +#ifndef MNG_SKIPCHUNK_BACK + {MNG_UINT_BACK, mng_init_general, mng_free_general, mng_read_general, mng_write_back, mng_assign_general, 0, 0, sizeof(mng_back), &mng_chunk_descr_back}, +#endif +#ifndef MNG_SKIPCHUNK_BASI + {MNG_UINT_BASI, mng_init_general, mng_free_general, mng_read_general, mng_write_basi, mng_assign_general, 0, 0, sizeof(mng_basi), &mng_chunk_descr_basi}, +#endif +#ifndef MNG_SKIPCHUNK_CLIP + {MNG_UINT_CLIP, mng_init_general, mng_free_general, mng_read_general, mng_write_clip, mng_assign_general, 0, 0, sizeof(mng_clip), &mng_chunk_descr_clip}, +#endif +#ifndef MNG_SKIPCHUNK_CLON + {MNG_UINT_CLON, mng_init_general, mng_free_general, mng_read_general, mng_write_clon, mng_assign_general, 0, 0, sizeof(mng_clon), &mng_chunk_descr_clon}, +#endif +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DBYK + {MNG_UINT_DBYK, mng_init_general, mng_free_dbyk, mng_read_general, mng_write_dbyk, mng_assign_dbyk, 0, 0, sizeof(mng_dbyk), &mng_chunk_descr_dbyk}, +#endif +#endif +#ifndef MNG_SKIPCHUNK_DEFI + {MNG_UINT_DEFI, mng_init_general, mng_free_general, mng_read_general, mng_write_defi, mng_assign_general, 0, 0, sizeof(mng_defi), &mng_chunk_descr_defi}, +#endif +#ifndef MNG_NO_DELTA_PNG + {MNG_UINT_DHDR, mng_init_general, mng_free_general, mng_read_general, mng_write_dhdr, mng_assign_general, 0, 0, sizeof(mng_dhdr), &mng_chunk_descr_dhdr}, +#endif +#ifndef MNG_SKIPCHUNK_DISC + {MNG_UINT_DISC, mng_init_general, mng_free_disc, mng_read_general, mng_write_disc, mng_assign_disc, 0, 0, sizeof(mng_disc), &mng_chunk_descr_disc}, +#endif +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DROP + {MNG_UINT_DROP, mng_init_general, mng_free_drop, mng_read_general, mng_write_drop, mng_assign_drop, 0, 0, sizeof(mng_drop), &mng_chunk_descr_drop}, +#endif +#endif +#ifndef MNG_SKIPCHUNK_LOOP + {MNG_UINT_ENDL, mng_init_general, mng_free_general, mng_read_general, mng_write_endl, mng_assign_general, 0, 0, sizeof(mng_endl), &mng_chunk_descr_endl}, +#endif +#ifndef MNG_SKIPCHUNK_FRAM + {MNG_UINT_FRAM, mng_init_general, mng_free_fram, mng_read_general, mng_write_fram, mng_assign_fram, 0, 0, sizeof(mng_fram), &mng_chunk_descr_fram}, +#endif + {MNG_UINT_IDAT, mng_init_general, mng_free_idat, mng_read_general, mng_write_idat, mng_assign_idat, 0, 0, sizeof(mng_idat), &mng_chunk_descr_idat}, /* 12-th element! */ + {MNG_UINT_IEND, mng_init_general, mng_free_general, mng_read_general, mng_write_iend, mng_assign_general, 0, 0, sizeof(mng_iend), &mng_chunk_descr_iend}, + {MNG_UINT_IHDR, mng_init_general, mng_free_general, mng_read_general, mng_write_ihdr, mng_assign_general, 0, 0, sizeof(mng_ihdr), &mng_chunk_descr_ihdr}, +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG + {MNG_UINT_IJNG, mng_init_general, mng_free_general, mng_read_general, mng_write_ijng, mng_assign_general, 0, 0, sizeof(mng_ijng), &mng_chunk_descr_ijng}, +#endif + {MNG_UINT_IPNG, mng_init_general, mng_free_general, mng_read_general, mng_write_ipng, mng_assign_general, 0, 0, sizeof(mng_ipng), &mng_chunk_descr_ipng}, +#endif +#ifdef MNG_INCLUDE_JNG + {MNG_UINT_JDAA, mng_init_general, mng_free_jdaa, mng_read_general, mng_write_jdaa, mng_assign_jdaa, 0, 0, sizeof(mng_jdaa), &mng_chunk_descr_jdaa}, + {MNG_UINT_JDAT, mng_init_general, mng_free_jdat, mng_read_general, mng_write_jdat, mng_assign_jdat, 0, 0, sizeof(mng_jdat), &mng_chunk_descr_jdat}, + {MNG_UINT_JHDR, mng_init_general, mng_free_general, mng_read_general, mng_write_jhdr, mng_assign_general, 0, 0, sizeof(mng_jhdr), &mng_chunk_descr_jhdr}, + {MNG_UINT_JSEP, mng_init_general, mng_free_general, mng_read_general, mng_write_jsep, mng_assign_general, 0, 0, sizeof(mng_jsep), &mng_chunk_descr_jsep}, + {MNG_UINT_JdAA, mng_init_general, mng_free_jdaa, mng_read_general, mng_write_jdaa, mng_assign_jdaa, 0, 0, sizeof(mng_jdaa), &mng_chunk_descr_jdaa}, +#endif +#ifndef MNG_SKIPCHUNK_LOOP + {MNG_UINT_LOOP, mng_init_general, mng_free_loop, mng_read_general, mng_write_loop, mng_assign_loop, 0, 0, sizeof(mng_loop), &mng_chunk_descr_loop}, +#endif +#ifndef MNG_SKIPCHUNK_MAGN + {MNG_UINT_MAGN, mng_init_general, mng_free_general, mng_read_general, mng_write_magn, mng_assign_general, 0, 0, sizeof(mng_magn), &mng_chunk_descr_magn}, +#endif + {MNG_UINT_MEND, mng_init_general, mng_free_general, mng_read_general, mng_write_mend, mng_assign_general, 0, 0, sizeof(mng_mend), &mng_chunk_descr_mend}, + {MNG_UINT_MHDR, mng_init_general, mng_free_general, mng_read_general, mng_write_mhdr, mng_assign_general, 0, 0, sizeof(mng_mhdr), &mng_chunk_descr_mhdr}, +#ifndef MNG_SKIPCHUNK_MOVE + {MNG_UINT_MOVE, mng_init_general, mng_free_general, mng_read_general, mng_write_move, mng_assign_general, 0, 0, sizeof(mng_move), &mng_chunk_descr_move}, +#endif +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR + {MNG_UINT_ORDR, mng_init_general, mng_free_ordr, mng_read_general, mng_write_ordr, mng_assign_ordr, 0, 0, sizeof(mng_ordr), &mng_chunk_descr_ordr}, +#endif +#endif +#ifndef MNG_SKIPCHUNK_PAST + {MNG_UINT_PAST, mng_init_general, mng_free_past, mng_read_general, mng_write_past, mng_assign_past, 0, 0, sizeof(mng_past), &mng_chunk_descr_past}, +#endif + {MNG_UINT_PLTE, mng_init_general, mng_free_general, mng_read_general, mng_write_plte, mng_assign_general, 0, 0, sizeof(mng_plte), &mng_chunk_descr_plte}, +#ifndef MNG_NO_DELTA_PNG + {MNG_UINT_PPLT, mng_init_general, mng_free_general, mng_read_general, mng_write_pplt, mng_assign_general, 0, 0, sizeof(mng_pplt), &mng_chunk_descr_pplt}, + {MNG_UINT_PROM, mng_init_general, mng_free_general, mng_read_general, mng_write_prom, mng_assign_general, 0, 0, sizeof(mng_prom), &mng_chunk_descr_prom}, +#endif +#ifndef MNG_SKIPCHUNK_SAVE + {MNG_UINT_SAVE, mng_init_general, mng_free_save, mng_read_general, mng_write_save, mng_assign_save, 0, 0, sizeof(mng_save), &mng_chunk_descr_save}, +#endif +#ifndef MNG_SKIPCHUNK_SEEK + {MNG_UINT_SEEK, mng_init_general, mng_free_seek, mng_read_general, mng_write_seek, mng_assign_seek, 0, 0, sizeof(mng_seek), &mng_chunk_descr_seek}, +#endif +#ifndef MNG_SKIPCHUNK_SHOW + {MNG_UINT_SHOW, mng_init_general, mng_free_general, mng_read_general, mng_write_show, mng_assign_general, 0, 0, sizeof(mng_show), &mng_chunk_descr_show}, +#endif +#ifndef MNG_SKIPCHUNK_TERM + {MNG_UINT_TERM, mng_init_general, mng_free_general, mng_read_general, mng_write_term, mng_assign_general, 0, 0, sizeof(mng_term), &mng_chunk_descr_term}, +#endif +#ifdef MNG_INCLUDE_ANG_PROPOSAL + {MNG_UINT_adAT, mng_init_general, mng_free_adat, mng_read_general, mng_write_adat, mng_assign_adat, 0, 0, sizeof(mng_adat), &mng_chunk_descr_adat}, + {MNG_UINT_ahDR, mng_init_general, mng_free_general, mng_read_general, mng_write_ahdr, mng_assign_ahdr, 0, 0, sizeof(mng_ahdr), &mng_chunk_descr_ahdr}, +#endif +#ifndef MNG_SKIPCHUNK_bKGD + {MNG_UINT_bKGD, mng_init_general, mng_free_general, mng_read_general, mng_write_bkgd, mng_assign_general, 0, 0, sizeof(mng_bkgd), &mng_chunk_descr_bkgd}, +#endif +#ifndef MNG_SKIPCHUNK_cHRM + {MNG_UINT_cHRM, mng_init_general, mng_free_general, mng_read_general, mng_write_chrm, mng_assign_general, 0, 0, sizeof(mng_chrm), &mng_chunk_descr_chrm}, +#endif +#ifndef MNG_SKIPCHUNK_eXPI + {MNG_UINT_eXPI, mng_init_general, mng_free_expi, mng_read_general, mng_write_expi, mng_assign_expi, 0, 0, sizeof(mng_expi), &mng_chunk_descr_expi}, +#endif +#ifndef MNG_SKIPCHUNK_evNT + {MNG_UINT_evNT, mng_init_general, mng_free_evnt, mng_read_general, mng_write_evnt, mng_assign_evnt, 0, 0, sizeof(mng_evnt), &mng_chunk_descr_evnt}, +#endif +#ifndef MNG_SKIPCHUNK_fPRI + {MNG_UINT_fPRI, mng_init_general, mng_free_general, mng_read_general, mng_write_fpri, mng_assign_general, 0, 0, sizeof(mng_fpri), &mng_chunk_descr_fpri}, +#endif +#ifndef MNG_SKIPCHUNK_gAMA + {MNG_UINT_gAMA, mng_init_general, mng_free_general, mng_read_general, mng_write_gama, mng_assign_general, 0, 0, sizeof(mng_gama), &mng_chunk_descr_gama}, +#endif +#ifndef MNG_SKIPCHUNK_hIST + {MNG_UINT_hIST, mng_init_general, mng_free_general, mng_read_general, mng_write_hist, mng_assign_general, 0, 0, sizeof(mng_hist), &mng_chunk_descr_hist}, +#endif +#ifndef MNG_SKIPCHUNK_iCCP + {MNG_UINT_iCCP, mng_init_general, mng_free_iccp, mng_read_general, mng_write_iccp, mng_assign_iccp, 0, 0, sizeof(mng_iccp), &mng_chunk_descr_iccp}, +#endif +#ifndef MNG_SKIPCHUNK_iTXt + {MNG_UINT_iTXt, mng_init_general, mng_free_itxt, mng_read_general, mng_write_itxt, mng_assign_itxt, 0, 0, sizeof(mng_itxt), &mng_chunk_descr_itxt}, +#endif +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + {MNG_UINT_mpNG, mng_init_general, mng_free_mpng, mng_read_general, mng_write_mpng, mng_assign_mpng, 0, 0, sizeof(mng_mpng), &mng_chunk_descr_mpng}, +#endif +#ifndef MNG_SKIPCHUNK_nEED + {MNG_UINT_nEED, mng_init_general, mng_free_need, mng_read_general, mng_write_need, mng_assign_need, 0, 0, sizeof(mng_need), &mng_chunk_descr_need}, +#endif +/* TODO: {MNG_UINT_oFFs, 0, 0, 0, 0, 0, 0}, */ +/* TODO: {MNG_UINT_pCAL, 0, 0, 0, 0, 0, 0}, */ +#ifndef MNG_SKIPCHUNK_pHYg + {MNG_UINT_pHYg, mng_init_general, mng_free_general, mng_read_general, mng_write_phyg, mng_assign_general, 0, 0, sizeof(mng_phyg), &mng_chunk_descr_phyg}, +#endif +#ifndef MNG_SKIPCHUNK_pHYs + {MNG_UINT_pHYs, mng_init_general, mng_free_general, mng_read_general, mng_write_phys, mng_assign_general, 0, 0, sizeof(mng_phys), &mng_chunk_descr_phys}, +#endif +#ifndef MNG_SKIPCHUNK_sBIT + {MNG_UINT_sBIT, mng_init_general, mng_free_general, mng_read_general, mng_write_sbit, mng_assign_general, 0, 0, sizeof(mng_sbit), &mng_chunk_descr_sbit}, +#endif +/* TODO: {MNG_UINT_sCAL, 0, 0, 0, 0, 0, 0}, */ +#ifndef MNG_SKIPCHUNK_sPLT + {MNG_UINT_sPLT, mng_init_general, mng_free_splt, mng_read_general, mng_write_splt, mng_assign_splt, 0, 0, sizeof(mng_splt), &mng_chunk_descr_splt}, +#endif + {MNG_UINT_sRGB, mng_init_general, mng_free_general, mng_read_general, mng_write_srgb, mng_assign_general, 0, 0, sizeof(mng_srgb), &mng_chunk_descr_srgb}, +#ifndef MNG_SKIPCHUNK_tEXt + {MNG_UINT_tEXt, mng_init_general, mng_free_text, mng_read_general, mng_write_text, mng_assign_text, 0, 0, sizeof(mng_text), &mng_chunk_descr_text}, +#endif +#ifndef MNG_SKIPCHUNK_tIME + {MNG_UINT_tIME, mng_init_general, mng_free_general, mng_read_general, mng_write_time, mng_assign_general, 0, 0, sizeof(mng_time), &mng_chunk_descr_time}, +#endif + {MNG_UINT_tRNS, mng_init_general, mng_free_general, mng_read_general, mng_write_trns, mng_assign_general, 0, 0, sizeof(mng_trns), &mng_chunk_descr_trns}, +#ifndef MNG_SKIPCHUNK_zTXt + {MNG_UINT_zTXt, mng_init_general, mng_free_ztxt, mng_read_general, mng_write_ztxt, mng_assign_ztxt, 0, 0, sizeof(mng_ztxt), &mng_chunk_descr_ztxt}, +#endif + }; + +/* ************************************************************************** */ +/* ************************************************************************** */ + +void mng_get_chunkheader (mng_chunkid iChunkname, + mng_chunk_headerp pResult) +{ + /* binary search variables */ + mng_int32 iTop, iLower, iUpper, iMiddle; + mng_chunk_headerp pEntry; /* pointer to found entry */ + /* determine max index of table */ + iTop = (sizeof (mng_chunk_table) / sizeof (mng_chunk_table [0])) - 1; + + /* binary search; with 54 chunks, worst-case is 7 comparisons */ + iLower = 0; +#ifndef MNG_NO_DELTA_PNG + iMiddle = 11; /* start with the IDAT entry */ +#else + iMiddle = 8; +#endif + iUpper = iTop; + pEntry = 0; /* no goods yet! */ + + do /* the binary search itself */ + { + if (mng_chunk_table [iMiddle].iChunkname < iChunkname) + iLower = iMiddle + 1; + else if (mng_chunk_table [iMiddle].iChunkname > iChunkname) + iUpper = iMiddle - 1; + else + { + pEntry = &mng_chunk_table [iMiddle]; + break; + } + iMiddle = (iLower + iUpper) >> 1; + } + while (iLower <= iUpper); + + if (!pEntry) /* unknown chunk ? */ + pEntry = &mng_chunk_unknown; /* make it so! */ + + MNG_COPY (pResult, pEntry, sizeof(mng_chunk_header)); + + return; +} + +/* ************************************************************************** */ +/* ************************************************************************** */ +/* PNG chunks */ + +MNG_C_SPECIALFUNC (mng_special_ihdr) +{ + pData->bHasIHDR = MNG_TRUE; /* indicate IHDR is present */ + /* and store interesting fields */ + if ((!pData->bHasDHDR) || (pData->iDeltatype == MNG_DELTATYPE_NOCHANGE)) + { + pData->iDatawidth = ((mng_ihdrp)pChunk)->iWidth; + pData->iDataheight = ((mng_ihdrp)pChunk)->iHeight; + } + + pData->iBitdepth = ((mng_ihdrp)pChunk)->iBitdepth; + pData->iColortype = ((mng_ihdrp)pChunk)->iColortype; + pData->iCompression = ((mng_ihdrp)pChunk)->iCompression; + pData->iFilter = ((mng_ihdrp)pChunk)->iFilter; + pData->iInterlace = ((mng_ihdrp)pChunk)->iInterlace; + +#if defined(MNG_NO_1_2_4BIT_SUPPORT) || defined(MNG_NO_16BIT_SUPPORT) + pData->iPNGmult = 1; + pData->iPNGdepth = pData->iBitdepth; +#endif + +#ifdef MNG_NO_1_2_4BIT_SUPPORT + if (pData->iBitdepth < 8) + pData->iBitdepth = 8; +#endif + +#ifdef MNG_NO_16BIT_SUPPORT + if (pData->iBitdepth > 8) + { + pData->iBitdepth = 8; + pData->iPNGmult = 2; + } +#endif + + if ((pData->iBitdepth != 8) /* parameter validity checks */ +#ifndef MNG_NO_1_2_4BIT_SUPPORT + && (pData->iBitdepth != 1) && + (pData->iBitdepth != 2) && + (pData->iBitdepth != 4) +#endif +#ifndef MNG_NO_16BIT_SUPPORT + && (pData->iBitdepth != 16) +#endif + ) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if ((pData->iColortype != MNG_COLORTYPE_GRAY ) && + (pData->iColortype != MNG_COLORTYPE_RGB ) && + (pData->iColortype != MNG_COLORTYPE_INDEXED) && + (pData->iColortype != MNG_COLORTYPE_GRAYA ) && + (pData->iColortype != MNG_COLORTYPE_RGBA ) ) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + + if ((pData->iColortype == MNG_COLORTYPE_INDEXED) && (pData->iBitdepth > 8)) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if (((pData->iColortype == MNG_COLORTYPE_RGB ) || + (pData->iColortype == MNG_COLORTYPE_GRAYA ) || + (pData->iColortype == MNG_COLORTYPE_RGBA ) ) && + (pData->iBitdepth < 8 ) ) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if (pData->iCompression != MNG_COMPRESSION_DEFLATE) + MNG_ERROR (pData, MNG_INVALIDCOMPRESS); + +#if defined(FILTER192) || defined(FILTER193) + if ((pData->iFilter != MNG_FILTER_ADAPTIVE ) && +#if defined(FILTER192) && defined(FILTER193) + (pData->iFilter != MNG_FILTER_DIFFERING) && + (pData->iFilter != MNG_FILTER_NOFILTER ) ) +#else +#ifdef FILTER192 + (pData->iFilter != MNG_FILTER_DIFFERING) ) +#else + (pData->iFilter != MNG_FILTER_NOFILTER ) ) +#endif +#endif + MNG_ERROR (pData, MNG_INVALIDFILTER); +#else + if (pData->iFilter) + MNG_ERROR (pData, MNG_INVALIDFILTER); +#endif + + if ((pData->iInterlace != MNG_INTERLACE_NONE ) && + (pData->iInterlace != MNG_INTERLACE_ADAM7) ) + MNG_ERROR (pData, MNG_INVALIDINTERLACE); + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* check the colortype for delta-images ! */ + { + mng_imagedatap pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; + + if (pData->iColortype != pBuf->iColortype) + { + if ( ( (pData->iColortype != MNG_COLORTYPE_INDEXED) || + (pBuf->iColortype == MNG_COLORTYPE_GRAY ) ) && + ( (pData->iColortype != MNG_COLORTYPE_GRAY ) || + (pBuf->iColortype == MNG_COLORTYPE_INDEXED) ) ) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + } + } +#endif +#endif + + if (!pData->bHasheader) /* first chunk ? */ + { + pData->bHasheader = MNG_TRUE; /* we've got a header */ + pData->eImagetype = mng_it_png; /* then this must be a PNG */ + pData->iWidth = pData->iDatawidth; + pData->iHeight = pData->iDataheight; + /* predict alpha-depth ! */ + if ((pData->iColortype == MNG_COLORTYPE_GRAYA ) || + (pData->iColortype == MNG_COLORTYPE_RGBA ) ) + pData->iAlphadepth = pData->iBitdepth; + else + if (pData->iColortype == MNG_COLORTYPE_INDEXED) + pData->iAlphadepth = 8; /* worst case scenario */ + else + pData->iAlphadepth = 1; /* Possible tRNS cheap binary transparency */ + /* fits on maximum canvas ? */ + if ((pData->iWidth > pData->iMaxwidth) || (pData->iHeight > pData->iMaxheight)) + MNG_WARNING (pData, MNG_IMAGETOOLARGE); + +#if !defined(MNG_INCLUDE_MPNG_PROPOSAL) || !defined(MNG_SUPPORT_DISPLAY) + if (pData->fProcessheader) /* inform the app ? */ + if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) + MNG_ERROR (pData, MNG_APPMISCERROR); +#endif + } + + if (!pData->bHasDHDR) + pData->iImagelevel++; /* one level deeper */ + +#ifdef MNG_SUPPORT_DISPLAY + return mng_process_display_ihdr (pData); +#else + return MNG_NOERROR; +#endif /* MNG_SUPPORT_DISPLAY */ +} + +/* ************************************************************************** */ + +MNG_F_SPECIALFUNC (mng_debunk_plte) +{ + mng_pltep pPLTE = (mng_pltep)pChunk; + mng_uint32 iRawlen = *piRawlen; + mng_uint8p pRawdata = *ppRawdata; + /* length must be multiple of 3 */ + if (((iRawlen % 3) != 0) || (iRawlen > 768)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + /* this is the exact length */ + pPLTE->iEntrycount = iRawlen / 3; + + MNG_COPY (pPLTE->aEntries, pRawdata, iRawlen); + + *piRawlen = 0; + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_C_SPECIALFUNC (mng_special_plte) +{ /* multiple PLTE only inside BASI */ + if ((pData->bHasPLTE) && (!pData->bHasBASI)) + MNG_ERROR (pData, MNG_MULTIPLEERROR); + + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + { /* only allowed for indexed-color or + rgb(a)-color! */ + if ((pData->iColortype != MNG_COLORTYPE_RGB ) && + (pData->iColortype != MNG_COLORTYPE_INDEXED) && + (pData->iColortype != MNG_COLORTYPE_RGBA ) ) + MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); + /* empty only allowed if global present */ + if ((((mng_pltep)pChunk)->bEmpty) && (!pData->bHasglobalPLTE)) + MNG_ERROR (pData, MNG_CANNOTBEEMPTY); + } + else + { + if (((mng_pltep)pChunk)->bEmpty) /* cannot be empty as global! */ + MNG_ERROR (pData, MNG_CANNOTBEEMPTY); + } + + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + pData->bHasPLTE = MNG_TRUE; /* got it! */ + else + pData->bHasglobalPLTE = MNG_TRUE; + + pData->iPLTEcount = ((mng_pltep)pChunk)->iEntrycount; + +#ifdef MNG_SUPPORT_DISPLAY + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + { + mng_imagep pImage; + mng_imagedatap pBuf; + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* processing delta-image ? */ + { /* store in object 0 !!! */ + pImage = (mng_imagep)pData->pObjzero; + pBuf = pImage->pImgbuf; + pBuf->bHasPLTE = MNG_TRUE; /* it's definitely got a PLTE now */ + pBuf->iPLTEcount = ((mng_pltep)pChunk)->iEntrycount; + MNG_COPY (pBuf->aPLTEentries, ((mng_pltep)pChunk)->aEntries, + sizeof (pBuf->aPLTEentries)); + } + else +#endif + { /* get the current object */ + pImage = (mng_imagep)pData->pCurrentobj; + if (!pImage) /* no object then dump it in obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + + pBuf = pImage->pImgbuf; /* address the object buffer */ + pBuf->bHasPLTE = MNG_TRUE; /* and tell it it's got a PLTE now */ + + if (((mng_pltep)pChunk)->bEmpty) /* if empty, inherit from global */ + { + pBuf->iPLTEcount = pData->iGlobalPLTEcount; + MNG_COPY (pBuf->aPLTEentries, pData->aGlobalPLTEentries, + sizeof (pBuf->aPLTEentries)); + + if (pData->bHasglobalTRNS) /* also copy global tRNS ? */ + { + mng_uint32 iRawlen2 = pData->iGlobalTRNSrawlen; + mng_uint8p pRawdata2 = (mng_uint8p)(pData->aGlobalTRNSrawdata); + /* indicate tRNS available */ + pBuf->bHasTRNS = MNG_TRUE; + /* global length oke ? */ + if ((iRawlen2 == 0) || (iRawlen2 > pBuf->iPLTEcount)) + MNG_ERROR (pData, MNG_GLOBALLENGTHERR); + /* copy it */ + pBuf->iTRNScount = iRawlen2; + MNG_COPY (pBuf->aTRNSentries, pRawdata2, iRawlen2); + } + } + else + { /* store fields for future reference */ + pBuf->iPLTEcount = ((mng_pltep)pChunk)->iEntrycount; + MNG_COPY (pBuf->aPLTEentries, ((mng_pltep)pChunk)->aEntries, + sizeof (pBuf->aPLTEentries)); + } + } + } + else /* store as global */ + { + pData->iGlobalPLTEcount = ((mng_pltep)pChunk)->iEntrycount; + MNG_COPY (pData->aGlobalPLTEentries, ((mng_pltep)pChunk)->aEntries, + sizeof (pData->aGlobalPLTEentries)); + /* create an animation object */ + return mng_create_ani_plte (pData); + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +MNG_C_SPECIALFUNC (mng_special_idat) +{ +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasJHDR) && + (pData->iJHDRalphacompression != MNG_COMPRESSION_DEFLATE)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); +#endif + /* not allowed for deltatype NO_CHANGE */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && ((pData->iDeltatype == MNG_DELTATYPE_NOCHANGE))) + MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); +#endif + /* can only be empty in BASI-block! */ + if ((((mng_idatp)pChunk)->bEmpty) && (!pData->bHasBASI)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + /* indexed-color requires PLTE */ + if ((pData->bHasIHDR) && (pData->iColortype == 3) && (!pData->bHasPLTE)) + MNG_ERROR (pData, MNG_PLTEMISSING); + + pData->bHasIDAT = MNG_TRUE; /* got some IDAT now, don't we */ + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +MNG_C_SPECIALFUNC (mng_special_iend) +{ /* IHDR-block requires IDAT */ + if ((pData->bHasIHDR) && (!pData->bHasIDAT)) + MNG_ERROR (pData, MNG_IDATMISSING); + + pData->iImagelevel--; /* one level up */ + +#ifdef MNG_SUPPORT_DISPLAY + { /* create an animation object */ + mng_retcode iRetcode = mng_create_ani_image (pData); + if (iRetcode) /* on error bail out */ + return iRetcode; + /* display processing */ + iRetcode = mng_process_display_iend (pData); + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_SUPPORT_DISPLAY + if (!pData->bTimerset) /* reset only if not broken !!! */ + { +#endif + /* IEND signals the end for most ... */ + pData->bHasIHDR = MNG_FALSE; + pData->bHasBASI = MNG_FALSE; + pData->bHasDHDR = MNG_FALSE; +#ifdef MNG_INCLUDE_JNG + pData->bHasJHDR = MNG_FALSE; + pData->bHasJSEP = MNG_FALSE; + pData->bHasJDAA = MNG_FALSE; + pData->bHasJDAT = MNG_FALSE; +#endif + pData->bHasPLTE = MNG_FALSE; + pData->bHasTRNS = MNG_FALSE; + pData->bHasGAMA = MNG_FALSE; + pData->bHasCHRM = MNG_FALSE; + pData->bHasSRGB = MNG_FALSE; + pData->bHasICCP = MNG_FALSE; + pData->bHasBKGD = MNG_FALSE; + pData->bHasIDAT = MNG_FALSE; +#ifdef MNG_SUPPORT_DISPLAY + } +#endif + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +MNG_F_SPECIALFUNC (mng_debunk_trns) +{ + mng_trnsp pTRNS = (mng_trnsp)pChunk; + mng_uint32 iRawlen = *piRawlen; + mng_uint8p pRawdata = *ppRawdata; + + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + { /* not global! */ + pTRNS->bGlobal = MNG_FALSE; + pTRNS->iType = pData->iColortype; + + if (iRawlen != 0) + { + switch (pData->iColortype) /* store fields */ + { + case 0: { /* gray */ + if (iRawlen != 2) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + pTRNS->iGray = mng_get_uint16 (pRawdata); + break; + } + case 2: { /* rgb */ + if (iRawlen != 6) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + pTRNS->iRed = mng_get_uint16 (pRawdata); + pTRNS->iGreen = mng_get_uint16 (pRawdata+2); + pTRNS->iBlue = mng_get_uint16 (pRawdata+4); + break; + } + case 3: { /* indexed */ + if (iRawlen > 256) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + pTRNS->iCount = iRawlen; + MNG_COPY (pTRNS->aEntries, pRawdata, iRawlen); + break; + } + } + } + } + else /* it's global! */ + { + if (iRawlen == 0) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + pTRNS->bGlobal = MNG_TRUE; + pTRNS->iType = 0; + pTRNS->iRawlen = iRawlen; + MNG_COPY (pTRNS->aRawdata, pRawdata, iRawlen); + + pData->iGlobalTRNSrawlen = iRawlen; + MNG_COPY (pData->aGlobalTRNSrawdata, pRawdata, iRawlen); + } + + *piRawlen = 0; + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_C_SPECIALFUNC (mng_special_trns) +{ /* multiple tRNS only inside BASI */ + if ((pData->bHasTRNS) && (!pData->bHasBASI)) + MNG_ERROR (pData, MNG_MULTIPLEERROR); + + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + { /* not allowed with full alpha-channel */ + if ((pData->iColortype == 4) || (pData->iColortype == 6)) + MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); + + if (!((mng_trnsp)pChunk)->bEmpty) /* filled ? */ + { +#ifdef MNG_SUPPORT_DISPLAY + if (pData->iColortype == 3) + { + mng_imagep pImage = (mng_imagep)pData->pCurrentobj; + mng_imagedatap pBuf; + + if (!pImage) /* no object then check obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + + pBuf = pImage->pImgbuf; /* address object buffer */ + + if (((mng_trnsp)pChunk)->iCount > pBuf->iPLTEcount) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } +#endif + } + else /* if empty there must be global stuff! */ + { + if (!pData->bHasglobalTRNS) + MNG_ERROR (pData, MNG_CANNOTBEEMPTY); + } + } + + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + pData->bHasTRNS = MNG_TRUE; /* indicate tRNS available */ + else + pData->bHasglobalTRNS = MNG_TRUE; + +#ifdef MNG_SUPPORT_DISPLAY + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + { + mng_imagep pImage; + mng_imagedatap pBuf; + mng_uint8p pRawdata2; + mng_uint32 iRawlen2; + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* processing delta-image ? */ + { /* store in object 0 !!! */ +#if defined(MNG_NO_1_2_4BIT_SUPPORT) + mng_uint8 multiplier[]={0,255,85,0,17,0,0,0,1,0,0,0,0,0,0,0,1}; +#endif + pImage = (mng_imagep)pData->pObjzero; + pBuf = pImage->pImgbuf; /* address object buffer */ + pBuf->bHasTRNS = MNG_TRUE; /* tell it it's got a tRNS now */ + pBuf->iTRNSgray = 0; + pBuf->iTRNSred = 0; + pBuf->iTRNSgreen = 0; + pBuf->iTRNSblue = 0; + pBuf->iTRNScount = 0; + + switch (pData->iColortype) /* store fields for future reference */ + { + case 0: { /* gray */ + pBuf->iTRNSgray = ((mng_trnsp)pChunk)->iGray; +#if defined(MNG_NO_1_2_4BIT_SUPPORT) + pBuf->iTRNSgray *= multiplier[pData->iPNGdepth]; +#endif +#if defined(MNG_NO_16BIT_SUPPORT) + if (pData->iPNGmult == 2) + pBuf->iTRNSgray >>= 8; +#endif + break; + } + case 2: { /* rgb */ + pBuf->iTRNSred = ((mng_trnsp)pChunk)->iRed; + pBuf->iTRNSgreen = ((mng_trnsp)pChunk)->iGreen; + pBuf->iTRNSblue = ((mng_trnsp)pChunk)->iBlue; +#if defined(MNG_NO_16BIT_SUPPORT) + if (pData->iPNGmult == 2) + { + pBuf->iTRNSred >>= 8; + pBuf->iTRNSgreen >>= 8; + pBuf->iTRNSblue >>= 8; + } +#endif + break; + } + case 3: { /* indexed */ + pBuf->iTRNScount = ((mng_trnsp)pChunk)->iCount; + MNG_COPY (pBuf->aTRNSentries, + ((mng_trnsp)pChunk)->aEntries, + ((mng_trnsp)pChunk)->iCount); + break; + } + } + } + else +#endif + { /* address current object */ + pImage = (mng_imagep)pData->pCurrentobj; + + if (!pImage) /* no object then dump it in obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + + pBuf = pImage->pImgbuf; /* address object buffer */ + pBuf->bHasTRNS = MNG_TRUE; /* and tell it it's got a tRNS now */ + pBuf->iTRNSgray = 0; + pBuf->iTRNSred = 0; + pBuf->iTRNSgreen = 0; + pBuf->iTRNSblue = 0; + pBuf->iTRNScount = 0; + + if (((mng_trnsp)pChunk)->bEmpty) /* if empty, inherit from global */ + { + iRawlen2 = pData->iGlobalTRNSrawlen; + pRawdata2 = (mng_ptr)(pData->aGlobalTRNSrawdata); + /* global length oke ? */ + if ((pData->iColortype == 0) && (iRawlen2 != 2)) + MNG_ERROR (pData, MNG_GLOBALLENGTHERR); + + if ((pData->iColortype == 2) && (iRawlen2 != 6)) + MNG_ERROR (pData, MNG_GLOBALLENGTHERR); + + if ((pData->iColortype == 3) && ((iRawlen2 == 0) || (iRawlen2 > pBuf->iPLTEcount))) + MNG_ERROR (pData, MNG_GLOBALLENGTHERR); + + switch (pData->iColortype) /* store fields for future reference */ + { + case 0: { /* gray */ + pBuf->iTRNSgray = mng_get_uint16 (pRawdata2); +#if defined(MNG_NO_16BIT_SUPPORT) + if (pData->iPNGmult == 2) + pBuf->iTRNSgray >>= 8; +#endif + break; + } + case 2: { /* rgb */ + pBuf->iTRNSred = mng_get_uint16 (pRawdata2); + pBuf->iTRNSgreen = mng_get_uint16 (pRawdata2+2); + pBuf->iTRNSblue = mng_get_uint16 (pRawdata2+4); +#if defined(MNG_NO_16BIT_SUPPORT) + if (pData->iPNGmult == 2) + { + pBuf->iTRNSred >>= 8; + pBuf->iTRNSgreen >>= 8; + pBuf->iTRNSblue >>= 8; + } +#endif + break; + } + case 3: { /* indexed */ + pBuf->iTRNScount = iRawlen2; + MNG_COPY (pBuf->aTRNSentries, pRawdata2, iRawlen2); + break; + } + } + } + else + { + switch (pData->iColortype) /* store fields for future reference */ + { + case 0: { /* gray */ + pBuf->iTRNSgray = ((mng_trnsp)pChunk)->iGray; +#if defined(MNG_NO_16BIT_SUPPORT) + if (pData->iPNGmult == 2) + pBuf->iTRNSgray >>= 8; +#endif + break; + } + case 2: { /* rgb */ + pBuf->iTRNSred = ((mng_trnsp)pChunk)->iRed; + pBuf->iTRNSgreen = ((mng_trnsp)pChunk)->iGreen; + pBuf->iTRNSblue = ((mng_trnsp)pChunk)->iBlue; +#if defined(MNG_NO_16BIT_SUPPORT) + if (pData->iPNGmult == 2) + { + pBuf->iTRNSred >>= 8; + pBuf->iTRNSgreen >>= 8; + pBuf->iTRNSblue >>= 8; + } +#endif + break; + } + case 3: { /* indexed */ + pBuf->iTRNScount = ((mng_trnsp)pChunk)->iCount; + MNG_COPY (pBuf->aTRNSentries, + ((mng_trnsp)pChunk)->aEntries, + ((mng_trnsp)pChunk)->iCount); + break; + } + } + } + } + } + else + { /* create an animation object */ + return mng_create_ani_trns (pData); + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +MNG_C_SPECIALFUNC (mng_special_gama) +{ +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + pData->bHasGAMA = MNG_TRUE; /* indicate we've got it */ + else + pData->bHasglobalGAMA = (mng_bool)!((mng_gamap)pChunk)->bEmpty; + +#ifdef MNG_SUPPORT_DISPLAY +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + { + mng_imagep pImage; + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* update delta image ? */ + pImage = (mng_imagep)pData->pObjzero; + else +#endif + { + pImage = (mng_imagep)pData->pCurrentobj; + if (!pImage) /* no object then dump it in obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + } + /* store for color-processing routines */ + pImage->pImgbuf->iGamma = ((mng_gamap)pChunk)->iGamma; + pImage->pImgbuf->bHasGAMA = MNG_TRUE; + } + else + { /* store as global */ + if (!((mng_gamap)pChunk)->bEmpty) + pData->iGlobalGamma = ((mng_gamap)pChunk)->iGamma; + /* create an animation object */ + return mng_create_ani_gama (pData, pChunk); + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_cHRM +MNG_C_SPECIALFUNC (mng_special_chrm) +{ +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + pData->bHasCHRM = MNG_TRUE; /* indicate we've got it */ + else + pData->bHasglobalCHRM = (mng_bool)!((mng_chrmp)pChunk)->bEmpty; + +#ifdef MNG_SUPPORT_DISPLAY + { +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + { + mng_imagep pImage; + mng_imagedatap pBuf; + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* update delta image ? */ + pImage = (mng_imagep)pData->pObjzero; + else +#endif + { + pImage = (mng_imagep)pData->pCurrentobj; + if (!pImage) /* no object then dump it in obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + } + + pBuf = pImage->pImgbuf; /* address object buffer */ + pBuf->bHasCHRM = MNG_TRUE; /* and tell it it's got a CHRM now */ + /* store for color-processing routines */ + pBuf->iWhitepointx = ((mng_chrmp)pChunk)->iWhitepointx; + pBuf->iWhitepointy = ((mng_chrmp)pChunk)->iWhitepointy; + pBuf->iPrimaryredx = ((mng_chrmp)pChunk)->iRedx; + pBuf->iPrimaryredy = ((mng_chrmp)pChunk)->iRedy; + pBuf->iPrimarygreenx = ((mng_chrmp)pChunk)->iGreenx; + pBuf->iPrimarygreeny = ((mng_chrmp)pChunk)->iGreeny; + pBuf->iPrimarybluex = ((mng_chrmp)pChunk)->iBluex; + pBuf->iPrimarybluey = ((mng_chrmp)pChunk)->iBluey; + } + else + { /* store as global */ + if (!((mng_chrmp)pChunk)->bEmpty) + { + pData->iGlobalWhitepointx = ((mng_chrmp)pChunk)->iWhitepointx; + pData->iGlobalWhitepointy = ((mng_chrmp)pChunk)->iWhitepointy; + pData->iGlobalPrimaryredx = ((mng_chrmp)pChunk)->iRedx; + pData->iGlobalPrimaryredy = ((mng_chrmp)pChunk)->iRedy; + pData->iGlobalPrimarygreenx = ((mng_chrmp)pChunk)->iGreenx; + pData->iGlobalPrimarygreeny = ((mng_chrmp)pChunk)->iGreeny; + pData->iGlobalPrimarybluex = ((mng_chrmp)pChunk)->iBluex; + pData->iGlobalPrimarybluey = ((mng_chrmp)pChunk)->iBluey; + } + /* create an animation object */ + return mng_create_ani_chrm (pData, pChunk); + } + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +MNG_C_SPECIALFUNC (mng_special_srgb) +{ +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + pData->bHasSRGB = MNG_TRUE; /* indicate we've got it */ + else + pData->bHasglobalSRGB = (mng_bool)!((mng_srgbp)pChunk)->bEmpty; + +#ifdef MNG_SUPPORT_DISPLAY +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + { + mng_imagep pImage; + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* update delta image ? */ + pImage = (mng_imagep)pData->pObjzero; + else +#endif + { + pImage = (mng_imagep)pData->pCurrentobj; + if (!pImage) /* no object then dump it in obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + } + /* store for color-processing routines */ + pImage->pImgbuf->iRenderingintent = ((mng_srgbp)pChunk)->iRenderingintent; + pImage->pImgbuf->bHasSRGB = MNG_TRUE; + } + else + { /* store as global */ + if (!((mng_srgbp)pChunk)->bEmpty) + pData->iGlobalRendintent = ((mng_srgbp)pChunk)->iRenderingintent; + /* create an animation object */ + return mng_create_ani_srgb (pData, pChunk); + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iCCP +MNG_C_SPECIALFUNC (mng_special_iccp) +{ + mng_retcode iRetcode; + mng_chunk_headerp pDummy; + +#ifdef MNG_CHECK_BAD_ICCP /* Check for bad iCCP chunk */ + if (!strncmp (((mng_iccpp)pChunk)->zName, "Photoshop ICC profile", 21)) + { + if (((mng_iccpp)pChunk)->iProfilesize == 2615) /* is it the sRGB profile ? */ + { + mng_chunk_header chunk_srgb; + mng_get_chunkheader (MNG_UINT_sRGB, &chunk_srgb); + /* pretend it's an sRGB chunk then ! */ + iRetcode = mng_read_general (pData, &chunk_srgb, 1, (mng_ptr)"0", &pDummy); + if (iRetcode) /* on error bail out */ + return iRetcode; + + pDummy->fCleanup (pData, pDummy); + } + } + else + { +#endif /* MNG_CHECK_BAD_ICCP */ + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + pData->bHasICCP = MNG_TRUE; /* indicate we've got it */ + else + pData->bHasglobalICCP = (mng_bool)!((mng_iccpp)pChunk)->bEmpty; + +#ifdef MNG_SUPPORT_DISPLAY +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + { + mng_imagep pImage; + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* update delta image ? */ + { /* store in object 0 ! */ + pImage = (mng_imagep)pData->pObjzero; + + if (pImage->pImgbuf->pProfile) /* profile existed ? */ + MNG_FREEX (pData, pImage->pImgbuf->pProfile, pImage->pImgbuf->iProfilesize); + /* allocate a buffer & copy it */ + MNG_ALLOC (pData, pImage->pImgbuf->pProfile, ((mng_iccpp)pChunk)->iProfilesize); + MNG_COPY (pImage->pImgbuf->pProfile, ((mng_iccpp)pChunk)->pProfile, ((mng_iccpp)pChunk)->iProfilesize); + /* store its length as well */ + pImage->pImgbuf->iProfilesize = ((mng_iccpp)pChunk)->iProfilesize; + pImage->pImgbuf->bHasICCP = MNG_TRUE; + } + else +#endif + { + pImage = (mng_imagep)pData->pCurrentobj; + + if (!pImage) /* no object then dump it in obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + + if (pImage->pImgbuf->pProfile) /* profile existed ? */ + MNG_FREEX (pData, pImage->pImgbuf->pProfile, pImage->pImgbuf->iProfilesize); + /* allocate a buffer & copy it */ + MNG_ALLOC (pData, pImage->pImgbuf->pProfile, ((mng_iccpp)pChunk)->iProfilesize); + MNG_COPY (pImage->pImgbuf->pProfile, ((mng_iccpp)pChunk)->pProfile, ((mng_iccpp)pChunk)->iProfilesize); + /* store its length as well */ + pImage->pImgbuf->iProfilesize = ((mng_iccpp)pChunk)->iProfilesize; + pImage->pImgbuf->bHasICCP = MNG_TRUE; + } + } + else + { /* store as global */ + if (pData->pGlobalProfile) /* did we have a global profile ? */ + MNG_FREEX (pData, pData->pGlobalProfile, pData->iGlobalProfilesize); + + if (((mng_iccpp)pChunk)->bEmpty) /* empty chunk ? */ + { + pData->iGlobalProfilesize = 0; /* reset to null */ + pData->pGlobalProfile = MNG_NULL; + } + else + { /* allocate a global buffer & copy it */ + MNG_ALLOC (pData, pData->pGlobalProfile, ((mng_iccpp)pChunk)->iProfilesize); + MNG_COPY (pData->pGlobalProfile, ((mng_iccpp)pChunk)->pProfile, ((mng_iccpp)pChunk)->iProfilesize); + /* store its length as well */ + pData->iGlobalProfilesize = ((mng_iccpp)pChunk)->iProfilesize; + } + /* create an animation object */ + return mng_create_ani_iccp (pData, pChunk); + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_CHECK_BAD_ICCP + } +#endif + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_tEXt +MNG_C_SPECIALFUNC (mng_special_text) +{ + if (pData->fProcesstext) /* inform the application ? */ + { + mng_bool bOke = pData->fProcesstext ((mng_handle)pData, MNG_TYPE_TEXT, + ((mng_textp)pChunk)->zKeyword, + ((mng_textp)pChunk)->zText, 0, 0); + if (!bOke) + MNG_ERROR (pData, MNG_APPMISCERROR); + } + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_zTXt +MNG_C_SPECIALFUNC (mng_special_ztxt) +{ + if (pData->fProcesstext) /* inform the application ? */ + { + mng_bool bOke = pData->fProcesstext ((mng_handle)pData, MNG_TYPE_ZTXT, + ((mng_ztxtp)pChunk)->zKeyword, + ((mng_ztxtp)pChunk)->zText, 0, 0); + if (!bOke) + MNG_ERROR (pData, MNG_APPMISCERROR); + } + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iTXt +MNG_F_SPECIALFUNC (mng_deflate_itxt) +{ + mng_itxtp pITXT = (mng_itxtp)pChunk; + mng_uint32 iBufsize = 0; + mng_uint8p pBuf = 0; + mng_uint32 iTextlen = 0; + + if (pITXT->iCompressionflag) /* decompress the text ? */ + { + mng_retcode iRetcode = mng_inflate_buffer (pData, *ppRawdata, *piRawlen, + &pBuf, &iBufsize, &iTextlen); + + if (iRetcode) /* on error bail out */ + { /* don't forget to drop the temp buffer */ + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + + MNG_ALLOC (pData, pITXT->zText, iTextlen+1); + MNG_COPY (pITXT->zText, pBuf, iTextlen); + + pITXT->iTextsize = iTextlen; + + MNG_FREEX (pData, pBuf, iBufsize); + + } else { + + MNG_ALLOC (pData, pITXT->zText, (*piRawlen)+1); + MNG_COPY (pITXT->zText, *ppRawdata, *piRawlen); + + pITXT->iTextsize = *piRawlen; + } + + *piRawlen = 0; + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iTXt +MNG_C_SPECIALFUNC (mng_special_itxt) +{ + if (pData->fProcesstext) /* inform the application ? */ + { + mng_bool bOke = pData->fProcesstext ((mng_handle)pData, MNG_TYPE_ITXT, + ((mng_itxtp)pChunk)->zKeyword, + ((mng_itxtp)pChunk)->zText, + ((mng_itxtp)pChunk)->zLanguage, + ((mng_itxtp)pChunk)->zTranslation); + if (!bOke) + MNG_ERROR (pData, MNG_APPMISCERROR); + } + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_bKGD +MNG_C_SPECIALFUNC (mng_special_bkgd) +{ +#ifdef MNG_SUPPORT_DISPLAY + mng_imagep pImage = (mng_imagep)pData->pCurrentobj; + mng_imagedatap pBuf; +#endif + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + pData->bHasBKGD = MNG_TRUE; /* indicate bKGD available */ + else + pData->bHasglobalBKGD = (mng_bool)!(((mng_bkgdp)pChunk)->bEmpty); + +#ifdef MNG_SUPPORT_DISPLAY + if (!pImage) /* if no object dump it in obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + pBuf = pImage->pImgbuf; /* address object buffer */ + +#ifdef MNG_INCLUDE_JNG + if (pData->bHasJHDR) + { + pBuf->bHasBKGD = MNG_TRUE; /* tell the object it's got bKGD now */ + + switch (pData->iJHDRcolortype) /* store fields for future reference */ + { + case 8 : ; /* gray */ + case 12 : { /* graya */ + pBuf->iBKGDgray = ((mng_bkgdp)pChunk)->iGray; + break; + } + case 10 : ; /* rgb */ + case 14 : { /* rgba */ + pBuf->iBKGDred = ((mng_bkgdp)pChunk)->iRed; + pBuf->iBKGDgreen = ((mng_bkgdp)pChunk)->iGreen; + pBuf->iBKGDblue = ((mng_bkgdp)pChunk)->iBlue; + break; + } + } + } + else +#endif /* MNG_INCLUDE_JNG */ + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + { + pBuf->bHasBKGD = MNG_TRUE; /* tell the object it's got bKGD now */ + + switch (pData->iColortype) /* store fields for future reference */ + { + case 0 : ; /* gray */ + case 4 : { /* graya */ + pBuf->iBKGDgray = ((mng_bkgdp)pChunk)->iGray; + break; + } + case 2 : ; /* rgb */ + case 6 : { /* rgba */ + pBuf->iBKGDred = ((mng_bkgdp)pChunk)->iRed; + pBuf->iBKGDgreen = ((mng_bkgdp)pChunk)->iGreen; + pBuf->iBKGDblue = ((mng_bkgdp)pChunk)->iBlue; + break; + } + case 3 : { /* indexed */ + pBuf->iBKGDindex = ((mng_bkgdp)pChunk)->iIndex; + break; + } + } + } + else /* store as global */ + { + if (!(((mng_bkgdp)pChunk)->bEmpty)) + { + pData->iGlobalBKGDred = ((mng_bkgdp)pChunk)->iRed; + pData->iGlobalBKGDgreen = ((mng_bkgdp)pChunk)->iGreen; + pData->iGlobalBKGDblue = ((mng_bkgdp)pChunk)->iBlue; + } + /* create an animation object */ + return mng_create_ani_bkgd (pData); + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_pHYs +MNG_C_SPECIALFUNC (mng_special_phys) +{ +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sBIT +MNG_C_SPECIALFUNC (mng_special_sbit) +{ +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sPLT +MNG_F_SPECIALFUNC (mng_splt_entries) +{ + mng_spltp pSPLT = (mng_spltp)pChunk; + mng_uint32 iRawlen = *piRawlen; + mng_uint8p pRawdata = *ppRawdata; + + if ((pSPLT->iSampledepth != MNG_BITDEPTH_8 ) && + (pSPLT->iSampledepth != MNG_BITDEPTH_16) ) + MNG_ERROR (pData, MNG_INVSAMPLEDEPTH); + /* check remaining length */ + if ( ((pSPLT->iSampledepth == MNG_BITDEPTH_8 ) && (iRawlen % 6 != 0)) || + ((pSPLT->iSampledepth == MNG_BITDEPTH_16) && (iRawlen % 10 != 0)) ) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if (pSPLT->iSampledepth == MNG_BITDEPTH_8) + pSPLT->iEntrycount = iRawlen / 6; + else + pSPLT->iEntrycount = iRawlen / 10; + + if (iRawlen) + { + MNG_ALLOC (pData, pSPLT->pEntries, iRawlen); + MNG_COPY (pSPLT->pEntries, pRawdata, iRawlen); + } + + *piRawlen = 0; + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sPLT +MNG_C_SPECIALFUNC (mng_special_splt) +{ +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_hIST +MNG_F_SPECIALFUNC (mng_hist_entries) +{ + mng_histp pHIST = (mng_histp)pChunk; + mng_uint32 iRawlen = *piRawlen; + mng_uint8p pRawdata = *ppRawdata; + mng_uint32 iX; + + if ( ((iRawlen & 0x01) != 0) || ((iRawlen >> 1) != pData->iPLTEcount) ) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + pHIST->iEntrycount = iRawlen >> 1; + + for (iX = 0; iX < pHIST->iEntrycount; iX++) + { + pHIST->aEntries[iX] = mng_get_uint16 (pRawdata); + pRawdata += 2; + } + + *piRawlen = 0; + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_hIST +MNG_C_SPECIALFUNC (mng_special_hist) +{ +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_tIME +MNG_C_SPECIALFUNC (mng_special_time) +{ +/* if (pData->fProcesstime) */ /* inform the application ? */ +/* { + + pData->fProcesstime ((mng_handle)pData, ); + } */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ +/* ************************************************************************** */ +/* JNG chunks */ + +#ifdef MNG_INCLUDE_JNG +MNG_C_SPECIALFUNC (mng_special_jhdr) +{ + if ((pData->eSigtype == mng_it_jng) && (pData->iChunkseq > 1)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* inside a JHDR-IEND block now */ + pData->bHasJHDR = MNG_TRUE; + /* and store interesting fields */ + pData->iDatawidth = ((mng_jhdrp)pChunk)->iWidth; + pData->iDataheight = ((mng_jhdrp)pChunk)->iHeight; + pData->iJHDRcolortype = ((mng_jhdrp)pChunk)->iColortype; + pData->iJHDRimgbitdepth = ((mng_jhdrp)pChunk)->iImagesampledepth; + pData->iJHDRimgcompression = ((mng_jhdrp)pChunk)->iImagecompression; + pData->iJHDRimginterlace = ((mng_jhdrp)pChunk)->iImageinterlace; + pData->iJHDRalphabitdepth = ((mng_jhdrp)pChunk)->iAlphasampledepth; + pData->iJHDRalphacompression = ((mng_jhdrp)pChunk)->iAlphacompression; + pData->iJHDRalphafilter = ((mng_jhdrp)pChunk)->iAlphafilter; + pData->iJHDRalphainterlace = ((mng_jhdrp)pChunk)->iAlphainterlace; + +#if defined(MNG_NO_1_2_4BIT_SUPPORT) || defined(MNG_NO_16BIT_SUPPORT) + pData->iPNGmult = 1; + pData->iPNGdepth = pData->iJHDRalphabitdepth; +#endif + +#ifdef MNG_NO_1_2_4BIT_SUPPORT + if (pData->iJHDRalphabitdepth < 8) + pData->iJHDRalphabitdepth = 8; +#endif + +#ifdef MNG_NO_16BIT_SUPPORT + if (pData->iJHDRalphabitdepth > 8) + { + pData->iPNGmult = 2; + pData->iJHDRalphabitdepth = 8; + } +#endif + /* parameter validity checks */ + if ((pData->iJHDRcolortype != MNG_COLORTYPE_JPEGGRAY ) && + (pData->iJHDRcolortype != MNG_COLORTYPE_JPEGCOLOR ) && + (pData->iJHDRcolortype != MNG_COLORTYPE_JPEGGRAYA ) && + (pData->iJHDRcolortype != MNG_COLORTYPE_JPEGCOLORA) ) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + + if ((pData->iJHDRimgbitdepth != MNG_BITDEPTH_JPEG8 ) && + (pData->iJHDRimgbitdepth != MNG_BITDEPTH_JPEG12 ) && + (pData->iJHDRimgbitdepth != MNG_BITDEPTH_JPEG8AND12) ) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || + (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) + { + if ((pData->iJHDRalphabitdepth != MNG_BITDEPTH_8 ) +#ifndef MNG_NO_1_2_4BIT_SUPPORT + && (pData->iJHDRalphabitdepth != MNG_BITDEPTH_1 ) && + (pData->iJHDRalphabitdepth != MNG_BITDEPTH_2 ) && + (pData->iJHDRalphabitdepth != MNG_BITDEPTH_4 ) +#endif +#ifndef MNG_NO_16BIT_SUPPORT + && (pData->iJHDRalphabitdepth != MNG_BITDEPTH_16) +#endif + ) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if ((pData->iJHDRalphacompression != MNG_COMPRESSION_DEFLATE ) && + (pData->iJHDRalphacompression != MNG_COMPRESSION_BASELINEJPEG) ) + MNG_ERROR (pData, MNG_INVALIDCOMPRESS); + + if ((pData->iJHDRalphacompression == MNG_COMPRESSION_BASELINEJPEG) && + (pData->iJHDRalphabitdepth != MNG_BITDEPTH_8 ) ) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + +#if defined(FILTER192) || defined(FILTER193) + if ((pData->iJHDRalphafilter != MNG_FILTER_ADAPTIVE ) && +#if defined(FILTER192) && defined(FILTER193) + (pData->iJHDRalphafilter != MNG_FILTER_DIFFERING) && + (pData->iJHDRalphafilter != MNG_FILTER_NOFILTER ) ) +#else +#ifdef FILTER192 + (pData->iJHDRalphafilter != MNG_FILTER_DIFFERING) ) +#else + (pData->iJHDRalphafilter != MNG_FILTER_NOFILTER ) ) +#endif +#endif + MNG_ERROR (pData, MNG_INVALIDFILTER); +#else + if (pData->iJHDRalphafilter) + MNG_ERROR (pData, MNG_INVALIDFILTER); +#endif + + } + else + { + if (pData->iJHDRalphabitdepth) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + if (pData->iJHDRalphacompression) + MNG_ERROR (pData, MNG_INVALIDCOMPRESS); + if (pData->iJHDRalphafilter) + MNG_ERROR (pData, MNG_INVALIDFILTER); + if (pData->iJHDRalphainterlace) + MNG_ERROR (pData, MNG_INVALIDINTERLACE); + } + + if (!pData->bHasheader) /* first chunk ? */ + { + pData->bHasheader = MNG_TRUE; /* we've got a header */ + pData->eImagetype = mng_it_jng; /* then this must be a JNG */ + pData->iWidth = ((mng_jhdrp)pChunk)->iWidth; + pData->iHeight = ((mng_jhdrp)pChunk)->iHeight; + /* predict alpha-depth ! */ + if ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || + (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) + pData->iAlphadepth = pData->iJHDRalphabitdepth; + else + pData->iAlphadepth = 0; + /* fits on maximum canvas ? */ + if ((pData->iWidth > pData->iMaxwidth) || (pData->iHeight > pData->iMaxheight)) + MNG_WARNING (pData, MNG_IMAGETOOLARGE); + + if (pData->fProcessheader) /* inform the app ? */ + if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) + MNG_ERROR (pData, MNG_APPMISCERROR); + + } + + pData->iColortype = 0; /* fake grayscale for other routines */ + pData->iImagelevel++; /* one level deeper */ + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode = mng_process_display_jhdr (pData); + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_NO_16BIT_SUPPORT + if (((mng_jhdrp)pChunk)->iAlphasampledepth > 8) + ((mng_jhdrp)pChunk)->iAlphasampledepth = 8; +#endif + + return MNG_NOERROR; /* done */ +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +MNG_C_SPECIALFUNC (mng_special_jdaa) +{ + if (pData->iJHDRalphacompression != MNG_COMPRESSION_BASELINEJPEG) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + pData->bHasJDAA = MNG_TRUE; /* got some JDAA now, don't we */ + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +MNG_C_SPECIALFUNC (mng_special_jdat) +{ + pData->bHasJDAT = MNG_TRUE; /* got some JDAT now, don't we */ + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +MNG_C_SPECIALFUNC (mng_special_jsep) +{ + pData->bHasJSEP = MNG_TRUE; /* indicate we've had the 8-/12-bit separator */ + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ +/* ************************************************************************** */ +/* MNG chunks */ + +MNG_C_SPECIALFUNC (mng_special_mhdr) +{ + if (pData->bHasheader) /* can only be the first chunk! */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + pData->bHasMHDR = MNG_TRUE; /* oh boy, a real MNG */ + pData->bHasheader = MNG_TRUE; /* we've got a header */ + pData->eImagetype = mng_it_mng; /* fill header fields */ + pData->iWidth = ((mng_mhdrp)pChunk)->iWidth; + pData->iHeight = ((mng_mhdrp)pChunk)->iHeight; + pData->iTicks = ((mng_mhdrp)pChunk)->iTicks; + pData->iLayercount = ((mng_mhdrp)pChunk)->iLayercount; + pData->iFramecount = ((mng_mhdrp)pChunk)->iFramecount; + pData->iPlaytime = ((mng_mhdrp)pChunk)->iPlaytime; + pData->iSimplicity = ((mng_mhdrp)pChunk)->iSimplicity; +#ifndef MNG_NO_OLD_VERSIONS + pData->bPreDraft48 = MNG_FALSE; +#endif + /* predict alpha-depth */ + if ((pData->iSimplicity & 0x00000001) == 0) +#ifndef MNG_NO_16BIT_SUPPORT + pData->iAlphadepth = 16; /* no indicators = assume the worst */ +#else + pData->iAlphadepth = 8; /* anything else = assume the worst */ +#endif + else + if ((pData->iSimplicity & 0x00000008) == 0) + pData->iAlphadepth = 0; /* no transparency at all */ + else + if ((pData->iSimplicity & 0x00000140) == 0x00000040) + pData->iAlphadepth = 1; /* no semi-transparency guaranteed */ + else +#ifndef MNG_NO_16BIT_SUPPORT + pData->iAlphadepth = 16; /* anything else = assume the worst */ +#else + pData->iAlphadepth = 8; /* anything else = assume the worst */ +#endif + +#ifdef MNG_INCLUDE_JNG /* can we handle the complexity ? */ + if (pData->iSimplicity & 0x0000FC00) +#else + if (pData->iSimplicity & 0x0000FC10) +#endif + MNG_ERROR (pData, MNG_MNGTOOCOMPLEX); + /* fits on maximum canvas ? */ + if ((pData->iWidth > pData->iMaxwidth) || (pData->iHeight > pData->iMaxheight)) + MNG_WARNING (pData, MNG_IMAGETOOLARGE); + + if (pData->fProcessheader) /* inform the app ? */ + if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) + MNG_ERROR (pData, MNG_APPMISCERROR); + + pData->iImagelevel++; /* one level deeper */ + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +MNG_C_SPECIALFUNC (mng_special_mend) +{ +#ifdef MNG_SUPPORT_DISPLAY + { /* do something */ + mng_retcode iRetcode = mng_process_display_mend (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + if (!pData->iTotalframes) /* save totals */ + pData->iTotalframes = pData->iFrameseq; + if (!pData->iTotallayers) + pData->iTotallayers = pData->iLayerseq; + if (!pData->iTotalplaytime) + pData->iTotalplaytime = pData->iFrametime; + } +#endif /* MNG_SUPPORT_DISPLAY */ + + pData->bHasMHDR = MNG_FALSE; /* end of the line, bro! */ + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_LOOP +MNG_F_SPECIALFUNC (mng_debunk_loop) +{ + mng_loopp pLOOP = (mng_loopp)pChunk; + mng_uint32 iRawlen = *piRawlen; + mng_uint8p pRawdata = *ppRawdata; + + if (iRawlen >= 5) /* length checks */ + { + if (iRawlen >= 6) + { + if ((iRawlen - 6) % 4 != 0) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if (iRawlen >= 5) /* store the fields */ + { + pLOOP->iLevel = *pRawdata; + +#ifndef MNG_NO_OLD_VERSIONS + if (pData->bPreDraft48) + { + pLOOP->iTermination = *(pRawdata+1); + pLOOP->iRepeat = mng_get_uint32 (pRawdata+2); + } + else +#endif + { + pLOOP->iRepeat = mng_get_uint32 (pRawdata+1); + } + + if (iRawlen >= 6) + { +#ifndef MNG_NO_OLD_VERSIONS + if (!pData->bPreDraft48) +#endif + pLOOP->iTermination = *(pRawdata+5); + + if (iRawlen >= 10) + { + pLOOP->iItermin = mng_get_uint32 (pRawdata+6); + +#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED + if (iRawlen >= 14) + { + pLOOP->iItermax = mng_get_uint32 (pRawdata+10); + pLOOP->iCount = (iRawlen - 14) / 4; + + if (pLOOP->iCount) + { + MNG_ALLOC (pData, pLOOP->pSignals, pLOOP->iCount << 2); + +#ifndef MNG_BIGENDIAN_SUPPORTED + { + mng_uint32 iX; + mng_uint8p pIn = pRawdata + 14; + mng_uint32p pOut = (mng_uint32p)pLOOP->pSignals; + + for (iX = 0; iX < pLOOP->iCount; iX++) + { + *pOut++ = mng_get_uint32 (pIn); + pIn += 4; + } + } +#else + MNG_COPY (pLOOP->pSignals, pRawdata + 14, pLOOP->iCount << 2); +#endif /* !MNG_BIGENDIAN_SUPPORTED */ + } + } +#endif + } + } + } + + *piRawlen = 0; + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_LOOP +MNG_C_SPECIALFUNC (mng_special_loop) +{ + if (!pData->bCacheplayback) /* must store playback info to work!! */ + MNG_ERROR (pData, MNG_LOOPWITHCACHEOFF); + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode; + + pData->bHasLOOP = MNG_TRUE; /* indicate we're inside a loop */ + /* create the LOOP ani-object */ + iRetcode = mng_create_ani_loop (pData, pChunk); + if (iRetcode) /* on error bail out */ + return iRetcode; + /* skip till matching ENDL if iteration=0 */ + if ((!pData->bSkipping) && (((mng_loopp)pChunk)->iRepeat == 0)) + pData->bSkipping = MNG_TRUE; + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_LOOP +MNG_C_SPECIALFUNC (mng_special_endl) +{ +#ifdef MNG_SUPPORT_DISPLAY + if (pData->bHasLOOP) /* are we really processing a loop ? */ + { + mng_uint8 iLevel = ((mng_endlp)pChunk)->iLevel; + /* create an ENDL animation object */ + return mng_create_ani_endl (pData, iLevel); + } + else + MNG_ERROR (pData, MNG_NOMATCHINGLOOP); +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DEFI +MNG_C_SPECIALFUNC (mng_special_defi) +{ +#ifdef MNG_SUPPORT_DISPLAY + mng_retcode iRetcode; + + pData->iDEFIobjectid = ((mng_defip)pChunk)->iObjectid; + pData->bDEFIhasdonotshow = ((mng_defip)pChunk)->bHasdonotshow; + pData->iDEFIdonotshow = ((mng_defip)pChunk)->iDonotshow; + pData->bDEFIhasconcrete = ((mng_defip)pChunk)->bHasconcrete; + pData->iDEFIconcrete = ((mng_defip)pChunk)->iConcrete; + pData->bDEFIhasloca = ((mng_defip)pChunk)->bHasloca; + pData->iDEFIlocax = ((mng_defip)pChunk)->iXlocation; + pData->iDEFIlocay = ((mng_defip)pChunk)->iYlocation; + pData->bDEFIhasclip = ((mng_defip)pChunk)->bHasclip; + pData->iDEFIclipl = ((mng_defip)pChunk)->iLeftcb; + pData->iDEFIclipr = ((mng_defip)pChunk)->iRightcb; + pData->iDEFIclipt = ((mng_defip)pChunk)->iTopcb; + pData->iDEFIclipb = ((mng_defip)pChunk)->iBottomcb; + /* create an animation object */ + iRetcode = mng_create_ani_defi (pData); + if (!iRetcode) /* do display processing */ + iRetcode = mng_process_display_defi (pData); + return iRetcode; +#else + return MNG_NOERROR; /* done */ +#endif /* MNG_SUPPORT_DISPLAY */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_BASI +MNG_C_SPECIALFUNC (mng_special_basi) +{ + pData->bHasBASI = MNG_TRUE; /* inside a BASI-IEND block now */ + /* store interesting fields */ + pData->iDatawidth = ((mng_basip)pChunk)->iWidth; + pData->iDataheight = ((mng_basip)pChunk)->iHeight; + pData->iBitdepth = ((mng_basip)pChunk)->iBitdepth; + pData->iColortype = ((mng_basip)pChunk)->iColortype; + pData->iCompression = ((mng_basip)pChunk)->iCompression; + pData->iFilter = ((mng_basip)pChunk)->iFilter; + pData->iInterlace = ((mng_basip)pChunk)->iInterlace; + +#if defined(MNG_NO_1_2_4BIT_SUPPORT) || defined(MNG_NO_16BIT_SUPPORT) + pData->iPNGmult = 1; + pData->iPNGdepth = pData->iBitdepth; +#endif + +#ifdef MNG_NO_1_2_4BIT_SUPPORT + if (pData->iBitdepth < 8) + pData->iBitdepth = 8; +#endif +#ifdef MNG_NO_16BIT_SUPPORT + if (pData->iBitdepth > 8) + { + pData->iBitdepth = 8; + pData->iPNGmult = 2; + } +#endif + + if ((pData->iBitdepth != 8) /* parameter validity checks */ +#ifndef MNG_NO_1_2_4BIT_SUPPORT + && (pData->iBitdepth != 1) && + (pData->iBitdepth != 2) && + (pData->iBitdepth != 4) +#endif +#ifndef MNG_NO_16BIT_SUPPORT + && (pData->iBitdepth != 16) +#endif + ) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if ((pData->iColortype != MNG_COLORTYPE_GRAY ) && + (pData->iColortype != MNG_COLORTYPE_RGB ) && + (pData->iColortype != MNG_COLORTYPE_INDEXED) && + (pData->iColortype != MNG_COLORTYPE_GRAYA ) && + (pData->iColortype != MNG_COLORTYPE_RGBA ) ) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + + if ((pData->iColortype == MNG_COLORTYPE_INDEXED) && (pData->iBitdepth > 8)) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if (((pData->iColortype == MNG_COLORTYPE_RGB ) || + (pData->iColortype == MNG_COLORTYPE_GRAYA ) || + (pData->iColortype == MNG_COLORTYPE_RGBA ) ) && + (pData->iBitdepth < 8 ) ) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + +#if defined(FILTER192) || defined(FILTER193) + if ((pData->iFilter != MNG_FILTER_ADAPTIVE ) && +#if defined(FILTER192) && defined(FILTER193) + (pData->iFilter != MNG_FILTER_DIFFERING) && + (pData->iFilter != MNG_FILTER_NOFILTER ) ) +#else +#ifdef FILTER192 + (pData->iFilter != MNG_FILTER_DIFFERING) ) +#else + (pData->iFilter != MNG_FILTER_NOFILTER ) ) +#endif +#endif + MNG_ERROR (pData, MNG_INVALIDFILTER); +#else + if (pData->iFilter) + MNG_ERROR (pData, MNG_INVALIDFILTER); +#endif + + pData->iImagelevel++; /* one level deeper */ + +#ifdef MNG_SUPPORT_DISPLAY + { /* create an animation object */ + mng_retcode iRetcode = mng_create_ani_basi (pData, pChunk); + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_NO_16BIT_SUPPORT + if (((mng_basip)pChunk)->iBitdepth > 8) + ((mng_basip)pChunk)->iBitdepth = 8; +#endif + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_CLON +MNG_C_SPECIALFUNC (mng_special_clon) +{ +#ifdef MNG_SUPPORT_DISPLAY + return mng_create_ani_clon (pData, pChunk); +#else + return MNG_NOERROR; /* done */ +#endif /* MNG_SUPPORT_DISPLAY */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +MNG_F_SPECIALFUNC (mng_debunk_past) +{ + mng_pastp pPAST = (mng_pastp)pChunk; + mng_uint32 iRawlen = *piRawlen; + mng_uint8p pRawdata = *ppRawdata; + mng_uint32 iSize; + mng_uint32 iX; + mng_past_sourcep pSource; + /* check the length */ + if ((iRawlen < 41) || (((iRawlen - 11) % 30) != 0)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + pPAST->iDestid = mng_get_uint16 (pRawdata); + pPAST->iTargettype = *(pRawdata+2); + pPAST->iTargetx = mng_get_int32 (pRawdata+3); + pPAST->iTargety = mng_get_int32 (pRawdata+7); + pPAST->iCount = ((iRawlen - 11) / 30); /* how many entries again? */ + iSize = pPAST->iCount * sizeof (mng_past_source); + + pRawdata += 11; + /* get a buffer for all the source blocks */ + MNG_ALLOC (pData, pPAST->pSources, iSize); + + pSource = (mng_past_sourcep)(pPAST->pSources); + + for (iX = pPAST->iCount; iX > 0; iX--) + { /* now copy the source blocks */ + pSource->iSourceid = mng_get_uint16 (pRawdata); + pSource->iComposition = *(pRawdata+2); + pSource->iOrientation = *(pRawdata+3); + pSource->iOffsettype = *(pRawdata+4); + pSource->iOffsetx = mng_get_int32 (pRawdata+5); + pSource->iOffsety = mng_get_int32 (pRawdata+9); + pSource->iBoundarytype = *(pRawdata+13); + pSource->iBoundaryl = mng_get_int32 (pRawdata+14); + pSource->iBoundaryr = mng_get_int32 (pRawdata+18); + pSource->iBoundaryt = mng_get_int32 (pRawdata+22); + pSource->iBoundaryb = mng_get_int32 (pRawdata+26); + + pSource++; + pRawdata += 30; + } + + *piRawlen = 0; + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +MNG_C_SPECIALFUNC (mng_special_past) +{ +#ifdef MNG_SUPPORT_DISPLAY + return mng_create_ani_past (pData, pChunk); +#else + return MNG_NOERROR; +#endif /* MNG_SUPPORT_DISPLAY */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DISC +MNG_F_SPECIALFUNC (mng_disc_entries) +{ + mng_discp pDISC = (mng_discp)pChunk; + mng_uint32 iRawlen = *piRawlen; + mng_uint8p pRawdata = *ppRawdata; + + if ((iRawlen % 2) != 0) /* check the length */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + pDISC->iCount = (iRawlen / sizeof (mng_uint16)); + + if (pDISC->iCount) + { + MNG_ALLOC (pData, pDISC->pObjectids, iRawlen); + +#ifndef MNG_BIGENDIAN_SUPPORTED + { + mng_uint32 iX; + mng_uint8p pIn = pRawdata; + mng_uint16p pOut = pDISC->pObjectids; + + for (iX = pDISC->iCount; iX > 0; iX--) + { + *pOut++ = mng_get_uint16 (pIn); + pIn += 2; + } + } +#else + MNG_COPY (pDISC->pObjectids, pRawdata, iRawlen); +#endif /* !MNG_BIGENDIAN_SUPPORTED */ + } + + *piRawlen = 0; + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DISC +MNG_C_SPECIALFUNC (mng_special_disc) +{ +#ifdef MNG_SUPPORT_DISPLAY + return mng_create_ani_disc (pData, pChunk); +#else + return MNG_NOERROR; +#endif /* MNG_SUPPORT_DISPLAY */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_BACK +MNG_C_SPECIALFUNC (mng_special_back) +{ +#ifdef MNG_SUPPORT_DISPLAY + /* retrieve the fields */ + pData->bHasBACK = MNG_TRUE; + pData->iBACKred = ((mng_backp)pChunk)->iRed; + pData->iBACKgreen = ((mng_backp)pChunk)->iGreen; + pData->iBACKblue = ((mng_backp)pChunk)->iBlue; + pData->iBACKmandatory = ((mng_backp)pChunk)->iMandatory; + pData->iBACKimageid = ((mng_backp)pChunk)->iImageid; + pData->iBACKtile = ((mng_backp)pChunk)->iTile; + + return mng_create_ani_back (pData); +#else + return MNG_NOERROR; +#endif /* MNG_SUPPORT_DISPLAY */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_FRAM +MNG_F_SPECIALFUNC (mng_fram_remainder) +{ + mng_framp pFRAM = (mng_framp)pChunk; + mng_uint32 iRawlen = *piRawlen; + mng_uint8p pRawdata = *ppRawdata; + mng_uint32 iRequired = 0; + + if (iRawlen < 4) /* must have at least 4 bytes */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + iRequired = 4; /* calculate and check required remaining length */ + + pFRAM->iChangedelay = *pRawdata; + pFRAM->iChangetimeout = *(pRawdata+1); + pFRAM->iChangeclipping = *(pRawdata+2); + pFRAM->iChangesyncid = *(pRawdata+3); + + if (pFRAM->iChangedelay ) { iRequired += 4; } + if (pFRAM->iChangetimeout ) { iRequired += 4; } + if (pFRAM->iChangeclipping) { iRequired += 17; } + + if (pFRAM->iChangesyncid) + { + if ((iRawlen - iRequired) % 4 != 0) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + else + { + if (iRawlen != iRequired) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + + pRawdata += 4; + + if (pFRAM->iChangedelay) /* delay changed ? */ + { + pFRAM->iDelay = mng_get_uint32 (pRawdata); + pRawdata += 4; + } + + if (pFRAM->iChangetimeout) /* timeout changed ? */ + { + pFRAM->iTimeout = mng_get_uint32 (pRawdata); + pRawdata += 4; + } + + if (pFRAM->iChangeclipping) /* clipping changed ? */ + { + pFRAM->iBoundarytype = *pRawdata; + pFRAM->iBoundaryl = mng_get_int32 (pRawdata+1); + pFRAM->iBoundaryr = mng_get_int32 (pRawdata+5); + pFRAM->iBoundaryt = mng_get_int32 (pRawdata+9); + pFRAM->iBoundaryb = mng_get_int32 (pRawdata+13); + pRawdata += 17; + } + + if (pFRAM->iChangesyncid) + { + pFRAM->iCount = (iRawlen - iRequired) / 4; + + if (pFRAM->iCount) + { + MNG_ALLOC (pData, pFRAM->pSyncids, pFRAM->iCount * 4); + +#ifndef MNG_BIGENDIAN_SUPPORTED + { + mng_uint32 iX; + mng_uint32p pOut = pFRAM->pSyncids; + + for (iX = pFRAM->iCount; iX > 0; iX--) + { + *pOut++ = mng_get_uint32 (pRawdata); + pRawdata += 4; + } + } +#else + MNG_COPY (pFRAM->pSyncids, pRawdata, pFRAM->iCount * 4); +#endif /* !MNG_BIGENDIAN_SUPPORTED */ + } + } + +#ifndef MNG_NO_OLD_VERSIONS + if (pData->bPreDraft48) /* old style input-stream ? */ + { + switch (pFRAM->iMode) /* fix the framing mode then */ + { + case 0: { break; } + case 1: { pFRAM->iMode = 3; break; } + case 2: { pFRAM->iMode = 4; break; } + case 3: { pFRAM->iMode = 1; break; } + case 4: { pFRAM->iMode = 1; break; } + case 5: { pFRAM->iMode = 2; break; } + default: { pFRAM->iMode = 1; break; } + } + } +#endif + + *piRawlen = 0; + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_FRAM +MNG_C_SPECIALFUNC (mng_special_fram) +{ +#ifdef MNG_SUPPORT_DISPLAY + return mng_create_ani_fram (pData, pChunk); +#else + return MNG_NOERROR; +#endif /* MNG_SUPPORT_DISPLAY */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MOVE +MNG_C_SPECIALFUNC (mng_special_move) +{ +#ifdef MNG_SUPPORT_DISPLAY + return mng_create_ani_move (pData, pChunk); +#else + return MNG_NOERROR; +#endif /* MNG_SUPPORT_DISPLAY */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_CLIP +MNG_C_SPECIALFUNC (mng_special_clip) +{ +#ifdef MNG_SUPPORT_DISPLAY + return mng_create_ani_clip (pData, pChunk); +#else + return MNG_NOERROR; +#endif /* MNG_SUPPORT_DISPLAY */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SHOW +MNG_C_SPECIALFUNC (mng_special_show) +{ +#ifdef MNG_SUPPORT_DISPLAY + mng_retcode iRetcode; + + if (!((mng_showp)pChunk)->bEmpty) /* any data ? */ + { + if (!((mng_showp)pChunk)->bHaslastid) + ((mng_showp)pChunk)->iLastid = ((mng_showp)pChunk)->iFirstid; + + pData->iSHOWfromid = ((mng_showp)pChunk)->iFirstid; + pData->iSHOWtoid = ((mng_showp)pChunk)->iLastid; + pData->iSHOWmode = ((mng_showp)pChunk)->iMode; + } + else /* use defaults then */ + { + pData->iSHOWfromid = 1; + pData->iSHOWtoid = 65535; + pData->iSHOWmode = 2; + } + /* create a SHOW animation object */ + iRetcode = mng_create_ani_show (pData); + if (!iRetcode) /* go and do it! */ + iRetcode = mng_process_display_show (pData); + +#endif /* MNG_SUPPORT_DISPLAY */ + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_TERM +MNG_C_SPECIALFUNC (mng_special_term) +{ + /* should be behind MHDR or SAVE !! */ + if ((!pData->bHasSAVE) && (pData->iChunkseq > 2)) + { + pData->bMisplacedTERM = MNG_TRUE; /* indicate we found a misplaced TERM */ + /* and send a warning signal!!! */ + MNG_WARNING (pData, MNG_SEQUENCEERROR); + } + + pData->bHasTERM = MNG_TRUE; + + if (pData->fProcessterm) /* inform the app ? */ + if (!pData->fProcessterm (((mng_handle)pData), + ((mng_termp)pChunk)->iTermaction, + ((mng_termp)pChunk)->iIteraction, + ((mng_termp)pChunk)->iDelay, + ((mng_termp)pChunk)->iItermax)) + MNG_ERROR (pData, MNG_APPMISCERROR); + +#ifdef MNG_SUPPORT_DISPLAY + { /* create the TERM ani-object */ + mng_retcode iRetcode = mng_create_ani_term (pData, pChunk); + if (iRetcode) /* on error bail out */ + return iRetcode; + /* save for future reference */ + pData->pTermaniobj = pData->pLastaniobj; + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SAVE +MNG_F_SPECIALFUNC (mng_save_entries) +{ + mng_savep pSAVE = (mng_savep)pChunk; + mng_uint32 iRawlen = *piRawlen; + mng_uint8p pRawdata = *ppRawdata; + mng_save_entryp pEntry = MNG_NULL; + mng_uint32 iCount = 0; + mng_uint8 iOtype = *pRawdata; + mng_uint8 iEtype; + mng_uint8p pTemp; + mng_uint8p pNull; + mng_uint32 iLen; + mng_uint32 iOffset[2]; + mng_uint32 iStarttime[2]; + mng_uint32 iFramenr; + mng_uint32 iLayernr; + mng_uint32 iX; + mng_uint32 iNamesize; + + if ((iOtype != 4) && (iOtype != 8)) + MNG_ERROR (pData, MNG_INVOFFSETSIZE); + + pSAVE->iOffsettype = iOtype; + + for (iX = 0; iX < 2; iX++) /* do this twice to get the count first ! */ + { + pTemp = pRawdata + 1; + iLen = iRawlen - 1; + + if (iX) /* second run ? */ + { + MNG_ALLOC (pData, pEntry, (iCount * sizeof (mng_save_entry))); + + pSAVE->iCount = iCount; + pSAVE->pEntries = pEntry; + } + + while (iLen) /* anything left ? */ + { + iEtype = *pTemp; /* entrytype */ + + if ((iEtype != 0) && (iEtype != 1) && (iEtype != 2) && (iEtype != 3)) + MNG_ERROR (pData, MNG_INVENTRYTYPE); + + pTemp++; + + if (iEtype > 1) + { + iOffset [0] = 0; + iOffset [1] = 0; + iStarttime [0] = 0; + iStarttime [1] = 0; + iLayernr = 0; + iFramenr = 0; + } + else + { + if (iOtype == 4) + { + iOffset [0] = 0; + iOffset [1] = mng_get_uint32 (pTemp); + + pTemp += 4; + } + else + { + iOffset [0] = mng_get_uint32 (pTemp); + iOffset [1] = mng_get_uint32 (pTemp+4); + + pTemp += 8; + } + + if (iEtype > 0) + { + iStarttime [0] = 0; + iStarttime [1] = 0; + iLayernr = 0; + iFramenr = 0; + } + else + { + if (iOtype == 4) + { + iStarttime [0] = 0; + iStarttime [1] = mng_get_uint32 (pTemp+0); + iLayernr = mng_get_uint32 (pTemp+4); + iFramenr = mng_get_uint32 (pTemp+8); + + pTemp += 12; + } + else + { + iStarttime [0] = mng_get_uint32 (pTemp+0); + iStarttime [1] = mng_get_uint32 (pTemp+4); + iLayernr = mng_get_uint32 (pTemp+8); + iFramenr = mng_get_uint32 (pTemp+12); + + pTemp += 16; + } + } + } + + pNull = pTemp; /* get the name length */ + while (*pNull) + pNull++; + + if ((pNull - pRawdata) > (mng_int32)iRawlen) + { + iNamesize = iLen; /* no null found; so end of SAVE */ + iLen = 0; + } + else + { + iNamesize = pNull - pTemp; /* should be another entry */ + iLen -= iNamesize; + + if (!iLen) /* must not end with a null ! */ + MNG_ERROR (pData, MNG_ENDWITHNULL); + } + + if (!pEntry) + { + iCount++; + } + else + { + pEntry->iEntrytype = iEtype; + pEntry->iOffset [0] = iOffset [0]; + pEntry->iOffset [1] = iOffset [1]; + pEntry->iStarttime [0] = iStarttime [0]; + pEntry->iStarttime [1] = iStarttime [1]; + pEntry->iLayernr = iLayernr; + pEntry->iFramenr = iFramenr; + pEntry->iNamesize = iNamesize; + + if (iNamesize) + { + MNG_ALLOC (pData, pEntry->zName, iNamesize+1); + MNG_COPY (pEntry->zName, pTemp, iNamesize); + } + + pEntry++; + } + + pTemp += iNamesize; + } + } + + *piRawlen = 0; + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SAVE +MNG_C_SPECIALFUNC (mng_special_save) +{ + pData->bHasSAVE = MNG_TRUE; + + if (pData->fProcesssave) /* inform the application ? */ + { + mng_bool bOke = pData->fProcesssave ((mng_handle)pData); + if (!bOke) + MNG_ERROR (pData, MNG_APPMISCERROR); + } + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode; + + /* TODO: something with the parameters */ + + /* create a SAVE animation object */ + iRetcode = mng_create_ani_save (pData); + if (!iRetcode) /* process it */ + iRetcode = mng_process_display_save (pData); + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SEEK +MNG_C_SPECIALFUNC (mng_special_seek) +{ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_DISPLAY + /* create a SEEK animation object */ + iRetcode = mng_create_ani_seek (pData, pChunk); + if (iRetcode) /* on error bail out */ + return iRetcode; + +#endif /* MNG_SUPPORT_DISPLAY */ + + if (pData->fProcessseek) /* inform the app ? */ + if (!pData->fProcessseek ((mng_handle)pData, ((mng_seekp)pChunk)->zName)) + MNG_ERROR (pData, MNG_APPMISCERROR); + +#ifdef MNG_SUPPORT_DISPLAY + return mng_process_display_seek (pData); +#else + return MNG_NOERROR; +#endif /* MNG_SUPPORT_DISPLAY */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_eXPI +MNG_C_SPECIALFUNC (mng_special_expi) +{ +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_fPRI +MNG_C_SPECIALFUNC (mng_special_fpri) +{ +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_nEED +MNG_LOCAL mng_bool CheckKeyword (mng_datap pData, + mng_uint8p pKeyword) +{ + mng_chunkid handled_chunks [] = + { + MNG_UINT_BACK, /* keep it sorted !!!! */ + MNG_UINT_BASI, + MNG_UINT_CLIP, + MNG_UINT_CLON, +#ifndef MNG_NO_DELTA_PNG +/* TODO: MNG_UINT_DBYK, */ +#endif + MNG_UINT_DEFI, +#ifndef MNG_NO_DELTA_PNG + MNG_UINT_DHDR, +#endif + MNG_UINT_DISC, +#ifndef MNG_NO_DELTA_PNG +/* TODO: MNG_UINT_DROP, */ +#endif + MNG_UINT_ENDL, + MNG_UINT_FRAM, + MNG_UINT_IDAT, + MNG_UINT_IEND, + MNG_UINT_IHDR, +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG + MNG_UINT_IJNG, +#endif + MNG_UINT_IPNG, +#endif +#ifdef MNG_INCLUDE_JNG + MNG_UINT_JDAA, + MNG_UINT_JDAT, + MNG_UINT_JHDR, +/* TODO: MNG_UINT_JSEP, */ + MNG_UINT_JdAA, +#endif + MNG_UINT_LOOP, + MNG_UINT_MAGN, + MNG_UINT_MEND, + MNG_UINT_MHDR, + MNG_UINT_MOVE, +/* TODO: MNG_UINT_ORDR, */ + MNG_UINT_PAST, + MNG_UINT_PLTE, +#ifndef MNG_NO_DELTA_PNG + MNG_UINT_PPLT, + MNG_UINT_PROM, +#endif + MNG_UINT_SAVE, + MNG_UINT_SEEK, + MNG_UINT_SHOW, + MNG_UINT_TERM, + MNG_UINT_bKGD, + MNG_UINT_cHRM, +/* TODO: MNG_UINT_eXPI, */ + MNG_UINT_evNT, +/* TODO: MNG_UINT_fPRI, */ + MNG_UINT_gAMA, +/* TODO: MNG_UINT_hIST, */ + MNG_UINT_iCCP, + MNG_UINT_iTXt, + MNG_UINT_nEED, +/* TODO: MNG_UINT_oFFs, */ +/* TODO: MNG_UINT_pCAL, */ +/* TODO: MNG_UINT_pHYg, */ +/* TODO: MNG_UINT_pHYs, */ +/* TODO: MNG_UINT_sBIT, */ +/* TODO: MNG_UINT_sCAL, */ +/* TODO: MNG_UINT_sPLT, */ + MNG_UINT_sRGB, + MNG_UINT_tEXt, + MNG_UINT_tIME, + MNG_UINT_tRNS, + MNG_UINT_zTXt, + }; + + mng_bool bOke = MNG_FALSE; + + if (pData->fProcessneed) /* does the app handle it ? */ + bOke = pData->fProcessneed ((mng_handle)pData, (mng_pchar)pKeyword); + + if (!bOke) + { /* find the keyword length */ + mng_uint8p pNull = pKeyword; + while (*pNull) + pNull++; + + if ((pNull - pKeyword) == 4) /* test a chunk ? */ + { /* get the chunk-id */ + mng_chunkid iChunkid = (*pKeyword << 24) + (*(pKeyword+1) << 16) + + (*(pKeyword+2) << 8) + (*(pKeyword+3) ); + /* binary search variables */ + mng_int32 iTop, iLower, iUpper, iMiddle; + /* determine max index of table */ + iTop = (sizeof (handled_chunks) / sizeof (handled_chunks [0])) - 1; + + /* binary search; with 52 chunks, worst-case is 7 comparisons */ + iLower = 0; + iMiddle = iTop >> 1; + iUpper = iTop; + + do /* the binary search itself */ + { + if (handled_chunks [iMiddle] < iChunkid) + iLower = iMiddle + 1; + else if (handled_chunks [iMiddle] > iChunkid) + iUpper = iMiddle - 1; + else + { + bOke = MNG_TRUE; + break; + } + + iMiddle = (iLower + iUpper) >> 1; + } + while (iLower <= iUpper); + } + /* test draft ? */ + if ((!bOke) && ((pNull - pKeyword) == 8) && + (*pKeyword == 'd') && (*(pKeyword+1) == 'r') && + (*(pKeyword+2) == 'a') && (*(pKeyword+3) == 'f') && + (*(pKeyword+4) == 't') && (*(pKeyword+5) == ' ')) + { + mng_uint32 iDraft; + + iDraft = (*(pKeyword+6) - '0') * 10 + (*(pKeyword+7) - '0'); + bOke = (mng_bool)(iDraft <= MNG_MNG_DRAFT); + } + /* test MNG 1.0/1.1 ? */ + if ((!bOke) && ((pNull - pKeyword) == 7) && + (*pKeyword == 'M') && (*(pKeyword+1) == 'N') && + (*(pKeyword+2) == 'G') && (*(pKeyword+3) == '-') && + (*(pKeyword+4) == '1') && (*(pKeyword+5) == '.') && + ((*(pKeyword+6) == '0') || (*(pKeyword+6) == '1'))) + bOke = MNG_TRUE; + /* test CACHEOFF ? */ + if ((!bOke) && ((pNull - pKeyword) == 8) && + (*pKeyword == 'C') && (*(pKeyword+1) == 'A') && + (*(pKeyword+2) == 'C') && (*(pKeyword+3) == 'H') && + (*(pKeyword+4) == 'E') && (*(pKeyword+5) == 'O') && + (*(pKeyword+6) == 'F') && (*(pKeyword+7) == 'F')) + { + if (!pData->pFirstaniobj) /* only if caching hasn't started yet ! */ + { + bOke = MNG_TRUE; + pData->bCacheplayback = MNG_FALSE; + pData->bStorechunks = MNG_FALSE; + } + } + } + + return bOke; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_nEED +MNG_C_SPECIALFUNC (mng_special_need) +{ + /* let's check it */ + mng_bool bOke = MNG_TRUE; + mng_uint8p pNull, pTemp, pMax; + + pTemp = (mng_uint8p)((mng_needp)pChunk)->zKeywords; + pMax = (mng_uint8p)(pTemp + ((mng_needp)pChunk)->iKeywordssize); + pNull = pTemp; + while (*pNull) + pNull++; + + while ((bOke) && (pNull < pMax)) + { + bOke = CheckKeyword (pData, pTemp); + pTemp = pNull + 1; + pNull = pTemp; + while (*pNull) + pNull++; + } + + if (bOke) + bOke = CheckKeyword (pData, pTemp); + + if (!bOke) + MNG_ERROR (pData, MNG_UNSUPPORTEDNEED); + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_pHYg +MNG_C_SPECIALFUNC (mng_special_phyg) +{ +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +MNG_C_SPECIALFUNC (mng_special_dhdr) +{ + if ((((mng_dhdrp)pChunk)->iDeltatype == MNG_DELTATYPE_REPLACE) && (((mng_dhdrp)pChunk)->bHasblockloc)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + if ((((mng_dhdrp)pChunk)->iDeltatype == MNG_DELTATYPE_NOCHANGE) && (((mng_dhdrp)pChunk)->bHasblocksize)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + pData->bHasDHDR = MNG_TRUE; /* inside a DHDR-IEND block now */ + pData->iDeltatype = ((mng_dhdrp)pChunk)->iDeltatype; + + pData->iImagelevel++; /* one level deeper */ + +#ifdef MNG_SUPPORT_DISPLAY + return mng_create_ani_dhdr (pData, pChunk); +#else + return MNG_NOERROR; +#endif /* MNG_SUPPORT_DISPLAY */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +MNG_C_SPECIALFUNC (mng_special_prom) +{ + if ((((mng_promp)pChunk)->iColortype != MNG_COLORTYPE_GRAY ) && + (((mng_promp)pChunk)->iColortype != MNG_COLORTYPE_RGB ) && + (((mng_promp)pChunk)->iColortype != MNG_COLORTYPE_INDEXED) && + (((mng_promp)pChunk)->iColortype != MNG_COLORTYPE_GRAYA ) && + (((mng_promp)pChunk)->iColortype != MNG_COLORTYPE_RGBA ) ) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + +#ifdef MNG_NO_16BIT_SUPPORT + if (((mng_promp)pChunk)->iSampledepth == MNG_BITDEPTH_16 ) + ((mng_promp)pChunk)->iSampledepth = MNG_BITDEPTH_8; +#endif + + if ((((mng_promp)pChunk)->iSampledepth != MNG_BITDEPTH_1 ) && + (((mng_promp)pChunk)->iSampledepth != MNG_BITDEPTH_2 ) && + (((mng_promp)pChunk)->iSampledepth != MNG_BITDEPTH_4 ) && + (((mng_promp)pChunk)->iSampledepth != MNG_BITDEPTH_8 ) +#ifndef MNG_NO_16BIT_SUPPORT + && (((mng_promp)pChunk)->iSampledepth != MNG_BITDEPTH_16) +#endif + ) + MNG_ERROR (pData, MNG_INVSAMPLEDEPTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode = mng_create_ani_prom (pData, pChunk); + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +MNG_C_SPECIALFUNC (mng_special_ipng) +{ +#ifdef MNG_SUPPORT_DISPLAY + mng_retcode iRetcode = mng_create_ani_ipng (pData); + if (!iRetcode) /* process it */ + iRetcode = mng_process_display_ipng (pData); + if (iRetcode) /* on error bail out */ + return iRetcode; +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +MNG_F_SPECIALFUNC (mng_pplt_entries) +{ + mng_ppltp pPPLT = (mng_ppltp)pChunk; + mng_uint32 iRawlen = *piRawlen; + mng_uint8p pRawdata = *ppRawdata; + mng_uint8 iDeltatype = pPPLT->iDeltatype; + mng_uint32 iMax = 0; + mng_int32 iX, iY, iM; + mng_rgbpaltab aIndexentries; + mng_uint8arr aAlphaentries; + mng_uint8arr aUsedentries; + /* must be indexed color ! */ + if (pData->iColortype != MNG_COLORTYPE_INDEXED) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + + for (iY = 255; iY >= 0; iY--) /* reset arrays */ + { + aIndexentries [iY].iRed = 0; + aIndexentries [iY].iGreen = 0; + aIndexentries [iY].iBlue = 0; + aAlphaentries [iY] = 255; + aUsedentries [iY] = 0; + } + + while (iRawlen) /* as long as there are entries left ... */ + { + mng_uint32 iDiff; + + if (iRawlen < 2) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + iX = (mng_int32)(*pRawdata); /* get start and end index */ + iM = (mng_int32)(*(pRawdata+1)); + + if (iM < iX) + MNG_ERROR (pData, MNG_INVALIDINDEX); + + if (iM >= (mng_int32) iMax) /* determine highest used index */ + iMax = iM + 1; + + pRawdata += 2; + iRawlen -= 2; + iDiff = (iM - iX + 1); + if ((iDeltatype == MNG_DELTATYPE_REPLACERGB ) || + (iDeltatype == MNG_DELTATYPE_DELTARGB ) ) + iDiff = iDiff * 3; + else + if ((iDeltatype == MNG_DELTATYPE_REPLACERGBA) || + (iDeltatype == MNG_DELTATYPE_DELTARGBA ) ) + iDiff = iDiff * 4; + + if (iRawlen < iDiff) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((iDeltatype == MNG_DELTATYPE_REPLACERGB ) || + (iDeltatype == MNG_DELTATYPE_DELTARGB ) ) + { + for (iY = iX; iY <= iM; iY++) + { + aIndexentries [iY].iRed = *pRawdata; + aIndexentries [iY].iGreen = *(pRawdata+1); + aIndexentries [iY].iBlue = *(pRawdata+2); + aUsedentries [iY] = 1; + + pRawdata += 3; + iRawlen -= 3; + } + } + else + if ((iDeltatype == MNG_DELTATYPE_REPLACEALPHA) || + (iDeltatype == MNG_DELTATYPE_DELTAALPHA ) ) + { + for (iY = iX; iY <= iM; iY++) + { + aAlphaentries [iY] = *pRawdata; + aUsedentries [iY] = 1; + + pRawdata++; + iRawlen--; + } + } + else + { + for (iY = iX; iY <= iM; iY++) + { + aIndexentries [iY].iRed = *pRawdata; + aIndexentries [iY].iGreen = *(pRawdata+1); + aIndexentries [iY].iBlue = *(pRawdata+2); + aAlphaentries [iY] = *(pRawdata+3); + aUsedentries [iY] = 1; + + pRawdata += 4; + iRawlen -= 4; + } + } + } + + switch (pData->iBitdepth) /* check maximum allowed entries for bitdepth */ + { + case MNG_BITDEPTH_1 : { + if (iMax > 2) + MNG_ERROR (pData, MNG_INVALIDINDEX); + break; + } + case MNG_BITDEPTH_2 : { + if (iMax > 4) + MNG_ERROR (pData, MNG_INVALIDINDEX); + break; + } + case MNG_BITDEPTH_4 : { + if (iMax > 16) + MNG_ERROR (pData, MNG_INVALIDINDEX); + break; + } + } + + pPPLT->iCount = iMax; + + for (iY = 255; iY >= 0; iY--) + { + pPPLT->aEntries [iY].iRed = aIndexentries [iY].iRed; + pPPLT->aEntries [iY].iGreen = aIndexentries [iY].iGreen; + pPPLT->aEntries [iY].iBlue = aIndexentries [iY].iBlue; + pPPLT->aEntries [iY].iAlpha = aAlphaentries [iY]; + pPPLT->aEntries [iY].bUsed = (mng_bool)(aUsedentries [iY]); + } + + { /* create animation object */ + mng_retcode iRetcode = mng_create_ani_pplt (pData, iDeltatype, iMax, + aIndexentries, aAlphaentries, + aUsedentries); + if (iRetcode) + return iRetcode; + } + + *piRawlen = 0; + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +MNG_C_SPECIALFUNC (mng_special_pplt) +{ + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG +MNG_C_SPECIALFUNC (mng_special_ijng) +{ +#ifdef MNG_SUPPORT_DISPLAY + mng_retcode iRetcode = mng_create_ani_ijng (pData); + if (!iRetcode) /* process it */ + iRetcode = mng_process_display_ijng (pData); + return iRetcode; +#else + return MNG_NOERROR; /* done */ +#endif /* MNG_SUPPORT_DISPLAY */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +MNG_F_SPECIALFUNC (mng_drop_entries) +{ + mng_dropp pDROP = (mng_dropp)pChunk; + mng_uint32 iRawlen = *piRawlen; + mng_uint8p pRawdata = *ppRawdata; + mng_uint32 iX; + mng_uint32p pEntry; + /* check length */ + if ((iRawlen < 4) || ((iRawlen % 4) != 0)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + MNG_ALLOC (pData, pEntry, iRawlen); + pDROP->iCount = iRawlen / 4; + pDROP->pChunknames = (mng_ptr)pEntry; + + for (iX = pDROP->iCount; iX > 0; iX--) + { + *pEntry++ = mng_get_uint32 (pRawdata); + pRawdata += 4; + } + + *piRawlen = 0; + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +MNG_C_SPECIALFUNC (mng_special_drop) +{ +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DBYK +MNG_C_SPECIALFUNC (mng_special_dbyk) +{ +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR +MNG_F_SPECIALFUNC (mng_ordr_entries) +{ + mng_ordrp pORDR = (mng_ordrp)pChunk; + mng_uint32 iRawlen = *piRawlen; + mng_uint8p pRawdata = *ppRawdata; + mng_uint32 iX; + mng_ordr_entryp pEntry; + /* check length */ + if ((iRawlen < 5) || ((iRawlen % 5) != 0)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + MNG_ALLOC (pData, pEntry, iRawlen); + pORDR->iCount = iRawlen / 5; + pORDR->pEntries = (mng_ptr)pEntry; + + for (iX = pORDR->iCount; iX > 0; iX--) + { + pEntry->iChunkname = mng_get_uint32 (pRawdata); + pEntry->iOrdertype = *(pRawdata+4); + pEntry++; + pRawdata += 5; + } + + *piRawlen = 0; + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR +MNG_C_SPECIALFUNC (mng_special_ordr) +{ +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MAGN +MNG_F_SPECIALFUNC (mng_debunk_magn) +{ + mng_magnp pMAGN = (mng_magnp)pChunk; + mng_uint32 iRawlen = *piRawlen; + mng_uint8p pRawdata = *ppRawdata; + mng_bool bFaulty; + /* check length */ + if (iRawlen > 20) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + /* following is an ugly hack to allow faulty layout caused by previous + versions of libmng and MNGeye, which wrote MAGN with a 16-bit + MethodX/MethodY (as opposed to the proper 8-bit as defined in the spec!) */ + + if ((iRawlen == 6) || (iRawlen == 8) || (iRawlen == 10) || (iRawlen == 12) || + (iRawlen == 14) || (iRawlen == 16) || (iRawlen == 20)) + bFaulty = MNG_TRUE; /* these lengths are all wrong */ + else /* length 18 can be right or wrong !!! */ + if ((iRawlen == 18) && (mng_get_uint16 (pRawdata+4) <= 5) && + (mng_get_uint16 (pRawdata+6) < 256) && + (mng_get_uint16 (pRawdata+8) < 256) && + (mng_get_uint16 (pRawdata+10) < 256) && + (mng_get_uint16 (pRawdata+12) < 256) && + (mng_get_uint16 (pRawdata+14) < 256) && + (mng_get_uint16 (pRawdata+16) < 256)) + bFaulty = MNG_TRUE; /* this is very likely the wrong layout */ + else + bFaulty = MNG_FALSE; /* all other cases are handled as right */ + + if (bFaulty) /* wrong layout ? */ + { + if (iRawlen > 0) /* get the fields */ + pMAGN->iFirstid = mng_get_uint16 (pRawdata); + else + pMAGN->iFirstid = 0; + + if (iRawlen > 2) + pMAGN->iLastid = mng_get_uint16 (pRawdata+2); + else + pMAGN->iLastid = pMAGN->iFirstid; + + if (iRawlen > 4) + pMAGN->iMethodX = (mng_uint8)(mng_get_uint16 (pRawdata+4)); + else + pMAGN->iMethodX = 0; + + if (iRawlen > 6) + pMAGN->iMX = mng_get_uint16 (pRawdata+6); + else + pMAGN->iMX = 1; + + if (iRawlen > 8) + pMAGN->iMY = mng_get_uint16 (pRawdata+8); + else + pMAGN->iMY = pMAGN->iMX; + + if (iRawlen > 10) + pMAGN->iML = mng_get_uint16 (pRawdata+10); + else + pMAGN->iML = pMAGN->iMX; + + if (iRawlen > 12) + pMAGN->iMR = mng_get_uint16 (pRawdata+12); + else + pMAGN->iMR = pMAGN->iMX; + + if (iRawlen > 14) + pMAGN->iMT = mng_get_uint16 (pRawdata+14); + else + pMAGN->iMT = pMAGN->iMY; + + if (iRawlen > 16) + pMAGN->iMB = mng_get_uint16 (pRawdata+16); + else + pMAGN->iMB = pMAGN->iMY; + + if (iRawlen > 18) + pMAGN->iMethodY = (mng_uint8)(mng_get_uint16 (pRawdata+18)); + else + pMAGN->iMethodY = pMAGN->iMethodX; + } + else /* proper layout !!!! */ + { + if (iRawlen > 0) /* get the fields */ + pMAGN->iFirstid = mng_get_uint16 (pRawdata); + else + pMAGN->iFirstid = 0; + + if (iRawlen > 2) + pMAGN->iLastid = mng_get_uint16 (pRawdata+2); + else + pMAGN->iLastid = pMAGN->iFirstid; + + if (iRawlen > 4) + pMAGN->iMethodX = *(pRawdata+4); + else + pMAGN->iMethodX = 0; + + if (iRawlen > 5) + pMAGN->iMX = mng_get_uint16 (pRawdata+5); + else + pMAGN->iMX = 1; + + if (iRawlen > 7) + pMAGN->iMY = mng_get_uint16 (pRawdata+7); + else + pMAGN->iMY = pMAGN->iMX; + + if (iRawlen > 9) + pMAGN->iML = mng_get_uint16 (pRawdata+9); + else + pMAGN->iML = pMAGN->iMX; + + if (iRawlen > 11) + pMAGN->iMR = mng_get_uint16 (pRawdata+11); + else + pMAGN->iMR = pMAGN->iMX; + + if (iRawlen > 13) + pMAGN->iMT = mng_get_uint16 (pRawdata+13); + else + pMAGN->iMT = pMAGN->iMY; + + if (iRawlen > 15) + pMAGN->iMB = mng_get_uint16 (pRawdata+15); + else + pMAGN->iMB = pMAGN->iMY; + + if (iRawlen > 17) + pMAGN->iMethodY = *(pRawdata+17); + else + pMAGN->iMethodY = pMAGN->iMethodX; + } + /* check field validity */ + if ((pMAGN->iMethodX > 5) || (pMAGN->iMethodY > 5)) + MNG_ERROR (pData, MNG_INVALIDMETHOD); + + *piRawlen = 0; + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MAGN +MNG_C_SPECIALFUNC (mng_special_magn) +{ +#ifdef MNG_SUPPORT_DISPLAY + return mng_create_ani_magn (pData, pChunk); +#else + return MNG_NOERROR; +#endif /* MNG_SUPPORT_DISPLAY */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_evNT +MNG_F_SPECIALFUNC (mng_evnt_entries) +{ + mng_evntp pEVNT = (mng_evntp)pChunk; + mng_uint32 iRawlen; + mng_uint8p pRawdata; +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_SUPPORT_DYNAMICMNG) + mng_retcode iRetcode; +#endif + mng_uint8p pNull; + mng_uint8 iEventtype; + mng_uint8 iMasktype; + mng_int32 iLeft; + mng_int32 iRight; + mng_int32 iTop; + mng_int32 iBottom; + mng_uint16 iObjectid; + mng_uint8 iIndex; + mng_uint32 iNamesize; + mng_uint32 iCount = 0; + mng_evnt_entryp pEntry = MNG_NULL; + mng_uint32 iX; + + for (iX = 0; iX < 2; iX++) + { + iRawlen = *piRawlen; + pRawdata = *ppRawdata; + + if (iX) /* second run ? */ + { + MNG_ALLOC (pData, pEntry, (iCount * sizeof (mng_evnt_entry))); + pEVNT->iCount = iCount; + pEVNT->pEntries = pEntry; + } + + while (iRawlen) /* anything left ? */ + { + if (iRawlen < 2) /* must have at least 2 bytes ! */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + iEventtype = *pRawdata; /* eventtype */ + if (iEventtype > 5) + MNG_ERROR (pData, MNG_INVALIDEVENT); + + pRawdata++; + + iMasktype = *pRawdata; /* masktype */ + if (iMasktype > 5) + MNG_ERROR (pData, MNG_INVALIDMASK); + + pRawdata++; + iRawlen -= 2; + + iLeft = 0; + iRight = 0; + iTop = 0; + iBottom = 0; + iObjectid = 0; + iIndex = 0; + + switch (iMasktype) + { + case 1 : + { + if (iRawlen > 16) + { + iLeft = mng_get_int32 (pRawdata); + iRight = mng_get_int32 (pRawdata+4); + iTop = mng_get_int32 (pRawdata+8); + iBottom = mng_get_int32 (pRawdata+12); + pRawdata += 16; + iRawlen -= 16; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + case 2 : + { + if (iRawlen > 2) + { + iObjectid = mng_get_uint16 (pRawdata); + pRawdata += 2; + iRawlen -= 2; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + case 3 : + { + if (iRawlen > 3) + { + iObjectid = mng_get_uint16 (pRawdata); + iIndex = *(pRawdata+2); + pRawdata += 3; + iRawlen -= 3; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + case 4 : + { + if (iRawlen > 18) + { + iLeft = mng_get_int32 (pRawdata); + iRight = mng_get_int32 (pRawdata+4); + iTop = mng_get_int32 (pRawdata+8); + iBottom = mng_get_int32 (pRawdata+12); + iObjectid = mng_get_uint16 (pRawdata+16); + pRawdata += 18; + iRawlen -= 18; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + case 5 : + { + if (iRawlen > 19) + { + iLeft = mng_get_int32 (pRawdata); + iRight = mng_get_int32 (pRawdata+4); + iTop = mng_get_int32 (pRawdata+8); + iBottom = mng_get_int32 (pRawdata+12); + iObjectid = mng_get_uint16 (pRawdata+16); + iIndex = *(pRawdata+18); + pRawdata += 19; + iRawlen -= 19; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + } + + pNull = pRawdata; /* get the name length */ + while (*pNull) + pNull++; + + if ((pNull - pRawdata) > (mng_int32)iRawlen) + { + iNamesize = iRawlen; /* no null found; so end of evNT */ + iRawlen = 0; + } + else + { + iNamesize = pNull - pRawdata; /* should be another entry */ + iRawlen = iRawlen - iNamesize - 1; + + if (!iRawlen) /* must not end with a null ! */ + MNG_ERROR (pData, MNG_ENDWITHNULL); + } + + if (!iX) + { + iCount++; + } + else + { + pEntry->iEventtype = iEventtype; + pEntry->iMasktype = iMasktype; + pEntry->iLeft = iLeft; + pEntry->iRight = iRight; + pEntry->iTop = iTop; + pEntry->iBottom = iBottom; + pEntry->iObjectid = iObjectid; + pEntry->iIndex = iIndex; + pEntry->iSegmentnamesize = iNamesize; + + if (iNamesize) + { + MNG_ALLOC (pData, pEntry->zSegmentname, iNamesize+1); + MNG_COPY (pEntry->zSegmentname, pRawdata, iNamesize); + } + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_SUPPORT_DYNAMICMNG) + iRetcode = mng_create_event (pData, (mng_ptr)pEntry); + if (iRetcode) /* on error bail out */ + return iRetcode; +#endif + + pEntry++; + } + + pRawdata = pRawdata + iNamesize + 1; + } + } + + *piRawlen = 0; + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_evNT +MNG_C_SPECIALFUNC (mng_special_evnt) +{ + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_MPNG_PROPOSAL +MNG_C_SPECIALFUNC (mng_special_mpng) +{ + if ((pData->eImagetype != mng_it_png) && (pData->eImagetype != mng_it_jng)) + MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); + +#ifdef MNG_SUPPORT_DISPLAY + return mng_create_mpng_obj (pData, pChunk); +#else + return MNG_NOERROR; +#endif +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ANG_PROPOSAL +MNG_C_SPECIALFUNC (mng_special_ahdr) +{ +#ifdef MNG_SUPPORT_DISPLAY + return mng_create_ang_obj (pData, pChunk); +#else + return MNG_NOERROR; +#endif +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ANG_PROPOSAL +MNG_F_SPECIALFUNC (mng_adat_tiles) +{ + if ((pData->eImagetype != mng_it_ang) || (!pData->pANG)) + MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); + + { + mng_adatp pADAT = (mng_adatp)pChunk; + mng_ang_objp pANG = (mng_ang_objp)pData->pANG; + mng_uint32 iRawlen = *piRawlen; + mng_uint8p pRawdata = *ppRawdata; + mng_retcode iRetcode; + mng_uint8p pBuf; + mng_uint32 iBufsize; + mng_uint32 iRealsize; + mng_uint8p pTemp; + mng_uint8p pTemp2; + mng_int32 iX; + mng_int32 iSize; + +#ifdef MNG_SUPPORT_DISPLAY + mng_imagep pImage; + mng_int32 iTemplen; + mng_uint8p pSwap; + + mng_processobject pProcess; + + mng_uint32 iSavedatawidth; + mng_uint32 iSavedataheight; + + mng_fptr fSaveinitrowproc; + mng_fptr fSavestorerow; + mng_fptr fSaveprocessrow; + mng_fptr fSavedifferrow; + mng_imagep fSavestoreobj; + mng_imagedatap fSavestorebuf; + +#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT + png_imgtype eSavepngimgtype; +#endif + + mng_uint8 iSaveinterlace; + mng_int8 iSavepass; + mng_int32 iSaverow; + mng_int32 iSaverowinc; + mng_int32 iSavecol; + mng_int32 iSavecolinc; + mng_int32 iSaverowsamples; + mng_int32 iSavesamplemul; + mng_int32 iSavesampleofs; + mng_int32 iSavesamplediv; + mng_int32 iSaverowsize; + mng_int32 iSaverowmax; + mng_int32 iSavefilterofs; + mng_int32 iSavepixelofs; + mng_uint32 iSavelevel0; + mng_uint32 iSavelevel1; + mng_uint32 iSavelevel2; + mng_uint32 iSavelevel3; + mng_uint8p pSaveworkrow; + mng_uint8p pSaveprevrow; + mng_uint8p pSaverGBArow; + mng_bool bSaveisRGBA16; + mng_bool bSaveisOpaque; + mng_int32 iSavefilterbpp; + + mng_int32 iSavedestl; + mng_int32 iSavedestt; + mng_int32 iSavedestr; + mng_int32 iSavedestb; + mng_int32 iSavesourcel; + mng_int32 iSavesourcet; + mng_int32 iSavesourcer; + mng_int32 iSavesourceb; +#endif /* MNG_SUPPORT_DISPLAY */ + + iRetcode = mng_inflate_buffer (pData, pRawdata, iRawlen, + &pBuf, &iBufsize, &iRealsize); + if (iRetcode) /* on error bail out */ + { /* don't forget to drop the temp buffer */ + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + /* get buffer for tile info in ADAT chunk */ + pADAT->iTilessize = pANG->iNumframes * sizeof(mng_adat_tile); + MNG_ALLOCX (pData, pADAT->pTiles, pADAT->iTilessize); + if (!pADAT->pTiles) + { + pADAT->iTilessize = 0; + MNG_FREEX (pData, pBuf, iBufsize); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + + pTemp = pBuf; + pTemp2 = (mng_uint8p)pADAT->pTiles; + + if (!pANG->iStillused) + iSize = 12; + else + iSize = 13; + + for (iX = 0; iX < pANG->iNumframes; iX++) + { + MNG_COPY (pTemp2, pTemp, iSize); + pTemp += iSize; + pTemp2 += sizeof(mng_adat_tile); + } + +#ifdef MNG_SUPPORT_DISPLAY + /* get buffer for tile info in ANG object */ + pANG->iTilessize = pADAT->iTilessize; + MNG_ALLOCX (pData, pANG->pTiles, pANG->iTilessize); + if (!pANG->pTiles) + { + pANG->iTilessize = 0; + MNG_FREEX (pData, pBuf, iBufsize); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + /* copy it from the ADAT object */ + MNG_COPY (pANG->pTiles, pADAT->pTiles, pANG->iTilessize); + + /* save IDAT work-parms */ + fSaveinitrowproc = pData->fInitrowproc; + fSavestorerow = pData->fDisplayrow; + fSaveprocessrow = pData->fProcessrow; + fSavedifferrow = pData->fDifferrow; + fSavestoreobj = pData->pStoreobj; + fSavestorebuf = pData->pStorebuf; + +#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT + eSavepngimgtype = pData->ePng_imgtype; +#endif + + iSavedatawidth = pData->iDatawidth; + iSavedataheight = pData->iDataheight; + iSaveinterlace = pData->iInterlace; + iSavepass = pData->iPass; + iSaverow = pData->iRow; + iSaverowinc = pData->iRowinc; + iSavecol = pData->iCol; + iSavecolinc = pData->iColinc; + iSaverowsamples = pData->iRowsamples; + iSavesamplemul = pData->iSamplemul; + iSavesampleofs = pData->iSampleofs; + iSavesamplediv = pData->iSamplediv; + iSaverowsize = pData->iRowsize; + iSaverowmax = pData->iRowmax; + iSavefilterofs = pData->iFilterofs; + iSavepixelofs = pData->iPixelofs; + iSavelevel0 = pData->iLevel0; + iSavelevel1 = pData->iLevel1; + iSavelevel2 = pData->iLevel2; + iSavelevel3 = pData->iLevel3; + pSaveworkrow = pData->pWorkrow; + pSaveprevrow = pData->pPrevrow; + pSaverGBArow = pData->pRGBArow; + bSaveisRGBA16 = pData->bIsRGBA16; + bSaveisOpaque = pData->bIsOpaque; + iSavefilterbpp = pData->iFilterbpp; + iSavedestl = pData->iDestl; + iSavedestt = pData->iDestt; + iSavedestr = pData->iDestr; + iSavedestb = pData->iDestb; + iSavesourcel = pData->iSourcel; + iSavesourcet = pData->iSourcet; + iSavesourcer = pData->iSourcer; + iSavesourceb = pData->iSourceb; + + pData->iDatawidth = pANG->iTilewidth; + pData->iDataheight = pANG->iTileheight; + + pData->iDestl = 0; + pData->iDestt = 0; + pData->iDestr = pANG->iTilewidth; + pData->iDestb = pANG->iTileheight; + pData->iSourcel = 0; + pData->iSourcet = 0; + pData->iSourcer = pANG->iTilewidth; + pData->iSourceb = pANG->iTileheight; + + pData->fInitrowproc = MNG_NULL; + pData->fStorerow = MNG_NULL; + pData->fProcessrow = MNG_NULL; + pData->fDifferrow = MNG_NULL; + + /* clone image object to store the pixel-data from object 0 */ + iRetcode = mng_clone_imageobject (pData, 1, MNG_FALSE, MNG_FALSE, MNG_FALSE, + MNG_FALSE, 0, 0, 0, pData->pObjzero, &pImage); + if (iRetcode) /* on error, drop temp buffer and bail */ + { + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + + /* make sure we got the right dimensions and interlacing */ + iRetcode = mng_reset_object_details (pData, pImage, pANG->iTilewidth, pANG->iTileheight, + pImage->pImgbuf->iBitdepth, pImage->pImgbuf->iColortype, + pImage->pImgbuf->iCompression, pImage->pImgbuf->iFilter, + pANG->iInterlace, MNG_FALSE); + if (iRetcode) /* on error, drop temp buffer and bail */ + { + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + + pData->pStoreobj = pImage; + +#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT + pData->fInitrowproc = (mng_fptr)mng_init_rowproc; + pData->ePng_imgtype = mng_png_imgtype(pData->iColortype,pData->iBitdepth); +#else + switch (pData->iColortype) /* determine row initialization routine */ + { + case 0 : { /* gray */ + switch (pData->iBitdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g1_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g1_i; + + break; + } + case 2 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g2_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g2_i; + + break; + } + case 4 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g4_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g4_i; + break; + } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g8_i; + + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g16_i; + + break; + } +#endif + } + + break; + } + case 2 : { /* rgb */ + switch (pData->iBitdepth) + { + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i; + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i; + + break; + } +#endif + } + + break; + } + case 3 : { /* indexed */ + switch (pData->iBitdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx1_i; + + break; + } + case 2 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx2_i; + + break; + } + case 4 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx4_i; + + break; + } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx8_i; + + break; + } + } + + break; + } + case 4 : { /* gray+alpha */ + switch (pData->iBitdepth) + { + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_ga8_i; + + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_ga16_i; + break; + } +#endif + } + + break; + } + case 6 : { /* rgb+alpha */ + switch (pData->iBitdepth) + { + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i; + + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i; + + break; + } +#endif + } + + break; + } + } +#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ + + pData->iFilterofs = 0; /* determine filter characteristics */ + pData->iLevel0 = 0; /* default levels */ + pData->iLevel1 = 0; + pData->iLevel2 = 0; + pData->iLevel3 = 0; + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + { + switch (pData->iColortype) + { + case 0 : { + if (pData->iBitdepth <= 8) + pData->iFilterofs = 1; + else + pData->iFilterofs = 2; + + break; + } + case 2 : { + if (pData->iBitdepth <= 8) + pData->iFilterofs = 3; + else + pData->iFilterofs = 6; + + break; + } + case 3 : { + pData->iFilterofs = 1; + break; + } + case 4 : { + if (pData->iBitdepth <= 8) + pData->iFilterofs = 2; + else + pData->iFilterofs = 4; + + break; + } + case 6 : { + if (pData->iBitdepth <= 8) + pData->iFilterofs = 4; + else + pData->iFilterofs = 8; + + break; + } + } + } +#endif + +#ifdef FILTER193 /* no adaptive filtering ? */ + if (pData->iFilter == MNG_FILTER_NOFILTER) + pData->iPixelofs = pData->iFilterofs; + else +#endif + pData->iPixelofs = pData->iFilterofs + 1; + + if (pData->fInitrowproc) /* need to initialize row processing? */ + { + iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData); + if (iRetcode) + { + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + } + /* calculate remainder of buffer */ + pTemp = pBuf + (mng_int32)(pANG->iNumframes * iSize); + iTemplen = iRealsize - (mng_int32)(pANG->iNumframes * iSize); + + do + { + if (iTemplen > pData->iRowmax) /* get a pixel-row from the temp buffer */ + { + MNG_COPY (pData->pWorkrow, pTemp, pData->iRowmax); + } + else + { + MNG_COPY (pData->pWorkrow, pTemp, iTemplen); + } + + { /* image not completed yet ? */ + if (pData->iRow < (mng_int32)pData->iDataheight) + { +#ifdef MNG_NO_1_2_4BIT_SUPPORT + if (pData->iPNGdepth == 1) + { + /* Inflate Workrow to 8-bit */ + mng_int32 iX; + mng_uint8p pSrc = pData->pWorkrow+1; + mng_uint8p pDest = pSrc + pData->iRowsize - (pData->iRowsize+7)/8; + + for (iX = ((pData->iRowsize+7)/8) ; iX > 0 ; iX--) + *pDest++ = *pSrc++; + + pDest = pData->pWorkrow+1; + pSrc = pDest + pData->iRowsize - (pData->iRowsize+7)/8; + for (iX = pData->iRowsize; ;) + { + *pDest++ = (((*pSrc)>>7)&1); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>6)&1); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>5)&1); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>4)&1); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>3)&1); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>2)&1); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>1)&1); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc) )&1); + if (iX-- <= 0) + break; + pSrc++; + } + } + else if (pData->iPNGdepth == 2) + { + /* Inflate Workrow to 8-bit */ + mng_int32 iX; + mng_uint8p pSrc = pData->pWorkrow+1; + mng_uint8p pDest = pSrc + pData->iRowsize - (2*pData->iRowsize+7)/8; + + for (iX = ((2*pData->iRowsize+7)/8) ; iX > 0 ; iX--) + *pDest++ = *pSrc++; + + pDest = pData->pWorkrow+1; + pSrc = pDest + pData->iRowsize - (2*pData->iRowsize+7)/8; + for (iX = pData->iRowsize; ;) + { + *pDest++ = (((*pSrc)>>6)&3); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>4)&3); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>2)&3); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc) )&3); + if (iX-- <= 0) + break; + pSrc++; + } + } + else if (pData->iPNGdepth == 4) + { + /* Inflate Workrow to 8-bit */ + mng_int32 iX; + mng_uint8p pSrc = pData->pWorkrow+1; + mng_uint8p pDest = pSrc + pData->iRowsize - (4*pData->iRowsize+7)/8; + + for (iX = ((4*pData->iRowsize+7)/8) ; iX > 0 ; iX--) + *pDest++ = *pSrc++; + + pDest = pData->pWorkrow+1; + pSrc = pDest + pData->iRowsize - (4*pData->iRowsize+7)/8; + for (iX = pData->iRowsize; ;) + { + *pDest++ = (((*pSrc)>>4)&0x0f); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc) )&0x0f); + if (iX-- <= 0) + break; + pSrc++; + } + } + if (pData->iPNGdepth < 8 && pData->iColortype == 0) + { + /* Expand samples to 8-bit by LBR */ + mng_int32 iX; + mng_uint8p pSrc = pData->pWorkrow+1; + mng_uint8 multiplier[]={0,255,85,0,17,0,0,0,1}; + + for (iX = pData->iRowsize; iX > 0; iX--) + *pSrc++ *= multiplier[pData->iPNGdepth]; + } +#endif +#ifdef MNG_NO_16BIT_SUPPORT + if (pData->iPNGdepth > 8) + { + /* Reduce Workrow to 8-bit */ + mng_int32 iX; + mng_uint8p pSrc = pData->pWorkrow+1; + mng_uint8p pDest = pSrc; + + for (iX = pData->iRowsize; iX > 0; iX--) + { + *pDest = *pSrc; + pDest++; + pSrc+=2; + } + } +#endif + +#ifdef FILTER192 /* has leveling info ? */ + if (pData->iFilterofs == MNG_FILTER_DIFFERING) + iRetcode = init_rowdiffering (pData); + else +#endif + iRetcode = MNG_NOERROR; + /* filter the row if necessary */ + if ((!iRetcode) && (pData->iFilterofs < pData->iPixelofs ) && + (*(pData->pWorkrow + pData->iFilterofs)) ) + iRetcode = mng_filter_a_row (pData); + + /* additional leveling/differing ? */ + if ((!iRetcode) && (pData->fDifferrow)) + { + iRetcode = ((mng_differrow)pData->fDifferrow) (pData); + + pSwap = pData->pWorkrow; + pData->pWorkrow = pData->pPrevrow; + pData->pPrevrow = pSwap; /* make sure we're processing the right data */ + } + + if (!iRetcode) + { + { /* process this row */ + if ((!iRetcode) && (pData->fProcessrow)) + iRetcode = ((mng_processrow)pData->fProcessrow) (pData); + /* store in object ? */ + if ((!iRetcode) && (pData->fStorerow)) + iRetcode = ((mng_storerow)pData->fStorerow) (pData); + } + } + + if (iRetcode) /* on error bail out */ + { + MNG_FREEX (pData, pBuf, iBufsize); + MNG_ERROR (pData, iRetcode); + } + + if (!pData->fDifferrow) /* swap row-pointers */ + { + pSwap = pData->pWorkrow; + pData->pWorkrow = pData->pPrevrow; + pData->pPrevrow = pSwap; /* so prev points to the processed row! */ + } + /* adjust variables for next row */ + iRetcode = mng_next_row (pData); + + if (iRetcode) /* on error bail out */ + { + MNG_FREEX (pData, pBuf, iBufsize); + MNG_ERROR (pData, iRetcode); + } + } + } + + pTemp += pData->iRowmax; + iTemplen -= pData->iRowmax; + } /* until some error or EOI + or all pixels received */ + while ( (iTemplen > 0) && + ( (pData->iRow < (mng_int32)pData->iDataheight) || + ( (pData->iPass >= 0) && (pData->iPass < 7) ) ) ); + + mng_cleanup_rowproc (pData); /* cleanup row processing buffers !! */ + + /* restore saved work-parms */ + pData->iDatawidth = iSavedatawidth; + pData->iDataheight = iSavedataheight; + + pData->fInitrowproc = fSaveinitrowproc; + pData->fDisplayrow = fSavestorerow; + pData->fProcessrow = fSaveprocessrow; + pData->fDifferrow = fSavedifferrow; + pData->pStoreobj = fSavestoreobj; + pData->pStorebuf = fSavestorebuf; + +#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT + pData->ePng_imgtype = eSavepngimgtype; +#endif + + pData->iInterlace = iSaveinterlace; + pData->iPass = iSavepass; + pData->iRow = iSaverow; + pData->iRowinc = iSaverowinc; + pData->iCol = iSavecol; + pData->iColinc = iSavecolinc; + pData->iRowsamples = iSaverowsamples; + pData->iSamplemul = iSavesamplemul; + pData->iSampleofs = iSavesampleofs; + pData->iSamplediv = iSavesamplediv; + pData->iRowsize = iSaverowsize; + pData->iRowmax = iSaverowmax; + pData->iFilterofs = iSavefilterofs; + pData->iPixelofs = iSavepixelofs; + pData->iLevel0 = iSavelevel0; + pData->iLevel1 = iSavelevel1; + pData->iLevel2 = iSavelevel2; + pData->iLevel3 = iSavelevel3; + pData->pWorkrow = pSaveworkrow; + pData->pPrevrow = pSaveprevrow; + pData->pRGBArow = pSaverGBArow; + pData->bIsRGBA16 = bSaveisRGBA16; + pData->bIsOpaque = bSaveisOpaque; + pData->iFilterbpp = iSavefilterbpp; + pData->iDestl = iSavedestl; + pData->iDestt = iSavedestt; + pData->iDestr = iSavedestr; + pData->iDestb = iSavedestb; + pData->iSourcel = iSavesourcel; + pData->iSourcet = iSavesourcet; + pData->iSourcer = iSavesourcer; + pData->iSourceb = iSavesourceb; + + /* create the animation directives ! */ + pProcess = (mng_processobject)pANG->sHeader.fProcess; + iRetcode = pProcess (pData, (mng_objectp)pData->pANG); + if (iRetcode) + return iRetcode; + +#endif /* MNG_SUPPORT_DISPLAY */ + + MNG_FREE (pData, pBuf, iBufsize); /* always free the temp buffer ! */ + } + + *piRawlen = 0; + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ANG_PROPOSAL +MNG_C_SPECIALFUNC (mng_special_adat) +{ + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +MNG_C_SPECIALFUNC (mng_special_unknown) +{ + /* critical chunk ? */ + if ((((mng_uint32)pData->iChunkname & 0x20000000) == 0) +#ifdef MNG_SKIPCHUNK_SAVE + && (pData->iChunkname != MNG_UINT_SAVE) +#endif +#ifdef MNG_SKIPCHUNK_SEEK + && (pData->iChunkname != MNG_UINT_SEEK) +#endif +#ifdef MNG_SKIPCHUNK_DBYK + && (pData->iChunkname != MNG_UINT_DBYK) +#endif +#ifdef MNG_SKIPCHUNK_ORDR + && (pData->iChunkname != MNG_UINT_ORDR) +#endif + ) + MNG_ERROR (pData, MNG_UNKNOWNCRITICAL); + + if (pData->fProcessunknown) /* let the app handle it ? */ + { + mng_bool bOke = pData->fProcessunknown ((mng_handle)pData, pData->iChunkname, + ((mng_unknown_chunkp)pChunk)->iDatasize, + ((mng_unknown_chunkp)pChunk)->pData); + if (!bOke) + MNG_ERROR (pData, MNG_APPMISCERROR); + } + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_READ_PROCS || MNG_INCLUDE_WRITE_PROCS */ +#endif /* MNG_OPTIMIZE_CHUNKREADER */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + + + + + diff --git a/Source/LibMNG/libmng_chunk_io.c b/Source/LibMNG/libmng_chunk_io.c index a75945f..eb18099 100644 --- a/Source/LibMNG/libmng_chunk_io.c +++ b/Source/LibMNG/libmng_chunk_io.c @@ -1,10740 +1,10740 @@ -/** ************************************************************************* */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_chunk_io.c copyright (c) 2000-2007 G.Juyn * */ -/* * version : 1.0.10 * */ -/* * * */ -/* * purpose : Chunk I/O routines (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of chunk input/output routines * */ -/* * * */ -/* * changes : 0.5.1 - 05/01/2000 - G.Juyn * */ -/* * - cleaned up left-over teststuff in the BACK chunk routine * */ -/* * 0.5.1 - 05/04/2000 - G.Juyn * */ -/* * - changed CRC initialization to use dynamic structure * */ -/* * (wasn't thread-safe the old way !) * */ -/* * 0.5.1 - 05/06/2000 - G.Juyn * */ -/* * - filled in many missing sequence&length checks * */ -/* * - filled in many missing chunk-store snippets * */ -/* * 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - added checks for running animations * */ -/* * - filled some write routines * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/10/2000 - G.Juyn * */ -/* * - filled some more write routines * */ -/* * 0.5.1 - 05/11/2000 - G.Juyn * */ -/* * - filled remaining write routines * */ -/* * - fixed read_pplt with regard to deltatype * */ -/* * - added callback error-reporting support * */ -/* * - added pre-draft48 support (short MHDR, frame_mode, LOOP) * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - changed trace to macro for callback error-reporting * */ -/* * - fixed chunk-storage bit in several routines * */ -/* * 0.5.1 - 05/13/2000 - G.Juyn * */ -/* * - added eMNGma hack (will be removed in 1.0.0 !!!) * */ -/* * - added TERM animation object pointer (easier reference) * */ -/* * - supplemented the SAVE & SEEK display processing * */ -/* * * */ -/* * 0.5.2 - 05/18/2000 - G.Juyn * */ -/* * - B004 - fixed problem with MNG_SUPPORT_WRITE not defined * */ -/* * also for MNG_SUPPORT_WRITE without MNG_INCLUDE_JNG * */ -/* * 0.5.2 - 05/19/2000 - G.Juyn * */ -/* * - cleaned up some code regarding mixed support * */ -/* * 0.5.2 - 05/20/2000 - G.Juyn * */ -/* * - implemented JNG support * */ -/* * 0.5.2 - 05/24/2000 - G.Juyn * */ -/* * - added support for global color-chunks in animation * */ -/* * - added support for global PLTE,tRNS,bKGD in animation * */ -/* * - added support for SAVE & SEEK in animation * */ -/* * 0.5.2 - 05/29/2000 - G.Juyn * */ -/* * - changed ani_create calls not returning object pointer * */ -/* * - create ani objects always (not just inside TERM/LOOP) * */ -/* * 0.5.2 - 05/30/2000 - G.Juyn * */ -/* * - added support for delta-image processing * */ -/* * 0.5.2 - 05/31/2000 - G.Juyn * */ -/* * - fixed up punctuation (contributed by Tim Rowley) * */ -/* * 0.5.2 - 06/02/2000 - G.Juyn * */ -/* * - changed SWAP_ENDIAN to BIGENDIAN_SUPPORTED * */ -/* * 0.5.2 - 06/03/2000 - G.Juyn * */ -/* * - fixed makeup for Linux gcc compile * */ -/* * * */ -/* * 0.5.3 - 06/12/2000 - G.Juyn * */ -/* * - added processing of color-info on delta-image * */ -/* * 0.5.3 - 06/13/2000 - G.Juyn * */ -/* * - fixed handling of empty SAVE chunk * */ -/* * 0.5.3 - 06/17/2000 - G.Juyn * */ -/* * - changed to support delta-images * */ -/* * - added extra checks for delta-images * */ -/* * 0.5.3 - 06/20/2000 - G.Juyn * */ -/* * - fixed possible trouble if IEND display-process got * */ -/* * broken up * */ -/* * 0.5.3 - 06/21/2000 - G.Juyn * */ -/* * - added processing of PLTE & tRNS for delta-images * */ -/* * - added administration of imagelevel parameter * */ -/* * 0.5.3 - 06/22/2000 - G.Juyn * */ -/* * - implemented support for PPLT chunk * */ -/* * 0.5.3 - 06/26/2000 - G.Juyn * */ -/* * - added precaution against faulty iCCP chunks from PS * */ -/* * 0.5.3 - 06/29/2000 - G.Juyn * */ -/* * - fixed some 64-bit warnings * */ -/* * * */ -/* * 0.9.1 - 07/14/2000 - G.Juyn * */ -/* * - changed pre-draft48 frame_mode=3 to frame_mode=1 * */ -/* * 0.9.1 - 07/16/2000 - G.Juyn * */ -/* * - fixed storage of images during mng_read() * */ -/* * - fixed support for mng_display() after mng_read() * */ -/* * 0.9.1 - 07/19/2000 - G.Juyn * */ -/* * - fixed several chunk-writing routines * */ -/* * 0.9.1 - 07/24/2000 - G.Juyn * */ -/* * - fixed reading of still-images * */ -/* * * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 0.9.3 - 08/07/2000 - G.Juyn * */ -/* * - B111300 - fixup for improved portability * */ -/* * 0.9.3 - 08/08/2000 - G.Juyn * */ -/* * - fixed compiler-warnings from Mozilla * */ -/* * 0.9.3 - 08/09/2000 - G.Juyn * */ -/* * - added check for simplicity-bits in MHDR * */ -/* * 0.9.3 - 08/12/2000 - G.Juyn * */ -/* * - fixed check for simplicity-bits in MHDR (JNG) * */ -/* * 0.9.3 - 08/12/2000 - G.Juyn * */ -/* * - added workaround for faulty PhotoShop iCCP chunk * */ -/* * 0.9.3 - 08/22/2000 - G.Juyn * */ -/* * - fixed write-code for zTXt & iTXt * */ -/* * - fixed read-code for iTXt * */ -/* * 0.9.3 - 08/26/2000 - G.Juyn * */ -/* * - added MAGN chunk * */ -/* * 0.9.3 - 09/07/2000 - G.Juyn * */ -/* * - added support for new filter_types * */ -/* * 0.9.3 - 09/10/2000 - G.Juyn * */ -/* * - fixed DEFI behavior * */ -/* * 0.9.3 - 10/02/2000 - G.Juyn * */ -/* * - fixed simplicity-check in compliance with draft 81/0.98a * */ -/* * 0.9.3 - 10/10/2000 - G.Juyn * */ -/* * - added support for alpha-depth prediction * */ -/* * 0.9.3 - 10/11/2000 - G.Juyn * */ -/* * - added support for nEED * */ -/* * 0.9.3 - 10/16/2000 - G.Juyn * */ -/* * - added support for JDAA * */ -/* * 0.9.3 - 10/17/2000 - G.Juyn * */ -/* * - fixed support for MAGN * */ -/* * - implemented nEED "xxxx" (where "xxxx" is a chunkid) * */ -/* * - added callback to process non-critical unknown chunks * */ -/* * - fixed support for bKGD * */ -/* * 0.9.3 - 10/23/2000 - G.Juyn * */ -/* * - fixed bug in empty PLTE handling * */ -/* * * */ -/* * 0.9.4 - 11/20/2000 - G.Juyn * */ -/* * - changed IHDR filter_method check for PNGs * */ -/* * 0.9.4 - 1/18/2001 - G.Juyn * */ -/* * - added errorchecking for MAGN methods * */ -/* * - removed test filter-methods 1 & 65 * */ -/* * * */ -/* * 0.9.5 - 1/25/2001 - G.Juyn * */ -/* * - fixed some small compiler warnings (thanks Nikki) * */ -/* * * */ -/* * 1.0.2 - 05/05/2000 - G.Juyn * */ -/* * - B421427 - writes wrong format in bKGD and tRNS * */ -/* * 1.0.2 - 06/20/2000 - G.Juyn * */ -/* * - B434583 - compiler-warning if MNG_STORE_CHUNKS undefined * */ -/* * * */ -/* * 1.0.5 - 07/08/2002 - G.Juyn * */ -/* * - B578572 - removed eMNGma hack (thanks Dimitri!) * */ -/* * 1.0.5 - 08/07/2002 - G.Juyn * */ -/* * - added test-option for PNG filter method 193 (=no filter) * */ -/* * 1.0.5 - 08/15/2002 - G.Juyn * */ -/* * - completed PROM support * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * 1.0.5 - 09/07/2002 - G.Juyn * */ -/* * - fixed reading of FRAM with just frame_mode and name * */ -/* * 1.0.5 - 09/13/2002 - G.Juyn * */ -/* * - fixed read/write of MAGN chunk * */ -/* * 1.0.5 - 09/14/2002 - G.Juyn * */ -/* * - added event handling for dynamic MNG * */ -/* * 1.0.5 - 09/15/2002 - G.Juyn * */ -/* * - fixed LOOP iteration=0 special case * */ -/* * 1.0.5 - 09/19/2002 - G.Juyn * */ -/* * - misplaced TERM is now treated as warning * */ -/* * 1.0.5 - 09/20/2002 - G.Juyn * */ -/* * - added support for PAST * */ -/* * 1.0.5 - 10/03/2002 - G.Juyn * */ -/* * - fixed chunk-storage for evNT chunk * */ -/* * 1.0.5 - 10/07/2002 - G.Juyn * */ -/* * - fixed DISC support * */ -/* * - added another fix for misplaced TERM chunk * */ -/* * 1.0.5 - 10/17/2002 - G.Juyn * */ -/* * - fixed initializtion of pIds in dISC read routine * */ -/* * 1.0.5 - 11/06/2002 - G.Juyn * */ -/* * - added support for nEED "MNG 1.1" * */ -/* * - added support for nEED "CACHEOFF" * */ -/* * * */ -/* * 1.0.6 - 05/25/2003 - G.R-P * */ -/* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */ -/* * 1.0.6 - 06/02/2003 - G.R-P * */ -/* * - removed some redundant checks for iRawlen==0 * */ -/* * 1.0.6 - 06/22/2003 - G.R-P * */ -/* * - added MNG_NO_16BIT_SUPPORT, MNG_NO_DELTA_PNG reductions * */ -/* * - optionally use zlib's crc32 function instead of * */ -/* * local mng_update_crc * */ -/* * 1.0.6 - 07/14/2003 - G.R-P * */ -/* * - added MNG_NO_LOOP_SIGNALS_SUPPORTED conditional * */ -/* * 1.0.6 - 07/29/2003 - G.R-P * */ -/* * - added conditionals around PAST chunk support * */ -/* * 1.0.6 - 08/17/2003 - G.R-P * */ -/* * - added conditionals around non-VLC chunk support * */ -/* * * */ -/* * 1.0.7 - 10/29/2003 - G.R-P * */ -/* * - revised JDAA and JDAT readers to avoid compiler bug * */ -/* * 1.0.7 - 01/25/2004 - J.S * */ -/* * - added premultiplied alpha canvas' for RGBA, ARGB, ABGR * */ -/* * 1.0.7 - 01/27/2004 - J.S * */ -/* * - fixed inclusion of IJNG chunk for non-JNG use * */ -/* * 1.0.7 - 02/26/2004 - G.Juyn * */ -/* * - fixed bug in chunk-storage of SHOW chunk (from == to) * */ -/* * * */ -/* * 1.0.8 - 04/02/2004 - G.Juyn * */ -/* * - added CRC existence & checking flags * */ -/* * 1.0.8 - 07/07/2004 - G.R-P * */ -/* * - change worst-case iAlphadepth to 1 for standalone PNGs * */ -/* * * */ -/* * 1.0.9 - 09/28/2004 - G.R-P * */ -/* * - improved handling of cheap transparency when 16-bit * */ -/* * support is disabled * */ -/* * 1.0.9 - 10/04/2004 - G.Juyn * */ -/* * - fixed bug in writing sBIT for indexed color * */ -/* * 1.0.9 - 10/10/2004 - G.R-P. * */ -/* * - added MNG_NO_1_2_4BIT_SUPPORT * */ -/* * 1.0.9 - 12/05/2004 - G.Juyn * */ -/* * - added conditional MNG_OPTIMIZE_CHUNKINITFREE * */ -/* * 1.0.9 - 12/06/2004 - G.Juyn * */ -/* * - added conditional MNG_OPTIMIZE_CHUNKASSIGN * */ -/* * 1.0.9 - 12/07/2004 - G.Juyn * */ -/* * - added conditional MNG_OPTIMIZE_CHUNKREADER * */ -/* * 1.0.9 - 12/11/2004 - G.Juyn * */ -/* * - added conditional MNG_OPTIMIZE_DISPLAYCALLS * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * 1.0.9 - 01/17/2005 - G.Juyn * */ -/* * - fixed problem with global PLTE/tRNS * */ -/* * * */ -/* * 1.0.10 - 02/07/2005 - G.Juyn * */ -/* * - fixed display routines called twice for FULL_MNG * */ -/* * support in mozlibmngconf.h * */ -/* * 1.0.10 - 12/04/2005 - G.R-P. * */ -/* * - #ifdef out use of mng_inflate_buffer when it is not * */ -/* * available. * */ -/* * 1.0.10 - 04/08/2007 - G.Juyn * */ -/* * - added support for mPNG proposal * */ -/* * 1.0.10 - 04/12/2007 - G.Juyn * */ -/* * - added support for ANG proposal * */ -/* * 1.0.10 - 05/02/2007 - G.Juyn * */ -/* * - fixed inflate_buffer for extreme compression ratios * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_objects.h" -#include "libmng_object_prc.h" -#include "libmng_chunks.h" -#ifdef MNG_CHECK_BAD_ICCP -#include "libmng_chunk_prc.h" -#endif -#include "libmng_memory.h" -#include "libmng_display.h" -#include "libmng_zlib.h" -#include "libmng_pixels.h" -#include "libmng_chunk_io.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ -/* * * */ -/* * CRC - Cyclic Redundancy Check * */ -/* * * */ -/* * The code below is taken directly from the sample provided with the * */ -/* * PNG specification. * */ -/* * (it is only adapted to the library's internal data-definitions) * */ -/* * * */ -/* ************************************************************************** */ -/* Make the table for a fast CRC. */ -#ifndef MNG_USE_ZLIB_CRC -MNG_LOCAL void make_crc_table (mng_datap pData) -{ - mng_uint32 iC; - mng_int32 iN, iK; - - for (iN = 0; iN < 256; iN++) - { - iC = (mng_uint32) iN; - - for (iK = 0; iK < 8; iK++) - { - if (iC & 1) - iC = 0xedb88320U ^ (iC >> 1); - else - iC = iC >> 1; - } - - pData->aCRCtable [iN] = iC; - } - - pData->bCRCcomputed = MNG_TRUE; -} -#endif - -/* Update a running CRC with the bytes buf[0..len-1]--the CRC - should be initialized to all 1's, and the transmitted value - is the 1's complement of the final running CRC (see the - crc() routine below). */ - -MNG_LOCAL mng_uint32 update_crc (mng_datap pData, - mng_uint32 iCrc, - mng_uint8p pBuf, - mng_int32 iLen) -{ -#ifdef MNG_USE_ZLIB_CRC - return crc32 (iCrc, pBuf, iLen); -#else - mng_uint32 iC = iCrc; - mng_int32 iN; - - if (!pData->bCRCcomputed) - make_crc_table (pData); - - for (iN = 0; iN < iLen; iN++) - iC = pData->aCRCtable [(iC ^ pBuf [iN]) & 0xff] ^ (iC >> 8); - - return iC; -#endif -} - -/* Return the CRC of the bytes buf[0..len-1]. */ -mng_uint32 mng_crc (mng_datap pData, - mng_uint8p pBuf, - mng_int32 iLen) -{ -#ifdef MNG_USE_ZLIB_CRC - return update_crc (pData, 0, pBuf, iLen); -#else - return update_crc (pData, 0xffffffffU, pBuf, iLen) ^ 0xffffffffU; -#endif -} - -/* ************************************************************************** */ -/* * * */ -/* * Routines for swapping byte-order from and to graphic files * */ -/* * (This code is adapted from the libpng package) * */ -/* * * */ -/* ************************************************************************** */ - -#ifndef MNG_BIGENDIAN_SUPPORTED - -/* ************************************************************************** */ - -mng_uint32 mng_get_uint32 (mng_uint8p pBuf) -{ - mng_uint32 i = ((mng_uint32)(*pBuf) << 24) + - ((mng_uint32)(*(pBuf + 1)) << 16) + - ((mng_uint32)(*(pBuf + 2)) << 8) + - (mng_uint32)(*(pBuf + 3)); - return (i); -} - -/* ************************************************************************** */ - -mng_int32 mng_get_int32 (mng_uint8p pBuf) -{ - mng_int32 i = ((mng_int32)(*pBuf) << 24) + - ((mng_int32)(*(pBuf + 1)) << 16) + - ((mng_int32)(*(pBuf + 2)) << 8) + - (mng_int32)(*(pBuf + 3)); - return (i); -} - -/* ************************************************************************** */ - -mng_uint16 mng_get_uint16 (mng_uint8p pBuf) -{ - mng_uint16 i = (mng_uint16)(((mng_uint16)(*pBuf) << 8) + - (mng_uint16)(*(pBuf + 1))); - return (i); -} - -/* ************************************************************************** */ - -void mng_put_uint32 (mng_uint8p pBuf, - mng_uint32 i) -{ - *pBuf = (mng_uint8)((i >> 24) & 0xff); - *(pBuf+1) = (mng_uint8)((i >> 16) & 0xff); - *(pBuf+2) = (mng_uint8)((i >> 8) & 0xff); - *(pBuf+3) = (mng_uint8)(i & 0xff); -} - -/* ************************************************************************** */ - -void mng_put_int32 (mng_uint8p pBuf, - mng_int32 i) -{ - *pBuf = (mng_uint8)((i >> 24) & 0xff); - *(pBuf+1) = (mng_uint8)((i >> 16) & 0xff); - *(pBuf+2) = (mng_uint8)((i >> 8) & 0xff); - *(pBuf+3) = (mng_uint8)(i & 0xff); -} - -/* ************************************************************************** */ - -void mng_put_uint16 (mng_uint8p pBuf, - mng_uint16 i) -{ - *pBuf = (mng_uint8)((i >> 8) & 0xff); - *(pBuf+1) = (mng_uint8)(i & 0xff); -} - -/* ************************************************************************** */ - -#endif /* !MNG_BIGENDIAN_SUPPORTED */ - -/* ************************************************************************** */ -/* * * */ -/* * Helper routines to simplify chunk-data extraction * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_READ_PROCS - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -MNG_LOCAL mng_uint8p find_null (mng_uint8p pIn) -{ - mng_uint8p pOut = pIn; - while (*pOut) /* the read_graphic routine has made sure there's */ - pOut++; /* always at least 1 zero-byte in the buffer */ - return pOut; -} -#endif - -/* ************************************************************************** */ - -#if !defined(MNG_SKIPCHUNK_iCCP) || !defined(MNG_SKIPCHUNK_zTXt) || \ - !defined(MNG_SKIPCHUNK_iTXt) || defined(MNG_INCLUDE_MPNG_PROPOSAL) || \ - defined(MNG_INCLUDE_ANG_PROPOSAL) -mng_retcode mng_inflate_buffer (mng_datap pData, - mng_uint8p pInbuf, - mng_uint32 iInsize, - mng_uint8p *pOutbuf, - mng_uint32 *iOutsize, - mng_uint32 *iRealsize) -{ - mng_retcode iRetcode = MNG_NOERROR; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INFLATE_BUFFER, MNG_LC_START); -#endif - - if (iInsize) /* anything to do ? */ - { - *iOutsize = iInsize * 3; /* estimate uncompressed size */ - /* and allocate a temporary buffer */ - MNG_ALLOC (pData, *pOutbuf, *iOutsize); - - do - { - mngzlib_inflateinit (pData); /* initialize zlib */ - /* let zlib know where to store the output */ - pData->sZlib.next_out = *pOutbuf; - /* "size - 1" so we've got space for the - zero-termination of a possible string */ - pData->sZlib.avail_out = *iOutsize - 1; - /* ok; let's inflate... */ - iRetcode = mngzlib_inflatedata (pData, iInsize, pInbuf); - /* determine actual output size */ - *iRealsize = (mng_uint32)pData->sZlib.total_out; - - mngzlib_inflatefree (pData); /* zlib's done */ - - if (iRetcode == MNG_BUFOVERFLOW) /* not enough space ? */ - { /* then get some more */ - MNG_FREEX (pData, *pOutbuf, *iOutsize); - *iOutsize = *iOutsize + *iOutsize; - MNG_ALLOC (pData, *pOutbuf, *iOutsize); - } - } /* repeat if we didn't have enough space */ - while ((iRetcode == MNG_BUFOVERFLOW) && - (*iOutsize < 200 * iInsize)); - - if (!iRetcode) /* if oke ? */ - *((*pOutbuf) + *iRealsize) = 0; /* then put terminator zero */ - - } - else - { - *pOutbuf = 0; /* nothing to do; then there's no output */ - *iOutsize = 0; - *iRealsize = 0; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INFLATE_BUFFER, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_READ_PROCS */ - -/* ************************************************************************** */ -/* * * */ -/* * Helper routines to simplify chunk writing * */ -/* * * */ -/* ************************************************************************** */ -#ifdef MNG_INCLUDE_WRITE_PROCS -/* ************************************************************************** */ - -#if !defined(MNG_SKIPCHUNK_iCCP) || !defined(MNG_SKIPCHUNK_zTXt) || !defined(MNG_SKIPCHUNK_iTXt) -MNG_LOCAL mng_retcode deflate_buffer (mng_datap pData, - mng_uint8p pInbuf, - mng_uint32 iInsize, - mng_uint8p *pOutbuf, - mng_uint32 *iOutsize, - mng_uint32 *iRealsize) -{ - mng_retcode iRetcode = MNG_NOERROR; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DEFLATE_BUFFER, MNG_LC_START); -#endif - - if (iInsize) /* anything to do ? */ - { - *iOutsize = (iInsize * 5) >> 2; /* estimate compressed size */ - /* and allocate a temporary buffer */ - MNG_ALLOC (pData, *pOutbuf, *iOutsize); - - do - { - mngzlib_deflateinit (pData); /* initialize zlib */ - /* let zlib know where to store the output */ - pData->sZlib.next_out = *pOutbuf; - pData->sZlib.avail_out = *iOutsize; - /* ok; let's deflate... */ - iRetcode = mngzlib_deflatedata (pData, iInsize, pInbuf); - /* determine actual output size */ - *iRealsize = pData->sZlib.total_out; - - mngzlib_deflatefree (pData); /* zlib's done */ - - if (iRetcode == MNG_BUFOVERFLOW) /* not enough space ? */ - { /* then get some more */ - MNG_FREEX (pData, *pOutbuf, *iOutsize); - *iOutsize = *iOutsize + (iInsize >> 1); - MNG_ALLOC (pData, *pOutbuf, *iOutsize); - } - } /* repeat if we didn't have enough space */ - while (iRetcode == MNG_BUFOVERFLOW); - } - else - { - *pOutbuf = 0; /* nothing to do; then there's no output */ - *iOutsize = 0; - *iRealsize = 0; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DEFLATE_BUFFER, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode write_raw_chunk (mng_datap pData, - mng_chunkid iChunkname, - mng_uint32 iRawlen, - mng_uint8p pRawdata) -{ - mng_uint32 iCrc; - mng_uint32 iWritten; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_RAW_CHUNK, MNG_LC_START); -#endif - /* temporary buffer ? */ - if ((pRawdata != 0) && (pRawdata != pData->pWritebuf+8)) - { /* store length & chunktype in default buffer */ - mng_put_uint32 (pData->pWritebuf, iRawlen); - mng_put_uint32 (pData->pWritebuf+4, (mng_uint32)iChunkname); - - if (pData->iCrcmode & MNG_CRC_OUTPUT) - { - if ((pData->iCrcmode & MNG_CRC_OUTPUT) == MNG_CRC_OUTPUT_GENERATE) - { /* calculate the crc */ - iCrc = update_crc (pData, 0xffffffffL, pData->pWritebuf+4, 4); - iCrc = update_crc (pData, iCrc, pRawdata, iRawlen) ^ 0xffffffffL; - } else { - iCrc = 0; /* dummy crc */ - } /* store in default buffer */ - mng_put_uint32 (pData->pWritebuf+8, iCrc); - } - /* write the length & chunktype */ - if (!pData->fWritedata ((mng_handle)pData, pData->pWritebuf, 8, &iWritten)) - MNG_ERROR (pData, MNG_APPIOERROR); - - if (iWritten != 8) /* disk full ? */ - MNG_ERROR (pData, MNG_OUTPUTERROR); - /* write the temporary buffer */ - if (!pData->fWritedata ((mng_handle)pData, pRawdata, iRawlen, &iWritten)) - MNG_ERROR (pData, MNG_APPIOERROR); - - if (iWritten != iRawlen) /* disk full ? */ - MNG_ERROR (pData, MNG_OUTPUTERROR); - - if (pData->iCrcmode & MNG_CRC_OUTPUT) - { /* write the crc */ - if (!pData->fWritedata ((mng_handle)pData, pData->pWritebuf+8, 4, &iWritten)) - MNG_ERROR (pData, MNG_APPIOERROR); - - if (iWritten != 4) /* disk full ? */ - MNG_ERROR (pData, MNG_OUTPUTERROR); - } - } - else - { /* prefix with length & chunktype */ - mng_put_uint32 (pData->pWritebuf, iRawlen); - mng_put_uint32 (pData->pWritebuf+4, (mng_uint32)iChunkname); - - if (pData->iCrcmode & MNG_CRC_OUTPUT) - { - if ((pData->iCrcmode & MNG_CRC_OUTPUT) == MNG_CRC_OUTPUT_GENERATE) - /* calculate the crc */ - iCrc = mng_crc (pData, pData->pWritebuf+4, iRawlen + 4); - else - iCrc = 0; /* dummy crc */ - /* add it to the buffer */ - mng_put_uint32 (pData->pWritebuf + iRawlen + 8, iCrc); - /* write it in a single pass */ - if (!pData->fWritedata ((mng_handle)pData, pData->pWritebuf, iRawlen + 12, &iWritten)) - MNG_ERROR (pData, MNG_APPIOERROR); - - if (iWritten != iRawlen + 12) /* disk full ? */ - MNG_ERROR (pData, MNG_OUTPUTERROR); - } else { - if (!pData->fWritedata ((mng_handle)pData, pData->pWritebuf, iRawlen + 8, &iWritten)) - MNG_ERROR (pData, MNG_APPIOERROR); - - if (iWritten != iRawlen + 8) /* disk full ? */ - MNG_ERROR (pData, MNG_OUTPUTERROR); - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_RAW_CHUNK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ -/* B004 */ -#endif /* MNG_INCLUDE_WRITE_PROCS */ -/* B004 */ -/* ************************************************************************** */ -/* * * */ -/* * chunk read functions * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_READ_PROCS - -/* ************************************************************************** */ - -#ifdef MNG_OPTIMIZE_CHUNKREADER - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode create_chunk_storage (mng_datap pData, - mng_chunkp pHeader, - mng_uint32 iRawlen, - mng_uint8p pRawdata, - mng_field_descp pField, - mng_uint16 iFields, - mng_chunkp* ppChunk, - mng_bool bWorkcopy) -{ - mng_field_descp pTempfield = pField; - mng_uint16 iFieldcount = iFields; - mng_uint8p pTempdata = pRawdata; - mng_uint32 iTemplen = iRawlen; - mng_uint16 iLastgroup = 0; - mng_uint8p pChunkdata; - mng_uint32 iDatalen; - mng_uint8 iColortype; - mng_bool bProcess; - /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - if (iRetcode) /* on error bail out */ - return iRetcode; - - if (((mng_chunk_headerp)(*ppChunk))->iChunkname == MNG_UINT_HUH) - ((mng_chunk_headerp)(*ppChunk))->iChunkname = pData->iChunkname; - - if ((!bWorkcopy) || - ((((mng_chunk_headerp)pHeader)->iChunkname != MNG_UINT_IDAT) && - (((mng_chunk_headerp)pHeader)->iChunkname != MNG_UINT_JDAT) && - (((mng_chunk_headerp)pHeader)->iChunkname != MNG_UINT_JDAA) )) - { - pChunkdata = (mng_uint8p)(*ppChunk); - -#ifdef MNG_INCLUDE_JNG /* determine current colortype */ - if (pData->bHasJHDR) - iColortype = (mng_uint8)(pData->iJHDRcolortype - 8); - else -#endif /* MNG_INCLUDE_JNG */ - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - iColortype = pData->iColortype; - else - iColortype = 6; - - if (iTemplen) /* not empty ? */ - { /* then go fill the fields */ - while ((iFieldcount) && (iTemplen)) - { - if (pTempfield->iOffsetchunk) - { - if (pTempfield->iFlags & MNG_FIELD_PUTIMGTYPE) - { - *(pChunkdata+pTempfield->iOffsetchunk) = iColortype; - bProcess = MNG_FALSE; - } - else - if (pTempfield->iFlags & MNG_FIELD_IFIMGTYPES) - bProcess = (mng_bool)(((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE0) && (iColortype == 0)) || - ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE2) && (iColortype == 2)) || - ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE3) && (iColortype == 3)) || - ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE4) && (iColortype == 4)) || - ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE6) && (iColortype == 6)) ); - else - bProcess = MNG_TRUE; - - if (bProcess) - { - iLastgroup = (mng_uint16)(pTempfield->iFlags & MNG_FIELD_GROUPMASK); - /* numeric field ? */ - if (pTempfield->iFlags & MNG_FIELD_INT) - { - if (iTemplen < pTempfield->iLengthmax) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - switch (pTempfield->iLengthmax) - { - case 1 : { mng_uint8 iNum = *pTempdata; - if (((mng_uint16)iNum < pTempfield->iMinvalue) || - ((mng_uint16)iNum > pTempfield->iMaxvalue) ) - MNG_ERROR (pData, MNG_INVALIDFIELDVAL); - *(pChunkdata+pTempfield->iOffsetchunk) = iNum; - break; } - case 2 : { mng_uint16 iNum = mng_get_uint16 (pTempdata); - if ((iNum < pTempfield->iMinvalue) || (iNum > pTempfield->iMaxvalue)) - MNG_ERROR (pData, MNG_INVALIDFIELDVAL); - *((mng_uint16p)(pChunkdata+pTempfield->iOffsetchunk)) = iNum; - break; } - case 4 : { mng_uint32 iNum = mng_get_uint32 (pTempdata); - if ((iNum < pTempfield->iMinvalue) || - ((pTempfield->iFlags & MNG_FIELD_NOHIGHBIT) && (iNum & 0x80000000)) ) - MNG_ERROR (pData, MNG_INVALIDFIELDVAL); - *((mng_uint32p)(pChunkdata+pTempfield->iOffsetchunk)) = iNum; - break; } - } - - pTempdata += pTempfield->iLengthmax; - iTemplen -= pTempfield->iLengthmax; - - } else { /* not numeric so it's a bunch of bytes */ - - if (!pTempfield->iOffsetchunklen) /* big fat NONO */ - MNG_ERROR (pData, MNG_INTERNALERROR); - /* with terminating 0 ? */ - if (pTempfield->iFlags & MNG_FIELD_TERMINATOR) - { - mng_uint8p pWork = pTempdata; - while (*pWork) /* find the zero */ - pWork++; - iDatalen = (mng_uint32)(pWork - pTempdata); - } else { /* no terminator, so everything that's left ! */ - iDatalen = iTemplen; - } - - if ((pTempfield->iLengthmax) && (iDatalen > pTempfield->iLengthmax)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); -#if !defined(MNG_SKIPCHUNK_iCCP) || !defined(MNG_SKIPCHUNK_zTXt) || \ - !defined(MNG_SKIPCHUNK_iTXt) || defined(MNG_INCLUDE_MPNG_PROPOSAL) || \ - defined(MNG_INCLUDE_ANG_PROPOSAL) - /* needs decompression ? */ - if (pTempfield->iFlags & MNG_FIELD_DEFLATED) - { - mng_uint8p pBuf = 0; - mng_uint32 iBufsize = 0; - mng_uint32 iRealsize; - mng_ptr pWork; - - iRetcode = mng_inflate_buffer (pData, pTempdata, iDatalen, - &pBuf, &iBufsize, &iRealsize); - -#ifdef MNG_CHECK_BAD_ICCP /* Check for bad iCCP chunk */ - if ((iRetcode) && (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_iCCP)) - { - *((mng_ptr *)(pChunkdata+pTempfield->iOffsetchunk)) = MNG_NULL; - *((mng_uint32p)(pChunkdata+pTempfield->iOffsetchunklen)) = iDatalen; - } - else -#endif - { - if (iRetcode) - return iRetcode; - -#if defined(MNG_INCLUDE_MPNG_PROPOSAL) || defined(MNG_INCLUDE_ANG_PROPOSAL) - if ( (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_mpNG) || - (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_adAT) ) - { - MNG_ALLOC (pData, pWork, iRealsize); - } - else - { -#endif - /* don't forget to generate null terminator */ - MNG_ALLOC (pData, pWork, iRealsize+1); -#if defined(MNG_INCLUDE_MPNG_PROPOSAL) || defined(MNG_INCLUDE_ANG_PROPOSAL) - } -#endif - MNG_COPY (pWork, pBuf, iRealsize); - - *((mng_ptr *)(pChunkdata+pTempfield->iOffsetchunk)) = pWork; - *((mng_uint32p)(pChunkdata+pTempfield->iOffsetchunklen)) = iRealsize; - } - - if (pBuf) /* free the temporary buffer */ - MNG_FREEX (pData, pBuf, iBufsize); - - } else -#endif - { /* no decompression, so just copy */ - - mng_ptr pWork; - /* don't forget to generate null terminator */ - MNG_ALLOC (pData, pWork, iDatalen+1); - MNG_COPY (pWork, pTempdata, iDatalen); - - *((mng_ptr *)(pChunkdata+pTempfield->iOffsetchunk)) = pWork; - *((mng_uint32p)(pChunkdata+pTempfield->iOffsetchunklen)) = iDatalen; - } - - if (pTempfield->iFlags & MNG_FIELD_TERMINATOR) - iDatalen++; /* skip the terminating zero as well !!! */ - - iTemplen -= iDatalen; - pTempdata += iDatalen; - } - /* need to set an indicator ? */ - if (pTempfield->iOffsetchunkind) - *((mng_uint8p)(pChunkdata+pTempfield->iOffsetchunkind)) = MNG_TRUE; - } - } - - if (pTempfield->pSpecialfunc) /* special function required ? */ - { - iRetcode = pTempfield->pSpecialfunc(pData, *ppChunk, &iTemplen, &pTempdata); - if (iRetcode) /* on error bail out */ - return iRetcode; - } - - pTempfield++; /* Neeeeeeexxxtt */ - iFieldcount--; - } - - if (iTemplen) /* extra data ??? */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - while (iFieldcount) /* not enough data ??? */ - { - if (pTempfield->iFlags & MNG_FIELD_IFIMGTYPES) - bProcess = (mng_bool)(((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE0) && (iColortype == 0)) || - ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE2) && (iColortype == 2)) || - ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE3) && (iColortype == 3)) || - ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE4) && (iColortype == 4)) || - ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE6) && (iColortype == 6)) ); - else - bProcess = MNG_TRUE; - - if (bProcess) - { - if (!(pTempfield->iFlags & MNG_FIELD_OPTIONAL)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - if ((pTempfield->iFlags & MNG_FIELD_GROUPMASK) && - ((mng_uint16)(pTempfield->iFlags & MNG_FIELD_GROUPMASK) == iLastgroup)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - - pTempfield++; - iFieldcount--; - } - } - } - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -READ_CHUNK (mng_read_general) -{ - mng_retcode iRetcode = MNG_NOERROR; - mng_chunk_descp pDescr = ((mng_chunk_headerp)pHeader)->pChunkdescr; - mng_field_descp pField; - mng_uint16 iFields; - - if (!pDescr) /* this is a bad booboo !!! */ - MNG_ERROR (pData, MNG_INTERNALERROR); - - pField = pDescr->pFielddesc; - iFields = pDescr->iFielddesc; - /* check chunk against signature */ - if ((pDescr->eImgtype == mng_it_mng) && (pData->eSigtype != mng_it_mng)) - MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); - - if ((pDescr->eImgtype == mng_it_jng) && (pData->eSigtype == mng_it_png)) - MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); - /* empties allowed ? */ - if ((iRawlen == 0) && (!(pDescr->iAllowed & MNG_DESCR_EMPTY))) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((pData->eImagetype != mng_it_mng) || (!(pDescr->iAllowed & MNG_DESCR_GLOBAL))) - { /* *a* header required ? */ - if ((pDescr->iMusthaves & MNG_DESCR_GenHDR) && -#ifdef MNG_INCLUDE_JNG - (!pData->bHasIHDR) && (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - (!pData->bHasIHDR) && (!pData->bHasBASI) && (!pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pDescr->iMusthaves & MNG_DESCR_JngHDR) && - (!pData->bHasDHDR) && (!pData->bHasJHDR)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); -#endif - } - /* specific chunk pre-requisite ? */ - if (((pDescr->iMusthaves & MNG_DESCR_IHDR) && (!pData->bHasIHDR)) || -#ifdef MNG_INCLUDE_JNG - ((pDescr->iMusthaves & MNG_DESCR_JHDR) && (!pData->bHasJHDR)) || -#endif - ((pDescr->iMusthaves & MNG_DESCR_DHDR) && (!pData->bHasDHDR)) || - ((pDescr->iMusthaves & MNG_DESCR_LOOP) && (!pData->bHasLOOP)) || - ((pDescr->iMusthaves & MNG_DESCR_PLTE) && (!pData->bHasPLTE)) || - ((pDescr->iMusthaves & MNG_DESCR_MHDR) && (!pData->bHasMHDR)) || - ((pDescr->iMusthaves & MNG_DESCR_SAVE) && (!pData->bHasSAVE)) ) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* specific chunk undesired ? */ - if (((pDescr->iMustNOThaves & MNG_DESCR_NOIHDR) && (pData->bHasIHDR)) || - ((pDescr->iMustNOThaves & MNG_DESCR_NOBASI) && (pData->bHasBASI)) || - ((pDescr->iMustNOThaves & MNG_DESCR_NODHDR) && (pData->bHasDHDR)) || - ((pDescr->iMustNOThaves & MNG_DESCR_NOIDAT) && (pData->bHasIDAT)) || - ((pDescr->iMustNOThaves & MNG_DESCR_NOPLTE) && (pData->bHasPLTE)) || -#ifdef MNG_INCLUDE_JNG - ((pDescr->iMustNOThaves & MNG_DESCR_NOJHDR) && (pData->bHasJHDR)) || - ((pDescr->iMustNOThaves & MNG_DESCR_NOJDAT) && (pData->bHasJDAT)) || - ((pDescr->iMustNOThaves & MNG_DESCR_NOJDAA) && (pData->bHasJDAA)) || - ((pDescr->iMustNOThaves & MNG_DESCR_NOJSEP) && (pData->bHasJSEP)) || -#endif - ((pDescr->iMustNOThaves & MNG_DESCR_NOMHDR) && (pData->bHasMHDR)) || - ((pDescr->iMustNOThaves & MNG_DESCR_NOLOOP) && (pData->bHasLOOP)) || - ((pDescr->iMustNOThaves & MNG_DESCR_NOTERM) && (pData->bHasTERM)) || - ((pDescr->iMustNOThaves & MNG_DESCR_NOSAVE) && (pData->bHasSAVE)) ) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (pData->eSigtype == mng_it_mng) /* check global and embedded empty chunks */ - { -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - { - if ((iRawlen == 0) && (!(pDescr->iAllowed & MNG_DESCR_EMPTYEMBED))) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } else { - if ((iRawlen == 0) && (!(pDescr->iAllowed & MNG_DESCR_EMPTYGLOBAL))) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - } - - if (pDescr->pSpecialfunc) /* need special processing ? */ - { - iRetcode = create_chunk_storage (pData, pHeader, iRawlen, pRawdata, - pField, iFields, ppChunk, MNG_TRUE); - if (iRetcode) /* on error bail out */ - return iRetcode; - /* empty indicator ? */ - if ((!iRawlen) && (pDescr->iOffsetempty)) - *(((mng_uint8p)*ppChunk)+pDescr->iOffsetempty) = MNG_TRUE; - - iRetcode = pDescr->pSpecialfunc(pData, *ppChunk); - if (iRetcode) /* on error bail out */ - return iRetcode; - - if ((((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_IDAT) || - (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_JDAT) || - (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_JDAA) ) - { - iRetcode = ((mng_chunk_headerp)*ppChunk)->fCleanup (pData, *ppChunk); - if (iRetcode) /* on error bail out */ - return iRetcode; - *ppChunk = MNG_NULL; - } else { -#ifdef MNG_STORE_CHUNKS - if (!pData->bStorechunks) -#endif - { - iRetcode = ((mng_chunk_headerp)*ppChunk)->fCleanup (pData, *ppChunk); - if (iRetcode) /* on error bail out */ - return iRetcode; - *ppChunk = MNG_NULL; - } - } - } - -#ifdef MNG_SUPPORT_DISPLAY - if (iRawlen) - { -#ifdef MNG_OPTIMIZE_DISPLAYCALLS - pData->iRawlen = iRawlen; - pData->pRawdata = pRawdata; -#endif - - /* display processing */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_IDAT) - iRetcode = mng_process_display_idat (pData, iRawlen, pRawdata); -#ifdef MNG_INCLUDE_JNG - else - if (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_JDAT) - iRetcode = mng_process_display_jdat (pData, iRawlen, pRawdata); - else - if (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_JDAA) - iRetcode = mng_process_display_jdaa (pData, iRawlen, pRawdata); -#endif -#else - if (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_IDAT) - iRetcode = mng_process_display_idat (pData); -#ifdef MNG_INCLUDE_JNG - else - if (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_JDAT) - iRetcode = mng_process_display_jdat (pData); - else - if (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_JDAA) - iRetcode = mng_process_display_jdaa (pData); -#endif -#endif - - if (iRetcode) - return iRetcode; - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if ((pData->bStorechunks) && (!(*ppChunk))) - { - iRetcode = create_chunk_storage (pData, pHeader, iRawlen, pRawdata, - pField, iFields, ppChunk, MNG_FALSE); - if (iRetcode) /* on error bail out */ - return iRetcode; - /* empty indicator ? */ - if ((!iRawlen) && (pDescr->iOffsetempty)) - *(((mng_uint8p)*ppChunk)+pDescr->iOffsetempty) = MNG_TRUE; - } -#endif /* MNG_STORE_CHUNKS */ - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#endif /* MNG_OPTIMIZE_CHUNKREADER */ - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -READ_CHUNK (mng_read_ihdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_IHDR, MNG_LC_START); -#endif - - if (iRawlen != 13) /* length oke ? */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - /* only allowed inside PNG or MNG */ - if ((pData->eSigtype != mng_it_png) && (pData->eSigtype != mng_it_mng)) - MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); - /* sequence checks */ - if ((pData->eSigtype == mng_it_png) && (pData->iChunkseq > 1)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasIDAT) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasIDAT)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - pData->bHasIHDR = MNG_TRUE; /* indicate IHDR is present */ - /* and store interesting fields */ - if ((!pData->bHasDHDR) || (pData->iDeltatype == MNG_DELTATYPE_NOCHANGE)) - { - pData->iDatawidth = mng_get_uint32 (pRawdata); - pData->iDataheight = mng_get_uint32 (pRawdata+4); - } - - pData->iBitdepth = *(pRawdata+8); - pData->iColortype = *(pRawdata+9); - pData->iCompression = *(pRawdata+10); - pData->iFilter = *(pRawdata+11); - pData->iInterlace = *(pRawdata+12); - -#if defined(MNG_NO_1_2_4BIT_SUPPORT) || defined(MNG_NO_16BIT_SUPPORT) - pData->iPNGmult = 1; - pData->iPNGdepth = pData->iBitdepth; -#endif - -#ifdef MNG_NO_1_2_4BIT_SUPPORT - if (pData->iBitdepth < 8) - pData->iBitdepth = 8; -#endif - -#ifdef MNG_NO_16BIT_SUPPORT - if (pData->iBitdepth > 8) - { - pData->iBitdepth = 8; - pData->iPNGmult = 2; - } -#endif - - if ((pData->iBitdepth != 8) /* parameter validity checks */ -#ifndef MNG_NO_1_2_4BIT_SUPPORT - && (pData->iBitdepth != 1) && - (pData->iBitdepth != 2) && - (pData->iBitdepth != 4) -#endif -#ifndef MNG_NO_16BIT_SUPPORT - && (pData->iBitdepth != 16) -#endif - ) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if ((pData->iColortype != MNG_COLORTYPE_GRAY ) && - (pData->iColortype != MNG_COLORTYPE_RGB ) && - (pData->iColortype != MNG_COLORTYPE_INDEXED) && - (pData->iColortype != MNG_COLORTYPE_GRAYA ) && - (pData->iColortype != MNG_COLORTYPE_RGBA ) ) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - - if ((pData->iColortype == MNG_COLORTYPE_INDEXED) && (pData->iBitdepth > 8)) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if (((pData->iColortype == MNG_COLORTYPE_RGB ) || - (pData->iColortype == MNG_COLORTYPE_GRAYA ) || - (pData->iColortype == MNG_COLORTYPE_RGBA ) ) && - (pData->iBitdepth < 8 ) ) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if (pData->iCompression != MNG_COMPRESSION_DEFLATE) - MNG_ERROR (pData, MNG_INVALIDCOMPRESS); - -#if defined(FILTER192) || defined(FILTER193) - if ((pData->iFilter != MNG_FILTER_ADAPTIVE ) && -#if defined(FILTER192) && defined(FILTER193) - (pData->iFilter != MNG_FILTER_DIFFERING) && - (pData->iFilter != MNG_FILTER_NOFILTER ) ) -#else -#ifdef FILTER192 - (pData->iFilter != MNG_FILTER_DIFFERING) ) -#else - (pData->iFilter != MNG_FILTER_NOFILTER ) ) -#endif -#endif - MNG_ERROR (pData, MNG_INVALIDFILTER); -#else - if (pData->iFilter) - MNG_ERROR (pData, MNG_INVALIDFILTER); -#endif - - if ((pData->iInterlace != MNG_INTERLACE_NONE ) && - (pData->iInterlace != MNG_INTERLACE_ADAM7) ) - MNG_ERROR (pData, MNG_INVALIDINTERLACE); - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* check the colortype for delta-images ! */ - { - mng_imagedatap pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; - - if (pData->iColortype != pBuf->iColortype) - { - if ( ( (pData->iColortype != MNG_COLORTYPE_INDEXED) || - (pBuf->iColortype == MNG_COLORTYPE_GRAY ) ) && - ( (pData->iColortype != MNG_COLORTYPE_GRAY ) || - (pBuf->iColortype == MNG_COLORTYPE_INDEXED) ) ) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - } - } -#endif -#endif - - if (!pData->bHasheader) /* first chunk ? */ - { - pData->bHasheader = MNG_TRUE; /* we've got a header */ - pData->eImagetype = mng_it_png; /* then this must be a PNG */ - pData->iWidth = pData->iDatawidth; - pData->iHeight = pData->iDataheight; - /* predict alpha-depth ! */ - if ((pData->iColortype == MNG_COLORTYPE_GRAYA ) || - (pData->iColortype == MNG_COLORTYPE_RGBA ) ) - pData->iAlphadepth = pData->iBitdepth; - else - if (pData->iColortype == MNG_COLORTYPE_INDEXED) - pData->iAlphadepth = 8; /* worst case scenario */ - else - pData->iAlphadepth = 1; /* Possible tRNS cheap binary transparency */ - /* fits on maximum canvas ? */ - if ((pData->iWidth > pData->iMaxwidth) || (pData->iHeight > pData->iMaxheight)) - MNG_WARNING (pData, MNG_IMAGETOOLARGE); - -#if !defined(MNG_INCLUDE_MPNG_PROPOSAL) || !defined(MNG_SUPPORT_DISPLAY) - if (pData->fProcessheader) /* inform the app ? */ - if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) - MNG_ERROR (pData, MNG_APPMISCERROR); -#endif - } - - if (!pData->bHasDHDR) - pData->iImagelevel++; /* one level deeper */ - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode = mng_process_display_ihdr (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the fields */ - ((mng_ihdrp)*ppChunk)->iWidth = mng_get_uint32 (pRawdata); - ((mng_ihdrp)*ppChunk)->iHeight = mng_get_uint32 (pRawdata+4); - ((mng_ihdrp)*ppChunk)->iBitdepth = pData->iBitdepth; - ((mng_ihdrp)*ppChunk)->iColortype = pData->iColortype; - ((mng_ihdrp)*ppChunk)->iCompression = pData->iCompression; - ((mng_ihdrp)*ppChunk)->iFilter = pData->iFilter; - ((mng_ihdrp)*ppChunk)->iInterlace = pData->iInterlace; - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_IHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif /* MNG_OPTIMIZE_CHUNKREADER */ - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -READ_CHUNK (mng_read_plte) -{ -#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) - mng_uint32 iX; - mng_uint8p pRawdata2; -#endif -#ifdef MNG_SUPPORT_DISPLAY - mng_uint32 iRawlen2; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_PLTE, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIDAT) || (pData->bHasJHDR)) -#else - if (pData->bHasIDAT) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* multiple PLTE only inside BASI */ - if ((pData->bHasPLTE) && (!pData->bHasBASI)) - MNG_ERROR (pData, MNG_MULTIPLEERROR); - /* length must be multiple of 3 */ - if (((iRawlen % 3) != 0) || (iRawlen > 768)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - { /* only allowed for indexed-color or - rgb(a)-color! */ - if ((pData->iColortype != 2) && (pData->iColortype != 3) && (pData->iColortype != 6)) - MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); - /* empty only allowed if global present */ - if ((iRawlen == 0) && (!pData->bHasglobalPLTE)) - MNG_ERROR (pData, MNG_CANNOTBEEMPTY); - } - else - { - if (iRawlen == 0) /* cannot be empty as global! */ - MNG_ERROR (pData, MNG_CANNOTBEEMPTY); - } - - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - pData->bHasPLTE = MNG_TRUE; /* got it! */ - else - pData->bHasglobalPLTE = MNG_TRUE; - - pData->iPLTEcount = iRawlen / 3; - -#ifdef MNG_SUPPORT_DISPLAY - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - { - mng_imagep pImage; - mng_imagedatap pBuf; - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* processing delta-image ? */ - { /* store in object 0 !!! */ - pImage = (mng_imagep)pData->pObjzero; - pBuf = pImage->pImgbuf; - pBuf->bHasPLTE = MNG_TRUE; /* it's definitely got a PLTE now */ - pBuf->iPLTEcount = iRawlen / 3; /* this is the exact length */ - pRawdata2 = pRawdata; /* copy the entries */ - - for (iX = 0; iX < iRawlen / 3; iX++) - { - pBuf->aPLTEentries[iX].iRed = *pRawdata2; - pBuf->aPLTEentries[iX].iGreen = *(pRawdata2+1); - pBuf->aPLTEentries[iX].iBlue = *(pRawdata2+2); - - pRawdata2 += 3; - } - } - else -#endif - { /* get the current object */ - pImage = (mng_imagep)pData->pCurrentobj; - - if (!pImage) /* no object then dump it in obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - - pBuf = pImage->pImgbuf; /* address the object buffer */ - pBuf->bHasPLTE = MNG_TRUE; /* and tell it it's got a PLTE now */ - - if (!iRawlen) /* if empty, inherit from global */ - { - pBuf->iPLTEcount = pData->iGlobalPLTEcount; - MNG_COPY (pBuf->aPLTEentries, pData->aGlobalPLTEentries, - sizeof (pBuf->aPLTEentries)); - - if (pData->bHasglobalTRNS) /* also copy global tRNS ? */ - { /* indicate tRNS available */ - pBuf->bHasTRNS = MNG_TRUE; - - iRawlen2 = pData->iGlobalTRNSrawlen; - pRawdata2 = (mng_uint8p)(pData->aGlobalTRNSrawdata); - /* global length oke ? */ - if ((iRawlen2 == 0) || (iRawlen2 > pBuf->iPLTEcount)) - MNG_ERROR (pData, MNG_GLOBALLENGTHERR); - /* copy it */ - pBuf->iTRNScount = iRawlen2; - MNG_COPY (pBuf->aTRNSentries, pRawdata2, iRawlen2); - } - } - else - { /* store fields for future reference */ - pBuf->iPLTEcount = iRawlen / 3; - pRawdata2 = pRawdata; - - for (iX = 0; iX < pBuf->iPLTEcount; iX++) - { - pBuf->aPLTEentries[iX].iRed = *pRawdata2; - pBuf->aPLTEentries[iX].iGreen = *(pRawdata2+1); - pBuf->aPLTEentries[iX].iBlue = *(pRawdata2+2); - - pRawdata2 += 3; - } - } - } - } - else /* store as global */ - { - pData->iGlobalPLTEcount = iRawlen / 3; - pRawdata2 = pRawdata; - - for (iX = 0; iX < pData->iGlobalPLTEcount; iX++) - { - pData->aGlobalPLTEentries[iX].iRed = *pRawdata2; - pData->aGlobalPLTEentries[iX].iGreen = *(pRawdata2+1); - pData->aGlobalPLTEentries[iX].iBlue = *(pRawdata2+2); - - pRawdata2 += 3; - } - - { /* create an animation object */ - mng_retcode iRetcode = mng_create_ani_plte (pData, pData->iGlobalPLTEcount, - pData->aGlobalPLTEentries); - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_pltep)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - ((mng_pltep)*ppChunk)->iEntrycount = iRawlen / 3; - pRawdata2 = pRawdata; - - for (iX = 0; iX < ((mng_pltep)*ppChunk)->iEntrycount; iX++) - { - ((mng_pltep)*ppChunk)->aEntries[iX].iRed = *pRawdata2; - ((mng_pltep)*ppChunk)->aEntries[iX].iGreen = *(pRawdata2+1); - ((mng_pltep)*ppChunk)->aEntries[iX].iBlue = *(pRawdata2+2); - - pRawdata2 += 3; - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_PLTE, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif /* MNG_OPTIMIZE_CHUNKREADER */ - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -READ_CHUNK (mng_read_idat) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_IDAT, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_JNG /* sequence checks */ - if ((!pData->bHasIHDR) && (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasIHDR) && (!pData->bHasBASI) && (!pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasJHDR) && - (pData->iJHDRalphacompression != MNG_COMPRESSION_DEFLATE)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (pData->bHasJSEP) - MNG_ERROR (pData, MNG_SEQUENCEERROR); -#endif - /* not allowed for deltatype NO_CHANGE */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && ((pData->iDeltatype == MNG_DELTATYPE_NOCHANGE))) - MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); -#endif - /* can only be empty in BASI-block! */ - if ((iRawlen == 0) && (!pData->bHasBASI)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - /* indexed-color requires PLTE */ - if ((pData->bHasIHDR) && (pData->iColortype == 3) && (!pData->bHasPLTE)) - MNG_ERROR (pData, MNG_PLTEMISSING); - - pData->bHasIDAT = MNG_TRUE; /* got some IDAT now, don't we */ - -#ifdef MNG_SUPPORT_DISPLAY - if (iRawlen) - { /* display processing */ - mng_retcode iRetcode = mng_process_display_idat (pData, iRawlen, pRawdata); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_idatp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - ((mng_idatp)*ppChunk)->iDatasize = iRawlen; - - if (iRawlen != 0) /* is there any data ? */ - { - MNG_ALLOC (pData, ((mng_idatp)*ppChunk)->pData, iRawlen); - MNG_COPY (((mng_idatp)*ppChunk)->pData, pRawdata, iRawlen); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_IDAT, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -READ_CHUNK (mng_read_iend) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_IEND, MNG_LC_START); -#endif - - if (iRawlen > 0) /* must not contain data! */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_INCLUDE_JNG /* sequence checks */ - if ((!pData->bHasIHDR) && (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasIHDR) && (!pData->bHasBASI) && (!pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* IHDR-block requires IDAT */ - if ((pData->bHasIHDR) && (!pData->bHasIDAT)) - MNG_ERROR (pData, MNG_IDATMISSING); - - pData->iImagelevel--; /* one level up */ - -#ifdef MNG_SUPPORT_DISPLAY - { /* create an animation object */ - mng_retcode iRetcode = mng_create_ani_image (pData); - if (iRetcode) /* on error bail out */ - return iRetcode; - /* display processing */ - iRetcode = mng_process_display_iend (pData); - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_SUPPORT_DISPLAY - if (!pData->bTimerset) /* reset only if not broken !!! */ - { -#endif - /* IEND signals the end for most ... */ - pData->bHasIHDR = MNG_FALSE; - pData->bHasBASI = MNG_FALSE; - pData->bHasDHDR = MNG_FALSE; -#ifdef MNG_INCLUDE_JNG - pData->bHasJHDR = MNG_FALSE; - pData->bHasJSEP = MNG_FALSE; - pData->bHasJDAA = MNG_FALSE; - pData->bHasJDAT = MNG_FALSE; -#endif - pData->bHasPLTE = MNG_FALSE; - pData->bHasTRNS = MNG_FALSE; - pData->bHasGAMA = MNG_FALSE; - pData->bHasCHRM = MNG_FALSE; - pData->bHasSRGB = MNG_FALSE; - pData->bHasICCP = MNG_FALSE; - pData->bHasBKGD = MNG_FALSE; - pData->bHasIDAT = MNG_FALSE; -#ifdef MNG_SUPPORT_DISPLAY - } -#endif - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_IEND, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -READ_CHUNK (mng_read_trns) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_TRNS, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIDAT) || (pData->bHasJHDR)) -#else - if (pData->bHasIDAT) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* multiple tRNS only inside BASI */ - if ((pData->bHasTRNS) && (!pData->bHasBASI)) - MNG_ERROR (pData, MNG_MULTIPLEERROR); - - if (iRawlen > 256) /* it just can't be bigger than that! */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - { /* not allowed with full alpha-channel */ - if ((pData->iColortype == 4) || (pData->iColortype == 6)) - MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); - - if (iRawlen != 0) /* filled ? */ - { /* length checks */ - if ((pData->iColortype == 0) && (iRawlen != 2)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((pData->iColortype == 2) && (iRawlen != 6)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - if (pData->iColortype == 3) - { - mng_imagep pImage = (mng_imagep)pData->pCurrentobj; - mng_imagedatap pBuf; - - if (!pImage) /* no object then check obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - - pBuf = pImage->pImgbuf; /* address object buffer */ - - if (iRawlen > pBuf->iPLTEcount) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } -#endif - } - else /* if empty there must be global stuff! */ - { - if (!pData->bHasglobalTRNS) - MNG_ERROR (pData, MNG_CANNOTBEEMPTY); - } - } - - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - pData->bHasTRNS = MNG_TRUE; /* indicate tRNS available */ - else - pData->bHasglobalTRNS = MNG_TRUE; - -#ifdef MNG_SUPPORT_DISPLAY - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - { - mng_imagep pImage; - mng_imagedatap pBuf; - mng_uint8p pRawdata2; - mng_uint32 iRawlen2; - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* processing delta-image ? */ - { /* store in object 0 !!! */ - pImage = (mng_imagep)pData->pObjzero; - pBuf = pImage->pImgbuf; /* address object buffer */ - - switch (pData->iColortype) /* store fields for future reference */ - { - case 0: { /* gray */ -#if defined(MNG_NO_1_2_4BIT_SUPPORT) - mng_uint8 multiplier[]={0,255,85,0,17,0,0,0,1, - 0,0,0,0,0,0,0,1}; -#endif - pBuf->iTRNSgray = mng_get_uint16 (pRawdata); - pBuf->iTRNSred = 0; - pBuf->iTRNSgreen = 0; - pBuf->iTRNSblue = 0; - pBuf->iTRNScount = 0; -#if defined(MNG_NO_1_2_4BIT_SUPPORT) - pBuf->iTRNSgray *= multiplier[pData->iPNGdepth]; -#endif -#if defined(MNG_NO_16BIT_SUPPORT) - if (pData->iPNGmult == 2) - pBuf->iTRNSgray >>= 8; -#endif - break; - } - case 2: { /* rgb */ - pBuf->iTRNSgray = 0; - pBuf->iTRNSred = mng_get_uint16 (pRawdata); - pBuf->iTRNSgreen = mng_get_uint16 (pRawdata+2); - pBuf->iTRNSblue = mng_get_uint16 (pRawdata+4); - pBuf->iTRNScount = 0; -#if defined(MNG_NO_16BIT_SUPPORT) - if (pData->iPNGmult == 2) - { - pBuf->iTRNSred >>= 8; - pBuf->iTRNSgreen >>= 8; - pBuf->iTRNSblue >>= 8; - } -#endif - break; - } - case 3: { /* indexed */ - pBuf->iTRNSgray = 0; - pBuf->iTRNSred = 0; - pBuf->iTRNSgreen = 0; - pBuf->iTRNSblue = 0; - pBuf->iTRNScount = iRawlen; - MNG_COPY (pBuf->aTRNSentries, pRawdata, iRawlen); - break; - } - } - - pBuf->bHasTRNS = MNG_TRUE; /* tell it it's got a tRNS now */ - } - else -#endif - { /* address current object */ - pImage = (mng_imagep)pData->pCurrentobj; - - if (!pImage) /* no object then dump it in obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - - pBuf = pImage->pImgbuf; /* address object buffer */ - pBuf->bHasTRNS = MNG_TRUE; /* and tell it it's got a tRNS now */ - - if (iRawlen == 0) /* if empty, inherit from global */ - { - iRawlen2 = pData->iGlobalTRNSrawlen; - pRawdata2 = (mng_ptr)(pData->aGlobalTRNSrawdata); - /* global length oke ? */ - if ((pData->iColortype == 0) && (iRawlen2 != 2)) - MNG_ERROR (pData, MNG_GLOBALLENGTHERR); - - if ((pData->iColortype == 2) && (iRawlen2 != 6)) - MNG_ERROR (pData, MNG_GLOBALLENGTHERR); - - if ((pData->iColortype == 3) && ((iRawlen2 == 0) || (iRawlen2 > pBuf->iPLTEcount))) - MNG_ERROR (pData, MNG_GLOBALLENGTHERR); - } - else - { - iRawlen2 = iRawlen; - pRawdata2 = pRawdata; - } - - switch (pData->iColortype) /* store fields for future reference */ - { - case 0: { /* gray */ - pBuf->iTRNSgray = mng_get_uint16 (pRawdata2); - pBuf->iTRNSred = 0; - pBuf->iTRNSgreen = 0; - pBuf->iTRNSblue = 0; - pBuf->iTRNScount = 0; -#if defined(MNG_NO_16BIT_SUPPORT) - if (pData->iPNGmult == 2) - pBuf->iTRNSgray >>= 8; -#endif - break; - } - case 2: { /* rgb */ - pBuf->iTRNSgray = 0; - pBuf->iTRNSred = mng_get_uint16 (pRawdata2); - pBuf->iTRNSgreen = mng_get_uint16 (pRawdata2+2); - pBuf->iTRNSblue = mng_get_uint16 (pRawdata2+4); - pBuf->iTRNScount = 0; -#if defined(MNG_NO_16BIT_SUPPORT) - if (pData->iPNGmult == 2) - { - pBuf->iTRNSred >>= 8; - pBuf->iTRNSgreen >>= 8; - pBuf->iTRNSblue >>= 8; - } -#endif - break; - } - case 3: { /* indexed */ - pBuf->iTRNSgray = 0; - pBuf->iTRNSred = 0; - pBuf->iTRNSgreen = 0; - pBuf->iTRNSblue = 0; - pBuf->iTRNScount = iRawlen2; - MNG_COPY (pBuf->aTRNSentries, pRawdata2, iRawlen2); - break; - } - } - } - } - else /* store as global */ - { - pData->iGlobalTRNSrawlen = iRawlen; - MNG_COPY (pData->aGlobalTRNSrawdata, pRawdata, iRawlen); - - { /* create an animation object */ - mng_retcode iRetcode = mng_create_ani_trns (pData, pData->iGlobalTRNSrawlen, - pData->aGlobalTRNSrawdata); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - { /* not global! */ - ((mng_trnsp)*ppChunk)->bGlobal = MNG_FALSE; - ((mng_trnsp)*ppChunk)->iType = pData->iColortype; - - if (iRawlen == 0) /* if empty, indicate so */ - ((mng_trnsp)*ppChunk)->bEmpty = MNG_TRUE; - else - { - ((mng_trnsp)*ppChunk)->bEmpty = MNG_FALSE; - - switch (pData->iColortype) /* store fields */ - { - case 0: { /* gray */ - ((mng_trnsp)*ppChunk)->iGray = mng_get_uint16 (pRawdata); - break; - } - case 2: { /* rgb */ - ((mng_trnsp)*ppChunk)->iRed = mng_get_uint16 (pRawdata); - ((mng_trnsp)*ppChunk)->iGreen = mng_get_uint16 (pRawdata+2); - ((mng_trnsp)*ppChunk)->iBlue = mng_get_uint16 (pRawdata+4); - break; - } - case 3: { /* indexed */ - ((mng_trnsp)*ppChunk)->iCount = iRawlen; - MNG_COPY (((mng_trnsp)*ppChunk)->aEntries, pRawdata, iRawlen); - break; - } - } - } - } - else /* it's global! */ - { - ((mng_trnsp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - ((mng_trnsp)*ppChunk)->bGlobal = MNG_TRUE; - ((mng_trnsp)*ppChunk)->iType = 0; - ((mng_trnsp)*ppChunk)->iRawlen = iRawlen; - - MNG_COPY (((mng_trnsp)*ppChunk)->aRawdata, pRawdata, iRawlen); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_TRNS, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -READ_CHUNK (mng_read_gama) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_GAMA, MNG_LC_START); -#endif - /* sequence checks */ -#ifdef MNG_INCLUDE_JNG - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIDAT) || (pData->bHasPLTE) || (pData->bHasJDAT) || (pData->bHasJDAA)) -#else - if ((pData->bHasIDAT) || (pData->bHasPLTE)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - { /* length must be exactly 4 */ - if (iRawlen != 4) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - else - { /* length must be empty or exactly 4 */ - if ((iRawlen != 0) && (iRawlen != 4)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - pData->bHasGAMA = MNG_TRUE; /* indicate we've got it */ - else - pData->bHasglobalGAMA = (mng_bool)(iRawlen != 0); - -#ifdef MNG_SUPPORT_DISPLAY -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - { - mng_imagep pImage; - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* update delta image ? */ - { /* store in object 0 ! */ - pImage = (mng_imagep)pData->pObjzero; - /* store for color-processing routines */ - pImage->pImgbuf->iGamma = mng_get_uint32 (pRawdata); - pImage->pImgbuf->bHasGAMA = MNG_TRUE; - } - else -#endif - { - pImage = (mng_imagep)pData->pCurrentobj; - - if (!pImage) /* no object then dump it in obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - /* store for color-processing routines */ - pImage->pImgbuf->iGamma = mng_get_uint32 (pRawdata); - pImage->pImgbuf->bHasGAMA = MNG_TRUE; - } - } - else - { /* store as global */ - if (iRawlen != 0) - pData->iGlobalGamma = mng_get_uint32 (pRawdata); - - { /* create an animation object */ - mng_retcode iRetcode = mng_create_ani_gama (pData, (mng_bool)(iRawlen == 0), - pData->iGlobalGamma); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_gamap)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - - if (iRawlen) - ((mng_gamap)*ppChunk)->iGamma = mng_get_uint32 (pRawdata); - - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_GAMA, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_cHRM -READ_CHUNK (mng_read_chrm) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_CHRM, MNG_LC_START); -#endif - /* sequence checks */ -#ifdef MNG_INCLUDE_JNG - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIDAT) || (pData->bHasPLTE) || (pData->bHasJDAT) || (pData->bHasJDAA)) -#else - if ((pData->bHasIDAT) || (pData->bHasPLTE)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - { /* length must be exactly 32 */ - if (iRawlen != 32) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - else - { /* length must be empty or exactly 32 */ - if ((iRawlen != 0) && (iRawlen != 32)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - pData->bHasCHRM = MNG_TRUE; /* indicate we've got it */ - else - pData->bHasglobalCHRM = (mng_bool)(iRawlen != 0); - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_uint32 iWhitepointx, iWhitepointy; - mng_uint32 iPrimaryredx, iPrimaryredy; - mng_uint32 iPrimarygreenx, iPrimarygreeny; - mng_uint32 iPrimarybluex, iPrimarybluey; - - iWhitepointx = mng_get_uint32 (pRawdata); - iWhitepointy = mng_get_uint32 (pRawdata+4); - iPrimaryredx = mng_get_uint32 (pRawdata+8); - iPrimaryredy = mng_get_uint32 (pRawdata+12); - iPrimarygreenx = mng_get_uint32 (pRawdata+16); - iPrimarygreeny = mng_get_uint32 (pRawdata+20); - iPrimarybluex = mng_get_uint32 (pRawdata+24); - iPrimarybluey = mng_get_uint32 (pRawdata+28); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - { - mng_imagep pImage; - mng_imagedatap pBuf; - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* update delta image ? */ - { /* store it in object 0 ! */ - pImage = (mng_imagep)pData->pObjzero; - - pBuf = pImage->pImgbuf; /* address object buffer */ - pBuf->bHasCHRM = MNG_TRUE; /* and tell it it's got a CHRM now */ - /* store for color-processing routines */ - pBuf->iWhitepointx = iWhitepointx; - pBuf->iWhitepointy = iWhitepointy; - pBuf->iPrimaryredx = iPrimaryredx; - pBuf->iPrimaryredy = iPrimaryredy; - pBuf->iPrimarygreenx = iPrimarygreenx; - pBuf->iPrimarygreeny = iPrimarygreeny; - pBuf->iPrimarybluex = iPrimarybluex; - pBuf->iPrimarybluey = iPrimarybluey; - } - else -#endif - { - pImage = (mng_imagep)pData->pCurrentobj; - - if (!pImage) /* no object then dump it in obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - - pBuf = pImage->pImgbuf; /* address object buffer */ - pBuf->bHasCHRM = MNG_TRUE; /* and tell it it's got a CHRM now */ - /* store for color-processing routines */ - pBuf->iWhitepointx = iWhitepointx; - pBuf->iWhitepointy = iWhitepointy; - pBuf->iPrimaryredx = iPrimaryredx; - pBuf->iPrimaryredy = iPrimaryredy; - pBuf->iPrimarygreenx = iPrimarygreenx; - pBuf->iPrimarygreeny = iPrimarygreeny; - pBuf->iPrimarybluex = iPrimarybluex; - pBuf->iPrimarybluey = iPrimarybluey; - } - } - else - { /* store as global */ - if (iRawlen != 0) - { - pData->iGlobalWhitepointx = iWhitepointx; - pData->iGlobalWhitepointy = iWhitepointy; - pData->iGlobalPrimaryredx = iPrimaryredx; - pData->iGlobalPrimaryredy = iPrimaryredy; - pData->iGlobalPrimarygreenx = iPrimarygreenx; - pData->iGlobalPrimarygreeny = iPrimarygreeny; - pData->iGlobalPrimarybluex = iPrimarybluex; - pData->iGlobalPrimarybluey = iPrimarybluey; - } - - { /* create an animation object */ - mng_retcode iRetcode = mng_create_ani_chrm (pData, (mng_bool)(iRawlen == 0), - iWhitepointx, iWhitepointy, - iPrimaryredx, iPrimaryredy, - iPrimarygreenx, iPrimarygreeny, - iPrimarybluex, iPrimarybluey); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_chrmp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - - if (iRawlen) - { - ((mng_chrmp)*ppChunk)->iWhitepointx = mng_get_uint32 (pRawdata); - ((mng_chrmp)*ppChunk)->iWhitepointy = mng_get_uint32 (pRawdata+4); - ((mng_chrmp)*ppChunk)->iRedx = mng_get_uint32 (pRawdata+8); - ((mng_chrmp)*ppChunk)->iRedy = mng_get_uint32 (pRawdata+12); - ((mng_chrmp)*ppChunk)->iGreenx = mng_get_uint32 (pRawdata+16); - ((mng_chrmp)*ppChunk)->iGreeny = mng_get_uint32 (pRawdata+20); - ((mng_chrmp)*ppChunk)->iBluex = mng_get_uint32 (pRawdata+24); - ((mng_chrmp)*ppChunk)->iBluey = mng_get_uint32 (pRawdata+28); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_CHRM, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -READ_CHUNK (mng_read_srgb) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_SRGB, MNG_LC_START); -#endif - /* sequence checks */ -#ifdef MNG_INCLUDE_JNG - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIDAT) || (pData->bHasPLTE) || (pData->bHasJDAT) || (pData->bHasJDAA)) -#else - if ((pData->bHasIDAT) || (pData->bHasPLTE)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - { /* length must be exactly 1 */ - if (iRawlen != 1) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - else - { /* length must be empty or exactly 1 */ - if ((iRawlen != 0) && (iRawlen != 1)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - pData->bHasSRGB = MNG_TRUE; /* indicate we've got it */ - else - pData->bHasglobalSRGB = (mng_bool)(iRawlen != 0); - -#ifdef MNG_SUPPORT_DISPLAY -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - { - mng_imagep pImage; - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* update delta image ? */ - { /* store in object 0 ! */ - pImage = (mng_imagep)pData->pObjzero; - /* store for color-processing routines */ - pImage->pImgbuf->iRenderingintent = *pRawdata; - pImage->pImgbuf->bHasSRGB = MNG_TRUE; - } - else -#endif - { - pImage = (mng_imagep)pData->pCurrentobj; - - if (!pImage) /* no object then dump it in obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - /* store for color-processing routines */ - pImage->pImgbuf->iRenderingintent = *pRawdata; - pImage->pImgbuf->bHasSRGB = MNG_TRUE; - } - } - else - { /* store as global */ - if (iRawlen != 0) - pData->iGlobalRendintent = *pRawdata; - - { /* create an animation object */ - mng_retcode iRetcode = mng_create_ani_srgb (pData, (mng_bool)(iRawlen == 0), - pData->iGlobalRendintent); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_srgbp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - - if (iRawlen) - ((mng_srgbp)*ppChunk)->iRenderingintent = *pRawdata; - - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_SRGB, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_iCCP -READ_CHUNK (mng_read_iccp) -{ - mng_retcode iRetcode; - mng_uint8p pTemp; - mng_uint32 iCompressedsize; - mng_uint32 iProfilesize; - mng_uint32 iBufsize = 0; - mng_uint8p pBuf = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_ICCP, MNG_LC_START); -#endif - /* sequence checks */ -#ifdef MNG_INCLUDE_JNG - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIDAT) || (pData->bHasPLTE) || (pData->bHasJDAT) || (pData->bHasJDAA)) -#else - if ((pData->bHasIDAT) || (pData->bHasPLTE)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - { /* length must be at least 2 */ - if (iRawlen < 2) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - else - { /* length must be empty or at least 2 */ - if ((iRawlen != 0) && (iRawlen < 2)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - - pTemp = find_null (pRawdata); /* find null-separator */ - /* not found inside input-data ? */ - if ((pTemp - pRawdata) > (mng_int32)iRawlen) - MNG_ERROR (pData, MNG_NULLNOTFOUND); - /* determine size of compressed profile */ - iCompressedsize = (mng_uint32)(iRawlen - (pTemp - pRawdata) - 2); - /* decompress the profile */ - iRetcode = mng_inflate_buffer (pData, pTemp+2, iCompressedsize, - &pBuf, &iBufsize, &iProfilesize); - -#ifdef MNG_CHECK_BAD_ICCP /* Check for bad iCCP chunk */ - if ((iRetcode) && (!strncmp ((char *)pRawdata, "Photoshop ICC profile", 21))) - { - if (iRawlen == 2615) /* is it the sRGB profile ? */ - { - mng_chunk_header chunk_srgb = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_sRGB, mng_init_general, mng_free_general, mng_read_srgb, mng_write_srgb, mng_assign_general, 0, 0, sizeof(mng_srgb)}; -#else - {MNG_UINT_sRGB, mng_init_srgb, mng_free_srgb, mng_read_srgb, mng_write_srgb, mng_assign_srgb, 0, 0}; -#endif - /* pretend it's an sRGB chunk then ! */ - iRetcode = mng_read_srgb (pData, &chunk_srgb, 1, (mng_ptr)"0", ppChunk); - - if (iRetcode) /* on error bail out */ - { /* don't forget to drop the temp buffer */ - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - } - } - else - { -#endif /* MNG_CHECK_BAD_ICCP */ - - if (iRetcode) /* on error bail out */ - { /* don't forget to drop the temp buffer */ - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - pData->bHasICCP = MNG_TRUE; /* indicate we've got it */ - else - pData->bHasglobalICCP = (mng_bool)(iRawlen != 0); - -#ifdef MNG_SUPPORT_DISPLAY -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - { - mng_imagep pImage; - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* update delta image ? */ - { /* store in object 0 ! */ - pImage = (mng_imagep)pData->pObjzero; - - if (pImage->pImgbuf->pProfile) /* profile existed ? */ - MNG_FREEX (pData, pImage->pImgbuf->pProfile, pImage->pImgbuf->iProfilesize); - /* allocate a buffer & copy it */ - MNG_ALLOC (pData, pImage->pImgbuf->pProfile, iProfilesize); - MNG_COPY (pImage->pImgbuf->pProfile, pBuf, iProfilesize); - /* store its length as well */ - pImage->pImgbuf->iProfilesize = iProfilesize; - pImage->pImgbuf->bHasICCP = MNG_TRUE; - } - else -#endif - { - pImage = (mng_imagep)pData->pCurrentobj; - - if (!pImage) /* no object then dump it in obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - - if (pImage->pImgbuf->pProfile) /* profile existed ? */ - MNG_FREEX (pData, pImage->pImgbuf->pProfile, pImage->pImgbuf->iProfilesize); - /* allocate a buffer & copy it */ - MNG_ALLOC (pData, pImage->pImgbuf->pProfile, iProfilesize); - MNG_COPY (pImage->pImgbuf->pProfile, pBuf, iProfilesize); - /* store its length as well */ - pImage->pImgbuf->iProfilesize = iProfilesize; - pImage->pImgbuf->bHasICCP = MNG_TRUE; - } - } - else - { /* store as global */ - if (iRawlen == 0) /* empty chunk ? */ - { - if (pData->pGlobalProfile) /* did we have a global profile ? */ - MNG_FREEX (pData, pData->pGlobalProfile, pData->iGlobalProfilesize); - - pData->iGlobalProfilesize = 0; /* reset to null */ - pData->pGlobalProfile = MNG_NULL; - } - else - { /* allocate a global buffer & copy it */ - MNG_ALLOC (pData, pData->pGlobalProfile, iProfilesize); - MNG_COPY (pData->pGlobalProfile, pBuf, iProfilesize); - /* store its length as well */ - pData->iGlobalProfilesize = iProfilesize; - } - - /* create an animation object */ - iRetcode = mng_create_ani_iccp (pData, (mng_bool)(iRawlen == 0), - pData->iGlobalProfilesize, - pData->pGlobalProfile); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - { /* don't forget to drop the temp buffer */ - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - /* store the fields */ - ((mng_iccpp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - - if (iRawlen) /* not empty ? */ - { - if (!pBuf) /* hasn't been unpuzzled it yet ? */ - { /* find null-separator */ - pTemp = find_null (pRawdata); - /* not found inside input-data ? */ - if ((pTemp - pRawdata) > (mng_int32)iRawlen) - MNG_ERROR (pData, MNG_NULLNOTFOUND); - /* determine size of compressed profile */ - iCompressedsize = iRawlen - (pTemp - pRawdata) - 2; - /* decompress the profile */ - iRetcode = mng_inflate_buffer (pData, pTemp+2, iCompressedsize, - &pBuf, &iBufsize, &iProfilesize); - - if (iRetcode) /* on error bail out */ - { /* don't forget to drop the temp buffer */ - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - } - - ((mng_iccpp)*ppChunk)->iNamesize = (mng_uint32)(pTemp - pRawdata); - - if (((mng_iccpp)*ppChunk)->iNamesize) - { - MNG_ALLOC (pData, ((mng_iccpp)*ppChunk)->zName, - ((mng_iccpp)*ppChunk)->iNamesize + 1); - MNG_COPY (((mng_iccpp)*ppChunk)->zName, pRawdata, - ((mng_iccpp)*ppChunk)->iNamesize); - } - - ((mng_iccpp)*ppChunk)->iCompression = *(pTemp+1); - ((mng_iccpp)*ppChunk)->iProfilesize = iProfilesize; - - MNG_ALLOC (pData, ((mng_iccpp)*ppChunk)->pProfile, iProfilesize); - MNG_COPY (((mng_iccpp)*ppChunk)->pProfile, pBuf, iProfilesize); - } - } -#endif /* MNG_STORE_CHUNKS */ - - if (pBuf) /* free the temporary buffer */ - MNG_FREEX (pData, pBuf, iBufsize); - -#ifdef MNG_CHECK_BAD_ICCP - } -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_ICCP, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_tEXt -READ_CHUNK (mng_read_text) -{ - mng_uint32 iKeywordlen, iTextlen; - mng_pchar zKeyword, zText; - mng_uint8p pTemp; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_TEXT, MNG_LC_START); -#endif - /* sequence checks */ -#ifdef MNG_INCLUDE_JNG - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen < 2) /* length must be at least 2 */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - pTemp = find_null (pRawdata); /* find the null separator */ - /* not found inside input-data ? */ - if ((pTemp - pRawdata) > (mng_int32)iRawlen) - MNG_ERROR (pData, MNG_NULLNOTFOUND); - - if (pTemp == pRawdata) /* there must be at least 1 char for keyword */ - MNG_ERROR (pData, MNG_KEYWORDNULL); - - iKeywordlen = (mng_uint32)(pTemp - pRawdata); - iTextlen = iRawlen - iKeywordlen - 1; - - if (pData->fProcesstext) /* inform the application ? */ - { - mng_bool bOke; - - MNG_ALLOC (pData, zKeyword, iKeywordlen + 1); - MNG_COPY (zKeyword, pRawdata, iKeywordlen); - - MNG_ALLOCX (pData, zText, iTextlen + 1); - - if (!zText) /* on error bail out */ - { - MNG_FREEX (pData, zKeyword, iKeywordlen + 1); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - - if (iTextlen) - MNG_COPY (zText, pTemp+1, iTextlen); - - bOke = pData->fProcesstext ((mng_handle)pData, MNG_TYPE_TEXT, zKeyword, zText, 0, 0); - - MNG_FREEX (pData, zText, iTextlen + 1); - MNG_FREEX (pData, zKeyword, iKeywordlen + 1); - - if (!bOke) - MNG_ERROR (pData, MNG_APPMISCERROR); - - } - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_textp)*ppChunk)->iKeywordsize = iKeywordlen; - ((mng_textp)*ppChunk)->iTextsize = iTextlen; - - if (iKeywordlen) - { - MNG_ALLOC (pData, ((mng_textp)*ppChunk)->zKeyword, iKeywordlen+1); - MNG_COPY (((mng_textp)*ppChunk)->zKeyword, pRawdata, iKeywordlen); - } - - if (iTextlen) - { - MNG_ALLOC (pData, ((mng_textp)*ppChunk)->zText, iTextlen+1); - MNG_COPY (((mng_textp)*ppChunk)->zText, pTemp+1, iTextlen); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_TEXT, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_zTXt -READ_CHUNK (mng_read_ztxt) -{ - mng_retcode iRetcode; - mng_uint32 iKeywordlen, iTextlen; - mng_pchar zKeyword; - mng_uint8p pTemp; - mng_uint32 iCompressedsize; - mng_uint32 iBufsize; - mng_uint8p pBuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_ZTXT, MNG_LC_START); -#endif - /* sequence checks */ -#ifdef MNG_INCLUDE_JNG - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen < 3) /* length must be at least 3 */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - pTemp = find_null (pRawdata); /* find the null separator */ - /* not found inside input-data ? */ - if ((pTemp - pRawdata) > (mng_int32)iRawlen) - MNG_ERROR (pData, MNG_NULLNOTFOUND); - - if (pTemp == pRawdata) /* there must be at least 1 char for keyword */ - MNG_ERROR (pData, MNG_KEYWORDNULL); - - if (*(pTemp+1) != 0) /* only deflate compression-method allowed */ - MNG_ERROR (pData, MNG_INVALIDCOMPRESS); - - iKeywordlen = (mng_uint32)(pTemp - pRawdata); - iCompressedsize = (mng_uint32)(iRawlen - iKeywordlen - 2); - - zKeyword = 0; /* there's no keyword buffer yet */ - pBuf = 0; /* or a temporary buffer ! */ - - if (pData->fProcesstext) /* inform the application ? */ - { /* decompress the text */ - iRetcode = mng_inflate_buffer (pData, pTemp+2, iCompressedsize, - &pBuf, &iBufsize, &iTextlen); - - if (iRetcode) /* on error bail out */ - { /* don't forget to drop the temp buffers */ - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - - MNG_ALLOCX (pData, zKeyword, iKeywordlen+1); - - if (!zKeyword) /* on error bail out */ - { /* don't forget to drop the temp buffers */ - MNG_FREEX (pData, pBuf, iBufsize); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - - MNG_COPY (zKeyword, pRawdata, iKeywordlen); - - if (!pData->fProcesstext ((mng_handle)pData, MNG_TYPE_ZTXT, zKeyword, (mng_pchar)pBuf, 0, 0)) - { /* don't forget to drop the temp buffers */ - MNG_FREEX (pData, pBuf, iBufsize); - MNG_FREEX (pData, zKeyword, iKeywordlen+1); - MNG_ERROR (pData, MNG_APPMISCERROR); - } - } - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - { /* don't forget to drop the temp buffers */ - MNG_FREEX (pData, pBuf, iBufsize); - MNG_FREEX (pData, zKeyword, iKeywordlen+1); - return iRetcode; - } - /* store the fields */ - ((mng_ztxtp)*ppChunk)->iKeywordsize = iKeywordlen; - ((mng_ztxtp)*ppChunk)->iCompression = *(pTemp+1); - - if ((!pBuf) && (iCompressedsize)) /* did we not get a text-buffer yet ? */ - { /* decompress the text */ - iRetcode = mng_inflate_buffer (pData, pTemp+2, iCompressedsize, - &pBuf, &iBufsize, &iTextlen); - - if (iRetcode) /* on error bail out */ - { /* don't forget to drop the temp buffers */ - MNG_FREEX (pData, pBuf, iBufsize); - MNG_FREEX (pData, zKeyword, iKeywordlen+1); - return iRetcode; - } - } - - MNG_ALLOCX (pData, ((mng_ztxtp)*ppChunk)->zKeyword, iKeywordlen + 1); - /* on error bail out */ - if (!((mng_ztxtp)*ppChunk)->zKeyword) - { /* don't forget to drop the temp buffers */ - MNG_FREEX (pData, pBuf, iBufsize); - MNG_FREEX (pData, zKeyword, iKeywordlen+1); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - - MNG_COPY (((mng_ztxtp)*ppChunk)->zKeyword, pRawdata, iKeywordlen); - - ((mng_ztxtp)*ppChunk)->iTextsize = iTextlen; - - if (iCompressedsize) - { - MNG_ALLOCX (pData, ((mng_ztxtp)*ppChunk)->zText, iTextlen + 1); - /* on error bail out */ - if (!((mng_ztxtp)*ppChunk)->zText) - { /* don't forget to drop the temp buffers */ - MNG_FREEX (pData, pBuf, iBufsize); - MNG_FREEX (pData, zKeyword, iKeywordlen+1); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - - MNG_COPY (((mng_ztxtp)*ppChunk)->zText, pBuf, iTextlen); - } - } -#endif /* MNG_STORE_CHUNKS */ - - MNG_FREEX (pData, pBuf, iBufsize); /* free the temporary buffers */ - MNG_FREEX (pData, zKeyword, iKeywordlen+1); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_ZTXT, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_iTXt -READ_CHUNK (mng_read_itxt) -{ - mng_retcode iRetcode; - mng_uint32 iKeywordlen, iTextlen, iLanguagelen, iTranslationlen; - mng_pchar zKeyword, zLanguage, zTranslation; - mng_uint8p pNull1, pNull2, pNull3; - mng_uint32 iCompressedsize; - mng_uint8 iCompressionflag; - mng_uint32 iBufsize; - mng_uint8p pBuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_ITXT, MNG_LC_START); -#endif - /* sequence checks */ -#ifdef MNG_INCLUDE_JNG - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen < 6) /* length must be at least 6 */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - pNull1 = find_null (pRawdata); /* find the null separators */ - pNull2 = find_null (pNull1+3); - pNull3 = find_null (pNull2+1); - /* not found inside input-data ? */ - if (((pNull1 - pRawdata) > (mng_int32)iRawlen) || - ((pNull2 - pRawdata) > (mng_int32)iRawlen) || - ((pNull3 - pRawdata) > (mng_int32)iRawlen) ) - MNG_ERROR (pData, MNG_NULLNOTFOUND); - - if (pNull1 == pRawdata) /* there must be at least 1 char for keyword */ - MNG_ERROR (pData, MNG_KEYWORDNULL); - /* compression or not ? */ - if ((*(pNull1+1) != 0) && (*(pNull1+1) != 1)) - MNG_ERROR (pData, MNG_INVALIDCOMPRESS); - - if (*(pNull1+2) != 0) /* only deflate compression-method allowed */ - MNG_ERROR (pData, MNG_INVALIDCOMPRESS); - - iKeywordlen = (mng_uint32)(pNull1 - pRawdata); - iLanguagelen = (mng_uint32)(pNull2 - pNull1 - 3); - iTranslationlen = (mng_uint32)(pNull3 - pNull2 - 1); - iCompressedsize = (mng_uint32)(iRawlen - iKeywordlen - iLanguagelen - iTranslationlen - 5); - iCompressionflag = *(pNull1+1); - - zKeyword = 0; /* no buffers acquired yet */ - zLanguage = 0; - zTranslation = 0; - pBuf = 0; - iTextlen = 0; - - if (pData->fProcesstext) /* inform the application ? */ - { - if (iCompressionflag) /* decompress the text ? */ - { - iRetcode = mng_inflate_buffer (pData, pNull3+1, iCompressedsize, - &pBuf, &iBufsize, &iTextlen); - - if (iRetcode) /* on error bail out */ - { /* don't forget to drop the temp buffer */ - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - } - else - { - iTextlen = iCompressedsize; - iBufsize = iTextlen+1; /* plus 1 for terminator byte!!! */ - - MNG_ALLOC (pData, pBuf, iBufsize); - MNG_COPY (pBuf, pNull3+1, iTextlen); - } - - MNG_ALLOCX (pData, zKeyword, iKeywordlen + 1); - MNG_ALLOCX (pData, zLanguage, iLanguagelen + 1); - MNG_ALLOCX (pData, zTranslation, iTranslationlen + 1); - /* on error bail out */ - if ((!zKeyword) || (!zLanguage) || (!zTranslation)) - { /* don't forget to drop the temp buffers */ - MNG_FREEX (pData, zTranslation, iTranslationlen + 1); - MNG_FREEX (pData, zLanguage, iLanguagelen + 1); - MNG_FREEX (pData, zKeyword, iKeywordlen + 1); - MNG_FREEX (pData, pBuf, iBufsize); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - - MNG_COPY (zKeyword, pRawdata, iKeywordlen); - MNG_COPY (zLanguage, pNull1+3, iLanguagelen); - MNG_COPY (zTranslation, pNull2+1, iTranslationlen); - - if (!pData->fProcesstext ((mng_handle)pData, MNG_TYPE_ITXT, zKeyword, (mng_pchar)pBuf, - zLanguage, zTranslation)) - { /* don't forget to drop the temp buffers */ - MNG_FREEX (pData, zTranslation, iTranslationlen + 1); - MNG_FREEX (pData, zLanguage, iLanguagelen + 1); - MNG_FREEX (pData, zKeyword, iKeywordlen + 1); - MNG_FREEX (pData, pBuf, iBufsize); - - MNG_ERROR (pData, MNG_APPMISCERROR); - } - } - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - { /* don't forget to drop the temp buffers */ - MNG_FREEX (pData, zTranslation, iTranslationlen + 1); - MNG_FREEX (pData, zLanguage, iLanguagelen + 1); - MNG_FREEX (pData, zKeyword, iKeywordlen + 1); - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - /* store the fields */ - ((mng_itxtp)*ppChunk)->iKeywordsize = iKeywordlen; - ((mng_itxtp)*ppChunk)->iLanguagesize = iLanguagelen; - ((mng_itxtp)*ppChunk)->iTranslationsize = iTranslationlen; - ((mng_itxtp)*ppChunk)->iCompressionflag = *(pNull1+1); - ((mng_itxtp)*ppChunk)->iCompressionmethod = *(pNull1+2); - - if ((!pBuf) && (iCompressedsize)) /* did we not get a text-buffer yet ? */ - { - if (iCompressionflag) /* decompress the text ? */ - { - iRetcode = mng_inflate_buffer (pData, pNull3+1, iCompressedsize, - &pBuf, &iBufsize, &iTextlen); - - if (iRetcode) /* on error bail out */ - { /* don't forget to drop the temp buffers */ - MNG_FREEX (pData, zTranslation, iTranslationlen + 1); - MNG_FREEX (pData, zLanguage, iLanguagelen + 1); - MNG_FREEX (pData, zKeyword, iKeywordlen + 1); - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - } - else - { - iTextlen = iCompressedsize; - iBufsize = iTextlen+1; /* plus 1 for terminator byte!!! */ - - MNG_ALLOC (pData, pBuf, iBufsize); - MNG_COPY (pBuf, pNull3+1, iTextlen); - } - } - - MNG_ALLOCX (pData, ((mng_itxtp)*ppChunk)->zKeyword, iKeywordlen + 1); - MNG_ALLOCX (pData, ((mng_itxtp)*ppChunk)->zLanguage, iLanguagelen + 1); - MNG_ALLOCX (pData, ((mng_itxtp)*ppChunk)->zTranslation, iTranslationlen + 1); - /* on error bail out */ - if ((!((mng_itxtp)*ppChunk)->zKeyword ) || - (!((mng_itxtp)*ppChunk)->zLanguage ) || - (!((mng_itxtp)*ppChunk)->zTranslation) ) - { /* don't forget to drop the temp buffers */ - MNG_FREEX (pData, zTranslation, iTranslationlen + 1); - MNG_FREEX (pData, zLanguage, iLanguagelen + 1); - MNG_FREEX (pData, zKeyword, iKeywordlen + 1); - MNG_FREEX (pData, pBuf, iBufsize); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - - MNG_COPY (((mng_itxtp)*ppChunk)->zKeyword, pRawdata, iKeywordlen); - MNG_COPY (((mng_itxtp)*ppChunk)->zLanguage, pNull1+3, iLanguagelen); - MNG_COPY (((mng_itxtp)*ppChunk)->zTranslation, pNull2+1, iTranslationlen); - - ((mng_itxtp)*ppChunk)->iTextsize = iTextlen; - - if (iTextlen) - { - MNG_ALLOCX (pData, ((mng_itxtp)*ppChunk)->zText, iTextlen + 1); - - if (!((mng_itxtp)*ppChunk)->zText) - { /* don't forget to drop the temp buffers */ - MNG_FREEX (pData, zTranslation, iTranslationlen + 1); - MNG_FREEX (pData, zLanguage, iLanguagelen + 1); - MNG_FREEX (pData, zKeyword, iKeywordlen + 1); - MNG_FREEX (pData, pBuf, iBufsize); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - - MNG_COPY (((mng_itxtp)*ppChunk)->zText, pBuf, iTextlen); - } - } -#endif /* MNG_STORE_CHUNKS */ - /* free the temporary buffers */ - MNG_FREEX (pData, zTranslation, iTranslationlen + 1); - MNG_FREEX (pData, zLanguage, iLanguagelen + 1); - MNG_FREEX (pData, zKeyword, iKeywordlen + 1); - MNG_FREEX (pData, pBuf, iBufsize); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_ITXT, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_bKGD -READ_CHUNK (mng_read_bkgd) -{ -#ifdef MNG_SUPPORT_DISPLAY - mng_imagep pImage = (mng_imagep)pData->pCurrentobj; - mng_imagedatap pBuf; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_BKGD, MNG_LC_START); -#endif - /* sequence checks */ -#ifdef MNG_INCLUDE_JNG - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIDAT) || (pData->bHasJDAT) || (pData->bHasJDAA)) -#else - if (pData->bHasIDAT) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen > 6) /* it just can't be bigger than that! */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_INCLUDE_JNG /* length checks */ - if (pData->bHasJHDR) - { - if (((pData->iJHDRcolortype == 8) || (pData->iJHDRcolortype == 12)) && (iRawlen != 2)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if (((pData->iJHDRcolortype == 10) || (pData->iJHDRcolortype == 14)) && (iRawlen != 6)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - else -#endif /* MNG_INCLUDE_JNG */ - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - { - if (((pData->iColortype == 0) || (pData->iColortype == 4)) && (iRawlen != 2)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if (((pData->iColortype == 2) || (pData->iColortype == 6)) && (iRawlen != 6)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((pData->iColortype == 3) && (iRawlen != 1)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - else - { - if (iRawlen != 6) /* global is always 16-bit RGB ! */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - pData->bHasBKGD = MNG_TRUE; /* indicate bKGD available */ - else - pData->bHasglobalBKGD = (mng_bool)(iRawlen != 0); - -#ifdef MNG_SUPPORT_DISPLAY - if (!pImage) /* if no object dump it in obj 0 */ - pImage = (mng_imagep)pData->pObjzero; - - pBuf = pImage->pImgbuf; /* address object buffer */ - -#ifdef MNG_INCLUDE_JNG - if (pData->bHasJHDR) - { - pBuf->bHasBKGD = MNG_TRUE; /* tell the object it's got bKGD now */ - - switch (pData->iJHDRcolortype) /* store fields for future reference */ - { - case 8 : ; /* gray */ - case 12 : { /* graya */ - pBuf->iBKGDgray = mng_get_uint16 (pRawdata); - break; - } - case 10 : ; /* rgb */ - case 14 : { /* rgba */ - pBuf->iBKGDred = mng_get_uint16 (pRawdata); - pBuf->iBKGDgreen = mng_get_uint16 (pRawdata+2); - pBuf->iBKGDblue = mng_get_uint16 (pRawdata+4); - break; - } - } - } - else -#endif /* MNG_INCLUDE_JNG */ - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - { - pBuf->bHasBKGD = MNG_TRUE; /* tell the object it's got bKGD now */ - - switch (pData->iColortype) /* store fields for future reference */ - { - case 0 : ; /* gray */ - case 4 : { /* graya */ - pBuf->iBKGDgray = mng_get_uint16 (pRawdata); - break; - } - case 2 : ; /* rgb */ - case 6 : { /* rgba */ - pBuf->iBKGDred = mng_get_uint16 (pRawdata); - pBuf->iBKGDgreen = mng_get_uint16 (pRawdata+2); - pBuf->iBKGDblue = mng_get_uint16 (pRawdata+4); - break; - } - case 3 : { /* indexed */ - pBuf->iBKGDindex = *pRawdata; - break; - } - } - } - else /* store as global */ - { - if (iRawlen) - { - pData->iGlobalBKGDred = mng_get_uint16 (pRawdata); - pData->iGlobalBKGDgreen = mng_get_uint16 (pRawdata+2); - pData->iGlobalBKGDblue = mng_get_uint16 (pRawdata+4); - } - - { /* create an animation object */ - mng_retcode iRetcode = mng_create_ani_bkgd (pData, pData->iGlobalBKGDred, - pData->iGlobalBKGDgreen, - pData->iGlobalBKGDblue); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_bkgdp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - ((mng_bkgdp)*ppChunk)->iType = pData->iColortype; - - if (iRawlen) - { - switch (iRawlen) /* guess from length */ - { - case 1 : { /* indexed */ - ((mng_bkgdp)*ppChunk)->iType = 3; - ((mng_bkgdp)*ppChunk)->iIndex = *pRawdata; - break; - } - case 2 : { /* gray */ - ((mng_bkgdp)*ppChunk)->iType = 0; - ((mng_bkgdp)*ppChunk)->iGray = mng_get_uint16 (pRawdata); - break; - } - case 6 : { /* rgb */ - ((mng_bkgdp)*ppChunk)->iType = 2; - ((mng_bkgdp)*ppChunk)->iRed = mng_get_uint16 (pRawdata); - ((mng_bkgdp)*ppChunk)->iGreen = mng_get_uint16 (pRawdata+2); - ((mng_bkgdp)*ppChunk)->iBlue = mng_get_uint16 (pRawdata+4); - break; - } - } - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_BKGD, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_pHYs -READ_CHUNK (mng_read_phys) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_PHYS, MNG_LC_START); -#endif - /* sequence checks */ -#ifdef MNG_INCLUDE_JNG - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIDAT) || (pData->bHasJDAT) || (pData->bHasJDAA)) -#else - if (pData->bHasIDAT) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* it's 9 bytes or empty; no more, no less! */ - if ((iRawlen != 9) && (iRawlen != 0)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_physp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - - if (iRawlen) - { - ((mng_physp)*ppChunk)->iSizex = mng_get_uint32 (pRawdata); - ((mng_physp)*ppChunk)->iSizey = mng_get_uint32 (pRawdata+4); - ((mng_physp)*ppChunk)->iUnit = *(pRawdata+8); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_PHYS, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_sBIT -READ_CHUNK (mng_read_sbit) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_SBIT, MNG_LC_START); -#endif - /* sequence checks */ -#ifdef MNG_INCLUDE_JNG - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasPLTE) || (pData->bHasIDAT) || (pData->bHasJDAT) || (pData->bHasJDAA)) -#else - if ((pData->bHasPLTE) || (pData->bHasIDAT)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen > 4) /* it just can't be bigger than that! */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_INCLUDE_JNG /* length checks */ - if (pData->bHasJHDR) - { - if ((pData->iJHDRcolortype == 8) && (iRawlen != 1)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((pData->iJHDRcolortype == 10) && (iRawlen != 3)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((pData->iJHDRcolortype == 12) && (iRawlen != 2)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((pData->iJHDRcolortype == 14) && (iRawlen != 4)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - else -#endif /* MNG_INCLUDE_JNG */ - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) - { - if ((pData->iColortype == 0) && (iRawlen != 1)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((pData->iColortype == 2) && (iRawlen != 3)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((pData->iColortype == 3) && (iRawlen != 3)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((pData->iColortype == 4) && (iRawlen != 2)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((pData->iColortype == 6) && (iRawlen != 4)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - else - { /* global = empty or RGBA */ - if ((iRawlen != 0) && (iRawlen != 4)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_sbitp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - - if (iRawlen) - { -#ifdef MNG_INCLUDE_JNG - if (pData->bHasJHDR) - ((mng_sbitp)*ppChunk)->iType = pData->iJHDRcolortype; - else -#endif - if (pData->bHasIHDR) - ((mng_sbitp)*ppChunk)->iType = pData->iColortype; - else /* global ! */ - ((mng_sbitp)*ppChunk)->iType = 6; - - if (iRawlen > 0) - ((mng_sbitp)*ppChunk)->aBits [0] = *pRawdata; - if (iRawlen > 1) - ((mng_sbitp)*ppChunk)->aBits [1] = *(pRawdata+1); - if (iRawlen > 2) - ((mng_sbitp)*ppChunk)->aBits [2] = *(pRawdata+2); - if (iRawlen > 3) - ((mng_sbitp)*ppChunk)->aBits [3] = *(pRawdata+3); - - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_SBIT, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_sPLT -READ_CHUNK (mng_read_splt) -{ - mng_uint8p pTemp; - mng_uint32 iNamelen; - mng_uint8 iSampledepth; - mng_uint32 iRemain; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_SPLT, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (pData->bHasIDAT) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen) - { - pTemp = find_null (pRawdata); /* find null-separator */ - /* not found inside input-data ? */ - if ((pTemp - pRawdata) > (mng_int32)iRawlen) - MNG_ERROR (pData, MNG_NULLNOTFOUND); - - iNamelen = (mng_uint32)(pTemp - pRawdata); - iSampledepth = *(pTemp+1); - iRemain = (iRawlen - 2 - iNamelen); - - if ((iSampledepth != 1) && (iSampledepth != 2)) - MNG_ERROR (pData, MNG_INVSAMPLEDEPTH); - /* check remaining length */ - if ( ((iSampledepth == 1) && (iRemain % 6 != 0)) || - ((iSampledepth == 2) && (iRemain % 10 != 0)) ) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - } - else - { - pTemp = MNG_NULL; - iNamelen = 0; - iSampledepth = 0; - iRemain = 0; - } - -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_spltp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - - if (iRawlen) - { - ((mng_spltp)*ppChunk)->iNamesize = iNamelen; - ((mng_spltp)*ppChunk)->iSampledepth = iSampledepth; - - if (iSampledepth == 1) - ((mng_spltp)*ppChunk)->iEntrycount = iRemain / 6; - else - ((mng_spltp)*ppChunk)->iEntrycount = iRemain / 10; - - if (iNamelen) - { - MNG_ALLOC (pData, ((mng_spltp)*ppChunk)->zName, iNamelen+1); - MNG_COPY (((mng_spltp)*ppChunk)->zName, pRawdata, iNamelen); - } - - if (iRemain) - { - MNG_ALLOC (pData, ((mng_spltp)*ppChunk)->pEntries, iRemain); - MNG_COPY (((mng_spltp)*ppChunk)->pEntries, pTemp+2, iRemain); - } - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_SPLT, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_hIST -READ_CHUNK (mng_read_hist) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_HIST, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasIHDR) && (!pData->bHasBASI) && (!pData->bHasDHDR) ) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if ((!pData->bHasPLTE) || (pData->bHasIDAT)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* length oke ? */ - if ( ((iRawlen & 0x01) != 0) || ((iRawlen >> 1) != pData->iPLTEcount) ) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { - mng_uint32 iX; - /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_histp)*ppChunk)->iEntrycount = iRawlen >> 1; - - for (iX = 0; iX < (iRawlen >> 1); iX++) - { - ((mng_histp)*ppChunk)->aEntries [iX] = mng_get_uint16 (pRawdata); - pRawdata += 2; - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_HIST, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_tIME -READ_CHUNK (mng_read_time) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_TIME, MNG_LC_START); -#endif - /* sequence checks */ -#ifdef MNG_INCLUDE_JNG - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen != 7) /* length must be exactly 7 */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -/* if (pData->fProcesstime) */ /* inform the application ? */ -/* { - - pData->fProcesstime ((mng_handle)pData, ); - } */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_timep)*ppChunk)->iYear = mng_get_uint16 (pRawdata); - ((mng_timep)*ppChunk)->iMonth = *(pRawdata+2); - ((mng_timep)*ppChunk)->iDay = *(pRawdata+3); - ((mng_timep)*ppChunk)->iHour = *(pRawdata+4); - ((mng_timep)*ppChunk)->iMinute = *(pRawdata+5); - ((mng_timep)*ppChunk)->iSecond = *(pRawdata+6); - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_TIME, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -READ_CHUNK (mng_read_mhdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_MHDR, MNG_LC_START); -#endif - - if (pData->eSigtype != mng_it_mng) /* sequence checks */ - MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); - - if (pData->bHasheader) /* can only be the first chunk! */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* correct length ? */ -#ifndef MNG_NO_OLD_VERSIONS - if ((iRawlen != 28) && (iRawlen != 12)) -#else - if ((iRawlen != 28)) -#endif - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - pData->bHasMHDR = MNG_TRUE; /* oh boy, a real MNG */ - pData->bHasheader = MNG_TRUE; /* we've got a header */ - pData->eImagetype = mng_it_mng; /* fill header fields */ - pData->iWidth = mng_get_uint32 (pRawdata); - pData->iHeight = mng_get_uint32 (pRawdata+4); - pData->iTicks = mng_get_uint32 (pRawdata+8); - -#ifndef MNG_NO_OLD_VERSIONS - if (iRawlen == 28) /* proper MHDR ? */ - { -#endif - pData->iLayercount = mng_get_uint32 (pRawdata+12); - pData->iFramecount = mng_get_uint32 (pRawdata+16); - pData->iPlaytime = mng_get_uint32 (pRawdata+20); - pData->iSimplicity = mng_get_uint32 (pRawdata+24); - -#ifndef MNG_NO_OLD_VERSIONS - pData->bPreDraft48 = MNG_FALSE; - } - else /* probably pre-draft48 then */ - { - pData->iLayercount = 0; - pData->iFramecount = 0; - pData->iPlaytime = 0; - pData->iSimplicity = 0; - - pData->bPreDraft48 = MNG_TRUE; - } -#endif - /* predict alpha-depth */ - if ((pData->iSimplicity & 0x00000001) == 0) -#ifndef MNG_NO_16BIT_SUPPORT - pData->iAlphadepth = 16; /* no indicators = assume the worst */ -#else - pData->iAlphadepth = 8; /* anything else = assume the worst */ -#endif - else - if ((pData->iSimplicity & 0x00000008) == 0) - pData->iAlphadepth = 0; /* no transparency at all */ - else - if ((pData->iSimplicity & 0x00000140) == 0x00000040) - pData->iAlphadepth = 1; /* no semi-transparency guaranteed */ - else -#ifndef MNG_NO_16BIT_SUPPORT - pData->iAlphadepth = 16; /* anything else = assume the worst */ -#else - pData->iAlphadepth = 8; /* anything else = assume the worst */ -#endif - -#ifdef MNG_INCLUDE_JNG /* can we handle the complexity ? */ - if (pData->iSimplicity & 0x0000FC00) -#else - if (pData->iSimplicity & 0x0000FC10) -#endif - MNG_ERROR (pData, MNG_MNGTOOCOMPLEX); - /* fits on maximum canvas ? */ - if ((pData->iWidth > pData->iMaxwidth) || (pData->iHeight > pData->iMaxheight)) - MNG_WARNING (pData, MNG_IMAGETOOLARGE); - - if (pData->fProcessheader) /* inform the app ? */ - if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) - MNG_ERROR (pData, MNG_APPMISCERROR); - - pData->iImagelevel++; /* one level deeper */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_mhdrp)*ppChunk)->iWidth = pData->iWidth; - ((mng_mhdrp)*ppChunk)->iHeight = pData->iHeight; - ((mng_mhdrp)*ppChunk)->iTicks = pData->iTicks; - ((mng_mhdrp)*ppChunk)->iLayercount = pData->iLayercount; - ((mng_mhdrp)*ppChunk)->iFramecount = pData->iFramecount; - ((mng_mhdrp)*ppChunk)->iPlaytime = pData->iPlaytime; - ((mng_mhdrp)*ppChunk)->iSimplicity = pData->iSimplicity; - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_MHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -READ_CHUNK (mng_read_mend) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_MEND, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen > 0) /* must not contain data! */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { /* do something */ - mng_retcode iRetcode = mng_process_display_mend (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - if (!pData->iTotalframes) /* save totals */ - pData->iTotalframes = pData->iFrameseq; - if (!pData->iTotallayers) - pData->iTotallayers = pData->iLayerseq; - if (!pData->iTotalplaytime) - pData->iTotalplaytime = pData->iFrametime; - } -#endif /* MNG_SUPPORT_DISPLAY */ - - pData->bHasMHDR = MNG_FALSE; /* end of the line, bro! */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_MEND, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_LOOP -READ_CHUNK (mng_read_loop) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_LOOP, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (!pData->bCacheplayback) /* must store playback info to work!! */ - MNG_ERROR (pData, MNG_LOOPWITHCACHEOFF); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen >= 5) /* length checks */ - { - if (iRawlen >= 6) - { - if ((iRawlen - 6) % 4 != 0) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_uint8 iLevel; - mng_uint32 iRepeat; - mng_uint8 iTermination = 0; - mng_uint32 iItermin = 1; - mng_uint32 iItermax = 0x7fffffffL; - mng_retcode iRetcode; - - pData->bHasLOOP = MNG_TRUE; /* indicate we're inside a loop */ - - iLevel = *pRawdata; /* determine the fields for processing */ - -#ifndef MNG_NO_OLD_VERSIONS - if (pData->bPreDraft48) - { - iTermination = *(pRawdata+1); - - iRepeat = mng_get_uint32 (pRawdata+2); - } - else -#endif - iRepeat = mng_get_uint32 (pRawdata+1); - - if (iRawlen >= 6) - { -#ifndef MNG_NO_OLD_VERSIONS - if (!pData->bPreDraft48) -#endif - iTermination = *(pRawdata+5); - - if (iRawlen >= 10) - { - iItermin = mng_get_uint32 (pRawdata+6); - - if (iRawlen >= 14) - { - iItermax = mng_get_uint32 (pRawdata+10); - - /* TODO: process signals */ - - } - } - } - /* create the LOOP ani-object */ - iRetcode = mng_create_ani_loop (pData, iLevel, iRepeat, iTermination, - iItermin, iItermax, 0, 0); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* skip till matching ENDL if iteration=0 */ - if ((!pData->bSkipping) && (iRepeat == 0)) - pData->bSkipping = MNG_TRUE; - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - if (iRawlen >= 5) /* store the fields */ - { - ((mng_loopp)*ppChunk)->iLevel = *pRawdata; - -#ifndef MNG_NO_OLD_VERSIONS - if (pData->bPreDraft48) - { - ((mng_loopp)*ppChunk)->iTermination = *(pRawdata+1); - ((mng_loopp)*ppChunk)->iRepeat = mng_get_uint32 (pRawdata+2); - } - else -#endif - { - ((mng_loopp)*ppChunk)->iRepeat = mng_get_uint32 (pRawdata+1); - } - - if (iRawlen >= 6) - { -#ifndef MNG_NO_OLD_VERSIONS - if (!pData->bPreDraft48) -#endif - ((mng_loopp)*ppChunk)->iTermination = *(pRawdata+5); - - if (iRawlen >= 10) - { - ((mng_loopp)*ppChunk)->iItermin = mng_get_uint32 (pRawdata+6); - -#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED - if (iRawlen >= 14) - { - ((mng_loopp)*ppChunk)->iItermax = mng_get_uint32 (pRawdata+10); - ((mng_loopp)*ppChunk)->iCount = (iRawlen - 14) / 4; - - if (((mng_loopp)*ppChunk)->iCount) - { - MNG_ALLOC (pData, ((mng_loopp)*ppChunk)->pSignals, - ((mng_loopp)*ppChunk)->iCount << 2); - -#ifndef MNG_BIGENDIAN_SUPPORTED - { - mng_uint32 iX; - mng_uint8p pIn = pRawdata + 14; - mng_uint32p pOut = (mng_uint32p)((mng_loopp)*ppChunk)->pSignals; - - for (iX = 0; iX < ((mng_loopp)*ppChunk)->iCount; iX++) - { - *pOut++ = mng_get_uint32 (pIn); - pIn += 4; - } - } -#else - MNG_COPY (((mng_loopp)*ppChunk)->pSignals, pRawdata + 14, - ((mng_loopp)*ppChunk)->iCount << 2); -#endif /* !MNG_BIGENDIAN_SUPPORTED */ - } - } -#endif - } - } - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_LOOP, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_LOOP -READ_CHUNK (mng_read_endl) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_ENDL, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen != 1) /* length must be exactly 1 */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - if (pData->bHasLOOP) /* are we really processing a loop ? */ - { - mng_uint8 iLevel = *pRawdata; /* get the nest level */ - /* create an ENDL animation object */ - mng_retcode iRetcode = mng_create_ani_endl (pData, iLevel); - - if (iRetcode) /* on error bail out */ - return iRetcode; - -/* { - mng_ani_endlp pENDL = (mng_ani_endlp)pData->pLastaniobj; - - iRetcode = pENDL->sHeader.fProcess (pData, pENDL); - - if (iRetcode) - return iRetcode; - } */ - } - else - MNG_ERROR (pData, MNG_NOMATCHINGLOOP); - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_endlp)*ppChunk)->iLevel = *pRawdata; - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_ENDL, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_DEFI -READ_CHUNK (mng_read_defi) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_DEFI, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* check the length */ - if ((iRawlen != 2) && (iRawlen != 3) && (iRawlen != 4) && - (iRawlen != 12) && (iRawlen != 28)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode; - - pData->iDEFIobjectid = mng_get_uint16 (pRawdata); - - if (iRawlen > 2) - { - pData->bDEFIhasdonotshow = MNG_TRUE; - pData->iDEFIdonotshow = *(pRawdata+2); - } - else - { - pData->bDEFIhasdonotshow = MNG_FALSE; - pData->iDEFIdonotshow = 0; - } - - if (iRawlen > 3) - { - pData->bDEFIhasconcrete = MNG_TRUE; - pData->iDEFIconcrete = *(pRawdata+3); - } - else - { - pData->bDEFIhasconcrete = MNG_FALSE; - pData->iDEFIconcrete = 0; - } - - if (iRawlen > 4) - { - pData->bDEFIhasloca = MNG_TRUE; - pData->iDEFIlocax = mng_get_int32 (pRawdata+4); - pData->iDEFIlocay = mng_get_int32 (pRawdata+8); - } - else - { - pData->bDEFIhasloca = MNG_FALSE; - pData->iDEFIlocax = 0; - pData->iDEFIlocay = 0; - } - - if (iRawlen > 12) - { - pData->bDEFIhasclip = MNG_TRUE; - pData->iDEFIclipl = mng_get_int32 (pRawdata+12); - pData->iDEFIclipr = mng_get_int32 (pRawdata+16); - pData->iDEFIclipt = mng_get_int32 (pRawdata+20); - pData->iDEFIclipb = mng_get_int32 (pRawdata+24); - } - else - { - pData->bDEFIhasclip = MNG_FALSE; - pData->iDEFIclipl = 0; - pData->iDEFIclipr = 0; - pData->iDEFIclipt = 0; - pData->iDEFIclipb = 0; - } - /* create an animation object */ - iRetcode = mng_create_ani_defi (pData); - - if (!iRetcode) /* do display processing */ - iRetcode = mng_process_display_defi (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_defip)*ppChunk)->iObjectid = mng_get_uint16 (pRawdata); - - if (iRawlen > 2) - { - ((mng_defip)*ppChunk)->bHasdonotshow = MNG_TRUE; - ((mng_defip)*ppChunk)->iDonotshow = *(pRawdata+2); - } - else - ((mng_defip)*ppChunk)->bHasdonotshow = MNG_FALSE; - - if (iRawlen > 3) - { - ((mng_defip)*ppChunk)->bHasconcrete = MNG_TRUE; - ((mng_defip)*ppChunk)->iConcrete = *(pRawdata+3); - } - else - ((mng_defip)*ppChunk)->bHasconcrete = MNG_FALSE; - - if (iRawlen > 4) - { - ((mng_defip)*ppChunk)->bHasloca = MNG_TRUE; - ((mng_defip)*ppChunk)->iXlocation = mng_get_int32 (pRawdata+4); - ((mng_defip)*ppChunk)->iYlocation = mng_get_int32 (pRawdata+8); - } - else - ((mng_defip)*ppChunk)->bHasloca = MNG_FALSE; - - if (iRawlen > 12) - { - ((mng_defip)*ppChunk)->bHasclip = MNG_TRUE; - ((mng_defip)*ppChunk)->iLeftcb = mng_get_int32 (pRawdata+12); - ((mng_defip)*ppChunk)->iRightcb = mng_get_int32 (pRawdata+16); - ((mng_defip)*ppChunk)->iTopcb = mng_get_int32 (pRawdata+20); - ((mng_defip)*ppChunk)->iBottomcb = mng_get_int32 (pRawdata+24); - } - else - ((mng_defip)*ppChunk)->bHasclip = MNG_FALSE; - - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_DEFI, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_BASI -READ_CHUNK (mng_read_basi) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_BASI, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* check the length */ - if ((iRawlen != 13) && (iRawlen != 19) && (iRawlen != 21) && (iRawlen != 22)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - pData->bHasBASI = MNG_TRUE; /* inside a BASI-IEND block now */ - /* store interesting fields */ - pData->iDatawidth = mng_get_uint32 (pRawdata); - pData->iDataheight = mng_get_uint32 (pRawdata+4); - pData->iBitdepth = *(pRawdata+8); - pData->iColortype = *(pRawdata+9); - pData->iCompression = *(pRawdata+10); - pData->iFilter = *(pRawdata+11); - pData->iInterlace = *(pRawdata+12); - - -#if defined(MNG_NO_1_2_4BIT_SUPPORT) || defined(MNG_NO_16BIT_SUPPORT) - pData->iPNGmult = 1; - pData->iPNGdepth = pData->iBitdepth; -#endif - -#ifdef MNG_NO_1_2_4BIT_SUPPORT - if (pData->iBitdepth < 8) - pData->iBitdepth = 8; -#endif -#ifdef MNG_NO_16BIT_SUPPORT - if (pData->iBitdepth > 8) - { - pData->iBitdepth = 8; - pData->iPNGmult = 2; - } -#endif - - if ((pData->iBitdepth != 8) /* parameter validity checks */ -#ifndef MNG_NO_1_2_4BIT_SUPPORT - && (pData->iBitdepth != 1) && - (pData->iBitdepth != 2) && - (pData->iBitdepth != 4) -#endif -#ifndef MNG_NO_16BIT_SUPPORT - && (pData->iBitdepth != 16) -#endif - ) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if ((pData->iColortype != MNG_COLORTYPE_GRAY ) && - (pData->iColortype != MNG_COLORTYPE_RGB ) && - (pData->iColortype != MNG_COLORTYPE_INDEXED) && - (pData->iColortype != MNG_COLORTYPE_GRAYA ) && - (pData->iColortype != MNG_COLORTYPE_RGBA ) ) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - - if ((pData->iColortype == MNG_COLORTYPE_INDEXED) && (pData->iBitdepth > 8)) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if (((pData->iColortype == MNG_COLORTYPE_RGB ) || - (pData->iColortype == MNG_COLORTYPE_GRAYA ) || - (pData->iColortype == MNG_COLORTYPE_RGBA ) ) && - (pData->iBitdepth < 8 ) ) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if (pData->iCompression != MNG_COMPRESSION_DEFLATE) - MNG_ERROR (pData, MNG_INVALIDCOMPRESS); - -#if defined(FILTER192) || defined(FILTER193) - if ((pData->iFilter != MNG_FILTER_ADAPTIVE ) && -#if defined(FILTER192) && defined(FILTER193) - (pData->iFilter != MNG_FILTER_DIFFERING) && - (pData->iFilter != MNG_FILTER_NOFILTER ) ) -#else -#ifdef FILTER192 - (pData->iFilter != MNG_FILTER_DIFFERING) ) -#else - (pData->iFilter != MNG_FILTER_NOFILTER ) ) -#endif -#endif - MNG_ERROR (pData, MNG_INVALIDFILTER); -#else - if (pData->iFilter) - MNG_ERROR (pData, MNG_INVALIDFILTER); -#endif - - if ((pData->iInterlace != MNG_INTERLACE_NONE ) && - (pData->iInterlace != MNG_INTERLACE_ADAM7) ) - MNG_ERROR (pData, MNG_INVALIDINTERLACE); - - pData->iImagelevel++; /* one level deeper */ - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_uint16 iRed = 0; - mng_uint16 iGreen = 0; - mng_uint16 iBlue = 0; - mng_bool bHasalpha = MNG_FALSE; - mng_uint16 iAlpha = 0xFFFF; - mng_uint8 iViewable = 0; - mng_retcode iRetcode; - - if (iRawlen > 13) /* get remaining fields, if any */ - { - iRed = mng_get_uint16 (pRawdata+13); - iGreen = mng_get_uint16 (pRawdata+15); - iBlue = mng_get_uint16 (pRawdata+17); - } - - if (iRawlen > 19) - { - bHasalpha = MNG_TRUE; - iAlpha = mng_get_uint16 (pRawdata+19); - } - - if (iRawlen > 21) - iViewable = *(pRawdata+21); - /* create an animation object */ - iRetcode = mng_create_ani_basi (pData, iRed, iGreen, iBlue, - bHasalpha, iAlpha, iViewable); - -/* if (!iRetcode) - iRetcode = mng_process_display_basi (pData, iRed, iGreen, iBlue, - bHasalpha, iAlpha, iViewable); */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_basip)*ppChunk)->iWidth = mng_get_uint32 (pRawdata); - ((mng_basip)*ppChunk)->iHeight = mng_get_uint32 (pRawdata+4); -#ifdef MNG_NO_16BIT_SUPPORT - if (*(pRawdata+8) > 8) - ((mng_basip)*ppChunk)->iBitdepth = 8; - else -#endif - ((mng_basip)*ppChunk)->iBitdepth = *(pRawdata+8); - ((mng_basip)*ppChunk)->iColortype = *(pRawdata+9); - ((mng_basip)*ppChunk)->iCompression = *(pRawdata+10); - ((mng_basip)*ppChunk)->iFilter = *(pRawdata+11); - ((mng_basip)*ppChunk)->iInterlace = *(pRawdata+12); - - if (iRawlen > 13) - { - ((mng_basip)*ppChunk)->iRed = mng_get_uint16 (pRawdata+13); - ((mng_basip)*ppChunk)->iGreen = mng_get_uint16 (pRawdata+15); - ((mng_basip)*ppChunk)->iBlue = mng_get_uint16 (pRawdata+17); - } - - if (iRawlen > 19) - ((mng_basip)*ppChunk)->iAlpha = mng_get_uint16 (pRawdata+19); - - if (iRawlen > 21) - ((mng_basip)*ppChunk)->iViewable = *(pRawdata+21); - - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_BASI, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_CLON -READ_CHUNK (mng_read_clon) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_CLON, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* check the length */ - if ((iRawlen != 4) && (iRawlen != 5) && (iRawlen != 6) && - (iRawlen != 7) && (iRawlen != 16)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_uint16 iSourceid, iCloneid; - mng_uint8 iClonetype = 0; - mng_bool bHasdonotshow = MNG_FALSE; - mng_uint8 iDonotshow = 0; - mng_uint8 iConcrete = 0; - mng_bool bHasloca = MNG_FALSE; - mng_uint8 iLocationtype = 0; - mng_int32 iLocationx = 0; - mng_int32 iLocationy = 0; - mng_retcode iRetcode; - - iSourceid = mng_get_uint16 (pRawdata); - iCloneid = mng_get_uint16 (pRawdata+2); - - if (iRawlen > 4) - iClonetype = *(pRawdata+4); - - if (iRawlen > 5) - { - bHasdonotshow = MNG_TRUE; - iDonotshow = *(pRawdata+5); - } - - if (iRawlen > 6) - iConcrete = *(pRawdata+6); - - if (iRawlen > 7) - { - bHasloca = MNG_TRUE; - iLocationtype = *(pRawdata+7); - iLocationx = mng_get_int32 (pRawdata+8); - iLocationy = mng_get_int32 (pRawdata+12); - } - - iRetcode = mng_create_ani_clon (pData, iSourceid, iCloneid, iClonetype, - bHasdonotshow, iDonotshow, iConcrete, - bHasloca, iLocationtype, iLocationx, iLocationy); - -/* if (!iRetcode) - iRetcode = mng_process_display_clon (pData, iSourceid, iCloneid, iClonetype, - bHasdonotshow, iDonotshow, iConcrete, - bHasloca, iLocationtype, iLocationx, - iLocationy); */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_clonp)*ppChunk)->iSourceid = mng_get_uint16 (pRawdata); - ((mng_clonp)*ppChunk)->iCloneid = mng_get_uint16 (pRawdata+2); - - if (iRawlen > 4) - ((mng_clonp)*ppChunk)->iClonetype = *(pRawdata+4); - - if (iRawlen > 5) - ((mng_clonp)*ppChunk)->iDonotshow = *(pRawdata+5); - - if (iRawlen > 6) - ((mng_clonp)*ppChunk)->iConcrete = *(pRawdata+6); - - if (iRawlen > 7) - { - ((mng_clonp)*ppChunk)->bHasloca = MNG_TRUE; - ((mng_clonp)*ppChunk)->iLocationtype = *(pRawdata+7); - ((mng_clonp)*ppChunk)->iLocationx = mng_get_int32 (pRawdata+8); - ((mng_clonp)*ppChunk)->iLocationy = mng_get_int32 (pRawdata+12); - } - else - { - ((mng_clonp)*ppChunk)->bHasloca = MNG_FALSE; - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_CLON, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_PAST -READ_CHUNK (mng_read_past) -{ -#if defined(MNG_STORE_CHUNKS) || defined(MNG_SUPPORT_DISPLAY) - mng_retcode iRetcode; - mng_uint16 iTargetid; - mng_uint8 iTargettype; - mng_int32 iTargetx; - mng_int32 iTargety; - mng_uint32 iCount; - mng_uint32 iSize; - mng_ptr pSources; - mng_uint32 iX; - mng_past_sourcep pSource; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_PAST, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - /* check the length */ - if ((iRawlen < 41) || (((iRawlen - 11) % 30) != 0)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#if defined(MNG_STORE_CHUNKS) || defined(MNG_SUPPORT_DISPLAY) - iTargetid = mng_get_uint16 (pRawdata); - iTargettype = *(pRawdata+2); - iTargetx = mng_get_int32 (pRawdata+3); - iTargety = mng_get_int32 (pRawdata+7); - iCount = ((iRawlen - 11) / 30); /* how many entries again? */ - iSize = iCount * sizeof (mng_past_source); - - pRawdata += 11; - /* get a buffer for all the source blocks */ - MNG_ALLOC (pData, pSources, iSize); - - pSource = (mng_past_sourcep)pSources; - - for (iX = 0; iX < iCount; iX++) /* now copy the source blocks */ - { - pSource->iSourceid = mng_get_uint16 (pRawdata); - pSource->iComposition = *(pRawdata+2); - pSource->iOrientation = *(pRawdata+3); - pSource->iOffsettype = *(pRawdata+4); - pSource->iOffsetx = mng_get_int32 (pRawdata+5); - pSource->iOffsety = mng_get_int32 (pRawdata+9); - pSource->iBoundarytype = *(pRawdata+13); - pSource->iBoundaryl = mng_get_int32 (pRawdata+14); - pSource->iBoundaryr = mng_get_int32 (pRawdata+18); - pSource->iBoundaryt = mng_get_int32 (pRawdata+22); - pSource->iBoundaryb = mng_get_int32 (pRawdata+26); - - pSource++; - pRawdata += 30; - } -#endif - -#ifdef MNG_SUPPORT_DISPLAY - { /* create playback object */ - iRetcode = mng_create_ani_past (pData, iTargetid, iTargettype, iTargetx, - iTargety, iCount, pSources); - -/* if (!iRetcode) - iRetcode = mng_process_display_past (pData, iTargetid, iTargettype, iTargetx, - iTargety, iCount, pSources); */ - - if (iRetcode) /* on error bail out */ - { - MNG_FREEX (pData, pSources, iSize); - return iRetcode; - } - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - { - MNG_FREEX (pData, pSources, iSize); - return iRetcode; - } - /* store the fields */ - ((mng_pastp)*ppChunk)->iDestid = iTargetid; - ((mng_pastp)*ppChunk)->iTargettype = iTargettype; - ((mng_pastp)*ppChunk)->iTargetx = iTargetx; - ((mng_pastp)*ppChunk)->iTargety = iTargety; - ((mng_pastp)*ppChunk)->iCount = iCount; - /* get a buffer & copy the source blocks */ - MNG_ALLOC (pData, ((mng_pastp)*ppChunk)->pSources, iSize); - MNG_COPY (((mng_pastp)*ppChunk)->pSources, pSources, iSize); - } -#endif /* MNG_STORE_CHUNKS */ - -#if defined(MNG_STORE_CHUNKS) || defined(MNG_SUPPORT_DISPLAY) - /* free the source block buffer */ - MNG_FREEX (pData, pSources, iSize); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_PAST, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_DISC -READ_CHUNK (mng_read_disc) -{ -#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) - mng_uint32 iCount; - mng_uint16p pIds = MNG_NULL; - mng_retcode iRetcode; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_DISC, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if ((iRawlen % 2) != 0) /* check the length */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) - iCount = (iRawlen / sizeof (mng_uint16)); - - if (iCount) - { - MNG_ALLOC (pData, pIds, iRawlen); - -#ifndef MNG_BIGENDIAN_SUPPORTED - { - mng_uint32 iX; - mng_uint8p pIn = pRawdata; - mng_uint16p pOut = pIds; - - for (iX = 0; iX < iCount; iX++) - { - *pOut++ = mng_get_uint16 (pIn); - pIn += 2; - } - } -#else - MNG_COPY (pIds, pRawdata, iRawlen); -#endif /* !MNG_BIGENDIAN_SUPPORTED */ - } -#endif - -#ifdef MNG_SUPPORT_DISPLAY - { /* create playback object */ - iRetcode = mng_create_ani_disc (pData, iCount, pIds); - -/* if (!iRetcode) - iRetcode = mng_process_display_disc (pData, iCount, pIds); */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_discp)*ppChunk)->iCount = iCount; - - if (iRawlen) - { - MNG_ALLOC (pData, ((mng_discp)*ppChunk)->pObjectids, iRawlen); - MNG_COPY (((mng_discp)*ppChunk)->pObjectids, pIds, iRawlen); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) - if (iRawlen) - MNG_FREEX (pData, pIds, iRawlen); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_DISC, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_BACK -READ_CHUNK (mng_read_back) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_BACK, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* check the length */ - if ((iRawlen != 6) && (iRawlen != 7) && (iRawlen != 9) && (iRawlen != 10)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode; - /* retrieve the fields */ - pData->bHasBACK = MNG_TRUE; - pData->iBACKred = mng_get_uint16 (pRawdata); - pData->iBACKgreen = mng_get_uint16 (pRawdata+2); - pData->iBACKblue = mng_get_uint16 (pRawdata+4); - - if (iRawlen > 6) - pData->iBACKmandatory = *(pRawdata+6); - else - pData->iBACKmandatory = 0; - - if (iRawlen > 7) - pData->iBACKimageid = mng_get_uint16 (pRawdata+7); - else - pData->iBACKimageid = 0; - - if (iRawlen > 9) - pData->iBACKtile = *(pRawdata+9); - else - pData->iBACKtile = 0; - - iRetcode = mng_create_ani_back (pData, pData->iBACKred, pData->iBACKgreen, - pData->iBACKblue, pData->iBACKmandatory, - pData->iBACKimageid, pData->iBACKtile); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_backp)*ppChunk)->iRed = mng_get_uint16 (pRawdata); - ((mng_backp)*ppChunk)->iGreen = mng_get_uint16 (pRawdata+2); - ((mng_backp)*ppChunk)->iBlue = mng_get_uint16 (pRawdata+4); - - if (iRawlen > 6) - ((mng_backp)*ppChunk)->iMandatory = *(pRawdata+6); - - if (iRawlen > 7) - ((mng_backp)*ppChunk)->iImageid = mng_get_uint16 (pRawdata+7); - - if (iRawlen > 9) - ((mng_backp)*ppChunk)->iTile = *(pRawdata+9); - - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_BACK, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_FRAM -READ_CHUNK (mng_read_fram) -{ - mng_uint8p pTemp; -#ifdef MNG_STORE_CHUNKS - mng_uint32 iNamelen; -#endif - mng_uint32 iRemain; - mng_uint32 iRequired = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_FRAM, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen <= 1) /* only framing-mode ? */ - { -#ifdef MNG_STORE_CHUNKS - iNamelen = 0; /* indicate so */ -#endif - iRemain = 0; - pTemp = MNG_NULL; - } - else - { - pTemp = find_null (pRawdata+1); /* find null-separator */ - /* not found inside input-data ? */ - if ((pTemp - pRawdata) > (mng_int32)iRawlen) - pTemp = pRawdata + iRawlen; /* than remainder is name */ - -#ifdef MNG_STORE_CHUNKS - iNamelen = (mng_uint32)((pTemp - pRawdata) - 1); -#endif - iRemain = (mng_uint32)(iRawlen - (pTemp - pRawdata)); - - if (iRemain) /* if there is remaining data it's less 1 byte */ - iRemain--; - - if ((iRemain) && (iRemain < 4)) /* remains must be empty or at least 4 bytes */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if (iRemain) - { - iRequired = 4; /* calculate and check required remaining length */ - - if (*(pTemp+1)) { iRequired += 4; } - if (*(pTemp+2)) { iRequired += 4; } - if (*(pTemp+3)) { iRequired += 17; } - - if (*(pTemp+4)) - { - if ((iRemain - iRequired) % 4 != 0) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - else - { - if (iRemain != iRequired) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - } - } - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_uint8p pWork = pTemp; - mng_uint8 iFramemode = 0; - mng_uint8 iChangedelay = 0; - mng_uint32 iDelay = 0; - mng_uint8 iChangetimeout = 0; - mng_uint32 iTimeout = 0; - mng_uint8 iChangeclipping = 0; - mng_uint8 iCliptype = 0; - mng_int32 iClipl = 0; - mng_int32 iClipr = 0; - mng_int32 iClipt = 0; - mng_int32 iClipb = 0; - mng_retcode iRetcode; - - if (iRawlen) /* any data specified ? */ - { - if (*(pRawdata)) /* save the new framing mode ? */ - { - iFramemode = *(pRawdata); - -#ifndef MNG_NO_OLD_VERSIONS - if (pData->bPreDraft48) /* old style input-stream ? */ - { - switch (iFramemode) - { - case 0: { break; } - case 1: { iFramemode = 3; break; } - case 2: { iFramemode = 4; break; } - case 3: { iFramemode = 1; break; } - case 4: { iFramemode = 1; break; } - case 5: { iFramemode = 2; break; } - default: { iFramemode = 1; break; } - } - } -#endif - } - - if (iRemain) - { - iChangedelay = *(pWork+1); - iChangetimeout = *(pWork+2); - iChangeclipping = *(pWork+3); - pWork += 5; - - if (iChangedelay) /* delay changed ? */ - { - iDelay = mng_get_uint32 (pWork); - pWork += 4; - } - - if (iChangetimeout) /* timeout changed ? */ - { - iTimeout = mng_get_uint32 (pWork); - pWork += 4; - } - - if (iChangeclipping) /* clipping changed ? */ - { - iCliptype = *pWork; - iClipl = mng_get_int32 (pWork+1); - iClipr = mng_get_int32 (pWork+5); - iClipt = mng_get_int32 (pWork+9); - iClipb = mng_get_int32 (pWork+13); - } - } - } - - iRetcode = mng_create_ani_fram (pData, iFramemode, iChangedelay, iDelay, - iChangetimeout, iTimeout, - iChangeclipping, iCliptype, - iClipl, iClipr, iClipt, iClipb); - -/* if (!iRetcode) - iRetcode = mng_process_display_fram (pData, iFramemode, iChangedelay, iDelay, - iChangetimeout, iTimeout, - iChangeclipping, iCliptype, - iClipl, iClipr, iClipt, iClipb); */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_framp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - - if (iRawlen) - { - mng_uint8 iFramemode = *(pRawdata); - -#ifndef MNG_NO_OLD_VERSIONS - if (pData->bPreDraft48) /* old style input-stream ? */ - { - switch (iFramemode) - { - case 1: { iFramemode = 3; break; } - case 2: { iFramemode = 4; break; } - case 3: { iFramemode = 5; break; } /* TODO: provision for mode=5 ??? */ - case 4: { iFramemode = 1; break; } - case 5: { iFramemode = 2; break; } - default: { iFramemode = 1; break; } - } - } -#endif - - ((mng_framp)*ppChunk)->iMode = iFramemode; - ((mng_framp)*ppChunk)->iNamesize = iNamelen; - - if (iNamelen) - { - MNG_ALLOC (pData, ((mng_framp)*ppChunk)->zName, iNamelen+1); - MNG_COPY (((mng_framp)*ppChunk)->zName, pRawdata+1, iNamelen); - } - - if (iRemain) - { - ((mng_framp)*ppChunk)->iChangedelay = *(pTemp+1); - ((mng_framp)*ppChunk)->iChangetimeout = *(pTemp+2); - ((mng_framp)*ppChunk)->iChangeclipping = *(pTemp+3); - ((mng_framp)*ppChunk)->iChangesyncid = *(pTemp+4); - - pTemp += 5; - - if (((mng_framp)*ppChunk)->iChangedelay) - { - ((mng_framp)*ppChunk)->iDelay = mng_get_uint32 (pTemp); - pTemp += 4; - } - - if (((mng_framp)*ppChunk)->iChangetimeout) - { - ((mng_framp)*ppChunk)->iTimeout = mng_get_uint32 (pTemp); - pTemp += 4; - } - - if (((mng_framp)*ppChunk)->iChangeclipping) - { - ((mng_framp)*ppChunk)->iBoundarytype = *pTemp; - ((mng_framp)*ppChunk)->iBoundaryl = mng_get_int32 (pTemp+1); - ((mng_framp)*ppChunk)->iBoundaryr = mng_get_int32 (pTemp+5); - ((mng_framp)*ppChunk)->iBoundaryt = mng_get_int32 (pTemp+9); - ((mng_framp)*ppChunk)->iBoundaryb = mng_get_int32 (pTemp+13); - pTemp += 17; - } - - if (((mng_framp)*ppChunk)->iChangesyncid) - { - ((mng_framp)*ppChunk)->iCount = (iRemain - iRequired) / 4; - - if (((mng_framp)*ppChunk)->iCount) - { - MNG_ALLOC (pData, ((mng_framp)*ppChunk)->pSyncids, - ((mng_framp)*ppChunk)->iCount * 4); - -#ifndef MNG_BIGENDIAN_SUPPORTED - { - mng_uint32 iX; - mng_uint32p pOut = ((mng_framp)*ppChunk)->pSyncids; - - for (iX = 0; iX < ((mng_framp)*ppChunk)->iCount; iX++) - { - *pOut++ = mng_get_uint32 (pTemp); - pTemp += 4; - } - } -#else - MNG_COPY (((mng_framp)*ppChunk)->pSyncids, pTemp, - ((mng_framp)*ppChunk)->iCount * 4); -#endif /* !MNG_BIGENDIAN_SUPPORTED */ - } - } - } - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_FRAM, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_MOVE -READ_CHUNK (mng_read_move) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_MOVE, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen != 13) /* check the length */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode; - /* create a MOVE animation object */ - iRetcode = mng_create_ani_move (pData, mng_get_uint16 (pRawdata), - mng_get_uint16 (pRawdata+2), - *(pRawdata+4), - mng_get_int32 (pRawdata+5), - mng_get_int32 (pRawdata+9)); - -/* if (!iRetcode) - iRetcode = mng_process_display_move (pData, - mng_get_uint16 (pRawdata), - mng_get_uint16 (pRawdata+2), - *(pRawdata+4), - mng_get_int32 (pRawdata+5), - mng_get_int32 (pRawdata+9)); */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_movep)*ppChunk)->iFirstid = mng_get_uint16 (pRawdata); - ((mng_movep)*ppChunk)->iLastid = mng_get_uint16 (pRawdata+2); - ((mng_movep)*ppChunk)->iMovetype = *(pRawdata+4); - ((mng_movep)*ppChunk)->iMovex = mng_get_int32 (pRawdata+5); - ((mng_movep)*ppChunk)->iMovey = mng_get_int32 (pRawdata+9); - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_MOVE, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_CLIP -READ_CHUNK (mng_read_clip) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_CLIP, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen != 21) /* check the length */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode; - /* create a CLIP animation object */ - iRetcode = mng_create_ani_clip (pData, mng_get_uint16 (pRawdata), - mng_get_uint16 (pRawdata+2), - *(pRawdata+4), - mng_get_int32 (pRawdata+5), - mng_get_int32 (pRawdata+9), - mng_get_int32 (pRawdata+13), - mng_get_int32 (pRawdata+17)); - -/* if (!iRetcode) - iRetcode = mng_process_display_clip (pData, - mng_get_uint16 (pRawdata), - mng_get_uint16 (pRawdata+2), - *(pRawdata+4), - mng_get_int32 (pRawdata+5), - mng_get_int32 (pRawdata+9), - mng_get_int32 (pRawdata+13), - mng_get_int32 (pRawdata+17)); */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_clipp)*ppChunk)->iFirstid = mng_get_uint16 (pRawdata); - ((mng_clipp)*ppChunk)->iLastid = mng_get_uint16 (pRawdata+2); - ((mng_clipp)*ppChunk)->iCliptype = *(pRawdata+4); - ((mng_clipp)*ppChunk)->iClipl = mng_get_int32 (pRawdata+5); - ((mng_clipp)*ppChunk)->iClipr = mng_get_int32 (pRawdata+9); - ((mng_clipp)*ppChunk)->iClipt = mng_get_int32 (pRawdata+13); - ((mng_clipp)*ppChunk)->iClipb = mng_get_int32 (pRawdata+17); - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_CLIP, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_SHOW -READ_CHUNK (mng_read_show) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_SHOW, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* check the length */ - if ((iRawlen != 0) && (iRawlen != 2) && (iRawlen != 4) && (iRawlen != 5)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode; - - if (iRawlen) /* determine parameters if any */ - { - pData->iSHOWfromid = mng_get_uint16 (pRawdata); - - if (iRawlen > 2) - pData->iSHOWtoid = mng_get_uint16 (pRawdata+2); - else - pData->iSHOWtoid = pData->iSHOWfromid; - - if (iRawlen > 4) - pData->iSHOWmode = *(pRawdata+4); - else - pData->iSHOWmode = 0; - } - else /* use defaults then */ - { - pData->iSHOWmode = 2; - pData->iSHOWfromid = 1; - pData->iSHOWtoid = 65535; - } - /* create a SHOW animation object */ - iRetcode = mng_create_ani_show (pData, pData->iSHOWfromid, - pData->iSHOWtoid, pData->iSHOWmode); - - if (!iRetcode) - iRetcode = mng_process_display_show (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_showp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - - if (iRawlen) - { - ((mng_showp)*ppChunk)->iFirstid = mng_get_uint16 (pRawdata); - - if (iRawlen > 2) - ((mng_showp)*ppChunk)->iLastid = mng_get_uint16 (pRawdata+2); - else - ((mng_showp)*ppChunk)->iLastid = ((mng_showp)*ppChunk)->iFirstid; - - if (iRawlen > 4) - ((mng_showp)*ppChunk)->iMode = *(pRawdata+4); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_SHOW, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_TERM -READ_CHUNK (mng_read_term) -{ - mng_uint8 iTermaction; - mng_uint8 iIteraction = 0; - mng_uint32 iDelay = 0; - mng_uint32 iItermax = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_TERM, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - /* should be behind MHDR or SAVE !! */ - if ((!pData->bHasSAVE) && (pData->iChunkseq > 2)) - { - pData->bMisplacedTERM = MNG_TRUE; /* indicate we found a misplaced TERM */ - /* and send a warning signal!!! */ - MNG_WARNING (pData, MNG_SEQUENCEERROR); - } - - if (pData->bHasLOOP) /* no way, jose! */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (pData->bHasTERM) /* only 1 allowed! */ - MNG_ERROR (pData, MNG_MULTIPLEERROR); - /* check the length */ - if ((iRawlen != 1) && (iRawlen != 10)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - pData->bHasTERM = MNG_TRUE; - - iTermaction = *pRawdata; /* get the fields */ - - if (iRawlen > 1) - { - iIteraction = *(pRawdata+1); - iDelay = mng_get_uint32 (pRawdata+2); - iItermax = mng_get_uint32 (pRawdata+6); - } - - if (pData->fProcessterm) /* inform the app ? */ - if (!pData->fProcessterm (((mng_handle)pData), iTermaction, iIteraction, - iDelay, iItermax)) - MNG_ERROR (pData, MNG_APPMISCERROR); - -#ifdef MNG_SUPPORT_DISPLAY - { /* create the TERM ani-object */ - mng_retcode iRetcode = mng_create_ani_term (pData, iTermaction, iIteraction, - iDelay, iItermax); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* save for future reference */ - pData->pTermaniobj = pData->pLastaniobj; - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_termp)*ppChunk)->iTermaction = iTermaction; - ((mng_termp)*ppChunk)->iIteraction = iIteraction; - ((mng_termp)*ppChunk)->iDelay = iDelay; - ((mng_termp)*ppChunk)->iItermax = iItermax; - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_TERM, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_SAVE -READ_CHUNK (mng_read_save) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_SAVE, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasMHDR) || (pData->bHasSAVE)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - pData->bHasSAVE = MNG_TRUE; - - if (pData->fProcesssave) /* inform the application ? */ - { - mng_bool bOke = pData->fProcesssave ((mng_handle)pData); - - if (!bOke) - MNG_ERROR (pData, MNG_APPMISCERROR); - } - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode; - - - /* TODO: something with the parameters */ - - - /* create a SAVE animation object */ - iRetcode = mng_create_ani_save (pData); - - if (!iRetcode) - iRetcode = mng_process_display_save (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_savep)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - - if (iRawlen) /* not empty ? */ - { - mng_uint8 iOtype = *pRawdata; - mng_uint8 iEtype; - mng_uint32 iCount = 0; - mng_uint8p pTemp; - mng_uint8p pNull; - mng_uint32 iLen; - mng_uint32 iOffset[2]; - mng_uint32 iStarttime[2]; - mng_uint32 iFramenr; - mng_uint32 iLayernr; - mng_uint32 iX; - mng_save_entryp pEntry = MNG_NULL; - mng_uint32 iNamesize; - - if ((iOtype != 4) && (iOtype != 8)) - MNG_ERROR (pData, MNG_INVOFFSETSIZE); - - ((mng_savep)*ppChunk)->iOffsettype = iOtype; - - for (iX = 0; iX < 2; iX++) /* do this twice to get the count first ! */ - { - pTemp = pRawdata + 1; - iLen = iRawlen - 1; - - if (iX) /* second run ? */ - { - MNG_ALLOC (pData, pEntry, (iCount * sizeof (mng_save_entry))); - - ((mng_savep)*ppChunk)->iCount = iCount; - ((mng_savep)*ppChunk)->pEntries = pEntry; - } - - while (iLen) /* anything left ? */ - { - iEtype = *pTemp; /* entrytype */ - - if ((iEtype != 0) && (iEtype != 1) && (iEtype != 2) && (iEtype != 3)) - MNG_ERROR (pData, MNG_INVENTRYTYPE); - - pTemp++; - - if (iEtype > 1) - { - iOffset [0] = 0; - iOffset [1] = 0; - iStarttime [0] = 0; - iStarttime [1] = 0; - iLayernr = 0; - iFramenr = 0; - } - else - { - if (iOtype == 4) - { - iOffset [0] = 0; - iOffset [1] = mng_get_uint32 (pTemp); - - pTemp += 4; - } - else - { - iOffset [0] = mng_get_uint32 (pTemp); - iOffset [1] = mng_get_uint32 (pTemp+4); - - pTemp += 8; - } - - if (iEtype > 0) - { - iStarttime [0] = 0; - iStarttime [1] = 0; - iLayernr = 0; - iFramenr = 0; - } - else - { - if (iOtype == 4) - { - iStarttime [0] = 0; - iStarttime [1] = mng_get_uint32 (pTemp+0); - iLayernr = mng_get_uint32 (pTemp+4); - iFramenr = mng_get_uint32 (pTemp+8); - - pTemp += 12; - } - else - { - iStarttime [0] = mng_get_uint32 (pTemp+0); - iStarttime [1] = mng_get_uint32 (pTemp+4); - iLayernr = mng_get_uint32 (pTemp+8); - iFramenr = mng_get_uint32 (pTemp+12); - - pTemp += 16; - } - } - } - - pNull = find_null (pTemp); /* get the name length */ - - if ((pNull - pRawdata) > (mng_int32)iRawlen) - { - iNamesize = iLen; /* no null found; so end of SAVE */ - iLen = 0; - } - else - { - iNamesize = pNull - pTemp; /* should be another entry */ - iLen -= iNamesize; - - if (!iLen) /* must not end with a null ! */ - MNG_ERROR (pData, MNG_ENDWITHNULL); - } - - if (!pEntry) - { - iCount++; - } - else - { - pEntry->iEntrytype = iEtype; - pEntry->iOffset [0] = iOffset [0]; - pEntry->iOffset [1] = iOffset [1]; - pEntry->iStarttime [0] = iStarttime [0]; - pEntry->iStarttime [1] = iStarttime [1]; - pEntry->iLayernr = iLayernr; - pEntry->iFramenr = iFramenr; - pEntry->iNamesize = iNamesize; - - if (iNamesize) - { - MNG_ALLOC (pData, pEntry->zName, iNamesize+1); - MNG_COPY (pEntry->zName, pTemp, iNamesize); - } - - pEntry++; - } - - pTemp += iNamesize; - } - } - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_SAVE, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_SEEK -READ_CHUNK (mng_read_seek) -{ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_SEEK, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasMHDR) || (!pData->bHasSAVE)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_SUPPORT_DISPLAY - /* create a SEEK animation object */ - iRetcode = mng_create_ani_seek (pData, iRawlen, (mng_pchar)pRawdata); - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#endif /* MNG_SUPPORT_DISPLAY */ - - if (pData->fProcessseek) /* inform the app ? */ - { - mng_bool bOke; - mng_pchar zName; - - MNG_ALLOC (pData, zName, iRawlen + 1); - - if (iRawlen) - MNG_COPY (zName, pRawdata, iRawlen); - - bOke = pData->fProcessseek ((mng_handle)pData, zName); - - MNG_FREEX (pData, zName, iRawlen + 1); - - if (!bOke) - MNG_ERROR (pData, MNG_APPMISCERROR); - } - -#ifdef MNG_SUPPORT_DISPLAY - /* do display processing of the SEEK */ - iRetcode = mng_process_display_seek (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_seekp)*ppChunk)->iNamesize = iRawlen; - - if (iRawlen) - { - MNG_ALLOC (pData, ((mng_seekp)*ppChunk)->zName, iRawlen+1); - MNG_COPY (((mng_seekp)*ppChunk)->zName, pRawdata, iRawlen); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_SEEK, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_eXPI -READ_CHUNK (mng_read_expi) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_EXPI, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen < 3) /* check the length */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_expip)*ppChunk)->iSnapshotid = mng_get_uint16 (pRawdata); - ((mng_expip)*ppChunk)->iNamesize = iRawlen - 2; - - if (((mng_expip)*ppChunk)->iNamesize) - { - MNG_ALLOC (pData, ((mng_expip)*ppChunk)->zName, - ((mng_expip)*ppChunk)->iNamesize + 1); - MNG_COPY (((mng_expip)*ppChunk)->zName, pRawdata+2, - ((mng_expip)*ppChunk)->iNamesize); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_EXPI, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_fPRI -READ_CHUNK (mng_read_fpri) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_FPRI, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen != 2) /* must be two bytes long */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_fprip)*ppChunk)->iDeltatype = *pRawdata; - ((mng_fprip)*ppChunk)->iPriority = *(pRawdata+1); - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_FPRI, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_nEED -MNG_LOCAL mng_bool CheckKeyword (mng_datap pData, - mng_uint8p pKeyword) -{ - mng_chunkid handled_chunks [] = - { - MNG_UINT_BACK, /* keep it sorted !!!! */ - MNG_UINT_BASI, - MNG_UINT_CLIP, - MNG_UINT_CLON, -#ifndef MNG_NO_DELTA_PNG -/* TODO: MNG_UINT_DBYK, */ -#endif - MNG_UINT_DEFI, -#ifndef MNG_NO_DELTA_PNG - MNG_UINT_DHDR, -#endif - MNG_UINT_DISC, -#ifndef MNG_NO_DELTA_PNG -/* TODO: MNG_UINT_DROP, */ -#endif - MNG_UINT_ENDL, - MNG_UINT_FRAM, - MNG_UINT_IDAT, - MNG_UINT_IEND, - MNG_UINT_IHDR, -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG - MNG_UINT_IJNG, -#endif - MNG_UINT_IPNG, -#endif -#ifdef MNG_INCLUDE_JNG - MNG_UINT_JDAA, - MNG_UINT_JDAT, - MNG_UINT_JHDR, -/* TODO: MNG_UINT_JSEP, */ - MNG_UINT_JdAA, -#endif - MNG_UINT_LOOP, - MNG_UINT_MAGN, - MNG_UINT_MEND, - MNG_UINT_MHDR, - MNG_UINT_MOVE, -/* TODO: MNG_UINT_ORDR, */ - MNG_UINT_PAST, - MNG_UINT_PLTE, -#ifndef MNG_NO_DELTA_PNG - MNG_UINT_PPLT, - MNG_UINT_PROM, -#endif - MNG_UINT_SAVE, - MNG_UINT_SEEK, - MNG_UINT_SHOW, - MNG_UINT_TERM, -#ifdef MNG_INCLUDE_ANG_PROPOSAL - MNG_UINT_adAT, - MNG_UINT_ahDR, -#endif - MNG_UINT_bKGD, - MNG_UINT_cHRM, -/* TODO: MNG_UINT_eXPI, */ - MNG_UINT_evNT, -/* TODO: MNG_UINT_fPRI, */ - MNG_UINT_gAMA, -/* TODO: MNG_UINT_hIST, */ - MNG_UINT_iCCP, - MNG_UINT_iTXt, -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - MNG_UINT_mpNG, -#endif - MNG_UINT_nEED, -/* TODO: MNG_UINT_oFFs, */ -/* TODO: MNG_UINT_pCAL, */ -/* TODO: MNG_UINT_pHYg, */ -/* TODO: MNG_UINT_pHYs, */ -/* TODO: MNG_UINT_sBIT, */ -/* TODO: MNG_UINT_sCAL, */ -/* TODO: MNG_UINT_sPLT, */ - MNG_UINT_sRGB, - MNG_UINT_tEXt, - MNG_UINT_tIME, - MNG_UINT_tRNS, - MNG_UINT_zTXt, - }; - - mng_bool bOke = MNG_FALSE; - - if (pData->fProcessneed) /* does the app handle it ? */ - bOke = pData->fProcessneed ((mng_handle)pData, (mng_pchar)pKeyword); - - if (!bOke) - { /* find the keyword length */ - mng_uint8p pNull = find_null (pKeyword); - - if (pNull - pKeyword == 4) /* test a chunk ? */ - { /* get the chunk-id */ - mng_chunkid iChunkid = (*pKeyword << 24) + (*(pKeyword+1) << 16) + - (*(pKeyword+2) << 8) + (*(pKeyword+3) ); - /* binary search variables */ - mng_int32 iTop, iLower, iUpper, iMiddle; - /* determine max index of table */ - iTop = (sizeof (handled_chunks) / sizeof (handled_chunks [0])) - 1; - - /* binary search; with 52 chunks, worst-case is 7 comparisons */ - iLower = 0; - iMiddle = iTop >> 1; - iUpper = iTop; - - do /* the binary search itself */ - { - if (handled_chunks [iMiddle] < iChunkid) - iLower = iMiddle + 1; - else if (handled_chunks [iMiddle] > iChunkid) - iUpper = iMiddle - 1; - else - { - bOke = MNG_TRUE; - break; - } - - iMiddle = (iLower + iUpper) >> 1; - } - while (iLower <= iUpper); - } - /* test draft ? */ - if ((!bOke) && (pNull - pKeyword == 8) && - (*pKeyword == 'd') && (*(pKeyword+1) == 'r') && - (*(pKeyword+2) == 'a') && (*(pKeyword+3) == 'f') && - (*(pKeyword+4) == 't') && (*(pKeyword+5) == ' ')) - { - mng_uint32 iDraft; - - iDraft = (*(pKeyword+6) - '0') * 10 + (*(pKeyword+7) - '0'); - bOke = (mng_bool)(iDraft <= MNG_MNG_DRAFT); - } - /* test MNG 1.0/1.1 ? */ - if ((!bOke) && (pNull - pKeyword == 7) && - (*pKeyword == 'M') && (*(pKeyword+1) == 'N') && - (*(pKeyword+2) == 'G') && (*(pKeyword+3) == '-') && - (*(pKeyword+4) == '1') && (*(pKeyword+5) == '.') && - ((*(pKeyword+6) == '0') || (*(pKeyword+6) == '1'))) - bOke = MNG_TRUE; - /* test CACHEOFF ? */ - if ((!bOke) && (pNull - pKeyword == 8) && - (*pKeyword == 'C') && (*(pKeyword+1) == 'A') && - (*(pKeyword+2) == 'C') && (*(pKeyword+3) == 'H') && - (*(pKeyword+4) == 'E') && (*(pKeyword+5) == 'O') && - (*(pKeyword+6) == 'F') && (*(pKeyword+7) == 'F')) - { - if (!pData->pFirstaniobj) /* only if caching hasn't started yet ! */ - { - bOke = MNG_TRUE; - pData->bCacheplayback = MNG_FALSE; - pData->bStorechunks = MNG_FALSE; - } - } - } - - return bOke; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_nEED -READ_CHUNK (mng_read_need) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_NEED, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen < 1) /* check the length */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - { /* let's check it */ - mng_bool bOke = MNG_TRUE; - mng_pchar zKeywords; - mng_uint8p pNull, pTemp; - - MNG_ALLOC (pData, zKeywords, iRawlen + 1); - - if (iRawlen) - MNG_COPY (zKeywords, pRawdata, iRawlen); - - pTemp = (mng_uint8p)zKeywords; - pNull = find_null (pTemp); - - while ((bOke) && (pNull < (mng_uint8p)zKeywords + iRawlen)) - { - bOke = CheckKeyword (pData, pTemp); - pTemp = pNull + 1; - pNull = find_null (pTemp); - } - - if (bOke) - bOke = CheckKeyword (pData, pTemp); - - MNG_FREEX (pData, zKeywords, iRawlen + 1); - - if (!bOke) - MNG_ERROR (pData, MNG_UNSUPPORTEDNEED); - } - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_needp)*ppChunk)->iKeywordssize = iRawlen; - - if (iRawlen) - { - MNG_ALLOC (pData, ((mng_needp)*ppChunk)->zKeywords, iRawlen+1); - MNG_COPY (((mng_needp)*ppChunk)->zKeywords, pRawdata, iRawlen); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_NEED, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_pHYg -READ_CHUNK (mng_read_phyg) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_PHYG, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* it's 9 bytes or empty; no more, no less! */ - if ((iRawlen != 9) && (iRawlen != 0)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_phygp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - - if (iRawlen) - { - ((mng_phygp)*ppChunk)->iSizex = mng_get_uint32 (pRawdata); - ((mng_phygp)*ppChunk)->iSizey = mng_get_uint32 (pRawdata+4); - ((mng_phygp)*ppChunk)->iUnit = *(pRawdata+8); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_PHYG, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_INCLUDE_JNG -READ_CHUNK (mng_read_jhdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_JHDR, MNG_LC_START); -#endif - /* sequence checks */ - if ((pData->eSigtype != mng_it_jng) && (pData->eSigtype != mng_it_mng)) - MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); - - if ((pData->eSigtype == mng_it_jng) && (pData->iChunkseq > 1)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen != 16) /* length oke ? */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - /* inside a JHDR-IEND block now */ - pData->bHasJHDR = MNG_TRUE; - /* and store interesting fields */ - pData->iDatawidth = mng_get_uint32 (pRawdata); - pData->iDataheight = mng_get_uint32 (pRawdata+4); - pData->iJHDRcolortype = *(pRawdata+8); - pData->iJHDRimgbitdepth = *(pRawdata+9); - pData->iJHDRimgcompression = *(pRawdata+10); - pData->iJHDRimginterlace = *(pRawdata+11); - pData->iJHDRalphabitdepth = *(pRawdata+12); - pData->iJHDRalphacompression = *(pRawdata+13); - pData->iJHDRalphafilter = *(pRawdata+14); - pData->iJHDRalphainterlace = *(pRawdata+15); - - -#if defined(MNG_NO_1_2_4BIT_SUPPORT) || defined(MNG_NO_16BIT_SUPPORT) - pData->iPNGmult = 1; - pData->iPNGdepth = pData->iJHDRalphabitdepth; -#endif - -#ifdef MNG_NO_1_2_4BIT_SUPPORT - if (pData->iJHDRalphabitdepth < 8) - pData->iJHDRalphabitdepth = 8; -#endif - -#ifdef MNG_NO_16BIT_SUPPORT - if (pData->iJHDRalphabitdepth > 8) - { - pData->iPNGmult = 2; - pData->iJHDRalphabitdepth = 8; - } -#endif - /* parameter validity checks */ - if ((pData->iJHDRcolortype != MNG_COLORTYPE_JPEGGRAY ) && - (pData->iJHDRcolortype != MNG_COLORTYPE_JPEGCOLOR ) && - (pData->iJHDRcolortype != MNG_COLORTYPE_JPEGGRAYA ) && - (pData->iJHDRcolortype != MNG_COLORTYPE_JPEGCOLORA) ) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - - if ((pData->iJHDRimgbitdepth != MNG_BITDEPTH_JPEG8 ) && - (pData->iJHDRimgbitdepth != MNG_BITDEPTH_JPEG12 ) && - (pData->iJHDRimgbitdepth != MNG_BITDEPTH_JPEG8AND12) ) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if (pData->iJHDRimgcompression != MNG_COMPRESSION_BASELINEJPEG) - MNG_ERROR (pData, MNG_INVALIDCOMPRESS); - - if ((pData->iJHDRimginterlace != MNG_INTERLACE_SEQUENTIAL ) && - (pData->iJHDRimginterlace != MNG_INTERLACE_PROGRESSIVE) ) - MNG_ERROR (pData, MNG_INVALIDINTERLACE); - - if ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || - (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) - { - if ((pData->iJHDRalphabitdepth != MNG_BITDEPTH_8 ) -#ifndef MNG_NO_1_2_4BIT_SUPPORT - && (pData->iJHDRalphabitdepth != MNG_BITDEPTH_1 ) && - (pData->iJHDRalphabitdepth != MNG_BITDEPTH_2 ) && - (pData->iJHDRalphabitdepth != MNG_BITDEPTH_4 ) -#endif -#ifndef MNG_NO_16BIT_SUPPORT - && (pData->iJHDRalphabitdepth != MNG_BITDEPTH_16) -#endif - ) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if ((pData->iJHDRalphacompression != MNG_COMPRESSION_DEFLATE ) && - (pData->iJHDRalphacompression != MNG_COMPRESSION_BASELINEJPEG) ) - MNG_ERROR (pData, MNG_INVALIDCOMPRESS); - - if ((pData->iJHDRalphacompression == MNG_COMPRESSION_BASELINEJPEG) && - (pData->iJHDRalphabitdepth != MNG_BITDEPTH_8 ) ) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - -#if defined(FILTER192) || defined(FILTER193) - if ((pData->iJHDRalphafilter != MNG_FILTER_ADAPTIVE ) && -#if defined(FILTER192) && defined(FILTER193) - (pData->iJHDRalphafilter != MNG_FILTER_DIFFERING) && - (pData->iJHDRalphafilter != MNG_FILTER_NOFILTER ) ) -#else -#ifdef FILTER192 - (pData->iJHDRalphafilter != MNG_FILTER_DIFFERING) ) -#else - (pData->iJHDRalphafilter != MNG_FILTER_NOFILTER ) ) -#endif -#endif - MNG_ERROR (pData, MNG_INVALIDFILTER); -#else - if (pData->iJHDRalphafilter) - MNG_ERROR (pData, MNG_INVALIDFILTER); -#endif - - if ((pData->iJHDRalphainterlace != MNG_INTERLACE_NONE ) && - (pData->iJHDRalphainterlace != MNG_INTERLACE_ADAM7) ) - MNG_ERROR (pData, MNG_INVALIDINTERLACE); - - } - else - { - if (pData->iJHDRalphabitdepth) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if (pData->iJHDRalphacompression) - MNG_ERROR (pData, MNG_INVALIDCOMPRESS); - - if (pData->iJHDRalphafilter) - MNG_ERROR (pData, MNG_INVALIDFILTER); - - if (pData->iJHDRalphainterlace) - MNG_ERROR (pData, MNG_INVALIDINTERLACE); - - } - - if (!pData->bHasheader) /* first chunk ? */ - { - pData->bHasheader = MNG_TRUE; /* we've got a header */ - pData->eImagetype = mng_it_jng; /* then this must be a JNG */ - pData->iWidth = mng_get_uint32 (pRawdata); - pData->iHeight = mng_get_uint32 (pRawdata+4); - /* predict alpha-depth ! */ - if ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || - (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) - pData->iAlphadepth = pData->iJHDRalphabitdepth; - else - pData->iAlphadepth = 0; - /* fits on maximum canvas ? */ - if ((pData->iWidth > pData->iMaxwidth) || (pData->iHeight > pData->iMaxheight)) - MNG_WARNING (pData, MNG_IMAGETOOLARGE); - - if (pData->fProcessheader) /* inform the app ? */ - if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) - MNG_ERROR (pData, MNG_APPMISCERROR); - - } - - pData->iColortype = 0; /* fake grayscale for other routines */ - pData->iImagelevel++; /* one level deeper */ - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode = mng_process_display_jhdr (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_jhdrp)*ppChunk)->iWidth = mng_get_uint32 (pRawdata); - ((mng_jhdrp)*ppChunk)->iHeight = mng_get_uint32 (pRawdata+4); - ((mng_jhdrp)*ppChunk)->iColortype = *(pRawdata+8); - ((mng_jhdrp)*ppChunk)->iImagesampledepth = *(pRawdata+9); - ((mng_jhdrp)*ppChunk)->iImagecompression = *(pRawdata+10); - ((mng_jhdrp)*ppChunk)->iImageinterlace = *(pRawdata+11); - ((mng_jhdrp)*ppChunk)->iAlphasampledepth = *(pRawdata+12); -#ifdef MNG_NO_16BIT_SUPPORT - if (*(pRawdata+12) > 8) - ((mng_jhdrp)*ppChunk)->iAlphasampledepth = 8; -#endif - ((mng_jhdrp)*ppChunk)->iAlphacompression = *(pRawdata+13); - ((mng_jhdrp)*ppChunk)->iAlphafilter = *(pRawdata+14); - ((mng_jhdrp)*ppChunk)->iAlphainterlace = *(pRawdata+15); - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_JHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#else -#define read_jhdr 0 -#endif /* MNG_INCLUDE_JNG */ -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_INCLUDE_JNG -READ_CHUNK (mng_read_jdaa) -{ -#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) - volatile mng_retcode iRetcode; - - iRetcode=MNG_NOERROR; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_JDAA, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasJHDR) && (!pData->bHasDHDR)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (pData->bHasJSEP) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (pData->iJHDRalphacompression != MNG_COMPRESSION_BASELINEJPEG) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen == 0) /* can never be empty */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - pData->bHasJDAA = MNG_TRUE; /* got some JDAA now, don't we */ - -#ifdef MNG_SUPPORT_DISPLAY - iRetcode = mng_process_display_jdaa (pData, iRawlen, pRawdata); - - if (iRetcode) /* on error bail out */ - return iRetcode; -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_jdaap)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - ((mng_jdaap)*ppChunk)->iDatasize = iRawlen; - - if (iRawlen != 0) /* is there any data ? */ - { - MNG_ALLOC (pData, ((mng_jdaap)*ppChunk)->pData, iRawlen); - MNG_COPY (((mng_jdaap)*ppChunk)->pData, pRawdata, iRawlen); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_JDAA, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#else -#define read_jdaa 0 -#endif /* MNG_INCLUDE_JNG */ -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_INCLUDE_JNG -READ_CHUNK (mng_read_jdat) -{ -#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) - volatile mng_retcode iRetcode; - - iRetcode=MNG_NOERROR; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_JDAT, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasJHDR) && (!pData->bHasDHDR)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen == 0) /* can never be empty */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - pData->bHasJDAT = MNG_TRUE; /* got some JDAT now, don't we */ - -#ifdef MNG_SUPPORT_DISPLAY - iRetcode = mng_process_display_jdat (pData, iRawlen, pRawdata); - - if (iRetcode) /* on error bail out */ - return iRetcode; -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_jdatp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); - ((mng_jdatp)*ppChunk)->iDatasize = iRawlen; - - if (iRawlen != 0) /* is there any data ? */ - { - MNG_ALLOC (pData, ((mng_jdatp)*ppChunk)->pData, iRawlen); - MNG_COPY (((mng_jdatp)*ppChunk)->pData, pRawdata, iRawlen); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_JDAT, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#else -#define read_jdat 0 -#endif /* MNG_INCLUDE_JNG */ -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_INCLUDE_JNG -READ_CHUNK (mng_read_jsep) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_JSEP, MNG_LC_START); -#endif - - if (!pData->bHasJHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen != 0) /* must be empty ! */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - pData->bHasJSEP = MNG_TRUE; /* indicate we've had the 8-/12-bit separator */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_JSEP, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#else -#define read_jsep 0 -#endif /* MNG_INCLUDE_JNG */ -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_NO_DELTA_PNG -READ_CHUNK (mng_read_dhdr) -{ - mng_uint8 iImagetype, iDeltatype; -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_DHDR, MNG_LC_START); -#endif - - if (!pData->bHasMHDR) /* sequence checks */ - MNG_ERROR (pData, MNG_SEQUENCEERROR); - -#ifdef MNG_INCLUDE_JNG - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* check for valid length */ - if ((iRawlen != 4) && (iRawlen != 12) && (iRawlen != 20)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - iImagetype = *(pRawdata+2); /* check fields for validity */ - iDeltatype = *(pRawdata+3); - - if (iImagetype > MNG_IMAGETYPE_JNG) - MNG_ERROR (pData, MNG_INVIMAGETYPE); - - if (iDeltatype > MNG_DELTATYPE_NOCHANGE) - MNG_ERROR (pData, MNG_INVDELTATYPE); - - if ((iDeltatype == MNG_DELTATYPE_REPLACE) && (iRawlen > 12)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((iDeltatype == MNG_DELTATYPE_NOCHANGE) && (iRawlen > 4)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - pData->bHasDHDR = MNG_TRUE; /* inside a DHDR-IEND block now */ - pData->iDeltatype = iDeltatype; - - pData->iImagelevel++; /* one level deeper */ - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_uint16 iObjectid = mng_get_uint16 (pRawdata); - mng_uint32 iBlockwidth = 0; - mng_uint32 iBlockheight = 0; - mng_uint32 iBlockx = 0; - mng_uint32 iBlocky = 0; - mng_retcode iRetcode; - - if (iRawlen > 4) - { - iBlockwidth = mng_get_uint32 (pRawdata+4); - iBlockheight = mng_get_uint32 (pRawdata+8); - } - - if (iRawlen > 12) - { - iBlockx = mng_get_uint32 (pRawdata+12); - iBlocky = mng_get_uint32 (pRawdata+16); - } - - iRetcode = mng_create_ani_dhdr (pData, iObjectid, iImagetype, iDeltatype, - iBlockwidth, iBlockheight, iBlockx, iBlocky); - -/* if (!iRetcode) - iRetcode = mng_process_display_dhdr (pData, iObjectid, iImagetype, iDeltatype, - iBlockwidth, iBlockheight, iBlockx, iBlocky); */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_dhdrp)*ppChunk)->iObjectid = mng_get_uint16 (pRawdata); - ((mng_dhdrp)*ppChunk)->iImagetype = iImagetype; - ((mng_dhdrp)*ppChunk)->iDeltatype = iDeltatype; - - if (iRawlen > 4) - { - ((mng_dhdrp)*ppChunk)->iBlockwidth = mng_get_uint32 (pRawdata+4); - ((mng_dhdrp)*ppChunk)->iBlockheight = mng_get_uint32 (pRawdata+8); - } - - if (iRawlen > 12) - { - ((mng_dhdrp)*ppChunk)->iBlockx = mng_get_uint32 (pRawdata+12); - ((mng_dhdrp)*ppChunk)->iBlocky = mng_get_uint32 (pRawdata+16); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_DHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_NO_DELTA_PNG -READ_CHUNK (mng_read_prom) -{ - mng_uint8 iColortype; - mng_uint8 iSampledepth; - mng_uint8 iFilltype; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_PROM, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasMHDR) || (!pData->bHasDHDR)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen != 3) /* gotta be exactly 3 bytes */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - iColortype = *pRawdata; /* check fields for validity */ - iSampledepth = *(pRawdata+1); - iFilltype = *(pRawdata+2); - - if ((iColortype != MNG_COLORTYPE_GRAY ) && - (iColortype != MNG_COLORTYPE_RGB ) && - (iColortype != MNG_COLORTYPE_INDEXED) && - (iColortype != MNG_COLORTYPE_GRAYA ) && - (iColortype != MNG_COLORTYPE_RGBA ) ) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - -#ifdef MNG_NO_16BIT_SUPPORT - if (iSampledepth == MNG_BITDEPTH_16 ) - iSampledepth = MNG_BITDEPTH_8; -#endif - - if ((iSampledepth != MNG_BITDEPTH_1 ) && - (iSampledepth != MNG_BITDEPTH_2 ) && - (iSampledepth != MNG_BITDEPTH_4 ) && - (iSampledepth != MNG_BITDEPTH_8 ) -#ifndef MNG_NO_16BIT_SUPPORT - && (iSampledepth != MNG_BITDEPTH_16) -#endif - ) - MNG_ERROR (pData, MNG_INVSAMPLEDEPTH); - - if ((iFilltype != MNG_FILLMETHOD_LEFTBITREPLICATE) && - (iFilltype != MNG_FILLMETHOD_ZEROFILL ) ) - MNG_ERROR (pData, MNG_INVFILLMETHOD); - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode = mng_create_ani_prom (pData, iSampledepth, - iColortype, iFilltype); - -/* if (!iRetcode) - iRetcode = mng_process_display_prom (pData, iSampledepth, - iColortype, iFilltype); */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_promp)*ppChunk)->iColortype = iColortype; - ((mng_promp)*ppChunk)->iSampledepth = iSampledepth; - ((mng_promp)*ppChunk)->iFilltype = iFilltype; - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_PROM, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_NO_DELTA_PNG -READ_CHUNK (mng_read_ipng) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_IPNG, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasMHDR) || (!pData->bHasDHDR)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen != 0) /* gotta be empty */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode = mng_create_ani_ipng (pData); - - if (!iRetcode) - iRetcode = mng_process_display_ipng (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_IPNG, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_NO_DELTA_PNG -READ_CHUNK (mng_read_pplt) -{ - mng_uint8 iDeltatype; - mng_uint8p pTemp; - mng_uint32 iLen; - mng_uint8 iX, iM; - mng_uint32 iY; - mng_uint32 iMax; - mng_rgbpaltab aIndexentries; - mng_uint8arr aAlphaentries; - mng_uint8arr aUsedentries; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_PPLT, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasMHDR) && (!pData->bHasDHDR)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen < 1) /* must have at least 1 byte */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - iDeltatype = *pRawdata; - /* valid ? */ - if (iDeltatype > MNG_DELTATYPE_DELTARGBA) - MNG_ERROR (pData, MNG_INVDELTATYPE); - /* must be indexed color ! */ - if (pData->iColortype != MNG_COLORTYPE_INDEXED) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - - pTemp = pRawdata + 1; - iLen = iRawlen - 1; - iMax = 0; - - for (iY = 0; iY < 256; iY++) /* reset arrays */ - { - aIndexentries [iY].iRed = 0; - aIndexentries [iY].iGreen = 0; - aIndexentries [iY].iBlue = 0; - aAlphaentries [iY] = 255; - aUsedentries [iY] = 0; - } - - while (iLen) /* as long as there are entries left ... */ - { - mng_uint32 iDiff; - - if (iLen < 2) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - iX = *pTemp; /* get start and end index */ - iM = *(pTemp+1); - - if (iM < iX) - MNG_ERROR (pData, MNG_INVALIDINDEX); - - if ((mng_uint32)iM >= iMax) /* determine highest used index */ - iMax = (mng_uint32)iM + 1; - - pTemp += 2; - iLen -= 2; - iDiff = (iM - iX + 1); - if ((iDeltatype == MNG_DELTATYPE_REPLACERGB ) || - (iDeltatype == MNG_DELTATYPE_DELTARGB ) ) - iDiff = iDiff * 3; - else - if ((iDeltatype == MNG_DELTATYPE_REPLACERGBA) || - (iDeltatype == MNG_DELTATYPE_DELTARGBA ) ) - iDiff = iDiff * 4; - - if (iLen < iDiff) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - if ((iDeltatype == MNG_DELTATYPE_REPLACERGB ) || - (iDeltatype == MNG_DELTATYPE_DELTARGB ) ) - { - for (iY = (mng_uint32)iX; iY <= (mng_uint32)iM; iY++) - { - aIndexentries [iY].iRed = *pTemp; - aIndexentries [iY].iGreen = *(pTemp+1); - aIndexentries [iY].iBlue = *(pTemp+2); - aUsedentries [iY] = 1; - - pTemp += 3; - iLen -= 3; - } - } - else - if ((iDeltatype == MNG_DELTATYPE_REPLACEALPHA) || - (iDeltatype == MNG_DELTATYPE_DELTAALPHA ) ) - { - for (iY = (mng_uint32)iX; iY <= (mng_uint32)iM; iY++) - { - aAlphaentries [iY] = *pTemp; - aUsedentries [iY] = 1; - - pTemp++; - iLen--; - } - } - else - { - for (iY = (mng_uint32)iX; iY <= (mng_uint32)iM; iY++) - { - aIndexentries [iY].iRed = *pTemp; - aIndexentries [iY].iGreen = *(pTemp+1); - aIndexentries [iY].iBlue = *(pTemp+2); - aAlphaentries [iY] = *(pTemp+3); - aUsedentries [iY] = 1; - - pTemp += 4; - iLen -= 4; - } - } - } - - switch (pData->iBitdepth) /* check maximum allowed entries for bitdepth */ - { - case MNG_BITDEPTH_1 : { - if (iMax > 2) - MNG_ERROR (pData, MNG_INVALIDINDEX); - break; - } - case MNG_BITDEPTH_2 : { - if (iMax > 4) - MNG_ERROR (pData, MNG_INVALIDINDEX); - break; - } - case MNG_BITDEPTH_4 : { - if (iMax > 16) - MNG_ERROR (pData, MNG_INVALIDINDEX); - break; - } - } - -#ifdef MNG_SUPPORT_DISPLAY - { /* create animation object */ - mng_retcode iRetcode = mng_create_ani_pplt (pData, iDeltatype, iMax, - aIndexentries, aAlphaentries, - aUsedentries); - -/* if (!iRetcode) - iRetcode = mng_process_display_pplt (pData, iDeltatype, iMax, aIndexentries, - aAlphaentries, aUsedentries); */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_ppltp)*ppChunk)->iDeltatype = iDeltatype; - ((mng_ppltp)*ppChunk)->iCount = iMax; - - for (iY = 0; iY < 256; iY++) - { - ((mng_ppltp)*ppChunk)->aEntries [iY].iRed = aIndexentries [iY].iRed; - ((mng_ppltp)*ppChunk)->aEntries [iY].iGreen = aIndexentries [iY].iGreen; - ((mng_ppltp)*ppChunk)->aEntries [iY].iBlue = aIndexentries [iY].iBlue; - ((mng_ppltp)*ppChunk)->aEntries [iY].iAlpha = aAlphaentries [iY]; - ((mng_ppltp)*ppChunk)->aEntries [iY].bUsed = (mng_bool)(aUsedentries [iY]); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_PPLT, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG -READ_CHUNK (mng_read_ijng) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_IJNG, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasMHDR) || (!pData->bHasDHDR)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen != 0) /* gotta be empty */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode = mng_create_ani_ijng (pData); - - if (!iRetcode) - iRetcode = mng_process_display_ijng (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_IJNG, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_NO_DELTA_PNG -READ_CHUNK (mng_read_drop) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_DROP, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasMHDR) || (!pData->bHasDHDR)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* check length */ - if ((iRawlen < 4) || ((iRawlen % 4) != 0)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_dropp)*ppChunk)->iCount = iRawlen / 4; - - if (iRawlen) - { - mng_uint32 iX; - mng_uint8p pTemp = pRawdata; - mng_uint32p pEntry; - - MNG_ALLOC (pData, pEntry, iRawlen); - - ((mng_dropp)*ppChunk)->pChunknames = (mng_ptr)pEntry; - - for (iX = 0; iX < iRawlen / 4; iX++) - { - *pEntry = mng_get_uint32 (pTemp); - - pTemp += 4; - pEntry++; - } - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_DROP, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DBYK -READ_CHUNK (mng_read_dbyk) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_DBYK, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasMHDR) || (!pData->bHasDHDR)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen < 6) /* must be at least 6 long */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_dbykp)*ppChunk)->iChunkname = mng_get_uint32 (pRawdata); - ((mng_dbykp)*ppChunk)->iPolarity = *(pRawdata+4); - ((mng_dbykp)*ppChunk)->iKeywordssize = iRawlen - 5; - - if (iRawlen > 5) - { - MNG_ALLOC (pData, ((mng_dbykp)*ppChunk)->zKeywords, iRawlen-4); - MNG_COPY (((mng_dbykp)*ppChunk)->zKeywords, pRawdata+5, iRawlen-5); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_DBYK, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR -READ_CHUNK (mng_read_ordr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_ORDR, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasMHDR) || (!pData->bHasDHDR)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* check length */ - if ((iRawlen < 5) || ((iRawlen % 5) != 0)) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#ifdef MNG_SUPPORT_DISPLAY - { - - - /* TODO: something !!! */ - - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_ordrp)*ppChunk)->iCount = iRawlen / 5; - - if (iRawlen) - { - mng_uint32 iX; - mng_ordr_entryp pEntry; - mng_uint8p pTemp = pRawdata; - - MNG_ALLOC (pData, pEntry, iRawlen); - - ((mng_ordrp)*ppChunk)->pEntries = pEntry; - - for (iX = 0; iX < iRawlen / 5; iX++) - { - pEntry->iChunkname = mng_get_uint32 (pTemp); - pEntry->iOrdertype = *(pTemp+4); - - pTemp += 5; - pEntry++; - } - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_ORDR, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_MAGN -READ_CHUNK (mng_read_magn) -{ - mng_uint16 iFirstid, iLastid; - mng_uint8 iMethodX, iMethodY; - mng_uint16 iMX, iMY, iML, iMR, iMT, iMB; - mng_bool bFaulty; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_MAGN, MNG_LC_START); -#endif - /* sequence checks */ -#ifdef MNG_SUPPORT_JNG - if ((!pData->bHasMHDR) || (pData->bHasIHDR) || (pData->bHasDHDR) || (pData->bHasJHDR)) -#else - if ((!pData->bHasMHDR) || (pData->bHasIHDR) || (pData->bHasDHDR)) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* check length */ - if (iRawlen > 20) - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - /* following is an ugly hack to allow faulty layout caused by previous - versions of libmng and MNGeye, which wrote MAGN with a 16-bit - MethodX/MethodY (as opposed to the proper 8-bit as defined in the spec!) */ - - if ((iRawlen == 6) || (iRawlen == 8) || (iRawlen == 10) || (iRawlen == 12) || - (iRawlen == 14) || (iRawlen == 16) || (iRawlen == 20)) - bFaulty = MNG_TRUE; /* these lengths are all wrong */ - else /* length 18 can be right or wrong !!! */ - if ((iRawlen == 18) && (mng_get_uint16 (pRawdata+4) <= 5) && - (mng_get_uint16 (pRawdata+6) < 256) && - (mng_get_uint16 (pRawdata+8) < 256) && - (mng_get_uint16 (pRawdata+10) < 256) && - (mng_get_uint16 (pRawdata+12) < 256) && - (mng_get_uint16 (pRawdata+14) < 256) && - (mng_get_uint16 (pRawdata+16) < 256)) - bFaulty = MNG_TRUE; /* this is very likely the wrong layout */ - else - bFaulty = MNG_FALSE; /* all other cases are handled as right */ - - if (bFaulty) /* wrong layout ? */ - { - if (iRawlen > 0) /* get the fields */ - iFirstid = mng_get_uint16 (pRawdata); - else - iFirstid = 0; - - if (iRawlen > 2) - iLastid = mng_get_uint16 (pRawdata+2); - else - iLastid = iFirstid; - - if (iRawlen > 4) - iMethodX = (mng_uint8)(mng_get_uint16 (pRawdata+4)); - else - iMethodX = 0; - - if (iRawlen > 6) - iMX = mng_get_uint16 (pRawdata+6); - else - iMX = 1; - - if (iRawlen > 8) - iMY = mng_get_uint16 (pRawdata+8); - else - iMY = iMX; - - if (iRawlen > 10) - iML = mng_get_uint16 (pRawdata+10); - else - iML = iMX; - - if (iRawlen > 12) - iMR = mng_get_uint16 (pRawdata+12); - else - iMR = iMX; - - if (iRawlen > 14) - iMT = mng_get_uint16 (pRawdata+14); - else - iMT = iMY; - - if (iRawlen > 16) - iMB = mng_get_uint16 (pRawdata+16); - else - iMB = iMY; - - if (iRawlen > 18) - iMethodY = (mng_uint8)(mng_get_uint16 (pRawdata+18)); - else - iMethodY = iMethodX; - } - else /* proper layout !!!! */ - { - if (iRawlen > 0) /* get the fields */ - iFirstid = mng_get_uint16 (pRawdata); - else - iFirstid = 0; - - if (iRawlen > 2) - iLastid = mng_get_uint16 (pRawdata+2); - else - iLastid = iFirstid; - - if (iRawlen > 4) - iMethodX = *(pRawdata+4); - else - iMethodX = 0; - - if (iRawlen > 5) - iMX = mng_get_uint16 (pRawdata+5); - else - iMX = 1; - - if (iRawlen > 7) - iMY = mng_get_uint16 (pRawdata+7); - else - iMY = iMX; - - if (iRawlen > 9) - iML = mng_get_uint16 (pRawdata+9); - else - iML = iMX; - - if (iRawlen > 11) - iMR = mng_get_uint16 (pRawdata+11); - else - iMR = iMX; - - if (iRawlen > 13) - iMT = mng_get_uint16 (pRawdata+13); - else - iMT = iMY; - - if (iRawlen > 15) - iMB = mng_get_uint16 (pRawdata+15); - else - iMB = iMY; - - if (iRawlen > 17) - iMethodY = *(pRawdata+17); - else - iMethodY = iMethodX; - } - /* check field validity */ - if ((iMethodX > 5) || (iMethodY > 5)) - MNG_ERROR (pData, MNG_INVALIDMETHOD); - -#ifdef MNG_SUPPORT_DISPLAY - { - mng_retcode iRetcode; - - iRetcode = mng_create_ani_magn (pData, iFirstid, iLastid, iMethodX, - iMX, iMY, iML, iMR, iMT, iMB, iMethodY); - -/* if (!iRetcode) - iRetcode = mng_process_display_magn (pData, iFirstid, iLastid, iMethodX, - iMX, iMY, iML, iMR, iMT, iMB, iMethodY); */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_magnp)*ppChunk)->iFirstid = iFirstid; - ((mng_magnp)*ppChunk)->iLastid = iLastid; - ((mng_magnp)*ppChunk)->iMethodX = iMethodX; - ((mng_magnp)*ppChunk)->iMX = iMX; - ((mng_magnp)*ppChunk)->iMY = iMY; - ((mng_magnp)*ppChunk)->iML = iML; - ((mng_magnp)*ppChunk)->iMR = iMR; - ((mng_magnp)*ppChunk)->iMT = iMT; - ((mng_magnp)*ppChunk)->iMB = iMB; - ((mng_magnp)*ppChunk)->iMethodY = iMethodY; - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_MAGN, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_INCLUDE_MPNG_PROPOSAL -READ_CHUNK (mng_read_mpng) -{ - mng_uint32 iFramewidth; - mng_uint32 iFrameheight; - mng_uint16 iTickspersec; - mng_uint32 iFramessize; - mng_uint32 iCompressedsize; -#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) - mng_retcode iRetcode; - mng_uint16 iNumplays; - mng_uint32 iBufsize; - mng_uint8p pBuf = 0; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_MPNG, MNG_LC_START); -#endif - /* sequence checks */ - if (!pData->bHasIHDR) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen < 41) /* length must be at least 41 */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - - iFramewidth = mng_get_int32 (pRawdata); - if (iFramewidth == 0) /* frame_width must not be zero */ - MNG_ERROR (pData, MNG_INVALIDWIDTH); - - iFrameheight = mng_get_int32 (pRawdata+4); - if (iFrameheight == 0) /* frame_height must not be zero */ - MNG_ERROR (pData, MNG_INVALIDHEIGHT); - - iTickspersec = mng_get_uint16 (pRawdata+10); - if (iTickspersec == 0) /* delay_den must not be zero */ - MNG_ERROR (pData, MNG_INVALIDFIELDVAL); - - if (*(pRawdata+12) != 0) /* only deflate compression-method allowed */ - MNG_ERROR (pData, MNG_INVALIDCOMPRESS); - -#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) - iNumplays = mng_get_uint16 (pRawdata+8); - iCompressedsize = (mng_uint32)(iRawlen - 13); -#endif - -#ifdef MNG_SUPPORT_DISPLAY - { - iRetcode = mng_inflate_buffer (pData, pRawdata+13, iCompressedsize, - &pBuf, &iBufsize, &iFramessize); - if (iRetcode) /* on error bail out */ - { - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - - if (iFramessize % 26) - { - MNG_FREEX (pData, pBuf, iBufsize); - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } - - iRetcode = mng_create_mpng_obj (pData, iFramewidth, iFrameheight, iNumplays, - iTickspersec, iFramessize, pBuf); - if (iRetcode) /* on error bail out */ - { - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - } -#endif /* MNG_SUPPORT_DISPLAY */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the fields */ - ((mng_mpngp)*ppChunk)->iFramewidth = iFramewidth; - ((mng_mpngp)*ppChunk)->iFrameheight = iFrameheight; - ((mng_mpngp)*ppChunk)->iNumplays = iNumplays; - ((mng_mpngp)*ppChunk)->iTickspersec = iTickspersec; - ((mng_mpngp)*ppChunk)->iCompressionmethod = *(pRawdata+14); - -#ifndef MNG_SUPPORT_DISPLAY - iRetcode = mng_inflate_buffer (pData, pRawdata+13, iCompressedsize, - &pBuf, &iBufsize, &iFramessize); - if (iRetcode) /* on error bail out */ - { - MNG_FREEX (pData, pBuf, iBufsize); - return iRetcode; - } - - if (iFramessize % 26) - { - MNG_FREEX (pData, pBuf, iBufsize); - MNG_ERROR (pData, MNG_INVALIDLENGTH); - } -#endif - - if (iFramessize) - { - MNG_ALLOCX (pData, ((mng_mpngp)*ppChunk)->pFrames, iFramessize); - if (((mng_mpngp)*ppChunk)->pFrames == 0) - { - MNG_FREEX (pData, pBuf, iBufsize); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - - ((mng_mpngp)*ppChunk)->iFramessize = iFramessize; - MNG_COPY (((mng_mpngp)*ppChunk)->pFrames, pBuf, iFramessize); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) - MNG_FREEX (pData, pBuf, iBufsize); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_MPNG, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifndef MNG_SKIPCHUNK_evNT -READ_CHUNK (mng_read_evnt) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_EVNT, MNG_LC_START); -#endif - /* sequence checks */ - if ((!pData->bHasMHDR) || (pData->bHasSAVE)) - MNG_ERROR (pData, MNG_SEQUENCEERROR); - - if (iRawlen < 2) /* must have at least 1 entry ! */ - MNG_ERROR (pData, MNG_INVALIDLENGTH); - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_SUPPORT_DYNAMICMNG) - { - if (iRawlen) /* not empty ? */ - { - mng_retcode iRetcode; - mng_uint8p pTemp; - mng_uint8p pNull; - mng_uint32 iLen; - mng_uint8 iEventtype; - mng_uint8 iMasktype; - mng_int32 iLeft; - mng_int32 iRight; - mng_int32 iTop; - mng_int32 iBottom; - mng_uint16 iObjectid; - mng_uint8 iIndex; - mng_uint32 iNamesize; - - pTemp = pRawdata; - iLen = iRawlen; - - while (iLen) /* anything left ? */ - { - iEventtype = *pTemp; /* eventtype */ - if (iEventtype > 5) - MNG_ERROR (pData, MNG_INVALIDEVENT); - - pTemp++; - - iMasktype = *pTemp; /* masktype */ - if (iMasktype > 5) - MNG_ERROR (pData, MNG_INVALIDMASK); - - pTemp++; - iLen -= 2; - - iLeft = 0; - iRight = 0; - iTop = 0; - iBottom = 0; - iObjectid = 0; - iIndex = 0; - - switch (iMasktype) - { - case 1 : - { - if (iLen > 16) - { - iLeft = mng_get_int32 (pTemp); - iRight = mng_get_int32 (pTemp+4); - iTop = mng_get_int32 (pTemp+8); - iBottom = mng_get_int32 (pTemp+12); - pTemp += 16; - iLen -= 16; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - case 2 : - { - if (iLen > 2) - { - iObjectid = mng_get_uint16 (pTemp); - pTemp += 2; - iLen -= 2; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - case 3 : - { - if (iLen > 3) - { - iObjectid = mng_get_uint16 (pTemp); - iIndex = *(pTemp+2); - pTemp += 3; - iLen -= 3; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - case 4 : - { - if (iLen > 18) - { - iLeft = mng_get_int32 (pTemp); - iRight = mng_get_int32 (pTemp+4); - iTop = mng_get_int32 (pTemp+8); - iBottom = mng_get_int32 (pTemp+12); - iObjectid = mng_get_uint16 (pTemp+16); - pTemp += 18; - iLen -= 18; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - case 5 : - { - if (iLen > 19) - { - iLeft = mng_get_int32 (pTemp); - iRight = mng_get_int32 (pTemp+4); - iTop = mng_get_int32 (pTemp+8); - iBottom = mng_get_int32 (pTemp+12); - iObjectid = mng_get_uint16 (pTemp+16); - iIndex = *(pTemp+18); - pTemp += 19; - iLen -= 19; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - } - - pNull = find_null (pTemp); /* get the name length */ - - if ((pNull - pTemp) > (mng_int32)iLen) - { - iNamesize = iLen; /* no null found; so end of evNT */ - iLen = 0; - } - else - { - iNamesize = pNull - pTemp; /* should be another entry */ - iLen = iLen - iNamesize - 1; - - if (!iLen) /* must not end with a null ! */ - MNG_ERROR (pData, MNG_ENDWITHNULL); - } - - iRetcode = mng_create_event (pData, iEventtype, iMasktype, iLeft, iRight, - iTop, iBottom, iObjectid, iIndex, - iNamesize, (mng_pchar)pTemp); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - pTemp = pTemp + iNamesize + 1; - } - } - } -#endif /* MNG_SUPPORT_DISPLAY && MNG_SUPPORT_DYNAMICMNG */ - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - if (iRawlen) /* not empty ? */ - { - mng_uint32 iX; - mng_uint32 iCount = 0; - mng_uint8p pTemp; - mng_uint8p pNull; - mng_uint32 iLen; - mng_uint8 iEventtype; - mng_uint8 iMasktype; - mng_int32 iLeft; - mng_int32 iRight; - mng_int32 iTop; - mng_int32 iBottom; - mng_uint16 iObjectid; - mng_uint8 iIndex; - mng_uint32 iNamesize; - mng_evnt_entryp pEntry = MNG_NULL; - - for (iX = 0; iX < 2; iX++) /* do this twice to get the count first ! */ - { - pTemp = pRawdata; - iLen = iRawlen; - - if (iX) /* second run ? */ - { - MNG_ALLOC (pData, pEntry, (iCount * sizeof (mng_evnt_entry))); - - ((mng_evntp)*ppChunk)->iCount = iCount; - ((mng_evntp)*ppChunk)->pEntries = pEntry; - } - - while (iLen) /* anything left ? */ - { - iEventtype = *pTemp; /* eventtype */ - if (iEventtype > 5) - MNG_ERROR (pData, MNG_INVALIDEVENT); - - pTemp++; - - iMasktype = *pTemp; /* masktype */ - if (iMasktype > 5) - MNG_ERROR (pData, MNG_INVALIDMASK); - - pTemp++; - iLen -= 2; - - iLeft = 0; - iRight = 0; - iTop = 0; - iBottom = 0; - iObjectid = 0; - iIndex = 0; - - switch (iMasktype) - { - case 1 : - { - if (iLen > 16) - { - iLeft = mng_get_int32 (pTemp); - iRight = mng_get_int32 (pTemp+4); - iTop = mng_get_int32 (pTemp+8); - iBottom = mng_get_int32 (pTemp+12); - pTemp += 16; - iLen -= 16; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - case 2 : - { - if (iLen > 2) - { - iObjectid = mng_get_uint16 (pTemp); - pTemp += 2; - iLen -= 2; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - case 3 : - { - if (iLen > 3) - { - iObjectid = mng_get_uint16 (pTemp); - iIndex = *(pTemp+2); - pTemp += 3; - iLen -= 3; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - case 4 : - { - if (iLen > 18) - { - iLeft = mng_get_int32 (pTemp); - iRight = mng_get_int32 (pTemp+4); - iTop = mng_get_int32 (pTemp+8); - iBottom = mng_get_int32 (pTemp+12); - iObjectid = mng_get_uint16 (pTemp+16); - pTemp += 18; - iLen -= 18; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - case 5 : - { - if (iLen > 19) - { - iLeft = mng_get_int32 (pTemp); - iRight = mng_get_int32 (pTemp+4); - iTop = mng_get_int32 (pTemp+8); - iBottom = mng_get_int32 (pTemp+12); - iObjectid = mng_get_uint16 (pTemp+16); - iIndex = *(pTemp+18); - pTemp += 19; - iLen -= 19; - } - else - MNG_ERROR (pData, MNG_INVALIDLENGTH); - break; - } - } - - pNull = find_null (pTemp); /* get the name length */ - - if ((pNull - pTemp) > (mng_int32)iLen) - { - iNamesize = iLen; /* no null found; so end of evNT */ - iLen = 0; - } - else - { - iNamesize = pNull - pTemp; /* should be another entry */ - iLen = iLen - iNamesize - 1; - - if (!iLen) /* must not end with a null ! */ - MNG_ERROR (pData, MNG_ENDWITHNULL); - } - - if (!iX) - { - iCount++; - } - else - { - pEntry->iEventtype = iEventtype; - pEntry->iMasktype = iMasktype; - pEntry->iLeft = iLeft; - pEntry->iRight = iRight; - pEntry->iTop = iTop; - pEntry->iBottom = iBottom; - pEntry->iObjectid = iObjectid; - pEntry->iIndex = iIndex; - pEntry->iSegmentnamesize = iNamesize; - - if (iNamesize) - { - MNG_ALLOC (pData, pEntry->zSegmentname, iNamesize+1); - MNG_COPY (pEntry->zSegmentname, pTemp, iNamesize); - } - - pEntry++; - } - - pTemp = pTemp + iNamesize + 1; - } - } - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_EVNT, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -READ_CHUNK (mng_read_unknown) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_UNKNOWN, MNG_LC_START); -#endif - /* sequence checks */ -#ifdef MNG_INCLUDE_JNG - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && - (!pData->bHasBASI) && (!pData->bHasDHDR) ) -#endif - MNG_ERROR (pData, MNG_SEQUENCEERROR); - /* critical chunk ? */ - if ((((mng_uint32)pData->iChunkname & 0x20000000) == 0) -#ifdef MNG_SKIPCHUNK_SAVE - && (pData->iChunkname != MNG_UINT_SAVE) -#endif -#ifdef MNG_SKIPCHUNK_SEEK - && (pData->iChunkname != MNG_UINT_SEEK) -#endif -#ifdef MNG_SKIPCHUNK_DBYK - && (pData->iChunkname != MNG_UINT_DBYK) -#endif -#ifdef MNG_SKIPCHUNK_ORDR - && (pData->iChunkname != MNG_UINT_ORDR) -#endif - ) - MNG_ERROR (pData, MNG_UNKNOWNCRITICAL); - - if (pData->fProcessunknown) /* let the app handle it ? */ - { - mng_bool bOke = pData->fProcessunknown ((mng_handle)pData, pData->iChunkname, - iRawlen, (mng_ptr)pRawdata); - - if (!bOke) - MNG_ERROR (pData, MNG_APPMISCERROR); - } - -#ifdef MNG_STORE_CHUNKS - if (pData->bStorechunks) - { /* initialize storage */ - mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* store the length */ - ((mng_chunk_headerp)*ppChunk)->iChunkname = pData->iChunkname; - ((mng_unknown_chunkp)*ppChunk)->iDatasize = iRawlen; - - if (iRawlen == 0) /* any data at all ? */ - ((mng_unknown_chunkp)*ppChunk)->pData = 0; - else - { /* then store it */ - MNG_ALLOC (pData, ((mng_unknown_chunkp)*ppChunk)->pData, iRawlen); - MNG_COPY (((mng_unknown_chunkp)*ppChunk)->pData, pRawdata, iRawlen); - } - } -#endif /* MNG_STORE_CHUNKS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_UNKNOWN, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} -#endif - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_READ_PROCS */ - -/* ************************************************************************** */ -/* * * */ -/* * chunk write functions * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_WRITE_PROCS - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_ihdr) -{ - mng_ihdrp pIHDR; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_IHDR, MNG_LC_START); -#endif - - pIHDR = (mng_ihdrp)pChunk; /* address the proper chunk */ - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 13; - /* fill the output buffer */ - mng_put_uint32 (pRawdata, pIHDR->iWidth); - mng_put_uint32 (pRawdata+4, pIHDR->iHeight); - - *(pRawdata+8) = pIHDR->iBitdepth; - *(pRawdata+9) = pIHDR->iColortype; - *(pRawdata+10) = pIHDR->iCompression; - *(pRawdata+11) = pIHDR->iFilter; - *(pRawdata+12) = pIHDR->iInterlace; - /* and write it */ - iRetcode = write_raw_chunk (pData, pIHDR->sHeader.iChunkname, iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_IHDR, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_plte) -{ - mng_pltep pPLTE; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_uint8p pTemp; - mng_uint32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_PLTE, MNG_LC_START); -#endif - - pPLTE = (mng_pltep)pChunk; /* address the proper chunk */ - - if (pPLTE->bEmpty) /* write empty chunk ? */ - iRetcode = write_raw_chunk (pData, pPLTE->sHeader.iChunkname, 0, 0); - else - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = pPLTE->iEntrycount * 3; - /* fill the output buffer */ - pTemp = pRawdata; - - for (iX = 0; iX < pPLTE->iEntrycount; iX++) - { - *pTemp = pPLTE->aEntries [iX].iRed; - *(pTemp+1) = pPLTE->aEntries [iX].iGreen; - *(pTemp+2) = pPLTE->aEntries [iX].iBlue; - - pTemp += 3; - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pPLTE->sHeader.iChunkname, iRawlen, pRawdata); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_PLTE, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_idat) -{ - mng_idatp pIDAT; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_IDAT, MNG_LC_START); -#endif - - pIDAT = (mng_idatp)pChunk; /* address the proper chunk */ - - if (pIDAT->bEmpty) /* and write it */ - iRetcode = write_raw_chunk (pData, pIDAT->sHeader.iChunkname, 0, 0); - else - iRetcode = write_raw_chunk (pData, pIDAT->sHeader.iChunkname, - pIDAT->iDatasize, pIDAT->pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_IDAT, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_iend) -{ - mng_iendp pIEND; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_IEND, MNG_LC_START); -#endif - - pIEND = (mng_iendp)pChunk; /* address the proper chunk */ - /* and write it */ - iRetcode = write_raw_chunk (pData, pIEND->sHeader.iChunkname, 0, 0); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_IEND, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_trns) -{ - mng_trnsp pTRNS; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_uint8p pTemp; - mng_uint32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_TRNS, MNG_LC_START); -#endif - - pTRNS = (mng_trnsp)pChunk; /* address the proper chunk */ - - if (pTRNS->bEmpty) /* write empty chunk ? */ - iRetcode = write_raw_chunk (pData, pTRNS->sHeader.iChunkname, 0, 0); - else - if (pTRNS->bGlobal) /* write global chunk ? */ - iRetcode = write_raw_chunk (pData, pTRNS->sHeader.iChunkname, - pTRNS->iRawlen, (mng_uint8p)pTRNS->aRawdata); - else - { - pRawdata = pData->pWritebuf+8; /* init output buffer */ - iRawlen = 0; /* and default size */ - - switch (pTRNS->iType) - { - case 0: { - iRawlen = 2; /* fill the size & output buffer */ - mng_put_uint16 (pRawdata, pTRNS->iGray); - - break; - } - case 2: { - iRawlen = 6; /* fill the size & output buffer */ - mng_put_uint16 (pRawdata, pTRNS->iRed); - mng_put_uint16 (pRawdata+2, pTRNS->iGreen); - mng_put_uint16 (pRawdata+4, pTRNS->iBlue); - - break; - } - case 3: { /* init output buffer size */ - iRawlen = pTRNS->iCount; - - pTemp = pRawdata; /* fill the output buffer */ - - for (iX = 0; iX < pTRNS->iCount; iX++) - { - *pTemp = pTRNS->aEntries[iX]; - pTemp++; - } - - break; - } - } - /* write the chunk */ - iRetcode = write_raw_chunk (pData, pTRNS->sHeader.iChunkname, - iRawlen, pRawdata); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_TRNS, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_gama) -{ - mng_gamap pGAMA; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_GAMA, MNG_LC_START); -#endif - - pGAMA = (mng_gamap)pChunk; /* address the proper chunk */ - - if (pGAMA->bEmpty) /* write empty ? */ - iRetcode = write_raw_chunk (pData, pGAMA->sHeader.iChunkname, 0, 0); - else - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 4; - /* fill the buffer */ - mng_put_uint32 (pRawdata, pGAMA->iGamma); - /* and write it */ - iRetcode = write_raw_chunk (pData, pGAMA->sHeader.iChunkname, - iRawlen, pRawdata); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_GAMA, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_cHRM -WRITE_CHUNK (mng_write_chrm) -{ - mng_chrmp pCHRM; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_CHRM, MNG_LC_START); -#endif - - pCHRM = (mng_chrmp)pChunk; /* address the proper chunk */ - - if (pCHRM->bEmpty) /* write empty ? */ - iRetcode = write_raw_chunk (pData, pCHRM->sHeader.iChunkname, 0, 0); - else - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 32; - /* fill the buffer */ - mng_put_uint32 (pRawdata, pCHRM->iWhitepointx); - mng_put_uint32 (pRawdata+4, pCHRM->iWhitepointy); - mng_put_uint32 (pRawdata+8, pCHRM->iRedx); - mng_put_uint32 (pRawdata+12, pCHRM->iRedy); - mng_put_uint32 (pRawdata+16, pCHRM->iGreenx); - mng_put_uint32 (pRawdata+20, pCHRM->iGreeny); - mng_put_uint32 (pRawdata+24, pCHRM->iBluex); - mng_put_uint32 (pRawdata+28, pCHRM->iBluey); - /* and write it */ - iRetcode = write_raw_chunk (pData, pCHRM->sHeader.iChunkname, - iRawlen, pRawdata); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_CHRM, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_srgb) -{ - mng_srgbp pSRGB; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_SRGB, MNG_LC_START); -#endif - - pSRGB = (mng_srgbp)pChunk; /* address the proper chunk */ - - if (pSRGB->bEmpty) /* write empty ? */ - iRetcode = write_raw_chunk (pData, pSRGB->sHeader.iChunkname, 0, 0); - else - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 1; - /* fill the buffer */ - *pRawdata = pSRGB->iRenderingintent; - /* and write it */ - iRetcode = write_raw_chunk (pData, pSRGB->sHeader.iChunkname, - iRawlen, pRawdata); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_SRGB, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iCCP -WRITE_CHUNK (mng_write_iccp) -{ - mng_iccpp pICCP; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_uint8p pTemp; - mng_uint8p pBuf = 0; - mng_uint32 iBuflen; - mng_uint32 iReallen; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_ICCP, MNG_LC_START); -#endif - - pICCP = (mng_iccpp)pChunk; /* address the proper chunk */ - - if (pICCP->bEmpty) /* write empty ? */ - iRetcode = write_raw_chunk (pData, pICCP->sHeader.iChunkname, 0, 0); - else - { /* compress the profile */ - iRetcode = deflate_buffer (pData, pICCP->pProfile, pICCP->iProfilesize, - &pBuf, &iBuflen, &iReallen); - - if (!iRetcode) /* still oke ? */ - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = pICCP->iNamesize + 2 + iReallen; - /* requires large buffer ? */ - if (iRawlen > pData->iWritebufsize) - MNG_ALLOC (pData, pRawdata, iRawlen); - - pTemp = pRawdata; /* fill the buffer */ - - if (pICCP->iNamesize) - { - MNG_COPY (pTemp, pICCP->zName, pICCP->iNamesize); - pTemp += pICCP->iNamesize; - } - - *pTemp = 0; - *(pTemp+1) = pICCP->iCompression; - pTemp += 2; - - if (iReallen) - MNG_COPY (pTemp, pBuf, iReallen); - /* and write it */ - iRetcode = write_raw_chunk (pData, pICCP->sHeader.iChunkname, - iRawlen, pRawdata); - /* drop the temp buffer ? */ - if (iRawlen > pData->iWritebufsize) - MNG_FREEX (pData, pRawdata, iRawlen); - - } - - MNG_FREEX (pData, pBuf, iBuflen); /* always drop the extra buffer */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_ICCP, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_tEXt -WRITE_CHUNK (mng_write_text) -{ - mng_textp pTEXT; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_uint8p pTemp; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_TEXT, MNG_LC_START); -#endif - - pTEXT = (mng_textp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = pTEXT->iKeywordsize + 1 + pTEXT->iTextsize; - /* requires large buffer ? */ - if (iRawlen > pData->iWritebufsize) - MNG_ALLOC (pData, pRawdata, iRawlen); - - pTemp = pRawdata; /* fill the buffer */ - - if (pTEXT->iKeywordsize) - { - MNG_COPY (pTemp, pTEXT->zKeyword, pTEXT->iKeywordsize); - pTemp += pTEXT->iKeywordsize; - } - - *pTemp = 0; - pTemp += 1; - - if (pTEXT->iTextsize) - MNG_COPY (pTemp, pTEXT->zText, pTEXT->iTextsize); - /* and write it */ - iRetcode = write_raw_chunk (pData, pTEXT->sHeader.iChunkname, - iRawlen, pRawdata); - - if (iRawlen > pData->iWritebufsize) /* drop the temp buffer ? */ - MNG_FREEX (pData, pRawdata, iRawlen); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_TEXT, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_zTXt -WRITE_CHUNK (mng_write_ztxt) -{ - mng_ztxtp pZTXT; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_uint8p pTemp; - mng_uint8p pBuf = 0; - mng_uint32 iBuflen; - mng_uint32 iReallen; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_ZTXT, MNG_LC_START); -#endif - - pZTXT = (mng_ztxtp)pChunk; /* address the proper chunk */ - /* compress the text */ - iRetcode = deflate_buffer (pData, (mng_uint8p)pZTXT->zText, pZTXT->iTextsize, - &pBuf, &iBuflen, &iReallen); - - if (!iRetcode) /* all ok ? */ - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = pZTXT->iKeywordsize + 2 + iReallen; - /* requires large buffer ? */ - if (iRawlen > pData->iWritebufsize) - MNG_ALLOC (pData, pRawdata, iRawlen); - - pTemp = pRawdata; /* fill the buffer */ - - if (pZTXT->iKeywordsize) - { - MNG_COPY (pTemp, pZTXT->zKeyword, pZTXT->iKeywordsize); - pTemp += pZTXT->iKeywordsize; - } - - *pTemp = 0; /* terminator zero */ - pTemp++; - *pTemp = 0; /* compression type */ - pTemp++; - - if (iReallen) - MNG_COPY (pTemp, pBuf, iReallen); - /* and write it */ - iRetcode = write_raw_chunk (pData, pZTXT->sHeader.iChunkname, - iRawlen, pRawdata); - /* drop the temp buffer ? */ - if (iRawlen > pData->iWritebufsize) - MNG_FREEX (pData, pRawdata, iRawlen); - - } - - MNG_FREEX (pData, pBuf, iBuflen); /* always drop the compression buffer */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_ZTXT, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iTXt -WRITE_CHUNK (mng_write_itxt) -{ - mng_itxtp pITXT; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_uint8p pTemp; - mng_uint8p pBuf = 0; - mng_uint32 iBuflen; - mng_uint32 iReallen; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_ITXT, MNG_LC_START); -#endif - - pITXT = (mng_itxtp)pChunk; /* address the proper chunk */ - - if (pITXT->iCompressionflag) /* compress the text */ - iRetcode = deflate_buffer (pData, (mng_uint8p)pITXT->zText, pITXT->iTextsize, - &pBuf, &iBuflen, &iReallen); - else - iRetcode = MNG_NOERROR; - - if (!iRetcode) /* all ok ? */ - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = pITXT->iKeywordsize + pITXT->iLanguagesize + - pITXT->iTranslationsize + 5; - - if (pITXT->iCompressionflag) - iRawlen = iRawlen + iReallen; - else - iRawlen = iRawlen + pITXT->iTextsize; - /* requires large buffer ? */ - if (iRawlen > pData->iWritebufsize) - MNG_ALLOC (pData, pRawdata, iRawlen); - - pTemp = pRawdata; /* fill the buffer */ - - if (pITXT->iKeywordsize) - { - MNG_COPY (pTemp, pITXT->zKeyword, pITXT->iKeywordsize); - pTemp += pITXT->iKeywordsize; - } - - *pTemp = 0; - pTemp++; - *pTemp = pITXT->iCompressionflag; - pTemp++; - *pTemp = pITXT->iCompressionmethod; - pTemp++; - - if (pITXT->iLanguagesize) - { - MNG_COPY (pTemp, pITXT->zLanguage, pITXT->iLanguagesize); - pTemp += pITXT->iLanguagesize; - } - - *pTemp = 0; - pTemp++; - - if (pITXT->iTranslationsize) - { - MNG_COPY (pTemp, pITXT->zTranslation, pITXT->iTranslationsize); - pTemp += pITXT->iTranslationsize; - } - - *pTemp = 0; - pTemp++; - - if (pITXT->iCompressionflag) - { - if (iReallen) - MNG_COPY (pTemp, pBuf, iReallen); - } - else - { - if (pITXT->iTextsize) - MNG_COPY (pTemp, pITXT->zText, pITXT->iTextsize); - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pITXT->sHeader.iChunkname, - iRawlen, pRawdata); - /* drop the temp buffer ? */ - if (iRawlen > pData->iWritebufsize) - MNG_FREEX (pData, pRawdata, iRawlen); - - } - - MNG_FREEX (pData, pBuf, iBuflen); /* always drop the compression buffer */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_ITXT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_bKGD -WRITE_CHUNK (mng_write_bkgd) -{ - mng_bkgdp pBKGD; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_BKGD, MNG_LC_START); -#endif - - pBKGD = (mng_bkgdp)pChunk; /* address the proper chunk */ - - if (pBKGD->bEmpty) /* write empty ? */ - iRetcode = write_raw_chunk (pData, pBKGD->sHeader.iChunkname, 0, 0); - else - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 0; /* and default size */ - - switch (pBKGD->iType) - { - case 0: { /* gray */ - iRawlen = 2; /* fill the size & output buffer */ - mng_put_uint16 (pRawdata, pBKGD->iGray); - - break; - } - case 2: { /* rgb */ - iRawlen = 6; /* fill the size & output buffer */ - mng_put_uint16 (pRawdata, pBKGD->iRed); - mng_put_uint16 (pRawdata+2, pBKGD->iGreen); - mng_put_uint16 (pRawdata+4, pBKGD->iBlue); - - break; - } - case 3: { /* indexed */ - iRawlen = 1; /* fill the size & output buffer */ - *pRawdata = pBKGD->iIndex; - - break; - } - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pBKGD->sHeader.iChunkname, - iRawlen, pRawdata); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_BKGD, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_pHYs -WRITE_CHUNK (mng_write_phys) -{ - mng_physp pPHYS; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_PHYS, MNG_LC_START); -#endif - - pPHYS = (mng_physp)pChunk; /* address the proper chunk */ - - if (pPHYS->bEmpty) /* write empty ? */ - iRetcode = write_raw_chunk (pData, pPHYS->sHeader.iChunkname, 0, 0); - else - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 9; - /* fill the output buffer */ - mng_put_uint32 (pRawdata, pPHYS->iSizex); - mng_put_uint32 (pRawdata+4, pPHYS->iSizey); - - *(pRawdata+8) = pPHYS->iUnit; - /* and write it */ - iRetcode = write_raw_chunk (pData, pPHYS->sHeader.iChunkname, - iRawlen, pRawdata); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_PHYS, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sBIT -WRITE_CHUNK (mng_write_sbit) -{ - mng_sbitp pSBIT; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_SBIT, MNG_LC_START); -#endif - - pSBIT = (mng_sbitp)pChunk; /* address the proper chunk */ - - if (pSBIT->bEmpty) /* write empty ? */ - iRetcode = write_raw_chunk (pData, pSBIT->sHeader.iChunkname, 0, 0); - else - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 0; /* and default size */ - - switch (pSBIT->iType) - { - case 0: { /* gray */ - iRawlen = 1; /* fill the size & output buffer */ - *pRawdata = pSBIT->aBits[0]; - - break; - } - case 2: { /* rgb */ - iRawlen = 3; /* fill the size & output buffer */ - *pRawdata = pSBIT->aBits[0]; - *(pRawdata+1) = pSBIT->aBits[1]; - *(pRawdata+2) = pSBIT->aBits[2]; - - break; - } - case 3: { /* indexed */ - iRawlen = 3; /* fill the size & output buffer */ - *pRawdata = pSBIT->aBits[0]; - *pRawdata = pSBIT->aBits[1]; - *pRawdata = pSBIT->aBits[2]; - - break; - } - case 4: { /* gray + alpha */ - iRawlen = 2; /* fill the size & output buffer */ - *pRawdata = pSBIT->aBits[0]; - *(pRawdata+1) = pSBIT->aBits[1]; - - break; - } - case 6: { /* rgb + alpha */ - iRawlen = 4; /* fill the size & output buffer */ - *pRawdata = pSBIT->aBits[0]; - *(pRawdata+1) = pSBIT->aBits[1]; - *(pRawdata+2) = pSBIT->aBits[2]; - *(pRawdata+3) = pSBIT->aBits[3]; - - break; - } - case 10: { /* jpeg gray */ - iRawlen = 1; /* fill the size & output buffer */ - *pRawdata = pSBIT->aBits[0]; - - break; - } - case 12: { /* jpeg rgb */ - iRawlen = 3; /* fill the size & output buffer */ - *pRawdata = pSBIT->aBits[0]; - *(pRawdata+1) = pSBIT->aBits[1]; - *(pRawdata+2) = pSBIT->aBits[2]; - - break; - } - case 14: { /* jpeg gray + alpha */ - iRawlen = 2; /* fill the size & output buffer */ - *pRawdata = pSBIT->aBits[0]; - *(pRawdata+1) = pSBIT->aBits[1]; - - break; - } - case 16: { /* jpeg rgb + alpha */ - iRawlen = 4; /* fill the size & output buffer */ - *pRawdata = pSBIT->aBits[0]; - *(pRawdata+1) = pSBIT->aBits[1]; - *(pRawdata+2) = pSBIT->aBits[2]; - *(pRawdata+3) = pSBIT->aBits[3]; - - break; - } - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pSBIT->sHeader.iChunkname, - iRawlen, pRawdata); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_SBIT, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sPLT -WRITE_CHUNK (mng_write_splt) -{ - mng_spltp pSPLT; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_uint32 iEntrieslen; - mng_uint8p pTemp; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_SPLT, MNG_LC_START); -#endif - - pSPLT = (mng_spltp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iEntrieslen = ((pSPLT->iSampledepth >> 3) * 4 + 2) * pSPLT->iEntrycount; - iRawlen = pSPLT->iNamesize + 2 + iEntrieslen; - /* requires large buffer ? */ - if (iRawlen > pData->iWritebufsize) - MNG_ALLOC (pData, pRawdata, iRawlen); - - pTemp = pRawdata; /* fill the buffer */ - - if (pSPLT->iNamesize) - { - MNG_COPY (pTemp, pSPLT->zName, pSPLT->iNamesize); - pTemp += pSPLT->iNamesize; - } - - *pTemp = 0; - *(pTemp+1) = pSPLT->iSampledepth; - pTemp += 2; - - if (pSPLT->iEntrycount) - MNG_COPY (pTemp, pSPLT->pEntries, iEntrieslen); - /* and write it */ - iRetcode = write_raw_chunk (pData, pSPLT->sHeader.iChunkname, - iRawlen, pRawdata); - - if (iRawlen > pData->iWritebufsize) /* drop the temp buffer ? */ - MNG_FREEX (pData, pRawdata, iRawlen); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_SPLT, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_hIST -WRITE_CHUNK (mng_write_hist) -{ - mng_histp pHIST; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_uint8p pTemp; - mng_uint32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_HIST, MNG_LC_START); -#endif - - pHIST = (mng_histp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = pHIST->iEntrycount << 1; - - pTemp = pRawdata; /* fill the output buffer */ - - for (iX = 0; iX < pHIST->iEntrycount; iX++) - { - mng_put_uint16 (pTemp, pHIST->aEntries [iX]); - pTemp += 2; - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pHIST->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_HIST, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_tIME -WRITE_CHUNK (mng_write_time) -{ - mng_timep pTIME; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_TIME, MNG_LC_START); -#endif - - pTIME = (mng_timep)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 7; - /* fill the output buffer */ - mng_put_uint16 (pRawdata, pTIME->iYear); - - *(pRawdata+2) = pTIME->iMonth; - *(pRawdata+3) = pTIME->iDay; - *(pRawdata+4) = pTIME->iHour; - *(pRawdata+5) = pTIME->iMinute; - *(pRawdata+6) = pTIME->iSecond; - /* and write it */ - iRetcode = write_raw_chunk (pData, pTIME->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_TIME, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_mhdr) -{ - mng_mhdrp pMHDR; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_MHDR, MNG_LC_START); -#endif - - pMHDR = (mng_mhdrp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 28; - /* fill the output buffer */ - mng_put_uint32 (pRawdata, pMHDR->iWidth); - mng_put_uint32 (pRawdata+4, pMHDR->iHeight); - mng_put_uint32 (pRawdata+8, pMHDR->iTicks); - mng_put_uint32 (pRawdata+12, pMHDR->iLayercount); - mng_put_uint32 (pRawdata+16, pMHDR->iFramecount); - mng_put_uint32 (pRawdata+20, pMHDR->iPlaytime); - mng_put_uint32 (pRawdata+24, pMHDR->iSimplicity); - - /* and write it */ - iRetcode = write_raw_chunk (pData, pMHDR->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_MHDR, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_mend) -{ - mng_mendp pMEND; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_MEND, MNG_LC_START); -#endif - - pMEND = (mng_mendp)pChunk; /* address the proper chunk */ - /* and write it */ - iRetcode = write_raw_chunk (pData, pMEND->sHeader.iChunkname, 0, 0); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_MEND, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_loop) -{ - mng_loopp pLOOP; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; -#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED - mng_uint8p pTemp1; - mng_uint32p pTemp2; - mng_uint32 iX; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_LOOP, MNG_LC_START); -#endif - - pLOOP = (mng_loopp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 5; - /* fill the output buffer */ - *pRawdata = pLOOP->iLevel; - mng_put_uint32 (pRawdata+1, pLOOP->iRepeat); - - if (pLOOP->iTermination) - { - iRawlen++; - *(pRawdata+5) = pLOOP->iTermination; - - if ((pLOOP->iCount) || - (pLOOP->iItermin != 1) || (pLOOP->iItermax != 0x7FFFFFFFL)) - { - iRawlen += 8; - - mng_put_uint32 (pRawdata+6, pLOOP->iItermin); - mng_put_uint32 (pRawdata+10, pLOOP->iItermax); - -#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED - if (pLOOP->iCount) - { - iRawlen += pLOOP->iCount * 4; - - pTemp1 = pRawdata+14; - pTemp2 = pLOOP->pSignals; - - for (iX = 0; iX < pLOOP->iCount; iX++) - { - mng_put_uint32 (pTemp1, *pTemp2); - - pTemp1 += 4; - pTemp2++; - } - } -#endif - } - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pLOOP->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_LOOP, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_endl) -{ - mng_endlp pENDL; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_ENDL, MNG_LC_START); -#endif - - pENDL = (mng_endlp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 1; - - *pRawdata = pENDL->iLevel; /* fill the output buffer */ - /* and write it */ - iRetcode = write_raw_chunk (pData, pENDL->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_ENDL, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_defi) -{ - mng_defip pDEFI; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_DEFI, MNG_LC_START); -#endif - - pDEFI = (mng_defip)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 2; - /* fill the output buffer */ - mng_put_uint16 (pRawdata, pDEFI->iObjectid); - - if ((pDEFI->iDonotshow) || (pDEFI->iConcrete) || (pDEFI->bHasloca) || (pDEFI->bHasclip)) - { - iRawlen++; - *(pRawdata+2) = pDEFI->iDonotshow; - - if ((pDEFI->iConcrete) || (pDEFI->bHasloca) || (pDEFI->bHasclip)) - { - iRawlen++; - *(pRawdata+3) = pDEFI->iConcrete; - - if ((pDEFI->bHasloca) || (pDEFI->bHasclip)) - { - iRawlen += 8; - - mng_put_uint32 (pRawdata+4, pDEFI->iXlocation); - mng_put_uint32 (pRawdata+8, pDEFI->iYlocation); - - if (pDEFI->bHasclip) - { - iRawlen += 16; - - mng_put_uint32 (pRawdata+12, pDEFI->iLeftcb); - mng_put_uint32 (pRawdata+16, pDEFI->iRightcb); - mng_put_uint32 (pRawdata+20, pDEFI->iTopcb); - mng_put_uint32 (pRawdata+24, pDEFI->iBottomcb); - } - } - } - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pDEFI->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_DEFI, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_basi) -{ - mng_basip pBASI; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_bool bOpaque; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_BASI, MNG_LC_START); -#endif - - pBASI = (mng_basip)pChunk; /* address the proper chunk */ - -#ifndef MNG_NO_16BIT_SUPPORT - if (pBASI->iBitdepth <= 8) /* determine opacity alpha-field */ -#endif - bOpaque = (mng_bool)(pBASI->iAlpha == 0xFF); -#ifndef MNG_NO_16BIT_SUPPORT - else - bOpaque = (mng_bool)(pBASI->iAlpha == 0xFFFF); -#endif - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 13; - /* fill the output buffer */ - mng_put_uint32 (pRawdata, pBASI->iWidth); - mng_put_uint32 (pRawdata+4, pBASI->iHeight); - - *(pRawdata+8) = pBASI->iBitdepth; - *(pRawdata+9) = pBASI->iColortype; - *(pRawdata+10) = pBASI->iCompression; - *(pRawdata+11) = pBASI->iFilter; - *(pRawdata+12) = pBASI->iInterlace; - - if ((pBASI->iRed) || (pBASI->iGreen) || (pBASI->iBlue) || - (!bOpaque) || (pBASI->iViewable)) - { - iRawlen += 6; - mng_put_uint16 (pRawdata+13, pBASI->iRed); - mng_put_uint16 (pRawdata+15, pBASI->iGreen); - mng_put_uint16 (pRawdata+17, pBASI->iBlue); - - if ((!bOpaque) || (pBASI->iViewable)) - { - iRawlen += 2; - mng_put_uint16 (pRawdata+19, pBASI->iAlpha); - - if (pBASI->iViewable) - { - iRawlen++; - *(pRawdata+21) = pBASI->iViewable; - } - } - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pBASI->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_BASI, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_clon) -{ - mng_clonp pCLON; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_CLON, MNG_LC_START); -#endif - - pCLON = (mng_clonp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 4; - /* fill the output buffer */ - mng_put_uint16 (pRawdata, pCLON->iSourceid); - mng_put_uint16 (pRawdata+2, pCLON->iCloneid); - - if ((pCLON->iClonetype) || (pCLON->iDonotshow) || (pCLON->iConcrete) || (pCLON->bHasloca)) - { - iRawlen++; - *(pRawdata+4) = pCLON->iClonetype; - - if ((pCLON->iDonotshow) || (pCLON->iConcrete) || (pCLON->bHasloca)) - { - iRawlen++; - *(pRawdata+5) = pCLON->iDonotshow; - - if ((pCLON->iConcrete) || (pCLON->bHasloca)) - { - iRawlen++; - *(pRawdata+6) = pCLON->iConcrete; - - if (pCLON->bHasloca) - { - iRawlen += 9; - *(pRawdata+7) = pCLON->iLocationtype; - mng_put_int32 (pRawdata+8, pCLON->iLocationx); - mng_put_int32 (pRawdata+12, pCLON->iLocationy); - } - } - } - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pCLON->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_CLON, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -WRITE_CHUNK (mng_write_past) -{ - mng_pastp pPAST; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_past_sourcep pSource; - mng_uint32 iX; - mng_uint8p pTemp; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_PAST, MNG_LC_START); -#endif - - pPAST = (mng_pastp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 11 + (30 * pPAST->iCount); - /* requires large buffer ? */ - if (iRawlen > pData->iWritebufsize) - MNG_ALLOC (pData, pRawdata, iRawlen); - /* fill the output buffer */ - mng_put_uint16 (pRawdata, pPAST->iDestid); - - *(pRawdata+2) = pPAST->iTargettype; - - mng_put_int32 (pRawdata+3, pPAST->iTargetx); - mng_put_int32 (pRawdata+7, pPAST->iTargety); - - pTemp = pRawdata+11; - pSource = pPAST->pSources; - - for (iX = 0; iX < pPAST->iCount; iX++) - { - mng_put_uint16 (pTemp, pSource->iSourceid); - - *(pTemp+2) = pSource->iComposition; - *(pTemp+3) = pSource->iOrientation; - *(pTemp+4) = pSource->iOffsettype; - - mng_put_int32 (pTemp+5, pSource->iOffsetx); - mng_put_int32 (pTemp+9, pSource->iOffsety); - - *(pTemp+13) = pSource->iBoundarytype; - - mng_put_int32 (pTemp+14, pSource->iBoundaryl); - mng_put_int32 (pTemp+18, pSource->iBoundaryr); - mng_put_int32 (pTemp+22, pSource->iBoundaryt); - mng_put_int32 (pTemp+26, pSource->iBoundaryb); - - pSource++; - pTemp += 30; - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pPAST->sHeader.iChunkname, - iRawlen, pRawdata); - /* free temporary buffer ? */ - if (iRawlen > pData->iWritebufsize) - MNG_FREEX (pData, pRawdata, iRawlen); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_PAST, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_disc) -{ - mng_discp pDISC; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_uint32 iX; - mng_uint8p pTemp1; - mng_uint16p pTemp2; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_DISC, MNG_LC_START); -#endif - - pDISC = (mng_discp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = pDISC->iCount << 1; - - pTemp1 = pRawdata; /* fill the output buffer */ - pTemp2 = pDISC->pObjectids; - - for (iX = 0; iX < pDISC->iCount; iX++) - { - mng_put_uint16 (pTemp1, *pTemp2); - - pTemp2++; - pTemp1 += 2; - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pDISC->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_DISC, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_back) -{ - mng_backp pBACK; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_BACK, MNG_LC_START); -#endif - - pBACK = (mng_backp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 6; - /* fill the output buffer */ - mng_put_uint16 (pRawdata, pBACK->iRed); - mng_put_uint16 (pRawdata+2, pBACK->iGreen); - mng_put_uint16 (pRawdata+4, pBACK->iBlue); - - if ((pBACK->iMandatory) || (pBACK->iImageid) || (pBACK->iTile)) - { - iRawlen++; - *(pRawdata+6) = pBACK->iMandatory; - - if ((pBACK->iImageid) || (pBACK->iTile)) - { - iRawlen += 2; - mng_put_uint16 (pRawdata+7, pBACK->iImageid); - - if (pBACK->iTile) - { - iRawlen++; - *(pRawdata+9) = pBACK->iTile; - } - } - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pBACK->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_BACK, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_fram) -{ - mng_framp pFRAM; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_uint8p pTemp; - mng_uint32p pTemp2; - mng_uint32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_FRAM, MNG_LC_START); -#endif - - pFRAM = (mng_framp)pChunk; /* address the proper chunk */ - - if (pFRAM->bEmpty) /* empty ? */ - iRetcode = write_raw_chunk (pData, pFRAM->sHeader.iChunkname, 0, 0); - else - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 1; - /* fill the output buffer */ - *pRawdata = pFRAM->iMode; - - if ((pFRAM->iNamesize ) || - (pFRAM->iChangedelay ) || (pFRAM->iChangetimeout) || - (pFRAM->iChangeclipping) || (pFRAM->iChangesyncid ) ) - { - if (pFRAM->iNamesize) - MNG_COPY (pRawdata+1, pFRAM->zName, pFRAM->iNamesize); - - iRawlen += pFRAM->iNamesize; - pTemp = pRawdata + pFRAM->iNamesize + 1; - - if ((pFRAM->iChangedelay ) || (pFRAM->iChangetimeout) || - (pFRAM->iChangeclipping) || (pFRAM->iChangesyncid ) ) - { - *pTemp = 0; - *(pTemp+1) = pFRAM->iChangedelay; - *(pTemp+2) = pFRAM->iChangetimeout; - *(pTemp+3) = pFRAM->iChangeclipping; - *(pTemp+4) = pFRAM->iChangesyncid; - - iRawlen += 5; - pTemp += 5; - - if (pFRAM->iChangedelay) - { - mng_put_uint32 (pTemp, pFRAM->iDelay); - iRawlen += 4; - pTemp += 4; - } - - if (pFRAM->iChangetimeout) - { - mng_put_uint32 (pTemp, pFRAM->iTimeout); - iRawlen += 4; - pTemp += 4; - } - - if (pFRAM->iChangeclipping) - { - *pTemp = pFRAM->iBoundarytype; - - mng_put_uint32 (pTemp+1, pFRAM->iBoundaryl); - mng_put_uint32 (pTemp+5, pFRAM->iBoundaryr); - mng_put_uint32 (pTemp+9, pFRAM->iBoundaryt); - mng_put_uint32 (pTemp+13, pFRAM->iBoundaryb); - - iRawlen += 17; - pTemp += 17; - } - - if (pFRAM->iChangesyncid) - { - iRawlen += pFRAM->iCount * 4; - pTemp2 = pFRAM->pSyncids; - - for (iX = 0; iX < pFRAM->iCount; iX++) - { - mng_put_uint32 (pTemp, *pTemp2); - - pTemp2++; - pTemp += 4; - } - } - } - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pFRAM->sHeader.iChunkname, - iRawlen, pRawdata); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_FRAM, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_move) -{ - mng_movep pMOVE; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_MOVE, MNG_LC_START); -#endif - - pMOVE = (mng_movep)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 13; - /* fill the output buffer */ - mng_put_uint16 (pRawdata, pMOVE->iFirstid); - mng_put_uint16 (pRawdata+2, pMOVE->iLastid); - - *(pRawdata+4) = pMOVE->iMovetype; - - mng_put_int32 (pRawdata+5, pMOVE->iMovex); - mng_put_int32 (pRawdata+9, pMOVE->iMovey); - /* and write it */ - iRetcode = write_raw_chunk (pData, pMOVE->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_MOVE, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_clip) -{ - mng_clipp pCLIP; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_CLIP, MNG_LC_START); -#endif - - pCLIP = (mng_clipp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 21; - /* fill the output buffer */ - mng_put_uint16 (pRawdata, pCLIP->iFirstid); - mng_put_uint16 (pRawdata+2, pCLIP->iLastid); - - *(pRawdata+4) = pCLIP->iCliptype; - - mng_put_int32 (pRawdata+5, pCLIP->iClipl); - mng_put_int32 (pRawdata+9, pCLIP->iClipr); - mng_put_int32 (pRawdata+13, pCLIP->iClipt); - mng_put_int32 (pRawdata+17, pCLIP->iClipb); - /* and write it */ - iRetcode = write_raw_chunk (pData, pCLIP->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_CLIP, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_show) -{ - mng_showp pSHOW; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_SHOW, MNG_LC_START); -#endif - - pSHOW = (mng_showp)pChunk; /* address the proper chunk */ - - if (pSHOW->bEmpty) /* empty ? */ - iRetcode = write_raw_chunk (pData, pSHOW->sHeader.iChunkname, 0, 0); - else - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 2; - /* fill the output buffer */ - mng_put_uint16 (pRawdata, pSHOW->iFirstid); - - if ((pSHOW->iLastid != pSHOW->iFirstid) || (pSHOW->iMode)) - { - iRawlen += 2; - mng_put_uint16 (pRawdata+2, pSHOW->iLastid); - - if (pSHOW->iMode) - { - iRawlen++; - *(pRawdata+4) = pSHOW->iMode; - } - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pSHOW->sHeader.iChunkname, - iRawlen, pRawdata); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_SHOW, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_term) -{ - mng_termp pTERM; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_TERM, MNG_LC_START); -#endif - - pTERM = (mng_termp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 1; - - *pRawdata = pTERM->iTermaction; /* fill the output buffer */ - - if (pTERM->iTermaction == 3) - { - iRawlen = 10; - *(pRawdata+1) = pTERM->iIteraction; - - mng_put_uint32 (pRawdata+2, pTERM->iDelay); - mng_put_uint32 (pRawdata+6, pTERM->iItermax); - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pTERM->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_TERM, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SAVE -WRITE_CHUNK (mng_write_save) -{ - mng_savep pSAVE; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_save_entryp pEntry; - mng_uint32 iEntrysize; - mng_uint8p pTemp; - mng_uint32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_SAVE, MNG_LC_START); -#endif - - pSAVE = (mng_savep)pChunk; /* address the proper chunk */ - - if (pSAVE->bEmpty) /* empty ? */ - iRetcode = write_raw_chunk (pData, pSAVE->sHeader.iChunkname, 0, 0); - else - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 1; - - *pRawdata = pSAVE->iOffsettype; /* fill the output buffer */ - - if (pSAVE->iOffsettype == 16) - iEntrysize = 25; - else - iEntrysize = 17; - - pTemp = pRawdata+1; - pEntry = pSAVE->pEntries; - - for (iX = 0; iX < pSAVE->iCount; iX++) - { - if (iX) /* put separator null-byte, except the first */ - { - *pTemp = 0; - pTemp++; - iRawlen++; - } - - iRawlen += iEntrysize + pEntry->iNamesize; - *pTemp = pEntry->iEntrytype; - - if (pSAVE->iOffsettype == 16) - { - mng_put_uint32 (pTemp+1, pEntry->iOffset[0]); - mng_put_uint32 (pTemp+5, pEntry->iOffset[1]); - mng_put_uint32 (pTemp+9, pEntry->iStarttime[0]); - mng_put_uint32 (pTemp+13, pEntry->iStarttime[1]); - mng_put_uint32 (pTemp+17, pEntry->iLayernr); - mng_put_uint32 (pTemp+21, pEntry->iFramenr); - - pTemp += 25; - } - else - { - mng_put_uint32 (pTemp+1, pEntry->iOffset[1]); - mng_put_uint32 (pTemp+5, pEntry->iStarttime[1]); - mng_put_uint32 (pTemp+9, pEntry->iLayernr); - mng_put_uint32 (pTemp+13, pEntry->iFramenr); - - pTemp += 17; - } - - if (pEntry->iNamesize) - { - MNG_COPY (pTemp, pEntry->zName, pEntry->iNamesize); - pTemp += pEntry->iNamesize; - } - - pEntry++; - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pSAVE->sHeader.iChunkname, - iRawlen, pRawdata); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_SAVE, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SEEK -WRITE_CHUNK (mng_write_seek) -{ - mng_seekp pSEEK; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_SEEK, MNG_LC_START); -#endif - - pSEEK = (mng_seekp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = pSEEK->iNamesize; - - if (iRawlen) /* fill the output buffer */ - MNG_COPY (pRawdata, pSEEK->zName, iRawlen); - /* and write it */ - iRetcode = write_raw_chunk (pData, pSEEK->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_SEEK, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_eXPI -WRITE_CHUNK (mng_write_expi) -{ - mng_expip pEXPI; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_EXPI, MNG_LC_START); -#endif - - pEXPI = (mng_expip)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 2 + pEXPI->iNamesize; - /* fill the output buffer */ - mng_put_uint16 (pRawdata, pEXPI->iSnapshotid); - - if (pEXPI->iNamesize) - MNG_COPY (pRawdata+2, pEXPI->zName, pEXPI->iNamesize); - /* and write it */ - iRetcode = write_raw_chunk (pData, pEXPI->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_EXPI, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_fPRI -WRITE_CHUNK (mng_write_fpri) -{ - mng_fprip pFPRI; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_FPRI, MNG_LC_START); -#endif - - pFPRI = (mng_fprip)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 2; - - *pRawdata = pFPRI->iDeltatype; /* fill the output buffer */ - *(pRawdata+1) = pFPRI->iPriority; - /* and write it */ - iRetcode = write_raw_chunk (pData, pFPRI->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_FPRI, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_nEED -WRITE_CHUNK (mng_write_need) -{ - mng_needp pNEED; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_NEED, MNG_LC_START); -#endif - - pNEED = (mng_needp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = pNEED->iKeywordssize; - /* fill the output buffer */ - if (pNEED->iKeywordssize) - MNG_COPY (pRawdata, pNEED->zKeywords, pNEED->iKeywordssize); - /* and write it */ - iRetcode = write_raw_chunk (pData, pNEED->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_NEED, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_pHYg -WRITE_CHUNK (mng_write_phyg) -{ - mng_phygp pPHYG; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_PHYG, MNG_LC_START); -#endif - - pPHYG = (mng_phygp)pChunk; /* address the proper chunk */ - - if (pPHYG->bEmpty) /* write empty ? */ - iRetcode = write_raw_chunk (pData, pPHYG->sHeader.iChunkname, 0, 0); - else - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 9; - /* fill the output buffer */ - mng_put_uint32 (pRawdata, pPHYG->iSizex); - mng_put_uint32 (pRawdata+4, pPHYG->iSizey); - - *(pRawdata+8) = pPHYG->iUnit; - /* and write it */ - iRetcode = write_raw_chunk (pData, pPHYG->sHeader.iChunkname, - iRawlen, pRawdata); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_PHYG, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -/* B004 */ -#ifdef MNG_INCLUDE_JNG -/* B004 */ -WRITE_CHUNK (mng_write_jhdr) -{ - mng_jhdrp pJHDR; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_JHDR, MNG_LC_START); -#endif - - pJHDR = (mng_jhdrp)pChunk; /* address the proper chunk */ - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 16; - /* fill the output buffer */ - mng_put_uint32 (pRawdata, pJHDR->iWidth); - mng_put_uint32 (pRawdata+4, pJHDR->iHeight); - - *(pRawdata+8) = pJHDR->iColortype; - *(pRawdata+9) = pJHDR->iImagesampledepth; - *(pRawdata+10) = pJHDR->iImagecompression; - *(pRawdata+11) = pJHDR->iImageinterlace; - *(pRawdata+12) = pJHDR->iAlphasampledepth; - *(pRawdata+13) = pJHDR->iAlphacompression; - *(pRawdata+14) = pJHDR->iAlphafilter; - *(pRawdata+15) = pJHDR->iAlphainterlace; - /* and write it */ - iRetcode = write_raw_chunk (pData, pJHDR->sHeader.iChunkname, iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_JHDR, MNG_LC_END); -#endif - - return iRetcode; -} -#else -#define write_jhdr 0 -/* B004 */ -#endif /* MNG_INCLUDE_JNG */ -/* B004 */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -WRITE_CHUNK (mng_write_jdaa) -{ - mng_jdatp pJDAA; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_JDAA, MNG_LC_START); -#endif - - pJDAA = (mng_jdaap)pChunk; /* address the proper chunk */ - - if (pJDAA->bEmpty) /* and write it */ - iRetcode = write_raw_chunk (pData, pJDAA->sHeader.iChunkname, 0, 0); - else - iRetcode = write_raw_chunk (pData, pJDAA->sHeader.iChunkname, - pJDAA->iDatasize, pJDAA->pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_JDAA, MNG_LC_END); -#endif - - return iRetcode; -} -#else -#define write_jdaa 0 -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -/* B004 */ -#ifdef MNG_INCLUDE_JNG -/* B004 */ -WRITE_CHUNK (mng_write_jdat) -{ - mng_jdatp pJDAT; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_JDAT, MNG_LC_START); -#endif - - pJDAT = (mng_jdatp)pChunk; /* address the proper chunk */ - - if (pJDAT->bEmpty) /* and write it */ - iRetcode = write_raw_chunk (pData, pJDAT->sHeader.iChunkname, 0, 0); - else - iRetcode = write_raw_chunk (pData, pJDAT->sHeader.iChunkname, - pJDAT->iDatasize, pJDAT->pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_JDAT, MNG_LC_END); -#endif - - return iRetcode; -} -#else -#define write_jdat 0 -/* B004 */ -#endif /* MNG_INCLUDE_JNG */ -/* B004 */ - -/* ************************************************************************** */ - -/* B004 */ -#ifdef MNG_INCLUDE_JNG -/* B004 */ -WRITE_CHUNK (mng_write_jsep) -{ - mng_jsepp pJSEP; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_JSEP, MNG_LC_START); -#endif - - pJSEP = (mng_jsepp)pChunk; /* address the proper chunk */ - /* and write it */ - iRetcode = write_raw_chunk (pData, pJSEP->sHeader.iChunkname, 0, 0); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_JSEP, MNG_LC_END); -#endif - - return iRetcode; -} -#else -#define write_jsep 0 -/* B004 */ -#endif /* MNG_INCLUDE_JNG */ -/* B004 */ - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -WRITE_CHUNK (mng_write_dhdr) -{ - mng_dhdrp pDHDR; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_DHDR, MNG_LC_START); -#endif - - pDHDR = (mng_dhdrp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 4; - /* fill the output buffer */ - mng_put_uint16 (pRawdata, pDHDR->iObjectid); - - *(pRawdata+2) = pDHDR->iImagetype; - *(pRawdata+3) = pDHDR->iDeltatype; - - if (pDHDR->iDeltatype != 7) - { - iRawlen += 8; - mng_put_uint32 (pRawdata+4, pDHDR->iBlockwidth); - mng_put_uint32 (pRawdata+8, pDHDR->iBlockheight); - - if (pDHDR->iDeltatype != 0) - { - iRawlen += 8; - mng_put_uint32 (pRawdata+12, pDHDR->iBlockx); - mng_put_uint32 (pRawdata+16, pDHDR->iBlocky); - } - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pDHDR->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_DHDR, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -WRITE_CHUNK (mng_write_prom) -{ - mng_promp pPROM; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_PROM, MNG_LC_START); -#endif - - pPROM = (mng_promp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 3; - - *pRawdata = pPROM->iColortype; /* fill the output buffer */ - *(pRawdata+1) = pPROM->iSampledepth; - *(pRawdata+2) = pPROM->iFilltype; - /* and write it */ - iRetcode = write_raw_chunk (pData, pPROM->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_PROM, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -WRITE_CHUNK (mng_write_ipng) -{ - mng_ipngp pIPNG; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_IPNG, MNG_LC_START); -#endif - - pIPNG = (mng_ipngp)pChunk; /* address the proper chunk */ - /* and write it */ - iRetcode = write_raw_chunk (pData, pIPNG->sHeader.iChunkname, 0, 0); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_IPNG, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -WRITE_CHUNK (mng_write_pplt) -{ - mng_ppltp pPPLT; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_pplt_entryp pEntry; - mng_uint8p pTemp; - mng_uint32 iX; - mng_bool bHasgroup; - mng_uint8p pLastid = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_PPLT, MNG_LC_START); -#endif - - pPPLT = (mng_ppltp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 1; - - *pRawdata = pPPLT->iDeltatype; /* fill the output buffer */ - - pTemp = pRawdata+1; - bHasgroup = MNG_FALSE; - - for (iX = 0; iX < pPPLT->iCount; iX++) - { - pEntry = &pPPLT->aEntries[iX]; - - if (pEntry->bUsed) /* valid entry ? */ - { - if (!bHasgroup) /* start a new group ? */ - { - bHasgroup = MNG_TRUE; - pLastid = pTemp+1; - - *pTemp = (mng_uint8)iX; - *(pTemp+1) = 0; - - pTemp += 2; - iRawlen += 2; - } - - switch (pPPLT->iDeltatype) /* add group-entry depending on type */ - { - case 0: ; - case 1: { - *pTemp = pEntry->iRed; - *(pTemp+1) = pEntry->iGreen; - *(pTemp+2) = pEntry->iBlue; - - pTemp += 3; - iRawlen += 3; - - break; - } - - case 2: ; - case 3: { - *pTemp = pEntry->iAlpha; - - pTemp++; - iRawlen++; - - break; - } - - case 4: ; - case 5: { - *pTemp = pEntry->iRed; - *(pTemp+1) = pEntry->iGreen; - *(pTemp+2) = pEntry->iBlue; - *(pTemp+3) = pEntry->iAlpha; - - pTemp += 4; - iRawlen += 4; - - break; - } - - } - } - else - { - if (bHasgroup) /* finish off a group ? */ - *pLastid = (mng_uint8)(iX-1); - - bHasgroup = MNG_FALSE; - } - } - - if (bHasgroup) /* last group unfinished ? */ - *pLastid = (mng_uint8)(pPPLT->iCount-1); - /* write the output buffer */ - iRetcode = write_raw_chunk (pData, pPPLT->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_PPLT, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG -WRITE_CHUNK (mng_write_ijng) -{ - mng_ijngp pIJNG; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_IJNG, MNG_LC_START); -#endif - - pIJNG = (mng_ijngp)pChunk; /* address the proper chunk */ - /* and write it */ - iRetcode = write_raw_chunk (pData, pIJNG->sHeader.iChunkname, 0, 0); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_IJNG, MNG_LC_END); -#endif - - return iRetcode; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -WRITE_CHUNK (mng_write_drop) -{ - mng_dropp pDROP; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_uint32 iX; - mng_uint8p pTemp1; - mng_chunkidp pTemp2; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_DROP, MNG_LC_START); -#endif - - pDROP = (mng_dropp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = pDROP->iCount << 2; - - pTemp1 = pRawdata; /* fill the output buffer */ - pTemp2 = pDROP->pChunknames; - - for (iX = 0; iX < pDROP->iCount; iX++) - { - mng_put_uint32 (pTemp1, (mng_uint32)*pTemp2); - - pTemp2++; - pTemp1 += 4; - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pDROP->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_DROP, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DBYK -WRITE_CHUNK (mng_write_dbyk) -{ - mng_dbykp pDBYK; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_DBYK, MNG_LC_START); -#endif - - pDBYK = (mng_dbykp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 5 + pDBYK->iKeywordssize; - /* fill the output buffer */ - mng_put_uint32 (pRawdata, pDBYK->iChunkname); - *(pRawdata+4) = pDBYK->iPolarity; - - if (pDBYK->iKeywordssize) - MNG_COPY (pRawdata+5, pDBYK->zKeywords, pDBYK->iKeywordssize); - /* and write it */ - iRetcode = write_raw_chunk (pData, pDBYK->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_DBYK, MNG_LC_END); -#endif - - return iRetcode; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR -WRITE_CHUNK (mng_write_ordr) -{ - mng_ordrp pORDR; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_uint8p pTemp; - mng_ordr_entryp pEntry; - mng_uint32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_ORDR, MNG_LC_START); -#endif - - pORDR = (mng_ordrp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = pORDR->iCount * 5; - - pTemp = pRawdata; /* fill the output buffer */ - pEntry = pORDR->pEntries; - - for (iX = 0; iX < pORDR->iCount; iX++) - { - mng_put_uint32 (pTemp, pEntry->iChunkname); - *(pTemp+4) = pEntry->iOrdertype; - pTemp += 5; - pEntry++; - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pORDR->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_ORDR, MNG_LC_END); -#endif - - return iRetcode; -} -#endif -#endif - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_magn) -{ - mng_magnp pMAGN; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_MAGN, MNG_LC_START); -#endif - - pMAGN = (mng_magnp)pChunk; /* address the proper chunk */ - - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 18; - /* fill the output buffer */ - mng_put_uint16 (pRawdata, pMAGN->iFirstid); - mng_put_uint16 (pRawdata+2, pMAGN->iLastid); - *(pRawdata+4) = pMAGN->iMethodX; - mng_put_uint16 (pRawdata+5, pMAGN->iMX); - mng_put_uint16 (pRawdata+7, pMAGN->iMY); - mng_put_uint16 (pRawdata+9, pMAGN->iML); - mng_put_uint16 (pRawdata+11, pMAGN->iMR); - mng_put_uint16 (pRawdata+13, pMAGN->iMT); - mng_put_uint16 (pRawdata+15, pMAGN->iMB); - *(pRawdata+17) = pMAGN->iMethodY; - /* optimize length */ - if (pMAGN->iMethodY == pMAGN->iMethodX) - { - iRawlen--; - - if (pMAGN->iMB == pMAGN->iMY) - { - iRawlen -= 2; - - if (pMAGN->iMT == pMAGN->iMY) - { - iRawlen -= 2; - - if (pMAGN->iMR == pMAGN->iMX) - { - iRawlen -= 2; - - if (pMAGN->iML == pMAGN->iMX) - { - iRawlen -= 2; - - if (pMAGN->iMY == pMAGN->iMX) - { - iRawlen -= 2; - - if (pMAGN->iMX == 1) - { - iRawlen -= 2; - - if (pMAGN->iMethodX == 0) - { - iRawlen--; - - if (pMAGN->iLastid == pMAGN->iFirstid) - { - iRawlen -= 2; - - if (pMAGN->iFirstid == 0) - iRawlen = 0; - - } - } - } - } - } - } - } - } - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pMAGN->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_MAGN, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_MPNG_PROPOSAL -WRITE_CHUNK (mng_write_mpng) -{ - mng_mpngp pMPNG; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_uint8p pBuf = 0; - mng_uint32 iBuflen; - mng_uint32 iReallen; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_MPNG, MNG_LC_START); -#endif - - pMPNG = (mng_mpngp)pChunk; /* address the proper chunk */ - /* compress the frame structures */ - iRetcode = deflate_buffer (pData, (mng_uint8p)pMPNG->pFrames, pMPNG->iFramessize, - &pBuf, &iBuflen, &iReallen); - - if (!iRetcode) /* all ok ? */ - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 15 + iReallen; - /* requires large buffer ? */ - if (iRawlen > pData->iWritebufsize) - MNG_ALLOC (pData, pRawdata, iRawlen); - /* fill the buffer */ - mng_put_uint32 (pRawdata, pMPNG->iFramewidth); - mng_put_uint32 (pRawdata+4, pMPNG->iFrameheight); - mng_put_uint16 (pRawdata+8, pMPNG->iNumplays); - mng_put_uint16 (pRawdata+10, pMPNG->iTickspersec); - *(pRawdata+12) = pMPNG->iCompressionmethod; - - if (iReallen) - MNG_COPY (pRawdata+13, pBuf, iReallen); - /* and write it */ - iRetcode = write_raw_chunk (pData, pMPNG->sHeader.iChunkname, - iRawlen, pRawdata); - /* drop the temp buffer ? */ - if (iRawlen > pData->iWritebufsize) - MNG_FREEX (pData, pRawdata, iRawlen); - } - - MNG_FREEX (pData, pBuf, iBuflen); /* always drop the compression buffer */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_MPNG, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ANG_PROPOSAL -WRITE_CHUNK (mng_write_ahdr) -{ - mng_ahdrp pAHDR; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_AHDR, MNG_LC_START); -#endif - - pAHDR = (mng_ahdrp)pChunk; /* address the proper chunk */ - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 22; - /* fill the buffer */ - mng_put_uint32 (pRawdata, pAHDR->iNumframes); - mng_put_uint32 (pRawdata+4, pAHDR->iTickspersec); - mng_put_uint32 (pRawdata+8, pAHDR->iNumplays); - mng_put_uint32 (pRawdata+12, pAHDR->iTilewidth); - mng_put_uint32 (pRawdata+16, pAHDR->iTileheight); - *(pRawdata+20) = pAHDR->iInterlace; - *(pRawdata+21) = pAHDR->iStillused; - /* and write it */ - iRetcode = write_raw_chunk (pData, pAHDR->sHeader.iChunkname, - iRawlen, pRawdata); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_AHDR, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ANG_PROPOSAL -WRITE_CHUNK (mng_write_adat) -{ - - /* TODO: something */ - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_evNT -WRITE_CHUNK (mng_write_evnt) -{ - mng_evntp pEVNT; - mng_uint8p pRawdata; - mng_uint32 iRawlen; - mng_retcode iRetcode; - mng_evnt_entryp pEntry; - mng_uint8p pTemp; - mng_uint32 iX; - mng_uint32 iNamesize; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_EVNT, MNG_LC_START); -#endif - - pEVNT = (mng_evntp)pChunk; /* address the proper chunk */ - - if (!pEVNT->iCount) /* empty ? */ - iRetcode = write_raw_chunk (pData, pEVNT->sHeader.iChunkname, 0, 0); - else - { - pRawdata = pData->pWritebuf+8; /* init output buffer & size */ - iRawlen = 0; - pTemp = pRawdata; - pEntry = pEVNT->pEntries; - - for (iX = 0; iX < pEVNT->iCount; iX++) - { - if (iX) /* put separator null-byte, except the first */ - { - *pTemp = 0; - pTemp++; - iRawlen++; - } - - *pTemp = pEntry->iEventtype; - *(pTemp+1) = pEntry->iMasktype; - pTemp += 2; - iRawlen += 2; - - switch (pEntry->iMasktype) - { - case 1 : - { - mng_put_int32 (pTemp, pEntry->iLeft); - mng_put_int32 (pTemp+4, pEntry->iRight); - mng_put_int32 (pTemp+8, pEntry->iTop); - mng_put_int32 (pTemp+12, pEntry->iBottom); - pTemp += 16; - iRawlen += 16; - break; - } - case 2 : - { - mng_put_uint16 (pTemp, pEntry->iObjectid); - pTemp += 2; - iRawlen += 2; - break; - } - case 3 : - { - mng_put_uint16 (pTemp, pEntry->iObjectid); - *(pTemp+2) = pEntry->iIndex; - pTemp += 3; - iRawlen += 3; - break; - } - case 4 : - { - mng_put_int32 (pTemp, pEntry->iLeft); - mng_put_int32 (pTemp+4, pEntry->iRight); - mng_put_int32 (pTemp+8, pEntry->iTop); - mng_put_int32 (pTemp+12, pEntry->iBottom); - mng_put_uint16 (pTemp+16, pEntry->iObjectid); - pTemp += 18; - iRawlen += 18; - break; - } - case 5 : - { - mng_put_int32 (pTemp, pEntry->iLeft); - mng_put_int32 (pTemp+4, pEntry->iRight); - mng_put_int32 (pTemp+8, pEntry->iTop); - mng_put_int32 (pTemp+12, pEntry->iBottom); - mng_put_uint16 (pTemp+16, pEntry->iObjectid); - *(pTemp+18) = pEntry->iIndex; - pTemp += 19; - iRawlen += 19; - break; - } - } - - iNamesize = pEntry->iSegmentnamesize; - - if (iNamesize) - { - MNG_COPY (pTemp, pEntry->zSegmentname, iNamesize); - pTemp += iNamesize; - iRawlen += iNamesize; - } - - pEntry++; - } - /* and write it */ - iRetcode = write_raw_chunk (pData, pEVNT->sHeader.iChunkname, - iRawlen, pRawdata); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_EVNT, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -WRITE_CHUNK (mng_write_unknown) -{ - mng_unknown_chunkp pUnknown; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_UNKNOWN, MNG_LC_START); -#endif - /* address the proper chunk */ - pUnknown = (mng_unknown_chunkp)pChunk; - /* and write it */ - iRetcode = write_raw_chunk (pData, pUnknown->sHeader.iChunkname, - pUnknown->iDatasize, pUnknown->pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_UNKNOWN, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_WRITE_PROCS */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - +/** ************************************************************************* */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_chunk_io.c copyright (c) 2000-2007 G.Juyn * */ +/* * version : 1.0.10 * */ +/* * * */ +/* * purpose : Chunk I/O routines (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of chunk input/output routines * */ +/* * * */ +/* * changes : 0.5.1 - 05/01/2000 - G.Juyn * */ +/* * - cleaned up left-over teststuff in the BACK chunk routine * */ +/* * 0.5.1 - 05/04/2000 - G.Juyn * */ +/* * - changed CRC initialization to use dynamic structure * */ +/* * (wasn't thread-safe the old way !) * */ +/* * 0.5.1 - 05/06/2000 - G.Juyn * */ +/* * - filled in many missing sequence&length checks * */ +/* * - filled in many missing chunk-store snippets * */ +/* * 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - added checks for running animations * */ +/* * - filled some write routines * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/10/2000 - G.Juyn * */ +/* * - filled some more write routines * */ +/* * 0.5.1 - 05/11/2000 - G.Juyn * */ +/* * - filled remaining write routines * */ +/* * - fixed read_pplt with regard to deltatype * */ +/* * - added callback error-reporting support * */ +/* * - added pre-draft48 support (short MHDR, frame_mode, LOOP) * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - changed trace to macro for callback error-reporting * */ +/* * - fixed chunk-storage bit in several routines * */ +/* * 0.5.1 - 05/13/2000 - G.Juyn * */ +/* * - added eMNGma hack (will be removed in 1.0.0 !!!) * */ +/* * - added TERM animation object pointer (easier reference) * */ +/* * - supplemented the SAVE & SEEK display processing * */ +/* * * */ +/* * 0.5.2 - 05/18/2000 - G.Juyn * */ +/* * - B004 - fixed problem with MNG_SUPPORT_WRITE not defined * */ +/* * also for MNG_SUPPORT_WRITE without MNG_INCLUDE_JNG * */ +/* * 0.5.2 - 05/19/2000 - G.Juyn * */ +/* * - cleaned up some code regarding mixed support * */ +/* * 0.5.2 - 05/20/2000 - G.Juyn * */ +/* * - implemented JNG support * */ +/* * 0.5.2 - 05/24/2000 - G.Juyn * */ +/* * - added support for global color-chunks in animation * */ +/* * - added support for global PLTE,tRNS,bKGD in animation * */ +/* * - added support for SAVE & SEEK in animation * */ +/* * 0.5.2 - 05/29/2000 - G.Juyn * */ +/* * - changed ani_create calls not returning object pointer * */ +/* * - create ani objects always (not just inside TERM/LOOP) * */ +/* * 0.5.2 - 05/30/2000 - G.Juyn * */ +/* * - added support for delta-image processing * */ +/* * 0.5.2 - 05/31/2000 - G.Juyn * */ +/* * - fixed up punctuation (contributed by Tim Rowley) * */ +/* * 0.5.2 - 06/02/2000 - G.Juyn * */ +/* * - changed SWAP_ENDIAN to BIGENDIAN_SUPPORTED * */ +/* * 0.5.2 - 06/03/2000 - G.Juyn * */ +/* * - fixed makeup for Linux gcc compile * */ +/* * * */ +/* * 0.5.3 - 06/12/2000 - G.Juyn * */ +/* * - added processing of color-info on delta-image * */ +/* * 0.5.3 - 06/13/2000 - G.Juyn * */ +/* * - fixed handling of empty SAVE chunk * */ +/* * 0.5.3 - 06/17/2000 - G.Juyn * */ +/* * - changed to support delta-images * */ +/* * - added extra checks for delta-images * */ +/* * 0.5.3 - 06/20/2000 - G.Juyn * */ +/* * - fixed possible trouble if IEND display-process got * */ +/* * broken up * */ +/* * 0.5.3 - 06/21/2000 - G.Juyn * */ +/* * - added processing of PLTE & tRNS for delta-images * */ +/* * - added administration of imagelevel parameter * */ +/* * 0.5.3 - 06/22/2000 - G.Juyn * */ +/* * - implemented support for PPLT chunk * */ +/* * 0.5.3 - 06/26/2000 - G.Juyn * */ +/* * - added precaution against faulty iCCP chunks from PS * */ +/* * 0.5.3 - 06/29/2000 - G.Juyn * */ +/* * - fixed some 64-bit warnings * */ +/* * * */ +/* * 0.9.1 - 07/14/2000 - G.Juyn * */ +/* * - changed pre-draft48 frame_mode=3 to frame_mode=1 * */ +/* * 0.9.1 - 07/16/2000 - G.Juyn * */ +/* * - fixed storage of images during mng_read() * */ +/* * - fixed support for mng_display() after mng_read() * */ +/* * 0.9.1 - 07/19/2000 - G.Juyn * */ +/* * - fixed several chunk-writing routines * */ +/* * 0.9.1 - 07/24/2000 - G.Juyn * */ +/* * - fixed reading of still-images * */ +/* * * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 0.9.3 - 08/07/2000 - G.Juyn * */ +/* * - B111300 - fixup for improved portability * */ +/* * 0.9.3 - 08/08/2000 - G.Juyn * */ +/* * - fixed compiler-warnings from Mozilla * */ +/* * 0.9.3 - 08/09/2000 - G.Juyn * */ +/* * - added check for simplicity-bits in MHDR * */ +/* * 0.9.3 - 08/12/2000 - G.Juyn * */ +/* * - fixed check for simplicity-bits in MHDR (JNG) * */ +/* * 0.9.3 - 08/12/2000 - G.Juyn * */ +/* * - added workaround for faulty PhotoShop iCCP chunk * */ +/* * 0.9.3 - 08/22/2000 - G.Juyn * */ +/* * - fixed write-code for zTXt & iTXt * */ +/* * - fixed read-code for iTXt * */ +/* * 0.9.3 - 08/26/2000 - G.Juyn * */ +/* * - added MAGN chunk * */ +/* * 0.9.3 - 09/07/2000 - G.Juyn * */ +/* * - added support for new filter_types * */ +/* * 0.9.3 - 09/10/2000 - G.Juyn * */ +/* * - fixed DEFI behavior * */ +/* * 0.9.3 - 10/02/2000 - G.Juyn * */ +/* * - fixed simplicity-check in compliance with draft 81/0.98a * */ +/* * 0.9.3 - 10/10/2000 - G.Juyn * */ +/* * - added support for alpha-depth prediction * */ +/* * 0.9.3 - 10/11/2000 - G.Juyn * */ +/* * - added support for nEED * */ +/* * 0.9.3 - 10/16/2000 - G.Juyn * */ +/* * - added support for JDAA * */ +/* * 0.9.3 - 10/17/2000 - G.Juyn * */ +/* * - fixed support for MAGN * */ +/* * - implemented nEED "xxxx" (where "xxxx" is a chunkid) * */ +/* * - added callback to process non-critical unknown chunks * */ +/* * - fixed support for bKGD * */ +/* * 0.9.3 - 10/23/2000 - G.Juyn * */ +/* * - fixed bug in empty PLTE handling * */ +/* * * */ +/* * 0.9.4 - 11/20/2000 - G.Juyn * */ +/* * - changed IHDR filter_method check for PNGs * */ +/* * 0.9.4 - 1/18/2001 - G.Juyn * */ +/* * - added errorchecking for MAGN methods * */ +/* * - removed test filter-methods 1 & 65 * */ +/* * * */ +/* * 0.9.5 - 1/25/2001 - G.Juyn * */ +/* * - fixed some small compiler warnings (thanks Nikki) * */ +/* * * */ +/* * 1.0.2 - 05/05/2000 - G.Juyn * */ +/* * - B421427 - writes wrong format in bKGD and tRNS * */ +/* * 1.0.2 - 06/20/2000 - G.Juyn * */ +/* * - B434583 - compiler-warning if MNG_STORE_CHUNKS undefined * */ +/* * * */ +/* * 1.0.5 - 07/08/2002 - G.Juyn * */ +/* * - B578572 - removed eMNGma hack (thanks Dimitri!) * */ +/* * 1.0.5 - 08/07/2002 - G.Juyn * */ +/* * - added test-option for PNG filter method 193 (=no filter) * */ +/* * 1.0.5 - 08/15/2002 - G.Juyn * */ +/* * - completed PROM support * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * 1.0.5 - 09/07/2002 - G.Juyn * */ +/* * - fixed reading of FRAM with just frame_mode and name * */ +/* * 1.0.5 - 09/13/2002 - G.Juyn * */ +/* * - fixed read/write of MAGN chunk * */ +/* * 1.0.5 - 09/14/2002 - G.Juyn * */ +/* * - added event handling for dynamic MNG * */ +/* * 1.0.5 - 09/15/2002 - G.Juyn * */ +/* * - fixed LOOP iteration=0 special case * */ +/* * 1.0.5 - 09/19/2002 - G.Juyn * */ +/* * - misplaced TERM is now treated as warning * */ +/* * 1.0.5 - 09/20/2002 - G.Juyn * */ +/* * - added support for PAST * */ +/* * 1.0.5 - 10/03/2002 - G.Juyn * */ +/* * - fixed chunk-storage for evNT chunk * */ +/* * 1.0.5 - 10/07/2002 - G.Juyn * */ +/* * - fixed DISC support * */ +/* * - added another fix for misplaced TERM chunk * */ +/* * 1.0.5 - 10/17/2002 - G.Juyn * */ +/* * - fixed initializtion of pIds in dISC read routine * */ +/* * 1.0.5 - 11/06/2002 - G.Juyn * */ +/* * - added support for nEED "MNG 1.1" * */ +/* * - added support for nEED "CACHEOFF" * */ +/* * * */ +/* * 1.0.6 - 05/25/2003 - G.R-P * */ +/* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */ +/* * 1.0.6 - 06/02/2003 - G.R-P * */ +/* * - removed some redundant checks for iRawlen==0 * */ +/* * 1.0.6 - 06/22/2003 - G.R-P * */ +/* * - added MNG_NO_16BIT_SUPPORT, MNG_NO_DELTA_PNG reductions * */ +/* * - optionally use zlib's crc32 function instead of * */ +/* * local mng_update_crc * */ +/* * 1.0.6 - 07/14/2003 - G.R-P * */ +/* * - added MNG_NO_LOOP_SIGNALS_SUPPORTED conditional * */ +/* * 1.0.6 - 07/29/2003 - G.R-P * */ +/* * - added conditionals around PAST chunk support * */ +/* * 1.0.6 - 08/17/2003 - G.R-P * */ +/* * - added conditionals around non-VLC chunk support * */ +/* * * */ +/* * 1.0.7 - 10/29/2003 - G.R-P * */ +/* * - revised JDAA and JDAT readers to avoid compiler bug * */ +/* * 1.0.7 - 01/25/2004 - J.S * */ +/* * - added premultiplied alpha canvas' for RGBA, ARGB, ABGR * */ +/* * 1.0.7 - 01/27/2004 - J.S * */ +/* * - fixed inclusion of IJNG chunk for non-JNG use * */ +/* * 1.0.7 - 02/26/2004 - G.Juyn * */ +/* * - fixed bug in chunk-storage of SHOW chunk (from == to) * */ +/* * * */ +/* * 1.0.8 - 04/02/2004 - G.Juyn * */ +/* * - added CRC existence & checking flags * */ +/* * 1.0.8 - 07/07/2004 - G.R-P * */ +/* * - change worst-case iAlphadepth to 1 for standalone PNGs * */ +/* * * */ +/* * 1.0.9 - 09/28/2004 - G.R-P * */ +/* * - improved handling of cheap transparency when 16-bit * */ +/* * support is disabled * */ +/* * 1.0.9 - 10/04/2004 - G.Juyn * */ +/* * - fixed bug in writing sBIT for indexed color * */ +/* * 1.0.9 - 10/10/2004 - G.R-P. * */ +/* * - added MNG_NO_1_2_4BIT_SUPPORT * */ +/* * 1.0.9 - 12/05/2004 - G.Juyn * */ +/* * - added conditional MNG_OPTIMIZE_CHUNKINITFREE * */ +/* * 1.0.9 - 12/06/2004 - G.Juyn * */ +/* * - added conditional MNG_OPTIMIZE_CHUNKASSIGN * */ +/* * 1.0.9 - 12/07/2004 - G.Juyn * */ +/* * - added conditional MNG_OPTIMIZE_CHUNKREADER * */ +/* * 1.0.9 - 12/11/2004 - G.Juyn * */ +/* * - added conditional MNG_OPTIMIZE_DISPLAYCALLS * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * 1.0.9 - 01/17/2005 - G.Juyn * */ +/* * - fixed problem with global PLTE/tRNS * */ +/* * * */ +/* * 1.0.10 - 02/07/2005 - G.Juyn * */ +/* * - fixed display routines called twice for FULL_MNG * */ +/* * support in mozlibmngconf.h * */ +/* * 1.0.10 - 12/04/2005 - G.R-P. * */ +/* * - #ifdef out use of mng_inflate_buffer when it is not * */ +/* * available. * */ +/* * 1.0.10 - 04/08/2007 - G.Juyn * */ +/* * - added support for mPNG proposal * */ +/* * 1.0.10 - 04/12/2007 - G.Juyn * */ +/* * - added support for ANG proposal * */ +/* * 1.0.10 - 05/02/2007 - G.Juyn * */ +/* * - fixed inflate_buffer for extreme compression ratios * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_objects.h" +#include "libmng_object_prc.h" +#include "libmng_chunks.h" +#ifdef MNG_CHECK_BAD_ICCP +#include "libmng_chunk_prc.h" +#endif +#include "libmng_memory.h" +#include "libmng_display.h" +#include "libmng_zlib.h" +#include "libmng_pixels.h" +#include "libmng_chunk_io.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ +/* * * */ +/* * CRC - Cyclic Redundancy Check * */ +/* * * */ +/* * The code below is taken directly from the sample provided with the * */ +/* * PNG specification. * */ +/* * (it is only adapted to the library's internal data-definitions) * */ +/* * * */ +/* ************************************************************************** */ +/* Make the table for a fast CRC. */ +#ifndef MNG_USE_ZLIB_CRC +MNG_LOCAL void make_crc_table (mng_datap pData) +{ + mng_uint32 iC; + mng_int32 iN, iK; + + for (iN = 0; iN < 256; iN++) + { + iC = (mng_uint32) iN; + + for (iK = 0; iK < 8; iK++) + { + if (iC & 1) + iC = 0xedb88320U ^ (iC >> 1); + else + iC = iC >> 1; + } + + pData->aCRCtable [iN] = iC; + } + + pData->bCRCcomputed = MNG_TRUE; +} +#endif + +/* Update a running CRC with the bytes buf[0..len-1]--the CRC + should be initialized to all 1's, and the transmitted value + is the 1's complement of the final running CRC (see the + crc() routine below). */ + +MNG_LOCAL mng_uint32 update_crc (mng_datap pData, + mng_uint32 iCrc, + mng_uint8p pBuf, + mng_int32 iLen) +{ +#ifdef MNG_USE_ZLIB_CRC + return crc32 (iCrc, pBuf, iLen); +#else + mng_uint32 iC = iCrc; + mng_int32 iN; + + if (!pData->bCRCcomputed) + make_crc_table (pData); + + for (iN = 0; iN < iLen; iN++) + iC = pData->aCRCtable [(iC ^ pBuf [iN]) & 0xff] ^ (iC >> 8); + + return iC; +#endif +} + +/* Return the CRC of the bytes buf[0..len-1]. */ +mng_uint32 mng_crc (mng_datap pData, + mng_uint8p pBuf, + mng_int32 iLen) +{ +#ifdef MNG_USE_ZLIB_CRC + return update_crc (pData, 0, pBuf, iLen); +#else + return update_crc (pData, 0xffffffffU, pBuf, iLen) ^ 0xffffffffU; +#endif +} + +/* ************************************************************************** */ +/* * * */ +/* * Routines for swapping byte-order from and to graphic files * */ +/* * (This code is adapted from the libpng package) * */ +/* * * */ +/* ************************************************************************** */ + +#ifndef MNG_BIGENDIAN_SUPPORTED + +/* ************************************************************************** */ + +mng_uint32 mng_get_uint32 (mng_uint8p pBuf) +{ + mng_uint32 i = ((mng_uint32)(*pBuf) << 24) + + ((mng_uint32)(*(pBuf + 1)) << 16) + + ((mng_uint32)(*(pBuf + 2)) << 8) + + (mng_uint32)(*(pBuf + 3)); + return (i); +} + +/* ************************************************************************** */ + +mng_int32 mng_get_int32 (mng_uint8p pBuf) +{ + mng_int32 i = ((mng_int32)(*pBuf) << 24) + + ((mng_int32)(*(pBuf + 1)) << 16) + + ((mng_int32)(*(pBuf + 2)) << 8) + + (mng_int32)(*(pBuf + 3)); + return (i); +} + +/* ************************************************************************** */ + +mng_uint16 mng_get_uint16 (mng_uint8p pBuf) +{ + mng_uint16 i = (mng_uint16)(((mng_uint16)(*pBuf) << 8) + + (mng_uint16)(*(pBuf + 1))); + return (i); +} + +/* ************************************************************************** */ + +void mng_put_uint32 (mng_uint8p pBuf, + mng_uint32 i) +{ + *pBuf = (mng_uint8)((i >> 24) & 0xff); + *(pBuf+1) = (mng_uint8)((i >> 16) & 0xff); + *(pBuf+2) = (mng_uint8)((i >> 8) & 0xff); + *(pBuf+3) = (mng_uint8)(i & 0xff); +} + +/* ************************************************************************** */ + +void mng_put_int32 (mng_uint8p pBuf, + mng_int32 i) +{ + *pBuf = (mng_uint8)((i >> 24) & 0xff); + *(pBuf+1) = (mng_uint8)((i >> 16) & 0xff); + *(pBuf+2) = (mng_uint8)((i >> 8) & 0xff); + *(pBuf+3) = (mng_uint8)(i & 0xff); +} + +/* ************************************************************************** */ + +void mng_put_uint16 (mng_uint8p pBuf, + mng_uint16 i) +{ + *pBuf = (mng_uint8)((i >> 8) & 0xff); + *(pBuf+1) = (mng_uint8)(i & 0xff); +} + +/* ************************************************************************** */ + +#endif /* !MNG_BIGENDIAN_SUPPORTED */ + +/* ************************************************************************** */ +/* * * */ +/* * Helper routines to simplify chunk-data extraction * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_READ_PROCS + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +MNG_LOCAL mng_uint8p find_null (mng_uint8p pIn) +{ + mng_uint8p pOut = pIn; + while (*pOut) /* the read_graphic routine has made sure there's */ + pOut++; /* always at least 1 zero-byte in the buffer */ + return pOut; +} +#endif + +/* ************************************************************************** */ + +#if !defined(MNG_SKIPCHUNK_iCCP) || !defined(MNG_SKIPCHUNK_zTXt) || \ + !defined(MNG_SKIPCHUNK_iTXt) || defined(MNG_INCLUDE_MPNG_PROPOSAL) || \ + defined(MNG_INCLUDE_ANG_PROPOSAL) +mng_retcode mng_inflate_buffer (mng_datap pData, + mng_uint8p pInbuf, + mng_uint32 iInsize, + mng_uint8p *pOutbuf, + mng_uint32 *iOutsize, + mng_uint32 *iRealsize) +{ + mng_retcode iRetcode = MNG_NOERROR; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INFLATE_BUFFER, MNG_LC_START); +#endif + + if (iInsize) /* anything to do ? */ + { + *iOutsize = iInsize * 3; /* estimate uncompressed size */ + /* and allocate a temporary buffer */ + MNG_ALLOC (pData, *pOutbuf, *iOutsize); + + do + { + mngzlib_inflateinit (pData); /* initialize zlib */ + /* let zlib know where to store the output */ + pData->sZlib.next_out = *pOutbuf; + /* "size - 1" so we've got space for the + zero-termination of a possible string */ + pData->sZlib.avail_out = *iOutsize - 1; + /* ok; let's inflate... */ + iRetcode = mngzlib_inflatedata (pData, iInsize, pInbuf); + /* determine actual output size */ + *iRealsize = (mng_uint32)pData->sZlib.total_out; + + mngzlib_inflatefree (pData); /* zlib's done */ + + if (iRetcode == MNG_BUFOVERFLOW) /* not enough space ? */ + { /* then get some more */ + MNG_FREEX (pData, *pOutbuf, *iOutsize); + *iOutsize = *iOutsize + *iOutsize; + MNG_ALLOC (pData, *pOutbuf, *iOutsize); + } + } /* repeat if we didn't have enough space */ + while ((iRetcode == MNG_BUFOVERFLOW) && + (*iOutsize < 200 * iInsize)); + + if (!iRetcode) /* if oke ? */ + *((*pOutbuf) + *iRealsize) = 0; /* then put terminator zero */ + + } + else + { + *pOutbuf = 0; /* nothing to do; then there's no output */ + *iOutsize = 0; + *iRealsize = 0; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INFLATE_BUFFER, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_READ_PROCS */ + +/* ************************************************************************** */ +/* * * */ +/* * Helper routines to simplify chunk writing * */ +/* * * */ +/* ************************************************************************** */ +#ifdef MNG_INCLUDE_WRITE_PROCS +/* ************************************************************************** */ + +#if !defined(MNG_SKIPCHUNK_iCCP) || !defined(MNG_SKIPCHUNK_zTXt) || !defined(MNG_SKIPCHUNK_iTXt) +MNG_LOCAL mng_retcode deflate_buffer (mng_datap pData, + mng_uint8p pInbuf, + mng_uint32 iInsize, + mng_uint8p *pOutbuf, + mng_uint32 *iOutsize, + mng_uint32 *iRealsize) +{ + mng_retcode iRetcode = MNG_NOERROR; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DEFLATE_BUFFER, MNG_LC_START); +#endif + + if (iInsize) /* anything to do ? */ + { + *iOutsize = (iInsize * 5) >> 2; /* estimate compressed size */ + /* and allocate a temporary buffer */ + MNG_ALLOC (pData, *pOutbuf, *iOutsize); + + do + { + mngzlib_deflateinit (pData); /* initialize zlib */ + /* let zlib know where to store the output */ + pData->sZlib.next_out = *pOutbuf; + pData->sZlib.avail_out = *iOutsize; + /* ok; let's deflate... */ + iRetcode = mngzlib_deflatedata (pData, iInsize, pInbuf); + /* determine actual output size */ + *iRealsize = pData->sZlib.total_out; + + mngzlib_deflatefree (pData); /* zlib's done */ + + if (iRetcode == MNG_BUFOVERFLOW) /* not enough space ? */ + { /* then get some more */ + MNG_FREEX (pData, *pOutbuf, *iOutsize); + *iOutsize = *iOutsize + (iInsize >> 1); + MNG_ALLOC (pData, *pOutbuf, *iOutsize); + } + } /* repeat if we didn't have enough space */ + while (iRetcode == MNG_BUFOVERFLOW); + } + else + { + *pOutbuf = 0; /* nothing to do; then there's no output */ + *iOutsize = 0; + *iRealsize = 0; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DEFLATE_BUFFER, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode write_raw_chunk (mng_datap pData, + mng_chunkid iChunkname, + mng_uint32 iRawlen, + mng_uint8p pRawdata) +{ + mng_uint32 iCrc; + mng_uint32 iWritten; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_RAW_CHUNK, MNG_LC_START); +#endif + /* temporary buffer ? */ + if ((pRawdata != 0) && (pRawdata != pData->pWritebuf+8)) + { /* store length & chunktype in default buffer */ + mng_put_uint32 (pData->pWritebuf, iRawlen); + mng_put_uint32 (pData->pWritebuf+4, (mng_uint32)iChunkname); + + if (pData->iCrcmode & MNG_CRC_OUTPUT) + { + if ((pData->iCrcmode & MNG_CRC_OUTPUT) == MNG_CRC_OUTPUT_GENERATE) + { /* calculate the crc */ + iCrc = update_crc (pData, 0xffffffffL, pData->pWritebuf+4, 4); + iCrc = update_crc (pData, iCrc, pRawdata, iRawlen) ^ 0xffffffffL; + } else { + iCrc = 0; /* dummy crc */ + } /* store in default buffer */ + mng_put_uint32 (pData->pWritebuf+8, iCrc); + } + /* write the length & chunktype */ + if (!pData->fWritedata ((mng_handle)pData, pData->pWritebuf, 8, &iWritten)) + MNG_ERROR (pData, MNG_APPIOERROR); + + if (iWritten != 8) /* disk full ? */ + MNG_ERROR (pData, MNG_OUTPUTERROR); + /* write the temporary buffer */ + if (!pData->fWritedata ((mng_handle)pData, pRawdata, iRawlen, &iWritten)) + MNG_ERROR (pData, MNG_APPIOERROR); + + if (iWritten != iRawlen) /* disk full ? */ + MNG_ERROR (pData, MNG_OUTPUTERROR); + + if (pData->iCrcmode & MNG_CRC_OUTPUT) + { /* write the crc */ + if (!pData->fWritedata ((mng_handle)pData, pData->pWritebuf+8, 4, &iWritten)) + MNG_ERROR (pData, MNG_APPIOERROR); + + if (iWritten != 4) /* disk full ? */ + MNG_ERROR (pData, MNG_OUTPUTERROR); + } + } + else + { /* prefix with length & chunktype */ + mng_put_uint32 (pData->pWritebuf, iRawlen); + mng_put_uint32 (pData->pWritebuf+4, (mng_uint32)iChunkname); + + if (pData->iCrcmode & MNG_CRC_OUTPUT) + { + if ((pData->iCrcmode & MNG_CRC_OUTPUT) == MNG_CRC_OUTPUT_GENERATE) + /* calculate the crc */ + iCrc = mng_crc (pData, pData->pWritebuf+4, iRawlen + 4); + else + iCrc = 0; /* dummy crc */ + /* add it to the buffer */ + mng_put_uint32 (pData->pWritebuf + iRawlen + 8, iCrc); + /* write it in a single pass */ + if (!pData->fWritedata ((mng_handle)pData, pData->pWritebuf, iRawlen + 12, &iWritten)) + MNG_ERROR (pData, MNG_APPIOERROR); + + if (iWritten != iRawlen + 12) /* disk full ? */ + MNG_ERROR (pData, MNG_OUTPUTERROR); + } else { + if (!pData->fWritedata ((mng_handle)pData, pData->pWritebuf, iRawlen + 8, &iWritten)) + MNG_ERROR (pData, MNG_APPIOERROR); + + if (iWritten != iRawlen + 8) /* disk full ? */ + MNG_ERROR (pData, MNG_OUTPUTERROR); + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_RAW_CHUNK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ +/* B004 */ +#endif /* MNG_INCLUDE_WRITE_PROCS */ +/* B004 */ +/* ************************************************************************** */ +/* * * */ +/* * chunk read functions * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_READ_PROCS + +/* ************************************************************************** */ + +#ifdef MNG_OPTIMIZE_CHUNKREADER + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode create_chunk_storage (mng_datap pData, + mng_chunkp pHeader, + mng_uint32 iRawlen, + mng_uint8p pRawdata, + mng_field_descp pField, + mng_uint16 iFields, + mng_chunkp* ppChunk, + mng_bool bWorkcopy) +{ + mng_field_descp pTempfield = pField; + mng_uint16 iFieldcount = iFields; + mng_uint8p pTempdata = pRawdata; + mng_uint32 iTemplen = iRawlen; + mng_uint16 iLastgroup = 0; + mng_uint8p pChunkdata; + mng_uint32 iDatalen; + mng_uint8 iColortype; + mng_bool bProcess; + /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + if (iRetcode) /* on error bail out */ + return iRetcode; + + if (((mng_chunk_headerp)(*ppChunk))->iChunkname == MNG_UINT_HUH) + ((mng_chunk_headerp)(*ppChunk))->iChunkname = pData->iChunkname; + + if ((!bWorkcopy) || + ((((mng_chunk_headerp)pHeader)->iChunkname != MNG_UINT_IDAT) && + (((mng_chunk_headerp)pHeader)->iChunkname != MNG_UINT_JDAT) && + (((mng_chunk_headerp)pHeader)->iChunkname != MNG_UINT_JDAA) )) + { + pChunkdata = (mng_uint8p)(*ppChunk); + +#ifdef MNG_INCLUDE_JNG /* determine current colortype */ + if (pData->bHasJHDR) + iColortype = (mng_uint8)(pData->iJHDRcolortype - 8); + else +#endif /* MNG_INCLUDE_JNG */ + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + iColortype = pData->iColortype; + else + iColortype = 6; + + if (iTemplen) /* not empty ? */ + { /* then go fill the fields */ + while ((iFieldcount) && (iTemplen)) + { + if (pTempfield->iOffsetchunk) + { + if (pTempfield->iFlags & MNG_FIELD_PUTIMGTYPE) + { + *(pChunkdata+pTempfield->iOffsetchunk) = iColortype; + bProcess = MNG_FALSE; + } + else + if (pTempfield->iFlags & MNG_FIELD_IFIMGTYPES) + bProcess = (mng_bool)(((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE0) && (iColortype == 0)) || + ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE2) && (iColortype == 2)) || + ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE3) && (iColortype == 3)) || + ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE4) && (iColortype == 4)) || + ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE6) && (iColortype == 6)) ); + else + bProcess = MNG_TRUE; + + if (bProcess) + { + iLastgroup = (mng_uint16)(pTempfield->iFlags & MNG_FIELD_GROUPMASK); + /* numeric field ? */ + if (pTempfield->iFlags & MNG_FIELD_INT) + { + if (iTemplen < pTempfield->iLengthmax) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + switch (pTempfield->iLengthmax) + { + case 1 : { mng_uint8 iNum = *pTempdata; + if (((mng_uint16)iNum < pTempfield->iMinvalue) || + ((mng_uint16)iNum > pTempfield->iMaxvalue) ) + MNG_ERROR (pData, MNG_INVALIDFIELDVAL); + *(pChunkdata+pTempfield->iOffsetchunk) = iNum; + break; } + case 2 : { mng_uint16 iNum = mng_get_uint16 (pTempdata); + if ((iNum < pTempfield->iMinvalue) || (iNum > pTempfield->iMaxvalue)) + MNG_ERROR (pData, MNG_INVALIDFIELDVAL); + *((mng_uint16p)(pChunkdata+pTempfield->iOffsetchunk)) = iNum; + break; } + case 4 : { mng_uint32 iNum = mng_get_uint32 (pTempdata); + if ((iNum < pTempfield->iMinvalue) || + ((pTempfield->iFlags & MNG_FIELD_NOHIGHBIT) && (iNum & 0x80000000)) ) + MNG_ERROR (pData, MNG_INVALIDFIELDVAL); + *((mng_uint32p)(pChunkdata+pTempfield->iOffsetchunk)) = iNum; + break; } + } + + pTempdata += pTempfield->iLengthmax; + iTemplen -= pTempfield->iLengthmax; + + } else { /* not numeric so it's a bunch of bytes */ + + if (!pTempfield->iOffsetchunklen) /* big fat NONO */ + MNG_ERROR (pData, MNG_INTERNALERROR); + /* with terminating 0 ? */ + if (pTempfield->iFlags & MNG_FIELD_TERMINATOR) + { + mng_uint8p pWork = pTempdata; + while (*pWork) /* find the zero */ + pWork++; + iDatalen = (mng_uint32)(pWork - pTempdata); + } else { /* no terminator, so everything that's left ! */ + iDatalen = iTemplen; + } + + if ((pTempfield->iLengthmax) && (iDatalen > pTempfield->iLengthmax)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); +#if !defined(MNG_SKIPCHUNK_iCCP) || !defined(MNG_SKIPCHUNK_zTXt) || \ + !defined(MNG_SKIPCHUNK_iTXt) || defined(MNG_INCLUDE_MPNG_PROPOSAL) || \ + defined(MNG_INCLUDE_ANG_PROPOSAL) + /* needs decompression ? */ + if (pTempfield->iFlags & MNG_FIELD_DEFLATED) + { + mng_uint8p pBuf = 0; + mng_uint32 iBufsize = 0; + mng_uint32 iRealsize; + mng_ptr pWork; + + iRetcode = mng_inflate_buffer (pData, pTempdata, iDatalen, + &pBuf, &iBufsize, &iRealsize); + +#ifdef MNG_CHECK_BAD_ICCP /* Check for bad iCCP chunk */ + if ((iRetcode) && (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_iCCP)) + { + *((mng_ptr *)(pChunkdata+pTempfield->iOffsetchunk)) = MNG_NULL; + *((mng_uint32p)(pChunkdata+pTempfield->iOffsetchunklen)) = iDatalen; + } + else +#endif + { + if (iRetcode) + return iRetcode; + +#if defined(MNG_INCLUDE_MPNG_PROPOSAL) || defined(MNG_INCLUDE_ANG_PROPOSAL) + if ( (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_mpNG) || + (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_adAT) ) + { + MNG_ALLOC (pData, pWork, iRealsize); + } + else + { +#endif + /* don't forget to generate null terminator */ + MNG_ALLOC (pData, pWork, iRealsize+1); +#if defined(MNG_INCLUDE_MPNG_PROPOSAL) || defined(MNG_INCLUDE_ANG_PROPOSAL) + } +#endif + MNG_COPY (pWork, pBuf, iRealsize); + + *((mng_ptr *)(pChunkdata+pTempfield->iOffsetchunk)) = pWork; + *((mng_uint32p)(pChunkdata+pTempfield->iOffsetchunklen)) = iRealsize; + } + + if (pBuf) /* free the temporary buffer */ + MNG_FREEX (pData, pBuf, iBufsize); + + } else +#endif + { /* no decompression, so just copy */ + + mng_ptr pWork; + /* don't forget to generate null terminator */ + MNG_ALLOC (pData, pWork, iDatalen+1); + MNG_COPY (pWork, pTempdata, iDatalen); + + *((mng_ptr *)(pChunkdata+pTempfield->iOffsetchunk)) = pWork; + *((mng_uint32p)(pChunkdata+pTempfield->iOffsetchunklen)) = iDatalen; + } + + if (pTempfield->iFlags & MNG_FIELD_TERMINATOR) + iDatalen++; /* skip the terminating zero as well !!! */ + + iTemplen -= iDatalen; + pTempdata += iDatalen; + } + /* need to set an indicator ? */ + if (pTempfield->iOffsetchunkind) + *((mng_uint8p)(pChunkdata+pTempfield->iOffsetchunkind)) = MNG_TRUE; + } + } + + if (pTempfield->pSpecialfunc) /* special function required ? */ + { + iRetcode = pTempfield->pSpecialfunc(pData, *ppChunk, &iTemplen, &pTempdata); + if (iRetcode) /* on error bail out */ + return iRetcode; + } + + pTempfield++; /* Neeeeeeexxxtt */ + iFieldcount--; + } + + if (iTemplen) /* extra data ??? */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + while (iFieldcount) /* not enough data ??? */ + { + if (pTempfield->iFlags & MNG_FIELD_IFIMGTYPES) + bProcess = (mng_bool)(((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE0) && (iColortype == 0)) || + ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE2) && (iColortype == 2)) || + ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE3) && (iColortype == 3)) || + ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE4) && (iColortype == 4)) || + ((pTempfield->iFlags & MNG_FIELD_IFIMGTYPE6) && (iColortype == 6)) ); + else + bProcess = MNG_TRUE; + + if (bProcess) + { + if (!(pTempfield->iFlags & MNG_FIELD_OPTIONAL)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + if ((pTempfield->iFlags & MNG_FIELD_GROUPMASK) && + ((mng_uint16)(pTempfield->iFlags & MNG_FIELD_GROUPMASK) == iLastgroup)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + + pTempfield++; + iFieldcount--; + } + } + } + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +READ_CHUNK (mng_read_general) +{ + mng_retcode iRetcode = MNG_NOERROR; + mng_chunk_descp pDescr = ((mng_chunk_headerp)pHeader)->pChunkdescr; + mng_field_descp pField; + mng_uint16 iFields; + + if (!pDescr) /* this is a bad booboo !!! */ + MNG_ERROR (pData, MNG_INTERNALERROR); + + pField = pDescr->pFielddesc; + iFields = pDescr->iFielddesc; + /* check chunk against signature */ + if ((pDescr->eImgtype == mng_it_mng) && (pData->eSigtype != mng_it_mng)) + MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); + + if ((pDescr->eImgtype == mng_it_jng) && (pData->eSigtype == mng_it_png)) + MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); + /* empties allowed ? */ + if ((iRawlen == 0) && (!(pDescr->iAllowed & MNG_DESCR_EMPTY))) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((pData->eImagetype != mng_it_mng) || (!(pDescr->iAllowed & MNG_DESCR_GLOBAL))) + { /* *a* header required ? */ + if ((pDescr->iMusthaves & MNG_DESCR_GenHDR) && +#ifdef MNG_INCLUDE_JNG + (!pData->bHasIHDR) && (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + (!pData->bHasIHDR) && (!pData->bHasBASI) && (!pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pDescr->iMusthaves & MNG_DESCR_JngHDR) && + (!pData->bHasDHDR) && (!pData->bHasJHDR)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); +#endif + } + /* specific chunk pre-requisite ? */ + if (((pDescr->iMusthaves & MNG_DESCR_IHDR) && (!pData->bHasIHDR)) || +#ifdef MNG_INCLUDE_JNG + ((pDescr->iMusthaves & MNG_DESCR_JHDR) && (!pData->bHasJHDR)) || +#endif + ((pDescr->iMusthaves & MNG_DESCR_DHDR) && (!pData->bHasDHDR)) || + ((pDescr->iMusthaves & MNG_DESCR_LOOP) && (!pData->bHasLOOP)) || + ((pDescr->iMusthaves & MNG_DESCR_PLTE) && (!pData->bHasPLTE)) || + ((pDescr->iMusthaves & MNG_DESCR_MHDR) && (!pData->bHasMHDR)) || + ((pDescr->iMusthaves & MNG_DESCR_SAVE) && (!pData->bHasSAVE)) ) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* specific chunk undesired ? */ + if (((pDescr->iMustNOThaves & MNG_DESCR_NOIHDR) && (pData->bHasIHDR)) || + ((pDescr->iMustNOThaves & MNG_DESCR_NOBASI) && (pData->bHasBASI)) || + ((pDescr->iMustNOThaves & MNG_DESCR_NODHDR) && (pData->bHasDHDR)) || + ((pDescr->iMustNOThaves & MNG_DESCR_NOIDAT) && (pData->bHasIDAT)) || + ((pDescr->iMustNOThaves & MNG_DESCR_NOPLTE) && (pData->bHasPLTE)) || +#ifdef MNG_INCLUDE_JNG + ((pDescr->iMustNOThaves & MNG_DESCR_NOJHDR) && (pData->bHasJHDR)) || + ((pDescr->iMustNOThaves & MNG_DESCR_NOJDAT) && (pData->bHasJDAT)) || + ((pDescr->iMustNOThaves & MNG_DESCR_NOJDAA) && (pData->bHasJDAA)) || + ((pDescr->iMustNOThaves & MNG_DESCR_NOJSEP) && (pData->bHasJSEP)) || +#endif + ((pDescr->iMustNOThaves & MNG_DESCR_NOMHDR) && (pData->bHasMHDR)) || + ((pDescr->iMustNOThaves & MNG_DESCR_NOLOOP) && (pData->bHasLOOP)) || + ((pDescr->iMustNOThaves & MNG_DESCR_NOTERM) && (pData->bHasTERM)) || + ((pDescr->iMustNOThaves & MNG_DESCR_NOSAVE) && (pData->bHasSAVE)) ) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (pData->eSigtype == mng_it_mng) /* check global and embedded empty chunks */ + { +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + { + if ((iRawlen == 0) && (!(pDescr->iAllowed & MNG_DESCR_EMPTYEMBED))) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } else { + if ((iRawlen == 0) && (!(pDescr->iAllowed & MNG_DESCR_EMPTYGLOBAL))) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + } + + if (pDescr->pSpecialfunc) /* need special processing ? */ + { + iRetcode = create_chunk_storage (pData, pHeader, iRawlen, pRawdata, + pField, iFields, ppChunk, MNG_TRUE); + if (iRetcode) /* on error bail out */ + return iRetcode; + /* empty indicator ? */ + if ((!iRawlen) && (pDescr->iOffsetempty)) + *(((mng_uint8p)*ppChunk)+pDescr->iOffsetempty) = MNG_TRUE; + + iRetcode = pDescr->pSpecialfunc(pData, *ppChunk); + if (iRetcode) /* on error bail out */ + return iRetcode; + + if ((((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_IDAT) || + (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_JDAT) || + (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_JDAA) ) + { + iRetcode = ((mng_chunk_headerp)*ppChunk)->fCleanup (pData, *ppChunk); + if (iRetcode) /* on error bail out */ + return iRetcode; + *ppChunk = MNG_NULL; + } else { +#ifdef MNG_STORE_CHUNKS + if (!pData->bStorechunks) +#endif + { + iRetcode = ((mng_chunk_headerp)*ppChunk)->fCleanup (pData, *ppChunk); + if (iRetcode) /* on error bail out */ + return iRetcode; + *ppChunk = MNG_NULL; + } + } + } + +#ifdef MNG_SUPPORT_DISPLAY + if (iRawlen) + { +#ifdef MNG_OPTIMIZE_DISPLAYCALLS + pData->iRawlen = iRawlen; + pData->pRawdata = pRawdata; +#endif + + /* display processing */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_IDAT) + iRetcode = mng_process_display_idat (pData, iRawlen, pRawdata); +#ifdef MNG_INCLUDE_JNG + else + if (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_JDAT) + iRetcode = mng_process_display_jdat (pData, iRawlen, pRawdata); + else + if (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_JDAA) + iRetcode = mng_process_display_jdaa (pData, iRawlen, pRawdata); +#endif +#else + if (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_IDAT) + iRetcode = mng_process_display_idat (pData); +#ifdef MNG_INCLUDE_JNG + else + if (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_JDAT) + iRetcode = mng_process_display_jdat (pData); + else + if (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_JDAA) + iRetcode = mng_process_display_jdaa (pData); +#endif +#endif + + if (iRetcode) + return iRetcode; + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if ((pData->bStorechunks) && (!(*ppChunk))) + { + iRetcode = create_chunk_storage (pData, pHeader, iRawlen, pRawdata, + pField, iFields, ppChunk, MNG_FALSE); + if (iRetcode) /* on error bail out */ + return iRetcode; + /* empty indicator ? */ + if ((!iRawlen) && (pDescr->iOffsetempty)) + *(((mng_uint8p)*ppChunk)+pDescr->iOffsetempty) = MNG_TRUE; + } +#endif /* MNG_STORE_CHUNKS */ + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#endif /* MNG_OPTIMIZE_CHUNKREADER */ + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +READ_CHUNK (mng_read_ihdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_IHDR, MNG_LC_START); +#endif + + if (iRawlen != 13) /* length oke ? */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + /* only allowed inside PNG or MNG */ + if ((pData->eSigtype != mng_it_png) && (pData->eSigtype != mng_it_mng)) + MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); + /* sequence checks */ + if ((pData->eSigtype == mng_it_png) && (pData->iChunkseq > 1)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasIDAT) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasIDAT)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + pData->bHasIHDR = MNG_TRUE; /* indicate IHDR is present */ + /* and store interesting fields */ + if ((!pData->bHasDHDR) || (pData->iDeltatype == MNG_DELTATYPE_NOCHANGE)) + { + pData->iDatawidth = mng_get_uint32 (pRawdata); + pData->iDataheight = mng_get_uint32 (pRawdata+4); + } + + pData->iBitdepth = *(pRawdata+8); + pData->iColortype = *(pRawdata+9); + pData->iCompression = *(pRawdata+10); + pData->iFilter = *(pRawdata+11); + pData->iInterlace = *(pRawdata+12); + +#if defined(MNG_NO_1_2_4BIT_SUPPORT) || defined(MNG_NO_16BIT_SUPPORT) + pData->iPNGmult = 1; + pData->iPNGdepth = pData->iBitdepth; +#endif + +#ifdef MNG_NO_1_2_4BIT_SUPPORT + if (pData->iBitdepth < 8) + pData->iBitdepth = 8; +#endif + +#ifdef MNG_NO_16BIT_SUPPORT + if (pData->iBitdepth > 8) + { + pData->iBitdepth = 8; + pData->iPNGmult = 2; + } +#endif + + if ((pData->iBitdepth != 8) /* parameter validity checks */ +#ifndef MNG_NO_1_2_4BIT_SUPPORT + && (pData->iBitdepth != 1) && + (pData->iBitdepth != 2) && + (pData->iBitdepth != 4) +#endif +#ifndef MNG_NO_16BIT_SUPPORT + && (pData->iBitdepth != 16) +#endif + ) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if ((pData->iColortype != MNG_COLORTYPE_GRAY ) && + (pData->iColortype != MNG_COLORTYPE_RGB ) && + (pData->iColortype != MNG_COLORTYPE_INDEXED) && + (pData->iColortype != MNG_COLORTYPE_GRAYA ) && + (pData->iColortype != MNG_COLORTYPE_RGBA ) ) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + + if ((pData->iColortype == MNG_COLORTYPE_INDEXED) && (pData->iBitdepth > 8)) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if (((pData->iColortype == MNG_COLORTYPE_RGB ) || + (pData->iColortype == MNG_COLORTYPE_GRAYA ) || + (pData->iColortype == MNG_COLORTYPE_RGBA ) ) && + (pData->iBitdepth < 8 ) ) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if (pData->iCompression != MNG_COMPRESSION_DEFLATE) + MNG_ERROR (pData, MNG_INVALIDCOMPRESS); + +#if defined(FILTER192) || defined(FILTER193) + if ((pData->iFilter != MNG_FILTER_ADAPTIVE ) && +#if defined(FILTER192) && defined(FILTER193) + (pData->iFilter != MNG_FILTER_DIFFERING) && + (pData->iFilter != MNG_FILTER_NOFILTER ) ) +#else +#ifdef FILTER192 + (pData->iFilter != MNG_FILTER_DIFFERING) ) +#else + (pData->iFilter != MNG_FILTER_NOFILTER ) ) +#endif +#endif + MNG_ERROR (pData, MNG_INVALIDFILTER); +#else + if (pData->iFilter) + MNG_ERROR (pData, MNG_INVALIDFILTER); +#endif + + if ((pData->iInterlace != MNG_INTERLACE_NONE ) && + (pData->iInterlace != MNG_INTERLACE_ADAM7) ) + MNG_ERROR (pData, MNG_INVALIDINTERLACE); + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* check the colortype for delta-images ! */ + { + mng_imagedatap pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; + + if (pData->iColortype != pBuf->iColortype) + { + if ( ( (pData->iColortype != MNG_COLORTYPE_INDEXED) || + (pBuf->iColortype == MNG_COLORTYPE_GRAY ) ) && + ( (pData->iColortype != MNG_COLORTYPE_GRAY ) || + (pBuf->iColortype == MNG_COLORTYPE_INDEXED) ) ) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + } + } +#endif +#endif + + if (!pData->bHasheader) /* first chunk ? */ + { + pData->bHasheader = MNG_TRUE; /* we've got a header */ + pData->eImagetype = mng_it_png; /* then this must be a PNG */ + pData->iWidth = pData->iDatawidth; + pData->iHeight = pData->iDataheight; + /* predict alpha-depth ! */ + if ((pData->iColortype == MNG_COLORTYPE_GRAYA ) || + (pData->iColortype == MNG_COLORTYPE_RGBA ) ) + pData->iAlphadepth = pData->iBitdepth; + else + if (pData->iColortype == MNG_COLORTYPE_INDEXED) + pData->iAlphadepth = 8; /* worst case scenario */ + else + pData->iAlphadepth = 1; /* Possible tRNS cheap binary transparency */ + /* fits on maximum canvas ? */ + if ((pData->iWidth > pData->iMaxwidth) || (pData->iHeight > pData->iMaxheight)) + MNG_WARNING (pData, MNG_IMAGETOOLARGE); + +#if !defined(MNG_INCLUDE_MPNG_PROPOSAL) || !defined(MNG_SUPPORT_DISPLAY) + if (pData->fProcessheader) /* inform the app ? */ + if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) + MNG_ERROR (pData, MNG_APPMISCERROR); +#endif + } + + if (!pData->bHasDHDR) + pData->iImagelevel++; /* one level deeper */ + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode = mng_process_display_ihdr (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the fields */ + ((mng_ihdrp)*ppChunk)->iWidth = mng_get_uint32 (pRawdata); + ((mng_ihdrp)*ppChunk)->iHeight = mng_get_uint32 (pRawdata+4); + ((mng_ihdrp)*ppChunk)->iBitdepth = pData->iBitdepth; + ((mng_ihdrp)*ppChunk)->iColortype = pData->iColortype; + ((mng_ihdrp)*ppChunk)->iCompression = pData->iCompression; + ((mng_ihdrp)*ppChunk)->iFilter = pData->iFilter; + ((mng_ihdrp)*ppChunk)->iInterlace = pData->iInterlace; + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_IHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif /* MNG_OPTIMIZE_CHUNKREADER */ + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +READ_CHUNK (mng_read_plte) +{ +#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) + mng_uint32 iX; + mng_uint8p pRawdata2; +#endif +#ifdef MNG_SUPPORT_DISPLAY + mng_uint32 iRawlen2; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_PLTE, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIDAT) || (pData->bHasJHDR)) +#else + if (pData->bHasIDAT) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* multiple PLTE only inside BASI */ + if ((pData->bHasPLTE) && (!pData->bHasBASI)) + MNG_ERROR (pData, MNG_MULTIPLEERROR); + /* length must be multiple of 3 */ + if (((iRawlen % 3) != 0) || (iRawlen > 768)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + { /* only allowed for indexed-color or + rgb(a)-color! */ + if ((pData->iColortype != 2) && (pData->iColortype != 3) && (pData->iColortype != 6)) + MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); + /* empty only allowed if global present */ + if ((iRawlen == 0) && (!pData->bHasglobalPLTE)) + MNG_ERROR (pData, MNG_CANNOTBEEMPTY); + } + else + { + if (iRawlen == 0) /* cannot be empty as global! */ + MNG_ERROR (pData, MNG_CANNOTBEEMPTY); + } + + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + pData->bHasPLTE = MNG_TRUE; /* got it! */ + else + pData->bHasglobalPLTE = MNG_TRUE; + + pData->iPLTEcount = iRawlen / 3; + +#ifdef MNG_SUPPORT_DISPLAY + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + { + mng_imagep pImage; + mng_imagedatap pBuf; + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* processing delta-image ? */ + { /* store in object 0 !!! */ + pImage = (mng_imagep)pData->pObjzero; + pBuf = pImage->pImgbuf; + pBuf->bHasPLTE = MNG_TRUE; /* it's definitely got a PLTE now */ + pBuf->iPLTEcount = iRawlen / 3; /* this is the exact length */ + pRawdata2 = pRawdata; /* copy the entries */ + + for (iX = 0; iX < iRawlen / 3; iX++) + { + pBuf->aPLTEentries[iX].iRed = *pRawdata2; + pBuf->aPLTEentries[iX].iGreen = *(pRawdata2+1); + pBuf->aPLTEentries[iX].iBlue = *(pRawdata2+2); + + pRawdata2 += 3; + } + } + else +#endif + { /* get the current object */ + pImage = (mng_imagep)pData->pCurrentobj; + + if (!pImage) /* no object then dump it in obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + + pBuf = pImage->pImgbuf; /* address the object buffer */ + pBuf->bHasPLTE = MNG_TRUE; /* and tell it it's got a PLTE now */ + + if (!iRawlen) /* if empty, inherit from global */ + { + pBuf->iPLTEcount = pData->iGlobalPLTEcount; + MNG_COPY (pBuf->aPLTEentries, pData->aGlobalPLTEentries, + sizeof (pBuf->aPLTEentries)); + + if (pData->bHasglobalTRNS) /* also copy global tRNS ? */ + { /* indicate tRNS available */ + pBuf->bHasTRNS = MNG_TRUE; + + iRawlen2 = pData->iGlobalTRNSrawlen; + pRawdata2 = (mng_uint8p)(pData->aGlobalTRNSrawdata); + /* global length oke ? */ + if ((iRawlen2 == 0) || (iRawlen2 > pBuf->iPLTEcount)) + MNG_ERROR (pData, MNG_GLOBALLENGTHERR); + /* copy it */ + pBuf->iTRNScount = iRawlen2; + MNG_COPY (pBuf->aTRNSentries, pRawdata2, iRawlen2); + } + } + else + { /* store fields for future reference */ + pBuf->iPLTEcount = iRawlen / 3; + pRawdata2 = pRawdata; + + for (iX = 0; iX < pBuf->iPLTEcount; iX++) + { + pBuf->aPLTEentries[iX].iRed = *pRawdata2; + pBuf->aPLTEentries[iX].iGreen = *(pRawdata2+1); + pBuf->aPLTEentries[iX].iBlue = *(pRawdata2+2); + + pRawdata2 += 3; + } + } + } + } + else /* store as global */ + { + pData->iGlobalPLTEcount = iRawlen / 3; + pRawdata2 = pRawdata; + + for (iX = 0; iX < pData->iGlobalPLTEcount; iX++) + { + pData->aGlobalPLTEentries[iX].iRed = *pRawdata2; + pData->aGlobalPLTEentries[iX].iGreen = *(pRawdata2+1); + pData->aGlobalPLTEentries[iX].iBlue = *(pRawdata2+2); + + pRawdata2 += 3; + } + + { /* create an animation object */ + mng_retcode iRetcode = mng_create_ani_plte (pData, pData->iGlobalPLTEcount, + pData->aGlobalPLTEentries); + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_pltep)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + ((mng_pltep)*ppChunk)->iEntrycount = iRawlen / 3; + pRawdata2 = pRawdata; + + for (iX = 0; iX < ((mng_pltep)*ppChunk)->iEntrycount; iX++) + { + ((mng_pltep)*ppChunk)->aEntries[iX].iRed = *pRawdata2; + ((mng_pltep)*ppChunk)->aEntries[iX].iGreen = *(pRawdata2+1); + ((mng_pltep)*ppChunk)->aEntries[iX].iBlue = *(pRawdata2+2); + + pRawdata2 += 3; + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_PLTE, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif /* MNG_OPTIMIZE_CHUNKREADER */ + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +READ_CHUNK (mng_read_idat) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_IDAT, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_JNG /* sequence checks */ + if ((!pData->bHasIHDR) && (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasIHDR) && (!pData->bHasBASI) && (!pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasJHDR) && + (pData->iJHDRalphacompression != MNG_COMPRESSION_DEFLATE)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (pData->bHasJSEP) + MNG_ERROR (pData, MNG_SEQUENCEERROR); +#endif + /* not allowed for deltatype NO_CHANGE */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && ((pData->iDeltatype == MNG_DELTATYPE_NOCHANGE))) + MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); +#endif + /* can only be empty in BASI-block! */ + if ((iRawlen == 0) && (!pData->bHasBASI)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + /* indexed-color requires PLTE */ + if ((pData->bHasIHDR) && (pData->iColortype == 3) && (!pData->bHasPLTE)) + MNG_ERROR (pData, MNG_PLTEMISSING); + + pData->bHasIDAT = MNG_TRUE; /* got some IDAT now, don't we */ + +#ifdef MNG_SUPPORT_DISPLAY + if (iRawlen) + { /* display processing */ + mng_retcode iRetcode = mng_process_display_idat (pData, iRawlen, pRawdata); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_idatp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + ((mng_idatp)*ppChunk)->iDatasize = iRawlen; + + if (iRawlen != 0) /* is there any data ? */ + { + MNG_ALLOC (pData, ((mng_idatp)*ppChunk)->pData, iRawlen); + MNG_COPY (((mng_idatp)*ppChunk)->pData, pRawdata, iRawlen); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_IDAT, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +READ_CHUNK (mng_read_iend) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_IEND, MNG_LC_START); +#endif + + if (iRawlen > 0) /* must not contain data! */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_INCLUDE_JNG /* sequence checks */ + if ((!pData->bHasIHDR) && (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasIHDR) && (!pData->bHasBASI) && (!pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* IHDR-block requires IDAT */ + if ((pData->bHasIHDR) && (!pData->bHasIDAT)) + MNG_ERROR (pData, MNG_IDATMISSING); + + pData->iImagelevel--; /* one level up */ + +#ifdef MNG_SUPPORT_DISPLAY + { /* create an animation object */ + mng_retcode iRetcode = mng_create_ani_image (pData); + if (iRetcode) /* on error bail out */ + return iRetcode; + /* display processing */ + iRetcode = mng_process_display_iend (pData); + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_SUPPORT_DISPLAY + if (!pData->bTimerset) /* reset only if not broken !!! */ + { +#endif + /* IEND signals the end for most ... */ + pData->bHasIHDR = MNG_FALSE; + pData->bHasBASI = MNG_FALSE; + pData->bHasDHDR = MNG_FALSE; +#ifdef MNG_INCLUDE_JNG + pData->bHasJHDR = MNG_FALSE; + pData->bHasJSEP = MNG_FALSE; + pData->bHasJDAA = MNG_FALSE; + pData->bHasJDAT = MNG_FALSE; +#endif + pData->bHasPLTE = MNG_FALSE; + pData->bHasTRNS = MNG_FALSE; + pData->bHasGAMA = MNG_FALSE; + pData->bHasCHRM = MNG_FALSE; + pData->bHasSRGB = MNG_FALSE; + pData->bHasICCP = MNG_FALSE; + pData->bHasBKGD = MNG_FALSE; + pData->bHasIDAT = MNG_FALSE; +#ifdef MNG_SUPPORT_DISPLAY + } +#endif + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_IEND, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +READ_CHUNK (mng_read_trns) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_TRNS, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIDAT) || (pData->bHasJHDR)) +#else + if (pData->bHasIDAT) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* multiple tRNS only inside BASI */ + if ((pData->bHasTRNS) && (!pData->bHasBASI)) + MNG_ERROR (pData, MNG_MULTIPLEERROR); + + if (iRawlen > 256) /* it just can't be bigger than that! */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + { /* not allowed with full alpha-channel */ + if ((pData->iColortype == 4) || (pData->iColortype == 6)) + MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); + + if (iRawlen != 0) /* filled ? */ + { /* length checks */ + if ((pData->iColortype == 0) && (iRawlen != 2)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((pData->iColortype == 2) && (iRawlen != 6)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + if (pData->iColortype == 3) + { + mng_imagep pImage = (mng_imagep)pData->pCurrentobj; + mng_imagedatap pBuf; + + if (!pImage) /* no object then check obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + + pBuf = pImage->pImgbuf; /* address object buffer */ + + if (iRawlen > pBuf->iPLTEcount) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } +#endif + } + else /* if empty there must be global stuff! */ + { + if (!pData->bHasglobalTRNS) + MNG_ERROR (pData, MNG_CANNOTBEEMPTY); + } + } + + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + pData->bHasTRNS = MNG_TRUE; /* indicate tRNS available */ + else + pData->bHasglobalTRNS = MNG_TRUE; + +#ifdef MNG_SUPPORT_DISPLAY + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + { + mng_imagep pImage; + mng_imagedatap pBuf; + mng_uint8p pRawdata2; + mng_uint32 iRawlen2; + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* processing delta-image ? */ + { /* store in object 0 !!! */ + pImage = (mng_imagep)pData->pObjzero; + pBuf = pImage->pImgbuf; /* address object buffer */ + + switch (pData->iColortype) /* store fields for future reference */ + { + case 0: { /* gray */ +#if defined(MNG_NO_1_2_4BIT_SUPPORT) + mng_uint8 multiplier[]={0,255,85,0,17,0,0,0,1, + 0,0,0,0,0,0,0,1}; +#endif + pBuf->iTRNSgray = mng_get_uint16 (pRawdata); + pBuf->iTRNSred = 0; + pBuf->iTRNSgreen = 0; + pBuf->iTRNSblue = 0; + pBuf->iTRNScount = 0; +#if defined(MNG_NO_1_2_4BIT_SUPPORT) + pBuf->iTRNSgray *= multiplier[pData->iPNGdepth]; +#endif +#if defined(MNG_NO_16BIT_SUPPORT) + if (pData->iPNGmult == 2) + pBuf->iTRNSgray >>= 8; +#endif + break; + } + case 2: { /* rgb */ + pBuf->iTRNSgray = 0; + pBuf->iTRNSred = mng_get_uint16 (pRawdata); + pBuf->iTRNSgreen = mng_get_uint16 (pRawdata+2); + pBuf->iTRNSblue = mng_get_uint16 (pRawdata+4); + pBuf->iTRNScount = 0; +#if defined(MNG_NO_16BIT_SUPPORT) + if (pData->iPNGmult == 2) + { + pBuf->iTRNSred >>= 8; + pBuf->iTRNSgreen >>= 8; + pBuf->iTRNSblue >>= 8; + } +#endif + break; + } + case 3: { /* indexed */ + pBuf->iTRNSgray = 0; + pBuf->iTRNSred = 0; + pBuf->iTRNSgreen = 0; + pBuf->iTRNSblue = 0; + pBuf->iTRNScount = iRawlen; + MNG_COPY (pBuf->aTRNSentries, pRawdata, iRawlen); + break; + } + } + + pBuf->bHasTRNS = MNG_TRUE; /* tell it it's got a tRNS now */ + } + else +#endif + { /* address current object */ + pImage = (mng_imagep)pData->pCurrentobj; + + if (!pImage) /* no object then dump it in obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + + pBuf = pImage->pImgbuf; /* address object buffer */ + pBuf->bHasTRNS = MNG_TRUE; /* and tell it it's got a tRNS now */ + + if (iRawlen == 0) /* if empty, inherit from global */ + { + iRawlen2 = pData->iGlobalTRNSrawlen; + pRawdata2 = (mng_ptr)(pData->aGlobalTRNSrawdata); + /* global length oke ? */ + if ((pData->iColortype == 0) && (iRawlen2 != 2)) + MNG_ERROR (pData, MNG_GLOBALLENGTHERR); + + if ((pData->iColortype == 2) && (iRawlen2 != 6)) + MNG_ERROR (pData, MNG_GLOBALLENGTHERR); + + if ((pData->iColortype == 3) && ((iRawlen2 == 0) || (iRawlen2 > pBuf->iPLTEcount))) + MNG_ERROR (pData, MNG_GLOBALLENGTHERR); + } + else + { + iRawlen2 = iRawlen; + pRawdata2 = pRawdata; + } + + switch (pData->iColortype) /* store fields for future reference */ + { + case 0: { /* gray */ + pBuf->iTRNSgray = mng_get_uint16 (pRawdata2); + pBuf->iTRNSred = 0; + pBuf->iTRNSgreen = 0; + pBuf->iTRNSblue = 0; + pBuf->iTRNScount = 0; +#if defined(MNG_NO_16BIT_SUPPORT) + if (pData->iPNGmult == 2) + pBuf->iTRNSgray >>= 8; +#endif + break; + } + case 2: { /* rgb */ + pBuf->iTRNSgray = 0; + pBuf->iTRNSred = mng_get_uint16 (pRawdata2); + pBuf->iTRNSgreen = mng_get_uint16 (pRawdata2+2); + pBuf->iTRNSblue = mng_get_uint16 (pRawdata2+4); + pBuf->iTRNScount = 0; +#if defined(MNG_NO_16BIT_SUPPORT) + if (pData->iPNGmult == 2) + { + pBuf->iTRNSred >>= 8; + pBuf->iTRNSgreen >>= 8; + pBuf->iTRNSblue >>= 8; + } +#endif + break; + } + case 3: { /* indexed */ + pBuf->iTRNSgray = 0; + pBuf->iTRNSred = 0; + pBuf->iTRNSgreen = 0; + pBuf->iTRNSblue = 0; + pBuf->iTRNScount = iRawlen2; + MNG_COPY (pBuf->aTRNSentries, pRawdata2, iRawlen2); + break; + } + } + } + } + else /* store as global */ + { + pData->iGlobalTRNSrawlen = iRawlen; + MNG_COPY (pData->aGlobalTRNSrawdata, pRawdata, iRawlen); + + { /* create an animation object */ + mng_retcode iRetcode = mng_create_ani_trns (pData, pData->iGlobalTRNSrawlen, + pData->aGlobalTRNSrawdata); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + { /* not global! */ + ((mng_trnsp)*ppChunk)->bGlobal = MNG_FALSE; + ((mng_trnsp)*ppChunk)->iType = pData->iColortype; + + if (iRawlen == 0) /* if empty, indicate so */ + ((mng_trnsp)*ppChunk)->bEmpty = MNG_TRUE; + else + { + ((mng_trnsp)*ppChunk)->bEmpty = MNG_FALSE; + + switch (pData->iColortype) /* store fields */ + { + case 0: { /* gray */ + ((mng_trnsp)*ppChunk)->iGray = mng_get_uint16 (pRawdata); + break; + } + case 2: { /* rgb */ + ((mng_trnsp)*ppChunk)->iRed = mng_get_uint16 (pRawdata); + ((mng_trnsp)*ppChunk)->iGreen = mng_get_uint16 (pRawdata+2); + ((mng_trnsp)*ppChunk)->iBlue = mng_get_uint16 (pRawdata+4); + break; + } + case 3: { /* indexed */ + ((mng_trnsp)*ppChunk)->iCount = iRawlen; + MNG_COPY (((mng_trnsp)*ppChunk)->aEntries, pRawdata, iRawlen); + break; + } + } + } + } + else /* it's global! */ + { + ((mng_trnsp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + ((mng_trnsp)*ppChunk)->bGlobal = MNG_TRUE; + ((mng_trnsp)*ppChunk)->iType = 0; + ((mng_trnsp)*ppChunk)->iRawlen = iRawlen; + + MNG_COPY (((mng_trnsp)*ppChunk)->aRawdata, pRawdata, iRawlen); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_TRNS, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +READ_CHUNK (mng_read_gama) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_GAMA, MNG_LC_START); +#endif + /* sequence checks */ +#ifdef MNG_INCLUDE_JNG + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIDAT) || (pData->bHasPLTE) || (pData->bHasJDAT) || (pData->bHasJDAA)) +#else + if ((pData->bHasIDAT) || (pData->bHasPLTE)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + { /* length must be exactly 4 */ + if (iRawlen != 4) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + else + { /* length must be empty or exactly 4 */ + if ((iRawlen != 0) && (iRawlen != 4)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + pData->bHasGAMA = MNG_TRUE; /* indicate we've got it */ + else + pData->bHasglobalGAMA = (mng_bool)(iRawlen != 0); + +#ifdef MNG_SUPPORT_DISPLAY +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + { + mng_imagep pImage; + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* update delta image ? */ + { /* store in object 0 ! */ + pImage = (mng_imagep)pData->pObjzero; + /* store for color-processing routines */ + pImage->pImgbuf->iGamma = mng_get_uint32 (pRawdata); + pImage->pImgbuf->bHasGAMA = MNG_TRUE; + } + else +#endif + { + pImage = (mng_imagep)pData->pCurrentobj; + + if (!pImage) /* no object then dump it in obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + /* store for color-processing routines */ + pImage->pImgbuf->iGamma = mng_get_uint32 (pRawdata); + pImage->pImgbuf->bHasGAMA = MNG_TRUE; + } + } + else + { /* store as global */ + if (iRawlen != 0) + pData->iGlobalGamma = mng_get_uint32 (pRawdata); + + { /* create an animation object */ + mng_retcode iRetcode = mng_create_ani_gama (pData, (mng_bool)(iRawlen == 0), + pData->iGlobalGamma); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_gamap)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + + if (iRawlen) + ((mng_gamap)*ppChunk)->iGamma = mng_get_uint32 (pRawdata); + + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_GAMA, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_cHRM +READ_CHUNK (mng_read_chrm) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_CHRM, MNG_LC_START); +#endif + /* sequence checks */ +#ifdef MNG_INCLUDE_JNG + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIDAT) || (pData->bHasPLTE) || (pData->bHasJDAT) || (pData->bHasJDAA)) +#else + if ((pData->bHasIDAT) || (pData->bHasPLTE)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + { /* length must be exactly 32 */ + if (iRawlen != 32) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + else + { /* length must be empty or exactly 32 */ + if ((iRawlen != 0) && (iRawlen != 32)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + pData->bHasCHRM = MNG_TRUE; /* indicate we've got it */ + else + pData->bHasglobalCHRM = (mng_bool)(iRawlen != 0); + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_uint32 iWhitepointx, iWhitepointy; + mng_uint32 iPrimaryredx, iPrimaryredy; + mng_uint32 iPrimarygreenx, iPrimarygreeny; + mng_uint32 iPrimarybluex, iPrimarybluey; + + iWhitepointx = mng_get_uint32 (pRawdata); + iWhitepointy = mng_get_uint32 (pRawdata+4); + iPrimaryredx = mng_get_uint32 (pRawdata+8); + iPrimaryredy = mng_get_uint32 (pRawdata+12); + iPrimarygreenx = mng_get_uint32 (pRawdata+16); + iPrimarygreeny = mng_get_uint32 (pRawdata+20); + iPrimarybluex = mng_get_uint32 (pRawdata+24); + iPrimarybluey = mng_get_uint32 (pRawdata+28); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + { + mng_imagep pImage; + mng_imagedatap pBuf; + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* update delta image ? */ + { /* store it in object 0 ! */ + pImage = (mng_imagep)pData->pObjzero; + + pBuf = pImage->pImgbuf; /* address object buffer */ + pBuf->bHasCHRM = MNG_TRUE; /* and tell it it's got a CHRM now */ + /* store for color-processing routines */ + pBuf->iWhitepointx = iWhitepointx; + pBuf->iWhitepointy = iWhitepointy; + pBuf->iPrimaryredx = iPrimaryredx; + pBuf->iPrimaryredy = iPrimaryredy; + pBuf->iPrimarygreenx = iPrimarygreenx; + pBuf->iPrimarygreeny = iPrimarygreeny; + pBuf->iPrimarybluex = iPrimarybluex; + pBuf->iPrimarybluey = iPrimarybluey; + } + else +#endif + { + pImage = (mng_imagep)pData->pCurrentobj; + + if (!pImage) /* no object then dump it in obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + + pBuf = pImage->pImgbuf; /* address object buffer */ + pBuf->bHasCHRM = MNG_TRUE; /* and tell it it's got a CHRM now */ + /* store for color-processing routines */ + pBuf->iWhitepointx = iWhitepointx; + pBuf->iWhitepointy = iWhitepointy; + pBuf->iPrimaryredx = iPrimaryredx; + pBuf->iPrimaryredy = iPrimaryredy; + pBuf->iPrimarygreenx = iPrimarygreenx; + pBuf->iPrimarygreeny = iPrimarygreeny; + pBuf->iPrimarybluex = iPrimarybluex; + pBuf->iPrimarybluey = iPrimarybluey; + } + } + else + { /* store as global */ + if (iRawlen != 0) + { + pData->iGlobalWhitepointx = iWhitepointx; + pData->iGlobalWhitepointy = iWhitepointy; + pData->iGlobalPrimaryredx = iPrimaryredx; + pData->iGlobalPrimaryredy = iPrimaryredy; + pData->iGlobalPrimarygreenx = iPrimarygreenx; + pData->iGlobalPrimarygreeny = iPrimarygreeny; + pData->iGlobalPrimarybluex = iPrimarybluex; + pData->iGlobalPrimarybluey = iPrimarybluey; + } + + { /* create an animation object */ + mng_retcode iRetcode = mng_create_ani_chrm (pData, (mng_bool)(iRawlen == 0), + iWhitepointx, iWhitepointy, + iPrimaryredx, iPrimaryredy, + iPrimarygreenx, iPrimarygreeny, + iPrimarybluex, iPrimarybluey); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_chrmp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + + if (iRawlen) + { + ((mng_chrmp)*ppChunk)->iWhitepointx = mng_get_uint32 (pRawdata); + ((mng_chrmp)*ppChunk)->iWhitepointy = mng_get_uint32 (pRawdata+4); + ((mng_chrmp)*ppChunk)->iRedx = mng_get_uint32 (pRawdata+8); + ((mng_chrmp)*ppChunk)->iRedy = mng_get_uint32 (pRawdata+12); + ((mng_chrmp)*ppChunk)->iGreenx = mng_get_uint32 (pRawdata+16); + ((mng_chrmp)*ppChunk)->iGreeny = mng_get_uint32 (pRawdata+20); + ((mng_chrmp)*ppChunk)->iBluex = mng_get_uint32 (pRawdata+24); + ((mng_chrmp)*ppChunk)->iBluey = mng_get_uint32 (pRawdata+28); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_CHRM, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +READ_CHUNK (mng_read_srgb) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_SRGB, MNG_LC_START); +#endif + /* sequence checks */ +#ifdef MNG_INCLUDE_JNG + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIDAT) || (pData->bHasPLTE) || (pData->bHasJDAT) || (pData->bHasJDAA)) +#else + if ((pData->bHasIDAT) || (pData->bHasPLTE)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + { /* length must be exactly 1 */ + if (iRawlen != 1) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + else + { /* length must be empty or exactly 1 */ + if ((iRawlen != 0) && (iRawlen != 1)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + pData->bHasSRGB = MNG_TRUE; /* indicate we've got it */ + else + pData->bHasglobalSRGB = (mng_bool)(iRawlen != 0); + +#ifdef MNG_SUPPORT_DISPLAY +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + { + mng_imagep pImage; + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* update delta image ? */ + { /* store in object 0 ! */ + pImage = (mng_imagep)pData->pObjzero; + /* store for color-processing routines */ + pImage->pImgbuf->iRenderingintent = *pRawdata; + pImage->pImgbuf->bHasSRGB = MNG_TRUE; + } + else +#endif + { + pImage = (mng_imagep)pData->pCurrentobj; + + if (!pImage) /* no object then dump it in obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + /* store for color-processing routines */ + pImage->pImgbuf->iRenderingintent = *pRawdata; + pImage->pImgbuf->bHasSRGB = MNG_TRUE; + } + } + else + { /* store as global */ + if (iRawlen != 0) + pData->iGlobalRendintent = *pRawdata; + + { /* create an animation object */ + mng_retcode iRetcode = mng_create_ani_srgb (pData, (mng_bool)(iRawlen == 0), + pData->iGlobalRendintent); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_srgbp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + + if (iRawlen) + ((mng_srgbp)*ppChunk)->iRenderingintent = *pRawdata; + + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_SRGB, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_iCCP +READ_CHUNK (mng_read_iccp) +{ + mng_retcode iRetcode; + mng_uint8p pTemp; + mng_uint32 iCompressedsize; + mng_uint32 iProfilesize; + mng_uint32 iBufsize = 0; + mng_uint8p pBuf = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_ICCP, MNG_LC_START); +#endif + /* sequence checks */ +#ifdef MNG_INCLUDE_JNG + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIDAT) || (pData->bHasPLTE) || (pData->bHasJDAT) || (pData->bHasJDAA)) +#else + if ((pData->bHasIDAT) || (pData->bHasPLTE)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + { /* length must be at least 2 */ + if (iRawlen < 2) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + else + { /* length must be empty or at least 2 */ + if ((iRawlen != 0) && (iRawlen < 2)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + + pTemp = find_null (pRawdata); /* find null-separator */ + /* not found inside input-data ? */ + if ((pTemp - pRawdata) > (mng_int32)iRawlen) + MNG_ERROR (pData, MNG_NULLNOTFOUND); + /* determine size of compressed profile */ + iCompressedsize = (mng_uint32)(iRawlen - (pTemp - pRawdata) - 2); + /* decompress the profile */ + iRetcode = mng_inflate_buffer (pData, pTemp+2, iCompressedsize, + &pBuf, &iBufsize, &iProfilesize); + +#ifdef MNG_CHECK_BAD_ICCP /* Check for bad iCCP chunk */ + if ((iRetcode) && (!strncmp ((char *)pRawdata, "Photoshop ICC profile", 21))) + { + if (iRawlen == 2615) /* is it the sRGB profile ? */ + { + mng_chunk_header chunk_srgb = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_sRGB, mng_init_general, mng_free_general, mng_read_srgb, mng_write_srgb, mng_assign_general, 0, 0, sizeof(mng_srgb)}; +#else + {MNG_UINT_sRGB, mng_init_srgb, mng_free_srgb, mng_read_srgb, mng_write_srgb, mng_assign_srgb, 0, 0}; +#endif + /* pretend it's an sRGB chunk then ! */ + iRetcode = mng_read_srgb (pData, &chunk_srgb, 1, (mng_ptr)"0", ppChunk); + + if (iRetcode) /* on error bail out */ + { /* don't forget to drop the temp buffer */ + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + } + } + else + { +#endif /* MNG_CHECK_BAD_ICCP */ + + if (iRetcode) /* on error bail out */ + { /* don't forget to drop the temp buffer */ + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + pData->bHasICCP = MNG_TRUE; /* indicate we've got it */ + else + pData->bHasglobalICCP = (mng_bool)(iRawlen != 0); + +#ifdef MNG_SUPPORT_DISPLAY +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + { + mng_imagep pImage; + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* update delta image ? */ + { /* store in object 0 ! */ + pImage = (mng_imagep)pData->pObjzero; + + if (pImage->pImgbuf->pProfile) /* profile existed ? */ + MNG_FREEX (pData, pImage->pImgbuf->pProfile, pImage->pImgbuf->iProfilesize); + /* allocate a buffer & copy it */ + MNG_ALLOC (pData, pImage->pImgbuf->pProfile, iProfilesize); + MNG_COPY (pImage->pImgbuf->pProfile, pBuf, iProfilesize); + /* store its length as well */ + pImage->pImgbuf->iProfilesize = iProfilesize; + pImage->pImgbuf->bHasICCP = MNG_TRUE; + } + else +#endif + { + pImage = (mng_imagep)pData->pCurrentobj; + + if (!pImage) /* no object then dump it in obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + + if (pImage->pImgbuf->pProfile) /* profile existed ? */ + MNG_FREEX (pData, pImage->pImgbuf->pProfile, pImage->pImgbuf->iProfilesize); + /* allocate a buffer & copy it */ + MNG_ALLOC (pData, pImage->pImgbuf->pProfile, iProfilesize); + MNG_COPY (pImage->pImgbuf->pProfile, pBuf, iProfilesize); + /* store its length as well */ + pImage->pImgbuf->iProfilesize = iProfilesize; + pImage->pImgbuf->bHasICCP = MNG_TRUE; + } + } + else + { /* store as global */ + if (iRawlen == 0) /* empty chunk ? */ + { + if (pData->pGlobalProfile) /* did we have a global profile ? */ + MNG_FREEX (pData, pData->pGlobalProfile, pData->iGlobalProfilesize); + + pData->iGlobalProfilesize = 0; /* reset to null */ + pData->pGlobalProfile = MNG_NULL; + } + else + { /* allocate a global buffer & copy it */ + MNG_ALLOC (pData, pData->pGlobalProfile, iProfilesize); + MNG_COPY (pData->pGlobalProfile, pBuf, iProfilesize); + /* store its length as well */ + pData->iGlobalProfilesize = iProfilesize; + } + + /* create an animation object */ + iRetcode = mng_create_ani_iccp (pData, (mng_bool)(iRawlen == 0), + pData->iGlobalProfilesize, + pData->pGlobalProfile); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + { /* don't forget to drop the temp buffer */ + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + /* store the fields */ + ((mng_iccpp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + + if (iRawlen) /* not empty ? */ + { + if (!pBuf) /* hasn't been unpuzzled it yet ? */ + { /* find null-separator */ + pTemp = find_null (pRawdata); + /* not found inside input-data ? */ + if ((pTemp - pRawdata) > (mng_int32)iRawlen) + MNG_ERROR (pData, MNG_NULLNOTFOUND); + /* determine size of compressed profile */ + iCompressedsize = iRawlen - (pTemp - pRawdata) - 2; + /* decompress the profile */ + iRetcode = mng_inflate_buffer (pData, pTemp+2, iCompressedsize, + &pBuf, &iBufsize, &iProfilesize); + + if (iRetcode) /* on error bail out */ + { /* don't forget to drop the temp buffer */ + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + } + + ((mng_iccpp)*ppChunk)->iNamesize = (mng_uint32)(pTemp - pRawdata); + + if (((mng_iccpp)*ppChunk)->iNamesize) + { + MNG_ALLOC (pData, ((mng_iccpp)*ppChunk)->zName, + ((mng_iccpp)*ppChunk)->iNamesize + 1); + MNG_COPY (((mng_iccpp)*ppChunk)->zName, pRawdata, + ((mng_iccpp)*ppChunk)->iNamesize); + } + + ((mng_iccpp)*ppChunk)->iCompression = *(pTemp+1); + ((mng_iccpp)*ppChunk)->iProfilesize = iProfilesize; + + MNG_ALLOC (pData, ((mng_iccpp)*ppChunk)->pProfile, iProfilesize); + MNG_COPY (((mng_iccpp)*ppChunk)->pProfile, pBuf, iProfilesize); + } + } +#endif /* MNG_STORE_CHUNKS */ + + if (pBuf) /* free the temporary buffer */ + MNG_FREEX (pData, pBuf, iBufsize); + +#ifdef MNG_CHECK_BAD_ICCP + } +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_ICCP, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_tEXt +READ_CHUNK (mng_read_text) +{ + mng_uint32 iKeywordlen, iTextlen; + mng_pchar zKeyword, zText; + mng_uint8p pTemp; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_TEXT, MNG_LC_START); +#endif + /* sequence checks */ +#ifdef MNG_INCLUDE_JNG + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen < 2) /* length must be at least 2 */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + pTemp = find_null (pRawdata); /* find the null separator */ + /* not found inside input-data ? */ + if ((pTemp - pRawdata) > (mng_int32)iRawlen) + MNG_ERROR (pData, MNG_NULLNOTFOUND); + + if (pTemp == pRawdata) /* there must be at least 1 char for keyword */ + MNG_ERROR (pData, MNG_KEYWORDNULL); + + iKeywordlen = (mng_uint32)(pTemp - pRawdata); + iTextlen = iRawlen - iKeywordlen - 1; + + if (pData->fProcesstext) /* inform the application ? */ + { + mng_bool bOke; + + MNG_ALLOC (pData, zKeyword, iKeywordlen + 1); + MNG_COPY (zKeyword, pRawdata, iKeywordlen); + + MNG_ALLOCX (pData, zText, iTextlen + 1); + + if (!zText) /* on error bail out */ + { + MNG_FREEX (pData, zKeyword, iKeywordlen + 1); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + + if (iTextlen) + MNG_COPY (zText, pTemp+1, iTextlen); + + bOke = pData->fProcesstext ((mng_handle)pData, MNG_TYPE_TEXT, zKeyword, zText, 0, 0); + + MNG_FREEX (pData, zText, iTextlen + 1); + MNG_FREEX (pData, zKeyword, iKeywordlen + 1); + + if (!bOke) + MNG_ERROR (pData, MNG_APPMISCERROR); + + } + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_textp)*ppChunk)->iKeywordsize = iKeywordlen; + ((mng_textp)*ppChunk)->iTextsize = iTextlen; + + if (iKeywordlen) + { + MNG_ALLOC (pData, ((mng_textp)*ppChunk)->zKeyword, iKeywordlen+1); + MNG_COPY (((mng_textp)*ppChunk)->zKeyword, pRawdata, iKeywordlen); + } + + if (iTextlen) + { + MNG_ALLOC (pData, ((mng_textp)*ppChunk)->zText, iTextlen+1); + MNG_COPY (((mng_textp)*ppChunk)->zText, pTemp+1, iTextlen); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_TEXT, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_zTXt +READ_CHUNK (mng_read_ztxt) +{ + mng_retcode iRetcode; + mng_uint32 iKeywordlen, iTextlen; + mng_pchar zKeyword; + mng_uint8p pTemp; + mng_uint32 iCompressedsize; + mng_uint32 iBufsize; + mng_uint8p pBuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_ZTXT, MNG_LC_START); +#endif + /* sequence checks */ +#ifdef MNG_INCLUDE_JNG + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen < 3) /* length must be at least 3 */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + pTemp = find_null (pRawdata); /* find the null separator */ + /* not found inside input-data ? */ + if ((pTemp - pRawdata) > (mng_int32)iRawlen) + MNG_ERROR (pData, MNG_NULLNOTFOUND); + + if (pTemp == pRawdata) /* there must be at least 1 char for keyword */ + MNG_ERROR (pData, MNG_KEYWORDNULL); + + if (*(pTemp+1) != 0) /* only deflate compression-method allowed */ + MNG_ERROR (pData, MNG_INVALIDCOMPRESS); + + iKeywordlen = (mng_uint32)(pTemp - pRawdata); + iCompressedsize = (mng_uint32)(iRawlen - iKeywordlen - 2); + + zKeyword = 0; /* there's no keyword buffer yet */ + pBuf = 0; /* or a temporary buffer ! */ + + if (pData->fProcesstext) /* inform the application ? */ + { /* decompress the text */ + iRetcode = mng_inflate_buffer (pData, pTemp+2, iCompressedsize, + &pBuf, &iBufsize, &iTextlen); + + if (iRetcode) /* on error bail out */ + { /* don't forget to drop the temp buffers */ + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + + MNG_ALLOCX (pData, zKeyword, iKeywordlen+1); + + if (!zKeyword) /* on error bail out */ + { /* don't forget to drop the temp buffers */ + MNG_FREEX (pData, pBuf, iBufsize); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + + MNG_COPY (zKeyword, pRawdata, iKeywordlen); + + if (!pData->fProcesstext ((mng_handle)pData, MNG_TYPE_ZTXT, zKeyword, (mng_pchar)pBuf, 0, 0)) + { /* don't forget to drop the temp buffers */ + MNG_FREEX (pData, pBuf, iBufsize); + MNG_FREEX (pData, zKeyword, iKeywordlen+1); + MNG_ERROR (pData, MNG_APPMISCERROR); + } + } + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + { /* don't forget to drop the temp buffers */ + MNG_FREEX (pData, pBuf, iBufsize); + MNG_FREEX (pData, zKeyword, iKeywordlen+1); + return iRetcode; + } + /* store the fields */ + ((mng_ztxtp)*ppChunk)->iKeywordsize = iKeywordlen; + ((mng_ztxtp)*ppChunk)->iCompression = *(pTemp+1); + + if ((!pBuf) && (iCompressedsize)) /* did we not get a text-buffer yet ? */ + { /* decompress the text */ + iRetcode = mng_inflate_buffer (pData, pTemp+2, iCompressedsize, + &pBuf, &iBufsize, &iTextlen); + + if (iRetcode) /* on error bail out */ + { /* don't forget to drop the temp buffers */ + MNG_FREEX (pData, pBuf, iBufsize); + MNG_FREEX (pData, zKeyword, iKeywordlen+1); + return iRetcode; + } + } + + MNG_ALLOCX (pData, ((mng_ztxtp)*ppChunk)->zKeyword, iKeywordlen + 1); + /* on error bail out */ + if (!((mng_ztxtp)*ppChunk)->zKeyword) + { /* don't forget to drop the temp buffers */ + MNG_FREEX (pData, pBuf, iBufsize); + MNG_FREEX (pData, zKeyword, iKeywordlen+1); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + + MNG_COPY (((mng_ztxtp)*ppChunk)->zKeyword, pRawdata, iKeywordlen); + + ((mng_ztxtp)*ppChunk)->iTextsize = iTextlen; + + if (iCompressedsize) + { + MNG_ALLOCX (pData, ((mng_ztxtp)*ppChunk)->zText, iTextlen + 1); + /* on error bail out */ + if (!((mng_ztxtp)*ppChunk)->zText) + { /* don't forget to drop the temp buffers */ + MNG_FREEX (pData, pBuf, iBufsize); + MNG_FREEX (pData, zKeyword, iKeywordlen+1); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + + MNG_COPY (((mng_ztxtp)*ppChunk)->zText, pBuf, iTextlen); + } + } +#endif /* MNG_STORE_CHUNKS */ + + MNG_FREEX (pData, pBuf, iBufsize); /* free the temporary buffers */ + MNG_FREEX (pData, zKeyword, iKeywordlen+1); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_ZTXT, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_iTXt +READ_CHUNK (mng_read_itxt) +{ + mng_retcode iRetcode; + mng_uint32 iKeywordlen, iTextlen, iLanguagelen, iTranslationlen; + mng_pchar zKeyword, zLanguage, zTranslation; + mng_uint8p pNull1, pNull2, pNull3; + mng_uint32 iCompressedsize; + mng_uint8 iCompressionflag; + mng_uint32 iBufsize; + mng_uint8p pBuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_ITXT, MNG_LC_START); +#endif + /* sequence checks */ +#ifdef MNG_INCLUDE_JNG + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen < 6) /* length must be at least 6 */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + pNull1 = find_null (pRawdata); /* find the null separators */ + pNull2 = find_null (pNull1+3); + pNull3 = find_null (pNull2+1); + /* not found inside input-data ? */ + if (((pNull1 - pRawdata) > (mng_int32)iRawlen) || + ((pNull2 - pRawdata) > (mng_int32)iRawlen) || + ((pNull3 - pRawdata) > (mng_int32)iRawlen) ) + MNG_ERROR (pData, MNG_NULLNOTFOUND); + + if (pNull1 == pRawdata) /* there must be at least 1 char for keyword */ + MNG_ERROR (pData, MNG_KEYWORDNULL); + /* compression or not ? */ + if ((*(pNull1+1) != 0) && (*(pNull1+1) != 1)) + MNG_ERROR (pData, MNG_INVALIDCOMPRESS); + + if (*(pNull1+2) != 0) /* only deflate compression-method allowed */ + MNG_ERROR (pData, MNG_INVALIDCOMPRESS); + + iKeywordlen = (mng_uint32)(pNull1 - pRawdata); + iLanguagelen = (mng_uint32)(pNull2 - pNull1 - 3); + iTranslationlen = (mng_uint32)(pNull3 - pNull2 - 1); + iCompressedsize = (mng_uint32)(iRawlen - iKeywordlen - iLanguagelen - iTranslationlen - 5); + iCompressionflag = *(pNull1+1); + + zKeyword = 0; /* no buffers acquired yet */ + zLanguage = 0; + zTranslation = 0; + pBuf = 0; + iTextlen = 0; + + if (pData->fProcesstext) /* inform the application ? */ + { + if (iCompressionflag) /* decompress the text ? */ + { + iRetcode = mng_inflate_buffer (pData, pNull3+1, iCompressedsize, + &pBuf, &iBufsize, &iTextlen); + + if (iRetcode) /* on error bail out */ + { /* don't forget to drop the temp buffer */ + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + } + else + { + iTextlen = iCompressedsize; + iBufsize = iTextlen+1; /* plus 1 for terminator byte!!! */ + + MNG_ALLOC (pData, pBuf, iBufsize); + MNG_COPY (pBuf, pNull3+1, iTextlen); + } + + MNG_ALLOCX (pData, zKeyword, iKeywordlen + 1); + MNG_ALLOCX (pData, zLanguage, iLanguagelen + 1); + MNG_ALLOCX (pData, zTranslation, iTranslationlen + 1); + /* on error bail out */ + if ((!zKeyword) || (!zLanguage) || (!zTranslation)) + { /* don't forget to drop the temp buffers */ + MNG_FREEX (pData, zTranslation, iTranslationlen + 1); + MNG_FREEX (pData, zLanguage, iLanguagelen + 1); + MNG_FREEX (pData, zKeyword, iKeywordlen + 1); + MNG_FREEX (pData, pBuf, iBufsize); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + + MNG_COPY (zKeyword, pRawdata, iKeywordlen); + MNG_COPY (zLanguage, pNull1+3, iLanguagelen); + MNG_COPY (zTranslation, pNull2+1, iTranslationlen); + + if (!pData->fProcesstext ((mng_handle)pData, MNG_TYPE_ITXT, zKeyword, (mng_pchar)pBuf, + zLanguage, zTranslation)) + { /* don't forget to drop the temp buffers */ + MNG_FREEX (pData, zTranslation, iTranslationlen + 1); + MNG_FREEX (pData, zLanguage, iLanguagelen + 1); + MNG_FREEX (pData, zKeyword, iKeywordlen + 1); + MNG_FREEX (pData, pBuf, iBufsize); + + MNG_ERROR (pData, MNG_APPMISCERROR); + } + } + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + { /* don't forget to drop the temp buffers */ + MNG_FREEX (pData, zTranslation, iTranslationlen + 1); + MNG_FREEX (pData, zLanguage, iLanguagelen + 1); + MNG_FREEX (pData, zKeyword, iKeywordlen + 1); + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + /* store the fields */ + ((mng_itxtp)*ppChunk)->iKeywordsize = iKeywordlen; + ((mng_itxtp)*ppChunk)->iLanguagesize = iLanguagelen; + ((mng_itxtp)*ppChunk)->iTranslationsize = iTranslationlen; + ((mng_itxtp)*ppChunk)->iCompressionflag = *(pNull1+1); + ((mng_itxtp)*ppChunk)->iCompressionmethod = *(pNull1+2); + + if ((!pBuf) && (iCompressedsize)) /* did we not get a text-buffer yet ? */ + { + if (iCompressionflag) /* decompress the text ? */ + { + iRetcode = mng_inflate_buffer (pData, pNull3+1, iCompressedsize, + &pBuf, &iBufsize, &iTextlen); + + if (iRetcode) /* on error bail out */ + { /* don't forget to drop the temp buffers */ + MNG_FREEX (pData, zTranslation, iTranslationlen + 1); + MNG_FREEX (pData, zLanguage, iLanguagelen + 1); + MNG_FREEX (pData, zKeyword, iKeywordlen + 1); + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + } + else + { + iTextlen = iCompressedsize; + iBufsize = iTextlen+1; /* plus 1 for terminator byte!!! */ + + MNG_ALLOC (pData, pBuf, iBufsize); + MNG_COPY (pBuf, pNull3+1, iTextlen); + } + } + + MNG_ALLOCX (pData, ((mng_itxtp)*ppChunk)->zKeyword, iKeywordlen + 1); + MNG_ALLOCX (pData, ((mng_itxtp)*ppChunk)->zLanguage, iLanguagelen + 1); + MNG_ALLOCX (pData, ((mng_itxtp)*ppChunk)->zTranslation, iTranslationlen + 1); + /* on error bail out */ + if ((!((mng_itxtp)*ppChunk)->zKeyword ) || + (!((mng_itxtp)*ppChunk)->zLanguage ) || + (!((mng_itxtp)*ppChunk)->zTranslation) ) + { /* don't forget to drop the temp buffers */ + MNG_FREEX (pData, zTranslation, iTranslationlen + 1); + MNG_FREEX (pData, zLanguage, iLanguagelen + 1); + MNG_FREEX (pData, zKeyword, iKeywordlen + 1); + MNG_FREEX (pData, pBuf, iBufsize); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + + MNG_COPY (((mng_itxtp)*ppChunk)->zKeyword, pRawdata, iKeywordlen); + MNG_COPY (((mng_itxtp)*ppChunk)->zLanguage, pNull1+3, iLanguagelen); + MNG_COPY (((mng_itxtp)*ppChunk)->zTranslation, pNull2+1, iTranslationlen); + + ((mng_itxtp)*ppChunk)->iTextsize = iTextlen; + + if (iTextlen) + { + MNG_ALLOCX (pData, ((mng_itxtp)*ppChunk)->zText, iTextlen + 1); + + if (!((mng_itxtp)*ppChunk)->zText) + { /* don't forget to drop the temp buffers */ + MNG_FREEX (pData, zTranslation, iTranslationlen + 1); + MNG_FREEX (pData, zLanguage, iLanguagelen + 1); + MNG_FREEX (pData, zKeyword, iKeywordlen + 1); + MNG_FREEX (pData, pBuf, iBufsize); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + + MNG_COPY (((mng_itxtp)*ppChunk)->zText, pBuf, iTextlen); + } + } +#endif /* MNG_STORE_CHUNKS */ + /* free the temporary buffers */ + MNG_FREEX (pData, zTranslation, iTranslationlen + 1); + MNG_FREEX (pData, zLanguage, iLanguagelen + 1); + MNG_FREEX (pData, zKeyword, iKeywordlen + 1); + MNG_FREEX (pData, pBuf, iBufsize); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_ITXT, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_bKGD +READ_CHUNK (mng_read_bkgd) +{ +#ifdef MNG_SUPPORT_DISPLAY + mng_imagep pImage = (mng_imagep)pData->pCurrentobj; + mng_imagedatap pBuf; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_BKGD, MNG_LC_START); +#endif + /* sequence checks */ +#ifdef MNG_INCLUDE_JNG + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIDAT) || (pData->bHasJDAT) || (pData->bHasJDAA)) +#else + if (pData->bHasIDAT) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen > 6) /* it just can't be bigger than that! */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_INCLUDE_JNG /* length checks */ + if (pData->bHasJHDR) + { + if (((pData->iJHDRcolortype == 8) || (pData->iJHDRcolortype == 12)) && (iRawlen != 2)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if (((pData->iJHDRcolortype == 10) || (pData->iJHDRcolortype == 14)) && (iRawlen != 6)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + else +#endif /* MNG_INCLUDE_JNG */ + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + { + if (((pData->iColortype == 0) || (pData->iColortype == 4)) && (iRawlen != 2)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if (((pData->iColortype == 2) || (pData->iColortype == 6)) && (iRawlen != 6)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((pData->iColortype == 3) && (iRawlen != 1)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + else + { + if (iRawlen != 6) /* global is always 16-bit RGB ! */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + pData->bHasBKGD = MNG_TRUE; /* indicate bKGD available */ + else + pData->bHasglobalBKGD = (mng_bool)(iRawlen != 0); + +#ifdef MNG_SUPPORT_DISPLAY + if (!pImage) /* if no object dump it in obj 0 */ + pImage = (mng_imagep)pData->pObjzero; + + pBuf = pImage->pImgbuf; /* address object buffer */ + +#ifdef MNG_INCLUDE_JNG + if (pData->bHasJHDR) + { + pBuf->bHasBKGD = MNG_TRUE; /* tell the object it's got bKGD now */ + + switch (pData->iJHDRcolortype) /* store fields for future reference */ + { + case 8 : ; /* gray */ + case 12 : { /* graya */ + pBuf->iBKGDgray = mng_get_uint16 (pRawdata); + break; + } + case 10 : ; /* rgb */ + case 14 : { /* rgba */ + pBuf->iBKGDred = mng_get_uint16 (pRawdata); + pBuf->iBKGDgreen = mng_get_uint16 (pRawdata+2); + pBuf->iBKGDblue = mng_get_uint16 (pRawdata+4); + break; + } + } + } + else +#endif /* MNG_INCLUDE_JNG */ + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + { + pBuf->bHasBKGD = MNG_TRUE; /* tell the object it's got bKGD now */ + + switch (pData->iColortype) /* store fields for future reference */ + { + case 0 : ; /* gray */ + case 4 : { /* graya */ + pBuf->iBKGDgray = mng_get_uint16 (pRawdata); + break; + } + case 2 : ; /* rgb */ + case 6 : { /* rgba */ + pBuf->iBKGDred = mng_get_uint16 (pRawdata); + pBuf->iBKGDgreen = mng_get_uint16 (pRawdata+2); + pBuf->iBKGDblue = mng_get_uint16 (pRawdata+4); + break; + } + case 3 : { /* indexed */ + pBuf->iBKGDindex = *pRawdata; + break; + } + } + } + else /* store as global */ + { + if (iRawlen) + { + pData->iGlobalBKGDred = mng_get_uint16 (pRawdata); + pData->iGlobalBKGDgreen = mng_get_uint16 (pRawdata+2); + pData->iGlobalBKGDblue = mng_get_uint16 (pRawdata+4); + } + + { /* create an animation object */ + mng_retcode iRetcode = mng_create_ani_bkgd (pData, pData->iGlobalBKGDred, + pData->iGlobalBKGDgreen, + pData->iGlobalBKGDblue); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_bkgdp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + ((mng_bkgdp)*ppChunk)->iType = pData->iColortype; + + if (iRawlen) + { + switch (iRawlen) /* guess from length */ + { + case 1 : { /* indexed */ + ((mng_bkgdp)*ppChunk)->iType = 3; + ((mng_bkgdp)*ppChunk)->iIndex = *pRawdata; + break; + } + case 2 : { /* gray */ + ((mng_bkgdp)*ppChunk)->iType = 0; + ((mng_bkgdp)*ppChunk)->iGray = mng_get_uint16 (pRawdata); + break; + } + case 6 : { /* rgb */ + ((mng_bkgdp)*ppChunk)->iType = 2; + ((mng_bkgdp)*ppChunk)->iRed = mng_get_uint16 (pRawdata); + ((mng_bkgdp)*ppChunk)->iGreen = mng_get_uint16 (pRawdata+2); + ((mng_bkgdp)*ppChunk)->iBlue = mng_get_uint16 (pRawdata+4); + break; + } + } + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_BKGD, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_pHYs +READ_CHUNK (mng_read_phys) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_PHYS, MNG_LC_START); +#endif + /* sequence checks */ +#ifdef MNG_INCLUDE_JNG + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIDAT) || (pData->bHasJDAT) || (pData->bHasJDAA)) +#else + if (pData->bHasIDAT) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* it's 9 bytes or empty; no more, no less! */ + if ((iRawlen != 9) && (iRawlen != 0)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_physp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + + if (iRawlen) + { + ((mng_physp)*ppChunk)->iSizex = mng_get_uint32 (pRawdata); + ((mng_physp)*ppChunk)->iSizey = mng_get_uint32 (pRawdata+4); + ((mng_physp)*ppChunk)->iUnit = *(pRawdata+8); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_PHYS, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_sBIT +READ_CHUNK (mng_read_sbit) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_SBIT, MNG_LC_START); +#endif + /* sequence checks */ +#ifdef MNG_INCLUDE_JNG + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasPLTE) || (pData->bHasIDAT) || (pData->bHasJDAT) || (pData->bHasJDAA)) +#else + if ((pData->bHasPLTE) || (pData->bHasIDAT)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen > 4) /* it just can't be bigger than that! */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_INCLUDE_JNG /* length checks */ + if (pData->bHasJHDR) + { + if ((pData->iJHDRcolortype == 8) && (iRawlen != 1)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((pData->iJHDRcolortype == 10) && (iRawlen != 3)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((pData->iJHDRcolortype == 12) && (iRawlen != 2)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((pData->iJHDRcolortype == 14) && (iRawlen != 4)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + else +#endif /* MNG_INCLUDE_JNG */ + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) + { + if ((pData->iColortype == 0) && (iRawlen != 1)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((pData->iColortype == 2) && (iRawlen != 3)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((pData->iColortype == 3) && (iRawlen != 3)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((pData->iColortype == 4) && (iRawlen != 2)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((pData->iColortype == 6) && (iRawlen != 4)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + else + { /* global = empty or RGBA */ + if ((iRawlen != 0) && (iRawlen != 4)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_sbitp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + + if (iRawlen) + { +#ifdef MNG_INCLUDE_JNG + if (pData->bHasJHDR) + ((mng_sbitp)*ppChunk)->iType = pData->iJHDRcolortype; + else +#endif + if (pData->bHasIHDR) + ((mng_sbitp)*ppChunk)->iType = pData->iColortype; + else /* global ! */ + ((mng_sbitp)*ppChunk)->iType = 6; + + if (iRawlen > 0) + ((mng_sbitp)*ppChunk)->aBits [0] = *pRawdata; + if (iRawlen > 1) + ((mng_sbitp)*ppChunk)->aBits [1] = *(pRawdata+1); + if (iRawlen > 2) + ((mng_sbitp)*ppChunk)->aBits [2] = *(pRawdata+2); + if (iRawlen > 3) + ((mng_sbitp)*ppChunk)->aBits [3] = *(pRawdata+3); + + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_SBIT, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_sPLT +READ_CHUNK (mng_read_splt) +{ + mng_uint8p pTemp; + mng_uint32 iNamelen; + mng_uint8 iSampledepth; + mng_uint32 iRemain; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_SPLT, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (pData->bHasIDAT) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen) + { + pTemp = find_null (pRawdata); /* find null-separator */ + /* not found inside input-data ? */ + if ((pTemp - pRawdata) > (mng_int32)iRawlen) + MNG_ERROR (pData, MNG_NULLNOTFOUND); + + iNamelen = (mng_uint32)(pTemp - pRawdata); + iSampledepth = *(pTemp+1); + iRemain = (iRawlen - 2 - iNamelen); + + if ((iSampledepth != 1) && (iSampledepth != 2)) + MNG_ERROR (pData, MNG_INVSAMPLEDEPTH); + /* check remaining length */ + if ( ((iSampledepth == 1) && (iRemain % 6 != 0)) || + ((iSampledepth == 2) && (iRemain % 10 != 0)) ) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + } + else + { + pTemp = MNG_NULL; + iNamelen = 0; + iSampledepth = 0; + iRemain = 0; + } + +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_spltp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + + if (iRawlen) + { + ((mng_spltp)*ppChunk)->iNamesize = iNamelen; + ((mng_spltp)*ppChunk)->iSampledepth = iSampledepth; + + if (iSampledepth == 1) + ((mng_spltp)*ppChunk)->iEntrycount = iRemain / 6; + else + ((mng_spltp)*ppChunk)->iEntrycount = iRemain / 10; + + if (iNamelen) + { + MNG_ALLOC (pData, ((mng_spltp)*ppChunk)->zName, iNamelen+1); + MNG_COPY (((mng_spltp)*ppChunk)->zName, pRawdata, iNamelen); + } + + if (iRemain) + { + MNG_ALLOC (pData, ((mng_spltp)*ppChunk)->pEntries, iRemain); + MNG_COPY (((mng_spltp)*ppChunk)->pEntries, pTemp+2, iRemain); + } + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_SPLT, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_hIST +READ_CHUNK (mng_read_hist) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_HIST, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasIHDR) && (!pData->bHasBASI) && (!pData->bHasDHDR) ) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if ((!pData->bHasPLTE) || (pData->bHasIDAT)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* length oke ? */ + if ( ((iRawlen & 0x01) != 0) || ((iRawlen >> 1) != pData->iPLTEcount) ) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { + mng_uint32 iX; + /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_histp)*ppChunk)->iEntrycount = iRawlen >> 1; + + for (iX = 0; iX < (iRawlen >> 1); iX++) + { + ((mng_histp)*ppChunk)->aEntries [iX] = mng_get_uint16 (pRawdata); + pRawdata += 2; + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_HIST, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_tIME +READ_CHUNK (mng_read_time) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_TIME, MNG_LC_START); +#endif + /* sequence checks */ +#ifdef MNG_INCLUDE_JNG + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen != 7) /* length must be exactly 7 */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +/* if (pData->fProcesstime) */ /* inform the application ? */ +/* { + + pData->fProcesstime ((mng_handle)pData, ); + } */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_timep)*ppChunk)->iYear = mng_get_uint16 (pRawdata); + ((mng_timep)*ppChunk)->iMonth = *(pRawdata+2); + ((mng_timep)*ppChunk)->iDay = *(pRawdata+3); + ((mng_timep)*ppChunk)->iHour = *(pRawdata+4); + ((mng_timep)*ppChunk)->iMinute = *(pRawdata+5); + ((mng_timep)*ppChunk)->iSecond = *(pRawdata+6); + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_TIME, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +READ_CHUNK (mng_read_mhdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_MHDR, MNG_LC_START); +#endif + + if (pData->eSigtype != mng_it_mng) /* sequence checks */ + MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); + + if (pData->bHasheader) /* can only be the first chunk! */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* correct length ? */ +#ifndef MNG_NO_OLD_VERSIONS + if ((iRawlen != 28) && (iRawlen != 12)) +#else + if ((iRawlen != 28)) +#endif + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + pData->bHasMHDR = MNG_TRUE; /* oh boy, a real MNG */ + pData->bHasheader = MNG_TRUE; /* we've got a header */ + pData->eImagetype = mng_it_mng; /* fill header fields */ + pData->iWidth = mng_get_uint32 (pRawdata); + pData->iHeight = mng_get_uint32 (pRawdata+4); + pData->iTicks = mng_get_uint32 (pRawdata+8); + +#ifndef MNG_NO_OLD_VERSIONS + if (iRawlen == 28) /* proper MHDR ? */ + { +#endif + pData->iLayercount = mng_get_uint32 (pRawdata+12); + pData->iFramecount = mng_get_uint32 (pRawdata+16); + pData->iPlaytime = mng_get_uint32 (pRawdata+20); + pData->iSimplicity = mng_get_uint32 (pRawdata+24); + +#ifndef MNG_NO_OLD_VERSIONS + pData->bPreDraft48 = MNG_FALSE; + } + else /* probably pre-draft48 then */ + { + pData->iLayercount = 0; + pData->iFramecount = 0; + pData->iPlaytime = 0; + pData->iSimplicity = 0; + + pData->bPreDraft48 = MNG_TRUE; + } +#endif + /* predict alpha-depth */ + if ((pData->iSimplicity & 0x00000001) == 0) +#ifndef MNG_NO_16BIT_SUPPORT + pData->iAlphadepth = 16; /* no indicators = assume the worst */ +#else + pData->iAlphadepth = 8; /* anything else = assume the worst */ +#endif + else + if ((pData->iSimplicity & 0x00000008) == 0) + pData->iAlphadepth = 0; /* no transparency at all */ + else + if ((pData->iSimplicity & 0x00000140) == 0x00000040) + pData->iAlphadepth = 1; /* no semi-transparency guaranteed */ + else +#ifndef MNG_NO_16BIT_SUPPORT + pData->iAlphadepth = 16; /* anything else = assume the worst */ +#else + pData->iAlphadepth = 8; /* anything else = assume the worst */ +#endif + +#ifdef MNG_INCLUDE_JNG /* can we handle the complexity ? */ + if (pData->iSimplicity & 0x0000FC00) +#else + if (pData->iSimplicity & 0x0000FC10) +#endif + MNG_ERROR (pData, MNG_MNGTOOCOMPLEX); + /* fits on maximum canvas ? */ + if ((pData->iWidth > pData->iMaxwidth) || (pData->iHeight > pData->iMaxheight)) + MNG_WARNING (pData, MNG_IMAGETOOLARGE); + + if (pData->fProcessheader) /* inform the app ? */ + if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) + MNG_ERROR (pData, MNG_APPMISCERROR); + + pData->iImagelevel++; /* one level deeper */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_mhdrp)*ppChunk)->iWidth = pData->iWidth; + ((mng_mhdrp)*ppChunk)->iHeight = pData->iHeight; + ((mng_mhdrp)*ppChunk)->iTicks = pData->iTicks; + ((mng_mhdrp)*ppChunk)->iLayercount = pData->iLayercount; + ((mng_mhdrp)*ppChunk)->iFramecount = pData->iFramecount; + ((mng_mhdrp)*ppChunk)->iPlaytime = pData->iPlaytime; + ((mng_mhdrp)*ppChunk)->iSimplicity = pData->iSimplicity; + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_MHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +READ_CHUNK (mng_read_mend) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_MEND, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen > 0) /* must not contain data! */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { /* do something */ + mng_retcode iRetcode = mng_process_display_mend (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + if (!pData->iTotalframes) /* save totals */ + pData->iTotalframes = pData->iFrameseq; + if (!pData->iTotallayers) + pData->iTotallayers = pData->iLayerseq; + if (!pData->iTotalplaytime) + pData->iTotalplaytime = pData->iFrametime; + } +#endif /* MNG_SUPPORT_DISPLAY */ + + pData->bHasMHDR = MNG_FALSE; /* end of the line, bro! */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_MEND, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_LOOP +READ_CHUNK (mng_read_loop) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_LOOP, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (!pData->bCacheplayback) /* must store playback info to work!! */ + MNG_ERROR (pData, MNG_LOOPWITHCACHEOFF); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen >= 5) /* length checks */ + { + if (iRawlen >= 6) + { + if ((iRawlen - 6) % 4 != 0) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_uint8 iLevel; + mng_uint32 iRepeat; + mng_uint8 iTermination = 0; + mng_uint32 iItermin = 1; + mng_uint32 iItermax = 0x7fffffffL; + mng_retcode iRetcode; + + pData->bHasLOOP = MNG_TRUE; /* indicate we're inside a loop */ + + iLevel = *pRawdata; /* determine the fields for processing */ + +#ifndef MNG_NO_OLD_VERSIONS + if (pData->bPreDraft48) + { + iTermination = *(pRawdata+1); + + iRepeat = mng_get_uint32 (pRawdata+2); + } + else +#endif + iRepeat = mng_get_uint32 (pRawdata+1); + + if (iRawlen >= 6) + { +#ifndef MNG_NO_OLD_VERSIONS + if (!pData->bPreDraft48) +#endif + iTermination = *(pRawdata+5); + + if (iRawlen >= 10) + { + iItermin = mng_get_uint32 (pRawdata+6); + + if (iRawlen >= 14) + { + iItermax = mng_get_uint32 (pRawdata+10); + + /* TODO: process signals */ + + } + } + } + /* create the LOOP ani-object */ + iRetcode = mng_create_ani_loop (pData, iLevel, iRepeat, iTermination, + iItermin, iItermax, 0, 0); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* skip till matching ENDL if iteration=0 */ + if ((!pData->bSkipping) && (iRepeat == 0)) + pData->bSkipping = MNG_TRUE; + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + if (iRawlen >= 5) /* store the fields */ + { + ((mng_loopp)*ppChunk)->iLevel = *pRawdata; + +#ifndef MNG_NO_OLD_VERSIONS + if (pData->bPreDraft48) + { + ((mng_loopp)*ppChunk)->iTermination = *(pRawdata+1); + ((mng_loopp)*ppChunk)->iRepeat = mng_get_uint32 (pRawdata+2); + } + else +#endif + { + ((mng_loopp)*ppChunk)->iRepeat = mng_get_uint32 (pRawdata+1); + } + + if (iRawlen >= 6) + { +#ifndef MNG_NO_OLD_VERSIONS + if (!pData->bPreDraft48) +#endif + ((mng_loopp)*ppChunk)->iTermination = *(pRawdata+5); + + if (iRawlen >= 10) + { + ((mng_loopp)*ppChunk)->iItermin = mng_get_uint32 (pRawdata+6); + +#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED + if (iRawlen >= 14) + { + ((mng_loopp)*ppChunk)->iItermax = mng_get_uint32 (pRawdata+10); + ((mng_loopp)*ppChunk)->iCount = (iRawlen - 14) / 4; + + if (((mng_loopp)*ppChunk)->iCount) + { + MNG_ALLOC (pData, ((mng_loopp)*ppChunk)->pSignals, + ((mng_loopp)*ppChunk)->iCount << 2); + +#ifndef MNG_BIGENDIAN_SUPPORTED + { + mng_uint32 iX; + mng_uint8p pIn = pRawdata + 14; + mng_uint32p pOut = (mng_uint32p)((mng_loopp)*ppChunk)->pSignals; + + for (iX = 0; iX < ((mng_loopp)*ppChunk)->iCount; iX++) + { + *pOut++ = mng_get_uint32 (pIn); + pIn += 4; + } + } +#else + MNG_COPY (((mng_loopp)*ppChunk)->pSignals, pRawdata + 14, + ((mng_loopp)*ppChunk)->iCount << 2); +#endif /* !MNG_BIGENDIAN_SUPPORTED */ + } + } +#endif + } + } + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_LOOP, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_LOOP +READ_CHUNK (mng_read_endl) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_ENDL, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen != 1) /* length must be exactly 1 */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + if (pData->bHasLOOP) /* are we really processing a loop ? */ + { + mng_uint8 iLevel = *pRawdata; /* get the nest level */ + /* create an ENDL animation object */ + mng_retcode iRetcode = mng_create_ani_endl (pData, iLevel); + + if (iRetcode) /* on error bail out */ + return iRetcode; + +/* { + mng_ani_endlp pENDL = (mng_ani_endlp)pData->pLastaniobj; + + iRetcode = pENDL->sHeader.fProcess (pData, pENDL); + + if (iRetcode) + return iRetcode; + } */ + } + else + MNG_ERROR (pData, MNG_NOMATCHINGLOOP); + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_endlp)*ppChunk)->iLevel = *pRawdata; + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_ENDL, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_DEFI +READ_CHUNK (mng_read_defi) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_DEFI, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* check the length */ + if ((iRawlen != 2) && (iRawlen != 3) && (iRawlen != 4) && + (iRawlen != 12) && (iRawlen != 28)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode; + + pData->iDEFIobjectid = mng_get_uint16 (pRawdata); + + if (iRawlen > 2) + { + pData->bDEFIhasdonotshow = MNG_TRUE; + pData->iDEFIdonotshow = *(pRawdata+2); + } + else + { + pData->bDEFIhasdonotshow = MNG_FALSE; + pData->iDEFIdonotshow = 0; + } + + if (iRawlen > 3) + { + pData->bDEFIhasconcrete = MNG_TRUE; + pData->iDEFIconcrete = *(pRawdata+3); + } + else + { + pData->bDEFIhasconcrete = MNG_FALSE; + pData->iDEFIconcrete = 0; + } + + if (iRawlen > 4) + { + pData->bDEFIhasloca = MNG_TRUE; + pData->iDEFIlocax = mng_get_int32 (pRawdata+4); + pData->iDEFIlocay = mng_get_int32 (pRawdata+8); + } + else + { + pData->bDEFIhasloca = MNG_FALSE; + pData->iDEFIlocax = 0; + pData->iDEFIlocay = 0; + } + + if (iRawlen > 12) + { + pData->bDEFIhasclip = MNG_TRUE; + pData->iDEFIclipl = mng_get_int32 (pRawdata+12); + pData->iDEFIclipr = mng_get_int32 (pRawdata+16); + pData->iDEFIclipt = mng_get_int32 (pRawdata+20); + pData->iDEFIclipb = mng_get_int32 (pRawdata+24); + } + else + { + pData->bDEFIhasclip = MNG_FALSE; + pData->iDEFIclipl = 0; + pData->iDEFIclipr = 0; + pData->iDEFIclipt = 0; + pData->iDEFIclipb = 0; + } + /* create an animation object */ + iRetcode = mng_create_ani_defi (pData); + + if (!iRetcode) /* do display processing */ + iRetcode = mng_process_display_defi (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_defip)*ppChunk)->iObjectid = mng_get_uint16 (pRawdata); + + if (iRawlen > 2) + { + ((mng_defip)*ppChunk)->bHasdonotshow = MNG_TRUE; + ((mng_defip)*ppChunk)->iDonotshow = *(pRawdata+2); + } + else + ((mng_defip)*ppChunk)->bHasdonotshow = MNG_FALSE; + + if (iRawlen > 3) + { + ((mng_defip)*ppChunk)->bHasconcrete = MNG_TRUE; + ((mng_defip)*ppChunk)->iConcrete = *(pRawdata+3); + } + else + ((mng_defip)*ppChunk)->bHasconcrete = MNG_FALSE; + + if (iRawlen > 4) + { + ((mng_defip)*ppChunk)->bHasloca = MNG_TRUE; + ((mng_defip)*ppChunk)->iXlocation = mng_get_int32 (pRawdata+4); + ((mng_defip)*ppChunk)->iYlocation = mng_get_int32 (pRawdata+8); + } + else + ((mng_defip)*ppChunk)->bHasloca = MNG_FALSE; + + if (iRawlen > 12) + { + ((mng_defip)*ppChunk)->bHasclip = MNG_TRUE; + ((mng_defip)*ppChunk)->iLeftcb = mng_get_int32 (pRawdata+12); + ((mng_defip)*ppChunk)->iRightcb = mng_get_int32 (pRawdata+16); + ((mng_defip)*ppChunk)->iTopcb = mng_get_int32 (pRawdata+20); + ((mng_defip)*ppChunk)->iBottomcb = mng_get_int32 (pRawdata+24); + } + else + ((mng_defip)*ppChunk)->bHasclip = MNG_FALSE; + + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_DEFI, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_BASI +READ_CHUNK (mng_read_basi) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_BASI, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* check the length */ + if ((iRawlen != 13) && (iRawlen != 19) && (iRawlen != 21) && (iRawlen != 22)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + pData->bHasBASI = MNG_TRUE; /* inside a BASI-IEND block now */ + /* store interesting fields */ + pData->iDatawidth = mng_get_uint32 (pRawdata); + pData->iDataheight = mng_get_uint32 (pRawdata+4); + pData->iBitdepth = *(pRawdata+8); + pData->iColortype = *(pRawdata+9); + pData->iCompression = *(pRawdata+10); + pData->iFilter = *(pRawdata+11); + pData->iInterlace = *(pRawdata+12); + + +#if defined(MNG_NO_1_2_4BIT_SUPPORT) || defined(MNG_NO_16BIT_SUPPORT) + pData->iPNGmult = 1; + pData->iPNGdepth = pData->iBitdepth; +#endif + +#ifdef MNG_NO_1_2_4BIT_SUPPORT + if (pData->iBitdepth < 8) + pData->iBitdepth = 8; +#endif +#ifdef MNG_NO_16BIT_SUPPORT + if (pData->iBitdepth > 8) + { + pData->iBitdepth = 8; + pData->iPNGmult = 2; + } +#endif + + if ((pData->iBitdepth != 8) /* parameter validity checks */ +#ifndef MNG_NO_1_2_4BIT_SUPPORT + && (pData->iBitdepth != 1) && + (pData->iBitdepth != 2) && + (pData->iBitdepth != 4) +#endif +#ifndef MNG_NO_16BIT_SUPPORT + && (pData->iBitdepth != 16) +#endif + ) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if ((pData->iColortype != MNG_COLORTYPE_GRAY ) && + (pData->iColortype != MNG_COLORTYPE_RGB ) && + (pData->iColortype != MNG_COLORTYPE_INDEXED) && + (pData->iColortype != MNG_COLORTYPE_GRAYA ) && + (pData->iColortype != MNG_COLORTYPE_RGBA ) ) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + + if ((pData->iColortype == MNG_COLORTYPE_INDEXED) && (pData->iBitdepth > 8)) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if (((pData->iColortype == MNG_COLORTYPE_RGB ) || + (pData->iColortype == MNG_COLORTYPE_GRAYA ) || + (pData->iColortype == MNG_COLORTYPE_RGBA ) ) && + (pData->iBitdepth < 8 ) ) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if (pData->iCompression != MNG_COMPRESSION_DEFLATE) + MNG_ERROR (pData, MNG_INVALIDCOMPRESS); + +#if defined(FILTER192) || defined(FILTER193) + if ((pData->iFilter != MNG_FILTER_ADAPTIVE ) && +#if defined(FILTER192) && defined(FILTER193) + (pData->iFilter != MNG_FILTER_DIFFERING) && + (pData->iFilter != MNG_FILTER_NOFILTER ) ) +#else +#ifdef FILTER192 + (pData->iFilter != MNG_FILTER_DIFFERING) ) +#else + (pData->iFilter != MNG_FILTER_NOFILTER ) ) +#endif +#endif + MNG_ERROR (pData, MNG_INVALIDFILTER); +#else + if (pData->iFilter) + MNG_ERROR (pData, MNG_INVALIDFILTER); +#endif + + if ((pData->iInterlace != MNG_INTERLACE_NONE ) && + (pData->iInterlace != MNG_INTERLACE_ADAM7) ) + MNG_ERROR (pData, MNG_INVALIDINTERLACE); + + pData->iImagelevel++; /* one level deeper */ + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_uint16 iRed = 0; + mng_uint16 iGreen = 0; + mng_uint16 iBlue = 0; + mng_bool bHasalpha = MNG_FALSE; + mng_uint16 iAlpha = 0xFFFF; + mng_uint8 iViewable = 0; + mng_retcode iRetcode; + + if (iRawlen > 13) /* get remaining fields, if any */ + { + iRed = mng_get_uint16 (pRawdata+13); + iGreen = mng_get_uint16 (pRawdata+15); + iBlue = mng_get_uint16 (pRawdata+17); + } + + if (iRawlen > 19) + { + bHasalpha = MNG_TRUE; + iAlpha = mng_get_uint16 (pRawdata+19); + } + + if (iRawlen > 21) + iViewable = *(pRawdata+21); + /* create an animation object */ + iRetcode = mng_create_ani_basi (pData, iRed, iGreen, iBlue, + bHasalpha, iAlpha, iViewable); + +/* if (!iRetcode) + iRetcode = mng_process_display_basi (pData, iRed, iGreen, iBlue, + bHasalpha, iAlpha, iViewable); */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_basip)*ppChunk)->iWidth = mng_get_uint32 (pRawdata); + ((mng_basip)*ppChunk)->iHeight = mng_get_uint32 (pRawdata+4); +#ifdef MNG_NO_16BIT_SUPPORT + if (*(pRawdata+8) > 8) + ((mng_basip)*ppChunk)->iBitdepth = 8; + else +#endif + ((mng_basip)*ppChunk)->iBitdepth = *(pRawdata+8); + ((mng_basip)*ppChunk)->iColortype = *(pRawdata+9); + ((mng_basip)*ppChunk)->iCompression = *(pRawdata+10); + ((mng_basip)*ppChunk)->iFilter = *(pRawdata+11); + ((mng_basip)*ppChunk)->iInterlace = *(pRawdata+12); + + if (iRawlen > 13) + { + ((mng_basip)*ppChunk)->iRed = mng_get_uint16 (pRawdata+13); + ((mng_basip)*ppChunk)->iGreen = mng_get_uint16 (pRawdata+15); + ((mng_basip)*ppChunk)->iBlue = mng_get_uint16 (pRawdata+17); + } + + if (iRawlen > 19) + ((mng_basip)*ppChunk)->iAlpha = mng_get_uint16 (pRawdata+19); + + if (iRawlen > 21) + ((mng_basip)*ppChunk)->iViewable = *(pRawdata+21); + + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_BASI, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_CLON +READ_CHUNK (mng_read_clon) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_CLON, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* check the length */ + if ((iRawlen != 4) && (iRawlen != 5) && (iRawlen != 6) && + (iRawlen != 7) && (iRawlen != 16)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_uint16 iSourceid, iCloneid; + mng_uint8 iClonetype = 0; + mng_bool bHasdonotshow = MNG_FALSE; + mng_uint8 iDonotshow = 0; + mng_uint8 iConcrete = 0; + mng_bool bHasloca = MNG_FALSE; + mng_uint8 iLocationtype = 0; + mng_int32 iLocationx = 0; + mng_int32 iLocationy = 0; + mng_retcode iRetcode; + + iSourceid = mng_get_uint16 (pRawdata); + iCloneid = mng_get_uint16 (pRawdata+2); + + if (iRawlen > 4) + iClonetype = *(pRawdata+4); + + if (iRawlen > 5) + { + bHasdonotshow = MNG_TRUE; + iDonotshow = *(pRawdata+5); + } + + if (iRawlen > 6) + iConcrete = *(pRawdata+6); + + if (iRawlen > 7) + { + bHasloca = MNG_TRUE; + iLocationtype = *(pRawdata+7); + iLocationx = mng_get_int32 (pRawdata+8); + iLocationy = mng_get_int32 (pRawdata+12); + } + + iRetcode = mng_create_ani_clon (pData, iSourceid, iCloneid, iClonetype, + bHasdonotshow, iDonotshow, iConcrete, + bHasloca, iLocationtype, iLocationx, iLocationy); + +/* if (!iRetcode) + iRetcode = mng_process_display_clon (pData, iSourceid, iCloneid, iClonetype, + bHasdonotshow, iDonotshow, iConcrete, + bHasloca, iLocationtype, iLocationx, + iLocationy); */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_clonp)*ppChunk)->iSourceid = mng_get_uint16 (pRawdata); + ((mng_clonp)*ppChunk)->iCloneid = mng_get_uint16 (pRawdata+2); + + if (iRawlen > 4) + ((mng_clonp)*ppChunk)->iClonetype = *(pRawdata+4); + + if (iRawlen > 5) + ((mng_clonp)*ppChunk)->iDonotshow = *(pRawdata+5); + + if (iRawlen > 6) + ((mng_clonp)*ppChunk)->iConcrete = *(pRawdata+6); + + if (iRawlen > 7) + { + ((mng_clonp)*ppChunk)->bHasloca = MNG_TRUE; + ((mng_clonp)*ppChunk)->iLocationtype = *(pRawdata+7); + ((mng_clonp)*ppChunk)->iLocationx = mng_get_int32 (pRawdata+8); + ((mng_clonp)*ppChunk)->iLocationy = mng_get_int32 (pRawdata+12); + } + else + { + ((mng_clonp)*ppChunk)->bHasloca = MNG_FALSE; + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_CLON, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_PAST +READ_CHUNK (mng_read_past) +{ +#if defined(MNG_STORE_CHUNKS) || defined(MNG_SUPPORT_DISPLAY) + mng_retcode iRetcode; + mng_uint16 iTargetid; + mng_uint8 iTargettype; + mng_int32 iTargetx; + mng_int32 iTargety; + mng_uint32 iCount; + mng_uint32 iSize; + mng_ptr pSources; + mng_uint32 iX; + mng_past_sourcep pSource; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_PAST, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + /* check the length */ + if ((iRawlen < 41) || (((iRawlen - 11) % 30) != 0)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#if defined(MNG_STORE_CHUNKS) || defined(MNG_SUPPORT_DISPLAY) + iTargetid = mng_get_uint16 (pRawdata); + iTargettype = *(pRawdata+2); + iTargetx = mng_get_int32 (pRawdata+3); + iTargety = mng_get_int32 (pRawdata+7); + iCount = ((iRawlen - 11) / 30); /* how many entries again? */ + iSize = iCount * sizeof (mng_past_source); + + pRawdata += 11; + /* get a buffer for all the source blocks */ + MNG_ALLOC (pData, pSources, iSize); + + pSource = (mng_past_sourcep)pSources; + + for (iX = 0; iX < iCount; iX++) /* now copy the source blocks */ + { + pSource->iSourceid = mng_get_uint16 (pRawdata); + pSource->iComposition = *(pRawdata+2); + pSource->iOrientation = *(pRawdata+3); + pSource->iOffsettype = *(pRawdata+4); + pSource->iOffsetx = mng_get_int32 (pRawdata+5); + pSource->iOffsety = mng_get_int32 (pRawdata+9); + pSource->iBoundarytype = *(pRawdata+13); + pSource->iBoundaryl = mng_get_int32 (pRawdata+14); + pSource->iBoundaryr = mng_get_int32 (pRawdata+18); + pSource->iBoundaryt = mng_get_int32 (pRawdata+22); + pSource->iBoundaryb = mng_get_int32 (pRawdata+26); + + pSource++; + pRawdata += 30; + } +#endif + +#ifdef MNG_SUPPORT_DISPLAY + { /* create playback object */ + iRetcode = mng_create_ani_past (pData, iTargetid, iTargettype, iTargetx, + iTargety, iCount, pSources); + +/* if (!iRetcode) + iRetcode = mng_process_display_past (pData, iTargetid, iTargettype, iTargetx, + iTargety, iCount, pSources); */ + + if (iRetcode) /* on error bail out */ + { + MNG_FREEX (pData, pSources, iSize); + return iRetcode; + } + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + { + MNG_FREEX (pData, pSources, iSize); + return iRetcode; + } + /* store the fields */ + ((mng_pastp)*ppChunk)->iDestid = iTargetid; + ((mng_pastp)*ppChunk)->iTargettype = iTargettype; + ((mng_pastp)*ppChunk)->iTargetx = iTargetx; + ((mng_pastp)*ppChunk)->iTargety = iTargety; + ((mng_pastp)*ppChunk)->iCount = iCount; + /* get a buffer & copy the source blocks */ + MNG_ALLOC (pData, ((mng_pastp)*ppChunk)->pSources, iSize); + MNG_COPY (((mng_pastp)*ppChunk)->pSources, pSources, iSize); + } +#endif /* MNG_STORE_CHUNKS */ + +#if defined(MNG_STORE_CHUNKS) || defined(MNG_SUPPORT_DISPLAY) + /* free the source block buffer */ + MNG_FREEX (pData, pSources, iSize); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_PAST, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_DISC +READ_CHUNK (mng_read_disc) +{ +#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) + mng_uint32 iCount; + mng_uint16p pIds = MNG_NULL; + mng_retcode iRetcode; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_DISC, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if ((iRawlen % 2) != 0) /* check the length */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) + iCount = (iRawlen / sizeof (mng_uint16)); + + if (iCount) + { + MNG_ALLOC (pData, pIds, iRawlen); + +#ifndef MNG_BIGENDIAN_SUPPORTED + { + mng_uint32 iX; + mng_uint8p pIn = pRawdata; + mng_uint16p pOut = pIds; + + for (iX = 0; iX < iCount; iX++) + { + *pOut++ = mng_get_uint16 (pIn); + pIn += 2; + } + } +#else + MNG_COPY (pIds, pRawdata, iRawlen); +#endif /* !MNG_BIGENDIAN_SUPPORTED */ + } +#endif + +#ifdef MNG_SUPPORT_DISPLAY + { /* create playback object */ + iRetcode = mng_create_ani_disc (pData, iCount, pIds); + +/* if (!iRetcode) + iRetcode = mng_process_display_disc (pData, iCount, pIds); */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_discp)*ppChunk)->iCount = iCount; + + if (iRawlen) + { + MNG_ALLOC (pData, ((mng_discp)*ppChunk)->pObjectids, iRawlen); + MNG_COPY (((mng_discp)*ppChunk)->pObjectids, pIds, iRawlen); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) + if (iRawlen) + MNG_FREEX (pData, pIds, iRawlen); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_DISC, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_BACK +READ_CHUNK (mng_read_back) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_BACK, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* check the length */ + if ((iRawlen != 6) && (iRawlen != 7) && (iRawlen != 9) && (iRawlen != 10)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode; + /* retrieve the fields */ + pData->bHasBACK = MNG_TRUE; + pData->iBACKred = mng_get_uint16 (pRawdata); + pData->iBACKgreen = mng_get_uint16 (pRawdata+2); + pData->iBACKblue = mng_get_uint16 (pRawdata+4); + + if (iRawlen > 6) + pData->iBACKmandatory = *(pRawdata+6); + else + pData->iBACKmandatory = 0; + + if (iRawlen > 7) + pData->iBACKimageid = mng_get_uint16 (pRawdata+7); + else + pData->iBACKimageid = 0; + + if (iRawlen > 9) + pData->iBACKtile = *(pRawdata+9); + else + pData->iBACKtile = 0; + + iRetcode = mng_create_ani_back (pData, pData->iBACKred, pData->iBACKgreen, + pData->iBACKblue, pData->iBACKmandatory, + pData->iBACKimageid, pData->iBACKtile); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_backp)*ppChunk)->iRed = mng_get_uint16 (pRawdata); + ((mng_backp)*ppChunk)->iGreen = mng_get_uint16 (pRawdata+2); + ((mng_backp)*ppChunk)->iBlue = mng_get_uint16 (pRawdata+4); + + if (iRawlen > 6) + ((mng_backp)*ppChunk)->iMandatory = *(pRawdata+6); + + if (iRawlen > 7) + ((mng_backp)*ppChunk)->iImageid = mng_get_uint16 (pRawdata+7); + + if (iRawlen > 9) + ((mng_backp)*ppChunk)->iTile = *(pRawdata+9); + + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_BACK, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_FRAM +READ_CHUNK (mng_read_fram) +{ + mng_uint8p pTemp; +#ifdef MNG_STORE_CHUNKS + mng_uint32 iNamelen; +#endif + mng_uint32 iRemain; + mng_uint32 iRequired = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_FRAM, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen <= 1) /* only framing-mode ? */ + { +#ifdef MNG_STORE_CHUNKS + iNamelen = 0; /* indicate so */ +#endif + iRemain = 0; + pTemp = MNG_NULL; + } + else + { + pTemp = find_null (pRawdata+1); /* find null-separator */ + /* not found inside input-data ? */ + if ((pTemp - pRawdata) > (mng_int32)iRawlen) + pTemp = pRawdata + iRawlen; /* than remainder is name */ + +#ifdef MNG_STORE_CHUNKS + iNamelen = (mng_uint32)((pTemp - pRawdata) - 1); +#endif + iRemain = (mng_uint32)(iRawlen - (pTemp - pRawdata)); + + if (iRemain) /* if there is remaining data it's less 1 byte */ + iRemain--; + + if ((iRemain) && (iRemain < 4)) /* remains must be empty or at least 4 bytes */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if (iRemain) + { + iRequired = 4; /* calculate and check required remaining length */ + + if (*(pTemp+1)) { iRequired += 4; } + if (*(pTemp+2)) { iRequired += 4; } + if (*(pTemp+3)) { iRequired += 17; } + + if (*(pTemp+4)) + { + if ((iRemain - iRequired) % 4 != 0) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + else + { + if (iRemain != iRequired) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + } + } + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_uint8p pWork = pTemp; + mng_uint8 iFramemode = 0; + mng_uint8 iChangedelay = 0; + mng_uint32 iDelay = 0; + mng_uint8 iChangetimeout = 0; + mng_uint32 iTimeout = 0; + mng_uint8 iChangeclipping = 0; + mng_uint8 iCliptype = 0; + mng_int32 iClipl = 0; + mng_int32 iClipr = 0; + mng_int32 iClipt = 0; + mng_int32 iClipb = 0; + mng_retcode iRetcode; + + if (iRawlen) /* any data specified ? */ + { + if (*(pRawdata)) /* save the new framing mode ? */ + { + iFramemode = *(pRawdata); + +#ifndef MNG_NO_OLD_VERSIONS + if (pData->bPreDraft48) /* old style input-stream ? */ + { + switch (iFramemode) + { + case 0: { break; } + case 1: { iFramemode = 3; break; } + case 2: { iFramemode = 4; break; } + case 3: { iFramemode = 1; break; } + case 4: { iFramemode = 1; break; } + case 5: { iFramemode = 2; break; } + default: { iFramemode = 1; break; } + } + } +#endif + } + + if (iRemain) + { + iChangedelay = *(pWork+1); + iChangetimeout = *(pWork+2); + iChangeclipping = *(pWork+3); + pWork += 5; + + if (iChangedelay) /* delay changed ? */ + { + iDelay = mng_get_uint32 (pWork); + pWork += 4; + } + + if (iChangetimeout) /* timeout changed ? */ + { + iTimeout = mng_get_uint32 (pWork); + pWork += 4; + } + + if (iChangeclipping) /* clipping changed ? */ + { + iCliptype = *pWork; + iClipl = mng_get_int32 (pWork+1); + iClipr = mng_get_int32 (pWork+5); + iClipt = mng_get_int32 (pWork+9); + iClipb = mng_get_int32 (pWork+13); + } + } + } + + iRetcode = mng_create_ani_fram (pData, iFramemode, iChangedelay, iDelay, + iChangetimeout, iTimeout, + iChangeclipping, iCliptype, + iClipl, iClipr, iClipt, iClipb); + +/* if (!iRetcode) + iRetcode = mng_process_display_fram (pData, iFramemode, iChangedelay, iDelay, + iChangetimeout, iTimeout, + iChangeclipping, iCliptype, + iClipl, iClipr, iClipt, iClipb); */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_framp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + + if (iRawlen) + { + mng_uint8 iFramemode = *(pRawdata); + +#ifndef MNG_NO_OLD_VERSIONS + if (pData->bPreDraft48) /* old style input-stream ? */ + { + switch (iFramemode) + { + case 1: { iFramemode = 3; break; } + case 2: { iFramemode = 4; break; } + case 3: { iFramemode = 5; break; } /* TODO: provision for mode=5 ??? */ + case 4: { iFramemode = 1; break; } + case 5: { iFramemode = 2; break; } + default: { iFramemode = 1; break; } + } + } +#endif + + ((mng_framp)*ppChunk)->iMode = iFramemode; + ((mng_framp)*ppChunk)->iNamesize = iNamelen; + + if (iNamelen) + { + MNG_ALLOC (pData, ((mng_framp)*ppChunk)->zName, iNamelen+1); + MNG_COPY (((mng_framp)*ppChunk)->zName, pRawdata+1, iNamelen); + } + + if (iRemain) + { + ((mng_framp)*ppChunk)->iChangedelay = *(pTemp+1); + ((mng_framp)*ppChunk)->iChangetimeout = *(pTemp+2); + ((mng_framp)*ppChunk)->iChangeclipping = *(pTemp+3); + ((mng_framp)*ppChunk)->iChangesyncid = *(pTemp+4); + + pTemp += 5; + + if (((mng_framp)*ppChunk)->iChangedelay) + { + ((mng_framp)*ppChunk)->iDelay = mng_get_uint32 (pTemp); + pTemp += 4; + } + + if (((mng_framp)*ppChunk)->iChangetimeout) + { + ((mng_framp)*ppChunk)->iTimeout = mng_get_uint32 (pTemp); + pTemp += 4; + } + + if (((mng_framp)*ppChunk)->iChangeclipping) + { + ((mng_framp)*ppChunk)->iBoundarytype = *pTemp; + ((mng_framp)*ppChunk)->iBoundaryl = mng_get_int32 (pTemp+1); + ((mng_framp)*ppChunk)->iBoundaryr = mng_get_int32 (pTemp+5); + ((mng_framp)*ppChunk)->iBoundaryt = mng_get_int32 (pTemp+9); + ((mng_framp)*ppChunk)->iBoundaryb = mng_get_int32 (pTemp+13); + pTemp += 17; + } + + if (((mng_framp)*ppChunk)->iChangesyncid) + { + ((mng_framp)*ppChunk)->iCount = (iRemain - iRequired) / 4; + + if (((mng_framp)*ppChunk)->iCount) + { + MNG_ALLOC (pData, ((mng_framp)*ppChunk)->pSyncids, + ((mng_framp)*ppChunk)->iCount * 4); + +#ifndef MNG_BIGENDIAN_SUPPORTED + { + mng_uint32 iX; + mng_uint32p pOut = ((mng_framp)*ppChunk)->pSyncids; + + for (iX = 0; iX < ((mng_framp)*ppChunk)->iCount; iX++) + { + *pOut++ = mng_get_uint32 (pTemp); + pTemp += 4; + } + } +#else + MNG_COPY (((mng_framp)*ppChunk)->pSyncids, pTemp, + ((mng_framp)*ppChunk)->iCount * 4); +#endif /* !MNG_BIGENDIAN_SUPPORTED */ + } + } + } + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_FRAM, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_MOVE +READ_CHUNK (mng_read_move) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_MOVE, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen != 13) /* check the length */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode; + /* create a MOVE animation object */ + iRetcode = mng_create_ani_move (pData, mng_get_uint16 (pRawdata), + mng_get_uint16 (pRawdata+2), + *(pRawdata+4), + mng_get_int32 (pRawdata+5), + mng_get_int32 (pRawdata+9)); + +/* if (!iRetcode) + iRetcode = mng_process_display_move (pData, + mng_get_uint16 (pRawdata), + mng_get_uint16 (pRawdata+2), + *(pRawdata+4), + mng_get_int32 (pRawdata+5), + mng_get_int32 (pRawdata+9)); */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_movep)*ppChunk)->iFirstid = mng_get_uint16 (pRawdata); + ((mng_movep)*ppChunk)->iLastid = mng_get_uint16 (pRawdata+2); + ((mng_movep)*ppChunk)->iMovetype = *(pRawdata+4); + ((mng_movep)*ppChunk)->iMovex = mng_get_int32 (pRawdata+5); + ((mng_movep)*ppChunk)->iMovey = mng_get_int32 (pRawdata+9); + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_MOVE, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_CLIP +READ_CHUNK (mng_read_clip) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_CLIP, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen != 21) /* check the length */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode; + /* create a CLIP animation object */ + iRetcode = mng_create_ani_clip (pData, mng_get_uint16 (pRawdata), + mng_get_uint16 (pRawdata+2), + *(pRawdata+4), + mng_get_int32 (pRawdata+5), + mng_get_int32 (pRawdata+9), + mng_get_int32 (pRawdata+13), + mng_get_int32 (pRawdata+17)); + +/* if (!iRetcode) + iRetcode = mng_process_display_clip (pData, + mng_get_uint16 (pRawdata), + mng_get_uint16 (pRawdata+2), + *(pRawdata+4), + mng_get_int32 (pRawdata+5), + mng_get_int32 (pRawdata+9), + mng_get_int32 (pRawdata+13), + mng_get_int32 (pRawdata+17)); */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_clipp)*ppChunk)->iFirstid = mng_get_uint16 (pRawdata); + ((mng_clipp)*ppChunk)->iLastid = mng_get_uint16 (pRawdata+2); + ((mng_clipp)*ppChunk)->iCliptype = *(pRawdata+4); + ((mng_clipp)*ppChunk)->iClipl = mng_get_int32 (pRawdata+5); + ((mng_clipp)*ppChunk)->iClipr = mng_get_int32 (pRawdata+9); + ((mng_clipp)*ppChunk)->iClipt = mng_get_int32 (pRawdata+13); + ((mng_clipp)*ppChunk)->iClipb = mng_get_int32 (pRawdata+17); + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_CLIP, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_SHOW +READ_CHUNK (mng_read_show) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_SHOW, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* check the length */ + if ((iRawlen != 0) && (iRawlen != 2) && (iRawlen != 4) && (iRawlen != 5)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode; + + if (iRawlen) /* determine parameters if any */ + { + pData->iSHOWfromid = mng_get_uint16 (pRawdata); + + if (iRawlen > 2) + pData->iSHOWtoid = mng_get_uint16 (pRawdata+2); + else + pData->iSHOWtoid = pData->iSHOWfromid; + + if (iRawlen > 4) + pData->iSHOWmode = *(pRawdata+4); + else + pData->iSHOWmode = 0; + } + else /* use defaults then */ + { + pData->iSHOWmode = 2; + pData->iSHOWfromid = 1; + pData->iSHOWtoid = 65535; + } + /* create a SHOW animation object */ + iRetcode = mng_create_ani_show (pData, pData->iSHOWfromid, + pData->iSHOWtoid, pData->iSHOWmode); + + if (!iRetcode) + iRetcode = mng_process_display_show (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_showp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + + if (iRawlen) + { + ((mng_showp)*ppChunk)->iFirstid = mng_get_uint16 (pRawdata); + + if (iRawlen > 2) + ((mng_showp)*ppChunk)->iLastid = mng_get_uint16 (pRawdata+2); + else + ((mng_showp)*ppChunk)->iLastid = ((mng_showp)*ppChunk)->iFirstid; + + if (iRawlen > 4) + ((mng_showp)*ppChunk)->iMode = *(pRawdata+4); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_SHOW, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_TERM +READ_CHUNK (mng_read_term) +{ + mng_uint8 iTermaction; + mng_uint8 iIteraction = 0; + mng_uint32 iDelay = 0; + mng_uint32 iItermax = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_TERM, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + /* should be behind MHDR or SAVE !! */ + if ((!pData->bHasSAVE) && (pData->iChunkseq > 2)) + { + pData->bMisplacedTERM = MNG_TRUE; /* indicate we found a misplaced TERM */ + /* and send a warning signal!!! */ + MNG_WARNING (pData, MNG_SEQUENCEERROR); + } + + if (pData->bHasLOOP) /* no way, jose! */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (pData->bHasTERM) /* only 1 allowed! */ + MNG_ERROR (pData, MNG_MULTIPLEERROR); + /* check the length */ + if ((iRawlen != 1) && (iRawlen != 10)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + pData->bHasTERM = MNG_TRUE; + + iTermaction = *pRawdata; /* get the fields */ + + if (iRawlen > 1) + { + iIteraction = *(pRawdata+1); + iDelay = mng_get_uint32 (pRawdata+2); + iItermax = mng_get_uint32 (pRawdata+6); + } + + if (pData->fProcessterm) /* inform the app ? */ + if (!pData->fProcessterm (((mng_handle)pData), iTermaction, iIteraction, + iDelay, iItermax)) + MNG_ERROR (pData, MNG_APPMISCERROR); + +#ifdef MNG_SUPPORT_DISPLAY + { /* create the TERM ani-object */ + mng_retcode iRetcode = mng_create_ani_term (pData, iTermaction, iIteraction, + iDelay, iItermax); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* save for future reference */ + pData->pTermaniobj = pData->pLastaniobj; + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_termp)*ppChunk)->iTermaction = iTermaction; + ((mng_termp)*ppChunk)->iIteraction = iIteraction; + ((mng_termp)*ppChunk)->iDelay = iDelay; + ((mng_termp)*ppChunk)->iItermax = iItermax; + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_TERM, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_SAVE +READ_CHUNK (mng_read_save) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_SAVE, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasMHDR) || (pData->bHasSAVE)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + pData->bHasSAVE = MNG_TRUE; + + if (pData->fProcesssave) /* inform the application ? */ + { + mng_bool bOke = pData->fProcesssave ((mng_handle)pData); + + if (!bOke) + MNG_ERROR (pData, MNG_APPMISCERROR); + } + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode; + + + /* TODO: something with the parameters */ + + + /* create a SAVE animation object */ + iRetcode = mng_create_ani_save (pData); + + if (!iRetcode) + iRetcode = mng_process_display_save (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_savep)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + + if (iRawlen) /* not empty ? */ + { + mng_uint8 iOtype = *pRawdata; + mng_uint8 iEtype; + mng_uint32 iCount = 0; + mng_uint8p pTemp; + mng_uint8p pNull; + mng_uint32 iLen; + mng_uint32 iOffset[2]; + mng_uint32 iStarttime[2]; + mng_uint32 iFramenr; + mng_uint32 iLayernr; + mng_uint32 iX; + mng_save_entryp pEntry = MNG_NULL; + mng_uint32 iNamesize; + + if ((iOtype != 4) && (iOtype != 8)) + MNG_ERROR (pData, MNG_INVOFFSETSIZE); + + ((mng_savep)*ppChunk)->iOffsettype = iOtype; + + for (iX = 0; iX < 2; iX++) /* do this twice to get the count first ! */ + { + pTemp = pRawdata + 1; + iLen = iRawlen - 1; + + if (iX) /* second run ? */ + { + MNG_ALLOC (pData, pEntry, (iCount * sizeof (mng_save_entry))); + + ((mng_savep)*ppChunk)->iCount = iCount; + ((mng_savep)*ppChunk)->pEntries = pEntry; + } + + while (iLen) /* anything left ? */ + { + iEtype = *pTemp; /* entrytype */ + + if ((iEtype != 0) && (iEtype != 1) && (iEtype != 2) && (iEtype != 3)) + MNG_ERROR (pData, MNG_INVENTRYTYPE); + + pTemp++; + + if (iEtype > 1) + { + iOffset [0] = 0; + iOffset [1] = 0; + iStarttime [0] = 0; + iStarttime [1] = 0; + iLayernr = 0; + iFramenr = 0; + } + else + { + if (iOtype == 4) + { + iOffset [0] = 0; + iOffset [1] = mng_get_uint32 (pTemp); + + pTemp += 4; + } + else + { + iOffset [0] = mng_get_uint32 (pTemp); + iOffset [1] = mng_get_uint32 (pTemp+4); + + pTemp += 8; + } + + if (iEtype > 0) + { + iStarttime [0] = 0; + iStarttime [1] = 0; + iLayernr = 0; + iFramenr = 0; + } + else + { + if (iOtype == 4) + { + iStarttime [0] = 0; + iStarttime [1] = mng_get_uint32 (pTemp+0); + iLayernr = mng_get_uint32 (pTemp+4); + iFramenr = mng_get_uint32 (pTemp+8); + + pTemp += 12; + } + else + { + iStarttime [0] = mng_get_uint32 (pTemp+0); + iStarttime [1] = mng_get_uint32 (pTemp+4); + iLayernr = mng_get_uint32 (pTemp+8); + iFramenr = mng_get_uint32 (pTemp+12); + + pTemp += 16; + } + } + } + + pNull = find_null (pTemp); /* get the name length */ + + if ((pNull - pRawdata) > (mng_int32)iRawlen) + { + iNamesize = iLen; /* no null found; so end of SAVE */ + iLen = 0; + } + else + { + iNamesize = pNull - pTemp; /* should be another entry */ + iLen -= iNamesize; + + if (!iLen) /* must not end with a null ! */ + MNG_ERROR (pData, MNG_ENDWITHNULL); + } + + if (!pEntry) + { + iCount++; + } + else + { + pEntry->iEntrytype = iEtype; + pEntry->iOffset [0] = iOffset [0]; + pEntry->iOffset [1] = iOffset [1]; + pEntry->iStarttime [0] = iStarttime [0]; + pEntry->iStarttime [1] = iStarttime [1]; + pEntry->iLayernr = iLayernr; + pEntry->iFramenr = iFramenr; + pEntry->iNamesize = iNamesize; + + if (iNamesize) + { + MNG_ALLOC (pData, pEntry->zName, iNamesize+1); + MNG_COPY (pEntry->zName, pTemp, iNamesize); + } + + pEntry++; + } + + pTemp += iNamesize; + } + } + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_SAVE, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_SEEK +READ_CHUNK (mng_read_seek) +{ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_SEEK, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasMHDR) || (!pData->bHasSAVE)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_SUPPORT_DISPLAY + /* create a SEEK animation object */ + iRetcode = mng_create_ani_seek (pData, iRawlen, (mng_pchar)pRawdata); + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#endif /* MNG_SUPPORT_DISPLAY */ + + if (pData->fProcessseek) /* inform the app ? */ + { + mng_bool bOke; + mng_pchar zName; + + MNG_ALLOC (pData, zName, iRawlen + 1); + + if (iRawlen) + MNG_COPY (zName, pRawdata, iRawlen); + + bOke = pData->fProcessseek ((mng_handle)pData, zName); + + MNG_FREEX (pData, zName, iRawlen + 1); + + if (!bOke) + MNG_ERROR (pData, MNG_APPMISCERROR); + } + +#ifdef MNG_SUPPORT_DISPLAY + /* do display processing of the SEEK */ + iRetcode = mng_process_display_seek (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_seekp)*ppChunk)->iNamesize = iRawlen; + + if (iRawlen) + { + MNG_ALLOC (pData, ((mng_seekp)*ppChunk)->zName, iRawlen+1); + MNG_COPY (((mng_seekp)*ppChunk)->zName, pRawdata, iRawlen); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_SEEK, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_eXPI +READ_CHUNK (mng_read_expi) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_EXPI, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen < 3) /* check the length */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_expip)*ppChunk)->iSnapshotid = mng_get_uint16 (pRawdata); + ((mng_expip)*ppChunk)->iNamesize = iRawlen - 2; + + if (((mng_expip)*ppChunk)->iNamesize) + { + MNG_ALLOC (pData, ((mng_expip)*ppChunk)->zName, + ((mng_expip)*ppChunk)->iNamesize + 1); + MNG_COPY (((mng_expip)*ppChunk)->zName, pRawdata+2, + ((mng_expip)*ppChunk)->iNamesize); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_EXPI, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_fPRI +READ_CHUNK (mng_read_fpri) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_FPRI, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen != 2) /* must be two bytes long */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_fprip)*ppChunk)->iDeltatype = *pRawdata; + ((mng_fprip)*ppChunk)->iPriority = *(pRawdata+1); + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_FPRI, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_nEED +MNG_LOCAL mng_bool CheckKeyword (mng_datap pData, + mng_uint8p pKeyword) +{ + mng_chunkid handled_chunks [] = + { + MNG_UINT_BACK, /* keep it sorted !!!! */ + MNG_UINT_BASI, + MNG_UINT_CLIP, + MNG_UINT_CLON, +#ifndef MNG_NO_DELTA_PNG +/* TODO: MNG_UINT_DBYK, */ +#endif + MNG_UINT_DEFI, +#ifndef MNG_NO_DELTA_PNG + MNG_UINT_DHDR, +#endif + MNG_UINT_DISC, +#ifndef MNG_NO_DELTA_PNG +/* TODO: MNG_UINT_DROP, */ +#endif + MNG_UINT_ENDL, + MNG_UINT_FRAM, + MNG_UINT_IDAT, + MNG_UINT_IEND, + MNG_UINT_IHDR, +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG + MNG_UINT_IJNG, +#endif + MNG_UINT_IPNG, +#endif +#ifdef MNG_INCLUDE_JNG + MNG_UINT_JDAA, + MNG_UINT_JDAT, + MNG_UINT_JHDR, +/* TODO: MNG_UINT_JSEP, */ + MNG_UINT_JdAA, +#endif + MNG_UINT_LOOP, + MNG_UINT_MAGN, + MNG_UINT_MEND, + MNG_UINT_MHDR, + MNG_UINT_MOVE, +/* TODO: MNG_UINT_ORDR, */ + MNG_UINT_PAST, + MNG_UINT_PLTE, +#ifndef MNG_NO_DELTA_PNG + MNG_UINT_PPLT, + MNG_UINT_PROM, +#endif + MNG_UINT_SAVE, + MNG_UINT_SEEK, + MNG_UINT_SHOW, + MNG_UINT_TERM, +#ifdef MNG_INCLUDE_ANG_PROPOSAL + MNG_UINT_adAT, + MNG_UINT_ahDR, +#endif + MNG_UINT_bKGD, + MNG_UINT_cHRM, +/* TODO: MNG_UINT_eXPI, */ + MNG_UINT_evNT, +/* TODO: MNG_UINT_fPRI, */ + MNG_UINT_gAMA, +/* TODO: MNG_UINT_hIST, */ + MNG_UINT_iCCP, + MNG_UINT_iTXt, +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + MNG_UINT_mpNG, +#endif + MNG_UINT_nEED, +/* TODO: MNG_UINT_oFFs, */ +/* TODO: MNG_UINT_pCAL, */ +/* TODO: MNG_UINT_pHYg, */ +/* TODO: MNG_UINT_pHYs, */ +/* TODO: MNG_UINT_sBIT, */ +/* TODO: MNG_UINT_sCAL, */ +/* TODO: MNG_UINT_sPLT, */ + MNG_UINT_sRGB, + MNG_UINT_tEXt, + MNG_UINT_tIME, + MNG_UINT_tRNS, + MNG_UINT_zTXt, + }; + + mng_bool bOke = MNG_FALSE; + + if (pData->fProcessneed) /* does the app handle it ? */ + bOke = pData->fProcessneed ((mng_handle)pData, (mng_pchar)pKeyword); + + if (!bOke) + { /* find the keyword length */ + mng_uint8p pNull = find_null (pKeyword); + + if (pNull - pKeyword == 4) /* test a chunk ? */ + { /* get the chunk-id */ + mng_chunkid iChunkid = (*pKeyword << 24) + (*(pKeyword+1) << 16) + + (*(pKeyword+2) << 8) + (*(pKeyword+3) ); + /* binary search variables */ + mng_int32 iTop, iLower, iUpper, iMiddle; + /* determine max index of table */ + iTop = (sizeof (handled_chunks) / sizeof (handled_chunks [0])) - 1; + + /* binary search; with 52 chunks, worst-case is 7 comparisons */ + iLower = 0; + iMiddle = iTop >> 1; + iUpper = iTop; + + do /* the binary search itself */ + { + if (handled_chunks [iMiddle] < iChunkid) + iLower = iMiddle + 1; + else if (handled_chunks [iMiddle] > iChunkid) + iUpper = iMiddle - 1; + else + { + bOke = MNG_TRUE; + break; + } + + iMiddle = (iLower + iUpper) >> 1; + } + while (iLower <= iUpper); + } + /* test draft ? */ + if ((!bOke) && (pNull - pKeyword == 8) && + (*pKeyword == 'd') && (*(pKeyword+1) == 'r') && + (*(pKeyword+2) == 'a') && (*(pKeyword+3) == 'f') && + (*(pKeyword+4) == 't') && (*(pKeyword+5) == ' ')) + { + mng_uint32 iDraft; + + iDraft = (*(pKeyword+6) - '0') * 10 + (*(pKeyword+7) - '0'); + bOke = (mng_bool)(iDraft <= MNG_MNG_DRAFT); + } + /* test MNG 1.0/1.1 ? */ + if ((!bOke) && (pNull - pKeyword == 7) && + (*pKeyword == 'M') && (*(pKeyword+1) == 'N') && + (*(pKeyword+2) == 'G') && (*(pKeyword+3) == '-') && + (*(pKeyword+4) == '1') && (*(pKeyword+5) == '.') && + ((*(pKeyword+6) == '0') || (*(pKeyword+6) == '1'))) + bOke = MNG_TRUE; + /* test CACHEOFF ? */ + if ((!bOke) && (pNull - pKeyword == 8) && + (*pKeyword == 'C') && (*(pKeyword+1) == 'A') && + (*(pKeyword+2) == 'C') && (*(pKeyword+3) == 'H') && + (*(pKeyword+4) == 'E') && (*(pKeyword+5) == 'O') && + (*(pKeyword+6) == 'F') && (*(pKeyword+7) == 'F')) + { + if (!pData->pFirstaniobj) /* only if caching hasn't started yet ! */ + { + bOke = MNG_TRUE; + pData->bCacheplayback = MNG_FALSE; + pData->bStorechunks = MNG_FALSE; + } + } + } + + return bOke; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_nEED +READ_CHUNK (mng_read_need) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_NEED, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen < 1) /* check the length */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + { /* let's check it */ + mng_bool bOke = MNG_TRUE; + mng_pchar zKeywords; + mng_uint8p pNull, pTemp; + + MNG_ALLOC (pData, zKeywords, iRawlen + 1); + + if (iRawlen) + MNG_COPY (zKeywords, pRawdata, iRawlen); + + pTemp = (mng_uint8p)zKeywords; + pNull = find_null (pTemp); + + while ((bOke) && (pNull < (mng_uint8p)zKeywords + iRawlen)) + { + bOke = CheckKeyword (pData, pTemp); + pTemp = pNull + 1; + pNull = find_null (pTemp); + } + + if (bOke) + bOke = CheckKeyword (pData, pTemp); + + MNG_FREEX (pData, zKeywords, iRawlen + 1); + + if (!bOke) + MNG_ERROR (pData, MNG_UNSUPPORTEDNEED); + } + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_needp)*ppChunk)->iKeywordssize = iRawlen; + + if (iRawlen) + { + MNG_ALLOC (pData, ((mng_needp)*ppChunk)->zKeywords, iRawlen+1); + MNG_COPY (((mng_needp)*ppChunk)->zKeywords, pRawdata, iRawlen); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_NEED, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_pHYg +READ_CHUNK (mng_read_phyg) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_PHYG, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* it's 9 bytes or empty; no more, no less! */ + if ((iRawlen != 9) && (iRawlen != 0)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_phygp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + + if (iRawlen) + { + ((mng_phygp)*ppChunk)->iSizex = mng_get_uint32 (pRawdata); + ((mng_phygp)*ppChunk)->iSizey = mng_get_uint32 (pRawdata+4); + ((mng_phygp)*ppChunk)->iUnit = *(pRawdata+8); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_PHYG, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_INCLUDE_JNG +READ_CHUNK (mng_read_jhdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_JHDR, MNG_LC_START); +#endif + /* sequence checks */ + if ((pData->eSigtype != mng_it_jng) && (pData->eSigtype != mng_it_mng)) + MNG_ERROR (pData, MNG_CHUNKNOTALLOWED); + + if ((pData->eSigtype == mng_it_jng) && (pData->iChunkseq > 1)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen != 16) /* length oke ? */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + /* inside a JHDR-IEND block now */ + pData->bHasJHDR = MNG_TRUE; + /* and store interesting fields */ + pData->iDatawidth = mng_get_uint32 (pRawdata); + pData->iDataheight = mng_get_uint32 (pRawdata+4); + pData->iJHDRcolortype = *(pRawdata+8); + pData->iJHDRimgbitdepth = *(pRawdata+9); + pData->iJHDRimgcompression = *(pRawdata+10); + pData->iJHDRimginterlace = *(pRawdata+11); + pData->iJHDRalphabitdepth = *(pRawdata+12); + pData->iJHDRalphacompression = *(pRawdata+13); + pData->iJHDRalphafilter = *(pRawdata+14); + pData->iJHDRalphainterlace = *(pRawdata+15); + + +#if defined(MNG_NO_1_2_4BIT_SUPPORT) || defined(MNG_NO_16BIT_SUPPORT) + pData->iPNGmult = 1; + pData->iPNGdepth = pData->iJHDRalphabitdepth; +#endif + +#ifdef MNG_NO_1_2_4BIT_SUPPORT + if (pData->iJHDRalphabitdepth < 8) + pData->iJHDRalphabitdepth = 8; +#endif + +#ifdef MNG_NO_16BIT_SUPPORT + if (pData->iJHDRalphabitdepth > 8) + { + pData->iPNGmult = 2; + pData->iJHDRalphabitdepth = 8; + } +#endif + /* parameter validity checks */ + if ((pData->iJHDRcolortype != MNG_COLORTYPE_JPEGGRAY ) && + (pData->iJHDRcolortype != MNG_COLORTYPE_JPEGCOLOR ) && + (pData->iJHDRcolortype != MNG_COLORTYPE_JPEGGRAYA ) && + (pData->iJHDRcolortype != MNG_COLORTYPE_JPEGCOLORA) ) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + + if ((pData->iJHDRimgbitdepth != MNG_BITDEPTH_JPEG8 ) && + (pData->iJHDRimgbitdepth != MNG_BITDEPTH_JPEG12 ) && + (pData->iJHDRimgbitdepth != MNG_BITDEPTH_JPEG8AND12) ) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if (pData->iJHDRimgcompression != MNG_COMPRESSION_BASELINEJPEG) + MNG_ERROR (pData, MNG_INVALIDCOMPRESS); + + if ((pData->iJHDRimginterlace != MNG_INTERLACE_SEQUENTIAL ) && + (pData->iJHDRimginterlace != MNG_INTERLACE_PROGRESSIVE) ) + MNG_ERROR (pData, MNG_INVALIDINTERLACE); + + if ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || + (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) + { + if ((pData->iJHDRalphabitdepth != MNG_BITDEPTH_8 ) +#ifndef MNG_NO_1_2_4BIT_SUPPORT + && (pData->iJHDRalphabitdepth != MNG_BITDEPTH_1 ) && + (pData->iJHDRalphabitdepth != MNG_BITDEPTH_2 ) && + (pData->iJHDRalphabitdepth != MNG_BITDEPTH_4 ) +#endif +#ifndef MNG_NO_16BIT_SUPPORT + && (pData->iJHDRalphabitdepth != MNG_BITDEPTH_16) +#endif + ) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if ((pData->iJHDRalphacompression != MNG_COMPRESSION_DEFLATE ) && + (pData->iJHDRalphacompression != MNG_COMPRESSION_BASELINEJPEG) ) + MNG_ERROR (pData, MNG_INVALIDCOMPRESS); + + if ((pData->iJHDRalphacompression == MNG_COMPRESSION_BASELINEJPEG) && + (pData->iJHDRalphabitdepth != MNG_BITDEPTH_8 ) ) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + +#if defined(FILTER192) || defined(FILTER193) + if ((pData->iJHDRalphafilter != MNG_FILTER_ADAPTIVE ) && +#if defined(FILTER192) && defined(FILTER193) + (pData->iJHDRalphafilter != MNG_FILTER_DIFFERING) && + (pData->iJHDRalphafilter != MNG_FILTER_NOFILTER ) ) +#else +#ifdef FILTER192 + (pData->iJHDRalphafilter != MNG_FILTER_DIFFERING) ) +#else + (pData->iJHDRalphafilter != MNG_FILTER_NOFILTER ) ) +#endif +#endif + MNG_ERROR (pData, MNG_INVALIDFILTER); +#else + if (pData->iJHDRalphafilter) + MNG_ERROR (pData, MNG_INVALIDFILTER); +#endif + + if ((pData->iJHDRalphainterlace != MNG_INTERLACE_NONE ) && + (pData->iJHDRalphainterlace != MNG_INTERLACE_ADAM7) ) + MNG_ERROR (pData, MNG_INVALIDINTERLACE); + + } + else + { + if (pData->iJHDRalphabitdepth) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if (pData->iJHDRalphacompression) + MNG_ERROR (pData, MNG_INVALIDCOMPRESS); + + if (pData->iJHDRalphafilter) + MNG_ERROR (pData, MNG_INVALIDFILTER); + + if (pData->iJHDRalphainterlace) + MNG_ERROR (pData, MNG_INVALIDINTERLACE); + + } + + if (!pData->bHasheader) /* first chunk ? */ + { + pData->bHasheader = MNG_TRUE; /* we've got a header */ + pData->eImagetype = mng_it_jng; /* then this must be a JNG */ + pData->iWidth = mng_get_uint32 (pRawdata); + pData->iHeight = mng_get_uint32 (pRawdata+4); + /* predict alpha-depth ! */ + if ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || + (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) + pData->iAlphadepth = pData->iJHDRalphabitdepth; + else + pData->iAlphadepth = 0; + /* fits on maximum canvas ? */ + if ((pData->iWidth > pData->iMaxwidth) || (pData->iHeight > pData->iMaxheight)) + MNG_WARNING (pData, MNG_IMAGETOOLARGE); + + if (pData->fProcessheader) /* inform the app ? */ + if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) + MNG_ERROR (pData, MNG_APPMISCERROR); + + } + + pData->iColortype = 0; /* fake grayscale for other routines */ + pData->iImagelevel++; /* one level deeper */ + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode = mng_process_display_jhdr (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_jhdrp)*ppChunk)->iWidth = mng_get_uint32 (pRawdata); + ((mng_jhdrp)*ppChunk)->iHeight = mng_get_uint32 (pRawdata+4); + ((mng_jhdrp)*ppChunk)->iColortype = *(pRawdata+8); + ((mng_jhdrp)*ppChunk)->iImagesampledepth = *(pRawdata+9); + ((mng_jhdrp)*ppChunk)->iImagecompression = *(pRawdata+10); + ((mng_jhdrp)*ppChunk)->iImageinterlace = *(pRawdata+11); + ((mng_jhdrp)*ppChunk)->iAlphasampledepth = *(pRawdata+12); +#ifdef MNG_NO_16BIT_SUPPORT + if (*(pRawdata+12) > 8) + ((mng_jhdrp)*ppChunk)->iAlphasampledepth = 8; +#endif + ((mng_jhdrp)*ppChunk)->iAlphacompression = *(pRawdata+13); + ((mng_jhdrp)*ppChunk)->iAlphafilter = *(pRawdata+14); + ((mng_jhdrp)*ppChunk)->iAlphainterlace = *(pRawdata+15); + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_JHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#else +#define read_jhdr 0 +#endif /* MNG_INCLUDE_JNG */ +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_INCLUDE_JNG +READ_CHUNK (mng_read_jdaa) +{ +#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) + volatile mng_retcode iRetcode; + + iRetcode=MNG_NOERROR; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_JDAA, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasJHDR) && (!pData->bHasDHDR)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (pData->bHasJSEP) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (pData->iJHDRalphacompression != MNG_COMPRESSION_BASELINEJPEG) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen == 0) /* can never be empty */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + pData->bHasJDAA = MNG_TRUE; /* got some JDAA now, don't we */ + +#ifdef MNG_SUPPORT_DISPLAY + iRetcode = mng_process_display_jdaa (pData, iRawlen, pRawdata); + + if (iRetcode) /* on error bail out */ + return iRetcode; +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_jdaap)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + ((mng_jdaap)*ppChunk)->iDatasize = iRawlen; + + if (iRawlen != 0) /* is there any data ? */ + { + MNG_ALLOC (pData, ((mng_jdaap)*ppChunk)->pData, iRawlen); + MNG_COPY (((mng_jdaap)*ppChunk)->pData, pRawdata, iRawlen); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_JDAA, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#else +#define read_jdaa 0 +#endif /* MNG_INCLUDE_JNG */ +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_INCLUDE_JNG +READ_CHUNK (mng_read_jdat) +{ +#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) + volatile mng_retcode iRetcode; + + iRetcode=MNG_NOERROR; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_JDAT, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasJHDR) && (!pData->bHasDHDR)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen == 0) /* can never be empty */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + pData->bHasJDAT = MNG_TRUE; /* got some JDAT now, don't we */ + +#ifdef MNG_SUPPORT_DISPLAY + iRetcode = mng_process_display_jdat (pData, iRawlen, pRawdata); + + if (iRetcode) /* on error bail out */ + return iRetcode; +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_jdatp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0); + ((mng_jdatp)*ppChunk)->iDatasize = iRawlen; + + if (iRawlen != 0) /* is there any data ? */ + { + MNG_ALLOC (pData, ((mng_jdatp)*ppChunk)->pData, iRawlen); + MNG_COPY (((mng_jdatp)*ppChunk)->pData, pRawdata, iRawlen); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_JDAT, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#else +#define read_jdat 0 +#endif /* MNG_INCLUDE_JNG */ +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_INCLUDE_JNG +READ_CHUNK (mng_read_jsep) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_JSEP, MNG_LC_START); +#endif + + if (!pData->bHasJHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen != 0) /* must be empty ! */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + pData->bHasJSEP = MNG_TRUE; /* indicate we've had the 8-/12-bit separator */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_JSEP, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#else +#define read_jsep 0 +#endif /* MNG_INCLUDE_JNG */ +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_NO_DELTA_PNG +READ_CHUNK (mng_read_dhdr) +{ + mng_uint8 iImagetype, iDeltatype; +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_DHDR, MNG_LC_START); +#endif + + if (!pData->bHasMHDR) /* sequence checks */ + MNG_ERROR (pData, MNG_SEQUENCEERROR); + +#ifdef MNG_INCLUDE_JNG + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* check for valid length */ + if ((iRawlen != 4) && (iRawlen != 12) && (iRawlen != 20)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + iImagetype = *(pRawdata+2); /* check fields for validity */ + iDeltatype = *(pRawdata+3); + + if (iImagetype > MNG_IMAGETYPE_JNG) + MNG_ERROR (pData, MNG_INVIMAGETYPE); + + if (iDeltatype > MNG_DELTATYPE_NOCHANGE) + MNG_ERROR (pData, MNG_INVDELTATYPE); + + if ((iDeltatype == MNG_DELTATYPE_REPLACE) && (iRawlen > 12)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((iDeltatype == MNG_DELTATYPE_NOCHANGE) && (iRawlen > 4)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + pData->bHasDHDR = MNG_TRUE; /* inside a DHDR-IEND block now */ + pData->iDeltatype = iDeltatype; + + pData->iImagelevel++; /* one level deeper */ + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_uint16 iObjectid = mng_get_uint16 (pRawdata); + mng_uint32 iBlockwidth = 0; + mng_uint32 iBlockheight = 0; + mng_uint32 iBlockx = 0; + mng_uint32 iBlocky = 0; + mng_retcode iRetcode; + + if (iRawlen > 4) + { + iBlockwidth = mng_get_uint32 (pRawdata+4); + iBlockheight = mng_get_uint32 (pRawdata+8); + } + + if (iRawlen > 12) + { + iBlockx = mng_get_uint32 (pRawdata+12); + iBlocky = mng_get_uint32 (pRawdata+16); + } + + iRetcode = mng_create_ani_dhdr (pData, iObjectid, iImagetype, iDeltatype, + iBlockwidth, iBlockheight, iBlockx, iBlocky); + +/* if (!iRetcode) + iRetcode = mng_process_display_dhdr (pData, iObjectid, iImagetype, iDeltatype, + iBlockwidth, iBlockheight, iBlockx, iBlocky); */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_dhdrp)*ppChunk)->iObjectid = mng_get_uint16 (pRawdata); + ((mng_dhdrp)*ppChunk)->iImagetype = iImagetype; + ((mng_dhdrp)*ppChunk)->iDeltatype = iDeltatype; + + if (iRawlen > 4) + { + ((mng_dhdrp)*ppChunk)->iBlockwidth = mng_get_uint32 (pRawdata+4); + ((mng_dhdrp)*ppChunk)->iBlockheight = mng_get_uint32 (pRawdata+8); + } + + if (iRawlen > 12) + { + ((mng_dhdrp)*ppChunk)->iBlockx = mng_get_uint32 (pRawdata+12); + ((mng_dhdrp)*ppChunk)->iBlocky = mng_get_uint32 (pRawdata+16); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_DHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_NO_DELTA_PNG +READ_CHUNK (mng_read_prom) +{ + mng_uint8 iColortype; + mng_uint8 iSampledepth; + mng_uint8 iFilltype; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_PROM, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasMHDR) || (!pData->bHasDHDR)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen != 3) /* gotta be exactly 3 bytes */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + iColortype = *pRawdata; /* check fields for validity */ + iSampledepth = *(pRawdata+1); + iFilltype = *(pRawdata+2); + + if ((iColortype != MNG_COLORTYPE_GRAY ) && + (iColortype != MNG_COLORTYPE_RGB ) && + (iColortype != MNG_COLORTYPE_INDEXED) && + (iColortype != MNG_COLORTYPE_GRAYA ) && + (iColortype != MNG_COLORTYPE_RGBA ) ) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + +#ifdef MNG_NO_16BIT_SUPPORT + if (iSampledepth == MNG_BITDEPTH_16 ) + iSampledepth = MNG_BITDEPTH_8; +#endif + + if ((iSampledepth != MNG_BITDEPTH_1 ) && + (iSampledepth != MNG_BITDEPTH_2 ) && + (iSampledepth != MNG_BITDEPTH_4 ) && + (iSampledepth != MNG_BITDEPTH_8 ) +#ifndef MNG_NO_16BIT_SUPPORT + && (iSampledepth != MNG_BITDEPTH_16) +#endif + ) + MNG_ERROR (pData, MNG_INVSAMPLEDEPTH); + + if ((iFilltype != MNG_FILLMETHOD_LEFTBITREPLICATE) && + (iFilltype != MNG_FILLMETHOD_ZEROFILL ) ) + MNG_ERROR (pData, MNG_INVFILLMETHOD); + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode = mng_create_ani_prom (pData, iSampledepth, + iColortype, iFilltype); + +/* if (!iRetcode) + iRetcode = mng_process_display_prom (pData, iSampledepth, + iColortype, iFilltype); */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_promp)*ppChunk)->iColortype = iColortype; + ((mng_promp)*ppChunk)->iSampledepth = iSampledepth; + ((mng_promp)*ppChunk)->iFilltype = iFilltype; + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_PROM, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_NO_DELTA_PNG +READ_CHUNK (mng_read_ipng) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_IPNG, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasMHDR) || (!pData->bHasDHDR)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen != 0) /* gotta be empty */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode = mng_create_ani_ipng (pData); + + if (!iRetcode) + iRetcode = mng_process_display_ipng (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_IPNG, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_NO_DELTA_PNG +READ_CHUNK (mng_read_pplt) +{ + mng_uint8 iDeltatype; + mng_uint8p pTemp; + mng_uint32 iLen; + mng_uint8 iX, iM; + mng_uint32 iY; + mng_uint32 iMax; + mng_rgbpaltab aIndexentries; + mng_uint8arr aAlphaentries; + mng_uint8arr aUsedentries; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_PPLT, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasMHDR) && (!pData->bHasDHDR)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen < 1) /* must have at least 1 byte */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + iDeltatype = *pRawdata; + /* valid ? */ + if (iDeltatype > MNG_DELTATYPE_DELTARGBA) + MNG_ERROR (pData, MNG_INVDELTATYPE); + /* must be indexed color ! */ + if (pData->iColortype != MNG_COLORTYPE_INDEXED) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + + pTemp = pRawdata + 1; + iLen = iRawlen - 1; + iMax = 0; + + for (iY = 0; iY < 256; iY++) /* reset arrays */ + { + aIndexentries [iY].iRed = 0; + aIndexentries [iY].iGreen = 0; + aIndexentries [iY].iBlue = 0; + aAlphaentries [iY] = 255; + aUsedentries [iY] = 0; + } + + while (iLen) /* as long as there are entries left ... */ + { + mng_uint32 iDiff; + + if (iLen < 2) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + iX = *pTemp; /* get start and end index */ + iM = *(pTemp+1); + + if (iM < iX) + MNG_ERROR (pData, MNG_INVALIDINDEX); + + if ((mng_uint32)iM >= iMax) /* determine highest used index */ + iMax = (mng_uint32)iM + 1; + + pTemp += 2; + iLen -= 2; + iDiff = (iM - iX + 1); + if ((iDeltatype == MNG_DELTATYPE_REPLACERGB ) || + (iDeltatype == MNG_DELTATYPE_DELTARGB ) ) + iDiff = iDiff * 3; + else + if ((iDeltatype == MNG_DELTATYPE_REPLACERGBA) || + (iDeltatype == MNG_DELTATYPE_DELTARGBA ) ) + iDiff = iDiff * 4; + + if (iLen < iDiff) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + if ((iDeltatype == MNG_DELTATYPE_REPLACERGB ) || + (iDeltatype == MNG_DELTATYPE_DELTARGB ) ) + { + for (iY = (mng_uint32)iX; iY <= (mng_uint32)iM; iY++) + { + aIndexentries [iY].iRed = *pTemp; + aIndexentries [iY].iGreen = *(pTemp+1); + aIndexentries [iY].iBlue = *(pTemp+2); + aUsedentries [iY] = 1; + + pTemp += 3; + iLen -= 3; + } + } + else + if ((iDeltatype == MNG_DELTATYPE_REPLACEALPHA) || + (iDeltatype == MNG_DELTATYPE_DELTAALPHA ) ) + { + for (iY = (mng_uint32)iX; iY <= (mng_uint32)iM; iY++) + { + aAlphaentries [iY] = *pTemp; + aUsedentries [iY] = 1; + + pTemp++; + iLen--; + } + } + else + { + for (iY = (mng_uint32)iX; iY <= (mng_uint32)iM; iY++) + { + aIndexentries [iY].iRed = *pTemp; + aIndexentries [iY].iGreen = *(pTemp+1); + aIndexentries [iY].iBlue = *(pTemp+2); + aAlphaentries [iY] = *(pTemp+3); + aUsedentries [iY] = 1; + + pTemp += 4; + iLen -= 4; + } + } + } + + switch (pData->iBitdepth) /* check maximum allowed entries for bitdepth */ + { + case MNG_BITDEPTH_1 : { + if (iMax > 2) + MNG_ERROR (pData, MNG_INVALIDINDEX); + break; + } + case MNG_BITDEPTH_2 : { + if (iMax > 4) + MNG_ERROR (pData, MNG_INVALIDINDEX); + break; + } + case MNG_BITDEPTH_4 : { + if (iMax > 16) + MNG_ERROR (pData, MNG_INVALIDINDEX); + break; + } + } + +#ifdef MNG_SUPPORT_DISPLAY + { /* create animation object */ + mng_retcode iRetcode = mng_create_ani_pplt (pData, iDeltatype, iMax, + aIndexentries, aAlphaentries, + aUsedentries); + +/* if (!iRetcode) + iRetcode = mng_process_display_pplt (pData, iDeltatype, iMax, aIndexentries, + aAlphaentries, aUsedentries); */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_ppltp)*ppChunk)->iDeltatype = iDeltatype; + ((mng_ppltp)*ppChunk)->iCount = iMax; + + for (iY = 0; iY < 256; iY++) + { + ((mng_ppltp)*ppChunk)->aEntries [iY].iRed = aIndexentries [iY].iRed; + ((mng_ppltp)*ppChunk)->aEntries [iY].iGreen = aIndexentries [iY].iGreen; + ((mng_ppltp)*ppChunk)->aEntries [iY].iBlue = aIndexentries [iY].iBlue; + ((mng_ppltp)*ppChunk)->aEntries [iY].iAlpha = aAlphaentries [iY]; + ((mng_ppltp)*ppChunk)->aEntries [iY].bUsed = (mng_bool)(aUsedentries [iY]); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_PPLT, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG +READ_CHUNK (mng_read_ijng) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_IJNG, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasMHDR) || (!pData->bHasDHDR)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen != 0) /* gotta be empty */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode = mng_create_ani_ijng (pData); + + if (!iRetcode) + iRetcode = mng_process_display_ijng (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_IJNG, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_NO_DELTA_PNG +READ_CHUNK (mng_read_drop) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_DROP, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasMHDR) || (!pData->bHasDHDR)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* check length */ + if ((iRawlen < 4) || ((iRawlen % 4) != 0)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_dropp)*ppChunk)->iCount = iRawlen / 4; + + if (iRawlen) + { + mng_uint32 iX; + mng_uint8p pTemp = pRawdata; + mng_uint32p pEntry; + + MNG_ALLOC (pData, pEntry, iRawlen); + + ((mng_dropp)*ppChunk)->pChunknames = (mng_ptr)pEntry; + + for (iX = 0; iX < iRawlen / 4; iX++) + { + *pEntry = mng_get_uint32 (pTemp); + + pTemp += 4; + pEntry++; + } + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_DROP, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DBYK +READ_CHUNK (mng_read_dbyk) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_DBYK, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasMHDR) || (!pData->bHasDHDR)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen < 6) /* must be at least 6 long */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_dbykp)*ppChunk)->iChunkname = mng_get_uint32 (pRawdata); + ((mng_dbykp)*ppChunk)->iPolarity = *(pRawdata+4); + ((mng_dbykp)*ppChunk)->iKeywordssize = iRawlen - 5; + + if (iRawlen > 5) + { + MNG_ALLOC (pData, ((mng_dbykp)*ppChunk)->zKeywords, iRawlen-4); + MNG_COPY (((mng_dbykp)*ppChunk)->zKeywords, pRawdata+5, iRawlen-5); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_DBYK, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR +READ_CHUNK (mng_read_ordr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_ORDR, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasMHDR) || (!pData->bHasDHDR)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* check length */ + if ((iRawlen < 5) || ((iRawlen % 5) != 0)) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#ifdef MNG_SUPPORT_DISPLAY + { + + + /* TODO: something !!! */ + + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_ordrp)*ppChunk)->iCount = iRawlen / 5; + + if (iRawlen) + { + mng_uint32 iX; + mng_ordr_entryp pEntry; + mng_uint8p pTemp = pRawdata; + + MNG_ALLOC (pData, pEntry, iRawlen); + + ((mng_ordrp)*ppChunk)->pEntries = pEntry; + + for (iX = 0; iX < iRawlen / 5; iX++) + { + pEntry->iChunkname = mng_get_uint32 (pTemp); + pEntry->iOrdertype = *(pTemp+4); + + pTemp += 5; + pEntry++; + } + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_ORDR, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_MAGN +READ_CHUNK (mng_read_magn) +{ + mng_uint16 iFirstid, iLastid; + mng_uint8 iMethodX, iMethodY; + mng_uint16 iMX, iMY, iML, iMR, iMT, iMB; + mng_bool bFaulty; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_MAGN, MNG_LC_START); +#endif + /* sequence checks */ +#ifdef MNG_SUPPORT_JNG + if ((!pData->bHasMHDR) || (pData->bHasIHDR) || (pData->bHasDHDR) || (pData->bHasJHDR)) +#else + if ((!pData->bHasMHDR) || (pData->bHasIHDR) || (pData->bHasDHDR)) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* check length */ + if (iRawlen > 20) + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + /* following is an ugly hack to allow faulty layout caused by previous + versions of libmng and MNGeye, which wrote MAGN with a 16-bit + MethodX/MethodY (as opposed to the proper 8-bit as defined in the spec!) */ + + if ((iRawlen == 6) || (iRawlen == 8) || (iRawlen == 10) || (iRawlen == 12) || + (iRawlen == 14) || (iRawlen == 16) || (iRawlen == 20)) + bFaulty = MNG_TRUE; /* these lengths are all wrong */ + else /* length 18 can be right or wrong !!! */ + if ((iRawlen == 18) && (mng_get_uint16 (pRawdata+4) <= 5) && + (mng_get_uint16 (pRawdata+6) < 256) && + (mng_get_uint16 (pRawdata+8) < 256) && + (mng_get_uint16 (pRawdata+10) < 256) && + (mng_get_uint16 (pRawdata+12) < 256) && + (mng_get_uint16 (pRawdata+14) < 256) && + (mng_get_uint16 (pRawdata+16) < 256)) + bFaulty = MNG_TRUE; /* this is very likely the wrong layout */ + else + bFaulty = MNG_FALSE; /* all other cases are handled as right */ + + if (bFaulty) /* wrong layout ? */ + { + if (iRawlen > 0) /* get the fields */ + iFirstid = mng_get_uint16 (pRawdata); + else + iFirstid = 0; + + if (iRawlen > 2) + iLastid = mng_get_uint16 (pRawdata+2); + else + iLastid = iFirstid; + + if (iRawlen > 4) + iMethodX = (mng_uint8)(mng_get_uint16 (pRawdata+4)); + else + iMethodX = 0; + + if (iRawlen > 6) + iMX = mng_get_uint16 (pRawdata+6); + else + iMX = 1; + + if (iRawlen > 8) + iMY = mng_get_uint16 (pRawdata+8); + else + iMY = iMX; + + if (iRawlen > 10) + iML = mng_get_uint16 (pRawdata+10); + else + iML = iMX; + + if (iRawlen > 12) + iMR = mng_get_uint16 (pRawdata+12); + else + iMR = iMX; + + if (iRawlen > 14) + iMT = mng_get_uint16 (pRawdata+14); + else + iMT = iMY; + + if (iRawlen > 16) + iMB = mng_get_uint16 (pRawdata+16); + else + iMB = iMY; + + if (iRawlen > 18) + iMethodY = (mng_uint8)(mng_get_uint16 (pRawdata+18)); + else + iMethodY = iMethodX; + } + else /* proper layout !!!! */ + { + if (iRawlen > 0) /* get the fields */ + iFirstid = mng_get_uint16 (pRawdata); + else + iFirstid = 0; + + if (iRawlen > 2) + iLastid = mng_get_uint16 (pRawdata+2); + else + iLastid = iFirstid; + + if (iRawlen > 4) + iMethodX = *(pRawdata+4); + else + iMethodX = 0; + + if (iRawlen > 5) + iMX = mng_get_uint16 (pRawdata+5); + else + iMX = 1; + + if (iRawlen > 7) + iMY = mng_get_uint16 (pRawdata+7); + else + iMY = iMX; + + if (iRawlen > 9) + iML = mng_get_uint16 (pRawdata+9); + else + iML = iMX; + + if (iRawlen > 11) + iMR = mng_get_uint16 (pRawdata+11); + else + iMR = iMX; + + if (iRawlen > 13) + iMT = mng_get_uint16 (pRawdata+13); + else + iMT = iMY; + + if (iRawlen > 15) + iMB = mng_get_uint16 (pRawdata+15); + else + iMB = iMY; + + if (iRawlen > 17) + iMethodY = *(pRawdata+17); + else + iMethodY = iMethodX; + } + /* check field validity */ + if ((iMethodX > 5) || (iMethodY > 5)) + MNG_ERROR (pData, MNG_INVALIDMETHOD); + +#ifdef MNG_SUPPORT_DISPLAY + { + mng_retcode iRetcode; + + iRetcode = mng_create_ani_magn (pData, iFirstid, iLastid, iMethodX, + iMX, iMY, iML, iMR, iMT, iMB, iMethodY); + +/* if (!iRetcode) + iRetcode = mng_process_display_magn (pData, iFirstid, iLastid, iMethodX, + iMX, iMY, iML, iMR, iMT, iMB, iMethodY); */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_magnp)*ppChunk)->iFirstid = iFirstid; + ((mng_magnp)*ppChunk)->iLastid = iLastid; + ((mng_magnp)*ppChunk)->iMethodX = iMethodX; + ((mng_magnp)*ppChunk)->iMX = iMX; + ((mng_magnp)*ppChunk)->iMY = iMY; + ((mng_magnp)*ppChunk)->iML = iML; + ((mng_magnp)*ppChunk)->iMR = iMR; + ((mng_magnp)*ppChunk)->iMT = iMT; + ((mng_magnp)*ppChunk)->iMB = iMB; + ((mng_magnp)*ppChunk)->iMethodY = iMethodY; + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_MAGN, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_INCLUDE_MPNG_PROPOSAL +READ_CHUNK (mng_read_mpng) +{ + mng_uint32 iFramewidth; + mng_uint32 iFrameheight; + mng_uint16 iTickspersec; + mng_uint32 iFramessize; + mng_uint32 iCompressedsize; +#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) + mng_retcode iRetcode; + mng_uint16 iNumplays; + mng_uint32 iBufsize; + mng_uint8p pBuf = 0; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_MPNG, MNG_LC_START); +#endif + /* sequence checks */ + if (!pData->bHasIHDR) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen < 41) /* length must be at least 41 */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + + iFramewidth = mng_get_int32 (pRawdata); + if (iFramewidth == 0) /* frame_width must not be zero */ + MNG_ERROR (pData, MNG_INVALIDWIDTH); + + iFrameheight = mng_get_int32 (pRawdata+4); + if (iFrameheight == 0) /* frame_height must not be zero */ + MNG_ERROR (pData, MNG_INVALIDHEIGHT); + + iTickspersec = mng_get_uint16 (pRawdata+10); + if (iTickspersec == 0) /* delay_den must not be zero */ + MNG_ERROR (pData, MNG_INVALIDFIELDVAL); + + if (*(pRawdata+12) != 0) /* only deflate compression-method allowed */ + MNG_ERROR (pData, MNG_INVALIDCOMPRESS); + +#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) + iNumplays = mng_get_uint16 (pRawdata+8); + iCompressedsize = (mng_uint32)(iRawlen - 13); +#endif + +#ifdef MNG_SUPPORT_DISPLAY + { + iRetcode = mng_inflate_buffer (pData, pRawdata+13, iCompressedsize, + &pBuf, &iBufsize, &iFramessize); + if (iRetcode) /* on error bail out */ + { + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + + if (iFramessize % 26) + { + MNG_FREEX (pData, pBuf, iBufsize); + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } + + iRetcode = mng_create_mpng_obj (pData, iFramewidth, iFrameheight, iNumplays, + iTickspersec, iFramessize, pBuf); + if (iRetcode) /* on error bail out */ + { + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + } +#endif /* MNG_SUPPORT_DISPLAY */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the fields */ + ((mng_mpngp)*ppChunk)->iFramewidth = iFramewidth; + ((mng_mpngp)*ppChunk)->iFrameheight = iFrameheight; + ((mng_mpngp)*ppChunk)->iNumplays = iNumplays; + ((mng_mpngp)*ppChunk)->iTickspersec = iTickspersec; + ((mng_mpngp)*ppChunk)->iCompressionmethod = *(pRawdata+14); + +#ifndef MNG_SUPPORT_DISPLAY + iRetcode = mng_inflate_buffer (pData, pRawdata+13, iCompressedsize, + &pBuf, &iBufsize, &iFramessize); + if (iRetcode) /* on error bail out */ + { + MNG_FREEX (pData, pBuf, iBufsize); + return iRetcode; + } + + if (iFramessize % 26) + { + MNG_FREEX (pData, pBuf, iBufsize); + MNG_ERROR (pData, MNG_INVALIDLENGTH); + } +#endif + + if (iFramessize) + { + MNG_ALLOCX (pData, ((mng_mpngp)*ppChunk)->pFrames, iFramessize); + if (((mng_mpngp)*ppChunk)->pFrames == 0) + { + MNG_FREEX (pData, pBuf, iBufsize); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + + ((mng_mpngp)*ppChunk)->iFramessize = iFramessize; + MNG_COPY (((mng_mpngp)*ppChunk)->pFrames, pBuf, iFramessize); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS) + MNG_FREEX (pData, pBuf, iBufsize); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_MPNG, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifndef MNG_SKIPCHUNK_evNT +READ_CHUNK (mng_read_evnt) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_EVNT, MNG_LC_START); +#endif + /* sequence checks */ + if ((!pData->bHasMHDR) || (pData->bHasSAVE)) + MNG_ERROR (pData, MNG_SEQUENCEERROR); + + if (iRawlen < 2) /* must have at least 1 entry ! */ + MNG_ERROR (pData, MNG_INVALIDLENGTH); + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_SUPPORT_DYNAMICMNG) + { + if (iRawlen) /* not empty ? */ + { + mng_retcode iRetcode; + mng_uint8p pTemp; + mng_uint8p pNull; + mng_uint32 iLen; + mng_uint8 iEventtype; + mng_uint8 iMasktype; + mng_int32 iLeft; + mng_int32 iRight; + mng_int32 iTop; + mng_int32 iBottom; + mng_uint16 iObjectid; + mng_uint8 iIndex; + mng_uint32 iNamesize; + + pTemp = pRawdata; + iLen = iRawlen; + + while (iLen) /* anything left ? */ + { + iEventtype = *pTemp; /* eventtype */ + if (iEventtype > 5) + MNG_ERROR (pData, MNG_INVALIDEVENT); + + pTemp++; + + iMasktype = *pTemp; /* masktype */ + if (iMasktype > 5) + MNG_ERROR (pData, MNG_INVALIDMASK); + + pTemp++; + iLen -= 2; + + iLeft = 0; + iRight = 0; + iTop = 0; + iBottom = 0; + iObjectid = 0; + iIndex = 0; + + switch (iMasktype) + { + case 1 : + { + if (iLen > 16) + { + iLeft = mng_get_int32 (pTemp); + iRight = mng_get_int32 (pTemp+4); + iTop = mng_get_int32 (pTemp+8); + iBottom = mng_get_int32 (pTemp+12); + pTemp += 16; + iLen -= 16; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + case 2 : + { + if (iLen > 2) + { + iObjectid = mng_get_uint16 (pTemp); + pTemp += 2; + iLen -= 2; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + case 3 : + { + if (iLen > 3) + { + iObjectid = mng_get_uint16 (pTemp); + iIndex = *(pTemp+2); + pTemp += 3; + iLen -= 3; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + case 4 : + { + if (iLen > 18) + { + iLeft = mng_get_int32 (pTemp); + iRight = mng_get_int32 (pTemp+4); + iTop = mng_get_int32 (pTemp+8); + iBottom = mng_get_int32 (pTemp+12); + iObjectid = mng_get_uint16 (pTemp+16); + pTemp += 18; + iLen -= 18; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + case 5 : + { + if (iLen > 19) + { + iLeft = mng_get_int32 (pTemp); + iRight = mng_get_int32 (pTemp+4); + iTop = mng_get_int32 (pTemp+8); + iBottom = mng_get_int32 (pTemp+12); + iObjectid = mng_get_uint16 (pTemp+16); + iIndex = *(pTemp+18); + pTemp += 19; + iLen -= 19; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + } + + pNull = find_null (pTemp); /* get the name length */ + + if ((pNull - pTemp) > (mng_int32)iLen) + { + iNamesize = iLen; /* no null found; so end of evNT */ + iLen = 0; + } + else + { + iNamesize = pNull - pTemp; /* should be another entry */ + iLen = iLen - iNamesize - 1; + + if (!iLen) /* must not end with a null ! */ + MNG_ERROR (pData, MNG_ENDWITHNULL); + } + + iRetcode = mng_create_event (pData, iEventtype, iMasktype, iLeft, iRight, + iTop, iBottom, iObjectid, iIndex, + iNamesize, (mng_pchar)pTemp); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + pTemp = pTemp + iNamesize + 1; + } + } + } +#endif /* MNG_SUPPORT_DISPLAY && MNG_SUPPORT_DYNAMICMNG */ + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + if (iRawlen) /* not empty ? */ + { + mng_uint32 iX; + mng_uint32 iCount = 0; + mng_uint8p pTemp; + mng_uint8p pNull; + mng_uint32 iLen; + mng_uint8 iEventtype; + mng_uint8 iMasktype; + mng_int32 iLeft; + mng_int32 iRight; + mng_int32 iTop; + mng_int32 iBottom; + mng_uint16 iObjectid; + mng_uint8 iIndex; + mng_uint32 iNamesize; + mng_evnt_entryp pEntry = MNG_NULL; + + for (iX = 0; iX < 2; iX++) /* do this twice to get the count first ! */ + { + pTemp = pRawdata; + iLen = iRawlen; + + if (iX) /* second run ? */ + { + MNG_ALLOC (pData, pEntry, (iCount * sizeof (mng_evnt_entry))); + + ((mng_evntp)*ppChunk)->iCount = iCount; + ((mng_evntp)*ppChunk)->pEntries = pEntry; + } + + while (iLen) /* anything left ? */ + { + iEventtype = *pTemp; /* eventtype */ + if (iEventtype > 5) + MNG_ERROR (pData, MNG_INVALIDEVENT); + + pTemp++; + + iMasktype = *pTemp; /* masktype */ + if (iMasktype > 5) + MNG_ERROR (pData, MNG_INVALIDMASK); + + pTemp++; + iLen -= 2; + + iLeft = 0; + iRight = 0; + iTop = 0; + iBottom = 0; + iObjectid = 0; + iIndex = 0; + + switch (iMasktype) + { + case 1 : + { + if (iLen > 16) + { + iLeft = mng_get_int32 (pTemp); + iRight = mng_get_int32 (pTemp+4); + iTop = mng_get_int32 (pTemp+8); + iBottom = mng_get_int32 (pTemp+12); + pTemp += 16; + iLen -= 16; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + case 2 : + { + if (iLen > 2) + { + iObjectid = mng_get_uint16 (pTemp); + pTemp += 2; + iLen -= 2; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + case 3 : + { + if (iLen > 3) + { + iObjectid = mng_get_uint16 (pTemp); + iIndex = *(pTemp+2); + pTemp += 3; + iLen -= 3; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + case 4 : + { + if (iLen > 18) + { + iLeft = mng_get_int32 (pTemp); + iRight = mng_get_int32 (pTemp+4); + iTop = mng_get_int32 (pTemp+8); + iBottom = mng_get_int32 (pTemp+12); + iObjectid = mng_get_uint16 (pTemp+16); + pTemp += 18; + iLen -= 18; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + case 5 : + { + if (iLen > 19) + { + iLeft = mng_get_int32 (pTemp); + iRight = mng_get_int32 (pTemp+4); + iTop = mng_get_int32 (pTemp+8); + iBottom = mng_get_int32 (pTemp+12); + iObjectid = mng_get_uint16 (pTemp+16); + iIndex = *(pTemp+18); + pTemp += 19; + iLen -= 19; + } + else + MNG_ERROR (pData, MNG_INVALIDLENGTH); + break; + } + } + + pNull = find_null (pTemp); /* get the name length */ + + if ((pNull - pTemp) > (mng_int32)iLen) + { + iNamesize = iLen; /* no null found; so end of evNT */ + iLen = 0; + } + else + { + iNamesize = pNull - pTemp; /* should be another entry */ + iLen = iLen - iNamesize - 1; + + if (!iLen) /* must not end with a null ! */ + MNG_ERROR (pData, MNG_ENDWITHNULL); + } + + if (!iX) + { + iCount++; + } + else + { + pEntry->iEventtype = iEventtype; + pEntry->iMasktype = iMasktype; + pEntry->iLeft = iLeft; + pEntry->iRight = iRight; + pEntry->iTop = iTop; + pEntry->iBottom = iBottom; + pEntry->iObjectid = iObjectid; + pEntry->iIndex = iIndex; + pEntry->iSegmentnamesize = iNamesize; + + if (iNamesize) + { + MNG_ALLOC (pData, pEntry->zSegmentname, iNamesize+1); + MNG_COPY (pEntry->zSegmentname, pTemp, iNamesize); + } + + pEntry++; + } + + pTemp = pTemp + iNamesize + 1; + } + } + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_EVNT, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +READ_CHUNK (mng_read_unknown) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_UNKNOWN, MNG_LC_START); +#endif + /* sequence checks */ +#ifdef MNG_INCLUDE_JNG + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && + (!pData->bHasBASI) && (!pData->bHasDHDR) ) +#endif + MNG_ERROR (pData, MNG_SEQUENCEERROR); + /* critical chunk ? */ + if ((((mng_uint32)pData->iChunkname & 0x20000000) == 0) +#ifdef MNG_SKIPCHUNK_SAVE + && (pData->iChunkname != MNG_UINT_SAVE) +#endif +#ifdef MNG_SKIPCHUNK_SEEK + && (pData->iChunkname != MNG_UINT_SEEK) +#endif +#ifdef MNG_SKIPCHUNK_DBYK + && (pData->iChunkname != MNG_UINT_DBYK) +#endif +#ifdef MNG_SKIPCHUNK_ORDR + && (pData->iChunkname != MNG_UINT_ORDR) +#endif + ) + MNG_ERROR (pData, MNG_UNKNOWNCRITICAL); + + if (pData->fProcessunknown) /* let the app handle it ? */ + { + mng_bool bOke = pData->fProcessunknown ((mng_handle)pData, pData->iChunkname, + iRawlen, (mng_ptr)pRawdata); + + if (!bOke) + MNG_ERROR (pData, MNG_APPMISCERROR); + } + +#ifdef MNG_STORE_CHUNKS + if (pData->bStorechunks) + { /* initialize storage */ + mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* store the length */ + ((mng_chunk_headerp)*ppChunk)->iChunkname = pData->iChunkname; + ((mng_unknown_chunkp)*ppChunk)->iDatasize = iRawlen; + + if (iRawlen == 0) /* any data at all ? */ + ((mng_unknown_chunkp)*ppChunk)->pData = 0; + else + { /* then store it */ + MNG_ALLOC (pData, ((mng_unknown_chunkp)*ppChunk)->pData, iRawlen); + MNG_COPY (((mng_unknown_chunkp)*ppChunk)->pData, pRawdata, iRawlen); + } + } +#endif /* MNG_STORE_CHUNKS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_UNKNOWN, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} +#endif + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_READ_PROCS */ + +/* ************************************************************************** */ +/* * * */ +/* * chunk write functions * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_WRITE_PROCS + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_ihdr) +{ + mng_ihdrp pIHDR; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_IHDR, MNG_LC_START); +#endif + + pIHDR = (mng_ihdrp)pChunk; /* address the proper chunk */ + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 13; + /* fill the output buffer */ + mng_put_uint32 (pRawdata, pIHDR->iWidth); + mng_put_uint32 (pRawdata+4, pIHDR->iHeight); + + *(pRawdata+8) = pIHDR->iBitdepth; + *(pRawdata+9) = pIHDR->iColortype; + *(pRawdata+10) = pIHDR->iCompression; + *(pRawdata+11) = pIHDR->iFilter; + *(pRawdata+12) = pIHDR->iInterlace; + /* and write it */ + iRetcode = write_raw_chunk (pData, pIHDR->sHeader.iChunkname, iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_IHDR, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_plte) +{ + mng_pltep pPLTE; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_uint8p pTemp; + mng_uint32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_PLTE, MNG_LC_START); +#endif + + pPLTE = (mng_pltep)pChunk; /* address the proper chunk */ + + if (pPLTE->bEmpty) /* write empty chunk ? */ + iRetcode = write_raw_chunk (pData, pPLTE->sHeader.iChunkname, 0, 0); + else + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = pPLTE->iEntrycount * 3; + /* fill the output buffer */ + pTemp = pRawdata; + + for (iX = 0; iX < pPLTE->iEntrycount; iX++) + { + *pTemp = pPLTE->aEntries [iX].iRed; + *(pTemp+1) = pPLTE->aEntries [iX].iGreen; + *(pTemp+2) = pPLTE->aEntries [iX].iBlue; + + pTemp += 3; + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pPLTE->sHeader.iChunkname, iRawlen, pRawdata); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_PLTE, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_idat) +{ + mng_idatp pIDAT; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_IDAT, MNG_LC_START); +#endif + + pIDAT = (mng_idatp)pChunk; /* address the proper chunk */ + + if (pIDAT->bEmpty) /* and write it */ + iRetcode = write_raw_chunk (pData, pIDAT->sHeader.iChunkname, 0, 0); + else + iRetcode = write_raw_chunk (pData, pIDAT->sHeader.iChunkname, + pIDAT->iDatasize, pIDAT->pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_IDAT, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_iend) +{ + mng_iendp pIEND; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_IEND, MNG_LC_START); +#endif + + pIEND = (mng_iendp)pChunk; /* address the proper chunk */ + /* and write it */ + iRetcode = write_raw_chunk (pData, pIEND->sHeader.iChunkname, 0, 0); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_IEND, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_trns) +{ + mng_trnsp pTRNS; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_uint8p pTemp; + mng_uint32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_TRNS, MNG_LC_START); +#endif + + pTRNS = (mng_trnsp)pChunk; /* address the proper chunk */ + + if (pTRNS->bEmpty) /* write empty chunk ? */ + iRetcode = write_raw_chunk (pData, pTRNS->sHeader.iChunkname, 0, 0); + else + if (pTRNS->bGlobal) /* write global chunk ? */ + iRetcode = write_raw_chunk (pData, pTRNS->sHeader.iChunkname, + pTRNS->iRawlen, (mng_uint8p)pTRNS->aRawdata); + else + { + pRawdata = pData->pWritebuf+8; /* init output buffer */ + iRawlen = 0; /* and default size */ + + switch (pTRNS->iType) + { + case 0: { + iRawlen = 2; /* fill the size & output buffer */ + mng_put_uint16 (pRawdata, pTRNS->iGray); + + break; + } + case 2: { + iRawlen = 6; /* fill the size & output buffer */ + mng_put_uint16 (pRawdata, pTRNS->iRed); + mng_put_uint16 (pRawdata+2, pTRNS->iGreen); + mng_put_uint16 (pRawdata+4, pTRNS->iBlue); + + break; + } + case 3: { /* init output buffer size */ + iRawlen = pTRNS->iCount; + + pTemp = pRawdata; /* fill the output buffer */ + + for (iX = 0; iX < pTRNS->iCount; iX++) + { + *pTemp = pTRNS->aEntries[iX]; + pTemp++; + } + + break; + } + } + /* write the chunk */ + iRetcode = write_raw_chunk (pData, pTRNS->sHeader.iChunkname, + iRawlen, pRawdata); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_TRNS, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_gama) +{ + mng_gamap pGAMA; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_GAMA, MNG_LC_START); +#endif + + pGAMA = (mng_gamap)pChunk; /* address the proper chunk */ + + if (pGAMA->bEmpty) /* write empty ? */ + iRetcode = write_raw_chunk (pData, pGAMA->sHeader.iChunkname, 0, 0); + else + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 4; + /* fill the buffer */ + mng_put_uint32 (pRawdata, pGAMA->iGamma); + /* and write it */ + iRetcode = write_raw_chunk (pData, pGAMA->sHeader.iChunkname, + iRawlen, pRawdata); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_GAMA, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_cHRM +WRITE_CHUNK (mng_write_chrm) +{ + mng_chrmp pCHRM; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_CHRM, MNG_LC_START); +#endif + + pCHRM = (mng_chrmp)pChunk; /* address the proper chunk */ + + if (pCHRM->bEmpty) /* write empty ? */ + iRetcode = write_raw_chunk (pData, pCHRM->sHeader.iChunkname, 0, 0); + else + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 32; + /* fill the buffer */ + mng_put_uint32 (pRawdata, pCHRM->iWhitepointx); + mng_put_uint32 (pRawdata+4, pCHRM->iWhitepointy); + mng_put_uint32 (pRawdata+8, pCHRM->iRedx); + mng_put_uint32 (pRawdata+12, pCHRM->iRedy); + mng_put_uint32 (pRawdata+16, pCHRM->iGreenx); + mng_put_uint32 (pRawdata+20, pCHRM->iGreeny); + mng_put_uint32 (pRawdata+24, pCHRM->iBluex); + mng_put_uint32 (pRawdata+28, pCHRM->iBluey); + /* and write it */ + iRetcode = write_raw_chunk (pData, pCHRM->sHeader.iChunkname, + iRawlen, pRawdata); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_CHRM, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_srgb) +{ + mng_srgbp pSRGB; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_SRGB, MNG_LC_START); +#endif + + pSRGB = (mng_srgbp)pChunk; /* address the proper chunk */ + + if (pSRGB->bEmpty) /* write empty ? */ + iRetcode = write_raw_chunk (pData, pSRGB->sHeader.iChunkname, 0, 0); + else + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 1; + /* fill the buffer */ + *pRawdata = pSRGB->iRenderingintent; + /* and write it */ + iRetcode = write_raw_chunk (pData, pSRGB->sHeader.iChunkname, + iRawlen, pRawdata); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_SRGB, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iCCP +WRITE_CHUNK (mng_write_iccp) +{ + mng_iccpp pICCP; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_uint8p pTemp; + mng_uint8p pBuf = 0; + mng_uint32 iBuflen; + mng_uint32 iReallen; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_ICCP, MNG_LC_START); +#endif + + pICCP = (mng_iccpp)pChunk; /* address the proper chunk */ + + if (pICCP->bEmpty) /* write empty ? */ + iRetcode = write_raw_chunk (pData, pICCP->sHeader.iChunkname, 0, 0); + else + { /* compress the profile */ + iRetcode = deflate_buffer (pData, pICCP->pProfile, pICCP->iProfilesize, + &pBuf, &iBuflen, &iReallen); + + if (!iRetcode) /* still oke ? */ + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = pICCP->iNamesize + 2 + iReallen; + /* requires large buffer ? */ + if (iRawlen > pData->iWritebufsize) + MNG_ALLOC (pData, pRawdata, iRawlen); + + pTemp = pRawdata; /* fill the buffer */ + + if (pICCP->iNamesize) + { + MNG_COPY (pTemp, pICCP->zName, pICCP->iNamesize); + pTemp += pICCP->iNamesize; + } + + *pTemp = 0; + *(pTemp+1) = pICCP->iCompression; + pTemp += 2; + + if (iReallen) + MNG_COPY (pTemp, pBuf, iReallen); + /* and write it */ + iRetcode = write_raw_chunk (pData, pICCP->sHeader.iChunkname, + iRawlen, pRawdata); + /* drop the temp buffer ? */ + if (iRawlen > pData->iWritebufsize) + MNG_FREEX (pData, pRawdata, iRawlen); + + } + + MNG_FREEX (pData, pBuf, iBuflen); /* always drop the extra buffer */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_ICCP, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_tEXt +WRITE_CHUNK (mng_write_text) +{ + mng_textp pTEXT; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_uint8p pTemp; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_TEXT, MNG_LC_START); +#endif + + pTEXT = (mng_textp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = pTEXT->iKeywordsize + 1 + pTEXT->iTextsize; + /* requires large buffer ? */ + if (iRawlen > pData->iWritebufsize) + MNG_ALLOC (pData, pRawdata, iRawlen); + + pTemp = pRawdata; /* fill the buffer */ + + if (pTEXT->iKeywordsize) + { + MNG_COPY (pTemp, pTEXT->zKeyword, pTEXT->iKeywordsize); + pTemp += pTEXT->iKeywordsize; + } + + *pTemp = 0; + pTemp += 1; + + if (pTEXT->iTextsize) + MNG_COPY (pTemp, pTEXT->zText, pTEXT->iTextsize); + /* and write it */ + iRetcode = write_raw_chunk (pData, pTEXT->sHeader.iChunkname, + iRawlen, pRawdata); + + if (iRawlen > pData->iWritebufsize) /* drop the temp buffer ? */ + MNG_FREEX (pData, pRawdata, iRawlen); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_TEXT, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_zTXt +WRITE_CHUNK (mng_write_ztxt) +{ + mng_ztxtp pZTXT; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_uint8p pTemp; + mng_uint8p pBuf = 0; + mng_uint32 iBuflen; + mng_uint32 iReallen; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_ZTXT, MNG_LC_START); +#endif + + pZTXT = (mng_ztxtp)pChunk; /* address the proper chunk */ + /* compress the text */ + iRetcode = deflate_buffer (pData, (mng_uint8p)pZTXT->zText, pZTXT->iTextsize, + &pBuf, &iBuflen, &iReallen); + + if (!iRetcode) /* all ok ? */ + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = pZTXT->iKeywordsize + 2 + iReallen; + /* requires large buffer ? */ + if (iRawlen > pData->iWritebufsize) + MNG_ALLOC (pData, pRawdata, iRawlen); + + pTemp = pRawdata; /* fill the buffer */ + + if (pZTXT->iKeywordsize) + { + MNG_COPY (pTemp, pZTXT->zKeyword, pZTXT->iKeywordsize); + pTemp += pZTXT->iKeywordsize; + } + + *pTemp = 0; /* terminator zero */ + pTemp++; + *pTemp = 0; /* compression type */ + pTemp++; + + if (iReallen) + MNG_COPY (pTemp, pBuf, iReallen); + /* and write it */ + iRetcode = write_raw_chunk (pData, pZTXT->sHeader.iChunkname, + iRawlen, pRawdata); + /* drop the temp buffer ? */ + if (iRawlen > pData->iWritebufsize) + MNG_FREEX (pData, pRawdata, iRawlen); + + } + + MNG_FREEX (pData, pBuf, iBuflen); /* always drop the compression buffer */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_ZTXT, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iTXt +WRITE_CHUNK (mng_write_itxt) +{ + mng_itxtp pITXT; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_uint8p pTemp; + mng_uint8p pBuf = 0; + mng_uint32 iBuflen; + mng_uint32 iReallen; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_ITXT, MNG_LC_START); +#endif + + pITXT = (mng_itxtp)pChunk; /* address the proper chunk */ + + if (pITXT->iCompressionflag) /* compress the text */ + iRetcode = deflate_buffer (pData, (mng_uint8p)pITXT->zText, pITXT->iTextsize, + &pBuf, &iBuflen, &iReallen); + else + iRetcode = MNG_NOERROR; + + if (!iRetcode) /* all ok ? */ + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = pITXT->iKeywordsize + pITXT->iLanguagesize + + pITXT->iTranslationsize + 5; + + if (pITXT->iCompressionflag) + iRawlen = iRawlen + iReallen; + else + iRawlen = iRawlen + pITXT->iTextsize; + /* requires large buffer ? */ + if (iRawlen > pData->iWritebufsize) + MNG_ALLOC (pData, pRawdata, iRawlen); + + pTemp = pRawdata; /* fill the buffer */ + + if (pITXT->iKeywordsize) + { + MNG_COPY (pTemp, pITXT->zKeyword, pITXT->iKeywordsize); + pTemp += pITXT->iKeywordsize; + } + + *pTemp = 0; + pTemp++; + *pTemp = pITXT->iCompressionflag; + pTemp++; + *pTemp = pITXT->iCompressionmethod; + pTemp++; + + if (pITXT->iLanguagesize) + { + MNG_COPY (pTemp, pITXT->zLanguage, pITXT->iLanguagesize); + pTemp += pITXT->iLanguagesize; + } + + *pTemp = 0; + pTemp++; + + if (pITXT->iTranslationsize) + { + MNG_COPY (pTemp, pITXT->zTranslation, pITXT->iTranslationsize); + pTemp += pITXT->iTranslationsize; + } + + *pTemp = 0; + pTemp++; + + if (pITXT->iCompressionflag) + { + if (iReallen) + MNG_COPY (pTemp, pBuf, iReallen); + } + else + { + if (pITXT->iTextsize) + MNG_COPY (pTemp, pITXT->zText, pITXT->iTextsize); + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pITXT->sHeader.iChunkname, + iRawlen, pRawdata); + /* drop the temp buffer ? */ + if (iRawlen > pData->iWritebufsize) + MNG_FREEX (pData, pRawdata, iRawlen); + + } + + MNG_FREEX (pData, pBuf, iBuflen); /* always drop the compression buffer */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_ITXT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_bKGD +WRITE_CHUNK (mng_write_bkgd) +{ + mng_bkgdp pBKGD; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_BKGD, MNG_LC_START); +#endif + + pBKGD = (mng_bkgdp)pChunk; /* address the proper chunk */ + + if (pBKGD->bEmpty) /* write empty ? */ + iRetcode = write_raw_chunk (pData, pBKGD->sHeader.iChunkname, 0, 0); + else + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 0; /* and default size */ + + switch (pBKGD->iType) + { + case 0: { /* gray */ + iRawlen = 2; /* fill the size & output buffer */ + mng_put_uint16 (pRawdata, pBKGD->iGray); + + break; + } + case 2: { /* rgb */ + iRawlen = 6; /* fill the size & output buffer */ + mng_put_uint16 (pRawdata, pBKGD->iRed); + mng_put_uint16 (pRawdata+2, pBKGD->iGreen); + mng_put_uint16 (pRawdata+4, pBKGD->iBlue); + + break; + } + case 3: { /* indexed */ + iRawlen = 1; /* fill the size & output buffer */ + *pRawdata = pBKGD->iIndex; + + break; + } + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pBKGD->sHeader.iChunkname, + iRawlen, pRawdata); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_BKGD, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_pHYs +WRITE_CHUNK (mng_write_phys) +{ + mng_physp pPHYS; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_PHYS, MNG_LC_START); +#endif + + pPHYS = (mng_physp)pChunk; /* address the proper chunk */ + + if (pPHYS->bEmpty) /* write empty ? */ + iRetcode = write_raw_chunk (pData, pPHYS->sHeader.iChunkname, 0, 0); + else + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 9; + /* fill the output buffer */ + mng_put_uint32 (pRawdata, pPHYS->iSizex); + mng_put_uint32 (pRawdata+4, pPHYS->iSizey); + + *(pRawdata+8) = pPHYS->iUnit; + /* and write it */ + iRetcode = write_raw_chunk (pData, pPHYS->sHeader.iChunkname, + iRawlen, pRawdata); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_PHYS, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sBIT +WRITE_CHUNK (mng_write_sbit) +{ + mng_sbitp pSBIT; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_SBIT, MNG_LC_START); +#endif + + pSBIT = (mng_sbitp)pChunk; /* address the proper chunk */ + + if (pSBIT->bEmpty) /* write empty ? */ + iRetcode = write_raw_chunk (pData, pSBIT->sHeader.iChunkname, 0, 0); + else + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 0; /* and default size */ + + switch (pSBIT->iType) + { + case 0: { /* gray */ + iRawlen = 1; /* fill the size & output buffer */ + *pRawdata = pSBIT->aBits[0]; + + break; + } + case 2: { /* rgb */ + iRawlen = 3; /* fill the size & output buffer */ + *pRawdata = pSBIT->aBits[0]; + *(pRawdata+1) = pSBIT->aBits[1]; + *(pRawdata+2) = pSBIT->aBits[2]; + + break; + } + case 3: { /* indexed */ + iRawlen = 3; /* fill the size & output buffer */ + *pRawdata = pSBIT->aBits[0]; + *pRawdata = pSBIT->aBits[1]; + *pRawdata = pSBIT->aBits[2]; + + break; + } + case 4: { /* gray + alpha */ + iRawlen = 2; /* fill the size & output buffer */ + *pRawdata = pSBIT->aBits[0]; + *(pRawdata+1) = pSBIT->aBits[1]; + + break; + } + case 6: { /* rgb + alpha */ + iRawlen = 4; /* fill the size & output buffer */ + *pRawdata = pSBIT->aBits[0]; + *(pRawdata+1) = pSBIT->aBits[1]; + *(pRawdata+2) = pSBIT->aBits[2]; + *(pRawdata+3) = pSBIT->aBits[3]; + + break; + } + case 10: { /* jpeg gray */ + iRawlen = 1; /* fill the size & output buffer */ + *pRawdata = pSBIT->aBits[0]; + + break; + } + case 12: { /* jpeg rgb */ + iRawlen = 3; /* fill the size & output buffer */ + *pRawdata = pSBIT->aBits[0]; + *(pRawdata+1) = pSBIT->aBits[1]; + *(pRawdata+2) = pSBIT->aBits[2]; + + break; + } + case 14: { /* jpeg gray + alpha */ + iRawlen = 2; /* fill the size & output buffer */ + *pRawdata = pSBIT->aBits[0]; + *(pRawdata+1) = pSBIT->aBits[1]; + + break; + } + case 16: { /* jpeg rgb + alpha */ + iRawlen = 4; /* fill the size & output buffer */ + *pRawdata = pSBIT->aBits[0]; + *(pRawdata+1) = pSBIT->aBits[1]; + *(pRawdata+2) = pSBIT->aBits[2]; + *(pRawdata+3) = pSBIT->aBits[3]; + + break; + } + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pSBIT->sHeader.iChunkname, + iRawlen, pRawdata); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_SBIT, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sPLT +WRITE_CHUNK (mng_write_splt) +{ + mng_spltp pSPLT; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_uint32 iEntrieslen; + mng_uint8p pTemp; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_SPLT, MNG_LC_START); +#endif + + pSPLT = (mng_spltp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iEntrieslen = ((pSPLT->iSampledepth >> 3) * 4 + 2) * pSPLT->iEntrycount; + iRawlen = pSPLT->iNamesize + 2 + iEntrieslen; + /* requires large buffer ? */ + if (iRawlen > pData->iWritebufsize) + MNG_ALLOC (pData, pRawdata, iRawlen); + + pTemp = pRawdata; /* fill the buffer */ + + if (pSPLT->iNamesize) + { + MNG_COPY (pTemp, pSPLT->zName, pSPLT->iNamesize); + pTemp += pSPLT->iNamesize; + } + + *pTemp = 0; + *(pTemp+1) = pSPLT->iSampledepth; + pTemp += 2; + + if (pSPLT->iEntrycount) + MNG_COPY (pTemp, pSPLT->pEntries, iEntrieslen); + /* and write it */ + iRetcode = write_raw_chunk (pData, pSPLT->sHeader.iChunkname, + iRawlen, pRawdata); + + if (iRawlen > pData->iWritebufsize) /* drop the temp buffer ? */ + MNG_FREEX (pData, pRawdata, iRawlen); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_SPLT, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_hIST +WRITE_CHUNK (mng_write_hist) +{ + mng_histp pHIST; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_uint8p pTemp; + mng_uint32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_HIST, MNG_LC_START); +#endif + + pHIST = (mng_histp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = pHIST->iEntrycount << 1; + + pTemp = pRawdata; /* fill the output buffer */ + + for (iX = 0; iX < pHIST->iEntrycount; iX++) + { + mng_put_uint16 (pTemp, pHIST->aEntries [iX]); + pTemp += 2; + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pHIST->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_HIST, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_tIME +WRITE_CHUNK (mng_write_time) +{ + mng_timep pTIME; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_TIME, MNG_LC_START); +#endif + + pTIME = (mng_timep)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 7; + /* fill the output buffer */ + mng_put_uint16 (pRawdata, pTIME->iYear); + + *(pRawdata+2) = pTIME->iMonth; + *(pRawdata+3) = pTIME->iDay; + *(pRawdata+4) = pTIME->iHour; + *(pRawdata+5) = pTIME->iMinute; + *(pRawdata+6) = pTIME->iSecond; + /* and write it */ + iRetcode = write_raw_chunk (pData, pTIME->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_TIME, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_mhdr) +{ + mng_mhdrp pMHDR; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_MHDR, MNG_LC_START); +#endif + + pMHDR = (mng_mhdrp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 28; + /* fill the output buffer */ + mng_put_uint32 (pRawdata, pMHDR->iWidth); + mng_put_uint32 (pRawdata+4, pMHDR->iHeight); + mng_put_uint32 (pRawdata+8, pMHDR->iTicks); + mng_put_uint32 (pRawdata+12, pMHDR->iLayercount); + mng_put_uint32 (pRawdata+16, pMHDR->iFramecount); + mng_put_uint32 (pRawdata+20, pMHDR->iPlaytime); + mng_put_uint32 (pRawdata+24, pMHDR->iSimplicity); + + /* and write it */ + iRetcode = write_raw_chunk (pData, pMHDR->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_MHDR, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_mend) +{ + mng_mendp pMEND; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_MEND, MNG_LC_START); +#endif + + pMEND = (mng_mendp)pChunk; /* address the proper chunk */ + /* and write it */ + iRetcode = write_raw_chunk (pData, pMEND->sHeader.iChunkname, 0, 0); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_MEND, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_loop) +{ + mng_loopp pLOOP; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; +#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED + mng_uint8p pTemp1; + mng_uint32p pTemp2; + mng_uint32 iX; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_LOOP, MNG_LC_START); +#endif + + pLOOP = (mng_loopp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 5; + /* fill the output buffer */ + *pRawdata = pLOOP->iLevel; + mng_put_uint32 (pRawdata+1, pLOOP->iRepeat); + + if (pLOOP->iTermination) + { + iRawlen++; + *(pRawdata+5) = pLOOP->iTermination; + + if ((pLOOP->iCount) || + (pLOOP->iItermin != 1) || (pLOOP->iItermax != 0x7FFFFFFFL)) + { + iRawlen += 8; + + mng_put_uint32 (pRawdata+6, pLOOP->iItermin); + mng_put_uint32 (pRawdata+10, pLOOP->iItermax); + +#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED + if (pLOOP->iCount) + { + iRawlen += pLOOP->iCount * 4; + + pTemp1 = pRawdata+14; + pTemp2 = pLOOP->pSignals; + + for (iX = 0; iX < pLOOP->iCount; iX++) + { + mng_put_uint32 (pTemp1, *pTemp2); + + pTemp1 += 4; + pTemp2++; + } + } +#endif + } + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pLOOP->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_LOOP, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_endl) +{ + mng_endlp pENDL; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_ENDL, MNG_LC_START); +#endif + + pENDL = (mng_endlp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 1; + + *pRawdata = pENDL->iLevel; /* fill the output buffer */ + /* and write it */ + iRetcode = write_raw_chunk (pData, pENDL->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_ENDL, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_defi) +{ + mng_defip pDEFI; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_DEFI, MNG_LC_START); +#endif + + pDEFI = (mng_defip)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 2; + /* fill the output buffer */ + mng_put_uint16 (pRawdata, pDEFI->iObjectid); + + if ((pDEFI->iDonotshow) || (pDEFI->iConcrete) || (pDEFI->bHasloca) || (pDEFI->bHasclip)) + { + iRawlen++; + *(pRawdata+2) = pDEFI->iDonotshow; + + if ((pDEFI->iConcrete) || (pDEFI->bHasloca) || (pDEFI->bHasclip)) + { + iRawlen++; + *(pRawdata+3) = pDEFI->iConcrete; + + if ((pDEFI->bHasloca) || (pDEFI->bHasclip)) + { + iRawlen += 8; + + mng_put_uint32 (pRawdata+4, pDEFI->iXlocation); + mng_put_uint32 (pRawdata+8, pDEFI->iYlocation); + + if (pDEFI->bHasclip) + { + iRawlen += 16; + + mng_put_uint32 (pRawdata+12, pDEFI->iLeftcb); + mng_put_uint32 (pRawdata+16, pDEFI->iRightcb); + mng_put_uint32 (pRawdata+20, pDEFI->iTopcb); + mng_put_uint32 (pRawdata+24, pDEFI->iBottomcb); + } + } + } + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pDEFI->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_DEFI, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_basi) +{ + mng_basip pBASI; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_bool bOpaque; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_BASI, MNG_LC_START); +#endif + + pBASI = (mng_basip)pChunk; /* address the proper chunk */ + +#ifndef MNG_NO_16BIT_SUPPORT + if (pBASI->iBitdepth <= 8) /* determine opacity alpha-field */ +#endif + bOpaque = (mng_bool)(pBASI->iAlpha == 0xFF); +#ifndef MNG_NO_16BIT_SUPPORT + else + bOpaque = (mng_bool)(pBASI->iAlpha == 0xFFFF); +#endif + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 13; + /* fill the output buffer */ + mng_put_uint32 (pRawdata, pBASI->iWidth); + mng_put_uint32 (pRawdata+4, pBASI->iHeight); + + *(pRawdata+8) = pBASI->iBitdepth; + *(pRawdata+9) = pBASI->iColortype; + *(pRawdata+10) = pBASI->iCompression; + *(pRawdata+11) = pBASI->iFilter; + *(pRawdata+12) = pBASI->iInterlace; + + if ((pBASI->iRed) || (pBASI->iGreen) || (pBASI->iBlue) || + (!bOpaque) || (pBASI->iViewable)) + { + iRawlen += 6; + mng_put_uint16 (pRawdata+13, pBASI->iRed); + mng_put_uint16 (pRawdata+15, pBASI->iGreen); + mng_put_uint16 (pRawdata+17, pBASI->iBlue); + + if ((!bOpaque) || (pBASI->iViewable)) + { + iRawlen += 2; + mng_put_uint16 (pRawdata+19, pBASI->iAlpha); + + if (pBASI->iViewable) + { + iRawlen++; + *(pRawdata+21) = pBASI->iViewable; + } + } + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pBASI->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_BASI, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_clon) +{ + mng_clonp pCLON; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_CLON, MNG_LC_START); +#endif + + pCLON = (mng_clonp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 4; + /* fill the output buffer */ + mng_put_uint16 (pRawdata, pCLON->iSourceid); + mng_put_uint16 (pRawdata+2, pCLON->iCloneid); + + if ((pCLON->iClonetype) || (pCLON->iDonotshow) || (pCLON->iConcrete) || (pCLON->bHasloca)) + { + iRawlen++; + *(pRawdata+4) = pCLON->iClonetype; + + if ((pCLON->iDonotshow) || (pCLON->iConcrete) || (pCLON->bHasloca)) + { + iRawlen++; + *(pRawdata+5) = pCLON->iDonotshow; + + if ((pCLON->iConcrete) || (pCLON->bHasloca)) + { + iRawlen++; + *(pRawdata+6) = pCLON->iConcrete; + + if (pCLON->bHasloca) + { + iRawlen += 9; + *(pRawdata+7) = pCLON->iLocationtype; + mng_put_int32 (pRawdata+8, pCLON->iLocationx); + mng_put_int32 (pRawdata+12, pCLON->iLocationy); + } + } + } + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pCLON->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_CLON, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +WRITE_CHUNK (mng_write_past) +{ + mng_pastp pPAST; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_past_sourcep pSource; + mng_uint32 iX; + mng_uint8p pTemp; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_PAST, MNG_LC_START); +#endif + + pPAST = (mng_pastp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 11 + (30 * pPAST->iCount); + /* requires large buffer ? */ + if (iRawlen > pData->iWritebufsize) + MNG_ALLOC (pData, pRawdata, iRawlen); + /* fill the output buffer */ + mng_put_uint16 (pRawdata, pPAST->iDestid); + + *(pRawdata+2) = pPAST->iTargettype; + + mng_put_int32 (pRawdata+3, pPAST->iTargetx); + mng_put_int32 (pRawdata+7, pPAST->iTargety); + + pTemp = pRawdata+11; + pSource = pPAST->pSources; + + for (iX = 0; iX < pPAST->iCount; iX++) + { + mng_put_uint16 (pTemp, pSource->iSourceid); + + *(pTemp+2) = pSource->iComposition; + *(pTemp+3) = pSource->iOrientation; + *(pTemp+4) = pSource->iOffsettype; + + mng_put_int32 (pTemp+5, pSource->iOffsetx); + mng_put_int32 (pTemp+9, pSource->iOffsety); + + *(pTemp+13) = pSource->iBoundarytype; + + mng_put_int32 (pTemp+14, pSource->iBoundaryl); + mng_put_int32 (pTemp+18, pSource->iBoundaryr); + mng_put_int32 (pTemp+22, pSource->iBoundaryt); + mng_put_int32 (pTemp+26, pSource->iBoundaryb); + + pSource++; + pTemp += 30; + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pPAST->sHeader.iChunkname, + iRawlen, pRawdata); + /* free temporary buffer ? */ + if (iRawlen > pData->iWritebufsize) + MNG_FREEX (pData, pRawdata, iRawlen); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_PAST, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_disc) +{ + mng_discp pDISC; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_uint32 iX; + mng_uint8p pTemp1; + mng_uint16p pTemp2; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_DISC, MNG_LC_START); +#endif + + pDISC = (mng_discp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = pDISC->iCount << 1; + + pTemp1 = pRawdata; /* fill the output buffer */ + pTemp2 = pDISC->pObjectids; + + for (iX = 0; iX < pDISC->iCount; iX++) + { + mng_put_uint16 (pTemp1, *pTemp2); + + pTemp2++; + pTemp1 += 2; + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pDISC->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_DISC, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_back) +{ + mng_backp pBACK; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_BACK, MNG_LC_START); +#endif + + pBACK = (mng_backp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 6; + /* fill the output buffer */ + mng_put_uint16 (pRawdata, pBACK->iRed); + mng_put_uint16 (pRawdata+2, pBACK->iGreen); + mng_put_uint16 (pRawdata+4, pBACK->iBlue); + + if ((pBACK->iMandatory) || (pBACK->iImageid) || (pBACK->iTile)) + { + iRawlen++; + *(pRawdata+6) = pBACK->iMandatory; + + if ((pBACK->iImageid) || (pBACK->iTile)) + { + iRawlen += 2; + mng_put_uint16 (pRawdata+7, pBACK->iImageid); + + if (pBACK->iTile) + { + iRawlen++; + *(pRawdata+9) = pBACK->iTile; + } + } + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pBACK->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_BACK, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_fram) +{ + mng_framp pFRAM; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_uint8p pTemp; + mng_uint32p pTemp2; + mng_uint32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_FRAM, MNG_LC_START); +#endif + + pFRAM = (mng_framp)pChunk; /* address the proper chunk */ + + if (pFRAM->bEmpty) /* empty ? */ + iRetcode = write_raw_chunk (pData, pFRAM->sHeader.iChunkname, 0, 0); + else + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 1; + /* fill the output buffer */ + *pRawdata = pFRAM->iMode; + + if ((pFRAM->iNamesize ) || + (pFRAM->iChangedelay ) || (pFRAM->iChangetimeout) || + (pFRAM->iChangeclipping) || (pFRAM->iChangesyncid ) ) + { + if (pFRAM->iNamesize) + MNG_COPY (pRawdata+1, pFRAM->zName, pFRAM->iNamesize); + + iRawlen += pFRAM->iNamesize; + pTemp = pRawdata + pFRAM->iNamesize + 1; + + if ((pFRAM->iChangedelay ) || (pFRAM->iChangetimeout) || + (pFRAM->iChangeclipping) || (pFRAM->iChangesyncid ) ) + { + *pTemp = 0; + *(pTemp+1) = pFRAM->iChangedelay; + *(pTemp+2) = pFRAM->iChangetimeout; + *(pTemp+3) = pFRAM->iChangeclipping; + *(pTemp+4) = pFRAM->iChangesyncid; + + iRawlen += 5; + pTemp += 5; + + if (pFRAM->iChangedelay) + { + mng_put_uint32 (pTemp, pFRAM->iDelay); + iRawlen += 4; + pTemp += 4; + } + + if (pFRAM->iChangetimeout) + { + mng_put_uint32 (pTemp, pFRAM->iTimeout); + iRawlen += 4; + pTemp += 4; + } + + if (pFRAM->iChangeclipping) + { + *pTemp = pFRAM->iBoundarytype; + + mng_put_uint32 (pTemp+1, pFRAM->iBoundaryl); + mng_put_uint32 (pTemp+5, pFRAM->iBoundaryr); + mng_put_uint32 (pTemp+9, pFRAM->iBoundaryt); + mng_put_uint32 (pTemp+13, pFRAM->iBoundaryb); + + iRawlen += 17; + pTemp += 17; + } + + if (pFRAM->iChangesyncid) + { + iRawlen += pFRAM->iCount * 4; + pTemp2 = pFRAM->pSyncids; + + for (iX = 0; iX < pFRAM->iCount; iX++) + { + mng_put_uint32 (pTemp, *pTemp2); + + pTemp2++; + pTemp += 4; + } + } + } + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pFRAM->sHeader.iChunkname, + iRawlen, pRawdata); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_FRAM, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_move) +{ + mng_movep pMOVE; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_MOVE, MNG_LC_START); +#endif + + pMOVE = (mng_movep)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 13; + /* fill the output buffer */ + mng_put_uint16 (pRawdata, pMOVE->iFirstid); + mng_put_uint16 (pRawdata+2, pMOVE->iLastid); + + *(pRawdata+4) = pMOVE->iMovetype; + + mng_put_int32 (pRawdata+5, pMOVE->iMovex); + mng_put_int32 (pRawdata+9, pMOVE->iMovey); + /* and write it */ + iRetcode = write_raw_chunk (pData, pMOVE->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_MOVE, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_clip) +{ + mng_clipp pCLIP; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_CLIP, MNG_LC_START); +#endif + + pCLIP = (mng_clipp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 21; + /* fill the output buffer */ + mng_put_uint16 (pRawdata, pCLIP->iFirstid); + mng_put_uint16 (pRawdata+2, pCLIP->iLastid); + + *(pRawdata+4) = pCLIP->iCliptype; + + mng_put_int32 (pRawdata+5, pCLIP->iClipl); + mng_put_int32 (pRawdata+9, pCLIP->iClipr); + mng_put_int32 (pRawdata+13, pCLIP->iClipt); + mng_put_int32 (pRawdata+17, pCLIP->iClipb); + /* and write it */ + iRetcode = write_raw_chunk (pData, pCLIP->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_CLIP, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_show) +{ + mng_showp pSHOW; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_SHOW, MNG_LC_START); +#endif + + pSHOW = (mng_showp)pChunk; /* address the proper chunk */ + + if (pSHOW->bEmpty) /* empty ? */ + iRetcode = write_raw_chunk (pData, pSHOW->sHeader.iChunkname, 0, 0); + else + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 2; + /* fill the output buffer */ + mng_put_uint16 (pRawdata, pSHOW->iFirstid); + + if ((pSHOW->iLastid != pSHOW->iFirstid) || (pSHOW->iMode)) + { + iRawlen += 2; + mng_put_uint16 (pRawdata+2, pSHOW->iLastid); + + if (pSHOW->iMode) + { + iRawlen++; + *(pRawdata+4) = pSHOW->iMode; + } + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pSHOW->sHeader.iChunkname, + iRawlen, pRawdata); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_SHOW, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_term) +{ + mng_termp pTERM; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_TERM, MNG_LC_START); +#endif + + pTERM = (mng_termp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 1; + + *pRawdata = pTERM->iTermaction; /* fill the output buffer */ + + if (pTERM->iTermaction == 3) + { + iRawlen = 10; + *(pRawdata+1) = pTERM->iIteraction; + + mng_put_uint32 (pRawdata+2, pTERM->iDelay); + mng_put_uint32 (pRawdata+6, pTERM->iItermax); + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pTERM->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_TERM, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SAVE +WRITE_CHUNK (mng_write_save) +{ + mng_savep pSAVE; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_save_entryp pEntry; + mng_uint32 iEntrysize; + mng_uint8p pTemp; + mng_uint32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_SAVE, MNG_LC_START); +#endif + + pSAVE = (mng_savep)pChunk; /* address the proper chunk */ + + if (pSAVE->bEmpty) /* empty ? */ + iRetcode = write_raw_chunk (pData, pSAVE->sHeader.iChunkname, 0, 0); + else + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 1; + + *pRawdata = pSAVE->iOffsettype; /* fill the output buffer */ + + if (pSAVE->iOffsettype == 16) + iEntrysize = 25; + else + iEntrysize = 17; + + pTemp = pRawdata+1; + pEntry = pSAVE->pEntries; + + for (iX = 0; iX < pSAVE->iCount; iX++) + { + if (iX) /* put separator null-byte, except the first */ + { + *pTemp = 0; + pTemp++; + iRawlen++; + } + + iRawlen += iEntrysize + pEntry->iNamesize; + *pTemp = pEntry->iEntrytype; + + if (pSAVE->iOffsettype == 16) + { + mng_put_uint32 (pTemp+1, pEntry->iOffset[0]); + mng_put_uint32 (pTemp+5, pEntry->iOffset[1]); + mng_put_uint32 (pTemp+9, pEntry->iStarttime[0]); + mng_put_uint32 (pTemp+13, pEntry->iStarttime[1]); + mng_put_uint32 (pTemp+17, pEntry->iLayernr); + mng_put_uint32 (pTemp+21, pEntry->iFramenr); + + pTemp += 25; + } + else + { + mng_put_uint32 (pTemp+1, pEntry->iOffset[1]); + mng_put_uint32 (pTemp+5, pEntry->iStarttime[1]); + mng_put_uint32 (pTemp+9, pEntry->iLayernr); + mng_put_uint32 (pTemp+13, pEntry->iFramenr); + + pTemp += 17; + } + + if (pEntry->iNamesize) + { + MNG_COPY (pTemp, pEntry->zName, pEntry->iNamesize); + pTemp += pEntry->iNamesize; + } + + pEntry++; + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pSAVE->sHeader.iChunkname, + iRawlen, pRawdata); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_SAVE, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SEEK +WRITE_CHUNK (mng_write_seek) +{ + mng_seekp pSEEK; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_SEEK, MNG_LC_START); +#endif + + pSEEK = (mng_seekp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = pSEEK->iNamesize; + + if (iRawlen) /* fill the output buffer */ + MNG_COPY (pRawdata, pSEEK->zName, iRawlen); + /* and write it */ + iRetcode = write_raw_chunk (pData, pSEEK->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_SEEK, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_eXPI +WRITE_CHUNK (mng_write_expi) +{ + mng_expip pEXPI; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_EXPI, MNG_LC_START); +#endif + + pEXPI = (mng_expip)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 2 + pEXPI->iNamesize; + /* fill the output buffer */ + mng_put_uint16 (pRawdata, pEXPI->iSnapshotid); + + if (pEXPI->iNamesize) + MNG_COPY (pRawdata+2, pEXPI->zName, pEXPI->iNamesize); + /* and write it */ + iRetcode = write_raw_chunk (pData, pEXPI->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_EXPI, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_fPRI +WRITE_CHUNK (mng_write_fpri) +{ + mng_fprip pFPRI; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_FPRI, MNG_LC_START); +#endif + + pFPRI = (mng_fprip)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 2; + + *pRawdata = pFPRI->iDeltatype; /* fill the output buffer */ + *(pRawdata+1) = pFPRI->iPriority; + /* and write it */ + iRetcode = write_raw_chunk (pData, pFPRI->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_FPRI, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_nEED +WRITE_CHUNK (mng_write_need) +{ + mng_needp pNEED; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_NEED, MNG_LC_START); +#endif + + pNEED = (mng_needp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = pNEED->iKeywordssize; + /* fill the output buffer */ + if (pNEED->iKeywordssize) + MNG_COPY (pRawdata, pNEED->zKeywords, pNEED->iKeywordssize); + /* and write it */ + iRetcode = write_raw_chunk (pData, pNEED->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_NEED, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_pHYg +WRITE_CHUNK (mng_write_phyg) +{ + mng_phygp pPHYG; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_PHYG, MNG_LC_START); +#endif + + pPHYG = (mng_phygp)pChunk; /* address the proper chunk */ + + if (pPHYG->bEmpty) /* write empty ? */ + iRetcode = write_raw_chunk (pData, pPHYG->sHeader.iChunkname, 0, 0); + else + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 9; + /* fill the output buffer */ + mng_put_uint32 (pRawdata, pPHYG->iSizex); + mng_put_uint32 (pRawdata+4, pPHYG->iSizey); + + *(pRawdata+8) = pPHYG->iUnit; + /* and write it */ + iRetcode = write_raw_chunk (pData, pPHYG->sHeader.iChunkname, + iRawlen, pRawdata); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_PHYG, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +/* B004 */ +#ifdef MNG_INCLUDE_JNG +/* B004 */ +WRITE_CHUNK (mng_write_jhdr) +{ + mng_jhdrp pJHDR; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_JHDR, MNG_LC_START); +#endif + + pJHDR = (mng_jhdrp)pChunk; /* address the proper chunk */ + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 16; + /* fill the output buffer */ + mng_put_uint32 (pRawdata, pJHDR->iWidth); + mng_put_uint32 (pRawdata+4, pJHDR->iHeight); + + *(pRawdata+8) = pJHDR->iColortype; + *(pRawdata+9) = pJHDR->iImagesampledepth; + *(pRawdata+10) = pJHDR->iImagecompression; + *(pRawdata+11) = pJHDR->iImageinterlace; + *(pRawdata+12) = pJHDR->iAlphasampledepth; + *(pRawdata+13) = pJHDR->iAlphacompression; + *(pRawdata+14) = pJHDR->iAlphafilter; + *(pRawdata+15) = pJHDR->iAlphainterlace; + /* and write it */ + iRetcode = write_raw_chunk (pData, pJHDR->sHeader.iChunkname, iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_JHDR, MNG_LC_END); +#endif + + return iRetcode; +} +#else +#define write_jhdr 0 +/* B004 */ +#endif /* MNG_INCLUDE_JNG */ +/* B004 */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +WRITE_CHUNK (mng_write_jdaa) +{ + mng_jdatp pJDAA; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_JDAA, MNG_LC_START); +#endif + + pJDAA = (mng_jdaap)pChunk; /* address the proper chunk */ + + if (pJDAA->bEmpty) /* and write it */ + iRetcode = write_raw_chunk (pData, pJDAA->sHeader.iChunkname, 0, 0); + else + iRetcode = write_raw_chunk (pData, pJDAA->sHeader.iChunkname, + pJDAA->iDatasize, pJDAA->pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_JDAA, MNG_LC_END); +#endif + + return iRetcode; +} +#else +#define write_jdaa 0 +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +/* B004 */ +#ifdef MNG_INCLUDE_JNG +/* B004 */ +WRITE_CHUNK (mng_write_jdat) +{ + mng_jdatp pJDAT; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_JDAT, MNG_LC_START); +#endif + + pJDAT = (mng_jdatp)pChunk; /* address the proper chunk */ + + if (pJDAT->bEmpty) /* and write it */ + iRetcode = write_raw_chunk (pData, pJDAT->sHeader.iChunkname, 0, 0); + else + iRetcode = write_raw_chunk (pData, pJDAT->sHeader.iChunkname, + pJDAT->iDatasize, pJDAT->pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_JDAT, MNG_LC_END); +#endif + + return iRetcode; +} +#else +#define write_jdat 0 +/* B004 */ +#endif /* MNG_INCLUDE_JNG */ +/* B004 */ + +/* ************************************************************************** */ + +/* B004 */ +#ifdef MNG_INCLUDE_JNG +/* B004 */ +WRITE_CHUNK (mng_write_jsep) +{ + mng_jsepp pJSEP; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_JSEP, MNG_LC_START); +#endif + + pJSEP = (mng_jsepp)pChunk; /* address the proper chunk */ + /* and write it */ + iRetcode = write_raw_chunk (pData, pJSEP->sHeader.iChunkname, 0, 0); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_JSEP, MNG_LC_END); +#endif + + return iRetcode; +} +#else +#define write_jsep 0 +/* B004 */ +#endif /* MNG_INCLUDE_JNG */ +/* B004 */ + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +WRITE_CHUNK (mng_write_dhdr) +{ + mng_dhdrp pDHDR; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_DHDR, MNG_LC_START); +#endif + + pDHDR = (mng_dhdrp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 4; + /* fill the output buffer */ + mng_put_uint16 (pRawdata, pDHDR->iObjectid); + + *(pRawdata+2) = pDHDR->iImagetype; + *(pRawdata+3) = pDHDR->iDeltatype; + + if (pDHDR->iDeltatype != 7) + { + iRawlen += 8; + mng_put_uint32 (pRawdata+4, pDHDR->iBlockwidth); + mng_put_uint32 (pRawdata+8, pDHDR->iBlockheight); + + if (pDHDR->iDeltatype != 0) + { + iRawlen += 8; + mng_put_uint32 (pRawdata+12, pDHDR->iBlockx); + mng_put_uint32 (pRawdata+16, pDHDR->iBlocky); + } + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pDHDR->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_DHDR, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +WRITE_CHUNK (mng_write_prom) +{ + mng_promp pPROM; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_PROM, MNG_LC_START); +#endif + + pPROM = (mng_promp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 3; + + *pRawdata = pPROM->iColortype; /* fill the output buffer */ + *(pRawdata+1) = pPROM->iSampledepth; + *(pRawdata+2) = pPROM->iFilltype; + /* and write it */ + iRetcode = write_raw_chunk (pData, pPROM->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_PROM, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +WRITE_CHUNK (mng_write_ipng) +{ + mng_ipngp pIPNG; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_IPNG, MNG_LC_START); +#endif + + pIPNG = (mng_ipngp)pChunk; /* address the proper chunk */ + /* and write it */ + iRetcode = write_raw_chunk (pData, pIPNG->sHeader.iChunkname, 0, 0); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_IPNG, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +WRITE_CHUNK (mng_write_pplt) +{ + mng_ppltp pPPLT; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_pplt_entryp pEntry; + mng_uint8p pTemp; + mng_uint32 iX; + mng_bool bHasgroup; + mng_uint8p pLastid = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_PPLT, MNG_LC_START); +#endif + + pPPLT = (mng_ppltp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 1; + + *pRawdata = pPPLT->iDeltatype; /* fill the output buffer */ + + pTemp = pRawdata+1; + bHasgroup = MNG_FALSE; + + for (iX = 0; iX < pPPLT->iCount; iX++) + { + pEntry = &pPPLT->aEntries[iX]; + + if (pEntry->bUsed) /* valid entry ? */ + { + if (!bHasgroup) /* start a new group ? */ + { + bHasgroup = MNG_TRUE; + pLastid = pTemp+1; + + *pTemp = (mng_uint8)iX; + *(pTemp+1) = 0; + + pTemp += 2; + iRawlen += 2; + } + + switch (pPPLT->iDeltatype) /* add group-entry depending on type */ + { + case 0: ; + case 1: { + *pTemp = pEntry->iRed; + *(pTemp+1) = pEntry->iGreen; + *(pTemp+2) = pEntry->iBlue; + + pTemp += 3; + iRawlen += 3; + + break; + } + + case 2: ; + case 3: { + *pTemp = pEntry->iAlpha; + + pTemp++; + iRawlen++; + + break; + } + + case 4: ; + case 5: { + *pTemp = pEntry->iRed; + *(pTemp+1) = pEntry->iGreen; + *(pTemp+2) = pEntry->iBlue; + *(pTemp+3) = pEntry->iAlpha; + + pTemp += 4; + iRawlen += 4; + + break; + } + + } + } + else + { + if (bHasgroup) /* finish off a group ? */ + *pLastid = (mng_uint8)(iX-1); + + bHasgroup = MNG_FALSE; + } + } + + if (bHasgroup) /* last group unfinished ? */ + *pLastid = (mng_uint8)(pPPLT->iCount-1); + /* write the output buffer */ + iRetcode = write_raw_chunk (pData, pPPLT->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_PPLT, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG +WRITE_CHUNK (mng_write_ijng) +{ + mng_ijngp pIJNG; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_IJNG, MNG_LC_START); +#endif + + pIJNG = (mng_ijngp)pChunk; /* address the proper chunk */ + /* and write it */ + iRetcode = write_raw_chunk (pData, pIJNG->sHeader.iChunkname, 0, 0); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_IJNG, MNG_LC_END); +#endif + + return iRetcode; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +WRITE_CHUNK (mng_write_drop) +{ + mng_dropp pDROP; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_uint32 iX; + mng_uint8p pTemp1; + mng_chunkidp pTemp2; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_DROP, MNG_LC_START); +#endif + + pDROP = (mng_dropp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = pDROP->iCount << 2; + + pTemp1 = pRawdata; /* fill the output buffer */ + pTemp2 = pDROP->pChunknames; + + for (iX = 0; iX < pDROP->iCount; iX++) + { + mng_put_uint32 (pTemp1, (mng_uint32)*pTemp2); + + pTemp2++; + pTemp1 += 4; + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pDROP->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_DROP, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DBYK +WRITE_CHUNK (mng_write_dbyk) +{ + mng_dbykp pDBYK; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_DBYK, MNG_LC_START); +#endif + + pDBYK = (mng_dbykp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 5 + pDBYK->iKeywordssize; + /* fill the output buffer */ + mng_put_uint32 (pRawdata, pDBYK->iChunkname); + *(pRawdata+4) = pDBYK->iPolarity; + + if (pDBYK->iKeywordssize) + MNG_COPY (pRawdata+5, pDBYK->zKeywords, pDBYK->iKeywordssize); + /* and write it */ + iRetcode = write_raw_chunk (pData, pDBYK->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_DBYK, MNG_LC_END); +#endif + + return iRetcode; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR +WRITE_CHUNK (mng_write_ordr) +{ + mng_ordrp pORDR; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_uint8p pTemp; + mng_ordr_entryp pEntry; + mng_uint32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_ORDR, MNG_LC_START); +#endif + + pORDR = (mng_ordrp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = pORDR->iCount * 5; + + pTemp = pRawdata; /* fill the output buffer */ + pEntry = pORDR->pEntries; + + for (iX = 0; iX < pORDR->iCount; iX++) + { + mng_put_uint32 (pTemp, pEntry->iChunkname); + *(pTemp+4) = pEntry->iOrdertype; + pTemp += 5; + pEntry++; + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pORDR->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_ORDR, MNG_LC_END); +#endif + + return iRetcode; +} +#endif +#endif + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_magn) +{ + mng_magnp pMAGN; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_MAGN, MNG_LC_START); +#endif + + pMAGN = (mng_magnp)pChunk; /* address the proper chunk */ + + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 18; + /* fill the output buffer */ + mng_put_uint16 (pRawdata, pMAGN->iFirstid); + mng_put_uint16 (pRawdata+2, pMAGN->iLastid); + *(pRawdata+4) = pMAGN->iMethodX; + mng_put_uint16 (pRawdata+5, pMAGN->iMX); + mng_put_uint16 (pRawdata+7, pMAGN->iMY); + mng_put_uint16 (pRawdata+9, pMAGN->iML); + mng_put_uint16 (pRawdata+11, pMAGN->iMR); + mng_put_uint16 (pRawdata+13, pMAGN->iMT); + mng_put_uint16 (pRawdata+15, pMAGN->iMB); + *(pRawdata+17) = pMAGN->iMethodY; + /* optimize length */ + if (pMAGN->iMethodY == pMAGN->iMethodX) + { + iRawlen--; + + if (pMAGN->iMB == pMAGN->iMY) + { + iRawlen -= 2; + + if (pMAGN->iMT == pMAGN->iMY) + { + iRawlen -= 2; + + if (pMAGN->iMR == pMAGN->iMX) + { + iRawlen -= 2; + + if (pMAGN->iML == pMAGN->iMX) + { + iRawlen -= 2; + + if (pMAGN->iMY == pMAGN->iMX) + { + iRawlen -= 2; + + if (pMAGN->iMX == 1) + { + iRawlen -= 2; + + if (pMAGN->iMethodX == 0) + { + iRawlen--; + + if (pMAGN->iLastid == pMAGN->iFirstid) + { + iRawlen -= 2; + + if (pMAGN->iFirstid == 0) + iRawlen = 0; + + } + } + } + } + } + } + } + } + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pMAGN->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_MAGN, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_MPNG_PROPOSAL +WRITE_CHUNK (mng_write_mpng) +{ + mng_mpngp pMPNG; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_uint8p pBuf = 0; + mng_uint32 iBuflen; + mng_uint32 iReallen; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_MPNG, MNG_LC_START); +#endif + + pMPNG = (mng_mpngp)pChunk; /* address the proper chunk */ + /* compress the frame structures */ + iRetcode = deflate_buffer (pData, (mng_uint8p)pMPNG->pFrames, pMPNG->iFramessize, + &pBuf, &iBuflen, &iReallen); + + if (!iRetcode) /* all ok ? */ + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 15 + iReallen; + /* requires large buffer ? */ + if (iRawlen > pData->iWritebufsize) + MNG_ALLOC (pData, pRawdata, iRawlen); + /* fill the buffer */ + mng_put_uint32 (pRawdata, pMPNG->iFramewidth); + mng_put_uint32 (pRawdata+4, pMPNG->iFrameheight); + mng_put_uint16 (pRawdata+8, pMPNG->iNumplays); + mng_put_uint16 (pRawdata+10, pMPNG->iTickspersec); + *(pRawdata+12) = pMPNG->iCompressionmethod; + + if (iReallen) + MNG_COPY (pRawdata+13, pBuf, iReallen); + /* and write it */ + iRetcode = write_raw_chunk (pData, pMPNG->sHeader.iChunkname, + iRawlen, pRawdata); + /* drop the temp buffer ? */ + if (iRawlen > pData->iWritebufsize) + MNG_FREEX (pData, pRawdata, iRawlen); + } + + MNG_FREEX (pData, pBuf, iBuflen); /* always drop the compression buffer */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_MPNG, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ANG_PROPOSAL +WRITE_CHUNK (mng_write_ahdr) +{ + mng_ahdrp pAHDR; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_AHDR, MNG_LC_START); +#endif + + pAHDR = (mng_ahdrp)pChunk; /* address the proper chunk */ + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 22; + /* fill the buffer */ + mng_put_uint32 (pRawdata, pAHDR->iNumframes); + mng_put_uint32 (pRawdata+4, pAHDR->iTickspersec); + mng_put_uint32 (pRawdata+8, pAHDR->iNumplays); + mng_put_uint32 (pRawdata+12, pAHDR->iTilewidth); + mng_put_uint32 (pRawdata+16, pAHDR->iTileheight); + *(pRawdata+20) = pAHDR->iInterlace; + *(pRawdata+21) = pAHDR->iStillused; + /* and write it */ + iRetcode = write_raw_chunk (pData, pAHDR->sHeader.iChunkname, + iRawlen, pRawdata); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_AHDR, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ANG_PROPOSAL +WRITE_CHUNK (mng_write_adat) +{ + + /* TODO: something */ + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_evNT +WRITE_CHUNK (mng_write_evnt) +{ + mng_evntp pEVNT; + mng_uint8p pRawdata; + mng_uint32 iRawlen; + mng_retcode iRetcode; + mng_evnt_entryp pEntry; + mng_uint8p pTemp; + mng_uint32 iX; + mng_uint32 iNamesize; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_EVNT, MNG_LC_START); +#endif + + pEVNT = (mng_evntp)pChunk; /* address the proper chunk */ + + if (!pEVNT->iCount) /* empty ? */ + iRetcode = write_raw_chunk (pData, pEVNT->sHeader.iChunkname, 0, 0); + else + { + pRawdata = pData->pWritebuf+8; /* init output buffer & size */ + iRawlen = 0; + pTemp = pRawdata; + pEntry = pEVNT->pEntries; + + for (iX = 0; iX < pEVNT->iCount; iX++) + { + if (iX) /* put separator null-byte, except the first */ + { + *pTemp = 0; + pTemp++; + iRawlen++; + } + + *pTemp = pEntry->iEventtype; + *(pTemp+1) = pEntry->iMasktype; + pTemp += 2; + iRawlen += 2; + + switch (pEntry->iMasktype) + { + case 1 : + { + mng_put_int32 (pTemp, pEntry->iLeft); + mng_put_int32 (pTemp+4, pEntry->iRight); + mng_put_int32 (pTemp+8, pEntry->iTop); + mng_put_int32 (pTemp+12, pEntry->iBottom); + pTemp += 16; + iRawlen += 16; + break; + } + case 2 : + { + mng_put_uint16 (pTemp, pEntry->iObjectid); + pTemp += 2; + iRawlen += 2; + break; + } + case 3 : + { + mng_put_uint16 (pTemp, pEntry->iObjectid); + *(pTemp+2) = pEntry->iIndex; + pTemp += 3; + iRawlen += 3; + break; + } + case 4 : + { + mng_put_int32 (pTemp, pEntry->iLeft); + mng_put_int32 (pTemp+4, pEntry->iRight); + mng_put_int32 (pTemp+8, pEntry->iTop); + mng_put_int32 (pTemp+12, pEntry->iBottom); + mng_put_uint16 (pTemp+16, pEntry->iObjectid); + pTemp += 18; + iRawlen += 18; + break; + } + case 5 : + { + mng_put_int32 (pTemp, pEntry->iLeft); + mng_put_int32 (pTemp+4, pEntry->iRight); + mng_put_int32 (pTemp+8, pEntry->iTop); + mng_put_int32 (pTemp+12, pEntry->iBottom); + mng_put_uint16 (pTemp+16, pEntry->iObjectid); + *(pTemp+18) = pEntry->iIndex; + pTemp += 19; + iRawlen += 19; + break; + } + } + + iNamesize = pEntry->iSegmentnamesize; + + if (iNamesize) + { + MNG_COPY (pTemp, pEntry->zSegmentname, iNamesize); + pTemp += iNamesize; + iRawlen += iNamesize; + } + + pEntry++; + } + /* and write it */ + iRetcode = write_raw_chunk (pData, pEVNT->sHeader.iChunkname, + iRawlen, pRawdata); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_EVNT, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +WRITE_CHUNK (mng_write_unknown) +{ + mng_unknown_chunkp pUnknown; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_UNKNOWN, MNG_LC_START); +#endif + /* address the proper chunk */ + pUnknown = (mng_unknown_chunkp)pChunk; + /* and write it */ + iRetcode = write_raw_chunk (pData, pUnknown->sHeader.iChunkname, + pUnknown->iDatasize, pUnknown->pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_UNKNOWN, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_WRITE_PROCS */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + diff --git a/Source/LibMNG/libmng_chunk_prc.c b/Source/LibMNG/libmng_chunk_prc.c index 6c8e589..e633e7e 100644 --- a/Source/LibMNG/libmng_chunk_prc.c +++ b/Source/LibMNG/libmng_chunk_prc.c @@ -1,4452 +1,4452 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_chunk_prc.c copyright (c) 2000-2005 G.Juyn * */ -/* * version : 1.0.10 * */ -/* * * */ -/* * purpose : Chunk initialization & cleanup (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the chunk initialization & cleanup * */ -/* * routines * */ -/* * * */ -/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - changed trace to macro for callback error-reporting * */ -/* * * */ -/* * 0.9.1 - 07/19/2000 - G.Juyn * */ -/* * - fixed creation-code * */ -/* * * */ -/* * 0.9.2 - 07/31/2000 - G.Juyn * */ -/* * - put add_chunk() inside MNG_INCLUDE_WRITE_PROCS wrapper * */ -/* * 0.9.2 - 08/01/2000 - G.Juyn * */ -/* * - wrapper for add_chunk() changed * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 0.9.3 - 08/26/2000 - G.Juyn * */ -/* * - added MAGN chunk * */ -/* * 0.9.3 - 10/16/2000 - G.Juyn * */ -/* * - added support for JDAA * */ -/* * * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * - added HLAPI function to copy chunks * */ -/* * 1.0.5 - 09/14/2002 - G.Juyn * */ -/* * - added event handling for dynamic MNG * */ -/* * 1.0.5 - 10/04/2002 - G.Juyn * */ -/* * - fixed chunk-storage for evNT chunk * */ -/* * 1.0.5 - 10/17/2002 - G.Juyn * */ -/* * - fixed issue in freeing evNT chunk * */ -/* * * */ -/* * 1.0.6 - 07/07/2003 - G.R-P * */ -/* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */ -/* * - added MNG_NO_DELTA_PNG reduction feature * */ -/* * 1.0.6 - 07/14/2003 - G.R-P * */ -/* * - added MNG_NO_LOOP_SIGNALS_SUPPORTED conditional * */ -/* * 1.0.6 - 07/29/2003 - G.R-P * */ -/* * - added conditionals around PAST chunk support * */ -/* * 1.0.6 - 08/17/2003 - G.R-P * */ -/* * - added conditionals around non-VLC chunk support * */ -/* * * */ -/* * 1.0.7 - 03/24/2004 - G.R-P * */ -/* * - fixed SKIPCHUNK_eXPI -> fPRI typo * */ -/* * * */ -/* * 1.0.9 - 09/25/2004 - G.Juyn * */ -/* * - replaced MNG_TWEAK_LARGE_FILES with permanent solution * */ -/* * 1.0.9 - 12/05/2004 - G.Juyn * */ -/* * - added conditional MNG_OPTIMIZE_CHUNKINITFREE * */ -/* * 1.0.9 - 12/06/2004 - G.Juyn * */ -/* * - added conditional MNG_OPTIMIZE_CHUNKASSIGN * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * * */ -/* * 1.0.10 - 07/30/2005 - G.Juyn * */ -/* * - fixed problem with CLON object during readdisplay() * */ -/* * 1.0.10 - 04/08/2007 - G.Juyn * */ -/* * - added support for mPNG proposal * */ -/* * 1.0.10 - 04/12/2007 - G.Juyn * */ -/* * - added support for ANG proposal * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_memory.h" -#include "libmng_chunks.h" -#include "libmng_chunk_prc.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ -/* * * */ -/* * General chunk routines * */ -/* * * */ -/* ************************************************************************** */ - -void mng_add_chunk (mng_datap pData, - mng_chunkp pChunk) -{ - if (!pData->pFirstchunk) /* list is still empty ? */ - { - pData->pFirstchunk = pChunk; /* then this becomes the first */ - -#ifdef MNG_SUPPORT_WRITE - if (!pData->iFirstchunkadded) - { - pData->iFirstchunkadded = ((mng_chunk_headerp)pChunk)->iChunkname; -#endif - - if (((mng_chunk_headerp)pChunk)->iChunkname == MNG_UINT_IHDR) - pData->eImagetype = mng_it_png; - else -#ifdef MNG_INCLUDE_JNG - if (((mng_chunk_headerp)pChunk)->iChunkname == MNG_UINT_JHDR) - pData->eImagetype = mng_it_jng; - else -#endif - pData->eImagetype = mng_it_mng; - - pData->eSigtype = pData->eImagetype; -#ifdef MNG_SUPPORT_WRITE - } -#endif - } - else - { /* else we make appropriate links */ - ((mng_chunk_headerp)pChunk)->pPrev = pData->pLastchunk; - ((mng_chunk_headerp)pData->pLastchunk)->pNext = pChunk; - } - - pData->pLastchunk = pChunk; /* and it's always the last */ - - return; -} - -/* ************************************************************************** */ -/* * * */ -/* * Chunk specific initialization routines * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_OPTIMIZE_CHUNKINITFREE -INIT_CHUNK_HDR (mng_init_general) -{ - MNG_ALLOC (pData, *ppChunk, ((mng_chunk_headerp)pHeader)->iChunksize); - MNG_COPY (*ppChunk, pHeader, sizeof (mng_chunk_header)); - return MNG_NOERROR; -} - -#else /* MNG_OPTIMIZE_CHUNKINITFREE */ - -/* ************************************************************************** */ - -INIT_CHUNK_HDR (mng_init_ihdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IHDR, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_ihdr)); - ((mng_ihdrp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -INIT_CHUNK_HDR (mng_init_plte) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_PLTE, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_plte)); - ((mng_pltep)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_PLTE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -INIT_CHUNK_HDR (mng_init_idat) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDAT, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_idat)); - ((mng_idatp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDAT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -INIT_CHUNK_HDR (mng_init_iend) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IEND, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_iend)); - ((mng_iendp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IEND, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -INIT_CHUNK_HDR (mng_init_trns) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_TRNS, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_trns)); - ((mng_trnsp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_TRNS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_gAMA -INIT_CHUNK_HDR (mng_init_gama) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_GAMA, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_gama)); - ((mng_gamap)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_GAMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_cHRM -INIT_CHUNK_HDR (mng_init_chrm) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_CHRM, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_chrm)); - ((mng_chrmp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_CHRM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sRGB -INIT_CHUNK_HDR (mng_init_srgb) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_SRGB, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_srgb)); - ((mng_srgbp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_SRGB, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iCCP -INIT_CHUNK_HDR (mng_init_iccp) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_ICCP, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_iccp)); - ((mng_iccpp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_ICCP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_tEXt -INIT_CHUNK_HDR (mng_init_text) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_TEXT, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_text)); - ((mng_textp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_TEXT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_zTXt -INIT_CHUNK_HDR (mng_init_ztxt) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_ZTXT, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_ztxt)); - ((mng_ztxtp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_ZTXT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iTXt -INIT_CHUNK_HDR (mng_init_itxt) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_ITXT, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_itxt)); - ((mng_itxtp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_ITXT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_bKGD -INIT_CHUNK_HDR (mng_init_bkgd) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_BKGD, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_bkgd)); - ((mng_bkgdp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_BKGD, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_pHYs -INIT_CHUNK_HDR (mng_init_phys) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_PHYS, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_phys)); - ((mng_physp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_PHYS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sBIT -INIT_CHUNK_HDR (mng_init_sbit) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_SBIT, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_sbit)); - ((mng_sbitp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_SBIT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sPLT -INIT_CHUNK_HDR (mng_init_splt) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_SPLT, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_splt)); - ((mng_spltp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_SPLT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_hIST -INIT_CHUNK_HDR (mng_init_hist) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_HIST, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_hist)); - ((mng_histp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_HIST, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_tIME -INIT_CHUNK_HDR (mng_init_time) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_TIME, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_time)); - ((mng_timep)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_TIME, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -INIT_CHUNK_HDR (mng_init_mhdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_MHDR, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_mhdr)); - ((mng_mhdrp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_MHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -INIT_CHUNK_HDR (mng_init_mend) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_MEND, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_mend)); - ((mng_mendp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_MEND, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_LOOP -INIT_CHUNK_HDR (mng_init_loop) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_LOOP, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_loop)); - ((mng_loopp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_LOOP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -INIT_CHUNK_HDR (mng_init_endl) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_ENDL, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_endl)); - ((mng_endlp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_ENDL, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DEFI -INIT_CHUNK_HDR (mng_init_defi) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_DEFI, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_defi)); - ((mng_defip)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_DEFI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_BASI -INIT_CHUNK_HDR (mng_init_basi) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_BASI, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_basi)); - ((mng_basip)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_BASI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_CLON -INIT_CHUNK_HDR (mng_init_clon) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_CLON, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_clon)); - ((mng_clonp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_CLON, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -INIT_CHUNK_HDR (mng_init_past) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_PAST, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_past)); - ((mng_pastp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_PAST, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DISC -INIT_CHUNK_HDR (mng_init_disc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_DISC, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_disc)); - ((mng_discp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_DISC, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_BACK -INIT_CHUNK_HDR (mng_init_back) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_BACK, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_back)); - ((mng_backp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_BACK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_FRAM -INIT_CHUNK_HDR (mng_init_fram) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_FRAM, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_fram)); - ((mng_framp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_FRAM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MOVE -INIT_CHUNK_HDR (mng_init_move) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_MOVE, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_move)); - ((mng_movep)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_MOVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_CLIP -INIT_CHUNK_HDR (mng_init_clip) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_CLIP, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_clip)); - ((mng_clipp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_CLIP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SHOW -INIT_CHUNK_HDR (mng_init_show) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_SHOW, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_show)); - ((mng_showp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_SHOW, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_TERM -INIT_CHUNK_HDR (mng_init_term) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_TERM, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_term)); - ((mng_termp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_TERM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SAVE -INIT_CHUNK_HDR (mng_init_save) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_SAVE, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_save)); - ((mng_savep)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_SAVE, MNG_LC_END); -#endif - - return MNG_NOERROR; - -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SEEK -INIT_CHUNK_HDR (mng_init_seek) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_SEEK, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_seek)); - ((mng_seekp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_SEEK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_eXPI -INIT_CHUNK_HDR (mng_init_expi) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_EXPI, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_expi)); - ((mng_expip)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_EXPI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_fPRI -INIT_CHUNK_HDR (mng_init_fpri) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_FPRI, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_fpri)); - ((mng_fprip)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_FPRI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_nEED -INIT_CHUNK_HDR (mng_init_need) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_NEED, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_need)); - ((mng_needp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_NEED, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_pHYg -INIT_CHUNK_HDR (mng_init_phyg) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_PHYG, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_phyg)); - ((mng_phygp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_PHYG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -INIT_CHUNK_HDR (mng_init_jhdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JHDR, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_jhdr)); - ((mng_jhdrp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -INIT_CHUNK_HDR (mng_init_jdaa) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JDAA, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_jdaa)); - ((mng_jdaap)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JDAA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -INIT_CHUNK_HDR (mng_init_jdat) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JDAT, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_jdat)); - ((mng_jdatp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JDAT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -INIT_CHUNK_HDR (mng_init_jsep) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JSEP, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_jsep)); - ((mng_jsepp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JSEP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -INIT_CHUNK_HDR (mng_init_dhdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_DHDR, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_dhdr)); - ((mng_dhdrp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_DHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -INIT_CHUNK_HDR (mng_init_prom) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_PROM, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_prom)); - ((mng_promp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_PROM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -INIT_CHUNK_HDR (mng_init_ipng) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IPNG, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_ipng)); - ((mng_ipngp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IPNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -INIT_CHUNK_HDR (mng_init_pplt) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_PPLT, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_pplt)); - ((mng_ppltp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_PPLT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG -INIT_CHUNK_HDR (mng_init_ijng) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IJNG, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_ijng)); - ((mng_ijngp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IJNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -INIT_CHUNK_HDR (mng_init_drop) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_DROP, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_drop)); - ((mng_dropp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_DROP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DBYK -INIT_CHUNK_HDR (mng_init_dbyk) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_DBYK, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_dbyk)); - ((mng_dbykp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_DBYK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR -INIT_CHUNK_HDR (mng_init_ordr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_ORDR, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_ordr)); - ((mng_ordrp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_ORDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MAGN -INIT_CHUNK_HDR (mng_init_magn) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_MAGN, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_magn)); - ((mng_magnp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_MAGN, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_evNT -INIT_CHUNK_HDR (mng_init_evnt) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_EVNT, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_evnt)); - ((mng_evntp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_EVNT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -INIT_CHUNK_HDR (mng_init_unknown) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_UNKNOWN, MNG_LC_START); -#endif - - MNG_ALLOC (pData, *ppChunk, sizeof (mng_unknown_chunk)); - ((mng_unknown_chunkp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_UNKNOWN, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#endif /* MNG_OPTIMIZE_CHUNKINITFREE */ - -/* ************************************************************************** */ -/* * * */ -/* * Chunk specific cleanup routines * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_OPTIMIZE_CHUNKINITFREE -FREE_CHUNK_HDR (mng_free_general) -{ - MNG_FREEX (pData, pHeader, ((mng_chunk_headerp)pHeader)->iChunksize); - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -FREE_CHUNK_HDR (mng_free_ihdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_IHDR, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_ihdr)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_IHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -FREE_CHUNK_HDR (mng_free_plte) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_PLTE, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_plte)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_PLTE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -FREE_CHUNK_HDR (mng_free_idat) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_IDAT, MNG_LC_START); -#endif - - if (((mng_idatp)pHeader)->iDatasize) - MNG_FREEX (pData, ((mng_idatp)pHeader)->pData, - ((mng_idatp)pHeader)->iDatasize); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_idat)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_IDAT, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -FREE_CHUNK_HDR (mng_free_iend) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_IEND, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_iend)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_IEND, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -FREE_CHUNK_HDR (mng_free_trns) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_TRNS, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_trns)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_TRNS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_gAMA -FREE_CHUNK_HDR (mng_free_gama) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_GAMA, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_gama)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_GAMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_cHRM -FREE_CHUNK_HDR (mng_free_chrm) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_CHRM, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_chrm)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_CHRM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_sRGB -FREE_CHUNK_HDR (mng_free_srgb) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_SRGB, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_srgb)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_SRGB, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iCCP -FREE_CHUNK_HDR (mng_free_iccp) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ICCP, MNG_LC_START); -#endif - - if (((mng_iccpp)pHeader)->iNamesize) - MNG_FREEX (pData, ((mng_iccpp)pHeader)->zName, - ((mng_iccpp)pHeader)->iNamesize + 1); - - if (((mng_iccpp)pHeader)->iProfilesize) - MNG_FREEX (pData, ((mng_iccpp)pHeader)->pProfile, - ((mng_iccpp)pHeader)->iProfilesize); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_iccp)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ICCP, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_tEXt -FREE_CHUNK_HDR (mng_free_text) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_TEXT, MNG_LC_START); -#endif - - if (((mng_textp)pHeader)->iKeywordsize) - MNG_FREEX (pData, ((mng_textp)pHeader)->zKeyword, - ((mng_textp)pHeader)->iKeywordsize + 1); - - if (((mng_textp)pHeader)->iTextsize) - MNG_FREEX (pData, ((mng_textp)pHeader)->zText, - ((mng_textp)pHeader)->iTextsize + 1); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_text)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_TEXT, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_zTXt -FREE_CHUNK_HDR (mng_free_ztxt) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ZTXT, MNG_LC_START); -#endif - - if (((mng_ztxtp)pHeader)->iKeywordsize) - MNG_FREEX (pData, ((mng_ztxtp)pHeader)->zKeyword, - ((mng_ztxtp)pHeader)->iKeywordsize + 1); - - if (((mng_ztxtp)pHeader)->iTextsize) - MNG_FREEX (pData, ((mng_ztxtp)pHeader)->zText, - ((mng_ztxtp)pHeader)->iTextsize); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_ztxt)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ZTXT, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ -#ifndef MNG_SKIPCHUNK_iTXt -FREE_CHUNK_HDR (mng_free_itxt) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ITXT, MNG_LC_START); -#endif - - if (((mng_itxtp)pHeader)->iKeywordsize) - MNG_FREEX (pData, ((mng_itxtp)pHeader)->zKeyword, - ((mng_itxtp)pHeader)->iKeywordsize + 1); - - if (((mng_itxtp)pHeader)->iLanguagesize) - MNG_FREEX (pData, ((mng_itxtp)pHeader)->zLanguage, - ((mng_itxtp)pHeader)->iLanguagesize + 1); - - if (((mng_itxtp)pHeader)->iTranslationsize) - MNG_FREEX (pData, ((mng_itxtp)pHeader)->zTranslation, - ((mng_itxtp)pHeader)->iTranslationsize + 1); - - if (((mng_itxtp)pHeader)->iTextsize) - MNG_FREEX (pData, ((mng_itxtp)pHeader)->zText, - ((mng_itxtp)pHeader)->iTextsize); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_itxt)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ITXT, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ -#ifdef MNG_INCLUDE_MPNG_PROPOSAL -FREE_CHUNK_HDR (mng_free_mpng) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_MPNG, MNG_LC_START); -#endif - - if (((mng_mpngp)pHeader)->iFramessize) - MNG_FREEX (pData, ((mng_mpngp)pHeader)->pFrames, - ((mng_mpngp)pHeader)->iFramessize); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_mpng)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_MPNG, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ -#ifdef MNG_INCLUDE_ANG_PROPOSAL -FREE_CHUNK_HDR (mng_free_adat) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ADAT, MNG_LC_START); -#endif - - if (((mng_adatp)pHeader)->iTilessize) - MNG_FREEX (pData, ((mng_adatp)pHeader)->pTiles, ((mng_adatp)pHeader)->iTilessize); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_adat)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ADAT, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_bKGD -FREE_CHUNK_HDR (mng_free_bkgd) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_BKGD, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_bkgd)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_BKGD, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_pHYs -FREE_CHUNK_HDR (mng_free_phys) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_PHYS, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_phys)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_PHYS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_sBIT -FREE_CHUNK_HDR (mng_free_sbit) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_SBIT, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_sbit)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_SBIT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sPLT -FREE_CHUNK_HDR (mng_free_splt) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_SPLT, MNG_LC_START); -#endif - - if (((mng_spltp)pHeader)->iNamesize) - MNG_FREEX (pData, ((mng_spltp)pHeader)->zName, - ((mng_spltp)pHeader)->iNamesize + 1); - - if (((mng_spltp)pHeader)->iEntrycount) - MNG_FREEX (pData, ((mng_spltp)pHeader)->pEntries, - ((mng_spltp)pHeader)->iEntrycount * - (((mng_spltp)pHeader)->iSampledepth * 3 + sizeof (mng_uint16)) ); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_splt)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_SPLT, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_hIST -FREE_CHUNK_HDR (mng_free_hist) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_HIST, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_hist)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_HIST, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_tIME -FREE_CHUNK_HDR (mng_free_time) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_TIME, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_time)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_TIME, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -FREE_CHUNK_HDR (mng_free_mhdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_MHDR, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_mhdr)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_MHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -FREE_CHUNK_HDR (mng_free_mend) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_MEND, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_mend)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_MEND, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_LOOP -FREE_CHUNK_HDR (mng_free_loop) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_LOOP, MNG_LC_START); -#endif - -#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED - if (((mng_loopp)pHeader)->iCount) - MNG_FREEX (pData, ((mng_loopp)pHeader)->pSignals, - ((mng_loopp)pHeader)->iCount * sizeof (mng_uint32) ); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_loop)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_LOOP, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -FREE_CHUNK_HDR (mng_free_endl) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ENDL, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_endl)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ENDL, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_DEFI -FREE_CHUNK_HDR (mng_free_defi) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_DEFI, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_defi)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_DEFI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_BASI -FREE_CHUNK_HDR (mng_free_basi) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_BASI, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_basi)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_BASI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_CLON -FREE_CHUNK_HDR (mng_free_clon) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_CLON, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_clon)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_CLON, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -FREE_CHUNK_HDR (mng_free_past) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_PAST, MNG_LC_START); -#endif - - if (((mng_pastp)pHeader)->iCount) - MNG_FREEX (pData, ((mng_pastp)pHeader)->pSources, - ((mng_pastp)pHeader)->iCount * sizeof (mng_past_source) ); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_past)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_PAST, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DISC -FREE_CHUNK_HDR (mng_free_disc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_DISC, MNG_LC_START); -#endif - - if (((mng_discp)pHeader)->iCount) - MNG_FREEX (pData, ((mng_discp)pHeader)->pObjectids, - ((mng_discp)pHeader)->iCount * sizeof (mng_uint16) ); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_disc)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_DISC, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_BACK -FREE_CHUNK_HDR (mng_free_back) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_BACK, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_back)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_BACK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_FRAM -FREE_CHUNK_HDR (mng_free_fram) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_FRAM, MNG_LC_START); -#endif - - if (((mng_framp)pHeader)->iNamesize) - MNG_FREEX (pData, ((mng_framp)pHeader)->zName, - ((mng_framp)pHeader)->iNamesize + 1); - - if (((mng_framp)pHeader)->iCount) - MNG_FREEX (pData, ((mng_framp)pHeader)->pSyncids, - ((mng_framp)pHeader)->iCount * sizeof (mng_uint32) ); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_fram)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_FRAM, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_MOVE -FREE_CHUNK_HDR (mng_free_move) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_MOVE, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_move)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_MOVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_CLIP -FREE_CHUNK_HDR (mng_free_clip) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_CLIP, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_clip)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_CLIP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_SHOW -FREE_CHUNK_HDR (mng_free_show) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_SHOW, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_show)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_SHOW, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_TERM -FREE_CHUNK_HDR (mng_free_term) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_TERM, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_term)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_TERM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SAVE -FREE_CHUNK_HDR (mng_free_save) -{ - mng_save_entryp pEntry = ((mng_savep)pHeader)->pEntries; - mng_uint32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_SAVE, MNG_LC_START); -#endif - - for (iX = 0; iX < ((mng_savep)pHeader)->iCount; iX++) - { - if (pEntry->iNamesize) - MNG_FREEX (pData, pEntry->zName, pEntry->iNamesize); - - pEntry = pEntry + sizeof (mng_save_entry); - } - - if (((mng_savep)pHeader)->iCount) - MNG_FREEX (pData, ((mng_savep)pHeader)->pEntries, - ((mng_savep)pHeader)->iCount * sizeof (mng_save_entry) ); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_save)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_SAVE, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SEEK -FREE_CHUNK_HDR (mng_free_seek) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_SEEK, MNG_LC_START); -#endif - - if (((mng_seekp)pHeader)->iNamesize) - MNG_FREEX (pData, ((mng_seekp)pHeader)->zName, - ((mng_seekp)pHeader)->iNamesize + 1); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_seek)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_SEEK, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_eXPI -FREE_CHUNK_HDR (mng_free_expi) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_EXPI, MNG_LC_START); -#endif - - if (((mng_expip)pHeader)->iNamesize) - MNG_FREEX (pData, ((mng_expip)pHeader)->zName, - ((mng_expip)pHeader)->iNamesize + 1); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_expi)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_EXPI, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_fPRI -FREE_CHUNK_HDR (mng_free_fpri) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_FPRI, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_fpri)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_FPRI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_nEED -FREE_CHUNK_HDR (mng_free_need) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_NEED, MNG_LC_START); -#endif - - if (((mng_needp)pHeader)->iKeywordssize) - MNG_FREEX (pData, ((mng_needp)pHeader)->zKeywords, - ((mng_needp)pHeader)->iKeywordssize + 1); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_need)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_NEED, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_pHYg -FREE_CHUNK_HDR (mng_free_phyg) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_PHYG, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_phyg)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_PHYG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifdef MNG_INCLUDE_JNG -FREE_CHUNK_HDR (mng_free_jhdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_JHDR, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_jhdr)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_JHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -FREE_CHUNK_HDR (mng_free_jdaa) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_JDAA, MNG_LC_START); -#endif - - if (((mng_jdaap)pHeader)->iDatasize) - MNG_FREEX (pData, ((mng_jdaap)pHeader)->pData, - ((mng_jdaap)pHeader)->iDatasize); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_jdaa)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_JDAA, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -FREE_CHUNK_HDR (mng_free_jdat) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_JDAT, MNG_LC_START); -#endif - - if (((mng_jdatp)pHeader)->iDatasize) - MNG_FREEX (pData, ((mng_jdatp)pHeader)->pData, - ((mng_jdatp)pHeader)->iDatasize); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_jdat)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_JDAT, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifdef MNG_INCLUDE_JNG -FREE_CHUNK_HDR (mng_free_jsep) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_JSEP, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_jsep)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_JSEP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_NO_DELTA_PNG -FREE_CHUNK_HDR (mng_free_dhdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_DHDR, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_dhdr)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_DHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_NO_DELTA_PNG -FREE_CHUNK_HDR (mng_free_prom) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_PROM, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_prom)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_PROM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_NO_DELTA_PNG -FREE_CHUNK_HDR (mng_free_ipng) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_IPNG, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_ipng)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_IPNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_NO_DELTA_PNG -FREE_CHUNK_HDR (mng_free_pplt) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_PPLT, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_pplt)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_PPLT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG -FREE_CHUNK_HDR (mng_free_ijng) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_IJNG, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_ijng)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_IJNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -FREE_CHUNK_HDR (mng_free_drop) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_DROP, MNG_LC_START); -#endif - - if (((mng_dropp)pHeader)->iCount) - MNG_FREEX (pData, ((mng_dropp)pHeader)->pChunknames, - ((mng_dropp)pHeader)->iCount * sizeof (mng_chunkid) ); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_drop)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_DROP, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DBYK -FREE_CHUNK_HDR (mng_free_dbyk) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_DBYK, MNG_LC_START); -#endif - - if (((mng_dbykp)pHeader)->iKeywordssize) - MNG_FREEX (pData, ((mng_dbykp)pHeader)->zKeywords, - ((mng_dbykp)pHeader)->iKeywordssize); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_dbyk)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_DBYK, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR -FREE_CHUNK_HDR (mng_free_ordr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ORDR, MNG_LC_START); -#endif - - if (((mng_ordrp)pHeader)->iCount) - MNG_FREEX (pData, ((mng_ordrp)pHeader)->pEntries, - ((mng_ordrp)pHeader)->iCount * sizeof (mng_ordr_entry) ); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_ordr)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ORDR, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE -#ifndef MNG_SKIPCHUNK_MAGN -FREE_CHUNK_HDR (mng_free_magn) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_MAGN, MNG_LC_START); -#endif - - MNG_FREEX (pData, pHeader, sizeof (mng_magn)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_MAGN, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_evNT -FREE_CHUNK_HDR (mng_free_evnt) -{ - mng_evnt_entryp pEntry = ((mng_evntp)pHeader)->pEntries; - mng_uint32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_EVNT, MNG_LC_START); -#endif - - for (iX = 0; iX < ((mng_evntp)pHeader)->iCount; iX++) - { - if (pEntry->iSegmentnamesize) - MNG_FREEX (pData, pEntry->zSegmentname, pEntry->iSegmentnamesize+1); - - pEntry++; - } - - if (((mng_evntp)pHeader)->iCount) - MNG_FREEX (pData, ((mng_evntp)pHeader)->pEntries, - ((mng_evntp)pHeader)->iCount * sizeof (mng_evnt_entry) ); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_evnt)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_EVNT, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} -#endif - -/* ************************************************************************** */ - -FREE_CHUNK_HDR (mng_free_unknown) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_UNKNOWN, MNG_LC_START); -#endif - - if (((mng_unknown_chunkp)pHeader)->iDatasize) - MNG_FREEX (pData, ((mng_unknown_chunkp)pHeader)->pData, - ((mng_unknown_chunkp)pHeader)->iDatasize); - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - MNG_FREEX (pData, pHeader, sizeof (mng_unknown_chunk)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_UNKNOWN, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_CHUNKINITFREE - return MNG_NOERROR; -#else - return mng_free_general(pData, pHeader); -#endif -} - -/* ************************************************************************** */ -/* * * */ -/* * Chunk specific copy routines * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_WRITE_PROCS - -/* ************************************************************************** */ - -#ifdef MNG_OPTIMIZE_CHUNKASSIGN -ASSIGN_CHUNK_HDR (mng_assign_general) -{ - mng_ptr pSrc = (mng_uint8p)pChunkfrom + sizeof (mng_chunk_header); - mng_ptr pDst = (mng_uint8p)pChunkto + sizeof (mng_chunk_header); - mng_size_t iLen = ((mng_chunk_headerp)pChunkfrom)->iChunksize - sizeof (mng_chunk_header); - - MNG_COPY (pDst, pSrc, iLen); - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -ASSIGN_CHUNK_HDR (mng_assign_ihdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_IHDR, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_IHDR) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_ihdrp)pChunkto)->iWidth = ((mng_ihdrp)pChunkfrom)->iWidth; - ((mng_ihdrp)pChunkto)->iHeight = ((mng_ihdrp)pChunkfrom)->iHeight; - ((mng_ihdrp)pChunkto)->iBitdepth = ((mng_ihdrp)pChunkfrom)->iBitdepth; - ((mng_ihdrp)pChunkto)->iColortype = ((mng_ihdrp)pChunkfrom)->iColortype; - ((mng_ihdrp)pChunkto)->iCompression = ((mng_ihdrp)pChunkfrom)->iCompression; - ((mng_ihdrp)pChunkto)->iFilter = ((mng_ihdrp)pChunkfrom)->iFilter; - ((mng_ihdrp)pChunkto)->iInterlace = ((mng_ihdrp)pChunkfrom)->iInterlace; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_IHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -ASSIGN_CHUNK_HDR (mng_assign_plte) -{ - mng_uint32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_PLTE, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_PLTE) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_pltep)pChunkto)->bEmpty = ((mng_pltep)pChunkfrom)->bEmpty; - ((mng_pltep)pChunkto)->iEntrycount = ((mng_pltep)pChunkfrom)->iEntrycount; - - for (iX = 0; iX < ((mng_pltep)pChunkto)->iEntrycount; iX++) - ((mng_pltep)pChunkto)->aEntries [iX] = ((mng_pltep)pChunkfrom)->aEntries [iX]; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_PLTE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -ASSIGN_CHUNK_HDR (mng_assign_idat) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_IDAT, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_IDAT) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_idatp)pChunkto)->bEmpty = ((mng_idatp)pChunkfrom)->bEmpty; - ((mng_idatp)pChunkto)->iDatasize = ((mng_idatp)pChunkfrom)->iDatasize; - - if (((mng_idatp)pChunkto)->iDatasize) - { - MNG_ALLOC (pData, ((mng_idatp)pChunkto)->pData, ((mng_idatp)pChunkto)->iDatasize); - MNG_COPY (((mng_idatp)pChunkto)->pData, ((mng_idatp)pChunkfrom)->pData, - ((mng_idatp)pChunkto)->iDatasize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_IDAT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -ASSIGN_CHUNK_HDR (mng_assign_iend) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_IEND, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_IEND) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_IEND, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -ASSIGN_CHUNK_HDR (mng_assign_trns) -{ - mng_uint32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_TRNS, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_tRNS) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_trnsp)pChunkto)->bEmpty = ((mng_trnsp)pChunkfrom)->bEmpty; - ((mng_trnsp)pChunkto)->bGlobal = ((mng_trnsp)pChunkfrom)->bGlobal; - ((mng_trnsp)pChunkto)->iType = ((mng_trnsp)pChunkfrom)->iType; - ((mng_trnsp)pChunkto)->iCount = ((mng_trnsp)pChunkfrom)->iCount; - ((mng_trnsp)pChunkto)->iGray = ((mng_trnsp)pChunkfrom)->iGray; - ((mng_trnsp)pChunkto)->iRed = ((mng_trnsp)pChunkfrom)->iRed; - ((mng_trnsp)pChunkto)->iGreen = ((mng_trnsp)pChunkfrom)->iGreen; - ((mng_trnsp)pChunkto)->iBlue = ((mng_trnsp)pChunkfrom)->iBlue; - ((mng_trnsp)pChunkto)->iRawlen = ((mng_trnsp)pChunkfrom)->iRawlen; - - for (iX = 0; iX < ((mng_trnsp)pChunkto)->iCount; iX++) - ((mng_trnsp)pChunkto)->aEntries [iX] = ((mng_trnsp)pChunkfrom)->aEntries [iX]; - - for (iX = 0; iX < ((mng_trnsp)pChunkto)->iRawlen; iX++) - ((mng_trnsp)pChunkto)->aRawdata [iX] = ((mng_trnsp)pChunkfrom)->aRawdata [iX]; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_TRNS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_gAMA -ASSIGN_CHUNK_HDR (mng_assign_gama) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_GAMA, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_gAMA) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_gamap)pChunkto)->bEmpty = ((mng_gamap)pChunkfrom)->bEmpty; - ((mng_gamap)pChunkto)->iGamma = ((mng_gamap)pChunkfrom)->iGamma; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_GAMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_cHRM -ASSIGN_CHUNK_HDR (mng_assign_chrm) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_CHRM, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_cHRM) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_chrmp)pChunkto)->bEmpty = ((mng_chrmp)pChunkfrom)->bEmpty; - ((mng_chrmp)pChunkto)->iWhitepointx = ((mng_chrmp)pChunkfrom)->iWhitepointx; - ((mng_chrmp)pChunkto)->iWhitepointy = ((mng_chrmp)pChunkfrom)->iWhitepointy; - ((mng_chrmp)pChunkto)->iRedx = ((mng_chrmp)pChunkfrom)->iRedx; - ((mng_chrmp)pChunkto)->iRedy = ((mng_chrmp)pChunkfrom)->iRedy; - ((mng_chrmp)pChunkto)->iGreenx = ((mng_chrmp)pChunkfrom)->iGreenx; - ((mng_chrmp)pChunkto)->iGreeny = ((mng_chrmp)pChunkfrom)->iGreeny; - ((mng_chrmp)pChunkto)->iBluex = ((mng_chrmp)pChunkfrom)->iBluex; - ((mng_chrmp)pChunkto)->iBluey = ((mng_chrmp)pChunkfrom)->iBluey; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_CHRM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_sRGB -ASSIGN_CHUNK_HDR (mng_assign_srgb) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_SRGB, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_sRGB) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_srgbp)pChunkto)->iRenderingintent = ((mng_srgbp)pChunkfrom)->iRenderingintent; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_SRGB, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iCCP -ASSIGN_CHUNK_HDR (mng_assign_iccp) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_ICCP, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_iCCP) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_iccpp)pChunkto)->bEmpty = ((mng_iccpp)pChunkfrom)->bEmpty; - ((mng_iccpp)pChunkto)->iNamesize = ((mng_iccpp)pChunkfrom)->iNamesize; - ((mng_iccpp)pChunkto)->iCompression = ((mng_iccpp)pChunkfrom)->iCompression; - ((mng_iccpp)pChunkto)->iProfilesize = ((mng_iccpp)pChunkfrom)->iProfilesize; - - if (((mng_iccpp)pChunkto)->iNamesize) - { - MNG_ALLOC (pData, ((mng_iccpp)pChunkto)->zName, ((mng_iccpp)pChunkto)->iNamesize); - MNG_COPY (((mng_iccpp)pChunkto)->zName, ((mng_iccpp)pChunkfrom)->zName, - ((mng_iccpp)pChunkto)->iNamesize); - } - - if (((mng_iccpp)pChunkto)->iProfilesize) - { - MNG_ALLOC (pData, ((mng_iccpp)pChunkto)->pProfile, ((mng_iccpp)pChunkto)->iProfilesize); - MNG_COPY (((mng_iccpp)pChunkto)->pProfile, ((mng_iccpp)pChunkfrom)->pProfile, - ((mng_iccpp)pChunkto)->iProfilesize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_ICCP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_tEXt -ASSIGN_CHUNK_HDR (mng_assign_text) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_TEXT, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_tEXt) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_textp)pChunkto)->iKeywordsize = ((mng_textp)pChunkfrom)->iKeywordsize; - ((mng_textp)pChunkto)->iTextsize = ((mng_textp)pChunkfrom)->iTextsize; - - if (((mng_textp)pChunkto)->iKeywordsize) - { - MNG_ALLOC (pData, ((mng_itxtp)pChunkto)->zKeyword, ((mng_textp)pChunkto)->iKeywordsize); - MNG_COPY (((mng_itxtp)pChunkto)->zKeyword, ((mng_textp)pChunkfrom)->zKeyword, - ((mng_itxtp)pChunkto)->iKeywordsize); - } - - if (((mng_textp)pChunkto)->iTextsize) - { - MNG_ALLOC (pData, ((mng_textp)pChunkto)->zText, ((mng_textp)pChunkto)->iTextsize); - MNG_COPY (((mng_textp)pChunkto)->zText, ((mng_textp)pChunkfrom)->zText, - ((mng_textp)pChunkto)->iTextsize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_TEXT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_zTXt -ASSIGN_CHUNK_HDR (mng_assign_ztxt) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_ZTXT, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_zTXt) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_ztxtp)pChunkto)->iKeywordsize = ((mng_ztxtp)pChunkfrom)->iKeywordsize; - ((mng_ztxtp)pChunkto)->iCompression = ((mng_ztxtp)pChunkfrom)->iCompression; - ((mng_ztxtp)pChunkto)->iTextsize = ((mng_ztxtp)pChunkfrom)->iTextsize; - - if (((mng_ztxtp)pChunkto)->iKeywordsize) - { - MNG_ALLOC (pData, ((mng_ztxtp)pChunkto)->zKeyword, ((mng_ztxtp)pChunkto)->iKeywordsize); - MNG_COPY (((mng_ztxtp)pChunkto)->zKeyword, ((mng_ztxtp)pChunkfrom)->zKeyword, - ((mng_ztxtp)pChunkto)->iKeywordsize); - } - - if (((mng_ztxtp)pChunkto)->iTextsize) - { - MNG_ALLOC (pData, ((mng_ztxtp)pChunkto)->zText, ((mng_ztxtp)pChunkto)->iTextsize); - MNG_COPY (((mng_ztxtp)pChunkto)->zText, ((mng_ztxtp)pChunkfrom)->zText, - ((mng_ztxtp)pChunkto)->iTextsize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_ZTXT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iTXt -ASSIGN_CHUNK_HDR (mng_assign_itxt) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_ITXT, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_iTXt) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_itxtp)pChunkto)->iKeywordsize = ((mng_itxtp)pChunkfrom)->iKeywordsize; - ((mng_itxtp)pChunkto)->iCompressionflag = ((mng_itxtp)pChunkfrom)->iCompressionflag; - ((mng_itxtp)pChunkto)->iCompressionmethod = ((mng_itxtp)pChunkfrom)->iCompressionmethod; - ((mng_itxtp)pChunkto)->iLanguagesize = ((mng_itxtp)pChunkfrom)->iLanguagesize; - ((mng_itxtp)pChunkto)->iTranslationsize = ((mng_itxtp)pChunkfrom)->iTranslationsize; - ((mng_itxtp)pChunkto)->iTextsize = ((mng_itxtp)pChunkfrom)->iTextsize; - - if (((mng_itxtp)pChunkto)->iKeywordsize) - { - MNG_ALLOC (pData, ((mng_itxtp)pChunkto)->zKeyword, ((mng_itxtp)pChunkto)->iKeywordsize); - MNG_COPY (((mng_itxtp)pChunkto)->zKeyword, ((mng_itxtp)pChunkfrom)->zKeyword, - ((mng_itxtp)pChunkto)->iKeywordsize); - } - - if (((mng_itxtp)pChunkto)->iTextsize) - { - MNG_ALLOC (pData, ((mng_itxtp)pChunkto)->zLanguage, ((mng_itxtp)pChunkto)->iLanguagesize); - MNG_COPY (((mng_itxtp)pChunkto)->zLanguage, ((mng_itxtp)pChunkfrom)->zLanguage, - ((mng_itxtp)pChunkto)->iLanguagesize); - } - - if (((mng_itxtp)pChunkto)->iTextsize) - { - MNG_ALLOC (pData, ((mng_itxtp)pChunkto)->zTranslation, ((mng_itxtp)pChunkto)->iTranslationsize); - MNG_COPY (((mng_itxtp)pChunkto)->zTranslation, ((mng_itxtp)pChunkfrom)->zTranslation, - ((mng_itxtp)pChunkto)->iTranslationsize); - } - - if (((mng_itxtp)pChunkto)->iTextsize) - { - MNG_ALLOC (pData, ((mng_itxtp)pChunkto)->zText, ((mng_itxtp)pChunkto)->iTextsize); - MNG_COPY (((mng_itxtp)pChunkto)->zText, ((mng_itxtp)pChunkfrom)->zText, - ((mng_itxtp)pChunkto)->iTextsize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_ITXT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_bKGD -ASSIGN_CHUNK_HDR (mng_assign_bkgd) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_BKGD, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_bKGD) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_bkgdp)pChunkto)->bEmpty = ((mng_bkgdp)pChunkfrom)->bEmpty; - ((mng_bkgdp)pChunkto)->iType = ((mng_bkgdp)pChunkfrom)->iType; - ((mng_bkgdp)pChunkto)->iIndex = ((mng_bkgdp)pChunkfrom)->iIndex; - ((mng_bkgdp)pChunkto)->iGray = ((mng_bkgdp)pChunkfrom)->iGray; - ((mng_bkgdp)pChunkto)->iRed = ((mng_bkgdp)pChunkfrom)->iRed; - ((mng_bkgdp)pChunkto)->iGreen = ((mng_bkgdp)pChunkfrom)->iGreen; - ((mng_bkgdp)pChunkto)->iBlue = ((mng_bkgdp)pChunkfrom)->iBlue; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_BKGD, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_pHYs -ASSIGN_CHUNK_HDR (mng_assign_phys) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_PHYS, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_pHYs) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_physp)pChunkto)->bEmpty = ((mng_physp)pChunkfrom)->bEmpty; - ((mng_physp)pChunkto)->iSizex = ((mng_physp)pChunkfrom)->iSizex; - ((mng_physp)pChunkto)->iSizey = ((mng_physp)pChunkfrom)->iSizey; - ((mng_physp)pChunkto)->iUnit = ((mng_physp)pChunkfrom)->iUnit; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_PHYS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_sBIT -ASSIGN_CHUNK_HDR (mng_assign_sbit) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_SBIT, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_sBIT) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_sbitp)pChunkto)->bEmpty = ((mng_sbitp)pChunkfrom)->bEmpty; - ((mng_sbitp)pChunkto)->iType = ((mng_sbitp)pChunkfrom)->iType; - ((mng_sbitp)pChunkto)->aBits [0] = ((mng_sbitp)pChunkfrom)->aBits [0]; - ((mng_sbitp)pChunkto)->aBits [1] = ((mng_sbitp)pChunkfrom)->aBits [1]; - ((mng_sbitp)pChunkto)->aBits [2] = ((mng_sbitp)pChunkfrom)->aBits [2]; - ((mng_sbitp)pChunkto)->aBits [3] = ((mng_sbitp)pChunkfrom)->aBits [3]; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_SBIT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sPLT -ASSIGN_CHUNK_HDR (mng_assign_splt) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_SPLT, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_sPLT) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_spltp)pChunkto)->bEmpty = ((mng_spltp)pChunkfrom)->bEmpty; - ((mng_spltp)pChunkto)->iNamesize = ((mng_spltp)pChunkfrom)->iNamesize; - ((mng_spltp)pChunkto)->iSampledepth = ((mng_spltp)pChunkfrom)->iSampledepth; - ((mng_spltp)pChunkto)->iEntrycount = ((mng_spltp)pChunkfrom)->iEntrycount; - ((mng_spltp)pChunkto)->pEntries = ((mng_spltp)pChunkfrom)->pEntries; - - if (((mng_spltp)pChunkto)->iNamesize) - { - MNG_ALLOC (pData, ((mng_spltp)pChunkto)->zName, ((mng_spltp)pChunkto)->iNamesize); - MNG_COPY (((mng_spltp)pChunkto)->zName, ((mng_spltp)pChunkfrom)->zName, - ((mng_spltp)pChunkto)->iNamesize); - } - - if (((mng_spltp)pChunkto)->iEntrycount) - { - mng_uint32 iLen = ((mng_spltp)pChunkto)->iEntrycount * - (((mng_spltp)pChunkto)->iSampledepth * 3 + sizeof (mng_uint16)); - - MNG_ALLOC (pData, ((mng_spltp)pChunkto)->pEntries, iLen); - MNG_COPY (((mng_spltp)pChunkto)->pEntries, ((mng_spltp)pChunkfrom)->pEntries, iLen); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_SPLT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_hIST -ASSIGN_CHUNK_HDR (mng_assign_hist) -{ - mng_uint32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_HIST, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_hIST) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_histp)pChunkto)->iEntrycount = ((mng_histp)pChunkfrom)->iEntrycount; - - for (iX = 0; iX < ((mng_histp)pChunkto)->iEntrycount; iX++) - ((mng_histp)pChunkto)->aEntries [iX] = ((mng_histp)pChunkfrom)->aEntries [iX]; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_HIST, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_tIME -ASSIGN_CHUNK_HDR (mng_assign_time) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_TIME, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_tIME) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_timep)pChunkto)->iYear = ((mng_timep)pChunkfrom)->iYear; - ((mng_timep)pChunkto)->iMonth = ((mng_timep)pChunkfrom)->iMonth; - ((mng_timep)pChunkto)->iDay = ((mng_timep)pChunkfrom)->iDay; - ((mng_timep)pChunkto)->iHour = ((mng_timep)pChunkfrom)->iHour; - ((mng_timep)pChunkto)->iMinute = ((mng_timep)pChunkfrom)->iMinute; - ((mng_timep)pChunkto)->iSecond = ((mng_timep)pChunkfrom)->iSecond; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_TIME, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -ASSIGN_CHUNK_HDR (mng_assign_mhdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_MHDR, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_mhdrp)pChunkto)->iWidth = ((mng_mhdrp)pChunkfrom)->iWidth; - ((mng_mhdrp)pChunkto)->iHeight = ((mng_mhdrp)pChunkfrom)->iHeight; - ((mng_mhdrp)pChunkto)->iTicks = ((mng_mhdrp)pChunkfrom)->iTicks; - ((mng_mhdrp)pChunkto)->iLayercount = ((mng_mhdrp)pChunkfrom)->iLayercount; - ((mng_mhdrp)pChunkto)->iFramecount = ((mng_mhdrp)pChunkfrom)->iFramecount; - ((mng_mhdrp)pChunkto)->iPlaytime = ((mng_mhdrp)pChunkfrom)->iPlaytime; - ((mng_mhdrp)pChunkto)->iSimplicity = ((mng_mhdrp)pChunkfrom)->iSimplicity; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_MHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -ASSIGN_CHUNK_HDR (mng_assign_mend) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_MEND, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_MEND) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_MEND, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_LOOP -ASSIGN_CHUNK_HDR (mng_assign_loop) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_LOOP, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_LOOP) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_loopp)pChunkto)->iLevel = ((mng_loopp)pChunkfrom)->iLevel; - ((mng_loopp)pChunkto)->iRepeat = ((mng_loopp)pChunkfrom)->iRepeat; - ((mng_loopp)pChunkto)->iTermination = ((mng_loopp)pChunkfrom)->iTermination; - ((mng_loopp)pChunkto)->iItermin = ((mng_loopp)pChunkfrom)->iItermin; - ((mng_loopp)pChunkto)->iItermax = ((mng_loopp)pChunkfrom)->iItermax; - ((mng_loopp)pChunkto)->iCount = ((mng_loopp)pChunkfrom)->iCount; - -#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED - if (((mng_loopp)pChunkto)->iCount) - { - mng_uint32 iLen = ((mng_loopp)pChunkto)->iCount * sizeof (mng_uint32); - MNG_ALLOC (pData, ((mng_loopp)pChunkto)->pSignals, iLen); - MNG_COPY (((mng_loopp)pChunkto)->pSignals, ((mng_loopp)pChunkfrom)->pSignals, iLen); - } -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_LOOP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -ASSIGN_CHUNK_HDR (mng_assign_endl) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_ENDL, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_ENDL) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_endlp)pChunkto)->iLevel = ((mng_endlp)pChunkfrom)->iLevel; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_ENDL, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_DEFI -ASSIGN_CHUNK_HDR (mng_assign_defi) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_DEFI, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_DEFI) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_defip)pChunkto)->iObjectid = ((mng_defip)pChunkfrom)->iObjectid; - ((mng_defip)pChunkto)->bHasdonotshow = ((mng_defip)pChunkfrom)->bHasdonotshow; - ((mng_defip)pChunkto)->iDonotshow = ((mng_defip)pChunkfrom)->iDonotshow; - ((mng_defip)pChunkto)->bHasconcrete = ((mng_defip)pChunkfrom)->bHasconcrete; - ((mng_defip)pChunkto)->iConcrete = ((mng_defip)pChunkfrom)->iConcrete; - ((mng_defip)pChunkto)->bHasloca = ((mng_defip)pChunkfrom)->bHasloca; - ((mng_defip)pChunkto)->iXlocation = ((mng_defip)pChunkfrom)->iXlocation; - ((mng_defip)pChunkto)->iYlocation = ((mng_defip)pChunkfrom)->iYlocation; - ((mng_defip)pChunkto)->bHasclip = ((mng_defip)pChunkfrom)->bHasclip; - ((mng_defip)pChunkto)->iLeftcb = ((mng_defip)pChunkfrom)->iLeftcb; - ((mng_defip)pChunkto)->iRightcb = ((mng_defip)pChunkfrom)->iRightcb; - ((mng_defip)pChunkto)->iTopcb = ((mng_defip)pChunkfrom)->iTopcb; - ((mng_defip)pChunkto)->iBottomcb = ((mng_defip)pChunkfrom)->iBottomcb; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_DEFI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_BASI -ASSIGN_CHUNK_HDR (mng_assign_basi) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_BASI, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_BASI) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_basip)pChunkto)->iWidth = ((mng_basip)pChunkfrom)->iWidth; - ((mng_basip)pChunkto)->iHeight = ((mng_basip)pChunkfrom)->iHeight; - ((mng_basip)pChunkto)->iBitdepth = ((mng_basip)pChunkfrom)->iBitdepth; - ((mng_basip)pChunkto)->iColortype = ((mng_basip)pChunkfrom)->iColortype; - ((mng_basip)pChunkto)->iCompression = ((mng_basip)pChunkfrom)->iCompression; - ((mng_basip)pChunkto)->iFilter = ((mng_basip)pChunkfrom)->iFilter; - ((mng_basip)pChunkto)->iInterlace = ((mng_basip)pChunkfrom)->iInterlace; - ((mng_basip)pChunkto)->iRed = ((mng_basip)pChunkfrom)->iRed; - ((mng_basip)pChunkto)->iGreen = ((mng_basip)pChunkfrom)->iGreen; - ((mng_basip)pChunkto)->iBlue = ((mng_basip)pChunkfrom)->iBlue; - ((mng_basip)pChunkto)->iAlpha = ((mng_basip)pChunkfrom)->iAlpha; - ((mng_basip)pChunkto)->iViewable = ((mng_basip)pChunkfrom)->iViewable; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_BASI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_CLON -ASSIGN_CHUNK_HDR (mng_assign_clon) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_CLON, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_CLON) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_clonp)pChunkto)->iSourceid = ((mng_clonp)pChunkfrom)->iSourceid; - ((mng_clonp)pChunkto)->iCloneid = ((mng_clonp)pChunkfrom)->iCloneid; - ((mng_clonp)pChunkto)->iClonetype = ((mng_clonp)pChunkfrom)->iClonetype; -#ifdef MNG_OPTIMIZE_CHUNKREADER - ((mng_clonp)pChunkto)->bHasdonotshow = ((mng_clonp)pChunkfrom)->bHasdonotshow; -#endif - ((mng_clonp)pChunkto)->iDonotshow = ((mng_clonp)pChunkfrom)->iDonotshow; - ((mng_clonp)pChunkto)->iConcrete = ((mng_clonp)pChunkfrom)->iConcrete; - ((mng_clonp)pChunkto)->bHasloca = ((mng_clonp)pChunkfrom)->bHasloca; - ((mng_clonp)pChunkto)->iLocationtype = ((mng_clonp)pChunkfrom)->iLocationtype; - ((mng_clonp)pChunkto)->iLocationx = ((mng_clonp)pChunkfrom)->iLocationx; - ((mng_clonp)pChunkto)->iLocationy = ((mng_clonp)pChunkfrom)->iLocationy; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_CLON, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -ASSIGN_CHUNK_HDR (mng_assign_past) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_PAST, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_PAST) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_pastp)pChunkto)->iDestid = ((mng_pastp)pChunkfrom)->iDestid; - ((mng_pastp)pChunkto)->iTargettype = ((mng_pastp)pChunkfrom)->iTargettype; - ((mng_pastp)pChunkto)->iTargetx = ((mng_pastp)pChunkfrom)->iTargetx; - ((mng_pastp)pChunkto)->iTargety = ((mng_pastp)pChunkfrom)->iTargety; - ((mng_pastp)pChunkto)->iCount = ((mng_pastp)pChunkfrom)->iCount; - - if (((mng_pastp)pChunkto)->iCount) - { - mng_uint32 iLen = ((mng_pastp)pChunkto)->iCount * sizeof (mng_past_source); - - MNG_ALLOC (pData, ((mng_pastp)pChunkto)->pSources, iLen); - MNG_COPY (((mng_pastp)pChunkto)->pSources, ((mng_pastp)pChunkfrom)->pSources, iLen); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_PAST, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DISC -ASSIGN_CHUNK_HDR (mng_assign_disc) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_DISC, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_DISC) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_discp)pChunkto)->iCount = ((mng_discp)pChunkfrom)->iCount; - - if (((mng_discp)pChunkto)->iCount) - { - mng_uint32 iLen = ((mng_discp)pChunkto)->iCount * sizeof (mng_uint16); - - MNG_ALLOC (pData, ((mng_discp)pChunkto)->pObjectids, iLen); - MNG_COPY (((mng_discp)pChunkto)->pObjectids, ((mng_discp)pChunkfrom)->pObjectids, iLen); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_DISC, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_BACK -ASSIGN_CHUNK_HDR (mng_assign_back) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_BACK, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_BACK) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_backp)pChunkto)->iRed = ((mng_backp)pChunkfrom)->iRed; - ((mng_backp)pChunkto)->iGreen = ((mng_backp)pChunkfrom)->iGreen; - ((mng_backp)pChunkto)->iBlue = ((mng_backp)pChunkfrom)->iBlue; - ((mng_backp)pChunkto)->iMandatory = ((mng_backp)pChunkfrom)->iMandatory; - ((mng_backp)pChunkto)->iImageid = ((mng_backp)pChunkfrom)->iImageid; - ((mng_backp)pChunkto)->iTile = ((mng_backp)pChunkfrom)->iTile; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_BACK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_FRAM -ASSIGN_CHUNK_HDR (mng_assign_fram) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_FRAM, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_FRAM) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_framp)pChunkto)->bEmpty = ((mng_framp)pChunkfrom)->bEmpty; - ((mng_framp)pChunkto)->iMode = ((mng_framp)pChunkfrom)->iMode; - ((mng_framp)pChunkto)->iNamesize = ((mng_framp)pChunkfrom)->iNamesize; - ((mng_framp)pChunkto)->iChangedelay = ((mng_framp)pChunkfrom)->iChangedelay; - ((mng_framp)pChunkto)->iChangetimeout = ((mng_framp)pChunkfrom)->iChangetimeout; - ((mng_framp)pChunkto)->iChangeclipping = ((mng_framp)pChunkfrom)->iChangeclipping; - ((mng_framp)pChunkto)->iChangesyncid = ((mng_framp)pChunkfrom)->iChangesyncid; - ((mng_framp)pChunkto)->iDelay = ((mng_framp)pChunkfrom)->iDelay; - ((mng_framp)pChunkto)->iTimeout = ((mng_framp)pChunkfrom)->iTimeout; - ((mng_framp)pChunkto)->iBoundarytype = ((mng_framp)pChunkfrom)->iBoundarytype; - ((mng_framp)pChunkto)->iBoundaryl = ((mng_framp)pChunkfrom)->iBoundaryl; - ((mng_framp)pChunkto)->iBoundaryr = ((mng_framp)pChunkfrom)->iBoundaryr; - ((mng_framp)pChunkto)->iBoundaryt = ((mng_framp)pChunkfrom)->iBoundaryt; - ((mng_framp)pChunkto)->iBoundaryb = ((mng_framp)pChunkfrom)->iBoundaryb; - ((mng_framp)pChunkto)->iCount = ((mng_framp)pChunkfrom)->iCount; - - if (((mng_framp)pChunkto)->iNamesize) - { - MNG_ALLOC (pData, ((mng_framp)pChunkto)->zName, ((mng_framp)pChunkto)->iNamesize); - MNG_COPY (((mng_framp)pChunkto)->zName, ((mng_framp)pChunkfrom)->zName, - ((mng_framp)pChunkto)->iNamesize); - } - - if (((mng_framp)pChunkto)->iCount) - { - mng_uint32 iLen = ((mng_framp)pChunkto)->iCount * sizeof (mng_uint32); - - MNG_ALLOC (pData, ((mng_framp)pChunkto)->pSyncids, iLen); - MNG_COPY (((mng_framp)pChunkto)->pSyncids, ((mng_framp)pChunkfrom)->pSyncids, iLen); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_FRAM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_MOVE -ASSIGN_CHUNK_HDR (mng_assign_move) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_MOVE, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_MOVE) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_movep)pChunkto)->iFirstid = ((mng_movep)pChunkfrom)->iFirstid; - ((mng_movep)pChunkto)->iLastid = ((mng_movep)pChunkfrom)->iLastid; - ((mng_movep)pChunkto)->iMovetype = ((mng_movep)pChunkfrom)->iMovetype; - ((mng_movep)pChunkto)->iMovex = ((mng_movep)pChunkfrom)->iMovex; - ((mng_movep)pChunkto)->iMovey = ((mng_movep)pChunkfrom)->iMovey; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_MOVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_CLIP -ASSIGN_CHUNK_HDR (mng_assign_clip) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_CLIP, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_CLIP) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_clipp)pChunkto)->iFirstid = ((mng_clipp)pChunkfrom)->iFirstid; - ((mng_clipp)pChunkto)->iLastid = ((mng_clipp)pChunkfrom)->iLastid; - ((mng_clipp)pChunkto)->iCliptype = ((mng_clipp)pChunkfrom)->iCliptype; - ((mng_clipp)pChunkto)->iClipl = ((mng_clipp)pChunkfrom)->iClipl; - ((mng_clipp)pChunkto)->iClipr = ((mng_clipp)pChunkfrom)->iClipr; - ((mng_clipp)pChunkto)->iClipt = ((mng_clipp)pChunkfrom)->iClipt; - ((mng_clipp)pChunkto)->iClipb = ((mng_clipp)pChunkfrom)->iClipb; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_CLIP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_SHOW -ASSIGN_CHUNK_HDR (mng_assign_show) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_SHOW, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_SHOW) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_showp)pChunkto)->bEmpty = ((mng_showp)pChunkfrom)->bEmpty; - ((mng_showp)pChunkto)->iFirstid = ((mng_showp)pChunkfrom)->iFirstid; - ((mng_showp)pChunkto)->iLastid = ((mng_showp)pChunkfrom)->iLastid; - ((mng_showp)pChunkto)->iMode = ((mng_showp)pChunkfrom)->iMode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_SHOW, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_TERM -ASSIGN_CHUNK_HDR (mng_assign_term) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_TERM, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_TERM) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_termp)pChunkto)->iTermaction = ((mng_termp)pChunkfrom)->iTermaction; - ((mng_termp)pChunkto)->iIteraction = ((mng_termp)pChunkfrom)->iIteraction; - ((mng_termp)pChunkto)->iDelay = ((mng_termp)pChunkfrom)->iDelay; - ((mng_termp)pChunkto)->iItermax = ((mng_termp)pChunkfrom)->iItermax; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_TERM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SAVE -ASSIGN_CHUNK_HDR (mng_assign_save) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_SAVE, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_SAVE) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_savep)pChunkto)->bEmpty = ((mng_savep)pChunkfrom)->bEmpty; - ((mng_savep)pChunkto)->iOffsettype = ((mng_savep)pChunkfrom)->iOffsettype; - ((mng_savep)pChunkto)->iCount = ((mng_savep)pChunkfrom)->iCount; - - if (((mng_savep)pChunkto)->iCount) - { - mng_uint32 iX; - mng_save_entryp pEntry; - mng_uint32 iLen = ((mng_savep)pChunkto)->iCount * sizeof (mng_save_entry); - - MNG_ALLOC (pData, ((mng_savep)pChunkto)->pEntries, iLen); - MNG_COPY (((mng_savep)pChunkto)->pEntries, ((mng_savep)pChunkfrom)->pEntries, iLen); - - pEntry = ((mng_savep)pChunkto)->pEntries; - - for (iX = 0; iX < ((mng_savep)pChunkto)->iCount; iX++) - { - if (pEntry->iNamesize) - { - mng_pchar pTemp = pEntry->zName; - - MNG_ALLOC (pData, pEntry->zName, pEntry->iNamesize); - MNG_COPY (pEntry->zName, pTemp, pEntry->iNamesize); - } - else - { - pEntry->zName = MNG_NULL; - } - - pEntry++; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_SAVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SEEK -ASSIGN_CHUNK_HDR (mng_assign_seek) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_SEEK, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_SEEK) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_seekp)pChunkto)->iNamesize = ((mng_seekp)pChunkfrom)->iNamesize; - - if (((mng_seekp)pChunkto)->iNamesize) - { - MNG_ALLOC (pData, ((mng_seekp)pChunkto)->zName, ((mng_seekp)pChunkto)->iNamesize); - MNG_COPY (((mng_seekp)pChunkto)->zName, ((mng_seekp)pChunkfrom)->zName, - ((mng_seekp)pChunkto)->iNamesize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_SEEK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_eXPI -ASSIGN_CHUNK_HDR (mng_assign_expi) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_EXPI, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_eXPI) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_expip)pChunkto)->iSnapshotid = ((mng_expip)pChunkfrom)->iSnapshotid; - ((mng_expip)pChunkto)->iNamesize = ((mng_expip)pChunkfrom)->iNamesize; - - if (((mng_expip)pChunkto)->iNamesize) - { - MNG_ALLOC (pData, ((mng_expip)pChunkto)->zName, ((mng_expip)pChunkto)->iNamesize); - MNG_COPY (((mng_expip)pChunkto)->zName, ((mng_expip)pChunkfrom)->zName, - ((mng_expip)pChunkto)->iNamesize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_EXPI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_fPRI -ASSIGN_CHUNK_HDR (mng_assign_fpri) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_FPRI, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_fPRI) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_fprip)pChunkto)->iDeltatype = ((mng_fprip)pChunkfrom)->iDeltatype; - ((mng_fprip)pChunkto)->iPriority = ((mng_fprip)pChunkfrom)->iPriority; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_FPRI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_nEED -ASSIGN_CHUNK_HDR (mng_assign_need) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_NEED, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_nEED) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_needp)pChunkto)->iKeywordssize = ((mng_needp)pChunkfrom)->iKeywordssize; - - if (((mng_needp)pChunkto)->iKeywordssize) - { - MNG_ALLOC (pData, ((mng_needp)pChunkto)->zKeywords, ((mng_needp)pChunkto)->iKeywordssize); - MNG_COPY (((mng_needp)pChunkto)->zKeywords, ((mng_needp)pChunkfrom)->zKeywords, - ((mng_needp)pChunkto)->iKeywordssize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_NEED, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_pHYg -ASSIGN_CHUNK_HDR (mng_assign_phyg) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_PHYG, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_pHYg) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_phygp)pChunkto)->bEmpty = ((mng_phygp)pChunkfrom)->bEmpty; - ((mng_phygp)pChunkto)->iSizex = ((mng_phygp)pChunkfrom)->iSizex; - ((mng_phygp)pChunkto)->iSizey = ((mng_phygp)pChunkfrom)->iSizey; - ((mng_phygp)pChunkto)->iUnit = ((mng_phygp)pChunkfrom)->iUnit; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_PHYG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifdef MNG_INCLUDE_JNG -ASSIGN_CHUNK_HDR (mng_assign_jhdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_JHDR, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_JHDR) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_jhdrp)pChunkto)->iWidth = ((mng_jhdrp)pChunkfrom)->iWidth; - ((mng_jhdrp)pChunkto)->iHeight = ((mng_jhdrp)pChunkfrom)->iHeight; - ((mng_jhdrp)pChunkto)->iColortype = ((mng_jhdrp)pChunkfrom)->iColortype; - ((mng_jhdrp)pChunkto)->iImagesampledepth = ((mng_jhdrp)pChunkfrom)->iImagesampledepth; - ((mng_jhdrp)pChunkto)->iImagecompression = ((mng_jhdrp)pChunkfrom)->iImagecompression; - ((mng_jhdrp)pChunkto)->iImageinterlace = ((mng_jhdrp)pChunkfrom)->iImageinterlace; - ((mng_jhdrp)pChunkto)->iAlphasampledepth = ((mng_jhdrp)pChunkfrom)->iAlphasampledepth; - ((mng_jhdrp)pChunkto)->iAlphacompression = ((mng_jhdrp)pChunkfrom)->iAlphacompression; - ((mng_jhdrp)pChunkto)->iAlphafilter = ((mng_jhdrp)pChunkfrom)->iAlphafilter; - ((mng_jhdrp)pChunkto)->iAlphainterlace = ((mng_jhdrp)pChunkfrom)->iAlphainterlace; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_JHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -ASSIGN_CHUNK_HDR (mng_assign_jdaa) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_JDAA, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_JDAA) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_jdaap)pChunkto)->bEmpty = ((mng_jdaap)pChunkfrom)->bEmpty; - ((mng_jdaap)pChunkto)->iDatasize = ((mng_jdaap)pChunkfrom)->iDatasize; - - if (((mng_jdaap)pChunkto)->iDatasize) - { - MNG_ALLOC (pData, ((mng_jdaap)pChunkto)->pData, ((mng_jdaap)pChunkto)->iDatasize); - MNG_COPY (((mng_jdaap)pChunkto)->pData, ((mng_jdaap)pChunkfrom)->pData, - ((mng_jdaap)pChunkto)->iDatasize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_JDAA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -ASSIGN_CHUNK_HDR (mng_assign_jdat) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_JDAT, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_JDAT) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_jdatp)pChunkto)->bEmpty = ((mng_jdatp)pChunkfrom)->bEmpty; - ((mng_jdatp)pChunkto)->iDatasize = ((mng_jdatp)pChunkfrom)->iDatasize; - - if (((mng_jdatp)pChunkto)->iDatasize) - { - MNG_ALLOC (pData, ((mng_jdatp)pChunkto)->pData, ((mng_jdatp)pChunkto)->iDatasize); - MNG_COPY (((mng_jdatp)pChunkto)->pData, ((mng_jdatp)pChunkfrom)->pData, - ((mng_jdatp)pChunkto)->iDatasize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_JDAT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifdef MNG_INCLUDE_JNG -ASSIGN_CHUNK_HDR (mng_assign_jsep) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_JSEP, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_JSEP) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_JSEP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_NO_DELTA_PNG -ASSIGN_CHUNK_HDR (mng_assign_dhdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_DHDR, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_DHDR) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_dhdrp)pChunkto)->iObjectid = ((mng_dhdrp)pChunkfrom)->iObjectid; - ((mng_dhdrp)pChunkto)->iImagetype = ((mng_dhdrp)pChunkfrom)->iImagetype; - ((mng_dhdrp)pChunkto)->iDeltatype = ((mng_dhdrp)pChunkfrom)->iDeltatype; - ((mng_dhdrp)pChunkto)->iBlockwidth = ((mng_dhdrp)pChunkfrom)->iBlockwidth; - ((mng_dhdrp)pChunkto)->iBlockheight = ((mng_dhdrp)pChunkfrom)->iBlockheight; - ((mng_dhdrp)pChunkto)->iBlockx = ((mng_dhdrp)pChunkfrom)->iBlockx; - ((mng_dhdrp)pChunkto)->iBlocky = ((mng_dhdrp)pChunkfrom)->iBlocky; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_DHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_NO_DELTA_PNG -ASSIGN_CHUNK_HDR (mng_assign_prom) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_PROM, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_PROM) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_promp)pChunkto)->iColortype = ((mng_promp)pChunkfrom)->iColortype; - ((mng_promp)pChunkto)->iSampledepth = ((mng_promp)pChunkfrom)->iSampledepth; - ((mng_promp)pChunkto)->iFilltype = ((mng_promp)pChunkfrom)->iFilltype; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_PROM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_NO_DELTA_PNG -ASSIGN_CHUNK_HDR (mng_assign_ipng) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_IPNG, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_IPNG) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_IPNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_NO_DELTA_PNG -ASSIGN_CHUNK_HDR (mng_assign_pplt) -{ - mng_uint32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_PPLT, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_PPLT) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_ppltp)pChunkto)->iDeltatype = ((mng_ppltp)pChunkfrom)->iDeltatype; - ((mng_ppltp)pChunkto)->iCount = ((mng_ppltp)pChunkfrom)->iCount; - - for (iX = 0; iX < ((mng_ppltp)pChunkto)->iCount; iX++) - ((mng_ppltp)pChunkto)->aEntries [iX] = ((mng_ppltp)pChunkfrom)->aEntries [iX]; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_PPLT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG -ASSIGN_CHUNK_HDR (mng_assign_ijng) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_IJNG, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_IJNG) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_IJNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -ASSIGN_CHUNK_HDR (mng_assign_drop) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_DROP, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_DROP) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_dropp)pChunkto)->iCount = ((mng_dropp)pChunkfrom)->iCount; - - if (((mng_dropp)pChunkto)->iCount) - { - mng_uint32 iLen = ((mng_dropp)pChunkto)->iCount * sizeof (mng_uint32); - - MNG_ALLOC (pData, ((mng_dropp)pChunkto)->pChunknames, iLen); - MNG_COPY (((mng_dropp)pChunkto)->pChunknames, ((mng_dropp)pChunkfrom)->pChunknames, iLen); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_DROP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DBYK -ASSIGN_CHUNK_HDR (mng_assign_dbyk) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_DBYK, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_DBYK) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_dbykp)pChunkto)->iChunkname = ((mng_dbykp)pChunkfrom)->iChunkname; - ((mng_dbykp)pChunkto)->iPolarity = ((mng_dbykp)pChunkfrom)->iPolarity; - ((mng_dbykp)pChunkto)->iKeywordssize = ((mng_dbykp)pChunkfrom)->iKeywordssize; - - if (((mng_dbykp)pChunkto)->iKeywordssize) - { - MNG_ALLOC (pData, ((mng_dbykp)pChunkto)->zKeywords, ((mng_dbykp)pChunkto)->iKeywordssize); - MNG_COPY (((mng_dbykp)pChunkto)->zKeywords, ((mng_dbykp)pChunkfrom)->zKeywords, - ((mng_dbykp)pChunkto)->iKeywordssize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_DBYK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR -ASSIGN_CHUNK_HDR (mng_assign_ordr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_ORDR, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_ORDR) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_ordrp)pChunkto)->iCount = ((mng_ordrp)pChunkfrom)->iCount; - - if (((mng_ordrp)pChunkto)->iCount) - { - mng_uint32 iLen = ((mng_ordrp)pChunkto)->iCount * sizeof (mng_ordr_entry); - - MNG_ALLOC (pData, ((mng_ordrp)pChunkto)->pEntries, iLen); - MNG_COPY (((mng_ordrp)pChunkto)->pEntries, ((mng_ordrp)pChunkfrom)->pEntries, iLen); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_ORDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKASSIGN -#ifndef MNG_SKIPCHUNK_MAGN -ASSIGN_CHUNK_HDR (mng_assign_magn) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_MAGN, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_MAGN) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_magnp)pChunkto)->iFirstid = ((mng_magnp)pChunkfrom)->iFirstid; - ((mng_magnp)pChunkto)->iLastid = ((mng_magnp)pChunkfrom)->iLastid; - ((mng_magnp)pChunkto)->iMethodX = ((mng_magnp)pChunkfrom)->iMethodX; - ((mng_magnp)pChunkto)->iMX = ((mng_magnp)pChunkfrom)->iMX; - ((mng_magnp)pChunkto)->iMY = ((mng_magnp)pChunkfrom)->iMY; - ((mng_magnp)pChunkto)->iML = ((mng_magnp)pChunkfrom)->iML; - ((mng_magnp)pChunkto)->iMR = ((mng_magnp)pChunkfrom)->iMR; - ((mng_magnp)pChunkto)->iMT = ((mng_magnp)pChunkfrom)->iMT; - ((mng_magnp)pChunkto)->iMB = ((mng_magnp)pChunkfrom)->iMB; - ((mng_magnp)pChunkto)->iMethodY = ((mng_magnp)pChunkfrom)->iMethodY; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_MAGN, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_MPNG_PROPOSAL -ASSIGN_CHUNK_HDR (mng_assign_mpng) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_MPNG, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_mpNG) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_mpngp)pChunkto)->iFramewidth = ((mng_mpngp)pChunkfrom)->iFramewidth; - ((mng_mpngp)pChunkto)->iFrameheight = ((mng_mpngp)pChunkfrom)->iFrameheight; - ((mng_mpngp)pChunkto)->iNumplays = ((mng_mpngp)pChunkfrom)->iNumplays; - ((mng_mpngp)pChunkto)->iTickspersec = ((mng_mpngp)pChunkfrom)->iTickspersec; - ((mng_mpngp)pChunkto)->iCompressionmethod = ((mng_mpngp)pChunkfrom)->iCompressionmethod; - ((mng_mpngp)pChunkto)->iFramessize = ((mng_mpngp)pChunkfrom)->iFramessize; - - if (((mng_mpngp)pChunkto)->iFramessize) - { - MNG_ALLOC (pData, ((mng_mpngp)pChunkto)->pFrames, ((mng_mpngp)pChunkto)->iFramessize); - MNG_COPY (((mng_mpngp)pChunkto)->pFrames, ((mng_mpngp)pChunkfrom)->pFrames, - ((mng_mpngp)pChunkto)->iFramessize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_MPNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ANG_PROPOSAL -ASSIGN_CHUNK_HDR (mng_assign_ahdr) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_AHDR, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_ahDR) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_ahdrp)pChunkto)->iNumframes = ((mng_ahdrp)pChunkfrom)->iNumframes; - ((mng_ahdrp)pChunkto)->iTickspersec = ((mng_ahdrp)pChunkfrom)->iTickspersec; - ((mng_ahdrp)pChunkto)->iNumplays = ((mng_ahdrp)pChunkfrom)->iNumplays; - ((mng_ahdrp)pChunkto)->iTilewidth = ((mng_ahdrp)pChunkfrom)->iTilewidth; - ((mng_ahdrp)pChunkto)->iTileheight = ((mng_ahdrp)pChunkfrom)->iTileheight; - ((mng_ahdrp)pChunkto)->iInterlace = ((mng_ahdrp)pChunkfrom)->iInterlace; - ((mng_ahdrp)pChunkto)->iStillused = ((mng_ahdrp)pChunkfrom)->iStillused; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_AHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ANG_PROPOSAL -ASSIGN_CHUNK_HDR (mng_assign_adat) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_ADAT, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_adAT) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_adatp)pChunkto)->iTilessize = ((mng_adatp)pChunkfrom)->iTilessize; - - if (((mng_adatp)pChunkto)->iTilessize) - { - MNG_ALLOC (pData, ((mng_adatp)pChunkto)->pTiles, ((mng_adatp)pChunkto)->iTilessize); - MNG_COPY (((mng_adatp)pChunkto)->pTiles, ((mng_adatp)pChunkfrom)->pTiles, - ((mng_adatp)pChunkto)->iTilessize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_ADAT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_evNT -ASSIGN_CHUNK_HDR (mng_assign_evnt) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_EVNT, MNG_LC_START); -#endif - - if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_evNT) - MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ - - ((mng_evntp)pChunkto)->iCount = ((mng_evntp)pChunkfrom)->iCount; - - if (((mng_evntp)pChunkto)->iCount) - { - mng_uint32 iX; - mng_evnt_entryp pEntry; - mng_uint32 iLen = ((mng_evntp)pChunkto)->iCount * sizeof (mng_evnt_entry); - - MNG_ALLOC (pData, ((mng_evntp)pChunkto)->pEntries, iLen); - MNG_COPY (((mng_evntp)pChunkto)->pEntries, ((mng_evntp)pChunkfrom)->pEntries, iLen); - - pEntry = ((mng_evntp)pChunkto)->pEntries; - - for (iX = 0; iX < ((mng_evntp)pChunkto)->iCount; iX++) - { - if (pEntry->iSegmentnamesize) - { - mng_pchar pTemp = pEntry->zSegmentname; - - MNG_ALLOC (pData, pEntry->zSegmentname, pEntry->iSegmentnamesize+1); - MNG_COPY (pEntry->zSegmentname, pTemp, pEntry->iSegmentnamesize); - } - else - { - pEntry->zSegmentname = MNG_NULL; - } - - pEntry++; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_EVNT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -ASSIGN_CHUNK_HDR (mng_assign_unknown) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_UNKNOWN, MNG_LC_START); -#endif - - ((mng_unknown_chunkp)pChunkto)->iDatasize = ((mng_unknown_chunkp)pChunkfrom)->iDatasize; - - if (((mng_unknown_chunkp)pChunkto)->iDatasize) - { - MNG_ALLOC (pData, ((mng_unknown_chunkp)pChunkto)->pData, ((mng_unknown_chunkp)pChunkto)->iDatasize); - MNG_COPY (((mng_unknown_chunkp)pChunkto)->pData, ((mng_unknown_chunkp)pChunkfrom)->pData, - ((mng_unknown_chunkp)pChunkto)->iDatasize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ASSIGN_UNKNOWN, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_WRITE_PROCS */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_chunk_prc.c copyright (c) 2000-2005 G.Juyn * */ +/* * version : 1.0.10 * */ +/* * * */ +/* * purpose : Chunk initialization & cleanup (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the chunk initialization & cleanup * */ +/* * routines * */ +/* * * */ +/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - changed trace to macro for callback error-reporting * */ +/* * * */ +/* * 0.9.1 - 07/19/2000 - G.Juyn * */ +/* * - fixed creation-code * */ +/* * * */ +/* * 0.9.2 - 07/31/2000 - G.Juyn * */ +/* * - put add_chunk() inside MNG_INCLUDE_WRITE_PROCS wrapper * */ +/* * 0.9.2 - 08/01/2000 - G.Juyn * */ +/* * - wrapper for add_chunk() changed * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 0.9.3 - 08/26/2000 - G.Juyn * */ +/* * - added MAGN chunk * */ +/* * 0.9.3 - 10/16/2000 - G.Juyn * */ +/* * - added support for JDAA * */ +/* * * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * - added HLAPI function to copy chunks * */ +/* * 1.0.5 - 09/14/2002 - G.Juyn * */ +/* * - added event handling for dynamic MNG * */ +/* * 1.0.5 - 10/04/2002 - G.Juyn * */ +/* * - fixed chunk-storage for evNT chunk * */ +/* * 1.0.5 - 10/17/2002 - G.Juyn * */ +/* * - fixed issue in freeing evNT chunk * */ +/* * * */ +/* * 1.0.6 - 07/07/2003 - G.R-P * */ +/* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */ +/* * - added MNG_NO_DELTA_PNG reduction feature * */ +/* * 1.0.6 - 07/14/2003 - G.R-P * */ +/* * - added MNG_NO_LOOP_SIGNALS_SUPPORTED conditional * */ +/* * 1.0.6 - 07/29/2003 - G.R-P * */ +/* * - added conditionals around PAST chunk support * */ +/* * 1.0.6 - 08/17/2003 - G.R-P * */ +/* * - added conditionals around non-VLC chunk support * */ +/* * * */ +/* * 1.0.7 - 03/24/2004 - G.R-P * */ +/* * - fixed SKIPCHUNK_eXPI -> fPRI typo * */ +/* * * */ +/* * 1.0.9 - 09/25/2004 - G.Juyn * */ +/* * - replaced MNG_TWEAK_LARGE_FILES with permanent solution * */ +/* * 1.0.9 - 12/05/2004 - G.Juyn * */ +/* * - added conditional MNG_OPTIMIZE_CHUNKINITFREE * */ +/* * 1.0.9 - 12/06/2004 - G.Juyn * */ +/* * - added conditional MNG_OPTIMIZE_CHUNKASSIGN * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * * */ +/* * 1.0.10 - 07/30/2005 - G.Juyn * */ +/* * - fixed problem with CLON object during readdisplay() * */ +/* * 1.0.10 - 04/08/2007 - G.Juyn * */ +/* * - added support for mPNG proposal * */ +/* * 1.0.10 - 04/12/2007 - G.Juyn * */ +/* * - added support for ANG proposal * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_memory.h" +#include "libmng_chunks.h" +#include "libmng_chunk_prc.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ +/* * * */ +/* * General chunk routines * */ +/* * * */ +/* ************************************************************************** */ + +void mng_add_chunk (mng_datap pData, + mng_chunkp pChunk) +{ + if (!pData->pFirstchunk) /* list is still empty ? */ + { + pData->pFirstchunk = pChunk; /* then this becomes the first */ + +#ifdef MNG_SUPPORT_WRITE + if (!pData->iFirstchunkadded) + { + pData->iFirstchunkadded = ((mng_chunk_headerp)pChunk)->iChunkname; +#endif + + if (((mng_chunk_headerp)pChunk)->iChunkname == MNG_UINT_IHDR) + pData->eImagetype = mng_it_png; + else +#ifdef MNG_INCLUDE_JNG + if (((mng_chunk_headerp)pChunk)->iChunkname == MNG_UINT_JHDR) + pData->eImagetype = mng_it_jng; + else +#endif + pData->eImagetype = mng_it_mng; + + pData->eSigtype = pData->eImagetype; +#ifdef MNG_SUPPORT_WRITE + } +#endif + } + else + { /* else we make appropriate links */ + ((mng_chunk_headerp)pChunk)->pPrev = pData->pLastchunk; + ((mng_chunk_headerp)pData->pLastchunk)->pNext = pChunk; + } + + pData->pLastchunk = pChunk; /* and it's always the last */ + + return; +} + +/* ************************************************************************** */ +/* * * */ +/* * Chunk specific initialization routines * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_OPTIMIZE_CHUNKINITFREE +INIT_CHUNK_HDR (mng_init_general) +{ + MNG_ALLOC (pData, *ppChunk, ((mng_chunk_headerp)pHeader)->iChunksize); + MNG_COPY (*ppChunk, pHeader, sizeof (mng_chunk_header)); + return MNG_NOERROR; +} + +#else /* MNG_OPTIMIZE_CHUNKINITFREE */ + +/* ************************************************************************** */ + +INIT_CHUNK_HDR (mng_init_ihdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IHDR, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_ihdr)); + ((mng_ihdrp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +INIT_CHUNK_HDR (mng_init_plte) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_PLTE, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_plte)); + ((mng_pltep)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_PLTE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +INIT_CHUNK_HDR (mng_init_idat) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDAT, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_idat)); + ((mng_idatp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDAT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +INIT_CHUNK_HDR (mng_init_iend) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IEND, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_iend)); + ((mng_iendp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IEND, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +INIT_CHUNK_HDR (mng_init_trns) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_TRNS, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_trns)); + ((mng_trnsp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_TRNS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_gAMA +INIT_CHUNK_HDR (mng_init_gama) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_GAMA, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_gama)); + ((mng_gamap)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_GAMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_cHRM +INIT_CHUNK_HDR (mng_init_chrm) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_CHRM, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_chrm)); + ((mng_chrmp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_CHRM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sRGB +INIT_CHUNK_HDR (mng_init_srgb) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_SRGB, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_srgb)); + ((mng_srgbp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_SRGB, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iCCP +INIT_CHUNK_HDR (mng_init_iccp) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_ICCP, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_iccp)); + ((mng_iccpp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_ICCP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_tEXt +INIT_CHUNK_HDR (mng_init_text) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_TEXT, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_text)); + ((mng_textp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_TEXT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_zTXt +INIT_CHUNK_HDR (mng_init_ztxt) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_ZTXT, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_ztxt)); + ((mng_ztxtp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_ZTXT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iTXt +INIT_CHUNK_HDR (mng_init_itxt) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_ITXT, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_itxt)); + ((mng_itxtp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_ITXT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_bKGD +INIT_CHUNK_HDR (mng_init_bkgd) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_BKGD, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_bkgd)); + ((mng_bkgdp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_BKGD, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_pHYs +INIT_CHUNK_HDR (mng_init_phys) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_PHYS, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_phys)); + ((mng_physp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_PHYS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sBIT +INIT_CHUNK_HDR (mng_init_sbit) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_SBIT, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_sbit)); + ((mng_sbitp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_SBIT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sPLT +INIT_CHUNK_HDR (mng_init_splt) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_SPLT, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_splt)); + ((mng_spltp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_SPLT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_hIST +INIT_CHUNK_HDR (mng_init_hist) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_HIST, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_hist)); + ((mng_histp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_HIST, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_tIME +INIT_CHUNK_HDR (mng_init_time) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_TIME, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_time)); + ((mng_timep)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_TIME, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +INIT_CHUNK_HDR (mng_init_mhdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_MHDR, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_mhdr)); + ((mng_mhdrp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_MHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +INIT_CHUNK_HDR (mng_init_mend) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_MEND, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_mend)); + ((mng_mendp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_MEND, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_LOOP +INIT_CHUNK_HDR (mng_init_loop) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_LOOP, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_loop)); + ((mng_loopp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_LOOP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +INIT_CHUNK_HDR (mng_init_endl) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_ENDL, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_endl)); + ((mng_endlp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_ENDL, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DEFI +INIT_CHUNK_HDR (mng_init_defi) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_DEFI, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_defi)); + ((mng_defip)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_DEFI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_BASI +INIT_CHUNK_HDR (mng_init_basi) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_BASI, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_basi)); + ((mng_basip)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_BASI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_CLON +INIT_CHUNK_HDR (mng_init_clon) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_CLON, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_clon)); + ((mng_clonp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_CLON, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +INIT_CHUNK_HDR (mng_init_past) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_PAST, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_past)); + ((mng_pastp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_PAST, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DISC +INIT_CHUNK_HDR (mng_init_disc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_DISC, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_disc)); + ((mng_discp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_DISC, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_BACK +INIT_CHUNK_HDR (mng_init_back) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_BACK, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_back)); + ((mng_backp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_BACK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_FRAM +INIT_CHUNK_HDR (mng_init_fram) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_FRAM, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_fram)); + ((mng_framp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_FRAM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MOVE +INIT_CHUNK_HDR (mng_init_move) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_MOVE, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_move)); + ((mng_movep)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_MOVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_CLIP +INIT_CHUNK_HDR (mng_init_clip) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_CLIP, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_clip)); + ((mng_clipp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_CLIP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SHOW +INIT_CHUNK_HDR (mng_init_show) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_SHOW, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_show)); + ((mng_showp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_SHOW, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_TERM +INIT_CHUNK_HDR (mng_init_term) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_TERM, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_term)); + ((mng_termp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_TERM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SAVE +INIT_CHUNK_HDR (mng_init_save) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_SAVE, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_save)); + ((mng_savep)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_SAVE, MNG_LC_END); +#endif + + return MNG_NOERROR; + +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SEEK +INIT_CHUNK_HDR (mng_init_seek) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_SEEK, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_seek)); + ((mng_seekp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_SEEK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_eXPI +INIT_CHUNK_HDR (mng_init_expi) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_EXPI, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_expi)); + ((mng_expip)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_EXPI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_fPRI +INIT_CHUNK_HDR (mng_init_fpri) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_FPRI, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_fpri)); + ((mng_fprip)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_FPRI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_nEED +INIT_CHUNK_HDR (mng_init_need) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_NEED, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_need)); + ((mng_needp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_NEED, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_pHYg +INIT_CHUNK_HDR (mng_init_phyg) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_PHYG, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_phyg)); + ((mng_phygp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_PHYG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +INIT_CHUNK_HDR (mng_init_jhdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JHDR, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_jhdr)); + ((mng_jhdrp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +INIT_CHUNK_HDR (mng_init_jdaa) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JDAA, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_jdaa)); + ((mng_jdaap)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JDAA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +INIT_CHUNK_HDR (mng_init_jdat) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JDAT, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_jdat)); + ((mng_jdatp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JDAT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +INIT_CHUNK_HDR (mng_init_jsep) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JSEP, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_jsep)); + ((mng_jsepp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JSEP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +INIT_CHUNK_HDR (mng_init_dhdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_DHDR, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_dhdr)); + ((mng_dhdrp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_DHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +INIT_CHUNK_HDR (mng_init_prom) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_PROM, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_prom)); + ((mng_promp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_PROM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +INIT_CHUNK_HDR (mng_init_ipng) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IPNG, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_ipng)); + ((mng_ipngp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IPNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +INIT_CHUNK_HDR (mng_init_pplt) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_PPLT, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_pplt)); + ((mng_ppltp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_PPLT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG +INIT_CHUNK_HDR (mng_init_ijng) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IJNG, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_ijng)); + ((mng_ijngp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IJNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +INIT_CHUNK_HDR (mng_init_drop) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_DROP, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_drop)); + ((mng_dropp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_DROP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DBYK +INIT_CHUNK_HDR (mng_init_dbyk) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_DBYK, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_dbyk)); + ((mng_dbykp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_DBYK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR +INIT_CHUNK_HDR (mng_init_ordr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_ORDR, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_ordr)); + ((mng_ordrp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_ORDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MAGN +INIT_CHUNK_HDR (mng_init_magn) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_MAGN, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_magn)); + ((mng_magnp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_MAGN, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_evNT +INIT_CHUNK_HDR (mng_init_evnt) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_EVNT, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_evnt)); + ((mng_evntp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_EVNT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +INIT_CHUNK_HDR (mng_init_unknown) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_UNKNOWN, MNG_LC_START); +#endif + + MNG_ALLOC (pData, *ppChunk, sizeof (mng_unknown_chunk)); + ((mng_unknown_chunkp)*ppChunk)->sHeader = *((mng_chunk_headerp)pHeader); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_UNKNOWN, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#endif /* MNG_OPTIMIZE_CHUNKINITFREE */ + +/* ************************************************************************** */ +/* * * */ +/* * Chunk specific cleanup routines * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_OPTIMIZE_CHUNKINITFREE +FREE_CHUNK_HDR (mng_free_general) +{ + MNG_FREEX (pData, pHeader, ((mng_chunk_headerp)pHeader)->iChunksize); + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +FREE_CHUNK_HDR (mng_free_ihdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_IHDR, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_ihdr)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_IHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +FREE_CHUNK_HDR (mng_free_plte) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_PLTE, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_plte)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_PLTE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +FREE_CHUNK_HDR (mng_free_idat) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_IDAT, MNG_LC_START); +#endif + + if (((mng_idatp)pHeader)->iDatasize) + MNG_FREEX (pData, ((mng_idatp)pHeader)->pData, + ((mng_idatp)pHeader)->iDatasize); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_idat)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_IDAT, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +FREE_CHUNK_HDR (mng_free_iend) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_IEND, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_iend)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_IEND, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +FREE_CHUNK_HDR (mng_free_trns) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_TRNS, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_trns)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_TRNS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_gAMA +FREE_CHUNK_HDR (mng_free_gama) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_GAMA, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_gama)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_GAMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_cHRM +FREE_CHUNK_HDR (mng_free_chrm) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_CHRM, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_chrm)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_CHRM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_sRGB +FREE_CHUNK_HDR (mng_free_srgb) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_SRGB, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_srgb)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_SRGB, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iCCP +FREE_CHUNK_HDR (mng_free_iccp) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ICCP, MNG_LC_START); +#endif + + if (((mng_iccpp)pHeader)->iNamesize) + MNG_FREEX (pData, ((mng_iccpp)pHeader)->zName, + ((mng_iccpp)pHeader)->iNamesize + 1); + + if (((mng_iccpp)pHeader)->iProfilesize) + MNG_FREEX (pData, ((mng_iccpp)pHeader)->pProfile, + ((mng_iccpp)pHeader)->iProfilesize); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_iccp)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ICCP, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_tEXt +FREE_CHUNK_HDR (mng_free_text) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_TEXT, MNG_LC_START); +#endif + + if (((mng_textp)pHeader)->iKeywordsize) + MNG_FREEX (pData, ((mng_textp)pHeader)->zKeyword, + ((mng_textp)pHeader)->iKeywordsize + 1); + + if (((mng_textp)pHeader)->iTextsize) + MNG_FREEX (pData, ((mng_textp)pHeader)->zText, + ((mng_textp)pHeader)->iTextsize + 1); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_text)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_TEXT, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_zTXt +FREE_CHUNK_HDR (mng_free_ztxt) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ZTXT, MNG_LC_START); +#endif + + if (((mng_ztxtp)pHeader)->iKeywordsize) + MNG_FREEX (pData, ((mng_ztxtp)pHeader)->zKeyword, + ((mng_ztxtp)pHeader)->iKeywordsize + 1); + + if (((mng_ztxtp)pHeader)->iTextsize) + MNG_FREEX (pData, ((mng_ztxtp)pHeader)->zText, + ((mng_ztxtp)pHeader)->iTextsize); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_ztxt)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ZTXT, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ +#ifndef MNG_SKIPCHUNK_iTXt +FREE_CHUNK_HDR (mng_free_itxt) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ITXT, MNG_LC_START); +#endif + + if (((mng_itxtp)pHeader)->iKeywordsize) + MNG_FREEX (pData, ((mng_itxtp)pHeader)->zKeyword, + ((mng_itxtp)pHeader)->iKeywordsize + 1); + + if (((mng_itxtp)pHeader)->iLanguagesize) + MNG_FREEX (pData, ((mng_itxtp)pHeader)->zLanguage, + ((mng_itxtp)pHeader)->iLanguagesize + 1); + + if (((mng_itxtp)pHeader)->iTranslationsize) + MNG_FREEX (pData, ((mng_itxtp)pHeader)->zTranslation, + ((mng_itxtp)pHeader)->iTranslationsize + 1); + + if (((mng_itxtp)pHeader)->iTextsize) + MNG_FREEX (pData, ((mng_itxtp)pHeader)->zText, + ((mng_itxtp)pHeader)->iTextsize); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_itxt)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ITXT, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ +#ifdef MNG_INCLUDE_MPNG_PROPOSAL +FREE_CHUNK_HDR (mng_free_mpng) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_MPNG, MNG_LC_START); +#endif + + if (((mng_mpngp)pHeader)->iFramessize) + MNG_FREEX (pData, ((mng_mpngp)pHeader)->pFrames, + ((mng_mpngp)pHeader)->iFramessize); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_mpng)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_MPNG, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ +#ifdef MNG_INCLUDE_ANG_PROPOSAL +FREE_CHUNK_HDR (mng_free_adat) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ADAT, MNG_LC_START); +#endif + + if (((mng_adatp)pHeader)->iTilessize) + MNG_FREEX (pData, ((mng_adatp)pHeader)->pTiles, ((mng_adatp)pHeader)->iTilessize); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_adat)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ADAT, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_bKGD +FREE_CHUNK_HDR (mng_free_bkgd) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_BKGD, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_bkgd)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_BKGD, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_pHYs +FREE_CHUNK_HDR (mng_free_phys) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_PHYS, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_phys)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_PHYS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_sBIT +FREE_CHUNK_HDR (mng_free_sbit) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_SBIT, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_sbit)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_SBIT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sPLT +FREE_CHUNK_HDR (mng_free_splt) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_SPLT, MNG_LC_START); +#endif + + if (((mng_spltp)pHeader)->iNamesize) + MNG_FREEX (pData, ((mng_spltp)pHeader)->zName, + ((mng_spltp)pHeader)->iNamesize + 1); + + if (((mng_spltp)pHeader)->iEntrycount) + MNG_FREEX (pData, ((mng_spltp)pHeader)->pEntries, + ((mng_spltp)pHeader)->iEntrycount * + (((mng_spltp)pHeader)->iSampledepth * 3 + sizeof (mng_uint16)) ); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_splt)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_SPLT, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_hIST +FREE_CHUNK_HDR (mng_free_hist) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_HIST, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_hist)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_HIST, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_tIME +FREE_CHUNK_HDR (mng_free_time) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_TIME, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_time)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_TIME, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +FREE_CHUNK_HDR (mng_free_mhdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_MHDR, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_mhdr)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_MHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +FREE_CHUNK_HDR (mng_free_mend) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_MEND, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_mend)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_MEND, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_LOOP +FREE_CHUNK_HDR (mng_free_loop) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_LOOP, MNG_LC_START); +#endif + +#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED + if (((mng_loopp)pHeader)->iCount) + MNG_FREEX (pData, ((mng_loopp)pHeader)->pSignals, + ((mng_loopp)pHeader)->iCount * sizeof (mng_uint32) ); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_loop)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_LOOP, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +FREE_CHUNK_HDR (mng_free_endl) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ENDL, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_endl)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ENDL, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_DEFI +FREE_CHUNK_HDR (mng_free_defi) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_DEFI, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_defi)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_DEFI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_BASI +FREE_CHUNK_HDR (mng_free_basi) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_BASI, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_basi)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_BASI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_CLON +FREE_CHUNK_HDR (mng_free_clon) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_CLON, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_clon)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_CLON, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +FREE_CHUNK_HDR (mng_free_past) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_PAST, MNG_LC_START); +#endif + + if (((mng_pastp)pHeader)->iCount) + MNG_FREEX (pData, ((mng_pastp)pHeader)->pSources, + ((mng_pastp)pHeader)->iCount * sizeof (mng_past_source) ); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_past)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_PAST, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DISC +FREE_CHUNK_HDR (mng_free_disc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_DISC, MNG_LC_START); +#endif + + if (((mng_discp)pHeader)->iCount) + MNG_FREEX (pData, ((mng_discp)pHeader)->pObjectids, + ((mng_discp)pHeader)->iCount * sizeof (mng_uint16) ); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_disc)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_DISC, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_BACK +FREE_CHUNK_HDR (mng_free_back) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_BACK, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_back)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_BACK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_FRAM +FREE_CHUNK_HDR (mng_free_fram) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_FRAM, MNG_LC_START); +#endif + + if (((mng_framp)pHeader)->iNamesize) + MNG_FREEX (pData, ((mng_framp)pHeader)->zName, + ((mng_framp)pHeader)->iNamesize + 1); + + if (((mng_framp)pHeader)->iCount) + MNG_FREEX (pData, ((mng_framp)pHeader)->pSyncids, + ((mng_framp)pHeader)->iCount * sizeof (mng_uint32) ); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_fram)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_FRAM, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_MOVE +FREE_CHUNK_HDR (mng_free_move) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_MOVE, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_move)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_MOVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_CLIP +FREE_CHUNK_HDR (mng_free_clip) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_CLIP, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_clip)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_CLIP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_SHOW +FREE_CHUNK_HDR (mng_free_show) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_SHOW, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_show)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_SHOW, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_TERM +FREE_CHUNK_HDR (mng_free_term) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_TERM, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_term)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_TERM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SAVE +FREE_CHUNK_HDR (mng_free_save) +{ + mng_save_entryp pEntry = ((mng_savep)pHeader)->pEntries; + mng_uint32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_SAVE, MNG_LC_START); +#endif + + for (iX = 0; iX < ((mng_savep)pHeader)->iCount; iX++) + { + if (pEntry->iNamesize) + MNG_FREEX (pData, pEntry->zName, pEntry->iNamesize); + + pEntry = pEntry + sizeof (mng_save_entry); + } + + if (((mng_savep)pHeader)->iCount) + MNG_FREEX (pData, ((mng_savep)pHeader)->pEntries, + ((mng_savep)pHeader)->iCount * sizeof (mng_save_entry) ); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_save)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_SAVE, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SEEK +FREE_CHUNK_HDR (mng_free_seek) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_SEEK, MNG_LC_START); +#endif + + if (((mng_seekp)pHeader)->iNamesize) + MNG_FREEX (pData, ((mng_seekp)pHeader)->zName, + ((mng_seekp)pHeader)->iNamesize + 1); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_seek)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_SEEK, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_eXPI +FREE_CHUNK_HDR (mng_free_expi) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_EXPI, MNG_LC_START); +#endif + + if (((mng_expip)pHeader)->iNamesize) + MNG_FREEX (pData, ((mng_expip)pHeader)->zName, + ((mng_expip)pHeader)->iNamesize + 1); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_expi)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_EXPI, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_fPRI +FREE_CHUNK_HDR (mng_free_fpri) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_FPRI, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_fpri)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_FPRI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_nEED +FREE_CHUNK_HDR (mng_free_need) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_NEED, MNG_LC_START); +#endif + + if (((mng_needp)pHeader)->iKeywordssize) + MNG_FREEX (pData, ((mng_needp)pHeader)->zKeywords, + ((mng_needp)pHeader)->iKeywordssize + 1); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_need)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_NEED, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_pHYg +FREE_CHUNK_HDR (mng_free_phyg) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_PHYG, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_phyg)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_PHYG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifdef MNG_INCLUDE_JNG +FREE_CHUNK_HDR (mng_free_jhdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_JHDR, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_jhdr)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_JHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +FREE_CHUNK_HDR (mng_free_jdaa) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_JDAA, MNG_LC_START); +#endif + + if (((mng_jdaap)pHeader)->iDatasize) + MNG_FREEX (pData, ((mng_jdaap)pHeader)->pData, + ((mng_jdaap)pHeader)->iDatasize); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_jdaa)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_JDAA, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +FREE_CHUNK_HDR (mng_free_jdat) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_JDAT, MNG_LC_START); +#endif + + if (((mng_jdatp)pHeader)->iDatasize) + MNG_FREEX (pData, ((mng_jdatp)pHeader)->pData, + ((mng_jdatp)pHeader)->iDatasize); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_jdat)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_JDAT, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifdef MNG_INCLUDE_JNG +FREE_CHUNK_HDR (mng_free_jsep) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_JSEP, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_jsep)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_JSEP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_NO_DELTA_PNG +FREE_CHUNK_HDR (mng_free_dhdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_DHDR, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_dhdr)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_DHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_NO_DELTA_PNG +FREE_CHUNK_HDR (mng_free_prom) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_PROM, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_prom)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_PROM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_NO_DELTA_PNG +FREE_CHUNK_HDR (mng_free_ipng) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_IPNG, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_ipng)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_IPNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_NO_DELTA_PNG +FREE_CHUNK_HDR (mng_free_pplt) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_PPLT, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_pplt)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_PPLT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG +FREE_CHUNK_HDR (mng_free_ijng) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_IJNG, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_ijng)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_IJNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +FREE_CHUNK_HDR (mng_free_drop) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_DROP, MNG_LC_START); +#endif + + if (((mng_dropp)pHeader)->iCount) + MNG_FREEX (pData, ((mng_dropp)pHeader)->pChunknames, + ((mng_dropp)pHeader)->iCount * sizeof (mng_chunkid) ); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_drop)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_DROP, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DBYK +FREE_CHUNK_HDR (mng_free_dbyk) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_DBYK, MNG_LC_START); +#endif + + if (((mng_dbykp)pHeader)->iKeywordssize) + MNG_FREEX (pData, ((mng_dbykp)pHeader)->zKeywords, + ((mng_dbykp)pHeader)->iKeywordssize); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_dbyk)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_DBYK, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR +FREE_CHUNK_HDR (mng_free_ordr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ORDR, MNG_LC_START); +#endif + + if (((mng_ordrp)pHeader)->iCount) + MNG_FREEX (pData, ((mng_ordrp)pHeader)->pEntries, + ((mng_ordrp)pHeader)->iCount * sizeof (mng_ordr_entry) ); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_ordr)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ORDR, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE +#ifndef MNG_SKIPCHUNK_MAGN +FREE_CHUNK_HDR (mng_free_magn) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_MAGN, MNG_LC_START); +#endif + + MNG_FREEX (pData, pHeader, sizeof (mng_magn)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_MAGN, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_evNT +FREE_CHUNK_HDR (mng_free_evnt) +{ + mng_evnt_entryp pEntry = ((mng_evntp)pHeader)->pEntries; + mng_uint32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_EVNT, MNG_LC_START); +#endif + + for (iX = 0; iX < ((mng_evntp)pHeader)->iCount; iX++) + { + if (pEntry->iSegmentnamesize) + MNG_FREEX (pData, pEntry->zSegmentname, pEntry->iSegmentnamesize+1); + + pEntry++; + } + + if (((mng_evntp)pHeader)->iCount) + MNG_FREEX (pData, ((mng_evntp)pHeader)->pEntries, + ((mng_evntp)pHeader)->iCount * sizeof (mng_evnt_entry) ); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_evnt)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_EVNT, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} +#endif + +/* ************************************************************************** */ + +FREE_CHUNK_HDR (mng_free_unknown) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_UNKNOWN, MNG_LC_START); +#endif + + if (((mng_unknown_chunkp)pHeader)->iDatasize) + MNG_FREEX (pData, ((mng_unknown_chunkp)pHeader)->pData, + ((mng_unknown_chunkp)pHeader)->iDatasize); + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + MNG_FREEX (pData, pHeader, sizeof (mng_unknown_chunk)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_UNKNOWN, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_CHUNKINITFREE + return MNG_NOERROR; +#else + return mng_free_general(pData, pHeader); +#endif +} + +/* ************************************************************************** */ +/* * * */ +/* * Chunk specific copy routines * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_WRITE_PROCS + +/* ************************************************************************** */ + +#ifdef MNG_OPTIMIZE_CHUNKASSIGN +ASSIGN_CHUNK_HDR (mng_assign_general) +{ + mng_ptr pSrc = (mng_uint8p)pChunkfrom + sizeof (mng_chunk_header); + mng_ptr pDst = (mng_uint8p)pChunkto + sizeof (mng_chunk_header); + mng_size_t iLen = ((mng_chunk_headerp)pChunkfrom)->iChunksize - sizeof (mng_chunk_header); + + MNG_COPY (pDst, pSrc, iLen); + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +ASSIGN_CHUNK_HDR (mng_assign_ihdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_IHDR, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_IHDR) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_ihdrp)pChunkto)->iWidth = ((mng_ihdrp)pChunkfrom)->iWidth; + ((mng_ihdrp)pChunkto)->iHeight = ((mng_ihdrp)pChunkfrom)->iHeight; + ((mng_ihdrp)pChunkto)->iBitdepth = ((mng_ihdrp)pChunkfrom)->iBitdepth; + ((mng_ihdrp)pChunkto)->iColortype = ((mng_ihdrp)pChunkfrom)->iColortype; + ((mng_ihdrp)pChunkto)->iCompression = ((mng_ihdrp)pChunkfrom)->iCompression; + ((mng_ihdrp)pChunkto)->iFilter = ((mng_ihdrp)pChunkfrom)->iFilter; + ((mng_ihdrp)pChunkto)->iInterlace = ((mng_ihdrp)pChunkfrom)->iInterlace; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_IHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +ASSIGN_CHUNK_HDR (mng_assign_plte) +{ + mng_uint32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_PLTE, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_PLTE) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_pltep)pChunkto)->bEmpty = ((mng_pltep)pChunkfrom)->bEmpty; + ((mng_pltep)pChunkto)->iEntrycount = ((mng_pltep)pChunkfrom)->iEntrycount; + + for (iX = 0; iX < ((mng_pltep)pChunkto)->iEntrycount; iX++) + ((mng_pltep)pChunkto)->aEntries [iX] = ((mng_pltep)pChunkfrom)->aEntries [iX]; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_PLTE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +ASSIGN_CHUNK_HDR (mng_assign_idat) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_IDAT, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_IDAT) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_idatp)pChunkto)->bEmpty = ((mng_idatp)pChunkfrom)->bEmpty; + ((mng_idatp)pChunkto)->iDatasize = ((mng_idatp)pChunkfrom)->iDatasize; + + if (((mng_idatp)pChunkto)->iDatasize) + { + MNG_ALLOC (pData, ((mng_idatp)pChunkto)->pData, ((mng_idatp)pChunkto)->iDatasize); + MNG_COPY (((mng_idatp)pChunkto)->pData, ((mng_idatp)pChunkfrom)->pData, + ((mng_idatp)pChunkto)->iDatasize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_IDAT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +ASSIGN_CHUNK_HDR (mng_assign_iend) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_IEND, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_IEND) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_IEND, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +ASSIGN_CHUNK_HDR (mng_assign_trns) +{ + mng_uint32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_TRNS, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_tRNS) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_trnsp)pChunkto)->bEmpty = ((mng_trnsp)pChunkfrom)->bEmpty; + ((mng_trnsp)pChunkto)->bGlobal = ((mng_trnsp)pChunkfrom)->bGlobal; + ((mng_trnsp)pChunkto)->iType = ((mng_trnsp)pChunkfrom)->iType; + ((mng_trnsp)pChunkto)->iCount = ((mng_trnsp)pChunkfrom)->iCount; + ((mng_trnsp)pChunkto)->iGray = ((mng_trnsp)pChunkfrom)->iGray; + ((mng_trnsp)pChunkto)->iRed = ((mng_trnsp)pChunkfrom)->iRed; + ((mng_trnsp)pChunkto)->iGreen = ((mng_trnsp)pChunkfrom)->iGreen; + ((mng_trnsp)pChunkto)->iBlue = ((mng_trnsp)pChunkfrom)->iBlue; + ((mng_trnsp)pChunkto)->iRawlen = ((mng_trnsp)pChunkfrom)->iRawlen; + + for (iX = 0; iX < ((mng_trnsp)pChunkto)->iCount; iX++) + ((mng_trnsp)pChunkto)->aEntries [iX] = ((mng_trnsp)pChunkfrom)->aEntries [iX]; + + for (iX = 0; iX < ((mng_trnsp)pChunkto)->iRawlen; iX++) + ((mng_trnsp)pChunkto)->aRawdata [iX] = ((mng_trnsp)pChunkfrom)->aRawdata [iX]; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_TRNS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_gAMA +ASSIGN_CHUNK_HDR (mng_assign_gama) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_GAMA, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_gAMA) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_gamap)pChunkto)->bEmpty = ((mng_gamap)pChunkfrom)->bEmpty; + ((mng_gamap)pChunkto)->iGamma = ((mng_gamap)pChunkfrom)->iGamma; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_GAMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_cHRM +ASSIGN_CHUNK_HDR (mng_assign_chrm) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_CHRM, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_cHRM) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_chrmp)pChunkto)->bEmpty = ((mng_chrmp)pChunkfrom)->bEmpty; + ((mng_chrmp)pChunkto)->iWhitepointx = ((mng_chrmp)pChunkfrom)->iWhitepointx; + ((mng_chrmp)pChunkto)->iWhitepointy = ((mng_chrmp)pChunkfrom)->iWhitepointy; + ((mng_chrmp)pChunkto)->iRedx = ((mng_chrmp)pChunkfrom)->iRedx; + ((mng_chrmp)pChunkto)->iRedy = ((mng_chrmp)pChunkfrom)->iRedy; + ((mng_chrmp)pChunkto)->iGreenx = ((mng_chrmp)pChunkfrom)->iGreenx; + ((mng_chrmp)pChunkto)->iGreeny = ((mng_chrmp)pChunkfrom)->iGreeny; + ((mng_chrmp)pChunkto)->iBluex = ((mng_chrmp)pChunkfrom)->iBluex; + ((mng_chrmp)pChunkto)->iBluey = ((mng_chrmp)pChunkfrom)->iBluey; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_CHRM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_sRGB +ASSIGN_CHUNK_HDR (mng_assign_srgb) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_SRGB, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_sRGB) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_srgbp)pChunkto)->iRenderingintent = ((mng_srgbp)pChunkfrom)->iRenderingintent; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_SRGB, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iCCP +ASSIGN_CHUNK_HDR (mng_assign_iccp) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_ICCP, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_iCCP) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_iccpp)pChunkto)->bEmpty = ((mng_iccpp)pChunkfrom)->bEmpty; + ((mng_iccpp)pChunkto)->iNamesize = ((mng_iccpp)pChunkfrom)->iNamesize; + ((mng_iccpp)pChunkto)->iCompression = ((mng_iccpp)pChunkfrom)->iCompression; + ((mng_iccpp)pChunkto)->iProfilesize = ((mng_iccpp)pChunkfrom)->iProfilesize; + + if (((mng_iccpp)pChunkto)->iNamesize) + { + MNG_ALLOC (pData, ((mng_iccpp)pChunkto)->zName, ((mng_iccpp)pChunkto)->iNamesize); + MNG_COPY (((mng_iccpp)pChunkto)->zName, ((mng_iccpp)pChunkfrom)->zName, + ((mng_iccpp)pChunkto)->iNamesize); + } + + if (((mng_iccpp)pChunkto)->iProfilesize) + { + MNG_ALLOC (pData, ((mng_iccpp)pChunkto)->pProfile, ((mng_iccpp)pChunkto)->iProfilesize); + MNG_COPY (((mng_iccpp)pChunkto)->pProfile, ((mng_iccpp)pChunkfrom)->pProfile, + ((mng_iccpp)pChunkto)->iProfilesize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_ICCP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_tEXt +ASSIGN_CHUNK_HDR (mng_assign_text) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_TEXT, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_tEXt) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_textp)pChunkto)->iKeywordsize = ((mng_textp)pChunkfrom)->iKeywordsize; + ((mng_textp)pChunkto)->iTextsize = ((mng_textp)pChunkfrom)->iTextsize; + + if (((mng_textp)pChunkto)->iKeywordsize) + { + MNG_ALLOC (pData, ((mng_itxtp)pChunkto)->zKeyword, ((mng_textp)pChunkto)->iKeywordsize); + MNG_COPY (((mng_itxtp)pChunkto)->zKeyword, ((mng_textp)pChunkfrom)->zKeyword, + ((mng_itxtp)pChunkto)->iKeywordsize); + } + + if (((mng_textp)pChunkto)->iTextsize) + { + MNG_ALLOC (pData, ((mng_textp)pChunkto)->zText, ((mng_textp)pChunkto)->iTextsize); + MNG_COPY (((mng_textp)pChunkto)->zText, ((mng_textp)pChunkfrom)->zText, + ((mng_textp)pChunkto)->iTextsize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_TEXT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_zTXt +ASSIGN_CHUNK_HDR (mng_assign_ztxt) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_ZTXT, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_zTXt) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_ztxtp)pChunkto)->iKeywordsize = ((mng_ztxtp)pChunkfrom)->iKeywordsize; + ((mng_ztxtp)pChunkto)->iCompression = ((mng_ztxtp)pChunkfrom)->iCompression; + ((mng_ztxtp)pChunkto)->iTextsize = ((mng_ztxtp)pChunkfrom)->iTextsize; + + if (((mng_ztxtp)pChunkto)->iKeywordsize) + { + MNG_ALLOC (pData, ((mng_ztxtp)pChunkto)->zKeyword, ((mng_ztxtp)pChunkto)->iKeywordsize); + MNG_COPY (((mng_ztxtp)pChunkto)->zKeyword, ((mng_ztxtp)pChunkfrom)->zKeyword, + ((mng_ztxtp)pChunkto)->iKeywordsize); + } + + if (((mng_ztxtp)pChunkto)->iTextsize) + { + MNG_ALLOC (pData, ((mng_ztxtp)pChunkto)->zText, ((mng_ztxtp)pChunkto)->iTextsize); + MNG_COPY (((mng_ztxtp)pChunkto)->zText, ((mng_ztxtp)pChunkfrom)->zText, + ((mng_ztxtp)pChunkto)->iTextsize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_ZTXT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iTXt +ASSIGN_CHUNK_HDR (mng_assign_itxt) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_ITXT, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_iTXt) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_itxtp)pChunkto)->iKeywordsize = ((mng_itxtp)pChunkfrom)->iKeywordsize; + ((mng_itxtp)pChunkto)->iCompressionflag = ((mng_itxtp)pChunkfrom)->iCompressionflag; + ((mng_itxtp)pChunkto)->iCompressionmethod = ((mng_itxtp)pChunkfrom)->iCompressionmethod; + ((mng_itxtp)pChunkto)->iLanguagesize = ((mng_itxtp)pChunkfrom)->iLanguagesize; + ((mng_itxtp)pChunkto)->iTranslationsize = ((mng_itxtp)pChunkfrom)->iTranslationsize; + ((mng_itxtp)pChunkto)->iTextsize = ((mng_itxtp)pChunkfrom)->iTextsize; + + if (((mng_itxtp)pChunkto)->iKeywordsize) + { + MNG_ALLOC (pData, ((mng_itxtp)pChunkto)->zKeyword, ((mng_itxtp)pChunkto)->iKeywordsize); + MNG_COPY (((mng_itxtp)pChunkto)->zKeyword, ((mng_itxtp)pChunkfrom)->zKeyword, + ((mng_itxtp)pChunkto)->iKeywordsize); + } + + if (((mng_itxtp)pChunkto)->iTextsize) + { + MNG_ALLOC (pData, ((mng_itxtp)pChunkto)->zLanguage, ((mng_itxtp)pChunkto)->iLanguagesize); + MNG_COPY (((mng_itxtp)pChunkto)->zLanguage, ((mng_itxtp)pChunkfrom)->zLanguage, + ((mng_itxtp)pChunkto)->iLanguagesize); + } + + if (((mng_itxtp)pChunkto)->iTextsize) + { + MNG_ALLOC (pData, ((mng_itxtp)pChunkto)->zTranslation, ((mng_itxtp)pChunkto)->iTranslationsize); + MNG_COPY (((mng_itxtp)pChunkto)->zTranslation, ((mng_itxtp)pChunkfrom)->zTranslation, + ((mng_itxtp)pChunkto)->iTranslationsize); + } + + if (((mng_itxtp)pChunkto)->iTextsize) + { + MNG_ALLOC (pData, ((mng_itxtp)pChunkto)->zText, ((mng_itxtp)pChunkto)->iTextsize); + MNG_COPY (((mng_itxtp)pChunkto)->zText, ((mng_itxtp)pChunkfrom)->zText, + ((mng_itxtp)pChunkto)->iTextsize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_ITXT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_bKGD +ASSIGN_CHUNK_HDR (mng_assign_bkgd) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_BKGD, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_bKGD) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_bkgdp)pChunkto)->bEmpty = ((mng_bkgdp)pChunkfrom)->bEmpty; + ((mng_bkgdp)pChunkto)->iType = ((mng_bkgdp)pChunkfrom)->iType; + ((mng_bkgdp)pChunkto)->iIndex = ((mng_bkgdp)pChunkfrom)->iIndex; + ((mng_bkgdp)pChunkto)->iGray = ((mng_bkgdp)pChunkfrom)->iGray; + ((mng_bkgdp)pChunkto)->iRed = ((mng_bkgdp)pChunkfrom)->iRed; + ((mng_bkgdp)pChunkto)->iGreen = ((mng_bkgdp)pChunkfrom)->iGreen; + ((mng_bkgdp)pChunkto)->iBlue = ((mng_bkgdp)pChunkfrom)->iBlue; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_BKGD, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_pHYs +ASSIGN_CHUNK_HDR (mng_assign_phys) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_PHYS, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_pHYs) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_physp)pChunkto)->bEmpty = ((mng_physp)pChunkfrom)->bEmpty; + ((mng_physp)pChunkto)->iSizex = ((mng_physp)pChunkfrom)->iSizex; + ((mng_physp)pChunkto)->iSizey = ((mng_physp)pChunkfrom)->iSizey; + ((mng_physp)pChunkto)->iUnit = ((mng_physp)pChunkfrom)->iUnit; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_PHYS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_sBIT +ASSIGN_CHUNK_HDR (mng_assign_sbit) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_SBIT, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_sBIT) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_sbitp)pChunkto)->bEmpty = ((mng_sbitp)pChunkfrom)->bEmpty; + ((mng_sbitp)pChunkto)->iType = ((mng_sbitp)pChunkfrom)->iType; + ((mng_sbitp)pChunkto)->aBits [0] = ((mng_sbitp)pChunkfrom)->aBits [0]; + ((mng_sbitp)pChunkto)->aBits [1] = ((mng_sbitp)pChunkfrom)->aBits [1]; + ((mng_sbitp)pChunkto)->aBits [2] = ((mng_sbitp)pChunkfrom)->aBits [2]; + ((mng_sbitp)pChunkto)->aBits [3] = ((mng_sbitp)pChunkfrom)->aBits [3]; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_SBIT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sPLT +ASSIGN_CHUNK_HDR (mng_assign_splt) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_SPLT, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_sPLT) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_spltp)pChunkto)->bEmpty = ((mng_spltp)pChunkfrom)->bEmpty; + ((mng_spltp)pChunkto)->iNamesize = ((mng_spltp)pChunkfrom)->iNamesize; + ((mng_spltp)pChunkto)->iSampledepth = ((mng_spltp)pChunkfrom)->iSampledepth; + ((mng_spltp)pChunkto)->iEntrycount = ((mng_spltp)pChunkfrom)->iEntrycount; + ((mng_spltp)pChunkto)->pEntries = ((mng_spltp)pChunkfrom)->pEntries; + + if (((mng_spltp)pChunkto)->iNamesize) + { + MNG_ALLOC (pData, ((mng_spltp)pChunkto)->zName, ((mng_spltp)pChunkto)->iNamesize); + MNG_COPY (((mng_spltp)pChunkto)->zName, ((mng_spltp)pChunkfrom)->zName, + ((mng_spltp)pChunkto)->iNamesize); + } + + if (((mng_spltp)pChunkto)->iEntrycount) + { + mng_uint32 iLen = ((mng_spltp)pChunkto)->iEntrycount * + (((mng_spltp)pChunkto)->iSampledepth * 3 + sizeof (mng_uint16)); + + MNG_ALLOC (pData, ((mng_spltp)pChunkto)->pEntries, iLen); + MNG_COPY (((mng_spltp)pChunkto)->pEntries, ((mng_spltp)pChunkfrom)->pEntries, iLen); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_SPLT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_hIST +ASSIGN_CHUNK_HDR (mng_assign_hist) +{ + mng_uint32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_HIST, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_hIST) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_histp)pChunkto)->iEntrycount = ((mng_histp)pChunkfrom)->iEntrycount; + + for (iX = 0; iX < ((mng_histp)pChunkto)->iEntrycount; iX++) + ((mng_histp)pChunkto)->aEntries [iX] = ((mng_histp)pChunkfrom)->aEntries [iX]; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_HIST, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_tIME +ASSIGN_CHUNK_HDR (mng_assign_time) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_TIME, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_tIME) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_timep)pChunkto)->iYear = ((mng_timep)pChunkfrom)->iYear; + ((mng_timep)pChunkto)->iMonth = ((mng_timep)pChunkfrom)->iMonth; + ((mng_timep)pChunkto)->iDay = ((mng_timep)pChunkfrom)->iDay; + ((mng_timep)pChunkto)->iHour = ((mng_timep)pChunkfrom)->iHour; + ((mng_timep)pChunkto)->iMinute = ((mng_timep)pChunkfrom)->iMinute; + ((mng_timep)pChunkto)->iSecond = ((mng_timep)pChunkfrom)->iSecond; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_TIME, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +ASSIGN_CHUNK_HDR (mng_assign_mhdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_MHDR, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_mhdrp)pChunkto)->iWidth = ((mng_mhdrp)pChunkfrom)->iWidth; + ((mng_mhdrp)pChunkto)->iHeight = ((mng_mhdrp)pChunkfrom)->iHeight; + ((mng_mhdrp)pChunkto)->iTicks = ((mng_mhdrp)pChunkfrom)->iTicks; + ((mng_mhdrp)pChunkto)->iLayercount = ((mng_mhdrp)pChunkfrom)->iLayercount; + ((mng_mhdrp)pChunkto)->iFramecount = ((mng_mhdrp)pChunkfrom)->iFramecount; + ((mng_mhdrp)pChunkto)->iPlaytime = ((mng_mhdrp)pChunkfrom)->iPlaytime; + ((mng_mhdrp)pChunkto)->iSimplicity = ((mng_mhdrp)pChunkfrom)->iSimplicity; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_MHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +ASSIGN_CHUNK_HDR (mng_assign_mend) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_MEND, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_MEND) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_MEND, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_LOOP +ASSIGN_CHUNK_HDR (mng_assign_loop) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_LOOP, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_LOOP) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_loopp)pChunkto)->iLevel = ((mng_loopp)pChunkfrom)->iLevel; + ((mng_loopp)pChunkto)->iRepeat = ((mng_loopp)pChunkfrom)->iRepeat; + ((mng_loopp)pChunkto)->iTermination = ((mng_loopp)pChunkfrom)->iTermination; + ((mng_loopp)pChunkto)->iItermin = ((mng_loopp)pChunkfrom)->iItermin; + ((mng_loopp)pChunkto)->iItermax = ((mng_loopp)pChunkfrom)->iItermax; + ((mng_loopp)pChunkto)->iCount = ((mng_loopp)pChunkfrom)->iCount; + +#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED + if (((mng_loopp)pChunkto)->iCount) + { + mng_uint32 iLen = ((mng_loopp)pChunkto)->iCount * sizeof (mng_uint32); + MNG_ALLOC (pData, ((mng_loopp)pChunkto)->pSignals, iLen); + MNG_COPY (((mng_loopp)pChunkto)->pSignals, ((mng_loopp)pChunkfrom)->pSignals, iLen); + } +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_LOOP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +ASSIGN_CHUNK_HDR (mng_assign_endl) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_ENDL, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_ENDL) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_endlp)pChunkto)->iLevel = ((mng_endlp)pChunkfrom)->iLevel; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_ENDL, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_DEFI +ASSIGN_CHUNK_HDR (mng_assign_defi) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_DEFI, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_DEFI) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_defip)pChunkto)->iObjectid = ((mng_defip)pChunkfrom)->iObjectid; + ((mng_defip)pChunkto)->bHasdonotshow = ((mng_defip)pChunkfrom)->bHasdonotshow; + ((mng_defip)pChunkto)->iDonotshow = ((mng_defip)pChunkfrom)->iDonotshow; + ((mng_defip)pChunkto)->bHasconcrete = ((mng_defip)pChunkfrom)->bHasconcrete; + ((mng_defip)pChunkto)->iConcrete = ((mng_defip)pChunkfrom)->iConcrete; + ((mng_defip)pChunkto)->bHasloca = ((mng_defip)pChunkfrom)->bHasloca; + ((mng_defip)pChunkto)->iXlocation = ((mng_defip)pChunkfrom)->iXlocation; + ((mng_defip)pChunkto)->iYlocation = ((mng_defip)pChunkfrom)->iYlocation; + ((mng_defip)pChunkto)->bHasclip = ((mng_defip)pChunkfrom)->bHasclip; + ((mng_defip)pChunkto)->iLeftcb = ((mng_defip)pChunkfrom)->iLeftcb; + ((mng_defip)pChunkto)->iRightcb = ((mng_defip)pChunkfrom)->iRightcb; + ((mng_defip)pChunkto)->iTopcb = ((mng_defip)pChunkfrom)->iTopcb; + ((mng_defip)pChunkto)->iBottomcb = ((mng_defip)pChunkfrom)->iBottomcb; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_DEFI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_BASI +ASSIGN_CHUNK_HDR (mng_assign_basi) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_BASI, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_BASI) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_basip)pChunkto)->iWidth = ((mng_basip)pChunkfrom)->iWidth; + ((mng_basip)pChunkto)->iHeight = ((mng_basip)pChunkfrom)->iHeight; + ((mng_basip)pChunkto)->iBitdepth = ((mng_basip)pChunkfrom)->iBitdepth; + ((mng_basip)pChunkto)->iColortype = ((mng_basip)pChunkfrom)->iColortype; + ((mng_basip)pChunkto)->iCompression = ((mng_basip)pChunkfrom)->iCompression; + ((mng_basip)pChunkto)->iFilter = ((mng_basip)pChunkfrom)->iFilter; + ((mng_basip)pChunkto)->iInterlace = ((mng_basip)pChunkfrom)->iInterlace; + ((mng_basip)pChunkto)->iRed = ((mng_basip)pChunkfrom)->iRed; + ((mng_basip)pChunkto)->iGreen = ((mng_basip)pChunkfrom)->iGreen; + ((mng_basip)pChunkto)->iBlue = ((mng_basip)pChunkfrom)->iBlue; + ((mng_basip)pChunkto)->iAlpha = ((mng_basip)pChunkfrom)->iAlpha; + ((mng_basip)pChunkto)->iViewable = ((mng_basip)pChunkfrom)->iViewable; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_BASI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_CLON +ASSIGN_CHUNK_HDR (mng_assign_clon) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_CLON, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_CLON) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_clonp)pChunkto)->iSourceid = ((mng_clonp)pChunkfrom)->iSourceid; + ((mng_clonp)pChunkto)->iCloneid = ((mng_clonp)pChunkfrom)->iCloneid; + ((mng_clonp)pChunkto)->iClonetype = ((mng_clonp)pChunkfrom)->iClonetype; +#ifdef MNG_OPTIMIZE_CHUNKREADER + ((mng_clonp)pChunkto)->bHasdonotshow = ((mng_clonp)pChunkfrom)->bHasdonotshow; +#endif + ((mng_clonp)pChunkto)->iDonotshow = ((mng_clonp)pChunkfrom)->iDonotshow; + ((mng_clonp)pChunkto)->iConcrete = ((mng_clonp)pChunkfrom)->iConcrete; + ((mng_clonp)pChunkto)->bHasloca = ((mng_clonp)pChunkfrom)->bHasloca; + ((mng_clonp)pChunkto)->iLocationtype = ((mng_clonp)pChunkfrom)->iLocationtype; + ((mng_clonp)pChunkto)->iLocationx = ((mng_clonp)pChunkfrom)->iLocationx; + ((mng_clonp)pChunkto)->iLocationy = ((mng_clonp)pChunkfrom)->iLocationy; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_CLON, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +ASSIGN_CHUNK_HDR (mng_assign_past) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_PAST, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_PAST) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_pastp)pChunkto)->iDestid = ((mng_pastp)pChunkfrom)->iDestid; + ((mng_pastp)pChunkto)->iTargettype = ((mng_pastp)pChunkfrom)->iTargettype; + ((mng_pastp)pChunkto)->iTargetx = ((mng_pastp)pChunkfrom)->iTargetx; + ((mng_pastp)pChunkto)->iTargety = ((mng_pastp)pChunkfrom)->iTargety; + ((mng_pastp)pChunkto)->iCount = ((mng_pastp)pChunkfrom)->iCount; + + if (((mng_pastp)pChunkto)->iCount) + { + mng_uint32 iLen = ((mng_pastp)pChunkto)->iCount * sizeof (mng_past_source); + + MNG_ALLOC (pData, ((mng_pastp)pChunkto)->pSources, iLen); + MNG_COPY (((mng_pastp)pChunkto)->pSources, ((mng_pastp)pChunkfrom)->pSources, iLen); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_PAST, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DISC +ASSIGN_CHUNK_HDR (mng_assign_disc) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_DISC, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_DISC) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_discp)pChunkto)->iCount = ((mng_discp)pChunkfrom)->iCount; + + if (((mng_discp)pChunkto)->iCount) + { + mng_uint32 iLen = ((mng_discp)pChunkto)->iCount * sizeof (mng_uint16); + + MNG_ALLOC (pData, ((mng_discp)pChunkto)->pObjectids, iLen); + MNG_COPY (((mng_discp)pChunkto)->pObjectids, ((mng_discp)pChunkfrom)->pObjectids, iLen); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_DISC, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_BACK +ASSIGN_CHUNK_HDR (mng_assign_back) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_BACK, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_BACK) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_backp)pChunkto)->iRed = ((mng_backp)pChunkfrom)->iRed; + ((mng_backp)pChunkto)->iGreen = ((mng_backp)pChunkfrom)->iGreen; + ((mng_backp)pChunkto)->iBlue = ((mng_backp)pChunkfrom)->iBlue; + ((mng_backp)pChunkto)->iMandatory = ((mng_backp)pChunkfrom)->iMandatory; + ((mng_backp)pChunkto)->iImageid = ((mng_backp)pChunkfrom)->iImageid; + ((mng_backp)pChunkto)->iTile = ((mng_backp)pChunkfrom)->iTile; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_BACK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_FRAM +ASSIGN_CHUNK_HDR (mng_assign_fram) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_FRAM, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_FRAM) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_framp)pChunkto)->bEmpty = ((mng_framp)pChunkfrom)->bEmpty; + ((mng_framp)pChunkto)->iMode = ((mng_framp)pChunkfrom)->iMode; + ((mng_framp)pChunkto)->iNamesize = ((mng_framp)pChunkfrom)->iNamesize; + ((mng_framp)pChunkto)->iChangedelay = ((mng_framp)pChunkfrom)->iChangedelay; + ((mng_framp)pChunkto)->iChangetimeout = ((mng_framp)pChunkfrom)->iChangetimeout; + ((mng_framp)pChunkto)->iChangeclipping = ((mng_framp)pChunkfrom)->iChangeclipping; + ((mng_framp)pChunkto)->iChangesyncid = ((mng_framp)pChunkfrom)->iChangesyncid; + ((mng_framp)pChunkto)->iDelay = ((mng_framp)pChunkfrom)->iDelay; + ((mng_framp)pChunkto)->iTimeout = ((mng_framp)pChunkfrom)->iTimeout; + ((mng_framp)pChunkto)->iBoundarytype = ((mng_framp)pChunkfrom)->iBoundarytype; + ((mng_framp)pChunkto)->iBoundaryl = ((mng_framp)pChunkfrom)->iBoundaryl; + ((mng_framp)pChunkto)->iBoundaryr = ((mng_framp)pChunkfrom)->iBoundaryr; + ((mng_framp)pChunkto)->iBoundaryt = ((mng_framp)pChunkfrom)->iBoundaryt; + ((mng_framp)pChunkto)->iBoundaryb = ((mng_framp)pChunkfrom)->iBoundaryb; + ((mng_framp)pChunkto)->iCount = ((mng_framp)pChunkfrom)->iCount; + + if (((mng_framp)pChunkto)->iNamesize) + { + MNG_ALLOC (pData, ((mng_framp)pChunkto)->zName, ((mng_framp)pChunkto)->iNamesize); + MNG_COPY (((mng_framp)pChunkto)->zName, ((mng_framp)pChunkfrom)->zName, + ((mng_framp)pChunkto)->iNamesize); + } + + if (((mng_framp)pChunkto)->iCount) + { + mng_uint32 iLen = ((mng_framp)pChunkto)->iCount * sizeof (mng_uint32); + + MNG_ALLOC (pData, ((mng_framp)pChunkto)->pSyncids, iLen); + MNG_COPY (((mng_framp)pChunkto)->pSyncids, ((mng_framp)pChunkfrom)->pSyncids, iLen); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_FRAM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_MOVE +ASSIGN_CHUNK_HDR (mng_assign_move) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_MOVE, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_MOVE) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_movep)pChunkto)->iFirstid = ((mng_movep)pChunkfrom)->iFirstid; + ((mng_movep)pChunkto)->iLastid = ((mng_movep)pChunkfrom)->iLastid; + ((mng_movep)pChunkto)->iMovetype = ((mng_movep)pChunkfrom)->iMovetype; + ((mng_movep)pChunkto)->iMovex = ((mng_movep)pChunkfrom)->iMovex; + ((mng_movep)pChunkto)->iMovey = ((mng_movep)pChunkfrom)->iMovey; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_MOVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_CLIP +ASSIGN_CHUNK_HDR (mng_assign_clip) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_CLIP, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_CLIP) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_clipp)pChunkto)->iFirstid = ((mng_clipp)pChunkfrom)->iFirstid; + ((mng_clipp)pChunkto)->iLastid = ((mng_clipp)pChunkfrom)->iLastid; + ((mng_clipp)pChunkto)->iCliptype = ((mng_clipp)pChunkfrom)->iCliptype; + ((mng_clipp)pChunkto)->iClipl = ((mng_clipp)pChunkfrom)->iClipl; + ((mng_clipp)pChunkto)->iClipr = ((mng_clipp)pChunkfrom)->iClipr; + ((mng_clipp)pChunkto)->iClipt = ((mng_clipp)pChunkfrom)->iClipt; + ((mng_clipp)pChunkto)->iClipb = ((mng_clipp)pChunkfrom)->iClipb; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_CLIP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_SHOW +ASSIGN_CHUNK_HDR (mng_assign_show) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_SHOW, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_SHOW) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_showp)pChunkto)->bEmpty = ((mng_showp)pChunkfrom)->bEmpty; + ((mng_showp)pChunkto)->iFirstid = ((mng_showp)pChunkfrom)->iFirstid; + ((mng_showp)pChunkto)->iLastid = ((mng_showp)pChunkfrom)->iLastid; + ((mng_showp)pChunkto)->iMode = ((mng_showp)pChunkfrom)->iMode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_SHOW, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_TERM +ASSIGN_CHUNK_HDR (mng_assign_term) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_TERM, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_TERM) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_termp)pChunkto)->iTermaction = ((mng_termp)pChunkfrom)->iTermaction; + ((mng_termp)pChunkto)->iIteraction = ((mng_termp)pChunkfrom)->iIteraction; + ((mng_termp)pChunkto)->iDelay = ((mng_termp)pChunkfrom)->iDelay; + ((mng_termp)pChunkto)->iItermax = ((mng_termp)pChunkfrom)->iItermax; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_TERM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SAVE +ASSIGN_CHUNK_HDR (mng_assign_save) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_SAVE, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_SAVE) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_savep)pChunkto)->bEmpty = ((mng_savep)pChunkfrom)->bEmpty; + ((mng_savep)pChunkto)->iOffsettype = ((mng_savep)pChunkfrom)->iOffsettype; + ((mng_savep)pChunkto)->iCount = ((mng_savep)pChunkfrom)->iCount; + + if (((mng_savep)pChunkto)->iCount) + { + mng_uint32 iX; + mng_save_entryp pEntry; + mng_uint32 iLen = ((mng_savep)pChunkto)->iCount * sizeof (mng_save_entry); + + MNG_ALLOC (pData, ((mng_savep)pChunkto)->pEntries, iLen); + MNG_COPY (((mng_savep)pChunkto)->pEntries, ((mng_savep)pChunkfrom)->pEntries, iLen); + + pEntry = ((mng_savep)pChunkto)->pEntries; + + for (iX = 0; iX < ((mng_savep)pChunkto)->iCount; iX++) + { + if (pEntry->iNamesize) + { + mng_pchar pTemp = pEntry->zName; + + MNG_ALLOC (pData, pEntry->zName, pEntry->iNamesize); + MNG_COPY (pEntry->zName, pTemp, pEntry->iNamesize); + } + else + { + pEntry->zName = MNG_NULL; + } + + pEntry++; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_SAVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SEEK +ASSIGN_CHUNK_HDR (mng_assign_seek) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_SEEK, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_SEEK) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_seekp)pChunkto)->iNamesize = ((mng_seekp)pChunkfrom)->iNamesize; + + if (((mng_seekp)pChunkto)->iNamesize) + { + MNG_ALLOC (pData, ((mng_seekp)pChunkto)->zName, ((mng_seekp)pChunkto)->iNamesize); + MNG_COPY (((mng_seekp)pChunkto)->zName, ((mng_seekp)pChunkfrom)->zName, + ((mng_seekp)pChunkto)->iNamesize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_SEEK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_eXPI +ASSIGN_CHUNK_HDR (mng_assign_expi) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_EXPI, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_eXPI) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_expip)pChunkto)->iSnapshotid = ((mng_expip)pChunkfrom)->iSnapshotid; + ((mng_expip)pChunkto)->iNamesize = ((mng_expip)pChunkfrom)->iNamesize; + + if (((mng_expip)pChunkto)->iNamesize) + { + MNG_ALLOC (pData, ((mng_expip)pChunkto)->zName, ((mng_expip)pChunkto)->iNamesize); + MNG_COPY (((mng_expip)pChunkto)->zName, ((mng_expip)pChunkfrom)->zName, + ((mng_expip)pChunkto)->iNamesize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_EXPI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_fPRI +ASSIGN_CHUNK_HDR (mng_assign_fpri) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_FPRI, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_fPRI) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_fprip)pChunkto)->iDeltatype = ((mng_fprip)pChunkfrom)->iDeltatype; + ((mng_fprip)pChunkto)->iPriority = ((mng_fprip)pChunkfrom)->iPriority; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_FPRI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_nEED +ASSIGN_CHUNK_HDR (mng_assign_need) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_NEED, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_nEED) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_needp)pChunkto)->iKeywordssize = ((mng_needp)pChunkfrom)->iKeywordssize; + + if (((mng_needp)pChunkto)->iKeywordssize) + { + MNG_ALLOC (pData, ((mng_needp)pChunkto)->zKeywords, ((mng_needp)pChunkto)->iKeywordssize); + MNG_COPY (((mng_needp)pChunkto)->zKeywords, ((mng_needp)pChunkfrom)->zKeywords, + ((mng_needp)pChunkto)->iKeywordssize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_NEED, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_pHYg +ASSIGN_CHUNK_HDR (mng_assign_phyg) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_PHYG, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_pHYg) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_phygp)pChunkto)->bEmpty = ((mng_phygp)pChunkfrom)->bEmpty; + ((mng_phygp)pChunkto)->iSizex = ((mng_phygp)pChunkfrom)->iSizex; + ((mng_phygp)pChunkto)->iSizey = ((mng_phygp)pChunkfrom)->iSizey; + ((mng_phygp)pChunkto)->iUnit = ((mng_phygp)pChunkfrom)->iUnit; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_PHYG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifdef MNG_INCLUDE_JNG +ASSIGN_CHUNK_HDR (mng_assign_jhdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_JHDR, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_JHDR) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_jhdrp)pChunkto)->iWidth = ((mng_jhdrp)pChunkfrom)->iWidth; + ((mng_jhdrp)pChunkto)->iHeight = ((mng_jhdrp)pChunkfrom)->iHeight; + ((mng_jhdrp)pChunkto)->iColortype = ((mng_jhdrp)pChunkfrom)->iColortype; + ((mng_jhdrp)pChunkto)->iImagesampledepth = ((mng_jhdrp)pChunkfrom)->iImagesampledepth; + ((mng_jhdrp)pChunkto)->iImagecompression = ((mng_jhdrp)pChunkfrom)->iImagecompression; + ((mng_jhdrp)pChunkto)->iImageinterlace = ((mng_jhdrp)pChunkfrom)->iImageinterlace; + ((mng_jhdrp)pChunkto)->iAlphasampledepth = ((mng_jhdrp)pChunkfrom)->iAlphasampledepth; + ((mng_jhdrp)pChunkto)->iAlphacompression = ((mng_jhdrp)pChunkfrom)->iAlphacompression; + ((mng_jhdrp)pChunkto)->iAlphafilter = ((mng_jhdrp)pChunkfrom)->iAlphafilter; + ((mng_jhdrp)pChunkto)->iAlphainterlace = ((mng_jhdrp)pChunkfrom)->iAlphainterlace; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_JHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +ASSIGN_CHUNK_HDR (mng_assign_jdaa) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_JDAA, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_JDAA) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_jdaap)pChunkto)->bEmpty = ((mng_jdaap)pChunkfrom)->bEmpty; + ((mng_jdaap)pChunkto)->iDatasize = ((mng_jdaap)pChunkfrom)->iDatasize; + + if (((mng_jdaap)pChunkto)->iDatasize) + { + MNG_ALLOC (pData, ((mng_jdaap)pChunkto)->pData, ((mng_jdaap)pChunkto)->iDatasize); + MNG_COPY (((mng_jdaap)pChunkto)->pData, ((mng_jdaap)pChunkfrom)->pData, + ((mng_jdaap)pChunkto)->iDatasize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_JDAA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +ASSIGN_CHUNK_HDR (mng_assign_jdat) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_JDAT, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_JDAT) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_jdatp)pChunkto)->bEmpty = ((mng_jdatp)pChunkfrom)->bEmpty; + ((mng_jdatp)pChunkto)->iDatasize = ((mng_jdatp)pChunkfrom)->iDatasize; + + if (((mng_jdatp)pChunkto)->iDatasize) + { + MNG_ALLOC (pData, ((mng_jdatp)pChunkto)->pData, ((mng_jdatp)pChunkto)->iDatasize); + MNG_COPY (((mng_jdatp)pChunkto)->pData, ((mng_jdatp)pChunkfrom)->pData, + ((mng_jdatp)pChunkto)->iDatasize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_JDAT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifdef MNG_INCLUDE_JNG +ASSIGN_CHUNK_HDR (mng_assign_jsep) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_JSEP, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_JSEP) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_JSEP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_NO_DELTA_PNG +ASSIGN_CHUNK_HDR (mng_assign_dhdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_DHDR, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_DHDR) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_dhdrp)pChunkto)->iObjectid = ((mng_dhdrp)pChunkfrom)->iObjectid; + ((mng_dhdrp)pChunkto)->iImagetype = ((mng_dhdrp)pChunkfrom)->iImagetype; + ((mng_dhdrp)pChunkto)->iDeltatype = ((mng_dhdrp)pChunkfrom)->iDeltatype; + ((mng_dhdrp)pChunkto)->iBlockwidth = ((mng_dhdrp)pChunkfrom)->iBlockwidth; + ((mng_dhdrp)pChunkto)->iBlockheight = ((mng_dhdrp)pChunkfrom)->iBlockheight; + ((mng_dhdrp)pChunkto)->iBlockx = ((mng_dhdrp)pChunkfrom)->iBlockx; + ((mng_dhdrp)pChunkto)->iBlocky = ((mng_dhdrp)pChunkfrom)->iBlocky; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_DHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_NO_DELTA_PNG +ASSIGN_CHUNK_HDR (mng_assign_prom) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_PROM, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_PROM) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_promp)pChunkto)->iColortype = ((mng_promp)pChunkfrom)->iColortype; + ((mng_promp)pChunkto)->iSampledepth = ((mng_promp)pChunkfrom)->iSampledepth; + ((mng_promp)pChunkto)->iFilltype = ((mng_promp)pChunkfrom)->iFilltype; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_PROM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_NO_DELTA_PNG +ASSIGN_CHUNK_HDR (mng_assign_ipng) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_IPNG, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_IPNG) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_IPNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_NO_DELTA_PNG +ASSIGN_CHUNK_HDR (mng_assign_pplt) +{ + mng_uint32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_PPLT, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_PPLT) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_ppltp)pChunkto)->iDeltatype = ((mng_ppltp)pChunkfrom)->iDeltatype; + ((mng_ppltp)pChunkto)->iCount = ((mng_ppltp)pChunkfrom)->iCount; + + for (iX = 0; iX < ((mng_ppltp)pChunkto)->iCount; iX++) + ((mng_ppltp)pChunkto)->aEntries [iX] = ((mng_ppltp)pChunkfrom)->aEntries [iX]; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_PPLT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG +ASSIGN_CHUNK_HDR (mng_assign_ijng) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_IJNG, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_IJNG) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_IJNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +ASSIGN_CHUNK_HDR (mng_assign_drop) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_DROP, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_DROP) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_dropp)pChunkto)->iCount = ((mng_dropp)pChunkfrom)->iCount; + + if (((mng_dropp)pChunkto)->iCount) + { + mng_uint32 iLen = ((mng_dropp)pChunkto)->iCount * sizeof (mng_uint32); + + MNG_ALLOC (pData, ((mng_dropp)pChunkto)->pChunknames, iLen); + MNG_COPY (((mng_dropp)pChunkto)->pChunknames, ((mng_dropp)pChunkfrom)->pChunknames, iLen); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_DROP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DBYK +ASSIGN_CHUNK_HDR (mng_assign_dbyk) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_DBYK, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_DBYK) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_dbykp)pChunkto)->iChunkname = ((mng_dbykp)pChunkfrom)->iChunkname; + ((mng_dbykp)pChunkto)->iPolarity = ((mng_dbykp)pChunkfrom)->iPolarity; + ((mng_dbykp)pChunkto)->iKeywordssize = ((mng_dbykp)pChunkfrom)->iKeywordssize; + + if (((mng_dbykp)pChunkto)->iKeywordssize) + { + MNG_ALLOC (pData, ((mng_dbykp)pChunkto)->zKeywords, ((mng_dbykp)pChunkto)->iKeywordssize); + MNG_COPY (((mng_dbykp)pChunkto)->zKeywords, ((mng_dbykp)pChunkfrom)->zKeywords, + ((mng_dbykp)pChunkto)->iKeywordssize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_DBYK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR +ASSIGN_CHUNK_HDR (mng_assign_ordr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_ORDR, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_ORDR) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_ordrp)pChunkto)->iCount = ((mng_ordrp)pChunkfrom)->iCount; + + if (((mng_ordrp)pChunkto)->iCount) + { + mng_uint32 iLen = ((mng_ordrp)pChunkto)->iCount * sizeof (mng_ordr_entry); + + MNG_ALLOC (pData, ((mng_ordrp)pChunkto)->pEntries, iLen); + MNG_COPY (((mng_ordrp)pChunkto)->pEntries, ((mng_ordrp)pChunkfrom)->pEntries, iLen); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_ORDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKASSIGN +#ifndef MNG_SKIPCHUNK_MAGN +ASSIGN_CHUNK_HDR (mng_assign_magn) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_MAGN, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_MAGN) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_magnp)pChunkto)->iFirstid = ((mng_magnp)pChunkfrom)->iFirstid; + ((mng_magnp)pChunkto)->iLastid = ((mng_magnp)pChunkfrom)->iLastid; + ((mng_magnp)pChunkto)->iMethodX = ((mng_magnp)pChunkfrom)->iMethodX; + ((mng_magnp)pChunkto)->iMX = ((mng_magnp)pChunkfrom)->iMX; + ((mng_magnp)pChunkto)->iMY = ((mng_magnp)pChunkfrom)->iMY; + ((mng_magnp)pChunkto)->iML = ((mng_magnp)pChunkfrom)->iML; + ((mng_magnp)pChunkto)->iMR = ((mng_magnp)pChunkfrom)->iMR; + ((mng_magnp)pChunkto)->iMT = ((mng_magnp)pChunkfrom)->iMT; + ((mng_magnp)pChunkto)->iMB = ((mng_magnp)pChunkfrom)->iMB; + ((mng_magnp)pChunkto)->iMethodY = ((mng_magnp)pChunkfrom)->iMethodY; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_MAGN, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_MPNG_PROPOSAL +ASSIGN_CHUNK_HDR (mng_assign_mpng) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_MPNG, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_mpNG) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_mpngp)pChunkto)->iFramewidth = ((mng_mpngp)pChunkfrom)->iFramewidth; + ((mng_mpngp)pChunkto)->iFrameheight = ((mng_mpngp)pChunkfrom)->iFrameheight; + ((mng_mpngp)pChunkto)->iNumplays = ((mng_mpngp)pChunkfrom)->iNumplays; + ((mng_mpngp)pChunkto)->iTickspersec = ((mng_mpngp)pChunkfrom)->iTickspersec; + ((mng_mpngp)pChunkto)->iCompressionmethod = ((mng_mpngp)pChunkfrom)->iCompressionmethod; + ((mng_mpngp)pChunkto)->iFramessize = ((mng_mpngp)pChunkfrom)->iFramessize; + + if (((mng_mpngp)pChunkto)->iFramessize) + { + MNG_ALLOC (pData, ((mng_mpngp)pChunkto)->pFrames, ((mng_mpngp)pChunkto)->iFramessize); + MNG_COPY (((mng_mpngp)pChunkto)->pFrames, ((mng_mpngp)pChunkfrom)->pFrames, + ((mng_mpngp)pChunkto)->iFramessize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_MPNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ANG_PROPOSAL +ASSIGN_CHUNK_HDR (mng_assign_ahdr) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_AHDR, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_ahDR) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_ahdrp)pChunkto)->iNumframes = ((mng_ahdrp)pChunkfrom)->iNumframes; + ((mng_ahdrp)pChunkto)->iTickspersec = ((mng_ahdrp)pChunkfrom)->iTickspersec; + ((mng_ahdrp)pChunkto)->iNumplays = ((mng_ahdrp)pChunkfrom)->iNumplays; + ((mng_ahdrp)pChunkto)->iTilewidth = ((mng_ahdrp)pChunkfrom)->iTilewidth; + ((mng_ahdrp)pChunkto)->iTileheight = ((mng_ahdrp)pChunkfrom)->iTileheight; + ((mng_ahdrp)pChunkto)->iInterlace = ((mng_ahdrp)pChunkfrom)->iInterlace; + ((mng_ahdrp)pChunkto)->iStillused = ((mng_ahdrp)pChunkfrom)->iStillused; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_AHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ANG_PROPOSAL +ASSIGN_CHUNK_HDR (mng_assign_adat) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_ADAT, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_adAT) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_adatp)pChunkto)->iTilessize = ((mng_adatp)pChunkfrom)->iTilessize; + + if (((mng_adatp)pChunkto)->iTilessize) + { + MNG_ALLOC (pData, ((mng_adatp)pChunkto)->pTiles, ((mng_adatp)pChunkto)->iTilessize); + MNG_COPY (((mng_adatp)pChunkto)->pTiles, ((mng_adatp)pChunkfrom)->pTiles, + ((mng_adatp)pChunkto)->iTilessize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_ADAT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_evNT +ASSIGN_CHUNK_HDR (mng_assign_evnt) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_EVNT, MNG_LC_START); +#endif + + if (((mng_chunk_headerp)pChunkfrom)->iChunkname != MNG_UINT_evNT) + MNG_ERROR (pData, MNG_WRONGCHUNK); /* ouch */ + + ((mng_evntp)pChunkto)->iCount = ((mng_evntp)pChunkfrom)->iCount; + + if (((mng_evntp)pChunkto)->iCount) + { + mng_uint32 iX; + mng_evnt_entryp pEntry; + mng_uint32 iLen = ((mng_evntp)pChunkto)->iCount * sizeof (mng_evnt_entry); + + MNG_ALLOC (pData, ((mng_evntp)pChunkto)->pEntries, iLen); + MNG_COPY (((mng_evntp)pChunkto)->pEntries, ((mng_evntp)pChunkfrom)->pEntries, iLen); + + pEntry = ((mng_evntp)pChunkto)->pEntries; + + for (iX = 0; iX < ((mng_evntp)pChunkto)->iCount; iX++) + { + if (pEntry->iSegmentnamesize) + { + mng_pchar pTemp = pEntry->zSegmentname; + + MNG_ALLOC (pData, pEntry->zSegmentname, pEntry->iSegmentnamesize+1); + MNG_COPY (pEntry->zSegmentname, pTemp, pEntry->iSegmentnamesize); + } + else + { + pEntry->zSegmentname = MNG_NULL; + } + + pEntry++; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_EVNT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +ASSIGN_CHUNK_HDR (mng_assign_unknown) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_UNKNOWN, MNG_LC_START); +#endif + + ((mng_unknown_chunkp)pChunkto)->iDatasize = ((mng_unknown_chunkp)pChunkfrom)->iDatasize; + + if (((mng_unknown_chunkp)pChunkto)->iDatasize) + { + MNG_ALLOC (pData, ((mng_unknown_chunkp)pChunkto)->pData, ((mng_unknown_chunkp)pChunkto)->iDatasize); + MNG_COPY (((mng_unknown_chunkp)pChunkto)->pData, ((mng_unknown_chunkp)pChunkfrom)->pData, + ((mng_unknown_chunkp)pChunkto)->iDatasize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ASSIGN_UNKNOWN, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_WRITE_PROCS */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + diff --git a/Source/LibMNG/libmng_chunk_xs.c b/Source/LibMNG/libmng_chunk_xs.c index 1c4ec2e..1311409 100644 --- a/Source/LibMNG/libmng_chunk_xs.c +++ b/Source/LibMNG/libmng_chunk_xs.c @@ -1,7016 +1,7016 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_chunk_xs.c copyright (c) 2000-2007 G.Juyn * */ -/* * version : 1.0.10 * */ -/* * * */ -/* * purpose : chunk access functions (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the chunk access functions * */ -/* * * */ -/* * changes : 0.5.1 - 05/06/2000 - G.Juyn * */ -/* * - changed and filled iterate-chunk function * */ -/* * 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - fixed calling convention * */ -/* * - added getchunk functions * */ -/* * - added putchunk functions * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/11/2000 - G.Juyn * */ -/* * - added empty-chunk put-routines * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - changed trace to macro for callback error-reporting * */ -/* * 0.5.1 - 05/15/2000 - G.Juyn * */ -/* * - added getimgdata & putimgdata functions * */ -/* * * */ -/* * 0.5.2 - 05/19/2000 - G.Juyn * */ -/* * - B004 - fixed problem with MNG_SUPPORT_WRITE not defined * */ -/* * also for MNG_SUPPORT_WRITE without MNG_INCLUDE_JNG * */ -/* * - Cleaned up some code regarding mixed support * */ -/* * * */ -/* * 0.9.1 - 07/19/2000 - G.Juyn * */ -/* * - fixed creation-code * */ -/* * * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * - added function to set simplicity field * */ -/* * - fixed putchunk_unknown() function * */ -/* * * */ -/* * 0.9.3 - 08/07/2000 - G.Juyn * */ -/* * - B111300 - fixup for improved portability * */ -/* * 0.9.3 - 08/26/2000 - G.Juyn * */ -/* * - added MAGN chunk * */ -/* * 0.9.3 - 10/20/2000 - G.Juyn * */ -/* * - fixed putchunk_plte() to set bEmpty parameter * */ -/* * * */ -/* * 0.9.5 - 01/25/2001 - G.Juyn * */ -/* * - fixed some small compiler warnings (thanks Nikki) * */ -/* * * */ -/* * 1.0.5 - 09/07/2002 - G.Juyn * */ -/* * - B578940 - unimplemented functions return errorcode * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * - added HLAPI function to copy chunks * */ -/* * 1.0.5 - 09/14/2002 - G.Juyn * */ -/* * - added event handling for dynamic MNG * */ -/* * 1.0.5 - 10/07/2002 - G.Juyn * */ -/* * - added check for TERM placement during create/write * */ -/* * 1.0.5 - 11/28/2002 - G.Juyn * */ -/* * - fixed definition of iMethodX/Y for MAGN chunk * */ -/* * * */ -/* * 1.0.6 - 05/25/2003 - G.R-P * */ -/* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */ -/* * 1.0.6 - 07/07/2003 - G.R-P * */ -/* * - added MNG_NO_DELTA_PNG reduction and more SKIPCHUNK * */ -/* * optimizations * */ -/* * 1.0.6 - 07/29/2003 - G.R-P * */ -/* * - added conditionals around PAST chunk support * */ -/* * 1.0.6 - 08/17/2003 - G.R-P * */ -/* * - added conditionals around non-VLC chunk support * */ -/* * * */ -/* * 1.0.8 - 04/01/2004 - G.Juyn * */ -/* * - added missing get-/put-chunk-jdaa * */ -/* * 1.0.8 - 08/02/2004 - G.Juyn * */ -/* * - added conditional to allow easier writing of large MNG's * */ -/* * * */ -/* * 1.0.9 - 09/17/2004 - G.R-P * */ -/* * - added two more conditionals * */ -/* * 1.0.9 - 09/25/2004 - G.Juyn * */ -/* * - replaced MNG_TWEAK_LARGE_FILES with permanent solution * */ -/* * 1.0.9 - 17/14/2004 - G.Juyn * */ -/* * - fixed PPLT getchunk/putchunk routines * */ -/* * 1.0.9 - 12/05/2004 - G.Juyn * */ -/* * - added conditional MNG_OPTIMIZE_CHUNKINITFREE * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * * */ -/* * 1.0.10 - 04/08/2007 - G.Juyn * */ -/* * - added support for mPNG proposal * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_memory.h" -#include "libmng_chunks.h" -#ifdef MNG_OPTIMIZE_CHUNKREADER -#include "libmng_chunk_descr.h" -#endif -#include "libmng_chunk_prc.h" -#include "libmng_chunk_io.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ - -#ifdef MNG_ACCESS_CHUNKS - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_iterate_chunks (mng_handle hHandle, - mng_uint32 iChunkseq, - mng_iteratechunk fProc) -{ - mng_uint32 iSeq; - mng_chunkid iChunkname; - mng_datap pData; - mng_chunkp pChunk; - mng_bool bCont; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_ITERATE_CHUNKS, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - - iSeq = 0; - bCont = MNG_TRUE; - pChunk = pData->pFirstchunk; /* get the first chunk */ - /* as long as there are some more */ - while ((pChunk) && (bCont)) /* and the app didn't signal a stop */ - { - if (iSeq >= iChunkseq) /* reached the first target ? */ - { /* then call this and next ones back in... */ - iChunkname = ((mng_chunk_headerp)pChunk)->iChunkname; - bCont = fProc (hHandle, (mng_handle)pChunk, iChunkname, iSeq); - } - - iSeq++; /* next one */ - pChunk = ((mng_chunk_headerp)pChunk)->pNext; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_ITERATE_CHUNKS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_copy_chunk (mng_handle hHandle, - mng_handle hChunk, - mng_handle hHandleOut) -{ - mng_datap pDataOut; - mng_chunkp pChunk; - mng_chunkp pChunkOut; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_COPY_CHUNK, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handles */ - MNG_VALIDHANDLE (hHandleOut) - - pDataOut = (mng_datap)hHandleOut; /* make outhandle addressable */ - pChunk = (mng_chunkp)hChunk; /* address the chunk */ - - if (!pDataOut->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pDataOut, MNG_FUNCTIONINVALID) - /* create a new chunk */ - iRetcode = ((mng_createchunk)((mng_chunk_headerp)pChunk)->fCreate) - (pDataOut, ((mng_chunk_headerp)pChunk), &pChunkOut); - if (!iRetcode) /* assign the chunk-specific data */ - iRetcode = ((mng_assignchunk)((mng_chunk_headerp)pChunk)->fAssign) - (pDataOut, pChunkOut, pChunk); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - mng_add_chunk (pDataOut, pChunkOut); /* and put it in the output-stream */ - - /* could it be the end of the chain ? */ - if (((mng_chunk_headerp)pChunkOut)->iChunkname == MNG_UINT_IEND) - { -#ifdef MNG_INCLUDE_JNG - if ((pDataOut->iFirstchunkadded == MNG_UINT_IHDR) || - (pDataOut->iFirstchunkadded == MNG_UINT_JHDR) ) -#else - if (pDataOut->iFirstchunkadded == MNG_UINT_IHDR) -#endif - pDataOut->bCreating = MNG_FALSE; /* right; this should be the last chunk !!! */ - } - - if (((mng_chunk_headerp)pChunkOut)->iChunkname == MNG_UINT_MEND) - pDataOut->bCreating = MNG_FALSE; /* definitely this should be the last !!! */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_COPY_CHUNK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_getchunk_ihdr (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iWidth, - mng_uint32 *iHeight, - mng_uint8 *iBitdepth, - mng_uint8 *iColortype, - mng_uint8 *iCompression, - mng_uint8 *iFilter, - mng_uint8 *iInterlace) -{ - mng_datap pData; - mng_ihdrp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_IHDR, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_ihdrp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_IHDR) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iWidth = pChunk->iWidth; /* fill the fields */ - *iHeight = pChunk->iHeight; - *iBitdepth = pChunk->iBitdepth; - *iColortype = pChunk->iColortype; - *iCompression = pChunk->iCompression; - *iFilter = pChunk->iFilter; - *iInterlace = pChunk->iInterlace; - - /* fill the chunk */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_IHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_getchunk_plte (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iCount, - mng_palette8 *aPalette) -{ - mng_datap pData; - mng_pltep pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PLTE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_pltep)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_PLTE) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iCount = pChunk->iEntrycount; /* fill the fields */ - - MNG_COPY (*aPalette, pChunk->aEntries, sizeof (mng_palette8)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PLTE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_getchunk_idat (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iRawlen, - mng_ptr *pRawdata) -{ - mng_datap pData; - mng_idatp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_IDAT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_idatp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_IDAT) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iRawlen = pChunk->iDatasize; /* fill the fields */ - *pRawdata = pChunk->pData; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_IDAT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_getchunk_trns (mng_handle hHandle, - mng_handle hChunk, - mng_bool *bEmpty, - mng_bool *bGlobal, - mng_uint8 *iType, - mng_uint32 *iCount, - mng_uint8arr *aAlphas, - mng_uint16 *iGray, - mng_uint16 *iRed, - mng_uint16 *iGreen, - mng_uint16 *iBlue, - mng_uint32 *iRawlen, - mng_uint8arr *aRawdata) -{ - mng_datap pData; - mng_trnsp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TRNS, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_trnsp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_tRNS) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *bEmpty = pChunk->bEmpty; /* fill the fields */ - *bGlobal = pChunk->bGlobal; - *iType = pChunk->iType; - *iCount = pChunk->iCount; - *iGray = pChunk->iGray; - *iRed = pChunk->iRed; - *iGreen = pChunk->iGreen; - *iBlue = pChunk->iBlue; - *iRawlen = pChunk->iRawlen; - - MNG_COPY (*aAlphas, pChunk->aEntries, sizeof (mng_uint8arr)); - MNG_COPY (*aRawdata, pChunk->aRawdata, sizeof (mng_uint8arr)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TRNS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_gAMA -mng_retcode MNG_DECL mng_getchunk_gama (mng_handle hHandle, - mng_handle hChunk, - mng_bool *bEmpty, - mng_uint32 *iGamma) -{ - mng_datap pData; - mng_gamap pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_GAMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_gamap)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_gAMA) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *bEmpty = pChunk->bEmpty; /* fill the fields */ - *iGamma = pChunk->iGamma; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_GAMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_cHRM -mng_retcode MNG_DECL mng_getchunk_chrm (mng_handle hHandle, - mng_handle hChunk, - mng_bool *bEmpty, - mng_uint32 *iWhitepointx, - mng_uint32 *iWhitepointy, - mng_uint32 *iRedx, - mng_uint32 *iRedy, - mng_uint32 *iGreenx, - mng_uint32 *iGreeny, - mng_uint32 *iBluex, - mng_uint32 *iBluey) -{ - mng_datap pData; - mng_chrmp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_CHRM, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_chrmp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_cHRM) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *bEmpty = pChunk->bEmpty; /* fill the fields */ - *iWhitepointx = pChunk->iWhitepointx; - *iWhitepointy = pChunk->iWhitepointy; - *iRedx = pChunk->iRedx; - *iRedy = pChunk->iRedy; - *iGreenx = pChunk->iGreenx; - *iGreeny = pChunk->iGreeny; - *iBluex = pChunk->iBluex; - *iBluey = pChunk->iBluey; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_CHRM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sRGB -mng_retcode MNG_DECL mng_getchunk_srgb (mng_handle hHandle, - mng_handle hChunk, - mng_bool *bEmpty, - mng_uint8 *iRenderingintent) -{ - mng_datap pData; - mng_srgbp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SRGB, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_srgbp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_sRGB) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *bEmpty = pChunk->bEmpty; /* fill the fields */ - *iRenderingintent = pChunk->iRenderingintent; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SRGB, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iCCP -mng_retcode MNG_DECL mng_getchunk_iccp (mng_handle hHandle, - mng_handle hChunk, - mng_bool *bEmpty, - mng_uint32 *iNamesize, - mng_pchar *zName, - mng_uint8 *iCompression, - mng_uint32 *iProfilesize, - mng_ptr *pProfile) -{ - mng_datap pData; - mng_iccpp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ICCP, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_iccpp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_iCCP) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *bEmpty = pChunk->bEmpty; /* fill the fields */ - *iNamesize = pChunk->iNamesize; - *zName = pChunk->zName; - *iCompression = pChunk->iCompression; - *iProfilesize = pChunk->iProfilesize; - *pProfile = pChunk->pProfile; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ICCP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_tEXt -mng_retcode MNG_DECL mng_getchunk_text (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iKeywordsize, - mng_pchar *zKeyword, - mng_uint32 *iTextsize, - mng_pchar *zText) -{ - mng_datap pData; - mng_textp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TEXT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_textp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_tEXt) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - /* fill the fields */ - *iKeywordsize = pChunk->iKeywordsize; - *zKeyword = pChunk->zKeyword; - *iTextsize = pChunk->iTextsize; - *zText = pChunk->zText; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TEXT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_zTXt -mng_retcode MNG_DECL mng_getchunk_ztxt (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iKeywordsize, - mng_pchar *zKeyword, - mng_uint8 *iCompression, - mng_uint32 *iTextsize, - mng_pchar *zText) -{ - mng_datap pData; - mng_ztxtp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ZTXT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_ztxtp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_zTXt) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - /* fill the fields */ - *iKeywordsize = pChunk->iKeywordsize; - *zKeyword = pChunk->zKeyword; - *iCompression = pChunk->iCompression; - *iTextsize = pChunk->iTextsize; - *zText = pChunk->zText; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ZTXT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iTXt -mng_retcode MNG_DECL mng_getchunk_itxt (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iKeywordsize, - mng_pchar *zKeyword, - mng_uint8 *iCompressionflag, - mng_uint8 *iCompressionmethod, - mng_uint32 *iLanguagesize, - mng_pchar *zLanguage, - mng_uint32 *iTranslationsize, - mng_pchar *zTranslation, - mng_uint32 *iTextsize, - mng_pchar *zText) -{ - mng_datap pData; - mng_itxtp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ITXT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_itxtp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_iTXt) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - /* fill the fields */ - *iKeywordsize = pChunk->iKeywordsize; - *zKeyword = pChunk->zKeyword; - *iCompressionflag = pChunk->iCompressionflag; - *iCompressionmethod = pChunk->iCompressionmethod; - *iLanguagesize = pChunk->iLanguagesize; - *zLanguage = pChunk->zLanguage; - *iTranslationsize = pChunk->iTranslationsize; - *zTranslation = pChunk->zTranslation; - *iTextsize = pChunk->iTextsize; - *zText = pChunk->zText; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ITXT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_bKGD -mng_retcode MNG_DECL mng_getchunk_bkgd (mng_handle hHandle, - mng_handle hChunk, - mng_bool *bEmpty, - mng_uint8 *iType, - mng_uint8 *iIndex, - mng_uint16 *iGray, - mng_uint16 *iRed, - mng_uint16 *iGreen, - mng_uint16 *iBlue) -{ - mng_datap pData; - mng_bkgdp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_BKGD, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_bkgdp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_bKGD) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *bEmpty = pChunk->bEmpty; /* fill the fields */ - *iType = pChunk->iType; - *iIndex = pChunk->iIndex; - *iGray = pChunk->iGray; - *iRed = pChunk->iRed; - *iGreen = pChunk->iGreen; - *iBlue = pChunk->iBlue; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_BKGD, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_pHYs -mng_retcode MNG_DECL mng_getchunk_phys (mng_handle hHandle, - mng_handle hChunk, - mng_bool *bEmpty, - mng_uint32 *iSizex, - mng_uint32 *iSizey, - mng_uint8 *iUnit) -{ - mng_datap pData; - mng_physp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PHYS, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_physp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_pHYs) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *bEmpty = pChunk->bEmpty; /* fill the fields */ - *iSizex = pChunk->iSizex; - *iSizey = pChunk->iSizey; - *iUnit = pChunk->iUnit; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PHYS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sBIT -mng_retcode MNG_DECL mng_getchunk_sbit (mng_handle hHandle, - mng_handle hChunk, - mng_bool *bEmpty, - mng_uint8 *iType, - mng_uint8arr4 *aBits) -{ - mng_datap pData; - mng_sbitp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SBIT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_sbitp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_sBIT) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *bEmpty = pChunk->bEmpty; - *iType = pChunk->iType; - (*aBits)[0] = pChunk->aBits[0]; - (*aBits)[1] = pChunk->aBits[1]; - (*aBits)[2] = pChunk->aBits[2]; - (*aBits)[3] = pChunk->aBits[3]; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SBIT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sPLT -mng_retcode MNG_DECL mng_getchunk_splt (mng_handle hHandle, - mng_handle hChunk, - mng_bool *bEmpty, - mng_uint32 *iNamesize, - mng_pchar *zName, - mng_uint8 *iSampledepth, - mng_uint32 *iEntrycount, - mng_ptr *pEntries) -{ - mng_datap pData; - mng_spltp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SPLT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_spltp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_sPLT) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *bEmpty = pChunk->bEmpty; /* fill the fields */ - *iNamesize = pChunk->iNamesize; - *zName = pChunk->zName; - *iSampledepth = pChunk->iSampledepth; - *iEntrycount = pChunk->iEntrycount; - *pEntries = pChunk->pEntries; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SPLT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_hIST -mng_retcode MNG_DECL mng_getchunk_hist (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iEntrycount, - mng_uint16arr *aEntries) -{ - mng_datap pData; - mng_histp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_HIST, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_histp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_hIST) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iEntrycount = pChunk->iEntrycount; /* fill the fields */ - - MNG_COPY (*aEntries, pChunk->aEntries, sizeof (mng_uint16arr)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_HIST, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_tIME -mng_retcode MNG_DECL mng_getchunk_time (mng_handle hHandle, - mng_handle hChunk, - mng_uint16 *iYear, - mng_uint8 *iMonth, - mng_uint8 *iDay, - mng_uint8 *iHour, - mng_uint8 *iMinute, - mng_uint8 *iSecond) -{ - mng_datap pData; - mng_timep pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TIME, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_timep)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_tIME) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iYear = pChunk->iYear; /* fill the fields */ - *iMonth = pChunk->iMonth; - *iDay = pChunk->iDay; - *iHour = pChunk->iHour; - *iMinute = pChunk->iMinute; - *iSecond = pChunk->iSecond; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TIME, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_getchunk_mhdr (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iWidth, - mng_uint32 *iHeight, - mng_uint32 *iTicks, - mng_uint32 *iLayercount, - mng_uint32 *iFramecount, - mng_uint32 *iPlaytime, - mng_uint32 *iSimplicity) -{ - mng_datap pData; - mng_mhdrp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MHDR, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_mhdrp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iWidth = pChunk->iWidth; /* fill the fields */ - *iHeight = pChunk->iHeight; - *iTicks = pChunk->iTicks; - *iLayercount = pChunk->iLayercount; - *iFramecount = pChunk->iFramecount; - *iPlaytime = pChunk->iPlaytime; - *iSimplicity = pChunk->iSimplicity; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_LOOP -mng_retcode MNG_DECL mng_getchunk_loop (mng_handle hHandle, - mng_handle hChunk, - mng_uint8 *iLevel, - mng_uint32 *iRepeat, - mng_uint8 *iTermination, - mng_uint32 *iItermin, - mng_uint32 *iItermax, - mng_uint32 *iCount, - mng_uint32p *pSignals) -{ - mng_datap pData; - mng_loopp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_LOOP, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_loopp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_LOOP) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iLevel = pChunk->iLevel; /* fill teh fields */ - *iRepeat = pChunk->iRepeat; - *iTermination = pChunk->iTermination; - *iItermin = pChunk->iItermin; - *iItermax = pChunk->iItermax; - *iCount = pChunk->iCount; - *pSignals = pChunk->pSignals; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_LOOP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_getchunk_endl (mng_handle hHandle, - mng_handle hChunk, - mng_uint8 *iLevel) -{ - mng_datap pData; - mng_endlp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ENDL, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_endlp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_ENDL) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iLevel = pChunk->iLevel; /* fill the field */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ENDL, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DEFI -mng_retcode MNG_DECL mng_getchunk_defi (mng_handle hHandle, - mng_handle hChunk, - mng_uint16 *iObjectid, - mng_uint8 *iDonotshow, - mng_uint8 *iConcrete, - mng_bool *bHasloca, - mng_int32 *iXlocation, - mng_int32 *iYlocation, - mng_bool *bHasclip, - mng_int32 *iLeftcb, - mng_int32 *iRightcb, - mng_int32 *iTopcb, - mng_int32 *iBottomcb) -{ - mng_datap pData; - mng_defip pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DEFI, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_defip)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_DEFI) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iObjectid = pChunk->iObjectid; /* fill the fields */ - *iDonotshow = pChunk->iDonotshow; - *iConcrete = pChunk->iConcrete; - *bHasloca = pChunk->bHasloca; - *iXlocation = pChunk->iXlocation; - *iYlocation = pChunk->iYlocation; - *bHasclip = pChunk->bHasclip; - *iLeftcb = pChunk->iLeftcb; - *iRightcb = pChunk->iRightcb; - *iTopcb = pChunk->iTopcb; - *iBottomcb = pChunk->iBottomcb; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DEFI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_BASI -mng_retcode MNG_DECL mng_getchunk_basi (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iWidth, - mng_uint32 *iHeight, - mng_uint8 *iBitdepth, - mng_uint8 *iColortype, - mng_uint8 *iCompression, - mng_uint8 *iFilter, - mng_uint8 *iInterlace, - mng_uint16 *iRed, - mng_uint16 *iGreen, - mng_uint16 *iBlue, - mng_uint16 *iAlpha, - mng_uint8 *iViewable) -{ - mng_datap pData; - mng_basip pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_BASI, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_basip)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_BASI) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iWidth = pChunk->iWidth; /* fill the fields */ - *iHeight = pChunk->iHeight; - *iBitdepth = pChunk->iBitdepth; - *iColortype = pChunk->iColortype; - *iCompression = pChunk->iCompression; - *iFilter = pChunk->iFilter; - *iInterlace = pChunk->iInterlace; - *iRed = pChunk->iRed; - *iGreen = pChunk->iGreen; - *iBlue = pChunk->iBlue; - *iAlpha = pChunk->iAlpha; - *iViewable = pChunk->iViewable; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_BASI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_CLON -mng_retcode MNG_DECL mng_getchunk_clon (mng_handle hHandle, - mng_handle hChunk, - mng_uint16 *iSourceid, - mng_uint16 *iCloneid, - mng_uint8 *iClonetype, - mng_uint8 *iDonotshow, - mng_uint8 *iConcrete, - mng_bool *bHasloca, - mng_uint8 *iLocationtype, - mng_int32 *iLocationx, - mng_int32 *iLocationy) -{ - mng_datap pData; - mng_clonp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_CLON, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_clonp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_CLON) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iSourceid = pChunk->iSourceid; /* fill the fields */ - *iCloneid = pChunk->iCloneid; - *iClonetype = pChunk->iClonetype; - *iDonotshow = pChunk->iDonotshow; - *iConcrete = pChunk->iConcrete; - *bHasloca = pChunk->bHasloca; - *iLocationtype = pChunk->iLocationtype; - *iLocationx = pChunk->iLocationx; - *iLocationy = pChunk->iLocationy; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_CLON, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -mng_retcode MNG_DECL mng_getchunk_past (mng_handle hHandle, - mng_handle hChunk, - mng_uint16 *iDestid, - mng_uint8 *iTargettype, - mng_int32 *iTargetx, - mng_int32 *iTargety, - mng_uint32 *iCount) -{ - mng_datap pData; - mng_pastp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PAST, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_pastp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_PAST) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iDestid = pChunk->iDestid; /* fill the fields */ - *iTargettype = pChunk->iTargettype; - *iTargetx = pChunk->iTargetx; - *iTargety = pChunk->iTargety; - *iCount = pChunk->iCount; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PAST, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -mng_retcode MNG_DECL mng_getchunk_past_src (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 iEntry, - mng_uint16 *iSourceid, - mng_uint8 *iComposition, - mng_uint8 *iOrientation, - mng_uint8 *iOffsettype, - mng_int32 *iOffsetx, - mng_int32 *iOffsety, - mng_uint8 *iBoundarytype, - mng_int32 *iBoundaryl, - mng_int32 *iBoundaryr, - mng_int32 *iBoundaryt, - mng_int32 *iBoundaryb) -{ - mng_datap pData; - mng_pastp pChunk; - mng_past_sourcep pEntry; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PAST_SRC, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_pastp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_PAST) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - if (iEntry >= pChunk->iCount) /* valid index ? */ - MNG_ERROR (pData, MNG_INVALIDENTRYIX) - /* address the entry */ - pEntry = pChunk->pSources + iEntry; - - *iSourceid = pEntry->iSourceid; /* fill the fields */ - *iComposition = pEntry->iComposition; - *iOrientation = pEntry->iOrientation; - *iOffsettype = pEntry->iOffsettype; - *iOffsetx = pEntry->iOffsetx; - *iOffsety = pEntry->iOffsety; - *iBoundarytype = pEntry->iBoundarytype; - *iBoundaryl = pEntry->iBoundaryl; - *iBoundaryr = pEntry->iBoundaryr; - *iBoundaryt = pEntry->iBoundaryt; - *iBoundaryb = pEntry->iBoundaryb; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PAST_SRC, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DISC -mng_retcode MNG_DECL mng_getchunk_disc (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iCount, - mng_uint16p *pObjectids) -{ - mng_datap pData; - mng_discp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DISC, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_discp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_DISC) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iCount = pChunk->iCount; /* fill the fields */ - *pObjectids = pChunk->pObjectids; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DISC, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_BACK -mng_retcode MNG_DECL mng_getchunk_back (mng_handle hHandle, - mng_handle hChunk, - mng_uint16 *iRed, - mng_uint16 *iGreen, - mng_uint16 *iBlue, - mng_uint8 *iMandatory, - mng_uint16 *iImageid, - mng_uint8 *iTile) -{ - mng_datap pData; - mng_backp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_BACK, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_backp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_BACK) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iRed = pChunk->iRed; /* fill the fields */ - *iGreen = pChunk->iGreen; - *iBlue = pChunk->iBlue; - *iMandatory = pChunk->iMandatory; - *iImageid = pChunk->iImageid; - *iTile = pChunk->iTile; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_BACK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_FRAM -mng_retcode MNG_DECL mng_getchunk_fram (mng_handle hHandle, - mng_handle hChunk, - mng_bool *bEmpty, - mng_uint8 *iMode, - mng_uint32 *iNamesize, - mng_pchar *zName, - mng_uint8 *iChangedelay, - mng_uint8 *iChangetimeout, - mng_uint8 *iChangeclipping, - mng_uint8 *iChangesyncid, - mng_uint32 *iDelay, - mng_uint32 *iTimeout, - mng_uint8 *iBoundarytype, - mng_int32 *iBoundaryl, - mng_int32 *iBoundaryr, - mng_int32 *iBoundaryt, - mng_int32 *iBoundaryb, - mng_uint32 *iCount, - mng_uint32p *pSyncids) -{ - mng_datap pData; - mng_framp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_FRAM, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_framp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_FRAM) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *bEmpty = pChunk->bEmpty; /* fill the fields */ - *iMode = pChunk->iMode; - *iNamesize = pChunk->iNamesize; - *zName = pChunk->zName; - *iChangedelay = pChunk->iChangedelay; - *iChangetimeout = pChunk->iChangetimeout; - *iChangeclipping = pChunk->iChangeclipping; - *iChangesyncid = pChunk->iChangesyncid; - *iDelay = pChunk->iDelay; - *iTimeout = pChunk->iTimeout; - *iBoundarytype = pChunk->iBoundarytype; - *iBoundaryl = pChunk->iBoundaryl; - *iBoundaryr = pChunk->iBoundaryr; - *iBoundaryt = pChunk->iBoundaryt; - *iBoundaryb = pChunk->iBoundaryb; - *iCount = pChunk->iCount; - *pSyncids = pChunk->pSyncids; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_FRAM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MOVE -mng_retcode MNG_DECL mng_getchunk_move (mng_handle hHandle, - mng_handle hChunk, - mng_uint16 *iFirstid, - mng_uint16 *iLastid, - mng_uint8 *iMovetype, - mng_int32 *iMovex, - mng_int32 *iMovey) -{ - mng_datap pData; - mng_movep pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MOVE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_movep)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_MOVE) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iFirstid = pChunk->iFirstid; /* fill the fields */ - *iLastid = pChunk->iLastid; - *iMovetype = pChunk->iMovetype; - *iMovex = pChunk->iMovex; - *iMovey = pChunk->iMovey; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MOVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_CLIP -mng_retcode MNG_DECL mng_getchunk_clip (mng_handle hHandle, - mng_handle hChunk, - mng_uint16 *iFirstid, - mng_uint16 *iLastid, - mng_uint8 *iCliptype, - mng_int32 *iClipl, - mng_int32 *iClipr, - mng_int32 *iClipt, - mng_int32 *iClipb) -{ - mng_datap pData; - mng_clipp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_CLIP, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_clipp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_CLIP) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iFirstid = pChunk->iFirstid; /* fill the fields */ - *iLastid = pChunk->iLastid; - *iCliptype = pChunk->iCliptype; - *iClipl = pChunk->iClipl; - *iClipr = pChunk->iClipr; - *iClipt = pChunk->iClipt; - *iClipb = pChunk->iClipb; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_CLIP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SHOW -mng_retcode MNG_DECL mng_getchunk_show (mng_handle hHandle, - mng_handle hChunk, - mng_bool *bEmpty, - mng_uint16 *iFirstid, - mng_uint16 *iLastid, - mng_uint8 *iMode) -{ - mng_datap pData; - mng_showp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SHOW, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_showp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_SHOW) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *bEmpty = pChunk->bEmpty; /* fill the fields */ - *iFirstid = pChunk->iFirstid; - *iLastid = pChunk->iLastid; - *iMode = pChunk->iMode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SHOW, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_TERM -mng_retcode MNG_DECL mng_getchunk_term (mng_handle hHandle, - mng_handle hChunk, - mng_uint8 *iTermaction, - mng_uint8 *iIteraction, - mng_uint32 *iDelay, - mng_uint32 *iItermax) -{ - mng_datap pData; - mng_termp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TERM, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_termp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_TERM) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iTermaction = pChunk->iTermaction; /* fill the fields */ - *iIteraction = pChunk->iIteraction; - *iDelay = pChunk->iDelay; - *iItermax = pChunk->iItermax; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TERM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SAVE -mng_retcode MNG_DECL mng_getchunk_save (mng_handle hHandle, - mng_handle hChunk, - mng_bool *bEmpty, - mng_uint8 *iOffsettype, - mng_uint32 *iCount) -{ - mng_datap pData; - mng_savep pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SAVE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_savep)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_SAVE) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *bEmpty = pChunk->bEmpty; /* fill the fields */ - *iOffsettype = pChunk->iOffsettype; - *iCount = pChunk->iCount; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SAVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_getchunk_save_entry (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 iEntry, - mng_uint8 *iEntrytype, - mng_uint32arr2 *iOffset, - mng_uint32arr2 *iStarttime, - mng_uint32 *iLayernr, - mng_uint32 *iFramenr, - mng_uint32 *iNamesize, - mng_pchar *zName) -{ - mng_datap pData; - mng_savep pChunk; - mng_save_entryp pEntry; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SAVE_ENTRY, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_savep)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_SAVE) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - if (iEntry >= pChunk->iCount) /* valid index ? */ - MNG_ERROR (pData, MNG_INVALIDENTRYIX) - - pEntry = pChunk->pEntries + iEntry; /* address the entry */ - /* fill the fields */ - *iEntrytype = pEntry->iEntrytype; - (*iOffset)[0] = pEntry->iOffset[0]; - (*iOffset)[1] = pEntry->iOffset[1]; - (*iStarttime)[0] = pEntry->iStarttime[0]; - (*iStarttime)[1] = pEntry->iStarttime[1]; - *iLayernr = pEntry->iLayernr; - *iFramenr = pEntry->iFramenr; - *iNamesize = pEntry->iNamesize; - *zName = pEntry->zName; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SAVE_ENTRY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SEEK -mng_retcode MNG_DECL mng_getchunk_seek (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iNamesize, - mng_pchar *zName) -{ - mng_datap pData; - mng_seekp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SEEK, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_seekp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_SEEK) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iNamesize = pChunk->iNamesize; /* fill the fields */ - *zName = pChunk->zName; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SEEK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_eXPI -mng_retcode MNG_DECL mng_getchunk_expi (mng_handle hHandle, - mng_handle hChunk, - mng_uint16 *iSnapshotid, - mng_uint32 *iNamesize, - mng_pchar *zName) -{ - mng_datap pData; - mng_expip pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_EXPI, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_expip)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_eXPI) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iSnapshotid = pChunk->iSnapshotid; /* fill the fields */ - *iNamesize = pChunk->iNamesize; - *zName = pChunk->zName; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_EXPI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_fPRI -mng_retcode MNG_DECL mng_getchunk_fpri (mng_handle hHandle, - mng_handle hChunk, - mng_uint8 *iDeltatype, - mng_uint8 *iPriority) -{ - mng_datap pData; - mng_fprip pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_FPRI, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_fprip)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_fPRI) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iDeltatype = pChunk->iDeltatype; /* fill the fields */ - *iPriority = pChunk->iPriority; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_FPRI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_nEED -mng_retcode MNG_DECL mng_getchunk_need (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iKeywordssize, - mng_pchar *zKeywords) -{ - mng_datap pData; - mng_needp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_NEED, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_needp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_nEED) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - /* fill the fields */ - *iKeywordssize = pChunk->iKeywordssize; - *zKeywords = pChunk->zKeywords; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_NEED, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_pHYg -mng_retcode MNG_DECL mng_getchunk_phyg (mng_handle hHandle, - mng_handle hChunk, - mng_bool *bEmpty, - mng_uint32 *iSizex, - mng_uint32 *iSizey, - mng_uint8 *iUnit) -{ - mng_datap pData; - mng_phygp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PHYG, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_phygp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_pHYg) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *bEmpty = pChunk->bEmpty; /* fill the fields */ - *iSizex = pChunk->iSizex; - *iSizey = pChunk->iSizey; - *iUnit = pChunk->iUnit; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PHYG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG - -mng_retcode MNG_DECL mng_getchunk_jhdr (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iWidth, - mng_uint32 *iHeight, - mng_uint8 *iColortype, - mng_uint8 *iImagesampledepth, - mng_uint8 *iImagecompression, - mng_uint8 *iImageinterlace, - mng_uint8 *iAlphasampledepth, - mng_uint8 *iAlphacompression, - mng_uint8 *iAlphafilter, - mng_uint8 *iAlphainterlace) -{ - mng_datap pData; - mng_jhdrp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_JHDR, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_jhdrp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_JHDR) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iWidth = pChunk->iWidth; /* fill the fields */ - *iHeight = pChunk->iHeight; - *iColortype = pChunk->iColortype; - *iImagesampledepth = pChunk->iImagesampledepth; - *iImagecompression = pChunk->iImagecompression; - *iImageinterlace = pChunk->iImageinterlace; - *iAlphasampledepth = pChunk->iAlphasampledepth; - *iAlphacompression = pChunk->iAlphacompression; - *iAlphafilter = pChunk->iAlphafilter; - *iAlphainterlace = pChunk->iAlphainterlace; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_JHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG - -mng_retcode MNG_DECL mng_getchunk_jdat (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iRawlen, - mng_ptr *pRawdata) -{ - mng_datap pData; - mng_jdatp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_JDAT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_jdatp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_JDAT) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iRawlen = pChunk->iDatasize; /* fill the fields */ - *pRawdata = pChunk->pData; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_JDAT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG - -mng_retcode MNG_DECL mng_getchunk_jdaa (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iRawlen, - mng_ptr *pRawdata) -{ - mng_datap pData; - mng_jdaap pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_JDAA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_jdaap)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_JDAA) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iRawlen = pChunk->iDatasize; /* fill the fields */ - *pRawdata = pChunk->pData; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_JDAA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode MNG_DECL mng_getchunk_dhdr (mng_handle hHandle, - mng_handle hChunk, - mng_uint16 *iObjectid, - mng_uint8 *iImagetype, - mng_uint8 *iDeltatype, - mng_uint32 *iBlockwidth, - mng_uint32 *iBlockheight, - mng_uint32 *iBlockx, - mng_uint32 *iBlocky) -{ - mng_datap pData; - mng_dhdrp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DHDR, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_dhdrp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_DHDR) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iObjectid = pChunk->iObjectid; /* fill the fields */ - *iImagetype = pChunk->iImagetype; - *iDeltatype = pChunk->iDeltatype; - *iBlockwidth = pChunk->iBlockwidth; - *iBlockheight = pChunk->iBlockheight; - *iBlockx = pChunk->iBlockx; - *iBlocky = pChunk->iBlocky; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode MNG_DECL mng_getchunk_prom (mng_handle hHandle, - mng_handle hChunk, - mng_uint8 *iColortype, - mng_uint8 *iSampledepth, - mng_uint8 *iFilltype) -{ - mng_datap pData; - mng_promp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PROM, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_promp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_PROM) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iColortype = pChunk->iColortype; /* fill the fields */ - *iSampledepth = pChunk->iSampledepth; - *iFilltype = pChunk->iFilltype; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PROM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode MNG_DECL mng_getchunk_pplt (mng_handle hHandle, - mng_handle hChunk, - mng_uint8 *iDeltatype, - mng_uint32 *iCount) -{ - mng_datap pData; - mng_ppltp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PPLT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_ppltp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_PPLT) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iDeltatype = pChunk->iDeltatype; /* fill the fields */ - *iCount = pChunk->iCount; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PPLT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode MNG_DECL mng_getchunk_pplt_entry (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 iEntry, - mng_uint16 *iRed, - mng_uint16 *iGreen, - mng_uint16 *iBlue, - mng_uint16 *iAlpha, - mng_bool *bUsed) -{ - mng_datap pData; - mng_ppltp pChunk; - mng_pplt_entryp pEntry; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PPLT_ENTRY, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_ppltp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_PPLT) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - if (iEntry >= pChunk->iCount) /* valid index ? */ - MNG_ERROR (pData, MNG_INVALIDENTRYIX) - - pEntry = &pChunk->aEntries[iEntry]; /* address the entry */ - - *iRed = pEntry->iRed; /* fill the fields */ - *iGreen = pEntry->iGreen; - *iBlue = pEntry->iBlue; - *iAlpha = pEntry->iAlpha; - *bUsed = pEntry->bUsed; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PPLT_ENTRY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode MNG_DECL mng_getchunk_drop (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iCount, - mng_chunkidp *pChunknames) -{ - mng_datap pData; - mng_dropp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DROP, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_dropp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_DROP) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iCount = pChunk->iCount; /* fill the fields */ - *pChunknames = pChunk->pChunknames; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DROP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DBYK -mng_retcode MNG_DECL mng_getchunk_dbyk (mng_handle hHandle, - mng_handle hChunk, - mng_chunkid *iChunkname, - mng_uint8 *iPolarity, - mng_uint32 *iKeywordssize, - mng_pchar *zKeywords) -{ - mng_datap pData; - mng_dbykp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DBYK, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_dbykp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_DBYK) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iChunkname = pChunk->iChunkname; /* fill the fields */ - *iPolarity = pChunk->iPolarity; - *iKeywordssize = pChunk->iKeywordssize; - *zKeywords = pChunk->zKeywords; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DBYK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR -mng_retcode MNG_DECL mng_getchunk_ordr (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iCount) -{ - mng_datap pData; - mng_ordrp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ORDR, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_ordrp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_ORDR) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iCount = pChunk->iCount; /* fill the field */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ORDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR -mng_retcode MNG_DECL mng_getchunk_ordr_entry (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 iEntry, - mng_chunkid *iChunkname, - mng_uint8 *iOrdertype) -{ - mng_datap pData; - mng_ordrp pChunk; - mng_ordr_entryp pEntry; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ORDR_ENTRY, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_ordrp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_ORDR) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - if (iEntry >= pChunk->iCount) /* valid index ? */ - MNG_ERROR (pData, MNG_INVALIDENTRYIX) - - pEntry = pChunk->pEntries + iEntry; /* address the proper entry */ - - *iChunkname = pEntry->iChunkname; /* fill the fields */ - *iOrdertype = pEntry->iOrdertype; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ORDR_ENTRY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MAGN -mng_retcode MNG_DECL mng_getchunk_magn (mng_handle hHandle, - mng_handle hChunk, - mng_uint16 *iFirstid, - mng_uint16 *iLastid, - mng_uint16 *iMethodX, - mng_uint16 *iMX, - mng_uint16 *iMY, - mng_uint16 *iML, - mng_uint16 *iMR, - mng_uint16 *iMT, - mng_uint16 *iMB, - mng_uint16 *iMethodY) -{ - mng_datap pData; - mng_magnp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MAGN, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_magnp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_MAGN) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iFirstid = pChunk->iFirstid; /* fill the fields */ - *iLastid = pChunk->iLastid; - *iMethodX = (mng_uint16)pChunk->iMethodX; - *iMX = pChunk->iMX; - *iMY = pChunk->iMY; - *iML = pChunk->iML; - *iMR = pChunk->iMR; - *iMT = pChunk->iMT; - *iMB = pChunk->iMB; - *iMethodY = (mng_uint16)pChunk->iMethodY; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MAGN, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_MPNG_PROPOSAL -MNG_EXT mng_retcode MNG_DECL mng_getchunk_mpng (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iFramewidth, - mng_uint32 *iFrameheight, - mng_uint16 *iNumplays, - mng_uint16 *iTickspersec, - mng_uint8 *iCompressionmethod, - mng_uint32 *iCount) -{ - mng_datap pData; - mng_mpngp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MPNG, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_mpngp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_mpNG) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - /* fill the fields */ - *iFramewidth = pChunk->iFramewidth; - *iFrameheight = pChunk->iFrameheight; - *iNumplays = pChunk->iNumplays; - *iTickspersec = pChunk->iTickspersec; - *iCompressionmethod = pChunk->iCompressionmethod; - *iCount = pChunk->iFramessize / sizeof (mng_mpng_frame); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MPNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_MPNG_PROPOSAL -MNG_EXT mng_retcode MNG_DECL mng_getchunk_mpng_frame (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 iEntry, - mng_uint32 *iX, - mng_uint32 *iY, - mng_uint32 *iWidth, - mng_uint32 *iHeight, - mng_int32 *iXoffset, - mng_int32 *iYoffset, - mng_uint16 *iTicks) -{ - mng_datap pData; - mng_mpngp pChunk; - mng_mpng_framep pFrame; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MPNG_FRAME, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_mpngp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_mpNG) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - /* valid index ? */ - if (iEntry >= (pChunk->iFramessize / sizeof (mng_mpng_frame))) - MNG_ERROR (pData, MNG_INVALIDENTRYIX) - - pFrame = pChunk->pFrames + iEntry; /* address the entry */ - /* fill the fields */ - *iX = pFrame->iX; - *iY = pFrame->iY; - *iWidth = pFrame->iWidth; - *iHeight = pFrame->iHeight; - *iXoffset = pFrame->iXoffset; - *iYoffset = pFrame->iYoffset; - *iTicks = pFrame->iTicks; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MPNG_FRAME, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_evNT -mng_retcode MNG_DECL mng_getchunk_evnt (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 *iCount) -{ - mng_datap pData; - mng_evntp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_EVNT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_evntp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_evNT) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - *iCount = pChunk->iCount; /* fill the fields */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_EVNT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_getchunk_evnt_entry (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 iEntry, - mng_uint8 *iEventtype, - mng_uint8 *iMasktype, - mng_int32 *iLeft, - mng_int32 *iRight, - mng_int32 *iTop, - mng_int32 *iBottom, - mng_uint16 *iObjectid, - mng_uint8 *iIndex, - mng_uint32 *iSegmentnamesize, - mng_pchar *zSegmentname) -{ - mng_datap pData; - mng_evntp pChunk; - mng_evnt_entryp pEntry; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_EVNT_ENTRY, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_evntp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.iChunkname != MNG_UINT_evNT) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - - if (iEntry >= pChunk->iCount) /* valid index ? */ - MNG_ERROR (pData, MNG_INVALIDENTRYIX) - - pEntry = pChunk->pEntries + iEntry; /* address the entry */ - /* fill the fields */ - *iEventtype = pEntry->iEventtype; - *iMasktype = pEntry->iMasktype; - *iLeft = pEntry->iLeft; - *iRight = pEntry->iRight; - *iTop = pEntry->iTop; - *iBottom = pEntry->iBottom; - *iObjectid = pEntry->iObjectid; - *iIndex = pEntry->iIndex; - *iSegmentnamesize = pEntry->iSegmentnamesize; - *zSegmentname = pEntry->zSegmentname; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_EVNT_ENTRY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_getchunk_unknown (mng_handle hHandle, - mng_handle hChunk, - mng_chunkid *iChunkname, - mng_uint32 *iRawlen, - mng_ptr *pRawdata) -{ - mng_datap pData; - mng_unknown_chunkp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_UNKNOWN, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - pChunk = (mng_unknown_chunkp)hChunk; /* address the chunk */ - - if (pChunk->sHeader.fCleanup != mng_free_unknown) - MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ - /* fill the fields */ - *iChunkname = pChunk->sHeader.iChunkname; - *iRawlen = pChunk->iDatasize; - *pRawdata = pChunk->pData; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_UNKNOWN, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_WRITE_PROCS - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_TERM -MNG_LOCAL mng_bool check_term (mng_datap pData, - mng_chunkid iChunkname) -{ - mng_chunk_headerp pChunk = (mng_chunk_headerp)pData->pLastchunk; - - if (!pChunk) /* nothing added yet ? */ - return MNG_TRUE; - /* last added chunk is TERM ? */ - if (pChunk->iChunkname != MNG_UINT_TERM) - return MNG_TRUE; - /* previous to last is MHDR ? */ - if ((pChunk->pPrev) && (((mng_chunk_headerp)pChunk->pPrev)->iChunkname == MNG_UINT_MHDR)) - return MNG_TRUE; - - if (iChunkname == MNG_UINT_SEEK) /* new chunk to be added is SEEK ? */ - return MNG_TRUE; - - return MNG_FALSE; -} -#endif - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_putchunk_ihdr (mng_handle hHandle, - mng_uint32 iWidth, - mng_uint32 iHeight, - mng_uint8 iBitdepth, - mng_uint8 iColortype, - mng_uint8 iCompression, - mng_uint8 iFilter, - mng_uint8 iInterlace) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_IHDR, mng_init_general, mng_free_general, mng_read_ihdr, mng_write_ihdr, mng_assign_general, 0, 0, sizeof(mng_ihdr)}; -#else - {MNG_UINT_IHDR, mng_init_ihdr, mng_free_ihdr, mng_read_ihdr, mng_write_ihdr, mng_assign_ihdr, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IHDR, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_IHDR)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_ihdr (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_IHDR, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - ((mng_ihdrp)pChunk)->iWidth = iWidth; - ((mng_ihdrp)pChunk)->iHeight = iHeight; - ((mng_ihdrp)pChunk)->iBitdepth = iBitdepth; - ((mng_ihdrp)pChunk)->iColortype = iColortype; - ((mng_ihdrp)pChunk)->iCompression = iCompression; - ((mng_ihdrp)pChunk)->iFilter = iFilter; - ((mng_ihdrp)pChunk)->iInterlace = iInterlace; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_putchunk_plte (mng_handle hHandle, - mng_uint32 iCount, - mng_palette8 aPalette) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_PLTE, mng_init_general, mng_free_general, mng_read_plte, mng_write_plte, mng_assign_general, 0, 0, sizeof(mng_plte)}; -#else - {MNG_UINT_PLTE, mng_init_plte, mng_free_plte, mng_read_plte, mng_write_plte, mng_assign_plte, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PLTE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_PLTE)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_plte (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_PLTE, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_pltep)pChunk)->iEntrycount = iCount; - ((mng_pltep)pChunk)->bEmpty = (mng_bool)(iCount == 0); - - MNG_COPY (((mng_pltep)pChunk)->aEntries, aPalette, sizeof (mng_palette8)); - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PLTE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_putchunk_idat (mng_handle hHandle, - mng_uint32 iRawlen, - mng_ptr pRawdata) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_IDAT, mng_init_general, mng_free_idat, mng_read_idat, mng_write_idat, mng_assign_idat, 0, 0, sizeof(mng_idat)}; -#else - {MNG_UINT_IDAT, mng_init_idat, mng_free_idat, mng_read_idat, mng_write_idat, mng_assign_idat, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IDAT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_IDAT)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_idat (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_IDAT, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_idatp)pChunk)->bEmpty = (mng_bool)(iRawlen == 0); - ((mng_idatp)pChunk)->iDatasize = iRawlen; - - if (iRawlen) - { - MNG_ALLOC (pData, ((mng_idatp)pChunk)->pData, iRawlen); - MNG_COPY (((mng_idatp)pChunk)->pData, pRawdata, iRawlen); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IDAT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_putchunk_iend (mng_handle hHandle) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_IEND, mng_init_general, mng_free_general, mng_read_iend, mng_write_iend, mng_assign_general, 0, 0, sizeof(mng_iend)}; -#else - {MNG_UINT_IEND, mng_init_iend, mng_free_iend, mng_read_iend, mng_write_iend, mng_assign_iend, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IEND, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_IEND)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_iend (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_IEND, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_INCLUDE_JNG - if ((pData->iFirstchunkadded == MNG_UINT_IHDR) || - (pData->iFirstchunkadded == MNG_UINT_JHDR) ) -#else - if (pData->iFirstchunkadded == MNG_UINT_IHDR) -#endif - pData->bCreating = MNG_FALSE; /* should be last chunk !!! */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IEND, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_putchunk_trns (mng_handle hHandle, - mng_bool bEmpty, - mng_bool bGlobal, - mng_uint8 iType, - mng_uint32 iCount, - mng_uint8arr aAlphas, - mng_uint16 iGray, - mng_uint16 iRed, - mng_uint16 iGreen, - mng_uint16 iBlue, - mng_uint32 iRawlen, - mng_uint8arr aRawdata) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_tRNS, mng_init_general, mng_free_general, mng_read_trns, mng_write_trns, mng_assign_general, 0, 0, sizeof(mng_trns)}; -#else - {MNG_UINT_tRNS, mng_init_trns, mng_free_trns, mng_read_trns, mng_write_trns, mng_assign_trns, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TRNS, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_tRNS)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_trns (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_tRNS, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_trnsp)pChunk)->bEmpty = bEmpty; - ((mng_trnsp)pChunk)->bGlobal = bGlobal; - ((mng_trnsp)pChunk)->iType = iType; - ((mng_trnsp)pChunk)->iCount = iCount; - ((mng_trnsp)pChunk)->iGray = iGray; - ((mng_trnsp)pChunk)->iRed = iRed; - ((mng_trnsp)pChunk)->iGreen = iGreen; - ((mng_trnsp)pChunk)->iBlue = iBlue; - ((mng_trnsp)pChunk)->iRawlen = iRawlen; - - MNG_COPY (((mng_trnsp)pChunk)->aEntries, aAlphas, sizeof (mng_uint8arr)); - MNG_COPY (((mng_trnsp)pChunk)->aRawdata, aRawdata, sizeof (mng_uint8arr)); - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TRNS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_gAMA -mng_retcode MNG_DECL mng_putchunk_gama (mng_handle hHandle, - mng_bool bEmpty, - mng_uint32 iGamma) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_gAMA, mng_init_general, mng_free_general, mng_read_gama, mng_write_gama, mng_assign_general, 0, 0, sizeof(mng_gama)}; -#else - {MNG_UINT_gAMA, mng_init_gama, mng_free_gama, mng_read_gama, mng_write_gama, mng_assign_gama, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_GAMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_gAMA)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_gama (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_gAMA, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_gamap)pChunk)->bEmpty = bEmpty; - ((mng_gamap)pChunk)->iGamma = iGamma; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_GAMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_cHRM -mng_retcode MNG_DECL mng_putchunk_chrm (mng_handle hHandle, - mng_bool bEmpty, - mng_uint32 iWhitepointx, - mng_uint32 iWhitepointy, - mng_uint32 iRedx, - mng_uint32 iRedy, - mng_uint32 iGreenx, - mng_uint32 iGreeny, - mng_uint32 iBluex, - mng_uint32 iBluey) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_cHRM, mng_init_general, mng_free_general, mng_read_chrm, mng_write_chrm, mng_assign_general, 0, 0, sizeof(mng_chrm)}; -#else - {MNG_UINT_cHRM, mng_init_chrm, mng_free_chrm, mng_read_chrm, mng_write_chrm, mng_assign_chrm, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_CHRM, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_cHRM)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_chrm (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_cHRM, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_chrmp)pChunk)->bEmpty = bEmpty; - ((mng_chrmp)pChunk)->iWhitepointx = iWhitepointx; - ((mng_chrmp)pChunk)->iWhitepointy = iWhitepointy; - ((mng_chrmp)pChunk)->iRedx = iRedx; - ((mng_chrmp)pChunk)->iRedy = iRedy; - ((mng_chrmp)pChunk)->iGreenx = iGreenx; - ((mng_chrmp)pChunk)->iGreeny = iGreeny; - ((mng_chrmp)pChunk)->iBluex = iBluex; - ((mng_chrmp)pChunk)->iBluey = iBluey; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_CHRM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sRGB -mng_retcode MNG_DECL mng_putchunk_srgb (mng_handle hHandle, - mng_bool bEmpty, - mng_uint8 iRenderingintent) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_sRGB, mng_init_general, mng_free_general, mng_read_srgb, mng_write_srgb, mng_assign_general, 0, 0, sizeof(mng_srgb)}; -#else - {MNG_UINT_sRGB, mng_init_srgb, mng_free_srgb, mng_read_srgb, mng_write_srgb, mng_assign_srgb, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SRGB, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_sRGB)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_srgb (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_sRGB, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_srgbp)pChunk)->bEmpty = bEmpty; - ((mng_srgbp)pChunk)->iRenderingintent = iRenderingintent; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SRGB, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iCCP -mng_retcode MNG_DECL mng_putchunk_iccp (mng_handle hHandle, - mng_bool bEmpty, - mng_uint32 iNamesize, - mng_pchar zName, - mng_uint8 iCompression, - mng_uint32 iProfilesize, - mng_ptr pProfile) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_iCCP, mng_init_general, mng_free_iccp, mng_read_iccp, mng_write_iccp, mng_assign_iccp, 0, 0, sizeof(mng_iccp)}; -#else - {MNG_UINT_iCCP, mng_init_iccp, mng_free_iccp, mng_read_iccp, mng_write_iccp, mng_assign_iccp, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ICCP, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_iCCP)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_iccp (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_iCCP, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_iccpp)pChunk)->bEmpty = bEmpty; - ((mng_iccpp)pChunk)->iNamesize = iNamesize; - ((mng_iccpp)pChunk)->iCompression = iCompression; - ((mng_iccpp)pChunk)->iProfilesize = iProfilesize; - - if (iNamesize) - { - MNG_ALLOC (pData, ((mng_iccpp)pChunk)->zName, iNamesize + 1); - MNG_COPY (((mng_iccpp)pChunk)->zName, zName, iNamesize); - } - - if (iProfilesize) - { - MNG_ALLOC (pData, ((mng_iccpp)pChunk)->pProfile, iProfilesize); - MNG_COPY (((mng_iccpp)pChunk)->pProfile, pProfile, iProfilesize); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ICCP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_tEXt -mng_retcode MNG_DECL mng_putchunk_text (mng_handle hHandle, - mng_uint32 iKeywordsize, - mng_pchar zKeyword, - mng_uint32 iTextsize, - mng_pchar zText) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_tEXt, mng_init_general, mng_free_text, mng_read_text, mng_write_text, mng_assign_text, 0, 0, sizeof(mng_text)}; -#else - {MNG_UINT_tEXt, mng_init_text, mng_free_text, mng_read_text, mng_write_text, mng_assign_text, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TEXT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_tEXt)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_text (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_tEXt, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_textp)pChunk)->iKeywordsize = iKeywordsize; - ((mng_textp)pChunk)->iTextsize = iTextsize; - - if (iKeywordsize) - { - MNG_ALLOC (pData, ((mng_textp)pChunk)->zKeyword, iKeywordsize + 1); - MNG_COPY (((mng_textp)pChunk)->zKeyword, zKeyword, iKeywordsize); - } - - if (iTextsize) - { - MNG_ALLOC (pData, ((mng_textp)pChunk)->zText, iTextsize + 1); - MNG_COPY (((mng_textp)pChunk)->zText, zText, iTextsize); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TEXT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_zTXt -mng_retcode MNG_DECL mng_putchunk_ztxt (mng_handle hHandle, - mng_uint32 iKeywordsize, - mng_pchar zKeyword, - mng_uint8 iCompression, - mng_uint32 iTextsize, - mng_pchar zText) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_zTXt, mng_init_general, mng_free_ztxt, mng_read_ztxt, mng_write_ztxt, mng_assign_ztxt, 0, 0, sizeof(mng_ztxt)}; -#else - {MNG_UINT_zTXt, mng_init_ztxt, mng_free_ztxt, mng_read_ztxt, mng_write_ztxt, mng_assign_ztxt, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ZTXT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_zTXt)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_ztxt (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_zTXt, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_ztxtp)pChunk)->iKeywordsize = iKeywordsize; - ((mng_ztxtp)pChunk)->iCompression = iCompression; - ((mng_ztxtp)pChunk)->iTextsize = iTextsize; - - if (iKeywordsize) - { - MNG_ALLOC (pData, ((mng_ztxtp)pChunk)->zKeyword, iKeywordsize + 1); - MNG_COPY (((mng_ztxtp)pChunk)->zKeyword, zKeyword, iKeywordsize); - } - - if (iTextsize) - { - MNG_ALLOC (pData, ((mng_ztxtp)pChunk)->zText, iTextsize + 1); - MNG_COPY (((mng_ztxtp)pChunk)->zText, zText, iTextsize); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ZTXT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iTXt -mng_retcode MNG_DECL mng_putchunk_itxt (mng_handle hHandle, - mng_uint32 iKeywordsize, - mng_pchar zKeyword, - mng_uint8 iCompressionflag, - mng_uint8 iCompressionmethod, - mng_uint32 iLanguagesize, - mng_pchar zLanguage, - mng_uint32 iTranslationsize, - mng_pchar zTranslation, - mng_uint32 iTextsize, - mng_pchar zText) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_iTXt, mng_init_general, mng_free_itxt, mng_read_itxt, mng_write_itxt, mng_assign_itxt, 0, 0, sizeof(mng_itxt)}; -#else - {MNG_UINT_iTXt, mng_init_itxt, mng_free_itxt, mng_read_itxt, mng_write_itxt, mng_assign_itxt, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ITXT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_iTXt)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_itxt (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_iTXt, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_itxtp)pChunk)->iKeywordsize = iKeywordsize; - ((mng_itxtp)pChunk)->iCompressionflag = iCompressionflag; - ((mng_itxtp)pChunk)->iCompressionmethod = iCompressionmethod; - ((mng_itxtp)pChunk)->iLanguagesize = iLanguagesize; - ((mng_itxtp)pChunk)->iTranslationsize = iTranslationsize; - ((mng_itxtp)pChunk)->iTextsize = iTextsize; - - if (iKeywordsize) - { - MNG_ALLOC (pData, ((mng_itxtp)pChunk)->zKeyword, iKeywordsize + 1); - MNG_COPY (((mng_itxtp)pChunk)->zKeyword, zKeyword, iKeywordsize); - } - - if (iLanguagesize) - { - MNG_ALLOC (pData, ((mng_itxtp)pChunk)->zLanguage, iLanguagesize + 1); - MNG_COPY (((mng_itxtp)pChunk)->zLanguage, zLanguage, iLanguagesize); - } - - if (iTranslationsize) - { - MNG_ALLOC (pData, ((mng_itxtp)pChunk)->zTranslation, iTranslationsize + 1); - MNG_COPY (((mng_itxtp)pChunk)->zTranslation, zTranslation, iTranslationsize); - } - - if (iTextsize) - { - MNG_ALLOC (pData, ((mng_itxtp)pChunk)->zText, iTextsize + 1); - MNG_COPY (((mng_itxtp)pChunk)->zText, zText, iTextsize); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ITXT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_bKGD -mng_retcode MNG_DECL mng_putchunk_bkgd (mng_handle hHandle, - mng_bool bEmpty, - mng_uint8 iType, - mng_uint8 iIndex, - mng_uint16 iGray, - mng_uint16 iRed, - mng_uint16 iGreen, - mng_uint16 iBlue) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_bKGD, mng_init_general, mng_free_general, mng_read_bkgd, mng_write_bkgd, mng_assign_general, 0, 0, sizeof(mng_bkgd)}; -#else - {MNG_UINT_bKGD, mng_init_bkgd, mng_free_bkgd, mng_read_bkgd, mng_write_bkgd, mng_assign_bkgd, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_BKGD, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_bKGD)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_bkgd (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_bKGD, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_bkgdp)pChunk)->bEmpty = bEmpty; - ((mng_bkgdp)pChunk)->iType = iType; - ((mng_bkgdp)pChunk)->iIndex = iIndex; - ((mng_bkgdp)pChunk)->iGray = iGray; - ((mng_bkgdp)pChunk)->iRed = iRed; - ((mng_bkgdp)pChunk)->iGreen = iGreen; - ((mng_bkgdp)pChunk)->iBlue = iBlue; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_BKGD, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_pHYs -mng_retcode MNG_DECL mng_putchunk_phys (mng_handle hHandle, - mng_bool bEmpty, - mng_uint32 iSizex, - mng_uint32 iSizey, - mng_uint8 iUnit) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_pHYs, mng_init_general, mng_free_general, mng_read_phys, mng_write_phys, mng_assign_general, 0, 0, sizeof(mng_phys)}; -#else - {MNG_UINT_pHYs, mng_init_phys, mng_free_phys, mng_read_phys, mng_write_phys, mng_assign_phys, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PHYS, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_pHYs)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_phys (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_pHYs, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_physp)pChunk)->bEmpty = bEmpty; - ((mng_physp)pChunk)->iSizex = iSizex; - ((mng_physp)pChunk)->iSizey = iSizey; - ((mng_physp)pChunk)->iUnit = iUnit; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PHYS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sBIT -mng_retcode MNG_DECL mng_putchunk_sbit (mng_handle hHandle, - mng_bool bEmpty, - mng_uint8 iType, - mng_uint8arr4 aBits) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_sBIT, mng_init_general, mng_free_general, mng_read_sbit, mng_write_sbit, mng_assign_general, 0, 0, sizeof(mng_sbit)}; -#else - {MNG_UINT_sBIT, mng_init_sbit, mng_free_sbit, mng_read_sbit, mng_write_sbit, mng_assign_sbit, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SBIT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_sBIT)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_sbit (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_sBIT, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_sbitp)pChunk)->bEmpty = bEmpty; - ((mng_sbitp)pChunk)->iType = iType; - ((mng_sbitp)pChunk)->aBits[0] = aBits[0]; - ((mng_sbitp)pChunk)->aBits[1] = aBits[1]; - ((mng_sbitp)pChunk)->aBits[2] = aBits[2]; - ((mng_sbitp)pChunk)->aBits[3] = aBits[3]; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SBIT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sPLT -mng_retcode MNG_DECL mng_putchunk_splt (mng_handle hHandle, - mng_bool bEmpty, - mng_uint32 iNamesize, - mng_pchar zName, - mng_uint8 iSampledepth, - mng_uint32 iEntrycount, - mng_ptr pEntries) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_sPLT, mng_init_general, mng_free_splt, mng_read_splt, mng_write_splt, mng_assign_splt, 0, 0, sizeof(mng_splt)}; -#else - {MNG_UINT_sPLT, mng_init_splt, mng_free_splt, mng_read_splt, mng_write_splt, mng_assign_splt, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SPLT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_sPLT)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_splt (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_sPLT, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_spltp)pChunk)->bEmpty = bEmpty; - ((mng_spltp)pChunk)->iNamesize = iNamesize; - ((mng_spltp)pChunk)->iSampledepth = iSampledepth; - ((mng_spltp)pChunk)->iEntrycount = iEntrycount; - - if (iNamesize) - { - MNG_ALLOC (pData, ((mng_spltp)pChunk)->zName, iNamesize + 1); - MNG_COPY (((mng_spltp)pChunk)->zName, zName, iNamesize); - } - - if (iEntrycount) - { - mng_uint32 iSize = iEntrycount * ((iSampledepth >> 1) + 2); - - MNG_ALLOC (pData, ((mng_spltp)pChunk)->pEntries, iSize); - MNG_COPY (((mng_spltp)pChunk)->pEntries, pEntries, iSize); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SPLT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_hIST -mng_retcode MNG_DECL mng_putchunk_hist (mng_handle hHandle, - mng_uint32 iEntrycount, - mng_uint16arr aEntries) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_hIST, mng_init_general, mng_free_general, mng_read_hist, mng_write_hist, mng_assign_general, 0, 0, sizeof(mng_hist)}; -#else - {MNG_UINT_hIST, mng_init_hist, mng_free_hist, mng_read_hist, mng_write_hist, mng_assign_hist, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_HIST, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_hIST)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_hist (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_hIST, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_histp)pChunk)->iEntrycount = iEntrycount; - - MNG_COPY (((mng_histp)pChunk)->aEntries, aEntries, sizeof (mng_uint16arr)); - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_HIST, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_tIME -mng_retcode MNG_DECL mng_putchunk_time (mng_handle hHandle, - mng_uint16 iYear, - mng_uint8 iMonth, - mng_uint8 iDay, - mng_uint8 iHour, - mng_uint8 iMinute, - mng_uint8 iSecond) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_tIME, mng_init_general, mng_free_general, mng_read_time, mng_write_time, mng_assign_general, 0, 0, sizeof(mng_time)}; -#else - {MNG_UINT_tIME, mng_init_time, mng_free_time, mng_read_time, mng_write_time, mng_assign_time, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TIME, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_tIME)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_time (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_tIME, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_timep)pChunk)->iYear = iYear; - ((mng_timep)pChunk)->iMonth = iMonth; - ((mng_timep)pChunk)->iDay = iDay; - ((mng_timep)pChunk)->iHour = iHour; - ((mng_timep)pChunk)->iMinute = iMinute; - ((mng_timep)pChunk)->iSecond = iSecond; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TIME, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_putchunk_mhdr (mng_handle hHandle, - mng_uint32 iWidth, - mng_uint32 iHeight, - mng_uint32 iTicks, - mng_uint32 iLayercount, - mng_uint32 iFramecount, - mng_uint32 iPlaytime, - mng_uint32 iSimplicity) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_MHDR, mng_init_general, mng_free_general, mng_read_mhdr, mng_write_mhdr, mng_assign_general, 0, 0, sizeof(mng_mhdr)}; -#else - {MNG_UINT_MHDR, mng_init_mhdr, mng_free_mhdr, mng_read_mhdr, mng_write_mhdr, mng_assign_mhdr, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MHDR, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must be very first! */ - if (pData->iFirstchunkadded != 0) - MNG_ERROR (pData, MNG_SEQUENCEERROR) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_MHDR)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_mhdr (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_MHDR, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_mhdrp)pChunk)->iWidth = iWidth; - ((mng_mhdrp)pChunk)->iHeight = iHeight; - ((mng_mhdrp)pChunk)->iTicks = iTicks; - ((mng_mhdrp)pChunk)->iLayercount = iLayercount; - ((mng_mhdrp)pChunk)->iFramecount = iFramecount; - ((mng_mhdrp)pChunk)->iPlaytime = iPlaytime; - ((mng_mhdrp)pChunk)->iSimplicity = iSimplicity; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_putchunk_mend (mng_handle hHandle) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_MEND, mng_init_general, mng_free_general, mng_read_mend, mng_write_mend, mng_assign_general, 0, 0, sizeof(mng_mend)}; -#else - {MNG_UINT_MEND, mng_init_mend, mng_free_mend, mng_read_mend, mng_write_mend, mng_assign_mend, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MEND, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_MEND)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_mend (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_MEND, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - - pData->bCreating = MNG_FALSE; /* should be last chunk !!! */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MEND, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_LOOP -mng_retcode MNG_DECL mng_putchunk_loop (mng_handle hHandle, - mng_uint8 iLevel, - mng_uint32 iRepeat, - mng_uint8 iTermination, - mng_uint32 iItermin, - mng_uint32 iItermax, - mng_uint32 iCount, - mng_uint32p pSignals) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_LOOP, mng_init_general, mng_free_loop, mng_read_loop, mng_write_loop, mng_assign_loop, 0, 0, sizeof(mng_loop)}; -#else - {MNG_UINT_LOOP, mng_init_loop, mng_free_loop, mng_read_loop, mng_write_loop, mng_assign_loop, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_LOOP, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_LOOP)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_loop (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_LOOP, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_loopp)pChunk)->iLevel = iLevel; - ((mng_loopp)pChunk)->iRepeat = iRepeat; - ((mng_loopp)pChunk)->iTermination = iTermination; - ((mng_loopp)pChunk)->iItermin = iItermin; - ((mng_loopp)pChunk)->iItermax = iItermax; - ((mng_loopp)pChunk)->iCount = iCount; - ((mng_loopp)pChunk)->pSignals = pSignals; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_LOOP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_putchunk_endl (mng_handle hHandle, - mng_uint8 iLevel) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_ENDL, mng_init_general, mng_free_general, mng_read_endl, mng_write_endl, mng_assign_general, 0, 0, sizeof(mng_endl)}; -#else - {MNG_UINT_ENDL, mng_init_endl, mng_free_endl, mng_read_endl, mng_write_endl, mng_assign_endl, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ENDL, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_ENDL)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_endl (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_ENDL, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_endlp)pChunk)->iLevel = iLevel; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ENDL, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DEFI -mng_retcode MNG_DECL mng_putchunk_defi (mng_handle hHandle, - mng_uint16 iObjectid, - mng_uint8 iDonotshow, - mng_uint8 iConcrete, - mng_bool bHasloca, - mng_int32 iXlocation, - mng_int32 iYlocation, - mng_bool bHasclip, - mng_int32 iLeftcb, - mng_int32 iRightcb, - mng_int32 iTopcb, - mng_int32 iBottomcb) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_DEFI, mng_init_general, mng_free_general, mng_read_defi, mng_write_defi, mng_assign_general, 0, 0, sizeof(mng_defi)}; -#else - {MNG_UINT_DEFI, mng_init_defi, mng_free_defi, mng_read_defi, mng_write_defi, mng_assign_defi, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DEFI, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_DEFI)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_defi (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_DEFI, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_defip)pChunk)->iObjectid = iObjectid; - ((mng_defip)pChunk)->iDonotshow = iDonotshow; - ((mng_defip)pChunk)->iConcrete = iConcrete; - ((mng_defip)pChunk)->bHasloca = bHasloca; - ((mng_defip)pChunk)->iXlocation = iXlocation; - ((mng_defip)pChunk)->iYlocation = iYlocation; - ((mng_defip)pChunk)->bHasclip = bHasclip; - ((mng_defip)pChunk)->iLeftcb = iLeftcb; - ((mng_defip)pChunk)->iRightcb = iRightcb; - ((mng_defip)pChunk)->iTopcb = iTopcb; - ((mng_defip)pChunk)->iBottomcb = iBottomcb; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DEFI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_BASI -mng_retcode MNG_DECL mng_putchunk_basi (mng_handle hHandle, - mng_uint32 iWidth, - mng_uint32 iHeight, - mng_uint8 iBitdepth, - mng_uint8 iColortype, - mng_uint8 iCompression, - mng_uint8 iFilter, - mng_uint8 iInterlace, - mng_uint16 iRed, - mng_uint16 iGreen, - mng_uint16 iBlue, - mng_uint16 iAlpha, - mng_uint8 iViewable) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_BASI, mng_init_general, mng_free_general, mng_read_basi, mng_write_basi, mng_assign_general, 0, 0, sizeof(mng_basi)}; -#else - {MNG_UINT_BASI, mng_init_basi, mng_free_basi, mng_read_basi, mng_write_basi, mng_assign_basi, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_BASI, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_BASI)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_basi (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_BASI, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_basip)pChunk)->iWidth = iWidth; - ((mng_basip)pChunk)->iHeight = iHeight; - ((mng_basip)pChunk)->iBitdepth = iBitdepth; - ((mng_basip)pChunk)->iColortype = iColortype; - ((mng_basip)pChunk)->iCompression = iCompression; - ((mng_basip)pChunk)->iFilter = iFilter; - ((mng_basip)pChunk)->iInterlace = iInterlace; - ((mng_basip)pChunk)->iRed = iRed; - ((mng_basip)pChunk)->iGreen = iGreen; - ((mng_basip)pChunk)->iBlue = iBlue; - ((mng_basip)pChunk)->iAlpha = iAlpha; - ((mng_basip)pChunk)->iViewable = iViewable; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_BASI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_CLON -mng_retcode MNG_DECL mng_putchunk_clon (mng_handle hHandle, - mng_uint16 iSourceid, - mng_uint16 iCloneid, - mng_uint8 iClonetype, - mng_uint8 iDonotshow, - mng_uint8 iConcrete, - mng_bool bHasloca, - mng_uint8 iLocationtype, - mng_int32 iLocationx, - mng_int32 iLocationy) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_CLON, mng_init_general, mng_free_general, mng_read_clon, mng_write_clon, mng_assign_general, 0, 0, sizeof(mng_clon)}; -#else - {MNG_UINT_CLON, mng_init_clon, mng_free_clon, mng_read_clon, mng_write_clon, mng_assign_clon, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_CLON, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_CLON)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_clon (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_CLON, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_clonp)pChunk)->iSourceid = iSourceid; - ((mng_clonp)pChunk)->iCloneid = iCloneid; - ((mng_clonp)pChunk)->iClonetype = iClonetype; - ((mng_clonp)pChunk)->iDonotshow = iDonotshow; - ((mng_clonp)pChunk)->iConcrete = iConcrete; - ((mng_clonp)pChunk)->bHasloca = bHasloca; - ((mng_clonp)pChunk)->iLocationtype = iLocationtype; - ((mng_clonp)pChunk)->iLocationx = iLocationx; - ((mng_clonp)pChunk)->iLocationy = iLocationy; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_CLON, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -mng_retcode MNG_DECL mng_putchunk_past (mng_handle hHandle, - mng_uint16 iDestid, - mng_uint8 iTargettype, - mng_int32 iTargetx, - mng_int32 iTargety, - mng_uint32 iCount) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_PAST, mng_init_general, mng_free_past, mng_read_past, mng_write_past, mng_assign_past, 0, 0, sizeof(mng_past)}; -#else - {MNG_UINT_PAST, mng_init_past, mng_free_past, mng_read_past, mng_write_past, mng_assign_past, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PAST, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_PAST)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_past (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_PAST, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_pastp)pChunk)->iDestid = iDestid; - ((mng_pastp)pChunk)->iTargettype = iTargettype; - ((mng_pastp)pChunk)->iTargetx = iTargetx; - ((mng_pastp)pChunk)->iTargety = iTargety; - ((mng_pastp)pChunk)->iCount = iCount; - - if (iCount) - MNG_ALLOC (pData, ((mng_pastp)pChunk)->pSources, iCount * sizeof (mng_past_source)); - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PAST, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -mng_retcode MNG_DECL mng_putchunk_past_src (mng_handle hHandle, - mng_uint32 iEntry, - mng_uint16 iSourceid, - mng_uint8 iComposition, - mng_uint8 iOrientation, - mng_uint8 iOffsettype, - mng_int32 iOffsetx, - mng_int32 iOffsety, - mng_uint8 iBoundarytype, - mng_int32 iBoundaryl, - mng_int32 iBoundaryr, - mng_int32 iBoundaryt, - mng_int32 iBoundaryb) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_past_sourcep pEntry; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PAST_SRC, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - - pChunk = pData->pLastchunk; /* last one must have been PAST ! */ - - if (((mng_chunk_headerp)pChunk)->iChunkname != MNG_UINT_PAST) - MNG_ERROR (pData, MNG_NOCORRCHUNK) - /* index out of bounds ? */ - if (iEntry >= ((mng_pastp)pChunk)->iCount) - MNG_ERROR (pData, MNG_INVALIDENTRYIX) - /* address proper entry */ - pEntry = ((mng_pastp)pChunk)->pSources + iEntry; - - pEntry->iSourceid = iSourceid; /* fill entry */ - pEntry->iComposition = iComposition; - pEntry->iOrientation = iOrientation; - pEntry->iOffsettype = iOffsettype; - pEntry->iOffsetx = iOffsetx; - pEntry->iOffsety = iOffsety; - pEntry->iBoundarytype = iBoundarytype; - pEntry->iBoundaryl = iBoundaryl; - pEntry->iBoundaryr = iBoundaryr; - pEntry->iBoundaryt = iBoundaryt; - pEntry->iBoundaryb = iBoundaryb; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PAST_SRC, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DISC -mng_retcode MNG_DECL mng_putchunk_disc (mng_handle hHandle, - mng_uint32 iCount, - mng_uint16p pObjectids) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_DISC, mng_init_general, mng_free_disc, mng_read_disc, mng_write_disc, mng_assign_disc, 0, 0, sizeof(mng_disc)}; -#else - {MNG_UINT_DISC, mng_init_disc, mng_free_disc, mng_read_disc, mng_write_disc, mng_assign_disc, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DISC, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_DISC)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_disc (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_DISC, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_discp)pChunk)->iCount = iCount; - - if (iCount) - { - mng_uint32 iSize = iCount * sizeof (mng_uint32); - - MNG_ALLOC (pData, ((mng_discp)pChunk)->pObjectids, iSize); - MNG_COPY (((mng_discp)pChunk)->pObjectids, pObjectids, iSize); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DISC, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_BACK -mng_retcode MNG_DECL mng_putchunk_back (mng_handle hHandle, - mng_uint16 iRed, - mng_uint16 iGreen, - mng_uint16 iBlue, - mng_uint8 iMandatory, - mng_uint16 iImageid, - mng_uint8 iTile) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_BACK, mng_init_general, mng_free_general, mng_read_back, mng_write_back, mng_assign_general, 0, 0, sizeof(mng_back)}; -#else - {MNG_UINT_BACK, mng_init_back, mng_free_back, mng_read_back, mng_write_back, mng_assign_back, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_BACK, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_BACK)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_back (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_BACK, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_backp)pChunk)->iRed = iRed; - ((mng_backp)pChunk)->iGreen = iGreen; - ((mng_backp)pChunk)->iBlue = iBlue; - ((mng_backp)pChunk)->iMandatory = iMandatory; - ((mng_backp)pChunk)->iImageid = iImageid; - ((mng_backp)pChunk)->iTile = iTile; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_BACK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_FRAM -mng_retcode MNG_DECL mng_putchunk_fram (mng_handle hHandle, - mng_bool bEmpty, - mng_uint8 iMode, - mng_uint32 iNamesize, - mng_pchar zName, - mng_uint8 iChangedelay, - mng_uint8 iChangetimeout, - mng_uint8 iChangeclipping, - mng_uint8 iChangesyncid, - mng_uint32 iDelay, - mng_uint32 iTimeout, - mng_uint8 iBoundarytype, - mng_int32 iBoundaryl, - mng_int32 iBoundaryr, - mng_int32 iBoundaryt, - mng_int32 iBoundaryb, - mng_uint32 iCount, - mng_uint32p pSyncids) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_FRAM, mng_init_general, mng_free_fram, mng_read_fram, mng_write_fram, mng_assign_fram, 0, 0, sizeof(mng_fram)}; -#else - {MNG_UINT_FRAM, mng_init_fram, mng_free_fram, mng_read_fram, mng_write_fram, mng_assign_fram, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_FRAM, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_FRAM)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_fram (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_FRAM, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_framp)pChunk)->bEmpty = bEmpty; - ((mng_framp)pChunk)->iMode = iMode; - ((mng_framp)pChunk)->iNamesize = iNamesize; - ((mng_framp)pChunk)->iChangedelay = iChangedelay; - ((mng_framp)pChunk)->iChangetimeout = iChangetimeout; - ((mng_framp)pChunk)->iChangeclipping = iChangeclipping; - ((mng_framp)pChunk)->iChangesyncid = iChangesyncid; - ((mng_framp)pChunk)->iDelay = iDelay; - ((mng_framp)pChunk)->iTimeout = iTimeout; - ((mng_framp)pChunk)->iBoundarytype = iBoundarytype; - ((mng_framp)pChunk)->iBoundaryl = iBoundaryl; - ((mng_framp)pChunk)->iBoundaryr = iBoundaryr; - ((mng_framp)pChunk)->iBoundaryt = iBoundaryt; - ((mng_framp)pChunk)->iBoundaryb = iBoundaryb; - ((mng_framp)pChunk)->iCount = iCount; - - if (iNamesize) - { - MNG_ALLOC (pData, ((mng_framp)pChunk)->zName, iNamesize + 1); - MNG_COPY (((mng_framp)pChunk)->zName, zName, iNamesize); - } - - if (iCount) - { - mng_uint32 iSize = iCount * sizeof (mng_uint32); - - MNG_ALLOC (pData, ((mng_framp)pChunk)->pSyncids, iSize); - MNG_COPY (((mng_framp)pChunk)->pSyncids, pSyncids, iSize); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_FRAM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MOVE -mng_retcode MNG_DECL mng_putchunk_move (mng_handle hHandle, - mng_uint16 iFirstid, - mng_uint16 iLastid, - mng_uint8 iMovetype, - mng_int32 iMovex, - mng_int32 iMovey) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_MOVE, mng_init_general, mng_free_general, mng_read_move, mng_write_move, mng_assign_general, 0, 0, sizeof(mng_move)}; -#else - {MNG_UINT_MOVE, mng_init_move, mng_free_move, mng_read_move, mng_write_move, mng_assign_move, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MOVE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_MOVE)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_move (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_MOVE, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_movep)pChunk)->iFirstid = iFirstid; - ((mng_movep)pChunk)->iLastid = iLastid; - ((mng_movep)pChunk)->iMovetype = iMovetype; - ((mng_movep)pChunk)->iMovex = iMovex; - ((mng_movep)pChunk)->iMovey = iMovey; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MOVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_CLIP -mng_retcode MNG_DECL mng_putchunk_clip (mng_handle hHandle, - mng_uint16 iFirstid, - mng_uint16 iLastid, - mng_uint8 iCliptype, - mng_int32 iClipl, - mng_int32 iClipr, - mng_int32 iClipt, - mng_int32 iClipb) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_CLIP, mng_init_general, mng_free_general, mng_read_clip, mng_write_clip, mng_assign_general, 0, 0, sizeof(mng_clip)}; -#else - {MNG_UINT_CLIP, mng_init_clip, mng_free_clip, mng_read_clip, mng_write_clip, mng_assign_clip, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_CLIP, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_CLIP)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_clip (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_CLIP, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_clipp)pChunk)->iFirstid = iFirstid; - ((mng_clipp)pChunk)->iLastid = iLastid; - ((mng_clipp)pChunk)->iCliptype = iCliptype; - ((mng_clipp)pChunk)->iClipl = iClipl; - ((mng_clipp)pChunk)->iClipr = iClipr; - ((mng_clipp)pChunk)->iClipt = iClipt; - ((mng_clipp)pChunk)->iClipb = iClipb; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_CLIP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SHOW -mng_retcode MNG_DECL mng_putchunk_show (mng_handle hHandle, - mng_bool bEmpty, - mng_uint16 iFirstid, - mng_uint16 iLastid, - mng_uint8 iMode) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_SHOW, mng_init_general, mng_free_general, mng_read_show, mng_write_show, mng_assign_general, 0, 0, sizeof(mng_show)}; -#else - {MNG_UINT_SHOW, mng_init_show, mng_free_show, mng_read_show, mng_write_show, mng_assign_show, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SHOW, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_SHOW)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_show (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_SHOW, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_showp)pChunk)->bEmpty = bEmpty; - ((mng_showp)pChunk)->iFirstid = iFirstid; - ((mng_showp)pChunk)->iLastid = iLastid; - ((mng_showp)pChunk)->iMode = iMode; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SHOW, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_TERM -mng_retcode MNG_DECL mng_putchunk_term (mng_handle hHandle, - mng_uint8 iTermaction, - mng_uint8 iIteraction, - mng_uint32 iDelay, - mng_uint32 iItermax) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_TERM, mng_init_general, mng_free_general, mng_read_term, mng_write_term, mng_assign_general, 0, 0, sizeof(mng_term)}; -#else - {MNG_UINT_TERM, mng_init_term, mng_free_term, mng_read_term, mng_write_term, mng_assign_term, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TERM, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_term (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_TERM, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_termp)pChunk)->iTermaction = iTermaction; - ((mng_termp)pChunk)->iIteraction = iIteraction; - ((mng_termp)pChunk)->iDelay = iDelay; - ((mng_termp)pChunk)->iItermax = iItermax; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TERM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SAVE -mng_retcode MNG_DECL mng_putchunk_save (mng_handle hHandle, - mng_bool bEmpty, - mng_uint8 iOffsettype, - mng_uint32 iCount) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_SAVE, mng_init_general, mng_free_save, mng_read_save, mng_write_save, mng_assign_save, 0, 0, sizeof(mng_save)}; -#else - {MNG_UINT_SAVE, mng_init_save, mng_free_save, mng_read_save, mng_write_save, mng_assign_save, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SAVE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_SAVE)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_save (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_SAVE, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_savep)pChunk)->bEmpty = bEmpty; - ((mng_savep)pChunk)->iOffsettype = iOffsettype; - ((mng_savep)pChunk)->iCount = iCount; - - if (iCount) - MNG_ALLOC (pData, ((mng_savep)pChunk)->pEntries, iCount * sizeof (mng_save_entry)); - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SAVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_putchunk_save_entry (mng_handle hHandle, - mng_uint32 iEntry, - mng_uint8 iEntrytype, - mng_uint32arr2 iOffset, - mng_uint32arr2 iStarttime, - mng_uint32 iLayernr, - mng_uint32 iFramenr, - mng_uint32 iNamesize, - mng_pchar zName) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_save_entryp pEntry; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SAVE_ENTRY, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - - pChunk = pData->pLastchunk; /* last one must have been SAVE ! */ - - if (((mng_chunk_headerp)pChunk)->iChunkname != MNG_UINT_SAVE) - MNG_ERROR (pData, MNG_NOCORRCHUNK) - /* index out of bounds ? */ - if (iEntry >= ((mng_savep)pChunk)->iCount) - MNG_ERROR (pData, MNG_INVALIDENTRYIX) - /* address proper entry */ - pEntry = ((mng_savep)pChunk)->pEntries + iEntry; - - pEntry->iEntrytype = iEntrytype; /* fill entry */ - pEntry->iOffset[0] = iOffset[0]; - pEntry->iOffset[1] = iOffset[1]; - pEntry->iStarttime[0] = iStarttime[0]; - pEntry->iStarttime[1] = iStarttime[1]; - pEntry->iLayernr = iLayernr; - pEntry->iFramenr = iFramenr; - pEntry->iNamesize = iNamesize; - - if (iNamesize) - { - MNG_ALLOC (pData, pEntry->zName, iNamesize + 1); - MNG_COPY (pEntry->zName, zName, iNamesize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SAVE_ENTRY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SEEK -mng_retcode MNG_DECL mng_putchunk_seek (mng_handle hHandle, - mng_uint32 iNamesize, - mng_pchar zName) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_SEEK, mng_init_general, mng_free_seek, mng_read_seek, mng_write_seek, mng_assign_seek, 0, 0, sizeof(mng_seek)}; -#else - {MNG_UINT_SEEK, mng_init_seek, mng_free_seek, mng_read_seek, mng_write_seek, mng_assign_seek, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SEEK, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_SEEK)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_seek (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_SEEK, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_seekp)pChunk)->iNamesize = iNamesize; - - if (iNamesize) - { - MNG_ALLOC (pData, ((mng_seekp)pChunk)->zName, iNamesize + 1); - MNG_COPY (((mng_seekp)pChunk)->zName, zName, iNamesize); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SEEK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_eXPI -mng_retcode MNG_DECL mng_putchunk_expi (mng_handle hHandle, - mng_uint16 iSnapshotid, - mng_uint32 iNamesize, - mng_pchar zName) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_eXPI, mng_init_general, mng_free_expi, mng_read_expi, mng_write_expi, mng_assign_general, 0, 0, sizeof(mng_expi)}; -#else - {MNG_UINT_eXPI, mng_init_expi, mng_free_expi, mng_read_expi, mng_write_expi, mng_assign_expi, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_EXPI, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_eXPI)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_expi (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_eXPI, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_expip)pChunk)->iSnapshotid = iSnapshotid; - ((mng_expip)pChunk)->iNamesize = iNamesize; - - if (iNamesize) - { - MNG_ALLOC (pData, ((mng_expip)pChunk)->zName, iNamesize + 1); - MNG_COPY (((mng_expip)pChunk)->zName, zName, iNamesize); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_EXPI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_fPRI -mng_retcode MNG_DECL mng_putchunk_fpri (mng_handle hHandle, - mng_uint8 iDeltatype, - mng_uint8 iPriority) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_fPRI, mng_init_general, mng_free_general, mng_read_fpri, mng_write_fpri, mng_assign_general, 0, 0, sizeof(mng_fpri)}; -#else - {MNG_UINT_fPRI, mng_init_fpri, mng_free_fpri, mng_read_fpri, mng_write_fpri, mng_assign_fpri, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_FPRI, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_fPRI)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_fpri (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_fPRI, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_fprip)pChunk)->iDeltatype = iDeltatype; - ((mng_fprip)pChunk)->iPriority = iPriority; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_FPRI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_nEED -mng_retcode MNG_DECL mng_putchunk_need (mng_handle hHandle, - mng_uint32 iKeywordssize, - mng_pchar zKeywords) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_nEED, mng_init_general, mng_free_need, mng_read_need, mng_write_need, mng_assign_need, 0, 0, sizeof(mng_need)}; -#else - {MNG_UINT_nEED, mng_init_need, mng_free_need, mng_read_need, mng_write_need, mng_assign_need, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_NEED, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_nEED)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_need (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_nEED, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_needp)pChunk)->iKeywordssize = iKeywordssize; - - if (iKeywordssize) - { - MNG_ALLOC (pData, ((mng_needp)pChunk)->zKeywords, iKeywordssize + 1); - MNG_COPY (((mng_needp)pChunk)->zKeywords, zKeywords, iKeywordssize); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_NEED, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_pHYg -mng_retcode MNG_DECL mng_putchunk_phyg (mng_handle hHandle, - mng_bool bEmpty, - mng_uint32 iSizex, - mng_uint32 iSizey, - mng_uint8 iUnit) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_pHYg, mng_init_general, mng_free_general, mng_read_phyg, mng_write_phyg, mng_assign_general, 0, 0, sizeof(mng_phyg)}; -#else - {MNG_UINT_pHYg, mng_init_phyg, mng_free_phyg, mng_read_phyg, mng_write_phyg, mng_assign_phyg, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PHYG, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_pHYg)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_phyg (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_pHYg, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_phygp)pChunk)->bEmpty = bEmpty; - ((mng_phygp)pChunk)->iSizex = iSizex; - ((mng_phygp)pChunk)->iSizey = iSizey; - ((mng_phygp)pChunk)->iUnit = iUnit; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PHYG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG - -mng_retcode MNG_DECL mng_putchunk_jhdr (mng_handle hHandle, - mng_uint32 iWidth, - mng_uint32 iHeight, - mng_uint8 iColortype, - mng_uint8 iImagesampledepth, - mng_uint8 iImagecompression, - mng_uint8 iImageinterlace, - mng_uint8 iAlphasampledepth, - mng_uint8 iAlphacompression, - mng_uint8 iAlphafilter, - mng_uint8 iAlphainterlace) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_JHDR, mng_init_general, mng_free_general, mng_read_jhdr, mng_write_jhdr, mng_assign_general, 0, 0, sizeof(mng_jhdr)}; -#else - {MNG_UINT_JHDR, mng_init_jhdr, mng_free_jhdr, mng_read_jhdr, mng_write_jhdr, mng_assign_jhdr, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JHDR, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_JHDR)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_jhdr (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_JHDR, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_jhdrp)pChunk)->iWidth = iWidth; - ((mng_jhdrp)pChunk)->iHeight = iHeight; - ((mng_jhdrp)pChunk)->iColortype = iColortype; - ((mng_jhdrp)pChunk)->iImagesampledepth = iImagesampledepth; - ((mng_jhdrp)pChunk)->iImagecompression = iImagecompression; - ((mng_jhdrp)pChunk)->iImageinterlace = iImageinterlace; - ((mng_jhdrp)pChunk)->iAlphasampledepth = iAlphasampledepth; - ((mng_jhdrp)pChunk)->iAlphacompression = iAlphacompression; - ((mng_jhdrp)pChunk)->iAlphafilter = iAlphafilter; - ((mng_jhdrp)pChunk)->iAlphainterlace = iAlphainterlace; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG - -mng_retcode MNG_DECL mng_putchunk_jdat (mng_handle hHandle, - mng_uint32 iRawlen, - mng_ptr pRawdata) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_JDAT, mng_init_general, mng_free_jdat, mng_read_jdat, mng_write_jdat, mng_assign_jdat, 0, 0, sizeof(mng_jdat)}; -#else - {MNG_UINT_JDAT, mng_init_jdat, mng_free_jdat, mng_read_jdat, mng_write_jdat, mng_assign_jdat, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JDAT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR or JHDR first! */ - if ((pData->iFirstchunkadded != MNG_UINT_MHDR) && - (pData->iFirstchunkadded != MNG_UINT_JHDR) ) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_JDAT)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_jdat (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_JDAT, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_jdatp)pChunk)->iDatasize = iRawlen; - - if (iRawlen) - { - MNG_ALLOC (pData, ((mng_jdatp)pChunk)->pData, iRawlen); - MNG_COPY (((mng_jdatp)pChunk)->pData, pRawdata, iRawlen); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JDAT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG - -mng_retcode MNG_DECL mng_putchunk_jdaa (mng_handle hHandle, - mng_uint32 iRawlen, - mng_ptr pRawdata) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_JDAA, mng_init_general, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0, sizeof(mng_jdaa)}; -#else - {MNG_UINT_JDAA, mng_init_jdaa, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JDAA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR or JHDR first! */ - if ((pData->iFirstchunkadded != MNG_UINT_MHDR) && - (pData->iFirstchunkadded != MNG_UINT_JHDR) ) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_JDAA)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_jdaa (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_JDAA, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_jdaap)pChunk)->iDatasize = iRawlen; - - if (iRawlen) - { - MNG_ALLOC (pData, ((mng_jdaap)pChunk)->pData, iRawlen); - MNG_COPY (((mng_jdaap)pChunk)->pData, pRawdata, iRawlen); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JDAA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG - -mng_retcode MNG_DECL mng_putchunk_jsep (mng_handle hHandle) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_JSEP, mng_init_general, mng_free_general, mng_read_jsep, mng_write_jsep, mng_assign_general, 0, 0, sizeof(mng_jsep)}; -#else - {MNG_UINT_JSEP, mng_init_jsep, mng_free_jsep, mng_read_jsep, mng_write_jsep, mng_assign_jsep, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JSEP, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR or JHDR first! */ - if ((pData->iFirstchunkadded != MNG_UINT_MHDR) && - (pData->iFirstchunkadded != MNG_UINT_JHDR) ) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_JSEP)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_jsep (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_JSEP, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JSEP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode MNG_DECL mng_putchunk_dhdr (mng_handle hHandle, - mng_uint16 iObjectid, - mng_uint8 iImagetype, - mng_uint8 iDeltatype, - mng_uint32 iBlockwidth, - mng_uint32 iBlockheight, - mng_uint32 iBlockx, - mng_uint32 iBlocky) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_DHDR, mng_init_general, mng_free_general, mng_read_dhdr, mng_write_dhdr, mng_assign_general, 0, 0, sizeof(mng_dhdr)}; -#else - {MNG_UINT_DHDR, mng_init_dhdr, mng_free_dhdr, mng_read_dhdr, mng_write_dhdr, mng_assign_dhdr, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DHDR, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_DHDR)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_dhdr (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_DHDR, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_dhdrp)pChunk)->iObjectid = iObjectid; - ((mng_dhdrp)pChunk)->iImagetype = iImagetype; - ((mng_dhdrp)pChunk)->iDeltatype = iDeltatype; - ((mng_dhdrp)pChunk)->iBlockwidth = iBlockwidth; - ((mng_dhdrp)pChunk)->iBlockheight = iBlockheight; - ((mng_dhdrp)pChunk)->iBlockx = iBlockx; - ((mng_dhdrp)pChunk)->iBlocky = iBlocky; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode MNG_DECL mng_putchunk_prom (mng_handle hHandle, - mng_uint8 iColortype, - mng_uint8 iSampledepth, - mng_uint8 iFilltype) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_PROM, mng_init_general, mng_free_general, mng_read_prom, mng_write_prom, mng_assign_general, 0, 0, sizeof(mng_prom)}; -#else - {MNG_UINT_PROM, mng_init_prom, mng_free_prom, mng_read_prom, mng_write_prom, mng_assign_prom, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PROM, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_PROM)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_prom (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_PROM, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_promp)pChunk)->iColortype = iColortype; - ((mng_promp)pChunk)->iSampledepth = iSampledepth; - ((mng_promp)pChunk)->iFilltype = iFilltype; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PROM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode MNG_DECL mng_putchunk_ipng (mng_handle hHandle) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_IPNG, mng_init_general, mng_free_general, mng_read_ipng, mng_write_ipng, mng_assign_general, 0, 0, sizeof(mng_ipng)}; -#else - {MNG_UINT_IPNG, mng_init_ipng, mng_free_ipng, mng_read_ipng, mng_write_ipng, mng_assign_ipng, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IPNG, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_IPNG)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_ipng (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_IPNG, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IPNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode MNG_DECL mng_putchunk_pplt (mng_handle hHandle, - mng_uint8 iDeltatype, - mng_uint32 iCount) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_PPLT, mng_init_general, mng_free_general, mng_read_pplt, mng_write_pplt, mng_assign_general, 0, 0, sizeof(mng_pplt)}; -#else - {MNG_UINT_PPLT, mng_init_pplt, mng_free_pplt, mng_read_pplt, mng_write_pplt, mng_assign_pplt, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PPLT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_PPLT)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_pplt (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_PPLT, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_ppltp)pChunk)->iDeltatype = iDeltatype; - ((mng_ppltp)pChunk)->iCount = iCount; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PPLT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode MNG_DECL mng_putchunk_pplt_entry (mng_handle hHandle, - mng_uint32 iEntry, - mng_uint16 iRed, - mng_uint16 iGreen, - mng_uint16 iBlue, - mng_uint16 iAlpha) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_pplt_entryp pEntry; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PPLT_ENTRY, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - - pChunk = pData->pLastchunk; /* last one must have been PPLT ! */ - - if (((mng_chunk_headerp)pChunk)->iChunkname != MNG_UINT_PPLT) - MNG_ERROR (pData, MNG_NOCORRCHUNK) - - /* index out of bounds ? */ - if (iEntry >= ((mng_ppltp)pChunk)->iCount) - MNG_ERROR (pData, MNG_INVALIDENTRYIX) - /* address proper entry */ - pEntry = (mng_pplt_entryp)(((mng_ppltp)pChunk)->aEntries) + iEntry; - - pEntry->iRed = (mng_uint8)iRed; /* fill the entry */ - pEntry->iGreen = (mng_uint8)iGreen; - pEntry->iBlue = (mng_uint8)iBlue; - pEntry->iAlpha = (mng_uint8)iAlpha; - pEntry->bUsed = MNG_TRUE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PPLT_ENTRY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG -mng_retcode MNG_DECL mng_putchunk_ijng (mng_handle hHandle) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_IJNG, mng_init_general, mng_free_general, mng_read_ijng, mng_write_ijng, mng_assign_general, 0, 0, sizeof(mng_ijng)}; -#else - {MNG_UINT_IJNG, mng_init_ijng, mng_free_ijng, mng_read_ijng, mng_write_ijng, mng_assign_ijng, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IJNG, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_IJNG)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_ijng (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_IJNG, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IJNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode MNG_DECL mng_putchunk_drop (mng_handle hHandle, - mng_uint32 iCount, - mng_chunkidp pChunknames) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_DROP, mng_init_general, mng_free_drop, mng_read_drop, mng_write_drop, mng_assign_drop, 0, 0, sizeof(mng_drop)}; -#else - {MNG_UINT_DROP, mng_init_drop, mng_free_drop, mng_read_drop, mng_write_drop, mng_assign_drop, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DROP, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_DROP)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_drop (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_DROP, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_dropp)pChunk)->iCount = iCount; - - if (iCount) - { - mng_uint32 iSize = iCount * sizeof (mng_chunkid); - - MNG_ALLOC (pData, ((mng_dropp)pChunk)->pChunknames, iSize); - MNG_COPY (((mng_dropp)pChunk)->pChunknames, pChunknames, iSize); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DROP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DBYK -mng_retcode MNG_DECL mng_putchunk_dbyk (mng_handle hHandle, - mng_chunkid iChunkname, - mng_uint8 iPolarity, - mng_uint32 iKeywordssize, - mng_pchar zKeywords) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_DBYK, mng_init_general, mng_free_dbyk, mng_read_dbyk, mng_write_dbyk, mng_assign_dbyk, 0, 0, sizeof(mng_dbyk)}; -#else - {MNG_UINT_DBYK, mng_init_dbyk, mng_free_dbyk, mng_read_dbyk, mng_write_dbyk, mng_assign_dbyk, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DBYK, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_DBYK)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_dbyk (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_DBYK, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_dbykp)pChunk)->iChunkname = iChunkname; - ((mng_dbykp)pChunk)->iPolarity = iPolarity; - ((mng_dbykp)pChunk)->iKeywordssize = iKeywordssize; - - if (iKeywordssize) - { - MNG_ALLOC (pData, ((mng_dbykp)pChunk)->zKeywords, iKeywordssize + 1); - MNG_COPY (((mng_dbykp)pChunk)->zKeywords, zKeywords, iKeywordssize); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DBYK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR -mng_retcode MNG_DECL mng_putchunk_ordr (mng_handle hHandle, - mng_uint32 iCount) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_ORDR, mng_init_general, mng_free_ordr, mng_read_ordr, mng_write_ordr, mng_assign_ordr, 0, 0, sizeof(mng_ordr)}; -#else - {MNG_UINT_ORDR, mng_init_ordr, mng_free_ordr, mng_read_ordr, mng_write_ordr, mng_assign_ordr, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ORDR, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_ORDR)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_ordr (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_ORDR, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_ordrp)pChunk)->iCount = iCount; - - if (iCount) - MNG_ALLOC (pData, ((mng_ordrp)pChunk)->pEntries, iCount * sizeof (mng_ordr_entry)); - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ORDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR -mng_retcode MNG_DECL mng_putchunk_ordr_entry (mng_handle hHandle, - mng_uint32 iEntry, - mng_chunkid iChunkname, - mng_uint8 iOrdertype) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_ordr_entryp pEntry; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ORDR_ENTRY, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - - pChunk = pData->pLastchunk; /* last one must have been ORDR ! */ - - if (((mng_chunk_headerp)pChunk)->iChunkname != MNG_UINT_ORDR) - MNG_ERROR (pData, MNG_NOCORRCHUNK) - /* index out of bounds ? */ - if (iEntry >= ((mng_ordrp)pChunk)->iCount) - MNG_ERROR (pData, MNG_INVALIDENTRYIX) - /* address proper entry */ - pEntry = ((mng_ordrp)pChunk)->pEntries + iEntry; - - pEntry->iChunkname = iChunkname; /* fill the entry */ - pEntry->iOrdertype = iOrdertype; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ORDR_ENTRY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MAGN -mng_retcode MNG_DECL mng_putchunk_magn (mng_handle hHandle, - mng_uint16 iFirstid, - mng_uint16 iLastid, - mng_uint16 iMethodX, - mng_uint16 iMX, - mng_uint16 iMY, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint16 iMT, - mng_uint16 iMB, - mng_uint16 iMethodY) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_MAGN, mng_init_general, mng_free_general, mng_read_magn, mng_write_magn, mng_assign_general, 0, 0, sizeof(mng_magn)}; -#else - {MNG_UINT_MAGN, mng_init_magn, mng_free_magn, mng_read_magn, mng_write_magn, mng_assign_magn, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MAGN, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_MAGN)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_magn (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_MAGN, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_magnp)pChunk)->iFirstid = iFirstid; - ((mng_magnp)pChunk)->iLastid = iLastid; - ((mng_magnp)pChunk)->iMethodX = (mng_uint8)iMethodX; - ((mng_magnp)pChunk)->iMX = iMX; - ((mng_magnp)pChunk)->iMY = iMY; - ((mng_magnp)pChunk)->iML = iML; - ((mng_magnp)pChunk)->iMR = iMR; - ((mng_magnp)pChunk)->iMT = iMT; - ((mng_magnp)pChunk)->iMB = iMB; - ((mng_magnp)pChunk)->iMethodY = (mng_uint8)iMethodY; - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MAGN, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_MPNG_PROPOSAL -MNG_EXT mng_retcode MNG_DECL mng_putchunk_mpng (mng_handle hHandle, - mng_uint32 iFramewidth, - mng_uint32 iFrameheight, - mng_uint16 iNumplays, - mng_uint16 iTickspersec, - mng_uint8 iCompressionmethod, - mng_uint32 iCount) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_mpNG, mng_init_general, mng_free_mpng, mng_read_mpng, mng_write_mpng, mng_assign_mpng, 0, 0, sizeof(mng_mpng)}; -#else - {MNG_UINT_mpNG, mng_init_mpng, mng_free_mpng, mng_read_mpng, mng_write_mpng, mng_assign_mpng, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MPNG, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a IHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_IHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_mpng (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_mpNG, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_mpngp)pChunk)->iFramewidth = iFramewidth; - ((mng_mpngp)pChunk)->iFrameheight = iFrameheight; - ((mng_mpngp)pChunk)->iNumplays = iNumplays; - ((mng_mpngp)pChunk)->iTickspersec = iTickspersec; - ((mng_mpngp)pChunk)->iCompressionmethod = iCompressionmethod; - ((mng_mpngp)pChunk)->iFramessize = iCount * sizeof (mng_mpng_frame); - - if (iCount) - MNG_ALLOC (pData, ((mng_mpngp)pChunk)->pFrames, ((mng_mpngp)pChunk)->iFramessize); - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MPNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_MPNG_PROPOSAL -MNG_EXT mng_retcode MNG_DECL mng_putchunk_mpng_frame (mng_handle hHandle, - mng_uint32 iEntry, - mng_uint32 iX, - mng_uint32 iY, - mng_uint32 iWidth, - mng_uint32 iHeight, - mng_int32 iXoffset, - mng_int32 iYoffset, - mng_uint16 iTicks) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_mpng_framep pFrame; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MPNG_FRAME, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a IHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_IHDR) - MNG_ERROR (pData, MNG_NOHEADER) - - pChunk = pData->pLastchunk; /* last one must have been mpNG ! */ - - if (((mng_chunk_headerp)pChunk)->iChunkname != MNG_UINT_mpNG) - MNG_ERROR (pData, MNG_NOCORRCHUNK) - /* index out of bounds ? */ - if (iEntry >= (((mng_mpngp)pChunk)->iFramessize / sizeof (mng_mpng_frame))) - MNG_ERROR (pData, MNG_INVALIDENTRYIX) - /* address proper entry */ - pFrame = ((mng_mpngp)pChunk)->pFrames + iEntry; - /* fill entry */ - pFrame->iX = iX; - pFrame->iY = iY; - pFrame->iWidth = iWidth; - pFrame->iHeight = iHeight; - pFrame->iXoffset = iXoffset; - pFrame->iYoffset = iYoffset; - pFrame->iTicks = iTicks; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MPNG_FRAME, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_evNT -mng_retcode MNG_DECL mng_putchunk_evnt (mng_handle hHandle, - mng_uint32 iCount) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_evNT, mng_init_general, mng_free_evnt, mng_read_evnt, mng_write_evnt, mng_assign_evnt, 0, 0, sizeof(mng_evnt)}; -#else - {MNG_UINT_evNT, mng_init_evnt, mng_free_evnt, mng_read_evnt, mng_write_evnt, mng_assign_evnt, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_EVNT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, MNG_UINT_evNT)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_evnt (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_evNT, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_evntp)pChunk)->iCount = iCount; - - if (iCount) - MNG_ALLOC (pData, ((mng_evntp)pChunk)->pEntries, iCount * sizeof (mng_evnt_entry)); - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_EVNT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_putchunk_evnt_entry (mng_handle hHandle, - mng_uint32 iEntry, - mng_uint8 iEventtype, - mng_uint8 iMasktype, - mng_int32 iLeft, - mng_int32 iRight, - mng_int32 iTop, - mng_int32 iBottom, - mng_uint16 iObjectid, - mng_uint8 iIndex, - mng_uint32 iSegmentnamesize, - mng_pchar zSegmentname) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_evnt_entryp pEntry; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_EVNT_ENTRY, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a MHDR first! */ - if (pData->iFirstchunkadded != MNG_UINT_MHDR) - MNG_ERROR (pData, MNG_NOHEADER) - - pChunk = pData->pLastchunk; /* last one must have been evNT ! */ - - if (((mng_chunk_headerp)pChunk)->iChunkname != MNG_UINT_evNT) - MNG_ERROR (pData, MNG_NOCORRCHUNK) - /* index out of bounds ? */ - if (iEntry >= ((mng_evntp)pChunk)->iCount) - MNG_ERROR (pData, MNG_INVALIDENTRYIX) - /* address proper entry */ - pEntry = ((mng_evntp)pChunk)->pEntries + iEntry; - /* fill entry */ - pEntry->iEventtype = iEventtype; - pEntry->iMasktype = iMasktype; - pEntry->iLeft = iLeft; - pEntry->iRight = iRight; - pEntry->iTop = iTop; - pEntry->iBottom = iBottom; - pEntry->iObjectid = iObjectid; - pEntry->iIndex = iIndex; - pEntry->iSegmentnamesize = iSegmentnamesize; - - if (iSegmentnamesize) - { - MNG_ALLOC (pData, pEntry->zSegmentname, iSegmentnamesize + 1); - MNG_COPY (pEntry->zSegmentname, zSegmentname, iSegmentnamesize); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_EVNT_ENTRY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_putchunk_unknown (mng_handle hHandle, - mng_chunkid iChunkname, - mng_uint32 iRawlen, - mng_ptr pRawdata) -{ - mng_datap pData; - mng_chunkp pChunk; - mng_retcode iRetcode; -#ifndef MNG_OPTIMIZE_CHUNKREADER - mng_chunk_header sChunkheader = -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - {MNG_UINT_HUH, mng_init_general, mng_free_unknown, mng_read_unknown, mng_write_unknown, mng_assign_unknown, 0, 0, sizeof(mng_unknown_chunk)}; -#else - {MNG_UINT_HUH, mng_init_unknown, mng_free_unknown, mng_read_unknown, mng_write_unknown, mng_assign_unknown, 0, 0}; -#endif -#else - mng_chunk_header sChunkheader; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_UNKNOWN, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must have had a header first! */ - if (pData->iFirstchunkadded == 0) - MNG_ERROR (pData, MNG_NOHEADER) - /* prevent misplaced TERM ! */ - if (!check_term (pData, iChunkname)) - MNG_ERROR (pData, MNG_TERMSEQERROR) - /* create the chunk */ -#ifndef MNG_OPTIMIZE_CHUNKREADER -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#else - iRetcode = mng_init_unknown (pData, &sChunkheader, &pChunk); -#endif -#else - mng_get_chunkheader(MNG_UINT_HUH, &sChunkheader); - iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fill the chunk */ - ((mng_unknown_chunkp)pChunk)->sHeader.iChunkname = iChunkname; - ((mng_unknown_chunkp)pChunk)->iDatasize = iRawlen; - - if (iRawlen) - { - MNG_ALLOC (pData, ((mng_unknown_chunkp)pChunk)->pData, iRawlen); - MNG_COPY (((mng_unknown_chunkp)pChunk)->pData, pRawdata, iRawlen); - } - - mng_add_chunk (pData, pChunk); /* add it to the list */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_UNKNOWN, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_WRITE_PROCS */ - -/* ************************************************************************** */ -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_getimgdata_seq (mng_handle hHandle, - mng_uint32 iSeqnr, - mng_uint32 iCanvasstyle, - mng_getcanvasline fGetcanvasline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETIMGDATA_SEQ, MNG_LC_START); -#endif - - - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETIMGDATA_SEQ, MNG_LC_END); -#endif - - return MNG_FNNOTIMPLEMENTED; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_getimgdata_chunkseq (mng_handle hHandle, - mng_uint32 iSeqnr, - mng_uint32 iCanvasstyle, - mng_getcanvasline fGetcanvasline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETIMGDATA_CHUNKSEQ, MNG_LC_START); -#endif - - - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETIMGDATA_CHUNKSEQ, MNG_LC_END); -#endif - - return MNG_FNNOTIMPLEMENTED; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_getimgdata_chunk (mng_handle hHandle, - mng_handle hChunk, - mng_uint32 iCanvasstyle, - mng_getcanvasline fGetcanvasline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETIMGDATA_CHUNK, MNG_LC_START); -#endif - - - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETIMGDATA_CHUNK, MNG_LC_END); -#endif - - return MNG_FNNOTIMPLEMENTED; -} - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_WRITE_PROCS - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_putimgdata_ihdr (mng_handle hHandle, - mng_uint32 iWidth, - mng_uint32 iHeight, - mng_uint8 iColortype, - mng_uint8 iBitdepth, - mng_uint8 iCompression, - mng_uint8 iFilter, - mng_uint8 iInterlace, - mng_uint32 iCanvasstyle, - mng_getcanvasline fGetcanvasline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTIMGDATA_IHDR, MNG_LC_START); -#endif - - - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTIMGDATA_IHDR, MNG_LC_END); -#endif - - return MNG_FNNOTIMPLEMENTED; -} - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -mng_retcode MNG_DECL mng_putimgdata_jhdr (mng_handle hHandle, - mng_uint32 iWidth, - mng_uint32 iHeight, - mng_uint8 iColortype, - mng_uint8 iBitdepth, - mng_uint8 iCompression, - mng_uint8 iInterlace, - mng_uint8 iAlphaBitdepth, - mng_uint8 iAlphaCompression, - mng_uint8 iAlphaFilter, - mng_uint8 iAlphaInterlace, - mng_uint32 iCanvasstyle, - mng_getcanvasline fGetcanvasline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTIMGDATA_JHDR, MNG_LC_START); -#endif - - - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTIMGDATA_JHDR, MNG_LC_END); -#endif - - return MNG_FNNOTIMPLEMENTED; -} -#endif - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_updatemngheader (mng_handle hHandle, - mng_uint32 iFramecount, - mng_uint32 iLayercount, - mng_uint32 iPlaytime) -{ - mng_datap pData; - mng_chunkp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_UPDATEMNGHEADER, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must be a MNG animation! */ - if ((pData->eImagetype != mng_it_mng) || (pData->iFirstchunkadded != MNG_UINT_MHDR)) - MNG_ERROR (pData, MNG_NOMHDR) - - pChunk = pData->pFirstchunk; /* get the first chunk */ - /* and update the variables */ - ((mng_mhdrp)pChunk)->iFramecount = iFramecount; - ((mng_mhdrp)pChunk)->iLayercount = iLayercount; - ((mng_mhdrp)pChunk)->iPlaytime = iPlaytime; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_UPDATEMNGHEADER, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_updatemngsimplicity (mng_handle hHandle, - mng_uint32 iSimplicity) -{ - mng_datap pData; - mng_chunkp pChunk; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_UPDATEMNGSIMPLICITY, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = (mng_datap)hHandle; /* and make it addressable */ - - if (!pData->bCreating) /* aren't we creating a new file ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID) - /* must be a MNG animation! */ - if ((pData->eImagetype != mng_it_mng) || (pData->iFirstchunkadded != MNG_UINT_MHDR)) - MNG_ERROR (pData, MNG_NOMHDR) - - pChunk = pData->pFirstchunk; /* get the first chunk */ - /* and update the variable */ - ((mng_mhdrp)pChunk)->iSimplicity = iSimplicity; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_UPDATEMNGSIMPLICITY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_WRITE_PROCS */ - -/* ************************************************************************** */ - -#endif /* MNG_ACCESS_CHUNKS */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - - - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_chunk_xs.c copyright (c) 2000-2007 G.Juyn * */ +/* * version : 1.0.10 * */ +/* * * */ +/* * purpose : chunk access functions (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the chunk access functions * */ +/* * * */ +/* * changes : 0.5.1 - 05/06/2000 - G.Juyn * */ +/* * - changed and filled iterate-chunk function * */ +/* * 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - fixed calling convention * */ +/* * - added getchunk functions * */ +/* * - added putchunk functions * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/11/2000 - G.Juyn * */ +/* * - added empty-chunk put-routines * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - changed trace to macro for callback error-reporting * */ +/* * 0.5.1 - 05/15/2000 - G.Juyn * */ +/* * - added getimgdata & putimgdata functions * */ +/* * * */ +/* * 0.5.2 - 05/19/2000 - G.Juyn * */ +/* * - B004 - fixed problem with MNG_SUPPORT_WRITE not defined * */ +/* * also for MNG_SUPPORT_WRITE without MNG_INCLUDE_JNG * */ +/* * - Cleaned up some code regarding mixed support * */ +/* * * */ +/* * 0.9.1 - 07/19/2000 - G.Juyn * */ +/* * - fixed creation-code * */ +/* * * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * - added function to set simplicity field * */ +/* * - fixed putchunk_unknown() function * */ +/* * * */ +/* * 0.9.3 - 08/07/2000 - G.Juyn * */ +/* * - B111300 - fixup for improved portability * */ +/* * 0.9.3 - 08/26/2000 - G.Juyn * */ +/* * - added MAGN chunk * */ +/* * 0.9.3 - 10/20/2000 - G.Juyn * */ +/* * - fixed putchunk_plte() to set bEmpty parameter * */ +/* * * */ +/* * 0.9.5 - 01/25/2001 - G.Juyn * */ +/* * - fixed some small compiler warnings (thanks Nikki) * */ +/* * * */ +/* * 1.0.5 - 09/07/2002 - G.Juyn * */ +/* * - B578940 - unimplemented functions return errorcode * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * - added HLAPI function to copy chunks * */ +/* * 1.0.5 - 09/14/2002 - G.Juyn * */ +/* * - added event handling for dynamic MNG * */ +/* * 1.0.5 - 10/07/2002 - G.Juyn * */ +/* * - added check for TERM placement during create/write * */ +/* * 1.0.5 - 11/28/2002 - G.Juyn * */ +/* * - fixed definition of iMethodX/Y for MAGN chunk * */ +/* * * */ +/* * 1.0.6 - 05/25/2003 - G.R-P * */ +/* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */ +/* * 1.0.6 - 07/07/2003 - G.R-P * */ +/* * - added MNG_NO_DELTA_PNG reduction and more SKIPCHUNK * */ +/* * optimizations * */ +/* * 1.0.6 - 07/29/2003 - G.R-P * */ +/* * - added conditionals around PAST chunk support * */ +/* * 1.0.6 - 08/17/2003 - G.R-P * */ +/* * - added conditionals around non-VLC chunk support * */ +/* * * */ +/* * 1.0.8 - 04/01/2004 - G.Juyn * */ +/* * - added missing get-/put-chunk-jdaa * */ +/* * 1.0.8 - 08/02/2004 - G.Juyn * */ +/* * - added conditional to allow easier writing of large MNG's * */ +/* * * */ +/* * 1.0.9 - 09/17/2004 - G.R-P * */ +/* * - added two more conditionals * */ +/* * 1.0.9 - 09/25/2004 - G.Juyn * */ +/* * - replaced MNG_TWEAK_LARGE_FILES with permanent solution * */ +/* * 1.0.9 - 17/14/2004 - G.Juyn * */ +/* * - fixed PPLT getchunk/putchunk routines * */ +/* * 1.0.9 - 12/05/2004 - G.Juyn * */ +/* * - added conditional MNG_OPTIMIZE_CHUNKINITFREE * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * * */ +/* * 1.0.10 - 04/08/2007 - G.Juyn * */ +/* * - added support for mPNG proposal * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_memory.h" +#include "libmng_chunks.h" +#ifdef MNG_OPTIMIZE_CHUNKREADER +#include "libmng_chunk_descr.h" +#endif +#include "libmng_chunk_prc.h" +#include "libmng_chunk_io.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ + +#ifdef MNG_ACCESS_CHUNKS + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_iterate_chunks (mng_handle hHandle, + mng_uint32 iChunkseq, + mng_iteratechunk fProc) +{ + mng_uint32 iSeq; + mng_chunkid iChunkname; + mng_datap pData; + mng_chunkp pChunk; + mng_bool bCont; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_ITERATE_CHUNKS, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + + iSeq = 0; + bCont = MNG_TRUE; + pChunk = pData->pFirstchunk; /* get the first chunk */ + /* as long as there are some more */ + while ((pChunk) && (bCont)) /* and the app didn't signal a stop */ + { + if (iSeq >= iChunkseq) /* reached the first target ? */ + { /* then call this and next ones back in... */ + iChunkname = ((mng_chunk_headerp)pChunk)->iChunkname; + bCont = fProc (hHandle, (mng_handle)pChunk, iChunkname, iSeq); + } + + iSeq++; /* next one */ + pChunk = ((mng_chunk_headerp)pChunk)->pNext; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_ITERATE_CHUNKS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_copy_chunk (mng_handle hHandle, + mng_handle hChunk, + mng_handle hHandleOut) +{ + mng_datap pDataOut; + mng_chunkp pChunk; + mng_chunkp pChunkOut; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_COPY_CHUNK, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handles */ + MNG_VALIDHANDLE (hHandleOut) + + pDataOut = (mng_datap)hHandleOut; /* make outhandle addressable */ + pChunk = (mng_chunkp)hChunk; /* address the chunk */ + + if (!pDataOut->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pDataOut, MNG_FUNCTIONINVALID) + /* create a new chunk */ + iRetcode = ((mng_createchunk)((mng_chunk_headerp)pChunk)->fCreate) + (pDataOut, ((mng_chunk_headerp)pChunk), &pChunkOut); + if (!iRetcode) /* assign the chunk-specific data */ + iRetcode = ((mng_assignchunk)((mng_chunk_headerp)pChunk)->fAssign) + (pDataOut, pChunkOut, pChunk); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + mng_add_chunk (pDataOut, pChunkOut); /* and put it in the output-stream */ + + /* could it be the end of the chain ? */ + if (((mng_chunk_headerp)pChunkOut)->iChunkname == MNG_UINT_IEND) + { +#ifdef MNG_INCLUDE_JNG + if ((pDataOut->iFirstchunkadded == MNG_UINT_IHDR) || + (pDataOut->iFirstchunkadded == MNG_UINT_JHDR) ) +#else + if (pDataOut->iFirstchunkadded == MNG_UINT_IHDR) +#endif + pDataOut->bCreating = MNG_FALSE; /* right; this should be the last chunk !!! */ + } + + if (((mng_chunk_headerp)pChunkOut)->iChunkname == MNG_UINT_MEND) + pDataOut->bCreating = MNG_FALSE; /* definitely this should be the last !!! */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_COPY_CHUNK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_getchunk_ihdr (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iWidth, + mng_uint32 *iHeight, + mng_uint8 *iBitdepth, + mng_uint8 *iColortype, + mng_uint8 *iCompression, + mng_uint8 *iFilter, + mng_uint8 *iInterlace) +{ + mng_datap pData; + mng_ihdrp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_IHDR, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_ihdrp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_IHDR) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iWidth = pChunk->iWidth; /* fill the fields */ + *iHeight = pChunk->iHeight; + *iBitdepth = pChunk->iBitdepth; + *iColortype = pChunk->iColortype; + *iCompression = pChunk->iCompression; + *iFilter = pChunk->iFilter; + *iInterlace = pChunk->iInterlace; + + /* fill the chunk */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_IHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_getchunk_plte (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iCount, + mng_palette8 *aPalette) +{ + mng_datap pData; + mng_pltep pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PLTE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_pltep)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_PLTE) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iCount = pChunk->iEntrycount; /* fill the fields */ + + MNG_COPY (*aPalette, pChunk->aEntries, sizeof (mng_palette8)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PLTE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_getchunk_idat (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iRawlen, + mng_ptr *pRawdata) +{ + mng_datap pData; + mng_idatp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_IDAT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_idatp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_IDAT) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iRawlen = pChunk->iDatasize; /* fill the fields */ + *pRawdata = pChunk->pData; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_IDAT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_getchunk_trns (mng_handle hHandle, + mng_handle hChunk, + mng_bool *bEmpty, + mng_bool *bGlobal, + mng_uint8 *iType, + mng_uint32 *iCount, + mng_uint8arr *aAlphas, + mng_uint16 *iGray, + mng_uint16 *iRed, + mng_uint16 *iGreen, + mng_uint16 *iBlue, + mng_uint32 *iRawlen, + mng_uint8arr *aRawdata) +{ + mng_datap pData; + mng_trnsp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TRNS, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_trnsp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_tRNS) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *bEmpty = pChunk->bEmpty; /* fill the fields */ + *bGlobal = pChunk->bGlobal; + *iType = pChunk->iType; + *iCount = pChunk->iCount; + *iGray = pChunk->iGray; + *iRed = pChunk->iRed; + *iGreen = pChunk->iGreen; + *iBlue = pChunk->iBlue; + *iRawlen = pChunk->iRawlen; + + MNG_COPY (*aAlphas, pChunk->aEntries, sizeof (mng_uint8arr)); + MNG_COPY (*aRawdata, pChunk->aRawdata, sizeof (mng_uint8arr)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TRNS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_gAMA +mng_retcode MNG_DECL mng_getchunk_gama (mng_handle hHandle, + mng_handle hChunk, + mng_bool *bEmpty, + mng_uint32 *iGamma) +{ + mng_datap pData; + mng_gamap pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_GAMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_gamap)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_gAMA) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *bEmpty = pChunk->bEmpty; /* fill the fields */ + *iGamma = pChunk->iGamma; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_GAMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_cHRM +mng_retcode MNG_DECL mng_getchunk_chrm (mng_handle hHandle, + mng_handle hChunk, + mng_bool *bEmpty, + mng_uint32 *iWhitepointx, + mng_uint32 *iWhitepointy, + mng_uint32 *iRedx, + mng_uint32 *iRedy, + mng_uint32 *iGreenx, + mng_uint32 *iGreeny, + mng_uint32 *iBluex, + mng_uint32 *iBluey) +{ + mng_datap pData; + mng_chrmp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_CHRM, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_chrmp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_cHRM) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *bEmpty = pChunk->bEmpty; /* fill the fields */ + *iWhitepointx = pChunk->iWhitepointx; + *iWhitepointy = pChunk->iWhitepointy; + *iRedx = pChunk->iRedx; + *iRedy = pChunk->iRedy; + *iGreenx = pChunk->iGreenx; + *iGreeny = pChunk->iGreeny; + *iBluex = pChunk->iBluex; + *iBluey = pChunk->iBluey; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_CHRM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sRGB +mng_retcode MNG_DECL mng_getchunk_srgb (mng_handle hHandle, + mng_handle hChunk, + mng_bool *bEmpty, + mng_uint8 *iRenderingintent) +{ + mng_datap pData; + mng_srgbp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SRGB, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_srgbp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_sRGB) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *bEmpty = pChunk->bEmpty; /* fill the fields */ + *iRenderingintent = pChunk->iRenderingintent; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SRGB, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iCCP +mng_retcode MNG_DECL mng_getchunk_iccp (mng_handle hHandle, + mng_handle hChunk, + mng_bool *bEmpty, + mng_uint32 *iNamesize, + mng_pchar *zName, + mng_uint8 *iCompression, + mng_uint32 *iProfilesize, + mng_ptr *pProfile) +{ + mng_datap pData; + mng_iccpp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ICCP, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_iccpp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_iCCP) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *bEmpty = pChunk->bEmpty; /* fill the fields */ + *iNamesize = pChunk->iNamesize; + *zName = pChunk->zName; + *iCompression = pChunk->iCompression; + *iProfilesize = pChunk->iProfilesize; + *pProfile = pChunk->pProfile; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ICCP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_tEXt +mng_retcode MNG_DECL mng_getchunk_text (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iKeywordsize, + mng_pchar *zKeyword, + mng_uint32 *iTextsize, + mng_pchar *zText) +{ + mng_datap pData; + mng_textp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TEXT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_textp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_tEXt) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + /* fill the fields */ + *iKeywordsize = pChunk->iKeywordsize; + *zKeyword = pChunk->zKeyword; + *iTextsize = pChunk->iTextsize; + *zText = pChunk->zText; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TEXT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_zTXt +mng_retcode MNG_DECL mng_getchunk_ztxt (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iKeywordsize, + mng_pchar *zKeyword, + mng_uint8 *iCompression, + mng_uint32 *iTextsize, + mng_pchar *zText) +{ + mng_datap pData; + mng_ztxtp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ZTXT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_ztxtp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_zTXt) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + /* fill the fields */ + *iKeywordsize = pChunk->iKeywordsize; + *zKeyword = pChunk->zKeyword; + *iCompression = pChunk->iCompression; + *iTextsize = pChunk->iTextsize; + *zText = pChunk->zText; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ZTXT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iTXt +mng_retcode MNG_DECL mng_getchunk_itxt (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iKeywordsize, + mng_pchar *zKeyword, + mng_uint8 *iCompressionflag, + mng_uint8 *iCompressionmethod, + mng_uint32 *iLanguagesize, + mng_pchar *zLanguage, + mng_uint32 *iTranslationsize, + mng_pchar *zTranslation, + mng_uint32 *iTextsize, + mng_pchar *zText) +{ + mng_datap pData; + mng_itxtp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ITXT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_itxtp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_iTXt) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + /* fill the fields */ + *iKeywordsize = pChunk->iKeywordsize; + *zKeyword = pChunk->zKeyword; + *iCompressionflag = pChunk->iCompressionflag; + *iCompressionmethod = pChunk->iCompressionmethod; + *iLanguagesize = pChunk->iLanguagesize; + *zLanguage = pChunk->zLanguage; + *iTranslationsize = pChunk->iTranslationsize; + *zTranslation = pChunk->zTranslation; + *iTextsize = pChunk->iTextsize; + *zText = pChunk->zText; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ITXT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_bKGD +mng_retcode MNG_DECL mng_getchunk_bkgd (mng_handle hHandle, + mng_handle hChunk, + mng_bool *bEmpty, + mng_uint8 *iType, + mng_uint8 *iIndex, + mng_uint16 *iGray, + mng_uint16 *iRed, + mng_uint16 *iGreen, + mng_uint16 *iBlue) +{ + mng_datap pData; + mng_bkgdp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_BKGD, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_bkgdp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_bKGD) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *bEmpty = pChunk->bEmpty; /* fill the fields */ + *iType = pChunk->iType; + *iIndex = pChunk->iIndex; + *iGray = pChunk->iGray; + *iRed = pChunk->iRed; + *iGreen = pChunk->iGreen; + *iBlue = pChunk->iBlue; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_BKGD, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_pHYs +mng_retcode MNG_DECL mng_getchunk_phys (mng_handle hHandle, + mng_handle hChunk, + mng_bool *bEmpty, + mng_uint32 *iSizex, + mng_uint32 *iSizey, + mng_uint8 *iUnit) +{ + mng_datap pData; + mng_physp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PHYS, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_physp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_pHYs) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *bEmpty = pChunk->bEmpty; /* fill the fields */ + *iSizex = pChunk->iSizex; + *iSizey = pChunk->iSizey; + *iUnit = pChunk->iUnit; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PHYS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sBIT +mng_retcode MNG_DECL mng_getchunk_sbit (mng_handle hHandle, + mng_handle hChunk, + mng_bool *bEmpty, + mng_uint8 *iType, + mng_uint8arr4 *aBits) +{ + mng_datap pData; + mng_sbitp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SBIT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_sbitp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_sBIT) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *bEmpty = pChunk->bEmpty; + *iType = pChunk->iType; + (*aBits)[0] = pChunk->aBits[0]; + (*aBits)[1] = pChunk->aBits[1]; + (*aBits)[2] = pChunk->aBits[2]; + (*aBits)[3] = pChunk->aBits[3]; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SBIT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sPLT +mng_retcode MNG_DECL mng_getchunk_splt (mng_handle hHandle, + mng_handle hChunk, + mng_bool *bEmpty, + mng_uint32 *iNamesize, + mng_pchar *zName, + mng_uint8 *iSampledepth, + mng_uint32 *iEntrycount, + mng_ptr *pEntries) +{ + mng_datap pData; + mng_spltp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SPLT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_spltp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_sPLT) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *bEmpty = pChunk->bEmpty; /* fill the fields */ + *iNamesize = pChunk->iNamesize; + *zName = pChunk->zName; + *iSampledepth = pChunk->iSampledepth; + *iEntrycount = pChunk->iEntrycount; + *pEntries = pChunk->pEntries; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SPLT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_hIST +mng_retcode MNG_DECL mng_getchunk_hist (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iEntrycount, + mng_uint16arr *aEntries) +{ + mng_datap pData; + mng_histp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_HIST, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_histp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_hIST) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iEntrycount = pChunk->iEntrycount; /* fill the fields */ + + MNG_COPY (*aEntries, pChunk->aEntries, sizeof (mng_uint16arr)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_HIST, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_tIME +mng_retcode MNG_DECL mng_getchunk_time (mng_handle hHandle, + mng_handle hChunk, + mng_uint16 *iYear, + mng_uint8 *iMonth, + mng_uint8 *iDay, + mng_uint8 *iHour, + mng_uint8 *iMinute, + mng_uint8 *iSecond) +{ + mng_datap pData; + mng_timep pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TIME, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_timep)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_tIME) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iYear = pChunk->iYear; /* fill the fields */ + *iMonth = pChunk->iMonth; + *iDay = pChunk->iDay; + *iHour = pChunk->iHour; + *iMinute = pChunk->iMinute; + *iSecond = pChunk->iSecond; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TIME, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_getchunk_mhdr (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iWidth, + mng_uint32 *iHeight, + mng_uint32 *iTicks, + mng_uint32 *iLayercount, + mng_uint32 *iFramecount, + mng_uint32 *iPlaytime, + mng_uint32 *iSimplicity) +{ + mng_datap pData; + mng_mhdrp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MHDR, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_mhdrp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iWidth = pChunk->iWidth; /* fill the fields */ + *iHeight = pChunk->iHeight; + *iTicks = pChunk->iTicks; + *iLayercount = pChunk->iLayercount; + *iFramecount = pChunk->iFramecount; + *iPlaytime = pChunk->iPlaytime; + *iSimplicity = pChunk->iSimplicity; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_LOOP +mng_retcode MNG_DECL mng_getchunk_loop (mng_handle hHandle, + mng_handle hChunk, + mng_uint8 *iLevel, + mng_uint32 *iRepeat, + mng_uint8 *iTermination, + mng_uint32 *iItermin, + mng_uint32 *iItermax, + mng_uint32 *iCount, + mng_uint32p *pSignals) +{ + mng_datap pData; + mng_loopp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_LOOP, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_loopp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_LOOP) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iLevel = pChunk->iLevel; /* fill teh fields */ + *iRepeat = pChunk->iRepeat; + *iTermination = pChunk->iTermination; + *iItermin = pChunk->iItermin; + *iItermax = pChunk->iItermax; + *iCount = pChunk->iCount; + *pSignals = pChunk->pSignals; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_LOOP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_getchunk_endl (mng_handle hHandle, + mng_handle hChunk, + mng_uint8 *iLevel) +{ + mng_datap pData; + mng_endlp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ENDL, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_endlp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_ENDL) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iLevel = pChunk->iLevel; /* fill the field */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ENDL, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DEFI +mng_retcode MNG_DECL mng_getchunk_defi (mng_handle hHandle, + mng_handle hChunk, + mng_uint16 *iObjectid, + mng_uint8 *iDonotshow, + mng_uint8 *iConcrete, + mng_bool *bHasloca, + mng_int32 *iXlocation, + mng_int32 *iYlocation, + mng_bool *bHasclip, + mng_int32 *iLeftcb, + mng_int32 *iRightcb, + mng_int32 *iTopcb, + mng_int32 *iBottomcb) +{ + mng_datap pData; + mng_defip pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DEFI, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_defip)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_DEFI) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iObjectid = pChunk->iObjectid; /* fill the fields */ + *iDonotshow = pChunk->iDonotshow; + *iConcrete = pChunk->iConcrete; + *bHasloca = pChunk->bHasloca; + *iXlocation = pChunk->iXlocation; + *iYlocation = pChunk->iYlocation; + *bHasclip = pChunk->bHasclip; + *iLeftcb = pChunk->iLeftcb; + *iRightcb = pChunk->iRightcb; + *iTopcb = pChunk->iTopcb; + *iBottomcb = pChunk->iBottomcb; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DEFI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_BASI +mng_retcode MNG_DECL mng_getchunk_basi (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iWidth, + mng_uint32 *iHeight, + mng_uint8 *iBitdepth, + mng_uint8 *iColortype, + mng_uint8 *iCompression, + mng_uint8 *iFilter, + mng_uint8 *iInterlace, + mng_uint16 *iRed, + mng_uint16 *iGreen, + mng_uint16 *iBlue, + mng_uint16 *iAlpha, + mng_uint8 *iViewable) +{ + mng_datap pData; + mng_basip pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_BASI, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_basip)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_BASI) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iWidth = pChunk->iWidth; /* fill the fields */ + *iHeight = pChunk->iHeight; + *iBitdepth = pChunk->iBitdepth; + *iColortype = pChunk->iColortype; + *iCompression = pChunk->iCompression; + *iFilter = pChunk->iFilter; + *iInterlace = pChunk->iInterlace; + *iRed = pChunk->iRed; + *iGreen = pChunk->iGreen; + *iBlue = pChunk->iBlue; + *iAlpha = pChunk->iAlpha; + *iViewable = pChunk->iViewable; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_BASI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_CLON +mng_retcode MNG_DECL mng_getchunk_clon (mng_handle hHandle, + mng_handle hChunk, + mng_uint16 *iSourceid, + mng_uint16 *iCloneid, + mng_uint8 *iClonetype, + mng_uint8 *iDonotshow, + mng_uint8 *iConcrete, + mng_bool *bHasloca, + mng_uint8 *iLocationtype, + mng_int32 *iLocationx, + mng_int32 *iLocationy) +{ + mng_datap pData; + mng_clonp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_CLON, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_clonp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_CLON) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iSourceid = pChunk->iSourceid; /* fill the fields */ + *iCloneid = pChunk->iCloneid; + *iClonetype = pChunk->iClonetype; + *iDonotshow = pChunk->iDonotshow; + *iConcrete = pChunk->iConcrete; + *bHasloca = pChunk->bHasloca; + *iLocationtype = pChunk->iLocationtype; + *iLocationx = pChunk->iLocationx; + *iLocationy = pChunk->iLocationy; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_CLON, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +mng_retcode MNG_DECL mng_getchunk_past (mng_handle hHandle, + mng_handle hChunk, + mng_uint16 *iDestid, + mng_uint8 *iTargettype, + mng_int32 *iTargetx, + mng_int32 *iTargety, + mng_uint32 *iCount) +{ + mng_datap pData; + mng_pastp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PAST, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_pastp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_PAST) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iDestid = pChunk->iDestid; /* fill the fields */ + *iTargettype = pChunk->iTargettype; + *iTargetx = pChunk->iTargetx; + *iTargety = pChunk->iTargety; + *iCount = pChunk->iCount; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PAST, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +mng_retcode MNG_DECL mng_getchunk_past_src (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 iEntry, + mng_uint16 *iSourceid, + mng_uint8 *iComposition, + mng_uint8 *iOrientation, + mng_uint8 *iOffsettype, + mng_int32 *iOffsetx, + mng_int32 *iOffsety, + mng_uint8 *iBoundarytype, + mng_int32 *iBoundaryl, + mng_int32 *iBoundaryr, + mng_int32 *iBoundaryt, + mng_int32 *iBoundaryb) +{ + mng_datap pData; + mng_pastp pChunk; + mng_past_sourcep pEntry; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PAST_SRC, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_pastp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_PAST) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + if (iEntry >= pChunk->iCount) /* valid index ? */ + MNG_ERROR (pData, MNG_INVALIDENTRYIX) + /* address the entry */ + pEntry = pChunk->pSources + iEntry; + + *iSourceid = pEntry->iSourceid; /* fill the fields */ + *iComposition = pEntry->iComposition; + *iOrientation = pEntry->iOrientation; + *iOffsettype = pEntry->iOffsettype; + *iOffsetx = pEntry->iOffsetx; + *iOffsety = pEntry->iOffsety; + *iBoundarytype = pEntry->iBoundarytype; + *iBoundaryl = pEntry->iBoundaryl; + *iBoundaryr = pEntry->iBoundaryr; + *iBoundaryt = pEntry->iBoundaryt; + *iBoundaryb = pEntry->iBoundaryb; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PAST_SRC, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DISC +mng_retcode MNG_DECL mng_getchunk_disc (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iCount, + mng_uint16p *pObjectids) +{ + mng_datap pData; + mng_discp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DISC, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_discp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_DISC) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iCount = pChunk->iCount; /* fill the fields */ + *pObjectids = pChunk->pObjectids; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DISC, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_BACK +mng_retcode MNG_DECL mng_getchunk_back (mng_handle hHandle, + mng_handle hChunk, + mng_uint16 *iRed, + mng_uint16 *iGreen, + mng_uint16 *iBlue, + mng_uint8 *iMandatory, + mng_uint16 *iImageid, + mng_uint8 *iTile) +{ + mng_datap pData; + mng_backp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_BACK, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_backp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_BACK) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iRed = pChunk->iRed; /* fill the fields */ + *iGreen = pChunk->iGreen; + *iBlue = pChunk->iBlue; + *iMandatory = pChunk->iMandatory; + *iImageid = pChunk->iImageid; + *iTile = pChunk->iTile; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_BACK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_FRAM +mng_retcode MNG_DECL mng_getchunk_fram (mng_handle hHandle, + mng_handle hChunk, + mng_bool *bEmpty, + mng_uint8 *iMode, + mng_uint32 *iNamesize, + mng_pchar *zName, + mng_uint8 *iChangedelay, + mng_uint8 *iChangetimeout, + mng_uint8 *iChangeclipping, + mng_uint8 *iChangesyncid, + mng_uint32 *iDelay, + mng_uint32 *iTimeout, + mng_uint8 *iBoundarytype, + mng_int32 *iBoundaryl, + mng_int32 *iBoundaryr, + mng_int32 *iBoundaryt, + mng_int32 *iBoundaryb, + mng_uint32 *iCount, + mng_uint32p *pSyncids) +{ + mng_datap pData; + mng_framp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_FRAM, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_framp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_FRAM) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *bEmpty = pChunk->bEmpty; /* fill the fields */ + *iMode = pChunk->iMode; + *iNamesize = pChunk->iNamesize; + *zName = pChunk->zName; + *iChangedelay = pChunk->iChangedelay; + *iChangetimeout = pChunk->iChangetimeout; + *iChangeclipping = pChunk->iChangeclipping; + *iChangesyncid = pChunk->iChangesyncid; + *iDelay = pChunk->iDelay; + *iTimeout = pChunk->iTimeout; + *iBoundarytype = pChunk->iBoundarytype; + *iBoundaryl = pChunk->iBoundaryl; + *iBoundaryr = pChunk->iBoundaryr; + *iBoundaryt = pChunk->iBoundaryt; + *iBoundaryb = pChunk->iBoundaryb; + *iCount = pChunk->iCount; + *pSyncids = pChunk->pSyncids; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_FRAM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MOVE +mng_retcode MNG_DECL mng_getchunk_move (mng_handle hHandle, + mng_handle hChunk, + mng_uint16 *iFirstid, + mng_uint16 *iLastid, + mng_uint8 *iMovetype, + mng_int32 *iMovex, + mng_int32 *iMovey) +{ + mng_datap pData; + mng_movep pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MOVE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_movep)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_MOVE) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iFirstid = pChunk->iFirstid; /* fill the fields */ + *iLastid = pChunk->iLastid; + *iMovetype = pChunk->iMovetype; + *iMovex = pChunk->iMovex; + *iMovey = pChunk->iMovey; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MOVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_CLIP +mng_retcode MNG_DECL mng_getchunk_clip (mng_handle hHandle, + mng_handle hChunk, + mng_uint16 *iFirstid, + mng_uint16 *iLastid, + mng_uint8 *iCliptype, + mng_int32 *iClipl, + mng_int32 *iClipr, + mng_int32 *iClipt, + mng_int32 *iClipb) +{ + mng_datap pData; + mng_clipp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_CLIP, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_clipp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_CLIP) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iFirstid = pChunk->iFirstid; /* fill the fields */ + *iLastid = pChunk->iLastid; + *iCliptype = pChunk->iCliptype; + *iClipl = pChunk->iClipl; + *iClipr = pChunk->iClipr; + *iClipt = pChunk->iClipt; + *iClipb = pChunk->iClipb; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_CLIP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SHOW +mng_retcode MNG_DECL mng_getchunk_show (mng_handle hHandle, + mng_handle hChunk, + mng_bool *bEmpty, + mng_uint16 *iFirstid, + mng_uint16 *iLastid, + mng_uint8 *iMode) +{ + mng_datap pData; + mng_showp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SHOW, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_showp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_SHOW) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *bEmpty = pChunk->bEmpty; /* fill the fields */ + *iFirstid = pChunk->iFirstid; + *iLastid = pChunk->iLastid; + *iMode = pChunk->iMode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SHOW, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_TERM +mng_retcode MNG_DECL mng_getchunk_term (mng_handle hHandle, + mng_handle hChunk, + mng_uint8 *iTermaction, + mng_uint8 *iIteraction, + mng_uint32 *iDelay, + mng_uint32 *iItermax) +{ + mng_datap pData; + mng_termp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TERM, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_termp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_TERM) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iTermaction = pChunk->iTermaction; /* fill the fields */ + *iIteraction = pChunk->iIteraction; + *iDelay = pChunk->iDelay; + *iItermax = pChunk->iItermax; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_TERM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SAVE +mng_retcode MNG_DECL mng_getchunk_save (mng_handle hHandle, + mng_handle hChunk, + mng_bool *bEmpty, + mng_uint8 *iOffsettype, + mng_uint32 *iCount) +{ + mng_datap pData; + mng_savep pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SAVE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_savep)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_SAVE) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *bEmpty = pChunk->bEmpty; /* fill the fields */ + *iOffsettype = pChunk->iOffsettype; + *iCount = pChunk->iCount; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SAVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_getchunk_save_entry (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 iEntry, + mng_uint8 *iEntrytype, + mng_uint32arr2 *iOffset, + mng_uint32arr2 *iStarttime, + mng_uint32 *iLayernr, + mng_uint32 *iFramenr, + mng_uint32 *iNamesize, + mng_pchar *zName) +{ + mng_datap pData; + mng_savep pChunk; + mng_save_entryp pEntry; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SAVE_ENTRY, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_savep)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_SAVE) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + if (iEntry >= pChunk->iCount) /* valid index ? */ + MNG_ERROR (pData, MNG_INVALIDENTRYIX) + + pEntry = pChunk->pEntries + iEntry; /* address the entry */ + /* fill the fields */ + *iEntrytype = pEntry->iEntrytype; + (*iOffset)[0] = pEntry->iOffset[0]; + (*iOffset)[1] = pEntry->iOffset[1]; + (*iStarttime)[0] = pEntry->iStarttime[0]; + (*iStarttime)[1] = pEntry->iStarttime[1]; + *iLayernr = pEntry->iLayernr; + *iFramenr = pEntry->iFramenr; + *iNamesize = pEntry->iNamesize; + *zName = pEntry->zName; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SAVE_ENTRY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SEEK +mng_retcode MNG_DECL mng_getchunk_seek (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iNamesize, + mng_pchar *zName) +{ + mng_datap pData; + mng_seekp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SEEK, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_seekp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_SEEK) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iNamesize = pChunk->iNamesize; /* fill the fields */ + *zName = pChunk->zName; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_SEEK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_eXPI +mng_retcode MNG_DECL mng_getchunk_expi (mng_handle hHandle, + mng_handle hChunk, + mng_uint16 *iSnapshotid, + mng_uint32 *iNamesize, + mng_pchar *zName) +{ + mng_datap pData; + mng_expip pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_EXPI, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_expip)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_eXPI) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iSnapshotid = pChunk->iSnapshotid; /* fill the fields */ + *iNamesize = pChunk->iNamesize; + *zName = pChunk->zName; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_EXPI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_fPRI +mng_retcode MNG_DECL mng_getchunk_fpri (mng_handle hHandle, + mng_handle hChunk, + mng_uint8 *iDeltatype, + mng_uint8 *iPriority) +{ + mng_datap pData; + mng_fprip pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_FPRI, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_fprip)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_fPRI) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iDeltatype = pChunk->iDeltatype; /* fill the fields */ + *iPriority = pChunk->iPriority; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_FPRI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_nEED +mng_retcode MNG_DECL mng_getchunk_need (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iKeywordssize, + mng_pchar *zKeywords) +{ + mng_datap pData; + mng_needp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_NEED, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_needp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_nEED) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + /* fill the fields */ + *iKeywordssize = pChunk->iKeywordssize; + *zKeywords = pChunk->zKeywords; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_NEED, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_pHYg +mng_retcode MNG_DECL mng_getchunk_phyg (mng_handle hHandle, + mng_handle hChunk, + mng_bool *bEmpty, + mng_uint32 *iSizex, + mng_uint32 *iSizey, + mng_uint8 *iUnit) +{ + mng_datap pData; + mng_phygp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PHYG, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_phygp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_pHYg) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *bEmpty = pChunk->bEmpty; /* fill the fields */ + *iSizex = pChunk->iSizex; + *iSizey = pChunk->iSizey; + *iUnit = pChunk->iUnit; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PHYG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG + +mng_retcode MNG_DECL mng_getchunk_jhdr (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iWidth, + mng_uint32 *iHeight, + mng_uint8 *iColortype, + mng_uint8 *iImagesampledepth, + mng_uint8 *iImagecompression, + mng_uint8 *iImageinterlace, + mng_uint8 *iAlphasampledepth, + mng_uint8 *iAlphacompression, + mng_uint8 *iAlphafilter, + mng_uint8 *iAlphainterlace) +{ + mng_datap pData; + mng_jhdrp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_JHDR, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_jhdrp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_JHDR) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iWidth = pChunk->iWidth; /* fill the fields */ + *iHeight = pChunk->iHeight; + *iColortype = pChunk->iColortype; + *iImagesampledepth = pChunk->iImagesampledepth; + *iImagecompression = pChunk->iImagecompression; + *iImageinterlace = pChunk->iImageinterlace; + *iAlphasampledepth = pChunk->iAlphasampledepth; + *iAlphacompression = pChunk->iAlphacompression; + *iAlphafilter = pChunk->iAlphafilter; + *iAlphainterlace = pChunk->iAlphainterlace; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_JHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG + +mng_retcode MNG_DECL mng_getchunk_jdat (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iRawlen, + mng_ptr *pRawdata) +{ + mng_datap pData; + mng_jdatp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_JDAT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_jdatp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_JDAT) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iRawlen = pChunk->iDatasize; /* fill the fields */ + *pRawdata = pChunk->pData; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_JDAT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG + +mng_retcode MNG_DECL mng_getchunk_jdaa (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iRawlen, + mng_ptr *pRawdata) +{ + mng_datap pData; + mng_jdaap pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_JDAA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_jdaap)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_JDAA) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iRawlen = pChunk->iDatasize; /* fill the fields */ + *pRawdata = pChunk->pData; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_JDAA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode MNG_DECL mng_getchunk_dhdr (mng_handle hHandle, + mng_handle hChunk, + mng_uint16 *iObjectid, + mng_uint8 *iImagetype, + mng_uint8 *iDeltatype, + mng_uint32 *iBlockwidth, + mng_uint32 *iBlockheight, + mng_uint32 *iBlockx, + mng_uint32 *iBlocky) +{ + mng_datap pData; + mng_dhdrp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DHDR, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_dhdrp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_DHDR) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iObjectid = pChunk->iObjectid; /* fill the fields */ + *iImagetype = pChunk->iImagetype; + *iDeltatype = pChunk->iDeltatype; + *iBlockwidth = pChunk->iBlockwidth; + *iBlockheight = pChunk->iBlockheight; + *iBlockx = pChunk->iBlockx; + *iBlocky = pChunk->iBlocky; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode MNG_DECL mng_getchunk_prom (mng_handle hHandle, + mng_handle hChunk, + mng_uint8 *iColortype, + mng_uint8 *iSampledepth, + mng_uint8 *iFilltype) +{ + mng_datap pData; + mng_promp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PROM, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_promp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_PROM) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iColortype = pChunk->iColortype; /* fill the fields */ + *iSampledepth = pChunk->iSampledepth; + *iFilltype = pChunk->iFilltype; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PROM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode MNG_DECL mng_getchunk_pplt (mng_handle hHandle, + mng_handle hChunk, + mng_uint8 *iDeltatype, + mng_uint32 *iCount) +{ + mng_datap pData; + mng_ppltp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PPLT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_ppltp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_PPLT) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iDeltatype = pChunk->iDeltatype; /* fill the fields */ + *iCount = pChunk->iCount; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PPLT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode MNG_DECL mng_getchunk_pplt_entry (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 iEntry, + mng_uint16 *iRed, + mng_uint16 *iGreen, + mng_uint16 *iBlue, + mng_uint16 *iAlpha, + mng_bool *bUsed) +{ + mng_datap pData; + mng_ppltp pChunk; + mng_pplt_entryp pEntry; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PPLT_ENTRY, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_ppltp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_PPLT) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + if (iEntry >= pChunk->iCount) /* valid index ? */ + MNG_ERROR (pData, MNG_INVALIDENTRYIX) + + pEntry = &pChunk->aEntries[iEntry]; /* address the entry */ + + *iRed = pEntry->iRed; /* fill the fields */ + *iGreen = pEntry->iGreen; + *iBlue = pEntry->iBlue; + *iAlpha = pEntry->iAlpha; + *bUsed = pEntry->bUsed; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_PPLT_ENTRY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode MNG_DECL mng_getchunk_drop (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iCount, + mng_chunkidp *pChunknames) +{ + mng_datap pData; + mng_dropp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DROP, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_dropp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_DROP) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iCount = pChunk->iCount; /* fill the fields */ + *pChunknames = pChunk->pChunknames; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DROP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DBYK +mng_retcode MNG_DECL mng_getchunk_dbyk (mng_handle hHandle, + mng_handle hChunk, + mng_chunkid *iChunkname, + mng_uint8 *iPolarity, + mng_uint32 *iKeywordssize, + mng_pchar *zKeywords) +{ + mng_datap pData; + mng_dbykp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DBYK, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_dbykp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_DBYK) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iChunkname = pChunk->iChunkname; /* fill the fields */ + *iPolarity = pChunk->iPolarity; + *iKeywordssize = pChunk->iKeywordssize; + *zKeywords = pChunk->zKeywords; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_DBYK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR +mng_retcode MNG_DECL mng_getchunk_ordr (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iCount) +{ + mng_datap pData; + mng_ordrp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ORDR, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_ordrp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_ORDR) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iCount = pChunk->iCount; /* fill the field */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ORDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR +mng_retcode MNG_DECL mng_getchunk_ordr_entry (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 iEntry, + mng_chunkid *iChunkname, + mng_uint8 *iOrdertype) +{ + mng_datap pData; + mng_ordrp pChunk; + mng_ordr_entryp pEntry; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ORDR_ENTRY, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_ordrp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_ORDR) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + if (iEntry >= pChunk->iCount) /* valid index ? */ + MNG_ERROR (pData, MNG_INVALIDENTRYIX) + + pEntry = pChunk->pEntries + iEntry; /* address the proper entry */ + + *iChunkname = pEntry->iChunkname; /* fill the fields */ + *iOrdertype = pEntry->iOrdertype; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_ORDR_ENTRY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MAGN +mng_retcode MNG_DECL mng_getchunk_magn (mng_handle hHandle, + mng_handle hChunk, + mng_uint16 *iFirstid, + mng_uint16 *iLastid, + mng_uint16 *iMethodX, + mng_uint16 *iMX, + mng_uint16 *iMY, + mng_uint16 *iML, + mng_uint16 *iMR, + mng_uint16 *iMT, + mng_uint16 *iMB, + mng_uint16 *iMethodY) +{ + mng_datap pData; + mng_magnp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MAGN, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_magnp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_MAGN) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iFirstid = pChunk->iFirstid; /* fill the fields */ + *iLastid = pChunk->iLastid; + *iMethodX = (mng_uint16)pChunk->iMethodX; + *iMX = pChunk->iMX; + *iMY = pChunk->iMY; + *iML = pChunk->iML; + *iMR = pChunk->iMR; + *iMT = pChunk->iMT; + *iMB = pChunk->iMB; + *iMethodY = (mng_uint16)pChunk->iMethodY; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MAGN, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_MPNG_PROPOSAL +MNG_EXT mng_retcode MNG_DECL mng_getchunk_mpng (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iFramewidth, + mng_uint32 *iFrameheight, + mng_uint16 *iNumplays, + mng_uint16 *iTickspersec, + mng_uint8 *iCompressionmethod, + mng_uint32 *iCount) +{ + mng_datap pData; + mng_mpngp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MPNG, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_mpngp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_mpNG) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + /* fill the fields */ + *iFramewidth = pChunk->iFramewidth; + *iFrameheight = pChunk->iFrameheight; + *iNumplays = pChunk->iNumplays; + *iTickspersec = pChunk->iTickspersec; + *iCompressionmethod = pChunk->iCompressionmethod; + *iCount = pChunk->iFramessize / sizeof (mng_mpng_frame); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MPNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_MPNG_PROPOSAL +MNG_EXT mng_retcode MNG_DECL mng_getchunk_mpng_frame (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 iEntry, + mng_uint32 *iX, + mng_uint32 *iY, + mng_uint32 *iWidth, + mng_uint32 *iHeight, + mng_int32 *iXoffset, + mng_int32 *iYoffset, + mng_uint16 *iTicks) +{ + mng_datap pData; + mng_mpngp pChunk; + mng_mpng_framep pFrame; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MPNG_FRAME, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_mpngp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_mpNG) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + /* valid index ? */ + if (iEntry >= (pChunk->iFramessize / sizeof (mng_mpng_frame))) + MNG_ERROR (pData, MNG_INVALIDENTRYIX) + + pFrame = pChunk->pFrames + iEntry; /* address the entry */ + /* fill the fields */ + *iX = pFrame->iX; + *iY = pFrame->iY; + *iWidth = pFrame->iWidth; + *iHeight = pFrame->iHeight; + *iXoffset = pFrame->iXoffset; + *iYoffset = pFrame->iYoffset; + *iTicks = pFrame->iTicks; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_MPNG_FRAME, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_evNT +mng_retcode MNG_DECL mng_getchunk_evnt (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 *iCount) +{ + mng_datap pData; + mng_evntp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_EVNT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_evntp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_evNT) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + *iCount = pChunk->iCount; /* fill the fields */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_EVNT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_getchunk_evnt_entry (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 iEntry, + mng_uint8 *iEventtype, + mng_uint8 *iMasktype, + mng_int32 *iLeft, + mng_int32 *iRight, + mng_int32 *iTop, + mng_int32 *iBottom, + mng_uint16 *iObjectid, + mng_uint8 *iIndex, + mng_uint32 *iSegmentnamesize, + mng_pchar *zSegmentname) +{ + mng_datap pData; + mng_evntp pChunk; + mng_evnt_entryp pEntry; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_EVNT_ENTRY, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_evntp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.iChunkname != MNG_UINT_evNT) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + + if (iEntry >= pChunk->iCount) /* valid index ? */ + MNG_ERROR (pData, MNG_INVALIDENTRYIX) + + pEntry = pChunk->pEntries + iEntry; /* address the entry */ + /* fill the fields */ + *iEventtype = pEntry->iEventtype; + *iMasktype = pEntry->iMasktype; + *iLeft = pEntry->iLeft; + *iRight = pEntry->iRight; + *iTop = pEntry->iTop; + *iBottom = pEntry->iBottom; + *iObjectid = pEntry->iObjectid; + *iIndex = pEntry->iIndex; + *iSegmentnamesize = pEntry->iSegmentnamesize; + *zSegmentname = pEntry->zSegmentname; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_EVNT_ENTRY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_getchunk_unknown (mng_handle hHandle, + mng_handle hChunk, + mng_chunkid *iChunkname, + mng_uint32 *iRawlen, + mng_ptr *pRawdata) +{ + mng_datap pData; + mng_unknown_chunkp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_UNKNOWN, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + pChunk = (mng_unknown_chunkp)hChunk; /* address the chunk */ + + if (pChunk->sHeader.fCleanup != mng_free_unknown) + MNG_ERROR (pData, MNG_WRONGCHUNK) /* ouch */ + /* fill the fields */ + *iChunkname = pChunk->sHeader.iChunkname; + *iRawlen = pChunk->iDatasize; + *pRawdata = pChunk->pData; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETCHUNK_UNKNOWN, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_WRITE_PROCS + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_TERM +MNG_LOCAL mng_bool check_term (mng_datap pData, + mng_chunkid iChunkname) +{ + mng_chunk_headerp pChunk = (mng_chunk_headerp)pData->pLastchunk; + + if (!pChunk) /* nothing added yet ? */ + return MNG_TRUE; + /* last added chunk is TERM ? */ + if (pChunk->iChunkname != MNG_UINT_TERM) + return MNG_TRUE; + /* previous to last is MHDR ? */ + if ((pChunk->pPrev) && (((mng_chunk_headerp)pChunk->pPrev)->iChunkname == MNG_UINT_MHDR)) + return MNG_TRUE; + + if (iChunkname == MNG_UINT_SEEK) /* new chunk to be added is SEEK ? */ + return MNG_TRUE; + + return MNG_FALSE; +} +#endif + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_putchunk_ihdr (mng_handle hHandle, + mng_uint32 iWidth, + mng_uint32 iHeight, + mng_uint8 iBitdepth, + mng_uint8 iColortype, + mng_uint8 iCompression, + mng_uint8 iFilter, + mng_uint8 iInterlace) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_IHDR, mng_init_general, mng_free_general, mng_read_ihdr, mng_write_ihdr, mng_assign_general, 0, 0, sizeof(mng_ihdr)}; +#else + {MNG_UINT_IHDR, mng_init_ihdr, mng_free_ihdr, mng_read_ihdr, mng_write_ihdr, mng_assign_ihdr, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IHDR, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_IHDR)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_ihdr (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_IHDR, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + ((mng_ihdrp)pChunk)->iWidth = iWidth; + ((mng_ihdrp)pChunk)->iHeight = iHeight; + ((mng_ihdrp)pChunk)->iBitdepth = iBitdepth; + ((mng_ihdrp)pChunk)->iColortype = iColortype; + ((mng_ihdrp)pChunk)->iCompression = iCompression; + ((mng_ihdrp)pChunk)->iFilter = iFilter; + ((mng_ihdrp)pChunk)->iInterlace = iInterlace; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_putchunk_plte (mng_handle hHandle, + mng_uint32 iCount, + mng_palette8 aPalette) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_PLTE, mng_init_general, mng_free_general, mng_read_plte, mng_write_plte, mng_assign_general, 0, 0, sizeof(mng_plte)}; +#else + {MNG_UINT_PLTE, mng_init_plte, mng_free_plte, mng_read_plte, mng_write_plte, mng_assign_plte, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PLTE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_PLTE)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_plte (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_PLTE, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_pltep)pChunk)->iEntrycount = iCount; + ((mng_pltep)pChunk)->bEmpty = (mng_bool)(iCount == 0); + + MNG_COPY (((mng_pltep)pChunk)->aEntries, aPalette, sizeof (mng_palette8)); + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PLTE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_putchunk_idat (mng_handle hHandle, + mng_uint32 iRawlen, + mng_ptr pRawdata) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_IDAT, mng_init_general, mng_free_idat, mng_read_idat, mng_write_idat, mng_assign_idat, 0, 0, sizeof(mng_idat)}; +#else + {MNG_UINT_IDAT, mng_init_idat, mng_free_idat, mng_read_idat, mng_write_idat, mng_assign_idat, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IDAT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_IDAT)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_idat (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_IDAT, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_idatp)pChunk)->bEmpty = (mng_bool)(iRawlen == 0); + ((mng_idatp)pChunk)->iDatasize = iRawlen; + + if (iRawlen) + { + MNG_ALLOC (pData, ((mng_idatp)pChunk)->pData, iRawlen); + MNG_COPY (((mng_idatp)pChunk)->pData, pRawdata, iRawlen); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IDAT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_putchunk_iend (mng_handle hHandle) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_IEND, mng_init_general, mng_free_general, mng_read_iend, mng_write_iend, mng_assign_general, 0, 0, sizeof(mng_iend)}; +#else + {MNG_UINT_IEND, mng_init_iend, mng_free_iend, mng_read_iend, mng_write_iend, mng_assign_iend, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IEND, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_IEND)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_iend (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_IEND, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_INCLUDE_JNG + if ((pData->iFirstchunkadded == MNG_UINT_IHDR) || + (pData->iFirstchunkadded == MNG_UINT_JHDR) ) +#else + if (pData->iFirstchunkadded == MNG_UINT_IHDR) +#endif + pData->bCreating = MNG_FALSE; /* should be last chunk !!! */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IEND, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_putchunk_trns (mng_handle hHandle, + mng_bool bEmpty, + mng_bool bGlobal, + mng_uint8 iType, + mng_uint32 iCount, + mng_uint8arr aAlphas, + mng_uint16 iGray, + mng_uint16 iRed, + mng_uint16 iGreen, + mng_uint16 iBlue, + mng_uint32 iRawlen, + mng_uint8arr aRawdata) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_tRNS, mng_init_general, mng_free_general, mng_read_trns, mng_write_trns, mng_assign_general, 0, 0, sizeof(mng_trns)}; +#else + {MNG_UINT_tRNS, mng_init_trns, mng_free_trns, mng_read_trns, mng_write_trns, mng_assign_trns, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TRNS, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_tRNS)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_trns (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_tRNS, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_trnsp)pChunk)->bEmpty = bEmpty; + ((mng_trnsp)pChunk)->bGlobal = bGlobal; + ((mng_trnsp)pChunk)->iType = iType; + ((mng_trnsp)pChunk)->iCount = iCount; + ((mng_trnsp)pChunk)->iGray = iGray; + ((mng_trnsp)pChunk)->iRed = iRed; + ((mng_trnsp)pChunk)->iGreen = iGreen; + ((mng_trnsp)pChunk)->iBlue = iBlue; + ((mng_trnsp)pChunk)->iRawlen = iRawlen; + + MNG_COPY (((mng_trnsp)pChunk)->aEntries, aAlphas, sizeof (mng_uint8arr)); + MNG_COPY (((mng_trnsp)pChunk)->aRawdata, aRawdata, sizeof (mng_uint8arr)); + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TRNS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_gAMA +mng_retcode MNG_DECL mng_putchunk_gama (mng_handle hHandle, + mng_bool bEmpty, + mng_uint32 iGamma) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_gAMA, mng_init_general, mng_free_general, mng_read_gama, mng_write_gama, mng_assign_general, 0, 0, sizeof(mng_gama)}; +#else + {MNG_UINT_gAMA, mng_init_gama, mng_free_gama, mng_read_gama, mng_write_gama, mng_assign_gama, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_GAMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_gAMA)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_gama (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_gAMA, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_gamap)pChunk)->bEmpty = bEmpty; + ((mng_gamap)pChunk)->iGamma = iGamma; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_GAMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_cHRM +mng_retcode MNG_DECL mng_putchunk_chrm (mng_handle hHandle, + mng_bool bEmpty, + mng_uint32 iWhitepointx, + mng_uint32 iWhitepointy, + mng_uint32 iRedx, + mng_uint32 iRedy, + mng_uint32 iGreenx, + mng_uint32 iGreeny, + mng_uint32 iBluex, + mng_uint32 iBluey) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_cHRM, mng_init_general, mng_free_general, mng_read_chrm, mng_write_chrm, mng_assign_general, 0, 0, sizeof(mng_chrm)}; +#else + {MNG_UINT_cHRM, mng_init_chrm, mng_free_chrm, mng_read_chrm, mng_write_chrm, mng_assign_chrm, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_CHRM, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_cHRM)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_chrm (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_cHRM, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_chrmp)pChunk)->bEmpty = bEmpty; + ((mng_chrmp)pChunk)->iWhitepointx = iWhitepointx; + ((mng_chrmp)pChunk)->iWhitepointy = iWhitepointy; + ((mng_chrmp)pChunk)->iRedx = iRedx; + ((mng_chrmp)pChunk)->iRedy = iRedy; + ((mng_chrmp)pChunk)->iGreenx = iGreenx; + ((mng_chrmp)pChunk)->iGreeny = iGreeny; + ((mng_chrmp)pChunk)->iBluex = iBluex; + ((mng_chrmp)pChunk)->iBluey = iBluey; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_CHRM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sRGB +mng_retcode MNG_DECL mng_putchunk_srgb (mng_handle hHandle, + mng_bool bEmpty, + mng_uint8 iRenderingintent) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_sRGB, mng_init_general, mng_free_general, mng_read_srgb, mng_write_srgb, mng_assign_general, 0, 0, sizeof(mng_srgb)}; +#else + {MNG_UINT_sRGB, mng_init_srgb, mng_free_srgb, mng_read_srgb, mng_write_srgb, mng_assign_srgb, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SRGB, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_sRGB)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_srgb (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_sRGB, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_srgbp)pChunk)->bEmpty = bEmpty; + ((mng_srgbp)pChunk)->iRenderingintent = iRenderingintent; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SRGB, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iCCP +mng_retcode MNG_DECL mng_putchunk_iccp (mng_handle hHandle, + mng_bool bEmpty, + mng_uint32 iNamesize, + mng_pchar zName, + mng_uint8 iCompression, + mng_uint32 iProfilesize, + mng_ptr pProfile) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_iCCP, mng_init_general, mng_free_iccp, mng_read_iccp, mng_write_iccp, mng_assign_iccp, 0, 0, sizeof(mng_iccp)}; +#else + {MNG_UINT_iCCP, mng_init_iccp, mng_free_iccp, mng_read_iccp, mng_write_iccp, mng_assign_iccp, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ICCP, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_iCCP)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_iccp (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_iCCP, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_iccpp)pChunk)->bEmpty = bEmpty; + ((mng_iccpp)pChunk)->iNamesize = iNamesize; + ((mng_iccpp)pChunk)->iCompression = iCompression; + ((mng_iccpp)pChunk)->iProfilesize = iProfilesize; + + if (iNamesize) + { + MNG_ALLOC (pData, ((mng_iccpp)pChunk)->zName, iNamesize + 1); + MNG_COPY (((mng_iccpp)pChunk)->zName, zName, iNamesize); + } + + if (iProfilesize) + { + MNG_ALLOC (pData, ((mng_iccpp)pChunk)->pProfile, iProfilesize); + MNG_COPY (((mng_iccpp)pChunk)->pProfile, pProfile, iProfilesize); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ICCP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_tEXt +mng_retcode MNG_DECL mng_putchunk_text (mng_handle hHandle, + mng_uint32 iKeywordsize, + mng_pchar zKeyword, + mng_uint32 iTextsize, + mng_pchar zText) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_tEXt, mng_init_general, mng_free_text, mng_read_text, mng_write_text, mng_assign_text, 0, 0, sizeof(mng_text)}; +#else + {MNG_UINT_tEXt, mng_init_text, mng_free_text, mng_read_text, mng_write_text, mng_assign_text, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TEXT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_tEXt)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_text (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_tEXt, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_textp)pChunk)->iKeywordsize = iKeywordsize; + ((mng_textp)pChunk)->iTextsize = iTextsize; + + if (iKeywordsize) + { + MNG_ALLOC (pData, ((mng_textp)pChunk)->zKeyword, iKeywordsize + 1); + MNG_COPY (((mng_textp)pChunk)->zKeyword, zKeyword, iKeywordsize); + } + + if (iTextsize) + { + MNG_ALLOC (pData, ((mng_textp)pChunk)->zText, iTextsize + 1); + MNG_COPY (((mng_textp)pChunk)->zText, zText, iTextsize); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TEXT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_zTXt +mng_retcode MNG_DECL mng_putchunk_ztxt (mng_handle hHandle, + mng_uint32 iKeywordsize, + mng_pchar zKeyword, + mng_uint8 iCompression, + mng_uint32 iTextsize, + mng_pchar zText) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_zTXt, mng_init_general, mng_free_ztxt, mng_read_ztxt, mng_write_ztxt, mng_assign_ztxt, 0, 0, sizeof(mng_ztxt)}; +#else + {MNG_UINT_zTXt, mng_init_ztxt, mng_free_ztxt, mng_read_ztxt, mng_write_ztxt, mng_assign_ztxt, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ZTXT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_zTXt)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_ztxt (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_zTXt, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_ztxtp)pChunk)->iKeywordsize = iKeywordsize; + ((mng_ztxtp)pChunk)->iCompression = iCompression; + ((mng_ztxtp)pChunk)->iTextsize = iTextsize; + + if (iKeywordsize) + { + MNG_ALLOC (pData, ((mng_ztxtp)pChunk)->zKeyword, iKeywordsize + 1); + MNG_COPY (((mng_ztxtp)pChunk)->zKeyword, zKeyword, iKeywordsize); + } + + if (iTextsize) + { + MNG_ALLOC (pData, ((mng_ztxtp)pChunk)->zText, iTextsize + 1); + MNG_COPY (((mng_ztxtp)pChunk)->zText, zText, iTextsize); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ZTXT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iTXt +mng_retcode MNG_DECL mng_putchunk_itxt (mng_handle hHandle, + mng_uint32 iKeywordsize, + mng_pchar zKeyword, + mng_uint8 iCompressionflag, + mng_uint8 iCompressionmethod, + mng_uint32 iLanguagesize, + mng_pchar zLanguage, + mng_uint32 iTranslationsize, + mng_pchar zTranslation, + mng_uint32 iTextsize, + mng_pchar zText) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_iTXt, mng_init_general, mng_free_itxt, mng_read_itxt, mng_write_itxt, mng_assign_itxt, 0, 0, sizeof(mng_itxt)}; +#else + {MNG_UINT_iTXt, mng_init_itxt, mng_free_itxt, mng_read_itxt, mng_write_itxt, mng_assign_itxt, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ITXT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_iTXt)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_itxt (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_iTXt, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_itxtp)pChunk)->iKeywordsize = iKeywordsize; + ((mng_itxtp)pChunk)->iCompressionflag = iCompressionflag; + ((mng_itxtp)pChunk)->iCompressionmethod = iCompressionmethod; + ((mng_itxtp)pChunk)->iLanguagesize = iLanguagesize; + ((mng_itxtp)pChunk)->iTranslationsize = iTranslationsize; + ((mng_itxtp)pChunk)->iTextsize = iTextsize; + + if (iKeywordsize) + { + MNG_ALLOC (pData, ((mng_itxtp)pChunk)->zKeyword, iKeywordsize + 1); + MNG_COPY (((mng_itxtp)pChunk)->zKeyword, zKeyword, iKeywordsize); + } + + if (iLanguagesize) + { + MNG_ALLOC (pData, ((mng_itxtp)pChunk)->zLanguage, iLanguagesize + 1); + MNG_COPY (((mng_itxtp)pChunk)->zLanguage, zLanguage, iLanguagesize); + } + + if (iTranslationsize) + { + MNG_ALLOC (pData, ((mng_itxtp)pChunk)->zTranslation, iTranslationsize + 1); + MNG_COPY (((mng_itxtp)pChunk)->zTranslation, zTranslation, iTranslationsize); + } + + if (iTextsize) + { + MNG_ALLOC (pData, ((mng_itxtp)pChunk)->zText, iTextsize + 1); + MNG_COPY (((mng_itxtp)pChunk)->zText, zText, iTextsize); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ITXT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_bKGD +mng_retcode MNG_DECL mng_putchunk_bkgd (mng_handle hHandle, + mng_bool bEmpty, + mng_uint8 iType, + mng_uint8 iIndex, + mng_uint16 iGray, + mng_uint16 iRed, + mng_uint16 iGreen, + mng_uint16 iBlue) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_bKGD, mng_init_general, mng_free_general, mng_read_bkgd, mng_write_bkgd, mng_assign_general, 0, 0, sizeof(mng_bkgd)}; +#else + {MNG_UINT_bKGD, mng_init_bkgd, mng_free_bkgd, mng_read_bkgd, mng_write_bkgd, mng_assign_bkgd, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_BKGD, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_bKGD)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_bkgd (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_bKGD, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_bkgdp)pChunk)->bEmpty = bEmpty; + ((mng_bkgdp)pChunk)->iType = iType; + ((mng_bkgdp)pChunk)->iIndex = iIndex; + ((mng_bkgdp)pChunk)->iGray = iGray; + ((mng_bkgdp)pChunk)->iRed = iRed; + ((mng_bkgdp)pChunk)->iGreen = iGreen; + ((mng_bkgdp)pChunk)->iBlue = iBlue; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_BKGD, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_pHYs +mng_retcode MNG_DECL mng_putchunk_phys (mng_handle hHandle, + mng_bool bEmpty, + mng_uint32 iSizex, + mng_uint32 iSizey, + mng_uint8 iUnit) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_pHYs, mng_init_general, mng_free_general, mng_read_phys, mng_write_phys, mng_assign_general, 0, 0, sizeof(mng_phys)}; +#else + {MNG_UINT_pHYs, mng_init_phys, mng_free_phys, mng_read_phys, mng_write_phys, mng_assign_phys, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PHYS, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_pHYs)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_phys (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_pHYs, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_physp)pChunk)->bEmpty = bEmpty; + ((mng_physp)pChunk)->iSizex = iSizex; + ((mng_physp)pChunk)->iSizey = iSizey; + ((mng_physp)pChunk)->iUnit = iUnit; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PHYS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sBIT +mng_retcode MNG_DECL mng_putchunk_sbit (mng_handle hHandle, + mng_bool bEmpty, + mng_uint8 iType, + mng_uint8arr4 aBits) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_sBIT, mng_init_general, mng_free_general, mng_read_sbit, mng_write_sbit, mng_assign_general, 0, 0, sizeof(mng_sbit)}; +#else + {MNG_UINT_sBIT, mng_init_sbit, mng_free_sbit, mng_read_sbit, mng_write_sbit, mng_assign_sbit, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SBIT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_sBIT)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_sbit (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_sBIT, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_sbitp)pChunk)->bEmpty = bEmpty; + ((mng_sbitp)pChunk)->iType = iType; + ((mng_sbitp)pChunk)->aBits[0] = aBits[0]; + ((mng_sbitp)pChunk)->aBits[1] = aBits[1]; + ((mng_sbitp)pChunk)->aBits[2] = aBits[2]; + ((mng_sbitp)pChunk)->aBits[3] = aBits[3]; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SBIT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sPLT +mng_retcode MNG_DECL mng_putchunk_splt (mng_handle hHandle, + mng_bool bEmpty, + mng_uint32 iNamesize, + mng_pchar zName, + mng_uint8 iSampledepth, + mng_uint32 iEntrycount, + mng_ptr pEntries) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_sPLT, mng_init_general, mng_free_splt, mng_read_splt, mng_write_splt, mng_assign_splt, 0, 0, sizeof(mng_splt)}; +#else + {MNG_UINT_sPLT, mng_init_splt, mng_free_splt, mng_read_splt, mng_write_splt, mng_assign_splt, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SPLT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_sPLT)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_splt (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_sPLT, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_spltp)pChunk)->bEmpty = bEmpty; + ((mng_spltp)pChunk)->iNamesize = iNamesize; + ((mng_spltp)pChunk)->iSampledepth = iSampledepth; + ((mng_spltp)pChunk)->iEntrycount = iEntrycount; + + if (iNamesize) + { + MNG_ALLOC (pData, ((mng_spltp)pChunk)->zName, iNamesize + 1); + MNG_COPY (((mng_spltp)pChunk)->zName, zName, iNamesize); + } + + if (iEntrycount) + { + mng_uint32 iSize = iEntrycount * ((iSampledepth >> 1) + 2); + + MNG_ALLOC (pData, ((mng_spltp)pChunk)->pEntries, iSize); + MNG_COPY (((mng_spltp)pChunk)->pEntries, pEntries, iSize); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SPLT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_hIST +mng_retcode MNG_DECL mng_putchunk_hist (mng_handle hHandle, + mng_uint32 iEntrycount, + mng_uint16arr aEntries) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_hIST, mng_init_general, mng_free_general, mng_read_hist, mng_write_hist, mng_assign_general, 0, 0, sizeof(mng_hist)}; +#else + {MNG_UINT_hIST, mng_init_hist, mng_free_hist, mng_read_hist, mng_write_hist, mng_assign_hist, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_HIST, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_hIST)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_hist (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_hIST, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_histp)pChunk)->iEntrycount = iEntrycount; + + MNG_COPY (((mng_histp)pChunk)->aEntries, aEntries, sizeof (mng_uint16arr)); + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_HIST, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_tIME +mng_retcode MNG_DECL mng_putchunk_time (mng_handle hHandle, + mng_uint16 iYear, + mng_uint8 iMonth, + mng_uint8 iDay, + mng_uint8 iHour, + mng_uint8 iMinute, + mng_uint8 iSecond) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_tIME, mng_init_general, mng_free_general, mng_read_time, mng_write_time, mng_assign_general, 0, 0, sizeof(mng_time)}; +#else + {MNG_UINT_tIME, mng_init_time, mng_free_time, mng_read_time, mng_write_time, mng_assign_time, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TIME, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_tIME)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_time (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_tIME, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_timep)pChunk)->iYear = iYear; + ((mng_timep)pChunk)->iMonth = iMonth; + ((mng_timep)pChunk)->iDay = iDay; + ((mng_timep)pChunk)->iHour = iHour; + ((mng_timep)pChunk)->iMinute = iMinute; + ((mng_timep)pChunk)->iSecond = iSecond; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TIME, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_putchunk_mhdr (mng_handle hHandle, + mng_uint32 iWidth, + mng_uint32 iHeight, + mng_uint32 iTicks, + mng_uint32 iLayercount, + mng_uint32 iFramecount, + mng_uint32 iPlaytime, + mng_uint32 iSimplicity) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_MHDR, mng_init_general, mng_free_general, mng_read_mhdr, mng_write_mhdr, mng_assign_general, 0, 0, sizeof(mng_mhdr)}; +#else + {MNG_UINT_MHDR, mng_init_mhdr, mng_free_mhdr, mng_read_mhdr, mng_write_mhdr, mng_assign_mhdr, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MHDR, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must be very first! */ + if (pData->iFirstchunkadded != 0) + MNG_ERROR (pData, MNG_SEQUENCEERROR) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_MHDR)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_mhdr (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_MHDR, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_mhdrp)pChunk)->iWidth = iWidth; + ((mng_mhdrp)pChunk)->iHeight = iHeight; + ((mng_mhdrp)pChunk)->iTicks = iTicks; + ((mng_mhdrp)pChunk)->iLayercount = iLayercount; + ((mng_mhdrp)pChunk)->iFramecount = iFramecount; + ((mng_mhdrp)pChunk)->iPlaytime = iPlaytime; + ((mng_mhdrp)pChunk)->iSimplicity = iSimplicity; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_putchunk_mend (mng_handle hHandle) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_MEND, mng_init_general, mng_free_general, mng_read_mend, mng_write_mend, mng_assign_general, 0, 0, sizeof(mng_mend)}; +#else + {MNG_UINT_MEND, mng_init_mend, mng_free_mend, mng_read_mend, mng_write_mend, mng_assign_mend, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MEND, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_MEND)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_mend (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_MEND, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + + pData->bCreating = MNG_FALSE; /* should be last chunk !!! */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MEND, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_LOOP +mng_retcode MNG_DECL mng_putchunk_loop (mng_handle hHandle, + mng_uint8 iLevel, + mng_uint32 iRepeat, + mng_uint8 iTermination, + mng_uint32 iItermin, + mng_uint32 iItermax, + mng_uint32 iCount, + mng_uint32p pSignals) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_LOOP, mng_init_general, mng_free_loop, mng_read_loop, mng_write_loop, mng_assign_loop, 0, 0, sizeof(mng_loop)}; +#else + {MNG_UINT_LOOP, mng_init_loop, mng_free_loop, mng_read_loop, mng_write_loop, mng_assign_loop, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_LOOP, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_LOOP)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_loop (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_LOOP, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_loopp)pChunk)->iLevel = iLevel; + ((mng_loopp)pChunk)->iRepeat = iRepeat; + ((mng_loopp)pChunk)->iTermination = iTermination; + ((mng_loopp)pChunk)->iItermin = iItermin; + ((mng_loopp)pChunk)->iItermax = iItermax; + ((mng_loopp)pChunk)->iCount = iCount; + ((mng_loopp)pChunk)->pSignals = pSignals; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_LOOP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_putchunk_endl (mng_handle hHandle, + mng_uint8 iLevel) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_ENDL, mng_init_general, mng_free_general, mng_read_endl, mng_write_endl, mng_assign_general, 0, 0, sizeof(mng_endl)}; +#else + {MNG_UINT_ENDL, mng_init_endl, mng_free_endl, mng_read_endl, mng_write_endl, mng_assign_endl, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ENDL, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_ENDL)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_endl (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_ENDL, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_endlp)pChunk)->iLevel = iLevel; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ENDL, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DEFI +mng_retcode MNG_DECL mng_putchunk_defi (mng_handle hHandle, + mng_uint16 iObjectid, + mng_uint8 iDonotshow, + mng_uint8 iConcrete, + mng_bool bHasloca, + mng_int32 iXlocation, + mng_int32 iYlocation, + mng_bool bHasclip, + mng_int32 iLeftcb, + mng_int32 iRightcb, + mng_int32 iTopcb, + mng_int32 iBottomcb) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_DEFI, mng_init_general, mng_free_general, mng_read_defi, mng_write_defi, mng_assign_general, 0, 0, sizeof(mng_defi)}; +#else + {MNG_UINT_DEFI, mng_init_defi, mng_free_defi, mng_read_defi, mng_write_defi, mng_assign_defi, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DEFI, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_DEFI)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_defi (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_DEFI, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_defip)pChunk)->iObjectid = iObjectid; + ((mng_defip)pChunk)->iDonotshow = iDonotshow; + ((mng_defip)pChunk)->iConcrete = iConcrete; + ((mng_defip)pChunk)->bHasloca = bHasloca; + ((mng_defip)pChunk)->iXlocation = iXlocation; + ((mng_defip)pChunk)->iYlocation = iYlocation; + ((mng_defip)pChunk)->bHasclip = bHasclip; + ((mng_defip)pChunk)->iLeftcb = iLeftcb; + ((mng_defip)pChunk)->iRightcb = iRightcb; + ((mng_defip)pChunk)->iTopcb = iTopcb; + ((mng_defip)pChunk)->iBottomcb = iBottomcb; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DEFI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_BASI +mng_retcode MNG_DECL mng_putchunk_basi (mng_handle hHandle, + mng_uint32 iWidth, + mng_uint32 iHeight, + mng_uint8 iBitdepth, + mng_uint8 iColortype, + mng_uint8 iCompression, + mng_uint8 iFilter, + mng_uint8 iInterlace, + mng_uint16 iRed, + mng_uint16 iGreen, + mng_uint16 iBlue, + mng_uint16 iAlpha, + mng_uint8 iViewable) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_BASI, mng_init_general, mng_free_general, mng_read_basi, mng_write_basi, mng_assign_general, 0, 0, sizeof(mng_basi)}; +#else + {MNG_UINT_BASI, mng_init_basi, mng_free_basi, mng_read_basi, mng_write_basi, mng_assign_basi, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_BASI, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_BASI)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_basi (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_BASI, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_basip)pChunk)->iWidth = iWidth; + ((mng_basip)pChunk)->iHeight = iHeight; + ((mng_basip)pChunk)->iBitdepth = iBitdepth; + ((mng_basip)pChunk)->iColortype = iColortype; + ((mng_basip)pChunk)->iCompression = iCompression; + ((mng_basip)pChunk)->iFilter = iFilter; + ((mng_basip)pChunk)->iInterlace = iInterlace; + ((mng_basip)pChunk)->iRed = iRed; + ((mng_basip)pChunk)->iGreen = iGreen; + ((mng_basip)pChunk)->iBlue = iBlue; + ((mng_basip)pChunk)->iAlpha = iAlpha; + ((mng_basip)pChunk)->iViewable = iViewable; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_BASI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_CLON +mng_retcode MNG_DECL mng_putchunk_clon (mng_handle hHandle, + mng_uint16 iSourceid, + mng_uint16 iCloneid, + mng_uint8 iClonetype, + mng_uint8 iDonotshow, + mng_uint8 iConcrete, + mng_bool bHasloca, + mng_uint8 iLocationtype, + mng_int32 iLocationx, + mng_int32 iLocationy) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_CLON, mng_init_general, mng_free_general, mng_read_clon, mng_write_clon, mng_assign_general, 0, 0, sizeof(mng_clon)}; +#else + {MNG_UINT_CLON, mng_init_clon, mng_free_clon, mng_read_clon, mng_write_clon, mng_assign_clon, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_CLON, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_CLON)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_clon (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_CLON, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_clonp)pChunk)->iSourceid = iSourceid; + ((mng_clonp)pChunk)->iCloneid = iCloneid; + ((mng_clonp)pChunk)->iClonetype = iClonetype; + ((mng_clonp)pChunk)->iDonotshow = iDonotshow; + ((mng_clonp)pChunk)->iConcrete = iConcrete; + ((mng_clonp)pChunk)->bHasloca = bHasloca; + ((mng_clonp)pChunk)->iLocationtype = iLocationtype; + ((mng_clonp)pChunk)->iLocationx = iLocationx; + ((mng_clonp)pChunk)->iLocationy = iLocationy; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_CLON, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +mng_retcode MNG_DECL mng_putchunk_past (mng_handle hHandle, + mng_uint16 iDestid, + mng_uint8 iTargettype, + mng_int32 iTargetx, + mng_int32 iTargety, + mng_uint32 iCount) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_PAST, mng_init_general, mng_free_past, mng_read_past, mng_write_past, mng_assign_past, 0, 0, sizeof(mng_past)}; +#else + {MNG_UINT_PAST, mng_init_past, mng_free_past, mng_read_past, mng_write_past, mng_assign_past, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PAST, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_PAST)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_past (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_PAST, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_pastp)pChunk)->iDestid = iDestid; + ((mng_pastp)pChunk)->iTargettype = iTargettype; + ((mng_pastp)pChunk)->iTargetx = iTargetx; + ((mng_pastp)pChunk)->iTargety = iTargety; + ((mng_pastp)pChunk)->iCount = iCount; + + if (iCount) + MNG_ALLOC (pData, ((mng_pastp)pChunk)->pSources, iCount * sizeof (mng_past_source)); + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PAST, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +mng_retcode MNG_DECL mng_putchunk_past_src (mng_handle hHandle, + mng_uint32 iEntry, + mng_uint16 iSourceid, + mng_uint8 iComposition, + mng_uint8 iOrientation, + mng_uint8 iOffsettype, + mng_int32 iOffsetx, + mng_int32 iOffsety, + mng_uint8 iBoundarytype, + mng_int32 iBoundaryl, + mng_int32 iBoundaryr, + mng_int32 iBoundaryt, + mng_int32 iBoundaryb) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_past_sourcep pEntry; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PAST_SRC, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + + pChunk = pData->pLastchunk; /* last one must have been PAST ! */ + + if (((mng_chunk_headerp)pChunk)->iChunkname != MNG_UINT_PAST) + MNG_ERROR (pData, MNG_NOCORRCHUNK) + /* index out of bounds ? */ + if (iEntry >= ((mng_pastp)pChunk)->iCount) + MNG_ERROR (pData, MNG_INVALIDENTRYIX) + /* address proper entry */ + pEntry = ((mng_pastp)pChunk)->pSources + iEntry; + + pEntry->iSourceid = iSourceid; /* fill entry */ + pEntry->iComposition = iComposition; + pEntry->iOrientation = iOrientation; + pEntry->iOffsettype = iOffsettype; + pEntry->iOffsetx = iOffsetx; + pEntry->iOffsety = iOffsety; + pEntry->iBoundarytype = iBoundarytype; + pEntry->iBoundaryl = iBoundaryl; + pEntry->iBoundaryr = iBoundaryr; + pEntry->iBoundaryt = iBoundaryt; + pEntry->iBoundaryb = iBoundaryb; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PAST_SRC, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DISC +mng_retcode MNG_DECL mng_putchunk_disc (mng_handle hHandle, + mng_uint32 iCount, + mng_uint16p pObjectids) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_DISC, mng_init_general, mng_free_disc, mng_read_disc, mng_write_disc, mng_assign_disc, 0, 0, sizeof(mng_disc)}; +#else + {MNG_UINT_DISC, mng_init_disc, mng_free_disc, mng_read_disc, mng_write_disc, mng_assign_disc, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DISC, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_DISC)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_disc (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_DISC, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_discp)pChunk)->iCount = iCount; + + if (iCount) + { + mng_uint32 iSize = iCount * sizeof (mng_uint32); + + MNG_ALLOC (pData, ((mng_discp)pChunk)->pObjectids, iSize); + MNG_COPY (((mng_discp)pChunk)->pObjectids, pObjectids, iSize); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DISC, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_BACK +mng_retcode MNG_DECL mng_putchunk_back (mng_handle hHandle, + mng_uint16 iRed, + mng_uint16 iGreen, + mng_uint16 iBlue, + mng_uint8 iMandatory, + mng_uint16 iImageid, + mng_uint8 iTile) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_BACK, mng_init_general, mng_free_general, mng_read_back, mng_write_back, mng_assign_general, 0, 0, sizeof(mng_back)}; +#else + {MNG_UINT_BACK, mng_init_back, mng_free_back, mng_read_back, mng_write_back, mng_assign_back, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_BACK, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_BACK)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_back (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_BACK, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_backp)pChunk)->iRed = iRed; + ((mng_backp)pChunk)->iGreen = iGreen; + ((mng_backp)pChunk)->iBlue = iBlue; + ((mng_backp)pChunk)->iMandatory = iMandatory; + ((mng_backp)pChunk)->iImageid = iImageid; + ((mng_backp)pChunk)->iTile = iTile; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_BACK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_FRAM +mng_retcode MNG_DECL mng_putchunk_fram (mng_handle hHandle, + mng_bool bEmpty, + mng_uint8 iMode, + mng_uint32 iNamesize, + mng_pchar zName, + mng_uint8 iChangedelay, + mng_uint8 iChangetimeout, + mng_uint8 iChangeclipping, + mng_uint8 iChangesyncid, + mng_uint32 iDelay, + mng_uint32 iTimeout, + mng_uint8 iBoundarytype, + mng_int32 iBoundaryl, + mng_int32 iBoundaryr, + mng_int32 iBoundaryt, + mng_int32 iBoundaryb, + mng_uint32 iCount, + mng_uint32p pSyncids) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_FRAM, mng_init_general, mng_free_fram, mng_read_fram, mng_write_fram, mng_assign_fram, 0, 0, sizeof(mng_fram)}; +#else + {MNG_UINT_FRAM, mng_init_fram, mng_free_fram, mng_read_fram, mng_write_fram, mng_assign_fram, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_FRAM, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_FRAM)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_fram (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_FRAM, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_framp)pChunk)->bEmpty = bEmpty; + ((mng_framp)pChunk)->iMode = iMode; + ((mng_framp)pChunk)->iNamesize = iNamesize; + ((mng_framp)pChunk)->iChangedelay = iChangedelay; + ((mng_framp)pChunk)->iChangetimeout = iChangetimeout; + ((mng_framp)pChunk)->iChangeclipping = iChangeclipping; + ((mng_framp)pChunk)->iChangesyncid = iChangesyncid; + ((mng_framp)pChunk)->iDelay = iDelay; + ((mng_framp)pChunk)->iTimeout = iTimeout; + ((mng_framp)pChunk)->iBoundarytype = iBoundarytype; + ((mng_framp)pChunk)->iBoundaryl = iBoundaryl; + ((mng_framp)pChunk)->iBoundaryr = iBoundaryr; + ((mng_framp)pChunk)->iBoundaryt = iBoundaryt; + ((mng_framp)pChunk)->iBoundaryb = iBoundaryb; + ((mng_framp)pChunk)->iCount = iCount; + + if (iNamesize) + { + MNG_ALLOC (pData, ((mng_framp)pChunk)->zName, iNamesize + 1); + MNG_COPY (((mng_framp)pChunk)->zName, zName, iNamesize); + } + + if (iCount) + { + mng_uint32 iSize = iCount * sizeof (mng_uint32); + + MNG_ALLOC (pData, ((mng_framp)pChunk)->pSyncids, iSize); + MNG_COPY (((mng_framp)pChunk)->pSyncids, pSyncids, iSize); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_FRAM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MOVE +mng_retcode MNG_DECL mng_putchunk_move (mng_handle hHandle, + mng_uint16 iFirstid, + mng_uint16 iLastid, + mng_uint8 iMovetype, + mng_int32 iMovex, + mng_int32 iMovey) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_MOVE, mng_init_general, mng_free_general, mng_read_move, mng_write_move, mng_assign_general, 0, 0, sizeof(mng_move)}; +#else + {MNG_UINT_MOVE, mng_init_move, mng_free_move, mng_read_move, mng_write_move, mng_assign_move, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MOVE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_MOVE)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_move (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_MOVE, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_movep)pChunk)->iFirstid = iFirstid; + ((mng_movep)pChunk)->iLastid = iLastid; + ((mng_movep)pChunk)->iMovetype = iMovetype; + ((mng_movep)pChunk)->iMovex = iMovex; + ((mng_movep)pChunk)->iMovey = iMovey; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MOVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_CLIP +mng_retcode MNG_DECL mng_putchunk_clip (mng_handle hHandle, + mng_uint16 iFirstid, + mng_uint16 iLastid, + mng_uint8 iCliptype, + mng_int32 iClipl, + mng_int32 iClipr, + mng_int32 iClipt, + mng_int32 iClipb) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_CLIP, mng_init_general, mng_free_general, mng_read_clip, mng_write_clip, mng_assign_general, 0, 0, sizeof(mng_clip)}; +#else + {MNG_UINT_CLIP, mng_init_clip, mng_free_clip, mng_read_clip, mng_write_clip, mng_assign_clip, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_CLIP, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_CLIP)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_clip (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_CLIP, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_clipp)pChunk)->iFirstid = iFirstid; + ((mng_clipp)pChunk)->iLastid = iLastid; + ((mng_clipp)pChunk)->iCliptype = iCliptype; + ((mng_clipp)pChunk)->iClipl = iClipl; + ((mng_clipp)pChunk)->iClipr = iClipr; + ((mng_clipp)pChunk)->iClipt = iClipt; + ((mng_clipp)pChunk)->iClipb = iClipb; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_CLIP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SHOW +mng_retcode MNG_DECL mng_putchunk_show (mng_handle hHandle, + mng_bool bEmpty, + mng_uint16 iFirstid, + mng_uint16 iLastid, + mng_uint8 iMode) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_SHOW, mng_init_general, mng_free_general, mng_read_show, mng_write_show, mng_assign_general, 0, 0, sizeof(mng_show)}; +#else + {MNG_UINT_SHOW, mng_init_show, mng_free_show, mng_read_show, mng_write_show, mng_assign_show, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SHOW, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_SHOW)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_show (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_SHOW, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_showp)pChunk)->bEmpty = bEmpty; + ((mng_showp)pChunk)->iFirstid = iFirstid; + ((mng_showp)pChunk)->iLastid = iLastid; + ((mng_showp)pChunk)->iMode = iMode; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SHOW, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_TERM +mng_retcode MNG_DECL mng_putchunk_term (mng_handle hHandle, + mng_uint8 iTermaction, + mng_uint8 iIteraction, + mng_uint32 iDelay, + mng_uint32 iItermax) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_TERM, mng_init_general, mng_free_general, mng_read_term, mng_write_term, mng_assign_general, 0, 0, sizeof(mng_term)}; +#else + {MNG_UINT_TERM, mng_init_term, mng_free_term, mng_read_term, mng_write_term, mng_assign_term, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TERM, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_term (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_TERM, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_termp)pChunk)->iTermaction = iTermaction; + ((mng_termp)pChunk)->iIteraction = iIteraction; + ((mng_termp)pChunk)->iDelay = iDelay; + ((mng_termp)pChunk)->iItermax = iItermax; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_TERM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SAVE +mng_retcode MNG_DECL mng_putchunk_save (mng_handle hHandle, + mng_bool bEmpty, + mng_uint8 iOffsettype, + mng_uint32 iCount) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_SAVE, mng_init_general, mng_free_save, mng_read_save, mng_write_save, mng_assign_save, 0, 0, sizeof(mng_save)}; +#else + {MNG_UINT_SAVE, mng_init_save, mng_free_save, mng_read_save, mng_write_save, mng_assign_save, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SAVE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_SAVE)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_save (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_SAVE, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_savep)pChunk)->bEmpty = bEmpty; + ((mng_savep)pChunk)->iOffsettype = iOffsettype; + ((mng_savep)pChunk)->iCount = iCount; + + if (iCount) + MNG_ALLOC (pData, ((mng_savep)pChunk)->pEntries, iCount * sizeof (mng_save_entry)); + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SAVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_putchunk_save_entry (mng_handle hHandle, + mng_uint32 iEntry, + mng_uint8 iEntrytype, + mng_uint32arr2 iOffset, + mng_uint32arr2 iStarttime, + mng_uint32 iLayernr, + mng_uint32 iFramenr, + mng_uint32 iNamesize, + mng_pchar zName) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_save_entryp pEntry; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SAVE_ENTRY, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + + pChunk = pData->pLastchunk; /* last one must have been SAVE ! */ + + if (((mng_chunk_headerp)pChunk)->iChunkname != MNG_UINT_SAVE) + MNG_ERROR (pData, MNG_NOCORRCHUNK) + /* index out of bounds ? */ + if (iEntry >= ((mng_savep)pChunk)->iCount) + MNG_ERROR (pData, MNG_INVALIDENTRYIX) + /* address proper entry */ + pEntry = ((mng_savep)pChunk)->pEntries + iEntry; + + pEntry->iEntrytype = iEntrytype; /* fill entry */ + pEntry->iOffset[0] = iOffset[0]; + pEntry->iOffset[1] = iOffset[1]; + pEntry->iStarttime[0] = iStarttime[0]; + pEntry->iStarttime[1] = iStarttime[1]; + pEntry->iLayernr = iLayernr; + pEntry->iFramenr = iFramenr; + pEntry->iNamesize = iNamesize; + + if (iNamesize) + { + MNG_ALLOC (pData, pEntry->zName, iNamesize + 1); + MNG_COPY (pEntry->zName, zName, iNamesize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SAVE_ENTRY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SEEK +mng_retcode MNG_DECL mng_putchunk_seek (mng_handle hHandle, + mng_uint32 iNamesize, + mng_pchar zName) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_SEEK, mng_init_general, mng_free_seek, mng_read_seek, mng_write_seek, mng_assign_seek, 0, 0, sizeof(mng_seek)}; +#else + {MNG_UINT_SEEK, mng_init_seek, mng_free_seek, mng_read_seek, mng_write_seek, mng_assign_seek, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SEEK, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_SEEK)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_seek (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_SEEK, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_seekp)pChunk)->iNamesize = iNamesize; + + if (iNamesize) + { + MNG_ALLOC (pData, ((mng_seekp)pChunk)->zName, iNamesize + 1); + MNG_COPY (((mng_seekp)pChunk)->zName, zName, iNamesize); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_SEEK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_eXPI +mng_retcode MNG_DECL mng_putchunk_expi (mng_handle hHandle, + mng_uint16 iSnapshotid, + mng_uint32 iNamesize, + mng_pchar zName) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_eXPI, mng_init_general, mng_free_expi, mng_read_expi, mng_write_expi, mng_assign_general, 0, 0, sizeof(mng_expi)}; +#else + {MNG_UINT_eXPI, mng_init_expi, mng_free_expi, mng_read_expi, mng_write_expi, mng_assign_expi, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_EXPI, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_eXPI)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_expi (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_eXPI, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_expip)pChunk)->iSnapshotid = iSnapshotid; + ((mng_expip)pChunk)->iNamesize = iNamesize; + + if (iNamesize) + { + MNG_ALLOC (pData, ((mng_expip)pChunk)->zName, iNamesize + 1); + MNG_COPY (((mng_expip)pChunk)->zName, zName, iNamesize); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_EXPI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_fPRI +mng_retcode MNG_DECL mng_putchunk_fpri (mng_handle hHandle, + mng_uint8 iDeltatype, + mng_uint8 iPriority) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_fPRI, mng_init_general, mng_free_general, mng_read_fpri, mng_write_fpri, mng_assign_general, 0, 0, sizeof(mng_fpri)}; +#else + {MNG_UINT_fPRI, mng_init_fpri, mng_free_fpri, mng_read_fpri, mng_write_fpri, mng_assign_fpri, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_FPRI, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_fPRI)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_fpri (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_fPRI, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_fprip)pChunk)->iDeltatype = iDeltatype; + ((mng_fprip)pChunk)->iPriority = iPriority; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_FPRI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_nEED +mng_retcode MNG_DECL mng_putchunk_need (mng_handle hHandle, + mng_uint32 iKeywordssize, + mng_pchar zKeywords) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_nEED, mng_init_general, mng_free_need, mng_read_need, mng_write_need, mng_assign_need, 0, 0, sizeof(mng_need)}; +#else + {MNG_UINT_nEED, mng_init_need, mng_free_need, mng_read_need, mng_write_need, mng_assign_need, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_NEED, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_nEED)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_need (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_nEED, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_needp)pChunk)->iKeywordssize = iKeywordssize; + + if (iKeywordssize) + { + MNG_ALLOC (pData, ((mng_needp)pChunk)->zKeywords, iKeywordssize + 1); + MNG_COPY (((mng_needp)pChunk)->zKeywords, zKeywords, iKeywordssize); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_NEED, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_pHYg +mng_retcode MNG_DECL mng_putchunk_phyg (mng_handle hHandle, + mng_bool bEmpty, + mng_uint32 iSizex, + mng_uint32 iSizey, + mng_uint8 iUnit) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_pHYg, mng_init_general, mng_free_general, mng_read_phyg, mng_write_phyg, mng_assign_general, 0, 0, sizeof(mng_phyg)}; +#else + {MNG_UINT_pHYg, mng_init_phyg, mng_free_phyg, mng_read_phyg, mng_write_phyg, mng_assign_phyg, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PHYG, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_pHYg)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_phyg (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_pHYg, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_phygp)pChunk)->bEmpty = bEmpty; + ((mng_phygp)pChunk)->iSizex = iSizex; + ((mng_phygp)pChunk)->iSizey = iSizey; + ((mng_phygp)pChunk)->iUnit = iUnit; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PHYG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG + +mng_retcode MNG_DECL mng_putchunk_jhdr (mng_handle hHandle, + mng_uint32 iWidth, + mng_uint32 iHeight, + mng_uint8 iColortype, + mng_uint8 iImagesampledepth, + mng_uint8 iImagecompression, + mng_uint8 iImageinterlace, + mng_uint8 iAlphasampledepth, + mng_uint8 iAlphacompression, + mng_uint8 iAlphafilter, + mng_uint8 iAlphainterlace) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_JHDR, mng_init_general, mng_free_general, mng_read_jhdr, mng_write_jhdr, mng_assign_general, 0, 0, sizeof(mng_jhdr)}; +#else + {MNG_UINT_JHDR, mng_init_jhdr, mng_free_jhdr, mng_read_jhdr, mng_write_jhdr, mng_assign_jhdr, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JHDR, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_JHDR)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_jhdr (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_JHDR, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_jhdrp)pChunk)->iWidth = iWidth; + ((mng_jhdrp)pChunk)->iHeight = iHeight; + ((mng_jhdrp)pChunk)->iColortype = iColortype; + ((mng_jhdrp)pChunk)->iImagesampledepth = iImagesampledepth; + ((mng_jhdrp)pChunk)->iImagecompression = iImagecompression; + ((mng_jhdrp)pChunk)->iImageinterlace = iImageinterlace; + ((mng_jhdrp)pChunk)->iAlphasampledepth = iAlphasampledepth; + ((mng_jhdrp)pChunk)->iAlphacompression = iAlphacompression; + ((mng_jhdrp)pChunk)->iAlphafilter = iAlphafilter; + ((mng_jhdrp)pChunk)->iAlphainterlace = iAlphainterlace; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG + +mng_retcode MNG_DECL mng_putchunk_jdat (mng_handle hHandle, + mng_uint32 iRawlen, + mng_ptr pRawdata) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_JDAT, mng_init_general, mng_free_jdat, mng_read_jdat, mng_write_jdat, mng_assign_jdat, 0, 0, sizeof(mng_jdat)}; +#else + {MNG_UINT_JDAT, mng_init_jdat, mng_free_jdat, mng_read_jdat, mng_write_jdat, mng_assign_jdat, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JDAT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR or JHDR first! */ + if ((pData->iFirstchunkadded != MNG_UINT_MHDR) && + (pData->iFirstchunkadded != MNG_UINT_JHDR) ) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_JDAT)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_jdat (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_JDAT, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_jdatp)pChunk)->iDatasize = iRawlen; + + if (iRawlen) + { + MNG_ALLOC (pData, ((mng_jdatp)pChunk)->pData, iRawlen); + MNG_COPY (((mng_jdatp)pChunk)->pData, pRawdata, iRawlen); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JDAT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG + +mng_retcode MNG_DECL mng_putchunk_jdaa (mng_handle hHandle, + mng_uint32 iRawlen, + mng_ptr pRawdata) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_JDAA, mng_init_general, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0, sizeof(mng_jdaa)}; +#else + {MNG_UINT_JDAA, mng_init_jdaa, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JDAA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR or JHDR first! */ + if ((pData->iFirstchunkadded != MNG_UINT_MHDR) && + (pData->iFirstchunkadded != MNG_UINT_JHDR) ) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_JDAA)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_jdaa (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_JDAA, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_jdaap)pChunk)->iDatasize = iRawlen; + + if (iRawlen) + { + MNG_ALLOC (pData, ((mng_jdaap)pChunk)->pData, iRawlen); + MNG_COPY (((mng_jdaap)pChunk)->pData, pRawdata, iRawlen); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JDAA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG + +mng_retcode MNG_DECL mng_putchunk_jsep (mng_handle hHandle) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_JSEP, mng_init_general, mng_free_general, mng_read_jsep, mng_write_jsep, mng_assign_general, 0, 0, sizeof(mng_jsep)}; +#else + {MNG_UINT_JSEP, mng_init_jsep, mng_free_jsep, mng_read_jsep, mng_write_jsep, mng_assign_jsep, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JSEP, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR or JHDR first! */ + if ((pData->iFirstchunkadded != MNG_UINT_MHDR) && + (pData->iFirstchunkadded != MNG_UINT_JHDR) ) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_JSEP)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_jsep (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_JSEP, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_JSEP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode MNG_DECL mng_putchunk_dhdr (mng_handle hHandle, + mng_uint16 iObjectid, + mng_uint8 iImagetype, + mng_uint8 iDeltatype, + mng_uint32 iBlockwidth, + mng_uint32 iBlockheight, + mng_uint32 iBlockx, + mng_uint32 iBlocky) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_DHDR, mng_init_general, mng_free_general, mng_read_dhdr, mng_write_dhdr, mng_assign_general, 0, 0, sizeof(mng_dhdr)}; +#else + {MNG_UINT_DHDR, mng_init_dhdr, mng_free_dhdr, mng_read_dhdr, mng_write_dhdr, mng_assign_dhdr, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DHDR, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_DHDR)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_dhdr (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_DHDR, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_dhdrp)pChunk)->iObjectid = iObjectid; + ((mng_dhdrp)pChunk)->iImagetype = iImagetype; + ((mng_dhdrp)pChunk)->iDeltatype = iDeltatype; + ((mng_dhdrp)pChunk)->iBlockwidth = iBlockwidth; + ((mng_dhdrp)pChunk)->iBlockheight = iBlockheight; + ((mng_dhdrp)pChunk)->iBlockx = iBlockx; + ((mng_dhdrp)pChunk)->iBlocky = iBlocky; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode MNG_DECL mng_putchunk_prom (mng_handle hHandle, + mng_uint8 iColortype, + mng_uint8 iSampledepth, + mng_uint8 iFilltype) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_PROM, mng_init_general, mng_free_general, mng_read_prom, mng_write_prom, mng_assign_general, 0, 0, sizeof(mng_prom)}; +#else + {MNG_UINT_PROM, mng_init_prom, mng_free_prom, mng_read_prom, mng_write_prom, mng_assign_prom, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PROM, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_PROM)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_prom (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_PROM, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_promp)pChunk)->iColortype = iColortype; + ((mng_promp)pChunk)->iSampledepth = iSampledepth; + ((mng_promp)pChunk)->iFilltype = iFilltype; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PROM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode MNG_DECL mng_putchunk_ipng (mng_handle hHandle) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_IPNG, mng_init_general, mng_free_general, mng_read_ipng, mng_write_ipng, mng_assign_general, 0, 0, sizeof(mng_ipng)}; +#else + {MNG_UINT_IPNG, mng_init_ipng, mng_free_ipng, mng_read_ipng, mng_write_ipng, mng_assign_ipng, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IPNG, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_IPNG)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_ipng (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_IPNG, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IPNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode MNG_DECL mng_putchunk_pplt (mng_handle hHandle, + mng_uint8 iDeltatype, + mng_uint32 iCount) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_PPLT, mng_init_general, mng_free_general, mng_read_pplt, mng_write_pplt, mng_assign_general, 0, 0, sizeof(mng_pplt)}; +#else + {MNG_UINT_PPLT, mng_init_pplt, mng_free_pplt, mng_read_pplt, mng_write_pplt, mng_assign_pplt, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PPLT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_PPLT)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_pplt (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_PPLT, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_ppltp)pChunk)->iDeltatype = iDeltatype; + ((mng_ppltp)pChunk)->iCount = iCount; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PPLT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode MNG_DECL mng_putchunk_pplt_entry (mng_handle hHandle, + mng_uint32 iEntry, + mng_uint16 iRed, + mng_uint16 iGreen, + mng_uint16 iBlue, + mng_uint16 iAlpha) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_pplt_entryp pEntry; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PPLT_ENTRY, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + + pChunk = pData->pLastchunk; /* last one must have been PPLT ! */ + + if (((mng_chunk_headerp)pChunk)->iChunkname != MNG_UINT_PPLT) + MNG_ERROR (pData, MNG_NOCORRCHUNK) + + /* index out of bounds ? */ + if (iEntry >= ((mng_ppltp)pChunk)->iCount) + MNG_ERROR (pData, MNG_INVALIDENTRYIX) + /* address proper entry */ + pEntry = (mng_pplt_entryp)(((mng_ppltp)pChunk)->aEntries) + iEntry; + + pEntry->iRed = (mng_uint8)iRed; /* fill the entry */ + pEntry->iGreen = (mng_uint8)iGreen; + pEntry->iBlue = (mng_uint8)iBlue; + pEntry->iAlpha = (mng_uint8)iAlpha; + pEntry->bUsed = MNG_TRUE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_PPLT_ENTRY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG +mng_retcode MNG_DECL mng_putchunk_ijng (mng_handle hHandle) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_IJNG, mng_init_general, mng_free_general, mng_read_ijng, mng_write_ijng, mng_assign_general, 0, 0, sizeof(mng_ijng)}; +#else + {MNG_UINT_IJNG, mng_init_ijng, mng_free_ijng, mng_read_ijng, mng_write_ijng, mng_assign_ijng, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IJNG, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_IJNG)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_ijng (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_IJNG, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_IJNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode MNG_DECL mng_putchunk_drop (mng_handle hHandle, + mng_uint32 iCount, + mng_chunkidp pChunknames) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_DROP, mng_init_general, mng_free_drop, mng_read_drop, mng_write_drop, mng_assign_drop, 0, 0, sizeof(mng_drop)}; +#else + {MNG_UINT_DROP, mng_init_drop, mng_free_drop, mng_read_drop, mng_write_drop, mng_assign_drop, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DROP, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_DROP)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_drop (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_DROP, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_dropp)pChunk)->iCount = iCount; + + if (iCount) + { + mng_uint32 iSize = iCount * sizeof (mng_chunkid); + + MNG_ALLOC (pData, ((mng_dropp)pChunk)->pChunknames, iSize); + MNG_COPY (((mng_dropp)pChunk)->pChunknames, pChunknames, iSize); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DROP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DBYK +mng_retcode MNG_DECL mng_putchunk_dbyk (mng_handle hHandle, + mng_chunkid iChunkname, + mng_uint8 iPolarity, + mng_uint32 iKeywordssize, + mng_pchar zKeywords) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_DBYK, mng_init_general, mng_free_dbyk, mng_read_dbyk, mng_write_dbyk, mng_assign_dbyk, 0, 0, sizeof(mng_dbyk)}; +#else + {MNG_UINT_DBYK, mng_init_dbyk, mng_free_dbyk, mng_read_dbyk, mng_write_dbyk, mng_assign_dbyk, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DBYK, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_DBYK)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_dbyk (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_DBYK, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_dbykp)pChunk)->iChunkname = iChunkname; + ((mng_dbykp)pChunk)->iPolarity = iPolarity; + ((mng_dbykp)pChunk)->iKeywordssize = iKeywordssize; + + if (iKeywordssize) + { + MNG_ALLOC (pData, ((mng_dbykp)pChunk)->zKeywords, iKeywordssize + 1); + MNG_COPY (((mng_dbykp)pChunk)->zKeywords, zKeywords, iKeywordssize); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_DBYK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR +mng_retcode MNG_DECL mng_putchunk_ordr (mng_handle hHandle, + mng_uint32 iCount) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_ORDR, mng_init_general, mng_free_ordr, mng_read_ordr, mng_write_ordr, mng_assign_ordr, 0, 0, sizeof(mng_ordr)}; +#else + {MNG_UINT_ORDR, mng_init_ordr, mng_free_ordr, mng_read_ordr, mng_write_ordr, mng_assign_ordr, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ORDR, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_ORDR)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_ordr (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_ORDR, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_ordrp)pChunk)->iCount = iCount; + + if (iCount) + MNG_ALLOC (pData, ((mng_ordrp)pChunk)->pEntries, iCount * sizeof (mng_ordr_entry)); + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ORDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR +mng_retcode MNG_DECL mng_putchunk_ordr_entry (mng_handle hHandle, + mng_uint32 iEntry, + mng_chunkid iChunkname, + mng_uint8 iOrdertype) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_ordr_entryp pEntry; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ORDR_ENTRY, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + + pChunk = pData->pLastchunk; /* last one must have been ORDR ! */ + + if (((mng_chunk_headerp)pChunk)->iChunkname != MNG_UINT_ORDR) + MNG_ERROR (pData, MNG_NOCORRCHUNK) + /* index out of bounds ? */ + if (iEntry >= ((mng_ordrp)pChunk)->iCount) + MNG_ERROR (pData, MNG_INVALIDENTRYIX) + /* address proper entry */ + pEntry = ((mng_ordrp)pChunk)->pEntries + iEntry; + + pEntry->iChunkname = iChunkname; /* fill the entry */ + pEntry->iOrdertype = iOrdertype; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_ORDR_ENTRY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MAGN +mng_retcode MNG_DECL mng_putchunk_magn (mng_handle hHandle, + mng_uint16 iFirstid, + mng_uint16 iLastid, + mng_uint16 iMethodX, + mng_uint16 iMX, + mng_uint16 iMY, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint16 iMT, + mng_uint16 iMB, + mng_uint16 iMethodY) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_MAGN, mng_init_general, mng_free_general, mng_read_magn, mng_write_magn, mng_assign_general, 0, 0, sizeof(mng_magn)}; +#else + {MNG_UINT_MAGN, mng_init_magn, mng_free_magn, mng_read_magn, mng_write_magn, mng_assign_magn, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MAGN, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_MAGN)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_magn (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_MAGN, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_magnp)pChunk)->iFirstid = iFirstid; + ((mng_magnp)pChunk)->iLastid = iLastid; + ((mng_magnp)pChunk)->iMethodX = (mng_uint8)iMethodX; + ((mng_magnp)pChunk)->iMX = iMX; + ((mng_magnp)pChunk)->iMY = iMY; + ((mng_magnp)pChunk)->iML = iML; + ((mng_magnp)pChunk)->iMR = iMR; + ((mng_magnp)pChunk)->iMT = iMT; + ((mng_magnp)pChunk)->iMB = iMB; + ((mng_magnp)pChunk)->iMethodY = (mng_uint8)iMethodY; + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MAGN, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_MPNG_PROPOSAL +MNG_EXT mng_retcode MNG_DECL mng_putchunk_mpng (mng_handle hHandle, + mng_uint32 iFramewidth, + mng_uint32 iFrameheight, + mng_uint16 iNumplays, + mng_uint16 iTickspersec, + mng_uint8 iCompressionmethod, + mng_uint32 iCount) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_mpNG, mng_init_general, mng_free_mpng, mng_read_mpng, mng_write_mpng, mng_assign_mpng, 0, 0, sizeof(mng_mpng)}; +#else + {MNG_UINT_mpNG, mng_init_mpng, mng_free_mpng, mng_read_mpng, mng_write_mpng, mng_assign_mpng, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MPNG, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a IHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_IHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_mpng (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_mpNG, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_mpngp)pChunk)->iFramewidth = iFramewidth; + ((mng_mpngp)pChunk)->iFrameheight = iFrameheight; + ((mng_mpngp)pChunk)->iNumplays = iNumplays; + ((mng_mpngp)pChunk)->iTickspersec = iTickspersec; + ((mng_mpngp)pChunk)->iCompressionmethod = iCompressionmethod; + ((mng_mpngp)pChunk)->iFramessize = iCount * sizeof (mng_mpng_frame); + + if (iCount) + MNG_ALLOC (pData, ((mng_mpngp)pChunk)->pFrames, ((mng_mpngp)pChunk)->iFramessize); + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MPNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_MPNG_PROPOSAL +MNG_EXT mng_retcode MNG_DECL mng_putchunk_mpng_frame (mng_handle hHandle, + mng_uint32 iEntry, + mng_uint32 iX, + mng_uint32 iY, + mng_uint32 iWidth, + mng_uint32 iHeight, + mng_int32 iXoffset, + mng_int32 iYoffset, + mng_uint16 iTicks) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_mpng_framep pFrame; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MPNG_FRAME, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a IHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_IHDR) + MNG_ERROR (pData, MNG_NOHEADER) + + pChunk = pData->pLastchunk; /* last one must have been mpNG ! */ + + if (((mng_chunk_headerp)pChunk)->iChunkname != MNG_UINT_mpNG) + MNG_ERROR (pData, MNG_NOCORRCHUNK) + /* index out of bounds ? */ + if (iEntry >= (((mng_mpngp)pChunk)->iFramessize / sizeof (mng_mpng_frame))) + MNG_ERROR (pData, MNG_INVALIDENTRYIX) + /* address proper entry */ + pFrame = ((mng_mpngp)pChunk)->pFrames + iEntry; + /* fill entry */ + pFrame->iX = iX; + pFrame->iY = iY; + pFrame->iWidth = iWidth; + pFrame->iHeight = iHeight; + pFrame->iXoffset = iXoffset; + pFrame->iYoffset = iYoffset; + pFrame->iTicks = iTicks; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_MPNG_FRAME, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_evNT +mng_retcode MNG_DECL mng_putchunk_evnt (mng_handle hHandle, + mng_uint32 iCount) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_evNT, mng_init_general, mng_free_evnt, mng_read_evnt, mng_write_evnt, mng_assign_evnt, 0, 0, sizeof(mng_evnt)}; +#else + {MNG_UINT_evNT, mng_init_evnt, mng_free_evnt, mng_read_evnt, mng_write_evnt, mng_assign_evnt, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_EVNT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, MNG_UINT_evNT)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_evnt (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_evNT, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_evntp)pChunk)->iCount = iCount; + + if (iCount) + MNG_ALLOC (pData, ((mng_evntp)pChunk)->pEntries, iCount * sizeof (mng_evnt_entry)); + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_EVNT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_putchunk_evnt_entry (mng_handle hHandle, + mng_uint32 iEntry, + mng_uint8 iEventtype, + mng_uint8 iMasktype, + mng_int32 iLeft, + mng_int32 iRight, + mng_int32 iTop, + mng_int32 iBottom, + mng_uint16 iObjectid, + mng_uint8 iIndex, + mng_uint32 iSegmentnamesize, + mng_pchar zSegmentname) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_evnt_entryp pEntry; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_EVNT_ENTRY, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a MHDR first! */ + if (pData->iFirstchunkadded != MNG_UINT_MHDR) + MNG_ERROR (pData, MNG_NOHEADER) + + pChunk = pData->pLastchunk; /* last one must have been evNT ! */ + + if (((mng_chunk_headerp)pChunk)->iChunkname != MNG_UINT_evNT) + MNG_ERROR (pData, MNG_NOCORRCHUNK) + /* index out of bounds ? */ + if (iEntry >= ((mng_evntp)pChunk)->iCount) + MNG_ERROR (pData, MNG_INVALIDENTRYIX) + /* address proper entry */ + pEntry = ((mng_evntp)pChunk)->pEntries + iEntry; + /* fill entry */ + pEntry->iEventtype = iEventtype; + pEntry->iMasktype = iMasktype; + pEntry->iLeft = iLeft; + pEntry->iRight = iRight; + pEntry->iTop = iTop; + pEntry->iBottom = iBottom; + pEntry->iObjectid = iObjectid; + pEntry->iIndex = iIndex; + pEntry->iSegmentnamesize = iSegmentnamesize; + + if (iSegmentnamesize) + { + MNG_ALLOC (pData, pEntry->zSegmentname, iSegmentnamesize + 1); + MNG_COPY (pEntry->zSegmentname, zSegmentname, iSegmentnamesize); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_EVNT_ENTRY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_putchunk_unknown (mng_handle hHandle, + mng_chunkid iChunkname, + mng_uint32 iRawlen, + mng_ptr pRawdata) +{ + mng_datap pData; + mng_chunkp pChunk; + mng_retcode iRetcode; +#ifndef MNG_OPTIMIZE_CHUNKREADER + mng_chunk_header sChunkheader = +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + {MNG_UINT_HUH, mng_init_general, mng_free_unknown, mng_read_unknown, mng_write_unknown, mng_assign_unknown, 0, 0, sizeof(mng_unknown_chunk)}; +#else + {MNG_UINT_HUH, mng_init_unknown, mng_free_unknown, mng_read_unknown, mng_write_unknown, mng_assign_unknown, 0, 0}; +#endif +#else + mng_chunk_header sChunkheader; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_UNKNOWN, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must have had a header first! */ + if (pData->iFirstchunkadded == 0) + MNG_ERROR (pData, MNG_NOHEADER) + /* prevent misplaced TERM ! */ + if (!check_term (pData, iChunkname)) + MNG_ERROR (pData, MNG_TERMSEQERROR) + /* create the chunk */ +#ifndef MNG_OPTIMIZE_CHUNKREADER +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#else + iRetcode = mng_init_unknown (pData, &sChunkheader, &pChunk); +#endif +#else + mng_get_chunkheader(MNG_UINT_HUH, &sChunkheader); + iRetcode = mng_init_general (pData, &sChunkheader, &pChunk); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fill the chunk */ + ((mng_unknown_chunkp)pChunk)->sHeader.iChunkname = iChunkname; + ((mng_unknown_chunkp)pChunk)->iDatasize = iRawlen; + + if (iRawlen) + { + MNG_ALLOC (pData, ((mng_unknown_chunkp)pChunk)->pData, iRawlen); + MNG_COPY (((mng_unknown_chunkp)pChunk)->pData, pRawdata, iRawlen); + } + + mng_add_chunk (pData, pChunk); /* add it to the list */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTCHUNK_UNKNOWN, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_WRITE_PROCS */ + +/* ************************************************************************** */ +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_getimgdata_seq (mng_handle hHandle, + mng_uint32 iSeqnr, + mng_uint32 iCanvasstyle, + mng_getcanvasline fGetcanvasline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETIMGDATA_SEQ, MNG_LC_START); +#endif + + + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETIMGDATA_SEQ, MNG_LC_END); +#endif + + return MNG_FNNOTIMPLEMENTED; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_getimgdata_chunkseq (mng_handle hHandle, + mng_uint32 iSeqnr, + mng_uint32 iCanvasstyle, + mng_getcanvasline fGetcanvasline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETIMGDATA_CHUNKSEQ, MNG_LC_START); +#endif + + + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETIMGDATA_CHUNKSEQ, MNG_LC_END); +#endif + + return MNG_FNNOTIMPLEMENTED; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_getimgdata_chunk (mng_handle hHandle, + mng_handle hChunk, + mng_uint32 iCanvasstyle, + mng_getcanvasline fGetcanvasline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETIMGDATA_CHUNK, MNG_LC_START); +#endif + + + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETIMGDATA_CHUNK, MNG_LC_END); +#endif + + return MNG_FNNOTIMPLEMENTED; +} + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_WRITE_PROCS + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_putimgdata_ihdr (mng_handle hHandle, + mng_uint32 iWidth, + mng_uint32 iHeight, + mng_uint8 iColortype, + mng_uint8 iBitdepth, + mng_uint8 iCompression, + mng_uint8 iFilter, + mng_uint8 iInterlace, + mng_uint32 iCanvasstyle, + mng_getcanvasline fGetcanvasline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTIMGDATA_IHDR, MNG_LC_START); +#endif + + + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTIMGDATA_IHDR, MNG_LC_END); +#endif + + return MNG_FNNOTIMPLEMENTED; +} + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +mng_retcode MNG_DECL mng_putimgdata_jhdr (mng_handle hHandle, + mng_uint32 iWidth, + mng_uint32 iHeight, + mng_uint8 iColortype, + mng_uint8 iBitdepth, + mng_uint8 iCompression, + mng_uint8 iInterlace, + mng_uint8 iAlphaBitdepth, + mng_uint8 iAlphaCompression, + mng_uint8 iAlphaFilter, + mng_uint8 iAlphaInterlace, + mng_uint32 iCanvasstyle, + mng_getcanvasline fGetcanvasline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTIMGDATA_JHDR, MNG_LC_START); +#endif + + + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_PUTIMGDATA_JHDR, MNG_LC_END); +#endif + + return MNG_FNNOTIMPLEMENTED; +} +#endif + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_updatemngheader (mng_handle hHandle, + mng_uint32 iFramecount, + mng_uint32 iLayercount, + mng_uint32 iPlaytime) +{ + mng_datap pData; + mng_chunkp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_UPDATEMNGHEADER, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must be a MNG animation! */ + if ((pData->eImagetype != mng_it_mng) || (pData->iFirstchunkadded != MNG_UINT_MHDR)) + MNG_ERROR (pData, MNG_NOMHDR) + + pChunk = pData->pFirstchunk; /* get the first chunk */ + /* and update the variables */ + ((mng_mhdrp)pChunk)->iFramecount = iFramecount; + ((mng_mhdrp)pChunk)->iLayercount = iLayercount; + ((mng_mhdrp)pChunk)->iPlaytime = iPlaytime; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_UPDATEMNGHEADER, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_updatemngsimplicity (mng_handle hHandle, + mng_uint32 iSimplicity) +{ + mng_datap pData; + mng_chunkp pChunk; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_UPDATEMNGSIMPLICITY, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = (mng_datap)hHandle; /* and make it addressable */ + + if (!pData->bCreating) /* aren't we creating a new file ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID) + /* must be a MNG animation! */ + if ((pData->eImagetype != mng_it_mng) || (pData->iFirstchunkadded != MNG_UINT_MHDR)) + MNG_ERROR (pData, MNG_NOMHDR) + + pChunk = pData->pFirstchunk; /* get the first chunk */ + /* and update the variable */ + ((mng_mhdrp)pChunk)->iSimplicity = iSimplicity; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_UPDATEMNGSIMPLICITY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_WRITE_PROCS */ + +/* ************************************************************************** */ + +#endif /* MNG_ACCESS_CHUNKS */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + + + diff --git a/Source/LibMNG/libmng_cms.c b/Source/LibMNG/libmng_cms.c index f215271..999575f 100644 --- a/Source/LibMNG/libmng_cms.c +++ b/Source/LibMNG/libmng_cms.c @@ -1,758 +1,758 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_cms.c copyright (c) 2000-2004 G.Juyn * */ -/* * version : 1.0.9 * */ -/* * * */ -/* * purpose : color management routines (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the color management routines * */ -/* * * */ -/* * changes : 0.5.1 - 05/01/2000 - G.Juyn * */ -/* * - B001(105795) - fixed a typo and misconception about * */ -/* * freeing allocated gamma-table. (reported by Marti Maria) * */ -/* * 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/09/2000 - G.Juyn * */ -/* * - filled application-based color-management routines * */ -/* * 0.5.1 - 05/11/2000 - G.Juyn * */ -/* * - added creatememprofile * */ -/* * - added callback error-reporting support * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - changed trace to macro for callback error-reporting * */ -/* * * */ -/* * 0.5.2 - 06/10/2000 - G.Juyn * */ -/* * - fixed some compilation-warnings (contrib Jason Morris) * */ -/* * * */ -/* * 0.5.3 - 06/21/2000 - G.Juyn * */ -/* * - fixed problem with color-correction for stored images * */ -/* * 0.5.3 - 06/23/2000 - G.Juyn * */ -/* * - fixed problem with incorrect gamma-correction * */ -/* * * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 0.9.3 - 08/31/2000 - G.Juyn * */ -/* * - fixed sRGB precedence for gamma_only corection * */ -/* * * */ -/* * 0.9.4 - 12/16/2000 - G.Juyn * */ -/* * - fixed mixup of data- & function-pointers (thanks Dimitri)* */ -/* * * */ -/* * 1.0.1 - 03/31/2001 - G.Juyn * */ -/* * - ignore gamma=0 (see png-list for more info) * */ -/* * 1.0.1 - 04/25/2001 - G.Juyn (reported by Gregg Kelly) * */ -/* * - fixed problem with cms profile being created multiple * */ -/* * times when both iCCP & cHRM/gAMA are present * */ -/* * 1.0.1 - 04/25/2001 - G.Juyn * */ -/* * - moved mng_clear_cms to libmng_cms * */ -/* * 1.0.1 - 05/02/2001 - G.Juyn * */ -/* * - added "default" sRGB generation (Thanks Marti!) * */ -/* * * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * 1.0.5 - 09/19/2002 - G.Juyn * */ -/* * - optimized color-correction routines * */ -/* * 1.0.5 - 09/23/2002 - G.Juyn * */ -/* * - added in-memory color-correction of abstract images * */ -/* * 1.0.5 - 11/08/2002 - G.Juyn * */ -/* * - fixed issues in init_app_cms() * */ -/* * * */ -/* * 1.0.6 - 04/11/2003 - G.Juyn * */ -/* * - B719420 - fixed several MNG_APP_CMS problems * */ -/* * 1.0.6 - 07/11/2003 - G. R-P * */ -/* * - added conditional MNG_SKIPCHUNK_cHRM/iCCP * */ -/* * * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_objects.h" -#include "libmng_cms.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_DISPLAY_PROCS - -/* ************************************************************************** */ -/* * * */ -/* * Little CMS helper routines * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_LCMS - -#define MNG_CMS_FLAGS 0 - -/* ************************************************************************** */ - -void mnglcms_initlibrary () -{ - cmsErrorAction (LCMS_ERROR_IGNORE); /* LCMS should ignore errors! */ -} - -/* ************************************************************************** */ - -mng_cmsprof mnglcms_createfileprofile (mng_pchar zFilename) -{ - return cmsOpenProfileFromFile (zFilename, "r"); -} - -/* ************************************************************************** */ - -mng_cmsprof mnglcms_creatememprofile (mng_uint32 iProfilesize, - mng_ptr pProfile) -{ - return cmsOpenProfileFromMem (pProfile, iProfilesize); -} - -/* ************************************************************************** */ - -mng_cmsprof mnglcms_createsrgbprofile (void) -{ - cmsCIExyY D65; - cmsCIExyYTRIPLE Rec709Primaries = { - {0.6400, 0.3300, 1.0}, - {0.3000, 0.6000, 1.0}, - {0.1500, 0.0600, 1.0} - }; - LPGAMMATABLE Gamma24[3]; - mng_cmsprof hsRGB; - - cmsWhitePointFromTemp(6504, &D65); - Gamma24[0] = Gamma24[1] = Gamma24[2] = cmsBuildGamma(256, 2.4); - hsRGB = cmsCreateRGBProfile(&D65, &Rec709Primaries, Gamma24); - cmsFreeGamma(Gamma24[0]); - - return hsRGB; -} - -/* ************************************************************************** */ - -void mnglcms_freeprofile (mng_cmsprof hProf) -{ - cmsCloseProfile (hProf); - return; -} - -/* ************************************************************************** */ - -void mnglcms_freetransform (mng_cmstrans hTrans) -{ -/* B001 start */ - cmsDeleteTransform (hTrans); -/* B001 end */ - return; -} - -/* ************************************************************************** */ - -mng_retcode mng_clear_cms (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CLEAR_CMS, MNG_LC_START); -#endif - - if (pData->hTrans) /* transformation still active ? */ - mnglcms_freetransform (pData->hTrans); - - pData->hTrans = 0; - - if (pData->hProf1) /* file profile still active ? */ - mnglcms_freeprofile (pData->hProf1); - - pData->hProf1 = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CLEAR_CMS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_LCMS */ - -/* ************************************************************************** */ -/* * * */ -/* * Color-management initialization & correction routines * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_LCMS - -mng_retcode mng_init_full_cms (mng_datap pData, - mng_bool bGlobal, - mng_bool bObject, - mng_bool bRetrobj) -{ - mng_cmsprof hProf; - mng_cmstrans hTrans; - mng_imagep pImage = MNG_NULL; - mng_imagedatap pBuf = MNG_NULL; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_FULL_CMS, MNG_LC_START); -#endif - - if (bObject) /* use object if present ? */ - { /* current object ? */ - if ((mng_imagep)pData->pCurrentobj) - pImage = (mng_imagep)pData->pCurrentobj; - else /* if not; use object 0 */ - pImage = (mng_imagep)pData->pObjzero; - } - - if (bRetrobj) /* retrieving from an object ? */ - pImage = (mng_imagep)pData->pRetrieveobj; - - if (pImage) /* are we using an object ? */ - pBuf = pImage->pImgbuf; /* then address the buffer */ - - if ((!pBuf) || (!pBuf->bCorrected)) /* is the buffer already corrected ? */ - { -#ifndef MNG_SKIPCHUNK_iCCP - if (((pBuf) && (pBuf->bHasICCP)) || ((bGlobal) && (pData->bHasglobalICCP))) - { - if (!pData->hProf2) /* output profile not defined ? */ - { /* then assume sRGB !! */ - pData->hProf2 = mnglcms_createsrgbprofile (); - - if (!pData->hProf2) /* handle error ? */ - MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); - } - - if ((pBuf) && (pBuf->bHasICCP)) /* generate a profile handle */ - hProf = cmsOpenProfileFromMem (pBuf->pProfile, pBuf->iProfilesize); - else - hProf = cmsOpenProfileFromMem (pData->pGlobalProfile, pData->iGlobalProfilesize); - - pData->hProf1 = hProf; /* save for future use */ - - if (!hProf) /* handle error ? */ - MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); - -#ifndef MNG_NO_16BIT_SUPPORT - if (pData->bIsRGBA16) /* 16-bit intermediates ? */ - hTrans = cmsCreateTransform (hProf, TYPE_RGBA_16_SE, - pData->hProf2, TYPE_RGBA_16_SE, - INTENT_PERCEPTUAL, MNG_CMS_FLAGS); - else -#endif - hTrans = cmsCreateTransform (hProf, TYPE_RGBA_8, - pData->hProf2, TYPE_RGBA_8, - INTENT_PERCEPTUAL, MNG_CMS_FLAGS); - - pData->hTrans = hTrans; /* save for future use */ - - if (!hTrans) /* handle error ? */ - MNG_ERRORL (pData, MNG_LCMS_NOTRANS); - /* load color-correction routine */ - pData->fCorrectrow = (mng_fptr)mng_correct_full_cms; - - return MNG_NOERROR; /* and done */ - } - else -#endif - if (((pBuf) && (pBuf->bHasSRGB)) || ((bGlobal) && (pData->bHasglobalSRGB))) - { - mng_uint8 iIntent; - - if (pData->bIssRGB) /* sRGB system ? */ - return MNG_NOERROR; /* no conversion required */ - - if (!pData->hProf3) /* sRGB profile not defined ? */ - { /* then create it implicitly !! */ - pData->hProf3 = mnglcms_createsrgbprofile (); - - if (!pData->hProf3) /* handle error ? */ - MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); - } - - hProf = pData->hProf3; /* convert from sRGB profile */ - - if ((pBuf) && (pBuf->bHasSRGB)) /* determine rendering intent */ - iIntent = pBuf->iRenderingintent; - else - iIntent = pData->iGlobalRendintent; - - if (pData->bIsRGBA16) /* 16-bit intermediates ? */ - hTrans = cmsCreateTransform (hProf, TYPE_RGBA_16_SE, - pData->hProf2, TYPE_RGBA_16_SE, - iIntent, MNG_CMS_FLAGS); - else - hTrans = cmsCreateTransform (hProf, TYPE_RGBA_8, - pData->hProf2, TYPE_RGBA_8, - iIntent, MNG_CMS_FLAGS); - - pData->hTrans = hTrans; /* save for future use */ - - if (!hTrans) /* handle error ? */ - MNG_ERRORL (pData, MNG_LCMS_NOTRANS); - /* load color-correction routine */ - pData->fCorrectrow = (mng_fptr)mng_correct_full_cms; - - return MNG_NOERROR; /* and done */ - } - else - if ( (((pBuf) && (pBuf->bHasCHRM)) || ((bGlobal) && (pData->bHasglobalCHRM))) && - ( ((pBuf) && (pBuf->bHasGAMA) && (pBuf->iGamma > 0)) || - ((bGlobal) && (pData->bHasglobalGAMA) && (pData->iGlobalGamma > 0)) ) ) - { - mng_CIExyY sWhitepoint; - mng_CIExyYTRIPLE sPrimaries; - mng_gammatabp pGammatable[3]; - mng_float dGamma; - - if (!pData->hProf2) /* output profile not defined ? */ - { /* then assume sRGB !! */ - pData->hProf2 = mnglcms_createsrgbprofile (); - - if (!pData->hProf2) /* handle error ? */ - MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); - } - -#ifndef MNG_SKIPCHUNK_cHRM - if ((pBuf) && (pBuf->bHasCHRM)) /* local cHRM ? */ - { - sWhitepoint.x = (mng_float)pBuf->iWhitepointx / 100000; - sWhitepoint.y = (mng_float)pBuf->iWhitepointy / 100000; - sPrimaries.Red.x = (mng_float)pBuf->iPrimaryredx / 100000; - sPrimaries.Red.y = (mng_float)pBuf->iPrimaryredy / 100000; - sPrimaries.Green.x = (mng_float)pBuf->iPrimarygreenx / 100000; - sPrimaries.Green.y = (mng_float)pBuf->iPrimarygreeny / 100000; - sPrimaries.Blue.x = (mng_float)pBuf->iPrimarybluex / 100000; - sPrimaries.Blue.y = (mng_float)pBuf->iPrimarybluey / 100000; - } - else - { - sWhitepoint.x = (mng_float)pData->iGlobalWhitepointx / 100000; - sWhitepoint.y = (mng_float)pData->iGlobalWhitepointy / 100000; - sPrimaries.Red.x = (mng_float)pData->iGlobalPrimaryredx / 100000; - sPrimaries.Red.y = (mng_float)pData->iGlobalPrimaryredy / 100000; - sPrimaries.Green.x = (mng_float)pData->iGlobalPrimarygreenx / 100000; - sPrimaries.Green.y = (mng_float)pData->iGlobalPrimarygreeny / 100000; - sPrimaries.Blue.x = (mng_float)pData->iGlobalPrimarybluex / 100000; - sPrimaries.Blue.y = (mng_float)pData->iGlobalPrimarybluey / 100000; - } -#endif - - sWhitepoint.Y = /* Y component is always 1.0 */ - sPrimaries.Red.Y = - sPrimaries.Green.Y = - sPrimaries.Blue.Y = 1.0; - - if ((pBuf) && (pBuf->bHasGAMA)) /* get the gamma value */ - dGamma = (mng_float)pBuf->iGamma / 100000; - else - dGamma = (mng_float)pData->iGlobalGamma / 100000; - - dGamma = pData->dViewgamma / dGamma; - - pGammatable [0] = /* and build the lookup tables */ - pGammatable [1] = - pGammatable [2] = cmsBuildGamma (256, dGamma); - - if (!pGammatable [0]) /* enough memory ? */ - MNG_ERRORL (pData, MNG_LCMS_NOMEM); - /* create the profile */ - hProf = cmsCreateRGBProfile (&sWhitepoint, &sPrimaries, pGammatable); - - cmsFreeGamma (pGammatable [0]); /* free the temporary gamma tables ? */ - /* yes! but just the one! */ - - pData->hProf1 = hProf; /* save for future use */ - - if (!hProf) /* handle error ? */ - MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); - - if (pData->bIsRGBA16) /* 16-bit intermediates ? */ - hTrans = cmsCreateTransform (hProf, TYPE_RGBA_16_SE, - pData->hProf2, TYPE_RGBA_16_SE, - INTENT_PERCEPTUAL, MNG_CMS_FLAGS); - else - hTrans = cmsCreateTransform (hProf, TYPE_RGBA_8, - pData->hProf2, TYPE_RGBA_8, - INTENT_PERCEPTUAL, MNG_CMS_FLAGS); - - pData->hTrans = hTrans; /* save for future use */ - - if (!hTrans) /* handle error ? */ - MNG_ERRORL (pData, MNG_LCMS_NOTRANS); - /* load color-correction routine */ - pData->fCorrectrow = (mng_fptr)mng_correct_full_cms; - - return MNG_NOERROR; /* and done */ - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_FULL_CMS, MNG_LC_END); -#endif - /* if we get here, we'll only do gamma */ - return mng_init_gamma_only (pData, bGlobal, bObject, bRetrobj); -} -#endif /* MNG_INCLUDE_LCMS */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_LCMS -mng_retcode mng_correct_full_cms (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CORRECT_FULL_CMS, MNG_LC_START); -#endif - - cmsDoTransform (pData->hTrans, pData->pRGBArow, pData->pRGBArow, pData->iRowsamples); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CORRECT_FULL_CMS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_LCMS */ - -/* ************************************************************************** */ - -#if defined(MNG_GAMMA_ONLY) || defined(MNG_FULL_CMS) || defined(MNG_APP_CMS) -mng_retcode mng_init_gamma_only (mng_datap pData, - mng_bool bGlobal, - mng_bool bObject, - mng_bool bRetrobj) -{ - mng_float dGamma; - mng_imagep pImage = MNG_NULL; - mng_imagedatap pBuf = MNG_NULL; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_GAMMA_ONLY, MNG_LC_START); -#endif - - if (bObject) /* use object if present ? */ - { /* current object ? */ - if ((mng_imagep)pData->pCurrentobj) - pImage = (mng_imagep)pData->pCurrentobj; - else /* if not; use object 0 */ - pImage = (mng_imagep)pData->pObjzero; - } - - if (bRetrobj) /* retrieving from an object ? */ - pImage = (mng_imagep)pData->pRetrieveobj; - - if (pImage) /* are we using an object ? */ - pBuf = pImage->pImgbuf; /* then address the buffer */ - - if ((!pBuf) || (!pBuf->bCorrected)) /* is the buffer already corrected ? */ - { - if ((pBuf) && (pBuf->bHasSRGB)) /* get the gamma value */ - dGamma = 0.45455; - else - if ((pBuf) && (pBuf->bHasGAMA)) - dGamma = (mng_float)pBuf->iGamma / 100000; - else - if ((bGlobal) && (pData->bHasglobalSRGB)) - dGamma = 0.45455; - else - if ((bGlobal) && (pData->bHasglobalGAMA)) - dGamma = (mng_float)pData->iGlobalGamma / 100000; - else - dGamma = pData->dDfltimggamma; - - if (dGamma > 0) /* ignore gamma=0 */ - { - dGamma = pData->dViewgamma / (dGamma * pData->dDisplaygamma); - - if (dGamma != pData->dLastgamma) /* lookup table needs to be computed ? */ - { - mng_int32 iX; - - pData->aGammatab [0] = 0; - - for (iX = 1; iX <= 255; iX++) - pData->aGammatab [iX] = (mng_uint8)(pow (iX / 255.0, dGamma) * 255 + 0.5); - - pData->dLastgamma = dGamma; /* keep for next time */ - } - /* load color-correction routine */ - pData->fCorrectrow = (mng_fptr)mng_correct_gamma_only; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_GAMMA_ONLY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_GAMMA_ONLY || MNG_FULL_CMS || MNG_APP_CMS */ - -/* ************************************************************************** */ - -#if defined(MNG_GAMMA_ONLY) || defined(MNG_FULL_CMS) || defined(MNG_APP_CMS) -mng_retcode mng_correct_gamma_only (mng_datap pData) -{ - mng_uint8p pWork; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CORRECT_GAMMA_ONLY, MNG_LC_START); -#endif - - pWork = pData->pRGBArow; /* address intermediate row */ - - if (pData->bIsRGBA16) /* 16-bit intermediate row ? */ - { - - - /* TODO: 16-bit precision gamma processing */ - /* we'll just do the high-order byte for now */ - - - /* convert all samples in the row */ - for (iX = 0; iX < pData->iRowsamples; iX++) - { /* using the precalculated gamma lookup table */ - *pWork = pData->aGammatab [*pWork]; - *(pWork+2) = pData->aGammatab [*(pWork+2)]; - *(pWork+4) = pData->aGammatab [*(pWork+4)]; - - pWork += 8; - } - } - else - { /* convert all samples in the row */ - for (iX = 0; iX < pData->iRowsamples; iX++) - { /* using the precalculated gamma lookup table */ - *pWork = pData->aGammatab [*pWork]; - *(pWork+1) = pData->aGammatab [*(pWork+1)]; - *(pWork+2) = pData->aGammatab [*(pWork+2)]; - - pWork += 4; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CORRECT_GAMMA_ONLY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_GAMMA_ONLY || MNG_FULL_CMS || MNG_APP_CMS */ - -/* ************************************************************************** */ - -#ifdef MNG_APP_CMS -mng_retcode mng_init_app_cms (mng_datap pData, - mng_bool bGlobal, - mng_bool bObject, - mng_bool bRetrobj) -{ - mng_imagep pImage = MNG_NULL; - mng_imagedatap pBuf = MNG_NULL; - mng_bool bDone = MNG_FALSE; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_APP_CMS, MNG_LC_START); -#endif - - if (bObject) /* use object if present ? */ - { /* current object ? */ - if ((mng_imagep)pData->pCurrentobj) - pImage = (mng_imagep)pData->pCurrentobj; - else /* if not; use object 0 */ - pImage = (mng_imagep)pData->pObjzero; - } - - if (bRetrobj) /* retrieving from an object ? */ - pImage = (mng_imagep)pData->pRetrieveobj; - - if (pImage) /* are we using an object ? */ - pBuf = pImage->pImgbuf; /* then address the buffer */ - - if ((!pBuf) || (!pBuf->bCorrected)) /* is the buffer already corrected ? */ - { -#ifndef MNG_SKIPCHUNK_iCCP - if ( (pData->fProcessiccp) && - (((pBuf) && (pBuf->bHasICCP)) || ((bGlobal) && (pData->bHasglobalICCP))) ) - { - mng_uint32 iProfilesize; - mng_ptr pProfile; - - if ((pBuf) && (pBuf->bHasICCP)) /* get the right profile */ - { - iProfilesize = pBuf->iProfilesize; - pProfile = pBuf->pProfile; - } - else - { - iProfilesize = pData->iGlobalProfilesize; - pProfile = pData->pGlobalProfile; - } - /* inform the app */ - if (!pData->fProcessiccp ((mng_handle)pData, iProfilesize, pProfile)) - MNG_ERROR (pData, MNG_APPCMSERROR); - /* load color-correction routine */ - pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; - bDone = MNG_TRUE; - } -#endif - - if ( (pData->fProcesssrgb) && - (((pBuf) && (pBuf->bHasSRGB)) || ((bGlobal) && (pData->bHasglobalSRGB))) ) - { - mng_uint8 iIntent; - - if ((pBuf) && (pBuf->bHasSRGB)) /* determine rendering intent */ - iIntent = pBuf->iRenderingintent; - else - iIntent = pData->iGlobalRendintent; - /* inform the app */ - if (!pData->fProcesssrgb ((mng_handle)pData, iIntent)) - MNG_ERROR (pData, MNG_APPCMSERROR); - /* load color-correction routine */ - pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; - bDone = MNG_TRUE; - } - -#ifndef MNG_SKIPCHUNK_cHRM - if ( (pData->fProcesschroma) && - (((pBuf) && (pBuf->bHasCHRM)) || ((bGlobal) && (pData->bHasglobalCHRM))) ) - { - mng_uint32 iWhitepointx, iWhitepointy; - mng_uint32 iPrimaryredx, iPrimaryredy; - mng_uint32 iPrimarygreenx, iPrimarygreeny; - mng_uint32 iPrimarybluex, iPrimarybluey; - - if ((pBuf) && (pBuf->bHasCHRM)) /* local cHRM ? */ - { - iWhitepointx = pBuf->iWhitepointx; - iWhitepointy = pBuf->iWhitepointy; - iPrimaryredx = pBuf->iPrimaryredx; - iPrimaryredy = pBuf->iPrimaryredy; - iPrimarygreenx = pBuf->iPrimarygreenx; - iPrimarygreeny = pBuf->iPrimarygreeny; - iPrimarybluex = pBuf->iPrimarybluex; - iPrimarybluey = pBuf->iPrimarybluey; - } - else - { - iWhitepointx = pData->iGlobalWhitepointx; - iWhitepointy = pData->iGlobalWhitepointy; - iPrimaryredx = pData->iGlobalPrimaryredx; - iPrimaryredy = pData->iGlobalPrimaryredy; - iPrimarygreenx = pData->iGlobalPrimarygreenx; - iPrimarygreeny = pData->iGlobalPrimarygreeny; - iPrimarybluex = pData->iGlobalPrimarybluex; - iPrimarybluey = pData->iGlobalPrimarybluey; - } - /* inform the app */ - if (!pData->fProcesschroma ((mng_handle)pData, iWhitepointx, iWhitepointy, - iPrimaryredx, iPrimaryredy, - iPrimarygreenx, iPrimarygreeny, - iPrimarybluex, iPrimarybluey)) - MNG_ERROR (pData, MNG_APPCMSERROR); - /* load color-correction routine */ - pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; - bDone = MNG_TRUE; - } -#endif - - if ( (pData->fProcessgamma) && - (((pBuf) && (pBuf->bHasGAMA)) || ((bGlobal) && (pData->bHasglobalGAMA))) ) - { - mng_uint32 iGamma; - - if ((pBuf) && (pBuf->bHasGAMA)) /* get the gamma value */ - iGamma = pBuf->iGamma; - else - iGamma = pData->iGlobalGamma; - /* inform the app */ - if (!pData->fProcessgamma ((mng_handle)pData, iGamma)) - { /* app wants us to use internal routines ! */ - iRetcode = mng_init_gamma_only (pData, bGlobal, bObject, bRetrobj); - if (iRetcode) /* on error bail out */ - return iRetcode; - } - else - { /* load color-correction routine */ - pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; - } - - bDone = MNG_TRUE; - } - - if (!bDone) /* no color-info at all ? */ - { - /* then use default image gamma ! */ - if (!pData->fProcessgamma ((mng_handle)pData, - (mng_uint32)((pData->dDfltimggamma * 100000) + 0.5))) - { /* app wants us to use internal routines ! */ - iRetcode = mng_init_gamma_only (pData, bGlobal, bObject, bRetrobj); - if (iRetcode) /* on error bail out */ - return iRetcode; - } - else - { /* load color-correction routine */ - pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; - } - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_APP_CMS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_APP_CMS */ - -/* ************************************************************************** */ - -#ifdef MNG_APP_CMS -mng_retcode mng_correct_app_cms (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CORRECT_APP_CMS, MNG_LC_START); -#endif - - if (pData->fProcessarow) /* let the app do something with our row */ - if (!pData->fProcessarow ((mng_handle)pData, pData->iRowsamples, - pData->bIsRGBA16, pData->pRGBArow)) - MNG_ERROR (pData, MNG_APPCMSERROR); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CORRECT_APP_CMS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_APP_CMS */ - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_DISPLAY_PROCS */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - - - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_cms.c copyright (c) 2000-2004 G.Juyn * */ +/* * version : 1.0.9 * */ +/* * * */ +/* * purpose : color management routines (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the color management routines * */ +/* * * */ +/* * changes : 0.5.1 - 05/01/2000 - G.Juyn * */ +/* * - B001(105795) - fixed a typo and misconception about * */ +/* * freeing allocated gamma-table. (reported by Marti Maria) * */ +/* * 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/09/2000 - G.Juyn * */ +/* * - filled application-based color-management routines * */ +/* * 0.5.1 - 05/11/2000 - G.Juyn * */ +/* * - added creatememprofile * */ +/* * - added callback error-reporting support * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - changed trace to macro for callback error-reporting * */ +/* * * */ +/* * 0.5.2 - 06/10/2000 - G.Juyn * */ +/* * - fixed some compilation-warnings (contrib Jason Morris) * */ +/* * * */ +/* * 0.5.3 - 06/21/2000 - G.Juyn * */ +/* * - fixed problem with color-correction for stored images * */ +/* * 0.5.3 - 06/23/2000 - G.Juyn * */ +/* * - fixed problem with incorrect gamma-correction * */ +/* * * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 0.9.3 - 08/31/2000 - G.Juyn * */ +/* * - fixed sRGB precedence for gamma_only corection * */ +/* * * */ +/* * 0.9.4 - 12/16/2000 - G.Juyn * */ +/* * - fixed mixup of data- & function-pointers (thanks Dimitri)* */ +/* * * */ +/* * 1.0.1 - 03/31/2001 - G.Juyn * */ +/* * - ignore gamma=0 (see png-list for more info) * */ +/* * 1.0.1 - 04/25/2001 - G.Juyn (reported by Gregg Kelly) * */ +/* * - fixed problem with cms profile being created multiple * */ +/* * times when both iCCP & cHRM/gAMA are present * */ +/* * 1.0.1 - 04/25/2001 - G.Juyn * */ +/* * - moved mng_clear_cms to libmng_cms * */ +/* * 1.0.1 - 05/02/2001 - G.Juyn * */ +/* * - added "default" sRGB generation (Thanks Marti!) * */ +/* * * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * 1.0.5 - 09/19/2002 - G.Juyn * */ +/* * - optimized color-correction routines * */ +/* * 1.0.5 - 09/23/2002 - G.Juyn * */ +/* * - added in-memory color-correction of abstract images * */ +/* * 1.0.5 - 11/08/2002 - G.Juyn * */ +/* * - fixed issues in init_app_cms() * */ +/* * * */ +/* * 1.0.6 - 04/11/2003 - G.Juyn * */ +/* * - B719420 - fixed several MNG_APP_CMS problems * */ +/* * 1.0.6 - 07/11/2003 - G. R-P * */ +/* * - added conditional MNG_SKIPCHUNK_cHRM/iCCP * */ +/* * * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_objects.h" +#include "libmng_cms.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_DISPLAY_PROCS + +/* ************************************************************************** */ +/* * * */ +/* * Little CMS helper routines * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_LCMS + +#define MNG_CMS_FLAGS 0 + +/* ************************************************************************** */ + +void mnglcms_initlibrary () +{ + cmsErrorAction (LCMS_ERROR_IGNORE); /* LCMS should ignore errors! */ +} + +/* ************************************************************************** */ + +mng_cmsprof mnglcms_createfileprofile (mng_pchar zFilename) +{ + return cmsOpenProfileFromFile (zFilename, "r"); +} + +/* ************************************************************************** */ + +mng_cmsprof mnglcms_creatememprofile (mng_uint32 iProfilesize, + mng_ptr pProfile) +{ + return cmsOpenProfileFromMem (pProfile, iProfilesize); +} + +/* ************************************************************************** */ + +mng_cmsprof mnglcms_createsrgbprofile (void) +{ + cmsCIExyY D65; + cmsCIExyYTRIPLE Rec709Primaries = { + {0.6400, 0.3300, 1.0}, + {0.3000, 0.6000, 1.0}, + {0.1500, 0.0600, 1.0} + }; + LPGAMMATABLE Gamma24[3]; + mng_cmsprof hsRGB; + + cmsWhitePointFromTemp(6504, &D65); + Gamma24[0] = Gamma24[1] = Gamma24[2] = cmsBuildGamma(256, 2.4); + hsRGB = cmsCreateRGBProfile(&D65, &Rec709Primaries, Gamma24); + cmsFreeGamma(Gamma24[0]); + + return hsRGB; +} + +/* ************************************************************************** */ + +void mnglcms_freeprofile (mng_cmsprof hProf) +{ + cmsCloseProfile (hProf); + return; +} + +/* ************************************************************************** */ + +void mnglcms_freetransform (mng_cmstrans hTrans) +{ +/* B001 start */ + cmsDeleteTransform (hTrans); +/* B001 end */ + return; +} + +/* ************************************************************************** */ + +mng_retcode mng_clear_cms (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CLEAR_CMS, MNG_LC_START); +#endif + + if (pData->hTrans) /* transformation still active ? */ + mnglcms_freetransform (pData->hTrans); + + pData->hTrans = 0; + + if (pData->hProf1) /* file profile still active ? */ + mnglcms_freeprofile (pData->hProf1); + + pData->hProf1 = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CLEAR_CMS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_LCMS */ + +/* ************************************************************************** */ +/* * * */ +/* * Color-management initialization & correction routines * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_LCMS + +mng_retcode mng_init_full_cms (mng_datap pData, + mng_bool bGlobal, + mng_bool bObject, + mng_bool bRetrobj) +{ + mng_cmsprof hProf; + mng_cmstrans hTrans; + mng_imagep pImage = MNG_NULL; + mng_imagedatap pBuf = MNG_NULL; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_FULL_CMS, MNG_LC_START); +#endif + + if (bObject) /* use object if present ? */ + { /* current object ? */ + if ((mng_imagep)pData->pCurrentobj) + pImage = (mng_imagep)pData->pCurrentobj; + else /* if not; use object 0 */ + pImage = (mng_imagep)pData->pObjzero; + } + + if (bRetrobj) /* retrieving from an object ? */ + pImage = (mng_imagep)pData->pRetrieveobj; + + if (pImage) /* are we using an object ? */ + pBuf = pImage->pImgbuf; /* then address the buffer */ + + if ((!pBuf) || (!pBuf->bCorrected)) /* is the buffer already corrected ? */ + { +#ifndef MNG_SKIPCHUNK_iCCP + if (((pBuf) && (pBuf->bHasICCP)) || ((bGlobal) && (pData->bHasglobalICCP))) + { + if (!pData->hProf2) /* output profile not defined ? */ + { /* then assume sRGB !! */ + pData->hProf2 = mnglcms_createsrgbprofile (); + + if (!pData->hProf2) /* handle error ? */ + MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); + } + + if ((pBuf) && (pBuf->bHasICCP)) /* generate a profile handle */ + hProf = cmsOpenProfileFromMem (pBuf->pProfile, pBuf->iProfilesize); + else + hProf = cmsOpenProfileFromMem (pData->pGlobalProfile, pData->iGlobalProfilesize); + + pData->hProf1 = hProf; /* save for future use */ + + if (!hProf) /* handle error ? */ + MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); + +#ifndef MNG_NO_16BIT_SUPPORT + if (pData->bIsRGBA16) /* 16-bit intermediates ? */ + hTrans = cmsCreateTransform (hProf, TYPE_RGBA_16_SE, + pData->hProf2, TYPE_RGBA_16_SE, + INTENT_PERCEPTUAL, MNG_CMS_FLAGS); + else +#endif + hTrans = cmsCreateTransform (hProf, TYPE_RGBA_8, + pData->hProf2, TYPE_RGBA_8, + INTENT_PERCEPTUAL, MNG_CMS_FLAGS); + + pData->hTrans = hTrans; /* save for future use */ + + if (!hTrans) /* handle error ? */ + MNG_ERRORL (pData, MNG_LCMS_NOTRANS); + /* load color-correction routine */ + pData->fCorrectrow = (mng_fptr)mng_correct_full_cms; + + return MNG_NOERROR; /* and done */ + } + else +#endif + if (((pBuf) && (pBuf->bHasSRGB)) || ((bGlobal) && (pData->bHasglobalSRGB))) + { + mng_uint8 iIntent; + + if (pData->bIssRGB) /* sRGB system ? */ + return MNG_NOERROR; /* no conversion required */ + + if (!pData->hProf3) /* sRGB profile not defined ? */ + { /* then create it implicitly !! */ + pData->hProf3 = mnglcms_createsrgbprofile (); + + if (!pData->hProf3) /* handle error ? */ + MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); + } + + hProf = pData->hProf3; /* convert from sRGB profile */ + + if ((pBuf) && (pBuf->bHasSRGB)) /* determine rendering intent */ + iIntent = pBuf->iRenderingintent; + else + iIntent = pData->iGlobalRendintent; + + if (pData->bIsRGBA16) /* 16-bit intermediates ? */ + hTrans = cmsCreateTransform (hProf, TYPE_RGBA_16_SE, + pData->hProf2, TYPE_RGBA_16_SE, + iIntent, MNG_CMS_FLAGS); + else + hTrans = cmsCreateTransform (hProf, TYPE_RGBA_8, + pData->hProf2, TYPE_RGBA_8, + iIntent, MNG_CMS_FLAGS); + + pData->hTrans = hTrans; /* save for future use */ + + if (!hTrans) /* handle error ? */ + MNG_ERRORL (pData, MNG_LCMS_NOTRANS); + /* load color-correction routine */ + pData->fCorrectrow = (mng_fptr)mng_correct_full_cms; + + return MNG_NOERROR; /* and done */ + } + else + if ( (((pBuf) && (pBuf->bHasCHRM)) || ((bGlobal) && (pData->bHasglobalCHRM))) && + ( ((pBuf) && (pBuf->bHasGAMA) && (pBuf->iGamma > 0)) || + ((bGlobal) && (pData->bHasglobalGAMA) && (pData->iGlobalGamma > 0)) ) ) + { + mng_CIExyY sWhitepoint; + mng_CIExyYTRIPLE sPrimaries; + mng_gammatabp pGammatable[3]; + mng_float dGamma; + + if (!pData->hProf2) /* output profile not defined ? */ + { /* then assume sRGB !! */ + pData->hProf2 = mnglcms_createsrgbprofile (); + + if (!pData->hProf2) /* handle error ? */ + MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); + } + +#ifndef MNG_SKIPCHUNK_cHRM + if ((pBuf) && (pBuf->bHasCHRM)) /* local cHRM ? */ + { + sWhitepoint.x = (mng_float)pBuf->iWhitepointx / 100000; + sWhitepoint.y = (mng_float)pBuf->iWhitepointy / 100000; + sPrimaries.Red.x = (mng_float)pBuf->iPrimaryredx / 100000; + sPrimaries.Red.y = (mng_float)pBuf->iPrimaryredy / 100000; + sPrimaries.Green.x = (mng_float)pBuf->iPrimarygreenx / 100000; + sPrimaries.Green.y = (mng_float)pBuf->iPrimarygreeny / 100000; + sPrimaries.Blue.x = (mng_float)pBuf->iPrimarybluex / 100000; + sPrimaries.Blue.y = (mng_float)pBuf->iPrimarybluey / 100000; + } + else + { + sWhitepoint.x = (mng_float)pData->iGlobalWhitepointx / 100000; + sWhitepoint.y = (mng_float)pData->iGlobalWhitepointy / 100000; + sPrimaries.Red.x = (mng_float)pData->iGlobalPrimaryredx / 100000; + sPrimaries.Red.y = (mng_float)pData->iGlobalPrimaryredy / 100000; + sPrimaries.Green.x = (mng_float)pData->iGlobalPrimarygreenx / 100000; + sPrimaries.Green.y = (mng_float)pData->iGlobalPrimarygreeny / 100000; + sPrimaries.Blue.x = (mng_float)pData->iGlobalPrimarybluex / 100000; + sPrimaries.Blue.y = (mng_float)pData->iGlobalPrimarybluey / 100000; + } +#endif + + sWhitepoint.Y = /* Y component is always 1.0 */ + sPrimaries.Red.Y = + sPrimaries.Green.Y = + sPrimaries.Blue.Y = 1.0; + + if ((pBuf) && (pBuf->bHasGAMA)) /* get the gamma value */ + dGamma = (mng_float)pBuf->iGamma / 100000; + else + dGamma = (mng_float)pData->iGlobalGamma / 100000; + + dGamma = pData->dViewgamma / dGamma; + + pGammatable [0] = /* and build the lookup tables */ + pGammatable [1] = + pGammatable [2] = cmsBuildGamma (256, dGamma); + + if (!pGammatable [0]) /* enough memory ? */ + MNG_ERRORL (pData, MNG_LCMS_NOMEM); + /* create the profile */ + hProf = cmsCreateRGBProfile (&sWhitepoint, &sPrimaries, pGammatable); + + cmsFreeGamma (pGammatable [0]); /* free the temporary gamma tables ? */ + /* yes! but just the one! */ + + pData->hProf1 = hProf; /* save for future use */ + + if (!hProf) /* handle error ? */ + MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); + + if (pData->bIsRGBA16) /* 16-bit intermediates ? */ + hTrans = cmsCreateTransform (hProf, TYPE_RGBA_16_SE, + pData->hProf2, TYPE_RGBA_16_SE, + INTENT_PERCEPTUAL, MNG_CMS_FLAGS); + else + hTrans = cmsCreateTransform (hProf, TYPE_RGBA_8, + pData->hProf2, TYPE_RGBA_8, + INTENT_PERCEPTUAL, MNG_CMS_FLAGS); + + pData->hTrans = hTrans; /* save for future use */ + + if (!hTrans) /* handle error ? */ + MNG_ERRORL (pData, MNG_LCMS_NOTRANS); + /* load color-correction routine */ + pData->fCorrectrow = (mng_fptr)mng_correct_full_cms; + + return MNG_NOERROR; /* and done */ + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_FULL_CMS, MNG_LC_END); +#endif + /* if we get here, we'll only do gamma */ + return mng_init_gamma_only (pData, bGlobal, bObject, bRetrobj); +} +#endif /* MNG_INCLUDE_LCMS */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_LCMS +mng_retcode mng_correct_full_cms (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CORRECT_FULL_CMS, MNG_LC_START); +#endif + + cmsDoTransform (pData->hTrans, pData->pRGBArow, pData->pRGBArow, pData->iRowsamples); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CORRECT_FULL_CMS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_LCMS */ + +/* ************************************************************************** */ + +#if defined(MNG_GAMMA_ONLY) || defined(MNG_FULL_CMS) || defined(MNG_APP_CMS) +mng_retcode mng_init_gamma_only (mng_datap pData, + mng_bool bGlobal, + mng_bool bObject, + mng_bool bRetrobj) +{ + mng_float dGamma; + mng_imagep pImage = MNG_NULL; + mng_imagedatap pBuf = MNG_NULL; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_GAMMA_ONLY, MNG_LC_START); +#endif + + if (bObject) /* use object if present ? */ + { /* current object ? */ + if ((mng_imagep)pData->pCurrentobj) + pImage = (mng_imagep)pData->pCurrentobj; + else /* if not; use object 0 */ + pImage = (mng_imagep)pData->pObjzero; + } + + if (bRetrobj) /* retrieving from an object ? */ + pImage = (mng_imagep)pData->pRetrieveobj; + + if (pImage) /* are we using an object ? */ + pBuf = pImage->pImgbuf; /* then address the buffer */ + + if ((!pBuf) || (!pBuf->bCorrected)) /* is the buffer already corrected ? */ + { + if ((pBuf) && (pBuf->bHasSRGB)) /* get the gamma value */ + dGamma = 0.45455; + else + if ((pBuf) && (pBuf->bHasGAMA)) + dGamma = (mng_float)pBuf->iGamma / 100000; + else + if ((bGlobal) && (pData->bHasglobalSRGB)) + dGamma = 0.45455; + else + if ((bGlobal) && (pData->bHasglobalGAMA)) + dGamma = (mng_float)pData->iGlobalGamma / 100000; + else + dGamma = pData->dDfltimggamma; + + if (dGamma > 0) /* ignore gamma=0 */ + { + dGamma = pData->dViewgamma / (dGamma * pData->dDisplaygamma); + + if (dGamma != pData->dLastgamma) /* lookup table needs to be computed ? */ + { + mng_int32 iX; + + pData->aGammatab [0] = 0; + + for (iX = 1; iX <= 255; iX++) + pData->aGammatab [iX] = (mng_uint8)(pow (iX / 255.0, dGamma) * 255 + 0.5); + + pData->dLastgamma = dGamma; /* keep for next time */ + } + /* load color-correction routine */ + pData->fCorrectrow = (mng_fptr)mng_correct_gamma_only; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_GAMMA_ONLY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_GAMMA_ONLY || MNG_FULL_CMS || MNG_APP_CMS */ + +/* ************************************************************************** */ + +#if defined(MNG_GAMMA_ONLY) || defined(MNG_FULL_CMS) || defined(MNG_APP_CMS) +mng_retcode mng_correct_gamma_only (mng_datap pData) +{ + mng_uint8p pWork; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CORRECT_GAMMA_ONLY, MNG_LC_START); +#endif + + pWork = pData->pRGBArow; /* address intermediate row */ + + if (pData->bIsRGBA16) /* 16-bit intermediate row ? */ + { + + + /* TODO: 16-bit precision gamma processing */ + /* we'll just do the high-order byte for now */ + + + /* convert all samples in the row */ + for (iX = 0; iX < pData->iRowsamples; iX++) + { /* using the precalculated gamma lookup table */ + *pWork = pData->aGammatab [*pWork]; + *(pWork+2) = pData->aGammatab [*(pWork+2)]; + *(pWork+4) = pData->aGammatab [*(pWork+4)]; + + pWork += 8; + } + } + else + { /* convert all samples in the row */ + for (iX = 0; iX < pData->iRowsamples; iX++) + { /* using the precalculated gamma lookup table */ + *pWork = pData->aGammatab [*pWork]; + *(pWork+1) = pData->aGammatab [*(pWork+1)]; + *(pWork+2) = pData->aGammatab [*(pWork+2)]; + + pWork += 4; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CORRECT_GAMMA_ONLY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_GAMMA_ONLY || MNG_FULL_CMS || MNG_APP_CMS */ + +/* ************************************************************************** */ + +#ifdef MNG_APP_CMS +mng_retcode mng_init_app_cms (mng_datap pData, + mng_bool bGlobal, + mng_bool bObject, + mng_bool bRetrobj) +{ + mng_imagep pImage = MNG_NULL; + mng_imagedatap pBuf = MNG_NULL; + mng_bool bDone = MNG_FALSE; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_APP_CMS, MNG_LC_START); +#endif + + if (bObject) /* use object if present ? */ + { /* current object ? */ + if ((mng_imagep)pData->pCurrentobj) + pImage = (mng_imagep)pData->pCurrentobj; + else /* if not; use object 0 */ + pImage = (mng_imagep)pData->pObjzero; + } + + if (bRetrobj) /* retrieving from an object ? */ + pImage = (mng_imagep)pData->pRetrieveobj; + + if (pImage) /* are we using an object ? */ + pBuf = pImage->pImgbuf; /* then address the buffer */ + + if ((!pBuf) || (!pBuf->bCorrected)) /* is the buffer already corrected ? */ + { +#ifndef MNG_SKIPCHUNK_iCCP + if ( (pData->fProcessiccp) && + (((pBuf) && (pBuf->bHasICCP)) || ((bGlobal) && (pData->bHasglobalICCP))) ) + { + mng_uint32 iProfilesize; + mng_ptr pProfile; + + if ((pBuf) && (pBuf->bHasICCP)) /* get the right profile */ + { + iProfilesize = pBuf->iProfilesize; + pProfile = pBuf->pProfile; + } + else + { + iProfilesize = pData->iGlobalProfilesize; + pProfile = pData->pGlobalProfile; + } + /* inform the app */ + if (!pData->fProcessiccp ((mng_handle)pData, iProfilesize, pProfile)) + MNG_ERROR (pData, MNG_APPCMSERROR); + /* load color-correction routine */ + pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; + bDone = MNG_TRUE; + } +#endif + + if ( (pData->fProcesssrgb) && + (((pBuf) && (pBuf->bHasSRGB)) || ((bGlobal) && (pData->bHasglobalSRGB))) ) + { + mng_uint8 iIntent; + + if ((pBuf) && (pBuf->bHasSRGB)) /* determine rendering intent */ + iIntent = pBuf->iRenderingintent; + else + iIntent = pData->iGlobalRendintent; + /* inform the app */ + if (!pData->fProcesssrgb ((mng_handle)pData, iIntent)) + MNG_ERROR (pData, MNG_APPCMSERROR); + /* load color-correction routine */ + pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; + bDone = MNG_TRUE; + } + +#ifndef MNG_SKIPCHUNK_cHRM + if ( (pData->fProcesschroma) && + (((pBuf) && (pBuf->bHasCHRM)) || ((bGlobal) && (pData->bHasglobalCHRM))) ) + { + mng_uint32 iWhitepointx, iWhitepointy; + mng_uint32 iPrimaryredx, iPrimaryredy; + mng_uint32 iPrimarygreenx, iPrimarygreeny; + mng_uint32 iPrimarybluex, iPrimarybluey; + + if ((pBuf) && (pBuf->bHasCHRM)) /* local cHRM ? */ + { + iWhitepointx = pBuf->iWhitepointx; + iWhitepointy = pBuf->iWhitepointy; + iPrimaryredx = pBuf->iPrimaryredx; + iPrimaryredy = pBuf->iPrimaryredy; + iPrimarygreenx = pBuf->iPrimarygreenx; + iPrimarygreeny = pBuf->iPrimarygreeny; + iPrimarybluex = pBuf->iPrimarybluex; + iPrimarybluey = pBuf->iPrimarybluey; + } + else + { + iWhitepointx = pData->iGlobalWhitepointx; + iWhitepointy = pData->iGlobalWhitepointy; + iPrimaryredx = pData->iGlobalPrimaryredx; + iPrimaryredy = pData->iGlobalPrimaryredy; + iPrimarygreenx = pData->iGlobalPrimarygreenx; + iPrimarygreeny = pData->iGlobalPrimarygreeny; + iPrimarybluex = pData->iGlobalPrimarybluex; + iPrimarybluey = pData->iGlobalPrimarybluey; + } + /* inform the app */ + if (!pData->fProcesschroma ((mng_handle)pData, iWhitepointx, iWhitepointy, + iPrimaryredx, iPrimaryredy, + iPrimarygreenx, iPrimarygreeny, + iPrimarybluex, iPrimarybluey)) + MNG_ERROR (pData, MNG_APPCMSERROR); + /* load color-correction routine */ + pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; + bDone = MNG_TRUE; + } +#endif + + if ( (pData->fProcessgamma) && + (((pBuf) && (pBuf->bHasGAMA)) || ((bGlobal) && (pData->bHasglobalGAMA))) ) + { + mng_uint32 iGamma; + + if ((pBuf) && (pBuf->bHasGAMA)) /* get the gamma value */ + iGamma = pBuf->iGamma; + else + iGamma = pData->iGlobalGamma; + /* inform the app */ + if (!pData->fProcessgamma ((mng_handle)pData, iGamma)) + { /* app wants us to use internal routines ! */ + iRetcode = mng_init_gamma_only (pData, bGlobal, bObject, bRetrobj); + if (iRetcode) /* on error bail out */ + return iRetcode; + } + else + { /* load color-correction routine */ + pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; + } + + bDone = MNG_TRUE; + } + + if (!bDone) /* no color-info at all ? */ + { + /* then use default image gamma ! */ + if (!pData->fProcessgamma ((mng_handle)pData, + (mng_uint32)((pData->dDfltimggamma * 100000) + 0.5))) + { /* app wants us to use internal routines ! */ + iRetcode = mng_init_gamma_only (pData, bGlobal, bObject, bRetrobj); + if (iRetcode) /* on error bail out */ + return iRetcode; + } + else + { /* load color-correction routine */ + pData->fCorrectrow = (mng_fptr)mng_correct_app_cms; + } + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_APP_CMS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_APP_CMS */ + +/* ************************************************************************** */ + +#ifdef MNG_APP_CMS +mng_retcode mng_correct_app_cms (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CORRECT_APP_CMS, MNG_LC_START); +#endif + + if (pData->fProcessarow) /* let the app do something with our row */ + if (!pData->fProcessarow ((mng_handle)pData, pData->iRowsamples, + pData->bIsRGBA16, pData->pRGBArow)) + MNG_ERROR (pData, MNG_APPCMSERROR); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CORRECT_APP_CMS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_APP_CMS */ + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_DISPLAY_PROCS */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + + + diff --git a/Source/LibMNG/libmng_display.c b/Source/LibMNG/libmng_display.c index 65a5c31..adfb91d 100644 --- a/Source/LibMNG/libmng_display.c +++ b/Source/LibMNG/libmng_display.c @@ -1,7135 +1,7135 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_display.c copyright (c) 2000-2007 G.Juyn * */ -/* * version : 1.0.10 * */ -/* * * */ -/* * purpose : Display management (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the display management routines * */ -/* * * */ -/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/11/2000 - G.Juyn * */ -/* * - added callback error-reporting support * */ -/* * - fixed frame_delay misalignment * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - added sanity check for frozen status * */ -/* * - changed trace to macro for callback error-reporting * */ -/* * 0.5.1 - 05/13/2000 - G.Juyn * */ -/* * - changed display_mend to reset state to initial or SAVE * */ -/* * - added eMNGma hack (will be removed in 1.0.0 !!!) * */ -/* * - added TERM animation object pointer (easier reference) * */ -/* * - added process_save & process_seek routines * */ -/* * 0.5.1 - 05/14/2000 - G.Juyn * */ -/* * - added save_state and restore_state for SAVE/SEEK/TERM * */ -/* * processing * */ -/* * * */ -/* * 0.5.2 - 05/20/2000 - G.Juyn * */ -/* * - added JNG support (JHDR/JDAT) * */ -/* * 0.5.2 - 05/23/2000 - G.Juyn * */ -/* * - fixed problem with DEFI clipping * */ -/* * 0.5.2 - 05/30/2000 - G.Juyn * */ -/* * - added delta-image support (DHDR,PROM,IPNG,IJNG) * */ -/* * 0.5.2 - 05/31/2000 - G.Juyn * */ -/* * - fixed pointer confusion (contributed by Tim Rowley) * */ -/* * 0.5.2 - 06/03/2000 - G.Juyn * */ -/* * - fixed makeup for Linux gcc compile * */ -/* * 0.5.2 - 06/05/2000 - G.Juyn * */ -/* * - added support for RGB8_A8 canvasstyle * */ -/* * 0.5.2 - 06/09/2000 - G.Juyn * */ -/* * - fixed timer-handling to run with Mozilla (Tim Rowley) * */ -/* * 0.5.2 - 06/10/2000 - G.Juyn * */ -/* * - fixed some compilation-warnings (contrib Jason Morris) * */ -/* * * */ -/* * 0.5.3 - 06/12/2000 - G.Juyn * */ -/* * - fixed display of stored JNG images * */ -/* * 0.5.3 - 06/13/2000 - G.Juyn * */ -/* * - fixed problem with BASI-IEND as object 0 * */ -/* * 0.5.3 - 06/16/2000 - G.Juyn * */ -/* * - changed progressive-display processing * */ -/* * 0.5.3 - 06/17/2000 - G.Juyn * */ -/* * - changed delta-image processing * */ -/* * 0.5.3 - 06/20/2000 - G.Juyn * */ -/* * - fixed some minor stuff * */ -/* * 0.5.3 - 06/21/2000 - G.Juyn * */ -/* * - added speed-modifier to timing routine * */ -/* * 0.5.3 - 06/22/2000 - G.Juyn * */ -/* * - added support for PPLT chunk processing * */ -/* * 0.5.3 - 06/29/2000 - G.Juyn * */ -/* * - swapped refresh parameters * */ -/* * * */ -/* * 0.9.0 - 06/30/2000 - G.Juyn * */ -/* * - changed refresh parameters to 'x,y,width,height' * */ -/* * * */ -/* * 0.9.1 - 07/07/2000 - G.Juyn * */ -/* * - implemented support for freeze/reset/resume & go_xxxx * */ -/* * 0.9.1 - 07/08/2000 - G.Juyn * */ -/* * - added support for improved timing * */ -/* * 0.9.1 - 07/14/2000 - G.Juyn * */ -/* * - changed EOF processing behavior * */ -/* * - fixed TERM delay processing * */ -/* * 0.9.1 - 07/15/2000 - G.Juyn * */ -/* * - fixed freeze & reset processing * */ -/* * 0.9.1 - 07/16/2000 - G.Juyn * */ -/* * - fixed storage of images during mng_read() * */ -/* * - fixed support for mng_display() after mng_read() * */ -/* * 0.9.1 - 07/24/2000 - G.Juyn * */ -/* * - fixed reading of still-images * */ -/* * * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 0.9.3 - 08/07/2000 - G.Juyn * */ -/* * - B111300 - fixup for improved portability * */ -/* * 0.9.3 - 08/21/2000 - G.Juyn * */ -/* * - fixed TERM processing delay of 0 msecs * */ -/* * 0.9.3 - 08/26/2000 - G.Juyn * */ -/* * - added MAGN chunk * */ -/* * 0.9.3 - 09/10/2000 - G.Juyn * */ -/* * - fixed problem with no refresh after TERM * */ -/* * - fixed DEFI behavior * */ -/* * 0.9.3 - 09/16/2000 - G.Juyn * */ -/* * - fixed timing & refresh behavior for single PNG/JNG * */ -/* * 0.9.3 - 09/19/2000 - G.Juyn * */ -/* * - refixed timing & refresh behavior for single PNG/JNG * */ -/* * 0.9.3 - 10/02/2000 - G.Juyn * */ -/* * - fixed timing again (this is getting boring...) * */ -/* * - refixed problem with no refresh after TERM * */ -/* * 0.9.3 - 10/16/2000 - G.Juyn * */ -/* * - added JDAA chunk * */ -/* * 0.9.3 - 10/17/2000 - G.Juyn * */ -/* * - fixed support for bKGD * */ -/* * 0.9.3 - 10/18/2000 - G.Juyn * */ -/* * - fixed delta-processing behavior * */ -/* * 0.9.3 - 10/19/2000 - G.Juyn * */ -/* * - added storage for pixel-/alpha-sampledepth for delta's * */ -/* * 0.9.3 - 10/27/2000 - G.Juyn * */ -/* * - fixed separate read() & display() processing * */ -/* * * */ -/* * 0.9.4 - 10/31/2000 - G.Juyn * */ -/* * - fixed possible loop in display_resume() (Thanks Vova!) * */ -/* * 0.9.4 - 11/20/2000 - G.Juyn * */ -/* * - fixed unwanted repetition in mng_readdisplay() * */ -/* * 0.9.4 - 11/24/2000 - G.Juyn * */ -/* * - moved restore of object 0 to libmng_display * */ -/* * - added restore of object 0 to TERM processing !!! * */ -/* * - fixed TERM delay processing * */ -/* * - fixed TERM end processing (count = 0) * */ -/* * 0.9.4 - 12/16/2000 - G.Juyn * */ -/* * - fixed mixup of data- & function-pointers (thanks Dimitri)* */ -/* * 0.9.4 - 1/18/2001 - G.Juyn * */ -/* * - removed test filter-methods 1 & 65 * */ -/* * - set default level-set for filtertype=64 to all zeroes * */ -/* * * */ -/* * 0.9.5 - 1/20/2001 - G.Juyn * */ -/* * - fixed compiler-warnings Mozilla (thanks Tim) * */ -/* * 0.9.5 - 1/23/2001 - G.Juyn * */ -/* * - fixed timing-problem with switching framing_modes * */ -/* * * */ -/* * 1.0.1 - 02/08/2001 - G.Juyn * */ -/* * - added MEND processing callback * */ -/* * 1.0.1 - 02/13/2001 - G.Juyn * */ -/* * - fixed first FRAM_MODE=4 timing problem * */ -/* * 1.0.1 - 04/21/2001 - G.Juyn * */ -/* * - fixed memory-leak for JNGs with alpha (Thanks Gregg!) * */ -/* * - added BGRA8 canvas with premultiplied alpha * */ -/* * * */ -/* * 1.0.2 - 06/25/2001 - G.Juyn * */ -/* * - fixed memory-leak with delta-images (Thanks Michael!) * */ -/* * * */ -/* * 1.0.5 - 08/15/2002 - G.Juyn * */ -/* * - completed PROM support * */ -/* * - completed delta-image support * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * 1.0.5 - 09/13/2002 - G.Juyn * */ -/* * - fixed read/write of MAGN chunk * */ -/* * 1.0.5 - 09/15/2002 - G.Juyn * */ -/* * - fixed LOOP iteration=0 special case * */ -/* * 1.0.5 - 09/19/2002 - G.Juyn * */ -/* * - fixed color-correction for restore-background handling * */ -/* * - optimized restore-background for bKGD cases * */ -/* * - cleaned up some old stuff * */ -/* * 1.0.5 - 09/20/2002 - G.Juyn * */ -/* * - finished support for BACK image & tiling * */ -/* * - added support for PAST * */ -/* * 1.0.5 - 09/22/2002 - G.Juyn * */ -/* * - added bgrx8 canvas (filler byte) * */ -/* * 1.0.5 - 10/05/2002 - G.Juyn * */ -/* * - fixed dropping mix of frozen/unfrozen objects * */ -/* * 1.0.5 - 10/07/2002 - G.Juyn * */ -/* * - added proposed change in handling of TERM- & if-delay * */ -/* * - added another fix for misplaced TERM chunk * */ -/* * - completed support for condition=2 in TERM chunk * */ -/* * 1.0.5 - 10/18/2002 - G.Juyn * */ -/* * - fixed clipping-problem with BACK tiling (Thanks Sakura!) * */ -/* * 1.0.5 - 10/20/2002 - G.Juyn * */ -/* * - fixed processing for multiple objects in MAGN * */ -/* * - fixed display of visible target of PAST operation * */ -/* * 1.0.5 - 10/30/2002 - G.Juyn * */ -/* * - modified TERM/MEND processing for max(1, TERM_delay, * */ -/* * interframe_delay) * */ -/* * 1.0.5 - 11/04/2002 - G.Juyn * */ -/* * - fixed layer- & frame-counting during read() * */ -/* * - fixed goframe/golayer/gotime processing * */ -/* * 1.0.5 - 01/19/2003 - G.Juyn * */ -/* * - B654627 - fixed SEGV when no gettickcount callback * */ -/* * - B664383 - fixed typo * */ -/* * - finalized changes in TERM/final_delay to elected proposal* */ -/* * * */ -/* * 1.0.6 - 05/11/2003 - G. Juyn * */ -/* * - added conditionals around canvas update routines * */ -/* * 1.0.6 - 05/25/2003 - G.R-P * */ -/* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */ -/* * 1.0.6 - 07/07/2003 - G.R-P * */ -/* * - added conditionals around some JNG-supporting code * */ -/* * - added conditionals around 16-bit supporting code * */ -/* * - reversed some loops to use decrementing counter * */ -/* * - combined init functions into one function * */ -/* * 1.0.6 - 07/10/2003 - G.R-P * */ -/* * - replaced nested switches with simple init setup function * */ -/* * 1.0.6 - 07/29/2003 - G.R-P * */ -/* * - added conditionals around PAST chunk support * */ -/* * 1.0.6 - 08/17/2003 - G.R-P * */ -/* * - added conditionals around non-VLC chunk support * */ -/* * * */ -/* * 1.0.7 - 11/27/2003 - R.A * */ -/* * - added CANVAS_RGB565 and CANVAS_BGR565 * */ -/* * 1.0.7 - 12/06/2003 - R.A * */ -/* * - added CANVAS_RGBA565 and CANVAS_BGRA565 * */ -/* * 1.0.7 - 01/25/2004 - J.S * */ -/* * - added premultiplied alpha canvas' for RGBA, ARGB, ABGR * */ -/* * * */ -/* * 1.0.8 - 03/31/2004 - G.Juyn * */ -/* * - fixed problem with PAST usage where source > dest * */ -/* * 1.0.8 - 05/04/2004 - G.R-P. * */ -/* * - fixed misplaced 16-bit conditionals * */ -/* * * */ -/* * 1.0.9 - 09/18/2004 - G.R-P. * */ -/* * - revised some SKIPCHUNK conditionals * */ -/* * 1.0.9 - 10/10/2004 - G.R-P. * */ -/* * - added MNG_NO_1_2_4BIT_SUPPORT * */ -/* * 1.0.9 - 10/14/2004 - G.Juyn * */ -/* * - added bgr565_a8 canvas-style (thanks to J. Elvander) * */ -/* * 1.0.9 - 12/11/2004 - G.Juyn * */ -/* * - added conditional MNG_OPTIMIZE_DISPLAYCALLS * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * * */ -/* * 1.0.10 - 07/06/2005 - G.R-P. * */ -/* * - added more SKIPCHUNK conditionals * */ -/* * 1.0.10 - 12/28/2005 - G.R-P. * */ -/* * - added missing SKIPCHUNK_MAGN conditional * */ -/* * 1.0.10 - 03/07/2006 - (thanks to W. Manthey) * */ -/* * - added CANVAS_RGB555 and CANVAS_BGR555 * */ -/* * 1.0.10 - 04/08/2007 - G.Juyn * */ -/* * - fixed several compiler warnings * */ -/* * 1.0.10 - 04/08/2007 - G.Juyn * */ -/* * - added support for mPNG proposal * */ -/* * 1.0.10 - 04/12/2007 - G.Juyn * */ -/* * - added support for ANG proposal * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_chunks.h" -#include "libmng_objects.h" -#include "libmng_object_prc.h" -#include "libmng_memory.h" -#include "libmng_zlib.h" -#include "libmng_jpeg.h" -#include "libmng_cms.h" -#include "libmng_pixels.h" -#include "libmng_display.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_DISPLAY_PROCS - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode set_delay (mng_datap pData, - mng_uint32 iInterval) -{ - if (!iInterval) /* at least 1 msec please! */ - iInterval = 1; - - if (pData->bRunning) /* only when really displaying */ - if (!pData->fSettimer ((mng_handle)pData, iInterval)) - MNG_ERROR (pData, MNG_APPTIMERERROR); - -#ifdef MNG_SUPPORT_DYNAMICMNG - if ((!pData->bDynamic) || (pData->bRunning)) -#else - if (pData->bRunning) -#endif - pData->bTimerset = MNG_TRUE; /* and indicate so */ - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_uint32 calculate_delay (mng_datap pData, - mng_uint32 iDelay) -{ - mng_uint32 iTicks = pData->iTicks; - mng_uint32 iWaitfor = 1; /* default non-MNG delay */ - - if (!iTicks) /* tick_count not specified ? */ - if (pData->eImagetype == mng_it_mng) - iTicks = 1000; - - if (iTicks) - { - switch (pData->iSpeed) /* honor speed modifier */ - { - case mng_st_fast : - { - iWaitfor = (mng_uint32)(( 500 * iDelay) / iTicks); - break; - } - case mng_st_slow : - { - iWaitfor = (mng_uint32)((3000 * iDelay) / iTicks); - break; - } - case mng_st_slowest : - { - iWaitfor = (mng_uint32)((8000 * iDelay) / iTicks); - break; - } - default : - { - iWaitfor = (mng_uint32)((1000 * iDelay) / iTicks); - } - } - } - - return iWaitfor; -} - -/* ************************************************************************** */ -/* * * */ -/* * Progressive display refresh - does the call to the refresh callback * */ -/* * and sets the timer to allow the app to perform the actual refresh to * */ -/* * the screen (eg. process its main message-loop) * */ -/* * * */ -/* ************************************************************************** */ - -mng_retcode mng_display_progressive_refresh (mng_datap pData, - mng_uint32 iInterval) -{ - { /* let the app refresh first ? */ - if ((pData->bRunning) && (!pData->bSkipping) && - (pData->iUpdatetop < pData->iUpdatebottom) && (pData->iUpdateleft < pData->iUpdateright)) - { - if (!pData->fRefresh (((mng_handle)pData), - pData->iUpdateleft, pData->iUpdatetop, - pData->iUpdateright - pData->iUpdateleft, - pData->iUpdatebottom - pData->iUpdatetop)) - MNG_ERROR (pData, MNG_APPMISCERROR); - - pData->iUpdateleft = 0; /* reset update-region */ - pData->iUpdateright = 0; - pData->iUpdatetop = 0; - pData->iUpdatebottom = 0; /* reset refreshneeded indicator */ - pData->bNeedrefresh = MNG_FALSE; - /* interval requested ? */ - if ((!pData->bFreezing) && (iInterval)) - { /* setup the timer */ - mng_retcode iRetcode = set_delay (pData, iInterval); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } - } - - return MNG_NOERROR; -} - -/* ************************************************************************** */ -/* * * */ -/* * Generic display routines * */ -/* * * */ -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode interframe_delay (mng_datap pData) -{ - mng_uint32 iWaitfor = 0; - mng_uint32 iInterval; - mng_uint32 iRuninterval; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INTERFRAME_DELAY, MNG_LC_START); -#endif - - { -#ifndef MNG_SKIPCHUNK_FRAM - if (pData->iFramedelay > 0) /* real delay ? */ - { /* let the app refresh first ? */ - if ((pData->bRunning) && (!pData->bSkipping) && - (pData->iUpdatetop < pData->iUpdatebottom) && (pData->iUpdateleft < pData->iUpdateright)) - if (!pData->fRefresh (((mng_handle)pData), - pData->iUpdateleft, pData->iUpdatetop, - pData->iUpdateright - pData->iUpdateleft, - pData->iUpdatebottom - pData->iUpdatetop)) - MNG_ERROR (pData, MNG_APPMISCERROR); - - pData->iUpdateleft = 0; /* reset update-region */ - pData->iUpdateright = 0; - pData->iUpdatetop = 0; - pData->iUpdatebottom = 0; /* reset refreshneeded indicator */ - pData->bNeedrefresh = MNG_FALSE; - -#ifndef MNG_SKIPCHUNK_TERM - if (pData->bOnlyfirstframe) /* only processing first frame after TERM ? */ - { - pData->iFramesafterTERM++; - /* did we do a frame yet ? */ - if (pData->iFramesafterTERM > 1) - { /* then that's it; just stop right here ! */ - pData->pCurraniobj = MNG_NULL; - pData->bRunning = MNG_FALSE; - - return MNG_NOERROR; - } - } -#endif - - if (pData->fGettickcount) - { /* get current tickcount */ - pData->iRuntime = pData->fGettickcount ((mng_handle)pData); - /* calculate interval since last sync-point */ - if (pData->iRuntime < pData->iSynctime) - iRuninterval = pData->iRuntime + ~pData->iSynctime + 1; - else - iRuninterval = pData->iRuntime - pData->iSynctime; - /* calculate actual run-time */ - if (pData->iRuntime < pData->iStarttime) - pData->iRuntime = pData->iRuntime + ~pData->iStarttime + 1; - else - pData->iRuntime = pData->iRuntime - pData->iStarttime; - } - else - { - iRuninterval = 0; - } - - iWaitfor = calculate_delay (pData, pData->iFramedelay); - - if (iWaitfor > iRuninterval) /* delay necessary ? */ - iInterval = iWaitfor - iRuninterval; - else - iInterval = 1; /* force app to process messageloop */ - /* set the timer ? */ - if (((pData->bRunning) || (pData->bSearching) || (pData->bReading)) && - (!pData->bSkipping)) - { - iRetcode = set_delay (pData, iInterval); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } - - if (!pData->bSkipping) /* increase frametime in advance */ - pData->iFrametime = pData->iFrametime + iWaitfor; - /* setup for next delay */ - pData->iFramedelay = pData->iNextdelay; -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INTERFRAME_DELAY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL void set_display_routine (mng_datap pData) -{ /* actively running ? */ - if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping)) - { - switch (pData->iCanvasstyle) /* determine display routine */ - { -#ifndef MNG_SKIPCANVAS_RGB8 - case MNG_CANVAS_RGB8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb8; break; } -#endif -#ifndef MNG_SKIPCANVAS_RGBA8 - case MNG_CANVAS_RGBA8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgba8; break; } -#endif -#ifndef MNG_SKIPCANVAS_RGBA8_PM - case MNG_CANVAS_RGBA8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_rgba8_pm; break; } -#endif -#ifndef MNG_SKIPCANVAS_ARGB8 - case MNG_CANVAS_ARGB8 : { pData->fDisplayrow = (mng_fptr)mng_display_argb8; break; } -#endif -#ifndef MNG_SKIPCANVAS_ARGB8_PM - case MNG_CANVAS_ARGB8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_argb8_pm; break; } -#endif -#ifndef MNG_SKIPCANVAS_RGB8_A8 - case MNG_CANVAS_RGB8_A8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb8_a8; break; } -#endif -#ifndef MNG_SKIPCANVAS_BGR8 - case MNG_CANVAS_BGR8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr8; break; } -#endif -#ifndef MNG_SKIPCANVAS_BGRX8 - case MNG_CANVAS_BGRX8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgrx8; break; } -#endif -#ifndef MNG_SKIPCANVAS_BGRA8 - case MNG_CANVAS_BGRA8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgra8; break; } -#endif -#ifndef MNG_SKIPCANVAS_BGRA8_PM - case MNG_CANVAS_BGRA8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_bgra8_pm; break; } -#endif -#ifndef MNG_SKIPCANVAS_ABGR8 - case MNG_CANVAS_ABGR8 : { pData->fDisplayrow = (mng_fptr)mng_display_abgr8; break; } -#endif -#ifndef MNG_SKIPCANVAS_ABGR8_PM - case MNG_CANVAS_ABGR8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_abgr8_pm; break; } -#endif -#ifndef MNG_SKIPCANVAS_RGB565 - case MNG_CANVAS_RGB565 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb565; break; } -#endif -#ifndef MNG_SKIPCANVAS_RGBA565 - case MNG_CANVAS_RGBA565 : { pData->fDisplayrow = (mng_fptr)mng_display_rgba565; break; } -#endif -#ifndef MNG_SKIPCANVAS_BGR565 - case MNG_CANVAS_BGR565 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr565; break; } -#endif -#ifndef MNG_SKIPCANVAS_BGRA565 - case MNG_CANVAS_BGRA565 : { pData->fDisplayrow = (mng_fptr)mng_display_bgra565; break; } -#endif -#ifndef MNG_SKIPCANVAS_BGR565_A8 - case MNG_CANVAS_BGR565_A8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr565_a8; break; } -#endif -#ifndef MNG_SKIPCANVAS_RGB555 - case MNG_CANVAS_RGB555 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb555; break; } -#endif -#ifndef MNG_SKIPCANVAS_BGR555 - case MNG_CANVAS_BGR555 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr555; break; } -#endif - -#ifndef MNG_NO_16BIT_SUPPORT -/* case MNG_CANVAS_RGB16 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb16; break; } */ -/* case MNG_CANVAS_RGBA16 : { pData->fDisplayrow = (mng_fptr)mng_display_rgba16; break; } */ -/* case MNG_CANVAS_ARGB16 : { pData->fDisplayrow = (mng_fptr)mng_display_argb16; break; } */ -/* case MNG_CANVAS_BGR16 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr16; break; } */ -/* case MNG_CANVAS_BGRA16 : { pData->fDisplayrow = (mng_fptr)mng_display_bgra16; break; } */ -/* case MNG_CANVAS_ABGR16 : { pData->fDisplayrow = (mng_fptr)mng_display_abgr16; break; } */ -#endif -/* case MNG_CANVAS_INDEX8 : { pData->fDisplayrow = (mng_fptr)mng_display_index8; break; } */ -/* case MNG_CANVAS_INDEXA8 : { pData->fDisplayrow = (mng_fptr)mng_display_indexa8; break; } */ -/* case MNG_CANVAS_AINDEX8 : { pData->fDisplayrow = (mng_fptr)mng_display_aindex8; break; } */ -/* case MNG_CANVAS_GRAY8 : { pData->fDisplayrow = (mng_fptr)mng_display_gray8; break; } */ -/* case MNG_CANVAS_AGRAY8 : { pData->fDisplayrow = (mng_fptr)mng_display_agray8; break; } */ -/* case MNG_CANVAS_GRAYA8 : { pData->fDisplayrow = (mng_fptr)mng_display_graya8; break; } */ -#ifndef MNG_NO_16BIT_SUPPORT -/* case MNG_CANVAS_GRAY16 : { pData->fDisplayrow = (mng_fptr)mng_display_gray16; break; } */ -/* case MNG_CANVAS_GRAYA16 : { pData->fDisplayrow = (mng_fptr)mng_display_graya16; break; } */ -/* case MNG_CANVAS_AGRAY16 : { pData->fDisplayrow = (mng_fptr)mng_display_agray16; break; } */ -#endif -/* case MNG_CANVAS_DX15 : { pData->fDisplayrow = (mng_fptr)mng_display_dx15; break; } */ -/* case MNG_CANVAS_DX16 : { pData->fDisplayrow = (mng_fptr)mng_display_dx16; break; } */ - } - } - - return; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode load_bkgdlayer (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_LOAD_BKGDLAYER, MNG_LC_START); -#endif - /* actively running ? */ - if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping)) - { - mng_int32 iY; - mng_retcode iRetcode; - mng_bool bColorcorr = MNG_FALSE; - /* save values */ - mng_int32 iDestl = pData->iDestl; - mng_int32 iDestr = pData->iDestr; - mng_int32 iDestt = pData->iDestt; - mng_int32 iDestb = pData->iDestb; - mng_int32 iSourcel = pData->iSourcel; - mng_int32 iSourcer = pData->iSourcer; - mng_int32 iSourcet = pData->iSourcet; - mng_int32 iSourceb = pData->iSourceb; - mng_int8 iPass = pData->iPass; - mng_int32 iRow = pData->iRow; - mng_int32 iRowinc = pData->iRowinc; - mng_int32 iCol = pData->iCol; - mng_int32 iColinc = pData->iColinc; - mng_int32 iRowsamples = pData->iRowsamples; - mng_int32 iRowsize = pData->iRowsize; - mng_uint8p pPrevrow = pData->pPrevrow; - mng_uint8p pRGBArow = pData->pRGBArow; - mng_bool bIsRGBA16 = pData->bIsRGBA16; - mng_bool bIsOpaque = pData->bIsOpaque; - mng_fptr fCorrectrow = pData->fCorrectrow; - mng_fptr fDisplayrow = pData->fDisplayrow; - mng_fptr fRetrieverow = pData->fRetrieverow; - mng_objectp pCurrentobj = pData->pCurrentobj; - mng_objectp pRetrieveobj = pData->pRetrieveobj; - - pData->iDestl = 0; /* determine clipping region */ - pData->iDestt = 0; - pData->iDestr = pData->iWidth; - pData->iDestb = pData->iHeight; - -#ifndef MNG_SKIPCHUNK_FRAM - if (pData->bFrameclipping) /* frame clipping specified ? */ - { - pData->iDestl = MAX_COORD (pData->iDestl, pData->iFrameclipl); - pData->iDestt = MAX_COORD (pData->iDestt, pData->iFrameclipt); - pData->iDestr = MIN_COORD (pData->iDestr, pData->iFrameclipr); - pData->iDestb = MIN_COORD (pData->iDestb, pData->iFrameclipb); - } -#endif - /* anything to clear ? */ - if ((pData->iDestr >= pData->iDestl) && (pData->iDestb >= pData->iDestt)) - { - pData->iPass = -1; /* these are the object's dimensions now */ - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iWidth; - pData->iRowsize = pData->iRowsamples << 2; - pData->bIsRGBA16 = MNG_FALSE; /* let's keep it simple ! */ - pData->bIsOpaque = MNG_TRUE; - - pData->iSourcel = 0; /* source relative to destination */ - pData->iSourcer = pData->iDestr - pData->iDestl; - pData->iSourcet = 0; - pData->iSourceb = pData->iDestb - pData->iDestt; - - set_display_routine (pData); /* determine display routine */ - /* default restore using preset BG color */ - pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgcolor; - -#ifndef MNG_SKIPCHUNK_bKGD - if (((pData->eImagetype == mng_it_png) || (pData->eImagetype == mng_it_jng)) && - (pData->bUseBKGD)) - { /* prefer bKGD in PNG/JNG */ - if (!pData->pCurrentobj) - pData->pCurrentobj = pData->pObjzero; - - if (((mng_imagep)pData->pCurrentobj)->pImgbuf->bHasBKGD) - { - pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bkgd; - bColorcorr = MNG_TRUE; - } - } -#endif - - if (pData->fGetbkgdline) /* background-canvas-access callback set ? */ - { - switch (pData->iBkgdstyle) - { -#ifndef MNG_SKIPCANVAS_RGB8 - case MNG_CANVAS_RGB8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb8; break; } -#endif -#ifndef MNG_SKIPCANVAS_BGR8 - case MNG_CANVAS_BGR8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr8; break; } -#endif -#ifndef MNG_SKIPCANVAS_BGRX8 - case MNG_CANVAS_BGRX8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgrx8; break; } -#endif -#ifndef MNG_SKIPCANVAS_BGR565 - case MNG_CANVAS_BGR565 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr565; break; } -#endif -#ifndef MNG_SKIPCANVAS_RGB565 - case MNG_CANVAS_RGB565 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb565; break; } -#endif -#ifndef MNG_NO_16BIT_SUPPORT - /* case MNG_CANVAS_RGB16 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb16; break; } */ - /* case MNG_CANVAS_BGR16 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr16; break; } */ -#endif - /* case MNG_CANVAS_INDEX8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_index8; break; } */ - /* case MNG_CANVAS_GRAY8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_gray8; break; } */ -#ifndef MNG_NO_16BIT_SUPPORT - /* case MNG_CANVAS_GRAY16 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_gray16; break; } */ -#endif - /* case MNG_CANVAS_DX15 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_dx15; break; } */ - /* case MNG_CANVAS_DX16 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_dx16; break; } */ - } - } - -#ifndef MNG_SKIPCHUNK_BACK - if (pData->bHasBACK) - { /* background image ? */ - if ((pData->iBACKmandatory & 0x02) && (pData->iBACKimageid)) - { - pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_backcolor; - bColorcorr = MNG_TRUE; - } - else /* background color ? */ - if (pData->iBACKmandatory & 0x01) - { - pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_backcolor; - bColorcorr = MNG_TRUE; - } - } -#endif - - pData->fCorrectrow = MNG_NULL; /* default no color-correction */ - - if (bColorcorr) /* do we have to do color-correction ? */ - { -#ifdef MNG_NO_CMS - iRetcode = MNG_NOERROR; -#else -#if defined(MNG_FULL_CMS) /* determine color-management routine */ - iRetcode = mng_init_full_cms (pData, MNG_TRUE, MNG_FALSE, MNG_FALSE); -#elif defined(MNG_GAMMA_ONLY) - iRetcode = mng_init_gamma_only (pData, MNG_TRUE, MNG_FALSE, MNG_FALSE); -#elif defined(MNG_APP_CMS) - iRetcode = mng_init_app_cms (pData, MNG_TRUE, MNG_FALSE, MNG_FALSE); -#endif - if (iRetcode) /* on error bail out */ - return iRetcode; -#endif /* MNG_NO_CMS */ - } - /* get a temporary row-buffer */ - MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize); - - iY = pData->iDestt; /* this is where we start */ - iRetcode = MNG_NOERROR; /* so far, so good */ - - while ((!iRetcode) && (iY < pData->iDestb)) - { /* restore a background row */ - iRetcode = ((mng_restbkgdrow)pData->fRestbkgdrow) (pData); - /* color correction ? */ - if ((!iRetcode) && (pData->fCorrectrow)) - iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData); - - if (!iRetcode) /* so... display it */ - iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData); - - if (!iRetcode) - iRetcode = mng_next_row (pData); - - iY++; /* and next line */ - } - /* drop the temporary row-buffer */ - MNG_FREE (pData, pData->pRGBArow, pData->iRowsize); - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#if defined(MNG_FULL_CMS) /* cleanup cms stuff */ - if (bColorcorr) /* did we do color-correction ? */ - { - iRetcode = mng_clear_cms (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif -#ifndef MNG_SKIPCHUNK_BACK - /* background image ? */ - if ((pData->bHasBACK) && (pData->iBACKmandatory & 0x02) && (pData->iBACKimageid)) - { - mng_imagep pImage; - /* let's find that object then */ - pData->pRetrieveobj = mng_find_imageobject (pData, pData->iBACKimageid); - pImage = (mng_imagep)pData->pRetrieveobj; - /* exists, viewable and visible ? */ - if ((pImage) && (pImage->bViewable) && (pImage->bVisible)) - { /* will it fall within the target region ? */ - if ((pImage->iPosx < pData->iDestr) && (pImage->iPosy < pData->iDestb) && - ((pData->iBACKtile) || - ((pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth >= pData->iDestl) && - (pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight >= pData->iDestt) )) && - ((!pImage->bClipped) || - ((pImage->iClipl <= pImage->iClipr) && (pImage->iClipt <= pImage->iClipb) && - (pImage->iClipl < pData->iDestr) && (pImage->iClipr >= pData->iDestl) && - (pImage->iClipt < pData->iDestb) && (pImage->iClipb >= pData->iDestt) ))) - { /* right; we've got ourselves something to do */ - if (pImage->bClipped) /* clip output region with image's clipping region ? */ - { - if (pImage->iClipl > pData->iDestl) - pData->iDestl = pImage->iClipl; - if (pImage->iClipr < pData->iDestr) - pData->iDestr = pImage->iClipr; - if (pImage->iClipt > pData->iDestt) - pData->iDestt = pImage->iClipt; - if (pImage->iClipb < pData->iDestb) - pData->iDestb = pImage->iClipb; - } - /* image offset does some extra clipping too ! */ - if (pImage->iPosx > pData->iDestl) - pData->iDestl = pImage->iPosx; - if (pImage->iPosy > pData->iDestt) - pData->iDestt = pImage->iPosy; - - if (!pData->iBACKtile) /* without tiling further clipping is needed */ - { - if (pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth < pData->iDestr) - pData->iDestr = pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth; - if (pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight < pData->iDestb) - pData->iDestb = pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight; - } - - pData->iSourcel = 0; /* source relative to destination */ - pData->iSourcer = pData->iDestr - pData->iDestl; - pData->iSourcet = 0; - pData->iSourceb = pData->iDestb - pData->iDestt; - /* 16-bit background ? */ - -#ifdef MNG_NO_16BIT_SUPPORT - pData->bIsRGBA16 = MNG_FALSE; -#else - pData->bIsRGBA16 = (mng_bool)(pImage->pImgbuf->iBitdepth > 8); -#endif - /* let restore routine know the offsets !!! */ - pData->iBackimgoffsx = pImage->iPosx; - pData->iBackimgoffsy = pImage->iPosy; - pData->iBackimgwidth = pImage->pImgbuf->iWidth; - pData->iBackimgheight = pImage->pImgbuf->iHeight; - pData->iRow = 0; /* start at the top again !! */ - /* determine background object retrieval routine */ - switch (pImage->pImgbuf->iColortype) - { - case 0 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_g16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_g8; - - pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS); - break; - } - - case 2 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8; - - pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS); - break; - } - - case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8; - pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS); - break; - } - - case 4 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8; - - pData->bIsOpaque = MNG_FALSE; - break; - } - - case 6 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; - - pData->bIsOpaque = MNG_FALSE; - break; - } - - case 8 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_g16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_g8; - - pData->bIsOpaque = MNG_TRUE; - break; - } - - case 10 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8; - - pData->bIsOpaque = MNG_TRUE; - break; - } - - case 12 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8; - - pData->bIsOpaque = MNG_FALSE; - break; - } - - case 14 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; - - pData->bIsOpaque = MNG_FALSE; - break; - } - } - -#ifdef MNG_NO_CMS - iRetcode = MNG_NOERROR; -#else -#if defined(MNG_FULL_CMS) /* determine color-management routine */ - iRetcode = mng_init_full_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); -#elif defined(MNG_GAMMA_ONLY) - iRetcode = mng_init_gamma_only (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); -#elif defined(MNG_APP_CMS) - iRetcode = mng_init_app_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); -#endif - if (iRetcode) /* on error bail out */ - return iRetcode; -#endif /* MNG_NO_CMS */ - /* get temporary row-buffers */ - MNG_ALLOC (pData, pData->pPrevrow, pData->iRowsize); - MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize); - - iY = pData->iDestt; /* this is where we start */ - iRetcode = MNG_NOERROR; /* so far, so good */ - - while ((!iRetcode) && (iY < pData->iDestb)) - { /* restore a background row */ - iRetcode = mng_restore_bkgd_backimage (pData); - /* color correction ? */ - if ((!iRetcode) && (pData->fCorrectrow)) - iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData); - - if (!iRetcode) /* so... display it */ - iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData); - - if (!iRetcode) - iRetcode = mng_next_row (pData); - - iY++; /* and next line */ - } - /* drop temporary row-buffers */ - MNG_FREE (pData, pData->pRGBArow, pData->iRowsize); - MNG_FREE (pData, pData->pPrevrow, pData->iRowsize); - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#if defined(MNG_FULL_CMS) /* cleanup cms stuff */ - iRetcode = mng_clear_cms (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; -#endif - } - } - } -#endif - } - - pData->iDestl = iDestl; /* restore values */ - pData->iDestr = iDestr; - pData->iDestt = iDestt; - pData->iDestb = iDestb; - pData->iSourcel = iSourcel; - pData->iSourcer = iSourcer; - pData->iSourcet = iSourcet; - pData->iSourceb = iSourceb; - pData->iPass = iPass; - pData->iRow = iRow; - pData->iRowinc = iRowinc; - pData->iCol = iCol; - pData->iColinc = iColinc; - pData->iRowsamples = iRowsamples; - pData->iRowsize = iRowsize; - pData->pPrevrow = pPrevrow; - pData->pRGBArow = pRGBArow; - pData->bIsRGBA16 = bIsRGBA16; - pData->bIsOpaque = bIsOpaque; - pData->fCorrectrow = fCorrectrow; - pData->fDisplayrow = fDisplayrow; - pData->fRetrieverow = fRetrieverow; - pData->pCurrentobj = pCurrentobj; - pData->pRetrieveobj = pRetrieveobj; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_LOAD_BKGDLAYER, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode clear_canvas (mng_datap pData) -{ - mng_int32 iY; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CLEAR_CANVAS, MNG_LC_START); -#endif - - pData->iDestl = 0; /* clipping region is full canvas! */ - pData->iDestt = 0; - pData->iDestr = pData->iWidth; - pData->iDestb = pData->iHeight; - - pData->iSourcel = 0; /* source is same as destination */ - pData->iSourcer = pData->iWidth; - pData->iSourcet = 0; - pData->iSourceb = pData->iHeight; - - pData->iPass = -1; /* these are the object's dimensions now */ - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iWidth; - pData->iRowsize = pData->iRowsamples << 2; - pData->bIsRGBA16 = MNG_FALSE; /* let's keep it simple ! */ - pData->bIsOpaque = MNG_TRUE; - - set_display_routine (pData); /* determine display routine */ - /* get a temporary row-buffer */ - /* it's transparent black by default!! */ - MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize); - - iY = pData->iDestt; /* this is where we start */ - iRetcode = MNG_NOERROR; /* so far, so good */ - - while ((!iRetcode) && (iY < pData->iDestb)) - { /* clear a row then */ - iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData); - - if (!iRetcode) - iRetcode = mng_next_row (pData); /* adjust variables for next row */ - - iY++; /* and next line */ - } - /* drop the temporary row-buffer */ - MNG_FREE (pData, pData->pRGBArow, pData->iRowsize); - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CLEAR_CANVAS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode next_frame (mng_datap pData, - mng_uint8 iFramemode, - mng_uint8 iChangedelay, - mng_uint32 iDelay, - mng_uint8 iChangetimeout, - mng_uint32 iTimeout, - mng_uint8 iChangeclipping, - mng_uint8 iCliptype, - mng_int32 iClipl, - mng_int32 iClipr, - mng_int32 iClipt, - mng_int32 iClipb) -{ - mng_retcode iRetcode = MNG_NOERROR; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_NEXT_FRAME, MNG_LC_START); -#endif - - if (!pData->iBreakpoint) /* no previous break here ? */ - { -#ifndef MNG_SKIPCHUNK_FRAM - mng_uint8 iOldmode = pData->iFramemode; - /* interframe delay required ? */ - if ((iOldmode == 2) || (iOldmode == 4)) - { - if ((pData->iFrameseq) && (iFramemode != 1) && (iFramemode != 3)) - iRetcode = interframe_delay (pData); - else - pData->iFramedelay = pData->iNextdelay; - } - else - { /* delay before inserting background layer? */ - if ((pData->bFramedone) && (iFramemode == 4)) - iRetcode = interframe_delay (pData); - } - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* now we'll assume we're in the next frame! */ - if (iFramemode) /* save the new framing mode ? */ - { - pData->iFRAMmode = iFramemode; - pData->iFramemode = iFramemode; - } - else /* reload default */ - pData->iFramemode = pData->iFRAMmode; - - if (iChangedelay) /* delay changed ? */ - { - pData->iNextdelay = iDelay; /* for *after* next subframe */ - - if ((iOldmode == 2) || (iOldmode == 4)) - pData->iFramedelay = pData->iFRAMdelay; - - if (iChangedelay == 2) /* also overall ? */ - pData->iFRAMdelay = iDelay; - } - else - { /* reload default */ - pData->iNextdelay = pData->iFRAMdelay; - } - - if (iChangetimeout) /* timeout changed ? */ - { /* for next subframe */ - pData->iFrametimeout = iTimeout; - - if ((iChangetimeout == 2) || /* also overall ? */ - (iChangetimeout == 4) || - (iChangetimeout == 6) || - (iChangetimeout == 8)) - pData->iFRAMtimeout = iTimeout; - } - else /* reload default */ - pData->iFrametimeout = pData->iFRAMtimeout; - - if (iChangeclipping) /* clipping changed ? */ - { - pData->bFrameclipping = MNG_TRUE; - - if (!iCliptype) /* absolute ? */ - { - pData->iFrameclipl = iClipl; - pData->iFrameclipr = iClipr; - pData->iFrameclipt = iClipt; - pData->iFrameclipb = iClipb; - } - else /* relative */ - { - pData->iFrameclipl = pData->iFrameclipl + iClipl; - pData->iFrameclipr = pData->iFrameclipr + iClipr; - pData->iFrameclipt = pData->iFrameclipt + iClipt; - pData->iFrameclipb = pData->iFrameclipb + iClipb; - } - - if (iChangeclipping == 2) /* also overall ? */ - { - pData->bFRAMclipping = MNG_TRUE; - - if (!iCliptype) /* absolute ? */ - { - pData->iFRAMclipl = iClipl; - pData->iFRAMclipr = iClipr; - pData->iFRAMclipt = iClipt; - pData->iFRAMclipb = iClipb; - } - else /* relative */ - { - pData->iFRAMclipl = pData->iFRAMclipl + iClipl; - pData->iFRAMclipr = pData->iFRAMclipr + iClipr; - pData->iFRAMclipt = pData->iFRAMclipt + iClipt; - pData->iFRAMclipb = pData->iFRAMclipb + iClipb; - } - } - } - else - { /* reload defaults */ - pData->bFrameclipping = pData->bFRAMclipping; - pData->iFrameclipl = pData->iFRAMclipl; - pData->iFrameclipr = pData->iFRAMclipr; - pData->iFrameclipt = pData->iFRAMclipt; - pData->iFrameclipb = pData->iFRAMclipb; - } -#endif - } - - if (!pData->bTimerset) /* timer still off ? */ - { - if ( -#ifndef MNG_SKIPCHUNK_FRAM - (pData->iFramemode == 4) || /* insert background layer after a new frame */ -#endif - (!pData->iLayerseq)) /* and certainly before the very first layer */ - iRetcode = load_bkgdlayer (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - pData->iFrameseq++; /* count the frame ! */ - pData->bFramedone = MNG_TRUE; /* and indicate we've done one */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_NEXT_FRAME, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode next_layer (mng_datap pData) -{ - mng_imagep pImage; - mng_retcode iRetcode = MNG_NOERROR; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_NEXT_LAYER, MNG_LC_START); -#endif - -#ifndef MNG_SKIPCHUNK_FRAM - if (!pData->iBreakpoint) /* no previous break here ? */ - { /* interframe delay required ? */ - if ((pData->eImagetype == mng_it_mng) && (pData->iLayerseq) && - ((pData->iFramemode == 1) || (pData->iFramemode == 3))) - iRetcode = interframe_delay (pData); - else - pData->iFramedelay = pData->iNextdelay; - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif - - if (!pData->bTimerset) /* timer still off ? */ - { - if (!pData->iLayerseq) /* restore background for the very first layer ? */ - { /* wait till IDAT/JDAT for PNGs & JNGs !!! */ - if ((pData->eImagetype == mng_it_png) || (pData->eImagetype == mng_it_jng)) - pData->bRestorebkgd = MNG_TRUE; - else - { /* for MNG we do it right away */ - iRetcode = load_bkgdlayer (pData); - pData->iLayerseq++; /* and it counts as a layer then ! */ - } - } -#ifndef MNG_SKIPCHUNK_FRAM - else - if (pData->iFramemode == 3) /* restore background for each layer ? */ - iRetcode = load_bkgdlayer (pData); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* processing a delta-image ? */ - pImage = (mng_imagep)pData->pDeltaImage; - else -#endif - pImage = (mng_imagep)pData->pCurrentobj; - - if (!pImage) /* not an active object ? */ - pImage = (mng_imagep)pData->pObjzero; - /* determine display rectangle */ - pData->iDestl = MAX_COORD ((mng_int32)0, pImage->iPosx); - pData->iDestt = MAX_COORD ((mng_int32)0, pImage->iPosy); - /* is it a valid buffer ? */ - if ((pImage->pImgbuf->iWidth) && (pImage->pImgbuf->iHeight)) - { - pData->iDestr = MIN_COORD ((mng_int32)pData->iWidth, - pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth ); - pData->iDestb = MIN_COORD ((mng_int32)pData->iHeight, - pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight); - } - else /* it's a single image ! */ - { - pData->iDestr = MIN_COORD ((mng_int32)pData->iWidth, - (mng_int32)pData->iDatawidth ); - pData->iDestb = MIN_COORD ((mng_int32)pData->iHeight, - (mng_int32)pData->iDataheight); - } - -#ifndef MNG_SKIPCHUNK_FRAM - if (pData->bFrameclipping) /* frame clipping specified ? */ - { - pData->iDestl = MAX_COORD (pData->iDestl, pData->iFrameclipl); - pData->iDestt = MAX_COORD (pData->iDestt, pData->iFrameclipt); - pData->iDestr = MIN_COORD (pData->iDestr, pData->iFrameclipr); - pData->iDestb = MIN_COORD (pData->iDestb, pData->iFrameclipb); - } -#endif - - if (pImage->bClipped) /* is the image clipped itself ? */ - { - pData->iDestl = MAX_COORD (pData->iDestl, pImage->iClipl); - pData->iDestt = MAX_COORD (pData->iDestt, pImage->iClipt); - pData->iDestr = MIN_COORD (pData->iDestr, pImage->iClipr); - pData->iDestb = MIN_COORD (pData->iDestb, pImage->iClipb); - } - /* determine source starting point */ - pData->iSourcel = MAX_COORD ((mng_int32)0, pData->iDestl - pImage->iPosx); - pData->iSourcet = MAX_COORD ((mng_int32)0, pData->iDestt - pImage->iPosy); - - if ((pImage->pImgbuf->iWidth) && (pImage->pImgbuf->iHeight)) - { /* and maximum size */ - pData->iSourcer = MIN_COORD ((mng_int32)pImage->pImgbuf->iWidth, - pData->iSourcel + pData->iDestr - pData->iDestl); - pData->iSourceb = MIN_COORD ((mng_int32)pImage->pImgbuf->iHeight, - pData->iSourcet + pData->iDestb - pData->iDestt); - } - else /* it's a single image ! */ - { - pData->iSourcer = pData->iSourcel + pData->iDestr - pData->iDestl; - pData->iSourceb = pData->iSourcet + pData->iDestb - pData->iDestt; - } - - pData->iLayerseq++; /* count the layer ! */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_NEXT_LAYER, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_display_image (mng_datap pData, - mng_imagep pImage, - mng_bool bLayeradvanced) -{ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_IMAGE, MNG_LC_START); -#endif - /* actively running ? */ -#ifndef MNG_SKIPCHUNK_MAGN - if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping)) - { - if ( (!pData->iBreakpoint) && /* needs magnification ? */ - ( (pImage->iMAGN_MethodX) || (pImage->iMAGN_MethodY) ) ) - { - iRetcode = mng_magnify_imageobject (pData, pImage); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } -#endif - - pData->pRetrieveobj = pImage; /* so retrieve-row and color-correction can find it */ - - if (!bLayeradvanced) /* need to advance the layer ? */ - { - mng_imagep pSave = pData->pCurrentobj; - pData->pCurrentobj = pImage; - next_layer (pData); /* advance to next layer */ - pData->pCurrentobj = pSave; - } - /* need to restore the background ? */ - if ((!pData->bTimerset) && (pData->bRestorebkgd)) - { - mng_imagep pSave = pData->pCurrentobj; - pData->pCurrentobj = pImage; - pData->bRestorebkgd = MNG_FALSE; - iRetcode = load_bkgdlayer (pData); - pData->pCurrentobj = pSave; - - if (iRetcode) /* on error bail out */ - return iRetcode; - - pData->iLayerseq++; /* and it counts as a layer then ! */ - } - /* actively running ? */ - if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping)) - { - if (!pData->bTimerset) /* all systems still go ? */ - { - pData->iBreakpoint = 0; /* let's make absolutely sure... */ - /* anything to display ? */ - if ((pData->iDestr >= pData->iDestl) && (pData->iDestb >= pData->iDestt)) - { - mng_int32 iY; - - set_display_routine (pData); /* determine display routine */ - /* and image-buffer retrieval routine */ - switch (pImage->pImgbuf->iColortype) - { - case 0 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_g16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_g8; - - pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS); - break; - } - - case 2 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8; - - pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS); - break; - } - - - case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8; - pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS); - break; - } - - - case 4 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8; - - pData->bIsOpaque = MNG_FALSE; - break; - } - - - case 6 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; - - pData->bIsOpaque = MNG_FALSE; - break; - } - - case 8 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_g16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_g8; - - pData->bIsOpaque = MNG_TRUE; - break; - } - - case 10 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8; - - pData->bIsOpaque = MNG_TRUE; - break; - } - - - case 12 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8; - - pData->bIsOpaque = MNG_FALSE; - break; - } - - - case 14 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; - - pData->bIsOpaque = MNG_FALSE; - break; - } - - } - - pData->iPass = -1; /* these are the object's dimensions now */ - pData->iRow = pData->iSourcet; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pImage->pImgbuf->iWidth; - pData->iRowsize = pData->iRowsamples << 2; - pData->bIsRGBA16 = MNG_FALSE; - /* adjust for 16-bit object ? */ -#ifndef MNG_NO_16BIT_SUPPORT - if (pImage->pImgbuf->iBitdepth > 8) - { - pData->bIsRGBA16 = MNG_TRUE; - pData->iRowsize = pData->iRowsamples << 3; - } -#endif - - pData->fCorrectrow = MNG_NULL; /* default no color-correction */ - -#ifdef MNG_NO_CMS - iRetcode = MNG_NOERROR; -#else -#if defined(MNG_FULL_CMS) /* determine color-management routine */ - iRetcode = mng_init_full_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); -#elif defined(MNG_GAMMA_ONLY) - iRetcode = mng_init_gamma_only (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); -#elif defined(MNG_APP_CMS) - iRetcode = mng_init_app_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); -#endif - if (iRetcode) /* on error bail out */ - return iRetcode; -#endif /* MNG_NO_CMS */ - /* get a temporary row-buffer */ - MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize); - - iY = pData->iSourcet; /* this is where we start */ - - while ((!iRetcode) && (iY < pData->iSourceb)) - { /* get a row */ - iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData); - /* color correction ? */ - if ((!iRetcode) && (pData->fCorrectrow)) - iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData); - - if (!iRetcode) /* so... display it */ - iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData); - - if (!iRetcode) /* adjust variables for next row */ - iRetcode = mng_next_row (pData); - - iY++; /* and next line */ - } - /* drop the temporary row-buffer */ - MNG_FREE (pData, pData->pRGBArow, pData->iRowsize); - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#if defined(MNG_FULL_CMS) /* cleanup cms stuff */ - iRetcode = mng_clear_cms (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; -#endif - } - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_IMAGE, MNG_LC_END); -#endif - - return MNG_NOERROR; /* whehehe, this is good ! */ -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode mng_execute_delta_image (mng_datap pData, - mng_imagep pTarget, - mng_imagep pDelta) -{ - mng_imagedatap pBuftarget = pTarget->pImgbuf; - mng_imagedatap pBufdelta = pDelta->pImgbuf; - mng_uint32 iY; - mng_retcode iRetcode; - mng_ptr pSaveRGBA; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_EXECUTE_DELTA_IMAGE, MNG_LC_START); -#endif - /* actively running ? */ - if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping)) - { - if (pBufdelta->bHasPLTE) /* palette in delta ? */ - { - mng_uint32 iX; - /* new palette larger than old one ? */ - if ((!pBuftarget->bHasPLTE) || (pBuftarget->iPLTEcount < pBufdelta->iPLTEcount)) - pBuftarget->iPLTEcount = pBufdelta->iPLTEcount; - /* it's definitely got a PLTE now */ - pBuftarget->bHasPLTE = MNG_TRUE; - - for (iX = 0; iX < pBufdelta->iPLTEcount; iX++) - { - pBuftarget->aPLTEentries[iX].iRed = pBufdelta->aPLTEentries[iX].iRed; - pBuftarget->aPLTEentries[iX].iGreen = pBufdelta->aPLTEentries[iX].iGreen; - pBuftarget->aPLTEentries[iX].iBlue = pBufdelta->aPLTEentries[iX].iBlue; - } - } - - if (pBufdelta->bHasTRNS) /* cheap transparency in delta ? */ - { - switch (pData->iColortype) /* drop it into the target */ - { - case 0: { /* gray */ - pBuftarget->iTRNSgray = pBufdelta->iTRNSgray; - pBuftarget->iTRNSred = 0; - pBuftarget->iTRNSgreen = 0; - pBuftarget->iTRNSblue = 0; - pBuftarget->iTRNScount = 0; - break; - } - case 2: { /* rgb */ - pBuftarget->iTRNSgray = 0; - pBuftarget->iTRNSred = pBufdelta->iTRNSred; - pBuftarget->iTRNSgreen = pBufdelta->iTRNSgreen; - pBuftarget->iTRNSblue = pBufdelta->iTRNSblue; - pBuftarget->iTRNScount = 0; - break; - } - case 3: { /* indexed */ - pBuftarget->iTRNSgray = 0; - pBuftarget->iTRNSred = 0; - pBuftarget->iTRNSgreen = 0; - pBuftarget->iTRNSblue = 0; - /* existing range smaller than new one ? */ - if ((!pBuftarget->bHasTRNS) || (pBuftarget->iTRNScount < pBufdelta->iTRNScount)) - pBuftarget->iTRNScount = pBufdelta->iTRNScount; - - MNG_COPY (pBuftarget->aTRNSentries, pBufdelta->aTRNSentries, pBufdelta->iTRNScount); - break; - } - } - - pBuftarget->bHasTRNS = MNG_TRUE; /* tell it it's got a tRNS now */ - } - -#ifndef MNG_SKIPCHUNK_bKGD - if (pBufdelta->bHasBKGD) /* bkgd in source ? */ - { /* drop it onto the target */ - pBuftarget->bHasBKGD = MNG_TRUE; - pBuftarget->iBKGDindex = pBufdelta->iBKGDindex; - pBuftarget->iBKGDgray = pBufdelta->iBKGDgray; - pBuftarget->iBKGDred = pBufdelta->iBKGDred; - pBuftarget->iBKGDgreen = pBufdelta->iBKGDgreen; - pBuftarget->iBKGDblue = pBufdelta->iBKGDblue; - } -#endif - - if (pBufdelta->bHasGAMA) /* gamma in source ? */ - { - pBuftarget->bHasGAMA = MNG_TRUE; /* drop it onto the target */ - pBuftarget->iGamma = pBufdelta->iGamma; - } - -#ifndef MNG_SKIPCHUNK_cHRM - if (pBufdelta->bHasCHRM) /* chroma in delta ? */ - { /* drop it onto the target */ - pBuftarget->bHasCHRM = MNG_TRUE; - pBuftarget->iWhitepointx = pBufdelta->iWhitepointx; - pBuftarget->iWhitepointy = pBufdelta->iWhitepointy; - pBuftarget->iPrimaryredx = pBufdelta->iPrimaryredx; - pBuftarget->iPrimaryredy = pBufdelta->iPrimaryredy; - pBuftarget->iPrimarygreenx = pBufdelta->iPrimarygreenx; - pBuftarget->iPrimarygreeny = pBufdelta->iPrimarygreeny; - pBuftarget->iPrimarybluex = pBufdelta->iPrimarybluex; - pBuftarget->iPrimarybluey = pBufdelta->iPrimarybluey; - } -#endif - -#ifndef MNG_SKIPCHUNK_sRGB - if (pBufdelta->bHasSRGB) /* sRGB in delta ? */ - { /* drop it onto the target */ - pBuftarget->bHasSRGB = MNG_TRUE; - pBuftarget->iRenderingintent = pBufdelta->iRenderingintent; - } -#endif - -#ifndef MNG_SKIPCHUNK_iCCP - if (pBufdelta->bHasICCP) /* ICC profile in delta ? */ - { - pBuftarget->bHasICCP = MNG_TRUE; /* drop it onto the target */ - - if (pBuftarget->pProfile) /* profile existed ? */ - MNG_FREEX (pData, pBuftarget->pProfile, pBuftarget->iProfilesize); - /* allocate a buffer & copy it */ - MNG_ALLOC (pData, pBuftarget->pProfile, pBufdelta->iProfilesize); - MNG_COPY (pBuftarget->pProfile, pBufdelta->pProfile, pBufdelta->iProfilesize); - /* store its length as well */ - pBuftarget->iProfilesize = pBufdelta->iProfilesize; - } -#endif - /* need to execute delta pixels ? */ - if ((!pData->bDeltaimmediate) && (pData->iDeltatype != MNG_DELTATYPE_NOCHANGE)) - { - pData->fScalerow = MNG_NULL; /* not needed by default */ - - switch (pBufdelta->iBitdepth) /* determine scaling routine */ - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { - switch (pBuftarget->iBitdepth) - { - case 2 : { pData->fScalerow = (mng_fptr)mng_scale_g1_g2; break; } - case 4 : { pData->fScalerow = (mng_fptr)mng_scale_g1_g4; break; } - - case 8 : { pData->fScalerow = (mng_fptr)mng_scale_g1_g8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fScalerow = (mng_fptr)mng_scale_g1_g16; break; } -#endif - } - break; - } - - case 2 : { - switch (pBuftarget->iBitdepth) - { - case 1 : { pData->fScalerow = (mng_fptr)mng_scale_g2_g1; break; } - case 4 : { pData->fScalerow = (mng_fptr)mng_scale_g2_g4; break; } - case 8 : { pData->fScalerow = (mng_fptr)mng_scale_g2_g8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fScalerow = (mng_fptr)mng_scale_g2_g16; break; } -#endif - } - break; - } - - case 4 : { - switch (pBuftarget->iBitdepth) - { - case 1 : { pData->fScalerow = (mng_fptr)mng_scale_g4_g1; break; } - case 2 : { pData->fScalerow = (mng_fptr)mng_scale_g4_g2; break; } - case 8 : { pData->fScalerow = (mng_fptr)mng_scale_g4_g8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fScalerow = (mng_fptr)mng_scale_g4_g16; break; } -#endif - } - break; - } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - - case 8 : { - switch (pBufdelta->iColortype) - { - case 0 : ; - case 3 : ; - case 8 : { - switch (pBuftarget->iBitdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { pData->fScalerow = (mng_fptr)mng_scale_g8_g1; break; } - case 2 : { pData->fScalerow = (mng_fptr)mng_scale_g8_g2; break; } - case 4 : { pData->fScalerow = (mng_fptr)mng_scale_g8_g4; break; } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fScalerow = (mng_fptr)mng_scale_g8_g16; break; } -#endif - } - break; - } - case 2 : ; - case 10 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pBuftarget->iBitdepth == 16) - pData->fScalerow = (mng_fptr)mng_scale_rgb8_rgb16; -#endif - break; - } - case 4 : ; - case 12 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pBuftarget->iBitdepth == 16) - pData->fScalerow = (mng_fptr)mng_scale_ga8_ga16; -#endif - break; - } - case 6 : ; - case 14 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pBuftarget->iBitdepth == 16) - pData->fScalerow = (mng_fptr)mng_scale_rgba8_rgba16; -#endif - break; - } - } - break; - } - -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - switch (pBufdelta->iColortype) - { - case 0 : ; - case 3 : ; - case 8 : { - switch (pBuftarget->iBitdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { pData->fScalerow = (mng_fptr)mng_scale_g16_g1; break; } - case 2 : { pData->fScalerow = (mng_fptr)mng_scale_g16_g2; break; } - case 4 : { pData->fScalerow = (mng_fptr)mng_scale_g16_g4; break; } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { pData->fScalerow = (mng_fptr)mng_scale_g16_g8; break; } - } - break; - } - case 2 : ; - case 10 : { - if (pBuftarget->iBitdepth == 8) - pData->fScalerow = (mng_fptr)mng_scale_rgb16_rgb8; - break; - } - case 4 : ; - case 12 : { - if (pBuftarget->iBitdepth == 8) - pData->fScalerow = (mng_fptr)mng_scale_ga16_ga8; - break; - } - case 6 : ; - case 14 : { - if (pBuftarget->iBitdepth == 8) - pData->fScalerow = (mng_fptr)mng_scale_rgba16_rgba8; - break; - } - } - break; - } -#endif - - } - - pData->fDeltarow = MNG_NULL; /* let's assume there's nothing to do */ - - switch (pBuftarget->iColortype) /* determine delta processing routine */ - { - case 0 : ; - case 8 : { /* gray */ - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3) || - (pBufdelta->iColortype == 8)) - { - switch (pBuftarget->iBitdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { pData->fDeltarow = (mng_fptr)mng_delta_g1_g1; break; } - case 2 : { pData->fDeltarow = (mng_fptr)mng_delta_g2_g2; break; } - case 4 : { pData->fDeltarow = (mng_fptr)mng_delta_g4_g4; break; } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_g8_g8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_g16_g16; break; } -#endif - } - } - } - - break; - } - - case 2 : ; - case 10 : { /* rgb */ - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - if ((pBufdelta->iColortype == 2) || (pBufdelta->iColortype == 10)) - { - switch (pBuftarget->iBitdepth) - { - case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_rgb8_rgb8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_rgb16_rgb16; break; } -#endif - } - } - } - - break; - } - - case 3 : { /* indexed; abuse gray routines */ - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3)) - { - switch (pBuftarget->iBitdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { pData->fDeltarow = (mng_fptr)mng_delta_g1_g1; break; } - case 2 : { pData->fDeltarow = (mng_fptr)mng_delta_g2_g2; break; } - case 4 : { pData->fDeltarow = (mng_fptr)mng_delta_g4_g4; break; } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_g8_g8; break; } - } - } - } - - break; - } - - case 4 : ; - case 12 : { /* gray + alpha */ - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - if ((pBufdelta->iColortype == 4) || (pBufdelta->iColortype == 12)) - { - switch (pBuftarget->iBitdepth) - { - case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_ga8_ga8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_ga16_ga16; break; } -#endif - } - } - } - else - if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) ) - { - if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3) || - (pBufdelta->iColortype == 8)) - { - switch (pBuftarget->iBitdepth) - { - case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_ga8_g8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_ga16_g16; break; } -#endif - } - } - } - else - if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) ) - { - if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3)) - { - switch (pBuftarget->iBitdepth) - { - case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_ga8_a8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_ga16_a16; break; } -#endif - } - } - } - - break; - } - - case 6 : ; - case 14 : { /* rgb + alpha */ - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - if ((pBufdelta->iColortype == 6) || (pBufdelta->iColortype == 14)) - { - switch (pBuftarget->iBitdepth) - { - case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba8_rgba8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba16_rgba16; break; } -#endif - } - } - } - else - if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) ) - { - if ((pBufdelta->iColortype == 2) || (pBufdelta->iColortype == 10)) - { - switch (pBuftarget->iBitdepth) - { - case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba8_rgb8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba16_rgb16; break; } -#endif - } - } - } - else - if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) ) - { - if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3)) - { - switch (pBuftarget->iBitdepth) - { - case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba8_a8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba16_a16; break; } -#endif - } - } - } - - break; - } - - } - - if (pData->fDeltarow) /* do we need to take action ? */ - { - pData->iPass = -1; /* setup row dimensions and stuff */ - pData->iRow = pData->iDeltaBlocky; - pData->iRowinc = 1; - pData->iCol = pData->iDeltaBlockx; - pData->iColinc = 1; - pData->iRowsamples = pBufdelta->iWidth; - pData->iRowsize = pBuftarget->iRowsize; - /* indicate where to retrieve & where to store */ - pData->pRetrieveobj = (mng_objectp)pDelta; - pData->pStoreobj = (mng_objectp)pTarget; - - pSaveRGBA = pData->pRGBArow; /* save current temp-buffer! */ - /* get a temporary row-buffer */ - MNG_ALLOC (pData, pData->pRGBArow, (pBufdelta->iRowsize << 1)); - - iY = 0; /* this is where we start */ - iRetcode = MNG_NOERROR; /* still oke for now */ - - while ((!iRetcode) && (iY < pBufdelta->iHeight)) - { /* get a row */ - mng_uint8p pWork = pBufdelta->pImgdata + (iY * pBufdelta->iRowsize); - - MNG_COPY (pData->pRGBArow, pWork, pBufdelta->iRowsize); - - if (pData->fScalerow) /* scale it (if necessary) */ - iRetcode = ((mng_scalerow)pData->fScalerow) (pData); - - if (!iRetcode) /* and... execute it */ - iRetcode = ((mng_deltarow)pData->fDeltarow) (pData); - - if (!iRetcode) /* adjust variables for next row */ - iRetcode = mng_next_row (pData); - - iY++; /* and next line */ - } - /* drop the temporary row-buffer */ - MNG_FREE (pData, pData->pRGBArow, (pBufdelta->iRowsize << 1)); - pData->pRGBArow = pSaveRGBA; /* restore saved temp-buffer! */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } - else - MNG_ERROR (pData, MNG_INVALIDDELTA); - - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_EXECUTE_DELTA_IMAGE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_DELTA_PNG */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SAVE -MNG_LOCAL mng_retcode save_state (mng_datap pData) -{ - mng_savedatap pSave; - mng_imagep pImage; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SAVE_STATE, MNG_LC_START); -#endif - - if (pData->pSavedata) /* sanity check */ - MNG_ERROR (pData, MNG_INTERNALERROR); - /* get a buffer for saving */ - MNG_ALLOC (pData, pData->pSavedata, sizeof (mng_savedata)); - - pSave = pData->pSavedata; /* address it more directly */ - /* and copy global data from the main struct */ -#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) - pSave->bHasglobalPLTE = pData->bHasglobalPLTE; - pSave->bHasglobalTRNS = pData->bHasglobalTRNS; - pSave->bHasglobalGAMA = pData->bHasglobalGAMA; - pSave->bHasglobalCHRM = pData->bHasglobalCHRM; - pSave->bHasglobalSRGB = pData->bHasglobalSRGB; - pSave->bHasglobalICCP = pData->bHasglobalICCP; - pSave->bHasglobalBKGD = pData->bHasglobalBKGD; -#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ - -#ifndef MNG_SKIPCHUNK_BACK - pSave->iBACKred = pData->iBACKred; - pSave->iBACKgreen = pData->iBACKgreen; - pSave->iBACKblue = pData->iBACKblue; - pSave->iBACKmandatory = pData->iBACKmandatory; - pSave->iBACKimageid = pData->iBACKimageid; - pSave->iBACKtile = pData->iBACKtile; -#endif - -#ifndef MNG_SKIPCHUNK_FRAM - pSave->iFRAMmode = pData->iFRAMmode; - pSave->iFRAMdelay = pData->iFRAMdelay; - pSave->iFRAMtimeout = pData->iFRAMtimeout; - pSave->bFRAMclipping = pData->bFRAMclipping; - pSave->iFRAMclipl = pData->iFRAMclipl; - pSave->iFRAMclipr = pData->iFRAMclipr; - pSave->iFRAMclipt = pData->iFRAMclipt; - pSave->iFRAMclipb = pData->iFRAMclipb; -#endif - - pSave->iGlobalPLTEcount = pData->iGlobalPLTEcount; - - MNG_COPY (pSave->aGlobalPLTEentries, pData->aGlobalPLTEentries, sizeof (mng_rgbpaltab)); - - pSave->iGlobalTRNSrawlen = pData->iGlobalTRNSrawlen; - MNG_COPY (pSave->aGlobalTRNSrawdata, pData->aGlobalTRNSrawdata, 256); - - pSave->iGlobalGamma = pData->iGlobalGamma; - -#ifndef MNG_SKIPCHUNK_cHRM - pSave->iGlobalWhitepointx = pData->iGlobalWhitepointx; - pSave->iGlobalWhitepointy = pData->iGlobalWhitepointy; - pSave->iGlobalPrimaryredx = pData->iGlobalPrimaryredx; - pSave->iGlobalPrimaryredy = pData->iGlobalPrimaryredy; - pSave->iGlobalPrimarygreenx = pData->iGlobalPrimarygreenx; - pSave->iGlobalPrimarygreeny = pData->iGlobalPrimarygreeny; - pSave->iGlobalPrimarybluex = pData->iGlobalPrimarybluex; - pSave->iGlobalPrimarybluey = pData->iGlobalPrimarybluey; -#endif - -#ifndef MNG_SKIPCHUNK_sRGB - pSave->iGlobalRendintent = pData->iGlobalRendintent; -#endif - -#ifndef MNG_SKIPCHUNK_iCCP - pSave->iGlobalProfilesize = pData->iGlobalProfilesize; - - if (pSave->iGlobalProfilesize) /* has a profile ? */ - { /* then copy that ! */ - MNG_ALLOC (pData, pSave->pGlobalProfile, pSave->iGlobalProfilesize); - MNG_COPY (pSave->pGlobalProfile, pData->pGlobalProfile, pSave->iGlobalProfilesize); - } -#endif - -#ifndef MNG_SKIPCHUNK_bKGD - pSave->iGlobalBKGDred = pData->iGlobalBKGDred; - pSave->iGlobalBKGDgreen = pData->iGlobalBKGDgreen; - pSave->iGlobalBKGDblue = pData->iGlobalBKGDblue; -#endif - - /* freeze current image objects */ - pImage = (mng_imagep)pData->pFirstimgobj; - - while (pImage) - { /* freeze the object AND its buffer */ - pImage->bFrozen = MNG_TRUE; - pImage->pImgbuf->bFrozen = MNG_TRUE; - /* neeeext */ - pImage = (mng_imagep)pImage->sHeader.pNext; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SAVE_STATE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_reset_objzero (mng_datap pData) -{ - mng_imagep pImage = (mng_imagep)pData->pObjzero; - mng_retcode iRetcode = mng_reset_object_details (pData, pImage, 0, 0, 0, - 0, 0, 0, 0, MNG_TRUE); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - pImage->bVisible = MNG_TRUE; - pImage->bViewable = MNG_TRUE; - pImage->iPosx = 0; - pImage->iPosy = 0; - pImage->bClipped = MNG_FALSE; - pImage->iClipl = 0; - pImage->iClipr = 0; - pImage->iClipt = 0; - pImage->iClipb = 0; -#ifndef MNG_SKIPCHUNK_MAGN - pImage->iMAGN_MethodX = 0; - pImage->iMAGN_MethodY = 0; - pImage->iMAGN_MX = 0; - pImage->iMAGN_MY = 0; - pImage->iMAGN_ML = 0; - pImage->iMAGN_MR = 0; - pImage->iMAGN_MT = 0; - pImage->iMAGN_MB = 0; -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode restore_state (mng_datap pData) -{ -#ifndef MNG_SKIPCHUNK_SAVE - mng_savedatap pSave; -#endif - mng_imagep pImage; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_STATE, MNG_LC_START); -#endif - /* restore object 0 status !!! */ - iRetcode = mng_reset_objzero (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* fresh cycle; fake no frames done yet */ - pData->bFramedone = MNG_FALSE; - -#ifndef MNG_SKIPCHUNK_SAVE - if (pData->pSavedata) /* do we have a saved state ? */ - { - pSave = pData->pSavedata; /* address it more directly */ - /* and copy it back to the main struct */ -#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) - pData->bHasglobalPLTE = pSave->bHasglobalPLTE; - pData->bHasglobalTRNS = pSave->bHasglobalTRNS; - pData->bHasglobalGAMA = pSave->bHasglobalGAMA; - pData->bHasglobalCHRM = pSave->bHasglobalCHRM; - pData->bHasglobalSRGB = pSave->bHasglobalSRGB; - pData->bHasglobalICCP = pSave->bHasglobalICCP; - pData->bHasglobalBKGD = pSave->bHasglobalBKGD; -#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ - -#ifndef MNG_SKIPCHUNK_BACK - pData->iBACKred = pSave->iBACKred; - pData->iBACKgreen = pSave->iBACKgreen; - pData->iBACKblue = pSave->iBACKblue; - pData->iBACKmandatory = pSave->iBACKmandatory; - pData->iBACKimageid = pSave->iBACKimageid; - pData->iBACKtile = pSave->iBACKtile; -#endif - -#ifndef MNG_SKIPCHUNK_FRAM - pData->iFRAMmode = pSave->iFRAMmode; -/* pData->iFRAMdelay = pSave->iFRAMdelay; */ - pData->iFRAMtimeout = pSave->iFRAMtimeout; - pData->bFRAMclipping = pSave->bFRAMclipping; - pData->iFRAMclipl = pSave->iFRAMclipl; - pData->iFRAMclipr = pSave->iFRAMclipr; - pData->iFRAMclipt = pSave->iFRAMclipt; - pData->iFRAMclipb = pSave->iFRAMclipb; - /* NOOOOOOOOOOOO */ -/* pData->iFramemode = pSave->iFRAMmode; - pData->iFramedelay = pSave->iFRAMdelay; - pData->iFrametimeout = pSave->iFRAMtimeout; - pData->bFrameclipping = pSave->bFRAMclipping; - pData->iFrameclipl = pSave->iFRAMclipl; - pData->iFrameclipr = pSave->iFRAMclipr; - pData->iFrameclipt = pSave->iFRAMclipt; - pData->iFrameclipb = pSave->iFRAMclipb; */ - -/* pData->iNextdelay = pSave->iFRAMdelay; */ - pData->iNextdelay = pData->iFramedelay; -#endif - - pData->iGlobalPLTEcount = pSave->iGlobalPLTEcount; - MNG_COPY (pData->aGlobalPLTEentries, pSave->aGlobalPLTEentries, sizeof (mng_rgbpaltab)); - - pData->iGlobalTRNSrawlen = pSave->iGlobalTRNSrawlen; - MNG_COPY (pData->aGlobalTRNSrawdata, pSave->aGlobalTRNSrawdata, 256); - - pData->iGlobalGamma = pSave->iGlobalGamma; - -#ifndef MNG_SKIPCHUNK_cHRM - pData->iGlobalWhitepointx = pSave->iGlobalWhitepointx; - pData->iGlobalWhitepointy = pSave->iGlobalWhitepointy; - pData->iGlobalPrimaryredx = pSave->iGlobalPrimaryredx; - pData->iGlobalPrimaryredy = pSave->iGlobalPrimaryredy; - pData->iGlobalPrimarygreenx = pSave->iGlobalPrimarygreenx; - pData->iGlobalPrimarygreeny = pSave->iGlobalPrimarygreeny; - pData->iGlobalPrimarybluex = pSave->iGlobalPrimarybluex; - pData->iGlobalPrimarybluey = pSave->iGlobalPrimarybluey; -#endif - - pData->iGlobalRendintent = pSave->iGlobalRendintent; - -#ifndef MNG_SKIPCHUNK_iCCP - pData->iGlobalProfilesize = pSave->iGlobalProfilesize; - - if (pData->iGlobalProfilesize) /* has a profile ? */ - { /* then copy that ! */ - MNG_ALLOC (pData, pData->pGlobalProfile, pData->iGlobalProfilesize); - MNG_COPY (pData->pGlobalProfile, pSave->pGlobalProfile, pData->iGlobalProfilesize); - } -#endif - -#ifndef MNG_SKIPCHUNK_bKGD - pData->iGlobalBKGDred = pSave->iGlobalBKGDred; - pData->iGlobalBKGDgreen = pSave->iGlobalBKGDgreen; - pData->iGlobalBKGDblue = pSave->iGlobalBKGDblue; -#endif - } - else /* no saved-data; so reset the lot */ -#endif /* SKIPCHUNK_SAVE */ - { -#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) - pData->bHasglobalPLTE = MNG_FALSE; - pData->bHasglobalTRNS = MNG_FALSE; - pData->bHasglobalGAMA = MNG_FALSE; - pData->bHasglobalCHRM = MNG_FALSE; - pData->bHasglobalSRGB = MNG_FALSE; - pData->bHasglobalICCP = MNG_FALSE; - pData->bHasglobalBKGD = MNG_FALSE; -#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ - -#ifndef MNG_SKIPCHUNK_TERM - if (!pData->bMisplacedTERM) /* backward compatible ugliness !!! */ - { - pData->iBACKred = 0; - pData->iBACKgreen = 0; - pData->iBACKblue = 0; - pData->iBACKmandatory = 0; - pData->iBACKimageid = 0; - pData->iBACKtile = 0; - } -#endif - -#ifndef MNG_SKIPCHUNK_FRAM - pData->iFRAMmode = 1; -/* pData->iFRAMdelay = 1; */ - pData->iFRAMtimeout = 0x7fffffffl; - pData->bFRAMclipping = MNG_FALSE; - pData->iFRAMclipl = 0; - pData->iFRAMclipr = 0; - pData->iFRAMclipt = 0; - pData->iFRAMclipb = 0; - /* NOOOOOOOOOOOO */ -/* pData->iFramemode = 1; - pData->iFramedelay = 1; - pData->iFrametimeout = 0x7fffffffl; - pData->bFrameclipping = MNG_FALSE; - pData->iFrameclipl = 0; - pData->iFrameclipr = 0; - pData->iFrameclipt = 0; - pData->iFrameclipb = 0; */ - -/* pData->iNextdelay = 1; */ - pData->iNextdelay = pData->iFramedelay; -#endif - - pData->iGlobalPLTEcount = 0; - - pData->iGlobalTRNSrawlen = 0; - - pData->iGlobalGamma = 0; - -#ifndef MNG_SKIPCHUNK_cHRM - pData->iGlobalWhitepointx = 0; - pData->iGlobalWhitepointy = 0; - pData->iGlobalPrimaryredx = 0; - pData->iGlobalPrimaryredy = 0; - pData->iGlobalPrimarygreenx = 0; - pData->iGlobalPrimarygreeny = 0; - pData->iGlobalPrimarybluex = 0; - pData->iGlobalPrimarybluey = 0; -#endif - - pData->iGlobalRendintent = 0; - -#ifndef MNG_SKIPCHUNK_iCCP - if (pData->iGlobalProfilesize) /* free a previous profile ? */ - MNG_FREE (pData, pData->pGlobalProfile, pData->iGlobalProfilesize); - - pData->iGlobalProfilesize = 0; -#endif - -#ifndef MNG_SKIPCHUNK_bKGD - pData->iGlobalBKGDred = 0; - pData->iGlobalBKGDgreen = 0; - pData->iGlobalBKGDblue = 0; -#endif - } - -#ifndef MNG_SKIPCHUNK_TERM - if (!pData->bMisplacedTERM) /* backward compatible ugliness !!! */ - { - pImage = (mng_imagep)pData->pFirstimgobj; - /* drop un-frozen image objects */ - while (pImage) - { - mng_imagep pNext = (mng_imagep)pImage->sHeader.pNext; - - if (!pImage->bFrozen) /* is it un-frozen ? */ - { - mng_imagep pPrev = (mng_imagep)pImage->sHeader.pPrev; - - if (pPrev) /* unlink it */ - pPrev->sHeader.pNext = pNext; - else - pData->pFirstimgobj = pNext; - - if (pNext) - pNext->sHeader.pPrev = pPrev; - else - pData->pLastimgobj = pPrev; - - if (pImage->pImgbuf->bFrozen) /* buffer frozen ? */ - { - if (pImage->pImgbuf->iRefcount < 2) - MNG_ERROR (pData, MNG_INTERNALERROR); - /* decrease ref counter */ - pImage->pImgbuf->iRefcount--; - /* just cleanup the object then */ - MNG_FREEX (pData, pImage, sizeof (mng_image)); - } - else - { /* free the image buffer */ - iRetcode = mng_free_imagedataobject (pData, pImage->pImgbuf); - /* and cleanup the object */ - MNG_FREEX (pData, pImage, sizeof (mng_image)); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } - - pImage = pNext; /* neeeext */ - } - } -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_STATE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ -/* * * */ -/* * General display processing routine * */ -/* * * */ -/* ************************************************************************** */ - -mng_retcode mng_process_display (mng_datap pData) -{ - mng_retcode iRetcode = MNG_NOERROR; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY, MNG_LC_START); -#endif - - if (!pData->iBreakpoint) /* not broken previously ? */ - { - if ((pData->iRequestframe) || (pData->iRequestlayer) || (pData->iRequesttime)) - { - pData->bSearching = MNG_TRUE; /* indicate we're searching */ - - iRetcode = clear_canvas (pData); /* make the canvas virgin black ?!? */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* let's start from the top, shall we */ - pData->pCurraniobj = pData->pFirstaniobj; - } - } - - do /* process the objects */ - { - if (pData->bSearching) /* clear timer-flag when searching !!! */ - pData->bTimerset = MNG_FALSE; - /* do we need to finish something first ? */ - if ((pData->iBreakpoint) && (pData->iBreakpoint < 99)) - { - switch (pData->iBreakpoint) /* return to broken display routine */ - { -#ifndef MNG_SKIPCHUNK_FRAM - case 1 : { iRetcode = mng_process_display_fram2 (pData); break; } -#endif -#ifndef MNG_SKIPCHUNK_SHOW - case 3 : ; /* same as 4 !!! */ - case 4 : { iRetcode = mng_process_display_show (pData); break; } -#endif -#ifndef MNG_SKIPCHUNK_CLON - case 5 : { iRetcode = mng_process_display_clon2 (pData); break; } -#endif -#ifndef MNG_SKIPCHUNK_MAGN - case 9 : { iRetcode = mng_process_display_magn2 (pData); break; } - case 10 : { iRetcode = mng_process_display_mend2 (pData); break; } -#endif -#ifndef MNG_SKIPCHUNK_PAST - case 11 : { iRetcode = mng_process_display_past2 (pData); break; } -#endif - default : MNG_ERROR (pData, MNG_INTERNALERROR); - } - } - else - { - if (pData->pCurraniobj) - iRetcode = ((mng_object_headerp)pData->pCurraniobj)->fProcess (pData, pData->pCurraniobj); - } - - if (!pData->bTimerset) /* reset breakpoint flag ? */ - pData->iBreakpoint = 0; - /* can we advance to next object ? */ - if ((!iRetcode) && (pData->pCurraniobj) && - (!pData->bTimerset) && (!pData->bSectionwait)) - { - pData->pCurraniobj = ((mng_object_headerp)pData->pCurraniobj)->pNext; - /* MEND processing to be done ? */ - if ((pData->eImagetype == mng_it_mng) && (!pData->pCurraniobj)) - iRetcode = mng_process_display_mend (pData); - - if (!pData->pCurraniobj) /* refresh after last image ? */ - pData->bNeedrefresh = MNG_TRUE; - } - - if (pData->bSearching) /* are we looking for something ? */ - { - if ((pData->iRequestframe) && (pData->iRequestframe <= pData->iFrameseq)) - { - pData->iRequestframe = 0; /* found the frame ! */ - pData->bSearching = MNG_FALSE; - } - else - if ((pData->iRequestlayer) && (pData->iRequestlayer <= pData->iLayerseq)) - { - pData->iRequestlayer = 0; /* found the layer ! */ - pData->bSearching = MNG_FALSE; - } - else - if ((pData->iRequesttime) && (pData->iRequesttime <= pData->iFrametime)) - { - pData->iRequesttime = 0; /* found the playtime ! */ - pData->bSearching = MNG_FALSE; - } - } - } /* until error or a break or no more objects */ - while ((!iRetcode) && (pData->pCurraniobj) && - (((pData->bRunning) && (!pData->bTimerset)) || (pData->bSearching)) && - (!pData->bSectionwait) && (!pData->bFreezing)); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* refresh needed ? */ - if ((!pData->bTimerset) && (pData->bNeedrefresh)) - { - iRetcode = mng_display_progressive_refresh (pData, 1); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - /* timer break ? */ - if ((pData->bTimerset) && (!pData->iBreakpoint)) - pData->iBreakpoint = 99; - else - if (!pData->bTimerset) - pData->iBreakpoint = 0; /* reset if no timer break */ - - if ((!pData->bTimerset) && (!pData->pCurraniobj)) - pData->bRunning = MNG_FALSE; /* all done now ! */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ -/* * * */ -/* * Chunk display processing routines * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT -png_imgtype mng_png_imgtype(mng_uint8 colortype, mng_uint8 bitdepth) -{ - png_imgtype ret; - switch (bitdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1: - { - png_imgtype imgtype[]={png_g1,png_none,png_none,png_idx1}; - ret=imgtype[colortype]; - break; - } - case 2: - { - png_imgtype imgtype[]={png_g2,png_none,png_none,png_idx2}; - ret=imgtype[colortype]; - break; - } - case 4: - { - png_imgtype imgtype[]={png_g4,png_none,png_none,png_idx4}; - ret=imgtype[colortype]; - break; - } -#endif - case 8: - { - png_imgtype imgtype[]={png_g8,png_none,png_rgb8,png_idx8,png_ga8, - png_none,png_rgba8}; - ret=imgtype[colortype]; - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16: - { - png_imgtype imgtype[]={png_g16,png_none,png_rgb16,png_none,png_ga16, - png_none,png_rgba16}; - ret=imgtype[colortype]; - break; - } -#endif - default: - ret=png_none; - break; - } - return (ret); -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ - -/* ************************************************************************** */ - -mng_retcode mng_process_display_ihdr (mng_datap pData) -{ /* address the current "object" if any */ - mng_imagep pImage = (mng_imagep)pData->pCurrentobj; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IHDR, MNG_LC_START); -#endif - - if (!pData->bHasDHDR) - { - pData->fInitrowproc = MNG_NULL; /* do nothing by default */ - pData->fDisplayrow = MNG_NULL; - pData->fCorrectrow = MNG_NULL; - pData->fStorerow = MNG_NULL; - pData->fProcessrow = MNG_NULL; - pData->fDifferrow = MNG_NULL; - pData->pStoreobj = MNG_NULL; - } - - if (!pData->iBreakpoint) /* not previously broken ? */ - { - mng_retcode iRetcode = MNG_NOERROR; - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* is a delta-image ? */ - { - if (pData->iDeltatype == MNG_DELTATYPE_REPLACE) - iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pDeltaImage, - pData->iDatawidth, pData->iDataheight, - pData->iBitdepth, pData->iColortype, - pData->iCompression, pData->iFilter, - pData->iInterlace, MNG_TRUE); - else - if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - ((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iBitdepth; - ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iBitdepth; - } - else - if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) ) - ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iBitdepth; - else - if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) ) - ((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iBitdepth; - - if (!iRetcode) - { /* process immediately if bitdepth & colortype are equal */ - pData->bDeltaimmediate = - (mng_bool)((pData->iBitdepth == ((mng_imagep)pData->pDeltaImage)->pImgbuf->iBitdepth ) && - (pData->iColortype == ((mng_imagep)pData->pDeltaImage)->pImgbuf->iColortype) ); - /* be sure to reset object 0 */ - iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pObjzero, - pData->iDatawidth, pData->iDataheight, - pData->iBitdepth, pData->iColortype, - pData->iCompression, pData->iFilter, - pData->iInterlace, MNG_TRUE); - } - } - else -#endif - { - if (pImage) /* update object buffer ? */ - iRetcode = mng_reset_object_details (pData, pImage, - pData->iDatawidth, pData->iDataheight, - pData->iBitdepth, pData->iColortype, - pData->iCompression, pData->iFilter, - pData->iInterlace, MNG_TRUE); - else - iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pObjzero, - pData->iDatawidth, pData->iDataheight, - pData->iBitdepth, pData->iColortype, - pData->iCompression, pData->iFilter, - pData->iInterlace, MNG_TRUE); - } - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - -#ifndef MNG_NO_DELTA_PNG - if (!pData->bHasDHDR) -#endif - { - if (pImage) /* real object ? */ - pData->pStoreobj = pImage; /* tell the row routines */ - else /* otherwise use object 0 */ - pData->pStoreobj = pData->pObjzero; - -#if !defined(MNG_INCLUDE_MPNG_PROPOSAL) && !defined(MNG_INCLUDE_ANG_PROPOSAL) - if ( /* display "on-the-fly" ? */ -#ifndef MNG_SKIPCHUNK_MAGN - (((mng_imagep)pData->pStoreobj)->iMAGN_MethodX == 0) && - (((mng_imagep)pData->pStoreobj)->iMAGN_MethodY == 0) && -#endif - ( (pData->eImagetype == mng_it_png ) || - (((mng_imagep)pData->pStoreobj)->bVisible) ) ) - { - next_layer (pData); /* that's a new layer then ! */ - - if (pData->bTimerset) /* timer break ? */ - pData->iBreakpoint = 2; - else - { - pData->iBreakpoint = 0; - /* anything to display ? */ - if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt)) - set_display_routine (pData); /* then determine display routine */ - } - } -#endif - } - - if (!pData->bTimerset) /* no timer break ? */ - { -#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT - pData->fInitrowproc = (mng_fptr)mng_init_rowproc; - pData->ePng_imgtype=mng_png_imgtype(pData->iColortype,pData->iBitdepth); -#else - switch (pData->iColortype) /* determine row initialization routine */ - { - case 0 : { /* gray */ - switch (pData->iBitdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g1_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g1_i; - - break; - } - case 2 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g2_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g2_i; - - break; - } - case 4 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g4_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g4_i; - break; - } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g8_i; - - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g16_i; - - break; - } -#endif - } - - break; - } - case 2 : { /* rgb */ - switch (pData->iBitdepth) - { - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i; - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i; - - break; - } -#endif - } - - break; - } - case 3 : { /* indexed */ - switch (pData->iBitdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx1_i; - - break; - } - case 2 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx2_i; - - break; - } - case 4 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx4_i; - - break; - } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx8_i; - - break; - } - } - - break; - } - case 4 : { /* gray+alpha */ - switch (pData->iBitdepth) - { - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_ga8_i; - - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_ga16_i; - break; - } -#endif - } - - break; - } - case 6 : { /* rgb+alpha */ - switch (pData->iBitdepth) - { - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i; - - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i; - - break; - } -#endif - } - - break; - } - } -#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ - - pData->iFilterofs = 0; /* determine filter characteristics */ - pData->iLevel0 = 0; /* default levels */ - pData->iLevel1 = 0; - pData->iLevel2 = 0; - pData->iLevel3 = 0; - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - { - switch (pData->iColortype) - { - case 0 : { - if (pData->iBitdepth <= 8) - pData->iFilterofs = 1; - else - pData->iFilterofs = 2; - - break; - } - case 2 : { - if (pData->iBitdepth <= 8) - pData->iFilterofs = 3; - else - pData->iFilterofs = 6; - - break; - } - case 3 : { - pData->iFilterofs = 1; - break; - } - case 4 : { - if (pData->iBitdepth <= 8) - pData->iFilterofs = 2; - else - pData->iFilterofs = 4; - - break; - } - case 6 : { - if (pData->iBitdepth <= 8) - pData->iFilterofs = 4; - else - pData->iFilterofs = 8; - - break; - } - } - } -#endif - -#ifdef FILTER193 /* no adaptive filtering ? */ - if (pData->iFilter == MNG_FILTER_NOFILTER) - pData->iPixelofs = pData->iFilterofs; - else -#endif - pData->iPixelofs = pData->iFilterofs + 1; - - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_MPNG_PROPOSAL -mng_retcode mng_process_display_mpng (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MPNG, MNG_LC_START); -#endif - - pData->iAlphadepth = 8; /* assume transparency !! */ - - if (pData->fProcessheader) /* inform the app (creating the output canvas) ? */ - { - pData->iWidth = ((mng_mpng_objp)pData->pMPNG)->iFramewidth; - pData->iHeight = ((mng_mpng_objp)pData->pMPNG)->iFrameheight; - - if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) - MNG_ERROR (pData, MNG_APPMISCERROR); - } - - next_layer (pData); /* first mPNG layer then ! */ - pData->bTimerset = MNG_FALSE; - pData->iBreakpoint = 0; - - if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt)) - set_display_routine (pData); /* then determine display routine */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MPNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ANG_PROPOSAL -mng_retcode mng_process_display_ang (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_ANG, MNG_LC_START); -#endif - - if (pData->fProcessheader) /* inform the app (creating the output canvas) ? */ - { - if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) - MNG_ERROR (pData, MNG_APPMISCERROR); - } - - next_layer (pData); /* first mPNG layer then ! */ - pData->bTimerset = MNG_FALSE; - pData->iBreakpoint = 0; - - if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt)) - set_display_routine (pData); /* then determine display routine */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_ANG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -mng_retcode mng_process_display_idat (mng_datap pData, - mng_uint32 iRawlen, - mng_uint8p pRawdata) -#else -mng_retcode mng_process_display_idat (mng_datap pData) -#endif -{ - mng_retcode iRetcode = MNG_NOERROR; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IDAT, MNG_LC_START); -#endif - -#if defined(MNG_INCLUDE_MPNG_PROPOSAL) || defined(MNG_INCLUDE_ANG_PROPOSAL) - if ((pData->eImagetype == mng_it_png) && (pData->iLayerseq <= 0)) - { - if (pData->fProcessheader) /* inform the app (creating the output canvas) ? */ - if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) - MNG_ERROR (pData, MNG_APPMISCERROR); - - next_layer (pData); /* first regular PNG layer then ! */ - pData->bTimerset = MNG_FALSE; - pData->iBreakpoint = 0; - - if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt)) - set_display_routine (pData); /* then determine display routine */ - } -#endif - - if (pData->bRestorebkgd) /* need to restore the background ? */ - { - pData->bRestorebkgd = MNG_FALSE; - iRetcode = load_bkgdlayer (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - pData->iLayerseq++; /* and it counts as a layer then ! */ - } - - if (pData->fInitrowproc) /* need to initialize row processing? */ - { - iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData); - pData->fInitrowproc = MNG_NULL; /* only call this once !!! */ - } - - if ((!iRetcode) && (!pData->bInflating)) - /* initialize inflate */ - iRetcode = mngzlib_inflateinit (pData); - - if (!iRetcode) /* all ok? then inflate, my man */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mngzlib_inflaterows (pData, iRawlen, pRawdata); -#else - iRetcode = mngzlib_inflaterows (pData, pData->iRawlen, pData->pRawdata); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IDAT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_process_display_iend (mng_datap pData) -{ - mng_retcode iRetcode, iRetcode2; - mng_bool bDodisplay = MNG_FALSE; - mng_bool bMagnify = MNG_FALSE; - mng_bool bCleanup = (mng_bool)(pData->iBreakpoint != 0); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IEND, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_JNG /* progressive+alpha JNG can be displayed now */ - if ( (pData->bHasJHDR ) && - ( (pData->bJPEGprogressive) || (pData->bJPEGprogressive2)) && - ( (pData->eImagetype == mng_it_jng ) || - (((mng_imagep)pData->pStoreobj)->bVisible) ) && - ( (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || - (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) ) - bDodisplay = MNG_TRUE; -#endif - -#ifndef MNG_SKIPCHUNK_MAGN - if ( (pData->pStoreobj) && /* on-the-fly magnification ? */ - ( (((mng_imagep)pData->pStoreobj)->iMAGN_MethodX) || - (((mng_imagep)pData->pStoreobj)->iMAGN_MethodY) ) ) - bMagnify = MNG_TRUE; -#endif - - if ((pData->bHasBASI) || /* was it a BASI stream */ - (bDodisplay) || /* or should we display the JNG */ -#ifndef MNG_SKIPCHUNK_MAGN - (bMagnify) || /* or should we magnify it */ -#endif - /* or did we get broken here last time ? */ - ((pData->iBreakpoint) && (pData->iBreakpoint != 8))) - { - mng_imagep pImage = (mng_imagep)pData->pCurrentobj; - - if (!pImage) /* or was it object 0 ? */ - pImage = (mng_imagep)pData->pObjzero; - /* display it now then ? */ - if ((pImage->bVisible) && (pImage->bViewable)) - { /* ok, so do it */ - iRetcode = mng_display_image (pData, pImage, bDodisplay); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - if (pData->bTimerset) /* timer break ? */ - pData->iBreakpoint = 6; - } - } -#ifndef MNG_NO_DELTA_PNG - else - if ((pData->bHasDHDR) || /* was it a DHDR stream */ - (pData->iBreakpoint == 8)) /* or did we get broken here last time ? */ - { - mng_imagep pImage = (mng_imagep)pData->pDeltaImage; - - if (!pData->iBreakpoint) - { /* perform the delta operations needed */ - iRetcode = mng_execute_delta_image (pData, pImage, (mng_imagep)pData->pObjzero); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - /* display it now then ? */ - if ((pImage->bVisible) && (pImage->bViewable)) - { /* ok, so do it */ - iRetcode = mng_display_image (pData, pImage, MNG_FALSE); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - if (pData->bTimerset) /* timer break ? */ - pData->iBreakpoint = 8; - } - } -#endif - - if (!pData->bTimerset) /* can we continue ? */ - { - pData->iBreakpoint = 0; /* clear this flag now ! */ - - -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - if (pData->eImagetype == mng_it_mpng) - { - pData->pCurraniobj = pData->pFirstaniobj; - } else -#endif -#ifdef MNG_INCLUDE_ANG_PROPOSAL - if (pData->eImagetype == mng_it_ang) - { - pData->pCurraniobj = pData->pFirstaniobj; - } else -#endif - { /* cleanup object 0 */ - mng_reset_object_details (pData, (mng_imagep)pData->pObjzero, - 0, 0, 0, 0, 0, 0, 0, MNG_TRUE); - } - - if (pData->bInflating) /* if we've been inflating */ - { /* cleanup row-processing, */ - iRetcode = mng_cleanup_rowproc (pData); - /* also cleanup inflate! */ - iRetcode2 = mngzlib_inflatefree (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - if (iRetcode2) - return iRetcode2; - } - -#ifdef MNG_INCLUDE_JNG - if (pData->bJPEGdecompress) /* if we've been decompressing JDAT */ - { /* cleanup row-processing, */ - iRetcode = mng_cleanup_rowproc (pData); - /* also cleanup decompress! */ - iRetcode2 = mngjpeg_decompressfree (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - if (iRetcode2) - return iRetcode2; - } - - if (pData->bJPEGdecompress2) /* if we've been decompressing JDAA */ - { /* cleanup row-processing, */ - iRetcode = mng_cleanup_rowproc (pData); - /* also cleanup decompress! */ - iRetcode2 = mngjpeg_decompressfree2 (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - if (iRetcode2) - return iRetcode2; - } -#endif - - if (bCleanup) /* if we got broken last time we need to cleanup */ - { - pData->bHasIHDR = MNG_FALSE; /* IEND signals the end for most ... */ - pData->bHasBASI = MNG_FALSE; - pData->bHasDHDR = MNG_FALSE; -#ifdef MNG_INCLUDE_JNG - pData->bHasJHDR = MNG_FALSE; - pData->bHasJSEP = MNG_FALSE; - pData->bHasJDAA = MNG_FALSE; - pData->bHasJDAT = MNG_FALSE; -#endif - pData->bHasPLTE = MNG_FALSE; - pData->bHasTRNS = MNG_FALSE; - pData->bHasGAMA = MNG_FALSE; - pData->bHasCHRM = MNG_FALSE; - pData->bHasSRGB = MNG_FALSE; - pData->bHasICCP = MNG_FALSE; - pData->bHasBKGD = MNG_FALSE; - pData->bHasIDAT = MNG_FALSE; - } - /* if the image was displayed on the fly, */ - /* we'll have to make the app refresh */ - if ((pData->eImagetype != mng_it_mng) && (pData->fDisplayrow)) - pData->bNeedrefresh = MNG_TRUE; - - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IEND, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -/* change in the MNG spec with regards to TERM delay & interframe_delay - as proposed by Adam M. Costello (option 4) and finalized by official vote - during december 2002 / check the 'mng-list' archives for more details */ - -mng_retcode mng_process_display_mend (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_START); -#endif - -#ifdef MNG_SUPPORT_DYNAMICMNG - if (pData->bStopafterseek) /* need to stop after this ? */ - { - pData->bFreezing = MNG_TRUE; /* stop processing on this one */ - pData->bRunningevent = MNG_FALSE; - pData->bStopafterseek = MNG_FALSE; - pData->bNeedrefresh = MNG_TRUE; /* make sure the last bit is displayed ! */ - } -#endif - -#ifndef MNG_SKIPCHUNK_TERM - /* TERM processed ? */ - if ((pData->bDisplaying) && (pData->bRunning) && - (pData->bHasTERM) && (pData->pTermaniobj)) - { - mng_retcode iRetcode; - mng_ani_termp pTERM; - /* get the right animation object ! */ - pTERM = (mng_ani_termp)pData->pTermaniobj; - - pData->iIterations++; /* increase iteration count */ - - switch (pTERM->iTermaction) /* determine what to do! */ - { - case 0 : { /* show last frame indefinitly */ - break; /* piece of cake, that is... */ - } - - case 1 : { /* cease displaying anything */ - /* max(1, TERM delay, interframe_delay) */ -#ifndef MNG_SKIPCHUNK_FRAM - if (pTERM->iDelay > pData->iFramedelay) - pData->iFramedelay = pTERM->iDelay; - if (!pData->iFramedelay) - pData->iFramedelay = 1; -#endif - - iRetcode = interframe_delay (pData); - /* no interframe_delay? then fake it */ - if ((!iRetcode) && (!pData->bTimerset)) - iRetcode = set_delay (pData, 1); - - if (iRetcode) - return iRetcode; - - pData->iBreakpoint = 10; - break; - } - - case 2 : { /* show first image after TERM */ - iRetcode = restore_state (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* notify the app ? */ - if (pData->fProcessmend) - if (!pData->fProcessmend ((mng_handle)pData, pData->iIterations, 0)) - MNG_ERROR (pData, MNG_APPMISCERROR); - - /* show first frame after TERM chunk */ - pData->pCurraniobj = pTERM; - pData->bOnlyfirstframe = MNG_TRUE; - pData->iFramesafterTERM = 0; - - /* max(1, TERM delay, interframe_delay) */ -#ifndef MNG_SKIPCHUNK_FRAM - if (pTERM->iDelay > pData->iFramedelay) - pData->iFramedelay = pTERM->iDelay; - if (!pData->iFramedelay) - pData->iFramedelay = 1; -#endif - - break; - } - - case 3 : { /* repeat */ - if ((pTERM->iItermax) && (pTERM->iItermax < 0x7FFFFFFF)) - pTERM->iItermax--; - - if (pTERM->iItermax) /* go back to TERM ? */ - { /* restore to initial or SAVE state */ - iRetcode = restore_state (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* notify the app ? */ - if (pData->fProcessmend) - if (!pData->fProcessmend ((mng_handle)pData, - pData->iIterations, pTERM->iItermax)) - MNG_ERROR (pData, MNG_APPMISCERROR); - - /* restart from TERM chunk */ - pData->pCurraniobj = pTERM; - - if (pTERM->iDelay) /* set the delay (?) */ - { - /* max(1, TERM delay, interframe_delay) */ -#ifndef MNG_SKIPCHUNK_FRAM - if (pTERM->iDelay > pData->iFramedelay) - pData->iFramedelay = pTERM->iDelay; - if (!pData->iFramedelay) - pData->iFramedelay = 1; -#endif - - pData->bNeedrefresh = MNG_TRUE; - } - } - else - { - switch (pTERM->iIteraction) - { - case 0 : { /* show last frame indefinitly */ - break; /* piece of cake, that is... */ - } - - case 1 : { /* cease displaying anything */ - /* max(1, TERM delay, interframe_delay) */ -#ifndef MNG_SKIPCHUNK_FRAM - if (pTERM->iDelay > pData->iFramedelay) - pData->iFramedelay = pTERM->iDelay; - if (!pData->iFramedelay) - pData->iFramedelay = 1; -#endif - - iRetcode = interframe_delay (pData); - /* no interframe_delay? then fake it */ - if ((!iRetcode) && (!pData->bTimerset)) - iRetcode = set_delay (pData, 1); - - if (iRetcode) - return iRetcode; - - pData->iBreakpoint = 10; - break; - } - - case 2 : { /* show first image after TERM */ - iRetcode = restore_state (pData); - /* on error bail out */ - if (iRetcode) - return iRetcode; - /* notify the app ? */ - if (pData->fProcessmend) - if (!pData->fProcessmend ((mng_handle)pData, - pData->iIterations, 0)) - MNG_ERROR (pData, MNG_APPMISCERROR); - - /* show first frame after TERM chunk */ - pData->pCurraniobj = pTERM; - pData->bOnlyfirstframe = MNG_TRUE; - pData->iFramesafterTERM = 0; - /* max(1, TERM delay, interframe_delay) */ -#ifndef MNG_SKIPCHUNK_FRAM - if (pTERM->iDelay > pData->iFramedelay) - pData->iFramedelay = pTERM->iDelay; - if (!pData->iFramedelay) - pData->iFramedelay = 1; -#endif - - break; - } - } - } - - break; - } - } - } -#endif /* MNG_SKIPCHUNK_TERM */ - /* just reading ? */ - if ((!pData->bDisplaying) && (pData->bReading)) - if (pData->fProcessmend) /* inform the app ? */ - if (!pData->fProcessmend ((mng_handle)pData, 0, 0)) - MNG_ERROR (pData, MNG_APPMISCERROR); - - if (!pData->pCurraniobj) /* always let the app refresh at the end ! */ - pData->bNeedrefresh = MNG_TRUE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_process_display_mend2 (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_START); -#endif - -#ifndef MNG_SKIPCHUNK_FRAM - pData->bFrameclipping = MNG_FALSE; /* nothing to do but restore the app background */ -#endif - load_bkgdlayer (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DEFI -mng_retcode mng_process_display_defi (mng_datap pData) -{ - mng_imagep pImage; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DEFI, MNG_LC_START); -#endif - - if (!pData->iDEFIobjectid) /* object id=0 ? */ - { - pImage = (mng_imagep)pData->pObjzero; - - if (pData->bDEFIhasdonotshow) - pImage->bVisible = (mng_bool)(pData->iDEFIdonotshow == 0); - - if (pData->bDEFIhasloca) - { - pImage->iPosx = pData->iDEFIlocax; - pImage->iPosy = pData->iDEFIlocay; - } - - if (pData->bDEFIhasclip) - { - pImage->bClipped = pData->bDEFIhasclip; - pImage->iClipl = pData->iDEFIclipl; - pImage->iClipr = pData->iDEFIclipr; - pImage->iClipt = pData->iDEFIclipt; - pImage->iClipb = pData->iDEFIclipb; - } - - pData->pCurrentobj = 0; /* not a real object ! */ - } - else - { /* already exists ? */ - pImage = (mng_imagep)mng_find_imageobject (pData, pData->iDEFIobjectid); - - if (!pImage) /* if not; create new */ - { - mng_retcode iRetcode = mng_create_imageobject (pData, pData->iDEFIobjectid, - (mng_bool)(pData->iDEFIconcrete == 1), - (mng_bool)(pData->iDEFIdonotshow == 0), - MNG_FALSE, 0, 0, 0, 0, 0, 0, 0, - pData->iDEFIlocax, pData->iDEFIlocay, - pData->bDEFIhasclip, - pData->iDEFIclipl, pData->iDEFIclipr, - pData->iDEFIclipt, pData->iDEFIclipb, - &pImage); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - else - { /* exists; then set new info */ - if (pData->bDEFIhasdonotshow) - pImage->bVisible = (mng_bool)(pData->iDEFIdonotshow == 0); - - pImage->bViewable = MNG_FALSE; - - if (pData->bDEFIhasloca) - { - pImage->iPosx = pData->iDEFIlocax; - pImage->iPosy = pData->iDEFIlocay; - } - - if (pData->bDEFIhasclip) - { - pImage->bClipped = pData->bDEFIhasclip; - pImage->iClipl = pData->iDEFIclipl; - pImage->iClipr = pData->iDEFIclipr; - pImage->iClipt = pData->iDEFIclipt; - pImage->iClipb = pData->iDEFIclipb; - } - - if (pData->bDEFIhasconcrete) - pImage->pImgbuf->bConcrete = (mng_bool)(pData->iDEFIconcrete == 1); - } - - pData->pCurrentobj = pImage; /* others may want to know this */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DEFI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_BASI -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -mng_retcode mng_process_display_basi (mng_datap pData, - mng_uint16 iRed, - mng_uint16 iGreen, - mng_uint16 iBlue, - mng_bool bHasalpha, - mng_uint16 iAlpha, - mng_uint8 iViewable) -#else -mng_retcode mng_process_display_basi (mng_datap pData) -#endif -{ /* address the current "object" if any */ - mng_imagep pImage = (mng_imagep)pData->pCurrentobj; - mng_uint8p pWork; - mng_uint32 iX; - mng_imagedatap pBuf; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_BASI, MNG_LC_START); -#endif - - if (!pImage) /* or is it an "on-the-fly" image ? */ - pImage = (mng_imagep)pData->pObjzero; - /* address the object-buffer */ - pBuf = pImage->pImgbuf; - - pData->fDisplayrow = MNG_NULL; /* do nothing by default */ - pData->fCorrectrow = MNG_NULL; - pData->fStorerow = MNG_NULL; - pData->fProcessrow = MNG_NULL; - /* set parms now that they're known */ - iRetcode = mng_reset_object_details (pData, pImage, pData->iDatawidth, - pData->iDataheight, pData->iBitdepth, - pData->iColortype, pData->iCompression, - pData->iFilter, pData->iInterlace, MNG_FALSE); - if (iRetcode) /* on error bail out */ - return iRetcode; - /* save the viewable flag */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pImage->bViewable = (mng_bool)(iViewable == 1); -#else - pImage->bViewable = (mng_bool)(pData->iBASIviewable == 1); -#endif - pBuf->bViewable = pImage->bViewable; - pData->pStoreobj = pImage; /* let row-routines know which object */ - - pWork = pBuf->pImgdata; /* fill the object-buffer with the specified - "color" sample */ - switch (pData->iColortype) /* depending on color_type & bit_depth */ - { - case 0 : { /* gray */ -#ifndef MNG_NO_16BIT_SUPPORT - if (pData->iBitdepth == 16) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iDatawidth * pData->iDataheight; - iX > 0;iX--) -#else - for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - mng_put_uint16 (pWork, iRed); -#else - mng_put_uint16 (pWork, pData->iBASIred); -#endif - pWork += 2; - } - } - else -#endif - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iDatawidth * pData->iDataheight; - iX > 0;iX--) -#else - for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - *pWork = (mng_uint8)iRed; -#else - *pWork = (mng_uint8)pData->iBASIred; -#endif - pWork++; - } - } - /* force tRNS ? */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if ((bHasalpha) && (!iAlpha)) -#else - if ((pData->bBASIhasalpha) && (!pData->iBASIalpha)) -#endif - { - pBuf->bHasTRNS = MNG_TRUE; -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pBuf->iTRNSgray = iRed; -#else - pBuf->iTRNSgray = pData->iBASIred; -#endif - } - - break; - } - - case 2 : { /* rgb */ -#ifndef MNG_NO_16BIT_SUPPORT - if (pData->iBitdepth == 16) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iDatawidth * pData->iDataheight; - iX > 0;iX--) -#else - for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - mng_put_uint16 (pWork, iRed ); - mng_put_uint16 (pWork+2, iGreen); - mng_put_uint16 (pWork+4, iBlue ); -#else - mng_put_uint16 (pWork, pData->iBASIred ); - mng_put_uint16 (pWork+2, pData->iBASIgreen); - mng_put_uint16 (pWork+4, pData->iBASIblue ); -#endif - pWork += 6; - } - } - else -#endif - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iDatawidth * pData->iDataheight; - iX > 0;iX--) -#else - for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - *pWork = (mng_uint8)iRed; - *(pWork+1) = (mng_uint8)iGreen; - *(pWork+2) = (mng_uint8)iBlue; -#else - *pWork = (mng_uint8)pData->iBASIred; - *(pWork+1) = (mng_uint8)pData->iBASIgreen; - *(pWork+2) = (mng_uint8)pData->iBASIblue; -#endif - pWork += 3; - } - } - /* force tRNS ? */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if ((bHasalpha) && (!iAlpha)) -#else - if ((pData->bBASIhasalpha) && (!pData->iBASIalpha)) -#endif - { - pBuf->bHasTRNS = MNG_TRUE; -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pBuf->iTRNSred = iRed; - pBuf->iTRNSgreen = iGreen; - pBuf->iTRNSblue = iBlue; -#else - pBuf->iTRNSred = pData->iBASIred; - pBuf->iTRNSgreen = pData->iBASIgreen; - pBuf->iTRNSblue = pData->iBASIblue; -#endif - } - - break; - } - - case 3 : { /* indexed */ - pBuf->bHasPLTE = MNG_TRUE; - - switch (pData->iBitdepth) - { - case 1 : { pBuf->iPLTEcount = 2; break; } - case 2 : { pBuf->iPLTEcount = 4; break; } - case 4 : { pBuf->iPLTEcount = 16; break; } - case 8 : { pBuf->iPLTEcount = 256; break; } - default : { pBuf->iPLTEcount = 1; break; } - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pBuf->aPLTEentries [0].iRed = (mng_uint8)iRed; - pBuf->aPLTEentries [0].iGreen = (mng_uint8)iGreen; - pBuf->aPLTEentries [0].iBlue = (mng_uint8)iBlue; -#else - pBuf->aPLTEentries [0].iRed = (mng_uint8)pData->iBASIred; - pBuf->aPLTEentries [0].iGreen = (mng_uint8)pData->iBASIgreen; - pBuf->aPLTEentries [0].iBlue = (mng_uint8)pData->iBASIblue; -#endif - - for (iX = 1; iX < pBuf->iPLTEcount; iX++) - { - pBuf->aPLTEentries [iX].iRed = 0; - pBuf->aPLTEentries [iX].iGreen = 0; - pBuf->aPLTEentries [iX].iBlue = 0; - } - /* force tRNS ? */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if ((bHasalpha) && (iAlpha < 255)) -#else - if ((pData->bBASIhasalpha) && (pData->iBASIalpha < 255)) -#endif - { - pBuf->bHasTRNS = MNG_TRUE; - pBuf->iTRNScount = 1; -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pBuf->aTRNSentries [0] = (mng_uint8)iAlpha; -#else - pBuf->aTRNSentries [0] = (mng_uint8)pData->iBASIalpha; -#endif - } - - break; - } - - case 4 : { /* gray+alpha */ -#ifndef MNG_NO_16BIT_SUPPORT - if (pData->iBitdepth == 16) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iDatawidth * pData->iDataheight; - iX > 0;iX--) -#else - for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - mng_put_uint16 (pWork, iRed); - mng_put_uint16 (pWork+2, iAlpha); -#else - mng_put_uint16 (pWork, pData->iBASIred); - mng_put_uint16 (pWork+2, pData->iBASIalpha); -#endif - pWork += 4; - } - } - else -#endif - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iDatawidth * pData->iDataheight; - iX > 0;iX--) -#else - for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - *pWork = (mng_uint8)iRed; - *(pWork+1) = (mng_uint8)iAlpha; -#else - *pWork = (mng_uint8)pData->iBASIred; - *(pWork+1) = (mng_uint8)pData->iBASIalpha; -#endif - pWork += 2; - } - } - - break; - } - - case 6 : { /* rgb+alpha */ -#ifndef MNG_NO_16BIT_SUPPORT - if (pData->iBitdepth == 16) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iDatawidth * pData->iDataheight; - iX > 0;iX--) -#else - for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - mng_put_uint16 (pWork, iRed); - mng_put_uint16 (pWork+2, iGreen); - mng_put_uint16 (pWork+4, iBlue); - mng_put_uint16 (pWork+6, iAlpha); -#else - mng_put_uint16 (pWork, pData->iBASIred); - mng_put_uint16 (pWork+2, pData->iBASIgreen); - mng_put_uint16 (pWork+4, pData->iBASIblue); - mng_put_uint16 (pWork+6, pData->iBASIalpha); -#endif - pWork += 8; - } - } - else -#endif - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iDatawidth * pData->iDataheight; - iX > 0;iX--) -#else - for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - *pWork = (mng_uint8)iRed; - *(pWork+1) = (mng_uint8)iGreen; - *(pWork+2) = (mng_uint8)iBlue; - *(pWork+3) = (mng_uint8)iAlpha; -#else - *pWork = (mng_uint8)pData->iBASIred; - *(pWork+1) = (mng_uint8)pData->iBASIgreen; - *(pWork+2) = (mng_uint8)pData->iBASIblue; - *(pWork+3) = (mng_uint8)pData->iBASIalpha; -#endif - pWork += 4; - } - } - - break; - } - - } - -#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT - pData->fInitrowproc = (mng_fptr)mng_init_rowproc; - pData->ePng_imgtype=mng_png_imgtype(pData->iColortype,pData->iBitdepth); -#else - switch (pData->iColortype) /* determine row initialization routine */ - { /* just to accomodate IDAT if it arrives */ - case 0 : { /* gray */ - switch (pData->iBitdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g1_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g1_i; - - break; - } - case 2 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g2_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g2_i; - - break; - } - case 4 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g4_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g4_i; - - break; - } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g8_i; - - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g16_i; - - break; - } -#endif - } - - break; - } - case 2 : { /* rgb */ - switch (pData->iBitdepth) - { - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i; - - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i; - - break; - } -#endif - } - - break; - } - case 3 : { /* indexed */ - switch (pData->iBitdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx1_i; - - break; - } - case 2 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx2_i; - - break; - } - case 4 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx4_i; - - break; - } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx8_i; - - break; - } - } - - break; - } - case 4 : { /* gray+alpha */ - switch (pData->iBitdepth) - { - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_ga8_i; - - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_ga16_i; - - break; - } -#endif - } - - break; - } - case 6 : { /* rgb+alpha */ - switch (pData->iBitdepth) - { - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i; - - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i; - - break; - } -#endif - } - - break; - } - } -#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ - - pData->iFilterofs = 0; /* determine filter characteristics */ - pData->iLevel0 = 0; /* default levels */ - pData->iLevel1 = 0; - pData->iLevel2 = 0; - pData->iLevel3 = 0; - -#ifdef FILTER192 - if (pData->iFilter == 0xC0) /* leveling & differing ? */ - { - switch (pData->iColortype) - { - case 0 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pData->iBitdepth <= 8) -#endif - pData->iFilterofs = 1; -#ifndef MNG_NO_16BIT_SUPPORT - else - pData->iFilterofs = 2; -#endif - - break; - } - case 2 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pData->iBitdepth <= 8) -#endif - pData->iFilterofs = 3; -#ifndef MNG_NO_16BIT_SUPPORT - else - pData->iFilterofs = 6; -#endif - - break; - } - case 3 : { - pData->iFilterofs = 1; - break; - } - case 4 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pData->iBitdepth <= 8) -#endif - pData->iFilterofs = 2; -#ifndef MNG_NO_16BIT_SUPPORT - else - pData->iFilterofs = 4; -#endif - - break; - } - case 6 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pData->iBitdepth <= 8) -#endif - pData->iFilterofs = 4; -#ifndef MNG_NO_16BIT_SUPPORT - else - pData->iFilterofs = 8; -#endif - - break; - } - } - } -#endif - -#ifdef FILTER193 - if (pData->iFilter == 0xC1) /* no adaptive filtering ? */ - pData->iPixelofs = pData->iFilterofs; - else -#endif - pData->iPixelofs = pData->iFilterofs + 1; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_BASI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_CLON -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -mng_retcode mng_process_display_clon (mng_datap pData, - mng_uint16 iSourceid, - mng_uint16 iCloneid, - mng_uint8 iClonetype, - mng_bool bHasdonotshow, - mng_uint8 iDonotshow, - mng_uint8 iConcrete, - mng_bool bHasloca, - mng_uint8 iLocationtype, - mng_int32 iLocationx, - mng_int32 iLocationy) -#else -mng_retcode mng_process_display_clon (mng_datap pData) -#endif -{ - mng_imagep pSource, pClone; - mng_bool bVisible, bAbstract; - mng_retcode iRetcode = MNG_NOERROR; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_START); -#endif -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - /* locate the source object first */ - pSource = mng_find_imageobject (pData, iSourceid); - /* check if the clone exists */ - pClone = mng_find_imageobject (pData, iCloneid); -#else - /* locate the source object first */ - pSource = mng_find_imageobject (pData, pData->iCLONsourceid); - /* check if the clone exists */ - pClone = mng_find_imageobject (pData, pData->iCLONcloneid); -#endif - - if (!pSource) /* source must exist ! */ - MNG_ERROR (pData, MNG_OBJECTUNKNOWN); - - if (pClone) /* clone must not exist ! */ - MNG_ERROR (pData, MNG_OBJECTEXISTS); - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (bHasdonotshow) /* DoNotShow flag filled ? */ - bVisible = (mng_bool)(iDonotshow == 0); - else - bVisible = pSource->bVisible; -#else - if (pData->bCLONhasdonotshow) /* DoNotShow flag filled ? */ - bVisible = (mng_bool)(pData->iCLONdonotshow == 0); - else - bVisible = pSource->bVisible; -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - bAbstract = (mng_bool)(iConcrete == 1); -#else - bAbstract = (mng_bool)(pData->iCLONconcrete == 1); -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - switch (iClonetype) /* determine action to take */ - { - case 0 : { /* full clone */ - iRetcode = mng_clone_imageobject (pData, iCloneid, MNG_FALSE, - bVisible, bAbstract, bHasloca, - iLocationtype, iLocationx, iLocationy, - pSource, &pClone); - break; - } - - case 1 : { /* partial clone */ - iRetcode = mng_clone_imageobject (pData, iCloneid, MNG_TRUE, - bVisible, bAbstract, bHasloca, - iLocationtype, iLocationx, iLocationy, - pSource, &pClone); - break; - } - - case 2 : { /* renumber object */ - iRetcode = mng_renum_imageobject (pData, pSource, iCloneid, - bVisible, bAbstract, bHasloca, - iLocationtype, iLocationx, iLocationy); - pClone = pSource; - break; - } - - } -#else - switch (pData->iCLONclonetype) /* determine action to take */ - { - case 0 : { /* full clone */ - iRetcode = mng_clone_imageobject (pData, pData->iCLONcloneid, MNG_FALSE, - bVisible, bAbstract, - pData->bCLONhasloca, pData->iCLONlocationtype, - pData->iCLONlocationx, pData->iCLONlocationy, - pSource, &pClone); - break; - } - - case 1 : { /* partial clone */ - iRetcode = mng_clone_imageobject (pData, pData->iCLONcloneid, MNG_TRUE, - bVisible, bAbstract, - pData->bCLONhasloca, pData->iCLONlocationtype, - pData->iCLONlocationx, pData->iCLONlocationy, - pSource, &pClone); - break; - } - - case 2 : { /* renumber object */ - iRetcode = mng_renum_imageobject (pData, pSource, pData->iCLONcloneid, - bVisible, bAbstract, - pData->bCLONhasloca, pData->iCLONlocationtype, - pData->iCLONlocationx, pData->iCLONlocationy); - pClone = pSource; - break; - } - - } -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - - /* display on the fly ? */ - if ((pClone->bViewable) && (pClone->bVisible)) - { - pData->pLastclone = pClone; /* remember in case of timer break ! */ - /* display it */ - mng_display_image (pData, pClone, MNG_FALSE); - - if (pData->bTimerset) /* timer break ? */ - pData->iBreakpoint = 5; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_process_display_clon2 (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_START); -#endif - /* only called after timer break ! */ - mng_display_image (pData, (mng_imagep)pData->pLastclone, MNG_FALSE); - pData->iBreakpoint = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DISC -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -mng_retcode mng_process_display_disc (mng_datap pData, - mng_uint32 iCount, - mng_uint16p pIds) -#else -mng_retcode mng_process_display_disc (mng_datap pData) -#endif -{ - mng_uint32 iX; - mng_imagep pImage; - mng_uint32 iRetcode; -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DISC, MNG_LC_START); -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (iCount) /* specific list ? */ -#else - if (pData->iDISCcount) /* specific list ? */ -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - mng_uint16p pWork = pIds; -#else - mng_uint16p pWork = pData->pDISCids; -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -#ifdef MNG_DECREMENT_LOOPS /* iterate the list */ - for (iX = iCount; iX > 0; iX--) -#else - for (iX = 0; iX < iCount; iX++) -#endif -#else -#ifdef MNG_DECREMENT_LOOPS /* iterate the list */ - for (iX = pData->iDISCcount; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iDISCcount; iX++) -#endif -#endif - { - pImage = mng_find_imageobject (pData, *pWork++); - - if (pImage) /* found the object ? */ - { /* then drop it */ - iRetcode = mng_free_imageobject (pData, pImage); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } - } - else /* empty: drop all un-frozen objects */ - { - mng_imagep pNext = (mng_imagep)pData->pFirstimgobj; - - while (pNext) /* any left ? */ - { - pImage = pNext; - pNext = pImage->sHeader.pNext; - - if (!pImage->bFrozen) /* not frozen ? */ - { /* then drop it */ - iRetcode = mng_free_imageobject (pData, pImage); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DISC, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_FRAM -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -mng_retcode mng_process_display_fram (mng_datap pData, - mng_uint8 iFramemode, - mng_uint8 iChangedelay, - mng_uint32 iDelay, - mng_uint8 iChangetimeout, - mng_uint32 iTimeout, - mng_uint8 iChangeclipping, - mng_uint8 iCliptype, - mng_int32 iClipl, - mng_int32 iClipr, - mng_int32 iClipt, - mng_int32 iClipb) -#else -mng_retcode mng_process_display_fram (mng_datap pData) -#endif -{ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_START); -#endif - /* advance a frame then */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = next_frame (pData, iFramemode, iChangedelay, iDelay, - iChangetimeout, iTimeout, iChangeclipping, - iCliptype, iClipl, iClipr, iClipt, iClipb); -#else - iRetcode = next_frame (pData, pData->iTempFramemode, pData->iTempChangedelay, - pData->iTempDelay, pData->iTempChangetimeout, - pData->iTempTimeout, pData->iTempChangeclipping, - pData->iTempCliptype, pData->iTempClipl, pData->iTempClipr, - pData->iTempClipt, pData->iTempClipb); -#endif - - if (pData->bTimerset) /* timer break ? */ - pData->iBreakpoint = 1; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -mng_retcode mng_process_display_fram2 (mng_datap pData) -{ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_START); -#endif - /* again; after the break */ - iRetcode = next_frame (pData, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - pData->iBreakpoint = 0; /* not again! */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MOVE -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -mng_retcode mng_process_display_move (mng_datap pData, - mng_uint16 iFromid, - mng_uint16 iToid, - mng_uint8 iMovetype, - mng_int32 iMovex, - mng_int32 iMovey) -#else -mng_retcode mng_process_display_move (mng_datap pData) -#endif -{ - mng_uint16 iX; - mng_imagep pImage; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MOVE, MNG_LC_START); -#endif - /* iterate the list */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - for (iX = iFromid; iX <= iToid; iX++) -#else - for (iX = pData->iMOVEfromid; iX <= pData->iMOVEtoid; iX++) -#endif - { - if (!iX) /* object id=0 ? */ - pImage = (mng_imagep)pData->pObjzero; - else - pImage = mng_find_imageobject (pData, iX); - - if (pImage) /* object exists ? */ - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - switch (iMovetype) -#else - switch (pData->iMOVEmovetype) -#endif - { - case 0 : { /* absolute */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pImage->iPosx = iMovex; - pImage->iPosy = iMovey; -#else - pImage->iPosx = pData->iMOVEmovex; - pImage->iPosy = pData->iMOVEmovey; -#endif - break; - } - case 1 : { /* relative */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pImage->iPosx = pImage->iPosx + iMovex; - pImage->iPosy = pImage->iPosy + iMovey; -#else - pImage->iPosx = pImage->iPosx + pData->iMOVEmovex; - pImage->iPosy = pImage->iPosy + pData->iMOVEmovey; -#endif - break; - } - } - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MOVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_CLIP -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -mng_retcode mng_process_display_clip (mng_datap pData, - mng_uint16 iFromid, - mng_uint16 iToid, - mng_uint8 iCliptype, - mng_int32 iClipl, - mng_int32 iClipr, - mng_int32 iClipt, - mng_int32 iClipb) -#else -mng_retcode mng_process_display_clip (mng_datap pData) -#endif -{ - mng_uint16 iX; - mng_imagep pImage; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLIP, MNG_LC_START); -#endif - /* iterate the list */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - for (iX = iFromid; iX <= iToid; iX++) -#else - for (iX = pData->iCLIPfromid; iX <= pData->iCLIPtoid; iX++) -#endif - { - if (!iX) /* object id=0 ? */ - pImage = (mng_imagep)pData->pObjzero; - else - pImage = mng_find_imageobject (pData, iX); - - if (pImage) /* object exists ? */ - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - switch (iCliptype) -#else - switch (pData->iCLIPcliptype) -#endif - { - case 0 : { /* absolute */ - pImage->bClipped = MNG_TRUE; -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pImage->iClipl = iClipl; - pImage->iClipr = iClipr; - pImage->iClipt = iClipt; - pImage->iClipb = iClipb; -#else - pImage->iClipl = pData->iCLIPclipl; - pImage->iClipr = pData->iCLIPclipr; - pImage->iClipt = pData->iCLIPclipt; - pImage->iClipb = pData->iCLIPclipb; -#endif - break; - } - case 1 : { /* relative */ - pImage->bClipped = MNG_TRUE; -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pImage->iClipl = pImage->iClipl + iClipl; - pImage->iClipr = pImage->iClipr + iClipr; - pImage->iClipt = pImage->iClipt + iClipt; - pImage->iClipb = pImage->iClipb + iClipb; -#else - pImage->iClipl = pImage->iClipl + pData->iCLIPclipl; - pImage->iClipr = pImage->iClipr + pData->iCLIPclipr; - pImage->iClipt = pImage->iClipt + pData->iCLIPclipt; - pImage->iClipb = pImage->iClipb + pData->iCLIPclipb; -#endif - break; - } - } - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLIP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SHOW -mng_retcode mng_process_display_show (mng_datap pData) -{ - mng_int16 iX, iS, iFrom, iTo; - mng_imagep pImage; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SHOW, MNG_LC_START); -#endif - - /* TODO: optimization for the cases where "abs (iTo - iFrom)" is rather high; - especially where ((iFrom==1) && (iTo==65535)); eg. an empty SHOW !!! */ - - if (pData->iBreakpoint == 3) /* previously broken during cycle-mode ? */ - { - pImage = mng_find_imageobject (pData, pData->iSHOWnextid); - - if (pImage) /* still there ? */ - mng_display_image (pData, pImage, MNG_FALSE); - - pData->iBreakpoint = 0; /* let's not go through this again! */ - } - else - { - if (pData->iBreakpoint) /* previously broken at other point ? */ - { /* restore last parms */ - iFrom = (mng_int16)pData->iSHOWfromid; - iTo = (mng_int16)pData->iSHOWtoid; - iX = (mng_int16)pData->iSHOWnextid; - iS = (mng_int16)pData->iSHOWskip; - } - else - { /* regular sequence ? */ - if (pData->iSHOWtoid >= pData->iSHOWfromid) - iS = 1; - else /* reverse sequence ! */ - iS = -1; - - iFrom = (mng_int16)pData->iSHOWfromid; - iTo = (mng_int16)pData->iSHOWtoid; - iX = iFrom; - - pData->iSHOWfromid = (mng_uint16)iFrom; - pData->iSHOWtoid = (mng_uint16)iTo; - pData->iSHOWskip = iS; - } - /* cycle mode ? */ - if ((pData->iSHOWmode == 6) || (pData->iSHOWmode == 7)) - { - mng_uint16 iTrigger = 0; - mng_uint16 iFound = 0; - mng_uint16 iPass = 0; - mng_imagep pFound = 0; - - do - { - iPass++; /* lets prevent endless loops when there - are no potential candidates in the list! */ - - if (iS > 0) /* forward ? */ - { - for (iX = iFrom; iX <= iTo; iX += iS) - { - pImage = mng_find_imageobject (pData, (mng_uint16)iX); - - if (pImage) /* object exists ? */ - { - if (iFound) /* already found a candidate ? */ - pImage->bVisible = MNG_FALSE; - else - if (iTrigger) /* found the trigger ? */ - { - pImage->bVisible = MNG_TRUE; - iFound = iX; - pFound = pImage; - } - else - if (pImage->bVisible) /* ok, this is the trigger */ - { - pImage->bVisible = MNG_FALSE; - iTrigger = iX; - } - } - } - } - else - { - for (iX = iFrom; iX >= iTo; iX += iS) - { - pImage = mng_find_imageobject (pData, (mng_uint16)iX); - - if (pImage) /* object exists ? */ - { - if (iFound) /* already found a candidate ? */ - pImage->bVisible = MNG_FALSE; - else - if (iTrigger) /* found the trigger ? */ - { - pImage->bVisible = MNG_TRUE; - iFound = iX; - pFound = pImage; - } - else - if (pImage->bVisible) /* ok, this is the trigger */ - { - pImage->bVisible = MNG_FALSE; - iTrigger = iX; - } - } - } - } - - if (!iTrigger) /* did not find a trigger ? */ - iTrigger = 1; /* then fake it so the first image - gets nominated */ - } /* cycle back to beginning ? */ - while ((iPass < 2) && (iTrigger) && (!iFound)); - - pData->iBreakpoint = 0; /* just a sanity precaution */ - /* display it ? */ - if ((pData->iSHOWmode == 6) && (pFound)) - { - mng_display_image (pData, pFound, MNG_FALSE); - - if (pData->bTimerset) /* timer set ? */ - { - pData->iBreakpoint = 3; - pData->iSHOWnextid = iFound; /* save it for after the break */ - } - } - } - else - { - do - { - pImage = mng_find_imageobject (pData, iX); - - if (pImage) /* object exists ? */ - { - if (pData->iBreakpoint) /* did we get broken last time ? */ - { /* could only happen in the display routine */ - mng_display_image (pData, pImage, MNG_FALSE); - pData->iBreakpoint = 0; /* only once inside this loop please ! */ - } - else - { - switch (pData->iSHOWmode) /* do what ? */ - { - case 0 : { - pImage->bVisible = MNG_TRUE; - mng_display_image (pData, pImage, MNG_FALSE); - break; - } - case 1 : { - pImage->bVisible = MNG_FALSE; - break; - } - case 2 : { - if (pImage->bVisible) - mng_display_image (pData, pImage, MNG_FALSE); - break; - } - case 3 : { - pImage->bVisible = MNG_TRUE; - break; - } - case 4 : { - pImage->bVisible = (mng_bool)(!pImage->bVisible); - if (pImage->bVisible) - mng_display_image (pData, pImage, MNG_FALSE); - break; - } - case 5 : { - pImage->bVisible = (mng_bool)(!pImage->bVisible); - } - } - } - } - - if (!pData->bTimerset) /* next ? */ - iX += iS; - - } /* continue ? */ - while ((!pData->bTimerset) && (((iS > 0) && (iX <= iTo)) || - ((iS < 0) && (iX >= iTo)) )); - - if (pData->bTimerset) /* timer set ? */ - { - pData->iBreakpoint = 4; - pData->iSHOWnextid = iX; /* save for next time */ - } - else - pData->iBreakpoint = 0; - - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SHOW, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SAVE -mng_retcode mng_process_display_save (mng_datap pData) -{ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SAVE, MNG_LC_START); -#endif - - iRetcode = save_state (pData); /* save the current state */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SAVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SEEK -mng_retcode mng_process_display_seek (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SEEK, MNG_LC_START); -#endif - -#ifdef MNG_SUPPORT_DYNAMICMNG - if (pData->bStopafterseek) /* need to stop after this SEEK ? */ - { - pData->bFreezing = MNG_TRUE; /* stop processing on this one */ - pData->bRunningevent = MNG_FALSE; - pData->bStopafterseek = MNG_FALSE; - pData->bNeedrefresh = MNG_TRUE; /* make sure the last bit is displayed ! */ - } - else -#endif - { /* restore the initial or SAVE state */ - mng_retcode iRetcode = restore_state (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifdef MNG_SUPPORT_DYNAMICMNG - /* stop after next SEEK ? */ - if ((pData->bDynamic) || (pData->bRunningevent)) - pData->bStopafterseek = MNG_TRUE; -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SEEK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -mng_retcode mng_process_display_jhdr (mng_datap pData) -{ /* address the current "object" if any */ - mng_imagep pImage = (mng_imagep)pData->pCurrentobj; - mng_retcode iRetcode = MNG_NOERROR; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JHDR, MNG_LC_START); -#endif - - if (!pData->bHasDHDR) - { - pData->fInitrowproc = MNG_NULL; /* do nothing by default */ - pData->fDisplayrow = MNG_NULL; - pData->fCorrectrow = MNG_NULL; - pData->fStorerow = MNG_NULL; - pData->fProcessrow = MNG_NULL; - pData->fDifferrow = MNG_NULL; - pData->fStorerow2 = MNG_NULL; - pData->fStorerow3 = MNG_NULL; - - pData->pStoreobj = MNG_NULL; /* initialize important work-parms */ - - pData->iJPEGrow = 0; - pData->iJPEGalpharow = 0; - pData->iJPEGrgbrow = 0; - pData->iRowmax = 0; /* so init_rowproc does the right thing ! */ - } - - if (!pData->iBreakpoint) /* not previously broken ? */ - { -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* delta-image ? */ - { - if (pData->iDeltatype == MNG_DELTATYPE_REPLACE) - { - iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pDeltaImage, - pData->iDatawidth, pData->iDataheight, - pData->iJHDRimgbitdepth, pData->iJHDRcolortype, - pData->iJHDRalphacompression, pData->iJHDRalphafilter, - pData->iJHDRalphainterlace, MNG_TRUE); - - ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphabitdepth = pData->iJHDRalphabitdepth; - ((mng_imagep)pData->pDeltaImage)->pImgbuf->iJHDRcompression = pData->iJHDRimgcompression; - ((mng_imagep)pData->pDeltaImage)->pImgbuf->iJHDRinterlace = pData->iJHDRimginterlace; - ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth; - } - else - if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - ((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iJHDRimgbitdepth; - ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth; - } - else - if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) ) - ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth; - else - if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) ) - ((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iJHDRimgbitdepth; - - } - else -#endif /* MNG_NO_DELTA_PNG */ - { - if (pImage) /* update object buffer ? */ - { - iRetcode = mng_reset_object_details (pData, pImage, - pData->iDatawidth, pData->iDataheight, - pData->iJHDRimgbitdepth, pData->iJHDRcolortype, - pData->iJHDRalphacompression, pData->iJHDRalphafilter, - pData->iJHDRalphainterlace, MNG_TRUE); - - pImage->pImgbuf->iAlphabitdepth = pData->iJHDRalphabitdepth; - pImage->pImgbuf->iJHDRcompression = pData->iJHDRimgcompression; - pImage->pImgbuf->iJHDRinterlace = pData->iJHDRimginterlace; - pImage->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth; - } - else /* update object 0 */ - { - iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pObjzero, - pData->iDatawidth, pData->iDataheight, - pData->iJHDRimgbitdepth, pData->iJHDRcolortype, - pData->iJHDRalphacompression, pData->iJHDRalphafilter, - pData->iJHDRalphainterlace, MNG_TRUE); - - ((mng_imagep)pData->pObjzero)->pImgbuf->iAlphabitdepth = pData->iJHDRalphabitdepth; - ((mng_imagep)pData->pObjzero)->pImgbuf->iJHDRcompression = pData->iJHDRimgcompression; - ((mng_imagep)pData->pObjzero)->pImgbuf->iJHDRinterlace = pData->iJHDRimginterlace; - ((mng_imagep)pData->pObjzero)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth; - } - } - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - - if (!pData->bHasDHDR) - { /* we're always storing a JPEG */ - if (pImage) /* real object ? */ - pData->pStoreobj = pImage; /* tell the row routines */ - else /* otherwise use object 0 */ - pData->pStoreobj = pData->pObjzero; - /* display "on-the-fly" ? */ - if ( -#ifndef MNG_SKIPCHUNK_MAGN - ( ((mng_imagep)pData->pStoreobj)->iMAGN_MethodX == 0) && - ( ((mng_imagep)pData->pStoreobj)->iMAGN_MethodY == 0) && -#endif - ( (pData->eImagetype == mng_it_jng ) || - (((mng_imagep)pData->pStoreobj)->bVisible) ) ) - { - next_layer (pData); /* that's a new layer then ! */ - - pData->iBreakpoint = 0; - - if (pData->bTimerset) /* timer break ? */ - pData->iBreakpoint = 7; - else - if (pData->bRunning) /* still running ? */ - { /* anything to display ? */ - if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt)) - { - set_display_routine (pData); /* then determine display routine */ - /* display from the object we store in */ - pData->pRetrieveobj = pData->pStoreobj; - } - } - } - } - - if (!pData->bTimerset) /* no timer break ? */ - { /* default row initialization ! */ -#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT - pData->ePng_imgtype=png_none; -#endif - pData->fInitrowproc = (mng_fptr)mng_init_rowproc; - - if ((!pData->bHasDHDR) || (pData->iDeltatype == MNG_DELTATYPE_REPLACE)) - { /* 8-bit JPEG ? */ - if (pData->iJHDRimgbitdepth == 8) - { /* intermediate row is 8-bit deep */ - pData->bIsRGBA16 = MNG_FALSE; - pData->iRowsamples = pData->iDatawidth; - - switch (pData->iJHDRcolortype) /* determine pixel processing routines */ - { - case MNG_COLORTYPE_JPEGGRAY : - { - pData->fStorerow2 = (mng_fptr)mng_store_jpeg_g8; - pData->fRetrieverow = (mng_fptr)mng_retrieve_g8; - pData->bIsOpaque = MNG_TRUE; - break; - } - case MNG_COLORTYPE_JPEGCOLOR : - { - pData->fStorerow2 = (mng_fptr)mng_store_jpeg_rgb8; - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8; - pData->bIsOpaque = MNG_TRUE; - break; - } - case MNG_COLORTYPE_JPEGGRAYA : - { - pData->fStorerow2 = (mng_fptr)mng_store_jpeg_ga8; - pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8; - pData->bIsOpaque = MNG_FALSE; - break; - } - case MNG_COLORTYPE_JPEGCOLORA : - { - pData->fStorerow2 = (mng_fptr)mng_store_jpeg_rgba8; - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; - pData->bIsOpaque = MNG_FALSE; - break; - } - } - } -#ifndef MNG_NO_16BIT_SUPPORT - else - { - pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ - - /* TODO: 12-bit JPEG */ - /* TODO: 8- + 12-bit JPEG (eg. type=20) */ - - } -#endif - /* possible IDAT alpha-channel ? */ - if (pData->iJHDRalphacompression == MNG_COMPRESSION_DEFLATE) - { - /* determine alpha processing routine */ -#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT - pData->fInitrowproc = (mng_fptr)mng_init_rowproc; -#endif - switch (pData->iJHDRalphabitdepth) - { -#ifndef MNG_OPTIMIZE_FOOTPRINT_INIT -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a1_ni; break; } - case 2 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a2_ni; break; } - case 4 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a4_ni; break; } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a8_ni; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a16_ni; break; } -#endif -#else -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { pData->ePng_imgtype = png_jpeg_a1; break; } - case 2 : { pData->ePng_imgtype = png_jpeg_a2; break; } - case 4 : { pData->ePng_imgtype = png_jpeg_a4; break; } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { pData->ePng_imgtype = png_jpeg_a8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->ePng_imgtype = png_jpeg_a16; break; } -#endif -#endif - } - } - else /* possible JDAA alpha-channel ? */ - if (pData->iJHDRalphacompression == MNG_COMPRESSION_BASELINEJPEG) - { /* 8-bit JPEG ? */ - if (pData->iJHDRimgbitdepth == 8) - { - if (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) - pData->fStorerow3 = (mng_fptr)mng_store_jpeg_g8_alpha; - else - if (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) - pData->fStorerow3 = (mng_fptr)mng_store_jpeg_rgb8_alpha; - } - else - { - /* TODO: 12-bit JPEG with 8-bit JDAA */ - } - } - /* initialize JPEG library */ - iRetcode = mngjpeg_initialize (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - else - { /* must be alpha add/replace !! */ - if ((pData->iDeltatype != MNG_DELTATYPE_BLOCKALPHAADD ) && - (pData->iDeltatype != MNG_DELTATYPE_BLOCKALPHAREPLACE) ) - MNG_ERROR (pData, MNG_INVDELTATYPE); - /* determine alpha processing routine */ -#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT - pData->fInitrowproc = (mng_fptr)mng_init_rowproc; -#endif - switch (pData->iJHDRalphabitdepth) - { -#ifndef MNG_OPTIMIZE_FOOTPRINT_INIT -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { pData->fInitrowproc = (mng_fptr)mng_init_g1_ni; break; } - case 2 : { pData->fInitrowproc = (mng_fptr)mng_init_g2_ni; break; } - case 4 : { pData->fInitrowproc = (mng_fptr)mng_init_g4_ni; break; } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { pData->fInitrowproc = (mng_fptr)mng_init_g8_ni; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fInitrowproc = (mng_fptr)mng_init_g16_ni; break; } -#endif -#else -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { pData->ePng_imgtype = png_jpeg_a1; break; } - case 2 : { pData->ePng_imgtype = png_jpeg_a2; break; } - case 4 : { pData->ePng_imgtype = png_jpeg_a4; break; } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { pData->ePng_imgtype = png_jpeg_a8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->ePng_imgtype = png_jpeg_a16; break; } -#endif -#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ - } - } - - pData->iFilterofs = 0; /* determine filter characteristics */ - pData->iLevel0 = 0; /* default levels */ - pData->iLevel1 = 0; - pData->iLevel2 = 0; - pData->iLevel3 = 0; - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iJHDRalphafilter == 0xC0) - { - if (pData->iJHDRalphabitdepth <= 8) - pData->iFilterofs = 1; - else - pData->iFilterofs = 2; - - } -#endif -#ifdef FILTER193 /* no adaptive filtering ? */ - if (pData->iJHDRalphafilter == 0xC1) - pData->iPixelofs = pData->iFilterofs; - else -#endif - pData->iPixelofs = pData->iFilterofs + 1; - - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -mng_retcode mng_process_display_jdaa (mng_datap pData, - mng_uint32 iRawlen, - mng_uint8p pRawdata) -#else -mng_retcode mng_process_display_jdaa (mng_datap pData) -#endif -{ - mng_retcode iRetcode = MNG_NOERROR; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAA, MNG_LC_START); -#endif - - if (!pData->bJPEGdecompress2) /* if we're not decompressing already */ - { - if (pData->fInitrowproc) /* initialize row-processing? */ - { - iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData); - pData->fInitrowproc = MNG_NULL; /* only call this once !!! */ - } - - if (!iRetcode) /* initialize decompress */ - iRetcode = mngjpeg_decompressinit2 (pData); - } - - if (!iRetcode) /* all ok? then decompress, my man */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mngjpeg_decompressdata2 (pData, iRawlen, pRawdata); -#else - iRetcode = mngjpeg_decompressdata2 (pData, pData->iRawlen, pData->pRawdata); -#endif - - if (iRetcode) - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -mng_retcode mng_process_display_jdat (mng_datap pData, - mng_uint32 iRawlen, - mng_uint8p pRawdata) -#else -mng_retcode mng_process_display_jdat (mng_datap pData) -#endif -{ - mng_retcode iRetcode = MNG_NOERROR; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAT, MNG_LC_START); -#endif - - if (pData->bRestorebkgd) /* need to restore the background ? */ - { - pData->bRestorebkgd = MNG_FALSE; - iRetcode = load_bkgdlayer (pData); - - pData->iLayerseq++; /* and it counts as a layer then ! */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - - if (!pData->bJPEGdecompress) /* if we're not decompressing already */ - { - if (pData->fInitrowproc) /* initialize row-processing? */ - { - iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData); - pData->fInitrowproc = MNG_NULL; /* only call this once !!! */ - } - - if (!iRetcode) /* initialize decompress */ - iRetcode = mngjpeg_decompressinit (pData); - } - - if (!iRetcode) /* all ok? then decompress, my man */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mngjpeg_decompressdata (pData, iRawlen, pRawdata); -#else - iRetcode = mngjpeg_decompressdata (pData, pData->iRawlen, pData->pRawdata); -#endif - - if (iRetcode) - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -mng_retcode mng_process_display_dhdr (mng_datap pData, - mng_uint16 iObjectid, - mng_uint8 iImagetype, - mng_uint8 iDeltatype, - mng_uint32 iBlockwidth, - mng_uint32 iBlockheight, - mng_uint32 iBlockx, - mng_uint32 iBlocky) -#else -mng_retcode mng_process_display_dhdr (mng_datap pData) -#endif -{ - mng_imagep pImage; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DHDR, MNG_LC_START); -#endif - - pData->fInitrowproc = MNG_NULL; /* do nothing by default */ - pData->fDisplayrow = MNG_NULL; - pData->fCorrectrow = MNG_NULL; - pData->fStorerow = MNG_NULL; - pData->fProcessrow = MNG_NULL; - pData->pStoreobj = MNG_NULL; - - pData->fDeltagetrow = MNG_NULL; - pData->fDeltaaddrow = MNG_NULL; - pData->fDeltareplacerow = MNG_NULL; - pData->fDeltaputrow = MNG_NULL; - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pImage = mng_find_imageobject (pData, iObjectid); -#else - pImage = mng_find_imageobject (pData, pData->iDHDRobjectid); -#endif - - if (pImage) /* object exists ? */ - { - if (pImage->pImgbuf->bConcrete) /* is it concrete ? */ - { /* previous magnification to be done ? */ -#ifndef MNG_SKIPCHUNK_MAGN - if ((pImage->iMAGN_MethodX) || (pImage->iMAGN_MethodY)) - { - iRetcode = mng_magnify_imageobject (pData, pImage); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif - /* save delta fields */ - pData->pDeltaImage = (mng_ptr)pImage; -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pData->iDeltaImagetype = iImagetype; - pData->iDeltatype = iDeltatype; - pData->iDeltaBlockwidth = iBlockwidth; - pData->iDeltaBlockheight = iBlockheight; - pData->iDeltaBlockx = iBlockx; - pData->iDeltaBlocky = iBlocky; -#else - pData->iDeltaImagetype = pData->iDHDRimagetype; - pData->iDeltatype = pData->iDHDRdeltatype; - pData->iDeltaBlockwidth = pData->iDHDRblockwidth; - pData->iDeltaBlockheight = pData->iDHDRblockheight; - pData->iDeltaBlockx = pData->iDHDRblockx; - pData->iDeltaBlocky = pData->iDHDRblocky; -#endif - /* restore target-object fields */ - pData->iDatawidth = pImage->pImgbuf->iWidth; - pData->iDataheight = pImage->pImgbuf->iHeight; - pData->iBitdepth = pImage->pImgbuf->iBitdepth; - pData->iColortype = pImage->pImgbuf->iColortype; - pData->iCompression = pImage->pImgbuf->iCompression; - pData->iFilter = pImage->pImgbuf->iFilter; - pData->iInterlace = pImage->pImgbuf->iInterlace; - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if ((iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || - (iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth; - else - if ((iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) || - (iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) ) - pData->iBitdepth = pImage->pImgbuf->iAlphasampledepth; - else - if ((iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) || - (iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) ) - pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth; -#else - if ((pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || - (pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth; - else - if ((pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) || - (pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) ) - pData->iBitdepth = pImage->pImgbuf->iAlphasampledepth; - else - if ((pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) || - (pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) ) - pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth; -#endif - -#ifdef MNG_INCLUDE_JNG - pData->iJHDRimgbitdepth = pImage->pImgbuf->iBitdepth; - pData->iJHDRcolortype = pImage->pImgbuf->iColortype; - pData->iJHDRimgcompression = pImage->pImgbuf->iJHDRcompression; - pData->iJHDRimginterlace = pImage->pImgbuf->iJHDRinterlace; - pData->iJHDRalphacompression = pImage->pImgbuf->iCompression; - pData->iJHDRalphafilter = pImage->pImgbuf->iFilter; - pData->iJHDRalphainterlace = pImage->pImgbuf->iInterlace; - pData->iJHDRalphabitdepth = pImage->pImgbuf->iAlphabitdepth; -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - /* block size specified ? */ - if (iDeltatype != MNG_DELTATYPE_NOCHANGE) - { /* block entirely within target ? */ - if (iDeltatype != MNG_DELTATYPE_REPLACE) - { - if (((iBlockx + iBlockwidth ) > pData->iDatawidth ) || - ((iBlocky + iBlockheight) > pData->iDataheight) ) - MNG_ERROR (pData, MNG_INVALIDBLOCK); - } - - pData->iDatawidth = iBlockwidth; - pData->iDataheight = iBlockheight; - } -#else - /* block size specified ? */ - if (pData->iDHDRdeltatype != MNG_DELTATYPE_NOCHANGE) - { /* block entirely within target ? */ - if (pData->iDHDRdeltatype != MNG_DELTATYPE_REPLACE) - { - if (((pData->iDHDRblockx + pData->iDHDRblockwidth ) > pData->iDatawidth ) || - ((pData->iDHDRblocky + pData->iDHDRblockheight) > pData->iDataheight) ) - MNG_ERROR (pData, MNG_INVALIDBLOCK); - } - - pData->iDatawidth = pData->iDHDRblockwidth; - pData->iDataheight = pData->iDHDRblockheight; - } -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - switch (iDeltatype) /* determine nr of delta-channels */ -#else - switch (pData->iDHDRdeltatype) /* determine nr of delta-channels */ -#endif - { - case MNG_DELTATYPE_BLOCKALPHAADD : ; - case MNG_DELTATYPE_BLOCKALPHAREPLACE : - { -#ifdef MNG_INCLUDE_JNG - if ((pData->iColortype == MNG_COLORTYPE_GRAYA ) || - (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) ) - { - pData->iColortype = MNG_COLORTYPE_GRAY; - pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY; - } - else - if ((pData->iColortype == MNG_COLORTYPE_RGBA ) || - (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) - { - pData->iColortype = MNG_COLORTYPE_GRAY; - pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY; - } -#else - if (pData->iColortype == MNG_COLORTYPE_GRAYA) - pData->iColortype = MNG_COLORTYPE_GRAY; - else - if (pData->iColortype == MNG_COLORTYPE_RGBA) - pData->iColortype = MNG_COLORTYPE_GRAY; -#endif - else /* target has no alpha; that sucks! */ - MNG_ERROR (pData, MNG_TARGETNOALPHA); - - break; - } - - case MNG_DELTATYPE_BLOCKCOLORADD : ; - case MNG_DELTATYPE_BLOCKCOLORREPLACE : - { -#ifdef MNG_INCLUDE_JNG - if ((pData->iColortype == MNG_COLORTYPE_GRAYA ) || - (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) ) - { - pData->iColortype = MNG_COLORTYPE_GRAY; - pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY; - } - else - if ((pData->iColortype == MNG_COLORTYPE_RGBA ) || - (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) - { - pData->iColortype = MNG_COLORTYPE_RGB; - pData->iJHDRcolortype = MNG_COLORTYPE_JPEGCOLOR; - } -#else - if (pData->iColortype == MNG_COLORTYPE_GRAYA) - pData->iColortype = MNG_COLORTYPE_GRAY; - else - if (pData->iColortype == MNG_COLORTYPE_RGBA) - pData->iColortype = MNG_COLORTYPE_RGB; -#endif - else /* target has no alpha; that sucks! */ - MNG_ERROR (pData, MNG_TARGETNOALPHA); - - break; - } - - } - /* full image replace ? */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (iDeltatype == MNG_DELTATYPE_REPLACE) -#else - if (pData->iDHDRdeltatype == MNG_DELTATYPE_REPLACE) -#endif - { - iRetcode = mng_reset_object_details (pData, pImage, - pData->iDatawidth, pData->iDataheight, - pData->iBitdepth, pData->iColortype, - pData->iCompression, pData->iFilter, - pData->iInterlace, MNG_FALSE); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - pData->pStoreobj = pImage; /* and store straight into this object */ - } - else - { - mng_imagedatap pBufzero, pBuf; - /* we store in object 0 and process it later */ - pData->pStoreobj = pData->pObjzero; - /* make sure to initialize object 0 then */ - iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pObjzero, - pData->iDatawidth, pData->iDataheight, - pData->iBitdepth, pData->iColortype, - pData->iCompression, pData->iFilter, - pData->iInterlace, MNG_TRUE); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - pBuf = pImage->pImgbuf; /* copy possible palette & cheap transparency */ - pBufzero = ((mng_imagep)pData->pObjzero)->pImgbuf; - - pBufzero->bHasPLTE = pBuf->bHasPLTE; - pBufzero->bHasTRNS = pBuf->bHasTRNS; - - if (pBufzero->bHasPLTE) /* copy palette ? */ - { - mng_uint32 iX; - - pBufzero->iPLTEcount = pBuf->iPLTEcount; - - for (iX = 0; iX < pBuf->iPLTEcount; iX++) - { - pBufzero->aPLTEentries [iX].iRed = pBuf->aPLTEentries [iX].iRed; - pBufzero->aPLTEentries [iX].iGreen = pBuf->aPLTEentries [iX].iGreen; - pBufzero->aPLTEentries [iX].iBlue = pBuf->aPLTEentries [iX].iBlue; - } - } - - if (pBufzero->bHasTRNS) /* copy cheap transparency ? */ - { - pBufzero->iTRNSgray = pBuf->iTRNSgray; - pBufzero->iTRNSred = pBuf->iTRNSred; - pBufzero->iTRNSgreen = pBuf->iTRNSgreen; - pBufzero->iTRNSblue = pBuf->iTRNSblue; - pBufzero->iTRNScount = pBuf->iTRNScount; - - MNG_COPY (pBufzero->aTRNSentries, pBuf->aTRNSentries, - sizeof (pBufzero->aTRNSentries)); - } - /* process immediately if bitdepth & colortype are equal */ - pData->bDeltaimmediate = - (mng_bool)((pData->bDisplaying) && (!pData->bSkipping) && - ((pData->bRunning) || (pData->bSearching)) && - (pData->iBitdepth == ((mng_imagep)pData->pDeltaImage)->pImgbuf->iBitdepth ) && - (pData->iColortype == ((mng_imagep)pData->pDeltaImage)->pImgbuf->iColortype) ); - } - -#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT - pData->fInitrowproc = (mng_fptr)mng_init_rowproc; - pData->ePng_imgtype = mng_png_imgtype (pData->iColortype, pData->iBitdepth); -#else - switch (pData->iColortype) /* determine row initialization routine */ - { - case 0 : { /* gray */ - switch (pData->iBitdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g1_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g1_i; - - break; - } - case 2 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g2_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g2_i; - - break; - } - case 4 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g4_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g4_i; - - break; - } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g8_i; - - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_g16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_g16_i; - - break; - } -#endif - } - - break; - } - case 2 : { /* rgb */ - switch (pData->iBitdepth) - { - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i; - - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i; - - break; - } -#endif - } - - break; - } - case 3 : { /* indexed */ - switch (pData->iBitdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx1_i; - - break; - } - case 2 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx2_i; - - break; - } - case 4 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx4_i; - - break; - } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_idx8_i; - - break; - } - } - - break; - } - case 4 : { /* gray+alpha */ - switch (pData->iBitdepth) - { - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_ga8_i; - - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_ga16_i; - - break; - } -#endif - } - - break; - } - case 6 : { /* rgb+alpha */ - switch (pData->iBitdepth) - { - case 8 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i; - - break; - } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { - if (!pData->iInterlace) - pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni; - else - pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i; - - break; - } -#endif - } - - break; - } - } -#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ - } - else - MNG_ERROR (pData, MNG_OBJNOTCONCRETE); - - } - else - MNG_ERROR (pData, MNG_OBJECTUNKNOWN); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -mng_retcode mng_process_display_prom (mng_datap pData, - mng_uint8 iBitdepth, - mng_uint8 iColortype, - mng_uint8 iFilltype) -#else -mng_retcode mng_process_display_prom (mng_datap pData) -#endif -{ - mng_imagep pImage; - mng_imagedatap pBuf; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PROM, MNG_LC_START); -#endif - - if (!pData->pDeltaImage) /* gotta have this now! */ - MNG_ERROR (pData, MNG_INVALIDDELTA); - - pImage = (mng_imagep)pData->pDeltaImage; - pBuf = pImage->pImgbuf; - /* can't demote bitdepth! */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (iBitdepth < pBuf->iBitdepth) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if ( ((pBuf->iColortype == MNG_COLORTYPE_GRAY ) && - (iColortype != MNG_COLORTYPE_GRAY ) && - (iColortype != MNG_COLORTYPE_GRAYA ) && - (iColortype != MNG_COLORTYPE_RGB ) && - (iColortype != MNG_COLORTYPE_RGBA ) ) || - ((pBuf->iColortype == MNG_COLORTYPE_GRAYA ) && - (iColortype != MNG_COLORTYPE_GRAYA ) && - (iColortype != MNG_COLORTYPE_RGBA ) ) || - ((pBuf->iColortype == MNG_COLORTYPE_RGB ) && - (iColortype != MNG_COLORTYPE_RGB ) && - (iColortype != MNG_COLORTYPE_RGBA ) ) || - ((pBuf->iColortype == MNG_COLORTYPE_RGBA ) && - (iColortype != MNG_COLORTYPE_RGBA ) ) || -#ifdef MNG_INCLUDE_JNG - ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAY ) && - (iColortype != MNG_COLORTYPE_JPEGGRAY ) && - (iColortype != MNG_COLORTYPE_JPEGCOLOR ) && - (iColortype != MNG_COLORTYPE_JPEGGRAYA ) && - (iColortype != MNG_COLORTYPE_JPEGCOLORA) ) || - ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLOR ) && - (iColortype != MNG_COLORTYPE_JPEGCOLOR ) && - (iColortype != MNG_COLORTYPE_JPEGCOLORA) ) || - ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAYA ) && - (iColortype != MNG_COLORTYPE_JPEGGRAYA ) && - (iColortype != MNG_COLORTYPE_JPEGCOLORA) ) || - ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLORA) && - (iColortype != MNG_COLORTYPE_JPEGCOLORA) ) || -#endif - ((pBuf->iColortype == MNG_COLORTYPE_INDEXED ) && - (iColortype != MNG_COLORTYPE_INDEXED ) && - (iColortype != MNG_COLORTYPE_RGB ) && - (iColortype != MNG_COLORTYPE_RGBA ) ) ) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - - iRetcode = mng_promote_imageobject (pData, pImage, iBitdepth, iColortype, iFilltype); -#else - if (pData->iPROMbitdepth < pBuf->iBitdepth) - MNG_ERROR (pData, MNG_INVALIDBITDEPTH); - - if ( ((pBuf->iColortype == MNG_COLORTYPE_GRAY ) && - (pData->iPROMcolortype != MNG_COLORTYPE_GRAY ) && - (pData->iPROMcolortype != MNG_COLORTYPE_GRAYA ) && - (pData->iPROMcolortype != MNG_COLORTYPE_RGB ) && - (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) || - ((pBuf->iColortype == MNG_COLORTYPE_GRAYA ) && - (pData->iPROMcolortype != MNG_COLORTYPE_GRAYA ) && - (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) || - ((pBuf->iColortype == MNG_COLORTYPE_RGB ) && - (pData->iPROMcolortype != MNG_COLORTYPE_RGB ) && - (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) || - ((pBuf->iColortype == MNG_COLORTYPE_RGBA ) && - (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) || -#ifdef MNG_INCLUDE_JNG - ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAY ) && - (pData->iPROMcolortype != MNG_COLORTYPE_JPEGGRAY ) && - (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLOR ) && - (pData->iPROMcolortype != MNG_COLORTYPE_JPEGGRAYA ) && - (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLORA) ) || - ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLOR ) && - (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLOR ) && - (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLORA) ) || - ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAYA ) && - (pData->iPROMcolortype != MNG_COLORTYPE_JPEGGRAYA ) && - (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLORA) ) || - ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLORA) && - (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLORA) ) || -#endif - ((pBuf->iColortype == MNG_COLORTYPE_INDEXED ) && - (pData->iPROMcolortype != MNG_COLORTYPE_INDEXED ) && - (pData->iPROMcolortype != MNG_COLORTYPE_RGB ) && - (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) ) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - - iRetcode = mng_promote_imageobject (pData, pImage, pData->iPROMbitdepth, - pData->iPROMcolortype, pData->iPROMfilltype); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PROM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode mng_process_display_ipng (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IPNG, MNG_LC_START); -#endif - /* indicate it for what it is now */ - pData->iDeltaImagetype = MNG_IMAGETYPE_PNG; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IPNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG -mng_retcode mng_process_display_ijng (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IJNG, MNG_LC_START); -#endif - /* indicate it for what it is now */ - pData->iDeltaImagetype = MNG_IMAGETYPE_JNG; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IJNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -mng_retcode mng_process_display_pplt (mng_datap pData, - mng_uint8 iType, - mng_uint32 iCount, - mng_palette8ep paIndexentries, - mng_uint8p paAlphaentries, - mng_uint8p paUsedentries) -#else -mng_retcode mng_process_display_pplt (mng_datap pData) -#endif -{ - mng_uint32 iX; - mng_imagep pImage = (mng_imagep)pData->pObjzero; - mng_imagedatap pBuf = pImage->pImgbuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PPLT, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iX = iCount; -#else - iX = pData->iPPLTcount; -#endif -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - switch (iType) -#else - switch (pData->iPPLTtype) -#endif - { - case MNG_DELTATYPE_REPLACERGB : - { -#ifdef MNG_DECREMENT_LOOPS - for (; iX > 0;iX--) -#else -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - for (iX = 0; iX < iCount; iX++) -#else - for (iX = 0; iX < pData->iPPLTcount; iX++) -#endif -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (paUsedentries [iX]) - { - pBuf->aPLTEentries [iX].iRed = paIndexentries [iX].iRed; - pBuf->aPLTEentries [iX].iGreen = paIndexentries [iX].iGreen; - pBuf->aPLTEentries [iX].iBlue = paIndexentries [iX].iBlue; - } -#else - if (pData->paPPLTusedentries [iX]) - { - pBuf->aPLTEentries [iX].iRed = pData->paPPLTindexentries [iX].iRed; - pBuf->aPLTEentries [iX].iGreen = pData->paPPLTindexentries [iX].iGreen; - pBuf->aPLTEentries [iX].iBlue = pData->paPPLTindexentries [iX].iBlue; - } -#endif - } - - break; - } - case MNG_DELTATYPE_DELTARGB : - { -#ifdef MNG_DECREMENT_LOOPS - for (; iX > 0;iX--) -#else -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - for (iX = 0; iX < iCount; iX++) -#else - for (iX = 0; iX < pData->iPPLTcount; iX++) -#endif -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (paUsedentries [iX]) - { - pBuf->aPLTEentries [iX].iRed = - (mng_uint8)(pBuf->aPLTEentries [iX].iRed + - paIndexentries [iX].iRed ); - pBuf->aPLTEentries [iX].iGreen = - (mng_uint8)(pBuf->aPLTEentries [iX].iGreen + - paIndexentries [iX].iGreen); - pBuf->aPLTEentries [iX].iBlue = - (mng_uint8)(pBuf->aPLTEentries [iX].iBlue + - paIndexentries [iX].iBlue ); - } -#else - if (pData->paPPLTusedentries [iX]) - { - pBuf->aPLTEentries [iX].iRed = - (mng_uint8)(pBuf->aPLTEentries [iX].iRed + - pData->paPPLTindexentries [iX].iRed ); - pBuf->aPLTEentries [iX].iGreen = - (mng_uint8)(pBuf->aPLTEentries [iX].iGreen + - pData->paPPLTindexentries [iX].iGreen); - pBuf->aPLTEentries [iX].iBlue = - (mng_uint8)(pBuf->aPLTEentries [iX].iBlue + - pData->paPPLTindexentries [iX].iBlue ); - } -#endif - } - - break; - } - case MNG_DELTATYPE_REPLACEALPHA : - { -#ifdef MNG_DECREMENT_LOOPS - for (; iX > 0;iX--) -#else -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - for (iX = 0; iX < iCount; iX++) -#else - for (iX = 0; iX < pData->iPPLTcount; iX++) -#endif -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (paUsedentries [iX]) - pBuf->aTRNSentries [iX] = paAlphaentries [iX]; - } -#else - if (pData->paPPLTusedentries [iX]) - pBuf->aTRNSentries [iX] = pData->paPPLTalphaentries [iX]; - } -#endif - - break; - } - case MNG_DELTATYPE_DELTAALPHA : - { -#ifdef MNG_DECREMENT_LOOPS - for (; iX > 0;iX--) -#else -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - for (iX = 0; iX < iCount; iX++) -#else - for (iX = 0; iX < pData->iPPLTcount; iX++) -#endif -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (paUsedentries [iX]) - pBuf->aTRNSentries [iX] = - (mng_uint8)(pBuf->aTRNSentries [iX] + - paAlphaentries [iX]); -#else - if (pData->paPPLTusedentries [iX]) - pBuf->aTRNSentries [iX] = - (mng_uint8)(pBuf->aTRNSentries [iX] + - pData->paPPLTalphaentries [iX]); -#endif - } - - break; - } - case MNG_DELTATYPE_REPLACERGBA : - { -#ifdef MNG_DECREMENT_LOOPS - for (; iX > 0;iX--) -#else -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - for (iX = 0; iX < iCount; iX++) -#else - for (iX = 0; iX < pData->iPPLTcount; iX++) -#endif -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (paUsedentries [iX]) - { - pBuf->aPLTEentries [iX].iRed = paIndexentries [iX].iRed; - pBuf->aPLTEentries [iX].iGreen = paIndexentries [iX].iGreen; - pBuf->aPLTEentries [iX].iBlue = paIndexentries [iX].iBlue; - pBuf->aTRNSentries [iX] = paAlphaentries [iX]; - } -#else - if (pData->paPPLTusedentries [iX]) - { - pBuf->aPLTEentries [iX].iRed = pData->paPPLTindexentries [iX].iRed; - pBuf->aPLTEentries [iX].iGreen = pData->paPPLTindexentries [iX].iGreen; - pBuf->aPLTEentries [iX].iBlue = pData->paPPLTindexentries [iX].iBlue; - pBuf->aTRNSentries [iX] = pData->paPPLTalphaentries [iX]; - } -#endif - } - - break; - } - case MNG_DELTATYPE_DELTARGBA : - { -#ifdef MNG_DECREMENT_LOOPS - for (; iX > 0;iX--) -#else -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - for (iX = 0; iX < iCount; iX++) -#else - for (iX = 0; iX < pData->iPPLTcount; iX++) -#endif -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (paUsedentries [iX]) - { - pBuf->aPLTEentries [iX].iRed = - (mng_uint8)(pBuf->aPLTEentries [iX].iRed + - paIndexentries [iX].iRed ); - pBuf->aPLTEentries [iX].iGreen = - (mng_uint8)(pBuf->aPLTEentries [iX].iGreen + - paIndexentries [iX].iGreen); - pBuf->aPLTEentries [iX].iBlue = - (mng_uint8)(pBuf->aPLTEentries [iX].iBlue + - paIndexentries [iX].iBlue ); - pBuf->aTRNSentries [iX] = - (mng_uint8)(pBuf->aTRNSentries [iX] + - paAlphaentries [iX]); - } -#else - if (pData->paPPLTusedentries [iX]) - { - pBuf->aPLTEentries [iX].iRed = - (mng_uint8)(pBuf->aPLTEentries [iX].iRed + - pData->paPPLTindexentries [iX].iRed ); - pBuf->aPLTEentries [iX].iGreen = - (mng_uint8)(pBuf->aPLTEentries [iX].iGreen + - pData->paPPLTindexentries [iX].iGreen); - pBuf->aPLTEentries [iX].iBlue = - (mng_uint8)(pBuf->aPLTEentries [iX].iBlue + - pData->paPPLTindexentries [iX].iBlue ); - pBuf->aTRNSentries [iX] = - (mng_uint8)(pBuf->aTRNSentries [iX] + - pData->paPPLTalphaentries [iX]); - } -#endif - } - - break; - } - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if ((iType != MNG_DELTATYPE_REPLACERGB) && (iType != MNG_DELTATYPE_DELTARGB)) -#else - if ((pData->iPPLTtype != MNG_DELTATYPE_REPLACERGB) && - (pData->iPPLTtype != MNG_DELTATYPE_DELTARGB ) ) -#endif - { - if (pBuf->bHasTRNS) - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (iCount > pBuf->iTRNScount) - pBuf->iTRNScount = iCount; -#else - if (pData->iPPLTcount > pBuf->iTRNScount) - pBuf->iTRNScount = pData->iPPLTcount; -#endif - } - else - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pBuf->iTRNScount = iCount; - pBuf->bHasTRNS = MNG_TRUE; -#else - pBuf->iTRNScount = pData->iPPLTcount; - pBuf->bHasTRNS = MNG_TRUE; -#endif - } - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if ((iType != MNG_DELTATYPE_REPLACEALPHA) && (iType != MNG_DELTATYPE_DELTAALPHA)) -#else - if ((pData->iPPLTtype != MNG_DELTATYPE_REPLACEALPHA) && - (pData->iPPLTtype != MNG_DELTATYPE_DELTAALPHA ) ) -#endif - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (iCount > pBuf->iPLTEcount) - pBuf->iPLTEcount = iCount; -#else - if (pData->iPPLTcount > pBuf->iPLTEcount) - pBuf->iPLTEcount = pData->iPPLTcount; -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PPLT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MAGN -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -mng_retcode mng_process_display_magn (mng_datap pData, - mng_uint16 iFirstid, - mng_uint16 iLastid, - mng_uint8 iMethodX, - mng_uint16 iMX, - mng_uint16 iMY, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint16 iMT, - mng_uint16 iMB, - mng_uint8 iMethodY) -#else -mng_retcode mng_process_display_magn (mng_datap pData) -#endif -{ - mng_uint16 iX; - mng_imagep pImage; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_START); -#endif - /* iterate the object-ids */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - for (iX = iFirstid; iX <= iLastid; iX++) -#else - for (iX = pData->iMAGNfirstid; iX <= pData->iMAGNlastid; iX++) -#endif - { - if (iX == 0) /* process object 0 ? */ - { - pImage = (mng_imagep)pData->pObjzero; - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pImage->iMAGN_MethodX = iMethodX; - pImage->iMAGN_MethodY = iMethodY; - pImage->iMAGN_MX = iMX; - pImage->iMAGN_MY = iMY; - pImage->iMAGN_ML = iML; - pImage->iMAGN_MR = iMR; - pImage->iMAGN_MT = iMT; - pImage->iMAGN_MB = iMB; -#else - pImage->iMAGN_MethodX = pData->iMAGNmethodX; - pImage->iMAGN_MethodY = pData->iMAGNmethodY; - pImage->iMAGN_MX = pData->iMAGNmX; - pImage->iMAGN_MY = pData->iMAGNmY; - pImage->iMAGN_ML = pData->iMAGNmL; - pImage->iMAGN_MR = pData->iMAGNmR; - pImage->iMAGN_MT = pData->iMAGNmT; - pImage->iMAGN_MB = pData->iMAGNmB; -#endif - } - else - { - pImage = mng_find_imageobject (pData, iX); - /* object exists & is not frozen ? */ - if ((pImage) && (!pImage->bFrozen)) - { /* previous magnification to be done ? */ - if ((pImage->iMAGN_MethodX) || (pImage->iMAGN_MethodY)) - { - mng_retcode iRetcode = mng_magnify_imageobject (pData, pImage); - if (iRetcode) /* on error bail out */ - return iRetcode; - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pImage->iMAGN_MethodX = iMethodX; - pImage->iMAGN_MethodY = iMethodY; - pImage->iMAGN_MX = iMX; - pImage->iMAGN_MY = iMY; - pImage->iMAGN_ML = iML; - pImage->iMAGN_MR = iMR; - pImage->iMAGN_MT = iMT; - pImage->iMAGN_MB = iMB; -#else - pImage->iMAGN_MethodX = pData->iMAGNmethodX; - pImage->iMAGN_MethodY = pData->iMAGNmethodY; - pImage->iMAGN_MX = pData->iMAGNmX; - pImage->iMAGN_MY = pData->iMAGNmY; - pImage->iMAGN_ML = pData->iMAGNmL; - pImage->iMAGN_MR = pData->iMAGNmR; - pImage->iMAGN_MT = pData->iMAGNmT; - pImage->iMAGN_MB = pData->iMAGNmB; -#endif - } - } - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pData->iMAGNfromid = iFirstid; - pData->iMAGNtoid = iLastid; - iX = iFirstid; -#else - pData->iMAGNfromid = pData->iMAGNfirstid; - pData->iMAGNtoid = pData->iMAGNlastid; - iX = pData->iMAGNfirstid; -#endif - /* iterate again for showing */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - while ((iX <= iLastid) && (!pData->bTimerset)) -#else - while ((iX <= pData->iMAGNlastid) && (!pData->bTimerset)) -#endif - { - pData->iMAGNcurrentid = iX; - - if (iX) /* only real objects ! */ - { - pImage = mng_find_imageobject (pData, iX); - /* object exists & is not frozen & - is visible & is viewable ? */ - if ((pImage) && (!pImage->bFrozen) && - (pImage->bVisible) && (pImage->bViewable)) - { - mng_retcode iRetcode = mng_display_image (pData, pImage, MNG_FALSE); - if (iRetcode) - return iRetcode; - } - } - - iX++; - } - - if (pData->bTimerset) /* broken ? */ - pData->iBreakpoint = 9; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_process_display_magn2 (mng_datap pData) -{ - mng_uint16 iX; - mng_imagep pImage; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_START); -#endif - - iX = pData->iMAGNcurrentid; - /* iterate again for showing */ - while ((iX <= pData->iMAGNtoid) && (!pData->bTimerset)) - { - pData->iMAGNcurrentid = iX; - - if (iX) /* only real objects ! */ - { - pImage = mng_find_imageobject (pData, iX); - /* object exists & is not frozen & - is visible & is viewable ? */ - if ((pImage) && (!pImage->bFrozen) && - (pImage->bVisible) && (pImage->bViewable)) - { - mng_retcode iRetcode = mng_display_image (pData, pImage, MNG_FALSE); - if (iRetcode) - return iRetcode; - } - } - - iX++; - } - - if (pData->bTimerset) /* broken ? */ - pData->iBreakpoint = 9; - else - pData->iBreakpoint = 0; /* not again ! */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -mng_retcode mng_process_display_past (mng_datap pData, - mng_uint16 iTargetid, - mng_uint8 iTargettype, - mng_int32 iTargetx, - mng_int32 iTargety, - mng_uint32 iCount, - mng_ptr pSources) -#else -mng_retcode mng_process_display_past (mng_datap pData) -#endif -{ - mng_retcode iRetcode = MNG_NOERROR; - mng_imagep pTargetimg; - mng_imagep pSourceimg; -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - mng_past_sourcep pSource = (mng_past_sourcep)pSources; -#else - mng_past_sourcep pSource = (mng_past_sourcep)pData->pPASTsources; -#endif - mng_uint32 iX = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_START); -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (iTargetid) /* a real destination object ? */ -#else - if (pData->iPASTtargetid) /* a real destination object ? */ -#endif - { /* let's find it then */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pTargetimg = (mng_imagep)mng_find_imageobject (pData, iTargetid); -#else - pTargetimg = (mng_imagep)mng_find_imageobject (pData, pData->iPASTtargetid); -#endif - - if (!pTargetimg) /* if it doesn't exists; do a barf */ - MNG_ERROR (pData, MNG_OBJECTUNKNOWN); - /* it's gotta be abstract !!! */ - if (pTargetimg->pImgbuf->bConcrete) - MNG_ERROR (pData, MNG_OBJNOTABSTRACT); - /* we want 32-/64-bit RGBA to play with ! */ - if ((pTargetimg->pImgbuf->iBitdepth <= MNG_BITDEPTH_8) || - (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_GRAY) || - (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_RGB) || - (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_INDEXED) || - (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_GRAYA) ) - iRetcode = mng_promote_imageobject (pData, pTargetimg, MNG_BITDEPTH_8, - MNG_COLORTYPE_RGBA, - MNG_FILLMETHOD_LEFTBITREPLICATE); - else - if ((pTargetimg->pImgbuf->iBitdepth > MNG_BITDEPTH_8) && - ((pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_GRAY) || - (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_RGB) || - (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_GRAYA) ) ) - iRetcode = mng_promote_imageobject (pData, pTargetimg, MNG_BITDEPTH_16, - MNG_COLORTYPE_RGBA, - MNG_FILLMETHOD_LEFTBITREPLICATE); -#ifdef MNG_INCLUDE_JNG - else - if ((pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_JPEGGRAY) || - (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_JPEGCOLOR) || - (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_JPEGGRAYA) ) - iRetcode = mng_promote_imageobject (pData, pTargetimg, - pTargetimg->pImgbuf->iBitdepth, - MNG_COLORTYPE_JPEGCOLORA, - MNG_FILLMETHOD_LEFTBITREPLICATE); -#endif - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* make it really abstract ? */ - if (!pTargetimg->pImgbuf->bCorrected) - { - iRetcode = mng_colorcorrect_object (pData, pTargetimg); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } - else - { /* pasting into object 0 !!! */ - pTargetimg = (mng_imagep)pData->pObjzero; - /* is it usable ??? */ - if ((pTargetimg->bClipped) && - (pTargetimg->iClipr > pTargetimg->iPosx) && - (pTargetimg->iClipb > pTargetimg->iPosy)) - { - /* make it 32-bit RGBA please !!! */ - iRetcode = mng_reset_object_details (pData, pTargetimg, - pTargetimg->iClipr - pTargetimg->iPosx, - pTargetimg->iClipb - pTargetimg->iPosy, - MNG_BITDEPTH_8, MNG_COLORTYPE_RGBA, - 0, 0, 0, MNG_FALSE); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - else - pTargetimg = MNG_NULL; /* clipped beyond visibility ! */ - } - - if (pTargetimg) /* usable destination ? */ - { - mng_int32 iSourceY; - mng_int32 iSourceYinc; - mng_int32 iSourcerowsize; - mng_int32 iSourcesamples; - mng_bool bSourceRGBA16; - mng_int32 iTargetY; - mng_int32 iTargetrowsize; - mng_int32 iTargetsamples; - mng_bool bTargetRGBA16 = MNG_FALSE; - mng_int32 iTemprowsize; - mng_imagedatap pBuf; -#ifndef MNG_SKIPCHUNK_MAGN - /* needs magnification ? */ - if ((pTargetimg->iMAGN_MethodX) || (pTargetimg->iMAGN_MethodY)) - iRetcode = mng_magnify_imageobject (pData, pTargetimg); -#endif - - if (!iRetcode) /* still ok ? */ - { - bTargetRGBA16 = (mng_bool)(pTargetimg->pImgbuf->iBitdepth > 8); - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - switch (iTargettype) /* determine target x/y */ -#else - switch (pData->iPASTtargettype) /* determine target x/y */ -#endif - { - case 0 : { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pData->iPastx = iTargetx; - pData->iPasty = iTargety; -#else - pData->iPastx = pData->iPASTtargetx; - pData->iPasty = pData->iPASTtargety; -#endif - break; - } - - case 1 : { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pData->iPastx = pTargetimg->iPastx + iTargetx; - pData->iPasty = pTargetimg->iPasty + iTargety; -#else - pData->iPastx = pTargetimg->iPastx + pData->iPASTtargetx; - pData->iPasty = pTargetimg->iPasty + pData->iPASTtargety; -#endif - break; - } - - case 2 : { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pData->iPastx += iTargetx; - pData->iPasty += iTargety; -#else - pData->iPastx += pData->iPASTtargetx; - pData->iPasty += pData->iPASTtargety; -#endif - break; - } - } - /* save for next time ... */ - pTargetimg->iPastx = pData->iPastx; - pTargetimg->iPasty = pData->iPasty; - /* address destination for row-routines */ - pData->pStoreobj = (mng_objectp)pTargetimg; - pData->pStorebuf = (mng_objectp)pTargetimg->pImgbuf; - } - /* process the sources one by one */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - while ((!iRetcode) && (iX < iCount)) -#else - while ((!iRetcode) && (iX < pData->iPASTcount)) -#endif - { /* find the little bastards first */ - pSourceimg = (mng_imagep)mng_find_imageobject (pData, pSource->iSourceid); - /* exists and viewable? */ - if ((pSourceimg) && (pSourceimg->bViewable)) - { /* needs magnification ? */ -#ifndef MNG_SKIPCHUNK_MAGN - if ((pSourceimg->iMAGN_MethodX) || (pSourceimg->iMAGN_MethodY)) - iRetcode = mng_magnify_imageobject (pData, pSourceimg); -#endif - - if (!iRetcode) /* still ok ? */ - { - pBuf = (mng_imagedatap)pSourceimg->pImgbuf; - /* address source for row-routines */ - pData->pRetrieveobj = (mng_objectp)pSourceimg; - - pData->iPass = -1; /* init row-processing variables */ - pData->iRowinc = 1; - pData->iColinc = 1; - pData->iPixelofs = 0; - iSourcesamples = (mng_int32)pBuf->iWidth; - iSourcerowsize = pBuf->iRowsize; - bSourceRGBA16 = (mng_bool)(pBuf->iBitdepth > 8); - /* make sure the delta-routines do the right thing */ - pData->iDeltatype = MNG_DELTATYPE_BLOCKPIXELREPLACE; - - switch (pBuf->iColortype) - { - case 0 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (bSourceRGBA16) - pData->fRetrieverow = (mng_fptr)mng_retrieve_g16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_g8; - - pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS); - break; - } - - case 2 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (bSourceRGBA16) - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8; - - pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS); - break; - } - - - case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8; - pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS); - break; - } - - - case 4 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (bSourceRGBA16) - pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8; - - pData->bIsOpaque = MNG_FALSE; - break; - } - - - case 6 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (bSourceRGBA16) - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; - - pData->bIsOpaque = MNG_FALSE; - break; - } - - case 8 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (bSourceRGBA16) - pData->fRetrieverow = (mng_fptr)mng_retrieve_g16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_g8; - - pData->bIsOpaque = MNG_TRUE; - break; - } - - case 10 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (bSourceRGBA16) - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8; - - pData->bIsOpaque = MNG_TRUE; - break; - } - - - case 12 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (bSourceRGBA16) - pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8; - - pData->bIsOpaque = MNG_FALSE; - break; - } - - - case 14 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (bSourceRGBA16) - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16; - else -#endif - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; - - pData->bIsOpaque = MNG_FALSE; - break; - } - } - /* determine scaling */ -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_NO_DELTA_PNG - if ((!bSourceRGBA16) && (bTargetRGBA16)) - pData->fScalerow = (mng_fptr)mng_scale_rgba8_rgba16; - else - if ((bSourceRGBA16) && (!bTargetRGBA16)) - pData->fScalerow = (mng_fptr)mng_scale_rgba16_rgba8; - else -#endif -#endif - pData->fScalerow = MNG_NULL; - - /* default no color-correction */ - pData->fCorrectrow = MNG_NULL; - -#if defined(MNG_FULL_CMS) /* determine color-management routine */ - iRetcode = mng_init_full_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); -#elif defined(MNG_GAMMA_ONLY) - iRetcode = mng_init_gamma_only (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); -#elif defined(MNG_APP_CMS) - iRetcode = mng_init_app_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); -#endif - } - - if (!iRetcode) /* still ok ? */ - { - pData->fFliprow = MNG_NULL; /* no flipping or tiling by default */ - pData->fTilerow = MNG_NULL; - /* but perhaps we do have to ... */ - switch (pSource->iOrientation) - { - case 2 : ; - case 4 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (bTargetRGBA16) - pData->fFliprow = (mng_fptr)mng_flip_rgba16; - else -#endif - pData->fFliprow = (mng_fptr)mng_flip_rgba8; - break; - } - - case 8 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (bTargetRGBA16) - pData->fTilerow = (mng_fptr)mng_tile_rgba16; - else -#endif - pData->fTilerow = (mng_fptr)mng_tile_rgba8; - break; - } - } - /* determine composition routine */ - /* note that we're abusing the delta-routine setup !!! */ - switch (pSource->iComposition) - { - case 0 : { /* composite over */ -#ifndef MNG_NO_16BIT_SUPPORT - if (bTargetRGBA16) - pData->fDeltarow = (mng_fptr)mng_composeover_rgba16; - else -#endif - pData->fDeltarow = (mng_fptr)mng_composeover_rgba8; - break; - } - - case 1 : { /* replace */ -#ifndef MNG_NO_16BIT_SUPPORT - if (bTargetRGBA16) - pData->fDeltarow = (mng_fptr)mng_delta_rgba16_rgba16; - else -#endif - pData->fDeltarow = (mng_fptr)mng_delta_rgba8_rgba8; - break; - } - - case 2 : { /* composite under */ -#ifndef MNG_NO_16BIT_SUPPORT - if (bTargetRGBA16) - pData->fDeltarow = (mng_fptr)mng_composeunder_rgba16; - else -#endif - pData->fDeltarow = (mng_fptr)mng_composeunder_rgba8; - break; - } - } - /* determine offsets & clipping */ - if (pSource->iOffsettype == 1) - { - pData->iDestl = pData->iPastx + pSource->iOffsetx; - pData->iDestt = pData->iPasty + pSource->iOffsety; - } - else - { - pData->iDestl = pSource->iOffsetx; - pData->iDestt = pSource->iOffsety; - } - - pData->iDestr = (mng_int32)pTargetimg->pImgbuf->iWidth; - pData->iDestb = (mng_int32)pTargetimg->pImgbuf->iHeight; - /* take the source dimension into account ? */ - if (pSource->iOrientation != 8) - { - pData->iDestr = MIN_COORD (pData->iDestr, pData->iDestl + (mng_int32)pBuf->iWidth); - pData->iDestb = MIN_COORD (pData->iDestb, pData->iDestt + (mng_int32)pBuf->iHeight); - } - /* source clipping */ - if (pSource->iBoundarytype == 1) - { - if (pData->iDestl < pData->iPastx + pSource->iBoundaryl) - pData->iSourcel = pData->iPastx + pSource->iBoundaryl - pData->iDestl; - else - pData->iSourcel = 0; - - if (pData->iDestt < pData->iPasty + pSource->iBoundaryt) - pData->iSourcet = pData->iPasty + pSource->iBoundaryt - pData->iDestt; - else - pData->iSourcet = 0; - - pData->iDestl = MAX_COORD (pData->iDestl, pData->iPastx + pSource->iBoundaryl); - pData->iDestt = MAX_COORD (pData->iDestt, pData->iPasty + pSource->iBoundaryt); - pData->iDestr = MIN_COORD (pData->iDestr, pData->iPastx + pSource->iBoundaryr); - pData->iDestb = MIN_COORD (pData->iDestb, pData->iPasty + pSource->iBoundaryb); - } - else - { - if (pData->iDestl < pSource->iBoundaryl) - pData->iSourcel = pSource->iBoundaryl - pData->iDestl; - else - pData->iSourcel = 0; - - if (pData->iDestt < pSource->iBoundaryt) - pData->iSourcet = pSource->iBoundaryt - pData->iDestt; - else - pData->iSourcet = 0; - - pData->iDestl = MAX_COORD (pData->iDestl, pSource->iBoundaryl); - pData->iDestt = MAX_COORD (pData->iDestt, pSource->iBoundaryt); - pData->iDestr = MIN_COORD (pData->iDestr, pSource->iBoundaryr); - pData->iDestb = MIN_COORD (pData->iDestb, pSource->iBoundaryb); - } - - if (pData->iSourcel) /* indent source ? */ - { -#ifndef MNG_NO_16BIT_SUPPORT - if (bTargetRGBA16) /* abuse tiling routine to shift source-pixels */ - pData->fTilerow = (mng_fptr)mng_tile_rgba16; - else -#endif - pData->fTilerow = (mng_fptr)mng_tile_rgba8; - } - /* anything to display ? */ - if ((pData->iDestl <= pData->iDestr) && (pData->iDestt <= pData->iDestb)) - { /* init variables for the loop */ - if ((pSource->iOrientation == 2) || (pSource->iOrientation == 6)) - { - iSourceY = (mng_int32)pBuf->iHeight - 1 - pData->iSourcet; - iSourceYinc = -1; - } - else - { - iSourceY = pData->iSourcet; - iSourceYinc = 1; - } - - iTargetY = pData->iDestt; - pData->iCol = pData->iDestl; - - iTargetsamples = pData->iDestr - pData->iDestl; - -#ifndef MNG_NO_16BIT_SUPPORT - if (bTargetRGBA16) - iTargetrowsize = (iTargetsamples << 3); - else -#endif - iTargetrowsize = (iTargetsamples << 2); - - /* get temporary work-buffers */ - if (iSourcerowsize > iTargetrowsize) - iTemprowsize = iSourcerowsize << 1; - else - iTemprowsize = iTargetrowsize << 1; - MNG_ALLOC (pData, pData->pRGBArow, iTemprowsize); - MNG_ALLOC (pData, pData->pWorkrow, iTemprowsize); - - while ((!iRetcode) && (iTargetY < pData->iDestb)) - { /* get a row */ - pData->iRow = iSourceY; - pData->iRowsamples = iSourcesamples; - pData->iRowsize = iSourcerowsize; - pData->bIsRGBA16 = bSourceRGBA16; - iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData); - /* scale it (if necessary) */ - if ((!iRetcode) && (pData->fScalerow)) - iRetcode = ((mng_scalerow)pData->fScalerow) (pData); - - pData->bIsRGBA16 = bTargetRGBA16; - /* color correction (if necessary) */ - if ((!iRetcode) && (pData->fCorrectrow)) - iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData); - /* flipping (if necessary) */ - if ((!iRetcode) && (pData->fFliprow)) - iRetcode = ((mng_fliprow)pData->fFliprow) (pData); - /* tiling (if necessary) */ - if ((!iRetcode) && (pData->fTilerow)) - iRetcode = ((mng_tilerow)pData->fTilerow) (pData); - - if (!iRetcode) /* and paste..... */ - { - pData->iRow = iTargetY; - pData->iRowsamples = iTargetsamples; - pData->iRowsize = iTargetrowsize; - iRetcode = ((mng_deltarow)pData->fDeltarow) (pData); - } - - iSourceY += iSourceYinc; /* and next line */ - - if (iSourceY < 0) - iSourceY = (mng_int32)pBuf->iHeight - 1; - else - if (iSourceY >= (mng_int32)pBuf->iHeight) - iSourceY = 0; - - iTargetY++; - } - /* drop the temporary row-buffer */ - MNG_FREEX (pData, pData->pWorkrow, iTemprowsize); - MNG_FREEX (pData, pData->pRGBArow, iTemprowsize); - } - -#if defined(MNG_FULL_CMS) /* cleanup cms stuff */ - if (!iRetcode) - iRetcode = mng_clear_cms (pData); -#endif - } - - pSource++; /* neeeeext */ - iX++; - } - } - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - if (!iTargetid) /* did we paste into object 0 ? */ -#else - if (!pData->iPASTtargetid) /* did we paste into object 0 ? */ -#endif - { /* display it then ! */ - iRetcode = mng_display_image (pData, pTargetimg, MNG_FALSE); - if (iRetcode) /* on error bail out */ - return iRetcode; - } - else - { /* target is visible & viewable ? */ - if ((pTargetimg->bVisible) && (pTargetimg->bViewable)) - { - iRetcode = mng_display_image (pData, pTargetimg, MNG_FALSE); - if (iRetcode) - return iRetcode; - } - } - } - - if (pData->bTimerset) /* broken ? */ - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - pData->iPASTid = iTargetid; -#else - pData->iPASTid = pData->iPASTtargetid; -#endif - pData->iBreakpoint = 11; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SKIPCHUNK_PAST */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -mng_retcode mng_process_display_past2 (mng_datap pData) -{ - mng_retcode iRetcode; - mng_imagep pTargetimg; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_START); -#endif - - if (pData->iPASTid) /* a real destination object ? */ - pTargetimg = (mng_imagep)mng_find_imageobject (pData, pData->iPASTid); - else /* otherwise object 0 */ - pTargetimg = (mng_imagep)pData->pObjzero; - - iRetcode = mng_display_image (pData, pTargetimg, MNG_FALSE); - if (iRetcode) - return iRetcode; - - pData->iBreakpoint = 0; /* only once */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SKIPCHUNK_PAST */ - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_DISPLAY_PROCS */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_display.c copyright (c) 2000-2007 G.Juyn * */ +/* * version : 1.0.10 * */ +/* * * */ +/* * purpose : Display management (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the display management routines * */ +/* * * */ +/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/11/2000 - G.Juyn * */ +/* * - added callback error-reporting support * */ +/* * - fixed frame_delay misalignment * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - added sanity check for frozen status * */ +/* * - changed trace to macro for callback error-reporting * */ +/* * 0.5.1 - 05/13/2000 - G.Juyn * */ +/* * - changed display_mend to reset state to initial or SAVE * */ +/* * - added eMNGma hack (will be removed in 1.0.0 !!!) * */ +/* * - added TERM animation object pointer (easier reference) * */ +/* * - added process_save & process_seek routines * */ +/* * 0.5.1 - 05/14/2000 - G.Juyn * */ +/* * - added save_state and restore_state for SAVE/SEEK/TERM * */ +/* * processing * */ +/* * * */ +/* * 0.5.2 - 05/20/2000 - G.Juyn * */ +/* * - added JNG support (JHDR/JDAT) * */ +/* * 0.5.2 - 05/23/2000 - G.Juyn * */ +/* * - fixed problem with DEFI clipping * */ +/* * 0.5.2 - 05/30/2000 - G.Juyn * */ +/* * - added delta-image support (DHDR,PROM,IPNG,IJNG) * */ +/* * 0.5.2 - 05/31/2000 - G.Juyn * */ +/* * - fixed pointer confusion (contributed by Tim Rowley) * */ +/* * 0.5.2 - 06/03/2000 - G.Juyn * */ +/* * - fixed makeup for Linux gcc compile * */ +/* * 0.5.2 - 06/05/2000 - G.Juyn * */ +/* * - added support for RGB8_A8 canvasstyle * */ +/* * 0.5.2 - 06/09/2000 - G.Juyn * */ +/* * - fixed timer-handling to run with Mozilla (Tim Rowley) * */ +/* * 0.5.2 - 06/10/2000 - G.Juyn * */ +/* * - fixed some compilation-warnings (contrib Jason Morris) * */ +/* * * */ +/* * 0.5.3 - 06/12/2000 - G.Juyn * */ +/* * - fixed display of stored JNG images * */ +/* * 0.5.3 - 06/13/2000 - G.Juyn * */ +/* * - fixed problem with BASI-IEND as object 0 * */ +/* * 0.5.3 - 06/16/2000 - G.Juyn * */ +/* * - changed progressive-display processing * */ +/* * 0.5.3 - 06/17/2000 - G.Juyn * */ +/* * - changed delta-image processing * */ +/* * 0.5.3 - 06/20/2000 - G.Juyn * */ +/* * - fixed some minor stuff * */ +/* * 0.5.3 - 06/21/2000 - G.Juyn * */ +/* * - added speed-modifier to timing routine * */ +/* * 0.5.3 - 06/22/2000 - G.Juyn * */ +/* * - added support for PPLT chunk processing * */ +/* * 0.5.3 - 06/29/2000 - G.Juyn * */ +/* * - swapped refresh parameters * */ +/* * * */ +/* * 0.9.0 - 06/30/2000 - G.Juyn * */ +/* * - changed refresh parameters to 'x,y,width,height' * */ +/* * * */ +/* * 0.9.1 - 07/07/2000 - G.Juyn * */ +/* * - implemented support for freeze/reset/resume & go_xxxx * */ +/* * 0.9.1 - 07/08/2000 - G.Juyn * */ +/* * - added support for improved timing * */ +/* * 0.9.1 - 07/14/2000 - G.Juyn * */ +/* * - changed EOF processing behavior * */ +/* * - fixed TERM delay processing * */ +/* * 0.9.1 - 07/15/2000 - G.Juyn * */ +/* * - fixed freeze & reset processing * */ +/* * 0.9.1 - 07/16/2000 - G.Juyn * */ +/* * - fixed storage of images during mng_read() * */ +/* * - fixed support for mng_display() after mng_read() * */ +/* * 0.9.1 - 07/24/2000 - G.Juyn * */ +/* * - fixed reading of still-images * */ +/* * * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 0.9.3 - 08/07/2000 - G.Juyn * */ +/* * - B111300 - fixup for improved portability * */ +/* * 0.9.3 - 08/21/2000 - G.Juyn * */ +/* * - fixed TERM processing delay of 0 msecs * */ +/* * 0.9.3 - 08/26/2000 - G.Juyn * */ +/* * - added MAGN chunk * */ +/* * 0.9.3 - 09/10/2000 - G.Juyn * */ +/* * - fixed problem with no refresh after TERM * */ +/* * - fixed DEFI behavior * */ +/* * 0.9.3 - 09/16/2000 - G.Juyn * */ +/* * - fixed timing & refresh behavior for single PNG/JNG * */ +/* * 0.9.3 - 09/19/2000 - G.Juyn * */ +/* * - refixed timing & refresh behavior for single PNG/JNG * */ +/* * 0.9.3 - 10/02/2000 - G.Juyn * */ +/* * - fixed timing again (this is getting boring...) * */ +/* * - refixed problem with no refresh after TERM * */ +/* * 0.9.3 - 10/16/2000 - G.Juyn * */ +/* * - added JDAA chunk * */ +/* * 0.9.3 - 10/17/2000 - G.Juyn * */ +/* * - fixed support for bKGD * */ +/* * 0.9.3 - 10/18/2000 - G.Juyn * */ +/* * - fixed delta-processing behavior * */ +/* * 0.9.3 - 10/19/2000 - G.Juyn * */ +/* * - added storage for pixel-/alpha-sampledepth for delta's * */ +/* * 0.9.3 - 10/27/2000 - G.Juyn * */ +/* * - fixed separate read() & display() processing * */ +/* * * */ +/* * 0.9.4 - 10/31/2000 - G.Juyn * */ +/* * - fixed possible loop in display_resume() (Thanks Vova!) * */ +/* * 0.9.4 - 11/20/2000 - G.Juyn * */ +/* * - fixed unwanted repetition in mng_readdisplay() * */ +/* * 0.9.4 - 11/24/2000 - G.Juyn * */ +/* * - moved restore of object 0 to libmng_display * */ +/* * - added restore of object 0 to TERM processing !!! * */ +/* * - fixed TERM delay processing * */ +/* * - fixed TERM end processing (count = 0) * */ +/* * 0.9.4 - 12/16/2000 - G.Juyn * */ +/* * - fixed mixup of data- & function-pointers (thanks Dimitri)* */ +/* * 0.9.4 - 1/18/2001 - G.Juyn * */ +/* * - removed test filter-methods 1 & 65 * */ +/* * - set default level-set for filtertype=64 to all zeroes * */ +/* * * */ +/* * 0.9.5 - 1/20/2001 - G.Juyn * */ +/* * - fixed compiler-warnings Mozilla (thanks Tim) * */ +/* * 0.9.5 - 1/23/2001 - G.Juyn * */ +/* * - fixed timing-problem with switching framing_modes * */ +/* * * */ +/* * 1.0.1 - 02/08/2001 - G.Juyn * */ +/* * - added MEND processing callback * */ +/* * 1.0.1 - 02/13/2001 - G.Juyn * */ +/* * - fixed first FRAM_MODE=4 timing problem * */ +/* * 1.0.1 - 04/21/2001 - G.Juyn * */ +/* * - fixed memory-leak for JNGs with alpha (Thanks Gregg!) * */ +/* * - added BGRA8 canvas with premultiplied alpha * */ +/* * * */ +/* * 1.0.2 - 06/25/2001 - G.Juyn * */ +/* * - fixed memory-leak with delta-images (Thanks Michael!) * */ +/* * * */ +/* * 1.0.5 - 08/15/2002 - G.Juyn * */ +/* * - completed PROM support * */ +/* * - completed delta-image support * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * 1.0.5 - 09/13/2002 - G.Juyn * */ +/* * - fixed read/write of MAGN chunk * */ +/* * 1.0.5 - 09/15/2002 - G.Juyn * */ +/* * - fixed LOOP iteration=0 special case * */ +/* * 1.0.5 - 09/19/2002 - G.Juyn * */ +/* * - fixed color-correction for restore-background handling * */ +/* * - optimized restore-background for bKGD cases * */ +/* * - cleaned up some old stuff * */ +/* * 1.0.5 - 09/20/2002 - G.Juyn * */ +/* * - finished support for BACK image & tiling * */ +/* * - added support for PAST * */ +/* * 1.0.5 - 09/22/2002 - G.Juyn * */ +/* * - added bgrx8 canvas (filler byte) * */ +/* * 1.0.5 - 10/05/2002 - G.Juyn * */ +/* * - fixed dropping mix of frozen/unfrozen objects * */ +/* * 1.0.5 - 10/07/2002 - G.Juyn * */ +/* * - added proposed change in handling of TERM- & if-delay * */ +/* * - added another fix for misplaced TERM chunk * */ +/* * - completed support for condition=2 in TERM chunk * */ +/* * 1.0.5 - 10/18/2002 - G.Juyn * */ +/* * - fixed clipping-problem with BACK tiling (Thanks Sakura!) * */ +/* * 1.0.5 - 10/20/2002 - G.Juyn * */ +/* * - fixed processing for multiple objects in MAGN * */ +/* * - fixed display of visible target of PAST operation * */ +/* * 1.0.5 - 10/30/2002 - G.Juyn * */ +/* * - modified TERM/MEND processing for max(1, TERM_delay, * */ +/* * interframe_delay) * */ +/* * 1.0.5 - 11/04/2002 - G.Juyn * */ +/* * - fixed layer- & frame-counting during read() * */ +/* * - fixed goframe/golayer/gotime processing * */ +/* * 1.0.5 - 01/19/2003 - G.Juyn * */ +/* * - B654627 - fixed SEGV when no gettickcount callback * */ +/* * - B664383 - fixed typo * */ +/* * - finalized changes in TERM/final_delay to elected proposal* */ +/* * * */ +/* * 1.0.6 - 05/11/2003 - G. Juyn * */ +/* * - added conditionals around canvas update routines * */ +/* * 1.0.6 - 05/25/2003 - G.R-P * */ +/* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */ +/* * 1.0.6 - 07/07/2003 - G.R-P * */ +/* * - added conditionals around some JNG-supporting code * */ +/* * - added conditionals around 16-bit supporting code * */ +/* * - reversed some loops to use decrementing counter * */ +/* * - combined init functions into one function * */ +/* * 1.0.6 - 07/10/2003 - G.R-P * */ +/* * - replaced nested switches with simple init setup function * */ +/* * 1.0.6 - 07/29/2003 - G.R-P * */ +/* * - added conditionals around PAST chunk support * */ +/* * 1.0.6 - 08/17/2003 - G.R-P * */ +/* * - added conditionals around non-VLC chunk support * */ +/* * * */ +/* * 1.0.7 - 11/27/2003 - R.A * */ +/* * - added CANVAS_RGB565 and CANVAS_BGR565 * */ +/* * 1.0.7 - 12/06/2003 - R.A * */ +/* * - added CANVAS_RGBA565 and CANVAS_BGRA565 * */ +/* * 1.0.7 - 01/25/2004 - J.S * */ +/* * - added premultiplied alpha canvas' for RGBA, ARGB, ABGR * */ +/* * * */ +/* * 1.0.8 - 03/31/2004 - G.Juyn * */ +/* * - fixed problem with PAST usage where source > dest * */ +/* * 1.0.8 - 05/04/2004 - G.R-P. * */ +/* * - fixed misplaced 16-bit conditionals * */ +/* * * */ +/* * 1.0.9 - 09/18/2004 - G.R-P. * */ +/* * - revised some SKIPCHUNK conditionals * */ +/* * 1.0.9 - 10/10/2004 - G.R-P. * */ +/* * - added MNG_NO_1_2_4BIT_SUPPORT * */ +/* * 1.0.9 - 10/14/2004 - G.Juyn * */ +/* * - added bgr565_a8 canvas-style (thanks to J. Elvander) * */ +/* * 1.0.9 - 12/11/2004 - G.Juyn * */ +/* * - added conditional MNG_OPTIMIZE_DISPLAYCALLS * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * * */ +/* * 1.0.10 - 07/06/2005 - G.R-P. * */ +/* * - added more SKIPCHUNK conditionals * */ +/* * 1.0.10 - 12/28/2005 - G.R-P. * */ +/* * - added missing SKIPCHUNK_MAGN conditional * */ +/* * 1.0.10 - 03/07/2006 - (thanks to W. Manthey) * */ +/* * - added CANVAS_RGB555 and CANVAS_BGR555 * */ +/* * 1.0.10 - 04/08/2007 - G.Juyn * */ +/* * - fixed several compiler warnings * */ +/* * 1.0.10 - 04/08/2007 - G.Juyn * */ +/* * - added support for mPNG proposal * */ +/* * 1.0.10 - 04/12/2007 - G.Juyn * */ +/* * - added support for ANG proposal * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_chunks.h" +#include "libmng_objects.h" +#include "libmng_object_prc.h" +#include "libmng_memory.h" +#include "libmng_zlib.h" +#include "libmng_jpeg.h" +#include "libmng_cms.h" +#include "libmng_pixels.h" +#include "libmng_display.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_DISPLAY_PROCS + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode set_delay (mng_datap pData, + mng_uint32 iInterval) +{ + if (!iInterval) /* at least 1 msec please! */ + iInterval = 1; + + if (pData->bRunning) /* only when really displaying */ + if (!pData->fSettimer ((mng_handle)pData, iInterval)) + MNG_ERROR (pData, MNG_APPTIMERERROR); + +#ifdef MNG_SUPPORT_DYNAMICMNG + if ((!pData->bDynamic) || (pData->bRunning)) +#else + if (pData->bRunning) +#endif + pData->bTimerset = MNG_TRUE; /* and indicate so */ + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_uint32 calculate_delay (mng_datap pData, + mng_uint32 iDelay) +{ + mng_uint32 iTicks = pData->iTicks; + mng_uint32 iWaitfor = 1; /* default non-MNG delay */ + + if (!iTicks) /* tick_count not specified ? */ + if (pData->eImagetype == mng_it_mng) + iTicks = 1000; + + if (iTicks) + { + switch (pData->iSpeed) /* honor speed modifier */ + { + case mng_st_fast : + { + iWaitfor = (mng_uint32)(( 500 * iDelay) / iTicks); + break; + } + case mng_st_slow : + { + iWaitfor = (mng_uint32)((3000 * iDelay) / iTicks); + break; + } + case mng_st_slowest : + { + iWaitfor = (mng_uint32)((8000 * iDelay) / iTicks); + break; + } + default : + { + iWaitfor = (mng_uint32)((1000 * iDelay) / iTicks); + } + } + } + + return iWaitfor; +} + +/* ************************************************************************** */ +/* * * */ +/* * Progressive display refresh - does the call to the refresh callback * */ +/* * and sets the timer to allow the app to perform the actual refresh to * */ +/* * the screen (eg. process its main message-loop) * */ +/* * * */ +/* ************************************************************************** */ + +mng_retcode mng_display_progressive_refresh (mng_datap pData, + mng_uint32 iInterval) +{ + { /* let the app refresh first ? */ + if ((pData->bRunning) && (!pData->bSkipping) && + (pData->iUpdatetop < pData->iUpdatebottom) && (pData->iUpdateleft < pData->iUpdateright)) + { + if (!pData->fRefresh (((mng_handle)pData), + pData->iUpdateleft, pData->iUpdatetop, + pData->iUpdateright - pData->iUpdateleft, + pData->iUpdatebottom - pData->iUpdatetop)) + MNG_ERROR (pData, MNG_APPMISCERROR); + + pData->iUpdateleft = 0; /* reset update-region */ + pData->iUpdateright = 0; + pData->iUpdatetop = 0; + pData->iUpdatebottom = 0; /* reset refreshneeded indicator */ + pData->bNeedrefresh = MNG_FALSE; + /* interval requested ? */ + if ((!pData->bFreezing) && (iInterval)) + { /* setup the timer */ + mng_retcode iRetcode = set_delay (pData, iInterval); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } + } + + return MNG_NOERROR; +} + +/* ************************************************************************** */ +/* * * */ +/* * Generic display routines * */ +/* * * */ +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode interframe_delay (mng_datap pData) +{ + mng_uint32 iWaitfor = 0; + mng_uint32 iInterval; + mng_uint32 iRuninterval; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INTERFRAME_DELAY, MNG_LC_START); +#endif + + { +#ifndef MNG_SKIPCHUNK_FRAM + if (pData->iFramedelay > 0) /* real delay ? */ + { /* let the app refresh first ? */ + if ((pData->bRunning) && (!pData->bSkipping) && + (pData->iUpdatetop < pData->iUpdatebottom) && (pData->iUpdateleft < pData->iUpdateright)) + if (!pData->fRefresh (((mng_handle)pData), + pData->iUpdateleft, pData->iUpdatetop, + pData->iUpdateright - pData->iUpdateleft, + pData->iUpdatebottom - pData->iUpdatetop)) + MNG_ERROR (pData, MNG_APPMISCERROR); + + pData->iUpdateleft = 0; /* reset update-region */ + pData->iUpdateright = 0; + pData->iUpdatetop = 0; + pData->iUpdatebottom = 0; /* reset refreshneeded indicator */ + pData->bNeedrefresh = MNG_FALSE; + +#ifndef MNG_SKIPCHUNK_TERM + if (pData->bOnlyfirstframe) /* only processing first frame after TERM ? */ + { + pData->iFramesafterTERM++; + /* did we do a frame yet ? */ + if (pData->iFramesafterTERM > 1) + { /* then that's it; just stop right here ! */ + pData->pCurraniobj = MNG_NULL; + pData->bRunning = MNG_FALSE; + + return MNG_NOERROR; + } + } +#endif + + if (pData->fGettickcount) + { /* get current tickcount */ + pData->iRuntime = pData->fGettickcount ((mng_handle)pData); + /* calculate interval since last sync-point */ + if (pData->iRuntime < pData->iSynctime) + iRuninterval = pData->iRuntime + ~pData->iSynctime + 1; + else + iRuninterval = pData->iRuntime - pData->iSynctime; + /* calculate actual run-time */ + if (pData->iRuntime < pData->iStarttime) + pData->iRuntime = pData->iRuntime + ~pData->iStarttime + 1; + else + pData->iRuntime = pData->iRuntime - pData->iStarttime; + } + else + { + iRuninterval = 0; + } + + iWaitfor = calculate_delay (pData, pData->iFramedelay); + + if (iWaitfor > iRuninterval) /* delay necessary ? */ + iInterval = iWaitfor - iRuninterval; + else + iInterval = 1; /* force app to process messageloop */ + /* set the timer ? */ + if (((pData->bRunning) || (pData->bSearching) || (pData->bReading)) && + (!pData->bSkipping)) + { + iRetcode = set_delay (pData, iInterval); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } + + if (!pData->bSkipping) /* increase frametime in advance */ + pData->iFrametime = pData->iFrametime + iWaitfor; + /* setup for next delay */ + pData->iFramedelay = pData->iNextdelay; +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INTERFRAME_DELAY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL void set_display_routine (mng_datap pData) +{ /* actively running ? */ + if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping)) + { + switch (pData->iCanvasstyle) /* determine display routine */ + { +#ifndef MNG_SKIPCANVAS_RGB8 + case MNG_CANVAS_RGB8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb8; break; } +#endif +#ifndef MNG_SKIPCANVAS_RGBA8 + case MNG_CANVAS_RGBA8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgba8; break; } +#endif +#ifndef MNG_SKIPCANVAS_RGBA8_PM + case MNG_CANVAS_RGBA8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_rgba8_pm; break; } +#endif +#ifndef MNG_SKIPCANVAS_ARGB8 + case MNG_CANVAS_ARGB8 : { pData->fDisplayrow = (mng_fptr)mng_display_argb8; break; } +#endif +#ifndef MNG_SKIPCANVAS_ARGB8_PM + case MNG_CANVAS_ARGB8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_argb8_pm; break; } +#endif +#ifndef MNG_SKIPCANVAS_RGB8_A8 + case MNG_CANVAS_RGB8_A8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb8_a8; break; } +#endif +#ifndef MNG_SKIPCANVAS_BGR8 + case MNG_CANVAS_BGR8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr8; break; } +#endif +#ifndef MNG_SKIPCANVAS_BGRX8 + case MNG_CANVAS_BGRX8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgrx8; break; } +#endif +#ifndef MNG_SKIPCANVAS_BGRA8 + case MNG_CANVAS_BGRA8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgra8; break; } +#endif +#ifndef MNG_SKIPCANVAS_BGRA8_PM + case MNG_CANVAS_BGRA8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_bgra8_pm; break; } +#endif +#ifndef MNG_SKIPCANVAS_ABGR8 + case MNG_CANVAS_ABGR8 : { pData->fDisplayrow = (mng_fptr)mng_display_abgr8; break; } +#endif +#ifndef MNG_SKIPCANVAS_ABGR8_PM + case MNG_CANVAS_ABGR8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_abgr8_pm; break; } +#endif +#ifndef MNG_SKIPCANVAS_RGB565 + case MNG_CANVAS_RGB565 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb565; break; } +#endif +#ifndef MNG_SKIPCANVAS_RGBA565 + case MNG_CANVAS_RGBA565 : { pData->fDisplayrow = (mng_fptr)mng_display_rgba565; break; } +#endif +#ifndef MNG_SKIPCANVAS_BGR565 + case MNG_CANVAS_BGR565 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr565; break; } +#endif +#ifndef MNG_SKIPCANVAS_BGRA565 + case MNG_CANVAS_BGRA565 : { pData->fDisplayrow = (mng_fptr)mng_display_bgra565; break; } +#endif +#ifndef MNG_SKIPCANVAS_BGR565_A8 + case MNG_CANVAS_BGR565_A8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr565_a8; break; } +#endif +#ifndef MNG_SKIPCANVAS_RGB555 + case MNG_CANVAS_RGB555 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb555; break; } +#endif +#ifndef MNG_SKIPCANVAS_BGR555 + case MNG_CANVAS_BGR555 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr555; break; } +#endif + +#ifndef MNG_NO_16BIT_SUPPORT +/* case MNG_CANVAS_RGB16 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb16; break; } */ +/* case MNG_CANVAS_RGBA16 : { pData->fDisplayrow = (mng_fptr)mng_display_rgba16; break; } */ +/* case MNG_CANVAS_ARGB16 : { pData->fDisplayrow = (mng_fptr)mng_display_argb16; break; } */ +/* case MNG_CANVAS_BGR16 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr16; break; } */ +/* case MNG_CANVAS_BGRA16 : { pData->fDisplayrow = (mng_fptr)mng_display_bgra16; break; } */ +/* case MNG_CANVAS_ABGR16 : { pData->fDisplayrow = (mng_fptr)mng_display_abgr16; break; } */ +#endif +/* case MNG_CANVAS_INDEX8 : { pData->fDisplayrow = (mng_fptr)mng_display_index8; break; } */ +/* case MNG_CANVAS_INDEXA8 : { pData->fDisplayrow = (mng_fptr)mng_display_indexa8; break; } */ +/* case MNG_CANVAS_AINDEX8 : { pData->fDisplayrow = (mng_fptr)mng_display_aindex8; break; } */ +/* case MNG_CANVAS_GRAY8 : { pData->fDisplayrow = (mng_fptr)mng_display_gray8; break; } */ +/* case MNG_CANVAS_AGRAY8 : { pData->fDisplayrow = (mng_fptr)mng_display_agray8; break; } */ +/* case MNG_CANVAS_GRAYA8 : { pData->fDisplayrow = (mng_fptr)mng_display_graya8; break; } */ +#ifndef MNG_NO_16BIT_SUPPORT +/* case MNG_CANVAS_GRAY16 : { pData->fDisplayrow = (mng_fptr)mng_display_gray16; break; } */ +/* case MNG_CANVAS_GRAYA16 : { pData->fDisplayrow = (mng_fptr)mng_display_graya16; break; } */ +/* case MNG_CANVAS_AGRAY16 : { pData->fDisplayrow = (mng_fptr)mng_display_agray16; break; } */ +#endif +/* case MNG_CANVAS_DX15 : { pData->fDisplayrow = (mng_fptr)mng_display_dx15; break; } */ +/* case MNG_CANVAS_DX16 : { pData->fDisplayrow = (mng_fptr)mng_display_dx16; break; } */ + } + } + + return; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode load_bkgdlayer (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_LOAD_BKGDLAYER, MNG_LC_START); +#endif + /* actively running ? */ + if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping)) + { + mng_int32 iY; + mng_retcode iRetcode; + mng_bool bColorcorr = MNG_FALSE; + /* save values */ + mng_int32 iDestl = pData->iDestl; + mng_int32 iDestr = pData->iDestr; + mng_int32 iDestt = pData->iDestt; + mng_int32 iDestb = pData->iDestb; + mng_int32 iSourcel = pData->iSourcel; + mng_int32 iSourcer = pData->iSourcer; + mng_int32 iSourcet = pData->iSourcet; + mng_int32 iSourceb = pData->iSourceb; + mng_int8 iPass = pData->iPass; + mng_int32 iRow = pData->iRow; + mng_int32 iRowinc = pData->iRowinc; + mng_int32 iCol = pData->iCol; + mng_int32 iColinc = pData->iColinc; + mng_int32 iRowsamples = pData->iRowsamples; + mng_int32 iRowsize = pData->iRowsize; + mng_uint8p pPrevrow = pData->pPrevrow; + mng_uint8p pRGBArow = pData->pRGBArow; + mng_bool bIsRGBA16 = pData->bIsRGBA16; + mng_bool bIsOpaque = pData->bIsOpaque; + mng_fptr fCorrectrow = pData->fCorrectrow; + mng_fptr fDisplayrow = pData->fDisplayrow; + mng_fptr fRetrieverow = pData->fRetrieverow; + mng_objectp pCurrentobj = pData->pCurrentobj; + mng_objectp pRetrieveobj = pData->pRetrieveobj; + + pData->iDestl = 0; /* determine clipping region */ + pData->iDestt = 0; + pData->iDestr = pData->iWidth; + pData->iDestb = pData->iHeight; + +#ifndef MNG_SKIPCHUNK_FRAM + if (pData->bFrameclipping) /* frame clipping specified ? */ + { + pData->iDestl = MAX_COORD (pData->iDestl, pData->iFrameclipl); + pData->iDestt = MAX_COORD (pData->iDestt, pData->iFrameclipt); + pData->iDestr = MIN_COORD (pData->iDestr, pData->iFrameclipr); + pData->iDestb = MIN_COORD (pData->iDestb, pData->iFrameclipb); + } +#endif + /* anything to clear ? */ + if ((pData->iDestr >= pData->iDestl) && (pData->iDestb >= pData->iDestt)) + { + pData->iPass = -1; /* these are the object's dimensions now */ + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iWidth; + pData->iRowsize = pData->iRowsamples << 2; + pData->bIsRGBA16 = MNG_FALSE; /* let's keep it simple ! */ + pData->bIsOpaque = MNG_TRUE; + + pData->iSourcel = 0; /* source relative to destination */ + pData->iSourcer = pData->iDestr - pData->iDestl; + pData->iSourcet = 0; + pData->iSourceb = pData->iDestb - pData->iDestt; + + set_display_routine (pData); /* determine display routine */ + /* default restore using preset BG color */ + pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgcolor; + +#ifndef MNG_SKIPCHUNK_bKGD + if (((pData->eImagetype == mng_it_png) || (pData->eImagetype == mng_it_jng)) && + (pData->bUseBKGD)) + { /* prefer bKGD in PNG/JNG */ + if (!pData->pCurrentobj) + pData->pCurrentobj = pData->pObjzero; + + if (((mng_imagep)pData->pCurrentobj)->pImgbuf->bHasBKGD) + { + pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bkgd; + bColorcorr = MNG_TRUE; + } + } +#endif + + if (pData->fGetbkgdline) /* background-canvas-access callback set ? */ + { + switch (pData->iBkgdstyle) + { +#ifndef MNG_SKIPCANVAS_RGB8 + case MNG_CANVAS_RGB8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb8; break; } +#endif +#ifndef MNG_SKIPCANVAS_BGR8 + case MNG_CANVAS_BGR8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr8; break; } +#endif +#ifndef MNG_SKIPCANVAS_BGRX8 + case MNG_CANVAS_BGRX8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgrx8; break; } +#endif +#ifndef MNG_SKIPCANVAS_BGR565 + case MNG_CANVAS_BGR565 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr565; break; } +#endif +#ifndef MNG_SKIPCANVAS_RGB565 + case MNG_CANVAS_RGB565 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb565; break; } +#endif +#ifndef MNG_NO_16BIT_SUPPORT + /* case MNG_CANVAS_RGB16 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb16; break; } */ + /* case MNG_CANVAS_BGR16 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr16; break; } */ +#endif + /* case MNG_CANVAS_INDEX8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_index8; break; } */ + /* case MNG_CANVAS_GRAY8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_gray8; break; } */ +#ifndef MNG_NO_16BIT_SUPPORT + /* case MNG_CANVAS_GRAY16 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_gray16; break; } */ +#endif + /* case MNG_CANVAS_DX15 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_dx15; break; } */ + /* case MNG_CANVAS_DX16 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_dx16; break; } */ + } + } + +#ifndef MNG_SKIPCHUNK_BACK + if (pData->bHasBACK) + { /* background image ? */ + if ((pData->iBACKmandatory & 0x02) && (pData->iBACKimageid)) + { + pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_backcolor; + bColorcorr = MNG_TRUE; + } + else /* background color ? */ + if (pData->iBACKmandatory & 0x01) + { + pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_backcolor; + bColorcorr = MNG_TRUE; + } + } +#endif + + pData->fCorrectrow = MNG_NULL; /* default no color-correction */ + + if (bColorcorr) /* do we have to do color-correction ? */ + { +#ifdef MNG_NO_CMS + iRetcode = MNG_NOERROR; +#else +#if defined(MNG_FULL_CMS) /* determine color-management routine */ + iRetcode = mng_init_full_cms (pData, MNG_TRUE, MNG_FALSE, MNG_FALSE); +#elif defined(MNG_GAMMA_ONLY) + iRetcode = mng_init_gamma_only (pData, MNG_TRUE, MNG_FALSE, MNG_FALSE); +#elif defined(MNG_APP_CMS) + iRetcode = mng_init_app_cms (pData, MNG_TRUE, MNG_FALSE, MNG_FALSE); +#endif + if (iRetcode) /* on error bail out */ + return iRetcode; +#endif /* MNG_NO_CMS */ + } + /* get a temporary row-buffer */ + MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize); + + iY = pData->iDestt; /* this is where we start */ + iRetcode = MNG_NOERROR; /* so far, so good */ + + while ((!iRetcode) && (iY < pData->iDestb)) + { /* restore a background row */ + iRetcode = ((mng_restbkgdrow)pData->fRestbkgdrow) (pData); + /* color correction ? */ + if ((!iRetcode) && (pData->fCorrectrow)) + iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData); + + if (!iRetcode) /* so... display it */ + iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData); + + if (!iRetcode) + iRetcode = mng_next_row (pData); + + iY++; /* and next line */ + } + /* drop the temporary row-buffer */ + MNG_FREE (pData, pData->pRGBArow, pData->iRowsize); + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#if defined(MNG_FULL_CMS) /* cleanup cms stuff */ + if (bColorcorr) /* did we do color-correction ? */ + { + iRetcode = mng_clear_cms (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif +#ifndef MNG_SKIPCHUNK_BACK + /* background image ? */ + if ((pData->bHasBACK) && (pData->iBACKmandatory & 0x02) && (pData->iBACKimageid)) + { + mng_imagep pImage; + /* let's find that object then */ + pData->pRetrieveobj = mng_find_imageobject (pData, pData->iBACKimageid); + pImage = (mng_imagep)pData->pRetrieveobj; + /* exists, viewable and visible ? */ + if ((pImage) && (pImage->bViewable) && (pImage->bVisible)) + { /* will it fall within the target region ? */ + if ((pImage->iPosx < pData->iDestr) && (pImage->iPosy < pData->iDestb) && + ((pData->iBACKtile) || + ((pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth >= pData->iDestl) && + (pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight >= pData->iDestt) )) && + ((!pImage->bClipped) || + ((pImage->iClipl <= pImage->iClipr) && (pImage->iClipt <= pImage->iClipb) && + (pImage->iClipl < pData->iDestr) && (pImage->iClipr >= pData->iDestl) && + (pImage->iClipt < pData->iDestb) && (pImage->iClipb >= pData->iDestt) ))) + { /* right; we've got ourselves something to do */ + if (pImage->bClipped) /* clip output region with image's clipping region ? */ + { + if (pImage->iClipl > pData->iDestl) + pData->iDestl = pImage->iClipl; + if (pImage->iClipr < pData->iDestr) + pData->iDestr = pImage->iClipr; + if (pImage->iClipt > pData->iDestt) + pData->iDestt = pImage->iClipt; + if (pImage->iClipb < pData->iDestb) + pData->iDestb = pImage->iClipb; + } + /* image offset does some extra clipping too ! */ + if (pImage->iPosx > pData->iDestl) + pData->iDestl = pImage->iPosx; + if (pImage->iPosy > pData->iDestt) + pData->iDestt = pImage->iPosy; + + if (!pData->iBACKtile) /* without tiling further clipping is needed */ + { + if (pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth < pData->iDestr) + pData->iDestr = pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth; + if (pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight < pData->iDestb) + pData->iDestb = pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight; + } + + pData->iSourcel = 0; /* source relative to destination */ + pData->iSourcer = pData->iDestr - pData->iDestl; + pData->iSourcet = 0; + pData->iSourceb = pData->iDestb - pData->iDestt; + /* 16-bit background ? */ + +#ifdef MNG_NO_16BIT_SUPPORT + pData->bIsRGBA16 = MNG_FALSE; +#else + pData->bIsRGBA16 = (mng_bool)(pImage->pImgbuf->iBitdepth > 8); +#endif + /* let restore routine know the offsets !!! */ + pData->iBackimgoffsx = pImage->iPosx; + pData->iBackimgoffsy = pImage->iPosy; + pData->iBackimgwidth = pImage->pImgbuf->iWidth; + pData->iBackimgheight = pImage->pImgbuf->iHeight; + pData->iRow = 0; /* start at the top again !! */ + /* determine background object retrieval routine */ + switch (pImage->pImgbuf->iColortype) + { + case 0 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_g16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_g8; + + pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS); + break; + } + + case 2 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8; + + pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS); + break; + } + + case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8; + pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS); + break; + } + + case 4 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8; + + pData->bIsOpaque = MNG_FALSE; + break; + } + + case 6 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; + + pData->bIsOpaque = MNG_FALSE; + break; + } + + case 8 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_g16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_g8; + + pData->bIsOpaque = MNG_TRUE; + break; + } + + case 10 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8; + + pData->bIsOpaque = MNG_TRUE; + break; + } + + case 12 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8; + + pData->bIsOpaque = MNG_FALSE; + break; + } + + case 14 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; + + pData->bIsOpaque = MNG_FALSE; + break; + } + } + +#ifdef MNG_NO_CMS + iRetcode = MNG_NOERROR; +#else +#if defined(MNG_FULL_CMS) /* determine color-management routine */ + iRetcode = mng_init_full_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); +#elif defined(MNG_GAMMA_ONLY) + iRetcode = mng_init_gamma_only (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); +#elif defined(MNG_APP_CMS) + iRetcode = mng_init_app_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); +#endif + if (iRetcode) /* on error bail out */ + return iRetcode; +#endif /* MNG_NO_CMS */ + /* get temporary row-buffers */ + MNG_ALLOC (pData, pData->pPrevrow, pData->iRowsize); + MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize); + + iY = pData->iDestt; /* this is where we start */ + iRetcode = MNG_NOERROR; /* so far, so good */ + + while ((!iRetcode) && (iY < pData->iDestb)) + { /* restore a background row */ + iRetcode = mng_restore_bkgd_backimage (pData); + /* color correction ? */ + if ((!iRetcode) && (pData->fCorrectrow)) + iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData); + + if (!iRetcode) /* so... display it */ + iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData); + + if (!iRetcode) + iRetcode = mng_next_row (pData); + + iY++; /* and next line */ + } + /* drop temporary row-buffers */ + MNG_FREE (pData, pData->pRGBArow, pData->iRowsize); + MNG_FREE (pData, pData->pPrevrow, pData->iRowsize); + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#if defined(MNG_FULL_CMS) /* cleanup cms stuff */ + iRetcode = mng_clear_cms (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; +#endif + } + } + } +#endif + } + + pData->iDestl = iDestl; /* restore values */ + pData->iDestr = iDestr; + pData->iDestt = iDestt; + pData->iDestb = iDestb; + pData->iSourcel = iSourcel; + pData->iSourcer = iSourcer; + pData->iSourcet = iSourcet; + pData->iSourceb = iSourceb; + pData->iPass = iPass; + pData->iRow = iRow; + pData->iRowinc = iRowinc; + pData->iCol = iCol; + pData->iColinc = iColinc; + pData->iRowsamples = iRowsamples; + pData->iRowsize = iRowsize; + pData->pPrevrow = pPrevrow; + pData->pRGBArow = pRGBArow; + pData->bIsRGBA16 = bIsRGBA16; + pData->bIsOpaque = bIsOpaque; + pData->fCorrectrow = fCorrectrow; + pData->fDisplayrow = fDisplayrow; + pData->fRetrieverow = fRetrieverow; + pData->pCurrentobj = pCurrentobj; + pData->pRetrieveobj = pRetrieveobj; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_LOAD_BKGDLAYER, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode clear_canvas (mng_datap pData) +{ + mng_int32 iY; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CLEAR_CANVAS, MNG_LC_START); +#endif + + pData->iDestl = 0; /* clipping region is full canvas! */ + pData->iDestt = 0; + pData->iDestr = pData->iWidth; + pData->iDestb = pData->iHeight; + + pData->iSourcel = 0; /* source is same as destination */ + pData->iSourcer = pData->iWidth; + pData->iSourcet = 0; + pData->iSourceb = pData->iHeight; + + pData->iPass = -1; /* these are the object's dimensions now */ + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iWidth; + pData->iRowsize = pData->iRowsamples << 2; + pData->bIsRGBA16 = MNG_FALSE; /* let's keep it simple ! */ + pData->bIsOpaque = MNG_TRUE; + + set_display_routine (pData); /* determine display routine */ + /* get a temporary row-buffer */ + /* it's transparent black by default!! */ + MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize); + + iY = pData->iDestt; /* this is where we start */ + iRetcode = MNG_NOERROR; /* so far, so good */ + + while ((!iRetcode) && (iY < pData->iDestb)) + { /* clear a row then */ + iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData); + + if (!iRetcode) + iRetcode = mng_next_row (pData); /* adjust variables for next row */ + + iY++; /* and next line */ + } + /* drop the temporary row-buffer */ + MNG_FREE (pData, pData->pRGBArow, pData->iRowsize); + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CLEAR_CANVAS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode next_frame (mng_datap pData, + mng_uint8 iFramemode, + mng_uint8 iChangedelay, + mng_uint32 iDelay, + mng_uint8 iChangetimeout, + mng_uint32 iTimeout, + mng_uint8 iChangeclipping, + mng_uint8 iCliptype, + mng_int32 iClipl, + mng_int32 iClipr, + mng_int32 iClipt, + mng_int32 iClipb) +{ + mng_retcode iRetcode = MNG_NOERROR; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_NEXT_FRAME, MNG_LC_START); +#endif + + if (!pData->iBreakpoint) /* no previous break here ? */ + { +#ifndef MNG_SKIPCHUNK_FRAM + mng_uint8 iOldmode = pData->iFramemode; + /* interframe delay required ? */ + if ((iOldmode == 2) || (iOldmode == 4)) + { + if ((pData->iFrameseq) && (iFramemode != 1) && (iFramemode != 3)) + iRetcode = interframe_delay (pData); + else + pData->iFramedelay = pData->iNextdelay; + } + else + { /* delay before inserting background layer? */ + if ((pData->bFramedone) && (iFramemode == 4)) + iRetcode = interframe_delay (pData); + } + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* now we'll assume we're in the next frame! */ + if (iFramemode) /* save the new framing mode ? */ + { + pData->iFRAMmode = iFramemode; + pData->iFramemode = iFramemode; + } + else /* reload default */ + pData->iFramemode = pData->iFRAMmode; + + if (iChangedelay) /* delay changed ? */ + { + pData->iNextdelay = iDelay; /* for *after* next subframe */ + + if ((iOldmode == 2) || (iOldmode == 4)) + pData->iFramedelay = pData->iFRAMdelay; + + if (iChangedelay == 2) /* also overall ? */ + pData->iFRAMdelay = iDelay; + } + else + { /* reload default */ + pData->iNextdelay = pData->iFRAMdelay; + } + + if (iChangetimeout) /* timeout changed ? */ + { /* for next subframe */ + pData->iFrametimeout = iTimeout; + + if ((iChangetimeout == 2) || /* also overall ? */ + (iChangetimeout == 4) || + (iChangetimeout == 6) || + (iChangetimeout == 8)) + pData->iFRAMtimeout = iTimeout; + } + else /* reload default */ + pData->iFrametimeout = pData->iFRAMtimeout; + + if (iChangeclipping) /* clipping changed ? */ + { + pData->bFrameclipping = MNG_TRUE; + + if (!iCliptype) /* absolute ? */ + { + pData->iFrameclipl = iClipl; + pData->iFrameclipr = iClipr; + pData->iFrameclipt = iClipt; + pData->iFrameclipb = iClipb; + } + else /* relative */ + { + pData->iFrameclipl = pData->iFrameclipl + iClipl; + pData->iFrameclipr = pData->iFrameclipr + iClipr; + pData->iFrameclipt = pData->iFrameclipt + iClipt; + pData->iFrameclipb = pData->iFrameclipb + iClipb; + } + + if (iChangeclipping == 2) /* also overall ? */ + { + pData->bFRAMclipping = MNG_TRUE; + + if (!iCliptype) /* absolute ? */ + { + pData->iFRAMclipl = iClipl; + pData->iFRAMclipr = iClipr; + pData->iFRAMclipt = iClipt; + pData->iFRAMclipb = iClipb; + } + else /* relative */ + { + pData->iFRAMclipl = pData->iFRAMclipl + iClipl; + pData->iFRAMclipr = pData->iFRAMclipr + iClipr; + pData->iFRAMclipt = pData->iFRAMclipt + iClipt; + pData->iFRAMclipb = pData->iFRAMclipb + iClipb; + } + } + } + else + { /* reload defaults */ + pData->bFrameclipping = pData->bFRAMclipping; + pData->iFrameclipl = pData->iFRAMclipl; + pData->iFrameclipr = pData->iFRAMclipr; + pData->iFrameclipt = pData->iFRAMclipt; + pData->iFrameclipb = pData->iFRAMclipb; + } +#endif + } + + if (!pData->bTimerset) /* timer still off ? */ + { + if ( +#ifndef MNG_SKIPCHUNK_FRAM + (pData->iFramemode == 4) || /* insert background layer after a new frame */ +#endif + (!pData->iLayerseq)) /* and certainly before the very first layer */ + iRetcode = load_bkgdlayer (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + pData->iFrameseq++; /* count the frame ! */ + pData->bFramedone = MNG_TRUE; /* and indicate we've done one */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_NEXT_FRAME, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode next_layer (mng_datap pData) +{ + mng_imagep pImage; + mng_retcode iRetcode = MNG_NOERROR; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_NEXT_LAYER, MNG_LC_START); +#endif + +#ifndef MNG_SKIPCHUNK_FRAM + if (!pData->iBreakpoint) /* no previous break here ? */ + { /* interframe delay required ? */ + if ((pData->eImagetype == mng_it_mng) && (pData->iLayerseq) && + ((pData->iFramemode == 1) || (pData->iFramemode == 3))) + iRetcode = interframe_delay (pData); + else + pData->iFramedelay = pData->iNextdelay; + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif + + if (!pData->bTimerset) /* timer still off ? */ + { + if (!pData->iLayerseq) /* restore background for the very first layer ? */ + { /* wait till IDAT/JDAT for PNGs & JNGs !!! */ + if ((pData->eImagetype == mng_it_png) || (pData->eImagetype == mng_it_jng)) + pData->bRestorebkgd = MNG_TRUE; + else + { /* for MNG we do it right away */ + iRetcode = load_bkgdlayer (pData); + pData->iLayerseq++; /* and it counts as a layer then ! */ + } + } +#ifndef MNG_SKIPCHUNK_FRAM + else + if (pData->iFramemode == 3) /* restore background for each layer ? */ + iRetcode = load_bkgdlayer (pData); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* processing a delta-image ? */ + pImage = (mng_imagep)pData->pDeltaImage; + else +#endif + pImage = (mng_imagep)pData->pCurrentobj; + + if (!pImage) /* not an active object ? */ + pImage = (mng_imagep)pData->pObjzero; + /* determine display rectangle */ + pData->iDestl = MAX_COORD ((mng_int32)0, pImage->iPosx); + pData->iDestt = MAX_COORD ((mng_int32)0, pImage->iPosy); + /* is it a valid buffer ? */ + if ((pImage->pImgbuf->iWidth) && (pImage->pImgbuf->iHeight)) + { + pData->iDestr = MIN_COORD ((mng_int32)pData->iWidth, + pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth ); + pData->iDestb = MIN_COORD ((mng_int32)pData->iHeight, + pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight); + } + else /* it's a single image ! */ + { + pData->iDestr = MIN_COORD ((mng_int32)pData->iWidth, + (mng_int32)pData->iDatawidth ); + pData->iDestb = MIN_COORD ((mng_int32)pData->iHeight, + (mng_int32)pData->iDataheight); + } + +#ifndef MNG_SKIPCHUNK_FRAM + if (pData->bFrameclipping) /* frame clipping specified ? */ + { + pData->iDestl = MAX_COORD (pData->iDestl, pData->iFrameclipl); + pData->iDestt = MAX_COORD (pData->iDestt, pData->iFrameclipt); + pData->iDestr = MIN_COORD (pData->iDestr, pData->iFrameclipr); + pData->iDestb = MIN_COORD (pData->iDestb, pData->iFrameclipb); + } +#endif + + if (pImage->bClipped) /* is the image clipped itself ? */ + { + pData->iDestl = MAX_COORD (pData->iDestl, pImage->iClipl); + pData->iDestt = MAX_COORD (pData->iDestt, pImage->iClipt); + pData->iDestr = MIN_COORD (pData->iDestr, pImage->iClipr); + pData->iDestb = MIN_COORD (pData->iDestb, pImage->iClipb); + } + /* determine source starting point */ + pData->iSourcel = MAX_COORD ((mng_int32)0, pData->iDestl - pImage->iPosx); + pData->iSourcet = MAX_COORD ((mng_int32)0, pData->iDestt - pImage->iPosy); + + if ((pImage->pImgbuf->iWidth) && (pImage->pImgbuf->iHeight)) + { /* and maximum size */ + pData->iSourcer = MIN_COORD ((mng_int32)pImage->pImgbuf->iWidth, + pData->iSourcel + pData->iDestr - pData->iDestl); + pData->iSourceb = MIN_COORD ((mng_int32)pImage->pImgbuf->iHeight, + pData->iSourcet + pData->iDestb - pData->iDestt); + } + else /* it's a single image ! */ + { + pData->iSourcer = pData->iSourcel + pData->iDestr - pData->iDestl; + pData->iSourceb = pData->iSourcet + pData->iDestb - pData->iDestt; + } + + pData->iLayerseq++; /* count the layer ! */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_NEXT_LAYER, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_display_image (mng_datap pData, + mng_imagep pImage, + mng_bool bLayeradvanced) +{ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_IMAGE, MNG_LC_START); +#endif + /* actively running ? */ +#ifndef MNG_SKIPCHUNK_MAGN + if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping)) + { + if ( (!pData->iBreakpoint) && /* needs magnification ? */ + ( (pImage->iMAGN_MethodX) || (pImage->iMAGN_MethodY) ) ) + { + iRetcode = mng_magnify_imageobject (pData, pImage); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } +#endif + + pData->pRetrieveobj = pImage; /* so retrieve-row and color-correction can find it */ + + if (!bLayeradvanced) /* need to advance the layer ? */ + { + mng_imagep pSave = pData->pCurrentobj; + pData->pCurrentobj = pImage; + next_layer (pData); /* advance to next layer */ + pData->pCurrentobj = pSave; + } + /* need to restore the background ? */ + if ((!pData->bTimerset) && (pData->bRestorebkgd)) + { + mng_imagep pSave = pData->pCurrentobj; + pData->pCurrentobj = pImage; + pData->bRestorebkgd = MNG_FALSE; + iRetcode = load_bkgdlayer (pData); + pData->pCurrentobj = pSave; + + if (iRetcode) /* on error bail out */ + return iRetcode; + + pData->iLayerseq++; /* and it counts as a layer then ! */ + } + /* actively running ? */ + if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping)) + { + if (!pData->bTimerset) /* all systems still go ? */ + { + pData->iBreakpoint = 0; /* let's make absolutely sure... */ + /* anything to display ? */ + if ((pData->iDestr >= pData->iDestl) && (pData->iDestb >= pData->iDestt)) + { + mng_int32 iY; + + set_display_routine (pData); /* determine display routine */ + /* and image-buffer retrieval routine */ + switch (pImage->pImgbuf->iColortype) + { + case 0 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_g16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_g8; + + pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS); + break; + } + + case 2 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8; + + pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS); + break; + } + + + case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8; + pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS); + break; + } + + + case 4 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8; + + pData->bIsOpaque = MNG_FALSE; + break; + } + + + case 6 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; + + pData->bIsOpaque = MNG_FALSE; + break; + } + + case 8 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_g16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_g8; + + pData->bIsOpaque = MNG_TRUE; + break; + } + + case 10 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8; + + pData->bIsOpaque = MNG_TRUE; + break; + } + + + case 12 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8; + + pData->bIsOpaque = MNG_FALSE; + break; + } + + + case 14 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; + + pData->bIsOpaque = MNG_FALSE; + break; + } + + } + + pData->iPass = -1; /* these are the object's dimensions now */ + pData->iRow = pData->iSourcet; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pImage->pImgbuf->iWidth; + pData->iRowsize = pData->iRowsamples << 2; + pData->bIsRGBA16 = MNG_FALSE; + /* adjust for 16-bit object ? */ +#ifndef MNG_NO_16BIT_SUPPORT + if (pImage->pImgbuf->iBitdepth > 8) + { + pData->bIsRGBA16 = MNG_TRUE; + pData->iRowsize = pData->iRowsamples << 3; + } +#endif + + pData->fCorrectrow = MNG_NULL; /* default no color-correction */ + +#ifdef MNG_NO_CMS + iRetcode = MNG_NOERROR; +#else +#if defined(MNG_FULL_CMS) /* determine color-management routine */ + iRetcode = mng_init_full_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); +#elif defined(MNG_GAMMA_ONLY) + iRetcode = mng_init_gamma_only (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); +#elif defined(MNG_APP_CMS) + iRetcode = mng_init_app_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); +#endif + if (iRetcode) /* on error bail out */ + return iRetcode; +#endif /* MNG_NO_CMS */ + /* get a temporary row-buffer */ + MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize); + + iY = pData->iSourcet; /* this is where we start */ + + while ((!iRetcode) && (iY < pData->iSourceb)) + { /* get a row */ + iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData); + /* color correction ? */ + if ((!iRetcode) && (pData->fCorrectrow)) + iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData); + + if (!iRetcode) /* so... display it */ + iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData); + + if (!iRetcode) /* adjust variables for next row */ + iRetcode = mng_next_row (pData); + + iY++; /* and next line */ + } + /* drop the temporary row-buffer */ + MNG_FREE (pData, pData->pRGBArow, pData->iRowsize); + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#if defined(MNG_FULL_CMS) /* cleanup cms stuff */ + iRetcode = mng_clear_cms (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; +#endif + } + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_IMAGE, MNG_LC_END); +#endif + + return MNG_NOERROR; /* whehehe, this is good ! */ +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode mng_execute_delta_image (mng_datap pData, + mng_imagep pTarget, + mng_imagep pDelta) +{ + mng_imagedatap pBuftarget = pTarget->pImgbuf; + mng_imagedatap pBufdelta = pDelta->pImgbuf; + mng_uint32 iY; + mng_retcode iRetcode; + mng_ptr pSaveRGBA; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_EXECUTE_DELTA_IMAGE, MNG_LC_START); +#endif + /* actively running ? */ + if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping)) + { + if (pBufdelta->bHasPLTE) /* palette in delta ? */ + { + mng_uint32 iX; + /* new palette larger than old one ? */ + if ((!pBuftarget->bHasPLTE) || (pBuftarget->iPLTEcount < pBufdelta->iPLTEcount)) + pBuftarget->iPLTEcount = pBufdelta->iPLTEcount; + /* it's definitely got a PLTE now */ + pBuftarget->bHasPLTE = MNG_TRUE; + + for (iX = 0; iX < pBufdelta->iPLTEcount; iX++) + { + pBuftarget->aPLTEentries[iX].iRed = pBufdelta->aPLTEentries[iX].iRed; + pBuftarget->aPLTEentries[iX].iGreen = pBufdelta->aPLTEentries[iX].iGreen; + pBuftarget->aPLTEentries[iX].iBlue = pBufdelta->aPLTEentries[iX].iBlue; + } + } + + if (pBufdelta->bHasTRNS) /* cheap transparency in delta ? */ + { + switch (pData->iColortype) /* drop it into the target */ + { + case 0: { /* gray */ + pBuftarget->iTRNSgray = pBufdelta->iTRNSgray; + pBuftarget->iTRNSred = 0; + pBuftarget->iTRNSgreen = 0; + pBuftarget->iTRNSblue = 0; + pBuftarget->iTRNScount = 0; + break; + } + case 2: { /* rgb */ + pBuftarget->iTRNSgray = 0; + pBuftarget->iTRNSred = pBufdelta->iTRNSred; + pBuftarget->iTRNSgreen = pBufdelta->iTRNSgreen; + pBuftarget->iTRNSblue = pBufdelta->iTRNSblue; + pBuftarget->iTRNScount = 0; + break; + } + case 3: { /* indexed */ + pBuftarget->iTRNSgray = 0; + pBuftarget->iTRNSred = 0; + pBuftarget->iTRNSgreen = 0; + pBuftarget->iTRNSblue = 0; + /* existing range smaller than new one ? */ + if ((!pBuftarget->bHasTRNS) || (pBuftarget->iTRNScount < pBufdelta->iTRNScount)) + pBuftarget->iTRNScount = pBufdelta->iTRNScount; + + MNG_COPY (pBuftarget->aTRNSentries, pBufdelta->aTRNSentries, pBufdelta->iTRNScount); + break; + } + } + + pBuftarget->bHasTRNS = MNG_TRUE; /* tell it it's got a tRNS now */ + } + +#ifndef MNG_SKIPCHUNK_bKGD + if (pBufdelta->bHasBKGD) /* bkgd in source ? */ + { /* drop it onto the target */ + pBuftarget->bHasBKGD = MNG_TRUE; + pBuftarget->iBKGDindex = pBufdelta->iBKGDindex; + pBuftarget->iBKGDgray = pBufdelta->iBKGDgray; + pBuftarget->iBKGDred = pBufdelta->iBKGDred; + pBuftarget->iBKGDgreen = pBufdelta->iBKGDgreen; + pBuftarget->iBKGDblue = pBufdelta->iBKGDblue; + } +#endif + + if (pBufdelta->bHasGAMA) /* gamma in source ? */ + { + pBuftarget->bHasGAMA = MNG_TRUE; /* drop it onto the target */ + pBuftarget->iGamma = pBufdelta->iGamma; + } + +#ifndef MNG_SKIPCHUNK_cHRM + if (pBufdelta->bHasCHRM) /* chroma in delta ? */ + { /* drop it onto the target */ + pBuftarget->bHasCHRM = MNG_TRUE; + pBuftarget->iWhitepointx = pBufdelta->iWhitepointx; + pBuftarget->iWhitepointy = pBufdelta->iWhitepointy; + pBuftarget->iPrimaryredx = pBufdelta->iPrimaryredx; + pBuftarget->iPrimaryredy = pBufdelta->iPrimaryredy; + pBuftarget->iPrimarygreenx = pBufdelta->iPrimarygreenx; + pBuftarget->iPrimarygreeny = pBufdelta->iPrimarygreeny; + pBuftarget->iPrimarybluex = pBufdelta->iPrimarybluex; + pBuftarget->iPrimarybluey = pBufdelta->iPrimarybluey; + } +#endif + +#ifndef MNG_SKIPCHUNK_sRGB + if (pBufdelta->bHasSRGB) /* sRGB in delta ? */ + { /* drop it onto the target */ + pBuftarget->bHasSRGB = MNG_TRUE; + pBuftarget->iRenderingintent = pBufdelta->iRenderingintent; + } +#endif + +#ifndef MNG_SKIPCHUNK_iCCP + if (pBufdelta->bHasICCP) /* ICC profile in delta ? */ + { + pBuftarget->bHasICCP = MNG_TRUE; /* drop it onto the target */ + + if (pBuftarget->pProfile) /* profile existed ? */ + MNG_FREEX (pData, pBuftarget->pProfile, pBuftarget->iProfilesize); + /* allocate a buffer & copy it */ + MNG_ALLOC (pData, pBuftarget->pProfile, pBufdelta->iProfilesize); + MNG_COPY (pBuftarget->pProfile, pBufdelta->pProfile, pBufdelta->iProfilesize); + /* store its length as well */ + pBuftarget->iProfilesize = pBufdelta->iProfilesize; + } +#endif + /* need to execute delta pixels ? */ + if ((!pData->bDeltaimmediate) && (pData->iDeltatype != MNG_DELTATYPE_NOCHANGE)) + { + pData->fScalerow = MNG_NULL; /* not needed by default */ + + switch (pBufdelta->iBitdepth) /* determine scaling routine */ + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { + switch (pBuftarget->iBitdepth) + { + case 2 : { pData->fScalerow = (mng_fptr)mng_scale_g1_g2; break; } + case 4 : { pData->fScalerow = (mng_fptr)mng_scale_g1_g4; break; } + + case 8 : { pData->fScalerow = (mng_fptr)mng_scale_g1_g8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fScalerow = (mng_fptr)mng_scale_g1_g16; break; } +#endif + } + break; + } + + case 2 : { + switch (pBuftarget->iBitdepth) + { + case 1 : { pData->fScalerow = (mng_fptr)mng_scale_g2_g1; break; } + case 4 : { pData->fScalerow = (mng_fptr)mng_scale_g2_g4; break; } + case 8 : { pData->fScalerow = (mng_fptr)mng_scale_g2_g8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fScalerow = (mng_fptr)mng_scale_g2_g16; break; } +#endif + } + break; + } + + case 4 : { + switch (pBuftarget->iBitdepth) + { + case 1 : { pData->fScalerow = (mng_fptr)mng_scale_g4_g1; break; } + case 2 : { pData->fScalerow = (mng_fptr)mng_scale_g4_g2; break; } + case 8 : { pData->fScalerow = (mng_fptr)mng_scale_g4_g8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fScalerow = (mng_fptr)mng_scale_g4_g16; break; } +#endif + } + break; + } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + + case 8 : { + switch (pBufdelta->iColortype) + { + case 0 : ; + case 3 : ; + case 8 : { + switch (pBuftarget->iBitdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { pData->fScalerow = (mng_fptr)mng_scale_g8_g1; break; } + case 2 : { pData->fScalerow = (mng_fptr)mng_scale_g8_g2; break; } + case 4 : { pData->fScalerow = (mng_fptr)mng_scale_g8_g4; break; } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fScalerow = (mng_fptr)mng_scale_g8_g16; break; } +#endif + } + break; + } + case 2 : ; + case 10 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pBuftarget->iBitdepth == 16) + pData->fScalerow = (mng_fptr)mng_scale_rgb8_rgb16; +#endif + break; + } + case 4 : ; + case 12 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pBuftarget->iBitdepth == 16) + pData->fScalerow = (mng_fptr)mng_scale_ga8_ga16; +#endif + break; + } + case 6 : ; + case 14 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pBuftarget->iBitdepth == 16) + pData->fScalerow = (mng_fptr)mng_scale_rgba8_rgba16; +#endif + break; + } + } + break; + } + +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + switch (pBufdelta->iColortype) + { + case 0 : ; + case 3 : ; + case 8 : { + switch (pBuftarget->iBitdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { pData->fScalerow = (mng_fptr)mng_scale_g16_g1; break; } + case 2 : { pData->fScalerow = (mng_fptr)mng_scale_g16_g2; break; } + case 4 : { pData->fScalerow = (mng_fptr)mng_scale_g16_g4; break; } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { pData->fScalerow = (mng_fptr)mng_scale_g16_g8; break; } + } + break; + } + case 2 : ; + case 10 : { + if (pBuftarget->iBitdepth == 8) + pData->fScalerow = (mng_fptr)mng_scale_rgb16_rgb8; + break; + } + case 4 : ; + case 12 : { + if (pBuftarget->iBitdepth == 8) + pData->fScalerow = (mng_fptr)mng_scale_ga16_ga8; + break; + } + case 6 : ; + case 14 : { + if (pBuftarget->iBitdepth == 8) + pData->fScalerow = (mng_fptr)mng_scale_rgba16_rgba8; + break; + } + } + break; + } +#endif + + } + + pData->fDeltarow = MNG_NULL; /* let's assume there's nothing to do */ + + switch (pBuftarget->iColortype) /* determine delta processing routine */ + { + case 0 : ; + case 8 : { /* gray */ + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3) || + (pBufdelta->iColortype == 8)) + { + switch (pBuftarget->iBitdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { pData->fDeltarow = (mng_fptr)mng_delta_g1_g1; break; } + case 2 : { pData->fDeltarow = (mng_fptr)mng_delta_g2_g2; break; } + case 4 : { pData->fDeltarow = (mng_fptr)mng_delta_g4_g4; break; } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_g8_g8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_g16_g16; break; } +#endif + } + } + } + + break; + } + + case 2 : ; + case 10 : { /* rgb */ + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + if ((pBufdelta->iColortype == 2) || (pBufdelta->iColortype == 10)) + { + switch (pBuftarget->iBitdepth) + { + case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_rgb8_rgb8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_rgb16_rgb16; break; } +#endif + } + } + } + + break; + } + + case 3 : { /* indexed; abuse gray routines */ + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3)) + { + switch (pBuftarget->iBitdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { pData->fDeltarow = (mng_fptr)mng_delta_g1_g1; break; } + case 2 : { pData->fDeltarow = (mng_fptr)mng_delta_g2_g2; break; } + case 4 : { pData->fDeltarow = (mng_fptr)mng_delta_g4_g4; break; } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_g8_g8; break; } + } + } + } + + break; + } + + case 4 : ; + case 12 : { /* gray + alpha */ + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + if ((pBufdelta->iColortype == 4) || (pBufdelta->iColortype == 12)) + { + switch (pBuftarget->iBitdepth) + { + case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_ga8_ga8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_ga16_ga16; break; } +#endif + } + } + } + else + if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) ) + { + if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3) || + (pBufdelta->iColortype == 8)) + { + switch (pBuftarget->iBitdepth) + { + case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_ga8_g8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_ga16_g16; break; } +#endif + } + } + } + else + if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) ) + { + if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3)) + { + switch (pBuftarget->iBitdepth) + { + case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_ga8_a8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_ga16_a16; break; } +#endif + } + } + } + + break; + } + + case 6 : ; + case 14 : { /* rgb + alpha */ + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + if ((pBufdelta->iColortype == 6) || (pBufdelta->iColortype == 14)) + { + switch (pBuftarget->iBitdepth) + { + case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba8_rgba8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba16_rgba16; break; } +#endif + } + } + } + else + if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) ) + { + if ((pBufdelta->iColortype == 2) || (pBufdelta->iColortype == 10)) + { + switch (pBuftarget->iBitdepth) + { + case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba8_rgb8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba16_rgb16; break; } +#endif + } + } + } + else + if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) ) + { + if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3)) + { + switch (pBuftarget->iBitdepth) + { + case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba8_a8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba16_a16; break; } +#endif + } + } + } + + break; + } + + } + + if (pData->fDeltarow) /* do we need to take action ? */ + { + pData->iPass = -1; /* setup row dimensions and stuff */ + pData->iRow = pData->iDeltaBlocky; + pData->iRowinc = 1; + pData->iCol = pData->iDeltaBlockx; + pData->iColinc = 1; + pData->iRowsamples = pBufdelta->iWidth; + pData->iRowsize = pBuftarget->iRowsize; + /* indicate where to retrieve & where to store */ + pData->pRetrieveobj = (mng_objectp)pDelta; + pData->pStoreobj = (mng_objectp)pTarget; + + pSaveRGBA = pData->pRGBArow; /* save current temp-buffer! */ + /* get a temporary row-buffer */ + MNG_ALLOC (pData, pData->pRGBArow, (pBufdelta->iRowsize << 1)); + + iY = 0; /* this is where we start */ + iRetcode = MNG_NOERROR; /* still oke for now */ + + while ((!iRetcode) && (iY < pBufdelta->iHeight)) + { /* get a row */ + mng_uint8p pWork = pBufdelta->pImgdata + (iY * pBufdelta->iRowsize); + + MNG_COPY (pData->pRGBArow, pWork, pBufdelta->iRowsize); + + if (pData->fScalerow) /* scale it (if necessary) */ + iRetcode = ((mng_scalerow)pData->fScalerow) (pData); + + if (!iRetcode) /* and... execute it */ + iRetcode = ((mng_deltarow)pData->fDeltarow) (pData); + + if (!iRetcode) /* adjust variables for next row */ + iRetcode = mng_next_row (pData); + + iY++; /* and next line */ + } + /* drop the temporary row-buffer */ + MNG_FREE (pData, pData->pRGBArow, (pBufdelta->iRowsize << 1)); + pData->pRGBArow = pSaveRGBA; /* restore saved temp-buffer! */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } + else + MNG_ERROR (pData, MNG_INVALIDDELTA); + + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_EXECUTE_DELTA_IMAGE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_DELTA_PNG */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SAVE +MNG_LOCAL mng_retcode save_state (mng_datap pData) +{ + mng_savedatap pSave; + mng_imagep pImage; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SAVE_STATE, MNG_LC_START); +#endif + + if (pData->pSavedata) /* sanity check */ + MNG_ERROR (pData, MNG_INTERNALERROR); + /* get a buffer for saving */ + MNG_ALLOC (pData, pData->pSavedata, sizeof (mng_savedata)); + + pSave = pData->pSavedata; /* address it more directly */ + /* and copy global data from the main struct */ +#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) + pSave->bHasglobalPLTE = pData->bHasglobalPLTE; + pSave->bHasglobalTRNS = pData->bHasglobalTRNS; + pSave->bHasglobalGAMA = pData->bHasglobalGAMA; + pSave->bHasglobalCHRM = pData->bHasglobalCHRM; + pSave->bHasglobalSRGB = pData->bHasglobalSRGB; + pSave->bHasglobalICCP = pData->bHasglobalICCP; + pSave->bHasglobalBKGD = pData->bHasglobalBKGD; +#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ + +#ifndef MNG_SKIPCHUNK_BACK + pSave->iBACKred = pData->iBACKred; + pSave->iBACKgreen = pData->iBACKgreen; + pSave->iBACKblue = pData->iBACKblue; + pSave->iBACKmandatory = pData->iBACKmandatory; + pSave->iBACKimageid = pData->iBACKimageid; + pSave->iBACKtile = pData->iBACKtile; +#endif + +#ifndef MNG_SKIPCHUNK_FRAM + pSave->iFRAMmode = pData->iFRAMmode; + pSave->iFRAMdelay = pData->iFRAMdelay; + pSave->iFRAMtimeout = pData->iFRAMtimeout; + pSave->bFRAMclipping = pData->bFRAMclipping; + pSave->iFRAMclipl = pData->iFRAMclipl; + pSave->iFRAMclipr = pData->iFRAMclipr; + pSave->iFRAMclipt = pData->iFRAMclipt; + pSave->iFRAMclipb = pData->iFRAMclipb; +#endif + + pSave->iGlobalPLTEcount = pData->iGlobalPLTEcount; + + MNG_COPY (pSave->aGlobalPLTEentries, pData->aGlobalPLTEentries, sizeof (mng_rgbpaltab)); + + pSave->iGlobalTRNSrawlen = pData->iGlobalTRNSrawlen; + MNG_COPY (pSave->aGlobalTRNSrawdata, pData->aGlobalTRNSrawdata, 256); + + pSave->iGlobalGamma = pData->iGlobalGamma; + +#ifndef MNG_SKIPCHUNK_cHRM + pSave->iGlobalWhitepointx = pData->iGlobalWhitepointx; + pSave->iGlobalWhitepointy = pData->iGlobalWhitepointy; + pSave->iGlobalPrimaryredx = pData->iGlobalPrimaryredx; + pSave->iGlobalPrimaryredy = pData->iGlobalPrimaryredy; + pSave->iGlobalPrimarygreenx = pData->iGlobalPrimarygreenx; + pSave->iGlobalPrimarygreeny = pData->iGlobalPrimarygreeny; + pSave->iGlobalPrimarybluex = pData->iGlobalPrimarybluex; + pSave->iGlobalPrimarybluey = pData->iGlobalPrimarybluey; +#endif + +#ifndef MNG_SKIPCHUNK_sRGB + pSave->iGlobalRendintent = pData->iGlobalRendintent; +#endif + +#ifndef MNG_SKIPCHUNK_iCCP + pSave->iGlobalProfilesize = pData->iGlobalProfilesize; + + if (pSave->iGlobalProfilesize) /* has a profile ? */ + { /* then copy that ! */ + MNG_ALLOC (pData, pSave->pGlobalProfile, pSave->iGlobalProfilesize); + MNG_COPY (pSave->pGlobalProfile, pData->pGlobalProfile, pSave->iGlobalProfilesize); + } +#endif + +#ifndef MNG_SKIPCHUNK_bKGD + pSave->iGlobalBKGDred = pData->iGlobalBKGDred; + pSave->iGlobalBKGDgreen = pData->iGlobalBKGDgreen; + pSave->iGlobalBKGDblue = pData->iGlobalBKGDblue; +#endif + + /* freeze current image objects */ + pImage = (mng_imagep)pData->pFirstimgobj; + + while (pImage) + { /* freeze the object AND its buffer */ + pImage->bFrozen = MNG_TRUE; + pImage->pImgbuf->bFrozen = MNG_TRUE; + /* neeeext */ + pImage = (mng_imagep)pImage->sHeader.pNext; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SAVE_STATE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_reset_objzero (mng_datap pData) +{ + mng_imagep pImage = (mng_imagep)pData->pObjzero; + mng_retcode iRetcode = mng_reset_object_details (pData, pImage, 0, 0, 0, + 0, 0, 0, 0, MNG_TRUE); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + pImage->bVisible = MNG_TRUE; + pImage->bViewable = MNG_TRUE; + pImage->iPosx = 0; + pImage->iPosy = 0; + pImage->bClipped = MNG_FALSE; + pImage->iClipl = 0; + pImage->iClipr = 0; + pImage->iClipt = 0; + pImage->iClipb = 0; +#ifndef MNG_SKIPCHUNK_MAGN + pImage->iMAGN_MethodX = 0; + pImage->iMAGN_MethodY = 0; + pImage->iMAGN_MX = 0; + pImage->iMAGN_MY = 0; + pImage->iMAGN_ML = 0; + pImage->iMAGN_MR = 0; + pImage->iMAGN_MT = 0; + pImage->iMAGN_MB = 0; +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode restore_state (mng_datap pData) +{ +#ifndef MNG_SKIPCHUNK_SAVE + mng_savedatap pSave; +#endif + mng_imagep pImage; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_STATE, MNG_LC_START); +#endif + /* restore object 0 status !!! */ + iRetcode = mng_reset_objzero (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* fresh cycle; fake no frames done yet */ + pData->bFramedone = MNG_FALSE; + +#ifndef MNG_SKIPCHUNK_SAVE + if (pData->pSavedata) /* do we have a saved state ? */ + { + pSave = pData->pSavedata; /* address it more directly */ + /* and copy it back to the main struct */ +#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) + pData->bHasglobalPLTE = pSave->bHasglobalPLTE; + pData->bHasglobalTRNS = pSave->bHasglobalTRNS; + pData->bHasglobalGAMA = pSave->bHasglobalGAMA; + pData->bHasglobalCHRM = pSave->bHasglobalCHRM; + pData->bHasglobalSRGB = pSave->bHasglobalSRGB; + pData->bHasglobalICCP = pSave->bHasglobalICCP; + pData->bHasglobalBKGD = pSave->bHasglobalBKGD; +#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ + +#ifndef MNG_SKIPCHUNK_BACK + pData->iBACKred = pSave->iBACKred; + pData->iBACKgreen = pSave->iBACKgreen; + pData->iBACKblue = pSave->iBACKblue; + pData->iBACKmandatory = pSave->iBACKmandatory; + pData->iBACKimageid = pSave->iBACKimageid; + pData->iBACKtile = pSave->iBACKtile; +#endif + +#ifndef MNG_SKIPCHUNK_FRAM + pData->iFRAMmode = pSave->iFRAMmode; +/* pData->iFRAMdelay = pSave->iFRAMdelay; */ + pData->iFRAMtimeout = pSave->iFRAMtimeout; + pData->bFRAMclipping = pSave->bFRAMclipping; + pData->iFRAMclipl = pSave->iFRAMclipl; + pData->iFRAMclipr = pSave->iFRAMclipr; + pData->iFRAMclipt = pSave->iFRAMclipt; + pData->iFRAMclipb = pSave->iFRAMclipb; + /* NOOOOOOOOOOOO */ +/* pData->iFramemode = pSave->iFRAMmode; + pData->iFramedelay = pSave->iFRAMdelay; + pData->iFrametimeout = pSave->iFRAMtimeout; + pData->bFrameclipping = pSave->bFRAMclipping; + pData->iFrameclipl = pSave->iFRAMclipl; + pData->iFrameclipr = pSave->iFRAMclipr; + pData->iFrameclipt = pSave->iFRAMclipt; + pData->iFrameclipb = pSave->iFRAMclipb; */ + +/* pData->iNextdelay = pSave->iFRAMdelay; */ + pData->iNextdelay = pData->iFramedelay; +#endif + + pData->iGlobalPLTEcount = pSave->iGlobalPLTEcount; + MNG_COPY (pData->aGlobalPLTEentries, pSave->aGlobalPLTEentries, sizeof (mng_rgbpaltab)); + + pData->iGlobalTRNSrawlen = pSave->iGlobalTRNSrawlen; + MNG_COPY (pData->aGlobalTRNSrawdata, pSave->aGlobalTRNSrawdata, 256); + + pData->iGlobalGamma = pSave->iGlobalGamma; + +#ifndef MNG_SKIPCHUNK_cHRM + pData->iGlobalWhitepointx = pSave->iGlobalWhitepointx; + pData->iGlobalWhitepointy = pSave->iGlobalWhitepointy; + pData->iGlobalPrimaryredx = pSave->iGlobalPrimaryredx; + pData->iGlobalPrimaryredy = pSave->iGlobalPrimaryredy; + pData->iGlobalPrimarygreenx = pSave->iGlobalPrimarygreenx; + pData->iGlobalPrimarygreeny = pSave->iGlobalPrimarygreeny; + pData->iGlobalPrimarybluex = pSave->iGlobalPrimarybluex; + pData->iGlobalPrimarybluey = pSave->iGlobalPrimarybluey; +#endif + + pData->iGlobalRendintent = pSave->iGlobalRendintent; + +#ifndef MNG_SKIPCHUNK_iCCP + pData->iGlobalProfilesize = pSave->iGlobalProfilesize; + + if (pData->iGlobalProfilesize) /* has a profile ? */ + { /* then copy that ! */ + MNG_ALLOC (pData, pData->pGlobalProfile, pData->iGlobalProfilesize); + MNG_COPY (pData->pGlobalProfile, pSave->pGlobalProfile, pData->iGlobalProfilesize); + } +#endif + +#ifndef MNG_SKIPCHUNK_bKGD + pData->iGlobalBKGDred = pSave->iGlobalBKGDred; + pData->iGlobalBKGDgreen = pSave->iGlobalBKGDgreen; + pData->iGlobalBKGDblue = pSave->iGlobalBKGDblue; +#endif + } + else /* no saved-data; so reset the lot */ +#endif /* SKIPCHUNK_SAVE */ + { +#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) + pData->bHasglobalPLTE = MNG_FALSE; + pData->bHasglobalTRNS = MNG_FALSE; + pData->bHasglobalGAMA = MNG_FALSE; + pData->bHasglobalCHRM = MNG_FALSE; + pData->bHasglobalSRGB = MNG_FALSE; + pData->bHasglobalICCP = MNG_FALSE; + pData->bHasglobalBKGD = MNG_FALSE; +#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ + +#ifndef MNG_SKIPCHUNK_TERM + if (!pData->bMisplacedTERM) /* backward compatible ugliness !!! */ + { + pData->iBACKred = 0; + pData->iBACKgreen = 0; + pData->iBACKblue = 0; + pData->iBACKmandatory = 0; + pData->iBACKimageid = 0; + pData->iBACKtile = 0; + } +#endif + +#ifndef MNG_SKIPCHUNK_FRAM + pData->iFRAMmode = 1; +/* pData->iFRAMdelay = 1; */ + pData->iFRAMtimeout = 0x7fffffffl; + pData->bFRAMclipping = MNG_FALSE; + pData->iFRAMclipl = 0; + pData->iFRAMclipr = 0; + pData->iFRAMclipt = 0; + pData->iFRAMclipb = 0; + /* NOOOOOOOOOOOO */ +/* pData->iFramemode = 1; + pData->iFramedelay = 1; + pData->iFrametimeout = 0x7fffffffl; + pData->bFrameclipping = MNG_FALSE; + pData->iFrameclipl = 0; + pData->iFrameclipr = 0; + pData->iFrameclipt = 0; + pData->iFrameclipb = 0; */ + +/* pData->iNextdelay = 1; */ + pData->iNextdelay = pData->iFramedelay; +#endif + + pData->iGlobalPLTEcount = 0; + + pData->iGlobalTRNSrawlen = 0; + + pData->iGlobalGamma = 0; + +#ifndef MNG_SKIPCHUNK_cHRM + pData->iGlobalWhitepointx = 0; + pData->iGlobalWhitepointy = 0; + pData->iGlobalPrimaryredx = 0; + pData->iGlobalPrimaryredy = 0; + pData->iGlobalPrimarygreenx = 0; + pData->iGlobalPrimarygreeny = 0; + pData->iGlobalPrimarybluex = 0; + pData->iGlobalPrimarybluey = 0; +#endif + + pData->iGlobalRendintent = 0; + +#ifndef MNG_SKIPCHUNK_iCCP + if (pData->iGlobalProfilesize) /* free a previous profile ? */ + MNG_FREE (pData, pData->pGlobalProfile, pData->iGlobalProfilesize); + + pData->iGlobalProfilesize = 0; +#endif + +#ifndef MNG_SKIPCHUNK_bKGD + pData->iGlobalBKGDred = 0; + pData->iGlobalBKGDgreen = 0; + pData->iGlobalBKGDblue = 0; +#endif + } + +#ifndef MNG_SKIPCHUNK_TERM + if (!pData->bMisplacedTERM) /* backward compatible ugliness !!! */ + { + pImage = (mng_imagep)pData->pFirstimgobj; + /* drop un-frozen image objects */ + while (pImage) + { + mng_imagep pNext = (mng_imagep)pImage->sHeader.pNext; + + if (!pImage->bFrozen) /* is it un-frozen ? */ + { + mng_imagep pPrev = (mng_imagep)pImage->sHeader.pPrev; + + if (pPrev) /* unlink it */ + pPrev->sHeader.pNext = pNext; + else + pData->pFirstimgobj = pNext; + + if (pNext) + pNext->sHeader.pPrev = pPrev; + else + pData->pLastimgobj = pPrev; + + if (pImage->pImgbuf->bFrozen) /* buffer frozen ? */ + { + if (pImage->pImgbuf->iRefcount < 2) + MNG_ERROR (pData, MNG_INTERNALERROR); + /* decrease ref counter */ + pImage->pImgbuf->iRefcount--; + /* just cleanup the object then */ + MNG_FREEX (pData, pImage, sizeof (mng_image)); + } + else + { /* free the image buffer */ + iRetcode = mng_free_imagedataobject (pData, pImage->pImgbuf); + /* and cleanup the object */ + MNG_FREEX (pData, pImage, sizeof (mng_image)); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } + + pImage = pNext; /* neeeext */ + } + } +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_STATE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ +/* * * */ +/* * General display processing routine * */ +/* * * */ +/* ************************************************************************** */ + +mng_retcode mng_process_display (mng_datap pData) +{ + mng_retcode iRetcode = MNG_NOERROR; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY, MNG_LC_START); +#endif + + if (!pData->iBreakpoint) /* not broken previously ? */ + { + if ((pData->iRequestframe) || (pData->iRequestlayer) || (pData->iRequesttime)) + { + pData->bSearching = MNG_TRUE; /* indicate we're searching */ + + iRetcode = clear_canvas (pData); /* make the canvas virgin black ?!? */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* let's start from the top, shall we */ + pData->pCurraniobj = pData->pFirstaniobj; + } + } + + do /* process the objects */ + { + if (pData->bSearching) /* clear timer-flag when searching !!! */ + pData->bTimerset = MNG_FALSE; + /* do we need to finish something first ? */ + if ((pData->iBreakpoint) && (pData->iBreakpoint < 99)) + { + switch (pData->iBreakpoint) /* return to broken display routine */ + { +#ifndef MNG_SKIPCHUNK_FRAM + case 1 : { iRetcode = mng_process_display_fram2 (pData); break; } +#endif +#ifndef MNG_SKIPCHUNK_SHOW + case 3 : ; /* same as 4 !!! */ + case 4 : { iRetcode = mng_process_display_show (pData); break; } +#endif +#ifndef MNG_SKIPCHUNK_CLON + case 5 : { iRetcode = mng_process_display_clon2 (pData); break; } +#endif +#ifndef MNG_SKIPCHUNK_MAGN + case 9 : { iRetcode = mng_process_display_magn2 (pData); break; } + case 10 : { iRetcode = mng_process_display_mend2 (pData); break; } +#endif +#ifndef MNG_SKIPCHUNK_PAST + case 11 : { iRetcode = mng_process_display_past2 (pData); break; } +#endif + default : MNG_ERROR (pData, MNG_INTERNALERROR); + } + } + else + { + if (pData->pCurraniobj) + iRetcode = ((mng_object_headerp)pData->pCurraniobj)->fProcess (pData, pData->pCurraniobj); + } + + if (!pData->bTimerset) /* reset breakpoint flag ? */ + pData->iBreakpoint = 0; + /* can we advance to next object ? */ + if ((!iRetcode) && (pData->pCurraniobj) && + (!pData->bTimerset) && (!pData->bSectionwait)) + { + pData->pCurraniobj = ((mng_object_headerp)pData->pCurraniobj)->pNext; + /* MEND processing to be done ? */ + if ((pData->eImagetype == mng_it_mng) && (!pData->pCurraniobj)) + iRetcode = mng_process_display_mend (pData); + + if (!pData->pCurraniobj) /* refresh after last image ? */ + pData->bNeedrefresh = MNG_TRUE; + } + + if (pData->bSearching) /* are we looking for something ? */ + { + if ((pData->iRequestframe) && (pData->iRequestframe <= pData->iFrameseq)) + { + pData->iRequestframe = 0; /* found the frame ! */ + pData->bSearching = MNG_FALSE; + } + else + if ((pData->iRequestlayer) && (pData->iRequestlayer <= pData->iLayerseq)) + { + pData->iRequestlayer = 0; /* found the layer ! */ + pData->bSearching = MNG_FALSE; + } + else + if ((pData->iRequesttime) && (pData->iRequesttime <= pData->iFrametime)) + { + pData->iRequesttime = 0; /* found the playtime ! */ + pData->bSearching = MNG_FALSE; + } + } + } /* until error or a break or no more objects */ + while ((!iRetcode) && (pData->pCurraniobj) && + (((pData->bRunning) && (!pData->bTimerset)) || (pData->bSearching)) && + (!pData->bSectionwait) && (!pData->bFreezing)); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* refresh needed ? */ + if ((!pData->bTimerset) && (pData->bNeedrefresh)) + { + iRetcode = mng_display_progressive_refresh (pData, 1); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + /* timer break ? */ + if ((pData->bTimerset) && (!pData->iBreakpoint)) + pData->iBreakpoint = 99; + else + if (!pData->bTimerset) + pData->iBreakpoint = 0; /* reset if no timer break */ + + if ((!pData->bTimerset) && (!pData->pCurraniobj)) + pData->bRunning = MNG_FALSE; /* all done now ! */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ +/* * * */ +/* * Chunk display processing routines * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT +png_imgtype mng_png_imgtype(mng_uint8 colortype, mng_uint8 bitdepth) +{ + png_imgtype ret; + switch (bitdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1: + { + png_imgtype imgtype[]={png_g1,png_none,png_none,png_idx1}; + ret=imgtype[colortype]; + break; + } + case 2: + { + png_imgtype imgtype[]={png_g2,png_none,png_none,png_idx2}; + ret=imgtype[colortype]; + break; + } + case 4: + { + png_imgtype imgtype[]={png_g4,png_none,png_none,png_idx4}; + ret=imgtype[colortype]; + break; + } +#endif + case 8: + { + png_imgtype imgtype[]={png_g8,png_none,png_rgb8,png_idx8,png_ga8, + png_none,png_rgba8}; + ret=imgtype[colortype]; + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16: + { + png_imgtype imgtype[]={png_g16,png_none,png_rgb16,png_none,png_ga16, + png_none,png_rgba16}; + ret=imgtype[colortype]; + break; + } +#endif + default: + ret=png_none; + break; + } + return (ret); +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ + +/* ************************************************************************** */ + +mng_retcode mng_process_display_ihdr (mng_datap pData) +{ /* address the current "object" if any */ + mng_imagep pImage = (mng_imagep)pData->pCurrentobj; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IHDR, MNG_LC_START); +#endif + + if (!pData->bHasDHDR) + { + pData->fInitrowproc = MNG_NULL; /* do nothing by default */ + pData->fDisplayrow = MNG_NULL; + pData->fCorrectrow = MNG_NULL; + pData->fStorerow = MNG_NULL; + pData->fProcessrow = MNG_NULL; + pData->fDifferrow = MNG_NULL; + pData->pStoreobj = MNG_NULL; + } + + if (!pData->iBreakpoint) /* not previously broken ? */ + { + mng_retcode iRetcode = MNG_NOERROR; + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* is a delta-image ? */ + { + if (pData->iDeltatype == MNG_DELTATYPE_REPLACE) + iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pDeltaImage, + pData->iDatawidth, pData->iDataheight, + pData->iBitdepth, pData->iColortype, + pData->iCompression, pData->iFilter, + pData->iInterlace, MNG_TRUE); + else + if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + ((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iBitdepth; + ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iBitdepth; + } + else + if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) ) + ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iBitdepth; + else + if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) ) + ((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iBitdepth; + + if (!iRetcode) + { /* process immediately if bitdepth & colortype are equal */ + pData->bDeltaimmediate = + (mng_bool)((pData->iBitdepth == ((mng_imagep)pData->pDeltaImage)->pImgbuf->iBitdepth ) && + (pData->iColortype == ((mng_imagep)pData->pDeltaImage)->pImgbuf->iColortype) ); + /* be sure to reset object 0 */ + iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pObjzero, + pData->iDatawidth, pData->iDataheight, + pData->iBitdepth, pData->iColortype, + pData->iCompression, pData->iFilter, + pData->iInterlace, MNG_TRUE); + } + } + else +#endif + { + if (pImage) /* update object buffer ? */ + iRetcode = mng_reset_object_details (pData, pImage, + pData->iDatawidth, pData->iDataheight, + pData->iBitdepth, pData->iColortype, + pData->iCompression, pData->iFilter, + pData->iInterlace, MNG_TRUE); + else + iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pObjzero, + pData->iDatawidth, pData->iDataheight, + pData->iBitdepth, pData->iColortype, + pData->iCompression, pData->iFilter, + pData->iInterlace, MNG_TRUE); + } + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + +#ifndef MNG_NO_DELTA_PNG + if (!pData->bHasDHDR) +#endif + { + if (pImage) /* real object ? */ + pData->pStoreobj = pImage; /* tell the row routines */ + else /* otherwise use object 0 */ + pData->pStoreobj = pData->pObjzero; + +#if !defined(MNG_INCLUDE_MPNG_PROPOSAL) && !defined(MNG_INCLUDE_ANG_PROPOSAL) + if ( /* display "on-the-fly" ? */ +#ifndef MNG_SKIPCHUNK_MAGN + (((mng_imagep)pData->pStoreobj)->iMAGN_MethodX == 0) && + (((mng_imagep)pData->pStoreobj)->iMAGN_MethodY == 0) && +#endif + ( (pData->eImagetype == mng_it_png ) || + (((mng_imagep)pData->pStoreobj)->bVisible) ) ) + { + next_layer (pData); /* that's a new layer then ! */ + + if (pData->bTimerset) /* timer break ? */ + pData->iBreakpoint = 2; + else + { + pData->iBreakpoint = 0; + /* anything to display ? */ + if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt)) + set_display_routine (pData); /* then determine display routine */ + } + } +#endif + } + + if (!pData->bTimerset) /* no timer break ? */ + { +#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT + pData->fInitrowproc = (mng_fptr)mng_init_rowproc; + pData->ePng_imgtype=mng_png_imgtype(pData->iColortype,pData->iBitdepth); +#else + switch (pData->iColortype) /* determine row initialization routine */ + { + case 0 : { /* gray */ + switch (pData->iBitdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g1_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g1_i; + + break; + } + case 2 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g2_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g2_i; + + break; + } + case 4 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g4_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g4_i; + break; + } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g8_i; + + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g16_i; + + break; + } +#endif + } + + break; + } + case 2 : { /* rgb */ + switch (pData->iBitdepth) + { + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i; + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i; + + break; + } +#endif + } + + break; + } + case 3 : { /* indexed */ + switch (pData->iBitdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx1_i; + + break; + } + case 2 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx2_i; + + break; + } + case 4 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx4_i; + + break; + } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx8_i; + + break; + } + } + + break; + } + case 4 : { /* gray+alpha */ + switch (pData->iBitdepth) + { + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_ga8_i; + + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_ga16_i; + break; + } +#endif + } + + break; + } + case 6 : { /* rgb+alpha */ + switch (pData->iBitdepth) + { + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i; + + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i; + + break; + } +#endif + } + + break; + } + } +#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ + + pData->iFilterofs = 0; /* determine filter characteristics */ + pData->iLevel0 = 0; /* default levels */ + pData->iLevel1 = 0; + pData->iLevel2 = 0; + pData->iLevel3 = 0; + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + { + switch (pData->iColortype) + { + case 0 : { + if (pData->iBitdepth <= 8) + pData->iFilterofs = 1; + else + pData->iFilterofs = 2; + + break; + } + case 2 : { + if (pData->iBitdepth <= 8) + pData->iFilterofs = 3; + else + pData->iFilterofs = 6; + + break; + } + case 3 : { + pData->iFilterofs = 1; + break; + } + case 4 : { + if (pData->iBitdepth <= 8) + pData->iFilterofs = 2; + else + pData->iFilterofs = 4; + + break; + } + case 6 : { + if (pData->iBitdepth <= 8) + pData->iFilterofs = 4; + else + pData->iFilterofs = 8; + + break; + } + } + } +#endif + +#ifdef FILTER193 /* no adaptive filtering ? */ + if (pData->iFilter == MNG_FILTER_NOFILTER) + pData->iPixelofs = pData->iFilterofs; + else +#endif + pData->iPixelofs = pData->iFilterofs + 1; + + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_MPNG_PROPOSAL +mng_retcode mng_process_display_mpng (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MPNG, MNG_LC_START); +#endif + + pData->iAlphadepth = 8; /* assume transparency !! */ + + if (pData->fProcessheader) /* inform the app (creating the output canvas) ? */ + { + pData->iWidth = ((mng_mpng_objp)pData->pMPNG)->iFramewidth; + pData->iHeight = ((mng_mpng_objp)pData->pMPNG)->iFrameheight; + + if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) + MNG_ERROR (pData, MNG_APPMISCERROR); + } + + next_layer (pData); /* first mPNG layer then ! */ + pData->bTimerset = MNG_FALSE; + pData->iBreakpoint = 0; + + if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt)) + set_display_routine (pData); /* then determine display routine */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MPNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ANG_PROPOSAL +mng_retcode mng_process_display_ang (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_ANG, MNG_LC_START); +#endif + + if (pData->fProcessheader) /* inform the app (creating the output canvas) ? */ + { + if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) + MNG_ERROR (pData, MNG_APPMISCERROR); + } + + next_layer (pData); /* first mPNG layer then ! */ + pData->bTimerset = MNG_FALSE; + pData->iBreakpoint = 0; + + if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt)) + set_display_routine (pData); /* then determine display routine */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_ANG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +mng_retcode mng_process_display_idat (mng_datap pData, + mng_uint32 iRawlen, + mng_uint8p pRawdata) +#else +mng_retcode mng_process_display_idat (mng_datap pData) +#endif +{ + mng_retcode iRetcode = MNG_NOERROR; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IDAT, MNG_LC_START); +#endif + +#if defined(MNG_INCLUDE_MPNG_PROPOSAL) || defined(MNG_INCLUDE_ANG_PROPOSAL) + if ((pData->eImagetype == mng_it_png) && (pData->iLayerseq <= 0)) + { + if (pData->fProcessheader) /* inform the app (creating the output canvas) ? */ + if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight)) + MNG_ERROR (pData, MNG_APPMISCERROR); + + next_layer (pData); /* first regular PNG layer then ! */ + pData->bTimerset = MNG_FALSE; + pData->iBreakpoint = 0; + + if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt)) + set_display_routine (pData); /* then determine display routine */ + } +#endif + + if (pData->bRestorebkgd) /* need to restore the background ? */ + { + pData->bRestorebkgd = MNG_FALSE; + iRetcode = load_bkgdlayer (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + pData->iLayerseq++; /* and it counts as a layer then ! */ + } + + if (pData->fInitrowproc) /* need to initialize row processing? */ + { + iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData); + pData->fInitrowproc = MNG_NULL; /* only call this once !!! */ + } + + if ((!iRetcode) && (!pData->bInflating)) + /* initialize inflate */ + iRetcode = mngzlib_inflateinit (pData); + + if (!iRetcode) /* all ok? then inflate, my man */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mngzlib_inflaterows (pData, iRawlen, pRawdata); +#else + iRetcode = mngzlib_inflaterows (pData, pData->iRawlen, pData->pRawdata); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IDAT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_process_display_iend (mng_datap pData) +{ + mng_retcode iRetcode, iRetcode2; + mng_bool bDodisplay = MNG_FALSE; + mng_bool bMagnify = MNG_FALSE; + mng_bool bCleanup = (mng_bool)(pData->iBreakpoint != 0); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IEND, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_JNG /* progressive+alpha JNG can be displayed now */ + if ( (pData->bHasJHDR ) && + ( (pData->bJPEGprogressive) || (pData->bJPEGprogressive2)) && + ( (pData->eImagetype == mng_it_jng ) || + (((mng_imagep)pData->pStoreobj)->bVisible) ) && + ( (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || + (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) ) + bDodisplay = MNG_TRUE; +#endif + +#ifndef MNG_SKIPCHUNK_MAGN + if ( (pData->pStoreobj) && /* on-the-fly magnification ? */ + ( (((mng_imagep)pData->pStoreobj)->iMAGN_MethodX) || + (((mng_imagep)pData->pStoreobj)->iMAGN_MethodY) ) ) + bMagnify = MNG_TRUE; +#endif + + if ((pData->bHasBASI) || /* was it a BASI stream */ + (bDodisplay) || /* or should we display the JNG */ +#ifndef MNG_SKIPCHUNK_MAGN + (bMagnify) || /* or should we magnify it */ +#endif + /* or did we get broken here last time ? */ + ((pData->iBreakpoint) && (pData->iBreakpoint != 8))) + { + mng_imagep pImage = (mng_imagep)pData->pCurrentobj; + + if (!pImage) /* or was it object 0 ? */ + pImage = (mng_imagep)pData->pObjzero; + /* display it now then ? */ + if ((pImage->bVisible) && (pImage->bViewable)) + { /* ok, so do it */ + iRetcode = mng_display_image (pData, pImage, bDodisplay); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + if (pData->bTimerset) /* timer break ? */ + pData->iBreakpoint = 6; + } + } +#ifndef MNG_NO_DELTA_PNG + else + if ((pData->bHasDHDR) || /* was it a DHDR stream */ + (pData->iBreakpoint == 8)) /* or did we get broken here last time ? */ + { + mng_imagep pImage = (mng_imagep)pData->pDeltaImage; + + if (!pData->iBreakpoint) + { /* perform the delta operations needed */ + iRetcode = mng_execute_delta_image (pData, pImage, (mng_imagep)pData->pObjzero); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + /* display it now then ? */ + if ((pImage->bVisible) && (pImage->bViewable)) + { /* ok, so do it */ + iRetcode = mng_display_image (pData, pImage, MNG_FALSE); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + if (pData->bTimerset) /* timer break ? */ + pData->iBreakpoint = 8; + } + } +#endif + + if (!pData->bTimerset) /* can we continue ? */ + { + pData->iBreakpoint = 0; /* clear this flag now ! */ + + +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + if (pData->eImagetype == mng_it_mpng) + { + pData->pCurraniobj = pData->pFirstaniobj; + } else +#endif +#ifdef MNG_INCLUDE_ANG_PROPOSAL + if (pData->eImagetype == mng_it_ang) + { + pData->pCurraniobj = pData->pFirstaniobj; + } else +#endif + { /* cleanup object 0 */ + mng_reset_object_details (pData, (mng_imagep)pData->pObjzero, + 0, 0, 0, 0, 0, 0, 0, MNG_TRUE); + } + + if (pData->bInflating) /* if we've been inflating */ + { /* cleanup row-processing, */ + iRetcode = mng_cleanup_rowproc (pData); + /* also cleanup inflate! */ + iRetcode2 = mngzlib_inflatefree (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + if (iRetcode2) + return iRetcode2; + } + +#ifdef MNG_INCLUDE_JNG + if (pData->bJPEGdecompress) /* if we've been decompressing JDAT */ + { /* cleanup row-processing, */ + iRetcode = mng_cleanup_rowproc (pData); + /* also cleanup decompress! */ + iRetcode2 = mngjpeg_decompressfree (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + if (iRetcode2) + return iRetcode2; + } + + if (pData->bJPEGdecompress2) /* if we've been decompressing JDAA */ + { /* cleanup row-processing, */ + iRetcode = mng_cleanup_rowproc (pData); + /* also cleanup decompress! */ + iRetcode2 = mngjpeg_decompressfree2 (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + if (iRetcode2) + return iRetcode2; + } +#endif + + if (bCleanup) /* if we got broken last time we need to cleanup */ + { + pData->bHasIHDR = MNG_FALSE; /* IEND signals the end for most ... */ + pData->bHasBASI = MNG_FALSE; + pData->bHasDHDR = MNG_FALSE; +#ifdef MNG_INCLUDE_JNG + pData->bHasJHDR = MNG_FALSE; + pData->bHasJSEP = MNG_FALSE; + pData->bHasJDAA = MNG_FALSE; + pData->bHasJDAT = MNG_FALSE; +#endif + pData->bHasPLTE = MNG_FALSE; + pData->bHasTRNS = MNG_FALSE; + pData->bHasGAMA = MNG_FALSE; + pData->bHasCHRM = MNG_FALSE; + pData->bHasSRGB = MNG_FALSE; + pData->bHasICCP = MNG_FALSE; + pData->bHasBKGD = MNG_FALSE; + pData->bHasIDAT = MNG_FALSE; + } + /* if the image was displayed on the fly, */ + /* we'll have to make the app refresh */ + if ((pData->eImagetype != mng_it_mng) && (pData->fDisplayrow)) + pData->bNeedrefresh = MNG_TRUE; + + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IEND, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +/* change in the MNG spec with regards to TERM delay & interframe_delay + as proposed by Adam M. Costello (option 4) and finalized by official vote + during december 2002 / check the 'mng-list' archives for more details */ + +mng_retcode mng_process_display_mend (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_START); +#endif + +#ifdef MNG_SUPPORT_DYNAMICMNG + if (pData->bStopafterseek) /* need to stop after this ? */ + { + pData->bFreezing = MNG_TRUE; /* stop processing on this one */ + pData->bRunningevent = MNG_FALSE; + pData->bStopafterseek = MNG_FALSE; + pData->bNeedrefresh = MNG_TRUE; /* make sure the last bit is displayed ! */ + } +#endif + +#ifndef MNG_SKIPCHUNK_TERM + /* TERM processed ? */ + if ((pData->bDisplaying) && (pData->bRunning) && + (pData->bHasTERM) && (pData->pTermaniobj)) + { + mng_retcode iRetcode; + mng_ani_termp pTERM; + /* get the right animation object ! */ + pTERM = (mng_ani_termp)pData->pTermaniobj; + + pData->iIterations++; /* increase iteration count */ + + switch (pTERM->iTermaction) /* determine what to do! */ + { + case 0 : { /* show last frame indefinitly */ + break; /* piece of cake, that is... */ + } + + case 1 : { /* cease displaying anything */ + /* max(1, TERM delay, interframe_delay) */ +#ifndef MNG_SKIPCHUNK_FRAM + if (pTERM->iDelay > pData->iFramedelay) + pData->iFramedelay = pTERM->iDelay; + if (!pData->iFramedelay) + pData->iFramedelay = 1; +#endif + + iRetcode = interframe_delay (pData); + /* no interframe_delay? then fake it */ + if ((!iRetcode) && (!pData->bTimerset)) + iRetcode = set_delay (pData, 1); + + if (iRetcode) + return iRetcode; + + pData->iBreakpoint = 10; + break; + } + + case 2 : { /* show first image after TERM */ + iRetcode = restore_state (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* notify the app ? */ + if (pData->fProcessmend) + if (!pData->fProcessmend ((mng_handle)pData, pData->iIterations, 0)) + MNG_ERROR (pData, MNG_APPMISCERROR); + + /* show first frame after TERM chunk */ + pData->pCurraniobj = pTERM; + pData->bOnlyfirstframe = MNG_TRUE; + pData->iFramesafterTERM = 0; + + /* max(1, TERM delay, interframe_delay) */ +#ifndef MNG_SKIPCHUNK_FRAM + if (pTERM->iDelay > pData->iFramedelay) + pData->iFramedelay = pTERM->iDelay; + if (!pData->iFramedelay) + pData->iFramedelay = 1; +#endif + + break; + } + + case 3 : { /* repeat */ + if ((pTERM->iItermax) && (pTERM->iItermax < 0x7FFFFFFF)) + pTERM->iItermax--; + + if (pTERM->iItermax) /* go back to TERM ? */ + { /* restore to initial or SAVE state */ + iRetcode = restore_state (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* notify the app ? */ + if (pData->fProcessmend) + if (!pData->fProcessmend ((mng_handle)pData, + pData->iIterations, pTERM->iItermax)) + MNG_ERROR (pData, MNG_APPMISCERROR); + + /* restart from TERM chunk */ + pData->pCurraniobj = pTERM; + + if (pTERM->iDelay) /* set the delay (?) */ + { + /* max(1, TERM delay, interframe_delay) */ +#ifndef MNG_SKIPCHUNK_FRAM + if (pTERM->iDelay > pData->iFramedelay) + pData->iFramedelay = pTERM->iDelay; + if (!pData->iFramedelay) + pData->iFramedelay = 1; +#endif + + pData->bNeedrefresh = MNG_TRUE; + } + } + else + { + switch (pTERM->iIteraction) + { + case 0 : { /* show last frame indefinitly */ + break; /* piece of cake, that is... */ + } + + case 1 : { /* cease displaying anything */ + /* max(1, TERM delay, interframe_delay) */ +#ifndef MNG_SKIPCHUNK_FRAM + if (pTERM->iDelay > pData->iFramedelay) + pData->iFramedelay = pTERM->iDelay; + if (!pData->iFramedelay) + pData->iFramedelay = 1; +#endif + + iRetcode = interframe_delay (pData); + /* no interframe_delay? then fake it */ + if ((!iRetcode) && (!pData->bTimerset)) + iRetcode = set_delay (pData, 1); + + if (iRetcode) + return iRetcode; + + pData->iBreakpoint = 10; + break; + } + + case 2 : { /* show first image after TERM */ + iRetcode = restore_state (pData); + /* on error bail out */ + if (iRetcode) + return iRetcode; + /* notify the app ? */ + if (pData->fProcessmend) + if (!pData->fProcessmend ((mng_handle)pData, + pData->iIterations, 0)) + MNG_ERROR (pData, MNG_APPMISCERROR); + + /* show first frame after TERM chunk */ + pData->pCurraniobj = pTERM; + pData->bOnlyfirstframe = MNG_TRUE; + pData->iFramesafterTERM = 0; + /* max(1, TERM delay, interframe_delay) */ +#ifndef MNG_SKIPCHUNK_FRAM + if (pTERM->iDelay > pData->iFramedelay) + pData->iFramedelay = pTERM->iDelay; + if (!pData->iFramedelay) + pData->iFramedelay = 1; +#endif + + break; + } + } + } + + break; + } + } + } +#endif /* MNG_SKIPCHUNK_TERM */ + /* just reading ? */ + if ((!pData->bDisplaying) && (pData->bReading)) + if (pData->fProcessmend) /* inform the app ? */ + if (!pData->fProcessmend ((mng_handle)pData, 0, 0)) + MNG_ERROR (pData, MNG_APPMISCERROR); + + if (!pData->pCurraniobj) /* always let the app refresh at the end ! */ + pData->bNeedrefresh = MNG_TRUE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_process_display_mend2 (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_START); +#endif + +#ifndef MNG_SKIPCHUNK_FRAM + pData->bFrameclipping = MNG_FALSE; /* nothing to do but restore the app background */ +#endif + load_bkgdlayer (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DEFI +mng_retcode mng_process_display_defi (mng_datap pData) +{ + mng_imagep pImage; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DEFI, MNG_LC_START); +#endif + + if (!pData->iDEFIobjectid) /* object id=0 ? */ + { + pImage = (mng_imagep)pData->pObjzero; + + if (pData->bDEFIhasdonotshow) + pImage->bVisible = (mng_bool)(pData->iDEFIdonotshow == 0); + + if (pData->bDEFIhasloca) + { + pImage->iPosx = pData->iDEFIlocax; + pImage->iPosy = pData->iDEFIlocay; + } + + if (pData->bDEFIhasclip) + { + pImage->bClipped = pData->bDEFIhasclip; + pImage->iClipl = pData->iDEFIclipl; + pImage->iClipr = pData->iDEFIclipr; + pImage->iClipt = pData->iDEFIclipt; + pImage->iClipb = pData->iDEFIclipb; + } + + pData->pCurrentobj = 0; /* not a real object ! */ + } + else + { /* already exists ? */ + pImage = (mng_imagep)mng_find_imageobject (pData, pData->iDEFIobjectid); + + if (!pImage) /* if not; create new */ + { + mng_retcode iRetcode = mng_create_imageobject (pData, pData->iDEFIobjectid, + (mng_bool)(pData->iDEFIconcrete == 1), + (mng_bool)(pData->iDEFIdonotshow == 0), + MNG_FALSE, 0, 0, 0, 0, 0, 0, 0, + pData->iDEFIlocax, pData->iDEFIlocay, + pData->bDEFIhasclip, + pData->iDEFIclipl, pData->iDEFIclipr, + pData->iDEFIclipt, pData->iDEFIclipb, + &pImage); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + else + { /* exists; then set new info */ + if (pData->bDEFIhasdonotshow) + pImage->bVisible = (mng_bool)(pData->iDEFIdonotshow == 0); + + pImage->bViewable = MNG_FALSE; + + if (pData->bDEFIhasloca) + { + pImage->iPosx = pData->iDEFIlocax; + pImage->iPosy = pData->iDEFIlocay; + } + + if (pData->bDEFIhasclip) + { + pImage->bClipped = pData->bDEFIhasclip; + pImage->iClipl = pData->iDEFIclipl; + pImage->iClipr = pData->iDEFIclipr; + pImage->iClipt = pData->iDEFIclipt; + pImage->iClipb = pData->iDEFIclipb; + } + + if (pData->bDEFIhasconcrete) + pImage->pImgbuf->bConcrete = (mng_bool)(pData->iDEFIconcrete == 1); + } + + pData->pCurrentobj = pImage; /* others may want to know this */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DEFI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_BASI +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +mng_retcode mng_process_display_basi (mng_datap pData, + mng_uint16 iRed, + mng_uint16 iGreen, + mng_uint16 iBlue, + mng_bool bHasalpha, + mng_uint16 iAlpha, + mng_uint8 iViewable) +#else +mng_retcode mng_process_display_basi (mng_datap pData) +#endif +{ /* address the current "object" if any */ + mng_imagep pImage = (mng_imagep)pData->pCurrentobj; + mng_uint8p pWork; + mng_uint32 iX; + mng_imagedatap pBuf; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_BASI, MNG_LC_START); +#endif + + if (!pImage) /* or is it an "on-the-fly" image ? */ + pImage = (mng_imagep)pData->pObjzero; + /* address the object-buffer */ + pBuf = pImage->pImgbuf; + + pData->fDisplayrow = MNG_NULL; /* do nothing by default */ + pData->fCorrectrow = MNG_NULL; + pData->fStorerow = MNG_NULL; + pData->fProcessrow = MNG_NULL; + /* set parms now that they're known */ + iRetcode = mng_reset_object_details (pData, pImage, pData->iDatawidth, + pData->iDataheight, pData->iBitdepth, + pData->iColortype, pData->iCompression, + pData->iFilter, pData->iInterlace, MNG_FALSE); + if (iRetcode) /* on error bail out */ + return iRetcode; + /* save the viewable flag */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pImage->bViewable = (mng_bool)(iViewable == 1); +#else + pImage->bViewable = (mng_bool)(pData->iBASIviewable == 1); +#endif + pBuf->bViewable = pImage->bViewable; + pData->pStoreobj = pImage; /* let row-routines know which object */ + + pWork = pBuf->pImgdata; /* fill the object-buffer with the specified + "color" sample */ + switch (pData->iColortype) /* depending on color_type & bit_depth */ + { + case 0 : { /* gray */ +#ifndef MNG_NO_16BIT_SUPPORT + if (pData->iBitdepth == 16) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iDatawidth * pData->iDataheight; + iX > 0;iX--) +#else + for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + mng_put_uint16 (pWork, iRed); +#else + mng_put_uint16 (pWork, pData->iBASIred); +#endif + pWork += 2; + } + } + else +#endif + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iDatawidth * pData->iDataheight; + iX > 0;iX--) +#else + for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + *pWork = (mng_uint8)iRed; +#else + *pWork = (mng_uint8)pData->iBASIred; +#endif + pWork++; + } + } + /* force tRNS ? */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if ((bHasalpha) && (!iAlpha)) +#else + if ((pData->bBASIhasalpha) && (!pData->iBASIalpha)) +#endif + { + pBuf->bHasTRNS = MNG_TRUE; +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pBuf->iTRNSgray = iRed; +#else + pBuf->iTRNSgray = pData->iBASIred; +#endif + } + + break; + } + + case 2 : { /* rgb */ +#ifndef MNG_NO_16BIT_SUPPORT + if (pData->iBitdepth == 16) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iDatawidth * pData->iDataheight; + iX > 0;iX--) +#else + for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + mng_put_uint16 (pWork, iRed ); + mng_put_uint16 (pWork+2, iGreen); + mng_put_uint16 (pWork+4, iBlue ); +#else + mng_put_uint16 (pWork, pData->iBASIred ); + mng_put_uint16 (pWork+2, pData->iBASIgreen); + mng_put_uint16 (pWork+4, pData->iBASIblue ); +#endif + pWork += 6; + } + } + else +#endif + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iDatawidth * pData->iDataheight; + iX > 0;iX--) +#else + for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + *pWork = (mng_uint8)iRed; + *(pWork+1) = (mng_uint8)iGreen; + *(pWork+2) = (mng_uint8)iBlue; +#else + *pWork = (mng_uint8)pData->iBASIred; + *(pWork+1) = (mng_uint8)pData->iBASIgreen; + *(pWork+2) = (mng_uint8)pData->iBASIblue; +#endif + pWork += 3; + } + } + /* force tRNS ? */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if ((bHasalpha) && (!iAlpha)) +#else + if ((pData->bBASIhasalpha) && (!pData->iBASIalpha)) +#endif + { + pBuf->bHasTRNS = MNG_TRUE; +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pBuf->iTRNSred = iRed; + pBuf->iTRNSgreen = iGreen; + pBuf->iTRNSblue = iBlue; +#else + pBuf->iTRNSred = pData->iBASIred; + pBuf->iTRNSgreen = pData->iBASIgreen; + pBuf->iTRNSblue = pData->iBASIblue; +#endif + } + + break; + } + + case 3 : { /* indexed */ + pBuf->bHasPLTE = MNG_TRUE; + + switch (pData->iBitdepth) + { + case 1 : { pBuf->iPLTEcount = 2; break; } + case 2 : { pBuf->iPLTEcount = 4; break; } + case 4 : { pBuf->iPLTEcount = 16; break; } + case 8 : { pBuf->iPLTEcount = 256; break; } + default : { pBuf->iPLTEcount = 1; break; } + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pBuf->aPLTEentries [0].iRed = (mng_uint8)iRed; + pBuf->aPLTEentries [0].iGreen = (mng_uint8)iGreen; + pBuf->aPLTEentries [0].iBlue = (mng_uint8)iBlue; +#else + pBuf->aPLTEentries [0].iRed = (mng_uint8)pData->iBASIred; + pBuf->aPLTEentries [0].iGreen = (mng_uint8)pData->iBASIgreen; + pBuf->aPLTEentries [0].iBlue = (mng_uint8)pData->iBASIblue; +#endif + + for (iX = 1; iX < pBuf->iPLTEcount; iX++) + { + pBuf->aPLTEentries [iX].iRed = 0; + pBuf->aPLTEentries [iX].iGreen = 0; + pBuf->aPLTEentries [iX].iBlue = 0; + } + /* force tRNS ? */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if ((bHasalpha) && (iAlpha < 255)) +#else + if ((pData->bBASIhasalpha) && (pData->iBASIalpha < 255)) +#endif + { + pBuf->bHasTRNS = MNG_TRUE; + pBuf->iTRNScount = 1; +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pBuf->aTRNSentries [0] = (mng_uint8)iAlpha; +#else + pBuf->aTRNSentries [0] = (mng_uint8)pData->iBASIalpha; +#endif + } + + break; + } + + case 4 : { /* gray+alpha */ +#ifndef MNG_NO_16BIT_SUPPORT + if (pData->iBitdepth == 16) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iDatawidth * pData->iDataheight; + iX > 0;iX--) +#else + for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + mng_put_uint16 (pWork, iRed); + mng_put_uint16 (pWork+2, iAlpha); +#else + mng_put_uint16 (pWork, pData->iBASIred); + mng_put_uint16 (pWork+2, pData->iBASIalpha); +#endif + pWork += 4; + } + } + else +#endif + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iDatawidth * pData->iDataheight; + iX > 0;iX--) +#else + for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + *pWork = (mng_uint8)iRed; + *(pWork+1) = (mng_uint8)iAlpha; +#else + *pWork = (mng_uint8)pData->iBASIred; + *(pWork+1) = (mng_uint8)pData->iBASIalpha; +#endif + pWork += 2; + } + } + + break; + } + + case 6 : { /* rgb+alpha */ +#ifndef MNG_NO_16BIT_SUPPORT + if (pData->iBitdepth == 16) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iDatawidth * pData->iDataheight; + iX > 0;iX--) +#else + for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + mng_put_uint16 (pWork, iRed); + mng_put_uint16 (pWork+2, iGreen); + mng_put_uint16 (pWork+4, iBlue); + mng_put_uint16 (pWork+6, iAlpha); +#else + mng_put_uint16 (pWork, pData->iBASIred); + mng_put_uint16 (pWork+2, pData->iBASIgreen); + mng_put_uint16 (pWork+4, pData->iBASIblue); + mng_put_uint16 (pWork+6, pData->iBASIalpha); +#endif + pWork += 8; + } + } + else +#endif + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iDatawidth * pData->iDataheight; + iX > 0;iX--) +#else + for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++) +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + *pWork = (mng_uint8)iRed; + *(pWork+1) = (mng_uint8)iGreen; + *(pWork+2) = (mng_uint8)iBlue; + *(pWork+3) = (mng_uint8)iAlpha; +#else + *pWork = (mng_uint8)pData->iBASIred; + *(pWork+1) = (mng_uint8)pData->iBASIgreen; + *(pWork+2) = (mng_uint8)pData->iBASIblue; + *(pWork+3) = (mng_uint8)pData->iBASIalpha; +#endif + pWork += 4; + } + } + + break; + } + + } + +#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT + pData->fInitrowproc = (mng_fptr)mng_init_rowproc; + pData->ePng_imgtype=mng_png_imgtype(pData->iColortype,pData->iBitdepth); +#else + switch (pData->iColortype) /* determine row initialization routine */ + { /* just to accomodate IDAT if it arrives */ + case 0 : { /* gray */ + switch (pData->iBitdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g1_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g1_i; + + break; + } + case 2 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g2_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g2_i; + + break; + } + case 4 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g4_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g4_i; + + break; + } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g8_i; + + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g16_i; + + break; + } +#endif + } + + break; + } + case 2 : { /* rgb */ + switch (pData->iBitdepth) + { + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i; + + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i; + + break; + } +#endif + } + + break; + } + case 3 : { /* indexed */ + switch (pData->iBitdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx1_i; + + break; + } + case 2 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx2_i; + + break; + } + case 4 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx4_i; + + break; + } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx8_i; + + break; + } + } + + break; + } + case 4 : { /* gray+alpha */ + switch (pData->iBitdepth) + { + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_ga8_i; + + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_ga16_i; + + break; + } +#endif + } + + break; + } + case 6 : { /* rgb+alpha */ + switch (pData->iBitdepth) + { + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i; + + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i; + + break; + } +#endif + } + + break; + } + } +#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ + + pData->iFilterofs = 0; /* determine filter characteristics */ + pData->iLevel0 = 0; /* default levels */ + pData->iLevel1 = 0; + pData->iLevel2 = 0; + pData->iLevel3 = 0; + +#ifdef FILTER192 + if (pData->iFilter == 0xC0) /* leveling & differing ? */ + { + switch (pData->iColortype) + { + case 0 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pData->iBitdepth <= 8) +#endif + pData->iFilterofs = 1; +#ifndef MNG_NO_16BIT_SUPPORT + else + pData->iFilterofs = 2; +#endif + + break; + } + case 2 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pData->iBitdepth <= 8) +#endif + pData->iFilterofs = 3; +#ifndef MNG_NO_16BIT_SUPPORT + else + pData->iFilterofs = 6; +#endif + + break; + } + case 3 : { + pData->iFilterofs = 1; + break; + } + case 4 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pData->iBitdepth <= 8) +#endif + pData->iFilterofs = 2; +#ifndef MNG_NO_16BIT_SUPPORT + else + pData->iFilterofs = 4; +#endif + + break; + } + case 6 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pData->iBitdepth <= 8) +#endif + pData->iFilterofs = 4; +#ifndef MNG_NO_16BIT_SUPPORT + else + pData->iFilterofs = 8; +#endif + + break; + } + } + } +#endif + +#ifdef FILTER193 + if (pData->iFilter == 0xC1) /* no adaptive filtering ? */ + pData->iPixelofs = pData->iFilterofs; + else +#endif + pData->iPixelofs = pData->iFilterofs + 1; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_BASI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_CLON +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +mng_retcode mng_process_display_clon (mng_datap pData, + mng_uint16 iSourceid, + mng_uint16 iCloneid, + mng_uint8 iClonetype, + mng_bool bHasdonotshow, + mng_uint8 iDonotshow, + mng_uint8 iConcrete, + mng_bool bHasloca, + mng_uint8 iLocationtype, + mng_int32 iLocationx, + mng_int32 iLocationy) +#else +mng_retcode mng_process_display_clon (mng_datap pData) +#endif +{ + mng_imagep pSource, pClone; + mng_bool bVisible, bAbstract; + mng_retcode iRetcode = MNG_NOERROR; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_START); +#endif +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + /* locate the source object first */ + pSource = mng_find_imageobject (pData, iSourceid); + /* check if the clone exists */ + pClone = mng_find_imageobject (pData, iCloneid); +#else + /* locate the source object first */ + pSource = mng_find_imageobject (pData, pData->iCLONsourceid); + /* check if the clone exists */ + pClone = mng_find_imageobject (pData, pData->iCLONcloneid); +#endif + + if (!pSource) /* source must exist ! */ + MNG_ERROR (pData, MNG_OBJECTUNKNOWN); + + if (pClone) /* clone must not exist ! */ + MNG_ERROR (pData, MNG_OBJECTEXISTS); + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (bHasdonotshow) /* DoNotShow flag filled ? */ + bVisible = (mng_bool)(iDonotshow == 0); + else + bVisible = pSource->bVisible; +#else + if (pData->bCLONhasdonotshow) /* DoNotShow flag filled ? */ + bVisible = (mng_bool)(pData->iCLONdonotshow == 0); + else + bVisible = pSource->bVisible; +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + bAbstract = (mng_bool)(iConcrete == 1); +#else + bAbstract = (mng_bool)(pData->iCLONconcrete == 1); +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + switch (iClonetype) /* determine action to take */ + { + case 0 : { /* full clone */ + iRetcode = mng_clone_imageobject (pData, iCloneid, MNG_FALSE, + bVisible, bAbstract, bHasloca, + iLocationtype, iLocationx, iLocationy, + pSource, &pClone); + break; + } + + case 1 : { /* partial clone */ + iRetcode = mng_clone_imageobject (pData, iCloneid, MNG_TRUE, + bVisible, bAbstract, bHasloca, + iLocationtype, iLocationx, iLocationy, + pSource, &pClone); + break; + } + + case 2 : { /* renumber object */ + iRetcode = mng_renum_imageobject (pData, pSource, iCloneid, + bVisible, bAbstract, bHasloca, + iLocationtype, iLocationx, iLocationy); + pClone = pSource; + break; + } + + } +#else + switch (pData->iCLONclonetype) /* determine action to take */ + { + case 0 : { /* full clone */ + iRetcode = mng_clone_imageobject (pData, pData->iCLONcloneid, MNG_FALSE, + bVisible, bAbstract, + pData->bCLONhasloca, pData->iCLONlocationtype, + pData->iCLONlocationx, pData->iCLONlocationy, + pSource, &pClone); + break; + } + + case 1 : { /* partial clone */ + iRetcode = mng_clone_imageobject (pData, pData->iCLONcloneid, MNG_TRUE, + bVisible, bAbstract, + pData->bCLONhasloca, pData->iCLONlocationtype, + pData->iCLONlocationx, pData->iCLONlocationy, + pSource, &pClone); + break; + } + + case 2 : { /* renumber object */ + iRetcode = mng_renum_imageobject (pData, pSource, pData->iCLONcloneid, + bVisible, bAbstract, + pData->bCLONhasloca, pData->iCLONlocationtype, + pData->iCLONlocationx, pData->iCLONlocationy); + pClone = pSource; + break; + } + + } +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + + /* display on the fly ? */ + if ((pClone->bViewable) && (pClone->bVisible)) + { + pData->pLastclone = pClone; /* remember in case of timer break ! */ + /* display it */ + mng_display_image (pData, pClone, MNG_FALSE); + + if (pData->bTimerset) /* timer break ? */ + pData->iBreakpoint = 5; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_process_display_clon2 (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_START); +#endif + /* only called after timer break ! */ + mng_display_image (pData, (mng_imagep)pData->pLastclone, MNG_FALSE); + pData->iBreakpoint = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DISC +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +mng_retcode mng_process_display_disc (mng_datap pData, + mng_uint32 iCount, + mng_uint16p pIds) +#else +mng_retcode mng_process_display_disc (mng_datap pData) +#endif +{ + mng_uint32 iX; + mng_imagep pImage; + mng_uint32 iRetcode; +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DISC, MNG_LC_START); +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (iCount) /* specific list ? */ +#else + if (pData->iDISCcount) /* specific list ? */ +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + mng_uint16p pWork = pIds; +#else + mng_uint16p pWork = pData->pDISCids; +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +#ifdef MNG_DECREMENT_LOOPS /* iterate the list */ + for (iX = iCount; iX > 0; iX--) +#else + for (iX = 0; iX < iCount; iX++) +#endif +#else +#ifdef MNG_DECREMENT_LOOPS /* iterate the list */ + for (iX = pData->iDISCcount; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iDISCcount; iX++) +#endif +#endif + { + pImage = mng_find_imageobject (pData, *pWork++); + + if (pImage) /* found the object ? */ + { /* then drop it */ + iRetcode = mng_free_imageobject (pData, pImage); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } + } + else /* empty: drop all un-frozen objects */ + { + mng_imagep pNext = (mng_imagep)pData->pFirstimgobj; + + while (pNext) /* any left ? */ + { + pImage = pNext; + pNext = pImage->sHeader.pNext; + + if (!pImage->bFrozen) /* not frozen ? */ + { /* then drop it */ + iRetcode = mng_free_imageobject (pData, pImage); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DISC, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_FRAM +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +mng_retcode mng_process_display_fram (mng_datap pData, + mng_uint8 iFramemode, + mng_uint8 iChangedelay, + mng_uint32 iDelay, + mng_uint8 iChangetimeout, + mng_uint32 iTimeout, + mng_uint8 iChangeclipping, + mng_uint8 iCliptype, + mng_int32 iClipl, + mng_int32 iClipr, + mng_int32 iClipt, + mng_int32 iClipb) +#else +mng_retcode mng_process_display_fram (mng_datap pData) +#endif +{ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_START); +#endif + /* advance a frame then */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = next_frame (pData, iFramemode, iChangedelay, iDelay, + iChangetimeout, iTimeout, iChangeclipping, + iCliptype, iClipl, iClipr, iClipt, iClipb); +#else + iRetcode = next_frame (pData, pData->iTempFramemode, pData->iTempChangedelay, + pData->iTempDelay, pData->iTempChangetimeout, + pData->iTempTimeout, pData->iTempChangeclipping, + pData->iTempCliptype, pData->iTempClipl, pData->iTempClipr, + pData->iTempClipt, pData->iTempClipb); +#endif + + if (pData->bTimerset) /* timer break ? */ + pData->iBreakpoint = 1; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +mng_retcode mng_process_display_fram2 (mng_datap pData) +{ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_START); +#endif + /* again; after the break */ + iRetcode = next_frame (pData, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + pData->iBreakpoint = 0; /* not again! */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MOVE +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +mng_retcode mng_process_display_move (mng_datap pData, + mng_uint16 iFromid, + mng_uint16 iToid, + mng_uint8 iMovetype, + mng_int32 iMovex, + mng_int32 iMovey) +#else +mng_retcode mng_process_display_move (mng_datap pData) +#endif +{ + mng_uint16 iX; + mng_imagep pImage; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MOVE, MNG_LC_START); +#endif + /* iterate the list */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + for (iX = iFromid; iX <= iToid; iX++) +#else + for (iX = pData->iMOVEfromid; iX <= pData->iMOVEtoid; iX++) +#endif + { + if (!iX) /* object id=0 ? */ + pImage = (mng_imagep)pData->pObjzero; + else + pImage = mng_find_imageobject (pData, iX); + + if (pImage) /* object exists ? */ + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + switch (iMovetype) +#else + switch (pData->iMOVEmovetype) +#endif + { + case 0 : { /* absolute */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pImage->iPosx = iMovex; + pImage->iPosy = iMovey; +#else + pImage->iPosx = pData->iMOVEmovex; + pImage->iPosy = pData->iMOVEmovey; +#endif + break; + } + case 1 : { /* relative */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pImage->iPosx = pImage->iPosx + iMovex; + pImage->iPosy = pImage->iPosy + iMovey; +#else + pImage->iPosx = pImage->iPosx + pData->iMOVEmovex; + pImage->iPosy = pImage->iPosy + pData->iMOVEmovey; +#endif + break; + } + } + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MOVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_CLIP +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +mng_retcode mng_process_display_clip (mng_datap pData, + mng_uint16 iFromid, + mng_uint16 iToid, + mng_uint8 iCliptype, + mng_int32 iClipl, + mng_int32 iClipr, + mng_int32 iClipt, + mng_int32 iClipb) +#else +mng_retcode mng_process_display_clip (mng_datap pData) +#endif +{ + mng_uint16 iX; + mng_imagep pImage; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLIP, MNG_LC_START); +#endif + /* iterate the list */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + for (iX = iFromid; iX <= iToid; iX++) +#else + for (iX = pData->iCLIPfromid; iX <= pData->iCLIPtoid; iX++) +#endif + { + if (!iX) /* object id=0 ? */ + pImage = (mng_imagep)pData->pObjzero; + else + pImage = mng_find_imageobject (pData, iX); + + if (pImage) /* object exists ? */ + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + switch (iCliptype) +#else + switch (pData->iCLIPcliptype) +#endif + { + case 0 : { /* absolute */ + pImage->bClipped = MNG_TRUE; +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pImage->iClipl = iClipl; + pImage->iClipr = iClipr; + pImage->iClipt = iClipt; + pImage->iClipb = iClipb; +#else + pImage->iClipl = pData->iCLIPclipl; + pImage->iClipr = pData->iCLIPclipr; + pImage->iClipt = pData->iCLIPclipt; + pImage->iClipb = pData->iCLIPclipb; +#endif + break; + } + case 1 : { /* relative */ + pImage->bClipped = MNG_TRUE; +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pImage->iClipl = pImage->iClipl + iClipl; + pImage->iClipr = pImage->iClipr + iClipr; + pImage->iClipt = pImage->iClipt + iClipt; + pImage->iClipb = pImage->iClipb + iClipb; +#else + pImage->iClipl = pImage->iClipl + pData->iCLIPclipl; + pImage->iClipr = pImage->iClipr + pData->iCLIPclipr; + pImage->iClipt = pImage->iClipt + pData->iCLIPclipt; + pImage->iClipb = pImage->iClipb + pData->iCLIPclipb; +#endif + break; + } + } + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLIP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SHOW +mng_retcode mng_process_display_show (mng_datap pData) +{ + mng_int16 iX, iS, iFrom, iTo; + mng_imagep pImage; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SHOW, MNG_LC_START); +#endif + + /* TODO: optimization for the cases where "abs (iTo - iFrom)" is rather high; + especially where ((iFrom==1) && (iTo==65535)); eg. an empty SHOW !!! */ + + if (pData->iBreakpoint == 3) /* previously broken during cycle-mode ? */ + { + pImage = mng_find_imageobject (pData, pData->iSHOWnextid); + + if (pImage) /* still there ? */ + mng_display_image (pData, pImage, MNG_FALSE); + + pData->iBreakpoint = 0; /* let's not go through this again! */ + } + else + { + if (pData->iBreakpoint) /* previously broken at other point ? */ + { /* restore last parms */ + iFrom = (mng_int16)pData->iSHOWfromid; + iTo = (mng_int16)pData->iSHOWtoid; + iX = (mng_int16)pData->iSHOWnextid; + iS = (mng_int16)pData->iSHOWskip; + } + else + { /* regular sequence ? */ + if (pData->iSHOWtoid >= pData->iSHOWfromid) + iS = 1; + else /* reverse sequence ! */ + iS = -1; + + iFrom = (mng_int16)pData->iSHOWfromid; + iTo = (mng_int16)pData->iSHOWtoid; + iX = iFrom; + + pData->iSHOWfromid = (mng_uint16)iFrom; + pData->iSHOWtoid = (mng_uint16)iTo; + pData->iSHOWskip = iS; + } + /* cycle mode ? */ + if ((pData->iSHOWmode == 6) || (pData->iSHOWmode == 7)) + { + mng_uint16 iTrigger = 0; + mng_uint16 iFound = 0; + mng_uint16 iPass = 0; + mng_imagep pFound = 0; + + do + { + iPass++; /* lets prevent endless loops when there + are no potential candidates in the list! */ + + if (iS > 0) /* forward ? */ + { + for (iX = iFrom; iX <= iTo; iX += iS) + { + pImage = mng_find_imageobject (pData, (mng_uint16)iX); + + if (pImage) /* object exists ? */ + { + if (iFound) /* already found a candidate ? */ + pImage->bVisible = MNG_FALSE; + else + if (iTrigger) /* found the trigger ? */ + { + pImage->bVisible = MNG_TRUE; + iFound = iX; + pFound = pImage; + } + else + if (pImage->bVisible) /* ok, this is the trigger */ + { + pImage->bVisible = MNG_FALSE; + iTrigger = iX; + } + } + } + } + else + { + for (iX = iFrom; iX >= iTo; iX += iS) + { + pImage = mng_find_imageobject (pData, (mng_uint16)iX); + + if (pImage) /* object exists ? */ + { + if (iFound) /* already found a candidate ? */ + pImage->bVisible = MNG_FALSE; + else + if (iTrigger) /* found the trigger ? */ + { + pImage->bVisible = MNG_TRUE; + iFound = iX; + pFound = pImage; + } + else + if (pImage->bVisible) /* ok, this is the trigger */ + { + pImage->bVisible = MNG_FALSE; + iTrigger = iX; + } + } + } + } + + if (!iTrigger) /* did not find a trigger ? */ + iTrigger = 1; /* then fake it so the first image + gets nominated */ + } /* cycle back to beginning ? */ + while ((iPass < 2) && (iTrigger) && (!iFound)); + + pData->iBreakpoint = 0; /* just a sanity precaution */ + /* display it ? */ + if ((pData->iSHOWmode == 6) && (pFound)) + { + mng_display_image (pData, pFound, MNG_FALSE); + + if (pData->bTimerset) /* timer set ? */ + { + pData->iBreakpoint = 3; + pData->iSHOWnextid = iFound; /* save it for after the break */ + } + } + } + else + { + do + { + pImage = mng_find_imageobject (pData, iX); + + if (pImage) /* object exists ? */ + { + if (pData->iBreakpoint) /* did we get broken last time ? */ + { /* could only happen in the display routine */ + mng_display_image (pData, pImage, MNG_FALSE); + pData->iBreakpoint = 0; /* only once inside this loop please ! */ + } + else + { + switch (pData->iSHOWmode) /* do what ? */ + { + case 0 : { + pImage->bVisible = MNG_TRUE; + mng_display_image (pData, pImage, MNG_FALSE); + break; + } + case 1 : { + pImage->bVisible = MNG_FALSE; + break; + } + case 2 : { + if (pImage->bVisible) + mng_display_image (pData, pImage, MNG_FALSE); + break; + } + case 3 : { + pImage->bVisible = MNG_TRUE; + break; + } + case 4 : { + pImage->bVisible = (mng_bool)(!pImage->bVisible); + if (pImage->bVisible) + mng_display_image (pData, pImage, MNG_FALSE); + break; + } + case 5 : { + pImage->bVisible = (mng_bool)(!pImage->bVisible); + } + } + } + } + + if (!pData->bTimerset) /* next ? */ + iX += iS; + + } /* continue ? */ + while ((!pData->bTimerset) && (((iS > 0) && (iX <= iTo)) || + ((iS < 0) && (iX >= iTo)) )); + + if (pData->bTimerset) /* timer set ? */ + { + pData->iBreakpoint = 4; + pData->iSHOWnextid = iX; /* save for next time */ + } + else + pData->iBreakpoint = 0; + + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SHOW, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SAVE +mng_retcode mng_process_display_save (mng_datap pData) +{ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SAVE, MNG_LC_START); +#endif + + iRetcode = save_state (pData); /* save the current state */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SAVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SEEK +mng_retcode mng_process_display_seek (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SEEK, MNG_LC_START); +#endif + +#ifdef MNG_SUPPORT_DYNAMICMNG + if (pData->bStopafterseek) /* need to stop after this SEEK ? */ + { + pData->bFreezing = MNG_TRUE; /* stop processing on this one */ + pData->bRunningevent = MNG_FALSE; + pData->bStopafterseek = MNG_FALSE; + pData->bNeedrefresh = MNG_TRUE; /* make sure the last bit is displayed ! */ + } + else +#endif + { /* restore the initial or SAVE state */ + mng_retcode iRetcode = restore_state (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifdef MNG_SUPPORT_DYNAMICMNG + /* stop after next SEEK ? */ + if ((pData->bDynamic) || (pData->bRunningevent)) + pData->bStopafterseek = MNG_TRUE; +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SEEK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +mng_retcode mng_process_display_jhdr (mng_datap pData) +{ /* address the current "object" if any */ + mng_imagep pImage = (mng_imagep)pData->pCurrentobj; + mng_retcode iRetcode = MNG_NOERROR; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JHDR, MNG_LC_START); +#endif + + if (!pData->bHasDHDR) + { + pData->fInitrowproc = MNG_NULL; /* do nothing by default */ + pData->fDisplayrow = MNG_NULL; + pData->fCorrectrow = MNG_NULL; + pData->fStorerow = MNG_NULL; + pData->fProcessrow = MNG_NULL; + pData->fDifferrow = MNG_NULL; + pData->fStorerow2 = MNG_NULL; + pData->fStorerow3 = MNG_NULL; + + pData->pStoreobj = MNG_NULL; /* initialize important work-parms */ + + pData->iJPEGrow = 0; + pData->iJPEGalpharow = 0; + pData->iJPEGrgbrow = 0; + pData->iRowmax = 0; /* so init_rowproc does the right thing ! */ + } + + if (!pData->iBreakpoint) /* not previously broken ? */ + { +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* delta-image ? */ + { + if (pData->iDeltatype == MNG_DELTATYPE_REPLACE) + { + iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pDeltaImage, + pData->iDatawidth, pData->iDataheight, + pData->iJHDRimgbitdepth, pData->iJHDRcolortype, + pData->iJHDRalphacompression, pData->iJHDRalphafilter, + pData->iJHDRalphainterlace, MNG_TRUE); + + ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphabitdepth = pData->iJHDRalphabitdepth; + ((mng_imagep)pData->pDeltaImage)->pImgbuf->iJHDRcompression = pData->iJHDRimgcompression; + ((mng_imagep)pData->pDeltaImage)->pImgbuf->iJHDRinterlace = pData->iJHDRimginterlace; + ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth; + } + else + if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + ((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iJHDRimgbitdepth; + ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth; + } + else + if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) ) + ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth; + else + if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) ) + ((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iJHDRimgbitdepth; + + } + else +#endif /* MNG_NO_DELTA_PNG */ + { + if (pImage) /* update object buffer ? */ + { + iRetcode = mng_reset_object_details (pData, pImage, + pData->iDatawidth, pData->iDataheight, + pData->iJHDRimgbitdepth, pData->iJHDRcolortype, + pData->iJHDRalphacompression, pData->iJHDRalphafilter, + pData->iJHDRalphainterlace, MNG_TRUE); + + pImage->pImgbuf->iAlphabitdepth = pData->iJHDRalphabitdepth; + pImage->pImgbuf->iJHDRcompression = pData->iJHDRimgcompression; + pImage->pImgbuf->iJHDRinterlace = pData->iJHDRimginterlace; + pImage->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth; + } + else /* update object 0 */ + { + iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pObjzero, + pData->iDatawidth, pData->iDataheight, + pData->iJHDRimgbitdepth, pData->iJHDRcolortype, + pData->iJHDRalphacompression, pData->iJHDRalphafilter, + pData->iJHDRalphainterlace, MNG_TRUE); + + ((mng_imagep)pData->pObjzero)->pImgbuf->iAlphabitdepth = pData->iJHDRalphabitdepth; + ((mng_imagep)pData->pObjzero)->pImgbuf->iJHDRcompression = pData->iJHDRimgcompression; + ((mng_imagep)pData->pObjzero)->pImgbuf->iJHDRinterlace = pData->iJHDRimginterlace; + ((mng_imagep)pData->pObjzero)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth; + } + } + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + + if (!pData->bHasDHDR) + { /* we're always storing a JPEG */ + if (pImage) /* real object ? */ + pData->pStoreobj = pImage; /* tell the row routines */ + else /* otherwise use object 0 */ + pData->pStoreobj = pData->pObjzero; + /* display "on-the-fly" ? */ + if ( +#ifndef MNG_SKIPCHUNK_MAGN + ( ((mng_imagep)pData->pStoreobj)->iMAGN_MethodX == 0) && + ( ((mng_imagep)pData->pStoreobj)->iMAGN_MethodY == 0) && +#endif + ( (pData->eImagetype == mng_it_jng ) || + (((mng_imagep)pData->pStoreobj)->bVisible) ) ) + { + next_layer (pData); /* that's a new layer then ! */ + + pData->iBreakpoint = 0; + + if (pData->bTimerset) /* timer break ? */ + pData->iBreakpoint = 7; + else + if (pData->bRunning) /* still running ? */ + { /* anything to display ? */ + if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt)) + { + set_display_routine (pData); /* then determine display routine */ + /* display from the object we store in */ + pData->pRetrieveobj = pData->pStoreobj; + } + } + } + } + + if (!pData->bTimerset) /* no timer break ? */ + { /* default row initialization ! */ +#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT + pData->ePng_imgtype=png_none; +#endif + pData->fInitrowproc = (mng_fptr)mng_init_rowproc; + + if ((!pData->bHasDHDR) || (pData->iDeltatype == MNG_DELTATYPE_REPLACE)) + { /* 8-bit JPEG ? */ + if (pData->iJHDRimgbitdepth == 8) + { /* intermediate row is 8-bit deep */ + pData->bIsRGBA16 = MNG_FALSE; + pData->iRowsamples = pData->iDatawidth; + + switch (pData->iJHDRcolortype) /* determine pixel processing routines */ + { + case MNG_COLORTYPE_JPEGGRAY : + { + pData->fStorerow2 = (mng_fptr)mng_store_jpeg_g8; + pData->fRetrieverow = (mng_fptr)mng_retrieve_g8; + pData->bIsOpaque = MNG_TRUE; + break; + } + case MNG_COLORTYPE_JPEGCOLOR : + { + pData->fStorerow2 = (mng_fptr)mng_store_jpeg_rgb8; + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8; + pData->bIsOpaque = MNG_TRUE; + break; + } + case MNG_COLORTYPE_JPEGGRAYA : + { + pData->fStorerow2 = (mng_fptr)mng_store_jpeg_ga8; + pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8; + pData->bIsOpaque = MNG_FALSE; + break; + } + case MNG_COLORTYPE_JPEGCOLORA : + { + pData->fStorerow2 = (mng_fptr)mng_store_jpeg_rgba8; + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; + pData->bIsOpaque = MNG_FALSE; + break; + } + } + } +#ifndef MNG_NO_16BIT_SUPPORT + else + { + pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ + + /* TODO: 12-bit JPEG */ + /* TODO: 8- + 12-bit JPEG (eg. type=20) */ + + } +#endif + /* possible IDAT alpha-channel ? */ + if (pData->iJHDRalphacompression == MNG_COMPRESSION_DEFLATE) + { + /* determine alpha processing routine */ +#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT + pData->fInitrowproc = (mng_fptr)mng_init_rowproc; +#endif + switch (pData->iJHDRalphabitdepth) + { +#ifndef MNG_OPTIMIZE_FOOTPRINT_INIT +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a1_ni; break; } + case 2 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a2_ni; break; } + case 4 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a4_ni; break; } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a8_ni; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a16_ni; break; } +#endif +#else +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { pData->ePng_imgtype = png_jpeg_a1; break; } + case 2 : { pData->ePng_imgtype = png_jpeg_a2; break; } + case 4 : { pData->ePng_imgtype = png_jpeg_a4; break; } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { pData->ePng_imgtype = png_jpeg_a8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->ePng_imgtype = png_jpeg_a16; break; } +#endif +#endif + } + } + else /* possible JDAA alpha-channel ? */ + if (pData->iJHDRalphacompression == MNG_COMPRESSION_BASELINEJPEG) + { /* 8-bit JPEG ? */ + if (pData->iJHDRimgbitdepth == 8) + { + if (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) + pData->fStorerow3 = (mng_fptr)mng_store_jpeg_g8_alpha; + else + if (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) + pData->fStorerow3 = (mng_fptr)mng_store_jpeg_rgb8_alpha; + } + else + { + /* TODO: 12-bit JPEG with 8-bit JDAA */ + } + } + /* initialize JPEG library */ + iRetcode = mngjpeg_initialize (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + else + { /* must be alpha add/replace !! */ + if ((pData->iDeltatype != MNG_DELTATYPE_BLOCKALPHAADD ) && + (pData->iDeltatype != MNG_DELTATYPE_BLOCKALPHAREPLACE) ) + MNG_ERROR (pData, MNG_INVDELTATYPE); + /* determine alpha processing routine */ +#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT + pData->fInitrowproc = (mng_fptr)mng_init_rowproc; +#endif + switch (pData->iJHDRalphabitdepth) + { +#ifndef MNG_OPTIMIZE_FOOTPRINT_INIT +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { pData->fInitrowproc = (mng_fptr)mng_init_g1_ni; break; } + case 2 : { pData->fInitrowproc = (mng_fptr)mng_init_g2_ni; break; } + case 4 : { pData->fInitrowproc = (mng_fptr)mng_init_g4_ni; break; } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { pData->fInitrowproc = (mng_fptr)mng_init_g8_ni; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fInitrowproc = (mng_fptr)mng_init_g16_ni; break; } +#endif +#else +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { pData->ePng_imgtype = png_jpeg_a1; break; } + case 2 : { pData->ePng_imgtype = png_jpeg_a2; break; } + case 4 : { pData->ePng_imgtype = png_jpeg_a4; break; } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { pData->ePng_imgtype = png_jpeg_a8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->ePng_imgtype = png_jpeg_a16; break; } +#endif +#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ + } + } + + pData->iFilterofs = 0; /* determine filter characteristics */ + pData->iLevel0 = 0; /* default levels */ + pData->iLevel1 = 0; + pData->iLevel2 = 0; + pData->iLevel3 = 0; + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iJHDRalphafilter == 0xC0) + { + if (pData->iJHDRalphabitdepth <= 8) + pData->iFilterofs = 1; + else + pData->iFilterofs = 2; + + } +#endif +#ifdef FILTER193 /* no adaptive filtering ? */ + if (pData->iJHDRalphafilter == 0xC1) + pData->iPixelofs = pData->iFilterofs; + else +#endif + pData->iPixelofs = pData->iFilterofs + 1; + + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +mng_retcode mng_process_display_jdaa (mng_datap pData, + mng_uint32 iRawlen, + mng_uint8p pRawdata) +#else +mng_retcode mng_process_display_jdaa (mng_datap pData) +#endif +{ + mng_retcode iRetcode = MNG_NOERROR; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAA, MNG_LC_START); +#endif + + if (!pData->bJPEGdecompress2) /* if we're not decompressing already */ + { + if (pData->fInitrowproc) /* initialize row-processing? */ + { + iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData); + pData->fInitrowproc = MNG_NULL; /* only call this once !!! */ + } + + if (!iRetcode) /* initialize decompress */ + iRetcode = mngjpeg_decompressinit2 (pData); + } + + if (!iRetcode) /* all ok? then decompress, my man */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mngjpeg_decompressdata2 (pData, iRawlen, pRawdata); +#else + iRetcode = mngjpeg_decompressdata2 (pData, pData->iRawlen, pData->pRawdata); +#endif + + if (iRetcode) + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +mng_retcode mng_process_display_jdat (mng_datap pData, + mng_uint32 iRawlen, + mng_uint8p pRawdata) +#else +mng_retcode mng_process_display_jdat (mng_datap pData) +#endif +{ + mng_retcode iRetcode = MNG_NOERROR; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAT, MNG_LC_START); +#endif + + if (pData->bRestorebkgd) /* need to restore the background ? */ + { + pData->bRestorebkgd = MNG_FALSE; + iRetcode = load_bkgdlayer (pData); + + pData->iLayerseq++; /* and it counts as a layer then ! */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + + if (!pData->bJPEGdecompress) /* if we're not decompressing already */ + { + if (pData->fInitrowproc) /* initialize row-processing? */ + { + iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData); + pData->fInitrowproc = MNG_NULL; /* only call this once !!! */ + } + + if (!iRetcode) /* initialize decompress */ + iRetcode = mngjpeg_decompressinit (pData); + } + + if (!iRetcode) /* all ok? then decompress, my man */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mngjpeg_decompressdata (pData, iRawlen, pRawdata); +#else + iRetcode = mngjpeg_decompressdata (pData, pData->iRawlen, pData->pRawdata); +#endif + + if (iRetcode) + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +mng_retcode mng_process_display_dhdr (mng_datap pData, + mng_uint16 iObjectid, + mng_uint8 iImagetype, + mng_uint8 iDeltatype, + mng_uint32 iBlockwidth, + mng_uint32 iBlockheight, + mng_uint32 iBlockx, + mng_uint32 iBlocky) +#else +mng_retcode mng_process_display_dhdr (mng_datap pData) +#endif +{ + mng_imagep pImage; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DHDR, MNG_LC_START); +#endif + + pData->fInitrowproc = MNG_NULL; /* do nothing by default */ + pData->fDisplayrow = MNG_NULL; + pData->fCorrectrow = MNG_NULL; + pData->fStorerow = MNG_NULL; + pData->fProcessrow = MNG_NULL; + pData->pStoreobj = MNG_NULL; + + pData->fDeltagetrow = MNG_NULL; + pData->fDeltaaddrow = MNG_NULL; + pData->fDeltareplacerow = MNG_NULL; + pData->fDeltaputrow = MNG_NULL; + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pImage = mng_find_imageobject (pData, iObjectid); +#else + pImage = mng_find_imageobject (pData, pData->iDHDRobjectid); +#endif + + if (pImage) /* object exists ? */ + { + if (pImage->pImgbuf->bConcrete) /* is it concrete ? */ + { /* previous magnification to be done ? */ +#ifndef MNG_SKIPCHUNK_MAGN + if ((pImage->iMAGN_MethodX) || (pImage->iMAGN_MethodY)) + { + iRetcode = mng_magnify_imageobject (pData, pImage); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif + /* save delta fields */ + pData->pDeltaImage = (mng_ptr)pImage; +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pData->iDeltaImagetype = iImagetype; + pData->iDeltatype = iDeltatype; + pData->iDeltaBlockwidth = iBlockwidth; + pData->iDeltaBlockheight = iBlockheight; + pData->iDeltaBlockx = iBlockx; + pData->iDeltaBlocky = iBlocky; +#else + pData->iDeltaImagetype = pData->iDHDRimagetype; + pData->iDeltatype = pData->iDHDRdeltatype; + pData->iDeltaBlockwidth = pData->iDHDRblockwidth; + pData->iDeltaBlockheight = pData->iDHDRblockheight; + pData->iDeltaBlockx = pData->iDHDRblockx; + pData->iDeltaBlocky = pData->iDHDRblocky; +#endif + /* restore target-object fields */ + pData->iDatawidth = pImage->pImgbuf->iWidth; + pData->iDataheight = pImage->pImgbuf->iHeight; + pData->iBitdepth = pImage->pImgbuf->iBitdepth; + pData->iColortype = pImage->pImgbuf->iColortype; + pData->iCompression = pImage->pImgbuf->iCompression; + pData->iFilter = pImage->pImgbuf->iFilter; + pData->iInterlace = pImage->pImgbuf->iInterlace; + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if ((iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || + (iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth; + else + if ((iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) || + (iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) ) + pData->iBitdepth = pImage->pImgbuf->iAlphasampledepth; + else + if ((iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) || + (iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) ) + pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth; +#else + if ((pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) || + (pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth; + else + if ((pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) || + (pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) ) + pData->iBitdepth = pImage->pImgbuf->iAlphasampledepth; + else + if ((pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) || + (pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) ) + pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth; +#endif + +#ifdef MNG_INCLUDE_JNG + pData->iJHDRimgbitdepth = pImage->pImgbuf->iBitdepth; + pData->iJHDRcolortype = pImage->pImgbuf->iColortype; + pData->iJHDRimgcompression = pImage->pImgbuf->iJHDRcompression; + pData->iJHDRimginterlace = pImage->pImgbuf->iJHDRinterlace; + pData->iJHDRalphacompression = pImage->pImgbuf->iCompression; + pData->iJHDRalphafilter = pImage->pImgbuf->iFilter; + pData->iJHDRalphainterlace = pImage->pImgbuf->iInterlace; + pData->iJHDRalphabitdepth = pImage->pImgbuf->iAlphabitdepth; +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + /* block size specified ? */ + if (iDeltatype != MNG_DELTATYPE_NOCHANGE) + { /* block entirely within target ? */ + if (iDeltatype != MNG_DELTATYPE_REPLACE) + { + if (((iBlockx + iBlockwidth ) > pData->iDatawidth ) || + ((iBlocky + iBlockheight) > pData->iDataheight) ) + MNG_ERROR (pData, MNG_INVALIDBLOCK); + } + + pData->iDatawidth = iBlockwidth; + pData->iDataheight = iBlockheight; + } +#else + /* block size specified ? */ + if (pData->iDHDRdeltatype != MNG_DELTATYPE_NOCHANGE) + { /* block entirely within target ? */ + if (pData->iDHDRdeltatype != MNG_DELTATYPE_REPLACE) + { + if (((pData->iDHDRblockx + pData->iDHDRblockwidth ) > pData->iDatawidth ) || + ((pData->iDHDRblocky + pData->iDHDRblockheight) > pData->iDataheight) ) + MNG_ERROR (pData, MNG_INVALIDBLOCK); + } + + pData->iDatawidth = pData->iDHDRblockwidth; + pData->iDataheight = pData->iDHDRblockheight; + } +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + switch (iDeltatype) /* determine nr of delta-channels */ +#else + switch (pData->iDHDRdeltatype) /* determine nr of delta-channels */ +#endif + { + case MNG_DELTATYPE_BLOCKALPHAADD : ; + case MNG_DELTATYPE_BLOCKALPHAREPLACE : + { +#ifdef MNG_INCLUDE_JNG + if ((pData->iColortype == MNG_COLORTYPE_GRAYA ) || + (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) ) + { + pData->iColortype = MNG_COLORTYPE_GRAY; + pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY; + } + else + if ((pData->iColortype == MNG_COLORTYPE_RGBA ) || + (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) + { + pData->iColortype = MNG_COLORTYPE_GRAY; + pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY; + } +#else + if (pData->iColortype == MNG_COLORTYPE_GRAYA) + pData->iColortype = MNG_COLORTYPE_GRAY; + else + if (pData->iColortype == MNG_COLORTYPE_RGBA) + pData->iColortype = MNG_COLORTYPE_GRAY; +#endif + else /* target has no alpha; that sucks! */ + MNG_ERROR (pData, MNG_TARGETNOALPHA); + + break; + } + + case MNG_DELTATYPE_BLOCKCOLORADD : ; + case MNG_DELTATYPE_BLOCKCOLORREPLACE : + { +#ifdef MNG_INCLUDE_JNG + if ((pData->iColortype == MNG_COLORTYPE_GRAYA ) || + (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) ) + { + pData->iColortype = MNG_COLORTYPE_GRAY; + pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY; + } + else + if ((pData->iColortype == MNG_COLORTYPE_RGBA ) || + (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) + { + pData->iColortype = MNG_COLORTYPE_RGB; + pData->iJHDRcolortype = MNG_COLORTYPE_JPEGCOLOR; + } +#else + if (pData->iColortype == MNG_COLORTYPE_GRAYA) + pData->iColortype = MNG_COLORTYPE_GRAY; + else + if (pData->iColortype == MNG_COLORTYPE_RGBA) + pData->iColortype = MNG_COLORTYPE_RGB; +#endif + else /* target has no alpha; that sucks! */ + MNG_ERROR (pData, MNG_TARGETNOALPHA); + + break; + } + + } + /* full image replace ? */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (iDeltatype == MNG_DELTATYPE_REPLACE) +#else + if (pData->iDHDRdeltatype == MNG_DELTATYPE_REPLACE) +#endif + { + iRetcode = mng_reset_object_details (pData, pImage, + pData->iDatawidth, pData->iDataheight, + pData->iBitdepth, pData->iColortype, + pData->iCompression, pData->iFilter, + pData->iInterlace, MNG_FALSE); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + pData->pStoreobj = pImage; /* and store straight into this object */ + } + else + { + mng_imagedatap pBufzero, pBuf; + /* we store in object 0 and process it later */ + pData->pStoreobj = pData->pObjzero; + /* make sure to initialize object 0 then */ + iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pObjzero, + pData->iDatawidth, pData->iDataheight, + pData->iBitdepth, pData->iColortype, + pData->iCompression, pData->iFilter, + pData->iInterlace, MNG_TRUE); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + pBuf = pImage->pImgbuf; /* copy possible palette & cheap transparency */ + pBufzero = ((mng_imagep)pData->pObjzero)->pImgbuf; + + pBufzero->bHasPLTE = pBuf->bHasPLTE; + pBufzero->bHasTRNS = pBuf->bHasTRNS; + + if (pBufzero->bHasPLTE) /* copy palette ? */ + { + mng_uint32 iX; + + pBufzero->iPLTEcount = pBuf->iPLTEcount; + + for (iX = 0; iX < pBuf->iPLTEcount; iX++) + { + pBufzero->aPLTEentries [iX].iRed = pBuf->aPLTEentries [iX].iRed; + pBufzero->aPLTEentries [iX].iGreen = pBuf->aPLTEentries [iX].iGreen; + pBufzero->aPLTEentries [iX].iBlue = pBuf->aPLTEentries [iX].iBlue; + } + } + + if (pBufzero->bHasTRNS) /* copy cheap transparency ? */ + { + pBufzero->iTRNSgray = pBuf->iTRNSgray; + pBufzero->iTRNSred = pBuf->iTRNSred; + pBufzero->iTRNSgreen = pBuf->iTRNSgreen; + pBufzero->iTRNSblue = pBuf->iTRNSblue; + pBufzero->iTRNScount = pBuf->iTRNScount; + + MNG_COPY (pBufzero->aTRNSentries, pBuf->aTRNSentries, + sizeof (pBufzero->aTRNSentries)); + } + /* process immediately if bitdepth & colortype are equal */ + pData->bDeltaimmediate = + (mng_bool)((pData->bDisplaying) && (!pData->bSkipping) && + ((pData->bRunning) || (pData->bSearching)) && + (pData->iBitdepth == ((mng_imagep)pData->pDeltaImage)->pImgbuf->iBitdepth ) && + (pData->iColortype == ((mng_imagep)pData->pDeltaImage)->pImgbuf->iColortype) ); + } + +#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT + pData->fInitrowproc = (mng_fptr)mng_init_rowproc; + pData->ePng_imgtype = mng_png_imgtype (pData->iColortype, pData->iBitdepth); +#else + switch (pData->iColortype) /* determine row initialization routine */ + { + case 0 : { /* gray */ + switch (pData->iBitdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g1_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g1_i; + + break; + } + case 2 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g2_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g2_i; + + break; + } + case 4 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g4_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g4_i; + + break; + } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g8_i; + + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_g16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_g16_i; + + break; + } +#endif + } + + break; + } + case 2 : { /* rgb */ + switch (pData->iBitdepth) + { + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i; + + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i; + + break; + } +#endif + } + + break; + } + case 3 : { /* indexed */ + switch (pData->iBitdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx1_i; + + break; + } + case 2 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx2_i; + + break; + } + case 4 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx4_i; + + break; + } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_idx8_i; + + break; + } + } + + break; + } + case 4 : { /* gray+alpha */ + switch (pData->iBitdepth) + { + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_ga8_i; + + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_ga16_i; + + break; + } +#endif + } + + break; + } + case 6 : { /* rgb+alpha */ + switch (pData->iBitdepth) + { + case 8 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i; + + break; + } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { + if (!pData->iInterlace) + pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni; + else + pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i; + + break; + } +#endif + } + + break; + } + } +#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ + } + else + MNG_ERROR (pData, MNG_OBJNOTCONCRETE); + + } + else + MNG_ERROR (pData, MNG_OBJECTUNKNOWN); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +mng_retcode mng_process_display_prom (mng_datap pData, + mng_uint8 iBitdepth, + mng_uint8 iColortype, + mng_uint8 iFilltype) +#else +mng_retcode mng_process_display_prom (mng_datap pData) +#endif +{ + mng_imagep pImage; + mng_imagedatap pBuf; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PROM, MNG_LC_START); +#endif + + if (!pData->pDeltaImage) /* gotta have this now! */ + MNG_ERROR (pData, MNG_INVALIDDELTA); + + pImage = (mng_imagep)pData->pDeltaImage; + pBuf = pImage->pImgbuf; + /* can't demote bitdepth! */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (iBitdepth < pBuf->iBitdepth) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if ( ((pBuf->iColortype == MNG_COLORTYPE_GRAY ) && + (iColortype != MNG_COLORTYPE_GRAY ) && + (iColortype != MNG_COLORTYPE_GRAYA ) && + (iColortype != MNG_COLORTYPE_RGB ) && + (iColortype != MNG_COLORTYPE_RGBA ) ) || + ((pBuf->iColortype == MNG_COLORTYPE_GRAYA ) && + (iColortype != MNG_COLORTYPE_GRAYA ) && + (iColortype != MNG_COLORTYPE_RGBA ) ) || + ((pBuf->iColortype == MNG_COLORTYPE_RGB ) && + (iColortype != MNG_COLORTYPE_RGB ) && + (iColortype != MNG_COLORTYPE_RGBA ) ) || + ((pBuf->iColortype == MNG_COLORTYPE_RGBA ) && + (iColortype != MNG_COLORTYPE_RGBA ) ) || +#ifdef MNG_INCLUDE_JNG + ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAY ) && + (iColortype != MNG_COLORTYPE_JPEGGRAY ) && + (iColortype != MNG_COLORTYPE_JPEGCOLOR ) && + (iColortype != MNG_COLORTYPE_JPEGGRAYA ) && + (iColortype != MNG_COLORTYPE_JPEGCOLORA) ) || + ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLOR ) && + (iColortype != MNG_COLORTYPE_JPEGCOLOR ) && + (iColortype != MNG_COLORTYPE_JPEGCOLORA) ) || + ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAYA ) && + (iColortype != MNG_COLORTYPE_JPEGGRAYA ) && + (iColortype != MNG_COLORTYPE_JPEGCOLORA) ) || + ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLORA) && + (iColortype != MNG_COLORTYPE_JPEGCOLORA) ) || +#endif + ((pBuf->iColortype == MNG_COLORTYPE_INDEXED ) && + (iColortype != MNG_COLORTYPE_INDEXED ) && + (iColortype != MNG_COLORTYPE_RGB ) && + (iColortype != MNG_COLORTYPE_RGBA ) ) ) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + + iRetcode = mng_promote_imageobject (pData, pImage, iBitdepth, iColortype, iFilltype); +#else + if (pData->iPROMbitdepth < pBuf->iBitdepth) + MNG_ERROR (pData, MNG_INVALIDBITDEPTH); + + if ( ((pBuf->iColortype == MNG_COLORTYPE_GRAY ) && + (pData->iPROMcolortype != MNG_COLORTYPE_GRAY ) && + (pData->iPROMcolortype != MNG_COLORTYPE_GRAYA ) && + (pData->iPROMcolortype != MNG_COLORTYPE_RGB ) && + (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) || + ((pBuf->iColortype == MNG_COLORTYPE_GRAYA ) && + (pData->iPROMcolortype != MNG_COLORTYPE_GRAYA ) && + (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) || + ((pBuf->iColortype == MNG_COLORTYPE_RGB ) && + (pData->iPROMcolortype != MNG_COLORTYPE_RGB ) && + (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) || + ((pBuf->iColortype == MNG_COLORTYPE_RGBA ) && + (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) || +#ifdef MNG_INCLUDE_JNG + ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAY ) && + (pData->iPROMcolortype != MNG_COLORTYPE_JPEGGRAY ) && + (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLOR ) && + (pData->iPROMcolortype != MNG_COLORTYPE_JPEGGRAYA ) && + (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLORA) ) || + ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLOR ) && + (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLOR ) && + (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLORA) ) || + ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAYA ) && + (pData->iPROMcolortype != MNG_COLORTYPE_JPEGGRAYA ) && + (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLORA) ) || + ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLORA) && + (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLORA) ) || +#endif + ((pBuf->iColortype == MNG_COLORTYPE_INDEXED ) && + (pData->iPROMcolortype != MNG_COLORTYPE_INDEXED ) && + (pData->iPROMcolortype != MNG_COLORTYPE_RGB ) && + (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) ) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + + iRetcode = mng_promote_imageobject (pData, pImage, pData->iPROMbitdepth, + pData->iPROMcolortype, pData->iPROMfilltype); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PROM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode mng_process_display_ipng (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IPNG, MNG_LC_START); +#endif + /* indicate it for what it is now */ + pData->iDeltaImagetype = MNG_IMAGETYPE_PNG; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IPNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG +mng_retcode mng_process_display_ijng (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IJNG, MNG_LC_START); +#endif + /* indicate it for what it is now */ + pData->iDeltaImagetype = MNG_IMAGETYPE_JNG; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IJNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +mng_retcode mng_process_display_pplt (mng_datap pData, + mng_uint8 iType, + mng_uint32 iCount, + mng_palette8ep paIndexentries, + mng_uint8p paAlphaentries, + mng_uint8p paUsedentries) +#else +mng_retcode mng_process_display_pplt (mng_datap pData) +#endif +{ + mng_uint32 iX; + mng_imagep pImage = (mng_imagep)pData->pObjzero; + mng_imagedatap pBuf = pImage->pImgbuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PPLT, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iX = iCount; +#else + iX = pData->iPPLTcount; +#endif +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + switch (iType) +#else + switch (pData->iPPLTtype) +#endif + { + case MNG_DELTATYPE_REPLACERGB : + { +#ifdef MNG_DECREMENT_LOOPS + for (; iX > 0;iX--) +#else +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + for (iX = 0; iX < iCount; iX++) +#else + for (iX = 0; iX < pData->iPPLTcount; iX++) +#endif +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (paUsedentries [iX]) + { + pBuf->aPLTEentries [iX].iRed = paIndexentries [iX].iRed; + pBuf->aPLTEentries [iX].iGreen = paIndexentries [iX].iGreen; + pBuf->aPLTEentries [iX].iBlue = paIndexentries [iX].iBlue; + } +#else + if (pData->paPPLTusedentries [iX]) + { + pBuf->aPLTEentries [iX].iRed = pData->paPPLTindexentries [iX].iRed; + pBuf->aPLTEentries [iX].iGreen = pData->paPPLTindexentries [iX].iGreen; + pBuf->aPLTEentries [iX].iBlue = pData->paPPLTindexentries [iX].iBlue; + } +#endif + } + + break; + } + case MNG_DELTATYPE_DELTARGB : + { +#ifdef MNG_DECREMENT_LOOPS + for (; iX > 0;iX--) +#else +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + for (iX = 0; iX < iCount; iX++) +#else + for (iX = 0; iX < pData->iPPLTcount; iX++) +#endif +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (paUsedentries [iX]) + { + pBuf->aPLTEentries [iX].iRed = + (mng_uint8)(pBuf->aPLTEentries [iX].iRed + + paIndexentries [iX].iRed ); + pBuf->aPLTEentries [iX].iGreen = + (mng_uint8)(pBuf->aPLTEentries [iX].iGreen + + paIndexentries [iX].iGreen); + pBuf->aPLTEentries [iX].iBlue = + (mng_uint8)(pBuf->aPLTEentries [iX].iBlue + + paIndexentries [iX].iBlue ); + } +#else + if (pData->paPPLTusedentries [iX]) + { + pBuf->aPLTEentries [iX].iRed = + (mng_uint8)(pBuf->aPLTEentries [iX].iRed + + pData->paPPLTindexentries [iX].iRed ); + pBuf->aPLTEentries [iX].iGreen = + (mng_uint8)(pBuf->aPLTEentries [iX].iGreen + + pData->paPPLTindexentries [iX].iGreen); + pBuf->aPLTEentries [iX].iBlue = + (mng_uint8)(pBuf->aPLTEentries [iX].iBlue + + pData->paPPLTindexentries [iX].iBlue ); + } +#endif + } + + break; + } + case MNG_DELTATYPE_REPLACEALPHA : + { +#ifdef MNG_DECREMENT_LOOPS + for (; iX > 0;iX--) +#else +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + for (iX = 0; iX < iCount; iX++) +#else + for (iX = 0; iX < pData->iPPLTcount; iX++) +#endif +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (paUsedentries [iX]) + pBuf->aTRNSentries [iX] = paAlphaentries [iX]; + } +#else + if (pData->paPPLTusedentries [iX]) + pBuf->aTRNSentries [iX] = pData->paPPLTalphaentries [iX]; + } +#endif + + break; + } + case MNG_DELTATYPE_DELTAALPHA : + { +#ifdef MNG_DECREMENT_LOOPS + for (; iX > 0;iX--) +#else +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + for (iX = 0; iX < iCount; iX++) +#else + for (iX = 0; iX < pData->iPPLTcount; iX++) +#endif +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (paUsedentries [iX]) + pBuf->aTRNSentries [iX] = + (mng_uint8)(pBuf->aTRNSentries [iX] + + paAlphaentries [iX]); +#else + if (pData->paPPLTusedentries [iX]) + pBuf->aTRNSentries [iX] = + (mng_uint8)(pBuf->aTRNSentries [iX] + + pData->paPPLTalphaentries [iX]); +#endif + } + + break; + } + case MNG_DELTATYPE_REPLACERGBA : + { +#ifdef MNG_DECREMENT_LOOPS + for (; iX > 0;iX--) +#else +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + for (iX = 0; iX < iCount; iX++) +#else + for (iX = 0; iX < pData->iPPLTcount; iX++) +#endif +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (paUsedentries [iX]) + { + pBuf->aPLTEentries [iX].iRed = paIndexentries [iX].iRed; + pBuf->aPLTEentries [iX].iGreen = paIndexentries [iX].iGreen; + pBuf->aPLTEentries [iX].iBlue = paIndexentries [iX].iBlue; + pBuf->aTRNSentries [iX] = paAlphaentries [iX]; + } +#else + if (pData->paPPLTusedentries [iX]) + { + pBuf->aPLTEentries [iX].iRed = pData->paPPLTindexentries [iX].iRed; + pBuf->aPLTEentries [iX].iGreen = pData->paPPLTindexentries [iX].iGreen; + pBuf->aPLTEentries [iX].iBlue = pData->paPPLTindexentries [iX].iBlue; + pBuf->aTRNSentries [iX] = pData->paPPLTalphaentries [iX]; + } +#endif + } + + break; + } + case MNG_DELTATYPE_DELTARGBA : + { +#ifdef MNG_DECREMENT_LOOPS + for (; iX > 0;iX--) +#else +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + for (iX = 0; iX < iCount; iX++) +#else + for (iX = 0; iX < pData->iPPLTcount; iX++) +#endif +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (paUsedentries [iX]) + { + pBuf->aPLTEentries [iX].iRed = + (mng_uint8)(pBuf->aPLTEentries [iX].iRed + + paIndexentries [iX].iRed ); + pBuf->aPLTEentries [iX].iGreen = + (mng_uint8)(pBuf->aPLTEentries [iX].iGreen + + paIndexentries [iX].iGreen); + pBuf->aPLTEentries [iX].iBlue = + (mng_uint8)(pBuf->aPLTEentries [iX].iBlue + + paIndexentries [iX].iBlue ); + pBuf->aTRNSentries [iX] = + (mng_uint8)(pBuf->aTRNSentries [iX] + + paAlphaentries [iX]); + } +#else + if (pData->paPPLTusedentries [iX]) + { + pBuf->aPLTEentries [iX].iRed = + (mng_uint8)(pBuf->aPLTEentries [iX].iRed + + pData->paPPLTindexentries [iX].iRed ); + pBuf->aPLTEentries [iX].iGreen = + (mng_uint8)(pBuf->aPLTEentries [iX].iGreen + + pData->paPPLTindexentries [iX].iGreen); + pBuf->aPLTEentries [iX].iBlue = + (mng_uint8)(pBuf->aPLTEentries [iX].iBlue + + pData->paPPLTindexentries [iX].iBlue ); + pBuf->aTRNSentries [iX] = + (mng_uint8)(pBuf->aTRNSentries [iX] + + pData->paPPLTalphaentries [iX]); + } +#endif + } + + break; + } + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if ((iType != MNG_DELTATYPE_REPLACERGB) && (iType != MNG_DELTATYPE_DELTARGB)) +#else + if ((pData->iPPLTtype != MNG_DELTATYPE_REPLACERGB) && + (pData->iPPLTtype != MNG_DELTATYPE_DELTARGB ) ) +#endif + { + if (pBuf->bHasTRNS) + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (iCount > pBuf->iTRNScount) + pBuf->iTRNScount = iCount; +#else + if (pData->iPPLTcount > pBuf->iTRNScount) + pBuf->iTRNScount = pData->iPPLTcount; +#endif + } + else + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pBuf->iTRNScount = iCount; + pBuf->bHasTRNS = MNG_TRUE; +#else + pBuf->iTRNScount = pData->iPPLTcount; + pBuf->bHasTRNS = MNG_TRUE; +#endif + } + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if ((iType != MNG_DELTATYPE_REPLACEALPHA) && (iType != MNG_DELTATYPE_DELTAALPHA)) +#else + if ((pData->iPPLTtype != MNG_DELTATYPE_REPLACEALPHA) && + (pData->iPPLTtype != MNG_DELTATYPE_DELTAALPHA ) ) +#endif + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (iCount > pBuf->iPLTEcount) + pBuf->iPLTEcount = iCount; +#else + if (pData->iPPLTcount > pBuf->iPLTEcount) + pBuf->iPLTEcount = pData->iPPLTcount; +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PPLT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MAGN +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +mng_retcode mng_process_display_magn (mng_datap pData, + mng_uint16 iFirstid, + mng_uint16 iLastid, + mng_uint8 iMethodX, + mng_uint16 iMX, + mng_uint16 iMY, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint16 iMT, + mng_uint16 iMB, + mng_uint8 iMethodY) +#else +mng_retcode mng_process_display_magn (mng_datap pData) +#endif +{ + mng_uint16 iX; + mng_imagep pImage; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_START); +#endif + /* iterate the object-ids */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + for (iX = iFirstid; iX <= iLastid; iX++) +#else + for (iX = pData->iMAGNfirstid; iX <= pData->iMAGNlastid; iX++) +#endif + { + if (iX == 0) /* process object 0 ? */ + { + pImage = (mng_imagep)pData->pObjzero; + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pImage->iMAGN_MethodX = iMethodX; + pImage->iMAGN_MethodY = iMethodY; + pImage->iMAGN_MX = iMX; + pImage->iMAGN_MY = iMY; + pImage->iMAGN_ML = iML; + pImage->iMAGN_MR = iMR; + pImage->iMAGN_MT = iMT; + pImage->iMAGN_MB = iMB; +#else + pImage->iMAGN_MethodX = pData->iMAGNmethodX; + pImage->iMAGN_MethodY = pData->iMAGNmethodY; + pImage->iMAGN_MX = pData->iMAGNmX; + pImage->iMAGN_MY = pData->iMAGNmY; + pImage->iMAGN_ML = pData->iMAGNmL; + pImage->iMAGN_MR = pData->iMAGNmR; + pImage->iMAGN_MT = pData->iMAGNmT; + pImage->iMAGN_MB = pData->iMAGNmB; +#endif + } + else + { + pImage = mng_find_imageobject (pData, iX); + /* object exists & is not frozen ? */ + if ((pImage) && (!pImage->bFrozen)) + { /* previous magnification to be done ? */ + if ((pImage->iMAGN_MethodX) || (pImage->iMAGN_MethodY)) + { + mng_retcode iRetcode = mng_magnify_imageobject (pData, pImage); + if (iRetcode) /* on error bail out */ + return iRetcode; + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pImage->iMAGN_MethodX = iMethodX; + pImage->iMAGN_MethodY = iMethodY; + pImage->iMAGN_MX = iMX; + pImage->iMAGN_MY = iMY; + pImage->iMAGN_ML = iML; + pImage->iMAGN_MR = iMR; + pImage->iMAGN_MT = iMT; + pImage->iMAGN_MB = iMB; +#else + pImage->iMAGN_MethodX = pData->iMAGNmethodX; + pImage->iMAGN_MethodY = pData->iMAGNmethodY; + pImage->iMAGN_MX = pData->iMAGNmX; + pImage->iMAGN_MY = pData->iMAGNmY; + pImage->iMAGN_ML = pData->iMAGNmL; + pImage->iMAGN_MR = pData->iMAGNmR; + pImage->iMAGN_MT = pData->iMAGNmT; + pImage->iMAGN_MB = pData->iMAGNmB; +#endif + } + } + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pData->iMAGNfromid = iFirstid; + pData->iMAGNtoid = iLastid; + iX = iFirstid; +#else + pData->iMAGNfromid = pData->iMAGNfirstid; + pData->iMAGNtoid = pData->iMAGNlastid; + iX = pData->iMAGNfirstid; +#endif + /* iterate again for showing */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + while ((iX <= iLastid) && (!pData->bTimerset)) +#else + while ((iX <= pData->iMAGNlastid) && (!pData->bTimerset)) +#endif + { + pData->iMAGNcurrentid = iX; + + if (iX) /* only real objects ! */ + { + pImage = mng_find_imageobject (pData, iX); + /* object exists & is not frozen & + is visible & is viewable ? */ + if ((pImage) && (!pImage->bFrozen) && + (pImage->bVisible) && (pImage->bViewable)) + { + mng_retcode iRetcode = mng_display_image (pData, pImage, MNG_FALSE); + if (iRetcode) + return iRetcode; + } + } + + iX++; + } + + if (pData->bTimerset) /* broken ? */ + pData->iBreakpoint = 9; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_process_display_magn2 (mng_datap pData) +{ + mng_uint16 iX; + mng_imagep pImage; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_START); +#endif + + iX = pData->iMAGNcurrentid; + /* iterate again for showing */ + while ((iX <= pData->iMAGNtoid) && (!pData->bTimerset)) + { + pData->iMAGNcurrentid = iX; + + if (iX) /* only real objects ! */ + { + pImage = mng_find_imageobject (pData, iX); + /* object exists & is not frozen & + is visible & is viewable ? */ + if ((pImage) && (!pImage->bFrozen) && + (pImage->bVisible) && (pImage->bViewable)) + { + mng_retcode iRetcode = mng_display_image (pData, pImage, MNG_FALSE); + if (iRetcode) + return iRetcode; + } + } + + iX++; + } + + if (pData->bTimerset) /* broken ? */ + pData->iBreakpoint = 9; + else + pData->iBreakpoint = 0; /* not again ! */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +mng_retcode mng_process_display_past (mng_datap pData, + mng_uint16 iTargetid, + mng_uint8 iTargettype, + mng_int32 iTargetx, + mng_int32 iTargety, + mng_uint32 iCount, + mng_ptr pSources) +#else +mng_retcode mng_process_display_past (mng_datap pData) +#endif +{ + mng_retcode iRetcode = MNG_NOERROR; + mng_imagep pTargetimg; + mng_imagep pSourceimg; +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + mng_past_sourcep pSource = (mng_past_sourcep)pSources; +#else + mng_past_sourcep pSource = (mng_past_sourcep)pData->pPASTsources; +#endif + mng_uint32 iX = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_START); +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (iTargetid) /* a real destination object ? */ +#else + if (pData->iPASTtargetid) /* a real destination object ? */ +#endif + { /* let's find it then */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pTargetimg = (mng_imagep)mng_find_imageobject (pData, iTargetid); +#else + pTargetimg = (mng_imagep)mng_find_imageobject (pData, pData->iPASTtargetid); +#endif + + if (!pTargetimg) /* if it doesn't exists; do a barf */ + MNG_ERROR (pData, MNG_OBJECTUNKNOWN); + /* it's gotta be abstract !!! */ + if (pTargetimg->pImgbuf->bConcrete) + MNG_ERROR (pData, MNG_OBJNOTABSTRACT); + /* we want 32-/64-bit RGBA to play with ! */ + if ((pTargetimg->pImgbuf->iBitdepth <= MNG_BITDEPTH_8) || + (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_GRAY) || + (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_RGB) || + (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_INDEXED) || + (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_GRAYA) ) + iRetcode = mng_promote_imageobject (pData, pTargetimg, MNG_BITDEPTH_8, + MNG_COLORTYPE_RGBA, + MNG_FILLMETHOD_LEFTBITREPLICATE); + else + if ((pTargetimg->pImgbuf->iBitdepth > MNG_BITDEPTH_8) && + ((pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_GRAY) || + (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_RGB) || + (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_GRAYA) ) ) + iRetcode = mng_promote_imageobject (pData, pTargetimg, MNG_BITDEPTH_16, + MNG_COLORTYPE_RGBA, + MNG_FILLMETHOD_LEFTBITREPLICATE); +#ifdef MNG_INCLUDE_JNG + else + if ((pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_JPEGGRAY) || + (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_JPEGCOLOR) || + (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_JPEGGRAYA) ) + iRetcode = mng_promote_imageobject (pData, pTargetimg, + pTargetimg->pImgbuf->iBitdepth, + MNG_COLORTYPE_JPEGCOLORA, + MNG_FILLMETHOD_LEFTBITREPLICATE); +#endif + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* make it really abstract ? */ + if (!pTargetimg->pImgbuf->bCorrected) + { + iRetcode = mng_colorcorrect_object (pData, pTargetimg); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } + else + { /* pasting into object 0 !!! */ + pTargetimg = (mng_imagep)pData->pObjzero; + /* is it usable ??? */ + if ((pTargetimg->bClipped) && + (pTargetimg->iClipr > pTargetimg->iPosx) && + (pTargetimg->iClipb > pTargetimg->iPosy)) + { + /* make it 32-bit RGBA please !!! */ + iRetcode = mng_reset_object_details (pData, pTargetimg, + pTargetimg->iClipr - pTargetimg->iPosx, + pTargetimg->iClipb - pTargetimg->iPosy, + MNG_BITDEPTH_8, MNG_COLORTYPE_RGBA, + 0, 0, 0, MNG_FALSE); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + else + pTargetimg = MNG_NULL; /* clipped beyond visibility ! */ + } + + if (pTargetimg) /* usable destination ? */ + { + mng_int32 iSourceY; + mng_int32 iSourceYinc; + mng_int32 iSourcerowsize; + mng_int32 iSourcesamples; + mng_bool bSourceRGBA16; + mng_int32 iTargetY; + mng_int32 iTargetrowsize; + mng_int32 iTargetsamples; + mng_bool bTargetRGBA16 = MNG_FALSE; + mng_int32 iTemprowsize; + mng_imagedatap pBuf; +#ifndef MNG_SKIPCHUNK_MAGN + /* needs magnification ? */ + if ((pTargetimg->iMAGN_MethodX) || (pTargetimg->iMAGN_MethodY)) + iRetcode = mng_magnify_imageobject (pData, pTargetimg); +#endif + + if (!iRetcode) /* still ok ? */ + { + bTargetRGBA16 = (mng_bool)(pTargetimg->pImgbuf->iBitdepth > 8); + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + switch (iTargettype) /* determine target x/y */ +#else + switch (pData->iPASTtargettype) /* determine target x/y */ +#endif + { + case 0 : { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pData->iPastx = iTargetx; + pData->iPasty = iTargety; +#else + pData->iPastx = pData->iPASTtargetx; + pData->iPasty = pData->iPASTtargety; +#endif + break; + } + + case 1 : { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pData->iPastx = pTargetimg->iPastx + iTargetx; + pData->iPasty = pTargetimg->iPasty + iTargety; +#else + pData->iPastx = pTargetimg->iPastx + pData->iPASTtargetx; + pData->iPasty = pTargetimg->iPasty + pData->iPASTtargety; +#endif + break; + } + + case 2 : { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pData->iPastx += iTargetx; + pData->iPasty += iTargety; +#else + pData->iPastx += pData->iPASTtargetx; + pData->iPasty += pData->iPASTtargety; +#endif + break; + } + } + /* save for next time ... */ + pTargetimg->iPastx = pData->iPastx; + pTargetimg->iPasty = pData->iPasty; + /* address destination for row-routines */ + pData->pStoreobj = (mng_objectp)pTargetimg; + pData->pStorebuf = (mng_objectp)pTargetimg->pImgbuf; + } + /* process the sources one by one */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + while ((!iRetcode) && (iX < iCount)) +#else + while ((!iRetcode) && (iX < pData->iPASTcount)) +#endif + { /* find the little bastards first */ + pSourceimg = (mng_imagep)mng_find_imageobject (pData, pSource->iSourceid); + /* exists and viewable? */ + if ((pSourceimg) && (pSourceimg->bViewable)) + { /* needs magnification ? */ +#ifndef MNG_SKIPCHUNK_MAGN + if ((pSourceimg->iMAGN_MethodX) || (pSourceimg->iMAGN_MethodY)) + iRetcode = mng_magnify_imageobject (pData, pSourceimg); +#endif + + if (!iRetcode) /* still ok ? */ + { + pBuf = (mng_imagedatap)pSourceimg->pImgbuf; + /* address source for row-routines */ + pData->pRetrieveobj = (mng_objectp)pSourceimg; + + pData->iPass = -1; /* init row-processing variables */ + pData->iRowinc = 1; + pData->iColinc = 1; + pData->iPixelofs = 0; + iSourcesamples = (mng_int32)pBuf->iWidth; + iSourcerowsize = pBuf->iRowsize; + bSourceRGBA16 = (mng_bool)(pBuf->iBitdepth > 8); + /* make sure the delta-routines do the right thing */ + pData->iDeltatype = MNG_DELTATYPE_BLOCKPIXELREPLACE; + + switch (pBuf->iColortype) + { + case 0 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (bSourceRGBA16) + pData->fRetrieverow = (mng_fptr)mng_retrieve_g16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_g8; + + pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS); + break; + } + + case 2 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (bSourceRGBA16) + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8; + + pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS); + break; + } + + + case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8; + pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS); + break; + } + + + case 4 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (bSourceRGBA16) + pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8; + + pData->bIsOpaque = MNG_FALSE; + break; + } + + + case 6 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (bSourceRGBA16) + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; + + pData->bIsOpaque = MNG_FALSE; + break; + } + + case 8 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (bSourceRGBA16) + pData->fRetrieverow = (mng_fptr)mng_retrieve_g16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_g8; + + pData->bIsOpaque = MNG_TRUE; + break; + } + + case 10 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (bSourceRGBA16) + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8; + + pData->bIsOpaque = MNG_TRUE; + break; + } + + + case 12 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (bSourceRGBA16) + pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8; + + pData->bIsOpaque = MNG_FALSE; + break; + } + + + case 14 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (bSourceRGBA16) + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16; + else +#endif + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; + + pData->bIsOpaque = MNG_FALSE; + break; + } + } + /* determine scaling */ +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_NO_DELTA_PNG + if ((!bSourceRGBA16) && (bTargetRGBA16)) + pData->fScalerow = (mng_fptr)mng_scale_rgba8_rgba16; + else + if ((bSourceRGBA16) && (!bTargetRGBA16)) + pData->fScalerow = (mng_fptr)mng_scale_rgba16_rgba8; + else +#endif +#endif + pData->fScalerow = MNG_NULL; + + /* default no color-correction */ + pData->fCorrectrow = MNG_NULL; + +#if defined(MNG_FULL_CMS) /* determine color-management routine */ + iRetcode = mng_init_full_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); +#elif defined(MNG_GAMMA_ONLY) + iRetcode = mng_init_gamma_only (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); +#elif defined(MNG_APP_CMS) + iRetcode = mng_init_app_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); +#endif + } + + if (!iRetcode) /* still ok ? */ + { + pData->fFliprow = MNG_NULL; /* no flipping or tiling by default */ + pData->fTilerow = MNG_NULL; + /* but perhaps we do have to ... */ + switch (pSource->iOrientation) + { + case 2 : ; + case 4 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (bTargetRGBA16) + pData->fFliprow = (mng_fptr)mng_flip_rgba16; + else +#endif + pData->fFliprow = (mng_fptr)mng_flip_rgba8; + break; + } + + case 8 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (bTargetRGBA16) + pData->fTilerow = (mng_fptr)mng_tile_rgba16; + else +#endif + pData->fTilerow = (mng_fptr)mng_tile_rgba8; + break; + } + } + /* determine composition routine */ + /* note that we're abusing the delta-routine setup !!! */ + switch (pSource->iComposition) + { + case 0 : { /* composite over */ +#ifndef MNG_NO_16BIT_SUPPORT + if (bTargetRGBA16) + pData->fDeltarow = (mng_fptr)mng_composeover_rgba16; + else +#endif + pData->fDeltarow = (mng_fptr)mng_composeover_rgba8; + break; + } + + case 1 : { /* replace */ +#ifndef MNG_NO_16BIT_SUPPORT + if (bTargetRGBA16) + pData->fDeltarow = (mng_fptr)mng_delta_rgba16_rgba16; + else +#endif + pData->fDeltarow = (mng_fptr)mng_delta_rgba8_rgba8; + break; + } + + case 2 : { /* composite under */ +#ifndef MNG_NO_16BIT_SUPPORT + if (bTargetRGBA16) + pData->fDeltarow = (mng_fptr)mng_composeunder_rgba16; + else +#endif + pData->fDeltarow = (mng_fptr)mng_composeunder_rgba8; + break; + } + } + /* determine offsets & clipping */ + if (pSource->iOffsettype == 1) + { + pData->iDestl = pData->iPastx + pSource->iOffsetx; + pData->iDestt = pData->iPasty + pSource->iOffsety; + } + else + { + pData->iDestl = pSource->iOffsetx; + pData->iDestt = pSource->iOffsety; + } + + pData->iDestr = (mng_int32)pTargetimg->pImgbuf->iWidth; + pData->iDestb = (mng_int32)pTargetimg->pImgbuf->iHeight; + /* take the source dimension into account ? */ + if (pSource->iOrientation != 8) + { + pData->iDestr = MIN_COORD (pData->iDestr, pData->iDestl + (mng_int32)pBuf->iWidth); + pData->iDestb = MIN_COORD (pData->iDestb, pData->iDestt + (mng_int32)pBuf->iHeight); + } + /* source clipping */ + if (pSource->iBoundarytype == 1) + { + if (pData->iDestl < pData->iPastx + pSource->iBoundaryl) + pData->iSourcel = pData->iPastx + pSource->iBoundaryl - pData->iDestl; + else + pData->iSourcel = 0; + + if (pData->iDestt < pData->iPasty + pSource->iBoundaryt) + pData->iSourcet = pData->iPasty + pSource->iBoundaryt - pData->iDestt; + else + pData->iSourcet = 0; + + pData->iDestl = MAX_COORD (pData->iDestl, pData->iPastx + pSource->iBoundaryl); + pData->iDestt = MAX_COORD (pData->iDestt, pData->iPasty + pSource->iBoundaryt); + pData->iDestr = MIN_COORD (pData->iDestr, pData->iPastx + pSource->iBoundaryr); + pData->iDestb = MIN_COORD (pData->iDestb, pData->iPasty + pSource->iBoundaryb); + } + else + { + if (pData->iDestl < pSource->iBoundaryl) + pData->iSourcel = pSource->iBoundaryl - pData->iDestl; + else + pData->iSourcel = 0; + + if (pData->iDestt < pSource->iBoundaryt) + pData->iSourcet = pSource->iBoundaryt - pData->iDestt; + else + pData->iSourcet = 0; + + pData->iDestl = MAX_COORD (pData->iDestl, pSource->iBoundaryl); + pData->iDestt = MAX_COORD (pData->iDestt, pSource->iBoundaryt); + pData->iDestr = MIN_COORD (pData->iDestr, pSource->iBoundaryr); + pData->iDestb = MIN_COORD (pData->iDestb, pSource->iBoundaryb); + } + + if (pData->iSourcel) /* indent source ? */ + { +#ifndef MNG_NO_16BIT_SUPPORT + if (bTargetRGBA16) /* abuse tiling routine to shift source-pixels */ + pData->fTilerow = (mng_fptr)mng_tile_rgba16; + else +#endif + pData->fTilerow = (mng_fptr)mng_tile_rgba8; + } + /* anything to display ? */ + if ((pData->iDestl <= pData->iDestr) && (pData->iDestt <= pData->iDestb)) + { /* init variables for the loop */ + if ((pSource->iOrientation == 2) || (pSource->iOrientation == 6)) + { + iSourceY = (mng_int32)pBuf->iHeight - 1 - pData->iSourcet; + iSourceYinc = -1; + } + else + { + iSourceY = pData->iSourcet; + iSourceYinc = 1; + } + + iTargetY = pData->iDestt; + pData->iCol = pData->iDestl; + + iTargetsamples = pData->iDestr - pData->iDestl; + +#ifndef MNG_NO_16BIT_SUPPORT + if (bTargetRGBA16) + iTargetrowsize = (iTargetsamples << 3); + else +#endif + iTargetrowsize = (iTargetsamples << 2); + + /* get temporary work-buffers */ + if (iSourcerowsize > iTargetrowsize) + iTemprowsize = iSourcerowsize << 1; + else + iTemprowsize = iTargetrowsize << 1; + MNG_ALLOC (pData, pData->pRGBArow, iTemprowsize); + MNG_ALLOC (pData, pData->pWorkrow, iTemprowsize); + + while ((!iRetcode) && (iTargetY < pData->iDestb)) + { /* get a row */ + pData->iRow = iSourceY; + pData->iRowsamples = iSourcesamples; + pData->iRowsize = iSourcerowsize; + pData->bIsRGBA16 = bSourceRGBA16; + iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData); + /* scale it (if necessary) */ + if ((!iRetcode) && (pData->fScalerow)) + iRetcode = ((mng_scalerow)pData->fScalerow) (pData); + + pData->bIsRGBA16 = bTargetRGBA16; + /* color correction (if necessary) */ + if ((!iRetcode) && (pData->fCorrectrow)) + iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData); + /* flipping (if necessary) */ + if ((!iRetcode) && (pData->fFliprow)) + iRetcode = ((mng_fliprow)pData->fFliprow) (pData); + /* tiling (if necessary) */ + if ((!iRetcode) && (pData->fTilerow)) + iRetcode = ((mng_tilerow)pData->fTilerow) (pData); + + if (!iRetcode) /* and paste..... */ + { + pData->iRow = iTargetY; + pData->iRowsamples = iTargetsamples; + pData->iRowsize = iTargetrowsize; + iRetcode = ((mng_deltarow)pData->fDeltarow) (pData); + } + + iSourceY += iSourceYinc; /* and next line */ + + if (iSourceY < 0) + iSourceY = (mng_int32)pBuf->iHeight - 1; + else + if (iSourceY >= (mng_int32)pBuf->iHeight) + iSourceY = 0; + + iTargetY++; + } + /* drop the temporary row-buffer */ + MNG_FREEX (pData, pData->pWorkrow, iTemprowsize); + MNG_FREEX (pData, pData->pRGBArow, iTemprowsize); + } + +#if defined(MNG_FULL_CMS) /* cleanup cms stuff */ + if (!iRetcode) + iRetcode = mng_clear_cms (pData); +#endif + } + + pSource++; /* neeeeext */ + iX++; + } + } + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + if (!iTargetid) /* did we paste into object 0 ? */ +#else + if (!pData->iPASTtargetid) /* did we paste into object 0 ? */ +#endif + { /* display it then ! */ + iRetcode = mng_display_image (pData, pTargetimg, MNG_FALSE); + if (iRetcode) /* on error bail out */ + return iRetcode; + } + else + { /* target is visible & viewable ? */ + if ((pTargetimg->bVisible) && (pTargetimg->bViewable)) + { + iRetcode = mng_display_image (pData, pTargetimg, MNG_FALSE); + if (iRetcode) + return iRetcode; + } + } + } + + if (pData->bTimerset) /* broken ? */ + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + pData->iPASTid = iTargetid; +#else + pData->iPASTid = pData->iPASTtargetid; +#endif + pData->iBreakpoint = 11; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SKIPCHUNK_PAST */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +mng_retcode mng_process_display_past2 (mng_datap pData) +{ + mng_retcode iRetcode; + mng_imagep pTargetimg; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_START); +#endif + + if (pData->iPASTid) /* a real destination object ? */ + pTargetimg = (mng_imagep)mng_find_imageobject (pData, pData->iPASTid); + else /* otherwise object 0 */ + pTargetimg = (mng_imagep)pData->pObjzero; + + iRetcode = mng_display_image (pData, pTargetimg, MNG_FALSE); + if (iRetcode) + return iRetcode; + + pData->iBreakpoint = 0; /* only once */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SKIPCHUNK_PAST */ + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_DISPLAY_PROCS */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + + diff --git a/Source/LibMNG/libmng_dither.c b/Source/LibMNG/libmng_dither.c index 3ba2a70..e23850c 100644 --- a/Source/LibMNG/libmng_dither.c +++ b/Source/LibMNG/libmng_dither.c @@ -1,58 +1,58 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_dither.c copyright (c) 2000-2004 G.Juyn * */ -/* * version : 1.0.9 * */ -/* * * */ -/* * purpose : Dithering routines (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the dithering routines * */ -/* * * */ -/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - changed strict-ANSI stuff * */ -/* * * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_dither.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ - -mng_retcode mng_dither_a_row (mng_datap pData, - mng_uint8p pRow) -{ - - - return MNG_NOERROR; -} - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - - - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_dither.c copyright (c) 2000-2004 G.Juyn * */ +/* * version : 1.0.9 * */ +/* * * */ +/* * purpose : Dithering routines (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the dithering routines * */ +/* * * */ +/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - changed strict-ANSI stuff * */ +/* * * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_dither.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ + +mng_retcode mng_dither_a_row (mng_datap pData, + mng_uint8p pRow) +{ + + + return MNG_NOERROR; +} + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + + + diff --git a/Source/LibMNG/libmng_error.c b/Source/LibMNG/libmng_error.c index 89501a2..3a4da20 100644 --- a/Source/LibMNG/libmng_error.c +++ b/Source/LibMNG/libmng_error.c @@ -1,326 +1,326 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_error.c copyright (c) 2000-2007 G.Juyn * */ -/* * version : 1.0.10 * */ -/* * * */ -/* * purpose : Error routines (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the general error handling routines * */ -/* * * */ -/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - changed strict-ANSI stuff * */ -/* * * */ -/* * 0.5.2 - 05/23/2000 - G.Juyn * */ -/* * - added error telltaling * */ -/* * 0.5.2 - 05/30/2000 - G.Juyn * */ -/* * - added errorstrings for delta-image processing * */ -/* * 0.5.2 - 05/31/2000 - G.Juyn * */ -/* * - fixed up punctuation (contributed by Tim Rowley) * */ -/* * 0.5.2 - 06/06/2000 - G.Juyn * */ -/* * - added errorstring for delayed buffer-processing * */ -/* * * */ -/* * 0.9.1 - 07/06/2000 - G.Juyn * */ -/* * - added MNG_NEEDTIMERWAIT errorstring * */ -/* * 0.9.1 - 07/15/2000 - G.Juyn * */ -/* * - added NEEDSECTIONWAIT errorstring * */ -/* * - added macro + routine to set returncode without * */ -/* * calling error callback * */ -/* * 0.9.1 - 07/19/2000 - G.Juyn * */ -/* * - added errorstring for updatemngheader if not a MNG * */ -/* * * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 0.9.3 - 08/09/2000 - G.Juyn * */ -/* * - added check for simplicity-bits in MHDR * */ -/* * 0.9.3 - 10/11/2000 - G.Juyn * */ -/* * - fixed processing of unknown critical chunks * */ -/* * - added support for nEED * */ -/* * 0.9.3 - 10/20/2000 - G.Juyn * */ -/* * - added errorcode for delayed delta-processing * */ -/* * * */ -/* * 0.9.4 - 01/18/2001 - G.Juyn * */ -/* * - added errorcode for MAGN methods * */ -/* * * */ -/* * 1.0.2 - 06/23/2001 - G.Juyn * */ -/* * - added optimization option for MNG-video playback * */ -/* * * */ -/* * 1.0.5 - 07/04/2002 - G.Juyn * */ -/* * - added errorcode for extreme chunk-sizes * */ -/* * 1.0.5 - 08/15/2002 - G.Juyn * */ -/* * - completed delta-image support * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * 1.0.5 - 09/14/2002 - G.Juyn * */ -/* * - added event handling for dynamic MNG * */ -/* * 1.0.5 - 09/15/2002 - G.Juyn * */ -/* * - fixed LOOP iteration=0 special case * */ -/* * 1.0.5 - 09/19/2002 - G.Juyn * */ -/* * - warnings are ignored by default now! * */ -/* * 1.0.5 - 09/20/2002 - G.Juyn * */ -/* * - added support for PAST * */ -/* * 1.0.5 - 10/07/2002 - G.Juyn * */ -/* * - added check for TERM placement during create/write * */ -/* * * */ -/* * 1.0.6 - 07/07/2003 - G. R-P * */ -/* * - added MNG_SKIPCHUNK_CHNK, MNG_NO_DELTA_PNG reductions. * */ -/* * - skipped more code when MNG_INCLUDE_JNG is not enabled. * */ -/* * 1.0.6 - 07/29/2003 - G.R-P * */ -/* * - added conditional around evNT chunk support * */ -/* * * */ -/* * 1.0.7 - 03/24/2004 - G.R-P * */ -/* * - fixed typo on SKIPCHUNK_evNT (->PAST) * */ -/* * * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * * */ -/* * 1.0.10 - 04/08/2007 - G.Juyn * */ -/* * - added support for mPNG proposal * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ERROR_STRINGS -MNG_LOCAL mng_error_entry const error_table [] = - { - {MNG_NOERROR, "No error"}, - {MNG_OUTOFMEMORY, "Out of memory"}, - {MNG_INVALIDHANDLE, "The handle is invalid"}, - {MNG_NOCALLBACK, "A required callback is not defined"}, - {MNG_UNEXPECTEDEOF, "Encountered unexpected end-of-file"}, - {MNG_ZLIBERROR, "zlib encountered an error"}, -#ifdef MNG_INCLUDE_JNG - {MNG_JPEGERROR, "ijgsrc6b encountered an error"}, -#endif - {MNG_LCMSERROR, "lcms encountered an error"}, - {MNG_NOOUTPUTPROFILE, "No output-profile defined for CMS"}, - {MNG_NOSRGBPROFILE, "No sRGB-profile defined for CMS"}, - {MNG_BUFOVERFLOW, "Internal buffer-overflow"}, - {MNG_FUNCTIONINVALID, "Function is invalid at this point"}, - {MNG_OUTPUTERROR, "Writing was unsuccessful; disk full?"}, - {MNG_JPEGBUFTOOSMALL, "Internal buffer for JPEG processing too small"}, - {MNG_NEEDMOREDATA, "Reading suspended; waiting for I/O to catch up"}, - {MNG_NEEDTIMERWAIT, "Timer suspension; normal animation delay"}, - {MNG_NEEDSECTIONWAIT, "SEEK suspension; application decides"}, - {MNG_LOOPWITHCACHEOFF, "LOOP encountered when playback cache is turned off"}, - - {MNG_APPIOERROR, "Application signalled I/O error"}, - {MNG_APPTIMERERROR, "Application signalled timing error"}, - {MNG_APPCMSERROR, "Application signalled CMS error"}, - {MNG_APPMISCERROR, "Application signalled an error"}, - {MNG_APPTRACEABORT, "Application signalled error during trace-callback"}, - - {MNG_INTERNALERROR, "Internal error in libmng"}, - - {MNG_INVALIDSIG, "The signature is invalid"}, - {MNG_INVALIDCRC, "The CRC for this chunk is invalid"}, - {MNG_INVALIDLENGTH, "Chunk-length is invalid"}, - {MNG_SEQUENCEERROR, "Chunk out of sequence"}, - {MNG_CHUNKNOTALLOWED, "Chunk not allowed at this point"}, - {MNG_MULTIPLEERROR, "Chunk cannot occur multiple times"}, - {MNG_PLTEMISSING, "Missing PLTE chunk"}, - {MNG_IDATMISSING, "Missing IDAT chunk(s)"}, - {MNG_CANNOTBEEMPTY, "Chunk cannot be empty"}, - {MNG_GLOBALLENGTHERR, "Global data length invalid"}, - {MNG_INVALIDBITDEPTH, "The bit_depth is invalid"}, - {MNG_INVALIDCOLORTYPE, "The color_type is invalid"}, - {MNG_INVALIDCOMPRESS, "The compression_method is invalid"}, - {MNG_INVALIDFILTER, "The filter_method or filter_type is invalid"}, - {MNG_INVALIDINTERLACE, "The interlace_method is invalid"}, - {MNG_NOTENOUGHIDAT, "There is not enough data in the IDAT chunk(s)"}, - {MNG_PLTEINDEXERROR, "Palette-index out of bounds"}, - {MNG_NULLNOTFOUND, "NULL separator not found"}, - {MNG_KEYWORDNULL, "Keyword cannot be zero-length"}, - {MNG_OBJECTUNKNOWN, "Object does not exist"}, - {MNG_OBJECTEXISTS, "Object already exists"}, - {MNG_TOOMUCHIDAT, "Too much data in IDAT chunk(s)"}, - {MNG_INVSAMPLEDEPTH, "The sample_depth is invalid"}, - {MNG_INVOFFSETSIZE, "The offset_type is invalid"}, - {MNG_INVENTRYTYPE, "The entry_type is invalid"}, - {MNG_ENDWITHNULL, "Chunk must not end with NULL byte"}, - {MNG_INVIMAGETYPE, "The image_type is invalid"}, -#ifndef MNG_NO_DELTA_PNG - {MNG_INVDELTATYPE, "The delta_type is invalid"}, -#endif - {MNG_INVALIDINDEX, "Index-value out of bounds"}, -#ifdef MNG_INCLUDE_JNG - {MNG_TOOMUCHJDAT, "Too much data in JDAT chunk(s)"}, - {MNG_JPEGPARMSERR, "JHDR parameters & JFIF-data do not match"}, -#endif - {MNG_INVFILLMETHOD, "The fill_method is invalid"}, -#ifndef MNG_NO_DELTA_PNG - {MNG_OBJNOTCONCRETE, "Target object for DHDR must be concrete"}, -#endif - {MNG_TARGETNOALPHA, "Target object must have alpha-channel"}, - {MNG_MNGTOOCOMPLEX, "MHDR simplicity indicates unsupported feature(s)"}, - {MNG_UNKNOWNCRITICAL, "Unknown critical chunk encountered"}, -#ifndef MNG_SKIPCHUNK_nEED - {MNG_UNSUPPORTEDNEED, "Requested nEED resources are not supported"}, -#endif - {MNG_INVALIDDELTA, "The delta operation is invalid (mismatched color_types?)"}, - {MNG_INVALIDMETHOD, "Method is invalid"}, - {MNG_IMPROBABLELENGTH, "Chunklength is incredibly large"}, - {MNG_INVALIDBLOCK, "Delta block width and or height invalid"}, - {MNG_INVALIDEVENT, "Event type is invalid"}, - {MNG_INVALIDMASK, "Mask type is invalid"}, - {MNG_NOMATCHINGLOOP, "ENDL without matching LOOP"}, -#ifndef MNG_SKIPCHUNK_evNT - {MNG_SEEKNOTFOUND, "evNT points to unknown SEEK"}, -#endif -#ifndef MNG_SKIPCHUNK_PAST - {MNG_OBJNOTABSTRACT, "Destination object for PAST must be abstract"}, -#endif - {MNG_TERMSEQERROR, "TERM misplaced during creation of MNG stream"}, - {MNG_INVALIDFIELDVAL, "invalid fieldvalue (generic)"}, - {MNG_INVALIDWIDTH, "invalid frame/image width"}, - {MNG_INVALIDHEIGHT, "invalid frame/image height"}, - - {MNG_INVALIDCNVSTYLE, "Canvas_style is invalid"}, - {MNG_WRONGCHUNK, "Attempt to access the wrong chunk"}, - {MNG_INVALIDENTRYIX, "Attempt to access an non-existing entry"}, - {MNG_NOHEADER, "No valid header-chunk"}, - {MNG_NOCORRCHUNK, "Parent chunk not found"}, - {MNG_NOMHDR, "No MNG header (MHDR) found"}, - - {MNG_IMAGETOOLARGE, "Image is larger than defined maximum"}, - {MNG_NOTANANIMATION, "Image is not an animation"}, - {MNG_FRAMENRTOOHIGH, "Framenr out of bounds"}, - {MNG_LAYERNRTOOHIGH, "Layernr out of bounds"}, - {MNG_PLAYTIMETOOHIGH, "Playtime out of bounds"}, - {MNG_FNNOTIMPLEMENTED, "Function not yet implemented"}, - {MNG_IMAGEFROZEN, "Image is frozen"}, - - {MNG_LCMS_NOHANDLE, "Handle could not be initialized"}, - {MNG_LCMS_NOMEM, "No memory for gamma-table(s)"}, - {MNG_LCMS_NOTRANS, "Transformation could not be initialized"} - }; -#endif /* MNG_INCLUDE_ERROR_STRINGS */ - -/* ************************************************************************** */ - -mng_bool mng_store_error (mng_datap pData, - mng_retcode iError, - mng_retcode iExtra1, - mng_retcode iExtra2) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (pData, MNG_FN_STORE_ERROR, MNG_LC_START); -#endif - - if (pData != 0) - { - pData->iErrorcode = iError; /* save also for getlasterror */ - pData->iErrorx1 = iExtra1; - pData->iErrorx2 = iExtra2; - -#ifdef MNG_INCLUDE_ERROR_STRINGS - { /* binary search variables */ - mng_int32 iTop, iLower, iUpper, iMiddle; - mng_error_entryp pEntry; /* pointer to found entry */ - /* determine max index of table */ - iTop = (sizeof (error_table) / sizeof (error_table [0])) - 1; - - iLower = 0; /* initialize binary search */ - iMiddle = iTop >> 1; /* start in the middle */ - iUpper = iTop; - pEntry = 0; /* no goods yet! */ - - do /* the binary search itself */ - { - if (error_table [iMiddle].iError < iError) - iLower = iMiddle + 1; - else if (error_table [iMiddle].iError > iError) - iUpper = iMiddle - 1; - else - { - pEntry = &error_table [iMiddle]; - break; - } - - iMiddle = (iLower + iUpper) >> 1; - } - while (iLower <= iUpper); - - if (pEntry) /* found it ? */ - pData->zErrortext = pEntry->zErrortext; - else - pData->zErrortext = "Unknown error"; - } -#else /* MNG_INCLUDE_ERROR_STRINGS */ - pData->zErrortext = 0; -#endif /* MNG_INCLUDE_ERROR_STRINGS */ - - if (iError == 0) /* no error is not severe ! */ - { - pData->iSeverity = 0; - } - else - { - switch (iError&0x3C00) /* determine the severity */ - { - case 0x0800 : { pData->iSeverity = 5; break; } - case 0x1000 : { pData->iSeverity = 2; break; } - case 0x2000 : { pData->iSeverity = 1; break; } - default : { pData->iSeverity = 9; } - } - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (pData, MNG_FN_STORE_ERROR, MNG_LC_END); -#endif - - return MNG_TRUE; -} - -/* ************************************************************************** */ - -mng_bool mng_process_error (mng_datap pData, - mng_retcode iError, - mng_retcode iExtra1, - mng_retcode iExtra2) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (pData, MNG_FN_PROCESS_ERROR, MNG_LC_START); -#endif - - mng_store_error (pData, iError, iExtra1, iExtra2); - - if ((pData != MNG_NULL) && (pData->iMagic == MNG_MAGIC)) - { - if (pData->fErrorproc) /* callback defined ? */ - return pData->fErrorproc (((mng_handle)pData), iError, pData->iSeverity, - pData->iChunkname, pData->iChunkseq, - pData->iErrorx1, pData->iErrorx2, pData->zErrortext); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (pData, MNG_FN_PROCESS_ERROR, MNG_LC_END); -#endif - - return MNG_TRUE; /* warnings are ignored by default ! */ -} - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_error.c copyright (c) 2000-2007 G.Juyn * */ +/* * version : 1.0.10 * */ +/* * * */ +/* * purpose : Error routines (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the general error handling routines * */ +/* * * */ +/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - changed strict-ANSI stuff * */ +/* * * */ +/* * 0.5.2 - 05/23/2000 - G.Juyn * */ +/* * - added error telltaling * */ +/* * 0.5.2 - 05/30/2000 - G.Juyn * */ +/* * - added errorstrings for delta-image processing * */ +/* * 0.5.2 - 05/31/2000 - G.Juyn * */ +/* * - fixed up punctuation (contributed by Tim Rowley) * */ +/* * 0.5.2 - 06/06/2000 - G.Juyn * */ +/* * - added errorstring for delayed buffer-processing * */ +/* * * */ +/* * 0.9.1 - 07/06/2000 - G.Juyn * */ +/* * - added MNG_NEEDTIMERWAIT errorstring * */ +/* * 0.9.1 - 07/15/2000 - G.Juyn * */ +/* * - added NEEDSECTIONWAIT errorstring * */ +/* * - added macro + routine to set returncode without * */ +/* * calling error callback * */ +/* * 0.9.1 - 07/19/2000 - G.Juyn * */ +/* * - added errorstring for updatemngheader if not a MNG * */ +/* * * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 0.9.3 - 08/09/2000 - G.Juyn * */ +/* * - added check for simplicity-bits in MHDR * */ +/* * 0.9.3 - 10/11/2000 - G.Juyn * */ +/* * - fixed processing of unknown critical chunks * */ +/* * - added support for nEED * */ +/* * 0.9.3 - 10/20/2000 - G.Juyn * */ +/* * - added errorcode for delayed delta-processing * */ +/* * * */ +/* * 0.9.4 - 01/18/2001 - G.Juyn * */ +/* * - added errorcode for MAGN methods * */ +/* * * */ +/* * 1.0.2 - 06/23/2001 - G.Juyn * */ +/* * - added optimization option for MNG-video playback * */ +/* * * */ +/* * 1.0.5 - 07/04/2002 - G.Juyn * */ +/* * - added errorcode for extreme chunk-sizes * */ +/* * 1.0.5 - 08/15/2002 - G.Juyn * */ +/* * - completed delta-image support * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * 1.0.5 - 09/14/2002 - G.Juyn * */ +/* * - added event handling for dynamic MNG * */ +/* * 1.0.5 - 09/15/2002 - G.Juyn * */ +/* * - fixed LOOP iteration=0 special case * */ +/* * 1.0.5 - 09/19/2002 - G.Juyn * */ +/* * - warnings are ignored by default now! * */ +/* * 1.0.5 - 09/20/2002 - G.Juyn * */ +/* * - added support for PAST * */ +/* * 1.0.5 - 10/07/2002 - G.Juyn * */ +/* * - added check for TERM placement during create/write * */ +/* * * */ +/* * 1.0.6 - 07/07/2003 - G. R-P * */ +/* * - added MNG_SKIPCHUNK_CHNK, MNG_NO_DELTA_PNG reductions. * */ +/* * - skipped more code when MNG_INCLUDE_JNG is not enabled. * */ +/* * 1.0.6 - 07/29/2003 - G.R-P * */ +/* * - added conditional around evNT chunk support * */ +/* * * */ +/* * 1.0.7 - 03/24/2004 - G.R-P * */ +/* * - fixed typo on SKIPCHUNK_evNT (->PAST) * */ +/* * * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * * */ +/* * 1.0.10 - 04/08/2007 - G.Juyn * */ +/* * - added support for mPNG proposal * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ERROR_STRINGS +MNG_LOCAL mng_error_entry const error_table [] = + { + {MNG_NOERROR, "No error"}, + {MNG_OUTOFMEMORY, "Out of memory"}, + {MNG_INVALIDHANDLE, "The handle is invalid"}, + {MNG_NOCALLBACK, "A required callback is not defined"}, + {MNG_UNEXPECTEDEOF, "Encountered unexpected end-of-file"}, + {MNG_ZLIBERROR, "zlib encountered an error"}, +#ifdef MNG_INCLUDE_JNG + {MNG_JPEGERROR, "ijgsrc6b encountered an error"}, +#endif + {MNG_LCMSERROR, "lcms encountered an error"}, + {MNG_NOOUTPUTPROFILE, "No output-profile defined for CMS"}, + {MNG_NOSRGBPROFILE, "No sRGB-profile defined for CMS"}, + {MNG_BUFOVERFLOW, "Internal buffer-overflow"}, + {MNG_FUNCTIONINVALID, "Function is invalid at this point"}, + {MNG_OUTPUTERROR, "Writing was unsuccessful; disk full?"}, + {MNG_JPEGBUFTOOSMALL, "Internal buffer for JPEG processing too small"}, + {MNG_NEEDMOREDATA, "Reading suspended; waiting for I/O to catch up"}, + {MNG_NEEDTIMERWAIT, "Timer suspension; normal animation delay"}, + {MNG_NEEDSECTIONWAIT, "SEEK suspension; application decides"}, + {MNG_LOOPWITHCACHEOFF, "LOOP encountered when playback cache is turned off"}, + + {MNG_APPIOERROR, "Application signalled I/O error"}, + {MNG_APPTIMERERROR, "Application signalled timing error"}, + {MNG_APPCMSERROR, "Application signalled CMS error"}, + {MNG_APPMISCERROR, "Application signalled an error"}, + {MNG_APPTRACEABORT, "Application signalled error during trace-callback"}, + + {MNG_INTERNALERROR, "Internal error in libmng"}, + + {MNG_INVALIDSIG, "The signature is invalid"}, + {MNG_INVALIDCRC, "The CRC for this chunk is invalid"}, + {MNG_INVALIDLENGTH, "Chunk-length is invalid"}, + {MNG_SEQUENCEERROR, "Chunk out of sequence"}, + {MNG_CHUNKNOTALLOWED, "Chunk not allowed at this point"}, + {MNG_MULTIPLEERROR, "Chunk cannot occur multiple times"}, + {MNG_PLTEMISSING, "Missing PLTE chunk"}, + {MNG_IDATMISSING, "Missing IDAT chunk(s)"}, + {MNG_CANNOTBEEMPTY, "Chunk cannot be empty"}, + {MNG_GLOBALLENGTHERR, "Global data length invalid"}, + {MNG_INVALIDBITDEPTH, "The bit_depth is invalid"}, + {MNG_INVALIDCOLORTYPE, "The color_type is invalid"}, + {MNG_INVALIDCOMPRESS, "The compression_method is invalid"}, + {MNG_INVALIDFILTER, "The filter_method or filter_type is invalid"}, + {MNG_INVALIDINTERLACE, "The interlace_method is invalid"}, + {MNG_NOTENOUGHIDAT, "There is not enough data in the IDAT chunk(s)"}, + {MNG_PLTEINDEXERROR, "Palette-index out of bounds"}, + {MNG_NULLNOTFOUND, "NULL separator not found"}, + {MNG_KEYWORDNULL, "Keyword cannot be zero-length"}, + {MNG_OBJECTUNKNOWN, "Object does not exist"}, + {MNG_OBJECTEXISTS, "Object already exists"}, + {MNG_TOOMUCHIDAT, "Too much data in IDAT chunk(s)"}, + {MNG_INVSAMPLEDEPTH, "The sample_depth is invalid"}, + {MNG_INVOFFSETSIZE, "The offset_type is invalid"}, + {MNG_INVENTRYTYPE, "The entry_type is invalid"}, + {MNG_ENDWITHNULL, "Chunk must not end with NULL byte"}, + {MNG_INVIMAGETYPE, "The image_type is invalid"}, +#ifndef MNG_NO_DELTA_PNG + {MNG_INVDELTATYPE, "The delta_type is invalid"}, +#endif + {MNG_INVALIDINDEX, "Index-value out of bounds"}, +#ifdef MNG_INCLUDE_JNG + {MNG_TOOMUCHJDAT, "Too much data in JDAT chunk(s)"}, + {MNG_JPEGPARMSERR, "JHDR parameters & JFIF-data do not match"}, +#endif + {MNG_INVFILLMETHOD, "The fill_method is invalid"}, +#ifndef MNG_NO_DELTA_PNG + {MNG_OBJNOTCONCRETE, "Target object for DHDR must be concrete"}, +#endif + {MNG_TARGETNOALPHA, "Target object must have alpha-channel"}, + {MNG_MNGTOOCOMPLEX, "MHDR simplicity indicates unsupported feature(s)"}, + {MNG_UNKNOWNCRITICAL, "Unknown critical chunk encountered"}, +#ifndef MNG_SKIPCHUNK_nEED + {MNG_UNSUPPORTEDNEED, "Requested nEED resources are not supported"}, +#endif + {MNG_INVALIDDELTA, "The delta operation is invalid (mismatched color_types?)"}, + {MNG_INVALIDMETHOD, "Method is invalid"}, + {MNG_IMPROBABLELENGTH, "Chunklength is incredibly large"}, + {MNG_INVALIDBLOCK, "Delta block width and or height invalid"}, + {MNG_INVALIDEVENT, "Event type is invalid"}, + {MNG_INVALIDMASK, "Mask type is invalid"}, + {MNG_NOMATCHINGLOOP, "ENDL without matching LOOP"}, +#ifndef MNG_SKIPCHUNK_evNT + {MNG_SEEKNOTFOUND, "evNT points to unknown SEEK"}, +#endif +#ifndef MNG_SKIPCHUNK_PAST + {MNG_OBJNOTABSTRACT, "Destination object for PAST must be abstract"}, +#endif + {MNG_TERMSEQERROR, "TERM misplaced during creation of MNG stream"}, + {MNG_INVALIDFIELDVAL, "invalid fieldvalue (generic)"}, + {MNG_INVALIDWIDTH, "invalid frame/image width"}, + {MNG_INVALIDHEIGHT, "invalid frame/image height"}, + + {MNG_INVALIDCNVSTYLE, "Canvas_style is invalid"}, + {MNG_WRONGCHUNK, "Attempt to access the wrong chunk"}, + {MNG_INVALIDENTRYIX, "Attempt to access an non-existing entry"}, + {MNG_NOHEADER, "No valid header-chunk"}, + {MNG_NOCORRCHUNK, "Parent chunk not found"}, + {MNG_NOMHDR, "No MNG header (MHDR) found"}, + + {MNG_IMAGETOOLARGE, "Image is larger than defined maximum"}, + {MNG_NOTANANIMATION, "Image is not an animation"}, + {MNG_FRAMENRTOOHIGH, "Framenr out of bounds"}, + {MNG_LAYERNRTOOHIGH, "Layernr out of bounds"}, + {MNG_PLAYTIMETOOHIGH, "Playtime out of bounds"}, + {MNG_FNNOTIMPLEMENTED, "Function not yet implemented"}, + {MNG_IMAGEFROZEN, "Image is frozen"}, + + {MNG_LCMS_NOHANDLE, "Handle could not be initialized"}, + {MNG_LCMS_NOMEM, "No memory for gamma-table(s)"}, + {MNG_LCMS_NOTRANS, "Transformation could not be initialized"} + }; +#endif /* MNG_INCLUDE_ERROR_STRINGS */ + +/* ************************************************************************** */ + +mng_bool mng_store_error (mng_datap pData, + mng_retcode iError, + mng_retcode iExtra1, + mng_retcode iExtra2) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (pData, MNG_FN_STORE_ERROR, MNG_LC_START); +#endif + + if (pData != 0) + { + pData->iErrorcode = iError; /* save also for getlasterror */ + pData->iErrorx1 = iExtra1; + pData->iErrorx2 = iExtra2; + +#ifdef MNG_INCLUDE_ERROR_STRINGS + { /* binary search variables */ + mng_int32 iTop, iLower, iUpper, iMiddle; + mng_error_entryp pEntry; /* pointer to found entry */ + /* determine max index of table */ + iTop = (sizeof (error_table) / sizeof (error_table [0])) - 1; + + iLower = 0; /* initialize binary search */ + iMiddle = iTop >> 1; /* start in the middle */ + iUpper = iTop; + pEntry = 0; /* no goods yet! */ + + do /* the binary search itself */ + { + if (error_table [iMiddle].iError < iError) + iLower = iMiddle + 1; + else if (error_table [iMiddle].iError > iError) + iUpper = iMiddle - 1; + else + { + pEntry = &error_table [iMiddle]; + break; + } + + iMiddle = (iLower + iUpper) >> 1; + } + while (iLower <= iUpper); + + if (pEntry) /* found it ? */ + pData->zErrortext = pEntry->zErrortext; + else + pData->zErrortext = "Unknown error"; + } +#else /* MNG_INCLUDE_ERROR_STRINGS */ + pData->zErrortext = 0; +#endif /* MNG_INCLUDE_ERROR_STRINGS */ + + if (iError == 0) /* no error is not severe ! */ + { + pData->iSeverity = 0; + } + else + { + switch (iError&0x3C00) /* determine the severity */ + { + case 0x0800 : { pData->iSeverity = 5; break; } + case 0x1000 : { pData->iSeverity = 2; break; } + case 0x2000 : { pData->iSeverity = 1; break; } + default : { pData->iSeverity = 9; } + } + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (pData, MNG_FN_STORE_ERROR, MNG_LC_END); +#endif + + return MNG_TRUE; +} + +/* ************************************************************************** */ + +mng_bool mng_process_error (mng_datap pData, + mng_retcode iError, + mng_retcode iExtra1, + mng_retcode iExtra2) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (pData, MNG_FN_PROCESS_ERROR, MNG_LC_START); +#endif + + mng_store_error (pData, iError, iExtra1, iExtra2); + + if ((pData != MNG_NULL) && (pData->iMagic == MNG_MAGIC)) + { + if (pData->fErrorproc) /* callback defined ? */ + return pData->fErrorproc (((mng_handle)pData), iError, pData->iSeverity, + pData->iChunkname, pData->iChunkseq, + pData->iErrorx1, pData->iErrorx2, pData->zErrortext); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (pData, MNG_FN_PROCESS_ERROR, MNG_LC_END); +#endif + + return MNG_TRUE; /* warnings are ignored by default ! */ +} + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + diff --git a/Source/LibMNG/libmng_filter.c b/Source/LibMNG/libmng_filter.c index ad57a3b..ed69a75 100644 --- a/Source/LibMNG/libmng_filter.c +++ b/Source/LibMNG/libmng_filter.c @@ -1,978 +1,978 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_filter.c copyright (c) 2000-2004 G.Juyn * */ -/* * version : 1.0.9 * */ -/* * * */ -/* * purpose : Filtering routines (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the filtering routines * */ -/* * * */ -/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - changed trace to macro for callback error-reporting * */ -/* * * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 0.9.3 - 09/07/2000 - G.Juyn * */ -/* * - added support for new filter_types * */ -/* * * */ -/* * 1.0.5 - 08/07/2002 - G.Juyn * */ -/* * - added test-option for PNG filter method 193 (=no filter) * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * * */ -/* * 1.0.6 - 07/07/2003 - G.R-P * */ -/* * - reversed some loops to use decrementing counter * */ -/* * * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_filter.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_FILTERS - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode filter_sub (mng_datap pData) -{ - mng_uint32 iBpp; - mng_uint8p pRawx; - mng_uint8p pRawx_prev; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FILTER_SUB, MNG_LC_START); -#endif - - iBpp = pData->iFilterbpp; - pRawx = pData->pWorkrow + pData->iPixelofs + iBpp; - pRawx_prev = pData->pWorkrow + pData->iPixelofs; - - for (iX = iBpp; iX < pData->iRowsize; iX++) - { - *pRawx = (mng_uint8)(*pRawx + *pRawx_prev); - pRawx++; - pRawx_prev++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FILTER_SUB, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode filter_up (mng_datap pData) -{ - mng_uint8p pRawx; - mng_uint8p pPriorx; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FILTER_UP, MNG_LC_START); -#endif - - pRawx = pData->pWorkrow + pData->iPixelofs; - pPriorx = pData->pPrevrow + pData->iPixelofs; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsize - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsize; iX++) -#endif - { - *pRawx = (mng_uint8)(*pRawx + *pPriorx); - pRawx++; - pPriorx++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FILTER_UP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode filter_average (mng_datap pData) -{ - mng_int32 iBpp; - mng_uint8p pRawx; - mng_uint8p pRawx_prev; - mng_uint8p pPriorx; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FILTER_AVERAGE, MNG_LC_START); -#endif - - iBpp = pData->iFilterbpp; - pRawx = pData->pWorkrow + pData->iPixelofs; - pPriorx = pData->pPrevrow + pData->iPixelofs; - pRawx_prev = pData->pWorkrow + pData->iPixelofs; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = iBpp - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < iBpp; iX++) -#endif - { - *pRawx = (mng_uint8)(*pRawx + ((*pPriorx) >> 1)); - pRawx++; - pPriorx++; - } - - for (iX = iBpp; iX < pData->iRowsize; iX++) - { - *pRawx = (mng_uint8)(*pRawx + ((*pRawx_prev + *pPriorx) >> 1)); - pRawx++; - pPriorx++; - pRawx_prev++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FILTER_AVERAGE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode filter_paeth (mng_datap pData) -{ - mng_int32 iBpp; - mng_uint8p pRawx; - mng_uint8p pRawx_prev; - mng_uint8p pPriorx; - mng_uint8p pPriorx_prev; - mng_int32 iX; - mng_uint32 iA, iB, iC; - mng_uint32 iP; - mng_uint32 iPa, iPb, iPc; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FILTER_PAETH, MNG_LC_START); -#endif - - iBpp = pData->iFilterbpp; - pRawx = pData->pWorkrow + pData->iPixelofs; - pPriorx = pData->pPrevrow + pData->iPixelofs; - pRawx_prev = pData->pWorkrow + pData->iPixelofs; - pPriorx_prev = pData->pPrevrow + pData->iPixelofs; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = iBpp - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < iBpp; iX++) -#endif - { - *pRawx = (mng_uint8)(*pRawx + *pPriorx); - - pRawx++; - pPriorx++; - } - - for (iX = iBpp; iX < pData->iRowsize; iX++) - { - iA = (mng_uint32)*pRawx_prev; - iB = (mng_uint32)*pPriorx; - iC = (mng_uint32)*pPriorx_prev; - iP = iA + iB - iC; - iPa = abs (iP - iA); - iPb = abs (iP - iB); - iPc = abs (iP - iC); - - if ((iPa <= iPb) && (iPa <= iPc)) - *pRawx = (mng_uint8)(*pRawx + iA); - else - if (iPb <= iPc) - *pRawx = (mng_uint8)(*pRawx + iB); - else - *pRawx = (mng_uint8)(*pRawx + iC); - - pRawx++; - pPriorx++; - pRawx_prev++; - pPriorx_prev++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FILTER_PAETH, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_filter_a_row (mng_datap pData) -{ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FILTER_A_ROW, MNG_LC_START); -#endif - - switch (*(pData->pWorkrow + pData->iFilterofs)) - { - case 1 : { - iRetcode = filter_sub (pData); - break; - } - case 2 : { - iRetcode = filter_up (pData); - break; - } - case 3 : { - iRetcode = filter_average (pData); - break; - } - case 4 : { - iRetcode = filter_paeth (pData); - break; - } - - default : iRetcode = MNG_INVALIDFILTER; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FILTER_A_ROW, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifdef FILTER192 -mng_retcode mng_init_rowdiffering (mng_datap pData) -{ - mng_uint8p pRawi, pRawo; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_ROWDIFFERING, MNG_LC_START); -#endif - - if (pData->iFilter == 0xC0) /* has leveling parameters ? */ - { - switch (pData->iColortype) /* salvage leveling parameters */ - { - case 0 : { /* gray */ - if (pData->iBitdepth <= 8) - pData->iLevel0 = (mng_uint16)*pData->pWorkrow; - else - pData->iLevel0 = mng_get_uint16 (pData->pWorkrow); - - break; - } - case 2 : { /* rgb */ - if (pData->iBitdepth <= 8) - { - pData->iLevel0 = (mng_uint16)*pData->pWorkrow; - pData->iLevel1 = (mng_uint16)*(pData->pWorkrow+1); - pData->iLevel2 = (mng_uint16)*(pData->pWorkrow+2); - } - else - { - pData->iLevel0 = mng_get_uint16 (pData->pWorkrow); - pData->iLevel1 = mng_get_uint16 (pData->pWorkrow+2); - pData->iLevel2 = mng_get_uint16 (pData->pWorkrow+4); - } - - break; - } - case 3 : { /* indexed */ - pData->iLevel0 = (mng_uint16)*pData->pWorkrow; - break; - } - case 4 : { /* gray+alpha */ - if (pData->iBitdepth <= 8) - { - pData->iLevel0 = (mng_uint16)*pData->pWorkrow; - pData->iLevel1 = (mng_uint16)*(pData->pWorkrow+1); - } - else - { - pData->iLevel0 = mng_get_uint16 (pData->pWorkrow); - pData->iLevel1 = mng_get_uint16 (pData->pWorkrow+2); - } - - break; - } - case 6 : { /* rgb+alpha */ - if (pData->iBitdepth <= 8) - { - pData->iLevel0 = (mng_uint16)*pData->pWorkrow; - pData->iLevel1 = (mng_uint16)*(pData->pWorkrow+1); - pData->iLevel2 = (mng_uint16)*(pData->pWorkrow+2); - pData->iLevel3 = (mng_uint16)*(pData->pWorkrow+3); - } - else - { - pData->iLevel0 = mng_get_uint16 (pData->pWorkrow); - pData->iLevel1 = mng_get_uint16 (pData->pWorkrow+2); - pData->iLevel2 = mng_get_uint16 (pData->pWorkrow+4); - pData->iLevel3 = mng_get_uint16 (pData->pWorkrow+6); - } - - break; - } - } - } - /* shift the entire row back in place */ - pRawi = pData->pWorkrow + pData->iFilterofs; - pRawo = pData->pWorkrow; - - for (iX = 0; iX < pData->iRowsize + pData->iPixelofs - pData->iFilterofs; iX++) - *pRawo++ = *pRawi++; - - pData->iFilterofs = 0; /* indicate so ! */ - -#ifdef FILTER193 - if (pData->iFilter == 0xC1) /* no adaptive filtering ? */ - pData->iPixelofs = pData->iFilterofs; - else -#endif - pData->iPixelofs = pData->iFilterofs + 1; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_ROWDIFFERING, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_g1 (mng_datap pData) -{ - mng_uint8p pRawi, pRawo; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_G1, MNG_LC_START); -#endif - - if (pData->iLevel0 & 0x01) /* is it uneven level ? */ - { - pRawi = pData->pWorkrow + pData->iPixelofs; - pRawo = pData->pPrevrow + pData->iPixelofs; - /* just invert every bit */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsize - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsize; iX++) -#endif - *pRawo++ = (mng_uint8)(~(*pRawi++)); - - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_G1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_g2 (mng_datap pData) -{ - mng_uint8p pRawi, pRawo; - mng_int32 iX; - mng_int32 iC, iS; - mng_uint8 iB, iN, iQ; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_G2, MNG_LC_START); -#endif - - pRawi = pData->pWorkrow + pData->iPixelofs; - pRawo = pData->pPrevrow + pData->iPixelofs; - iC = 0; - iB = 0; - iN = 0; - iS = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iC) - { - iC = 4; - iB = *pRawi++; - iN = 0; - iS = 8; - } - - iS -= 2; - iQ = (mng_uint8)(((iB >> iS) + pData->iLevel0) & 0x03); - iN = (mng_uint8)((iN << 2) + iQ); - iC--; - - if (!iC) - *pRawo++ = iN; - - } - - if (iC) - *pRawo = (mng_uint8)(iN << iS); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_G2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_g4 (mng_datap pData) -{ - mng_uint8p pRawi, pRawo; - mng_int32 iX; - mng_int32 iC, iS; - mng_uint8 iB, iN, iQ; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_G4, MNG_LC_START); -#endif - - pRawi = pData->pWorkrow + pData->iPixelofs; - pRawo = pData->pPrevrow + pData->iPixelofs; - iC = 0; - iB = 0; - iN = 0; - iS = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iC) - { - iC = 2; - iB = *pRawi++; - iN = 0; - iS = 8; - } - - iS -= 4; - iQ = (mng_uint8)(((iB >> iS) + pData->iLevel0) & 0x0F); - iN = (mng_uint8)((iN << 4) + iQ); - iC--; - - if (!iC) - *pRawo++ = iN; - - } - - if (iC) - *pRawo = (mng_uint8)(iN << iS); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_G4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_g8 (mng_datap pData) -{ - mng_uint8p pRawi, pRawo; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_G8, MNG_LC_START); -#endif - - pRawi = pData->pWorkrow + pData->iPixelofs; - pRawo = pData->pPrevrow + pData->iPixelofs; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pRawo++ = (mng_uint8)(((mng_uint16)*pRawi + pData->iLevel0) & 0xFF); - - pRawi++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_G8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_g16 (mng_datap pData) -{ - mng_uint16p pRawi, pRawo; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_G16, MNG_LC_START); -#endif - - pRawi = (mng_uint16p)(pData->pWorkrow + pData->iPixelofs); - pRawo = (mng_uint16p)(pData->pPrevrow + pData->iPixelofs); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pRawo++ = (mng_uint16)(((mng_uint32)*pRawi + (mng_uint32)pData->iLevel0) & 0xFFFF); - - pRawi++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_G16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_rgb8 (mng_datap pData) -{ - mng_uint8p pRawi, pRawo; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_RGB8, MNG_LC_START); -#endif - - pRawi = pData->pWorkrow + pData->iPixelofs; - pRawo = pData->pPrevrow + pData->iPixelofs; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *(pRawo+1) = (mng_uint8)(((mng_uint16)*(pRawi+1) + pData->iLevel1) & 0xFF); - *pRawo = (mng_uint8)(((mng_uint16)*pRawi + pData->iLevel0 + - (mng_uint16)*(pRawo+1)) & 0xFF); - *(pRawo+2) = (mng_uint8)(((mng_uint16)*(pRawi+2) + pData->iLevel2 + - (mng_uint16)*(pRawo+1)) & 0xFF); - - pRawi += 3; - pRawo += 3; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_RGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_rgb16 (mng_datap pData) -{ - mng_uint16p pRawi, pRawo; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_RGB16, MNG_LC_START); -#endif - - pRawi = (mng_uint16p)(pData->pWorkrow + pData->iPixelofs); - pRawo = (mng_uint16p)(pData->pPrevrow + pData->iPixelofs); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *(pRawo+1) = (mng_uint16)(((mng_uint32)*(pRawi+1) + (mng_uint32)pData->iLevel1) & 0xFFFF); - *pRawo = (mng_uint16)(((mng_uint32)*pRawi + (mng_uint32)pData->iLevel0 + - (mng_uint32)*(pRawo+1)) & 0xFFFF); - *(pRawo+2) = (mng_uint16)(((mng_uint32)*(pRawi+2) + (mng_uint32)pData->iLevel2 + - (mng_uint32)*(pRawo+1)) & 0xFFFF); - - pRawi += 3; - pRawo += 3; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_RGB16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_idx1 (mng_datap pData) -{ - mng_uint8p pRawi, pRawo; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_IDX1, MNG_LC_START); -#endif - - if (pData->iLevel0 & 0x01) /* is it uneven level ? */ - { - pRawi = pData->pWorkrow + pData->iPixelofs; - pRawo = pData->pPrevrow + pData->iPixelofs; - /* just invert every bit */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsize - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsize; iX++) -#endif - *pRawo++ = (mng_uint8)(~(*pRawi++)); - - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_IDX1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_idx2 (mng_datap pData) -{ - mng_uint8p pRawi, pRawo; - mng_int32 iX; - mng_int32 iC, iS; - mng_uint8 iB, iN, iQ; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_IDX2, MNG_LC_START); -#endif - - pRawi = pData->pWorkrow + pData->iPixelofs; - pRawo = pData->pPrevrow + pData->iPixelofs; - iC = 0; - iB = 0; - iN = 0; - iS = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iC) - { - iC = 4; - iB = *pRawi++; - iN = 0; - iS = 8; - } - - iS -= 2; - iQ = (mng_uint8)(((iB >> iS) + pData->iLevel0) & 0x03); - iN = (mng_uint8)((iN << 2) + iQ); - iC--; - - if (!iC) - *pRawo++ = iN; - - } - - if (iC) - *pRawo = (mng_uint8)(iN << iS); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_IDX2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_idx4 (mng_datap pData) -{ - mng_uint8p pRawi, pRawo; - mng_int32 iX; - mng_int32 iC, iS; - mng_uint8 iB, iN, iQ; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_IDX4, MNG_LC_START); -#endif - - pRawi = pData->pWorkrow + pData->iPixelofs; - pRawo = pData->pPrevrow + pData->iPixelofs; - iC = 0; - iB = 0; - iN = 0; - iS = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iC) - { - iC = 2; - iB = *pRawi++; - iN = 0; - iS = 8; - } - - iS -= 4; - iQ = (mng_uint8)(((iB >> iS) + pData->iLevel0) & 0x0F); - iN = (mng_uint8)((iN << 4) + iQ); - iC--; - - if (!iC) - *pRawo++ = iN; - - } - - if (iC) - *pRawo = (mng_uint8)(iN << iS); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_IDX4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_idx8 (mng_datap pData) -{ - mng_uint8p pRawi, pRawo; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_IDX8, MNG_LC_START); -#endif - - pRawi = pData->pWorkrow + pData->iPixelofs; - pRawo = pData->pPrevrow + pData->iPixelofs; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pRawo++ = (mng_uint8)(((mng_uint16)*pRawi + pData->iLevel0) & 0xFF); - - pRawi++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_IDX8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_ga8 (mng_datap pData) -{ - mng_uint8p pRawi, pRawo; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_GA8, MNG_LC_START); -#endif - - pRawi = pData->pWorkrow + pData->iPixelofs; - pRawo = pData->pPrevrow + pData->iPixelofs; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pRawo = (mng_uint8)(((mng_uint16)*pRawi + pData->iLevel0) & 0xFF); - *(pRawo+1) = (mng_uint8)(((mng_uint16)*(pRawi+1) + pData->iLevel1) & 0xFF); - - pRawi += 2; - pRawo += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_GA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_ga16 (mng_datap pData) -{ - mng_uint16p pRawi, pRawo; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_GA16, MNG_LC_START); -#endif - - pRawi = (mng_uint16p)(pData->pWorkrow + pData->iPixelofs); - pRawo = (mng_uint16p)(pData->pPrevrow + pData->iPixelofs); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pRawo = (mng_uint16)(((mng_uint32)*pRawi + (mng_uint32)pData->iLevel0) & 0xFFFF); - *(pRawo+1) = (mng_uint16)(((mng_uint32)*(pRawi+1) + (mng_uint32)pData->iLevel1) & 0xFFFF); - - pRawi += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_GA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_rgba8 (mng_datap pData) -{ - mng_uint8p pRawi, pRawo; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_RGBA8, MNG_LC_START); -#endif - - pRawi = pData->pWorkrow + pData->iPixelofs; - pRawo = pData->pPrevrow + pData->iPixelofs; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *(pRawo+1) = (mng_uint8)(((mng_uint16)*(pRawi+1) + pData->iLevel1) & 0xFF); - *pRawo = (mng_uint8)(((mng_uint16)*pRawi + pData->iLevel0 + - (mng_uint16)*(pRawo+1)) & 0xFF); - *(pRawo+2) = (mng_uint8)(((mng_uint16)*(pRawi+2) + pData->iLevel2 + - (mng_uint16)*(pRawo+1)) & 0xFF); - *(pRawo+3) = (mng_uint8)(((mng_uint16)*(pRawi+3) + pData->iLevel3) & 0xFF); - - pRawi += 4; - pRawo += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_differ_rgba16 (mng_datap pData) -{ - mng_uint16p pRawi, pRawo; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_RGBA16, MNG_LC_START); -#endif - - pRawi = (mng_uint16p)(pData->pWorkrow + pData->iPixelofs); - pRawo = (mng_uint16p)(pData->pPrevrow + pData->iPixelofs); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples - 1; iX >= 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *(pRawo+1) = (mng_uint16)(((mng_uint32)*(pRawi+1) + (mng_uint32)pData->iLevel1) & 0xFFFF); - *pRawo = (mng_uint16)(((mng_uint32)*pRawi + (mng_uint32)pData->iLevel0 + - (mng_uint32)*(pRawo+1)) & 0xFFFF); - *(pRawo+2) = (mng_uint16)(((mng_uint32)*(pRawi+2) + (mng_uint32)pData->iLevel2 + - (mng_uint32)*(pRawo+1)) & 0xFFFF); - *(pRawo+3) = (mng_uint16)(((mng_uint32)*(pRawi+3) + (mng_uint32)pData->iLevel3) & 0xFFFF); - - pRawi += 4; - pRawo += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DIFFER_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#endif /* FILTER192 */ - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_FILTERS */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_filter.c copyright (c) 2000-2004 G.Juyn * */ +/* * version : 1.0.9 * */ +/* * * */ +/* * purpose : Filtering routines (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the filtering routines * */ +/* * * */ +/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - changed trace to macro for callback error-reporting * */ +/* * * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 0.9.3 - 09/07/2000 - G.Juyn * */ +/* * - added support for new filter_types * */ +/* * * */ +/* * 1.0.5 - 08/07/2002 - G.Juyn * */ +/* * - added test-option for PNG filter method 193 (=no filter) * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * * */ +/* * 1.0.6 - 07/07/2003 - G.R-P * */ +/* * - reversed some loops to use decrementing counter * */ +/* * * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_filter.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_FILTERS + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode filter_sub (mng_datap pData) +{ + mng_uint32 iBpp; + mng_uint8p pRawx; + mng_uint8p pRawx_prev; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FILTER_SUB, MNG_LC_START); +#endif + + iBpp = pData->iFilterbpp; + pRawx = pData->pWorkrow + pData->iPixelofs + iBpp; + pRawx_prev = pData->pWorkrow + pData->iPixelofs; + + for (iX = iBpp; iX < pData->iRowsize; iX++) + { + *pRawx = (mng_uint8)(*pRawx + *pRawx_prev); + pRawx++; + pRawx_prev++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FILTER_SUB, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode filter_up (mng_datap pData) +{ + mng_uint8p pRawx; + mng_uint8p pPriorx; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FILTER_UP, MNG_LC_START); +#endif + + pRawx = pData->pWorkrow + pData->iPixelofs; + pPriorx = pData->pPrevrow + pData->iPixelofs; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsize - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsize; iX++) +#endif + { + *pRawx = (mng_uint8)(*pRawx + *pPriorx); + pRawx++; + pPriorx++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FILTER_UP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode filter_average (mng_datap pData) +{ + mng_int32 iBpp; + mng_uint8p pRawx; + mng_uint8p pRawx_prev; + mng_uint8p pPriorx; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FILTER_AVERAGE, MNG_LC_START); +#endif + + iBpp = pData->iFilterbpp; + pRawx = pData->pWorkrow + pData->iPixelofs; + pPriorx = pData->pPrevrow + pData->iPixelofs; + pRawx_prev = pData->pWorkrow + pData->iPixelofs; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = iBpp - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < iBpp; iX++) +#endif + { + *pRawx = (mng_uint8)(*pRawx + ((*pPriorx) >> 1)); + pRawx++; + pPriorx++; + } + + for (iX = iBpp; iX < pData->iRowsize; iX++) + { + *pRawx = (mng_uint8)(*pRawx + ((*pRawx_prev + *pPriorx) >> 1)); + pRawx++; + pPriorx++; + pRawx_prev++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FILTER_AVERAGE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode filter_paeth (mng_datap pData) +{ + mng_int32 iBpp; + mng_uint8p pRawx; + mng_uint8p pRawx_prev; + mng_uint8p pPriorx; + mng_uint8p pPriorx_prev; + mng_int32 iX; + mng_uint32 iA, iB, iC; + mng_uint32 iP; + mng_uint32 iPa, iPb, iPc; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FILTER_PAETH, MNG_LC_START); +#endif + + iBpp = pData->iFilterbpp; + pRawx = pData->pWorkrow + pData->iPixelofs; + pPriorx = pData->pPrevrow + pData->iPixelofs; + pRawx_prev = pData->pWorkrow + pData->iPixelofs; + pPriorx_prev = pData->pPrevrow + pData->iPixelofs; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = iBpp - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < iBpp; iX++) +#endif + { + *pRawx = (mng_uint8)(*pRawx + *pPriorx); + + pRawx++; + pPriorx++; + } + + for (iX = iBpp; iX < pData->iRowsize; iX++) + { + iA = (mng_uint32)*pRawx_prev; + iB = (mng_uint32)*pPriorx; + iC = (mng_uint32)*pPriorx_prev; + iP = iA + iB - iC; + iPa = abs (iP - iA); + iPb = abs (iP - iB); + iPc = abs (iP - iC); + + if ((iPa <= iPb) && (iPa <= iPc)) + *pRawx = (mng_uint8)(*pRawx + iA); + else + if (iPb <= iPc) + *pRawx = (mng_uint8)(*pRawx + iB); + else + *pRawx = (mng_uint8)(*pRawx + iC); + + pRawx++; + pPriorx++; + pRawx_prev++; + pPriorx_prev++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FILTER_PAETH, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_filter_a_row (mng_datap pData) +{ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FILTER_A_ROW, MNG_LC_START); +#endif + + switch (*(pData->pWorkrow + pData->iFilterofs)) + { + case 1 : { + iRetcode = filter_sub (pData); + break; + } + case 2 : { + iRetcode = filter_up (pData); + break; + } + case 3 : { + iRetcode = filter_average (pData); + break; + } + case 4 : { + iRetcode = filter_paeth (pData); + break; + } + + default : iRetcode = MNG_INVALIDFILTER; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FILTER_A_ROW, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifdef FILTER192 +mng_retcode mng_init_rowdiffering (mng_datap pData) +{ + mng_uint8p pRawi, pRawo; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_ROWDIFFERING, MNG_LC_START); +#endif + + if (pData->iFilter == 0xC0) /* has leveling parameters ? */ + { + switch (pData->iColortype) /* salvage leveling parameters */ + { + case 0 : { /* gray */ + if (pData->iBitdepth <= 8) + pData->iLevel0 = (mng_uint16)*pData->pWorkrow; + else + pData->iLevel0 = mng_get_uint16 (pData->pWorkrow); + + break; + } + case 2 : { /* rgb */ + if (pData->iBitdepth <= 8) + { + pData->iLevel0 = (mng_uint16)*pData->pWorkrow; + pData->iLevel1 = (mng_uint16)*(pData->pWorkrow+1); + pData->iLevel2 = (mng_uint16)*(pData->pWorkrow+2); + } + else + { + pData->iLevel0 = mng_get_uint16 (pData->pWorkrow); + pData->iLevel1 = mng_get_uint16 (pData->pWorkrow+2); + pData->iLevel2 = mng_get_uint16 (pData->pWorkrow+4); + } + + break; + } + case 3 : { /* indexed */ + pData->iLevel0 = (mng_uint16)*pData->pWorkrow; + break; + } + case 4 : { /* gray+alpha */ + if (pData->iBitdepth <= 8) + { + pData->iLevel0 = (mng_uint16)*pData->pWorkrow; + pData->iLevel1 = (mng_uint16)*(pData->pWorkrow+1); + } + else + { + pData->iLevel0 = mng_get_uint16 (pData->pWorkrow); + pData->iLevel1 = mng_get_uint16 (pData->pWorkrow+2); + } + + break; + } + case 6 : { /* rgb+alpha */ + if (pData->iBitdepth <= 8) + { + pData->iLevel0 = (mng_uint16)*pData->pWorkrow; + pData->iLevel1 = (mng_uint16)*(pData->pWorkrow+1); + pData->iLevel2 = (mng_uint16)*(pData->pWorkrow+2); + pData->iLevel3 = (mng_uint16)*(pData->pWorkrow+3); + } + else + { + pData->iLevel0 = mng_get_uint16 (pData->pWorkrow); + pData->iLevel1 = mng_get_uint16 (pData->pWorkrow+2); + pData->iLevel2 = mng_get_uint16 (pData->pWorkrow+4); + pData->iLevel3 = mng_get_uint16 (pData->pWorkrow+6); + } + + break; + } + } + } + /* shift the entire row back in place */ + pRawi = pData->pWorkrow + pData->iFilterofs; + pRawo = pData->pWorkrow; + + for (iX = 0; iX < pData->iRowsize + pData->iPixelofs - pData->iFilterofs; iX++) + *pRawo++ = *pRawi++; + + pData->iFilterofs = 0; /* indicate so ! */ + +#ifdef FILTER193 + if (pData->iFilter == 0xC1) /* no adaptive filtering ? */ + pData->iPixelofs = pData->iFilterofs; + else +#endif + pData->iPixelofs = pData->iFilterofs + 1; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_ROWDIFFERING, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_g1 (mng_datap pData) +{ + mng_uint8p pRawi, pRawo; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_G1, MNG_LC_START); +#endif + + if (pData->iLevel0 & 0x01) /* is it uneven level ? */ + { + pRawi = pData->pWorkrow + pData->iPixelofs; + pRawo = pData->pPrevrow + pData->iPixelofs; + /* just invert every bit */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsize - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsize; iX++) +#endif + *pRawo++ = (mng_uint8)(~(*pRawi++)); + + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_G1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_g2 (mng_datap pData) +{ + mng_uint8p pRawi, pRawo; + mng_int32 iX; + mng_int32 iC, iS; + mng_uint8 iB, iN, iQ; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_G2, MNG_LC_START); +#endif + + pRawi = pData->pWorkrow + pData->iPixelofs; + pRawo = pData->pPrevrow + pData->iPixelofs; + iC = 0; + iB = 0; + iN = 0; + iS = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iC) + { + iC = 4; + iB = *pRawi++; + iN = 0; + iS = 8; + } + + iS -= 2; + iQ = (mng_uint8)(((iB >> iS) + pData->iLevel0) & 0x03); + iN = (mng_uint8)((iN << 2) + iQ); + iC--; + + if (!iC) + *pRawo++ = iN; + + } + + if (iC) + *pRawo = (mng_uint8)(iN << iS); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_G2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_g4 (mng_datap pData) +{ + mng_uint8p pRawi, pRawo; + mng_int32 iX; + mng_int32 iC, iS; + mng_uint8 iB, iN, iQ; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_G4, MNG_LC_START); +#endif + + pRawi = pData->pWorkrow + pData->iPixelofs; + pRawo = pData->pPrevrow + pData->iPixelofs; + iC = 0; + iB = 0; + iN = 0; + iS = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iC) + { + iC = 2; + iB = *pRawi++; + iN = 0; + iS = 8; + } + + iS -= 4; + iQ = (mng_uint8)(((iB >> iS) + pData->iLevel0) & 0x0F); + iN = (mng_uint8)((iN << 4) + iQ); + iC--; + + if (!iC) + *pRawo++ = iN; + + } + + if (iC) + *pRawo = (mng_uint8)(iN << iS); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_G4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_g8 (mng_datap pData) +{ + mng_uint8p pRawi, pRawo; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_G8, MNG_LC_START); +#endif + + pRawi = pData->pWorkrow + pData->iPixelofs; + pRawo = pData->pPrevrow + pData->iPixelofs; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pRawo++ = (mng_uint8)(((mng_uint16)*pRawi + pData->iLevel0) & 0xFF); + + pRawi++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_G8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_g16 (mng_datap pData) +{ + mng_uint16p pRawi, pRawo; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_G16, MNG_LC_START); +#endif + + pRawi = (mng_uint16p)(pData->pWorkrow + pData->iPixelofs); + pRawo = (mng_uint16p)(pData->pPrevrow + pData->iPixelofs); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pRawo++ = (mng_uint16)(((mng_uint32)*pRawi + (mng_uint32)pData->iLevel0) & 0xFFFF); + + pRawi++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_G16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_rgb8 (mng_datap pData) +{ + mng_uint8p pRawi, pRawo; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_RGB8, MNG_LC_START); +#endif + + pRawi = pData->pWorkrow + pData->iPixelofs; + pRawo = pData->pPrevrow + pData->iPixelofs; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *(pRawo+1) = (mng_uint8)(((mng_uint16)*(pRawi+1) + pData->iLevel1) & 0xFF); + *pRawo = (mng_uint8)(((mng_uint16)*pRawi + pData->iLevel0 + + (mng_uint16)*(pRawo+1)) & 0xFF); + *(pRawo+2) = (mng_uint8)(((mng_uint16)*(pRawi+2) + pData->iLevel2 + + (mng_uint16)*(pRawo+1)) & 0xFF); + + pRawi += 3; + pRawo += 3; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_RGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_rgb16 (mng_datap pData) +{ + mng_uint16p pRawi, pRawo; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_RGB16, MNG_LC_START); +#endif + + pRawi = (mng_uint16p)(pData->pWorkrow + pData->iPixelofs); + pRawo = (mng_uint16p)(pData->pPrevrow + pData->iPixelofs); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *(pRawo+1) = (mng_uint16)(((mng_uint32)*(pRawi+1) + (mng_uint32)pData->iLevel1) & 0xFFFF); + *pRawo = (mng_uint16)(((mng_uint32)*pRawi + (mng_uint32)pData->iLevel0 + + (mng_uint32)*(pRawo+1)) & 0xFFFF); + *(pRawo+2) = (mng_uint16)(((mng_uint32)*(pRawi+2) + (mng_uint32)pData->iLevel2 + + (mng_uint32)*(pRawo+1)) & 0xFFFF); + + pRawi += 3; + pRawo += 3; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_RGB16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_idx1 (mng_datap pData) +{ + mng_uint8p pRawi, pRawo; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_IDX1, MNG_LC_START); +#endif + + if (pData->iLevel0 & 0x01) /* is it uneven level ? */ + { + pRawi = pData->pWorkrow + pData->iPixelofs; + pRawo = pData->pPrevrow + pData->iPixelofs; + /* just invert every bit */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsize - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsize; iX++) +#endif + *pRawo++ = (mng_uint8)(~(*pRawi++)); + + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_IDX1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_idx2 (mng_datap pData) +{ + mng_uint8p pRawi, pRawo; + mng_int32 iX; + mng_int32 iC, iS; + mng_uint8 iB, iN, iQ; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_IDX2, MNG_LC_START); +#endif + + pRawi = pData->pWorkrow + pData->iPixelofs; + pRawo = pData->pPrevrow + pData->iPixelofs; + iC = 0; + iB = 0; + iN = 0; + iS = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iC) + { + iC = 4; + iB = *pRawi++; + iN = 0; + iS = 8; + } + + iS -= 2; + iQ = (mng_uint8)(((iB >> iS) + pData->iLevel0) & 0x03); + iN = (mng_uint8)((iN << 2) + iQ); + iC--; + + if (!iC) + *pRawo++ = iN; + + } + + if (iC) + *pRawo = (mng_uint8)(iN << iS); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_IDX2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_idx4 (mng_datap pData) +{ + mng_uint8p pRawi, pRawo; + mng_int32 iX; + mng_int32 iC, iS; + mng_uint8 iB, iN, iQ; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_IDX4, MNG_LC_START); +#endif + + pRawi = pData->pWorkrow + pData->iPixelofs; + pRawo = pData->pPrevrow + pData->iPixelofs; + iC = 0; + iB = 0; + iN = 0; + iS = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iC) + { + iC = 2; + iB = *pRawi++; + iN = 0; + iS = 8; + } + + iS -= 4; + iQ = (mng_uint8)(((iB >> iS) + pData->iLevel0) & 0x0F); + iN = (mng_uint8)((iN << 4) + iQ); + iC--; + + if (!iC) + *pRawo++ = iN; + + } + + if (iC) + *pRawo = (mng_uint8)(iN << iS); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_IDX4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_idx8 (mng_datap pData) +{ + mng_uint8p pRawi, pRawo; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_IDX8, MNG_LC_START); +#endif + + pRawi = pData->pWorkrow + pData->iPixelofs; + pRawo = pData->pPrevrow + pData->iPixelofs; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pRawo++ = (mng_uint8)(((mng_uint16)*pRawi + pData->iLevel0) & 0xFF); + + pRawi++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_IDX8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_ga8 (mng_datap pData) +{ + mng_uint8p pRawi, pRawo; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_GA8, MNG_LC_START); +#endif + + pRawi = pData->pWorkrow + pData->iPixelofs; + pRawo = pData->pPrevrow + pData->iPixelofs; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pRawo = (mng_uint8)(((mng_uint16)*pRawi + pData->iLevel0) & 0xFF); + *(pRawo+1) = (mng_uint8)(((mng_uint16)*(pRawi+1) + pData->iLevel1) & 0xFF); + + pRawi += 2; + pRawo += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_GA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_ga16 (mng_datap pData) +{ + mng_uint16p pRawi, pRawo; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_GA16, MNG_LC_START); +#endif + + pRawi = (mng_uint16p)(pData->pWorkrow + pData->iPixelofs); + pRawo = (mng_uint16p)(pData->pPrevrow + pData->iPixelofs); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pRawo = (mng_uint16)(((mng_uint32)*pRawi + (mng_uint32)pData->iLevel0) & 0xFFFF); + *(pRawo+1) = (mng_uint16)(((mng_uint32)*(pRawi+1) + (mng_uint32)pData->iLevel1) & 0xFFFF); + + pRawi += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_GA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_rgba8 (mng_datap pData) +{ + mng_uint8p pRawi, pRawo; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_RGBA8, MNG_LC_START); +#endif + + pRawi = pData->pWorkrow + pData->iPixelofs; + pRawo = pData->pPrevrow + pData->iPixelofs; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *(pRawo+1) = (mng_uint8)(((mng_uint16)*(pRawi+1) + pData->iLevel1) & 0xFF); + *pRawo = (mng_uint8)(((mng_uint16)*pRawi + pData->iLevel0 + + (mng_uint16)*(pRawo+1)) & 0xFF); + *(pRawo+2) = (mng_uint8)(((mng_uint16)*(pRawi+2) + pData->iLevel2 + + (mng_uint16)*(pRawo+1)) & 0xFF); + *(pRawo+3) = (mng_uint8)(((mng_uint16)*(pRawi+3) + pData->iLevel3) & 0xFF); + + pRawi += 4; + pRawo += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_differ_rgba16 (mng_datap pData) +{ + mng_uint16p pRawi, pRawo; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_RGBA16, MNG_LC_START); +#endif + + pRawi = (mng_uint16p)(pData->pWorkrow + pData->iPixelofs); + pRawo = (mng_uint16p)(pData->pPrevrow + pData->iPixelofs); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples - 1; iX >= 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *(pRawo+1) = (mng_uint16)(((mng_uint32)*(pRawi+1) + (mng_uint32)pData->iLevel1) & 0xFFFF); + *pRawo = (mng_uint16)(((mng_uint32)*pRawi + (mng_uint32)pData->iLevel0 + + (mng_uint32)*(pRawo+1)) & 0xFFFF); + *(pRawo+2) = (mng_uint16)(((mng_uint32)*(pRawi+2) + (mng_uint32)pData->iLevel2 + + (mng_uint32)*(pRawo+1)) & 0xFFFF); + *(pRawo+3) = (mng_uint16)(((mng_uint32)*(pRawi+3) + (mng_uint32)pData->iLevel3) & 0xFFFF); + + pRawi += 4; + pRawo += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DIFFER_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#endif /* FILTER192 */ + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_FILTERS */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + diff --git a/Source/LibMNG/libmng_hlapi.c b/Source/LibMNG/libmng_hlapi.c index ef0c2e1..6199d59 100644 --- a/Source/LibMNG/libmng_hlapi.c +++ b/Source/LibMNG/libmng_hlapi.c @@ -1,2995 +1,2995 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_hlapi.c copyright (c) 2000-2007 G.Juyn * */ -/* * version : 1.0.10 * */ -/* * * */ -/* * purpose : high-level application API (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the high-level function interface * */ -/* * for applications. * */ -/* * * */ -/* * changes : 0.5.1 - 05/06/2000 - G.Juyn * */ -/* * - added init of iPLTEcount * */ -/* * 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - changed calling-convention definition * */ -/* * - changed status-handling of display-routines * */ -/* * - added versioning-control routines * */ -/* * - filled the write routine * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/11/2000 - G.Juyn * */ -/* * - added callback error-reporting support * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - changed trace to macro for callback error-reporting * */ -/* * 0.5.1 - 05/13/2000 - G.Juyn * */ -/* * - added eMNGma hack (will be removed in 1.0.0 !!!) * */ -/* * - added TERM animation object pointer (easier reference) * */ -/* * 0.5.1 - 05/14/2000 - G.Juyn * */ -/* * - added cleanup of saved-data (SAVE/SEEK processing) * */ -/* * 0.5.1 - 05/16/2000 - G.Juyn * */ -/* * - moved the actual write_graphic functionality from here * */ -/* * to its appropriate function in the mng_write module * */ -/* * * */ -/* * 0.5.2 - 05/19/2000 - G.Juyn * */ -/* * - cleaned up some code regarding mixed support * */ -/* * - added JNG support * */ -/* * 0.5.2 - 05/24/2000 - G.Juyn * */ -/* * - moved init of default zlib parms here from "mng_zlib.c" * */ -/* * - added init of default IJG parms * */ -/* * 0.5.2 - 05/29/2000 - G.Juyn * */ -/* * - fixed inconsistancy with freeing global iCCP profile * */ -/* * 0.5.2 - 05/30/2000 - G.Juyn * */ -/* * - added delta-image field initialization * */ -/* * 0.5.2 - 06/06/2000 - G.Juyn * */ -/* * - added initialization of the buffer-suspend parameter * */ -/* * * */ -/* * 0.5.3 - 06/16/2000 - G.Juyn * */ -/* * - added initialization of update-region for refresh * */ -/* * - added initialization of Needrefresh parameter * */ -/* * 0.5.3 - 06/17/2000 - G.Juyn * */ -/* * - added initialization of Deltaimmediate * */ -/* * 0.5.3 - 06/21/2000 - G.Juyn * */ -/* * - added initialization of Speed * */ -/* * - added initialization of Imagelevel * */ -/* * 0.5.3 - 06/26/2000 - G.Juyn * */ -/* * - changed userdata variable to mng_ptr * */ -/* * 0.5.3 - 06/29/2000 - G.Juyn * */ -/* * - fixed initialization routine for new mng_handle type * */ -/* * * */ -/* * 0.9.1 - 07/06/2000 - G.Juyn * */ -/* * - changed mng_display_resume to allow to be called after * */ -/* * a suspension return with MNG_NEEDMOREDATA * */ -/* * - added returncode MNG_NEEDTIMERWAIT for timer breaks * */ -/* * 0.9.1 - 07/07/2000 - G.Juyn * */ -/* * - implemented support for freeze/reset/resume & go_xxxx * */ -/* * 0.9.1 - 07/08/2000 - G.Juyn * */ -/* * - added support for improved timing * */ -/* * - added support for improved I/O-suspension * */ -/* * 0.9.1 - 07/14/2000 - G.Juyn * */ -/* * - changed EOF processing behavior * */ -/* * 0.9.1 - 07/15/2000 - G.Juyn * */ -/* * - added callbacks for SAVE/SEEK processing * */ -/* * - added variable for NEEDSECTIONWAIT breaks * */ -/* * - added variable for freeze & reset processing * */ -/* * 0.9.1 - 07/17/2000 - G.Juyn * */ -/* * - added error cleanup processing * */ -/* * - fixed support for mng_display_reset() * */ -/* * - fixed suspension-buffering for 32K+ chunks * */ -/* * * */ -/* * 0.9.2 - 07/29/2000 - G.Juyn * */ -/* * - fixed small bugs in display processing * */ -/* * 0.9.2 - 07/31/2000 - G.Juyn * */ -/* * - fixed wrapping of suspension parameters * */ -/* * 0.9.2 - 08/04/2000 - G.Juyn * */ -/* * - B111096 - fixed large-buffer read-suspension * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 0.9.3 - 09/07/2000 - G.Juyn * */ -/* * - added support for new filter_types * */ -/* * 0.9.3 - 09/10/2000 - G.Juyn * */ -/* * - fixed DEFI behavior * */ -/* * 0.9.3 - 10/11/2000 - G.Juyn * */ -/* * - added support for nEED * */ -/* * 0.9.3 - 10/16/2000 - G.Juyn * */ -/* * - added optional support for bKGD for PNG images * */ -/* * - raised initial maximum canvas size * */ -/* * - added support for JDAA * */ -/* * 0.9.3 - 10/17/2000 - G.Juyn * */ -/* * - added callback to process non-critical unknown chunks * */ -/* * - fixed support for delta-images during read() / display() * */ -/* * 0.9.3 - 10/18/2000 - G.Juyn * */ -/* * - added closestream() processing for mng_cleanup() * */ -/* * 0.9.3 - 10/27/2000 - G.Juyn * */ -/* * - fixed separate read() & display() processing * */ -/* * * */ -/* * 0.9.4 - 11/20/2000 - G.Juyn * */ -/* * - fixed unwanted repetition in mng_readdisplay() * */ -/* * 0.9.4 - 11/24/2000 - G.Juyn * */ -/* * - moved restore of object 0 to libmng_display * */ -/* * * */ -/* * 1.0.1 - 02/08/2001 - G.Juyn * */ -/* * - added MEND processing callback * */ -/* * 1.0.1 - 02/13/2001 - G.Juyn * */ -/* * - fixed first FRAM_MODE=4 timing problem * */ -/* * 1.0.1 - 04/21/2001 - G.Juyn * */ -/* * - fixed bug with display_reset/display_resume (Thanks G!) * */ -/* * 1.0.1 - 04/22/2001 - G.Juyn * */ -/* * - fixed memory-leak (Thanks Gregg!) * */ -/* * 1.0.1 - 04/23/2001 - G.Juyn * */ -/* * - fixed reset_rundata to drop all objects * */ -/* * 1.0.1 - 04/25/2001 - G.Juyn * */ -/* * - moved mng_clear_cms to libmng_cms * */ -/* * * */ -/* * 1.0.2 - 06/23/2001 - G.Juyn * */ -/* * - added optimization option for MNG-video playback * */ -/* * - added processterm callback * */ -/* * 1.0.2 - 06/25/2001 - G.Juyn * */ -/* * - added option to turn off progressive refresh * */ -/* * * */ -/* * 1.0.5 - 07/08/2002 - G.Juyn * */ -/* * - B578572 - removed eMNGma hack (thanks Dimitri!) * */ -/* * 1.0.5 - 07/16/2002 - G.Juyn * */ -/* * - B581625 - large chunks fail with suspension reads * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * 1.0.5 - 09/15/2002 - G.Juyn * */ -/* * - fixed LOOP iteration=0 special case * */ -/* * 1.0.5 - 10/07/2002 - G.Juyn * */ -/* * - added another fix for misplaced TERM chunk * */ -/* * - completed support for condition=2 in TERM chunk * */ -/* * - added beta version function & constant * */ -/* * 1.0.5 - 10/11/2002 - G.Juyn * */ -/* * - added mng_status_dynamic to supports function * */ -/* * 1.0.5 - 11/04/2002 - G.Juyn * */ -/* * - changed FRAMECOUNT/LAYERCOUNT/PLAYTIME error to warning * */ -/* * 1.0.5 - 11/07/2002 - G.Juyn * */ -/* * - added support to get totals after mng_read() * */ -/* * 1.0.5 - 11/29/2002 - G.Juyn * */ -/* * - fixed goxxxxx() support for zero values * */ -/* * * */ -/* * 1.0.6 - 05/25/2003 - G.R-P * */ -/* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */ -/* * 1.0.6 - 07/11/2003 - G.R-P * */ -/* * - added conditionals zlib and jpeg property accessors * */ -/* * 1.0.6 - 07/14/2003 - G.R-P * */ -/* * - added conditionals around "mng_display_go*" and other * */ -/* * unused functions * */ -/* * 1.0.6 - 07/29/2003 - G.R-P * */ -/* * - added conditionals around PAST chunk support * */ -/* * * */ -/* * 1.0.7 - 03/07/2004 - G. Randers-Pehrson * */ -/* * - put gamma, cms-related declarations inside #ifdef * */ -/* * 1.0.7 - 03/10/2004 - G.R-P * */ -/* * - added conditionals around openstream/closestream * */ -/* * 1.0.7 - 03/24/2004 - G.R-P * */ -/* * - fixed zTXT -> zTXt typo * */ -/* * * */ -/* * 1.0.8 - 04/02/2004 - G.Juyn * */ -/* * - added CRC existence & checking flags * */ -/* * 1.0.8 - 04/10/2004 - G.Juyn * */ -/* * - added data-push mechanisms for specialized decoders * */ -/* * 1.0.8 - 07/06/2004 - G.R-P * */ -/* * - defend against using undefined openstream function * */ -/* * 1.0.8 - 08/02/2004 - G.Juyn * */ -/* * - added conditional to allow easier writing of large MNG's * */ -/* * * */ -/* * 1.0.9 - 08/17/2004 - G.R-P * */ -/* * - added more SKIPCHUNK conditionals * */ -/* * 1.0.9 - 09/25/2004 - G.Juyn * */ -/* * - replaced MNG_TWEAK_LARGE_FILES with permanent solution * */ -/* * 1.0.9 - 10/03/2004 - G.Juyn * */ -/* * - added function to retrieve current FRAM delay * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * * */ -/* * 1.0.10 - 07/06/2005 - G.R-P * */ -/* * - added more SKIPCHUNK conditionals * */ -/* * 1.0.10 - 04/08/2007 - G.Juyn * */ -/* * - added support for mPNG proposal * */ -/* * 1.0.10 - 04/12/2007 - G.Juyn * */ -/* * - added support for ANG proposal * */ -/* * 1.0.10 - 07/06/2007 - G.R-P bugfix by Lucas Quintana * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_objects.h" -#include "libmng_object_prc.h" -#include "libmng_chunks.h" -#include "libmng_memory.h" -#include "libmng_read.h" -#include "libmng_write.h" -#include "libmng_display.h" -#include "libmng_zlib.h" -#include "libmng_jpeg.h" -#include "libmng_cms.h" -#include "libmng_pixels.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ -/* * * */ -/* * local routines * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -MNG_LOCAL mng_retcode mng_drop_objects (mng_datap pData, - mng_bool bDropaniobj) -{ - mng_objectp pObject; - mng_objectp pNext; - mng_cleanupobject fCleanup; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DROP_OBJECTS, MNG_LC_START); -#endif - - pObject = pData->pFirstimgobj; /* get first stored image-object (if any) */ - - while (pObject) /* more objects to discard ? */ - { - pNext = ((mng_object_headerp)pObject)->pNext; - /* call appropriate cleanup */ - fCleanup = ((mng_object_headerp)pObject)->fCleanup; - fCleanup (pData, pObject); - - pObject = pNext; /* neeeext */ - } - - pData->pFirstimgobj = MNG_NULL; /* clean this up!!! */ - pData->pLastimgobj = MNG_NULL; - - if (bDropaniobj) /* drop animation objects ? */ - { - pObject = pData->pFirstaniobj; /* get first stored animation-object (if any) */ - - while (pObject) /* more objects to discard ? */ - { - pNext = ((mng_object_headerp)pObject)->pNext; - /* call appropriate cleanup */ - fCleanup = ((mng_object_headerp)pObject)->fCleanup; - fCleanup (pData, pObject); - - pObject = pNext; /* neeeext */ - } - - pData->pFirstaniobj = MNG_NULL; /* clean this up!!! */ - pData->pLastaniobj = MNG_NULL; - -#ifdef MNG_SUPPORT_DYNAMICMNG - pObject = pData->pFirstevent; /* get first event-object (if any) */ - - while (pObject) /* more objects to discard ? */ - { - pNext = ((mng_object_headerp)pObject)->pNext; - /* call appropriate cleanup */ - fCleanup = ((mng_object_headerp)pObject)->fCleanup; - fCleanup (pData, pObject); - - pObject = pNext; /* neeeext */ - } - - pData->pFirstevent = MNG_NULL; /* clean this up!!! */ - pData->pLastevent = MNG_NULL; -#endif - } - -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - if (pData->pMPNG) /* drop MPNG data (if any) */ - { - fCleanup = ((mng_object_headerp)pData->pMPNG)->fCleanup; - fCleanup (pData, pData->pMPNG); - pData->pMPNG = MNG_NULL; - } -#endif - -#ifdef MNG_INCLUDE_ANG_PROPOSAL - if (pData->pANG) /* drop ANG data (if any) */ - { - fCleanup = ((mng_object_headerp)pData->pANG)->fCleanup; - fCleanup (pData, pData->pANG); - pData->pANG = MNG_NULL; - } -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DROP_OBJECTS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_SKIPCHUNK_SAVE -MNG_LOCAL mng_retcode mng_drop_savedata (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DROP_SAVEDATA, MNG_LC_START); -#endif - - if (pData->pSavedata) /* sanity check */ - { /* address it more directly */ - mng_savedatap pSave = pData->pSavedata; - - if (pSave->iGlobalProfilesize) /* cleanup the profile ? */ - MNG_FREEX (pData, pSave->pGlobalProfile, pSave->iGlobalProfilesize); - /* cleanup the save structure */ - MNG_FREE (pData, pData->pSavedata, sizeof (mng_savedata)); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DROP_SAVEDATA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -MNG_LOCAL mng_retcode mng_reset_rundata (mng_datap pData) -{ - mng_drop_invalid_objects (pData); /* drop invalidly stored objects */ -#ifndef MNG_SKIPCHUNK_SAVE - mng_drop_savedata (pData); /* drop stored savedata */ -#endif - mng_reset_objzero (pData); /* reset object 0 */ - /* drop stored objects (if any) */ - mng_drop_objects (pData, MNG_FALSE); - - pData->bFramedone = MNG_FALSE; - pData->iFrameseq = 0; /* reset counters & stuff */ - pData->iLayerseq = 0; - pData->iFrametime = 0; - - pData->bSkipping = MNG_FALSE; - -#ifdef MNG_SUPPORT_DYNAMICMNG - pData->bRunningevent = MNG_FALSE; - pData->bStopafterseek = MNG_FALSE; - pData->iEventx = 0; - pData->iEventy = 0; - pData->pLastmousemove = MNG_NULL; -#endif - - pData->iRequestframe = 0; - pData->iRequestlayer = 0; - pData->iRequesttime = 0; - pData->bSearching = MNG_FALSE; - - pData->iRuntime = 0; - pData->iSynctime = 0; - pData->iStarttime = 0; - pData->iEndtime = 0; - pData->bRunning = MNG_FALSE; - pData->bTimerset = MNG_FALSE; - pData->iBreakpoint = 0; - pData->bSectionwait = MNG_FALSE; - pData->bFreezing = MNG_FALSE; - pData->bResetting = MNG_FALSE; - pData->bNeedrefresh = MNG_FALSE; - pData->bOnlyfirstframe = MNG_FALSE; - pData->iFramesafterTERM = 0; - - pData->iIterations = 0; - /* start of animation objects! */ - pData->pCurraniobj = MNG_NULL; - - pData->iUpdateleft = 0; /* reset region */ - pData->iUpdateright = 0; - pData->iUpdatetop = 0; - pData->iUpdatebottom = 0; - pData->iPLTEcount = 0; /* reset PLTE data */ - -#ifndef MNG_SKIPCHUNK_DEFI - pData->iDEFIobjectid = 0; /* reset DEFI data */ - pData->bDEFIhasdonotshow = MNG_FALSE; - pData->iDEFIdonotshow = 0; - pData->bDEFIhasconcrete = MNG_FALSE; - pData->iDEFIconcrete = 0; - pData->bDEFIhasloca = MNG_FALSE; - pData->iDEFIlocax = 0; - pData->iDEFIlocay = 0; - pData->bDEFIhasclip = MNG_FALSE; - pData->iDEFIclipl = 0; - pData->iDEFIclipr = 0; - pData->iDEFIclipt = 0; - pData->iDEFIclipb = 0; -#endif - -#ifndef MNG_SKIPCHUNK_BACK - pData->iBACKred = 0; /* reset BACK data */ - pData->iBACKgreen = 0; - pData->iBACKblue = 0; - pData->iBACKmandatory = 0; - pData->iBACKimageid = 0; - pData->iBACKtile = 0; -#endif - -#ifndef MNG_SKIPCHUNK_FRAM - pData->iFRAMmode = 1; /* default global FRAM variables */ - pData->iFRAMdelay = 1; - pData->iFRAMtimeout = 0x7fffffffl; - pData->bFRAMclipping = MNG_FALSE; - pData->iFRAMclipl = 0; - pData->iFRAMclipr = 0; - pData->iFRAMclipt = 0; - pData->iFRAMclipb = 0; - - pData->iFramemode = 1; /* again for the current frame */ - pData->iFramedelay = 1; - pData->iFrametimeout = 0x7fffffffl; - pData->bFrameclipping = MNG_FALSE; - pData->iFrameclipl = 0; - pData->iFrameclipr = 0; - pData->iFrameclipt = 0; - pData->iFrameclipb = 0; - - pData->iNextdelay = 1; -#endif - -#ifndef MNG_SKIPCHUNK_SHOW - pData->iSHOWmode = 0; /* reset SHOW data */ - pData->iSHOWfromid = 0; - pData->iSHOWtoid = 0; - pData->iSHOWnextid = 0; - pData->iSHOWskip = 0; -#endif - - pData->iGlobalPLTEcount = 0; /* reset global PLTE data */ - - pData->iGlobalTRNSrawlen = 0; /* reset global tRNS data */ - - pData->iGlobalGamma = 0; /* reset global gAMA data */ - -#ifndef MNG_SKIPCHUNK_cHRM - pData->iGlobalWhitepointx = 0; /* reset global cHRM data */ - pData->iGlobalWhitepointy = 0; - pData->iGlobalPrimaryredx = 0; - pData->iGlobalPrimaryredy = 0; - pData->iGlobalPrimarygreenx = 0; - pData->iGlobalPrimarygreeny = 0; - pData->iGlobalPrimarybluex = 0; - pData->iGlobalPrimarybluey = 0; -#endif - -#ifndef MNG_SKIPCHUNK_sRGB - pData->iGlobalRendintent = 0; /* reset global sRGB data */ -#endif - -#ifndef MNG_SKIPCHUNK_iCCP - if (pData->iGlobalProfilesize) /* drop global profile (if any) */ - MNG_FREE (pData, pData->pGlobalProfile, pData->iGlobalProfilesize); - - pData->iGlobalProfilesize = 0; -#endif - -#ifndef MNG_SKIPCHUNK_bKGD - pData->iGlobalBKGDred = 0; /* reset global bKGD data */ - pData->iGlobalBKGDgreen = 0; - pData->iGlobalBKGDblue = 0; -#endif -#ifndef MNG_NO_DELTA_PNG - /* reset delta-image */ - pData->pDeltaImage = MNG_NULL; - pData->iDeltaImagetype = 0; - pData->iDeltatype = 0; - pData->iDeltaBlockwidth = 0; - pData->iDeltaBlockheight = 0; - pData->iDeltaBlockx = 0; - pData->iDeltaBlocky = 0; - pData->bDeltaimmediate = MNG_FALSE; - - pData->fDeltagetrow = MNG_NULL; - pData->fDeltaaddrow = MNG_NULL; - pData->fDeltareplacerow = MNG_NULL; - pData->fDeltaputrow = MNG_NULL; - - pData->fPromoterow = MNG_NULL; - pData->fPromBitdepth = MNG_NULL; - pData->pPromBuf = MNG_NULL; - pData->iPromColortype = 0; - pData->iPromBitdepth = 0; - pData->iPromFilltype = 0; - pData->iPromWidth = 0; - pData->pPromSrc = MNG_NULL; - pData->pPromDst = MNG_NULL; -#endif - -#ifndef MNG_SKIPCHUNK_MAGN - pData->iMAGNfromid = 0; - pData->iMAGNtoid = 0; -#endif - -#ifndef MNG_SKIPCHUNK_PAST - pData->iPastx = 0; - pData->iPasty = 0; -#endif - - pData->pLastseek = MNG_NULL; - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -MNG_LOCAL void cleanup_errors (mng_datap pData) -{ - pData->iErrorcode = MNG_NOERROR; - pData->iSeverity = 0; - pData->iErrorx1 = 0; - pData->iErrorx2 = 0; - pData->zErrortext = MNG_NULL; - - return; -} - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -MNG_LOCAL mng_retcode make_pushbuffer (mng_datap pData, - mng_ptr pPushdata, - mng_size_t iLength, - mng_bool bTakeownership, - mng_pushdatap * pPush) -{ - mng_pushdatap pTemp; - - MNG_ALLOC (pData, pTemp, sizeof(mng_pushdata)); - - pTemp->pNext = MNG_NULL; - - if (bTakeownership) /* are we going to own the buffer? */ - { /* then just copy the pointer */ - pTemp->pData = (mng_uint8p)pPushdata; - } - else - { /* otherwise create new buffer */ - MNG_ALLOCX (pData, pTemp->pData, iLength); - if (!pTemp->pData) /* succeeded? */ - { - MNG_FREEX (pData, pTemp, sizeof(mng_pushdata)); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - /* and copy the bytes across */ - MNG_COPY (pTemp->pData, pPushdata, iLength); - } - - pTemp->iLength = iLength; - pTemp->bOwned = bTakeownership; - pTemp->pDatanext = pTemp->pData; - pTemp->iRemaining = iLength; - - *pPush = pTemp; /* return it */ - - return MNG_NOERROR; /* and all's well */ -} -#endif - -#ifdef MNG_VERSION_QUERY_SUPPORT -/* ************************************************************************** */ -/* * * */ -/* * Versioning control * */ -/* * * */ -/* ************************************************************************** */ - -mng_pchar MNG_DECL mng_version_text (void) -{ - return MNG_VERSION_TEXT; -} - -/* ************************************************************************** */ - -mng_uint8 MNG_DECL mng_version_so (void) -{ - return MNG_VERSION_SO; -} - -/* ************************************************************************** */ - -mng_uint8 MNG_DECL mng_version_dll (void) -{ - return MNG_VERSION_DLL; -} - -/* ************************************************************************** */ - -mng_uint8 MNG_DECL mng_version_major (void) -{ - return MNG_VERSION_MAJOR; -} - -/* ************************************************************************** */ - -mng_uint8 MNG_DECL mng_version_minor (void) -{ - return MNG_VERSION_MINOR; -} - -/* ************************************************************************** */ - -mng_uint8 MNG_DECL mng_version_release (void) -{ - return MNG_VERSION_RELEASE; -} - -/* ************************************************************************** */ - -mng_bool MNG_DECL mng_version_beta (void) -{ - return MNG_VERSION_BETA; -} -#endif - -/* ************************************************************************** */ -/* * * */ -/* * 'supports' function * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_FUNCQUERY -typedef struct { - mng_pchar zFunction; - mng_uint8 iMajor; /* Major == 0 means not implemented ! */ - mng_uint8 iMinor; - mng_uint8 iRelease; - } mng_func_entry; -typedef mng_func_entry const * mng_func_entryp; - -MNG_LOCAL mng_func_entry const func_table [] = - { /* keep it alphabetically sorted !!!!! */ - {"mng_cleanup", 1, 0, 0}, - {"mng_copy_chunk", 1, 0, 5}, - {"mng_create", 1, 0, 0}, - {"mng_display", 1, 0, 0}, - {"mng_display_freeze", 1, 0, 0}, -#ifndef MNG_NO_DISPLAY_GO_SUPPORTED - {"mng_display_goframe", 1, 0, 0}, - {"mng_display_golayer", 1, 0, 0}, - {"mng_display_gotime", 1, 0, 0}, -#endif - {"mng_display_reset", 1, 0, 0}, - {"mng_display_resume", 1, 0, 0}, - {"mng_get_alphabitdepth", 1, 0, 0}, - {"mng_get_alphacompression", 1, 0, 0}, - {"mng_get_alphadepth", 1, 0, 0}, - {"mng_get_alphafilter", 1, 0, 0}, - {"mng_get_alphainterlace", 1, 0, 0}, - {"mng_get_bgcolor", 1, 0, 0}, - {"mng_get_bitdepth", 1, 0, 0}, - {"mng_get_bkgdstyle", 1, 0, 0}, - {"mng_get_cacheplayback", 1, 0, 2}, - {"mng_get_canvasstyle", 1, 0, 0}, - {"mng_get_colortype", 1, 0, 0}, - {"mng_get_compression", 1, 0, 0}, -#ifndef MNG_NO_CURRENT_INFO - {"mng_get_currentframe", 1, 0, 0}, - {"mng_get_currentlayer", 1, 0, 0}, - {"mng_get_currentplaytime", 1, 0, 0}, -#endif - {"mng_get_currframdelay", 1, 0, 9}, -#ifndef MNG_NO_DFLT_INFO - {"mng_get_dfltimggamma", 1, 0, 0}, - {"mng_get_dfltimggammaint", 1, 0, 0}, -#endif - {"mng_get_displaygamma", 1, 0, 0}, - {"mng_get_displaygammaint", 1, 0, 0}, - {"mng_get_doprogressive", 1, 0, 2}, - {"mng_get_filter", 1, 0, 0}, - {"mng_get_framecount", 1, 0, 0}, - {"mng_get_imageheight", 1, 0, 0}, - {"mng_get_imagelevel", 1, 0, 0}, - {"mng_get_imagetype", 1, 0, 0}, - {"mng_get_imagewidth", 1, 0, 0}, - {"mng_get_interlace", 1, 0, 0}, -#ifdef MNG_ACCESS_JPEG - {"mng_get_jpeg_dctmethod", 1, 0, 0}, - {"mng_get_jpeg_maxjdat", 1, 0, 0}, - {"mng_get_jpeg_optimized", 1, 0, 0}, - {"mng_get_jpeg_progressive", 1, 0, 0}, - {"mng_get_jpeg_quality", 1, 0, 0}, - {"mng_get_jpeg_smoothing", 1, 0, 0}, -#endif - {"mng_get_lastbackchunk", 1, 0, 3}, - {"mng_get_lastseekname", 1, 0, 5}, - {"mng_get_layercount", 1, 0, 0}, -#ifndef MNG_SKIP_MAXCANVAS - {"mng_get_maxcanvasheight", 1, 0, 0}, - {"mng_get_maxcanvaswidth", 1, 0, 0}, -#endif - {"mng_get_playtime", 1, 0, 0}, - {"mng_get_refreshpass", 1, 0, 0}, - {"mng_get_runtime", 1, 0, 0}, - {"mng_get_sectionbreaks", 1, 0, 0}, - {"mng_get_sigtype", 1, 0, 0}, - {"mng_get_simplicity", 1, 0, 0}, - {"mng_get_speed", 1, 0, 0}, - {"mng_get_srgb", 1, 0, 0}, - {"mng_get_starttime", 1, 0, 0}, - {"mng_get_storechunks", 1, 0, 0}, - {"mng_get_suspensionmode", 1, 0, 0}, - {"mng_get_ticks", 1, 0, 0}, -#ifndef MNG_NO_CURRENT_INFO - {"mng_get_totalframes", 1, 0, 5}, - {"mng_get_totallayers", 1, 0, 5}, - {"mng_get_totalplaytime", 1, 0, 5}, -#endif - {"mng_get_usebkgd", 1, 0, 0}, - {"mng_get_userdata", 1, 0, 0}, -#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) - {"mng_get_viewgamma", 1, 0, 0}, - {"mng_get_viewgammaint", 1, 0, 0}, -#endif -#ifdef MNG_ACCESS_ZLIB - {"mng_get_zlib_level", 1, 0, 0}, - {"mng_get_zlib_maxidat", 1, 0, 0}, - {"mng_get_zlib_memlevel", 1, 0, 0}, - {"mng_get_zlib_method", 1, 0, 0}, - {"mng_get_zlib_strategy", 1, 0, 0}, - {"mng_get_zlib_windowbits", 1, 0, 0}, -#endif -#ifndef MNG_NO_OPEN_CLOSE_STREAM - {"mng_getcb_closestream", 1, 0, 0}, -#endif - {"mng_getcb_errorproc", 1, 0, 0}, - {"mng_getcb_getalphaline", 1, 0, 0}, - {"mng_getcb_getbkgdline", 1, 0, 0}, - {"mng_getcb_getcanvasline", 1, 0, 0}, - {"mng_getcb_gettickcount", 1, 0, 0}, - {"mng_getcb_memalloc", 1, 0, 0}, - {"mng_getcb_memfree", 1, 0, 0}, -#ifndef MNG_NO_OPEN_CLOSE_STREAM - {"mng_getcb_openstream", 1, 0, 0}, -#endif - {"mng_getcb_processarow", 1, 0, 0}, - {"mng_getcb_processchroma", 1, 0, 0}, - {"mng_getcb_processgamma", 1, 0, 0}, - {"mng_getcb_processheader", 1, 0, 0}, - {"mng_getcb_processiccp", 1, 0, 0}, - {"mng_getcb_processmend", 1, 0, 1}, - {"mng_getcb_processneed", 1, 0, 0}, - {"mng_getcb_processsave", 1, 0, 0}, - {"mng_getcb_processseek", 1, 0, 0}, - {"mng_getcb_processsrgb", 1, 0, 0}, - {"mng_getcb_processterm", 1, 0, 2}, - {"mng_getcb_processtext", 1, 0, 0}, - {"mng_getcb_processunknown", 1, 0, 0}, - {"mng_getcb_readdata", 1, 0, 0}, - {"mng_getcb_refresh", 1, 0, 0}, - {"mng_getcb_releasedata", 1, 0, 8}, - {"mng_getcb_settimer", 1, 0, 0}, - {"mng_getcb_traceproc", 1, 0, 0}, - {"mng_getcb_writedata", 1, 0, 0}, - {"mng_getchunk_back", 1, 0, 0}, - {"mng_getchunk_basi", 1, 0, 0}, -#ifndef MNG_SKIPCHUNK_bKGD - {"mng_getchunk_bkgd", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_cHRM - {"mng_getchunk_chrm", 1, 0, 0}, -#endif - {"mng_getchunk_clip", 1, 0, 0}, - {"mng_getchunk_clon", 1, 0, 0}, -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_dBYK - {"mng_getchunk_dbyk", 1, 0, 0}, -#endif -#endif - {"mng_getchunk_defi", 1, 0, 0}, -#ifndef MNG_NO_DELTA_PNG - {"mng_getchunk_dhdr", 1, 0, 0}, -#endif - {"mng_getchunk_disc", 1, 0, 0}, -#ifndef MNG_NO_DELTA_PNG - {"mng_getchunk_drop", 1, 0, 0}, -#endif - {"mng_getchunk_endl", 1, 0, 0}, -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - {"mng_getchunk_mpng", 1, 0, 10}, - {"mng_getchunk_mpng_frame", 1, 0, 10}, -#endif -#ifndef MNG_SKIPCHUNK_evNT - {"mng_getchunk_evnt", 1, 0, 5}, - {"mng_getchunk_evnt_entry", 1, 0, 5}, -#endif -#ifndef MNG_SKIPCHUNK_eXPI - {"mng_getchunk_expi", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_fPRI - {"mng_getchunk_fpri", 1, 0, 0}, -#endif - {"mng_getchunk_fram", 1, 0, 0}, - {"mng_getchunk_gama", 1, 0, 0}, -#ifndef MNG_SKIPCHUNK_hIST - {"mng_getchunk_hist", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_iCCP - {"mng_getchunk_iccp", 1, 0, 0}, -#endif - {"mng_getchunk_idat", 1, 0, 0}, - {"mng_getchunk_iend", 1, 0, 0}, - {"mng_getchunk_ihdr", 1, 0, 0}, -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG - {"mng_getchunk_ijng", 1, 0, 0}, -#endif - {"mng_getchunk_ipng", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_iTXt - {"mng_getchunk_itxt", 1, 0, 0}, -#endif -#ifdef MNG_INCLUDE_JNG - {"mng_getchunk_jdaa", 1, 0, 0}, - {"mng_getchunk_jdat", 1, 0, 0}, - {"mng_getchunk_jhdr", 1, 0, 0}, - {"mng_getchunk_jsep", 1, 0, 0}, -#endif - {"mng_getchunk_loop", 1, 0, 0}, -#ifndef MNG_SKIPCHUNK_MAGN - {"mng_getchunk_magn", 1, 0, 0}, -#endif - {"mng_getchunk_mend", 1, 0, 0}, - {"mng_getchunk_mhdr", 1, 0, 0}, - {"mng_getchunk_move", 1, 0, 0}, -#ifndef MNG_SKIPCHUNK_nEED - {"mng_getchunk_need", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_ORDR -#ifndef MNG_NO_DELTA_PNG - {"mng_getchunk_ordr", 1, 0, 0}, - {"mng_getchunk_ordr_entry", 1, 0, 0}, -#endif -#endif -#ifndef MNG_SKIPCHUNK_PAST - {"mng_getchunk_past", 1, 0, 0}, - {"mng_getchunk_past_src", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_pHYg - {"mng_getchunk_phyg", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_pHYs - {"mng_getchunk_phys", 1, 0, 0}, -#endif -#ifndef MNG_NO_DELTA_PNG - {"mng_getchunk_plte", 1, 0, 0}, - {"mng_getchunk_pplt", 1, 0, 0}, - {"mng_getchunk_pplt_entry", 1, 0, 0}, - {"mng_getchunk_prom", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_SAVE - {"mng_getchunk_save", 1, 0, 0}, - {"mng_getchunk_save_entry", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_sBIT - {"mng_getchunk_sbit", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_SEEK - {"mng_getchunk_seek", 1, 0, 0}, -#endif - {"mng_getchunk_show", 1, 0, 0}, -#ifndef MNG_SKIPCHUNK_sPLT - {"mng_getchunk_splt", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_sRGB - {"mng_getchunk_srgb", 1, 0, 0}, -#endif - {"mng_getchunk_term", 1, 0, 0}, -#ifndef MNG_SKIPCHUNK_tEXt - {"mng_getchunk_text", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_tIME - {"mng_getchunk_time", 1, 0, 0}, -#endif - {"mng_getchunk_trns", 1, 0, 0}, - {"mng_getchunk_unkown", 1, 0, 0}, -#ifndef MNG_SKIPCHUNK_zTXt - {"mng_getchunk_ztxt", 1, 0, 0}, -#endif - {"mng_getimgdata_chunk", 0, 0, 0}, - {"mng_getimgdata_chunkseq", 0, 0, 0}, - {"mng_getimgdata_seq", 0, 0, 0}, - {"mng_getlasterror", 1, 0, 0}, - {"mng_initialize", 1, 0, 0}, - {"mng_iterate_chunks", 1, 0, 0}, - {"mng_putchunk_back", 1, 0, 0}, -#ifndef MNG_SKIPCHUNK_BASI - {"mng_putchunk_basi", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_bKGD - {"mng_putchunk_bkgd", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_cHRM - {"mng_putchunk_chrm", 1, 0, 0}, -#endif - {"mng_putchunk_clip", 1, 0, 0}, - {"mng_putchunk_clon", 1, 0, 0}, -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DBYK - {"mng_putchunk_dbyk", 1, 0, 0}, -#endif -#endif - {"mng_putchunk_defi", 1, 0, 0}, -#ifndef MNG_NO_DELTA_PNG - {"mng_putchunk_dhdr", 1, 0, 0}, -#endif - {"mng_putchunk_disc", 1, 0, 0}, -#ifndef MNG_NO_DELTA_PNG - {"mng_putchunk_drop", 1, 0, 0}, -#endif - {"mng_putchunk_endl", 1, 0, 0}, -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - {"mng_putchunk_mpng", 1, 0, 10}, - {"mng_putchunk_mpng_frame", 1, 0, 10}, -#endif -#ifndef MNG_SKIPCHUNK_evNT - {"mng_putchunk_evnt", 1, 0, 5}, - {"mng_putchunk_evnt_entry", 1, 0, 5}, -#endif -#ifndef MNG_SKIPCHUNK_eXPI - {"mng_putchunk_expi", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_fPRI - {"mng_putchunk_fpri", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_FRAM - {"mng_putchunk_fram", 1, 0, 0}, -#endif - {"mng_putchunk_gama", 1, 0, 0}, -#ifndef MNG_SKIPCHUNK_hIST - {"mng_putchunk_hist", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_iCCP - {"mng_putchunk_iccp", 1, 0, 0}, -#endif - {"mng_putchunk_idat", 1, 0, 0}, - {"mng_putchunk_iend", 1, 0, 0}, - {"mng_putchunk_ihdr", 1, 0, 0}, -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG - {"mng_putchunk_ijng", 1, 0, 0}, -#endif - {"mng_putchunk_ipng", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_iTXt - {"mng_putchunk_itxt", 1, 0, 0}, -#endif -#ifdef MNG_INCLUDE_JNG - {"mng_putchunk_jdaa", 1, 0, 0}, - {"mng_putchunk_jdat", 1, 0, 0}, - {"mng_putchunk_jhdr", 1, 0, 0}, - {"mng_putchunk_jsep", 1, 0, 0}, -#endif - {"mng_putchunk_loop", 1, 0, 0}, -#ifndef MNG_SKIPCHUNK_MAGN - {"mng_putchunk_magn", 1, 0, 0}, -#endif - {"mng_putchunk_mend", 1, 0, 0}, - {"mng_putchunk_mhdr", 1, 0, 0}, - {"mng_putchunk_move", 1, 0, 0}, -#ifndef MNG_SKIPCHUNK_nEED - {"mng_putchunk_need", 1, 0, 0}, -#endif -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR - {"mng_putchunk_ordr", 1, 0, 0}, - {"mng_putchunk_ordr_entry", 1, 0, 0}, -#endif -#endif -#ifndef MNG_SKIPCHUNK_PAST - {"mng_putchunk_past", 1, 0, 0}, - {"mng_putchunk_past_src", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_pHYg - {"mng_putchunk_phyg", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_pHYs - {"mng_putchunk_phys", 1, 0, 0}, -#endif -#ifndef MNG_NO_DELTA_PNG - {"mng_putchunk_plte", 1, 0, 0}, - {"mng_putchunk_pplt", 1, 0, 0}, - {"mng_putchunk_pplt_entry", 1, 0, 0}, - {"mng_putchunk_prom", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_SAVE - {"mng_putchunk_save", 1, 0, 0}, - {"mng_putchunk_save_entry", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_sBIT - {"mng_putchunk_sbit", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_SEEK - {"mng_putchunk_seek", 1, 0, 0}, -#endif - {"mng_putchunk_show", 1, 0, 0}, -#ifndef MNG_SKIPCHUNK_sPLT - {"mng_putchunk_splt", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_sRGB - {"mng_putchunk_srgb", 1, 0, 0}, -#endif - {"mng_putchunk_term", 1, 0, 0}, -#ifndef MNG_SKIPCHUNK_tEXt - {"mng_putchunk_text", 1, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_tIME - {"mng_putchunk_time", 1, 0, 0}, -#endif - {"mng_putchunk_trns", 1, 0, 0}, - {"mng_putchunk_unkown", 1, 0, 0}, -#ifndef MNG_SKIPCHUNK_zTXt - {"mng_putchunk_ztxt", 1, 0, 0}, -#endif - {"mng_putimgdata_ihdr", 0, 0, 0}, - {"mng_putimgdata_jhdr", 0, 0, 0}, - {"mng_reset", 1, 0, 0}, - {"mng_read", 1, 0, 0}, - {"mng_read_pushchunk", 1, 0, 8}, - {"mng_read_pushdata", 1, 0, 8}, - {"mng_read_pushsig", 1, 0, 8}, - {"mng_read_resume", 1, 0, 0}, - {"mng_readdisplay", 1, 0, 0}, - {"mng_set_bgcolor", 1, 0, 0}, - {"mng_set_bkgdstyle", 1, 0, 0}, - {"mng_set_cacheplayback", 1, 0, 2}, - {"mng_set_canvasstyle", 1, 0, 0}, - {"mng_set_dfltimggamma", 1, 0, 0}, -#ifndef MNG_NO_DFLT_INFO - {"mng_set_dfltimggammaint", 1, 0, 0}, -#endif - {"mng_set_displaygamma", 1, 0, 0}, - {"mng_set_displaygammaint", 1, 0, 0}, - {"mng_set_doprogressive", 1, 0, 2}, -#ifdef MNG_ACCESS_JPEG - {"mng_set_jpeg_dctmethod", 1, 0, 0}, - {"mng_set_jpeg_maxjdat", 1, 0, 0}, - {"mng_set_jpeg_optimized", 1, 0, 0}, - {"mng_set_jpeg_progressive", 1, 0, 0}, - {"mng_set_jpeg_quality", 1, 0, 0}, - {"mng_set_jpeg_smoothing", 1, 0, 0}, -#endif -#ifndef MNG_SKIP_MAXCANVAS - {"mng_set_maxcanvasheight", 1, 0, 0}, - {"mng_set_maxcanvassize", 1, 0, 0}, - {"mng_set_maxcanvaswidth", 1, 0, 0}, -#endif - {"mng_set_outputprofile", 1, 0, 0}, - {"mng_set_outputprofile2", 1, 0, 0}, - {"mng_set_outputsrgb", 1, 0, 1}, - {"mng_set_sectionbreaks", 1, 0, 0}, - {"mng_set_speed", 1, 0, 0}, - {"mng_set_srgb", 1, 0, 0}, - {"mng_set_srgbimplicit", 1, 0, 1}, - {"mng_set_srgbprofile", 1, 0, 0}, - {"mng_set_srgbprofile2", 1, 0, 0}, - {"mng_set_storechunks", 1, 0, 0}, - {"mng_set_suspensionmode", 1, 0, 0}, - {"mng_set_usebkgd", 1, 0, 0}, - {"mng_set_userdata", 1, 0, 0}, -#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) - {"mng_set_viewgamma", 1, 0, 0}, - {"mng_set_viewgammaint", 1, 0, 0}, -#endif -#ifdef MNG_ACCESS_ZLIB - {"mng_set_zlib_level", 1, 0, 0}, - {"mng_set_zlib_maxidat", 1, 0, 0}, - {"mng_set_zlib_memlevel", 1, 0, 0}, - {"mng_set_zlib_method", 1, 0, 0}, - {"mng_set_zlib_strategy", 1, 0, 0}, - {"mng_set_zlib_windowbits", 1, 0, 0}, -#endif -#ifndef MNG_NO_OPEN_CLOSE_STREAM - {"mng_setcb_closestream", 1, 0, 0}, -#endif - {"mng_setcb_errorproc", 1, 0, 0}, - {"mng_setcb_getalphaline", 1, 0, 0}, - {"mng_setcb_getbkgdline", 1, 0, 0}, - {"mng_setcb_getcanvasline", 1, 0, 0}, - {"mng_setcb_gettickcount", 1, 0, 0}, - {"mng_setcb_memalloc", 1, 0, 0}, - {"mng_setcb_memfree", 1, 0, 0}, -#ifndef MNG_NO_OPEN_CLOSE_STREAM - {"mng_setcb_openstream", 1, 0, 0}, -#endif - {"mng_setcb_processarow", 1, 0, 0}, - {"mng_setcb_processchroma", 1, 0, 0}, - {"mng_setcb_processgamma", 1, 0, 0}, - {"mng_setcb_processheader", 1, 0, 0}, - {"mng_setcb_processiccp", 1, 0, 0}, - {"mng_setcb_processmend", 1, 0, 1}, - {"mng_setcb_processneed", 1, 0, 0}, - {"mng_setcb_processsave", 1, 0, 0}, - {"mng_setcb_processseek", 1, 0, 0}, - {"mng_setcb_processsrgb", 1, 0, 0}, - {"mng_setcb_processterm", 1, 0, 2}, - {"mng_setcb_processtext", 1, 0, 0}, - {"mng_setcb_processunknown", 1, 0, 0}, - {"mng_setcb_readdata", 1, 0, 0}, - {"mng_setcb_refresh", 1, 0, 0}, - {"mng_setcb_releasedata", 1, 0, 8}, - {"mng_setcb_settimer", 1, 0, 0}, - {"mng_setcb_traceproc", 1, 0, 0}, - {"mng_setcb_writedata", 1, 0, 0}, - {"mng_status_creating", 1, 0, 0}, - {"mng_status_displaying", 1, 0, 0}, - {"mng_status_dynamic", 1, 0, 5}, - {"mng_status_error", 1, 0, 0}, - {"mng_status_reading", 1, 0, 0}, - {"mng_status_running", 1, 0, 0}, - {"mng_status_runningevent", 1, 0, 5}, - {"mng_status_suspendbreak", 1, 0, 0}, - {"mng_status_timerbreak", 1, 0, 0}, - {"mng_status_writing", 1, 0, 0}, - {"mng_supports_func", 1, 0, 5}, - {"mng_trapevent", 1, 0, 5}, - {"mng_updatemngheader", 1, 0, 0}, - {"mng_updatemngsimplicity", 1, 0, 0}, - {"mng_version_beta", 1, 0, 5}, - {"mng_version_dll", 1, 0, 0}, - {"mng_version_major", 1, 0, 0}, - {"mng_version_minor", 1, 0, 0}, - {"mng_version_release", 1, 0, 0}, - {"mng_version_so", 1, 0, 0}, - {"mng_version_text", 1, 0, 0}, - {"mng_write", 1, 0, 0}, - }; - -mng_bool MNG_DECL mng_supports_func (mng_pchar zFunction, - mng_uint8* iMajor, - mng_uint8* iMinor, - mng_uint8* iRelease) -{ - mng_int32 iTop, iLower, iUpper, iMiddle; - mng_func_entryp pEntry; /* pointer to found entry */ - /* determine max index of table */ - iTop = (sizeof (func_table) / sizeof (func_table [0])) - 1; - - iLower = 0; /* initialize binary search */ - iMiddle = iTop >> 1; /* start in the middle */ - iUpper = iTop; - pEntry = 0; /* no goods yet! */ - - do /* the binary search itself */ - { - mng_int32 iRslt = strcmp(func_table [iMiddle].zFunction, zFunction); - if (iRslt < 0) - iLower = iMiddle + 1; - else if (iRslt > 0) - iUpper = iMiddle - 1; - else - { - pEntry = &func_table [iMiddle]; - break; - }; - - iMiddle = (iLower + iUpper) >> 1; - } - while (iLower <= iUpper); - - if (pEntry) /* found it ? */ - { - *iMajor = pEntry->iMajor; - *iMinor = pEntry->iMinor; - *iRelease = pEntry->iRelease; - return MNG_TRUE; - } - else - { - *iMajor = 0; - *iMinor = 0; - *iRelease = 0; - return MNG_FALSE; - } -} -#endif - -/* ************************************************************************** */ -/* * * */ -/* * HLAPI routines * */ -/* * * */ -/* ************************************************************************** */ - -mng_handle MNG_DECL mng_initialize (mng_ptr pUserdata, - mng_memalloc fMemalloc, - mng_memfree fMemfree, - mng_traceproc fTraceproc) -{ - mng_datap pData; -#ifdef MNG_SUPPORT_DISPLAY - mng_retcode iRetcode; - mng_imagep pImage; -#endif - -#ifdef MNG_INTERNAL_MEMMNGMT /* allocate the main datastruc */ - pData = (mng_datap)calloc (1, sizeof (mng_data)); -#else - pData = (mng_datap)fMemalloc (sizeof (mng_data)); -#endif - - if (!pData) - return MNG_NULL; /* error: out of memory?? */ - /* validate the structure */ - pData->iMagic = MNG_MAGIC; - /* save userdata field */ - pData->pUserdata = pUserdata; - /* remember trace callback */ - pData->fTraceproc = fTraceproc; - -#ifdef MNG_SUPPORT_TRACE - if (mng_trace (pData, MNG_FN_INITIALIZE, MNG_LC_INITIALIZE)) - { - MNG_FREEX (pData, pData, sizeof (mng_data)); - return MNG_NULL; - } -#endif - /* default canvas styles are 8-bit RGB */ - pData->iCanvasstyle = MNG_CANVAS_RGB8; - pData->iBkgdstyle = MNG_CANVAS_RGB8; - - pData->iBGred = 0; /* black */ - pData->iBGgreen = 0; - pData->iBGblue = 0; - - pData->bUseBKGD = MNG_TRUE; - -#ifdef MNG_FULL_CMS - pData->bIssRGB = MNG_TRUE; - pData->hProf1 = 0; /* no profiles yet */ - pData->hProf2 = 0; - pData->hProf3 = 0; - pData->hTrans = 0; -#endif - - pData->dViewgamma = 1.0; - pData->dDisplaygamma = 2.2; - pData->dDfltimggamma = 0.45455; - /* initially remember chunks */ - pData->bStorechunks = MNG_TRUE; - /* no breaks at section-borders */ - pData->bSectionbreaks = MNG_FALSE; - /* initially cache playback info */ - pData->bCacheplayback = MNG_TRUE; - /* progressive refresh for large images */ - pData->bDoProgressive = MNG_TRUE; - /* crc exists; should check; error for - critical chunks; warning for ancillery; - generate crc for output */ - pData->iCrcmode = MNG_CRC_DEFAULT; - /* normal animation-speed ! */ - pData->iSpeed = mng_st_normal; - /* initial image limits */ - pData->iMaxwidth = 10000; - pData->iMaxheight = 10000; - -#ifdef MNG_INTERNAL_MEMMNGMT /* internal management */ - pData->fMemalloc = MNG_NULL; - pData->fMemfree = MNG_NULL; -#else /* keep callbacks */ - pData->fMemalloc = fMemalloc; - pData->fMemfree = fMemfree; -#endif - /* no value (yet) */ - pData->fReleasedata = MNG_NULL; -#ifndef MNG_NO_OPEN_CLOSE_STREAM - pData->fOpenstream = MNG_NULL; - pData->fClosestream = MNG_NULL; -#endif - pData->fReaddata = MNG_NULL; - pData->fWritedata = MNG_NULL; - pData->fErrorproc = MNG_NULL; - pData->fProcessheader = MNG_NULL; - pData->fProcesstext = MNG_NULL; - pData->fProcesssave = MNG_NULL; - pData->fProcessseek = MNG_NULL; - pData->fProcessneed = MNG_NULL; - pData->fProcessmend = MNG_NULL; - pData->fProcessunknown = MNG_NULL; - pData->fProcessterm = MNG_NULL; - pData->fGetcanvasline = MNG_NULL; - pData->fGetbkgdline = MNG_NULL; - pData->fGetalphaline = MNG_NULL; - pData->fRefresh = MNG_NULL; - pData->fGettickcount = MNG_NULL; - pData->fSettimer = MNG_NULL; - pData->fProcessgamma = MNG_NULL; - pData->fProcesschroma = MNG_NULL; - pData->fProcesssrgb = MNG_NULL; - pData->fProcessiccp = MNG_NULL; - pData->fProcessarow = MNG_NULL; - -#if defined(MNG_SUPPORT_DISPLAY) && (defined(MNG_GAMMA_ONLY) || defined(MNG_FULL_CMS)) - pData->dLastgamma = 0; /* lookup table needs first-time calc */ -#endif - -#ifdef MNG_SUPPORT_DISPLAY /* create object 0 */ - iRetcode = mng_create_imageobject (pData, 0, MNG_TRUE, MNG_TRUE, MNG_TRUE, - 0, 0, 0, 0, 0, 0, 0, 0, 0, MNG_FALSE, - 0, 0, 0, 0, &pImage); - - if (iRetcode) /* on error drop out */ - { - MNG_FREEX (pData, pData, sizeof (mng_data)); - return MNG_NULL; - } - - pData->pObjzero = pImage; -#endif - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_INCLUDE_LCMS) - mnglcms_initlibrary (); /* init lcms particulars */ -#endif - -#ifdef MNG_SUPPORT_READ - pData->bSuspensionmode = MNG_FALSE; - pData->iSuspendbufsize = 0; - pData->pSuspendbuf = MNG_NULL; - pData->pSuspendbufnext = MNG_NULL; - pData->iSuspendbufleft = 0; - pData->iChunklen = 0; - pData->pReadbufnext = MNG_NULL; - pData->pLargebufnext = MNG_NULL; - - pData->pFirstpushchunk = MNG_NULL; - pData->pLastpushchunk = MNG_NULL; - pData->pFirstpushdata = MNG_NULL; - pData->pLastpushdata = MNG_NULL; -#endif - -#ifdef MNG_INCLUDE_ZLIB - mngzlib_initialize (pData); /* initialize zlib structures and such */ - /* default zlib compression parameters */ - pData->iZlevel = MNG_ZLIB_LEVEL; - pData->iZmethod = MNG_ZLIB_METHOD; - pData->iZwindowbits = MNG_ZLIB_WINDOWBITS; - pData->iZmemlevel = MNG_ZLIB_MEMLEVEL; - pData->iZstrategy = MNG_ZLIB_STRATEGY; - /* default maximum IDAT data size */ - pData->iMaxIDAT = MNG_MAX_IDAT_SIZE; -#endif - -#ifdef MNG_INCLUDE_JNG /* default IJG compression parameters */ - pData->eJPEGdctmethod = MNG_JPEG_DCT; - pData->iJPEGquality = MNG_JPEG_QUALITY; - pData->iJPEGsmoothing = MNG_JPEG_SMOOTHING; - pData->bJPEGcompressprogr = MNG_JPEG_PROGRESSIVE; - pData->bJPEGcompressopt = MNG_JPEG_OPTIMIZED; - /* default maximum JDAT data size */ - pData->iMaxJDAT = MNG_MAX_JDAT_SIZE; -#endif - - mng_reset ((mng_handle)pData); - -#ifdef MNG_SUPPORT_TRACE - if (mng_trace (pData, MNG_FN_INITIALIZE, MNG_LC_END)) - { - MNG_FREEX (pData, pData, sizeof (mng_data)); - return MNG_NULL; - } -#endif - - return (mng_handle)pData; /* if we get here, we're in business */ -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_reset (mng_handle hHandle) -{ - mng_datap pData; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_RESET, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = ((mng_datap)(hHandle)); /* address main structure */ - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_SKIPCHUNK_SAVE - mng_drop_savedata (pData); /* cleanup saved-data from SAVE/SEEK */ -#endif -#endif - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_FULL_CMS) - mng_clear_cms (pData); /* cleanup left-over cms stuff if any */ -#endif - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_INCLUDE_JNG) - mngjpeg_cleanup (pData); /* cleanup jpeg stuff */ -#endif - -#ifdef MNG_INCLUDE_ZLIB - if (pData->bInflating) /* if we've been inflating */ - { -#ifdef MNG_INCLUDE_DISPLAY_PROCS - mng_cleanup_rowproc (pData); /* cleanup row-processing, */ -#endif - mngzlib_inflatefree (pData); /* cleanup inflate! */ - } -#endif /* MNG_INCLUDE_ZLIB */ - -#ifdef MNG_SUPPORT_READ - if ((pData->bReading) && (!pData->bEOF)) - mng_process_eof (pData); /* cleanup app streaming */ - /* cleanup default read buffers */ - MNG_FREE (pData, pData->pReadbuf, pData->iReadbufsize); - MNG_FREE (pData, pData->pLargebuf, pData->iLargebufsize); - MNG_FREE (pData, pData->pSuspendbuf, pData->iSuspendbufsize); - - while (pData->pFirstpushdata) /* release any pushed data & chunks */ - mng_release_pushdata (pData); - while (pData->pFirstpushchunk) - mng_release_pushchunk (pData); -#endif - -#ifdef MNG_SUPPORT_WRITE /* cleanup default write buffer */ - MNG_FREE (pData, pData->pWritebuf, pData->iWritebufsize); -#endif - -#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) - mng_drop_chunks (pData); /* drop stored chunks (if any) */ -#endif - -#ifdef MNG_SUPPORT_DISPLAY - mng_drop_objects (pData, MNG_TRUE); /* drop stored objects (if any) */ - -#ifndef MNG_SKIPCHUNK_iCCP - if (pData->iGlobalProfilesize) /* drop global profile (if any) */ - MNG_FREEX (pData, pData->pGlobalProfile, pData->iGlobalProfilesize); -#endif -#endif - - pData->eSigtype = mng_it_unknown; - pData->eImagetype = mng_it_unknown; - pData->iWidth = 0; /* these are unknown yet */ - pData->iHeight = 0; - pData->iTicks = 0; - pData->iLayercount = 0; - pData->iFramecount = 0; - pData->iPlaytime = 0; - pData->iSimplicity = 0; - pData->iAlphadepth = 16; /* assume the worst! */ - - pData->iImagelevel = 0; /* no image encountered */ - - pData->iMagnify = 0; /* 1-to-1 display */ - pData->iOffsetx = 0; /* no offsets */ - pData->iOffsety = 0; - pData->iCanvaswidth = 0; /* let the app decide during processheader */ - pData->iCanvasheight = 0; - /* so far, so good */ - pData->iErrorcode = MNG_NOERROR; - pData->iSeverity = 0; - pData->iErrorx1 = 0; - pData->iErrorx2 = 0; - pData->zErrortext = MNG_NULL; - -#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) - /* let's assume the best scenario */ -#ifndef MNG_NO_OLD_VERSIONS - pData->bPreDraft48 = MNG_FALSE; -#endif - /* the unknown chunk */ - pData->iChunkname = MNG_UINT_HUH; - pData->iChunkseq = 0; - pData->pFirstchunk = MNG_NULL; - pData->pLastchunk = MNG_NULL; - /* nothing processed yet */ - pData->bHasheader = MNG_FALSE; - pData->bHasMHDR = MNG_FALSE; - pData->bHasIHDR = MNG_FALSE; - pData->bHasBASI = MNG_FALSE; - pData->bHasDHDR = MNG_FALSE; -#ifdef MNG_INCLUDE_JNG - pData->bHasJHDR = MNG_FALSE; - pData->bHasJSEP = MNG_FALSE; - pData->bHasJDAA = MNG_FALSE; - pData->bHasJDAT = MNG_FALSE; -#endif - pData->bHasPLTE = MNG_FALSE; - pData->bHasTRNS = MNG_FALSE; - pData->bHasGAMA = MNG_FALSE; - pData->bHasCHRM = MNG_FALSE; - pData->bHasSRGB = MNG_FALSE; - pData->bHasICCP = MNG_FALSE; - pData->bHasBKGD = MNG_FALSE; - pData->bHasIDAT = MNG_FALSE; - - pData->bHasSAVE = MNG_FALSE; - pData->bHasBACK = MNG_FALSE; - pData->bHasFRAM = MNG_FALSE; - pData->bHasTERM = MNG_FALSE; - pData->bHasLOOP = MNG_FALSE; - /* there's no global stuff yet either */ - pData->bHasglobalPLTE = MNG_FALSE; - pData->bHasglobalTRNS = MNG_FALSE; - pData->bHasglobalGAMA = MNG_FALSE; - pData->bHasglobalCHRM = MNG_FALSE; - pData->bHasglobalSRGB = MNG_FALSE; - pData->bHasglobalICCP = MNG_FALSE; - - pData->iDatawidth = 0; /* no IHDR/BASI/DHDR done yet */ - pData->iDataheight = 0; - pData->iBitdepth = 0; - pData->iColortype = 0; - pData->iCompression = 0; - pData->iFilter = 0; - pData->iInterlace = 0; - -#ifdef MNG_INCLUDE_JNG - pData->iJHDRcolortype = 0; /* no JHDR data */ - pData->iJHDRimgbitdepth = 0; - pData->iJHDRimgcompression = 0; - pData->iJHDRimginterlace = 0; - pData->iJHDRalphabitdepth = 0; - pData->iJHDRalphacompression = 0; - pData->iJHDRalphafilter = 0; - pData->iJHDRalphainterlace = 0; -#endif - -#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ - -#ifdef MNG_SUPPORT_READ /* no reading done */ - pData->bReading = MNG_FALSE; - pData->bHavesig = MNG_FALSE; - pData->bEOF = MNG_FALSE; - pData->iReadbufsize = 0; - pData->pReadbuf = MNG_NULL; - - pData->iLargebufsize = 0; - pData->pLargebuf = MNG_NULL; - - pData->iSuspendtime = 0; - pData->bSuspended = MNG_FALSE; - pData->iSuspendpoint = 0; - - pData->pSuspendbufnext = pData->pSuspendbuf; - pData->iSuspendbufleft = 0; -#endif /* MNG_SUPPORT_READ */ - -#ifdef MNG_SUPPORT_WRITE /* no creating/writing done */ - pData->bCreating = MNG_FALSE; - pData->bWriting = MNG_FALSE; - pData->iFirstchunkadded = 0; - pData->iWritebufsize = 0; - pData->pWritebuf = MNG_NULL; -#endif /* MNG_SUPPORT_WRITE */ - -#ifdef MNG_SUPPORT_DISPLAY /* done nuttin' yet */ - pData->bDisplaying = MNG_FALSE; - pData->iFrameseq = 0; - pData->iLayerseq = 0; - pData->iFrametime = 0; - - pData->iTotallayers = 0; - pData->iTotalframes = 0; - pData->iTotalplaytime = 0; - - pData->bSkipping = MNG_FALSE; - -#ifdef MNG_SUPPORT_DYNAMICMNG - pData->bDynamic = MNG_FALSE; - pData->bRunningevent = MNG_FALSE; - pData->bStopafterseek = MNG_FALSE; - pData->iEventx = 0; - pData->iEventy = 0; - pData->pLastmousemove = MNG_NULL; -#endif - - pData->iRequestframe = 0; - pData->iRequestlayer = 0; - pData->iRequesttime = 0; - pData->bSearching = MNG_FALSE; - - pData->bRestorebkgd = MNG_FALSE; - - pData->iRuntime = 0; - pData->iSynctime = 0; - pData->iStarttime = 0; - pData->iEndtime = 0; - pData->bRunning = MNG_FALSE; - pData->bTimerset = MNG_FALSE; - pData->iBreakpoint = 0; - pData->bSectionwait = MNG_FALSE; - pData->bFreezing = MNG_FALSE; - pData->bResetting = MNG_FALSE; - pData->bNeedrefresh = MNG_FALSE; - pData->bMisplacedTERM = MNG_FALSE; - pData->bOnlyfirstframe = MNG_FALSE; - pData->iFramesafterTERM = 0; - /* these don't exist yet */ - pData->pCurrentobj = MNG_NULL; - pData->pCurraniobj = MNG_NULL; - pData->pTermaniobj = MNG_NULL; - pData->pLastclone = MNG_NULL; - pData->pStoreobj = MNG_NULL; - pData->pStorebuf = MNG_NULL; - pData->pRetrieveobj = MNG_NULL; - /* no saved data ! */ - pData->pSavedata = MNG_NULL; - - pData->iUpdateleft = 0; /* no region updated yet */ - pData->iUpdateright = 0; - pData->iUpdatetop = 0; - pData->iUpdatebottom = 0; - - pData->iPass = -1; /* interlacing stuff and temp buffers */ - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = 0; - pData->iSamplemul = 0; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = 0; - pData->iRowmax = 0; - pData->iFilterofs = 0; - pData->iPixelofs = 1; - pData->iLevel0 = 0; - pData->iLevel1 = 0; - pData->iLevel2 = 0; - pData->iLevel3 = 0; - pData->pWorkrow = MNG_NULL; - pData->pPrevrow = MNG_NULL; - pData->pRGBArow = MNG_NULL; - pData->bIsRGBA16 = MNG_TRUE; - pData->bIsOpaque = MNG_TRUE; - pData->iFilterbpp = 1; - - pData->iSourcel = 0; /* always initialized just before */ - pData->iSourcer = 0; /* compositing the next layer */ - pData->iSourcet = 0; - pData->iSourceb = 0; - pData->iDestl = 0; - pData->iDestr = 0; - pData->iDestt = 0; - pData->iDestb = 0; - /* lists are empty */ - pData->pFirstimgobj = MNG_NULL; - pData->pLastimgobj = MNG_NULL; - pData->pFirstaniobj = MNG_NULL; - pData->pLastaniobj = MNG_NULL; -#ifdef MNG_SUPPORT_DYNAMICMNG - pData->pFirstevent = MNG_NULL; - pData->pLastevent = MNG_NULL; -#endif - /* no processing callbacks */ - pData->fDisplayrow = MNG_NULL; - pData->fRestbkgdrow = MNG_NULL; - pData->fCorrectrow = MNG_NULL; - pData->fRetrieverow = MNG_NULL; - pData->fStorerow = MNG_NULL; - pData->fProcessrow = MNG_NULL; - pData->fDifferrow = MNG_NULL; - pData->fScalerow = MNG_NULL; - pData->fDeltarow = MNG_NULL; -#ifndef MNG_SKIPCHUNK_PAST - pData->fFliprow = MNG_NULL; - pData->fTilerow = MNG_NULL; -#endif - pData->fInitrowproc = MNG_NULL; - - pData->iPLTEcount = 0; /* no PLTE data */ - -#ifndef MNG_SKIPCHUNK_DEFI - pData->iDEFIobjectid = 0; /* no DEFI data */ - pData->bDEFIhasdonotshow = MNG_FALSE; - pData->iDEFIdonotshow = 0; - pData->bDEFIhasconcrete = MNG_FALSE; - pData->iDEFIconcrete = 0; - pData->bDEFIhasloca = MNG_FALSE; - pData->iDEFIlocax = 0; - pData->iDEFIlocay = 0; - pData->bDEFIhasclip = MNG_FALSE; - pData->iDEFIclipl = 0; - pData->iDEFIclipr = 0; - pData->iDEFIclipt = 0; - pData->iDEFIclipb = 0; -#endif - -#ifndef MNG_SKIPCHUNK_BACK - pData->iBACKred = 0; /* no BACK data */ - pData->iBACKgreen = 0; - pData->iBACKblue = 0; - pData->iBACKmandatory = 0; - pData->iBACKimageid = 0; - pData->iBACKtile = 0; -#endif - -#ifndef MNG_SKIPCHUNK_FRAM - pData->iFRAMmode = 1; /* default global FRAM variables */ - pData->iFRAMdelay = 1; - pData->iFRAMtimeout = 0x7fffffffl; - pData->bFRAMclipping = MNG_FALSE; - pData->iFRAMclipl = 0; - pData->iFRAMclipr = 0; - pData->iFRAMclipt = 0; - pData->iFRAMclipb = 0; - - pData->iFramemode = 1; /* again for the current frame */ - pData->iFramedelay = 1; - pData->iFrametimeout = 0x7fffffffl; - pData->bFrameclipping = MNG_FALSE; - pData->iFrameclipl = 0; - pData->iFrameclipr = 0; - pData->iFrameclipt = 0; - pData->iFrameclipb = 0; - - pData->iNextdelay = 1; -#endif - -#ifndef MNG_SKIPCHUNK_SHOW - pData->iSHOWmode = 0; /* no SHOW data */ - pData->iSHOWfromid = 0; - pData->iSHOWtoid = 0; - pData->iSHOWnextid = 0; - pData->iSHOWskip = 0; -#endif - - pData->iGlobalPLTEcount = 0; /* no global PLTE data */ - - pData->iGlobalTRNSrawlen = 0; /* no global tRNS data */ - - pData->iGlobalGamma = 0; /* no global gAMA data */ - -#ifndef MNG_SKIPCHUNK_cHRM - pData->iGlobalWhitepointx = 0; /* no global cHRM data */ - pData->iGlobalWhitepointy = 0; - pData->iGlobalPrimaryredx = 0; - pData->iGlobalPrimaryredy = 0; - pData->iGlobalPrimarygreenx = 0; - pData->iGlobalPrimarygreeny = 0; - pData->iGlobalPrimarybluex = 0; - pData->iGlobalPrimarybluey = 0; -#endif - - pData->iGlobalRendintent = 0; /* no global sRGB data */ - -#ifndef MNG_SKIPCHUNK_iCCP - pData->iGlobalProfilesize = 0; /* no global iCCP data */ - pData->pGlobalProfile = MNG_NULL; -#endif - -#ifndef MNG_SKIPCHUNK_bKGD - pData->iGlobalBKGDred = 0; /* no global bKGD data */ - pData->iGlobalBKGDgreen = 0; - pData->iGlobalBKGDblue = 0; -#endif - /* no delta-image */ -#ifndef MNG_NO_DELTA_PNG - pData->pDeltaImage = MNG_NULL; - pData->iDeltaImagetype = 0; - pData->iDeltatype = 0; - pData->iDeltaBlockwidth = 0; - pData->iDeltaBlockheight = 0; - pData->iDeltaBlockx = 0; - pData->iDeltaBlocky = 0; - pData->bDeltaimmediate = MNG_FALSE; - - pData->fDeltagetrow = MNG_NULL; - pData->fDeltaaddrow = MNG_NULL; - pData->fDeltareplacerow = MNG_NULL; - pData->fDeltaputrow = MNG_NULL; - - pData->fPromoterow = MNG_NULL; - pData->fPromBitdepth = MNG_NULL; - pData->pPromBuf = MNG_NULL; - pData->iPromColortype = 0; - pData->iPromBitdepth = 0; - pData->iPromFilltype = 0; - pData->iPromWidth = 0; - pData->pPromSrc = MNG_NULL; - pData->pPromDst = MNG_NULL; -#endif - -#ifndef MNG_SKIPCHUNK_MAGN - pData->iMAGNfromid = 0; - pData->iMAGNtoid = 0; -#endif - -#ifndef MNG_SKIPCHUNK_PAST - pData->iPastx = 0; - pData->iPasty = 0; -#endif - - pData->pLastseek = MNG_NULL; -#endif - -#ifdef MNG_INCLUDE_ZLIB - pData->bInflating = 0; /* no inflating or deflating */ - pData->bDeflating = 0; /* going on at the moment */ -#endif - -#ifdef MNG_SUPPORT_DISPLAY /* reset object 0 */ - mng_reset_objzero (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_RESET, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_cleanup (mng_handle* hHandle) -{ - mng_datap pData; /* local vars */ -#ifndef MNG_INTERNAL_MEMMNGMT - mng_memfree fFree; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)*hHandle), MNG_FN_CLEANUP, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (*hHandle) /* check validity handle */ - pData = ((mng_datap)(*hHandle)); /* and address main structure */ - - mng_reset (*hHandle); /* do an implicit reset to cleanup most stuff */ - -#ifdef MNG_SUPPORT_DISPLAY /* drop object 0 */ - mng_free_imageobject (pData, (mng_imagep)pData->pObjzero); -#endif - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_FULL_CMS) - if (pData->hProf2) /* output profile defined ? */ - mnglcms_freeprofile (pData->hProf2); - - if (pData->hProf3) /* sRGB profile defined ? */ - mnglcms_freeprofile (pData->hProf3); -#endif - -#ifdef MNG_INCLUDE_ZLIB - mngzlib_cleanup (pData); /* cleanup zlib stuff */ -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)*hHandle), MNG_FN_CLEANUP, MNG_LC_CLEANUP) -#endif - - pData->iMagic = 0; /* invalidate the actual memory */ - -#ifdef MNG_INTERNAL_MEMMNGMT - free ((void *)*hHandle); /* cleanup the data-structure */ -#else - fFree = ((mng_datap)*hHandle)->fMemfree; - fFree ((mng_ptr)*hHandle, sizeof (mng_data)); -#endif - - *hHandle = 0; /* wipe pointer to inhibit future use */ - - return MNG_NOERROR; /* and we're done */ -} - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_retcode MNG_DECL mng_read (mng_handle hHandle) -{ - mng_datap pData; /* local vars */ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - -#ifndef MNG_INTERNAL_MEMMNGMT - MNG_VALIDCB (hHandle, fMemalloc) - MNG_VALIDCB (hHandle, fMemfree) -#endif - -#ifndef MNG_NO_OPEN_CLOSE_STREAM - MNG_VALIDCB (hHandle, fOpenstream) - MNG_VALIDCB (hHandle, fClosestream) -#endif - MNG_VALIDCB (hHandle, fReaddata) - -#ifdef MNG_SUPPORT_DISPLAY /* valid at this point ? */ - if ((pData->bReading) || (pData->bDisplaying)) -#else - if (pData->bReading) -#endif - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - -#ifdef MNG_SUPPORT_WRITE - if ((pData->bWriting) || (pData->bCreating)) - MNG_ERROR (pData, MNG_FUNCTIONINVALID); -#endif - - if (!pData->bCacheplayback) /* must store playback info to work!! */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - cleanup_errors (pData); /* cleanup previous errors */ - - pData->bReading = MNG_TRUE; /* read only! */ - -#ifndef MNG_NO_OPEN_CLOSE_STREAM - if (pData->fOpenstream && !pData->fOpenstream (hHandle)) - /* open it and start reading */ - iRetcode = MNG_APPIOERROR; - else -#endif - iRetcode = mng_read_graphic (pData); - - if (pData->bEOF) /* already at EOF ? */ - { - pData->bReading = MNG_FALSE; /* then we're no longer reading */ - -#ifdef MNG_SUPPORT_DISPLAY - mng_reset_rundata (pData); /* reset rundata */ -#endif - } - - if (iRetcode) /* on error bail out */ - return iRetcode; - - if (pData->bSuspended) /* read suspension ? */ - { - iRetcode = MNG_NEEDMOREDATA; - pData->iSuspendtime = pData->fGettickcount ((mng_handle)pData); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ, MNG_LC_END); -#endif - - return iRetcode; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_retcode MNG_DECL mng_read_pushdata (mng_handle hHandle, - mng_ptr pData, - mng_size_t iLength, - mng_bool bTakeownership) -{ - mng_datap pMyData; /* local vars */ - mng_pushdatap pPush; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHDATA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pMyData = ((mng_datap)hHandle); /* and make it addressable */ - /* create a containing buffer */ - iRetcode = make_pushbuffer (pMyData, pData, iLength, bTakeownership, &pPush); - if (iRetcode) - return iRetcode; - - if (pMyData->pLastpushdata) /* and update the buffer chain */ - pMyData->pLastpushdata->pNext = pPush; - else - pMyData->pFirstpushdata = pPush; - - pMyData->pLastpushdata = pPush; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHDATA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_retcode MNG_DECL mng_read_pushsig (mng_handle hHandle, - mng_imgtype eSigtype) -{ - mng_datap pData; /* local vars */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHSIG, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - - if (pData->bHavesig) /* can we expect this call ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - pData->eSigtype = eSigtype; - pData->bHavesig = MNG_TRUE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHSIG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_retcode MNG_DECL mng_read_pushchunk (mng_handle hHandle, - mng_ptr pChunk, - mng_size_t iLength, - mng_bool bTakeownership) -{ - mng_datap pMyData; /* local vars */ - mng_pushdatap pPush; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHCHUNK, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pMyData = ((mng_datap)hHandle); /* and make it addressable */ - /* create a containing buffer */ - iRetcode = make_pushbuffer (pMyData, pChunk, iLength, bTakeownership, &pPush); - if (iRetcode) - return iRetcode; - - if (pMyData->pLastpushchunk) /* and update the buffer chain */ - pMyData->pLastpushchunk->pNext = pPush; - else - pMyData->pFirstpushchunk = pPush; - - pMyData->pLastpushchunk = pPush; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHCHUNK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_retcode MNG_DECL mng_read_resume (mng_handle hHandle) -{ - mng_datap pData; /* local vars */ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_RESUME, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - /* can we expect this call ? */ - if ((!pData->bReading) || (!pData->bSuspended)) - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - cleanup_errors (pData); /* cleanup previous errors */ - - pData->bSuspended = MNG_FALSE; /* reset the flag */ - -#ifdef MNG_SUPPORT_DISPLAY /* re-synchronize ? */ - if ((pData->bDisplaying) && (pData->bRunning)) - pData->iSynctime = pData->iSynctime - pData->iSuspendtime + - pData->fGettickcount (hHandle); -#endif - - iRetcode = mng_read_graphic (pData); /* continue reading now */ - - if (pData->bEOF) /* at EOF ? */ - { - pData->bReading = MNG_FALSE; /* then we're no longer reading */ - -#ifdef MNG_SUPPORT_DISPLAY - mng_reset_rundata (pData); /* reset rundata */ -#endif - } - - if (iRetcode) /* on error bail out */ - return iRetcode; - - if (pData->bSuspended) /* read suspension ? */ - { - iRetcode = MNG_NEEDMOREDATA; - pData->iSuspendtime = pData->fGettickcount ((mng_handle)pData); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_RESUME, MNG_LC_END); -#endif - - return iRetcode; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_write (mng_handle hHandle) -{ - mng_datap pData; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_WRITE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - -#ifndef MNG_INTERNAL_MEMMNGMT - MNG_VALIDCB (hHandle, fMemalloc) - MNG_VALIDCB (hHandle, fMemfree) -#endif - -#ifndef MNG_NO_OPEN_CLOSE_STREAM - MNG_VALIDCB (hHandle, fOpenstream) - MNG_VALIDCB (hHandle, fClosestream) -#endif - MNG_VALIDCB (hHandle, fWritedata) - -#ifdef MNG_SUPPORT_READ - if (pData->bReading) /* valid at this point ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID); -#endif - - cleanup_errors (pData); /* cleanup previous errors */ - - iRetcode = mng_write_graphic (pData);/* do the write */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_WRITE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_create (mng_handle hHandle) -{ - mng_datap pData; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_CREATE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - -#ifndef MNG_INTERNAL_MEMMNGMT - MNG_VALIDCB (hHandle, fMemalloc) - MNG_VALIDCB (hHandle, fMemfree) -#endif - -#ifdef MNG_SUPPORT_READ - if (pData->bReading) /* valid at this point ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID); -#endif - - if ((pData->bWriting) || (pData->bCreating)) - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - cleanup_errors (pData); /* cleanup previous errors */ - - iRetcode = mng_reset (hHandle); /* clear any previous stuff */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - - pData->bCreating = MNG_TRUE; /* indicate we're creating a new file */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_CREATE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_SUPPORT_READ) -mng_retcode MNG_DECL mng_readdisplay (mng_handle hHandle) -{ - mng_datap pData; /* local vars */ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_READDISPLAY, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - -#ifndef MNG_INTERNAL_MEMMNGMT - MNG_VALIDCB (hHandle, fMemalloc) - MNG_VALIDCB (hHandle, fMemfree) -#endif - - MNG_VALIDCB (hHandle, fReaddata) - MNG_VALIDCB (hHandle, fGetcanvasline) - MNG_VALIDCB (hHandle, fRefresh) - MNG_VALIDCB (hHandle, fGettickcount) - MNG_VALIDCB (hHandle, fSettimer) - /* valid at this point ? */ - if ((pData->bReading) || (pData->bDisplaying)) - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - -#ifdef MNG_SUPPORT_WRITE - if ((pData->bWriting) || (pData->bCreating)) - MNG_ERROR (pData, MNG_FUNCTIONINVALID); -#endif - - cleanup_errors (pData); /* cleanup previous errors */ - - pData->bReading = MNG_TRUE; /* read & display! */ - pData->bDisplaying = MNG_TRUE; - pData->bRunning = MNG_TRUE; - pData->iFrameseq = 0; - pData->iLayerseq = 0; - pData->iFrametime = 0; - pData->iRequestframe = 0; - pData->iRequestlayer = 0; - pData->iRequesttime = 0; - pData->bSearching = MNG_FALSE; - pData->iRuntime = 0; - pData->iSynctime = pData->fGettickcount (hHandle); - pData->iSuspendtime = 0; - pData->iStarttime = pData->iSynctime; - pData->iEndtime = 0; - -#ifndef MNG_NO_OPEN_CLOSE_STREAM - if (pData->fOpenstream && !pData->fOpenstream (hHandle)) - /* open it and start reading */ - iRetcode = MNG_APPIOERROR; - else -#endif - iRetcode = mng_read_graphic (pData); - - if (pData->bEOF) /* already at EOF ? */ - { - pData->bReading = MNG_FALSE; /* then we're no longer reading */ - mng_drop_invalid_objects (pData); /* drop invalidly stored objects */ - } - - if (iRetcode) /* on error bail out */ - return iRetcode; - - if (pData->bSuspended) /* read suspension ? */ - { - iRetcode = MNG_NEEDMOREDATA; - pData->iSuspendtime = pData->fGettickcount ((mng_handle)pData); - } - else - if (pData->bTimerset) /* indicate timer break ? */ - iRetcode = MNG_NEEDTIMERWAIT; - else - if (pData->bSectionwait) /* indicate section break ? */ - iRetcode = MNG_NEEDSECTIONWAIT; - else - { /* no breaks = end of run */ - pData->bRunning = MNG_FALSE; - - if (pData->bFreezing) /* dynamic MNG reached SEEK ? */ - pData->bFreezing = MNG_FALSE; /* reset it ! */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_READDISPLAY, MNG_LC_END); -#endif - - return iRetcode; -} -#endif /* MNG_SUPPORT_DISPLAY && MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_display (mng_handle hHandle) -{ - mng_datap pData; /* local vars */ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - -#ifndef MNG_INTERNAL_MEMMNGMT - MNG_VALIDCB (hHandle, fMemalloc) - MNG_VALIDCB (hHandle, fMemfree) -#endif - - MNG_VALIDCB (hHandle, fGetcanvasline) - MNG_VALIDCB (hHandle, fRefresh) - MNG_VALIDCB (hHandle, fGettickcount) - MNG_VALIDCB (hHandle, fSettimer) - - if (pData->bDisplaying) /* valid at this point ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - -#ifdef MNG_SUPPORT_READ - if (pData->bReading) - MNG_ERROR (pData, MNG_FUNCTIONINVALID); -#endif - -#ifdef MNG_SUPPORT_WRITE - if ((pData->bWriting) || (pData->bCreating)) - MNG_ERROR (pData, MNG_FUNCTIONINVALID); -#endif - - cleanup_errors (pData); /* cleanup previous errors */ - - pData->bDisplaying = MNG_TRUE; /* display! */ - pData->bRunning = MNG_TRUE; - pData->iFrameseq = 0; - pData->iLayerseq = 0; - pData->iFrametime = 0; - pData->iRequestframe = 0; - pData->iRequestlayer = 0; - pData->iRequesttime = 0; - pData->bSearching = MNG_FALSE; - pData->iRuntime = 0; - pData->iSynctime = pData->fGettickcount (hHandle); -#ifdef MNG_SUPPORT_READ - pData->iSuspendtime = 0; -#endif - pData->iStarttime = pData->iSynctime; - pData->iEndtime = 0; - pData->pCurraniobj = pData->pFirstaniobj; - /* go do it */ - iRetcode = mng_process_display (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - if (pData->bTimerset) /* indicate timer break ? */ - iRetcode = MNG_NEEDTIMERWAIT; - else - { /* no breaks = end of run */ - pData->bRunning = MNG_FALSE; - - if (pData->bFreezing) /* dynamic MNG reached SEEK ? */ - pData->bFreezing = MNG_FALSE; /* reset it ! */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY, MNG_LC_END); -#endif - - return iRetcode; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_display_resume (mng_handle hHandle) -{ - mng_datap pData; /* local vars */ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_RESUME, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - - if (!pData->bDisplaying) /* can we expect this call ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - cleanup_errors (pData); /* cleanup previous errors */ - /* was it running ? */ - if ((pData->bRunning) || (pData->bReading)) - { /* are we expecting this call ? */ - if ((pData->bTimerset) || (pData->bSuspended) || (pData->bSectionwait)) - { - pData->bTimerset = MNG_FALSE; /* reset the flags */ - pData->bSectionwait = MNG_FALSE; - -#ifdef MNG_SUPPORT_READ - if (pData->bReading) /* set during read&display ? */ - { - if (pData->bSuspended) /* calculate proper synchronization */ - pData->iSynctime = pData->iSynctime - pData->iSuspendtime + - pData->fGettickcount (hHandle); - else - pData->iSynctime = pData->fGettickcount (hHandle); - - pData->bSuspended = MNG_FALSE; /* now reset this flag */ - /* and continue reading */ - iRetcode = mng_read_graphic (pData); - - if (pData->bEOF) /* already at EOF ? */ - { - pData->bReading = MNG_FALSE; /* then we're no longer reading */ - /* drop invalidly stored objects */ - mng_drop_invalid_objects (pData); - } - } - else -#endif /* MNG_SUPPORT_READ */ - { /* synchronize timing */ - pData->iSynctime = pData->fGettickcount (hHandle); - /* resume display processing */ - iRetcode = mng_process_display (pData); - } - } - else - { - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - } - } - else - { /* synchronize timing */ - pData->iSynctime = pData->fGettickcount (hHandle); - pData->bRunning = MNG_TRUE; /* it's restarted again ! */ - /* resume display processing */ - iRetcode = mng_process_display (pData); - } - - if (iRetcode) /* on error bail out */ - return iRetcode; - - if (pData->bSuspended) /* read suspension ? */ - { - iRetcode = MNG_NEEDMOREDATA; - pData->iSuspendtime = pData->fGettickcount ((mng_handle)pData); - } - else - if (pData->bTimerset) /* indicate timer break ? */ - iRetcode = MNG_NEEDTIMERWAIT; - else - if (pData->bSectionwait) /* indicate section break ? */ - iRetcode = MNG_NEEDSECTIONWAIT; - else - { /* no breaks = end of run */ - pData->bRunning = MNG_FALSE; - - if (pData->bFreezing) /* trying to freeze ? */ - pData->bFreezing = MNG_FALSE; /* then we're there */ - - if (pData->bResetting) /* trying to reset as well ? */ - { /* full stop!!! */ - pData->bDisplaying = MNG_FALSE; - - iRetcode = mng_reset_rundata (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_RESUME, MNG_LC_END); -#endif - - return iRetcode; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_display_freeze (mng_handle hHandle) -{ - mng_datap pData; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_FREEZE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - /* can we expect this call ? */ - if ((!pData->bDisplaying) || (pData->bReading)) - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - cleanup_errors (pData); /* cleanup previous errors */ - - if (pData->bRunning) /* is it running ? */ - { - mng_retcode iRetcode; - - pData->bFreezing = MNG_TRUE; /* indicate we need to freeze */ - /* continue "normal" processing */ - iRetcode = mng_display_resume (hHandle); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_FREEZE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_display_reset (mng_handle hHandle) -{ - mng_datap pData; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_RESET, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - /* can we expect this call ? */ - if ((!pData->bDisplaying) || (pData->bReading)) - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - if (!pData->bCacheplayback) /* must store playback info to work!! */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - cleanup_errors (pData); /* cleanup previous errors */ - - if (pData->bRunning) /* is it running ? */ - { - pData->bFreezing = MNG_TRUE; /* indicate we need to freeze */ - pData->bResetting = MNG_TRUE; /* indicate we're about to reset too */ - /* continue normal processing ? */ - iRetcode = mng_display_resume (hHandle); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - else - { /* full stop!!! */ - pData->bDisplaying = MNG_FALSE; - - iRetcode = mng_reset_rundata (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_RESET, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_NO_DISPLAY_GO_SUPPORTED -mng_retcode MNG_DECL mng_display_goframe (mng_handle hHandle, - mng_uint32 iFramenr) -{ - mng_datap pData; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOFRAME, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - - if (pData->eImagetype != mng_it_mng) /* is it an animation ? */ - MNG_ERROR (pData, MNG_NOTANANIMATION); - /* can we expect this call ? */ - if ((!pData->bDisplaying) || (pData->bRunning)) - MNG_ERROR ((mng_datap)hHandle, MNG_FUNCTIONINVALID); - - if (!pData->bCacheplayback) /* must store playback info to work!! */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - if (iFramenr > pData->iTotalframes) /* is the parameter within bounds ? */ - MNG_ERROR (pData, MNG_FRAMENRTOOHIGH); - /* within MHDR bounds ? */ - if ((pData->iFramecount) && (iFramenr > pData->iFramecount)) - MNG_WARNING (pData, MNG_FRAMENRTOOHIGH); - - cleanup_errors (pData); /* cleanup previous errors */ - - if (pData->iFrameseq > iFramenr) /* search from current or go back to start ? */ - { - iRetcode = mng_reset_rundata (pData); - if (iRetcode) /* on error bail out */ - return iRetcode; - } - - if (iFramenr) - { - pData->iRequestframe = iFramenr; /* go find the requested frame then */ - iRetcode = mng_process_display (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - pData->bTimerset = MNG_FALSE; /* reset just to be safe */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOFRAME, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_NO_DISPLAY_GO_SUPPORTED -mng_retcode MNG_DECL mng_display_golayer (mng_handle hHandle, - mng_uint32 iLayernr) -{ - mng_datap pData; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOLAYER, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - - if (pData->eImagetype != mng_it_mng) /* is it an animation ? */ - MNG_ERROR (pData, MNG_NOTANANIMATION); - /* can we expect this call ? */ - if ((!pData->bDisplaying) || (pData->bRunning)) - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - if (!pData->bCacheplayback) /* must store playback info to work!! */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - if (iLayernr > pData->iTotallayers) /* is the parameter within bounds ? */ - MNG_ERROR (pData, MNG_LAYERNRTOOHIGH); - /* within MHDR bounds ? */ - if ((pData->iLayercount) && (iLayernr > pData->iLayercount)) - MNG_WARNING (pData, MNG_LAYERNRTOOHIGH); - - cleanup_errors (pData); /* cleanup previous errors */ - - if (pData->iLayerseq > iLayernr) /* search from current or go back to start ? */ - { - iRetcode = mng_reset_rundata (pData); - if (iRetcode) /* on error bail out */ - return iRetcode; - } - - if (iLayernr) - { - pData->iRequestlayer = iLayernr; /* go find the requested layer then */ - iRetcode = mng_process_display (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - pData->bTimerset = MNG_FALSE; /* reset just to be safe */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOLAYER, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_NO_DISPLAY_GO_SUPPORTED -mng_retcode MNG_DECL mng_display_gotime (mng_handle hHandle, - mng_uint32 iPlaytime) -{ - mng_datap pData; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOTIME, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - - if (pData->eImagetype != mng_it_mng) /* is it an animation ? */ - MNG_ERROR (pData, MNG_NOTANANIMATION); - /* can we expect this call ? */ - if ((!pData->bDisplaying) || (pData->bRunning)) - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - if (!pData->bCacheplayback) /* must store playback info to work!! */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - /* is the parameter within bounds ? */ - if (iPlaytime > pData->iTotalplaytime) - MNG_ERROR (pData, MNG_PLAYTIMETOOHIGH); - /* within MHDR bounds ? */ - if ((pData->iPlaytime) && (iPlaytime > pData->iPlaytime)) - MNG_WARNING (pData, MNG_PLAYTIMETOOHIGH); - - cleanup_errors (pData); /* cleanup previous errors */ - - if (pData->iFrametime > iPlaytime) /* search from current or go back to start ? */ - { - iRetcode = mng_reset_rundata (pData); - if (iRetcode) /* on error bail out */ - return iRetcode; - } - - if (iPlaytime) - { - pData->iRequesttime = iPlaytime; /* go find the requested playtime then */ - iRetcode = mng_process_display (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - pData->bTimerset = MNG_FALSE; /* reset just to be safe */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOTIME, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_SUPPORT_DYNAMICMNG) -mng_retcode MNG_DECL mng_trapevent (mng_handle hHandle, - mng_uint8 iEventtype, - mng_int32 iX, - mng_int32 iY) -{ - mng_datap pData; - mng_eventp pEvent; - mng_bool bFound = MNG_FALSE; - mng_retcode iRetcode; - mng_imagep pImage; - mng_uint8p pPixel; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_TRAPEVENT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - - if (pData->eImagetype != mng_it_mng) /* is it an animation ? */ - MNG_ERROR (pData, MNG_NOTANANIMATION); - - if (!pData->bDisplaying) /* can we expect this call ? */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - if (!pData->bCacheplayback) /* must store playback info to work!! */ - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - /* let's find a matching event object */ - pEvent = (mng_eventp)pData->pFirstevent; - - while ((pEvent) && (!bFound)) - { /* matching eventtype ? */ - if (pEvent->iEventtype == iEventtype) - { - switch (pEvent->iMasktype) /* check X/Y on basis of masktype */ - { - case MNG_MASK_NONE : /* no mask is easy */ - { - bFound = MNG_TRUE; - break; - } - - case MNG_MASK_BOX : /* inside the given box ? */ - { /* right- and bottom-border don't count ! */ - if ((iX >= pEvent->iLeft) && (iX < pEvent->iRight) && - (iY >= pEvent->iTop) && (iY < pEvent->iBottom)) - bFound = MNG_TRUE; - break; - } - - case MNG_MASK_OBJECT : /* non-zero pixel in the image object ? */ - { - pImage = mng_find_imageobject (pData, pEvent->iObjectid); - /* valid image ? */ - if ((pImage) && (pImage->pImgbuf->iBitdepth <= 8) && - ((pImage->pImgbuf->iColortype == 0) || (pImage->pImgbuf->iColortype == 3)) && - ((mng_int32)pImage->pImgbuf->iWidth > iX) && - ((mng_int32)pImage->pImgbuf->iHeight > iY)) - { - pPixel = pImage->pImgbuf->pImgdata + ((pImage->pImgbuf->iWidth * iY) + iX); - - if (*pPixel) /* non-zero ? */ - bFound = MNG_TRUE; - } - - break; - } - - case MNG_MASK_OBJECTIX : /* pixel in the image object matches index ? */ - { - pImage = mng_find_imageobject (pData, pEvent->iObjectid); - /* valid image ? */ - if ((pImage) && (pImage->pImgbuf->iBitdepth <= 8) && - ((pImage->pImgbuf->iColortype == 0) || (pImage->pImgbuf->iColortype == 3)) && - ((mng_int32)pImage->pImgbuf->iWidth > iX) && (iX >= 0) && - ((mng_int32)pImage->pImgbuf->iHeight > iY) && (iY >= 0)) - { - pPixel = pImage->pImgbuf->pImgdata + ((pImage->pImgbuf->iWidth * iY) + iX); - /* matching index ? */ - if (*pPixel == pEvent->iIndex) - bFound = MNG_TRUE; - } - - break; - } - - case MNG_MASK_BOXOBJECT : /* non-zero pixel in the image object ? */ - { - mng_int32 iTempx = iX - pEvent->iLeft; - mng_int32 iTempy = iY - pEvent->iTop; - - pImage = mng_find_imageobject (pData, pEvent->iObjectid); - /* valid image ? */ - if ((pImage) && (pImage->pImgbuf->iBitdepth <= 8) && - ((pImage->pImgbuf->iColortype == 0) || (pImage->pImgbuf->iColortype == 3)) && - (iTempx < (mng_int32)pImage->pImgbuf->iWidth) && - (iTempx >= 0) && (iX < pEvent->iRight) && - (iTempy < (mng_int32)pImage->pImgbuf->iHeight) && - (iTempy >= 0) && (iY < pEvent->iBottom)) - { - pPixel = pImage->pImgbuf->pImgdata + ((pImage->pImgbuf->iWidth * iTempy) + iTempx); - - if (*pPixel) /* non-zero ? */ - bFound = MNG_TRUE; - } - - break; - } - - case MNG_MASK_BOXOBJECTIX : /* pixel in the image object matches index ? */ - { - mng_int32 iTempx = iX - pEvent->iLeft; - mng_int32 iTempy = iY - pEvent->iTop; - - pImage = mng_find_imageobject (pData, pEvent->iObjectid); - /* valid image ? */ - if ((pImage) && (pImage->pImgbuf->iBitdepth <= 8) && - ((pImage->pImgbuf->iColortype == 0) || (pImage->pImgbuf->iColortype == 3)) && - (iTempx < (mng_int32)pImage->pImgbuf->iWidth) && - (iTempx >= 0) && (iX < pEvent->iRight) && - (iTempy < (mng_int32)pImage->pImgbuf->iHeight) && - (iTempy >= 0) && (iY < pEvent->iBottom)) - { - pPixel = pImage->pImgbuf->pImgdata + ((pImage->pImgbuf->iWidth * iTempy) + iTempx); - /* matching index ? */ - if (*pPixel == pEvent->iIndex) - bFound = MNG_TRUE; - } - - break; - } - - } - } - - if (!bFound) /* try the next one */ - pEvent = (mng_eventp)pEvent->sHeader.pNext; - } - /* found one that's not the last mousemove ? */ - if ((pEvent) && ((mng_objectp)pEvent != pData->pLastmousemove)) - { /* can we start an event process now ? */ - if ((!pData->bReading) && (!pData->bRunning)) - { - pData->iEventx = iX; /* save coordinates */ - pData->iEventy = iY; - /* do it then ! */ - iRetcode = pEvent->sHeader.fProcess (pData, pEvent); - - if (iRetcode) /* on error bail out */ - return iRetcode; - /* remember last mousemove event */ - if (pEvent->iEventtype == MNG_EVENT_MOUSEMOVE) - pData->pLastmousemove = (mng_objectp)pEvent; - else - pData->pLastmousemove = MNG_NULL; - } - else - { - - /* TODO: store unprocessed events or not ??? */ - - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_TRAPEVENT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_getlasterror (mng_handle hHandle, - mng_int8* iSeverity, - mng_chunkid* iChunkname, - mng_uint32* iChunkseq, - mng_int32* iExtra1, - mng_int32* iExtra2, - mng_pchar* zErrortext) -{ - mng_datap pData; /* local vars */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETLASTERROR, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) /* check validity handle */ - pData = ((mng_datap)hHandle); /* and make it addressable */ - - *iSeverity = pData->iSeverity; /* return the appropriate fields */ - -#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) - *iChunkname = pData->iChunkname; - *iChunkseq = pData->iChunkseq; -#else - *iChunkname = MNG_UINT_HUH; - *iChunkseq = 0; -#endif - - *iExtra1 = pData->iErrorx1; - *iExtra2 = pData->iErrorx2; - *zErrortext = pData->zErrortext; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETLASTERROR, MNG_LC_END); -#endif - - return pData->iErrorcode; /* and the errorcode */ -} - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_hlapi.c copyright (c) 2000-2007 G.Juyn * */ +/* * version : 1.0.10 * */ +/* * * */ +/* * purpose : high-level application API (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the high-level function interface * */ +/* * for applications. * */ +/* * * */ +/* * changes : 0.5.1 - 05/06/2000 - G.Juyn * */ +/* * - added init of iPLTEcount * */ +/* * 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - changed calling-convention definition * */ +/* * - changed status-handling of display-routines * */ +/* * - added versioning-control routines * */ +/* * - filled the write routine * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/11/2000 - G.Juyn * */ +/* * - added callback error-reporting support * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - changed trace to macro for callback error-reporting * */ +/* * 0.5.1 - 05/13/2000 - G.Juyn * */ +/* * - added eMNGma hack (will be removed in 1.0.0 !!!) * */ +/* * - added TERM animation object pointer (easier reference) * */ +/* * 0.5.1 - 05/14/2000 - G.Juyn * */ +/* * - added cleanup of saved-data (SAVE/SEEK processing) * */ +/* * 0.5.1 - 05/16/2000 - G.Juyn * */ +/* * - moved the actual write_graphic functionality from here * */ +/* * to its appropriate function in the mng_write module * */ +/* * * */ +/* * 0.5.2 - 05/19/2000 - G.Juyn * */ +/* * - cleaned up some code regarding mixed support * */ +/* * - added JNG support * */ +/* * 0.5.2 - 05/24/2000 - G.Juyn * */ +/* * - moved init of default zlib parms here from "mng_zlib.c" * */ +/* * - added init of default IJG parms * */ +/* * 0.5.2 - 05/29/2000 - G.Juyn * */ +/* * - fixed inconsistancy with freeing global iCCP profile * */ +/* * 0.5.2 - 05/30/2000 - G.Juyn * */ +/* * - added delta-image field initialization * */ +/* * 0.5.2 - 06/06/2000 - G.Juyn * */ +/* * - added initialization of the buffer-suspend parameter * */ +/* * * */ +/* * 0.5.3 - 06/16/2000 - G.Juyn * */ +/* * - added initialization of update-region for refresh * */ +/* * - added initialization of Needrefresh parameter * */ +/* * 0.5.3 - 06/17/2000 - G.Juyn * */ +/* * - added initialization of Deltaimmediate * */ +/* * 0.5.3 - 06/21/2000 - G.Juyn * */ +/* * - added initialization of Speed * */ +/* * - added initialization of Imagelevel * */ +/* * 0.5.3 - 06/26/2000 - G.Juyn * */ +/* * - changed userdata variable to mng_ptr * */ +/* * 0.5.3 - 06/29/2000 - G.Juyn * */ +/* * - fixed initialization routine for new mng_handle type * */ +/* * * */ +/* * 0.9.1 - 07/06/2000 - G.Juyn * */ +/* * - changed mng_display_resume to allow to be called after * */ +/* * a suspension return with MNG_NEEDMOREDATA * */ +/* * - added returncode MNG_NEEDTIMERWAIT for timer breaks * */ +/* * 0.9.1 - 07/07/2000 - G.Juyn * */ +/* * - implemented support for freeze/reset/resume & go_xxxx * */ +/* * 0.9.1 - 07/08/2000 - G.Juyn * */ +/* * - added support for improved timing * */ +/* * - added support for improved I/O-suspension * */ +/* * 0.9.1 - 07/14/2000 - G.Juyn * */ +/* * - changed EOF processing behavior * */ +/* * 0.9.1 - 07/15/2000 - G.Juyn * */ +/* * - added callbacks for SAVE/SEEK processing * */ +/* * - added variable for NEEDSECTIONWAIT breaks * */ +/* * - added variable for freeze & reset processing * */ +/* * 0.9.1 - 07/17/2000 - G.Juyn * */ +/* * - added error cleanup processing * */ +/* * - fixed support for mng_display_reset() * */ +/* * - fixed suspension-buffering for 32K+ chunks * */ +/* * * */ +/* * 0.9.2 - 07/29/2000 - G.Juyn * */ +/* * - fixed small bugs in display processing * */ +/* * 0.9.2 - 07/31/2000 - G.Juyn * */ +/* * - fixed wrapping of suspension parameters * */ +/* * 0.9.2 - 08/04/2000 - G.Juyn * */ +/* * - B111096 - fixed large-buffer read-suspension * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 0.9.3 - 09/07/2000 - G.Juyn * */ +/* * - added support for new filter_types * */ +/* * 0.9.3 - 09/10/2000 - G.Juyn * */ +/* * - fixed DEFI behavior * */ +/* * 0.9.3 - 10/11/2000 - G.Juyn * */ +/* * - added support for nEED * */ +/* * 0.9.3 - 10/16/2000 - G.Juyn * */ +/* * - added optional support for bKGD for PNG images * */ +/* * - raised initial maximum canvas size * */ +/* * - added support for JDAA * */ +/* * 0.9.3 - 10/17/2000 - G.Juyn * */ +/* * - added callback to process non-critical unknown chunks * */ +/* * - fixed support for delta-images during read() / display() * */ +/* * 0.9.3 - 10/18/2000 - G.Juyn * */ +/* * - added closestream() processing for mng_cleanup() * */ +/* * 0.9.3 - 10/27/2000 - G.Juyn * */ +/* * - fixed separate read() & display() processing * */ +/* * * */ +/* * 0.9.4 - 11/20/2000 - G.Juyn * */ +/* * - fixed unwanted repetition in mng_readdisplay() * */ +/* * 0.9.4 - 11/24/2000 - G.Juyn * */ +/* * - moved restore of object 0 to libmng_display * */ +/* * * */ +/* * 1.0.1 - 02/08/2001 - G.Juyn * */ +/* * - added MEND processing callback * */ +/* * 1.0.1 - 02/13/2001 - G.Juyn * */ +/* * - fixed first FRAM_MODE=4 timing problem * */ +/* * 1.0.1 - 04/21/2001 - G.Juyn * */ +/* * - fixed bug with display_reset/display_resume (Thanks G!) * */ +/* * 1.0.1 - 04/22/2001 - G.Juyn * */ +/* * - fixed memory-leak (Thanks Gregg!) * */ +/* * 1.0.1 - 04/23/2001 - G.Juyn * */ +/* * - fixed reset_rundata to drop all objects * */ +/* * 1.0.1 - 04/25/2001 - G.Juyn * */ +/* * - moved mng_clear_cms to libmng_cms * */ +/* * * */ +/* * 1.0.2 - 06/23/2001 - G.Juyn * */ +/* * - added optimization option for MNG-video playback * */ +/* * - added processterm callback * */ +/* * 1.0.2 - 06/25/2001 - G.Juyn * */ +/* * - added option to turn off progressive refresh * */ +/* * * */ +/* * 1.0.5 - 07/08/2002 - G.Juyn * */ +/* * - B578572 - removed eMNGma hack (thanks Dimitri!) * */ +/* * 1.0.5 - 07/16/2002 - G.Juyn * */ +/* * - B581625 - large chunks fail with suspension reads * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * 1.0.5 - 09/15/2002 - G.Juyn * */ +/* * - fixed LOOP iteration=0 special case * */ +/* * 1.0.5 - 10/07/2002 - G.Juyn * */ +/* * - added another fix for misplaced TERM chunk * */ +/* * - completed support for condition=2 in TERM chunk * */ +/* * - added beta version function & constant * */ +/* * 1.0.5 - 10/11/2002 - G.Juyn * */ +/* * - added mng_status_dynamic to supports function * */ +/* * 1.0.5 - 11/04/2002 - G.Juyn * */ +/* * - changed FRAMECOUNT/LAYERCOUNT/PLAYTIME error to warning * */ +/* * 1.0.5 - 11/07/2002 - G.Juyn * */ +/* * - added support to get totals after mng_read() * */ +/* * 1.0.5 - 11/29/2002 - G.Juyn * */ +/* * - fixed goxxxxx() support for zero values * */ +/* * * */ +/* * 1.0.6 - 05/25/2003 - G.R-P * */ +/* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */ +/* * 1.0.6 - 07/11/2003 - G.R-P * */ +/* * - added conditionals zlib and jpeg property accessors * */ +/* * 1.0.6 - 07/14/2003 - G.R-P * */ +/* * - added conditionals around "mng_display_go*" and other * */ +/* * unused functions * */ +/* * 1.0.6 - 07/29/2003 - G.R-P * */ +/* * - added conditionals around PAST chunk support * */ +/* * * */ +/* * 1.0.7 - 03/07/2004 - G. Randers-Pehrson * */ +/* * - put gamma, cms-related declarations inside #ifdef * */ +/* * 1.0.7 - 03/10/2004 - G.R-P * */ +/* * - added conditionals around openstream/closestream * */ +/* * 1.0.7 - 03/24/2004 - G.R-P * */ +/* * - fixed zTXT -> zTXt typo * */ +/* * * */ +/* * 1.0.8 - 04/02/2004 - G.Juyn * */ +/* * - added CRC existence & checking flags * */ +/* * 1.0.8 - 04/10/2004 - G.Juyn * */ +/* * - added data-push mechanisms for specialized decoders * */ +/* * 1.0.8 - 07/06/2004 - G.R-P * */ +/* * - defend against using undefined openstream function * */ +/* * 1.0.8 - 08/02/2004 - G.Juyn * */ +/* * - added conditional to allow easier writing of large MNG's * */ +/* * * */ +/* * 1.0.9 - 08/17/2004 - G.R-P * */ +/* * - added more SKIPCHUNK conditionals * */ +/* * 1.0.9 - 09/25/2004 - G.Juyn * */ +/* * - replaced MNG_TWEAK_LARGE_FILES with permanent solution * */ +/* * 1.0.9 - 10/03/2004 - G.Juyn * */ +/* * - added function to retrieve current FRAM delay * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * * */ +/* * 1.0.10 - 07/06/2005 - G.R-P * */ +/* * - added more SKIPCHUNK conditionals * */ +/* * 1.0.10 - 04/08/2007 - G.Juyn * */ +/* * - added support for mPNG proposal * */ +/* * 1.0.10 - 04/12/2007 - G.Juyn * */ +/* * - added support for ANG proposal * */ +/* * 1.0.10 - 07/06/2007 - G.R-P bugfix by Lucas Quintana * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_objects.h" +#include "libmng_object_prc.h" +#include "libmng_chunks.h" +#include "libmng_memory.h" +#include "libmng_read.h" +#include "libmng_write.h" +#include "libmng_display.h" +#include "libmng_zlib.h" +#include "libmng_jpeg.h" +#include "libmng_cms.h" +#include "libmng_pixels.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ +/* * * */ +/* * local routines * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +MNG_LOCAL mng_retcode mng_drop_objects (mng_datap pData, + mng_bool bDropaniobj) +{ + mng_objectp pObject; + mng_objectp pNext; + mng_cleanupobject fCleanup; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DROP_OBJECTS, MNG_LC_START); +#endif + + pObject = pData->pFirstimgobj; /* get first stored image-object (if any) */ + + while (pObject) /* more objects to discard ? */ + { + pNext = ((mng_object_headerp)pObject)->pNext; + /* call appropriate cleanup */ + fCleanup = ((mng_object_headerp)pObject)->fCleanup; + fCleanup (pData, pObject); + + pObject = pNext; /* neeeext */ + } + + pData->pFirstimgobj = MNG_NULL; /* clean this up!!! */ + pData->pLastimgobj = MNG_NULL; + + if (bDropaniobj) /* drop animation objects ? */ + { + pObject = pData->pFirstaniobj; /* get first stored animation-object (if any) */ + + while (pObject) /* more objects to discard ? */ + { + pNext = ((mng_object_headerp)pObject)->pNext; + /* call appropriate cleanup */ + fCleanup = ((mng_object_headerp)pObject)->fCleanup; + fCleanup (pData, pObject); + + pObject = pNext; /* neeeext */ + } + + pData->pFirstaniobj = MNG_NULL; /* clean this up!!! */ + pData->pLastaniobj = MNG_NULL; + +#ifdef MNG_SUPPORT_DYNAMICMNG + pObject = pData->pFirstevent; /* get first event-object (if any) */ + + while (pObject) /* more objects to discard ? */ + { + pNext = ((mng_object_headerp)pObject)->pNext; + /* call appropriate cleanup */ + fCleanup = ((mng_object_headerp)pObject)->fCleanup; + fCleanup (pData, pObject); + + pObject = pNext; /* neeeext */ + } + + pData->pFirstevent = MNG_NULL; /* clean this up!!! */ + pData->pLastevent = MNG_NULL; +#endif + } + +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + if (pData->pMPNG) /* drop MPNG data (if any) */ + { + fCleanup = ((mng_object_headerp)pData->pMPNG)->fCleanup; + fCleanup (pData, pData->pMPNG); + pData->pMPNG = MNG_NULL; + } +#endif + +#ifdef MNG_INCLUDE_ANG_PROPOSAL + if (pData->pANG) /* drop ANG data (if any) */ + { + fCleanup = ((mng_object_headerp)pData->pANG)->fCleanup; + fCleanup (pData, pData->pANG); + pData->pANG = MNG_NULL; + } +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DROP_OBJECTS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_SKIPCHUNK_SAVE +MNG_LOCAL mng_retcode mng_drop_savedata (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DROP_SAVEDATA, MNG_LC_START); +#endif + + if (pData->pSavedata) /* sanity check */ + { /* address it more directly */ + mng_savedatap pSave = pData->pSavedata; + + if (pSave->iGlobalProfilesize) /* cleanup the profile ? */ + MNG_FREEX (pData, pSave->pGlobalProfile, pSave->iGlobalProfilesize); + /* cleanup the save structure */ + MNG_FREE (pData, pData->pSavedata, sizeof (mng_savedata)); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DROP_SAVEDATA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +MNG_LOCAL mng_retcode mng_reset_rundata (mng_datap pData) +{ + mng_drop_invalid_objects (pData); /* drop invalidly stored objects */ +#ifndef MNG_SKIPCHUNK_SAVE + mng_drop_savedata (pData); /* drop stored savedata */ +#endif + mng_reset_objzero (pData); /* reset object 0 */ + /* drop stored objects (if any) */ + mng_drop_objects (pData, MNG_FALSE); + + pData->bFramedone = MNG_FALSE; + pData->iFrameseq = 0; /* reset counters & stuff */ + pData->iLayerseq = 0; + pData->iFrametime = 0; + + pData->bSkipping = MNG_FALSE; + +#ifdef MNG_SUPPORT_DYNAMICMNG + pData->bRunningevent = MNG_FALSE; + pData->bStopafterseek = MNG_FALSE; + pData->iEventx = 0; + pData->iEventy = 0; + pData->pLastmousemove = MNG_NULL; +#endif + + pData->iRequestframe = 0; + pData->iRequestlayer = 0; + pData->iRequesttime = 0; + pData->bSearching = MNG_FALSE; + + pData->iRuntime = 0; + pData->iSynctime = 0; + pData->iStarttime = 0; + pData->iEndtime = 0; + pData->bRunning = MNG_FALSE; + pData->bTimerset = MNG_FALSE; + pData->iBreakpoint = 0; + pData->bSectionwait = MNG_FALSE; + pData->bFreezing = MNG_FALSE; + pData->bResetting = MNG_FALSE; + pData->bNeedrefresh = MNG_FALSE; + pData->bOnlyfirstframe = MNG_FALSE; + pData->iFramesafterTERM = 0; + + pData->iIterations = 0; + /* start of animation objects! */ + pData->pCurraniobj = MNG_NULL; + + pData->iUpdateleft = 0; /* reset region */ + pData->iUpdateright = 0; + pData->iUpdatetop = 0; + pData->iUpdatebottom = 0; + pData->iPLTEcount = 0; /* reset PLTE data */ + +#ifndef MNG_SKIPCHUNK_DEFI + pData->iDEFIobjectid = 0; /* reset DEFI data */ + pData->bDEFIhasdonotshow = MNG_FALSE; + pData->iDEFIdonotshow = 0; + pData->bDEFIhasconcrete = MNG_FALSE; + pData->iDEFIconcrete = 0; + pData->bDEFIhasloca = MNG_FALSE; + pData->iDEFIlocax = 0; + pData->iDEFIlocay = 0; + pData->bDEFIhasclip = MNG_FALSE; + pData->iDEFIclipl = 0; + pData->iDEFIclipr = 0; + pData->iDEFIclipt = 0; + pData->iDEFIclipb = 0; +#endif + +#ifndef MNG_SKIPCHUNK_BACK + pData->iBACKred = 0; /* reset BACK data */ + pData->iBACKgreen = 0; + pData->iBACKblue = 0; + pData->iBACKmandatory = 0; + pData->iBACKimageid = 0; + pData->iBACKtile = 0; +#endif + +#ifndef MNG_SKIPCHUNK_FRAM + pData->iFRAMmode = 1; /* default global FRAM variables */ + pData->iFRAMdelay = 1; + pData->iFRAMtimeout = 0x7fffffffl; + pData->bFRAMclipping = MNG_FALSE; + pData->iFRAMclipl = 0; + pData->iFRAMclipr = 0; + pData->iFRAMclipt = 0; + pData->iFRAMclipb = 0; + + pData->iFramemode = 1; /* again for the current frame */ + pData->iFramedelay = 1; + pData->iFrametimeout = 0x7fffffffl; + pData->bFrameclipping = MNG_FALSE; + pData->iFrameclipl = 0; + pData->iFrameclipr = 0; + pData->iFrameclipt = 0; + pData->iFrameclipb = 0; + + pData->iNextdelay = 1; +#endif + +#ifndef MNG_SKIPCHUNK_SHOW + pData->iSHOWmode = 0; /* reset SHOW data */ + pData->iSHOWfromid = 0; + pData->iSHOWtoid = 0; + pData->iSHOWnextid = 0; + pData->iSHOWskip = 0; +#endif + + pData->iGlobalPLTEcount = 0; /* reset global PLTE data */ + + pData->iGlobalTRNSrawlen = 0; /* reset global tRNS data */ + + pData->iGlobalGamma = 0; /* reset global gAMA data */ + +#ifndef MNG_SKIPCHUNK_cHRM + pData->iGlobalWhitepointx = 0; /* reset global cHRM data */ + pData->iGlobalWhitepointy = 0; + pData->iGlobalPrimaryredx = 0; + pData->iGlobalPrimaryredy = 0; + pData->iGlobalPrimarygreenx = 0; + pData->iGlobalPrimarygreeny = 0; + pData->iGlobalPrimarybluex = 0; + pData->iGlobalPrimarybluey = 0; +#endif + +#ifndef MNG_SKIPCHUNK_sRGB + pData->iGlobalRendintent = 0; /* reset global sRGB data */ +#endif + +#ifndef MNG_SKIPCHUNK_iCCP + if (pData->iGlobalProfilesize) /* drop global profile (if any) */ + MNG_FREE (pData, pData->pGlobalProfile, pData->iGlobalProfilesize); + + pData->iGlobalProfilesize = 0; +#endif + +#ifndef MNG_SKIPCHUNK_bKGD + pData->iGlobalBKGDred = 0; /* reset global bKGD data */ + pData->iGlobalBKGDgreen = 0; + pData->iGlobalBKGDblue = 0; +#endif +#ifndef MNG_NO_DELTA_PNG + /* reset delta-image */ + pData->pDeltaImage = MNG_NULL; + pData->iDeltaImagetype = 0; + pData->iDeltatype = 0; + pData->iDeltaBlockwidth = 0; + pData->iDeltaBlockheight = 0; + pData->iDeltaBlockx = 0; + pData->iDeltaBlocky = 0; + pData->bDeltaimmediate = MNG_FALSE; + + pData->fDeltagetrow = MNG_NULL; + pData->fDeltaaddrow = MNG_NULL; + pData->fDeltareplacerow = MNG_NULL; + pData->fDeltaputrow = MNG_NULL; + + pData->fPromoterow = MNG_NULL; + pData->fPromBitdepth = MNG_NULL; + pData->pPromBuf = MNG_NULL; + pData->iPromColortype = 0; + pData->iPromBitdepth = 0; + pData->iPromFilltype = 0; + pData->iPromWidth = 0; + pData->pPromSrc = MNG_NULL; + pData->pPromDst = MNG_NULL; +#endif + +#ifndef MNG_SKIPCHUNK_MAGN + pData->iMAGNfromid = 0; + pData->iMAGNtoid = 0; +#endif + +#ifndef MNG_SKIPCHUNK_PAST + pData->iPastx = 0; + pData->iPasty = 0; +#endif + + pData->pLastseek = MNG_NULL; + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +MNG_LOCAL void cleanup_errors (mng_datap pData) +{ + pData->iErrorcode = MNG_NOERROR; + pData->iSeverity = 0; + pData->iErrorx1 = 0; + pData->iErrorx2 = 0; + pData->zErrortext = MNG_NULL; + + return; +} + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +MNG_LOCAL mng_retcode make_pushbuffer (mng_datap pData, + mng_ptr pPushdata, + mng_size_t iLength, + mng_bool bTakeownership, + mng_pushdatap * pPush) +{ + mng_pushdatap pTemp; + + MNG_ALLOC (pData, pTemp, sizeof(mng_pushdata)); + + pTemp->pNext = MNG_NULL; + + if (bTakeownership) /* are we going to own the buffer? */ + { /* then just copy the pointer */ + pTemp->pData = (mng_uint8p)pPushdata; + } + else + { /* otherwise create new buffer */ + MNG_ALLOCX (pData, pTemp->pData, iLength); + if (!pTemp->pData) /* succeeded? */ + { + MNG_FREEX (pData, pTemp, sizeof(mng_pushdata)); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + /* and copy the bytes across */ + MNG_COPY (pTemp->pData, pPushdata, iLength); + } + + pTemp->iLength = iLength; + pTemp->bOwned = bTakeownership; + pTemp->pDatanext = pTemp->pData; + pTemp->iRemaining = iLength; + + *pPush = pTemp; /* return it */ + + return MNG_NOERROR; /* and all's well */ +} +#endif + +#ifdef MNG_VERSION_QUERY_SUPPORT +/* ************************************************************************** */ +/* * * */ +/* * Versioning control * */ +/* * * */ +/* ************************************************************************** */ + +mng_pchar MNG_DECL mng_version_text (void) +{ + return MNG_VERSION_TEXT; +} + +/* ************************************************************************** */ + +mng_uint8 MNG_DECL mng_version_so (void) +{ + return MNG_VERSION_SO; +} + +/* ************************************************************************** */ + +mng_uint8 MNG_DECL mng_version_dll (void) +{ + return MNG_VERSION_DLL; +} + +/* ************************************************************************** */ + +mng_uint8 MNG_DECL mng_version_major (void) +{ + return MNG_VERSION_MAJOR; +} + +/* ************************************************************************** */ + +mng_uint8 MNG_DECL mng_version_minor (void) +{ + return MNG_VERSION_MINOR; +} + +/* ************************************************************************** */ + +mng_uint8 MNG_DECL mng_version_release (void) +{ + return MNG_VERSION_RELEASE; +} + +/* ************************************************************************** */ + +mng_bool MNG_DECL mng_version_beta (void) +{ + return MNG_VERSION_BETA; +} +#endif + +/* ************************************************************************** */ +/* * * */ +/* * 'supports' function * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_FUNCQUERY +typedef struct { + mng_pchar zFunction; + mng_uint8 iMajor; /* Major == 0 means not implemented ! */ + mng_uint8 iMinor; + mng_uint8 iRelease; + } mng_func_entry; +typedef mng_func_entry const * mng_func_entryp; + +MNG_LOCAL mng_func_entry const func_table [] = + { /* keep it alphabetically sorted !!!!! */ + {"mng_cleanup", 1, 0, 0}, + {"mng_copy_chunk", 1, 0, 5}, + {"mng_create", 1, 0, 0}, + {"mng_display", 1, 0, 0}, + {"mng_display_freeze", 1, 0, 0}, +#ifndef MNG_NO_DISPLAY_GO_SUPPORTED + {"mng_display_goframe", 1, 0, 0}, + {"mng_display_golayer", 1, 0, 0}, + {"mng_display_gotime", 1, 0, 0}, +#endif + {"mng_display_reset", 1, 0, 0}, + {"mng_display_resume", 1, 0, 0}, + {"mng_get_alphabitdepth", 1, 0, 0}, + {"mng_get_alphacompression", 1, 0, 0}, + {"mng_get_alphadepth", 1, 0, 0}, + {"mng_get_alphafilter", 1, 0, 0}, + {"mng_get_alphainterlace", 1, 0, 0}, + {"mng_get_bgcolor", 1, 0, 0}, + {"mng_get_bitdepth", 1, 0, 0}, + {"mng_get_bkgdstyle", 1, 0, 0}, + {"mng_get_cacheplayback", 1, 0, 2}, + {"mng_get_canvasstyle", 1, 0, 0}, + {"mng_get_colortype", 1, 0, 0}, + {"mng_get_compression", 1, 0, 0}, +#ifndef MNG_NO_CURRENT_INFO + {"mng_get_currentframe", 1, 0, 0}, + {"mng_get_currentlayer", 1, 0, 0}, + {"mng_get_currentplaytime", 1, 0, 0}, +#endif + {"mng_get_currframdelay", 1, 0, 9}, +#ifndef MNG_NO_DFLT_INFO + {"mng_get_dfltimggamma", 1, 0, 0}, + {"mng_get_dfltimggammaint", 1, 0, 0}, +#endif + {"mng_get_displaygamma", 1, 0, 0}, + {"mng_get_displaygammaint", 1, 0, 0}, + {"mng_get_doprogressive", 1, 0, 2}, + {"mng_get_filter", 1, 0, 0}, + {"mng_get_framecount", 1, 0, 0}, + {"mng_get_imageheight", 1, 0, 0}, + {"mng_get_imagelevel", 1, 0, 0}, + {"mng_get_imagetype", 1, 0, 0}, + {"mng_get_imagewidth", 1, 0, 0}, + {"mng_get_interlace", 1, 0, 0}, +#ifdef MNG_ACCESS_JPEG + {"mng_get_jpeg_dctmethod", 1, 0, 0}, + {"mng_get_jpeg_maxjdat", 1, 0, 0}, + {"mng_get_jpeg_optimized", 1, 0, 0}, + {"mng_get_jpeg_progressive", 1, 0, 0}, + {"mng_get_jpeg_quality", 1, 0, 0}, + {"mng_get_jpeg_smoothing", 1, 0, 0}, +#endif + {"mng_get_lastbackchunk", 1, 0, 3}, + {"mng_get_lastseekname", 1, 0, 5}, + {"mng_get_layercount", 1, 0, 0}, +#ifndef MNG_SKIP_MAXCANVAS + {"mng_get_maxcanvasheight", 1, 0, 0}, + {"mng_get_maxcanvaswidth", 1, 0, 0}, +#endif + {"mng_get_playtime", 1, 0, 0}, + {"mng_get_refreshpass", 1, 0, 0}, + {"mng_get_runtime", 1, 0, 0}, + {"mng_get_sectionbreaks", 1, 0, 0}, + {"mng_get_sigtype", 1, 0, 0}, + {"mng_get_simplicity", 1, 0, 0}, + {"mng_get_speed", 1, 0, 0}, + {"mng_get_srgb", 1, 0, 0}, + {"mng_get_starttime", 1, 0, 0}, + {"mng_get_storechunks", 1, 0, 0}, + {"mng_get_suspensionmode", 1, 0, 0}, + {"mng_get_ticks", 1, 0, 0}, +#ifndef MNG_NO_CURRENT_INFO + {"mng_get_totalframes", 1, 0, 5}, + {"mng_get_totallayers", 1, 0, 5}, + {"mng_get_totalplaytime", 1, 0, 5}, +#endif + {"mng_get_usebkgd", 1, 0, 0}, + {"mng_get_userdata", 1, 0, 0}, +#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) + {"mng_get_viewgamma", 1, 0, 0}, + {"mng_get_viewgammaint", 1, 0, 0}, +#endif +#ifdef MNG_ACCESS_ZLIB + {"mng_get_zlib_level", 1, 0, 0}, + {"mng_get_zlib_maxidat", 1, 0, 0}, + {"mng_get_zlib_memlevel", 1, 0, 0}, + {"mng_get_zlib_method", 1, 0, 0}, + {"mng_get_zlib_strategy", 1, 0, 0}, + {"mng_get_zlib_windowbits", 1, 0, 0}, +#endif +#ifndef MNG_NO_OPEN_CLOSE_STREAM + {"mng_getcb_closestream", 1, 0, 0}, +#endif + {"mng_getcb_errorproc", 1, 0, 0}, + {"mng_getcb_getalphaline", 1, 0, 0}, + {"mng_getcb_getbkgdline", 1, 0, 0}, + {"mng_getcb_getcanvasline", 1, 0, 0}, + {"mng_getcb_gettickcount", 1, 0, 0}, + {"mng_getcb_memalloc", 1, 0, 0}, + {"mng_getcb_memfree", 1, 0, 0}, +#ifndef MNG_NO_OPEN_CLOSE_STREAM + {"mng_getcb_openstream", 1, 0, 0}, +#endif + {"mng_getcb_processarow", 1, 0, 0}, + {"mng_getcb_processchroma", 1, 0, 0}, + {"mng_getcb_processgamma", 1, 0, 0}, + {"mng_getcb_processheader", 1, 0, 0}, + {"mng_getcb_processiccp", 1, 0, 0}, + {"mng_getcb_processmend", 1, 0, 1}, + {"mng_getcb_processneed", 1, 0, 0}, + {"mng_getcb_processsave", 1, 0, 0}, + {"mng_getcb_processseek", 1, 0, 0}, + {"mng_getcb_processsrgb", 1, 0, 0}, + {"mng_getcb_processterm", 1, 0, 2}, + {"mng_getcb_processtext", 1, 0, 0}, + {"mng_getcb_processunknown", 1, 0, 0}, + {"mng_getcb_readdata", 1, 0, 0}, + {"mng_getcb_refresh", 1, 0, 0}, + {"mng_getcb_releasedata", 1, 0, 8}, + {"mng_getcb_settimer", 1, 0, 0}, + {"mng_getcb_traceproc", 1, 0, 0}, + {"mng_getcb_writedata", 1, 0, 0}, + {"mng_getchunk_back", 1, 0, 0}, + {"mng_getchunk_basi", 1, 0, 0}, +#ifndef MNG_SKIPCHUNK_bKGD + {"mng_getchunk_bkgd", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_cHRM + {"mng_getchunk_chrm", 1, 0, 0}, +#endif + {"mng_getchunk_clip", 1, 0, 0}, + {"mng_getchunk_clon", 1, 0, 0}, +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_dBYK + {"mng_getchunk_dbyk", 1, 0, 0}, +#endif +#endif + {"mng_getchunk_defi", 1, 0, 0}, +#ifndef MNG_NO_DELTA_PNG + {"mng_getchunk_dhdr", 1, 0, 0}, +#endif + {"mng_getchunk_disc", 1, 0, 0}, +#ifndef MNG_NO_DELTA_PNG + {"mng_getchunk_drop", 1, 0, 0}, +#endif + {"mng_getchunk_endl", 1, 0, 0}, +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + {"mng_getchunk_mpng", 1, 0, 10}, + {"mng_getchunk_mpng_frame", 1, 0, 10}, +#endif +#ifndef MNG_SKIPCHUNK_evNT + {"mng_getchunk_evnt", 1, 0, 5}, + {"mng_getchunk_evnt_entry", 1, 0, 5}, +#endif +#ifndef MNG_SKIPCHUNK_eXPI + {"mng_getchunk_expi", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_fPRI + {"mng_getchunk_fpri", 1, 0, 0}, +#endif + {"mng_getchunk_fram", 1, 0, 0}, + {"mng_getchunk_gama", 1, 0, 0}, +#ifndef MNG_SKIPCHUNK_hIST + {"mng_getchunk_hist", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_iCCP + {"mng_getchunk_iccp", 1, 0, 0}, +#endif + {"mng_getchunk_idat", 1, 0, 0}, + {"mng_getchunk_iend", 1, 0, 0}, + {"mng_getchunk_ihdr", 1, 0, 0}, +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG + {"mng_getchunk_ijng", 1, 0, 0}, +#endif + {"mng_getchunk_ipng", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_iTXt + {"mng_getchunk_itxt", 1, 0, 0}, +#endif +#ifdef MNG_INCLUDE_JNG + {"mng_getchunk_jdaa", 1, 0, 0}, + {"mng_getchunk_jdat", 1, 0, 0}, + {"mng_getchunk_jhdr", 1, 0, 0}, + {"mng_getchunk_jsep", 1, 0, 0}, +#endif + {"mng_getchunk_loop", 1, 0, 0}, +#ifndef MNG_SKIPCHUNK_MAGN + {"mng_getchunk_magn", 1, 0, 0}, +#endif + {"mng_getchunk_mend", 1, 0, 0}, + {"mng_getchunk_mhdr", 1, 0, 0}, + {"mng_getchunk_move", 1, 0, 0}, +#ifndef MNG_SKIPCHUNK_nEED + {"mng_getchunk_need", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_ORDR +#ifndef MNG_NO_DELTA_PNG + {"mng_getchunk_ordr", 1, 0, 0}, + {"mng_getchunk_ordr_entry", 1, 0, 0}, +#endif +#endif +#ifndef MNG_SKIPCHUNK_PAST + {"mng_getchunk_past", 1, 0, 0}, + {"mng_getchunk_past_src", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_pHYg + {"mng_getchunk_phyg", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_pHYs + {"mng_getchunk_phys", 1, 0, 0}, +#endif +#ifndef MNG_NO_DELTA_PNG + {"mng_getchunk_plte", 1, 0, 0}, + {"mng_getchunk_pplt", 1, 0, 0}, + {"mng_getchunk_pplt_entry", 1, 0, 0}, + {"mng_getchunk_prom", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_SAVE + {"mng_getchunk_save", 1, 0, 0}, + {"mng_getchunk_save_entry", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_sBIT + {"mng_getchunk_sbit", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_SEEK + {"mng_getchunk_seek", 1, 0, 0}, +#endif + {"mng_getchunk_show", 1, 0, 0}, +#ifndef MNG_SKIPCHUNK_sPLT + {"mng_getchunk_splt", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_sRGB + {"mng_getchunk_srgb", 1, 0, 0}, +#endif + {"mng_getchunk_term", 1, 0, 0}, +#ifndef MNG_SKIPCHUNK_tEXt + {"mng_getchunk_text", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_tIME + {"mng_getchunk_time", 1, 0, 0}, +#endif + {"mng_getchunk_trns", 1, 0, 0}, + {"mng_getchunk_unkown", 1, 0, 0}, +#ifndef MNG_SKIPCHUNK_zTXt + {"mng_getchunk_ztxt", 1, 0, 0}, +#endif + {"mng_getimgdata_chunk", 0, 0, 0}, + {"mng_getimgdata_chunkseq", 0, 0, 0}, + {"mng_getimgdata_seq", 0, 0, 0}, + {"mng_getlasterror", 1, 0, 0}, + {"mng_initialize", 1, 0, 0}, + {"mng_iterate_chunks", 1, 0, 0}, + {"mng_putchunk_back", 1, 0, 0}, +#ifndef MNG_SKIPCHUNK_BASI + {"mng_putchunk_basi", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_bKGD + {"mng_putchunk_bkgd", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_cHRM + {"mng_putchunk_chrm", 1, 0, 0}, +#endif + {"mng_putchunk_clip", 1, 0, 0}, + {"mng_putchunk_clon", 1, 0, 0}, +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DBYK + {"mng_putchunk_dbyk", 1, 0, 0}, +#endif +#endif + {"mng_putchunk_defi", 1, 0, 0}, +#ifndef MNG_NO_DELTA_PNG + {"mng_putchunk_dhdr", 1, 0, 0}, +#endif + {"mng_putchunk_disc", 1, 0, 0}, +#ifndef MNG_NO_DELTA_PNG + {"mng_putchunk_drop", 1, 0, 0}, +#endif + {"mng_putchunk_endl", 1, 0, 0}, +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + {"mng_putchunk_mpng", 1, 0, 10}, + {"mng_putchunk_mpng_frame", 1, 0, 10}, +#endif +#ifndef MNG_SKIPCHUNK_evNT + {"mng_putchunk_evnt", 1, 0, 5}, + {"mng_putchunk_evnt_entry", 1, 0, 5}, +#endif +#ifndef MNG_SKIPCHUNK_eXPI + {"mng_putchunk_expi", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_fPRI + {"mng_putchunk_fpri", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_FRAM + {"mng_putchunk_fram", 1, 0, 0}, +#endif + {"mng_putchunk_gama", 1, 0, 0}, +#ifndef MNG_SKIPCHUNK_hIST + {"mng_putchunk_hist", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_iCCP + {"mng_putchunk_iccp", 1, 0, 0}, +#endif + {"mng_putchunk_idat", 1, 0, 0}, + {"mng_putchunk_iend", 1, 0, 0}, + {"mng_putchunk_ihdr", 1, 0, 0}, +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG + {"mng_putchunk_ijng", 1, 0, 0}, +#endif + {"mng_putchunk_ipng", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_iTXt + {"mng_putchunk_itxt", 1, 0, 0}, +#endif +#ifdef MNG_INCLUDE_JNG + {"mng_putchunk_jdaa", 1, 0, 0}, + {"mng_putchunk_jdat", 1, 0, 0}, + {"mng_putchunk_jhdr", 1, 0, 0}, + {"mng_putchunk_jsep", 1, 0, 0}, +#endif + {"mng_putchunk_loop", 1, 0, 0}, +#ifndef MNG_SKIPCHUNK_MAGN + {"mng_putchunk_magn", 1, 0, 0}, +#endif + {"mng_putchunk_mend", 1, 0, 0}, + {"mng_putchunk_mhdr", 1, 0, 0}, + {"mng_putchunk_move", 1, 0, 0}, +#ifndef MNG_SKIPCHUNK_nEED + {"mng_putchunk_need", 1, 0, 0}, +#endif +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR + {"mng_putchunk_ordr", 1, 0, 0}, + {"mng_putchunk_ordr_entry", 1, 0, 0}, +#endif +#endif +#ifndef MNG_SKIPCHUNK_PAST + {"mng_putchunk_past", 1, 0, 0}, + {"mng_putchunk_past_src", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_pHYg + {"mng_putchunk_phyg", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_pHYs + {"mng_putchunk_phys", 1, 0, 0}, +#endif +#ifndef MNG_NO_DELTA_PNG + {"mng_putchunk_plte", 1, 0, 0}, + {"mng_putchunk_pplt", 1, 0, 0}, + {"mng_putchunk_pplt_entry", 1, 0, 0}, + {"mng_putchunk_prom", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_SAVE + {"mng_putchunk_save", 1, 0, 0}, + {"mng_putchunk_save_entry", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_sBIT + {"mng_putchunk_sbit", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_SEEK + {"mng_putchunk_seek", 1, 0, 0}, +#endif + {"mng_putchunk_show", 1, 0, 0}, +#ifndef MNG_SKIPCHUNK_sPLT + {"mng_putchunk_splt", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_sRGB + {"mng_putchunk_srgb", 1, 0, 0}, +#endif + {"mng_putchunk_term", 1, 0, 0}, +#ifndef MNG_SKIPCHUNK_tEXt + {"mng_putchunk_text", 1, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_tIME + {"mng_putchunk_time", 1, 0, 0}, +#endif + {"mng_putchunk_trns", 1, 0, 0}, + {"mng_putchunk_unkown", 1, 0, 0}, +#ifndef MNG_SKIPCHUNK_zTXt + {"mng_putchunk_ztxt", 1, 0, 0}, +#endif + {"mng_putimgdata_ihdr", 0, 0, 0}, + {"mng_putimgdata_jhdr", 0, 0, 0}, + {"mng_reset", 1, 0, 0}, + {"mng_read", 1, 0, 0}, + {"mng_read_pushchunk", 1, 0, 8}, + {"mng_read_pushdata", 1, 0, 8}, + {"mng_read_pushsig", 1, 0, 8}, + {"mng_read_resume", 1, 0, 0}, + {"mng_readdisplay", 1, 0, 0}, + {"mng_set_bgcolor", 1, 0, 0}, + {"mng_set_bkgdstyle", 1, 0, 0}, + {"mng_set_cacheplayback", 1, 0, 2}, + {"mng_set_canvasstyle", 1, 0, 0}, + {"mng_set_dfltimggamma", 1, 0, 0}, +#ifndef MNG_NO_DFLT_INFO + {"mng_set_dfltimggammaint", 1, 0, 0}, +#endif + {"mng_set_displaygamma", 1, 0, 0}, + {"mng_set_displaygammaint", 1, 0, 0}, + {"mng_set_doprogressive", 1, 0, 2}, +#ifdef MNG_ACCESS_JPEG + {"mng_set_jpeg_dctmethod", 1, 0, 0}, + {"mng_set_jpeg_maxjdat", 1, 0, 0}, + {"mng_set_jpeg_optimized", 1, 0, 0}, + {"mng_set_jpeg_progressive", 1, 0, 0}, + {"mng_set_jpeg_quality", 1, 0, 0}, + {"mng_set_jpeg_smoothing", 1, 0, 0}, +#endif +#ifndef MNG_SKIP_MAXCANVAS + {"mng_set_maxcanvasheight", 1, 0, 0}, + {"mng_set_maxcanvassize", 1, 0, 0}, + {"mng_set_maxcanvaswidth", 1, 0, 0}, +#endif + {"mng_set_outputprofile", 1, 0, 0}, + {"mng_set_outputprofile2", 1, 0, 0}, + {"mng_set_outputsrgb", 1, 0, 1}, + {"mng_set_sectionbreaks", 1, 0, 0}, + {"mng_set_speed", 1, 0, 0}, + {"mng_set_srgb", 1, 0, 0}, + {"mng_set_srgbimplicit", 1, 0, 1}, + {"mng_set_srgbprofile", 1, 0, 0}, + {"mng_set_srgbprofile2", 1, 0, 0}, + {"mng_set_storechunks", 1, 0, 0}, + {"mng_set_suspensionmode", 1, 0, 0}, + {"mng_set_usebkgd", 1, 0, 0}, + {"mng_set_userdata", 1, 0, 0}, +#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) + {"mng_set_viewgamma", 1, 0, 0}, + {"mng_set_viewgammaint", 1, 0, 0}, +#endif +#ifdef MNG_ACCESS_ZLIB + {"mng_set_zlib_level", 1, 0, 0}, + {"mng_set_zlib_maxidat", 1, 0, 0}, + {"mng_set_zlib_memlevel", 1, 0, 0}, + {"mng_set_zlib_method", 1, 0, 0}, + {"mng_set_zlib_strategy", 1, 0, 0}, + {"mng_set_zlib_windowbits", 1, 0, 0}, +#endif +#ifndef MNG_NO_OPEN_CLOSE_STREAM + {"mng_setcb_closestream", 1, 0, 0}, +#endif + {"mng_setcb_errorproc", 1, 0, 0}, + {"mng_setcb_getalphaline", 1, 0, 0}, + {"mng_setcb_getbkgdline", 1, 0, 0}, + {"mng_setcb_getcanvasline", 1, 0, 0}, + {"mng_setcb_gettickcount", 1, 0, 0}, + {"mng_setcb_memalloc", 1, 0, 0}, + {"mng_setcb_memfree", 1, 0, 0}, +#ifndef MNG_NO_OPEN_CLOSE_STREAM + {"mng_setcb_openstream", 1, 0, 0}, +#endif + {"mng_setcb_processarow", 1, 0, 0}, + {"mng_setcb_processchroma", 1, 0, 0}, + {"mng_setcb_processgamma", 1, 0, 0}, + {"mng_setcb_processheader", 1, 0, 0}, + {"mng_setcb_processiccp", 1, 0, 0}, + {"mng_setcb_processmend", 1, 0, 1}, + {"mng_setcb_processneed", 1, 0, 0}, + {"mng_setcb_processsave", 1, 0, 0}, + {"mng_setcb_processseek", 1, 0, 0}, + {"mng_setcb_processsrgb", 1, 0, 0}, + {"mng_setcb_processterm", 1, 0, 2}, + {"mng_setcb_processtext", 1, 0, 0}, + {"mng_setcb_processunknown", 1, 0, 0}, + {"mng_setcb_readdata", 1, 0, 0}, + {"mng_setcb_refresh", 1, 0, 0}, + {"mng_setcb_releasedata", 1, 0, 8}, + {"mng_setcb_settimer", 1, 0, 0}, + {"mng_setcb_traceproc", 1, 0, 0}, + {"mng_setcb_writedata", 1, 0, 0}, + {"mng_status_creating", 1, 0, 0}, + {"mng_status_displaying", 1, 0, 0}, + {"mng_status_dynamic", 1, 0, 5}, + {"mng_status_error", 1, 0, 0}, + {"mng_status_reading", 1, 0, 0}, + {"mng_status_running", 1, 0, 0}, + {"mng_status_runningevent", 1, 0, 5}, + {"mng_status_suspendbreak", 1, 0, 0}, + {"mng_status_timerbreak", 1, 0, 0}, + {"mng_status_writing", 1, 0, 0}, + {"mng_supports_func", 1, 0, 5}, + {"mng_trapevent", 1, 0, 5}, + {"mng_updatemngheader", 1, 0, 0}, + {"mng_updatemngsimplicity", 1, 0, 0}, + {"mng_version_beta", 1, 0, 5}, + {"mng_version_dll", 1, 0, 0}, + {"mng_version_major", 1, 0, 0}, + {"mng_version_minor", 1, 0, 0}, + {"mng_version_release", 1, 0, 0}, + {"mng_version_so", 1, 0, 0}, + {"mng_version_text", 1, 0, 0}, + {"mng_write", 1, 0, 0}, + }; + +mng_bool MNG_DECL mng_supports_func (mng_pchar zFunction, + mng_uint8* iMajor, + mng_uint8* iMinor, + mng_uint8* iRelease) +{ + mng_int32 iTop, iLower, iUpper, iMiddle; + mng_func_entryp pEntry; /* pointer to found entry */ + /* determine max index of table */ + iTop = (sizeof (func_table) / sizeof (func_table [0])) - 1; + + iLower = 0; /* initialize binary search */ + iMiddle = iTop >> 1; /* start in the middle */ + iUpper = iTop; + pEntry = 0; /* no goods yet! */ + + do /* the binary search itself */ + { + mng_int32 iRslt = strcmp(func_table [iMiddle].zFunction, zFunction); + if (iRslt < 0) + iLower = iMiddle + 1; + else if (iRslt > 0) + iUpper = iMiddle - 1; + else + { + pEntry = &func_table [iMiddle]; + break; + }; + + iMiddle = (iLower + iUpper) >> 1; + } + while (iLower <= iUpper); + + if (pEntry) /* found it ? */ + { + *iMajor = pEntry->iMajor; + *iMinor = pEntry->iMinor; + *iRelease = pEntry->iRelease; + return MNG_TRUE; + } + else + { + *iMajor = 0; + *iMinor = 0; + *iRelease = 0; + return MNG_FALSE; + } +} +#endif + +/* ************************************************************************** */ +/* * * */ +/* * HLAPI routines * */ +/* * * */ +/* ************************************************************************** */ + +mng_handle MNG_DECL mng_initialize (mng_ptr pUserdata, + mng_memalloc fMemalloc, + mng_memfree fMemfree, + mng_traceproc fTraceproc) +{ + mng_datap pData; +#ifdef MNG_SUPPORT_DISPLAY + mng_retcode iRetcode; + mng_imagep pImage; +#endif + +#ifdef MNG_INTERNAL_MEMMNGMT /* allocate the main datastruc */ + pData = (mng_datap)calloc (1, sizeof (mng_data)); +#else + pData = (mng_datap)fMemalloc (sizeof (mng_data)); +#endif + + if (!pData) + return MNG_NULL; /* error: out of memory?? */ + /* validate the structure */ + pData->iMagic = MNG_MAGIC; + /* save userdata field */ + pData->pUserdata = pUserdata; + /* remember trace callback */ + pData->fTraceproc = fTraceproc; + +#ifdef MNG_SUPPORT_TRACE + if (mng_trace (pData, MNG_FN_INITIALIZE, MNG_LC_INITIALIZE)) + { + MNG_FREEX (pData, pData, sizeof (mng_data)); + return MNG_NULL; + } +#endif + /* default canvas styles are 8-bit RGB */ + pData->iCanvasstyle = MNG_CANVAS_RGB8; + pData->iBkgdstyle = MNG_CANVAS_RGB8; + + pData->iBGred = 0; /* black */ + pData->iBGgreen = 0; + pData->iBGblue = 0; + + pData->bUseBKGD = MNG_TRUE; + +#ifdef MNG_FULL_CMS + pData->bIssRGB = MNG_TRUE; + pData->hProf1 = 0; /* no profiles yet */ + pData->hProf2 = 0; + pData->hProf3 = 0; + pData->hTrans = 0; +#endif + + pData->dViewgamma = 1.0; + pData->dDisplaygamma = 2.2; + pData->dDfltimggamma = 0.45455; + /* initially remember chunks */ + pData->bStorechunks = MNG_TRUE; + /* no breaks at section-borders */ + pData->bSectionbreaks = MNG_FALSE; + /* initially cache playback info */ + pData->bCacheplayback = MNG_TRUE; + /* progressive refresh for large images */ + pData->bDoProgressive = MNG_TRUE; + /* crc exists; should check; error for + critical chunks; warning for ancillery; + generate crc for output */ + pData->iCrcmode = MNG_CRC_DEFAULT; + /* normal animation-speed ! */ + pData->iSpeed = mng_st_normal; + /* initial image limits */ + pData->iMaxwidth = 10000; + pData->iMaxheight = 10000; + +#ifdef MNG_INTERNAL_MEMMNGMT /* internal management */ + pData->fMemalloc = MNG_NULL; + pData->fMemfree = MNG_NULL; +#else /* keep callbacks */ + pData->fMemalloc = fMemalloc; + pData->fMemfree = fMemfree; +#endif + /* no value (yet) */ + pData->fReleasedata = MNG_NULL; +#ifndef MNG_NO_OPEN_CLOSE_STREAM + pData->fOpenstream = MNG_NULL; + pData->fClosestream = MNG_NULL; +#endif + pData->fReaddata = MNG_NULL; + pData->fWritedata = MNG_NULL; + pData->fErrorproc = MNG_NULL; + pData->fProcessheader = MNG_NULL; + pData->fProcesstext = MNG_NULL; + pData->fProcesssave = MNG_NULL; + pData->fProcessseek = MNG_NULL; + pData->fProcessneed = MNG_NULL; + pData->fProcessmend = MNG_NULL; + pData->fProcessunknown = MNG_NULL; + pData->fProcessterm = MNG_NULL; + pData->fGetcanvasline = MNG_NULL; + pData->fGetbkgdline = MNG_NULL; + pData->fGetalphaline = MNG_NULL; + pData->fRefresh = MNG_NULL; + pData->fGettickcount = MNG_NULL; + pData->fSettimer = MNG_NULL; + pData->fProcessgamma = MNG_NULL; + pData->fProcesschroma = MNG_NULL; + pData->fProcesssrgb = MNG_NULL; + pData->fProcessiccp = MNG_NULL; + pData->fProcessarow = MNG_NULL; + +#if defined(MNG_SUPPORT_DISPLAY) && (defined(MNG_GAMMA_ONLY) || defined(MNG_FULL_CMS)) + pData->dLastgamma = 0; /* lookup table needs first-time calc */ +#endif + +#ifdef MNG_SUPPORT_DISPLAY /* create object 0 */ + iRetcode = mng_create_imageobject (pData, 0, MNG_TRUE, MNG_TRUE, MNG_TRUE, + 0, 0, 0, 0, 0, 0, 0, 0, 0, MNG_FALSE, + 0, 0, 0, 0, &pImage); + + if (iRetcode) /* on error drop out */ + { + MNG_FREEX (pData, pData, sizeof (mng_data)); + return MNG_NULL; + } + + pData->pObjzero = pImage; +#endif + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_INCLUDE_LCMS) + mnglcms_initlibrary (); /* init lcms particulars */ +#endif + +#ifdef MNG_SUPPORT_READ + pData->bSuspensionmode = MNG_FALSE; + pData->iSuspendbufsize = 0; + pData->pSuspendbuf = MNG_NULL; + pData->pSuspendbufnext = MNG_NULL; + pData->iSuspendbufleft = 0; + pData->iChunklen = 0; + pData->pReadbufnext = MNG_NULL; + pData->pLargebufnext = MNG_NULL; + + pData->pFirstpushchunk = MNG_NULL; + pData->pLastpushchunk = MNG_NULL; + pData->pFirstpushdata = MNG_NULL; + pData->pLastpushdata = MNG_NULL; +#endif + +#ifdef MNG_INCLUDE_ZLIB + mngzlib_initialize (pData); /* initialize zlib structures and such */ + /* default zlib compression parameters */ + pData->iZlevel = MNG_ZLIB_LEVEL; + pData->iZmethod = MNG_ZLIB_METHOD; + pData->iZwindowbits = MNG_ZLIB_WINDOWBITS; + pData->iZmemlevel = MNG_ZLIB_MEMLEVEL; + pData->iZstrategy = MNG_ZLIB_STRATEGY; + /* default maximum IDAT data size */ + pData->iMaxIDAT = MNG_MAX_IDAT_SIZE; +#endif + +#ifdef MNG_INCLUDE_JNG /* default IJG compression parameters */ + pData->eJPEGdctmethod = MNG_JPEG_DCT; + pData->iJPEGquality = MNG_JPEG_QUALITY; + pData->iJPEGsmoothing = MNG_JPEG_SMOOTHING; + pData->bJPEGcompressprogr = MNG_JPEG_PROGRESSIVE; + pData->bJPEGcompressopt = MNG_JPEG_OPTIMIZED; + /* default maximum JDAT data size */ + pData->iMaxJDAT = MNG_MAX_JDAT_SIZE; +#endif + + mng_reset ((mng_handle)pData); + +#ifdef MNG_SUPPORT_TRACE + if (mng_trace (pData, MNG_FN_INITIALIZE, MNG_LC_END)) + { + MNG_FREEX (pData, pData, sizeof (mng_data)); + return MNG_NULL; + } +#endif + + return (mng_handle)pData; /* if we get here, we're in business */ +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_reset (mng_handle hHandle) +{ + mng_datap pData; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_RESET, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = ((mng_datap)(hHandle)); /* address main structure */ + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_SKIPCHUNK_SAVE + mng_drop_savedata (pData); /* cleanup saved-data from SAVE/SEEK */ +#endif +#endif + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_FULL_CMS) + mng_clear_cms (pData); /* cleanup left-over cms stuff if any */ +#endif + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_INCLUDE_JNG) + mngjpeg_cleanup (pData); /* cleanup jpeg stuff */ +#endif + +#ifdef MNG_INCLUDE_ZLIB + if (pData->bInflating) /* if we've been inflating */ + { +#ifdef MNG_INCLUDE_DISPLAY_PROCS + mng_cleanup_rowproc (pData); /* cleanup row-processing, */ +#endif + mngzlib_inflatefree (pData); /* cleanup inflate! */ + } +#endif /* MNG_INCLUDE_ZLIB */ + +#ifdef MNG_SUPPORT_READ + if ((pData->bReading) && (!pData->bEOF)) + mng_process_eof (pData); /* cleanup app streaming */ + /* cleanup default read buffers */ + MNG_FREE (pData, pData->pReadbuf, pData->iReadbufsize); + MNG_FREE (pData, pData->pLargebuf, pData->iLargebufsize); + MNG_FREE (pData, pData->pSuspendbuf, pData->iSuspendbufsize); + + while (pData->pFirstpushdata) /* release any pushed data & chunks */ + mng_release_pushdata (pData); + while (pData->pFirstpushchunk) + mng_release_pushchunk (pData); +#endif + +#ifdef MNG_SUPPORT_WRITE /* cleanup default write buffer */ + MNG_FREE (pData, pData->pWritebuf, pData->iWritebufsize); +#endif + +#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) + mng_drop_chunks (pData); /* drop stored chunks (if any) */ +#endif + +#ifdef MNG_SUPPORT_DISPLAY + mng_drop_objects (pData, MNG_TRUE); /* drop stored objects (if any) */ + +#ifndef MNG_SKIPCHUNK_iCCP + if (pData->iGlobalProfilesize) /* drop global profile (if any) */ + MNG_FREEX (pData, pData->pGlobalProfile, pData->iGlobalProfilesize); +#endif +#endif + + pData->eSigtype = mng_it_unknown; + pData->eImagetype = mng_it_unknown; + pData->iWidth = 0; /* these are unknown yet */ + pData->iHeight = 0; + pData->iTicks = 0; + pData->iLayercount = 0; + pData->iFramecount = 0; + pData->iPlaytime = 0; + pData->iSimplicity = 0; + pData->iAlphadepth = 16; /* assume the worst! */ + + pData->iImagelevel = 0; /* no image encountered */ + + pData->iMagnify = 0; /* 1-to-1 display */ + pData->iOffsetx = 0; /* no offsets */ + pData->iOffsety = 0; + pData->iCanvaswidth = 0; /* let the app decide during processheader */ + pData->iCanvasheight = 0; + /* so far, so good */ + pData->iErrorcode = MNG_NOERROR; + pData->iSeverity = 0; + pData->iErrorx1 = 0; + pData->iErrorx2 = 0; + pData->zErrortext = MNG_NULL; + +#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) + /* let's assume the best scenario */ +#ifndef MNG_NO_OLD_VERSIONS + pData->bPreDraft48 = MNG_FALSE; +#endif + /* the unknown chunk */ + pData->iChunkname = MNG_UINT_HUH; + pData->iChunkseq = 0; + pData->pFirstchunk = MNG_NULL; + pData->pLastchunk = MNG_NULL; + /* nothing processed yet */ + pData->bHasheader = MNG_FALSE; + pData->bHasMHDR = MNG_FALSE; + pData->bHasIHDR = MNG_FALSE; + pData->bHasBASI = MNG_FALSE; + pData->bHasDHDR = MNG_FALSE; +#ifdef MNG_INCLUDE_JNG + pData->bHasJHDR = MNG_FALSE; + pData->bHasJSEP = MNG_FALSE; + pData->bHasJDAA = MNG_FALSE; + pData->bHasJDAT = MNG_FALSE; +#endif + pData->bHasPLTE = MNG_FALSE; + pData->bHasTRNS = MNG_FALSE; + pData->bHasGAMA = MNG_FALSE; + pData->bHasCHRM = MNG_FALSE; + pData->bHasSRGB = MNG_FALSE; + pData->bHasICCP = MNG_FALSE; + pData->bHasBKGD = MNG_FALSE; + pData->bHasIDAT = MNG_FALSE; + + pData->bHasSAVE = MNG_FALSE; + pData->bHasBACK = MNG_FALSE; + pData->bHasFRAM = MNG_FALSE; + pData->bHasTERM = MNG_FALSE; + pData->bHasLOOP = MNG_FALSE; + /* there's no global stuff yet either */ + pData->bHasglobalPLTE = MNG_FALSE; + pData->bHasglobalTRNS = MNG_FALSE; + pData->bHasglobalGAMA = MNG_FALSE; + pData->bHasglobalCHRM = MNG_FALSE; + pData->bHasglobalSRGB = MNG_FALSE; + pData->bHasglobalICCP = MNG_FALSE; + + pData->iDatawidth = 0; /* no IHDR/BASI/DHDR done yet */ + pData->iDataheight = 0; + pData->iBitdepth = 0; + pData->iColortype = 0; + pData->iCompression = 0; + pData->iFilter = 0; + pData->iInterlace = 0; + +#ifdef MNG_INCLUDE_JNG + pData->iJHDRcolortype = 0; /* no JHDR data */ + pData->iJHDRimgbitdepth = 0; + pData->iJHDRimgcompression = 0; + pData->iJHDRimginterlace = 0; + pData->iJHDRalphabitdepth = 0; + pData->iJHDRalphacompression = 0; + pData->iJHDRalphafilter = 0; + pData->iJHDRalphainterlace = 0; +#endif + +#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ + +#ifdef MNG_SUPPORT_READ /* no reading done */ + pData->bReading = MNG_FALSE; + pData->bHavesig = MNG_FALSE; + pData->bEOF = MNG_FALSE; + pData->iReadbufsize = 0; + pData->pReadbuf = MNG_NULL; + + pData->iLargebufsize = 0; + pData->pLargebuf = MNG_NULL; + + pData->iSuspendtime = 0; + pData->bSuspended = MNG_FALSE; + pData->iSuspendpoint = 0; + + pData->pSuspendbufnext = pData->pSuspendbuf; + pData->iSuspendbufleft = 0; +#endif /* MNG_SUPPORT_READ */ + +#ifdef MNG_SUPPORT_WRITE /* no creating/writing done */ + pData->bCreating = MNG_FALSE; + pData->bWriting = MNG_FALSE; + pData->iFirstchunkadded = 0; + pData->iWritebufsize = 0; + pData->pWritebuf = MNG_NULL; +#endif /* MNG_SUPPORT_WRITE */ + +#ifdef MNG_SUPPORT_DISPLAY /* done nuttin' yet */ + pData->bDisplaying = MNG_FALSE; + pData->iFrameseq = 0; + pData->iLayerseq = 0; + pData->iFrametime = 0; + + pData->iTotallayers = 0; + pData->iTotalframes = 0; + pData->iTotalplaytime = 0; + + pData->bSkipping = MNG_FALSE; + +#ifdef MNG_SUPPORT_DYNAMICMNG + pData->bDynamic = MNG_FALSE; + pData->bRunningevent = MNG_FALSE; + pData->bStopafterseek = MNG_FALSE; + pData->iEventx = 0; + pData->iEventy = 0; + pData->pLastmousemove = MNG_NULL; +#endif + + pData->iRequestframe = 0; + pData->iRequestlayer = 0; + pData->iRequesttime = 0; + pData->bSearching = MNG_FALSE; + + pData->bRestorebkgd = MNG_FALSE; + + pData->iRuntime = 0; + pData->iSynctime = 0; + pData->iStarttime = 0; + pData->iEndtime = 0; + pData->bRunning = MNG_FALSE; + pData->bTimerset = MNG_FALSE; + pData->iBreakpoint = 0; + pData->bSectionwait = MNG_FALSE; + pData->bFreezing = MNG_FALSE; + pData->bResetting = MNG_FALSE; + pData->bNeedrefresh = MNG_FALSE; + pData->bMisplacedTERM = MNG_FALSE; + pData->bOnlyfirstframe = MNG_FALSE; + pData->iFramesafterTERM = 0; + /* these don't exist yet */ + pData->pCurrentobj = MNG_NULL; + pData->pCurraniobj = MNG_NULL; + pData->pTermaniobj = MNG_NULL; + pData->pLastclone = MNG_NULL; + pData->pStoreobj = MNG_NULL; + pData->pStorebuf = MNG_NULL; + pData->pRetrieveobj = MNG_NULL; + /* no saved data ! */ + pData->pSavedata = MNG_NULL; + + pData->iUpdateleft = 0; /* no region updated yet */ + pData->iUpdateright = 0; + pData->iUpdatetop = 0; + pData->iUpdatebottom = 0; + + pData->iPass = -1; /* interlacing stuff and temp buffers */ + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = 0; + pData->iSamplemul = 0; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = 0; + pData->iRowmax = 0; + pData->iFilterofs = 0; + pData->iPixelofs = 1; + pData->iLevel0 = 0; + pData->iLevel1 = 0; + pData->iLevel2 = 0; + pData->iLevel3 = 0; + pData->pWorkrow = MNG_NULL; + pData->pPrevrow = MNG_NULL; + pData->pRGBArow = MNG_NULL; + pData->bIsRGBA16 = MNG_TRUE; + pData->bIsOpaque = MNG_TRUE; + pData->iFilterbpp = 1; + + pData->iSourcel = 0; /* always initialized just before */ + pData->iSourcer = 0; /* compositing the next layer */ + pData->iSourcet = 0; + pData->iSourceb = 0; + pData->iDestl = 0; + pData->iDestr = 0; + pData->iDestt = 0; + pData->iDestb = 0; + /* lists are empty */ + pData->pFirstimgobj = MNG_NULL; + pData->pLastimgobj = MNG_NULL; + pData->pFirstaniobj = MNG_NULL; + pData->pLastaniobj = MNG_NULL; +#ifdef MNG_SUPPORT_DYNAMICMNG + pData->pFirstevent = MNG_NULL; + pData->pLastevent = MNG_NULL; +#endif + /* no processing callbacks */ + pData->fDisplayrow = MNG_NULL; + pData->fRestbkgdrow = MNG_NULL; + pData->fCorrectrow = MNG_NULL; + pData->fRetrieverow = MNG_NULL; + pData->fStorerow = MNG_NULL; + pData->fProcessrow = MNG_NULL; + pData->fDifferrow = MNG_NULL; + pData->fScalerow = MNG_NULL; + pData->fDeltarow = MNG_NULL; +#ifndef MNG_SKIPCHUNK_PAST + pData->fFliprow = MNG_NULL; + pData->fTilerow = MNG_NULL; +#endif + pData->fInitrowproc = MNG_NULL; + + pData->iPLTEcount = 0; /* no PLTE data */ + +#ifndef MNG_SKIPCHUNK_DEFI + pData->iDEFIobjectid = 0; /* no DEFI data */ + pData->bDEFIhasdonotshow = MNG_FALSE; + pData->iDEFIdonotshow = 0; + pData->bDEFIhasconcrete = MNG_FALSE; + pData->iDEFIconcrete = 0; + pData->bDEFIhasloca = MNG_FALSE; + pData->iDEFIlocax = 0; + pData->iDEFIlocay = 0; + pData->bDEFIhasclip = MNG_FALSE; + pData->iDEFIclipl = 0; + pData->iDEFIclipr = 0; + pData->iDEFIclipt = 0; + pData->iDEFIclipb = 0; +#endif + +#ifndef MNG_SKIPCHUNK_BACK + pData->iBACKred = 0; /* no BACK data */ + pData->iBACKgreen = 0; + pData->iBACKblue = 0; + pData->iBACKmandatory = 0; + pData->iBACKimageid = 0; + pData->iBACKtile = 0; +#endif + +#ifndef MNG_SKIPCHUNK_FRAM + pData->iFRAMmode = 1; /* default global FRAM variables */ + pData->iFRAMdelay = 1; + pData->iFRAMtimeout = 0x7fffffffl; + pData->bFRAMclipping = MNG_FALSE; + pData->iFRAMclipl = 0; + pData->iFRAMclipr = 0; + pData->iFRAMclipt = 0; + pData->iFRAMclipb = 0; + + pData->iFramemode = 1; /* again for the current frame */ + pData->iFramedelay = 1; + pData->iFrametimeout = 0x7fffffffl; + pData->bFrameclipping = MNG_FALSE; + pData->iFrameclipl = 0; + pData->iFrameclipr = 0; + pData->iFrameclipt = 0; + pData->iFrameclipb = 0; + + pData->iNextdelay = 1; +#endif + +#ifndef MNG_SKIPCHUNK_SHOW + pData->iSHOWmode = 0; /* no SHOW data */ + pData->iSHOWfromid = 0; + pData->iSHOWtoid = 0; + pData->iSHOWnextid = 0; + pData->iSHOWskip = 0; +#endif + + pData->iGlobalPLTEcount = 0; /* no global PLTE data */ + + pData->iGlobalTRNSrawlen = 0; /* no global tRNS data */ + + pData->iGlobalGamma = 0; /* no global gAMA data */ + +#ifndef MNG_SKIPCHUNK_cHRM + pData->iGlobalWhitepointx = 0; /* no global cHRM data */ + pData->iGlobalWhitepointy = 0; + pData->iGlobalPrimaryredx = 0; + pData->iGlobalPrimaryredy = 0; + pData->iGlobalPrimarygreenx = 0; + pData->iGlobalPrimarygreeny = 0; + pData->iGlobalPrimarybluex = 0; + pData->iGlobalPrimarybluey = 0; +#endif + + pData->iGlobalRendintent = 0; /* no global sRGB data */ + +#ifndef MNG_SKIPCHUNK_iCCP + pData->iGlobalProfilesize = 0; /* no global iCCP data */ + pData->pGlobalProfile = MNG_NULL; +#endif + +#ifndef MNG_SKIPCHUNK_bKGD + pData->iGlobalBKGDred = 0; /* no global bKGD data */ + pData->iGlobalBKGDgreen = 0; + pData->iGlobalBKGDblue = 0; +#endif + /* no delta-image */ +#ifndef MNG_NO_DELTA_PNG + pData->pDeltaImage = MNG_NULL; + pData->iDeltaImagetype = 0; + pData->iDeltatype = 0; + pData->iDeltaBlockwidth = 0; + pData->iDeltaBlockheight = 0; + pData->iDeltaBlockx = 0; + pData->iDeltaBlocky = 0; + pData->bDeltaimmediate = MNG_FALSE; + + pData->fDeltagetrow = MNG_NULL; + pData->fDeltaaddrow = MNG_NULL; + pData->fDeltareplacerow = MNG_NULL; + pData->fDeltaputrow = MNG_NULL; + + pData->fPromoterow = MNG_NULL; + pData->fPromBitdepth = MNG_NULL; + pData->pPromBuf = MNG_NULL; + pData->iPromColortype = 0; + pData->iPromBitdepth = 0; + pData->iPromFilltype = 0; + pData->iPromWidth = 0; + pData->pPromSrc = MNG_NULL; + pData->pPromDst = MNG_NULL; +#endif + +#ifndef MNG_SKIPCHUNK_MAGN + pData->iMAGNfromid = 0; + pData->iMAGNtoid = 0; +#endif + +#ifndef MNG_SKIPCHUNK_PAST + pData->iPastx = 0; + pData->iPasty = 0; +#endif + + pData->pLastseek = MNG_NULL; +#endif + +#ifdef MNG_INCLUDE_ZLIB + pData->bInflating = 0; /* no inflating or deflating */ + pData->bDeflating = 0; /* going on at the moment */ +#endif + +#ifdef MNG_SUPPORT_DISPLAY /* reset object 0 */ + mng_reset_objzero (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_RESET, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_cleanup (mng_handle* hHandle) +{ + mng_datap pData; /* local vars */ +#ifndef MNG_INTERNAL_MEMMNGMT + mng_memfree fFree; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)*hHandle), MNG_FN_CLEANUP, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (*hHandle) /* check validity handle */ + pData = ((mng_datap)(*hHandle)); /* and address main structure */ + + mng_reset (*hHandle); /* do an implicit reset to cleanup most stuff */ + +#ifdef MNG_SUPPORT_DISPLAY /* drop object 0 */ + mng_free_imageobject (pData, (mng_imagep)pData->pObjzero); +#endif + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_FULL_CMS) + if (pData->hProf2) /* output profile defined ? */ + mnglcms_freeprofile (pData->hProf2); + + if (pData->hProf3) /* sRGB profile defined ? */ + mnglcms_freeprofile (pData->hProf3); +#endif + +#ifdef MNG_INCLUDE_ZLIB + mngzlib_cleanup (pData); /* cleanup zlib stuff */ +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)*hHandle), MNG_FN_CLEANUP, MNG_LC_CLEANUP) +#endif + + pData->iMagic = 0; /* invalidate the actual memory */ + +#ifdef MNG_INTERNAL_MEMMNGMT + free ((void *)*hHandle); /* cleanup the data-structure */ +#else + fFree = ((mng_datap)*hHandle)->fMemfree; + fFree ((mng_ptr)*hHandle, sizeof (mng_data)); +#endif + + *hHandle = 0; /* wipe pointer to inhibit future use */ + + return MNG_NOERROR; /* and we're done */ +} + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_retcode MNG_DECL mng_read (mng_handle hHandle) +{ + mng_datap pData; /* local vars */ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + +#ifndef MNG_INTERNAL_MEMMNGMT + MNG_VALIDCB (hHandle, fMemalloc) + MNG_VALIDCB (hHandle, fMemfree) +#endif + +#ifndef MNG_NO_OPEN_CLOSE_STREAM + MNG_VALIDCB (hHandle, fOpenstream) + MNG_VALIDCB (hHandle, fClosestream) +#endif + MNG_VALIDCB (hHandle, fReaddata) + +#ifdef MNG_SUPPORT_DISPLAY /* valid at this point ? */ + if ((pData->bReading) || (pData->bDisplaying)) +#else + if (pData->bReading) +#endif + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + +#ifdef MNG_SUPPORT_WRITE + if ((pData->bWriting) || (pData->bCreating)) + MNG_ERROR (pData, MNG_FUNCTIONINVALID); +#endif + + if (!pData->bCacheplayback) /* must store playback info to work!! */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + cleanup_errors (pData); /* cleanup previous errors */ + + pData->bReading = MNG_TRUE; /* read only! */ + +#ifndef MNG_NO_OPEN_CLOSE_STREAM + if (pData->fOpenstream && !pData->fOpenstream (hHandle)) + /* open it and start reading */ + iRetcode = MNG_APPIOERROR; + else +#endif + iRetcode = mng_read_graphic (pData); + + if (pData->bEOF) /* already at EOF ? */ + { + pData->bReading = MNG_FALSE; /* then we're no longer reading */ + +#ifdef MNG_SUPPORT_DISPLAY + mng_reset_rundata (pData); /* reset rundata */ +#endif + } + + if (iRetcode) /* on error bail out */ + return iRetcode; + + if (pData->bSuspended) /* read suspension ? */ + { + iRetcode = MNG_NEEDMOREDATA; + pData->iSuspendtime = pData->fGettickcount ((mng_handle)pData); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ, MNG_LC_END); +#endif + + return iRetcode; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_retcode MNG_DECL mng_read_pushdata (mng_handle hHandle, + mng_ptr pData, + mng_size_t iLength, + mng_bool bTakeownership) +{ + mng_datap pMyData; /* local vars */ + mng_pushdatap pPush; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHDATA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pMyData = ((mng_datap)hHandle); /* and make it addressable */ + /* create a containing buffer */ + iRetcode = make_pushbuffer (pMyData, pData, iLength, bTakeownership, &pPush); + if (iRetcode) + return iRetcode; + + if (pMyData->pLastpushdata) /* and update the buffer chain */ + pMyData->pLastpushdata->pNext = pPush; + else + pMyData->pFirstpushdata = pPush; + + pMyData->pLastpushdata = pPush; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHDATA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_retcode MNG_DECL mng_read_pushsig (mng_handle hHandle, + mng_imgtype eSigtype) +{ + mng_datap pData; /* local vars */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHSIG, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + + if (pData->bHavesig) /* can we expect this call ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + pData->eSigtype = eSigtype; + pData->bHavesig = MNG_TRUE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHSIG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_retcode MNG_DECL mng_read_pushchunk (mng_handle hHandle, + mng_ptr pChunk, + mng_size_t iLength, + mng_bool bTakeownership) +{ + mng_datap pMyData; /* local vars */ + mng_pushdatap pPush; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHCHUNK, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pMyData = ((mng_datap)hHandle); /* and make it addressable */ + /* create a containing buffer */ + iRetcode = make_pushbuffer (pMyData, pChunk, iLength, bTakeownership, &pPush); + if (iRetcode) + return iRetcode; + + if (pMyData->pLastpushchunk) /* and update the buffer chain */ + pMyData->pLastpushchunk->pNext = pPush; + else + pMyData->pFirstpushchunk = pPush; + + pMyData->pLastpushchunk = pPush; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHCHUNK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_retcode MNG_DECL mng_read_resume (mng_handle hHandle) +{ + mng_datap pData; /* local vars */ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_RESUME, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + /* can we expect this call ? */ + if ((!pData->bReading) || (!pData->bSuspended)) + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + cleanup_errors (pData); /* cleanup previous errors */ + + pData->bSuspended = MNG_FALSE; /* reset the flag */ + +#ifdef MNG_SUPPORT_DISPLAY /* re-synchronize ? */ + if ((pData->bDisplaying) && (pData->bRunning)) + pData->iSynctime = pData->iSynctime - pData->iSuspendtime + + pData->fGettickcount (hHandle); +#endif + + iRetcode = mng_read_graphic (pData); /* continue reading now */ + + if (pData->bEOF) /* at EOF ? */ + { + pData->bReading = MNG_FALSE; /* then we're no longer reading */ + +#ifdef MNG_SUPPORT_DISPLAY + mng_reset_rundata (pData); /* reset rundata */ +#endif + } + + if (iRetcode) /* on error bail out */ + return iRetcode; + + if (pData->bSuspended) /* read suspension ? */ + { + iRetcode = MNG_NEEDMOREDATA; + pData->iSuspendtime = pData->fGettickcount ((mng_handle)pData); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_RESUME, MNG_LC_END); +#endif + + return iRetcode; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_write (mng_handle hHandle) +{ + mng_datap pData; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_WRITE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + +#ifndef MNG_INTERNAL_MEMMNGMT + MNG_VALIDCB (hHandle, fMemalloc) + MNG_VALIDCB (hHandle, fMemfree) +#endif + +#ifndef MNG_NO_OPEN_CLOSE_STREAM + MNG_VALIDCB (hHandle, fOpenstream) + MNG_VALIDCB (hHandle, fClosestream) +#endif + MNG_VALIDCB (hHandle, fWritedata) + +#ifdef MNG_SUPPORT_READ + if (pData->bReading) /* valid at this point ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID); +#endif + + cleanup_errors (pData); /* cleanup previous errors */ + + iRetcode = mng_write_graphic (pData);/* do the write */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_WRITE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_create (mng_handle hHandle) +{ + mng_datap pData; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_CREATE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + +#ifndef MNG_INTERNAL_MEMMNGMT + MNG_VALIDCB (hHandle, fMemalloc) + MNG_VALIDCB (hHandle, fMemfree) +#endif + +#ifdef MNG_SUPPORT_READ + if (pData->bReading) /* valid at this point ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID); +#endif + + if ((pData->bWriting) || (pData->bCreating)) + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + cleanup_errors (pData); /* cleanup previous errors */ + + iRetcode = mng_reset (hHandle); /* clear any previous stuff */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + + pData->bCreating = MNG_TRUE; /* indicate we're creating a new file */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_CREATE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_SUPPORT_READ) +mng_retcode MNG_DECL mng_readdisplay (mng_handle hHandle) +{ + mng_datap pData; /* local vars */ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_READDISPLAY, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + +#ifndef MNG_INTERNAL_MEMMNGMT + MNG_VALIDCB (hHandle, fMemalloc) + MNG_VALIDCB (hHandle, fMemfree) +#endif + + MNG_VALIDCB (hHandle, fReaddata) + MNG_VALIDCB (hHandle, fGetcanvasline) + MNG_VALIDCB (hHandle, fRefresh) + MNG_VALIDCB (hHandle, fGettickcount) + MNG_VALIDCB (hHandle, fSettimer) + /* valid at this point ? */ + if ((pData->bReading) || (pData->bDisplaying)) + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + +#ifdef MNG_SUPPORT_WRITE + if ((pData->bWriting) || (pData->bCreating)) + MNG_ERROR (pData, MNG_FUNCTIONINVALID); +#endif + + cleanup_errors (pData); /* cleanup previous errors */ + + pData->bReading = MNG_TRUE; /* read & display! */ + pData->bDisplaying = MNG_TRUE; + pData->bRunning = MNG_TRUE; + pData->iFrameseq = 0; + pData->iLayerseq = 0; + pData->iFrametime = 0; + pData->iRequestframe = 0; + pData->iRequestlayer = 0; + pData->iRequesttime = 0; + pData->bSearching = MNG_FALSE; + pData->iRuntime = 0; + pData->iSynctime = pData->fGettickcount (hHandle); + pData->iSuspendtime = 0; + pData->iStarttime = pData->iSynctime; + pData->iEndtime = 0; + +#ifndef MNG_NO_OPEN_CLOSE_STREAM + if (pData->fOpenstream && !pData->fOpenstream (hHandle)) + /* open it and start reading */ + iRetcode = MNG_APPIOERROR; + else +#endif + iRetcode = mng_read_graphic (pData); + + if (pData->bEOF) /* already at EOF ? */ + { + pData->bReading = MNG_FALSE; /* then we're no longer reading */ + mng_drop_invalid_objects (pData); /* drop invalidly stored objects */ + } + + if (iRetcode) /* on error bail out */ + return iRetcode; + + if (pData->bSuspended) /* read suspension ? */ + { + iRetcode = MNG_NEEDMOREDATA; + pData->iSuspendtime = pData->fGettickcount ((mng_handle)pData); + } + else + if (pData->bTimerset) /* indicate timer break ? */ + iRetcode = MNG_NEEDTIMERWAIT; + else + if (pData->bSectionwait) /* indicate section break ? */ + iRetcode = MNG_NEEDSECTIONWAIT; + else + { /* no breaks = end of run */ + pData->bRunning = MNG_FALSE; + + if (pData->bFreezing) /* dynamic MNG reached SEEK ? */ + pData->bFreezing = MNG_FALSE; /* reset it ! */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_READDISPLAY, MNG_LC_END); +#endif + + return iRetcode; +} +#endif /* MNG_SUPPORT_DISPLAY && MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_display (mng_handle hHandle) +{ + mng_datap pData; /* local vars */ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + +#ifndef MNG_INTERNAL_MEMMNGMT + MNG_VALIDCB (hHandle, fMemalloc) + MNG_VALIDCB (hHandle, fMemfree) +#endif + + MNG_VALIDCB (hHandle, fGetcanvasline) + MNG_VALIDCB (hHandle, fRefresh) + MNG_VALIDCB (hHandle, fGettickcount) + MNG_VALIDCB (hHandle, fSettimer) + + if (pData->bDisplaying) /* valid at this point ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + +#ifdef MNG_SUPPORT_READ + if (pData->bReading) + MNG_ERROR (pData, MNG_FUNCTIONINVALID); +#endif + +#ifdef MNG_SUPPORT_WRITE + if ((pData->bWriting) || (pData->bCreating)) + MNG_ERROR (pData, MNG_FUNCTIONINVALID); +#endif + + cleanup_errors (pData); /* cleanup previous errors */ + + pData->bDisplaying = MNG_TRUE; /* display! */ + pData->bRunning = MNG_TRUE; + pData->iFrameseq = 0; + pData->iLayerseq = 0; + pData->iFrametime = 0; + pData->iRequestframe = 0; + pData->iRequestlayer = 0; + pData->iRequesttime = 0; + pData->bSearching = MNG_FALSE; + pData->iRuntime = 0; + pData->iSynctime = pData->fGettickcount (hHandle); +#ifdef MNG_SUPPORT_READ + pData->iSuspendtime = 0; +#endif + pData->iStarttime = pData->iSynctime; + pData->iEndtime = 0; + pData->pCurraniobj = pData->pFirstaniobj; + /* go do it */ + iRetcode = mng_process_display (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + if (pData->bTimerset) /* indicate timer break ? */ + iRetcode = MNG_NEEDTIMERWAIT; + else + { /* no breaks = end of run */ + pData->bRunning = MNG_FALSE; + + if (pData->bFreezing) /* dynamic MNG reached SEEK ? */ + pData->bFreezing = MNG_FALSE; /* reset it ! */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY, MNG_LC_END); +#endif + + return iRetcode; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_display_resume (mng_handle hHandle) +{ + mng_datap pData; /* local vars */ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_RESUME, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + + if (!pData->bDisplaying) /* can we expect this call ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + cleanup_errors (pData); /* cleanup previous errors */ + /* was it running ? */ + if ((pData->bRunning) || (pData->bReading)) + { /* are we expecting this call ? */ + if ((pData->bTimerset) || (pData->bSuspended) || (pData->bSectionwait)) + { + pData->bTimerset = MNG_FALSE; /* reset the flags */ + pData->bSectionwait = MNG_FALSE; + +#ifdef MNG_SUPPORT_READ + if (pData->bReading) /* set during read&display ? */ + { + if (pData->bSuspended) /* calculate proper synchronization */ + pData->iSynctime = pData->iSynctime - pData->iSuspendtime + + pData->fGettickcount (hHandle); + else + pData->iSynctime = pData->fGettickcount (hHandle); + + pData->bSuspended = MNG_FALSE; /* now reset this flag */ + /* and continue reading */ + iRetcode = mng_read_graphic (pData); + + if (pData->bEOF) /* already at EOF ? */ + { + pData->bReading = MNG_FALSE; /* then we're no longer reading */ + /* drop invalidly stored objects */ + mng_drop_invalid_objects (pData); + } + } + else +#endif /* MNG_SUPPORT_READ */ + { /* synchronize timing */ + pData->iSynctime = pData->fGettickcount (hHandle); + /* resume display processing */ + iRetcode = mng_process_display (pData); + } + } + else + { + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + } + } + else + { /* synchronize timing */ + pData->iSynctime = pData->fGettickcount (hHandle); + pData->bRunning = MNG_TRUE; /* it's restarted again ! */ + /* resume display processing */ + iRetcode = mng_process_display (pData); + } + + if (iRetcode) /* on error bail out */ + return iRetcode; + + if (pData->bSuspended) /* read suspension ? */ + { + iRetcode = MNG_NEEDMOREDATA; + pData->iSuspendtime = pData->fGettickcount ((mng_handle)pData); + } + else + if (pData->bTimerset) /* indicate timer break ? */ + iRetcode = MNG_NEEDTIMERWAIT; + else + if (pData->bSectionwait) /* indicate section break ? */ + iRetcode = MNG_NEEDSECTIONWAIT; + else + { /* no breaks = end of run */ + pData->bRunning = MNG_FALSE; + + if (pData->bFreezing) /* trying to freeze ? */ + pData->bFreezing = MNG_FALSE; /* then we're there */ + + if (pData->bResetting) /* trying to reset as well ? */ + { /* full stop!!! */ + pData->bDisplaying = MNG_FALSE; + + iRetcode = mng_reset_rundata (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_RESUME, MNG_LC_END); +#endif + + return iRetcode; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_display_freeze (mng_handle hHandle) +{ + mng_datap pData; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_FREEZE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + /* can we expect this call ? */ + if ((!pData->bDisplaying) || (pData->bReading)) + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + cleanup_errors (pData); /* cleanup previous errors */ + + if (pData->bRunning) /* is it running ? */ + { + mng_retcode iRetcode; + + pData->bFreezing = MNG_TRUE; /* indicate we need to freeze */ + /* continue "normal" processing */ + iRetcode = mng_display_resume (hHandle); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_FREEZE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_display_reset (mng_handle hHandle) +{ + mng_datap pData; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_RESET, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + /* can we expect this call ? */ + if ((!pData->bDisplaying) || (pData->bReading)) + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + if (!pData->bCacheplayback) /* must store playback info to work!! */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + cleanup_errors (pData); /* cleanup previous errors */ + + if (pData->bRunning) /* is it running ? */ + { + pData->bFreezing = MNG_TRUE; /* indicate we need to freeze */ + pData->bResetting = MNG_TRUE; /* indicate we're about to reset too */ + /* continue normal processing ? */ + iRetcode = mng_display_resume (hHandle); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + else + { /* full stop!!! */ + pData->bDisplaying = MNG_FALSE; + + iRetcode = mng_reset_rundata (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_RESET, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_NO_DISPLAY_GO_SUPPORTED +mng_retcode MNG_DECL mng_display_goframe (mng_handle hHandle, + mng_uint32 iFramenr) +{ + mng_datap pData; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOFRAME, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + + if (pData->eImagetype != mng_it_mng) /* is it an animation ? */ + MNG_ERROR (pData, MNG_NOTANANIMATION); + /* can we expect this call ? */ + if ((!pData->bDisplaying) || (pData->bRunning)) + MNG_ERROR ((mng_datap)hHandle, MNG_FUNCTIONINVALID); + + if (!pData->bCacheplayback) /* must store playback info to work!! */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + if (iFramenr > pData->iTotalframes) /* is the parameter within bounds ? */ + MNG_ERROR (pData, MNG_FRAMENRTOOHIGH); + /* within MHDR bounds ? */ + if ((pData->iFramecount) && (iFramenr > pData->iFramecount)) + MNG_WARNING (pData, MNG_FRAMENRTOOHIGH); + + cleanup_errors (pData); /* cleanup previous errors */ + + if (pData->iFrameseq > iFramenr) /* search from current or go back to start ? */ + { + iRetcode = mng_reset_rundata (pData); + if (iRetcode) /* on error bail out */ + return iRetcode; + } + + if (iFramenr) + { + pData->iRequestframe = iFramenr; /* go find the requested frame then */ + iRetcode = mng_process_display (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + pData->bTimerset = MNG_FALSE; /* reset just to be safe */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOFRAME, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_NO_DISPLAY_GO_SUPPORTED +mng_retcode MNG_DECL mng_display_golayer (mng_handle hHandle, + mng_uint32 iLayernr) +{ + mng_datap pData; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOLAYER, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + + if (pData->eImagetype != mng_it_mng) /* is it an animation ? */ + MNG_ERROR (pData, MNG_NOTANANIMATION); + /* can we expect this call ? */ + if ((!pData->bDisplaying) || (pData->bRunning)) + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + if (!pData->bCacheplayback) /* must store playback info to work!! */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + if (iLayernr > pData->iTotallayers) /* is the parameter within bounds ? */ + MNG_ERROR (pData, MNG_LAYERNRTOOHIGH); + /* within MHDR bounds ? */ + if ((pData->iLayercount) && (iLayernr > pData->iLayercount)) + MNG_WARNING (pData, MNG_LAYERNRTOOHIGH); + + cleanup_errors (pData); /* cleanup previous errors */ + + if (pData->iLayerseq > iLayernr) /* search from current or go back to start ? */ + { + iRetcode = mng_reset_rundata (pData); + if (iRetcode) /* on error bail out */ + return iRetcode; + } + + if (iLayernr) + { + pData->iRequestlayer = iLayernr; /* go find the requested layer then */ + iRetcode = mng_process_display (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + pData->bTimerset = MNG_FALSE; /* reset just to be safe */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOLAYER, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_NO_DISPLAY_GO_SUPPORTED +mng_retcode MNG_DECL mng_display_gotime (mng_handle hHandle, + mng_uint32 iPlaytime) +{ + mng_datap pData; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOTIME, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + + if (pData->eImagetype != mng_it_mng) /* is it an animation ? */ + MNG_ERROR (pData, MNG_NOTANANIMATION); + /* can we expect this call ? */ + if ((!pData->bDisplaying) || (pData->bRunning)) + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + if (!pData->bCacheplayback) /* must store playback info to work!! */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + /* is the parameter within bounds ? */ + if (iPlaytime > pData->iTotalplaytime) + MNG_ERROR (pData, MNG_PLAYTIMETOOHIGH); + /* within MHDR bounds ? */ + if ((pData->iPlaytime) && (iPlaytime > pData->iPlaytime)) + MNG_WARNING (pData, MNG_PLAYTIMETOOHIGH); + + cleanup_errors (pData); /* cleanup previous errors */ + + if (pData->iFrametime > iPlaytime) /* search from current or go back to start ? */ + { + iRetcode = mng_reset_rundata (pData); + if (iRetcode) /* on error bail out */ + return iRetcode; + } + + if (iPlaytime) + { + pData->iRequesttime = iPlaytime; /* go find the requested playtime then */ + iRetcode = mng_process_display (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + pData->bTimerset = MNG_FALSE; /* reset just to be safe */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOTIME, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_SUPPORT_DYNAMICMNG) +mng_retcode MNG_DECL mng_trapevent (mng_handle hHandle, + mng_uint8 iEventtype, + mng_int32 iX, + mng_int32 iY) +{ + mng_datap pData; + mng_eventp pEvent; + mng_bool bFound = MNG_FALSE; + mng_retcode iRetcode; + mng_imagep pImage; + mng_uint8p pPixel; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_TRAPEVENT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + + if (pData->eImagetype != mng_it_mng) /* is it an animation ? */ + MNG_ERROR (pData, MNG_NOTANANIMATION); + + if (!pData->bDisplaying) /* can we expect this call ? */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + if (!pData->bCacheplayback) /* must store playback info to work!! */ + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + /* let's find a matching event object */ + pEvent = (mng_eventp)pData->pFirstevent; + + while ((pEvent) && (!bFound)) + { /* matching eventtype ? */ + if (pEvent->iEventtype == iEventtype) + { + switch (pEvent->iMasktype) /* check X/Y on basis of masktype */ + { + case MNG_MASK_NONE : /* no mask is easy */ + { + bFound = MNG_TRUE; + break; + } + + case MNG_MASK_BOX : /* inside the given box ? */ + { /* right- and bottom-border don't count ! */ + if ((iX >= pEvent->iLeft) && (iX < pEvent->iRight) && + (iY >= pEvent->iTop) && (iY < pEvent->iBottom)) + bFound = MNG_TRUE; + break; + } + + case MNG_MASK_OBJECT : /* non-zero pixel in the image object ? */ + { + pImage = mng_find_imageobject (pData, pEvent->iObjectid); + /* valid image ? */ + if ((pImage) && (pImage->pImgbuf->iBitdepth <= 8) && + ((pImage->pImgbuf->iColortype == 0) || (pImage->pImgbuf->iColortype == 3)) && + ((mng_int32)pImage->pImgbuf->iWidth > iX) && + ((mng_int32)pImage->pImgbuf->iHeight > iY)) + { + pPixel = pImage->pImgbuf->pImgdata + ((pImage->pImgbuf->iWidth * iY) + iX); + + if (*pPixel) /* non-zero ? */ + bFound = MNG_TRUE; + } + + break; + } + + case MNG_MASK_OBJECTIX : /* pixel in the image object matches index ? */ + { + pImage = mng_find_imageobject (pData, pEvent->iObjectid); + /* valid image ? */ + if ((pImage) && (pImage->pImgbuf->iBitdepth <= 8) && + ((pImage->pImgbuf->iColortype == 0) || (pImage->pImgbuf->iColortype == 3)) && + ((mng_int32)pImage->pImgbuf->iWidth > iX) && (iX >= 0) && + ((mng_int32)pImage->pImgbuf->iHeight > iY) && (iY >= 0)) + { + pPixel = pImage->pImgbuf->pImgdata + ((pImage->pImgbuf->iWidth * iY) + iX); + /* matching index ? */ + if (*pPixel == pEvent->iIndex) + bFound = MNG_TRUE; + } + + break; + } + + case MNG_MASK_BOXOBJECT : /* non-zero pixel in the image object ? */ + { + mng_int32 iTempx = iX - pEvent->iLeft; + mng_int32 iTempy = iY - pEvent->iTop; + + pImage = mng_find_imageobject (pData, pEvent->iObjectid); + /* valid image ? */ + if ((pImage) && (pImage->pImgbuf->iBitdepth <= 8) && + ((pImage->pImgbuf->iColortype == 0) || (pImage->pImgbuf->iColortype == 3)) && + (iTempx < (mng_int32)pImage->pImgbuf->iWidth) && + (iTempx >= 0) && (iX < pEvent->iRight) && + (iTempy < (mng_int32)pImage->pImgbuf->iHeight) && + (iTempy >= 0) && (iY < pEvent->iBottom)) + { + pPixel = pImage->pImgbuf->pImgdata + ((pImage->pImgbuf->iWidth * iTempy) + iTempx); + + if (*pPixel) /* non-zero ? */ + bFound = MNG_TRUE; + } + + break; + } + + case MNG_MASK_BOXOBJECTIX : /* pixel in the image object matches index ? */ + { + mng_int32 iTempx = iX - pEvent->iLeft; + mng_int32 iTempy = iY - pEvent->iTop; + + pImage = mng_find_imageobject (pData, pEvent->iObjectid); + /* valid image ? */ + if ((pImage) && (pImage->pImgbuf->iBitdepth <= 8) && + ((pImage->pImgbuf->iColortype == 0) || (pImage->pImgbuf->iColortype == 3)) && + (iTempx < (mng_int32)pImage->pImgbuf->iWidth) && + (iTempx >= 0) && (iX < pEvent->iRight) && + (iTempy < (mng_int32)pImage->pImgbuf->iHeight) && + (iTempy >= 0) && (iY < pEvent->iBottom)) + { + pPixel = pImage->pImgbuf->pImgdata + ((pImage->pImgbuf->iWidth * iTempy) + iTempx); + /* matching index ? */ + if (*pPixel == pEvent->iIndex) + bFound = MNG_TRUE; + } + + break; + } + + } + } + + if (!bFound) /* try the next one */ + pEvent = (mng_eventp)pEvent->sHeader.pNext; + } + /* found one that's not the last mousemove ? */ + if ((pEvent) && ((mng_objectp)pEvent != pData->pLastmousemove)) + { /* can we start an event process now ? */ + if ((!pData->bReading) && (!pData->bRunning)) + { + pData->iEventx = iX; /* save coordinates */ + pData->iEventy = iY; + /* do it then ! */ + iRetcode = pEvent->sHeader.fProcess (pData, pEvent); + + if (iRetcode) /* on error bail out */ + return iRetcode; + /* remember last mousemove event */ + if (pEvent->iEventtype == MNG_EVENT_MOUSEMOVE) + pData->pLastmousemove = (mng_objectp)pEvent; + else + pData->pLastmousemove = MNG_NULL; + } + else + { + + /* TODO: store unprocessed events or not ??? */ + + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_TRAPEVENT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_getlasterror (mng_handle hHandle, + mng_int8* iSeverity, + mng_chunkid* iChunkname, + mng_uint32* iChunkseq, + mng_int32* iExtra1, + mng_int32* iExtra2, + mng_pchar* zErrortext) +{ + mng_datap pData; /* local vars */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETLASTERROR, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) /* check validity handle */ + pData = ((mng_datap)hHandle); /* and make it addressable */ + + *iSeverity = pData->iSeverity; /* return the appropriate fields */ + +#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) + *iChunkname = pData->iChunkname; + *iChunkseq = pData->iChunkseq; +#else + *iChunkname = MNG_UINT_HUH; + *iChunkseq = 0; +#endif + + *iExtra1 = pData->iErrorx1; + *iExtra2 = pData->iErrorx2; + *zErrortext = pData->zErrortext; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETLASTERROR, MNG_LC_END); +#endif + + return pData->iErrorcode; /* and the errorcode */ +} + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + + diff --git a/Source/LibMNG/libmng_jpeg.c b/Source/LibMNG/libmng_jpeg.c index 409f6df..5042e1d 100644 --- a/Source/LibMNG/libmng_jpeg.c +++ b/Source/LibMNG/libmng_jpeg.c @@ -1,1088 +1,1088 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_jpeg.c copyright (c) 2000-2004 G.Juyn * */ -/* * version : 1.0.9 * */ -/* * * */ -/* * purpose : JPEG library interface (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the JPEG library interface * */ -/* * * */ -/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - changed strict-ANSI stuff * */ -/* * * */ -/* * 0.5.2 - 05/22/2000 - G.Juyn * */ -/* * - implemented all the JNG routines * */ -/* * * */ -/* * 0.5.3 - 06/17/2000 - G.Juyn * */ -/* * - added tracing of JPEG calls * */ -/* * 0.5.3 - 06/24/2000 - G.Juyn * */ -/* * - fixed inclusion of IJG read/write code * */ -/* * 0.5.3 - 06/29/2000 - G.Juyn * */ -/* * - fixed some 64-bit warnings * */ -/* * * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 0.9.3 - 10/16/2000 - G.Juyn * */ -/* * - added support for JDAA * */ -/* * * */ -/* * 1.0.1 - 04/19/2001 - G.Juyn * */ -/* * - added export of JPEG functions for DLL * */ -/* * 1.0.1 - 04/22/2001 - G.Juyn * */ -/* * - fixed memory-leaks (Thanks Gregg!) * */ -/* * * */ -/* * 1.0.4 - 06/22/2002 - G.Juyn * */ -/* * - B526138 - returned IJGSRC6B calling convention to * */ -/* * default for MSVC * */ -/* * * */ -/* * 1.0.5 - 24/02/2003 - G.Juyn * */ -/* * - B683152 - libjpeg suspension not always honored correctly* */ -/* * * */ -/* * 1.0.6 - 03/04/2003 - G.Juyn * */ -/* * - fixed some compiler-warnings * */ -/* * * */ -/* * 1.0.8 - 08/01/2004 - G.Juyn * */ -/* * - added support for 3+byte pixelsize for JPEG's * */ -/* * * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_memory.h" -#include "libmng_pixels.h" -#include "libmng_jpeg.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ - -#if defined(MNG_INCLUDE_JNG) && defined(MNG_INCLUDE_DISPLAY_PROCS) - -/* ************************************************************************** */ -/* * * */ -/* * Local IJG callback routines (source-manager, error-manager and such) * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_IJG6B - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG_READ -#ifdef MNG_DEFINE_JPEG_STDCALL -void MNG_DECL mng_init_source (j_decompress_ptr cinfo) -#else -void mng_init_source (j_decompress_ptr cinfo) -#endif -{ - return; /* nothing needed */ -} -#endif /* MNG_INCLUDE_JNG_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG_READ -#ifdef MNG_DEFINE_JPEG_STDCALL -boolean MNG_DECL mng_fill_input_buffer (j_decompress_ptr cinfo) -#else -boolean mng_fill_input_buffer (j_decompress_ptr cinfo) -#endif -{ - return FALSE; /* force IJG routine to return to caller */ -} -#endif /* MNG_INCLUDE_JNG_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG_READ -#ifdef MNG_DEFINE_JPEG_STDCALL -void MNG_DECL mng_skip_input_data (j_decompress_ptr cinfo, long num_bytes) -#else -void mng_skip_input_data (j_decompress_ptr cinfo, long num_bytes) -#endif -{ - if (num_bytes > 0) /* ignore fony calls */ - { /* address my generic structure */ - mng_datap pData = (mng_datap)cinfo->client_data; - /* address source manager */ - mngjpeg_sourcep pSrc = pData->pJPEGdinfo->src; - /* problem scenario ? */ - if (pSrc->bytes_in_buffer < (size_t)num_bytes) - { /* tell the boss we need to skip some data! */ - pData->iJPEGtoskip = (mng_uint32)((size_t)num_bytes - pSrc->bytes_in_buffer); - - pSrc->bytes_in_buffer = 0; /* let the JPEG lib suspend */ - pSrc->next_input_byte = MNG_NULL; - } - else - { /* simply advance in the buffer */ - pSrc->bytes_in_buffer -= num_bytes; - pSrc->next_input_byte += num_bytes; - } - } - - return; -} -#endif /* MNG_INCLUDE_JNG_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG_READ -#ifdef MNG_DEFINE_JPEG_STDCALL -void MNG_DECL mng_skip_input_data2 (j_decompress_ptr cinfo, long num_bytes) -#else -void mng_skip_input_data2 (j_decompress_ptr cinfo, long num_bytes) -#endif -{ - if (num_bytes > 0) /* ignore fony calls */ - { /* address my generic structure */ - mng_datap pData = (mng_datap)cinfo->client_data; - /* address source manager */ - mngjpeg_sourcep pSrc = pData->pJPEGdinfo2->src; - /* problem scenario ? */ - if (pSrc->bytes_in_buffer < (size_t)num_bytes) - { /* tell the boss we need to skip some data! */ - pData->iJPEGtoskip2 = (mng_uint32)((size_t)num_bytes - pSrc->bytes_in_buffer); - - pSrc->bytes_in_buffer = 0; /* let the JPEG lib suspend */ - pSrc->next_input_byte = MNG_NULL; - } - else - { /* simply advance in the buffer */ - pSrc->bytes_in_buffer -= num_bytes; - pSrc->next_input_byte += num_bytes; - } - } - - return; -} -#endif /* MNG_INCLUDE_JNG_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG_READ -#ifdef MNG_DEFINE_JPEG_STDCALL -void MNG_DECL mng_term_source (j_decompress_ptr cinfo) -#else -void mng_term_source (j_decompress_ptr cinfo) -#endif -{ - return; /* nothing needed */ -} -#endif /* MNG_INCLUDE_JNG_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_USE_SETJMP -#ifdef MNG_DEFINE_JPEG_STDCALL -void MNG_DECL mng_error_exit (j_common_ptr cinfo) -#else -void mng_error_exit (j_common_ptr cinfo) -#endif -{ /* address my generic structure */ - mng_datap pData = (mng_datap)cinfo->client_data; - -#ifdef MNG_ERROR_TELLTALE /* fill the message text ??? */ - (*cinfo->err->output_message) (cinfo); -#endif - /* return to the point of no return... */ - longjmp (pData->sErrorbuf, cinfo->err->msg_code); -} -#endif /* MNG_USE_SETJMP */ - -/* ************************************************************************** */ - -#ifdef MNG_USE_SETJMP -#ifdef MNG_DEFINE_JPEG_STDCALL -void MNG_DECL mng_output_message (j_common_ptr cinfo) -#else -void mng_output_message (j_common_ptr cinfo) -#endif -{ - return; /* just do nothing ! */ -} -#endif /* MNG_USE_SETJMP */ - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_IJG6B */ - -/* ************************************************************************** */ -/* * * */ -/* * Global JPEG routines * */ -/* * * */ -/* ************************************************************************** */ - -mng_retcode mngjpeg_initialize (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_INITIALIZE, MNG_LC_START); -#endif - /* allocate space for JPEG structures if necessary */ -#ifdef MNG_INCLUDE_JNG_READ - if (pData->pJPEGderr == MNG_NULL) - MNG_ALLOC (pData, pData->pJPEGderr, sizeof (mngjpeg_error )); - if (pData->pJPEGdsrc == MNG_NULL) - MNG_ALLOC (pData, pData->pJPEGdsrc, sizeof (mngjpeg_source)); - if (pData->pJPEGdinfo == MNG_NULL) - MNG_ALLOC (pData, pData->pJPEGdinfo, sizeof (mngjpeg_decomp)); - /* enable reverse addressing */ - pData->pJPEGdinfo->client_data = pData; - - if (pData->pJPEGderr2 == MNG_NULL) - MNG_ALLOC (pData, pData->pJPEGderr2, sizeof (mngjpeg_error )); - if (pData->pJPEGdsrc2 == MNG_NULL) - MNG_ALLOC (pData, pData->pJPEGdsrc2, sizeof (mngjpeg_source)); - if (pData->pJPEGdinfo2 == MNG_NULL) - MNG_ALLOC (pData, pData->pJPEGdinfo2, sizeof (mngjpeg_decomp)); - /* enable reverse addressing */ - pData->pJPEGdinfo2->client_data = pData; -#endif - -#ifdef MNG_INCLUDE_JNG_WRITE - if (pData->pJPEGcerr == MNG_NULL) - MNG_ALLOC (pData, pData->pJPEGcerr, sizeof (mngjpeg_error )); - if (pData->pJPEGcinfo == MNG_NULL) - MNG_ALLOC (pData, pData->pJPEGcinfo, sizeof (mngjpeg_comp )); - /* enable reverse addressing */ - pData->pJPEGcinfo->client_data = pData; -#endif - - if (pData->pJPEGbuf == MNG_NULL) /* initialize temporary buffers */ - { - pData->iJPEGbufmax = MNG_JPEG_MAXBUF; - MNG_ALLOC (pData, pData->pJPEGbuf, pData->iJPEGbufmax); - } - - if (pData->pJPEGbuf2 == MNG_NULL) - { - pData->iJPEGbufmax2 = MNG_JPEG_MAXBUF; - MNG_ALLOC (pData, pData->pJPEGbuf2, pData->iJPEGbufmax2); - } - - pData->pJPEGcurrent = pData->pJPEGbuf; - pData->iJPEGbufremain = 0; - pData->pJPEGrow = MNG_NULL; - pData->iJPEGrowlen = 0; - pData->iJPEGtoskip = 0; - - pData->pJPEGcurrent2 = pData->pJPEGbuf2; - pData->iJPEGbufremain2 = 0; - pData->pJPEGrow2 = MNG_NULL; - pData->iJPEGrowlen2 = 0; - pData->iJPEGtoskip2 = 0; - /* not doing anything yet ! */ - pData->bJPEGcompress = MNG_FALSE; - - pData->bJPEGdecompress = MNG_FALSE; - pData->bJPEGhasheader = MNG_FALSE; - pData->bJPEGdecostarted = MNG_FALSE; - pData->bJPEGscanstarted = MNG_FALSE; - pData->bJPEGscanending = MNG_FALSE; - - pData->bJPEGdecompress2 = MNG_FALSE; - pData->bJPEGhasheader2 = MNG_FALSE; - pData->bJPEGdecostarted2 = MNG_FALSE; - pData->bJPEGscanstarted2 = MNG_FALSE; - - pData->iJPEGrow = 0; /* zero input/output lines */ - pData->iJPEGalpharow = 0; - pData->iJPEGrgbrow = 0; - pData->iJPEGdisprow = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_INITIALIZE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mngjpeg_cleanup (mng_datap pData) -{ -#if defined(MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) - mng_retcode iRetcode; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_CLEANUP, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_IJG6B -#ifdef MNG_USE_SETJMP - iRetcode = setjmp (pData->sErrorbuf);/* setup local JPEG error-recovery */ - if (iRetcode != 0) /* got here from longjmp ? */ - MNG_ERRORJ (pData, iRetcode); /* then IJG-lib issued an error */ -#endif - -#ifdef MNG_INCLUDE_JNG_READ /* still decompressing something ? */ - if (pData->bJPEGdecompress) - jpeg_destroy_decompress (pData->pJPEGdinfo); - if (pData->bJPEGdecompress2) - jpeg_destroy_decompress (pData->pJPEGdinfo2); -#endif - -#ifdef MNG_INCLUDE_JNG_WRITE - if (pData->bJPEGcompress) /* still compressing something ? */ - jpeg_destroy_compress (pData->pJPEGcinfo); -#endif - -#endif /* MNG_INCLUDE_IJG6B */ - /* cleanup temporary buffers */ - MNG_FREE (pData, pData->pJPEGbuf2, pData->iJPEGbufmax2); - MNG_FREE (pData, pData->pJPEGbuf, pData->iJPEGbufmax); - /* cleanup space for JPEG structures */ -#ifdef MNG_INCLUDE_JNG_WRITE - MNG_FREE (pData, pData->pJPEGcinfo, sizeof (mngjpeg_comp )); - MNG_FREE (pData, pData->pJPEGcerr, sizeof (mngjpeg_error )); -#endif - -#ifdef MNG_INCLUDE_JNG_READ - MNG_FREE (pData, pData->pJPEGdinfo, sizeof (mngjpeg_decomp)); - MNG_FREE (pData, pData->pJPEGdsrc, sizeof (mngjpeg_source)); - MNG_FREE (pData, pData->pJPEGderr, sizeof (mngjpeg_error )); - MNG_FREE (pData, pData->pJPEGdinfo2, sizeof (mngjpeg_decomp)); - MNG_FREE (pData, pData->pJPEGdsrc2, sizeof (mngjpeg_source)); - MNG_FREE (pData, pData->pJPEGderr2, sizeof (mngjpeg_error )); -#endif - - MNG_FREE (pData, pData->pJPEGrow2, pData->iJPEGrowlen2); - MNG_FREE (pData, pData->pJPEGrow, pData->iJPEGrowlen); - /* whatever we were doing ... */ - /* we don't anymore ... */ - pData->bJPEGcompress = MNG_FALSE; - - pData->bJPEGdecompress = MNG_FALSE; - pData->bJPEGhasheader = MNG_FALSE; - pData->bJPEGdecostarted = MNG_FALSE; - pData->bJPEGscanstarted = MNG_FALSE; - pData->bJPEGscanending = MNG_FALSE; - - pData->bJPEGdecompress2 = MNG_FALSE; - pData->bJPEGhasheader2 = MNG_FALSE; - pData->bJPEGdecostarted2 = MNG_FALSE; - pData->bJPEGscanstarted2 = MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_CLEANUP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ -/* * * */ -/* * JPEG decompression routines (JDAT) * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG_READ -mng_retcode mngjpeg_decompressinit (mng_datap pData) -{ -#if defined(MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) - mng_retcode iRetcode; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_IJG6B - /* allocate and initialize a JPEG decompression object */ - pData->pJPEGdinfo->err = jpeg_std_error (pData->pJPEGderr); - -#ifdef MNG_USE_SETJMP /* setup local JPEG error-routines */ - pData->pJPEGderr->error_exit = mng_error_exit; - pData->pJPEGderr->output_message = mng_output_message; - - iRetcode = setjmp (pData->sErrorbuf);/* setup local JPEG error-recovery */ - if (iRetcode != 0) /* got here from longjmp ? */ - MNG_ERRORJ (pData, iRetcode); /* then IJG-lib issued an error */ -#endif /* MNG_USE_SETJMP */ - - /* allocate and initialize a JPEG decompression object (continued) */ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_JPEG_CREATE_DECOMPRESS) -#endif - jpeg_create_decompress (pData->pJPEGdinfo); - - pData->bJPEGdecompress = MNG_TRUE; /* indicate it's initialized */ - - /* specify the source of the compressed data (eg, a file) */ - /* no, not a file; we have buffered input */ - pData->pJPEGdinfo->src = pData->pJPEGdsrc; - /* use the default handler */ - pData->pJPEGdinfo->src->resync_to_restart = jpeg_resync_to_restart; - /* setup local source routine & parms */ - pData->pJPEGdinfo->src->init_source = mng_init_source; - pData->pJPEGdinfo->src->fill_input_buffer = mng_fill_input_buffer; - pData->pJPEGdinfo->src->skip_input_data = mng_skip_input_data; - pData->pJPEGdinfo->src->term_source = mng_term_source; - pData->pJPEGdinfo->src->next_input_byte = pData->pJPEGcurrent; - pData->pJPEGdinfo->src->bytes_in_buffer = pData->iJPEGbufremain; - -#endif /* MNG_INCLUDE_IJG6B */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG_READ -mng_retcode mngjpeg_decompressdata (mng_datap pData, - mng_uint32 iRawsize, - mng_uint8p pRawdata) -{ - mng_retcode iRetcode; - mng_uint32 iRemain; - mng_uint8p pWork; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_START); -#endif - -#if defined (MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) - iRetcode = setjmp (pData->sErrorbuf);/* initialize local JPEG error-recovery */ - if (iRetcode != 0) /* got here from longjmp ? */ - MNG_ERRORJ (pData, iRetcode); /* then IJG-lib issued an error */ -#endif - - pWork = pRawdata; - iRemain = iRawsize; - - if (pData->iJPEGtoskip) /* JPEG-lib told us to skip some more data ? */ - { - if (iRemain > pData->iJPEGtoskip) /* enough data in this buffer ? */ - { - iRemain -= pData->iJPEGtoskip; /* skip enough to access the next byte */ - pWork += pData->iJPEGtoskip; - - pData->iJPEGtoskip = 0; /* no more to skip then */ - } - else - { - pData->iJPEGtoskip -= iRemain; /* skip all data in the buffer */ - iRemain = 0; /* and indicate this accordingly */ - } - /* the skip set current-pointer to NULL ! */ - pData->pJPEGcurrent = pData->pJPEGbuf; - } - - while (iRemain) /* repeat until no more input-bytes */ - { /* need to shift anything ? */ - if ((pData->pJPEGcurrent > pData->pJPEGbuf) && - (pData->pJPEGcurrent - pData->pJPEGbuf + pData->iJPEGbufremain + iRemain > pData->iJPEGbufmax)) - { - if (pData->iJPEGbufremain > 0) /* then do so */ - MNG_COPY (pData->pJPEGbuf, pData->pJPEGcurrent, pData->iJPEGbufremain); - - pData->pJPEGcurrent = pData->pJPEGbuf; - } - /* does the remaining input fit into the buffer ? */ - if (pData->iJPEGbufremain + iRemain <= pData->iJPEGbufmax) - { /* move the lot */ - MNG_COPY ((pData->pJPEGcurrent + pData->iJPEGbufremain), pWork, iRemain); - - pData->iJPEGbufremain += iRemain;/* adjust remaining_bytes counter */ - iRemain = 0; /* and indicate there's no input left */ - } - else - { /* calculate what does fit */ - mng_uint32 iFits = pData->iJPEGbufmax - pData->iJPEGbufremain; - - if (iFits <= 0) /* no space is just bugger 'm all */ - MNG_ERROR (pData, MNG_JPEGBUFTOOSMALL); - /* move that */ - MNG_COPY ((pData->pJPEGcurrent + pData->iJPEGbufremain), pWork, iFits); - - pData->iJPEGbufremain += iFits; /* adjust remain_bytes counter */ - iRemain -= iFits; /* and the input-parms */ - pWork += iFits; - } - -#ifdef MNG_INCLUDE_IJG6B - pData->pJPEGdinfo->src->next_input_byte = pData->pJPEGcurrent; - pData->pJPEGdinfo->src->bytes_in_buffer = pData->iJPEGbufremain; - - if (!pData->bJPEGhasheader) /* haven't got the header yet ? */ - { - /* call jpeg_read_header() to obtain image info */ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_READ_HEADER) -#endif - if (jpeg_read_header (pData->pJPEGdinfo, TRUE) != JPEG_SUSPENDED) - { /* indicate the header's oke */ - pData->bJPEGhasheader = MNG_TRUE; - /* let's do some sanity checks ! */ - if ((pData->pJPEGdinfo->image_width != pData->iDatawidth ) || - (pData->pJPEGdinfo->image_height != pData->iDataheight) ) - MNG_ERROR (pData, MNG_JPEGPARMSERR); - - if ( ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAY ) || - (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) ) && - (pData->pJPEGdinfo->jpeg_color_space != JCS_GRAYSCALE ) ) - MNG_ERROR (pData, MNG_JPEGPARMSERR); - - if ( ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLOR ) || - (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) && - (pData->pJPEGdinfo->jpeg_color_space != JCS_YCbCr ) ) - MNG_ERROR (pData, MNG_JPEGPARMSERR); - /* indicate whether or not it's progressive */ - pData->bJPEGprogressive = (mng_bool)jpeg_has_multiple_scans (pData->pJPEGdinfo); - /* progressive+alpha can't display "on-the-fly"!! */ - if ((pData->bJPEGprogressive) && - ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || - (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) )) - pData->fDisplayrow = MNG_NULL; - /* allocate a row of JPEG-samples */ - if (pData->pJPEGdinfo->jpeg_color_space == JCS_YCbCr) - pData->iJPEGrowlen = pData->pJPEGdinfo->image_width * RGB_PIXELSIZE; - else - pData->iJPEGrowlen = pData->pJPEGdinfo->image_width; - - MNG_ALLOC (pData, pData->pJPEGrow, pData->iJPEGrowlen); - - pData->iJPEGrgbrow = 0; /* quite empty up to now */ - } - - pData->pJPEGcurrent = (mng_uint8p)pData->pJPEGdinfo->src->next_input_byte; - pData->iJPEGbufremain = (mng_uint32)pData->pJPEGdinfo->src->bytes_in_buffer; - } - /* decompress not started ? */ - if ((pData->bJPEGhasheader) && (!pData->bJPEGdecostarted)) - { - /* set parameters for decompression */ - - if (pData->bJPEGprogressive) /* progressive display ? */ - pData->pJPEGdinfo->buffered_image = TRUE; - - /* jpeg_start_decompress(...); */ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_START_DECOMPRESS) -#endif - if (jpeg_start_decompress (pData->pJPEGdinfo) == TRUE) - /* indicate it started */ - pData->bJPEGdecostarted = MNG_TRUE; - - pData->pJPEGcurrent = (mng_uint8p)pData->pJPEGdinfo->src->next_input_byte; - pData->iJPEGbufremain = (mng_uint32)pData->pJPEGdinfo->src->bytes_in_buffer; - } - /* process some scanlines ? */ - if ((pData->bJPEGhasheader) && (pData->bJPEGdecostarted) && - ((!jpeg_input_complete (pData->pJPEGdinfo)) || - (pData->pJPEGdinfo->output_scanline < pData->pJPEGdinfo->output_height) || - ((pData->bJPEGprogressive) && (pData->bJPEGscanending)))) - { - mng_int32 iLines = 0; - - /* for (each output pass) */ - do - { /* address the row output buffer */ - JSAMPROW pRow = (JSAMPROW)pData->pJPEGrow; - - /* init new pass ? */ - if ((pData->bJPEGprogressive) && (!pData->bJPEGscanstarted)) - { - pData->bJPEGscanstarted = MNG_TRUE; - - /* adjust output decompression parameters if required */ - /* nop */ - - /* start a new output pass */ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_START_OUTPUT) -#endif - jpeg_start_output (pData->pJPEGdinfo, pData->pJPEGdinfo->input_scan_number); - - pData->iJPEGrow = 0; /* start at row 0 in the image again */ - } - - /* while (scan lines remain to be read) */ - if ((!pData->bJPEGprogressive) || (!pData->bJPEGscanending)) - { - do - { - /* jpeg_read_scanlines(...); */ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_READ_SCANLINES) -#endif - iLines = jpeg_read_scanlines (pData->pJPEGdinfo, (JSAMPARRAY)&pRow, 1); - - pData->pJPEGcurrent = (mng_uint8p)pData->pJPEGdinfo->src->next_input_byte; - pData->iJPEGbufremain = (mng_uint32)pData->pJPEGdinfo->src->bytes_in_buffer; - - if (iLines > 0) /* got something ? */ - { - if (pData->fStorerow2) /* store in object ? */ - { - iRetcode = ((mng_storerow)pData->fStorerow2) (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } - } - } - while ((pData->pJPEGdinfo->output_scanline < pData->pJPEGdinfo->output_height) && - (iLines > 0)); /* until end-of-image or not enough input-data */ - } - - /* terminate output pass */ - if ((pData->bJPEGprogressive) && - (pData->pJPEGdinfo->output_scanline >= pData->pJPEGdinfo->output_height)) - { -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_FINISH_OUTPUT) -#endif - if (jpeg_finish_output (pData->pJPEGdinfo) != JPEG_SUSPENDED) - { /* this scan has ended */ - pData->bJPEGscanstarted = MNG_FALSE; - pData->bJPEGscanending = MNG_FALSE; - } - else - { - pData->bJPEGscanending = MNG_TRUE; - } - } - } - while ((!jpeg_input_complete (pData->pJPEGdinfo)) && - (iLines > 0) && (!pData->bJPEGscanending)); - } - /* end of image ? */ - if ((pData->bJPEGhasheader) && (pData->bJPEGdecostarted) && - (!pData->bJPEGscanending) && (jpeg_input_complete (pData->pJPEGdinfo)) && - (pData->pJPEGdinfo->input_scan_number == pData->pJPEGdinfo->output_scan_number)) - { - /* jpeg_finish_decompress(...); */ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_FINISH_DECOMPRESS) -#endif - if (jpeg_finish_decompress (pData->pJPEGdinfo) == TRUE) - { /* indicate it's done */ - pData->bJPEGhasheader = MNG_FALSE; - pData->bJPEGdecostarted = MNG_FALSE; - pData->pJPEGcurrent = (mng_uint8p)pData->pJPEGdinfo->src->next_input_byte; - pData->iJPEGbufremain = (mng_uint32)pData->pJPEGdinfo->src->bytes_in_buffer; - /* remaining fluff is an error ! */ - if ((pData->iJPEGbufremain > 0) || (iRemain > 0)) - MNG_ERROR (pData, MNG_TOOMUCHJDAT); - } - } -#endif /* MNG_INCLUDE_IJG6B */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG_READ -mng_retcode mngjpeg_decompressfree (mng_datap pData) -{ -#if defined(MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) - mng_retcode iRetcode; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_IJG6B -#ifdef MNG_USE_SETJMP - iRetcode = setjmp (pData->sErrorbuf);/* setup local JPEG error-recovery */ - if (iRetcode != 0) /* got here from longjmp ? */ - MNG_ERRORJ (pData, iRetcode); /* then IJG-lib issued an error */ -#endif - /* free the row of JPEG-samples*/ - MNG_FREE (pData, pData->pJPEGrow, pData->iJPEGrowlen); - - /* release the JPEG decompression object */ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_JPEG_DESTROY_DECOMPRESS) -#endif - jpeg_destroy_decompress (pData->pJPEGdinfo); - - pData->bJPEGdecompress = MNG_FALSE; /* indicate it's done */ - -#endif /* MNG_INCLUDE_IJG6B */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG_READ */ - -/* ************************************************************************** */ -/* * * */ -/* * JPEG decompression routines (JDAA) * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG_READ -mng_retcode mngjpeg_decompressinit2 (mng_datap pData) -{ -#if defined(MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) - mng_retcode iRetcode; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_IJG6B - /* allocate and initialize a JPEG decompression object */ - pData->pJPEGdinfo2->err = jpeg_std_error (pData->pJPEGderr2); - -#ifdef MNG_USE_SETJMP /* setup local JPEG error-routines */ - pData->pJPEGderr2->error_exit = mng_error_exit; - pData->pJPEGderr2->output_message = mng_output_message; - - iRetcode = setjmp (pData->sErrorbuf);/* setup local JPEG error-recovery */ - if (iRetcode != 0) /* got here from longjmp ? */ - MNG_ERRORJ (pData, iRetcode); /* then IJG-lib issued an error */ -#endif /* MNG_USE_SETJMP */ - - /* allocate and initialize a JPEG decompression object (continued) */ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_JPEG_CREATE_DECOMPRESS) -#endif - jpeg_create_decompress (pData->pJPEGdinfo2); - - pData->bJPEGdecompress2 = MNG_TRUE; /* indicate it's initialized */ - - /* specify the source of the compressed data (eg, a file) */ - /* no, not a file; we have buffered input */ - pData->pJPEGdinfo2->src = pData->pJPEGdsrc2; - /* use the default handler */ - pData->pJPEGdinfo2->src->resync_to_restart = jpeg_resync_to_restart; - /* setup local source routine & parms */ - pData->pJPEGdinfo2->src->init_source = mng_init_source; - pData->pJPEGdinfo2->src->fill_input_buffer = mng_fill_input_buffer; - pData->pJPEGdinfo2->src->skip_input_data = mng_skip_input_data2; - pData->pJPEGdinfo2->src->term_source = mng_term_source; - pData->pJPEGdinfo2->src->next_input_byte = pData->pJPEGcurrent2; - pData->pJPEGdinfo2->src->bytes_in_buffer = pData->iJPEGbufremain2; - -#endif /* MNG_INCLUDE_IJG6B */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG_READ -mng_retcode mngjpeg_decompressdata2 (mng_datap pData, - mng_uint32 iRawsize, - mng_uint8p pRawdata) -{ - mng_retcode iRetcode; - mng_uint32 iRemain; - mng_uint8p pWork; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_START); -#endif - -#if defined (MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) - iRetcode = setjmp (pData->sErrorbuf);/* initialize local JPEG error-recovery */ - if (iRetcode != 0) /* got here from longjmp ? */ - MNG_ERRORJ (pData, iRetcode); /* then IJG-lib issued an error */ -#endif - - pWork = pRawdata; - iRemain = iRawsize; - - if (pData->iJPEGtoskip2) /* JPEG-lib told us to skip some more data ? */ - { - if (iRemain > pData->iJPEGtoskip2) /* enough data in this buffer ? */ - { - iRemain -= pData->iJPEGtoskip2; /* skip enough to access the next byte */ - pWork += pData->iJPEGtoskip2; - - pData->iJPEGtoskip2 = 0; /* no more to skip then */ - } - else - { - pData->iJPEGtoskip2 -= iRemain; /* skip all data in the buffer */ - iRemain = 0; /* and indicate this accordingly */ - } - /* the skip set current-pointer to NULL ! */ - pData->pJPEGcurrent2 = pData->pJPEGbuf2; - } - - while (iRemain) /* repeat until no more input-bytes */ - { /* need to shift anything ? */ - if ((pData->pJPEGcurrent2 > pData->pJPEGbuf2) && - (pData->pJPEGcurrent2 - pData->pJPEGbuf2 + pData->iJPEGbufremain2 + iRemain > pData->iJPEGbufmax2)) - { - if (pData->iJPEGbufremain2 > 0) /* then do so */ - MNG_COPY (pData->pJPEGbuf2, pData->pJPEGcurrent2, pData->iJPEGbufremain2); - - pData->pJPEGcurrent2 = pData->pJPEGbuf2; - } - /* does the remaining input fit into the buffer ? */ - if (pData->iJPEGbufremain2 + iRemain <= pData->iJPEGbufmax2) - { /* move the lot */ - MNG_COPY ((pData->pJPEGcurrent2 + pData->iJPEGbufremain2), pWork, iRemain); - /* adjust remaining_bytes counter */ - pData->iJPEGbufremain2 += iRemain; - iRemain = 0; /* and indicate there's no input left */ - } - else - { /* calculate what does fit */ - mng_uint32 iFits = pData->iJPEGbufmax2 - pData->iJPEGbufremain2; - - if (iFits <= 0) /* no space is just bugger 'm all */ - MNG_ERROR (pData, MNG_JPEGBUFTOOSMALL); - /* move that */ - MNG_COPY ((pData->pJPEGcurrent2 + pData->iJPEGbufremain2), pWork, iFits); - - pData->iJPEGbufremain2 += iFits; /* adjust remain_bytes counter */ - iRemain -= iFits; /* and the input-parms */ - pWork += iFits; - } - -#ifdef MNG_INCLUDE_IJG6B - pData->pJPEGdinfo2->src->next_input_byte = pData->pJPEGcurrent2; - pData->pJPEGdinfo2->src->bytes_in_buffer = pData->iJPEGbufremain2; - - if (!pData->bJPEGhasheader2) /* haven't got the header yet ? */ - { - /* call jpeg_read_header() to obtain image info */ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_READ_HEADER) -#endif - if (jpeg_read_header (pData->pJPEGdinfo2, TRUE) != JPEG_SUSPENDED) - { /* indicate the header's oke */ - pData->bJPEGhasheader2 = MNG_TRUE; - /* let's do some sanity checks ! */ - if ((pData->pJPEGdinfo2->image_width != pData->iDatawidth ) || - (pData->pJPEGdinfo2->image_height != pData->iDataheight) ) - MNG_ERROR (pData, MNG_JPEGPARMSERR); - - if (pData->pJPEGdinfo2->jpeg_color_space != JCS_GRAYSCALE) - MNG_ERROR (pData, MNG_JPEGPARMSERR); - /* indicate whether or not it's progressive */ - pData->bJPEGprogressive2 = (mng_bool)jpeg_has_multiple_scans (pData->pJPEGdinfo2); - - if (pData->bJPEGprogressive2) /* progressive alphachannel not allowed !!! */ - MNG_ERROR (pData, MNG_JPEGPARMSERR); - /* allocate a row of JPEG-samples */ - if (pData->pJPEGdinfo2->jpeg_color_space == JCS_YCbCr) - pData->iJPEGrowlen2 = pData->pJPEGdinfo2->image_width * RGB_PIXELSIZE; - else - pData->iJPEGrowlen2 = pData->pJPEGdinfo2->image_width; - - MNG_ALLOC (pData, pData->pJPEGrow2, pData->iJPEGrowlen2); - - pData->iJPEGalpharow = 0; /* quite empty up to now */ - } - - pData->pJPEGcurrent2 = (mng_uint8p)pData->pJPEGdinfo2->src->next_input_byte; - pData->iJPEGbufremain2 = (mng_uint32)pData->pJPEGdinfo2->src->bytes_in_buffer; - } - /* decompress not started ? */ - if ((pData->bJPEGhasheader2) && (!pData->bJPEGdecostarted2)) - { - /* set parameters for decompression */ - - if (pData->bJPEGprogressive2) /* progressive display ? */ - pData->pJPEGdinfo2->buffered_image = TRUE; - - /* jpeg_start_decompress(...); */ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_START_DECOMPRESS) -#endif - if (jpeg_start_decompress (pData->pJPEGdinfo2) == TRUE) - /* indicate it started */ - pData->bJPEGdecostarted2 = MNG_TRUE; - - pData->pJPEGcurrent2 = (mng_uint8p)pData->pJPEGdinfo2->src->next_input_byte; - pData->iJPEGbufremain2 = (mng_uint32)pData->pJPEGdinfo2->src->bytes_in_buffer; - } - /* process some scanlines ? */ - if ((pData->bJPEGhasheader2) && (pData->bJPEGdecostarted2) && - ((!jpeg_input_complete (pData->pJPEGdinfo2)) || - (pData->pJPEGdinfo2->output_scanline < pData->pJPEGdinfo2->output_height))) - { - mng_int32 iLines; - - /* for (each output pass) */ - do - { /* address the row output buffer */ - JSAMPROW pRow = (JSAMPROW)pData->pJPEGrow2; - - /* init new pass ? */ - if ((pData->bJPEGprogressive2) && - ((!pData->bJPEGscanstarted2) || - (pData->pJPEGdinfo2->output_scanline >= pData->pJPEGdinfo2->output_height))) - { - pData->bJPEGscanstarted2 = MNG_TRUE; - - /* adjust output decompression parameters if required */ - /* nop */ - - /* start a new output pass */ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_START_OUTPUT) -#endif - jpeg_start_output (pData->pJPEGdinfo2, pData->pJPEGdinfo2->input_scan_number); - - pData->iJPEGrow = 0; /* start at row 0 in the image again */ - } - - /* while (scan lines remain to be read) */ - do - { - /* jpeg_read_scanlines(...); */ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_READ_SCANLINES) -#endif - iLines = jpeg_read_scanlines (pData->pJPEGdinfo2, (JSAMPARRAY)&pRow, 1); - - pData->pJPEGcurrent2 = (mng_uint8p)pData->pJPEGdinfo2->src->next_input_byte; - pData->iJPEGbufremain2 = (mng_uint32)pData->pJPEGdinfo2->src->bytes_in_buffer; - - if (iLines > 0) /* got something ? */ - { - if (pData->fStorerow3) /* store in object ? */ - { - iRetcode = ((mng_storerow)pData->fStorerow3) (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } - } - } - while ((pData->pJPEGdinfo2->output_scanline < pData->pJPEGdinfo2->output_height) && - (iLines > 0)); /* until end-of-image or not enough input-data */ - - /* terminate output pass */ - if ((pData->bJPEGprogressive2) && - (pData->pJPEGdinfo2->output_scanline >= pData->pJPEGdinfo2->output_height)) - { -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_FINISH_OUTPUT) -#endif - if (jpeg_finish_output (pData->pJPEGdinfo2) == JPEG_SUSPENDED) - jpeg_finish_output (pData->pJPEGdinfo2); - /* this scan has ended */ - pData->bJPEGscanstarted2 = MNG_FALSE; - } - } - while ((!jpeg_input_complete (pData->pJPEGdinfo2)) && (iLines > 0)); - } - /* end of image ? */ - if ((pData->bJPEGhasheader2) && (pData->bJPEGdecostarted2) && - (jpeg_input_complete (pData->pJPEGdinfo2)) && - (pData->pJPEGdinfo2->input_scan_number == pData->pJPEGdinfo2->output_scan_number)) - { - /* jpeg_finish_decompress(...); */ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_FINISH_DECOMPRESS) -#endif - if (jpeg_finish_decompress (pData->pJPEGdinfo2) == TRUE) - { /* indicate it's done */ - pData->bJPEGhasheader2 = MNG_FALSE; - pData->bJPEGdecostarted2 = MNG_FALSE; - pData->pJPEGcurrent2 = (mng_uint8p)pData->pJPEGdinfo2->src->next_input_byte; - pData->iJPEGbufremain2 = (mng_uint32)pData->pJPEGdinfo2->src->bytes_in_buffer; - /* remaining fluff is an error ! */ - if ((pData->iJPEGbufremain2 > 0) || (iRemain > 0)) - MNG_ERROR (pData, MNG_TOOMUCHJDAT); - } - } -#endif /* MNG_INCLUDE_IJG6B */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG_READ -mng_retcode mngjpeg_decompressfree2 (mng_datap pData) -{ -#if defined(MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) - mng_retcode iRetcode; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_IJG6B -#ifdef MNG_USE_SETJMP - iRetcode = setjmp (pData->sErrorbuf);/* setup local JPEG error-recovery */ - if (iRetcode != 0) /* got here from longjmp ? */ - MNG_ERRORJ (pData, iRetcode); /* then IJG-lib issued an error */ -#endif - /* free the row of JPEG-samples*/ - MNG_FREE (pData, pData->pJPEGrow2, pData->iJPEGrowlen2); - - /* release the JPEG decompression object */ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_JPEG_DESTROY_DECOMPRESS) -#endif - jpeg_destroy_decompress (pData->pJPEGdinfo2); - - pData->bJPEGdecompress2 = MNG_FALSE; /* indicate it's done */ - -#endif /* MNG_INCLUDE_IJG6B */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_INCLUDE_JNG_READ */ - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_JNG && MNG_INCLUDE_DISPLAY_PROCS */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_jpeg.c copyright (c) 2000-2004 G.Juyn * */ +/* * version : 1.0.9 * */ +/* * * */ +/* * purpose : JPEG library interface (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the JPEG library interface * */ +/* * * */ +/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - changed strict-ANSI stuff * */ +/* * * */ +/* * 0.5.2 - 05/22/2000 - G.Juyn * */ +/* * - implemented all the JNG routines * */ +/* * * */ +/* * 0.5.3 - 06/17/2000 - G.Juyn * */ +/* * - added tracing of JPEG calls * */ +/* * 0.5.3 - 06/24/2000 - G.Juyn * */ +/* * - fixed inclusion of IJG read/write code * */ +/* * 0.5.3 - 06/29/2000 - G.Juyn * */ +/* * - fixed some 64-bit warnings * */ +/* * * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 0.9.3 - 10/16/2000 - G.Juyn * */ +/* * - added support for JDAA * */ +/* * * */ +/* * 1.0.1 - 04/19/2001 - G.Juyn * */ +/* * - added export of JPEG functions for DLL * */ +/* * 1.0.1 - 04/22/2001 - G.Juyn * */ +/* * - fixed memory-leaks (Thanks Gregg!) * */ +/* * * */ +/* * 1.0.4 - 06/22/2002 - G.Juyn * */ +/* * - B526138 - returned IJGSRC6B calling convention to * */ +/* * default for MSVC * */ +/* * * */ +/* * 1.0.5 - 24/02/2003 - G.Juyn * */ +/* * - B683152 - libjpeg suspension not always honored correctly* */ +/* * * */ +/* * 1.0.6 - 03/04/2003 - G.Juyn * */ +/* * - fixed some compiler-warnings * */ +/* * * */ +/* * 1.0.8 - 08/01/2004 - G.Juyn * */ +/* * - added support for 3+byte pixelsize for JPEG's * */ +/* * * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_memory.h" +#include "libmng_pixels.h" +#include "libmng_jpeg.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ + +#if defined(MNG_INCLUDE_JNG) && defined(MNG_INCLUDE_DISPLAY_PROCS) + +/* ************************************************************************** */ +/* * * */ +/* * Local IJG callback routines (source-manager, error-manager and such) * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_IJG6B + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG_READ +#ifdef MNG_DEFINE_JPEG_STDCALL +void MNG_DECL mng_init_source (j_decompress_ptr cinfo) +#else +void mng_init_source (j_decompress_ptr cinfo) +#endif +{ + return; /* nothing needed */ +} +#endif /* MNG_INCLUDE_JNG_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG_READ +#ifdef MNG_DEFINE_JPEG_STDCALL +boolean MNG_DECL mng_fill_input_buffer (j_decompress_ptr cinfo) +#else +boolean mng_fill_input_buffer (j_decompress_ptr cinfo) +#endif +{ + return FALSE; /* force IJG routine to return to caller */ +} +#endif /* MNG_INCLUDE_JNG_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG_READ +#ifdef MNG_DEFINE_JPEG_STDCALL +void MNG_DECL mng_skip_input_data (j_decompress_ptr cinfo, long num_bytes) +#else +void mng_skip_input_data (j_decompress_ptr cinfo, long num_bytes) +#endif +{ + if (num_bytes > 0) /* ignore fony calls */ + { /* address my generic structure */ + mng_datap pData = (mng_datap)cinfo->client_data; + /* address source manager */ + mngjpeg_sourcep pSrc = pData->pJPEGdinfo->src; + /* problem scenario ? */ + if (pSrc->bytes_in_buffer < (size_t)num_bytes) + { /* tell the boss we need to skip some data! */ + pData->iJPEGtoskip = (mng_uint32)((size_t)num_bytes - pSrc->bytes_in_buffer); + + pSrc->bytes_in_buffer = 0; /* let the JPEG lib suspend */ + pSrc->next_input_byte = MNG_NULL; + } + else + { /* simply advance in the buffer */ + pSrc->bytes_in_buffer -= num_bytes; + pSrc->next_input_byte += num_bytes; + } + } + + return; +} +#endif /* MNG_INCLUDE_JNG_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG_READ +#ifdef MNG_DEFINE_JPEG_STDCALL +void MNG_DECL mng_skip_input_data2 (j_decompress_ptr cinfo, long num_bytes) +#else +void mng_skip_input_data2 (j_decompress_ptr cinfo, long num_bytes) +#endif +{ + if (num_bytes > 0) /* ignore fony calls */ + { /* address my generic structure */ + mng_datap pData = (mng_datap)cinfo->client_data; + /* address source manager */ + mngjpeg_sourcep pSrc = pData->pJPEGdinfo2->src; + /* problem scenario ? */ + if (pSrc->bytes_in_buffer < (size_t)num_bytes) + { /* tell the boss we need to skip some data! */ + pData->iJPEGtoskip2 = (mng_uint32)((size_t)num_bytes - pSrc->bytes_in_buffer); + + pSrc->bytes_in_buffer = 0; /* let the JPEG lib suspend */ + pSrc->next_input_byte = MNG_NULL; + } + else + { /* simply advance in the buffer */ + pSrc->bytes_in_buffer -= num_bytes; + pSrc->next_input_byte += num_bytes; + } + } + + return; +} +#endif /* MNG_INCLUDE_JNG_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG_READ +#ifdef MNG_DEFINE_JPEG_STDCALL +void MNG_DECL mng_term_source (j_decompress_ptr cinfo) +#else +void mng_term_source (j_decompress_ptr cinfo) +#endif +{ + return; /* nothing needed */ +} +#endif /* MNG_INCLUDE_JNG_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_USE_SETJMP +#ifdef MNG_DEFINE_JPEG_STDCALL +void MNG_DECL mng_error_exit (j_common_ptr cinfo) +#else +void mng_error_exit (j_common_ptr cinfo) +#endif +{ /* address my generic structure */ + mng_datap pData = (mng_datap)cinfo->client_data; + +#ifdef MNG_ERROR_TELLTALE /* fill the message text ??? */ + (*cinfo->err->output_message) (cinfo); +#endif + /* return to the point of no return... */ + longjmp (pData->sErrorbuf, cinfo->err->msg_code); +} +#endif /* MNG_USE_SETJMP */ + +/* ************************************************************************** */ + +#ifdef MNG_USE_SETJMP +#ifdef MNG_DEFINE_JPEG_STDCALL +void MNG_DECL mng_output_message (j_common_ptr cinfo) +#else +void mng_output_message (j_common_ptr cinfo) +#endif +{ + return; /* just do nothing ! */ +} +#endif /* MNG_USE_SETJMP */ + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_IJG6B */ + +/* ************************************************************************** */ +/* * * */ +/* * Global JPEG routines * */ +/* * * */ +/* ************************************************************************** */ + +mng_retcode mngjpeg_initialize (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_INITIALIZE, MNG_LC_START); +#endif + /* allocate space for JPEG structures if necessary */ +#ifdef MNG_INCLUDE_JNG_READ + if (pData->pJPEGderr == MNG_NULL) + MNG_ALLOC (pData, pData->pJPEGderr, sizeof (mngjpeg_error )); + if (pData->pJPEGdsrc == MNG_NULL) + MNG_ALLOC (pData, pData->pJPEGdsrc, sizeof (mngjpeg_source)); + if (pData->pJPEGdinfo == MNG_NULL) + MNG_ALLOC (pData, pData->pJPEGdinfo, sizeof (mngjpeg_decomp)); + /* enable reverse addressing */ + pData->pJPEGdinfo->client_data = pData; + + if (pData->pJPEGderr2 == MNG_NULL) + MNG_ALLOC (pData, pData->pJPEGderr2, sizeof (mngjpeg_error )); + if (pData->pJPEGdsrc2 == MNG_NULL) + MNG_ALLOC (pData, pData->pJPEGdsrc2, sizeof (mngjpeg_source)); + if (pData->pJPEGdinfo2 == MNG_NULL) + MNG_ALLOC (pData, pData->pJPEGdinfo2, sizeof (mngjpeg_decomp)); + /* enable reverse addressing */ + pData->pJPEGdinfo2->client_data = pData; +#endif + +#ifdef MNG_INCLUDE_JNG_WRITE + if (pData->pJPEGcerr == MNG_NULL) + MNG_ALLOC (pData, pData->pJPEGcerr, sizeof (mngjpeg_error )); + if (pData->pJPEGcinfo == MNG_NULL) + MNG_ALLOC (pData, pData->pJPEGcinfo, sizeof (mngjpeg_comp )); + /* enable reverse addressing */ + pData->pJPEGcinfo->client_data = pData; +#endif + + if (pData->pJPEGbuf == MNG_NULL) /* initialize temporary buffers */ + { + pData->iJPEGbufmax = MNG_JPEG_MAXBUF; + MNG_ALLOC (pData, pData->pJPEGbuf, pData->iJPEGbufmax); + } + + if (pData->pJPEGbuf2 == MNG_NULL) + { + pData->iJPEGbufmax2 = MNG_JPEG_MAXBUF; + MNG_ALLOC (pData, pData->pJPEGbuf2, pData->iJPEGbufmax2); + } + + pData->pJPEGcurrent = pData->pJPEGbuf; + pData->iJPEGbufremain = 0; + pData->pJPEGrow = MNG_NULL; + pData->iJPEGrowlen = 0; + pData->iJPEGtoskip = 0; + + pData->pJPEGcurrent2 = pData->pJPEGbuf2; + pData->iJPEGbufremain2 = 0; + pData->pJPEGrow2 = MNG_NULL; + pData->iJPEGrowlen2 = 0; + pData->iJPEGtoskip2 = 0; + /* not doing anything yet ! */ + pData->bJPEGcompress = MNG_FALSE; + + pData->bJPEGdecompress = MNG_FALSE; + pData->bJPEGhasheader = MNG_FALSE; + pData->bJPEGdecostarted = MNG_FALSE; + pData->bJPEGscanstarted = MNG_FALSE; + pData->bJPEGscanending = MNG_FALSE; + + pData->bJPEGdecompress2 = MNG_FALSE; + pData->bJPEGhasheader2 = MNG_FALSE; + pData->bJPEGdecostarted2 = MNG_FALSE; + pData->bJPEGscanstarted2 = MNG_FALSE; + + pData->iJPEGrow = 0; /* zero input/output lines */ + pData->iJPEGalpharow = 0; + pData->iJPEGrgbrow = 0; + pData->iJPEGdisprow = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_INITIALIZE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mngjpeg_cleanup (mng_datap pData) +{ +#if defined(MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) + mng_retcode iRetcode; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_CLEANUP, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_IJG6B +#ifdef MNG_USE_SETJMP + iRetcode = setjmp (pData->sErrorbuf);/* setup local JPEG error-recovery */ + if (iRetcode != 0) /* got here from longjmp ? */ + MNG_ERRORJ (pData, iRetcode); /* then IJG-lib issued an error */ +#endif + +#ifdef MNG_INCLUDE_JNG_READ /* still decompressing something ? */ + if (pData->bJPEGdecompress) + jpeg_destroy_decompress (pData->pJPEGdinfo); + if (pData->bJPEGdecompress2) + jpeg_destroy_decompress (pData->pJPEGdinfo2); +#endif + +#ifdef MNG_INCLUDE_JNG_WRITE + if (pData->bJPEGcompress) /* still compressing something ? */ + jpeg_destroy_compress (pData->pJPEGcinfo); +#endif + +#endif /* MNG_INCLUDE_IJG6B */ + /* cleanup temporary buffers */ + MNG_FREE (pData, pData->pJPEGbuf2, pData->iJPEGbufmax2); + MNG_FREE (pData, pData->pJPEGbuf, pData->iJPEGbufmax); + /* cleanup space for JPEG structures */ +#ifdef MNG_INCLUDE_JNG_WRITE + MNG_FREE (pData, pData->pJPEGcinfo, sizeof (mngjpeg_comp )); + MNG_FREE (pData, pData->pJPEGcerr, sizeof (mngjpeg_error )); +#endif + +#ifdef MNG_INCLUDE_JNG_READ + MNG_FREE (pData, pData->pJPEGdinfo, sizeof (mngjpeg_decomp)); + MNG_FREE (pData, pData->pJPEGdsrc, sizeof (mngjpeg_source)); + MNG_FREE (pData, pData->pJPEGderr, sizeof (mngjpeg_error )); + MNG_FREE (pData, pData->pJPEGdinfo2, sizeof (mngjpeg_decomp)); + MNG_FREE (pData, pData->pJPEGdsrc2, sizeof (mngjpeg_source)); + MNG_FREE (pData, pData->pJPEGderr2, sizeof (mngjpeg_error )); +#endif + + MNG_FREE (pData, pData->pJPEGrow2, pData->iJPEGrowlen2); + MNG_FREE (pData, pData->pJPEGrow, pData->iJPEGrowlen); + /* whatever we were doing ... */ + /* we don't anymore ... */ + pData->bJPEGcompress = MNG_FALSE; + + pData->bJPEGdecompress = MNG_FALSE; + pData->bJPEGhasheader = MNG_FALSE; + pData->bJPEGdecostarted = MNG_FALSE; + pData->bJPEGscanstarted = MNG_FALSE; + pData->bJPEGscanending = MNG_FALSE; + + pData->bJPEGdecompress2 = MNG_FALSE; + pData->bJPEGhasheader2 = MNG_FALSE; + pData->bJPEGdecostarted2 = MNG_FALSE; + pData->bJPEGscanstarted2 = MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_CLEANUP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ +/* * * */ +/* * JPEG decompression routines (JDAT) * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG_READ +mng_retcode mngjpeg_decompressinit (mng_datap pData) +{ +#if defined(MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) + mng_retcode iRetcode; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_IJG6B + /* allocate and initialize a JPEG decompression object */ + pData->pJPEGdinfo->err = jpeg_std_error (pData->pJPEGderr); + +#ifdef MNG_USE_SETJMP /* setup local JPEG error-routines */ + pData->pJPEGderr->error_exit = mng_error_exit; + pData->pJPEGderr->output_message = mng_output_message; + + iRetcode = setjmp (pData->sErrorbuf);/* setup local JPEG error-recovery */ + if (iRetcode != 0) /* got here from longjmp ? */ + MNG_ERRORJ (pData, iRetcode); /* then IJG-lib issued an error */ +#endif /* MNG_USE_SETJMP */ + + /* allocate and initialize a JPEG decompression object (continued) */ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_JPEG_CREATE_DECOMPRESS) +#endif + jpeg_create_decompress (pData->pJPEGdinfo); + + pData->bJPEGdecompress = MNG_TRUE; /* indicate it's initialized */ + + /* specify the source of the compressed data (eg, a file) */ + /* no, not a file; we have buffered input */ + pData->pJPEGdinfo->src = pData->pJPEGdsrc; + /* use the default handler */ + pData->pJPEGdinfo->src->resync_to_restart = jpeg_resync_to_restart; + /* setup local source routine & parms */ + pData->pJPEGdinfo->src->init_source = mng_init_source; + pData->pJPEGdinfo->src->fill_input_buffer = mng_fill_input_buffer; + pData->pJPEGdinfo->src->skip_input_data = mng_skip_input_data; + pData->pJPEGdinfo->src->term_source = mng_term_source; + pData->pJPEGdinfo->src->next_input_byte = pData->pJPEGcurrent; + pData->pJPEGdinfo->src->bytes_in_buffer = pData->iJPEGbufremain; + +#endif /* MNG_INCLUDE_IJG6B */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG_READ +mng_retcode mngjpeg_decompressdata (mng_datap pData, + mng_uint32 iRawsize, + mng_uint8p pRawdata) +{ + mng_retcode iRetcode; + mng_uint32 iRemain; + mng_uint8p pWork; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_START); +#endif + +#if defined (MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) + iRetcode = setjmp (pData->sErrorbuf);/* initialize local JPEG error-recovery */ + if (iRetcode != 0) /* got here from longjmp ? */ + MNG_ERRORJ (pData, iRetcode); /* then IJG-lib issued an error */ +#endif + + pWork = pRawdata; + iRemain = iRawsize; + + if (pData->iJPEGtoskip) /* JPEG-lib told us to skip some more data ? */ + { + if (iRemain > pData->iJPEGtoskip) /* enough data in this buffer ? */ + { + iRemain -= pData->iJPEGtoskip; /* skip enough to access the next byte */ + pWork += pData->iJPEGtoskip; + + pData->iJPEGtoskip = 0; /* no more to skip then */ + } + else + { + pData->iJPEGtoskip -= iRemain; /* skip all data in the buffer */ + iRemain = 0; /* and indicate this accordingly */ + } + /* the skip set current-pointer to NULL ! */ + pData->pJPEGcurrent = pData->pJPEGbuf; + } + + while (iRemain) /* repeat until no more input-bytes */ + { /* need to shift anything ? */ + if ((pData->pJPEGcurrent > pData->pJPEGbuf) && + (pData->pJPEGcurrent - pData->pJPEGbuf + pData->iJPEGbufremain + iRemain > pData->iJPEGbufmax)) + { + if (pData->iJPEGbufremain > 0) /* then do so */ + MNG_COPY (pData->pJPEGbuf, pData->pJPEGcurrent, pData->iJPEGbufremain); + + pData->pJPEGcurrent = pData->pJPEGbuf; + } + /* does the remaining input fit into the buffer ? */ + if (pData->iJPEGbufremain + iRemain <= pData->iJPEGbufmax) + { /* move the lot */ + MNG_COPY ((pData->pJPEGcurrent + pData->iJPEGbufremain), pWork, iRemain); + + pData->iJPEGbufremain += iRemain;/* adjust remaining_bytes counter */ + iRemain = 0; /* and indicate there's no input left */ + } + else + { /* calculate what does fit */ + mng_uint32 iFits = pData->iJPEGbufmax - pData->iJPEGbufremain; + + if (iFits <= 0) /* no space is just bugger 'm all */ + MNG_ERROR (pData, MNG_JPEGBUFTOOSMALL); + /* move that */ + MNG_COPY ((pData->pJPEGcurrent + pData->iJPEGbufremain), pWork, iFits); + + pData->iJPEGbufremain += iFits; /* adjust remain_bytes counter */ + iRemain -= iFits; /* and the input-parms */ + pWork += iFits; + } + +#ifdef MNG_INCLUDE_IJG6B + pData->pJPEGdinfo->src->next_input_byte = pData->pJPEGcurrent; + pData->pJPEGdinfo->src->bytes_in_buffer = pData->iJPEGbufremain; + + if (!pData->bJPEGhasheader) /* haven't got the header yet ? */ + { + /* call jpeg_read_header() to obtain image info */ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_READ_HEADER) +#endif + if (jpeg_read_header (pData->pJPEGdinfo, TRUE) != JPEG_SUSPENDED) + { /* indicate the header's oke */ + pData->bJPEGhasheader = MNG_TRUE; + /* let's do some sanity checks ! */ + if ((pData->pJPEGdinfo->image_width != pData->iDatawidth ) || + (pData->pJPEGdinfo->image_height != pData->iDataheight) ) + MNG_ERROR (pData, MNG_JPEGPARMSERR); + + if ( ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAY ) || + (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) ) && + (pData->pJPEGdinfo->jpeg_color_space != JCS_GRAYSCALE ) ) + MNG_ERROR (pData, MNG_JPEGPARMSERR); + + if ( ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLOR ) || + (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) && + (pData->pJPEGdinfo->jpeg_color_space != JCS_YCbCr ) ) + MNG_ERROR (pData, MNG_JPEGPARMSERR); + /* indicate whether or not it's progressive */ + pData->bJPEGprogressive = (mng_bool)jpeg_has_multiple_scans (pData->pJPEGdinfo); + /* progressive+alpha can't display "on-the-fly"!! */ + if ((pData->bJPEGprogressive) && + ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || + (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) )) + pData->fDisplayrow = MNG_NULL; + /* allocate a row of JPEG-samples */ + if (pData->pJPEGdinfo->jpeg_color_space == JCS_YCbCr) + pData->iJPEGrowlen = pData->pJPEGdinfo->image_width * RGB_PIXELSIZE; + else + pData->iJPEGrowlen = pData->pJPEGdinfo->image_width; + + MNG_ALLOC (pData, pData->pJPEGrow, pData->iJPEGrowlen); + + pData->iJPEGrgbrow = 0; /* quite empty up to now */ + } + + pData->pJPEGcurrent = (mng_uint8p)pData->pJPEGdinfo->src->next_input_byte; + pData->iJPEGbufremain = (mng_uint32)pData->pJPEGdinfo->src->bytes_in_buffer; + } + /* decompress not started ? */ + if ((pData->bJPEGhasheader) && (!pData->bJPEGdecostarted)) + { + /* set parameters for decompression */ + + if (pData->bJPEGprogressive) /* progressive display ? */ + pData->pJPEGdinfo->buffered_image = TRUE; + + /* jpeg_start_decompress(...); */ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_START_DECOMPRESS) +#endif + if (jpeg_start_decompress (pData->pJPEGdinfo) == TRUE) + /* indicate it started */ + pData->bJPEGdecostarted = MNG_TRUE; + + pData->pJPEGcurrent = (mng_uint8p)pData->pJPEGdinfo->src->next_input_byte; + pData->iJPEGbufremain = (mng_uint32)pData->pJPEGdinfo->src->bytes_in_buffer; + } + /* process some scanlines ? */ + if ((pData->bJPEGhasheader) && (pData->bJPEGdecostarted) && + ((!jpeg_input_complete (pData->pJPEGdinfo)) || + (pData->pJPEGdinfo->output_scanline < pData->pJPEGdinfo->output_height) || + ((pData->bJPEGprogressive) && (pData->bJPEGscanending)))) + { + mng_int32 iLines = 0; + + /* for (each output pass) */ + do + { /* address the row output buffer */ + JSAMPROW pRow = (JSAMPROW)pData->pJPEGrow; + + /* init new pass ? */ + if ((pData->bJPEGprogressive) && (!pData->bJPEGscanstarted)) + { + pData->bJPEGscanstarted = MNG_TRUE; + + /* adjust output decompression parameters if required */ + /* nop */ + + /* start a new output pass */ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_START_OUTPUT) +#endif + jpeg_start_output (pData->pJPEGdinfo, pData->pJPEGdinfo->input_scan_number); + + pData->iJPEGrow = 0; /* start at row 0 in the image again */ + } + + /* while (scan lines remain to be read) */ + if ((!pData->bJPEGprogressive) || (!pData->bJPEGscanending)) + { + do + { + /* jpeg_read_scanlines(...); */ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_READ_SCANLINES) +#endif + iLines = jpeg_read_scanlines (pData->pJPEGdinfo, (JSAMPARRAY)&pRow, 1); + + pData->pJPEGcurrent = (mng_uint8p)pData->pJPEGdinfo->src->next_input_byte; + pData->iJPEGbufremain = (mng_uint32)pData->pJPEGdinfo->src->bytes_in_buffer; + + if (iLines > 0) /* got something ? */ + { + if (pData->fStorerow2) /* store in object ? */ + { + iRetcode = ((mng_storerow)pData->fStorerow2) (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } + } + } + while ((pData->pJPEGdinfo->output_scanline < pData->pJPEGdinfo->output_height) && + (iLines > 0)); /* until end-of-image or not enough input-data */ + } + + /* terminate output pass */ + if ((pData->bJPEGprogressive) && + (pData->pJPEGdinfo->output_scanline >= pData->pJPEGdinfo->output_height)) + { +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_FINISH_OUTPUT) +#endif + if (jpeg_finish_output (pData->pJPEGdinfo) != JPEG_SUSPENDED) + { /* this scan has ended */ + pData->bJPEGscanstarted = MNG_FALSE; + pData->bJPEGscanending = MNG_FALSE; + } + else + { + pData->bJPEGscanending = MNG_TRUE; + } + } + } + while ((!jpeg_input_complete (pData->pJPEGdinfo)) && + (iLines > 0) && (!pData->bJPEGscanending)); + } + /* end of image ? */ + if ((pData->bJPEGhasheader) && (pData->bJPEGdecostarted) && + (!pData->bJPEGscanending) && (jpeg_input_complete (pData->pJPEGdinfo)) && + (pData->pJPEGdinfo->input_scan_number == pData->pJPEGdinfo->output_scan_number)) + { + /* jpeg_finish_decompress(...); */ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_FINISH_DECOMPRESS) +#endif + if (jpeg_finish_decompress (pData->pJPEGdinfo) == TRUE) + { /* indicate it's done */ + pData->bJPEGhasheader = MNG_FALSE; + pData->bJPEGdecostarted = MNG_FALSE; + pData->pJPEGcurrent = (mng_uint8p)pData->pJPEGdinfo->src->next_input_byte; + pData->iJPEGbufremain = (mng_uint32)pData->pJPEGdinfo->src->bytes_in_buffer; + /* remaining fluff is an error ! */ + if ((pData->iJPEGbufremain > 0) || (iRemain > 0)) + MNG_ERROR (pData, MNG_TOOMUCHJDAT); + } + } +#endif /* MNG_INCLUDE_IJG6B */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG_READ +mng_retcode mngjpeg_decompressfree (mng_datap pData) +{ +#if defined(MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) + mng_retcode iRetcode; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_IJG6B +#ifdef MNG_USE_SETJMP + iRetcode = setjmp (pData->sErrorbuf);/* setup local JPEG error-recovery */ + if (iRetcode != 0) /* got here from longjmp ? */ + MNG_ERRORJ (pData, iRetcode); /* then IJG-lib issued an error */ +#endif + /* free the row of JPEG-samples*/ + MNG_FREE (pData, pData->pJPEGrow, pData->iJPEGrowlen); + + /* release the JPEG decompression object */ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_JPEG_DESTROY_DECOMPRESS) +#endif + jpeg_destroy_decompress (pData->pJPEGdinfo); + + pData->bJPEGdecompress = MNG_FALSE; /* indicate it's done */ + +#endif /* MNG_INCLUDE_IJG6B */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG_READ */ + +/* ************************************************************************** */ +/* * * */ +/* * JPEG decompression routines (JDAA) * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG_READ +mng_retcode mngjpeg_decompressinit2 (mng_datap pData) +{ +#if defined(MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) + mng_retcode iRetcode; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_IJG6B + /* allocate and initialize a JPEG decompression object */ + pData->pJPEGdinfo2->err = jpeg_std_error (pData->pJPEGderr2); + +#ifdef MNG_USE_SETJMP /* setup local JPEG error-routines */ + pData->pJPEGderr2->error_exit = mng_error_exit; + pData->pJPEGderr2->output_message = mng_output_message; + + iRetcode = setjmp (pData->sErrorbuf);/* setup local JPEG error-recovery */ + if (iRetcode != 0) /* got here from longjmp ? */ + MNG_ERRORJ (pData, iRetcode); /* then IJG-lib issued an error */ +#endif /* MNG_USE_SETJMP */ + + /* allocate and initialize a JPEG decompression object (continued) */ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_JPEG_CREATE_DECOMPRESS) +#endif + jpeg_create_decompress (pData->pJPEGdinfo2); + + pData->bJPEGdecompress2 = MNG_TRUE; /* indicate it's initialized */ + + /* specify the source of the compressed data (eg, a file) */ + /* no, not a file; we have buffered input */ + pData->pJPEGdinfo2->src = pData->pJPEGdsrc2; + /* use the default handler */ + pData->pJPEGdinfo2->src->resync_to_restart = jpeg_resync_to_restart; + /* setup local source routine & parms */ + pData->pJPEGdinfo2->src->init_source = mng_init_source; + pData->pJPEGdinfo2->src->fill_input_buffer = mng_fill_input_buffer; + pData->pJPEGdinfo2->src->skip_input_data = mng_skip_input_data2; + pData->pJPEGdinfo2->src->term_source = mng_term_source; + pData->pJPEGdinfo2->src->next_input_byte = pData->pJPEGcurrent2; + pData->pJPEGdinfo2->src->bytes_in_buffer = pData->iJPEGbufremain2; + +#endif /* MNG_INCLUDE_IJG6B */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG_READ +mng_retcode mngjpeg_decompressdata2 (mng_datap pData, + mng_uint32 iRawsize, + mng_uint8p pRawdata) +{ + mng_retcode iRetcode; + mng_uint32 iRemain; + mng_uint8p pWork; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_START); +#endif + +#if defined (MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) + iRetcode = setjmp (pData->sErrorbuf);/* initialize local JPEG error-recovery */ + if (iRetcode != 0) /* got here from longjmp ? */ + MNG_ERRORJ (pData, iRetcode); /* then IJG-lib issued an error */ +#endif + + pWork = pRawdata; + iRemain = iRawsize; + + if (pData->iJPEGtoskip2) /* JPEG-lib told us to skip some more data ? */ + { + if (iRemain > pData->iJPEGtoskip2) /* enough data in this buffer ? */ + { + iRemain -= pData->iJPEGtoskip2; /* skip enough to access the next byte */ + pWork += pData->iJPEGtoskip2; + + pData->iJPEGtoskip2 = 0; /* no more to skip then */ + } + else + { + pData->iJPEGtoskip2 -= iRemain; /* skip all data in the buffer */ + iRemain = 0; /* and indicate this accordingly */ + } + /* the skip set current-pointer to NULL ! */ + pData->pJPEGcurrent2 = pData->pJPEGbuf2; + } + + while (iRemain) /* repeat until no more input-bytes */ + { /* need to shift anything ? */ + if ((pData->pJPEGcurrent2 > pData->pJPEGbuf2) && + (pData->pJPEGcurrent2 - pData->pJPEGbuf2 + pData->iJPEGbufremain2 + iRemain > pData->iJPEGbufmax2)) + { + if (pData->iJPEGbufremain2 > 0) /* then do so */ + MNG_COPY (pData->pJPEGbuf2, pData->pJPEGcurrent2, pData->iJPEGbufremain2); + + pData->pJPEGcurrent2 = pData->pJPEGbuf2; + } + /* does the remaining input fit into the buffer ? */ + if (pData->iJPEGbufremain2 + iRemain <= pData->iJPEGbufmax2) + { /* move the lot */ + MNG_COPY ((pData->pJPEGcurrent2 + pData->iJPEGbufremain2), pWork, iRemain); + /* adjust remaining_bytes counter */ + pData->iJPEGbufremain2 += iRemain; + iRemain = 0; /* and indicate there's no input left */ + } + else + { /* calculate what does fit */ + mng_uint32 iFits = pData->iJPEGbufmax2 - pData->iJPEGbufremain2; + + if (iFits <= 0) /* no space is just bugger 'm all */ + MNG_ERROR (pData, MNG_JPEGBUFTOOSMALL); + /* move that */ + MNG_COPY ((pData->pJPEGcurrent2 + pData->iJPEGbufremain2), pWork, iFits); + + pData->iJPEGbufremain2 += iFits; /* adjust remain_bytes counter */ + iRemain -= iFits; /* and the input-parms */ + pWork += iFits; + } + +#ifdef MNG_INCLUDE_IJG6B + pData->pJPEGdinfo2->src->next_input_byte = pData->pJPEGcurrent2; + pData->pJPEGdinfo2->src->bytes_in_buffer = pData->iJPEGbufremain2; + + if (!pData->bJPEGhasheader2) /* haven't got the header yet ? */ + { + /* call jpeg_read_header() to obtain image info */ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_READ_HEADER) +#endif + if (jpeg_read_header (pData->pJPEGdinfo2, TRUE) != JPEG_SUSPENDED) + { /* indicate the header's oke */ + pData->bJPEGhasheader2 = MNG_TRUE; + /* let's do some sanity checks ! */ + if ((pData->pJPEGdinfo2->image_width != pData->iDatawidth ) || + (pData->pJPEGdinfo2->image_height != pData->iDataheight) ) + MNG_ERROR (pData, MNG_JPEGPARMSERR); + + if (pData->pJPEGdinfo2->jpeg_color_space != JCS_GRAYSCALE) + MNG_ERROR (pData, MNG_JPEGPARMSERR); + /* indicate whether or not it's progressive */ + pData->bJPEGprogressive2 = (mng_bool)jpeg_has_multiple_scans (pData->pJPEGdinfo2); + + if (pData->bJPEGprogressive2) /* progressive alphachannel not allowed !!! */ + MNG_ERROR (pData, MNG_JPEGPARMSERR); + /* allocate a row of JPEG-samples */ + if (pData->pJPEGdinfo2->jpeg_color_space == JCS_YCbCr) + pData->iJPEGrowlen2 = pData->pJPEGdinfo2->image_width * RGB_PIXELSIZE; + else + pData->iJPEGrowlen2 = pData->pJPEGdinfo2->image_width; + + MNG_ALLOC (pData, pData->pJPEGrow2, pData->iJPEGrowlen2); + + pData->iJPEGalpharow = 0; /* quite empty up to now */ + } + + pData->pJPEGcurrent2 = (mng_uint8p)pData->pJPEGdinfo2->src->next_input_byte; + pData->iJPEGbufremain2 = (mng_uint32)pData->pJPEGdinfo2->src->bytes_in_buffer; + } + /* decompress not started ? */ + if ((pData->bJPEGhasheader2) && (!pData->bJPEGdecostarted2)) + { + /* set parameters for decompression */ + + if (pData->bJPEGprogressive2) /* progressive display ? */ + pData->pJPEGdinfo2->buffered_image = TRUE; + + /* jpeg_start_decompress(...); */ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_START_DECOMPRESS) +#endif + if (jpeg_start_decompress (pData->pJPEGdinfo2) == TRUE) + /* indicate it started */ + pData->bJPEGdecostarted2 = MNG_TRUE; + + pData->pJPEGcurrent2 = (mng_uint8p)pData->pJPEGdinfo2->src->next_input_byte; + pData->iJPEGbufremain2 = (mng_uint32)pData->pJPEGdinfo2->src->bytes_in_buffer; + } + /* process some scanlines ? */ + if ((pData->bJPEGhasheader2) && (pData->bJPEGdecostarted2) && + ((!jpeg_input_complete (pData->pJPEGdinfo2)) || + (pData->pJPEGdinfo2->output_scanline < pData->pJPEGdinfo2->output_height))) + { + mng_int32 iLines; + + /* for (each output pass) */ + do + { /* address the row output buffer */ + JSAMPROW pRow = (JSAMPROW)pData->pJPEGrow2; + + /* init new pass ? */ + if ((pData->bJPEGprogressive2) && + ((!pData->bJPEGscanstarted2) || + (pData->pJPEGdinfo2->output_scanline >= pData->pJPEGdinfo2->output_height))) + { + pData->bJPEGscanstarted2 = MNG_TRUE; + + /* adjust output decompression parameters if required */ + /* nop */ + + /* start a new output pass */ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_START_OUTPUT) +#endif + jpeg_start_output (pData->pJPEGdinfo2, pData->pJPEGdinfo2->input_scan_number); + + pData->iJPEGrow = 0; /* start at row 0 in the image again */ + } + + /* while (scan lines remain to be read) */ + do + { + /* jpeg_read_scanlines(...); */ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_READ_SCANLINES) +#endif + iLines = jpeg_read_scanlines (pData->pJPEGdinfo2, (JSAMPARRAY)&pRow, 1); + + pData->pJPEGcurrent2 = (mng_uint8p)pData->pJPEGdinfo2->src->next_input_byte; + pData->iJPEGbufremain2 = (mng_uint32)pData->pJPEGdinfo2->src->bytes_in_buffer; + + if (iLines > 0) /* got something ? */ + { + if (pData->fStorerow3) /* store in object ? */ + { + iRetcode = ((mng_storerow)pData->fStorerow3) (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } + } + } + while ((pData->pJPEGdinfo2->output_scanline < pData->pJPEGdinfo2->output_height) && + (iLines > 0)); /* until end-of-image or not enough input-data */ + + /* terminate output pass */ + if ((pData->bJPEGprogressive2) && + (pData->pJPEGdinfo2->output_scanline >= pData->pJPEGdinfo2->output_height)) + { +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_FINISH_OUTPUT) +#endif + if (jpeg_finish_output (pData->pJPEGdinfo2) == JPEG_SUSPENDED) + jpeg_finish_output (pData->pJPEGdinfo2); + /* this scan has ended */ + pData->bJPEGscanstarted2 = MNG_FALSE; + } + } + while ((!jpeg_input_complete (pData->pJPEGdinfo2)) && (iLines > 0)); + } + /* end of image ? */ + if ((pData->bJPEGhasheader2) && (pData->bJPEGdecostarted2) && + (jpeg_input_complete (pData->pJPEGdinfo2)) && + (pData->pJPEGdinfo2->input_scan_number == pData->pJPEGdinfo2->output_scan_number)) + { + /* jpeg_finish_decompress(...); */ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_FINISH_DECOMPRESS) +#endif + if (jpeg_finish_decompress (pData->pJPEGdinfo2) == TRUE) + { /* indicate it's done */ + pData->bJPEGhasheader2 = MNG_FALSE; + pData->bJPEGdecostarted2 = MNG_FALSE; + pData->pJPEGcurrent2 = (mng_uint8p)pData->pJPEGdinfo2->src->next_input_byte; + pData->iJPEGbufremain2 = (mng_uint32)pData->pJPEGdinfo2->src->bytes_in_buffer; + /* remaining fluff is an error ! */ + if ((pData->iJPEGbufremain2 > 0) || (iRemain > 0)) + MNG_ERROR (pData, MNG_TOOMUCHJDAT); + } + } +#endif /* MNG_INCLUDE_IJG6B */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG_READ +mng_retcode mngjpeg_decompressfree2 (mng_datap pData) +{ +#if defined(MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP) + mng_retcode iRetcode; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_IJG6B +#ifdef MNG_USE_SETJMP + iRetcode = setjmp (pData->sErrorbuf);/* setup local JPEG error-recovery */ + if (iRetcode != 0) /* got here from longjmp ? */ + MNG_ERRORJ (pData, iRetcode); /* then IJG-lib issued an error */ +#endif + /* free the row of JPEG-samples*/ + MNG_FREE (pData, pData->pJPEGrow2, pData->iJPEGrowlen2); + + /* release the JPEG decompression object */ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_JPEG_DESTROY_DECOMPRESS) +#endif + jpeg_destroy_decompress (pData->pJPEGdinfo2); + + pData->bJPEGdecompress2 = MNG_FALSE; /* indicate it's done */ + +#endif /* MNG_INCLUDE_IJG6B */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_INCLUDE_JNG_READ */ + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_JNG && MNG_INCLUDE_DISPLAY_PROCS */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + diff --git a/Source/LibMNG/libmng_object_prc.c b/Source/LibMNG/libmng_object_prc.c index 570d346..f6691ff 100644 --- a/Source/LibMNG/libmng_object_prc.c +++ b/Source/LibMNG/libmng_object_prc.c @@ -1,6998 +1,6998 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_object_prc.c copyright (c) 2000-2007 G.Juyn * */ -/* * version : 1.0.10 * */ -/* * * */ -/* * purpose : Object processing routines (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the internal object processing routines * */ -/* * * */ -/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - changed trace to macro for callback error-reporting * */ -/* * * */ -/* * 0.5.2 - 05/20/2000 - G.Juyn * */ -/* * - fixed to support JNG objects * */ -/* * 0.5.2 - 05/24/2000 - G.Juyn * */ -/* * - added support for global color-chunks in animation * */ -/* * - added support for global PLTE,tRNS,bKGD in animation * */ -/* * - added SAVE & SEEK animation objects * */ -/* * 0.5.2 - 05/29/2000 - G.Juyn * */ -/* * - added initialization of framenr/layernr/playtime * */ -/* * - changed ani_object create routines not to return the * */ -/* * created object (wasn't necessary) * */ -/* * 0.5.2 - 05/30/2000 - G.Juyn * */ -/* * - added object promotion routine (PROM handling) * */ -/* * - added ani-object routines for delta-image processing * */ -/* * - added compression/filter/interlace fields to * */ -/* * object-buffer for delta-image processing * */ -/* * * */ -/* * 0.5.3 - 06/17/2000 - G.Juyn * */ -/* * - changed support for delta-image processing * */ -/* * 0.5.3 - 06/20/2000 - G.Juyn * */ -/* * - fixed some small things (as precaution) * */ -/* * 0.5.3 - 06/21/2000 - G.Juyn * */ -/* * - added processing of PLTE/tRNS & color-info for * */ -/* * delta-images in the ani_objects chain * */ -/* * 0.5.3 - 06/22/2000 - G.Juyn * */ -/* * - added support for PPLT chunk * */ -/* * * */ -/* * 0.9.1 - 07/07/2000 - G.Juyn * */ -/* * - added support for freeze/restart/resume & go_xxxx * */ -/* * 0.9.1 - 07/16/2000 - G.Juyn * */ -/* * - fixed support for mng_display() after mng_read() * */ -/* * * */ -/* * 0.9.2 - 07/29/2000 - G.Juyn * */ -/* * - fixed small bugs in display processing * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 0.9.3 - 08/07/2000 - G.Juyn * */ -/* * - B111300 - fixup for improved portability * */ -/* * 0.9.3 - 08/26/2000 - G.Juyn * */ -/* * - added MAGN chunk * */ -/* * 0.9.3 - 09/10/2000 - G.Juyn * */ -/* * - fixed DEFI behavior * */ -/* * 0.9.3 - 10/17/2000 - G.Juyn * */ -/* * - added valid-flag to stored objects for read() / display()* */ -/* * - added routine to discard "invalid" objects * */ -/* * 0.9.3 - 10/18/2000 - G.Juyn * */ -/* * - fixed delta-processing behavior * */ -/* * 0.9.3 - 10/19/2000 - G.Juyn * */ -/* * - added storage for pixel-/alpha-sampledepth for delta's * */ -/* * * */ -/* * 0.9.4 - 1/18/2001 - G.Juyn * */ -/* * - removed "old" MAGN methods 3 & 4 * */ -/* * - added "new" MAGN methods 3, 4 & 5 * */ -/* * * */ -/* * 0.9.5 - 1/22/2001 - G.Juyn * */ -/* * - B129681 - fixed compiler warnings SGI/Irix * */ -/* * * */ -/* * 1.0.2 - 06/23/2001 - G.Juyn * */ -/* * - added optimization option for MNG-video playback * */ -/* * * */ -/* * 1.0.5 - 08/15/2002 - G.Juyn * */ -/* * - completed PROM support * */ -/* * 1.0.5 - 08/16/2002 - G.Juyn * */ -/* * - completed MAGN support (16-bit functions) * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * 1.0.5 - 09/13/2002 - G.Juyn * */ -/* * - fixed read/write of MAGN chunk * */ -/* * 1.0.5 - 09/15/2002 - G.Juyn * */ -/* * - added event handling for dynamic MNG * */ -/* * 1.0.5 - 09/20/2002 - G.Juyn * */ -/* * - added support for PAST * */ -/* * 1.0.5 - 09/23/2002 - G.Juyn * */ -/* * - fixed reset_object_detail to clear old buffer * */ -/* * - added in-memory color-correction of abstract images * */ -/* * 1.0.5 - 10/05/2002 - G.Juyn * */ -/* * - fixed problem with cloned objects marked as invalid * */ -/* * - fixed problem cloning frozen object_buffers * */ -/* * 1.0.5 - 10/07/2002 - G.Juyn * */ -/* * - fixed DISC support * */ -/* * 1.0.5 - 11/04/2002 - G.Juyn * */ -/* * - fixed goframe/golayer/gotime processing * */ -/* * 1.0.5 - 11/07/2002 - G.Juyn * */ -/* * - fixed magnification bug with object 0 * */ -/* * 1.0.5 - 01/19/2003 - G.Juyn * */ -/* * - B664911 - fixed buffer overflow during init * */ -/* * * */ -/* * 1.0.6 - 04/19/2003 - G.Juyn * */ -/* * - fixed problem with infinite loops during readdisplay() * */ -/* * 1.0.6 - 05/25/2003 - G.R-P * */ -/* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */ -/* * 1.0.6 - 06/09/2003 - G. R-P * */ -/* * - added conditionals around 8-bit magn routines * */ -/* * 1.0.6 - 07/07/2003 - G.R-P * */ -/* * - added conditionals around some JNG-supporting code * */ -/* * - removed conditionals around 8-bit magn routines * */ -/* * - added conditionals around delta-png and 16-bit code * */ -/* * 1.0.6 - 07/14/2003 - G.R-P * */ -/* * - added MNG_NO_LOOP_SIGNALS_SUPPORTED conditional * */ -/* * 1.0.6 - 07/29/2003 - G.Juyn * */ -/* * - fixed invalid test in promote_imageobject * */ -/* * 1.0.6 - 07/29/2003 - G.R-P. * */ -/* * - added conditionals around PAST chunk support * */ -/* * 1.0.6 - 08/17/2003 - G.R-P. * */ -/* * - added conditionals around MAGN chunk support * */ -/* * * */ -/* * 1.0.7 - 03/21/2004 - G.Juyn * */ -/* * - fixed some 64-bit platform compiler warnings * */ -/* * * */ -/* * 1.0.9 - 10/10/2004 - G.R-P. * */ -/* * - added MNG_NO_1_2_4BIT_SUPPORT support * */ -/* * 1.0.9 - 12/05/2004 - G.Juyn * */ -/* * - added conditional MNG_OPTIMIZE_OBJCLEANUP * */ -/* * 1.0.9 - 12/11/2004 - G.Juyn * */ -/* * - added conditional MNG_OPTIMIZE_DISPLAYCALLS * */ -/* * 1.0.9 - 12/31/2004 - G.R-P. * */ -/* * - fixed warnings about possible uninitialized pointers * */ -/* * 1.0.9 - 01/02/2005 - G.Juyn * */ -/* * - fixing some compiler-warnings * */ -/* * * */ -/* * 1.0.10 - 02/07/2005 - G.Juyn * */ -/* * - fixed some compiler-warnings * */ -/* * 1.0.10 - 07/30/2005 - G.Juyn * */ -/* * - fixed problem with CLON object during readdisplay() * */ -/* * 1.0.10 - 04/08/2007 - G.Juyn * */ -/* * - added support for mPNG proposal * */ -/* * 1.0.10 - 04/12/2007 - G.Juyn * */ -/* * - added support for ANG proposal * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_memory.h" -#include "libmng_chunks.h" -#include "libmng_objects.h" -#include "libmng_display.h" -#include "libmng_pixels.h" -#include "libmng_object_prc.h" -#include "libmng_cms.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_DISPLAY_PROCS - -/* ************************************************************************** */ -/* * * */ -/* * Generic object routines * */ -/* * * */ -/* ************************************************************************** */ - -mng_retcode mng_drop_invalid_objects (mng_datap pData) -{ - mng_objectp pObject; - mng_objectp pNext; - mng_cleanupobject fCleanup; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DROP_INVALID_OBJECTS, MNG_LC_START); -#endif - - pObject = pData->pFirstimgobj; /* get first stored image-object (if any) */ - - while (pObject) /* more objects to check ? */ - { - pNext = ((mng_object_headerp)pObject)->pNext; - /* invalid ? */ - if (!((mng_imagep)pObject)->bValid) - { /* call appropriate cleanup */ - fCleanup = ((mng_object_headerp)pObject)->fCleanup; - fCleanup (pData, pObject); - } - - pObject = pNext; /* neeeext */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DROP_INVALID_OBJECTS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifdef MNG_OPTIMIZE_OBJCLEANUP -MNG_LOCAL mng_retcode create_obj_general (mng_datap pData, - mng_size_t iObjsize, - mng_cleanupobject fCleanup, - mng_processobject fProcess, - mng_ptr *ppObject) -{ - mng_object_headerp pWork; - - MNG_ALLOC (pData, pWork, iObjsize); - - pWork->fCleanup = fCleanup; - pWork->fProcess = fProcess; - pWork->iObjsize = iObjsize; - *ppObject = (mng_ptr)pWork; - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode mng_free_obj_general (mng_datap pData, - mng_objectp pObject) -{ - MNG_FREEX (pData, pObject, ((mng_object_headerp)pObject)->iObjsize); - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ -/* * * */ -/* * Image-data-object routines * */ -/* * * */ -/* * these handle the "object buffer" as defined by the MNG specification * */ -/* * * */ -/* ************************************************************************** */ - -mng_retcode mng_create_imagedataobject (mng_datap pData, - mng_bool bConcrete, - mng_bool bViewable, - mng_uint32 iWidth, - mng_uint32 iHeight, - mng_uint8 iBitdepth, - mng_uint8 iColortype, - mng_uint8 iCompression, - mng_uint8 iFilter, - mng_uint8 iInterlace, - mng_imagedatap *ppObject) -{ - mng_imagedatap pImagedata; - mng_uint32 iSamplesize = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_IMGDATAOBJECT, MNG_LC_START); -#endif - /* get a buffer */ -#ifdef MNG_OPTIMIZE_OBJCLEANUP - { - mng_ptr pTemp; - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_imagedata), - (mng_cleanupobject)mng_free_imagedataobject, - MNG_NULL, &pTemp); - if (iRetcode) - return iRetcode; - pImagedata = (mng_imagedatap)pTemp; - } -#else - MNG_ALLOC (pData, pImagedata, sizeof (mng_imagedata)); - /* fill the appropriate fields */ - pImagedata->sHeader.fCleanup = (mng_cleanupobject)mng_free_imagedataobject; - pImagedata->sHeader.fProcess = MNG_NULL; -#endif - pImagedata->iRefcount = 1; - pImagedata->bFrozen = MNG_FALSE; - pImagedata->bConcrete = bConcrete; - pImagedata->bViewable = bViewable; - pImagedata->iWidth = iWidth; - pImagedata->iHeight = iHeight; - pImagedata->iBitdepth = iBitdepth; - pImagedata->iColortype = iColortype; - pImagedata->iCompression = iCompression; - pImagedata->iFilter = iFilter; - pImagedata->iInterlace = iInterlace; - pImagedata->bCorrected = MNG_FALSE; - pImagedata->iAlphabitdepth = 0; - pImagedata->iJHDRcompression = 0; - pImagedata->iJHDRinterlace = 0; - pImagedata->iPixelsampledepth = iBitdepth; - pImagedata->iAlphasampledepth = iBitdepth; - /* determine samplesize from color_type/bit_depth */ - switch (iColortype) /* for < 8-bit samples we just reserve 8 bits */ - { - case 0 : ; /* gray */ - case 8 : { /* JPEG gray */ -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth > 8) - iSamplesize = 2; - else -#endif - iSamplesize = 1; - - break; - } - case 2 : ; /* rgb */ - case 10 : { /* JPEG rgb */ -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth > 8) - iSamplesize = 6; - else -#endif - iSamplesize = 3; - - break; - } - case 3 : { /* indexed */ - iSamplesize = 1; - break; - } - case 4 : ; /* gray+alpha */ - case 12 : { /* JPEG gray+alpha */ -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth > 8) - iSamplesize = 4; - else -#endif - iSamplesize = 2; - - break; - } - case 6 : ; /* rgb+alpha */ - case 14 : { /* JPEG rgb+alpha */ -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth > 8) - iSamplesize = 8; - else -#endif - iSamplesize = 4; - - break; - } - } - /* make sure we remember all this */ - pImagedata->iSamplesize = iSamplesize; - pImagedata->iRowsize = iSamplesize * iWidth; - pImagedata->iImgdatasize = pImagedata->iRowsize * iHeight; - - if (pImagedata->iImgdatasize) /* need a buffer ? */ - { /* so allocate it */ - MNG_ALLOCX (pData, pImagedata->pImgdata, pImagedata->iImgdatasize); - - if (!pImagedata->pImgdata) /* enough memory ? */ - { - MNG_FREEX (pData, pImagedata, sizeof (mng_imagedata)); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - } - /* check global stuff */ - pImagedata->bHasGAMA = pData->bHasglobalGAMA; -#ifndef MNG_SKIPCHUNK_cHRM - pImagedata->bHasCHRM = pData->bHasglobalCHRM; -#endif - pImagedata->bHasSRGB = pData->bHasglobalSRGB; -#ifndef MNG_SKIPCHUNK_iCCP - pImagedata->bHasICCP = pData->bHasglobalICCP; -#endif -#ifndef MNG_SKIPCHUNK_bKGD - pImagedata->bHasBKGD = pData->bHasglobalBKGD; -#endif - - if (pData->bHasglobalGAMA) /* global gAMA present ? */ - pImagedata->iGamma = pData->iGlobalGamma; - -#ifndef MNG_SKIPCHUNK_cHRM - if (pData->bHasglobalCHRM) /* global cHRM present ? */ - { - pImagedata->iWhitepointx = pData->iGlobalWhitepointx; - pImagedata->iWhitepointy = pData->iGlobalWhitepointy; - pImagedata->iPrimaryredx = pData->iGlobalPrimaryredx; - pImagedata->iPrimaryredy = pData->iGlobalPrimaryredy; - pImagedata->iPrimarygreenx = pData->iGlobalPrimarygreenx; - pImagedata->iPrimarygreeny = pData->iGlobalPrimarygreeny; - pImagedata->iPrimarybluex = pData->iGlobalPrimarybluex; - pImagedata->iPrimarybluey = pData->iGlobalPrimarybluey; - } -#endif - - if (pData->bHasglobalSRGB) /* glbal sRGB present ? */ - pImagedata->iRenderingintent = pData->iGlobalRendintent; - -#ifndef MNG_SKIPCHUNK_iCCP - if (pData->bHasglobalICCP) /* glbal iCCP present ? */ - { - pImagedata->iProfilesize = pData->iGlobalProfilesize; - - if (pImagedata->iProfilesize) - { - MNG_ALLOCX (pData, pImagedata->pProfile, pImagedata->iProfilesize); - - if (!pImagedata->pProfile) /* enough memory ? */ - { - MNG_FREEX (pData, pImagedata->pImgdata, pImagedata->iImgdatasize); - MNG_FREEX (pData, pImagedata, sizeof (mng_imagedata)); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - - MNG_COPY (pImagedata->pProfile, pData->pGlobalProfile, pImagedata->iProfilesize); - } - } -#endif - -#ifndef MNG_SKIPCHUNK_bKGD - if (pData->bHasglobalBKGD) /* global bKGD present ? */ - { - pImagedata->iBKGDred = pData->iGlobalBKGDred; - pImagedata->iBKGDgreen = pData->iGlobalBKGDgreen; - pImagedata->iBKGDblue = pData->iGlobalBKGDblue; - } -#endif - - *ppObject = pImagedata; /* return it */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_IMGDATAOBJECT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_free_imagedataobject (mng_datap pData, - mng_imagedatap pImagedata) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_IMGDATAOBJECT, MNG_LC_START); -#endif - - if (pImagedata->iRefcount) /* decrease reference count */ - pImagedata->iRefcount--; - - if (!pImagedata->iRefcount) /* reached zero ? */ - { -#ifndef MNG_SKIPCHUNK_iCCP - if (pImagedata->iProfilesize) /* stored an iCCP profile ? */ - MNG_FREEX (pData, pImagedata->pProfile, pImagedata->iProfilesize); -#endif - if (pImagedata->iImgdatasize) /* sample-buffer present ? */ - MNG_FREEX (pData, pImagedata->pImgdata, pImagedata->iImgdatasize); - /* drop the buffer */ - MNG_FREEX (pData, pImagedata, sizeof (mng_imagedata)); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_IMGDATAOBJECT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_clone_imagedataobject (mng_datap pData, - mng_bool bConcrete, - mng_imagedatap pSource, - mng_imagedatap *ppClone) -{ - mng_imagedatap pNewdata; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CLONE_IMGDATAOBJECT, MNG_LC_START); -#endif - /* get a buffer */ - MNG_ALLOC (pData, pNewdata, sizeof (mng_imagedata)); - /* blatently copy the original buffer */ - MNG_COPY (pNewdata, pSource, sizeof (mng_imagedata)); - - pNewdata->iRefcount = 1; /* only the reference count */ - pNewdata->bConcrete = bConcrete; /* and concrete-flag are different */ - pNewdata->bFrozen = MNG_FALSE; - - if (pNewdata->iImgdatasize) /* sample buffer present ? */ - { - MNG_ALLOCX (pData, pNewdata->pImgdata, pNewdata->iImgdatasize); - - if (!pNewdata->pImgdata) /* not enough memory ? */ - { - MNG_FREEX (pData, pNewdata, sizeof (mng_imagedata)); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - /* make a copy */ - MNG_COPY (pNewdata->pImgdata, pSource->pImgdata, pNewdata->iImgdatasize); - } - -#ifndef MNG_SKIPCHUNK_iCCP - if (pNewdata->iProfilesize) /* iCCP profile present ? */ - { - MNG_ALLOCX (pData, pNewdata->pProfile, pNewdata->iProfilesize); - - if (!pNewdata->pProfile) /* enough memory ? */ - { - MNG_FREEX (pData, pNewdata, sizeof (mng_imagedata)); - MNG_ERROR (pData, MNG_OUTOFMEMORY); - } - /* make a copy */ - MNG_COPY (pNewdata->pProfile, pSource->pProfile, pNewdata->iProfilesize); - } -#endif - - *ppClone = pNewdata; /* return the clone */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CLONE_IMGDATAOBJECT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ -/* * * */ -/* * Image-object routines * */ -/* * * */ -/* * these handle the "object" as defined by the MNG specification * */ -/* * * */ -/* ************************************************************************** */ - -mng_retcode mng_create_imageobject (mng_datap pData, - mng_uint16 iId, - mng_bool bConcrete, - mng_bool bVisible, - mng_bool bViewable, - mng_uint32 iWidth, - mng_uint32 iHeight, - mng_uint8 iBitdepth, - mng_uint8 iColortype, - mng_uint8 iCompression, - mng_uint8 iFilter, - mng_uint8 iInterlace, - mng_int32 iPosx, - mng_int32 iPosy, - mng_bool bClipped, - mng_int32 iClipl, - mng_int32 iClipr, - mng_int32 iClipt, - mng_int32 iClipb, - mng_imagep *ppObject) -{ - mng_imagep pImage; - mng_imagep pPrev, pNext; - mng_retcode iRetcode; - mng_imagedatap pImgbuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_IMGOBJECT, MNG_LC_START); -#endif - /* get a buffer */ - MNG_ALLOC (pData, pImage, sizeof (mng_image)); - /* now get a new "object buffer" */ - iRetcode = mng_create_imagedataobject (pData, bConcrete, bViewable, - iWidth, iHeight, iBitdepth, iColortype, - iCompression, iFilter, iInterlace, - &pImgbuf); - - if (iRetcode) /* on error bail out */ - { - MNG_FREEX (pData, pImage, sizeof (mng_image)); - return iRetcode; - } - /* fill the appropriate fields */ - pImage->sHeader.fCleanup = (mng_cleanupobject)mng_free_imageobject; - pImage->sHeader.fProcess = MNG_NULL; -#ifdef MNG_OPTIMIZE_OBJCLEANUP - pImage->sHeader.iObjsize = sizeof (mng_image); -#endif - pImage->iId = iId; - pImage->bFrozen = MNG_FALSE; - pImage->bVisible = bVisible; - pImage->bViewable = bViewable; - pImage->bValid = (mng_bool)((pData->bDisplaying) && - ((pData->bRunning) || (pData->bSearching)) && - (!pData->bFreezing)); - pImage->iPosx = iPosx; - pImage->iPosy = iPosy; - pImage->bClipped = bClipped; - pImage->iClipl = iClipl; - pImage->iClipr = iClipr; - pImage->iClipt = iClipt; - pImage->iClipb = iClipb; -#ifndef MNG_SKIPCHUNK_MAGN - pImage->iMAGN_MethodX = 0; - pImage->iMAGN_MethodY = 0; - pImage->iMAGN_MX = 0; - pImage->iMAGN_MY = 0; - pImage->iMAGN_ML = 0; - pImage->iMAGN_MR = 0; - pImage->iMAGN_MT = 0; - pImage->iMAGN_MB = 0; -#endif -#ifndef MNG_SKIPCHUNK_PAST - pImage->iPastx = 0; - pImage->iPasty = 0; -#endif - pImage->pImgbuf = pImgbuf; - - if (iId) /* only if not object 0 ! */ - { /* find previous lower object-id */ - pPrev = (mng_imagep)pData->pLastimgobj; - - while ((pPrev) && (pPrev->iId > iId)) - pPrev = (mng_imagep)pPrev->sHeader.pPrev; - - if (pPrev) /* found it ? */ - { - pImage->sHeader.pPrev = pPrev; /* than link it in place */ - pImage->sHeader.pNext = pPrev->sHeader.pNext; - pPrev->sHeader.pNext = pImage; - } - else /* if not found, it becomes the first ! */ - { - pImage->sHeader.pNext = pData->pFirstimgobj; - pData->pFirstimgobj = pImage; - } - - pNext = (mng_imagep)pImage->sHeader.pNext; - - if (pNext) - pNext->sHeader.pPrev = pImage; - else - pData->pLastimgobj = pImage; - - } - - *ppObject = pImage; /* and return the new buffer */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_IMGOBJECT, MNG_LC_END); -#endif - - return MNG_NOERROR; /* okido */ -} - -/* ************************************************************************** */ - -mng_retcode mng_free_imageobject (mng_datap pData, - mng_imagep pImage) -{ - mng_retcode iRetcode; - mng_imagep pPrev = pImage->sHeader.pPrev; - mng_imagep pNext = pImage->sHeader.pNext; - mng_imagedatap pImgbuf = pImage->pImgbuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_IMGOBJECT, MNG_LC_START); -#endif - - if (pImage->iId) /* not for object 0 */ - { - if (pPrev) /* unlink from the list first ! */ - pPrev->sHeader.pNext = pImage->sHeader.pNext; - else - pData->pFirstimgobj = pImage->sHeader.pNext; - - if (pNext) - pNext->sHeader.pPrev = pImage->sHeader.pPrev; - else - pData->pLastimgobj = pImage->sHeader.pPrev; - - } - /* unlink the image-data buffer */ - iRetcode = mng_free_imagedataobject (pData, pImgbuf); - /* drop its own buffer */ - MNG_FREEX (pData, pImage, sizeof (mng_image)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_IMGOBJECT, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -mng_imagep mng_find_imageobject (mng_datap pData, - mng_uint16 iId) -{ - mng_imagep pImage = (mng_imagep)pData->pFirstimgobj; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (pData, MNG_FN_FIND_IMGOBJECT, MNG_LC_START); -#endif - /* look up the right id */ - while ((pImage) && (pImage->iId != iId)) - pImage = (mng_imagep)pImage->sHeader.pNext; - -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - if ((!pImage) && (pData->eImagetype == mng_it_mpng)) - pImage = pData->pObjzero; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (pData, MNG_FN_FIND_IMGOBJECT, MNG_LC_END); -#endif - - return pImage; -} - -/* ************************************************************************** */ - -mng_retcode mng_clone_imageobject (mng_datap pData, - mng_uint16 iId, - mng_bool bPartial, - mng_bool bVisible, - mng_bool bAbstract, - mng_bool bHasloca, - mng_uint8 iLocationtype, - mng_int32 iLocationx, - mng_int32 iLocationy, - mng_imagep pSource, - mng_imagep *ppClone) -{ - mng_imagep pNew; - mng_imagep pPrev, pNext; - mng_retcode iRetcode; - mng_imagedatap pImgbuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CLONE_IMGOBJECT, MNG_LC_START); -#endif - -#ifndef MNG_SKIPCHUNK_MAGN - if ((pSource->iId) && /* needs magnification ? */ - ((pSource->iMAGN_MethodX) || (pSource->iMAGN_MethodY))) - { - iRetcode = mng_magnify_imageobject (pData, pSource); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif - /* get a buffer */ -#ifdef MNG_OPTIMIZE_OBJCLEANUP - { - mng_ptr pTemp; - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_image), - (mng_cleanupobject)mng_free_imageobject, - MNG_NULL, &pTemp); - if (iRetcode) - return iRetcode; - pNew = (mng_imagep)pTemp; - } -#else - MNG_ALLOC (pData, pNew, sizeof (mng_image)); - /* fill or copy the appropriate fields */ - pNew->sHeader.fCleanup = (mng_cleanupobject)mng_free_imageobject; - pNew->sHeader.fProcess = MNG_NULL; -#endif - pNew->iId = iId; - pNew->bFrozen = MNG_FALSE; - pNew->bVisible = bVisible; - pNew->bViewable = pSource->bViewable; - pNew->bValid = MNG_TRUE; - - if (bHasloca) /* location info available ? */ - { - if (iLocationtype == 0) /* absolute position ? */ - { - pNew->iPosx = iLocationx; - pNew->iPosy = iLocationy; - } - else /* relative */ - { - pNew->iPosx = pSource->iPosx + iLocationx; - pNew->iPosy = pSource->iPosy + iLocationy; - } - } - else /* copy from source */ - { - pNew->iPosx = pSource->iPosx; - pNew->iPosy = pSource->iPosy; - } - /* copy clipping info */ - pNew->bClipped = pSource->bClipped; - pNew->iClipl = pSource->iClipl; - pNew->iClipr = pSource->iClipr; - pNew->iClipt = pSource->iClipt; - pNew->iClipb = pSource->iClipb; -#ifndef MNG_SKIPCHUNK_MAGN - /* copy magnification info */ -/* pNew->iMAGN_MethodX = pSource->iMAGN_MethodX; LET'S NOT !!!!!! - pNew->iMAGN_MethodY = pSource->iMAGN_MethodY; - pNew->iMAGN_MX = pSource->iMAGN_MX; - pNew->iMAGN_MY = pSource->iMAGN_MY; - pNew->iMAGN_ML = pSource->iMAGN_ML; - pNew->iMAGN_MR = pSource->iMAGN_MR; - pNew->iMAGN_MT = pSource->iMAGN_MT; - pNew->iMAGN_MB = pSource->iMAGN_MB; */ -#endif - -#ifndef MNG_SKIPCHUNK_PAST - pNew->iPastx = 0; /* initialize PAST info */ - pNew->iPasty = 0; -#endif - - if (iId) /* not for object 0 */ - { /* find previous lower object-id */ - pPrev = (mng_imagep)pData->pLastimgobj; - while ((pPrev) && (pPrev->iId > iId)) - pPrev = (mng_imagep)pPrev->sHeader.pPrev; - - if (pPrev) /* found it ? */ - { - pNew->sHeader.pPrev = pPrev; /* than link it in place */ - pNew->sHeader.pNext = pPrev->sHeader.pNext; - pPrev->sHeader.pNext = pNew; - } - else /* if not found, it becomes the first ! */ - { - pNew->sHeader.pNext = pData->pFirstimgobj; - pData->pFirstimgobj = pNew; - } - - pNext = (mng_imagep)pNew->sHeader.pNext; - - if (pNext) - pNext->sHeader.pPrev = pNew; - else - pData->pLastimgobj = pNew; - - } - - if (bPartial) /* partial clone ? */ - { - pNew->pImgbuf = pSource->pImgbuf; /* use the same object buffer */ - pNew->pImgbuf->iRefcount++; /* and increase the reference count */ - } - else /* create a full clone ! */ - { - mng_bool bConcrete = MNG_FALSE; /* it's abstract by default (?) */ - - if (!bAbstract) /* determine concreteness from source ? */ - bConcrete = pSource->pImgbuf->bConcrete; - /* create a full clone ! */ - iRetcode = mng_clone_imagedataobject (pData, bConcrete, pSource->pImgbuf, &pImgbuf); - - if (iRetcode) /* on error bail out */ - { - MNG_FREEX (pData, pNew, sizeof (mng_image)); - return iRetcode; - } - - pNew->pImgbuf = pImgbuf; /* and remember it */ - } - - *ppClone = pNew; /* return it */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CLONE_IMGOBJECT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_renum_imageobject (mng_datap pData, - mng_imagep pSource, - mng_uint16 iId, - mng_bool bVisible, - mng_bool bAbstract, - mng_bool bHasloca, - mng_uint8 iLocationtype, - mng_int32 iLocationx, - mng_int32 iLocationy) -{ - mng_imagep pPrev, pNext; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RENUM_IMGOBJECT, MNG_LC_START); -#endif - - pSource->bVisible = bVisible; /* store the new visibility */ - - if (bHasloca) /* location info available ? */ - { - if (iLocationtype == 0) /* absolute position ? */ - { - pSource->iPosx = iLocationx; - pSource->iPosy = iLocationy; - } - else /* relative */ - { - pSource->iPosx = pSource->iPosx + iLocationx; - pSource->iPosy = pSource->iPosy + iLocationy; - } - } - - if (iId) /* not for object 0 */ - { /* find previous lower object-id */ - pPrev = (mng_imagep)pData->pLastimgobj; - while ((pPrev) && (pPrev->iId > iId)) - pPrev = (mng_imagep)pPrev->sHeader.pPrev; - /* different from current ? */ - if (pPrev != (mng_imagep)pSource->sHeader.pPrev) - { - if (pSource->sHeader.pPrev) /* unlink from current position !! */ - ((mng_imagep)pSource->sHeader.pPrev)->sHeader.pNext = pSource->sHeader.pNext; - else - pData->pFirstimgobj = pSource->sHeader.pNext; - - if (pSource->sHeader.pNext) - ((mng_imagep)pSource->sHeader.pNext)->sHeader.pPrev = pSource->sHeader.pPrev; - else - pData->pLastimgobj = pSource->sHeader.pPrev; - - if (pPrev) /* found the previous ? */ - { /* than link it in place */ - pSource->sHeader.pPrev = pPrev; - pSource->sHeader.pNext = pPrev->sHeader.pNext; - pPrev->sHeader.pNext = pSource; - } - else /* if not found, it becomes the first ! */ - { - pSource->sHeader.pNext = pData->pFirstimgobj; - pData->pFirstimgobj = pSource; - } - - pNext = (mng_imagep)pSource->sHeader.pNext; - - if (pNext) - pNext->sHeader.pPrev = pSource; - else - pData->pLastimgobj = pSource; - - } - } - - pSource->iId = iId; /* now set the new id! */ - - if (bAbstract) /* force it to abstract ? */ - pSource->pImgbuf->bConcrete = MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RENUM_IMGOBJECT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_reset_object_details (mng_datap pData, - mng_imagep pImage, - mng_uint32 iWidth, - mng_uint32 iHeight, - mng_uint8 iBitdepth, - mng_uint8 iColortype, - mng_uint8 iCompression, - mng_uint8 iFilter, - mng_uint8 iInterlace, - mng_bool bResetall) -{ - mng_imagedatap pBuf = pImage->pImgbuf; - mng_uint32 iSamplesize = 0; - mng_uint32 iRowsize; - mng_uint32 iImgdatasize; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESET_OBJECTDETAILS, MNG_LC_START); -#endif - - pBuf->iWidth = iWidth; /* set buffer characteristics */ - pBuf->iHeight = iHeight; - pBuf->iBitdepth = iBitdepth; - pBuf->iColortype = iColortype; - pBuf->iCompression = iCompression; - pBuf->iFilter = iFilter; - pBuf->iInterlace = iInterlace; - pBuf->bCorrected = MNG_FALSE; - pBuf->iAlphabitdepth = 0; - /* determine samplesize from color_type/bit_depth */ - switch (iColortype) /* for < 8-bit samples we just reserve 8 bits */ - { - case 0 : ; /* gray */ - case 8 : { /* JPEG gray */ -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth > 8) - iSamplesize = 2; - else -#endif - iSamplesize = 1; - - break; - } - case 2 : ; /* rgb */ - case 10 : { /* JPEG rgb */ -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth > 8) - iSamplesize = 6; - else -#endif - iSamplesize = 3; - - break; - } - case 3 : { /* indexed */ - iSamplesize = 1; - break; - } - case 4 : ; /* gray+alpha */ - case 12 : { /* JPEG gray+alpha */ -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth > 8) - iSamplesize = 4; - else -#endif - iSamplesize = 2; - - break; - } - case 6 : ; /* rgb+alpha */ - case 14 : { /* JPEG rgb+alpha */ -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth > 8) - iSamplesize = 8; - else -#endif - iSamplesize = 4; - - break; - } - } - - iRowsize = iSamplesize * iWidth; - iImgdatasize = iRowsize * iHeight; - /* buffer size changed ? */ - if (iImgdatasize != pBuf->iImgdatasize) - { /* drop the old one */ - MNG_FREE (pData, pBuf->pImgdata, pBuf->iImgdatasize); - - if (iImgdatasize) /* allocate new sample-buffer ? */ - MNG_ALLOC (pData, pBuf->pImgdata, iImgdatasize); - } - else - { - if (iImgdatasize) /* clear old buffer */ - { - mng_uint8p pTemp = pBuf->pImgdata; - mng_uint32 iX; - - for (iX = 0; iX < (iImgdatasize & (mng_uint32)(~3L)); iX += 4) - { - *((mng_uint32p)pTemp) = 0x00000000l; - pTemp += 4; - } - - while (pTemp < (pBuf->pImgdata + iImgdatasize)) - { - *pTemp = 0; - pTemp++; - } - } - } - - pBuf->iSamplesize = iSamplesize; /* remember new sizes */ - pBuf->iRowsize = iRowsize; - pBuf->iImgdatasize = iImgdatasize; - - if (!pBuf->iPixelsampledepth) /* set delta sampledepths if empty */ - pBuf->iPixelsampledepth = iBitdepth; - if (!pBuf->iAlphasampledepth) - pBuf->iAlphasampledepth = iBitdepth; - /* dimension set and clipping not ? */ - if ((iWidth) && (iHeight) && (!pImage->bClipped)) - { - pImage->iClipl = 0; /* set clipping to dimension by default */ - pImage->iClipr = iWidth; - pImage->iClipt = 0; - pImage->iClipb = iHeight; - } - -#ifndef MNG_SKIPCHUNK_MAGN - if (pImage->iId) /* reset magnification info ? */ - { - pImage->iMAGN_MethodX = 0; - pImage->iMAGN_MethodY = 0; - pImage->iMAGN_MX = 0; - pImage->iMAGN_MY = 0; - pImage->iMAGN_ML = 0; - pImage->iMAGN_MR = 0; - pImage->iMAGN_MT = 0; - pImage->iMAGN_MB = 0; - } -#endif - - if (bResetall) /* reset the other characteristics ? */ - { -#ifndef MNG_SKIPCHUNK_PAST - pImage->iPastx = 0; - pImage->iPasty = 0; -#endif - - pBuf->bHasPLTE = MNG_FALSE; - pBuf->bHasTRNS = MNG_FALSE; - pBuf->bHasGAMA = pData->bHasglobalGAMA; -#ifndef MNG_SKIPCHUNK_cHRM - pBuf->bHasCHRM = pData->bHasglobalCHRM; -#endif - pBuf->bHasSRGB = pData->bHasglobalSRGB; -#ifndef MNG_SKIPCHUNK_iCCP - pBuf->bHasICCP = pData->bHasglobalICCP; -#endif -#ifndef MNG_SKIPCHUNK_bKGD - pBuf->bHasBKGD = pData->bHasglobalBKGD; -#endif - -#ifndef MNG_SKIPCHUNK_iCCP - if (pBuf->iProfilesize) /* drop possibly old ICC profile */ - { - MNG_FREE (pData, pBuf->pProfile, pBuf->iProfilesize); - pBuf->iProfilesize = 0; - } -#endif - - if (pData->bHasglobalGAMA) /* global gAMA present ? */ - pBuf->iGamma = pData->iGlobalGamma; - -#ifndef MNG_SKIPCHUNK_cHRM - if (pData->bHasglobalCHRM) /* global cHRM present ? */ - { - pBuf->iWhitepointx = pData->iGlobalWhitepointx; - pBuf->iWhitepointy = pData->iGlobalWhitepointy; - pBuf->iPrimaryredx = pData->iGlobalPrimaryredx; - pBuf->iPrimaryredy = pData->iGlobalPrimaryredy; - pBuf->iPrimarygreenx = pData->iGlobalPrimarygreenx; - pBuf->iPrimarygreeny = pData->iGlobalPrimarygreeny; - pBuf->iPrimarybluex = pData->iGlobalPrimarybluex; - pBuf->iPrimarybluey = pData->iGlobalPrimarybluey; - } -#endif - - if (pData->bHasglobalSRGB) /* global sRGB present ? */ - pBuf->iRenderingintent = pData->iGlobalRendintent; - -#ifndef MNG_SKIPCHUNK_iCCP - if (pData->bHasglobalICCP) /* global iCCP present ? */ - { - if (pData->iGlobalProfilesize) - { - MNG_ALLOC (pData, pBuf->pProfile, pData->iGlobalProfilesize); - MNG_COPY (pBuf->pProfile, pData->pGlobalProfile, pData->iGlobalProfilesize); - } - - pBuf->iProfilesize = pData->iGlobalProfilesize; - } -#endif - -#ifndef MNG_SKIPCHUNK_bKGD - if (pData->bHasglobalBKGD) /* global bKGD present ? */ - { - pBuf->iBKGDred = pData->iGlobalBKGDred; - pBuf->iBKGDgreen = pData->iGlobalBKGDgreen; - pBuf->iBKGDblue = pData->iGlobalBKGDblue; - } -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESET_OBJECTDETAILS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#if !defined(MNG_NO_DELTA_PNG) || !defined(MNG_SKIPCHUNK_PAST) || !defined(MNG_SKIPCHUNK_MAGN) -mng_retcode mng_promote_imageobject (mng_datap pData, - mng_imagep pImage, - mng_uint8 iBitdepth, - mng_uint8 iColortype, - mng_uint8 iFilltype) -{ - mng_retcode iRetcode = MNG_NOERROR; - mng_imagedatap pBuf = pImage->pImgbuf; - mng_uint32 iW = pBuf->iWidth; - mng_uint32 iH = pBuf->iHeight; - mng_uint8p pNewbuf; - mng_uint32 iNewbufsize; - mng_uint32 iNewrowsize; - mng_uint32 iNewsamplesize = pBuf->iSamplesize; - mng_uint32 iY; - mng_uint8 iTempdepth; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_IMGOBJECT, MNG_LC_START); -#endif - -#ifdef MNG_NO_1_2_4BIT_SUPPORT - if (iBitdepth < 8) - iBitdepth=8; - if (pBuf->iBitdepth < 8) - pBuf->iBitdepth=8; -#endif -#ifdef MNG_NO_16BIT_SUPPORT - if (iBitdepth > 8) - iBitdepth=8; - if (pBuf->iBitdepth > 8) - pBuf->iBitdepth=8; -#endif - - pData->fPromoterow = MNG_NULL; /* init promotion fields */ - pData->fPromBitdepth = MNG_NULL; - pData->iPromColortype = iColortype; - pData->iPromBitdepth = iBitdepth; - pData->iPromFilltype = iFilltype; - - if (iBitdepth != pBuf->iBitdepth) /* determine bitdepth promotion */ - { - if (pBuf->iColortype == MNG_COLORTYPE_INDEXED) - iTempdepth = 8; - else - iTempdepth = pBuf->iBitdepth; - -#ifndef MNG_NO_DELTA_PNG - if (iFilltype == MNG_FILLMETHOD_ZEROFILL) - { - switch (iTempdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { - switch (iBitdepth) - { - case 2 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_1_2; break; } - case 4 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_1_4; break; } - case 8 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_1_8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_1_16; break; } -#endif - } - break; - } - case 2 : { - switch (iBitdepth) - { - case 4 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_2_4; break; } - case 8 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_2_8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_2_16; break; } -#endif - } - break; - } - case 4 : { - switch (iBitdepth) - { - case 8 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_4_8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_4_16; break; } -#endif - } - break; - } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_8_16; -#endif - break; - } - } - } - else -#endif - { - switch (iTempdepth) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case 1 : { - switch (iBitdepth) - { - case 2 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_1_2; break; } - case 4 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_1_4; break; } - case 8 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_1_8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_1_16; break; } -#endif - } - break; - } - case 2 : { - switch (iBitdepth) - { - case 4 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_2_4; break; } - case 8 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_2_8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_2_16; break; } -#endif - } - break; - } - case 4 : { - switch (iBitdepth) - { - case 8 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_4_8; break; } -#ifndef MNG_NO_16BIT_SUPPORT - case 16 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_4_16; break; } -#endif - } - break; - } -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case 8 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_8_16; -#endif - break; - } - } - } - } - /* g -> g */ - if ((pBuf->iColortype == MNG_COLORTYPE_GRAY) && - (iColortype == MNG_COLORTYPE_GRAY)) - { - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_g8_g16; - else -#endif - pData->fPromoterow = (mng_fptr)mng_promote_g8_g8; - } - - iNewsamplesize = 1; - -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 2; -#endif - } - else /* g -> ga */ - if ((pBuf->iColortype == MNG_COLORTYPE_GRAY) && - (iColortype == MNG_COLORTYPE_GRAYA)) - { - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_g8_ga16; - else -#endif - pData->fPromoterow = (mng_fptr)mng_promote_g8_ga8; - } -#ifndef MNG_NO_16BIT_SUPPORT - else /* source = 16 bits */ - pData->fPromoterow = (mng_fptr)mng_promote_g16_ga16; -#endif - - iNewsamplesize = 2; - -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 4; -#endif - } - else /* g -> rgb */ - if ((pBuf->iColortype == MNG_COLORTYPE_GRAY) && - (iColortype == MNG_COLORTYPE_RGB)) - { - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_g8_rgb16; - else -#endif - pData->fPromoterow = (mng_fptr)mng_promote_g8_rgb8; - } -#ifndef MNG_NO_16BIT_SUPPORT - else /* source = 16 bits */ - pData->fPromoterow = (mng_fptr)mng_promote_g16_rgb16; -#endif - - iNewsamplesize = 3; - -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 6; -#endif - } - else /* g -> rgba */ - if ((pBuf->iColortype == MNG_COLORTYPE_GRAY) && - (iColortype == MNG_COLORTYPE_RGBA)) - { - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_g8_rgba16; - else -#endif - pData->fPromoterow = (mng_fptr)mng_promote_g8_rgba8; - } -#ifndef MNG_NO_16BIT_SUPPORT - else /* source = 16 bits */ - pData->fPromoterow = (mng_fptr)mng_promote_g16_rgba16; -#endif - - iNewsamplesize = 4; - -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 8; -#endif - } - else /* ga -> ga */ - if ((pBuf->iColortype == MNG_COLORTYPE_GRAYA) && - (iColortype == MNG_COLORTYPE_GRAYA)) - { - iNewsamplesize = 2; -#ifndef MNG_NO_16BIT_SUPPORT - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_ga8_ga16; - if (iBitdepth == 16) - iNewsamplesize = 4; -#endif - } - else /* ga -> rgba */ - if ((pBuf->iColortype == MNG_COLORTYPE_GRAYA) && - (iColortype == MNG_COLORTYPE_RGBA)) - { - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_ga8_rgba16; - else -#endif - pData->fPromoterow = (mng_fptr)mng_promote_ga8_rgba8; - } -#ifndef MNG_NO_16BIT_SUPPORT - else /* source = 16 bits */ - pData->fPromoterow = (mng_fptr)mng_promote_ga16_rgba16; -#endif - - iNewsamplesize = 4; - -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 8; -#endif - } - else /* rgb -> rgb */ - if ((pBuf->iColortype == MNG_COLORTYPE_RGB) && - (iColortype == MNG_COLORTYPE_RGB)) - { - iNewsamplesize = 3; -#ifndef MNG_NO_16BIT_SUPPORT - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_rgb8_rgb16; - if (iBitdepth == 16) - iNewsamplesize = 6; -#endif - } - else /* rgb -> rgba */ - if ((pBuf->iColortype == MNG_COLORTYPE_RGB) && - (iColortype == MNG_COLORTYPE_RGBA)) - { - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_rgb8_rgba16; - else -#endif - pData->fPromoterow = (mng_fptr)mng_promote_rgb8_rgba8; - } -#ifndef MNG_NO_16BIT_SUPPORT - else /* source = 16 bits */ - pData->fPromoterow = (mng_fptr)mng_promote_rgb16_rgba16; -#endif - - iNewsamplesize = 4; -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 8; -#endif - } - else /* indexed -> rgb */ - if ((pBuf->iColortype == MNG_COLORTYPE_INDEXED) && - (iColortype == MNG_COLORTYPE_RGB)) - { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_idx8_rgb16; - else -#endif - pData->fPromoterow = (mng_fptr)mng_promote_idx8_rgb8; - - iNewsamplesize = 3; - -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 6; -#endif - } - else /* indexed -> rgba */ - if ((pBuf->iColortype == MNG_COLORTYPE_INDEXED) && - (iColortype == MNG_COLORTYPE_RGBA)) - { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_idx8_rgba16; - else -#endif - pData->fPromoterow = (mng_fptr)mng_promote_idx8_rgba8; - - iNewsamplesize = 4; - -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 8; -#endif - } - else /* rgba -> rgba */ - if ((pBuf->iColortype == MNG_COLORTYPE_RGBA) && - (iColortype == MNG_COLORTYPE_RGBA)) - { - iNewsamplesize = 4; -#ifndef MNG_NO_16BIT_SUPPORT - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - { - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_rgba8_rgba16; - } - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 8; -#endif - } -#ifdef MNG_INCLUDE_JNG - else /* JPEG g -> g */ - if ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAY) && - (iColortype == MNG_COLORTYPE_JPEGGRAY)) - { - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_g8_g16; - else -#endif - pData->fPromoterow = (mng_fptr)mng_promote_g8_g8; - } - - iNewsamplesize = 1; - -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 2; -#endif - } - else /* JPEG g -> ga */ - if ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAY) && - (iColortype == MNG_COLORTYPE_JPEGGRAYA)) - { - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_g8_ga16; - else -#endif - pData->fPromoterow = (mng_fptr)mng_promote_g8_ga8; - } -#ifndef MNG_NO_16BIT_SUPPORT - else /* source = 16 bits */ - pData->fPromoterow = (mng_fptr)mng_promote_g16_ga16; -#endif - - iNewsamplesize = 2; - -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 4; -#endif - } - else /* JPEG g -> rgb */ - if ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAY) && - (iColortype == MNG_COLORTYPE_JPEGCOLOR)) - { - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_g8_rgb16; - else -#endif - pData->fPromoterow = (mng_fptr)mng_promote_g8_rgb8; - } -#ifndef MNG_NO_16BIT_SUPPORT - else /* source = 16 bits */ - pData->fPromoterow = (mng_fptr)mng_promote_g16_rgb16; -#endif - - iNewsamplesize = 3; - -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 6; -#endif - } - else /* JPEG g -> rgba */ - if ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAY) && - (iColortype == MNG_COLORTYPE_JPEGCOLORA)) - { - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_g8_rgba16; - else -#endif - pData->fPromoterow = (mng_fptr)mng_promote_g8_rgba8; - } -#ifndef MNG_NO_16BIT_SUPPORT - else /* source = 16 bits */ - pData->fPromoterow = (mng_fptr)mng_promote_g16_rgba16; -#endif - - iNewsamplesize = 4; - -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 8; -#endif - } - else /* JPEG ga -> ga */ - if ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAYA) && - (iColortype == MNG_COLORTYPE_JPEGGRAYA)) - { - iNewsamplesize = 2; -#ifndef MNG_NO_16BIT_SUPPORT - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_ga8_ga16; - if (iBitdepth == 16) - iNewsamplesize = 4; -#endif - - } - else /* JPEG ga -> rgba */ - if ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAYA) && - (iColortype == MNG_COLORTYPE_JPEGCOLORA)) - { - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_ga8_rgba16; - else -#endif - pData->fPromoterow = (mng_fptr)mng_promote_ga8_rgba8; - } -#ifndef MNG_NO_16BIT_SUPPORT - else /* source = 16 bits */ - pData->fPromoterow = (mng_fptr)mng_promote_ga16_rgba16; -#endif - - iNewsamplesize = 4; - -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 8; -#endif - } - else /* JPEG rgb -> rgb */ - if ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLOR) && - (iColortype == MNG_COLORTYPE_JPEGCOLOR)) - { - iNewsamplesize = 3; -#ifndef MNG_NO_16BIT_SUPPORT - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_rgb8_rgb16; - if (iBitdepth == 16) - iNewsamplesize = 6; -#endif - - } - else /* JPEG rgb -> rgba */ - if ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLOR) && - (iColortype == MNG_COLORTYPE_JPEGCOLORA)) - { - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - { -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_rgb8_rgba16; - else -#endif - pData->fPromoterow = (mng_fptr)mng_promote_rgb8_rgba8; - } -#ifndef MNG_NO_16BIT_SUPPORT - else /* source = 16 bits */ - pData->fPromoterow = (mng_fptr)mng_promote_rgb16_rgba16; -#endif - - iNewsamplesize = 4; - -#ifndef MNG_NO_16BIT_SUPPORT - if (iBitdepth == 16) /* 16-bit wide ? */ - iNewsamplesize = 8; -#endif - } - else /* JPEG rgba -> rgba */ - if ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLORA) && - (iColortype == MNG_COLORTYPE_JPEGCOLORA)) - { - iNewsamplesize = 4; -#ifndef MNG_NO_16BIT_SUPPORT - if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ - if (iBitdepth == 16) - pData->fPromoterow = (mng_fptr)mng_promote_rgba8_rgba16; - if (iBitdepth == 16) - iNewsamplesize = 8; -#endif - } -#endif /* JNG */ - - /* found a proper promotion ? */ - if (pData->fPromoterow) - { - pData->pPromBuf = (mng_ptr)pBuf; - pData->iPromWidth = pBuf->iWidth; - iNewrowsize = iW * iNewsamplesize; - iNewbufsize = iH * iNewrowsize; - - MNG_ALLOC (pData, pNewbuf, iNewbufsize); - - pData->pPromSrc = (mng_ptr)pBuf->pImgdata; - pData->pPromDst = (mng_ptr)pNewbuf; - iY = 0; - - while ((!iRetcode) && (iY < iH)) - { - iRetcode = ((mng_promoterow)pData->fPromoterow) (pData); - pData->pPromSrc = (mng_uint8p)pData->pPromSrc + pBuf->iRowsize; - pData->pPromDst = (mng_uint8p)pData->pPromDst + iNewrowsize; -/* pData->pPromSrc = (mng_ptr)((mng_uint32)pData->pPromSrc + pBuf->iRowsize); */ -/* pData->pPromDst = (mng_ptr)((mng_uint32)pData->pPromDst + iNewrowsize); */ - iY++; - } - - MNG_FREEX (pData, pBuf->pImgdata, pBuf->iImgdatasize); - - pBuf->iBitdepth = iBitdepth; - pBuf->iColortype = iColortype; - pBuf->iSamplesize = iNewsamplesize; - pBuf->iRowsize = iNewrowsize; - pBuf->iImgdatasize = iNewbufsize; - pBuf->pImgdata = pNewbuf; - pBuf->bHasPLTE = MNG_FALSE; - pBuf->iPLTEcount = 0; - pBuf->bHasTRNS = MNG_FALSE; - pBuf->iTRNScount = 0; - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_IMGOBJECT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MAGN -mng_retcode mng_magnify_imageobject (mng_datap pData, - mng_imagep pImage) -{ - mng_uint8p pNewdata; - mng_uint8p pSrcline1; - mng_uint8p pSrcline2; - mng_uint8p pTempline; - mng_uint8p pDstline; - mng_uint32 iNewrowsize; - mng_uint32 iNewsize; - mng_uint32 iY; - mng_int32 iS, iM; - mng_retcode iRetcode; - - mng_imagedatap pBuf = pImage->pImgbuf; - mng_uint32 iNewW = pBuf->iWidth; - mng_uint32 iNewH = pBuf->iHeight; - mng_magnify_x fMagnifyX = MNG_NULL; - mng_magnify_y fMagnifyY = MNG_NULL; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_IMGOBJECT, MNG_LC_START); -#endif - - if (pBuf->iColortype == MNG_COLORTYPE_INDEXED) /* indexed color ? */ - { /* concrete buffer ? */ - if ((pBuf->bConcrete) && (pImage->iId)) - MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); - -#ifndef MNG_OPTIMIZE_FOOTPRINT_MAGN - if (pBuf->iTRNScount) /* with transparency ? */ - iRetcode = mng_promote_imageobject (pData, pImage, 8, 6, 0); - else - iRetcode = mng_promote_imageobject (pData, pImage, 8, 2, 0); - - if (iRetcode) /* on error bail out */ - return iRetcode; -#endif - } - -#ifdef MNG_OPTIMIZE_FOOTPRINT_MAGN - /* Promote everything to RGBA, using fill method 0 (LBR) */ - iRetcode = mng_promote_imageobject (pData, pImage, 8, 6, 0); - if (iRetcode) /* on error bail out */ - return iRetcode; -#endif - - if (pImage->iMAGN_MethodX) /* determine new width */ - { - if (pImage->iMAGN_MethodX == 1) - { - iNewW = pImage->iMAGN_ML; - if (pBuf->iWidth > 1) - iNewW = iNewW + pImage->iMAGN_MR; - if (pBuf->iWidth > 2) - iNewW = iNewW + (pBuf->iWidth - 2) * (pImage->iMAGN_MX); - } - else - { - iNewW = pBuf->iWidth + pImage->iMAGN_ML - 1; - if (pBuf->iWidth > 2) - iNewW = iNewW + pImage->iMAGN_MR - 1; - if (pBuf->iWidth > 3) - iNewW = iNewW + (pBuf->iWidth - 3) * (pImage->iMAGN_MX - 1); - } - } - - if (pImage->iMAGN_MethodY) /* determine new height */ - { - if (pImage->iMAGN_MethodY == 1) - { - iNewH = pImage->iMAGN_MT; - if (pBuf->iHeight > 1) - iNewH = iNewH + pImage->iMAGN_ML; - if (pBuf->iHeight > 2) - iNewH = iNewH + (pBuf->iHeight - 2) * (pImage->iMAGN_MY); - } - else - { - iNewH = pBuf->iHeight + pImage->iMAGN_MT - 1; - if (pBuf->iHeight > 2) - iNewH = iNewH + pImage->iMAGN_MB - 1; - if (pBuf->iHeight > 3) - iNewH = iNewH + (pBuf->iHeight - 3) * (pImage->iMAGN_MY - 1); - } - } - /* get new buffer */ - iNewrowsize = iNewW * pBuf->iSamplesize; - iNewsize = iNewH * iNewrowsize; - - MNG_ALLOC (pData, pNewdata, iNewsize); - - switch (pBuf->iColortype) /* determine magnification routines */ - { -#ifndef MNG_OPTIMIZE_FOOTPRINT_MAGN - case 0 : ; - case 8 : { - if (pBuf->iBitdepth <= 8) - { - switch (pImage->iMAGN_MethodX) - { - case 1 : { fMagnifyX = mng_magnify_g8_x1; break; } - case 2 : { fMagnifyX = mng_magnify_g8_x2; break; } - case 3 : { fMagnifyX = mng_magnify_g8_x3; break; } - case 4 : { fMagnifyX = mng_magnify_g8_x2; break; } - case 5 : { fMagnifyX = mng_magnify_g8_x3; break; } - } - - switch (pImage->iMAGN_MethodY) - { - case 1 : { fMagnifyY = mng_magnify_g8_y1; break; } - case 2 : { fMagnifyY = mng_magnify_g8_y2; break; } - case 3 : { fMagnifyY = mng_magnify_g8_y3; break; } - case 4 : { fMagnifyY = mng_magnify_g8_y2; break; } - case 5 : { fMagnifyY = mng_magnify_g8_y3; break; } - } - } -#ifndef MNG_NO_16BIT_SUPPORT - else - { - switch (pImage->iMAGN_MethodX) - { - case 1 : { fMagnifyX = mng_magnify_g16_x1; break; } - case 2 : { fMagnifyX = mng_magnify_g16_x2; break; } - case 3 : { fMagnifyX = mng_magnify_g16_x3; break; } - case 4 : { fMagnifyX = mng_magnify_g16_x2; break; } - case 5 : { fMagnifyX = mng_magnify_g16_x3; break; } - } - - switch (pImage->iMAGN_MethodY) - { - case 1 : { fMagnifyY = mng_magnify_g16_y1; break; } - case 2 : { fMagnifyY = mng_magnify_g16_y2; break; } - case 3 : { fMagnifyY = mng_magnify_g16_y3; break; } - case 4 : { fMagnifyY = mng_magnify_g16_y2; break; } - case 5 : { fMagnifyY = mng_magnify_g16_y3; break; } - } - } -#endif - - break; - } - - case 2 : ; - case 10 : { - if (pBuf->iBitdepth <= 8) - { - switch (pImage->iMAGN_MethodX) - { - case 1 : { fMagnifyX = mng_magnify_rgb8_x1; break; } - case 2 : { fMagnifyX = mng_magnify_rgb8_x2; break; } - case 3 : { fMagnifyX = mng_magnify_rgb8_x3; break; } - case 4 : { fMagnifyX = mng_magnify_rgb8_x2; break; } - case 5 : { fMagnifyX = mng_magnify_rgb8_x3; break; } - } - - switch (pImage->iMAGN_MethodY) - { - case 1 : { fMagnifyY = mng_magnify_rgb8_y1; break; } - case 2 : { fMagnifyY = mng_magnify_rgb8_y2; break; } - case 3 : { fMagnifyY = mng_magnify_rgb8_y3; break; } - case 4 : { fMagnifyY = mng_magnify_rgb8_y2; break; } - case 5 : { fMagnifyY = mng_magnify_rgb8_y3; break; } - } - } -#ifndef MNG_NO_16BIT_SUPPORT - else - { - switch (pImage->iMAGN_MethodX) - { - case 1 : { fMagnifyX = mng_magnify_rgb16_x1; break; } - case 2 : { fMagnifyX = mng_magnify_rgb16_x2; break; } - case 3 : { fMagnifyX = mng_magnify_rgb16_x3; break; } - case 4 : { fMagnifyX = mng_magnify_rgb16_x2; break; } - case 5 : { fMagnifyX = mng_magnify_rgb16_x3; break; } - } - - switch (pImage->iMAGN_MethodY) - { - case 1 : { fMagnifyY = mng_magnify_rgb16_y1; break; } - case 2 : { fMagnifyY = mng_magnify_rgb16_y2; break; } - case 3 : { fMagnifyY = mng_magnify_rgb16_y3; break; } - case 4 : { fMagnifyY = mng_magnify_rgb16_y2; break; } - case 5 : { fMagnifyY = mng_magnify_rgb16_y3; break; } - } - } -#endif - - break; - } - - case 4 : ; - case 12 : { - if (pBuf->iBitdepth <= 8) - { - switch (pImage->iMAGN_MethodX) - { - case 1 : { fMagnifyX = mng_magnify_ga8_x1; break; } - case 2 : { fMagnifyX = mng_magnify_ga8_x2; break; } - case 3 : { fMagnifyX = mng_magnify_ga8_x3; break; } - case 4 : { fMagnifyX = mng_magnify_ga8_x4; break; } - case 5 : { fMagnifyX = mng_magnify_ga8_x5; break; } - } - - switch (pImage->iMAGN_MethodY) - { - case 1 : { fMagnifyY = mng_magnify_ga8_y1; break; } - case 2 : { fMagnifyY = mng_magnify_ga8_y2; break; } - case 3 : { fMagnifyY = mng_magnify_ga8_y3; break; } - case 4 : { fMagnifyY = mng_magnify_ga8_y4; break; } - case 5 : { fMagnifyY = mng_magnify_ga8_y5; break; } - } - } -#ifndef MNG_NO_16BIT_SUPPORT - else - { - switch (pImage->iMAGN_MethodX) - { - case 1 : { fMagnifyX = mng_magnify_ga16_x1; break; } - case 2 : { fMagnifyX = mng_magnify_ga16_x2; break; } - case 3 : { fMagnifyX = mng_magnify_ga16_x3; break; } - case 4 : { fMagnifyX = mng_magnify_ga16_x4; break; } - case 5 : { fMagnifyX = mng_magnify_ga16_x5; break; } - } - - switch (pImage->iMAGN_MethodY) - { - case 1 : { fMagnifyY = mng_magnify_ga16_y1; break; } - case 2 : { fMagnifyY = mng_magnify_ga16_y2; break; } - case 3 : { fMagnifyY = mng_magnify_ga16_y3; break; } - case 4 : { fMagnifyY = mng_magnify_ga16_y4; break; } - case 5 : { fMagnifyY = mng_magnify_ga16_y5; break; } - } - } -#endif - - break; - } -#endif - - case 6 : ; - case 14 : { - if (pBuf->iBitdepth <= 8) - { - switch (pImage->iMAGN_MethodX) - { - case 1 : { fMagnifyX = mng_magnify_rgba8_x1; break; } - case 2 : { fMagnifyX = mng_magnify_rgba8_x2; break; } - case 3 : { fMagnifyX = mng_magnify_rgba8_x3; break; } - case 4 : { fMagnifyX = mng_magnify_rgba8_x4; break; } - case 5 : { fMagnifyX = mng_magnify_rgba8_x5; break; } - } - - switch (pImage->iMAGN_MethodY) - { - case 1 : { fMagnifyY = mng_magnify_rgba8_y1; break; } - case 2 : { fMagnifyY = mng_magnify_rgba8_y2; break; } - case 3 : { fMagnifyY = mng_magnify_rgba8_y3; break; } - case 4 : { fMagnifyY = mng_magnify_rgba8_y4; break; } - case 5 : { fMagnifyY = mng_magnify_rgba8_y5; break; } - } - } -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_MAGN - else - { - switch (pImage->iMAGN_MethodX) - { - case 1 : { fMagnifyX = mng_magnify_rgba16_x1; break; } - case 2 : { fMagnifyX = mng_magnify_rgba16_x2; break; } - case 3 : { fMagnifyX = mng_magnify_rgba16_x3; break; } - case 4 : { fMagnifyX = mng_magnify_rgba16_x4; break; } - case 5 : { fMagnifyX = mng_magnify_rgba16_x5; break; } - } - - switch (pImage->iMAGN_MethodY) - { - case 1 : { fMagnifyY = mng_magnify_rgba16_y1; break; } - case 2 : { fMagnifyY = mng_magnify_rgba16_y2; break; } - case 3 : { fMagnifyY = mng_magnify_rgba16_y3; break; } - case 4 : { fMagnifyY = mng_magnify_rgba16_y4; break; } - case 5 : { fMagnifyY = mng_magnify_rgba16_y5; break; } - } - } -#endif -#endif - break; - } - } - - pSrcline1 = pBuf->pImgdata; /* initialize row-loop variables */ - pDstline = pNewdata; - /* allocate temporary row */ - MNG_ALLOC (pData, pTempline, iNewrowsize); - - for (iY = 0; iY < pBuf->iHeight; iY++) - { - pSrcline2 = pSrcline1 + pBuf->iRowsize; - - if (fMagnifyX) /* magnifying in X-direction ? */ - { - iRetcode = fMagnifyX (pData, pImage->iMAGN_MX, - pImage->iMAGN_ML, pImage->iMAGN_MR, - pBuf->iWidth, pSrcline1, pDstline); - - if (iRetcode) /* on error bail out */ - { - MNG_FREEX (pData, pTempline, iNewrowsize); - MNG_FREEX (pData, pNewdata, iNewsize); - return iRetcode; - } - } - else - { - MNG_COPY (pDstline, pSrcline1, iNewrowsize); - } - - pDstline += iNewrowsize; - /* magnifying in Y-direction ? */ - if ((fMagnifyY) && - ((iY < pBuf->iHeight - 1) || (pBuf->iHeight == 1) || (pImage->iMAGN_MethodY == 1))) - { - if (iY == 0) /* first interval ? */ - { - if (pBuf->iHeight == 1) /* single row ? */ - pSrcline2 = MNG_NULL; - - iM = (mng_int32)pImage->iMAGN_MT; - } - else /* last interval ? */ - if (((pImage->iMAGN_MethodY == 1) && (iY == (pBuf->iHeight - 1))) || - ((pImage->iMAGN_MethodY != 1) && (iY == (pBuf->iHeight - 2))) ) - iM = (mng_int32)pImage->iMAGN_MB; - else /* middle interval */ - iM = (mng_int32)pImage->iMAGN_MY; - - for (iS = 1; iS < iM; iS++) - { - iRetcode = fMagnifyY (pData, iS, iM, pBuf->iWidth, - pSrcline1, pSrcline2, pTempline); - - if (iRetcode) /* on error bail out */ - { - MNG_FREEX (pData, pTempline, iNewrowsize); - MNG_FREEX (pData, pNewdata, iNewsize); - return iRetcode; - } - - if (fMagnifyX) /* magnifying in X-direction ? */ - { - iRetcode = fMagnifyX (pData, pImage->iMAGN_MX, - pImage->iMAGN_ML, pImage->iMAGN_MR, - pBuf->iWidth, pTempline, pDstline); - - if (iRetcode) /* on error bail out */ - { - MNG_FREEX (pData, pTempline, iNewrowsize); - MNG_FREEX (pData, pNewdata, iNewsize); - return iRetcode; - } - } - else - { - MNG_COPY (pDstline, pTempline, iNewrowsize); - } - - pDstline += iNewrowsize; - } - } - - pSrcline1 += pBuf->iRowsize; - } - /* drop temporary row */ - MNG_FREEX (pData, pTempline, iNewrowsize); - /* drop old pixel-data */ - MNG_FREEX (pData, pBuf->pImgdata, pBuf->iImgdatasize); - - pBuf->pImgdata = pNewdata; /* save new buffer dimensions */ - pBuf->iRowsize = iNewrowsize; - pBuf->iImgdatasize = iNewsize; - pBuf->iWidth = iNewW; - pBuf->iHeight = iNewH; - - if (pImage->iId) /* real object ? */ - { - pImage->iMAGN_MethodX = 0; /* it's done; don't do it again !!! */ - pImage->iMAGN_MethodY = 0; - pImage->iMAGN_MX = 0; - pImage->iMAGN_MY = 0; - pImage->iMAGN_ML = 0; - pImage->iMAGN_MR = 0; - pImage->iMAGN_MT = 0; - pImage->iMAGN_MB = 0; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_IMGOBJECT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_colorcorrect_object (mng_datap pData, - mng_imagep pImage) -{ - mng_imagedatap pBuf = pImage->pImgbuf; - mng_retcode iRetcode; - mng_uint32 iY; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_COLORCORRECT_OBJECT, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_JNG - if ((pBuf->iBitdepth < 8) || /* we need 8- or 16-bit RGBA !!! */ - ((pBuf->iColortype != MNG_COLORTYPE_RGBA ) && - (pBuf->iColortype != MNG_COLORTYPE_JPEGCOLORA) )) -#else - if (pBuf->iBitdepth < 8) /* we need 8- or 16-bit RGBA !!! */ -#endif - MNG_ERROR (pData, MNG_OBJNOTABSTRACT); - - if (!pBuf->bCorrected) /* only if not already done ! */ - { /* so the row routines now to find it */ - pData->pRetrieveobj = (mng_objectp)pImage; - pData->pStoreobj = (mng_objectp)pImage; - pData->pStorebuf = (mng_objectp)pImage->pImgbuf; - -#ifndef MNG_NO_16BIT_SUPPORT - if (pBuf->iBitdepth > 8) - { - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16; - pData->fStorerow = (mng_fptr)mng_store_rgba16; - } - else -#endif - { - pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; - pData->fStorerow = (mng_fptr)mng_store_rgba8; - } - - pData->bIsOpaque = MNG_FALSE; - - pData->iPass = -1; /* these are the object's dimensions now */ - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pBuf->iWidth; - pData->iRowsize = pData->iRowsamples << 2; - pData->iPixelofs = 0; - pData->bIsRGBA16 = MNG_FALSE; - /* adjust for 16-bit object ? */ -#ifndef MNG_NO_16BIT_SUPPORT - if (pBuf->iBitdepth > 8) - { - pData->bIsRGBA16 = MNG_TRUE; - pData->iRowsize = pData->iRowsamples << 3; - } -#endif - - pData->fCorrectrow = MNG_NULL; /* default no color-correction */ - -#ifdef MNG_NO_CMS - iRetcode = MNG_NOERROR; -#else -#if defined(MNG_FULL_CMS) /* determine color-management routine */ - iRetcode = mng_init_full_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); -#elif defined(MNG_GAMMA_ONLY) - iRetcode = mng_init_gamma_only (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); -#elif defined(MNG_APP_CMS) - iRetcode = mng_init_app_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); -#endif - if (iRetcode) /* on error bail out */ - return iRetcode; -#endif /* MNG_NO_CMS */ - - if (pData->fCorrectrow) /* really correct something ? */ - { /* get a temporary row-buffer */ - MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize); - - pData->pWorkrow = pData->pRGBArow; - iY = 0; /* start from the top */ - - while ((!iRetcode) && (iY < pBuf->iHeight)) - { /* get a row */ - iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData); - - if (!iRetcode) /* color correct it */ - iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData); - - if (!iRetcode) /* store it back ! */ - iRetcode = ((mng_storerow)pData->fStorerow) (pData); - - if (!iRetcode) /* adjust variables for next row */ - iRetcode = mng_next_row (pData); - - iY++; /* and next line */ - } - /* drop the temporary row-buffer */ - MNG_FREEX (pData, pData->pRGBArow, pData->iRowsize); - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#if defined(MNG_FULL_CMS) /* cleanup cms stuff */ - iRetcode = mng_clear_cms (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; -#endif - } - - pBuf->bCorrected = MNG_TRUE; /* let's not go through that again ! */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_COLORCORRECT_OBJECT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ -/* * * */ -/* * Animation-object routines * */ -/* * * */ -/* * these handle the animation objects used to re-run parts of a MNG. * */ -/* * eg. during LOOP or TERM processing * */ -/* * * */ -/* ************************************************************************** */ - -void mng_add_ani_object (mng_datap pData, - mng_object_headerp pObject) -{ - mng_object_headerp pLast = (mng_object_headerp)pData->pLastaniobj; - - if (pLast) /* link it as last in the chain */ - { - pObject->pPrev = pLast; - pLast->pNext = pObject; - } - else - { - pObject->pPrev = MNG_NULL; /* be on the safe side */ - pData->pFirstaniobj = pObject; - } - - pObject->pNext = MNG_NULL; /* be on the safe side */ - pData->pLastaniobj = pObject; - /* keep track for jumping */ - pObject->iFramenr = pData->iFrameseq; - pObject->iLayernr = pData->iLayerseq; - pObject->iPlaytime = pData->iFrametime; - /* save restart object ? */ - if ((pData->bDisplaying) && (!pData->bRunning) && (!pData->pCurraniobj)) - pData->pCurraniobj = pObject; - - return; -} - -/* ************************************************************************** */ -/* ************************************************************************** */ - -mng_retcode mng_create_ani_image (mng_datap pData) -{ - mng_ani_imagep pImage; - mng_imagep pCurrent; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_IMAGE, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* processing delta-image ? */ - pCurrent = (mng_imagep)pData->pObjzero; - else /* get the current object */ -#endif - pCurrent = (mng_imagep)pData->pCurrentobj; - - if (!pCurrent) /* otherwise object 0 */ - pCurrent = (mng_imagep)pData->pObjzero; - /* now just clone the object !!! */ - iRetcode = mng_clone_imageobject (pData, 0, MNG_FALSE, pCurrent->bVisible, - MNG_FALSE, MNG_FALSE, 0, 0, 0, pCurrent, - &pImage); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - pImage->sHeader.fCleanup = mng_free_ani_image; - pImage->sHeader.fProcess = mng_process_ani_image; - - mng_add_ani_object (pData, (mng_object_headerp)pImage); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_IMAGE, MNG_LC_END); -#endif - - return MNG_NOERROR; /* okido */ -} - -/* ************************************************************************** */ - -mng_retcode mng_free_ani_image (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_imagep pImage = (mng_ani_imagep)pObject; - mng_imagedatap pImgbuf = pImage->pImgbuf; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_IMAGE, MNG_LC_START); -#endif - /* unlink the image-data buffer */ - iRetcode = mng_free_imagedataobject (pData, pImgbuf); - /* drop its own buffer */ - MNG_FREEX (pData, pImage, sizeof (mng_ani_image)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_IMAGE, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_image (mng_datap pData, - mng_objectp pObject) -{ - mng_retcode iRetcode = MNG_NOERROR; - mng_ani_imagep pImage = (mng_imagep)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_IMAGE, MNG_LC_START); -#endif - -#ifndef MNG_NO_DELTA_PNG - if (pData->bHasDHDR) /* processing delta-image ? */ - { - mng_imagep pDelta = (mng_imagep)pData->pDeltaImage; - - if (!pData->iBreakpoint) /* only execute if not broken before */ - { /* make sure to process pixels as well */ - pData->bDeltaimmediate = MNG_FALSE; - /* execute the delta process */ - iRetcode = mng_execute_delta_image (pData, pDelta, (mng_imagep)pObject); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - /* now go and shoot it off (if required) */ - if ((pDelta->bVisible) && (pDelta->bViewable)) - iRetcode = mng_display_image (pData, pDelta, MNG_FALSE); - - if (!pData->bTimerset) - pData->bHasDHDR = MNG_FALSE; /* this image signifies IEND !! */ - - } - else -#endif - if (pData->pCurrentobj) /* active object ? */ - { - mng_imagep pCurrent = (mng_imagep)pData->pCurrentobj; - mng_imagedatap pBuf = pCurrent->pImgbuf; - - if (!pData->iBreakpoint) /* don't copy it again ! */ - { - if (pBuf->iImgdatasize) /* buffer present in active object ? */ - /* then drop it */ - MNG_FREE (pData, pBuf->pImgdata, pBuf->iImgdatasize); - -#ifndef MNG_SKIPCHUNK_iCCP - if (pBuf->iProfilesize) /* iCCP profile present ? */ - /* then drop it */ - MNG_FREE (pData, pBuf->pProfile, pBuf->iProfilesize); -#endif - /* now blatently copy the animation buffer */ - MNG_COPY (pBuf, pImage->pImgbuf, sizeof (mng_imagedata)); - /* copy viewability */ - pCurrent->bViewable = pImage->bViewable; - - if (pBuf->iImgdatasize) /* sample buffer present ? */ - { /* then make a copy */ - MNG_ALLOC (pData, pBuf->pImgdata, pBuf->iImgdatasize); - MNG_COPY (pBuf->pImgdata, pImage->pImgbuf->pImgdata, pBuf->iImgdatasize); - } - -#ifndef MNG_SKIPCHUNK_iCCP - if (pBuf->iProfilesize) /* iCCP profile present ? */ - { /* then make a copy */ - MNG_ALLOC (pData, pBuf->pProfile, pBuf->iProfilesize); - MNG_COPY (pBuf->pProfile, pImage->pImgbuf->pProfile, pBuf->iProfilesize); - } -#endif - } - /* now go and shoot it off (if required) */ - if ((pCurrent->bVisible) && (pCurrent->bViewable)) - iRetcode = mng_display_image (pData, pCurrent, MNG_FALSE); - } - else - { - mng_imagep pObjzero = (mng_imagep)pData->pObjzero; - mng_imagedatap pBuf = pObjzero->pImgbuf; - - if (!pData->iBreakpoint) /* don't copy it again ! */ - { - if (pBuf->iImgdatasize) /* buffer present in active object ? */ - /* then drop it */ - MNG_FREE (pData, pBuf->pImgdata, pBuf->iImgdatasize); - -#ifndef MNG_SKIPCHUNK_iCCP - if (pBuf->iProfilesize) /* iCCP profile present ? */ - /* then drop it */ - MNG_FREE (pData, pBuf->pProfile, pBuf->iProfilesize); -#endif - /* now blatently copy the animation buffer */ - MNG_COPY (pBuf, pImage->pImgbuf, sizeof (mng_imagedata)); - /* copy viewability */ - pObjzero->bViewable = pImage->bViewable; - - if (pBuf->iImgdatasize) /* sample buffer present ? */ - { /* then make a copy */ - MNG_ALLOC (pData, pBuf->pImgdata, pBuf->iImgdatasize); - MNG_COPY (pBuf->pImgdata, pImage->pImgbuf->pImgdata, pBuf->iImgdatasize); - } - -#ifndef MNG_SKIPCHUNK_iCCP - if (pBuf->iProfilesize) /* iCCP profile present ? */ - { /* then make a copy */ - MNG_ALLOC (pData, pBuf->pProfile, pBuf->iProfilesize); - MNG_COPY (pBuf->pProfile, pImage->pImgbuf->pProfile, pBuf->iProfilesize); - } -#endif - } - /* now go and show it */ - iRetcode = mng_display_image (pData, pObjzero, MNG_FALSE); - } - - if (!iRetcode) /* all's well ? */ - { - if (pData->bTimerset) /* timer break ? */ - pData->iBreakpoint = 99; /* fictive number; no more processing needed! */ - else - pData->iBreakpoint = 0; /* else clear it */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_IMAGE, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_plte (mng_datap pData, - mng_uint32 iEntrycount, - mng_palette8ep paEntries) -#else -mng_retcode mng_create_ani_plte (mng_datap pData) -#endif -{ - mng_ani_pltep pPLTE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_PLTE, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_plte), - mng_free_obj_general, - mng_process_ani_plte, - &pTemp); - if (iRetcode) - return iRetcode; - pPLTE = (mng_ani_pltep)pTemp; -#else - MNG_ALLOC (pData, pPLTE, sizeof (mng_ani_plte)); - - pPLTE->sHeader.fCleanup = mng_free_ani_plte; - pPLTE->sHeader.fProcess = mng_process_ani_plte; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pPLTE); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pPLTE->iEntrycount = iEntrycount; - MNG_COPY (pPLTE->aEntries, paEntries, sizeof (pPLTE->aEntries)); -#else - pPLTE->iEntrycount = pData->iGlobalPLTEcount; - MNG_COPY (pPLTE->aEntries, pData->aGlobalPLTEentries, sizeof (pPLTE->aEntries)); -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_PLTE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_plte (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_PLTE, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_plte)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_PLTE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_plte (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_pltep pPLTE = (mng_ani_pltep)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PLTE, MNG_LC_START); -#endif - - pData->bHasglobalPLTE = MNG_TRUE; - pData->iGlobalPLTEcount = pPLTE->iEntrycount; - - MNG_COPY (pData->aGlobalPLTEentries, pPLTE->aEntries, sizeof (pPLTE->aEntries)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PLTE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_trns (mng_datap pData, - mng_uint32 iRawlen, - mng_uint8p pRawdata) -#else -mng_retcode mng_create_ani_trns (mng_datap pData) -#endif -{ - mng_ani_trnsp pTRNS; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_TRNS, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_trns), - mng_free_obj_general, - mng_process_ani_trns, - &pTemp); - if (iRetcode) - return iRetcode; - pTRNS = (mng_ani_trnsp)pTemp; -#else - MNG_ALLOC (pData, pTRNS, sizeof (mng_ani_trns)); - - pTRNS->sHeader.fCleanup = mng_free_ani_trns; - pTRNS->sHeader.fProcess = mng_process_ani_trns; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pTRNS); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pTRNS->iRawlen = iRawlen; - MNG_COPY (pTRNS->aRawdata, pRawdata, sizeof (pTRNS->aRawdata)); -#else - pTRNS->iRawlen = pData->iGlobalTRNSrawlen; - MNG_COPY (pTRNS->aRawdata, pData->aGlobalTRNSrawdata, sizeof (pTRNS->aRawdata)); -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_TRNS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_trns (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_TRNS, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_trns)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_TRNS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_trns (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_trnsp pTRNS = (mng_ani_trnsp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_TRNS, MNG_LC_START); -#endif - - pData->bHasglobalTRNS = MNG_TRUE; - pData->iGlobalTRNSrawlen = pTRNS->iRawlen; - - MNG_COPY (pData->aGlobalTRNSrawdata, pTRNS->aRawdata, sizeof (pTRNS->aRawdata)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_TRNS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_gAMA -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_gama (mng_datap pData, - mng_bool bEmpty, - mng_uint32 iGamma) -#else -mng_retcode mng_create_ani_gama (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ani_gamap pGAMA; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_GAMA, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_gama), - mng_free_obj_general, - mng_process_ani_gama, - &pTemp); - if (iRetcode) - return iRetcode; - pGAMA = (mng_ani_gamap)pTemp; -#else - MNG_ALLOC (pData, pGAMA, sizeof (mng_ani_gama)); - - pGAMA->sHeader.fCleanup = mng_free_ani_gama; - pGAMA->sHeader.fProcess = mng_process_ani_gama; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pGAMA); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pGAMA->bEmpty = bEmpty; - pGAMA->iGamma = iGamma; -#else - pGAMA->bEmpty = ((mng_gamap)pChunk)->bEmpty; - pGAMA->iGamma = ((mng_gamap)pChunk)->iGamma; -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_GAMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_gama (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_GAMA, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_gama)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_GAMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_gama (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_gamap pGAMA = (mng_ani_gamap)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_GAMA, MNG_LC_START); -#endif - - if (pGAMA->bEmpty) /* empty chunk ? */ - { /* clear global gAMA */ - pData->bHasglobalGAMA = MNG_FALSE; - pData->iGlobalGamma = 0; - } - else - { /* set global gAMA */ - pData->bHasglobalGAMA = MNG_TRUE; - pData->iGlobalGamma = pGAMA->iGamma; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_GAMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_cHRM -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_chrm (mng_datap pData, - mng_bool bEmpty, - mng_uint32 iWhitepointx, - mng_uint32 iWhitepointy, - mng_uint32 iRedx, - mng_uint32 iRedy, - mng_uint32 iGreenx, - mng_uint32 iGreeny, - mng_uint32 iBluex, - mng_uint32 iBluey) -#else -mng_retcode mng_create_ani_chrm (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ptr pTemp; - mng_ani_chrmp pCHRM; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_CHRM, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_chrm), - mng_free_obj_general, - mng_process_ani_chrm, - &pTemp); - if (iRetcode) - return iRetcode; - pCHRM = (mng_ani_chrmp)pTemp; -#else - MNG_ALLOC (pData, pCHRM, sizeof (mng_ani_chrm)); - - pCHRM->sHeader.fCleanup = mng_free_ani_chrm; - pCHRM->sHeader.fProcess = mng_process_ani_chrm; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pCHRM); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pCHRM->bEmpty = bEmpty; - pCHRM->iWhitepointx = iWhitepointx; - pCHRM->iWhitepointy = iWhitepointy; - pCHRM->iRedx = iRedx; - pCHRM->iRedy = iRedy; - pCHRM->iGreenx = iGreenx; - pCHRM->iGreeny = iGreeny; - pCHRM->iBluex = iBluex; - pCHRM->iBluey = iBluey; -#else - pCHRM->bEmpty = ((mng_chrmp)pChunk)->bEmpty; - pCHRM->iWhitepointx = ((mng_chrmp)pChunk)->iWhitepointx; - pCHRM->iWhitepointy = ((mng_chrmp)pChunk)->iWhitepointy; - pCHRM->iRedx = ((mng_chrmp)pChunk)->iRedx; - pCHRM->iRedy = ((mng_chrmp)pChunk)->iRedy; - pCHRM->iGreenx = ((mng_chrmp)pChunk)->iGreenx; - pCHRM->iGreeny = ((mng_chrmp)pChunk)->iGreeny; - pCHRM->iBluex = ((mng_chrmp)pChunk)->iBluex; - pCHRM->iBluey = ((mng_chrmp)pChunk)->iBluey; -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_CHRM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_chrm (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_CHRM, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_chrm)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_CHRM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_chrm (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_chrmp pCHRM = (mng_ani_chrmp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_CHRM, MNG_LC_START); -#endif - - if (pCHRM->bEmpty) /* empty chunk ? */ - { /* clear global cHRM */ - pData->bHasglobalCHRM = MNG_FALSE; - pData->iGlobalWhitepointx = 0; - pData->iGlobalWhitepointy = 0; - pData->iGlobalPrimaryredx = 0; - pData->iGlobalPrimaryredy = 0; - pData->iGlobalPrimarygreenx = 0; - pData->iGlobalPrimarygreeny = 0; - pData->iGlobalPrimarybluex = 0; - pData->iGlobalPrimarybluey = 0; - } - else - { /* set global cHRM */ - pData->bHasglobalCHRM = MNG_TRUE; - pData->iGlobalWhitepointx = pCHRM->iWhitepointx; - pData->iGlobalWhitepointy = pCHRM->iWhitepointy; - pData->iGlobalPrimaryredx = pCHRM->iRedx; - pData->iGlobalPrimaryredy = pCHRM->iRedy; - pData->iGlobalPrimarygreenx = pCHRM->iGreenx; - pData->iGlobalPrimarygreeny = pCHRM->iGreeny; - pData->iGlobalPrimarybluex = pCHRM->iBluex; - pData->iGlobalPrimarybluey = pCHRM->iBluey; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_CHRM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_sRGB -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_srgb (mng_datap pData, - mng_bool bEmpty, - mng_uint8 iRenderingintent) -#else -mng_retcode mng_create_ani_srgb (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ani_srgbp pSRGB; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_SRGB, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_srgb), - mng_free_obj_general, - mng_process_ani_srgb, - &pTemp); - if (iRetcode) - return iRetcode; - pSRGB = (mng_ani_srgbp)pTemp; -#else - MNG_ALLOC (pData, pSRGB, sizeof (mng_ani_srgb)); - - pSRGB->sHeader.fCleanup = mng_free_ani_srgb; - pSRGB->sHeader.fProcess = mng_process_ani_srgb; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pSRGB); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pSRGB->bEmpty = bEmpty; - pSRGB->iRenderingintent = iRenderingintent; -#else - pSRGB->bEmpty = ((mng_srgbp)pChunk)->bEmpty; - pSRGB->iRenderingintent = ((mng_srgbp)pChunk)->iRenderingintent; -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_SRGB, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_srgb (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_SRGB, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_srgb)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_SRGB, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_srgb (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_srgbp pSRGB = (mng_ani_srgbp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SRGB, MNG_LC_START); -#endif - - if (pSRGB->bEmpty) /* empty chunk ? */ - { /* clear global sRGB */ - pData->bHasglobalSRGB = MNG_FALSE; - pData->iGlobalRendintent = 0; - } - else - { /* set global sRGB */ - pData->bHasglobalSRGB = MNG_TRUE; - pData->iGlobalRendintent = pSRGB->iRenderingintent; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SRGB, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_iCCP -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_iccp (mng_datap pData, - mng_bool bEmpty, - mng_uint32 iProfilesize, - mng_ptr pProfile) -#else -mng_retcode mng_create_ani_iccp (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ptr pTemp; - mng_ani_iccpp pICCP; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_ICCP, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_iccp), - mng_free_ani_iccp, - mng_process_ani_iccp, - &pTemp); - if (iRetcode) - return iRetcode; - pICCP = (mng_ani_iccpp)pTemp; -#else - MNG_ALLOC (pData, pICCP, sizeof (mng_ani_iccp)); - - pICCP->sHeader.fCleanup = mng_free_ani_iccp; - pICCP->sHeader.fProcess = mng_process_ani_iccp; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pICCP); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pICCP->bEmpty = bEmpty; - pICCP->iProfilesize = iProfilesize; - - if (iProfilesize) - { - MNG_ALLOC (pData, pICCP->pProfile, iProfilesize); - MNG_COPY (pICCP->pProfile, pProfile, iProfilesize); - } -#else - pICCP->bEmpty = ((mng_iccpp)pChunk)->bEmpty; - pICCP->iProfilesize = ((mng_iccpp)pChunk)->iProfilesize; - - if (pICCP->iProfilesize) - { - MNG_ALLOC (pData, pICCP->pProfile, pICCP->iProfilesize); - MNG_COPY (pICCP->pProfile, ((mng_iccpp)pChunk)->pProfile, pICCP->iProfilesize); - } -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_ICCP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_free_ani_iccp (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_iccpp pICCP = (mng_ani_iccpp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_ICCP, MNG_LC_START); -#endif - - if (pICCP->iProfilesize) - MNG_FREEX (pData, pICCP->pProfile, pICCP->iProfilesize); - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - MNG_FREEX (pData, pObject, sizeof (mng_ani_iccp)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_ICCP, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - return MNG_NOERROR; -#else - return mng_free_obj_general(pData, pObject); -#endif -} - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_iccp (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_iccpp pICCP = (mng_ani_iccpp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_ICCP, MNG_LC_START); -#endif - - if (pICCP->bEmpty) /* empty chunk ? */ - { /* clear global iCCP */ - pData->bHasglobalICCP = MNG_FALSE; - - if (pData->iGlobalProfilesize) - MNG_FREEX (pData, pData->pGlobalProfile, pData->iGlobalProfilesize); - - pData->iGlobalProfilesize = 0; - pData->pGlobalProfile = MNG_NULL; - } - else - { /* set global iCCP */ - pData->bHasglobalICCP = MNG_TRUE; - pData->iGlobalProfilesize = pICCP->iProfilesize; - - if (pICCP->iProfilesize) - { - MNG_ALLOC (pData, pData->pGlobalProfile, pICCP->iProfilesize); - MNG_COPY (pData->pGlobalProfile, pICCP->pProfile, pICCP->iProfilesize); - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_ICCP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_bKGD -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_bkgd (mng_datap pData, - mng_uint16 iRed, - mng_uint16 iGreen, - mng_uint16 iBlue) -#else -mng_retcode mng_create_ani_bkgd (mng_datap pData) -#endif -{ - mng_ptr pTemp; - mng_ani_bkgdp pBKGD; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_BKGD, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_bkgd), - mng_free_obj_general, - mng_process_ani_bkgd, - &pTemp); - if (iRetcode) - return iRetcode; - pBKGD = (mng_ani_bkgdp)pTemp; -#else - MNG_ALLOC (pData, pBKGD, sizeof (mng_ani_bkgd)); - - pBKGD->sHeader.fCleanup = mng_free_ani_bkgd; - pBKGD->sHeader.fProcess = mng_process_ani_bkgd; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pBKGD); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pBKGD->iRed = iRed; - pBKGD->iGreen = iGreen; - pBKGD->iBlue = iBlue; -#else - pBKGD->iRed = pData->iGlobalBKGDred; - pBKGD->iGreen = pData->iGlobalBKGDgreen; - pBKGD->iBlue = pData->iGlobalBKGDblue; -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_BKGD, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_bkgd (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_BKGD, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_bkgd)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_BKGD, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_bkgd (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_bkgdp pBKGD = (mng_ani_bkgdp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_BKGD, MNG_LC_START); -#endif - - pData->bHasglobalBKGD = MNG_TRUE; - pData->iGlobalBKGDred = pBKGD->iRed; - pData->iGlobalBKGDgreen = pBKGD->iGreen; - pData->iGlobalBKGDblue = pBKGD->iBlue; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_BKGD, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_LOOP -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_loop (mng_datap pData, - mng_uint8 iLevel, - mng_uint32 iRepeatcount, - mng_uint8 iTermcond, - mng_uint32 iItermin, - mng_uint32 iItermax, - mng_uint32 iCount, - mng_uint32p pSignals) -#else -mng_retcode mng_create_ani_loop (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ani_loopp pLOOP; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_LOOP, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_loop), - mng_free_ani_loop, - mng_process_ani_loop, - &pTemp); - if (iRetcode) - return iRetcode; - pLOOP = (mng_ani_loopp)pTemp; -#else - MNG_ALLOC (pData, pLOOP, sizeof (mng_ani_loop)); - - pLOOP->sHeader.fCleanup = mng_free_ani_loop; - pLOOP->sHeader.fProcess = mng_process_ani_loop; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pLOOP); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pLOOP->iLevel = iLevel; - pLOOP->iRepeatcount = iRepeatcount; - pLOOP->iTermcond = iTermcond; - pLOOP->iItermin = iItermin; - pLOOP->iItermax = iItermax; - pLOOP->iCount = iCount; - -#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED - if (iCount) - { - MNG_ALLOC (pData, pLOOP->pSignals, (iCount << 1)); - MNG_COPY (pLOOP->pSignals, pSignals, (iCount << 1)); - } -#endif -#else /* MNG_OPTIMIZE_CHUNKREADER */ - pLOOP->iLevel = ((mng_loopp)pChunk)->iLevel; - pLOOP->iRepeatcount = ((mng_loopp)pChunk)->iRepeat; - pLOOP->iTermcond = ((mng_loopp)pChunk)->iTermination; - pLOOP->iItermin = ((mng_loopp)pChunk)->iItermin; - pLOOP->iItermax = ((mng_loopp)pChunk)->iItermax; - pLOOP->iCount = ((mng_loopp)pChunk)->iCount; - -#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED - if (pLOOP->iCount) - { - MNG_ALLOC (pData, pLOOP->pSignals, (pLOOP->iCount << 1)); - MNG_COPY (pLOOP->pSignals, ((mng_loopp)pChunk)->pSignals, (pLOOP->iCount << 1)); - } -#endif -#endif /* MNG_OPTIMIZE_CHUNKREADER */ - /* running counter starts with repeat_count */ - pLOOP->iRunningcount = pLOOP->iRepeatcount; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_LOOP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_free_ani_loop (mng_datap pData, - mng_objectp pObject) -{ -#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED - mng_ani_loopp pLOOP = (mng_ani_loopp)pObject; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_LOOP, MNG_LC_START); -#endif - -#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED - if (pLOOP->iCount) /* drop signal buffer ? */ - MNG_FREEX (pData, pLOOP->pSignals, (pLOOP->iCount << 1)); -#endif - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - MNG_FREEX (pData, pObject, sizeof (mng_ani_loop)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_LOOP, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - return MNG_NOERROR; -#else - return mng_free_obj_general(pData, pObject); -#endif -} - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_loop (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_loopp pLOOP = (mng_ani_loopp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_LOOP, MNG_LC_START); -#endif - /* just reset the running counter */ - pLOOP->iRunningcount = pLOOP->iRepeatcount; - /* iteration=0 means we're skipping ! */ - if ((!pData->bSkipping) && (pLOOP->iRepeatcount == 0)) - pData->bSkipping = MNG_TRUE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_LOOP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ -/* ************************************************************************** */ - -mng_retcode mng_create_ani_endl (mng_datap pData, - mng_uint8 iLevel) -{ - mng_ani_endlp pENDL; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_ENDL, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { - mng_retcode iRetcode; -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - iRetcode = create_obj_general (pData, sizeof (mng_ani_endl), - mng_free_obj_general, - mng_process_ani_endl, - &pTemp); - if (iRetcode) - return iRetcode; - pENDL = (mng_ani_endlp)pTemp; -#else - MNG_ALLOC (pData, pENDL, sizeof (mng_ani_endl)); - - pENDL->sHeader.fCleanup = mng_free_ani_endl; - pENDL->sHeader.fProcess = mng_process_ani_endl; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pENDL); - - pENDL->iLevel = iLevel; - - iRetcode = mng_process_ani_endl (pData, (mng_objectp)pENDL); - if (iRetcode) - return iRetcode; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_ENDL, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_endl (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_ENDL, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_endl)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_ENDL, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_endl (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_endlp pENDL = (mng_ani_endlp)pObject; - mng_ani_loopp pLOOP; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_ENDL, MNG_LC_START); -#endif - - if (((pData->bDisplaying) && ((pData->bRunning) || (pData->bSearching))) || - (pData->bReading) ) - { - pLOOP = pENDL->pLOOP; /* determine matching LOOP */ - - if (!pLOOP) /* haven't got it yet ? */ - { /* go and look back in the list */ - pLOOP = (mng_ani_loopp)pENDL->sHeader.pPrev; - - while ((pLOOP) && - ((pLOOP->sHeader.fCleanup != mng_free_ani_loop) || - (pLOOP->iLevel != pENDL->iLevel) )) - pLOOP = pLOOP->sHeader.pPrev; - } - /* got it now ? */ - if ((pLOOP) && (pLOOP->iLevel == pENDL->iLevel)) - { - pENDL->pLOOP = pLOOP; /* save for next time ! */ - /* decrease running counter ? */ - if ((pLOOP->iRunningcount) && (pLOOP->iRunningcount < 0x7fffffffL)) - pLOOP->iRunningcount--; - - if ((!pData->bDisplaying) && (pData->bReading) && - (pLOOP->iRunningcount >= 0x7fffffffL)) - { - pData->iTotalframes = 0x7fffffffL; - pData->iTotallayers = 0x7fffffffL; - pData->iTotalplaytime = 0x7fffffffL; - } - else - { - /* TODO: we're cheating out on the termination_condition, - iteration_min, iteration_max and possible signals; - the code is just not ready for that can of worms.... */ - - if (!pLOOP->iRunningcount) /* reached zero ? */ - { /* was this the outer LOOP ? */ - if (pData->pFirstaniobj == (mng_objectp)pLOOP) /* TODO: THIS IS WRONG!! */ - pData->bHasLOOP = MNG_FALSE; - } - else - { - if (pData->pCurraniobj) /* was we processing objects ? */ - pData->pCurraniobj = pLOOP;/* then restart with LOOP */ - else /* else restart behind LOOP !!! */ - pData->pCurraniobj = pLOOP->sHeader.pNext; - } - } - /* does this match a 'skipping' LOOP? */ - if ((pData->bSkipping) && (pLOOP->iRepeatcount == 0)) - pData->bSkipping = MNG_FALSE; - } - else - MNG_ERROR (pData, MNG_NOMATCHINGLOOP); - - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_ENDL, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DEFI -mng_retcode mng_create_ani_defi (mng_datap pData) -{ - mng_ani_defip pDEFI; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_DEFI, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_defi), - mng_free_obj_general, - mng_process_ani_defi, - &pTemp); - if (iRetcode) - return iRetcode; - pDEFI = (mng_ani_defip)pTemp; -#else - MNG_ALLOC (pData, pDEFI, sizeof (mng_ani_defi)); - - pDEFI->sHeader.fCleanup = mng_free_ani_defi; - pDEFI->sHeader.fProcess = mng_process_ani_defi; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pDEFI); - - pDEFI->iId = pData->iDEFIobjectid; - pDEFI->bHasdonotshow = pData->bDEFIhasdonotshow; - pDEFI->iDonotshow = pData->iDEFIdonotshow; - pDEFI->bHasconcrete = pData->bDEFIhasconcrete; - pDEFI->iConcrete = pData->iDEFIconcrete; - pDEFI->bHasloca = pData->bDEFIhasloca; - pDEFI->iLocax = pData->iDEFIlocax; - pDEFI->iLocay = pData->iDEFIlocay; - pDEFI->bHasclip = pData->bDEFIhasclip; - pDEFI->iClipl = pData->iDEFIclipl; - pDEFI->iClipr = pData->iDEFIclipr; - pDEFI->iClipt = pData->iDEFIclipt; - pDEFI->iClipb = pData->iDEFIclipb; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_DEFI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_defi (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_DEFI, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_defi)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_DEFI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_defi (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_defip pDEFI = (mng_ani_defip)pObject; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_DEFI, MNG_LC_START); -#endif - - pData->iDEFIobjectid = pDEFI->iId; - pData->bDEFIhasdonotshow = pDEFI->bHasdonotshow; - pData->iDEFIdonotshow = pDEFI->iDonotshow; - pData->bDEFIhasconcrete = pDEFI->bHasconcrete; - pData->iDEFIconcrete = pDEFI->iConcrete; - pData->bDEFIhasloca = pDEFI->bHasloca; - pData->iDEFIlocax = pDEFI->iLocax; - pData->iDEFIlocay = pDEFI->iLocay; - pData->bDEFIhasclip = pDEFI->bHasclip; - pData->iDEFIclipl = pDEFI->iClipl; - pData->iDEFIclipr = pDEFI->iClipr; - pData->iDEFIclipt = pDEFI->iClipt; - pData->iDEFIclipb = pDEFI->iClipb; - - iRetcode = mng_process_display_defi (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_DEFI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_BASI -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_basi (mng_datap pData, - mng_uint16 iRed, - mng_uint16 iGreen, - mng_uint16 iBlue, - mng_bool bHasalpha, - mng_uint16 iAlpha, - mng_uint8 iViewable) -#else -mng_retcode mng_create_ani_basi (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ani_basip pBASI; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_BASI, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - iRetcode = create_obj_general (pData, sizeof (mng_ani_basi), - mng_free_obj_general, - mng_process_ani_basi, - &pTemp); - if (iRetcode) - return iRetcode; - pBASI = (mng_ani_basip)pTemp; -#else - MNG_ALLOC (pData, pBASI, sizeof (mng_ani_basi)); - - pBASI->sHeader.fCleanup = mng_free_ani_basi; - pBASI->sHeader.fProcess = mng_process_ani_basi; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pBASI); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pBASI->iRed = iRed; - pBASI->iGreen = iGreen; - pBASI->iBlue = iBlue; - pBASI->bHasalpha = bHasalpha; - pBASI->iAlpha = iAlpha; - pBASI->iViewable = iViewable; -#else - pBASI->iRed = ((mng_basip)pChunk)->iRed; - pBASI->iGreen = ((mng_basip)pChunk)->iGreen; - pBASI->iBlue = ((mng_basip)pChunk)->iBlue; - pBASI->bHasalpha = ((mng_basip)pChunk)->bHasalpha; - pBASI->iAlpha = ((mng_basip)pChunk)->iAlpha; - pBASI->iViewable = ((mng_basip)pChunk)->iViewable; -#endif - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -#ifndef MNG_OPTIMIZE_CHUNKREADER - iRetcode = mng_process_display_basi (pData, iRed, iGreen, iBlue, - bHasalpha, iAlpha, iViewable); -#else - iRetcode = mng_process_display_basi (pData, - ((mng_basip)pChunk)->iRed, - ((mng_basip)pChunk)->iGreen, - ((mng_basip)pChunk)->iBlue, - ((mng_basip)pChunk)->bHasalpha, - ((mng_basip)pChunk)->iAlpha, - ((mng_basip)pChunk)->iViewable); -#endif -#else -#ifndef MNG_OPTIMIZE_CHUNKREADER - pData->iBASIred = iRed; - pData->iBASIgreen = iGreen; - pData->iBASIblue = iBlue; - pData->bBASIhasalpha = bHasalpha; - pData->iBASIalpha = iAlpha; - pData->iBASIviewable = iViewable; -#else - pData->iBASIred = ((mng_basip)pChunk)->iRed; - pData->iBASIgreen = ((mng_basip)pChunk)->iGreen; - pData->iBASIblue = ((mng_basip)pChunk)->iBlue; - pData->bBASIhasalpha = ((mng_basip)pChunk)->bHasalpha; - pData->iBASIalpha = ((mng_basip)pChunk)->iAlpha; - pData->iBASIviewable = ((mng_basip)pChunk)->iViewable; -#endif - - iRetcode = mng_process_display_basi (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_BASI, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_basi (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_BASI, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_basi)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_BASI, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_basi (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_basip pBASI = (mng_ani_basip)pObject; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_BASI, MNG_LC_START); -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mng_process_display_basi (pData, pBASI->iRed, pBASI->iGreen, pBASI->iBlue, - pBASI->bHasalpha, pBASI->iAlpha, pBASI->iViewable); -#else - pData->iBASIred = pBASI->iRed; - pData->iBASIgreen = pBASI->iGreen; - pData->iBASIblue = pBASI->iBlue; - pData->bBASIhasalpha = pBASI->bHasalpha; - pData->iBASIalpha = pBASI->iAlpha; - pData->iBASIviewable = pBASI->iViewable; - - iRetcode = mng_process_display_basi (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_BASI, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_CLON -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_clon (mng_datap pData, - mng_uint16 iSourceid, - mng_uint16 iCloneid, - mng_uint8 iClonetype, - mng_bool bHasdonotshow, - mng_uint8 iDonotshow, - mng_uint8 iConcrete, - mng_bool bHasloca, - mng_uint8 iLocatype, - mng_int32 iLocax, - mng_int32 iLocay) -#else -mng_retcode mng_create_ani_clon (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ani_clonp pCLON; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_CLON, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - iRetcode = create_obj_general (pData, sizeof (mng_ani_clon), - mng_free_obj_general, - mng_process_ani_clon, - &pTemp); - if (iRetcode) - return iRetcode; - pCLON = (mng_ani_clonp)pTemp; -#else - MNG_ALLOC (pData, pCLON, sizeof (mng_ani_clon)); - - pCLON->sHeader.fCleanup = mng_free_ani_clon; - pCLON->sHeader.fProcess = mng_process_ani_clon; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pCLON); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pCLON->iSourceid = iSourceid; - pCLON->iCloneid = iCloneid; - pCLON->iClonetype = iClonetype; - pCLON->bHasdonotshow = bHasdonotshow; - pCLON->iDonotshow = iDonotshow; - pCLON->iConcrete = iConcrete; - pCLON->bHasloca = bHasloca; - pCLON->iLocatype = iLocatype; - pCLON->iLocax = iLocax; - pCLON->iLocay = iLocay; -#else - pCLON->iSourceid = ((mng_clonp)pChunk)->iSourceid; - pCLON->iCloneid = ((mng_clonp)pChunk)->iCloneid; - pCLON->iClonetype = ((mng_clonp)pChunk)->iClonetype; - pCLON->bHasdonotshow = ((mng_clonp)pChunk)->bHasdonotshow; - pCLON->iDonotshow = ((mng_clonp)pChunk)->iDonotshow; - pCLON->iConcrete = ((mng_clonp)pChunk)->iConcrete; - pCLON->bHasloca = ((mng_clonp)pChunk)->bHasloca; - pCLON->iLocatype = ((mng_clonp)pChunk)->iLocationtype; - pCLON->iLocax = ((mng_clonp)pChunk)->iLocationx; - pCLON->iLocay = ((mng_clonp)pChunk)->iLocationy; -#endif - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -#ifndef MNG_OPTIMIZE_CHUNKREADER - iRetcode = mng_process_display_clon (pData, iSourceid, iCloneid, iClonetype, - bHasdonotshow, iDonotshow, iConcrete, - bHasloca, iLocatype, iLocax, iLocay); -#else - iRetcode = mng_process_display_clon (pData, - ((mng_clonp)pChunk)->iSourceid, - ((mng_clonp)pChunk)->iCloneid, - ((mng_clonp)pChunk)->iClonetype, - ((mng_clonp)pChunk)->bHasdonotshow, - ((mng_clonp)pChunk)->iDonotshow, - ((mng_clonp)pChunk)->iConcrete, - ((mng_clonp)pChunk)->bHasloca, - ((mng_clonp)pChunk)->iLocationtype, - ((mng_clonp)pChunk)->iLocationx, - ((mng_clonp)pChunk)->iLocationy); -#endif -#else -#ifndef MNG_OPTIMIZE_CHUNKREADER - pData->iCLONsourceid = iSourceid; - pData->iCLONcloneid = iCloneid; - pData->iCLONclonetype = iClonetype; - pData->bCLONhasdonotshow = bHasdonotshow; - pData->iCLONdonotshow = iDonotshow; - pData->iCLONconcrete = iConcrete; - pData->bCLONhasloca = bHasloca; - pData->iCLONlocationtype = iLocatype; - pData->iCLONlocationx = iLocax; - pData->iCLONlocationy = iLocay; -#else - pData->iCLONsourceid = ((mng_clonp)pChunk)->iSourceid; - pData->iCLONcloneid = ((mng_clonp)pChunk)->iCloneid; - pData->iCLONclonetype = ((mng_clonp)pChunk)->iClonetype; - pData->bCLONhasdonotshow = ((mng_clonp)pChunk)->bHasdonotshow; - pData->iCLONdonotshow = ((mng_clonp)pChunk)->iDonotshow; - pData->iCLONconcrete = ((mng_clonp)pChunk)->iConcrete; - pData->bCLONhasloca = ((mng_clonp)pChunk)->bHasloca; - pData->iCLONlocationtype = ((mng_clonp)pChunk)->iLocationtype; - pData->iCLONlocationx = ((mng_clonp)pChunk)->iLocationx; - pData->iCLONlocationy = ((mng_clonp)pChunk)->iLocationy; -#endif - - iRetcode = mng_process_display_clon (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_CLON, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_clon (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_CLON, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_clon)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_CLON, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_clon (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_clonp pCLON = (mng_ani_clonp)pObject; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_CLON, MNG_LC_START); -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mng_process_display_clon (pData, pCLON->iSourceid, pCLON->iCloneid, - pCLON->iClonetype, pCLON->bHasdonotshow, - pCLON->iDonotshow, pCLON->iConcrete, - pCLON->bHasloca, pCLON->iLocatype, - pCLON->iLocax, pCLON->iLocay); -#else - pData->iCLONcloneid = pCLON->iCloneid; - pData->iCLONsourceid = pCLON->iSourceid; - pData->iCLONclonetype = pCLON->iClonetype; - pData->bCLONhasdonotshow = pCLON->bHasdonotshow; - pData->iCLONdonotshow = pCLON->iDonotshow; - pData->iCLONconcrete = pCLON->iConcrete; - pData->bCLONhasloca = pCLON->bHasloca; - pData->iCLONlocationtype = pCLON->iLocatype; - pData->iCLONlocationx = pCLON->iLocax; - pData->iCLONlocationy = pCLON->iLocay; - - iRetcode = mng_process_display_clon (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_CLON, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_BACK -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_back (mng_datap pData, - mng_uint16 iRed, - mng_uint16 iGreen, - mng_uint16 iBlue, - mng_uint8 iMandatory, - mng_uint16 iImageid, - mng_uint8 iTile) -#else -mng_retcode mng_create_ani_back (mng_datap pData) -#endif -{ - mng_ani_backp pBACK; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_BACK, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_back), - mng_free_obj_general, - mng_process_ani_back, - &pTemp); - if (iRetcode) - return iRetcode; - pBACK = (mng_ani_backp)pTemp; -#else - MNG_ALLOC (pData, pBACK, sizeof (mng_ani_back)); - - pBACK->sHeader.fCleanup = mng_free_ani_back; - pBACK->sHeader.fProcess = mng_process_ani_back; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pBACK); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pBACK->iRed = iRed; - pBACK->iGreen = iGreen; - pBACK->iBlue = iBlue; - pBACK->iMandatory = iMandatory; - pBACK->iImageid = iImageid; - pBACK->iTile = iTile; -#else - pBACK->iRed = pData->iBACKred; - pBACK->iGreen = pData->iBACKgreen; - pBACK->iBlue = pData->iBACKblue; - pBACK->iMandatory = pData->iBACKmandatory; - pBACK->iImageid = pData->iBACKimageid; - pBACK->iTile = pData->iBACKtile; -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_BACK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_back (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_BACK, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_back)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_BACK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_back (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_backp pBACK = (mng_ani_backp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_BACK, MNG_LC_START); -#endif - - pData->iBACKred = pBACK->iRed; - pData->iBACKgreen = pBACK->iGreen; - pData->iBACKblue = pBACK->iBlue; - pData->iBACKmandatory = pBACK->iMandatory; - pData->iBACKimageid = pBACK->iImageid; - pData->iBACKtile = pBACK->iTile; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_BACK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_FRAM -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_fram (mng_datap pData, - mng_uint8 iFramemode, - mng_uint8 iChangedelay, - mng_uint32 iDelay, - mng_uint8 iChangetimeout, - mng_uint32 iTimeout, - mng_uint8 iChangeclipping, - mng_uint8 iCliptype, - mng_int32 iClipl, - mng_int32 iClipr, - mng_int32 iClipt, - mng_int32 iClipb) -#else -mng_retcode mng_create_ani_fram (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ani_framp pFRAM; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_FRAM, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - iRetcode = create_obj_general (pData, sizeof (mng_ani_fram), - mng_free_obj_general, - mng_process_ani_fram, - &pTemp); - if (iRetcode) - return iRetcode; - pFRAM = (mng_ani_framp)pTemp; -#else - MNG_ALLOC (pData, pFRAM, sizeof (mng_ani_fram)); - - pFRAM->sHeader.fCleanup = mng_free_ani_fram; - pFRAM->sHeader.fProcess = mng_process_ani_fram; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pFRAM); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pFRAM->iFramemode = iFramemode; - pFRAM->iChangedelay = iChangedelay; - pFRAM->iDelay = iDelay; - pFRAM->iChangetimeout = iChangetimeout; - pFRAM->iTimeout = iTimeout; - pFRAM->iChangeclipping = iChangeclipping; - pFRAM->iCliptype = iCliptype; - pFRAM->iClipl = iClipl; - pFRAM->iClipr = iClipr; - pFRAM->iClipt = iClipt; - pFRAM->iClipb = iClipb; -#else - pFRAM->iFramemode = ((mng_framp)pChunk)->iMode; - pFRAM->iChangedelay = ((mng_framp)pChunk)->iChangedelay; - pFRAM->iDelay = ((mng_framp)pChunk)->iDelay; - pFRAM->iChangetimeout = ((mng_framp)pChunk)->iChangetimeout; - pFRAM->iTimeout = ((mng_framp)pChunk)->iTimeout; - pFRAM->iChangeclipping = ((mng_framp)pChunk)->iChangeclipping; - pFRAM->iCliptype = ((mng_framp)pChunk)->iBoundarytype; - pFRAM->iClipl = ((mng_framp)pChunk)->iBoundaryl; - pFRAM->iClipr = ((mng_framp)pChunk)->iBoundaryr; - pFRAM->iClipt = ((mng_framp)pChunk)->iBoundaryt; - pFRAM->iClipb = ((mng_framp)pChunk)->iBoundaryb; -#endif - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -#ifndef MNG_OPTIMIZE_CHUNKREADER - iRetcode = mng_process_display_fram (pData, iFramemode, - iChangedelay, iDelay, - iChangetimeout, iTimeout, - iChangeclipping, iCliptype, - iClipl, iClipr, - iClipt, iClipb); -#else - iRetcode = mng_process_display_fram (pData, - ((mng_framp)pChunk)->iMode, - ((mng_framp)pChunk)->iChangedelay, - ((mng_framp)pChunk)->iDelay, - ((mng_framp)pChunk)->iChangetimeout, - ((mng_framp)pChunk)->iTimeout, - ((mng_framp)pChunk)->iChangeclipping, - ((mng_framp)pChunk)->iBoundarytype, - ((mng_framp)pChunk)->iBoundaryl, - ((mng_framp)pChunk)->iBoundaryr, - ((mng_framp)pChunk)->iBoundaryt, - ((mng_framp)pChunk)->iBoundaryb); -#endif -#else -#ifndef MNG_OPTIMIZE_CHUNKREADER - pData->iTempFramemode = iFramemode; - pData->iTempChangedelay = iChangedelay; - pData->iTempDelay = iDelay; - pData->iTempChangetimeout = iChangetimeout; - pData->iTempTimeout = iTimeout; - pData->iTempChangeclipping = iChangeclipping; - pData->iTempCliptype = iCliptype; - pData->iTempClipl = iClipl; - pData->iTempClipr = iClipr; - pData->iTempClipt = iClipt; - pData->iTempClipb = iClipb; -#else - pData->iTempFramemode = ((mng_framp)pChunk)->iMode; - pData->iTempChangedelay = ((mng_framp)pChunk)->iChangedelay; - pData->iTempDelay = ((mng_framp)pChunk)->iDelay; - pData->iTempChangetimeout = ((mng_framp)pChunk)->iChangetimeout; - pData->iTempTimeout = ((mng_framp)pChunk)->iTimeout; - pData->iTempChangeclipping = ((mng_framp)pChunk)->iChangeclipping; - pData->iTempCliptype = ((mng_framp)pChunk)->iBoundarytype; - pData->iTempClipl = ((mng_framp)pChunk)->iBoundaryl; - pData->iTempClipr = ((mng_framp)pChunk)->iBoundaryr; - pData->iTempClipt = ((mng_framp)pChunk)->iBoundaryt; - pData->iTempClipb = ((mng_framp)pChunk)->iBoundaryb; -#endif - - iRetcode = mng_process_display_fram (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_FRAM, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_fram (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_FRAM, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_fram)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_FRAM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_fram (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_framp pFRAM = (mng_ani_framp)pObject; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_FRAM, MNG_LC_START); -#endif - - if (pData->iBreakpoint) /* previously broken ? */ - { - iRetcode = mng_process_display_fram2 (pData); - pData->iBreakpoint = 0; /* not again */ - } - else - { -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mng_process_display_fram (pData, pFRAM->iFramemode, - pFRAM->iChangedelay, pFRAM->iDelay, - pFRAM->iChangetimeout, pFRAM->iTimeout, - pFRAM->iChangeclipping, pFRAM->iCliptype, - pFRAM->iClipl, pFRAM->iClipr, - pFRAM->iClipt, pFRAM->iClipb); -#else - pData->iTempFramemode = pFRAM->iFramemode; - pData->iTempChangedelay = pFRAM->iChangedelay; - pData->iTempDelay = pFRAM->iDelay; - pData->iTempChangetimeout = pFRAM->iChangetimeout; - pData->iTempTimeout = pFRAM->iTimeout; - pData->iTempChangeclipping = pFRAM->iChangeclipping; - pData->iTempCliptype = pFRAM->iCliptype; - pData->iTempClipl = pFRAM->iClipl; - pData->iTempClipr = pFRAM->iClipr; - pData->iTempClipt = pFRAM->iClipt; - pData->iTempClipb = pFRAM->iClipb; - - iRetcode = mng_process_display_fram (pData); -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_FRAM, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MOVE -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_move (mng_datap pData, - mng_uint16 iFirstid, - mng_uint16 iLastid, - mng_uint8 iType, - mng_int32 iLocax, - mng_int32 iLocay) -#else -mng_retcode mng_create_ani_move (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ani_movep pMOVE; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_MOVE, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - iRetcode = create_obj_general (pData, sizeof (mng_ani_move), - mng_free_obj_general, - mng_process_ani_move, - &pTemp); - if (iRetcode) - return iRetcode; - pMOVE = (mng_ani_movep)pTemp; -#else - MNG_ALLOC (pData, pMOVE, sizeof (mng_ani_move)); - - pMOVE->sHeader.fCleanup = mng_free_ani_move; - pMOVE->sHeader.fProcess = mng_process_ani_move; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pMOVE); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pMOVE->iFirstid = iFirstid; - pMOVE->iLastid = iLastid; - pMOVE->iType = iType; - pMOVE->iLocax = iLocax; - pMOVE->iLocay = iLocay; -#else - pMOVE->iFirstid = ((mng_movep)pChunk)->iFirstid; - pMOVE->iLastid = ((mng_movep)pChunk)->iLastid; - pMOVE->iType = ((mng_movep)pChunk)->iMovetype; - pMOVE->iLocax = ((mng_movep)pChunk)->iMovex; - pMOVE->iLocay = ((mng_movep)pChunk)->iMovey; -#endif - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -#ifndef MNG_OPTIMIZE_CHUNKREADER - iRetcode = mng_process_display_move (pData, iFirstid, iLastid, - iType, iLocax, iLocay); -#else - iRetcode = mng_process_display_move (pData, - ((mng_movep)pChunk)->iFirstid, - ((mng_movep)pChunk)->iLastid, - ((mng_movep)pChunk)->iMovetype, - ((mng_movep)pChunk)->iMovex, - ((mng_movep)pChunk)->iMovey); -#endif -#else -#ifndef MNG_OPTIMIZE_CHUNKREADER - pData->iMOVEfromid = iFirstid; - pData->iMOVEtoid = iLastid; - pData->iMOVEmovetype = iType; - pData->iMOVEmovex = iLocax; - pData->iMOVEmovey = iLocay; -#else - pData->iMOVEfromid = ((mng_movep)pChunk)->iFirstid; - pData->iMOVEtoid = ((mng_movep)pChunk)->iLastid; - pData->iMOVEmovetype = ((mng_movep)pChunk)->iMovetype; - pData->iMOVEmovex = ((mng_movep)pChunk)->iMovex; - pData->iMOVEmovey = ((mng_movep)pChunk)->iMovey; -#endif - - iRetcode = mng_process_display_move (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_MOVE, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_move (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_MOVE, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_move)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_MOVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_move (mng_datap pData, - mng_objectp pObject) -{ - mng_retcode iRetcode; - mng_ani_movep pMOVE = (mng_ani_movep)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_MOVE, MNG_LC_START); -#endif - /* re-process the MOVE chunk */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mng_process_display_move (pData, pMOVE->iFirstid, pMOVE->iLastid, - pMOVE->iType, pMOVE->iLocax, pMOVE->iLocay); -#else - pData->iMOVEfromid = pMOVE->iFirstid; - pData->iMOVEtoid = pMOVE->iLastid; - pData->iMOVEmovetype = pMOVE->iType; - pData->iMOVEmovex = pMOVE->iLocax; - pData->iMOVEmovey = pMOVE->iLocay; - - iRetcode = mng_process_display_move (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_MOVE, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_CLIP -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_clip (mng_datap pData, - mng_uint16 iFirstid, - mng_uint16 iLastid, - mng_uint8 iType, - mng_int32 iClipl, - mng_int32 iClipr, - mng_int32 iClipt, - mng_int32 iClipb) -#else -mng_retcode mng_create_ani_clip (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ani_clipp pCLIP; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_CLIP, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - iRetcode = create_obj_general (pData, sizeof (mng_ani_clip), - mng_free_obj_general, - mng_process_ani_clip, - &pTemp); - if (iRetcode) - return iRetcode; - pCLIP = (mng_ani_clipp)pTemp; -#else - MNG_ALLOC (pData, pCLIP, sizeof (mng_ani_clip)); - - pCLIP->sHeader.fCleanup = mng_free_ani_clip; - pCLIP->sHeader.fProcess = mng_process_ani_clip; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pCLIP); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pCLIP->iFirstid = iFirstid; - pCLIP->iLastid = iLastid; - pCLIP->iType = iType; - pCLIP->iClipl = iClipl; - pCLIP->iClipr = iClipr; - pCLIP->iClipt = iClipt; - pCLIP->iClipb = iClipb; -#else - pCLIP->iFirstid = ((mng_clipp)pChunk)->iFirstid; - pCLIP->iLastid = ((mng_clipp)pChunk)->iLastid; - pCLIP->iType = ((mng_clipp)pChunk)->iCliptype; - pCLIP->iClipl = ((mng_clipp)pChunk)->iClipl; - pCLIP->iClipr = ((mng_clipp)pChunk)->iClipr; - pCLIP->iClipt = ((mng_clipp)pChunk)->iClipt; - pCLIP->iClipb = ((mng_clipp)pChunk)->iClipb; -#endif - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -#ifndef MNG_OPTIMIZE_CHUNKREADER - iRetcode = mng_process_display_clip (pData, iFirstid, iLastid, - iType, iClipl, iClipr, - iClipt, iClipb); -#else - iRetcode = mng_process_display_clip (pData, - ((mng_clipp)pChunk)->iFirstid, - ((mng_clipp)pChunk)->iLastid, - ((mng_clipp)pChunk)->iCliptype, - ((mng_clipp)pChunk)->iClipl, - ((mng_clipp)pChunk)->iClipr, - ((mng_clipp)pChunk)->iClipt, - ((mng_clipp)pChunk)->iClipb); -#endif -#else -#ifndef MNG_OPTIMIZE_CHUNKREADER - pData->iCLIPfromid = iFirstid; - pData->iCLIPtoid = iLastid; - pData->iCLIPcliptype = iType; - pData->iCLIPclipl = iClipl; - pData->iCLIPclipr = iClipr; - pData->iCLIPclipt = iClipt; - pData->iCLIPclipb = iClipb; -#else - pData->iCLIPfromid = ((mng_clipp)pChunk)->iFirstid; - pData->iCLIPtoid = ((mng_clipp)pChunk)->iLastid; - pData->iCLIPcliptype = ((mng_clipp)pChunk)->iCliptype; - pData->iCLIPclipl = ((mng_clipp)pChunk)->iClipl; - pData->iCLIPclipr = ((mng_clipp)pChunk)->iClipr; - pData->iCLIPclipt = ((mng_clipp)pChunk)->iClipt; - pData->iCLIPclipb = ((mng_clipp)pChunk)->iClipb; -#endif - - iRetcode = mng_process_display_clip (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_CLIP, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_clip (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_CLIP, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_clip)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_CLIP, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_clip (mng_datap pData, - mng_objectp pObject) -{ - mng_retcode iRetcode; - mng_ani_clipp pCLIP = (mng_ani_clipp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_CLIP, MNG_LC_START); -#endif - /* re-process the CLIP chunk */ -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mng_process_display_clip (pData, pCLIP->iFirstid, pCLIP->iLastid, - pCLIP->iType, pCLIP->iClipl, pCLIP->iClipr, - pCLIP->iClipt, pCLIP->iClipb); -#else - pData->iCLIPfromid = pCLIP->iFirstid; - pData->iCLIPtoid = pCLIP->iLastid; - pData->iCLIPcliptype = pCLIP->iType; - pData->iCLIPclipl = pCLIP->iClipl; - pData->iCLIPclipr = pCLIP->iClipr; - pData->iCLIPclipt = pCLIP->iClipt; - pData->iCLIPclipb = pCLIP->iClipb; - - iRetcode = mng_process_display_clip (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_CLIP, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SHOW -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_show (mng_datap pData, - mng_uint16 iFirstid, - mng_uint16 iLastid, - mng_uint8 iMode) -#else -mng_retcode mng_create_ani_show (mng_datap pData) -#endif -{ - mng_ani_showp pSHOW; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_SHOW, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_show), - mng_free_obj_general, - mng_process_ani_show, - &pTemp); - if (iRetcode) - return iRetcode; - pSHOW = (mng_ani_showp)pTemp; -#else - MNG_ALLOC (pData, pSHOW, sizeof (mng_ani_show)); - - pSHOW->sHeader.fCleanup = mng_free_ani_show; - pSHOW->sHeader.fProcess = mng_process_ani_show; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pSHOW); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pSHOW->iFirstid = iFirstid; - pSHOW->iLastid = iLastid; - pSHOW->iMode = iMode; -#else - pSHOW->iFirstid = pData->iSHOWfromid; - pSHOW->iLastid = pData->iSHOWtoid; - pSHOW->iMode = pData->iSHOWmode; -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_SHOW, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_show (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_SHOW, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_show)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_SHOW, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_show (mng_datap pData, - mng_objectp pObject) -{ - mng_retcode iRetcode; - mng_ani_showp pSHOW = (mng_ani_showp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SHOW, MNG_LC_START); -#endif - - if (pData->iBreakpoint) /* returning from breakpoint ? */ - { - iRetcode = mng_process_display_show (pData); - } - else - { /* "re-run" SHOW chunk */ - pData->iSHOWmode = pSHOW->iMode; - pData->iSHOWfromid = pSHOW->iFirstid; - pData->iSHOWtoid = pSHOW->iLastid; - - iRetcode = mng_process_display_show (pData); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SHOW, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_TERM -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_term (mng_datap pData, - mng_uint8 iTermaction, - mng_uint8 iIteraction, - mng_uint32 iDelay, - mng_uint32 iItermax) -#else -mng_retcode mng_create_ani_term (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ani_termp pTERM; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_TERM, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_term), - mng_free_obj_general, - mng_process_ani_term, - &pTemp); - if (iRetcode) - return iRetcode; - pTERM = (mng_ani_termp)pTemp; -#else - MNG_ALLOC (pData, pTERM, sizeof (mng_ani_term)); - - pTERM->sHeader.fCleanup = mng_free_ani_term; - pTERM->sHeader.fProcess = mng_process_ani_term; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pTERM); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pTERM->iTermaction = iTermaction; - pTERM->iIteraction = iIteraction; - pTERM->iDelay = iDelay; - pTERM->iItermax = iItermax; -#else - pTERM->iTermaction = ((mng_termp)pChunk)->iTermaction; - pTERM->iIteraction = ((mng_termp)pChunk)->iIteraction; - pTERM->iDelay = ((mng_termp)pChunk)->iDelay; - pTERM->iItermax = ((mng_termp)pChunk)->iItermax; -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_TERM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_term (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_TERM, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_term)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_TERM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_term (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_TERM, MNG_LC_START); -#endif - - /* dummy: no action required! */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_TERM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SAVE -mng_retcode mng_create_ani_save (mng_datap pData) -{ - mng_ptr pTemp; - mng_ani_savep pSAVE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_SAVE, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_save), - mng_free_obj_general, - mng_process_ani_save, - &pTemp); - if (iRetcode) - return iRetcode; - pSAVE = (mng_ani_savep)pTemp; -#else - MNG_ALLOC (pData, pSAVE, sizeof (mng_ani_save)); - - pSAVE->sHeader.fCleanup = mng_free_ani_save; - pSAVE->sHeader.fProcess = mng_process_ani_save; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pSAVE); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_SAVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_save (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_SAVE, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_save)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_SAVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_save (mng_datap pData, - mng_objectp pObject) -{ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SAVE, MNG_LC_START); -#endif - - iRetcode = mng_process_display_save (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SAVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_SEEK -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_seek (mng_datap pData, - mng_uint32 iSegmentnamesize, - mng_pchar zSegmentname) -#else -mng_retcode mng_create_ani_seek (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ptr pTemp; - mng_ani_seekp pSEEK; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_SEEK, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_seek), - mng_free_ani_seek, - mng_process_ani_seek, - &pTemp); - if (iRetcode) - return iRetcode; - pSEEK = (mng_ani_seekp)pTemp; -#else - MNG_ALLOC (pData, pSEEK, sizeof (mng_ani_seek)); - - pSEEK->sHeader.fCleanup = mng_free_ani_seek; - pSEEK->sHeader.fProcess = mng_process_ani_seek; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pSEEK); - - pData->pLastseek = (mng_objectp)pSEEK; - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pSEEK->iSegmentnamesize = iSegmentnamesize; - if (iSegmentnamesize) - { - MNG_ALLOC (pData, pSEEK->zSegmentname, iSegmentnamesize + 1); - MNG_COPY (pSEEK->zSegmentname, zSegmentname, iSegmentnamesize); - } -#else - pSEEK->iSegmentnamesize = ((mng_seekp)pChunk)->iNamesize; - if (pSEEK->iSegmentnamesize) - { - MNG_ALLOC (pData, pSEEK->zSegmentname, pSEEK->iSegmentnamesize + 1); - MNG_COPY (pSEEK->zSegmentname, ((mng_seekp)pChunk)->zName, pSEEK->iSegmentnamesize); - } -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_SEEK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_free_ani_seek (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_seekp pSEEK = (mng_ani_seekp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_SEEK, MNG_LC_START); -#endif - - if (pSEEK->iSegmentnamesize) - MNG_FREEX (pData, pSEEK->zSegmentname, pSEEK->iSegmentnamesize + 1); - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - MNG_FREEX (pData, pObject, sizeof (mng_ani_seek)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_SEEK, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - return MNG_NOERROR; -#else - return mng_free_obj_general(pData, pObject); -#endif -} - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_seek (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_seekp pSEEK = (mng_ani_seekp)pObject; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SEEK, MNG_LC_START); -#endif - -#ifdef MNG_SUPPORT_DYNAMICMNG - if (!pData->bStopafterseek) /* can we really process this one ? */ -#endif - { - pData->pLastseek = pObject; - - if (pData->fProcessseek) /* inform the app ? */ - { - mng_bool bOke; - mng_pchar zName; - - MNG_ALLOC (pData, zName, pSEEK->iSegmentnamesize + 1); - - if (pSEEK->iSegmentnamesize) - MNG_COPY (zName, pSEEK->zSegmentname, pSEEK->iSegmentnamesize); - - bOke = pData->fProcessseek ((mng_handle)pData, zName); - - MNG_FREEX (pData, zName, pSEEK->iSegmentnamesize + 1); - - if (!bOke) - MNG_ERROR (pData, MNG_APPMISCERROR); - } - } - - iRetcode = mng_process_display_seek (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SEEK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_dhdr (mng_datap pData, - mng_uint16 iObjectid, - mng_uint8 iImagetype, - mng_uint8 iDeltatype, - mng_uint32 iBlockwidth, - mng_uint32 iBlockheight, - mng_uint32 iBlockx, - mng_uint32 iBlocky) -#else -mng_retcode mng_create_ani_dhdr (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ani_dhdrp pDHDR; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_DHDR, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - iRetcode = create_obj_general (pData, sizeof (mng_ani_dhdr), - mng_free_obj_general, - mng_process_ani_dhdr, - &pTemp); - if (iRetcode) - return iRetcode; - pDHDR = (mng_ani_dhdrp)pTemp; -#else - MNG_ALLOC (pData, pDHDR, sizeof (mng_ani_dhdr)); - - pDHDR->sHeader.fCleanup = mng_free_ani_dhdr; - pDHDR->sHeader.fProcess = mng_process_ani_dhdr; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pDHDR); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pDHDR->iObjectid = iObjectid; - pDHDR->iImagetype = iImagetype; - pDHDR->iDeltatype = iDeltatype; - pDHDR->iBlockwidth = iBlockwidth; - pDHDR->iBlockheight = iBlockheight; - pDHDR->iBlockx = iBlockx; - pDHDR->iBlocky = iBlocky; -#else - pDHDR->iObjectid = ((mng_dhdrp)pChunk)->iObjectid; - pDHDR->iImagetype = ((mng_dhdrp)pChunk)->iImagetype; - pDHDR->iDeltatype = ((mng_dhdrp)pChunk)->iDeltatype; - pDHDR->iBlockwidth = ((mng_dhdrp)pChunk)->iBlockwidth; - pDHDR->iBlockheight = ((mng_dhdrp)pChunk)->iBlockheight; - pDHDR->iBlockx = ((mng_dhdrp)pChunk)->iBlockx; - pDHDR->iBlocky = ((mng_dhdrp)pChunk)->iBlocky; -#endif - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -#ifndef MNG_OPTIMIZE_CHUNKREADER - iRetcode = mng_process_display_dhdr (pData, iObjectid, - iImagetype, iDeltatype, - iBlockwidth, iBlockheight, - iBlockx, iBlocky); -#else - iRetcode = mng_process_display_dhdr (pData, - ((mng_dhdrp)pChunk)->iObjectid, - ((mng_dhdrp)pChunk)->iImagetype, - ((mng_dhdrp)pChunk)->iDeltatype, - ((mng_dhdrp)pChunk)->iBlockwidth, - ((mng_dhdrp)pChunk)->iBlockheight, - ((mng_dhdrp)pChunk)->iBlockx, - ((mng_dhdrp)pChunk)->iBlocky); -#endif -#else -#ifndef MNG_OPTIMIZE_CHUNKREADER - pData->iDHDRobjectid = iObjectid; - pData->iDHDRimagetype = iImagetype; - pData->iDHDRdeltatype = iDeltatype; - pData->iDHDRblockwidth = iBlockwidth; - pData->iDHDRblockheight = iBlockheight; - pData->iDHDRblockx = iBlockx; - pData->iDHDRblocky = iBlocky; -#else - pData->iDHDRobjectid = ((mng_dhdrp)pChunk)->iObjectid; - pData->iDHDRimagetype = ((mng_dhdrp)pChunk)->iImagetype; - pData->iDHDRdeltatype = ((mng_dhdrp)pChunk)->iDeltatype; - pData->iDHDRblockwidth = ((mng_dhdrp)pChunk)->iBlockwidth; - pData->iDHDRblockheight = ((mng_dhdrp)pChunk)->iBlockheight; - pData->iDHDRblockx = ((mng_dhdrp)pChunk)->iBlockx; - pData->iDHDRblocky = ((mng_dhdrp)pChunk)->iBlocky; -#endif - - iRetcode = mng_process_display_dhdr (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_DHDR, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_dhdr (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_DHDR, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_dhdr)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_DHDR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_dhdr (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_dhdrp pDHDR = (mng_ani_dhdrp)pObject; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_DHDR, MNG_LC_START); -#endif - - pData->bHasDHDR = MNG_TRUE; /* let everyone know we're inside a DHDR */ - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mng_process_display_dhdr (pData, pDHDR->iObjectid, - pDHDR->iImagetype, pDHDR->iDeltatype, - pDHDR->iBlockwidth, pDHDR->iBlockheight, - pDHDR->iBlockx, pDHDR->iBlocky); -#else - pData->iDHDRobjectid = pDHDR->iObjectid; - pData->iDHDRimagetype = pDHDR->iImagetype; - pData->iDHDRdeltatype = pDHDR->iDeltatype; - pData->iDHDRblockwidth = pDHDR->iBlockwidth; - pData->iDHDRblockheight = pDHDR->iBlockheight; - pData->iDHDRblockx = pDHDR->iBlockx; - pData->iDHDRblocky = pDHDR->iBlocky; - - iRetcode = mng_process_display_dhdr (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_DHDR, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_prom (mng_datap pData, - mng_uint8 iBitdepth, - mng_uint8 iColortype, - mng_uint8 iFilltype) -#else -mng_retcode mng_create_ani_prom (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ani_promp pPROM=NULL; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_PROM, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - iRetcode = create_obj_general (pData, sizeof (mng_ani_prom), - mng_free_obj_general, - mng_process_ani_prom, - &pTemp); - if (iRetcode) - return iRetcode; - pPROM = (mng_ani_promp)pTemp; -#else - MNG_ALLOC (pData, pPROM, sizeof (mng_ani_prom)); - - pPROM->sHeader.fCleanup = mng_free_ani_prom; - pPROM->sHeader.fProcess = mng_process_ani_prom; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pPROM); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pPROM->iBitdepth = iBitdepth; - pPROM->iColortype = iColortype; - pPROM->iFilltype = iFilltype; -#else - pPROM->iBitdepth = ((mng_promp)pChunk)->iSampledepth; - pPROM->iColortype = ((mng_promp)pChunk)->iColortype; - pPROM->iFilltype = ((mng_promp)pChunk)->iFilltype; -#endif - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -#ifndef MNG_OPTIMIZE_CHUNKREADER - iRetcode = mng_process_display_prom (pData, iBitdepth, - iColortype, iFilltype); -#else - iRetcode = mng_process_display_prom (pData, - ((mng_promp)pChunk)->iSampledepth, - ((mng_promp)pChunk)->iColortype, - ((mng_promp)pChunk)->iFilltype); -#endif -#else -#ifndef MNG_OPTIMIZE_CHUNKREADER - pData->iPROMbitdepth = iBitdepth; - pData->iPROMcolortype = iColortype; - pData->iPROMfilltype = iFilltype; -#else - pData->iPROMbitdepth = ((mng_promp)pChunk)->iSampledepth; - pData->iPROMcolortype = ((mng_promp)pChunk)->iColortype; - pData->iPROMfilltype = ((mng_promp)pChunk)->iFilltype; -#endif - - iRetcode = mng_process_display_prom (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_PROM, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_prom (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_PROM, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_prom)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_PROM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_prom (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_promp pPROM = (mng_ani_promp)pObject; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PROM, MNG_LC_START); -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mng_process_display_prom (pData, pPROM->iBitdepth, - pPROM->iColortype, pPROM->iFilltype); -#else - pData->iPROMbitdepth = pPROM->iBitdepth; - pData->iPROMcolortype = pPROM->iColortype; - pData->iPROMfilltype = pPROM->iFilltype; - - iRetcode = mng_process_display_prom (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PROM, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode mng_create_ani_ipng (mng_datap pData) -{ - mng_ani_ipngp pIPNG; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_IPNG, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_ipng), - mng_free_obj_general, - mng_process_ani_ipng, - &pTemp); - if (iRetcode) - return iRetcode; - pIPNG = (mng_ani_ipngp)pTemp; -#else - MNG_ALLOC (pData, pIPNG, sizeof (mng_ani_ipng)); - - pIPNG->sHeader.fCleanup = mng_free_ani_ipng; - pIPNG->sHeader.fProcess = mng_process_ani_ipng; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pIPNG); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_IPNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_ipng (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_IPNG, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_ipng)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_IPNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_ipng (mng_datap pData, - mng_objectp pObject) -{ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_IPNG, MNG_LC_START); -#endif - - iRetcode = mng_process_display_ipng (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_IPNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG -mng_retcode mng_create_ani_ijng (mng_datap pData) -{ - mng_ani_ijngp pIJNG; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_IJNG, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_ijng), - mng_free_obj_general, - mng_process_ani_ijng, - &pTemp); - if (iRetcode) - return iRetcode; - pIJNG = (mng_ani_ijngp)pTemp; -#else - MNG_ALLOC (pData, pIJNG, sizeof (mng_ani_ijng)); - - pIJNG->sHeader.fCleanup = mng_free_ani_ijng; - pIJNG->sHeader.fProcess = mng_process_ani_ijng; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pIJNG); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_IJNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_ijng (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_IJNG, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_ijng)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_IJNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_ijng (mng_datap pData, - mng_objectp pObject) -{ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_IJNG, MNG_LC_START); -#endif - - iRetcode = mng_process_display_ijng (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_IJNG, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode mng_create_ani_pplt (mng_datap pData, - mng_uint8 iType, - mng_uint32 iCount, - mng_palette8ep paIndexentries, - mng_uint8p paAlphaentries, - mng_uint8p paUsedentries) -{ - mng_ani_ppltp pPPLT; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_PPLT, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - iRetcode = create_obj_general (pData, sizeof (mng_ani_pplt), - mng_free_obj_general, - mng_process_ani_pplt, - &pTemp); - if (iRetcode) - return iRetcode; - pPPLT = (mng_ani_ppltp)pTemp; -#else - MNG_ALLOC (pData, pPPLT, sizeof (mng_ani_pplt)); - - pPPLT->sHeader.fCleanup = mng_free_ani_pplt; - pPPLT->sHeader.fProcess = mng_process_ani_pplt; -#endif - - pPPLT->iType = iType; - pPPLT->iCount = iCount; - - MNG_COPY (pPPLT->aIndexentries, paIndexentries, sizeof (pPPLT->aIndexentries)); - MNG_COPY (pPPLT->aAlphaentries, paAlphaentries, sizeof (pPPLT->aAlphaentries)); - MNG_COPY (pPPLT->aUsedentries, paUsedentries, sizeof (pPPLT->aUsedentries )); - - mng_add_ani_object (pData, (mng_object_headerp)pPPLT); - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mng_process_display_pplt (pData, iType, iCount, - paIndexentries, paAlphaentries, paUsedentries); -#else - pData->iPPLTtype = iType; - pData->iPPLTcount = iCount; - pData->paPPLTindexentries = paIndexentries; - pData->paPPLTalphaentries = paAlphaentries; - pData->paPPLTusedentries = paUsedentries; - - iRetcode = mng_process_display_pplt (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_PPLT, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_pplt (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_PPLT, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_pplt)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_PPLT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_pplt (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_ppltp pPPLT = (mng_ani_ppltp)pObject; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PPLT, MNG_LC_START); -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mng_process_display_pplt (pData, pPPLT->iType, pPPLT->iCount, - pPPLT->aIndexentries, pPPLT->aAlphaentries, - pPPLT->aUsedentries); -#else - pData->iPPLTtype = pPPLT->iType; - pData->iPPLTcount = pPPLT->iCount; - pData->paPPLTindexentries = &pPPLT->aIndexentries; - pData->paPPLTalphaentries = &pPPLT->aAlphaentries; - pData->paPPLTusedentries = &pPPLT->aUsedentries; - - iRetcode = mng_process_display_pplt (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PPLT, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MAGN -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_magn (mng_datap pData, - mng_uint16 iFirstid, - mng_uint16 iLastid, - mng_uint8 iMethodX, - mng_uint16 iMX, - mng_uint16 iMY, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint16 iMT, - mng_uint16 iMB, - mng_uint8 iMethodY) -#else -mng_retcode mng_create_ani_magn (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ani_magnp pMAGN=NULL; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_MAGN, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - iRetcode = create_obj_general (pData, sizeof (mng_ani_magn), - mng_free_obj_general, - mng_process_ani_magn, - &pTemp); - if (iRetcode) - return iRetcode; - pMAGN = (mng_ani_magnp)pTemp; -#else - MNG_ALLOC (pData, pMAGN, sizeof (mng_ani_magn)); - - pMAGN->sHeader.fCleanup = mng_free_ani_magn; - pMAGN->sHeader.fProcess = mng_process_ani_magn; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pMAGN); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pMAGN->iFirstid = iFirstid; - pMAGN->iLastid = iLastid; - pMAGN->iMethodX = iMethodX; - pMAGN->iMX = iMX; - pMAGN->iMY = iMY; - pMAGN->iML = iML; - pMAGN->iMR = iMR; - pMAGN->iMT = iMT; - pMAGN->iMB = iMB; - pMAGN->iMethodY = iMethodY; -#else - pMAGN->iFirstid = ((mng_magnp)pChunk)->iFirstid; - pMAGN->iLastid = ((mng_magnp)pChunk)->iLastid; - pMAGN->iMethodX = ((mng_magnp)pChunk)->iMethodX; - pMAGN->iMX = ((mng_magnp)pChunk)->iMX; - pMAGN->iMY = ((mng_magnp)pChunk)->iMY; - pMAGN->iML = ((mng_magnp)pChunk)->iML; - pMAGN->iMR = ((mng_magnp)pChunk)->iMR; - pMAGN->iMT = ((mng_magnp)pChunk)->iMT; - pMAGN->iMB = ((mng_magnp)pChunk)->iMB; - pMAGN->iMethodY = ((mng_magnp)pChunk)->iMethodY; -#endif - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -#ifndef MNG_OPTIMIZE_CHUNKREADER - iRetcode = mng_process_display_magn (pData, pMAGN->iFirstid, pMAGN->iLastid, - pMAGN->iMethodX, pMAGN->iMX, pMAGN->iMY, - pMAGN->iML, pMAGN->iMR, pMAGN->iMT, - pMAGN->iMB, pMAGN->iMethodY); -#else - iRetcode = mng_process_display_magn (pData, - ((mng_magnp)pChunk)->iFirstid, - ((mng_magnp)pChunk)->iLastid, - ((mng_magnp)pChunk)->iMethodX, - ((mng_magnp)pChunk)->iMX, - ((mng_magnp)pChunk)->iMY, - ((mng_magnp)pChunk)->iML, - ((mng_magnp)pChunk)->iMR, - ((mng_magnp)pChunk)->iMT, - ((mng_magnp)pChunk)->iMB, - ((mng_magnp)pChunk)->iMethodY); -#endif -#else -#ifndef MNG_OPTIMIZE_CHUNKREADER - pData->iMAGNfirstid = iFirstid; - pData->iMAGNlastid = iLastid; - pData->iMAGNmethodX = iMethodX; - pData->iMAGNmX = iMX; - pData->iMAGNmY = iMY; - pData->iMAGNmL = iML; - pData->iMAGNmR = iMR; - pData->iMAGNmT = iMT; - pData->iMAGNmB = iMB; - pData->iMAGNmethodY = iMethodY; -#else - pData->iMAGNfirstid = ((mng_magnp)pChunk)->iFirstid; - pData->iMAGNlastid = ((mng_magnp)pChunk)->iLastid; - pData->iMAGNmethodX = ((mng_magnp)pChunk)->iMethodX; - pData->iMAGNmX = ((mng_magnp)pChunk)->iMX; - pData->iMAGNmY = ((mng_magnp)pChunk)->iMY; - pData->iMAGNmL = ((mng_magnp)pChunk)->iML; - pData->iMAGNmR = ((mng_magnp)pChunk)->iMR; - pData->iMAGNmT = ((mng_magnp)pChunk)->iMT; - pData->iMAGNmB = ((mng_magnp)pChunk)->iMB; - pData->iMAGNmethodY = ((mng_magnp)pChunk)->iMethodY; -#endif - - iRetcode = mng_process_display_magn (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_MAGN, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_OBJCLEANUP -mng_retcode mng_free_ani_magn (mng_datap pData, - mng_objectp pObject) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_MAGN, MNG_LC_START); -#endif - - MNG_FREEX (pData, pObject, sizeof (mng_ani_magn)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_MAGN, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_magn (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_magnp pMAGN = (mng_ani_magnp)pObject; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_MAGN, MNG_LC_START); -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mng_process_display_magn (pData, pMAGN->iFirstid, pMAGN->iLastid, - pMAGN->iMethodX, pMAGN->iMX, pMAGN->iMY, - pMAGN->iML, pMAGN->iMR, pMAGN->iMT, - pMAGN->iMB, pMAGN->iMethodY); -#else - pData->iMAGNfirstid = pMAGN->iFirstid; - pData->iMAGNlastid = pMAGN->iLastid; - pData->iMAGNmethodX = pMAGN->iMethodX; - pData->iMAGNmX = pMAGN->iMX; - pData->iMAGNmY = pMAGN->iMY; - pData->iMAGNmL = pMAGN->iML; - pData->iMAGNmR = pMAGN->iMR; - pData->iMAGNmT = pMAGN->iMT; - pData->iMAGNmB = pMAGN->iMB; - pData->iMAGNmethodY = pMAGN->iMethodY; - - iRetcode = mng_process_display_magn (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_MAGN, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_past (mng_datap pData, - mng_uint16 iTargetid, - mng_uint8 iTargettype, - mng_int32 iTargetx, - mng_int32 iTargety, - mng_uint32 iCount, - mng_ptr pSources) -#else -mng_retcode mng_create_ani_past (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ani_pastp pPAST; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_PAST, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - iRetcode = create_obj_general (pData, sizeof (mng_ani_past), - mng_free_ani_past, - mng_process_ani_past, - &pTemp); - if (iRetcode) - return iRetcode; - pPAST = (mng_ani_pastp)pTemp; -#else - MNG_ALLOC (pData, pPAST, sizeof (mng_ani_past)); - - pPAST->sHeader.fCleanup = mng_free_ani_past; - pPAST->sHeader.fProcess = mng_process_ani_past; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pPAST); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pPAST->iTargetid = iTargetid; - pPAST->iTargettype = iTargettype; - pPAST->iTargetx = iTargetx; - pPAST->iTargety = iTargety; - pPAST->iCount = iCount; - - if (iCount) - { - MNG_ALLOC (pData, pPAST->pSources, (iCount * sizeof (mng_past_source))); - MNG_COPY (pPAST->pSources, pSources, (iCount * sizeof (mng_past_source))); - } -#else - pPAST->iTargetid = ((mng_pastp)pChunk)->iDestid; - pPAST->iTargettype = ((mng_pastp)pChunk)->iTargettype; - pPAST->iTargetx = ((mng_pastp)pChunk)->iTargetx; - pPAST->iTargety = ((mng_pastp)pChunk)->iTargety; - pPAST->iCount = ((mng_pastp)pChunk)->iCount; - - if (pPAST->iCount) - { - mng_size_t iSize = (mng_size_t)(pPAST->iCount * sizeof (mng_past_source)); - MNG_ALLOC (pData, pPAST->pSources, iSize); - MNG_COPY (pPAST->pSources, ((mng_pastp)pChunk)->pSources, iSize); - } -#endif - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -#ifndef MNG_OPTIMIZE_CHUNKREADER - iRetcode = mng_process_display_past (pData, iTargetid, iTargettype, - iTargetx, iTargety, - iCount, pSources); -#else - iRetcode = mng_process_display_past (pData, - ((mng_pastp)pChunk)->iDestid, - ((mng_pastp)pChunk)->iTargettype, - ((mng_pastp)pChunk)->iTargetx, - ((mng_pastp)pChunk)->iTargety, - ((mng_pastp)pChunk)->iCount, - ((mng_pastp)pChunk)->pSources); -#endif -#else -#ifndef MNG_OPTIMIZE_CHUNKREADER - pData->iPASTtargetid = iTargetid; - pData->iPASTtargettype = iTargettype; - pData->iPASTtargetx = iTargetx; - pData->iPASTtargety = iTargety; - pData->iPASTcount = iCount; - pData->pPASTsources = pSources; -#else - pData->iPASTtargetid = ((mng_pastp)pChunk)->iDestid; - pData->iPASTtargettype = ((mng_pastp)pChunk)->iTargettype; - pData->iPASTtargetx = ((mng_pastp)pChunk)->iTargetx; - pData->iPASTtargety = ((mng_pastp)pChunk)->iTargety; - pData->iPASTcount = ((mng_pastp)pChunk)->iCount; - pData->pPASTsources = ((mng_pastp)pChunk)->pSources; -#endif - - iRetcode = mng_process_display_past (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_PAST, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -mng_retcode mng_free_ani_past (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_pastp pPAST = (mng_ani_pastp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_PAST, MNG_LC_START); -#endif - - if (pPAST->iCount) - MNG_FREEX (pData, pPAST->pSources, (pPAST->iCount * sizeof (mng_past_source))); - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - MNG_FREEX (pData, pObject, sizeof (mng_ani_past)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_PAST, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - return MNG_NOERROR; -#else - return mng_free_obj_general(pData, pObject); -#endif -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -mng_retcode mng_process_ani_past (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_pastp pPAST = (mng_ani_pastp)pObject; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PAST, MNG_LC_START); -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mng_process_display_past (pData, pPAST->iTargetid, pPAST->iTargettype, - pPAST->iTargetx, pPAST->iTargety, - pPAST->iCount, pPAST->pSources); -#else - pData->iPASTtargetid = pPAST->iTargetid; - pData->iPASTtargettype = pPAST->iTargettype; - pData->iPASTtargetx = pPAST->iTargetx; - pData->iPASTtargety = pPAST->iTargety; - pData->iPASTcount = pPAST->iCount; - pData->pPASTsources = pPAST->pSources; - - iRetcode = mng_process_display_past (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PAST, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_DISC -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ani_disc (mng_datap pData, - mng_uint32 iCount, - mng_uint16p pIds) -#else -mng_retcode mng_create_ani_disc (mng_datap pData, - mng_chunkp pChunk) -#endif -{ - mng_ani_discp pDISC; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_DISC, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - iRetcode = create_obj_general (pData, sizeof (mng_ani_disc), - mng_free_ani_disc, - mng_process_ani_disc, - &pTemp); - if (iRetcode) - return iRetcode; - pDISC = (mng_ani_discp)pTemp; -#else - MNG_ALLOC (pData, pDISC, sizeof (mng_ani_disc)); - - pDISC->sHeader.fCleanup = mng_free_ani_disc; - pDISC->sHeader.fProcess = mng_process_ani_disc; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pDISC); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pDISC->iCount = iCount; - - if (iCount) - { - MNG_ALLOC (pData, pDISC->pIds, (iCount << 1)); - MNG_COPY (pDISC->pIds, pIds, (iCount << 1)); - } -#else - pDISC->iCount = ((mng_discp)pChunk)->iCount; - - if (pDISC->iCount) - { - mng_size_t iSize = (mng_size_t)(pDISC->iCount << 1); - MNG_ALLOC (pData, pDISC->pIds, iSize); - MNG_COPY (pDISC->pIds, ((mng_discp)pChunk)->pObjectids, iSize); - } -#endif - } - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS -#ifndef MNG_OPTIMIZE_CHUNKREADER - iRetcode = mng_process_display_disc (pData, iCount, pIds); -#else - iRetcode = mng_process_display_disc (pData, - ((mng_discp)pChunk)->iCount, - ((mng_discp)pChunk)->pObjectids); -#endif -#else -#ifndef MNG_OPTIMIZE_CHUNKREADER - pData->iDISCcount = iCount; - pData->pDISCids = pIds; -#else - pData->iDISCcount = ((mng_discp)pChunk)->iCount; - pData->pDISCids = ((mng_discp)pChunk)->pObjectids; -#endif - - iRetcode = mng_process_display_disc (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANI_DISC, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_free_ani_disc (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_discp pDISC = (mng_ani_discp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_DISC, MNG_LC_START); -#endif - - if (pDISC->iCount) - MNG_FREEX (pData, pDISC->pIds, (pDISC->iCount << 1)); - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - MNG_FREEX (pData, pObject, sizeof (mng_ani_disc)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANI_DISC, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - return MNG_NOERROR; -#else - return mng_free_obj_general(pData, pObject); -#endif -} - -/* ************************************************************************** */ - -mng_retcode mng_process_ani_disc (mng_datap pData, - mng_objectp pObject) -{ - mng_ani_discp pDISC = (mng_ani_discp)pObject; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_DISC, MNG_LC_START); -#endif - -#ifndef MNG_OPTIMIZE_DISPLAYCALLS - iRetcode = mng_process_display_disc (pData, pDISC->iCount, pDISC->pIds); -#else - pData->iDISCcount = pDISC->iCount; - pData->pDISCids = pDISC->pIds; - - iRetcode = mng_process_display_disc (pData); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANI_DISC, MNG_LC_END); -#endif - - return iRetcode; -} -#endif - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DYNAMICMNG - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_event (mng_datap pData, - mng_uint8 iEventtype, - mng_uint8 iMasktype, - mng_int32 iLeft, - mng_int32 iRight, - mng_int32 iTop, - mng_int32 iBottom, - mng_uint16 iObjectid, - mng_uint8 iIndex, - mng_uint32 iSegmentnamesize, - mng_pchar zSegmentname) -#else -mng_retcode mng_create_event (mng_datap pData, - mng_ptr pEntry) -#endif -{ - mng_eventp pEvent; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_EVENT, MNG_LC_START); -#endif - - if (pData->bCacheplayback) /* caching playback info ? */ - { - mng_object_headerp pLast; - -#ifdef MNG_OPTIMIZE_OBJCLEANUP - mng_ptr pTemp; - mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_event), - mng_free_event, - mng_process_event, - &pTemp); - if (iRetcode) - return iRetcode; - pEvent = (mng_eventp)pTemp; -#else - MNG_ALLOC (pData, pEvent, sizeof (mng_event)); - - pEvent->sHeader.fCleanup = mng_free_event; - pEvent->sHeader.fProcess = mng_process_event; -#endif - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pEvent->iEventtype = iEventtype; - pEvent->iMasktype = iMasktype; - pEvent->iLeft = iLeft; - pEvent->iRight = iRight; - pEvent->iTop = iTop; - pEvent->iBottom = iBottom; - pEvent->iObjectid = iObjectid; - pEvent->iIndex = iIndex; - pEvent->iSegmentnamesize = iSegmentnamesize; - - if (iSegmentnamesize) - { - MNG_ALLOC (pData, pEvent->zSegmentname, iSegmentnamesize+1); - MNG_COPY (pEvent->zSegmentname, zSegmentname, iSegmentnamesize); - } -#else - pEvent->iEventtype = ((mng_evnt_entryp)pEntry)->iEventtype; - pEvent->iMasktype = ((mng_evnt_entryp)pEntry)->iMasktype; - pEvent->iLeft = ((mng_evnt_entryp)pEntry)->iLeft; - pEvent->iRight = ((mng_evnt_entryp)pEntry)->iRight; - pEvent->iTop = ((mng_evnt_entryp)pEntry)->iTop; - pEvent->iBottom = ((mng_evnt_entryp)pEntry)->iBottom; - pEvent->iObjectid = ((mng_evnt_entryp)pEntry)->iObjectid; - pEvent->iIndex = ((mng_evnt_entryp)pEntry)->iIndex; - pEvent->iSegmentnamesize = ((mng_evnt_entryp)pEntry)->iSegmentnamesize; - - if (pEvent->iSegmentnamesize) - { - MNG_ALLOC (pData, pEvent->zSegmentname, pEvent->iSegmentnamesize+1); - MNG_COPY (pEvent->zSegmentname, ((mng_evnt_entryp)pEntry)->zSegmentname, pEvent->iSegmentnamesize); - } -#endif - /* fixup the double-linked list */ - pLast = (mng_object_headerp)pData->pLastevent; - - if (pLast) /* link it as last in the chain */ - { - pEvent->sHeader.pPrev = pLast; - pLast->pNext = pEvent; - } - else - { - pData->pFirstevent = pEvent; - } - - pData->pLastevent = pEvent; - pData->bDynamic = MNG_TRUE; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_EVENT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_free_event (mng_datap pData, - mng_objectp pObject) -{ - mng_eventp pEvent = (mng_eventp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_EVENT, MNG_LC_START); -#endif - - if (pEvent->iSegmentnamesize) - MNG_FREEX (pData, pEvent->zSegmentname, pEvent->iSegmentnamesize + 1); - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - MNG_FREEX (pData, pEvent, sizeof (mng_event)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_EVENT, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - return MNG_NOERROR; -#else - return mng_free_obj_general(pData, pObject); -#endif -} - -/* ************************************************************************** */ - -mng_retcode mng_process_event (mng_datap pData, - mng_objectp pObject) -{ -#ifndef MNG_SKIPCHUNK_SEEK - mng_eventp pEvent = (mng_eventp)pObject; - mng_object_headerp pAni; - mng_bool bFound = MNG_FALSE; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_EVENT, MNG_LC_START); -#endif - -#ifndef MNG_SKIPCHUNK_SEEK - if (!pEvent->pSEEK) /* need to find SEEK first ? */ - { - pAni = (mng_object_headerp)pData->pFirstaniobj; - - while ((pAni) && (!bFound)) - { - if ((pAni->fCleanup == mng_free_ani_seek) && - (strcmp(pEvent->zSegmentname, ((mng_ani_seekp)pAni)->zSegmentname) == 0)) - bFound = MNG_TRUE; - else - pAni = (mng_object_headerp)pAni->pNext; - } - - if (pAni) - pEvent->pSEEK = (mng_ani_seekp)pAni; - } - - if (pEvent->pSEEK) /* anything to do ? */ - { - pEvent->iLastx = pData->iEventx; - pEvent->iLasty = pData->iEventy; - /* let's start from this SEEK then */ - pData->pCurraniobj = (mng_objectp)pEvent->pSEEK; - pData->bRunningevent = MNG_TRUE; - /* wake-up the app ! */ - if (!pData->fSettimer ((mng_handle)pData, 5)) - MNG_ERROR (pData, MNG_APPTIMERERROR); - - } - else - MNG_ERROR (pData, MNG_SEEKNOTFOUND); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_EVENT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#endif /* MNG_SUPPORT_DYNAMICMNG */ - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_mpng_obj (mng_datap pData, - mng_uint32 iFramewidth, - mng_uint32 iFrameheight, - mng_uint16 iNumplays, - mng_uint16 iTickspersec, - mng_uint32 iFramessize, - mng_ptr pFrames) -#else -mng_retcode mng_create_mpng_obj (mng_datap pData, - mng_ptr pEntry) -#endif -{ - mng_mpng_objp pMPNG; - mng_ptr pTemp; - mng_retcode iRetcode; - mng_uint8p pFrame; - mng_int32 iCnt, iMax; - mng_uint32 iX, iY, iWidth, iHeight; - mng_int32 iXoffset, iYoffset; - mng_uint16 iTicks; - mng_uint16 iDelay; - mng_bool bNewframe; - mng_ani_loopp pLOOP; - mng_ani_endlp pENDL; - mng_ani_framp pFRAM; - mng_ani_movep pMOVE; - mng_ani_clipp pCLIP; - mng_ani_showp pSHOW; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_MPNG_OBJ, MNG_LC_START); -#endif - -#ifdef MNG_OPTIMIZE_OBJCLEANUP - iRetcode = create_obj_general (pData, sizeof (mng_mpng_obj), mng_free_mpng_obj, - mng_process_mpng_obj, &pTemp); - if (iRetcode) - return iRetcode; - pMPNG = (mng_mpng_objp)pTemp; -#else - MNG_ALLOC (pData, pMPNG, sizeof (mng_mpng_obj)); - - pMPNG->sHeader.fCleanup = mng_free_mpng_obj; - pMPNG->sHeader.fProcess = mng_process_mpng_obj; -#endif - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pMPNG->iFramewidth = iFramewidth; - pMPNG->iFrameheight = iFrameheight; - pMPNG->iNumplays = iNumplays; - pMPNG->iTickspersec = iTickspersec; - pMPNG->iFramessize = iFramessize; - - if (iFramessize) - { - MNG_ALLOC (pData, pMPNG->pFrames, iFramessize); - MNG_COPY (pMPNG->pFrames, pFrames, iFramessize); - } -#else - pMPNG->iFramewidth = ((mng_mpngp)pEntry)->iFramewidth; - pMPNG->iFrameheight = ((mng_mpngp)pEntry)->iFrameheight; - pMPNG->iNumplays = ((mng_mpngp)pEntry)->iNumplays; - pMPNG->iTickspersec = ((mng_mpngp)pEntry)->iTickspersec; - pMPNG->iFramessize = ((mng_mpngp)pEntry)->iFramessize; - - if (pMPNG->iFramessize) - { - MNG_ALLOC (pData, pMPNG->pFrames, pMPNG->iFramessize); - MNG_COPY (pMPNG->pFrames, ((mng_mpngp)pEntry)->pFrames, pMPNG->iFramessize); - } -#endif - - pData->pMPNG = pMPNG; - pData->eImagetype = mng_it_mpng; - - iRetcode = mng_process_display_mpng (pData); - if (iRetcode) - return iRetcode; - - /* now let's create the MNG animation directives from this */ - - pFrame = (mng_uint8p)pMPNG->pFrames; - iMax = pMPNG->iFramessize / 26; - /* set up MNG impersonation */ - pData->iTicks = pMPNG->iTickspersec; - pData->iLayercount = iMax; - - if (pMPNG->iNumplays != 1) /* create a LOOP/ENDL pair ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - iRetcode = create_obj_general (pData, sizeof (mng_ani_loop), - mng_free_ani_loop, mng_process_ani_loop, - &((mng_ptr)pLOOP)); - if (iRetcode) - return iRetcode; -#else - MNG_ALLOC (pData, pLOOP, sizeof (mng_ani_loop)); - - pLOOP->sHeader.fCleanup = mng_free_ani_loop; - pLOOP->sHeader.fProcess = mng_process_ani_loop; -#endif - - pLOOP->iLevel = 1; - if (pMPNG->iNumplays) - pLOOP->iRepeatcount = pMPNG->iNumplays; - else - pLOOP->iRepeatcount = 0xFFFFFFFFl; - - mng_add_ani_object (pData, (mng_object_headerp)pLOOP); - } - - bNewframe = MNG_TRUE; /* create the frame display objects */ - - for (iCnt = 0; iCnt < iMax; iCnt++) - { - iX = mng_get_uint32 (pFrame); - iY = mng_get_uint32 (pFrame+4); - iWidth = mng_get_uint32 (pFrame+8); - iHeight = mng_get_uint32 (pFrame+12); - iXoffset = mng_get_int32 (pFrame+16); - iYoffset = mng_get_int32 (pFrame+20); - iTicks = mng_get_uint16 (pFrame+24); - - iDelay = iTicks; - if (!iDelay) - { - mng_uint8p pTemp = pFrame+26; - mng_int32 iTemp = iCnt+1; - - while ((iTemp < iMax) && (!iDelay)) - { - iDelay = mng_get_uint16 (pTemp+24); - pTemp += 26; - iTemp++; - } - } - - if (bNewframe) - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - iRetcode = create_obj_general (pData, sizeof (mng_ani_fram), - mng_free_obj_general, mng_process_ani_fram, - &((mng_ptr)pFRAM)); - if (iRetcode) - return iRetcode; -#else - MNG_ALLOC (pData, pFRAM, sizeof (mng_ani_fram)); - - pFRAM->sHeader.fCleanup = mng_free_ani_fram; - pFRAM->sHeader.fProcess = mng_process_ani_fram; -#endif - - pFRAM->iFramemode = 4; - pFRAM->iChangedelay = 1; - pFRAM->iDelay = iDelay; - - mng_add_ani_object (pData, (mng_object_headerp)pFRAM); - } - -#ifdef MNG_OPTIMIZE_OBJCLEANUP - iRetcode = create_obj_general (pData, sizeof (mng_ani_move), - mng_free_obj_general, - mng_process_ani_move, - &((mng_ptr)pMOVE)); - if (iRetcode) - return iRetcode; -#else - MNG_ALLOC (pData, pMOVE, sizeof (mng_ani_move)); - - pMOVE->sHeader.fCleanup = mng_free_ani_move; - pMOVE->sHeader.fProcess = mng_process_ani_move; -#endif - - pMOVE->iLocax = iXoffset - (mng_int32)iX; - pMOVE->iLocay = iYoffset - (mng_int32)iY; - - mng_add_ani_object (pData, (mng_object_headerp)pMOVE); - -#ifdef MNG_OPTIMIZE_OBJCLEANUP - iRetcode = create_obj_general (pData, sizeof (mng_ani_clip), - mng_free_obj_general, - mng_process_ani_clip, - &((mng_ptr)pCLIP)); - if (iRetcode) - return iRetcode; -#else - MNG_ALLOC (pData, pCLIP, sizeof (mng_ani_clip)); - - pCLIP->sHeader.fCleanup = mng_free_ani_clip; - pCLIP->sHeader.fProcess = mng_process_ani_clip; -#endif - - pCLIP->iClipl = iXoffset; - pCLIP->iClipr = iXoffset + (mng_int32)iWidth; - pCLIP->iClipt = iYoffset; - pCLIP->iClipb = iYoffset + (mng_int32)iHeight; - - mng_add_ani_object (pData, (mng_object_headerp)pCLIP); - -#ifdef MNG_OPTIMIZE_OBJCLEANUP - iRetcode = create_obj_general (pData, sizeof (mng_ani_show), - mng_free_obj_general, mng_process_ani_show, - &((mng_ptr)pSHOW)); - if (iRetcode) - return iRetcode; -#else - MNG_ALLOC (pData, pSHOW, sizeof (mng_ani_show)); - - pSHOW->sHeader.fCleanup = mng_free_ani_show; - pSHOW->sHeader.fProcess = mng_process_ani_show; -#endif - - mng_add_ani_object (pData, (mng_object_headerp)pSHOW); - - bNewframe = (mng_bool)iTicks; - pFrame += 26; - } - - if (pMPNG->iNumplays != 1) /* create a LOOP/ENDL pair ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - iRetcode = create_obj_general (pData, sizeof (mng_ani_endl), - mng_free_obj_general, mng_process_ani_endl, - &((mng_ptr)pENDL)); - if (iRetcode) - return iRetcode; -#else - MNG_ALLOC (pData, pENDL, sizeof (mng_ani_endl)); - - pENDL->sHeader.fCleanup = mng_free_ani_endl; - pENDL->sHeader.fProcess = mng_process_ani_endl; -#endif - - pENDL->iLevel = 1; - - mng_add_ani_object (pData, (mng_object_headerp)pENDL); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_MPNG_OBJ, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_free_mpng_obj (mng_datap pData, - mng_objectp pObject) -{ - mng_mpng_objp pMPNG = (mng_mpng_objp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_MPNG_OBJ, MNG_LC_START); -#endif - - if (pMPNG->iFramessize) - MNG_FREEX (pData, pMPNG->pFrames, pMPNG->iFramessize); - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - MNG_FREEX (pData, pMPNG, sizeof (mng_mpng_obj)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_MPNG_OBJ, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - return MNG_NOERROR; -#else - return mng_free_obj_general(pData, pObject); -#endif -} - -/* ************************************************************************** */ - -mng_retcode mng_process_mpng_obj (mng_datap pData, - mng_objectp pObject) -{ - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_MPNG_PROPOSAL */ - -/* ************************************************************************** */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ANG_PROPOSAL - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_CHUNKREADER -mng_retcode mng_create_ang_obj (mng_datap pData, - mng_uint32 iNumframes, - mng_uint32 iTickspersec, - mng_uint32 iNumplays, - mng_uint32 iTilewidth, - mng_uint32 iTileheight, - mng_uint8 iInterlace, - mng_uint8 iStillused) -#else -mng_retcode mng_create_ang_obj (mng_datap pData, - mng_ptr pEntry) -#endif -{ - mng_ang_objp pANG; - mng_ptr pTemp; - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANG_OBJ, MNG_LC_START); -#endif - -#ifdef MNG_OPTIMIZE_OBJCLEANUP - iRetcode = create_obj_general (pData, sizeof (mng_ang_obj), mng_free_ang_obj, - mng_process_ang_obj, &pTemp); - if (iRetcode) - return iRetcode; - pANG = (mng_ang_objp)pTemp; -#else - MNG_ALLOC (pData, pANG, sizeof (mng_ang_obj)); - - pANG->sHeader.fCleanup = mng_free_ang_obj; - pANG->sHeader.fProcess = mng_process_ang_obj; -#endif - -#ifndef MNG_OPTIMIZE_CHUNKREADER - pANG->iNumframes = iNumframes; - pANG->iTickspersec = iTickspersec; - pANG->iNumplays = iNumplays; - pANG->iTilewidth = iTilewidth; - pANG->iTileheight = iTileheight; - pANG->iInterlace = iInterlace; - pANG->iStillused = iStillused; -#else - pANG->iNumframes = ((mng_ahdrp)pEntry)->iNumframes; - pANG->iTickspersec = ((mng_ahdrp)pEntry)->iTickspersec; - pANG->iNumplays = ((mng_ahdrp)pEntry)->iNumplays; - pANG->iTilewidth = ((mng_ahdrp)pEntry)->iTilewidth; - pANG->iTileheight = ((mng_ahdrp)pEntry)->iTileheight; - pANG->iInterlace = ((mng_ahdrp)pEntry)->iInterlace; - pANG->iStillused = ((mng_ahdrp)pEntry)->iStillused; -#endif - - pData->pANG = pANG; - pData->eImagetype = mng_it_ang; - - iRetcode = mng_process_display_ang (pData); - if (iRetcode) - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CREATE_ANG_OBJ, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_free_ang_obj (mng_datap pData, - mng_objectp pObject) -{ - mng_ang_objp pANG = (mng_ang_objp)pObject; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANG_OBJ, MNG_LC_START); -#endif - - if (pANG->iTilessize) - MNG_FREEX (pData, pANG->pTiles, pANG->iTilessize); - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - MNG_FREEX (pData, pANG, sizeof (mng_ang_obj)); -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FREE_ANG_OBJ, MNG_LC_END); -#endif - -#ifndef MNG_OPTIMIZE_OBJCLEANUP - return MNG_NOERROR; -#else - return mng_free_obj_general(pData, pObject); -#endif -} - -/* ************************************************************************** */ - -mng_retcode mng_process_ang_obj (mng_datap pData, - mng_objectp pObject) -{ - mng_ang_objp pANG = (mng_ang_objp)pObject; - mng_uint8p pTile = (mng_uint8p)pANG->pTiles; - mng_retcode iRetcode; - mng_int32 iCnt, iMax; - mng_uint32 iTicks; - mng_int32 iXoffset, iYoffset; - mng_uint8 iSource; - mng_ani_loopp pLOOP; - mng_ani_endlp pENDL; - mng_ani_framp pFRAM; - mng_ani_movep pMOVE; - mng_ani_showp pSHOW; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANG_OBJ, MNG_LC_START); -#endif - - /* let's create the MNG animation directives from this */ - - iMax = pANG->iNumframes; - /* set up MNG impersonation */ - pData->iTicks = pANG->iTickspersec; - pData->iLayercount = iMax; - - if (pANG->iNumplays != 1) /* create a LOOP/ENDL pair ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - iRetcode = create_obj_general (pData, sizeof (mng_ani_loop), - mng_free_ani_loop, mng_process_ani_loop, - &((mng_ptr)pLOOP)); - if (iRetcode) - return iRetcode; -#else - MNG_ALLOC (pData, pLOOP, sizeof (mng_ani_loop)); - - pLOOP->sHeader.fCleanup = mng_free_ani_loop; - pLOOP->sHeader.fProcess = mng_process_ani_loop; -#endif - - pLOOP->iLevel = 1; - if (pANG->iNumplays) - pLOOP->iRepeatcount = pANG->iNumplays; - else - pLOOP->iRepeatcount = 0xFFFFFFFFl; - - mng_add_ani_object (pData, (mng_object_headerp)pLOOP); - } - - for (iCnt = 0; iCnt < iMax; iCnt++) - { - iTicks = mng_get_uint32 (pTile); - iXoffset = mng_get_int32 (pTile+4); - iYoffset = mng_get_int32 (pTile+8); - iSource = *(pTile+12); - -#ifdef MNG_OPTIMIZE_OBJCLEANUP - iRetcode = create_obj_general (pData, sizeof (mng_ani_fram), - mng_free_obj_general, mng_process_ani_fram, - &((mng_ptr)pFRAM)); - if (iRetcode) - return iRetcode; -#else - MNG_ALLOC (pData, pFRAM, sizeof (mng_ani_fram)); - - pFRAM->sHeader.fCleanup = mng_free_ani_fram; - pFRAM->sHeader.fProcess = mng_process_ani_fram; -#endif - - pFRAM->iFramemode = 4; - pFRAM->iChangedelay = 1; - pFRAM->iDelay = iTicks; - - mng_add_ani_object (pData, (mng_object_headerp)pFRAM); - - if (!iSource) - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - iRetcode = create_obj_general (pData, sizeof (mng_ani_move), - mng_free_obj_general, - mng_process_ani_move, - &((mng_ptr)pMOVE)); - if (iRetcode) - return iRetcode; -#else - MNG_ALLOC (pData, pMOVE, sizeof (mng_ani_move)); - - pMOVE->sHeader.fCleanup = mng_free_ani_move; - pMOVE->sHeader.fProcess = mng_process_ani_move; -#endif - - pMOVE->iFirstid = 1; - pMOVE->iLastid = 1; - pMOVE->iLocax = -iXoffset; - pMOVE->iLocay = -iYoffset; - - mng_add_ani_object (pData, (mng_object_headerp)pMOVE); - } - -#ifdef MNG_OPTIMIZE_OBJCLEANUP - iRetcode = create_obj_general (pData, sizeof (mng_ani_show), - mng_free_obj_general, mng_process_ani_show, - &((mng_ptr)pSHOW)); - if (iRetcode) - return iRetcode; -#else - MNG_ALLOC (pData, pSHOW, sizeof (mng_ani_show)); - - pSHOW->sHeader.fCleanup = mng_free_ani_show; - pSHOW->sHeader.fProcess = mng_process_ani_show; -#endif - - if (iSource) - pSHOW->iFirstid = 0; - else - pSHOW->iFirstid = 1; - pSHOW->iLastid = pSHOW->iFirstid; - - mng_add_ani_object (pData, (mng_object_headerp)pSHOW); - - pTile += sizeof(mng_adat_tile); - } - - if (pANG->iNumplays != 1) /* create a LOOP/ENDL pair ? */ - { -#ifdef MNG_OPTIMIZE_OBJCLEANUP - iRetcode = create_obj_general (pData, sizeof (mng_ani_endl), - mng_free_obj_general, mng_process_ani_endl, - &((mng_ptr)pENDL)); - if (iRetcode) - return iRetcode; -#else - MNG_ALLOC (pData, pENDL, sizeof (mng_ani_endl)); - - pENDL->sHeader.fCleanup = mng_free_ani_endl; - pENDL->sHeader.fProcess = mng_process_ani_endl; -#endif - - pENDL->iLevel = 1; - - mng_add_ani_object (pData, (mng_object_headerp)pENDL); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_ANG_OBJ, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_ANG_PROPOSAL */ - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_DISPLAY_PROCS */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_object_prc.c copyright (c) 2000-2007 G.Juyn * */ +/* * version : 1.0.10 * */ +/* * * */ +/* * purpose : Object processing routines (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the internal object processing routines * */ +/* * * */ +/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - changed trace to macro for callback error-reporting * */ +/* * * */ +/* * 0.5.2 - 05/20/2000 - G.Juyn * */ +/* * - fixed to support JNG objects * */ +/* * 0.5.2 - 05/24/2000 - G.Juyn * */ +/* * - added support for global color-chunks in animation * */ +/* * - added support for global PLTE,tRNS,bKGD in animation * */ +/* * - added SAVE & SEEK animation objects * */ +/* * 0.5.2 - 05/29/2000 - G.Juyn * */ +/* * - added initialization of framenr/layernr/playtime * */ +/* * - changed ani_object create routines not to return the * */ +/* * created object (wasn't necessary) * */ +/* * 0.5.2 - 05/30/2000 - G.Juyn * */ +/* * - added object promotion routine (PROM handling) * */ +/* * - added ani-object routines for delta-image processing * */ +/* * - added compression/filter/interlace fields to * */ +/* * object-buffer for delta-image processing * */ +/* * * */ +/* * 0.5.3 - 06/17/2000 - G.Juyn * */ +/* * - changed support for delta-image processing * */ +/* * 0.5.3 - 06/20/2000 - G.Juyn * */ +/* * - fixed some small things (as precaution) * */ +/* * 0.5.3 - 06/21/2000 - G.Juyn * */ +/* * - added processing of PLTE/tRNS & color-info for * */ +/* * delta-images in the ani_objects chain * */ +/* * 0.5.3 - 06/22/2000 - G.Juyn * */ +/* * - added support for PPLT chunk * */ +/* * * */ +/* * 0.9.1 - 07/07/2000 - G.Juyn * */ +/* * - added support for freeze/restart/resume & go_xxxx * */ +/* * 0.9.1 - 07/16/2000 - G.Juyn * */ +/* * - fixed support for mng_display() after mng_read() * */ +/* * * */ +/* * 0.9.2 - 07/29/2000 - G.Juyn * */ +/* * - fixed small bugs in display processing * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 0.9.3 - 08/07/2000 - G.Juyn * */ +/* * - B111300 - fixup for improved portability * */ +/* * 0.9.3 - 08/26/2000 - G.Juyn * */ +/* * - added MAGN chunk * */ +/* * 0.9.3 - 09/10/2000 - G.Juyn * */ +/* * - fixed DEFI behavior * */ +/* * 0.9.3 - 10/17/2000 - G.Juyn * */ +/* * - added valid-flag to stored objects for read() / display()* */ +/* * - added routine to discard "invalid" objects * */ +/* * 0.9.3 - 10/18/2000 - G.Juyn * */ +/* * - fixed delta-processing behavior * */ +/* * 0.9.3 - 10/19/2000 - G.Juyn * */ +/* * - added storage for pixel-/alpha-sampledepth for delta's * */ +/* * * */ +/* * 0.9.4 - 1/18/2001 - G.Juyn * */ +/* * - removed "old" MAGN methods 3 & 4 * */ +/* * - added "new" MAGN methods 3, 4 & 5 * */ +/* * * */ +/* * 0.9.5 - 1/22/2001 - G.Juyn * */ +/* * - B129681 - fixed compiler warnings SGI/Irix * */ +/* * * */ +/* * 1.0.2 - 06/23/2001 - G.Juyn * */ +/* * - added optimization option for MNG-video playback * */ +/* * * */ +/* * 1.0.5 - 08/15/2002 - G.Juyn * */ +/* * - completed PROM support * */ +/* * 1.0.5 - 08/16/2002 - G.Juyn * */ +/* * - completed MAGN support (16-bit functions) * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * 1.0.5 - 09/13/2002 - G.Juyn * */ +/* * - fixed read/write of MAGN chunk * */ +/* * 1.0.5 - 09/15/2002 - G.Juyn * */ +/* * - added event handling for dynamic MNG * */ +/* * 1.0.5 - 09/20/2002 - G.Juyn * */ +/* * - added support for PAST * */ +/* * 1.0.5 - 09/23/2002 - G.Juyn * */ +/* * - fixed reset_object_detail to clear old buffer * */ +/* * - added in-memory color-correction of abstract images * */ +/* * 1.0.5 - 10/05/2002 - G.Juyn * */ +/* * - fixed problem with cloned objects marked as invalid * */ +/* * - fixed problem cloning frozen object_buffers * */ +/* * 1.0.5 - 10/07/2002 - G.Juyn * */ +/* * - fixed DISC support * */ +/* * 1.0.5 - 11/04/2002 - G.Juyn * */ +/* * - fixed goframe/golayer/gotime processing * */ +/* * 1.0.5 - 11/07/2002 - G.Juyn * */ +/* * - fixed magnification bug with object 0 * */ +/* * 1.0.5 - 01/19/2003 - G.Juyn * */ +/* * - B664911 - fixed buffer overflow during init * */ +/* * * */ +/* * 1.0.6 - 04/19/2003 - G.Juyn * */ +/* * - fixed problem with infinite loops during readdisplay() * */ +/* * 1.0.6 - 05/25/2003 - G.R-P * */ +/* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */ +/* * 1.0.6 - 06/09/2003 - G. R-P * */ +/* * - added conditionals around 8-bit magn routines * */ +/* * 1.0.6 - 07/07/2003 - G.R-P * */ +/* * - added conditionals around some JNG-supporting code * */ +/* * - removed conditionals around 8-bit magn routines * */ +/* * - added conditionals around delta-png and 16-bit code * */ +/* * 1.0.6 - 07/14/2003 - G.R-P * */ +/* * - added MNG_NO_LOOP_SIGNALS_SUPPORTED conditional * */ +/* * 1.0.6 - 07/29/2003 - G.Juyn * */ +/* * - fixed invalid test in promote_imageobject * */ +/* * 1.0.6 - 07/29/2003 - G.R-P. * */ +/* * - added conditionals around PAST chunk support * */ +/* * 1.0.6 - 08/17/2003 - G.R-P. * */ +/* * - added conditionals around MAGN chunk support * */ +/* * * */ +/* * 1.0.7 - 03/21/2004 - G.Juyn * */ +/* * - fixed some 64-bit platform compiler warnings * */ +/* * * */ +/* * 1.0.9 - 10/10/2004 - G.R-P. * */ +/* * - added MNG_NO_1_2_4BIT_SUPPORT support * */ +/* * 1.0.9 - 12/05/2004 - G.Juyn * */ +/* * - added conditional MNG_OPTIMIZE_OBJCLEANUP * */ +/* * 1.0.9 - 12/11/2004 - G.Juyn * */ +/* * - added conditional MNG_OPTIMIZE_DISPLAYCALLS * */ +/* * 1.0.9 - 12/31/2004 - G.R-P. * */ +/* * - fixed warnings about possible uninitialized pointers * */ +/* * 1.0.9 - 01/02/2005 - G.Juyn * */ +/* * - fixing some compiler-warnings * */ +/* * * */ +/* * 1.0.10 - 02/07/2005 - G.Juyn * */ +/* * - fixed some compiler-warnings * */ +/* * 1.0.10 - 07/30/2005 - G.Juyn * */ +/* * - fixed problem with CLON object during readdisplay() * */ +/* * 1.0.10 - 04/08/2007 - G.Juyn * */ +/* * - added support for mPNG proposal * */ +/* * 1.0.10 - 04/12/2007 - G.Juyn * */ +/* * - added support for ANG proposal * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_memory.h" +#include "libmng_chunks.h" +#include "libmng_objects.h" +#include "libmng_display.h" +#include "libmng_pixels.h" +#include "libmng_object_prc.h" +#include "libmng_cms.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_DISPLAY_PROCS + +/* ************************************************************************** */ +/* * * */ +/* * Generic object routines * */ +/* * * */ +/* ************************************************************************** */ + +mng_retcode mng_drop_invalid_objects (mng_datap pData) +{ + mng_objectp pObject; + mng_objectp pNext; + mng_cleanupobject fCleanup; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DROP_INVALID_OBJECTS, MNG_LC_START); +#endif + + pObject = pData->pFirstimgobj; /* get first stored image-object (if any) */ + + while (pObject) /* more objects to check ? */ + { + pNext = ((mng_object_headerp)pObject)->pNext; + /* invalid ? */ + if (!((mng_imagep)pObject)->bValid) + { /* call appropriate cleanup */ + fCleanup = ((mng_object_headerp)pObject)->fCleanup; + fCleanup (pData, pObject); + } + + pObject = pNext; /* neeeext */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DROP_INVALID_OBJECTS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifdef MNG_OPTIMIZE_OBJCLEANUP +MNG_LOCAL mng_retcode create_obj_general (mng_datap pData, + mng_size_t iObjsize, + mng_cleanupobject fCleanup, + mng_processobject fProcess, + mng_ptr *ppObject) +{ + mng_object_headerp pWork; + + MNG_ALLOC (pData, pWork, iObjsize); + + pWork->fCleanup = fCleanup; + pWork->fProcess = fProcess; + pWork->iObjsize = iObjsize; + *ppObject = (mng_ptr)pWork; + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode mng_free_obj_general (mng_datap pData, + mng_objectp pObject) +{ + MNG_FREEX (pData, pObject, ((mng_object_headerp)pObject)->iObjsize); + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ +/* * * */ +/* * Image-data-object routines * */ +/* * * */ +/* * these handle the "object buffer" as defined by the MNG specification * */ +/* * * */ +/* ************************************************************************** */ + +mng_retcode mng_create_imagedataobject (mng_datap pData, + mng_bool bConcrete, + mng_bool bViewable, + mng_uint32 iWidth, + mng_uint32 iHeight, + mng_uint8 iBitdepth, + mng_uint8 iColortype, + mng_uint8 iCompression, + mng_uint8 iFilter, + mng_uint8 iInterlace, + mng_imagedatap *ppObject) +{ + mng_imagedatap pImagedata; + mng_uint32 iSamplesize = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_IMGDATAOBJECT, MNG_LC_START); +#endif + /* get a buffer */ +#ifdef MNG_OPTIMIZE_OBJCLEANUP + { + mng_ptr pTemp; + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_imagedata), + (mng_cleanupobject)mng_free_imagedataobject, + MNG_NULL, &pTemp); + if (iRetcode) + return iRetcode; + pImagedata = (mng_imagedatap)pTemp; + } +#else + MNG_ALLOC (pData, pImagedata, sizeof (mng_imagedata)); + /* fill the appropriate fields */ + pImagedata->sHeader.fCleanup = (mng_cleanupobject)mng_free_imagedataobject; + pImagedata->sHeader.fProcess = MNG_NULL; +#endif + pImagedata->iRefcount = 1; + pImagedata->bFrozen = MNG_FALSE; + pImagedata->bConcrete = bConcrete; + pImagedata->bViewable = bViewable; + pImagedata->iWidth = iWidth; + pImagedata->iHeight = iHeight; + pImagedata->iBitdepth = iBitdepth; + pImagedata->iColortype = iColortype; + pImagedata->iCompression = iCompression; + pImagedata->iFilter = iFilter; + pImagedata->iInterlace = iInterlace; + pImagedata->bCorrected = MNG_FALSE; + pImagedata->iAlphabitdepth = 0; + pImagedata->iJHDRcompression = 0; + pImagedata->iJHDRinterlace = 0; + pImagedata->iPixelsampledepth = iBitdepth; + pImagedata->iAlphasampledepth = iBitdepth; + /* determine samplesize from color_type/bit_depth */ + switch (iColortype) /* for < 8-bit samples we just reserve 8 bits */ + { + case 0 : ; /* gray */ + case 8 : { /* JPEG gray */ +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth > 8) + iSamplesize = 2; + else +#endif + iSamplesize = 1; + + break; + } + case 2 : ; /* rgb */ + case 10 : { /* JPEG rgb */ +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth > 8) + iSamplesize = 6; + else +#endif + iSamplesize = 3; + + break; + } + case 3 : { /* indexed */ + iSamplesize = 1; + break; + } + case 4 : ; /* gray+alpha */ + case 12 : { /* JPEG gray+alpha */ +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth > 8) + iSamplesize = 4; + else +#endif + iSamplesize = 2; + + break; + } + case 6 : ; /* rgb+alpha */ + case 14 : { /* JPEG rgb+alpha */ +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth > 8) + iSamplesize = 8; + else +#endif + iSamplesize = 4; + + break; + } + } + /* make sure we remember all this */ + pImagedata->iSamplesize = iSamplesize; + pImagedata->iRowsize = iSamplesize * iWidth; + pImagedata->iImgdatasize = pImagedata->iRowsize * iHeight; + + if (pImagedata->iImgdatasize) /* need a buffer ? */ + { /* so allocate it */ + MNG_ALLOCX (pData, pImagedata->pImgdata, pImagedata->iImgdatasize); + + if (!pImagedata->pImgdata) /* enough memory ? */ + { + MNG_FREEX (pData, pImagedata, sizeof (mng_imagedata)); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + } + /* check global stuff */ + pImagedata->bHasGAMA = pData->bHasglobalGAMA; +#ifndef MNG_SKIPCHUNK_cHRM + pImagedata->bHasCHRM = pData->bHasglobalCHRM; +#endif + pImagedata->bHasSRGB = pData->bHasglobalSRGB; +#ifndef MNG_SKIPCHUNK_iCCP + pImagedata->bHasICCP = pData->bHasglobalICCP; +#endif +#ifndef MNG_SKIPCHUNK_bKGD + pImagedata->bHasBKGD = pData->bHasglobalBKGD; +#endif + + if (pData->bHasglobalGAMA) /* global gAMA present ? */ + pImagedata->iGamma = pData->iGlobalGamma; + +#ifndef MNG_SKIPCHUNK_cHRM + if (pData->bHasglobalCHRM) /* global cHRM present ? */ + { + pImagedata->iWhitepointx = pData->iGlobalWhitepointx; + pImagedata->iWhitepointy = pData->iGlobalWhitepointy; + pImagedata->iPrimaryredx = pData->iGlobalPrimaryredx; + pImagedata->iPrimaryredy = pData->iGlobalPrimaryredy; + pImagedata->iPrimarygreenx = pData->iGlobalPrimarygreenx; + pImagedata->iPrimarygreeny = pData->iGlobalPrimarygreeny; + pImagedata->iPrimarybluex = pData->iGlobalPrimarybluex; + pImagedata->iPrimarybluey = pData->iGlobalPrimarybluey; + } +#endif + + if (pData->bHasglobalSRGB) /* glbal sRGB present ? */ + pImagedata->iRenderingintent = pData->iGlobalRendintent; + +#ifndef MNG_SKIPCHUNK_iCCP + if (pData->bHasglobalICCP) /* glbal iCCP present ? */ + { + pImagedata->iProfilesize = pData->iGlobalProfilesize; + + if (pImagedata->iProfilesize) + { + MNG_ALLOCX (pData, pImagedata->pProfile, pImagedata->iProfilesize); + + if (!pImagedata->pProfile) /* enough memory ? */ + { + MNG_FREEX (pData, pImagedata->pImgdata, pImagedata->iImgdatasize); + MNG_FREEX (pData, pImagedata, sizeof (mng_imagedata)); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + + MNG_COPY (pImagedata->pProfile, pData->pGlobalProfile, pImagedata->iProfilesize); + } + } +#endif + +#ifndef MNG_SKIPCHUNK_bKGD + if (pData->bHasglobalBKGD) /* global bKGD present ? */ + { + pImagedata->iBKGDred = pData->iGlobalBKGDred; + pImagedata->iBKGDgreen = pData->iGlobalBKGDgreen; + pImagedata->iBKGDblue = pData->iGlobalBKGDblue; + } +#endif + + *ppObject = pImagedata; /* return it */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_IMGDATAOBJECT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_free_imagedataobject (mng_datap pData, + mng_imagedatap pImagedata) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_IMGDATAOBJECT, MNG_LC_START); +#endif + + if (pImagedata->iRefcount) /* decrease reference count */ + pImagedata->iRefcount--; + + if (!pImagedata->iRefcount) /* reached zero ? */ + { +#ifndef MNG_SKIPCHUNK_iCCP + if (pImagedata->iProfilesize) /* stored an iCCP profile ? */ + MNG_FREEX (pData, pImagedata->pProfile, pImagedata->iProfilesize); +#endif + if (pImagedata->iImgdatasize) /* sample-buffer present ? */ + MNG_FREEX (pData, pImagedata->pImgdata, pImagedata->iImgdatasize); + /* drop the buffer */ + MNG_FREEX (pData, pImagedata, sizeof (mng_imagedata)); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_IMGDATAOBJECT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_clone_imagedataobject (mng_datap pData, + mng_bool bConcrete, + mng_imagedatap pSource, + mng_imagedatap *ppClone) +{ + mng_imagedatap pNewdata; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CLONE_IMGDATAOBJECT, MNG_LC_START); +#endif + /* get a buffer */ + MNG_ALLOC (pData, pNewdata, sizeof (mng_imagedata)); + /* blatently copy the original buffer */ + MNG_COPY (pNewdata, pSource, sizeof (mng_imagedata)); + + pNewdata->iRefcount = 1; /* only the reference count */ + pNewdata->bConcrete = bConcrete; /* and concrete-flag are different */ + pNewdata->bFrozen = MNG_FALSE; + + if (pNewdata->iImgdatasize) /* sample buffer present ? */ + { + MNG_ALLOCX (pData, pNewdata->pImgdata, pNewdata->iImgdatasize); + + if (!pNewdata->pImgdata) /* not enough memory ? */ + { + MNG_FREEX (pData, pNewdata, sizeof (mng_imagedata)); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + /* make a copy */ + MNG_COPY (pNewdata->pImgdata, pSource->pImgdata, pNewdata->iImgdatasize); + } + +#ifndef MNG_SKIPCHUNK_iCCP + if (pNewdata->iProfilesize) /* iCCP profile present ? */ + { + MNG_ALLOCX (pData, pNewdata->pProfile, pNewdata->iProfilesize); + + if (!pNewdata->pProfile) /* enough memory ? */ + { + MNG_FREEX (pData, pNewdata, sizeof (mng_imagedata)); + MNG_ERROR (pData, MNG_OUTOFMEMORY); + } + /* make a copy */ + MNG_COPY (pNewdata->pProfile, pSource->pProfile, pNewdata->iProfilesize); + } +#endif + + *ppClone = pNewdata; /* return the clone */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CLONE_IMGDATAOBJECT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ +/* * * */ +/* * Image-object routines * */ +/* * * */ +/* * these handle the "object" as defined by the MNG specification * */ +/* * * */ +/* ************************************************************************** */ + +mng_retcode mng_create_imageobject (mng_datap pData, + mng_uint16 iId, + mng_bool bConcrete, + mng_bool bVisible, + mng_bool bViewable, + mng_uint32 iWidth, + mng_uint32 iHeight, + mng_uint8 iBitdepth, + mng_uint8 iColortype, + mng_uint8 iCompression, + mng_uint8 iFilter, + mng_uint8 iInterlace, + mng_int32 iPosx, + mng_int32 iPosy, + mng_bool bClipped, + mng_int32 iClipl, + mng_int32 iClipr, + mng_int32 iClipt, + mng_int32 iClipb, + mng_imagep *ppObject) +{ + mng_imagep pImage; + mng_imagep pPrev, pNext; + mng_retcode iRetcode; + mng_imagedatap pImgbuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_IMGOBJECT, MNG_LC_START); +#endif + /* get a buffer */ + MNG_ALLOC (pData, pImage, sizeof (mng_image)); + /* now get a new "object buffer" */ + iRetcode = mng_create_imagedataobject (pData, bConcrete, bViewable, + iWidth, iHeight, iBitdepth, iColortype, + iCompression, iFilter, iInterlace, + &pImgbuf); + + if (iRetcode) /* on error bail out */ + { + MNG_FREEX (pData, pImage, sizeof (mng_image)); + return iRetcode; + } + /* fill the appropriate fields */ + pImage->sHeader.fCleanup = (mng_cleanupobject)mng_free_imageobject; + pImage->sHeader.fProcess = MNG_NULL; +#ifdef MNG_OPTIMIZE_OBJCLEANUP + pImage->sHeader.iObjsize = sizeof (mng_image); +#endif + pImage->iId = iId; + pImage->bFrozen = MNG_FALSE; + pImage->bVisible = bVisible; + pImage->bViewable = bViewable; + pImage->bValid = (mng_bool)((pData->bDisplaying) && + ((pData->bRunning) || (pData->bSearching)) && + (!pData->bFreezing)); + pImage->iPosx = iPosx; + pImage->iPosy = iPosy; + pImage->bClipped = bClipped; + pImage->iClipl = iClipl; + pImage->iClipr = iClipr; + pImage->iClipt = iClipt; + pImage->iClipb = iClipb; +#ifndef MNG_SKIPCHUNK_MAGN + pImage->iMAGN_MethodX = 0; + pImage->iMAGN_MethodY = 0; + pImage->iMAGN_MX = 0; + pImage->iMAGN_MY = 0; + pImage->iMAGN_ML = 0; + pImage->iMAGN_MR = 0; + pImage->iMAGN_MT = 0; + pImage->iMAGN_MB = 0; +#endif +#ifndef MNG_SKIPCHUNK_PAST + pImage->iPastx = 0; + pImage->iPasty = 0; +#endif + pImage->pImgbuf = pImgbuf; + + if (iId) /* only if not object 0 ! */ + { /* find previous lower object-id */ + pPrev = (mng_imagep)pData->pLastimgobj; + + while ((pPrev) && (pPrev->iId > iId)) + pPrev = (mng_imagep)pPrev->sHeader.pPrev; + + if (pPrev) /* found it ? */ + { + pImage->sHeader.pPrev = pPrev; /* than link it in place */ + pImage->sHeader.pNext = pPrev->sHeader.pNext; + pPrev->sHeader.pNext = pImage; + } + else /* if not found, it becomes the first ! */ + { + pImage->sHeader.pNext = pData->pFirstimgobj; + pData->pFirstimgobj = pImage; + } + + pNext = (mng_imagep)pImage->sHeader.pNext; + + if (pNext) + pNext->sHeader.pPrev = pImage; + else + pData->pLastimgobj = pImage; + + } + + *ppObject = pImage; /* and return the new buffer */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_IMGOBJECT, MNG_LC_END); +#endif + + return MNG_NOERROR; /* okido */ +} + +/* ************************************************************************** */ + +mng_retcode mng_free_imageobject (mng_datap pData, + mng_imagep pImage) +{ + mng_retcode iRetcode; + mng_imagep pPrev = pImage->sHeader.pPrev; + mng_imagep pNext = pImage->sHeader.pNext; + mng_imagedatap pImgbuf = pImage->pImgbuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_IMGOBJECT, MNG_LC_START); +#endif + + if (pImage->iId) /* not for object 0 */ + { + if (pPrev) /* unlink from the list first ! */ + pPrev->sHeader.pNext = pImage->sHeader.pNext; + else + pData->pFirstimgobj = pImage->sHeader.pNext; + + if (pNext) + pNext->sHeader.pPrev = pImage->sHeader.pPrev; + else + pData->pLastimgobj = pImage->sHeader.pPrev; + + } + /* unlink the image-data buffer */ + iRetcode = mng_free_imagedataobject (pData, pImgbuf); + /* drop its own buffer */ + MNG_FREEX (pData, pImage, sizeof (mng_image)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_IMGOBJECT, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +mng_imagep mng_find_imageobject (mng_datap pData, + mng_uint16 iId) +{ + mng_imagep pImage = (mng_imagep)pData->pFirstimgobj; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (pData, MNG_FN_FIND_IMGOBJECT, MNG_LC_START); +#endif + /* look up the right id */ + while ((pImage) && (pImage->iId != iId)) + pImage = (mng_imagep)pImage->sHeader.pNext; + +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + if ((!pImage) && (pData->eImagetype == mng_it_mpng)) + pImage = pData->pObjzero; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (pData, MNG_FN_FIND_IMGOBJECT, MNG_LC_END); +#endif + + return pImage; +} + +/* ************************************************************************** */ + +mng_retcode mng_clone_imageobject (mng_datap pData, + mng_uint16 iId, + mng_bool bPartial, + mng_bool bVisible, + mng_bool bAbstract, + mng_bool bHasloca, + mng_uint8 iLocationtype, + mng_int32 iLocationx, + mng_int32 iLocationy, + mng_imagep pSource, + mng_imagep *ppClone) +{ + mng_imagep pNew; + mng_imagep pPrev, pNext; + mng_retcode iRetcode; + mng_imagedatap pImgbuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CLONE_IMGOBJECT, MNG_LC_START); +#endif + +#ifndef MNG_SKIPCHUNK_MAGN + if ((pSource->iId) && /* needs magnification ? */ + ((pSource->iMAGN_MethodX) || (pSource->iMAGN_MethodY))) + { + iRetcode = mng_magnify_imageobject (pData, pSource); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif + /* get a buffer */ +#ifdef MNG_OPTIMIZE_OBJCLEANUP + { + mng_ptr pTemp; + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_image), + (mng_cleanupobject)mng_free_imageobject, + MNG_NULL, &pTemp); + if (iRetcode) + return iRetcode; + pNew = (mng_imagep)pTemp; + } +#else + MNG_ALLOC (pData, pNew, sizeof (mng_image)); + /* fill or copy the appropriate fields */ + pNew->sHeader.fCleanup = (mng_cleanupobject)mng_free_imageobject; + pNew->sHeader.fProcess = MNG_NULL; +#endif + pNew->iId = iId; + pNew->bFrozen = MNG_FALSE; + pNew->bVisible = bVisible; + pNew->bViewable = pSource->bViewable; + pNew->bValid = MNG_TRUE; + + if (bHasloca) /* location info available ? */ + { + if (iLocationtype == 0) /* absolute position ? */ + { + pNew->iPosx = iLocationx; + pNew->iPosy = iLocationy; + } + else /* relative */ + { + pNew->iPosx = pSource->iPosx + iLocationx; + pNew->iPosy = pSource->iPosy + iLocationy; + } + } + else /* copy from source */ + { + pNew->iPosx = pSource->iPosx; + pNew->iPosy = pSource->iPosy; + } + /* copy clipping info */ + pNew->bClipped = pSource->bClipped; + pNew->iClipl = pSource->iClipl; + pNew->iClipr = pSource->iClipr; + pNew->iClipt = pSource->iClipt; + pNew->iClipb = pSource->iClipb; +#ifndef MNG_SKIPCHUNK_MAGN + /* copy magnification info */ +/* pNew->iMAGN_MethodX = pSource->iMAGN_MethodX; LET'S NOT !!!!!! + pNew->iMAGN_MethodY = pSource->iMAGN_MethodY; + pNew->iMAGN_MX = pSource->iMAGN_MX; + pNew->iMAGN_MY = pSource->iMAGN_MY; + pNew->iMAGN_ML = pSource->iMAGN_ML; + pNew->iMAGN_MR = pSource->iMAGN_MR; + pNew->iMAGN_MT = pSource->iMAGN_MT; + pNew->iMAGN_MB = pSource->iMAGN_MB; */ +#endif + +#ifndef MNG_SKIPCHUNK_PAST + pNew->iPastx = 0; /* initialize PAST info */ + pNew->iPasty = 0; +#endif + + if (iId) /* not for object 0 */ + { /* find previous lower object-id */ + pPrev = (mng_imagep)pData->pLastimgobj; + while ((pPrev) && (pPrev->iId > iId)) + pPrev = (mng_imagep)pPrev->sHeader.pPrev; + + if (pPrev) /* found it ? */ + { + pNew->sHeader.pPrev = pPrev; /* than link it in place */ + pNew->sHeader.pNext = pPrev->sHeader.pNext; + pPrev->sHeader.pNext = pNew; + } + else /* if not found, it becomes the first ! */ + { + pNew->sHeader.pNext = pData->pFirstimgobj; + pData->pFirstimgobj = pNew; + } + + pNext = (mng_imagep)pNew->sHeader.pNext; + + if (pNext) + pNext->sHeader.pPrev = pNew; + else + pData->pLastimgobj = pNew; + + } + + if (bPartial) /* partial clone ? */ + { + pNew->pImgbuf = pSource->pImgbuf; /* use the same object buffer */ + pNew->pImgbuf->iRefcount++; /* and increase the reference count */ + } + else /* create a full clone ! */ + { + mng_bool bConcrete = MNG_FALSE; /* it's abstract by default (?) */ + + if (!bAbstract) /* determine concreteness from source ? */ + bConcrete = pSource->pImgbuf->bConcrete; + /* create a full clone ! */ + iRetcode = mng_clone_imagedataobject (pData, bConcrete, pSource->pImgbuf, &pImgbuf); + + if (iRetcode) /* on error bail out */ + { + MNG_FREEX (pData, pNew, sizeof (mng_image)); + return iRetcode; + } + + pNew->pImgbuf = pImgbuf; /* and remember it */ + } + + *ppClone = pNew; /* return it */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CLONE_IMGOBJECT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_renum_imageobject (mng_datap pData, + mng_imagep pSource, + mng_uint16 iId, + mng_bool bVisible, + mng_bool bAbstract, + mng_bool bHasloca, + mng_uint8 iLocationtype, + mng_int32 iLocationx, + mng_int32 iLocationy) +{ + mng_imagep pPrev, pNext; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RENUM_IMGOBJECT, MNG_LC_START); +#endif + + pSource->bVisible = bVisible; /* store the new visibility */ + + if (bHasloca) /* location info available ? */ + { + if (iLocationtype == 0) /* absolute position ? */ + { + pSource->iPosx = iLocationx; + pSource->iPosy = iLocationy; + } + else /* relative */ + { + pSource->iPosx = pSource->iPosx + iLocationx; + pSource->iPosy = pSource->iPosy + iLocationy; + } + } + + if (iId) /* not for object 0 */ + { /* find previous lower object-id */ + pPrev = (mng_imagep)pData->pLastimgobj; + while ((pPrev) && (pPrev->iId > iId)) + pPrev = (mng_imagep)pPrev->sHeader.pPrev; + /* different from current ? */ + if (pPrev != (mng_imagep)pSource->sHeader.pPrev) + { + if (pSource->sHeader.pPrev) /* unlink from current position !! */ + ((mng_imagep)pSource->sHeader.pPrev)->sHeader.pNext = pSource->sHeader.pNext; + else + pData->pFirstimgobj = pSource->sHeader.pNext; + + if (pSource->sHeader.pNext) + ((mng_imagep)pSource->sHeader.pNext)->sHeader.pPrev = pSource->sHeader.pPrev; + else + pData->pLastimgobj = pSource->sHeader.pPrev; + + if (pPrev) /* found the previous ? */ + { /* than link it in place */ + pSource->sHeader.pPrev = pPrev; + pSource->sHeader.pNext = pPrev->sHeader.pNext; + pPrev->sHeader.pNext = pSource; + } + else /* if not found, it becomes the first ! */ + { + pSource->sHeader.pNext = pData->pFirstimgobj; + pData->pFirstimgobj = pSource; + } + + pNext = (mng_imagep)pSource->sHeader.pNext; + + if (pNext) + pNext->sHeader.pPrev = pSource; + else + pData->pLastimgobj = pSource; + + } + } + + pSource->iId = iId; /* now set the new id! */ + + if (bAbstract) /* force it to abstract ? */ + pSource->pImgbuf->bConcrete = MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RENUM_IMGOBJECT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_reset_object_details (mng_datap pData, + mng_imagep pImage, + mng_uint32 iWidth, + mng_uint32 iHeight, + mng_uint8 iBitdepth, + mng_uint8 iColortype, + mng_uint8 iCompression, + mng_uint8 iFilter, + mng_uint8 iInterlace, + mng_bool bResetall) +{ + mng_imagedatap pBuf = pImage->pImgbuf; + mng_uint32 iSamplesize = 0; + mng_uint32 iRowsize; + mng_uint32 iImgdatasize; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESET_OBJECTDETAILS, MNG_LC_START); +#endif + + pBuf->iWidth = iWidth; /* set buffer characteristics */ + pBuf->iHeight = iHeight; + pBuf->iBitdepth = iBitdepth; + pBuf->iColortype = iColortype; + pBuf->iCompression = iCompression; + pBuf->iFilter = iFilter; + pBuf->iInterlace = iInterlace; + pBuf->bCorrected = MNG_FALSE; + pBuf->iAlphabitdepth = 0; + /* determine samplesize from color_type/bit_depth */ + switch (iColortype) /* for < 8-bit samples we just reserve 8 bits */ + { + case 0 : ; /* gray */ + case 8 : { /* JPEG gray */ +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth > 8) + iSamplesize = 2; + else +#endif + iSamplesize = 1; + + break; + } + case 2 : ; /* rgb */ + case 10 : { /* JPEG rgb */ +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth > 8) + iSamplesize = 6; + else +#endif + iSamplesize = 3; + + break; + } + case 3 : { /* indexed */ + iSamplesize = 1; + break; + } + case 4 : ; /* gray+alpha */ + case 12 : { /* JPEG gray+alpha */ +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth > 8) + iSamplesize = 4; + else +#endif + iSamplesize = 2; + + break; + } + case 6 : ; /* rgb+alpha */ + case 14 : { /* JPEG rgb+alpha */ +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth > 8) + iSamplesize = 8; + else +#endif + iSamplesize = 4; + + break; + } + } + + iRowsize = iSamplesize * iWidth; + iImgdatasize = iRowsize * iHeight; + /* buffer size changed ? */ + if (iImgdatasize != pBuf->iImgdatasize) + { /* drop the old one */ + MNG_FREE (pData, pBuf->pImgdata, pBuf->iImgdatasize); + + if (iImgdatasize) /* allocate new sample-buffer ? */ + MNG_ALLOC (pData, pBuf->pImgdata, iImgdatasize); + } + else + { + if (iImgdatasize) /* clear old buffer */ + { + mng_uint8p pTemp = pBuf->pImgdata; + mng_uint32 iX; + + for (iX = 0; iX < (iImgdatasize & (mng_uint32)(~3L)); iX += 4) + { + *((mng_uint32p)pTemp) = 0x00000000l; + pTemp += 4; + } + + while (pTemp < (pBuf->pImgdata + iImgdatasize)) + { + *pTemp = 0; + pTemp++; + } + } + } + + pBuf->iSamplesize = iSamplesize; /* remember new sizes */ + pBuf->iRowsize = iRowsize; + pBuf->iImgdatasize = iImgdatasize; + + if (!pBuf->iPixelsampledepth) /* set delta sampledepths if empty */ + pBuf->iPixelsampledepth = iBitdepth; + if (!pBuf->iAlphasampledepth) + pBuf->iAlphasampledepth = iBitdepth; + /* dimension set and clipping not ? */ + if ((iWidth) && (iHeight) && (!pImage->bClipped)) + { + pImage->iClipl = 0; /* set clipping to dimension by default */ + pImage->iClipr = iWidth; + pImage->iClipt = 0; + pImage->iClipb = iHeight; + } + +#ifndef MNG_SKIPCHUNK_MAGN + if (pImage->iId) /* reset magnification info ? */ + { + pImage->iMAGN_MethodX = 0; + pImage->iMAGN_MethodY = 0; + pImage->iMAGN_MX = 0; + pImage->iMAGN_MY = 0; + pImage->iMAGN_ML = 0; + pImage->iMAGN_MR = 0; + pImage->iMAGN_MT = 0; + pImage->iMAGN_MB = 0; + } +#endif + + if (bResetall) /* reset the other characteristics ? */ + { +#ifndef MNG_SKIPCHUNK_PAST + pImage->iPastx = 0; + pImage->iPasty = 0; +#endif + + pBuf->bHasPLTE = MNG_FALSE; + pBuf->bHasTRNS = MNG_FALSE; + pBuf->bHasGAMA = pData->bHasglobalGAMA; +#ifndef MNG_SKIPCHUNK_cHRM + pBuf->bHasCHRM = pData->bHasglobalCHRM; +#endif + pBuf->bHasSRGB = pData->bHasglobalSRGB; +#ifndef MNG_SKIPCHUNK_iCCP + pBuf->bHasICCP = pData->bHasglobalICCP; +#endif +#ifndef MNG_SKIPCHUNK_bKGD + pBuf->bHasBKGD = pData->bHasglobalBKGD; +#endif + +#ifndef MNG_SKIPCHUNK_iCCP + if (pBuf->iProfilesize) /* drop possibly old ICC profile */ + { + MNG_FREE (pData, pBuf->pProfile, pBuf->iProfilesize); + pBuf->iProfilesize = 0; + } +#endif + + if (pData->bHasglobalGAMA) /* global gAMA present ? */ + pBuf->iGamma = pData->iGlobalGamma; + +#ifndef MNG_SKIPCHUNK_cHRM + if (pData->bHasglobalCHRM) /* global cHRM present ? */ + { + pBuf->iWhitepointx = pData->iGlobalWhitepointx; + pBuf->iWhitepointy = pData->iGlobalWhitepointy; + pBuf->iPrimaryredx = pData->iGlobalPrimaryredx; + pBuf->iPrimaryredy = pData->iGlobalPrimaryredy; + pBuf->iPrimarygreenx = pData->iGlobalPrimarygreenx; + pBuf->iPrimarygreeny = pData->iGlobalPrimarygreeny; + pBuf->iPrimarybluex = pData->iGlobalPrimarybluex; + pBuf->iPrimarybluey = pData->iGlobalPrimarybluey; + } +#endif + + if (pData->bHasglobalSRGB) /* global sRGB present ? */ + pBuf->iRenderingintent = pData->iGlobalRendintent; + +#ifndef MNG_SKIPCHUNK_iCCP + if (pData->bHasglobalICCP) /* global iCCP present ? */ + { + if (pData->iGlobalProfilesize) + { + MNG_ALLOC (pData, pBuf->pProfile, pData->iGlobalProfilesize); + MNG_COPY (pBuf->pProfile, pData->pGlobalProfile, pData->iGlobalProfilesize); + } + + pBuf->iProfilesize = pData->iGlobalProfilesize; + } +#endif + +#ifndef MNG_SKIPCHUNK_bKGD + if (pData->bHasglobalBKGD) /* global bKGD present ? */ + { + pBuf->iBKGDred = pData->iGlobalBKGDred; + pBuf->iBKGDgreen = pData->iGlobalBKGDgreen; + pBuf->iBKGDblue = pData->iGlobalBKGDblue; + } +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESET_OBJECTDETAILS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#if !defined(MNG_NO_DELTA_PNG) || !defined(MNG_SKIPCHUNK_PAST) || !defined(MNG_SKIPCHUNK_MAGN) +mng_retcode mng_promote_imageobject (mng_datap pData, + mng_imagep pImage, + mng_uint8 iBitdepth, + mng_uint8 iColortype, + mng_uint8 iFilltype) +{ + mng_retcode iRetcode = MNG_NOERROR; + mng_imagedatap pBuf = pImage->pImgbuf; + mng_uint32 iW = pBuf->iWidth; + mng_uint32 iH = pBuf->iHeight; + mng_uint8p pNewbuf; + mng_uint32 iNewbufsize; + mng_uint32 iNewrowsize; + mng_uint32 iNewsamplesize = pBuf->iSamplesize; + mng_uint32 iY; + mng_uint8 iTempdepth; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_IMGOBJECT, MNG_LC_START); +#endif + +#ifdef MNG_NO_1_2_4BIT_SUPPORT + if (iBitdepth < 8) + iBitdepth=8; + if (pBuf->iBitdepth < 8) + pBuf->iBitdepth=8; +#endif +#ifdef MNG_NO_16BIT_SUPPORT + if (iBitdepth > 8) + iBitdepth=8; + if (pBuf->iBitdepth > 8) + pBuf->iBitdepth=8; +#endif + + pData->fPromoterow = MNG_NULL; /* init promotion fields */ + pData->fPromBitdepth = MNG_NULL; + pData->iPromColortype = iColortype; + pData->iPromBitdepth = iBitdepth; + pData->iPromFilltype = iFilltype; + + if (iBitdepth != pBuf->iBitdepth) /* determine bitdepth promotion */ + { + if (pBuf->iColortype == MNG_COLORTYPE_INDEXED) + iTempdepth = 8; + else + iTempdepth = pBuf->iBitdepth; + +#ifndef MNG_NO_DELTA_PNG + if (iFilltype == MNG_FILLMETHOD_ZEROFILL) + { + switch (iTempdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { + switch (iBitdepth) + { + case 2 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_1_2; break; } + case 4 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_1_4; break; } + case 8 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_1_8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_1_16; break; } +#endif + } + break; + } + case 2 : { + switch (iBitdepth) + { + case 4 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_2_4; break; } + case 8 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_2_8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_2_16; break; } +#endif + } + break; + } + case 4 : { + switch (iBitdepth) + { + case 8 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_4_8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_4_16; break; } +#endif + } + break; + } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromBitdepth = (mng_fptr)mng_promote_zerofill_8_16; +#endif + break; + } + } + } + else +#endif + { + switch (iTempdepth) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case 1 : { + switch (iBitdepth) + { + case 2 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_1_2; break; } + case 4 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_1_4; break; } + case 8 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_1_8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_1_16; break; } +#endif + } + break; + } + case 2 : { + switch (iBitdepth) + { + case 4 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_2_4; break; } + case 8 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_2_8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_2_16; break; } +#endif + } + break; + } + case 4 : { + switch (iBitdepth) + { + case 8 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_4_8; break; } +#ifndef MNG_NO_16BIT_SUPPORT + case 16 : { pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_4_16; break; } +#endif + } + break; + } +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case 8 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromBitdepth = (mng_fptr)mng_promote_replicate_8_16; +#endif + break; + } + } + } + } + /* g -> g */ + if ((pBuf->iColortype == MNG_COLORTYPE_GRAY) && + (iColortype == MNG_COLORTYPE_GRAY)) + { + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_g8_g16; + else +#endif + pData->fPromoterow = (mng_fptr)mng_promote_g8_g8; + } + + iNewsamplesize = 1; + +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 2; +#endif + } + else /* g -> ga */ + if ((pBuf->iColortype == MNG_COLORTYPE_GRAY) && + (iColortype == MNG_COLORTYPE_GRAYA)) + { + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_g8_ga16; + else +#endif + pData->fPromoterow = (mng_fptr)mng_promote_g8_ga8; + } +#ifndef MNG_NO_16BIT_SUPPORT + else /* source = 16 bits */ + pData->fPromoterow = (mng_fptr)mng_promote_g16_ga16; +#endif + + iNewsamplesize = 2; + +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 4; +#endif + } + else /* g -> rgb */ + if ((pBuf->iColortype == MNG_COLORTYPE_GRAY) && + (iColortype == MNG_COLORTYPE_RGB)) + { + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_g8_rgb16; + else +#endif + pData->fPromoterow = (mng_fptr)mng_promote_g8_rgb8; + } +#ifndef MNG_NO_16BIT_SUPPORT + else /* source = 16 bits */ + pData->fPromoterow = (mng_fptr)mng_promote_g16_rgb16; +#endif + + iNewsamplesize = 3; + +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 6; +#endif + } + else /* g -> rgba */ + if ((pBuf->iColortype == MNG_COLORTYPE_GRAY) && + (iColortype == MNG_COLORTYPE_RGBA)) + { + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_g8_rgba16; + else +#endif + pData->fPromoterow = (mng_fptr)mng_promote_g8_rgba8; + } +#ifndef MNG_NO_16BIT_SUPPORT + else /* source = 16 bits */ + pData->fPromoterow = (mng_fptr)mng_promote_g16_rgba16; +#endif + + iNewsamplesize = 4; + +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 8; +#endif + } + else /* ga -> ga */ + if ((pBuf->iColortype == MNG_COLORTYPE_GRAYA) && + (iColortype == MNG_COLORTYPE_GRAYA)) + { + iNewsamplesize = 2; +#ifndef MNG_NO_16BIT_SUPPORT + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_ga8_ga16; + if (iBitdepth == 16) + iNewsamplesize = 4; +#endif + } + else /* ga -> rgba */ + if ((pBuf->iColortype == MNG_COLORTYPE_GRAYA) && + (iColortype == MNG_COLORTYPE_RGBA)) + { + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_ga8_rgba16; + else +#endif + pData->fPromoterow = (mng_fptr)mng_promote_ga8_rgba8; + } +#ifndef MNG_NO_16BIT_SUPPORT + else /* source = 16 bits */ + pData->fPromoterow = (mng_fptr)mng_promote_ga16_rgba16; +#endif + + iNewsamplesize = 4; + +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 8; +#endif + } + else /* rgb -> rgb */ + if ((pBuf->iColortype == MNG_COLORTYPE_RGB) && + (iColortype == MNG_COLORTYPE_RGB)) + { + iNewsamplesize = 3; +#ifndef MNG_NO_16BIT_SUPPORT + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_rgb8_rgb16; + if (iBitdepth == 16) + iNewsamplesize = 6; +#endif + } + else /* rgb -> rgba */ + if ((pBuf->iColortype == MNG_COLORTYPE_RGB) && + (iColortype == MNG_COLORTYPE_RGBA)) + { + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_rgb8_rgba16; + else +#endif + pData->fPromoterow = (mng_fptr)mng_promote_rgb8_rgba8; + } +#ifndef MNG_NO_16BIT_SUPPORT + else /* source = 16 bits */ + pData->fPromoterow = (mng_fptr)mng_promote_rgb16_rgba16; +#endif + + iNewsamplesize = 4; +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 8; +#endif + } + else /* indexed -> rgb */ + if ((pBuf->iColortype == MNG_COLORTYPE_INDEXED) && + (iColortype == MNG_COLORTYPE_RGB)) + { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_idx8_rgb16; + else +#endif + pData->fPromoterow = (mng_fptr)mng_promote_idx8_rgb8; + + iNewsamplesize = 3; + +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 6; +#endif + } + else /* indexed -> rgba */ + if ((pBuf->iColortype == MNG_COLORTYPE_INDEXED) && + (iColortype == MNG_COLORTYPE_RGBA)) + { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_idx8_rgba16; + else +#endif + pData->fPromoterow = (mng_fptr)mng_promote_idx8_rgba8; + + iNewsamplesize = 4; + +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 8; +#endif + } + else /* rgba -> rgba */ + if ((pBuf->iColortype == MNG_COLORTYPE_RGBA) && + (iColortype == MNG_COLORTYPE_RGBA)) + { + iNewsamplesize = 4; +#ifndef MNG_NO_16BIT_SUPPORT + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + { + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_rgba8_rgba16; + } + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 8; +#endif + } +#ifdef MNG_INCLUDE_JNG + else /* JPEG g -> g */ + if ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAY) && + (iColortype == MNG_COLORTYPE_JPEGGRAY)) + { + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_g8_g16; + else +#endif + pData->fPromoterow = (mng_fptr)mng_promote_g8_g8; + } + + iNewsamplesize = 1; + +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 2; +#endif + } + else /* JPEG g -> ga */ + if ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAY) && + (iColortype == MNG_COLORTYPE_JPEGGRAYA)) + { + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_g8_ga16; + else +#endif + pData->fPromoterow = (mng_fptr)mng_promote_g8_ga8; + } +#ifndef MNG_NO_16BIT_SUPPORT + else /* source = 16 bits */ + pData->fPromoterow = (mng_fptr)mng_promote_g16_ga16; +#endif + + iNewsamplesize = 2; + +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 4; +#endif + } + else /* JPEG g -> rgb */ + if ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAY) && + (iColortype == MNG_COLORTYPE_JPEGCOLOR)) + { + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_g8_rgb16; + else +#endif + pData->fPromoterow = (mng_fptr)mng_promote_g8_rgb8; + } +#ifndef MNG_NO_16BIT_SUPPORT + else /* source = 16 bits */ + pData->fPromoterow = (mng_fptr)mng_promote_g16_rgb16; +#endif + + iNewsamplesize = 3; + +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 6; +#endif + } + else /* JPEG g -> rgba */ + if ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAY) && + (iColortype == MNG_COLORTYPE_JPEGCOLORA)) + { + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_g8_rgba16; + else +#endif + pData->fPromoterow = (mng_fptr)mng_promote_g8_rgba8; + } +#ifndef MNG_NO_16BIT_SUPPORT + else /* source = 16 bits */ + pData->fPromoterow = (mng_fptr)mng_promote_g16_rgba16; +#endif + + iNewsamplesize = 4; + +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 8; +#endif + } + else /* JPEG ga -> ga */ + if ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAYA) && + (iColortype == MNG_COLORTYPE_JPEGGRAYA)) + { + iNewsamplesize = 2; +#ifndef MNG_NO_16BIT_SUPPORT + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_ga8_ga16; + if (iBitdepth == 16) + iNewsamplesize = 4; +#endif + + } + else /* JPEG ga -> rgba */ + if ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAYA) && + (iColortype == MNG_COLORTYPE_JPEGCOLORA)) + { + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_ga8_rgba16; + else +#endif + pData->fPromoterow = (mng_fptr)mng_promote_ga8_rgba8; + } +#ifndef MNG_NO_16BIT_SUPPORT + else /* source = 16 bits */ + pData->fPromoterow = (mng_fptr)mng_promote_ga16_rgba16; +#endif + + iNewsamplesize = 4; + +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 8; +#endif + } + else /* JPEG rgb -> rgb */ + if ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLOR) && + (iColortype == MNG_COLORTYPE_JPEGCOLOR)) + { + iNewsamplesize = 3; +#ifndef MNG_NO_16BIT_SUPPORT + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_rgb8_rgb16; + if (iBitdepth == 16) + iNewsamplesize = 6; +#endif + + } + else /* JPEG rgb -> rgba */ + if ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLOR) && + (iColortype == MNG_COLORTYPE_JPEGCOLORA)) + { + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + { +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_rgb8_rgba16; + else +#endif + pData->fPromoterow = (mng_fptr)mng_promote_rgb8_rgba8; + } +#ifndef MNG_NO_16BIT_SUPPORT + else /* source = 16 bits */ + pData->fPromoterow = (mng_fptr)mng_promote_rgb16_rgba16; +#endif + + iNewsamplesize = 4; + +#ifndef MNG_NO_16BIT_SUPPORT + if (iBitdepth == 16) /* 16-bit wide ? */ + iNewsamplesize = 8; +#endif + } + else /* JPEG rgba -> rgba */ + if ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLORA) && + (iColortype == MNG_COLORTYPE_JPEGCOLORA)) + { + iNewsamplesize = 4; +#ifndef MNG_NO_16BIT_SUPPORT + if (pBuf->iBitdepth <= 8) /* source <= 8 bits */ + if (iBitdepth == 16) + pData->fPromoterow = (mng_fptr)mng_promote_rgba8_rgba16; + if (iBitdepth == 16) + iNewsamplesize = 8; +#endif + } +#endif /* JNG */ + + /* found a proper promotion ? */ + if (pData->fPromoterow) + { + pData->pPromBuf = (mng_ptr)pBuf; + pData->iPromWidth = pBuf->iWidth; + iNewrowsize = iW * iNewsamplesize; + iNewbufsize = iH * iNewrowsize; + + MNG_ALLOC (pData, pNewbuf, iNewbufsize); + + pData->pPromSrc = (mng_ptr)pBuf->pImgdata; + pData->pPromDst = (mng_ptr)pNewbuf; + iY = 0; + + while ((!iRetcode) && (iY < iH)) + { + iRetcode = ((mng_promoterow)pData->fPromoterow) (pData); + pData->pPromSrc = (mng_uint8p)pData->pPromSrc + pBuf->iRowsize; + pData->pPromDst = (mng_uint8p)pData->pPromDst + iNewrowsize; +/* pData->pPromSrc = (mng_ptr)((mng_uint32)pData->pPromSrc + pBuf->iRowsize); */ +/* pData->pPromDst = (mng_ptr)((mng_uint32)pData->pPromDst + iNewrowsize); */ + iY++; + } + + MNG_FREEX (pData, pBuf->pImgdata, pBuf->iImgdatasize); + + pBuf->iBitdepth = iBitdepth; + pBuf->iColortype = iColortype; + pBuf->iSamplesize = iNewsamplesize; + pBuf->iRowsize = iNewrowsize; + pBuf->iImgdatasize = iNewbufsize; + pBuf->pImgdata = pNewbuf; + pBuf->bHasPLTE = MNG_FALSE; + pBuf->iPLTEcount = 0; + pBuf->bHasTRNS = MNG_FALSE; + pBuf->iTRNScount = 0; + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_IMGOBJECT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MAGN +mng_retcode mng_magnify_imageobject (mng_datap pData, + mng_imagep pImage) +{ + mng_uint8p pNewdata; + mng_uint8p pSrcline1; + mng_uint8p pSrcline2; + mng_uint8p pTempline; + mng_uint8p pDstline; + mng_uint32 iNewrowsize; + mng_uint32 iNewsize; + mng_uint32 iY; + mng_int32 iS, iM; + mng_retcode iRetcode; + + mng_imagedatap pBuf = pImage->pImgbuf; + mng_uint32 iNewW = pBuf->iWidth; + mng_uint32 iNewH = pBuf->iHeight; + mng_magnify_x fMagnifyX = MNG_NULL; + mng_magnify_y fMagnifyY = MNG_NULL; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_IMGOBJECT, MNG_LC_START); +#endif + + if (pBuf->iColortype == MNG_COLORTYPE_INDEXED) /* indexed color ? */ + { /* concrete buffer ? */ + if ((pBuf->bConcrete) && (pImage->iId)) + MNG_ERROR (pData, MNG_INVALIDCOLORTYPE); + +#ifndef MNG_OPTIMIZE_FOOTPRINT_MAGN + if (pBuf->iTRNScount) /* with transparency ? */ + iRetcode = mng_promote_imageobject (pData, pImage, 8, 6, 0); + else + iRetcode = mng_promote_imageobject (pData, pImage, 8, 2, 0); + + if (iRetcode) /* on error bail out */ + return iRetcode; +#endif + } + +#ifdef MNG_OPTIMIZE_FOOTPRINT_MAGN + /* Promote everything to RGBA, using fill method 0 (LBR) */ + iRetcode = mng_promote_imageobject (pData, pImage, 8, 6, 0); + if (iRetcode) /* on error bail out */ + return iRetcode; +#endif + + if (pImage->iMAGN_MethodX) /* determine new width */ + { + if (pImage->iMAGN_MethodX == 1) + { + iNewW = pImage->iMAGN_ML; + if (pBuf->iWidth > 1) + iNewW = iNewW + pImage->iMAGN_MR; + if (pBuf->iWidth > 2) + iNewW = iNewW + (pBuf->iWidth - 2) * (pImage->iMAGN_MX); + } + else + { + iNewW = pBuf->iWidth + pImage->iMAGN_ML - 1; + if (pBuf->iWidth > 2) + iNewW = iNewW + pImage->iMAGN_MR - 1; + if (pBuf->iWidth > 3) + iNewW = iNewW + (pBuf->iWidth - 3) * (pImage->iMAGN_MX - 1); + } + } + + if (pImage->iMAGN_MethodY) /* determine new height */ + { + if (pImage->iMAGN_MethodY == 1) + { + iNewH = pImage->iMAGN_MT; + if (pBuf->iHeight > 1) + iNewH = iNewH + pImage->iMAGN_ML; + if (pBuf->iHeight > 2) + iNewH = iNewH + (pBuf->iHeight - 2) * (pImage->iMAGN_MY); + } + else + { + iNewH = pBuf->iHeight + pImage->iMAGN_MT - 1; + if (pBuf->iHeight > 2) + iNewH = iNewH + pImage->iMAGN_MB - 1; + if (pBuf->iHeight > 3) + iNewH = iNewH + (pBuf->iHeight - 3) * (pImage->iMAGN_MY - 1); + } + } + /* get new buffer */ + iNewrowsize = iNewW * pBuf->iSamplesize; + iNewsize = iNewH * iNewrowsize; + + MNG_ALLOC (pData, pNewdata, iNewsize); + + switch (pBuf->iColortype) /* determine magnification routines */ + { +#ifndef MNG_OPTIMIZE_FOOTPRINT_MAGN + case 0 : ; + case 8 : { + if (pBuf->iBitdepth <= 8) + { + switch (pImage->iMAGN_MethodX) + { + case 1 : { fMagnifyX = mng_magnify_g8_x1; break; } + case 2 : { fMagnifyX = mng_magnify_g8_x2; break; } + case 3 : { fMagnifyX = mng_magnify_g8_x3; break; } + case 4 : { fMagnifyX = mng_magnify_g8_x2; break; } + case 5 : { fMagnifyX = mng_magnify_g8_x3; break; } + } + + switch (pImage->iMAGN_MethodY) + { + case 1 : { fMagnifyY = mng_magnify_g8_y1; break; } + case 2 : { fMagnifyY = mng_magnify_g8_y2; break; } + case 3 : { fMagnifyY = mng_magnify_g8_y3; break; } + case 4 : { fMagnifyY = mng_magnify_g8_y2; break; } + case 5 : { fMagnifyY = mng_magnify_g8_y3; break; } + } + } +#ifndef MNG_NO_16BIT_SUPPORT + else + { + switch (pImage->iMAGN_MethodX) + { + case 1 : { fMagnifyX = mng_magnify_g16_x1; break; } + case 2 : { fMagnifyX = mng_magnify_g16_x2; break; } + case 3 : { fMagnifyX = mng_magnify_g16_x3; break; } + case 4 : { fMagnifyX = mng_magnify_g16_x2; break; } + case 5 : { fMagnifyX = mng_magnify_g16_x3; break; } + } + + switch (pImage->iMAGN_MethodY) + { + case 1 : { fMagnifyY = mng_magnify_g16_y1; break; } + case 2 : { fMagnifyY = mng_magnify_g16_y2; break; } + case 3 : { fMagnifyY = mng_magnify_g16_y3; break; } + case 4 : { fMagnifyY = mng_magnify_g16_y2; break; } + case 5 : { fMagnifyY = mng_magnify_g16_y3; break; } + } + } +#endif + + break; + } + + case 2 : ; + case 10 : { + if (pBuf->iBitdepth <= 8) + { + switch (pImage->iMAGN_MethodX) + { + case 1 : { fMagnifyX = mng_magnify_rgb8_x1; break; } + case 2 : { fMagnifyX = mng_magnify_rgb8_x2; break; } + case 3 : { fMagnifyX = mng_magnify_rgb8_x3; break; } + case 4 : { fMagnifyX = mng_magnify_rgb8_x2; break; } + case 5 : { fMagnifyX = mng_magnify_rgb8_x3; break; } + } + + switch (pImage->iMAGN_MethodY) + { + case 1 : { fMagnifyY = mng_magnify_rgb8_y1; break; } + case 2 : { fMagnifyY = mng_magnify_rgb8_y2; break; } + case 3 : { fMagnifyY = mng_magnify_rgb8_y3; break; } + case 4 : { fMagnifyY = mng_magnify_rgb8_y2; break; } + case 5 : { fMagnifyY = mng_magnify_rgb8_y3; break; } + } + } +#ifndef MNG_NO_16BIT_SUPPORT + else + { + switch (pImage->iMAGN_MethodX) + { + case 1 : { fMagnifyX = mng_magnify_rgb16_x1; break; } + case 2 : { fMagnifyX = mng_magnify_rgb16_x2; break; } + case 3 : { fMagnifyX = mng_magnify_rgb16_x3; break; } + case 4 : { fMagnifyX = mng_magnify_rgb16_x2; break; } + case 5 : { fMagnifyX = mng_magnify_rgb16_x3; break; } + } + + switch (pImage->iMAGN_MethodY) + { + case 1 : { fMagnifyY = mng_magnify_rgb16_y1; break; } + case 2 : { fMagnifyY = mng_magnify_rgb16_y2; break; } + case 3 : { fMagnifyY = mng_magnify_rgb16_y3; break; } + case 4 : { fMagnifyY = mng_magnify_rgb16_y2; break; } + case 5 : { fMagnifyY = mng_magnify_rgb16_y3; break; } + } + } +#endif + + break; + } + + case 4 : ; + case 12 : { + if (pBuf->iBitdepth <= 8) + { + switch (pImage->iMAGN_MethodX) + { + case 1 : { fMagnifyX = mng_magnify_ga8_x1; break; } + case 2 : { fMagnifyX = mng_magnify_ga8_x2; break; } + case 3 : { fMagnifyX = mng_magnify_ga8_x3; break; } + case 4 : { fMagnifyX = mng_magnify_ga8_x4; break; } + case 5 : { fMagnifyX = mng_magnify_ga8_x5; break; } + } + + switch (pImage->iMAGN_MethodY) + { + case 1 : { fMagnifyY = mng_magnify_ga8_y1; break; } + case 2 : { fMagnifyY = mng_magnify_ga8_y2; break; } + case 3 : { fMagnifyY = mng_magnify_ga8_y3; break; } + case 4 : { fMagnifyY = mng_magnify_ga8_y4; break; } + case 5 : { fMagnifyY = mng_magnify_ga8_y5; break; } + } + } +#ifndef MNG_NO_16BIT_SUPPORT + else + { + switch (pImage->iMAGN_MethodX) + { + case 1 : { fMagnifyX = mng_magnify_ga16_x1; break; } + case 2 : { fMagnifyX = mng_magnify_ga16_x2; break; } + case 3 : { fMagnifyX = mng_magnify_ga16_x3; break; } + case 4 : { fMagnifyX = mng_magnify_ga16_x4; break; } + case 5 : { fMagnifyX = mng_magnify_ga16_x5; break; } + } + + switch (pImage->iMAGN_MethodY) + { + case 1 : { fMagnifyY = mng_magnify_ga16_y1; break; } + case 2 : { fMagnifyY = mng_magnify_ga16_y2; break; } + case 3 : { fMagnifyY = mng_magnify_ga16_y3; break; } + case 4 : { fMagnifyY = mng_magnify_ga16_y4; break; } + case 5 : { fMagnifyY = mng_magnify_ga16_y5; break; } + } + } +#endif + + break; + } +#endif + + case 6 : ; + case 14 : { + if (pBuf->iBitdepth <= 8) + { + switch (pImage->iMAGN_MethodX) + { + case 1 : { fMagnifyX = mng_magnify_rgba8_x1; break; } + case 2 : { fMagnifyX = mng_magnify_rgba8_x2; break; } + case 3 : { fMagnifyX = mng_magnify_rgba8_x3; break; } + case 4 : { fMagnifyX = mng_magnify_rgba8_x4; break; } + case 5 : { fMagnifyX = mng_magnify_rgba8_x5; break; } + } + + switch (pImage->iMAGN_MethodY) + { + case 1 : { fMagnifyY = mng_magnify_rgba8_y1; break; } + case 2 : { fMagnifyY = mng_magnify_rgba8_y2; break; } + case 3 : { fMagnifyY = mng_magnify_rgba8_y3; break; } + case 4 : { fMagnifyY = mng_magnify_rgba8_y4; break; } + case 5 : { fMagnifyY = mng_magnify_rgba8_y5; break; } + } + } +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_MAGN + else + { + switch (pImage->iMAGN_MethodX) + { + case 1 : { fMagnifyX = mng_magnify_rgba16_x1; break; } + case 2 : { fMagnifyX = mng_magnify_rgba16_x2; break; } + case 3 : { fMagnifyX = mng_magnify_rgba16_x3; break; } + case 4 : { fMagnifyX = mng_magnify_rgba16_x4; break; } + case 5 : { fMagnifyX = mng_magnify_rgba16_x5; break; } + } + + switch (pImage->iMAGN_MethodY) + { + case 1 : { fMagnifyY = mng_magnify_rgba16_y1; break; } + case 2 : { fMagnifyY = mng_magnify_rgba16_y2; break; } + case 3 : { fMagnifyY = mng_magnify_rgba16_y3; break; } + case 4 : { fMagnifyY = mng_magnify_rgba16_y4; break; } + case 5 : { fMagnifyY = mng_magnify_rgba16_y5; break; } + } + } +#endif +#endif + break; + } + } + + pSrcline1 = pBuf->pImgdata; /* initialize row-loop variables */ + pDstline = pNewdata; + /* allocate temporary row */ + MNG_ALLOC (pData, pTempline, iNewrowsize); + + for (iY = 0; iY < pBuf->iHeight; iY++) + { + pSrcline2 = pSrcline1 + pBuf->iRowsize; + + if (fMagnifyX) /* magnifying in X-direction ? */ + { + iRetcode = fMagnifyX (pData, pImage->iMAGN_MX, + pImage->iMAGN_ML, pImage->iMAGN_MR, + pBuf->iWidth, pSrcline1, pDstline); + + if (iRetcode) /* on error bail out */ + { + MNG_FREEX (pData, pTempline, iNewrowsize); + MNG_FREEX (pData, pNewdata, iNewsize); + return iRetcode; + } + } + else + { + MNG_COPY (pDstline, pSrcline1, iNewrowsize); + } + + pDstline += iNewrowsize; + /* magnifying in Y-direction ? */ + if ((fMagnifyY) && + ((iY < pBuf->iHeight - 1) || (pBuf->iHeight == 1) || (pImage->iMAGN_MethodY == 1))) + { + if (iY == 0) /* first interval ? */ + { + if (pBuf->iHeight == 1) /* single row ? */ + pSrcline2 = MNG_NULL; + + iM = (mng_int32)pImage->iMAGN_MT; + } + else /* last interval ? */ + if (((pImage->iMAGN_MethodY == 1) && (iY == (pBuf->iHeight - 1))) || + ((pImage->iMAGN_MethodY != 1) && (iY == (pBuf->iHeight - 2))) ) + iM = (mng_int32)pImage->iMAGN_MB; + else /* middle interval */ + iM = (mng_int32)pImage->iMAGN_MY; + + for (iS = 1; iS < iM; iS++) + { + iRetcode = fMagnifyY (pData, iS, iM, pBuf->iWidth, + pSrcline1, pSrcline2, pTempline); + + if (iRetcode) /* on error bail out */ + { + MNG_FREEX (pData, pTempline, iNewrowsize); + MNG_FREEX (pData, pNewdata, iNewsize); + return iRetcode; + } + + if (fMagnifyX) /* magnifying in X-direction ? */ + { + iRetcode = fMagnifyX (pData, pImage->iMAGN_MX, + pImage->iMAGN_ML, pImage->iMAGN_MR, + pBuf->iWidth, pTempline, pDstline); + + if (iRetcode) /* on error bail out */ + { + MNG_FREEX (pData, pTempline, iNewrowsize); + MNG_FREEX (pData, pNewdata, iNewsize); + return iRetcode; + } + } + else + { + MNG_COPY (pDstline, pTempline, iNewrowsize); + } + + pDstline += iNewrowsize; + } + } + + pSrcline1 += pBuf->iRowsize; + } + /* drop temporary row */ + MNG_FREEX (pData, pTempline, iNewrowsize); + /* drop old pixel-data */ + MNG_FREEX (pData, pBuf->pImgdata, pBuf->iImgdatasize); + + pBuf->pImgdata = pNewdata; /* save new buffer dimensions */ + pBuf->iRowsize = iNewrowsize; + pBuf->iImgdatasize = iNewsize; + pBuf->iWidth = iNewW; + pBuf->iHeight = iNewH; + + if (pImage->iId) /* real object ? */ + { + pImage->iMAGN_MethodX = 0; /* it's done; don't do it again !!! */ + pImage->iMAGN_MethodY = 0; + pImage->iMAGN_MX = 0; + pImage->iMAGN_MY = 0; + pImage->iMAGN_ML = 0; + pImage->iMAGN_MR = 0; + pImage->iMAGN_MT = 0; + pImage->iMAGN_MB = 0; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_IMGOBJECT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_colorcorrect_object (mng_datap pData, + mng_imagep pImage) +{ + mng_imagedatap pBuf = pImage->pImgbuf; + mng_retcode iRetcode; + mng_uint32 iY; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_COLORCORRECT_OBJECT, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_JNG + if ((pBuf->iBitdepth < 8) || /* we need 8- or 16-bit RGBA !!! */ + ((pBuf->iColortype != MNG_COLORTYPE_RGBA ) && + (pBuf->iColortype != MNG_COLORTYPE_JPEGCOLORA) )) +#else + if (pBuf->iBitdepth < 8) /* we need 8- or 16-bit RGBA !!! */ +#endif + MNG_ERROR (pData, MNG_OBJNOTABSTRACT); + + if (!pBuf->bCorrected) /* only if not already done ! */ + { /* so the row routines now to find it */ + pData->pRetrieveobj = (mng_objectp)pImage; + pData->pStoreobj = (mng_objectp)pImage; + pData->pStorebuf = (mng_objectp)pImage->pImgbuf; + +#ifndef MNG_NO_16BIT_SUPPORT + if (pBuf->iBitdepth > 8) + { + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16; + pData->fStorerow = (mng_fptr)mng_store_rgba16; + } + else +#endif + { + pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8; + pData->fStorerow = (mng_fptr)mng_store_rgba8; + } + + pData->bIsOpaque = MNG_FALSE; + + pData->iPass = -1; /* these are the object's dimensions now */ + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pBuf->iWidth; + pData->iRowsize = pData->iRowsamples << 2; + pData->iPixelofs = 0; + pData->bIsRGBA16 = MNG_FALSE; + /* adjust for 16-bit object ? */ +#ifndef MNG_NO_16BIT_SUPPORT + if (pBuf->iBitdepth > 8) + { + pData->bIsRGBA16 = MNG_TRUE; + pData->iRowsize = pData->iRowsamples << 3; + } +#endif + + pData->fCorrectrow = MNG_NULL; /* default no color-correction */ + +#ifdef MNG_NO_CMS + iRetcode = MNG_NOERROR; +#else +#if defined(MNG_FULL_CMS) /* determine color-management routine */ + iRetcode = mng_init_full_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); +#elif defined(MNG_GAMMA_ONLY) + iRetcode = mng_init_gamma_only (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); +#elif defined(MNG_APP_CMS) + iRetcode = mng_init_app_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE); +#endif + if (iRetcode) /* on error bail out */ + return iRetcode; +#endif /* MNG_NO_CMS */ + + if (pData->fCorrectrow) /* really correct something ? */ + { /* get a temporary row-buffer */ + MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize); + + pData->pWorkrow = pData->pRGBArow; + iY = 0; /* start from the top */ + + while ((!iRetcode) && (iY < pBuf->iHeight)) + { /* get a row */ + iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData); + + if (!iRetcode) /* color correct it */ + iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData); + + if (!iRetcode) /* store it back ! */ + iRetcode = ((mng_storerow)pData->fStorerow) (pData); + + if (!iRetcode) /* adjust variables for next row */ + iRetcode = mng_next_row (pData); + + iY++; /* and next line */ + } + /* drop the temporary row-buffer */ + MNG_FREEX (pData, pData->pRGBArow, pData->iRowsize); + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#if defined(MNG_FULL_CMS) /* cleanup cms stuff */ + iRetcode = mng_clear_cms (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; +#endif + } + + pBuf->bCorrected = MNG_TRUE; /* let's not go through that again ! */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_COLORCORRECT_OBJECT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ +/* * * */ +/* * Animation-object routines * */ +/* * * */ +/* * these handle the animation objects used to re-run parts of a MNG. * */ +/* * eg. during LOOP or TERM processing * */ +/* * * */ +/* ************************************************************************** */ + +void mng_add_ani_object (mng_datap pData, + mng_object_headerp pObject) +{ + mng_object_headerp pLast = (mng_object_headerp)pData->pLastaniobj; + + if (pLast) /* link it as last in the chain */ + { + pObject->pPrev = pLast; + pLast->pNext = pObject; + } + else + { + pObject->pPrev = MNG_NULL; /* be on the safe side */ + pData->pFirstaniobj = pObject; + } + + pObject->pNext = MNG_NULL; /* be on the safe side */ + pData->pLastaniobj = pObject; + /* keep track for jumping */ + pObject->iFramenr = pData->iFrameseq; + pObject->iLayernr = pData->iLayerseq; + pObject->iPlaytime = pData->iFrametime; + /* save restart object ? */ + if ((pData->bDisplaying) && (!pData->bRunning) && (!pData->pCurraniobj)) + pData->pCurraniobj = pObject; + + return; +} + +/* ************************************************************************** */ +/* ************************************************************************** */ + +mng_retcode mng_create_ani_image (mng_datap pData) +{ + mng_ani_imagep pImage; + mng_imagep pCurrent; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_IMAGE, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* processing delta-image ? */ + pCurrent = (mng_imagep)pData->pObjzero; + else /* get the current object */ +#endif + pCurrent = (mng_imagep)pData->pCurrentobj; + + if (!pCurrent) /* otherwise object 0 */ + pCurrent = (mng_imagep)pData->pObjzero; + /* now just clone the object !!! */ + iRetcode = mng_clone_imageobject (pData, 0, MNG_FALSE, pCurrent->bVisible, + MNG_FALSE, MNG_FALSE, 0, 0, 0, pCurrent, + &pImage); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + pImage->sHeader.fCleanup = mng_free_ani_image; + pImage->sHeader.fProcess = mng_process_ani_image; + + mng_add_ani_object (pData, (mng_object_headerp)pImage); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_IMAGE, MNG_LC_END); +#endif + + return MNG_NOERROR; /* okido */ +} + +/* ************************************************************************** */ + +mng_retcode mng_free_ani_image (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_imagep pImage = (mng_ani_imagep)pObject; + mng_imagedatap pImgbuf = pImage->pImgbuf; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_IMAGE, MNG_LC_START); +#endif + /* unlink the image-data buffer */ + iRetcode = mng_free_imagedataobject (pData, pImgbuf); + /* drop its own buffer */ + MNG_FREEX (pData, pImage, sizeof (mng_ani_image)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_IMAGE, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_image (mng_datap pData, + mng_objectp pObject) +{ + mng_retcode iRetcode = MNG_NOERROR; + mng_ani_imagep pImage = (mng_imagep)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_IMAGE, MNG_LC_START); +#endif + +#ifndef MNG_NO_DELTA_PNG + if (pData->bHasDHDR) /* processing delta-image ? */ + { + mng_imagep pDelta = (mng_imagep)pData->pDeltaImage; + + if (!pData->iBreakpoint) /* only execute if not broken before */ + { /* make sure to process pixels as well */ + pData->bDeltaimmediate = MNG_FALSE; + /* execute the delta process */ + iRetcode = mng_execute_delta_image (pData, pDelta, (mng_imagep)pObject); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + /* now go and shoot it off (if required) */ + if ((pDelta->bVisible) && (pDelta->bViewable)) + iRetcode = mng_display_image (pData, pDelta, MNG_FALSE); + + if (!pData->bTimerset) + pData->bHasDHDR = MNG_FALSE; /* this image signifies IEND !! */ + + } + else +#endif + if (pData->pCurrentobj) /* active object ? */ + { + mng_imagep pCurrent = (mng_imagep)pData->pCurrentobj; + mng_imagedatap pBuf = pCurrent->pImgbuf; + + if (!pData->iBreakpoint) /* don't copy it again ! */ + { + if (pBuf->iImgdatasize) /* buffer present in active object ? */ + /* then drop it */ + MNG_FREE (pData, pBuf->pImgdata, pBuf->iImgdatasize); + +#ifndef MNG_SKIPCHUNK_iCCP + if (pBuf->iProfilesize) /* iCCP profile present ? */ + /* then drop it */ + MNG_FREE (pData, pBuf->pProfile, pBuf->iProfilesize); +#endif + /* now blatently copy the animation buffer */ + MNG_COPY (pBuf, pImage->pImgbuf, sizeof (mng_imagedata)); + /* copy viewability */ + pCurrent->bViewable = pImage->bViewable; + + if (pBuf->iImgdatasize) /* sample buffer present ? */ + { /* then make a copy */ + MNG_ALLOC (pData, pBuf->pImgdata, pBuf->iImgdatasize); + MNG_COPY (pBuf->pImgdata, pImage->pImgbuf->pImgdata, pBuf->iImgdatasize); + } + +#ifndef MNG_SKIPCHUNK_iCCP + if (pBuf->iProfilesize) /* iCCP profile present ? */ + { /* then make a copy */ + MNG_ALLOC (pData, pBuf->pProfile, pBuf->iProfilesize); + MNG_COPY (pBuf->pProfile, pImage->pImgbuf->pProfile, pBuf->iProfilesize); + } +#endif + } + /* now go and shoot it off (if required) */ + if ((pCurrent->bVisible) && (pCurrent->bViewable)) + iRetcode = mng_display_image (pData, pCurrent, MNG_FALSE); + } + else + { + mng_imagep pObjzero = (mng_imagep)pData->pObjzero; + mng_imagedatap pBuf = pObjzero->pImgbuf; + + if (!pData->iBreakpoint) /* don't copy it again ! */ + { + if (pBuf->iImgdatasize) /* buffer present in active object ? */ + /* then drop it */ + MNG_FREE (pData, pBuf->pImgdata, pBuf->iImgdatasize); + +#ifndef MNG_SKIPCHUNK_iCCP + if (pBuf->iProfilesize) /* iCCP profile present ? */ + /* then drop it */ + MNG_FREE (pData, pBuf->pProfile, pBuf->iProfilesize); +#endif + /* now blatently copy the animation buffer */ + MNG_COPY (pBuf, pImage->pImgbuf, sizeof (mng_imagedata)); + /* copy viewability */ + pObjzero->bViewable = pImage->bViewable; + + if (pBuf->iImgdatasize) /* sample buffer present ? */ + { /* then make a copy */ + MNG_ALLOC (pData, pBuf->pImgdata, pBuf->iImgdatasize); + MNG_COPY (pBuf->pImgdata, pImage->pImgbuf->pImgdata, pBuf->iImgdatasize); + } + +#ifndef MNG_SKIPCHUNK_iCCP + if (pBuf->iProfilesize) /* iCCP profile present ? */ + { /* then make a copy */ + MNG_ALLOC (pData, pBuf->pProfile, pBuf->iProfilesize); + MNG_COPY (pBuf->pProfile, pImage->pImgbuf->pProfile, pBuf->iProfilesize); + } +#endif + } + /* now go and show it */ + iRetcode = mng_display_image (pData, pObjzero, MNG_FALSE); + } + + if (!iRetcode) /* all's well ? */ + { + if (pData->bTimerset) /* timer break ? */ + pData->iBreakpoint = 99; /* fictive number; no more processing needed! */ + else + pData->iBreakpoint = 0; /* else clear it */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_IMAGE, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_plte (mng_datap pData, + mng_uint32 iEntrycount, + mng_palette8ep paEntries) +#else +mng_retcode mng_create_ani_plte (mng_datap pData) +#endif +{ + mng_ani_pltep pPLTE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_PLTE, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_plte), + mng_free_obj_general, + mng_process_ani_plte, + &pTemp); + if (iRetcode) + return iRetcode; + pPLTE = (mng_ani_pltep)pTemp; +#else + MNG_ALLOC (pData, pPLTE, sizeof (mng_ani_plte)); + + pPLTE->sHeader.fCleanup = mng_free_ani_plte; + pPLTE->sHeader.fProcess = mng_process_ani_plte; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pPLTE); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pPLTE->iEntrycount = iEntrycount; + MNG_COPY (pPLTE->aEntries, paEntries, sizeof (pPLTE->aEntries)); +#else + pPLTE->iEntrycount = pData->iGlobalPLTEcount; + MNG_COPY (pPLTE->aEntries, pData->aGlobalPLTEentries, sizeof (pPLTE->aEntries)); +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_PLTE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_plte (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_PLTE, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_plte)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_PLTE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_plte (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_pltep pPLTE = (mng_ani_pltep)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PLTE, MNG_LC_START); +#endif + + pData->bHasglobalPLTE = MNG_TRUE; + pData->iGlobalPLTEcount = pPLTE->iEntrycount; + + MNG_COPY (pData->aGlobalPLTEentries, pPLTE->aEntries, sizeof (pPLTE->aEntries)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PLTE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_trns (mng_datap pData, + mng_uint32 iRawlen, + mng_uint8p pRawdata) +#else +mng_retcode mng_create_ani_trns (mng_datap pData) +#endif +{ + mng_ani_trnsp pTRNS; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_TRNS, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_trns), + mng_free_obj_general, + mng_process_ani_trns, + &pTemp); + if (iRetcode) + return iRetcode; + pTRNS = (mng_ani_trnsp)pTemp; +#else + MNG_ALLOC (pData, pTRNS, sizeof (mng_ani_trns)); + + pTRNS->sHeader.fCleanup = mng_free_ani_trns; + pTRNS->sHeader.fProcess = mng_process_ani_trns; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pTRNS); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pTRNS->iRawlen = iRawlen; + MNG_COPY (pTRNS->aRawdata, pRawdata, sizeof (pTRNS->aRawdata)); +#else + pTRNS->iRawlen = pData->iGlobalTRNSrawlen; + MNG_COPY (pTRNS->aRawdata, pData->aGlobalTRNSrawdata, sizeof (pTRNS->aRawdata)); +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_TRNS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_trns (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_TRNS, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_trns)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_TRNS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_trns (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_trnsp pTRNS = (mng_ani_trnsp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_TRNS, MNG_LC_START); +#endif + + pData->bHasglobalTRNS = MNG_TRUE; + pData->iGlobalTRNSrawlen = pTRNS->iRawlen; + + MNG_COPY (pData->aGlobalTRNSrawdata, pTRNS->aRawdata, sizeof (pTRNS->aRawdata)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_TRNS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_gAMA +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_gama (mng_datap pData, + mng_bool bEmpty, + mng_uint32 iGamma) +#else +mng_retcode mng_create_ani_gama (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ani_gamap pGAMA; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_GAMA, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_gama), + mng_free_obj_general, + mng_process_ani_gama, + &pTemp); + if (iRetcode) + return iRetcode; + pGAMA = (mng_ani_gamap)pTemp; +#else + MNG_ALLOC (pData, pGAMA, sizeof (mng_ani_gama)); + + pGAMA->sHeader.fCleanup = mng_free_ani_gama; + pGAMA->sHeader.fProcess = mng_process_ani_gama; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pGAMA); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pGAMA->bEmpty = bEmpty; + pGAMA->iGamma = iGamma; +#else + pGAMA->bEmpty = ((mng_gamap)pChunk)->bEmpty; + pGAMA->iGamma = ((mng_gamap)pChunk)->iGamma; +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_GAMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_gama (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_GAMA, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_gama)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_GAMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_gama (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_gamap pGAMA = (mng_ani_gamap)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_GAMA, MNG_LC_START); +#endif + + if (pGAMA->bEmpty) /* empty chunk ? */ + { /* clear global gAMA */ + pData->bHasglobalGAMA = MNG_FALSE; + pData->iGlobalGamma = 0; + } + else + { /* set global gAMA */ + pData->bHasglobalGAMA = MNG_TRUE; + pData->iGlobalGamma = pGAMA->iGamma; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_GAMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_cHRM +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_chrm (mng_datap pData, + mng_bool bEmpty, + mng_uint32 iWhitepointx, + mng_uint32 iWhitepointy, + mng_uint32 iRedx, + mng_uint32 iRedy, + mng_uint32 iGreenx, + mng_uint32 iGreeny, + mng_uint32 iBluex, + mng_uint32 iBluey) +#else +mng_retcode mng_create_ani_chrm (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ptr pTemp; + mng_ani_chrmp pCHRM; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_CHRM, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_chrm), + mng_free_obj_general, + mng_process_ani_chrm, + &pTemp); + if (iRetcode) + return iRetcode; + pCHRM = (mng_ani_chrmp)pTemp; +#else + MNG_ALLOC (pData, pCHRM, sizeof (mng_ani_chrm)); + + pCHRM->sHeader.fCleanup = mng_free_ani_chrm; + pCHRM->sHeader.fProcess = mng_process_ani_chrm; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pCHRM); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pCHRM->bEmpty = bEmpty; + pCHRM->iWhitepointx = iWhitepointx; + pCHRM->iWhitepointy = iWhitepointy; + pCHRM->iRedx = iRedx; + pCHRM->iRedy = iRedy; + pCHRM->iGreenx = iGreenx; + pCHRM->iGreeny = iGreeny; + pCHRM->iBluex = iBluex; + pCHRM->iBluey = iBluey; +#else + pCHRM->bEmpty = ((mng_chrmp)pChunk)->bEmpty; + pCHRM->iWhitepointx = ((mng_chrmp)pChunk)->iWhitepointx; + pCHRM->iWhitepointy = ((mng_chrmp)pChunk)->iWhitepointy; + pCHRM->iRedx = ((mng_chrmp)pChunk)->iRedx; + pCHRM->iRedy = ((mng_chrmp)pChunk)->iRedy; + pCHRM->iGreenx = ((mng_chrmp)pChunk)->iGreenx; + pCHRM->iGreeny = ((mng_chrmp)pChunk)->iGreeny; + pCHRM->iBluex = ((mng_chrmp)pChunk)->iBluex; + pCHRM->iBluey = ((mng_chrmp)pChunk)->iBluey; +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_CHRM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_chrm (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_CHRM, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_chrm)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_CHRM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_chrm (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_chrmp pCHRM = (mng_ani_chrmp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_CHRM, MNG_LC_START); +#endif + + if (pCHRM->bEmpty) /* empty chunk ? */ + { /* clear global cHRM */ + pData->bHasglobalCHRM = MNG_FALSE; + pData->iGlobalWhitepointx = 0; + pData->iGlobalWhitepointy = 0; + pData->iGlobalPrimaryredx = 0; + pData->iGlobalPrimaryredy = 0; + pData->iGlobalPrimarygreenx = 0; + pData->iGlobalPrimarygreeny = 0; + pData->iGlobalPrimarybluex = 0; + pData->iGlobalPrimarybluey = 0; + } + else + { /* set global cHRM */ + pData->bHasglobalCHRM = MNG_TRUE; + pData->iGlobalWhitepointx = pCHRM->iWhitepointx; + pData->iGlobalWhitepointy = pCHRM->iWhitepointy; + pData->iGlobalPrimaryredx = pCHRM->iRedx; + pData->iGlobalPrimaryredy = pCHRM->iRedy; + pData->iGlobalPrimarygreenx = pCHRM->iGreenx; + pData->iGlobalPrimarygreeny = pCHRM->iGreeny; + pData->iGlobalPrimarybluex = pCHRM->iBluex; + pData->iGlobalPrimarybluey = pCHRM->iBluey; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_CHRM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_sRGB +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_srgb (mng_datap pData, + mng_bool bEmpty, + mng_uint8 iRenderingintent) +#else +mng_retcode mng_create_ani_srgb (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ani_srgbp pSRGB; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_SRGB, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_srgb), + mng_free_obj_general, + mng_process_ani_srgb, + &pTemp); + if (iRetcode) + return iRetcode; + pSRGB = (mng_ani_srgbp)pTemp; +#else + MNG_ALLOC (pData, pSRGB, sizeof (mng_ani_srgb)); + + pSRGB->sHeader.fCleanup = mng_free_ani_srgb; + pSRGB->sHeader.fProcess = mng_process_ani_srgb; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pSRGB); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pSRGB->bEmpty = bEmpty; + pSRGB->iRenderingintent = iRenderingintent; +#else + pSRGB->bEmpty = ((mng_srgbp)pChunk)->bEmpty; + pSRGB->iRenderingintent = ((mng_srgbp)pChunk)->iRenderingintent; +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_SRGB, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_srgb (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_SRGB, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_srgb)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_SRGB, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_srgb (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_srgbp pSRGB = (mng_ani_srgbp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SRGB, MNG_LC_START); +#endif + + if (pSRGB->bEmpty) /* empty chunk ? */ + { /* clear global sRGB */ + pData->bHasglobalSRGB = MNG_FALSE; + pData->iGlobalRendintent = 0; + } + else + { /* set global sRGB */ + pData->bHasglobalSRGB = MNG_TRUE; + pData->iGlobalRendintent = pSRGB->iRenderingintent; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SRGB, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_iCCP +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_iccp (mng_datap pData, + mng_bool bEmpty, + mng_uint32 iProfilesize, + mng_ptr pProfile) +#else +mng_retcode mng_create_ani_iccp (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ptr pTemp; + mng_ani_iccpp pICCP; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_ICCP, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_iccp), + mng_free_ani_iccp, + mng_process_ani_iccp, + &pTemp); + if (iRetcode) + return iRetcode; + pICCP = (mng_ani_iccpp)pTemp; +#else + MNG_ALLOC (pData, pICCP, sizeof (mng_ani_iccp)); + + pICCP->sHeader.fCleanup = mng_free_ani_iccp; + pICCP->sHeader.fProcess = mng_process_ani_iccp; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pICCP); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pICCP->bEmpty = bEmpty; + pICCP->iProfilesize = iProfilesize; + + if (iProfilesize) + { + MNG_ALLOC (pData, pICCP->pProfile, iProfilesize); + MNG_COPY (pICCP->pProfile, pProfile, iProfilesize); + } +#else + pICCP->bEmpty = ((mng_iccpp)pChunk)->bEmpty; + pICCP->iProfilesize = ((mng_iccpp)pChunk)->iProfilesize; + + if (pICCP->iProfilesize) + { + MNG_ALLOC (pData, pICCP->pProfile, pICCP->iProfilesize); + MNG_COPY (pICCP->pProfile, ((mng_iccpp)pChunk)->pProfile, pICCP->iProfilesize); + } +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_ICCP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_free_ani_iccp (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_iccpp pICCP = (mng_ani_iccpp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_ICCP, MNG_LC_START); +#endif + + if (pICCP->iProfilesize) + MNG_FREEX (pData, pICCP->pProfile, pICCP->iProfilesize); + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + MNG_FREEX (pData, pObject, sizeof (mng_ani_iccp)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_ICCP, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + return MNG_NOERROR; +#else + return mng_free_obj_general(pData, pObject); +#endif +} + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_iccp (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_iccpp pICCP = (mng_ani_iccpp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_ICCP, MNG_LC_START); +#endif + + if (pICCP->bEmpty) /* empty chunk ? */ + { /* clear global iCCP */ + pData->bHasglobalICCP = MNG_FALSE; + + if (pData->iGlobalProfilesize) + MNG_FREEX (pData, pData->pGlobalProfile, pData->iGlobalProfilesize); + + pData->iGlobalProfilesize = 0; + pData->pGlobalProfile = MNG_NULL; + } + else + { /* set global iCCP */ + pData->bHasglobalICCP = MNG_TRUE; + pData->iGlobalProfilesize = pICCP->iProfilesize; + + if (pICCP->iProfilesize) + { + MNG_ALLOC (pData, pData->pGlobalProfile, pICCP->iProfilesize); + MNG_COPY (pData->pGlobalProfile, pICCP->pProfile, pICCP->iProfilesize); + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_ICCP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_bKGD +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_bkgd (mng_datap pData, + mng_uint16 iRed, + mng_uint16 iGreen, + mng_uint16 iBlue) +#else +mng_retcode mng_create_ani_bkgd (mng_datap pData) +#endif +{ + mng_ptr pTemp; + mng_ani_bkgdp pBKGD; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_BKGD, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_bkgd), + mng_free_obj_general, + mng_process_ani_bkgd, + &pTemp); + if (iRetcode) + return iRetcode; + pBKGD = (mng_ani_bkgdp)pTemp; +#else + MNG_ALLOC (pData, pBKGD, sizeof (mng_ani_bkgd)); + + pBKGD->sHeader.fCleanup = mng_free_ani_bkgd; + pBKGD->sHeader.fProcess = mng_process_ani_bkgd; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pBKGD); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pBKGD->iRed = iRed; + pBKGD->iGreen = iGreen; + pBKGD->iBlue = iBlue; +#else + pBKGD->iRed = pData->iGlobalBKGDred; + pBKGD->iGreen = pData->iGlobalBKGDgreen; + pBKGD->iBlue = pData->iGlobalBKGDblue; +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_BKGD, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_bkgd (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_BKGD, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_bkgd)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_BKGD, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_bkgd (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_bkgdp pBKGD = (mng_ani_bkgdp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_BKGD, MNG_LC_START); +#endif + + pData->bHasglobalBKGD = MNG_TRUE; + pData->iGlobalBKGDred = pBKGD->iRed; + pData->iGlobalBKGDgreen = pBKGD->iGreen; + pData->iGlobalBKGDblue = pBKGD->iBlue; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_BKGD, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_LOOP +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_loop (mng_datap pData, + mng_uint8 iLevel, + mng_uint32 iRepeatcount, + mng_uint8 iTermcond, + mng_uint32 iItermin, + mng_uint32 iItermax, + mng_uint32 iCount, + mng_uint32p pSignals) +#else +mng_retcode mng_create_ani_loop (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ani_loopp pLOOP; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_LOOP, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_loop), + mng_free_ani_loop, + mng_process_ani_loop, + &pTemp); + if (iRetcode) + return iRetcode; + pLOOP = (mng_ani_loopp)pTemp; +#else + MNG_ALLOC (pData, pLOOP, sizeof (mng_ani_loop)); + + pLOOP->sHeader.fCleanup = mng_free_ani_loop; + pLOOP->sHeader.fProcess = mng_process_ani_loop; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pLOOP); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pLOOP->iLevel = iLevel; + pLOOP->iRepeatcount = iRepeatcount; + pLOOP->iTermcond = iTermcond; + pLOOP->iItermin = iItermin; + pLOOP->iItermax = iItermax; + pLOOP->iCount = iCount; + +#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED + if (iCount) + { + MNG_ALLOC (pData, pLOOP->pSignals, (iCount << 1)); + MNG_COPY (pLOOP->pSignals, pSignals, (iCount << 1)); + } +#endif +#else /* MNG_OPTIMIZE_CHUNKREADER */ + pLOOP->iLevel = ((mng_loopp)pChunk)->iLevel; + pLOOP->iRepeatcount = ((mng_loopp)pChunk)->iRepeat; + pLOOP->iTermcond = ((mng_loopp)pChunk)->iTermination; + pLOOP->iItermin = ((mng_loopp)pChunk)->iItermin; + pLOOP->iItermax = ((mng_loopp)pChunk)->iItermax; + pLOOP->iCount = ((mng_loopp)pChunk)->iCount; + +#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED + if (pLOOP->iCount) + { + MNG_ALLOC (pData, pLOOP->pSignals, (pLOOP->iCount << 1)); + MNG_COPY (pLOOP->pSignals, ((mng_loopp)pChunk)->pSignals, (pLOOP->iCount << 1)); + } +#endif +#endif /* MNG_OPTIMIZE_CHUNKREADER */ + /* running counter starts with repeat_count */ + pLOOP->iRunningcount = pLOOP->iRepeatcount; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_LOOP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_free_ani_loop (mng_datap pData, + mng_objectp pObject) +{ +#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED + mng_ani_loopp pLOOP = (mng_ani_loopp)pObject; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_LOOP, MNG_LC_START); +#endif + +#ifndef MNG_NO_LOOP_SIGNALS_SUPPORTED + if (pLOOP->iCount) /* drop signal buffer ? */ + MNG_FREEX (pData, pLOOP->pSignals, (pLOOP->iCount << 1)); +#endif + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + MNG_FREEX (pData, pObject, sizeof (mng_ani_loop)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_LOOP, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + return MNG_NOERROR; +#else + return mng_free_obj_general(pData, pObject); +#endif +} + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_loop (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_loopp pLOOP = (mng_ani_loopp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_LOOP, MNG_LC_START); +#endif + /* just reset the running counter */ + pLOOP->iRunningcount = pLOOP->iRepeatcount; + /* iteration=0 means we're skipping ! */ + if ((!pData->bSkipping) && (pLOOP->iRepeatcount == 0)) + pData->bSkipping = MNG_TRUE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_LOOP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ +/* ************************************************************************** */ + +mng_retcode mng_create_ani_endl (mng_datap pData, + mng_uint8 iLevel) +{ + mng_ani_endlp pENDL; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_ENDL, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { + mng_retcode iRetcode; +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + iRetcode = create_obj_general (pData, sizeof (mng_ani_endl), + mng_free_obj_general, + mng_process_ani_endl, + &pTemp); + if (iRetcode) + return iRetcode; + pENDL = (mng_ani_endlp)pTemp; +#else + MNG_ALLOC (pData, pENDL, sizeof (mng_ani_endl)); + + pENDL->sHeader.fCleanup = mng_free_ani_endl; + pENDL->sHeader.fProcess = mng_process_ani_endl; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pENDL); + + pENDL->iLevel = iLevel; + + iRetcode = mng_process_ani_endl (pData, (mng_objectp)pENDL); + if (iRetcode) + return iRetcode; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_ENDL, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_endl (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_ENDL, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_endl)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_ENDL, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_endl (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_endlp pENDL = (mng_ani_endlp)pObject; + mng_ani_loopp pLOOP; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_ENDL, MNG_LC_START); +#endif + + if (((pData->bDisplaying) && ((pData->bRunning) || (pData->bSearching))) || + (pData->bReading) ) + { + pLOOP = pENDL->pLOOP; /* determine matching LOOP */ + + if (!pLOOP) /* haven't got it yet ? */ + { /* go and look back in the list */ + pLOOP = (mng_ani_loopp)pENDL->sHeader.pPrev; + + while ((pLOOP) && + ((pLOOP->sHeader.fCleanup != mng_free_ani_loop) || + (pLOOP->iLevel != pENDL->iLevel) )) + pLOOP = pLOOP->sHeader.pPrev; + } + /* got it now ? */ + if ((pLOOP) && (pLOOP->iLevel == pENDL->iLevel)) + { + pENDL->pLOOP = pLOOP; /* save for next time ! */ + /* decrease running counter ? */ + if ((pLOOP->iRunningcount) && (pLOOP->iRunningcount < 0x7fffffffL)) + pLOOP->iRunningcount--; + + if ((!pData->bDisplaying) && (pData->bReading) && + (pLOOP->iRunningcount >= 0x7fffffffL)) + { + pData->iTotalframes = 0x7fffffffL; + pData->iTotallayers = 0x7fffffffL; + pData->iTotalplaytime = 0x7fffffffL; + } + else + { + /* TODO: we're cheating out on the termination_condition, + iteration_min, iteration_max and possible signals; + the code is just not ready for that can of worms.... */ + + if (!pLOOP->iRunningcount) /* reached zero ? */ + { /* was this the outer LOOP ? */ + if (pData->pFirstaniobj == (mng_objectp)pLOOP) /* TODO: THIS IS WRONG!! */ + pData->bHasLOOP = MNG_FALSE; + } + else + { + if (pData->pCurraniobj) /* was we processing objects ? */ + pData->pCurraniobj = pLOOP;/* then restart with LOOP */ + else /* else restart behind LOOP !!! */ + pData->pCurraniobj = pLOOP->sHeader.pNext; + } + } + /* does this match a 'skipping' LOOP? */ + if ((pData->bSkipping) && (pLOOP->iRepeatcount == 0)) + pData->bSkipping = MNG_FALSE; + } + else + MNG_ERROR (pData, MNG_NOMATCHINGLOOP); + + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_ENDL, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DEFI +mng_retcode mng_create_ani_defi (mng_datap pData) +{ + mng_ani_defip pDEFI; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_DEFI, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_defi), + mng_free_obj_general, + mng_process_ani_defi, + &pTemp); + if (iRetcode) + return iRetcode; + pDEFI = (mng_ani_defip)pTemp; +#else + MNG_ALLOC (pData, pDEFI, sizeof (mng_ani_defi)); + + pDEFI->sHeader.fCleanup = mng_free_ani_defi; + pDEFI->sHeader.fProcess = mng_process_ani_defi; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pDEFI); + + pDEFI->iId = pData->iDEFIobjectid; + pDEFI->bHasdonotshow = pData->bDEFIhasdonotshow; + pDEFI->iDonotshow = pData->iDEFIdonotshow; + pDEFI->bHasconcrete = pData->bDEFIhasconcrete; + pDEFI->iConcrete = pData->iDEFIconcrete; + pDEFI->bHasloca = pData->bDEFIhasloca; + pDEFI->iLocax = pData->iDEFIlocax; + pDEFI->iLocay = pData->iDEFIlocay; + pDEFI->bHasclip = pData->bDEFIhasclip; + pDEFI->iClipl = pData->iDEFIclipl; + pDEFI->iClipr = pData->iDEFIclipr; + pDEFI->iClipt = pData->iDEFIclipt; + pDEFI->iClipb = pData->iDEFIclipb; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_DEFI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_defi (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_DEFI, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_defi)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_DEFI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_defi (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_defip pDEFI = (mng_ani_defip)pObject; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_DEFI, MNG_LC_START); +#endif + + pData->iDEFIobjectid = pDEFI->iId; + pData->bDEFIhasdonotshow = pDEFI->bHasdonotshow; + pData->iDEFIdonotshow = pDEFI->iDonotshow; + pData->bDEFIhasconcrete = pDEFI->bHasconcrete; + pData->iDEFIconcrete = pDEFI->iConcrete; + pData->bDEFIhasloca = pDEFI->bHasloca; + pData->iDEFIlocax = pDEFI->iLocax; + pData->iDEFIlocay = pDEFI->iLocay; + pData->bDEFIhasclip = pDEFI->bHasclip; + pData->iDEFIclipl = pDEFI->iClipl; + pData->iDEFIclipr = pDEFI->iClipr; + pData->iDEFIclipt = pDEFI->iClipt; + pData->iDEFIclipb = pDEFI->iClipb; + + iRetcode = mng_process_display_defi (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_DEFI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_BASI +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_basi (mng_datap pData, + mng_uint16 iRed, + mng_uint16 iGreen, + mng_uint16 iBlue, + mng_bool bHasalpha, + mng_uint16 iAlpha, + mng_uint8 iViewable) +#else +mng_retcode mng_create_ani_basi (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ani_basip pBASI; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_BASI, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + iRetcode = create_obj_general (pData, sizeof (mng_ani_basi), + mng_free_obj_general, + mng_process_ani_basi, + &pTemp); + if (iRetcode) + return iRetcode; + pBASI = (mng_ani_basip)pTemp; +#else + MNG_ALLOC (pData, pBASI, sizeof (mng_ani_basi)); + + pBASI->sHeader.fCleanup = mng_free_ani_basi; + pBASI->sHeader.fProcess = mng_process_ani_basi; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pBASI); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pBASI->iRed = iRed; + pBASI->iGreen = iGreen; + pBASI->iBlue = iBlue; + pBASI->bHasalpha = bHasalpha; + pBASI->iAlpha = iAlpha; + pBASI->iViewable = iViewable; +#else + pBASI->iRed = ((mng_basip)pChunk)->iRed; + pBASI->iGreen = ((mng_basip)pChunk)->iGreen; + pBASI->iBlue = ((mng_basip)pChunk)->iBlue; + pBASI->bHasalpha = ((mng_basip)pChunk)->bHasalpha; + pBASI->iAlpha = ((mng_basip)pChunk)->iAlpha; + pBASI->iViewable = ((mng_basip)pChunk)->iViewable; +#endif + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +#ifndef MNG_OPTIMIZE_CHUNKREADER + iRetcode = mng_process_display_basi (pData, iRed, iGreen, iBlue, + bHasalpha, iAlpha, iViewable); +#else + iRetcode = mng_process_display_basi (pData, + ((mng_basip)pChunk)->iRed, + ((mng_basip)pChunk)->iGreen, + ((mng_basip)pChunk)->iBlue, + ((mng_basip)pChunk)->bHasalpha, + ((mng_basip)pChunk)->iAlpha, + ((mng_basip)pChunk)->iViewable); +#endif +#else +#ifndef MNG_OPTIMIZE_CHUNKREADER + pData->iBASIred = iRed; + pData->iBASIgreen = iGreen; + pData->iBASIblue = iBlue; + pData->bBASIhasalpha = bHasalpha; + pData->iBASIalpha = iAlpha; + pData->iBASIviewable = iViewable; +#else + pData->iBASIred = ((mng_basip)pChunk)->iRed; + pData->iBASIgreen = ((mng_basip)pChunk)->iGreen; + pData->iBASIblue = ((mng_basip)pChunk)->iBlue; + pData->bBASIhasalpha = ((mng_basip)pChunk)->bHasalpha; + pData->iBASIalpha = ((mng_basip)pChunk)->iAlpha; + pData->iBASIviewable = ((mng_basip)pChunk)->iViewable; +#endif + + iRetcode = mng_process_display_basi (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_BASI, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_basi (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_BASI, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_basi)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_BASI, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_basi (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_basip pBASI = (mng_ani_basip)pObject; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_BASI, MNG_LC_START); +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mng_process_display_basi (pData, pBASI->iRed, pBASI->iGreen, pBASI->iBlue, + pBASI->bHasalpha, pBASI->iAlpha, pBASI->iViewable); +#else + pData->iBASIred = pBASI->iRed; + pData->iBASIgreen = pBASI->iGreen; + pData->iBASIblue = pBASI->iBlue; + pData->bBASIhasalpha = pBASI->bHasalpha; + pData->iBASIalpha = pBASI->iAlpha; + pData->iBASIviewable = pBASI->iViewable; + + iRetcode = mng_process_display_basi (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_BASI, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_CLON +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_clon (mng_datap pData, + mng_uint16 iSourceid, + mng_uint16 iCloneid, + mng_uint8 iClonetype, + mng_bool bHasdonotshow, + mng_uint8 iDonotshow, + mng_uint8 iConcrete, + mng_bool bHasloca, + mng_uint8 iLocatype, + mng_int32 iLocax, + mng_int32 iLocay) +#else +mng_retcode mng_create_ani_clon (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ani_clonp pCLON; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_CLON, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + iRetcode = create_obj_general (pData, sizeof (mng_ani_clon), + mng_free_obj_general, + mng_process_ani_clon, + &pTemp); + if (iRetcode) + return iRetcode; + pCLON = (mng_ani_clonp)pTemp; +#else + MNG_ALLOC (pData, pCLON, sizeof (mng_ani_clon)); + + pCLON->sHeader.fCleanup = mng_free_ani_clon; + pCLON->sHeader.fProcess = mng_process_ani_clon; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pCLON); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pCLON->iSourceid = iSourceid; + pCLON->iCloneid = iCloneid; + pCLON->iClonetype = iClonetype; + pCLON->bHasdonotshow = bHasdonotshow; + pCLON->iDonotshow = iDonotshow; + pCLON->iConcrete = iConcrete; + pCLON->bHasloca = bHasloca; + pCLON->iLocatype = iLocatype; + pCLON->iLocax = iLocax; + pCLON->iLocay = iLocay; +#else + pCLON->iSourceid = ((mng_clonp)pChunk)->iSourceid; + pCLON->iCloneid = ((mng_clonp)pChunk)->iCloneid; + pCLON->iClonetype = ((mng_clonp)pChunk)->iClonetype; + pCLON->bHasdonotshow = ((mng_clonp)pChunk)->bHasdonotshow; + pCLON->iDonotshow = ((mng_clonp)pChunk)->iDonotshow; + pCLON->iConcrete = ((mng_clonp)pChunk)->iConcrete; + pCLON->bHasloca = ((mng_clonp)pChunk)->bHasloca; + pCLON->iLocatype = ((mng_clonp)pChunk)->iLocationtype; + pCLON->iLocax = ((mng_clonp)pChunk)->iLocationx; + pCLON->iLocay = ((mng_clonp)pChunk)->iLocationy; +#endif + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +#ifndef MNG_OPTIMIZE_CHUNKREADER + iRetcode = mng_process_display_clon (pData, iSourceid, iCloneid, iClonetype, + bHasdonotshow, iDonotshow, iConcrete, + bHasloca, iLocatype, iLocax, iLocay); +#else + iRetcode = mng_process_display_clon (pData, + ((mng_clonp)pChunk)->iSourceid, + ((mng_clonp)pChunk)->iCloneid, + ((mng_clonp)pChunk)->iClonetype, + ((mng_clonp)pChunk)->bHasdonotshow, + ((mng_clonp)pChunk)->iDonotshow, + ((mng_clonp)pChunk)->iConcrete, + ((mng_clonp)pChunk)->bHasloca, + ((mng_clonp)pChunk)->iLocationtype, + ((mng_clonp)pChunk)->iLocationx, + ((mng_clonp)pChunk)->iLocationy); +#endif +#else +#ifndef MNG_OPTIMIZE_CHUNKREADER + pData->iCLONsourceid = iSourceid; + pData->iCLONcloneid = iCloneid; + pData->iCLONclonetype = iClonetype; + pData->bCLONhasdonotshow = bHasdonotshow; + pData->iCLONdonotshow = iDonotshow; + pData->iCLONconcrete = iConcrete; + pData->bCLONhasloca = bHasloca; + pData->iCLONlocationtype = iLocatype; + pData->iCLONlocationx = iLocax; + pData->iCLONlocationy = iLocay; +#else + pData->iCLONsourceid = ((mng_clonp)pChunk)->iSourceid; + pData->iCLONcloneid = ((mng_clonp)pChunk)->iCloneid; + pData->iCLONclonetype = ((mng_clonp)pChunk)->iClonetype; + pData->bCLONhasdonotshow = ((mng_clonp)pChunk)->bHasdonotshow; + pData->iCLONdonotshow = ((mng_clonp)pChunk)->iDonotshow; + pData->iCLONconcrete = ((mng_clonp)pChunk)->iConcrete; + pData->bCLONhasloca = ((mng_clonp)pChunk)->bHasloca; + pData->iCLONlocationtype = ((mng_clonp)pChunk)->iLocationtype; + pData->iCLONlocationx = ((mng_clonp)pChunk)->iLocationx; + pData->iCLONlocationy = ((mng_clonp)pChunk)->iLocationy; +#endif + + iRetcode = mng_process_display_clon (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_CLON, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_clon (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_CLON, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_clon)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_CLON, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_clon (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_clonp pCLON = (mng_ani_clonp)pObject; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_CLON, MNG_LC_START); +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mng_process_display_clon (pData, pCLON->iSourceid, pCLON->iCloneid, + pCLON->iClonetype, pCLON->bHasdonotshow, + pCLON->iDonotshow, pCLON->iConcrete, + pCLON->bHasloca, pCLON->iLocatype, + pCLON->iLocax, pCLON->iLocay); +#else + pData->iCLONcloneid = pCLON->iCloneid; + pData->iCLONsourceid = pCLON->iSourceid; + pData->iCLONclonetype = pCLON->iClonetype; + pData->bCLONhasdonotshow = pCLON->bHasdonotshow; + pData->iCLONdonotshow = pCLON->iDonotshow; + pData->iCLONconcrete = pCLON->iConcrete; + pData->bCLONhasloca = pCLON->bHasloca; + pData->iCLONlocationtype = pCLON->iLocatype; + pData->iCLONlocationx = pCLON->iLocax; + pData->iCLONlocationy = pCLON->iLocay; + + iRetcode = mng_process_display_clon (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_CLON, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_BACK +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_back (mng_datap pData, + mng_uint16 iRed, + mng_uint16 iGreen, + mng_uint16 iBlue, + mng_uint8 iMandatory, + mng_uint16 iImageid, + mng_uint8 iTile) +#else +mng_retcode mng_create_ani_back (mng_datap pData) +#endif +{ + mng_ani_backp pBACK; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_BACK, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_back), + mng_free_obj_general, + mng_process_ani_back, + &pTemp); + if (iRetcode) + return iRetcode; + pBACK = (mng_ani_backp)pTemp; +#else + MNG_ALLOC (pData, pBACK, sizeof (mng_ani_back)); + + pBACK->sHeader.fCleanup = mng_free_ani_back; + pBACK->sHeader.fProcess = mng_process_ani_back; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pBACK); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pBACK->iRed = iRed; + pBACK->iGreen = iGreen; + pBACK->iBlue = iBlue; + pBACK->iMandatory = iMandatory; + pBACK->iImageid = iImageid; + pBACK->iTile = iTile; +#else + pBACK->iRed = pData->iBACKred; + pBACK->iGreen = pData->iBACKgreen; + pBACK->iBlue = pData->iBACKblue; + pBACK->iMandatory = pData->iBACKmandatory; + pBACK->iImageid = pData->iBACKimageid; + pBACK->iTile = pData->iBACKtile; +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_BACK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_back (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_BACK, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_back)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_BACK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_back (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_backp pBACK = (mng_ani_backp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_BACK, MNG_LC_START); +#endif + + pData->iBACKred = pBACK->iRed; + pData->iBACKgreen = pBACK->iGreen; + pData->iBACKblue = pBACK->iBlue; + pData->iBACKmandatory = pBACK->iMandatory; + pData->iBACKimageid = pBACK->iImageid; + pData->iBACKtile = pBACK->iTile; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_BACK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_FRAM +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_fram (mng_datap pData, + mng_uint8 iFramemode, + mng_uint8 iChangedelay, + mng_uint32 iDelay, + mng_uint8 iChangetimeout, + mng_uint32 iTimeout, + mng_uint8 iChangeclipping, + mng_uint8 iCliptype, + mng_int32 iClipl, + mng_int32 iClipr, + mng_int32 iClipt, + mng_int32 iClipb) +#else +mng_retcode mng_create_ani_fram (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ani_framp pFRAM; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_FRAM, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + iRetcode = create_obj_general (pData, sizeof (mng_ani_fram), + mng_free_obj_general, + mng_process_ani_fram, + &pTemp); + if (iRetcode) + return iRetcode; + pFRAM = (mng_ani_framp)pTemp; +#else + MNG_ALLOC (pData, pFRAM, sizeof (mng_ani_fram)); + + pFRAM->sHeader.fCleanup = mng_free_ani_fram; + pFRAM->sHeader.fProcess = mng_process_ani_fram; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pFRAM); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pFRAM->iFramemode = iFramemode; + pFRAM->iChangedelay = iChangedelay; + pFRAM->iDelay = iDelay; + pFRAM->iChangetimeout = iChangetimeout; + pFRAM->iTimeout = iTimeout; + pFRAM->iChangeclipping = iChangeclipping; + pFRAM->iCliptype = iCliptype; + pFRAM->iClipl = iClipl; + pFRAM->iClipr = iClipr; + pFRAM->iClipt = iClipt; + pFRAM->iClipb = iClipb; +#else + pFRAM->iFramemode = ((mng_framp)pChunk)->iMode; + pFRAM->iChangedelay = ((mng_framp)pChunk)->iChangedelay; + pFRAM->iDelay = ((mng_framp)pChunk)->iDelay; + pFRAM->iChangetimeout = ((mng_framp)pChunk)->iChangetimeout; + pFRAM->iTimeout = ((mng_framp)pChunk)->iTimeout; + pFRAM->iChangeclipping = ((mng_framp)pChunk)->iChangeclipping; + pFRAM->iCliptype = ((mng_framp)pChunk)->iBoundarytype; + pFRAM->iClipl = ((mng_framp)pChunk)->iBoundaryl; + pFRAM->iClipr = ((mng_framp)pChunk)->iBoundaryr; + pFRAM->iClipt = ((mng_framp)pChunk)->iBoundaryt; + pFRAM->iClipb = ((mng_framp)pChunk)->iBoundaryb; +#endif + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +#ifndef MNG_OPTIMIZE_CHUNKREADER + iRetcode = mng_process_display_fram (pData, iFramemode, + iChangedelay, iDelay, + iChangetimeout, iTimeout, + iChangeclipping, iCliptype, + iClipl, iClipr, + iClipt, iClipb); +#else + iRetcode = mng_process_display_fram (pData, + ((mng_framp)pChunk)->iMode, + ((mng_framp)pChunk)->iChangedelay, + ((mng_framp)pChunk)->iDelay, + ((mng_framp)pChunk)->iChangetimeout, + ((mng_framp)pChunk)->iTimeout, + ((mng_framp)pChunk)->iChangeclipping, + ((mng_framp)pChunk)->iBoundarytype, + ((mng_framp)pChunk)->iBoundaryl, + ((mng_framp)pChunk)->iBoundaryr, + ((mng_framp)pChunk)->iBoundaryt, + ((mng_framp)pChunk)->iBoundaryb); +#endif +#else +#ifndef MNG_OPTIMIZE_CHUNKREADER + pData->iTempFramemode = iFramemode; + pData->iTempChangedelay = iChangedelay; + pData->iTempDelay = iDelay; + pData->iTempChangetimeout = iChangetimeout; + pData->iTempTimeout = iTimeout; + pData->iTempChangeclipping = iChangeclipping; + pData->iTempCliptype = iCliptype; + pData->iTempClipl = iClipl; + pData->iTempClipr = iClipr; + pData->iTempClipt = iClipt; + pData->iTempClipb = iClipb; +#else + pData->iTempFramemode = ((mng_framp)pChunk)->iMode; + pData->iTempChangedelay = ((mng_framp)pChunk)->iChangedelay; + pData->iTempDelay = ((mng_framp)pChunk)->iDelay; + pData->iTempChangetimeout = ((mng_framp)pChunk)->iChangetimeout; + pData->iTempTimeout = ((mng_framp)pChunk)->iTimeout; + pData->iTempChangeclipping = ((mng_framp)pChunk)->iChangeclipping; + pData->iTempCliptype = ((mng_framp)pChunk)->iBoundarytype; + pData->iTempClipl = ((mng_framp)pChunk)->iBoundaryl; + pData->iTempClipr = ((mng_framp)pChunk)->iBoundaryr; + pData->iTempClipt = ((mng_framp)pChunk)->iBoundaryt; + pData->iTempClipb = ((mng_framp)pChunk)->iBoundaryb; +#endif + + iRetcode = mng_process_display_fram (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_FRAM, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_fram (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_FRAM, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_fram)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_FRAM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_fram (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_framp pFRAM = (mng_ani_framp)pObject; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_FRAM, MNG_LC_START); +#endif + + if (pData->iBreakpoint) /* previously broken ? */ + { + iRetcode = mng_process_display_fram2 (pData); + pData->iBreakpoint = 0; /* not again */ + } + else + { +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mng_process_display_fram (pData, pFRAM->iFramemode, + pFRAM->iChangedelay, pFRAM->iDelay, + pFRAM->iChangetimeout, pFRAM->iTimeout, + pFRAM->iChangeclipping, pFRAM->iCliptype, + pFRAM->iClipl, pFRAM->iClipr, + pFRAM->iClipt, pFRAM->iClipb); +#else + pData->iTempFramemode = pFRAM->iFramemode; + pData->iTempChangedelay = pFRAM->iChangedelay; + pData->iTempDelay = pFRAM->iDelay; + pData->iTempChangetimeout = pFRAM->iChangetimeout; + pData->iTempTimeout = pFRAM->iTimeout; + pData->iTempChangeclipping = pFRAM->iChangeclipping; + pData->iTempCliptype = pFRAM->iCliptype; + pData->iTempClipl = pFRAM->iClipl; + pData->iTempClipr = pFRAM->iClipr; + pData->iTempClipt = pFRAM->iClipt; + pData->iTempClipb = pFRAM->iClipb; + + iRetcode = mng_process_display_fram (pData); +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_FRAM, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MOVE +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_move (mng_datap pData, + mng_uint16 iFirstid, + mng_uint16 iLastid, + mng_uint8 iType, + mng_int32 iLocax, + mng_int32 iLocay) +#else +mng_retcode mng_create_ani_move (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ani_movep pMOVE; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_MOVE, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + iRetcode = create_obj_general (pData, sizeof (mng_ani_move), + mng_free_obj_general, + mng_process_ani_move, + &pTemp); + if (iRetcode) + return iRetcode; + pMOVE = (mng_ani_movep)pTemp; +#else + MNG_ALLOC (pData, pMOVE, sizeof (mng_ani_move)); + + pMOVE->sHeader.fCleanup = mng_free_ani_move; + pMOVE->sHeader.fProcess = mng_process_ani_move; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pMOVE); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pMOVE->iFirstid = iFirstid; + pMOVE->iLastid = iLastid; + pMOVE->iType = iType; + pMOVE->iLocax = iLocax; + pMOVE->iLocay = iLocay; +#else + pMOVE->iFirstid = ((mng_movep)pChunk)->iFirstid; + pMOVE->iLastid = ((mng_movep)pChunk)->iLastid; + pMOVE->iType = ((mng_movep)pChunk)->iMovetype; + pMOVE->iLocax = ((mng_movep)pChunk)->iMovex; + pMOVE->iLocay = ((mng_movep)pChunk)->iMovey; +#endif + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +#ifndef MNG_OPTIMIZE_CHUNKREADER + iRetcode = mng_process_display_move (pData, iFirstid, iLastid, + iType, iLocax, iLocay); +#else + iRetcode = mng_process_display_move (pData, + ((mng_movep)pChunk)->iFirstid, + ((mng_movep)pChunk)->iLastid, + ((mng_movep)pChunk)->iMovetype, + ((mng_movep)pChunk)->iMovex, + ((mng_movep)pChunk)->iMovey); +#endif +#else +#ifndef MNG_OPTIMIZE_CHUNKREADER + pData->iMOVEfromid = iFirstid; + pData->iMOVEtoid = iLastid; + pData->iMOVEmovetype = iType; + pData->iMOVEmovex = iLocax; + pData->iMOVEmovey = iLocay; +#else + pData->iMOVEfromid = ((mng_movep)pChunk)->iFirstid; + pData->iMOVEtoid = ((mng_movep)pChunk)->iLastid; + pData->iMOVEmovetype = ((mng_movep)pChunk)->iMovetype; + pData->iMOVEmovex = ((mng_movep)pChunk)->iMovex; + pData->iMOVEmovey = ((mng_movep)pChunk)->iMovey; +#endif + + iRetcode = mng_process_display_move (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_MOVE, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_move (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_MOVE, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_move)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_MOVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_move (mng_datap pData, + mng_objectp pObject) +{ + mng_retcode iRetcode; + mng_ani_movep pMOVE = (mng_ani_movep)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_MOVE, MNG_LC_START); +#endif + /* re-process the MOVE chunk */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mng_process_display_move (pData, pMOVE->iFirstid, pMOVE->iLastid, + pMOVE->iType, pMOVE->iLocax, pMOVE->iLocay); +#else + pData->iMOVEfromid = pMOVE->iFirstid; + pData->iMOVEtoid = pMOVE->iLastid; + pData->iMOVEmovetype = pMOVE->iType; + pData->iMOVEmovex = pMOVE->iLocax; + pData->iMOVEmovey = pMOVE->iLocay; + + iRetcode = mng_process_display_move (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_MOVE, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_CLIP +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_clip (mng_datap pData, + mng_uint16 iFirstid, + mng_uint16 iLastid, + mng_uint8 iType, + mng_int32 iClipl, + mng_int32 iClipr, + mng_int32 iClipt, + mng_int32 iClipb) +#else +mng_retcode mng_create_ani_clip (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ani_clipp pCLIP; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_CLIP, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + iRetcode = create_obj_general (pData, sizeof (mng_ani_clip), + mng_free_obj_general, + mng_process_ani_clip, + &pTemp); + if (iRetcode) + return iRetcode; + pCLIP = (mng_ani_clipp)pTemp; +#else + MNG_ALLOC (pData, pCLIP, sizeof (mng_ani_clip)); + + pCLIP->sHeader.fCleanup = mng_free_ani_clip; + pCLIP->sHeader.fProcess = mng_process_ani_clip; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pCLIP); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pCLIP->iFirstid = iFirstid; + pCLIP->iLastid = iLastid; + pCLIP->iType = iType; + pCLIP->iClipl = iClipl; + pCLIP->iClipr = iClipr; + pCLIP->iClipt = iClipt; + pCLIP->iClipb = iClipb; +#else + pCLIP->iFirstid = ((mng_clipp)pChunk)->iFirstid; + pCLIP->iLastid = ((mng_clipp)pChunk)->iLastid; + pCLIP->iType = ((mng_clipp)pChunk)->iCliptype; + pCLIP->iClipl = ((mng_clipp)pChunk)->iClipl; + pCLIP->iClipr = ((mng_clipp)pChunk)->iClipr; + pCLIP->iClipt = ((mng_clipp)pChunk)->iClipt; + pCLIP->iClipb = ((mng_clipp)pChunk)->iClipb; +#endif + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +#ifndef MNG_OPTIMIZE_CHUNKREADER + iRetcode = mng_process_display_clip (pData, iFirstid, iLastid, + iType, iClipl, iClipr, + iClipt, iClipb); +#else + iRetcode = mng_process_display_clip (pData, + ((mng_clipp)pChunk)->iFirstid, + ((mng_clipp)pChunk)->iLastid, + ((mng_clipp)pChunk)->iCliptype, + ((mng_clipp)pChunk)->iClipl, + ((mng_clipp)pChunk)->iClipr, + ((mng_clipp)pChunk)->iClipt, + ((mng_clipp)pChunk)->iClipb); +#endif +#else +#ifndef MNG_OPTIMIZE_CHUNKREADER + pData->iCLIPfromid = iFirstid; + pData->iCLIPtoid = iLastid; + pData->iCLIPcliptype = iType; + pData->iCLIPclipl = iClipl; + pData->iCLIPclipr = iClipr; + pData->iCLIPclipt = iClipt; + pData->iCLIPclipb = iClipb; +#else + pData->iCLIPfromid = ((mng_clipp)pChunk)->iFirstid; + pData->iCLIPtoid = ((mng_clipp)pChunk)->iLastid; + pData->iCLIPcliptype = ((mng_clipp)pChunk)->iCliptype; + pData->iCLIPclipl = ((mng_clipp)pChunk)->iClipl; + pData->iCLIPclipr = ((mng_clipp)pChunk)->iClipr; + pData->iCLIPclipt = ((mng_clipp)pChunk)->iClipt; + pData->iCLIPclipb = ((mng_clipp)pChunk)->iClipb; +#endif + + iRetcode = mng_process_display_clip (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_CLIP, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_clip (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_CLIP, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_clip)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_CLIP, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_clip (mng_datap pData, + mng_objectp pObject) +{ + mng_retcode iRetcode; + mng_ani_clipp pCLIP = (mng_ani_clipp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_CLIP, MNG_LC_START); +#endif + /* re-process the CLIP chunk */ +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mng_process_display_clip (pData, pCLIP->iFirstid, pCLIP->iLastid, + pCLIP->iType, pCLIP->iClipl, pCLIP->iClipr, + pCLIP->iClipt, pCLIP->iClipb); +#else + pData->iCLIPfromid = pCLIP->iFirstid; + pData->iCLIPtoid = pCLIP->iLastid; + pData->iCLIPcliptype = pCLIP->iType; + pData->iCLIPclipl = pCLIP->iClipl; + pData->iCLIPclipr = pCLIP->iClipr; + pData->iCLIPclipt = pCLIP->iClipt; + pData->iCLIPclipb = pCLIP->iClipb; + + iRetcode = mng_process_display_clip (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_CLIP, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SHOW +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_show (mng_datap pData, + mng_uint16 iFirstid, + mng_uint16 iLastid, + mng_uint8 iMode) +#else +mng_retcode mng_create_ani_show (mng_datap pData) +#endif +{ + mng_ani_showp pSHOW; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_SHOW, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_show), + mng_free_obj_general, + mng_process_ani_show, + &pTemp); + if (iRetcode) + return iRetcode; + pSHOW = (mng_ani_showp)pTemp; +#else + MNG_ALLOC (pData, pSHOW, sizeof (mng_ani_show)); + + pSHOW->sHeader.fCleanup = mng_free_ani_show; + pSHOW->sHeader.fProcess = mng_process_ani_show; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pSHOW); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pSHOW->iFirstid = iFirstid; + pSHOW->iLastid = iLastid; + pSHOW->iMode = iMode; +#else + pSHOW->iFirstid = pData->iSHOWfromid; + pSHOW->iLastid = pData->iSHOWtoid; + pSHOW->iMode = pData->iSHOWmode; +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_SHOW, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_show (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_SHOW, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_show)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_SHOW, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_show (mng_datap pData, + mng_objectp pObject) +{ + mng_retcode iRetcode; + mng_ani_showp pSHOW = (mng_ani_showp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SHOW, MNG_LC_START); +#endif + + if (pData->iBreakpoint) /* returning from breakpoint ? */ + { + iRetcode = mng_process_display_show (pData); + } + else + { /* "re-run" SHOW chunk */ + pData->iSHOWmode = pSHOW->iMode; + pData->iSHOWfromid = pSHOW->iFirstid; + pData->iSHOWtoid = pSHOW->iLastid; + + iRetcode = mng_process_display_show (pData); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SHOW, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_TERM +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_term (mng_datap pData, + mng_uint8 iTermaction, + mng_uint8 iIteraction, + mng_uint32 iDelay, + mng_uint32 iItermax) +#else +mng_retcode mng_create_ani_term (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ani_termp pTERM; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_TERM, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_term), + mng_free_obj_general, + mng_process_ani_term, + &pTemp); + if (iRetcode) + return iRetcode; + pTERM = (mng_ani_termp)pTemp; +#else + MNG_ALLOC (pData, pTERM, sizeof (mng_ani_term)); + + pTERM->sHeader.fCleanup = mng_free_ani_term; + pTERM->sHeader.fProcess = mng_process_ani_term; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pTERM); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pTERM->iTermaction = iTermaction; + pTERM->iIteraction = iIteraction; + pTERM->iDelay = iDelay; + pTERM->iItermax = iItermax; +#else + pTERM->iTermaction = ((mng_termp)pChunk)->iTermaction; + pTERM->iIteraction = ((mng_termp)pChunk)->iIteraction; + pTERM->iDelay = ((mng_termp)pChunk)->iDelay; + pTERM->iItermax = ((mng_termp)pChunk)->iItermax; +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_TERM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_term (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_TERM, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_term)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_TERM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_term (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_TERM, MNG_LC_START); +#endif + + /* dummy: no action required! */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_TERM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SAVE +mng_retcode mng_create_ani_save (mng_datap pData) +{ + mng_ptr pTemp; + mng_ani_savep pSAVE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_SAVE, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_save), + mng_free_obj_general, + mng_process_ani_save, + &pTemp); + if (iRetcode) + return iRetcode; + pSAVE = (mng_ani_savep)pTemp; +#else + MNG_ALLOC (pData, pSAVE, sizeof (mng_ani_save)); + + pSAVE->sHeader.fCleanup = mng_free_ani_save; + pSAVE->sHeader.fProcess = mng_process_ani_save; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pSAVE); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_SAVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_save (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_SAVE, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_save)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_SAVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_save (mng_datap pData, + mng_objectp pObject) +{ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SAVE, MNG_LC_START); +#endif + + iRetcode = mng_process_display_save (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SAVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_SEEK +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_seek (mng_datap pData, + mng_uint32 iSegmentnamesize, + mng_pchar zSegmentname) +#else +mng_retcode mng_create_ani_seek (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ptr pTemp; + mng_ani_seekp pSEEK; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_SEEK, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_seek), + mng_free_ani_seek, + mng_process_ani_seek, + &pTemp); + if (iRetcode) + return iRetcode; + pSEEK = (mng_ani_seekp)pTemp; +#else + MNG_ALLOC (pData, pSEEK, sizeof (mng_ani_seek)); + + pSEEK->sHeader.fCleanup = mng_free_ani_seek; + pSEEK->sHeader.fProcess = mng_process_ani_seek; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pSEEK); + + pData->pLastseek = (mng_objectp)pSEEK; + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pSEEK->iSegmentnamesize = iSegmentnamesize; + if (iSegmentnamesize) + { + MNG_ALLOC (pData, pSEEK->zSegmentname, iSegmentnamesize + 1); + MNG_COPY (pSEEK->zSegmentname, zSegmentname, iSegmentnamesize); + } +#else + pSEEK->iSegmentnamesize = ((mng_seekp)pChunk)->iNamesize; + if (pSEEK->iSegmentnamesize) + { + MNG_ALLOC (pData, pSEEK->zSegmentname, pSEEK->iSegmentnamesize + 1); + MNG_COPY (pSEEK->zSegmentname, ((mng_seekp)pChunk)->zName, pSEEK->iSegmentnamesize); + } +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_SEEK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_free_ani_seek (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_seekp pSEEK = (mng_ani_seekp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_SEEK, MNG_LC_START); +#endif + + if (pSEEK->iSegmentnamesize) + MNG_FREEX (pData, pSEEK->zSegmentname, pSEEK->iSegmentnamesize + 1); + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + MNG_FREEX (pData, pObject, sizeof (mng_ani_seek)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_SEEK, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + return MNG_NOERROR; +#else + return mng_free_obj_general(pData, pObject); +#endif +} + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_seek (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_seekp pSEEK = (mng_ani_seekp)pObject; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SEEK, MNG_LC_START); +#endif + +#ifdef MNG_SUPPORT_DYNAMICMNG + if (!pData->bStopafterseek) /* can we really process this one ? */ +#endif + { + pData->pLastseek = pObject; + + if (pData->fProcessseek) /* inform the app ? */ + { + mng_bool bOke; + mng_pchar zName; + + MNG_ALLOC (pData, zName, pSEEK->iSegmentnamesize + 1); + + if (pSEEK->iSegmentnamesize) + MNG_COPY (zName, pSEEK->zSegmentname, pSEEK->iSegmentnamesize); + + bOke = pData->fProcessseek ((mng_handle)pData, zName); + + MNG_FREEX (pData, zName, pSEEK->iSegmentnamesize + 1); + + if (!bOke) + MNG_ERROR (pData, MNG_APPMISCERROR); + } + } + + iRetcode = mng_process_display_seek (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_SEEK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_dhdr (mng_datap pData, + mng_uint16 iObjectid, + mng_uint8 iImagetype, + mng_uint8 iDeltatype, + mng_uint32 iBlockwidth, + mng_uint32 iBlockheight, + mng_uint32 iBlockx, + mng_uint32 iBlocky) +#else +mng_retcode mng_create_ani_dhdr (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ani_dhdrp pDHDR; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_DHDR, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + iRetcode = create_obj_general (pData, sizeof (mng_ani_dhdr), + mng_free_obj_general, + mng_process_ani_dhdr, + &pTemp); + if (iRetcode) + return iRetcode; + pDHDR = (mng_ani_dhdrp)pTemp; +#else + MNG_ALLOC (pData, pDHDR, sizeof (mng_ani_dhdr)); + + pDHDR->sHeader.fCleanup = mng_free_ani_dhdr; + pDHDR->sHeader.fProcess = mng_process_ani_dhdr; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pDHDR); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pDHDR->iObjectid = iObjectid; + pDHDR->iImagetype = iImagetype; + pDHDR->iDeltatype = iDeltatype; + pDHDR->iBlockwidth = iBlockwidth; + pDHDR->iBlockheight = iBlockheight; + pDHDR->iBlockx = iBlockx; + pDHDR->iBlocky = iBlocky; +#else + pDHDR->iObjectid = ((mng_dhdrp)pChunk)->iObjectid; + pDHDR->iImagetype = ((mng_dhdrp)pChunk)->iImagetype; + pDHDR->iDeltatype = ((mng_dhdrp)pChunk)->iDeltatype; + pDHDR->iBlockwidth = ((mng_dhdrp)pChunk)->iBlockwidth; + pDHDR->iBlockheight = ((mng_dhdrp)pChunk)->iBlockheight; + pDHDR->iBlockx = ((mng_dhdrp)pChunk)->iBlockx; + pDHDR->iBlocky = ((mng_dhdrp)pChunk)->iBlocky; +#endif + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +#ifndef MNG_OPTIMIZE_CHUNKREADER + iRetcode = mng_process_display_dhdr (pData, iObjectid, + iImagetype, iDeltatype, + iBlockwidth, iBlockheight, + iBlockx, iBlocky); +#else + iRetcode = mng_process_display_dhdr (pData, + ((mng_dhdrp)pChunk)->iObjectid, + ((mng_dhdrp)pChunk)->iImagetype, + ((mng_dhdrp)pChunk)->iDeltatype, + ((mng_dhdrp)pChunk)->iBlockwidth, + ((mng_dhdrp)pChunk)->iBlockheight, + ((mng_dhdrp)pChunk)->iBlockx, + ((mng_dhdrp)pChunk)->iBlocky); +#endif +#else +#ifndef MNG_OPTIMIZE_CHUNKREADER + pData->iDHDRobjectid = iObjectid; + pData->iDHDRimagetype = iImagetype; + pData->iDHDRdeltatype = iDeltatype; + pData->iDHDRblockwidth = iBlockwidth; + pData->iDHDRblockheight = iBlockheight; + pData->iDHDRblockx = iBlockx; + pData->iDHDRblocky = iBlocky; +#else + pData->iDHDRobjectid = ((mng_dhdrp)pChunk)->iObjectid; + pData->iDHDRimagetype = ((mng_dhdrp)pChunk)->iImagetype; + pData->iDHDRdeltatype = ((mng_dhdrp)pChunk)->iDeltatype; + pData->iDHDRblockwidth = ((mng_dhdrp)pChunk)->iBlockwidth; + pData->iDHDRblockheight = ((mng_dhdrp)pChunk)->iBlockheight; + pData->iDHDRblockx = ((mng_dhdrp)pChunk)->iBlockx; + pData->iDHDRblocky = ((mng_dhdrp)pChunk)->iBlocky; +#endif + + iRetcode = mng_process_display_dhdr (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_DHDR, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_dhdr (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_DHDR, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_dhdr)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_DHDR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_dhdr (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_dhdrp pDHDR = (mng_ani_dhdrp)pObject; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_DHDR, MNG_LC_START); +#endif + + pData->bHasDHDR = MNG_TRUE; /* let everyone know we're inside a DHDR */ + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mng_process_display_dhdr (pData, pDHDR->iObjectid, + pDHDR->iImagetype, pDHDR->iDeltatype, + pDHDR->iBlockwidth, pDHDR->iBlockheight, + pDHDR->iBlockx, pDHDR->iBlocky); +#else + pData->iDHDRobjectid = pDHDR->iObjectid; + pData->iDHDRimagetype = pDHDR->iImagetype; + pData->iDHDRdeltatype = pDHDR->iDeltatype; + pData->iDHDRblockwidth = pDHDR->iBlockwidth; + pData->iDHDRblockheight = pDHDR->iBlockheight; + pData->iDHDRblockx = pDHDR->iBlockx; + pData->iDHDRblocky = pDHDR->iBlocky; + + iRetcode = mng_process_display_dhdr (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_DHDR, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_prom (mng_datap pData, + mng_uint8 iBitdepth, + mng_uint8 iColortype, + mng_uint8 iFilltype) +#else +mng_retcode mng_create_ani_prom (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ani_promp pPROM=NULL; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_PROM, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + iRetcode = create_obj_general (pData, sizeof (mng_ani_prom), + mng_free_obj_general, + mng_process_ani_prom, + &pTemp); + if (iRetcode) + return iRetcode; + pPROM = (mng_ani_promp)pTemp; +#else + MNG_ALLOC (pData, pPROM, sizeof (mng_ani_prom)); + + pPROM->sHeader.fCleanup = mng_free_ani_prom; + pPROM->sHeader.fProcess = mng_process_ani_prom; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pPROM); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pPROM->iBitdepth = iBitdepth; + pPROM->iColortype = iColortype; + pPROM->iFilltype = iFilltype; +#else + pPROM->iBitdepth = ((mng_promp)pChunk)->iSampledepth; + pPROM->iColortype = ((mng_promp)pChunk)->iColortype; + pPROM->iFilltype = ((mng_promp)pChunk)->iFilltype; +#endif + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +#ifndef MNG_OPTIMIZE_CHUNKREADER + iRetcode = mng_process_display_prom (pData, iBitdepth, + iColortype, iFilltype); +#else + iRetcode = mng_process_display_prom (pData, + ((mng_promp)pChunk)->iSampledepth, + ((mng_promp)pChunk)->iColortype, + ((mng_promp)pChunk)->iFilltype); +#endif +#else +#ifndef MNG_OPTIMIZE_CHUNKREADER + pData->iPROMbitdepth = iBitdepth; + pData->iPROMcolortype = iColortype; + pData->iPROMfilltype = iFilltype; +#else + pData->iPROMbitdepth = ((mng_promp)pChunk)->iSampledepth; + pData->iPROMcolortype = ((mng_promp)pChunk)->iColortype; + pData->iPROMfilltype = ((mng_promp)pChunk)->iFilltype; +#endif + + iRetcode = mng_process_display_prom (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_PROM, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_prom (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_PROM, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_prom)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_PROM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_prom (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_promp pPROM = (mng_ani_promp)pObject; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PROM, MNG_LC_START); +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mng_process_display_prom (pData, pPROM->iBitdepth, + pPROM->iColortype, pPROM->iFilltype); +#else + pData->iPROMbitdepth = pPROM->iBitdepth; + pData->iPROMcolortype = pPROM->iColortype; + pData->iPROMfilltype = pPROM->iFilltype; + + iRetcode = mng_process_display_prom (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PROM, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode mng_create_ani_ipng (mng_datap pData) +{ + mng_ani_ipngp pIPNG; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_IPNG, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_ipng), + mng_free_obj_general, + mng_process_ani_ipng, + &pTemp); + if (iRetcode) + return iRetcode; + pIPNG = (mng_ani_ipngp)pTemp; +#else + MNG_ALLOC (pData, pIPNG, sizeof (mng_ani_ipng)); + + pIPNG->sHeader.fCleanup = mng_free_ani_ipng; + pIPNG->sHeader.fProcess = mng_process_ani_ipng; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pIPNG); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_IPNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_ipng (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_IPNG, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_ipng)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_IPNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_ipng (mng_datap pData, + mng_objectp pObject) +{ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_IPNG, MNG_LC_START); +#endif + + iRetcode = mng_process_display_ipng (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_IPNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG +mng_retcode mng_create_ani_ijng (mng_datap pData) +{ + mng_ani_ijngp pIJNG; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_IJNG, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_ani_ijng), + mng_free_obj_general, + mng_process_ani_ijng, + &pTemp); + if (iRetcode) + return iRetcode; + pIJNG = (mng_ani_ijngp)pTemp; +#else + MNG_ALLOC (pData, pIJNG, sizeof (mng_ani_ijng)); + + pIJNG->sHeader.fCleanup = mng_free_ani_ijng; + pIJNG->sHeader.fProcess = mng_process_ani_ijng; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pIJNG); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_IJNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_ijng (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_IJNG, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_ijng)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_IJNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_ijng (mng_datap pData, + mng_objectp pObject) +{ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_IJNG, MNG_LC_START); +#endif + + iRetcode = mng_process_display_ijng (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_IJNG, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode mng_create_ani_pplt (mng_datap pData, + mng_uint8 iType, + mng_uint32 iCount, + mng_palette8ep paIndexentries, + mng_uint8p paAlphaentries, + mng_uint8p paUsedentries) +{ + mng_ani_ppltp pPPLT; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_PPLT, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + iRetcode = create_obj_general (pData, sizeof (mng_ani_pplt), + mng_free_obj_general, + mng_process_ani_pplt, + &pTemp); + if (iRetcode) + return iRetcode; + pPPLT = (mng_ani_ppltp)pTemp; +#else + MNG_ALLOC (pData, pPPLT, sizeof (mng_ani_pplt)); + + pPPLT->sHeader.fCleanup = mng_free_ani_pplt; + pPPLT->sHeader.fProcess = mng_process_ani_pplt; +#endif + + pPPLT->iType = iType; + pPPLT->iCount = iCount; + + MNG_COPY (pPPLT->aIndexentries, paIndexentries, sizeof (pPPLT->aIndexentries)); + MNG_COPY (pPPLT->aAlphaentries, paAlphaentries, sizeof (pPPLT->aAlphaentries)); + MNG_COPY (pPPLT->aUsedentries, paUsedentries, sizeof (pPPLT->aUsedentries )); + + mng_add_ani_object (pData, (mng_object_headerp)pPPLT); + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mng_process_display_pplt (pData, iType, iCount, + paIndexentries, paAlphaentries, paUsedentries); +#else + pData->iPPLTtype = iType; + pData->iPPLTcount = iCount; + pData->paPPLTindexentries = paIndexentries; + pData->paPPLTalphaentries = paAlphaentries; + pData->paPPLTusedentries = paUsedentries; + + iRetcode = mng_process_display_pplt (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_PPLT, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_pplt (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_PPLT, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_pplt)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_PPLT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_pplt (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_ppltp pPPLT = (mng_ani_ppltp)pObject; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PPLT, MNG_LC_START); +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mng_process_display_pplt (pData, pPPLT->iType, pPPLT->iCount, + pPPLT->aIndexentries, pPPLT->aAlphaentries, + pPPLT->aUsedentries); +#else + pData->iPPLTtype = pPPLT->iType; + pData->iPPLTcount = pPPLT->iCount; + pData->paPPLTindexentries = &pPPLT->aIndexentries; + pData->paPPLTalphaentries = &pPPLT->aAlphaentries; + pData->paPPLTusedentries = &pPPLT->aUsedentries; + + iRetcode = mng_process_display_pplt (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PPLT, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MAGN +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_magn (mng_datap pData, + mng_uint16 iFirstid, + mng_uint16 iLastid, + mng_uint8 iMethodX, + mng_uint16 iMX, + mng_uint16 iMY, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint16 iMT, + mng_uint16 iMB, + mng_uint8 iMethodY) +#else +mng_retcode mng_create_ani_magn (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ani_magnp pMAGN=NULL; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_MAGN, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + iRetcode = create_obj_general (pData, sizeof (mng_ani_magn), + mng_free_obj_general, + mng_process_ani_magn, + &pTemp); + if (iRetcode) + return iRetcode; + pMAGN = (mng_ani_magnp)pTemp; +#else + MNG_ALLOC (pData, pMAGN, sizeof (mng_ani_magn)); + + pMAGN->sHeader.fCleanup = mng_free_ani_magn; + pMAGN->sHeader.fProcess = mng_process_ani_magn; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pMAGN); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pMAGN->iFirstid = iFirstid; + pMAGN->iLastid = iLastid; + pMAGN->iMethodX = iMethodX; + pMAGN->iMX = iMX; + pMAGN->iMY = iMY; + pMAGN->iML = iML; + pMAGN->iMR = iMR; + pMAGN->iMT = iMT; + pMAGN->iMB = iMB; + pMAGN->iMethodY = iMethodY; +#else + pMAGN->iFirstid = ((mng_magnp)pChunk)->iFirstid; + pMAGN->iLastid = ((mng_magnp)pChunk)->iLastid; + pMAGN->iMethodX = ((mng_magnp)pChunk)->iMethodX; + pMAGN->iMX = ((mng_magnp)pChunk)->iMX; + pMAGN->iMY = ((mng_magnp)pChunk)->iMY; + pMAGN->iML = ((mng_magnp)pChunk)->iML; + pMAGN->iMR = ((mng_magnp)pChunk)->iMR; + pMAGN->iMT = ((mng_magnp)pChunk)->iMT; + pMAGN->iMB = ((mng_magnp)pChunk)->iMB; + pMAGN->iMethodY = ((mng_magnp)pChunk)->iMethodY; +#endif + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +#ifndef MNG_OPTIMIZE_CHUNKREADER + iRetcode = mng_process_display_magn (pData, pMAGN->iFirstid, pMAGN->iLastid, + pMAGN->iMethodX, pMAGN->iMX, pMAGN->iMY, + pMAGN->iML, pMAGN->iMR, pMAGN->iMT, + pMAGN->iMB, pMAGN->iMethodY); +#else + iRetcode = mng_process_display_magn (pData, + ((mng_magnp)pChunk)->iFirstid, + ((mng_magnp)pChunk)->iLastid, + ((mng_magnp)pChunk)->iMethodX, + ((mng_magnp)pChunk)->iMX, + ((mng_magnp)pChunk)->iMY, + ((mng_magnp)pChunk)->iML, + ((mng_magnp)pChunk)->iMR, + ((mng_magnp)pChunk)->iMT, + ((mng_magnp)pChunk)->iMB, + ((mng_magnp)pChunk)->iMethodY); +#endif +#else +#ifndef MNG_OPTIMIZE_CHUNKREADER + pData->iMAGNfirstid = iFirstid; + pData->iMAGNlastid = iLastid; + pData->iMAGNmethodX = iMethodX; + pData->iMAGNmX = iMX; + pData->iMAGNmY = iMY; + pData->iMAGNmL = iML; + pData->iMAGNmR = iMR; + pData->iMAGNmT = iMT; + pData->iMAGNmB = iMB; + pData->iMAGNmethodY = iMethodY; +#else + pData->iMAGNfirstid = ((mng_magnp)pChunk)->iFirstid; + pData->iMAGNlastid = ((mng_magnp)pChunk)->iLastid; + pData->iMAGNmethodX = ((mng_magnp)pChunk)->iMethodX; + pData->iMAGNmX = ((mng_magnp)pChunk)->iMX; + pData->iMAGNmY = ((mng_magnp)pChunk)->iMY; + pData->iMAGNmL = ((mng_magnp)pChunk)->iML; + pData->iMAGNmR = ((mng_magnp)pChunk)->iMR; + pData->iMAGNmT = ((mng_magnp)pChunk)->iMT; + pData->iMAGNmB = ((mng_magnp)pChunk)->iMB; + pData->iMAGNmethodY = ((mng_magnp)pChunk)->iMethodY; +#endif + + iRetcode = mng_process_display_magn (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_MAGN, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_OBJCLEANUP +mng_retcode mng_free_ani_magn (mng_datap pData, + mng_objectp pObject) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_MAGN, MNG_LC_START); +#endif + + MNG_FREEX (pData, pObject, sizeof (mng_ani_magn)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_MAGN, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_magn (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_magnp pMAGN = (mng_ani_magnp)pObject; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_MAGN, MNG_LC_START); +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mng_process_display_magn (pData, pMAGN->iFirstid, pMAGN->iLastid, + pMAGN->iMethodX, pMAGN->iMX, pMAGN->iMY, + pMAGN->iML, pMAGN->iMR, pMAGN->iMT, + pMAGN->iMB, pMAGN->iMethodY); +#else + pData->iMAGNfirstid = pMAGN->iFirstid; + pData->iMAGNlastid = pMAGN->iLastid; + pData->iMAGNmethodX = pMAGN->iMethodX; + pData->iMAGNmX = pMAGN->iMX; + pData->iMAGNmY = pMAGN->iMY; + pData->iMAGNmL = pMAGN->iML; + pData->iMAGNmR = pMAGN->iMR; + pData->iMAGNmT = pMAGN->iMT; + pData->iMAGNmB = pMAGN->iMB; + pData->iMAGNmethodY = pMAGN->iMethodY; + + iRetcode = mng_process_display_magn (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_MAGN, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_past (mng_datap pData, + mng_uint16 iTargetid, + mng_uint8 iTargettype, + mng_int32 iTargetx, + mng_int32 iTargety, + mng_uint32 iCount, + mng_ptr pSources) +#else +mng_retcode mng_create_ani_past (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ani_pastp pPAST; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_PAST, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + iRetcode = create_obj_general (pData, sizeof (mng_ani_past), + mng_free_ani_past, + mng_process_ani_past, + &pTemp); + if (iRetcode) + return iRetcode; + pPAST = (mng_ani_pastp)pTemp; +#else + MNG_ALLOC (pData, pPAST, sizeof (mng_ani_past)); + + pPAST->sHeader.fCleanup = mng_free_ani_past; + pPAST->sHeader.fProcess = mng_process_ani_past; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pPAST); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pPAST->iTargetid = iTargetid; + pPAST->iTargettype = iTargettype; + pPAST->iTargetx = iTargetx; + pPAST->iTargety = iTargety; + pPAST->iCount = iCount; + + if (iCount) + { + MNG_ALLOC (pData, pPAST->pSources, (iCount * sizeof (mng_past_source))); + MNG_COPY (pPAST->pSources, pSources, (iCount * sizeof (mng_past_source))); + } +#else + pPAST->iTargetid = ((mng_pastp)pChunk)->iDestid; + pPAST->iTargettype = ((mng_pastp)pChunk)->iTargettype; + pPAST->iTargetx = ((mng_pastp)pChunk)->iTargetx; + pPAST->iTargety = ((mng_pastp)pChunk)->iTargety; + pPAST->iCount = ((mng_pastp)pChunk)->iCount; + + if (pPAST->iCount) + { + mng_size_t iSize = (mng_size_t)(pPAST->iCount * sizeof (mng_past_source)); + MNG_ALLOC (pData, pPAST->pSources, iSize); + MNG_COPY (pPAST->pSources, ((mng_pastp)pChunk)->pSources, iSize); + } +#endif + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +#ifndef MNG_OPTIMIZE_CHUNKREADER + iRetcode = mng_process_display_past (pData, iTargetid, iTargettype, + iTargetx, iTargety, + iCount, pSources); +#else + iRetcode = mng_process_display_past (pData, + ((mng_pastp)pChunk)->iDestid, + ((mng_pastp)pChunk)->iTargettype, + ((mng_pastp)pChunk)->iTargetx, + ((mng_pastp)pChunk)->iTargety, + ((mng_pastp)pChunk)->iCount, + ((mng_pastp)pChunk)->pSources); +#endif +#else +#ifndef MNG_OPTIMIZE_CHUNKREADER + pData->iPASTtargetid = iTargetid; + pData->iPASTtargettype = iTargettype; + pData->iPASTtargetx = iTargetx; + pData->iPASTtargety = iTargety; + pData->iPASTcount = iCount; + pData->pPASTsources = pSources; +#else + pData->iPASTtargetid = ((mng_pastp)pChunk)->iDestid; + pData->iPASTtargettype = ((mng_pastp)pChunk)->iTargettype; + pData->iPASTtargetx = ((mng_pastp)pChunk)->iTargetx; + pData->iPASTtargety = ((mng_pastp)pChunk)->iTargety; + pData->iPASTcount = ((mng_pastp)pChunk)->iCount; + pData->pPASTsources = ((mng_pastp)pChunk)->pSources; +#endif + + iRetcode = mng_process_display_past (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_PAST, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +mng_retcode mng_free_ani_past (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_pastp pPAST = (mng_ani_pastp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_PAST, MNG_LC_START); +#endif + + if (pPAST->iCount) + MNG_FREEX (pData, pPAST->pSources, (pPAST->iCount * sizeof (mng_past_source))); + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + MNG_FREEX (pData, pObject, sizeof (mng_ani_past)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_PAST, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + return MNG_NOERROR; +#else + return mng_free_obj_general(pData, pObject); +#endif +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +mng_retcode mng_process_ani_past (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_pastp pPAST = (mng_ani_pastp)pObject; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PAST, MNG_LC_START); +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mng_process_display_past (pData, pPAST->iTargetid, pPAST->iTargettype, + pPAST->iTargetx, pPAST->iTargety, + pPAST->iCount, pPAST->pSources); +#else + pData->iPASTtargetid = pPAST->iTargetid; + pData->iPASTtargettype = pPAST->iTargettype; + pData->iPASTtargetx = pPAST->iTargetx; + pData->iPASTtargety = pPAST->iTargety; + pData->iPASTcount = pPAST->iCount; + pData->pPASTsources = pPAST->pSources; + + iRetcode = mng_process_display_past (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_PAST, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_DISC +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ani_disc (mng_datap pData, + mng_uint32 iCount, + mng_uint16p pIds) +#else +mng_retcode mng_create_ani_disc (mng_datap pData, + mng_chunkp pChunk) +#endif +{ + mng_ani_discp pDISC; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_DISC, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + iRetcode = create_obj_general (pData, sizeof (mng_ani_disc), + mng_free_ani_disc, + mng_process_ani_disc, + &pTemp); + if (iRetcode) + return iRetcode; + pDISC = (mng_ani_discp)pTemp; +#else + MNG_ALLOC (pData, pDISC, sizeof (mng_ani_disc)); + + pDISC->sHeader.fCleanup = mng_free_ani_disc; + pDISC->sHeader.fProcess = mng_process_ani_disc; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pDISC); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pDISC->iCount = iCount; + + if (iCount) + { + MNG_ALLOC (pData, pDISC->pIds, (iCount << 1)); + MNG_COPY (pDISC->pIds, pIds, (iCount << 1)); + } +#else + pDISC->iCount = ((mng_discp)pChunk)->iCount; + + if (pDISC->iCount) + { + mng_size_t iSize = (mng_size_t)(pDISC->iCount << 1); + MNG_ALLOC (pData, pDISC->pIds, iSize); + MNG_COPY (pDISC->pIds, ((mng_discp)pChunk)->pObjectids, iSize); + } +#endif + } + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS +#ifndef MNG_OPTIMIZE_CHUNKREADER + iRetcode = mng_process_display_disc (pData, iCount, pIds); +#else + iRetcode = mng_process_display_disc (pData, + ((mng_discp)pChunk)->iCount, + ((mng_discp)pChunk)->pObjectids); +#endif +#else +#ifndef MNG_OPTIMIZE_CHUNKREADER + pData->iDISCcount = iCount; + pData->pDISCids = pIds; +#else + pData->iDISCcount = ((mng_discp)pChunk)->iCount; + pData->pDISCids = ((mng_discp)pChunk)->pObjectids; +#endif + + iRetcode = mng_process_display_disc (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANI_DISC, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_free_ani_disc (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_discp pDISC = (mng_ani_discp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_DISC, MNG_LC_START); +#endif + + if (pDISC->iCount) + MNG_FREEX (pData, pDISC->pIds, (pDISC->iCount << 1)); + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + MNG_FREEX (pData, pObject, sizeof (mng_ani_disc)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANI_DISC, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + return MNG_NOERROR; +#else + return mng_free_obj_general(pData, pObject); +#endif +} + +/* ************************************************************************** */ + +mng_retcode mng_process_ani_disc (mng_datap pData, + mng_objectp pObject) +{ + mng_ani_discp pDISC = (mng_ani_discp)pObject; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_DISC, MNG_LC_START); +#endif + +#ifndef MNG_OPTIMIZE_DISPLAYCALLS + iRetcode = mng_process_display_disc (pData, pDISC->iCount, pDISC->pIds); +#else + pData->iDISCcount = pDISC->iCount; + pData->pDISCids = pDISC->pIds; + + iRetcode = mng_process_display_disc (pData); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANI_DISC, MNG_LC_END); +#endif + + return iRetcode; +} +#endif + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DYNAMICMNG + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_event (mng_datap pData, + mng_uint8 iEventtype, + mng_uint8 iMasktype, + mng_int32 iLeft, + mng_int32 iRight, + mng_int32 iTop, + mng_int32 iBottom, + mng_uint16 iObjectid, + mng_uint8 iIndex, + mng_uint32 iSegmentnamesize, + mng_pchar zSegmentname) +#else +mng_retcode mng_create_event (mng_datap pData, + mng_ptr pEntry) +#endif +{ + mng_eventp pEvent; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_EVENT, MNG_LC_START); +#endif + + if (pData->bCacheplayback) /* caching playback info ? */ + { + mng_object_headerp pLast; + +#ifdef MNG_OPTIMIZE_OBJCLEANUP + mng_ptr pTemp; + mng_retcode iRetcode = create_obj_general (pData, sizeof (mng_event), + mng_free_event, + mng_process_event, + &pTemp); + if (iRetcode) + return iRetcode; + pEvent = (mng_eventp)pTemp; +#else + MNG_ALLOC (pData, pEvent, sizeof (mng_event)); + + pEvent->sHeader.fCleanup = mng_free_event; + pEvent->sHeader.fProcess = mng_process_event; +#endif + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pEvent->iEventtype = iEventtype; + pEvent->iMasktype = iMasktype; + pEvent->iLeft = iLeft; + pEvent->iRight = iRight; + pEvent->iTop = iTop; + pEvent->iBottom = iBottom; + pEvent->iObjectid = iObjectid; + pEvent->iIndex = iIndex; + pEvent->iSegmentnamesize = iSegmentnamesize; + + if (iSegmentnamesize) + { + MNG_ALLOC (pData, pEvent->zSegmentname, iSegmentnamesize+1); + MNG_COPY (pEvent->zSegmentname, zSegmentname, iSegmentnamesize); + } +#else + pEvent->iEventtype = ((mng_evnt_entryp)pEntry)->iEventtype; + pEvent->iMasktype = ((mng_evnt_entryp)pEntry)->iMasktype; + pEvent->iLeft = ((mng_evnt_entryp)pEntry)->iLeft; + pEvent->iRight = ((mng_evnt_entryp)pEntry)->iRight; + pEvent->iTop = ((mng_evnt_entryp)pEntry)->iTop; + pEvent->iBottom = ((mng_evnt_entryp)pEntry)->iBottom; + pEvent->iObjectid = ((mng_evnt_entryp)pEntry)->iObjectid; + pEvent->iIndex = ((mng_evnt_entryp)pEntry)->iIndex; + pEvent->iSegmentnamesize = ((mng_evnt_entryp)pEntry)->iSegmentnamesize; + + if (pEvent->iSegmentnamesize) + { + MNG_ALLOC (pData, pEvent->zSegmentname, pEvent->iSegmentnamesize+1); + MNG_COPY (pEvent->zSegmentname, ((mng_evnt_entryp)pEntry)->zSegmentname, pEvent->iSegmentnamesize); + } +#endif + /* fixup the double-linked list */ + pLast = (mng_object_headerp)pData->pLastevent; + + if (pLast) /* link it as last in the chain */ + { + pEvent->sHeader.pPrev = pLast; + pLast->pNext = pEvent; + } + else + { + pData->pFirstevent = pEvent; + } + + pData->pLastevent = pEvent; + pData->bDynamic = MNG_TRUE; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_EVENT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_free_event (mng_datap pData, + mng_objectp pObject) +{ + mng_eventp pEvent = (mng_eventp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_EVENT, MNG_LC_START); +#endif + + if (pEvent->iSegmentnamesize) + MNG_FREEX (pData, pEvent->zSegmentname, pEvent->iSegmentnamesize + 1); + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + MNG_FREEX (pData, pEvent, sizeof (mng_event)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_EVENT, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + return MNG_NOERROR; +#else + return mng_free_obj_general(pData, pObject); +#endif +} + +/* ************************************************************************** */ + +mng_retcode mng_process_event (mng_datap pData, + mng_objectp pObject) +{ +#ifndef MNG_SKIPCHUNK_SEEK + mng_eventp pEvent = (mng_eventp)pObject; + mng_object_headerp pAni; + mng_bool bFound = MNG_FALSE; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_EVENT, MNG_LC_START); +#endif + +#ifndef MNG_SKIPCHUNK_SEEK + if (!pEvent->pSEEK) /* need to find SEEK first ? */ + { + pAni = (mng_object_headerp)pData->pFirstaniobj; + + while ((pAni) && (!bFound)) + { + if ((pAni->fCleanup == mng_free_ani_seek) && + (strcmp(pEvent->zSegmentname, ((mng_ani_seekp)pAni)->zSegmentname) == 0)) + bFound = MNG_TRUE; + else + pAni = (mng_object_headerp)pAni->pNext; + } + + if (pAni) + pEvent->pSEEK = (mng_ani_seekp)pAni; + } + + if (pEvent->pSEEK) /* anything to do ? */ + { + pEvent->iLastx = pData->iEventx; + pEvent->iLasty = pData->iEventy; + /* let's start from this SEEK then */ + pData->pCurraniobj = (mng_objectp)pEvent->pSEEK; + pData->bRunningevent = MNG_TRUE; + /* wake-up the app ! */ + if (!pData->fSettimer ((mng_handle)pData, 5)) + MNG_ERROR (pData, MNG_APPTIMERERROR); + + } + else + MNG_ERROR (pData, MNG_SEEKNOTFOUND); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_EVENT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#endif /* MNG_SUPPORT_DYNAMICMNG */ + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_mpng_obj (mng_datap pData, + mng_uint32 iFramewidth, + mng_uint32 iFrameheight, + mng_uint16 iNumplays, + mng_uint16 iTickspersec, + mng_uint32 iFramessize, + mng_ptr pFrames) +#else +mng_retcode mng_create_mpng_obj (mng_datap pData, + mng_ptr pEntry) +#endif +{ + mng_mpng_objp pMPNG; + mng_ptr pTemp; + mng_retcode iRetcode; + mng_uint8p pFrame; + mng_int32 iCnt, iMax; + mng_uint32 iX, iY, iWidth, iHeight; + mng_int32 iXoffset, iYoffset; + mng_uint16 iTicks; + mng_uint16 iDelay; + mng_bool bNewframe; + mng_ani_loopp pLOOP; + mng_ani_endlp pENDL; + mng_ani_framp pFRAM; + mng_ani_movep pMOVE; + mng_ani_clipp pCLIP; + mng_ani_showp pSHOW; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_MPNG_OBJ, MNG_LC_START); +#endif + +#ifdef MNG_OPTIMIZE_OBJCLEANUP + iRetcode = create_obj_general (pData, sizeof (mng_mpng_obj), mng_free_mpng_obj, + mng_process_mpng_obj, &pTemp); + if (iRetcode) + return iRetcode; + pMPNG = (mng_mpng_objp)pTemp; +#else + MNG_ALLOC (pData, pMPNG, sizeof (mng_mpng_obj)); + + pMPNG->sHeader.fCleanup = mng_free_mpng_obj; + pMPNG->sHeader.fProcess = mng_process_mpng_obj; +#endif + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pMPNG->iFramewidth = iFramewidth; + pMPNG->iFrameheight = iFrameheight; + pMPNG->iNumplays = iNumplays; + pMPNG->iTickspersec = iTickspersec; + pMPNG->iFramessize = iFramessize; + + if (iFramessize) + { + MNG_ALLOC (pData, pMPNG->pFrames, iFramessize); + MNG_COPY (pMPNG->pFrames, pFrames, iFramessize); + } +#else + pMPNG->iFramewidth = ((mng_mpngp)pEntry)->iFramewidth; + pMPNG->iFrameheight = ((mng_mpngp)pEntry)->iFrameheight; + pMPNG->iNumplays = ((mng_mpngp)pEntry)->iNumplays; + pMPNG->iTickspersec = ((mng_mpngp)pEntry)->iTickspersec; + pMPNG->iFramessize = ((mng_mpngp)pEntry)->iFramessize; + + if (pMPNG->iFramessize) + { + MNG_ALLOC (pData, pMPNG->pFrames, pMPNG->iFramessize); + MNG_COPY (pMPNG->pFrames, ((mng_mpngp)pEntry)->pFrames, pMPNG->iFramessize); + } +#endif + + pData->pMPNG = pMPNG; + pData->eImagetype = mng_it_mpng; + + iRetcode = mng_process_display_mpng (pData); + if (iRetcode) + return iRetcode; + + /* now let's create the MNG animation directives from this */ + + pFrame = (mng_uint8p)pMPNG->pFrames; + iMax = pMPNG->iFramessize / 26; + /* set up MNG impersonation */ + pData->iTicks = pMPNG->iTickspersec; + pData->iLayercount = iMax; + + if (pMPNG->iNumplays != 1) /* create a LOOP/ENDL pair ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + iRetcode = create_obj_general (pData, sizeof (mng_ani_loop), + mng_free_ani_loop, mng_process_ani_loop, + &((mng_ptr)pLOOP)); + if (iRetcode) + return iRetcode; +#else + MNG_ALLOC (pData, pLOOP, sizeof (mng_ani_loop)); + + pLOOP->sHeader.fCleanup = mng_free_ani_loop; + pLOOP->sHeader.fProcess = mng_process_ani_loop; +#endif + + pLOOP->iLevel = 1; + if (pMPNG->iNumplays) + pLOOP->iRepeatcount = pMPNG->iNumplays; + else + pLOOP->iRepeatcount = 0xFFFFFFFFl; + + mng_add_ani_object (pData, (mng_object_headerp)pLOOP); + } + + bNewframe = MNG_TRUE; /* create the frame display objects */ + + for (iCnt = 0; iCnt < iMax; iCnt++) + { + iX = mng_get_uint32 (pFrame); + iY = mng_get_uint32 (pFrame+4); + iWidth = mng_get_uint32 (pFrame+8); + iHeight = mng_get_uint32 (pFrame+12); + iXoffset = mng_get_int32 (pFrame+16); + iYoffset = mng_get_int32 (pFrame+20); + iTicks = mng_get_uint16 (pFrame+24); + + iDelay = iTicks; + if (!iDelay) + { + mng_uint8p pTemp = pFrame+26; + mng_int32 iTemp = iCnt+1; + + while ((iTemp < iMax) && (!iDelay)) + { + iDelay = mng_get_uint16 (pTemp+24); + pTemp += 26; + iTemp++; + } + } + + if (bNewframe) + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + iRetcode = create_obj_general (pData, sizeof (mng_ani_fram), + mng_free_obj_general, mng_process_ani_fram, + &((mng_ptr)pFRAM)); + if (iRetcode) + return iRetcode; +#else + MNG_ALLOC (pData, pFRAM, sizeof (mng_ani_fram)); + + pFRAM->sHeader.fCleanup = mng_free_ani_fram; + pFRAM->sHeader.fProcess = mng_process_ani_fram; +#endif + + pFRAM->iFramemode = 4; + pFRAM->iChangedelay = 1; + pFRAM->iDelay = iDelay; + + mng_add_ani_object (pData, (mng_object_headerp)pFRAM); + } + +#ifdef MNG_OPTIMIZE_OBJCLEANUP + iRetcode = create_obj_general (pData, sizeof (mng_ani_move), + mng_free_obj_general, + mng_process_ani_move, + &((mng_ptr)pMOVE)); + if (iRetcode) + return iRetcode; +#else + MNG_ALLOC (pData, pMOVE, sizeof (mng_ani_move)); + + pMOVE->sHeader.fCleanup = mng_free_ani_move; + pMOVE->sHeader.fProcess = mng_process_ani_move; +#endif + + pMOVE->iLocax = iXoffset - (mng_int32)iX; + pMOVE->iLocay = iYoffset - (mng_int32)iY; + + mng_add_ani_object (pData, (mng_object_headerp)pMOVE); + +#ifdef MNG_OPTIMIZE_OBJCLEANUP + iRetcode = create_obj_general (pData, sizeof (mng_ani_clip), + mng_free_obj_general, + mng_process_ani_clip, + &((mng_ptr)pCLIP)); + if (iRetcode) + return iRetcode; +#else + MNG_ALLOC (pData, pCLIP, sizeof (mng_ani_clip)); + + pCLIP->sHeader.fCleanup = mng_free_ani_clip; + pCLIP->sHeader.fProcess = mng_process_ani_clip; +#endif + + pCLIP->iClipl = iXoffset; + pCLIP->iClipr = iXoffset + (mng_int32)iWidth; + pCLIP->iClipt = iYoffset; + pCLIP->iClipb = iYoffset + (mng_int32)iHeight; + + mng_add_ani_object (pData, (mng_object_headerp)pCLIP); + +#ifdef MNG_OPTIMIZE_OBJCLEANUP + iRetcode = create_obj_general (pData, sizeof (mng_ani_show), + mng_free_obj_general, mng_process_ani_show, + &((mng_ptr)pSHOW)); + if (iRetcode) + return iRetcode; +#else + MNG_ALLOC (pData, pSHOW, sizeof (mng_ani_show)); + + pSHOW->sHeader.fCleanup = mng_free_ani_show; + pSHOW->sHeader.fProcess = mng_process_ani_show; +#endif + + mng_add_ani_object (pData, (mng_object_headerp)pSHOW); + + bNewframe = (mng_bool)iTicks; + pFrame += 26; + } + + if (pMPNG->iNumplays != 1) /* create a LOOP/ENDL pair ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + iRetcode = create_obj_general (pData, sizeof (mng_ani_endl), + mng_free_obj_general, mng_process_ani_endl, + &((mng_ptr)pENDL)); + if (iRetcode) + return iRetcode; +#else + MNG_ALLOC (pData, pENDL, sizeof (mng_ani_endl)); + + pENDL->sHeader.fCleanup = mng_free_ani_endl; + pENDL->sHeader.fProcess = mng_process_ani_endl; +#endif + + pENDL->iLevel = 1; + + mng_add_ani_object (pData, (mng_object_headerp)pENDL); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_MPNG_OBJ, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_free_mpng_obj (mng_datap pData, + mng_objectp pObject) +{ + mng_mpng_objp pMPNG = (mng_mpng_objp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_MPNG_OBJ, MNG_LC_START); +#endif + + if (pMPNG->iFramessize) + MNG_FREEX (pData, pMPNG->pFrames, pMPNG->iFramessize); + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + MNG_FREEX (pData, pMPNG, sizeof (mng_mpng_obj)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_MPNG_OBJ, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + return MNG_NOERROR; +#else + return mng_free_obj_general(pData, pObject); +#endif +} + +/* ************************************************************************** */ + +mng_retcode mng_process_mpng_obj (mng_datap pData, + mng_objectp pObject) +{ + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_MPNG_PROPOSAL */ + +/* ************************************************************************** */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ANG_PROPOSAL + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_CHUNKREADER +mng_retcode mng_create_ang_obj (mng_datap pData, + mng_uint32 iNumframes, + mng_uint32 iTickspersec, + mng_uint32 iNumplays, + mng_uint32 iTilewidth, + mng_uint32 iTileheight, + mng_uint8 iInterlace, + mng_uint8 iStillused) +#else +mng_retcode mng_create_ang_obj (mng_datap pData, + mng_ptr pEntry) +#endif +{ + mng_ang_objp pANG; + mng_ptr pTemp; + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANG_OBJ, MNG_LC_START); +#endif + +#ifdef MNG_OPTIMIZE_OBJCLEANUP + iRetcode = create_obj_general (pData, sizeof (mng_ang_obj), mng_free_ang_obj, + mng_process_ang_obj, &pTemp); + if (iRetcode) + return iRetcode; + pANG = (mng_ang_objp)pTemp; +#else + MNG_ALLOC (pData, pANG, sizeof (mng_ang_obj)); + + pANG->sHeader.fCleanup = mng_free_ang_obj; + pANG->sHeader.fProcess = mng_process_ang_obj; +#endif + +#ifndef MNG_OPTIMIZE_CHUNKREADER + pANG->iNumframes = iNumframes; + pANG->iTickspersec = iTickspersec; + pANG->iNumplays = iNumplays; + pANG->iTilewidth = iTilewidth; + pANG->iTileheight = iTileheight; + pANG->iInterlace = iInterlace; + pANG->iStillused = iStillused; +#else + pANG->iNumframes = ((mng_ahdrp)pEntry)->iNumframes; + pANG->iTickspersec = ((mng_ahdrp)pEntry)->iTickspersec; + pANG->iNumplays = ((mng_ahdrp)pEntry)->iNumplays; + pANG->iTilewidth = ((mng_ahdrp)pEntry)->iTilewidth; + pANG->iTileheight = ((mng_ahdrp)pEntry)->iTileheight; + pANG->iInterlace = ((mng_ahdrp)pEntry)->iInterlace; + pANG->iStillused = ((mng_ahdrp)pEntry)->iStillused; +#endif + + pData->pANG = pANG; + pData->eImagetype = mng_it_ang; + + iRetcode = mng_process_display_ang (pData); + if (iRetcode) + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CREATE_ANG_OBJ, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_free_ang_obj (mng_datap pData, + mng_objectp pObject) +{ + mng_ang_objp pANG = (mng_ang_objp)pObject; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANG_OBJ, MNG_LC_START); +#endif + + if (pANG->iTilessize) + MNG_FREEX (pData, pANG->pTiles, pANG->iTilessize); + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + MNG_FREEX (pData, pANG, sizeof (mng_ang_obj)); +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FREE_ANG_OBJ, MNG_LC_END); +#endif + +#ifndef MNG_OPTIMIZE_OBJCLEANUP + return MNG_NOERROR; +#else + return mng_free_obj_general(pData, pObject); +#endif +} + +/* ************************************************************************** */ + +mng_retcode mng_process_ang_obj (mng_datap pData, + mng_objectp pObject) +{ + mng_ang_objp pANG = (mng_ang_objp)pObject; + mng_uint8p pTile = (mng_uint8p)pANG->pTiles; + mng_retcode iRetcode; + mng_int32 iCnt, iMax; + mng_uint32 iTicks; + mng_int32 iXoffset, iYoffset; + mng_uint8 iSource; + mng_ani_loopp pLOOP; + mng_ani_endlp pENDL; + mng_ani_framp pFRAM; + mng_ani_movep pMOVE; + mng_ani_showp pSHOW; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANG_OBJ, MNG_LC_START); +#endif + + /* let's create the MNG animation directives from this */ + + iMax = pANG->iNumframes; + /* set up MNG impersonation */ + pData->iTicks = pANG->iTickspersec; + pData->iLayercount = iMax; + + if (pANG->iNumplays != 1) /* create a LOOP/ENDL pair ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + iRetcode = create_obj_general (pData, sizeof (mng_ani_loop), + mng_free_ani_loop, mng_process_ani_loop, + &((mng_ptr)pLOOP)); + if (iRetcode) + return iRetcode; +#else + MNG_ALLOC (pData, pLOOP, sizeof (mng_ani_loop)); + + pLOOP->sHeader.fCleanup = mng_free_ani_loop; + pLOOP->sHeader.fProcess = mng_process_ani_loop; +#endif + + pLOOP->iLevel = 1; + if (pANG->iNumplays) + pLOOP->iRepeatcount = pANG->iNumplays; + else + pLOOP->iRepeatcount = 0xFFFFFFFFl; + + mng_add_ani_object (pData, (mng_object_headerp)pLOOP); + } + + for (iCnt = 0; iCnt < iMax; iCnt++) + { + iTicks = mng_get_uint32 (pTile); + iXoffset = mng_get_int32 (pTile+4); + iYoffset = mng_get_int32 (pTile+8); + iSource = *(pTile+12); + +#ifdef MNG_OPTIMIZE_OBJCLEANUP + iRetcode = create_obj_general (pData, sizeof (mng_ani_fram), + mng_free_obj_general, mng_process_ani_fram, + &((mng_ptr)pFRAM)); + if (iRetcode) + return iRetcode; +#else + MNG_ALLOC (pData, pFRAM, sizeof (mng_ani_fram)); + + pFRAM->sHeader.fCleanup = mng_free_ani_fram; + pFRAM->sHeader.fProcess = mng_process_ani_fram; +#endif + + pFRAM->iFramemode = 4; + pFRAM->iChangedelay = 1; + pFRAM->iDelay = iTicks; + + mng_add_ani_object (pData, (mng_object_headerp)pFRAM); + + if (!iSource) + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + iRetcode = create_obj_general (pData, sizeof (mng_ani_move), + mng_free_obj_general, + mng_process_ani_move, + &((mng_ptr)pMOVE)); + if (iRetcode) + return iRetcode; +#else + MNG_ALLOC (pData, pMOVE, sizeof (mng_ani_move)); + + pMOVE->sHeader.fCleanup = mng_free_ani_move; + pMOVE->sHeader.fProcess = mng_process_ani_move; +#endif + + pMOVE->iFirstid = 1; + pMOVE->iLastid = 1; + pMOVE->iLocax = -iXoffset; + pMOVE->iLocay = -iYoffset; + + mng_add_ani_object (pData, (mng_object_headerp)pMOVE); + } + +#ifdef MNG_OPTIMIZE_OBJCLEANUP + iRetcode = create_obj_general (pData, sizeof (mng_ani_show), + mng_free_obj_general, mng_process_ani_show, + &((mng_ptr)pSHOW)); + if (iRetcode) + return iRetcode; +#else + MNG_ALLOC (pData, pSHOW, sizeof (mng_ani_show)); + + pSHOW->sHeader.fCleanup = mng_free_ani_show; + pSHOW->sHeader.fProcess = mng_process_ani_show; +#endif + + if (iSource) + pSHOW->iFirstid = 0; + else + pSHOW->iFirstid = 1; + pSHOW->iLastid = pSHOW->iFirstid; + + mng_add_ani_object (pData, (mng_object_headerp)pSHOW); + + pTile += sizeof(mng_adat_tile); + } + + if (pANG->iNumplays != 1) /* create a LOOP/ENDL pair ? */ + { +#ifdef MNG_OPTIMIZE_OBJCLEANUP + iRetcode = create_obj_general (pData, sizeof (mng_ani_endl), + mng_free_obj_general, mng_process_ani_endl, + &((mng_ptr)pENDL)); + if (iRetcode) + return iRetcode; +#else + MNG_ALLOC (pData, pENDL, sizeof (mng_ani_endl)); + + pENDL->sHeader.fCleanup = mng_free_ani_endl; + pENDL->sHeader.fProcess = mng_process_ani_endl; +#endif + + pENDL->iLevel = 1; + + mng_add_ani_object (pData, (mng_object_headerp)pENDL); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_ANG_OBJ, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_ANG_PROPOSAL */ + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_DISPLAY_PROCS */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + diff --git a/Source/LibMNG/libmng_pixels.c b/Source/LibMNG/libmng_pixels.c index 9990ee6..ce5637b 100644 --- a/Source/LibMNG/libmng_pixels.c +++ b/Source/LibMNG/libmng_pixels.c @@ -1,24610 +1,24610 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_pixels.c copyright (c) 2000-2005 G.Juyn * */ -/* * version : 1.0.10 * */ -/* * * */ -/* * purpose : Pixel-row management routines (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the pixel-row management routines * */ -/* * * */ -/* * the dual alpha-composing for RGBA/BGRA/etc output-canvas' * */ -/* * is based on the Note on Compositing chapter of the * */ -/* * DOH-3 draft, noted to me by Adam M. Costello * */ -/* * * */ -/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/11/2000 - G.Juyn * */ -/* * - added callback error-reporting support * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - changed trace to macro for callback error-reporting * */ -/* * * */ -/* * 0.5.2 - 05/22/2000 - G.Juyn * */ -/* * - added JNG support * */ -/* * 0.5.2 - 05/30/2000 - G.Juyn * */ -/* * - fixed minor bugs 16-bit pixel-handling * */ -/* * - added delta-image row-processing routines * */ -/* * 0.5.2 - 06/02/2000 - G.Juyn * */ -/* * - fixed endian support (hopefully) * */ -/* * 0.5.2 - 06/03/2000 - G.Juyn * */ -/* * - fixed makeup for Linux gcc compile * */ -/* * 0.5.2 - 06/05/2000 - G.Juyn * */ -/* * - implemented app bkgd restore routines * */ -/* * - implemented RGBA8, ARGB8, BGRA8 & ABGR8 display routines * */ -/* * - added support for RGB8_A8 canvasstyle * */ -/* * 0.5.2 - 06/09/2000 - G.Juyn * */ -/* * - fixed alpha-handling for alpha canvasstyles * */ -/* * * */ -/* * 0.5.3 - 06/16/2000 - G.Juyn * */ -/* * - changed progressive-display processing * */ -/* * 0.5.3 - 06/17/2000 - G.Juyn * */ -/* * - changed to support delta-images * */ -/* * - optimized some store_xxx routines * */ -/* * 0.5.3 - 06/20/2000 - G.Juyn * */ -/* * - fixed nasty bug with embedded PNG after delta-image * */ -/* * 0.5.3 - 06/24/2000 - G.Juyn * */ -/* * - fixed problem with 16-bit GA format * */ -/* * 0.5.3 - 06/25/2000 - G.Juyn * */ -/* * - fixed problem with cheap transparency for 4-bit gray * */ -/* * - fixed display_xxxx routines for interlaced images * */ -/* * 0.5.3 - 06/28/2000 - G.Juyn * */ -/* * - fixed compiler-warning for non-initialized iB variable * */ -/* * * */ -/* * 0.9.1 - 07/05/2000 - G.Juyn * */ -/* * - fixed mandatory BACK color to be opaque * */ -/* * * */ -/* * 0.9.2 - 07/31/2000 - G.Juyn * */ -/* * - B110547 - fixed bug in interlace code * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 0.9.3 - 08/20/2000 - G.Juyn * */ -/* * - fixed app-supplied background restore * */ -/* * 0.9.3 - 08/26/2000 - G.Juyn * */ -/* * - added MAGN chunk * */ -/* * 0.9.3 - 09/07/2000 - G.Juyn * */ -/* * - added support for new filter_types * */ -/* * 0.9.3 - 09/30/2000 - G.Juyn * */ -/* * - fixed MAGN rounding errors (thanks Matthias!) * */ -/* * 0.9.3 - 10/10/2000 - G.Juyn * */ -/* * - fixed alpha-blending for RGBA canvasstyle * */ -/* * 0.9.3 - 10/11/2000 - G.Juyn * */ -/* * - fixed alpha-blending for other alpha-canvasstyles * */ -/* * 0.9.3 - 10/16/2000 - G.Juyn * */ -/* * - added optional support for bKGD for PNG images * */ -/* * - added support for JDAA * */ -/* * 0.9.3 - 10/17/2000 - G.Juyn * */ -/* * - fixed support for bKGD * */ -/* * 0.9.3 - 10/19/2000 - G.Juyn * */ -/* * - implemented delayed delta-processing * */ -/* * 0.9.3 - 10/28/2000 - G.Juyn * */ -/* * - fixed tRNS processing for gray-image < 8-bits * */ -/* * * */ -/* * 0.9.4 - 12/16/2000 - G.Juyn * */ -/* * - fixed mixup of data- & function-pointers (thanks Dimitri)* */ -/* * 0.9.4 - 1/18/2001 - G.Juyn * */ -/* * - removed "old" MAGN methods 3 & 4 * */ -/* * - added "new" MAGN methods 3, 4 & 5 * */ -/* * - removed test filter-methods 1 & 65 * */ -/* * * */ -/* * 1.0.1 - 04/21/2001 - G.Juyn (code by G.Kelly) * */ -/* * - added BGRA8 canvas with premultiplied alpha * */ -/* * 1.0.1 - 04/25/2001 - G.Juyn * */ -/* * - moved mng_clear_cms to libmng_cms * */ -/* * * */ -/* * 1.0.2 - 06/25/2001 - G.Juyn * */ -/* * - added option to turn off progressive refresh * */ -/* * * */ -/* * 1.0.4 - 11/04/2001 - G.Juyn * */ -/* * - fixed possible compile-problem in cleanup_rowproc * */ -/* * 1.0.4 - 06/22/2002 - G.Juyn * */ -/* * - B558212 - off by one error * */ -/* * - MNG subimage alpha composite wrong for rgba8 images * */ -/* * * */ -/* * 1.0.5 - 08/07/2002 - G.Juyn * */ -/* * - added test-option for PNG filter method 193 (=no filter) * */ -/* * 1.0.5 - 08/15/2002 - G.Juyn * */ -/* * - completed PROM support * */ -/* * - completed delta-image support * */ -/* * 1.0.5 - 08/16/2002 - G.Juyn * */ -/* * - completed MAGN support (16-bit functions) * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * 1.0.5 - 09/19/2002 - G.Juyn * */ -/* * - optimized restore-background for bKGD cases * */ -/* * 1.0.5 - 09/20/2002 - G.Juyn * */ -/* * - finished support for BACK image & tiling * */ -/* * 1.0.5 - 09/22/2002 - G.Juyn * */ -/* * - added bgrx8 canvas (filler byte) * */ -/* * 1.0.5 - 09/23/2002 - G.Juyn * */ -/* * - added compose over/under routines for PAST processing * */ -/* * - added flip & tile routines for PAST processing * */ -/* * * */ -/* * 1.0.6 - 03/09/2003 - G.Juyn * */ -/* * - hiding 12-bit JPEG stuff * */ -/* * 1.0.6 - 05/11/2003 - Glenn RP * */ -/* * - added size-optimization COMPOSE routine usage * */ -/* * 1.0.6 - 05/11/2003 - G. Juyn * */ -/* * - added conditionals around canvas update routines * */ -/* * 1.0.6 - 05/25/2003 - Glenn RP * */ -/* * - added size-optimization DIV255B8 routine usage * */ -/* * 1.0.6 - 06/09/2003 - G. R-P * */ -/* * - added conditionals around 8-bit magn routines * */ -/* * 1.0.6 - 07/07/2003 - G. R-P * */ -/* * - removed conditionals around 8-bit magn routines * */ -/* * - added MNG_NO_16BIT_SUPPORT and MNG_NO_DELTA_PNG * */ -/* * conditionals * */ -/* * - reversed many loops to use decrementing counter * */ -/* * - combined init functions * */ -/* * - converted some switches to array references * */ -/* * 1.0.6 - 07/29/2003 - G.Juyn * */ -/* * - fixed duplicate for-loop * */ -/* * 1.0.6 - 07/29/2003 - G.R-P * */ -/* * - added SKIPCHUNK conditionals around PAST chunk support * */ -/* * - fixed "FOOTPRINT_COMPOSEIV" typo (now "FOOTPRINT_DIV") * */ -/* * 1.0.6 - 08/17/2003 - G.R-P * */ -/* * - added more conditionals around "promote" functions * */ -/* * * */ -/* * 1.0.7 - 11/27/2003 - R.A * */ -/* * - added CANVAS_RGB565 and CANVAS_BGR565 * */ -/* * 1.0.7 - 12/06/2003 - R.A * */ -/* * - added CANVAS_RGBA565 and CANVAS_BGRA565 * */ -/* * 1.0.7 - 01/25/2004 - J.S * */ -/* * - added premultiplied alpha canvas' for RGBA, ARGB, ABGR * */ -/* * 1.0.7 - 03/08/2004 - G.R-P * */ -/* * - added more conditionals around 16-bit-supporting code * */ -/* * 1.0.7 - 03/09/2004 - G.Juyn * */ -/* * - fixed bug in promote_g8_g8 with 16bit support off * */ -/* * 1.0.7 - 03/09/2004 - G.R-P * */ -/* * - more optimizations with 16bit support off * */ -/* * 1.0.7 - 03/10/2004 - G.Juyn * */ -/* * - fixed some warnings for 16bit optimizations * */ -/* * 1.0.7 - 03/21/2004 - G.Juyn * */ -/* * - fixed some 64-bit platform compiler warnings * */ -/* * * */ -/* * 1.0.8 - 06/20/2004 - G.Juyn * */ -/* * - some speed optimizations (thanks to John Stiles) * */ -/* * 1.0.8 - 08/01/2004 - G.Juyn * */ -/* * - added support for 3+byte pixelsize for JPEG's * */ -/* * * */ -/* * 1.0.9 - 10/10/2004 - G.R-P. * */ -/* * - added MNG_NO_1_2_4BIT_SUPPORT * */ -/* * 1.0.9 - 10/14/2004 - G.Juyn * */ -/* * - added bgr565_a8 canvas-style (thanks to J. Elvander) * */ -/* * 1.0.9 - 12/05/2004 - G.Juyn * */ -/* * - added LITTLEENDIAN/BIGENDIAN fixtures (thanks J.Stiles) * */ -/* * - fixed MNG_NO_1_2_4BIT_SUPPORT for TBBN1G04.PNG * */ -/* * 1.0.9 - 12/31/2004 - G.R-P. * */ -/* * - fixed warnings about C++ style (//) comments * */ -/* * * */ -/* * 1.0.10 - 07/06/2005 - G.R-P. * */ -/* * - added MORE MNG_NO_1_2_4BIT_SUPPORT * */ -/* * 1.0.10 - 10/06/2005 - G.R-P. * */ -/* * - alloc more memory for MNG_NO_1_2_4BIT_SUPPORT * */ -/* * 1.0.10 - 12/07/2005 - G.R-P. * */ -/* * - optimized footprint of 16bit support * */ -/* * 1.0.10 - 03/07/2006 - (thanks to W. Manthey) * */ -/* * - added CANVAS_RGB555 and CANVAS_BGR555 * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_objects.h" -#include "libmng_object_prc.h" -#include "libmng_memory.h" -#include "libmng_cms.h" -#include "libmng_filter.h" -#include "libmng_pixels.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_DISPLAY_PROCS - -/* TODO: magnification & canvas-positioning/-clipping */ - -/* TODO: major optimization of pixel-loops by using assembler (?) */ - -/* ************************************************************************** */ -/* * * */ -/* * Interlace tables * */ -/* * * */ -/* ************************************************************************** */ - -MNG_LOCAL mng_uint32 const interlace_row [7] = { 0, 0, 4, 0, 2, 0, 1 }; -MNG_LOCAL mng_uint32 const interlace_rowskip [7] = { 8, 8, 8, 4, 4, 2, 2 }; -MNG_LOCAL mng_uint32 const interlace_col [7] = { 0, 4, 0, 2, 0, 1, 0 }; -MNG_LOCAL mng_uint32 const interlace_colskip [7] = { 8, 8, 4, 4, 2, 2, 1 }; -MNG_LOCAL mng_uint32 const interlace_roundoff [7] = { 7, 7, 3, 3, 1, 1, 0 }; -MNG_LOCAL mng_uint32 const interlace_divider [7] = { 3, 3, 2, 2, 1, 1, 0 }; - -/* ************************************************************************** */ -/* * * */ -/* * Alpha composing macros * */ -/* * the code below is slightly modified from the libpng package * */ -/* * the original was last optimized by Greg Roelofs & Mark Adler * */ -/* * * */ -/* ************************************************************************** */ - -#define MNG_COMPOSE8(RET,FG,ALPHA,BG) { \ - mng_uint16 iH = (mng_uint16)((mng_uint16)(FG) * (mng_uint16)(ALPHA) \ - + (mng_uint16)(BG)*(mng_uint16)(255 - \ - (mng_uint16)(ALPHA)) + (mng_uint16)128); \ - (RET) = (mng_uint8)((iH + (iH >> 8)) >> 8); } - -#define MNG_COMPOSE16(RET,FG,ALPHA,BG) { \ - mng_uint32 iH = (mng_uint32)((mng_uint32)(FG) * (mng_uint32)(ALPHA) \ - + (mng_uint32)(BG)*(mng_uint32)(65535L - \ - (mng_uint32)(ALPHA)) + (mng_uint32)32768L); \ - (RET) = (mng_uint16)((iH + (iH >> 16)) >> 16); } - -/* ************************************************************************** */ -/* * * */ -/* * Alpha blending macros * */ -/* * this code is based on Adam Costello's "Note on Compositing" from the * */ -/* * mng-list which gives the following formula: * */ -/* * * */ -/* * top pixel = (Rt, Gt, Bt, At) * */ -/* * bottom pixel = (Rb, Gb, Bb, Ab) * */ -/* * composite pixel = (Rc, Gc, Bc, Ac) * */ -/* * * */ -/* * all values in the range 0..1 * */ -/* * * */ -/* * Ac = 1 - (1 - At)(1 - Ab) * */ -/* * s = At / Ac * */ -/* * t = (1 - At) Ab / Ac * */ -/* * Rc = s Rt + t Rb * */ -/* * Gc = s Gt + t Gb * */ -/* * Bc = s Bt + t Bb * */ -/* * * */ -/* * (I just hope I coded it correctly in integer arithmetic...) * */ -/* * * */ -/* ************************************************************************** */ - -#define MNG_BLEND8(RT, GT, BT, AT, RB, GB, BB, AB, RC, GC, BC, AC) { \ - mng_uint32 S, T; \ - (AC) = (mng_uint8)((mng_uint32)255 - \ - ((((mng_uint32)255 - (mng_uint32)(AT)) * \ - ((mng_uint32)255 - (mng_uint32)(AB)) ) >> 8)); \ - S = (mng_uint32)(((mng_uint32)(AT) << 8) / \ - (mng_uint32)(AC)); \ - T = (mng_uint32)(((mng_uint32)255 - (mng_uint32)(AT)) * \ - (mng_uint32)(AB) / (mng_uint32)(AC)); \ - (RC) = (mng_uint8)((S * (mng_uint32)(RT) + \ - T * (mng_uint32)(RB) + (mng_uint32)127) >> 8); \ - (GC) = (mng_uint8)((S * (mng_uint32)(GT) + \ - T * (mng_uint32)(GB) + (mng_uint32)127) >> 8); \ - (BC) = (mng_uint8)((S * (mng_uint32)(BT) + \ - T * (mng_uint32)(BB) + (mng_uint32)127) >> 8); } - -#define MNG_BLEND16(RT, GT, BT, AT, RB, GB, BB, AB, RC, GC, BC, AC) { \ - mng_uint32 S, T; \ - (AC) = (mng_uint16)((mng_uint32)65535 - \ - ((((mng_uint32)65535 - (mng_uint32)(AT)) * \ - ((mng_uint32)65535 - (mng_uint32)(AB)) ) >> 16)); \ - S = (mng_uint32)(((mng_uint32)(AT) << 16) / \ - (mng_uint32)(AC)); \ - T = (mng_uint32)(((mng_uint32)65535 - (mng_uint32)(AT)) * \ - (mng_uint32)(AB) / (mng_uint32)(AC)); \ - (RC) = (mng_uint16)((S * (mng_uint32)(RT) + \ - T * (mng_uint32)(RB) + (mng_uint32)32767) >> 16); \ - (GC) = (mng_uint16)((S * (mng_uint32)(GT) + \ - T * (mng_uint32)(GB) + (mng_uint32)32767) >> 16); \ - (BC) = (mng_uint16)((S * (mng_uint32)(BT) + \ - T * (mng_uint32)(BB) + (mng_uint32)32767) >> 16); } - -/* ************************************************************************** */ - -/* note a good optimizing compiler will optimize this */ -#define DIV255B8(x) (mng_uint8)(((x) + 127) / 255) -#define DIV255B16(x) (mng_uint16)(((x) + 32767) / 65535) - -/* ************************************************************************** */ -/* * * */ -/* * Progressive display check - checks to see if progressive display is * */ -/* * in order & indicates so * */ -/* * * */ -/* * The routine is called after a call to one of the display_xxx routines * */ -/* * if appropriate * */ -/* * * */ -/* * The refresh is warrented in the read_chunk routine (mng_read.c) * */ -/* * and only during read&display processing, since there's not much point * */ -/* * doing it from memory! * */ -/* * * */ -/* ************************************************************************** */ - -mng_retcode mng_display_progressive_check (mng_datap pData) -{ - if ((pData->bDoProgressive) && /* need progressive display? */ - ((pData->eImagetype != mng_it_mng) || (pData->iDataheight > 300)) && - (pData->iDestb - pData->iDestt > 50) && (!pData->pCurraniobj)) - { - mng_int32 iC = pData->iRow + pData->iDestt - pData->iSourcet; - - if (iC % 20 == 0) /* every 20th line */ - pData->bNeedrefresh = MNG_TRUE; - - } - - return MNG_NOERROR; -} - -/* ************************************************************************** */ -/* * * */ -/* * Display routines - convert rowdata (which is already color-corrected) * */ -/* * to the output canvas, respecting the opacity information * */ -/* * * */ -/* ************************************************************************** */ - -MNG_LOCAL void check_update_region (mng_datap pData) -{ /* determine actual canvas row */ - mng_int32 iRow = pData->iRow + pData->iDestt - pData->iSourcet; - /* check for change in update-region */ - if ((pData->iDestl < (mng_int32)pData->iUpdateleft) || (pData->iUpdateright == 0)) - pData->iUpdateleft = pData->iDestl; - - if (pData->iDestr > (mng_int32)pData->iUpdateright) - pData->iUpdateright = pData->iDestr; - - if ((iRow < (mng_int32)pData->iUpdatetop) || (pData->iUpdatebottom == 0)) - pData->iUpdatetop = iRow; - - if (iRow+1 > (mng_int32)pData->iUpdatebottom) - pData->iUpdatebottom = iRow+1; - - return; -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_RGB8 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_rgb8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint8 iA8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *(pDataline+4); - - pScanline += (pData->iColinc * 3); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - - pScanline += (pData->iColinc * 3); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA16 = mng_get_uint16 (pDataline+6); - - if (iA16) /* any opacity at all ? */ - { - if (iA16 == 0xFFFF) /* fully opaque ? */ - { /* scale down by dropping the LSB */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *(pDataline+4); - } - else - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - iBGr16 = (mng_uint16)(*pScanline ); - iBGg16 = (mng_uint16)(*(pScanline+1)); - iBGb16 = (mng_uint16)(*(pScanline+2)); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iFGr16 >> 8); - *(pScanline+1) = (mng_uint8)(iFGg16 >> 8); - *(pScanline+2) = (mng_uint8)(iFGb16 >> 8); - } - } - - pScanline += (pData->iColinc * 3); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - } - else - { /* do alpha composing */ - MNG_COMPOSE8 (*pScanline, *pDataline, iA8, *pScanline ); - MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iA8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *(pDataline+2), iA8, *(pScanline+2)); - } - } - - pScanline += (pData->iColinc * 3); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_rgb8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGg16; - mng_uint16 iBGg16; - mng_uint8 iA8; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+iBps); - *(pScanline+2) = *(pDataline+2*iBps); - - pScanline += (pData->iColinc * 3); - pDataline += 4*iBps; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA16 = mng_get_uint16 (pDataline+6); - - if (iA16) /* any opacity at all ? */ - { - if (iA16 == 0xFFFF) /* fully opaque ? */ - { /* scale down by dropping the LSB */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *(pDataline+4); - } - else - { /* get the proper values */ - int i; - for (i=2; i >= 0; i--) - { - iFGg16 = mng_get_uint16 (pDataline+i+i); - /* scale background up */ - iBGg16 = (mng_uint16)(*(pScanline+i)); - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - /* now compose */ - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - /* and return the composed values */ - *(pScanline+i) = (mng_uint8)(iFGg16 >> 8); - } - } - } - - pScanline += (pData->iColinc * 3); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - } - else - { /* do alpha composing */ - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i), *(pDataline+i), iA8, *(pScanline+i)); - } - } - } - - pScanline += (pData->iColinc * 3); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_rgb8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iA8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - - pScanline += (pData->iColinc * 3); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - } - else - { /* do alpha composing */ -#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i), *(pDataline+i), iA8, *(pScanline+i)); - } -#else - MNG_COMPOSE8 (*pScanline, *pDataline, iA8, *pScanline ); - MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iA8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *(pDataline+2), iA8, *(pScanline+2)); -#endif - } - } - - pScanline += (pData->iColinc * 3); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_RGB8 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_RGBA8 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_rgba8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint16 iFGa16, iBGa16, iCa16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *(pDataline+4); - *(pScanline+3) = *(pDataline+6); - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - *(pScanline+3) = *(pDataline+3); - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - iFGa16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*(pScanline+3)); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* plain copy it */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *(pDataline+4); - *(pScanline+3) = *(pDataline+6); - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - iBGr16 = (mng_uint16)(*pScanline ); - iBGg16 = (mng_uint16)(*(pScanline+1)); - iBGb16 = (mng_uint16)(*(pScanline+2)); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iFGr16 >> 8); - *(pScanline+1) = (mng_uint8)(iFGg16 >> 8); - *(pScanline+2) = (mng_uint8)(iFGb16 >> 8); - /* alpha remains fully opaque !!! */ - } - else - { /* scale background up */ - iBGr16 = (mng_uint16)(*pScanline ); - iBGg16 = (mng_uint16)(*(pScanline+1)); - iBGb16 = (mng_uint16)(*(pScanline+2)); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iCr16 >> 8); - *(pScanline+1) = (mng_uint8)(iCg16 >> 8); - *(pScanline+2) = (mng_uint8)(iCb16 >> 8); - *(pScanline+3) = (mng_uint8)(iCa16 >> 8); - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *(pScanline+3); - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - *(pScanline+3) = *(pDataline+3); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ - MNG_COMPOSE8 (*pScanline, *pDataline, iFGa8, *pScanline ); - MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iFGa8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *(pDataline+2), iFGa8, *(pScanline+2)); - /* alpha remains fully opaque !!! */ - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCr8; - *(pScanline+1) = iCg8; - *(pScanline+2) = iCb8; - *(pScanline+3) = iCa8; - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_rgba8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint16 iFGa16, iBGa16, iCa16; - mng_uint16 iFGg16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16; - mng_uint8 iCr8, iCg8, iCb8; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+iBps); - *(pScanline+2) = *(pDataline+2*iBps); - *(pScanline+3) = *(pDataline+3*iBps); - - pScanline += (pData->iColinc << 2); - pDataline += 4*iBps; - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - iFGa16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*(pScanline+3)); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* plain copy it */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *(pDataline+4); - *(pScanline+3) = *(pDataline+6); - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* get the proper values */ - int i; - for (i=2; i >= 0; i--) - { - iFGg16 = mng_get_uint16 (pDataline+i+i); - /* scale background up */ - iBGg16 = (mng_uint16)(*(pScanline+i)); - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - /* now compose */ - MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); - /* and return the composed values */ - *(pScanline+i) = (mng_uint8)(iFGg16 >> 8); - /* alpha remains fully opaque !!! */ - } - } - else - { /* scale background up */ - iBGr16 = (mng_uint16)(*pScanline ); - iBGg16 = (mng_uint16)(*(pScanline+1)); - iBGb16 = (mng_uint16)(*(pScanline+2)); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iCr16 >> 8); - *(pScanline+1) = (mng_uint8)(iCg16 >> 8); - *(pScanline+2) = (mng_uint8)(iCb16 >> 8); - *(pScanline+3) = (mng_uint8)(iCa16 >> 8); - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *(pScanline+3); - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - *(pScanline+3) = *(pDataline+3); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i), *(pDataline+i), iFGa8, *(pScanline+i)); - } - /* alpha remains fully opaque !!! */ - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCr8; - *(pScanline+1) = iCg8; - *(pScanline+2) = iCb8; - *(pScanline+3) = iCa8; - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_rgba8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - *(pScanline+3) = *(pDataline+3); - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *(pScanline+3); - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - *(pScanline+3) = *(pDataline+3); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ -#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i), *(pDataline+i), iFGa8, *(pScanline+i)); - } -#else - MNG_COMPOSE8 (*pScanline, *pDataline, iFGa8, *pScanline ); - MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iFGa8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *(pDataline+2), iFGa8, *(pScanline+2)); -#endif - /* alpha remains fully opaque !!! */ - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCr8; - *(pScanline+1) = iCg8; - *(pScanline+2) = iCb8; - *(pScanline+3) = iCa8; - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_RGBA8 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_RGBA8_PM -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_rgba8_pm (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint32 s, t; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8_PM, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - if ((s = pDataline[6]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = pDataline[0]; - pScanline[1] = pDataline[2]; - pScanline[2] = pDataline[4]; - pScanline[3] = 255; - } - else - { -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - int i; - for (i=2; i >= 0; i--) - { - pScanline[2-i] = DIV255B8(s * pDataline[4-i-i]); - } -#else - pScanline[0] = DIV255B8(s * pDataline[0]); - pScanline[1] = DIV255B8(s * pDataline[2]); - pScanline[2] = DIV255B8(s * pDataline[4]); -#endif - pScanline[3] = (mng_uint8)s; - } - } - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values and premultiply */ - if ((s = pDataline[3]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { -#ifdef MNG_BIGENDIAN_SUPPORTED - *(mng_uint32*)pScanline = (*(mng_uint32*)pDataline) | 0x000000FF; -#else - pScanline[0] = pDataline[0]; - pScanline[1] = pDataline[1]; - pScanline[2] = pDataline[2]; - pScanline[3] = 255; -#endif - } - else - { -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - int i; - for (i=2; i >= 0; i--) - { - pScanline[2-i] = DIV255B8(s * pDataline[2-i]); - } -#else - pScanline[0] = DIV255B8(s * pDataline[0]); - pScanline[1] = DIV255B8(s * pDataline[1]); - pScanline[2] = DIV255B8(s * pDataline[2]); -#endif - pScanline[3] = (mng_uint8)s; - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - if ((s = pDataline[6]) != 0) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if (s == 255) - { /* plain copy it */ - pScanline[0] = pDataline[0]; - pScanline[1] = pDataline[2]; - pScanline[2] = pDataline[4]; - pScanline[3] = 255; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[2-i] = DIV255B8(s * pDataline[4-i-i] + t * - pScanline[2-i]); - } - } -#else - pScanline[0] = DIV255B8(s * pDataline[0] + t * pScanline[0]); - pScanline[1] = DIV255B8(s * pDataline[2] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[4] + t * pScanline[2]); -#endif - pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - if ((s = pDataline[3]) != 0) /* any opacity at all ? */ - { /* fully opaque ? */ - if (s == 255) - { /* then simply copy the values */ -#ifdef MNG_BIGENDIAN_SUPPORTED - *(mng_uint32*)pScanline = (*(mng_uint32*)pDataline) | 0x000000FF; -#else - pScanline[0] = pDataline[0]; - pScanline[1] = pDataline[1]; - pScanline[2] = pDataline[2]; - pScanline[3] = 255; -#endif - } - else - { /* now blend (premultiplied) */ - t = 255 - s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[2-i] = DIV255B8(s * pDataline[2-i] + t * - pScanline[2-i]); - } - } -#else - pScanline[0] = DIV255B8(s * pDataline[0] + t * pScanline[0]); - pScanline[1] = DIV255B8(s * pDataline[1] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[2] + t * pScanline[2]); -#endif - pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8_PM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_rgba8_pm (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint32 s, t; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8_PM, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - if ((s = pDataline[6]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = pDataline[0]; - pScanline[1] = pDataline[2]; - pScanline[2] = pDataline[4]; - pScanline[3] = 255; - } - else - { -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - int i; - for (i=2; i >= 0; i--) - { - pScanline[2-i] = DIV255B8(s * pDataline[4-i-i]); - } -#else - pScanline[0] = DIV255B8(s * pDataline[0]); - pScanline[1] = DIV255B8(s * pDataline[2]); - pScanline[2] = DIV255B8(s * pDataline[4]); -#endif - pScanline[3] = (mng_uint8)s; - } - } - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values and premultiply */ - if ((s = pDataline[3]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { -#ifdef MNG_BIGENDIAN_SUPPORTED - *(mng_uint32*)pScanline = (*(mng_uint32*)pDataline) | 0x000000FF; -#else - pScanline[0] = pDataline[0]; - pScanline[1] = pDataline[1]; - pScanline[2] = pDataline[2]; - pScanline[3] = 255; -#endif - } - else - { -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - int i; - for (i=2; i >= 0; i--) - { - pScanline[2-i] = DIV255B8(s * pDataline[2-i]); - } -#else - pScanline[0] = DIV255B8(s * pDataline[0]); - pScanline[1] = DIV255B8(s * pDataline[1]); - pScanline[2] = DIV255B8(s * pDataline[2]); -#endif - pScanline[3] = (mng_uint8)s; - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - if ((s = pDataline[6]) != 0) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if (s == 255) - { /* plain copy it */ - pScanline[0] = pDataline[0]; - pScanline[1] = pDataline[2]; - pScanline[2] = pDataline[4]; - pScanline[3] = 255; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[2-i] = DIV255B8(s * pDataline[4-i-i] + t * - pScanline[2-i]); - } - } -#else - pScanline[0] = DIV255B8(s * pDataline[0] + t * pScanline[0]); - pScanline[1] = DIV255B8(s * pDataline[2] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[4] + t * pScanline[2]); -#endif - pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - if ((s = pDataline[3]) != 0) /* any opacity at all ? */ - { /* fully opaque ? */ - if (s == 255) - { /* then simply copy the values */ -#ifdef MNG_BIGENDIAN_SUPPORTED - *(mng_uint32*)pScanline = (*(mng_uint32*)pDataline) | 0x000000FF; -#else - pScanline[0] = pDataline[0]; - pScanline[1] = pDataline[1]; - pScanline[2] = pDataline[2]; - pScanline[3] = 255; -#endif - } - else - { /* now blend (premultiplied) */ - t = 255 - s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[2-i] = DIV255B8(s * pDataline[2-i] + t * - pScanline[2-i]); - } - } -#else - pScanline[0] = DIV255B8(s * pDataline[0] + t * pScanline[0]); - pScanline[1] = DIV255B8(s * pDataline[1] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[2] + t * pScanline[2]); -#endif - pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8_PM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_rgba8_pm (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint32 s, t; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8_PM, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values and premultiply */ - if ((s = pDataline[3]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { -#ifdef MNG_BIGENDIAN_SUPPORTED - *(mng_uint32*)pScanline = (*(mng_uint32*)pDataline) | 0x000000FF; -#else - pScanline[0] = pDataline[0]; - pScanline[1] = pDataline[1]; - pScanline[2] = pDataline[2]; - pScanline[3] = 255; -#endif - } - else - { -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - int i; - for (i=2; i >= 0; i--) - { - pScanline[2-i] = DIV255B8(s * pDataline[2-i]); - } -#else - pScanline[0] = DIV255B8(s * pDataline[0]); - pScanline[1] = DIV255B8(s * pDataline[1]); - pScanline[2] = DIV255B8(s * pDataline[2]); -#endif - pScanline[3] = (mng_uint8)s; - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - if ((s = pDataline[3]) != 0) /* any opacity at all ? */ - { /* fully opaque ? */ - if (s == 255) - { /* then simply copy the values */ -#ifdef MNG_BIGENDIAN_SUPPORTED - *(mng_uint32*)pScanline = (*(mng_uint32*)pDataline) | 0x000000FF; -#else - pScanline[0] = pDataline[0]; - pScanline[1] = pDataline[1]; - pScanline[2] = pDataline[2]; - pScanline[3] = 255; -#endif - } - else - { /* now blend (premultiplied) */ - t = 255 - s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[2-i] = DIV255B8(s * pDataline[2-i] + t * - pScanline[2-i]); - } - } -#else - pScanline[0] = DIV255B8(s * pDataline[0] + t * pScanline[0]); - pScanline[1] = DIV255B8(s * pDataline[1] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[2] + t * pScanline[2]); -#endif - pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8_PM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_RGBA8_PM */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_ARGB8 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_argb8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint16 iFGa16, iBGa16, iCa16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8, MNG_LC_START); -#endif - - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *(pDataline+6); - *(pScanline+1) = *pDataline; - *(pScanline+2) = *(pDataline+2); - *(pScanline+3) = *(pDataline+4); - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *(pDataline+3); - *(pScanline+1) = *pDataline; - *(pScanline+2) = *(pDataline+1); - *(pScanline+3) = *(pDataline+2); - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - iFGa16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*pScanline); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* plain copy it */ - *pScanline = *(pDataline+6); - *(pScanline+1) = *pDataline; - *(pScanline+2) = *(pDataline+2); - *(pScanline+3) = *(pDataline+4); - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - iBGr16 = (mng_uint16)(*(pScanline+1)); - iBGg16 = (mng_uint16)(*(pScanline+2)); - iBGb16 = (mng_uint16)(*(pScanline+3)); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); - /* and return the composed values */ - /* alpha remains fully opaque !!! */ - *(pScanline+1) = (mng_uint8)(iFGr16 >> 8); - *(pScanline+2) = (mng_uint8)(iFGg16 >> 8); - *(pScanline+3) = (mng_uint8)(iFGb16 >> 8); - } - else - { /* scale background up */ - iBGr16 = (mng_uint16)(*(pScanline+1)); - iBGg16 = (mng_uint16)(*(pScanline+2)); - iBGb16 = (mng_uint16)(*(pScanline+3)); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iCa16 >> 8); - *(pScanline+1) = (mng_uint8)(iCr16 >> 8); - *(pScanline+2) = (mng_uint8)(iCg16 >> 8); - *(pScanline+3) = (mng_uint8)(iCb16 >> 8); - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *pScanline; - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *(pDataline+3); - *(pScanline+1) = *pDataline; - *(pScanline+2) = *(pDataline+1); - *(pScanline+3) = *(pDataline+2); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do simple alpha composing */ - /* alpha itself remains fully opaque !!! */ - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *(pScanline+1), *(pScanline+2), *(pScanline+3), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCa8; - *(pScanline+1) = iCr8; - *(pScanline+2) = iCg8; - *(pScanline+3) = iCb8; - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_argb8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint16 iFGa16, iBGa16, iCa16; - mng_uint16 iFGg16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16; - mng_uint8 iCr8, iCg8, iCb8; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *(pDataline+3*iBps); - *(pScanline+1) = *pDataline; - *(pScanline+2) = *(pDataline+iBps); - *(pScanline+3) = *(pDataline+2*iBps); - - pScanline += (pData->iColinc << 2); - pDataline += 4*iBps; - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - iFGa16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*pScanline); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* plain copy it */ - *pScanline = *(pDataline+6); - *(pScanline+1) = *pDataline; - *(pScanline+2) = *(pDataline+2); - *(pScanline+3) = *(pDataline+4); - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* get the proper values */ - int i; - for (i=2; i >= 0; i--) - { - iFGg16 = mng_get_uint16 (pDataline+i+i); - /* scale background up */ - iBGg16 = (mng_uint16)(*(pScanline+i+1)); - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - /* now compose */ - MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); - /* and return the composed values */ - /* alpha remains fully opaque !!! */ - *(pScanline+i+1) = (mng_uint8)(iFGg16 >> 8); - } - } - else - { /* scale background up */ - iBGr16 = (mng_uint16)(*(pScanline+1)); - iBGg16 = (mng_uint16)(*(pScanline+2)); - iBGb16 = (mng_uint16)(*(pScanline+3)); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iCa16 >> 8); - *(pScanline+1) = (mng_uint8)(iCr16 >> 8); - *(pScanline+2) = (mng_uint8)(iCg16 >> 8); - *(pScanline+3) = (mng_uint8)(iCb16 >> 8); - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *pScanline; - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *(pDataline+3); - *(pScanline+1) = *pDataline; - *(pScanline+2) = *(pDataline+1); - *(pScanline+3) = *(pDataline+2); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do simple alpha composing */ - /* alpha itself remains fully opaque !!! */ - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i+1), *(pDataline+i), iFGa8, *(pScanline+i+1)); - } - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *(pScanline+1), *(pScanline+2), *(pScanline+3), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCa8; - *(pScanline+1) = iCr8; - *(pScanline+2) = iCg8; - *(pScanline+3) = iCb8; - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_argb8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8, MNG_LC_START); -#endif - - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *(pDataline+3); - *(pScanline+1) = *pDataline; - *(pScanline+2) = *(pDataline+1); - *(pScanline+3) = *(pDataline+2); - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *pScanline; - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *(pDataline+3); - *(pScanline+1) = *pDataline; - *(pScanline+2) = *(pDataline+1); - *(pScanline+3) = *(pDataline+2); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do simple alpha composing */ - /* alpha itself remains fully opaque !!! */ -#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i+1), *(pDataline+i), iFGa8, *(pScanline+i+1)); - } -#else - MNG_COMPOSE8 (*(pScanline+1), *pDataline, iFGa8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *(pDataline+1), iFGa8, *(pScanline+2)); - MNG_COMPOSE8 (*(pScanline+3), *(pDataline+2), iFGa8, *(pScanline+3)); -#endif - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *(pScanline+1), *(pScanline+2), *(pScanline+3), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCa8; - *(pScanline+1) = iCr8; - *(pScanline+2) = iCg8; - *(pScanline+3) = iCb8; - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_ARGB8 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_ARGB8_PM -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_argb8_pm (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint32 s, t; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8_PM, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - if ((s = pDataline[6]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = 255; - pScanline[1] = pDataline[0]; - pScanline[2] = pDataline[2]; - pScanline[3] = pDataline[4]; - } - else - { - pScanline[0] = (mng_uint8)s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[3-i] = DIV255B8(s * pDataline[4-i-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[0]); - pScanline[2] = DIV255B8(s * pDataline[2]); - pScanline[3] = DIV255B8(s * pDataline[4]); -#endif - } - } - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values and premultiply */ - if ((s = pDataline[3]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = 255; - pScanline[1] = pDataline[0]; - pScanline[2] = pDataline[1]; - pScanline[3] = pDataline[2]; - } - else - { - pScanline[0] = (mng_uint8)s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[3-i] = DIV255B8(s * pDataline[2-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[0]); - pScanline[2] = DIV255B8(s * pDataline[1]); - pScanline[3] = DIV255B8(s * pDataline[2]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - if ((s = pDataline[6]) != 0) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if (s == 255) - { /* plain copy it */ - pScanline[0] = 255; - pScanline[1] = pDataline[0]; - pScanline[2] = pDataline[2]; - pScanline[3] = pDataline[4]; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; - pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[3-i] = DIV255B8(s * pDataline[4-i-i] + t * - pScanline[3-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[0] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[2] + t * pScanline[2]); - pScanline[3] = DIV255B8(s * pDataline[4] + t * pScanline[3]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - if ((s = pDataline[3]) != 0) /* any opacity at all ? */ - { /* fully opaque ? */ - if (s == 255) - { /* then simply copy the values */ - pScanline[0] = 255; - pScanline[1] = pDataline[0]; - pScanline[2] = pDataline[1]; - pScanline[3] = pDataline[2]; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; - pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[3-i] = DIV255B8(s * pDataline[2-i] + t * - pScanline[3-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[0] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[1] + t * pScanline[2]); - pScanline[3] = DIV255B8(s * pDataline[2] + t * pScanline[3]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8_PM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_argb8_pm (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint32 s, t; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8_PM, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - if ((s = pDataline[6]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = 255; - pScanline[1] = pDataline[0]; - pScanline[2] = pDataline[2]; - pScanline[3] = pDataline[4]; - } - else - { - pScanline[0] = (mng_uint8)s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[3-i] = DIV255B8(s * pDataline[4-i-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[0]); - pScanline[2] = DIV255B8(s * pDataline[2]); - pScanline[3] = DIV255B8(s * pDataline[4]); -#endif - } - } - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values and premultiply */ - if ((s = pDataline[3]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = 255; - pScanline[1] = pDataline[0]; - pScanline[2] = pDataline[1]; - pScanline[3] = pDataline[2]; - } - else - { - pScanline[0] = (mng_uint8)s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[3-i] = DIV255B8(s * pDataline[2-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[0]); - pScanline[2] = DIV255B8(s * pDataline[1]); - pScanline[3] = DIV255B8(s * pDataline[2]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - if ((s = pDataline[6]) != 0) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if (s == 255) - { /* plain copy it */ - pScanline[0] = 255; - pScanline[1] = pDataline[0]; - pScanline[2] = pDataline[2]; - pScanline[3] = pDataline[4]; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; - pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[3-i] = DIV255B8(s * pDataline[4-i-i] + t * - pScanline[3-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[0] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[2] + t * pScanline[2]); - pScanline[3] = DIV255B8(s * pDataline[4] + t * pScanline[3]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - if ((s = pDataline[3]) != 0) /* any opacity at all ? */ - { /* fully opaque ? */ - if (s == 255) - { /* then simply copy the values */ - pScanline[0] = 255; - pScanline[1] = pDataline[0]; - pScanline[2] = pDataline[1]; - pScanline[3] = pDataline[2]; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; - pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[3-i] = DIV255B8(s * pDataline[2-i] + t * - pScanline[3-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[0] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[1] + t * pScanline[2]); - pScanline[3] = DIV255B8(s * pDataline[2] + t * pScanline[3]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8_PM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_argb8_pm (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint32 s, t; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8_PM, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values and premultiply */ - if ((s = pDataline[3]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = 255; - pScanline[1] = pDataline[0]; - pScanline[2] = pDataline[1]; - pScanline[3] = pDataline[2]; - } - else - { - pScanline[0] = (mng_uint8)s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[3-i] = DIV255B8(s * pDataline[2-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[0]); - pScanline[2] = DIV255B8(s * pDataline[1]); - pScanline[3] = DIV255B8(s * pDataline[2]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - if ((s = pDataline[3]) != 0) /* any opacity at all ? */ - { /* fully opaque ? */ - if (s == 255) - { /* then simply copy the values */ - pScanline[0] = 255; - pScanline[1] = pDataline[0]; - pScanline[2] = pDataline[1]; - pScanline[3] = pDataline[2]; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; - pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[3-i] = DIV255B8(s * pDataline[2-i] + t * - pScanline[3-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[0] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[1] + t * pScanline[2]); - pScanline[3] = DIV255B8(s * pDataline[2] + t * pScanline[3]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8_PM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_ARGB8_PM */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_RGB8_A8 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_rgb8_a8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pAlphaline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint16 iFGa16, iBGa16, iCa16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8_A8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination rows */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - pAlphaline = (mng_uint8p)pData->fGetalphaline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination rows starting-point */ - pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); - pAlphaline = pAlphaline + pData->iCol + pData->iDestl; - - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *(pDataline+4); - *pAlphaline = *(pDataline+6); - - pScanline += (pData->iColinc * 3); - pAlphaline += pData->iColinc; - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - *pAlphaline = *(pDataline+3); - - pScanline += (pData->iColinc * 3); - pAlphaline += pData->iColinc; - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - iFGa16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*pAlphaline); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* plain copy it */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *(pDataline+4); - *pAlphaline = *(pDataline+6); - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - iBGr16 = (mng_uint16)(*pScanline ); - iBGg16 = (mng_uint16)(*(pScanline+1)); - iBGb16 = (mng_uint16)(*(pScanline+2)); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iFGr16 >> 8); - *(pScanline+1) = (mng_uint8)(iFGg16 >> 8); - *(pScanline+2) = (mng_uint8)(iFGb16 >> 8); - /* alpha remains fully opaque !!! */ - } - else - { /* scale background up */ - iBGr16 = (mng_uint16)(*pScanline ); - iBGg16 = (mng_uint16)(*(pScanline+1)); - iBGb16 = (mng_uint16)(*(pScanline+2)); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iCr16 >> 8); - *(pScanline+1) = (mng_uint8)(iCg16 >> 8); - *(pScanline+2) = (mng_uint8)(iCb16 >> 8); - *pAlphaline = (mng_uint8)(iCa16 >> 8); - } - } - } - - pScanline += (pData->iColinc * 3); - pAlphaline += pData->iColinc; - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *pAlphaline; - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - *pAlphaline = *(pDataline+3); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ - MNG_COMPOSE8 (*pScanline, *pDataline, iFGa8, *pScanline ); - MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iFGa8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *(pDataline+2), iFGa8, *(pScanline+2)); - /* alpha remains fully opaque !!! */ - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCr8; - *(pScanline+1) = iCg8; - *(pScanline+2) = iCb8; - *pAlphaline = iCa8; - } - } - } - - pScanline += (pData->iColinc * 3); - pAlphaline += pData->iColinc; - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8_A8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_rgb8_a8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pAlphaline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint16 iFGa16, iBGa16, iCa16; - mng_uint16 iFGg16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16; - mng_uint8 iCr8, iCg8, iCb8; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8_A8, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination rows */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - pAlphaline = (mng_uint8p)pData->fGetalphaline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination rows starting-point */ - pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); - pAlphaline = pAlphaline + pData->iCol + pData->iDestl; - - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+iBps); - *(pScanline+2) = *(pDataline+2*iBps); - *pAlphaline = *(pDataline+3*iBps); - - pScanline += (pData->iColinc * 3); - pAlphaline += pData->iColinc; - pDataline += 4*iBps; - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - iFGa16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*pAlphaline); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* plain copy it */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *(pDataline+4); - *pAlphaline = *(pDataline+6); - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* get the proper values */ - int i; - for (i=2; i >= 0; i--) - { - iFGg16 = mng_get_uint16 (pDataline+i+i); - /* scale background up */ - iBGg16 = (mng_uint16)(*(pScanline+i)); - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - /* now compose */ - MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); - /* and return the composed values */ - *(pScanline+i) = (mng_uint8)(iFGg16 >> 8); - /* alpha remains fully opaque !!! */ - } - } - else - { /* scale background up */ - iBGr16 = (mng_uint16)(*pScanline ); - iBGg16 = (mng_uint16)(*(pScanline+1)); - iBGb16 = (mng_uint16)(*(pScanline+2)); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iCr16 >> 8); - *(pScanline+1) = (mng_uint8)(iCg16 >> 8); - *(pScanline+2) = (mng_uint8)(iCb16 >> 8); - *pAlphaline = (mng_uint8)(iCa16 >> 8); - } - } - } - - pScanline += (pData->iColinc * 3); - pAlphaline += pData->iColinc; - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *pAlphaline; - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - *pAlphaline = *(pDataline+3); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i), *(pDataline+i), iFGa8, *(pScanline+i)); - } - /* alpha remains fully opaque !!! */ - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCr8; - *(pScanline+1) = iCg8; - *(pScanline+2) = iCb8; - *pAlphaline = iCa8; - } - } - } - - pScanline += (pData->iColinc * 3); - pAlphaline += pData->iColinc; - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8_A8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_rgb8_a8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pAlphaline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8_A8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination rows */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - pAlphaline = (mng_uint8p)pData->fGetalphaline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination rows starting-point */ - pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); - pAlphaline = pAlphaline + pData->iCol + pData->iDestl; - - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - *pAlphaline = *(pDataline+3); - - pScanline += (pData->iColinc * 3); - pAlphaline += pData->iColinc; - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *pAlphaline; - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *pDataline; - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *(pDataline+2); - *pAlphaline = *(pDataline+3); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ -#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i), *(pDataline+i), iFGa8, *(pScanline+i)); - } -#else - MNG_COMPOSE8 (*pScanline, *pDataline, iFGa8, *pScanline ); - MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iFGa8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *(pDataline+2), iFGa8, *(pScanline+2)); -#endif - /* alpha remains fully opaque !!! */ - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCr8; - *(pScanline+1) = iCg8; - *(pScanline+2) = iCb8; - *pAlphaline = iCa8; - } - } - } - - pScanline += (pData->iColinc * 3); - pAlphaline += pData->iColinc; - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8_A8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_RGB8_A8 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_BGR8 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_bgr8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint8 iA8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + (pData->iSourcel / pData->iColinc) * 8; - else - pDataline = pDataline + (pData->iSourcel / pData->iColinc) * 4; - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *(pDataline+4); - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *pDataline; - - pScanline += (pData->iColinc * 3); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - - pScanline += (pData->iColinc * 3); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha value */ - iA16 = mng_get_uint16 (pDataline+6); - - if (iA16) /* any opacity at all ? */ - { - if (iA16 == 0xFFFF) /* fully opaque ? */ - { /* scale down by dropping the LSB */ - *pScanline = *(pDataline+4); - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *pDataline; - } - else - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - iBGr16 = (mng_uint16)(*(pScanline+2)); - iBGg16 = (mng_uint16)(*(pScanline+1)); - iBGb16 = (mng_uint16)(*pScanline ); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iFGb16 >> 8); - *(pScanline+1) = (mng_uint8)(iFGg16 >> 8); - *(pScanline+2) = (mng_uint8)(iFGr16 >> 8); - } - } - - pScanline += (pData->iColinc * 3); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - } - else - { /* do alpha composing */ - MNG_COMPOSE8 (*pScanline, *(pDataline+2), iA8, *pScanline ); - MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iA8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *pDataline, iA8, *(pScanline+2)); - } - } - - pScanline += (pData->iColinc * 3); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_bgr8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGg16; - mng_uint16 iBGg16; - mng_uint8 iA8; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR8, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *(pDataline+2*iBps); - *(pScanline+1) = *(pDataline+iBps); - *(pScanline+2) = *pDataline; - - pScanline += (pData->iColinc * 3); - pDataline += 4*iBps; - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha value */ - iA16 = mng_get_uint16 (pDataline+6); - - if (iA16) /* any opacity at all ? */ - { - if (iA16 == 0xFFFF) /* fully opaque ? */ - { /* scale down by dropping the LSB */ - *pScanline = *(pDataline+4); - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *pDataline; - } - else - { /* get the proper values */ - int i; - for (i=2; i >= 0; i--) - { - iFGg16 = mng_get_uint16 (pDataline+i+i); - /* scale background up */ - iBGg16 = (mng_uint16)(*(pScanline+2-i)); - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - /* now compose */ - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - /* and return the composed values */ - *(pScanline+2-i) = (mng_uint8)(iFGg16 >> 8); - } - } - } - - pScanline += (pData->iColinc * 3); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - } - else - { /* do alpha composing */ - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i), *(pDataline+2-i), iA8, *(pScanline+i)); - } - } - } - - pScanline += (pData->iColinc * 3); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_bgr8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iA8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + (pData->iSourcel / pData->iColinc) * 4; - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - - pScanline += (pData->iColinc * 3); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - } - else - { /* do alpha composing */ -#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i), *(pDataline+2-i), iA8, *(pScanline+i)); - } -#else - MNG_COMPOSE8 (*pScanline, *(pDataline+2), iA8, *pScanline ); - MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iA8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *pDataline, iA8, *(pScanline+2)); -#endif - } - } - - pScanline += (pData->iColinc * 3); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_BGR8 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_BGRX8 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_bgrx8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint8 iA8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRX8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + (pData->iSourcel / pData->iColinc) * 8; - else - pDataline = pDataline + (pData->iSourcel / pData->iColinc) * 4; - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *(pDataline+4); - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *pDataline; - *(pScanline+3) = 0xFF; /* filler byte */ - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - *(pScanline+3) = 0xFF; /* filler byte */ - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha value */ - iA16 = mng_get_uint16 (pDataline+6); - - if (iA16) /* any opacity at all ? */ - { - if (iA16 == 0xFFFF) /* fully opaque ? */ - { /* scale down by dropping the LSB */ - *pScanline = *(pDataline+4); - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *pDataline; - *(pScanline+3) = 0xFF; /* filler byte */ - } - else - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - iBGr16 = (mng_uint16)(*(pScanline+2)); - iBGg16 = (mng_uint16)(*(pScanline+1)); - iBGb16 = (mng_uint16)(*pScanline ); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iFGb16 >> 8); - *(pScanline+1) = (mng_uint8)(iFGg16 >> 8); - *(pScanline+2) = (mng_uint8)(iFGr16 >> 8); - *(pScanline+3) = 0xFF; /* filler byte */ - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - *(pScanline+3) = 0xFF; /* filler byte */ - } - else - { /* do alpha composing */ - MNG_COMPOSE8 (*pScanline, *(pDataline+2), iA8, *pScanline ); - MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iA8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *pDataline, iA8, *(pScanline+2)); - *(pScanline+3) = 0xFF; /* filler byte */ - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRX8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_bgrx8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGg16; - mng_uint16 iBGg16; - mng_uint8 iA8; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRX8, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *(pDataline+2*iBps); - *(pScanline+1) = *(pDataline+iBps); - *(pScanline+2) = *pDataline; - *(pScanline+3) = 0xFF; /* filler byte */ - - pScanline += (pData->iColinc << 2); - pDataline += 4*iBps; - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha value */ - iA16 = mng_get_uint16 (pDataline+6); - - if (iA16) /* any opacity at all ? */ - { - if (iA16 == 0xFFFF) /* fully opaque ? */ - { /* scale down by dropping the LSB */ - *pScanline = *(pDataline+4); - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *pDataline; - *(pScanline+3) = 0xFF; /* filler byte */ - } - else - { /* get the proper values */ - int i; - for (i=2; i >= 0; i--) - { - iFGg16 = mng_get_uint16 (pDataline+i+i); - /* scale background up */ - iBGg16 = (mng_uint16)(*(pScanline+2-i)); - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - /* now compose */ - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - /* and return the composed values */ - *(pScanline+2-i) = (mng_uint8)(iFGg16 >> 8); - } - *(pScanline+3) = 0xFF; /* filler byte */ - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - *(pScanline+3) = 0xFF; /* filler byte */ - } - else - { /* do alpha composing */ - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i), *(pDataline+2-i), iA8, *(pScanline+i)); - } - *(pScanline+3) = 0xFF; /* filler byte */ - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRX8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_bgrx8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iA8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRX8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + (pData->iSourcel / pData->iColinc) * 4; - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - *(pScanline+3) = 0xFF; /* filler byte */ - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - *(pScanline+3) = 0xFF; /* filler byte */ - } - else - { /* do alpha composing */ -#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i), *(pDataline+2-i), iA8, *(pScanline+i)); - } -#else - MNG_COMPOSE8 (*pScanline, *(pDataline+2), iA8, *pScanline ); - MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iA8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *pDataline, iA8, *(pScanline+2)); -#endif - *(pScanline+3) = 0xFF; /* filler byte */ - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRX8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_BGRX8 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_BGRA8 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_bgra8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint16 iFGa16, iBGa16, iCa16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *(pDataline+4); - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *pDataline; - *(pScanline+3) = *(pDataline+6); - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - *(pScanline+3) = *(pDataline+3); - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - iFGa16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*(pScanline+3)); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* plain copy it */ - *pScanline = *(pDataline+4); - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *pDataline; - *(pScanline+3) = *(pDataline+6); - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - iBGr16 = (mng_uint16)(*(pScanline+2)); - iBGg16 = (mng_uint16)(*(pScanline+1)); - iBGb16 = (mng_uint16)(*pScanline ); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iFGb16 >> 8); - *(pScanline+1) = (mng_uint8)(iFGg16 >> 8); - *(pScanline+2) = (mng_uint8)(iFGr16 >> 8); - /* alpha remains fully opaque !!! */ - } - else - { /* scale background up */ - iBGr16 = (mng_uint16)(*(pScanline+2)); - iBGg16 = (mng_uint16)(*(pScanline+1)); - iBGb16 = (mng_uint16)(*pScanline ); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iCb16 >> 8); - *(pScanline+1) = (mng_uint8)(iCg16 >> 8); - *(pScanline+2) = (mng_uint8)(iCr16 >> 8); - *(pScanline+3) = (mng_uint8)(iCa16 >> 8); - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *(pScanline+3); - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - *(pScanline+3) = *(pDataline+3); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ - MNG_COMPOSE8 (*pScanline, *(pDataline+2), iFGa8, *pScanline ); - MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iFGa8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *pDataline, iFGa8, *(pScanline+2)); - /* alpha remains fully opaque !!! */ - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *(pScanline+2), *(pScanline+1), *pScanline, iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCb8; - *(pScanline+1) = iCg8; - *(pScanline+2) = iCr8; - *(pScanline+3) = iCa8; - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_bgra8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint16 iFGa16, iBGa16, iCa16; - mng_uint16 iFGg16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16; - mng_uint8 iCr8, iCg8, iCb8; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *(pDataline+2*iBps); - *(pScanline+1) = *(pDataline+iBps); - *(pScanline+2) = *pDataline; - *(pScanline+3) = *(pDataline+3*iBps); - - pScanline += (pData->iColinc << 2); - pDataline += 4*iBps; - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - iFGa16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*(pScanline+3)); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* plain copy it */ - *pScanline = *(pDataline+4); - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *pDataline; - *(pScanline+3) = *(pDataline+6); - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* get the proper values */ - int i; - for (i=2; i >= 0; i--) - { - iFGg16 = mng_get_uint16 (pDataline+i+i); - /* scale background up */ - iBGg16 = (mng_uint16)(*(pScanline+2-i)); - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - /* now compose */ - MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); - /* and return the composed values */ - *(pScanline+2-i) = (mng_uint8)(iFGg16 >> 8); - /* alpha remains fully opaque !!! */ - } - } - else - { /* scale background up */ - iBGr16 = (mng_uint16)(*(pScanline+2)); - iBGg16 = (mng_uint16)(*(pScanline+1)); - iBGb16 = (mng_uint16)(*pScanline ); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iCb16 >> 8); - *(pScanline+1) = (mng_uint8)(iCg16 >> 8); - *(pScanline+2) = (mng_uint8)(iCr16 >> 8); - *(pScanline+3) = (mng_uint8)(iCa16 >> 8); - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *(pScanline+3); - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - *(pScanline+3) = *(pDataline+3); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i), *(pDataline+2-i), iFGa8, *(pScanline+i)); - } - /* alpha remains fully opaque !!! */ - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *(pScanline+2), *(pScanline+1), *pScanline, iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCb8; - *(pScanline+1) = iCg8; - *(pScanline+2) = iCr8; - *(pScanline+3) = iCa8; - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_bgra8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - *(pScanline+3) = *(pDataline+3); - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *(pScanline+3); - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *(pDataline+2); - *(pScanline+1) = *(pDataline+1); - *(pScanline+2) = *pDataline; - *(pScanline+3) = *(pDataline+3); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ -#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i), *(pDataline+2-i), iFGa8, *(pScanline+i)); - } -#else - MNG_COMPOSE8 (*pScanline, *(pDataline+2), iFGa8, *pScanline ); - MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iFGa8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *pDataline, iFGa8, *(pScanline+2)); -#endif - /* alpha remains fully opaque !!! */ - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *(pScanline+2), *(pScanline+1), *pScanline, iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCb8; - *(pScanline+1) = iCg8; - *(pScanline+2) = iCr8; - *(pScanline+3) = iCa8; - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_BGRA8 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_BGRA8_PM -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_bgra8_pm (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint32 s, t; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8PM, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - if ((s = pDataline[6]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = pDataline[4]; - pScanline[1] = pDataline[2]; - pScanline[2] = pDataline[0]; - pScanline[3] = 255; - } - else - { - pScanline[0] = DIV255B8(s * pDataline[4]); - pScanline[1] = DIV255B8(s * pDataline[2]); - pScanline[2] = DIV255B8(s * pDataline[0]); - pScanline[3] = (mng_uint8)s; - } - } - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values and premultiply */ - if ((s = pDataline[3]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = pDataline[2]; - pScanline[1] = pDataline[1]; - pScanline[2] = pDataline[0]; - pScanline[3] = 255; - } - else - { - pScanline[0] = DIV255B8(s * pDataline[2]); - pScanline[1] = DIV255B8(s * pDataline[1]); - pScanline[2] = DIV255B8(s * pDataline[0]); - pScanline[3] = (mng_uint8)s; - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - if ((s = pDataline[6]) != 0) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if (s == 255) - { /* plain copy it */ - pScanline[0] = pDataline[4]; - pScanline[1] = pDataline[2]; - pScanline[2] = pDataline[0]; - pScanline[3] = 255; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i] = DIV255B8(s * pDataline[4-i-i] + t * - pScanline[i]); - } - } -#else - pScanline[0] = DIV255B8(s * pDataline[4] + t * pScanline[0]); - pScanline[1] = DIV255B8(s * pDataline[2] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[0] + t * pScanline[2]); -#endif - pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - if ((s = pDataline[3]) != 0) /* any opacity at all ? */ - { /* fully opaque ? */ - if (s == 255) - { /* then simply copy the values */ - pScanline[0] = pDataline[2]; - pScanline[1] = pDataline[1]; - pScanline[2] = pDataline[0]; - pScanline[3] = 255; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i] = DIV255B8(s * pDataline[2-i] + t * - pScanline[i]); - } - } -#else - pScanline[0] = DIV255B8(s * pDataline[2] + t * pScanline[0]); - pScanline[1] = DIV255B8(s * pDataline[1] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[0] + t * pScanline[2]); -#endif - pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8PM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_bgra8_pm (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint32 s, t; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8PM, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - if ((s = pDataline[6]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = pDataline[4]; - pScanline[1] = pDataline[2]; - pScanline[2] = pDataline[0]; - pScanline[3] = 255; - } - else - { -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - int i; - for (i=2; i >= 0; i--) - { - pScanline[i] = DIV255B8(s * pDataline[4-i-i]); - } -#else - pScanline[0] = DIV255B8(s * pDataline[4]); - pScanline[1] = DIV255B8(s * pDataline[2]); - pScanline[2] = DIV255B8(s * pDataline[0]); -#endif - pScanline[3] = (mng_uint8)s; - } - } - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values and premultiply */ - if ((s = pDataline[3]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = pDataline[2]; - pScanline[1] = pDataline[1]; - pScanline[2] = pDataline[0]; - pScanline[3] = 255; - } - else - { -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - int i; - for (i=2; i >= 0; i--) - { - pScanline[i] = DIV255B8(s * pDataline[2-i]); - } -#else - pScanline[0] = DIV255B8(s * pDataline[2]); - pScanline[1] = DIV255B8(s * pDataline[1]); - pScanline[2] = DIV255B8(s * pDataline[0]); -#endif - pScanline[3] = (mng_uint8)s; - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - if ((s = pDataline[6]) != 0) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if (s == 255) - { /* plain copy it */ - pScanline[0] = pDataline[4]; - pScanline[1] = pDataline[2]; - pScanline[2] = pDataline[0]; - pScanline[3] = 255; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i] = DIV255B8(s * pDataline[4-i-i] + t * - pScanline[i]); - } - } -#else - pScanline[0] = DIV255B8(s * pDataline[4] + t * pScanline[0]); - pScanline[1] = DIV255B8(s * pDataline[2] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[0] + t * pScanline[2]); -#endif - pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - if ((s = pDataline[3]) != 0) /* any opacity at all ? */ - { /* fully opaque ? */ - if (s == 255) - { /* then simply copy the values */ - pScanline[0] = pDataline[2]; - pScanline[1] = pDataline[1]; - pScanline[2] = pDataline[0]; - pScanline[3] = 255; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i] = DIV255B8(s * pDataline[2-i] + t * - pScanline[i]); - } - } -#else - pScanline[0] = DIV255B8(s * pDataline[2] + t * pScanline[0]); - pScanline[1] = DIV255B8(s * pDataline[1] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[0] + t * pScanline[2]); -#endif - pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8PM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_bgra8_pm (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint32 s, t; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8PM, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values and premultiply */ - if ((s = pDataline[3]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = pDataline[2]; - pScanline[1] = pDataline[1]; - pScanline[2] = pDataline[0]; - pScanline[3] = 255; - } - else - { -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - int i; - for (i=2; i >= 0; i--) - { - pScanline[i] = DIV255B8(s * pDataline[2-i]); - } -#else - pScanline[0] = DIV255B8(s * pDataline[2]); - pScanline[1] = DIV255B8(s * pDataline[1]); - pScanline[2] = DIV255B8(s * pDataline[0]); -#endif - pScanline[3] = (mng_uint8)s; - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - if ((s = pDataline[3]) != 0) /* any opacity at all ? */ - { /* fully opaque ? */ - if (s == 255) - { /* then simply copy the values */ - pScanline[0] = pDataline[2]; - pScanline[1] = pDataline[1]; - pScanline[2] = pDataline[0]; - pScanline[3] = 255; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i] = DIV255B8(s * pDataline[2-i] + t * - pScanline[i]); - } - } -#else - pScanline[0] = DIV255B8(s * pDataline[2] + t * pScanline[0]); - pScanline[1] = DIV255B8(s * pDataline[1] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[0] + t * pScanline[2]); -#endif - pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8PM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_BGRA8_PM */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_ABGR8 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_abgr8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint16 iFGa16, iBGa16, iCa16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *(pDataline+6); - *(pScanline+1) = *(pDataline+4); - *(pScanline+2) = *(pDataline+2); - *(pScanline+3) = *pDataline; - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *(pDataline+3); - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *(pDataline+1); - *(pScanline+3) = *pDataline; - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - iFGa16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*pScanline); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* plain copy it */ - *pScanline = *(pDataline+6); - *(pScanline+1) = *(pDataline+4); - *(pScanline+2) = *(pDataline+2); - *(pScanline+3) = *pDataline; - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - iBGr16 = (mng_uint16)(*(pScanline+3)); - iBGg16 = (mng_uint16)(*(pScanline+2)); - iBGb16 = (mng_uint16)(*(pScanline+1)); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); - /* and return the composed values */ - /* alpha itself remains fully opaque !!! */ - *(pScanline+1) = (mng_uint8)(iFGb16 >> 8); - *(pScanline+2) = (mng_uint8)(iFGg16 >> 8); - *(pScanline+3) = (mng_uint8)(iFGr16 >> 8); - } - else - { /* scale background up */ - iBGr16 = (mng_uint16)(*(pScanline+3)); - iBGg16 = (mng_uint16)(*(pScanline+2)); - iBGb16 = (mng_uint16)(*(pScanline+1)); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iCa16 >> 8); - *(pScanline+1) = (mng_uint8)(iCb16 >> 8); - *(pScanline+2) = (mng_uint8)(iCg16 >> 8); - *(pScanline+3) = (mng_uint8)(iCr16 >> 8); - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *pScanline; - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *(pDataline+3); - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *(pDataline+1); - *(pScanline+3) = *pDataline; - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do simple alpha composing */ - /* alpha itself remains fully opaque !!! */ - MNG_COMPOSE8 (*(pScanline+1), *(pDataline+2), iFGa8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *(pDataline+1), iFGa8, *(pScanline+2)); - MNG_COMPOSE8 (*(pScanline+3), *pDataline, iFGa8, *(pScanline+3)); - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *(pScanline+3), *(pScanline+2), *(pScanline+1), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCa8; - *(pScanline+1) = iCb8; - *(pScanline+2) = iCg8; - *(pScanline+3) = iCr8; - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_abgr8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint16 iFGa16, iBGa16, iCa16; - mng_uint16 iFGg16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16; - mng_uint8 iCr8, iCg8, iCb8; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *pScanline = *(pDataline+3*iBps); - *(pScanline+1) = *(pDataline+2*iBps); - *(pScanline+2) = *(pDataline+iBps); - *(pScanline+3) = *pDataline; - - pScanline += (pData->iColinc << 2); - pDataline += 4*iBps; - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - iFGa16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*pScanline); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* plain copy it */ - *pScanline = *(pDataline+6); - *(pScanline+1) = *(pDataline+4); - *(pScanline+2) = *(pDataline+2); - *(pScanline+3) = *pDataline; - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* get the proper values */ - int i; - for (i=2; i >= 0; i--) - { - iFGg16 = mng_get_uint16 (pDataline+i+i); - /* scale background up */ - iBGg16 = (mng_uint16)(*(pScanline+3-i)); - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - /* now compose */ - MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); - /* and return the composed values */ - /* alpha itself remains fully opaque !!! */ - *(pScanline+3-i) = (mng_uint8)(iFGg16 >> 8); - } - } - else - { /* scale background up */ - iBGr16 = (mng_uint16)(*(pScanline+3)); - iBGg16 = (mng_uint16)(*(pScanline+2)); - iBGb16 = (mng_uint16)(*(pScanline+1)); - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *pScanline = (mng_uint8)(iCa16 >> 8); - *(pScanline+1) = (mng_uint8)(iCb16 >> 8); - *(pScanline+2) = (mng_uint8)(iCg16 >> 8); - *(pScanline+3) = (mng_uint8)(iCr16 >> 8); - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *pScanline; - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *(pDataline+3); - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *(pDataline+1); - *(pScanline+3) = *pDataline; - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do simple alpha composing */ - /* alpha itself remains fully opaque !!! */ - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i+1), *(pDataline+2-i), iFGa8, *(pScanline+i+1)); - } - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *(pScanline+3), *(pScanline+2), *(pScanline+1), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCa8; - *(pScanline+1) = iCb8; - *(pScanline+2) = iCg8; - *(pScanline+3) = iCr8; - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_abgr8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *pScanline = *(pDataline+3); - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *(pDataline+1); - *(pScanline+3) = *pDataline; - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *pScanline; - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pScanline = *(pDataline+3); - *(pScanline+1) = *(pDataline+2); - *(pScanline+2) = *(pDataline+1); - *(pScanline+3) = *pDataline; - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do simple alpha composing */ - /* alpha itself remains fully opaque !!! */ -#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pScanline+i+1), *(pDataline+2-i), iFGa8, *(pScanline+i+1)); - } -#else - MNG_COMPOSE8 (*(pScanline+1), *(pDataline+2), iFGa8, *(pScanline+1)); - MNG_COMPOSE8 (*(pScanline+2), *(pDataline+1), iFGa8, *(pScanline+2)); - MNG_COMPOSE8 (*(pScanline+3), *pDataline, iFGa8, *(pScanline+3)); -#endif - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - *(pScanline+3), *(pScanline+2), *(pScanline+1), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pScanline = iCa8; - *(pScanline+1) = iCb8; - *(pScanline+2) = iCg8; - *(pScanline+3) = iCr8; - } - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_ABGR8 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_ABGR8_PM -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_abgr8_pm (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint32 s, t; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8_PM, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - if ((s = pDataline[6]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = 255; - pScanline[1] = pDataline[4]; - pScanline[2] = pDataline[2]; - pScanline[3] = pDataline[0]; - } - else - { - pScanline[0] = (mng_uint8)s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i+1] = DIV255B8(s * pDataline[4-i-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[4]); - pScanline[2] = DIV255B8(s * pDataline[2]); - pScanline[3] = DIV255B8(s * pDataline[0]); -#endif - } - } - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values and premultiply */ - if ((s = pDataline[3]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = 255; - pScanline[1] = pDataline[2]; - pScanline[2] = pDataline[1]; - pScanline[3] = pDataline[0]; - } - else - { - pScanline[0] = (mng_uint8)s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i+1] = DIV255B8(s * pDataline[2-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[2]); - pScanline[2] = DIV255B8(s * pDataline[1]); - pScanline[3] = DIV255B8(s * pDataline[0]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - if ((s = pDataline[6]) != 0) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if (s == 255) - { /* plain copy it */ - pScanline[0] = 255; - pScanline[1] = pDataline[4]; - pScanline[2] = pDataline[2]; - pScanline[3] = pDataline[0]; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; - pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i+1] = DIV255B8(s * pDataline[4-i-i] + t * - pScanline[i+1]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[4] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[2] + t * pScanline[2]); - pScanline[3] = DIV255B8(s * pDataline[0] + t * pScanline[3]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - if ((s = pDataline[3]) != 0) /* any opacity at all ? */ - { /* fully opaque ? */ - if (s == 255) - { /* then simply copy the values */ - pScanline[0] = 255; - pScanline[1] = pDataline[2]; - pScanline[2] = pDataline[1]; - pScanline[3] = pDataline[0]; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; - pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i+1] = DIV255B8(s * pDataline[2-i] + t * - pScanline[i+1]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[2] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[1] + t * pScanline[2]); - pScanline[3] = DIV255B8(s * pDataline[0] + t * pScanline[3]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8_PM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_abgr8_pm (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint32 s, t; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8_PM, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - if ((s = pDataline[6]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = 255; - pScanline[1] = pDataline[4]; - pScanline[2] = pDataline[2]; - pScanline[3] = pDataline[0]; - } - else - { - pScanline[0] = (mng_uint8)s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i+1] = DIV255B8(s * pDataline[4-i-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[4]); - pScanline[2] = DIV255B8(s * pDataline[2]); - pScanline[3] = DIV255B8(s * pDataline[0]); -#endif - } - } - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values and premultiply */ - if ((s = pDataline[3]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = 255; - pScanline[1] = pDataline[2]; - pScanline[2] = pDataline[1]; - pScanline[3] = pDataline[0]; - } - else - { - pScanline[0] = (mng_uint8)s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i+1] = DIV255B8(s * pDataline[2-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[2]); - pScanline[2] = DIV255B8(s * pDataline[1]); - pScanline[3] = DIV255B8(s * pDataline[0]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - if ((s = pDataline[6]) != 0) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if (s == 255) - { /* plain copy it */ - pScanline[0] = 255; - pScanline[1] = pDataline[4]; - pScanline[2] = pDataline[2]; - pScanline[3] = pDataline[0]; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; - pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i+1] = DIV255B8(s * pDataline[4-i-i] + t * - pScanline[i+1]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[4] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[2] + t * pScanline[2]); - pScanline[3] = DIV255B8(s * pDataline[0] + t * pScanline[3]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - if ((s = pDataline[3]) != 0) /* any opacity at all ? */ - { /* fully opaque ? */ - if (s == 255) - { /* then simply copy the values */ - pScanline[0] = 255; - pScanline[1] = pDataline[2]; - pScanline[2] = pDataline[1]; - pScanline[3] = pDataline[0]; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; - pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i+1] = DIV255B8(s * pDataline[2-i] + t * - pScanline[i+1]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[2] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[1] + t * pScanline[2]); - pScanline[3] = DIV255B8(s * pDataline[0] + t * pScanline[3]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8_PM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_abgr8_pm (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint32 s, t; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8_PM, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values and premultiply */ - if ((s = pDataline[3]) == 0) - *(mng_uint32*) pScanline = 0; /* set all components = 0 */ - else - { - if (s == 255) - { - pScanline[0] = 255; - pScanline[1] = pDataline[2]; - pScanline[2] = pDataline[1]; - pScanline[3] = pDataline[0]; - } - else - { - pScanline[0] = (mng_uint8)s; -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i+1] = DIV255B8(s * pDataline[2-i]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[2]); - pScanline[2] = DIV255B8(s * pDataline[1]); - pScanline[3] = DIV255B8(s * pDataline[0]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - if ((s = pDataline[3]) != 0) /* any opacity at all ? */ - { /* fully opaque ? */ - if (s == 255) - { /* then simply copy the values */ - pScanline[0] = 255; - pScanline[1] = pDataline[2]; - pScanline[2] = pDataline[1]; - pScanline[3] = pDataline[0]; - } - else - { /* now blend (premultiplied) */ - t = 255 - s; - pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); -#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV - { - int i; - for (i=2; i >= 0; i--) - { - pScanline[i+1] = DIV255B8(s * pDataline[2-i] + t * - pScanline[i+1]); - } - } -#else - pScanline[1] = DIV255B8(s * pDataline[2] + t * pScanline[1]); - pScanline[2] = DIV255B8(s * pDataline[1] + t * pScanline[2]); - pScanline[3] = DIV255B8(s * pDataline[0] + t * pScanline[3]); -#endif - } - } - - pScanline += (pData->iColinc << 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8_PM, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_ABGR8_PM */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_BGR565 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_bgr565 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint8 iA8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ( (*(pDataline+2)>>5) ) ); - *pScanline = (mng_uint8)( ( (*(pDataline+4)) >>3) | ( (*(pDataline+2)&0xFC) << 3) ); - - pScanline += (pData->iColinc * 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ( (*(pDataline+1)>>5 ) ) ); - *pScanline = (mng_uint8)( ( *(pDataline+2) >>3 ) | ( (*(pDataline+1)&0xFC ) << 3) ); - - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA16 = mng_get_uint16 (pDataline+6); - - if (iA16) /* any opacity at all ? */ - { - if (iA16 == 0xFFFF) /* fully opaque ? */ - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( (*(pDataline))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); - *pScanline = (mng_uint8)( (*(pDataline+4)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); - } - else - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - - iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); - iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); - iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( (iFGr16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); - *pScanline = (mng_uint8) ( ( (iFGb16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); - *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); - } - else - { /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); - iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); - iBlue = (mng_uint8) ( (*pScanline << 3) ); - - MNG_COMPOSE8 (iRed, *pDataline, iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); - *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_bgr565 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint8 iA8; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | - ( (*(pDataline+iBps)>>5) ) ); - *pScanline = (mng_uint8)( ( (*(pDataline+2*iBps)) >>3) | - ( (*(pDataline+iBps)&0xFC) << 3) ); - - pScanline += (pData->iColinc * 2); - pDataline += 4*iBps; - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA16 = mng_get_uint16 (pDataline+6); - - if (iA16) /* any opacity at all ? */ - { - if (iA16 == 0xFFFF) /* fully opaque ? */ - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( (*(pDataline))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); - *pScanline = (mng_uint8)( (*(pDataline+4)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); - } - else - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - - iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); - iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); - iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( (iFGr16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); - *pScanline = (mng_uint8) ( ( (iFGb16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); - *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); - } - else - { /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); - iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); - iBlue = (mng_uint8) ( (*pScanline << 3) ); - - MNG_COMPOSE8 (iRed, *pDataline, iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); - *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_bgr565 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iA8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ( (*(pDataline+1)>>5 ) ) ); - *pScanline = (mng_uint8)( ( *(pDataline+2) >>3 ) | ( (*(pDataline+1)&0xFC ) << 3) ); - - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); - *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); - } - else - { /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); - iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); - iBlue = (mng_uint8) ( (*pScanline << 3) ); - - MNG_COMPOSE8 (iRed, *pDataline, iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); - *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_BGR565 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_RGB565 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_rgb565 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint8 iA8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB565, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ( ( *(pDataline+4)) & 0xF8) | (*(pDataline+2) >> 5 ) ); - *pScanline = (mng_uint8)( ( ( *(pDataline )) >> 3 ) | ((*(pDataline+2) & 0xFC) << 3) ); - - pScanline += (pData->iColinc * 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) & 0xF8) | (*(pDataline+1) >> 5 ) ); - *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+1) & 0xFC) << 3) ); - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA16 = mng_get_uint16 (pDataline+6); - - if (iA16) /* any opacity at all ? */ - { - if (iA16 == 0xFFFF) /* fully opaque ? */ - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline+4)) & 0xF8) | (*(pDataline+2)>>5) ); - *pScanline = (mng_uint8)( ( (*(pDataline )) >> 3 ) | ((*(pDataline+2)&0xFC) << 3) ); - } - else - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - - /* scale background up */ - iBGr16 = (mng_uint8)( *(pScanline+1) & 0xF8 ); - iBGg16 = (mng_uint8)( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0) >> 3 ) ); - iBGb16 = (mng_uint8)( *(pScanline ) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8)( (mng_uint8)((iFGb16 >> 8) &0xF8) | ( (mng_uint8)(iFGg16 >> 8) >> 5 ) ); - *pScanline = (mng_uint8)( (mng_uint8) (iFGr16 >>11) | ( ( (mng_uint8)(iFGg16 >> 8) & 0xFC) << 3) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) & 0xF8) | ( *(pDataline+1) >> 5 ) ); - *pScanline = (mng_uint8)( ( (*(pDataline )) >> 3 ) | ( (*(pDataline+1) & 0xFC) << 3 ) ); - } - else - { /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8)( *(pScanline+1) & 0xF8); - iGreen = (mng_uint8)( ( *(pScanline+1) << 5 ) | ( ( (*pScanline)&0xE0)>>3 ) ); - iBlue = (mng_uint8)( *(pScanline ) << 3 ); - - MNG_COMPOSE8 (iRed, *(pDataline+2), iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+0), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8)( ( iRed & 0xF8) | ( iGreen >> 5 ) ); - *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB565, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_rgb565 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint8 iA8; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB565, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ( ( *(pDataline+2*iBps)) & 0xF8) | - (*(pDataline+iBps) >> 5 ) ); - *pScanline = (mng_uint8)( ( ( *(pDataline )) >> 3 ) | - ((*(pDataline+iBps) & 0xFC) << 3) ); - - pScanline += (pData->iColinc * 2); - pDataline += 4*iBps; - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA16 = mng_get_uint16 (pDataline+6); - - if (iA16) /* any opacity at all ? */ - { - if (iA16 == 0xFFFF) /* fully opaque ? */ - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline+4)) & 0xF8) | (*(pDataline+2)>>5) ); - *pScanline = (mng_uint8)( ( (*(pDataline )) >> 3 ) | ((*(pDataline+2)&0xFC) << 3) ); - } - else - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - - /* scale background up */ - iBGr16 = (mng_uint8)( *(pScanline+1) & 0xF8 ); - iBGg16 = (mng_uint8)( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0) >> 3 ) ); - iBGb16 = (mng_uint8)( *(pScanline ) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8)( (mng_uint8)((iFGb16 >> 8) &0xF8) | ( (mng_uint8)(iFGg16 >> 8) >> 5 ) ); - *pScanline = (mng_uint8)( (mng_uint8) (iFGr16 >>11) | ( ( (mng_uint8)(iFGg16 >> 8) & 0xFC) << 3) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) & 0xF8) | ( *(pDataline+1) >> 5 ) ); - *pScanline = (mng_uint8)( ( (*(pDataline )) >> 3 ) | ( (*(pDataline+1) & 0xFC) << 3 ) ); - } - else - { /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8)( *(pScanline+1) & 0xF8); - iGreen = (mng_uint8)( ( *(pScanline+1) << 5 ) | ( ( (*pScanline)&0xE0)>>3 ) ); - iBlue = (mng_uint8)( *(pScanline ) << 3 ); - - MNG_COMPOSE8 (iRed, *(pDataline+2), iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+0), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8)( ( iRed & 0xF8) | ( iGreen >> 5 ) ); - *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB565, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_rgb565 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iA8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB565, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) & 0xF8) | (*(pDataline+1) >> 5 ) ); - *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+1) & 0xFC) << 3) ); - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) & 0xF8) | ( *(pDataline+1) >> 5 ) ); - *pScanline = (mng_uint8)( ( (*(pDataline )) >> 3 ) | ( (*(pDataline+1) & 0xFC) << 3 ) ); - } - else - { /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8)( *(pScanline+1) & 0xF8); - iGreen = (mng_uint8)( ( *(pScanline+1) << 5 ) | ( ( (*pScanline)&0xE0)>>3 ) ); - iBlue = (mng_uint8)( *(pScanline ) << 3 ); - - MNG_COMPOSE8 (iRed, *(pDataline+2), iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+0), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8)( ( iRed & 0xF8) | ( iGreen >> 5 ) ); - *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB565, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_RGB565 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_BGRA565 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_bgra565 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint16 iFGa16, iBGa16, iCa16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA565, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl * 3); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ( (*(pDataline+2)>>5) ) ); - *pScanline = (mng_uint8)( ( (*(pDataline+4)) >>3) | ( (*(pDataline+2)&0xFC) << 3) ); - *(pScanline+2) = *(pDataline+6); - - pScanline += (pData->iColinc * 3); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ( (*(pDataline+1)>>5 ) ) ); - *pScanline = (mng_uint8)( ( *(pDataline+2) >>3 ) | ( (*(pDataline+1)&0xFC ) << 3) ); - *(pScanline+2) = *(pDataline+3); - - pScanline += (pData->iColinc * 3); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - iFGa16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*(pScanline+2)); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* plain copy it */ - *(pScanline+1) = (mng_uint8)( (*(pDataline))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); - *pScanline = (mng_uint8)( (*(pDataline+4)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); - *(pScanline+2) = *(pDataline+6); - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); - iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); - iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( (iFGr16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); - *pScanline = (mng_uint8) ( ( (iFGb16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); - } - else - { /* scale background up */ - iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); - iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); - iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( (iCr16 >> 8) & 0xF8 ) | ( (mng_uint8)(iCg16 >> 8) >> 5 ) ); - *pScanline = (mng_uint8) ( ( (iCb16 >> 11) ) | (((mng_uint8)(iCg16 >> 8) & 0xFC) << 3) ); - *(pScanline+2) = (mng_uint8)(iCa16 >> 8); - } - } - } - - pScanline += (pData->iColinc * 3); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *(pScanline+2); - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); - *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); - *(pScanline+2) = *(pDataline+3); - } - else - { - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); - iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); - iBlue = (mng_uint8) ( (*pScanline << 3) ); - - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ - MNG_COMPOSE8 (iRed, *pDataline, iFGa8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iFGa8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iFGa8, iBlue ); - /* alpha remains fully opaque !!! */ - *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); - *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - iRed , iGreen , iBlue , iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - - - *pScanline = (mng_uint8) ( ( iCb8 >> 3 ) | ( (iCg8 & 0xFC) << 3) ); - *(pScanline+1) = (mng_uint8) ( ( iCr8 & 0xF8 ) | (iCg8>>5) ); - *(pScanline+2) = (mng_uint8) iCa8; - } - } - } - - pScanline += (pData->iColinc *3); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA565, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_bgra565 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint16 iFGa16, iBGa16, iCa16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16; - mng_uint8 iCr8, iCg8, iCb8; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA565, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl * 3); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | - ( (*(pDataline+iBps)>>5) ) ); - *pScanline = (mng_uint8)( ( (*(pDataline+2*iBps)) >>3) | - ( (*(pDataline+iBps)&0xFC) << 3) ); - *(pScanline+2) = *(pDataline+3*iBps); - - pScanline += (pData->iColinc * 3); - pDataline += 4*iBps; - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - iFGa16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*(pScanline+2)); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* plain copy it */ - *(pScanline+1) = (mng_uint8)( (*(pDataline))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); - *pScanline = (mng_uint8)( (*(pDataline+4)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); - *(pScanline+2) = *(pDataline+6); - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); - iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); - iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( (iFGr16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); - *pScanline = (mng_uint8) ( ( (iFGb16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); - } - else - { /* scale background up */ - iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); - iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); - iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( (iCr16 >> 8) & 0xF8 ) | ( (mng_uint8)(iCg16 >> 8) >> 5 ) ); - *pScanline = (mng_uint8) ( ( (iCb16 >> 11) ) | (((mng_uint8)(iCg16 >> 8) & 0xFC) << 3) ); - *(pScanline+2) = (mng_uint8)(iCa16 >> 8); - } - } - } - - pScanline += (pData->iColinc * 3); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *(pScanline+2); - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); - *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); - *(pScanline+2) = *(pDataline+3); - } - else - { - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); - iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); - iBlue = (mng_uint8) ( (*pScanline << 3) ); - - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ - MNG_COMPOSE8 (iRed, *pDataline, iFGa8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iFGa8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iFGa8, iBlue ); - /* alpha remains fully opaque !!! */ - *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); - *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - iRed , iGreen , iBlue , iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - - - *pScanline = (mng_uint8) ( ( iCb8 >> 3 ) | ( (iCg8 & 0xFC) << 3) ); - *(pScanline+1) = (mng_uint8) ( ( iCr8 & 0xF8 ) | (iCg8>>5) ); - *(pScanline+2) = (mng_uint8) iCa8; - } - } - } - - pScanline += (pData->iColinc *3); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA565, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_bgra565 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA565, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl * 3); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ( (*(pDataline+1)>>5 ) ) ); - *pScanline = (mng_uint8)( ( *(pDataline+2) >>3 ) | ( (*(pDataline+1)&0xFC ) << 3) ); - *(pScanline+2) = *(pDataline+3); - - pScanline += (pData->iColinc * 3); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *(pScanline+2); - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); - *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); - *(pScanline+2) = *(pDataline+3); - } - else - { - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); - iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); - iBlue = (mng_uint8) ( (*pScanline << 3) ); - - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ - MNG_COMPOSE8 (iRed, *pDataline, iFGa8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iFGa8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iFGa8, iBlue ); - /* alpha remains fully opaque !!! */ - *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); - *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - iRed , iGreen , iBlue , iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - - - *pScanline = (mng_uint8) ( ( iCb8 >> 3 ) | ( (iCg8 & 0xFC) << 3) ); - *(pScanline+1) = (mng_uint8) ( ( iCr8 & 0xF8 ) | (iCg8>>5) ); - *(pScanline+2) = (mng_uint8) iCa8; - } - } - } - - pScanline += (pData->iColinc *3); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA565, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_BGRA565 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_RGBA565 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_rgba565 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint16 iFGa16, iBGa16, iCa16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA565, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl * 3); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline+4))&0xF8 ) | ( (*(pDataline+2)>>5) ) ); - *pScanline = (mng_uint8)( ( (*(pDataline)) >>3) | ( (*(pDataline+2)&0xFC) << 3) ); - *(pScanline+2) = *(pDataline+6); - - pScanline += (pData->iColinc * 3); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2))&0xF8 ) | ( (*(pDataline+1)>>5 ) ) ); - *pScanline = (mng_uint8)( ( *(pDataline) >>3 ) | ( (*(pDataline+1)&0xFC ) << 3) ); - *(pScanline+2) = *(pDataline+3); - - pScanline += (pData->iColinc * 3); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - iFGa16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*(pScanline+2)); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* plain copy it */ - *(pScanline+1) = (mng_uint8)( (*(pDataline+4))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); - *pScanline = (mng_uint8)( (*(pDataline)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); - *(pScanline+2) = *(pDataline+6); - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - iBGr16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); - iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); - iBGb16 = (mng_uint16)( (*(pScanline )) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( (iFGb16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); - *pScanline = (mng_uint8) ( ( (iFGr16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); - } - else - { /* scale background up */ - iBGr16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); - iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); - iBGb16 = (mng_uint16)( (*(pScanline )) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( (iCb16 >> 8) & 0xF8 ) | ( (mng_uint8)(iCg16 >> 8) >> 5 ) ); - *pScanline = (mng_uint8) ( ( (iCr16 >> 11) ) | (((mng_uint8)(iCg16 >> 8) & 0xFC) << 3) ); - *(pScanline+2) = (mng_uint8)(iCa16 >> 8); - } - } - } - - pScanline += (pData->iColinc * 3); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *(pScanline+2); - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) &0xF8 ) | (*(pDataline+1) >>5 ) ); - *pScanline = (mng_uint8)( ( ((*(pDataline))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); - *(pScanline+2) = *(pDataline+3); - } - else - { - mng_uint8 iRed, iGreen, iBlue; - - iBlue = (mng_uint8) ( *(pScanline+1) & 0xF8 ); - iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); - iRed = (mng_uint8) ( (*pScanline << 3) ); - - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ - MNG_COMPOSE8 (iRed, *pDataline, iFGa8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iFGa8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iFGa8, iBlue ); - /* alpha remains fully opaque !!! */ - *(pScanline+1) = (mng_uint8) ( ( iBlue & 0xF8 ) | (iGreen>>5) ); - *pScanline = (mng_uint8) ( ( iRed >> 3 ) | ( (iGreen & 0xFC) << 3) ); - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - iRed , iGreen , iBlue , iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - - - *pScanline = (mng_uint8) ( ( iCr8 >> 3 ) | ( (iCg8 & 0xFC) << 3) ); - *(pScanline+1) = (mng_uint8) ( ( iCb8 & 0xF8 ) | (iCg8>>5) ); - *(pScanline+2) = (mng_uint8) iCa8; - } - } - } - - pScanline += (pData->iColinc *3); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA565, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_rgba565 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint16 iFGa16, iBGa16, iCa16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16; - mng_uint8 iCr8, iCg8, iCb8; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA565, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl * 3); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2*iBps))&0xF8 ) | - ( (*(pDataline+iBps)>>5) ) ); - *pScanline = (mng_uint8)( ( (*(pDataline)) >>3) | - ( (*(pDataline+iBps)&0xFC) << 3) ); - *(pScanline+2) = *(pDataline+3*iBps); - - pScanline += (pData->iColinc * 3); - pDataline += 4*iBps; - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* get alpha values */ - iFGa16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*(pScanline+2)); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* plain copy it */ - *(pScanline+1) = (mng_uint8)( (*(pDataline+4))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); - *pScanline = (mng_uint8)( (*(pDataline)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); - *(pScanline+2) = *(pDataline+6); - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - iBGr16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); - iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); - iBGb16 = (mng_uint16)( (*(pScanline )) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( (iFGb16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); - *pScanline = (mng_uint8) ( ( (iFGr16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); - } - else - { /* scale background up */ - iBGr16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); - iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); - iBGb16 = (mng_uint16)( (*(pScanline )) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( (iCb16 >> 8) & 0xF8 ) | ( (mng_uint8)(iCg16 >> 8) >> 5 ) ); - *pScanline = (mng_uint8) ( ( (iCr16 >> 11) ) | (((mng_uint8)(iCg16 >> 8) & 0xFC) << 3) ); - *(pScanline+2) = (mng_uint8)(iCa16 >> 8); - } - } - } - - pScanline += (pData->iColinc * 3); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *(pScanline+2); - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) &0xF8 ) | (*(pDataline+1) >>5 ) ); - *pScanline = (mng_uint8)( ( ((*(pDataline))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); - *(pScanline+2) = *(pDataline+3); - } - else - { - mng_uint8 iRed, iGreen, iBlue; - - iBlue = (mng_uint8) ( *(pScanline+1) & 0xF8 ); - iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); - iRed = (mng_uint8) ( (*pScanline << 3) ); - - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ - MNG_COMPOSE8 (iRed, *pDataline, iFGa8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iFGa8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iFGa8, iBlue ); - /* alpha remains fully opaque !!! */ - *(pScanline+1) = (mng_uint8) ( ( iBlue & 0xF8 ) | (iGreen>>5) ); - *pScanline = (mng_uint8) ( ( iRed >> 3 ) | ( (iGreen & 0xFC) << 3) ); - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - iRed , iGreen , iBlue , iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - - - *pScanline = (mng_uint8) ( ( iCr8 >> 3 ) | ( (iCg8 & 0xFC) << 3) ); - *(pScanline+1) = (mng_uint8) ( ( iCb8 & 0xF8 ) | (iCg8>>5) ); - *(pScanline+2) = (mng_uint8) iCa8; - } - } - } - - pScanline += (pData->iColinc *3); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA565, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_rgba565 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8, iCa8; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA565, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl * 3); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2))&0xF8 ) | ( (*(pDataline+1)>>5 ) ) ); - *pScanline = (mng_uint8)( ( *(pDataline) >>3 ) | ( (*(pDataline+1)&0xFC ) << 3) ); - *(pScanline+2) = *(pDataline+3); - - pScanline += (pData->iColinc * 3); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iFGa8 = *(pDataline+3); /* get alpha values */ - iBGa8 = *(pScanline+2); - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) &0xF8 ) | (*(pDataline+1) >>5 ) ); - *pScanline = (mng_uint8)( ( ((*(pDataline))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); - *(pScanline+2) = *(pDataline+3); - } - else - { - mng_uint8 iRed, iGreen, iBlue; - - iBlue = (mng_uint8) ( *(pScanline+1) & 0xF8 ); - iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); - iRed = (mng_uint8) ( (*pScanline << 3) ); - - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ - MNG_COMPOSE8 (iRed, *pDataline, iFGa8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iFGa8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iFGa8, iBlue ); - /* alpha remains fully opaque !!! */ - *(pScanline+1) = (mng_uint8) ( ( iBlue & 0xF8 ) | (iGreen>>5) ); - *pScanline = (mng_uint8) ( ( iRed >> 3 ) | ( (iGreen & 0xFC) << 3) ); - } - else - { /* now blend */ - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, - iRed , iGreen , iBlue , iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - - - *pScanline = (mng_uint8) ( ( iCr8 >> 3 ) | ( (iCg8 & 0xFC) << 3) ); - *(pScanline+1) = (mng_uint8) ( ( iCb8 & 0xF8 ) | (iCg8>>5) ); - *(pScanline+2) = (mng_uint8) iCa8; - } - } - } - - pScanline += (pData->iColinc *3); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA565, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_RGBA565 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_BGR565_A8 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_bgr565_a8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pAlphaline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16, iBGa16; - mng_uint16 iCr16, iCg16, iCb16, iCa16; - mng_uint8 iA8, iBGa8, iCa8; - mng_uint8 iCr8, iCg8, iCb8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565_A8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - pAlphaline = (mng_uint8p)pData->fGetalphaline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row -starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pAlphaline = pAlphaline + pData->iCol + pData->iDestl; - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ((*(pDataline+2)>>5) ) ); - *pScanline = (mng_uint8)( ( (*(pDataline+4)) >>3) | ((*(pDataline+2)&0xFC) << 3) ); - *pAlphaline = (mng_uint8)(*(pDataline+6)); - - pScanline += (pData->iColinc * 2); - pAlphaline += pData->iColinc; - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ((*(pDataline+1)>>5 ) ) ); - *pScanline = (mng_uint8)( ( *(pDataline+2) >>3 ) | ((*(pDataline+1)&0xFC ) << 3) ); - *pAlphaline = (mng_uint8)(*(pDataline+3)); - - pScanline += (pData->iColinc * 2); - pAlphaline += pData->iColinc; - pDataline += 4; - } - } - } - else /* Not fully opaque */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*pAlphaline); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iA16) /* any opacity at all ? */ - { - if ((iA16 == 0xFFFF) || (iBGa16 == 0)) /* fully opaque or background fully transparent ? */ - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( (*(pDataline))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); - *pScanline = (mng_uint8)( (*(pDataline+4)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); - *pAlphaline = *(pDataline+6); - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { - /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - - iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); - iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); - iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( (iFGr16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); - *pScanline = (mng_uint8) ( ( (iFGb16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); - *pAlphaline = (mng_uint8)(iA16>>8); - } - else /* background is not fully opaque */ - { /* scale background up */ - iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); - iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); - iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iA16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( (iCr16 >> 8)&0xF8 ) | ( (mng_uint8)(iCg16>>8) >> 5) ); - *pScanline = (mng_uint8) ( ( (iCb16>>11) ) | (((mng_uint8)(iCg16>>8)&0xFC) << 3) ); - *pAlphaline = (mng_uint8)(iCa16 >> 8); - } - } - } - - pScanline += (pData->iColinc * 2); - pAlphaline += pData->iColinc; - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; -iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - iBGa8 = *pAlphaline; - - if (iA8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iA8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); - *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); - *pAlphaline = *(pDataline+3); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { - /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); - iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | (((*pScanline) & 0xE0)>>3 ) ); - iBlue = (mng_uint8) ( (*pScanline << 3) ); - - MNG_COMPOSE8 (iRed, *pDataline, iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); - *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ((iGreen & 0xFC) << 3) ); - *pAlphaline = iA8; - } - else /* background not fully opaque */ - { - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iA8, - *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( iCr8 & 0xF8 ) | (iCg8>>5) ); - *pScanline = (mng_uint8) ( ( iCb8 >> 3 ) | ((iCg8 & 0xFC) << 3) ); - *pAlphaline = iCa8; - } - } - } - - pScanline += (pData->iColinc * 2); - pAlphaline += pData->iColinc; - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565_A8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_bgr565_a8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pAlphaline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16, iBGa16; - mng_uint16 iCr16, iCg16, iCb16, iCa16; - mng_uint8 iA8, iBGa8, iCa8; - mng_uint8 iCr8, iCg8, iCb8; - mng_uint8 iBps; - - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565_A8, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - pAlphaline = (mng_uint8p)pData->fGetalphaline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row -starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pAlphaline = pAlphaline + pData->iCol + pData->iDestl; - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | - ((*(pDataline+iBps)>>5) ) ); - *pScanline = (mng_uint8)( ( (*(pDataline+2*iBps)) >>3) | - ((*(pDataline+iBps)&0xFC) << 3) ); - *pAlphaline = (mng_uint8)(*(pDataline+6)); - - pScanline += (pData->iColinc * 2); - pAlphaline += pData->iColinc; - pDataline += 8; - } - } - else /* Not fully opaque */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA16 = mng_get_uint16 (pDataline+6); - iBGa16 = (mng_uint16)(*pAlphaline); - iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; - - if (iA16) /* any opacity at all ? */ - { - if ((iA16 == 0xFFFF) || (iBGa16 == 0)) /* fully opaque or background fully transparent ? */ - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( (*(pDataline))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); - *pScanline = (mng_uint8)( (*(pDataline+4)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); - *pAlphaline = *(pDataline+6); - } - else - { - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { - /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - /* scale background up */ - - iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); - iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); - iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( (iFGr16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); - *pScanline = (mng_uint8) ( ( (iFGb16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); - *pAlphaline = (mng_uint8)(iA16>>8); - } - else /* background is not fully opaque */ - { /* scale background up */ - iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); - iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); - iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* let's blend */ - MNG_BLEND16 (mng_get_uint16 (pDataline ), - mng_get_uint16 (pDataline+2), - mng_get_uint16 (pDataline+4), iA16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( (iCr16 >> 8)&0xF8 ) | ( (mng_uint8)(iCg16>>8) >> 5) ); - *pScanline = (mng_uint8) ( ( (iCb16>>11) ) | (((mng_uint8)(iCg16>>8)&0xFC) << 3) ); - *pAlphaline = (mng_uint8)(iCa16 >> 8); - } - } - } - - pScanline += (pData->iColinc * 2); - pAlphaline += pData->iColinc; - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; -iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - iBGa8 = *pAlphaline; - - if (iA8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iA8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); - *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); - *pAlphaline = *(pDataline+3); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { - /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); - iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | (((*pScanline) & 0xE0)>>3 ) ); - iBlue = (mng_uint8) ( (*pScanline << 3) ); - - MNG_COMPOSE8 (iRed, *pDataline, iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); - *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ((iGreen & 0xFC) << 3) ); - *pAlphaline = iA8; - } - else /* background not fully opaque */ - { - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iA8, - *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( iCr8 & 0xF8 ) | (iCg8>>5) ); - *pScanline = (mng_uint8) ( ( iCb8 >> 3 ) | ((iCg8 & 0xFC) << 3) ); - *pAlphaline = iCa8; - } - } - } - - pScanline += (pData->iColinc * 2); - pAlphaline += pData->iColinc; - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565_A8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_bgr565_a8 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pAlphaline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iA8, iBGa8, iCa8; - mng_uint8 iCr8, iCg8, iCb8; - - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565_A8, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - pAlphaline = (mng_uint8p)pData->fGetalphaline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row -starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pAlphaline = pAlphaline + pData->iCol + pData->iDestl; - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ((*(pDataline+1)>>5 ) ) ); - *pScanline = (mng_uint8)( ( *(pDataline+2) >>3 ) | ((*(pDataline+1)&0xFC ) << 3) ); - *pAlphaline = (mng_uint8)(*(pDataline+3)); - - pScanline += (pData->iColinc * 2); - pAlphaline += pData->iColinc; - pDataline += 4; - } - } - } - else /* Not fully opaque */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; -iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - iBGa8 = *pAlphaline; - - if (iA8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iA8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); - *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); - *pAlphaline = *(pDataline+3); - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { - /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); - iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | (((*pScanline) & 0xE0)>>3 ) ); - iBlue = (mng_uint8) ( (*pScanline << 3) ); - - MNG_COMPOSE8 (iRed, *pDataline, iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); - *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ((iGreen & 0xFC) << 3) ); - *pAlphaline = iA8; - } - else /* background not fully opaque */ - { - MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iA8, - *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8) ( ( iCr8 & 0xF8 ) | (iCg8>>5) ); - *pScanline = (mng_uint8) ( ( iCb8 >> 3 ) | ((iCg8 & 0xFC) << 3) ); - *pAlphaline = iCa8; - } - } - } - - pScanline += (pData->iColinc * 2); - pAlphaline += pData->iColinc; - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565_A8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_BGR565_A8 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_RGB555 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_rgb555 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint8 iA8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB555, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline+4) & 0xF8) >> 1 ) | (*(pDataline+2) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+2) & 0xF8) << 2 ) ); - - pScanline += (pData->iColinc * 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline+2) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA16 = mng_get_uint16 (pDataline+6); - - if (iA16) /* any opacity at all ? */ - { - if (iA16 == 0xFFFF) /* fully opaque ? */ - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline+4) & 0xF8) >> 1 ) | (*(pDataline+2) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+2) & 0xF8) << 2 ) ); - } - else - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - - /* scale background up */ - iBGr16 = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); - iBGg16 = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); - iBGb16 = (mng_uint8)( *(pScanline ) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8)( (mng_uint8)(((iFGb16 >> 8) & 0xF8) >> 1 ) | ( (mng_uint8)(iFGg16 >> 8) >> 6 ) ); - *pScanline = (mng_uint8)( (mng_uint8) ((iFGr16 >>11) >> 3 ) | ( ( (mng_uint8)(iFGg16 >> 8) & 0xF8) << 2 ) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline+2) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); - } - else - { /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); - iGreen = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); - iBlue = (mng_uint8)( *(pScanline ) << 3 ); - - MNG_COMPOSE8 (iRed, *(pDataline+2), iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+0), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8)( ( (iRed & 0xF8) >> 1 ) | ( iGreen >> 6 ) ); - *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xF8) << 2 ) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB555, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_rgb555 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint8 iA8; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB555, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline+2*iBps) & 0xF8) >> 1 ) | (*(pDataline+iBps) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+iBps) & 0xF8) << 2 ) ); - - pScanline += (pData->iColinc * 2); - pDataline += 4*iBps; - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA16 = mng_get_uint16 (pDataline+6); - - if (iA16) /* any opacity at all ? */ - { - if (iA16 == 0xFFFF) /* fully opaque ? */ - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline+4) & 0xF8) >> 1 ) | (*(pDataline+2) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+2) & 0xF8) << 2 ) ); - } - else - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - - /* scale background up */ - iBGr16 = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); - iBGg16 = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); - iBGb16 = (mng_uint8)( *(pScanline ) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8)( (mng_uint8)(((iFGb16 >> 8) & 0xF8) >> 1 ) | ( (mng_uint8)(iFGg16 >> 8) >> 6 ) ); - *pScanline = (mng_uint8)( (mng_uint8) ((iFGr16 >>11) >> 3 ) | ( ( (mng_uint8)(iFGg16 >> 8) & 0xF8) << 2 ) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline+2) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); - } - else - { /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); - iGreen = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); - iBlue = (mng_uint8)( *(pScanline ) << 3 ); - - MNG_COMPOSE8 (iRed, *(pDataline+2), iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+0), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8)( ( (iRed & 0xF8) >> 1 ) | ( iGreen >> 6 ) ); - *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xF8) << 2 ) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB555, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_rgb555 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iA8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB555, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline+2) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline+2) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); - } - else - { /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); - iGreen = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); - iBlue = (mng_uint8)( *(pScanline ) << 3 ); - - MNG_COMPOSE8 (iRed, *(pDataline+2), iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+0), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8)( ( (iRed & 0xF8) >> 1 ) | ( iGreen >> 6 ) ); - *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xF8) << 2 ) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_RGB555, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_RGB555 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_BGR555 -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE -mng_retcode mng_display_bgr555 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint8 iA8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR555, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pDataline = pData->pRGBArow; /* address source row */ - - if (pData->bIsRGBA16) /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); - else - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+2) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline+4) >> 3 ) | ((*(pDataline+2) & 0xF8) << 2 ) ); - - pScanline += (pData->iColinc * 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline+2) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA16 = mng_get_uint16 (pDataline+6); - - if (iA16) /* any opacity at all ? */ - { - if (iA16 == 0xFFFF) /* fully opaque ? */ - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+2) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline+4) >> 3 ) | ((*(pDataline+2) & 0xF8) << 2 ) ); - } - else - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - - /* scale background up */ - iBGb16 = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); - iBGg16 = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); - iBGr16 = (mng_uint8)( *(pScanline ) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8)( (mng_uint8)(((iFGr16 >> 8) & 0xF8) >> 1 ) | ( (mng_uint8)(iFGg16 >> 8) >> 6 ) ); - *pScanline = (mng_uint8)( (mng_uint8) ((iFGb16 >>11) >> 3 ) | ( ( (mng_uint8)(iFGg16 >> 8) & 0xF8) << 2 ) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline+2) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); - } - else - { /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); - iGreen = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); - iBlue = (mng_uint8)( *(pScanline ) << 3 ); - - MNG_COMPOSE8 (iRed, *(pDataline+0), iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8)( ( (iRed & 0xF8) >> 1 ) | ( iGreen >> 6 ) ); - *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xF8) << 2 ) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR555, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -mng_retcode mng_display_bgr555 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint16 iA16; - mng_uint16 iFGr16, iFGg16, iFGb16; - mng_uint16 iBGr16, iBGg16, iBGb16; - mng_uint8 iA8; - mng_uint8 iBps; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR555, MNG_LC_START); -#endif - - iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pDataline = pData->pRGBArow; /* address source row */ - - /* adjust source row starting-point */ - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+iBps) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline+2*iBps) >> 3 ) | ((*(pDataline+iBps) & 0xF8) << 2 ) ); - - pScanline += (pData->iColinc * 2); - pDataline += 4*iBps; - } - } - else - { - if (pData->bIsRGBA16) /* 16-bit input row ? */ - { - - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA16 = mng_get_uint16 (pDataline+6); - - if (iA16) /* any opacity at all ? */ - { - if (iA16 == 0xFFFF) /* fully opaque ? */ - { /* scale down by dropping the LSB */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+2) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline+4) >> 3 ) | ((*(pDataline+2) & 0xF8) << 2 ) ); - } - else - { /* get the proper values */ - iFGr16 = mng_get_uint16 (pDataline ); - iFGg16 = mng_get_uint16 (pDataline+2); - iFGb16 = mng_get_uint16 (pDataline+4); - - /* scale background up */ - iBGb16 = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); - iBGg16 = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); - iBGr16 = (mng_uint8)( *(pScanline ) << 3 ); - - iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; - iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; - iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; - /* now compose */ - MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); - MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); - MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); - /* and return the composed values */ - *(pScanline+1) = (mng_uint8)( (mng_uint8)(((iFGr16 >> 8) & 0xF8) >> 1 ) | ( (mng_uint8)(iFGg16 >> 8) >> 6 ) ); - *pScanline = (mng_uint8)( (mng_uint8) ((iFGb16 >>11) >> 3 ) | ( ( (mng_uint8)(iFGg16 >> 8) & 0xF8) << 2 ) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 8; - } - } - else - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline+2) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); - } - else - { /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); - iGreen = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); - iBlue = (mng_uint8)( *(pScanline ) << 3 ); - - MNG_COMPOSE8 (iRed, *(pDataline+0), iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8)( ( (iRed & 0xF8) >> 1 ) | ( iGreen >> 6 ) ); - *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xF8) << 2 ) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR555, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ -#else /* MNG_NO_16BIT_SUPPORT */ -mng_retcode mng_display_bgr555 (mng_datap pData) -{ - mng_uint8p pScanline; - mng_uint8p pDataline; - mng_int32 iX; - mng_uint8 iA8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR555, MNG_LC_START); -#endif - /* viewable row ? */ - if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) - { /* address destination row */ - pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), - pData->iRow + pData->iDestt - - pData->iSourcet); - /* adjust destination row starting-point */ - pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); - pDataline = pData->pRGBArow; /* address source row */ - - pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); - - if (pData->bIsOpaque) /* forget about transparency ? */ - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { /* copy the values */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline+2) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - else - { - { - for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; - iX += pData->iColinc) - { - iA8 = *(pDataline+3); /* get alpha value */ - - if (iA8) /* any opacity at all ? */ - { - if (iA8 == 0xFF) /* fully opaque ? */ - { /* then simply copy the values */ - *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); - *pScanline = (mng_uint8)( ( *(pDataline+2) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); - } - else - { /* do alpha composing */ - mng_uint8 iRed, iGreen, iBlue; - - iRed = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); - iGreen = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); - iBlue = (mng_uint8)( *(pScanline ) << 3 ); - - MNG_COMPOSE8 (iRed, *(pDataline+0), iA8, iRed ); - MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); - MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); - - *(pScanline+1) = (mng_uint8)( ( (iRed & 0xF8) >> 1 ) | ( iGreen >> 6 ) ); - *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xF8) << 2 ) ); - } - } - - pScanline += (pData->iColinc * 2); - pDataline += 4; - } - } - } - } - - check_update_region (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_BGR555, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_SKIPCANVAS_BGR555 */ - - -#ifndef MNG_SKIPCHUNK_BACK -/* ************************************************************************** */ -/* * * */ -/* * Background restore routines - restore the background with info from * */ -/* * the BACK and/or bKGD chunk or the app's background canvas * */ -/* * * */ -/* ************************************************************************** */ - -mng_retcode mng_restore_bkgd_backimage (mng_datap pData) -{ - /* save some stuff */ - mng_uint8p pRGBArow = pData->pRGBArow; - mng_int32 iRow = pData->iRow; - mng_int32 iRowsamples = pData->iRowsamples; - - mng_retcode iRetcode; /* work variables */ - mng_uint8p pTemp; - mng_uint8p pWork = pRGBArow; - mng_uint32 iX; - mng_int32 iZ; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_BACKIMAGE, MNG_LC_START); -#endif - /* determine row to retrieve */ - pData->iRow = pData->iDestt + iRow + pData->iBackimgoffsy; - - while (pData->iRow >= (mng_int32)pData->iBackimgheight) - pData->iRow -= (mng_int32)pData->iBackimgheight; - /* set width to that of background image */ - pData->iRowsamples = pData->iBackimgwidth; - /* retrieve into alternate buffer ! */ - pData->pRGBArow = pData->pPrevrow; - /* get it then */ - iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData); - - if (iRetcode) /* on error; bail out */ - return iRetcode; - /* we got the full row; but now need to - paste it into the proper location */ - iX = pData->iDestl - pData->iBackimgoffsx; - - while (iX >= pData->iBackimgwidth) - iX -= pData->iBackimgwidth; - -#ifndef MNG_NO_16BIT_SUPPORT - if (pData->bIsRGBA16) /* 16-bit buffer ? */ - { - pTemp = pData->pPrevrow + (iX << 3); - - for (iZ = (pData->iDestr - pData->iDestl); iZ > 0; iZ--) - { - MNG_COPY (pWork, pTemp, 8); - - pWork += 8; - pTemp += 8; - iX++; - /* reached end of bkgd-image line ? */ - if (iX >= pData->iBackimgwidth) - { - iX = 0; - pTemp = pData->pPrevrow; - } - } - } - else -#endif - { - pTemp = pData->pPrevrow + (iX << 2); - - for (iZ = (pData->iDestr - pData->iDestl); iZ > 0; iZ--) - { - MNG_COPY (pWork, pTemp, 4); - - pWork += 4; - pTemp += 4; - iX++; - /* reached end of bkgd-image line ? */ - if (iX >= pData->iBackimgwidth) - { - iX = 0; - pTemp = pData->pPrevrow; - } - } - } - - pData->pRGBArow = pRGBArow; /* restore original values */ - pData->iRow = iRow; - pData->iRowsamples = iRowsamples; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_BACKIMAGE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_restore_bkgd_backcolor (mng_datap pData) -{ - mng_int32 iX; - mng_uint32p pWork32 = (mng_uint32p)pData->pRGBArow; - mng_uint32 iWrite; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_BACKCOLOR, MNG_LC_START); -#endif - -#ifdef MNG_BIGENDIAN_SUPPORTED - /* fast way for big endian */ - iWrite = (((mng_uint8)(pData->iBACKred >> 8)) << 24) | - (((mng_uint8)(pData->iBACKgreen >> 8)) << 16) | - (((mng_uint8)(pData->iBACKblue >> 8)) << 8) | - ( 0xFF ); -#elif defined(MNG_LITTLEENDIAN_SUPPORTED) - /* fast way for little endian */ - iWrite = ( 0xFF << 24) | - (((mng_uint8)(pData->iBACKblue >> 8)) << 16) | - (((mng_uint8)(pData->iBACKgreen >> 8)) << 8) | - (((mng_uint8)(pData->iBACKred >> 8)) ); -#else - /* generic way, works on all platforms */ - /* put the data in memory in the correct order */ - { - mng_uint8 aBytes[4]; - aBytes[0] = (mng_uint8)(pData->iBACKred >> 8); - aBytes[1] = (mng_uint8)(pData->iBACKgreen >> 8); - aBytes[2] = (mng_uint8)(pData->iBACKblue >> 8); - aBytes[3] = 0xFF; - /* load that data into a register */ - iWrite = *(mng_uint32*) aBytes; - } -#endif - /* ok; drop the background-color in there */ - for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) - *pWork32++ = iWrite; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_BACKCOLOR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_bKGD -mng_retcode mng_restore_bkgd_bkgd (mng_datap pData) -{ - mng_int32 iX; - mng_uint8p pWork = pData->pRGBArow; - mng_imagep pImage = (mng_imagep)pData->pCurrentobj; - mng_imagedatap pBuf = pImage->pImgbuf; - mng_uint8 iRed = 0; - mng_uint8 iGreen = 0; - mng_uint8 iBlue = 0; - mng_uint32p pWork32 = (mng_uint32p)pWork; - mng_uint32 iWrite; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_BKGD, MNG_LC_START); -#endif - - switch (pBuf->iColortype) - { - case 0 : ; /* gray types */ - case 4 : { - mng_uint8 iGray; - -#ifndef MNG_NO_16BIT_SUPPORT - if (pBuf->iBitdepth > 8) - iGray = (mng_uint8)(pBuf->iBKGDgray >> 8); - else -#endif - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - /* LBR scaling */ - mng_uint8 multiplier[]={0,255,85,0,17,0,0,0,1}; - iGray = (mng_uint8)(multiplier[pBuf->iBitdepth] * pBuf->iBKGDgray); -#else - iGray = (mng_uint8)pBuf->iBKGDgray; -#endif - } - - iRed = iGray; - iGreen = iGray; - iBlue = iGray; - - break; - } - - case 3 : { /* indexed type */ - iRed = pBuf->aPLTEentries [pBuf->iBKGDindex].iRed; - iGreen = pBuf->aPLTEentries [pBuf->iBKGDindex].iGreen; - iBlue = pBuf->aPLTEentries [pBuf->iBKGDindex].iBlue; - - break; - } - - case 2 : ; /* rgb types */ - case 6 : { -#ifndef MNG_NO_16BIT_SUPPORT - if (pBuf->iBitdepth > 8) - { - iRed = (mng_uint8)(pBuf->iBKGDred >> 8); - iGreen = (mng_uint8)(pBuf->iBKGDgreen >> 8); - iBlue = (mng_uint8)(pBuf->iBKGDblue >> 8); - } - else -#endif - { - iRed = (mng_uint8)(pBuf->iBKGDred ); - iGreen = (mng_uint8)(pBuf->iBKGDgreen); - iBlue = (mng_uint8)(pBuf->iBKGDblue ); - } - - break; - } - } - -#ifdef MNG_BIGENDIAN_SUPPORTED - /* fast way for big endian */ - iWrite = (iRed << 24) | - (iGreen << 16) | - (iBlue << 8); -#elif defined(MNG_LITTLEENDIAN_SUPPORTED) - /* fast way for little endian */ - iWrite = (iBlue << 16) | - (iGreen << 8) | - (iRed ); -#else - /* generic way, works on all platforms */ - /* put the data in memory in the correct order */ - { - mng_uint8 aBytes[4]; - aBytes[0] = (mng_uint8)(iRed); - aBytes[1] = (mng_uint8)(iGreen); - aBytes[2] = (mng_uint8)(iBlue); - aBytes[3] = 0x00; - /* load that data into a register */ - iWrite = *(mng_uint32*) aBytes; - } -#endif - /* ok; drop it in there */ - for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) - *pWork32++ = iWrite; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_BKGD, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_restore_bkgd_bgcolor (mng_datap pData) -{ - mng_int32 iX; - mng_uint32p pWork32 = (mng_uint32p)pData->pRGBArow; - mng_uint32 iWrite; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_BGCOLOR, MNG_LC_START); -#endif - -#ifdef MNG_BIGENDIAN_SUPPORTED - /* fast way for big endian */ - iWrite = (((mng_uint8)(pData->iBGred >> 8)) << 24) | - (((mng_uint8)(pData->iBGgreen >> 8)) << 16) | - (((mng_uint8)(pData->iBGblue >> 8)) << 8); -#elif defined(MNG_LITTLEENDIAN_SUPPORTED) - /* fast way for little endian */ - iWrite = (((mng_uint8)(pData->iBGblue >> 8)) << 16) | - (((mng_uint8)(pData->iBGgreen >> 8)) << 8) | - (((mng_uint8)(pData->iBGred >> 8)) ); -#else - /* generic way, works on all platforms */ - /* put the data in memory in the correct order */ - { - mng_uint8 aBytes[4]; - aBytes[0] = (mng_uint8)(pData->iBGred >> 8); - aBytes[1] = (mng_uint8)(pData->iBGgreen >> 8); - aBytes[2] = (mng_uint8)(pData->iBGblue >> 8); - aBytes[3] = 0x00; - /* load that data into a register */ - iWrite = *(mng_uint32*) aBytes; - } -#endif - /* ok; drop the background-color in there */ - for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) - *pWork32++ = iWrite; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_BGCOLOR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_RGB8 -mng_retcode mng_restore_bkgd_rgb8 (mng_datap pData) -{ - mng_int32 iX; - mng_uint8p pBkgd; - mng_uint8p pWork = pData->pRGBArow; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_RGB8, MNG_LC_START); -#endif - - if (pData->fGetbkgdline) /* can we access the background ? */ - { /* point to the right pixel then */ - pBkgd = (mng_uint8p)pData->fGetbkgdline ((mng_handle)pData, - pData->iRow + pData->iDestt) + - (3 * pData->iDestl); - - for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) - { - *pWork = *pBkgd; /* ok; copy the pixel */ - *(pWork+1) = *(pBkgd+1); - *(pWork+2) = *(pBkgd+2); - *(pWork+3) = 0x00; /* transparant for alpha-canvasses */ - - pWork += 4; - pBkgd += 3; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_RGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SKIPCANVAS_RGB8 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_BGR8 -mng_retcode mng_restore_bkgd_bgr8 (mng_datap pData) -{ - mng_int32 iX; - mng_uint8p pBkgd; - mng_uint8p pWork = pData->pRGBArow; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_BGR8, MNG_LC_START); -#endif - - if (pData->fGetbkgdline) /* can we access the background ? */ - { /* point to the right pixel then */ - pBkgd = (mng_uint8p)pData->fGetbkgdline ((mng_handle)pData, - pData->iRow + pData->iDestt) + - (3 * pData->iDestl); - - for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) - { - *pWork = *(pBkgd+2); /* ok; copy the pixel */ - *(pWork+1) = *(pBkgd+1); - *(pWork+2) = *pBkgd; - *(pWork+3) = 0x00; /* transparant for alpha-canvasses */ - - pWork += 4; - pBkgd += 3; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_BGR8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SKIPCANVAS_BGR8 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_BGRX8 -mng_retcode mng_restore_bkgd_bgrx8 (mng_datap pData) -{ - mng_int32 iX; - mng_uint8p pBkgd; - mng_uint8p pWork = pData->pRGBArow; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_BGRX8, MNG_LC_START); -#endif - - if (pData->fGetbkgdline) /* can we access the background ? */ - { /* point to the right pixel then */ - pBkgd = (mng_uint8p)pData->fGetbkgdline ((mng_handle)pData, - pData->iRow + pData->iDestt) + - (3 * pData->iDestl); - - for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) - { - *pWork = *(pBkgd+2); /* ok; copy the pixel */ - *(pWork+1) = *(pBkgd+1); - *(pWork+2) = *pBkgd; - *(pWork+3) = 0x00; /* transparant for alpha-canvasses */ - - pWork += 4; - pBkgd += 4; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_BGRX8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SKIPCANVAS_BGRX8 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_BGR565 -mng_retcode mng_restore_bkgd_bgr565 (mng_datap pData) -{ - mng_int32 iX; - mng_uint8p pBkgd; - mng_uint8p pWork = pData->pRGBArow; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_BGR565, MNG_LC_START); -#endif - - if (pData->fGetbkgdline) /* can we access the background ? */ - { /* point to the right pixel then */ - pBkgd = (mng_uint8p)pData->fGetbkgdline ((mng_handle)pData, - pData->iRow + pData->iDestt) + - (3 * pData->iDestl); - - for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) - { - *pWork = (mng_uint8)( *(pBkgd+1) & 0xF8); /* ok; copy the pixel */ - *(pWork+1) = (mng_uint8)( (*(pBkgd+1) << 5 ) | ( ((*pBkgd)&0xE0)>>3 ) ); - *(pWork+2) = (mng_uint8)( *(pBkgd) << 3 ); - *(pWork+3) = 0x00; /* transparant for alpha-canvasses */ - - pWork += 4; - pBkgd += 2; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_BGR565, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SKIPCANVAS_BGR565 */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCANVAS_RGB565 -mng_retcode mng_restore_bkgd_rgb565 (mng_datap pData) -{ - mng_int32 iX; - mng_uint8p pBkgd; - mng_uint8p pWork = pData->pRGBArow; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_RGB565, MNG_LC_START); -#endif - - if (pData->fGetbkgdline) /* can we access the background ? */ - { /* point to the right pixel then */ - pBkgd = (mng_uint8p)pData->fGetbkgdline ((mng_handle)pData, - pData->iRow + pData->iDestt) + - (3 * pData->iDestl); - - for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) - { - *pWork = (mng_uint8)( *(pBkgd)&0xF8); /* ok; copy the pixel */ - *(pWork+1) = (mng_uint8)( (*(pBkgd+1) << 5) | ( ((*pBkgd)&0xE0)>>3 ) ); - *(pWork+2) = (mng_uint8)( *(pBkgd+1) << 3); - *(pWork+3) = 0x00; /* transparant for alpha-canvasses */ - - pWork += 4; - pBkgd += 2; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RESTORE_RGB565, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SKIPCANVAS_RBB565 */ - - -/* ************************************************************************** */ -/* * * */ -/* * Row retrieval routines - retrieve processed & uncompressed row-data * */ -/* * from the current "object" * */ -/* * * */ -/* ************************************************************************** */ - -/* TODO: a serious optimization is to retrieve only those pixels that will - actually be displayed; this would require changes in - the "display_image" routine (in mng_display.c) & - all the "retrieve_xxx" routines below & - the "display_xxx" routines above !!!!! - NOTE that "correct_xxx" routines would not require modification */ - -mng_retcode mng_retrieve_g8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint8 iG; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_G8, MNG_LC_START); -#endif - - pRGBArow = pData->pRGBArow; /* temporary work pointers */ - pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); - - if (pBuf->bHasTRNS) /* tRNS in buffer ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iG = *pWorkrow; /* get the gray-value */ - /* is it transparent ? */ - if ((mng_uint16)iG == pBuf->iTRNSgray) - { - *pRGBArow = 0x00; /* nuttin to display */ - *(pRGBArow+1) = 0x00; - *(pRGBArow+2) = 0x00; - *(pRGBArow+3) = 0x00; - } - else - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - mng_uint8 multiplier[]={0,255,85,0,17,0,0,0,1}; - iG = (mng_uint8)(iG * multiplier[pBuf->iBitdepth]); -#endif - - *pRGBArow = iG; /* put in intermediate row */ - *(pRGBArow+1) = iG; - *(pRGBArow+2) = iG; - *(pRGBArow+3) = 0xFF; - } - - pWorkrow++; /* next pixel */ - pRGBArow += 4; - } - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - mng_uint8 multiplier[]={0,255,85,0,17,0,0,0,1}; /* LBR scaling */ - iG = (mng_uint8)(multiplier[pBuf->iBitdepth] * *pWorkrow); -#else - iG = *pWorkrow; /* get the gray-value */ -#endif - - *pRGBArow = iG; /* put in intermediate row */ - *(pRGBArow+1) = iG; - *(pRGBArow+2) = iG; - *(pRGBArow+3) = 0xFF; - - pWorkrow++; /* next pixel */ - pRGBArow += 4; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_G8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_retrieve_g16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint16 iG; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_G16, MNG_LC_START); -#endif - /* temporary work pointers */ - pRGBArow = pData->pRGBArow; - pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); - - if (pBuf->bHasTRNS) /* tRNS in buffer ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iG = mng_get_uint16 (pWorkrow); /* get the gray-value */ - /* is it transparent ? */ - if (iG == pBuf->iTRNSgray) - { /* nuttin to display */ - mng_put_uint16 (pRGBArow, 0x0000); - mng_put_uint16 (pRGBArow+2, 0x0000); - mng_put_uint16 (pRGBArow+4, 0x0000); - mng_put_uint16 (pRGBArow+6, 0x0000); - } - else - { /* put in intermediate row */ - mng_put_uint16 (pRGBArow, iG); - mng_put_uint16 (pRGBArow+2, iG); - mng_put_uint16 (pRGBArow+4, iG); - mng_put_uint16 (pRGBArow+6, 0xFFFF); - } - - pWorkrow += 2; /* next pixel */ - pRGBArow += 8; - } - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iG = mng_get_uint16 (pWorkrow); /* get the gray-value */ - - mng_put_uint16 (pRGBArow, iG); /* and put in intermediate row */ - mng_put_uint16 (pRGBArow+2, iG); - mng_put_uint16 (pRGBArow+4, iG); - mng_put_uint16 (pRGBArow+6, 0xFFFF); - - pWorkrow += 2; /* next pixel */ - pRGBArow += 8; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_G16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_retrieve_rgb8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint8 iR, iG, iB; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_RGB8, MNG_LC_START); -#endif - - pRGBArow = pData->pRGBArow; /* temporary work pointers */ - pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); - - if (pBuf->bHasTRNS) /* tRNS in buffer ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iR = *pWorkrow; /* get the rgb-values */ - iG = *(pWorkrow+1); - iB = *(pWorkrow+2); - /* is it transparent ? */ - if (((mng_uint16)iR == pBuf->iTRNSred ) && - ((mng_uint16)iG == pBuf->iTRNSgreen) && - ((mng_uint16)iB == pBuf->iTRNSblue ) ) - { - *pRGBArow = 0x00; /* nothing to display */ - *(pRGBArow+1) = 0x00; - *(pRGBArow+2) = 0x00; - *(pRGBArow+3) = 0x00; - } - else - { - *pRGBArow = iR; /* put in intermediate row */ - *(pRGBArow+1) = iG; - *(pRGBArow+2) = iB; - *(pRGBArow+3) = 0xFF; - } - - pWorkrow += 3; /* next pixel */ - pRGBArow += 4; - } - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pRGBArow = *pWorkrow; /* just copy the pixel */ - *(pRGBArow+1) = *(pWorkrow+1); - *(pRGBArow+2) = *(pWorkrow+2); - *(pRGBArow+3) = 0xFF; - - pWorkrow += 3; /* next pixel */ - pRGBArow += 4; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_RGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_retrieve_rgb16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint16 iR, iG, iB; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_RGB16, MNG_LC_START); -#endif - /* temporary work pointers */ - pRGBArow = pData->pRGBArow; - pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); - - if (pBuf->bHasTRNS) /* tRNS in buffer ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iR = mng_get_uint16 (pWorkrow); /* get the rgb-values */ - iG = mng_get_uint16 (pWorkrow+2); - iB = mng_get_uint16 (pWorkrow+4); - /* is it transparent ? */ - if ((iR == pBuf->iTRNSred ) && - (iG == pBuf->iTRNSgreen) && - (iB == pBuf->iTRNSblue ) ) - { /* nothing to display */ - mng_put_uint16 (pRGBArow, 0x0000); - mng_put_uint16 (pRGBArow+2, 0x0000); - mng_put_uint16 (pRGBArow+4, 0x0000); - mng_put_uint16 (pRGBArow+6, 0x0000); - } - else - { /* put in intermediate row */ - mng_put_uint16 (pRGBArow, iR); - mng_put_uint16 (pRGBArow+2, iG); - mng_put_uint16 (pRGBArow+4, iB); - mng_put_uint16 (pRGBArow+6, 0xFFFF); - } - - pWorkrow += 6; /* next pixel */ - pRGBArow += 8; - } - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* just copy the pixel */ - mng_put_uint16 (pRGBArow, mng_get_uint16 (pWorkrow )); - mng_put_uint16 (pRGBArow+2, mng_get_uint16 (pWorkrow+2)); - mng_put_uint16 (pRGBArow+4, mng_get_uint16 (pWorkrow+4)); - mng_put_uint16 (pRGBArow+6, 0xFFFF); - - pWorkrow += 6; /* next pixel */ - pRGBArow += 8; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_RGB16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_retrieve_idx8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint8 iQ; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_IDX8, MNG_LC_START); -#endif - - pRGBArow = pData->pRGBArow; /* temporary work pointers */ - pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); - - if (pBuf->bHasTRNS) /* tRNS in buffer ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iQ = *pWorkrow; /* get the index */ - /* is it valid ? */ - if ((mng_uint32)iQ < pBuf->iPLTEcount) - { /* put in intermediate row */ - *pRGBArow = pBuf->aPLTEentries [iQ].iRed; - *(pRGBArow+1) = pBuf->aPLTEentries [iQ].iGreen; - *(pRGBArow+2) = pBuf->aPLTEentries [iQ].iBlue; - /* transparency for this index ? */ - if ((mng_uint32)iQ < pBuf->iTRNScount) - *(pRGBArow+3) = pBuf->aTRNSentries [iQ]; - else - *(pRGBArow+3) = 0xFF; - } - else - MNG_ERROR (pData, MNG_PLTEINDEXERROR); - - pWorkrow++; /* next pixel */ - pRGBArow += 4; - } - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iQ = *pWorkrow; /* get the index */ - /* is it valid ? */ - if ((mng_uint32)iQ < pBuf->iPLTEcount) - { /* put in intermediate row */ - *pRGBArow = pBuf->aPLTEentries [iQ].iRed; - *(pRGBArow+1) = pBuf->aPLTEentries [iQ].iGreen; - *(pRGBArow+2) = pBuf->aPLTEentries [iQ].iBlue; - *(pRGBArow+3) = 0xFF; - } - else - MNG_ERROR (pData, MNG_PLTEINDEXERROR); - - pWorkrow++; /* next pixel */ - pRGBArow += 4; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_IDX8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_retrieve_ga8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint8 iG; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_GA8, MNG_LC_START); -#endif - - pRGBArow = pData->pRGBArow; /* temporary work pointers */ - pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iG = *pWorkrow; /* get the gray-value */ - *pRGBArow = iG; /* put in intermediate row */ - *(pRGBArow+1) = iG; - *(pRGBArow+2) = iG; - *(pRGBArow+3) = *(pWorkrow+1); - - pWorkrow += 2; /* next pixel */ - pRGBArow += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_GA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_retrieve_ga16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint16 iG; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_GA16, MNG_LC_START); -#endif - /* temporary work pointers */ - pRGBArow = pData->pRGBArow; - pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iG = mng_get_uint16 (pWorkrow); /* get the gray-value */ - - mng_put_uint16 (pRGBArow, iG); /* and put in intermediate row */ - mng_put_uint16 (pRGBArow+2, iG); - mng_put_uint16 (pRGBArow+4, iG); - mng_put_uint16 (pRGBArow+6, mng_get_uint16 (pWorkrow+2)); - - pWorkrow += 4; /* next pixel */ - pRGBArow += 8; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_GA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_retrieve_rgba8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_RGBA8, MNG_LC_START); -#endif - - pRGBArow = pData->pRGBArow; /* temporary work pointers */ - pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); - /* can't be easier than this ! */ - MNG_COPY (pRGBArow, pWorkrow, pBuf->iRowsize); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_retrieve_rgba16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_RGBA16, MNG_LC_START); -#endif - /* temporary work pointers */ - pRGBArow = pData->pRGBArow; - pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); - /* can't be easier than this ! */ - MNG_COPY (pRGBArow, pWorkrow, pBuf->iRowsize); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RETRIEVE_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ -/* * * */ -/* * Row storage routines - store processed & uncompressed row-data * */ -/* * into the current "object" * */ -/* * * */ -/* ************************************************************************** */ - -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_retcode mng_store_g1 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_G1, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - iM = 0; /* start at pixel 0 */ - iB = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0x80; - } - - if (iB & iM) /* is it white ? */ - *pOutrow = 0x01; /* white */ - else - *pOutrow = 0x00; /* black */ - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 1; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_G1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_store_g2 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - mng_uint8 iQ; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_G2, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xC0; - iS = 6; - } - - iQ = (mng_uint8)((iB & iM) >> iS); /* get the gray level */ - *pOutrow = iQ; /* put in object buffer */ - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 2; - iS -= 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_G2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_store_g4 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - mng_uint8 iQ; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_G4, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xF0; - iS = 4; - } - - iQ = (mng_uint8)((iB & iM) >> iS); /* get the gray level */ - *pOutrow = iQ; /* put in object buffer */ - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 4; - iS -= 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_G4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_store_g8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_G8, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* put in object buffer */ - - pOutrow += pData->iColinc; /* next pixel */ - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_G8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_store_g16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_G16, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* copy into object buffer */ - mng_put_uint16 (pOutrow, mng_get_uint16 (pWorkrow)); - - pOutrow += (pData->iColinc << 1); /* next pixel */ - pWorkrow += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_G16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_store_rgb8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_RGB8, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* copy the RGB bytes */ - *(pOutrow+1) = *(pWorkrow+1); - *(pOutrow+2) = *(pWorkrow+2); - - pWorkrow += 3; /* next pixel */ - pOutrow += (pData->iColinc * 3); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_RGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_store_rgb16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_RGB16, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - MNG_COPY (pOutrow, pWorkrow, 6); /* copy the RGB bytes */ - - pWorkrow += 6; /* next pixel */ - pOutrow += (pData->iColinc * 6); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_RGB16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_retcode mng_store_idx1 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_IDX1, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - iM = 0; /* start at pixel 0 */ - iB = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0x80; - } - - if (iB & iM) /* store the index */ - *pOutrow = 0x01; - else - *pOutrow = 0x00; - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 1; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_IDX1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_store_idx2 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_IDX2, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xC0; - iS = 6; - } - /* store the index */ - *pOutrow = (mng_uint8)((iB & iM) >> iS); - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 2; - iS -= 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_IDX2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_store_idx4 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_IDX4, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xF0; - iS = 4; - } - /* store the index */ - *pOutrow = (mng_uint8)((iB & iM) >> iS); - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 4; - iS -= 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_IDX4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_store_idx8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_IDX8, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* put in object buffer */ - - pOutrow += pData->iColinc; /* next pixel */ - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_IDX8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_store_ga8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_GA8, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* copy the GA bytes */ - *(pOutrow+1) = *(pWorkrow+1); - - pWorkrow += 2; /* next pixel */ - pOutrow += (pData->iColinc << 1); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_GA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_store_ga16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_GA16, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - MNG_COPY (pOutrow, pWorkrow, 4); /* copy the GA bytes */ - - pWorkrow += 4; /* next pixel */ - pOutrow += (pData->iColinc << 2); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_GA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_store_rgba8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_RGBA8, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* copy the RGBA bytes */ - *(pOutrow+1) = *(pWorkrow+1); - *(pOutrow+2) = *(pWorkrow+2); - *(pOutrow+3) = *(pWorkrow+3); - - pWorkrow += 4; /* next pixel */ - pOutrow += (pData->iColinc << 2); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_store_rgba16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_RGBA16, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - MNG_COPY (pOutrow, pWorkrow, 8); /* copy the RGBA bytes */ - - pWorkrow += 8; /* next pixel */ - pOutrow += (pData->iColinc << 3); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ -/* * * */ -/* * Row storage routines (JPEG) - store processed & uncompressed row-data * */ -/* * into the current "object" * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG - -/* ************************************************************************** */ - -mng_retcode mng_store_jpeg_g8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8, MNG_LC_START); -#endif - - pWorkrow = pData->pJPEGrow; /* temporary work pointers */ - pOutrow = pBuf->pImgdata + (pData->iJPEGrow * pBuf->iRowsize); - /* easy as pie ... */ - MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8, MNG_LC_END); -#endif - - return mng_next_jpeg_row (pData); /* we've got one more row of gray-samples */ -} - -/* ************************************************************************** */ - -mng_retcode mng_store_jpeg_rgb8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; -#if RGB_PIXELSIZE != 3 - mng_int32 iX; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8, MNG_LC_START); -#endif - - pWorkrow = pData->pJPEGrow; /* temporary work pointers */ - pOutrow = pBuf->pImgdata + (pData->iJPEGrow * pBuf->iRowsize); - -#if RGB_PIXELSIZE == 3 - /* easy as pie ... */ - MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples * 3); -#else -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* copy pixel into object buffer */ - *(pOutrow+1) = *(pWorkrow+1); - *(pOutrow+2) = *(pWorkrow+2); - - pOutrow += 3; /* next pixel */ - pWorkrow += RGB_PIXELSIZE; - } -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8, MNG_LC_END); -#endif - - return mng_next_jpeg_row (pData); /* we've got one more row of rgb-samples */ -} - -/* ************************************************************************** */ - -mng_retcode mng_store_jpeg_ga8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_GA8, MNG_LC_START); -#endif - - pWorkrow = pData->pJPEGrow; /* temporary work pointers */ - pOutrow = pBuf->pImgdata + (pData->iJPEGrow * pBuf->iRowsize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* copy into object buffer */ - - pOutrow += 2; /* next pixel */ - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_GA8, MNG_LC_END); -#endif - - return mng_next_jpeg_row (pData); /* we've got one more row of gray-samples */ -} - -/* ************************************************************************** */ - -mng_retcode mng_store_jpeg_rgba8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGBA8, MNG_LC_START); -#endif - - pWorkrow = pData->pJPEGrow; /* temporary work pointers */ - pOutrow = pBuf->pImgdata + (pData->iJPEGrow * pBuf->iRowsize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* copy pixel into object buffer */ - *(pOutrow+1) = *(pWorkrow+1); - *(pOutrow+2) = *(pWorkrow+2); - - pOutrow += 4; /* next pixel */ - pWorkrow += RGB_PIXELSIZE; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGBA8, MNG_LC_END); -#endif - - return mng_next_jpeg_row (pData); /* we've got one more row of rgb-samples */ -} - -/* ************************************************************************** */ - -mng_retcode mng_store_jpeg_g8_alpha (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_ALPHA, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pJPEGrow2; - pOutrow = pBuf->pImgdata + (pData->iJPEGalpharow * pBuf->iRowsize) + 1; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* put in object buffer */ - - pOutrow += 2; /* next pixel */ - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_ALPHA, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_store_jpeg_rgb8_alpha (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_ALPHA, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pJPEGrow2; - pOutrow = pBuf->pImgdata + (pData->iJPEGalpharow * pBuf->iRowsize) + 3; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* put in object buffer */ - - pOutrow += 4; /* next pixel */ - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_ALPHA, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_retcode mng_store_jpeg_g8_a1 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A1, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 1; - iM = 0; /* start at pixel 0 */ - iB = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0x80; - } - - if (iB & iM) /* is it opaque ? */ - *pOutrow = 0xFF; /* opaque */ - else - *pOutrow = 0x00; /* transparent */ - - pOutrow += 2; /* next pixel */ - iM >>= 1; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A1, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_store_jpeg_g8_a2 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A2, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 1; - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xC0; - iS = 6; - } - -#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH - { - const mng_uint8 alpha_level[4] = { 0x00, 0x55, 0xAA, 0xFF}; - *pOutrow = alpha_level[((iB & iM) >> iS)] ; - } -#else - switch ((iB & iM) >> iS) /* determine the alpha level */ - { - case 0x03 : { *pOutrow = 0xFF; break; } - case 0x02 : { *pOutrow = 0xAA; break; } - case 0x01 : { *pOutrow = 0x55; break; } - default : { *pOutrow = 0x00; } - } -#endif - - pOutrow += 2; /* next pixel */ - iM >>= 2; - iS -= 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A2, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_store_jpeg_g8_a4 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - mng_uint8 iQ; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A4, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 1; - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xF0; - iS = 4; - } - /* get the alpha level */ - iQ = (mng_uint8)((iB & iM) >> iS); - iQ = (mng_uint8)(iQ + (iQ << 4)); /* expand to 8-bit by replication */ - - *pOutrow = iQ; /* put in object buffer */ - - pOutrow += 2; /* next pixel */ - iM >>= 4; - iS -= 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A4, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_store_jpeg_g8_a8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A8, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 1; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* put in object buffer */ - - pOutrow += 2; /* next pixel */ - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A8, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_store_jpeg_g8_a16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A16, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 1; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* only high-order byte! */ - - pOutrow += 2; /* next pixel */ - pWorkrow += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A16, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_retcode mng_store_jpeg_rgb8_a1 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A1, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 3; - iM = 0; /* start at pixel 0 */ - iB = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0x80; - } - - if (iB & iM) /* is it opaque ? */ - *pOutrow = 0xFF; /* opaque */ - else - *pOutrow = 0x00; /* transparent */ - - pOutrow += 4; /* next pixel */ - iM >>= 1; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A1, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_store_jpeg_rgb8_a2 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A2, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 3; - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xC0; - iS = 6; - } - -#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH - { - const mng_uint8 alpha_level[4] = { 0x00, 0x55, 0xAA, 0xFF}; - *pOutrow = alpha_level[((iB & iM) >> iS)] ; - } -#else - switch ((iB & iM) >> iS) /* determine the alpha level */ - { - case 0x03 : { *pOutrow = 0xFF; break; } - case 0x02 : { *pOutrow = 0xAA; break; } - case 0x01 : { *pOutrow = 0x55; break; } - default : { *pOutrow = 0x00; } - } -#endif - - pOutrow += 4; /* next pixel */ - iM >>= 2; - iS -= 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A2, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_store_jpeg_rgb8_a4 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - mng_uint8 iQ; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A4, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 3; - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xF0; - iS = 4; - } - /* get the alpha level */ - iQ = (mng_uint8)((iB & iM) >> iS); - iQ = (mng_uint8)(iQ + (iQ << 4)); /* expand to 8-bit by replication */ - - *pOutrow = iQ; /* put in object buffer */ - - pOutrow += 4; /* next pixel */ - iM >>= 4; - iS -= 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A4, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_store_jpeg_rgb8_a8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A8, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 3; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* put in buffer */ - - pOutrow += 4; /* next pixel */ - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A8, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_store_jpeg_rgb8_a16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A16, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 3; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* only high-order byte */ - - pOutrow += 4; /* next pixel */ - pWorkrow += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A16, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_JPEG12 -mng_retcode mng_store_jpeg_g12_a1 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A1, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 2; - iM = 0; /* start at pixel 0 */ - iB = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0x80; - } - - if (iB & iM) /* opaque ? */ - mng_put_uint16 (pOutrow, 0xFFFF);/* opaque */ - else - mng_put_uint16 (pOutrow, 0x0000);/* transparent */ - - pOutrow += 4; /* next pixel */ - iM >>= 1; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A1, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} -#endif /* MNG_SUPPORT_JPEG12 */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_JPEG12 -mng_retcode mng_store_jpeg_g12_a2 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A2, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 2; - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xC0; - iS = 6; - } - -#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH - { - const mng_uint16 gray_level[4] = { 0x0000, 0x5555, 0xAAAA, 0xFFFF}; - mng_put_uint16 (pOutrow, gray_level[((iB & iM) >> iS)]) ; - } -#else - switch ((iB & iM) >> iS) /* determine the gray level */ - { - case 0x03 : { mng_put_uint16 (pOutrow, 0xFFFF); break; } - case 0x02 : { mng_put_uint16 (pOutrow, 0xAAAA); break; } - case 0x01 : { mng_put_uint16 (pOutrow, 0x5555); break; } - default : { mng_put_uint16 (pOutrow, 0x0000); } - } -#endif - - pOutrow += 4; /* next pixel */ - iM >>= 2; - iS -= 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A2, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} -#endif /* MNG_SUPPORT_JPEG12 */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_JPEG12 -mng_retcode mng_store_jpeg_g12_a4 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - mng_uint16 iQ; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A4, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 2; - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xF0; - iS = 4; - } - /* get the gray level */ - iQ = (mng_uint16)((iB & iM) >> iS); - iQ = (mng_uint16)(iQ + (iQ << 4)); /* expand to 16-bit by replication */ - iQ = (mng_uint16)(iQ + (iQ << 8)); - /* put in object buffer */ - mng_put_uint16 (pOutrow, iQ); - - pOutrow += 4; /* next pixel */ - iM >>= 4; - iS -= 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A4, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} -#endif /* MNG_SUPPORT_JPEG12 */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_JPEG12 -mng_retcode mng_store_jpeg_g12_a8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint16 iW; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A8, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 2; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iW = (mng_uint16)(*pWorkrow); /* get input byte */ - iW = (mng_uint16)(iW + (iW << 8)); /* expand to 16-bit by replication */ - - mng_put_uint16 (pOutrow, iW); /* put in object buffer */ - - pOutrow += 4; /* next pixel */ - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A8, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} -#endif /* MNG_SUPPORT_JPEG12 */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_JPEG12 -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_store_jpeg_g12_a16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A16, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 2; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* copy it */ - mng_put_uint16 (pOutrow, mng_get_uint16 (pWorkrow)); - - pOutrow += 4; /* next pixel */ - pWorkrow += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A16, MNG_LC_END); -#endif - /* we've got one more row of alpha-samples */ - return mng_next_jpeg_alpharow (pData); -} -#endif -#endif /* MNG_SUPPORT_JPEG12 */ - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_JNG */ - -#ifndef MNG_NO_DELTA_PNG -/* ************************************************************************** */ -/* * * */ -/* * Delta-image row routines - apply the processed & uncompressed row-data * */ -/* * onto the target "object" * */ -/* * * */ -/* ************************************************************************** */ - -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_retcode mng_delta_g1 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G1, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - iM = 0; /* start at pixel 0 */ - iB = 0; - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0x80; - } - - if (iB & iM) /* is it white ? */ - *pOutrow = 0xFF; /* white */ - else - *pOutrow = 0x00; /* black */ - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 1; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0x80; - } - - if (iB & iM) /* invert if it is white ? */ - *pOutrow = (mng_uint8)(*pOutrow ^ 0xFF); - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 1; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G1, MNG_LC_END); -#endif - - return mng_store_g1 (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_delta_g2 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; -#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH - const mng_uint8 level[4] = { 0x00, 0x55, 0xAA, 0xFF}; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G2, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xC0; - iS = 6; - } - -#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH - *pOutrow = level[((iB & iM) >> iS)] ; -#else - switch ((iB & iM) >> iS) /* determine the alpha level */ - { - case 0x03 : { *pOutrow = 0xFF; break; } - case 0x02 : { *pOutrow = 0xAA; break; } - case 0x01 : { *pOutrow = 0x55; break; } - default : { *pOutrow = 0x00; } - } -#endif - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 2; - iS -= 2; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xC0; - iS = 6; - } - -#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH - *pOutrow = level[((*pOutrow >> 6) + ((iB & iM) >> iS)) & 0x03] ; -#else - switch (((*pOutrow >> 6) + ((iB & iM) >> iS)) & 0x03) - { - case 0x03 : { *pOutrow = 0xFF; break; } - case 0x02 : { *pOutrow = 0xAA; break; } - case 0x01 : { *pOutrow = 0x55; break; } - default : { *pOutrow = 0x00; } - } -#endif - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 2; - iS -= 2; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G2, MNG_LC_END); -#endif - - return mng_store_g2 (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_delta_g4 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - mng_uint8 iQ; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G4, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xF0; - iS = 4; - } - /* get the gray level */ - iQ = (mng_uint8)((iB & iM) >> iS); - /* expand to 8-bit by replication */ - iQ = (mng_uint8)(iQ + (iQ << 4)); - - *pOutrow = iQ; /* put in object buffer */ - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 4; - iS -= 4; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xF0; - iS = 4; - } - /* get the gray level */ - iQ = (mng_uint8)(((*pOutrow >> 4) + ((iB & iM) >> iS)) & 0x0F); - /* expand to 8-bit by replication */ - iQ = (mng_uint8)(iQ + (iQ << 4)); - - *pOutrow = iQ; /* put in object buffer */ - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 4; - iS -= 4; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G4, MNG_LC_END); -#endif - - return mng_store_g4 (pData); -} -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - -/* ************************************************************************** */ - -mng_retcode mng_delta_g8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G8, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* put in object buffer */ - - pOutrow += pData->iColinc; /* next pixel */ - pWorkrow++; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* add to object buffer */ - *pOutrow = (mng_uint8)(*pOutrow + *pWorkrow); - - pOutrow += pData->iColinc; /* next pixel */ - pWorkrow++; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G8, MNG_LC_END); -#endif - - return mng_store_g8 (pData); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_delta_g16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G16, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* put in object buffer */ - *(pOutrow+1) = *(pWorkrow+1); - /* next pixel */ - pOutrow += (pData->iColinc << 1); - pWorkrow += 2; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* add to object buffer */ - mng_put_uint16 (pOutrow, (mng_uint16)(mng_get_uint16 (pOutrow ) + - mng_get_uint16 (pWorkrow) )); - /* next pixel */ - pOutrow += (pData->iColinc << 1); - pWorkrow += 2; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G16, MNG_LC_END); -#endif - - return mng_store_g16 (pData); -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_delta_rgb8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGB8, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* put in object buffer */ - *(pOutrow+1) = *(pWorkrow+1); - *(pOutrow+2) = *(pWorkrow+2); - /* next pixel */ - pOutrow += (pData->iColinc * 3); - pWorkrow += 3; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* add to object buffer */ - *pOutrow = (mng_uint8)(*pOutrow + *pWorkrow ); - *(pOutrow+1) = (mng_uint8)(*(pOutrow+1) + *(pWorkrow+1)); - *(pOutrow+2) = (mng_uint8)(*(pOutrow+2) + *(pWorkrow+2)); - /* next pixel */ - pOutrow += (pData->iColinc * 3); - pWorkrow += 3; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGB8, MNG_LC_END); -#endif - - return mng_store_rgb8 (pData); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_delta_rgb16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGB16, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* put in object buffer */ - *(pOutrow+1) = *(pWorkrow+1); - *(pOutrow+2) = *(pWorkrow+2); - *(pOutrow+3) = *(pWorkrow+3); - *(pOutrow+4) = *(pWorkrow+4); - *(pOutrow+5) = *(pWorkrow+5); - /* next pixel */ - pOutrow += (pData->iColinc * 6); - pWorkrow += 6; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* add to object buffer */ - mng_put_uint16 (pOutrow, (mng_uint16)(mng_get_uint16 (pOutrow ) + - mng_get_uint16 (pWorkrow ) )); - mng_put_uint16 (pOutrow+2, (mng_uint16)(mng_get_uint16 (pOutrow+2 ) + - mng_get_uint16 (pWorkrow+2) )); - mng_put_uint16 (pOutrow+4, (mng_uint16)(mng_get_uint16 (pOutrow+4 ) + - mng_get_uint16 (pWorkrow+4) )); - /* next pixel */ - pOutrow += (pData->iColinc * 6); - pWorkrow += 6; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGB16, MNG_LC_END); -#endif - - return mng_store_rgb16 (pData); -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_retcode mng_delta_idx1 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_IDX1, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - iM = 0; /* start at pixel 0 */ - iB = 0; - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0x80; - } - - if (iB & iM) /* put the right index value */ - *pOutrow = 1; - else - *pOutrow = 0; - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 1; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0x80; - } - - if (iB & iM) /* invert if it is non-zero index */ - *pOutrow = (mng_uint8)(*pOutrow ^ 0x01); - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 1; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_IDX1, MNG_LC_END); -#endif - - return mng_store_idx1 (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_delta_idx2 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_IDX2, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xC0; - iS = 6; - } - /* put the index */ - *pOutrow = (mng_uint8)((iB & iM) >> iS); - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 2; - iS -= 2; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xC0; - iS = 6; - } - /* calculate the index */ - *pOutrow = (mng_uint8)((*pOutrow + ((iB & iM) >> iS)) & 0x03); - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 2; - iS -= 2; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_IDX2, MNG_LC_END); -#endif - - return mng_store_idx2 (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_delta_idx4 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_IDX4, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xF0; - iS = 4; - } - /* put the index */ - *pOutrow = (mng_uint8)((iB & iM) >> iS); - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 4; - iS -= 4; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xF0; - iS = 4; - } - /* calculate the index */ - *pOutrow = (mng_uint8)((*pOutrow + ((iB & iM) >> iS)) & 0x0F); - - pOutrow += pData->iColinc; /* next pixel */ - iM >>= 4; - iS -= 4; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_IDX4, MNG_LC_END); -#endif - - return mng_store_idx4 (pData); -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_delta_idx8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_IDX8, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* put in object buffer */ - - pOutrow += pData->iColinc; /* next pixel */ - pWorkrow++; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* add to object buffer */ - *pOutrow = (mng_uint8)(*pOutrow + *pWorkrow); - - pOutrow += pData->iColinc; /* next pixel */ - pWorkrow++; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_IDX8, MNG_LC_END); -#endif - - return mng_store_idx8 (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_delta_ga8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA8, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* put in object buffer */ - *(pOutrow+1) = *(pWorkrow+1); - /* next pixel */ - pOutrow += (pData->iColinc << 1); - pWorkrow += 2; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* add to object buffer */ - *pOutrow = (mng_uint8)(*pOutrow + *pWorkrow ); - *(pOutrow+1) = (mng_uint8)(*(pOutrow+1) + *(pWorkrow+1)); - /* next pixel */ - pOutrow += (pData->iColinc << 1); - pWorkrow += 2; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA8, MNG_LC_END); -#endif - - return mng_store_ga8 (pData); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_delta_ga16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA16, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* put in object buffer */ - *(pOutrow+1) = *(pWorkrow+1); - *(pOutrow+2) = *(pWorkrow+2); - *(pOutrow+3) = *(pWorkrow+3); - /* next pixel */ - pOutrow += (pData->iColinc << 2); - pWorkrow += 4; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* add to object buffer */ - mng_put_uint16 (pOutrow, (mng_uint16)(mng_get_uint16 (pOutrow ) + - mng_get_uint16 (pWorkrow ) )); - mng_put_uint16 (pOutrow+2, (mng_uint16)(mng_get_uint16 (pOutrow+2 ) + - mng_get_uint16 (pWorkrow+2) )); - /* next pixel */ - pOutrow += (pData->iColinc << 2); - pWorkrow += 4; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA16, MNG_LC_END); -#endif - - return mng_store_ga16 (pData); -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_delta_rgba8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA8, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; /* put in object buffer */ - *(pOutrow+1) = *(pWorkrow+1); - *(pOutrow+2) = *(pWorkrow+2); - *(pOutrow+3) = *(pWorkrow+3); - /* next pixel */ - pOutrow += (pData->iColinc << 2); - pWorkrow += 4; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* add to object buffer */ - *pOutrow = (mng_uint8)(*pOutrow + *pWorkrow ); - *(pOutrow+1) = (mng_uint8)(*(pOutrow+1) + *(pWorkrow+1)); - *(pOutrow+2) = (mng_uint8)(*(pOutrow+2) + *(pWorkrow+2)); - *(pOutrow+3) = (mng_uint8)(*(pOutrow+3) + *(pWorkrow+3)); - /* next pixel */ - pOutrow += (pData->iColinc << 2); - pWorkrow += 4; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA8, MNG_LC_END); -#endif - - return mng_store_rgba8 (pData); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_delta_rgba16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA16, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iDeltaBlocky * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + - (pData->iDeltaBlockx * pBuf->iSamplesize); - /* pixel replace ? */ - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - MNG_COPY (pOutrow, pWorkrow, 8); /* put in object buffer */ - /* next pixel */ - pOutrow += (pData->iColinc << 3); - pWorkrow += 8; - } - } - else - { /* pixel add ! */ -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* add to object buffer */ - mng_put_uint16 (pOutrow, (mng_uint16)(mng_get_uint16 (pOutrow ) + - mng_get_uint16 (pWorkrow ) )); - mng_put_uint16 (pOutrow+2, (mng_uint16)(mng_get_uint16 (pOutrow+2 ) + - mng_get_uint16 (pWorkrow+2) )); - mng_put_uint16 (pOutrow+4, (mng_uint16)(mng_get_uint16 (pOutrow+4 ) + - mng_get_uint16 (pWorkrow+4) )); - mng_put_uint16 (pOutrow+6, (mng_uint16)(mng_get_uint16 (pOutrow+6 ) + - mng_get_uint16 (pWorkrow+6) )); - /* next pixel */ - pOutrow += (pData->iColinc << 3); - pWorkrow += 8; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA16, MNG_LC_END); -#endif - - return mng_store_rgba16 (pData); -} -#endif - -/* ************************************************************************** */ -/* * * */ -/* * Delta-image row routines - apply the source row onto the target * */ -/* * * */ -/* ************************************************************************** */ - -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_retcode mng_delta_g1_g1 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G1_G1, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples); - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + - (mng_uint16)*pWorkrow) & 0x01); - - pOutrow++; - pWorkrow++; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G1_G1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_delta_g2_g2 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G2_G2, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples); - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + - (mng_uint16)*pWorkrow) & 0x03); - - pOutrow++; - pWorkrow++; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G2_G2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_delta_g4_g4 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G4_G4, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples); - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + - (mng_uint16)*pWorkrow) & 0x0F); - - pOutrow++; - pWorkrow++; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G4_G4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_delta_g8_g8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G8_G8, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples); - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + - (mng_uint16)*pWorkrow) & 0xFF); - - pOutrow++; - pWorkrow++; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G8_G8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_delta_g16_g16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G16_G16, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - MNG_COPY (pOutrow, pWorkrow, (pData->iRowsamples << 1)); - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - mng_put_uint16 (pOutrow, (mng_uint16)((mng_get_uint16 (pOutrow) + - mng_get_uint16 (pWorkrow)) & 0xFFFF)); - - pOutrow += 2; - pWorkrow += 2; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_G16_G16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_NO_DELTA_PNG */ - -/* ************************************************************************** */ - -mng_retcode mng_delta_rgb8_rgb8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGB8_RGB8, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples * 3); - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples*3; iX > 0; iX--) -#else - for (iX = 0; iX < (pData->iRowsamples * 3); iX++) -#endif - { - *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + - (mng_uint16)*pWorkrow) & 0xFF); - - pOutrow++; - pWorkrow++; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGB8_RGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_delta_rgb16_rgb16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGB16_RGB16, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - MNG_COPY (pOutrow, pWorkrow, (pData->iRowsamples * 6)); - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - mng_put_uint16 (pOutrow, (mng_uint16)((mng_get_uint16 (pOutrow ) + - mng_get_uint16 (pWorkrow )) & 0xFFFF)); - mng_put_uint16 (pOutrow+2, (mng_uint16)((mng_get_uint16 (pOutrow+2) + - mng_get_uint16 (pWorkrow+2)) & 0xFFFF)); - mng_put_uint16 (pOutrow+4, (mng_uint16)((mng_get_uint16 (pOutrow+4) + - mng_get_uint16 (pWorkrow+4)) & 0xFFFF)); - - pOutrow += 6; - pWorkrow += 6; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGB16_RGB16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode mng_delta_ga8_ga8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA8_GA8, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples << 1); - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = (pData->iRowsamples<<1); iX > 0; iX--) -#else - for (iX = 0; iX < (pData->iRowsamples << 1); iX++) -#endif - { - *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + - (mng_uint16)*pWorkrow) & 0xFF); - - pOutrow++; - pWorkrow++; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA8_GA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_delta_ga8_g8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA8_G8, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; - - pOutrow += 2; - pWorkrow++; - } - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + - (mng_uint16)*pWorkrow) & 0xFF); - - pOutrow += 2; - pWorkrow++; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA8_G8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_delta_ga8_a8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA8_A8, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 1; - - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; - - pOutrow += 2; - pWorkrow++; - } - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + - (mng_uint16)*pWorkrow) & 0xFF); - - pOutrow += 2; - pWorkrow++; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA8_A8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_delta_ga16_ga16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA16_GA16, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - MNG_COPY (pOutrow, pWorkrow, (pData->iRowsamples << 2)); - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - mng_put_uint16 (pOutrow, (mng_uint16)((mng_get_uint16 (pOutrow ) + - mng_get_uint16 (pWorkrow )) & 0xFFFF)); - mng_put_uint16 (pOutrow+2, (mng_uint16)((mng_get_uint16 (pOutrow+2) + - mng_get_uint16 (pWorkrow+2)) & 0xFFFF)); - - pOutrow += 4; - pWorkrow += 4; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA16_GA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_delta_ga16_g16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA16_G16, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - mng_put_uint16 (pOutrow, mng_get_uint16 (pWorkrow)); - - pOutrow += 4; - pWorkrow += 2; - } - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - mng_put_uint16 (pOutrow, (mng_uint16)((mng_get_uint16 (pOutrow) + - mng_get_uint16 (pWorkrow)) & 0xFFFF)); - - pOutrow += 4; - pWorkrow += 2; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA16_G16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_delta_ga16_a16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA16_A16, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - mng_put_uint16 (pOutrow+2, mng_get_uint16 (pWorkrow)); - - pOutrow += 4; - pWorkrow += 2; - } - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - mng_put_uint16 (pOutrow+2, (mng_uint16)((mng_get_uint16 (pOutrow+2) + - mng_get_uint16 (pWorkrow)) & 0xFFFF)); - - pOutrow += 4; - pWorkrow += 2; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_GA16_A16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_NO_DELTA_PNG */ - -/* ************************************************************************** */ - -mng_retcode mng_delta_rgba8_rgba8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA8_RGBA8, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples << 2); - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = (pData->iRowsamples << 2); iX > 0; iX--) -#else - for (iX = 0; iX < (pData->iRowsamples << 2); iX++) -#endif - { - *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + - (mng_uint16)*pWorkrow) & 0xFF); - - pOutrow++; - pWorkrow++; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA8_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -mng_retcode mng_delta_rgba8_rgb8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA8_RGB8, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; - *(pOutrow+1) = *(pWorkrow+1); - *(pOutrow+2) = *(pWorkrow+2); - - pOutrow += 4; - pWorkrow += 3; - } - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + - (mng_uint16)*pWorkrow ) & 0xFF); - *(pOutrow+1) = (mng_uint8)(((mng_uint16)*(pOutrow+1) + - (mng_uint16)*(pWorkrow+1)) & 0xFF); - *(pOutrow+2) = (mng_uint8)(((mng_uint16)*(pOutrow+2) + - (mng_uint16)*(pWorkrow+2)) & 0xFF); - - pOutrow += 4; - pWorkrow += 3; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA8_RGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_delta_rgba8_a8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA8_A8, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize) + 3; - - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = *pWorkrow; - - pOutrow += 4; - pWorkrow++; - } - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + - (mng_uint16)*pWorkrow) & 0xFF); - - pOutrow += 4; - pWorkrow++; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA8_A8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_DELTA_PNG */ - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_delta_rgba16_rgba16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA16_RGBA16, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || - (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) - { - MNG_COPY (pOutrow, pWorkrow, (pData->iRowsamples << 3)); - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - mng_put_uint16 (pOutrow, (mng_uint16)((mng_get_uint16 (pOutrow ) + - mng_get_uint16 (pWorkrow )) & 0xFFFF)); - mng_put_uint16 (pOutrow+2, (mng_uint16)((mng_get_uint16 (pOutrow+2) + - mng_get_uint16 (pWorkrow+2)) & 0xFFFF)); - mng_put_uint16 (pOutrow+4, (mng_uint16)((mng_get_uint16 (pOutrow+4) + - mng_get_uint16 (pWorkrow+4)) & 0xFFFF)); - mng_put_uint16 (pOutrow+6, (mng_uint16)((mng_get_uint16 (pOutrow+6) + - mng_get_uint16 (pWorkrow+6)) & 0xFFFF)); - - pOutrow += 8; - pWorkrow += 8; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA16_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_delta_rgba16_rgb16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA16_RGB16, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - mng_put_uint16 (pOutrow, mng_get_uint16 (pWorkrow )); - mng_put_uint16 (pOutrow+2, mng_get_uint16 (pWorkrow+2)); - mng_put_uint16 (pOutrow+4, mng_get_uint16 (pWorkrow+4)); - - pOutrow += 8; - pWorkrow += 6; - } - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - mng_put_uint16 (pOutrow, (mng_uint16)((mng_get_uint16 (pOutrow ) + - mng_get_uint16 (pWorkrow )) & 0xFFFF)); - mng_put_uint16 (pOutrow+2, (mng_uint16)((mng_get_uint16 (pOutrow+2) + - mng_get_uint16 (pWorkrow+2)) & 0xFFFF)); - mng_put_uint16 (pOutrow+4, (mng_uint16)((mng_get_uint16 (pOutrow+4) + - mng_get_uint16 (pWorkrow+4)) & 0xFFFF)); - - pOutrow += 8; - pWorkrow += 6; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA16_RGB16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_delta_rgba16_a16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA16_A16, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - mng_put_uint16 (pOutrow+6, mng_get_uint16 (pWorkrow)); - - pOutrow += 8; - pWorkrow += 2; - } - } - else - if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD) - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - mng_put_uint16 (pOutrow+6, (mng_uint16)((mng_get_uint16 (pOutrow+6) + - mng_get_uint16 (pWorkrow)) & 0xFFFF)); - - pOutrow += 8; - pWorkrow += 2; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DELTA_RGBA16_A16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_NO_DELTA_PNG */ - -/* ************************************************************************** */ -/* * * */ -/* * Delta-image row routines - scale the delta to bitdepth of target * */ -/* * * */ -/* ************************************************************************** */ - -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_retcode mng_scale_g1_g2 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G1_G2, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pWorkrow = (mng_uint8)(*pWorkrow << 1); - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G1_G2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_scale_g1_g4 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G1_G4, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pWorkrow = (mng_uint8)(*pWorkrow << 3); - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G1_G4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_scale_g1_g8 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G1_G8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pWorkrow = (mng_uint8)(*pWorkrow << 7); - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G1_G8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_scale_g1_g16 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_uint8p pOutrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G1_G16, MNG_LC_START); -#endif - - pWorkrow = pWorkrow + (pData->iRowsamples - 1); - pOutrow = pOutrow + ((pData->iRowsamples - 1) << 1); -/* pWorkrow = (mng_uint8p)((mng_uint32)pWorkrow + pData->iRowsamples - 1); */ -/* pOutrow = (mng_uint8p)((mng_uint32)pOutrow + ((pData->iRowsamples - 1) << 1)); */ - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *(pOutrow+1) = 0; - *pOutrow = (mng_uint8)(*pWorkrow << 7); - - pWorkrow--; - pOutrow -= 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G1_G16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_scale_g2_g4 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G2_G4, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pWorkrow = (mng_uint8)(*pWorkrow << 2); - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G2_G4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_scale_g2_g8 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G2_G8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pWorkrow = (mng_uint8)(*pWorkrow << 6); - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G2_G8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_scale_g2_g16 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_uint8p pOutrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G2_G16, MNG_LC_START); -#endif - - pWorkrow = pWorkrow + (pData->iRowsamples - 1); - pOutrow = pOutrow + ((pData->iRowsamples - 1) << 1); -/* pWorkrow = (mng_uint8p)((mng_uint32)pWorkrow + pData->iRowsamples - 1); */ -/* pOutrow = (mng_uint8p)((mng_uint32)pOutrow + ((pData->iRowsamples - 1) << 1)); */ - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *(pOutrow+1) = 0; - *pOutrow = (mng_uint8)(*pWorkrow << 6); - - pWorkrow--; - pOutrow -= 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G2_G16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_scale_g4_g8 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G4_G8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pWorkrow = (mng_uint8)(*pWorkrow << 4); - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G4_G8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_scale_g4_g16 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_uint8p pOutrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G4_G16, MNG_LC_START); -#endif - - pWorkrow = pWorkrow + (pData->iRowsamples - 1); - pOutrow = pOutrow + ((pData->iRowsamples - 1) << 1); -/* pWorkrow = (mng_uint8p)((mng_uint32)pWorkrow + pData->iRowsamples - 1); */ -/* pOutrow = (mng_uint8p)((mng_uint32)pOutrow + ((pData->iRowsamples - 1) << 1)); */ - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *(pOutrow+1) = 0; - *pOutrow = (mng_uint8)(*pWorkrow << 4); - - pWorkrow--; - pOutrow -= 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G4_G16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_scale_g8_g16 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_uint8p pOutrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G8_G16, MNG_LC_START); -#endif - - pWorkrow = pWorkrow + (pData->iRowsamples - 1); - pOutrow = pOutrow + ((pData->iRowsamples - 1) << 1); -/* pWorkrow = (mng_uint8p)((mng_uint32)pWorkrow + pData->iRowsamples - 1); */ -/* pOutrow = (mng_uint8p)((mng_uint32)pOutrow + ((pData->iRowsamples - 1) << 1)); */ - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *(pOutrow+1) = 0; - *pOutrow = *pWorkrow; - - pWorkrow--; - pOutrow -= 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G8_G16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_scale_ga8_ga16 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_uint8p pOutrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_GA8_GA16, MNG_LC_START); -#endif - - pWorkrow = pWorkrow + ((pData->iRowsamples - 1) << 1); - pOutrow = pOutrow + ((pData->iRowsamples - 1) << 2); -/* pWorkrow = (mng_uint8p)((mng_uint32)pWorkrow + ((pData->iRowsamples - 1) << 1)); */ -/* pOutrow = (mng_uint8p)((mng_uint32)pOutrow + ((pData->iRowsamples - 1) << 2)); */ - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *(pOutrow+3) = 0; - *(pOutrow+2) = *(pWorkrow+1); - *(pOutrow+1) = 0; - *pOutrow = *pWorkrow; - - pWorkrow -= 2; - pOutrow -= 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_GA8_GA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_scale_rgb8_rgb16 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_uint8p pOutrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_RGB8_RGB16, MNG_LC_START); -#endif - - pWorkrow = pWorkrow + (3 * (pData->iRowsamples - 1)); - pOutrow = pOutrow + (6 * (pData->iRowsamples - 1)); -/* pWorkrow = (mng_uint8p)((mng_uint32)pWorkrow + 3 * (pData->iRowsamples - 1)); */ -/* pOutrow = (mng_uint8p)((mng_uint32)pOutrow + 6 * (pData->iRowsamples - 1)); */ - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *(pOutrow+5) = 0; - *(pOutrow+4) = *(pWorkrow+2); - *(pOutrow+3) = 0; - *(pOutrow+2) = *(pWorkrow+1); - *(pOutrow+1) = 0; - *pOutrow = *pWorkrow; - - pWorkrow -= 3; - pOutrow -= 6; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_RGB8_RGB16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_scale_rgba8_rgba16 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_uint8p pOutrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_RGBA8_RGBA16, MNG_LC_START); -#endif - - pWorkrow = pWorkrow + ((pData->iRowsamples - 1) << 2); - pOutrow = pOutrow + ((pData->iRowsamples - 1) << 3); -/* pWorkrow = (mng_uint8p)((mng_uint32)pWorkrow + ((pData->iRowsamples - 1) << 2)); */ -/* pOutrow = (mng_uint8p)((mng_uint32)pOutrow + ((pData->iRowsamples - 1) << 3)); */ - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *(pOutrow+7) = 0; - *(pOutrow+6) = *(pWorkrow+3); - *(pOutrow+5) = 0; - *(pOutrow+4) = *(pWorkrow+2); - *(pOutrow+3) = 0; - *(pOutrow+2) = *(pWorkrow+1); - *(pOutrow+1) = 0; - *pOutrow = *pWorkrow; - - pWorkrow -= 4; - pOutrow -= 8; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_RGBA8_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_retcode mng_scale_g2_g1 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G2_G1, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pWorkrow = (mng_uint8)(*pWorkrow >> 1); - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G2_G1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_scale_g4_g1 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G4_G1, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pWorkrow = (mng_uint8)(*pWorkrow >> 3); - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G4_G1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_scale_g8_g1 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G8_G1, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pWorkrow = (mng_uint8)(*pWorkrow >> 7); - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G8_G1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_scale_g16_g1 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_uint8p pOutrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G16_G1, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 15); - pOutrow++; - pWorkrow += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G16_G1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_scale_g4_g2 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G4_G2, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pWorkrow = (mng_uint8)(*pWorkrow >> 2); - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G4_G2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_scale_g8_g2 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G8_G2, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pWorkrow = (mng_uint8)(*pWorkrow >> 6); - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G8_G2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_scale_g16_g2 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_uint8p pOutrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G16_G2, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 14); - pOutrow++; - pWorkrow += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G16_G2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_scale_g8_g4 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G8_G4, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pWorkrow = (mng_uint8)(*pWorkrow >> 4); - pWorkrow++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G8_G4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_scale_g16_g4 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_uint8p pOutrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G16_G4, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 12); - pOutrow++; - pWorkrow += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G16_G4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* NO_1_2_4BIT_SUPPORT */ - -/* ************************************************************************** */ - -mng_retcode mng_scale_g16_g8 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_uint8p pOutrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G16_G8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); - pOutrow++; - pWorkrow += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_G16_G8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_scale_ga16_ga8 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_uint8p pOutrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_GA16_GA8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); - pOutrow++; - pWorkrow += 2; - *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); - pOutrow++; - pWorkrow += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_GA16_GA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_scale_rgb16_rgb8 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_uint8p pOutrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_RGB16_RGB8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); - pOutrow++; - pWorkrow += 2; - *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); - pOutrow++; - pWorkrow += 2; - *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); - pOutrow++; - pWorkrow += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_RGB16_RGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_scale_rgba16_rgba8 (mng_datap pData) -{ - mng_uint8p pWorkrow = pData->pRGBArow; - mng_uint8p pOutrow = pData->pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_RGBA16_RGBA8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); - pOutrow++; - pWorkrow += 2; - *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); - pOutrow++; - pWorkrow += 2; - *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); - pOutrow++; - pWorkrow += 2; - *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); - pOutrow++; - pWorkrow += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_SCALE_RGBA16_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ -/* * * */ -/* * Delta-image bit routines - promote bit_depth * */ -/* * * */ -/* ************************************************************************** */ - -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_uint8 mng_promote_replicate_1_2 (mng_uint8 iB) -{ - return (mng_uint8)((iB << 1) | iB); -} - -/* ************************************************************************** */ - -mng_uint8 mng_promote_replicate_1_4 (mng_uint8 iB) -{ - iB = (mng_uint8)((iB << 1) + iB); - return (mng_uint8)((iB << 2) + iB); -} - -/* ************************************************************************** */ - -mng_uint8 mng_promote_replicate_1_8 (mng_uint8 iB) -{ - iB = (mng_uint8)((iB << 1) + iB); - iB = (mng_uint8)((iB << 2) + iB); - return (mng_uint8)((iB << 4) + iB); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_uint16 mng_promote_replicate_1_16 (mng_uint8 iB) -{ - iB = (mng_uint8)((iB << 1) + iB); - iB = (mng_uint8)((iB << 2) + iB); - iB = (mng_uint8)((iB << 4) + iB); - return (mng_uint16)(((mng_uint16)iB << 8) + (mng_uint16)iB); -} -#endif - -/* ************************************************************************** */ - -mng_uint8 mng_promote_replicate_2_4 (mng_uint8 iB) -{ - return (mng_uint8)((iB << 2) + iB); -} - -/* ************************************************************************** */ - -mng_uint8 mng_promote_replicate_2_8 (mng_uint8 iB) -{ - iB = (mng_uint8)((iB << 2) + iB); - return (mng_uint8)((iB << 4) + iB); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_uint16 mng_promote_replicate_2_16 (mng_uint8 iB) -{ - iB = (mng_uint8)((iB << 2) + iB); - iB = (mng_uint8)((iB << 4) + iB); - return (mng_uint16)(((mng_uint16)iB << 8) + (mng_uint16)iB); -} -#endif - -/* ************************************************************************** */ - -mng_uint8 mng_promote_replicate_4_8 (mng_uint8 iB) -{ - return (mng_uint8)((iB << 4) + iB); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_uint16 mng_promote_replicate_4_16 (mng_uint8 iB) -{ - iB = (mng_uint8)((iB << 4) + iB); - return (mng_uint16)(((mng_uint16)iB << 8) + (mng_uint16)iB); -} -#endif -#endif /* NO_1_2_4BIT_SUPPORT */ - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_uint16 mng_promote_replicate_8_16 (mng_uint8 iB) -{ - return (mng_uint16)(((mng_uint16)iB << 8) + (mng_uint16)iB); -} -#endif - -/* ************************************************************************** */ - -#if !defined(MNG_NO_DELTA_PNG) -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_uint8 mng_promote_zerofill_1_2 (mng_uint8 iB) -{ - return (mng_uint8)(iB << 1); -} - -/* ************************************************************************** */ - -mng_uint8 mng_promote_zerofill_1_4 (mng_uint8 iB) -{ - return (mng_uint8)(iB << 3); -} - -/* ************************************************************************** */ - -mng_uint8 mng_promote_zerofill_1_8 (mng_uint8 iB) -{ - return (mng_uint8)(iB << 7); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_uint16 mng_promote_zerofill_1_16 (mng_uint8 iB) -{ - return (mng_uint16)((mng_uint16)iB << 15); -} -#endif - -/* ************************************************************************** */ - -mng_uint8 mng_promote_zerofill_2_4 (mng_uint8 iB) -{ - return (mng_uint8)(iB << 2); -} - -/* ************************************************************************** */ - -mng_uint8 mng_promote_zerofill_2_8 (mng_uint8 iB) -{ - return (mng_uint8)(iB << 6); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_uint16 mng_promote_zerofill_2_16 (mng_uint8 iB) -{ - return (mng_uint16)((mng_uint16)iB << 14); -} -#endif - -/* ************************************************************************** */ - -mng_uint8 mng_promote_zerofill_4_8 (mng_uint8 iB) -{ - return (mng_uint8)(iB << 4); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_uint16 mng_promote_zerofill_4_16 (mng_uint8 iB) -{ - return (mng_uint16)((mng_uint16)iB << 12); -} -#endif -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_uint16 mng_promote_zerofill_8_16 (mng_uint8 iB) -{ - return (mng_uint16)((mng_uint16)iB << 8); -} -#endif -#endif /* MNG_NO_DELTA_PNG */ - -/* ************************************************************************** */ -/* * * */ -/* * Delta-image row routines - promote color_type * */ -/* * * */ -/* ************************************************************************** */ - -#if !defined(MNG_NO_DELTA_PNG) || !defined(MNG_SKIPCHUNK_PAST) || !defined(MNG_SKIPCHUNK_MAGN) -mng_retcode mng_promote_g8_g8 (mng_datap pData) -{ - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iB; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_G8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iB = *pSrcline; - if (pData->fPromBitdepth) /* bitdepth promoted ? */ - iB = ((mng_bitdepth_8)pData->fPromBitdepth) (iB); - *pDstline = iB; - - pSrcline++; - pDstline++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_G8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_g8_g16 (mng_datap pData) -{ - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint16 iW; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_G16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iW = ((mng_bitdepth_16)pData->fPromBitdepth) (*pSrcline); - - *pDstline = (mng_uint8)(iW >> 8); - *(pDstline+1) = (mng_uint8)(iW && 0xFF); - - pSrcline++; - pDstline += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_G16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_promote_g16_g16 (mng_datap pData) -{ - mng_uint16p pSrcline = (mng_uint16p)pData->pPromSrc; - mng_uint16p pDstline = (mng_uint16p)pData->pPromDst; - mng_uint32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G16_G16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - *pDstline = *pSrcline; - pSrcline++; - pDstline++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G16_G16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_promote_g8_ga8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iB; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_GA8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iB = *pSrcline; - /* no cheap transparency ? */ - if ((!pBuf->bHasTRNS) || ((mng_uint16)iB != pBuf->iTRNSgray)) - *(pDstline+1) = 0xFF; - - if (pData->fPromBitdepth) /* bitdepth promoted ? */ - iB = ((mng_bitdepth_8)pData->fPromBitdepth) (iB); - - *pDstline = iB; - - pSrcline++; - pDstline += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_GA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_g8_ga16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iB; - mng_uint16 iW; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_GA16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iB = *pSrcline; - /* no cheap transparency ? */ - if ((!pBuf->bHasTRNS) || ((mng_uint16)iB != pBuf->iTRNSgray)) - { - *(pDstline+2) = 0xFF; - *(pDstline+3) = 0xFF; - } - - iW = ((mng_bitdepth_16)pData->fPromBitdepth) (iB); - - *pDstline = (mng_uint8)(iW >> 8); - *(pDstline+1) = (mng_uint8)(iW && 0xFF); - - pSrcline++; - pDstline += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_GA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_g16_ga16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; - mng_uint16p pSrcline = (mng_uint16p)pData->pPromSrc; - mng_uint16p pDstline = (mng_uint16p)pData->pPromDst; - mng_uint32 iX; - mng_uint16 iW; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G16_GA16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iW = *pSrcline; - /* no cheap transparency ? */ - if ((!pBuf->bHasTRNS) || ((mng_uint16)iW != pBuf->iTRNSgray)) - *(pDstline+1) = 0xFFFF; - - *pDstline = iW; - - pSrcline++; - pDstline += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G16_GA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_promote_g8_rgb8 (mng_datap pData) -{ - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iB; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGB8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iB = *pSrcline; - - if (pData->fPromBitdepth) /* bitdepth promoted ? */ - iB = ((mng_bitdepth_8)pData->fPromBitdepth) (iB); - - *pDstline = iB; - *(pDstline+1) = iB; - *(pDstline+2) = iB; - - pSrcline++; - pDstline += 3; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_g8_rgb16 (mng_datap pData) -{ - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iB; - mng_uint16 iW; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGB16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iB = *pSrcline; - iW = ((mng_bitdepth_16)pData->fPromBitdepth) (iB); - - iB = (mng_uint8)(iW >> 8); - *pDstline = iB; - *(pDstline+2) = iB; - *(pDstline+4) = iB; - iB = (mng_uint8)(iW && 0xFF); - *(pDstline+1) = iB; - *(pDstline+3) = iB; - *(pDstline+5) = iB; - - pSrcline++; - pDstline += 6; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGB16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_g16_rgb16 (mng_datap pData) -{ - mng_uint16p pSrcline = (mng_uint16p)pData->pPromSrc; - mng_uint16p pDstline = (mng_uint16p)pData->pPromDst; - mng_uint32 iX; - mng_uint16 iW; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G16_RGB16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iW = *pSrcline; - - *pDstline = iW; - *(pDstline+1) = iW; - *(pDstline+2) = iW; - - pSrcline++; - pDstline += 3; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G16_RGB16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_promote_g8_rgba8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iB; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGBA8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iB = *pSrcline; - /* no cheap transparency ? */ - if ((!pBuf->bHasTRNS) || ((mng_uint16)iB != pBuf->iTRNSgray)) - *(pDstline+3) = 0xFF; - - if (pData->fPromBitdepth) /* bitdepth promoted ? */ - iB = ((mng_bitdepth_8)pData->fPromBitdepth) (iB); - - *pDstline = iB; - *(pDstline+1) = iB; - *(pDstline+2) = iB; - - pSrcline++; - pDstline += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_g8_rgba16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iB; - mng_uint16 iW; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGBA16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iB = *pSrcline; - /* no cheap transparency ? */ - if ((!pBuf->bHasTRNS) || ((mng_uint16)iB != pBuf->iTRNSgray)) - { - *(pDstline+6) = 0xFF; - *(pDstline+7) = 0xFF; - } - - iW = ((mng_bitdepth_16)pData->fPromBitdepth) (iB); - - iB = (mng_uint8)(iW >> 8); - *pDstline = iB; - *(pDstline+2) = iB; - *(pDstline+4) = iB; - iB = (mng_uint8)(iW && 0xFF); - *(pDstline+1) = iB; - *(pDstline+3) = iB; - *(pDstline+5) = iB;; - - pSrcline++; - pDstline += 8; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_g16_rgba16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; - mng_uint16p pSrcline = (mng_uint16p)pData->pPromSrc; - mng_uint16p pDstline = (mng_uint16p)pData->pPromDst; - mng_uint32 iX; - mng_uint16 iW; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G16_RGBA16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iW = *pSrcline; - /* no cheap transparency ? */ - if ((!pBuf->bHasTRNS) || (iW != pBuf->iTRNSgray)) - *(pDstline+3) = 0xFFFF; - - *pDstline = iW; - *(pDstline+1) = iW; - *(pDstline+2) = iW; - - pSrcline++; - pDstline += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_G16_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_ga8_ga16 (mng_datap pData) -{ - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint16 iW; - mng_uint16 iA; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_GA8_GA16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iW = ((mng_bitdepth_16)pData->fPromBitdepth) (*pSrcline); - iA = ((mng_bitdepth_16)pData->fPromBitdepth) (*(pSrcline+1)); - - *pDstline = (mng_uint8)(iW >> 8); - *(pDstline+1) = (mng_uint8)(iW && 0xFF); - *(pDstline+2) = (mng_uint8)(iA >> 8); - *(pDstline+3) = (mng_uint8)(iA && 0xFF); - - pSrcline += 2; - pDstline += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_GA8_GA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_promote_ga8_rgba8 (mng_datap pData) -{ - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iB; - mng_uint8 iA; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_GA8_RGBA8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iB = *pSrcline; - iA = *(pSrcline+1); - - *pDstline = iB; - *(pDstline+1) = iB; - *(pDstline+2) = iB; - *(pDstline+3) = iA; - - pSrcline += 2; - pDstline += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_GA8_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_ga8_rgba16 (mng_datap pData) -{ - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iB; - mng_uint16 iW; - mng_uint16 iA; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_GA8_RGBA16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iW = ((mng_bitdepth_16)pData->fPromBitdepth) (*pSrcline); - iA = ((mng_bitdepth_16)pData->fPromBitdepth) (*(pSrcline+1)); - - iB = (mng_uint8)(iW >> 8); - *pDstline = iB; - *(pDstline+2) = iB; - *(pDstline+4) = iB; - iB = (mng_uint8)(iW && 0xFF); - *(pDstline+1) = iB; - *(pDstline+3) = iB; - *(pDstline+5) = iB; - *(pDstline+6) = (mng_uint8)(iA >> 8); - *(pDstline+7) = (mng_uint8)(iA && 0xFF); - - pSrcline += 2; - pDstline += 8; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_GA8_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_ga16_rgba16 (mng_datap pData) -{ - mng_uint16p pSrcline = (mng_uint16p)pData->pPromSrc; - mng_uint16p pDstline = (mng_uint16p)pData->pPromDst; - mng_uint32 iX; - mng_uint16 iW; - mng_uint16 iA; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_GA16_RGBA16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iW = *pSrcline; - iA = *(pSrcline+1); - - *pDstline = iW; - *(pDstline+1) = iW; - *(pDstline+2) = iW; - *(pDstline+3) = iA; - - pSrcline += 2; - pDstline += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_GA16_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_rgb8_rgb16 (mng_datap pData) -{ - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint16 iR; - mng_uint16 iG; - mng_uint16 iB; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_RGB8_RGB16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iR = ((mng_bitdepth_16)pData->fPromBitdepth) (*pSrcline); - iG = ((mng_bitdepth_16)pData->fPromBitdepth) (*(pSrcline+1)); - iB = ((mng_bitdepth_16)pData->fPromBitdepth) (*(pSrcline+2)); - - *pDstline = (mng_uint8)(iR >> 8); - *(pDstline+1) = (mng_uint8)(iR && 0xFF); - *(pDstline+2) = (mng_uint8)(iG >> 8); - *(pDstline+3) = (mng_uint8)(iG && 0xFF); - *(pDstline+4) = (mng_uint8)(iB >> 8); - *(pDstline+5) = (mng_uint8)(iB && 0xFF); - - pSrcline += 3; - pDstline += 6; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_RGB8_RGB16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_promote_rgb8_rgba8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iR; - mng_uint8 iG; - mng_uint8 iB; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_RGB8_RGBA8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iR = *pSrcline; - iG = *(pSrcline+1); - iB = *(pSrcline+2); - /* no cheap transparency ? */ - if ((!pBuf->bHasTRNS) || ((mng_uint16)iR != pBuf->iTRNSred) || - ((mng_uint16)iG != pBuf->iTRNSgreen) || ((mng_uint16)iB != pBuf->iTRNSblue)) - *(pDstline+3) = 0xFF; - - *pDstline = iR; - *(pDstline+1) = iG; - *(pDstline+2) = iB; - - pSrcline += 3; - pDstline += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_RGB8_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_rgb8_rgba16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iR; - mng_uint8 iG; - mng_uint8 iB; - mng_uint16 iRw; - mng_uint16 iGw; - mng_uint16 iBw; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_RGB8_RGBA16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iR = *pSrcline; - iG = *(pSrcline+1); - iB = *(pSrcline+2); - /* no cheap transparency ? */ - if ((!pBuf->bHasTRNS) || ((mng_uint16)iR != pBuf->iTRNSred) || - ((mng_uint16)iG != pBuf->iTRNSgreen) || ((mng_uint16)iB != pBuf->iTRNSblue)) - { - *(pDstline+6) = 0xFF; - *(pDstline+7) = 0xFF; - } - - iRw = ((mng_bitdepth_16)pData->fPromBitdepth) (iR); - iGw = ((mng_bitdepth_16)pData->fPromBitdepth) (iG); - iBw = ((mng_bitdepth_16)pData->fPromBitdepth) (iB); - - *pDstline = (mng_uint8)(iRw >> 8); - *(pDstline+1) = (mng_uint8)(iRw && 0xFF); - *(pDstline+2) = (mng_uint8)(iGw >> 8); - *(pDstline+3) = (mng_uint8)(iGw && 0xFF); - *(pDstline+4) = (mng_uint8)(iBw >> 8); - *(pDstline+5) = (mng_uint8)(iBw && 0xFF); - - pSrcline += 3; - pDstline += 8; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_RGB8_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_rgb16_rgba16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; - mng_uint16p pSrcline = (mng_uint16p)pData->pPromSrc; - mng_uint16p pDstline = (mng_uint16p)pData->pPromDst; - mng_uint32 iX; - mng_uint16 iR; - mng_uint16 iG; - mng_uint16 iB; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_RGB16_RGBA16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iR = *pSrcline; - iG = *(pSrcline+1); - iB = *(pSrcline+2); - /* no cheap transparency ? */ - if ((!pBuf->bHasTRNS) || (iR != pBuf->iTRNSred) || - (iG != pBuf->iTRNSgreen) || (iB != pBuf->iTRNSblue)) - *(pDstline+3) = 0xFFFF; - - *pDstline = iR; - *(pDstline+1) = iG; - *(pDstline+2) = iB; - - pSrcline += 3; - pDstline += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_RGB16_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_promote_idx8_rgb8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iB; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGB8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iB = *pSrcline; - - if ((mng_uint32)iB < pBuf->iPLTEcount) - { - *pDstline = pBuf->aPLTEentries [iB].iRed; - *(pDstline+1) = pBuf->aPLTEentries [iB].iGreen; - *(pDstline+2) = pBuf->aPLTEentries [iB].iBlue; - } - - pSrcline++; - pDstline += 3; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_idx8_rgb16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iN; - mng_uint16 iR; - mng_uint16 iG; - mng_uint16 iB; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGB16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iN = *pSrcline; - - if ((mng_uint32)iN < pBuf->iPLTEcount) - { - iR = ((mng_bitdepth_16)pData->fPromBitdepth) (pBuf->aPLTEentries [iN].iRed); - iG = ((mng_bitdepth_16)pData->fPromBitdepth) (pBuf->aPLTEentries [iN].iGreen); - iB = ((mng_bitdepth_16)pData->fPromBitdepth) (pBuf->aPLTEentries [iN].iBlue); - *pDstline = (mng_uint8)(iR >> 8); - *(pDstline+1) = (mng_uint8)(iR && 0xFF); - *(pDstline+2) = (mng_uint8)(iG >> 8); - *(pDstline+3) = (mng_uint8)(iG && 0xFF); - *(pDstline+4) = (mng_uint8)(iB >> 8); - *(pDstline+5) = (mng_uint8)(iB && 0xFF); - } - - pSrcline++; - pDstline += 6; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGB16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_promote_idx8_rgba8 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iB; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGBA8, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iB = *pSrcline; - - if ((mng_uint32)iB < pBuf->iPLTEcount) - { - *pDstline = pBuf->aPLTEentries [iB].iRed; - *(pDstline+1) = pBuf->aPLTEentries [iB].iGreen; - *(pDstline+2) = pBuf->aPLTEentries [iB].iBlue; - - if ((pBuf->bHasTRNS) && ((mng_uint32)iB < pBuf->iTRNScount)) - *(pDstline+3) = pBuf->aTRNSentries [iB]; - else - *(pDstline+3) = 0xFF; - } - - pSrcline++; - pDstline += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_promote_idx8_rgba16 (mng_datap pData) -{ - mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint8 iN; - mng_uint16 iR; - mng_uint16 iG; - mng_uint16 iB; - mng_uint16 iA; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGBA16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iN = *pSrcline; - - if ((mng_uint32)iN < pBuf->iPLTEcount) - { - iR = ((mng_bitdepth_16)pData->fPromBitdepth) (pBuf->aPLTEentries [iN].iRed); - iG = ((mng_bitdepth_16)pData->fPromBitdepth) (pBuf->aPLTEentries [iN].iGreen); - iB = ((mng_bitdepth_16)pData->fPromBitdepth) (pBuf->aPLTEentries [iN].iBlue); - - if ((pBuf->bHasTRNS) && ((mng_uint32)iN < pBuf->iTRNScount)) - iA = ((mng_bitdepth_16)pData->fPromBitdepth) (pBuf->aTRNSentries [iN]); - else - iA = 0xFFFF; - - *pDstline = (mng_uint8)(iR >> 8); - *(pDstline+1) = (mng_uint8)(iR && 0xFF); - *(pDstline+2) = (mng_uint8)(iG >> 8); - *(pDstline+3) = (mng_uint8)(iG && 0xFF); - *(pDstline+4) = (mng_uint8)(iB >> 8); - *(pDstline+5) = (mng_uint8)(iB && 0xFF); - *(pDstline+6) = (mng_uint8)(iA >> 8); - *(pDstline+7) = (mng_uint8)(iA && 0xFF); - } - - pSrcline++; - pDstline += 8; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_promote_rgba8_rgba16 (mng_datap pData) -{ - mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; - mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; - mng_uint32 iX; - mng_uint16 iR; - mng_uint16 iG; - mng_uint16 iB; - mng_uint16 iA; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_RGBA8_RGBA16, MNG_LC_START); -#endif - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPromWidth; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPromWidth; iX++) -#endif - { - iR = ((mng_bitdepth_16)pData->fPromBitdepth) (*pSrcline); - iG = ((mng_bitdepth_16)pData->fPromBitdepth) (*(pSrcline+1)); - iB = ((mng_bitdepth_16)pData->fPromBitdepth) (*(pSrcline+2)); - iA = ((mng_bitdepth_16)pData->fPromBitdepth) (*(pSrcline+3)); - - *pDstline = (mng_uint8)(iR >> 8); - *(pDstline+1) = (mng_uint8)(iR && 0xFF); - *(pDstline+2) = (mng_uint8)(iG >> 8); - *(pDstline+3) = (mng_uint8)(iG && 0xFF); - *(pDstline+4) = (mng_uint8)(iB >> 8); - *(pDstline+5) = (mng_uint8)(iB && 0xFF); - *(pDstline+6) = (mng_uint8)(iA >> 8); - *(pDstline+7) = (mng_uint8)(iA && 0xFF); - - pSrcline += 4; - pDstline += 8; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROMOTE_RGBA8_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* !defined(MNG_NO_DELTA_PNG) || !defined(MNG_SKIPCHUNK_PAST) || !defined(MNG_SKIPCHUNK_MAGN) */ - -/* ************************************************************************** */ -/* * * */ -/* * Row processing routines - convert uncompressed data from zlib to * */ -/* * managable row-data which serves as input to the color-management * */ -/* * routines * */ -/* * * */ -/* ************************************************************************** */ - -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_retcode mng_process_g1 (mng_datap pData) -{ - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_G1, MNG_LC_START); -#endif - - if (!pBuf) /* no object? then use obj 0 */ - pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pRGBArow = pData->pRGBArow; - iM = 0; /* start at pixel 0 */ - iB = 0; - - if (pBuf->bHasTRNS) /* tRNS encountered ? */ - { - if (pBuf->iTRNSgray) /* white transparent ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0x80; - } - - if (iB & iM) /* is it white ? */ - /* transparent ! */ - mng_put_uint32 (pRGBArow, 0x00000000); - else /* opaque black */ - mng_put_uint32 (pRGBArow, 0x000000FF); - - pRGBArow += 4; /* next pixel */ - iM >>= 1; - } - } - else /* black transparent */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0x80; - } - - if (iB & iM) /* is it white ? */ - /* opaque white */ - mng_put_uint32 (pRGBArow, 0xFFFFFFFF); - else /* transparent */ - mng_put_uint32 (pRGBArow, 0x00000000); - - pRGBArow += 4; /* next pixel */ - iM >>= 1; - } - } - - pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ - } - else /* no transparency */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0x80; - } - - if (iB & iM) /* is it white ? */ - /* opaque white */ - mng_put_uint32 (pRGBArow, 0xFFFFFFFF); - else /* opaque black */ - mng_put_uint32 (pRGBArow, 0x000000FF); - - pRGBArow += 4; /* next pixel */ - iM >>= 1; - } - - pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_G1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_process_g2 (mng_datap pData) -{ - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - mng_uint8 iQ; - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; -#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH - const mng_uint32 level[4] = { 0x000000FF, 0x555555FF, - 0xAAAAAAFF, 0xFFFFFFFF}; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_G2, MNG_LC_START); -#endif - - if (!pBuf) /* no object? then use obj 0 */ - pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pRGBArow = pData->pRGBArow; - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - - if (pBuf->bHasTRNS) /* tRNS encountered ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xC0; - iS = 6; - } - /* determine gray level */ - iQ = (mng_uint8)((iB & iM) >> iS); - - if (iQ == pBuf->iTRNSgray) /* transparent ? */ - mng_put_uint32 (pRGBArow, 0x00000000); - else - { -#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH - mng_put_uint32 (pRGBArow, level[iQ]); -#else - switch (iQ) /* determine the gray level */ - { - case 0x03 : { mng_put_uint32 (pRGBArow, 0xFFFFFFFF); break; } - case 0x02 : { mng_put_uint32 (pRGBArow, 0xAAAAAAFF); break; } - case 0x01 : { mng_put_uint32 (pRGBArow, 0x555555FF); break; } - default : { mng_put_uint32 (pRGBArow, 0x000000FF); } - } -#endif - } - - pRGBArow += 4; /* next pixel */ - iM >>= 2; - iS -= 2; - } - - pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xC0; - iS = 6; - } - -#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH - mng_put_uint32 (pRGBArow, level[((iB & iM) >> iS)] ); -#else - switch ((iB & iM) >> iS) /* determine the gray level */ - { - case 0x03 : { mng_put_uint32 (pRGBArow, 0xFFFFFFFF); break; } - case 0x02 : { mng_put_uint32 (pRGBArow, 0xAAAAAAFF); break; } - case 0x01 : { mng_put_uint32 (pRGBArow, 0x555555FF); break; } - default : { mng_put_uint32 (pRGBArow, 0x000000FF); } - } -#endif - - pRGBArow += 4; /* next pixel */ - iM >>= 2; - iS -= 2; - } - - pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_G2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_process_g4 (mng_datap pData) -{ - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - mng_uint8 iQ; - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_G4, MNG_LC_START); -#endif - - if (!pBuf) /* no object? then use obj 0 */ - pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pRGBArow = pData->pRGBArow; - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - - if (pBuf->bHasTRNS) /* tRNS encountered ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xF0; - iS = 4; - } - /* get the gray level */ - iQ = (mng_uint8)((iB & iM) >> iS); - - if (iQ == pBuf->iTRNSgray) /* transparent ? */ - { - *pRGBArow = 0; /* put in intermediate row */ - *(pRGBArow+1) = 0; - *(pRGBArow+2) = 0; - *(pRGBArow+3) = 0; - } - else - { /* expand to 8-bit by replication */ - iQ = (mng_uint8)(iQ + (iQ << 4)); - - *pRGBArow = iQ; /* put in intermediate row */ - *(pRGBArow+1) = iQ; - *(pRGBArow+2) = iQ; - *(pRGBArow+3) = 0xFF; - } - - pRGBArow += 4; /* next pixel */ - iM >>= 4; - iS -= 4; - } - - pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xF0; - iS = 4; - } - /* get the gray level */ - iQ = (mng_uint8)((iB & iM) >> iS); - iQ = (mng_uint8)(iQ + (iQ << 4));/* expand to 8-bit by replication */ - - *pRGBArow = iQ; /* put in intermediate row */ - *(pRGBArow+1) = iQ; - *(pRGBArow+2) = iQ; - *(pRGBArow+3) = 0xFF; - - pRGBArow += 4; /* next pixel */ - iM >>= 4; - iS -= 4; - } - - pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_G4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - -/* ************************************************************************** */ - -mng_retcode mng_process_g8 (mng_datap pData) -{ - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint8 iB; - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_G8, MNG_LC_START); -#endif - - if (!pBuf) /* no object? then use obj 0 */ - pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pRGBArow = pData->pRGBArow; - - if (pBuf->bHasTRNS) /* tRNS encountered ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iB = *pWorkrow; /* get next input-byte */ - - if (iB == pBuf->iTRNSgray) /* transparent ? */ - { - *pRGBArow = 0; /* put in intermediate row */ - *(pRGBArow+1) = 0; - *(pRGBArow+2) = 0; - *(pRGBArow+3) = 0; - } - else - { - *pRGBArow = iB; /* put in intermediate row */ - *(pRGBArow+1) = iB; - *(pRGBArow+2) = iB; - *(pRGBArow+3) = 0xFF; - } - - pRGBArow += 4; /* next pixel */ - pWorkrow++; - } - - pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iB = *pWorkrow; /* get next input-byte */ - - *pRGBArow = iB; /* put in intermediate row */ - *(pRGBArow+1) = iB; - *(pRGBArow+2) = iB; - *(pRGBArow+3) = 0xFF; - - pRGBArow += 4; /* next pixel */ - pWorkrow++; - } - - pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_G8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_process_g16 (mng_datap pData) -{ - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint16 iW; - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_G16, MNG_LC_START); -#endif - - if (!pBuf) /* no object? then use obj 0 */ - pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pRGBArow = pData->pRGBArow; - - if (pBuf->bHasTRNS) /* tRNS encountered ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iW = mng_get_uint16 (pWorkrow); /* get input */ - - if (iW == pBuf->iTRNSgray) /* transparent ? */ - { /* put in intermediate row */ - mng_put_uint16 (pRGBArow, 0); - mng_put_uint16 (pRGBArow+2, 0); - mng_put_uint16 (pRGBArow+4, 0); - mng_put_uint16 (pRGBArow+6, 0); - } - else - { /* put in intermediate row */ - mng_put_uint16 (pRGBArow, iW); - mng_put_uint16 (pRGBArow+2, iW); - mng_put_uint16 (pRGBArow+4, iW); - mng_put_uint16 (pRGBArow+6, 0xFFFF); - } - - pRGBArow += 8; /* next pixel */ - pWorkrow += 2; - } - - pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iW = mng_get_uint16 (pWorkrow); /* get input */ - - mng_put_uint16 (pRGBArow, iW); /* and put in intermediate row */ - mng_put_uint16 (pRGBArow+2, iW); - mng_put_uint16 (pRGBArow+4, iW); - mng_put_uint16 (pRGBArow+6, 0xFFFF); - - pRGBArow += 8; /* next pixel */ - pWorkrow += 2; - } - - pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_G16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_rgb8 (mng_datap pData) -{ - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint8 iR, iG, iB; - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_RGB8, MNG_LC_START); -#endif - - if (!pBuf) /* no object? then use obj 0 */ - pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pRGBArow = pData->pRGBArow; - - if (pBuf->bHasTRNS) /* tRNS encountered ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iR = *pWorkrow; /* get the RGB values */ - iG = *(pWorkrow+1); - iB = *(pWorkrow+2); - /* transparent ? */ - if ((iR == pBuf->iTRNSred) && (iG == pBuf->iTRNSgreen) && - (iB == pBuf->iTRNSblue)) - { - *pRGBArow = 0; /* this pixel is transparent ! */ - *(pRGBArow+1) = 0; - *(pRGBArow+2) = 0; - *(pRGBArow+3) = 0; - } - else - { - *pRGBArow = iR; /* copy the RGB values */ - *(pRGBArow+1) = iG; - *(pRGBArow+2) = iB; - *(pRGBArow+3) = 0xFF; /* this one isn't transparent */ - } - - pWorkrow += 3; /* next pixel */ - pRGBArow += 4; - } - - pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pRGBArow = *pWorkrow; /* copy the RGB bytes */ - *(pRGBArow+1) = *(pWorkrow+1); - *(pRGBArow+2) = *(pWorkrow+2); - *(pRGBArow+3) = 0xFF; /* no alpha; so always fully opaque */ - - pWorkrow += 3; /* next pixel */ - pRGBArow += 4; - } - - pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_RGB8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_process_rgb16 (mng_datap pData) -{ - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint16 iR, iG, iB; - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_RGB16, MNG_LC_START); -#endif - - if (!pBuf) /* no object? then use obj 0 */ - pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pRGBArow = pData->pRGBArow; - - if (pBuf->bHasTRNS) /* tRNS encountered ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iR = mng_get_uint16 (pWorkrow); /* get the RGB values */ - iG = mng_get_uint16 (pWorkrow+2); - iB = mng_get_uint16 (pWorkrow+4); - /* transparent ? */ - if ((iR == pBuf->iTRNSred) && (iG == pBuf->iTRNSgreen) && - (iB == pBuf->iTRNSblue)) - { /* transparent then */ - mng_put_uint16 (pRGBArow, 0); - mng_put_uint16 (pRGBArow+2, 0); - mng_put_uint16 (pRGBArow+4, 0); - mng_put_uint16 (pRGBArow+6, 0); - } - else - { /* put in intermediate row */ - mng_put_uint16 (pRGBArow, iR); - mng_put_uint16 (pRGBArow+2, iG); - mng_put_uint16 (pRGBArow+4, iB); - mng_put_uint16 (pRGBArow+6, 0xFFFF); - } - - pWorkrow += 6; /* next pixel */ - pRGBArow += 8; - } - - pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* copy the RGB values */ - mng_put_uint16 (pRGBArow, mng_get_uint16 (pWorkrow )); - mng_put_uint16 (pRGBArow+2, mng_get_uint16 (pWorkrow+2)); - mng_put_uint16 (pRGBArow+4, mng_get_uint16 (pWorkrow+4)); - mng_put_uint16 (pRGBArow+6, 0xFFFF); - - pWorkrow += 6; /* next pixel */ - pRGBArow += 8; - } - - pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_RGB16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_retcode mng_process_idx1 (mng_datap pData) -{ - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - mng_uint8 iQ; - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_IDX1, MNG_LC_START); -#endif - - if (!pBuf) /* no object? then use obj 0 */ - pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pRGBArow = pData->pRGBArow; - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - - if (pBuf->bHasTRNS) /* tRNS encountered ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0x80; - iS = 7; - } - /* get the index */ - iQ = (mng_uint8)((iB & iM) >> iS); - /* index valid ? */ - if ((mng_uint32)iQ < pBuf->iPLTEcount) - { /* put in intermediate row */ - *pRGBArow = pBuf->aPLTEentries [iQ].iRed; - *(pRGBArow+1) = pBuf->aPLTEentries [iQ].iGreen; - *(pRGBArow+2) = pBuf->aPLTEentries [iQ].iBlue; - /* transparency for this index ? */ - if ((mng_uint32)iQ < pBuf->iTRNScount) - *(pRGBArow+3) = pBuf->aTRNSentries [iQ]; - else - *(pRGBArow+3) = 0xFF; - } - else - MNG_ERROR (pData, MNG_PLTEINDEXERROR); - - pRGBArow += 4; /* next pixel */ - iM >>= 1; - iS -= 1; - } - - pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0x80; - iS = 7; - } - /* get the index */ - iQ = (mng_uint8)((iB & iM) >> iS); - /* index valid ? */ - if ((mng_uint32)iQ < pBuf->iPLTEcount) - { /* put in intermediate row */ - *pRGBArow = pBuf->aPLTEentries [iQ].iRed; - *(pRGBArow+1) = pBuf->aPLTEentries [iQ].iGreen; - *(pRGBArow+2) = pBuf->aPLTEentries [iQ].iBlue; - *(pRGBArow+3) = 0xFF; - } - else - MNG_ERROR (pData, MNG_PLTEINDEXERROR); - - pRGBArow += 4; /* next pixel */ - iM >>= 1; - iS -= 1; - } - - pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_IDX1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_process_idx2 (mng_datap pData) -{ - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - mng_uint8 iQ; - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_IDX2, MNG_LC_START); -#endif - - if (!pBuf) /* no object? then use obj 0 */ - pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pRGBArow = pData->pRGBArow; - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - - if (pBuf->bHasTRNS) /* tRNS encountered ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xC0; - iS = 6; - } - /* get the index */ - iQ = (mng_uint8)((iB & iM) >> iS); - /* index valid ? */ - if ((mng_uint32)iQ < pBuf->iPLTEcount) - { /* put in intermediate row */ - *pRGBArow = pBuf->aPLTEentries [iQ].iRed; - *(pRGBArow+1) = pBuf->aPLTEentries [iQ].iGreen; - *(pRGBArow+2) = pBuf->aPLTEentries [iQ].iBlue; - /* transparency for this index ? */ - if ((mng_uint32)iQ < pBuf->iTRNScount) - *(pRGBArow+3) = pBuf->aTRNSentries [iQ]; - else - *(pRGBArow+3) = 0xFF; - } - else - MNG_ERROR (pData, MNG_PLTEINDEXERROR); - - pRGBArow += 4; /* next pixel */ - iM >>= 2; - iS -= 2; - } - - pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = *pWorkrow; /* get next input-byte */ - pWorkrow++; - iM = 0xC0; - iS = 6; - } - /* get the index */ - iQ = (mng_uint8)((iB & iM) >> iS); - /* index valid ? */ - if ((mng_uint32)iQ < pBuf->iPLTEcount) - { /* put in intermediate row */ - *pRGBArow = pBuf->aPLTEentries [iQ].iRed; - *(pRGBArow+1) = pBuf->aPLTEentries [iQ].iGreen; - *(pRGBArow+2) = pBuf->aPLTEentries [iQ].iBlue; - *(pRGBArow+3) = 0xFF; - } - else - MNG_ERROR (pData, MNG_PLTEINDEXERROR); - - pRGBArow += 4; /* next pixel */ - iM >>= 2; - iS -= 2; - } - - pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_IDX2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_process_idx4 (mng_datap pData) -{ - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint8 iB; - mng_uint8 iM; - mng_uint32 iS; - mng_uint8 iQ; - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_IDX4, MNG_LC_START); -#endif - - if (!pBuf) /* no object? then use obj 0 */ - pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pRGBArow = pData->pRGBArow; - iM = 0; /* start at pixel 0 */ - iB = 0; - iS = 0; - - if (pBuf->bHasTRNS) /* tRNS encountered ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = pWorkrow [0]; /* get next input-byte */ - pWorkrow++; - iM = 0xF0; - iS = 4; - } - /* get the index */ - iQ = (mng_uint8)((iB & iM) >> iS); - /* index valid ? */ - if ((mng_uint32)iQ < pBuf->iPLTEcount) - { /* put in intermediate row */ - pRGBArow [0] = pBuf->aPLTEentries [iQ].iRed; - pRGBArow [1] = pBuf->aPLTEentries [iQ].iGreen; - pRGBArow [2] = pBuf->aPLTEentries [iQ].iBlue; - /* transparency for this index ? */ - if ((mng_uint32)iQ < pBuf->iTRNScount) - pRGBArow [3] = pBuf->aTRNSentries [iQ]; - else - pRGBArow [3] = 0xFF; - } - else - MNG_ERROR (pData, MNG_PLTEINDEXERROR); - - pRGBArow += 4; /* next pixel */ - iM >>= 4; - iS -= 4; - } - - pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - if (!iM) /* mask underflow ? */ - { - iB = pWorkrow [0]; /* get next input-byte */ - pWorkrow++; - iM = 0xF0; - iS = 4; - } - /* get the index */ - iQ = (mng_uint8)((iB & iM) >> iS); - /* index valid ? */ - if ((mng_uint32)iQ < pBuf->iPLTEcount) - { /* put in intermediate row */ - pRGBArow [0] = pBuf->aPLTEentries [iQ].iRed; - pRGBArow [1] = pBuf->aPLTEentries [iQ].iGreen; - pRGBArow [2] = pBuf->aPLTEentries [iQ].iBlue; - pRGBArow [3] = 0xFF; - } - else - MNG_ERROR (pData, MNG_PLTEINDEXERROR); - - pRGBArow += 4; /* next pixel */ - iM >>= 4; - iS -= 4; - } - - pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_IDX4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - -/* ************************************************************************** */ - -mng_retcode mng_process_idx8 (mng_datap pData) -{ - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint8 iQ; - mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_IDX8, MNG_LC_START); -#endif - - if (!pBuf) /* no object? then use obj 0 */ - pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pRGBArow = pData->pRGBArow; - - if (pBuf->bHasTRNS) /* tRNS encountered ? */ - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iQ = *pWorkrow; /* get input byte */ - /* index valid ? */ - if ((mng_uint32)iQ < pBuf->iPLTEcount) - { /* put in intermediate row */ - pRGBArow [0] = pBuf->aPLTEentries [iQ].iRed; - pRGBArow [1] = pBuf->aPLTEentries [iQ].iGreen; - pRGBArow [2] = pBuf->aPLTEentries [iQ].iBlue; - /* transparency for this index ? */ - if ((mng_uint32)iQ < pBuf->iTRNScount) - pRGBArow [3] = pBuf->aTRNSentries [iQ]; - else - pRGBArow [3] = 0xFF; - } - else - MNG_ERROR (pData, MNG_PLTEINDEXERROR); - - pRGBArow += 4; /* next pixel */ - pWorkrow++; - } - - pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ - } - else - { -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iQ = *pWorkrow; /* get input byte */ - /* index valid ? */ - if ((mng_uint32)iQ < pBuf->iPLTEcount) - { /* put in intermediate row */ - pRGBArow [0] = pBuf->aPLTEentries [iQ].iRed; - pRGBArow [1] = pBuf->aPLTEentries [iQ].iGreen; - pRGBArow [2] = pBuf->aPLTEentries [iQ].iBlue; - pRGBArow [3] = 0xFF; - } - else - MNG_ERROR (pData, MNG_PLTEINDEXERROR); - - pRGBArow += 4; /* next pixel */ - pWorkrow++; - } - - pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_IDX8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_process_ga8 (mng_datap pData) -{ - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_GA8, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pRGBArow = pData->pRGBArow; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - *pRGBArow = *pWorkrow; /* copy the gray value */ - *(pRGBArow+1) = *pWorkrow; - *(pRGBArow+2) = *pWorkrow; - *(pRGBArow+3) = *(pWorkrow+1); /* copy the alpha value */ - - pWorkrow += 2; /* next pixel */ - pRGBArow += 4; - } - - pData->bIsOpaque = MNG_FALSE; /* it's definitely not fully opaque */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_GA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_process_ga16 (mng_datap pData) -{ - mng_uint8p pWorkrow; - mng_uint8p pRGBArow; - mng_int32 iX; - mng_uint16 iW; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_GA16, MNG_LC_START); -#endif - /* temporary work pointers */ - pWorkrow = pData->pWorkrow + pData->iPixelofs; - pRGBArow = pData->pRGBArow; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iW = mng_get_uint16 (pWorkrow); /* copy the gray value */ - mng_put_uint16 (pRGBArow, iW); - mng_put_uint16 (pRGBArow+2, iW); - mng_put_uint16 (pRGBArow+4, iW); - /* copy the alpha value */ - mng_put_uint16 (pRGBArow+6, mng_get_uint16 (pWorkrow+2)); - - pWorkrow += 4; /* next pixel */ - pRGBArow += 8; - } - - pData->bIsOpaque = MNG_FALSE; /* it's definitely not fully opaque */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_GA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_process_rgba8 (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_RGBA8, MNG_LC_START); -#endif - /* this is the easiest transform */ - MNG_COPY (pData->pRGBArow, pData->pWorkrow + pData->iPixelofs, pData->iRowsize); - - pData->bIsOpaque = MNG_FALSE; /* it's definitely not fully opaque */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_process_rgba16 (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_RGBA16, MNG_LC_START); -#endif - /* this is the easiest transform */ - MNG_COPY (pData->pRGBArow, pData->pWorkrow + pData->iPixelofs, pData->iRowsize); - - pData->bIsOpaque = MNG_FALSE; /* it's definitely not fully opaque */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ -/* * * */ -/* * Row processing initialization routines - set up the variables needed * */ -/* * to process uncompressed row-data * */ -/* * * */ -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_FOOTPRINT_INIT -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_retcode mng_init_g1_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G1_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_g1; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_g1; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_g1; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g1; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 1; - pData->iSampleofs = 7; - pData->iSamplediv = 3; - pData->iRowsize = (pData->iRowsamples + 7) >> 3; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G1_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_g1_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G1_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_g1; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_g1; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_g1; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g1; -#endif - - pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 1; - pData->iSampleofs = 7; - pData->iSamplediv = 3; - pData->iRowsize = ((pData->iRowsamples + 7) >> 3); - pData->iRowmax = ((pData->iDatawidth + 7) >> 3) + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G1_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_g2_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G2_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_g2; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_g2; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_g2; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g2; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 1; - pData->iSampleofs = 3; - pData->iSamplediv = 2; - pData->iRowsize = (pData->iRowsamples + 3) >> 2; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G2_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_g2_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G2_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_g2; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_g2; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_g2; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g2; -#endif - - pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 1; - pData->iSampleofs = 3; - pData->iSamplediv = 2; - pData->iRowsize = ((pData->iRowsamples + 3) >> 2); - pData->iRowmax = ((pData->iDatawidth + 3) >> 2) + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G2_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_g4_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G4_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_g4; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_g4; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_g4; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g4; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 1; - pData->iSampleofs = 1; - pData->iSamplediv = 1; - pData->iRowsize = (pData->iRowsamples + 1) >> 1; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G4_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_g4_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G4_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_g4; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_g4; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_g4; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g4; -#endif - - pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 1; - pData->iSampleofs = 1; - pData->iSamplediv = 1; - pData->iRowsize = ((pData->iRowsamples + 1) >> 1); - pData->iRowmax = ((pData->iDatawidth + 1) >> 1) + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G4_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - -/* ************************************************************************** */ - -mng_retcode mng_init_g8_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G8_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_g8; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_g8; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_g8; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g8; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 1; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G8_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_g8_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G8_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_g8; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_g8; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_g8; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g8; -#endif - - pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 1; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples; - pData->iRowmax = pData->iDatawidth + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G8_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_init_g16_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G16_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_g16; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_g16; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_g16; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g16; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 2; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples << 1; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 2; - pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G16_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_init_g16_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G16_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_g16; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_g16; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_g16; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g16; -#endif - - pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 2; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples << 1; - pData->iRowmax = (pData->iDatawidth << 1) + pData->iPixelofs; - pData->iFilterbpp = 2; - pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_G16_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_init_rgb8_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGB8_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_rgb8; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_rgb8; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_rgb8; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_rgb8; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 3; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples * 3; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 3; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGB8_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_rgb8_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGB8_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_rgb8; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_rgb8; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_rgb8; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_rgb8; -#endif - - pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 3; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples * 3; - pData->iRowmax = (pData->iDatawidth * 3) + pData->iPixelofs; - pData->iFilterbpp = 3; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGB8_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_init_rgb16_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGB16_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_rgb16; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_rgb16; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_rgb16; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_rgb16; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 6; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples * 6; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 6; - pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGB16_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_init_rgb16_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGB16_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_rgb16; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_rgb16; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_rgb16; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_rgb16; -#endif - - pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 6; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples * 6; - pData->iRowmax = (pData->iDatawidth * 6) + pData->iPixelofs; - pData->iFilterbpp = 6; - pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGB16_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_retcode mng_init_idx1_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX1_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_idx1; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_idx1; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_idx1; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_idx1; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 1; - pData->iSampleofs = 7; - pData->iSamplediv = 3; - pData->iRowsize = (pData->iRowsamples + 7) >> 3; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX1_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_idx1_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX1_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_idx1; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_idx1; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_idx1; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_idx1; -#endif - - pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 1; - pData->iSampleofs = 7; - pData->iSamplediv = 3; - pData->iRowsize = (pData->iRowsamples + 7) >> 3; - pData->iRowmax = ((pData->iDatawidth + 7) >> 3) + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX1_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_idx2_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX2_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_idx2; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_idx2; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_idx2; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_idx2; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 1; - pData->iSampleofs = 3; - pData->iSamplediv = 2; - pData->iRowsize = (pData->iRowsamples + 3) >> 2; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX2_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_idx2_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX2_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_idx2; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_idx2; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_idx2; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_idx2; -#endif - - pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 1; - pData->iSampleofs = 3; - pData->iSamplediv = 2; - pData->iRowsize = (pData->iRowsamples + 3) >> 2; - pData->iRowmax = ((pData->iDatawidth + 3) >> 2) + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX2_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_idx4_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX4_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_idx4; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_idx4; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_idx4; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_idx4; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 1; - pData->iSampleofs = 1; - pData->iSamplediv = 1; - pData->iRowsize = (pData->iRowsamples + 1) >> 1; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX4_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_idx4_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX4_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_idx4; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_idx4; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_idx4; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_idx4; -#endif - - pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 1; - pData->iSampleofs = 1; - pData->iSamplediv = 1; - pData->iRowsize = (pData->iRowsamples + 1) >> 1; - pData->iRowmax = ((pData->iDatawidth + 1) >> 1) + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX4_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - -/* ************************************************************************** */ - -mng_retcode mng_init_idx8_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX8_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_idx8; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_idx8; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_idx8; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_idx8; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 1; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX8_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_idx8_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX8_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_idx8; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_idx8; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_idx8; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_idx8; -#endif - - pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 1; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples; - pData->iRowmax = pData->iDatawidth + pData->iPixelofs; - pData->iFilterbpp = 1; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_IDX8_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_ga8_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_GA8_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_ga8; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_ga8; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_ga8; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_ga8; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 2; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples << 1; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 2; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_GA8_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_ga8_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_GA8_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_ga8; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_ga8; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_ga8; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_ga8; -#endif - - pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 2; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples << 1; - pData->iRowmax = (pData->iDatawidth << 1) + pData->iPixelofs; - pData->iFilterbpp = 2; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_GA8_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_init_ga16_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_GA16_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_ga16; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_ga16; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_ga16; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_ga16; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 4; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples << 2; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 4; - pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_GA16_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_init_ga16_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_GA16_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_ga16; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_ga16; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_ga16; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_ga16; -#endif - - pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 4; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples << 2; - pData->iRowmax = (pData->iDatawidth << 2) + pData->iPixelofs; - pData->iFilterbpp = 4; - pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_GA16_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_init_rgba8_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGBA8_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_rgba8; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_rgba8; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_rgba8; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_rgba8; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 4; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples << 2; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 4; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGBA8_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} -/* ************************************************************************** */ - -mng_retcode mng_init_rgba8_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGBA8_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_rgba8; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_rgba8; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_rgba8; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_rgba8; -#endif - - pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 4; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples << 2; - pData->iRowmax = (pData->iDatawidth << 2) + pData->iPixelofs; - pData->iFilterbpp = 4; - pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGBA8_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_init_rgba16_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGBA16_NI, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_rgba16; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_rgba16; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_rgba16; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_rgba16; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 8; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples << 3; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 8; - pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGBA16_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_init_rgba16_i (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGBA16_I, MNG_LC_START); -#endif - - if (pData->fDisplayrow) - pData->fProcessrow = (mng_fptr)mng_process_rgba16; - - if (pData->pStoreobj) /* store in object too ? */ - { /* immediate delta ? */ -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - pData->fStorerow = (mng_fptr)mng_delta_rgba16; - else -#endif - pData->fStorerow = (mng_fptr)mng_store_rgba16; - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_rgba16; -#endif - - pData->iPass = 0; /* from 0..6; (1..7 in specification) */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; - pData->iSamplemul = 8; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples << 3; - pData->iRowmax = (pData->iDatawidth << 3) + pData->iPixelofs; - pData->iFilterbpp = 8; - pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_RGBA16_I, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} -#endif - -/* ************************************************************************** */ -/* * * */ -/* * Row processing initialization routines (JPEG) - set up the variables * */ -/* * needed to process uncompressed row-data * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG - -/* ************************************************************************** */ - -#ifndef MNG_NO_1_2_4BIT_SUPPORT -mng_retcode mng_init_jpeg_a1_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JPEG_A1_NI, MNG_LC_START); -#endif - - if (pData->pStoreobj) /* store in object too ? */ - { - if (pData->iJHDRimgbitdepth == 8) - { - switch (pData->iJHDRcolortype) - { - case 12 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a1; break; } - case 14 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a1; break; } - } - } - - /* TODO: bitdepth 12 & 20 */ - - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g1; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 1; - pData->iSampleofs = 7; - pData->iSamplediv = 3; - pData->iRowsize = (pData->iRowsamples + 7) >> 3; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 1; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JPEG_A1_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_jpeg_a2_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JPEG_A2_NI, MNG_LC_START); -#endif - - if (pData->pStoreobj) /* store in object too ? */ - { - if (pData->iJHDRimgbitdepth == 8) - { - switch (pData->iJHDRcolortype) - { - case 12 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a2; break; } - case 14 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a2; break; } - } - } - - /* TODO: bitdepth 12 & 20 */ - - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g2; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 1; - pData->iSampleofs = 3; - pData->iSamplediv = 2; - pData->iRowsize = (pData->iRowsamples + 3) >> 2; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 1; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JPEG_A2_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_init_jpeg_a4_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JPEG_A4_NI, MNG_LC_START); -#endif - - if (pData->pStoreobj) /* store in object too ? */ - { - if (pData->iJHDRimgbitdepth == 8) - { - switch (pData->iJHDRcolortype) - { - case 12 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a4; break; } - case 14 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a4; break; } - } - } - - /* TODO: bitdepth 12 & 20 */ - - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g4; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 1; - pData->iSampleofs = 1; - pData->iSamplediv = 1; - pData->iRowsize = (pData->iRowsamples + 1) >> 1; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 1; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JPEG_A4_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - -/* ************************************************************************** */ - -mng_retcode mng_init_jpeg_a8_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JPEG_A8_NI, MNG_LC_START); -#endif - - if (pData->pStoreobj) /* store in object too ? */ - { - if (pData->iJHDRimgbitdepth == 8) - { - switch (pData->iJHDRcolortype) - { - case 12 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a8; break; } - case 14 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a8; break; } - } - } - - /* TODO: bitdepth 12 & 20 */ - - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g8; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 1; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 1; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JPEG_A8_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_init_jpeg_a16_ni (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JPEG_A16_NI, MNG_LC_START); -#endif - - if (pData->pStoreobj) /* store in object too ? */ - { - if (pData->iJHDRimgbitdepth == 8) - { - switch (pData->iJHDRcolortype) - { - case 12 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a16; break; } - case 14 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a16; break; } - } - } - - /* TODO: bitdepth 12 & 20 */ - - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - pData->fDifferrow = (mng_fptr)mng_differ_g16; -#endif - - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - pData->iSamplemul = 2; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iRowsize = pData->iRowsamples << 1; - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - pData->iFilterbpp = 2; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_JPEG_A16_NI, MNG_LC_END); -#endif - - return mng_init_rowproc (pData); -} -#endif - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_JNG */ -#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ - - -/* ************************************************************************** */ -/* * * */ -/* * Generic row processing initialization & cleanup routines * */ -/* * - initialize the buffers used by the row processing routines * */ -/* * - cleanup the buffers used by the row processing routines * */ -/* * * */ -/* ************************************************************************** */ - -mng_retcode mng_init_rowproc (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_ROWPROC, MNG_LC_START); -#endif - -#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT - if (pData->ePng_imgtype != png_none) - { - if (pData->fDisplayrow) - switch (pData->ePng_imgtype) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case png_g1: - pData->fProcessrow = (mng_fptr)mng_process_g1; - break; - case png_g2: - pData->fProcessrow = (mng_fptr)mng_process_g2; - break; - case png_g4: - pData->fProcessrow = (mng_fptr)mng_process_g4; - break; -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case png_g8: - pData->fProcessrow = (mng_fptr)mng_process_g8; - break; -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case png_idx1: - pData->fProcessrow = (mng_fptr)mng_process_idx1; - break; - case png_idx2: - pData->fProcessrow = (mng_fptr)mng_process_idx2; - break; - case png_idx4: - pData->fProcessrow = (mng_fptr)mng_process_idx4; - break; -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case png_idx8: - pData->fProcessrow = (mng_fptr)mng_process_idx8; - break; - case png_ga8: - pData->fProcessrow = (mng_fptr)mng_process_ga8; - break; - case png_rgb8: - pData->fProcessrow = (mng_fptr)mng_process_rgb8; - break; - case png_rgba8: - pData->fProcessrow = (mng_fptr)mng_process_rgba8; - break; -#ifndef MNG_NO_16BIT_SUPPORT - case png_g16: - pData->fProcessrow = (mng_fptr)mng_process_g16; - break; - case png_ga16: - pData->fProcessrow = (mng_fptr)mng_process_ga16; - break; - case png_rgb16: - pData->fProcessrow = (mng_fptr)mng_process_rgb16; - break; - case png_rgba16: - pData->fProcessrow = (mng_fptr)mng_process_rgba16; - break; -#endif - default: - break; - } - - if (pData->pStoreobj) /* store in object too ? */ - { -#ifndef MNG_NO_DELTA_PNG - if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) - switch (pData->ePng_imgtype) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case png_g1: - pData->fStorerow = (mng_fptr)mng_delta_g1; - break; - case png_g2: - pData->fStorerow = (mng_fptr)mng_delta_g2; - break; - case png_g4: - pData->fStorerow = (mng_fptr)mng_delta_g4; - break; -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case png_g8: - pData->fStorerow = (mng_fptr)mng_delta_g8; - break; -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case png_idx1: - pData->fStorerow = (mng_fptr)mng_delta_idx1; - break; - case png_idx2: - pData->fStorerow = (mng_fptr)mng_delta_idx2; - break; - case png_idx4: - pData->fStorerow = (mng_fptr)mng_delta_idx4; - break; -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case png_idx8: - pData->fStorerow = (mng_fptr)mng_delta_idx8; - break; - case png_ga8: - pData->fStorerow = (mng_fptr)mng_delta_ga8; - break; - case png_rgb8: - pData->fStorerow = (mng_fptr)mng_delta_rgb8; - break; - case png_rgba8: - pData->fStorerow = (mng_fptr)mng_delta_rgba8; - break; -#ifndef MNG_NO_16BIT_SUPPORT - case png_g16: - pData->fStorerow = (mng_fptr)mng_delta_g16; - break; - case png_ga16: - pData->fStorerow = (mng_fptr)mng_delta_ga16; - break; - case png_rgb16: - pData->fStorerow = (mng_fptr)mng_delta_rgb16; - break; - case png_rgba16: - pData->fStorerow = (mng_fptr)mng_delta_rgba16; - break; -#endif - default: - break; - } - else -#endif /* MNG_NO_DELTA_PNG */ - switch (pData->ePng_imgtype) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case png_g1: - pData->fStorerow = (mng_fptr)mng_store_g1; - break; - case png_g2: - pData->fStorerow = (mng_fptr)mng_store_g2; - break; - case png_g4: - pData->fStorerow = (mng_fptr)mng_store_g4; - break; -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case png_g8: - pData->fStorerow = (mng_fptr)mng_store_g8; - break; -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case png_idx1: - pData->fStorerow = (mng_fptr)mng_store_idx1; - break; - case png_idx2: - pData->fStorerow = (mng_fptr)mng_store_idx2; - break; - case png_idx4: - pData->fStorerow = (mng_fptr)mng_store_idx4; - break; -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case png_idx8: - pData->fStorerow = (mng_fptr)mng_store_idx8; - break; - case png_ga8: - pData->fStorerow = (mng_fptr)mng_store_ga8; - break; - case png_rgb8: - pData->fStorerow = (mng_fptr)mng_store_rgb8; - break; - case png_rgba8: - pData->fStorerow = (mng_fptr)mng_store_rgba8; - break; -#ifndef MNG_NO_16BIT_SUPPORT - case png_g16: - pData->fStorerow = (mng_fptr)mng_store_g16; - break; - case png_ga16: - pData->fStorerow = (mng_fptr)mng_store_ga16; - break; - case png_rgb16: - pData->fStorerow = (mng_fptr)mng_store_rgb16; - break; - case png_rgba16: - pData->fStorerow = (mng_fptr)mng_store_rgba16; - break; -#endif - -#ifdef MNG_INCLUDE_JNG -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case png_jpeg_a1: -/* if (pData->iJHDRimgbitdepth == 8) */ - { - switch (pData->iJHDRcolortype) - { - case 12 : - { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a1; break; } - case 14 : - { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a1; break; } - } - } - /* TODO: bitdepth 12 & 20 */ - break; - case png_jpeg_a2: -/* if (pData->iJHDRimgbitdepth == 8) */ - { - switch (pData->iJHDRcolortype) - { - case 12 : - { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a2; break; } - case 14 : - { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a2; break; } - } - } - break; - /* TODO: bitdepth 12 & 20 */ - case png_jpeg_a4: -/* if (pData->iJHDRimgbitdepth == 8) */ - { - switch (pData->iJHDRcolortype) - { - case 12 : - { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a4; break; } - case 14 : - { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a4; break; } - } - } - break; -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - /* TODO: bitdepth 12 & 20 */ - case png_jpeg_a8: -/* if (pData->iJHDRimgbitdepth == 8) */ - { - switch (pData->iJHDRcolortype) - { - case 12 : - { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a8; break; } - case 14 : - { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a8; break; } - } - } - break; - /* TODO: bitdepth 12 & 20 */ -#ifndef MNG_NO_16BIT_SUPPORT - case png_jpeg_a16: -/* if (pData->iJHDRimgbitdepth == 8) */ - { - switch (pData->iJHDRcolortype) - { - case 12 : - { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a16; break; } - case 14 : - { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a16; break; } - } - } - break; - /* TODO: bitdepth 12 & 20 */ -#endif -#endif /* MNG_INCLUDE_JNG */ - default: - break; - } - } - -#ifdef FILTER192 /* leveling & differing ? */ - if (pData->iFilter == MNG_FILTER_DIFFERING) - switch (pData->ePng_imgtype) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case png_g1: -#ifdef MNG_INCLUDE_JNG - case png_jpeg_a1: -#endif - pData->fDifferrow = (mng_fptr)mng_differ_g1; - break; - case png_g2: -#ifdef MNG_INCLUDE_JNG - case png_jpeg_a2: -#endif - pData->fDifferrow = (mng_fptr)mng_differ_g2; - break; - case png_g4: -#ifdef MNG_INCLUDE_JNG - case png_jpeg_a4: -#endif - pData->fDifferrow = (mng_fptr)mng_differ_g4; - break; -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case png_g8: -#ifdef MNG_INCLUDE_JNG - case png_jpeg_a8: -#endif - pData->fDifferrow = (mng_fptr)mng_differ_g8; - break; - case png_rgb8: - pData->fDifferrow = (mng_fptr)mng_differ_rgb8; - break; -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case png_idx1: - pData->fDifferrow = (mng_fptr)mng_differ_idx1; - break; - case png_idx2: - pData->fDifferrow = (mng_fptr)mng_differ_idx2; - break; - case png_idx4: - pData->fDifferrow = (mng_fptr)mng_differ_idx4; - break; -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case png_idx8: - pData->fDifferrow = (mng_fptr)mng_differ_idx8; - break; - case png_ga8: - pData->fDifferrow = (mng_fptr)mng_differ_ga8; - break; - case png_rgb8: - pData->fDifferrow = (mng_fptr)mng_differ_rgb8; - break; - case png_rgba8: - pData->fDifferrow = (mng_fptr)mng_differ_rgba8; - break; -#ifndef MNG_NO_16BIT_SUPPORT - case png_g16: -#ifdef MNG_INCLUDE_JNG - case png_jpeg_a16: -#endif - pData->fDifferrow = (mng_fptr)mng_differ_g16; - break; - case png_ga16: - pData->fDifferrow = (mng_fptr)mng_differ_ga16; - break; - case png_rgb16: - pData->fDifferrow = (mng_fptr)mng_differ_rgb16; - break; - case png_rgba16: - pData->fDifferrow = (mng_fptr)mng_differ_rgba16; - break; -#endif - default: - break; - } -#endif - - switch (pData->ePng_imgtype) - { -#ifndef MNG_NO_1_2_4BIT_SUPPORT - case png_g1: - case png_idx1: -#ifdef MNG_INCLUDE_JNG - case png_jpeg_a1: -#endif - pData->iSamplemul = 1; - pData->iSampleofs = 7; - pData->iSamplediv = 3; - pData->iFilterbpp = 1; - break; - case png_g2: - case png_idx2: -#ifdef MNG_INCLUDE_JNG - case png_jpeg_a2: -#endif - pData->iSamplemul = 1; - pData->iSampleofs = 3; - pData->iSamplediv = 2; - pData->iFilterbpp = 1; - break; - case png_g4: - case png_idx4: -#ifdef MNG_INCLUDE_JNG - case png_jpeg_a4: -#endif - pData->iSamplemul = 1; - pData->iSampleofs = 1; - pData->iSamplediv = 1; - pData->iFilterbpp = 1; - break; -#endif /* MNG_NO_1_2_4BIT_SUPPORT */ - case png_g8: - case png_idx8: -#ifdef MNG_INCLUDE_JNG - case png_jpeg_a8: -#endif - pData->iSamplemul = 1; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iFilterbpp = 1; - break; - case png_ga8: -#ifndef MNG_NO_16BIT_SUPPORT - case png_g16: -#ifdef MNG_INCLUDE_JNG - case png_jpeg_a16: -#endif -#endif - pData->iSamplemul = 2; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iFilterbpp = 2; - break; - case png_rgb8: - pData->iSamplemul = 3; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iFilterbpp = 3; - break; -#ifndef MNG_NO_16BIT_SUPPORT - case png_ga16: -#endif - case png_rgba8: - pData->iSamplemul = 4; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iFilterbpp = 4; - break; -#ifndef MNG_NO_16BIT_SUPPORT - case png_rgb16: - pData->iSamplemul = 6; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iFilterbpp = 6; - break; - case png_rgba16: - pData->iSamplemul = 8; - pData->iSampleofs = 0; - pData->iSamplediv = 0; - pData->iFilterbpp = 8; - break; -#endif - default: - break; - } - - if (pData->iInterlace) /* noninterlaced */ - { - pData->iPass = 0; /* from 0..6; (1..7 in specification) */ - pData->iRow = interlace_row [0]; - pData->iRowinc = interlace_rowskip [0]; - pData->iCol = interlace_col [0]; - pData->iColinc = interlace_colskip [0]; - pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> - interlace_divider [0]; - pData->iRowmax = ((pData->iDatawidth * pData->iSamplemul + - pData->iSampleofs) >> pData->iSamplediv) + pData->iPixelofs; - } - else /* interlaced */ - { - pData->iPass = -1; - pData->iRow = 0; - pData->iRowinc = 1; - pData->iCol = 0; - pData->iColinc = 1; - pData->iRowsamples = pData->iDatawidth; - } - if (pData->iSamplediv > 0) - pData->iRowsize = (pData->iRowsamples + pData->iSampleofs) >> - pData->iSamplediv; - else - pData->iRowsize = (pData->iRowsamples * pData->iSamplemul); - - if (!pData->iInterlace) /* noninterlaced */ - pData->iRowmax = pData->iRowsize + pData->iPixelofs; - -#ifdef MNG_NO_16BIT_SUPPORT - pData->bIsRGBA16 = MNG_FALSE; -#else - switch (pData->ePng_imgtype) - { - case png_g16: - case png_ga16: - case png_rgb16: - case png_rgba16: - pData->bIsRGBA16 = MNG_TRUE; - break; - default: - pData->bIsRGBA16 = MNG_FALSE; - break; - } -#endif - - } -#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ - - if (pData->pStoreobj) /* storage object selected ? */ - { - pData->pStorebuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - /* and so it becomes viewable ! */ - ((mng_imagep)pData->pStoreobj)->bViewable = MNG_TRUE; - ((mng_imagedatap)pData->pStorebuf)->bViewable = MNG_TRUE; - } - - /* allocate the buffers; the individual init routines have already - calculated the required maximum size; except in the case of a JNG - without alpha!!! */ - if (pData->iRowmax) - { -#if defined(MNG_NO_16BIT_SUPPORT) || defined (MNG_NO_1_2_4BIT_SUPPORT) - mng_uint8 iRowadd = 0; -#ifdef MNG_NO_1_2_4BIT_SUPPORT - if (pData->iPNGdepth < 8) - iRowadd=(pData->iPNGdepth*pData->iRowmax+7)/8; -#endif -#ifdef MNG_NO_16BIT_SUPPORT - if (pData->iPNGdepth > 8) - iRowadd=pData->iRowmax; -#endif - MNG_ALLOC (pData, pData->pWorkrow, pData->iRowmax+iRowadd); - MNG_ALLOC (pData, pData->pPrevrow, pData->iRowmax+iRowadd); -#else - MNG_ALLOC (pData, pData->pWorkrow, pData->iRowmax); - MNG_ALLOC (pData, pData->pPrevrow, pData->iRowmax); -#endif - } - - /* allocate an RGBA16 row for intermediate processing */ - MNG_ALLOC (pData, pData->pRGBArow, (pData->iDatawidth << 3)); - -#ifndef MNG_NO_CMS - if (pData->fDisplayrow) /* display "on-the-fly" ? */ - { -#if defined(MNG_FULL_CMS) /* determine color-management initialization */ - mng_retcode iRetcode = mng_init_full_cms (pData, MNG_TRUE, MNG_TRUE, MNG_FALSE); -#elif defined(MNG_GAMMA_ONLY) - mng_retcode iRetcode = mng_init_gamma_only (pData, MNG_TRUE, MNG_TRUE, MNG_FALSE); -#elif defined(MNG_APP_CMS) - mng_retcode iRetcode = mng_init_app_cms (pData, MNG_TRUE, MNG_TRUE, MNG_FALSE); -#endif - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* !MNG_NO_CMS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_INIT_ROWPROC, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_next_row (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_NEXT_ROW, MNG_LC_START); -#endif - - pData->iRow += pData->iRowinc; /* increase the row counter */ - - if (pData->iPass >= 0) /* interlaced ? */ - { - while ((pData->iPass < 7) && /* went 'outside' the image ? */ - ((pData->iRow >= (mng_int32)pData->iDataheight) || - (pData->iCol >= (mng_int32)pData->iDatawidth ) )) - { - pData->iPass++; /* next pass ! */ - - if (pData->iPass < 7) /* there's only 7 passes ! */ - { - pData->iRow = interlace_row [pData->iPass]; - pData->iRowinc = interlace_rowskip [pData->iPass]; - pData->iCol = interlace_col [pData->iPass]; - pData->iColinc = interlace_colskip [pData->iPass]; - pData->iRowsamples = (pData->iDatawidth - pData->iCol + interlace_roundoff [pData->iPass]) - >> interlace_divider [pData->iPass]; - - if (pData->iSamplemul > 1) /* recalculate row dimension */ - pData->iRowsize = pData->iRowsamples * pData->iSamplemul; - else - if (pData->iSamplediv > 0) - pData->iRowsize = (pData->iRowsamples + pData->iSampleofs) >> pData->iSamplediv; - else - pData->iRowsize = pData->iRowsamples; - - } - - if ((pData->iPass < 7) && /* reset previous row to zeroes ? */ - (pData->iRow < (mng_int32)pData->iDataheight) && - (pData->iCol < (mng_int32)pData->iDatawidth ) ) - { /* making sure the filters will work properly! */ - mng_int32 iX; - mng_uint8p pTemp = pData->pPrevrow; - -#ifdef MNG_NO_16BIT_SUPPORT -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iPNGmult*pData->iRowsize; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iPNGmult*pData->iRowsize; iX++) -#endif -#else -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsize; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsize; iX++) -#endif -#endif - { - *pTemp = 0; - pTemp++; - } - } - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_NEXT_ROW, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_cleanup_rowproc (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CLEANUP_ROWPROC, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_LCMS /* cleanup cms profile/transform */ - { - mng_retcode iRetcode = mng_clear_cms (pData); - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif /* MNG_INCLUDE_LCMS */ - - if (pData->pRGBArow) /* cleanup buffer for intermediate row */ - MNG_FREEX (pData, pData->pRGBArow, (pData->iDatawidth << 3)); - if (pData->pPrevrow) /* cleanup buffer for previous row */ - MNG_FREEX (pData, pData->pPrevrow, pData->iRowmax); - if (pData->pWorkrow) /* cleanup buffer for working row */ - MNG_FREEX (pData, pData->pWorkrow, pData->iRowmax); - - pData->pWorkrow = MNG_NULL; /* propogate uninitialized buffers */ - pData->pPrevrow = MNG_NULL; - pData->pRGBArow = MNG_NULL; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_CLEANUP_ROWPROC, MNG_LC_END); -#endif - - return MNG_NOERROR; /* woohiii */ -} - -/* ************************************************************************** */ -/* * * */ -/* * Generic row processing routines for JNG * */ -/* * * */ -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG - -/* ************************************************************************** */ - -mng_retcode mng_display_jpeg_rows (mng_datap pData) -{ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_JPEG_ROWS, MNG_LC_START); -#endif - /* any completed rows ? */ - if ((pData->iJPEGrow > pData->iJPEGdisprow) && - (pData->iJPEGalpharow > pData->iJPEGdisprow) ) - { - mng_uint32 iX, iMax; - mng_uint32 iSaverow = pData->iRow; /* save alpha decompression row-count */ - /* determine the highest complete(!) row */ - if (pData->iJPEGrow > pData->iJPEGalpharow) - iMax = pData->iJPEGalpharow; - else - iMax = pData->iJPEGrow; - /* display the rows */ - for (iX = pData->iJPEGdisprow; iX < iMax; iX++) - { - pData->iRow = iX; /* make sure we all know which row to handle */ - /* makeup an intermediate row from the buffer */ - iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData); - /* color-correct it if necessary */ - if ((!iRetcode) && (pData->fCorrectrow)) - iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData); - - if (!iRetcode) /* and display it */ - { - iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData); - - if (!iRetcode) /* check progressive display refresh */ - iRetcode = mng_display_progressive_check (pData); - } - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - - pData->iJPEGdisprow = iMax; /* keep track of the last displayed row */ - pData->iRow = iSaverow; /* restore alpha decompression row-count */ - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DISPLAY_JPEG_ROWS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_next_jpeg_alpharow (mng_datap pData) -{ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_NEXT_JPEG_ALPHAROW, MNG_LC_START); -#endif - - pData->iJPEGalpharow++; /* count the row */ - - if (pData->fDisplayrow) /* display "on-the-fly" ? */ - { /* try to display what you can */ - iRetcode = mng_display_jpeg_rows (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_NEXT_JPEG_ALPHAROW, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_next_jpeg_row (mng_datap pData) -{ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_NEXT_JPEG_ROW, MNG_LC_START); -#endif - - pData->iJPEGrow++; /* increase the row-counter */ - - if (pData->fDisplayrow) /* display "on-the-fly" ? */ - { /* has alpha channel ? */ - if ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || - (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) - { /* try to display what you can */ - iRetcode = mng_display_jpeg_rows (pData); - } - else - { /* make sure we all know which row to handle */ - pData->iRow = pData->iJPEGrow - 1; - /* makeup an intermediate row from the buffer */ - iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData); - /* color-correct it if necessary */ - if ((!iRetcode) && (pData->fCorrectrow)) - iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData); - - if (!iRetcode) /* and display it */ - { - iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData); - - if (!iRetcode) /* check progressive display refresh */ - iRetcode = mng_display_progressive_check (pData); - } - } - - if (iRetcode) /* on error bail out */ - return iRetcode; - } - - /* surpassed last filled row ? */ - if (pData->iJPEGrow > pData->iJPEGrgbrow) - pData->iJPEGrgbrow = pData->iJPEGrow; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_NEXT_JPEG_ROW, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_MAGN -#ifndef MNG_OPTIMIZE_FOOTPRINT_MAGN -#ifndef MNG_NO_GRAY_SUPPORT -mng_retcode mng_magnify_g8_x1 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX, iS, iM; - mng_uint8p pTempsrc1; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_X1, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - - if (iX == 0) /* first interval ? */ - iM = iML; - else - if (iX == (iWidth - 1)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - - for (iS = 1; iS < iM; iS++) /* fill interval */ - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - } - - pTempsrc1++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_X1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_g8_x2 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_X2, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 1; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { /* is it same as first ? */ - if (*pTempsrc1 == *pTempsrc2) - { - for (iS = 1; iS < iM; iS++) /* then just repeat the first */ - { - *pTempdst = *pTempsrc1; - pTempdst++; - } - } - else - { - for (iS = 1; iS < iM; iS++) /* calculate the distances */ - { - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2)) + (mng_int32)(*pTempsrc1) ); - pTempdst++; - } - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - } - } - } - - pTempsrc1++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_X2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_g8_x3 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_X3, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 1; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { /* is it same as first ? */ - if (*pTempsrc1 == *pTempsrc2) - { - for (iS = 1; iS < iM; iS++) /* then just repeat the first */ - { - *pTempdst = *pTempsrc1; - pTempdst++; - } - } - else - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* replicate first half */ - { - *pTempdst = *pTempsrc1; - pTempdst++; - } - - for (iS = iH; iS < iM; iS++) /* replicate second half */ - { - *pTempdst = *pTempsrc2; - pTempdst++; - } - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - } - } - } - - pTempsrc1++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_X3, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_GRAY_SUPPORT */ - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgb8_x1 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX, iS, iM; - mng_uint8p pTempsrc1; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_X1, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - - if (iX == 0) /* first interval ? */ - iM = iML; - else - if (iX == (iWidth - 1)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - - for (iS = 1; iS < iM; iS++) /* fill interval */ - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - } - - pTempsrc1 += 3; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_X1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgb8_x2 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_X2, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 3; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = (mng_int32)iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = (mng_int32)iMR; - else - iM = (mng_int32)iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - for (iS = 1; iS < iM; iS++) - { - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; /* just repeat the first */ - else /* calculate the distance */ - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2)) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - - if (*(pTempsrc1+1) == *(pTempsrc2+1)) - *pTempdst = *(pTempsrc1+1); - else - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+1)) - - (mng_int32)(*(pTempsrc1+1)) ) + iM) / - (iM * 2)) + (mng_int32)(*(pTempsrc1+1)) ); - - pTempdst++; - - if (*(pTempsrc1+2) == *(pTempsrc2+2)) - *pTempdst = *(pTempsrc1+2); - else - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+2)) - - (mng_int32)(*(pTempsrc1+2)) ) + iM) / - (iM * 2)) + (mng_int32)(*(pTempsrc1+2)) ); - - pTempdst++; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - } - } - } - - pTempsrc1 += 3; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_X2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgb8_x3 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_X3, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 3; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = (mng_int32)iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = (mng_int32)iMR; - else - iM = (mng_int32)iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* replicate first half */ - { - *pTempdst = *pTempsrc1; - *(pTempdst+1) = *(pTempsrc1+1); - *(pTempdst+2) = *(pTempsrc1+2); - - pTempdst += 3; - } - - for (iS = iH; iS < iM; iS++) /* replicate second half */ - { - *pTempdst = *pTempsrc2; - *(pTempdst+1) = *(pTempsrc2+1); - *(pTempdst+2) = *(pTempsrc2+2); - - pTempdst += 3; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - } - } - } - - pTempsrc1 += 3; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_X3, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_GRAY_SUPPORT -mng_retcode mng_magnify_ga8_x1 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX, iS, iM; - mng_uint8p pTempsrc1; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X1, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - - if (iX == 0) /* first interval ? */ - iM = iML; - else - if (iX == (iWidth - 1)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - - for (iS = 1; iS < iM; iS++) /* fill interval */ - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - } - - pTempsrc1 += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga8_x2 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X2, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 2; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - for (iS = 1; iS < iM; iS++) - { - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; /* just repeat the first */ - else /* calculate the distance */ - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2)) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - - if (*(pTempsrc1+1) == *(pTempsrc2+1)) - *pTempdst = *(pTempsrc1+1); - else - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+1)) - - (mng_int32)(*(pTempsrc1+1)) ) + iM) / - (iM * 2)) + (mng_int32)(*(pTempsrc1+1)) ); - - pTempdst++; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - } - } - } - - pTempsrc1 += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga8_x3 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X3, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 2; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* replicate first half */ - { - *pTempdst = *pTempsrc1; - *(pTempdst+1) = *(pTempsrc1+1); - - pTempdst += 2; - } - - for (iS = iH; iS < iM; iS++) /* replicate second half */ - { - *pTempdst = *pTempsrc2; - *(pTempdst+1) = *(pTempsrc2+1); - - pTempdst += 2; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - } - } - } - - pTempsrc1 += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X3, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga8_x4 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X4, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 2; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* first half */ - { - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; /* just repeat the first */ - else /* calculate the distance */ - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2)) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - - *pTempdst = *(pTempsrc1+1); /* replicate alpha from left */ - - pTempdst++; - } - - for (iS = iH; iS < iM; iS++) /* second half */ - { - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; /* just repeat the first */ - else /* calculate the distance */ - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2)) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - - *pTempdst = *(pTempsrc2+1); /* replicate alpha from right */ - - pTempdst++; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - } - } - } - - pTempsrc1 += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga8_x5 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X5, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 2; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* first half */ - { - *pTempdst = *pTempsrc1; /* replicate gray from left */ - - pTempdst++; - - if (*(pTempsrc1+1) == *(pTempsrc2+1)) - *pTempdst = *(pTempsrc1+1);/* just repeat the first */ - else /* calculate the distance */ - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+1)) - - (mng_int32)(*(pTempsrc1+1)) ) + iM) / - (iM * 2)) + (mng_int32)(*(pTempsrc1+1)) ); - - pTempdst++; - } - - for (iS = iH; iS < iM; iS++) /* second half */ - { - *pTempdst = *pTempsrc2; /* replicate gray from right */ - - pTempdst++; - - if (*(pTempsrc1+1) == *(pTempsrc2+1)) - *pTempdst = *(pTempsrc1+1);/* just repeat the first */ - else /* calculate the distance */ - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+1)) - - (mng_int32)(*(pTempsrc1+1)) ) + iM) / - (iM * 2)) + (mng_int32)(*(pTempsrc1+1)) ); - - pTempdst++; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - } - } - } - - pTempsrc1 += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X5, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_GRAY_SUPPORT */ -#endif /* MNG_OPTIMIZE_FOOTPRINT_MAGN */ - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba8_x1 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX, iS, iM; - mng_uint8p pTempsrc1; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X1, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - - if (iX == 0) /* first interval ? */ - iM = iML; - else - if (iX == (iWidth - 1)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - - for (iS = 1; iS < iM; iS++) /* fill interval */ - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - } - - pTempsrc1 += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba8_x2 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X2, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 4; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = (mng_int32)iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = (mng_int32)iMR; - else - iM = (mng_int32)iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - for (iS = 1; iS < iM; iS++) - { - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; /* just repeat the first */ - else /* calculate the distance */ - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2)) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - - if (*(pTempsrc1+1) == *(pTempsrc2+1)) - *pTempdst = *(pTempsrc1+1); - else - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+1)) - - (mng_int32)(*(pTempsrc1+1)) ) + iM) / - (iM * 2)) + (mng_int32)(*(pTempsrc1+1)) ); - - pTempdst++; - - if (*(pTempsrc1+2) == *(pTempsrc2+2)) - *pTempdst = *(pTempsrc1+2); - else - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+2)) - - (mng_int32)(*(pTempsrc1+2)) ) + iM) / - (iM * 2)) + (mng_int32)(*(pTempsrc1+2)) ); - - pTempdst++; - - if (*(pTempsrc1+3) == *(pTempsrc2+3)) - *pTempdst = *(pTempsrc1+3); - else - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+3)) - - (mng_int32)(*(pTempsrc1+3)) ) + iM) / - (iM * 2)) + (mng_int32)(*(pTempsrc1+3)) ); - - pTempdst++; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - } - } - } - - pTempsrc1 += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba8_x3 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X3, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 4; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = (mng_int32)iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = (mng_int32)iMR; - else - iM = (mng_int32)iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* replicate first half */ - { - *pTempdst = *pTempsrc1; - *(pTempdst+1) = *(pTempsrc1+1); - *(pTempdst+2) = *(pTempsrc1+2); - *(pTempdst+3) = *(pTempsrc1+3); - - pTempdst += 4; - } - - for (iS = iH; iS < iM; iS++) /* replicate second half */ - { - *pTempdst = *pTempsrc2; - *(pTempdst+1) = *(pTempsrc2+1); - *(pTempdst+2) = *(pTempsrc2+2); - *(pTempdst+3) = *(pTempsrc2+3); - - pTempdst += 4; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - } - } - } - - pTempsrc1 += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X3, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba8_x4 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X4, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 4; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = (mng_int32)iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = (mng_int32)iMR; - else - iM = (mng_int32)iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* first half */ - { - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; /* just repeat the first */ - else /* calculate the distance */ - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2)) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - - if (*(pTempsrc1+1) == *(pTempsrc2+1)) - *pTempdst = *(pTempsrc1+1); - else - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+1)) - - (mng_int32)(*(pTempsrc1+1)) ) + iM) / - (iM * 2)) + (mng_int32)(*(pTempsrc1+1)) ); - - pTempdst++; - - if (*(pTempsrc1+2) == *(pTempsrc2+2)) - *pTempdst = *(pTempsrc1+2); - else - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+2)) - - (mng_int32)(*(pTempsrc1+2)) ) + iM) / - (iM * 2)) + (mng_int32)(*(pTempsrc1+2)) ); - - pTempdst++; - /* replicate alpha from left */ - *pTempdst = *(pTempsrc1+3); - - pTempdst++; - } - - for (iS = iH; iS < iM; iS++) /* second half */ - { - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; /* just repeat the first */ - else /* calculate the distance */ - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2)) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - - if (*(pTempsrc1+1) == *(pTempsrc2+1)) - *pTempdst = *(pTempsrc1+1); - else - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+1)) - - (mng_int32)(*(pTempsrc1+1)) ) + iM) / - (iM * 2)) + (mng_int32)(*(pTempsrc1+1)) ); - - pTempdst++; - - if (*(pTempsrc1+2) == *(pTempsrc2+2)) - *pTempdst = *(pTempsrc1+2); - else - *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+2)) - - (mng_int32)(*(pTempsrc1+2)) ) + iM) / - (iM * 2)) + (mng_int32)(*(pTempsrc1+2)) ); - - pTempdst++; - /* replicate alpha from right */ - *pTempdst = *(pTempsrc2+3); - - pTempdst++; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - } - } - } - - pTempsrc1 += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba8_x5 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X5, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline; /* initialize pixel-loop */ - pTempdst = pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 4; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = (mng_int32)iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = (mng_int32)iMR; - else - iM = (mng_int32)iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* first half */ - { - *pTempdst = *pTempsrc1; /* replicate color from left */ - *(pTempdst+1) = *(pTempsrc1+1); - *(pTempdst+2) = *(pTempsrc1+2); - - if (*(pTempsrc1+3) == *(pTempsrc2+3)) - *(pTempdst+3) = *(pTempsrc1+3); - else - *(pTempdst+3) = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+3)) - - (mng_int32)(*(pTempsrc1+3)) ) + iM) / - (iM * 2)) + (mng_int32)(*(pTempsrc1+3)) ); - - pTempdst += 4; - } - - for (iS = iH; iS < iM; iS++) /* second half */ - { - *pTempdst = *pTempsrc2; /* replicate color from right */ - *(pTempdst+1) = *(pTempsrc2+1); - *(pTempdst+2) = *(pTempsrc2+2); - - if (*(pTempsrc1+3) == *(pTempsrc2+3)) - *(pTempdst+3) = *(pTempsrc1+3); - else - *(pTempdst+3) = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+3)) - - (mng_int32)(*(pTempsrc1+3)) ) + iM) / - (iM * 2)) + (mng_int32)(*(pTempsrc1+3)) ); - - pTempdst += 4; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - } - } - } - - pTempsrc1 += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_FOOTPRINT_MAGN -#ifndef MNG_NO_GRAY_SUPPORT -mng_retcode mng_magnify_g8_y1 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_Y1, MNG_LC_START); -#endif - - MNG_COPY (pDstline, pSrcline1, iWidth); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_Y1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ -mng_retcode mng_magnify_g8_y2 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_Y2, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = pSrcline2; - pTempdst = pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, iWidth); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_Y2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_g8_y3 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_Y3, MNG_LC_START); -#endif - - if (pSrcline2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - MNG_COPY (pDstline, pSrcline1, iWidth) - else - MNG_COPY (pDstline, pSrcline2, iWidth); - } - else - { /* just repeat the entire line */ - MNG_COPY (pDstline, pSrcline1, iWidth); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_Y3, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_GRAY_SUPPORT */ - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgb8_y1 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_Y1, MNG_LC_START); -#endif - - MNG_COPY (pDstline, pSrcline1, iWidth * 3); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_Y1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgb8_y2 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_Y2, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = pSrcline2; - pTempdst = pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, iWidth * 3); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_Y2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgb8_y3 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_Y3, MNG_LC_START); -#endif - - if (pSrcline2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - MNG_COPY (pDstline, pSrcline1, iWidth * 3) - else - MNG_COPY (pDstline, pSrcline2, iWidth * 3); - } - else - { /* just repeat the entire line */ - MNG_COPY (pDstline, pSrcline1, iWidth * 3); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_Y3, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_GRAY_SUPPORT -mng_retcode mng_magnify_ga8_y1 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y1, MNG_LC_START); -#endif - - MNG_COPY (pDstline, pSrcline1, iWidth << 1); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga8_y2 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y2, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = pSrcline2; - pTempdst = pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, iWidth << 1); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga8_y3 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y3, MNG_LC_START); -#endif - - if (pSrcline2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - MNG_COPY (pDstline, pSrcline1, iWidth << 1) - else - MNG_COPY (pDstline, pSrcline2, iWidth << 1); - } - else - { /* just repeat the entire line */ - MNG_COPY (pDstline, pSrcline1, iWidth << 1); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga8_y4 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y4, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = pSrcline2; - pTempdst = pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2 += 2; - - *pTempdst++ = *pTempsrc1++; /* replicate alpha from top */ - } - } - else - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1 += 2; - pTempsrc2++; - - *pTempdst++ = *pTempsrc2++; /* replicate alpha from bottom */ - } - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, iWidth << 1); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga8_y5 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y5, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = pSrcline2; - pTempdst = pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - { - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst = *pTempsrc1; /* replicate gray from top */ - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - else - { - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst = *pTempsrc2; /* replicate gray from bottom */ - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, iWidth << 1); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y5, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_GRAY_SUPPORT */ -#endif /* MNG_OPTIMIZE_FOOTPRINT_MAGN */ - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba8_y1 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y1, MNG_LC_START); -#endif - - MNG_COPY (pDstline, pSrcline1, iWidth << 2); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba8_y2 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y2, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = pSrcline2; - pTempdst = pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, iWidth << 2); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba8_y3 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y3, MNG_LC_START); -#endif - - if (pSrcline2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - MNG_COPY (pDstline, pSrcline1, iWidth << 2) - else - MNG_COPY (pDstline, pSrcline2, iWidth << 2); - } - else - { /* just repeat the entire line */ - MNG_COPY (pDstline, pSrcline1, iWidth << 2); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba8_y4 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y4, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = pSrcline2; - pTempdst = pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2 += 2; - - *pTempdst++ = *pTempsrc1++; /* replicate alpha from top */ - } - } - else - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1 += 2; - pTempsrc2++; - - *pTempdst++ = *pTempsrc2++; /* replicate alpha from bottom */ - } - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, iWidth << 2); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba8_y5 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint8p pTempsrc1; - mng_uint8p pTempsrc2; - mng_uint8p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y5, MNG_LC_START); -#endif - - pTempsrc1 = pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = pSrcline2; - pTempdst = pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - { - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst++ = *pTempsrc1++; /* replicate color from top */ - *pTempdst++ = *pTempsrc1++; - *pTempdst++ = *pTempsrc1++; - - pTempsrc2 += 3; - - if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - else - { - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst++ = *pTempsrc2++; /* replicate color from bottom */ - *pTempdst++ = *pTempsrc2++; - *pTempdst++ = *pTempsrc2++; - - pTempsrc1 += 3; - - if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ - *pTempdst = *pTempsrc1; - else - *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - - (mng_int32)(*pTempsrc1) ) + iM) / - (iM * 2) ) + (mng_int32)(*pTempsrc1) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, iWidth << 2); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y5, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_OPTIMIZE_FOOTPRINT_MAGN -#ifndef MNG_NO_16BIT_SUPPORT -#ifndef MNG_NO_GRAY_SUPPORT -mng_retcode mng_magnify_g16_x1 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX, iS, iM; - mng_uint16p pTempsrc1; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_X1, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - - if (iX == 0) /* first interval ? */ - iM = iML; - else - if (iX == (iWidth - 1)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - - for (iS = 1; iS < iM; iS++) /* fill interval */ - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - } - - pTempsrc1++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_X1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_g16_x2 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_X2, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 1; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { /* is it same as first ? */ - if (*pTempsrc1 == *pTempsrc2) - { - for (iS = 1; iS < iM; iS++) /* then just repeat the first */ - { - *pTempdst = *pTempsrc1; - pTempdst++; - } - } - else - { - for (iS = 1; iS < iM; iS++) /* calculate the distances */ - { - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) )); - pTempdst++; - } - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - } - } - } - - pTempsrc1++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_X2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_g16_x3 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_X3, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 1; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { /* is it same as first ? */ - if (*pTempsrc1 == *pTempsrc2) - { - for (iS = 1; iS < iM; iS++) /* then just repeat the first */ - { - *pTempdst = *pTempsrc1; - pTempdst++; - } - } - else - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* replicate first half */ - { - *pTempdst = *pTempsrc1; - pTempdst++; - } - - for (iS = iH; iS < iM; iS++) /* replicate second half */ - { - *pTempdst = *pTempsrc2; - pTempdst++; - } - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - } - } - } - - pTempsrc1++; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_X3, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_GRAY_SUPPORT */ - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgb16_x1 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX, iS, iM; - mng_uint16p pTempsrc1; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_X1, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - - if (iX == 0) /* first interval ? */ - iM = iML; - else - if (iX == (iWidth - 1)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - - for (iS = 1; iS < iM; iS++) /* fill interval */ - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - } - - pTempsrc1 += 3; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_X1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgb16_x2 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_X2, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 3; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = (mng_int32)iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = (mng_int32)iMR; - else - iM = (mng_int32)iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - for (iS = 1; iS < iM; iS++) - { - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; /* just repeat the first */ - else /* calculate the distance */ - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - - if (*(pTempsrc1+1) == *(pTempsrc2+1)) - *pTempdst = *(pTempsrc1+1); - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+1))) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) ); - - pTempdst++; - - if (*(pTempsrc1+2) == *(pTempsrc2+2)) - *pTempdst = *(pTempsrc1+2); - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+2))) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) ); - - pTempdst++; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - } - } - } - - pTempsrc1 += 3; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_X2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgb16_x3 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_X3, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 3; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = (mng_int32)iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = (mng_int32)iMR; - else - iM = (mng_int32)iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* replicate first half */ - { - *pTempdst = *pTempsrc1; - *(pTempdst+1) = *(pTempsrc1+1); - *(pTempdst+2) = *(pTempsrc1+2); - - pTempdst += 3; - } - - for (iS = iH; iS < iM; iS++) /* replicate second half */ - { - *pTempdst = *pTempsrc2; - *(pTempdst+1) = *(pTempsrc2+1); - *(pTempdst+2) = *(pTempsrc2+2); - - pTempdst += 3; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - } - } - } - - pTempsrc1 += 3; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_X3, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_GRAY_SUPPORT -mng_retcode mng_magnify_ga16_x1 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX, iS, iM; - mng_uint16p pTempsrc1; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X1, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p) pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - - if (iX == 0) /* first interval ? */ - iM = iML; - else - if (iX == (iWidth - 1)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - - for (iS = 1; iS < iM; iS++) /* fill interval */ - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - } - - pTempsrc1 += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga16_x2 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X2, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 2; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - for (iS = 1; iS < iM; iS++) - { - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; /* just repeat the first */ - else /* calculate the distance */ - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - - if (*(pTempsrc1+1) == *(pTempsrc2+1)) - *pTempdst = *(pTempsrc1+1); - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+1))) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) ); - - pTempdst++; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - } - } - } - - pTempsrc1 += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga16_x3 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X3, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 2; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* replicate first half */ - { - *pTempdst = *pTempsrc1; - *(pTempdst+1) = *(pTempsrc1+1); - - pTempdst += 2; - } - - for (iS = iH; iS < iM; iS++) /* replicate second half */ - { - *pTempdst = *pTempsrc2; - *(pTempdst+1) = *(pTempsrc2+1); - - pTempdst += 2; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - } - } - } - - pTempsrc1 += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X3, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga16_x4 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X4, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 2; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* first half */ - { - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; /* just repeat the first */ - else /* calculate the distance */ - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - - *pTempdst = *(pTempsrc1+1); /* replicate alpha from left */ - - pTempdst++; - } - - for (iS = iH; iS < iM; iS++) /* second half */ - { - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; /* just repeat the first */ - else /* calculate the distance */ - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - - *pTempdst = *(pTempsrc2+1); /* replicate alpha from right */ - - pTempdst++; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - } - } - } - - pTempsrc1 += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga16_x5 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X5, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 2; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* first half */ - { - *pTempdst = *pTempsrc1; /* replicate gray from left */ - - pTempdst++; - - if (*(pTempsrc1+1) == *(pTempsrc2+1)) - *pTempdst = *(pTempsrc1+1);/* just repeat the first */ - else /* calculate the distance */ - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+1))) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) ); - - pTempdst++; - } - - for (iS = iH; iS < iM; iS++) /* second half */ - { - *pTempdst = *pTempsrc2; /* replicate gray from right */ - - pTempdst++; - - if (*(pTempsrc1+1) == *(pTempsrc2+1)) - *pTempdst = *(pTempsrc1+1);/* just repeat the first */ - else /* calculate the distance */ - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+1))) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) ); - - pTempdst++; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - } - } - } - - pTempsrc1 += 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X5, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_GRAY_SUPPORT */ - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba16_x1 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX, iS, iM; - mng_uint16p pTempsrc1; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X1, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - - if (iX == 0) /* first interval ? */ - iM = iML; - else - if (iX == (iWidth - 1)) /* last interval ? */ - iM = iMR; - else - iM = iMX; - - for (iS = 1; iS < iM; iS++) /* fill interval */ - { - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - } - - pTempsrc1 += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba16_x2 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X2, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 4; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = (mng_int32)iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = (mng_int32)iMR; - else - iM = (mng_int32)iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - for (iS = 1; iS < iM; iS++) - { - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; /* just repeat the first */ - else /* calculate the distance */ - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - - if (*(pTempsrc1+1) == *(pTempsrc2+1)) - *pTempdst = *(pTempsrc1+1); - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+1))) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) ); - - pTempdst++; - - if (*(pTempsrc1+2) == *(pTempsrc2+2)) - *pTempdst = *(pTempsrc1+2); - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+2))) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) ); - - pTempdst++; - - if (*(pTempsrc1+3) == *(pTempsrc2+3)) - *pTempdst = *(pTempsrc1+3); - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+3))) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+3))) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+3))) ) ); - - pTempdst++; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - } - } - } - - pTempsrc1 += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba16_x3 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X3, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 4; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = (mng_int32)iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = (mng_int32)iMR; - else - iM = (mng_int32)iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* replicate first half */ - { - *pTempdst = *pTempsrc1; - *(pTempdst+1) = *(pTempsrc1+1); - *(pTempdst+2) = *(pTempsrc1+2); - *(pTempdst+3) = *(pTempsrc1+3); - - pTempdst += 4; - } - - for (iS = iH; iS < iM; iS++) /* replicate second half */ - { - *pTempdst = *pTempsrc2; - *(pTempdst+1) = *(pTempsrc2+1); - *(pTempdst+2) = *(pTempsrc2+2); - *(pTempdst+3) = *(pTempsrc2+3); - - pTempdst += 4; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - } - } - } - - pTempsrc1 += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X3, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba16_x4 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X4, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 4; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = (mng_int32)iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = (mng_int32)iMR; - else - iM = (mng_int32)iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* first half */ - { - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; /* just repeat the first */ - else /* calculate the distance */ - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - - if (*(pTempsrc1+1) == *(pTempsrc2+1)) - *pTempdst = *(pTempsrc1+1); - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+1))) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) ); - - pTempdst++; - - if (*(pTempsrc1+2) == *(pTempsrc2+2)) - *pTempdst = *(pTempsrc1+2); - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+2))) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) ); - - pTempdst++; - /* replicate alpha from left */ - *pTempdst = *(pTempsrc1+3); - - pTempdst++; - } - - for (iS = iH; iS < iM; iS++) /* second half */ - { - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; /* just repeat the first */ - else /* calculate the distance */ - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - - if (*(pTempsrc1+1) == *(pTempsrc2+1)) - *pTempdst = *(pTempsrc1+1); - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+1))) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) ); - - pTempdst++; - - if (*(pTempsrc1+2) == *(pTempsrc2+2)) - *pTempdst = *(pTempsrc1+2); - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+2))) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) ); - - pTempdst++; - /* replicate alpha from right */ - *pTempdst = *(pTempsrc2+3); - - pTempdst++; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - } - } - } - - pTempsrc1 += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba16_x5 (mng_datap pData, - mng_uint16 iMX, - mng_uint16 iML, - mng_uint16 iMR, - mng_uint32 iWidth, - mng_uint8p pSrcline, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_int32 iS, iM, iH; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X5, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ - pTempdst = (mng_uint16p)pDstline; - - for (iX = 0; iX < iWidth; iX++) - { - pTempsrc2 = pTempsrc1 + 4; - - *pTempdst = *pTempsrc1; /* copy original source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - - if (iX == 0) /* first interval ? */ - { - if (iWidth == 1) /* single pixel ? */ - pTempsrc2 = MNG_NULL; - - iM = (mng_int32)iML; - } - else - if (iX == (iWidth - 2)) /* last interval ? */ - iM = (mng_int32)iMR; - else - iM = (mng_int32)iMX; - /* fill interval ? */ - if ((iX < iWidth - 1) || (iWidth == 1)) - { - if (pTempsrc2) /* do we have the second pixel ? */ - { - iH = (iM+1) / 2; /* calculate halfway point */ - - for (iS = 1; iS < iH; iS++) /* first half */ - { - *pTempdst = *pTempsrc1; /* replicate color from left */ - *(pTempdst+1) = *(pTempsrc1+1); - *(pTempdst+2) = *(pTempsrc1+2); - - if (*(pTempsrc1+3) == *(pTempsrc2+3)) - *(pTempdst+3) = *(pTempsrc1+3); - else - mng_put_uint16 ((mng_uint8p)(pTempdst+3), - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+3))) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+3))) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+3))) ) ); - - pTempdst += 4; - } - - for (iS = iH; iS < iM; iS++) /* second half */ - { - *pTempdst = *pTempsrc2; /* replicate color from right */ - *(pTempdst+1) = *(pTempsrc2+1); - *(pTempdst+2) = *(pTempsrc2+2); - - if (*(pTempsrc1+3) == *(pTempsrc2+3)) - *(pTempdst+3) = *(pTempsrc1+3); - else - mng_put_uint16 ((mng_uint8p)(pTempdst+3), - (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+3))) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+3))) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+3))) ) ); - - pTempdst += 4; - } - } - else - { - for (iS = 1; iS < iM; iS++) - { - *pTempdst = *pTempsrc1; /* repeat first source pixel */ - pTempdst++; - *pTempdst = *(pTempsrc1+1); - pTempdst++; - *pTempdst = *(pTempsrc1+2); - pTempdst++; - *pTempdst = *(pTempsrc1+3); - pTempdst++; - } - } - } - - pTempsrc1 += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_GRAY_SUPPORT -mng_retcode mng_magnify_g16_y1 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_Y1, MNG_LC_START); -#endif - - MNG_COPY (pDstline, pSrcline1, (iWidth << 1)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_Y1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_g16_y2 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_Y2, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = (mng_uint16p)pSrcline2; - pTempdst = (mng_uint16p)pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, (iWidth << 1)); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_Y2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_g16_y3 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_Y3, MNG_LC_START); -#endif - - if (pSrcline2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - MNG_COPY (pDstline, pSrcline1, (iWidth << 1)) - else - MNG_COPY (pDstline, pSrcline2, (iWidth << 1)); - } - else - { /* just repeat the entire line */ - MNG_COPY (pDstline, pSrcline1, (iWidth << 1)); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_Y3, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_GRAY_SUPPORT */ - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgb16_y1 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_Y1, MNG_LC_START); -#endif - - MNG_COPY (pDstline, pSrcline1, iWidth * 6); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_Y1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgb16_y2 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_Y2, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = (mng_uint16p)pSrcline2; - pTempdst = (mng_uint16p)pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, iWidth * 6); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_Y2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgb16_y3 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_Y3, MNG_LC_START); -#endif - - if (pSrcline2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - MNG_COPY (pDstline, pSrcline1, iWidth * 6) - else - MNG_COPY (pDstline, pSrcline2, iWidth * 6); - } - else - { /* just repeat the entire line */ - MNG_COPY (pDstline, pSrcline1, iWidth * 6); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_Y3, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_GRAY_SUPPORT -mng_retcode mng_magnify_ga16_y1 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y1, MNG_LC_START); -#endif - - MNG_COPY (pDstline, pSrcline1, (iWidth << 2)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga16_y2 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y2, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = (mng_uint16p)pSrcline2; - pTempdst = (mng_uint16p)pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, (iWidth << 2)); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga16_y3 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y3, MNG_LC_START); -#endif - - if (pSrcline2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - MNG_COPY (pDstline, pSrcline1, (iWidth << 2)) - else - MNG_COPY (pDstline, pSrcline2, (iWidth << 2)); - } - else - { /* just repeat the entire line */ - MNG_COPY (pDstline, pSrcline1, (iWidth << 2)); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga16_y4 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y4, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = (mng_uint16p)pSrcline2; - pTempdst = (mng_uint16p)pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2 += 2; - - *pTempdst++ = *pTempsrc1++; /* replicate alpha from top */ - } - } - else - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1 += 2; - pTempsrc2++; - - *pTempdst++ = *pTempsrc2++; /* replicate alpha from bottom */ - } - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, (iWidth << 2)); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_ga16_y5 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y5, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = (mng_uint16p)pSrcline2; - pTempdst = (mng_uint16p)pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - { - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst = *pTempsrc1; /* replicate gray from top */ - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - else - { - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst = *pTempsrc2; /* replicate gray from bottom */ - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, (iWidth << 2)); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y5, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_GRAY_SUPPORT */ - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba16_y1 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y1, MNG_LC_START); -#endif - - MNG_COPY (pDstline, pSrcline1, (iWidth << 3)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y1, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba16_y2 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y2, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = (mng_uint16p)pSrcline2; - pTempdst = (mng_uint16p)pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, (iWidth << 3)); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba16_y3 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y3, MNG_LC_START); -#endif - - if (pSrcline2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - MNG_COPY (pDstline, pSrcline1, (iWidth << 3)) - else - MNG_COPY (pDstline, pSrcline2, (iWidth << 3)); - } - else - { /* just repeat the entire line */ - MNG_COPY (pDstline, pSrcline1, (iWidth << 3)); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba16_y4 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y4, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = (mng_uint16p)pSrcline2; - pTempdst = (mng_uint16p)pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2 += 2; - - *pTempdst++ = *pTempsrc1++; /* replicate alpha from top */ - } - } - else - { - for (iX = 0; iX < iWidth; iX++) - { /* calculate the distances */ - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - - if (*pTempsrc1 == *pTempsrc2) - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1 += 2; - pTempsrc2++; - - *pTempdst++ = *pTempsrc2++; /* replicate alpha from bottom */ - } - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, (iWidth << 3)); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y4, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_magnify_rgba16_y5 (mng_datap pData, - mng_int32 iS, - mng_int32 iM, - mng_uint32 iWidth, - mng_uint8p pSrcline1, - mng_uint8p pSrcline2, - mng_uint8p pDstline) -{ - mng_uint32 iX; - mng_uint16p pTempsrc1; - mng_uint16p pTempsrc2; - mng_uint16p pTempdst; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y5, MNG_LC_START); -#endif - - pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ - pTempsrc2 = (mng_uint16p)pSrcline2; - pTempdst = (mng_uint16p)pDstline; - - if (pTempsrc2) /* do we have a second line ? */ - { - if (iS < (iM+1) / 2) /* top half ? */ - { - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst++ = *pTempsrc1++; /* replicate color from top */ - *pTempdst++ = *pTempsrc1++; - *pTempdst++ = *pTempsrc1++; - - pTempsrc2 += 3; - - if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - else - { - for (iX = 0; iX < iWidth; iX++) - { - *pTempdst++ = *pTempsrc2++; /* replicate color from bottom */ - *pTempdst++ = *pTempsrc2++; - *pTempdst++ = *pTempsrc2++; - - pTempsrc1 += 3; - - if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ - *pTempdst = *pTempsrc1; - else - mng_put_uint16 ((mng_uint8p)pTempdst, - (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - - (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / - (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); - - pTempdst++; - pTempsrc1++; - pTempsrc2++; - } - } - } - else - { /* just repeat the entire line */ - MNG_COPY (pTempdst, pTempsrc1, (iWidth << 3)); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y5, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_NO_16BIT_SUPPORT */ -#endif /* MNG_OPTIMIZE_FOOTPRINT_MAGN */ -#endif /* MNG_SKIPCHUNK_MAGN */ - -/* ************************************************************************** */ -/* * * */ -/* * PAST composition routines - compose over/under with a target object * */ -/* * * */ -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -mng_retcode mng_composeover_rgba8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8; - mng_uint8 iCr8, iCg8, iCb8, iCa8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_COMPOSEOVER_RGBA8, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iFGa8 = *(pWorkrow+3); /* get alpha values */ - iBGa8 = *(pOutrow+3); - - if (iFGa8) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa8 == 0xFF) || (iBGa8 == 0)) - { /* then simply copy the values */ - *pOutrow = *pWorkrow; - *(pOutrow+1) = *(pWorkrow+1); - *(pOutrow+2) = *(pWorkrow+2); - *(pOutrow+3) = iFGa8; - } - else - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ -#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pOutrow+i), *(pWorkrow+i), iFGa8, *(pOutrow+i)); - } -#else - MNG_COMPOSE8 (*pOutrow, *pWorkrow, iFGa8, *pOutrow ); - MNG_COMPOSE8 (*(pOutrow+1), *(pWorkrow+1), iFGa8, *(pOutrow+1)); - MNG_COMPOSE8 (*(pOutrow+2), *(pWorkrow+2), iFGa8, *(pOutrow+2)); -#endif - /* alpha remains fully opaque !!! */ - } - else - { /* here we'll have to blend */ - MNG_BLEND8 (*pWorkrow, *(pWorkrow+1), *(pWorkrow+2), iFGa8, - *pOutrow, *(pOutrow+1), *(pOutrow+2), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pOutrow = iCr8; - *(pOutrow+1) = iCg8; - *(pOutrow+2) = iCb8; - *(pOutrow+3) = iCa8; - } - } - } - - pOutrow += 4; - pWorkrow += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_COMPOSEOVER_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_composeover_rgba16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint16p pWorkrow; - mng_uint16p pOutrow; - mng_int32 iX; - mng_uint16 iFGa16, iFGr16, iFGg16, iFGb16; - mng_uint16 iBGa16, iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16, iCa16; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_COMPOSEOVER_RGBA16, MNG_LC_START); -#endif - - pWorkrow = (mng_uint16p)pData->pRGBArow; - pOutrow = (mng_uint16p)(pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize)); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* get alpha values */ - iFGa16 = mng_get_uint16 ((mng_uint8p)(pWorkrow+3)); - iBGa16 = mng_get_uint16 ((mng_uint8p)(pOutrow+3)); - - if (iFGa16) /* any opacity at all ? */ - { /* fully opaque or background fully transparent ? */ - if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) - { /* then simply copy the values */ - *pOutrow = *pWorkrow; - *(pOutrow+1) = *(pWorkrow+1); - *(pOutrow+2) = *(pWorkrow+2); - *(pOutrow+3) = *(pWorkrow+3); - } - else - { /* get color values */ - iFGr16 = mng_get_uint16 ((mng_uint8p)pWorkrow); - iFGg16 = mng_get_uint16 ((mng_uint8p)(pWorkrow+1)); - iFGb16 = mng_get_uint16 ((mng_uint8p)(pWorkrow+2)); - iBGr16 = mng_get_uint16 ((mng_uint8p)pOutrow); - iBGg16 = mng_get_uint16 ((mng_uint8p)(pOutrow+1)); - iBGb16 = mng_get_uint16 ((mng_uint8p)(pOutrow+2)); - - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* do alpha composing */ - MNG_COMPOSE16 (iFGr16, iFGr16, iFGa16, iBGr16); - MNG_COMPOSE16 (iFGg16, iFGg16, iFGa16, iBGg16); - MNG_COMPOSE16 (iFGb16, iFGb16, iFGa16, iBGb16); - - mng_put_uint16 ((mng_uint8p)pOutrow, iFGr16); - mng_put_uint16 ((mng_uint8p)(pOutrow+1), iFGg16); - mng_put_uint16 ((mng_uint8p)(pOutrow+2), iFGb16); - /* alpha remains fully opaque !!! */ - } - else - { /* here we'll have to blend */ - MNG_BLEND16 (iFGr16, iFGg16, iFGb16, iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - mng_put_uint16 ((mng_uint8p)pOutrow, iCr16); - mng_put_uint16 ((mng_uint8p)(pOutrow+1), iCg16); - mng_put_uint16 ((mng_uint8p)(pOutrow+2), iCb16); - mng_put_uint16 ((mng_uint8p)(pOutrow+3), iCa16); - } - } - } - - pOutrow += 4; - pWorkrow += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_COMPOSEOVER_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_composeunder_rgba8 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint8p pWorkrow; - mng_uint8p pOutrow; - mng_int32 iX; - mng_uint8 iFGa8, iBGa8; - mng_uint8 iCr8, iCg8, iCb8, iCa8; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_COMPOSEUNDER_RGBA8, MNG_LC_START); -#endif - - pWorkrow = pData->pRGBArow; - pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { - iFGa8 = *(pOutrow+3); /* get alpha values */ - iBGa8 = *(pWorkrow+3); - /* anything to do at all ? */ - if ((iBGa8) && (iFGa8 != 0xFF)) - { - if (iBGa8 == 0xFF) /* background fully opaque ? */ - { /* do alpha composing */ -#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE - int i; - for (i=2; i >= 0; i--) - { - MNG_COMPOSE8 (*(pOutrow+i), *(pOutrow+i), iFGa8, *(pWorkrow+i)); - } -#else - MNG_COMPOSE8 (*pOutrow, *pOutrow, iFGa8, *pWorkrow ); - MNG_COMPOSE8 (*(pOutrow+1), *(pOutrow+1), iFGa8, *(pWorkrow+1)); - MNG_COMPOSE8 (*(pOutrow+2), *(pOutrow+2), iFGa8, *(pWorkrow+2)); -#endif - *(pOutrow+3) = 0xFF; /* alpha becomes fully opaque !!! */ - } - else - { /* here we'll have to blend */ - MNG_BLEND8 (*pOutrow, *(pOutrow+1), *(pOutrow+2), iFGa8, - *pWorkrow, *(pWorkrow+1), *(pWorkrow+2), iBGa8, - iCr8, iCg8, iCb8, iCa8); - /* and return the composed values */ - *pOutrow = iCr8; - *(pOutrow+1) = iCg8; - *(pOutrow+2) = iCb8; - *(pOutrow+3) = iCa8; - } - } - - pOutrow += 4; - pWorkrow += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_COMPOSEUNDER_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_composeunder_rgba16 (mng_datap pData) -{ - mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; - mng_uint16p pWorkrow; - mng_uint16p pOutrow; - mng_int32 iX; - mng_uint16 iFGa16, iFGr16, iFGg16, iFGb16; - mng_uint16 iBGa16, iBGr16, iBGg16, iBGb16; - mng_uint16 iCr16, iCg16, iCb16, iCa16; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_COMPOSEUNDER_RGBA16, MNG_LC_START); -#endif - - pWorkrow = (mng_uint16p)pData->pRGBArow; - pOutrow = (mng_uint16p)(pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + - (pData->iCol * pBuf->iSamplesize)); - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* get alpha values */ - iFGa16 = mng_get_uint16 ((mng_uint8p)(pOutrow+3)); - iBGa16 = mng_get_uint16 ((mng_uint8p)(pWorkrow+3)); - /* anything to do at all ? */ - if ((iBGa16) && (iFGa16 != 0xFFFF)) - { - iFGr16 = mng_get_uint16 ((mng_uint8p)pOutrow); - iFGg16 = mng_get_uint16 ((mng_uint8p)(pOutrow+1)); - iFGb16 = mng_get_uint16 ((mng_uint8p)(pOutrow+2)); - iBGr16 = mng_get_uint16 ((mng_uint8p)pWorkrow); - iBGg16 = mng_get_uint16 ((mng_uint8p)(pWorkrow+1)); - iBGb16 = mng_get_uint16 ((mng_uint8p)(pWorkrow+2)); - - if (iBGa16 == 0xFFFF) /* background fully opaque ? */ - { /* do alpha composing */ - MNG_COMPOSE16 (iFGr16, iFGr16, iFGa16, iBGr16); - MNG_COMPOSE16 (iFGg16, iFGg16, iFGa16, iBGg16); - MNG_COMPOSE16 (iFGb16, iFGb16, iFGa16, iBGb16); - - mng_put_uint16 ((mng_uint8p)pOutrow, iFGr16); - mng_put_uint16 ((mng_uint8p)(pOutrow+1), iFGg16); - mng_put_uint16 ((mng_uint8p)(pOutrow+2), iFGb16); - *(pOutrow+3) = 0xFFFF; /* alpha becomes fully opaque !!! */ - } - else - { /* here we'll have to blend */ - MNG_BLEND16 (iFGr16, iFGg16, iFGb16, iFGa16, - iBGr16, iBGg16, iBGb16, iBGa16, - iCr16, iCg16, iCb16, iCa16); - /* and return the composed values */ - mng_put_uint16 ((mng_uint8p)pOutrow, iCr16); - mng_put_uint16 ((mng_uint8p)(pOutrow+1), iCg16); - mng_put_uint16 ((mng_uint8p)(pOutrow+2), iCb16); - mng_put_uint16 ((mng_uint8p)(pOutrow+3), iCa16); - } - } - - pOutrow += 4; - pWorkrow += 4; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_COMPOSEUNDER_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif - -/* ************************************************************************** */ -/* * * */ -/* * PAST flip & tile routines - flip or tile a row of pixels * */ -/* * * */ -/* ************************************************************************** */ - -#ifndef MNG_SKIPCHUNK_PAST -mng_retcode mng_flip_rgba8 (mng_datap pData) -{ - mng_uint32p pWorkrow; - mng_uint32p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FLIP_RGBA8, MNG_LC_START); -#endif - /* setup temp pointers */ - pWorkrow = (mng_uint32p)pData->pRGBArow + pData->iRowsamples - 1; - pOutrow = (mng_uint32p)pData->pWorkrow; - /* swap original buffers */ - pData->pWorkrow = pData->pRGBArow; - pData->pRGBArow = (mng_uint8p)pOutrow; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* let's flip */ - *pOutrow = *pWorkrow; - pOutrow++; - pWorkrow--; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FLIP_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_flip_rgba16 (mng_datap pData) -{ - mng_uint32p pWorkrow; - mng_uint32p pOutrow; - mng_int32 iX; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FLIP_RGBA16, MNG_LC_START); -#endif - /* setup temp pointers */ - pWorkrow = (mng_uint32p)pData->pRGBArow + ((pData->iRowsamples - 1) << 1); - pOutrow = (mng_uint32p)pData->pWorkrow; - /* swap original buffers */ - pData->pWorkrow = pData->pRGBArow; - pData->pRGBArow = (mng_uint8p)pOutrow; - -#ifdef MNG_DECREMENT_LOOPS - for (iX = pData->iRowsamples; iX > 0; iX--) -#else - for (iX = 0; iX < pData->iRowsamples; iX++) -#endif - { /* let's flip */ - *pOutrow = *pWorkrow; - *(pOutrow + 1) = *(pWorkrow + 1); - - pOutrow += 2; - pWorkrow -= 2; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_FLIP_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode mng_tile_rgba8 (mng_datap pData) -{ - mng_uint32p pWorkrow; - mng_uint32p pOutrow; - mng_int32 iX; - mng_uint32 iZ, iMax; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_TILE_RGBA8, MNG_LC_START); -#endif - - iZ = pData->iSourcel; /* indent ? */ - /* what's our source-length */ - iMax = ((mng_imagep)pData->pRetrieveobj)->pImgbuf->iWidth; - /* setup temp pointers */ - pWorkrow = (mng_uint32p)pData->pRGBArow + iZ; - pOutrow = (mng_uint32p)pData->pWorkrow; - /* swap original buffers */ - pData->pWorkrow = pData->pRGBArow; - pData->pRGBArow = (mng_uint8p)pOutrow; - - for (iX = pData->iDestl; iX < pData->iDestr; iX++) - { /* tiiiile */ - *pOutrow = *pWorkrow; - - pWorkrow++; - pOutrow++; - iZ++; - - if (iZ >= iMax) /* end of source ? */ - { - iZ = 0; - pWorkrow = (mng_uint32p)pData->pWorkrow; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_TILE_RGBA8, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_16BIT_SUPPORT -mng_retcode mng_tile_rgba16 (mng_datap pData) -{ - mng_uint32p pWorkrow; - mng_uint32p pOutrow; - mng_int32 iX; - mng_uint32 iZ, iMax; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_TILE_RGBA16, MNG_LC_START); -#endif - - iZ = pData->iSourcel; /* indent ? */ - /* what's our source-length */ - iMax = ((mng_imagep)pData->pRetrieveobj)->pImgbuf->iWidth; - /* setup temp pointers */ - pWorkrow = (mng_uint32p)pData->pRGBArow + (iZ << 1); - pOutrow = (mng_uint32p)pData->pWorkrow; - /* swap original buffers */ - pData->pWorkrow = pData->pRGBArow; - pData->pRGBArow = (mng_uint8p)pOutrow; - - for (iX = pData->iDestl; iX < pData->iDestr; iX++) - { /* tiiiile */ - *pOutrow = *pWorkrow; - *(pOutrow + 1) = *(pWorkrow + 1); - - pWorkrow += 2; - pOutrow += 2; - iZ++; - - if (iZ >= iMax) /* end of source ? */ - { - iZ = 0; - pWorkrow = (mng_uint32p)pData->pWorkrow; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_TILE_RGBA16, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SKIPCHUNK_PAST */ - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_DISPLAY_PROCS */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_pixels.c copyright (c) 2000-2005 G.Juyn * */ +/* * version : 1.0.10 * */ +/* * * */ +/* * purpose : Pixel-row management routines (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the pixel-row management routines * */ +/* * * */ +/* * the dual alpha-composing for RGBA/BGRA/etc output-canvas' * */ +/* * is based on the Note on Compositing chapter of the * */ +/* * DOH-3 draft, noted to me by Adam M. Costello * */ +/* * * */ +/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/11/2000 - G.Juyn * */ +/* * - added callback error-reporting support * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - changed trace to macro for callback error-reporting * */ +/* * * */ +/* * 0.5.2 - 05/22/2000 - G.Juyn * */ +/* * - added JNG support * */ +/* * 0.5.2 - 05/30/2000 - G.Juyn * */ +/* * - fixed minor bugs 16-bit pixel-handling * */ +/* * - added delta-image row-processing routines * */ +/* * 0.5.2 - 06/02/2000 - G.Juyn * */ +/* * - fixed endian support (hopefully) * */ +/* * 0.5.2 - 06/03/2000 - G.Juyn * */ +/* * - fixed makeup for Linux gcc compile * */ +/* * 0.5.2 - 06/05/2000 - G.Juyn * */ +/* * - implemented app bkgd restore routines * */ +/* * - implemented RGBA8, ARGB8, BGRA8 & ABGR8 display routines * */ +/* * - added support for RGB8_A8 canvasstyle * */ +/* * 0.5.2 - 06/09/2000 - G.Juyn * */ +/* * - fixed alpha-handling for alpha canvasstyles * */ +/* * * */ +/* * 0.5.3 - 06/16/2000 - G.Juyn * */ +/* * - changed progressive-display processing * */ +/* * 0.5.3 - 06/17/2000 - G.Juyn * */ +/* * - changed to support delta-images * */ +/* * - optimized some store_xxx routines * */ +/* * 0.5.3 - 06/20/2000 - G.Juyn * */ +/* * - fixed nasty bug with embedded PNG after delta-image * */ +/* * 0.5.3 - 06/24/2000 - G.Juyn * */ +/* * - fixed problem with 16-bit GA format * */ +/* * 0.5.3 - 06/25/2000 - G.Juyn * */ +/* * - fixed problem with cheap transparency for 4-bit gray * */ +/* * - fixed display_xxxx routines for interlaced images * */ +/* * 0.5.3 - 06/28/2000 - G.Juyn * */ +/* * - fixed compiler-warning for non-initialized iB variable * */ +/* * * */ +/* * 0.9.1 - 07/05/2000 - G.Juyn * */ +/* * - fixed mandatory BACK color to be opaque * */ +/* * * */ +/* * 0.9.2 - 07/31/2000 - G.Juyn * */ +/* * - B110547 - fixed bug in interlace code * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 0.9.3 - 08/20/2000 - G.Juyn * */ +/* * - fixed app-supplied background restore * */ +/* * 0.9.3 - 08/26/2000 - G.Juyn * */ +/* * - added MAGN chunk * */ +/* * 0.9.3 - 09/07/2000 - G.Juyn * */ +/* * - added support for new filter_types * */ +/* * 0.9.3 - 09/30/2000 - G.Juyn * */ +/* * - fixed MAGN rounding errors (thanks Matthias!) * */ +/* * 0.9.3 - 10/10/2000 - G.Juyn * */ +/* * - fixed alpha-blending for RGBA canvasstyle * */ +/* * 0.9.3 - 10/11/2000 - G.Juyn * */ +/* * - fixed alpha-blending for other alpha-canvasstyles * */ +/* * 0.9.3 - 10/16/2000 - G.Juyn * */ +/* * - added optional support for bKGD for PNG images * */ +/* * - added support for JDAA * */ +/* * 0.9.3 - 10/17/2000 - G.Juyn * */ +/* * - fixed support for bKGD * */ +/* * 0.9.3 - 10/19/2000 - G.Juyn * */ +/* * - implemented delayed delta-processing * */ +/* * 0.9.3 - 10/28/2000 - G.Juyn * */ +/* * - fixed tRNS processing for gray-image < 8-bits * */ +/* * * */ +/* * 0.9.4 - 12/16/2000 - G.Juyn * */ +/* * - fixed mixup of data- & function-pointers (thanks Dimitri)* */ +/* * 0.9.4 - 1/18/2001 - G.Juyn * */ +/* * - removed "old" MAGN methods 3 & 4 * */ +/* * - added "new" MAGN methods 3, 4 & 5 * */ +/* * - removed test filter-methods 1 & 65 * */ +/* * * */ +/* * 1.0.1 - 04/21/2001 - G.Juyn (code by G.Kelly) * */ +/* * - added BGRA8 canvas with premultiplied alpha * */ +/* * 1.0.1 - 04/25/2001 - G.Juyn * */ +/* * - moved mng_clear_cms to libmng_cms * */ +/* * * */ +/* * 1.0.2 - 06/25/2001 - G.Juyn * */ +/* * - added option to turn off progressive refresh * */ +/* * * */ +/* * 1.0.4 - 11/04/2001 - G.Juyn * */ +/* * - fixed possible compile-problem in cleanup_rowproc * */ +/* * 1.0.4 - 06/22/2002 - G.Juyn * */ +/* * - B558212 - off by one error * */ +/* * - MNG subimage alpha composite wrong for rgba8 images * */ +/* * * */ +/* * 1.0.5 - 08/07/2002 - G.Juyn * */ +/* * - added test-option for PNG filter method 193 (=no filter) * */ +/* * 1.0.5 - 08/15/2002 - G.Juyn * */ +/* * - completed PROM support * */ +/* * - completed delta-image support * */ +/* * 1.0.5 - 08/16/2002 - G.Juyn * */ +/* * - completed MAGN support (16-bit functions) * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * 1.0.5 - 09/19/2002 - G.Juyn * */ +/* * - optimized restore-background for bKGD cases * */ +/* * 1.0.5 - 09/20/2002 - G.Juyn * */ +/* * - finished support for BACK image & tiling * */ +/* * 1.0.5 - 09/22/2002 - G.Juyn * */ +/* * - added bgrx8 canvas (filler byte) * */ +/* * 1.0.5 - 09/23/2002 - G.Juyn * */ +/* * - added compose over/under routines for PAST processing * */ +/* * - added flip & tile routines for PAST processing * */ +/* * * */ +/* * 1.0.6 - 03/09/2003 - G.Juyn * */ +/* * - hiding 12-bit JPEG stuff * */ +/* * 1.0.6 - 05/11/2003 - Glenn RP * */ +/* * - added size-optimization COMPOSE routine usage * */ +/* * 1.0.6 - 05/11/2003 - G. Juyn * */ +/* * - added conditionals around canvas update routines * */ +/* * 1.0.6 - 05/25/2003 - Glenn RP * */ +/* * - added size-optimization DIV255B8 routine usage * */ +/* * 1.0.6 - 06/09/2003 - G. R-P * */ +/* * - added conditionals around 8-bit magn routines * */ +/* * 1.0.6 - 07/07/2003 - G. R-P * */ +/* * - removed conditionals around 8-bit magn routines * */ +/* * - added MNG_NO_16BIT_SUPPORT and MNG_NO_DELTA_PNG * */ +/* * conditionals * */ +/* * - reversed many loops to use decrementing counter * */ +/* * - combined init functions * */ +/* * - converted some switches to array references * */ +/* * 1.0.6 - 07/29/2003 - G.Juyn * */ +/* * - fixed duplicate for-loop * */ +/* * 1.0.6 - 07/29/2003 - G.R-P * */ +/* * - added SKIPCHUNK conditionals around PAST chunk support * */ +/* * - fixed "FOOTPRINT_COMPOSEIV" typo (now "FOOTPRINT_DIV") * */ +/* * 1.0.6 - 08/17/2003 - G.R-P * */ +/* * - added more conditionals around "promote" functions * */ +/* * * */ +/* * 1.0.7 - 11/27/2003 - R.A * */ +/* * - added CANVAS_RGB565 and CANVAS_BGR565 * */ +/* * 1.0.7 - 12/06/2003 - R.A * */ +/* * - added CANVAS_RGBA565 and CANVAS_BGRA565 * */ +/* * 1.0.7 - 01/25/2004 - J.S * */ +/* * - added premultiplied alpha canvas' for RGBA, ARGB, ABGR * */ +/* * 1.0.7 - 03/08/2004 - G.R-P * */ +/* * - added more conditionals around 16-bit-supporting code * */ +/* * 1.0.7 - 03/09/2004 - G.Juyn * */ +/* * - fixed bug in promote_g8_g8 with 16bit support off * */ +/* * 1.0.7 - 03/09/2004 - G.R-P * */ +/* * - more optimizations with 16bit support off * */ +/* * 1.0.7 - 03/10/2004 - G.Juyn * */ +/* * - fixed some warnings for 16bit optimizations * */ +/* * 1.0.7 - 03/21/2004 - G.Juyn * */ +/* * - fixed some 64-bit platform compiler warnings * */ +/* * * */ +/* * 1.0.8 - 06/20/2004 - G.Juyn * */ +/* * - some speed optimizations (thanks to John Stiles) * */ +/* * 1.0.8 - 08/01/2004 - G.Juyn * */ +/* * - added support for 3+byte pixelsize for JPEG's * */ +/* * * */ +/* * 1.0.9 - 10/10/2004 - G.R-P. * */ +/* * - added MNG_NO_1_2_4BIT_SUPPORT * */ +/* * 1.0.9 - 10/14/2004 - G.Juyn * */ +/* * - added bgr565_a8 canvas-style (thanks to J. Elvander) * */ +/* * 1.0.9 - 12/05/2004 - G.Juyn * */ +/* * - added LITTLEENDIAN/BIGENDIAN fixtures (thanks J.Stiles) * */ +/* * - fixed MNG_NO_1_2_4BIT_SUPPORT for TBBN1G04.PNG * */ +/* * 1.0.9 - 12/31/2004 - G.R-P. * */ +/* * - fixed warnings about C++ style (//) comments * */ +/* * * */ +/* * 1.0.10 - 07/06/2005 - G.R-P. * */ +/* * - added MORE MNG_NO_1_2_4BIT_SUPPORT * */ +/* * 1.0.10 - 10/06/2005 - G.R-P. * */ +/* * - alloc more memory for MNG_NO_1_2_4BIT_SUPPORT * */ +/* * 1.0.10 - 12/07/2005 - G.R-P. * */ +/* * - optimized footprint of 16bit support * */ +/* * 1.0.10 - 03/07/2006 - (thanks to W. Manthey) * */ +/* * - added CANVAS_RGB555 and CANVAS_BGR555 * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_objects.h" +#include "libmng_object_prc.h" +#include "libmng_memory.h" +#include "libmng_cms.h" +#include "libmng_filter.h" +#include "libmng_pixels.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_DISPLAY_PROCS + +/* TODO: magnification & canvas-positioning/-clipping */ + +/* TODO: major optimization of pixel-loops by using assembler (?) */ + +/* ************************************************************************** */ +/* * * */ +/* * Interlace tables * */ +/* * * */ +/* ************************************************************************** */ + +MNG_LOCAL mng_uint32 const interlace_row [7] = { 0, 0, 4, 0, 2, 0, 1 }; +MNG_LOCAL mng_uint32 const interlace_rowskip [7] = { 8, 8, 8, 4, 4, 2, 2 }; +MNG_LOCAL mng_uint32 const interlace_col [7] = { 0, 4, 0, 2, 0, 1, 0 }; +MNG_LOCAL mng_uint32 const interlace_colskip [7] = { 8, 8, 4, 4, 2, 2, 1 }; +MNG_LOCAL mng_uint32 const interlace_roundoff [7] = { 7, 7, 3, 3, 1, 1, 0 }; +MNG_LOCAL mng_uint32 const interlace_divider [7] = { 3, 3, 2, 2, 1, 1, 0 }; + +/* ************************************************************************** */ +/* * * */ +/* * Alpha composing macros * */ +/* * the code below is slightly modified from the libpng package * */ +/* * the original was last optimized by Greg Roelofs & Mark Adler * */ +/* * * */ +/* ************************************************************************** */ + +#define MNG_COMPOSE8(RET,FG,ALPHA,BG) { \ + mng_uint16 iH = (mng_uint16)((mng_uint16)(FG) * (mng_uint16)(ALPHA) \ + + (mng_uint16)(BG)*(mng_uint16)(255 - \ + (mng_uint16)(ALPHA)) + (mng_uint16)128); \ + (RET) = (mng_uint8)((iH + (iH >> 8)) >> 8); } + +#define MNG_COMPOSE16(RET,FG,ALPHA,BG) { \ + mng_uint32 iH = (mng_uint32)((mng_uint32)(FG) * (mng_uint32)(ALPHA) \ + + (mng_uint32)(BG)*(mng_uint32)(65535L - \ + (mng_uint32)(ALPHA)) + (mng_uint32)32768L); \ + (RET) = (mng_uint16)((iH + (iH >> 16)) >> 16); } + +/* ************************************************************************** */ +/* * * */ +/* * Alpha blending macros * */ +/* * this code is based on Adam Costello's "Note on Compositing" from the * */ +/* * mng-list which gives the following formula: * */ +/* * * */ +/* * top pixel = (Rt, Gt, Bt, At) * */ +/* * bottom pixel = (Rb, Gb, Bb, Ab) * */ +/* * composite pixel = (Rc, Gc, Bc, Ac) * */ +/* * * */ +/* * all values in the range 0..1 * */ +/* * * */ +/* * Ac = 1 - (1 - At)(1 - Ab) * */ +/* * s = At / Ac * */ +/* * t = (1 - At) Ab / Ac * */ +/* * Rc = s Rt + t Rb * */ +/* * Gc = s Gt + t Gb * */ +/* * Bc = s Bt + t Bb * */ +/* * * */ +/* * (I just hope I coded it correctly in integer arithmetic...) * */ +/* * * */ +/* ************************************************************************** */ + +#define MNG_BLEND8(RT, GT, BT, AT, RB, GB, BB, AB, RC, GC, BC, AC) { \ + mng_uint32 S, T; \ + (AC) = (mng_uint8)((mng_uint32)255 - \ + ((((mng_uint32)255 - (mng_uint32)(AT)) * \ + ((mng_uint32)255 - (mng_uint32)(AB)) ) >> 8)); \ + S = (mng_uint32)(((mng_uint32)(AT) << 8) / \ + (mng_uint32)(AC)); \ + T = (mng_uint32)(((mng_uint32)255 - (mng_uint32)(AT)) * \ + (mng_uint32)(AB) / (mng_uint32)(AC)); \ + (RC) = (mng_uint8)((S * (mng_uint32)(RT) + \ + T * (mng_uint32)(RB) + (mng_uint32)127) >> 8); \ + (GC) = (mng_uint8)((S * (mng_uint32)(GT) + \ + T * (mng_uint32)(GB) + (mng_uint32)127) >> 8); \ + (BC) = (mng_uint8)((S * (mng_uint32)(BT) + \ + T * (mng_uint32)(BB) + (mng_uint32)127) >> 8); } + +#define MNG_BLEND16(RT, GT, BT, AT, RB, GB, BB, AB, RC, GC, BC, AC) { \ + mng_uint32 S, T; \ + (AC) = (mng_uint16)((mng_uint32)65535 - \ + ((((mng_uint32)65535 - (mng_uint32)(AT)) * \ + ((mng_uint32)65535 - (mng_uint32)(AB)) ) >> 16)); \ + S = (mng_uint32)(((mng_uint32)(AT) << 16) / \ + (mng_uint32)(AC)); \ + T = (mng_uint32)(((mng_uint32)65535 - (mng_uint32)(AT)) * \ + (mng_uint32)(AB) / (mng_uint32)(AC)); \ + (RC) = (mng_uint16)((S * (mng_uint32)(RT) + \ + T * (mng_uint32)(RB) + (mng_uint32)32767) >> 16); \ + (GC) = (mng_uint16)((S * (mng_uint32)(GT) + \ + T * (mng_uint32)(GB) + (mng_uint32)32767) >> 16); \ + (BC) = (mng_uint16)((S * (mng_uint32)(BT) + \ + T * (mng_uint32)(BB) + (mng_uint32)32767) >> 16); } + +/* ************************************************************************** */ + +/* note a good optimizing compiler will optimize this */ +#define DIV255B8(x) (mng_uint8)(((x) + 127) / 255) +#define DIV255B16(x) (mng_uint16)(((x) + 32767) / 65535) + +/* ************************************************************************** */ +/* * * */ +/* * Progressive display check - checks to see if progressive display is * */ +/* * in order & indicates so * */ +/* * * */ +/* * The routine is called after a call to one of the display_xxx routines * */ +/* * if appropriate * */ +/* * * */ +/* * The refresh is warrented in the read_chunk routine (mng_read.c) * */ +/* * and only during read&display processing, since there's not much point * */ +/* * doing it from memory! * */ +/* * * */ +/* ************************************************************************** */ + +mng_retcode mng_display_progressive_check (mng_datap pData) +{ + if ((pData->bDoProgressive) && /* need progressive display? */ + ((pData->eImagetype != mng_it_mng) || (pData->iDataheight > 300)) && + (pData->iDestb - pData->iDestt > 50) && (!pData->pCurraniobj)) + { + mng_int32 iC = pData->iRow + pData->iDestt - pData->iSourcet; + + if (iC % 20 == 0) /* every 20th line */ + pData->bNeedrefresh = MNG_TRUE; + + } + + return MNG_NOERROR; +} + +/* ************************************************************************** */ +/* * * */ +/* * Display routines - convert rowdata (which is already color-corrected) * */ +/* * to the output canvas, respecting the opacity information * */ +/* * * */ +/* ************************************************************************** */ + +MNG_LOCAL void check_update_region (mng_datap pData) +{ /* determine actual canvas row */ + mng_int32 iRow = pData->iRow + pData->iDestt - pData->iSourcet; + /* check for change in update-region */ + if ((pData->iDestl < (mng_int32)pData->iUpdateleft) || (pData->iUpdateright == 0)) + pData->iUpdateleft = pData->iDestl; + + if (pData->iDestr > (mng_int32)pData->iUpdateright) + pData->iUpdateright = pData->iDestr; + + if ((iRow < (mng_int32)pData->iUpdatetop) || (pData->iUpdatebottom == 0)) + pData->iUpdatetop = iRow; + + if (iRow+1 > (mng_int32)pData->iUpdatebottom) + pData->iUpdatebottom = iRow+1; + + return; +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_RGB8 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_rgb8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint8 iA8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *(pDataline+4); + + pScanline += (pData->iColinc * 3); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + + pScanline += (pData->iColinc * 3); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA16 = mng_get_uint16 (pDataline+6); + + if (iA16) /* any opacity at all ? */ + { + if (iA16 == 0xFFFF) /* fully opaque ? */ + { /* scale down by dropping the LSB */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *(pDataline+4); + } + else + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + iBGr16 = (mng_uint16)(*pScanline ); + iBGg16 = (mng_uint16)(*(pScanline+1)); + iBGb16 = (mng_uint16)(*(pScanline+2)); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iFGr16 >> 8); + *(pScanline+1) = (mng_uint8)(iFGg16 >> 8); + *(pScanline+2) = (mng_uint8)(iFGb16 >> 8); + } + } + + pScanline += (pData->iColinc * 3); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + } + else + { /* do alpha composing */ + MNG_COMPOSE8 (*pScanline, *pDataline, iA8, *pScanline ); + MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iA8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *(pDataline+2), iA8, *(pScanline+2)); + } + } + + pScanline += (pData->iColinc * 3); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_rgb8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGg16; + mng_uint16 iBGg16; + mng_uint8 iA8; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+iBps); + *(pScanline+2) = *(pDataline+2*iBps); + + pScanline += (pData->iColinc * 3); + pDataline += 4*iBps; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA16 = mng_get_uint16 (pDataline+6); + + if (iA16) /* any opacity at all ? */ + { + if (iA16 == 0xFFFF) /* fully opaque ? */ + { /* scale down by dropping the LSB */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *(pDataline+4); + } + else + { /* get the proper values */ + int i; + for (i=2; i >= 0; i--) + { + iFGg16 = mng_get_uint16 (pDataline+i+i); + /* scale background up */ + iBGg16 = (mng_uint16)(*(pScanline+i)); + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + /* now compose */ + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + /* and return the composed values */ + *(pScanline+i) = (mng_uint8)(iFGg16 >> 8); + } + } + } + + pScanline += (pData->iColinc * 3); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + } + else + { /* do alpha composing */ + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i), *(pDataline+i), iA8, *(pScanline+i)); + } + } + } + + pScanline += (pData->iColinc * 3); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_rgb8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iA8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + + pScanline += (pData->iColinc * 3); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + } + else + { /* do alpha composing */ +#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i), *(pDataline+i), iA8, *(pScanline+i)); + } +#else + MNG_COMPOSE8 (*pScanline, *pDataline, iA8, *pScanline ); + MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iA8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *(pDataline+2), iA8, *(pScanline+2)); +#endif + } + } + + pScanline += (pData->iColinc * 3); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_RGB8 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_RGBA8 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_rgba8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint16 iFGa16, iBGa16, iCa16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *(pDataline+4); + *(pScanline+3) = *(pDataline+6); + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + *(pScanline+3) = *(pDataline+3); + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + iFGa16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*(pScanline+3)); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* plain copy it */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *(pDataline+4); + *(pScanline+3) = *(pDataline+6); + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + iBGr16 = (mng_uint16)(*pScanline ); + iBGg16 = (mng_uint16)(*(pScanline+1)); + iBGb16 = (mng_uint16)(*(pScanline+2)); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iFGr16 >> 8); + *(pScanline+1) = (mng_uint8)(iFGg16 >> 8); + *(pScanline+2) = (mng_uint8)(iFGb16 >> 8); + /* alpha remains fully opaque !!! */ + } + else + { /* scale background up */ + iBGr16 = (mng_uint16)(*pScanline ); + iBGg16 = (mng_uint16)(*(pScanline+1)); + iBGb16 = (mng_uint16)(*(pScanline+2)); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iCr16 >> 8); + *(pScanline+1) = (mng_uint8)(iCg16 >> 8); + *(pScanline+2) = (mng_uint8)(iCb16 >> 8); + *(pScanline+3) = (mng_uint8)(iCa16 >> 8); + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *(pScanline+3); + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + *(pScanline+3) = *(pDataline+3); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ + MNG_COMPOSE8 (*pScanline, *pDataline, iFGa8, *pScanline ); + MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iFGa8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *(pDataline+2), iFGa8, *(pScanline+2)); + /* alpha remains fully opaque !!! */ + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCr8; + *(pScanline+1) = iCg8; + *(pScanline+2) = iCb8; + *(pScanline+3) = iCa8; + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_rgba8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint16 iFGa16, iBGa16, iCa16; + mng_uint16 iFGg16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16; + mng_uint8 iCr8, iCg8, iCb8; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+iBps); + *(pScanline+2) = *(pDataline+2*iBps); + *(pScanline+3) = *(pDataline+3*iBps); + + pScanline += (pData->iColinc << 2); + pDataline += 4*iBps; + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + iFGa16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*(pScanline+3)); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* plain copy it */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *(pDataline+4); + *(pScanline+3) = *(pDataline+6); + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* get the proper values */ + int i; + for (i=2; i >= 0; i--) + { + iFGg16 = mng_get_uint16 (pDataline+i+i); + /* scale background up */ + iBGg16 = (mng_uint16)(*(pScanline+i)); + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + /* now compose */ + MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); + /* and return the composed values */ + *(pScanline+i) = (mng_uint8)(iFGg16 >> 8); + /* alpha remains fully opaque !!! */ + } + } + else + { /* scale background up */ + iBGr16 = (mng_uint16)(*pScanline ); + iBGg16 = (mng_uint16)(*(pScanline+1)); + iBGb16 = (mng_uint16)(*(pScanline+2)); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iCr16 >> 8); + *(pScanline+1) = (mng_uint8)(iCg16 >> 8); + *(pScanline+2) = (mng_uint8)(iCb16 >> 8); + *(pScanline+3) = (mng_uint8)(iCa16 >> 8); + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *(pScanline+3); + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + *(pScanline+3) = *(pDataline+3); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i), *(pDataline+i), iFGa8, *(pScanline+i)); + } + /* alpha remains fully opaque !!! */ + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCr8; + *(pScanline+1) = iCg8; + *(pScanline+2) = iCb8; + *(pScanline+3) = iCa8; + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_rgba8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + *(pScanline+3) = *(pDataline+3); + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *(pScanline+3); + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + *(pScanline+3) = *(pDataline+3); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ +#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i), *(pDataline+i), iFGa8, *(pScanline+i)); + } +#else + MNG_COMPOSE8 (*pScanline, *pDataline, iFGa8, *pScanline ); + MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iFGa8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *(pDataline+2), iFGa8, *(pScanline+2)); +#endif + /* alpha remains fully opaque !!! */ + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCr8; + *(pScanline+1) = iCg8; + *(pScanline+2) = iCb8; + *(pScanline+3) = iCa8; + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_RGBA8 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_RGBA8_PM +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_rgba8_pm (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint32 s, t; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8_PM, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + if ((s = pDataline[6]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = pDataline[0]; + pScanline[1] = pDataline[2]; + pScanline[2] = pDataline[4]; + pScanline[3] = 255; + } + else + { +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + int i; + for (i=2; i >= 0; i--) + { + pScanline[2-i] = DIV255B8(s * pDataline[4-i-i]); + } +#else + pScanline[0] = DIV255B8(s * pDataline[0]); + pScanline[1] = DIV255B8(s * pDataline[2]); + pScanline[2] = DIV255B8(s * pDataline[4]); +#endif + pScanline[3] = (mng_uint8)s; + } + } + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values and premultiply */ + if ((s = pDataline[3]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { +#ifdef MNG_BIGENDIAN_SUPPORTED + *(mng_uint32*)pScanline = (*(mng_uint32*)pDataline) | 0x000000FF; +#else + pScanline[0] = pDataline[0]; + pScanline[1] = pDataline[1]; + pScanline[2] = pDataline[2]; + pScanline[3] = 255; +#endif + } + else + { +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + int i; + for (i=2; i >= 0; i--) + { + pScanline[2-i] = DIV255B8(s * pDataline[2-i]); + } +#else + pScanline[0] = DIV255B8(s * pDataline[0]); + pScanline[1] = DIV255B8(s * pDataline[1]); + pScanline[2] = DIV255B8(s * pDataline[2]); +#endif + pScanline[3] = (mng_uint8)s; + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + if ((s = pDataline[6]) != 0) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if (s == 255) + { /* plain copy it */ + pScanline[0] = pDataline[0]; + pScanline[1] = pDataline[2]; + pScanline[2] = pDataline[4]; + pScanline[3] = 255; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[2-i] = DIV255B8(s * pDataline[4-i-i] + t * + pScanline[2-i]); + } + } +#else + pScanline[0] = DIV255B8(s * pDataline[0] + t * pScanline[0]); + pScanline[1] = DIV255B8(s * pDataline[2] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[4] + t * pScanline[2]); +#endif + pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + if ((s = pDataline[3]) != 0) /* any opacity at all ? */ + { /* fully opaque ? */ + if (s == 255) + { /* then simply copy the values */ +#ifdef MNG_BIGENDIAN_SUPPORTED + *(mng_uint32*)pScanline = (*(mng_uint32*)pDataline) | 0x000000FF; +#else + pScanline[0] = pDataline[0]; + pScanline[1] = pDataline[1]; + pScanline[2] = pDataline[2]; + pScanline[3] = 255; +#endif + } + else + { /* now blend (premultiplied) */ + t = 255 - s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[2-i] = DIV255B8(s * pDataline[2-i] + t * + pScanline[2-i]); + } + } +#else + pScanline[0] = DIV255B8(s * pDataline[0] + t * pScanline[0]); + pScanline[1] = DIV255B8(s * pDataline[1] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[2] + t * pScanline[2]); +#endif + pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8_PM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_rgba8_pm (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint32 s, t; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8_PM, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + if ((s = pDataline[6]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = pDataline[0]; + pScanline[1] = pDataline[2]; + pScanline[2] = pDataline[4]; + pScanline[3] = 255; + } + else + { +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + int i; + for (i=2; i >= 0; i--) + { + pScanline[2-i] = DIV255B8(s * pDataline[4-i-i]); + } +#else + pScanline[0] = DIV255B8(s * pDataline[0]); + pScanline[1] = DIV255B8(s * pDataline[2]); + pScanline[2] = DIV255B8(s * pDataline[4]); +#endif + pScanline[3] = (mng_uint8)s; + } + } + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values and premultiply */ + if ((s = pDataline[3]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { +#ifdef MNG_BIGENDIAN_SUPPORTED + *(mng_uint32*)pScanline = (*(mng_uint32*)pDataline) | 0x000000FF; +#else + pScanline[0] = pDataline[0]; + pScanline[1] = pDataline[1]; + pScanline[2] = pDataline[2]; + pScanline[3] = 255; +#endif + } + else + { +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + int i; + for (i=2; i >= 0; i--) + { + pScanline[2-i] = DIV255B8(s * pDataline[2-i]); + } +#else + pScanline[0] = DIV255B8(s * pDataline[0]); + pScanline[1] = DIV255B8(s * pDataline[1]); + pScanline[2] = DIV255B8(s * pDataline[2]); +#endif + pScanline[3] = (mng_uint8)s; + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + if ((s = pDataline[6]) != 0) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if (s == 255) + { /* plain copy it */ + pScanline[0] = pDataline[0]; + pScanline[1] = pDataline[2]; + pScanline[2] = pDataline[4]; + pScanline[3] = 255; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[2-i] = DIV255B8(s * pDataline[4-i-i] + t * + pScanline[2-i]); + } + } +#else + pScanline[0] = DIV255B8(s * pDataline[0] + t * pScanline[0]); + pScanline[1] = DIV255B8(s * pDataline[2] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[4] + t * pScanline[2]); +#endif + pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + if ((s = pDataline[3]) != 0) /* any opacity at all ? */ + { /* fully opaque ? */ + if (s == 255) + { /* then simply copy the values */ +#ifdef MNG_BIGENDIAN_SUPPORTED + *(mng_uint32*)pScanline = (*(mng_uint32*)pDataline) | 0x000000FF; +#else + pScanline[0] = pDataline[0]; + pScanline[1] = pDataline[1]; + pScanline[2] = pDataline[2]; + pScanline[3] = 255; +#endif + } + else + { /* now blend (premultiplied) */ + t = 255 - s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[2-i] = DIV255B8(s * pDataline[2-i] + t * + pScanline[2-i]); + } + } +#else + pScanline[0] = DIV255B8(s * pDataline[0] + t * pScanline[0]); + pScanline[1] = DIV255B8(s * pDataline[1] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[2] + t * pScanline[2]); +#endif + pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8_PM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_rgba8_pm (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint32 s, t; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8_PM, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values and premultiply */ + if ((s = pDataline[3]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { +#ifdef MNG_BIGENDIAN_SUPPORTED + *(mng_uint32*)pScanline = (*(mng_uint32*)pDataline) | 0x000000FF; +#else + pScanline[0] = pDataline[0]; + pScanline[1] = pDataline[1]; + pScanline[2] = pDataline[2]; + pScanline[3] = 255; +#endif + } + else + { +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + int i; + for (i=2; i >= 0; i--) + { + pScanline[2-i] = DIV255B8(s * pDataline[2-i]); + } +#else + pScanline[0] = DIV255B8(s * pDataline[0]); + pScanline[1] = DIV255B8(s * pDataline[1]); + pScanline[2] = DIV255B8(s * pDataline[2]); +#endif + pScanline[3] = (mng_uint8)s; + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + if ((s = pDataline[3]) != 0) /* any opacity at all ? */ + { /* fully opaque ? */ + if (s == 255) + { /* then simply copy the values */ +#ifdef MNG_BIGENDIAN_SUPPORTED + *(mng_uint32*)pScanline = (*(mng_uint32*)pDataline) | 0x000000FF; +#else + pScanline[0] = pDataline[0]; + pScanline[1] = pDataline[1]; + pScanline[2] = pDataline[2]; + pScanline[3] = 255; +#endif + } + else + { /* now blend (premultiplied) */ + t = 255 - s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[2-i] = DIV255B8(s * pDataline[2-i] + t * + pScanline[2-i]); + } + } +#else + pScanline[0] = DIV255B8(s * pDataline[0] + t * pScanline[0]); + pScanline[1] = DIV255B8(s * pDataline[1] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[2] + t * pScanline[2]); +#endif + pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA8_PM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_RGBA8_PM */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_ARGB8 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_argb8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint16 iFGa16, iBGa16, iCa16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8, MNG_LC_START); +#endif + + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *(pDataline+6); + *(pScanline+1) = *pDataline; + *(pScanline+2) = *(pDataline+2); + *(pScanline+3) = *(pDataline+4); + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *(pDataline+3); + *(pScanline+1) = *pDataline; + *(pScanline+2) = *(pDataline+1); + *(pScanline+3) = *(pDataline+2); + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + iFGa16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*pScanline); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* plain copy it */ + *pScanline = *(pDataline+6); + *(pScanline+1) = *pDataline; + *(pScanline+2) = *(pDataline+2); + *(pScanline+3) = *(pDataline+4); + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + iBGr16 = (mng_uint16)(*(pScanline+1)); + iBGg16 = (mng_uint16)(*(pScanline+2)); + iBGb16 = (mng_uint16)(*(pScanline+3)); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); + /* and return the composed values */ + /* alpha remains fully opaque !!! */ + *(pScanline+1) = (mng_uint8)(iFGr16 >> 8); + *(pScanline+2) = (mng_uint8)(iFGg16 >> 8); + *(pScanline+3) = (mng_uint8)(iFGb16 >> 8); + } + else + { /* scale background up */ + iBGr16 = (mng_uint16)(*(pScanline+1)); + iBGg16 = (mng_uint16)(*(pScanline+2)); + iBGb16 = (mng_uint16)(*(pScanline+3)); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iCa16 >> 8); + *(pScanline+1) = (mng_uint8)(iCr16 >> 8); + *(pScanline+2) = (mng_uint8)(iCg16 >> 8); + *(pScanline+3) = (mng_uint8)(iCb16 >> 8); + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *pScanline; + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *(pDataline+3); + *(pScanline+1) = *pDataline; + *(pScanline+2) = *(pDataline+1); + *(pScanline+3) = *(pDataline+2); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do simple alpha composing */ + /* alpha itself remains fully opaque !!! */ + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *(pScanline+1), *(pScanline+2), *(pScanline+3), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCa8; + *(pScanline+1) = iCr8; + *(pScanline+2) = iCg8; + *(pScanline+3) = iCb8; + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_argb8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint16 iFGa16, iBGa16, iCa16; + mng_uint16 iFGg16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16; + mng_uint8 iCr8, iCg8, iCb8; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *(pDataline+3*iBps); + *(pScanline+1) = *pDataline; + *(pScanline+2) = *(pDataline+iBps); + *(pScanline+3) = *(pDataline+2*iBps); + + pScanline += (pData->iColinc << 2); + pDataline += 4*iBps; + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + iFGa16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*pScanline); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* plain copy it */ + *pScanline = *(pDataline+6); + *(pScanline+1) = *pDataline; + *(pScanline+2) = *(pDataline+2); + *(pScanline+3) = *(pDataline+4); + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* get the proper values */ + int i; + for (i=2; i >= 0; i--) + { + iFGg16 = mng_get_uint16 (pDataline+i+i); + /* scale background up */ + iBGg16 = (mng_uint16)(*(pScanline+i+1)); + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + /* now compose */ + MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); + /* and return the composed values */ + /* alpha remains fully opaque !!! */ + *(pScanline+i+1) = (mng_uint8)(iFGg16 >> 8); + } + } + else + { /* scale background up */ + iBGr16 = (mng_uint16)(*(pScanline+1)); + iBGg16 = (mng_uint16)(*(pScanline+2)); + iBGb16 = (mng_uint16)(*(pScanline+3)); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iCa16 >> 8); + *(pScanline+1) = (mng_uint8)(iCr16 >> 8); + *(pScanline+2) = (mng_uint8)(iCg16 >> 8); + *(pScanline+3) = (mng_uint8)(iCb16 >> 8); + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *pScanline; + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *(pDataline+3); + *(pScanline+1) = *pDataline; + *(pScanline+2) = *(pDataline+1); + *(pScanline+3) = *(pDataline+2); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do simple alpha composing */ + /* alpha itself remains fully opaque !!! */ + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i+1), *(pDataline+i), iFGa8, *(pScanline+i+1)); + } + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *(pScanline+1), *(pScanline+2), *(pScanline+3), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCa8; + *(pScanline+1) = iCr8; + *(pScanline+2) = iCg8; + *(pScanline+3) = iCb8; + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_argb8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8, MNG_LC_START); +#endif + + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *(pDataline+3); + *(pScanline+1) = *pDataline; + *(pScanline+2) = *(pDataline+1); + *(pScanline+3) = *(pDataline+2); + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *pScanline; + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *(pDataline+3); + *(pScanline+1) = *pDataline; + *(pScanline+2) = *(pDataline+1); + *(pScanline+3) = *(pDataline+2); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do simple alpha composing */ + /* alpha itself remains fully opaque !!! */ +#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i+1), *(pDataline+i), iFGa8, *(pScanline+i+1)); + } +#else + MNG_COMPOSE8 (*(pScanline+1), *pDataline, iFGa8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *(pDataline+1), iFGa8, *(pScanline+2)); + MNG_COMPOSE8 (*(pScanline+3), *(pDataline+2), iFGa8, *(pScanline+3)); +#endif + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *(pScanline+1), *(pScanline+2), *(pScanline+3), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCa8; + *(pScanline+1) = iCr8; + *(pScanline+2) = iCg8; + *(pScanline+3) = iCb8; + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_ARGB8 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_ARGB8_PM +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_argb8_pm (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint32 s, t; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8_PM, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + if ((s = pDataline[6]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = 255; + pScanline[1] = pDataline[0]; + pScanline[2] = pDataline[2]; + pScanline[3] = pDataline[4]; + } + else + { + pScanline[0] = (mng_uint8)s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[3-i] = DIV255B8(s * pDataline[4-i-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[0]); + pScanline[2] = DIV255B8(s * pDataline[2]); + pScanline[3] = DIV255B8(s * pDataline[4]); +#endif + } + } + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values and premultiply */ + if ((s = pDataline[3]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = 255; + pScanline[1] = pDataline[0]; + pScanline[2] = pDataline[1]; + pScanline[3] = pDataline[2]; + } + else + { + pScanline[0] = (mng_uint8)s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[3-i] = DIV255B8(s * pDataline[2-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[0]); + pScanline[2] = DIV255B8(s * pDataline[1]); + pScanline[3] = DIV255B8(s * pDataline[2]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + if ((s = pDataline[6]) != 0) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if (s == 255) + { /* plain copy it */ + pScanline[0] = 255; + pScanline[1] = pDataline[0]; + pScanline[2] = pDataline[2]; + pScanline[3] = pDataline[4]; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; + pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[3-i] = DIV255B8(s * pDataline[4-i-i] + t * + pScanline[3-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[0] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[2] + t * pScanline[2]); + pScanline[3] = DIV255B8(s * pDataline[4] + t * pScanline[3]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + if ((s = pDataline[3]) != 0) /* any opacity at all ? */ + { /* fully opaque ? */ + if (s == 255) + { /* then simply copy the values */ + pScanline[0] = 255; + pScanline[1] = pDataline[0]; + pScanline[2] = pDataline[1]; + pScanline[3] = pDataline[2]; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; + pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[3-i] = DIV255B8(s * pDataline[2-i] + t * + pScanline[3-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[0] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[1] + t * pScanline[2]); + pScanline[3] = DIV255B8(s * pDataline[2] + t * pScanline[3]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8_PM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_argb8_pm (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint32 s, t; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8_PM, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + if ((s = pDataline[6]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = 255; + pScanline[1] = pDataline[0]; + pScanline[2] = pDataline[2]; + pScanline[3] = pDataline[4]; + } + else + { + pScanline[0] = (mng_uint8)s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[3-i] = DIV255B8(s * pDataline[4-i-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[0]); + pScanline[2] = DIV255B8(s * pDataline[2]); + pScanline[3] = DIV255B8(s * pDataline[4]); +#endif + } + } + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values and premultiply */ + if ((s = pDataline[3]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = 255; + pScanline[1] = pDataline[0]; + pScanline[2] = pDataline[1]; + pScanline[3] = pDataline[2]; + } + else + { + pScanline[0] = (mng_uint8)s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[3-i] = DIV255B8(s * pDataline[2-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[0]); + pScanline[2] = DIV255B8(s * pDataline[1]); + pScanline[3] = DIV255B8(s * pDataline[2]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + if ((s = pDataline[6]) != 0) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if (s == 255) + { /* plain copy it */ + pScanline[0] = 255; + pScanline[1] = pDataline[0]; + pScanline[2] = pDataline[2]; + pScanline[3] = pDataline[4]; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; + pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[3-i] = DIV255B8(s * pDataline[4-i-i] + t * + pScanline[3-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[0] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[2] + t * pScanline[2]); + pScanline[3] = DIV255B8(s * pDataline[4] + t * pScanline[3]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + if ((s = pDataline[3]) != 0) /* any opacity at all ? */ + { /* fully opaque ? */ + if (s == 255) + { /* then simply copy the values */ + pScanline[0] = 255; + pScanline[1] = pDataline[0]; + pScanline[2] = pDataline[1]; + pScanline[3] = pDataline[2]; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; + pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[3-i] = DIV255B8(s * pDataline[2-i] + t * + pScanline[3-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[0] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[1] + t * pScanline[2]); + pScanline[3] = DIV255B8(s * pDataline[2] + t * pScanline[3]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8_PM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_argb8_pm (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint32 s, t; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8_PM, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values and premultiply */ + if ((s = pDataline[3]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = 255; + pScanline[1] = pDataline[0]; + pScanline[2] = pDataline[1]; + pScanline[3] = pDataline[2]; + } + else + { + pScanline[0] = (mng_uint8)s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[3-i] = DIV255B8(s * pDataline[2-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[0]); + pScanline[2] = DIV255B8(s * pDataline[1]); + pScanline[3] = DIV255B8(s * pDataline[2]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + if ((s = pDataline[3]) != 0) /* any opacity at all ? */ + { /* fully opaque ? */ + if (s == 255) + { /* then simply copy the values */ + pScanline[0] = 255; + pScanline[1] = pDataline[0]; + pScanline[2] = pDataline[1]; + pScanline[3] = pDataline[2]; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; + pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[3-i] = DIV255B8(s * pDataline[2-i] + t * + pScanline[3-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[0] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[1] + t * pScanline[2]); + pScanline[3] = DIV255B8(s * pDataline[2] + t * pScanline[3]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ARGB8_PM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_ARGB8_PM */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_RGB8_A8 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_rgb8_a8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pAlphaline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint16 iFGa16, iBGa16, iCa16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8_A8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination rows */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + pAlphaline = (mng_uint8p)pData->fGetalphaline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination rows starting-point */ + pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); + pAlphaline = pAlphaline + pData->iCol + pData->iDestl; + + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *(pDataline+4); + *pAlphaline = *(pDataline+6); + + pScanline += (pData->iColinc * 3); + pAlphaline += pData->iColinc; + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + *pAlphaline = *(pDataline+3); + + pScanline += (pData->iColinc * 3); + pAlphaline += pData->iColinc; + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + iFGa16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*pAlphaline); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* plain copy it */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *(pDataline+4); + *pAlphaline = *(pDataline+6); + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + iBGr16 = (mng_uint16)(*pScanline ); + iBGg16 = (mng_uint16)(*(pScanline+1)); + iBGb16 = (mng_uint16)(*(pScanline+2)); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iFGr16 >> 8); + *(pScanline+1) = (mng_uint8)(iFGg16 >> 8); + *(pScanline+2) = (mng_uint8)(iFGb16 >> 8); + /* alpha remains fully opaque !!! */ + } + else + { /* scale background up */ + iBGr16 = (mng_uint16)(*pScanline ); + iBGg16 = (mng_uint16)(*(pScanline+1)); + iBGb16 = (mng_uint16)(*(pScanline+2)); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iCr16 >> 8); + *(pScanline+1) = (mng_uint8)(iCg16 >> 8); + *(pScanline+2) = (mng_uint8)(iCb16 >> 8); + *pAlphaline = (mng_uint8)(iCa16 >> 8); + } + } + } + + pScanline += (pData->iColinc * 3); + pAlphaline += pData->iColinc; + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *pAlphaline; + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + *pAlphaline = *(pDataline+3); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ + MNG_COMPOSE8 (*pScanline, *pDataline, iFGa8, *pScanline ); + MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iFGa8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *(pDataline+2), iFGa8, *(pScanline+2)); + /* alpha remains fully opaque !!! */ + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCr8; + *(pScanline+1) = iCg8; + *(pScanline+2) = iCb8; + *pAlphaline = iCa8; + } + } + } + + pScanline += (pData->iColinc * 3); + pAlphaline += pData->iColinc; + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8_A8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_rgb8_a8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pAlphaline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint16 iFGa16, iBGa16, iCa16; + mng_uint16 iFGg16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16; + mng_uint8 iCr8, iCg8, iCb8; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8_A8, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination rows */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + pAlphaline = (mng_uint8p)pData->fGetalphaline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination rows starting-point */ + pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); + pAlphaline = pAlphaline + pData->iCol + pData->iDestl; + + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+iBps); + *(pScanline+2) = *(pDataline+2*iBps); + *pAlphaline = *(pDataline+3*iBps); + + pScanline += (pData->iColinc * 3); + pAlphaline += pData->iColinc; + pDataline += 4*iBps; + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + iFGa16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*pAlphaline); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* plain copy it */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *(pDataline+4); + *pAlphaline = *(pDataline+6); + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* get the proper values */ + int i; + for (i=2; i >= 0; i--) + { + iFGg16 = mng_get_uint16 (pDataline+i+i); + /* scale background up */ + iBGg16 = (mng_uint16)(*(pScanline+i)); + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + /* now compose */ + MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); + /* and return the composed values */ + *(pScanline+i) = (mng_uint8)(iFGg16 >> 8); + /* alpha remains fully opaque !!! */ + } + } + else + { /* scale background up */ + iBGr16 = (mng_uint16)(*pScanline ); + iBGg16 = (mng_uint16)(*(pScanline+1)); + iBGb16 = (mng_uint16)(*(pScanline+2)); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iCr16 >> 8); + *(pScanline+1) = (mng_uint8)(iCg16 >> 8); + *(pScanline+2) = (mng_uint8)(iCb16 >> 8); + *pAlphaline = (mng_uint8)(iCa16 >> 8); + } + } + } + + pScanline += (pData->iColinc * 3); + pAlphaline += pData->iColinc; + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *pAlphaline; + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + *pAlphaline = *(pDataline+3); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i), *(pDataline+i), iFGa8, *(pScanline+i)); + } + /* alpha remains fully opaque !!! */ + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCr8; + *(pScanline+1) = iCg8; + *(pScanline+2) = iCb8; + *pAlphaline = iCa8; + } + } + } + + pScanline += (pData->iColinc * 3); + pAlphaline += pData->iColinc; + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8_A8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_rgb8_a8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pAlphaline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8_A8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination rows */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + pAlphaline = (mng_uint8p)pData->fGetalphaline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination rows starting-point */ + pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); + pAlphaline = pAlphaline + pData->iCol + pData->iDestl; + + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + *pAlphaline = *(pDataline+3); + + pScanline += (pData->iColinc * 3); + pAlphaline += pData->iColinc; + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *pAlphaline; + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *pDataline; + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *(pDataline+2); + *pAlphaline = *(pDataline+3); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ +#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i), *(pDataline+i), iFGa8, *(pScanline+i)); + } +#else + MNG_COMPOSE8 (*pScanline, *pDataline, iFGa8, *pScanline ); + MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iFGa8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *(pDataline+2), iFGa8, *(pScanline+2)); +#endif + /* alpha remains fully opaque !!! */ + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCr8; + *(pScanline+1) = iCg8; + *(pScanline+2) = iCb8; + *pAlphaline = iCa8; + } + } + } + + pScanline += (pData->iColinc * 3); + pAlphaline += pData->iColinc; + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB8_A8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_RGB8_A8 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_BGR8 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_bgr8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint8 iA8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + (pData->iSourcel / pData->iColinc) * 8; + else + pDataline = pDataline + (pData->iSourcel / pData->iColinc) * 4; + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *(pDataline+4); + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *pDataline; + + pScanline += (pData->iColinc * 3); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + + pScanline += (pData->iColinc * 3); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha value */ + iA16 = mng_get_uint16 (pDataline+6); + + if (iA16) /* any opacity at all ? */ + { + if (iA16 == 0xFFFF) /* fully opaque ? */ + { /* scale down by dropping the LSB */ + *pScanline = *(pDataline+4); + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *pDataline; + } + else + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + iBGr16 = (mng_uint16)(*(pScanline+2)); + iBGg16 = (mng_uint16)(*(pScanline+1)); + iBGb16 = (mng_uint16)(*pScanline ); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iFGb16 >> 8); + *(pScanline+1) = (mng_uint8)(iFGg16 >> 8); + *(pScanline+2) = (mng_uint8)(iFGr16 >> 8); + } + } + + pScanline += (pData->iColinc * 3); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + } + else + { /* do alpha composing */ + MNG_COMPOSE8 (*pScanline, *(pDataline+2), iA8, *pScanline ); + MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iA8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *pDataline, iA8, *(pScanline+2)); + } + } + + pScanline += (pData->iColinc * 3); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_bgr8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGg16; + mng_uint16 iBGg16; + mng_uint8 iA8; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR8, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *(pDataline+2*iBps); + *(pScanline+1) = *(pDataline+iBps); + *(pScanline+2) = *pDataline; + + pScanline += (pData->iColinc * 3); + pDataline += 4*iBps; + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha value */ + iA16 = mng_get_uint16 (pDataline+6); + + if (iA16) /* any opacity at all ? */ + { + if (iA16 == 0xFFFF) /* fully opaque ? */ + { /* scale down by dropping the LSB */ + *pScanline = *(pDataline+4); + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *pDataline; + } + else + { /* get the proper values */ + int i; + for (i=2; i >= 0; i--) + { + iFGg16 = mng_get_uint16 (pDataline+i+i); + /* scale background up */ + iBGg16 = (mng_uint16)(*(pScanline+2-i)); + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + /* now compose */ + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + /* and return the composed values */ + *(pScanline+2-i) = (mng_uint8)(iFGg16 >> 8); + } + } + } + + pScanline += (pData->iColinc * 3); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + } + else + { /* do alpha composing */ + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i), *(pDataline+2-i), iA8, *(pScanline+i)); + } + } + } + + pScanline += (pData->iColinc * 3); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_bgr8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iA8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 3) + (pData->iDestl * 3); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + (pData->iSourcel / pData->iColinc) * 4; + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + + pScanline += (pData->iColinc * 3); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + } + else + { /* do alpha composing */ +#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i), *(pDataline+2-i), iA8, *(pScanline+i)); + } +#else + MNG_COMPOSE8 (*pScanline, *(pDataline+2), iA8, *pScanline ); + MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iA8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *pDataline, iA8, *(pScanline+2)); +#endif + } + } + + pScanline += (pData->iColinc * 3); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_BGR8 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_BGRX8 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_bgrx8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint8 iA8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRX8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + (pData->iSourcel / pData->iColinc) * 8; + else + pDataline = pDataline + (pData->iSourcel / pData->iColinc) * 4; + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *(pDataline+4); + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *pDataline; + *(pScanline+3) = 0xFF; /* filler byte */ + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + *(pScanline+3) = 0xFF; /* filler byte */ + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha value */ + iA16 = mng_get_uint16 (pDataline+6); + + if (iA16) /* any opacity at all ? */ + { + if (iA16 == 0xFFFF) /* fully opaque ? */ + { /* scale down by dropping the LSB */ + *pScanline = *(pDataline+4); + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *pDataline; + *(pScanline+3) = 0xFF; /* filler byte */ + } + else + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + iBGr16 = (mng_uint16)(*(pScanline+2)); + iBGg16 = (mng_uint16)(*(pScanline+1)); + iBGb16 = (mng_uint16)(*pScanline ); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iFGb16 >> 8); + *(pScanline+1) = (mng_uint8)(iFGg16 >> 8); + *(pScanline+2) = (mng_uint8)(iFGr16 >> 8); + *(pScanline+3) = 0xFF; /* filler byte */ + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + *(pScanline+3) = 0xFF; /* filler byte */ + } + else + { /* do alpha composing */ + MNG_COMPOSE8 (*pScanline, *(pDataline+2), iA8, *pScanline ); + MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iA8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *pDataline, iA8, *(pScanline+2)); + *(pScanline+3) = 0xFF; /* filler byte */ + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRX8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_bgrx8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGg16; + mng_uint16 iBGg16; + mng_uint8 iA8; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRX8, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *(pDataline+2*iBps); + *(pScanline+1) = *(pDataline+iBps); + *(pScanline+2) = *pDataline; + *(pScanline+3) = 0xFF; /* filler byte */ + + pScanline += (pData->iColinc << 2); + pDataline += 4*iBps; + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha value */ + iA16 = mng_get_uint16 (pDataline+6); + + if (iA16) /* any opacity at all ? */ + { + if (iA16 == 0xFFFF) /* fully opaque ? */ + { /* scale down by dropping the LSB */ + *pScanline = *(pDataline+4); + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *pDataline; + *(pScanline+3) = 0xFF; /* filler byte */ + } + else + { /* get the proper values */ + int i; + for (i=2; i >= 0; i--) + { + iFGg16 = mng_get_uint16 (pDataline+i+i); + /* scale background up */ + iBGg16 = (mng_uint16)(*(pScanline+2-i)); + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + /* now compose */ + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + /* and return the composed values */ + *(pScanline+2-i) = (mng_uint8)(iFGg16 >> 8); + } + *(pScanline+3) = 0xFF; /* filler byte */ + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + *(pScanline+3) = 0xFF; /* filler byte */ + } + else + { /* do alpha composing */ + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i), *(pDataline+2-i), iA8, *(pScanline+i)); + } + *(pScanline+3) = 0xFF; /* filler byte */ + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRX8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_bgrx8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iA8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRX8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + (pData->iSourcel / pData->iColinc) * 4; + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + *(pScanline+3) = 0xFF; /* filler byte */ + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + *(pScanline+3) = 0xFF; /* filler byte */ + } + else + { /* do alpha composing */ +#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i), *(pDataline+2-i), iA8, *(pScanline+i)); + } +#else + MNG_COMPOSE8 (*pScanline, *(pDataline+2), iA8, *pScanline ); + MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iA8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *pDataline, iA8, *(pScanline+2)); +#endif + *(pScanline+3) = 0xFF; /* filler byte */ + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRX8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_BGRX8 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_BGRA8 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_bgra8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint16 iFGa16, iBGa16, iCa16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *(pDataline+4); + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *pDataline; + *(pScanline+3) = *(pDataline+6); + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + *(pScanline+3) = *(pDataline+3); + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + iFGa16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*(pScanline+3)); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* plain copy it */ + *pScanline = *(pDataline+4); + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *pDataline; + *(pScanline+3) = *(pDataline+6); + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + iBGr16 = (mng_uint16)(*(pScanline+2)); + iBGg16 = (mng_uint16)(*(pScanline+1)); + iBGb16 = (mng_uint16)(*pScanline ); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iFGb16 >> 8); + *(pScanline+1) = (mng_uint8)(iFGg16 >> 8); + *(pScanline+2) = (mng_uint8)(iFGr16 >> 8); + /* alpha remains fully opaque !!! */ + } + else + { /* scale background up */ + iBGr16 = (mng_uint16)(*(pScanline+2)); + iBGg16 = (mng_uint16)(*(pScanline+1)); + iBGb16 = (mng_uint16)(*pScanline ); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iCb16 >> 8); + *(pScanline+1) = (mng_uint8)(iCg16 >> 8); + *(pScanline+2) = (mng_uint8)(iCr16 >> 8); + *(pScanline+3) = (mng_uint8)(iCa16 >> 8); + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *(pScanline+3); + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + *(pScanline+3) = *(pDataline+3); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ + MNG_COMPOSE8 (*pScanline, *(pDataline+2), iFGa8, *pScanline ); + MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iFGa8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *pDataline, iFGa8, *(pScanline+2)); + /* alpha remains fully opaque !!! */ + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *(pScanline+2), *(pScanline+1), *pScanline, iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCb8; + *(pScanline+1) = iCg8; + *(pScanline+2) = iCr8; + *(pScanline+3) = iCa8; + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_bgra8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint16 iFGa16, iBGa16, iCa16; + mng_uint16 iFGg16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16; + mng_uint8 iCr8, iCg8, iCb8; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *(pDataline+2*iBps); + *(pScanline+1) = *(pDataline+iBps); + *(pScanline+2) = *pDataline; + *(pScanline+3) = *(pDataline+3*iBps); + + pScanline += (pData->iColinc << 2); + pDataline += 4*iBps; + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + iFGa16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*(pScanline+3)); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* plain copy it */ + *pScanline = *(pDataline+4); + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *pDataline; + *(pScanline+3) = *(pDataline+6); + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* get the proper values */ + int i; + for (i=2; i >= 0; i--) + { + iFGg16 = mng_get_uint16 (pDataline+i+i); + /* scale background up */ + iBGg16 = (mng_uint16)(*(pScanline+2-i)); + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + /* now compose */ + MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); + /* and return the composed values */ + *(pScanline+2-i) = (mng_uint8)(iFGg16 >> 8); + /* alpha remains fully opaque !!! */ + } + } + else + { /* scale background up */ + iBGr16 = (mng_uint16)(*(pScanline+2)); + iBGg16 = (mng_uint16)(*(pScanline+1)); + iBGb16 = (mng_uint16)(*pScanline ); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iCb16 >> 8); + *(pScanline+1) = (mng_uint8)(iCg16 >> 8); + *(pScanline+2) = (mng_uint8)(iCr16 >> 8); + *(pScanline+3) = (mng_uint8)(iCa16 >> 8); + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *(pScanline+3); + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + *(pScanline+3) = *(pDataline+3); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i), *(pDataline+2-i), iFGa8, *(pScanline+i)); + } + /* alpha remains fully opaque !!! */ + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *(pScanline+2), *(pScanline+1), *pScanline, iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCb8; + *(pScanline+1) = iCg8; + *(pScanline+2) = iCr8; + *(pScanline+3) = iCa8; + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_bgra8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + *(pScanline+3) = *(pDataline+3); + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *(pScanline+3); + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *(pDataline+2); + *(pScanline+1) = *(pDataline+1); + *(pScanline+2) = *pDataline; + *(pScanline+3) = *(pDataline+3); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ +#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i), *(pDataline+2-i), iFGa8, *(pScanline+i)); + } +#else + MNG_COMPOSE8 (*pScanline, *(pDataline+2), iFGa8, *pScanline ); + MNG_COMPOSE8 (*(pScanline+1), *(pDataline+1), iFGa8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *pDataline, iFGa8, *(pScanline+2)); +#endif + /* alpha remains fully opaque !!! */ + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *(pScanline+2), *(pScanline+1), *pScanline, iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCb8; + *(pScanline+1) = iCg8; + *(pScanline+2) = iCr8; + *(pScanline+3) = iCa8; + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_BGRA8 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_BGRA8_PM +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_bgra8_pm (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint32 s, t; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8PM, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + if ((s = pDataline[6]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = pDataline[4]; + pScanline[1] = pDataline[2]; + pScanline[2] = pDataline[0]; + pScanline[3] = 255; + } + else + { + pScanline[0] = DIV255B8(s * pDataline[4]); + pScanline[1] = DIV255B8(s * pDataline[2]); + pScanline[2] = DIV255B8(s * pDataline[0]); + pScanline[3] = (mng_uint8)s; + } + } + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values and premultiply */ + if ((s = pDataline[3]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = pDataline[2]; + pScanline[1] = pDataline[1]; + pScanline[2] = pDataline[0]; + pScanline[3] = 255; + } + else + { + pScanline[0] = DIV255B8(s * pDataline[2]); + pScanline[1] = DIV255B8(s * pDataline[1]); + pScanline[2] = DIV255B8(s * pDataline[0]); + pScanline[3] = (mng_uint8)s; + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + if ((s = pDataline[6]) != 0) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if (s == 255) + { /* plain copy it */ + pScanline[0] = pDataline[4]; + pScanline[1] = pDataline[2]; + pScanline[2] = pDataline[0]; + pScanline[3] = 255; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i] = DIV255B8(s * pDataline[4-i-i] + t * + pScanline[i]); + } + } +#else + pScanline[0] = DIV255B8(s * pDataline[4] + t * pScanline[0]); + pScanline[1] = DIV255B8(s * pDataline[2] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[0] + t * pScanline[2]); +#endif + pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + if ((s = pDataline[3]) != 0) /* any opacity at all ? */ + { /* fully opaque ? */ + if (s == 255) + { /* then simply copy the values */ + pScanline[0] = pDataline[2]; + pScanline[1] = pDataline[1]; + pScanline[2] = pDataline[0]; + pScanline[3] = 255; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i] = DIV255B8(s * pDataline[2-i] + t * + pScanline[i]); + } + } +#else + pScanline[0] = DIV255B8(s * pDataline[2] + t * pScanline[0]); + pScanline[1] = DIV255B8(s * pDataline[1] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[0] + t * pScanline[2]); +#endif + pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8PM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_bgra8_pm (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint32 s, t; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8PM, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + if ((s = pDataline[6]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = pDataline[4]; + pScanline[1] = pDataline[2]; + pScanline[2] = pDataline[0]; + pScanline[3] = 255; + } + else + { +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + int i; + for (i=2; i >= 0; i--) + { + pScanline[i] = DIV255B8(s * pDataline[4-i-i]); + } +#else + pScanline[0] = DIV255B8(s * pDataline[4]); + pScanline[1] = DIV255B8(s * pDataline[2]); + pScanline[2] = DIV255B8(s * pDataline[0]); +#endif + pScanline[3] = (mng_uint8)s; + } + } + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values and premultiply */ + if ((s = pDataline[3]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = pDataline[2]; + pScanline[1] = pDataline[1]; + pScanline[2] = pDataline[0]; + pScanline[3] = 255; + } + else + { +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + int i; + for (i=2; i >= 0; i--) + { + pScanline[i] = DIV255B8(s * pDataline[2-i]); + } +#else + pScanline[0] = DIV255B8(s * pDataline[2]); + pScanline[1] = DIV255B8(s * pDataline[1]); + pScanline[2] = DIV255B8(s * pDataline[0]); +#endif + pScanline[3] = (mng_uint8)s; + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + if ((s = pDataline[6]) != 0) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if (s == 255) + { /* plain copy it */ + pScanline[0] = pDataline[4]; + pScanline[1] = pDataline[2]; + pScanline[2] = pDataline[0]; + pScanline[3] = 255; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i] = DIV255B8(s * pDataline[4-i-i] + t * + pScanline[i]); + } + } +#else + pScanline[0] = DIV255B8(s * pDataline[4] + t * pScanline[0]); + pScanline[1] = DIV255B8(s * pDataline[2] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[0] + t * pScanline[2]); +#endif + pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + if ((s = pDataline[3]) != 0) /* any opacity at all ? */ + { /* fully opaque ? */ + if (s == 255) + { /* then simply copy the values */ + pScanline[0] = pDataline[2]; + pScanline[1] = pDataline[1]; + pScanline[2] = pDataline[0]; + pScanline[3] = 255; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i] = DIV255B8(s * pDataline[2-i] + t * + pScanline[i]); + } + } +#else + pScanline[0] = DIV255B8(s * pDataline[2] + t * pScanline[0]); + pScanline[1] = DIV255B8(s * pDataline[1] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[0] + t * pScanline[2]); +#endif + pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8PM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_bgra8_pm (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint32 s, t; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8PM, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values and premultiply */ + if ((s = pDataline[3]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = pDataline[2]; + pScanline[1] = pDataline[1]; + pScanline[2] = pDataline[0]; + pScanline[3] = 255; + } + else + { +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + int i; + for (i=2; i >= 0; i--) + { + pScanline[i] = DIV255B8(s * pDataline[2-i]); + } +#else + pScanline[0] = DIV255B8(s * pDataline[2]); + pScanline[1] = DIV255B8(s * pDataline[1]); + pScanline[2] = DIV255B8(s * pDataline[0]); +#endif + pScanline[3] = (mng_uint8)s; + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + if ((s = pDataline[3]) != 0) /* any opacity at all ? */ + { /* fully opaque ? */ + if (s == 255) + { /* then simply copy the values */ + pScanline[0] = pDataline[2]; + pScanline[1] = pDataline[1]; + pScanline[2] = pDataline[0]; + pScanline[3] = 255; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i] = DIV255B8(s * pDataline[2-i] + t * + pScanline[i]); + } + } +#else + pScanline[0] = DIV255B8(s * pDataline[2] + t * pScanline[0]); + pScanline[1] = DIV255B8(s * pDataline[1] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[0] + t * pScanline[2]); +#endif + pScanline[3] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[3]))); + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA8PM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_BGRA8_PM */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_ABGR8 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_abgr8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint16 iFGa16, iBGa16, iCa16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *(pDataline+6); + *(pScanline+1) = *(pDataline+4); + *(pScanline+2) = *(pDataline+2); + *(pScanline+3) = *pDataline; + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *(pDataline+3); + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *(pDataline+1); + *(pScanline+3) = *pDataline; + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + iFGa16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*pScanline); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* plain copy it */ + *pScanline = *(pDataline+6); + *(pScanline+1) = *(pDataline+4); + *(pScanline+2) = *(pDataline+2); + *(pScanline+3) = *pDataline; + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + iBGr16 = (mng_uint16)(*(pScanline+3)); + iBGg16 = (mng_uint16)(*(pScanline+2)); + iBGb16 = (mng_uint16)(*(pScanline+1)); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); + /* and return the composed values */ + /* alpha itself remains fully opaque !!! */ + *(pScanline+1) = (mng_uint8)(iFGb16 >> 8); + *(pScanline+2) = (mng_uint8)(iFGg16 >> 8); + *(pScanline+3) = (mng_uint8)(iFGr16 >> 8); + } + else + { /* scale background up */ + iBGr16 = (mng_uint16)(*(pScanline+3)); + iBGg16 = (mng_uint16)(*(pScanline+2)); + iBGb16 = (mng_uint16)(*(pScanline+1)); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iCa16 >> 8); + *(pScanline+1) = (mng_uint8)(iCb16 >> 8); + *(pScanline+2) = (mng_uint8)(iCg16 >> 8); + *(pScanline+3) = (mng_uint8)(iCr16 >> 8); + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *pScanline; + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *(pDataline+3); + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *(pDataline+1); + *(pScanline+3) = *pDataline; + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do simple alpha composing */ + /* alpha itself remains fully opaque !!! */ + MNG_COMPOSE8 (*(pScanline+1), *(pDataline+2), iFGa8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *(pDataline+1), iFGa8, *(pScanline+2)); + MNG_COMPOSE8 (*(pScanline+3), *pDataline, iFGa8, *(pScanline+3)); + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *(pScanline+3), *(pScanline+2), *(pScanline+1), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCa8; + *(pScanline+1) = iCb8; + *(pScanline+2) = iCg8; + *(pScanline+3) = iCr8; + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_abgr8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint16 iFGa16, iBGa16, iCa16; + mng_uint16 iFGg16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16; + mng_uint8 iCr8, iCg8, iCb8; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *pScanline = *(pDataline+3*iBps); + *(pScanline+1) = *(pDataline+2*iBps); + *(pScanline+2) = *(pDataline+iBps); + *(pScanline+3) = *pDataline; + + pScanline += (pData->iColinc << 2); + pDataline += 4*iBps; + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + iFGa16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*pScanline); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* plain copy it */ + *pScanline = *(pDataline+6); + *(pScanline+1) = *(pDataline+4); + *(pScanline+2) = *(pDataline+2); + *(pScanline+3) = *pDataline; + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* get the proper values */ + int i; + for (i=2; i >= 0; i--) + { + iFGg16 = mng_get_uint16 (pDataline+i+i); + /* scale background up */ + iBGg16 = (mng_uint16)(*(pScanline+3-i)); + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + /* now compose */ + MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); + /* and return the composed values */ + /* alpha itself remains fully opaque !!! */ + *(pScanline+3-i) = (mng_uint8)(iFGg16 >> 8); + } + } + else + { /* scale background up */ + iBGr16 = (mng_uint16)(*(pScanline+3)); + iBGg16 = (mng_uint16)(*(pScanline+2)); + iBGb16 = (mng_uint16)(*(pScanline+1)); + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *pScanline = (mng_uint8)(iCa16 >> 8); + *(pScanline+1) = (mng_uint8)(iCb16 >> 8); + *(pScanline+2) = (mng_uint8)(iCg16 >> 8); + *(pScanline+3) = (mng_uint8)(iCr16 >> 8); + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *pScanline; + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *(pDataline+3); + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *(pDataline+1); + *(pScanline+3) = *pDataline; + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do simple alpha composing */ + /* alpha itself remains fully opaque !!! */ + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i+1), *(pDataline+2-i), iFGa8, *(pScanline+i+1)); + } + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *(pScanline+3), *(pScanline+2), *(pScanline+1), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCa8; + *(pScanline+1) = iCb8; + *(pScanline+2) = iCg8; + *(pScanline+3) = iCr8; + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_abgr8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *pScanline = *(pDataline+3); + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *(pDataline+1); + *(pScanline+3) = *pDataline; + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *pScanline; + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pScanline = *(pDataline+3); + *(pScanline+1) = *(pDataline+2); + *(pScanline+2) = *(pDataline+1); + *(pScanline+3) = *pDataline; + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do simple alpha composing */ + /* alpha itself remains fully opaque !!! */ +#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pScanline+i+1), *(pDataline+2-i), iFGa8, *(pScanline+i+1)); + } +#else + MNG_COMPOSE8 (*(pScanline+1), *(pDataline+2), iFGa8, *(pScanline+1)); + MNG_COMPOSE8 (*(pScanline+2), *(pDataline+1), iFGa8, *(pScanline+2)); + MNG_COMPOSE8 (*(pScanline+3), *pDataline, iFGa8, *(pScanline+3)); +#endif + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + *(pScanline+3), *(pScanline+2), *(pScanline+1), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pScanline = iCa8; + *(pScanline+1) = iCb8; + *(pScanline+2) = iCg8; + *(pScanline+3) = iCr8; + } + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_ABGR8 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_ABGR8_PM +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_abgr8_pm (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint32 s, t; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8_PM, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + if ((s = pDataline[6]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = 255; + pScanline[1] = pDataline[4]; + pScanline[2] = pDataline[2]; + pScanline[3] = pDataline[0]; + } + else + { + pScanline[0] = (mng_uint8)s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i+1] = DIV255B8(s * pDataline[4-i-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[4]); + pScanline[2] = DIV255B8(s * pDataline[2]); + pScanline[3] = DIV255B8(s * pDataline[0]); +#endif + } + } + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values and premultiply */ + if ((s = pDataline[3]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = 255; + pScanline[1] = pDataline[2]; + pScanline[2] = pDataline[1]; + pScanline[3] = pDataline[0]; + } + else + { + pScanline[0] = (mng_uint8)s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i+1] = DIV255B8(s * pDataline[2-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[2]); + pScanline[2] = DIV255B8(s * pDataline[1]); + pScanline[3] = DIV255B8(s * pDataline[0]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + if ((s = pDataline[6]) != 0) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if (s == 255) + { /* plain copy it */ + pScanline[0] = 255; + pScanline[1] = pDataline[4]; + pScanline[2] = pDataline[2]; + pScanline[3] = pDataline[0]; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; + pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i+1] = DIV255B8(s * pDataline[4-i-i] + t * + pScanline[i+1]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[4] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[2] + t * pScanline[2]); + pScanline[3] = DIV255B8(s * pDataline[0] + t * pScanline[3]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + if ((s = pDataline[3]) != 0) /* any opacity at all ? */ + { /* fully opaque ? */ + if (s == 255) + { /* then simply copy the values */ + pScanline[0] = 255; + pScanline[1] = pDataline[2]; + pScanline[2] = pDataline[1]; + pScanline[3] = pDataline[0]; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; + pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i+1] = DIV255B8(s * pDataline[2-i] + t * + pScanline[i+1]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[2] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[1] + t * pScanline[2]); + pScanline[3] = DIV255B8(s * pDataline[0] + t * pScanline[3]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8_PM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_abgr8_pm (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint32 s, t; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8_PM, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + if ((s = pDataline[6]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = 255; + pScanline[1] = pDataline[4]; + pScanline[2] = pDataline[2]; + pScanline[3] = pDataline[0]; + } + else + { + pScanline[0] = (mng_uint8)s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i+1] = DIV255B8(s * pDataline[4-i-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[4]); + pScanline[2] = DIV255B8(s * pDataline[2]); + pScanline[3] = DIV255B8(s * pDataline[0]); +#endif + } + } + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values and premultiply */ + if ((s = pDataline[3]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = 255; + pScanline[1] = pDataline[2]; + pScanline[2] = pDataline[1]; + pScanline[3] = pDataline[0]; + } + else + { + pScanline[0] = (mng_uint8)s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i+1] = DIV255B8(s * pDataline[2-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[2]); + pScanline[2] = DIV255B8(s * pDataline[1]); + pScanline[3] = DIV255B8(s * pDataline[0]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + if ((s = pDataline[6]) != 0) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if (s == 255) + { /* plain copy it */ + pScanline[0] = 255; + pScanline[1] = pDataline[4]; + pScanline[2] = pDataline[2]; + pScanline[3] = pDataline[0]; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; + pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i+1] = DIV255B8(s * pDataline[4-i-i] + t * + pScanline[i+1]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[4] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[2] + t * pScanline[2]); + pScanline[3] = DIV255B8(s * pDataline[0] + t * pScanline[3]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + if ((s = pDataline[3]) != 0) /* any opacity at all ? */ + { /* fully opaque ? */ + if (s == 255) + { /* then simply copy the values */ + pScanline[0] = 255; + pScanline[1] = pDataline[2]; + pScanline[2] = pDataline[1]; + pScanline[3] = pDataline[0]; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; + pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i+1] = DIV255B8(s * pDataline[2-i] + t * + pScanline[i+1]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[2] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[1] + t * pScanline[2]); + pScanline[3] = DIV255B8(s * pDataline[0] + t * pScanline[3]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8_PM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_abgr8_pm (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint32 s, t; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8_PM, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl << 2); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values and premultiply */ + if ((s = pDataline[3]) == 0) + *(mng_uint32*) pScanline = 0; /* set all components = 0 */ + else + { + if (s == 255) + { + pScanline[0] = 255; + pScanline[1] = pDataline[2]; + pScanline[2] = pDataline[1]; + pScanline[3] = pDataline[0]; + } + else + { + pScanline[0] = (mng_uint8)s; +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i+1] = DIV255B8(s * pDataline[2-i]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[2]); + pScanline[2] = DIV255B8(s * pDataline[1]); + pScanline[3] = DIV255B8(s * pDataline[0]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + if ((s = pDataline[3]) != 0) /* any opacity at all ? */ + { /* fully opaque ? */ + if (s == 255) + { /* then simply copy the values */ + pScanline[0] = 255; + pScanline[1] = pDataline[2]; + pScanline[2] = pDataline[1]; + pScanline[3] = pDataline[0]; + } + else + { /* now blend (premultiplied) */ + t = 255 - s; + pScanline[0] = (mng_uint8)(255 - DIV255B8(t * (255 - pScanline[0]))); +#ifdef MNG_OPTIMIZE_FOOTPRINT_DIV + { + int i; + for (i=2; i >= 0; i--) + { + pScanline[i+1] = DIV255B8(s * pDataline[2-i] + t * + pScanline[i+1]); + } + } +#else + pScanline[1] = DIV255B8(s * pDataline[2] + t * pScanline[1]); + pScanline[2] = DIV255B8(s * pDataline[1] + t * pScanline[2]); + pScanline[3] = DIV255B8(s * pDataline[0] + t * pScanline[3]); +#endif + } + } + + pScanline += (pData->iColinc << 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_ABGR8_PM, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_ABGR8_PM */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_BGR565 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_bgr565 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint8 iA8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ( (*(pDataline+2)>>5) ) ); + *pScanline = (mng_uint8)( ( (*(pDataline+4)) >>3) | ( (*(pDataline+2)&0xFC) << 3) ); + + pScanline += (pData->iColinc * 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ( (*(pDataline+1)>>5 ) ) ); + *pScanline = (mng_uint8)( ( *(pDataline+2) >>3 ) | ( (*(pDataline+1)&0xFC ) << 3) ); + + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA16 = mng_get_uint16 (pDataline+6); + + if (iA16) /* any opacity at all ? */ + { + if (iA16 == 0xFFFF) /* fully opaque ? */ + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( (*(pDataline))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); + *pScanline = (mng_uint8)( (*(pDataline+4)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); + } + else + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + + iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); + iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); + iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( (iFGr16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); + *pScanline = (mng_uint8) ( ( (iFGb16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); + *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); + } + else + { /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); + iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); + iBlue = (mng_uint8) ( (*pScanline << 3) ); + + MNG_COMPOSE8 (iRed, *pDataline, iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); + *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_bgr565 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint8 iA8; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | + ( (*(pDataline+iBps)>>5) ) ); + *pScanline = (mng_uint8)( ( (*(pDataline+2*iBps)) >>3) | + ( (*(pDataline+iBps)&0xFC) << 3) ); + + pScanline += (pData->iColinc * 2); + pDataline += 4*iBps; + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA16 = mng_get_uint16 (pDataline+6); + + if (iA16) /* any opacity at all ? */ + { + if (iA16 == 0xFFFF) /* fully opaque ? */ + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( (*(pDataline))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); + *pScanline = (mng_uint8)( (*(pDataline+4)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); + } + else + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + + iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); + iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); + iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( (iFGr16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); + *pScanline = (mng_uint8) ( ( (iFGb16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); + *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); + } + else + { /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); + iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); + iBlue = (mng_uint8) ( (*pScanline << 3) ); + + MNG_COMPOSE8 (iRed, *pDataline, iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); + *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_bgr565 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iA8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ( (*(pDataline+1)>>5 ) ) ); + *pScanline = (mng_uint8)( ( *(pDataline+2) >>3 ) | ( (*(pDataline+1)&0xFC ) << 3) ); + + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); + *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); + } + else + { /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); + iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); + iBlue = (mng_uint8) ( (*pScanline << 3) ); + + MNG_COMPOSE8 (iRed, *pDataline, iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); + *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_BGR565 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_RGB565 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_rgb565 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint8 iA8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB565, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ( ( *(pDataline+4)) & 0xF8) | (*(pDataline+2) >> 5 ) ); + *pScanline = (mng_uint8)( ( ( *(pDataline )) >> 3 ) | ((*(pDataline+2) & 0xFC) << 3) ); + + pScanline += (pData->iColinc * 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) & 0xF8) | (*(pDataline+1) >> 5 ) ); + *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+1) & 0xFC) << 3) ); + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA16 = mng_get_uint16 (pDataline+6); + + if (iA16) /* any opacity at all ? */ + { + if (iA16 == 0xFFFF) /* fully opaque ? */ + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline+4)) & 0xF8) | (*(pDataline+2)>>5) ); + *pScanline = (mng_uint8)( ( (*(pDataline )) >> 3 ) | ((*(pDataline+2)&0xFC) << 3) ); + } + else + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + + /* scale background up */ + iBGr16 = (mng_uint8)( *(pScanline+1) & 0xF8 ); + iBGg16 = (mng_uint8)( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0) >> 3 ) ); + iBGb16 = (mng_uint8)( *(pScanline ) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8)( (mng_uint8)((iFGb16 >> 8) &0xF8) | ( (mng_uint8)(iFGg16 >> 8) >> 5 ) ); + *pScanline = (mng_uint8)( (mng_uint8) (iFGr16 >>11) | ( ( (mng_uint8)(iFGg16 >> 8) & 0xFC) << 3) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) & 0xF8) | ( *(pDataline+1) >> 5 ) ); + *pScanline = (mng_uint8)( ( (*(pDataline )) >> 3 ) | ( (*(pDataline+1) & 0xFC) << 3 ) ); + } + else + { /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8)( *(pScanline+1) & 0xF8); + iGreen = (mng_uint8)( ( *(pScanline+1) << 5 ) | ( ( (*pScanline)&0xE0)>>3 ) ); + iBlue = (mng_uint8)( *(pScanline ) << 3 ); + + MNG_COMPOSE8 (iRed, *(pDataline+2), iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+0), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8)( ( iRed & 0xF8) | ( iGreen >> 5 ) ); + *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB565, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_rgb565 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint8 iA8; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB565, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ( ( *(pDataline+2*iBps)) & 0xF8) | + (*(pDataline+iBps) >> 5 ) ); + *pScanline = (mng_uint8)( ( ( *(pDataline )) >> 3 ) | + ((*(pDataline+iBps) & 0xFC) << 3) ); + + pScanline += (pData->iColinc * 2); + pDataline += 4*iBps; + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA16 = mng_get_uint16 (pDataline+6); + + if (iA16) /* any opacity at all ? */ + { + if (iA16 == 0xFFFF) /* fully opaque ? */ + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline+4)) & 0xF8) | (*(pDataline+2)>>5) ); + *pScanline = (mng_uint8)( ( (*(pDataline )) >> 3 ) | ((*(pDataline+2)&0xFC) << 3) ); + } + else + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + + /* scale background up */ + iBGr16 = (mng_uint8)( *(pScanline+1) & 0xF8 ); + iBGg16 = (mng_uint8)( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0) >> 3 ) ); + iBGb16 = (mng_uint8)( *(pScanline ) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8)( (mng_uint8)((iFGb16 >> 8) &0xF8) | ( (mng_uint8)(iFGg16 >> 8) >> 5 ) ); + *pScanline = (mng_uint8)( (mng_uint8) (iFGr16 >>11) | ( ( (mng_uint8)(iFGg16 >> 8) & 0xFC) << 3) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) & 0xF8) | ( *(pDataline+1) >> 5 ) ); + *pScanline = (mng_uint8)( ( (*(pDataline )) >> 3 ) | ( (*(pDataline+1) & 0xFC) << 3 ) ); + } + else + { /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8)( *(pScanline+1) & 0xF8); + iGreen = (mng_uint8)( ( *(pScanline+1) << 5 ) | ( ( (*pScanline)&0xE0)>>3 ) ); + iBlue = (mng_uint8)( *(pScanline ) << 3 ); + + MNG_COMPOSE8 (iRed, *(pDataline+2), iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+0), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8)( ( iRed & 0xF8) | ( iGreen >> 5 ) ); + *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB565, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_rgb565 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iA8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB565, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) & 0xF8) | (*(pDataline+1) >> 5 ) ); + *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+1) & 0xFC) << 3) ); + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) & 0xF8) | ( *(pDataline+1) >> 5 ) ); + *pScanline = (mng_uint8)( ( (*(pDataline )) >> 3 ) | ( (*(pDataline+1) & 0xFC) << 3 ) ); + } + else + { /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8)( *(pScanline+1) & 0xF8); + iGreen = (mng_uint8)( ( *(pScanline+1) << 5 ) | ( ( (*pScanline)&0xE0)>>3 ) ); + iBlue = (mng_uint8)( *(pScanline ) << 3 ); + + MNG_COMPOSE8 (iRed, *(pDataline+2), iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+0), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8)( ( iRed & 0xF8) | ( iGreen >> 5 ) ); + *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB565, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_RGB565 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_BGRA565 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_bgra565 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint16 iFGa16, iBGa16, iCa16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA565, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl * 3); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ( (*(pDataline+2)>>5) ) ); + *pScanline = (mng_uint8)( ( (*(pDataline+4)) >>3) | ( (*(pDataline+2)&0xFC) << 3) ); + *(pScanline+2) = *(pDataline+6); + + pScanline += (pData->iColinc * 3); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ( (*(pDataline+1)>>5 ) ) ); + *pScanline = (mng_uint8)( ( *(pDataline+2) >>3 ) | ( (*(pDataline+1)&0xFC ) << 3) ); + *(pScanline+2) = *(pDataline+3); + + pScanline += (pData->iColinc * 3); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + iFGa16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*(pScanline+2)); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* plain copy it */ + *(pScanline+1) = (mng_uint8)( (*(pDataline))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); + *pScanline = (mng_uint8)( (*(pDataline+4)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); + *(pScanline+2) = *(pDataline+6); + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); + iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); + iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( (iFGr16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); + *pScanline = (mng_uint8) ( ( (iFGb16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); + } + else + { /* scale background up */ + iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); + iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); + iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( (iCr16 >> 8) & 0xF8 ) | ( (mng_uint8)(iCg16 >> 8) >> 5 ) ); + *pScanline = (mng_uint8) ( ( (iCb16 >> 11) ) | (((mng_uint8)(iCg16 >> 8) & 0xFC) << 3) ); + *(pScanline+2) = (mng_uint8)(iCa16 >> 8); + } + } + } + + pScanline += (pData->iColinc * 3); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *(pScanline+2); + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); + *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); + *(pScanline+2) = *(pDataline+3); + } + else + { + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); + iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); + iBlue = (mng_uint8) ( (*pScanline << 3) ); + + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ + MNG_COMPOSE8 (iRed, *pDataline, iFGa8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iFGa8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iFGa8, iBlue ); + /* alpha remains fully opaque !!! */ + *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); + *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + iRed , iGreen , iBlue , iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + + + *pScanline = (mng_uint8) ( ( iCb8 >> 3 ) | ( (iCg8 & 0xFC) << 3) ); + *(pScanline+1) = (mng_uint8) ( ( iCr8 & 0xF8 ) | (iCg8>>5) ); + *(pScanline+2) = (mng_uint8) iCa8; + } + } + } + + pScanline += (pData->iColinc *3); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA565, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_bgra565 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint16 iFGa16, iBGa16, iCa16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16; + mng_uint8 iCr8, iCg8, iCb8; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA565, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl * 3); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | + ( (*(pDataline+iBps)>>5) ) ); + *pScanline = (mng_uint8)( ( (*(pDataline+2*iBps)) >>3) | + ( (*(pDataline+iBps)&0xFC) << 3) ); + *(pScanline+2) = *(pDataline+3*iBps); + + pScanline += (pData->iColinc * 3); + pDataline += 4*iBps; + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + iFGa16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*(pScanline+2)); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* plain copy it */ + *(pScanline+1) = (mng_uint8)( (*(pDataline))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); + *pScanline = (mng_uint8)( (*(pDataline+4)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); + *(pScanline+2) = *(pDataline+6); + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); + iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); + iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( (iFGr16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); + *pScanline = (mng_uint8) ( ( (iFGb16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); + } + else + { /* scale background up */ + iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); + iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); + iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( (iCr16 >> 8) & 0xF8 ) | ( (mng_uint8)(iCg16 >> 8) >> 5 ) ); + *pScanline = (mng_uint8) ( ( (iCb16 >> 11) ) | (((mng_uint8)(iCg16 >> 8) & 0xFC) << 3) ); + *(pScanline+2) = (mng_uint8)(iCa16 >> 8); + } + } + } + + pScanline += (pData->iColinc * 3); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *(pScanline+2); + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); + *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); + *(pScanline+2) = *(pDataline+3); + } + else + { + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); + iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); + iBlue = (mng_uint8) ( (*pScanline << 3) ); + + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ + MNG_COMPOSE8 (iRed, *pDataline, iFGa8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iFGa8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iFGa8, iBlue ); + /* alpha remains fully opaque !!! */ + *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); + *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + iRed , iGreen , iBlue , iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + + + *pScanline = (mng_uint8) ( ( iCb8 >> 3 ) | ( (iCg8 & 0xFC) << 3) ); + *(pScanline+1) = (mng_uint8) ( ( iCr8 & 0xF8 ) | (iCg8>>5) ); + *(pScanline+2) = (mng_uint8) iCa8; + } + } + } + + pScanline += (pData->iColinc *3); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA565, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_bgra565 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA565, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl * 3); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ( (*(pDataline+1)>>5 ) ) ); + *pScanline = (mng_uint8)( ( *(pDataline+2) >>3 ) | ( (*(pDataline+1)&0xFC ) << 3) ); + *(pScanline+2) = *(pDataline+3); + + pScanline += (pData->iColinc * 3); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *(pScanline+2); + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); + *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); + *(pScanline+2) = *(pDataline+3); + } + else + { + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); + iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); + iBlue = (mng_uint8) ( (*pScanline << 3) ); + + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ + MNG_COMPOSE8 (iRed, *pDataline, iFGa8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iFGa8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iFGa8, iBlue ); + /* alpha remains fully opaque !!! */ + *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); + *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ( (iGreen & 0xFC) << 3) ); + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + iRed , iGreen , iBlue , iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + + + *pScanline = (mng_uint8) ( ( iCb8 >> 3 ) | ( (iCg8 & 0xFC) << 3) ); + *(pScanline+1) = (mng_uint8) ( ( iCr8 & 0xF8 ) | (iCg8>>5) ); + *(pScanline+2) = (mng_uint8) iCa8; + } + } + } + + pScanline += (pData->iColinc *3); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGRA565, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_BGRA565 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_RGBA565 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_rgba565 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint16 iFGa16, iBGa16, iCa16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA565, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl * 3); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline+4))&0xF8 ) | ( (*(pDataline+2)>>5) ) ); + *pScanline = (mng_uint8)( ( (*(pDataline)) >>3) | ( (*(pDataline+2)&0xFC) << 3) ); + *(pScanline+2) = *(pDataline+6); + + pScanline += (pData->iColinc * 3); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2))&0xF8 ) | ( (*(pDataline+1)>>5 ) ) ); + *pScanline = (mng_uint8)( ( *(pDataline) >>3 ) | ( (*(pDataline+1)&0xFC ) << 3) ); + *(pScanline+2) = *(pDataline+3); + + pScanline += (pData->iColinc * 3); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + iFGa16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*(pScanline+2)); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* plain copy it */ + *(pScanline+1) = (mng_uint8)( (*(pDataline+4))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); + *pScanline = (mng_uint8)( (*(pDataline)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); + *(pScanline+2) = *(pDataline+6); + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + iBGr16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); + iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); + iBGb16 = (mng_uint16)( (*(pScanline )) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( (iFGb16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); + *pScanline = (mng_uint8) ( ( (iFGr16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); + } + else + { /* scale background up */ + iBGr16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); + iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); + iBGb16 = (mng_uint16)( (*(pScanline )) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( (iCb16 >> 8) & 0xF8 ) | ( (mng_uint8)(iCg16 >> 8) >> 5 ) ); + *pScanline = (mng_uint8) ( ( (iCr16 >> 11) ) | (((mng_uint8)(iCg16 >> 8) & 0xFC) << 3) ); + *(pScanline+2) = (mng_uint8)(iCa16 >> 8); + } + } + } + + pScanline += (pData->iColinc * 3); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *(pScanline+2); + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) &0xF8 ) | (*(pDataline+1) >>5 ) ); + *pScanline = (mng_uint8)( ( ((*(pDataline))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); + *(pScanline+2) = *(pDataline+3); + } + else + { + mng_uint8 iRed, iGreen, iBlue; + + iBlue = (mng_uint8) ( *(pScanline+1) & 0xF8 ); + iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); + iRed = (mng_uint8) ( (*pScanline << 3) ); + + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ + MNG_COMPOSE8 (iRed, *pDataline, iFGa8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iFGa8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iFGa8, iBlue ); + /* alpha remains fully opaque !!! */ + *(pScanline+1) = (mng_uint8) ( ( iBlue & 0xF8 ) | (iGreen>>5) ); + *pScanline = (mng_uint8) ( ( iRed >> 3 ) | ( (iGreen & 0xFC) << 3) ); + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + iRed , iGreen , iBlue , iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + + + *pScanline = (mng_uint8) ( ( iCr8 >> 3 ) | ( (iCg8 & 0xFC) << 3) ); + *(pScanline+1) = (mng_uint8) ( ( iCb8 & 0xF8 ) | (iCg8>>5) ); + *(pScanline+2) = (mng_uint8) iCa8; + } + } + } + + pScanline += (pData->iColinc *3); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA565, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_rgba565 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint16 iFGa16, iBGa16, iCa16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16; + mng_uint8 iCr8, iCg8, iCb8; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA565, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl * 3); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2*iBps))&0xF8 ) | + ( (*(pDataline+iBps)>>5) ) ); + *pScanline = (mng_uint8)( ( (*(pDataline)) >>3) | + ( (*(pDataline+iBps)&0xFC) << 3) ); + *(pScanline+2) = *(pDataline+3*iBps); + + pScanline += (pData->iColinc * 3); + pDataline += 4*iBps; + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* get alpha values */ + iFGa16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*(pScanline+2)); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* plain copy it */ + *(pScanline+1) = (mng_uint8)( (*(pDataline+4))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); + *pScanline = (mng_uint8)( (*(pDataline)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); + *(pScanline+2) = *(pDataline+6); + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + iBGr16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); + iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); + iBGb16 = (mng_uint16)( (*(pScanline )) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iFGa16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iFGa16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iFGa16, iBGb16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( (iFGb16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); + *pScanline = (mng_uint8) ( ( (iFGr16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); + } + else + { /* scale background up */ + iBGr16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); + iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); + iBGb16 = (mng_uint16)( (*(pScanline )) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( (iCb16 >> 8) & 0xF8 ) | ( (mng_uint8)(iCg16 >> 8) >> 5 ) ); + *pScanline = (mng_uint8) ( ( (iCr16 >> 11) ) | (((mng_uint8)(iCg16 >> 8) & 0xFC) << 3) ); + *(pScanline+2) = (mng_uint8)(iCa16 >> 8); + } + } + } + + pScanline += (pData->iColinc * 3); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *(pScanline+2); + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) &0xF8 ) | (*(pDataline+1) >>5 ) ); + *pScanline = (mng_uint8)( ( ((*(pDataline))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); + *(pScanline+2) = *(pDataline+3); + } + else + { + mng_uint8 iRed, iGreen, iBlue; + + iBlue = (mng_uint8) ( *(pScanline+1) & 0xF8 ); + iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); + iRed = (mng_uint8) ( (*pScanline << 3) ); + + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ + MNG_COMPOSE8 (iRed, *pDataline, iFGa8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iFGa8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iFGa8, iBlue ); + /* alpha remains fully opaque !!! */ + *(pScanline+1) = (mng_uint8) ( ( iBlue & 0xF8 ) | (iGreen>>5) ); + *pScanline = (mng_uint8) ( ( iRed >> 3 ) | ( (iGreen & 0xFC) << 3) ); + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + iRed , iGreen , iBlue , iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + + + *pScanline = (mng_uint8) ( ( iCr8 >> 3 ) | ( (iCg8 & 0xFC) << 3) ); + *(pScanline+1) = (mng_uint8) ( ( iCb8 & 0xF8 ) | (iCg8>>5) ); + *(pScanline+2) = (mng_uint8) iCa8; + } + } + } + + pScanline += (pData->iColinc *3); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA565, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_rgba565 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8, iCa8; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA565, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol << 2) + (pData->iDestl * 3); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2))&0xF8 ) | ( (*(pDataline+1)>>5 ) ) ); + *pScanline = (mng_uint8)( ( *(pDataline) >>3 ) | ( (*(pDataline+1)&0xFC ) << 3) ); + *(pScanline+2) = *(pDataline+3); + + pScanline += (pData->iColinc * 3); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iFGa8 = *(pDataline+3); /* get alpha values */ + iBGa8 = *(pScanline+2); + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline+2)) &0xF8 ) | (*(pDataline+1) >>5 ) ); + *pScanline = (mng_uint8)( ( ((*(pDataline))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); + *(pScanline+2) = *(pDataline+3); + } + else + { + mng_uint8 iRed, iGreen, iBlue; + + iBlue = (mng_uint8) ( *(pScanline+1) & 0xF8 ); + iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | ( ((*pScanline) & 0xE0)>>3 ) ); + iRed = (mng_uint8) ( (*pScanline << 3) ); + + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ + MNG_COMPOSE8 (iRed, *pDataline, iFGa8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iFGa8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iFGa8, iBlue ); + /* alpha remains fully opaque !!! */ + *(pScanline+1) = (mng_uint8) ( ( iBlue & 0xF8 ) | (iGreen>>5) ); + *pScanline = (mng_uint8) ( ( iRed >> 3 ) | ( (iGreen & 0xFC) << 3) ); + } + else + { /* now blend */ + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iFGa8, + iRed , iGreen , iBlue , iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + + + *pScanline = (mng_uint8) ( ( iCr8 >> 3 ) | ( (iCg8 & 0xFC) << 3) ); + *(pScanline+1) = (mng_uint8) ( ( iCb8 & 0xF8 ) | (iCg8>>5) ); + *(pScanline+2) = (mng_uint8) iCa8; + } + } + } + + pScanline += (pData->iColinc *3); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGBA565, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_RGBA565 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_BGR565_A8 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_bgr565_a8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pAlphaline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16, iBGa16; + mng_uint16 iCr16, iCg16, iCb16, iCa16; + mng_uint8 iA8, iBGa8, iCa8; + mng_uint8 iCr8, iCg8, iCb8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565_A8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + pAlphaline = (mng_uint8p)pData->fGetalphaline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row +starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pAlphaline = pAlphaline + pData->iCol + pData->iDestl; + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ((*(pDataline+2)>>5) ) ); + *pScanline = (mng_uint8)( ( (*(pDataline+4)) >>3) | ((*(pDataline+2)&0xFC) << 3) ); + *pAlphaline = (mng_uint8)(*(pDataline+6)); + + pScanline += (pData->iColinc * 2); + pAlphaline += pData->iColinc; + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ((*(pDataline+1)>>5 ) ) ); + *pScanline = (mng_uint8)( ( *(pDataline+2) >>3 ) | ((*(pDataline+1)&0xFC ) << 3) ); + *pAlphaline = (mng_uint8)(*(pDataline+3)); + + pScanline += (pData->iColinc * 2); + pAlphaline += pData->iColinc; + pDataline += 4; + } + } + } + else /* Not fully opaque */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*pAlphaline); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iA16) /* any opacity at all ? */ + { + if ((iA16 == 0xFFFF) || (iBGa16 == 0)) /* fully opaque or background fully transparent ? */ + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( (*(pDataline))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); + *pScanline = (mng_uint8)( (*(pDataline+4)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); + *pAlphaline = *(pDataline+6); + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { + /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + + iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); + iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); + iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( (iFGr16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); + *pScanline = (mng_uint8) ( ( (iFGb16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); + *pAlphaline = (mng_uint8)(iA16>>8); + } + else /* background is not fully opaque */ + { /* scale background up */ + iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); + iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); + iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iA16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( (iCr16 >> 8)&0xF8 ) | ( (mng_uint8)(iCg16>>8) >> 5) ); + *pScanline = (mng_uint8) ( ( (iCb16>>11) ) | (((mng_uint8)(iCg16>>8)&0xFC) << 3) ); + *pAlphaline = (mng_uint8)(iCa16 >> 8); + } + } + } + + pScanline += (pData->iColinc * 2); + pAlphaline += pData->iColinc; + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; +iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + iBGa8 = *pAlphaline; + + if (iA8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iA8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); + *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); + *pAlphaline = *(pDataline+3); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { + /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); + iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | (((*pScanline) & 0xE0)>>3 ) ); + iBlue = (mng_uint8) ( (*pScanline << 3) ); + + MNG_COMPOSE8 (iRed, *pDataline, iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); + *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ((iGreen & 0xFC) << 3) ); + *pAlphaline = iA8; + } + else /* background not fully opaque */ + { + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iA8, + *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( iCr8 & 0xF8 ) | (iCg8>>5) ); + *pScanline = (mng_uint8) ( ( iCb8 >> 3 ) | ((iCg8 & 0xFC) << 3) ); + *pAlphaline = iCa8; + } + } + } + + pScanline += (pData->iColinc * 2); + pAlphaline += pData->iColinc; + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565_A8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_bgr565_a8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pAlphaline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16, iBGa16; + mng_uint16 iCr16, iCg16, iCb16, iCa16; + mng_uint8 iA8, iBGa8, iCa8; + mng_uint8 iCr8, iCg8, iCb8; + mng_uint8 iBps; + + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565_A8, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + pAlphaline = (mng_uint8p)pData->fGetalphaline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row +starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pAlphaline = pAlphaline + pData->iCol + pData->iDestl; + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | + ((*(pDataline+iBps)>>5) ) ); + *pScanline = (mng_uint8)( ( (*(pDataline+2*iBps)) >>3) | + ((*(pDataline+iBps)&0xFC) << 3) ); + *pAlphaline = (mng_uint8)(*(pDataline+6)); + + pScanline += (pData->iColinc * 2); + pAlphaline += pData->iColinc; + pDataline += 8; + } + } + else /* Not fully opaque */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA16 = mng_get_uint16 (pDataline+6); + iBGa16 = (mng_uint16)(*pAlphaline); + iBGa16 = (mng_uint16)(iBGa16 << 8) | iBGa16; + + if (iA16) /* any opacity at all ? */ + { + if ((iA16 == 0xFFFF) || (iBGa16 == 0)) /* fully opaque or background fully transparent ? */ + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( (*(pDataline))&0xF8 ) | (mng_uint8)( (*(pDataline+2)>>5 ) ); + *pScanline = (mng_uint8)( (*(pDataline+4)) >>3) | (mng_uint8)( (*(pDataline+2)&0xFC) << 3); + *pAlphaline = *(pDataline+6); + } + else + { + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { + /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + /* scale background up */ + + iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); + iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); + iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( (iFGr16 >> 8)&0xF8 ) | ( (mng_uint8)(iFGg16>>8) >> 5) ); + *pScanline = (mng_uint8) ( ( (iFGb16>>11) ) | (((mng_uint8)(iFGg16>>8)&0xFC) << 3) ); + *pAlphaline = (mng_uint8)(iA16>>8); + } + else /* background is not fully opaque */ + { /* scale background up */ + iBGb16 = (mng_uint16)( (*(pScanline+1)) & 0xF8 ); + iBGg16 = (mng_uint16)( (*(pScanline+1) << 5) | (((*(pScanline )) & 0xE0) >>3 ) ); + iBGr16 = (mng_uint16)( (*(pScanline )) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* let's blend */ + MNG_BLEND16 (mng_get_uint16 (pDataline ), + mng_get_uint16 (pDataline+2), + mng_get_uint16 (pDataline+4), iA16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( (iCr16 >> 8)&0xF8 ) | ( (mng_uint8)(iCg16>>8) >> 5) ); + *pScanline = (mng_uint8) ( ( (iCb16>>11) ) | (((mng_uint8)(iCg16>>8)&0xFC) << 3) ); + *pAlphaline = (mng_uint8)(iCa16 >> 8); + } + } + } + + pScanline += (pData->iColinc * 2); + pAlphaline += pData->iColinc; + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; +iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + iBGa8 = *pAlphaline; + + if (iA8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iA8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); + *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); + *pAlphaline = *(pDataline+3); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { + /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); + iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | (((*pScanline) & 0xE0)>>3 ) ); + iBlue = (mng_uint8) ( (*pScanline << 3) ); + + MNG_COMPOSE8 (iRed, *pDataline, iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); + *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ((iGreen & 0xFC) << 3) ); + *pAlphaline = iA8; + } + else /* background not fully opaque */ + { + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iA8, + *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( iCr8 & 0xF8 ) | (iCg8>>5) ); + *pScanline = (mng_uint8) ( ( iCb8 >> 3 ) | ((iCg8 & 0xFC) << 3) ); + *pAlphaline = iCa8; + } + } + } + + pScanline += (pData->iColinc * 2); + pAlphaline += pData->iColinc; + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565_A8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_bgr565_a8 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pAlphaline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iA8, iBGa8, iCa8; + mng_uint8 iCr8, iCg8, iCb8; + + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565_A8, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + pAlphaline = (mng_uint8p)pData->fGetalphaline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row +starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pAlphaline = pAlphaline + pData->iCol + pData->iDestl; + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline))&0xF8 ) | ((*(pDataline+1)>>5 ) ) ); + *pScanline = (mng_uint8)( ( *(pDataline+2) >>3 ) | ((*(pDataline+1)&0xFC ) << 3) ); + *pAlphaline = (mng_uint8)(*(pDataline+3)); + + pScanline += (pData->iColinc * 2); + pAlphaline += pData->iColinc; + pDataline += 4; + } + } + } + else /* Not fully opaque */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; +iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + iBGa8 = *pAlphaline; + + if (iA8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iA8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ( (*(pDataline)) &0xF8 ) | (*(pDataline+1) >>5 ) ); + *pScanline = (mng_uint8)( ( ((*(pDataline+2))>>3) ) | ((*(pDataline+1)&0xFC) << 3) ); + *pAlphaline = *(pDataline+3); + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { + /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8) ( *(pScanline+1) & 0xF8 ); + iGreen = (mng_uint8) ( (*(pScanline+1) << 5) | (((*pScanline) & 0xE0)>>3 ) ); + iBlue = (mng_uint8) ( (*pScanline << 3) ); + + MNG_COMPOSE8 (iRed, *pDataline, iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8) ( ( iRed & 0xF8 ) | (iGreen>>5) ); + *pScanline = (mng_uint8) ( ( iBlue >> 3 ) | ((iGreen & 0xFC) << 3) ); + *pAlphaline = iA8; + } + else /* background not fully opaque */ + { + MNG_BLEND8 (*pDataline, *(pDataline+1), *(pDataline+2), iA8, + *pScanline, *(pScanline+1), *(pScanline+2), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8) ( ( iCr8 & 0xF8 ) | (iCg8>>5) ); + *pScanline = (mng_uint8) ( ( iCb8 >> 3 ) | ((iCg8 & 0xFC) << 3) ); + *pAlphaline = iCa8; + } + } + } + + pScanline += (pData->iColinc * 2); + pAlphaline += pData->iColinc; + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR565_A8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_BGR565_A8 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_RGB555 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_rgb555 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint8 iA8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB555, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline+4) & 0xF8) >> 1 ) | (*(pDataline+2) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+2) & 0xF8) << 2 ) ); + + pScanline += (pData->iColinc * 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline+2) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA16 = mng_get_uint16 (pDataline+6); + + if (iA16) /* any opacity at all ? */ + { + if (iA16 == 0xFFFF) /* fully opaque ? */ + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline+4) & 0xF8) >> 1 ) | (*(pDataline+2) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+2) & 0xF8) << 2 ) ); + } + else + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + + /* scale background up */ + iBGr16 = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); + iBGg16 = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); + iBGb16 = (mng_uint8)( *(pScanline ) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8)( (mng_uint8)(((iFGb16 >> 8) & 0xF8) >> 1 ) | ( (mng_uint8)(iFGg16 >> 8) >> 6 ) ); + *pScanline = (mng_uint8)( (mng_uint8) ((iFGr16 >>11) >> 3 ) | ( ( (mng_uint8)(iFGg16 >> 8) & 0xF8) << 2 ) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline+2) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); + } + else + { /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); + iGreen = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); + iBlue = (mng_uint8)( *(pScanline ) << 3 ); + + MNG_COMPOSE8 (iRed, *(pDataline+2), iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+0), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8)( ( (iRed & 0xF8) >> 1 ) | ( iGreen >> 6 ) ); + *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xF8) << 2 ) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB555, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_rgb555 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint8 iA8; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB555, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline+2*iBps) & 0xF8) >> 1 ) | (*(pDataline+iBps) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+iBps) & 0xF8) << 2 ) ); + + pScanline += (pData->iColinc * 2); + pDataline += 4*iBps; + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA16 = mng_get_uint16 (pDataline+6); + + if (iA16) /* any opacity at all ? */ + { + if (iA16 == 0xFFFF) /* fully opaque ? */ + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline+4) & 0xF8) >> 1 ) | (*(pDataline+2) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+2) & 0xF8) << 2 ) ); + } + else + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + + /* scale background up */ + iBGr16 = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); + iBGg16 = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); + iBGb16 = (mng_uint8)( *(pScanline ) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8)( (mng_uint8)(((iFGb16 >> 8) & 0xF8) >> 1 ) | ( (mng_uint8)(iFGg16 >> 8) >> 6 ) ); + *pScanline = (mng_uint8)( (mng_uint8) ((iFGr16 >>11) >> 3 ) | ( ( (mng_uint8)(iFGg16 >> 8) & 0xF8) << 2 ) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline+2) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); + } + else + { /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); + iGreen = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); + iBlue = (mng_uint8)( *(pScanline ) << 3 ); + + MNG_COMPOSE8 (iRed, *(pDataline+2), iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+0), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8)( ( (iRed & 0xF8) >> 1 ) | ( iGreen >> 6 ) ); + *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xF8) << 2 ) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB555, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_rgb555 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iA8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB555, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline+2) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline+2) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline ) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); + } + else + { /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); + iGreen = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); + iBlue = (mng_uint8)( *(pScanline ) << 3 ); + + MNG_COMPOSE8 (iRed, *(pDataline+2), iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+0), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8)( ( (iRed & 0xF8) >> 1 ) | ( iGreen >> 6 ) ); + *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xF8) << 2 ) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_RGB555, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_RGB555 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_BGR555 +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_OPTIMIZE_FOOTPRINT_COMPOSE +mng_retcode mng_display_bgr555 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint8 iA8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR555, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pDataline = pData->pRGBArow; /* address source row */ + + if (pData->bIsRGBA16) /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 3); + else + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+2) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline+4) >> 3 ) | ((*(pDataline+2) & 0xF8) << 2 ) ); + + pScanline += (pData->iColinc * 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline+2) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA16 = mng_get_uint16 (pDataline+6); + + if (iA16) /* any opacity at all ? */ + { + if (iA16 == 0xFFFF) /* fully opaque ? */ + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+2) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline+4) >> 3 ) | ((*(pDataline+2) & 0xF8) << 2 ) ); + } + else + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + + /* scale background up */ + iBGb16 = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); + iBGg16 = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); + iBGr16 = (mng_uint8)( *(pScanline ) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8)( (mng_uint8)(((iFGr16 >> 8) & 0xF8) >> 1 ) | ( (mng_uint8)(iFGg16 >> 8) >> 6 ) ); + *pScanline = (mng_uint8)( (mng_uint8) ((iFGb16 >>11) >> 3 ) | ( ( (mng_uint8)(iFGg16 >> 8) & 0xF8) << 2 ) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline+2) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); + } + else + { /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); + iGreen = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); + iBlue = (mng_uint8)( *(pScanline ) << 3 ); + + MNG_COMPOSE8 (iRed, *(pDataline+0), iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8)( ( (iRed & 0xF8) >> 1 ) | ( iGreen >> 6 ) ); + *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xF8) << 2 ) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR555, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#else /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +mng_retcode mng_display_bgr555 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint16 iA16; + mng_uint16 iFGr16, iFGg16, iFGb16; + mng_uint16 iBGr16, iBGg16, iBGb16; + mng_uint8 iA8; + mng_uint8 iBps; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR555, MNG_LC_START); +#endif + + iBps=(mng_uint8)(pData->bIsRGBA16 ? 2:1); + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pDataline = pData->pRGBArow; /* address source row */ + + /* adjust source row starting-point */ + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << (iBps+1)); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+iBps) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline+2*iBps) >> 3 ) | ((*(pDataline+iBps) & 0xF8) << 2 ) ); + + pScanline += (pData->iColinc * 2); + pDataline += 4*iBps; + } + } + else + { + if (pData->bIsRGBA16) /* 16-bit input row ? */ + { + + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA16 = mng_get_uint16 (pDataline+6); + + if (iA16) /* any opacity at all ? */ + { + if (iA16 == 0xFFFF) /* fully opaque ? */ + { /* scale down by dropping the LSB */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+2) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline+4) >> 3 ) | ((*(pDataline+2) & 0xF8) << 2 ) ); + } + else + { /* get the proper values */ + iFGr16 = mng_get_uint16 (pDataline ); + iFGg16 = mng_get_uint16 (pDataline+2); + iFGb16 = mng_get_uint16 (pDataline+4); + + /* scale background up */ + iBGb16 = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); + iBGg16 = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); + iBGr16 = (mng_uint8)( *(pScanline ) << 3 ); + + iBGr16 = (mng_uint16)((mng_uint32)iBGr16 << 8) | iBGr16; + iBGg16 = (mng_uint16)((mng_uint32)iBGg16 << 8) | iBGg16; + iBGb16 = (mng_uint16)((mng_uint32)iBGb16 << 8) | iBGb16; + /* now compose */ + MNG_COMPOSE16(iFGr16, iFGr16, iA16, iBGr16); + MNG_COMPOSE16(iFGg16, iFGg16, iA16, iBGg16); + MNG_COMPOSE16(iFGb16, iFGb16, iA16, iBGb16); + /* and return the composed values */ + *(pScanline+1) = (mng_uint8)( (mng_uint8)(((iFGr16 >> 8) & 0xF8) >> 1 ) | ( (mng_uint8)(iFGg16 >> 8) >> 6 ) ); + *pScanline = (mng_uint8)( (mng_uint8) ((iFGb16 >>11) >> 3 ) | ( ( (mng_uint8)(iFGg16 >> 8) & 0xF8) << 2 ) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 8; + } + } + else + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline+2) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); + } + else + { /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); + iGreen = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); + iBlue = (mng_uint8)( *(pScanline ) << 3 ); + + MNG_COMPOSE8 (iRed, *(pDataline+0), iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8)( ( (iRed & 0xF8) >> 1 ) | ( iGreen >> 6 ) ); + *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xF8) << 2 ) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR555, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_OPTIMIZE_FOOTPRINT_COMPOSE */ +#else /* MNG_NO_16BIT_SUPPORT */ +mng_retcode mng_display_bgr555 (mng_datap pData) +{ + mng_uint8p pScanline; + mng_uint8p pDataline; + mng_int32 iX; + mng_uint8 iA8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR555, MNG_LC_START); +#endif + /* viewable row ? */ + if ((pData->iRow >= pData->iSourcet) && (pData->iRow < pData->iSourceb)) + { /* address destination row */ + pScanline = (mng_uint8p)pData->fGetcanvasline (((mng_handle)pData), + pData->iRow + pData->iDestt - + pData->iSourcet); + /* adjust destination row starting-point */ + pScanline = pScanline + (pData->iCol * 2) + (pData->iDestl * 2); + pDataline = pData->pRGBArow; /* address source row */ + + pDataline = pDataline + ((pData->iSourcel / pData->iColinc) << 2); + + if (pData->bIsOpaque) /* forget about transparency ? */ + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { /* copy the values */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline+2) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + else + { + { + for (iX = pData->iSourcel + pData->iCol; iX < pData->iSourcer; + iX += pData->iColinc) + { + iA8 = *(pDataline+3); /* get alpha value */ + + if (iA8) /* any opacity at all ? */ + { + if (iA8 == 0xFF) /* fully opaque ? */ + { /* then simply copy the values */ + *(pScanline+1) = (mng_uint8)( ((*(pDataline ) & 0xF8) >> 1 ) | (*(pDataline+1) >> 6 ) ); + *pScanline = (mng_uint8)( ( *(pDataline+2) >> 3 ) | ((*(pDataline+1) & 0xF8) << 2 ) ); + } + else + { /* do alpha composing */ + mng_uint8 iRed, iGreen, iBlue; + + iRed = (mng_uint8)( (*(pScanline+1) & 0xF8) << 1 ); + iGreen = (mng_uint8)( (*(pScanline+1) << 6 ) | ( ((*pScanline) & 0xE0) >> 2 ) ); + iBlue = (mng_uint8)( *(pScanline ) << 3 ); + + MNG_COMPOSE8 (iRed, *(pDataline+0), iA8, iRed ); + MNG_COMPOSE8 (iGreen, *(pDataline+1), iA8, iGreen ); + MNG_COMPOSE8 (iBlue, *(pDataline+2), iA8, iBlue ); + + *(pScanline+1) = (mng_uint8)( ( (iRed & 0xF8) >> 1 ) | ( iGreen >> 6 ) ); + *pScanline = (mng_uint8)( (iBlue >> 3 ) | ( (iGreen & 0xF8) << 2 ) ); + } + } + + pScanline += (pData->iColinc * 2); + pDataline += 4; + } + } + } + } + + check_update_region (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_BGR555, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_SKIPCANVAS_BGR555 */ + + +#ifndef MNG_SKIPCHUNK_BACK +/* ************************************************************************** */ +/* * * */ +/* * Background restore routines - restore the background with info from * */ +/* * the BACK and/or bKGD chunk or the app's background canvas * */ +/* * * */ +/* ************************************************************************** */ + +mng_retcode mng_restore_bkgd_backimage (mng_datap pData) +{ + /* save some stuff */ + mng_uint8p pRGBArow = pData->pRGBArow; + mng_int32 iRow = pData->iRow; + mng_int32 iRowsamples = pData->iRowsamples; + + mng_retcode iRetcode; /* work variables */ + mng_uint8p pTemp; + mng_uint8p pWork = pRGBArow; + mng_uint32 iX; + mng_int32 iZ; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_BACKIMAGE, MNG_LC_START); +#endif + /* determine row to retrieve */ + pData->iRow = pData->iDestt + iRow + pData->iBackimgoffsy; + + while (pData->iRow >= (mng_int32)pData->iBackimgheight) + pData->iRow -= (mng_int32)pData->iBackimgheight; + /* set width to that of background image */ + pData->iRowsamples = pData->iBackimgwidth; + /* retrieve into alternate buffer ! */ + pData->pRGBArow = pData->pPrevrow; + /* get it then */ + iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData); + + if (iRetcode) /* on error; bail out */ + return iRetcode; + /* we got the full row; but now need to + paste it into the proper location */ + iX = pData->iDestl - pData->iBackimgoffsx; + + while (iX >= pData->iBackimgwidth) + iX -= pData->iBackimgwidth; + +#ifndef MNG_NO_16BIT_SUPPORT + if (pData->bIsRGBA16) /* 16-bit buffer ? */ + { + pTemp = pData->pPrevrow + (iX << 3); + + for (iZ = (pData->iDestr - pData->iDestl); iZ > 0; iZ--) + { + MNG_COPY (pWork, pTemp, 8); + + pWork += 8; + pTemp += 8; + iX++; + /* reached end of bkgd-image line ? */ + if (iX >= pData->iBackimgwidth) + { + iX = 0; + pTemp = pData->pPrevrow; + } + } + } + else +#endif + { + pTemp = pData->pPrevrow + (iX << 2); + + for (iZ = (pData->iDestr - pData->iDestl); iZ > 0; iZ--) + { + MNG_COPY (pWork, pTemp, 4); + + pWork += 4; + pTemp += 4; + iX++; + /* reached end of bkgd-image line ? */ + if (iX >= pData->iBackimgwidth) + { + iX = 0; + pTemp = pData->pPrevrow; + } + } + } + + pData->pRGBArow = pRGBArow; /* restore original values */ + pData->iRow = iRow; + pData->iRowsamples = iRowsamples; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_BACKIMAGE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_restore_bkgd_backcolor (mng_datap pData) +{ + mng_int32 iX; + mng_uint32p pWork32 = (mng_uint32p)pData->pRGBArow; + mng_uint32 iWrite; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_BACKCOLOR, MNG_LC_START); +#endif + +#ifdef MNG_BIGENDIAN_SUPPORTED + /* fast way for big endian */ + iWrite = (((mng_uint8)(pData->iBACKred >> 8)) << 24) | + (((mng_uint8)(pData->iBACKgreen >> 8)) << 16) | + (((mng_uint8)(pData->iBACKblue >> 8)) << 8) | + ( 0xFF ); +#elif defined(MNG_LITTLEENDIAN_SUPPORTED) + /* fast way for little endian */ + iWrite = ( 0xFF << 24) | + (((mng_uint8)(pData->iBACKblue >> 8)) << 16) | + (((mng_uint8)(pData->iBACKgreen >> 8)) << 8) | + (((mng_uint8)(pData->iBACKred >> 8)) ); +#else + /* generic way, works on all platforms */ + /* put the data in memory in the correct order */ + { + mng_uint8 aBytes[4]; + aBytes[0] = (mng_uint8)(pData->iBACKred >> 8); + aBytes[1] = (mng_uint8)(pData->iBACKgreen >> 8); + aBytes[2] = (mng_uint8)(pData->iBACKblue >> 8); + aBytes[3] = 0xFF; + /* load that data into a register */ + iWrite = *(mng_uint32*) aBytes; + } +#endif + /* ok; drop the background-color in there */ + for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) + *pWork32++ = iWrite; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_BACKCOLOR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_bKGD +mng_retcode mng_restore_bkgd_bkgd (mng_datap pData) +{ + mng_int32 iX; + mng_uint8p pWork = pData->pRGBArow; + mng_imagep pImage = (mng_imagep)pData->pCurrentobj; + mng_imagedatap pBuf = pImage->pImgbuf; + mng_uint8 iRed = 0; + mng_uint8 iGreen = 0; + mng_uint8 iBlue = 0; + mng_uint32p pWork32 = (mng_uint32p)pWork; + mng_uint32 iWrite; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_BKGD, MNG_LC_START); +#endif + + switch (pBuf->iColortype) + { + case 0 : ; /* gray types */ + case 4 : { + mng_uint8 iGray; + +#ifndef MNG_NO_16BIT_SUPPORT + if (pBuf->iBitdepth > 8) + iGray = (mng_uint8)(pBuf->iBKGDgray >> 8); + else +#endif + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + /* LBR scaling */ + mng_uint8 multiplier[]={0,255,85,0,17,0,0,0,1}; + iGray = (mng_uint8)(multiplier[pBuf->iBitdepth] * pBuf->iBKGDgray); +#else + iGray = (mng_uint8)pBuf->iBKGDgray; +#endif + } + + iRed = iGray; + iGreen = iGray; + iBlue = iGray; + + break; + } + + case 3 : { /* indexed type */ + iRed = pBuf->aPLTEentries [pBuf->iBKGDindex].iRed; + iGreen = pBuf->aPLTEentries [pBuf->iBKGDindex].iGreen; + iBlue = pBuf->aPLTEentries [pBuf->iBKGDindex].iBlue; + + break; + } + + case 2 : ; /* rgb types */ + case 6 : { +#ifndef MNG_NO_16BIT_SUPPORT + if (pBuf->iBitdepth > 8) + { + iRed = (mng_uint8)(pBuf->iBKGDred >> 8); + iGreen = (mng_uint8)(pBuf->iBKGDgreen >> 8); + iBlue = (mng_uint8)(pBuf->iBKGDblue >> 8); + } + else +#endif + { + iRed = (mng_uint8)(pBuf->iBKGDred ); + iGreen = (mng_uint8)(pBuf->iBKGDgreen); + iBlue = (mng_uint8)(pBuf->iBKGDblue ); + } + + break; + } + } + +#ifdef MNG_BIGENDIAN_SUPPORTED + /* fast way for big endian */ + iWrite = (iRed << 24) | + (iGreen << 16) | + (iBlue << 8); +#elif defined(MNG_LITTLEENDIAN_SUPPORTED) + /* fast way for little endian */ + iWrite = (iBlue << 16) | + (iGreen << 8) | + (iRed ); +#else + /* generic way, works on all platforms */ + /* put the data in memory in the correct order */ + { + mng_uint8 aBytes[4]; + aBytes[0] = (mng_uint8)(iRed); + aBytes[1] = (mng_uint8)(iGreen); + aBytes[2] = (mng_uint8)(iBlue); + aBytes[3] = 0x00; + /* load that data into a register */ + iWrite = *(mng_uint32*) aBytes; + } +#endif + /* ok; drop it in there */ + for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) + *pWork32++ = iWrite; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_BKGD, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_restore_bkgd_bgcolor (mng_datap pData) +{ + mng_int32 iX; + mng_uint32p pWork32 = (mng_uint32p)pData->pRGBArow; + mng_uint32 iWrite; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_BGCOLOR, MNG_LC_START); +#endif + +#ifdef MNG_BIGENDIAN_SUPPORTED + /* fast way for big endian */ + iWrite = (((mng_uint8)(pData->iBGred >> 8)) << 24) | + (((mng_uint8)(pData->iBGgreen >> 8)) << 16) | + (((mng_uint8)(pData->iBGblue >> 8)) << 8); +#elif defined(MNG_LITTLEENDIAN_SUPPORTED) + /* fast way for little endian */ + iWrite = (((mng_uint8)(pData->iBGblue >> 8)) << 16) | + (((mng_uint8)(pData->iBGgreen >> 8)) << 8) | + (((mng_uint8)(pData->iBGred >> 8)) ); +#else + /* generic way, works on all platforms */ + /* put the data in memory in the correct order */ + { + mng_uint8 aBytes[4]; + aBytes[0] = (mng_uint8)(pData->iBGred >> 8); + aBytes[1] = (mng_uint8)(pData->iBGgreen >> 8); + aBytes[2] = (mng_uint8)(pData->iBGblue >> 8); + aBytes[3] = 0x00; + /* load that data into a register */ + iWrite = *(mng_uint32*) aBytes; + } +#endif + /* ok; drop the background-color in there */ + for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) + *pWork32++ = iWrite; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_BGCOLOR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_RGB8 +mng_retcode mng_restore_bkgd_rgb8 (mng_datap pData) +{ + mng_int32 iX; + mng_uint8p pBkgd; + mng_uint8p pWork = pData->pRGBArow; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_RGB8, MNG_LC_START); +#endif + + if (pData->fGetbkgdline) /* can we access the background ? */ + { /* point to the right pixel then */ + pBkgd = (mng_uint8p)pData->fGetbkgdline ((mng_handle)pData, + pData->iRow + pData->iDestt) + + (3 * pData->iDestl); + + for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) + { + *pWork = *pBkgd; /* ok; copy the pixel */ + *(pWork+1) = *(pBkgd+1); + *(pWork+2) = *(pBkgd+2); + *(pWork+3) = 0x00; /* transparant for alpha-canvasses */ + + pWork += 4; + pBkgd += 3; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_RGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SKIPCANVAS_RGB8 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_BGR8 +mng_retcode mng_restore_bkgd_bgr8 (mng_datap pData) +{ + mng_int32 iX; + mng_uint8p pBkgd; + mng_uint8p pWork = pData->pRGBArow; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_BGR8, MNG_LC_START); +#endif + + if (pData->fGetbkgdline) /* can we access the background ? */ + { /* point to the right pixel then */ + pBkgd = (mng_uint8p)pData->fGetbkgdline ((mng_handle)pData, + pData->iRow + pData->iDestt) + + (3 * pData->iDestl); + + for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) + { + *pWork = *(pBkgd+2); /* ok; copy the pixel */ + *(pWork+1) = *(pBkgd+1); + *(pWork+2) = *pBkgd; + *(pWork+3) = 0x00; /* transparant for alpha-canvasses */ + + pWork += 4; + pBkgd += 3; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_BGR8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SKIPCANVAS_BGR8 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_BGRX8 +mng_retcode mng_restore_bkgd_bgrx8 (mng_datap pData) +{ + mng_int32 iX; + mng_uint8p pBkgd; + mng_uint8p pWork = pData->pRGBArow; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_BGRX8, MNG_LC_START); +#endif + + if (pData->fGetbkgdline) /* can we access the background ? */ + { /* point to the right pixel then */ + pBkgd = (mng_uint8p)pData->fGetbkgdline ((mng_handle)pData, + pData->iRow + pData->iDestt) + + (3 * pData->iDestl); + + for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) + { + *pWork = *(pBkgd+2); /* ok; copy the pixel */ + *(pWork+1) = *(pBkgd+1); + *(pWork+2) = *pBkgd; + *(pWork+3) = 0x00; /* transparant for alpha-canvasses */ + + pWork += 4; + pBkgd += 4; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_BGRX8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SKIPCANVAS_BGRX8 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_BGR565 +mng_retcode mng_restore_bkgd_bgr565 (mng_datap pData) +{ + mng_int32 iX; + mng_uint8p pBkgd; + mng_uint8p pWork = pData->pRGBArow; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_BGR565, MNG_LC_START); +#endif + + if (pData->fGetbkgdline) /* can we access the background ? */ + { /* point to the right pixel then */ + pBkgd = (mng_uint8p)pData->fGetbkgdline ((mng_handle)pData, + pData->iRow + pData->iDestt) + + (3 * pData->iDestl); + + for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) + { + *pWork = (mng_uint8)( *(pBkgd+1) & 0xF8); /* ok; copy the pixel */ + *(pWork+1) = (mng_uint8)( (*(pBkgd+1) << 5 ) | ( ((*pBkgd)&0xE0)>>3 ) ); + *(pWork+2) = (mng_uint8)( *(pBkgd) << 3 ); + *(pWork+3) = 0x00; /* transparant for alpha-canvasses */ + + pWork += 4; + pBkgd += 2; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_BGR565, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SKIPCANVAS_BGR565 */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCANVAS_RGB565 +mng_retcode mng_restore_bkgd_rgb565 (mng_datap pData) +{ + mng_int32 iX; + mng_uint8p pBkgd; + mng_uint8p pWork = pData->pRGBArow; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_RGB565, MNG_LC_START); +#endif + + if (pData->fGetbkgdline) /* can we access the background ? */ + { /* point to the right pixel then */ + pBkgd = (mng_uint8p)pData->fGetbkgdline ((mng_handle)pData, + pData->iRow + pData->iDestt) + + (3 * pData->iDestl); + + for (iX = (pData->iSourcer - pData->iSourcel); iX > 0; iX--) + { + *pWork = (mng_uint8)( *(pBkgd)&0xF8); /* ok; copy the pixel */ + *(pWork+1) = (mng_uint8)( (*(pBkgd+1) << 5) | ( ((*pBkgd)&0xE0)>>3 ) ); + *(pWork+2) = (mng_uint8)( *(pBkgd+1) << 3); + *(pWork+3) = 0x00; /* transparant for alpha-canvasses */ + + pWork += 4; + pBkgd += 2; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RESTORE_RGB565, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SKIPCANVAS_RBB565 */ + + +/* ************************************************************************** */ +/* * * */ +/* * Row retrieval routines - retrieve processed & uncompressed row-data * */ +/* * from the current "object" * */ +/* * * */ +/* ************************************************************************** */ + +/* TODO: a serious optimization is to retrieve only those pixels that will + actually be displayed; this would require changes in + the "display_image" routine (in mng_display.c) & + all the "retrieve_xxx" routines below & + the "display_xxx" routines above !!!!! + NOTE that "correct_xxx" routines would not require modification */ + +mng_retcode mng_retrieve_g8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint8 iG; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_G8, MNG_LC_START); +#endif + + pRGBArow = pData->pRGBArow; /* temporary work pointers */ + pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); + + if (pBuf->bHasTRNS) /* tRNS in buffer ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iG = *pWorkrow; /* get the gray-value */ + /* is it transparent ? */ + if ((mng_uint16)iG == pBuf->iTRNSgray) + { + *pRGBArow = 0x00; /* nuttin to display */ + *(pRGBArow+1) = 0x00; + *(pRGBArow+2) = 0x00; + *(pRGBArow+3) = 0x00; + } + else + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + mng_uint8 multiplier[]={0,255,85,0,17,0,0,0,1}; + iG = (mng_uint8)(iG * multiplier[pBuf->iBitdepth]); +#endif + + *pRGBArow = iG; /* put in intermediate row */ + *(pRGBArow+1) = iG; + *(pRGBArow+2) = iG; + *(pRGBArow+3) = 0xFF; + } + + pWorkrow++; /* next pixel */ + pRGBArow += 4; + } + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + mng_uint8 multiplier[]={0,255,85,0,17,0,0,0,1}; /* LBR scaling */ + iG = (mng_uint8)(multiplier[pBuf->iBitdepth] * *pWorkrow); +#else + iG = *pWorkrow; /* get the gray-value */ +#endif + + *pRGBArow = iG; /* put in intermediate row */ + *(pRGBArow+1) = iG; + *(pRGBArow+2) = iG; + *(pRGBArow+3) = 0xFF; + + pWorkrow++; /* next pixel */ + pRGBArow += 4; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_G8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_retrieve_g16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint16 iG; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_G16, MNG_LC_START); +#endif + /* temporary work pointers */ + pRGBArow = pData->pRGBArow; + pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); + + if (pBuf->bHasTRNS) /* tRNS in buffer ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iG = mng_get_uint16 (pWorkrow); /* get the gray-value */ + /* is it transparent ? */ + if (iG == pBuf->iTRNSgray) + { /* nuttin to display */ + mng_put_uint16 (pRGBArow, 0x0000); + mng_put_uint16 (pRGBArow+2, 0x0000); + mng_put_uint16 (pRGBArow+4, 0x0000); + mng_put_uint16 (pRGBArow+6, 0x0000); + } + else + { /* put in intermediate row */ + mng_put_uint16 (pRGBArow, iG); + mng_put_uint16 (pRGBArow+2, iG); + mng_put_uint16 (pRGBArow+4, iG); + mng_put_uint16 (pRGBArow+6, 0xFFFF); + } + + pWorkrow += 2; /* next pixel */ + pRGBArow += 8; + } + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iG = mng_get_uint16 (pWorkrow); /* get the gray-value */ + + mng_put_uint16 (pRGBArow, iG); /* and put in intermediate row */ + mng_put_uint16 (pRGBArow+2, iG); + mng_put_uint16 (pRGBArow+4, iG); + mng_put_uint16 (pRGBArow+6, 0xFFFF); + + pWorkrow += 2; /* next pixel */ + pRGBArow += 8; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_G16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_retrieve_rgb8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint8 iR, iG, iB; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_RGB8, MNG_LC_START); +#endif + + pRGBArow = pData->pRGBArow; /* temporary work pointers */ + pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); + + if (pBuf->bHasTRNS) /* tRNS in buffer ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iR = *pWorkrow; /* get the rgb-values */ + iG = *(pWorkrow+1); + iB = *(pWorkrow+2); + /* is it transparent ? */ + if (((mng_uint16)iR == pBuf->iTRNSred ) && + ((mng_uint16)iG == pBuf->iTRNSgreen) && + ((mng_uint16)iB == pBuf->iTRNSblue ) ) + { + *pRGBArow = 0x00; /* nothing to display */ + *(pRGBArow+1) = 0x00; + *(pRGBArow+2) = 0x00; + *(pRGBArow+3) = 0x00; + } + else + { + *pRGBArow = iR; /* put in intermediate row */ + *(pRGBArow+1) = iG; + *(pRGBArow+2) = iB; + *(pRGBArow+3) = 0xFF; + } + + pWorkrow += 3; /* next pixel */ + pRGBArow += 4; + } + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pRGBArow = *pWorkrow; /* just copy the pixel */ + *(pRGBArow+1) = *(pWorkrow+1); + *(pRGBArow+2) = *(pWorkrow+2); + *(pRGBArow+3) = 0xFF; + + pWorkrow += 3; /* next pixel */ + pRGBArow += 4; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_RGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_retrieve_rgb16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint16 iR, iG, iB; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_RGB16, MNG_LC_START); +#endif + /* temporary work pointers */ + pRGBArow = pData->pRGBArow; + pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); + + if (pBuf->bHasTRNS) /* tRNS in buffer ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iR = mng_get_uint16 (pWorkrow); /* get the rgb-values */ + iG = mng_get_uint16 (pWorkrow+2); + iB = mng_get_uint16 (pWorkrow+4); + /* is it transparent ? */ + if ((iR == pBuf->iTRNSred ) && + (iG == pBuf->iTRNSgreen) && + (iB == pBuf->iTRNSblue ) ) + { /* nothing to display */ + mng_put_uint16 (pRGBArow, 0x0000); + mng_put_uint16 (pRGBArow+2, 0x0000); + mng_put_uint16 (pRGBArow+4, 0x0000); + mng_put_uint16 (pRGBArow+6, 0x0000); + } + else + { /* put in intermediate row */ + mng_put_uint16 (pRGBArow, iR); + mng_put_uint16 (pRGBArow+2, iG); + mng_put_uint16 (pRGBArow+4, iB); + mng_put_uint16 (pRGBArow+6, 0xFFFF); + } + + pWorkrow += 6; /* next pixel */ + pRGBArow += 8; + } + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* just copy the pixel */ + mng_put_uint16 (pRGBArow, mng_get_uint16 (pWorkrow )); + mng_put_uint16 (pRGBArow+2, mng_get_uint16 (pWorkrow+2)); + mng_put_uint16 (pRGBArow+4, mng_get_uint16 (pWorkrow+4)); + mng_put_uint16 (pRGBArow+6, 0xFFFF); + + pWorkrow += 6; /* next pixel */ + pRGBArow += 8; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_RGB16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_retrieve_idx8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint8 iQ; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_IDX8, MNG_LC_START); +#endif + + pRGBArow = pData->pRGBArow; /* temporary work pointers */ + pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); + + if (pBuf->bHasTRNS) /* tRNS in buffer ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iQ = *pWorkrow; /* get the index */ + /* is it valid ? */ + if ((mng_uint32)iQ < pBuf->iPLTEcount) + { /* put in intermediate row */ + *pRGBArow = pBuf->aPLTEentries [iQ].iRed; + *(pRGBArow+1) = pBuf->aPLTEentries [iQ].iGreen; + *(pRGBArow+2) = pBuf->aPLTEentries [iQ].iBlue; + /* transparency for this index ? */ + if ((mng_uint32)iQ < pBuf->iTRNScount) + *(pRGBArow+3) = pBuf->aTRNSentries [iQ]; + else + *(pRGBArow+3) = 0xFF; + } + else + MNG_ERROR (pData, MNG_PLTEINDEXERROR); + + pWorkrow++; /* next pixel */ + pRGBArow += 4; + } + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iQ = *pWorkrow; /* get the index */ + /* is it valid ? */ + if ((mng_uint32)iQ < pBuf->iPLTEcount) + { /* put in intermediate row */ + *pRGBArow = pBuf->aPLTEentries [iQ].iRed; + *(pRGBArow+1) = pBuf->aPLTEentries [iQ].iGreen; + *(pRGBArow+2) = pBuf->aPLTEentries [iQ].iBlue; + *(pRGBArow+3) = 0xFF; + } + else + MNG_ERROR (pData, MNG_PLTEINDEXERROR); + + pWorkrow++; /* next pixel */ + pRGBArow += 4; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_IDX8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_retrieve_ga8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint8 iG; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_GA8, MNG_LC_START); +#endif + + pRGBArow = pData->pRGBArow; /* temporary work pointers */ + pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iG = *pWorkrow; /* get the gray-value */ + *pRGBArow = iG; /* put in intermediate row */ + *(pRGBArow+1) = iG; + *(pRGBArow+2) = iG; + *(pRGBArow+3) = *(pWorkrow+1); + + pWorkrow += 2; /* next pixel */ + pRGBArow += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_GA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_retrieve_ga16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint16 iG; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_GA16, MNG_LC_START); +#endif + /* temporary work pointers */ + pRGBArow = pData->pRGBArow; + pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iG = mng_get_uint16 (pWorkrow); /* get the gray-value */ + + mng_put_uint16 (pRGBArow, iG); /* and put in intermediate row */ + mng_put_uint16 (pRGBArow+2, iG); + mng_put_uint16 (pRGBArow+4, iG); + mng_put_uint16 (pRGBArow+6, mng_get_uint16 (pWorkrow+2)); + + pWorkrow += 4; /* next pixel */ + pRGBArow += 8; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_GA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_retrieve_rgba8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_RGBA8, MNG_LC_START); +#endif + + pRGBArow = pData->pRGBArow; /* temporary work pointers */ + pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); + /* can't be easier than this ! */ + MNG_COPY (pRGBArow, pWorkrow, pBuf->iRowsize); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_retrieve_rgba16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_RGBA16, MNG_LC_START); +#endif + /* temporary work pointers */ + pRGBArow = pData->pRGBArow; + pWorkrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize); + /* can't be easier than this ! */ + MNG_COPY (pRGBArow, pWorkrow, pBuf->iRowsize); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RETRIEVE_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ +/* * * */ +/* * Row storage routines - store processed & uncompressed row-data * */ +/* * into the current "object" * */ +/* * * */ +/* ************************************************************************** */ + +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_retcode mng_store_g1 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_G1, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + iM = 0; /* start at pixel 0 */ + iB = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0x80; + } + + if (iB & iM) /* is it white ? */ + *pOutrow = 0x01; /* white */ + else + *pOutrow = 0x00; /* black */ + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 1; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_G1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_store_g2 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + mng_uint8 iQ; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_G2, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xC0; + iS = 6; + } + + iQ = (mng_uint8)((iB & iM) >> iS); /* get the gray level */ + *pOutrow = iQ; /* put in object buffer */ + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 2; + iS -= 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_G2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_store_g4 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + mng_uint8 iQ; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_G4, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xF0; + iS = 4; + } + + iQ = (mng_uint8)((iB & iM) >> iS); /* get the gray level */ + *pOutrow = iQ; /* put in object buffer */ + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 4; + iS -= 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_G4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_store_g8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_G8, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* put in object buffer */ + + pOutrow += pData->iColinc; /* next pixel */ + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_G8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_store_g16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_G16, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* copy into object buffer */ + mng_put_uint16 (pOutrow, mng_get_uint16 (pWorkrow)); + + pOutrow += (pData->iColinc << 1); /* next pixel */ + pWorkrow += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_G16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_store_rgb8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_RGB8, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* copy the RGB bytes */ + *(pOutrow+1) = *(pWorkrow+1); + *(pOutrow+2) = *(pWorkrow+2); + + pWorkrow += 3; /* next pixel */ + pOutrow += (pData->iColinc * 3); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_RGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_store_rgb16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_RGB16, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + MNG_COPY (pOutrow, pWorkrow, 6); /* copy the RGB bytes */ + + pWorkrow += 6; /* next pixel */ + pOutrow += (pData->iColinc * 6); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_RGB16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_retcode mng_store_idx1 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_IDX1, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + iM = 0; /* start at pixel 0 */ + iB = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0x80; + } + + if (iB & iM) /* store the index */ + *pOutrow = 0x01; + else + *pOutrow = 0x00; + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 1; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_IDX1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_store_idx2 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_IDX2, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xC0; + iS = 6; + } + /* store the index */ + *pOutrow = (mng_uint8)((iB & iM) >> iS); + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 2; + iS -= 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_IDX2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_store_idx4 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_IDX4, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xF0; + iS = 4; + } + /* store the index */ + *pOutrow = (mng_uint8)((iB & iM) >> iS); + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 4; + iS -= 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_IDX4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_store_idx8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_IDX8, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* put in object buffer */ + + pOutrow += pData->iColinc; /* next pixel */ + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_IDX8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_store_ga8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_GA8, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* copy the GA bytes */ + *(pOutrow+1) = *(pWorkrow+1); + + pWorkrow += 2; /* next pixel */ + pOutrow += (pData->iColinc << 1); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_GA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_store_ga16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_GA16, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + MNG_COPY (pOutrow, pWorkrow, 4); /* copy the GA bytes */ + + pWorkrow += 4; /* next pixel */ + pOutrow += (pData->iColinc << 2); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_GA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_store_rgba8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_RGBA8, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* copy the RGBA bytes */ + *(pOutrow+1) = *(pWorkrow+1); + *(pOutrow+2) = *(pWorkrow+2); + *(pOutrow+3) = *(pWorkrow+3); + + pWorkrow += 4; /* next pixel */ + pOutrow += (pData->iColinc << 2); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_store_rgba16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_RGBA16, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + MNG_COPY (pOutrow, pWorkrow, 8); /* copy the RGBA bytes */ + + pWorkrow += 8; /* next pixel */ + pOutrow += (pData->iColinc << 3); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ +/* * * */ +/* * Row storage routines (JPEG) - store processed & uncompressed row-data * */ +/* * into the current "object" * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG + +/* ************************************************************************** */ + +mng_retcode mng_store_jpeg_g8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8, MNG_LC_START); +#endif + + pWorkrow = pData->pJPEGrow; /* temporary work pointers */ + pOutrow = pBuf->pImgdata + (pData->iJPEGrow * pBuf->iRowsize); + /* easy as pie ... */ + MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8, MNG_LC_END); +#endif + + return mng_next_jpeg_row (pData); /* we've got one more row of gray-samples */ +} + +/* ************************************************************************** */ + +mng_retcode mng_store_jpeg_rgb8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; +#if RGB_PIXELSIZE != 3 + mng_int32 iX; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8, MNG_LC_START); +#endif + + pWorkrow = pData->pJPEGrow; /* temporary work pointers */ + pOutrow = pBuf->pImgdata + (pData->iJPEGrow * pBuf->iRowsize); + +#if RGB_PIXELSIZE == 3 + /* easy as pie ... */ + MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples * 3); +#else +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* copy pixel into object buffer */ + *(pOutrow+1) = *(pWorkrow+1); + *(pOutrow+2) = *(pWorkrow+2); + + pOutrow += 3; /* next pixel */ + pWorkrow += RGB_PIXELSIZE; + } +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8, MNG_LC_END); +#endif + + return mng_next_jpeg_row (pData); /* we've got one more row of rgb-samples */ +} + +/* ************************************************************************** */ + +mng_retcode mng_store_jpeg_ga8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_GA8, MNG_LC_START); +#endif + + pWorkrow = pData->pJPEGrow; /* temporary work pointers */ + pOutrow = pBuf->pImgdata + (pData->iJPEGrow * pBuf->iRowsize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* copy into object buffer */ + + pOutrow += 2; /* next pixel */ + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_GA8, MNG_LC_END); +#endif + + return mng_next_jpeg_row (pData); /* we've got one more row of gray-samples */ +} + +/* ************************************************************************** */ + +mng_retcode mng_store_jpeg_rgba8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGBA8, MNG_LC_START); +#endif + + pWorkrow = pData->pJPEGrow; /* temporary work pointers */ + pOutrow = pBuf->pImgdata + (pData->iJPEGrow * pBuf->iRowsize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* copy pixel into object buffer */ + *(pOutrow+1) = *(pWorkrow+1); + *(pOutrow+2) = *(pWorkrow+2); + + pOutrow += 4; /* next pixel */ + pWorkrow += RGB_PIXELSIZE; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGBA8, MNG_LC_END); +#endif + + return mng_next_jpeg_row (pData); /* we've got one more row of rgb-samples */ +} + +/* ************************************************************************** */ + +mng_retcode mng_store_jpeg_g8_alpha (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_ALPHA, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pJPEGrow2; + pOutrow = pBuf->pImgdata + (pData->iJPEGalpharow * pBuf->iRowsize) + 1; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* put in object buffer */ + + pOutrow += 2; /* next pixel */ + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_ALPHA, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_store_jpeg_rgb8_alpha (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_ALPHA, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pJPEGrow2; + pOutrow = pBuf->pImgdata + (pData->iJPEGalpharow * pBuf->iRowsize) + 3; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* put in object buffer */ + + pOutrow += 4; /* next pixel */ + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_ALPHA, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_retcode mng_store_jpeg_g8_a1 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A1, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 1; + iM = 0; /* start at pixel 0 */ + iB = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0x80; + } + + if (iB & iM) /* is it opaque ? */ + *pOutrow = 0xFF; /* opaque */ + else + *pOutrow = 0x00; /* transparent */ + + pOutrow += 2; /* next pixel */ + iM >>= 1; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A1, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_store_jpeg_g8_a2 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A2, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 1; + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xC0; + iS = 6; + } + +#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH + { + const mng_uint8 alpha_level[4] = { 0x00, 0x55, 0xAA, 0xFF}; + *pOutrow = alpha_level[((iB & iM) >> iS)] ; + } +#else + switch ((iB & iM) >> iS) /* determine the alpha level */ + { + case 0x03 : { *pOutrow = 0xFF; break; } + case 0x02 : { *pOutrow = 0xAA; break; } + case 0x01 : { *pOutrow = 0x55; break; } + default : { *pOutrow = 0x00; } + } +#endif + + pOutrow += 2; /* next pixel */ + iM >>= 2; + iS -= 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A2, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_store_jpeg_g8_a4 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + mng_uint8 iQ; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A4, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 1; + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xF0; + iS = 4; + } + /* get the alpha level */ + iQ = (mng_uint8)((iB & iM) >> iS); + iQ = (mng_uint8)(iQ + (iQ << 4)); /* expand to 8-bit by replication */ + + *pOutrow = iQ; /* put in object buffer */ + + pOutrow += 2; /* next pixel */ + iM >>= 4; + iS -= 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A4, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_store_jpeg_g8_a8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A8, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 1; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* put in object buffer */ + + pOutrow += 2; /* next pixel */ + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A8, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_store_jpeg_g8_a16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A16, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 1; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* only high-order byte! */ + + pOutrow += 2; /* next pixel */ + pWorkrow += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G8_A16, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_retcode mng_store_jpeg_rgb8_a1 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A1, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 3; + iM = 0; /* start at pixel 0 */ + iB = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0x80; + } + + if (iB & iM) /* is it opaque ? */ + *pOutrow = 0xFF; /* opaque */ + else + *pOutrow = 0x00; /* transparent */ + + pOutrow += 4; /* next pixel */ + iM >>= 1; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A1, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_store_jpeg_rgb8_a2 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A2, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 3; + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xC0; + iS = 6; + } + +#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH + { + const mng_uint8 alpha_level[4] = { 0x00, 0x55, 0xAA, 0xFF}; + *pOutrow = alpha_level[((iB & iM) >> iS)] ; + } +#else + switch ((iB & iM) >> iS) /* determine the alpha level */ + { + case 0x03 : { *pOutrow = 0xFF; break; } + case 0x02 : { *pOutrow = 0xAA; break; } + case 0x01 : { *pOutrow = 0x55; break; } + default : { *pOutrow = 0x00; } + } +#endif + + pOutrow += 4; /* next pixel */ + iM >>= 2; + iS -= 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A2, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_store_jpeg_rgb8_a4 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + mng_uint8 iQ; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A4, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 3; + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xF0; + iS = 4; + } + /* get the alpha level */ + iQ = (mng_uint8)((iB & iM) >> iS); + iQ = (mng_uint8)(iQ + (iQ << 4)); /* expand to 8-bit by replication */ + + *pOutrow = iQ; /* put in object buffer */ + + pOutrow += 4; /* next pixel */ + iM >>= 4; + iS -= 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A4, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_store_jpeg_rgb8_a8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A8, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 3; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* put in buffer */ + + pOutrow += 4; /* next pixel */ + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A8, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_store_jpeg_rgb8_a16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A16, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 3; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* only high-order byte */ + + pOutrow += 4; /* next pixel */ + pWorkrow += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_RGB8_A16, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_JPEG12 +mng_retcode mng_store_jpeg_g12_a1 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A1, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 2; + iM = 0; /* start at pixel 0 */ + iB = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0x80; + } + + if (iB & iM) /* opaque ? */ + mng_put_uint16 (pOutrow, 0xFFFF);/* opaque */ + else + mng_put_uint16 (pOutrow, 0x0000);/* transparent */ + + pOutrow += 4; /* next pixel */ + iM >>= 1; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A1, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} +#endif /* MNG_SUPPORT_JPEG12 */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_JPEG12 +mng_retcode mng_store_jpeg_g12_a2 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A2, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 2; + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xC0; + iS = 6; + } + +#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH + { + const mng_uint16 gray_level[4] = { 0x0000, 0x5555, 0xAAAA, 0xFFFF}; + mng_put_uint16 (pOutrow, gray_level[((iB & iM) >> iS)]) ; + } +#else + switch ((iB & iM) >> iS) /* determine the gray level */ + { + case 0x03 : { mng_put_uint16 (pOutrow, 0xFFFF); break; } + case 0x02 : { mng_put_uint16 (pOutrow, 0xAAAA); break; } + case 0x01 : { mng_put_uint16 (pOutrow, 0x5555); break; } + default : { mng_put_uint16 (pOutrow, 0x0000); } + } +#endif + + pOutrow += 4; /* next pixel */ + iM >>= 2; + iS -= 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A2, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} +#endif /* MNG_SUPPORT_JPEG12 */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_JPEG12 +mng_retcode mng_store_jpeg_g12_a4 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + mng_uint16 iQ; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A4, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 2; + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xF0; + iS = 4; + } + /* get the gray level */ + iQ = (mng_uint16)((iB & iM) >> iS); + iQ = (mng_uint16)(iQ + (iQ << 4)); /* expand to 16-bit by replication */ + iQ = (mng_uint16)(iQ + (iQ << 8)); + /* put in object buffer */ + mng_put_uint16 (pOutrow, iQ); + + pOutrow += 4; /* next pixel */ + iM >>= 4; + iS -= 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A4, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} +#endif /* MNG_SUPPORT_JPEG12 */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_JPEG12 +mng_retcode mng_store_jpeg_g12_a8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint16 iW; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A8, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 2; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iW = (mng_uint16)(*pWorkrow); /* get input byte */ + iW = (mng_uint16)(iW + (iW << 8)); /* expand to 16-bit by replication */ + + mng_put_uint16 (pOutrow, iW); /* put in object buffer */ + + pOutrow += 4; /* next pixel */ + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A8, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} +#endif /* MNG_SUPPORT_JPEG12 */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_JPEG12 +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_store_jpeg_g12_a16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A16, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 2; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* copy it */ + mng_put_uint16 (pOutrow, mng_get_uint16 (pWorkrow)); + + pOutrow += 4; /* next pixel */ + pWorkrow += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_STORE_JPEG_G12_A16, MNG_LC_END); +#endif + /* we've got one more row of alpha-samples */ + return mng_next_jpeg_alpharow (pData); +} +#endif +#endif /* MNG_SUPPORT_JPEG12 */ + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_JNG */ + +#ifndef MNG_NO_DELTA_PNG +/* ************************************************************************** */ +/* * * */ +/* * Delta-image row routines - apply the processed & uncompressed row-data * */ +/* * onto the target "object" * */ +/* * * */ +/* ************************************************************************** */ + +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_retcode mng_delta_g1 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G1, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + iM = 0; /* start at pixel 0 */ + iB = 0; + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0x80; + } + + if (iB & iM) /* is it white ? */ + *pOutrow = 0xFF; /* white */ + else + *pOutrow = 0x00; /* black */ + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 1; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0x80; + } + + if (iB & iM) /* invert if it is white ? */ + *pOutrow = (mng_uint8)(*pOutrow ^ 0xFF); + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 1; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G1, MNG_LC_END); +#endif + + return mng_store_g1 (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_delta_g2 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; +#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH + const mng_uint8 level[4] = { 0x00, 0x55, 0xAA, 0xFF}; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G2, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xC0; + iS = 6; + } + +#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH + *pOutrow = level[((iB & iM) >> iS)] ; +#else + switch ((iB & iM) >> iS) /* determine the alpha level */ + { + case 0x03 : { *pOutrow = 0xFF; break; } + case 0x02 : { *pOutrow = 0xAA; break; } + case 0x01 : { *pOutrow = 0x55; break; } + default : { *pOutrow = 0x00; } + } +#endif + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 2; + iS -= 2; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xC0; + iS = 6; + } + +#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH + *pOutrow = level[((*pOutrow >> 6) + ((iB & iM) >> iS)) & 0x03] ; +#else + switch (((*pOutrow >> 6) + ((iB & iM) >> iS)) & 0x03) + { + case 0x03 : { *pOutrow = 0xFF; break; } + case 0x02 : { *pOutrow = 0xAA; break; } + case 0x01 : { *pOutrow = 0x55; break; } + default : { *pOutrow = 0x00; } + } +#endif + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 2; + iS -= 2; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G2, MNG_LC_END); +#endif + + return mng_store_g2 (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_delta_g4 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + mng_uint8 iQ; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G4, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xF0; + iS = 4; + } + /* get the gray level */ + iQ = (mng_uint8)((iB & iM) >> iS); + /* expand to 8-bit by replication */ + iQ = (mng_uint8)(iQ + (iQ << 4)); + + *pOutrow = iQ; /* put in object buffer */ + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 4; + iS -= 4; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xF0; + iS = 4; + } + /* get the gray level */ + iQ = (mng_uint8)(((*pOutrow >> 4) + ((iB & iM) >> iS)) & 0x0F); + /* expand to 8-bit by replication */ + iQ = (mng_uint8)(iQ + (iQ << 4)); + + *pOutrow = iQ; /* put in object buffer */ + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 4; + iS -= 4; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G4, MNG_LC_END); +#endif + + return mng_store_g4 (pData); +} +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + +/* ************************************************************************** */ + +mng_retcode mng_delta_g8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G8, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* put in object buffer */ + + pOutrow += pData->iColinc; /* next pixel */ + pWorkrow++; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* add to object buffer */ + *pOutrow = (mng_uint8)(*pOutrow + *pWorkrow); + + pOutrow += pData->iColinc; /* next pixel */ + pWorkrow++; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G8, MNG_LC_END); +#endif + + return mng_store_g8 (pData); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_delta_g16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G16, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* put in object buffer */ + *(pOutrow+1) = *(pWorkrow+1); + /* next pixel */ + pOutrow += (pData->iColinc << 1); + pWorkrow += 2; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* add to object buffer */ + mng_put_uint16 (pOutrow, (mng_uint16)(mng_get_uint16 (pOutrow ) + + mng_get_uint16 (pWorkrow) )); + /* next pixel */ + pOutrow += (pData->iColinc << 1); + pWorkrow += 2; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G16, MNG_LC_END); +#endif + + return mng_store_g16 (pData); +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_delta_rgb8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGB8, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* put in object buffer */ + *(pOutrow+1) = *(pWorkrow+1); + *(pOutrow+2) = *(pWorkrow+2); + /* next pixel */ + pOutrow += (pData->iColinc * 3); + pWorkrow += 3; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* add to object buffer */ + *pOutrow = (mng_uint8)(*pOutrow + *pWorkrow ); + *(pOutrow+1) = (mng_uint8)(*(pOutrow+1) + *(pWorkrow+1)); + *(pOutrow+2) = (mng_uint8)(*(pOutrow+2) + *(pWorkrow+2)); + /* next pixel */ + pOutrow += (pData->iColinc * 3); + pWorkrow += 3; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGB8, MNG_LC_END); +#endif + + return mng_store_rgb8 (pData); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_delta_rgb16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGB16, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* put in object buffer */ + *(pOutrow+1) = *(pWorkrow+1); + *(pOutrow+2) = *(pWorkrow+2); + *(pOutrow+3) = *(pWorkrow+3); + *(pOutrow+4) = *(pWorkrow+4); + *(pOutrow+5) = *(pWorkrow+5); + /* next pixel */ + pOutrow += (pData->iColinc * 6); + pWorkrow += 6; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* add to object buffer */ + mng_put_uint16 (pOutrow, (mng_uint16)(mng_get_uint16 (pOutrow ) + + mng_get_uint16 (pWorkrow ) )); + mng_put_uint16 (pOutrow+2, (mng_uint16)(mng_get_uint16 (pOutrow+2 ) + + mng_get_uint16 (pWorkrow+2) )); + mng_put_uint16 (pOutrow+4, (mng_uint16)(mng_get_uint16 (pOutrow+4 ) + + mng_get_uint16 (pWorkrow+4) )); + /* next pixel */ + pOutrow += (pData->iColinc * 6); + pWorkrow += 6; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGB16, MNG_LC_END); +#endif + + return mng_store_rgb16 (pData); +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_retcode mng_delta_idx1 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_IDX1, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + iM = 0; /* start at pixel 0 */ + iB = 0; + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0x80; + } + + if (iB & iM) /* put the right index value */ + *pOutrow = 1; + else + *pOutrow = 0; + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 1; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0x80; + } + + if (iB & iM) /* invert if it is non-zero index */ + *pOutrow = (mng_uint8)(*pOutrow ^ 0x01); + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 1; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_IDX1, MNG_LC_END); +#endif + + return mng_store_idx1 (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_delta_idx2 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_IDX2, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xC0; + iS = 6; + } + /* put the index */ + *pOutrow = (mng_uint8)((iB & iM) >> iS); + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 2; + iS -= 2; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xC0; + iS = 6; + } + /* calculate the index */ + *pOutrow = (mng_uint8)((*pOutrow + ((iB & iM) >> iS)) & 0x03); + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 2; + iS -= 2; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_IDX2, MNG_LC_END); +#endif + + return mng_store_idx2 (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_delta_idx4 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_IDX4, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xF0; + iS = 4; + } + /* put the index */ + *pOutrow = (mng_uint8)((iB & iM) >> iS); + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 4; + iS -= 4; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xF0; + iS = 4; + } + /* calculate the index */ + *pOutrow = (mng_uint8)((*pOutrow + ((iB & iM) >> iS)) & 0x0F); + + pOutrow += pData->iColinc; /* next pixel */ + iM >>= 4; + iS -= 4; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_IDX4, MNG_LC_END); +#endif + + return mng_store_idx4 (pData); +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_delta_idx8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_IDX8, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* put in object buffer */ + + pOutrow += pData->iColinc; /* next pixel */ + pWorkrow++; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* add to object buffer */ + *pOutrow = (mng_uint8)(*pOutrow + *pWorkrow); + + pOutrow += pData->iColinc; /* next pixel */ + pWorkrow++; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_IDX8, MNG_LC_END); +#endif + + return mng_store_idx8 (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_delta_ga8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA8, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* put in object buffer */ + *(pOutrow+1) = *(pWorkrow+1); + /* next pixel */ + pOutrow += (pData->iColinc << 1); + pWorkrow += 2; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* add to object buffer */ + *pOutrow = (mng_uint8)(*pOutrow + *pWorkrow ); + *(pOutrow+1) = (mng_uint8)(*(pOutrow+1) + *(pWorkrow+1)); + /* next pixel */ + pOutrow += (pData->iColinc << 1); + pWorkrow += 2; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA8, MNG_LC_END); +#endif + + return mng_store_ga8 (pData); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_delta_ga16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA16, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* put in object buffer */ + *(pOutrow+1) = *(pWorkrow+1); + *(pOutrow+2) = *(pWorkrow+2); + *(pOutrow+3) = *(pWorkrow+3); + /* next pixel */ + pOutrow += (pData->iColinc << 2); + pWorkrow += 4; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* add to object buffer */ + mng_put_uint16 (pOutrow, (mng_uint16)(mng_get_uint16 (pOutrow ) + + mng_get_uint16 (pWorkrow ) )); + mng_put_uint16 (pOutrow+2, (mng_uint16)(mng_get_uint16 (pOutrow+2 ) + + mng_get_uint16 (pWorkrow+2) )); + /* next pixel */ + pOutrow += (pData->iColinc << 2); + pWorkrow += 4; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA16, MNG_LC_END); +#endif + + return mng_store_ga16 (pData); +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_delta_rgba8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA8, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; /* put in object buffer */ + *(pOutrow+1) = *(pWorkrow+1); + *(pOutrow+2) = *(pWorkrow+2); + *(pOutrow+3) = *(pWorkrow+3); + /* next pixel */ + pOutrow += (pData->iColinc << 2); + pWorkrow += 4; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* add to object buffer */ + *pOutrow = (mng_uint8)(*pOutrow + *pWorkrow ); + *(pOutrow+1) = (mng_uint8)(*(pOutrow+1) + *(pWorkrow+1)); + *(pOutrow+2) = (mng_uint8)(*(pOutrow+2) + *(pWorkrow+2)); + *(pOutrow+3) = (mng_uint8)(*(pOutrow+3) + *(pWorkrow+3)); + /* next pixel */ + pOutrow += (pData->iColinc << 2); + pWorkrow += 4; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA8, MNG_LC_END); +#endif + + return mng_store_rgba8 (pData); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_delta_rgba16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pDeltaImage)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA16, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iDeltaBlocky * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + + (pData->iDeltaBlockx * pBuf->iSamplesize); + /* pixel replace ? */ + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + MNG_COPY (pOutrow, pWorkrow, 8); /* put in object buffer */ + /* next pixel */ + pOutrow += (pData->iColinc << 3); + pWorkrow += 8; + } + } + else + { /* pixel add ! */ +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* add to object buffer */ + mng_put_uint16 (pOutrow, (mng_uint16)(mng_get_uint16 (pOutrow ) + + mng_get_uint16 (pWorkrow ) )); + mng_put_uint16 (pOutrow+2, (mng_uint16)(mng_get_uint16 (pOutrow+2 ) + + mng_get_uint16 (pWorkrow+2) )); + mng_put_uint16 (pOutrow+4, (mng_uint16)(mng_get_uint16 (pOutrow+4 ) + + mng_get_uint16 (pWorkrow+4) )); + mng_put_uint16 (pOutrow+6, (mng_uint16)(mng_get_uint16 (pOutrow+6 ) + + mng_get_uint16 (pWorkrow+6) )); + /* next pixel */ + pOutrow += (pData->iColinc << 3); + pWorkrow += 8; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA16, MNG_LC_END); +#endif + + return mng_store_rgba16 (pData); +} +#endif + +/* ************************************************************************** */ +/* * * */ +/* * Delta-image row routines - apply the source row onto the target * */ +/* * * */ +/* ************************************************************************** */ + +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_retcode mng_delta_g1_g1 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G1_G1, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples); + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + + (mng_uint16)*pWorkrow) & 0x01); + + pOutrow++; + pWorkrow++; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G1_G1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_delta_g2_g2 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G2_G2, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples); + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + + (mng_uint16)*pWorkrow) & 0x03); + + pOutrow++; + pWorkrow++; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G2_G2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_delta_g4_g4 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G4_G4, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples); + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + + (mng_uint16)*pWorkrow) & 0x0F); + + pOutrow++; + pWorkrow++; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G4_G4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_delta_g8_g8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G8_G8, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples); + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + + (mng_uint16)*pWorkrow) & 0xFF); + + pOutrow++; + pWorkrow++; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G8_G8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_delta_g16_g16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G16_G16, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + MNG_COPY (pOutrow, pWorkrow, (pData->iRowsamples << 1)); + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + mng_put_uint16 (pOutrow, (mng_uint16)((mng_get_uint16 (pOutrow) + + mng_get_uint16 (pWorkrow)) & 0xFFFF)); + + pOutrow += 2; + pWorkrow += 2; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_G16_G16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_NO_DELTA_PNG */ + +/* ************************************************************************** */ + +mng_retcode mng_delta_rgb8_rgb8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGB8_RGB8, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples * 3); + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples*3; iX > 0; iX--) +#else + for (iX = 0; iX < (pData->iRowsamples * 3); iX++) +#endif + { + *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + + (mng_uint16)*pWorkrow) & 0xFF); + + pOutrow++; + pWorkrow++; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGB8_RGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_delta_rgb16_rgb16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGB16_RGB16, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + MNG_COPY (pOutrow, pWorkrow, (pData->iRowsamples * 6)); + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + mng_put_uint16 (pOutrow, (mng_uint16)((mng_get_uint16 (pOutrow ) + + mng_get_uint16 (pWorkrow )) & 0xFFFF)); + mng_put_uint16 (pOutrow+2, (mng_uint16)((mng_get_uint16 (pOutrow+2) + + mng_get_uint16 (pWorkrow+2)) & 0xFFFF)); + mng_put_uint16 (pOutrow+4, (mng_uint16)((mng_get_uint16 (pOutrow+4) + + mng_get_uint16 (pWorkrow+4)) & 0xFFFF)); + + pOutrow += 6; + pWorkrow += 6; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGB16_RGB16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode mng_delta_ga8_ga8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA8_GA8, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples << 1); + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = (pData->iRowsamples<<1); iX > 0; iX--) +#else + for (iX = 0; iX < (pData->iRowsamples << 1); iX++) +#endif + { + *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + + (mng_uint16)*pWorkrow) & 0xFF); + + pOutrow++; + pWorkrow++; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA8_GA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_delta_ga8_g8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA8_G8, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; + + pOutrow += 2; + pWorkrow++; + } + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + + (mng_uint16)*pWorkrow) & 0xFF); + + pOutrow += 2; + pWorkrow++; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA8_G8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_delta_ga8_a8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA8_A8, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 1; + + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; + + pOutrow += 2; + pWorkrow++; + } + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + + (mng_uint16)*pWorkrow) & 0xFF); + + pOutrow += 2; + pWorkrow++; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA8_A8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_delta_ga16_ga16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA16_GA16, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + MNG_COPY (pOutrow, pWorkrow, (pData->iRowsamples << 2)); + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + mng_put_uint16 (pOutrow, (mng_uint16)((mng_get_uint16 (pOutrow ) + + mng_get_uint16 (pWorkrow )) & 0xFFFF)); + mng_put_uint16 (pOutrow+2, (mng_uint16)((mng_get_uint16 (pOutrow+2) + + mng_get_uint16 (pWorkrow+2)) & 0xFFFF)); + + pOutrow += 4; + pWorkrow += 4; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA16_GA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_delta_ga16_g16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA16_G16, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + mng_put_uint16 (pOutrow, mng_get_uint16 (pWorkrow)); + + pOutrow += 4; + pWorkrow += 2; + } + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + mng_put_uint16 (pOutrow, (mng_uint16)((mng_get_uint16 (pOutrow) + + mng_get_uint16 (pWorkrow)) & 0xFFFF)); + + pOutrow += 4; + pWorkrow += 2; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA16_G16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_delta_ga16_a16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA16_A16, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + mng_put_uint16 (pOutrow+2, mng_get_uint16 (pWorkrow)); + + pOutrow += 4; + pWorkrow += 2; + } + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + mng_put_uint16 (pOutrow+2, (mng_uint16)((mng_get_uint16 (pOutrow+2) + + mng_get_uint16 (pWorkrow)) & 0xFFFF)); + + pOutrow += 4; + pWorkrow += 2; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_GA16_A16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_NO_DELTA_PNG */ + +/* ************************************************************************** */ + +mng_retcode mng_delta_rgba8_rgba8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA8_RGBA8, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + MNG_COPY (pOutrow, pWorkrow, pData->iRowsamples << 2); + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = (pData->iRowsamples << 2); iX > 0; iX--) +#else + for (iX = 0; iX < (pData->iRowsamples << 2); iX++) +#endif + { + *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + + (mng_uint16)*pWorkrow) & 0xFF); + + pOutrow++; + pWorkrow++; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA8_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +mng_retcode mng_delta_rgba8_rgb8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA8_RGB8, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; + *(pOutrow+1) = *(pWorkrow+1); + *(pOutrow+2) = *(pWorkrow+2); + + pOutrow += 4; + pWorkrow += 3; + } + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + + (mng_uint16)*pWorkrow ) & 0xFF); + *(pOutrow+1) = (mng_uint8)(((mng_uint16)*(pOutrow+1) + + (mng_uint16)*(pWorkrow+1)) & 0xFF); + *(pOutrow+2) = (mng_uint8)(((mng_uint16)*(pOutrow+2) + + (mng_uint16)*(pWorkrow+2)) & 0xFF); + + pOutrow += 4; + pWorkrow += 3; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA8_RGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_delta_rgba8_a8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA8_A8, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize) + 3; + + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = *pWorkrow; + + pOutrow += 4; + pWorkrow++; + } + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(((mng_uint16)*pOutrow + + (mng_uint16)*pWorkrow) & 0xFF); + + pOutrow += 4; + pWorkrow++; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA8_A8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_DELTA_PNG */ + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_delta_rgba16_rgba16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA16_RGBA16, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) || + (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) ) + { + MNG_COPY (pOutrow, pWorkrow, (pData->iRowsamples << 3)); + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + mng_put_uint16 (pOutrow, (mng_uint16)((mng_get_uint16 (pOutrow ) + + mng_get_uint16 (pWorkrow )) & 0xFFFF)); + mng_put_uint16 (pOutrow+2, (mng_uint16)((mng_get_uint16 (pOutrow+2) + + mng_get_uint16 (pWorkrow+2)) & 0xFFFF)); + mng_put_uint16 (pOutrow+4, (mng_uint16)((mng_get_uint16 (pOutrow+4) + + mng_get_uint16 (pWorkrow+4)) & 0xFFFF)); + mng_put_uint16 (pOutrow+6, (mng_uint16)((mng_get_uint16 (pOutrow+6) + + mng_get_uint16 (pWorkrow+6)) & 0xFFFF)); + + pOutrow += 8; + pWorkrow += 8; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA16_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_delta_rgba16_rgb16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA16_RGB16, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + mng_put_uint16 (pOutrow, mng_get_uint16 (pWorkrow )); + mng_put_uint16 (pOutrow+2, mng_get_uint16 (pWorkrow+2)); + mng_put_uint16 (pOutrow+4, mng_get_uint16 (pWorkrow+4)); + + pOutrow += 8; + pWorkrow += 6; + } + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + mng_put_uint16 (pOutrow, (mng_uint16)((mng_get_uint16 (pOutrow ) + + mng_get_uint16 (pWorkrow )) & 0xFFFF)); + mng_put_uint16 (pOutrow+2, (mng_uint16)((mng_get_uint16 (pOutrow+2) + + mng_get_uint16 (pWorkrow+2)) & 0xFFFF)); + mng_put_uint16 (pOutrow+4, (mng_uint16)((mng_get_uint16 (pOutrow+4) + + mng_get_uint16 (pWorkrow+4)) & 0xFFFF)); + + pOutrow += 8; + pWorkrow += 6; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA16_RGB16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_delta_rgba16_a16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA16_A16, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + mng_put_uint16 (pOutrow+6, mng_get_uint16 (pWorkrow)); + + pOutrow += 8; + pWorkrow += 2; + } + } + else + if (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD) + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + mng_put_uint16 (pOutrow+6, (mng_uint16)((mng_get_uint16 (pOutrow+6) + + mng_get_uint16 (pWorkrow)) & 0xFFFF)); + + pOutrow += 8; + pWorkrow += 2; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DELTA_RGBA16_A16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_NO_DELTA_PNG */ + +/* ************************************************************************** */ +/* * * */ +/* * Delta-image row routines - scale the delta to bitdepth of target * */ +/* * * */ +/* ************************************************************************** */ + +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_retcode mng_scale_g1_g2 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G1_G2, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pWorkrow = (mng_uint8)(*pWorkrow << 1); + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G1_G2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_scale_g1_g4 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G1_G4, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pWorkrow = (mng_uint8)(*pWorkrow << 3); + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G1_G4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_scale_g1_g8 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G1_G8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pWorkrow = (mng_uint8)(*pWorkrow << 7); + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G1_G8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_scale_g1_g16 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_uint8p pOutrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G1_G16, MNG_LC_START); +#endif + + pWorkrow = pWorkrow + (pData->iRowsamples - 1); + pOutrow = pOutrow + ((pData->iRowsamples - 1) << 1); +/* pWorkrow = (mng_uint8p)((mng_uint32)pWorkrow + pData->iRowsamples - 1); */ +/* pOutrow = (mng_uint8p)((mng_uint32)pOutrow + ((pData->iRowsamples - 1) << 1)); */ + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *(pOutrow+1) = 0; + *pOutrow = (mng_uint8)(*pWorkrow << 7); + + pWorkrow--; + pOutrow -= 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G1_G16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_scale_g2_g4 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G2_G4, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pWorkrow = (mng_uint8)(*pWorkrow << 2); + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G2_G4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_scale_g2_g8 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G2_G8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pWorkrow = (mng_uint8)(*pWorkrow << 6); + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G2_G8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_scale_g2_g16 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_uint8p pOutrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G2_G16, MNG_LC_START); +#endif + + pWorkrow = pWorkrow + (pData->iRowsamples - 1); + pOutrow = pOutrow + ((pData->iRowsamples - 1) << 1); +/* pWorkrow = (mng_uint8p)((mng_uint32)pWorkrow + pData->iRowsamples - 1); */ +/* pOutrow = (mng_uint8p)((mng_uint32)pOutrow + ((pData->iRowsamples - 1) << 1)); */ + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *(pOutrow+1) = 0; + *pOutrow = (mng_uint8)(*pWorkrow << 6); + + pWorkrow--; + pOutrow -= 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G2_G16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_scale_g4_g8 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G4_G8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pWorkrow = (mng_uint8)(*pWorkrow << 4); + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G4_G8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_scale_g4_g16 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_uint8p pOutrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G4_G16, MNG_LC_START); +#endif + + pWorkrow = pWorkrow + (pData->iRowsamples - 1); + pOutrow = pOutrow + ((pData->iRowsamples - 1) << 1); +/* pWorkrow = (mng_uint8p)((mng_uint32)pWorkrow + pData->iRowsamples - 1); */ +/* pOutrow = (mng_uint8p)((mng_uint32)pOutrow + ((pData->iRowsamples - 1) << 1)); */ + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *(pOutrow+1) = 0; + *pOutrow = (mng_uint8)(*pWorkrow << 4); + + pWorkrow--; + pOutrow -= 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G4_G16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_scale_g8_g16 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_uint8p pOutrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G8_G16, MNG_LC_START); +#endif + + pWorkrow = pWorkrow + (pData->iRowsamples - 1); + pOutrow = pOutrow + ((pData->iRowsamples - 1) << 1); +/* pWorkrow = (mng_uint8p)((mng_uint32)pWorkrow + pData->iRowsamples - 1); */ +/* pOutrow = (mng_uint8p)((mng_uint32)pOutrow + ((pData->iRowsamples - 1) << 1)); */ + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *(pOutrow+1) = 0; + *pOutrow = *pWorkrow; + + pWorkrow--; + pOutrow -= 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G8_G16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_scale_ga8_ga16 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_uint8p pOutrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_GA8_GA16, MNG_LC_START); +#endif + + pWorkrow = pWorkrow + ((pData->iRowsamples - 1) << 1); + pOutrow = pOutrow + ((pData->iRowsamples - 1) << 2); +/* pWorkrow = (mng_uint8p)((mng_uint32)pWorkrow + ((pData->iRowsamples - 1) << 1)); */ +/* pOutrow = (mng_uint8p)((mng_uint32)pOutrow + ((pData->iRowsamples - 1) << 2)); */ + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *(pOutrow+3) = 0; + *(pOutrow+2) = *(pWorkrow+1); + *(pOutrow+1) = 0; + *pOutrow = *pWorkrow; + + pWorkrow -= 2; + pOutrow -= 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_GA8_GA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_scale_rgb8_rgb16 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_uint8p pOutrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_RGB8_RGB16, MNG_LC_START); +#endif + + pWorkrow = pWorkrow + (3 * (pData->iRowsamples - 1)); + pOutrow = pOutrow + (6 * (pData->iRowsamples - 1)); +/* pWorkrow = (mng_uint8p)((mng_uint32)pWorkrow + 3 * (pData->iRowsamples - 1)); */ +/* pOutrow = (mng_uint8p)((mng_uint32)pOutrow + 6 * (pData->iRowsamples - 1)); */ + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *(pOutrow+5) = 0; + *(pOutrow+4) = *(pWorkrow+2); + *(pOutrow+3) = 0; + *(pOutrow+2) = *(pWorkrow+1); + *(pOutrow+1) = 0; + *pOutrow = *pWorkrow; + + pWorkrow -= 3; + pOutrow -= 6; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_RGB8_RGB16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_scale_rgba8_rgba16 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_uint8p pOutrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_RGBA8_RGBA16, MNG_LC_START); +#endif + + pWorkrow = pWorkrow + ((pData->iRowsamples - 1) << 2); + pOutrow = pOutrow + ((pData->iRowsamples - 1) << 3); +/* pWorkrow = (mng_uint8p)((mng_uint32)pWorkrow + ((pData->iRowsamples - 1) << 2)); */ +/* pOutrow = (mng_uint8p)((mng_uint32)pOutrow + ((pData->iRowsamples - 1) << 3)); */ + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *(pOutrow+7) = 0; + *(pOutrow+6) = *(pWorkrow+3); + *(pOutrow+5) = 0; + *(pOutrow+4) = *(pWorkrow+2); + *(pOutrow+3) = 0; + *(pOutrow+2) = *(pWorkrow+1); + *(pOutrow+1) = 0; + *pOutrow = *pWorkrow; + + pWorkrow -= 4; + pOutrow -= 8; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_RGBA8_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_retcode mng_scale_g2_g1 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G2_G1, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pWorkrow = (mng_uint8)(*pWorkrow >> 1); + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G2_G1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_scale_g4_g1 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G4_G1, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pWorkrow = (mng_uint8)(*pWorkrow >> 3); + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G4_G1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_scale_g8_g1 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G8_G1, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pWorkrow = (mng_uint8)(*pWorkrow >> 7); + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G8_G1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_scale_g16_g1 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_uint8p pOutrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G16_G1, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 15); + pOutrow++; + pWorkrow += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G16_G1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_scale_g4_g2 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G4_G2, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pWorkrow = (mng_uint8)(*pWorkrow >> 2); + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G4_G2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_scale_g8_g2 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G8_G2, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pWorkrow = (mng_uint8)(*pWorkrow >> 6); + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G8_G2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_scale_g16_g2 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_uint8p pOutrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G16_G2, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 14); + pOutrow++; + pWorkrow += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G16_G2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_scale_g8_g4 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G8_G4, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pWorkrow = (mng_uint8)(*pWorkrow >> 4); + pWorkrow++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G8_G4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_scale_g16_g4 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_uint8p pOutrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G16_G4, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 12); + pOutrow++; + pWorkrow += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G16_G4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* NO_1_2_4BIT_SUPPORT */ + +/* ************************************************************************** */ + +mng_retcode mng_scale_g16_g8 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_uint8p pOutrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G16_G8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); + pOutrow++; + pWorkrow += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_G16_G8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_scale_ga16_ga8 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_uint8p pOutrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_GA16_GA8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); + pOutrow++; + pWorkrow += 2; + *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); + pOutrow++; + pWorkrow += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_GA16_GA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_scale_rgb16_rgb8 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_uint8p pOutrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_RGB16_RGB8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); + pOutrow++; + pWorkrow += 2; + *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); + pOutrow++; + pWorkrow += 2; + *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); + pOutrow++; + pWorkrow += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_RGB16_RGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_scale_rgba16_rgba8 (mng_datap pData) +{ + mng_uint8p pWorkrow = pData->pRGBArow; + mng_uint8p pOutrow = pData->pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_RGBA16_RGBA8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); + pOutrow++; + pWorkrow += 2; + *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); + pOutrow++; + pWorkrow += 2; + *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); + pOutrow++; + pWorkrow += 2; + *pOutrow = (mng_uint8)(mng_get_uint16 (pWorkrow) >> 8); + pOutrow++; + pWorkrow += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_SCALE_RGBA16_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ +/* * * */ +/* * Delta-image bit routines - promote bit_depth * */ +/* * * */ +/* ************************************************************************** */ + +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_uint8 mng_promote_replicate_1_2 (mng_uint8 iB) +{ + return (mng_uint8)((iB << 1) | iB); +} + +/* ************************************************************************** */ + +mng_uint8 mng_promote_replicate_1_4 (mng_uint8 iB) +{ + iB = (mng_uint8)((iB << 1) + iB); + return (mng_uint8)((iB << 2) + iB); +} + +/* ************************************************************************** */ + +mng_uint8 mng_promote_replicate_1_8 (mng_uint8 iB) +{ + iB = (mng_uint8)((iB << 1) + iB); + iB = (mng_uint8)((iB << 2) + iB); + return (mng_uint8)((iB << 4) + iB); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_uint16 mng_promote_replicate_1_16 (mng_uint8 iB) +{ + iB = (mng_uint8)((iB << 1) + iB); + iB = (mng_uint8)((iB << 2) + iB); + iB = (mng_uint8)((iB << 4) + iB); + return (mng_uint16)(((mng_uint16)iB << 8) + (mng_uint16)iB); +} +#endif + +/* ************************************************************************** */ + +mng_uint8 mng_promote_replicate_2_4 (mng_uint8 iB) +{ + return (mng_uint8)((iB << 2) + iB); +} + +/* ************************************************************************** */ + +mng_uint8 mng_promote_replicate_2_8 (mng_uint8 iB) +{ + iB = (mng_uint8)((iB << 2) + iB); + return (mng_uint8)((iB << 4) + iB); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_uint16 mng_promote_replicate_2_16 (mng_uint8 iB) +{ + iB = (mng_uint8)((iB << 2) + iB); + iB = (mng_uint8)((iB << 4) + iB); + return (mng_uint16)(((mng_uint16)iB << 8) + (mng_uint16)iB); +} +#endif + +/* ************************************************************************** */ + +mng_uint8 mng_promote_replicate_4_8 (mng_uint8 iB) +{ + return (mng_uint8)((iB << 4) + iB); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_uint16 mng_promote_replicate_4_16 (mng_uint8 iB) +{ + iB = (mng_uint8)((iB << 4) + iB); + return (mng_uint16)(((mng_uint16)iB << 8) + (mng_uint16)iB); +} +#endif +#endif /* NO_1_2_4BIT_SUPPORT */ + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_uint16 mng_promote_replicate_8_16 (mng_uint8 iB) +{ + return (mng_uint16)(((mng_uint16)iB << 8) + (mng_uint16)iB); +} +#endif + +/* ************************************************************************** */ + +#if !defined(MNG_NO_DELTA_PNG) +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_uint8 mng_promote_zerofill_1_2 (mng_uint8 iB) +{ + return (mng_uint8)(iB << 1); +} + +/* ************************************************************************** */ + +mng_uint8 mng_promote_zerofill_1_4 (mng_uint8 iB) +{ + return (mng_uint8)(iB << 3); +} + +/* ************************************************************************** */ + +mng_uint8 mng_promote_zerofill_1_8 (mng_uint8 iB) +{ + return (mng_uint8)(iB << 7); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_uint16 mng_promote_zerofill_1_16 (mng_uint8 iB) +{ + return (mng_uint16)((mng_uint16)iB << 15); +} +#endif + +/* ************************************************************************** */ + +mng_uint8 mng_promote_zerofill_2_4 (mng_uint8 iB) +{ + return (mng_uint8)(iB << 2); +} + +/* ************************************************************************** */ + +mng_uint8 mng_promote_zerofill_2_8 (mng_uint8 iB) +{ + return (mng_uint8)(iB << 6); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_uint16 mng_promote_zerofill_2_16 (mng_uint8 iB) +{ + return (mng_uint16)((mng_uint16)iB << 14); +} +#endif + +/* ************************************************************************** */ + +mng_uint8 mng_promote_zerofill_4_8 (mng_uint8 iB) +{ + return (mng_uint8)(iB << 4); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_uint16 mng_promote_zerofill_4_16 (mng_uint8 iB) +{ + return (mng_uint16)((mng_uint16)iB << 12); +} +#endif +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_uint16 mng_promote_zerofill_8_16 (mng_uint8 iB) +{ + return (mng_uint16)((mng_uint16)iB << 8); +} +#endif +#endif /* MNG_NO_DELTA_PNG */ + +/* ************************************************************************** */ +/* * * */ +/* * Delta-image row routines - promote color_type * */ +/* * * */ +/* ************************************************************************** */ + +#if !defined(MNG_NO_DELTA_PNG) || !defined(MNG_SKIPCHUNK_PAST) || !defined(MNG_SKIPCHUNK_MAGN) +mng_retcode mng_promote_g8_g8 (mng_datap pData) +{ + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iB; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_G8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iB = *pSrcline; + if (pData->fPromBitdepth) /* bitdepth promoted ? */ + iB = ((mng_bitdepth_8)pData->fPromBitdepth) (iB); + *pDstline = iB; + + pSrcline++; + pDstline++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_G8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_g8_g16 (mng_datap pData) +{ + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint16 iW; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_G16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iW = ((mng_bitdepth_16)pData->fPromBitdepth) (*pSrcline); + + *pDstline = (mng_uint8)(iW >> 8); + *(pDstline+1) = (mng_uint8)(iW && 0xFF); + + pSrcline++; + pDstline += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_G16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_promote_g16_g16 (mng_datap pData) +{ + mng_uint16p pSrcline = (mng_uint16p)pData->pPromSrc; + mng_uint16p pDstline = (mng_uint16p)pData->pPromDst; + mng_uint32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G16_G16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + *pDstline = *pSrcline; + pSrcline++; + pDstline++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G16_G16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_promote_g8_ga8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iB; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_GA8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iB = *pSrcline; + /* no cheap transparency ? */ + if ((!pBuf->bHasTRNS) || ((mng_uint16)iB != pBuf->iTRNSgray)) + *(pDstline+1) = 0xFF; + + if (pData->fPromBitdepth) /* bitdepth promoted ? */ + iB = ((mng_bitdepth_8)pData->fPromBitdepth) (iB); + + *pDstline = iB; + + pSrcline++; + pDstline += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_GA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_g8_ga16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iB; + mng_uint16 iW; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_GA16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iB = *pSrcline; + /* no cheap transparency ? */ + if ((!pBuf->bHasTRNS) || ((mng_uint16)iB != pBuf->iTRNSgray)) + { + *(pDstline+2) = 0xFF; + *(pDstline+3) = 0xFF; + } + + iW = ((mng_bitdepth_16)pData->fPromBitdepth) (iB); + + *pDstline = (mng_uint8)(iW >> 8); + *(pDstline+1) = (mng_uint8)(iW && 0xFF); + + pSrcline++; + pDstline += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_GA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_g16_ga16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; + mng_uint16p pSrcline = (mng_uint16p)pData->pPromSrc; + mng_uint16p pDstline = (mng_uint16p)pData->pPromDst; + mng_uint32 iX; + mng_uint16 iW; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G16_GA16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iW = *pSrcline; + /* no cheap transparency ? */ + if ((!pBuf->bHasTRNS) || ((mng_uint16)iW != pBuf->iTRNSgray)) + *(pDstline+1) = 0xFFFF; + + *pDstline = iW; + + pSrcline++; + pDstline += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G16_GA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_promote_g8_rgb8 (mng_datap pData) +{ + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iB; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGB8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iB = *pSrcline; + + if (pData->fPromBitdepth) /* bitdepth promoted ? */ + iB = ((mng_bitdepth_8)pData->fPromBitdepth) (iB); + + *pDstline = iB; + *(pDstline+1) = iB; + *(pDstline+2) = iB; + + pSrcline++; + pDstline += 3; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_g8_rgb16 (mng_datap pData) +{ + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iB; + mng_uint16 iW; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGB16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iB = *pSrcline; + iW = ((mng_bitdepth_16)pData->fPromBitdepth) (iB); + + iB = (mng_uint8)(iW >> 8); + *pDstline = iB; + *(pDstline+2) = iB; + *(pDstline+4) = iB; + iB = (mng_uint8)(iW && 0xFF); + *(pDstline+1) = iB; + *(pDstline+3) = iB; + *(pDstline+5) = iB; + + pSrcline++; + pDstline += 6; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGB16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_g16_rgb16 (mng_datap pData) +{ + mng_uint16p pSrcline = (mng_uint16p)pData->pPromSrc; + mng_uint16p pDstline = (mng_uint16p)pData->pPromDst; + mng_uint32 iX; + mng_uint16 iW; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G16_RGB16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iW = *pSrcline; + + *pDstline = iW; + *(pDstline+1) = iW; + *(pDstline+2) = iW; + + pSrcline++; + pDstline += 3; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G16_RGB16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_promote_g8_rgba8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iB; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGBA8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iB = *pSrcline; + /* no cheap transparency ? */ + if ((!pBuf->bHasTRNS) || ((mng_uint16)iB != pBuf->iTRNSgray)) + *(pDstline+3) = 0xFF; + + if (pData->fPromBitdepth) /* bitdepth promoted ? */ + iB = ((mng_bitdepth_8)pData->fPromBitdepth) (iB); + + *pDstline = iB; + *(pDstline+1) = iB; + *(pDstline+2) = iB; + + pSrcline++; + pDstline += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_g8_rgba16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iB; + mng_uint16 iW; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGBA16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iB = *pSrcline; + /* no cheap transparency ? */ + if ((!pBuf->bHasTRNS) || ((mng_uint16)iB != pBuf->iTRNSgray)) + { + *(pDstline+6) = 0xFF; + *(pDstline+7) = 0xFF; + } + + iW = ((mng_bitdepth_16)pData->fPromBitdepth) (iB); + + iB = (mng_uint8)(iW >> 8); + *pDstline = iB; + *(pDstline+2) = iB; + *(pDstline+4) = iB; + iB = (mng_uint8)(iW && 0xFF); + *(pDstline+1) = iB; + *(pDstline+3) = iB; + *(pDstline+5) = iB;; + + pSrcline++; + pDstline += 8; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G8_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_g16_rgba16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; + mng_uint16p pSrcline = (mng_uint16p)pData->pPromSrc; + mng_uint16p pDstline = (mng_uint16p)pData->pPromDst; + mng_uint32 iX; + mng_uint16 iW; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G16_RGBA16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iW = *pSrcline; + /* no cheap transparency ? */ + if ((!pBuf->bHasTRNS) || (iW != pBuf->iTRNSgray)) + *(pDstline+3) = 0xFFFF; + + *pDstline = iW; + *(pDstline+1) = iW; + *(pDstline+2) = iW; + + pSrcline++; + pDstline += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_G16_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_ga8_ga16 (mng_datap pData) +{ + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint16 iW; + mng_uint16 iA; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_GA8_GA16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iW = ((mng_bitdepth_16)pData->fPromBitdepth) (*pSrcline); + iA = ((mng_bitdepth_16)pData->fPromBitdepth) (*(pSrcline+1)); + + *pDstline = (mng_uint8)(iW >> 8); + *(pDstline+1) = (mng_uint8)(iW && 0xFF); + *(pDstline+2) = (mng_uint8)(iA >> 8); + *(pDstline+3) = (mng_uint8)(iA && 0xFF); + + pSrcline += 2; + pDstline += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_GA8_GA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_promote_ga8_rgba8 (mng_datap pData) +{ + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iB; + mng_uint8 iA; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_GA8_RGBA8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iB = *pSrcline; + iA = *(pSrcline+1); + + *pDstline = iB; + *(pDstline+1) = iB; + *(pDstline+2) = iB; + *(pDstline+3) = iA; + + pSrcline += 2; + pDstline += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_GA8_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_ga8_rgba16 (mng_datap pData) +{ + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iB; + mng_uint16 iW; + mng_uint16 iA; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_GA8_RGBA16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iW = ((mng_bitdepth_16)pData->fPromBitdepth) (*pSrcline); + iA = ((mng_bitdepth_16)pData->fPromBitdepth) (*(pSrcline+1)); + + iB = (mng_uint8)(iW >> 8); + *pDstline = iB; + *(pDstline+2) = iB; + *(pDstline+4) = iB; + iB = (mng_uint8)(iW && 0xFF); + *(pDstline+1) = iB; + *(pDstline+3) = iB; + *(pDstline+5) = iB; + *(pDstline+6) = (mng_uint8)(iA >> 8); + *(pDstline+7) = (mng_uint8)(iA && 0xFF); + + pSrcline += 2; + pDstline += 8; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_GA8_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_ga16_rgba16 (mng_datap pData) +{ + mng_uint16p pSrcline = (mng_uint16p)pData->pPromSrc; + mng_uint16p pDstline = (mng_uint16p)pData->pPromDst; + mng_uint32 iX; + mng_uint16 iW; + mng_uint16 iA; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_GA16_RGBA16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iW = *pSrcline; + iA = *(pSrcline+1); + + *pDstline = iW; + *(pDstline+1) = iW; + *(pDstline+2) = iW; + *(pDstline+3) = iA; + + pSrcline += 2; + pDstline += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_GA16_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_rgb8_rgb16 (mng_datap pData) +{ + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint16 iR; + mng_uint16 iG; + mng_uint16 iB; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_RGB8_RGB16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iR = ((mng_bitdepth_16)pData->fPromBitdepth) (*pSrcline); + iG = ((mng_bitdepth_16)pData->fPromBitdepth) (*(pSrcline+1)); + iB = ((mng_bitdepth_16)pData->fPromBitdepth) (*(pSrcline+2)); + + *pDstline = (mng_uint8)(iR >> 8); + *(pDstline+1) = (mng_uint8)(iR && 0xFF); + *(pDstline+2) = (mng_uint8)(iG >> 8); + *(pDstline+3) = (mng_uint8)(iG && 0xFF); + *(pDstline+4) = (mng_uint8)(iB >> 8); + *(pDstline+5) = (mng_uint8)(iB && 0xFF); + + pSrcline += 3; + pDstline += 6; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_RGB8_RGB16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_promote_rgb8_rgba8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iR; + mng_uint8 iG; + mng_uint8 iB; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_RGB8_RGBA8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iR = *pSrcline; + iG = *(pSrcline+1); + iB = *(pSrcline+2); + /* no cheap transparency ? */ + if ((!pBuf->bHasTRNS) || ((mng_uint16)iR != pBuf->iTRNSred) || + ((mng_uint16)iG != pBuf->iTRNSgreen) || ((mng_uint16)iB != pBuf->iTRNSblue)) + *(pDstline+3) = 0xFF; + + *pDstline = iR; + *(pDstline+1) = iG; + *(pDstline+2) = iB; + + pSrcline += 3; + pDstline += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_RGB8_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_rgb8_rgba16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iR; + mng_uint8 iG; + mng_uint8 iB; + mng_uint16 iRw; + mng_uint16 iGw; + mng_uint16 iBw; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_RGB8_RGBA16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iR = *pSrcline; + iG = *(pSrcline+1); + iB = *(pSrcline+2); + /* no cheap transparency ? */ + if ((!pBuf->bHasTRNS) || ((mng_uint16)iR != pBuf->iTRNSred) || + ((mng_uint16)iG != pBuf->iTRNSgreen) || ((mng_uint16)iB != pBuf->iTRNSblue)) + { + *(pDstline+6) = 0xFF; + *(pDstline+7) = 0xFF; + } + + iRw = ((mng_bitdepth_16)pData->fPromBitdepth) (iR); + iGw = ((mng_bitdepth_16)pData->fPromBitdepth) (iG); + iBw = ((mng_bitdepth_16)pData->fPromBitdepth) (iB); + + *pDstline = (mng_uint8)(iRw >> 8); + *(pDstline+1) = (mng_uint8)(iRw && 0xFF); + *(pDstline+2) = (mng_uint8)(iGw >> 8); + *(pDstline+3) = (mng_uint8)(iGw && 0xFF); + *(pDstline+4) = (mng_uint8)(iBw >> 8); + *(pDstline+5) = (mng_uint8)(iBw && 0xFF); + + pSrcline += 3; + pDstline += 8; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_RGB8_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_rgb16_rgba16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; + mng_uint16p pSrcline = (mng_uint16p)pData->pPromSrc; + mng_uint16p pDstline = (mng_uint16p)pData->pPromDst; + mng_uint32 iX; + mng_uint16 iR; + mng_uint16 iG; + mng_uint16 iB; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_RGB16_RGBA16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iR = *pSrcline; + iG = *(pSrcline+1); + iB = *(pSrcline+2); + /* no cheap transparency ? */ + if ((!pBuf->bHasTRNS) || (iR != pBuf->iTRNSred) || + (iG != pBuf->iTRNSgreen) || (iB != pBuf->iTRNSblue)) + *(pDstline+3) = 0xFFFF; + + *pDstline = iR; + *(pDstline+1) = iG; + *(pDstline+2) = iB; + + pSrcline += 3; + pDstline += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_RGB16_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_promote_idx8_rgb8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iB; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGB8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iB = *pSrcline; + + if ((mng_uint32)iB < pBuf->iPLTEcount) + { + *pDstline = pBuf->aPLTEentries [iB].iRed; + *(pDstline+1) = pBuf->aPLTEentries [iB].iGreen; + *(pDstline+2) = pBuf->aPLTEentries [iB].iBlue; + } + + pSrcline++; + pDstline += 3; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_idx8_rgb16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iN; + mng_uint16 iR; + mng_uint16 iG; + mng_uint16 iB; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGB16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iN = *pSrcline; + + if ((mng_uint32)iN < pBuf->iPLTEcount) + { + iR = ((mng_bitdepth_16)pData->fPromBitdepth) (pBuf->aPLTEentries [iN].iRed); + iG = ((mng_bitdepth_16)pData->fPromBitdepth) (pBuf->aPLTEentries [iN].iGreen); + iB = ((mng_bitdepth_16)pData->fPromBitdepth) (pBuf->aPLTEentries [iN].iBlue); + *pDstline = (mng_uint8)(iR >> 8); + *(pDstline+1) = (mng_uint8)(iR && 0xFF); + *(pDstline+2) = (mng_uint8)(iG >> 8); + *(pDstline+3) = (mng_uint8)(iG && 0xFF); + *(pDstline+4) = (mng_uint8)(iB >> 8); + *(pDstline+5) = (mng_uint8)(iB && 0xFF); + } + + pSrcline++; + pDstline += 6; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGB16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_promote_idx8_rgba8 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iB; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGBA8, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iB = *pSrcline; + + if ((mng_uint32)iB < pBuf->iPLTEcount) + { + *pDstline = pBuf->aPLTEentries [iB].iRed; + *(pDstline+1) = pBuf->aPLTEentries [iB].iGreen; + *(pDstline+2) = pBuf->aPLTEentries [iB].iBlue; + + if ((pBuf->bHasTRNS) && ((mng_uint32)iB < pBuf->iTRNScount)) + *(pDstline+3) = pBuf->aTRNSentries [iB]; + else + *(pDstline+3) = 0xFF; + } + + pSrcline++; + pDstline += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_promote_idx8_rgba16 (mng_datap pData) +{ + mng_imagedatap pBuf = (mng_imagedatap)pData->pPromBuf; + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint8 iN; + mng_uint16 iR; + mng_uint16 iG; + mng_uint16 iB; + mng_uint16 iA; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGBA16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iN = *pSrcline; + + if ((mng_uint32)iN < pBuf->iPLTEcount) + { + iR = ((mng_bitdepth_16)pData->fPromBitdepth) (pBuf->aPLTEentries [iN].iRed); + iG = ((mng_bitdepth_16)pData->fPromBitdepth) (pBuf->aPLTEentries [iN].iGreen); + iB = ((mng_bitdepth_16)pData->fPromBitdepth) (pBuf->aPLTEentries [iN].iBlue); + + if ((pBuf->bHasTRNS) && ((mng_uint32)iN < pBuf->iTRNScount)) + iA = ((mng_bitdepth_16)pData->fPromBitdepth) (pBuf->aTRNSentries [iN]); + else + iA = 0xFFFF; + + *pDstline = (mng_uint8)(iR >> 8); + *(pDstline+1) = (mng_uint8)(iR && 0xFF); + *(pDstline+2) = (mng_uint8)(iG >> 8); + *(pDstline+3) = (mng_uint8)(iG && 0xFF); + *(pDstline+4) = (mng_uint8)(iB >> 8); + *(pDstline+5) = (mng_uint8)(iB && 0xFF); + *(pDstline+6) = (mng_uint8)(iA >> 8); + *(pDstline+7) = (mng_uint8)(iA && 0xFF); + } + + pSrcline++; + pDstline += 8; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_IDX8_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_promote_rgba8_rgba16 (mng_datap pData) +{ + mng_uint8p pSrcline = (mng_uint8p)pData->pPromSrc; + mng_uint8p pDstline = (mng_uint8p)pData->pPromDst; + mng_uint32 iX; + mng_uint16 iR; + mng_uint16 iG; + mng_uint16 iB; + mng_uint16 iA; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_RGBA8_RGBA16, MNG_LC_START); +#endif + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPromWidth; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPromWidth; iX++) +#endif + { + iR = ((mng_bitdepth_16)pData->fPromBitdepth) (*pSrcline); + iG = ((mng_bitdepth_16)pData->fPromBitdepth) (*(pSrcline+1)); + iB = ((mng_bitdepth_16)pData->fPromBitdepth) (*(pSrcline+2)); + iA = ((mng_bitdepth_16)pData->fPromBitdepth) (*(pSrcline+3)); + + *pDstline = (mng_uint8)(iR >> 8); + *(pDstline+1) = (mng_uint8)(iR && 0xFF); + *(pDstline+2) = (mng_uint8)(iG >> 8); + *(pDstline+3) = (mng_uint8)(iG && 0xFF); + *(pDstline+4) = (mng_uint8)(iB >> 8); + *(pDstline+5) = (mng_uint8)(iB && 0xFF); + *(pDstline+6) = (mng_uint8)(iA >> 8); + *(pDstline+7) = (mng_uint8)(iA && 0xFF); + + pSrcline += 4; + pDstline += 8; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROMOTE_RGBA8_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* !defined(MNG_NO_DELTA_PNG) || !defined(MNG_SKIPCHUNK_PAST) || !defined(MNG_SKIPCHUNK_MAGN) */ + +/* ************************************************************************** */ +/* * * */ +/* * Row processing routines - convert uncompressed data from zlib to * */ +/* * managable row-data which serves as input to the color-management * */ +/* * routines * */ +/* * * */ +/* ************************************************************************** */ + +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_retcode mng_process_g1 (mng_datap pData) +{ + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_G1, MNG_LC_START); +#endif + + if (!pBuf) /* no object? then use obj 0 */ + pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pRGBArow = pData->pRGBArow; + iM = 0; /* start at pixel 0 */ + iB = 0; + + if (pBuf->bHasTRNS) /* tRNS encountered ? */ + { + if (pBuf->iTRNSgray) /* white transparent ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0x80; + } + + if (iB & iM) /* is it white ? */ + /* transparent ! */ + mng_put_uint32 (pRGBArow, 0x00000000); + else /* opaque black */ + mng_put_uint32 (pRGBArow, 0x000000FF); + + pRGBArow += 4; /* next pixel */ + iM >>= 1; + } + } + else /* black transparent */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0x80; + } + + if (iB & iM) /* is it white ? */ + /* opaque white */ + mng_put_uint32 (pRGBArow, 0xFFFFFFFF); + else /* transparent */ + mng_put_uint32 (pRGBArow, 0x00000000); + + pRGBArow += 4; /* next pixel */ + iM >>= 1; + } + } + + pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ + } + else /* no transparency */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0x80; + } + + if (iB & iM) /* is it white ? */ + /* opaque white */ + mng_put_uint32 (pRGBArow, 0xFFFFFFFF); + else /* opaque black */ + mng_put_uint32 (pRGBArow, 0x000000FF); + + pRGBArow += 4; /* next pixel */ + iM >>= 1; + } + + pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_G1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_process_g2 (mng_datap pData) +{ + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + mng_uint8 iQ; + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; +#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH + const mng_uint32 level[4] = { 0x000000FF, 0x555555FF, + 0xAAAAAAFF, 0xFFFFFFFF}; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_G2, MNG_LC_START); +#endif + + if (!pBuf) /* no object? then use obj 0 */ + pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pRGBArow = pData->pRGBArow; + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + + if (pBuf->bHasTRNS) /* tRNS encountered ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xC0; + iS = 6; + } + /* determine gray level */ + iQ = (mng_uint8)((iB & iM) >> iS); + + if (iQ == pBuf->iTRNSgray) /* transparent ? */ + mng_put_uint32 (pRGBArow, 0x00000000); + else + { +#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH + mng_put_uint32 (pRGBArow, level[iQ]); +#else + switch (iQ) /* determine the gray level */ + { + case 0x03 : { mng_put_uint32 (pRGBArow, 0xFFFFFFFF); break; } + case 0x02 : { mng_put_uint32 (pRGBArow, 0xAAAAAAFF); break; } + case 0x01 : { mng_put_uint32 (pRGBArow, 0x555555FF); break; } + default : { mng_put_uint32 (pRGBArow, 0x000000FF); } + } +#endif + } + + pRGBArow += 4; /* next pixel */ + iM >>= 2; + iS -= 2; + } + + pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xC0; + iS = 6; + } + +#ifdef MNG_OPTIMIZE_FOOTPRINT_SWITCH + mng_put_uint32 (pRGBArow, level[((iB & iM) >> iS)] ); +#else + switch ((iB & iM) >> iS) /* determine the gray level */ + { + case 0x03 : { mng_put_uint32 (pRGBArow, 0xFFFFFFFF); break; } + case 0x02 : { mng_put_uint32 (pRGBArow, 0xAAAAAAFF); break; } + case 0x01 : { mng_put_uint32 (pRGBArow, 0x555555FF); break; } + default : { mng_put_uint32 (pRGBArow, 0x000000FF); } + } +#endif + + pRGBArow += 4; /* next pixel */ + iM >>= 2; + iS -= 2; + } + + pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_G2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_process_g4 (mng_datap pData) +{ + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + mng_uint8 iQ; + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_G4, MNG_LC_START); +#endif + + if (!pBuf) /* no object? then use obj 0 */ + pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pRGBArow = pData->pRGBArow; + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + + if (pBuf->bHasTRNS) /* tRNS encountered ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xF0; + iS = 4; + } + /* get the gray level */ + iQ = (mng_uint8)((iB & iM) >> iS); + + if (iQ == pBuf->iTRNSgray) /* transparent ? */ + { + *pRGBArow = 0; /* put in intermediate row */ + *(pRGBArow+1) = 0; + *(pRGBArow+2) = 0; + *(pRGBArow+3) = 0; + } + else + { /* expand to 8-bit by replication */ + iQ = (mng_uint8)(iQ + (iQ << 4)); + + *pRGBArow = iQ; /* put in intermediate row */ + *(pRGBArow+1) = iQ; + *(pRGBArow+2) = iQ; + *(pRGBArow+3) = 0xFF; + } + + pRGBArow += 4; /* next pixel */ + iM >>= 4; + iS -= 4; + } + + pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xF0; + iS = 4; + } + /* get the gray level */ + iQ = (mng_uint8)((iB & iM) >> iS); + iQ = (mng_uint8)(iQ + (iQ << 4));/* expand to 8-bit by replication */ + + *pRGBArow = iQ; /* put in intermediate row */ + *(pRGBArow+1) = iQ; + *(pRGBArow+2) = iQ; + *(pRGBArow+3) = 0xFF; + + pRGBArow += 4; /* next pixel */ + iM >>= 4; + iS -= 4; + } + + pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_G4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + +/* ************************************************************************** */ + +mng_retcode mng_process_g8 (mng_datap pData) +{ + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint8 iB; + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_G8, MNG_LC_START); +#endif + + if (!pBuf) /* no object? then use obj 0 */ + pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pRGBArow = pData->pRGBArow; + + if (pBuf->bHasTRNS) /* tRNS encountered ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iB = *pWorkrow; /* get next input-byte */ + + if (iB == pBuf->iTRNSgray) /* transparent ? */ + { + *pRGBArow = 0; /* put in intermediate row */ + *(pRGBArow+1) = 0; + *(pRGBArow+2) = 0; + *(pRGBArow+3) = 0; + } + else + { + *pRGBArow = iB; /* put in intermediate row */ + *(pRGBArow+1) = iB; + *(pRGBArow+2) = iB; + *(pRGBArow+3) = 0xFF; + } + + pRGBArow += 4; /* next pixel */ + pWorkrow++; + } + + pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iB = *pWorkrow; /* get next input-byte */ + + *pRGBArow = iB; /* put in intermediate row */ + *(pRGBArow+1) = iB; + *(pRGBArow+2) = iB; + *(pRGBArow+3) = 0xFF; + + pRGBArow += 4; /* next pixel */ + pWorkrow++; + } + + pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_G8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_process_g16 (mng_datap pData) +{ + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint16 iW; + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_G16, MNG_LC_START); +#endif + + if (!pBuf) /* no object? then use obj 0 */ + pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pRGBArow = pData->pRGBArow; + + if (pBuf->bHasTRNS) /* tRNS encountered ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iW = mng_get_uint16 (pWorkrow); /* get input */ + + if (iW == pBuf->iTRNSgray) /* transparent ? */ + { /* put in intermediate row */ + mng_put_uint16 (pRGBArow, 0); + mng_put_uint16 (pRGBArow+2, 0); + mng_put_uint16 (pRGBArow+4, 0); + mng_put_uint16 (pRGBArow+6, 0); + } + else + { /* put in intermediate row */ + mng_put_uint16 (pRGBArow, iW); + mng_put_uint16 (pRGBArow+2, iW); + mng_put_uint16 (pRGBArow+4, iW); + mng_put_uint16 (pRGBArow+6, 0xFFFF); + } + + pRGBArow += 8; /* next pixel */ + pWorkrow += 2; + } + + pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iW = mng_get_uint16 (pWorkrow); /* get input */ + + mng_put_uint16 (pRGBArow, iW); /* and put in intermediate row */ + mng_put_uint16 (pRGBArow+2, iW); + mng_put_uint16 (pRGBArow+4, iW); + mng_put_uint16 (pRGBArow+6, 0xFFFF); + + pRGBArow += 8; /* next pixel */ + pWorkrow += 2; + } + + pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_G16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_rgb8 (mng_datap pData) +{ + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint8 iR, iG, iB; + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_RGB8, MNG_LC_START); +#endif + + if (!pBuf) /* no object? then use obj 0 */ + pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pRGBArow = pData->pRGBArow; + + if (pBuf->bHasTRNS) /* tRNS encountered ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iR = *pWorkrow; /* get the RGB values */ + iG = *(pWorkrow+1); + iB = *(pWorkrow+2); + /* transparent ? */ + if ((iR == pBuf->iTRNSred) && (iG == pBuf->iTRNSgreen) && + (iB == pBuf->iTRNSblue)) + { + *pRGBArow = 0; /* this pixel is transparent ! */ + *(pRGBArow+1) = 0; + *(pRGBArow+2) = 0; + *(pRGBArow+3) = 0; + } + else + { + *pRGBArow = iR; /* copy the RGB values */ + *(pRGBArow+1) = iG; + *(pRGBArow+2) = iB; + *(pRGBArow+3) = 0xFF; /* this one isn't transparent */ + } + + pWorkrow += 3; /* next pixel */ + pRGBArow += 4; + } + + pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pRGBArow = *pWorkrow; /* copy the RGB bytes */ + *(pRGBArow+1) = *(pWorkrow+1); + *(pRGBArow+2) = *(pWorkrow+2); + *(pRGBArow+3) = 0xFF; /* no alpha; so always fully opaque */ + + pWorkrow += 3; /* next pixel */ + pRGBArow += 4; + } + + pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_RGB8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_process_rgb16 (mng_datap pData) +{ + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint16 iR, iG, iB; + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_RGB16, MNG_LC_START); +#endif + + if (!pBuf) /* no object? then use obj 0 */ + pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pRGBArow = pData->pRGBArow; + + if (pBuf->bHasTRNS) /* tRNS encountered ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iR = mng_get_uint16 (pWorkrow); /* get the RGB values */ + iG = mng_get_uint16 (pWorkrow+2); + iB = mng_get_uint16 (pWorkrow+4); + /* transparent ? */ + if ((iR == pBuf->iTRNSred) && (iG == pBuf->iTRNSgreen) && + (iB == pBuf->iTRNSblue)) + { /* transparent then */ + mng_put_uint16 (pRGBArow, 0); + mng_put_uint16 (pRGBArow+2, 0); + mng_put_uint16 (pRGBArow+4, 0); + mng_put_uint16 (pRGBArow+6, 0); + } + else + { /* put in intermediate row */ + mng_put_uint16 (pRGBArow, iR); + mng_put_uint16 (pRGBArow+2, iG); + mng_put_uint16 (pRGBArow+4, iB); + mng_put_uint16 (pRGBArow+6, 0xFFFF); + } + + pWorkrow += 6; /* next pixel */ + pRGBArow += 8; + } + + pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* copy the RGB values */ + mng_put_uint16 (pRGBArow, mng_get_uint16 (pWorkrow )); + mng_put_uint16 (pRGBArow+2, mng_get_uint16 (pWorkrow+2)); + mng_put_uint16 (pRGBArow+4, mng_get_uint16 (pWorkrow+4)); + mng_put_uint16 (pRGBArow+6, 0xFFFF); + + pWorkrow += 6; /* next pixel */ + pRGBArow += 8; + } + + pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_RGB16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_retcode mng_process_idx1 (mng_datap pData) +{ + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + mng_uint8 iQ; + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_IDX1, MNG_LC_START); +#endif + + if (!pBuf) /* no object? then use obj 0 */ + pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pRGBArow = pData->pRGBArow; + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + + if (pBuf->bHasTRNS) /* tRNS encountered ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0x80; + iS = 7; + } + /* get the index */ + iQ = (mng_uint8)((iB & iM) >> iS); + /* index valid ? */ + if ((mng_uint32)iQ < pBuf->iPLTEcount) + { /* put in intermediate row */ + *pRGBArow = pBuf->aPLTEentries [iQ].iRed; + *(pRGBArow+1) = pBuf->aPLTEentries [iQ].iGreen; + *(pRGBArow+2) = pBuf->aPLTEentries [iQ].iBlue; + /* transparency for this index ? */ + if ((mng_uint32)iQ < pBuf->iTRNScount) + *(pRGBArow+3) = pBuf->aTRNSentries [iQ]; + else + *(pRGBArow+3) = 0xFF; + } + else + MNG_ERROR (pData, MNG_PLTEINDEXERROR); + + pRGBArow += 4; /* next pixel */ + iM >>= 1; + iS -= 1; + } + + pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0x80; + iS = 7; + } + /* get the index */ + iQ = (mng_uint8)((iB & iM) >> iS); + /* index valid ? */ + if ((mng_uint32)iQ < pBuf->iPLTEcount) + { /* put in intermediate row */ + *pRGBArow = pBuf->aPLTEentries [iQ].iRed; + *(pRGBArow+1) = pBuf->aPLTEentries [iQ].iGreen; + *(pRGBArow+2) = pBuf->aPLTEentries [iQ].iBlue; + *(pRGBArow+3) = 0xFF; + } + else + MNG_ERROR (pData, MNG_PLTEINDEXERROR); + + pRGBArow += 4; /* next pixel */ + iM >>= 1; + iS -= 1; + } + + pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_IDX1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_process_idx2 (mng_datap pData) +{ + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + mng_uint8 iQ; + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_IDX2, MNG_LC_START); +#endif + + if (!pBuf) /* no object? then use obj 0 */ + pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pRGBArow = pData->pRGBArow; + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + + if (pBuf->bHasTRNS) /* tRNS encountered ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xC0; + iS = 6; + } + /* get the index */ + iQ = (mng_uint8)((iB & iM) >> iS); + /* index valid ? */ + if ((mng_uint32)iQ < pBuf->iPLTEcount) + { /* put in intermediate row */ + *pRGBArow = pBuf->aPLTEentries [iQ].iRed; + *(pRGBArow+1) = pBuf->aPLTEentries [iQ].iGreen; + *(pRGBArow+2) = pBuf->aPLTEentries [iQ].iBlue; + /* transparency for this index ? */ + if ((mng_uint32)iQ < pBuf->iTRNScount) + *(pRGBArow+3) = pBuf->aTRNSentries [iQ]; + else + *(pRGBArow+3) = 0xFF; + } + else + MNG_ERROR (pData, MNG_PLTEINDEXERROR); + + pRGBArow += 4; /* next pixel */ + iM >>= 2; + iS -= 2; + } + + pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = *pWorkrow; /* get next input-byte */ + pWorkrow++; + iM = 0xC0; + iS = 6; + } + /* get the index */ + iQ = (mng_uint8)((iB & iM) >> iS); + /* index valid ? */ + if ((mng_uint32)iQ < pBuf->iPLTEcount) + { /* put in intermediate row */ + *pRGBArow = pBuf->aPLTEentries [iQ].iRed; + *(pRGBArow+1) = pBuf->aPLTEentries [iQ].iGreen; + *(pRGBArow+2) = pBuf->aPLTEentries [iQ].iBlue; + *(pRGBArow+3) = 0xFF; + } + else + MNG_ERROR (pData, MNG_PLTEINDEXERROR); + + pRGBArow += 4; /* next pixel */ + iM >>= 2; + iS -= 2; + } + + pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_IDX2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_process_idx4 (mng_datap pData) +{ + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint8 iB; + mng_uint8 iM; + mng_uint32 iS; + mng_uint8 iQ; + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_IDX4, MNG_LC_START); +#endif + + if (!pBuf) /* no object? then use obj 0 */ + pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pRGBArow = pData->pRGBArow; + iM = 0; /* start at pixel 0 */ + iB = 0; + iS = 0; + + if (pBuf->bHasTRNS) /* tRNS encountered ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = pWorkrow [0]; /* get next input-byte */ + pWorkrow++; + iM = 0xF0; + iS = 4; + } + /* get the index */ + iQ = (mng_uint8)((iB & iM) >> iS); + /* index valid ? */ + if ((mng_uint32)iQ < pBuf->iPLTEcount) + { /* put in intermediate row */ + pRGBArow [0] = pBuf->aPLTEentries [iQ].iRed; + pRGBArow [1] = pBuf->aPLTEentries [iQ].iGreen; + pRGBArow [2] = pBuf->aPLTEentries [iQ].iBlue; + /* transparency for this index ? */ + if ((mng_uint32)iQ < pBuf->iTRNScount) + pRGBArow [3] = pBuf->aTRNSentries [iQ]; + else + pRGBArow [3] = 0xFF; + } + else + MNG_ERROR (pData, MNG_PLTEINDEXERROR); + + pRGBArow += 4; /* next pixel */ + iM >>= 4; + iS -= 4; + } + + pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + if (!iM) /* mask underflow ? */ + { + iB = pWorkrow [0]; /* get next input-byte */ + pWorkrow++; + iM = 0xF0; + iS = 4; + } + /* get the index */ + iQ = (mng_uint8)((iB & iM) >> iS); + /* index valid ? */ + if ((mng_uint32)iQ < pBuf->iPLTEcount) + { /* put in intermediate row */ + pRGBArow [0] = pBuf->aPLTEentries [iQ].iRed; + pRGBArow [1] = pBuf->aPLTEentries [iQ].iGreen; + pRGBArow [2] = pBuf->aPLTEentries [iQ].iBlue; + pRGBArow [3] = 0xFF; + } + else + MNG_ERROR (pData, MNG_PLTEINDEXERROR); + + pRGBArow += 4; /* next pixel */ + iM >>= 4; + iS -= 4; + } + + pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_IDX4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + +/* ************************************************************************** */ + +mng_retcode mng_process_idx8 (mng_datap pData) +{ + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint8 iQ; + mng_imagedatap pBuf = (mng_imagedatap)pData->pStorebuf; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_IDX8, MNG_LC_START); +#endif + + if (!pBuf) /* no object? then use obj 0 */ + pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf; + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pRGBArow = pData->pRGBArow; + + if (pBuf->bHasTRNS) /* tRNS encountered ? */ + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iQ = *pWorkrow; /* get input byte */ + /* index valid ? */ + if ((mng_uint32)iQ < pBuf->iPLTEcount) + { /* put in intermediate row */ + pRGBArow [0] = pBuf->aPLTEentries [iQ].iRed; + pRGBArow [1] = pBuf->aPLTEentries [iQ].iGreen; + pRGBArow [2] = pBuf->aPLTEentries [iQ].iBlue; + /* transparency for this index ? */ + if ((mng_uint32)iQ < pBuf->iTRNScount) + pRGBArow [3] = pBuf->aTRNSentries [iQ]; + else + pRGBArow [3] = 0xFF; + } + else + MNG_ERROR (pData, MNG_PLTEINDEXERROR); + + pRGBArow += 4; /* next pixel */ + pWorkrow++; + } + + pData->bIsOpaque = MNG_FALSE; /* it's not fully opaque */ + } + else + { +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iQ = *pWorkrow; /* get input byte */ + /* index valid ? */ + if ((mng_uint32)iQ < pBuf->iPLTEcount) + { /* put in intermediate row */ + pRGBArow [0] = pBuf->aPLTEentries [iQ].iRed; + pRGBArow [1] = pBuf->aPLTEentries [iQ].iGreen; + pRGBArow [2] = pBuf->aPLTEentries [iQ].iBlue; + pRGBArow [3] = 0xFF; + } + else + MNG_ERROR (pData, MNG_PLTEINDEXERROR); + + pRGBArow += 4; /* next pixel */ + pWorkrow++; + } + + pData->bIsOpaque = MNG_TRUE; /* it's fully opaque */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_IDX8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_process_ga8 (mng_datap pData) +{ + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_GA8, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pRGBArow = pData->pRGBArow; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + *pRGBArow = *pWorkrow; /* copy the gray value */ + *(pRGBArow+1) = *pWorkrow; + *(pRGBArow+2) = *pWorkrow; + *(pRGBArow+3) = *(pWorkrow+1); /* copy the alpha value */ + + pWorkrow += 2; /* next pixel */ + pRGBArow += 4; + } + + pData->bIsOpaque = MNG_FALSE; /* it's definitely not fully opaque */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_GA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_process_ga16 (mng_datap pData) +{ + mng_uint8p pWorkrow; + mng_uint8p pRGBArow; + mng_int32 iX; + mng_uint16 iW; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_GA16, MNG_LC_START); +#endif + /* temporary work pointers */ + pWorkrow = pData->pWorkrow + pData->iPixelofs; + pRGBArow = pData->pRGBArow; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iW = mng_get_uint16 (pWorkrow); /* copy the gray value */ + mng_put_uint16 (pRGBArow, iW); + mng_put_uint16 (pRGBArow+2, iW); + mng_put_uint16 (pRGBArow+4, iW); + /* copy the alpha value */ + mng_put_uint16 (pRGBArow+6, mng_get_uint16 (pWorkrow+2)); + + pWorkrow += 4; /* next pixel */ + pRGBArow += 8; + } + + pData->bIsOpaque = MNG_FALSE; /* it's definitely not fully opaque */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_GA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_process_rgba8 (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_RGBA8, MNG_LC_START); +#endif + /* this is the easiest transform */ + MNG_COPY (pData->pRGBArow, pData->pWorkrow + pData->iPixelofs, pData->iRowsize); + + pData->bIsOpaque = MNG_FALSE; /* it's definitely not fully opaque */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_process_rgba16 (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_RGBA16, MNG_LC_START); +#endif + /* this is the easiest transform */ + MNG_COPY (pData->pRGBArow, pData->pWorkrow + pData->iPixelofs, pData->iRowsize); + + pData->bIsOpaque = MNG_FALSE; /* it's definitely not fully opaque */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ +/* * * */ +/* * Row processing initialization routines - set up the variables needed * */ +/* * to process uncompressed row-data * */ +/* * * */ +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_FOOTPRINT_INIT +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_retcode mng_init_g1_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G1_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_g1; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_g1; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_g1; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g1; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 1; + pData->iSampleofs = 7; + pData->iSamplediv = 3; + pData->iRowsize = (pData->iRowsamples + 7) >> 3; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G1_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_g1_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G1_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_g1; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_g1; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_g1; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g1; +#endif + + pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 1; + pData->iSampleofs = 7; + pData->iSamplediv = 3; + pData->iRowsize = ((pData->iRowsamples + 7) >> 3); + pData->iRowmax = ((pData->iDatawidth + 7) >> 3) + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G1_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_g2_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G2_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_g2; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_g2; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_g2; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g2; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 1; + pData->iSampleofs = 3; + pData->iSamplediv = 2; + pData->iRowsize = (pData->iRowsamples + 3) >> 2; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G2_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_g2_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G2_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_g2; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_g2; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_g2; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g2; +#endif + + pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 1; + pData->iSampleofs = 3; + pData->iSamplediv = 2; + pData->iRowsize = ((pData->iRowsamples + 3) >> 2); + pData->iRowmax = ((pData->iDatawidth + 3) >> 2) + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G2_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_g4_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G4_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_g4; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_g4; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_g4; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g4; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 1; + pData->iSampleofs = 1; + pData->iSamplediv = 1; + pData->iRowsize = (pData->iRowsamples + 1) >> 1; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G4_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_g4_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G4_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_g4; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_g4; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_g4; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g4; +#endif + + pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 1; + pData->iSampleofs = 1; + pData->iSamplediv = 1; + pData->iRowsize = ((pData->iRowsamples + 1) >> 1); + pData->iRowmax = ((pData->iDatawidth + 1) >> 1) + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G4_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + +/* ************************************************************************** */ + +mng_retcode mng_init_g8_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G8_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_g8; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_g8; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_g8; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g8; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 1; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G8_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_g8_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G8_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_g8; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_g8; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_g8; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g8; +#endif + + pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 1; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples; + pData->iRowmax = pData->iDatawidth + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G8_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_init_g16_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G16_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_g16; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_g16; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_g16; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g16; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 2; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples << 1; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 2; + pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G16_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_init_g16_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G16_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_g16; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_g16; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_g16; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g16; +#endif + + pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 2; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples << 1; + pData->iRowmax = (pData->iDatawidth << 1) + pData->iPixelofs; + pData->iFilterbpp = 2; + pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_G16_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_init_rgb8_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGB8_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_rgb8; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_rgb8; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_rgb8; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_rgb8; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 3; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples * 3; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 3; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGB8_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_rgb8_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGB8_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_rgb8; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_rgb8; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_rgb8; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_rgb8; +#endif + + pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 3; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples * 3; + pData->iRowmax = (pData->iDatawidth * 3) + pData->iPixelofs; + pData->iFilterbpp = 3; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGB8_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_init_rgb16_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGB16_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_rgb16; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_rgb16; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_rgb16; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_rgb16; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 6; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples * 6; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 6; + pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGB16_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_init_rgb16_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGB16_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_rgb16; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_rgb16; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_rgb16; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_rgb16; +#endif + + pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 6; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples * 6; + pData->iRowmax = (pData->iDatawidth * 6) + pData->iPixelofs; + pData->iFilterbpp = 6; + pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGB16_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_retcode mng_init_idx1_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX1_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_idx1; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_idx1; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_idx1; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_idx1; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 1; + pData->iSampleofs = 7; + pData->iSamplediv = 3; + pData->iRowsize = (pData->iRowsamples + 7) >> 3; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX1_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_idx1_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX1_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_idx1; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_idx1; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_idx1; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_idx1; +#endif + + pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 1; + pData->iSampleofs = 7; + pData->iSamplediv = 3; + pData->iRowsize = (pData->iRowsamples + 7) >> 3; + pData->iRowmax = ((pData->iDatawidth + 7) >> 3) + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX1_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_idx2_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX2_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_idx2; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_idx2; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_idx2; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_idx2; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 1; + pData->iSampleofs = 3; + pData->iSamplediv = 2; + pData->iRowsize = (pData->iRowsamples + 3) >> 2; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX2_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_idx2_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX2_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_idx2; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_idx2; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_idx2; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_idx2; +#endif + + pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 1; + pData->iSampleofs = 3; + pData->iSamplediv = 2; + pData->iRowsize = (pData->iRowsamples + 3) >> 2; + pData->iRowmax = ((pData->iDatawidth + 3) >> 2) + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX2_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_idx4_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX4_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_idx4; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_idx4; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_idx4; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_idx4; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 1; + pData->iSampleofs = 1; + pData->iSamplediv = 1; + pData->iRowsize = (pData->iRowsamples + 1) >> 1; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX4_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_idx4_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX4_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_idx4; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_idx4; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_idx4; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_idx4; +#endif + + pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 1; + pData->iSampleofs = 1; + pData->iSamplediv = 1; + pData->iRowsize = (pData->iRowsamples + 1) >> 1; + pData->iRowmax = ((pData->iDatawidth + 1) >> 1) + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX4_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + +/* ************************************************************************** */ + +mng_retcode mng_init_idx8_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX8_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_idx8; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_idx8; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_idx8; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_idx8; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 1; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX8_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_idx8_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX8_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_idx8; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_idx8; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_idx8; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_idx8; +#endif + + pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 1; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples; + pData->iRowmax = pData->iDatawidth + pData->iPixelofs; + pData->iFilterbpp = 1; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_IDX8_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_ga8_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_GA8_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_ga8; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_ga8; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_ga8; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_ga8; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 2; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples << 1; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 2; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_GA8_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_ga8_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_GA8_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_ga8; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_ga8; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_ga8; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_ga8; +#endif + + pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 2; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples << 1; + pData->iRowmax = (pData->iDatawidth << 1) + pData->iPixelofs; + pData->iFilterbpp = 2; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_GA8_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_init_ga16_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_GA16_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_ga16; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_ga16; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_ga16; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_ga16; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 4; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples << 2; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 4; + pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_GA16_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_init_ga16_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_GA16_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_ga16; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_ga16; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_ga16; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_ga16; +#endif + + pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 4; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples << 2; + pData->iRowmax = (pData->iDatawidth << 2) + pData->iPixelofs; + pData->iFilterbpp = 4; + pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_GA16_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_init_rgba8_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGBA8_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_rgba8; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_rgba8; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_rgba8; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_rgba8; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 4; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples << 2; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 4; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGBA8_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} +/* ************************************************************************** */ + +mng_retcode mng_init_rgba8_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGBA8_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_rgba8; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_rgba8; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_rgba8; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_rgba8; +#endif + + pData->iPass = 0; /* from 0..6; is 1..7 in specifications */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 4; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples << 2; + pData->iRowmax = (pData->iDatawidth << 2) + pData->iPixelofs; + pData->iFilterbpp = 4; + pData->bIsRGBA16 = MNG_FALSE; /* intermediate row is 8-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGBA8_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_init_rgba16_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGBA16_NI, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_rgba16; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_rgba16; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_rgba16; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_rgba16; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 8; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples << 3; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 8; + pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGBA16_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_init_rgba16_i (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGBA16_I, MNG_LC_START); +#endif + + if (pData->fDisplayrow) + pData->fProcessrow = (mng_fptr)mng_process_rgba16; + + if (pData->pStoreobj) /* store in object too ? */ + { /* immediate delta ? */ +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + pData->fStorerow = (mng_fptr)mng_delta_rgba16; + else +#endif + pData->fStorerow = (mng_fptr)mng_store_rgba16; + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_rgba16; +#endif + + pData->iPass = 0; /* from 0..6; (1..7 in specification) */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> interlace_divider [0]; + pData->iSamplemul = 8; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples << 3; + pData->iRowmax = (pData->iDatawidth << 3) + pData->iPixelofs; + pData->iFilterbpp = 8; + pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_RGBA16_I, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} +#endif + +/* ************************************************************************** */ +/* * * */ +/* * Row processing initialization routines (JPEG) - set up the variables * */ +/* * needed to process uncompressed row-data * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG + +/* ************************************************************************** */ + +#ifndef MNG_NO_1_2_4BIT_SUPPORT +mng_retcode mng_init_jpeg_a1_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JPEG_A1_NI, MNG_LC_START); +#endif + + if (pData->pStoreobj) /* store in object too ? */ + { + if (pData->iJHDRimgbitdepth == 8) + { + switch (pData->iJHDRcolortype) + { + case 12 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a1; break; } + case 14 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a1; break; } + } + } + + /* TODO: bitdepth 12 & 20 */ + + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g1; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 1; + pData->iSampleofs = 7; + pData->iSamplediv = 3; + pData->iRowsize = (pData->iRowsamples + 7) >> 3; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 1; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JPEG_A1_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_jpeg_a2_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JPEG_A2_NI, MNG_LC_START); +#endif + + if (pData->pStoreobj) /* store in object too ? */ + { + if (pData->iJHDRimgbitdepth == 8) + { + switch (pData->iJHDRcolortype) + { + case 12 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a2; break; } + case 14 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a2; break; } + } + } + + /* TODO: bitdepth 12 & 20 */ + + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g2; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 1; + pData->iSampleofs = 3; + pData->iSamplediv = 2; + pData->iRowsize = (pData->iRowsamples + 3) >> 2; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 1; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JPEG_A2_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_init_jpeg_a4_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JPEG_A4_NI, MNG_LC_START); +#endif + + if (pData->pStoreobj) /* store in object too ? */ + { + if (pData->iJHDRimgbitdepth == 8) + { + switch (pData->iJHDRcolortype) + { + case 12 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a4; break; } + case 14 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a4; break; } + } + } + + /* TODO: bitdepth 12 & 20 */ + + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g4; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 1; + pData->iSampleofs = 1; + pData->iSamplediv = 1; + pData->iRowsize = (pData->iRowsamples + 1) >> 1; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 1; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JPEG_A4_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + +/* ************************************************************************** */ + +mng_retcode mng_init_jpeg_a8_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JPEG_A8_NI, MNG_LC_START); +#endif + + if (pData->pStoreobj) /* store in object too ? */ + { + if (pData->iJHDRimgbitdepth == 8) + { + switch (pData->iJHDRcolortype) + { + case 12 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a8; break; } + case 14 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a8; break; } + } + } + + /* TODO: bitdepth 12 & 20 */ + + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g8; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 1; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 1; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JPEG_A8_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_init_jpeg_a16_ni (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JPEG_A16_NI, MNG_LC_START); +#endif + + if (pData->pStoreobj) /* store in object too ? */ + { + if (pData->iJHDRimgbitdepth == 8) + { + switch (pData->iJHDRcolortype) + { + case 12 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a16; break; } + case 14 : { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a16; break; } + } + } + + /* TODO: bitdepth 12 & 20 */ + + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + pData->fDifferrow = (mng_fptr)mng_differ_g16; +#endif + + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + pData->iSamplemul = 2; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iRowsize = pData->iRowsamples << 1; + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + pData->iFilterbpp = 2; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_JPEG_A16_NI, MNG_LC_END); +#endif + + return mng_init_rowproc (pData); +} +#endif + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_JNG */ +#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ + + +/* ************************************************************************** */ +/* * * */ +/* * Generic row processing initialization & cleanup routines * */ +/* * - initialize the buffers used by the row processing routines * */ +/* * - cleanup the buffers used by the row processing routines * */ +/* * * */ +/* ************************************************************************** */ + +mng_retcode mng_init_rowproc (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_ROWPROC, MNG_LC_START); +#endif + +#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT + if (pData->ePng_imgtype != png_none) + { + if (pData->fDisplayrow) + switch (pData->ePng_imgtype) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case png_g1: + pData->fProcessrow = (mng_fptr)mng_process_g1; + break; + case png_g2: + pData->fProcessrow = (mng_fptr)mng_process_g2; + break; + case png_g4: + pData->fProcessrow = (mng_fptr)mng_process_g4; + break; +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case png_g8: + pData->fProcessrow = (mng_fptr)mng_process_g8; + break; +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case png_idx1: + pData->fProcessrow = (mng_fptr)mng_process_idx1; + break; + case png_idx2: + pData->fProcessrow = (mng_fptr)mng_process_idx2; + break; + case png_idx4: + pData->fProcessrow = (mng_fptr)mng_process_idx4; + break; +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case png_idx8: + pData->fProcessrow = (mng_fptr)mng_process_idx8; + break; + case png_ga8: + pData->fProcessrow = (mng_fptr)mng_process_ga8; + break; + case png_rgb8: + pData->fProcessrow = (mng_fptr)mng_process_rgb8; + break; + case png_rgba8: + pData->fProcessrow = (mng_fptr)mng_process_rgba8; + break; +#ifndef MNG_NO_16BIT_SUPPORT + case png_g16: + pData->fProcessrow = (mng_fptr)mng_process_g16; + break; + case png_ga16: + pData->fProcessrow = (mng_fptr)mng_process_ga16; + break; + case png_rgb16: + pData->fProcessrow = (mng_fptr)mng_process_rgb16; + break; + case png_rgba16: + pData->fProcessrow = (mng_fptr)mng_process_rgba16; + break; +#endif + default: + break; + } + + if (pData->pStoreobj) /* store in object too ? */ + { +#ifndef MNG_NO_DELTA_PNG + if ((pData->bHasDHDR) && (pData->bDeltaimmediate)) + switch (pData->ePng_imgtype) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case png_g1: + pData->fStorerow = (mng_fptr)mng_delta_g1; + break; + case png_g2: + pData->fStorerow = (mng_fptr)mng_delta_g2; + break; + case png_g4: + pData->fStorerow = (mng_fptr)mng_delta_g4; + break; +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case png_g8: + pData->fStorerow = (mng_fptr)mng_delta_g8; + break; +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case png_idx1: + pData->fStorerow = (mng_fptr)mng_delta_idx1; + break; + case png_idx2: + pData->fStorerow = (mng_fptr)mng_delta_idx2; + break; + case png_idx4: + pData->fStorerow = (mng_fptr)mng_delta_idx4; + break; +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case png_idx8: + pData->fStorerow = (mng_fptr)mng_delta_idx8; + break; + case png_ga8: + pData->fStorerow = (mng_fptr)mng_delta_ga8; + break; + case png_rgb8: + pData->fStorerow = (mng_fptr)mng_delta_rgb8; + break; + case png_rgba8: + pData->fStorerow = (mng_fptr)mng_delta_rgba8; + break; +#ifndef MNG_NO_16BIT_SUPPORT + case png_g16: + pData->fStorerow = (mng_fptr)mng_delta_g16; + break; + case png_ga16: + pData->fStorerow = (mng_fptr)mng_delta_ga16; + break; + case png_rgb16: + pData->fStorerow = (mng_fptr)mng_delta_rgb16; + break; + case png_rgba16: + pData->fStorerow = (mng_fptr)mng_delta_rgba16; + break; +#endif + default: + break; + } + else +#endif /* MNG_NO_DELTA_PNG */ + switch (pData->ePng_imgtype) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case png_g1: + pData->fStorerow = (mng_fptr)mng_store_g1; + break; + case png_g2: + pData->fStorerow = (mng_fptr)mng_store_g2; + break; + case png_g4: + pData->fStorerow = (mng_fptr)mng_store_g4; + break; +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case png_g8: + pData->fStorerow = (mng_fptr)mng_store_g8; + break; +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case png_idx1: + pData->fStorerow = (mng_fptr)mng_store_idx1; + break; + case png_idx2: + pData->fStorerow = (mng_fptr)mng_store_idx2; + break; + case png_idx4: + pData->fStorerow = (mng_fptr)mng_store_idx4; + break; +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case png_idx8: + pData->fStorerow = (mng_fptr)mng_store_idx8; + break; + case png_ga8: + pData->fStorerow = (mng_fptr)mng_store_ga8; + break; + case png_rgb8: + pData->fStorerow = (mng_fptr)mng_store_rgb8; + break; + case png_rgba8: + pData->fStorerow = (mng_fptr)mng_store_rgba8; + break; +#ifndef MNG_NO_16BIT_SUPPORT + case png_g16: + pData->fStorerow = (mng_fptr)mng_store_g16; + break; + case png_ga16: + pData->fStorerow = (mng_fptr)mng_store_ga16; + break; + case png_rgb16: + pData->fStorerow = (mng_fptr)mng_store_rgb16; + break; + case png_rgba16: + pData->fStorerow = (mng_fptr)mng_store_rgba16; + break; +#endif + +#ifdef MNG_INCLUDE_JNG +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case png_jpeg_a1: +/* if (pData->iJHDRimgbitdepth == 8) */ + { + switch (pData->iJHDRcolortype) + { + case 12 : + { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a1; break; } + case 14 : + { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a1; break; } + } + } + /* TODO: bitdepth 12 & 20 */ + break; + case png_jpeg_a2: +/* if (pData->iJHDRimgbitdepth == 8) */ + { + switch (pData->iJHDRcolortype) + { + case 12 : + { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a2; break; } + case 14 : + { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a2; break; } + } + } + break; + /* TODO: bitdepth 12 & 20 */ + case png_jpeg_a4: +/* if (pData->iJHDRimgbitdepth == 8) */ + { + switch (pData->iJHDRcolortype) + { + case 12 : + { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a4; break; } + case 14 : + { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a4; break; } + } + } + break; +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + /* TODO: bitdepth 12 & 20 */ + case png_jpeg_a8: +/* if (pData->iJHDRimgbitdepth == 8) */ + { + switch (pData->iJHDRcolortype) + { + case 12 : + { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a8; break; } + case 14 : + { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a8; break; } + } + } + break; + /* TODO: bitdepth 12 & 20 */ +#ifndef MNG_NO_16BIT_SUPPORT + case png_jpeg_a16: +/* if (pData->iJHDRimgbitdepth == 8) */ + { + switch (pData->iJHDRcolortype) + { + case 12 : + { pData->fStorerow = (mng_fptr)mng_store_jpeg_g8_a16; break; } + case 14 : + { pData->fStorerow = (mng_fptr)mng_store_jpeg_rgb8_a16; break; } + } + } + break; + /* TODO: bitdepth 12 & 20 */ +#endif +#endif /* MNG_INCLUDE_JNG */ + default: + break; + } + } + +#ifdef FILTER192 /* leveling & differing ? */ + if (pData->iFilter == MNG_FILTER_DIFFERING) + switch (pData->ePng_imgtype) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case png_g1: +#ifdef MNG_INCLUDE_JNG + case png_jpeg_a1: +#endif + pData->fDifferrow = (mng_fptr)mng_differ_g1; + break; + case png_g2: +#ifdef MNG_INCLUDE_JNG + case png_jpeg_a2: +#endif + pData->fDifferrow = (mng_fptr)mng_differ_g2; + break; + case png_g4: +#ifdef MNG_INCLUDE_JNG + case png_jpeg_a4: +#endif + pData->fDifferrow = (mng_fptr)mng_differ_g4; + break; +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case png_g8: +#ifdef MNG_INCLUDE_JNG + case png_jpeg_a8: +#endif + pData->fDifferrow = (mng_fptr)mng_differ_g8; + break; + case png_rgb8: + pData->fDifferrow = (mng_fptr)mng_differ_rgb8; + break; +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case png_idx1: + pData->fDifferrow = (mng_fptr)mng_differ_idx1; + break; + case png_idx2: + pData->fDifferrow = (mng_fptr)mng_differ_idx2; + break; + case png_idx4: + pData->fDifferrow = (mng_fptr)mng_differ_idx4; + break; +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case png_idx8: + pData->fDifferrow = (mng_fptr)mng_differ_idx8; + break; + case png_ga8: + pData->fDifferrow = (mng_fptr)mng_differ_ga8; + break; + case png_rgb8: + pData->fDifferrow = (mng_fptr)mng_differ_rgb8; + break; + case png_rgba8: + pData->fDifferrow = (mng_fptr)mng_differ_rgba8; + break; +#ifndef MNG_NO_16BIT_SUPPORT + case png_g16: +#ifdef MNG_INCLUDE_JNG + case png_jpeg_a16: +#endif + pData->fDifferrow = (mng_fptr)mng_differ_g16; + break; + case png_ga16: + pData->fDifferrow = (mng_fptr)mng_differ_ga16; + break; + case png_rgb16: + pData->fDifferrow = (mng_fptr)mng_differ_rgb16; + break; + case png_rgba16: + pData->fDifferrow = (mng_fptr)mng_differ_rgba16; + break; +#endif + default: + break; + } +#endif + + switch (pData->ePng_imgtype) + { +#ifndef MNG_NO_1_2_4BIT_SUPPORT + case png_g1: + case png_idx1: +#ifdef MNG_INCLUDE_JNG + case png_jpeg_a1: +#endif + pData->iSamplemul = 1; + pData->iSampleofs = 7; + pData->iSamplediv = 3; + pData->iFilterbpp = 1; + break; + case png_g2: + case png_idx2: +#ifdef MNG_INCLUDE_JNG + case png_jpeg_a2: +#endif + pData->iSamplemul = 1; + pData->iSampleofs = 3; + pData->iSamplediv = 2; + pData->iFilterbpp = 1; + break; + case png_g4: + case png_idx4: +#ifdef MNG_INCLUDE_JNG + case png_jpeg_a4: +#endif + pData->iSamplemul = 1; + pData->iSampleofs = 1; + pData->iSamplediv = 1; + pData->iFilterbpp = 1; + break; +#endif /* MNG_NO_1_2_4BIT_SUPPORT */ + case png_g8: + case png_idx8: +#ifdef MNG_INCLUDE_JNG + case png_jpeg_a8: +#endif + pData->iSamplemul = 1; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iFilterbpp = 1; + break; + case png_ga8: +#ifndef MNG_NO_16BIT_SUPPORT + case png_g16: +#ifdef MNG_INCLUDE_JNG + case png_jpeg_a16: +#endif +#endif + pData->iSamplemul = 2; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iFilterbpp = 2; + break; + case png_rgb8: + pData->iSamplemul = 3; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iFilterbpp = 3; + break; +#ifndef MNG_NO_16BIT_SUPPORT + case png_ga16: +#endif + case png_rgba8: + pData->iSamplemul = 4; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iFilterbpp = 4; + break; +#ifndef MNG_NO_16BIT_SUPPORT + case png_rgb16: + pData->iSamplemul = 6; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iFilterbpp = 6; + break; + case png_rgba16: + pData->iSamplemul = 8; + pData->iSampleofs = 0; + pData->iSamplediv = 0; + pData->iFilterbpp = 8; + break; +#endif + default: + break; + } + + if (pData->iInterlace) /* noninterlaced */ + { + pData->iPass = 0; /* from 0..6; (1..7 in specification) */ + pData->iRow = interlace_row [0]; + pData->iRowinc = interlace_rowskip [0]; + pData->iCol = interlace_col [0]; + pData->iColinc = interlace_colskip [0]; + pData->iRowsamples = (pData->iDatawidth + interlace_roundoff [0]) >> + interlace_divider [0]; + pData->iRowmax = ((pData->iDatawidth * pData->iSamplemul + + pData->iSampleofs) >> pData->iSamplediv) + pData->iPixelofs; + } + else /* interlaced */ + { + pData->iPass = -1; + pData->iRow = 0; + pData->iRowinc = 1; + pData->iCol = 0; + pData->iColinc = 1; + pData->iRowsamples = pData->iDatawidth; + } + if (pData->iSamplediv > 0) + pData->iRowsize = (pData->iRowsamples + pData->iSampleofs) >> + pData->iSamplediv; + else + pData->iRowsize = (pData->iRowsamples * pData->iSamplemul); + + if (!pData->iInterlace) /* noninterlaced */ + pData->iRowmax = pData->iRowsize + pData->iPixelofs; + +#ifdef MNG_NO_16BIT_SUPPORT + pData->bIsRGBA16 = MNG_FALSE; +#else + switch (pData->ePng_imgtype) + { + case png_g16: + case png_ga16: + case png_rgb16: + case png_rgba16: + pData->bIsRGBA16 = MNG_TRUE; + break; + default: + pData->bIsRGBA16 = MNG_FALSE; + break; + } +#endif + + } +#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */ + + if (pData->pStoreobj) /* storage object selected ? */ + { + pData->pStorebuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + /* and so it becomes viewable ! */ + ((mng_imagep)pData->pStoreobj)->bViewable = MNG_TRUE; + ((mng_imagedatap)pData->pStorebuf)->bViewable = MNG_TRUE; + } + + /* allocate the buffers; the individual init routines have already + calculated the required maximum size; except in the case of a JNG + without alpha!!! */ + if (pData->iRowmax) + { +#if defined(MNG_NO_16BIT_SUPPORT) || defined (MNG_NO_1_2_4BIT_SUPPORT) + mng_uint8 iRowadd = 0; +#ifdef MNG_NO_1_2_4BIT_SUPPORT + if (pData->iPNGdepth < 8) + iRowadd=(pData->iPNGdepth*pData->iRowmax+7)/8; +#endif +#ifdef MNG_NO_16BIT_SUPPORT + if (pData->iPNGdepth > 8) + iRowadd=pData->iRowmax; +#endif + MNG_ALLOC (pData, pData->pWorkrow, pData->iRowmax+iRowadd); + MNG_ALLOC (pData, pData->pPrevrow, pData->iRowmax+iRowadd); +#else + MNG_ALLOC (pData, pData->pWorkrow, pData->iRowmax); + MNG_ALLOC (pData, pData->pPrevrow, pData->iRowmax); +#endif + } + + /* allocate an RGBA16 row for intermediate processing */ + MNG_ALLOC (pData, pData->pRGBArow, (pData->iDatawidth << 3)); + +#ifndef MNG_NO_CMS + if (pData->fDisplayrow) /* display "on-the-fly" ? */ + { +#if defined(MNG_FULL_CMS) /* determine color-management initialization */ + mng_retcode iRetcode = mng_init_full_cms (pData, MNG_TRUE, MNG_TRUE, MNG_FALSE); +#elif defined(MNG_GAMMA_ONLY) + mng_retcode iRetcode = mng_init_gamma_only (pData, MNG_TRUE, MNG_TRUE, MNG_FALSE); +#elif defined(MNG_APP_CMS) + mng_retcode iRetcode = mng_init_app_cms (pData, MNG_TRUE, MNG_TRUE, MNG_FALSE); +#endif + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* !MNG_NO_CMS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_INIT_ROWPROC, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_next_row (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_NEXT_ROW, MNG_LC_START); +#endif + + pData->iRow += pData->iRowinc; /* increase the row counter */ + + if (pData->iPass >= 0) /* interlaced ? */ + { + while ((pData->iPass < 7) && /* went 'outside' the image ? */ + ((pData->iRow >= (mng_int32)pData->iDataheight) || + (pData->iCol >= (mng_int32)pData->iDatawidth ) )) + { + pData->iPass++; /* next pass ! */ + + if (pData->iPass < 7) /* there's only 7 passes ! */ + { + pData->iRow = interlace_row [pData->iPass]; + pData->iRowinc = interlace_rowskip [pData->iPass]; + pData->iCol = interlace_col [pData->iPass]; + pData->iColinc = interlace_colskip [pData->iPass]; + pData->iRowsamples = (pData->iDatawidth - pData->iCol + interlace_roundoff [pData->iPass]) + >> interlace_divider [pData->iPass]; + + if (pData->iSamplemul > 1) /* recalculate row dimension */ + pData->iRowsize = pData->iRowsamples * pData->iSamplemul; + else + if (pData->iSamplediv > 0) + pData->iRowsize = (pData->iRowsamples + pData->iSampleofs) >> pData->iSamplediv; + else + pData->iRowsize = pData->iRowsamples; + + } + + if ((pData->iPass < 7) && /* reset previous row to zeroes ? */ + (pData->iRow < (mng_int32)pData->iDataheight) && + (pData->iCol < (mng_int32)pData->iDatawidth ) ) + { /* making sure the filters will work properly! */ + mng_int32 iX; + mng_uint8p pTemp = pData->pPrevrow; + +#ifdef MNG_NO_16BIT_SUPPORT +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iPNGmult*pData->iRowsize; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iPNGmult*pData->iRowsize; iX++) +#endif +#else +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsize; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsize; iX++) +#endif +#endif + { + *pTemp = 0; + pTemp++; + } + } + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_NEXT_ROW, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_cleanup_rowproc (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CLEANUP_ROWPROC, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_LCMS /* cleanup cms profile/transform */ + { + mng_retcode iRetcode = mng_clear_cms (pData); + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif /* MNG_INCLUDE_LCMS */ + + if (pData->pRGBArow) /* cleanup buffer for intermediate row */ + MNG_FREEX (pData, pData->pRGBArow, (pData->iDatawidth << 3)); + if (pData->pPrevrow) /* cleanup buffer for previous row */ + MNG_FREEX (pData, pData->pPrevrow, pData->iRowmax); + if (pData->pWorkrow) /* cleanup buffer for working row */ + MNG_FREEX (pData, pData->pWorkrow, pData->iRowmax); + + pData->pWorkrow = MNG_NULL; /* propogate uninitialized buffers */ + pData->pPrevrow = MNG_NULL; + pData->pRGBArow = MNG_NULL; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_CLEANUP_ROWPROC, MNG_LC_END); +#endif + + return MNG_NOERROR; /* woohiii */ +} + +/* ************************************************************************** */ +/* * * */ +/* * Generic row processing routines for JNG * */ +/* * * */ +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG + +/* ************************************************************************** */ + +mng_retcode mng_display_jpeg_rows (mng_datap pData) +{ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_JPEG_ROWS, MNG_LC_START); +#endif + /* any completed rows ? */ + if ((pData->iJPEGrow > pData->iJPEGdisprow) && + (pData->iJPEGalpharow > pData->iJPEGdisprow) ) + { + mng_uint32 iX, iMax; + mng_uint32 iSaverow = pData->iRow; /* save alpha decompression row-count */ + /* determine the highest complete(!) row */ + if (pData->iJPEGrow > pData->iJPEGalpharow) + iMax = pData->iJPEGalpharow; + else + iMax = pData->iJPEGrow; + /* display the rows */ + for (iX = pData->iJPEGdisprow; iX < iMax; iX++) + { + pData->iRow = iX; /* make sure we all know which row to handle */ + /* makeup an intermediate row from the buffer */ + iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData); + /* color-correct it if necessary */ + if ((!iRetcode) && (pData->fCorrectrow)) + iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData); + + if (!iRetcode) /* and display it */ + { + iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData); + + if (!iRetcode) /* check progressive display refresh */ + iRetcode = mng_display_progressive_check (pData); + } + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + + pData->iJPEGdisprow = iMax; /* keep track of the last displayed row */ + pData->iRow = iSaverow; /* restore alpha decompression row-count */ + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DISPLAY_JPEG_ROWS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_next_jpeg_alpharow (mng_datap pData) +{ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_NEXT_JPEG_ALPHAROW, MNG_LC_START); +#endif + + pData->iJPEGalpharow++; /* count the row */ + + if (pData->fDisplayrow) /* display "on-the-fly" ? */ + { /* try to display what you can */ + iRetcode = mng_display_jpeg_rows (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_NEXT_JPEG_ALPHAROW, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_next_jpeg_row (mng_datap pData) +{ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_NEXT_JPEG_ROW, MNG_LC_START); +#endif + + pData->iJPEGrow++; /* increase the row-counter */ + + if (pData->fDisplayrow) /* display "on-the-fly" ? */ + { /* has alpha channel ? */ + if ((pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) || + (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) + { /* try to display what you can */ + iRetcode = mng_display_jpeg_rows (pData); + } + else + { /* make sure we all know which row to handle */ + pData->iRow = pData->iJPEGrow - 1; + /* makeup an intermediate row from the buffer */ + iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData); + /* color-correct it if necessary */ + if ((!iRetcode) && (pData->fCorrectrow)) + iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData); + + if (!iRetcode) /* and display it */ + { + iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData); + + if (!iRetcode) /* check progressive display refresh */ + iRetcode = mng_display_progressive_check (pData); + } + } + + if (iRetcode) /* on error bail out */ + return iRetcode; + } + + /* surpassed last filled row ? */ + if (pData->iJPEGrow > pData->iJPEGrgbrow) + pData->iJPEGrgbrow = pData->iJPEGrow; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_NEXT_JPEG_ROW, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_MAGN +#ifndef MNG_OPTIMIZE_FOOTPRINT_MAGN +#ifndef MNG_NO_GRAY_SUPPORT +mng_retcode mng_magnify_g8_x1 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX, iS, iM; + mng_uint8p pTempsrc1; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_X1, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + + if (iX == 0) /* first interval ? */ + iM = iML; + else + if (iX == (iWidth - 1)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + + for (iS = 1; iS < iM; iS++) /* fill interval */ + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + } + + pTempsrc1++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_X1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_g8_x2 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_X2, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 1; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { /* is it same as first ? */ + if (*pTempsrc1 == *pTempsrc2) + { + for (iS = 1; iS < iM; iS++) /* then just repeat the first */ + { + *pTempdst = *pTempsrc1; + pTempdst++; + } + } + else + { + for (iS = 1; iS < iM; iS++) /* calculate the distances */ + { + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2)) + (mng_int32)(*pTempsrc1) ); + pTempdst++; + } + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + } + } + } + + pTempsrc1++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_X2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_g8_x3 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_X3, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 1; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { /* is it same as first ? */ + if (*pTempsrc1 == *pTempsrc2) + { + for (iS = 1; iS < iM; iS++) /* then just repeat the first */ + { + *pTempdst = *pTempsrc1; + pTempdst++; + } + } + else + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* replicate first half */ + { + *pTempdst = *pTempsrc1; + pTempdst++; + } + + for (iS = iH; iS < iM; iS++) /* replicate second half */ + { + *pTempdst = *pTempsrc2; + pTempdst++; + } + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + } + } + } + + pTempsrc1++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_X3, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_GRAY_SUPPORT */ + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgb8_x1 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX, iS, iM; + mng_uint8p pTempsrc1; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_X1, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + + if (iX == 0) /* first interval ? */ + iM = iML; + else + if (iX == (iWidth - 1)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + + for (iS = 1; iS < iM; iS++) /* fill interval */ + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + } + + pTempsrc1 += 3; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_X1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgb8_x2 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_X2, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 3; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = (mng_int32)iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = (mng_int32)iMR; + else + iM = (mng_int32)iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + for (iS = 1; iS < iM; iS++) + { + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; /* just repeat the first */ + else /* calculate the distance */ + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2)) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + + if (*(pTempsrc1+1) == *(pTempsrc2+1)) + *pTempdst = *(pTempsrc1+1); + else + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+1)) - + (mng_int32)(*(pTempsrc1+1)) ) + iM) / + (iM * 2)) + (mng_int32)(*(pTempsrc1+1)) ); + + pTempdst++; + + if (*(pTempsrc1+2) == *(pTempsrc2+2)) + *pTempdst = *(pTempsrc1+2); + else + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+2)) - + (mng_int32)(*(pTempsrc1+2)) ) + iM) / + (iM * 2)) + (mng_int32)(*(pTempsrc1+2)) ); + + pTempdst++; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + } + } + } + + pTempsrc1 += 3; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_X2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgb8_x3 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_X3, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 3; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = (mng_int32)iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = (mng_int32)iMR; + else + iM = (mng_int32)iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* replicate first half */ + { + *pTempdst = *pTempsrc1; + *(pTempdst+1) = *(pTempsrc1+1); + *(pTempdst+2) = *(pTempsrc1+2); + + pTempdst += 3; + } + + for (iS = iH; iS < iM; iS++) /* replicate second half */ + { + *pTempdst = *pTempsrc2; + *(pTempdst+1) = *(pTempsrc2+1); + *(pTempdst+2) = *(pTempsrc2+2); + + pTempdst += 3; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + } + } + } + + pTempsrc1 += 3; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_X3, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_GRAY_SUPPORT +mng_retcode mng_magnify_ga8_x1 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX, iS, iM; + mng_uint8p pTempsrc1; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X1, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + + if (iX == 0) /* first interval ? */ + iM = iML; + else + if (iX == (iWidth - 1)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + + for (iS = 1; iS < iM; iS++) /* fill interval */ + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + } + + pTempsrc1 += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga8_x2 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X2, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 2; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + for (iS = 1; iS < iM; iS++) + { + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; /* just repeat the first */ + else /* calculate the distance */ + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2)) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + + if (*(pTempsrc1+1) == *(pTempsrc2+1)) + *pTempdst = *(pTempsrc1+1); + else + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+1)) - + (mng_int32)(*(pTempsrc1+1)) ) + iM) / + (iM * 2)) + (mng_int32)(*(pTempsrc1+1)) ); + + pTempdst++; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + } + } + } + + pTempsrc1 += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga8_x3 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X3, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 2; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* replicate first half */ + { + *pTempdst = *pTempsrc1; + *(pTempdst+1) = *(pTempsrc1+1); + + pTempdst += 2; + } + + for (iS = iH; iS < iM; iS++) /* replicate second half */ + { + *pTempdst = *pTempsrc2; + *(pTempdst+1) = *(pTempsrc2+1); + + pTempdst += 2; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + } + } + } + + pTempsrc1 += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X3, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga8_x4 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X4, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 2; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* first half */ + { + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; /* just repeat the first */ + else /* calculate the distance */ + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2)) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + + *pTempdst = *(pTempsrc1+1); /* replicate alpha from left */ + + pTempdst++; + } + + for (iS = iH; iS < iM; iS++) /* second half */ + { + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; /* just repeat the first */ + else /* calculate the distance */ + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2)) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + + *pTempdst = *(pTempsrc2+1); /* replicate alpha from right */ + + pTempdst++; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + } + } + } + + pTempsrc1 += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga8_x5 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X5, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 2; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* first half */ + { + *pTempdst = *pTempsrc1; /* replicate gray from left */ + + pTempdst++; + + if (*(pTempsrc1+1) == *(pTempsrc2+1)) + *pTempdst = *(pTempsrc1+1);/* just repeat the first */ + else /* calculate the distance */ + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+1)) - + (mng_int32)(*(pTempsrc1+1)) ) + iM) / + (iM * 2)) + (mng_int32)(*(pTempsrc1+1)) ); + + pTempdst++; + } + + for (iS = iH; iS < iM; iS++) /* second half */ + { + *pTempdst = *pTempsrc2; /* replicate gray from right */ + + pTempdst++; + + if (*(pTempsrc1+1) == *(pTempsrc2+1)) + *pTempdst = *(pTempsrc1+1);/* just repeat the first */ + else /* calculate the distance */ + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+1)) - + (mng_int32)(*(pTempsrc1+1)) ) + iM) / + (iM * 2)) + (mng_int32)(*(pTempsrc1+1)) ); + + pTempdst++; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + } + } + } + + pTempsrc1 += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_X5, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_GRAY_SUPPORT */ +#endif /* MNG_OPTIMIZE_FOOTPRINT_MAGN */ + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba8_x1 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX, iS, iM; + mng_uint8p pTempsrc1; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X1, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + + if (iX == 0) /* first interval ? */ + iM = iML; + else + if (iX == (iWidth - 1)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + + for (iS = 1; iS < iM; iS++) /* fill interval */ + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + } + + pTempsrc1 += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba8_x2 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X2, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 4; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = (mng_int32)iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = (mng_int32)iMR; + else + iM = (mng_int32)iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + for (iS = 1; iS < iM; iS++) + { + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; /* just repeat the first */ + else /* calculate the distance */ + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2)) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + + if (*(pTempsrc1+1) == *(pTempsrc2+1)) + *pTempdst = *(pTempsrc1+1); + else + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+1)) - + (mng_int32)(*(pTempsrc1+1)) ) + iM) / + (iM * 2)) + (mng_int32)(*(pTempsrc1+1)) ); + + pTempdst++; + + if (*(pTempsrc1+2) == *(pTempsrc2+2)) + *pTempdst = *(pTempsrc1+2); + else + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+2)) - + (mng_int32)(*(pTempsrc1+2)) ) + iM) / + (iM * 2)) + (mng_int32)(*(pTempsrc1+2)) ); + + pTempdst++; + + if (*(pTempsrc1+3) == *(pTempsrc2+3)) + *pTempdst = *(pTempsrc1+3); + else + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+3)) - + (mng_int32)(*(pTempsrc1+3)) ) + iM) / + (iM * 2)) + (mng_int32)(*(pTempsrc1+3)) ); + + pTempdst++; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + } + } + } + + pTempsrc1 += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba8_x3 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X3, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 4; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = (mng_int32)iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = (mng_int32)iMR; + else + iM = (mng_int32)iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* replicate first half */ + { + *pTempdst = *pTempsrc1; + *(pTempdst+1) = *(pTempsrc1+1); + *(pTempdst+2) = *(pTempsrc1+2); + *(pTempdst+3) = *(pTempsrc1+3); + + pTempdst += 4; + } + + for (iS = iH; iS < iM; iS++) /* replicate second half */ + { + *pTempdst = *pTempsrc2; + *(pTempdst+1) = *(pTempsrc2+1); + *(pTempdst+2) = *(pTempsrc2+2); + *(pTempdst+3) = *(pTempsrc2+3); + + pTempdst += 4; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + } + } + } + + pTempsrc1 += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X3, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba8_x4 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X4, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 4; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = (mng_int32)iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = (mng_int32)iMR; + else + iM = (mng_int32)iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* first half */ + { + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; /* just repeat the first */ + else /* calculate the distance */ + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2)) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + + if (*(pTempsrc1+1) == *(pTempsrc2+1)) + *pTempdst = *(pTempsrc1+1); + else + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+1)) - + (mng_int32)(*(pTempsrc1+1)) ) + iM) / + (iM * 2)) + (mng_int32)(*(pTempsrc1+1)) ); + + pTempdst++; + + if (*(pTempsrc1+2) == *(pTempsrc2+2)) + *pTempdst = *(pTempsrc1+2); + else + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+2)) - + (mng_int32)(*(pTempsrc1+2)) ) + iM) / + (iM * 2)) + (mng_int32)(*(pTempsrc1+2)) ); + + pTempdst++; + /* replicate alpha from left */ + *pTempdst = *(pTempsrc1+3); + + pTempdst++; + } + + for (iS = iH; iS < iM; iS++) /* second half */ + { + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; /* just repeat the first */ + else /* calculate the distance */ + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2)) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + + if (*(pTempsrc1+1) == *(pTempsrc2+1)) + *pTempdst = *(pTempsrc1+1); + else + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+1)) - + (mng_int32)(*(pTempsrc1+1)) ) + iM) / + (iM * 2)) + (mng_int32)(*(pTempsrc1+1)) ); + + pTempdst++; + + if (*(pTempsrc1+2) == *(pTempsrc2+2)) + *pTempdst = *(pTempsrc1+2); + else + *pTempdst = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+2)) - + (mng_int32)(*(pTempsrc1+2)) ) + iM) / + (iM * 2)) + (mng_int32)(*(pTempsrc1+2)) ); + + pTempdst++; + /* replicate alpha from right */ + *pTempdst = *(pTempsrc2+3); + + pTempdst++; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + } + } + } + + pTempsrc1 += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba8_x5 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X5, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline; /* initialize pixel-loop */ + pTempdst = pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 4; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = (mng_int32)iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = (mng_int32)iMR; + else + iM = (mng_int32)iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* first half */ + { + *pTempdst = *pTempsrc1; /* replicate color from left */ + *(pTempdst+1) = *(pTempsrc1+1); + *(pTempdst+2) = *(pTempsrc1+2); + + if (*(pTempsrc1+3) == *(pTempsrc2+3)) + *(pTempdst+3) = *(pTempsrc1+3); + else + *(pTempdst+3) = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+3)) - + (mng_int32)(*(pTempsrc1+3)) ) + iM) / + (iM * 2)) + (mng_int32)(*(pTempsrc1+3)) ); + + pTempdst += 4; + } + + for (iS = iH; iS < iM; iS++) /* second half */ + { + *pTempdst = *pTempsrc2; /* replicate color from right */ + *(pTempdst+1) = *(pTempsrc2+1); + *(pTempdst+2) = *(pTempsrc2+2); + + if (*(pTempsrc1+3) == *(pTempsrc2+3)) + *(pTempdst+3) = *(pTempsrc1+3); + else + *(pTempdst+3) = (mng_uint8)(((2 * iS * ( (mng_int32)(*(pTempsrc2+3)) - + (mng_int32)(*(pTempsrc1+3)) ) + iM) / + (iM * 2)) + (mng_int32)(*(pTempsrc1+3)) ); + + pTempdst += 4; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + } + } + } + + pTempsrc1 += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_X4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_FOOTPRINT_MAGN +#ifndef MNG_NO_GRAY_SUPPORT +mng_retcode mng_magnify_g8_y1 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_Y1, MNG_LC_START); +#endif + + MNG_COPY (pDstline, pSrcline1, iWidth); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_Y1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ +mng_retcode mng_magnify_g8_y2 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_Y2, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = pSrcline2; + pTempdst = pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, iWidth); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_Y2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_g8_y3 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_Y3, MNG_LC_START); +#endif + + if (pSrcline2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + MNG_COPY (pDstline, pSrcline1, iWidth) + else + MNG_COPY (pDstline, pSrcline2, iWidth); + } + else + { /* just repeat the entire line */ + MNG_COPY (pDstline, pSrcline1, iWidth); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G8_Y3, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_GRAY_SUPPORT */ + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgb8_y1 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_Y1, MNG_LC_START); +#endif + + MNG_COPY (pDstline, pSrcline1, iWidth * 3); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_Y1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgb8_y2 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_Y2, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = pSrcline2; + pTempdst = pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, iWidth * 3); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_Y2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgb8_y3 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_Y3, MNG_LC_START); +#endif + + if (pSrcline2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + MNG_COPY (pDstline, pSrcline1, iWidth * 3) + else + MNG_COPY (pDstline, pSrcline2, iWidth * 3); + } + else + { /* just repeat the entire line */ + MNG_COPY (pDstline, pSrcline1, iWidth * 3); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB8_Y3, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_GRAY_SUPPORT +mng_retcode mng_magnify_ga8_y1 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y1, MNG_LC_START); +#endif + + MNG_COPY (pDstline, pSrcline1, iWidth << 1); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga8_y2 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y2, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = pSrcline2; + pTempdst = pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, iWidth << 1); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga8_y3 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y3, MNG_LC_START); +#endif + + if (pSrcline2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + MNG_COPY (pDstline, pSrcline1, iWidth << 1) + else + MNG_COPY (pDstline, pSrcline2, iWidth << 1); + } + else + { /* just repeat the entire line */ + MNG_COPY (pDstline, pSrcline1, iWidth << 1); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga8_y4 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y4, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = pSrcline2; + pTempdst = pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2 += 2; + + *pTempdst++ = *pTempsrc1++; /* replicate alpha from top */ + } + } + else + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1 += 2; + pTempsrc2++; + + *pTempdst++ = *pTempsrc2++; /* replicate alpha from bottom */ + } + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, iWidth << 1); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga8_y5 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y5, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = pSrcline2; + pTempdst = pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + { + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst = *pTempsrc1; /* replicate gray from top */ + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + else + { + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst = *pTempsrc2; /* replicate gray from bottom */ + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, iWidth << 1); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA8_Y5, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_GRAY_SUPPORT */ +#endif /* MNG_OPTIMIZE_FOOTPRINT_MAGN */ + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba8_y1 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y1, MNG_LC_START); +#endif + + MNG_COPY (pDstline, pSrcline1, iWidth << 2); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba8_y2 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y2, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = pSrcline2; + pTempdst = pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, iWidth << 2); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba8_y3 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y3, MNG_LC_START); +#endif + + if (pSrcline2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + MNG_COPY (pDstline, pSrcline1, iWidth << 2) + else + MNG_COPY (pDstline, pSrcline2, iWidth << 2); + } + else + { /* just repeat the entire line */ + MNG_COPY (pDstline, pSrcline1, iWidth << 2); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba8_y4 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y4, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = pSrcline2; + pTempdst = pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2 += 2; + + *pTempdst++ = *pTempsrc1++; /* replicate alpha from top */ + } + } + else + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1 += 2; + pTempsrc2++; + + *pTempdst++ = *pTempsrc2++; /* replicate alpha from bottom */ + } + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, iWidth << 2); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba8_y5 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint8p pTempsrc1; + mng_uint8p pTempsrc2; + mng_uint8p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y5, MNG_LC_START); +#endif + + pTempsrc1 = pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = pSrcline2; + pTempdst = pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + { + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst++ = *pTempsrc1++; /* replicate color from top */ + *pTempdst++ = *pTempsrc1++; + *pTempdst++ = *pTempsrc1++; + + pTempsrc2 += 3; + + if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + else + { + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst++ = *pTempsrc2++; /* replicate color from bottom */ + *pTempdst++ = *pTempsrc2++; + *pTempdst++ = *pTempsrc2++; + + pTempsrc1 += 3; + + if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ + *pTempdst = *pTempsrc1; + else + *pTempdst = (mng_uint8)( ( (2 * iS * ( (mng_int32)(*pTempsrc2) - + (mng_int32)(*pTempsrc1) ) + iM) / + (iM * 2) ) + (mng_int32)(*pTempsrc1) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, iWidth << 2); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA8_Y5, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_OPTIMIZE_FOOTPRINT_MAGN +#ifndef MNG_NO_16BIT_SUPPORT +#ifndef MNG_NO_GRAY_SUPPORT +mng_retcode mng_magnify_g16_x1 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX, iS, iM; + mng_uint16p pTempsrc1; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_X1, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + + if (iX == 0) /* first interval ? */ + iM = iML; + else + if (iX == (iWidth - 1)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + + for (iS = 1; iS < iM; iS++) /* fill interval */ + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + } + + pTempsrc1++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_X1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_g16_x2 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_X2, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 1; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { /* is it same as first ? */ + if (*pTempsrc1 == *pTempsrc2) + { + for (iS = 1; iS < iM; iS++) /* then just repeat the first */ + { + *pTempdst = *pTempsrc1; + pTempdst++; + } + } + else + { + for (iS = 1; iS < iM; iS++) /* calculate the distances */ + { + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) )); + pTempdst++; + } + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + } + } + } + + pTempsrc1++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_X2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_g16_x3 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_X3, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 1; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { /* is it same as first ? */ + if (*pTempsrc1 == *pTempsrc2) + { + for (iS = 1; iS < iM; iS++) /* then just repeat the first */ + { + *pTempdst = *pTempsrc1; + pTempdst++; + } + } + else + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* replicate first half */ + { + *pTempdst = *pTempsrc1; + pTempdst++; + } + + for (iS = iH; iS < iM; iS++) /* replicate second half */ + { + *pTempdst = *pTempsrc2; + pTempdst++; + } + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + } + } + } + + pTempsrc1++; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_X3, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_GRAY_SUPPORT */ + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgb16_x1 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX, iS, iM; + mng_uint16p pTempsrc1; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_X1, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + + if (iX == 0) /* first interval ? */ + iM = iML; + else + if (iX == (iWidth - 1)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + + for (iS = 1; iS < iM; iS++) /* fill interval */ + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + } + + pTempsrc1 += 3; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_X1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgb16_x2 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_X2, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 3; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = (mng_int32)iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = (mng_int32)iMR; + else + iM = (mng_int32)iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + for (iS = 1; iS < iM; iS++) + { + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; /* just repeat the first */ + else /* calculate the distance */ + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + + if (*(pTempsrc1+1) == *(pTempsrc2+1)) + *pTempdst = *(pTempsrc1+1); + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+1))) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) ); + + pTempdst++; + + if (*(pTempsrc1+2) == *(pTempsrc2+2)) + *pTempdst = *(pTempsrc1+2); + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+2))) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) ); + + pTempdst++; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + } + } + } + + pTempsrc1 += 3; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_X2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgb16_x3 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_X3, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 3; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = (mng_int32)iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = (mng_int32)iMR; + else + iM = (mng_int32)iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* replicate first half */ + { + *pTempdst = *pTempsrc1; + *(pTempdst+1) = *(pTempsrc1+1); + *(pTempdst+2) = *(pTempsrc1+2); + + pTempdst += 3; + } + + for (iS = iH; iS < iM; iS++) /* replicate second half */ + { + *pTempdst = *pTempsrc2; + *(pTempdst+1) = *(pTempsrc2+1); + *(pTempdst+2) = *(pTempsrc2+2); + + pTempdst += 3; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + } + } + } + + pTempsrc1 += 3; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_X3, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_GRAY_SUPPORT +mng_retcode mng_magnify_ga16_x1 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX, iS, iM; + mng_uint16p pTempsrc1; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X1, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p) pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + + if (iX == 0) /* first interval ? */ + iM = iML; + else + if (iX == (iWidth - 1)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + + for (iS = 1; iS < iM; iS++) /* fill interval */ + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + } + + pTempsrc1 += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga16_x2 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X2, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 2; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + for (iS = 1; iS < iM; iS++) + { + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; /* just repeat the first */ + else /* calculate the distance */ + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + + if (*(pTempsrc1+1) == *(pTempsrc2+1)) + *pTempdst = *(pTempsrc1+1); + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+1))) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) ); + + pTempdst++; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + } + } + } + + pTempsrc1 += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga16_x3 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X3, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 2; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* replicate first half */ + { + *pTempdst = *pTempsrc1; + *(pTempdst+1) = *(pTempsrc1+1); + + pTempdst += 2; + } + + for (iS = iH; iS < iM; iS++) /* replicate second half */ + { + *pTempdst = *pTempsrc2; + *(pTempdst+1) = *(pTempsrc2+1); + + pTempdst += 2; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + } + } + } + + pTempsrc1 += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X3, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga16_x4 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X4, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 2; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* first half */ + { + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; /* just repeat the first */ + else /* calculate the distance */ + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + + *pTempdst = *(pTempsrc1+1); /* replicate alpha from left */ + + pTempdst++; + } + + for (iS = iH; iS < iM; iS++) /* second half */ + { + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; /* just repeat the first */ + else /* calculate the distance */ + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + + *pTempdst = *(pTempsrc2+1); /* replicate alpha from right */ + + pTempdst++; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + } + } + } + + pTempsrc1 += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga16_x5 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X5, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 2; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* first half */ + { + *pTempdst = *pTempsrc1; /* replicate gray from left */ + + pTempdst++; + + if (*(pTempsrc1+1) == *(pTempsrc2+1)) + *pTempdst = *(pTempsrc1+1);/* just repeat the first */ + else /* calculate the distance */ + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+1))) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) ); + + pTempdst++; + } + + for (iS = iH; iS < iM; iS++) /* second half */ + { + *pTempdst = *pTempsrc2; /* replicate gray from right */ + + pTempdst++; + + if (*(pTempsrc1+1) == *(pTempsrc2+1)) + *pTempdst = *(pTempsrc1+1);/* just repeat the first */ + else /* calculate the distance */ + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+1))) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) ); + + pTempdst++; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + } + } + } + + pTempsrc1 += 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_X5, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_GRAY_SUPPORT */ + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba16_x1 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX, iS, iM; + mng_uint16p pTempsrc1; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X1, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + + if (iX == 0) /* first interval ? */ + iM = iML; + else + if (iX == (iWidth - 1)) /* last interval ? */ + iM = iMR; + else + iM = iMX; + + for (iS = 1; iS < iM; iS++) /* fill interval */ + { + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + } + + pTempsrc1 += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba16_x2 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X2, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 4; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = (mng_int32)iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = (mng_int32)iMR; + else + iM = (mng_int32)iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + for (iS = 1; iS < iM; iS++) + { + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; /* just repeat the first */ + else /* calculate the distance */ + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + + if (*(pTempsrc1+1) == *(pTempsrc2+1)) + *pTempdst = *(pTempsrc1+1); + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+1))) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) ); + + pTempdst++; + + if (*(pTempsrc1+2) == *(pTempsrc2+2)) + *pTempdst = *(pTempsrc1+2); + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+2))) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) ); + + pTempdst++; + + if (*(pTempsrc1+3) == *(pTempsrc2+3)) + *pTempdst = *(pTempsrc1+3); + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+3))) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+3))) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+3))) ) ); + + pTempdst++; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + } + } + } + + pTempsrc1 += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba16_x3 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X3, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 4; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = (mng_int32)iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = (mng_int32)iMR; + else + iM = (mng_int32)iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* replicate first half */ + { + *pTempdst = *pTempsrc1; + *(pTempdst+1) = *(pTempsrc1+1); + *(pTempdst+2) = *(pTempsrc1+2); + *(pTempdst+3) = *(pTempsrc1+3); + + pTempdst += 4; + } + + for (iS = iH; iS < iM; iS++) /* replicate second half */ + { + *pTempdst = *pTempsrc2; + *(pTempdst+1) = *(pTempsrc2+1); + *(pTempdst+2) = *(pTempsrc2+2); + *(pTempdst+3) = *(pTempsrc2+3); + + pTempdst += 4; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + } + } + } + + pTempsrc1 += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X3, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba16_x4 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X4, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 4; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = (mng_int32)iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = (mng_int32)iMR; + else + iM = (mng_int32)iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* first half */ + { + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; /* just repeat the first */ + else /* calculate the distance */ + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + + if (*(pTempsrc1+1) == *(pTempsrc2+1)) + *pTempdst = *(pTempsrc1+1); + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+1))) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) ); + + pTempdst++; + + if (*(pTempsrc1+2) == *(pTempsrc2+2)) + *pTempdst = *(pTempsrc1+2); + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+2))) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) ); + + pTempdst++; + /* replicate alpha from left */ + *pTempdst = *(pTempsrc1+3); + + pTempdst++; + } + + for (iS = iH; iS < iM; iS++) /* second half */ + { + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; /* just repeat the first */ + else /* calculate the distance */ + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + + if (*(pTempsrc1+1) == *(pTempsrc2+1)) + *pTempdst = *(pTempsrc1+1); + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+1))) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+1))) ) ); + + pTempdst++; + + if (*(pTempsrc1+2) == *(pTempsrc2+2)) + *pTempdst = *(pTempsrc1+2); + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+2))) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+2))) ) ); + + pTempdst++; + /* replicate alpha from right */ + *pTempdst = *(pTempsrc2+3); + + pTempdst++; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + } + } + } + + pTempsrc1 += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba16_x5 (mng_datap pData, + mng_uint16 iMX, + mng_uint16 iML, + mng_uint16 iMR, + mng_uint32 iWidth, + mng_uint8p pSrcline, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_int32 iS, iM, iH; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X5, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline; /* initialize pixel-loop */ + pTempdst = (mng_uint16p)pDstline; + + for (iX = 0; iX < iWidth; iX++) + { + pTempsrc2 = pTempsrc1 + 4; + + *pTempdst = *pTempsrc1; /* copy original source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + + if (iX == 0) /* first interval ? */ + { + if (iWidth == 1) /* single pixel ? */ + pTempsrc2 = MNG_NULL; + + iM = (mng_int32)iML; + } + else + if (iX == (iWidth - 2)) /* last interval ? */ + iM = (mng_int32)iMR; + else + iM = (mng_int32)iMX; + /* fill interval ? */ + if ((iX < iWidth - 1) || (iWidth == 1)) + { + if (pTempsrc2) /* do we have the second pixel ? */ + { + iH = (iM+1) / 2; /* calculate halfway point */ + + for (iS = 1; iS < iH; iS++) /* first half */ + { + *pTempdst = *pTempsrc1; /* replicate color from left */ + *(pTempdst+1) = *(pTempsrc1+1); + *(pTempdst+2) = *(pTempsrc1+2); + + if (*(pTempsrc1+3) == *(pTempsrc2+3)) + *(pTempdst+3) = *(pTempsrc1+3); + else + mng_put_uint16 ((mng_uint8p)(pTempdst+3), + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+3))) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+3))) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+3))) ) ); + + pTempdst += 4; + } + + for (iS = iH; iS < iM; iS++) /* second half */ + { + *pTempdst = *pTempsrc2; /* replicate color from right */ + *(pTempdst+1) = *(pTempsrc2+1); + *(pTempdst+2) = *(pTempsrc2+2); + + if (*(pTempsrc1+3) == *(pTempsrc2+3)) + *(pTempdst+3) = *(pTempsrc1+3); + else + mng_put_uint16 ((mng_uint8p)(pTempdst+3), + (mng_uint16)(((2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc2+3))) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+3))) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)(pTempsrc1+3))) ) ); + + pTempdst += 4; + } + } + else + { + for (iS = 1; iS < iM; iS++) + { + *pTempdst = *pTempsrc1; /* repeat first source pixel */ + pTempdst++; + *pTempdst = *(pTempsrc1+1); + pTempdst++; + *pTempdst = *(pTempsrc1+2); + pTempdst++; + *pTempdst = *(pTempsrc1+3); + pTempdst++; + } + } + } + + pTempsrc1 += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_X4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_GRAY_SUPPORT +mng_retcode mng_magnify_g16_y1 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_Y1, MNG_LC_START); +#endif + + MNG_COPY (pDstline, pSrcline1, (iWidth << 1)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_Y1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_g16_y2 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_Y2, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = (mng_uint16p)pSrcline2; + pTempdst = (mng_uint16p)pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, (iWidth << 1)); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_Y2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_g16_y3 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_Y3, MNG_LC_START); +#endif + + if (pSrcline2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + MNG_COPY (pDstline, pSrcline1, (iWidth << 1)) + else + MNG_COPY (pDstline, pSrcline2, (iWidth << 1)); + } + else + { /* just repeat the entire line */ + MNG_COPY (pDstline, pSrcline1, (iWidth << 1)); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_G16_Y3, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_GRAY_SUPPORT */ + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgb16_y1 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_Y1, MNG_LC_START); +#endif + + MNG_COPY (pDstline, pSrcline1, iWidth * 6); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_Y1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgb16_y2 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_Y2, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = (mng_uint16p)pSrcline2; + pTempdst = (mng_uint16p)pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, iWidth * 6); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_Y2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgb16_y3 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_Y3, MNG_LC_START); +#endif + + if (pSrcline2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + MNG_COPY (pDstline, pSrcline1, iWidth * 6) + else + MNG_COPY (pDstline, pSrcline2, iWidth * 6); + } + else + { /* just repeat the entire line */ + MNG_COPY (pDstline, pSrcline1, iWidth * 6); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGB16_Y3, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_GRAY_SUPPORT +mng_retcode mng_magnify_ga16_y1 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y1, MNG_LC_START); +#endif + + MNG_COPY (pDstline, pSrcline1, (iWidth << 2)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga16_y2 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y2, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = (mng_uint16p)pSrcline2; + pTempdst = (mng_uint16p)pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, (iWidth << 2)); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga16_y3 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y3, MNG_LC_START); +#endif + + if (pSrcline2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + MNG_COPY (pDstline, pSrcline1, (iWidth << 2)) + else + MNG_COPY (pDstline, pSrcline2, (iWidth << 2)); + } + else + { /* just repeat the entire line */ + MNG_COPY (pDstline, pSrcline1, (iWidth << 2)); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga16_y4 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y4, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = (mng_uint16p)pSrcline2; + pTempdst = (mng_uint16p)pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2 += 2; + + *pTempdst++ = *pTempsrc1++; /* replicate alpha from top */ + } + } + else + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1 += 2; + pTempsrc2++; + + *pTempdst++ = *pTempsrc2++; /* replicate alpha from bottom */ + } + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, (iWidth << 2)); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_ga16_y5 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y5, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = (mng_uint16p)pSrcline2; + pTempdst = (mng_uint16p)pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + { + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst = *pTempsrc1; /* replicate gray from top */ + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + else + { + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst = *pTempsrc2; /* replicate gray from bottom */ + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, (iWidth << 2)); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_GA16_Y5, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_GRAY_SUPPORT */ + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba16_y1 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y1, MNG_LC_START); +#endif + + MNG_COPY (pDstline, pSrcline1, (iWidth << 3)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y1, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba16_y2 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y2, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = (mng_uint16p)pSrcline2; + pTempdst = (mng_uint16p)pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, (iWidth << 3)); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba16_y3 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y3, MNG_LC_START); +#endif + + if (pSrcline2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + MNG_COPY (pDstline, pSrcline1, (iWidth << 3)) + else + MNG_COPY (pDstline, pSrcline2, (iWidth << 3)); + } + else + { /* just repeat the entire line */ + MNG_COPY (pDstline, pSrcline1, (iWidth << 3)); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba16_y4 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y4, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = (mng_uint16p)pSrcline2; + pTempdst = (mng_uint16p)pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2 += 2; + + *pTempdst++ = *pTempsrc1++; /* replicate alpha from top */ + } + } + else + { + for (iX = 0; iX < iWidth; iX++) + { /* calculate the distances */ + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + + if (*pTempsrc1 == *pTempsrc2) + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1 += 2; + pTempsrc2++; + + *pTempdst++ = *pTempsrc2++; /* replicate alpha from bottom */ + } + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, (iWidth << 3)); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y4, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_magnify_rgba16_y5 (mng_datap pData, + mng_int32 iS, + mng_int32 iM, + mng_uint32 iWidth, + mng_uint8p pSrcline1, + mng_uint8p pSrcline2, + mng_uint8p pDstline) +{ + mng_uint32 iX; + mng_uint16p pTempsrc1; + mng_uint16p pTempsrc2; + mng_uint16p pTempdst; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y5, MNG_LC_START); +#endif + + pTempsrc1 = (mng_uint16p)pSrcline1; /* initialize pixel-loop */ + pTempsrc2 = (mng_uint16p)pSrcline2; + pTempdst = (mng_uint16p)pDstline; + + if (pTempsrc2) /* do we have a second line ? */ + { + if (iS < (iM+1) / 2) /* top half ? */ + { + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst++ = *pTempsrc1++; /* replicate color from top */ + *pTempdst++ = *pTempsrc1++; + *pTempdst++ = *pTempsrc1++; + + pTempsrc2 += 3; + + if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + else + { + for (iX = 0; iX < iWidth; iX++) + { + *pTempdst++ = *pTempsrc2++; /* replicate color from bottom */ + *pTempdst++ = *pTempsrc2++; + *pTempdst++ = *pTempsrc2++; + + pTempsrc1 += 3; + + if (*pTempsrc1 == *pTempsrc2) /* calculate the distances */ + *pTempdst = *pTempsrc1; + else + mng_put_uint16 ((mng_uint8p)pTempdst, + (mng_uint16)( ( (2 * iS * ( (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc2)) - + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) + iM) / + (iM * 2)) + (mng_int32)(mng_get_uint16 ((mng_uint8p)pTempsrc1)) ) ); + + pTempdst++; + pTempsrc1++; + pTempsrc2++; + } + } + } + else + { /* just repeat the entire line */ + MNG_COPY (pTempdst, pTempsrc1, (iWidth << 3)); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_MAGNIFY_RGBA16_Y5, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_NO_16BIT_SUPPORT */ +#endif /* MNG_OPTIMIZE_FOOTPRINT_MAGN */ +#endif /* MNG_SKIPCHUNK_MAGN */ + +/* ************************************************************************** */ +/* * * */ +/* * PAST composition routines - compose over/under with a target object * */ +/* * * */ +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +mng_retcode mng_composeover_rgba8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8; + mng_uint8 iCr8, iCg8, iCb8, iCa8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_COMPOSEOVER_RGBA8, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iFGa8 = *(pWorkrow+3); /* get alpha values */ + iBGa8 = *(pOutrow+3); + + if (iFGa8) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa8 == 0xFF) || (iBGa8 == 0)) + { /* then simply copy the values */ + *pOutrow = *pWorkrow; + *(pOutrow+1) = *(pWorkrow+1); + *(pOutrow+2) = *(pWorkrow+2); + *(pOutrow+3) = iFGa8; + } + else + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ +#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pOutrow+i), *(pWorkrow+i), iFGa8, *(pOutrow+i)); + } +#else + MNG_COMPOSE8 (*pOutrow, *pWorkrow, iFGa8, *pOutrow ); + MNG_COMPOSE8 (*(pOutrow+1), *(pWorkrow+1), iFGa8, *(pOutrow+1)); + MNG_COMPOSE8 (*(pOutrow+2), *(pWorkrow+2), iFGa8, *(pOutrow+2)); +#endif + /* alpha remains fully opaque !!! */ + } + else + { /* here we'll have to blend */ + MNG_BLEND8 (*pWorkrow, *(pWorkrow+1), *(pWorkrow+2), iFGa8, + *pOutrow, *(pOutrow+1), *(pOutrow+2), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pOutrow = iCr8; + *(pOutrow+1) = iCg8; + *(pOutrow+2) = iCb8; + *(pOutrow+3) = iCa8; + } + } + } + + pOutrow += 4; + pWorkrow += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_COMPOSEOVER_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_composeover_rgba16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint16p pWorkrow; + mng_uint16p pOutrow; + mng_int32 iX; + mng_uint16 iFGa16, iFGr16, iFGg16, iFGb16; + mng_uint16 iBGa16, iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16, iCa16; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_COMPOSEOVER_RGBA16, MNG_LC_START); +#endif + + pWorkrow = (mng_uint16p)pData->pRGBArow; + pOutrow = (mng_uint16p)(pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize)); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* get alpha values */ + iFGa16 = mng_get_uint16 ((mng_uint8p)(pWorkrow+3)); + iBGa16 = mng_get_uint16 ((mng_uint8p)(pOutrow+3)); + + if (iFGa16) /* any opacity at all ? */ + { /* fully opaque or background fully transparent ? */ + if ((iFGa16 == 0xFFFF) || (iBGa16 == 0)) + { /* then simply copy the values */ + *pOutrow = *pWorkrow; + *(pOutrow+1) = *(pWorkrow+1); + *(pOutrow+2) = *(pWorkrow+2); + *(pOutrow+3) = *(pWorkrow+3); + } + else + { /* get color values */ + iFGr16 = mng_get_uint16 ((mng_uint8p)pWorkrow); + iFGg16 = mng_get_uint16 ((mng_uint8p)(pWorkrow+1)); + iFGb16 = mng_get_uint16 ((mng_uint8p)(pWorkrow+2)); + iBGr16 = mng_get_uint16 ((mng_uint8p)pOutrow); + iBGg16 = mng_get_uint16 ((mng_uint8p)(pOutrow+1)); + iBGb16 = mng_get_uint16 ((mng_uint8p)(pOutrow+2)); + + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* do alpha composing */ + MNG_COMPOSE16 (iFGr16, iFGr16, iFGa16, iBGr16); + MNG_COMPOSE16 (iFGg16, iFGg16, iFGa16, iBGg16); + MNG_COMPOSE16 (iFGb16, iFGb16, iFGa16, iBGb16); + + mng_put_uint16 ((mng_uint8p)pOutrow, iFGr16); + mng_put_uint16 ((mng_uint8p)(pOutrow+1), iFGg16); + mng_put_uint16 ((mng_uint8p)(pOutrow+2), iFGb16); + /* alpha remains fully opaque !!! */ + } + else + { /* here we'll have to blend */ + MNG_BLEND16 (iFGr16, iFGg16, iFGb16, iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + mng_put_uint16 ((mng_uint8p)pOutrow, iCr16); + mng_put_uint16 ((mng_uint8p)(pOutrow+1), iCg16); + mng_put_uint16 ((mng_uint8p)(pOutrow+2), iCb16); + mng_put_uint16 ((mng_uint8p)(pOutrow+3), iCa16); + } + } + } + + pOutrow += 4; + pWorkrow += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_COMPOSEOVER_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_composeunder_rgba8 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint8p pWorkrow; + mng_uint8p pOutrow; + mng_int32 iX; + mng_uint8 iFGa8, iBGa8; + mng_uint8 iCr8, iCg8, iCb8, iCa8; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_COMPOSEUNDER_RGBA8, MNG_LC_START); +#endif + + pWorkrow = pData->pRGBArow; + pOutrow = pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { + iFGa8 = *(pOutrow+3); /* get alpha values */ + iBGa8 = *(pWorkrow+3); + /* anything to do at all ? */ + if ((iBGa8) && (iFGa8 != 0xFF)) + { + if (iBGa8 == 0xFF) /* background fully opaque ? */ + { /* do alpha composing */ +#ifdef MNG_OPTIMIZE_FOOTPRINT_COMPOSE + int i; + for (i=2; i >= 0; i--) + { + MNG_COMPOSE8 (*(pOutrow+i), *(pOutrow+i), iFGa8, *(pWorkrow+i)); + } +#else + MNG_COMPOSE8 (*pOutrow, *pOutrow, iFGa8, *pWorkrow ); + MNG_COMPOSE8 (*(pOutrow+1), *(pOutrow+1), iFGa8, *(pWorkrow+1)); + MNG_COMPOSE8 (*(pOutrow+2), *(pOutrow+2), iFGa8, *(pWorkrow+2)); +#endif + *(pOutrow+3) = 0xFF; /* alpha becomes fully opaque !!! */ + } + else + { /* here we'll have to blend */ + MNG_BLEND8 (*pOutrow, *(pOutrow+1), *(pOutrow+2), iFGa8, + *pWorkrow, *(pWorkrow+1), *(pWorkrow+2), iBGa8, + iCr8, iCg8, iCb8, iCa8); + /* and return the composed values */ + *pOutrow = iCr8; + *(pOutrow+1) = iCg8; + *(pOutrow+2) = iCb8; + *(pOutrow+3) = iCa8; + } + } + + pOutrow += 4; + pWorkrow += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_COMPOSEUNDER_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_composeunder_rgba16 (mng_datap pData) +{ + mng_imagedatap pBuf = ((mng_imagep)pData->pStoreobj)->pImgbuf; + mng_uint16p pWorkrow; + mng_uint16p pOutrow; + mng_int32 iX; + mng_uint16 iFGa16, iFGr16, iFGg16, iFGb16; + mng_uint16 iBGa16, iBGr16, iBGg16, iBGb16; + mng_uint16 iCr16, iCg16, iCb16, iCa16; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_COMPOSEUNDER_RGBA16, MNG_LC_START); +#endif + + pWorkrow = (mng_uint16p)pData->pRGBArow; + pOutrow = (mng_uint16p)(pBuf->pImgdata + (pData->iRow * pBuf->iRowsize ) + + (pData->iCol * pBuf->iSamplesize)); + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* get alpha values */ + iFGa16 = mng_get_uint16 ((mng_uint8p)(pOutrow+3)); + iBGa16 = mng_get_uint16 ((mng_uint8p)(pWorkrow+3)); + /* anything to do at all ? */ + if ((iBGa16) && (iFGa16 != 0xFFFF)) + { + iFGr16 = mng_get_uint16 ((mng_uint8p)pOutrow); + iFGg16 = mng_get_uint16 ((mng_uint8p)(pOutrow+1)); + iFGb16 = mng_get_uint16 ((mng_uint8p)(pOutrow+2)); + iBGr16 = mng_get_uint16 ((mng_uint8p)pWorkrow); + iBGg16 = mng_get_uint16 ((mng_uint8p)(pWorkrow+1)); + iBGb16 = mng_get_uint16 ((mng_uint8p)(pWorkrow+2)); + + if (iBGa16 == 0xFFFF) /* background fully opaque ? */ + { /* do alpha composing */ + MNG_COMPOSE16 (iFGr16, iFGr16, iFGa16, iBGr16); + MNG_COMPOSE16 (iFGg16, iFGg16, iFGa16, iBGg16); + MNG_COMPOSE16 (iFGb16, iFGb16, iFGa16, iBGb16); + + mng_put_uint16 ((mng_uint8p)pOutrow, iFGr16); + mng_put_uint16 ((mng_uint8p)(pOutrow+1), iFGg16); + mng_put_uint16 ((mng_uint8p)(pOutrow+2), iFGb16); + *(pOutrow+3) = 0xFFFF; /* alpha becomes fully opaque !!! */ + } + else + { /* here we'll have to blend */ + MNG_BLEND16 (iFGr16, iFGg16, iFGb16, iFGa16, + iBGr16, iBGg16, iBGb16, iBGa16, + iCr16, iCg16, iCb16, iCa16); + /* and return the composed values */ + mng_put_uint16 ((mng_uint8p)pOutrow, iCr16); + mng_put_uint16 ((mng_uint8p)(pOutrow+1), iCg16); + mng_put_uint16 ((mng_uint8p)(pOutrow+2), iCb16); + mng_put_uint16 ((mng_uint8p)(pOutrow+3), iCa16); + } + } + + pOutrow += 4; + pWorkrow += 4; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_COMPOSEUNDER_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif + +/* ************************************************************************** */ +/* * * */ +/* * PAST flip & tile routines - flip or tile a row of pixels * */ +/* * * */ +/* ************************************************************************** */ + +#ifndef MNG_SKIPCHUNK_PAST +mng_retcode mng_flip_rgba8 (mng_datap pData) +{ + mng_uint32p pWorkrow; + mng_uint32p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FLIP_RGBA8, MNG_LC_START); +#endif + /* setup temp pointers */ + pWorkrow = (mng_uint32p)pData->pRGBArow + pData->iRowsamples - 1; + pOutrow = (mng_uint32p)pData->pWorkrow; + /* swap original buffers */ + pData->pWorkrow = pData->pRGBArow; + pData->pRGBArow = (mng_uint8p)pOutrow; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* let's flip */ + *pOutrow = *pWorkrow; + pOutrow++; + pWorkrow--; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FLIP_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_flip_rgba16 (mng_datap pData) +{ + mng_uint32p pWorkrow; + mng_uint32p pOutrow; + mng_int32 iX; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FLIP_RGBA16, MNG_LC_START); +#endif + /* setup temp pointers */ + pWorkrow = (mng_uint32p)pData->pRGBArow + ((pData->iRowsamples - 1) << 1); + pOutrow = (mng_uint32p)pData->pWorkrow; + /* swap original buffers */ + pData->pWorkrow = pData->pRGBArow; + pData->pRGBArow = (mng_uint8p)pOutrow; + +#ifdef MNG_DECREMENT_LOOPS + for (iX = pData->iRowsamples; iX > 0; iX--) +#else + for (iX = 0; iX < pData->iRowsamples; iX++) +#endif + { /* let's flip */ + *pOutrow = *pWorkrow; + *(pOutrow + 1) = *(pWorkrow + 1); + + pOutrow += 2; + pWorkrow -= 2; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_FLIP_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode mng_tile_rgba8 (mng_datap pData) +{ + mng_uint32p pWorkrow; + mng_uint32p pOutrow; + mng_int32 iX; + mng_uint32 iZ, iMax; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_TILE_RGBA8, MNG_LC_START); +#endif + + iZ = pData->iSourcel; /* indent ? */ + /* what's our source-length */ + iMax = ((mng_imagep)pData->pRetrieveobj)->pImgbuf->iWidth; + /* setup temp pointers */ + pWorkrow = (mng_uint32p)pData->pRGBArow + iZ; + pOutrow = (mng_uint32p)pData->pWorkrow; + /* swap original buffers */ + pData->pWorkrow = pData->pRGBArow; + pData->pRGBArow = (mng_uint8p)pOutrow; + + for (iX = pData->iDestl; iX < pData->iDestr; iX++) + { /* tiiiile */ + *pOutrow = *pWorkrow; + + pWorkrow++; + pOutrow++; + iZ++; + + if (iZ >= iMax) /* end of source ? */ + { + iZ = 0; + pWorkrow = (mng_uint32p)pData->pWorkrow; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_TILE_RGBA8, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_16BIT_SUPPORT +mng_retcode mng_tile_rgba16 (mng_datap pData) +{ + mng_uint32p pWorkrow; + mng_uint32p pOutrow; + mng_int32 iX; + mng_uint32 iZ, iMax; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_TILE_RGBA16, MNG_LC_START); +#endif + + iZ = pData->iSourcel; /* indent ? */ + /* what's our source-length */ + iMax = ((mng_imagep)pData->pRetrieveobj)->pImgbuf->iWidth; + /* setup temp pointers */ + pWorkrow = (mng_uint32p)pData->pRGBArow + (iZ << 1); + pOutrow = (mng_uint32p)pData->pWorkrow; + /* swap original buffers */ + pData->pWorkrow = pData->pRGBArow; + pData->pRGBArow = (mng_uint8p)pOutrow; + + for (iX = pData->iDestl; iX < pData->iDestr; iX++) + { /* tiiiile */ + *pOutrow = *pWorkrow; + *(pOutrow + 1) = *(pWorkrow + 1); + + pWorkrow += 2; + pOutrow += 2; + iZ++; + + if (iZ >= iMax) /* end of source ? */ + { + iZ = 0; + pWorkrow = (mng_uint32p)pData->pWorkrow; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_TILE_RGBA16, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SKIPCHUNK_PAST */ + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_DISPLAY_PROCS */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ diff --git a/Source/LibMNG/libmng_prop_xs.c b/Source/LibMNG/libmng_prop_xs.c index d4afc87..88e416d 100644 --- a/Source/LibMNG/libmng_prop_xs.c +++ b/Source/LibMNG/libmng_prop_xs.c @@ -1,2799 +1,2799 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_prop_xs.c copyright (c) 2000-2006 G.Juyn * */ -/* * version : 1.0.10 * */ -/* * * */ -/* * purpose : property get/set interface (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the property get/set functions * */ -/* * * */ -/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - fixed calling convention * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/11/2000 - G.Juyn * */ -/* * - added set_outputprofile2 & set_srgbprofile2 * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - changed trace to macro for callback error-reporting * */ -/* * * */ -/* * 0.5.2 - 05/23/2000 - G.Juyn * */ -/* * - changed inclusion of cms-routines * */ -/* * 0.5.2 - 05/24/2000 - G.Juyn * */ -/* * - added support for get/set default zlib/IJG parms * */ -/* * 0.5.2 - 05/31/2000 - G.Juyn * */ -/* * - fixed up punctuation (contribution by Tim Rowley) * */ -/* * 0.5.2 - 06/05/2000 - G.Juyn * */ -/* * - added support for RGB8_A8 canvasstyle * */ -/* * * */ -/* * 0.5.3 - 06/21/2000 - G.Juyn * */ -/* * - added get/set for speedtype to facilitate testing * */ -/* * - added get for imagelevel during processtext callback * */ -/* * 0.5.3 - 06/26/2000 - G.Juyn * */ -/* * - changed userdata variable to mng_ptr * */ -/* * 0.5.3 - 06/29/2000 - G.Juyn * */ -/* * - fixed incompatible return-types * */ -/* * * */ -/* * 0.9.1 - 07/08/2000 - G.Juyn * */ -/* * - added get routines for internal display variables * */ -/* * - added get/set routines for suspensionmode variable * */ -/* * 0.9.1 - 07/15/2000 - G.Juyn * */ -/* * - added get/set routines for sectionbreak variable * */ -/* * * */ -/* * 0.9.2 - 07/31/2000 - G.Juyn * */ -/* * - added status_xxxx functions * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 0.9.3 - 10/10/2000 - G.Juyn * */ -/* * - added support for alpha-depth prediction * */ -/* * 0.9.3 - 10/16/2000 - G.Juyn * */ -/* * - added functions to retrieve PNG/JNG specific header-info * */ -/* * 0.9.3 - 10/20/2000 - G.Juyn * */ -/* * - added get/set for bKGD preference setting * */ -/* * 0.9.3 - 10/21/2000 - G.Juyn * */ -/* * - added get function for interlace/progressive display * */ -/* * * */ -/* * 1.0.1 - 04/21/2001 - G.Juyn (code by G.Kelly) * */ -/* * - added BGRA8 canvas with premultiplied alpha * */ -/* * 1.0.1 - 05/02/2001 - G.Juyn * */ -/* * - added "default" sRGB generation (Thanks Marti!) * */ -/* * * */ -/* * 1.0.2 - 06/23/2001 - G.Juyn * */ -/* * - added optimization option for MNG-video playback * */ -/* * 1.0.2 - 06/25/2001 - G.Juyn * */ -/* * - added option to turn off progressive refresh * */ -/* * * */ -/* * 1.0.3 - 08/06/2001 - G.Juyn * */ -/* * - added get function for last processed BACK chunk * */ -/* * * */ -/* * 1.0.4 - 06/22/2002 - G.Juyn * */ -/* * - B495442 - invalid returnvalue in mng_get_suspensionmode * */ -/* * * */ -/* * 1.0.5 - 09/14/2002 - G.Juyn * */ -/* * - added event handling for dynamic MNG * */ -/* * 1.0.5 - 09/22/2002 - G.Juyn * */ -/* * - added bgrx8 canvas (filler byte) * */ -/* * 1.0.5 - 11/07/2002 - G.Juyn * */ -/* * - added support to get totals after mng_read() * */ -/* * * */ -/* * 1.0.6 - 05/11/2003 - G. Juyn * */ -/* * - added conditionals around canvas update routines * */ -/* * 1.0.6 - 07/07/2003 - G.R-P * */ -/* * - added conditionals around some JNG-supporting code * */ -/* * 1.0.6 - 07/11/2003 - G.R-P * */ -/* * - added conditionals zlib and jpeg property accessors * */ -/* * 1.0.6 - 07/14/2003 - G.R-P * */ -/* * - added conditionals around various unused functions * */ -/* * * */ -/* * 1.0.7 - 11/27/2003 - R.A * */ -/* * - added CANVAS_RGB565 and CANVAS_BGR565 * */ -/* * 1.0.7 - 12/06/2003 - R.A * */ -/* * - added CANVAS_RGBA565 and CANVAS_BGRA565 * */ -/* * 1.0.7 - 01/25/2004 - J.S * */ -/* * - added premultiplied alpha canvas' for RGBA, ARGB, ABGR * */ -/* * 1.0.7 - 03/07/2004 - G.R-P. * */ -/* * - put gamma, cms-related functions inside #ifdef * */ -/* * * */ -/* * 1.0.8 - 04/02/2004 - G.Juyn * */ -/* * - added CRC existence & checking flags * */ -/* * * */ -/* * 1.0.9 - 09/18/2004 - G.R-P. * */ -/* * - added some MNG_SUPPORT_WRITE conditionals * */ -/* * 1.0.9 - 10/03/2004 - G.Juyn * */ -/* * - added function to retrieve current FRAM delay * */ -/* * 1.0.9 - 10/14/2004 - G.Juyn * */ -/* * - added bgr565_a8 canvas-style (thanks to J. Elvander) * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * * */ -/* * 1.0.10 - 03/07/2006 - (thanks to W. Manthey) * */ -/* * - added CANVAS_RGB555 and CANVAS_BGR555 * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_objects.h" -#include "libmng_memory.h" -#include "libmng_cms.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ -/* * * */ -/* * Property set functions * */ -/* * * */ -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_userdata (mng_handle hHandle, - mng_ptr pUserdata) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_USERDATA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->pUserdata = pUserdata; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_USERDATA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_canvasstyle (mng_handle hHandle, - mng_uint32 iStyle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_CANVASSTYLE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - - switch (iStyle) - { -#ifndef MNG_SKIPCANVAS_RGB8 - case MNG_CANVAS_RGB8 : break; -#endif -#ifndef MNG_SKIPCANVAS_RGBA8 - case MNG_CANVAS_RGBA8 : break; -#endif -#ifndef MNG_SKIPCANVAS_RGBA8_PM - case MNG_CANVAS_RGBA8_PM: break; -#endif -#ifndef MNG_SKIPCANVAS_ARGB8 - case MNG_CANVAS_ARGB8 : break; -#endif -#ifndef MNG_SKIPCANVAS_ARGB8_PM - case MNG_CANVAS_ARGB8_PM: break; -#endif -#ifndef MNG_SKIPCANVAS_RGB8_A8 - case MNG_CANVAS_RGB8_A8 : break; -#endif -#ifndef MNG_SKIPCANVAS_BGR8 - case MNG_CANVAS_BGR8 : break; -#endif -#ifndef MNG_SKIPCANVAS_BGRX8 - case MNG_CANVAS_BGRX8 : break; -#endif -#ifndef MNG_SKIPCANVAS_BGRA8 - case MNG_CANVAS_BGRA8 : break; -#endif -#ifndef MNG_SKIPCANVAS_BGRA8_PM - case MNG_CANVAS_BGRA8_PM: break; -#endif -#ifndef MNG_SKIPCANVAS_ABGR8 - case MNG_CANVAS_ABGR8 : break; -#endif -#ifndef MNG_SKIPCANVAS_ABGR8_PM - case MNG_CANVAS_ABGR8_PM: break; -#endif -#ifndef MNG_SKIPCANVAS_RGB565 - case MNG_CANVAS_RGB565 : break; -#endif -#ifndef MNG_SKIPCANVAS_RGBA565 - case MNG_CANVAS_RGBA565 : break; -#endif -#ifndef MNG_SKIPCANVAS_BGR565 - case MNG_CANVAS_BGR565 : break; -#endif -#ifndef MNG_SKIPCANVAS_BGRA565 - case MNG_CANVAS_BGRA565 : break; -#endif -#ifndef MNG_SKIPCANVAS_BGR565_A8 - case MNG_CANVAS_BGR565_A8 : break; -#endif -#ifndef MNG_SKIPCANVAS_RGB555 - case MNG_CANVAS_RGB555 : break; -#endif -#ifndef MNG_SKIPCANVAS_BGR555 - case MNG_CANVAS_BGR555 : break; -#endif -/* case MNG_CANVAS_RGB16 : break; */ -/* case MNG_CANVAS_RGBA16 : break; */ -/* case MNG_CANVAS_ARGB16 : break; */ -/* case MNG_CANVAS_BGR16 : break; */ -/* case MNG_CANVAS_BGRA16 : break; */ -/* case MNG_CANVAS_ABGR16 : break; */ -/* case MNG_CANVAS_INDEX8 : break; */ -/* case MNG_CANVAS_INDEXA8 : break; */ -/* case MNG_CANVAS_AINDEX8 : break; */ -/* case MNG_CANVAS_GRAY8 : break; */ -/* case MNG_CANVAS_GRAY16 : break; */ -/* case MNG_CANVAS_GRAYA8 : break; */ -/* case MNG_CANVAS_GRAYA16 : break; */ -/* case MNG_CANVAS_AGRAY8 : break; */ -/* case MNG_CANVAS_AGRAY16 : break; */ -/* case MNG_CANVAS_DX15 : break; */ -/* case MNG_CANVAS_DX16 : break; */ - default : { MNG_ERROR (((mng_datap)hHandle), MNG_INVALIDCNVSTYLE) }; - } - - ((mng_datap)hHandle)->iCanvasstyle = iStyle; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_CANVASSTYLE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_bkgdstyle (mng_handle hHandle, - mng_uint32 iStyle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_BKGDSTYLE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - - switch (iStyle) /* alpha-modes not supported */ - { -#ifndef MNG_SKIPCANVAS_RGB8 - case MNG_CANVAS_RGB8 : break; -#endif -#ifndef MNG_SKIPCANVAS_BGR8 - case MNG_CANVAS_BGR8 : break; -#endif -#ifndef MNG_SKIPCANVAS_BGRX8 - case MNG_CANVAS_BGRX8 : break; -#endif -#ifndef MNG_SKIPCANVAS_RGB565 - case MNG_CANVAS_RGB565 : break; -#endif -#ifndef MNG_SKIPCANVAS_BGR565 - case MNG_CANVAS_BGR565 : break; -#endif -/* case MNG_CANVAS_RGB16 : break; */ -/* case MNG_CANVAS_BGR16 : break; */ -/* case MNG_CANVAS_INDEX8 : break; */ -/* case MNG_CANVAS_GRAY8 : break; */ -/* case MNG_CANVAS_GRAY16 : break; */ -/* case MNG_CANVAS_DX15 : break; */ -/* case MNG_CANVAS_DX16 : break; */ - default : MNG_ERROR (((mng_datap)hHandle), MNG_INVALIDCNVSTYLE); - } - - ((mng_datap)hHandle)->iBkgdstyle = iStyle; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_BKGDSTYLE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_bgcolor (mng_handle hHandle, - mng_uint16 iRed, - mng_uint16 iGreen, - mng_uint16 iBlue) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_BGCOLOR, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->iBGred = iRed; - ((mng_datap)hHandle)->iBGgreen = iGreen; - ((mng_datap)hHandle)->iBGblue = iBlue; - ((mng_datap)hHandle)->bUseBKGD = MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_BGCOLOR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_usebkgd (mng_handle hHandle, - mng_bool bUseBKGD) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_USEBKGD, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->bUseBKGD = bUseBKGD; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_USEBKGD, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_storechunks (mng_handle hHandle, - mng_bool bStorechunks) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_STORECHUNKS, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->bStorechunks = bStorechunks; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_STORECHUNKS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_sectionbreaks (mng_handle hHandle, - mng_bool bSectionbreaks) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SECTIONBREAKS, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->bSectionbreaks = bSectionbreaks; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SECTIONBREAKS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_cacheplayback (mng_handle hHandle, - mng_bool bCacheplayback) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_CACHEPLAYBACK, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - - if (((mng_datap)hHandle)->bHasheader) - MNG_ERROR (((mng_datap)hHandle), MNG_FUNCTIONINVALID); - - ((mng_datap)hHandle)->bCacheplayback = bCacheplayback; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_CACHEPLAYBACK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_doprogressive (mng_handle hHandle, - mng_bool bDoProgressive) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DOPROGRESSIVE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - - ((mng_datap)hHandle)->bDoProgressive = bDoProgressive; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DOPROGRESSIVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_crcmode (mng_handle hHandle, - mng_uint32 iCrcmode) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_CRCMODE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - - ((mng_datap)hHandle)->iCrcmode = iCrcmode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_CRCMODE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_set_srgb (mng_handle hHandle, - mng_bool bIssRGB) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGB, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->bIssRGB = bIssRGB; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGB, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_SKIPCHUNK_iCCP -mng_retcode MNG_DECL mng_set_outputprofile (mng_handle hHandle, - mng_pchar zFilename) -{ -#ifdef MNG_INCLUDE_LCMS - mng_datap pData; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_OUTPUTPROFILE, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_LCMS - MNG_VALIDHANDLE (hHandle) - - pData = (mng_datap)hHandle; /* address the structure */ - - if (pData->hProf2) /* previously defined ? */ - mnglcms_freeprofile (pData->hProf2); - /* allocate new CMS profile handle */ - pData->hProf2 = mnglcms_createfileprofile (zFilename); - - if (!pData->hProf2) /* handle error ? */ - MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); -#endif /* MNG_INCLUDE_LCMS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_OUTPUTPROFILE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_SKIPCHUNK_iCCP -mng_retcode MNG_DECL mng_set_outputprofile2 (mng_handle hHandle, - mng_uint32 iProfilesize, - mng_ptr pProfile) -{ -#ifdef MNG_INCLUDE_LCMS - mng_datap pData; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_OUTPUTPROFILE2, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_LCMS - MNG_VALIDHANDLE (hHandle) - - pData = (mng_datap)hHandle; /* address the structure */ - - if (pData->hProf2) /* previously defined ? */ - mnglcms_freeprofile (pData->hProf2); - /* allocate new CMS profile handle */ - pData->hProf2 = mnglcms_creatememprofile (iProfilesize, pProfile); - - if (!pData->hProf2) /* handle error ? */ - MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); -#endif /* MNG_INCLUDE_LCMS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_OUTPUTPROFILE2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_outputsrgb (mng_handle hHandle) -{ -#ifdef MNG_INCLUDE_LCMS - mng_datap pData; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_OUTPUTSRGB, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_LCMS - MNG_VALIDHANDLE (hHandle) - - pData = (mng_datap)hHandle; /* address the structure */ - - if (pData->hProf2) /* previously defined ? */ - mnglcms_freeprofile (pData->hProf2); - /* allocate new CMS profile handle */ - pData->hProf2 = mnglcms_createsrgbprofile (); - - if (!pData->hProf2) /* handle error ? */ - MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); -#endif /* MNG_INCLUDE_LCMS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_OUTPUTSRGB, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_set_srgbprofile (mng_handle hHandle, - mng_pchar zFilename) -{ -#ifdef MNG_INCLUDE_LCMS - mng_datap pData; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGBPROFILE2, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_LCMS - MNG_VALIDHANDLE (hHandle) - - pData = (mng_datap)hHandle; /* address the structure */ - - if (pData->hProf3) /* previously defined ? */ - mnglcms_freeprofile (pData->hProf3); - /* allocate new CMS profile handle */ - pData->hProf3 = mnglcms_createfileprofile (zFilename); - - if (!pData->hProf3) /* handle error ? */ - MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); -#endif /* MNG_INCLUDE_LCMS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGBPROFILE2, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_set_srgbprofile2 (mng_handle hHandle, - mng_uint32 iProfilesize, - mng_ptr pProfile) -{ -#ifdef MNG_INCLUDE_LCMS - mng_datap pData; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGBPROFILE, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_LCMS - MNG_VALIDHANDLE (hHandle) - - pData = (mng_datap)hHandle; /* address the structure */ - - if (pData->hProf3) /* previously defined ? */ - mnglcms_freeprofile (pData->hProf3); - /* allocate new CMS profile handle */ - pData->hProf3 = mnglcms_creatememprofile (iProfilesize, pProfile); - - if (!pData->hProf3) /* handle error ? */ - MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); -#endif /* MNG_INCLUDE_LCMS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGBPROFILE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_srgbimplicit (mng_handle hHandle) -{ -#ifdef MNG_INCLUDE_LCMS - mng_datap pData; -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGBIMPLICIT, MNG_LC_START); -#endif - -#ifdef MNG_INCLUDE_LCMS - MNG_VALIDHANDLE (hHandle) - - pData = (mng_datap)hHandle; /* address the structure */ - - if (pData->hProf3) /* previously defined ? */ - mnglcms_freeprofile (pData->hProf3); - /* allocate new CMS profile handle */ - pData->hProf3 = mnglcms_createsrgbprofile (); - - if (!pData->hProf3) /* handle error ? */ - MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); -#endif /* MNG_INCLUDE_LCMS */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGBIMPLICIT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) -mng_retcode MNG_DECL mng_set_viewgamma (mng_handle hHandle, - mng_float dGamma) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_VIEWGAMMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->dViewgamma = dGamma; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_VIEWGAMMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_displaygamma (mng_handle hHandle, - mng_float dGamma) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DISPLAYGAMMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->dDisplaygamma = dGamma; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DISPLAYGAMMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_dfltimggamma (mng_handle hHandle, - mng_float dGamma) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DFLTIMGGAMMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->dDfltimggamma = dGamma; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DFLTIMGGAMMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) -mng_retcode MNG_DECL mng_set_viewgammaint (mng_handle hHandle, - mng_uint32 iGamma) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_VIEWGAMMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->dViewgamma = (mng_float)iGamma / 100000; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_VIEWGAMMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_displaygammaint (mng_handle hHandle, - mng_uint32 iGamma) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DISPLAYGAMMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->dDisplaygamma = (mng_float)iGamma / 100000; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DISPLAYGAMMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#ifndef MNG_NO_DFLT_INFO -mng_retcode MNG_DECL mng_set_dfltimggammaint (mng_handle hHandle, - mng_uint32 iGamma) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DFLTIMGGAMMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->dDfltimggamma = (mng_float)iGamma / 100000; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DFLTIMGGAMMA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIP_MAXCANVAS -mng_retcode MNG_DECL mng_set_maxcanvaswidth (mng_handle hHandle, - mng_uint32 iMaxwidth) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_MAXCANVASWIDTH, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->iMaxwidth = iMaxwidth; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_MAXCANVASWIDTH, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_maxcanvasheight (mng_handle hHandle, - mng_uint32 iMaxheight) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_MAXCANVASHEIGHT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->iMaxheight = iMaxheight; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_MAXCANVASHEIGHT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_set_maxcanvassize (mng_handle hHandle, - mng_uint32 iMaxwidth, - mng_uint32 iMaxheight) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_MAXCANVASSIZE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->iMaxwidth = iMaxwidth; - ((mng_datap)hHandle)->iMaxheight = iMaxheight; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_MAXCANVASSIZE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ZLIB -#ifdef MNG_ACCESS_ZLIB -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_set_zlib_level (mng_handle hHandle, - mng_int32 iZlevel) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_LEVEL, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->iZlevel = iZlevel; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_LEVEL, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ -#endif /* MNG_ACCESS_ZLIB */ -#endif /* MNG_INCLUDE_ZLIB */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ZLIB -#ifdef MNG_ACCESS_ZLIB -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_set_zlib_method (mng_handle hHandle, - mng_int32 iZmethod) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_METHOD, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->iZmethod = iZmethod; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_METHOD, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ -#endif /* MNG_ACCESS_ZLIB */ -#endif /* MNG_INCLUDE_ZLIB */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ZLIB -#ifdef MNG_ACCESS_ZLIB -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_set_zlib_windowbits (mng_handle hHandle, - mng_int32 iZwindowbits) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_WINDOWBITS, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->iZwindowbits = iZwindowbits; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_WINDOWBITS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ -#endif /* MNG_ACCESS_ZLIB */ -#endif /* MNG_INCLUDE_ZLIB */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ZLIB -#ifdef MNG_ACCESS_ZLIB -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_set_zlib_memlevel (mng_handle hHandle, - mng_int32 iZmemlevel) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_MEMLEVEL, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->iZmemlevel = iZmemlevel; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_MEMLEVEL, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ -#endif /* MNG_ACCESS_ZLIB */ -#endif /* MNG_INCLUDE_ZLIB */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ZLIB -#ifdef MNG_ACCESS_ZLIB -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_set_zlib_strategy (mng_handle hHandle, - mng_int32 iZstrategy) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_STRATEGY, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->iZstrategy = iZstrategy; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_STRATEGY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ -#endif /* MNG_ACCESS_ZLIB */ -#endif /* MNG_INCLUDE_ZLIB */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ZLIB -#ifdef MNG_ACCESS_ZLIB -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_set_zlib_maxidat (mng_handle hHandle, - mng_uint32 iMaxIDAT) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_MAXIDAT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->iMaxIDAT = iMaxIDAT; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_MAXIDAT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ -#endif /* MNG_ACCESS_ZLIB */ -#endif /* MNG_INCLUDE_ZLIB */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#ifdef MNG_ACCESS_JPEG -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_set_jpeg_dctmethod (mng_handle hHandle, - mngjpeg_dctmethod eJPEGdctmethod) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_DCTMETHOD, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->eJPEGdctmethod = eJPEGdctmethod; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_DCTMETHOD, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif MNG_SUPPORT_WRITE -#endif /* MNG_ACCESS_JPEG */ -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#ifdef MNG_ACCESS_JPEG -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_set_jpeg_quality (mng_handle hHandle, - mng_int32 iJPEGquality) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_QUALITY, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->iJPEGquality = iJPEGquality; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_QUALITY, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ -#endif /* MNG_ACCESS_JPEG */ -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#ifdef MNG_ACCESS_JPEG -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_set_jpeg_smoothing (mng_handle hHandle, - mng_int32 iJPEGsmoothing) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_SMOOTHING, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->iJPEGsmoothing = iJPEGsmoothing; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_SMOOTHING, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ -#endif /* MNG_ACCESS_JPEG */ -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#ifdef MNG_ACCESS_JPEG -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_set_jpeg_progressive (mng_handle hHandle, - mng_bool bJPEGprogressive) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_PROGRESSIVE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->bJPEGcompressprogr = bJPEGprogressive; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_PROGRESSIVE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ -#endif /* MNG_ACCESS_JPEG */ -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#ifdef MNG_ACCESS_JPEG -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_set_jpeg_optimized (mng_handle hHandle, - mng_bool bJPEGoptimized) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_OPTIMIZED, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->bJPEGcompressopt = bJPEGoptimized; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_OPTIMIZED, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ -#endif /* MNG_ACCESS_JPEG */ -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#ifdef MNG_ACCESS_JPEG -#ifdef MNG_SUPPORT_WRITE -mng_retcode MNG_DECL mng_set_jpeg_maxjdat (mng_handle hHandle, - mng_uint32 iMaxJDAT) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_MAXJDAT, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->iMaxJDAT = iMaxJDAT; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_MAXJDAT, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_WRITE */ -#endif /* MNG_ACCESS_JPEG */ -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_retcode MNG_DECL mng_set_suspensionmode (mng_handle hHandle, - mng_bool bSuspensionmode) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SUSPENSIONMODE, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - - if (((mng_datap)hHandle)->bReading) /* we must NOT be reading !!! */ - MNG_ERROR ((mng_datap)hHandle, MNG_FUNCTIONINVALID); - - ((mng_datap)hHandle)->bSuspensionmode = bSuspensionmode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SUSPENSIONMODE, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_set_speed (mng_handle hHandle, - mng_speedtype iSpeed) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SPEED, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - ((mng_datap)hHandle)->iSpeed = iSpeed; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SPEED, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ -/* * * */ -/* * Property get functions * */ -/* * * */ -/* ************************************************************************** */ - -mng_ptr MNG_DECL mng_get_userdata (mng_handle hHandle) -{ /* no tracing in here to prevent recursive calls */ - MNG_VALIDHANDLEX (hHandle) - return ((mng_datap)hHandle)->pUserdata; -} - -/* ************************************************************************** */ - -mng_imgtype MNG_DECL mng_get_sigtype (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SIGTYPE, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return mng_it_unknown; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SIGTYPE, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->eSigtype; -} - -/* ************************************************************************** */ - -mng_imgtype MNG_DECL mng_get_imagetype (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGETYPE, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return mng_it_unknown; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGETYPE, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->eImagetype; -} - -/* ************************************************************************** */ - -mng_uint32 MNG_DECL mng_get_imagewidth (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGEWIDTH, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGEWIDTH, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iWidth; -} - -/* ************************************************************************** */ - -mng_uint32 MNG_DECL mng_get_imageheight (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGEWIDTH, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGEHEIGHT, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iHeight; -} - -/* ************************************************************************** */ - -mng_uint32 MNG_DECL mng_get_ticks (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TICKS, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TICKS, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iTicks; -} - -/* ************************************************************************** */ - -mng_uint32 MNG_DECL mng_get_framecount (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_FRAMECOUNT, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_FRAMECOUNT, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iFramecount; -} - -/* ************************************************************************** */ - -mng_uint32 MNG_DECL mng_get_layercount (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_LAYERCOUNT, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_LAYERCOUNT, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iLayercount; -} - -/* ************************************************************************** */ - -mng_uint32 MNG_DECL mng_get_playtime (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_PLAYTIME, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_PLAYTIME, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iPlaytime; -} - -/* ************************************************************************** */ - -mng_uint32 MNG_DECL mng_get_simplicity (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SIMPLICITY, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SIMPLICITY, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iSimplicity; -} - -/* ************************************************************************** */ - -mng_uint8 MNG_DECL mng_get_bitdepth (mng_handle hHandle) -{ - mng_uint8 iRslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_BITDEPTH, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - - if (((mng_datap)hHandle)->eImagetype == mng_it_png) - iRslt = ((mng_datap)hHandle)->iBitdepth; - else -#ifdef MNG_INCLUDE_JNG - if (((mng_datap)hHandle)->eImagetype == mng_it_jng) - iRslt = ((mng_datap)hHandle)->iJHDRimgbitdepth; - else -#endif - iRslt = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_BITDEPTH, MNG_LC_END); -#endif - - return iRslt; -} - -/* ************************************************************************** */ - -mng_uint8 MNG_DECL mng_get_colortype (mng_handle hHandle) -{ - mng_uint8 iRslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_COLORTYPE, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - - if (((mng_datap)hHandle)->eImagetype == mng_it_png) - iRslt = ((mng_datap)hHandle)->iColortype; - else -#ifdef MNG_INCLUDE_JNG - if (((mng_datap)hHandle)->eImagetype == mng_it_jng) - iRslt = ((mng_datap)hHandle)->iJHDRcolortype; - else -#endif - iRslt = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_COLORTYPE, MNG_LC_END); -#endif - - return iRslt; -} - -/* ************************************************************************** */ - -mng_uint8 MNG_DECL mng_get_compression (mng_handle hHandle) -{ - mng_uint8 iRslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_COMPRESSION, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - - if (((mng_datap)hHandle)->eImagetype == mng_it_png) - iRslt = ((mng_datap)hHandle)->iCompression; - else -#ifdef MNG_INCLUDE_JNG - if (((mng_datap)hHandle)->eImagetype == mng_it_jng) - iRslt = ((mng_datap)hHandle)->iJHDRimgcompression; - else -#endif - iRslt = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_COMPRESSION, MNG_LC_END); -#endif - - return iRslt; -} - -/* ************************************************************************** */ - -mng_uint8 MNG_DECL mng_get_filter (mng_handle hHandle) -{ - mng_uint8 iRslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_FILTER, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - - if (((mng_datap)hHandle)->eImagetype == mng_it_png) - iRslt = ((mng_datap)hHandle)->iFilter; - else - iRslt = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_FILTER, MNG_LC_END); -#endif - - return iRslt; -} - -/* ************************************************************************** */ - -mng_uint8 MNG_DECL mng_get_interlace (mng_handle hHandle) -{ - mng_uint8 iRslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_INTERLACE, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - - if (((mng_datap)hHandle)->eImagetype == mng_it_png) - iRslt = ((mng_datap)hHandle)->iInterlace; - else -#ifdef MNG_INCLUDE_JNG - if (((mng_datap)hHandle)->eImagetype == mng_it_jng) - iRslt = ((mng_datap)hHandle)->iJHDRimginterlace; - else -#endif - iRslt = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_INTERLACE, MNG_LC_END); -#endif - - return iRslt; -} - -/* ************************************************************************** */ - -mng_uint8 MNG_DECL mng_get_alphabitdepth (mng_handle hHandle) -{ - mng_uint8 iRslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHABITDEPTH, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_INCLUDE_JNG - if (((mng_datap)hHandle)->eImagetype == mng_it_jng) - iRslt = ((mng_datap)hHandle)->iJHDRalphabitdepth; - else -#endif - iRslt = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHABITDEPTH, MNG_LC_END); -#endif - - return iRslt; -} - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_uint8 MNG_DECL mng_get_refreshpass (mng_handle hHandle) -{ - mng_uint8 iRslt; - mng_datap pData; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_REFRESHPASS, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - - pData = (mng_datap)hHandle; - /* for PNG we know the exact pass */ - if ((pData->eImagetype == mng_it_png) && (pData->iPass >= 0)) - iRslt = pData->iPass; -#ifdef MNG_INCLUDE_JNG - else /* for JNG we'll fake it... */ - if ((pData->eImagetype == mng_it_jng) && - (pData->bJPEGhasheader) && (pData->bJPEGdecostarted) && - (pData->bJPEGprogressive)) - { - if (pData->pJPEGdinfo->input_scan_number <= 1) - iRslt = 0; /* first pass (I think...) */ - else - if (jpeg_input_complete (pData->pJPEGdinfo)) - iRslt = 7; /* input complete; aka final pass */ - else - iRslt = 3; /* anything between 0 and 7 will do */ - - } -#endif - else - iRslt = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_REFRESHPASS, MNG_LC_END); -#endif - - return iRslt; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ -mng_uint8 MNG_DECL mng_get_alphacompression (mng_handle hHandle) -{ - mng_uint8 iRslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHACOMPRESSION, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_INCLUDE_JNG - if (((mng_datap)hHandle)->eImagetype == mng_it_jng) - iRslt = ((mng_datap)hHandle)->iJHDRalphacompression; - else -#endif - iRslt = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHACOMPRESSION, MNG_LC_END); -#endif - - return iRslt; -} - -/* ************************************************************************** */ - -mng_uint8 MNG_DECL mng_get_alphafilter (mng_handle hHandle) -{ - mng_uint8 iRslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHAFILTER, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_INCLUDE_JNG - if (((mng_datap)hHandle)->eImagetype == mng_it_jng) - iRslt = ((mng_datap)hHandle)->iJHDRalphafilter; - else -#endif - iRslt = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHAFILTER, MNG_LC_END); -#endif - - return iRslt; -} - -/* ************************************************************************** */ - -mng_uint8 MNG_DECL mng_get_alphainterlace (mng_handle hHandle) -{ - mng_uint8 iRslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHAINTERLACE, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_INCLUDE_JNG - if (((mng_datap)hHandle)->eImagetype == mng_it_jng) - iRslt = ((mng_datap)hHandle)->iJHDRalphainterlace; - else -#endif - iRslt = 0; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHAINTERLACE, MNG_LC_END); -#endif - - return iRslt; -} - -/* ************************************************************************** */ - -mng_uint8 MNG_DECL mng_get_alphadepth (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHADEPTH, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHADEPTH, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iAlphadepth; -} - -/* ************************************************************************** */ - -mng_uint32 MNG_DECL mng_get_canvasstyle (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CANVASSTYLE, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CANVASSTYLE, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iCanvasstyle; -} - -/* ************************************************************************** */ - -mng_uint32 MNG_DECL mng_get_bkgdstyle (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_BKGDSTYLE, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_BKGDSTYLE, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iBkgdstyle; -} - -/* ************************************************************************** */ - -mng_retcode MNG_DECL mng_get_bgcolor (mng_handle hHandle, - mng_uint16* iRed, - mng_uint16* iGreen, - mng_uint16* iBlue) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GET_BGCOLOR, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - *iRed = ((mng_datap)hHandle)->iBGred; - *iGreen = ((mng_datap)hHandle)->iBGgreen; - *iBlue = ((mng_datap)hHandle)->iBGblue; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (((mng_datap)hHandle), MNG_FN_GET_BGCOLOR, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_bool MNG_DECL mng_get_usebkgd (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_USEBKGD, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_USEBKGD, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bUseBKGD; -} - -/* ************************************************************************** */ - -mng_bool MNG_DECL mng_get_storechunks (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_STORECHUNKS, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_STORECHUNKS, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bStorechunks; -} - -/* ************************************************************************** */ - -mng_bool MNG_DECL mng_get_sectionbreaks (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_SECTIONBREAKS, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_SECTIONBREAKS, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bSectionbreaks; -} - -/* ************************************************************************** */ - -mng_bool MNG_DECL mng_get_cacheplayback (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_CACHEPLAYBACK, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_CACHEPLAYBACK, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bCacheplayback; -} - -/* ************************************************************************** */ - -mng_bool MNG_DECL mng_get_doprogressive (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_DOPROGRESSIVE, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_DOPROGRESSIVE, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bDoProgressive; -} - -/* ************************************************************************** */ - -mng_uint32 MNG_DECL mng_get_crcmode (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_CRCMODE, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_CRCMODE, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iCrcmode; -} - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_bool MNG_DECL mng_get_srgb (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_SRGB, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_SRGB, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bIssRGB; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) -mng_float MNG_DECL mng_get_viewgamma (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_VIEWGAMMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_VIEWGAMMA, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->dViewgamma; -} -#endif - -/* ************************************************************************** */ - -#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) -mng_float MNG_DECL mng_get_displaygamma (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DISPLAYGAMMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DISPLAYGAMMA, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->dDisplaygamma; -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DFLT_INFO -#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) -mng_float MNG_DECL mng_get_dfltimggamma (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DFLTIMGGAMMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DFLTIMGGAMMA, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->dDfltimggamma; -} -#endif -#endif - -/* ************************************************************************** */ - -#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) -mng_uint32 MNG_DECL mng_get_viewgammaint (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_VIEWGAMMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_VIEWGAMMA, MNG_LC_END); -#endif - - return (mng_uint32)(((mng_datap)hHandle)->dViewgamma * 100000); -} -#endif - -/* ************************************************************************** */ - -#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) -mng_uint32 MNG_DECL mng_get_displaygammaint (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DISPLAYGAMMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DISPLAYGAMMA, MNG_LC_END); -#endif - - return (mng_uint32)(((mng_datap)hHandle)->dDisplaygamma * 100000); -} -#endif - -/* ************************************************************************** */ - -#ifndef MNG_NO_DFLT_INFO -#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) -mng_uint32 MNG_DECL mng_get_dfltimggammaint (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DFLTIMGGAMMA, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DFLTIMGGAMMA, MNG_LC_END); -#endif - - return (mng_uint32)(((mng_datap)hHandle)->dDfltimggamma * 100000); -} -#endif -#endif - -/* ************************************************************************** */ - -#ifndef MNG_SKIP_MAXCANVAS -mng_uint32 MNG_DECL mng_get_maxcanvaswidth (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_MAXCANVASWIDTH, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_MAXCANVASWIDTH, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iMaxwidth; -} - -/* ************************************************************************** */ - -mng_uint32 MNG_DECL mng_get_maxcanvasheight (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_MAXCANVASHEIGHT, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_MAXCANVASHEIGHT, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iMaxheight; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ZLIB -#ifdef MNG_ACCESS_ZLIB -mng_int32 MNG_DECL mng_get_zlib_level (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_LEVEL, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_LEVEL, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iZlevel; -} -#endif /* MNG_ACCESS_ZLIB */ -#endif /* MNG_INCLUDE_ZLIB */ - -/* ************************************************************************** */ -#ifdef MNG_INCLUDE_ZLIB -#ifdef MNG_ACCESS_ZLIB -mng_int32 MNG_DECL mng_get_zlib_method (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_METHOD, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_METHOD, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iZmethod; -} - -#endif /* MNG_ACCESS_ZLIB */ -#endif /* MNG_INCLUDE_ZLIB */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ZLIB -#ifdef MNG_ACCESS_ZLIB -mng_int32 MNG_DECL mng_get_zlib_windowbits (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_WINDOWBITS, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_WINDOWBITS, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iZwindowbits; -} -#endif /* MNG_ACCESS_ZLIB */ -#endif /* MNG_INCLUDE_ZLIB */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ZLIB -#ifdef MNG_ACCESS_ZLIB -mng_int32 MNG_DECL mng_get_zlib_memlevel (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_MEMLEVEL, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_MEMLEVEL, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iZmemlevel; -} -#endif /* MNG_ACCESS_ZLIB */ -#endif /* MNG_INCLUDE_ZLIB */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ZLIB -#ifdef MNG_ACCESS_ZLIB -mng_int32 MNG_DECL mng_get_zlib_strategy (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_STRATEGY, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_STRATEGY, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iZstrategy; -} -#endif /* MNG_ACCESS_ZLIB */ -#endif /* MNG_INCLUDE_ZLIB */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ZLIB -#ifdef MNG_ACCESS_ZLIB -mng_uint32 MNG_DECL mng_get_zlib_maxidat (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_MAXIDAT, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_MAXIDAT, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iMaxIDAT; -} -#endif /* MNG_ACCESS_ZLIB */ -#endif /* MNG_INCLUDE_ZLIB */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#ifdef MNG_ACCESS_JPEG -mngjpeg_dctmethod MNG_DECL mng_get_jpeg_dctmethod (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_DCTMETHOD, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return JDCT_ISLOW; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_DCTMETHOD, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->eJPEGdctmethod; -} -#endif /* MNG_ACCESS_JPEG */ -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#ifdef MNG_ACCESS_JPEG -mng_int32 MNG_DECL mng_get_jpeg_quality (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_QUALITY, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_QUALITY, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iJPEGquality; -} -#endif /* MNG_ACCESS_JPEG */ -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#ifdef MNG_ACCESS_JPEG -mng_int32 MNG_DECL mng_get_jpeg_smoothing (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_SMOOTHING, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_SMOOTHING, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iJPEGsmoothing; -} -#endif /* MNG_ACCESS_JPEG */ -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#ifdef MNG_ACCESS_JPEG -mng_bool MNG_DECL mng_get_jpeg_progressive (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_PROGRESSIVE, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_PROGRESSIVE, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bJPEGcompressprogr; -} -#endif /* MNG_ACCESS_JPEG */ -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#ifdef MNG_ACCESS_JPEG -mng_bool MNG_DECL mng_get_jpeg_optimized (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_OPTIMIZED, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_OPTIMIZED, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bJPEGcompressopt; -} -#endif /* MNG_ACCESS_JPEG */ -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_JNG -#ifdef MNG_ACCESS_JPEG -mng_uint32 MNG_DECL mng_get_jpeg_maxjdat (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_MAXJDAT, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_MAXJDAT, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iMaxJDAT; -} -#endif /* MNG_ACCESS_JPEG */ -#endif /* MNG_INCLUDE_JNG */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_bool MNG_DECL mng_get_suspensionmode (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SUSPENSIONMODE, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SUSPENSIONMODE, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bSuspensionmode; -} -#endif /* MNG_SUPPORT_READ */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_speedtype MNG_DECL mng_get_speed (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SPEED, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return mng_st_normal; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SPEED, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iSpeed; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -mng_uint32 MNG_DECL mng_get_imagelevel (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGELEVEL, MNG_LC_START); -#endif - - MNG_VALIDHANDLEX (hHandle) - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGELEVEL, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iImagelevel; -} - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_get_lastbackchunk (mng_handle hHandle, - mng_uint16* iRed, - mng_uint16* iGreen, - mng_uint16* iBlue, - mng_uint8* iMandatory) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_LASTBACKCHUNK, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - - if (((mng_datap)hHandle)->eImagetype != mng_it_mng) - MNG_ERROR (((mng_datap)hHandle), MNG_FUNCTIONINVALID); - - *iRed = ((mng_datap)hHandle)->iBACKred; - *iGreen = ((mng_datap)hHandle)->iBACKgreen; - *iBlue = ((mng_datap)hHandle)->iBACKblue; - *iMandatory = ((mng_datap)hHandle)->iBACKmandatory; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_LASTBACKCHUNK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode MNG_DECL mng_get_lastseekname (mng_handle hHandle, - mng_pchar zSegmentname) -{ - mng_datap pData; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_LASTSEEKNAME, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - - pData = (mng_datap)hHandle; - /* only allowed for MNG ! */ - if (pData->eImagetype != mng_it_mng) - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - if (pData->pLastseek) /* is there a last SEEK ? */ - { - mng_ani_seekp pSEEK = (mng_ani_seekp)pData->pLastseek; - - if (pSEEK->iSegmentnamesize) /* copy the name if there is one */ - MNG_COPY (zSegmentname, pSEEK->zSegmentname, pSEEK->iSegmentnamesize); - - *(((mng_uint8p)zSegmentname) + pSEEK->iSegmentnamesize) = 0; - } - else - { /* return an empty string */ - *((mng_uint8p)zSegmentname) = 0; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_LASTSEEKNAME, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_uint32 MNG_DECL mng_get_currframdelay (mng_handle hHandle) -{ - mng_datap pData; - mng_uint32 iRslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRFRAMDELAY, MNG_LC_START); -#endif - - MNG_VALIDHANDLE (hHandle) - - pData = (mng_datap)hHandle; - /* only allowed for MNG ! */ - if (pData->eImagetype != mng_it_mng) - MNG_ERROR (pData, MNG_FUNCTIONINVALID); - - iRslt = pData->iFramedelay; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRFRAMDELAY, MNG_LC_END); -#endif - - return iRslt; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_uint32 MNG_DECL mng_get_starttime (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_STARTTIME, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return mng_st_normal; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_STARTTIME, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iStarttime; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_uint32 MNG_DECL mng_get_runtime (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_RUNTIME, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return mng_st_normal; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_RUNTIME, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iRuntime; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_NO_CURRENT_INFO -mng_uint32 MNG_DECL mng_get_currentframe (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRENTFRAME, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return mng_st_normal; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRENTFRAME, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iFrameseq; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_NO_CURRENT_INFO -mng_uint32 MNG_DECL mng_get_currentlayer (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRENTLAYER, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return mng_st_normal; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRENTLAYER, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iLayerseq; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_NO_CURRENT_INFO -mng_uint32 MNG_DECL mng_get_currentplaytime (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRENTPLAYTIME, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return mng_st_normal; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRENTPLAYTIME, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iFrametime; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_NO_CURRENT_INFO -mng_uint32 MNG_DECL mng_get_totalframes (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TOTALFRAMES, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return mng_st_normal; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TOTALFRAMES, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iTotalframes; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_NO_CURRENT_INFO -mng_uint32 MNG_DECL mng_get_totallayers (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TOTALLAYERS, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return mng_st_normal; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TOTALLAYERS, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iTotallayers; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -#ifndef MNG_NO_CURRENT_INFO -mng_uint32 MNG_DECL mng_get_totalplaytime (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TOTALPLAYTIME, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return mng_st_normal; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TOTALPLAYTIME, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->iTotalplaytime; -} -#endif -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -mng_bool MNG_DECL mng_status_error (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_ERROR, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_ERROR, MNG_LC_END); -#endif - - return (mng_bool)((mng_datap)hHandle)->iErrorcode; -} - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_bool MNG_DECL mng_status_reading (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_READING, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_READING, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bReading; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_READ -mng_bool MNG_DECL mng_status_suspendbreak (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_SUSPENDBREAK, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_SUSPENDBREAK, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bSuspended; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_WRITE -mng_bool MNG_DECL mng_status_creating (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_CREATING, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_CREATING, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bCreating; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_WRITE -mng_bool MNG_DECL mng_status_writing (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_WRITING, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_WRITING, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bWriting; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_bool MNG_DECL mng_status_displaying (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_DISPLAYING, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_DISPLAYING, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bDisplaying; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_bool MNG_DECL mng_status_running (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_RUNNING, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_RUNNING, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bRunning; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_bool MNG_DECL mng_status_timerbreak (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_TIMERBREAK, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_TIMERBREAK, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bTimerset; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DYNAMICMNG -mng_bool MNG_DECL mng_status_dynamic (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_DYNAMIC, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_DYNAMIC, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bDynamic; -} -#endif - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DYNAMICMNG -mng_bool MNG_DECL mng_status_runningevent (mng_handle hHandle) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_RUNNINGEVENT, MNG_LC_START); -#endif - - if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) - return MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_RUNNINGEVENT, MNG_LC_END); -#endif - - return ((mng_datap)hHandle)->bRunningevent; -} -#endif - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_prop_xs.c copyright (c) 2000-2006 G.Juyn * */ +/* * version : 1.0.10 * */ +/* * * */ +/* * purpose : property get/set interface (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the property get/set functions * */ +/* * * */ +/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - fixed calling convention * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/11/2000 - G.Juyn * */ +/* * - added set_outputprofile2 & set_srgbprofile2 * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - changed trace to macro for callback error-reporting * */ +/* * * */ +/* * 0.5.2 - 05/23/2000 - G.Juyn * */ +/* * - changed inclusion of cms-routines * */ +/* * 0.5.2 - 05/24/2000 - G.Juyn * */ +/* * - added support for get/set default zlib/IJG parms * */ +/* * 0.5.2 - 05/31/2000 - G.Juyn * */ +/* * - fixed up punctuation (contribution by Tim Rowley) * */ +/* * 0.5.2 - 06/05/2000 - G.Juyn * */ +/* * - added support for RGB8_A8 canvasstyle * */ +/* * * */ +/* * 0.5.3 - 06/21/2000 - G.Juyn * */ +/* * - added get/set for speedtype to facilitate testing * */ +/* * - added get for imagelevel during processtext callback * */ +/* * 0.5.3 - 06/26/2000 - G.Juyn * */ +/* * - changed userdata variable to mng_ptr * */ +/* * 0.5.3 - 06/29/2000 - G.Juyn * */ +/* * - fixed incompatible return-types * */ +/* * * */ +/* * 0.9.1 - 07/08/2000 - G.Juyn * */ +/* * - added get routines for internal display variables * */ +/* * - added get/set routines for suspensionmode variable * */ +/* * 0.9.1 - 07/15/2000 - G.Juyn * */ +/* * - added get/set routines for sectionbreak variable * */ +/* * * */ +/* * 0.9.2 - 07/31/2000 - G.Juyn * */ +/* * - added status_xxxx functions * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 0.9.3 - 10/10/2000 - G.Juyn * */ +/* * - added support for alpha-depth prediction * */ +/* * 0.9.3 - 10/16/2000 - G.Juyn * */ +/* * - added functions to retrieve PNG/JNG specific header-info * */ +/* * 0.9.3 - 10/20/2000 - G.Juyn * */ +/* * - added get/set for bKGD preference setting * */ +/* * 0.9.3 - 10/21/2000 - G.Juyn * */ +/* * - added get function for interlace/progressive display * */ +/* * * */ +/* * 1.0.1 - 04/21/2001 - G.Juyn (code by G.Kelly) * */ +/* * - added BGRA8 canvas with premultiplied alpha * */ +/* * 1.0.1 - 05/02/2001 - G.Juyn * */ +/* * - added "default" sRGB generation (Thanks Marti!) * */ +/* * * */ +/* * 1.0.2 - 06/23/2001 - G.Juyn * */ +/* * - added optimization option for MNG-video playback * */ +/* * 1.0.2 - 06/25/2001 - G.Juyn * */ +/* * - added option to turn off progressive refresh * */ +/* * * */ +/* * 1.0.3 - 08/06/2001 - G.Juyn * */ +/* * - added get function for last processed BACK chunk * */ +/* * * */ +/* * 1.0.4 - 06/22/2002 - G.Juyn * */ +/* * - B495442 - invalid returnvalue in mng_get_suspensionmode * */ +/* * * */ +/* * 1.0.5 - 09/14/2002 - G.Juyn * */ +/* * - added event handling for dynamic MNG * */ +/* * 1.0.5 - 09/22/2002 - G.Juyn * */ +/* * - added bgrx8 canvas (filler byte) * */ +/* * 1.0.5 - 11/07/2002 - G.Juyn * */ +/* * - added support to get totals after mng_read() * */ +/* * * */ +/* * 1.0.6 - 05/11/2003 - G. Juyn * */ +/* * - added conditionals around canvas update routines * */ +/* * 1.0.6 - 07/07/2003 - G.R-P * */ +/* * - added conditionals around some JNG-supporting code * */ +/* * 1.0.6 - 07/11/2003 - G.R-P * */ +/* * - added conditionals zlib and jpeg property accessors * */ +/* * 1.0.6 - 07/14/2003 - G.R-P * */ +/* * - added conditionals around various unused functions * */ +/* * * */ +/* * 1.0.7 - 11/27/2003 - R.A * */ +/* * - added CANVAS_RGB565 and CANVAS_BGR565 * */ +/* * 1.0.7 - 12/06/2003 - R.A * */ +/* * - added CANVAS_RGBA565 and CANVAS_BGRA565 * */ +/* * 1.0.7 - 01/25/2004 - J.S * */ +/* * - added premultiplied alpha canvas' for RGBA, ARGB, ABGR * */ +/* * 1.0.7 - 03/07/2004 - G.R-P. * */ +/* * - put gamma, cms-related functions inside #ifdef * */ +/* * * */ +/* * 1.0.8 - 04/02/2004 - G.Juyn * */ +/* * - added CRC existence & checking flags * */ +/* * * */ +/* * 1.0.9 - 09/18/2004 - G.R-P. * */ +/* * - added some MNG_SUPPORT_WRITE conditionals * */ +/* * 1.0.9 - 10/03/2004 - G.Juyn * */ +/* * - added function to retrieve current FRAM delay * */ +/* * 1.0.9 - 10/14/2004 - G.Juyn * */ +/* * - added bgr565_a8 canvas-style (thanks to J. Elvander) * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * * */ +/* * 1.0.10 - 03/07/2006 - (thanks to W. Manthey) * */ +/* * - added CANVAS_RGB555 and CANVAS_BGR555 * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_objects.h" +#include "libmng_memory.h" +#include "libmng_cms.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ +/* * * */ +/* * Property set functions * */ +/* * * */ +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_userdata (mng_handle hHandle, + mng_ptr pUserdata) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_USERDATA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->pUserdata = pUserdata; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_USERDATA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_canvasstyle (mng_handle hHandle, + mng_uint32 iStyle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_CANVASSTYLE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + + switch (iStyle) + { +#ifndef MNG_SKIPCANVAS_RGB8 + case MNG_CANVAS_RGB8 : break; +#endif +#ifndef MNG_SKIPCANVAS_RGBA8 + case MNG_CANVAS_RGBA8 : break; +#endif +#ifndef MNG_SKIPCANVAS_RGBA8_PM + case MNG_CANVAS_RGBA8_PM: break; +#endif +#ifndef MNG_SKIPCANVAS_ARGB8 + case MNG_CANVAS_ARGB8 : break; +#endif +#ifndef MNG_SKIPCANVAS_ARGB8_PM + case MNG_CANVAS_ARGB8_PM: break; +#endif +#ifndef MNG_SKIPCANVAS_RGB8_A8 + case MNG_CANVAS_RGB8_A8 : break; +#endif +#ifndef MNG_SKIPCANVAS_BGR8 + case MNG_CANVAS_BGR8 : break; +#endif +#ifndef MNG_SKIPCANVAS_BGRX8 + case MNG_CANVAS_BGRX8 : break; +#endif +#ifndef MNG_SKIPCANVAS_BGRA8 + case MNG_CANVAS_BGRA8 : break; +#endif +#ifndef MNG_SKIPCANVAS_BGRA8_PM + case MNG_CANVAS_BGRA8_PM: break; +#endif +#ifndef MNG_SKIPCANVAS_ABGR8 + case MNG_CANVAS_ABGR8 : break; +#endif +#ifndef MNG_SKIPCANVAS_ABGR8_PM + case MNG_CANVAS_ABGR8_PM: break; +#endif +#ifndef MNG_SKIPCANVAS_RGB565 + case MNG_CANVAS_RGB565 : break; +#endif +#ifndef MNG_SKIPCANVAS_RGBA565 + case MNG_CANVAS_RGBA565 : break; +#endif +#ifndef MNG_SKIPCANVAS_BGR565 + case MNG_CANVAS_BGR565 : break; +#endif +#ifndef MNG_SKIPCANVAS_BGRA565 + case MNG_CANVAS_BGRA565 : break; +#endif +#ifndef MNG_SKIPCANVAS_BGR565_A8 + case MNG_CANVAS_BGR565_A8 : break; +#endif +#ifndef MNG_SKIPCANVAS_RGB555 + case MNG_CANVAS_RGB555 : break; +#endif +#ifndef MNG_SKIPCANVAS_BGR555 + case MNG_CANVAS_BGR555 : break; +#endif +/* case MNG_CANVAS_RGB16 : break; */ +/* case MNG_CANVAS_RGBA16 : break; */ +/* case MNG_CANVAS_ARGB16 : break; */ +/* case MNG_CANVAS_BGR16 : break; */ +/* case MNG_CANVAS_BGRA16 : break; */ +/* case MNG_CANVAS_ABGR16 : break; */ +/* case MNG_CANVAS_INDEX8 : break; */ +/* case MNG_CANVAS_INDEXA8 : break; */ +/* case MNG_CANVAS_AINDEX8 : break; */ +/* case MNG_CANVAS_GRAY8 : break; */ +/* case MNG_CANVAS_GRAY16 : break; */ +/* case MNG_CANVAS_GRAYA8 : break; */ +/* case MNG_CANVAS_GRAYA16 : break; */ +/* case MNG_CANVAS_AGRAY8 : break; */ +/* case MNG_CANVAS_AGRAY16 : break; */ +/* case MNG_CANVAS_DX15 : break; */ +/* case MNG_CANVAS_DX16 : break; */ + default : { MNG_ERROR (((mng_datap)hHandle), MNG_INVALIDCNVSTYLE) }; + } + + ((mng_datap)hHandle)->iCanvasstyle = iStyle; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_CANVASSTYLE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_bkgdstyle (mng_handle hHandle, + mng_uint32 iStyle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_BKGDSTYLE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + + switch (iStyle) /* alpha-modes not supported */ + { +#ifndef MNG_SKIPCANVAS_RGB8 + case MNG_CANVAS_RGB8 : break; +#endif +#ifndef MNG_SKIPCANVAS_BGR8 + case MNG_CANVAS_BGR8 : break; +#endif +#ifndef MNG_SKIPCANVAS_BGRX8 + case MNG_CANVAS_BGRX8 : break; +#endif +#ifndef MNG_SKIPCANVAS_RGB565 + case MNG_CANVAS_RGB565 : break; +#endif +#ifndef MNG_SKIPCANVAS_BGR565 + case MNG_CANVAS_BGR565 : break; +#endif +/* case MNG_CANVAS_RGB16 : break; */ +/* case MNG_CANVAS_BGR16 : break; */ +/* case MNG_CANVAS_INDEX8 : break; */ +/* case MNG_CANVAS_GRAY8 : break; */ +/* case MNG_CANVAS_GRAY16 : break; */ +/* case MNG_CANVAS_DX15 : break; */ +/* case MNG_CANVAS_DX16 : break; */ + default : MNG_ERROR (((mng_datap)hHandle), MNG_INVALIDCNVSTYLE); + } + + ((mng_datap)hHandle)->iBkgdstyle = iStyle; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_BKGDSTYLE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_bgcolor (mng_handle hHandle, + mng_uint16 iRed, + mng_uint16 iGreen, + mng_uint16 iBlue) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_BGCOLOR, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->iBGred = iRed; + ((mng_datap)hHandle)->iBGgreen = iGreen; + ((mng_datap)hHandle)->iBGblue = iBlue; + ((mng_datap)hHandle)->bUseBKGD = MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_BGCOLOR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_usebkgd (mng_handle hHandle, + mng_bool bUseBKGD) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_USEBKGD, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->bUseBKGD = bUseBKGD; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_USEBKGD, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_storechunks (mng_handle hHandle, + mng_bool bStorechunks) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_STORECHUNKS, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->bStorechunks = bStorechunks; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_STORECHUNKS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_sectionbreaks (mng_handle hHandle, + mng_bool bSectionbreaks) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SECTIONBREAKS, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->bSectionbreaks = bSectionbreaks; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SECTIONBREAKS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_cacheplayback (mng_handle hHandle, + mng_bool bCacheplayback) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_CACHEPLAYBACK, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + + if (((mng_datap)hHandle)->bHasheader) + MNG_ERROR (((mng_datap)hHandle), MNG_FUNCTIONINVALID); + + ((mng_datap)hHandle)->bCacheplayback = bCacheplayback; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_CACHEPLAYBACK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_doprogressive (mng_handle hHandle, + mng_bool bDoProgressive) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DOPROGRESSIVE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + + ((mng_datap)hHandle)->bDoProgressive = bDoProgressive; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DOPROGRESSIVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_crcmode (mng_handle hHandle, + mng_uint32 iCrcmode) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_CRCMODE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + + ((mng_datap)hHandle)->iCrcmode = iCrcmode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_CRCMODE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_set_srgb (mng_handle hHandle, + mng_bool bIssRGB) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGB, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->bIssRGB = bIssRGB; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGB, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_SKIPCHUNK_iCCP +mng_retcode MNG_DECL mng_set_outputprofile (mng_handle hHandle, + mng_pchar zFilename) +{ +#ifdef MNG_INCLUDE_LCMS + mng_datap pData; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_OUTPUTPROFILE, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_LCMS + MNG_VALIDHANDLE (hHandle) + + pData = (mng_datap)hHandle; /* address the structure */ + + if (pData->hProf2) /* previously defined ? */ + mnglcms_freeprofile (pData->hProf2); + /* allocate new CMS profile handle */ + pData->hProf2 = mnglcms_createfileprofile (zFilename); + + if (!pData->hProf2) /* handle error ? */ + MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); +#endif /* MNG_INCLUDE_LCMS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_OUTPUTPROFILE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_SKIPCHUNK_iCCP +mng_retcode MNG_DECL mng_set_outputprofile2 (mng_handle hHandle, + mng_uint32 iProfilesize, + mng_ptr pProfile) +{ +#ifdef MNG_INCLUDE_LCMS + mng_datap pData; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_OUTPUTPROFILE2, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_LCMS + MNG_VALIDHANDLE (hHandle) + + pData = (mng_datap)hHandle; /* address the structure */ + + if (pData->hProf2) /* previously defined ? */ + mnglcms_freeprofile (pData->hProf2); + /* allocate new CMS profile handle */ + pData->hProf2 = mnglcms_creatememprofile (iProfilesize, pProfile); + + if (!pData->hProf2) /* handle error ? */ + MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); +#endif /* MNG_INCLUDE_LCMS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_OUTPUTPROFILE2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_outputsrgb (mng_handle hHandle) +{ +#ifdef MNG_INCLUDE_LCMS + mng_datap pData; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_OUTPUTSRGB, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_LCMS + MNG_VALIDHANDLE (hHandle) + + pData = (mng_datap)hHandle; /* address the structure */ + + if (pData->hProf2) /* previously defined ? */ + mnglcms_freeprofile (pData->hProf2); + /* allocate new CMS profile handle */ + pData->hProf2 = mnglcms_createsrgbprofile (); + + if (!pData->hProf2) /* handle error ? */ + MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); +#endif /* MNG_INCLUDE_LCMS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_OUTPUTSRGB, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_set_srgbprofile (mng_handle hHandle, + mng_pchar zFilename) +{ +#ifdef MNG_INCLUDE_LCMS + mng_datap pData; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGBPROFILE2, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_LCMS + MNG_VALIDHANDLE (hHandle) + + pData = (mng_datap)hHandle; /* address the structure */ + + if (pData->hProf3) /* previously defined ? */ + mnglcms_freeprofile (pData->hProf3); + /* allocate new CMS profile handle */ + pData->hProf3 = mnglcms_createfileprofile (zFilename); + + if (!pData->hProf3) /* handle error ? */ + MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); +#endif /* MNG_INCLUDE_LCMS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGBPROFILE2, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_set_srgbprofile2 (mng_handle hHandle, + mng_uint32 iProfilesize, + mng_ptr pProfile) +{ +#ifdef MNG_INCLUDE_LCMS + mng_datap pData; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGBPROFILE, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_LCMS + MNG_VALIDHANDLE (hHandle) + + pData = (mng_datap)hHandle; /* address the structure */ + + if (pData->hProf3) /* previously defined ? */ + mnglcms_freeprofile (pData->hProf3); + /* allocate new CMS profile handle */ + pData->hProf3 = mnglcms_creatememprofile (iProfilesize, pProfile); + + if (!pData->hProf3) /* handle error ? */ + MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); +#endif /* MNG_INCLUDE_LCMS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGBPROFILE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_srgbimplicit (mng_handle hHandle) +{ +#ifdef MNG_INCLUDE_LCMS + mng_datap pData; +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGBIMPLICIT, MNG_LC_START); +#endif + +#ifdef MNG_INCLUDE_LCMS + MNG_VALIDHANDLE (hHandle) + + pData = (mng_datap)hHandle; /* address the structure */ + + if (pData->hProf3) /* previously defined ? */ + mnglcms_freeprofile (pData->hProf3); + /* allocate new CMS profile handle */ + pData->hProf3 = mnglcms_createsrgbprofile (); + + if (!pData->hProf3) /* handle error ? */ + MNG_ERRORL (pData, MNG_LCMS_NOHANDLE); +#endif /* MNG_INCLUDE_LCMS */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SRGBIMPLICIT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) +mng_retcode MNG_DECL mng_set_viewgamma (mng_handle hHandle, + mng_float dGamma) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_VIEWGAMMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->dViewgamma = dGamma; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_VIEWGAMMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_displaygamma (mng_handle hHandle, + mng_float dGamma) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DISPLAYGAMMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->dDisplaygamma = dGamma; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DISPLAYGAMMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_dfltimggamma (mng_handle hHandle, + mng_float dGamma) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DFLTIMGGAMMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->dDfltimggamma = dGamma; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DFLTIMGGAMMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) +mng_retcode MNG_DECL mng_set_viewgammaint (mng_handle hHandle, + mng_uint32 iGamma) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_VIEWGAMMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->dViewgamma = (mng_float)iGamma / 100000; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_VIEWGAMMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_displaygammaint (mng_handle hHandle, + mng_uint32 iGamma) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DISPLAYGAMMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->dDisplaygamma = (mng_float)iGamma / 100000; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DISPLAYGAMMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#ifndef MNG_NO_DFLT_INFO +mng_retcode MNG_DECL mng_set_dfltimggammaint (mng_handle hHandle, + mng_uint32 iGamma) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DFLTIMGGAMMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->dDfltimggamma = (mng_float)iGamma / 100000; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_DFLTIMGGAMMA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIP_MAXCANVAS +mng_retcode MNG_DECL mng_set_maxcanvaswidth (mng_handle hHandle, + mng_uint32 iMaxwidth) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_MAXCANVASWIDTH, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->iMaxwidth = iMaxwidth; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_MAXCANVASWIDTH, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_maxcanvasheight (mng_handle hHandle, + mng_uint32 iMaxheight) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_MAXCANVASHEIGHT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->iMaxheight = iMaxheight; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_MAXCANVASHEIGHT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_set_maxcanvassize (mng_handle hHandle, + mng_uint32 iMaxwidth, + mng_uint32 iMaxheight) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_MAXCANVASSIZE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->iMaxwidth = iMaxwidth; + ((mng_datap)hHandle)->iMaxheight = iMaxheight; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_MAXCANVASSIZE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ZLIB +#ifdef MNG_ACCESS_ZLIB +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_set_zlib_level (mng_handle hHandle, + mng_int32 iZlevel) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_LEVEL, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->iZlevel = iZlevel; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_LEVEL, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ +#endif /* MNG_ACCESS_ZLIB */ +#endif /* MNG_INCLUDE_ZLIB */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ZLIB +#ifdef MNG_ACCESS_ZLIB +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_set_zlib_method (mng_handle hHandle, + mng_int32 iZmethod) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_METHOD, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->iZmethod = iZmethod; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_METHOD, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ +#endif /* MNG_ACCESS_ZLIB */ +#endif /* MNG_INCLUDE_ZLIB */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ZLIB +#ifdef MNG_ACCESS_ZLIB +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_set_zlib_windowbits (mng_handle hHandle, + mng_int32 iZwindowbits) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_WINDOWBITS, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->iZwindowbits = iZwindowbits; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_WINDOWBITS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ +#endif /* MNG_ACCESS_ZLIB */ +#endif /* MNG_INCLUDE_ZLIB */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ZLIB +#ifdef MNG_ACCESS_ZLIB +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_set_zlib_memlevel (mng_handle hHandle, + mng_int32 iZmemlevel) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_MEMLEVEL, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->iZmemlevel = iZmemlevel; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_MEMLEVEL, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ +#endif /* MNG_ACCESS_ZLIB */ +#endif /* MNG_INCLUDE_ZLIB */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ZLIB +#ifdef MNG_ACCESS_ZLIB +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_set_zlib_strategy (mng_handle hHandle, + mng_int32 iZstrategy) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_STRATEGY, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->iZstrategy = iZstrategy; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_STRATEGY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ +#endif /* MNG_ACCESS_ZLIB */ +#endif /* MNG_INCLUDE_ZLIB */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ZLIB +#ifdef MNG_ACCESS_ZLIB +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_set_zlib_maxidat (mng_handle hHandle, + mng_uint32 iMaxIDAT) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_MAXIDAT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->iMaxIDAT = iMaxIDAT; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_ZLIB_MAXIDAT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ +#endif /* MNG_ACCESS_ZLIB */ +#endif /* MNG_INCLUDE_ZLIB */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#ifdef MNG_ACCESS_JPEG +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_set_jpeg_dctmethod (mng_handle hHandle, + mngjpeg_dctmethod eJPEGdctmethod) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_DCTMETHOD, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->eJPEGdctmethod = eJPEGdctmethod; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_DCTMETHOD, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif MNG_SUPPORT_WRITE +#endif /* MNG_ACCESS_JPEG */ +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#ifdef MNG_ACCESS_JPEG +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_set_jpeg_quality (mng_handle hHandle, + mng_int32 iJPEGquality) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_QUALITY, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->iJPEGquality = iJPEGquality; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_QUALITY, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ +#endif /* MNG_ACCESS_JPEG */ +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#ifdef MNG_ACCESS_JPEG +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_set_jpeg_smoothing (mng_handle hHandle, + mng_int32 iJPEGsmoothing) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_SMOOTHING, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->iJPEGsmoothing = iJPEGsmoothing; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_SMOOTHING, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ +#endif /* MNG_ACCESS_JPEG */ +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#ifdef MNG_ACCESS_JPEG +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_set_jpeg_progressive (mng_handle hHandle, + mng_bool bJPEGprogressive) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_PROGRESSIVE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->bJPEGcompressprogr = bJPEGprogressive; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_PROGRESSIVE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ +#endif /* MNG_ACCESS_JPEG */ +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#ifdef MNG_ACCESS_JPEG +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_set_jpeg_optimized (mng_handle hHandle, + mng_bool bJPEGoptimized) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_OPTIMIZED, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->bJPEGcompressopt = bJPEGoptimized; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_OPTIMIZED, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ +#endif /* MNG_ACCESS_JPEG */ +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#ifdef MNG_ACCESS_JPEG +#ifdef MNG_SUPPORT_WRITE +mng_retcode MNG_DECL mng_set_jpeg_maxjdat (mng_handle hHandle, + mng_uint32 iMaxJDAT) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_MAXJDAT, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->iMaxJDAT = iMaxJDAT; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_JPEG_MAXJDAT, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_WRITE */ +#endif /* MNG_ACCESS_JPEG */ +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_retcode MNG_DECL mng_set_suspensionmode (mng_handle hHandle, + mng_bool bSuspensionmode) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SUSPENSIONMODE, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + + if (((mng_datap)hHandle)->bReading) /* we must NOT be reading !!! */ + MNG_ERROR ((mng_datap)hHandle, MNG_FUNCTIONINVALID); + + ((mng_datap)hHandle)->bSuspensionmode = bSuspensionmode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SUSPENSIONMODE, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_set_speed (mng_handle hHandle, + mng_speedtype iSpeed) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SPEED, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + ((mng_datap)hHandle)->iSpeed = iSpeed; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_SET_SPEED, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ +/* * * */ +/* * Property get functions * */ +/* * * */ +/* ************************************************************************** */ + +mng_ptr MNG_DECL mng_get_userdata (mng_handle hHandle) +{ /* no tracing in here to prevent recursive calls */ + MNG_VALIDHANDLEX (hHandle) + return ((mng_datap)hHandle)->pUserdata; +} + +/* ************************************************************************** */ + +mng_imgtype MNG_DECL mng_get_sigtype (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SIGTYPE, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return mng_it_unknown; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SIGTYPE, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->eSigtype; +} + +/* ************************************************************************** */ + +mng_imgtype MNG_DECL mng_get_imagetype (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGETYPE, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return mng_it_unknown; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGETYPE, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->eImagetype; +} + +/* ************************************************************************** */ + +mng_uint32 MNG_DECL mng_get_imagewidth (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGEWIDTH, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGEWIDTH, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iWidth; +} + +/* ************************************************************************** */ + +mng_uint32 MNG_DECL mng_get_imageheight (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGEWIDTH, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGEHEIGHT, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iHeight; +} + +/* ************************************************************************** */ + +mng_uint32 MNG_DECL mng_get_ticks (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TICKS, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TICKS, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iTicks; +} + +/* ************************************************************************** */ + +mng_uint32 MNG_DECL mng_get_framecount (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_FRAMECOUNT, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_FRAMECOUNT, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iFramecount; +} + +/* ************************************************************************** */ + +mng_uint32 MNG_DECL mng_get_layercount (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_LAYERCOUNT, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_LAYERCOUNT, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iLayercount; +} + +/* ************************************************************************** */ + +mng_uint32 MNG_DECL mng_get_playtime (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_PLAYTIME, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_PLAYTIME, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iPlaytime; +} + +/* ************************************************************************** */ + +mng_uint32 MNG_DECL mng_get_simplicity (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SIMPLICITY, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SIMPLICITY, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iSimplicity; +} + +/* ************************************************************************** */ + +mng_uint8 MNG_DECL mng_get_bitdepth (mng_handle hHandle) +{ + mng_uint8 iRslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_BITDEPTH, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + + if (((mng_datap)hHandle)->eImagetype == mng_it_png) + iRslt = ((mng_datap)hHandle)->iBitdepth; + else +#ifdef MNG_INCLUDE_JNG + if (((mng_datap)hHandle)->eImagetype == mng_it_jng) + iRslt = ((mng_datap)hHandle)->iJHDRimgbitdepth; + else +#endif + iRslt = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_BITDEPTH, MNG_LC_END); +#endif + + return iRslt; +} + +/* ************************************************************************** */ + +mng_uint8 MNG_DECL mng_get_colortype (mng_handle hHandle) +{ + mng_uint8 iRslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_COLORTYPE, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + + if (((mng_datap)hHandle)->eImagetype == mng_it_png) + iRslt = ((mng_datap)hHandle)->iColortype; + else +#ifdef MNG_INCLUDE_JNG + if (((mng_datap)hHandle)->eImagetype == mng_it_jng) + iRslt = ((mng_datap)hHandle)->iJHDRcolortype; + else +#endif + iRslt = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_COLORTYPE, MNG_LC_END); +#endif + + return iRslt; +} + +/* ************************************************************************** */ + +mng_uint8 MNG_DECL mng_get_compression (mng_handle hHandle) +{ + mng_uint8 iRslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_COMPRESSION, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + + if (((mng_datap)hHandle)->eImagetype == mng_it_png) + iRslt = ((mng_datap)hHandle)->iCompression; + else +#ifdef MNG_INCLUDE_JNG + if (((mng_datap)hHandle)->eImagetype == mng_it_jng) + iRslt = ((mng_datap)hHandle)->iJHDRimgcompression; + else +#endif + iRslt = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_COMPRESSION, MNG_LC_END); +#endif + + return iRslt; +} + +/* ************************************************************************** */ + +mng_uint8 MNG_DECL mng_get_filter (mng_handle hHandle) +{ + mng_uint8 iRslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_FILTER, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + + if (((mng_datap)hHandle)->eImagetype == mng_it_png) + iRslt = ((mng_datap)hHandle)->iFilter; + else + iRslt = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_FILTER, MNG_LC_END); +#endif + + return iRslt; +} + +/* ************************************************************************** */ + +mng_uint8 MNG_DECL mng_get_interlace (mng_handle hHandle) +{ + mng_uint8 iRslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_INTERLACE, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + + if (((mng_datap)hHandle)->eImagetype == mng_it_png) + iRslt = ((mng_datap)hHandle)->iInterlace; + else +#ifdef MNG_INCLUDE_JNG + if (((mng_datap)hHandle)->eImagetype == mng_it_jng) + iRslt = ((mng_datap)hHandle)->iJHDRimginterlace; + else +#endif + iRslt = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_INTERLACE, MNG_LC_END); +#endif + + return iRslt; +} + +/* ************************************************************************** */ + +mng_uint8 MNG_DECL mng_get_alphabitdepth (mng_handle hHandle) +{ + mng_uint8 iRslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHABITDEPTH, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_INCLUDE_JNG + if (((mng_datap)hHandle)->eImagetype == mng_it_jng) + iRslt = ((mng_datap)hHandle)->iJHDRalphabitdepth; + else +#endif + iRslt = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHABITDEPTH, MNG_LC_END); +#endif + + return iRslt; +} + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_uint8 MNG_DECL mng_get_refreshpass (mng_handle hHandle) +{ + mng_uint8 iRslt; + mng_datap pData; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_REFRESHPASS, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + + pData = (mng_datap)hHandle; + /* for PNG we know the exact pass */ + if ((pData->eImagetype == mng_it_png) && (pData->iPass >= 0)) + iRslt = pData->iPass; +#ifdef MNG_INCLUDE_JNG + else /* for JNG we'll fake it... */ + if ((pData->eImagetype == mng_it_jng) && + (pData->bJPEGhasheader) && (pData->bJPEGdecostarted) && + (pData->bJPEGprogressive)) + { + if (pData->pJPEGdinfo->input_scan_number <= 1) + iRslt = 0; /* first pass (I think...) */ + else + if (jpeg_input_complete (pData->pJPEGdinfo)) + iRslt = 7; /* input complete; aka final pass */ + else + iRslt = 3; /* anything between 0 and 7 will do */ + + } +#endif + else + iRslt = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_REFRESHPASS, MNG_LC_END); +#endif + + return iRslt; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ +mng_uint8 MNG_DECL mng_get_alphacompression (mng_handle hHandle) +{ + mng_uint8 iRslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHACOMPRESSION, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_INCLUDE_JNG + if (((mng_datap)hHandle)->eImagetype == mng_it_jng) + iRslt = ((mng_datap)hHandle)->iJHDRalphacompression; + else +#endif + iRslt = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHACOMPRESSION, MNG_LC_END); +#endif + + return iRslt; +} + +/* ************************************************************************** */ + +mng_uint8 MNG_DECL mng_get_alphafilter (mng_handle hHandle) +{ + mng_uint8 iRslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHAFILTER, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_INCLUDE_JNG + if (((mng_datap)hHandle)->eImagetype == mng_it_jng) + iRslt = ((mng_datap)hHandle)->iJHDRalphafilter; + else +#endif + iRslt = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHAFILTER, MNG_LC_END); +#endif + + return iRslt; +} + +/* ************************************************************************** */ + +mng_uint8 MNG_DECL mng_get_alphainterlace (mng_handle hHandle) +{ + mng_uint8 iRslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHAINTERLACE, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_INCLUDE_JNG + if (((mng_datap)hHandle)->eImagetype == mng_it_jng) + iRslt = ((mng_datap)hHandle)->iJHDRalphainterlace; + else +#endif + iRslt = 0; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHAINTERLACE, MNG_LC_END); +#endif + + return iRslt; +} + +/* ************************************************************************** */ + +mng_uint8 MNG_DECL mng_get_alphadepth (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHADEPTH, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ALPHADEPTH, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iAlphadepth; +} + +/* ************************************************************************** */ + +mng_uint32 MNG_DECL mng_get_canvasstyle (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CANVASSTYLE, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CANVASSTYLE, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iCanvasstyle; +} + +/* ************************************************************************** */ + +mng_uint32 MNG_DECL mng_get_bkgdstyle (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_BKGDSTYLE, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_BKGDSTYLE, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iBkgdstyle; +} + +/* ************************************************************************** */ + +mng_retcode MNG_DECL mng_get_bgcolor (mng_handle hHandle, + mng_uint16* iRed, + mng_uint16* iGreen, + mng_uint16* iBlue) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GET_BGCOLOR, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + *iRed = ((mng_datap)hHandle)->iBGred; + *iGreen = ((mng_datap)hHandle)->iBGgreen; + *iBlue = ((mng_datap)hHandle)->iBGblue; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (((mng_datap)hHandle), MNG_FN_GET_BGCOLOR, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_bool MNG_DECL mng_get_usebkgd (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_USEBKGD, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_USEBKGD, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bUseBKGD; +} + +/* ************************************************************************** */ + +mng_bool MNG_DECL mng_get_storechunks (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_STORECHUNKS, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_STORECHUNKS, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bStorechunks; +} + +/* ************************************************************************** */ + +mng_bool MNG_DECL mng_get_sectionbreaks (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_SECTIONBREAKS, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_SECTIONBREAKS, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bSectionbreaks; +} + +/* ************************************************************************** */ + +mng_bool MNG_DECL mng_get_cacheplayback (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_CACHEPLAYBACK, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_CACHEPLAYBACK, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bCacheplayback; +} + +/* ************************************************************************** */ + +mng_bool MNG_DECL mng_get_doprogressive (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_DOPROGRESSIVE, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_DOPROGRESSIVE, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bDoProgressive; +} + +/* ************************************************************************** */ + +mng_uint32 MNG_DECL mng_get_crcmode (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_CRCMODE, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_CRCMODE, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iCrcmode; +} + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_bool MNG_DECL mng_get_srgb (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_SRGB, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEB (((mng_datap)hHandle), MNG_FN_GET_SRGB, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bIssRGB; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) +mng_float MNG_DECL mng_get_viewgamma (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_VIEWGAMMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_VIEWGAMMA, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->dViewgamma; +} +#endif + +/* ************************************************************************** */ + +#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) +mng_float MNG_DECL mng_get_displaygamma (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DISPLAYGAMMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DISPLAYGAMMA, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->dDisplaygamma; +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DFLT_INFO +#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) +mng_float MNG_DECL mng_get_dfltimggamma (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DFLTIMGGAMMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DFLTIMGGAMMA, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->dDfltimggamma; +} +#endif +#endif + +/* ************************************************************************** */ + +#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) +mng_uint32 MNG_DECL mng_get_viewgammaint (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_VIEWGAMMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_VIEWGAMMA, MNG_LC_END); +#endif + + return (mng_uint32)(((mng_datap)hHandle)->dViewgamma * 100000); +} +#endif + +/* ************************************************************************** */ + +#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) +mng_uint32 MNG_DECL mng_get_displaygammaint (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DISPLAYGAMMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DISPLAYGAMMA, MNG_LC_END); +#endif + + return (mng_uint32)(((mng_datap)hHandle)->dDisplaygamma * 100000); +} +#endif + +/* ************************************************************************** */ + +#ifndef MNG_NO_DFLT_INFO +#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) +mng_uint32 MNG_DECL mng_get_dfltimggammaint (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DFLTIMGGAMMA, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_DFLTIMGGAMMA, MNG_LC_END); +#endif + + return (mng_uint32)(((mng_datap)hHandle)->dDfltimggamma * 100000); +} +#endif +#endif + +/* ************************************************************************** */ + +#ifndef MNG_SKIP_MAXCANVAS +mng_uint32 MNG_DECL mng_get_maxcanvaswidth (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_MAXCANVASWIDTH, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_MAXCANVASWIDTH, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iMaxwidth; +} + +/* ************************************************************************** */ + +mng_uint32 MNG_DECL mng_get_maxcanvasheight (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_MAXCANVASHEIGHT, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_MAXCANVASHEIGHT, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iMaxheight; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ZLIB +#ifdef MNG_ACCESS_ZLIB +mng_int32 MNG_DECL mng_get_zlib_level (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_LEVEL, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_LEVEL, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iZlevel; +} +#endif /* MNG_ACCESS_ZLIB */ +#endif /* MNG_INCLUDE_ZLIB */ + +/* ************************************************************************** */ +#ifdef MNG_INCLUDE_ZLIB +#ifdef MNG_ACCESS_ZLIB +mng_int32 MNG_DECL mng_get_zlib_method (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_METHOD, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_METHOD, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iZmethod; +} + +#endif /* MNG_ACCESS_ZLIB */ +#endif /* MNG_INCLUDE_ZLIB */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ZLIB +#ifdef MNG_ACCESS_ZLIB +mng_int32 MNG_DECL mng_get_zlib_windowbits (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_WINDOWBITS, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_WINDOWBITS, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iZwindowbits; +} +#endif /* MNG_ACCESS_ZLIB */ +#endif /* MNG_INCLUDE_ZLIB */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ZLIB +#ifdef MNG_ACCESS_ZLIB +mng_int32 MNG_DECL mng_get_zlib_memlevel (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_MEMLEVEL, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_MEMLEVEL, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iZmemlevel; +} +#endif /* MNG_ACCESS_ZLIB */ +#endif /* MNG_INCLUDE_ZLIB */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ZLIB +#ifdef MNG_ACCESS_ZLIB +mng_int32 MNG_DECL mng_get_zlib_strategy (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_STRATEGY, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_STRATEGY, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iZstrategy; +} +#endif /* MNG_ACCESS_ZLIB */ +#endif /* MNG_INCLUDE_ZLIB */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ZLIB +#ifdef MNG_ACCESS_ZLIB +mng_uint32 MNG_DECL mng_get_zlib_maxidat (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_MAXIDAT, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_ZLIB_MAXIDAT, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iMaxIDAT; +} +#endif /* MNG_ACCESS_ZLIB */ +#endif /* MNG_INCLUDE_ZLIB */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#ifdef MNG_ACCESS_JPEG +mngjpeg_dctmethod MNG_DECL mng_get_jpeg_dctmethod (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_DCTMETHOD, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return JDCT_ISLOW; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_DCTMETHOD, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->eJPEGdctmethod; +} +#endif /* MNG_ACCESS_JPEG */ +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#ifdef MNG_ACCESS_JPEG +mng_int32 MNG_DECL mng_get_jpeg_quality (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_QUALITY, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_QUALITY, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iJPEGquality; +} +#endif /* MNG_ACCESS_JPEG */ +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#ifdef MNG_ACCESS_JPEG +mng_int32 MNG_DECL mng_get_jpeg_smoothing (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_SMOOTHING, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_SMOOTHING, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iJPEGsmoothing; +} +#endif /* MNG_ACCESS_JPEG */ +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#ifdef MNG_ACCESS_JPEG +mng_bool MNG_DECL mng_get_jpeg_progressive (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_PROGRESSIVE, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_PROGRESSIVE, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bJPEGcompressprogr; +} +#endif /* MNG_ACCESS_JPEG */ +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#ifdef MNG_ACCESS_JPEG +mng_bool MNG_DECL mng_get_jpeg_optimized (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_OPTIMIZED, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_OPTIMIZED, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bJPEGcompressopt; +} +#endif /* MNG_ACCESS_JPEG */ +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_JNG +#ifdef MNG_ACCESS_JPEG +mng_uint32 MNG_DECL mng_get_jpeg_maxjdat (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_MAXJDAT, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_JPEG_MAXJDAT, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iMaxJDAT; +} +#endif /* MNG_ACCESS_JPEG */ +#endif /* MNG_INCLUDE_JNG */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_bool MNG_DECL mng_get_suspensionmode (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SUSPENSIONMODE, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SUSPENSIONMODE, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bSuspensionmode; +} +#endif /* MNG_SUPPORT_READ */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_speedtype MNG_DECL mng_get_speed (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SPEED, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return mng_st_normal; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_SPEED, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iSpeed; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +mng_uint32 MNG_DECL mng_get_imagelevel (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGELEVEL, MNG_LC_START); +#endif + + MNG_VALIDHANDLEX (hHandle) + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_IMAGELEVEL, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iImagelevel; +} + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_get_lastbackchunk (mng_handle hHandle, + mng_uint16* iRed, + mng_uint16* iGreen, + mng_uint16* iBlue, + mng_uint8* iMandatory) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_LASTBACKCHUNK, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + + if (((mng_datap)hHandle)->eImagetype != mng_it_mng) + MNG_ERROR (((mng_datap)hHandle), MNG_FUNCTIONINVALID); + + *iRed = ((mng_datap)hHandle)->iBACKred; + *iGreen = ((mng_datap)hHandle)->iBACKgreen; + *iBlue = ((mng_datap)hHandle)->iBACKblue; + *iMandatory = ((mng_datap)hHandle)->iBACKmandatory; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_LASTBACKCHUNK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode MNG_DECL mng_get_lastseekname (mng_handle hHandle, + mng_pchar zSegmentname) +{ + mng_datap pData; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_LASTSEEKNAME, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + + pData = (mng_datap)hHandle; + /* only allowed for MNG ! */ + if (pData->eImagetype != mng_it_mng) + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + if (pData->pLastseek) /* is there a last SEEK ? */ + { + mng_ani_seekp pSEEK = (mng_ani_seekp)pData->pLastseek; + + if (pSEEK->iSegmentnamesize) /* copy the name if there is one */ + MNG_COPY (zSegmentname, pSEEK->zSegmentname, pSEEK->iSegmentnamesize); + + *(((mng_uint8p)zSegmentname) + pSEEK->iSegmentnamesize) = 0; + } + else + { /* return an empty string */ + *((mng_uint8p)zSegmentname) = 0; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_LASTSEEKNAME, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_uint32 MNG_DECL mng_get_currframdelay (mng_handle hHandle) +{ + mng_datap pData; + mng_uint32 iRslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRFRAMDELAY, MNG_LC_START); +#endif + + MNG_VALIDHANDLE (hHandle) + + pData = (mng_datap)hHandle; + /* only allowed for MNG ! */ + if (pData->eImagetype != mng_it_mng) + MNG_ERROR (pData, MNG_FUNCTIONINVALID); + + iRslt = pData->iFramedelay; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRFRAMDELAY, MNG_LC_END); +#endif + + return iRslt; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_uint32 MNG_DECL mng_get_starttime (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_STARTTIME, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return mng_st_normal; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_STARTTIME, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iStarttime; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_uint32 MNG_DECL mng_get_runtime (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_RUNTIME, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return mng_st_normal; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_RUNTIME, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iRuntime; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_NO_CURRENT_INFO +mng_uint32 MNG_DECL mng_get_currentframe (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRENTFRAME, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return mng_st_normal; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRENTFRAME, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iFrameseq; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_NO_CURRENT_INFO +mng_uint32 MNG_DECL mng_get_currentlayer (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRENTLAYER, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return mng_st_normal; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRENTLAYER, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iLayerseq; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_NO_CURRENT_INFO +mng_uint32 MNG_DECL mng_get_currentplaytime (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRENTPLAYTIME, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return mng_st_normal; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_CURRENTPLAYTIME, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iFrametime; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_NO_CURRENT_INFO +mng_uint32 MNG_DECL mng_get_totalframes (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TOTALFRAMES, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return mng_st_normal; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TOTALFRAMES, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iTotalframes; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_NO_CURRENT_INFO +mng_uint32 MNG_DECL mng_get_totallayers (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TOTALLAYERS, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return mng_st_normal; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TOTALLAYERS, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iTotallayers; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +#ifndef MNG_NO_CURRENT_INFO +mng_uint32 MNG_DECL mng_get_totalplaytime (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TOTALPLAYTIME, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return mng_st_normal; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_GET_TOTALPLAYTIME, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->iTotalplaytime; +} +#endif +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +mng_bool MNG_DECL mng_status_error (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_ERROR, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_ERROR, MNG_LC_END); +#endif + + return (mng_bool)((mng_datap)hHandle)->iErrorcode; +} + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_bool MNG_DECL mng_status_reading (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_READING, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_READING, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bReading; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_READ +mng_bool MNG_DECL mng_status_suspendbreak (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_SUSPENDBREAK, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_SUSPENDBREAK, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bSuspended; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_WRITE +mng_bool MNG_DECL mng_status_creating (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_CREATING, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_CREATING, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bCreating; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_WRITE +mng_bool MNG_DECL mng_status_writing (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_WRITING, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_WRITING, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bWriting; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_bool MNG_DECL mng_status_displaying (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_DISPLAYING, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_DISPLAYING, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bDisplaying; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_bool MNG_DECL mng_status_running (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_RUNNING, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_RUNNING, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bRunning; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_bool MNG_DECL mng_status_timerbreak (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_TIMERBREAK, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_TIMERBREAK, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bTimerset; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DYNAMICMNG +mng_bool MNG_DECL mng_status_dynamic (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_DYNAMIC, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_DYNAMIC, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bDynamic; +} +#endif + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DYNAMICMNG +mng_bool MNG_DECL mng_status_runningevent (mng_handle hHandle) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_RUNNINGEVENT, MNG_LC_START); +#endif + + if ((hHandle == 0) || (((mng_datap)hHandle)->iMagic != MNG_MAGIC)) + return MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACEX (((mng_datap)hHandle), MNG_FN_STATUS_RUNNINGEVENT, MNG_LC_END); +#endif + + return ((mng_datap)hHandle)->bRunningevent; +} +#endif + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + diff --git a/Source/LibMNG/libmng_read.c b/Source/LibMNG/libmng_read.c index 3a6e49f..c922e19 100644 --- a/Source/LibMNG/libmng_read.c +++ b/Source/LibMNG/libmng_read.c @@ -1,1369 +1,1369 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_read.c copyright (c) 2000-2007 G.Juyn * */ -/* * version : 1.0.10 * */ -/* * * */ -/* * purpose : Read logic (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the high-level read logic * */ -/* * * */ -/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/11/2000 - G.Juyn * */ -/* * - added callback error-reporting support * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - changed trace to macro for callback error-reporting * */ -/* * * */ -/* * 0.5.2 - 05/19/2000 - G.Juyn * */ -/* * - cleaned up some code regarding mixed support * */ -/* * 0.5.2 - 05/20/2000 - G.Juyn * */ -/* * - added support for JNG * */ -/* * 0.5.2 - 05/31/2000 - G.Juyn * */ -/* * - fixed up punctuation (contribution by Tim Rowley) * */ -/* * * */ -/* * 0.5.3 - 06/16/2000 - G.Juyn * */ -/* * - changed progressive-display processing * */ -/* * * */ -/* * 0.9.1 - 07/08/2000 - G.Juyn * */ -/* * - changed read-processing for improved I/O-suspension * */ -/* * 0.9.1 - 07/14/2000 - G.Juyn * */ -/* * - changed EOF processing behavior * */ -/* * 0.9.1 - 07/14/2000 - G.Juyn * */ -/* * - changed default readbuffer size from 1024 to 4200 * */ -/* * * */ -/* * 0.9.2 - 07/27/2000 - G.Juyn * */ -/* * - B110320 - fixed GCC warning about mix-sized pointer math * */ -/* * 0.9.2 - 07/31/2000 - G.Juyn * */ -/* * - B110546 - fixed for improperly returning UNEXPECTEDEOF * */ -/* * 0.9.2 - 08/04/2000 - G.Juyn * */ -/* * - B111096 - fixed large-buffer read-suspension * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 0.9.3 - 08/26/2000 - G.Juyn * */ -/* * - added MAGN chunk * */ -/* * 0.9.3 - 10/11/2000 - G.Juyn * */ -/* * - removed test-MaGN * */ -/* * 0.9.3 - 10/16/2000 - G.Juyn * */ -/* * - added support for JDAA * */ -/* * * */ -/* * 0.9.5 - 01/23/2001 - G.Juyn * */ -/* * - fixed timing-problem with switching framing_modes * */ -/* * * */ -/* * 1.0.4 - 06/22/2002 - G.Juyn * */ -/* * - B495443 - incorrect suspend check in read_databuffer * */ -/* * * */ -/* * 1.0.5 - 07/04/2002 - G.Juyn * */ -/* * - added errorcode for extreme chunk-sizes * */ -/* * 1.0.5 - 07/08/2002 - G.Juyn * */ -/* * - B578572 - removed eMNGma hack (thanks Dimitri!) * */ -/* * 1.0.5 - 07/16/2002 - G.Juyn * */ -/* * - B581625 - large chunks fail with suspension reads * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * - added HLAPI function to copy chunks * */ -/* * 1.0.5 - 09/16/2002 - G.Juyn * */ -/* * - added event handling for dynamic MNG * */ -/* * * */ -/* * 1.0.6 - 05/25/2003 - G.R-P * */ -/* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */ -/* * 1.0.6 - 07/07/2003 - G.R-P * */ -/* * - added MNG_NO_DELTA_PNG reduction * */ -/* * - skip additional code when MNG_INCLUDE_JNG is not enabled * */ -/* * 1.0.6 - 07/29/2003 - G.R-P * */ -/* * - added conditionals around PAST chunk support * */ -/* * 1.0.6 - 08/17/2003 - G.R-P * */ -/* * - added conditionals around non-VLC chunk support * */ -/* * * */ -/* * 1.0.7 - 03/10/2004 - G.R-P * */ -/* * - added conditionals around openstream/closestream * */ -/* * * */ -/* * 1.0.8 - 04/08/2004 - G.Juyn * */ -/* * - added CRC existence & checking flags * */ -/* * 1.0.8 - 04/11/2004 - G.Juyn * */ -/* * - added data-push mechanisms for specialized decoders * */ -/* * 1.0.8 - 07/06/2004 - G.R-P * */ -/* * - defend against using undefined closestream function * */ -/* * 1.0.8 - 07/28/2004 - G.R-P * */ -/* * - added check for extreme chunk-lengths * */ -/* * * */ -/* * 1.0.9 - 09/16/2004 - G.Juyn * */ -/* * - fixed chunk pushing mechanism * */ -/* * 1.0.9 - 12/05/2004 - G.Juyn * */ -/* * - added conditional MNG_OPTIMIZE_CHUNKINITFREE * */ -/* * 1.0.9 - 12/06/2004 - G.Juyn * */ -/* * - added conditional MNG_OPTIMIZE_CHUNKASSIGN * */ -/* * - added conditional MNG_OPTIMIZE_CHUNKREADER * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * 1.0.9 - 12/31/2004 - G.R-P * */ -/* * - removed stray characters from #ifdef directive * */ -/* * * */ -/* * 1.0.10 - 04/08/2007 - G.Juyn * */ -/* * - added support for mPNG proposal * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_memory.h" -#include "libmng_objects.h" -#include "libmng_object_prc.h" -#include "libmng_chunks.h" -#ifdef MNG_OPTIMIZE_CHUNKREADER -#include "libmng_chunk_descr.h" -#endif -#include "libmng_chunk_prc.h" -#include "libmng_chunk_io.h" -#include "libmng_display.h" -#include "libmng_read.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_READ_PROCS - -/* ************************************************************************** */ - -mng_retcode mng_process_eof (mng_datap pData) -{ - if (!pData->bEOF) /* haven't closed the stream yet ? */ - { - pData->bEOF = MNG_TRUE; /* now we do! */ - -#ifndef MNG_NO_OPEN_CLOSE_STREAM - if (pData->fClosestream && !pData->fClosestream ((mng_handle)pData)) - { - MNG_ERROR (pData, MNG_APPIOERROR); - } -#endif - } - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_release_pushdata (mng_datap pData) -{ - mng_pushdatap pFirst = pData->pFirstpushdata; - mng_pushdatap pNext = pFirst->pNext; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RELEASE_PUSHDATA, MNG_LC_START); -#endif - - pData->pFirstpushdata = pNext; /* next becomes the first */ - - if (!pNext) /* no next? => no last! */ - pData->pLastpushdata = MNG_NULL; - /* buffer owned and release callback defined? */ - if ((pFirst->bOwned) && (pData->fReleasedata)) - pData->fReleasedata ((mng_handle)pData, pFirst->pData, pFirst->iLength); - else /* otherwise use internal free mechanism */ - MNG_FREEX (pData, pFirst->pData, pFirst->iLength); - /* and free it */ - MNG_FREEX (pData, pFirst, sizeof(mng_pushdata)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RELEASE_PUSHDATA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mng_release_pushchunk (mng_datap pData) -{ - mng_pushdatap pFirst = pData->pFirstpushchunk; - mng_pushdatap pNext = pFirst->pNext; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RELEASE_PUSHCHUNK, MNG_LC_START); -#endif - - pData->pFirstpushchunk = pNext; /* next becomes the first */ - - if (!pNext) /* no next? => no last! */ - pData->pLastpushchunk = MNG_NULL; - /* buffer owned and release callback defined? */ - if ((pFirst->bOwned) && (pData->fReleasedata)) - pData->fReleasedata ((mng_handle)pData, pFirst->pData, pFirst->iLength); - else /* otherwise use internal free mechanism */ - MNG_FREEX (pData, pFirst->pData, pFirst->iLength); - /* and free it */ - MNG_FREEX (pData, pFirst, sizeof(mng_pushdata)); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_RELEASE_PUSHCHUNK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode read_data (mng_datap pData, - mng_uint8p pBuf, - mng_uint32 iSize, - mng_uint32 * iRead) -{ - mng_retcode iRetcode; - mng_uint32 iTempsize = iSize; - mng_uint8p pTempbuf = pBuf; - mng_pushdatap pPush = pData->pFirstpushdata; - mng_uint32 iPushsize = 0; - *iRead = 0; /* nothing yet */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_DATA, MNG_LC_START); -#endif - - while (pPush) /* calculate size of pushed data */ - { - iPushsize += pPush->iRemaining; - pPush = pPush->pNext; - } - - if (iTempsize <= iPushsize) /* got enough push data? */ - { - while (iTempsize) - { - pPush = pData->pFirstpushdata; - /* enough data remaining in this buffer? */ - if (pPush->iRemaining <= iTempsize) - { /* no: then copy what we've got */ - MNG_COPY (pTempbuf, pPush->pDatanext, pPush->iRemaining); - /* move pointers & lengths */ - pTempbuf += pPush->iRemaining; - *iRead += pPush->iRemaining; - iTempsize -= pPush->iRemaining; - /* release the depleted buffer */ - iRetcode = mng_release_pushdata (pData); - if (iRetcode) - return iRetcode; - } - else - { /* copy the needed bytes */ - MNG_COPY (pTempbuf, pPush->pDatanext, iTempsize); - /* move pointers & lengths */ - pPush->iRemaining -= iTempsize; - pPush->pDatanext += iTempsize; - pTempbuf += iTempsize; - *iRead += iTempsize; - iTempsize = 0; /* all done!!! */ - } - } - } - else - { - mng_uint32 iTempread = 0; - /* get it from the app then */ - if (!pData->fReaddata (((mng_handle)pData), pTempbuf, iTempsize, &iTempread)) - MNG_ERROR (pData, MNG_APPIOERROR); - - *iRead += iTempread; - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_DATA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode read_databuffer (mng_datap pData, - mng_uint8p pBuf, - mng_uint8p * pBufnext, - mng_uint32 iSize, - mng_uint32 * iRead) -{ - mng_retcode iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_DATABUFFER, MNG_LC_START); -#endif - - if (pData->bSuspensionmode) - { - mng_uint8p pTemp; - mng_uint32 iTemp; - - *iRead = 0; /* let's be negative about the outcome */ - - if (!pData->pSuspendbuf) /* need to create a suspension buffer ? */ - { - pData->iSuspendbufsize = MNG_SUSPENDBUFFERSIZE; - /* so, create it */ - MNG_ALLOC (pData, pData->pSuspendbuf, pData->iSuspendbufsize); - - pData->iSuspendbufleft = 0; /* make sure to fill it first time */ - pData->pSuspendbufnext = pData->pSuspendbuf; - } - /* more than our buffer can hold ? */ - if (iSize > pData->iSuspendbufsize) - { - mng_uint32 iRemain; - - if (!*pBufnext) /* first time ? */ - { - if (pData->iSuspendbufleft) /* do we have some data left ? */ - { /* then copy it */ - MNG_COPY (pBuf, pData->pSuspendbufnext, pData->iSuspendbufleft); - /* fixup variables */ - *pBufnext = pBuf + pData->iSuspendbufleft; - pData->pSuspendbufnext = pData->pSuspendbuf; - pData->iSuspendbufleft = 0; - } - else - { - *pBufnext = pBuf; - } - } - /* calculate how much to get */ - iRemain = iSize - (mng_uint32)(*pBufnext - pBuf); - /* let's go get it */ - iRetcode = read_data (pData, *pBufnext, iRemain, &iTemp); - if (iRetcode) - return iRetcode; - /* first read after suspension return 0 means EOF */ - if ((pData->iSuspendpoint) && (iTemp == 0)) - { /* that makes it final */ - mng_retcode iRetcode = mng_process_eof (pData); - if (iRetcode) /* on error bail out */ - return iRetcode; - /* indicate the source is depleted */ - *iRead = iSize - iRemain + iTemp; - } - else - { - if (iTemp < iRemain) /* suspension required ? */ - { - *pBufnext = *pBufnext + iTemp; - pData->bSuspended = MNG_TRUE; - } - else - { - *iRead = iSize; /* got it all now ! */ - } - } - } - else - { /* need to read some more ? */ - while ((!pData->bSuspended) && (!pData->bEOF) && (iSize > pData->iSuspendbufleft)) - { /* not enough space left in buffer ? */ - if (pData->iSuspendbufsize - pData->iSuspendbufleft - - (mng_uint32)(pData->pSuspendbufnext - pData->pSuspendbuf) < - MNG_SUSPENDREQUESTSIZE) - { - if (pData->iSuspendbufleft) /* then lets shift (if there's anything left) */ - MNG_COPY (pData->pSuspendbuf, pData->pSuspendbufnext, pData->iSuspendbufleft); - /* adjust running pointer */ - pData->pSuspendbufnext = pData->pSuspendbuf; - } - /* still not enough room ? */ - if (pData->iSuspendbufsize - pData->iSuspendbufleft < MNG_SUSPENDREQUESTSIZE) - MNG_ERROR (pData, MNG_INTERNALERROR); - /* now read some more data */ - pTemp = pData->pSuspendbufnext + pData->iSuspendbufleft; - - iRetcode = read_data (pData, pTemp, MNG_SUSPENDREQUESTSIZE, &iTemp); - if (iRetcode) - return iRetcode; - /* adjust fill-counter */ - pData->iSuspendbufleft += iTemp; - /* first read after suspension returning 0 means EOF */ - if ((pData->iSuspendpoint) && (iTemp == 0)) - { /* that makes it final */ - mng_retcode iRetcode = mng_process_eof (pData); - if (iRetcode) /* on error bail out */ - return iRetcode; - - if (pData->iSuspendbufleft) /* return the leftover scraps */ - MNG_COPY (pBuf, pData->pSuspendbufnext, pData->iSuspendbufleft); - /* and indicate so */ - *iRead = pData->iSuspendbufleft; - pData->pSuspendbufnext = pData->pSuspendbuf; - pData->iSuspendbufleft = 0; - } - else - { /* suspension required ? */ - if ((iSize > pData->iSuspendbufleft) && (iTemp < MNG_SUSPENDREQUESTSIZE)) - pData->bSuspended = MNG_TRUE; - - } - - pData->iSuspendpoint = 0; /* reset it here in case we loop back */ - } - - if ((!pData->bSuspended) && (!pData->bEOF)) - { /* return the data ! */ - MNG_COPY (pBuf, pData->pSuspendbufnext, iSize); - - *iRead = iSize; /* returned it all */ - /* adjust suspension-buffer variables */ - pData->pSuspendbufnext += iSize; - pData->iSuspendbufleft -= iSize; - } - } - } - else - { - iRetcode = read_data (pData, (mng_ptr)pBuf, iSize, iRead); - if (iRetcode) - return iRetcode; - if (*iRead == 0) /* suspension required ? */ - pData->bSuspended = MNG_TRUE; - } - - pData->iSuspendpoint = 0; /* safely reset it here ! */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_DATABUFFER, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode process_raw_chunk (mng_datap pData, - mng_uint8p pBuf, - mng_uint32 iBuflen) -{ - -#ifndef MNG_OPTIMIZE_CHUNKREADER - /* the table-idea & binary search code was adapted from - libpng 1.1.0 (pngread.c) */ - /* NOTE1: the table must remain sorted by chunkname, otherwise the binary - search will break !!! (ps. watch upper-/lower-case chunknames !!) */ - /* NOTE2: the layout must remain equal to the header part of all the - chunk-structures (yes, that means even the pNext and pPrev fields; - it's wasting a bit of space, but hey, the code is a lot easier) */ - -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - mng_chunk_header mng_chunk_unknown = {MNG_UINT_HUH, mng_init_general, mng_free_unknown, - mng_read_unknown, mng_write_unknown, mng_assign_unknown, 0, 0, sizeof(mng_unknown_chunk)}; -#else - mng_chunk_header mng_chunk_unknown = {MNG_UINT_HUH, mng_init_unknown, mng_free_unknown, - mng_read_unknown, mng_write_unknown, mng_assign_unknown, 0, 0}; -#endif - -#ifdef MNG_OPTIMIZE_CHUNKINITFREE - - mng_chunk_header mng_chunk_table [] = - { -#ifndef MNG_SKIPCHUNK_BACK - {MNG_UINT_BACK, mng_init_general, mng_free_general, mng_read_back, mng_write_back, mng_assign_general, 0, 0, sizeof(mng_back)}, -#endif -#ifndef MNG_SKIPCHUNK_BASI - {MNG_UINT_BASI, mng_init_general, mng_free_general, mng_read_basi, mng_write_basi, mng_assign_general, 0, 0, sizeof(mng_basi)}, -#endif -#ifndef MNG_SKIPCHUNK_CLIP - {MNG_UINT_CLIP, mng_init_general, mng_free_general, mng_read_clip, mng_write_clip, mng_assign_general, 0, 0, sizeof(mng_clip)}, -#endif -#ifndef MNG_SKIPCHUNK_CLON - {MNG_UINT_CLON, mng_init_general, mng_free_general, mng_read_clon, mng_write_clon, mng_assign_general, 0, 0, sizeof(mng_clon)}, -#endif -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DBYK - {MNG_UINT_DBYK, mng_init_general, mng_free_dbyk, mng_read_dbyk, mng_write_dbyk, mng_assign_dbyk, 0, 0, sizeof(mng_dbyk)}, -#endif -#endif -#ifndef MNG_SKIPCHUNK_DEFI - {MNG_UINT_DEFI, mng_init_general, mng_free_general, mng_read_defi, mng_write_defi, mng_assign_general, 0, 0, sizeof(mng_defi)}, -#endif -#ifndef MNG_NO_DELTA_PNG - {MNG_UINT_DHDR, mng_init_general, mng_free_general, mng_read_dhdr, mng_write_dhdr, mng_assign_general, 0, 0, sizeof(mng_dhdr)}, -#endif -#ifndef MNG_SKIPCHUNK_DISC - {MNG_UINT_DISC, mng_init_general, mng_free_disc, mng_read_disc, mng_write_disc, mng_assign_disc, 0, 0, sizeof(mng_disc)}, -#endif -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DROP - {MNG_UINT_DROP, mng_init_general, mng_free_drop, mng_read_drop, mng_write_drop, mng_assign_drop, 0, 0, sizeof(mng_drop)}, -#endif -#endif -#ifndef MNG_SKIPCHUNK_LOOP - {MNG_UINT_ENDL, mng_init_general, mng_free_general, mng_read_endl, mng_write_endl, mng_assign_general, 0, 0, sizeof(mng_endl)}, -#endif -#ifndef MNG_SKIPCHUNK_FRAM - {MNG_UINT_FRAM, mng_init_general, mng_free_fram, mng_read_fram, mng_write_fram, mng_assign_fram, 0, 0, sizeof(mng_fram)}, -#endif - {MNG_UINT_IDAT, mng_init_general, mng_free_idat, mng_read_idat, mng_write_idat, mng_assign_idat, 0, 0, sizeof(mng_idat)}, /* 12-th element! */ - {MNG_UINT_IEND, mng_init_general, mng_free_general, mng_read_iend, mng_write_iend, mng_assign_general, 0, 0, sizeof(mng_iend)}, - {MNG_UINT_IHDR, mng_init_general, mng_free_general, mng_read_ihdr, mng_write_ihdr, mng_assign_general, 0, 0, sizeof(mng_ihdr)}, -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG - {MNG_UINT_IJNG, mng_init_general, mng_free_general, mng_read_ijng, mng_write_ijng, mng_assign_general, 0, 0, sizeof(mng_ijng)}, -#endif - {MNG_UINT_IPNG, mng_init_general, mng_free_general, mng_read_ipng, mng_write_ipng, mng_assign_general, 0, 0, sizeof(mng_ipng)}, -#endif -#ifdef MNG_INCLUDE_JNG - {MNG_UINT_JDAA, mng_init_general, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0, sizeof(mng_jdaa)}, - {MNG_UINT_JDAT, mng_init_general, mng_free_jdat, mng_read_jdat, mng_write_jdat, mng_assign_jdat, 0, 0, sizeof(mng_jdat)}, - {MNG_UINT_JHDR, mng_init_general, mng_free_general, mng_read_jhdr, mng_write_jhdr, mng_assign_general, 0, 0, sizeof(mng_jhdr)}, - {MNG_UINT_JSEP, mng_init_general, mng_free_general, mng_read_jsep, mng_write_jsep, mng_assign_general, 0, 0, sizeof(mng_jsep)}, - {MNG_UINT_JdAA, mng_init_general, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0, sizeof(mng_jdaa)}, -#endif -#ifndef MNG_SKIPCHUNK_LOOP - {MNG_UINT_LOOP, mng_init_general, mng_free_loop, mng_read_loop, mng_write_loop, mng_assign_loop, 0, 0, sizeof(mng_loop)}, -#endif -#ifndef MNG_SKIPCHUNK_MAGN - {MNG_UINT_MAGN, mng_init_general, mng_free_general, mng_read_magn, mng_write_magn, mng_assign_general, 0, 0, sizeof(mng_magn)}, -#endif - {MNG_UINT_MEND, mng_init_general, mng_free_general, mng_read_mend, mng_write_mend, mng_assign_general, 0, 0, sizeof(mng_mend)}, - {MNG_UINT_MHDR, mng_init_general, mng_free_general, mng_read_mhdr, mng_write_mhdr, mng_assign_general, 0, 0, sizeof(mng_mhdr)}, -#ifndef MNG_SKIPCHUNK_MOVE - {MNG_UINT_MOVE, mng_init_general, mng_free_general, mng_read_move, mng_write_move, mng_assign_general, 0, 0, sizeof(mng_move)}, -#endif -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR - {MNG_UINT_ORDR, mng_init_general, mng_free_ordr, mng_read_ordr, mng_write_ordr, mng_assign_ordr, 0, 0, sizeof(mng_ordr)}, -#endif -#endif -#ifndef MNG_SKIPCHUNK_PAST - {MNG_UINT_PAST, mng_init_general, mng_free_past, mng_read_past, mng_write_past, mng_assign_past, 0, 0, sizeof(mng_past)}, -#endif - {MNG_UINT_PLTE, mng_init_general, mng_free_general, mng_read_plte, mng_write_plte, mng_assign_general, 0, 0, sizeof(mng_plte)}, -#ifndef MNG_NO_DELTA_PNG - {MNG_UINT_PPLT, mng_init_general, mng_free_general, mng_read_pplt, mng_write_pplt, mng_assign_general, 0, 0, sizeof(mng_pplt)}, - {MNG_UINT_PROM, mng_init_general, mng_free_general, mng_read_prom, mng_write_prom, mng_assign_general, 0, 0, sizeof(mng_prom)}, -#endif -#ifndef MNG_SKIPCHUNK_SAVE - {MNG_UINT_SAVE, mng_init_general, mng_free_save, mng_read_save, mng_write_save, mng_assign_save, 0, 0, sizeof(mng_save)}, -#endif -#ifndef MNG_SKIPCHUNK_SEEK - {MNG_UINT_SEEK, mng_init_general, mng_free_seek, mng_read_seek, mng_write_seek, mng_assign_seek, 0, 0, sizeof(mng_seek)}, -#endif -#ifndef MNG_SKIPCHUNK_SHOW - {MNG_UINT_SHOW, mng_init_general, mng_free_general, mng_read_show, mng_write_show, mng_assign_general, 0, 0, sizeof(mng_show)}, -#endif -#ifndef MNG_SKIPCHUNK_TERM - {MNG_UINT_TERM, mng_init_general, mng_free_general, mng_read_term, mng_write_term, mng_assign_general, 0, 0, sizeof(mng_term)}, -#endif -#ifndef MNG_SKIPCHUNK_bKGD - {MNG_UINT_bKGD, mng_init_general, mng_free_general, mng_read_bkgd, mng_write_bkgd, mng_assign_general, 0, 0, sizeof(mng_bkgd)}, -#endif -#ifndef MNG_SKIPCHUNK_cHRM - {MNG_UINT_cHRM, mng_init_general, mng_free_general, mng_read_chrm, mng_write_chrm, mng_assign_general, 0, 0, sizeof(mng_chrm)}, -#endif -#ifndef MNG_SKIPCHUNK_eXPI - {MNG_UINT_eXPI, mng_init_general, mng_free_expi, mng_read_expi, mng_write_expi, mng_assign_expi, 0, 0, sizeof(mng_expi)}, -#endif -#ifndef MNG_SKIPCHUNK_evNT - {MNG_UINT_evNT, mng_init_general, mng_free_evnt, mng_read_evnt, mng_write_evnt, mng_assign_evnt, 0, 0, sizeof(mng_evnt)}, -#endif -#ifndef MNG_SKIPCHUNK_fPRI - {MNG_UINT_fPRI, mng_init_general, mng_free_general, mng_read_fpri, mng_write_fpri, mng_assign_general, 0, 0, sizeof(mng_fpri)}, -#endif -#ifndef MNG_SKIPCHUNK_gAMA - {MNG_UINT_gAMA, mng_init_general, mng_free_general, mng_read_gama, mng_write_gama, mng_assign_general, 0, 0, sizeof(mng_gama)}, -#endif -#ifndef MNG_SKIPCHUNK_hIST - {MNG_UINT_hIST, mng_init_general, mng_free_general, mng_read_hist, mng_write_hist, mng_assign_general, 0, 0, sizeof(mng_hist)}, -#endif -#ifndef MNG_SKIPCHUNK_iCCP - {MNG_UINT_iCCP, mng_init_general, mng_free_iccp, mng_read_iccp, mng_write_iccp, mng_assign_iccp, 0, 0, sizeof(mng_iccp)}, -#endif -#ifndef MNG_SKIPCHUNK_iTXt - {MNG_UINT_iTXt, mng_init_general, mng_free_itxt, mng_read_itxt, mng_write_itxt, mng_assign_itxt, 0, 0, sizeof(mng_itxt)}, -#endif -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - {MNG_UINT_mpNG, mng_init_general, mng_free_mpng, mng_read_mpng, mng_write_mpng, mng_assign_mpng, 0, 0, sizeof(mng_mpng)}, -#endif -#ifndef MNG_SKIPCHUNK_nEED - {MNG_UINT_nEED, mng_init_general, mng_free_need, mng_read_need, mng_write_need, mng_assign_need, 0, 0, sizeof(mng_need)}, -#endif -/* TODO: {MNG_UINT_oFFs, 0, 0, 0, 0, 0, 0}, */ -/* TODO: {MNG_UINT_pCAL, 0, 0, 0, 0, 0, 0}, */ -#ifndef MNG_SKIPCHUNK_pHYg - {MNG_UINT_pHYg, mng_init_general, mng_free_general, mng_read_phyg, mng_write_phyg, mng_assign_general, 0, 0, sizeof(mng_phyg)}, -#endif -#ifndef MNG_SKIPCHUNK_pHYs - {MNG_UINT_pHYs, mng_init_general, mng_free_general, mng_read_phys, mng_write_phys, mng_assign_general, 0, 0, sizeof(mng_phys)}, -#endif -#ifndef MNG_SKIPCHUNK_sBIT - {MNG_UINT_sBIT, mng_init_general, mng_free_general, mng_read_sbit, mng_write_sbit, mng_assign_general, 0, 0, sizeof(mng_sbit)}, -#endif -/* TODO: {MNG_UINT_sCAL, 0, 0, 0, 0, 0, 0}, */ -#ifndef MNG_SKIPCHUNK_sPLT - {MNG_UINT_sPLT, mng_init_general, mng_free_splt, mng_read_splt, mng_write_splt, mng_assign_splt, 0, 0, sizeof(mng_splt)}, -#endif - {MNG_UINT_sRGB, mng_init_general, mng_free_general, mng_read_srgb, mng_write_srgb, mng_assign_general, 0, 0, sizeof(mng_srgb)}, -#ifndef MNG_SKIPCHUNK_tEXt - {MNG_UINT_tEXt, mng_init_general, mng_free_text, mng_read_text, mng_write_text, mng_assign_text, 0, 0, sizeof(mng_text)}, -#endif -#ifndef MNG_SKIPCHUNK_tIME - {MNG_UINT_tIME, mng_init_general, mng_free_general, mng_read_time, mng_write_time, mng_assign_general, 0, 0, sizeof(mng_time)}, -#endif - {MNG_UINT_tRNS, mng_init_general, mng_free_general, mng_read_trns, mng_write_trns, mng_assign_general, 0, 0, sizeof(mng_trns)}, -#ifndef MNG_SKIPCHUNK_zTXt - {MNG_UINT_zTXt, mng_init_general, mng_free_ztxt, mng_read_ztxt, mng_write_ztxt, mng_assign_ztxt, 0, 0, sizeof(mng_ztxt)}, -#endif - }; - -#else /* MNG_OPTIMIZE_CHUNKINITFREE */ - - mng_chunk_header mng_chunk_table [] = - { -#ifndef MNG_SKIPCHUNK_BACK - {MNG_UINT_BACK, mng_init_back, mng_free_back, mng_read_back, mng_write_back, mng_assign_back, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_BASI - {MNG_UINT_BASI, mng_init_basi, mng_free_basi, mng_read_basi, mng_write_basi, mng_assign_basi, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_CLIP - {MNG_UINT_CLIP, mng_init_clip, mng_free_clip, mng_read_clip, mng_write_clip, mng_assign_clip, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_CLON - {MNG_UINT_CLON, mng_init_clon, mng_free_clon, mng_read_clon, mng_write_clon, mng_assign_clon, 0, 0}, -#endif -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DBYK - {MNG_UINT_DBYK, mng_init_dbyk, mng_free_dbyk, mng_read_dbyk, mng_write_dbyk, mng_assign_dbyk, 0, 0}, -#endif -#endif -#ifndef MNG_SKIPCHUNK_DEFI - {MNG_UINT_DEFI, mng_init_defi, mng_free_defi, mng_read_defi, mng_write_defi, mng_assign_defi, 0, 0}, -#endif -#ifndef MNG_NO_DELTA_PNG - {MNG_UINT_DHDR, mng_init_dhdr, mng_free_dhdr, mng_read_dhdr, mng_write_dhdr, mng_assign_dhdr, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_DISC - {MNG_UINT_DISC, mng_init_disc, mng_free_disc, mng_read_disc, mng_write_disc, mng_assign_disc, 0, 0}, -#endif -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_DROP - {MNG_UINT_DROP, mng_init_drop, mng_free_drop, mng_read_drop, mng_write_drop, mng_assign_drop, 0, 0}, -#endif -#endif -#ifndef MNG_SKIPCHUNK_LOOP - {MNG_UINT_ENDL, mng_init_endl, mng_free_endl, mng_read_endl, mng_write_endl, mng_assign_endl, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_FRAM - {MNG_UINT_FRAM, mng_init_fram, mng_free_fram, mng_read_fram, mng_write_fram, mng_assign_fram, 0, 0}, -#endif - {MNG_UINT_IDAT, mng_init_idat, mng_free_idat, mng_read_idat, mng_write_idat, mng_assign_idat, 0, 0}, /* 12-th element! */ - {MNG_UINT_IEND, mng_init_iend, mng_free_iend, mng_read_iend, mng_write_iend, mng_assign_iend, 0, 0}, - {MNG_UINT_IHDR, mng_init_ihdr, mng_free_ihdr, mng_read_ihdr, mng_write_ihdr, mng_assign_ihdr, 0, 0}, -#ifndef MNG_NO_DELTA_PNG -#ifdef MNG_INCLUDE_JNG - {MNG_UINT_IJNG, mng_init_ijng, mng_free_ijng, mng_read_ijng, mng_write_ijng, mng_assign_ijng, 0, 0}, -#endif - {MNG_UINT_IPNG, mng_init_ipng, mng_free_ipng, mng_read_ipng, mng_write_ipng, mng_assign_ipng, 0, 0}, -#endif -#ifdef MNG_INCLUDE_JNG - {MNG_UINT_JDAA, mng_init_jdaa, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0}, - {MNG_UINT_JDAT, mng_init_jdat, mng_free_jdat, mng_read_jdat, mng_write_jdat, mng_assign_jdat, 0, 0}, - {MNG_UINT_JHDR, mng_init_jhdr, mng_free_jhdr, mng_read_jhdr, mng_write_jhdr, mng_assign_jhdr, 0, 0}, - {MNG_UINT_JSEP, mng_init_jsep, mng_free_jsep, mng_read_jsep, mng_write_jsep, mng_assign_jsep, 0, 0}, - {MNG_UINT_JdAA, mng_init_jdaa, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_LOOP - {MNG_UINT_LOOP, mng_init_loop, mng_free_loop, mng_read_loop, mng_write_loop, mng_assign_loop, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_MAGN - {MNG_UINT_MAGN, mng_init_magn, mng_free_magn, mng_read_magn, mng_write_magn, mng_assign_magn, 0, 0}, -#endif - {MNG_UINT_MEND, mng_init_mend, mng_free_mend, mng_read_mend, mng_write_mend, mng_assign_mend, 0, 0}, - {MNG_UINT_MHDR, mng_init_mhdr, mng_free_mhdr, mng_read_mhdr, mng_write_mhdr, mng_assign_mhdr, 0, 0}, -#ifndef MNG_SKIPCHUNK_MOVE - {MNG_UINT_MOVE, mng_init_move, mng_free_move, mng_read_move, mng_write_move, mng_assign_move, 0, 0}, -#endif -#ifndef MNG_NO_DELTA_PNG -#ifndef MNG_SKIPCHUNK_ORDR - {MNG_UINT_ORDR, mng_init_ordr, mng_free_ordr, mng_read_ordr, mng_write_ordr, mng_assign_ordr, 0, 0}, -#endif -#endif -#ifndef MNG_SKIPCHUNK_PAST - {MNG_UINT_PAST, mng_init_past, mng_free_past, mng_read_past, mng_write_past, mng_assign_past, 0, 0}, -#endif - {MNG_UINT_PLTE, mng_init_plte, mng_free_plte, mng_read_plte, mng_write_plte, mng_assign_plte, 0, 0}, -#ifndef MNG_NO_DELTA_PNG - {MNG_UINT_PPLT, mng_init_pplt, mng_free_pplt, mng_read_pplt, mng_write_pplt, mng_assign_pplt, 0, 0}, - {MNG_UINT_PROM, mng_init_prom, mng_free_prom, mng_read_prom, mng_write_prom, mng_assign_prom, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_SAVE - {MNG_UINT_SAVE, mng_init_save, mng_free_save, mng_read_save, mng_write_save, mng_assign_save, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_SEEK - {MNG_UINT_SEEK, mng_init_seek, mng_free_seek, mng_read_seek, mng_write_seek, mng_assign_seek, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_SHOW - {MNG_UINT_SHOW, mng_init_show, mng_free_show, mng_read_show, mng_write_show, mng_assign_show, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_TERM - {MNG_UINT_TERM, mng_init_term, mng_free_term, mng_read_term, mng_write_term, mng_assign_term, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_bKGD - {MNG_UINT_bKGD, mng_init_bkgd, mng_free_bkgd, mng_read_bkgd, mng_write_bkgd, mng_assign_bkgd, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_cHRM - {MNG_UINT_cHRM, mng_init_chrm, mng_free_chrm, mng_read_chrm, mng_write_chrm, mng_assign_chrm, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_eXPI - {MNG_UINT_eXPI, mng_init_expi, mng_free_expi, mng_read_expi, mng_write_expi, mng_assign_expi, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_evNT - {MNG_UINT_evNT, mng_init_evnt, mng_free_evnt, mng_read_evnt, mng_write_evnt, mng_assign_evnt, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_fPRI - {MNG_UINT_fPRI, mng_init_fpri, mng_free_fpri, mng_read_fpri, mng_write_fpri, mng_assign_fpri, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_gAMA - {MNG_UINT_gAMA, mng_init_gama, mng_free_gama, mng_read_gama, mng_write_gama, mng_assign_gama, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_hIST - {MNG_UINT_hIST, mng_init_hist, mng_free_hist, mng_read_hist, mng_write_hist, mng_assign_hist, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_iCCP - {MNG_UINT_iCCP, mng_init_iccp, mng_free_iccp, mng_read_iccp, mng_write_iccp, mng_assign_iccp, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_iTXt - {MNG_UINT_iTXt, mng_init_itxt, mng_free_itxt, mng_read_itxt, mng_write_itxt, mng_assign_itxt, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_nEED - {MNG_UINT_nEED, mng_init_need, mng_free_need, mng_read_need, mng_write_need, mng_assign_need, 0, 0}, -#endif -/* TODO: {MNG_UINT_oFFs, 0, 0, 0, 0, 0, 0}, */ -/* TODO: {MNG_UINT_pCAL, 0, 0, 0, 0, 0, 0}, */ -#ifndef MNG_SKIPCHUNK_pHYg - {MNG_UINT_pHYg, mng_init_phyg, mng_free_phyg, mng_read_phyg, mng_write_phyg, mng_assign_phyg, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_pHYs - {MNG_UINT_pHYs, mng_init_phys, mng_free_phys, mng_read_phys, mng_write_phys, mng_assign_phys, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_sBIT - {MNG_UINT_sBIT, mng_init_sbit, mng_free_sbit, mng_read_sbit, mng_write_sbit, mng_assign_sbit, 0, 0}, -#endif -/* TODO: {MNG_UINT_sCAL, 0, 0, 0, 0, 0, 0}, */ -#ifndef MNG_SKIPCHUNK_sPLT - {MNG_UINT_sPLT, mng_init_splt, mng_free_splt, mng_read_splt, mng_write_splt, mng_assign_splt, 0, 0}, -#endif - {MNG_UINT_sRGB, mng_init_srgb, mng_free_srgb, mng_read_srgb, mng_write_srgb, mng_assign_srgb, 0, 0}, -#ifndef MNG_SKIPCHUNK_tEXt - {MNG_UINT_tEXt, mng_init_text, mng_free_text, mng_read_text, mng_write_text, mng_assign_text, 0, 0}, -#endif -#ifndef MNG_SKIPCHUNK_tIME - {MNG_UINT_tIME, mng_init_time, mng_free_time, mng_read_time, mng_write_time, mng_assign_time, 0, 0}, -#endif - {MNG_UINT_tRNS, mng_init_trns, mng_free_trns, mng_read_trns, mng_write_trns, mng_assign_trns, 0, 0}, -#ifndef MNG_SKIPCHUNK_zTXt - {MNG_UINT_zTXt, mng_init_ztxt, mng_free_ztxt, mng_read_ztxt, mng_write_ztxt, mng_assign_ztxt, 0, 0}, -#endif - }; - -#endif /* MNG_OPTIMIZE_CHUNKINITFREE */ - - /* binary search variables */ - mng_int32 iTop, iLower, iUpper, iMiddle; - mng_chunk_headerp pEntry; /* pointer to found entry */ -#else - mng_chunk_header sEntry; /* temp chunk-header */ -#endif /* MNG_OPTIMIZE_CHUNKREADER */ - - mng_chunkid iChunkname; /* the chunk's tag */ - mng_chunkp pChunk; /* chunk structure (if #define MNG_STORE_CHUNKS) */ - mng_retcode iRetcode; /* temporary error-code */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_RAW_CHUNK, MNG_LC_START); -#endif - /* reset timer indicator on read-cycle */ - if ((pData->bReading) && (!pData->bDisplaying)) - pData->bTimerset = MNG_FALSE; - /* get the chunkname */ - iChunkname = (mng_chunkid)(mng_get_uint32 (pBuf)); - - pBuf += sizeof (mng_chunkid); /* adjust the buffer */ - iBuflen -= sizeof (mng_chunkid); - pChunk = 0; - -#ifndef MNG_OPTIMIZE_CHUNKREADER - /* determine max index of table */ - iTop = (sizeof (mng_chunk_table) / sizeof (mng_chunk_table [0])) - 1; - - /* binary search; with 54 chunks, worst-case is 7 comparisons */ - iLower = 0; -#ifndef MNG_NO_DELTA_PNG - iMiddle = 11; /* start with the IDAT entry */ -#else - iMiddle = 8; -#endif - iUpper = iTop; - pEntry = 0; /* no goods yet! */ - - do /* the binary search itself */ - { - if (mng_chunk_table [iMiddle].iChunkname < iChunkname) - iLower = iMiddle + 1; - else if (mng_chunk_table [iMiddle].iChunkname > iChunkname) - iUpper = iMiddle - 1; - else - { - pEntry = &mng_chunk_table [iMiddle]; - break; - } - - iMiddle = (iLower + iUpper) >> 1; - } - while (iLower <= iUpper); - - if (!pEntry) /* unknown chunk ? */ - pEntry = &mng_chunk_unknown; /* make it so! */ - -#else /* MNG_OPTIMIZE_CHUNKREADER */ - - mng_get_chunkheader (iChunkname, &sEntry); - -#endif /* MNG_OPTIMIZE_CHUNKREADER */ - - pData->iChunkname = iChunkname; /* keep track of where we are */ - pData->iChunkseq++; - -#ifndef MNG_OPTIMIZE_CHUNKREADER - if (pEntry->fRead) /* read-callback available ? */ - { - iRetcode = pEntry->fRead (pData, pEntry, iBuflen, (mng_ptr)pBuf, &pChunk); - - if (!iRetcode) /* everything oke ? */ - { /* remember unknown chunk's id */ - if ((pChunk) && (pEntry->iChunkname == MNG_UINT_HUH)) - ((mng_chunk_headerp)pChunk)->iChunkname = iChunkname; - } - } -#else /* MNG_OPTIMIZE_CHUNKREADER */ - if (sEntry.fRead) /* read-callback available ? */ - { - iRetcode = sEntry.fRead (pData, &sEntry, iBuflen, (mng_ptr)pBuf, &pChunk); - -#ifndef MNG_OPTIMIZE_CHUNKREADER - if (!iRetcode) /* everything oke ? */ - { /* remember unknown chunk's id */ - if ((pChunk) && (sEntry.iChunkname == MNG_UINT_HUH)) - ((mng_chunk_headerp)pChunk)->iChunkname = iChunkname; - } -#endif - } -#endif /* MNG_OPTIMIZE_CHUNKREADER */ - else - iRetcode = MNG_NOERROR; - - if (pChunk) /* store this chunk ? */ - mng_add_chunk (pData, pChunk); /* do it */ - -#ifdef MNG_INCLUDE_JNG /* implicit EOF ? */ - if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && (!pData->bHasJHDR)) -#else - if ((!pData->bHasMHDR) && (!pData->bHasIHDR)) -#endif - iRetcode = mng_process_eof (pData);/* then do some EOF processing */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_PROCESS_RAW_CHUNK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode check_chunk_crc (mng_datap pData, - mng_uint8p pBuf, - mng_uint32 iBuflen) -{ - mng_uint32 iCrc; /* calculated CRC */ - mng_bool bDiscard = MNG_FALSE; - mng_retcode iRetcode = MNG_NOERROR; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_CHUNK_CRC, MNG_LC_START); -#endif - - if (pData->iCrcmode & MNG_CRC_INPUT) /* crc included ? */ - { - mng_bool bCritical = (mng_bool)((*pBuf & 0x20) == 0); - mng_uint32 iL = iBuflen - (mng_uint32)(sizeof (iCrc)); - - if (((bCritical ) && (pData->iCrcmode & MNG_CRC_CRITICAL )) || - ((!bCritical) && (pData->iCrcmode & MNG_CRC_ANCILLARY))) - { /* calculate the crc */ - iCrc = mng_crc (pData, pBuf, iL); - /* and check it */ - if (!(iCrc == mng_get_uint32 (pBuf + iL))) - { - mng_bool bWarning = MNG_FALSE; - mng_bool bError = MNG_FALSE; - - if (bCritical) - { - switch (pData->iCrcmode & MNG_CRC_CRITICAL) - { - case MNG_CRC_CRITICAL_WARNING : { bWarning = MNG_TRUE; break; } - case MNG_CRC_CRITICAL_ERROR : { bError = MNG_TRUE; break; } - } - } - else - { - switch (pData->iCrcmode & MNG_CRC_ANCILLARY) - { - case MNG_CRC_ANCILLARY_DISCARD : { bDiscard = MNG_TRUE; break; } - case MNG_CRC_ANCILLARY_WARNING : { bWarning = MNG_TRUE; break; } - case MNG_CRC_ANCILLARY_ERROR : { bError = MNG_TRUE; break; } - } - } - - if (bWarning) - MNG_WARNING (pData, MNG_INVALIDCRC); - if (bError) - MNG_ERROR (pData, MNG_INVALIDCRC); - } - } - - if (!bDiscard) /* still processing ? */ - iRetcode = process_raw_chunk (pData, pBuf, iL); - } - else - { /* no crc => straight onto processing */ - iRetcode = process_raw_chunk (pData, pBuf, iBuflen); - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_CHUNK_CRC, MNG_LC_END); -#endif - - return iRetcode; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode read_chunk (mng_datap pData) -{ - mng_uint32 iBufmax = pData->iReadbufsize; - mng_uint8p pBuf = pData->pReadbuf; - mng_uint32 iBuflen = 0; /* number of bytes requested */ - mng_uint32 iRead = 0; /* number of bytes read */ - mng_retcode iRetcode = MNG_NOERROR; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_CHUNK, MNG_LC_START); -#endif - -#ifdef MNG_SUPPORT_DISPLAY - if (pData->pCurraniobj) /* processing an animation object ? */ - { - do /* process it then */ - { - iRetcode = ((mng_object_headerp)pData->pCurraniobj)->fProcess (pData, pData->pCurraniobj); - /* refresh needed ? */ -/* if ((!iRetcode) && (!pData->bTimerset) && (pData->bNeedrefresh)) - iRetcode = display_progressive_refresh (pData, 1); */ - /* can we advance to next object ? */ - if ((!iRetcode) && (pData->pCurraniobj) && - (!pData->bTimerset) && (!pData->bSectionwait)) - { /* reset timer indicator on read-cycle */ - if ((pData->bReading) && (!pData->bDisplaying)) - pData->bTimerset = MNG_FALSE; - - pData->pCurraniobj = ((mng_object_headerp)pData->pCurraniobj)->pNext; - /* TERM processing to be done ? */ - if ((!pData->pCurraniobj) && (pData->bHasTERM) && (!pData->bHasMHDR)) - iRetcode = mng_process_display_mend (pData); - } - } /* until error or a break or no more objects */ - while ((!iRetcode) && (pData->pCurraniobj) && - (!pData->bTimerset) && (!pData->bSectionwait) && (!pData->bFreezing)); - } - else - { - if (pData->iBreakpoint) /* do we need to finish something first ? */ - { - switch (pData->iBreakpoint) /* return to broken display routine */ - { -#ifndef MNG_SKIPCHUNK_FRAM - case 1 : { iRetcode = mng_process_display_fram2 (pData); break; } -#endif - case 2 : { iRetcode = mng_process_display_ihdr (pData); break; } -#ifndef MNG_SKIPCHUNK_SHOW - case 3 : ; /* same as 4 !!! */ - case 4 : { iRetcode = mng_process_display_show (pData); break; } -#endif -#ifndef MNG_SKIPCHUNK_CLON - case 5 : { iRetcode = mng_process_display_clon2 (pData); break; } -#endif -#ifdef MNG_INCLUDE_JNG - case 7 : { iRetcode = mng_process_display_jhdr (pData); break; } -#endif - case 6 : ; /* same as 8 !!! */ - case 8 : { iRetcode = mng_process_display_iend (pData); break; } -#ifndef MNG_SKIPCHUNK_MAGN - case 9 : { iRetcode = mng_process_display_magn2 (pData); break; } -#endif - case 10 : { iRetcode = mng_process_display_mend2 (pData); break; } -#ifndef MNG_SKIPCHUNK_PAST - case 11 : { iRetcode = mng_process_display_past2 (pData); break; } -#endif - } - } - } - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#endif /* MNG_SUPPORT_DISPLAY */ - /* can we continue processing now, or do we */ - /* need to wait for the timer to finish (again) ? */ -#ifdef MNG_SUPPORT_DISPLAY - if ((!pData->bTimerset) && (!pData->bSectionwait) && (!pData->bEOF)) -#else - if (!pData->bEOF) -#endif - { -#ifdef MNG_SUPPORT_DISPLAY - /* freezing in progress ? */ - if ((pData->bFreezing) && (pData->iSuspendpoint == 0)) - pData->bRunning = MNG_FALSE; /* then this is the right moment to do it */ -#endif - - if (pData->iSuspendpoint <= 2) - { - iBuflen = sizeof (mng_uint32); /* read length */ - iRetcode = read_databuffer (pData, pBuf, &pData->pReadbufnext, iBuflen, &iRead); - - if (iRetcode) /* bail on errors */ - return iRetcode; - - if (pData->bSuspended) /* suspended ? */ - pData->iSuspendpoint = 2; - else /* save the length */ - { - pData->iChunklen = mng_get_uint32 (pBuf); - if (pData->iChunklen > 0x7ffffff) - return MNG_INVALIDLENGTH; - } - - } - - if (!pData->bSuspended) /* still going ? */ - { /* previously suspended or not eof ? */ - if ((pData->iSuspendpoint > 2) || (iRead == iBuflen)) - { /* determine length chunkname + data (+ crc) */ - if (pData->iCrcmode & MNG_CRC_INPUT) - iBuflen = pData->iChunklen + (mng_uint32)(sizeof (mng_chunkid) + sizeof (mng_uint32)); - else - iBuflen = pData->iChunklen + (mng_uint32)(sizeof (mng_chunkid)); - - /* do we have enough data in the current push buffer ? */ - if ((pData->pFirstpushdata) && (iBuflen <= pData->pFirstpushdata->iRemaining)) - { - mng_pushdatap pPush = pData->pFirstpushdata; - pBuf = pPush->pDatanext; - pPush->pDatanext += iBuflen; - pPush->iRemaining -= iBuflen; - pData->iSuspendpoint = 0; /* safely reset this here ! */ - - iRetcode = check_chunk_crc (pData, pBuf, iBuflen); - if (iRetcode) - return iRetcode; - - if (!pPush->iRemaining) /* buffer depleted? then release it */ - iRetcode = mng_release_pushdata (pData); - } - else - { - if (iBuflen < iBufmax) /* does it fit in default buffer ? */ - { /* note that we don't use the full size - so there's always a zero-byte at the - very end !!! */ - iRetcode = read_databuffer (pData, pBuf, &pData->pReadbufnext, iBuflen, &iRead); - if (iRetcode) /* bail on errors */ - return iRetcode; - - if (pData->bSuspended) /* suspended ? */ - pData->iSuspendpoint = 3; - else - { - if (iRead != iBuflen) /* did we get all the data ? */ - MNG_ERROR (pData, MNG_UNEXPECTEDEOF); - iRetcode = check_chunk_crc (pData, pBuf, iBuflen); - } - } - else - { - if (iBuflen > 16777216) /* is the length incredible? */ - MNG_ERROR (pData, MNG_IMPROBABLELENGTH); - - if (!pData->iSuspendpoint) /* create additional large buffer ? */ - { /* again reserve space for the last zero-byte */ - pData->iLargebufsize = iBuflen + 1; - pData->pLargebufnext = MNG_NULL; - MNG_ALLOC (pData, pData->pLargebuf, pData->iLargebufsize); - } - - iRetcode = read_databuffer (pData, pData->pLargebuf, &pData->pLargebufnext, iBuflen, &iRead); - if (iRetcode) - return iRetcode; - - if (pData->bSuspended) /* suspended ? */ - pData->iSuspendpoint = 4; - else - { - if (iRead != iBuflen) /* did we get all the data ? */ - MNG_ERROR (pData, MNG_UNEXPECTEDEOF); - iRetcode = check_chunk_crc (pData, pData->pLargebuf, iBuflen); - /* cleanup additional large buffer */ - MNG_FREE (pData, pData->pLargebuf, pData->iLargebufsize); - } - } - } - - if (iRetcode) /* on error bail out */ - return iRetcode; - - } - else - { /* that's final */ - iRetcode = mng_process_eof (pData); - - if (iRetcode) /* on error bail out */ - return iRetcode; - - if ((iRead != 0) || /* did we get an unexpected eof ? */ -#ifdef MNG_INCLUDE_JNG - (pData->bHasIHDR || pData->bHasMHDR || pData->bHasJHDR)) -#else - (pData->bHasIHDR || pData->bHasMHDR)) -#endif - MNG_ERROR (pData, MNG_UNEXPECTEDEOF); - } - } - } - -#ifdef MNG_SUPPORT_DISPLAY /* refresh needed ? */ - if ((!pData->bTimerset) && (!pData->bSuspended) && (pData->bNeedrefresh)) - { - iRetcode = mng_display_progressive_refresh (pData, 1); - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_CHUNK, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -MNG_LOCAL mng_retcode process_pushedchunk (mng_datap pData) -{ - mng_pushdatap pPush; - mng_retcode iRetcode = MNG_NOERROR; - -#ifdef MNG_SUPPORT_DISPLAY - if (pData->pCurraniobj) /* processing an animation object ? */ - { - do /* process it then */ - { - iRetcode = ((mng_object_headerp)pData->pCurraniobj)->fProcess (pData, pData->pCurraniobj); - /* refresh needed ? */ -/* if ((!iRetcode) && (!pData->bTimerset) && (pData->bNeedrefresh)) - iRetcode = display_progressive_refresh (pData, 1); */ - /* can we advance to next object ? */ - if ((!iRetcode) && (pData->pCurraniobj) && - (!pData->bTimerset) && (!pData->bSectionwait)) - { /* reset timer indicator on read-cycle */ - if ((pData->bReading) && (!pData->bDisplaying)) - pData->bTimerset = MNG_FALSE; - - pData->pCurraniobj = ((mng_object_headerp)pData->pCurraniobj)->pNext; - /* TERM processing to be done ? */ - if ((!pData->pCurraniobj) && (pData->bHasTERM) && (!pData->bHasMHDR)) - iRetcode = mng_process_display_mend (pData); - } - } /* until error or a break or no more objects */ - while ((!iRetcode) && (pData->pCurraniobj) && - (!pData->bTimerset) && (!pData->bSectionwait) && (!pData->bFreezing)); - } - else - { - if (pData->iBreakpoint) /* do we need to finish something first ? */ - { - switch (pData->iBreakpoint) /* return to broken display routine */ - { -#ifndef MNG_SKIPCHUNK_FRAM - case 1 : { iRetcode = mng_process_display_fram2 (pData); break; } -#endif - case 2 : { iRetcode = mng_process_display_ihdr (pData); break; } -#ifndef MNG_SKIPCHUNK_SHOW - case 3 : ; /* same as 4 !!! */ - case 4 : { iRetcode = mng_process_display_show (pData); break; } -#endif -#ifndef MNG_SKIPCHUNK_CLON - case 5 : { iRetcode = mng_process_display_clon2 (pData); break; } -#endif -#ifdef MNG_INCLUDE_JNG - case 7 : { iRetcode = mng_process_display_jhdr (pData); break; } -#endif - case 6 : ; /* same as 8 !!! */ - case 8 : { iRetcode = mng_process_display_iend (pData); break; } -#ifndef MNG_SKIPCHUNK_MAGN - case 9 : { iRetcode = mng_process_display_magn2 (pData); break; } -#endif - case 10 : { iRetcode = mng_process_display_mend2 (pData); break; } -#ifndef MNG_SKIPCHUNK_PAST - case 11 : { iRetcode = mng_process_display_past2 (pData); break; } -#endif - } - } - } - - if (iRetcode) /* on error bail out */ - return iRetcode; - -#endif /* MNG_SUPPORT_DISPLAY */ - /* can we continue processing now, or do we */ - /* need to wait for the timer to finish (again) ? */ -#ifdef MNG_SUPPORT_DISPLAY - if ((!pData->bTimerset) && (!pData->bSectionwait) && (!pData->bEOF)) -#else - if (!pData->bEOF) -#endif - { - pData->iSuspendpoint = 0; /* safely reset it here ! */ - pPush = pData->pFirstpushchunk; - - iRetcode = process_raw_chunk (pData, pPush->pData, pPush->iLength); - if (iRetcode) - return iRetcode; - -#ifdef MNG_SUPPORT_DISPLAY /* refresh needed ? */ - if ((!pData->bTimerset) && (!pData->bSuspended) && (pData->bNeedrefresh)) - { - iRetcode = mng_display_progressive_refresh (pData, 1); - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#endif - } - - return mng_release_pushchunk (pData); -} - -/* ************************************************************************** */ - -mng_retcode mng_read_graphic (mng_datap pData) -{ - mng_uint32 iBuflen; /* number of bytes requested */ - mng_uint32 iRead; /* number of bytes read */ - mng_retcode iRetcode; /* temporary error-code */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_GRAPHIC, MNG_LC_START); -#endif - - if (!pData->pReadbuf) /* buffer allocated ? */ - { - pData->iReadbufsize = 4200; /* allocate a default read buffer */ - MNG_ALLOC (pData, pData->pReadbuf, pData->iReadbufsize); - } - /* haven't processed the signature ? */ - if ((!pData->bHavesig) || (pData->iSuspendpoint == 1)) - { - iBuflen = 2 * sizeof (mng_uint32); /* read signature */ - - iRetcode = read_databuffer (pData, pData->pReadbuf, &pData->pReadbufnext, iBuflen, &iRead); - - if (iRetcode) - return iRetcode; - - if (pData->bSuspended) /* input suspension ? */ - pData->iSuspendpoint = 1; - else - { - if (iRead != iBuflen) /* full signature received ? */ - MNG_ERROR (pData, MNG_UNEXPECTEDEOF); - /* is it a valid signature ? */ - if (mng_get_uint32 (pData->pReadbuf) == PNG_SIG) - pData->eSigtype = mng_it_png; - else -#ifdef MNG_INCLUDE_JNG - if (mng_get_uint32 (pData->pReadbuf) == JNG_SIG) - pData->eSigtype = mng_it_jng; - else -#endif - if (mng_get_uint32 (pData->pReadbuf) == MNG_SIG) - pData->eSigtype = mng_it_mng; - else - MNG_ERROR (pData, MNG_INVALIDSIG); - /* all of it ? */ - if (mng_get_uint32 (pData->pReadbuf+4) != POST_SIG) - MNG_ERROR (pData, MNG_INVALIDSIG); - - pData->bHavesig = MNG_TRUE; - } - } - - if (!pData->bSuspended) /* still going ? */ - { - do - { /* reset timer during mng_read() ? */ - if ((pData->bReading) && (!pData->bDisplaying)) - pData->bTimerset = MNG_FALSE; - - if (pData->pFirstpushchunk) /* chunks pushed ? */ - iRetcode = process_pushedchunk (pData); /* process the pushed chunk */ - else - iRetcode = read_chunk (pData); /* read & process a chunk */ - - if (iRetcode) /* on error bail out */ - return iRetcode; - } -#ifdef MNG_SUPPORT_DISPLAY /* until EOF or a break-request */ - while (((!pData->bEOF) || (pData->pCurraniobj)) && - (!pData->bSuspended) && (!pData->bSectionwait) && - ((!pData->bTimerset) || ((pData->bReading) && (!pData->bDisplaying)))); -#else - while ((!pData->bEOF) && (!pData->bSuspended)); -#endif - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_READ_GRAPHIC, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_READ_PROCS */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_read.c copyright (c) 2000-2007 G.Juyn * */ +/* * version : 1.0.10 * */ +/* * * */ +/* * purpose : Read logic (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the high-level read logic * */ +/* * * */ +/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/11/2000 - G.Juyn * */ +/* * - added callback error-reporting support * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - changed trace to macro for callback error-reporting * */ +/* * * */ +/* * 0.5.2 - 05/19/2000 - G.Juyn * */ +/* * - cleaned up some code regarding mixed support * */ +/* * 0.5.2 - 05/20/2000 - G.Juyn * */ +/* * - added support for JNG * */ +/* * 0.5.2 - 05/31/2000 - G.Juyn * */ +/* * - fixed up punctuation (contribution by Tim Rowley) * */ +/* * * */ +/* * 0.5.3 - 06/16/2000 - G.Juyn * */ +/* * - changed progressive-display processing * */ +/* * * */ +/* * 0.9.1 - 07/08/2000 - G.Juyn * */ +/* * - changed read-processing for improved I/O-suspension * */ +/* * 0.9.1 - 07/14/2000 - G.Juyn * */ +/* * - changed EOF processing behavior * */ +/* * 0.9.1 - 07/14/2000 - G.Juyn * */ +/* * - changed default readbuffer size from 1024 to 4200 * */ +/* * * */ +/* * 0.9.2 - 07/27/2000 - G.Juyn * */ +/* * - B110320 - fixed GCC warning about mix-sized pointer math * */ +/* * 0.9.2 - 07/31/2000 - G.Juyn * */ +/* * - B110546 - fixed for improperly returning UNEXPECTEDEOF * */ +/* * 0.9.2 - 08/04/2000 - G.Juyn * */ +/* * - B111096 - fixed large-buffer read-suspension * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 0.9.3 - 08/26/2000 - G.Juyn * */ +/* * - added MAGN chunk * */ +/* * 0.9.3 - 10/11/2000 - G.Juyn * */ +/* * - removed test-MaGN * */ +/* * 0.9.3 - 10/16/2000 - G.Juyn * */ +/* * - added support for JDAA * */ +/* * * */ +/* * 0.9.5 - 01/23/2001 - G.Juyn * */ +/* * - fixed timing-problem with switching framing_modes * */ +/* * * */ +/* * 1.0.4 - 06/22/2002 - G.Juyn * */ +/* * - B495443 - incorrect suspend check in read_databuffer * */ +/* * * */ +/* * 1.0.5 - 07/04/2002 - G.Juyn * */ +/* * - added errorcode for extreme chunk-sizes * */ +/* * 1.0.5 - 07/08/2002 - G.Juyn * */ +/* * - B578572 - removed eMNGma hack (thanks Dimitri!) * */ +/* * 1.0.5 - 07/16/2002 - G.Juyn * */ +/* * - B581625 - large chunks fail with suspension reads * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * - added HLAPI function to copy chunks * */ +/* * 1.0.5 - 09/16/2002 - G.Juyn * */ +/* * - added event handling for dynamic MNG * */ +/* * * */ +/* * 1.0.6 - 05/25/2003 - G.R-P * */ +/* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */ +/* * 1.0.6 - 07/07/2003 - G.R-P * */ +/* * - added MNG_NO_DELTA_PNG reduction * */ +/* * - skip additional code when MNG_INCLUDE_JNG is not enabled * */ +/* * 1.0.6 - 07/29/2003 - G.R-P * */ +/* * - added conditionals around PAST chunk support * */ +/* * 1.0.6 - 08/17/2003 - G.R-P * */ +/* * - added conditionals around non-VLC chunk support * */ +/* * * */ +/* * 1.0.7 - 03/10/2004 - G.R-P * */ +/* * - added conditionals around openstream/closestream * */ +/* * * */ +/* * 1.0.8 - 04/08/2004 - G.Juyn * */ +/* * - added CRC existence & checking flags * */ +/* * 1.0.8 - 04/11/2004 - G.Juyn * */ +/* * - added data-push mechanisms for specialized decoders * */ +/* * 1.0.8 - 07/06/2004 - G.R-P * */ +/* * - defend against using undefined closestream function * */ +/* * 1.0.8 - 07/28/2004 - G.R-P * */ +/* * - added check for extreme chunk-lengths * */ +/* * * */ +/* * 1.0.9 - 09/16/2004 - G.Juyn * */ +/* * - fixed chunk pushing mechanism * */ +/* * 1.0.9 - 12/05/2004 - G.Juyn * */ +/* * - added conditional MNG_OPTIMIZE_CHUNKINITFREE * */ +/* * 1.0.9 - 12/06/2004 - G.Juyn * */ +/* * - added conditional MNG_OPTIMIZE_CHUNKASSIGN * */ +/* * - added conditional MNG_OPTIMIZE_CHUNKREADER * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * 1.0.9 - 12/31/2004 - G.R-P * */ +/* * - removed stray characters from #ifdef directive * */ +/* * * */ +/* * 1.0.10 - 04/08/2007 - G.Juyn * */ +/* * - added support for mPNG proposal * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_memory.h" +#include "libmng_objects.h" +#include "libmng_object_prc.h" +#include "libmng_chunks.h" +#ifdef MNG_OPTIMIZE_CHUNKREADER +#include "libmng_chunk_descr.h" +#endif +#include "libmng_chunk_prc.h" +#include "libmng_chunk_io.h" +#include "libmng_display.h" +#include "libmng_read.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_READ_PROCS + +/* ************************************************************************** */ + +mng_retcode mng_process_eof (mng_datap pData) +{ + if (!pData->bEOF) /* haven't closed the stream yet ? */ + { + pData->bEOF = MNG_TRUE; /* now we do! */ + +#ifndef MNG_NO_OPEN_CLOSE_STREAM + if (pData->fClosestream && !pData->fClosestream ((mng_handle)pData)) + { + MNG_ERROR (pData, MNG_APPIOERROR); + } +#endif + } + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_release_pushdata (mng_datap pData) +{ + mng_pushdatap pFirst = pData->pFirstpushdata; + mng_pushdatap pNext = pFirst->pNext; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RELEASE_PUSHDATA, MNG_LC_START); +#endif + + pData->pFirstpushdata = pNext; /* next becomes the first */ + + if (!pNext) /* no next? => no last! */ + pData->pLastpushdata = MNG_NULL; + /* buffer owned and release callback defined? */ + if ((pFirst->bOwned) && (pData->fReleasedata)) + pData->fReleasedata ((mng_handle)pData, pFirst->pData, pFirst->iLength); + else /* otherwise use internal free mechanism */ + MNG_FREEX (pData, pFirst->pData, pFirst->iLength); + /* and free it */ + MNG_FREEX (pData, pFirst, sizeof(mng_pushdata)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RELEASE_PUSHDATA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mng_release_pushchunk (mng_datap pData) +{ + mng_pushdatap pFirst = pData->pFirstpushchunk; + mng_pushdatap pNext = pFirst->pNext; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RELEASE_PUSHCHUNK, MNG_LC_START); +#endif + + pData->pFirstpushchunk = pNext; /* next becomes the first */ + + if (!pNext) /* no next? => no last! */ + pData->pLastpushchunk = MNG_NULL; + /* buffer owned and release callback defined? */ + if ((pFirst->bOwned) && (pData->fReleasedata)) + pData->fReleasedata ((mng_handle)pData, pFirst->pData, pFirst->iLength); + else /* otherwise use internal free mechanism */ + MNG_FREEX (pData, pFirst->pData, pFirst->iLength); + /* and free it */ + MNG_FREEX (pData, pFirst, sizeof(mng_pushdata)); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_RELEASE_PUSHCHUNK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode read_data (mng_datap pData, + mng_uint8p pBuf, + mng_uint32 iSize, + mng_uint32 * iRead) +{ + mng_retcode iRetcode; + mng_uint32 iTempsize = iSize; + mng_uint8p pTempbuf = pBuf; + mng_pushdatap pPush = pData->pFirstpushdata; + mng_uint32 iPushsize = 0; + *iRead = 0; /* nothing yet */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_DATA, MNG_LC_START); +#endif + + while (pPush) /* calculate size of pushed data */ + { + iPushsize += pPush->iRemaining; + pPush = pPush->pNext; + } + + if (iTempsize <= iPushsize) /* got enough push data? */ + { + while (iTempsize) + { + pPush = pData->pFirstpushdata; + /* enough data remaining in this buffer? */ + if (pPush->iRemaining <= iTempsize) + { /* no: then copy what we've got */ + MNG_COPY (pTempbuf, pPush->pDatanext, pPush->iRemaining); + /* move pointers & lengths */ + pTempbuf += pPush->iRemaining; + *iRead += pPush->iRemaining; + iTempsize -= pPush->iRemaining; + /* release the depleted buffer */ + iRetcode = mng_release_pushdata (pData); + if (iRetcode) + return iRetcode; + } + else + { /* copy the needed bytes */ + MNG_COPY (pTempbuf, pPush->pDatanext, iTempsize); + /* move pointers & lengths */ + pPush->iRemaining -= iTempsize; + pPush->pDatanext += iTempsize; + pTempbuf += iTempsize; + *iRead += iTempsize; + iTempsize = 0; /* all done!!! */ + } + } + } + else + { + mng_uint32 iTempread = 0; + /* get it from the app then */ + if (!pData->fReaddata (((mng_handle)pData), pTempbuf, iTempsize, &iTempread)) + MNG_ERROR (pData, MNG_APPIOERROR); + + *iRead += iTempread; + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_DATA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode read_databuffer (mng_datap pData, + mng_uint8p pBuf, + mng_uint8p * pBufnext, + mng_uint32 iSize, + mng_uint32 * iRead) +{ + mng_retcode iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_DATABUFFER, MNG_LC_START); +#endif + + if (pData->bSuspensionmode) + { + mng_uint8p pTemp; + mng_uint32 iTemp; + + *iRead = 0; /* let's be negative about the outcome */ + + if (!pData->pSuspendbuf) /* need to create a suspension buffer ? */ + { + pData->iSuspendbufsize = MNG_SUSPENDBUFFERSIZE; + /* so, create it */ + MNG_ALLOC (pData, pData->pSuspendbuf, pData->iSuspendbufsize); + + pData->iSuspendbufleft = 0; /* make sure to fill it first time */ + pData->pSuspendbufnext = pData->pSuspendbuf; + } + /* more than our buffer can hold ? */ + if (iSize > pData->iSuspendbufsize) + { + mng_uint32 iRemain; + + if (!*pBufnext) /* first time ? */ + { + if (pData->iSuspendbufleft) /* do we have some data left ? */ + { /* then copy it */ + MNG_COPY (pBuf, pData->pSuspendbufnext, pData->iSuspendbufleft); + /* fixup variables */ + *pBufnext = pBuf + pData->iSuspendbufleft; + pData->pSuspendbufnext = pData->pSuspendbuf; + pData->iSuspendbufleft = 0; + } + else + { + *pBufnext = pBuf; + } + } + /* calculate how much to get */ + iRemain = iSize - (mng_uint32)(*pBufnext - pBuf); + /* let's go get it */ + iRetcode = read_data (pData, *pBufnext, iRemain, &iTemp); + if (iRetcode) + return iRetcode; + /* first read after suspension return 0 means EOF */ + if ((pData->iSuspendpoint) && (iTemp == 0)) + { /* that makes it final */ + mng_retcode iRetcode = mng_process_eof (pData); + if (iRetcode) /* on error bail out */ + return iRetcode; + /* indicate the source is depleted */ + *iRead = iSize - iRemain + iTemp; + } + else + { + if (iTemp < iRemain) /* suspension required ? */ + { + *pBufnext = *pBufnext + iTemp; + pData->bSuspended = MNG_TRUE; + } + else + { + *iRead = iSize; /* got it all now ! */ + } + } + } + else + { /* need to read some more ? */ + while ((!pData->bSuspended) && (!pData->bEOF) && (iSize > pData->iSuspendbufleft)) + { /* not enough space left in buffer ? */ + if (pData->iSuspendbufsize - pData->iSuspendbufleft - + (mng_uint32)(pData->pSuspendbufnext - pData->pSuspendbuf) < + MNG_SUSPENDREQUESTSIZE) + { + if (pData->iSuspendbufleft) /* then lets shift (if there's anything left) */ + MNG_COPY (pData->pSuspendbuf, pData->pSuspendbufnext, pData->iSuspendbufleft); + /* adjust running pointer */ + pData->pSuspendbufnext = pData->pSuspendbuf; + } + /* still not enough room ? */ + if (pData->iSuspendbufsize - pData->iSuspendbufleft < MNG_SUSPENDREQUESTSIZE) + MNG_ERROR (pData, MNG_INTERNALERROR); + /* now read some more data */ + pTemp = pData->pSuspendbufnext + pData->iSuspendbufleft; + + iRetcode = read_data (pData, pTemp, MNG_SUSPENDREQUESTSIZE, &iTemp); + if (iRetcode) + return iRetcode; + /* adjust fill-counter */ + pData->iSuspendbufleft += iTemp; + /* first read after suspension returning 0 means EOF */ + if ((pData->iSuspendpoint) && (iTemp == 0)) + { /* that makes it final */ + mng_retcode iRetcode = mng_process_eof (pData); + if (iRetcode) /* on error bail out */ + return iRetcode; + + if (pData->iSuspendbufleft) /* return the leftover scraps */ + MNG_COPY (pBuf, pData->pSuspendbufnext, pData->iSuspendbufleft); + /* and indicate so */ + *iRead = pData->iSuspendbufleft; + pData->pSuspendbufnext = pData->pSuspendbuf; + pData->iSuspendbufleft = 0; + } + else + { /* suspension required ? */ + if ((iSize > pData->iSuspendbufleft) && (iTemp < MNG_SUSPENDREQUESTSIZE)) + pData->bSuspended = MNG_TRUE; + + } + + pData->iSuspendpoint = 0; /* reset it here in case we loop back */ + } + + if ((!pData->bSuspended) && (!pData->bEOF)) + { /* return the data ! */ + MNG_COPY (pBuf, pData->pSuspendbufnext, iSize); + + *iRead = iSize; /* returned it all */ + /* adjust suspension-buffer variables */ + pData->pSuspendbufnext += iSize; + pData->iSuspendbufleft -= iSize; + } + } + } + else + { + iRetcode = read_data (pData, (mng_ptr)pBuf, iSize, iRead); + if (iRetcode) + return iRetcode; + if (*iRead == 0) /* suspension required ? */ + pData->bSuspended = MNG_TRUE; + } + + pData->iSuspendpoint = 0; /* safely reset it here ! */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_DATABUFFER, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode process_raw_chunk (mng_datap pData, + mng_uint8p pBuf, + mng_uint32 iBuflen) +{ + +#ifndef MNG_OPTIMIZE_CHUNKREADER + /* the table-idea & binary search code was adapted from + libpng 1.1.0 (pngread.c) */ + /* NOTE1: the table must remain sorted by chunkname, otherwise the binary + search will break !!! (ps. watch upper-/lower-case chunknames !!) */ + /* NOTE2: the layout must remain equal to the header part of all the + chunk-structures (yes, that means even the pNext and pPrev fields; + it's wasting a bit of space, but hey, the code is a lot easier) */ + +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + mng_chunk_header mng_chunk_unknown = {MNG_UINT_HUH, mng_init_general, mng_free_unknown, + mng_read_unknown, mng_write_unknown, mng_assign_unknown, 0, 0, sizeof(mng_unknown_chunk)}; +#else + mng_chunk_header mng_chunk_unknown = {MNG_UINT_HUH, mng_init_unknown, mng_free_unknown, + mng_read_unknown, mng_write_unknown, mng_assign_unknown, 0, 0}; +#endif + +#ifdef MNG_OPTIMIZE_CHUNKINITFREE + + mng_chunk_header mng_chunk_table [] = + { +#ifndef MNG_SKIPCHUNK_BACK + {MNG_UINT_BACK, mng_init_general, mng_free_general, mng_read_back, mng_write_back, mng_assign_general, 0, 0, sizeof(mng_back)}, +#endif +#ifndef MNG_SKIPCHUNK_BASI + {MNG_UINT_BASI, mng_init_general, mng_free_general, mng_read_basi, mng_write_basi, mng_assign_general, 0, 0, sizeof(mng_basi)}, +#endif +#ifndef MNG_SKIPCHUNK_CLIP + {MNG_UINT_CLIP, mng_init_general, mng_free_general, mng_read_clip, mng_write_clip, mng_assign_general, 0, 0, sizeof(mng_clip)}, +#endif +#ifndef MNG_SKIPCHUNK_CLON + {MNG_UINT_CLON, mng_init_general, mng_free_general, mng_read_clon, mng_write_clon, mng_assign_general, 0, 0, sizeof(mng_clon)}, +#endif +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DBYK + {MNG_UINT_DBYK, mng_init_general, mng_free_dbyk, mng_read_dbyk, mng_write_dbyk, mng_assign_dbyk, 0, 0, sizeof(mng_dbyk)}, +#endif +#endif +#ifndef MNG_SKIPCHUNK_DEFI + {MNG_UINT_DEFI, mng_init_general, mng_free_general, mng_read_defi, mng_write_defi, mng_assign_general, 0, 0, sizeof(mng_defi)}, +#endif +#ifndef MNG_NO_DELTA_PNG + {MNG_UINT_DHDR, mng_init_general, mng_free_general, mng_read_dhdr, mng_write_dhdr, mng_assign_general, 0, 0, sizeof(mng_dhdr)}, +#endif +#ifndef MNG_SKIPCHUNK_DISC + {MNG_UINT_DISC, mng_init_general, mng_free_disc, mng_read_disc, mng_write_disc, mng_assign_disc, 0, 0, sizeof(mng_disc)}, +#endif +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DROP + {MNG_UINT_DROP, mng_init_general, mng_free_drop, mng_read_drop, mng_write_drop, mng_assign_drop, 0, 0, sizeof(mng_drop)}, +#endif +#endif +#ifndef MNG_SKIPCHUNK_LOOP + {MNG_UINT_ENDL, mng_init_general, mng_free_general, mng_read_endl, mng_write_endl, mng_assign_general, 0, 0, sizeof(mng_endl)}, +#endif +#ifndef MNG_SKIPCHUNK_FRAM + {MNG_UINT_FRAM, mng_init_general, mng_free_fram, mng_read_fram, mng_write_fram, mng_assign_fram, 0, 0, sizeof(mng_fram)}, +#endif + {MNG_UINT_IDAT, mng_init_general, mng_free_idat, mng_read_idat, mng_write_idat, mng_assign_idat, 0, 0, sizeof(mng_idat)}, /* 12-th element! */ + {MNG_UINT_IEND, mng_init_general, mng_free_general, mng_read_iend, mng_write_iend, mng_assign_general, 0, 0, sizeof(mng_iend)}, + {MNG_UINT_IHDR, mng_init_general, mng_free_general, mng_read_ihdr, mng_write_ihdr, mng_assign_general, 0, 0, sizeof(mng_ihdr)}, +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG + {MNG_UINT_IJNG, mng_init_general, mng_free_general, mng_read_ijng, mng_write_ijng, mng_assign_general, 0, 0, sizeof(mng_ijng)}, +#endif + {MNG_UINT_IPNG, mng_init_general, mng_free_general, mng_read_ipng, mng_write_ipng, mng_assign_general, 0, 0, sizeof(mng_ipng)}, +#endif +#ifdef MNG_INCLUDE_JNG + {MNG_UINT_JDAA, mng_init_general, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0, sizeof(mng_jdaa)}, + {MNG_UINT_JDAT, mng_init_general, mng_free_jdat, mng_read_jdat, mng_write_jdat, mng_assign_jdat, 0, 0, sizeof(mng_jdat)}, + {MNG_UINT_JHDR, mng_init_general, mng_free_general, mng_read_jhdr, mng_write_jhdr, mng_assign_general, 0, 0, sizeof(mng_jhdr)}, + {MNG_UINT_JSEP, mng_init_general, mng_free_general, mng_read_jsep, mng_write_jsep, mng_assign_general, 0, 0, sizeof(mng_jsep)}, + {MNG_UINT_JdAA, mng_init_general, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0, sizeof(mng_jdaa)}, +#endif +#ifndef MNG_SKIPCHUNK_LOOP + {MNG_UINT_LOOP, mng_init_general, mng_free_loop, mng_read_loop, mng_write_loop, mng_assign_loop, 0, 0, sizeof(mng_loop)}, +#endif +#ifndef MNG_SKIPCHUNK_MAGN + {MNG_UINT_MAGN, mng_init_general, mng_free_general, mng_read_magn, mng_write_magn, mng_assign_general, 0, 0, sizeof(mng_magn)}, +#endif + {MNG_UINT_MEND, mng_init_general, mng_free_general, mng_read_mend, mng_write_mend, mng_assign_general, 0, 0, sizeof(mng_mend)}, + {MNG_UINT_MHDR, mng_init_general, mng_free_general, mng_read_mhdr, mng_write_mhdr, mng_assign_general, 0, 0, sizeof(mng_mhdr)}, +#ifndef MNG_SKIPCHUNK_MOVE + {MNG_UINT_MOVE, mng_init_general, mng_free_general, mng_read_move, mng_write_move, mng_assign_general, 0, 0, sizeof(mng_move)}, +#endif +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR + {MNG_UINT_ORDR, mng_init_general, mng_free_ordr, mng_read_ordr, mng_write_ordr, mng_assign_ordr, 0, 0, sizeof(mng_ordr)}, +#endif +#endif +#ifndef MNG_SKIPCHUNK_PAST + {MNG_UINT_PAST, mng_init_general, mng_free_past, mng_read_past, mng_write_past, mng_assign_past, 0, 0, sizeof(mng_past)}, +#endif + {MNG_UINT_PLTE, mng_init_general, mng_free_general, mng_read_plte, mng_write_plte, mng_assign_general, 0, 0, sizeof(mng_plte)}, +#ifndef MNG_NO_DELTA_PNG + {MNG_UINT_PPLT, mng_init_general, mng_free_general, mng_read_pplt, mng_write_pplt, mng_assign_general, 0, 0, sizeof(mng_pplt)}, + {MNG_UINT_PROM, mng_init_general, mng_free_general, mng_read_prom, mng_write_prom, mng_assign_general, 0, 0, sizeof(mng_prom)}, +#endif +#ifndef MNG_SKIPCHUNK_SAVE + {MNG_UINT_SAVE, mng_init_general, mng_free_save, mng_read_save, mng_write_save, mng_assign_save, 0, 0, sizeof(mng_save)}, +#endif +#ifndef MNG_SKIPCHUNK_SEEK + {MNG_UINT_SEEK, mng_init_general, mng_free_seek, mng_read_seek, mng_write_seek, mng_assign_seek, 0, 0, sizeof(mng_seek)}, +#endif +#ifndef MNG_SKIPCHUNK_SHOW + {MNG_UINT_SHOW, mng_init_general, mng_free_general, mng_read_show, mng_write_show, mng_assign_general, 0, 0, sizeof(mng_show)}, +#endif +#ifndef MNG_SKIPCHUNK_TERM + {MNG_UINT_TERM, mng_init_general, mng_free_general, mng_read_term, mng_write_term, mng_assign_general, 0, 0, sizeof(mng_term)}, +#endif +#ifndef MNG_SKIPCHUNK_bKGD + {MNG_UINT_bKGD, mng_init_general, mng_free_general, mng_read_bkgd, mng_write_bkgd, mng_assign_general, 0, 0, sizeof(mng_bkgd)}, +#endif +#ifndef MNG_SKIPCHUNK_cHRM + {MNG_UINT_cHRM, mng_init_general, mng_free_general, mng_read_chrm, mng_write_chrm, mng_assign_general, 0, 0, sizeof(mng_chrm)}, +#endif +#ifndef MNG_SKIPCHUNK_eXPI + {MNG_UINT_eXPI, mng_init_general, mng_free_expi, mng_read_expi, mng_write_expi, mng_assign_expi, 0, 0, sizeof(mng_expi)}, +#endif +#ifndef MNG_SKIPCHUNK_evNT + {MNG_UINT_evNT, mng_init_general, mng_free_evnt, mng_read_evnt, mng_write_evnt, mng_assign_evnt, 0, 0, sizeof(mng_evnt)}, +#endif +#ifndef MNG_SKIPCHUNK_fPRI + {MNG_UINT_fPRI, mng_init_general, mng_free_general, mng_read_fpri, mng_write_fpri, mng_assign_general, 0, 0, sizeof(mng_fpri)}, +#endif +#ifndef MNG_SKIPCHUNK_gAMA + {MNG_UINT_gAMA, mng_init_general, mng_free_general, mng_read_gama, mng_write_gama, mng_assign_general, 0, 0, sizeof(mng_gama)}, +#endif +#ifndef MNG_SKIPCHUNK_hIST + {MNG_UINT_hIST, mng_init_general, mng_free_general, mng_read_hist, mng_write_hist, mng_assign_general, 0, 0, sizeof(mng_hist)}, +#endif +#ifndef MNG_SKIPCHUNK_iCCP + {MNG_UINT_iCCP, mng_init_general, mng_free_iccp, mng_read_iccp, mng_write_iccp, mng_assign_iccp, 0, 0, sizeof(mng_iccp)}, +#endif +#ifndef MNG_SKIPCHUNK_iTXt + {MNG_UINT_iTXt, mng_init_general, mng_free_itxt, mng_read_itxt, mng_write_itxt, mng_assign_itxt, 0, 0, sizeof(mng_itxt)}, +#endif +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + {MNG_UINT_mpNG, mng_init_general, mng_free_mpng, mng_read_mpng, mng_write_mpng, mng_assign_mpng, 0, 0, sizeof(mng_mpng)}, +#endif +#ifndef MNG_SKIPCHUNK_nEED + {MNG_UINT_nEED, mng_init_general, mng_free_need, mng_read_need, mng_write_need, mng_assign_need, 0, 0, sizeof(mng_need)}, +#endif +/* TODO: {MNG_UINT_oFFs, 0, 0, 0, 0, 0, 0}, */ +/* TODO: {MNG_UINT_pCAL, 0, 0, 0, 0, 0, 0}, */ +#ifndef MNG_SKIPCHUNK_pHYg + {MNG_UINT_pHYg, mng_init_general, mng_free_general, mng_read_phyg, mng_write_phyg, mng_assign_general, 0, 0, sizeof(mng_phyg)}, +#endif +#ifndef MNG_SKIPCHUNK_pHYs + {MNG_UINT_pHYs, mng_init_general, mng_free_general, mng_read_phys, mng_write_phys, mng_assign_general, 0, 0, sizeof(mng_phys)}, +#endif +#ifndef MNG_SKIPCHUNK_sBIT + {MNG_UINT_sBIT, mng_init_general, mng_free_general, mng_read_sbit, mng_write_sbit, mng_assign_general, 0, 0, sizeof(mng_sbit)}, +#endif +/* TODO: {MNG_UINT_sCAL, 0, 0, 0, 0, 0, 0}, */ +#ifndef MNG_SKIPCHUNK_sPLT + {MNG_UINT_sPLT, mng_init_general, mng_free_splt, mng_read_splt, mng_write_splt, mng_assign_splt, 0, 0, sizeof(mng_splt)}, +#endif + {MNG_UINT_sRGB, mng_init_general, mng_free_general, mng_read_srgb, mng_write_srgb, mng_assign_general, 0, 0, sizeof(mng_srgb)}, +#ifndef MNG_SKIPCHUNK_tEXt + {MNG_UINT_tEXt, mng_init_general, mng_free_text, mng_read_text, mng_write_text, mng_assign_text, 0, 0, sizeof(mng_text)}, +#endif +#ifndef MNG_SKIPCHUNK_tIME + {MNG_UINT_tIME, mng_init_general, mng_free_general, mng_read_time, mng_write_time, mng_assign_general, 0, 0, sizeof(mng_time)}, +#endif + {MNG_UINT_tRNS, mng_init_general, mng_free_general, mng_read_trns, mng_write_trns, mng_assign_general, 0, 0, sizeof(mng_trns)}, +#ifndef MNG_SKIPCHUNK_zTXt + {MNG_UINT_zTXt, mng_init_general, mng_free_ztxt, mng_read_ztxt, mng_write_ztxt, mng_assign_ztxt, 0, 0, sizeof(mng_ztxt)}, +#endif + }; + +#else /* MNG_OPTIMIZE_CHUNKINITFREE */ + + mng_chunk_header mng_chunk_table [] = + { +#ifndef MNG_SKIPCHUNK_BACK + {MNG_UINT_BACK, mng_init_back, mng_free_back, mng_read_back, mng_write_back, mng_assign_back, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_BASI + {MNG_UINT_BASI, mng_init_basi, mng_free_basi, mng_read_basi, mng_write_basi, mng_assign_basi, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_CLIP + {MNG_UINT_CLIP, mng_init_clip, mng_free_clip, mng_read_clip, mng_write_clip, mng_assign_clip, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_CLON + {MNG_UINT_CLON, mng_init_clon, mng_free_clon, mng_read_clon, mng_write_clon, mng_assign_clon, 0, 0}, +#endif +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DBYK + {MNG_UINT_DBYK, mng_init_dbyk, mng_free_dbyk, mng_read_dbyk, mng_write_dbyk, mng_assign_dbyk, 0, 0}, +#endif +#endif +#ifndef MNG_SKIPCHUNK_DEFI + {MNG_UINT_DEFI, mng_init_defi, mng_free_defi, mng_read_defi, mng_write_defi, mng_assign_defi, 0, 0}, +#endif +#ifndef MNG_NO_DELTA_PNG + {MNG_UINT_DHDR, mng_init_dhdr, mng_free_dhdr, mng_read_dhdr, mng_write_dhdr, mng_assign_dhdr, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_DISC + {MNG_UINT_DISC, mng_init_disc, mng_free_disc, mng_read_disc, mng_write_disc, mng_assign_disc, 0, 0}, +#endif +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_DROP + {MNG_UINT_DROP, mng_init_drop, mng_free_drop, mng_read_drop, mng_write_drop, mng_assign_drop, 0, 0}, +#endif +#endif +#ifndef MNG_SKIPCHUNK_LOOP + {MNG_UINT_ENDL, mng_init_endl, mng_free_endl, mng_read_endl, mng_write_endl, mng_assign_endl, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_FRAM + {MNG_UINT_FRAM, mng_init_fram, mng_free_fram, mng_read_fram, mng_write_fram, mng_assign_fram, 0, 0}, +#endif + {MNG_UINT_IDAT, mng_init_idat, mng_free_idat, mng_read_idat, mng_write_idat, mng_assign_idat, 0, 0}, /* 12-th element! */ + {MNG_UINT_IEND, mng_init_iend, mng_free_iend, mng_read_iend, mng_write_iend, mng_assign_iend, 0, 0}, + {MNG_UINT_IHDR, mng_init_ihdr, mng_free_ihdr, mng_read_ihdr, mng_write_ihdr, mng_assign_ihdr, 0, 0}, +#ifndef MNG_NO_DELTA_PNG +#ifdef MNG_INCLUDE_JNG + {MNG_UINT_IJNG, mng_init_ijng, mng_free_ijng, mng_read_ijng, mng_write_ijng, mng_assign_ijng, 0, 0}, +#endif + {MNG_UINT_IPNG, mng_init_ipng, mng_free_ipng, mng_read_ipng, mng_write_ipng, mng_assign_ipng, 0, 0}, +#endif +#ifdef MNG_INCLUDE_JNG + {MNG_UINT_JDAA, mng_init_jdaa, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0}, + {MNG_UINT_JDAT, mng_init_jdat, mng_free_jdat, mng_read_jdat, mng_write_jdat, mng_assign_jdat, 0, 0}, + {MNG_UINT_JHDR, mng_init_jhdr, mng_free_jhdr, mng_read_jhdr, mng_write_jhdr, mng_assign_jhdr, 0, 0}, + {MNG_UINT_JSEP, mng_init_jsep, mng_free_jsep, mng_read_jsep, mng_write_jsep, mng_assign_jsep, 0, 0}, + {MNG_UINT_JdAA, mng_init_jdaa, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_LOOP + {MNG_UINT_LOOP, mng_init_loop, mng_free_loop, mng_read_loop, mng_write_loop, mng_assign_loop, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_MAGN + {MNG_UINT_MAGN, mng_init_magn, mng_free_magn, mng_read_magn, mng_write_magn, mng_assign_magn, 0, 0}, +#endif + {MNG_UINT_MEND, mng_init_mend, mng_free_mend, mng_read_mend, mng_write_mend, mng_assign_mend, 0, 0}, + {MNG_UINT_MHDR, mng_init_mhdr, mng_free_mhdr, mng_read_mhdr, mng_write_mhdr, mng_assign_mhdr, 0, 0}, +#ifndef MNG_SKIPCHUNK_MOVE + {MNG_UINT_MOVE, mng_init_move, mng_free_move, mng_read_move, mng_write_move, mng_assign_move, 0, 0}, +#endif +#ifndef MNG_NO_DELTA_PNG +#ifndef MNG_SKIPCHUNK_ORDR + {MNG_UINT_ORDR, mng_init_ordr, mng_free_ordr, mng_read_ordr, mng_write_ordr, mng_assign_ordr, 0, 0}, +#endif +#endif +#ifndef MNG_SKIPCHUNK_PAST + {MNG_UINT_PAST, mng_init_past, mng_free_past, mng_read_past, mng_write_past, mng_assign_past, 0, 0}, +#endif + {MNG_UINT_PLTE, mng_init_plte, mng_free_plte, mng_read_plte, mng_write_plte, mng_assign_plte, 0, 0}, +#ifndef MNG_NO_DELTA_PNG + {MNG_UINT_PPLT, mng_init_pplt, mng_free_pplt, mng_read_pplt, mng_write_pplt, mng_assign_pplt, 0, 0}, + {MNG_UINT_PROM, mng_init_prom, mng_free_prom, mng_read_prom, mng_write_prom, mng_assign_prom, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_SAVE + {MNG_UINT_SAVE, mng_init_save, mng_free_save, mng_read_save, mng_write_save, mng_assign_save, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_SEEK + {MNG_UINT_SEEK, mng_init_seek, mng_free_seek, mng_read_seek, mng_write_seek, mng_assign_seek, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_SHOW + {MNG_UINT_SHOW, mng_init_show, mng_free_show, mng_read_show, mng_write_show, mng_assign_show, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_TERM + {MNG_UINT_TERM, mng_init_term, mng_free_term, mng_read_term, mng_write_term, mng_assign_term, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_bKGD + {MNG_UINT_bKGD, mng_init_bkgd, mng_free_bkgd, mng_read_bkgd, mng_write_bkgd, mng_assign_bkgd, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_cHRM + {MNG_UINT_cHRM, mng_init_chrm, mng_free_chrm, mng_read_chrm, mng_write_chrm, mng_assign_chrm, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_eXPI + {MNG_UINT_eXPI, mng_init_expi, mng_free_expi, mng_read_expi, mng_write_expi, mng_assign_expi, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_evNT + {MNG_UINT_evNT, mng_init_evnt, mng_free_evnt, mng_read_evnt, mng_write_evnt, mng_assign_evnt, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_fPRI + {MNG_UINT_fPRI, mng_init_fpri, mng_free_fpri, mng_read_fpri, mng_write_fpri, mng_assign_fpri, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_gAMA + {MNG_UINT_gAMA, mng_init_gama, mng_free_gama, mng_read_gama, mng_write_gama, mng_assign_gama, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_hIST + {MNG_UINT_hIST, mng_init_hist, mng_free_hist, mng_read_hist, mng_write_hist, mng_assign_hist, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_iCCP + {MNG_UINT_iCCP, mng_init_iccp, mng_free_iccp, mng_read_iccp, mng_write_iccp, mng_assign_iccp, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_iTXt + {MNG_UINT_iTXt, mng_init_itxt, mng_free_itxt, mng_read_itxt, mng_write_itxt, mng_assign_itxt, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_nEED + {MNG_UINT_nEED, mng_init_need, mng_free_need, mng_read_need, mng_write_need, mng_assign_need, 0, 0}, +#endif +/* TODO: {MNG_UINT_oFFs, 0, 0, 0, 0, 0, 0}, */ +/* TODO: {MNG_UINT_pCAL, 0, 0, 0, 0, 0, 0}, */ +#ifndef MNG_SKIPCHUNK_pHYg + {MNG_UINT_pHYg, mng_init_phyg, mng_free_phyg, mng_read_phyg, mng_write_phyg, mng_assign_phyg, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_pHYs + {MNG_UINT_pHYs, mng_init_phys, mng_free_phys, mng_read_phys, mng_write_phys, mng_assign_phys, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_sBIT + {MNG_UINT_sBIT, mng_init_sbit, mng_free_sbit, mng_read_sbit, mng_write_sbit, mng_assign_sbit, 0, 0}, +#endif +/* TODO: {MNG_UINT_sCAL, 0, 0, 0, 0, 0, 0}, */ +#ifndef MNG_SKIPCHUNK_sPLT + {MNG_UINT_sPLT, mng_init_splt, mng_free_splt, mng_read_splt, mng_write_splt, mng_assign_splt, 0, 0}, +#endif + {MNG_UINT_sRGB, mng_init_srgb, mng_free_srgb, mng_read_srgb, mng_write_srgb, mng_assign_srgb, 0, 0}, +#ifndef MNG_SKIPCHUNK_tEXt + {MNG_UINT_tEXt, mng_init_text, mng_free_text, mng_read_text, mng_write_text, mng_assign_text, 0, 0}, +#endif +#ifndef MNG_SKIPCHUNK_tIME + {MNG_UINT_tIME, mng_init_time, mng_free_time, mng_read_time, mng_write_time, mng_assign_time, 0, 0}, +#endif + {MNG_UINT_tRNS, mng_init_trns, mng_free_trns, mng_read_trns, mng_write_trns, mng_assign_trns, 0, 0}, +#ifndef MNG_SKIPCHUNK_zTXt + {MNG_UINT_zTXt, mng_init_ztxt, mng_free_ztxt, mng_read_ztxt, mng_write_ztxt, mng_assign_ztxt, 0, 0}, +#endif + }; + +#endif /* MNG_OPTIMIZE_CHUNKINITFREE */ + + /* binary search variables */ + mng_int32 iTop, iLower, iUpper, iMiddle; + mng_chunk_headerp pEntry; /* pointer to found entry */ +#else + mng_chunk_header sEntry; /* temp chunk-header */ +#endif /* MNG_OPTIMIZE_CHUNKREADER */ + + mng_chunkid iChunkname; /* the chunk's tag */ + mng_chunkp pChunk; /* chunk structure (if #define MNG_STORE_CHUNKS) */ + mng_retcode iRetcode; /* temporary error-code */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_RAW_CHUNK, MNG_LC_START); +#endif + /* reset timer indicator on read-cycle */ + if ((pData->bReading) && (!pData->bDisplaying)) + pData->bTimerset = MNG_FALSE; + /* get the chunkname */ + iChunkname = (mng_chunkid)(mng_get_uint32 (pBuf)); + + pBuf += sizeof (mng_chunkid); /* adjust the buffer */ + iBuflen -= sizeof (mng_chunkid); + pChunk = 0; + +#ifndef MNG_OPTIMIZE_CHUNKREADER + /* determine max index of table */ + iTop = (sizeof (mng_chunk_table) / sizeof (mng_chunk_table [0])) - 1; + + /* binary search; with 54 chunks, worst-case is 7 comparisons */ + iLower = 0; +#ifndef MNG_NO_DELTA_PNG + iMiddle = 11; /* start with the IDAT entry */ +#else + iMiddle = 8; +#endif + iUpper = iTop; + pEntry = 0; /* no goods yet! */ + + do /* the binary search itself */ + { + if (mng_chunk_table [iMiddle].iChunkname < iChunkname) + iLower = iMiddle + 1; + else if (mng_chunk_table [iMiddle].iChunkname > iChunkname) + iUpper = iMiddle - 1; + else + { + pEntry = &mng_chunk_table [iMiddle]; + break; + } + + iMiddle = (iLower + iUpper) >> 1; + } + while (iLower <= iUpper); + + if (!pEntry) /* unknown chunk ? */ + pEntry = &mng_chunk_unknown; /* make it so! */ + +#else /* MNG_OPTIMIZE_CHUNKREADER */ + + mng_get_chunkheader (iChunkname, &sEntry); + +#endif /* MNG_OPTIMIZE_CHUNKREADER */ + + pData->iChunkname = iChunkname; /* keep track of where we are */ + pData->iChunkseq++; + +#ifndef MNG_OPTIMIZE_CHUNKREADER + if (pEntry->fRead) /* read-callback available ? */ + { + iRetcode = pEntry->fRead (pData, pEntry, iBuflen, (mng_ptr)pBuf, &pChunk); + + if (!iRetcode) /* everything oke ? */ + { /* remember unknown chunk's id */ + if ((pChunk) && (pEntry->iChunkname == MNG_UINT_HUH)) + ((mng_chunk_headerp)pChunk)->iChunkname = iChunkname; + } + } +#else /* MNG_OPTIMIZE_CHUNKREADER */ + if (sEntry.fRead) /* read-callback available ? */ + { + iRetcode = sEntry.fRead (pData, &sEntry, iBuflen, (mng_ptr)pBuf, &pChunk); + +#ifndef MNG_OPTIMIZE_CHUNKREADER + if (!iRetcode) /* everything oke ? */ + { /* remember unknown chunk's id */ + if ((pChunk) && (sEntry.iChunkname == MNG_UINT_HUH)) + ((mng_chunk_headerp)pChunk)->iChunkname = iChunkname; + } +#endif + } +#endif /* MNG_OPTIMIZE_CHUNKREADER */ + else + iRetcode = MNG_NOERROR; + + if (pChunk) /* store this chunk ? */ + mng_add_chunk (pData, pChunk); /* do it */ + +#ifdef MNG_INCLUDE_JNG /* implicit EOF ? */ + if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && (!pData->bHasJHDR)) +#else + if ((!pData->bHasMHDR) && (!pData->bHasIHDR)) +#endif + iRetcode = mng_process_eof (pData);/* then do some EOF processing */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_PROCESS_RAW_CHUNK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode check_chunk_crc (mng_datap pData, + mng_uint8p pBuf, + mng_uint32 iBuflen) +{ + mng_uint32 iCrc; /* calculated CRC */ + mng_bool bDiscard = MNG_FALSE; + mng_retcode iRetcode = MNG_NOERROR; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_CHUNK_CRC, MNG_LC_START); +#endif + + if (pData->iCrcmode & MNG_CRC_INPUT) /* crc included ? */ + { + mng_bool bCritical = (mng_bool)((*pBuf & 0x20) == 0); + mng_uint32 iL = iBuflen - (mng_uint32)(sizeof (iCrc)); + + if (((bCritical ) && (pData->iCrcmode & MNG_CRC_CRITICAL )) || + ((!bCritical) && (pData->iCrcmode & MNG_CRC_ANCILLARY))) + { /* calculate the crc */ + iCrc = mng_crc (pData, pBuf, iL); + /* and check it */ + if (!(iCrc == mng_get_uint32 (pBuf + iL))) + { + mng_bool bWarning = MNG_FALSE; + mng_bool bError = MNG_FALSE; + + if (bCritical) + { + switch (pData->iCrcmode & MNG_CRC_CRITICAL) + { + case MNG_CRC_CRITICAL_WARNING : { bWarning = MNG_TRUE; break; } + case MNG_CRC_CRITICAL_ERROR : { bError = MNG_TRUE; break; } + } + } + else + { + switch (pData->iCrcmode & MNG_CRC_ANCILLARY) + { + case MNG_CRC_ANCILLARY_DISCARD : { bDiscard = MNG_TRUE; break; } + case MNG_CRC_ANCILLARY_WARNING : { bWarning = MNG_TRUE; break; } + case MNG_CRC_ANCILLARY_ERROR : { bError = MNG_TRUE; break; } + } + } + + if (bWarning) + MNG_WARNING (pData, MNG_INVALIDCRC); + if (bError) + MNG_ERROR (pData, MNG_INVALIDCRC); + } + } + + if (!bDiscard) /* still processing ? */ + iRetcode = process_raw_chunk (pData, pBuf, iL); + } + else + { /* no crc => straight onto processing */ + iRetcode = process_raw_chunk (pData, pBuf, iBuflen); + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_CHUNK_CRC, MNG_LC_END); +#endif + + return iRetcode; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode read_chunk (mng_datap pData) +{ + mng_uint32 iBufmax = pData->iReadbufsize; + mng_uint8p pBuf = pData->pReadbuf; + mng_uint32 iBuflen = 0; /* number of bytes requested */ + mng_uint32 iRead = 0; /* number of bytes read */ + mng_retcode iRetcode = MNG_NOERROR; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_CHUNK, MNG_LC_START); +#endif + +#ifdef MNG_SUPPORT_DISPLAY + if (pData->pCurraniobj) /* processing an animation object ? */ + { + do /* process it then */ + { + iRetcode = ((mng_object_headerp)pData->pCurraniobj)->fProcess (pData, pData->pCurraniobj); + /* refresh needed ? */ +/* if ((!iRetcode) && (!pData->bTimerset) && (pData->bNeedrefresh)) + iRetcode = display_progressive_refresh (pData, 1); */ + /* can we advance to next object ? */ + if ((!iRetcode) && (pData->pCurraniobj) && + (!pData->bTimerset) && (!pData->bSectionwait)) + { /* reset timer indicator on read-cycle */ + if ((pData->bReading) && (!pData->bDisplaying)) + pData->bTimerset = MNG_FALSE; + + pData->pCurraniobj = ((mng_object_headerp)pData->pCurraniobj)->pNext; + /* TERM processing to be done ? */ + if ((!pData->pCurraniobj) && (pData->bHasTERM) && (!pData->bHasMHDR)) + iRetcode = mng_process_display_mend (pData); + } + } /* until error or a break or no more objects */ + while ((!iRetcode) && (pData->pCurraniobj) && + (!pData->bTimerset) && (!pData->bSectionwait) && (!pData->bFreezing)); + } + else + { + if (pData->iBreakpoint) /* do we need to finish something first ? */ + { + switch (pData->iBreakpoint) /* return to broken display routine */ + { +#ifndef MNG_SKIPCHUNK_FRAM + case 1 : { iRetcode = mng_process_display_fram2 (pData); break; } +#endif + case 2 : { iRetcode = mng_process_display_ihdr (pData); break; } +#ifndef MNG_SKIPCHUNK_SHOW + case 3 : ; /* same as 4 !!! */ + case 4 : { iRetcode = mng_process_display_show (pData); break; } +#endif +#ifndef MNG_SKIPCHUNK_CLON + case 5 : { iRetcode = mng_process_display_clon2 (pData); break; } +#endif +#ifdef MNG_INCLUDE_JNG + case 7 : { iRetcode = mng_process_display_jhdr (pData); break; } +#endif + case 6 : ; /* same as 8 !!! */ + case 8 : { iRetcode = mng_process_display_iend (pData); break; } +#ifndef MNG_SKIPCHUNK_MAGN + case 9 : { iRetcode = mng_process_display_magn2 (pData); break; } +#endif + case 10 : { iRetcode = mng_process_display_mend2 (pData); break; } +#ifndef MNG_SKIPCHUNK_PAST + case 11 : { iRetcode = mng_process_display_past2 (pData); break; } +#endif + } + } + } + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#endif /* MNG_SUPPORT_DISPLAY */ + /* can we continue processing now, or do we */ + /* need to wait for the timer to finish (again) ? */ +#ifdef MNG_SUPPORT_DISPLAY + if ((!pData->bTimerset) && (!pData->bSectionwait) && (!pData->bEOF)) +#else + if (!pData->bEOF) +#endif + { +#ifdef MNG_SUPPORT_DISPLAY + /* freezing in progress ? */ + if ((pData->bFreezing) && (pData->iSuspendpoint == 0)) + pData->bRunning = MNG_FALSE; /* then this is the right moment to do it */ +#endif + + if (pData->iSuspendpoint <= 2) + { + iBuflen = sizeof (mng_uint32); /* read length */ + iRetcode = read_databuffer (pData, pBuf, &pData->pReadbufnext, iBuflen, &iRead); + + if (iRetcode) /* bail on errors */ + return iRetcode; + + if (pData->bSuspended) /* suspended ? */ + pData->iSuspendpoint = 2; + else /* save the length */ + { + pData->iChunklen = mng_get_uint32 (pBuf); + if (pData->iChunklen > 0x7ffffff) + return MNG_INVALIDLENGTH; + } + + } + + if (!pData->bSuspended) /* still going ? */ + { /* previously suspended or not eof ? */ + if ((pData->iSuspendpoint > 2) || (iRead == iBuflen)) + { /* determine length chunkname + data (+ crc) */ + if (pData->iCrcmode & MNG_CRC_INPUT) + iBuflen = pData->iChunklen + (mng_uint32)(sizeof (mng_chunkid) + sizeof (mng_uint32)); + else + iBuflen = pData->iChunklen + (mng_uint32)(sizeof (mng_chunkid)); + + /* do we have enough data in the current push buffer ? */ + if ((pData->pFirstpushdata) && (iBuflen <= pData->pFirstpushdata->iRemaining)) + { + mng_pushdatap pPush = pData->pFirstpushdata; + pBuf = pPush->pDatanext; + pPush->pDatanext += iBuflen; + pPush->iRemaining -= iBuflen; + pData->iSuspendpoint = 0; /* safely reset this here ! */ + + iRetcode = check_chunk_crc (pData, pBuf, iBuflen); + if (iRetcode) + return iRetcode; + + if (!pPush->iRemaining) /* buffer depleted? then release it */ + iRetcode = mng_release_pushdata (pData); + } + else + { + if (iBuflen < iBufmax) /* does it fit in default buffer ? */ + { /* note that we don't use the full size + so there's always a zero-byte at the + very end !!! */ + iRetcode = read_databuffer (pData, pBuf, &pData->pReadbufnext, iBuflen, &iRead); + if (iRetcode) /* bail on errors */ + return iRetcode; + + if (pData->bSuspended) /* suspended ? */ + pData->iSuspendpoint = 3; + else + { + if (iRead != iBuflen) /* did we get all the data ? */ + MNG_ERROR (pData, MNG_UNEXPECTEDEOF); + iRetcode = check_chunk_crc (pData, pBuf, iBuflen); + } + } + else + { + if (iBuflen > 16777216) /* is the length incredible? */ + MNG_ERROR (pData, MNG_IMPROBABLELENGTH); + + if (!pData->iSuspendpoint) /* create additional large buffer ? */ + { /* again reserve space for the last zero-byte */ + pData->iLargebufsize = iBuflen + 1; + pData->pLargebufnext = MNG_NULL; + MNG_ALLOC (pData, pData->pLargebuf, pData->iLargebufsize); + } + + iRetcode = read_databuffer (pData, pData->pLargebuf, &pData->pLargebufnext, iBuflen, &iRead); + if (iRetcode) + return iRetcode; + + if (pData->bSuspended) /* suspended ? */ + pData->iSuspendpoint = 4; + else + { + if (iRead != iBuflen) /* did we get all the data ? */ + MNG_ERROR (pData, MNG_UNEXPECTEDEOF); + iRetcode = check_chunk_crc (pData, pData->pLargebuf, iBuflen); + /* cleanup additional large buffer */ + MNG_FREE (pData, pData->pLargebuf, pData->iLargebufsize); + } + } + } + + if (iRetcode) /* on error bail out */ + return iRetcode; + + } + else + { /* that's final */ + iRetcode = mng_process_eof (pData); + + if (iRetcode) /* on error bail out */ + return iRetcode; + + if ((iRead != 0) || /* did we get an unexpected eof ? */ +#ifdef MNG_INCLUDE_JNG + (pData->bHasIHDR || pData->bHasMHDR || pData->bHasJHDR)) +#else + (pData->bHasIHDR || pData->bHasMHDR)) +#endif + MNG_ERROR (pData, MNG_UNEXPECTEDEOF); + } + } + } + +#ifdef MNG_SUPPORT_DISPLAY /* refresh needed ? */ + if ((!pData->bTimerset) && (!pData->bSuspended) && (pData->bNeedrefresh)) + { + iRetcode = mng_display_progressive_refresh (pData, 1); + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_CHUNK, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +MNG_LOCAL mng_retcode process_pushedchunk (mng_datap pData) +{ + mng_pushdatap pPush; + mng_retcode iRetcode = MNG_NOERROR; + +#ifdef MNG_SUPPORT_DISPLAY + if (pData->pCurraniobj) /* processing an animation object ? */ + { + do /* process it then */ + { + iRetcode = ((mng_object_headerp)pData->pCurraniobj)->fProcess (pData, pData->pCurraniobj); + /* refresh needed ? */ +/* if ((!iRetcode) && (!pData->bTimerset) && (pData->bNeedrefresh)) + iRetcode = display_progressive_refresh (pData, 1); */ + /* can we advance to next object ? */ + if ((!iRetcode) && (pData->pCurraniobj) && + (!pData->bTimerset) && (!pData->bSectionwait)) + { /* reset timer indicator on read-cycle */ + if ((pData->bReading) && (!pData->bDisplaying)) + pData->bTimerset = MNG_FALSE; + + pData->pCurraniobj = ((mng_object_headerp)pData->pCurraniobj)->pNext; + /* TERM processing to be done ? */ + if ((!pData->pCurraniobj) && (pData->bHasTERM) && (!pData->bHasMHDR)) + iRetcode = mng_process_display_mend (pData); + } + } /* until error or a break or no more objects */ + while ((!iRetcode) && (pData->pCurraniobj) && + (!pData->bTimerset) && (!pData->bSectionwait) && (!pData->bFreezing)); + } + else + { + if (pData->iBreakpoint) /* do we need to finish something first ? */ + { + switch (pData->iBreakpoint) /* return to broken display routine */ + { +#ifndef MNG_SKIPCHUNK_FRAM + case 1 : { iRetcode = mng_process_display_fram2 (pData); break; } +#endif + case 2 : { iRetcode = mng_process_display_ihdr (pData); break; } +#ifndef MNG_SKIPCHUNK_SHOW + case 3 : ; /* same as 4 !!! */ + case 4 : { iRetcode = mng_process_display_show (pData); break; } +#endif +#ifndef MNG_SKIPCHUNK_CLON + case 5 : { iRetcode = mng_process_display_clon2 (pData); break; } +#endif +#ifdef MNG_INCLUDE_JNG + case 7 : { iRetcode = mng_process_display_jhdr (pData); break; } +#endif + case 6 : ; /* same as 8 !!! */ + case 8 : { iRetcode = mng_process_display_iend (pData); break; } +#ifndef MNG_SKIPCHUNK_MAGN + case 9 : { iRetcode = mng_process_display_magn2 (pData); break; } +#endif + case 10 : { iRetcode = mng_process_display_mend2 (pData); break; } +#ifndef MNG_SKIPCHUNK_PAST + case 11 : { iRetcode = mng_process_display_past2 (pData); break; } +#endif + } + } + } + + if (iRetcode) /* on error bail out */ + return iRetcode; + +#endif /* MNG_SUPPORT_DISPLAY */ + /* can we continue processing now, or do we */ + /* need to wait for the timer to finish (again) ? */ +#ifdef MNG_SUPPORT_DISPLAY + if ((!pData->bTimerset) && (!pData->bSectionwait) && (!pData->bEOF)) +#else + if (!pData->bEOF) +#endif + { + pData->iSuspendpoint = 0; /* safely reset it here ! */ + pPush = pData->pFirstpushchunk; + + iRetcode = process_raw_chunk (pData, pPush->pData, pPush->iLength); + if (iRetcode) + return iRetcode; + +#ifdef MNG_SUPPORT_DISPLAY /* refresh needed ? */ + if ((!pData->bTimerset) && (!pData->bSuspended) && (pData->bNeedrefresh)) + { + iRetcode = mng_display_progressive_refresh (pData, 1); + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#endif + } + + return mng_release_pushchunk (pData); +} + +/* ************************************************************************** */ + +mng_retcode mng_read_graphic (mng_datap pData) +{ + mng_uint32 iBuflen; /* number of bytes requested */ + mng_uint32 iRead; /* number of bytes read */ + mng_retcode iRetcode; /* temporary error-code */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_GRAPHIC, MNG_LC_START); +#endif + + if (!pData->pReadbuf) /* buffer allocated ? */ + { + pData->iReadbufsize = 4200; /* allocate a default read buffer */ + MNG_ALLOC (pData, pData->pReadbuf, pData->iReadbufsize); + } + /* haven't processed the signature ? */ + if ((!pData->bHavesig) || (pData->iSuspendpoint == 1)) + { + iBuflen = 2 * sizeof (mng_uint32); /* read signature */ + + iRetcode = read_databuffer (pData, pData->pReadbuf, &pData->pReadbufnext, iBuflen, &iRead); + + if (iRetcode) + return iRetcode; + + if (pData->bSuspended) /* input suspension ? */ + pData->iSuspendpoint = 1; + else + { + if (iRead != iBuflen) /* full signature received ? */ + MNG_ERROR (pData, MNG_UNEXPECTEDEOF); + /* is it a valid signature ? */ + if (mng_get_uint32 (pData->pReadbuf) == PNG_SIG) + pData->eSigtype = mng_it_png; + else +#ifdef MNG_INCLUDE_JNG + if (mng_get_uint32 (pData->pReadbuf) == JNG_SIG) + pData->eSigtype = mng_it_jng; + else +#endif + if (mng_get_uint32 (pData->pReadbuf) == MNG_SIG) + pData->eSigtype = mng_it_mng; + else + MNG_ERROR (pData, MNG_INVALIDSIG); + /* all of it ? */ + if (mng_get_uint32 (pData->pReadbuf+4) != POST_SIG) + MNG_ERROR (pData, MNG_INVALIDSIG); + + pData->bHavesig = MNG_TRUE; + } + } + + if (!pData->bSuspended) /* still going ? */ + { + do + { /* reset timer during mng_read() ? */ + if ((pData->bReading) && (!pData->bDisplaying)) + pData->bTimerset = MNG_FALSE; + + if (pData->pFirstpushchunk) /* chunks pushed ? */ + iRetcode = process_pushedchunk (pData); /* process the pushed chunk */ + else + iRetcode = read_chunk (pData); /* read & process a chunk */ + + if (iRetcode) /* on error bail out */ + return iRetcode; + } +#ifdef MNG_SUPPORT_DISPLAY /* until EOF or a break-request */ + while (((!pData->bEOF) || (pData->pCurraniobj)) && + (!pData->bSuspended) && (!pData->bSectionwait) && + ((!pData->bTimerset) || ((pData->bReading) && (!pData->bDisplaying)))); +#else + while ((!pData->bEOF) && (!pData->bSuspended)); +#endif + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_READ_GRAPHIC, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_READ_PROCS */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + diff --git a/Source/LibMNG/libmng_trace.c b/Source/LibMNG/libmng_trace.c index ffb7b57..a6a2cab 100644 --- a/Source/LibMNG/libmng_trace.c +++ b/Source/LibMNG/libmng_trace.c @@ -1,1683 +1,1683 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_trace.c copyright (c) 2000-2007 G.Juyn * */ -/* * version : 1.0.10 * */ -/* * * */ -/* * purpose : Trace functions (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the trace functions * */ -/* * * */ -/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - added callback error-reporting support * */ -/* * * */ -/* * 0.5.2 - 05/23/2000 - G.Juyn * */ -/* * - added trace telltale reporting * */ -/* * 0.5.2 - 05/24/2000 - G.Juyn * */ -/* * - added tracestrings for global animation color-chunks * */ -/* * - added tracestrings for get/set of default ZLIB/IJG parms * */ -/* * - added tracestrings for global PLTE,tRNS,bKGD * */ -/* * 0.5.2 - 05/30/2000 - G.Juyn * */ -/* * - added tracestrings for image-object promotion * */ -/* * - added tracestrings for delta-image processing * */ -/* * 0.5.2 - 06/02/2000 - G.Juyn * */ -/* * - added tracestrings for getalphaline callback * */ -/* * 0.5.2 - 06/05/2000 - G.Juyn * */ -/* * - added tracestring for RGB8_A8 canvasstyle * */ -/* * 0.5.2 - 06/06/2000 - G.Juyn * */ -/* * - added tracestring for mng_read_resume HLAPI function * */ -/* * * */ -/* * 0.5.3 - 06/21/2000 - G.Juyn * */ -/* * - added tracestrings for get/set speedtype * */ -/* * - added tracestring for get imagelevel * */ -/* * 0.5.3 - 06/22/2000 - G.Juyn * */ -/* * - added tracestring for delta-image processing * */ -/* * - added tracestrings for PPLT chunk processing * */ -/* * * */ -/* * 0.9.1 - 07/07/2000 - G.Juyn * */ -/* * - added tracecodes for special display processing * */ -/* * 0.9.1 - 07/08/2000 - G.Juyn * */ -/* * - added tracestring for get/set suspensionmode * */ -/* * - added tracestrings for get/set display variables * */ -/* * - added tracecode for read_databuffer (I/O-suspension) * */ -/* * 0.9.1 - 07/15/2000 - G.Juyn * */ -/* * - added tracestrings for SAVE/SEEK callbacks * */ -/* * - added tracestrings for get/set sectionbreaks * */ -/* * - added tracestring for special error routine * */ -/* * 0.9.1 - 07/19/2000 - G.Juyn * */ -/* * - added tracestring for updatemngheader * */ -/* * * */ -/* * 0.9.2 - 07/31/2000 - G.Juyn * */ -/* * - added tracestrings for status_xxxxx functions * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * - added tracestring for updatemngsimplicity * */ -/* * * */ -/* * 0.9.3 - 08/26/2000 - G.Juyn * */ -/* * - added MAGN chunk * */ -/* * 0.9.3 - 09/07/2000 - G.Juyn * */ -/* * - added support for new filter_types * */ -/* * 0.9.3 - 10/10/2000 - G.Juyn * */ -/* * - added support for alpha-depth prediction * */ -/* * 0.9.3 - 10/11/2000 - G.Juyn * */ -/* * - added JDAA chunk * */ -/* * - added support for nEED * */ -/* * 0.9.3 - 10/16/2000 - G.Juyn * */ -/* * - added functions to retrieve PNG/JNG specific header-info * */ -/* * - added optional support for bKGD for PNG images * */ -/* * 0.9.3 - 10/17/2000 - G.Juyn * */ -/* * - added callback to process non-critical unknown chunks * */ -/* * - added routine to discard "invalid" objects * */ -/* * 0.9.3 - 10/19/2000 - G.Juyn * */ -/* * - implemented delayed delta-processing * */ -/* * 0.9.3 - 10/20/2000 - G.Juyn * */ -/* * - added get/set for bKGD preference setting * */ -/* * 0.9.3 - 10/21/2000 - G.Juyn * */ -/* * - added get function for interlace/progressive display * */ -/* * * */ -/* * 0.9.4 - 1/18/2001 - G.Juyn * */ -/* * - added "new" MAGN methods 3, 4 & 5 * */ -/* * * */ -/* * 1.0.1 - 02/08/2001 - G.Juyn * */ -/* * - added MEND processing callback * */ -/* * 1.0.1 - 04/21/2001 - G.Juyn (code by G.Kelly) * */ -/* * - added BGRA8 canvas with premultiplied alpha * */ -/* * 1.0.1 - 05/02/2001 - G.Juyn * */ -/* * - added "default" sRGB generation (Thanks Marti!) * */ -/* * * */ -/* * 1.0.2 - 06/23/2001 - G.Juyn * */ -/* * - added optimization option for MNG-video playback * */ -/* * - added processterm callback * */ -/* * 1.0.2 - 06/25/2001 - G.Juyn * */ -/* * - added option to turn off progressive refresh * */ -/* * * */ -/* * 1.0.3 - 08/06/2001 - G.Juyn * */ -/* * - added get function for last processed BACK chunk * */ -/* * * */ -/* * 1.0.5 - 08/15/2002 - G.Juyn * */ -/* * - completed PROM support * */ -/* * - completed delta-image support * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * - added HLAPI function to copy chunks * */ -/* * 1.0.5 - 09/14/2002 - G.Juyn * */ -/* * - added event handling for dynamic MNG * */ -/* * 1.0.5 - 09/20/2002 - G.Juyn * */ -/* * - added support for PAST * */ -/* * 1.0.5 - 09/22/2002 - G.Juyn * */ -/* * - added bgrx8 canvas (filler byte) * */ -/* * 1.0.5 - 09/23/2002 - G.Juyn * */ -/* * - added in-memory color-correction of abstract images * */ -/* * - added compose over/under routines for PAST processing * */ -/* * - added flip & tile routines for PAST processing * */ -/* * 1.0.5 - 10/09/2002 - G.Juyn * */ -/* * - fixed trace-constants for PAST chunk * */ -/* * 1.0.5 - 11/07/2002 - G.Juyn * */ -/* * - added support to get totals after mng_read() * */ -/* * * */ -/* * 1.0.6 - 07/07/2003 - G.R-P * */ -/* * - added conditionals around JNG and Delta-PNG code * */ -/* * 1.0.6 - 07/14/2003 - G.R-P * */ -/* * - added conditionals around various unused functions * */ -/* * 1.0.6 - 07/29/2003 - G.R-P * */ -/* * - added conditionals around PAST chunk support * */ -/* * * */ -/* * 1.0.7 - 11/27/2003 - R.A * */ -/* * - added CANVAS_RGB565 and CANVAS_BGR565 * */ -/* * 1.0.7 - 01/25/2004 - J.S * */ -/* * - added premultiplied alpha canvas' for RGBA, ARGB, ABGR * */ -/* * 1.0.7 - 03/07/2004 - G. Randers-Pehrson * */ -/* * - put gamma, cms-related declarations inside #ifdef * */ -/* * 1.0.7 - 03/10/2004 - G.R-P * */ -/* * - added conditionals around openstream/closestream * */ -/* * * */ -/* * 1.0.8 - 04/02/2004 - G.Juyn * */ -/* * - added CRC existence & checking flags * */ -/* * 1.0.8 - 04/11/2004 - G.Juyn * */ -/* * - added data-push mechanisms for specialized decoders * */ -/* * * */ -/* * 1.0.9 - 10/03/2004 - G.Juyn * */ -/* * - added function to retrieve current FRAM delay * */ -/* * 1.0.9 - 10/14/2004 - G.Juyn * */ -/* * - added bgr565_a8 canvas-style (thanks to J. Elvander) * */ -/* * * */ -/* * 1.0.10 - 04/08/2007 - G.Juyn * */ -/* * - added support for mPNG proposal * */ -/* * 1.0.10 - 07/06/2007 - G.R-P bugfix by Lucas Quintana * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_TRACE_PROCS - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_TRACE_STRINGS -MNG_LOCAL mng_trace_entry const trace_table [] = - { - {MNG_FN_INITIALIZE, "initialize"}, - {MNG_FN_RESET, "reset"}, - {MNG_FN_CLEANUP, "cleanup"}, - {MNG_FN_READ, "read"}, - {MNG_FN_WRITE, "write"}, - {MNG_FN_CREATE, "create"}, - {MNG_FN_READDISPLAY, "readdisplay"}, - {MNG_FN_DISPLAY, "display"}, - {MNG_FN_DISPLAY_RESUME, "display_resume"}, - {MNG_FN_DISPLAY_FREEZE, "display_freeze"}, - {MNG_FN_DISPLAY_RESET, "display_reset"}, -#ifndef MNG_NO_DISPLAY_GO_SUPPORTED - {MNG_FN_DISPLAY_GOFRAME, "display_goframe"}, - {MNG_FN_DISPLAY_GOLAYER, "display_golayer"}, - {MNG_FN_DISPLAY_GOTIME, "display_gotime"}, -#endif - {MNG_FN_GETLASTERROR, "getlasterror"}, - {MNG_FN_READ_RESUME, "read_resume"}, - {MNG_FN_TRAPEVENT, "trapevent"}, - {MNG_FN_READ_PUSHDATA, "read_pushdata"}, - {MNG_FN_READ_PUSHSIG, "read_pushsig"}, - {MNG_FN_READ_PUSHCHUNK, "read_pushchunk"}, - - {MNG_FN_SETCB_MEMALLOC, "setcb_memalloc"}, - {MNG_FN_SETCB_MEMFREE, "setcb_memfree"}, - {MNG_FN_SETCB_READDATA, "setcb_readdata"}, - {MNG_FN_SETCB_WRITEDATA, "setcb_writedata"}, - {MNG_FN_SETCB_ERRORPROC, "setcb_errorproc"}, - {MNG_FN_SETCB_TRACEPROC, "setcb_traceproc"}, - {MNG_FN_SETCB_PROCESSHEADER, "setcb_processheader"}, - {MNG_FN_SETCB_PROCESSTEXT, "setcb_processtext"}, - {MNG_FN_SETCB_GETCANVASLINE, "setcb_getcanvasline"}, - {MNG_FN_SETCB_GETBKGDLINE, "setcb_getbkgdline"}, - {MNG_FN_SETCB_REFRESH, "setcb_refresh"}, - {MNG_FN_SETCB_GETTICKCOUNT, "setcb_gettickcount"}, - {MNG_FN_SETCB_SETTIMER, "setcb_settimer"}, - {MNG_FN_SETCB_PROCESSGAMMA, "setcb_processgamma"}, - {MNG_FN_SETCB_PROCESSCHROMA, "setcb_processchroma"}, - {MNG_FN_SETCB_PROCESSSRGB, "setcb_processsrgb"}, - {MNG_FN_SETCB_PROCESSICCP, "setcb_processiccp"}, - {MNG_FN_SETCB_PROCESSAROW, "setcb_processarow"}, -#ifndef MNG_NO_OPEN_CLOSE_STREAM - {MNG_FN_SETCB_OPENSTREAM, "setcb_openstream"}, - {MNG_FN_SETCB_CLOSESTREAM, "setcb_closestream"}, -#endif - {MNG_FN_SETCB_GETALPHALINE, "setcb_getalphaline"}, - {MNG_FN_SETCB_PROCESSSAVE, "setcb_processsave"}, - {MNG_FN_SETCB_PROCESSSEEK, "setcb_processseek"}, - {MNG_FN_SETCB_PROCESSNEED, "setcb_processneed"}, - {MNG_FN_SETCB_PROCESSUNKNOWN, "setcb_processunknown"}, - {MNG_FN_SETCB_PROCESSMEND, "setcb_processmend"}, - {MNG_FN_SETCB_PROCESSTERM, "setcb_processterm"}, - {MNG_FN_SETCB_RELEASEDATA, "setcb_releasedata"}, - - {MNG_FN_GETCB_MEMALLOC, "getcb_memalloc"}, - {MNG_FN_GETCB_MEMFREE, "getcb_memfree"}, - {MNG_FN_GETCB_READDATA, "getcb_readdata,"}, - {MNG_FN_GETCB_WRITEDATA, "getcb_writedata"}, - {MNG_FN_GETCB_ERRORPROC, "getcb_errorproc"}, - {MNG_FN_GETCB_TRACEPROC, "getcb_traceproc"}, - {MNG_FN_GETCB_PROCESSHEADER, "getcb_processheader"}, - {MNG_FN_GETCB_PROCESSTEXT, "getcb_processtext"}, - {MNG_FN_GETCB_GETCANVASLINE, "getcb_getcanvasline"}, - {MNG_FN_GETCB_GETBKGDLINE, "getcb_getbkgdline"}, - {MNG_FN_GETCB_REFRESH, "getcb_refresh"}, - {MNG_FN_GETCB_GETTICKCOUNT, "getcb_gettickcount"}, - {MNG_FN_GETCB_SETTIMER, "getcb_settimer"}, - {MNG_FN_GETCB_PROCESSGAMMA, "getcb_processgamma"}, - {MNG_FN_GETCB_PROCESSCHROMA, "getcb_processchroma"}, - {MNG_FN_GETCB_PROCESSSRGB, "getcb_processsrgb"}, - {MNG_FN_GETCB_PROCESSICCP, "getcb_processiccp"}, - {MNG_FN_GETCB_PROCESSAROW, "getcb_processarow"}, -#ifndef MNG_NO_OPEN_CLOSE_STREAM - {MNG_FN_GETCB_OPENSTREAM, "getcb_openstream"}, - {MNG_FN_GETCB_CLOSESTREAM, "getcb_closestream"}, -#endif - {MNG_FN_GETCB_GETALPHALINE, "getcb_getalphaline"}, - {MNG_FN_GETCB_PROCESSSAVE, "getcb_processsave"}, - {MNG_FN_GETCB_PROCESSSEEK, "getcb_processseek"}, - {MNG_FN_GETCB_PROCESSNEED, "getcb_processneed"}, - {MNG_FN_GETCB_PROCESSUNKNOWN, "getcb_processunknown"}, - {MNG_FN_GETCB_PROCESSMEND, "getcb_processmend"}, - {MNG_FN_GETCB_PROCESSTERM, "getcb_processterm"}, - {MNG_FN_GETCB_RELEASEDATA, "getcb_releasedata"}, - - {MNG_FN_SET_USERDATA, "set_userdata"}, - {MNG_FN_SET_CANVASSTYLE, "set_canvasstyle"}, - {MNG_FN_SET_BKGDSTYLE, "set_bkgdstyle"}, - {MNG_FN_SET_BGCOLOR, "set_bgcolor"}, - {MNG_FN_SET_STORECHUNKS, "set_storechunks"}, -#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) - {MNG_FN_SET_VIEWGAMMA, "set_viewgamma"}, -#ifndef MNG_NO_DFLT_INFO - {MNG_FN_SET_DISPLAYGAMMA, "set_displaygamma"}, -#endif - {MNG_FN_SET_DFLTIMGGAMMA, "set_dfltimggamma"}, -#endif - {MNG_FN_SET_SRGB, "set_srgb"}, - {MNG_FN_SET_OUTPUTPROFILE, "set_outputprofile"}, - {MNG_FN_SET_SRGBPROFILE, "set_srgbprofile"}, -#ifndef MNG_SKIP_MAXCANVAS - {MNG_FN_SET_MAXCANVASWIDTH, "set_maxcanvaswidth"}, - {MNG_FN_SET_MAXCANVASHEIGHT, "set_maxcanvasheight"}, - {MNG_FN_SET_MAXCANVASSIZE, "set_maxcanvassize"}, -#endif -#ifndef MNG_NO_ACCESS_ZLIB - {MNG_FN_SET_ZLIB_LEVEL, "set_zlib_level"}, - {MNG_FN_SET_ZLIB_METHOD, "set_zlib_method"}, - {MNG_FN_SET_ZLIB_WINDOWBITS, "set_zlib_windowbits"}, - {MNG_FN_SET_ZLIB_MEMLEVEL, "set_zlib_memlevel"}, - {MNG_FN_SET_ZLIB_STRATEGY, "set_zlib_strategy"}, - {MNG_FN_SET_ZLIB_MAXIDAT, "set_zlib_maxidat"}, -#endif -#ifndef MNG_NO_ACCESS_JPEG - {MNG_FN_SET_JPEG_DCTMETHOD, "set_jpeg_dctmethod"}, - {MNG_FN_SET_JPEG_QUALITY, "set_jpeg_quality"}, - {MNG_FN_SET_JPEG_SMOOTHING, "set_jpeg_smoothing"}, - {MNG_FN_SET_JPEG_PROGRESSIVE, "set_jpeg_progressive"}, - {MNG_FN_SET_JPEG_OPTIMIZED, "set_jpeg_optimized"}, - {MNG_FN_SET_JPEG_MAXJDAT, "set_jpeg_maxjdat"}, -#endif - {MNG_FN_SET_SPEED, "set_speed"}, - {MNG_FN_SET_SUSPENSIONMODE, "set_suspensionmode"}, - {MNG_FN_SET_SECTIONBREAKS, "set_sectionbreaks"}, - {MNG_FN_SET_USEBKGD, "set_usebkgd"}, - {MNG_FN_SET_OUTPUTPROFILE2, "set_outputprofile2"}, - {MNG_FN_SET_SRGBPROFILE2, "set_srgbprofile2"}, - {MNG_FN_SET_OUTPUTSRGB, "set_outputsrgb"}, - {MNG_FN_SET_SRGBIMPLICIT, "set_srgbimplicit"}, - {MNG_FN_SET_CACHEPLAYBACK, "set_cacheplayback"}, - {MNG_FN_SET_DOPROGRESSIVE, "set_doprogressive"}, - {MNG_FN_SET_CRCMODE, "set_crcmode"}, - - {MNG_FN_GET_USERDATA, "get_userdata"}, - {MNG_FN_GET_SIGTYPE, "get_sigtype"}, - {MNG_FN_GET_IMAGETYPE, "get_imagetype"}, - {MNG_FN_GET_IMAGEWIDTH, "get_imagewidth"}, - {MNG_FN_GET_IMAGEHEIGHT, "get_imageheight"}, - {MNG_FN_GET_TICKS, "get_ticks"}, - {MNG_FN_GET_FRAMECOUNT, "get_framecount"}, - {MNG_FN_GET_LAYERCOUNT, "get_layercount"}, - {MNG_FN_GET_PLAYTIME, "get_playtime"}, - {MNG_FN_GET_SIMPLICITY, "get_simplicity"}, - {MNG_FN_GET_CANVASSTYLE, "get_canvasstyle"}, - {MNG_FN_GET_BKGDSTYLE, "get_bkgdstyle"}, - {MNG_FN_GET_BGCOLOR, "get_bgcolor"}, - {MNG_FN_GET_STORECHUNKS, "get_storechunks"}, -#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) - {MNG_FN_GET_VIEWGAMMA, "get_viewgamma"}, - {MNG_FN_GET_DISPLAYGAMMA, "get_displaygamma"}, -#ifndef MNG_NO_DFLT_INFO - {MNG_FN_GET_DFLTIMGGAMMA, "get_dfltimggamma"}, -#endif -#endif - {MNG_FN_GET_SRGB, "get_srgb"}, -#ifndef MNG_SKIP_MAXCANVAS - {MNG_FN_GET_MAXCANVASWIDTH, "get_maxcanvaswidth"}, - {MNG_FN_GET_MAXCANVASHEIGHT, "get_maxcanvasheight"}, -#endif -#ifndef MNG_NO_ACCESS_ZLIB - {MNG_FN_GET_ZLIB_LEVEL, "get_zlib_level"}, - {MNG_FN_GET_ZLIB_METHOD, "get_zlib_method"}, - {MNG_FN_GET_ZLIB_WINDOWBITS, "get_zlib_windowbits"}, - {MNG_FN_GET_ZLIB_MEMLEVEL, "get_zlib_memlevel"}, - {MNG_FN_GET_ZLIB_STRATEGY, "get_zlib_strategy"}, - {MNG_FN_GET_ZLIB_MAXIDAT, "get_zlib_maxidat"}, -#endif -#ifndef MNG_NO_ACCESS_JPEG - {MNG_FN_GET_JPEG_DCTMETHOD, "get_jpeg_dctmethod"}, - {MNG_FN_GET_JPEG_QUALITY, "get_jpeg_quality"}, - {MNG_FN_GET_JPEG_SMOOTHING, "get_jpeg_smoothing"}, - {MNG_FN_GET_JPEG_PROGRESSIVE, "get_jpeg_progressive"}, - {MNG_FN_GET_JPEG_OPTIMIZED, "get_jpeg_optimized"}, - {MNG_FN_GET_JPEG_MAXJDAT, "get_jpeg_maxjdat"}, -#endif - {MNG_FN_GET_SPEED, "get_speed"}, - {MNG_FN_GET_IMAGELEVEL, "get_imagelevel"}, - {MNG_FN_GET_SUSPENSIONMODE, "get_speed"}, - {MNG_FN_GET_STARTTIME, "get_starttime"}, - {MNG_FN_GET_RUNTIME, "get_runtime"}, -#ifndef MNG_NO_CURRENT_INFO - {MNG_FN_GET_CURRENTFRAME, "get_currentframe"}, - {MNG_FN_GET_CURRENTLAYER, "get_currentlayer"}, - {MNG_FN_GET_CURRENTPLAYTIME, "get_currentplaytime"}, -#endif - {MNG_FN_GET_SECTIONBREAKS, "get_sectionbreaks"}, - {MNG_FN_GET_ALPHADEPTH, "get_alphadepth"}, - {MNG_FN_GET_BITDEPTH, "get_bitdepth"}, - {MNG_FN_GET_COLORTYPE, "get_colortype"}, - {MNG_FN_GET_COMPRESSION, "get_compression"}, - {MNG_FN_GET_FILTER, "get_filter"}, - {MNG_FN_GET_INTERLACE, "get_interlace"}, - {MNG_FN_GET_ALPHABITDEPTH, "get_alphabitdepth"}, - {MNG_FN_GET_ALPHACOMPRESSION, "get_alphacompression"}, - {MNG_FN_GET_ALPHAFILTER, "get_alphafilter"}, - {MNG_FN_GET_ALPHAINTERLACE, "get_alphainterlace"}, - {MNG_FN_GET_USEBKGD, "get_usebkgd"}, - {MNG_FN_GET_REFRESHPASS, "get_refreshpass"}, - {MNG_FN_GET_CACHEPLAYBACK, "get_cacheplayback"}, - {MNG_FN_GET_DOPROGRESSIVE, "get_doprogressive"}, - {MNG_FN_GET_LASTBACKCHUNK, "get_lastbackchunk"}, - {MNG_FN_GET_LASTSEEKNAME, "get_lastseekname"}, -#ifndef MNG_NO_CURRENT_INFO - {MNG_FN_GET_TOTALFRAMES, "get_totalframes"}, - {MNG_FN_GET_TOTALLAYERS, "get_totallayers"}, - {MNG_FN_GET_TOTALPLAYTIME, "get_totalplaytime"}, -#endif - {MNG_FN_GET_CRCMODE, "get_crcmode"}, - {MNG_FN_GET_CURRFRAMDELAY, "get_currframdelay"}, - - {MNG_FN_STATUS_ERROR, "status_error"}, - {MNG_FN_STATUS_READING, "status_reading"}, - {MNG_FN_STATUS_SUSPENDBREAK, "status_suspendbreak"}, - {MNG_FN_STATUS_CREATING, "status_creating"}, - {MNG_FN_STATUS_WRITING, "status_writing"}, - {MNG_FN_STATUS_DISPLAYING, "status_displaying"}, - {MNG_FN_STATUS_RUNNING, "status_running"}, - {MNG_FN_STATUS_TIMERBREAK, "status_timerbreak"}, - {MNG_FN_STATUS_DYNAMIC, "status_dynamic"}, - {MNG_FN_STATUS_RUNNINGEVENT, "status_runningevent"}, - - {MNG_FN_ITERATE_CHUNKS, "iterate_chunks"}, - {MNG_FN_COPY_CHUNK, "copy_chunk"}, - - {MNG_FN_GETCHUNK_IHDR, "getchunk_ihdr"}, - {MNG_FN_GETCHUNK_PLTE, "getchunk_plte"}, - {MNG_FN_GETCHUNK_IDAT, "getchunk_idat"}, - {MNG_FN_GETCHUNK_IEND, "getchunk_iend"}, - {MNG_FN_GETCHUNK_TRNS, "getchunk_trns"}, -#ifndef MNG_SKIPCHUNK_gAMA - {MNG_FN_GETCHUNK_GAMA, "getchunk_gama"}, -#endif -#ifndef MNG_SKIPCHUNK_cHRM - {MNG_FN_GETCHUNK_CHRM, "getchunk_chrm"}, -#endif -#ifndef MNG_SKIPCHUNK_sRGB - {MNG_FN_GETCHUNK_SRGB, "getchunk_srgb"}, -#endif -#ifndef MNG_SKIPCHUNK_iCCP - {MNG_FN_GETCHUNK_ICCP, "getchunk_iccp"}, -#endif -#ifndef MNG_SKIPCHUNK_tEXt - {MNG_FN_GETCHUNK_TEXT, "getchunk_text"}, -#endif -#ifndef MNG_SKIPCHUNK_zTXt - {MNG_FN_GETCHUNK_ZTXT, "getchunk_ztxt"}, -#endif -#ifndef MNG_SKIPCHUNK_iTXt - {MNG_FN_GETCHUNK_ITXT, "getchunk_itxt"}, -#endif -#ifndef MNG_SKIPCHUNK_bKGD - {MNG_FN_GETCHUNK_BKGD, "getchunk_bkgd"}, -#endif -#ifndef MNG_SKIPCHUNK_pHYs - {MNG_FN_GETCHUNK_PHYS, "getchunk_phys"}, -#endif -#ifndef MNG_SKIPCHUNK_sBIT - {MNG_FN_GETCHUNK_SBIT, "getchunk_sbit"}, -#endif -#ifndef MNG_SKIPCHUNK_sPLT - {MNG_FN_GETCHUNK_SPLT, "getchunk_splt"}, -#endif -#ifndef MNG_SKIPCHUNK_hIST - {MNG_FN_GETCHUNK_HIST, "getchunk_hist"}, -#endif -#ifndef MNG_SKIPCHUNK_tIME - {MNG_FN_GETCHUNK_TIME, "getchunk_time"}, -#endif - {MNG_FN_GETCHUNK_MHDR, "getchunk_mhdr"}, - {MNG_FN_GETCHUNK_MEND, "getchunk_mend"}, -#ifndef MNG_SKIPCHUNK_LOOP - {MNG_FN_GETCHUNK_LOOP, "getchunk_loop"}, - {MNG_FN_GETCHUNK_ENDL, "getchunk_endl"}, -#endif - {MNG_FN_GETCHUNK_DEFI, "getchunk_defi"}, -#ifndef MNG_SKIPCHUNK_BASI - {MNG_FN_GETCHUNK_BASI, "getchunk_basi"}, -#endif - {MNG_FN_GETCHUNK_CLON, "getchunk_clon"}, -#ifndef MNG_SKIPCHUNK_PAST - {MNG_FN_GETCHUNK_PAST, "getchunk_past"}, -#endif - {MNG_FN_GETCHUNK_DISC, "getchunk_disc"}, - {MNG_FN_GETCHUNK_BACK, "getchunk_back"}, - {MNG_FN_GETCHUNK_FRAM, "getchunk_fram"}, - {MNG_FN_GETCHUNK_MOVE, "getchunk_move"}, - {MNG_FN_GETCHUNK_CLIP, "getchunk_clip"}, - {MNG_FN_GETCHUNK_SHOW, "getchunk_show"}, - {MNG_FN_GETCHUNK_TERM, "getchunk_term"}, -#ifndef MNG_SKIPCHUNK_SAVE - {MNG_FN_GETCHUNK_SAVE, "getchunk_save"}, -#endif -#ifndef MNG_SKIPCHUNK_SEEK - {MNG_FN_GETCHUNK_SEEK, "getchunk_seek"}, -#endif -#ifndef MNG_SKIPCHUNK_eXPI - {MNG_FN_GETCHUNK_EXPI, "getchunk_expi"}, -#endif -#ifndef MNG_SKIPCHUNK_fPRI - {MNG_FN_GETCHUNK_FPRI, "getchunk_fpri"}, -#endif -#ifndef MNG_SKIPCHUNK_nEED - {MNG_FN_GETCHUNK_NEED, "getchunk_need"}, -#endif -#ifndef MNG_SKIPCHUNK_pHYg - {MNG_FN_GETCHUNK_PHYG, "getchunk_phyg"}, -#endif -#ifdef MNG_INCLUDE_JNG - {MNG_FN_GETCHUNK_JHDR, "getchunk_jhdr"}, - {MNG_FN_GETCHUNK_JDAT, "getchunk_jdat"}, - {MNG_FN_GETCHUNK_JSEP, "getchunk_jsep"}, -#endif -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_GETCHUNK_DHDR, "getchunk_dhdr"}, - {MNG_FN_GETCHUNK_PROM, "getchunk_prom"}, - {MNG_FN_GETCHUNK_IPNG, "getchunk_ipng"}, - {MNG_FN_GETCHUNK_PPLT, "getchunk_pplt"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_GETCHUNK_IJNG, "getchunk_ijng"}, -#endif -#ifndef MNG_SKIPCHUNK_DROP - {MNG_FN_GETCHUNK_DROP, "getchunk_drop"}, -#endif -#ifndef MNG_SKIPCHUNK_DBYK - {MNG_FN_GETCHUNK_DBYK, "getchunk_dbyk"}, -#endif -#ifndef MNG_SKIPCHUNK_ORDR - {MNG_FN_GETCHUNK_ORDR, "getchunk_ordr"}, -#endif -#endif - {MNG_FN_GETCHUNK_UNKNOWN, "getchunk_unknown"}, - {MNG_FN_GETCHUNK_MAGN, "getchunk_magn"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_GETCHUNK_JDAA, "getchunk_jdaa"}, -#endif -#ifndef MNG_SKIPCHUNK_evNT - {MNG_FN_GETCHUNK_EVNT, "getchunk_evnt"}, -#endif -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - {MNG_FN_GETCHUNK_MPNG, "getchunk_mpng"}, -#endif - -#ifndef MNG_SKIPCHUNK_PAST - {MNG_FN_GETCHUNK_PAST_SRC, "getchunk_past_src"}, -#endif -#ifndef MNG_SKIPCHUNK_SAVE - {MNG_FN_GETCHUNK_SAVE_ENTRY, "getchunk_save_entry"}, -#endif -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_GETCHUNK_PPLT_ENTRY, "getchunk_pplt_entry"}, - {MNG_FN_GETCHUNK_ORDR_ENTRY, "getchunk_ordr_entry"}, -#endif -#ifndef MNG_SKIPCHUNK_evNT - {MNG_FN_GETCHUNK_EVNT_ENTRY, "getchunk_evnt_entry"}, -#endif -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - {MNG_FN_GETCHUNK_MPNG_FRAME, "getchunk_mpng_frame"}, -#endif - - {MNG_FN_PUTCHUNK_IHDR, "putchunk_ihdr"}, - {MNG_FN_PUTCHUNK_PLTE, "putchunk_plte"}, - {MNG_FN_PUTCHUNK_IDAT, "putchunk_idat"}, - {MNG_FN_PUTCHUNK_IEND, "putchunk_iend"}, - {MNG_FN_PUTCHUNK_TRNS, "putchunk_trns"}, -#ifndef MNG_SKIPCHUNK_gAMA - {MNG_FN_PUTCHUNK_GAMA, "putchunk_gama"}, -#endif -#ifndef MNG_SKIPCHUNK_cHRM - {MNG_FN_PUTCHUNK_CHRM, "putchunk_chrm"}, -#endif -#ifndef MNG_SKIPCHUNK_sRGB - {MNG_FN_PUTCHUNK_SRGB, "putchunk_srgb"}, -#endif -#ifndef MNG_SKIPCHUNK_iCCP - {MNG_FN_PUTCHUNK_ICCP, "putchunk_iccp"}, -#endif -#ifndef MNG_SKIPCHUNK_tEXt - {MNG_FN_PUTCHUNK_TEXT, "putchunk_text"}, -#endif -#ifndef MNG_SKIPCHUNK_zTXt - {MNG_FN_PUTCHUNK_ZTXT, "putchunk_ztxt"}, -#endif -#ifndef MNG_SKIPCHUNK_iTXt - {MNG_FN_PUTCHUNK_ITXT, "putchunk_itxt"}, -#endif -#ifndef MNG_SKIPCHUNK_bKGD - {MNG_FN_PUTCHUNK_BKGD, "putchunk_bkgd"}, -#endif -#ifndef MNG_SKIPCHUNK_pHYs - {MNG_FN_PUTCHUNK_PHYS, "putchunk_phys"}, -#endif -#ifndef MNG_SKIPCHUNK_sBIT - {MNG_FN_PUTCHUNK_SBIT, "putchunk_sbit"}, -#endif -#ifndef MNG_SKIPCHUNK_sPLT - {MNG_FN_PUTCHUNK_SPLT, "putchunk_splt"}, -#endif -#ifndef MNG_SKIPCHUNK_hIST - {MNG_FN_PUTCHUNK_HIST, "putchunk_hist"}, -#endif -#ifndef MNG_SKIPCHUNK_tIME - {MNG_FN_PUTCHUNK_TIME, "putchunk_time"}, -#endif - {MNG_FN_PUTCHUNK_MHDR, "putchunk_mhdr"}, - {MNG_FN_PUTCHUNK_MEND, "putchunk_mend"}, - {MNG_FN_PUTCHUNK_LOOP, "putchunk_loop"}, - {MNG_FN_PUTCHUNK_ENDL, "putchunk_endl"}, - {MNG_FN_PUTCHUNK_DEFI, "putchunk_defi"}, - {MNG_FN_PUTCHUNK_BASI, "putchunk_basi"}, - {MNG_FN_PUTCHUNK_CLON, "putchunk_clon"}, -#ifndef MNG_SKIPCHUNK_PAST - {MNG_FN_PUTCHUNK_PAST, "putchunk_past"}, -#endif - {MNG_FN_PUTCHUNK_DISC, "putchunk_disc"}, - {MNG_FN_PUTCHUNK_BACK, "putchunk_back"}, - {MNG_FN_PUTCHUNK_FRAM, "putchunk_fram"}, - {MNG_FN_PUTCHUNK_MOVE, "putchunk_move"}, - {MNG_FN_PUTCHUNK_CLIP, "putchunk_clip"}, - {MNG_FN_PUTCHUNK_SHOW, "putchunk_show"}, - {MNG_FN_PUTCHUNK_TERM, "putchunk_term"}, -#ifndef MNG_SKIPCHUNK_SAVE - {MNG_FN_PUTCHUNK_SAVE, "putchunk_save"}, -#endif -#ifndef MNG_SKIPCHUNK_SEEK - {MNG_FN_PUTCHUNK_SEEK, "putchunk_seek"}, -#endif -#ifndef MNG_SKIPCHUNK_eXPI - {MNG_FN_PUTCHUNK_EXPI, "putchunk_expi"}, -#endif -#ifndef MNG_SKIPCHUNK_fPRI - {MNG_FN_PUTCHUNK_FPRI, "putchunk_fpri"}, -#endif -#ifndef MNG_SKIPCHUNK_nEED - {MNG_FN_PUTCHUNK_NEED, "putchunk_need"}, -#endif -#ifndef MNG_SKIPCHUNK_pHYg - {MNG_FN_PUTCHUNK_PHYG, "putchunk_phyg"}, -#endif -#ifdef MNG_INCLUDE_JNG - {MNG_FN_PUTCHUNK_JHDR, "putchunk_jhdr"}, - {MNG_FN_PUTCHUNK_JDAT, "putchunk_jdat"}, - {MNG_FN_PUTCHUNK_JSEP, "putchunk_jsep"}, -#endif -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_PUTCHUNK_DHDR, "putchunk_dhdr"}, - {MNG_FN_PUTCHUNK_PROM, "putchunk_prom"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_PUTCHUNK_IPNG, "putchunk_ipng"}, -#endif - {MNG_FN_PUTCHUNK_PPLT, "putchunk_pplt"}, - {MNG_FN_PUTCHUNK_IJNG, "putchunk_ijng"}, -#ifndef MNG_SKIPCHUNK_DROP - {MNG_FN_PUTCHUNK_DROP, "putchunk_drop"}, -#endif -#ifndef MNG_SKIPCHUNK_DBYK - {MNG_FN_PUTCHUNK_DBYK, "putchunk_dbyk"}, -#endif -#ifndef MNG_SKIPCHUNK_ORDR - {MNG_FN_PUTCHUNK_ORDR, "putchunk_ordr"}, -#endif -#endif - {MNG_FN_PUTCHUNK_UNKNOWN, "putchunk_unknown"}, - {MNG_FN_PUTCHUNK_MAGN, "putchunk_magn"}, - {MNG_FN_PUTCHUNK_JDAA, "putchunk_jdaa"}, -#ifndef MNG_SKIPCHUNK_evNT - {MNG_FN_PUTCHUNK_EVNT, "putchunk_evnt"}, -#endif -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - {MNG_FN_PUTCHUNK_MPNG, "putchunk_mpng"}, -#endif - -#ifndef MNG_SKIPCHUNK_PAST - {MNG_FN_PUTCHUNK_PAST_SRC, "putchunk_past_src"}, -#endif -#ifndef MNG_SKIPCHUNK_SAVE - {MNG_FN_PUTCHUNK_SAVE_ENTRY, "putchunk_save_entry"}, -#endif -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_PUTCHUNK_PPLT_ENTRY, "putchunk_pplt_entry"}, -#ifndef MNG_SKIPCHUNK_ORDR - {MNG_FN_PUTCHUNK_ORDR_ENTRY, "putchunk_ordr_entry"}, -#endif -#endif -#ifndef MNG_SKIPCHUNK_evNT - {MNG_FN_PUTCHUNK_EVNT_ENTRY, "putchunk_evnt_entry"}, -#endif -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - {MNG_FN_PUTCHUNK_MPNG_FRAME, "putchunk_mpng_frame"}, -#endif - - {MNG_FN_GETIMGDATA_SEQ, "getimgdata_seq"}, - {MNG_FN_GETIMGDATA_CHUNKSEQ, "getimgdata_chunkseq"}, - {MNG_FN_GETIMGDATA_CHUNK, "getimgdata_chunk"}, - - {MNG_FN_PUTIMGDATA_IHDR, "putimgdata_ihdr"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_PUTIMGDATA_JHDR, "putimgdata_jhdr"}, - {MNG_FN_PUTIMGDATA_BASI, "putimgdata_basi"}, - {MNG_FN_PUTIMGDATA_DHDR, "putimgdata_dhdr"}, -#endif - - {MNG_FN_UPDATEMNGHEADER, "updatemngheader"}, - {MNG_FN_UPDATEMNGSIMPLICITY, "updatemngsimplicity"}, - - {MNG_FN_PROCESS_RAW_CHUNK, "process_raw_chunk"}, - {MNG_FN_READ_GRAPHIC, "read_graphic"}, - {MNG_FN_DROP_CHUNKS, "drop_chunks"}, - {MNG_FN_PROCESS_ERROR, "process_error"}, - {MNG_FN_CLEAR_CMS, "clear_cms"}, - {MNG_FN_DROP_OBJECTS, "drop_objects"}, - {MNG_FN_READ_CHUNK, "read_chunk"}, - {MNG_FN_LOAD_BKGDLAYER, "load_bkgdlayer"}, - {MNG_FN_NEXT_FRAME, "next_frame"}, - {MNG_FN_NEXT_LAYER, "next_layer"}, - {MNG_FN_INTERFRAME_DELAY, "interframe_delay"}, - {MNG_FN_DISPLAY_IMAGE, "display_image"}, - {MNG_FN_DROP_IMGOBJECTS, "drop_imgobjects"}, - {MNG_FN_DROP_ANIOBJECTS, "drop_aniobjects"}, - {MNG_FN_INFLATE_BUFFER, "inflate_buffer"}, - {MNG_FN_DEFLATE_BUFFER, "deflate_buffer"}, - {MNG_FN_WRITE_RAW_CHUNK, "write_raw_chunk"}, - {MNG_FN_WRITE_GRAPHIC, "write_graphic"}, - {MNG_FN_SAVE_STATE, "save_state"}, - {MNG_FN_RESTORE_STATE, "restore_state"}, - {MNG_FN_DROP_SAVEDATA, "drop_savedata"}, -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_EXECUTE_DELTA_IMAGE, "execute_delta_image"}, -#endif - {MNG_FN_PROCESS_DISPLAY, "process_display"}, - {MNG_FN_CLEAR_CANVAS, "clear_canvas"}, - {MNG_FN_READ_DATABUFFER, "read_databuffer"}, - {MNG_FN_STORE_ERROR, "store_error"}, - {MNG_FN_DROP_INVALID_OBJECTS, "drop_invalid_objects"}, - {MNG_FN_RELEASE_PUSHDATA, "release_pushdata"}, - {MNG_FN_READ_DATA, "read_data"}, - {MNG_FN_READ_CHUNK_CRC, "read_chunk_crc"}, - {MNG_FN_RELEASE_PUSHCHUNK, "release_pushchunk"}, - - {MNG_FN_DISPLAY_RGB8, "display_rgb8"}, - {MNG_FN_DISPLAY_RGBA8, "display_rgba8"}, - {MNG_FN_DISPLAY_ARGB8, "display_argb8"}, - {MNG_FN_DISPLAY_BGR8, "display_bgr8"}, - {MNG_FN_DISPLAY_BGRA8, "display_bgra8"}, - {MNG_FN_DISPLAY_ABGR8, "display_abgr8"}, - {MNG_FN_DISPLAY_RGB16, "display_rgb16"}, - {MNG_FN_DISPLAY_RGBA16, "display_rgba16"}, - {MNG_FN_DISPLAY_ARGB16, "display_argb16"}, - {MNG_FN_DISPLAY_BGR16, "display_bgr16"}, - {MNG_FN_DISPLAY_BGRA16, "display_bgra16"}, - {MNG_FN_DISPLAY_ABGR16, "display_abgr16"}, - {MNG_FN_DISPLAY_INDEX8, "display_index8"}, - {MNG_FN_DISPLAY_INDEXA8, "display_indexa8"}, - {MNG_FN_DISPLAY_AINDEX8, "display_aindex8"}, - {MNG_FN_DISPLAY_GRAY8, "display_gray8"}, - {MNG_FN_DISPLAY_GRAY16, "display_gray16"}, - {MNG_FN_DISPLAY_GRAYA8, "display_graya8"}, - {MNG_FN_DISPLAY_GRAYA16, "display_graya16"}, - {MNG_FN_DISPLAY_AGRAY8, "display_agray8"}, - {MNG_FN_DISPLAY_AGRAY16, "display_agray16"}, - {MNG_FN_DISPLAY_DX15, "display_dx15"}, - {MNG_FN_DISPLAY_DX16, "display_dx16"}, - {MNG_FN_DISPLAY_RGB8_A8, "display_rgb8_a8"}, - {MNG_FN_DISPLAY_BGRA8PM, "display_bgra8_pm"}, - {MNG_FN_DISPLAY_BGRX8, "display_bgrx8"}, - {MNG_FN_DISPLAY_RGB565, "display_rgb565"}, - {MNG_FN_DISPLAY_RGBA565, "display_rgba565"}, - {MNG_FN_DISPLAY_BGR565, "display_bgr565"}, - {MNG_FN_DISPLAY_BGRA565, "display_bgra565"}, - {MNG_FN_DISPLAY_RGBA8_PM, "display_rgba8_pm"}, - {MNG_FN_DISPLAY_ARGB8_PM, "display_argb8_pm"}, - {MNG_FN_DISPLAY_ABGR8_PM, "display_abgr8_pm"}, - {MNG_FN_DISPLAY_BGR565_A8, "display_bgr565_a8"}, - - {MNG_FN_INIT_FULL_CMS, "init_full_cms"}, - {MNG_FN_CORRECT_FULL_CMS, "correct_full_cms"}, - {MNG_FN_INIT_GAMMA_ONLY, "init_gamma_only"}, - {MNG_FN_CORRECT_GAMMA_ONLY, "correct_gamma_only"}, - {MNG_FN_CORRECT_APP_CMS, "correct_app_cms"}, - {MNG_FN_INIT_FULL_CMS_OBJ, "init_full_cms_obj"}, - {MNG_FN_INIT_GAMMA_ONLY_OBJ, "init_gamma_only_obj"}, - {MNG_FN_INIT_APP_CMS, "init_app_cms"}, - {MNG_FN_INIT_APP_CMS_OBJ, "init_app_cms_obj"}, - - {MNG_FN_PROCESS_G1, "process_g1"}, - {MNG_FN_PROCESS_G2, "process_g2"}, - {MNG_FN_PROCESS_G4, "process_g4"}, - {MNG_FN_PROCESS_G8, "process_g8"}, - {MNG_FN_PROCESS_G16, "process_g16"}, - {MNG_FN_PROCESS_RGB8, "process_rgb8"}, - {MNG_FN_PROCESS_RGB16, "process_rgb16"}, - {MNG_FN_PROCESS_IDX1, "process_idx1"}, - {MNG_FN_PROCESS_IDX2, "process_idx2"}, - {MNG_FN_PROCESS_IDX4, "process_idx4"}, - {MNG_FN_PROCESS_IDX8, "process_idx8"}, - {MNG_FN_PROCESS_GA8, "process_ga8"}, - {MNG_FN_PROCESS_GA16, "process_ga16"}, - {MNG_FN_PROCESS_RGBA8, "process_rgba8"}, - {MNG_FN_PROCESS_RGBA16, "process_rgba16"}, - - {MNG_FN_INIT_G1_I, "init_g1_i"}, - {MNG_FN_INIT_G2_I, "init_g2_i"}, - {MNG_FN_INIT_G4_I, "init_g4_i"}, - {MNG_FN_INIT_G8_I, "init_g8_i"}, - {MNG_FN_INIT_G16_I, "init_g16_i"}, - {MNG_FN_INIT_RGB8_I, "init_rgb8_i"}, - {MNG_FN_INIT_RGB16_I, "init_rgb16_i"}, - {MNG_FN_INIT_IDX1_I, "init_idx1_i"}, - {MNG_FN_INIT_IDX2_I, "init_idx2_i"}, - {MNG_FN_INIT_IDX4_I, "init_idx4_i"}, - {MNG_FN_INIT_IDX8_I, "init_idx8_i"}, - {MNG_FN_INIT_GA8_I, "init_ga8_i"}, - {MNG_FN_INIT_GA16_I, "init_ga16_i"}, - {MNG_FN_INIT_RGBA8_I, "init_rgba8_i"}, - {MNG_FN_INIT_RGBA16_I, "init_rgba16_i"}, -#ifndef MNG_OPTIMIZE_FOOTPRINT_INIT - {MNG_FN_INIT_G1_NI, "init_g1_ni"}, - {MNG_FN_INIT_G2_NI, "init_g2_ni"}, - {MNG_FN_INIT_G4_NI, "init_g4_ni"}, - {MNG_FN_INIT_G8_NI, "init_g8_ni"}, - {MNG_FN_INIT_G16_NI, "init_g16_ni"}, - {MNG_FN_INIT_RGB8_NI, "init_rgb8_ni"}, - {MNG_FN_INIT_RGB16_NI, "init_rgb16_ni"}, - {MNG_FN_INIT_IDX1_NI, "init_idx1_ni"}, - {MNG_FN_INIT_IDX2_NI, "init_idx2_ni"}, - {MNG_FN_INIT_IDX4_NI, "init_idx4_ni"}, - {MNG_FN_INIT_IDX8_NI, "init_idx8_ni"}, - {MNG_FN_INIT_GA8_NI, "init_ga8_ni"}, - {MNG_FN_INIT_GA16_NI, "init_ga16_ni"}, - {MNG_FN_INIT_RGBA8_NI, "init_rgba8_ni"}, - {MNG_FN_INIT_RGBA16_NI, "init_rgba16_ni"}, -#endif - - {MNG_FN_INIT_ROWPROC, "init_rowproc"}, - {MNG_FN_NEXT_ROW, "next_row"}, - {MNG_FN_CLEANUP_ROWPROC, "cleanup_rowproc"}, - - {MNG_FN_FILTER_A_ROW, "filter_a_row"}, - {MNG_FN_FILTER_SUB, "filter_sub"}, - {MNG_FN_FILTER_UP, "filter_up"}, - {MNG_FN_FILTER_AVERAGE, "filter_average"}, - {MNG_FN_FILTER_PAETH, "filter_paeth"}, - - {MNG_FN_INIT_ROWDIFFERING, "init_rowdiffering"}, - {MNG_FN_DIFFER_G1, "differ_g1"}, - {MNG_FN_DIFFER_G2, "differ_g2"}, - {MNG_FN_DIFFER_G4, "differ_g4"}, - {MNG_FN_DIFFER_G8, "differ_g8"}, - {MNG_FN_DIFFER_G16, "differ_g16"}, - {MNG_FN_DIFFER_RGB8, "differ_rgb8"}, - {MNG_FN_DIFFER_RGB16, "differ_rgb16"}, - {MNG_FN_DIFFER_IDX1, "differ_idx1"}, - {MNG_FN_DIFFER_IDX2, "differ_idx2"}, - {MNG_FN_DIFFER_IDX4, "differ_idx4"}, - {MNG_FN_DIFFER_IDX8, "differ_idx8"}, - {MNG_FN_DIFFER_GA8, "differ_ga8"}, - {MNG_FN_DIFFER_GA16, "differ_ga16"}, - {MNG_FN_DIFFER_RGBA8, "differ_rgba8"}, - {MNG_FN_DIFFER_RGBA16, "differ_rgba16"}, - - {MNG_FN_CREATE_IMGDATAOBJECT, "create_imgdataobject"}, - {MNG_FN_FREE_IMGDATAOBJECT, "free_imgdataobject"}, - {MNG_FN_CLONE_IMGDATAOBJECT, "clone_imgdataobject"}, - {MNG_FN_CREATE_IMGOBJECT, "create_imgobject"}, - {MNG_FN_FREE_IMGOBJECT, "free_imgobject"}, - {MNG_FN_FIND_IMGOBJECT, "find_imgobject"}, - {MNG_FN_CLONE_IMGOBJECT, "clone_imgobject"}, - {MNG_FN_RESET_OBJECTDETAILS, "reset_objectdetails"}, - {MNG_FN_RENUM_IMGOBJECT, "renum_imgobject"}, - {MNG_FN_PROMOTE_IMGOBJECT, "promote_imgobject"}, - {MNG_FN_MAGNIFY_IMGOBJECT, "magnify_imgobject"}, - {MNG_FN_COLORCORRECT_OBJECT, "colorcorrect_object"}, - - {MNG_FN_STORE_G1, "store_g1"}, - {MNG_FN_STORE_G2, "store_g2"}, - {MNG_FN_STORE_G4, "store_g4"}, - {MNG_FN_STORE_G8, "store_g8"}, - {MNG_FN_STORE_G16, "store_g16"}, - {MNG_FN_STORE_RGB8, "store_rgb8"}, - {MNG_FN_STORE_RGB16, "store_rgb16"}, - {MNG_FN_STORE_IDX1, "store_idx1"}, - {MNG_FN_STORE_IDX2, "store_idx2"}, - {MNG_FN_STORE_IDX4, "store_idx4"}, - {MNG_FN_STORE_IDX8, "store_idx8"}, - {MNG_FN_STORE_GA8, "store_ga8"}, - {MNG_FN_STORE_GA16, "store_ga16"}, - {MNG_FN_STORE_RGBA8, "store_rgba8"}, - {MNG_FN_STORE_RGBA16, "store_rgba16"}, - - {MNG_FN_RETRIEVE_G8, "retrieve_g8"}, - {MNG_FN_RETRIEVE_G16, "retrieve_g16"}, - {MNG_FN_RETRIEVE_RGB8, "retrieve_rgb8"}, - {MNG_FN_RETRIEVE_RGB16, "retrieve_rgb16"}, - {MNG_FN_RETRIEVE_IDX8, "retrieve_idx8"}, - {MNG_FN_RETRIEVE_GA8, "retrieve_ga8"}, - {MNG_FN_RETRIEVE_GA16, "retrieve_ga16"}, - {MNG_FN_RETRIEVE_RGBA8, "retrieve_rgba8"}, - {MNG_FN_RETRIEVE_RGBA16, "retrieve_rgba16"}, - -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_DELTA_G1, "delta_g1"}, - {MNG_FN_DELTA_G2, "delta_g2"}, - {MNG_FN_DELTA_G4, "delta_g4"}, - {MNG_FN_DELTA_G8, "delta_g8"}, - {MNG_FN_DELTA_G16, "delta_g16"}, - {MNG_FN_DELTA_RGB8, "delta_rgb8"}, - {MNG_FN_DELTA_RGB16, "delta_rgb16"}, - {MNG_FN_DELTA_IDX1, "delta_idx1"}, - {MNG_FN_DELTA_IDX2, "delta_idx2"}, - {MNG_FN_DELTA_IDX4, "delta_idx4"}, - {MNG_FN_DELTA_IDX8, "delta_idx8"}, - {MNG_FN_DELTA_GA8, "delta_ga8"}, - {MNG_FN_DELTA_GA16, "delta_ga16"}, - {MNG_FN_DELTA_RGBA8, "delta_rgba8"}, - {MNG_FN_DELTA_RGBA16, "delta_rgba16"}, -#endif - - {MNG_FN_CREATE_ANI_LOOP, "create_ani_loop"}, - {MNG_FN_CREATE_ANI_ENDL, "create_ani_endl"}, - {MNG_FN_CREATE_ANI_DEFI, "create_ani_defi"}, - {MNG_FN_CREATE_ANI_BASI, "create_ani_basi"}, - {MNG_FN_CREATE_ANI_CLON, "create_ani_clon"}, -#ifndef MNG_SKIPCHUNK_PAST - {MNG_FN_CREATE_ANI_PAST, "create_ani_past"}, -#endif - {MNG_FN_CREATE_ANI_DISC, "create_ani_disc"}, - {MNG_FN_CREATE_ANI_BACK, "create_ani_back"}, - {MNG_FN_CREATE_ANI_FRAM, "create_ani_fram"}, - {MNG_FN_CREATE_ANI_MOVE, "create_ani_move"}, - {MNG_FN_CREATE_ANI_CLIP, "create_ani_clip"}, - {MNG_FN_CREATE_ANI_SHOW, "create_ani_show"}, - {MNG_FN_CREATE_ANI_TERM, "create_ani_term"}, - {MNG_FN_CREATE_ANI_SAVE, "create_ani_save"}, - {MNG_FN_CREATE_ANI_SEEK, "create_ani_seek"}, - {MNG_FN_CREATE_ANI_GAMA, "create_ani_gama"}, - {MNG_FN_CREATE_ANI_CHRM, "create_ani_chrm"}, - {MNG_FN_CREATE_ANI_SRGB, "create_ani_srgb"}, - {MNG_FN_CREATE_ANI_ICCP, "create_ani_iccp"}, - {MNG_FN_CREATE_ANI_PLTE, "create_ani_plte"}, - {MNG_FN_CREATE_ANI_TRNS, "create_ani_trns"}, - {MNG_FN_CREATE_ANI_BKGD, "create_ani_bkgd"}, -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_CREATE_ANI_DHDR, "create_ani_dhdr"}, - {MNG_FN_CREATE_ANI_PROM, "create_ani_prom"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_CREATE_ANI_IPNG, "create_ani_ipng"}, -#endif - {MNG_FN_CREATE_ANI_IJNG, "create_ani_ijng"}, - {MNG_FN_CREATE_ANI_PPLT, "create_ani_pplt"}, -#endif - {MNG_FN_CREATE_ANI_MAGN, "create_ani_magn"}, - - {MNG_FN_CREATE_ANI_IMAGE, "create_ani_image"}, - {MNG_FN_CREATE_EVENT, "create_event"}, - - {MNG_FN_FREE_ANI_LOOP, "free_ani_loop"}, - {MNG_FN_FREE_ANI_ENDL, "free_ani_endl"}, - {MNG_FN_FREE_ANI_DEFI, "free_ani_defi"}, - {MNG_FN_FREE_ANI_BASI, "free_ani_basi"}, - {MNG_FN_FREE_ANI_CLON, "free_ani_clon"}, -#ifndef MNG_SKIPCHUNK_PAST - {MNG_FN_FREE_ANI_PAST, "free_ani_past"}, -#endif - {MNG_FN_FREE_ANI_DISC, "free_ani_disc"}, - {MNG_FN_FREE_ANI_BACK, "free_ani_back"}, - {MNG_FN_FREE_ANI_FRAM, "free_ani_fram"}, - {MNG_FN_FREE_ANI_MOVE, "free_ani_move"}, - {MNG_FN_FREE_ANI_CLIP, "free_ani_clip"}, - {MNG_FN_FREE_ANI_SHOW, "free_ani_show"}, - {MNG_FN_FREE_ANI_TERM, "free_ani_term"}, - {MNG_FN_FREE_ANI_SAVE, "free_ani_save"}, - {MNG_FN_FREE_ANI_SEEK, "free_ani_seek"}, - {MNG_FN_FREE_ANI_GAMA, "free_ani_gama"}, - {MNG_FN_FREE_ANI_CHRM, "free_ani_chrm"}, - {MNG_FN_FREE_ANI_SRGB, "free_ani_srgb"}, - {MNG_FN_FREE_ANI_ICCP, "free_ani_iccp"}, - {MNG_FN_FREE_ANI_PLTE, "free_ani_plte"}, - {MNG_FN_FREE_ANI_TRNS, "free_ani_trns"}, - {MNG_FN_FREE_ANI_BKGD, "free_ani_bkgd"}, -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_FREE_ANI_DHDR, "free_ani_dhdr"}, - {MNG_FN_FREE_ANI_PROM, "free_ani_prom"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_FREE_ANI_IPNG, "free_ani_ipng"}, -#endif - {MNG_FN_FREE_ANI_IJNG, "free_ani_ijng"}, - {MNG_FN_FREE_ANI_PPLT, "free_ani_pplt"}, -#endif - {MNG_FN_FREE_ANI_MAGN, "free_ani_magn"}, - - {MNG_FN_FREE_ANI_IMAGE, "free_ani_image"}, - {MNG_FN_FREE_EVENT, "free_event"}, - - {MNG_FN_PROCESS_ANI_LOOP, "process_ani_loop"}, - {MNG_FN_PROCESS_ANI_ENDL, "process_ani_endl"}, - {MNG_FN_PROCESS_ANI_DEFI, "process_ani_defi"}, - {MNG_FN_PROCESS_ANI_BASI, "process_ani_basi"}, - {MNG_FN_PROCESS_ANI_CLON, "process_ani_clon"}, -#ifndef MNG_SKIPCHUNK_PAST - {MNG_FN_PROCESS_ANI_PAST, "process_ani_past"}, -#endif - {MNG_FN_PROCESS_ANI_DISC, "process_ani_disc"}, - {MNG_FN_PROCESS_ANI_BACK, "process_ani_back"}, - {MNG_FN_PROCESS_ANI_FRAM, "process_ani_fram"}, - {MNG_FN_PROCESS_ANI_MOVE, "process_ani_move"}, - {MNG_FN_PROCESS_ANI_CLIP, "process_ani_clip"}, - {MNG_FN_PROCESS_ANI_SHOW, "process_ani_show"}, - {MNG_FN_PROCESS_ANI_TERM, "process_ani_term"}, - {MNG_FN_PROCESS_ANI_SAVE, "process_ani_save"}, - {MNG_FN_PROCESS_ANI_SEEK, "process_ani_seek"}, - {MNG_FN_PROCESS_ANI_GAMA, "process_ani_gama"}, - {MNG_FN_PROCESS_ANI_CHRM, "process_ani_chrm"}, - {MNG_FN_PROCESS_ANI_SRGB, "process_ani_srgb"}, - {MNG_FN_PROCESS_ANI_ICCP, "process_ani_iccp"}, - {MNG_FN_PROCESS_ANI_PLTE, "process_ani_plte"}, - {MNG_FN_PROCESS_ANI_TRNS, "process_ani_trns"}, - {MNG_FN_PROCESS_ANI_BKGD, "process_ani_bkgd"}, -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_PROCESS_ANI_DHDR, "process_ani_dhdr"}, - {MNG_FN_PROCESS_ANI_PROM, "process_ani_prom"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_PROCESS_ANI_IPNG, "process_ani_ipng"}, -#endif - {MNG_FN_PROCESS_ANI_IJNG, "process_ani_ijng"}, - {MNG_FN_PROCESS_ANI_PPLT, "process_ani_pplt"}, -#endif - {MNG_FN_PROCESS_ANI_MAGN, "process_ani_magn"}, - - {MNG_FN_PROCESS_ANI_IMAGE, "process_ani_image"}, - {MNG_FN_PROCESS_EVENT, "process_event"}, - - {MNG_FN_RESTORE_BACKIMAGE, "restore_backimage"}, - {MNG_FN_RESTORE_BACKCOLOR, "restore_backcolor"}, - {MNG_FN_RESTORE_BGCOLOR, "restore_bgcolor"}, - {MNG_FN_RESTORE_RGB8, "restore_rgb8"}, - {MNG_FN_RESTORE_BGR8, "restore_bgr8"}, - {MNG_FN_RESTORE_BKGD, "restore_bkgd"}, - {MNG_FN_RESTORE_BGRX8, "restore_bgrx8"}, - {MNG_FN_RESTORE_RGB565, "restore_rgb565"}, - - {MNG_FN_INIT_IHDR, "init_ihdr"}, - {MNG_FN_INIT_PLTE, "init_plte"}, - {MNG_FN_INIT_IDAT, "init_idat"}, - {MNG_FN_INIT_IEND, "init_iend"}, - {MNG_FN_INIT_TRNS, "init_trns"}, - {MNG_FN_INIT_GAMA, "init_gama"}, - {MNG_FN_INIT_CHRM, "init_chrm"}, - {MNG_FN_INIT_SRGB, "init_srgb"}, - {MNG_FN_INIT_ICCP, "init_iccp"}, - {MNG_FN_INIT_TEXT, "init_text"}, - {MNG_FN_INIT_ZTXT, "init_ztxt"}, - {MNG_FN_INIT_ITXT, "init_itxt"}, - {MNG_FN_INIT_BKGD, "init_bkgd"}, - {MNG_FN_INIT_PHYS, "init_phys"}, - {MNG_FN_INIT_SBIT, "init_sbit"}, - {MNG_FN_INIT_SPLT, "init_splt"}, - {MNG_FN_INIT_HIST, "init_hist"}, - {MNG_FN_INIT_TIME, "init_time"}, - {MNG_FN_INIT_MHDR, "init_mhdr"}, - {MNG_FN_INIT_MEND, "init_mend"}, - {MNG_FN_INIT_LOOP, "init_loop"}, - {MNG_FN_INIT_ENDL, "init_endl"}, - {MNG_FN_INIT_DEFI, "init_defi"}, - {MNG_FN_INIT_BASI, "init_basi"}, - {MNG_FN_INIT_CLON, "init_clon"}, -#ifndef MNG_SKIPCHUNK_PAST - {MNG_FN_INIT_PAST, "init_past"}, -#endif - {MNG_FN_INIT_DISC, "init_disc"}, - {MNG_FN_INIT_BACK, "init_back"}, - {MNG_FN_INIT_FRAM, "init_fram"}, - {MNG_FN_INIT_MOVE, "init_move"}, - {MNG_FN_INIT_CLIP, "init_clip"}, - {MNG_FN_INIT_SHOW, "init_show"}, - {MNG_FN_INIT_TERM, "init_term"}, - {MNG_FN_INIT_SAVE, "init_save"}, - {MNG_FN_INIT_SEEK, "init_seek"}, - {MNG_FN_INIT_EXPI, "init_expi"}, - {MNG_FN_INIT_FPRI, "init_fpri"}, - {MNG_FN_INIT_NEED, "init_need"}, - {MNG_FN_INIT_PHYG, "init_phyg"}, -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_INIT_JHDR, "init_jhdr"}, - {MNG_FN_INIT_JDAT, "init_jdat"}, - {MNG_FN_INIT_JSEP, "init_jsep"}, -#endif -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_INIT_DHDR, "init_dhdr"}, - {MNG_FN_INIT_PROM, "init_prom"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_INIT_IPNG, "init_ipng"}, -#endif - {MNG_FN_INIT_PPLT, "init_pplt"}, - {MNG_FN_INIT_IJNG, "init_ijng"}, - {MNG_FN_INIT_DROP, "init_drop"}, - {MNG_FN_INIT_DBYK, "init_dbyk"}, - {MNG_FN_INIT_ORDR, "init_ordr"}, -#endif - {MNG_FN_INIT_UNKNOWN, "init_unknown"}, - {MNG_FN_INIT_MAGN, "init_magn"}, - {MNG_FN_INIT_JDAA, "init_jdaa"}, - {MNG_FN_INIT_EVNT, "init_evnt"}, -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - {MNG_FN_INIT_MPNG, "init_mpng"}, -#endif - - {MNG_FN_ASSIGN_IHDR, "assign_ihdr"}, - {MNG_FN_ASSIGN_PLTE, "assign_plte"}, - {MNG_FN_ASSIGN_IDAT, "assign_idat"}, - {MNG_FN_ASSIGN_IEND, "assign_iend"}, - {MNG_FN_ASSIGN_TRNS, "assign_trns"}, - {MNG_FN_ASSIGN_GAMA, "assign_gama"}, - {MNG_FN_ASSIGN_CHRM, "assign_chrm"}, - {MNG_FN_ASSIGN_SRGB, "assign_srgb"}, - {MNG_FN_ASSIGN_ICCP, "assign_iccp"}, - {MNG_FN_ASSIGN_TEXT, "assign_text"}, - {MNG_FN_ASSIGN_ZTXT, "assign_ztxt"}, - {MNG_FN_ASSIGN_ITXT, "assign_itxt"}, - {MNG_FN_ASSIGN_BKGD, "assign_bkgd"}, - {MNG_FN_ASSIGN_PHYS, "assign_phys"}, - {MNG_FN_ASSIGN_SBIT, "assign_sbit"}, - {MNG_FN_ASSIGN_SPLT, "assign_splt"}, - {MNG_FN_ASSIGN_HIST, "assign_hist"}, - {MNG_FN_ASSIGN_TIME, "assign_time"}, - {MNG_FN_ASSIGN_MHDR, "assign_mhdr"}, - {MNG_FN_ASSIGN_MEND, "assign_mend"}, - {MNG_FN_ASSIGN_LOOP, "assign_loop"}, - {MNG_FN_ASSIGN_ENDL, "assign_endl"}, - {MNG_FN_ASSIGN_DEFI, "assign_defi"}, - {MNG_FN_ASSIGN_BASI, "assign_basi"}, - {MNG_FN_ASSIGN_CLON, "assign_clon"}, -#ifndef MNG_SKIPCHUNK_PAST - {MNG_FN_ASSIGN_PAST, "assign_past"}, -#endif - {MNG_FN_ASSIGN_DISC, "assign_disc"}, - {MNG_FN_ASSIGN_BACK, "assign_back"}, - {MNG_FN_ASSIGN_FRAM, "assign_fram"}, - {MNG_FN_ASSIGN_MOVE, "assign_move"}, - {MNG_FN_ASSIGN_CLIP, "assign_clip"}, - {MNG_FN_ASSIGN_SHOW, "assign_show"}, - {MNG_FN_ASSIGN_TERM, "assign_term"}, - {MNG_FN_ASSIGN_SAVE, "assign_save"}, - {MNG_FN_ASSIGN_SEEK, "assign_seek"}, - {MNG_FN_ASSIGN_EXPI, "assign_expi"}, - {MNG_FN_ASSIGN_FPRI, "assign_fpri"}, - {MNG_FN_ASSIGN_NEED, "assign_need"}, - {MNG_FN_ASSIGN_PHYG, "assign_phyg"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_ASSIGN_JHDR, "assign_jhdr"}, - {MNG_FN_ASSIGN_JDAT, "assign_jdat"}, - {MNG_FN_ASSIGN_JSEP, "assign_jsep"}, -#endif -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_ASSIGN_DHDR, "assign_dhdr"}, - {MNG_FN_ASSIGN_PROM, "assign_prom"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_ASSIGN_IPNG, "assign_ipng"}, -#endif - {MNG_FN_ASSIGN_PPLT, "assign_pplt"}, - {MNG_FN_ASSIGN_IJNG, "assign_ijng"}, - {MNG_FN_ASSIGN_DROP, "assign_drop"}, - {MNG_FN_ASSIGN_DBYK, "assign_dbyk"}, - {MNG_FN_ASSIGN_ORDR, "assign_ordr"}, -#endif - {MNG_FN_ASSIGN_UNKNOWN, "assign_unknown"}, - {MNG_FN_ASSIGN_MAGN, "assign_magn"}, - {MNG_FN_ASSIGN_JDAA, "assign_jdaa"}, - {MNG_FN_ASSIGN_EVNT, "assign_evnt"}, -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - {MNG_FN_ASSIGN_MPNG, "assign_mpng"}, -#endif - - {MNG_FN_FREE_IHDR, "free_ihdr"}, - {MNG_FN_FREE_PLTE, "free_plte"}, - {MNG_FN_FREE_IDAT, "free_idat"}, - {MNG_FN_FREE_IEND, "free_iend"}, - {MNG_FN_FREE_TRNS, "free_trns"}, - {MNG_FN_FREE_GAMA, "free_gama"}, - {MNG_FN_FREE_CHRM, "free_chrm"}, - {MNG_FN_FREE_SRGB, "free_srgb"}, - {MNG_FN_FREE_ICCP, "free_iccp"}, - {MNG_FN_FREE_TEXT, "free_text"}, - {MNG_FN_FREE_ZTXT, "free_ztxt"}, - {MNG_FN_FREE_ITXT, "free_itxt"}, - {MNG_FN_FREE_BKGD, "free_bkgd"}, - {MNG_FN_FREE_PHYS, "free_phys"}, - {MNG_FN_FREE_SBIT, "free_sbit"}, - {MNG_FN_FREE_SPLT, "free_splt"}, - {MNG_FN_FREE_HIST, "free_hist"}, - {MNG_FN_FREE_TIME, "free_time"}, - {MNG_FN_FREE_MHDR, "free_mhdr"}, - {MNG_FN_FREE_MEND, "free_mend"}, - {MNG_FN_FREE_LOOP, "free_loop"}, - {MNG_FN_FREE_ENDL, "free_endl"}, - {MNG_FN_FREE_DEFI, "free_defi"}, - {MNG_FN_FREE_BASI, "free_basi"}, - {MNG_FN_FREE_CLON, "free_clon"}, -#ifndef MNG_SKIPCHUNK_PAST - {MNG_FN_FREE_PAST, "free_past"}, -#endif - {MNG_FN_FREE_DISC, "free_disc"}, - {MNG_FN_FREE_BACK, "free_back"}, - {MNG_FN_FREE_FRAM, "free_fram"}, - {MNG_FN_FREE_MOVE, "free_move"}, - {MNG_FN_FREE_CLIP, "free_clip"}, - {MNG_FN_FREE_SHOW, "free_show"}, - {MNG_FN_FREE_TERM, "free_term"}, - {MNG_FN_FREE_SAVE, "free_save"}, - {MNG_FN_FREE_SEEK, "free_seek"}, - {MNG_FN_FREE_EXPI, "free_expi"}, - {MNG_FN_FREE_FPRI, "free_fpri"}, - {MNG_FN_FREE_NEED, "free_need"}, - {MNG_FN_FREE_PHYG, "free_phyg"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_FREE_JHDR, "free_jhdr"}, - {MNG_FN_FREE_JDAT, "free_jdat"}, - {MNG_FN_FREE_JSEP, "free_jsep"}, -#endif -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_FREE_DHDR, "free_dhdr"}, - {MNG_FN_FREE_PROM, "free_prom"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_FREE_IPNG, "free_ipng"}, -#endif - {MNG_FN_FREE_PPLT, "free_pplt"}, - {MNG_FN_FREE_IJNG, "free_ijng"}, - {MNG_FN_FREE_DROP, "free_drop"}, - {MNG_FN_FREE_DBYK, "free_dbyk"}, - {MNG_FN_FREE_ORDR, "free_ordr"}, -#endif - {MNG_FN_FREE_UNKNOWN, "free_unknown"}, - {MNG_FN_FREE_MAGN, "free_magn"}, - {MNG_FN_FREE_JDAA, "free_jdaa"}, - {MNG_FN_FREE_EVNT, "free_evnt"}, -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - {MNG_FN_FREE_MPNG, "free_mpng"}, -#endif - - {MNG_FN_READ_IHDR, "read_ihdr"}, - {MNG_FN_READ_PLTE, "read_plte"}, - {MNG_FN_READ_IDAT, "read_idat"}, - {MNG_FN_READ_IEND, "read_iend"}, - {MNG_FN_READ_TRNS, "read_trns"}, - {MNG_FN_READ_GAMA, "read_gama"}, - {MNG_FN_READ_CHRM, "read_chrm"}, - {MNG_FN_READ_SRGB, "read_srgb"}, - {MNG_FN_READ_ICCP, "read_iccp"}, - {MNG_FN_READ_TEXT, "read_text"}, - {MNG_FN_READ_ZTXT, "read_ztxt"}, - {MNG_FN_READ_ITXT, "read_itxt"}, - {MNG_FN_READ_BKGD, "read_bkgd"}, - {MNG_FN_READ_PHYS, "read_phys"}, - {MNG_FN_READ_SBIT, "read_sbit"}, - {MNG_FN_READ_SPLT, "read_splt"}, - {MNG_FN_READ_HIST, "read_hist"}, - {MNG_FN_READ_TIME, "read_time"}, - {MNG_FN_READ_MHDR, "read_mhdr"}, - {MNG_FN_READ_MEND, "read_mend"}, - {MNG_FN_READ_LOOP, "read_loop"}, - {MNG_FN_READ_ENDL, "read_endl"}, - {MNG_FN_READ_DEFI, "read_defi"}, - {MNG_FN_READ_BASI, "read_basi"}, - {MNG_FN_READ_CLON, "read_clon"}, -#ifndef MNG_SKIPCHUNK_PAST - {MNG_FN_READ_PAST, "read_past"}, -#endif - {MNG_FN_READ_DISC, "read_disc"}, - {MNG_FN_READ_BACK, "read_back"}, - {MNG_FN_READ_FRAM, "read_fram"}, - {MNG_FN_READ_MOVE, "read_move"}, - {MNG_FN_READ_CLIP, "read_clip"}, - {MNG_FN_READ_SHOW, "read_show"}, - {MNG_FN_READ_TERM, "read_term"}, - {MNG_FN_READ_SAVE, "read_save"}, - {MNG_FN_READ_SEEK, "read_seek"}, - {MNG_FN_READ_EXPI, "read_expi"}, - {MNG_FN_READ_FPRI, "read_fpri"}, - {MNG_FN_READ_NEED, "read_need"}, - {MNG_FN_READ_PHYG, "read_phyg"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_READ_JHDR, "read_jhdr"}, - {MNG_FN_READ_JDAT, "read_jdat"}, - {MNG_FN_READ_JSEP, "read_jsep"}, -#endif -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_READ_DHDR, "read_dhdr"}, - {MNG_FN_READ_PROM, "read_prom"}, - {MNG_FN_READ_IPNG, "read_ipng"}, - {MNG_FN_READ_PPLT, "read_pplt"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_READ_IJNG, "read_ijng"}, -#endif - {MNG_FN_READ_DROP, "read_drop"}, - {MNG_FN_READ_DBYK, "read_dbyk"}, - {MNG_FN_READ_ORDR, "read_ordr"}, -#endif - {MNG_FN_READ_UNKNOWN, "read_unknown"}, - {MNG_FN_READ_MAGN, "read_magn"}, - {MNG_FN_READ_JDAA, "read_jdaa"}, - {MNG_FN_READ_EVNT, "read_evnt"}, -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - {MNG_FN_READ_MPNG, "read_mpng"}, -#endif - - {MNG_FN_WRITE_IHDR, "write_ihdr"}, - {MNG_FN_WRITE_PLTE, "write_plte"}, - {MNG_FN_WRITE_IDAT, "write_idat"}, - {MNG_FN_WRITE_IEND, "write_iend"}, - {MNG_FN_WRITE_TRNS, "write_trns"}, - {MNG_FN_WRITE_GAMA, "write_gama"}, - {MNG_FN_WRITE_CHRM, "write_chrm"}, - {MNG_FN_WRITE_SRGB, "write_srgb"}, - {MNG_FN_WRITE_ICCP, "write_iccp"}, - {MNG_FN_WRITE_TEXT, "write_text"}, - {MNG_FN_WRITE_ZTXT, "write_ztxt"}, - {MNG_FN_WRITE_ITXT, "write_itxt"}, - {MNG_FN_WRITE_BKGD, "write_bkgd"}, - {MNG_FN_WRITE_PHYS, "write_phys"}, - {MNG_FN_WRITE_SBIT, "write_sbit"}, - {MNG_FN_WRITE_SPLT, "write_splt"}, - {MNG_FN_WRITE_HIST, "write_hist"}, - {MNG_FN_WRITE_TIME, "write_time"}, - {MNG_FN_WRITE_MHDR, "write_mhdr"}, - {MNG_FN_WRITE_MEND, "write_mend"}, - {MNG_FN_WRITE_LOOP, "write_loop"}, - {MNG_FN_WRITE_ENDL, "write_endl"}, - {MNG_FN_WRITE_DEFI, "write_defi"}, - {MNG_FN_WRITE_BASI, "write_basi"}, - {MNG_FN_WRITE_CLON, "write_clon"}, -#ifndef MNG_SKIPCHUNK_PAST - {MNG_FN_WRITE_PAST, "write_past"}, -#endif - {MNG_FN_WRITE_DISC, "write_disc"}, - {MNG_FN_WRITE_BACK, "write_back"}, - {MNG_FN_WRITE_FRAM, "write_fram"}, - {MNG_FN_WRITE_MOVE, "write_move"}, - {MNG_FN_WRITE_CLIP, "write_clip"}, - {MNG_FN_WRITE_SHOW, "write_show"}, - {MNG_FN_WRITE_TERM, "write_term"}, - {MNG_FN_WRITE_SAVE, "write_save"}, - {MNG_FN_WRITE_SEEK, "write_seek"}, - {MNG_FN_WRITE_EXPI, "write_expi"}, - {MNG_FN_WRITE_FPRI, "write_fpri"}, - {MNG_FN_WRITE_NEED, "write_need"}, - {MNG_FN_WRITE_PHYG, "write_phyg"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_WRITE_JHDR, "write_jhdr"}, - {MNG_FN_WRITE_JDAT, "write_jdat"}, - {MNG_FN_WRITE_JSEP, "write_jsep"}, -#endif -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_WRITE_DHDR, "write_dhdr"}, - {MNG_FN_WRITE_PROM, "write_prom"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_WRITE_IPNG, "write_ipng"}, -#endif - {MNG_FN_WRITE_PPLT, "write_pplt"}, - {MNG_FN_WRITE_IJNG, "write_ijng"}, - {MNG_FN_WRITE_DROP, "write_drop"}, - {MNG_FN_WRITE_DBYK, "write_dbyk"}, - {MNG_FN_WRITE_ORDR, "write_ordr"}, -#endif - {MNG_FN_WRITE_UNKNOWN, "write_unknown"}, - {MNG_FN_WRITE_MAGN, "write_magn"}, - {MNG_FN_WRITE_JDAA, "write_jdaa"}, - {MNG_FN_WRITE_EVNT, "write_evnt"}, -#ifdef MNG_INCLUDE_MPNG_PROPOSAL - {MNG_FN_WRITE_MPNG, "write_mpng"}, -#endif - - {MNG_FN_ZLIB_INITIALIZE, "zlib_initialize"}, - {MNG_FN_ZLIB_CLEANUP, "zlib_cleanup"}, - {MNG_FN_ZLIB_INFLATEINIT, "zlib_inflateinit"}, - {MNG_FN_ZLIB_INFLATEROWS, "zlib_inflaterows"}, - {MNG_FN_ZLIB_INFLATEDATA, "zlib_inflatedata"}, - {MNG_FN_ZLIB_INFLATEFREE, "zlib_inflatefree"}, - {MNG_FN_ZLIB_DEFLATEINIT, "zlib_deflateinit"}, - {MNG_FN_ZLIB_DEFLATEROWS, "zlib_deflaterows"}, - {MNG_FN_ZLIB_DEFLATEDATA, "zlib_deflatedata"}, - {MNG_FN_ZLIB_DEFLATEFREE, "zlib_deflatefree"}, - - {MNG_FN_PROCESS_DISPLAY_IHDR, "process_display_ihdr"}, - {MNG_FN_PROCESS_DISPLAY_PLTE, "process_display_plte"}, - {MNG_FN_PROCESS_DISPLAY_IDAT, "process_display_idat"}, - {MNG_FN_PROCESS_DISPLAY_IEND, "process_display_iend"}, - {MNG_FN_PROCESS_DISPLAY_TRNS, "process_display_trns"}, - {MNG_FN_PROCESS_DISPLAY_GAMA, "process_display_gama"}, - {MNG_FN_PROCESS_DISPLAY_CHRM, "process_display_chrm"}, - {MNG_FN_PROCESS_DISPLAY_SRGB, "process_display_srgb"}, - {MNG_FN_PROCESS_DISPLAY_ICCP, "process_display_iccp"}, - {MNG_FN_PROCESS_DISPLAY_BKGD, "process_display_bkgd"}, - {MNG_FN_PROCESS_DISPLAY_PHYS, "process_display_phys"}, - {MNG_FN_PROCESS_DISPLAY_SBIT, "process_display_sbit"}, - {MNG_FN_PROCESS_DISPLAY_SPLT, "process_display_splt"}, - {MNG_FN_PROCESS_DISPLAY_HIST, "process_display_hist"}, - {MNG_FN_PROCESS_DISPLAY_MHDR, "process_display_mhdr"}, - {MNG_FN_PROCESS_DISPLAY_MEND, "process_display_mend"}, - {MNG_FN_PROCESS_DISPLAY_LOOP, "process_display_loop"}, - {MNG_FN_PROCESS_DISPLAY_ENDL, "process_display_endl"}, - {MNG_FN_PROCESS_DISPLAY_DEFI, "process_display_defi"}, - {MNG_FN_PROCESS_DISPLAY_BASI, "process_display_basi"}, - {MNG_FN_PROCESS_DISPLAY_CLON, "process_display_clon"}, -#ifndef MNG_SKIPCHUNK_PAST - {MNG_FN_PROCESS_DISPLAY_PAST, "process_display_past"}, -#endif - {MNG_FN_PROCESS_DISPLAY_DISC, "process_display_disc"}, - {MNG_FN_PROCESS_DISPLAY_BACK, "process_display_back"}, - {MNG_FN_PROCESS_DISPLAY_FRAM, "process_display_fram"}, - {MNG_FN_PROCESS_DISPLAY_MOVE, "process_display_move"}, - {MNG_FN_PROCESS_DISPLAY_CLIP, "process_display_clip"}, - {MNG_FN_PROCESS_DISPLAY_SHOW, "process_display_show"}, - {MNG_FN_PROCESS_DISPLAY_TERM, "process_display_term"}, - {MNG_FN_PROCESS_DISPLAY_SAVE, "process_display_save"}, - {MNG_FN_PROCESS_DISPLAY_SEEK, "process_display_seek"}, - {MNG_FN_PROCESS_DISPLAY_EXPI, "process_display_expi"}, - {MNG_FN_PROCESS_DISPLAY_FPRI, "process_display_fpri"}, - {MNG_FN_PROCESS_DISPLAY_NEED, "process_display_need"}, - {MNG_FN_PROCESS_DISPLAY_PHYG, "process_display_phyg"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_PROCESS_DISPLAY_JHDR, "process_display_jhdr"}, - {MNG_FN_PROCESS_DISPLAY_JDAT, "process_display_jdat"}, - {MNG_FN_PROCESS_DISPLAY_JSEP, "process_display_jsep"}, -#endif -#ifndef MNG_NO_DELTA_PNG - {MNG_FN_PROCESS_DISPLAY_DHDR, "process_display_dhdr"}, - {MNG_FN_PROCESS_DISPLAY_PROM, "process_display_prom"}, -#ifdef MNG_INCLUDE_JNG - {MNG_FN_PROCESS_DISPLAY_IPNG, "process_display_ipng"}, -#endif - {MNG_FN_PROCESS_DISPLAY_PPLT, "process_display_pplt"}, - {MNG_FN_PROCESS_DISPLAY_IJNG, "process_display_ijng"}, - {MNG_FN_PROCESS_DISPLAY_DROP, "process_display_drop"}, - {MNG_FN_PROCESS_DISPLAY_DBYK, "process_display_dbyk"}, - {MNG_FN_PROCESS_DISPLAY_ORDR, "process_display_ordr"}, -#endif - {MNG_FN_PROCESS_DISPLAY_MAGN, "process_display_magn"}, - {MNG_FN_PROCESS_DISPLAY_JDAA, "process_display_jdaa"}, - - {MNG_FN_JPEG_INITIALIZE, "jpeg_initialize"}, - {MNG_FN_JPEG_CLEANUP, "jpeg_cleanup"}, - {MNG_FN_JPEG_DECOMPRESSINIT, "jpeg_decompressinit"}, - {MNG_FN_JPEG_DECOMPRESSDATA, "jpeg_decompressdata"}, - {MNG_FN_JPEG_DECOMPRESSFREE, "jpeg_decompressfree"}, - - {MNG_FN_STORE_JPEG_G8, "store_jpeg_g8"}, - {MNG_FN_STORE_JPEG_RGB8, "store_jpeg_rgb8"}, - {MNG_FN_STORE_JPEG_G12, "store_jpeg_g12"}, - {MNG_FN_STORE_JPEG_RGB12, "store_jpeg_rgb12"}, - {MNG_FN_STORE_JPEG_GA8, "store_jpeg_ga8"}, - {MNG_FN_STORE_JPEG_RGBA8, "store_jpeg_rgba8"}, - {MNG_FN_STORE_JPEG_GA12, "store_jpeg_ga12"}, - {MNG_FN_STORE_JPEG_RGBA12, "store_jpeg_rgba12"}, - {MNG_FN_STORE_JPEG_G8_ALPHA, "store_jpeg_g8_alpha"}, - {MNG_FN_STORE_JPEG_RGB8_ALPHA, "store_jpeg_rgb8_alpha"}, - - {MNG_FN_INIT_JPEG_A1_NI, "init_jpeg_a1_ni"}, - {MNG_FN_INIT_JPEG_A2_NI, "init_jpeg_a2_ni"}, - {MNG_FN_INIT_JPEG_A4_NI, "init_jpeg_a4_ni"}, - {MNG_FN_INIT_JPEG_A8_NI, "init_jpeg_a8_ni"}, - {MNG_FN_INIT_JPEG_A16_NI, "init_jpeg_a16_ni"}, - - {MNG_FN_STORE_JPEG_G8_A1, "store_jpeg_g8_a1"}, - {MNG_FN_STORE_JPEG_G8_A2, "store_jpeg_g8_a2"}, - {MNG_FN_STORE_JPEG_G8_A4, "store_jpeg_g8_a4"}, - {MNG_FN_STORE_JPEG_G8_A8, "store_jpeg_g8_a8"}, - {MNG_FN_STORE_JPEG_G8_A16, "store_jpeg_g8_a16"}, - - {MNG_FN_STORE_JPEG_RGB8_A1, "store_jpeg_rgb8_a1"}, - {MNG_FN_STORE_JPEG_RGB8_A2, "store_jpeg_rgb8_a2"}, - {MNG_FN_STORE_JPEG_RGB8_A4, "store_jpeg_rgb8_a4"}, - {MNG_FN_STORE_JPEG_RGB8_A8, "store_jpeg_rgb8_a8"}, - {MNG_FN_STORE_JPEG_RGB8_A16, "store_jpeg_rgb8_a16"}, - - {MNG_FN_STORE_JPEG_G12_A1, "store_jpeg_g12_a1"}, - {MNG_FN_STORE_JPEG_G12_A2, "store_jpeg_g12_a2"}, - {MNG_FN_STORE_JPEG_G12_A4, "store_jpeg_g12_a4"}, - {MNG_FN_STORE_JPEG_G12_A8, "store_jpeg_g12_a8"}, - {MNG_FN_STORE_JPEG_G12_A16, "store_jpeg_g12_a16"}, - - {MNG_FN_STORE_JPEG_RGB12_A1, "store_jpeg_rgb12_a1"}, - {MNG_FN_STORE_JPEG_RGB12_A2, "store_jpeg_rgb12_a2"}, - {MNG_FN_STORE_JPEG_RGB12_A4, "store_jpeg_rgb12_a4"}, - {MNG_FN_STORE_JPEG_RGB12_A8, "store_jpeg_rgb12_a8"}, - {MNG_FN_STORE_JPEG_RGB12_A16, "store_jpeg_rgb12_a16"}, - - {MNG_FN_NEXT_JPEG_ALPHAROW, "next_jpeg_alpharow"}, - {MNG_FN_NEXT_JPEG_ROW, "next_jpeg_row"}, - {MNG_FN_DISPLAY_JPEG_ROWS, "display_jpeg_rows"}, - - {MNG_FN_MAGNIFY_G8_X1, "magnify_g8_x1"}, - {MNG_FN_MAGNIFY_G8_X2, "magnify_g8_x2"}, - {MNG_FN_MAGNIFY_RGB8_X1, "magnify_rgb8_x1"}, - {MNG_FN_MAGNIFY_RGB8_X2, "magnify_rgb8_x2"}, - {MNG_FN_MAGNIFY_GA8_X1, "magnify_ga8_x1"}, - {MNG_FN_MAGNIFY_GA8_X2, "magnify_ga8_x2"}, - {MNG_FN_MAGNIFY_GA8_X3, "magnify_ga8_x3"}, - {MNG_FN_MAGNIFY_GA8_X4, "magnify_ga8_x4"}, - {MNG_FN_MAGNIFY_RGBA8_X1, "magnify_rgba8_x1"}, - {MNG_FN_MAGNIFY_RGBA8_X2, "magnify_rgba8_x2"}, - {MNG_FN_MAGNIFY_RGBA8_X3, "magnify_rgba8_x3"}, - {MNG_FN_MAGNIFY_RGBA8_X4, "magnify_rgba8_x4"}, - {MNG_FN_MAGNIFY_G8_X3, "magnify_g8_x3"}, - {MNG_FN_MAGNIFY_RGB8_X3, "magnify_rgb8_x3"}, - {MNG_FN_MAGNIFY_GA8_X5, "magnify_ga8_x5"}, - {MNG_FN_MAGNIFY_RGBA8_X5, "magnify_rgba8_x5"}, - - {MNG_FN_MAGNIFY_G8_Y1, "magnify_g8_y1"}, - {MNG_FN_MAGNIFY_G8_Y2, "magnify_g8_y2"}, - {MNG_FN_MAGNIFY_RGB8_Y1, "magnify_rgb8_y1"}, - {MNG_FN_MAGNIFY_RGB8_Y2, "magnify_rgb8_y2"}, - {MNG_FN_MAGNIFY_GA8_Y1, "magnify_ga8_y1"}, - {MNG_FN_MAGNIFY_GA8_Y2, "magnify_ga8_y2"}, - {MNG_FN_MAGNIFY_GA8_Y3, "magnify_ga8_y3"}, - {MNG_FN_MAGNIFY_GA8_Y4, "magnify_ga8_y4"}, - {MNG_FN_MAGNIFY_RGBA8_Y1, "magnify_rgba8_y1"}, - {MNG_FN_MAGNIFY_RGBA8_Y2, "magnify_rgba8_y2"}, - {MNG_FN_MAGNIFY_RGBA8_Y3, "magnify_rgba8_y3"}, - {MNG_FN_MAGNIFY_RGBA8_Y4, "magnify_rgba8_y4"}, - {MNG_FN_MAGNIFY_G8_Y3, "magnify_g8_y3"}, - {MNG_FN_MAGNIFY_RGB8_Y3, "magnify_rgb8_y3"}, - {MNG_FN_MAGNIFY_GA8_Y5, "magnify_ga8_y5"}, - {MNG_FN_MAGNIFY_RGBA8_Y5, "magnify_rgba8_y5"}, - - {MNG_FN_MAGNIFY_G8_X1, "magnify_g8_x1"}, - {MNG_FN_MAGNIFY_G8_X2, "magnify_g8_x2"}, - {MNG_FN_MAGNIFY_RGB8_X1, "magnify_rgb8_x1"}, - {MNG_FN_MAGNIFY_RGB8_X2, "magnify_rgb8_x2"}, - {MNG_FN_MAGNIFY_GA8_X1, "magnify_ga8_x1"}, - {MNG_FN_MAGNIFY_GA8_X2, "magnify_ga8_x2"}, - {MNG_FN_MAGNIFY_GA8_X3, "magnify_ga8_x3"}, - {MNG_FN_MAGNIFY_GA8_X4, "magnify_ga8_x4"}, - {MNG_FN_MAGNIFY_RGBA8_X1, "magnify_rgba8_x1"}, - {MNG_FN_MAGNIFY_RGBA8_X2, "magnify_rgba8_x2"}, - {MNG_FN_MAGNIFY_RGBA8_X3, "magnify_rgba8_x3"}, - {MNG_FN_MAGNIFY_RGBA8_X4, "magnify_rgba8_x4"}, - {MNG_FN_MAGNIFY_G8_X3, "magnify_g8_x3"}, - {MNG_FN_MAGNIFY_RGB8_X3, "magnify_rgb8_x3"}, - {MNG_FN_MAGNIFY_GA8_X5, "magnify_ga8_x5"}, - {MNG_FN_MAGNIFY_RGBA8_X5, "magnify_rgba8_x5"}, - - {MNG_FN_MAGNIFY_G8_Y1, "magnify_g8_y1"}, - {MNG_FN_MAGNIFY_G8_Y2, "magnify_g8_y2"}, - {MNG_FN_MAGNIFY_RGB8_Y1, "magnify_rgb8_y1"}, - {MNG_FN_MAGNIFY_RGB8_Y2, "magnify_rgb8_y2"}, - {MNG_FN_MAGNIFY_GA8_Y1, "magnify_ga8_y1"}, - {MNG_FN_MAGNIFY_GA8_Y2, "magnify_ga8_y2"}, - {MNG_FN_MAGNIFY_GA8_Y3, "magnify_ga8_y3"}, - {MNG_FN_MAGNIFY_GA8_Y4, "magnify_ga8_y4"}, - {MNG_FN_MAGNIFY_RGBA8_Y1, "magnify_rgba8_y1"}, - {MNG_FN_MAGNIFY_RGBA8_Y2, "magnify_rgba8_y2"}, - {MNG_FN_MAGNIFY_RGBA8_Y3, "magnify_rgba8_y3"}, - {MNG_FN_MAGNIFY_RGBA8_Y4, "magnify_rgba8_y4"}, - {MNG_FN_MAGNIFY_G8_Y3, "magnify_g8_y3"}, - {MNG_FN_MAGNIFY_RGB8_Y3, "magnify_rgb8_y3"}, - {MNG_FN_MAGNIFY_GA8_Y5, "magnify_ga8_y5"}, - {MNG_FN_MAGNIFY_RGBA8_Y5, "magnify_rgba8_y5"}, - - {MNG_FN_DELTA_G1_G1, "delta_g1_g1"}, - {MNG_FN_DELTA_G2_G2, "delta_g2_g2"}, - {MNG_FN_DELTA_G4_G4, "delta_g4_g4"}, - {MNG_FN_DELTA_G8_G8, "delta_g8_g8"}, - {MNG_FN_DELTA_G16_G16, "delta_g16_g16"}, - {MNG_FN_DELTA_RGB8_RGB8, "delta_rgb8_rgb8"}, - {MNG_FN_DELTA_RGB16_RGB16, "delta_rgb16_rgb16"}, - {MNG_FN_DELTA_GA8_GA8, "delta_ga8_ga8"}, - {MNG_FN_DELTA_GA8_G8, "delta_ga8_g8"}, - {MNG_FN_DELTA_GA8_A8, "delta_ga8_a8"}, - {MNG_FN_DELTA_GA16_GA16, "delta_ga16_ga16"}, - {MNG_FN_DELTA_GA16_G16, "delta_ga16_g16"}, - {MNG_FN_DELTA_GA16_A16, "delta_ga16_a16"}, - {MNG_FN_DELTA_RGBA8_RGBA8, "delta_rgba8_rgba8"}, - {MNG_FN_DELTA_RGBA8_RGB8, "delta_rgba8_rgb8"}, - {MNG_FN_DELTA_RGBA8_A8, "delta_rgba8_a8"}, - {MNG_FN_DELTA_RGBA16_RGBA16, "delta_rgba16_rgba16"}, - {MNG_FN_DELTA_RGBA16_RGB16, "delta_rgba16_rgb16"}, - {MNG_FN_DELTA_RGBA16_A16, "delta_rgba16_a16"}, - - {MNG_FN_PROMOTE_G8_G8, "promote_g8_g8"}, - {MNG_FN_PROMOTE_G8_G16, "promote_g8_g16"}, - {MNG_FN_PROMOTE_G16_G16, "promote_g8_g16"}, - {MNG_FN_PROMOTE_G8_GA8, "promote_g8_ga8"}, - {MNG_FN_PROMOTE_G8_GA16, "promote_g8_ga16"}, - {MNG_FN_PROMOTE_G16_GA16, "promote_g16_ga16"}, - {MNG_FN_PROMOTE_G8_RGB8, "promote_g8_rgb8"}, - {MNG_FN_PROMOTE_G8_RGB16, "promote_g8_rgb16"}, - {MNG_FN_PROMOTE_G16_RGB16, "promote_g16_rgb16"}, - {MNG_FN_PROMOTE_G8_RGBA8, "promote_g8_rgba8"}, - {MNG_FN_PROMOTE_G8_RGBA16, "promote_g8_rgba16"}, - {MNG_FN_PROMOTE_G16_RGBA16, "promote_g16_rgba16"}, - {MNG_FN_PROMOTE_GA8_GA16, "promote_ga8_ga16"}, - {MNG_FN_PROMOTE_GA8_RGBA8, "promote_ga8_rgba8"}, - {MNG_FN_PROMOTE_GA8_RGBA16, "promote_ga8_rgba16"}, - {MNG_FN_PROMOTE_GA16_RGBA16, "promote_ga16_rgba16"}, - {MNG_FN_PROMOTE_RGB8_RGB16, "promote_rgb8_rgb16"}, - {MNG_FN_PROMOTE_RGB8_RGBA8, "promote_rgb8_rgba8"}, - {MNG_FN_PROMOTE_RGB8_RGBA16, "promote_rgb8_rgba16"}, - {MNG_FN_PROMOTE_RGB16_RGBA16, "promote_rgb16_rgba16"}, - {MNG_FN_PROMOTE_RGBA8_RGBA16, "promote_rgba8_rgba16"}, - {MNG_FN_PROMOTE_IDX8_RGB8, "promote_idx8_rgb8"}, - {MNG_FN_PROMOTE_IDX8_RGB16, "promote_idx8_rgb16"}, - {MNG_FN_PROMOTE_IDX8_RGBA8, "promote_idx8_rgba8"}, - {MNG_FN_PROMOTE_IDX8_RGBA16, "promote_idx8_rgba16"}, - - {MNG_FN_SCALE_G1_G2, "scale_g1_g2"}, - {MNG_FN_SCALE_G1_G4, "scale_g1_g4"}, - {MNG_FN_SCALE_G1_G8, "scale_g1_g8"}, - {MNG_FN_SCALE_G1_G16, "scale_g1_g16"}, - {MNG_FN_SCALE_G2_G4, "scale_g2_g4"}, - {MNG_FN_SCALE_G2_G8, "scale_g2_g8"}, - {MNG_FN_SCALE_G2_G16, "scale_g2_g16"}, - {MNG_FN_SCALE_G4_G8, "scale_g4_g8"}, - {MNG_FN_SCALE_G4_G16, "scale_g4_g16"}, - {MNG_FN_SCALE_G8_G16, "scale_g8_g16"}, - {MNG_FN_SCALE_GA8_GA16, "scale_ga8_ga16"}, - {MNG_FN_SCALE_RGB8_RGB16, "scale_rgb8_rgb16"}, - {MNG_FN_SCALE_RGBA8_RGBA16, "scale_rgba8_rgba16"}, - - {MNG_FN_SCALE_G2_G1, "scale_g2_g1"}, - {MNG_FN_SCALE_G4_G1, "scale_g4_g1"}, - {MNG_FN_SCALE_G8_G1, "scale_g8_g1"}, - {MNG_FN_SCALE_G16_G1, "scale_g16_g1"}, - {MNG_FN_SCALE_G4_G2, "scale_g4_g2"}, - {MNG_FN_SCALE_G8_G2, "scale_g8_g2"}, - {MNG_FN_SCALE_G16_G2, "scale_g16_g2"}, - {MNG_FN_SCALE_G8_G4, "scale_g8_g4"}, - {MNG_FN_SCALE_G16_G4, "scale_g16_g4"}, - {MNG_FN_SCALE_G16_G8, "scale_g16_g8"}, - {MNG_FN_SCALE_GA16_GA8, "scale_ga16_ga8"}, - {MNG_FN_SCALE_RGB16_RGB8, "scale_rgb16_rgb8"}, - {MNG_FN_SCALE_RGBA16_RGBA8, "scale_rgba16_rgba8"}, - - {MNG_FN_COMPOSEOVER_RGBA8, "composeover_rgba8"}, - {MNG_FN_COMPOSEOVER_RGBA16, "composeover_rgba16"}, - {MNG_FN_COMPOSEUNDER_RGBA8, "composeunder_rgba8"}, - {MNG_FN_COMPOSEUNDER_RGBA16, "composeunder_rgba16"}, - - {MNG_FN_FLIP_RGBA8, "flip_rgba8"}, - {MNG_FN_FLIP_RGBA16, "flip_rgba16"}, - {MNG_FN_TILE_RGBA8, "tile_rgba8"}, - {MNG_FN_TILE_RGBA16, "tile_rgba16"} - - }; -#endif /* MNG_INCLUDE_TRACE_STINGS */ - -/* ************************************************************************** */ - -mng_retcode mng_trace (mng_datap pData, - mng_uint32 iFunction, - mng_uint32 iLocation) -{ - mng_pchar zName = 0; /* bufferptr for tracestring */ - - if ((pData == 0) || (pData->iMagic != MNG_MAGIC)) - return MNG_INVALIDHANDLE; /* no good if the handle is corrupt */ - - if (pData->fTraceproc) /* report back to user ? */ - { -#ifdef MNG_INCLUDE_TRACE_STRINGS - { /* binary search variables */ - mng_int32 iTop, iLower, iUpper, iMiddle; - mng_trace_entryp pEntry; /* pointer to found entry */ - /* determine max index of table */ - iTop = (sizeof (trace_table) / sizeof (trace_table [0])) - 1; - - iLower = 0; /* initialize binary search */ - iMiddle = iTop >> 1; /* start in the middle */ - iUpper = iTop; - pEntry = 0; /* no goods yet! */ - - do /* the binary search itself */ - { - if (trace_table [iMiddle].iFunction < iFunction) - iLower = iMiddle + 1; - else if (trace_table [iMiddle].iFunction > iFunction) - iUpper = iMiddle - 1; - else - { - pEntry = &trace_table [iMiddle]; - break; - }; - - iMiddle = (iLower + iUpper) >> 1; - } - while (iLower <= iUpper); - - if (pEntry) /* found it ? */ - zName = pEntry->zTracetext; - - } -#endif - /* oke, now tell */ - if (!pData->fTraceproc (((mng_handle)pData), iFunction, iLocation, zName)) - return MNG_APPTRACEABORT; - - } - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_TRACE_PROCS */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_trace.c copyright (c) 2000-2007 G.Juyn * */ +/* * version : 1.0.10 * */ +/* * * */ +/* * purpose : Trace functions (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the trace functions * */ +/* * * */ +/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - added callback error-reporting support * */ +/* * * */ +/* * 0.5.2 - 05/23/2000 - G.Juyn * */ +/* * - added trace telltale reporting * */ +/* * 0.5.2 - 05/24/2000 - G.Juyn * */ +/* * - added tracestrings for global animation color-chunks * */ +/* * - added tracestrings for get/set of default ZLIB/IJG parms * */ +/* * - added tracestrings for global PLTE,tRNS,bKGD * */ +/* * 0.5.2 - 05/30/2000 - G.Juyn * */ +/* * - added tracestrings for image-object promotion * */ +/* * - added tracestrings for delta-image processing * */ +/* * 0.5.2 - 06/02/2000 - G.Juyn * */ +/* * - added tracestrings for getalphaline callback * */ +/* * 0.5.2 - 06/05/2000 - G.Juyn * */ +/* * - added tracestring for RGB8_A8 canvasstyle * */ +/* * 0.5.2 - 06/06/2000 - G.Juyn * */ +/* * - added tracestring for mng_read_resume HLAPI function * */ +/* * * */ +/* * 0.5.3 - 06/21/2000 - G.Juyn * */ +/* * - added tracestrings for get/set speedtype * */ +/* * - added tracestring for get imagelevel * */ +/* * 0.5.3 - 06/22/2000 - G.Juyn * */ +/* * - added tracestring for delta-image processing * */ +/* * - added tracestrings for PPLT chunk processing * */ +/* * * */ +/* * 0.9.1 - 07/07/2000 - G.Juyn * */ +/* * - added tracecodes for special display processing * */ +/* * 0.9.1 - 07/08/2000 - G.Juyn * */ +/* * - added tracestring for get/set suspensionmode * */ +/* * - added tracestrings for get/set display variables * */ +/* * - added tracecode for read_databuffer (I/O-suspension) * */ +/* * 0.9.1 - 07/15/2000 - G.Juyn * */ +/* * - added tracestrings for SAVE/SEEK callbacks * */ +/* * - added tracestrings for get/set sectionbreaks * */ +/* * - added tracestring for special error routine * */ +/* * 0.9.1 - 07/19/2000 - G.Juyn * */ +/* * - added tracestring for updatemngheader * */ +/* * * */ +/* * 0.9.2 - 07/31/2000 - G.Juyn * */ +/* * - added tracestrings for status_xxxxx functions * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * - added tracestring for updatemngsimplicity * */ +/* * * */ +/* * 0.9.3 - 08/26/2000 - G.Juyn * */ +/* * - added MAGN chunk * */ +/* * 0.9.3 - 09/07/2000 - G.Juyn * */ +/* * - added support for new filter_types * */ +/* * 0.9.3 - 10/10/2000 - G.Juyn * */ +/* * - added support for alpha-depth prediction * */ +/* * 0.9.3 - 10/11/2000 - G.Juyn * */ +/* * - added JDAA chunk * */ +/* * - added support for nEED * */ +/* * 0.9.3 - 10/16/2000 - G.Juyn * */ +/* * - added functions to retrieve PNG/JNG specific header-info * */ +/* * - added optional support for bKGD for PNG images * */ +/* * 0.9.3 - 10/17/2000 - G.Juyn * */ +/* * - added callback to process non-critical unknown chunks * */ +/* * - added routine to discard "invalid" objects * */ +/* * 0.9.3 - 10/19/2000 - G.Juyn * */ +/* * - implemented delayed delta-processing * */ +/* * 0.9.3 - 10/20/2000 - G.Juyn * */ +/* * - added get/set for bKGD preference setting * */ +/* * 0.9.3 - 10/21/2000 - G.Juyn * */ +/* * - added get function for interlace/progressive display * */ +/* * * */ +/* * 0.9.4 - 1/18/2001 - G.Juyn * */ +/* * - added "new" MAGN methods 3, 4 & 5 * */ +/* * * */ +/* * 1.0.1 - 02/08/2001 - G.Juyn * */ +/* * - added MEND processing callback * */ +/* * 1.0.1 - 04/21/2001 - G.Juyn (code by G.Kelly) * */ +/* * - added BGRA8 canvas with premultiplied alpha * */ +/* * 1.0.1 - 05/02/2001 - G.Juyn * */ +/* * - added "default" sRGB generation (Thanks Marti!) * */ +/* * * */ +/* * 1.0.2 - 06/23/2001 - G.Juyn * */ +/* * - added optimization option for MNG-video playback * */ +/* * - added processterm callback * */ +/* * 1.0.2 - 06/25/2001 - G.Juyn * */ +/* * - added option to turn off progressive refresh * */ +/* * * */ +/* * 1.0.3 - 08/06/2001 - G.Juyn * */ +/* * - added get function for last processed BACK chunk * */ +/* * * */ +/* * 1.0.5 - 08/15/2002 - G.Juyn * */ +/* * - completed PROM support * */ +/* * - completed delta-image support * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * - added HLAPI function to copy chunks * */ +/* * 1.0.5 - 09/14/2002 - G.Juyn * */ +/* * - added event handling for dynamic MNG * */ +/* * 1.0.5 - 09/20/2002 - G.Juyn * */ +/* * - added support for PAST * */ +/* * 1.0.5 - 09/22/2002 - G.Juyn * */ +/* * - added bgrx8 canvas (filler byte) * */ +/* * 1.0.5 - 09/23/2002 - G.Juyn * */ +/* * - added in-memory color-correction of abstract images * */ +/* * - added compose over/under routines for PAST processing * */ +/* * - added flip & tile routines for PAST processing * */ +/* * 1.0.5 - 10/09/2002 - G.Juyn * */ +/* * - fixed trace-constants for PAST chunk * */ +/* * 1.0.5 - 11/07/2002 - G.Juyn * */ +/* * - added support to get totals after mng_read() * */ +/* * * */ +/* * 1.0.6 - 07/07/2003 - G.R-P * */ +/* * - added conditionals around JNG and Delta-PNG code * */ +/* * 1.0.6 - 07/14/2003 - G.R-P * */ +/* * - added conditionals around various unused functions * */ +/* * 1.0.6 - 07/29/2003 - G.R-P * */ +/* * - added conditionals around PAST chunk support * */ +/* * * */ +/* * 1.0.7 - 11/27/2003 - R.A * */ +/* * - added CANVAS_RGB565 and CANVAS_BGR565 * */ +/* * 1.0.7 - 01/25/2004 - J.S * */ +/* * - added premultiplied alpha canvas' for RGBA, ARGB, ABGR * */ +/* * 1.0.7 - 03/07/2004 - G. Randers-Pehrson * */ +/* * - put gamma, cms-related declarations inside #ifdef * */ +/* * 1.0.7 - 03/10/2004 - G.R-P * */ +/* * - added conditionals around openstream/closestream * */ +/* * * */ +/* * 1.0.8 - 04/02/2004 - G.Juyn * */ +/* * - added CRC existence & checking flags * */ +/* * 1.0.8 - 04/11/2004 - G.Juyn * */ +/* * - added data-push mechanisms for specialized decoders * */ +/* * * */ +/* * 1.0.9 - 10/03/2004 - G.Juyn * */ +/* * - added function to retrieve current FRAM delay * */ +/* * 1.0.9 - 10/14/2004 - G.Juyn * */ +/* * - added bgr565_a8 canvas-style (thanks to J. Elvander) * */ +/* * * */ +/* * 1.0.10 - 04/08/2007 - G.Juyn * */ +/* * - added support for mPNG proposal * */ +/* * 1.0.10 - 07/06/2007 - G.R-P bugfix by Lucas Quintana * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_TRACE_PROCS + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_TRACE_STRINGS +MNG_LOCAL mng_trace_entry const trace_table [] = + { + {MNG_FN_INITIALIZE, "initialize"}, + {MNG_FN_RESET, "reset"}, + {MNG_FN_CLEANUP, "cleanup"}, + {MNG_FN_READ, "read"}, + {MNG_FN_WRITE, "write"}, + {MNG_FN_CREATE, "create"}, + {MNG_FN_READDISPLAY, "readdisplay"}, + {MNG_FN_DISPLAY, "display"}, + {MNG_FN_DISPLAY_RESUME, "display_resume"}, + {MNG_FN_DISPLAY_FREEZE, "display_freeze"}, + {MNG_FN_DISPLAY_RESET, "display_reset"}, +#ifndef MNG_NO_DISPLAY_GO_SUPPORTED + {MNG_FN_DISPLAY_GOFRAME, "display_goframe"}, + {MNG_FN_DISPLAY_GOLAYER, "display_golayer"}, + {MNG_FN_DISPLAY_GOTIME, "display_gotime"}, +#endif + {MNG_FN_GETLASTERROR, "getlasterror"}, + {MNG_FN_READ_RESUME, "read_resume"}, + {MNG_FN_TRAPEVENT, "trapevent"}, + {MNG_FN_READ_PUSHDATA, "read_pushdata"}, + {MNG_FN_READ_PUSHSIG, "read_pushsig"}, + {MNG_FN_READ_PUSHCHUNK, "read_pushchunk"}, + + {MNG_FN_SETCB_MEMALLOC, "setcb_memalloc"}, + {MNG_FN_SETCB_MEMFREE, "setcb_memfree"}, + {MNG_FN_SETCB_READDATA, "setcb_readdata"}, + {MNG_FN_SETCB_WRITEDATA, "setcb_writedata"}, + {MNG_FN_SETCB_ERRORPROC, "setcb_errorproc"}, + {MNG_FN_SETCB_TRACEPROC, "setcb_traceproc"}, + {MNG_FN_SETCB_PROCESSHEADER, "setcb_processheader"}, + {MNG_FN_SETCB_PROCESSTEXT, "setcb_processtext"}, + {MNG_FN_SETCB_GETCANVASLINE, "setcb_getcanvasline"}, + {MNG_FN_SETCB_GETBKGDLINE, "setcb_getbkgdline"}, + {MNG_FN_SETCB_REFRESH, "setcb_refresh"}, + {MNG_FN_SETCB_GETTICKCOUNT, "setcb_gettickcount"}, + {MNG_FN_SETCB_SETTIMER, "setcb_settimer"}, + {MNG_FN_SETCB_PROCESSGAMMA, "setcb_processgamma"}, + {MNG_FN_SETCB_PROCESSCHROMA, "setcb_processchroma"}, + {MNG_FN_SETCB_PROCESSSRGB, "setcb_processsrgb"}, + {MNG_FN_SETCB_PROCESSICCP, "setcb_processiccp"}, + {MNG_FN_SETCB_PROCESSAROW, "setcb_processarow"}, +#ifndef MNG_NO_OPEN_CLOSE_STREAM + {MNG_FN_SETCB_OPENSTREAM, "setcb_openstream"}, + {MNG_FN_SETCB_CLOSESTREAM, "setcb_closestream"}, +#endif + {MNG_FN_SETCB_GETALPHALINE, "setcb_getalphaline"}, + {MNG_FN_SETCB_PROCESSSAVE, "setcb_processsave"}, + {MNG_FN_SETCB_PROCESSSEEK, "setcb_processseek"}, + {MNG_FN_SETCB_PROCESSNEED, "setcb_processneed"}, + {MNG_FN_SETCB_PROCESSUNKNOWN, "setcb_processunknown"}, + {MNG_FN_SETCB_PROCESSMEND, "setcb_processmend"}, + {MNG_FN_SETCB_PROCESSTERM, "setcb_processterm"}, + {MNG_FN_SETCB_RELEASEDATA, "setcb_releasedata"}, + + {MNG_FN_GETCB_MEMALLOC, "getcb_memalloc"}, + {MNG_FN_GETCB_MEMFREE, "getcb_memfree"}, + {MNG_FN_GETCB_READDATA, "getcb_readdata,"}, + {MNG_FN_GETCB_WRITEDATA, "getcb_writedata"}, + {MNG_FN_GETCB_ERRORPROC, "getcb_errorproc"}, + {MNG_FN_GETCB_TRACEPROC, "getcb_traceproc"}, + {MNG_FN_GETCB_PROCESSHEADER, "getcb_processheader"}, + {MNG_FN_GETCB_PROCESSTEXT, "getcb_processtext"}, + {MNG_FN_GETCB_GETCANVASLINE, "getcb_getcanvasline"}, + {MNG_FN_GETCB_GETBKGDLINE, "getcb_getbkgdline"}, + {MNG_FN_GETCB_REFRESH, "getcb_refresh"}, + {MNG_FN_GETCB_GETTICKCOUNT, "getcb_gettickcount"}, + {MNG_FN_GETCB_SETTIMER, "getcb_settimer"}, + {MNG_FN_GETCB_PROCESSGAMMA, "getcb_processgamma"}, + {MNG_FN_GETCB_PROCESSCHROMA, "getcb_processchroma"}, + {MNG_FN_GETCB_PROCESSSRGB, "getcb_processsrgb"}, + {MNG_FN_GETCB_PROCESSICCP, "getcb_processiccp"}, + {MNG_FN_GETCB_PROCESSAROW, "getcb_processarow"}, +#ifndef MNG_NO_OPEN_CLOSE_STREAM + {MNG_FN_GETCB_OPENSTREAM, "getcb_openstream"}, + {MNG_FN_GETCB_CLOSESTREAM, "getcb_closestream"}, +#endif + {MNG_FN_GETCB_GETALPHALINE, "getcb_getalphaline"}, + {MNG_FN_GETCB_PROCESSSAVE, "getcb_processsave"}, + {MNG_FN_GETCB_PROCESSSEEK, "getcb_processseek"}, + {MNG_FN_GETCB_PROCESSNEED, "getcb_processneed"}, + {MNG_FN_GETCB_PROCESSUNKNOWN, "getcb_processunknown"}, + {MNG_FN_GETCB_PROCESSMEND, "getcb_processmend"}, + {MNG_FN_GETCB_PROCESSTERM, "getcb_processterm"}, + {MNG_FN_GETCB_RELEASEDATA, "getcb_releasedata"}, + + {MNG_FN_SET_USERDATA, "set_userdata"}, + {MNG_FN_SET_CANVASSTYLE, "set_canvasstyle"}, + {MNG_FN_SET_BKGDSTYLE, "set_bkgdstyle"}, + {MNG_FN_SET_BGCOLOR, "set_bgcolor"}, + {MNG_FN_SET_STORECHUNKS, "set_storechunks"}, +#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) + {MNG_FN_SET_VIEWGAMMA, "set_viewgamma"}, +#ifndef MNG_NO_DFLT_INFO + {MNG_FN_SET_DISPLAYGAMMA, "set_displaygamma"}, +#endif + {MNG_FN_SET_DFLTIMGGAMMA, "set_dfltimggamma"}, +#endif + {MNG_FN_SET_SRGB, "set_srgb"}, + {MNG_FN_SET_OUTPUTPROFILE, "set_outputprofile"}, + {MNG_FN_SET_SRGBPROFILE, "set_srgbprofile"}, +#ifndef MNG_SKIP_MAXCANVAS + {MNG_FN_SET_MAXCANVASWIDTH, "set_maxcanvaswidth"}, + {MNG_FN_SET_MAXCANVASHEIGHT, "set_maxcanvasheight"}, + {MNG_FN_SET_MAXCANVASSIZE, "set_maxcanvassize"}, +#endif +#ifndef MNG_NO_ACCESS_ZLIB + {MNG_FN_SET_ZLIB_LEVEL, "set_zlib_level"}, + {MNG_FN_SET_ZLIB_METHOD, "set_zlib_method"}, + {MNG_FN_SET_ZLIB_WINDOWBITS, "set_zlib_windowbits"}, + {MNG_FN_SET_ZLIB_MEMLEVEL, "set_zlib_memlevel"}, + {MNG_FN_SET_ZLIB_STRATEGY, "set_zlib_strategy"}, + {MNG_FN_SET_ZLIB_MAXIDAT, "set_zlib_maxidat"}, +#endif +#ifndef MNG_NO_ACCESS_JPEG + {MNG_FN_SET_JPEG_DCTMETHOD, "set_jpeg_dctmethod"}, + {MNG_FN_SET_JPEG_QUALITY, "set_jpeg_quality"}, + {MNG_FN_SET_JPEG_SMOOTHING, "set_jpeg_smoothing"}, + {MNG_FN_SET_JPEG_PROGRESSIVE, "set_jpeg_progressive"}, + {MNG_FN_SET_JPEG_OPTIMIZED, "set_jpeg_optimized"}, + {MNG_FN_SET_JPEG_MAXJDAT, "set_jpeg_maxjdat"}, +#endif + {MNG_FN_SET_SPEED, "set_speed"}, + {MNG_FN_SET_SUSPENSIONMODE, "set_suspensionmode"}, + {MNG_FN_SET_SECTIONBREAKS, "set_sectionbreaks"}, + {MNG_FN_SET_USEBKGD, "set_usebkgd"}, + {MNG_FN_SET_OUTPUTPROFILE2, "set_outputprofile2"}, + {MNG_FN_SET_SRGBPROFILE2, "set_srgbprofile2"}, + {MNG_FN_SET_OUTPUTSRGB, "set_outputsrgb"}, + {MNG_FN_SET_SRGBIMPLICIT, "set_srgbimplicit"}, + {MNG_FN_SET_CACHEPLAYBACK, "set_cacheplayback"}, + {MNG_FN_SET_DOPROGRESSIVE, "set_doprogressive"}, + {MNG_FN_SET_CRCMODE, "set_crcmode"}, + + {MNG_FN_GET_USERDATA, "get_userdata"}, + {MNG_FN_GET_SIGTYPE, "get_sigtype"}, + {MNG_FN_GET_IMAGETYPE, "get_imagetype"}, + {MNG_FN_GET_IMAGEWIDTH, "get_imagewidth"}, + {MNG_FN_GET_IMAGEHEIGHT, "get_imageheight"}, + {MNG_FN_GET_TICKS, "get_ticks"}, + {MNG_FN_GET_FRAMECOUNT, "get_framecount"}, + {MNG_FN_GET_LAYERCOUNT, "get_layercount"}, + {MNG_FN_GET_PLAYTIME, "get_playtime"}, + {MNG_FN_GET_SIMPLICITY, "get_simplicity"}, + {MNG_FN_GET_CANVASSTYLE, "get_canvasstyle"}, + {MNG_FN_GET_BKGDSTYLE, "get_bkgdstyle"}, + {MNG_FN_GET_BGCOLOR, "get_bgcolor"}, + {MNG_FN_GET_STORECHUNKS, "get_storechunks"}, +#if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS) + {MNG_FN_GET_VIEWGAMMA, "get_viewgamma"}, + {MNG_FN_GET_DISPLAYGAMMA, "get_displaygamma"}, +#ifndef MNG_NO_DFLT_INFO + {MNG_FN_GET_DFLTIMGGAMMA, "get_dfltimggamma"}, +#endif +#endif + {MNG_FN_GET_SRGB, "get_srgb"}, +#ifndef MNG_SKIP_MAXCANVAS + {MNG_FN_GET_MAXCANVASWIDTH, "get_maxcanvaswidth"}, + {MNG_FN_GET_MAXCANVASHEIGHT, "get_maxcanvasheight"}, +#endif +#ifndef MNG_NO_ACCESS_ZLIB + {MNG_FN_GET_ZLIB_LEVEL, "get_zlib_level"}, + {MNG_FN_GET_ZLIB_METHOD, "get_zlib_method"}, + {MNG_FN_GET_ZLIB_WINDOWBITS, "get_zlib_windowbits"}, + {MNG_FN_GET_ZLIB_MEMLEVEL, "get_zlib_memlevel"}, + {MNG_FN_GET_ZLIB_STRATEGY, "get_zlib_strategy"}, + {MNG_FN_GET_ZLIB_MAXIDAT, "get_zlib_maxidat"}, +#endif +#ifndef MNG_NO_ACCESS_JPEG + {MNG_FN_GET_JPEG_DCTMETHOD, "get_jpeg_dctmethod"}, + {MNG_FN_GET_JPEG_QUALITY, "get_jpeg_quality"}, + {MNG_FN_GET_JPEG_SMOOTHING, "get_jpeg_smoothing"}, + {MNG_FN_GET_JPEG_PROGRESSIVE, "get_jpeg_progressive"}, + {MNG_FN_GET_JPEG_OPTIMIZED, "get_jpeg_optimized"}, + {MNG_FN_GET_JPEG_MAXJDAT, "get_jpeg_maxjdat"}, +#endif + {MNG_FN_GET_SPEED, "get_speed"}, + {MNG_FN_GET_IMAGELEVEL, "get_imagelevel"}, + {MNG_FN_GET_SUSPENSIONMODE, "get_speed"}, + {MNG_FN_GET_STARTTIME, "get_starttime"}, + {MNG_FN_GET_RUNTIME, "get_runtime"}, +#ifndef MNG_NO_CURRENT_INFO + {MNG_FN_GET_CURRENTFRAME, "get_currentframe"}, + {MNG_FN_GET_CURRENTLAYER, "get_currentlayer"}, + {MNG_FN_GET_CURRENTPLAYTIME, "get_currentplaytime"}, +#endif + {MNG_FN_GET_SECTIONBREAKS, "get_sectionbreaks"}, + {MNG_FN_GET_ALPHADEPTH, "get_alphadepth"}, + {MNG_FN_GET_BITDEPTH, "get_bitdepth"}, + {MNG_FN_GET_COLORTYPE, "get_colortype"}, + {MNG_FN_GET_COMPRESSION, "get_compression"}, + {MNG_FN_GET_FILTER, "get_filter"}, + {MNG_FN_GET_INTERLACE, "get_interlace"}, + {MNG_FN_GET_ALPHABITDEPTH, "get_alphabitdepth"}, + {MNG_FN_GET_ALPHACOMPRESSION, "get_alphacompression"}, + {MNG_FN_GET_ALPHAFILTER, "get_alphafilter"}, + {MNG_FN_GET_ALPHAINTERLACE, "get_alphainterlace"}, + {MNG_FN_GET_USEBKGD, "get_usebkgd"}, + {MNG_FN_GET_REFRESHPASS, "get_refreshpass"}, + {MNG_FN_GET_CACHEPLAYBACK, "get_cacheplayback"}, + {MNG_FN_GET_DOPROGRESSIVE, "get_doprogressive"}, + {MNG_FN_GET_LASTBACKCHUNK, "get_lastbackchunk"}, + {MNG_FN_GET_LASTSEEKNAME, "get_lastseekname"}, +#ifndef MNG_NO_CURRENT_INFO + {MNG_FN_GET_TOTALFRAMES, "get_totalframes"}, + {MNG_FN_GET_TOTALLAYERS, "get_totallayers"}, + {MNG_FN_GET_TOTALPLAYTIME, "get_totalplaytime"}, +#endif + {MNG_FN_GET_CRCMODE, "get_crcmode"}, + {MNG_FN_GET_CURRFRAMDELAY, "get_currframdelay"}, + + {MNG_FN_STATUS_ERROR, "status_error"}, + {MNG_FN_STATUS_READING, "status_reading"}, + {MNG_FN_STATUS_SUSPENDBREAK, "status_suspendbreak"}, + {MNG_FN_STATUS_CREATING, "status_creating"}, + {MNG_FN_STATUS_WRITING, "status_writing"}, + {MNG_FN_STATUS_DISPLAYING, "status_displaying"}, + {MNG_FN_STATUS_RUNNING, "status_running"}, + {MNG_FN_STATUS_TIMERBREAK, "status_timerbreak"}, + {MNG_FN_STATUS_DYNAMIC, "status_dynamic"}, + {MNG_FN_STATUS_RUNNINGEVENT, "status_runningevent"}, + + {MNG_FN_ITERATE_CHUNKS, "iterate_chunks"}, + {MNG_FN_COPY_CHUNK, "copy_chunk"}, + + {MNG_FN_GETCHUNK_IHDR, "getchunk_ihdr"}, + {MNG_FN_GETCHUNK_PLTE, "getchunk_plte"}, + {MNG_FN_GETCHUNK_IDAT, "getchunk_idat"}, + {MNG_FN_GETCHUNK_IEND, "getchunk_iend"}, + {MNG_FN_GETCHUNK_TRNS, "getchunk_trns"}, +#ifndef MNG_SKIPCHUNK_gAMA + {MNG_FN_GETCHUNK_GAMA, "getchunk_gama"}, +#endif +#ifndef MNG_SKIPCHUNK_cHRM + {MNG_FN_GETCHUNK_CHRM, "getchunk_chrm"}, +#endif +#ifndef MNG_SKIPCHUNK_sRGB + {MNG_FN_GETCHUNK_SRGB, "getchunk_srgb"}, +#endif +#ifndef MNG_SKIPCHUNK_iCCP + {MNG_FN_GETCHUNK_ICCP, "getchunk_iccp"}, +#endif +#ifndef MNG_SKIPCHUNK_tEXt + {MNG_FN_GETCHUNK_TEXT, "getchunk_text"}, +#endif +#ifndef MNG_SKIPCHUNK_zTXt + {MNG_FN_GETCHUNK_ZTXT, "getchunk_ztxt"}, +#endif +#ifndef MNG_SKIPCHUNK_iTXt + {MNG_FN_GETCHUNK_ITXT, "getchunk_itxt"}, +#endif +#ifndef MNG_SKIPCHUNK_bKGD + {MNG_FN_GETCHUNK_BKGD, "getchunk_bkgd"}, +#endif +#ifndef MNG_SKIPCHUNK_pHYs + {MNG_FN_GETCHUNK_PHYS, "getchunk_phys"}, +#endif +#ifndef MNG_SKIPCHUNK_sBIT + {MNG_FN_GETCHUNK_SBIT, "getchunk_sbit"}, +#endif +#ifndef MNG_SKIPCHUNK_sPLT + {MNG_FN_GETCHUNK_SPLT, "getchunk_splt"}, +#endif +#ifndef MNG_SKIPCHUNK_hIST + {MNG_FN_GETCHUNK_HIST, "getchunk_hist"}, +#endif +#ifndef MNG_SKIPCHUNK_tIME + {MNG_FN_GETCHUNK_TIME, "getchunk_time"}, +#endif + {MNG_FN_GETCHUNK_MHDR, "getchunk_mhdr"}, + {MNG_FN_GETCHUNK_MEND, "getchunk_mend"}, +#ifndef MNG_SKIPCHUNK_LOOP + {MNG_FN_GETCHUNK_LOOP, "getchunk_loop"}, + {MNG_FN_GETCHUNK_ENDL, "getchunk_endl"}, +#endif + {MNG_FN_GETCHUNK_DEFI, "getchunk_defi"}, +#ifndef MNG_SKIPCHUNK_BASI + {MNG_FN_GETCHUNK_BASI, "getchunk_basi"}, +#endif + {MNG_FN_GETCHUNK_CLON, "getchunk_clon"}, +#ifndef MNG_SKIPCHUNK_PAST + {MNG_FN_GETCHUNK_PAST, "getchunk_past"}, +#endif + {MNG_FN_GETCHUNK_DISC, "getchunk_disc"}, + {MNG_FN_GETCHUNK_BACK, "getchunk_back"}, + {MNG_FN_GETCHUNK_FRAM, "getchunk_fram"}, + {MNG_FN_GETCHUNK_MOVE, "getchunk_move"}, + {MNG_FN_GETCHUNK_CLIP, "getchunk_clip"}, + {MNG_FN_GETCHUNK_SHOW, "getchunk_show"}, + {MNG_FN_GETCHUNK_TERM, "getchunk_term"}, +#ifndef MNG_SKIPCHUNK_SAVE + {MNG_FN_GETCHUNK_SAVE, "getchunk_save"}, +#endif +#ifndef MNG_SKIPCHUNK_SEEK + {MNG_FN_GETCHUNK_SEEK, "getchunk_seek"}, +#endif +#ifndef MNG_SKIPCHUNK_eXPI + {MNG_FN_GETCHUNK_EXPI, "getchunk_expi"}, +#endif +#ifndef MNG_SKIPCHUNK_fPRI + {MNG_FN_GETCHUNK_FPRI, "getchunk_fpri"}, +#endif +#ifndef MNG_SKIPCHUNK_nEED + {MNG_FN_GETCHUNK_NEED, "getchunk_need"}, +#endif +#ifndef MNG_SKIPCHUNK_pHYg + {MNG_FN_GETCHUNK_PHYG, "getchunk_phyg"}, +#endif +#ifdef MNG_INCLUDE_JNG + {MNG_FN_GETCHUNK_JHDR, "getchunk_jhdr"}, + {MNG_FN_GETCHUNK_JDAT, "getchunk_jdat"}, + {MNG_FN_GETCHUNK_JSEP, "getchunk_jsep"}, +#endif +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_GETCHUNK_DHDR, "getchunk_dhdr"}, + {MNG_FN_GETCHUNK_PROM, "getchunk_prom"}, + {MNG_FN_GETCHUNK_IPNG, "getchunk_ipng"}, + {MNG_FN_GETCHUNK_PPLT, "getchunk_pplt"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_GETCHUNK_IJNG, "getchunk_ijng"}, +#endif +#ifndef MNG_SKIPCHUNK_DROP + {MNG_FN_GETCHUNK_DROP, "getchunk_drop"}, +#endif +#ifndef MNG_SKIPCHUNK_DBYK + {MNG_FN_GETCHUNK_DBYK, "getchunk_dbyk"}, +#endif +#ifndef MNG_SKIPCHUNK_ORDR + {MNG_FN_GETCHUNK_ORDR, "getchunk_ordr"}, +#endif +#endif + {MNG_FN_GETCHUNK_UNKNOWN, "getchunk_unknown"}, + {MNG_FN_GETCHUNK_MAGN, "getchunk_magn"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_GETCHUNK_JDAA, "getchunk_jdaa"}, +#endif +#ifndef MNG_SKIPCHUNK_evNT + {MNG_FN_GETCHUNK_EVNT, "getchunk_evnt"}, +#endif +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + {MNG_FN_GETCHUNK_MPNG, "getchunk_mpng"}, +#endif + +#ifndef MNG_SKIPCHUNK_PAST + {MNG_FN_GETCHUNK_PAST_SRC, "getchunk_past_src"}, +#endif +#ifndef MNG_SKIPCHUNK_SAVE + {MNG_FN_GETCHUNK_SAVE_ENTRY, "getchunk_save_entry"}, +#endif +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_GETCHUNK_PPLT_ENTRY, "getchunk_pplt_entry"}, + {MNG_FN_GETCHUNK_ORDR_ENTRY, "getchunk_ordr_entry"}, +#endif +#ifndef MNG_SKIPCHUNK_evNT + {MNG_FN_GETCHUNK_EVNT_ENTRY, "getchunk_evnt_entry"}, +#endif +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + {MNG_FN_GETCHUNK_MPNG_FRAME, "getchunk_mpng_frame"}, +#endif + + {MNG_FN_PUTCHUNK_IHDR, "putchunk_ihdr"}, + {MNG_FN_PUTCHUNK_PLTE, "putchunk_plte"}, + {MNG_FN_PUTCHUNK_IDAT, "putchunk_idat"}, + {MNG_FN_PUTCHUNK_IEND, "putchunk_iend"}, + {MNG_FN_PUTCHUNK_TRNS, "putchunk_trns"}, +#ifndef MNG_SKIPCHUNK_gAMA + {MNG_FN_PUTCHUNK_GAMA, "putchunk_gama"}, +#endif +#ifndef MNG_SKIPCHUNK_cHRM + {MNG_FN_PUTCHUNK_CHRM, "putchunk_chrm"}, +#endif +#ifndef MNG_SKIPCHUNK_sRGB + {MNG_FN_PUTCHUNK_SRGB, "putchunk_srgb"}, +#endif +#ifndef MNG_SKIPCHUNK_iCCP + {MNG_FN_PUTCHUNK_ICCP, "putchunk_iccp"}, +#endif +#ifndef MNG_SKIPCHUNK_tEXt + {MNG_FN_PUTCHUNK_TEXT, "putchunk_text"}, +#endif +#ifndef MNG_SKIPCHUNK_zTXt + {MNG_FN_PUTCHUNK_ZTXT, "putchunk_ztxt"}, +#endif +#ifndef MNG_SKIPCHUNK_iTXt + {MNG_FN_PUTCHUNK_ITXT, "putchunk_itxt"}, +#endif +#ifndef MNG_SKIPCHUNK_bKGD + {MNG_FN_PUTCHUNK_BKGD, "putchunk_bkgd"}, +#endif +#ifndef MNG_SKIPCHUNK_pHYs + {MNG_FN_PUTCHUNK_PHYS, "putchunk_phys"}, +#endif +#ifndef MNG_SKIPCHUNK_sBIT + {MNG_FN_PUTCHUNK_SBIT, "putchunk_sbit"}, +#endif +#ifndef MNG_SKIPCHUNK_sPLT + {MNG_FN_PUTCHUNK_SPLT, "putchunk_splt"}, +#endif +#ifndef MNG_SKIPCHUNK_hIST + {MNG_FN_PUTCHUNK_HIST, "putchunk_hist"}, +#endif +#ifndef MNG_SKIPCHUNK_tIME + {MNG_FN_PUTCHUNK_TIME, "putchunk_time"}, +#endif + {MNG_FN_PUTCHUNK_MHDR, "putchunk_mhdr"}, + {MNG_FN_PUTCHUNK_MEND, "putchunk_mend"}, + {MNG_FN_PUTCHUNK_LOOP, "putchunk_loop"}, + {MNG_FN_PUTCHUNK_ENDL, "putchunk_endl"}, + {MNG_FN_PUTCHUNK_DEFI, "putchunk_defi"}, + {MNG_FN_PUTCHUNK_BASI, "putchunk_basi"}, + {MNG_FN_PUTCHUNK_CLON, "putchunk_clon"}, +#ifndef MNG_SKIPCHUNK_PAST + {MNG_FN_PUTCHUNK_PAST, "putchunk_past"}, +#endif + {MNG_FN_PUTCHUNK_DISC, "putchunk_disc"}, + {MNG_FN_PUTCHUNK_BACK, "putchunk_back"}, + {MNG_FN_PUTCHUNK_FRAM, "putchunk_fram"}, + {MNG_FN_PUTCHUNK_MOVE, "putchunk_move"}, + {MNG_FN_PUTCHUNK_CLIP, "putchunk_clip"}, + {MNG_FN_PUTCHUNK_SHOW, "putchunk_show"}, + {MNG_FN_PUTCHUNK_TERM, "putchunk_term"}, +#ifndef MNG_SKIPCHUNK_SAVE + {MNG_FN_PUTCHUNK_SAVE, "putchunk_save"}, +#endif +#ifndef MNG_SKIPCHUNK_SEEK + {MNG_FN_PUTCHUNK_SEEK, "putchunk_seek"}, +#endif +#ifndef MNG_SKIPCHUNK_eXPI + {MNG_FN_PUTCHUNK_EXPI, "putchunk_expi"}, +#endif +#ifndef MNG_SKIPCHUNK_fPRI + {MNG_FN_PUTCHUNK_FPRI, "putchunk_fpri"}, +#endif +#ifndef MNG_SKIPCHUNK_nEED + {MNG_FN_PUTCHUNK_NEED, "putchunk_need"}, +#endif +#ifndef MNG_SKIPCHUNK_pHYg + {MNG_FN_PUTCHUNK_PHYG, "putchunk_phyg"}, +#endif +#ifdef MNG_INCLUDE_JNG + {MNG_FN_PUTCHUNK_JHDR, "putchunk_jhdr"}, + {MNG_FN_PUTCHUNK_JDAT, "putchunk_jdat"}, + {MNG_FN_PUTCHUNK_JSEP, "putchunk_jsep"}, +#endif +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_PUTCHUNK_DHDR, "putchunk_dhdr"}, + {MNG_FN_PUTCHUNK_PROM, "putchunk_prom"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_PUTCHUNK_IPNG, "putchunk_ipng"}, +#endif + {MNG_FN_PUTCHUNK_PPLT, "putchunk_pplt"}, + {MNG_FN_PUTCHUNK_IJNG, "putchunk_ijng"}, +#ifndef MNG_SKIPCHUNK_DROP + {MNG_FN_PUTCHUNK_DROP, "putchunk_drop"}, +#endif +#ifndef MNG_SKIPCHUNK_DBYK + {MNG_FN_PUTCHUNK_DBYK, "putchunk_dbyk"}, +#endif +#ifndef MNG_SKIPCHUNK_ORDR + {MNG_FN_PUTCHUNK_ORDR, "putchunk_ordr"}, +#endif +#endif + {MNG_FN_PUTCHUNK_UNKNOWN, "putchunk_unknown"}, + {MNG_FN_PUTCHUNK_MAGN, "putchunk_magn"}, + {MNG_FN_PUTCHUNK_JDAA, "putchunk_jdaa"}, +#ifndef MNG_SKIPCHUNK_evNT + {MNG_FN_PUTCHUNK_EVNT, "putchunk_evnt"}, +#endif +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + {MNG_FN_PUTCHUNK_MPNG, "putchunk_mpng"}, +#endif + +#ifndef MNG_SKIPCHUNK_PAST + {MNG_FN_PUTCHUNK_PAST_SRC, "putchunk_past_src"}, +#endif +#ifndef MNG_SKIPCHUNK_SAVE + {MNG_FN_PUTCHUNK_SAVE_ENTRY, "putchunk_save_entry"}, +#endif +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_PUTCHUNK_PPLT_ENTRY, "putchunk_pplt_entry"}, +#ifndef MNG_SKIPCHUNK_ORDR + {MNG_FN_PUTCHUNK_ORDR_ENTRY, "putchunk_ordr_entry"}, +#endif +#endif +#ifndef MNG_SKIPCHUNK_evNT + {MNG_FN_PUTCHUNK_EVNT_ENTRY, "putchunk_evnt_entry"}, +#endif +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + {MNG_FN_PUTCHUNK_MPNG_FRAME, "putchunk_mpng_frame"}, +#endif + + {MNG_FN_GETIMGDATA_SEQ, "getimgdata_seq"}, + {MNG_FN_GETIMGDATA_CHUNKSEQ, "getimgdata_chunkseq"}, + {MNG_FN_GETIMGDATA_CHUNK, "getimgdata_chunk"}, + + {MNG_FN_PUTIMGDATA_IHDR, "putimgdata_ihdr"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_PUTIMGDATA_JHDR, "putimgdata_jhdr"}, + {MNG_FN_PUTIMGDATA_BASI, "putimgdata_basi"}, + {MNG_FN_PUTIMGDATA_DHDR, "putimgdata_dhdr"}, +#endif + + {MNG_FN_UPDATEMNGHEADER, "updatemngheader"}, + {MNG_FN_UPDATEMNGSIMPLICITY, "updatemngsimplicity"}, + + {MNG_FN_PROCESS_RAW_CHUNK, "process_raw_chunk"}, + {MNG_FN_READ_GRAPHIC, "read_graphic"}, + {MNG_FN_DROP_CHUNKS, "drop_chunks"}, + {MNG_FN_PROCESS_ERROR, "process_error"}, + {MNG_FN_CLEAR_CMS, "clear_cms"}, + {MNG_FN_DROP_OBJECTS, "drop_objects"}, + {MNG_FN_READ_CHUNK, "read_chunk"}, + {MNG_FN_LOAD_BKGDLAYER, "load_bkgdlayer"}, + {MNG_FN_NEXT_FRAME, "next_frame"}, + {MNG_FN_NEXT_LAYER, "next_layer"}, + {MNG_FN_INTERFRAME_DELAY, "interframe_delay"}, + {MNG_FN_DISPLAY_IMAGE, "display_image"}, + {MNG_FN_DROP_IMGOBJECTS, "drop_imgobjects"}, + {MNG_FN_DROP_ANIOBJECTS, "drop_aniobjects"}, + {MNG_FN_INFLATE_BUFFER, "inflate_buffer"}, + {MNG_FN_DEFLATE_BUFFER, "deflate_buffer"}, + {MNG_FN_WRITE_RAW_CHUNK, "write_raw_chunk"}, + {MNG_FN_WRITE_GRAPHIC, "write_graphic"}, + {MNG_FN_SAVE_STATE, "save_state"}, + {MNG_FN_RESTORE_STATE, "restore_state"}, + {MNG_FN_DROP_SAVEDATA, "drop_savedata"}, +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_EXECUTE_DELTA_IMAGE, "execute_delta_image"}, +#endif + {MNG_FN_PROCESS_DISPLAY, "process_display"}, + {MNG_FN_CLEAR_CANVAS, "clear_canvas"}, + {MNG_FN_READ_DATABUFFER, "read_databuffer"}, + {MNG_FN_STORE_ERROR, "store_error"}, + {MNG_FN_DROP_INVALID_OBJECTS, "drop_invalid_objects"}, + {MNG_FN_RELEASE_PUSHDATA, "release_pushdata"}, + {MNG_FN_READ_DATA, "read_data"}, + {MNG_FN_READ_CHUNK_CRC, "read_chunk_crc"}, + {MNG_FN_RELEASE_PUSHCHUNK, "release_pushchunk"}, + + {MNG_FN_DISPLAY_RGB8, "display_rgb8"}, + {MNG_FN_DISPLAY_RGBA8, "display_rgba8"}, + {MNG_FN_DISPLAY_ARGB8, "display_argb8"}, + {MNG_FN_DISPLAY_BGR8, "display_bgr8"}, + {MNG_FN_DISPLAY_BGRA8, "display_bgra8"}, + {MNG_FN_DISPLAY_ABGR8, "display_abgr8"}, + {MNG_FN_DISPLAY_RGB16, "display_rgb16"}, + {MNG_FN_DISPLAY_RGBA16, "display_rgba16"}, + {MNG_FN_DISPLAY_ARGB16, "display_argb16"}, + {MNG_FN_DISPLAY_BGR16, "display_bgr16"}, + {MNG_FN_DISPLAY_BGRA16, "display_bgra16"}, + {MNG_FN_DISPLAY_ABGR16, "display_abgr16"}, + {MNG_FN_DISPLAY_INDEX8, "display_index8"}, + {MNG_FN_DISPLAY_INDEXA8, "display_indexa8"}, + {MNG_FN_DISPLAY_AINDEX8, "display_aindex8"}, + {MNG_FN_DISPLAY_GRAY8, "display_gray8"}, + {MNG_FN_DISPLAY_GRAY16, "display_gray16"}, + {MNG_FN_DISPLAY_GRAYA8, "display_graya8"}, + {MNG_FN_DISPLAY_GRAYA16, "display_graya16"}, + {MNG_FN_DISPLAY_AGRAY8, "display_agray8"}, + {MNG_FN_DISPLAY_AGRAY16, "display_agray16"}, + {MNG_FN_DISPLAY_DX15, "display_dx15"}, + {MNG_FN_DISPLAY_DX16, "display_dx16"}, + {MNG_FN_DISPLAY_RGB8_A8, "display_rgb8_a8"}, + {MNG_FN_DISPLAY_BGRA8PM, "display_bgra8_pm"}, + {MNG_FN_DISPLAY_BGRX8, "display_bgrx8"}, + {MNG_FN_DISPLAY_RGB565, "display_rgb565"}, + {MNG_FN_DISPLAY_RGBA565, "display_rgba565"}, + {MNG_FN_DISPLAY_BGR565, "display_bgr565"}, + {MNG_FN_DISPLAY_BGRA565, "display_bgra565"}, + {MNG_FN_DISPLAY_RGBA8_PM, "display_rgba8_pm"}, + {MNG_FN_DISPLAY_ARGB8_PM, "display_argb8_pm"}, + {MNG_FN_DISPLAY_ABGR8_PM, "display_abgr8_pm"}, + {MNG_FN_DISPLAY_BGR565_A8, "display_bgr565_a8"}, + + {MNG_FN_INIT_FULL_CMS, "init_full_cms"}, + {MNG_FN_CORRECT_FULL_CMS, "correct_full_cms"}, + {MNG_FN_INIT_GAMMA_ONLY, "init_gamma_only"}, + {MNG_FN_CORRECT_GAMMA_ONLY, "correct_gamma_only"}, + {MNG_FN_CORRECT_APP_CMS, "correct_app_cms"}, + {MNG_FN_INIT_FULL_CMS_OBJ, "init_full_cms_obj"}, + {MNG_FN_INIT_GAMMA_ONLY_OBJ, "init_gamma_only_obj"}, + {MNG_FN_INIT_APP_CMS, "init_app_cms"}, + {MNG_FN_INIT_APP_CMS_OBJ, "init_app_cms_obj"}, + + {MNG_FN_PROCESS_G1, "process_g1"}, + {MNG_FN_PROCESS_G2, "process_g2"}, + {MNG_FN_PROCESS_G4, "process_g4"}, + {MNG_FN_PROCESS_G8, "process_g8"}, + {MNG_FN_PROCESS_G16, "process_g16"}, + {MNG_FN_PROCESS_RGB8, "process_rgb8"}, + {MNG_FN_PROCESS_RGB16, "process_rgb16"}, + {MNG_FN_PROCESS_IDX1, "process_idx1"}, + {MNG_FN_PROCESS_IDX2, "process_idx2"}, + {MNG_FN_PROCESS_IDX4, "process_idx4"}, + {MNG_FN_PROCESS_IDX8, "process_idx8"}, + {MNG_FN_PROCESS_GA8, "process_ga8"}, + {MNG_FN_PROCESS_GA16, "process_ga16"}, + {MNG_FN_PROCESS_RGBA8, "process_rgba8"}, + {MNG_FN_PROCESS_RGBA16, "process_rgba16"}, + + {MNG_FN_INIT_G1_I, "init_g1_i"}, + {MNG_FN_INIT_G2_I, "init_g2_i"}, + {MNG_FN_INIT_G4_I, "init_g4_i"}, + {MNG_FN_INIT_G8_I, "init_g8_i"}, + {MNG_FN_INIT_G16_I, "init_g16_i"}, + {MNG_FN_INIT_RGB8_I, "init_rgb8_i"}, + {MNG_FN_INIT_RGB16_I, "init_rgb16_i"}, + {MNG_FN_INIT_IDX1_I, "init_idx1_i"}, + {MNG_FN_INIT_IDX2_I, "init_idx2_i"}, + {MNG_FN_INIT_IDX4_I, "init_idx4_i"}, + {MNG_FN_INIT_IDX8_I, "init_idx8_i"}, + {MNG_FN_INIT_GA8_I, "init_ga8_i"}, + {MNG_FN_INIT_GA16_I, "init_ga16_i"}, + {MNG_FN_INIT_RGBA8_I, "init_rgba8_i"}, + {MNG_FN_INIT_RGBA16_I, "init_rgba16_i"}, +#ifndef MNG_OPTIMIZE_FOOTPRINT_INIT + {MNG_FN_INIT_G1_NI, "init_g1_ni"}, + {MNG_FN_INIT_G2_NI, "init_g2_ni"}, + {MNG_FN_INIT_G4_NI, "init_g4_ni"}, + {MNG_FN_INIT_G8_NI, "init_g8_ni"}, + {MNG_FN_INIT_G16_NI, "init_g16_ni"}, + {MNG_FN_INIT_RGB8_NI, "init_rgb8_ni"}, + {MNG_FN_INIT_RGB16_NI, "init_rgb16_ni"}, + {MNG_FN_INIT_IDX1_NI, "init_idx1_ni"}, + {MNG_FN_INIT_IDX2_NI, "init_idx2_ni"}, + {MNG_FN_INIT_IDX4_NI, "init_idx4_ni"}, + {MNG_FN_INIT_IDX8_NI, "init_idx8_ni"}, + {MNG_FN_INIT_GA8_NI, "init_ga8_ni"}, + {MNG_FN_INIT_GA16_NI, "init_ga16_ni"}, + {MNG_FN_INIT_RGBA8_NI, "init_rgba8_ni"}, + {MNG_FN_INIT_RGBA16_NI, "init_rgba16_ni"}, +#endif + + {MNG_FN_INIT_ROWPROC, "init_rowproc"}, + {MNG_FN_NEXT_ROW, "next_row"}, + {MNG_FN_CLEANUP_ROWPROC, "cleanup_rowproc"}, + + {MNG_FN_FILTER_A_ROW, "filter_a_row"}, + {MNG_FN_FILTER_SUB, "filter_sub"}, + {MNG_FN_FILTER_UP, "filter_up"}, + {MNG_FN_FILTER_AVERAGE, "filter_average"}, + {MNG_FN_FILTER_PAETH, "filter_paeth"}, + + {MNG_FN_INIT_ROWDIFFERING, "init_rowdiffering"}, + {MNG_FN_DIFFER_G1, "differ_g1"}, + {MNG_FN_DIFFER_G2, "differ_g2"}, + {MNG_FN_DIFFER_G4, "differ_g4"}, + {MNG_FN_DIFFER_G8, "differ_g8"}, + {MNG_FN_DIFFER_G16, "differ_g16"}, + {MNG_FN_DIFFER_RGB8, "differ_rgb8"}, + {MNG_FN_DIFFER_RGB16, "differ_rgb16"}, + {MNG_FN_DIFFER_IDX1, "differ_idx1"}, + {MNG_FN_DIFFER_IDX2, "differ_idx2"}, + {MNG_FN_DIFFER_IDX4, "differ_idx4"}, + {MNG_FN_DIFFER_IDX8, "differ_idx8"}, + {MNG_FN_DIFFER_GA8, "differ_ga8"}, + {MNG_FN_DIFFER_GA16, "differ_ga16"}, + {MNG_FN_DIFFER_RGBA8, "differ_rgba8"}, + {MNG_FN_DIFFER_RGBA16, "differ_rgba16"}, + + {MNG_FN_CREATE_IMGDATAOBJECT, "create_imgdataobject"}, + {MNG_FN_FREE_IMGDATAOBJECT, "free_imgdataobject"}, + {MNG_FN_CLONE_IMGDATAOBJECT, "clone_imgdataobject"}, + {MNG_FN_CREATE_IMGOBJECT, "create_imgobject"}, + {MNG_FN_FREE_IMGOBJECT, "free_imgobject"}, + {MNG_FN_FIND_IMGOBJECT, "find_imgobject"}, + {MNG_FN_CLONE_IMGOBJECT, "clone_imgobject"}, + {MNG_FN_RESET_OBJECTDETAILS, "reset_objectdetails"}, + {MNG_FN_RENUM_IMGOBJECT, "renum_imgobject"}, + {MNG_FN_PROMOTE_IMGOBJECT, "promote_imgobject"}, + {MNG_FN_MAGNIFY_IMGOBJECT, "magnify_imgobject"}, + {MNG_FN_COLORCORRECT_OBJECT, "colorcorrect_object"}, + + {MNG_FN_STORE_G1, "store_g1"}, + {MNG_FN_STORE_G2, "store_g2"}, + {MNG_FN_STORE_G4, "store_g4"}, + {MNG_FN_STORE_G8, "store_g8"}, + {MNG_FN_STORE_G16, "store_g16"}, + {MNG_FN_STORE_RGB8, "store_rgb8"}, + {MNG_FN_STORE_RGB16, "store_rgb16"}, + {MNG_FN_STORE_IDX1, "store_idx1"}, + {MNG_FN_STORE_IDX2, "store_idx2"}, + {MNG_FN_STORE_IDX4, "store_idx4"}, + {MNG_FN_STORE_IDX8, "store_idx8"}, + {MNG_FN_STORE_GA8, "store_ga8"}, + {MNG_FN_STORE_GA16, "store_ga16"}, + {MNG_FN_STORE_RGBA8, "store_rgba8"}, + {MNG_FN_STORE_RGBA16, "store_rgba16"}, + + {MNG_FN_RETRIEVE_G8, "retrieve_g8"}, + {MNG_FN_RETRIEVE_G16, "retrieve_g16"}, + {MNG_FN_RETRIEVE_RGB8, "retrieve_rgb8"}, + {MNG_FN_RETRIEVE_RGB16, "retrieve_rgb16"}, + {MNG_FN_RETRIEVE_IDX8, "retrieve_idx8"}, + {MNG_FN_RETRIEVE_GA8, "retrieve_ga8"}, + {MNG_FN_RETRIEVE_GA16, "retrieve_ga16"}, + {MNG_FN_RETRIEVE_RGBA8, "retrieve_rgba8"}, + {MNG_FN_RETRIEVE_RGBA16, "retrieve_rgba16"}, + +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_DELTA_G1, "delta_g1"}, + {MNG_FN_DELTA_G2, "delta_g2"}, + {MNG_FN_DELTA_G4, "delta_g4"}, + {MNG_FN_DELTA_G8, "delta_g8"}, + {MNG_FN_DELTA_G16, "delta_g16"}, + {MNG_FN_DELTA_RGB8, "delta_rgb8"}, + {MNG_FN_DELTA_RGB16, "delta_rgb16"}, + {MNG_FN_DELTA_IDX1, "delta_idx1"}, + {MNG_FN_DELTA_IDX2, "delta_idx2"}, + {MNG_FN_DELTA_IDX4, "delta_idx4"}, + {MNG_FN_DELTA_IDX8, "delta_idx8"}, + {MNG_FN_DELTA_GA8, "delta_ga8"}, + {MNG_FN_DELTA_GA16, "delta_ga16"}, + {MNG_FN_DELTA_RGBA8, "delta_rgba8"}, + {MNG_FN_DELTA_RGBA16, "delta_rgba16"}, +#endif + + {MNG_FN_CREATE_ANI_LOOP, "create_ani_loop"}, + {MNG_FN_CREATE_ANI_ENDL, "create_ani_endl"}, + {MNG_FN_CREATE_ANI_DEFI, "create_ani_defi"}, + {MNG_FN_CREATE_ANI_BASI, "create_ani_basi"}, + {MNG_FN_CREATE_ANI_CLON, "create_ani_clon"}, +#ifndef MNG_SKIPCHUNK_PAST + {MNG_FN_CREATE_ANI_PAST, "create_ani_past"}, +#endif + {MNG_FN_CREATE_ANI_DISC, "create_ani_disc"}, + {MNG_FN_CREATE_ANI_BACK, "create_ani_back"}, + {MNG_FN_CREATE_ANI_FRAM, "create_ani_fram"}, + {MNG_FN_CREATE_ANI_MOVE, "create_ani_move"}, + {MNG_FN_CREATE_ANI_CLIP, "create_ani_clip"}, + {MNG_FN_CREATE_ANI_SHOW, "create_ani_show"}, + {MNG_FN_CREATE_ANI_TERM, "create_ani_term"}, + {MNG_FN_CREATE_ANI_SAVE, "create_ani_save"}, + {MNG_FN_CREATE_ANI_SEEK, "create_ani_seek"}, + {MNG_FN_CREATE_ANI_GAMA, "create_ani_gama"}, + {MNG_FN_CREATE_ANI_CHRM, "create_ani_chrm"}, + {MNG_FN_CREATE_ANI_SRGB, "create_ani_srgb"}, + {MNG_FN_CREATE_ANI_ICCP, "create_ani_iccp"}, + {MNG_FN_CREATE_ANI_PLTE, "create_ani_plte"}, + {MNG_FN_CREATE_ANI_TRNS, "create_ani_trns"}, + {MNG_FN_CREATE_ANI_BKGD, "create_ani_bkgd"}, +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_CREATE_ANI_DHDR, "create_ani_dhdr"}, + {MNG_FN_CREATE_ANI_PROM, "create_ani_prom"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_CREATE_ANI_IPNG, "create_ani_ipng"}, +#endif + {MNG_FN_CREATE_ANI_IJNG, "create_ani_ijng"}, + {MNG_FN_CREATE_ANI_PPLT, "create_ani_pplt"}, +#endif + {MNG_FN_CREATE_ANI_MAGN, "create_ani_magn"}, + + {MNG_FN_CREATE_ANI_IMAGE, "create_ani_image"}, + {MNG_FN_CREATE_EVENT, "create_event"}, + + {MNG_FN_FREE_ANI_LOOP, "free_ani_loop"}, + {MNG_FN_FREE_ANI_ENDL, "free_ani_endl"}, + {MNG_FN_FREE_ANI_DEFI, "free_ani_defi"}, + {MNG_FN_FREE_ANI_BASI, "free_ani_basi"}, + {MNG_FN_FREE_ANI_CLON, "free_ani_clon"}, +#ifndef MNG_SKIPCHUNK_PAST + {MNG_FN_FREE_ANI_PAST, "free_ani_past"}, +#endif + {MNG_FN_FREE_ANI_DISC, "free_ani_disc"}, + {MNG_FN_FREE_ANI_BACK, "free_ani_back"}, + {MNG_FN_FREE_ANI_FRAM, "free_ani_fram"}, + {MNG_FN_FREE_ANI_MOVE, "free_ani_move"}, + {MNG_FN_FREE_ANI_CLIP, "free_ani_clip"}, + {MNG_FN_FREE_ANI_SHOW, "free_ani_show"}, + {MNG_FN_FREE_ANI_TERM, "free_ani_term"}, + {MNG_FN_FREE_ANI_SAVE, "free_ani_save"}, + {MNG_FN_FREE_ANI_SEEK, "free_ani_seek"}, + {MNG_FN_FREE_ANI_GAMA, "free_ani_gama"}, + {MNG_FN_FREE_ANI_CHRM, "free_ani_chrm"}, + {MNG_FN_FREE_ANI_SRGB, "free_ani_srgb"}, + {MNG_FN_FREE_ANI_ICCP, "free_ani_iccp"}, + {MNG_FN_FREE_ANI_PLTE, "free_ani_plte"}, + {MNG_FN_FREE_ANI_TRNS, "free_ani_trns"}, + {MNG_FN_FREE_ANI_BKGD, "free_ani_bkgd"}, +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_FREE_ANI_DHDR, "free_ani_dhdr"}, + {MNG_FN_FREE_ANI_PROM, "free_ani_prom"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_FREE_ANI_IPNG, "free_ani_ipng"}, +#endif + {MNG_FN_FREE_ANI_IJNG, "free_ani_ijng"}, + {MNG_FN_FREE_ANI_PPLT, "free_ani_pplt"}, +#endif + {MNG_FN_FREE_ANI_MAGN, "free_ani_magn"}, + + {MNG_FN_FREE_ANI_IMAGE, "free_ani_image"}, + {MNG_FN_FREE_EVENT, "free_event"}, + + {MNG_FN_PROCESS_ANI_LOOP, "process_ani_loop"}, + {MNG_FN_PROCESS_ANI_ENDL, "process_ani_endl"}, + {MNG_FN_PROCESS_ANI_DEFI, "process_ani_defi"}, + {MNG_FN_PROCESS_ANI_BASI, "process_ani_basi"}, + {MNG_FN_PROCESS_ANI_CLON, "process_ani_clon"}, +#ifndef MNG_SKIPCHUNK_PAST + {MNG_FN_PROCESS_ANI_PAST, "process_ani_past"}, +#endif + {MNG_FN_PROCESS_ANI_DISC, "process_ani_disc"}, + {MNG_FN_PROCESS_ANI_BACK, "process_ani_back"}, + {MNG_FN_PROCESS_ANI_FRAM, "process_ani_fram"}, + {MNG_FN_PROCESS_ANI_MOVE, "process_ani_move"}, + {MNG_FN_PROCESS_ANI_CLIP, "process_ani_clip"}, + {MNG_FN_PROCESS_ANI_SHOW, "process_ani_show"}, + {MNG_FN_PROCESS_ANI_TERM, "process_ani_term"}, + {MNG_FN_PROCESS_ANI_SAVE, "process_ani_save"}, + {MNG_FN_PROCESS_ANI_SEEK, "process_ani_seek"}, + {MNG_FN_PROCESS_ANI_GAMA, "process_ani_gama"}, + {MNG_FN_PROCESS_ANI_CHRM, "process_ani_chrm"}, + {MNG_FN_PROCESS_ANI_SRGB, "process_ani_srgb"}, + {MNG_FN_PROCESS_ANI_ICCP, "process_ani_iccp"}, + {MNG_FN_PROCESS_ANI_PLTE, "process_ani_plte"}, + {MNG_FN_PROCESS_ANI_TRNS, "process_ani_trns"}, + {MNG_FN_PROCESS_ANI_BKGD, "process_ani_bkgd"}, +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_PROCESS_ANI_DHDR, "process_ani_dhdr"}, + {MNG_FN_PROCESS_ANI_PROM, "process_ani_prom"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_PROCESS_ANI_IPNG, "process_ani_ipng"}, +#endif + {MNG_FN_PROCESS_ANI_IJNG, "process_ani_ijng"}, + {MNG_FN_PROCESS_ANI_PPLT, "process_ani_pplt"}, +#endif + {MNG_FN_PROCESS_ANI_MAGN, "process_ani_magn"}, + + {MNG_FN_PROCESS_ANI_IMAGE, "process_ani_image"}, + {MNG_FN_PROCESS_EVENT, "process_event"}, + + {MNG_FN_RESTORE_BACKIMAGE, "restore_backimage"}, + {MNG_FN_RESTORE_BACKCOLOR, "restore_backcolor"}, + {MNG_FN_RESTORE_BGCOLOR, "restore_bgcolor"}, + {MNG_FN_RESTORE_RGB8, "restore_rgb8"}, + {MNG_FN_RESTORE_BGR8, "restore_bgr8"}, + {MNG_FN_RESTORE_BKGD, "restore_bkgd"}, + {MNG_FN_RESTORE_BGRX8, "restore_bgrx8"}, + {MNG_FN_RESTORE_RGB565, "restore_rgb565"}, + + {MNG_FN_INIT_IHDR, "init_ihdr"}, + {MNG_FN_INIT_PLTE, "init_plte"}, + {MNG_FN_INIT_IDAT, "init_idat"}, + {MNG_FN_INIT_IEND, "init_iend"}, + {MNG_FN_INIT_TRNS, "init_trns"}, + {MNG_FN_INIT_GAMA, "init_gama"}, + {MNG_FN_INIT_CHRM, "init_chrm"}, + {MNG_FN_INIT_SRGB, "init_srgb"}, + {MNG_FN_INIT_ICCP, "init_iccp"}, + {MNG_FN_INIT_TEXT, "init_text"}, + {MNG_FN_INIT_ZTXT, "init_ztxt"}, + {MNG_FN_INIT_ITXT, "init_itxt"}, + {MNG_FN_INIT_BKGD, "init_bkgd"}, + {MNG_FN_INIT_PHYS, "init_phys"}, + {MNG_FN_INIT_SBIT, "init_sbit"}, + {MNG_FN_INIT_SPLT, "init_splt"}, + {MNG_FN_INIT_HIST, "init_hist"}, + {MNG_FN_INIT_TIME, "init_time"}, + {MNG_FN_INIT_MHDR, "init_mhdr"}, + {MNG_FN_INIT_MEND, "init_mend"}, + {MNG_FN_INIT_LOOP, "init_loop"}, + {MNG_FN_INIT_ENDL, "init_endl"}, + {MNG_FN_INIT_DEFI, "init_defi"}, + {MNG_FN_INIT_BASI, "init_basi"}, + {MNG_FN_INIT_CLON, "init_clon"}, +#ifndef MNG_SKIPCHUNK_PAST + {MNG_FN_INIT_PAST, "init_past"}, +#endif + {MNG_FN_INIT_DISC, "init_disc"}, + {MNG_FN_INIT_BACK, "init_back"}, + {MNG_FN_INIT_FRAM, "init_fram"}, + {MNG_FN_INIT_MOVE, "init_move"}, + {MNG_FN_INIT_CLIP, "init_clip"}, + {MNG_FN_INIT_SHOW, "init_show"}, + {MNG_FN_INIT_TERM, "init_term"}, + {MNG_FN_INIT_SAVE, "init_save"}, + {MNG_FN_INIT_SEEK, "init_seek"}, + {MNG_FN_INIT_EXPI, "init_expi"}, + {MNG_FN_INIT_FPRI, "init_fpri"}, + {MNG_FN_INIT_NEED, "init_need"}, + {MNG_FN_INIT_PHYG, "init_phyg"}, +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_INIT_JHDR, "init_jhdr"}, + {MNG_FN_INIT_JDAT, "init_jdat"}, + {MNG_FN_INIT_JSEP, "init_jsep"}, +#endif +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_INIT_DHDR, "init_dhdr"}, + {MNG_FN_INIT_PROM, "init_prom"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_INIT_IPNG, "init_ipng"}, +#endif + {MNG_FN_INIT_PPLT, "init_pplt"}, + {MNG_FN_INIT_IJNG, "init_ijng"}, + {MNG_FN_INIT_DROP, "init_drop"}, + {MNG_FN_INIT_DBYK, "init_dbyk"}, + {MNG_FN_INIT_ORDR, "init_ordr"}, +#endif + {MNG_FN_INIT_UNKNOWN, "init_unknown"}, + {MNG_FN_INIT_MAGN, "init_magn"}, + {MNG_FN_INIT_JDAA, "init_jdaa"}, + {MNG_FN_INIT_EVNT, "init_evnt"}, +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + {MNG_FN_INIT_MPNG, "init_mpng"}, +#endif + + {MNG_FN_ASSIGN_IHDR, "assign_ihdr"}, + {MNG_FN_ASSIGN_PLTE, "assign_plte"}, + {MNG_FN_ASSIGN_IDAT, "assign_idat"}, + {MNG_FN_ASSIGN_IEND, "assign_iend"}, + {MNG_FN_ASSIGN_TRNS, "assign_trns"}, + {MNG_FN_ASSIGN_GAMA, "assign_gama"}, + {MNG_FN_ASSIGN_CHRM, "assign_chrm"}, + {MNG_FN_ASSIGN_SRGB, "assign_srgb"}, + {MNG_FN_ASSIGN_ICCP, "assign_iccp"}, + {MNG_FN_ASSIGN_TEXT, "assign_text"}, + {MNG_FN_ASSIGN_ZTXT, "assign_ztxt"}, + {MNG_FN_ASSIGN_ITXT, "assign_itxt"}, + {MNG_FN_ASSIGN_BKGD, "assign_bkgd"}, + {MNG_FN_ASSIGN_PHYS, "assign_phys"}, + {MNG_FN_ASSIGN_SBIT, "assign_sbit"}, + {MNG_FN_ASSIGN_SPLT, "assign_splt"}, + {MNG_FN_ASSIGN_HIST, "assign_hist"}, + {MNG_FN_ASSIGN_TIME, "assign_time"}, + {MNG_FN_ASSIGN_MHDR, "assign_mhdr"}, + {MNG_FN_ASSIGN_MEND, "assign_mend"}, + {MNG_FN_ASSIGN_LOOP, "assign_loop"}, + {MNG_FN_ASSIGN_ENDL, "assign_endl"}, + {MNG_FN_ASSIGN_DEFI, "assign_defi"}, + {MNG_FN_ASSIGN_BASI, "assign_basi"}, + {MNG_FN_ASSIGN_CLON, "assign_clon"}, +#ifndef MNG_SKIPCHUNK_PAST + {MNG_FN_ASSIGN_PAST, "assign_past"}, +#endif + {MNG_FN_ASSIGN_DISC, "assign_disc"}, + {MNG_FN_ASSIGN_BACK, "assign_back"}, + {MNG_FN_ASSIGN_FRAM, "assign_fram"}, + {MNG_FN_ASSIGN_MOVE, "assign_move"}, + {MNG_FN_ASSIGN_CLIP, "assign_clip"}, + {MNG_FN_ASSIGN_SHOW, "assign_show"}, + {MNG_FN_ASSIGN_TERM, "assign_term"}, + {MNG_FN_ASSIGN_SAVE, "assign_save"}, + {MNG_FN_ASSIGN_SEEK, "assign_seek"}, + {MNG_FN_ASSIGN_EXPI, "assign_expi"}, + {MNG_FN_ASSIGN_FPRI, "assign_fpri"}, + {MNG_FN_ASSIGN_NEED, "assign_need"}, + {MNG_FN_ASSIGN_PHYG, "assign_phyg"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_ASSIGN_JHDR, "assign_jhdr"}, + {MNG_FN_ASSIGN_JDAT, "assign_jdat"}, + {MNG_FN_ASSIGN_JSEP, "assign_jsep"}, +#endif +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_ASSIGN_DHDR, "assign_dhdr"}, + {MNG_FN_ASSIGN_PROM, "assign_prom"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_ASSIGN_IPNG, "assign_ipng"}, +#endif + {MNG_FN_ASSIGN_PPLT, "assign_pplt"}, + {MNG_FN_ASSIGN_IJNG, "assign_ijng"}, + {MNG_FN_ASSIGN_DROP, "assign_drop"}, + {MNG_FN_ASSIGN_DBYK, "assign_dbyk"}, + {MNG_FN_ASSIGN_ORDR, "assign_ordr"}, +#endif + {MNG_FN_ASSIGN_UNKNOWN, "assign_unknown"}, + {MNG_FN_ASSIGN_MAGN, "assign_magn"}, + {MNG_FN_ASSIGN_JDAA, "assign_jdaa"}, + {MNG_FN_ASSIGN_EVNT, "assign_evnt"}, +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + {MNG_FN_ASSIGN_MPNG, "assign_mpng"}, +#endif + + {MNG_FN_FREE_IHDR, "free_ihdr"}, + {MNG_FN_FREE_PLTE, "free_plte"}, + {MNG_FN_FREE_IDAT, "free_idat"}, + {MNG_FN_FREE_IEND, "free_iend"}, + {MNG_FN_FREE_TRNS, "free_trns"}, + {MNG_FN_FREE_GAMA, "free_gama"}, + {MNG_FN_FREE_CHRM, "free_chrm"}, + {MNG_FN_FREE_SRGB, "free_srgb"}, + {MNG_FN_FREE_ICCP, "free_iccp"}, + {MNG_FN_FREE_TEXT, "free_text"}, + {MNG_FN_FREE_ZTXT, "free_ztxt"}, + {MNG_FN_FREE_ITXT, "free_itxt"}, + {MNG_FN_FREE_BKGD, "free_bkgd"}, + {MNG_FN_FREE_PHYS, "free_phys"}, + {MNG_FN_FREE_SBIT, "free_sbit"}, + {MNG_FN_FREE_SPLT, "free_splt"}, + {MNG_FN_FREE_HIST, "free_hist"}, + {MNG_FN_FREE_TIME, "free_time"}, + {MNG_FN_FREE_MHDR, "free_mhdr"}, + {MNG_FN_FREE_MEND, "free_mend"}, + {MNG_FN_FREE_LOOP, "free_loop"}, + {MNG_FN_FREE_ENDL, "free_endl"}, + {MNG_FN_FREE_DEFI, "free_defi"}, + {MNG_FN_FREE_BASI, "free_basi"}, + {MNG_FN_FREE_CLON, "free_clon"}, +#ifndef MNG_SKIPCHUNK_PAST + {MNG_FN_FREE_PAST, "free_past"}, +#endif + {MNG_FN_FREE_DISC, "free_disc"}, + {MNG_FN_FREE_BACK, "free_back"}, + {MNG_FN_FREE_FRAM, "free_fram"}, + {MNG_FN_FREE_MOVE, "free_move"}, + {MNG_FN_FREE_CLIP, "free_clip"}, + {MNG_FN_FREE_SHOW, "free_show"}, + {MNG_FN_FREE_TERM, "free_term"}, + {MNG_FN_FREE_SAVE, "free_save"}, + {MNG_FN_FREE_SEEK, "free_seek"}, + {MNG_FN_FREE_EXPI, "free_expi"}, + {MNG_FN_FREE_FPRI, "free_fpri"}, + {MNG_FN_FREE_NEED, "free_need"}, + {MNG_FN_FREE_PHYG, "free_phyg"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_FREE_JHDR, "free_jhdr"}, + {MNG_FN_FREE_JDAT, "free_jdat"}, + {MNG_FN_FREE_JSEP, "free_jsep"}, +#endif +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_FREE_DHDR, "free_dhdr"}, + {MNG_FN_FREE_PROM, "free_prom"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_FREE_IPNG, "free_ipng"}, +#endif + {MNG_FN_FREE_PPLT, "free_pplt"}, + {MNG_FN_FREE_IJNG, "free_ijng"}, + {MNG_FN_FREE_DROP, "free_drop"}, + {MNG_FN_FREE_DBYK, "free_dbyk"}, + {MNG_FN_FREE_ORDR, "free_ordr"}, +#endif + {MNG_FN_FREE_UNKNOWN, "free_unknown"}, + {MNG_FN_FREE_MAGN, "free_magn"}, + {MNG_FN_FREE_JDAA, "free_jdaa"}, + {MNG_FN_FREE_EVNT, "free_evnt"}, +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + {MNG_FN_FREE_MPNG, "free_mpng"}, +#endif + + {MNG_FN_READ_IHDR, "read_ihdr"}, + {MNG_FN_READ_PLTE, "read_plte"}, + {MNG_FN_READ_IDAT, "read_idat"}, + {MNG_FN_READ_IEND, "read_iend"}, + {MNG_FN_READ_TRNS, "read_trns"}, + {MNG_FN_READ_GAMA, "read_gama"}, + {MNG_FN_READ_CHRM, "read_chrm"}, + {MNG_FN_READ_SRGB, "read_srgb"}, + {MNG_FN_READ_ICCP, "read_iccp"}, + {MNG_FN_READ_TEXT, "read_text"}, + {MNG_FN_READ_ZTXT, "read_ztxt"}, + {MNG_FN_READ_ITXT, "read_itxt"}, + {MNG_FN_READ_BKGD, "read_bkgd"}, + {MNG_FN_READ_PHYS, "read_phys"}, + {MNG_FN_READ_SBIT, "read_sbit"}, + {MNG_FN_READ_SPLT, "read_splt"}, + {MNG_FN_READ_HIST, "read_hist"}, + {MNG_FN_READ_TIME, "read_time"}, + {MNG_FN_READ_MHDR, "read_mhdr"}, + {MNG_FN_READ_MEND, "read_mend"}, + {MNG_FN_READ_LOOP, "read_loop"}, + {MNG_FN_READ_ENDL, "read_endl"}, + {MNG_FN_READ_DEFI, "read_defi"}, + {MNG_FN_READ_BASI, "read_basi"}, + {MNG_FN_READ_CLON, "read_clon"}, +#ifndef MNG_SKIPCHUNK_PAST + {MNG_FN_READ_PAST, "read_past"}, +#endif + {MNG_FN_READ_DISC, "read_disc"}, + {MNG_FN_READ_BACK, "read_back"}, + {MNG_FN_READ_FRAM, "read_fram"}, + {MNG_FN_READ_MOVE, "read_move"}, + {MNG_FN_READ_CLIP, "read_clip"}, + {MNG_FN_READ_SHOW, "read_show"}, + {MNG_FN_READ_TERM, "read_term"}, + {MNG_FN_READ_SAVE, "read_save"}, + {MNG_FN_READ_SEEK, "read_seek"}, + {MNG_FN_READ_EXPI, "read_expi"}, + {MNG_FN_READ_FPRI, "read_fpri"}, + {MNG_FN_READ_NEED, "read_need"}, + {MNG_FN_READ_PHYG, "read_phyg"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_READ_JHDR, "read_jhdr"}, + {MNG_FN_READ_JDAT, "read_jdat"}, + {MNG_FN_READ_JSEP, "read_jsep"}, +#endif +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_READ_DHDR, "read_dhdr"}, + {MNG_FN_READ_PROM, "read_prom"}, + {MNG_FN_READ_IPNG, "read_ipng"}, + {MNG_FN_READ_PPLT, "read_pplt"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_READ_IJNG, "read_ijng"}, +#endif + {MNG_FN_READ_DROP, "read_drop"}, + {MNG_FN_READ_DBYK, "read_dbyk"}, + {MNG_FN_READ_ORDR, "read_ordr"}, +#endif + {MNG_FN_READ_UNKNOWN, "read_unknown"}, + {MNG_FN_READ_MAGN, "read_magn"}, + {MNG_FN_READ_JDAA, "read_jdaa"}, + {MNG_FN_READ_EVNT, "read_evnt"}, +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + {MNG_FN_READ_MPNG, "read_mpng"}, +#endif + + {MNG_FN_WRITE_IHDR, "write_ihdr"}, + {MNG_FN_WRITE_PLTE, "write_plte"}, + {MNG_FN_WRITE_IDAT, "write_idat"}, + {MNG_FN_WRITE_IEND, "write_iend"}, + {MNG_FN_WRITE_TRNS, "write_trns"}, + {MNG_FN_WRITE_GAMA, "write_gama"}, + {MNG_FN_WRITE_CHRM, "write_chrm"}, + {MNG_FN_WRITE_SRGB, "write_srgb"}, + {MNG_FN_WRITE_ICCP, "write_iccp"}, + {MNG_FN_WRITE_TEXT, "write_text"}, + {MNG_FN_WRITE_ZTXT, "write_ztxt"}, + {MNG_FN_WRITE_ITXT, "write_itxt"}, + {MNG_FN_WRITE_BKGD, "write_bkgd"}, + {MNG_FN_WRITE_PHYS, "write_phys"}, + {MNG_FN_WRITE_SBIT, "write_sbit"}, + {MNG_FN_WRITE_SPLT, "write_splt"}, + {MNG_FN_WRITE_HIST, "write_hist"}, + {MNG_FN_WRITE_TIME, "write_time"}, + {MNG_FN_WRITE_MHDR, "write_mhdr"}, + {MNG_FN_WRITE_MEND, "write_mend"}, + {MNG_FN_WRITE_LOOP, "write_loop"}, + {MNG_FN_WRITE_ENDL, "write_endl"}, + {MNG_FN_WRITE_DEFI, "write_defi"}, + {MNG_FN_WRITE_BASI, "write_basi"}, + {MNG_FN_WRITE_CLON, "write_clon"}, +#ifndef MNG_SKIPCHUNK_PAST + {MNG_FN_WRITE_PAST, "write_past"}, +#endif + {MNG_FN_WRITE_DISC, "write_disc"}, + {MNG_FN_WRITE_BACK, "write_back"}, + {MNG_FN_WRITE_FRAM, "write_fram"}, + {MNG_FN_WRITE_MOVE, "write_move"}, + {MNG_FN_WRITE_CLIP, "write_clip"}, + {MNG_FN_WRITE_SHOW, "write_show"}, + {MNG_FN_WRITE_TERM, "write_term"}, + {MNG_FN_WRITE_SAVE, "write_save"}, + {MNG_FN_WRITE_SEEK, "write_seek"}, + {MNG_FN_WRITE_EXPI, "write_expi"}, + {MNG_FN_WRITE_FPRI, "write_fpri"}, + {MNG_FN_WRITE_NEED, "write_need"}, + {MNG_FN_WRITE_PHYG, "write_phyg"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_WRITE_JHDR, "write_jhdr"}, + {MNG_FN_WRITE_JDAT, "write_jdat"}, + {MNG_FN_WRITE_JSEP, "write_jsep"}, +#endif +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_WRITE_DHDR, "write_dhdr"}, + {MNG_FN_WRITE_PROM, "write_prom"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_WRITE_IPNG, "write_ipng"}, +#endif + {MNG_FN_WRITE_PPLT, "write_pplt"}, + {MNG_FN_WRITE_IJNG, "write_ijng"}, + {MNG_FN_WRITE_DROP, "write_drop"}, + {MNG_FN_WRITE_DBYK, "write_dbyk"}, + {MNG_FN_WRITE_ORDR, "write_ordr"}, +#endif + {MNG_FN_WRITE_UNKNOWN, "write_unknown"}, + {MNG_FN_WRITE_MAGN, "write_magn"}, + {MNG_FN_WRITE_JDAA, "write_jdaa"}, + {MNG_FN_WRITE_EVNT, "write_evnt"}, +#ifdef MNG_INCLUDE_MPNG_PROPOSAL + {MNG_FN_WRITE_MPNG, "write_mpng"}, +#endif + + {MNG_FN_ZLIB_INITIALIZE, "zlib_initialize"}, + {MNG_FN_ZLIB_CLEANUP, "zlib_cleanup"}, + {MNG_FN_ZLIB_INFLATEINIT, "zlib_inflateinit"}, + {MNG_FN_ZLIB_INFLATEROWS, "zlib_inflaterows"}, + {MNG_FN_ZLIB_INFLATEDATA, "zlib_inflatedata"}, + {MNG_FN_ZLIB_INFLATEFREE, "zlib_inflatefree"}, + {MNG_FN_ZLIB_DEFLATEINIT, "zlib_deflateinit"}, + {MNG_FN_ZLIB_DEFLATEROWS, "zlib_deflaterows"}, + {MNG_FN_ZLIB_DEFLATEDATA, "zlib_deflatedata"}, + {MNG_FN_ZLIB_DEFLATEFREE, "zlib_deflatefree"}, + + {MNG_FN_PROCESS_DISPLAY_IHDR, "process_display_ihdr"}, + {MNG_FN_PROCESS_DISPLAY_PLTE, "process_display_plte"}, + {MNG_FN_PROCESS_DISPLAY_IDAT, "process_display_idat"}, + {MNG_FN_PROCESS_DISPLAY_IEND, "process_display_iend"}, + {MNG_FN_PROCESS_DISPLAY_TRNS, "process_display_trns"}, + {MNG_FN_PROCESS_DISPLAY_GAMA, "process_display_gama"}, + {MNG_FN_PROCESS_DISPLAY_CHRM, "process_display_chrm"}, + {MNG_FN_PROCESS_DISPLAY_SRGB, "process_display_srgb"}, + {MNG_FN_PROCESS_DISPLAY_ICCP, "process_display_iccp"}, + {MNG_FN_PROCESS_DISPLAY_BKGD, "process_display_bkgd"}, + {MNG_FN_PROCESS_DISPLAY_PHYS, "process_display_phys"}, + {MNG_FN_PROCESS_DISPLAY_SBIT, "process_display_sbit"}, + {MNG_FN_PROCESS_DISPLAY_SPLT, "process_display_splt"}, + {MNG_FN_PROCESS_DISPLAY_HIST, "process_display_hist"}, + {MNG_FN_PROCESS_DISPLAY_MHDR, "process_display_mhdr"}, + {MNG_FN_PROCESS_DISPLAY_MEND, "process_display_mend"}, + {MNG_FN_PROCESS_DISPLAY_LOOP, "process_display_loop"}, + {MNG_FN_PROCESS_DISPLAY_ENDL, "process_display_endl"}, + {MNG_FN_PROCESS_DISPLAY_DEFI, "process_display_defi"}, + {MNG_FN_PROCESS_DISPLAY_BASI, "process_display_basi"}, + {MNG_FN_PROCESS_DISPLAY_CLON, "process_display_clon"}, +#ifndef MNG_SKIPCHUNK_PAST + {MNG_FN_PROCESS_DISPLAY_PAST, "process_display_past"}, +#endif + {MNG_FN_PROCESS_DISPLAY_DISC, "process_display_disc"}, + {MNG_FN_PROCESS_DISPLAY_BACK, "process_display_back"}, + {MNG_FN_PROCESS_DISPLAY_FRAM, "process_display_fram"}, + {MNG_FN_PROCESS_DISPLAY_MOVE, "process_display_move"}, + {MNG_FN_PROCESS_DISPLAY_CLIP, "process_display_clip"}, + {MNG_FN_PROCESS_DISPLAY_SHOW, "process_display_show"}, + {MNG_FN_PROCESS_DISPLAY_TERM, "process_display_term"}, + {MNG_FN_PROCESS_DISPLAY_SAVE, "process_display_save"}, + {MNG_FN_PROCESS_DISPLAY_SEEK, "process_display_seek"}, + {MNG_FN_PROCESS_DISPLAY_EXPI, "process_display_expi"}, + {MNG_FN_PROCESS_DISPLAY_FPRI, "process_display_fpri"}, + {MNG_FN_PROCESS_DISPLAY_NEED, "process_display_need"}, + {MNG_FN_PROCESS_DISPLAY_PHYG, "process_display_phyg"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_PROCESS_DISPLAY_JHDR, "process_display_jhdr"}, + {MNG_FN_PROCESS_DISPLAY_JDAT, "process_display_jdat"}, + {MNG_FN_PROCESS_DISPLAY_JSEP, "process_display_jsep"}, +#endif +#ifndef MNG_NO_DELTA_PNG + {MNG_FN_PROCESS_DISPLAY_DHDR, "process_display_dhdr"}, + {MNG_FN_PROCESS_DISPLAY_PROM, "process_display_prom"}, +#ifdef MNG_INCLUDE_JNG + {MNG_FN_PROCESS_DISPLAY_IPNG, "process_display_ipng"}, +#endif + {MNG_FN_PROCESS_DISPLAY_PPLT, "process_display_pplt"}, + {MNG_FN_PROCESS_DISPLAY_IJNG, "process_display_ijng"}, + {MNG_FN_PROCESS_DISPLAY_DROP, "process_display_drop"}, + {MNG_FN_PROCESS_DISPLAY_DBYK, "process_display_dbyk"}, + {MNG_FN_PROCESS_DISPLAY_ORDR, "process_display_ordr"}, +#endif + {MNG_FN_PROCESS_DISPLAY_MAGN, "process_display_magn"}, + {MNG_FN_PROCESS_DISPLAY_JDAA, "process_display_jdaa"}, + + {MNG_FN_JPEG_INITIALIZE, "jpeg_initialize"}, + {MNG_FN_JPEG_CLEANUP, "jpeg_cleanup"}, + {MNG_FN_JPEG_DECOMPRESSINIT, "jpeg_decompressinit"}, + {MNG_FN_JPEG_DECOMPRESSDATA, "jpeg_decompressdata"}, + {MNG_FN_JPEG_DECOMPRESSFREE, "jpeg_decompressfree"}, + + {MNG_FN_STORE_JPEG_G8, "store_jpeg_g8"}, + {MNG_FN_STORE_JPEG_RGB8, "store_jpeg_rgb8"}, + {MNG_FN_STORE_JPEG_G12, "store_jpeg_g12"}, + {MNG_FN_STORE_JPEG_RGB12, "store_jpeg_rgb12"}, + {MNG_FN_STORE_JPEG_GA8, "store_jpeg_ga8"}, + {MNG_FN_STORE_JPEG_RGBA8, "store_jpeg_rgba8"}, + {MNG_FN_STORE_JPEG_GA12, "store_jpeg_ga12"}, + {MNG_FN_STORE_JPEG_RGBA12, "store_jpeg_rgba12"}, + {MNG_FN_STORE_JPEG_G8_ALPHA, "store_jpeg_g8_alpha"}, + {MNG_FN_STORE_JPEG_RGB8_ALPHA, "store_jpeg_rgb8_alpha"}, + + {MNG_FN_INIT_JPEG_A1_NI, "init_jpeg_a1_ni"}, + {MNG_FN_INIT_JPEG_A2_NI, "init_jpeg_a2_ni"}, + {MNG_FN_INIT_JPEG_A4_NI, "init_jpeg_a4_ni"}, + {MNG_FN_INIT_JPEG_A8_NI, "init_jpeg_a8_ni"}, + {MNG_FN_INIT_JPEG_A16_NI, "init_jpeg_a16_ni"}, + + {MNG_FN_STORE_JPEG_G8_A1, "store_jpeg_g8_a1"}, + {MNG_FN_STORE_JPEG_G8_A2, "store_jpeg_g8_a2"}, + {MNG_FN_STORE_JPEG_G8_A4, "store_jpeg_g8_a4"}, + {MNG_FN_STORE_JPEG_G8_A8, "store_jpeg_g8_a8"}, + {MNG_FN_STORE_JPEG_G8_A16, "store_jpeg_g8_a16"}, + + {MNG_FN_STORE_JPEG_RGB8_A1, "store_jpeg_rgb8_a1"}, + {MNG_FN_STORE_JPEG_RGB8_A2, "store_jpeg_rgb8_a2"}, + {MNG_FN_STORE_JPEG_RGB8_A4, "store_jpeg_rgb8_a4"}, + {MNG_FN_STORE_JPEG_RGB8_A8, "store_jpeg_rgb8_a8"}, + {MNG_FN_STORE_JPEG_RGB8_A16, "store_jpeg_rgb8_a16"}, + + {MNG_FN_STORE_JPEG_G12_A1, "store_jpeg_g12_a1"}, + {MNG_FN_STORE_JPEG_G12_A2, "store_jpeg_g12_a2"}, + {MNG_FN_STORE_JPEG_G12_A4, "store_jpeg_g12_a4"}, + {MNG_FN_STORE_JPEG_G12_A8, "store_jpeg_g12_a8"}, + {MNG_FN_STORE_JPEG_G12_A16, "store_jpeg_g12_a16"}, + + {MNG_FN_STORE_JPEG_RGB12_A1, "store_jpeg_rgb12_a1"}, + {MNG_FN_STORE_JPEG_RGB12_A2, "store_jpeg_rgb12_a2"}, + {MNG_FN_STORE_JPEG_RGB12_A4, "store_jpeg_rgb12_a4"}, + {MNG_FN_STORE_JPEG_RGB12_A8, "store_jpeg_rgb12_a8"}, + {MNG_FN_STORE_JPEG_RGB12_A16, "store_jpeg_rgb12_a16"}, + + {MNG_FN_NEXT_JPEG_ALPHAROW, "next_jpeg_alpharow"}, + {MNG_FN_NEXT_JPEG_ROW, "next_jpeg_row"}, + {MNG_FN_DISPLAY_JPEG_ROWS, "display_jpeg_rows"}, + + {MNG_FN_MAGNIFY_G8_X1, "magnify_g8_x1"}, + {MNG_FN_MAGNIFY_G8_X2, "magnify_g8_x2"}, + {MNG_FN_MAGNIFY_RGB8_X1, "magnify_rgb8_x1"}, + {MNG_FN_MAGNIFY_RGB8_X2, "magnify_rgb8_x2"}, + {MNG_FN_MAGNIFY_GA8_X1, "magnify_ga8_x1"}, + {MNG_FN_MAGNIFY_GA8_X2, "magnify_ga8_x2"}, + {MNG_FN_MAGNIFY_GA8_X3, "magnify_ga8_x3"}, + {MNG_FN_MAGNIFY_GA8_X4, "magnify_ga8_x4"}, + {MNG_FN_MAGNIFY_RGBA8_X1, "magnify_rgba8_x1"}, + {MNG_FN_MAGNIFY_RGBA8_X2, "magnify_rgba8_x2"}, + {MNG_FN_MAGNIFY_RGBA8_X3, "magnify_rgba8_x3"}, + {MNG_FN_MAGNIFY_RGBA8_X4, "magnify_rgba8_x4"}, + {MNG_FN_MAGNIFY_G8_X3, "magnify_g8_x3"}, + {MNG_FN_MAGNIFY_RGB8_X3, "magnify_rgb8_x3"}, + {MNG_FN_MAGNIFY_GA8_X5, "magnify_ga8_x5"}, + {MNG_FN_MAGNIFY_RGBA8_X5, "magnify_rgba8_x5"}, + + {MNG_FN_MAGNIFY_G8_Y1, "magnify_g8_y1"}, + {MNG_FN_MAGNIFY_G8_Y2, "magnify_g8_y2"}, + {MNG_FN_MAGNIFY_RGB8_Y1, "magnify_rgb8_y1"}, + {MNG_FN_MAGNIFY_RGB8_Y2, "magnify_rgb8_y2"}, + {MNG_FN_MAGNIFY_GA8_Y1, "magnify_ga8_y1"}, + {MNG_FN_MAGNIFY_GA8_Y2, "magnify_ga8_y2"}, + {MNG_FN_MAGNIFY_GA8_Y3, "magnify_ga8_y3"}, + {MNG_FN_MAGNIFY_GA8_Y4, "magnify_ga8_y4"}, + {MNG_FN_MAGNIFY_RGBA8_Y1, "magnify_rgba8_y1"}, + {MNG_FN_MAGNIFY_RGBA8_Y2, "magnify_rgba8_y2"}, + {MNG_FN_MAGNIFY_RGBA8_Y3, "magnify_rgba8_y3"}, + {MNG_FN_MAGNIFY_RGBA8_Y4, "magnify_rgba8_y4"}, + {MNG_FN_MAGNIFY_G8_Y3, "magnify_g8_y3"}, + {MNG_FN_MAGNIFY_RGB8_Y3, "magnify_rgb8_y3"}, + {MNG_FN_MAGNIFY_GA8_Y5, "magnify_ga8_y5"}, + {MNG_FN_MAGNIFY_RGBA8_Y5, "magnify_rgba8_y5"}, + + {MNG_FN_MAGNIFY_G8_X1, "magnify_g8_x1"}, + {MNG_FN_MAGNIFY_G8_X2, "magnify_g8_x2"}, + {MNG_FN_MAGNIFY_RGB8_X1, "magnify_rgb8_x1"}, + {MNG_FN_MAGNIFY_RGB8_X2, "magnify_rgb8_x2"}, + {MNG_FN_MAGNIFY_GA8_X1, "magnify_ga8_x1"}, + {MNG_FN_MAGNIFY_GA8_X2, "magnify_ga8_x2"}, + {MNG_FN_MAGNIFY_GA8_X3, "magnify_ga8_x3"}, + {MNG_FN_MAGNIFY_GA8_X4, "magnify_ga8_x4"}, + {MNG_FN_MAGNIFY_RGBA8_X1, "magnify_rgba8_x1"}, + {MNG_FN_MAGNIFY_RGBA8_X2, "magnify_rgba8_x2"}, + {MNG_FN_MAGNIFY_RGBA8_X3, "magnify_rgba8_x3"}, + {MNG_FN_MAGNIFY_RGBA8_X4, "magnify_rgba8_x4"}, + {MNG_FN_MAGNIFY_G8_X3, "magnify_g8_x3"}, + {MNG_FN_MAGNIFY_RGB8_X3, "magnify_rgb8_x3"}, + {MNG_FN_MAGNIFY_GA8_X5, "magnify_ga8_x5"}, + {MNG_FN_MAGNIFY_RGBA8_X5, "magnify_rgba8_x5"}, + + {MNG_FN_MAGNIFY_G8_Y1, "magnify_g8_y1"}, + {MNG_FN_MAGNIFY_G8_Y2, "magnify_g8_y2"}, + {MNG_FN_MAGNIFY_RGB8_Y1, "magnify_rgb8_y1"}, + {MNG_FN_MAGNIFY_RGB8_Y2, "magnify_rgb8_y2"}, + {MNG_FN_MAGNIFY_GA8_Y1, "magnify_ga8_y1"}, + {MNG_FN_MAGNIFY_GA8_Y2, "magnify_ga8_y2"}, + {MNG_FN_MAGNIFY_GA8_Y3, "magnify_ga8_y3"}, + {MNG_FN_MAGNIFY_GA8_Y4, "magnify_ga8_y4"}, + {MNG_FN_MAGNIFY_RGBA8_Y1, "magnify_rgba8_y1"}, + {MNG_FN_MAGNIFY_RGBA8_Y2, "magnify_rgba8_y2"}, + {MNG_FN_MAGNIFY_RGBA8_Y3, "magnify_rgba8_y3"}, + {MNG_FN_MAGNIFY_RGBA8_Y4, "magnify_rgba8_y4"}, + {MNG_FN_MAGNIFY_G8_Y3, "magnify_g8_y3"}, + {MNG_FN_MAGNIFY_RGB8_Y3, "magnify_rgb8_y3"}, + {MNG_FN_MAGNIFY_GA8_Y5, "magnify_ga8_y5"}, + {MNG_FN_MAGNIFY_RGBA8_Y5, "magnify_rgba8_y5"}, + + {MNG_FN_DELTA_G1_G1, "delta_g1_g1"}, + {MNG_FN_DELTA_G2_G2, "delta_g2_g2"}, + {MNG_FN_DELTA_G4_G4, "delta_g4_g4"}, + {MNG_FN_DELTA_G8_G8, "delta_g8_g8"}, + {MNG_FN_DELTA_G16_G16, "delta_g16_g16"}, + {MNG_FN_DELTA_RGB8_RGB8, "delta_rgb8_rgb8"}, + {MNG_FN_DELTA_RGB16_RGB16, "delta_rgb16_rgb16"}, + {MNG_FN_DELTA_GA8_GA8, "delta_ga8_ga8"}, + {MNG_FN_DELTA_GA8_G8, "delta_ga8_g8"}, + {MNG_FN_DELTA_GA8_A8, "delta_ga8_a8"}, + {MNG_FN_DELTA_GA16_GA16, "delta_ga16_ga16"}, + {MNG_FN_DELTA_GA16_G16, "delta_ga16_g16"}, + {MNG_FN_DELTA_GA16_A16, "delta_ga16_a16"}, + {MNG_FN_DELTA_RGBA8_RGBA8, "delta_rgba8_rgba8"}, + {MNG_FN_DELTA_RGBA8_RGB8, "delta_rgba8_rgb8"}, + {MNG_FN_DELTA_RGBA8_A8, "delta_rgba8_a8"}, + {MNG_FN_DELTA_RGBA16_RGBA16, "delta_rgba16_rgba16"}, + {MNG_FN_DELTA_RGBA16_RGB16, "delta_rgba16_rgb16"}, + {MNG_FN_DELTA_RGBA16_A16, "delta_rgba16_a16"}, + + {MNG_FN_PROMOTE_G8_G8, "promote_g8_g8"}, + {MNG_FN_PROMOTE_G8_G16, "promote_g8_g16"}, + {MNG_FN_PROMOTE_G16_G16, "promote_g8_g16"}, + {MNG_FN_PROMOTE_G8_GA8, "promote_g8_ga8"}, + {MNG_FN_PROMOTE_G8_GA16, "promote_g8_ga16"}, + {MNG_FN_PROMOTE_G16_GA16, "promote_g16_ga16"}, + {MNG_FN_PROMOTE_G8_RGB8, "promote_g8_rgb8"}, + {MNG_FN_PROMOTE_G8_RGB16, "promote_g8_rgb16"}, + {MNG_FN_PROMOTE_G16_RGB16, "promote_g16_rgb16"}, + {MNG_FN_PROMOTE_G8_RGBA8, "promote_g8_rgba8"}, + {MNG_FN_PROMOTE_G8_RGBA16, "promote_g8_rgba16"}, + {MNG_FN_PROMOTE_G16_RGBA16, "promote_g16_rgba16"}, + {MNG_FN_PROMOTE_GA8_GA16, "promote_ga8_ga16"}, + {MNG_FN_PROMOTE_GA8_RGBA8, "promote_ga8_rgba8"}, + {MNG_FN_PROMOTE_GA8_RGBA16, "promote_ga8_rgba16"}, + {MNG_FN_PROMOTE_GA16_RGBA16, "promote_ga16_rgba16"}, + {MNG_FN_PROMOTE_RGB8_RGB16, "promote_rgb8_rgb16"}, + {MNG_FN_PROMOTE_RGB8_RGBA8, "promote_rgb8_rgba8"}, + {MNG_FN_PROMOTE_RGB8_RGBA16, "promote_rgb8_rgba16"}, + {MNG_FN_PROMOTE_RGB16_RGBA16, "promote_rgb16_rgba16"}, + {MNG_FN_PROMOTE_RGBA8_RGBA16, "promote_rgba8_rgba16"}, + {MNG_FN_PROMOTE_IDX8_RGB8, "promote_idx8_rgb8"}, + {MNG_FN_PROMOTE_IDX8_RGB16, "promote_idx8_rgb16"}, + {MNG_FN_PROMOTE_IDX8_RGBA8, "promote_idx8_rgba8"}, + {MNG_FN_PROMOTE_IDX8_RGBA16, "promote_idx8_rgba16"}, + + {MNG_FN_SCALE_G1_G2, "scale_g1_g2"}, + {MNG_FN_SCALE_G1_G4, "scale_g1_g4"}, + {MNG_FN_SCALE_G1_G8, "scale_g1_g8"}, + {MNG_FN_SCALE_G1_G16, "scale_g1_g16"}, + {MNG_FN_SCALE_G2_G4, "scale_g2_g4"}, + {MNG_FN_SCALE_G2_G8, "scale_g2_g8"}, + {MNG_FN_SCALE_G2_G16, "scale_g2_g16"}, + {MNG_FN_SCALE_G4_G8, "scale_g4_g8"}, + {MNG_FN_SCALE_G4_G16, "scale_g4_g16"}, + {MNG_FN_SCALE_G8_G16, "scale_g8_g16"}, + {MNG_FN_SCALE_GA8_GA16, "scale_ga8_ga16"}, + {MNG_FN_SCALE_RGB8_RGB16, "scale_rgb8_rgb16"}, + {MNG_FN_SCALE_RGBA8_RGBA16, "scale_rgba8_rgba16"}, + + {MNG_FN_SCALE_G2_G1, "scale_g2_g1"}, + {MNG_FN_SCALE_G4_G1, "scale_g4_g1"}, + {MNG_FN_SCALE_G8_G1, "scale_g8_g1"}, + {MNG_FN_SCALE_G16_G1, "scale_g16_g1"}, + {MNG_FN_SCALE_G4_G2, "scale_g4_g2"}, + {MNG_FN_SCALE_G8_G2, "scale_g8_g2"}, + {MNG_FN_SCALE_G16_G2, "scale_g16_g2"}, + {MNG_FN_SCALE_G8_G4, "scale_g8_g4"}, + {MNG_FN_SCALE_G16_G4, "scale_g16_g4"}, + {MNG_FN_SCALE_G16_G8, "scale_g16_g8"}, + {MNG_FN_SCALE_GA16_GA8, "scale_ga16_ga8"}, + {MNG_FN_SCALE_RGB16_RGB8, "scale_rgb16_rgb8"}, + {MNG_FN_SCALE_RGBA16_RGBA8, "scale_rgba16_rgba8"}, + + {MNG_FN_COMPOSEOVER_RGBA8, "composeover_rgba8"}, + {MNG_FN_COMPOSEOVER_RGBA16, "composeover_rgba16"}, + {MNG_FN_COMPOSEUNDER_RGBA8, "composeunder_rgba8"}, + {MNG_FN_COMPOSEUNDER_RGBA16, "composeunder_rgba16"}, + + {MNG_FN_FLIP_RGBA8, "flip_rgba8"}, + {MNG_FN_FLIP_RGBA16, "flip_rgba16"}, + {MNG_FN_TILE_RGBA8, "tile_rgba8"}, + {MNG_FN_TILE_RGBA16, "tile_rgba16"} + + }; +#endif /* MNG_INCLUDE_TRACE_STINGS */ + +/* ************************************************************************** */ + +mng_retcode mng_trace (mng_datap pData, + mng_uint32 iFunction, + mng_uint32 iLocation) +{ + mng_pchar zName = 0; /* bufferptr for tracestring */ + + if ((pData == 0) || (pData->iMagic != MNG_MAGIC)) + return MNG_INVALIDHANDLE; /* no good if the handle is corrupt */ + + if (pData->fTraceproc) /* report back to user ? */ + { +#ifdef MNG_INCLUDE_TRACE_STRINGS + { /* binary search variables */ + mng_int32 iTop, iLower, iUpper, iMiddle; + mng_trace_entryp pEntry; /* pointer to found entry */ + /* determine max index of table */ + iTop = (sizeof (trace_table) / sizeof (trace_table [0])) - 1; + + iLower = 0; /* initialize binary search */ + iMiddle = iTop >> 1; /* start in the middle */ + iUpper = iTop; + pEntry = 0; /* no goods yet! */ + + do /* the binary search itself */ + { + if (trace_table [iMiddle].iFunction < iFunction) + iLower = iMiddle + 1; + else if (trace_table [iMiddle].iFunction > iFunction) + iUpper = iMiddle - 1; + else + { + pEntry = &trace_table [iMiddle]; + break; + }; + + iMiddle = (iLower + iUpper) >> 1; + } + while (iLower <= iUpper); + + if (pEntry) /* found it ? */ + zName = pEntry->zTracetext; + + } +#endif + /* oke, now tell */ + if (!pData->fTraceproc (((mng_handle)pData), iFunction, iLocation, zName)) + return MNG_APPTRACEABORT; + + } + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_TRACE_PROCS */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + diff --git a/Source/LibMNG/libmng_write.c b/Source/LibMNG/libmng_write.c index 22ed3a0..79ff544 100644 --- a/Source/LibMNG/libmng_write.c +++ b/Source/LibMNG/libmng_write.c @@ -1,198 +1,198 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_write.c copyright (c) 2000-2004 G.Juyn * */ -/* * version : 1.0.9 * */ -/* * * */ -/* * purpose : Write management (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the write management routines * */ -/* * * */ -/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - changed trace to macro for callback error-reporting * */ -/* * 0.5.1 - 05/16/2000 - G.Juyn * */ -/* * - moved the actual write_graphic functionality from * */ -/* * mng_hlapi to its appropriate function here * */ -/* * * */ -/* * 0.9.1 - 07/19/2000 - G.Juyn * */ -/* * - fixed writing of signature * */ -/* * * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * * */ -/* * 1.0.8 - 07/06/2004 - G.R-P * */ -/* * - added conditionals around openstream/closestream * */ -/* * - defend against using undefined Open/Closestream function * */ -/* * 1.0.8 - 08/02/2004 - G.Juyn * */ -/* * - added conditional to allow easier writing of large MNG's * */ -/* * * */ -/* * 1.0.9 - 09/25/2004 - G.Juyn * */ -/* * - replaced MNG_TWEAK_LARGE_FILES with permanent solution * */ -/* * 1.0.9 - 12/20/2004 - G.Juyn * */ -/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_memory.h" -#include "libmng_chunks.h" -#include "libmng_chunk_io.h" -#include "libmng_write.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ - -#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) -mng_retcode mng_drop_chunks (mng_datap pData) -{ - mng_chunkp pChunk; - mng_chunkp pNext; - mng_cleanupchunk fCleanup; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DROP_CHUNKS, MNG_LC_START); -#endif - - pChunk = pData->pFirstchunk; /* and get first stored chunk (if any) */ - - while (pChunk) /* more chunks to discard ? */ - { - pNext = ((mng_chunk_headerp)pChunk)->pNext; - /* call appropriate cleanup */ - fCleanup = ((mng_chunk_headerp)pChunk)->fCleanup; - fCleanup (pData, pChunk); - - pChunk = pNext; /* neeeext */ - } - - pData->pFirstchunk = MNG_NULL; - pData->pLastchunk = MNG_NULL; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_DROP_CHUNKS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_WRITE_PROCS - -/* ************************************************************************** */ - -mng_retcode mng_write_graphic (mng_datap pData) -{ - mng_chunkp pChunk; - mng_retcode iRetcode; - mng_uint32 iWritten; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_GRAPHIC, MNG_LC_START); -#endif - - pChunk = pData->pFirstchunk; /* we'll start with the first, thank you */ - - if (pChunk) /* is there anything to write ? */ - { /* open the file */ - if (!pData->bWriting) - { -#ifndef MNG_NO_OPEN_CLOSE_STREAM - if (pData->fOpenstream && !pData->fOpenstream ((mng_handle)pData)) - MNG_ERROR (pData, MNG_APPIOERROR); -#endif - { - pData->bWriting = MNG_TRUE; /* indicate writing */ - pData->iWritebufsize = 32768; /* get a temporary write buffer */ - /* reserve 12 bytes for length, chunkname & crc */ - MNG_ALLOC (pData, pData->pWritebuf, pData->iWritebufsize+12); - - /* write the signature */ - if (((mng_chunk_headerp)pChunk)->iChunkname == MNG_UINT_IHDR) - mng_put_uint32 (pData->pWritebuf, PNG_SIG); - else - if (((mng_chunk_headerp)pChunk)->iChunkname == MNG_UINT_JHDR) - mng_put_uint32 (pData->pWritebuf, JNG_SIG); - else - mng_put_uint32 (pData->pWritebuf, MNG_SIG); - - mng_put_uint32 (pData->pWritebuf+4, POST_SIG); - - if (!pData->fWritedata ((mng_handle)pData, pData->pWritebuf, 8, &iWritten)) - { - MNG_FREE (pData, pData->pWritebuf, pData->iWritebufsize+12); - MNG_ERROR (pData, MNG_APPIOERROR); - } - - if (iWritten != 8) /* disk full ? */ - { - MNG_FREE (pData, pData->pWritebuf, pData->iWritebufsize+12); - MNG_ERROR (pData, MNG_OUTPUTERROR); - } - } - } - - while (pChunk) /* so long as there's something to write */ - { /* let's call its output routine */ - iRetcode = ((mng_chunk_headerp)pChunk)->fWrite (pData, pChunk); - if (iRetcode) /* on error bail out */ - return iRetcode; - /* neeeext */ - pChunk = ((mng_chunk_headerp)pChunk)->pNext; - } - - if (!pData->bCreating) - { /* free the temporary buffer */ - MNG_FREE (pData, pData->pWritebuf, pData->iWritebufsize+12); - - pData->bWriting = MNG_FALSE; /* done writing */ - /* close the stream now */ -#ifndef MNG_NO_OPEN_CLOSE_STREAM - if (pData->fClosestream && !pData->fClosestream ((mng_handle)pData)) - MNG_ERROR (pData, MNG_APPIOERROR); -#endif - - } else { - /* cleanup the written chunks */ - iRetcode = mng_drop_chunks (pData); - if (iRetcode) /* on error bail out */ - return iRetcode; - } - } - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_WRITE_GRAPHIC, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_WRITE_PROCS */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_write.c copyright (c) 2000-2004 G.Juyn * */ +/* * version : 1.0.9 * */ +/* * * */ +/* * purpose : Write management (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the write management routines * */ +/* * * */ +/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - changed trace to macro for callback error-reporting * */ +/* * 0.5.1 - 05/16/2000 - G.Juyn * */ +/* * - moved the actual write_graphic functionality from * */ +/* * mng_hlapi to its appropriate function here * */ +/* * * */ +/* * 0.9.1 - 07/19/2000 - G.Juyn * */ +/* * - fixed writing of signature * */ +/* * * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * * */ +/* * 1.0.8 - 07/06/2004 - G.R-P * */ +/* * - added conditionals around openstream/closestream * */ +/* * - defend against using undefined Open/Closestream function * */ +/* * 1.0.8 - 08/02/2004 - G.Juyn * */ +/* * - added conditional to allow easier writing of large MNG's * */ +/* * * */ +/* * 1.0.9 - 09/25/2004 - G.Juyn * */ +/* * - replaced MNG_TWEAK_LARGE_FILES with permanent solution * */ +/* * 1.0.9 - 12/20/2004 - G.Juyn * */ +/* * - cleaned up macro-invocations (thanks to D. Airlie) * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_memory.h" +#include "libmng_chunks.h" +#include "libmng_chunk_io.h" +#include "libmng_write.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ + +#if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE) +mng_retcode mng_drop_chunks (mng_datap pData) +{ + mng_chunkp pChunk; + mng_chunkp pNext; + mng_cleanupchunk fCleanup; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DROP_CHUNKS, MNG_LC_START); +#endif + + pChunk = pData->pFirstchunk; /* and get first stored chunk (if any) */ + + while (pChunk) /* more chunks to discard ? */ + { + pNext = ((mng_chunk_headerp)pChunk)->pNext; + /* call appropriate cleanup */ + fCleanup = ((mng_chunk_headerp)pChunk)->fCleanup; + fCleanup (pData, pChunk); + + pChunk = pNext; /* neeeext */ + } + + pData->pFirstchunk = MNG_NULL; + pData->pLastchunk = MNG_NULL; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_DROP_CHUNKS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */ + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_WRITE_PROCS + +/* ************************************************************************** */ + +mng_retcode mng_write_graphic (mng_datap pData) +{ + mng_chunkp pChunk; + mng_retcode iRetcode; + mng_uint32 iWritten; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_GRAPHIC, MNG_LC_START); +#endif + + pChunk = pData->pFirstchunk; /* we'll start with the first, thank you */ + + if (pChunk) /* is there anything to write ? */ + { /* open the file */ + if (!pData->bWriting) + { +#ifndef MNG_NO_OPEN_CLOSE_STREAM + if (pData->fOpenstream && !pData->fOpenstream ((mng_handle)pData)) + MNG_ERROR (pData, MNG_APPIOERROR); +#endif + { + pData->bWriting = MNG_TRUE; /* indicate writing */ + pData->iWritebufsize = 32768; /* get a temporary write buffer */ + /* reserve 12 bytes for length, chunkname & crc */ + MNG_ALLOC (pData, pData->pWritebuf, pData->iWritebufsize+12); + + /* write the signature */ + if (((mng_chunk_headerp)pChunk)->iChunkname == MNG_UINT_IHDR) + mng_put_uint32 (pData->pWritebuf, PNG_SIG); + else + if (((mng_chunk_headerp)pChunk)->iChunkname == MNG_UINT_JHDR) + mng_put_uint32 (pData->pWritebuf, JNG_SIG); + else + mng_put_uint32 (pData->pWritebuf, MNG_SIG); + + mng_put_uint32 (pData->pWritebuf+4, POST_SIG); + + if (!pData->fWritedata ((mng_handle)pData, pData->pWritebuf, 8, &iWritten)) + { + MNG_FREE (pData, pData->pWritebuf, pData->iWritebufsize+12); + MNG_ERROR (pData, MNG_APPIOERROR); + } + + if (iWritten != 8) /* disk full ? */ + { + MNG_FREE (pData, pData->pWritebuf, pData->iWritebufsize+12); + MNG_ERROR (pData, MNG_OUTPUTERROR); + } + } + } + + while (pChunk) /* so long as there's something to write */ + { /* let's call its output routine */ + iRetcode = ((mng_chunk_headerp)pChunk)->fWrite (pData, pChunk); + if (iRetcode) /* on error bail out */ + return iRetcode; + /* neeeext */ + pChunk = ((mng_chunk_headerp)pChunk)->pNext; + } + + if (!pData->bCreating) + { /* free the temporary buffer */ + MNG_FREE (pData, pData->pWritebuf, pData->iWritebufsize+12); + + pData->bWriting = MNG_FALSE; /* done writing */ + /* close the stream now */ +#ifndef MNG_NO_OPEN_CLOSE_STREAM + if (pData->fClosestream && !pData->fClosestream ((mng_handle)pData)) + MNG_ERROR (pData, MNG_APPIOERROR); +#endif + + } else { + /* cleanup the written chunks */ + iRetcode = mng_drop_chunks (pData); + if (iRetcode) /* on error bail out */ + return iRetcode; + } + } + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_WRITE_GRAPHIC, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_WRITE_PROCS */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + + diff --git a/Source/LibMNG/libmng_zlib.c b/Source/LibMNG/libmng_zlib.c index 894bc74..7d102e1 100644 --- a/Source/LibMNG/libmng_zlib.c +++ b/Source/LibMNG/libmng_zlib.c @@ -1,607 +1,607 @@ -/* ************************************************************************** */ -/* * For conditions of distribution and use, * */ -/* * see copyright notice in libmng.h * */ -/* ************************************************************************** */ -/* * * */ -/* * project : libmng * */ -/* * file : libmng_zlib.c copyright (c) 2000-2004 G.Juyn * */ -/* * version : 1.0.9 * */ -/* * * */ -/* * purpose : ZLIB library interface (implementation) * */ -/* * * */ -/* * author : G.Juyn * */ -/* * * */ -/* * comment : implementation of the ZLIB library interface * */ -/* * * */ -/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ -/* * - changed strict-ANSI stuff * */ -/* * 0.5.1 - 05/11/2000 - G.Juyn * */ -/* * - filled the deflatedata routine * */ -/* * 0.5.1 - 05/12/2000 - G.Juyn * */ -/* * - changed trace to macro for callback error-reporting * */ -/* * * */ -/* * 0.5.2 - 05/20/2000 - G.Juyn * */ -/* * - fixed for JNG alpha handling * */ -/* * 0.5.2 - 05/24/2000 - G.Juyn * */ -/* * - moved init of default zlib parms from here to * */ -/* * "mng_hlapi.c" * */ -/* * * */ -/* * 0.5.3 - 06/16/2000 - G.Juyn * */ -/* * - changed progressive-display processing * */ -/* * * */ -/* * 0.9.2 - 08/05/2000 - G.Juyn * */ -/* * - changed file-prefixes * */ -/* * * */ -/* * 0.9.3 - 08/08/2000 - G.Juyn * */ -/* * - fixed compiler-warnings from Mozilla * */ -/* * 0.9.3 - 09/07/2000 - G.Juyn * */ -/* * - added support for new filter_types * */ -/* * * */ -/* * 1.0.5 - 08/07/2002 - G.Juyn * */ -/* * - added test-option for PNG filter method 193 (=no filter) * */ -/* * 1.0.5 - 08/19/2002 - G.Juyn * */ -/* * - B597134 - libmng pollutes the linker namespace * */ -/* * 1.0.5 - 09/19/2002 - G.Juyn * */ -/* * - added warning for too much IDAT data * */ -/* * * */ -/* * 1.0.6 - 07/07/2003 - G.R-P * */ -/* * - added MNG_NO_16BIT_SUPPORT support * */ -/* * * */ -/* * 1.0.9 - 10/09/2004 - G.R-P * */ -/* * - added MNG_NO_1_2_4BIT_SUPPORT support * */ -/* * * */ -/* ************************************************************************** */ - -#include "libmng.h" -#include "libmng_data.h" -#include "libmng_error.h" -#include "libmng_trace.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif -#include "libmng_memory.h" -#include "libmng_pixels.h" -#include "libmng_filter.h" -#include "libmng_zlib.h" - -#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) -#pragma option -A /* force ANSI-C */ -#endif - -/* ************************************************************************** */ - -#ifdef MNG_INCLUDE_ZLIB - -/* ************************************************************************** */ - -voidpf mngzlib_alloc (voidpf pData, - uInt iCount, - uInt iSize) -{ - voidpf pPtr; /* temporary space */ - -#ifdef MNG_INTERNAL_MEMMNGMT - pPtr = calloc (iCount, iSize); /* local allocation */ -#else - if (((mng_datap)pData)->fMemalloc) /* callback function set ? */ - pPtr = ((mng_datap)pData)->fMemalloc (iCount * iSize); - else - pPtr = Z_NULL; /* can't allocate! */ -#endif - - return pPtr; /* return the result */ -} - -/* ************************************************************************** */ - -void mngzlib_free (voidpf pData, - voidpf pAddress) -{ -#ifdef MNG_INTERNAL_MEMMNGMT - free (pAddress); /* free locally */ -#else - if (((mng_datap)pData)->fMemfree) /* callback set? */ - ((mng_datap)pData)->fMemfree (pAddress, 1); -#endif -} - -/* ************************************************************************** */ - -mng_retcode mngzlib_initialize (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_INITIALIZE, MNG_LC_START); -#endif - -#ifdef MNG_INTERNAL_MEMMNGMT - pData->sZlib.zalloc = Z_NULL; /* let zlib figure out memory management */ - pData->sZlib.zfree = Z_NULL; - pData->sZlib.opaque = Z_NULL; -#else /* use user-provided callbacks */ - pData->sZlib.zalloc = mngzlib_alloc; - pData->sZlib.zfree = mngzlib_free; - pData->sZlib.opaque = (voidpf)pData; -#endif - - pData->bInflating = MNG_FALSE; /* not performing any action yet */ - pData->bDeflating = MNG_FALSE; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_INITIALIZE, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -mng_retcode mngzlib_cleanup (mng_datap pData) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_CLEANUP, MNG_LC_START); -#endif - - if (pData->bInflating) /* force zlib cleanup */ - mngzlib_inflatefree (pData); - if (pData->bDeflating) - mngzlib_deflatefree (pData); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_CLEANUP, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -mng_retcode mngzlib_inflateinit (mng_datap pData) -{ - int iZrslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEINIT, MNG_LC_START); -#endif - /* initialize zlib structures and such */ - iZrslt = inflateInit (&pData->sZlib); - - if (iZrslt != Z_OK) /* on error bail out */ - MNG_ERRORZ (pData, (mng_uint32)iZrslt); - - pData->bInflating = MNG_TRUE; /* really inflating something now */ - pData->sZlib.next_out = 0; /* force JIT initialization */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEINIT, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -#ifdef MNG_SUPPORT_DISPLAY -mng_retcode mngzlib_inflaterows (mng_datap pData, - mng_uint32 iInlen, - mng_uint8p pIndata) -{ - int iZrslt; - mng_retcode iRslt; - mng_ptr pSwap; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEROWS, MNG_LC_START); -#endif - - pData->sZlib.next_in = pIndata; /* let zlib know where to get stuff */ - pData->sZlib.avail_in = (uInt)iInlen; - - if (pData->sZlib.next_out == 0) /* initialize output variables ? */ - { /* let zlib know where to store stuff */ - pData->sZlib.next_out = pData->pWorkrow; - pData->sZlib.avail_out = (uInt)(pData->iRowsize + pData->iPixelofs); -#ifdef MNG_NO_1_2_4BIT_SUPPORT - if (pData->iPNGdepth < 8) - pData->sZlib.avail_out = (uInt)((pData->iPNGdepth*pData->iRowsize + 7)/8 - + pData->iPixelofs); -#endif -#ifdef MNG_NO_16BIT_SUPPORT - if (pData->iPNGdepth > 8) - pData->sZlib.avail_out = (uInt)(2*pData->iRowsize + pData->iPixelofs); -#endif - } - - do - { /* now inflate a row */ - iZrslt = inflate (&pData->sZlib, Z_SYNC_FLUSH); - /* produced a full row ? */ - if (((iZrslt == Z_OK) || (iZrslt == Z_STREAM_END)) && - (pData->sZlib.avail_out == 0)) - { /* image not completed yet ? */ - if (pData->iRow < (mng_int32)pData->iDataheight) - { -#ifdef MNG_NO_1_2_4BIT_SUPPORT - if (pData->iPNGdepth == 1) - { - /* Inflate Workrow to 8-bit */ - mng_int32 iX; - mng_uint8p pSrc = pData->pWorkrow+1; - mng_uint8p pDest = pSrc + pData->iRowsize - (pData->iRowsize+7)/8; - - for (iX = ((pData->iRowsize+7)/8) ; iX > 0 ; iX--) - *pDest++ = *pSrc++; - - pDest = pData->pWorkrow+1; - pSrc = pDest + pData->iRowsize - (pData->iRowsize+7)/8; - for (iX = pData->iRowsize; ;) - { - *pDest++ = (((*pSrc)>>7)&1); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>6)&1); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>5)&1); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>4)&1); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>3)&1); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>2)&1); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>1)&1); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc) )&1); - if (iX-- <= 0) - break; - pSrc++; - } - } - else if (pData->iPNGdepth == 2) - { - /* Inflate Workrow to 8-bit */ - mng_int32 iX; - mng_uint8p pSrc = pData->pWorkrow+1; - mng_uint8p pDest = pSrc + pData->iRowsize - (2*pData->iRowsize+7)/8; - - for (iX = ((2*pData->iRowsize+7)/8) ; iX > 0 ; iX--) - *pDest++ = *pSrc++; - - pDest = pData->pWorkrow+1; - pSrc = pDest + pData->iRowsize - (2*pData->iRowsize+7)/8; - for (iX = pData->iRowsize; ;) - { - *pDest++ = (((*pSrc)>>6)&3); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>4)&3); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc)>>2)&3); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc) )&3); - if (iX-- <= 0) - break; - pSrc++; - } - } - else if (pData->iPNGdepth == 4) - { - /* Inflate Workrow to 8-bit */ - mng_int32 iX; - mng_uint8p pSrc = pData->pWorkrow+1; - mng_uint8p pDest = pSrc + pData->iRowsize - (4*pData->iRowsize+7)/8; - - for (iX = ((4*pData->iRowsize+7)/8) ; iX > 0 ; iX--) - *pDest++ = *pSrc++; - - pDest = pData->pWorkrow+1; - pSrc = pDest + pData->iRowsize - (4*pData->iRowsize+7)/8; - for (iX = pData->iRowsize; ;) - { - *pDest++ = (((*pSrc)>>4)&0x0f); - if (iX-- <= 0) - break; - *pDest++ = (((*pSrc) )&0x0f); - if (iX-- <= 0) - break; - pSrc++; - } - } - if (pData->iPNGdepth < 8 && pData->iColortype == 0) - { - /* Expand samples to 8-bit by LBR */ - mng_int32 iX; - mng_uint8p pSrc = pData->pWorkrow+1; - mng_uint8 multiplier[]={0,255,85,0,17,0,0,0,1}; - - for (iX = pData->iRowsize; iX > 0; iX--) - *pSrc++ *= multiplier[pData->iPNGdepth]; - } -#endif -#ifdef MNG_NO_16BIT_SUPPORT - if (pData->iPNGdepth > 8) - { - /* Reduce Workrow to 8-bit */ - mng_int32 iX; - mng_uint8p pSrc = pData->pWorkrow+1; - mng_uint8p pDest = pSrc; - - for (iX = pData->iRowsize; iX > 0; iX--) - { - *pDest = *pSrc; - pDest++; - pSrc+=2; - } - } -#endif - -#ifdef FILTER192 /* has leveling info ? */ - if (pData->iFilterofs == MNG_FILTER_DIFFERING) - iRslt = init_rowdiffering (pData); - else -#endif - iRslt = MNG_NOERROR; - /* filter the row if necessary */ - if ((!iRslt) && (pData->iFilterofs < pData->iPixelofs ) && - (*(pData->pWorkrow + pData->iFilterofs)) ) - iRslt = mng_filter_a_row (pData); - else - iRslt = MNG_NOERROR; - /* additional leveling/differing ? */ - if ((!iRslt) && (pData->fDifferrow)) - { - iRslt = ((mng_differrow)pData->fDifferrow) (pData); - - pSwap = pData->pWorkrow; - pData->pWorkrow = pData->pPrevrow; - pData->pPrevrow = pSwap; /* make sure we're processing the right data */ - } - - if (!iRslt) - { -#ifdef MNG_INCLUDE_JNG - if (pData->bHasJHDR) /* is JNG alpha-channel ? */ - { /* just store in object ? */ - if ((!iRslt) && (pData->fStorerow)) - iRslt = ((mng_storerow)pData->fStorerow) (pData); - } - else -#endif /* MNG_INCLUDE_JNG */ - { /* process this row */ - if ((!iRslt) && (pData->fProcessrow)) - iRslt = ((mng_processrow)pData->fProcessrow) (pData); - /* store in object ? */ - if ((!iRslt) && (pData->fStorerow)) - iRslt = ((mng_storerow)pData->fStorerow) (pData); - /* color correction ? */ - if ((!iRslt) && (pData->fCorrectrow)) - iRslt = ((mng_correctrow)pData->fCorrectrow) (pData); - /* slap onto canvas ? */ - if ((!iRslt) && (pData->fDisplayrow)) - { - iRslt = ((mng_displayrow)pData->fDisplayrow) (pData); - - if (!iRslt) /* check progressive display refresh */ - iRslt = mng_display_progressive_check (pData); - - } - } - } - - if (iRslt) /* on error bail out */ - MNG_ERROR (pData, iRslt); - - if (!pData->fDifferrow) /* swap row-pointers */ - { - pSwap = pData->pWorkrow; - pData->pWorkrow = pData->pPrevrow; - pData->pPrevrow = pSwap; /* so prev points to the processed row! */ - } - - iRslt = mng_next_row (pData); /* adjust variables for next row */ - - if (iRslt) /* on error bail out */ - MNG_ERROR (pData, iRslt); - } - /* let zlib know where to store next output */ - pData->sZlib.next_out = pData->pWorkrow; - pData->sZlib.avail_out = (uInt)(pData->iRowsize + pData->iPixelofs); -#ifdef MNG_NO_1_2_4BIT_SUPPORT - if (pData->iPNGdepth < 8) - pData->sZlib.avail_out = (uInt)((pData->iPNGdepth*pData->iRowsize + 7)/8 - + pData->iPixelofs); -#endif -#ifdef MNG_NO_16BIT_SUPPORT - if (pData->iPNGdepth > 8) - pData->sZlib.avail_out = (uInt)(2*pData->iRowsize + pData->iPixelofs); -#endif - } - } /* until some error or EOI - or all pixels received */ - while ( (iZrslt == Z_OK) && (pData->sZlib.avail_in > 0) && - ( (pData->iRow < (mng_int32)pData->iDataheight) || - ( (pData->iPass >= 0) && (pData->iPass < 7) ) ) ); - /* on error bail out */ - if ((iZrslt != Z_OK) && (iZrslt != Z_STREAM_END)) - MNG_ERRORZ (pData, (mng_uint32)iZrslt); - /* too much data ? */ - if ((iZrslt == Z_OK) && (pData->sZlib.avail_in > 0)) - MNG_WARNING (pData, MNG_TOOMUCHIDAT); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEROWS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} -#endif /* MNG_SUPPORT_DISPLAY */ - -/* ************************************************************************** */ - -mng_retcode mngzlib_inflatedata (mng_datap pData, - mng_uint32 iInlen, - mng_uint8p pIndata) -{ - int iZrslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEDATA, MNG_LC_START); -#endif - /* let zlib know where to get stuff */ - pData->sZlib.next_in = pIndata; - pData->sZlib.avail_in = (uInt)iInlen; - /* now inflate the data in one go! */ - iZrslt = inflate (&pData->sZlib, Z_FINISH); - /* not enough room in output-buffer ? */ - if ((iZrslt == Z_BUF_ERROR) || (pData->sZlib.avail_in > 0)) - return MNG_BUFOVERFLOW; - /* on error bail out */ - if ((iZrslt != Z_OK) && (iZrslt != Z_STREAM_END)) - MNG_ERRORZ (pData, (mng_uint32)iZrslt); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEDATA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mngzlib_inflatefree (mng_datap pData) -{ - int iZrslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEFREE, MNG_LC_START); -#endif - - pData->bInflating = MNG_FALSE; /* stopped it */ - - iZrslt = inflateEnd (&pData->sZlib); /* let zlib cleanup its own stuff */ - - if (iZrslt != Z_OK) /* on error bail out */ - MNG_ERRORZ (pData, (mng_uint32)iZrslt); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEFREE, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -mng_retcode mngzlib_deflateinit (mng_datap pData) -{ - int iZrslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEINIT, MNG_LC_START); -#endif - /* initialize zlib structures and such */ - iZrslt = deflateInit2 (&pData->sZlib, pData->iZlevel, pData->iZmethod, - pData->iZwindowbits, pData->iZmemlevel, - pData->iZstrategy); - - if (iZrslt != Z_OK) /* on error bail out */ - MNG_ERRORZ (pData, (mng_uint32)iZrslt); - - pData->bDeflating = MNG_TRUE; /* really deflating something now */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEINIT, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -mng_retcode mngzlib_deflaterows (mng_datap pData, - mng_uint32 iInlen, - mng_uint8p pIndata) -{ -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEROWS, MNG_LC_START); -#endif - - - - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEROWS, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mngzlib_deflatedata (mng_datap pData, - mng_uint32 iInlen, - mng_uint8p pIndata) -{ - int iZrslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEDATA, MNG_LC_START); -#endif - - pData->sZlib.next_in = pIndata; /* let zlib know where to get stuff */ - pData->sZlib.avail_in = (uInt)iInlen; - /* now deflate the data in one go! */ - iZrslt = deflate (&pData->sZlib, Z_FINISH); - /* not enough room in output-buffer ? */ - if ((iZrslt == Z_BUF_ERROR) || (pData->sZlib.avail_in > 0)) - return MNG_BUFOVERFLOW; - /* on error bail out */ - if ((iZrslt != Z_OK) && (iZrslt != Z_STREAM_END)) - MNG_ERRORZ (pData, (mng_uint32)iZrslt); - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEDATA, MNG_LC_END); -#endif - - return MNG_NOERROR; -} - -/* ************************************************************************** */ - -mng_retcode mngzlib_deflatefree (mng_datap pData) -{ - int iZrslt; - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEFREE, MNG_LC_START); -#endif - - iZrslt = deflateEnd (&pData->sZlib); /* let zlib cleanup its own stuff */ - - if (iZrslt != Z_OK) /* on error bail out */ - MNG_ERRORZ (pData, (mng_uint32)iZrslt); - - pData->bDeflating = MNG_FALSE; /* stopped it */ - -#ifdef MNG_SUPPORT_TRACE - MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEFREE, MNG_LC_END); -#endif - - return MNG_NOERROR; /* done */ -} - -/* ************************************************************************** */ - -#endif /* MNG_INCLUDE_ZLIB */ - -/* ************************************************************************** */ -/* * end of file * */ -/* ************************************************************************** */ - +/* ************************************************************************** */ +/* * For conditions of distribution and use, * */ +/* * see copyright notice in libmng.h * */ +/* ************************************************************************** */ +/* * * */ +/* * project : libmng * */ +/* * file : libmng_zlib.c copyright (c) 2000-2004 G.Juyn * */ +/* * version : 1.0.9 * */ +/* * * */ +/* * purpose : ZLIB library interface (implementation) * */ +/* * * */ +/* * author : G.Juyn * */ +/* * * */ +/* * comment : implementation of the ZLIB library interface * */ +/* * * */ +/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */ +/* * - changed strict-ANSI stuff * */ +/* * 0.5.1 - 05/11/2000 - G.Juyn * */ +/* * - filled the deflatedata routine * */ +/* * 0.5.1 - 05/12/2000 - G.Juyn * */ +/* * - changed trace to macro for callback error-reporting * */ +/* * * */ +/* * 0.5.2 - 05/20/2000 - G.Juyn * */ +/* * - fixed for JNG alpha handling * */ +/* * 0.5.2 - 05/24/2000 - G.Juyn * */ +/* * - moved init of default zlib parms from here to * */ +/* * "mng_hlapi.c" * */ +/* * * */ +/* * 0.5.3 - 06/16/2000 - G.Juyn * */ +/* * - changed progressive-display processing * */ +/* * * */ +/* * 0.9.2 - 08/05/2000 - G.Juyn * */ +/* * - changed file-prefixes * */ +/* * * */ +/* * 0.9.3 - 08/08/2000 - G.Juyn * */ +/* * - fixed compiler-warnings from Mozilla * */ +/* * 0.9.3 - 09/07/2000 - G.Juyn * */ +/* * - added support for new filter_types * */ +/* * * */ +/* * 1.0.5 - 08/07/2002 - G.Juyn * */ +/* * - added test-option for PNG filter method 193 (=no filter) * */ +/* * 1.0.5 - 08/19/2002 - G.Juyn * */ +/* * - B597134 - libmng pollutes the linker namespace * */ +/* * 1.0.5 - 09/19/2002 - G.Juyn * */ +/* * - added warning for too much IDAT data * */ +/* * * */ +/* * 1.0.6 - 07/07/2003 - G.R-P * */ +/* * - added MNG_NO_16BIT_SUPPORT support * */ +/* * * */ +/* * 1.0.9 - 10/09/2004 - G.R-P * */ +/* * - added MNG_NO_1_2_4BIT_SUPPORT support * */ +/* * * */ +/* ************************************************************************** */ + +#include "libmng.h" +#include "libmng_data.h" +#include "libmng_error.h" +#include "libmng_trace.h" +#ifdef __BORLANDC__ +#pragma hdrstop +#endif +#include "libmng_memory.h" +#include "libmng_pixels.h" +#include "libmng_filter.h" +#include "libmng_zlib.h" + +#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI) +#pragma option -A /* force ANSI-C */ +#endif + +/* ************************************************************************** */ + +#ifdef MNG_INCLUDE_ZLIB + +/* ************************************************************************** */ + +voidpf mngzlib_alloc (voidpf pData, + uInt iCount, + uInt iSize) +{ + voidpf pPtr; /* temporary space */ + +#ifdef MNG_INTERNAL_MEMMNGMT + pPtr = calloc (iCount, iSize); /* local allocation */ +#else + if (((mng_datap)pData)->fMemalloc) /* callback function set ? */ + pPtr = ((mng_datap)pData)->fMemalloc (iCount * iSize); + else + pPtr = Z_NULL; /* can't allocate! */ +#endif + + return pPtr; /* return the result */ +} + +/* ************************************************************************** */ + +void mngzlib_free (voidpf pData, + voidpf pAddress) +{ +#ifdef MNG_INTERNAL_MEMMNGMT + free (pAddress); /* free locally */ +#else + if (((mng_datap)pData)->fMemfree) /* callback set? */ + ((mng_datap)pData)->fMemfree (pAddress, 1); +#endif +} + +/* ************************************************************************** */ + +mng_retcode mngzlib_initialize (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_INITIALIZE, MNG_LC_START); +#endif + +#ifdef MNG_INTERNAL_MEMMNGMT + pData->sZlib.zalloc = Z_NULL; /* let zlib figure out memory management */ + pData->sZlib.zfree = Z_NULL; + pData->sZlib.opaque = Z_NULL; +#else /* use user-provided callbacks */ + pData->sZlib.zalloc = mngzlib_alloc; + pData->sZlib.zfree = mngzlib_free; + pData->sZlib.opaque = (voidpf)pData; +#endif + + pData->bInflating = MNG_FALSE; /* not performing any action yet */ + pData->bDeflating = MNG_FALSE; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_INITIALIZE, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +mng_retcode mngzlib_cleanup (mng_datap pData) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_CLEANUP, MNG_LC_START); +#endif + + if (pData->bInflating) /* force zlib cleanup */ + mngzlib_inflatefree (pData); + if (pData->bDeflating) + mngzlib_deflatefree (pData); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_CLEANUP, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +mng_retcode mngzlib_inflateinit (mng_datap pData) +{ + int iZrslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEINIT, MNG_LC_START); +#endif + /* initialize zlib structures and such */ + iZrslt = inflateInit (&pData->sZlib); + + if (iZrslt != Z_OK) /* on error bail out */ + MNG_ERRORZ (pData, (mng_uint32)iZrslt); + + pData->bInflating = MNG_TRUE; /* really inflating something now */ + pData->sZlib.next_out = 0; /* force JIT initialization */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEINIT, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +#ifdef MNG_SUPPORT_DISPLAY +mng_retcode mngzlib_inflaterows (mng_datap pData, + mng_uint32 iInlen, + mng_uint8p pIndata) +{ + int iZrslt; + mng_retcode iRslt; + mng_ptr pSwap; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEROWS, MNG_LC_START); +#endif + + pData->sZlib.next_in = pIndata; /* let zlib know where to get stuff */ + pData->sZlib.avail_in = (uInt)iInlen; + + if (pData->sZlib.next_out == 0) /* initialize output variables ? */ + { /* let zlib know where to store stuff */ + pData->sZlib.next_out = pData->pWorkrow; + pData->sZlib.avail_out = (uInt)(pData->iRowsize + pData->iPixelofs); +#ifdef MNG_NO_1_2_4BIT_SUPPORT + if (pData->iPNGdepth < 8) + pData->sZlib.avail_out = (uInt)((pData->iPNGdepth*pData->iRowsize + 7)/8 + + pData->iPixelofs); +#endif +#ifdef MNG_NO_16BIT_SUPPORT + if (pData->iPNGdepth > 8) + pData->sZlib.avail_out = (uInt)(2*pData->iRowsize + pData->iPixelofs); +#endif + } + + do + { /* now inflate a row */ + iZrslt = inflate (&pData->sZlib, Z_SYNC_FLUSH); + /* produced a full row ? */ + if (((iZrslt == Z_OK) || (iZrslt == Z_STREAM_END)) && + (pData->sZlib.avail_out == 0)) + { /* image not completed yet ? */ + if (pData->iRow < (mng_int32)pData->iDataheight) + { +#ifdef MNG_NO_1_2_4BIT_SUPPORT + if (pData->iPNGdepth == 1) + { + /* Inflate Workrow to 8-bit */ + mng_int32 iX; + mng_uint8p pSrc = pData->pWorkrow+1; + mng_uint8p pDest = pSrc + pData->iRowsize - (pData->iRowsize+7)/8; + + for (iX = ((pData->iRowsize+7)/8) ; iX > 0 ; iX--) + *pDest++ = *pSrc++; + + pDest = pData->pWorkrow+1; + pSrc = pDest + pData->iRowsize - (pData->iRowsize+7)/8; + for (iX = pData->iRowsize; ;) + { + *pDest++ = (((*pSrc)>>7)&1); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>6)&1); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>5)&1); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>4)&1); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>3)&1); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>2)&1); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>1)&1); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc) )&1); + if (iX-- <= 0) + break; + pSrc++; + } + } + else if (pData->iPNGdepth == 2) + { + /* Inflate Workrow to 8-bit */ + mng_int32 iX; + mng_uint8p pSrc = pData->pWorkrow+1; + mng_uint8p pDest = pSrc + pData->iRowsize - (2*pData->iRowsize+7)/8; + + for (iX = ((2*pData->iRowsize+7)/8) ; iX > 0 ; iX--) + *pDest++ = *pSrc++; + + pDest = pData->pWorkrow+1; + pSrc = pDest + pData->iRowsize - (2*pData->iRowsize+7)/8; + for (iX = pData->iRowsize; ;) + { + *pDest++ = (((*pSrc)>>6)&3); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>4)&3); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc)>>2)&3); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc) )&3); + if (iX-- <= 0) + break; + pSrc++; + } + } + else if (pData->iPNGdepth == 4) + { + /* Inflate Workrow to 8-bit */ + mng_int32 iX; + mng_uint8p pSrc = pData->pWorkrow+1; + mng_uint8p pDest = pSrc + pData->iRowsize - (4*pData->iRowsize+7)/8; + + for (iX = ((4*pData->iRowsize+7)/8) ; iX > 0 ; iX--) + *pDest++ = *pSrc++; + + pDest = pData->pWorkrow+1; + pSrc = pDest + pData->iRowsize - (4*pData->iRowsize+7)/8; + for (iX = pData->iRowsize; ;) + { + *pDest++ = (((*pSrc)>>4)&0x0f); + if (iX-- <= 0) + break; + *pDest++ = (((*pSrc) )&0x0f); + if (iX-- <= 0) + break; + pSrc++; + } + } + if (pData->iPNGdepth < 8 && pData->iColortype == 0) + { + /* Expand samples to 8-bit by LBR */ + mng_int32 iX; + mng_uint8p pSrc = pData->pWorkrow+1; + mng_uint8 multiplier[]={0,255,85,0,17,0,0,0,1}; + + for (iX = pData->iRowsize; iX > 0; iX--) + *pSrc++ *= multiplier[pData->iPNGdepth]; + } +#endif +#ifdef MNG_NO_16BIT_SUPPORT + if (pData->iPNGdepth > 8) + { + /* Reduce Workrow to 8-bit */ + mng_int32 iX; + mng_uint8p pSrc = pData->pWorkrow+1; + mng_uint8p pDest = pSrc; + + for (iX = pData->iRowsize; iX > 0; iX--) + { + *pDest = *pSrc; + pDest++; + pSrc+=2; + } + } +#endif + +#ifdef FILTER192 /* has leveling info ? */ + if (pData->iFilterofs == MNG_FILTER_DIFFERING) + iRslt = init_rowdiffering (pData); + else +#endif + iRslt = MNG_NOERROR; + /* filter the row if necessary */ + if ((!iRslt) && (pData->iFilterofs < pData->iPixelofs ) && + (*(pData->pWorkrow + pData->iFilterofs)) ) + iRslt = mng_filter_a_row (pData); + else + iRslt = MNG_NOERROR; + /* additional leveling/differing ? */ + if ((!iRslt) && (pData->fDifferrow)) + { + iRslt = ((mng_differrow)pData->fDifferrow) (pData); + + pSwap = pData->pWorkrow; + pData->pWorkrow = pData->pPrevrow; + pData->pPrevrow = pSwap; /* make sure we're processing the right data */ + } + + if (!iRslt) + { +#ifdef MNG_INCLUDE_JNG + if (pData->bHasJHDR) /* is JNG alpha-channel ? */ + { /* just store in object ? */ + if ((!iRslt) && (pData->fStorerow)) + iRslt = ((mng_storerow)pData->fStorerow) (pData); + } + else +#endif /* MNG_INCLUDE_JNG */ + { /* process this row */ + if ((!iRslt) && (pData->fProcessrow)) + iRslt = ((mng_processrow)pData->fProcessrow) (pData); + /* store in object ? */ + if ((!iRslt) && (pData->fStorerow)) + iRslt = ((mng_storerow)pData->fStorerow) (pData); + /* color correction ? */ + if ((!iRslt) && (pData->fCorrectrow)) + iRslt = ((mng_correctrow)pData->fCorrectrow) (pData); + /* slap onto canvas ? */ + if ((!iRslt) && (pData->fDisplayrow)) + { + iRslt = ((mng_displayrow)pData->fDisplayrow) (pData); + + if (!iRslt) /* check progressive display refresh */ + iRslt = mng_display_progressive_check (pData); + + } + } + } + + if (iRslt) /* on error bail out */ + MNG_ERROR (pData, iRslt); + + if (!pData->fDifferrow) /* swap row-pointers */ + { + pSwap = pData->pWorkrow; + pData->pWorkrow = pData->pPrevrow; + pData->pPrevrow = pSwap; /* so prev points to the processed row! */ + } + + iRslt = mng_next_row (pData); /* adjust variables for next row */ + + if (iRslt) /* on error bail out */ + MNG_ERROR (pData, iRslt); + } + /* let zlib know where to store next output */ + pData->sZlib.next_out = pData->pWorkrow; + pData->sZlib.avail_out = (uInt)(pData->iRowsize + pData->iPixelofs); +#ifdef MNG_NO_1_2_4BIT_SUPPORT + if (pData->iPNGdepth < 8) + pData->sZlib.avail_out = (uInt)((pData->iPNGdepth*pData->iRowsize + 7)/8 + + pData->iPixelofs); +#endif +#ifdef MNG_NO_16BIT_SUPPORT + if (pData->iPNGdepth > 8) + pData->sZlib.avail_out = (uInt)(2*pData->iRowsize + pData->iPixelofs); +#endif + } + } /* until some error or EOI + or all pixels received */ + while ( (iZrslt == Z_OK) && (pData->sZlib.avail_in > 0) && + ( (pData->iRow < (mng_int32)pData->iDataheight) || + ( (pData->iPass >= 0) && (pData->iPass < 7) ) ) ); + /* on error bail out */ + if ((iZrslt != Z_OK) && (iZrslt != Z_STREAM_END)) + MNG_ERRORZ (pData, (mng_uint32)iZrslt); + /* too much data ? */ + if ((iZrslt == Z_OK) && (pData->sZlib.avail_in > 0)) + MNG_WARNING (pData, MNG_TOOMUCHIDAT); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEROWS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} +#endif /* MNG_SUPPORT_DISPLAY */ + +/* ************************************************************************** */ + +mng_retcode mngzlib_inflatedata (mng_datap pData, + mng_uint32 iInlen, + mng_uint8p pIndata) +{ + int iZrslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEDATA, MNG_LC_START); +#endif + /* let zlib know where to get stuff */ + pData->sZlib.next_in = pIndata; + pData->sZlib.avail_in = (uInt)iInlen; + /* now inflate the data in one go! */ + iZrslt = inflate (&pData->sZlib, Z_FINISH); + /* not enough room in output-buffer ? */ + if ((iZrslt == Z_BUF_ERROR) || (pData->sZlib.avail_in > 0)) + return MNG_BUFOVERFLOW; + /* on error bail out */ + if ((iZrslt != Z_OK) && (iZrslt != Z_STREAM_END)) + MNG_ERRORZ (pData, (mng_uint32)iZrslt); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEDATA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mngzlib_inflatefree (mng_datap pData) +{ + int iZrslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEFREE, MNG_LC_START); +#endif + + pData->bInflating = MNG_FALSE; /* stopped it */ + + iZrslt = inflateEnd (&pData->sZlib); /* let zlib cleanup its own stuff */ + + if (iZrslt != Z_OK) /* on error bail out */ + MNG_ERRORZ (pData, (mng_uint32)iZrslt); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_INFLATEFREE, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +mng_retcode mngzlib_deflateinit (mng_datap pData) +{ + int iZrslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEINIT, MNG_LC_START); +#endif + /* initialize zlib structures and such */ + iZrslt = deflateInit2 (&pData->sZlib, pData->iZlevel, pData->iZmethod, + pData->iZwindowbits, pData->iZmemlevel, + pData->iZstrategy); + + if (iZrslt != Z_OK) /* on error bail out */ + MNG_ERRORZ (pData, (mng_uint32)iZrslt); + + pData->bDeflating = MNG_TRUE; /* really deflating something now */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEINIT, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +mng_retcode mngzlib_deflaterows (mng_datap pData, + mng_uint32 iInlen, + mng_uint8p pIndata) +{ +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEROWS, MNG_LC_START); +#endif + + + + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEROWS, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mngzlib_deflatedata (mng_datap pData, + mng_uint32 iInlen, + mng_uint8p pIndata) +{ + int iZrslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEDATA, MNG_LC_START); +#endif + + pData->sZlib.next_in = pIndata; /* let zlib know where to get stuff */ + pData->sZlib.avail_in = (uInt)iInlen; + /* now deflate the data in one go! */ + iZrslt = deflate (&pData->sZlib, Z_FINISH); + /* not enough room in output-buffer ? */ + if ((iZrslt == Z_BUF_ERROR) || (pData->sZlib.avail_in > 0)) + return MNG_BUFOVERFLOW; + /* on error bail out */ + if ((iZrslt != Z_OK) && (iZrslt != Z_STREAM_END)) + MNG_ERRORZ (pData, (mng_uint32)iZrslt); + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEDATA, MNG_LC_END); +#endif + + return MNG_NOERROR; +} + +/* ************************************************************************** */ + +mng_retcode mngzlib_deflatefree (mng_datap pData) +{ + int iZrslt; + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEFREE, MNG_LC_START); +#endif + + iZrslt = deflateEnd (&pData->sZlib); /* let zlib cleanup its own stuff */ + + if (iZrslt != Z_OK) /* on error bail out */ + MNG_ERRORZ (pData, (mng_uint32)iZrslt); + + pData->bDeflating = MNG_FALSE; /* stopped it */ + +#ifdef MNG_SUPPORT_TRACE + MNG_TRACE (pData, MNG_FN_ZLIB_DEFLATEFREE, MNG_LC_END); +#endif + + return MNG_NOERROR; /* done */ +} + +/* ************************************************************************** */ + +#endif /* MNG_INCLUDE_ZLIB */ + +/* ************************************************************************** */ +/* * end of file * */ +/* ************************************************************************** */ + diff --git a/Source/LibOpenJPEG/LICENSE b/Source/LibOpenJPEG/LICENSE index 88bd07a..f7b3b66 100644 --- a/Source/LibOpenJPEG/LICENSE +++ b/Source/LibOpenJPEG/LICENSE @@ -1,31 +1,31 @@ -/* - * Copyright (c) 2002-2012, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2012, Professor Benoit Macq - * Copyright (c) 2003-2012, Antonin Descampe - * Copyright (c) 2003-2009, Francois-Olivier Devaux - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2001-2003, David Janssens - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ +/* + * Copyright (c) 2002-2012, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2012, Professor Benoit Macq + * Copyright (c) 2003-2012, Antonin Descampe + * Copyright (c) 2003-2009, Francois-Olivier Devaux + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2001-2003, David Janssens + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ diff --git a/Source/LibOpenJPEG/bio.c b/Source/LibOpenJPEG/bio.c index 9438ff1..4c02f46 100644 --- a/Source/LibOpenJPEG/bio.c +++ b/Source/LibOpenJPEG/bio.c @@ -1,187 +1,187 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/** @defgroup BIO BIO - Individual bit input-output stream */ -/*@{*/ - -/** @name Local static functions */ -/*@{*/ - -/** -Write a bit -@param bio BIO handle -@param b Bit to write (0 or 1) -*/ -static void bio_putbit(opj_bio_t *bio, int b); -/** -Read a bit -@param bio BIO handle -@return Returns the read bit -*/ -static int bio_getbit(opj_bio_t *bio); -/** -Write a byte -@param bio BIO handle -@return Returns 0 if successful, returns 1 otherwise -*/ -static int bio_byteout(opj_bio_t *bio); -/** -Read a byte -@param bio BIO handle -@return Returns 0 if successful, returns 1 otherwise -*/ -static int bio_bytein(opj_bio_t *bio); - -/*@}*/ - -/*@}*/ - -/* -========================================================== - local functions -========================================================== -*/ - -static int bio_byteout(opj_bio_t *bio) { - bio->buf = (bio->buf << 8) & 0xffff; - bio->ct = bio->buf == 0xff00 ? 7 : 8; - if (bio->bp >= bio->end) { - return 1; - } - *bio->bp++ = bio->buf >> 8; - return 0; -} - -static int bio_bytein(opj_bio_t *bio) { - bio->buf = (bio->buf << 8) & 0xffff; - bio->ct = bio->buf == 0xff00 ? 7 : 8; - if (bio->bp >= bio->end) { - return 1; - } - bio->buf |= *bio->bp++; - return 0; -} - -static void bio_putbit(opj_bio_t *bio, int b) { - if (bio->ct == 0) { - bio_byteout(bio); - } - bio->ct--; - bio->buf |= b << bio->ct; -} - -static int bio_getbit(opj_bio_t *bio) { - if (bio->ct == 0) { - bio_bytein(bio); - } - bio->ct--; - return (bio->buf >> bio->ct) & 1; -} - -/* -========================================================== - Bit Input/Output interface -========================================================== -*/ - -opj_bio_t* bio_create(void) { - opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t)); - return bio; -} - -void bio_destroy(opj_bio_t *bio) { - if(bio) { - opj_free(bio); - } -} - -int bio_numbytes(opj_bio_t *bio) { - return (bio->bp - bio->start); -} - -void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) { - bio->start = bp; - bio->end = bp + len; - bio->bp = bp; - bio->buf = 0; - bio->ct = 8; -} - -void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) { - bio->start = bp; - bio->end = bp + len; - bio->bp = bp; - bio->buf = 0; - bio->ct = 0; -} - -void bio_write(opj_bio_t *bio, int v, int n) { - int i; - for (i = n - 1; i >= 0; i--) { - bio_putbit(bio, (v >> i) & 1); - } -} - -int bio_read(opj_bio_t *bio, int n) { - int i, v; - v = 0; - for (i = n - 1; i >= 0; i--) { - v += bio_getbit(bio) << i; - } - return v; -} - -int bio_flush(opj_bio_t *bio) { - bio->ct = 0; - if (bio_byteout(bio)) { - return 1; - } - if (bio->ct == 7) { - bio->ct = 0; - if (bio_byteout(bio)) { - return 1; - } - } - return 0; -} - -int bio_inalign(opj_bio_t *bio) { - bio->ct = 0; - if ((bio->buf & 0xff) == 0xff) { - if (bio_bytein(bio)) { - return 1; - } - bio->ct = 0; - } - return 0; -} +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/** @defgroup BIO BIO - Individual bit input-output stream */ +/*@{*/ + +/** @name Local static functions */ +/*@{*/ + +/** +Write a bit +@param bio BIO handle +@param b Bit to write (0 or 1) +*/ +static void bio_putbit(opj_bio_t *bio, int b); +/** +Read a bit +@param bio BIO handle +@return Returns the read bit +*/ +static int bio_getbit(opj_bio_t *bio); +/** +Write a byte +@param bio BIO handle +@return Returns 0 if successful, returns 1 otherwise +*/ +static int bio_byteout(opj_bio_t *bio); +/** +Read a byte +@param bio BIO handle +@return Returns 0 if successful, returns 1 otherwise +*/ +static int bio_bytein(opj_bio_t *bio); + +/*@}*/ + +/*@}*/ + +/* +========================================================== + local functions +========================================================== +*/ + +static int bio_byteout(opj_bio_t *bio) { + bio->buf = (bio->buf << 8) & 0xffff; + bio->ct = bio->buf == 0xff00 ? 7 : 8; + if (bio->bp >= bio->end) { + return 1; + } + *bio->bp++ = bio->buf >> 8; + return 0; +} + +static int bio_bytein(opj_bio_t *bio) { + bio->buf = (bio->buf << 8) & 0xffff; + bio->ct = bio->buf == 0xff00 ? 7 : 8; + if (bio->bp >= bio->end) { + return 1; + } + bio->buf |= *bio->bp++; + return 0; +} + +static void bio_putbit(opj_bio_t *bio, int b) { + if (bio->ct == 0) { + bio_byteout(bio); + } + bio->ct--; + bio->buf |= b << bio->ct; +} + +static int bio_getbit(opj_bio_t *bio) { + if (bio->ct == 0) { + bio_bytein(bio); + } + bio->ct--; + return (bio->buf >> bio->ct) & 1; +} + +/* +========================================================== + Bit Input/Output interface +========================================================== +*/ + +opj_bio_t* bio_create(void) { + opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t)); + return bio; +} + +void bio_destroy(opj_bio_t *bio) { + if(bio) { + opj_free(bio); + } +} + +int bio_numbytes(opj_bio_t *bio) { + return (bio->bp - bio->start); +} + +void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) { + bio->start = bp; + bio->end = bp + len; + bio->bp = bp; + bio->buf = 0; + bio->ct = 8; +} + +void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) { + bio->start = bp; + bio->end = bp + len; + bio->bp = bp; + bio->buf = 0; + bio->ct = 0; +} + +void bio_write(opj_bio_t *bio, int v, int n) { + int i; + for (i = n - 1; i >= 0; i--) { + bio_putbit(bio, (v >> i) & 1); + } +} + +int bio_read(opj_bio_t *bio, int n) { + int i, v; + v = 0; + for (i = n - 1; i >= 0; i--) { + v += bio_getbit(bio) << i; + } + return v; +} + +int bio_flush(opj_bio_t *bio) { + bio->ct = 0; + if (bio_byteout(bio)) { + return 1; + } + if (bio->ct == 7) { + bio->ct = 0; + if (bio_byteout(bio)) { + return 1; + } + } + return 0; +} + +int bio_inalign(opj_bio_t *bio) { + bio->ct = 0; + if ((bio->buf & 0xff) == 0xff) { + if (bio_bytein(bio)) { + return 1; + } + bio->ct = 0; + } + return 0; +} diff --git a/Source/LibOpenJPEG/bio.h b/Source/LibOpenJPEG/bio.h index 81f93f3..764d7cb 100644 --- a/Source/LibOpenJPEG/bio.h +++ b/Source/LibOpenJPEG/bio.h @@ -1,125 +1,125 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __BIO_H -#define __BIO_H -/** -@file bio.h -@brief Implementation of an individual bit input-output (BIO) - -The functions in BIO.C have for goal to realize an individual bit input - output. -*/ - -/** @defgroup BIO BIO - Individual bit input-output stream */ -/*@{*/ - -/** -Individual bit input-output stream (BIO) -*/ -typedef struct opj_bio { - /** pointer to the start of the buffer */ - unsigned char *start; - /** pointer to the end of the buffer */ - unsigned char *end; - /** pointer to the present position in the buffer */ - unsigned char *bp; - /** temporary place where each byte is read or written */ - unsigned int buf; - /** coder : number of bits free to write. decoder : number of bits read */ - int ct; -} opj_bio_t; - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Create a new BIO handle -@return Returns a new BIO handle if successful, returns NULL otherwise -*/ -opj_bio_t* bio_create(void); -/** -Destroy a previously created BIO handle -@param bio BIO handle to destroy -*/ -void bio_destroy(opj_bio_t *bio); -/** -Number of bytes written. -@param bio BIO handle -@return Returns the number of bytes written -*/ -int bio_numbytes(opj_bio_t *bio); -/** -Init encoder -@param bio BIO handle -@param bp Output buffer -@param len Output buffer length -*/ -void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len); -/** -Init decoder -@param bio BIO handle -@param bp Input buffer -@param len Input buffer length -*/ -void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len); -/** -Write bits -@param bio BIO handle -@param v Value of bits -@param n Number of bits to write -*/ -void bio_write(opj_bio_t *bio, int v, int n); -/** -Read bits -@param bio BIO handle -@param n Number of bits to read -@return Returns the corresponding read number -*/ -int bio_read(opj_bio_t *bio, int n); -/** -Flush bits -@param bio BIO handle -@return Returns 1 if successful, returns 0 otherwise -*/ -int bio_flush(opj_bio_t *bio); -/** -Passes the ending bits (coming from flushing) -@param bio BIO handle -@return Returns 1 if successful, returns 0 otherwise -*/ -int bio_inalign(opj_bio_t *bio); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __BIO_H */ - +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __BIO_H +#define __BIO_H +/** +@file bio.h +@brief Implementation of an individual bit input-output (BIO) + +The functions in BIO.C have for goal to realize an individual bit input - output. +*/ + +/** @defgroup BIO BIO - Individual bit input-output stream */ +/*@{*/ + +/** +Individual bit input-output stream (BIO) +*/ +typedef struct opj_bio { + /** pointer to the start of the buffer */ + unsigned char *start; + /** pointer to the end of the buffer */ + unsigned char *end; + /** pointer to the present position in the buffer */ + unsigned char *bp; + /** temporary place where each byte is read or written */ + unsigned int buf; + /** coder : number of bits free to write. decoder : number of bits read */ + int ct; +} opj_bio_t; + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Create a new BIO handle +@return Returns a new BIO handle if successful, returns NULL otherwise +*/ +opj_bio_t* bio_create(void); +/** +Destroy a previously created BIO handle +@param bio BIO handle to destroy +*/ +void bio_destroy(opj_bio_t *bio); +/** +Number of bytes written. +@param bio BIO handle +@return Returns the number of bytes written +*/ +int bio_numbytes(opj_bio_t *bio); +/** +Init encoder +@param bio BIO handle +@param bp Output buffer +@param len Output buffer length +*/ +void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len); +/** +Init decoder +@param bio BIO handle +@param bp Input buffer +@param len Input buffer length +*/ +void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len); +/** +Write bits +@param bio BIO handle +@param v Value of bits +@param n Number of bits to write +*/ +void bio_write(opj_bio_t *bio, int v, int n); +/** +Read bits +@param bio BIO handle +@param n Number of bits to read +@return Returns the corresponding read number +*/ +int bio_read(opj_bio_t *bio, int n); +/** +Flush bits +@param bio BIO handle +@return Returns 1 if successful, returns 0 otherwise +*/ +int bio_flush(opj_bio_t *bio); +/** +Passes the ending bits (coming from flushing) +@param bio BIO handle +@return Returns 1 if successful, returns 0 otherwise +*/ +int bio_inalign(opj_bio_t *bio); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __BIO_H */ + diff --git a/Source/LibOpenJPEG/cidx_manager.c b/Source/LibOpenJPEG/cidx_manager.c index 778683e..b63142f 100644 --- a/Source/LibOpenJPEG/cidx_manager.c +++ b/Source/LibOpenJPEG/cidx_manager.c @@ -1,211 +1,211 @@ -/* - * $Id: cidx_manager.c,v 1.2 2012/09/23 12:44:41 drolon Exp $ - * - * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2011, Professor Benoit Macq - * Copyright (c) 2003-2004, Yannick Verschueren - * Copyright (c) 2010-2011, Kaori Hagihara - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - - -/* - * Write CPTR Codestream finder box - * - * @param[in] coff offset of j2k codestream - * @param[in] clen length of j2k codestream - * @param[in] cio file output handle - */ -void write_cptr(int coff, int clen, opj_cio_t *cio); - - -/* - * Write main header index table (box) - * - * @param[in] coff offset of j2k codestream - * @param[in] cstr_info codestream information - * @param[in] cio file output handle - * @return length of mainmhix box - */ -int write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio); - - -/* - * Check if EPH option is used - * - * @param[in] coff offset of j2k codestream - * @param[in] markers marker information - * @param[in] marknum number of markers - * @param[in] cio file output handle - * @return true if EPH is used - */ -opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_cio_t *cio); - - -int write_cidx( int offset, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t cstr_info, int j2klen) -{ - int len, i, lenp; - opj_jp2_box_t *box; - int num_box = 0; - opj_bool EPHused; - (void)image; /* unused ? */ - - lenp = -1; - box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t)); - - for (i=0;i<2;i++){ - - if(i) - cio_seek( cio, lenp); - - lenp = cio_tell( cio); - - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_CIDX, 4); /* CIDX */ - write_cptr( offset, cstr_info.codestream_size, cio); - - write_manf( i, num_box, box, cio); - - num_box = 0; - box[num_box].length = write_mainmhix( offset, cstr_info, cio); - box[num_box].type = JPIP_MHIX; - num_box++; - - box[num_box].length = write_tpix( offset, cstr_info, j2klen, cio); - box[num_box].type = JPIP_TPIX; - num_box++; - - box[num_box].length = write_thix( offset, cstr_info, cio); - box[num_box].type = JPIP_THIX; - num_box++; - - EPHused = check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio); - - box[num_box].length = write_ppix( offset, cstr_info, EPHused, j2klen, cio); - box[num_box].type = JPIP_PPIX; - num_box++; - - box[num_box].length = write_phix( offset, cstr_info, EPHused, j2klen, cio); - box[num_box].type = JPIP_PHIX; - num_box++; - - len = cio_tell( cio)-lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); - } - - opj_free( box); - - return len; -} - -void write_cptr(int coff, int clen, opj_cio_t *cio) -{ - int len, lenp; - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_CPTR, 4); /* T */ - cio_write( cio, 0, 2); /* DR A PRECISER !! */ - cio_write( cio, 0, 2); /* CONT */ - cio_write( cio, coff, 8); /* COFF A PRECISER !! */ - cio_write( cio, clen, 8); /* CLEN */ - len = cio_tell( cio) - lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); -} - -void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio) -{ - int len, lenp, i; - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_MANF,4); /* T */ - - if (second){ /* Write only during the second pass */ - for( i=0; i> 2) & 1)) - EPHused = OPJ_TRUE; - cio_seek( cio, org_pos); - - break; - } - } - return EPHused; -} +/* + * $Id: cidx_manager.c,v 1.2 2012/09/23 12:44:41 drolon Exp $ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2003-2004, Yannick Verschueren + * Copyright (c) 2010-2011, Kaori Hagihara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + + +/* + * Write CPTR Codestream finder box + * + * @param[in] coff offset of j2k codestream + * @param[in] clen length of j2k codestream + * @param[in] cio file output handle + */ +void write_cptr(int coff, int clen, opj_cio_t *cio); + + +/* + * Write main header index table (box) + * + * @param[in] coff offset of j2k codestream + * @param[in] cstr_info codestream information + * @param[in] cio file output handle + * @return length of mainmhix box + */ +int write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio); + + +/* + * Check if EPH option is used + * + * @param[in] coff offset of j2k codestream + * @param[in] markers marker information + * @param[in] marknum number of markers + * @param[in] cio file output handle + * @return true if EPH is used + */ +opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_cio_t *cio); + + +int write_cidx( int offset, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t cstr_info, int j2klen) +{ + int len, i, lenp; + opj_jp2_box_t *box; + int num_box = 0; + opj_bool EPHused; + (void)image; /* unused ? */ + + lenp = -1; + box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t)); + + for (i=0;i<2;i++){ + + if(i) + cio_seek( cio, lenp); + + lenp = cio_tell( cio); + + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_CIDX, 4); /* CIDX */ + write_cptr( offset, cstr_info.codestream_size, cio); + + write_manf( i, num_box, box, cio); + + num_box = 0; + box[num_box].length = write_mainmhix( offset, cstr_info, cio); + box[num_box].type = JPIP_MHIX; + num_box++; + + box[num_box].length = write_tpix( offset, cstr_info, j2klen, cio); + box[num_box].type = JPIP_TPIX; + num_box++; + + box[num_box].length = write_thix( offset, cstr_info, cio); + box[num_box].type = JPIP_THIX; + num_box++; + + EPHused = check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio); + + box[num_box].length = write_ppix( offset, cstr_info, EPHused, j2klen, cio); + box[num_box].type = JPIP_PPIX; + num_box++; + + box[num_box].length = write_phix( offset, cstr_info, EPHused, j2klen, cio); + box[num_box].type = JPIP_PHIX; + num_box++; + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); + } + + opj_free( box); + + return len; +} + +void write_cptr(int coff, int clen, opj_cio_t *cio) +{ + int len, lenp; + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_CPTR, 4); /* T */ + cio_write( cio, 0, 2); /* DR A PRECISER !! */ + cio_write( cio, 0, 2); /* CONT */ + cio_write( cio, coff, 8); /* COFF A PRECISER !! */ + cio_write( cio, clen, 8); /* CLEN */ + len = cio_tell( cio) - lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); +} + +void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio) +{ + int len, lenp, i; + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_MANF,4); /* T */ + + if (second){ /* Write only during the second pass */ + for( i=0; i> 2) & 1)) + EPHused = OPJ_TRUE; + cio_seek( cio, org_pos); + + break; + } + } + return EPHused; +} diff --git a/Source/LibOpenJPEG/cidx_manager.h b/Source/LibOpenJPEG/cidx_manager.h index 91bb3fb..c1a69d9 100644 --- a/Source/LibOpenJPEG/cidx_manager.h +++ b/Source/LibOpenJPEG/cidx_manager.h @@ -1,56 +1,56 @@ -/* - * $Id: cidx_manager.h,v 1.2 2012/09/23 12:44:41 drolon Exp $ - * - * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2011, Professor Benoit Macq - * Copyright (c) 2003-2004, Yannick Verschueren - * Copyright (c) 2010-2011, Kaori Hagihara - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/*! \file - * \brief Modification of jpip.h from 2KAN indexer - */ - - -#ifndef CIDX_MANAGER_H_ -# define CIDX_MANAGER_H_ - -#include "openjpeg.h" - - -/* - * Write Codestream index box (superbox) - * - * @param[in] offset offset of j2k codestream - * @param[in] cio file output handle - * @param[in] image image data - * @param[in] cstr_info codestream information - * @param[in] j2klen length of j2k codestream - * @return length of cidx box - */ -int write_cidx( int offset, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t cstr_info, int j2klen); - - -#endif /* !CIDX_MANAGER_H_ */ +/* + * $Id: cidx_manager.h,v 1.2 2012/09/23 12:44:41 drolon Exp $ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2003-2004, Yannick Verschueren + * Copyright (c) 2010-2011, Kaori Hagihara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*! \file + * \brief Modification of jpip.h from 2KAN indexer + */ + + +#ifndef CIDX_MANAGER_H_ +# define CIDX_MANAGER_H_ + +#include "openjpeg.h" + + +/* + * Write Codestream index box (superbox) + * + * @param[in] offset offset of j2k codestream + * @param[in] cio file output handle + * @param[in] image image data + * @param[in] cstr_info codestream information + * @param[in] j2klen length of j2k codestream + * @return length of cidx box + */ +int write_cidx( int offset, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t cstr_info, int j2klen); + + +#endif /* !CIDX_MANAGER_H_ */ diff --git a/Source/LibOpenJPEG/cio.c b/Source/LibOpenJPEG/cio.c index 1a428ed..c0cb028 100644 --- a/Source/LibOpenJPEG/cio.c +++ b/Source/LibOpenJPEG/cio.c @@ -1,191 +1,191 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/* ----------------------------------------------------------------------- */ - -opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) { - opj_cp_t *cp = NULL; - opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t)); - if(!cio) return NULL; - cio->cinfo = cinfo; - if(buffer && length) { - /* wrap a user buffer containing the encoded image */ - cio->openmode = OPJ_STREAM_READ; - cio->buffer = buffer; - cio->length = length; - } - else if(!buffer && !length && cinfo) { - /* allocate a buffer for the encoded image */ - cio->openmode = OPJ_STREAM_WRITE; - switch(cinfo->codec_format) { - case CODEC_J2K: - cp = ((opj_j2k_t*)cinfo->j2k_handle)->cp; - break; - case CODEC_JP2: - cp = ((opj_jp2_t*)cinfo->jp2_handle)->j2k->cp; - break; - default: - opj_free(cio); - return NULL; - } - cio->length = (unsigned int) (0.1625 * cp->img_size + 2000); /* 0.1625 = 1.3/8 and 2000 bytes as a minimum for headers */ - cio->buffer = (unsigned char *)opj_malloc(cio->length); - if(!cio->buffer) { - opj_event_msg(cio->cinfo, EVT_ERROR, "Error allocating memory for compressed bitstream\n"); - opj_free(cio); - return NULL; - } - } - else { - opj_free(cio); - return NULL; - } - - /* Initialize byte IO */ - cio->start = cio->buffer; - cio->end = cio->buffer + cio->length; - cio->bp = cio->buffer; - - return cio; -} - -void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) { - if(cio) { - if(cio->openmode == OPJ_STREAM_WRITE) { - /* destroy the allocated buffer */ - opj_free(cio->buffer); - } - /* destroy the cio */ - opj_free(cio); - } -} - - -/* ----------------------------------------------------------------------- */ - -/* - * Get position in byte stream. - */ -int OPJ_CALLCONV cio_tell(opj_cio_t *cio) { - return cio->bp - cio->start; -} - -/* - * Set position in byte stream. - * - * pos : position, in number of bytes, from the beginning of the stream - */ -void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) { - cio->bp = cio->start + pos; -} - -/* - * Number of bytes left before the end of the stream. - */ -int cio_numbytesleft(opj_cio_t *cio) { - return cio->end - cio->bp; -} - -/* - * Get pointer to the current position in the stream. - */ -unsigned char *cio_getbp(opj_cio_t *cio) { - return cio->bp; -} - -/* - * Write a byte. - */ -opj_bool cio_byteout(opj_cio_t *cio, unsigned char v) { - if (cio->bp >= cio->end) { - opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n"); - return OPJ_FALSE; - } - *cio->bp++ = v; - return OPJ_TRUE; -} - -/* - * Read a byte. - */ -unsigned char cio_bytein(opj_cio_t *cio) { - if (cio->bp >= cio->end) { - opj_event_msg(cio->cinfo, EVT_ERROR, "read error: passed the end of the codestream (start = %d, current = %d, end = %d\n", cio->start, cio->bp, cio->end); - return 0; - } - return *cio->bp++; -} - -/* - * Write some bytes. - * - * v : value to write - * n : number of bytes to write - */ -unsigned int cio_write(opj_cio_t *cio, unsigned int64 v, int n) { - int i; - for (i = n - 1; i >= 0; i--) { - if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) ) - return 0; - } - return n; -} - -/* - * Read some bytes. - * - * n : number of bytes to read - * - * return : value of the n bytes read - */ -unsigned int cio_read(opj_cio_t *cio, int n) { - int i; - unsigned int v; - v = 0; - for (i = n - 1; i >= 0; i--) { - v += cio_bytein(cio) << (i << 3); - } - return v; -} - -/* - * Skip some bytes. - * - * n : number of bytes to skip - */ -void cio_skip(opj_cio_t *cio, int n) { - cio->bp += n; -} - - - +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/* ----------------------------------------------------------------------- */ + +opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) { + opj_cp_t *cp = NULL; + opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t)); + if(!cio) return NULL; + cio->cinfo = cinfo; + if(buffer && length) { + /* wrap a user buffer containing the encoded image */ + cio->openmode = OPJ_STREAM_READ; + cio->buffer = buffer; + cio->length = length; + } + else if(!buffer && !length && cinfo) { + /* allocate a buffer for the encoded image */ + cio->openmode = OPJ_STREAM_WRITE; + switch(cinfo->codec_format) { + case CODEC_J2K: + cp = ((opj_j2k_t*)cinfo->j2k_handle)->cp; + break; + case CODEC_JP2: + cp = ((opj_jp2_t*)cinfo->jp2_handle)->j2k->cp; + break; + default: + opj_free(cio); + return NULL; + } + cio->length = (unsigned int) (0.1625 * cp->img_size + 2000); /* 0.1625 = 1.3/8 and 2000 bytes as a minimum for headers */ + cio->buffer = (unsigned char *)opj_malloc(cio->length); + if(!cio->buffer) { + opj_event_msg(cio->cinfo, EVT_ERROR, "Error allocating memory for compressed bitstream\n"); + opj_free(cio); + return NULL; + } + } + else { + opj_free(cio); + return NULL; + } + + /* Initialize byte IO */ + cio->start = cio->buffer; + cio->end = cio->buffer + cio->length; + cio->bp = cio->buffer; + + return cio; +} + +void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) { + if(cio) { + if(cio->openmode == OPJ_STREAM_WRITE) { + /* destroy the allocated buffer */ + opj_free(cio->buffer); + } + /* destroy the cio */ + opj_free(cio); + } +} + + +/* ----------------------------------------------------------------------- */ + +/* + * Get position in byte stream. + */ +int OPJ_CALLCONV cio_tell(opj_cio_t *cio) { + return cio->bp - cio->start; +} + +/* + * Set position in byte stream. + * + * pos : position, in number of bytes, from the beginning of the stream + */ +void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) { + cio->bp = cio->start + pos; +} + +/* + * Number of bytes left before the end of the stream. + */ +int cio_numbytesleft(opj_cio_t *cio) { + return cio->end - cio->bp; +} + +/* + * Get pointer to the current position in the stream. + */ +unsigned char *cio_getbp(opj_cio_t *cio) { + return cio->bp; +} + +/* + * Write a byte. + */ +opj_bool cio_byteout(opj_cio_t *cio, unsigned char v) { + if (cio->bp >= cio->end) { + opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n"); + return OPJ_FALSE; + } + *cio->bp++ = v; + return OPJ_TRUE; +} + +/* + * Read a byte. + */ +unsigned char cio_bytein(opj_cio_t *cio) { + if (cio->bp >= cio->end) { + opj_event_msg(cio->cinfo, EVT_ERROR, "read error: passed the end of the codestream (start = %d, current = %d, end = %d\n", cio->start, cio->bp, cio->end); + return 0; + } + return *cio->bp++; +} + +/* + * Write some bytes. + * + * v : value to write + * n : number of bytes to write + */ +unsigned int cio_write(opj_cio_t *cio, unsigned int64 v, int n) { + int i; + for (i = n - 1; i >= 0; i--) { + if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) ) + return 0; + } + return n; +} + +/* + * Read some bytes. + * + * n : number of bytes to read + * + * return : value of the n bytes read + */ +unsigned int cio_read(opj_cio_t *cio, int n) { + int i; + unsigned int v; + v = 0; + for (i = n - 1; i >= 0; i--) { + v += cio_bytein(cio) << (i << 3); + } + return v; +} + +/* + * Skip some bytes. + * + * n : number of bytes to skip + */ +void cio_skip(opj_cio_t *cio, int n) { + cio->bp += n; +} + + + diff --git a/Source/LibOpenJPEG/cio.h b/Source/LibOpenJPEG/cio.h index cccaf91..e627431 100644 --- a/Source/LibOpenJPEG/cio.h +++ b/Source/LibOpenJPEG/cio.h @@ -1,93 +1,93 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __CIO_H -#define __CIO_H - -#if defined(_MSC_VER) || defined(__BORLANDC__) -#define int64 __int64 -#else -#define int64 long long -#endif - -/** -@file cio.h -@brief Implementation of a byte input-output process (CIO) - -The functions in CIO.C have for goal to realize a byte input / output process. -*/ - -/** @defgroup CIO CIO - byte input-output stream */ -/*@{*/ - -/** @name Exported functions (see also openjpeg.h) */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Number of bytes left before the end of the stream -@param cio CIO handle -@return Returns the number of bytes before the end of the stream -*/ -int cio_numbytesleft(opj_cio_t *cio); -/** -Get pointer to the current position in the stream -@param cio CIO handle -@return Returns a pointer to the current position -*/ -unsigned char *cio_getbp(opj_cio_t *cio); -/** -Write some bytes -@param cio CIO handle -@param v Value to write -@param n Number of bytes to write -@return Returns the number of bytes written or 0 if an error occured -*/ -unsigned int cio_write(opj_cio_t *cio, unsigned int64 v, int n); -/** -Read some bytes -@param cio CIO handle -@param n Number of bytes to read -@return Returns the value of the n bytes read -*/ -unsigned int cio_read(opj_cio_t *cio, int n); -/** -Skip some bytes -@param cio CIO handle -@param n Number of bytes to skip -*/ -void cio_skip(opj_cio_t *cio, int n); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __CIO_H */ - +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __CIO_H +#define __CIO_H + +#if defined(_MSC_VER) || defined(__BORLANDC__) +#define int64 __int64 +#else +#define int64 long long +#endif + +/** +@file cio.h +@brief Implementation of a byte input-output process (CIO) + +The functions in CIO.C have for goal to realize a byte input / output process. +*/ + +/** @defgroup CIO CIO - byte input-output stream */ +/*@{*/ + +/** @name Exported functions (see also openjpeg.h) */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Number of bytes left before the end of the stream +@param cio CIO handle +@return Returns the number of bytes before the end of the stream +*/ +int cio_numbytesleft(opj_cio_t *cio); +/** +Get pointer to the current position in the stream +@param cio CIO handle +@return Returns a pointer to the current position +*/ +unsigned char *cio_getbp(opj_cio_t *cio); +/** +Write some bytes +@param cio CIO handle +@param v Value to write +@param n Number of bytes to write +@return Returns the number of bytes written or 0 if an error occured +*/ +unsigned int cio_write(opj_cio_t *cio, unsigned int64 v, int n); +/** +Read some bytes +@param cio CIO handle +@param n Number of bytes to read +@return Returns the value of the n bytes read +*/ +unsigned int cio_read(opj_cio_t *cio, int n); +/** +Skip some bytes +@param cio CIO handle +@param n Number of bytes to skip +*/ +void cio_skip(opj_cio_t *cio, int n); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __CIO_H */ + diff --git a/Source/LibOpenJPEG/dwt.c b/Source/LibOpenJPEG/dwt.c index 6f9b12d..0fbfc20 100644 --- a/Source/LibOpenJPEG/dwt.c +++ b/Source/LibOpenJPEG/dwt.c @@ -1,858 +1,858 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2007, Jonathan Ballard - * Copyright (c) 2007, Callum Lerwick - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef __SSE__ -#include -#endif - -#include "opj_includes.h" - -/** @defgroup DWT DWT - Implementation of a discrete wavelet transform */ -/*@{*/ - -#define WS(i) v->mem[(i)*2] -#define WD(i) v->mem[(1+(i)*2)] - -/** @name Local data structures */ -/*@{*/ - -typedef struct dwt_local { - int* mem; - int dn; - int sn; - int cas; -} dwt_t; - -typedef union { - float f[4]; -} v4; - -typedef struct v4dwt_local { - v4* wavelet ; - int dn ; - int sn ; - int cas ; -} v4dwt_t ; - -static const float dwt_alpha = 1.586134342f; /* 12994 */ -static const float dwt_beta = 0.052980118f; /* 434 */ -static const float dwt_gamma = -0.882911075f; /* -7233 */ -static const float dwt_delta = -0.443506852f; /* -3633 */ - -static const float K = 1.230174105f; /* 10078 */ -/* FIXME: What is this constant? */ -static const float c13318 = 1.625732422f; - -/*@}*/ - -/** -Virtual function type for wavelet transform in 1-D -*/ -typedef void (*DWT1DFN)(dwt_t* v); - -/** @name Local static functions */ -/*@{*/ - -/** -Forward lazy transform (horizontal) -*/ -static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas); -/** -Forward lazy transform (vertical) -*/ -static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas); -/** -Inverse lazy transform (horizontal) -*/ -static void dwt_interleave_h(dwt_t* h, int *a); -/** -Inverse lazy transform (vertical) -*/ -static void dwt_interleave_v(dwt_t* v, int *a, int x); -/** -Forward 5-3 wavelet transform in 1-D -*/ -static void dwt_encode_1(int *a, int dn, int sn, int cas); -/** -Inverse 5-3 wavelet transform in 1-D -*/ -static void dwt_decode_1(dwt_t *v); -/** -Forward 9-7 wavelet transform in 1-D -*/ -static void dwt_encode_1_real(int *a, int dn, int sn, int cas); -/** -Explicit calculation of the Quantization Stepsizes -*/ -static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize); -/** -Inverse wavelet transform in 2-D. -*/ -static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int i, DWT1DFN fn); - -/*@}*/ - -/*@}*/ - -#define S(i) a[(i)*2] -#define D(i) a[(1+(i)*2)] -#define S_(i) ((i)<0?S(0):((i)>=sn?S(sn-1):S(i))) -#define D_(i) ((i)<0?D(0):((i)>=dn?D(dn-1):D(i))) -/* new */ -#define SS_(i) ((i)<0?S(0):((i)>=dn?S(dn-1):S(i))) -#define DD_(i) ((i)<0?D(0):((i)>=sn?D(sn-1):D(i))) - -/* */ -/* This table contains the norms of the 5-3 wavelets for different bands. */ -/* */ -static const double dwt_norms[4][10] = { - {1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3}, - {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9}, - {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9}, - {.7186, .9218, 1.586, 3.043, 6.019, 12.01, 24.00, 47.97, 95.93} -}; - -/* */ -/* This table contains the norms of the 9-7 wavelets for different bands. */ -/* */ -static const double dwt_norms_real[4][10] = { - {1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9}, - {2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0}, - {2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0}, - {2.080, 3.865, 8.307, 17.18, 34.71, 69.59, 139.3, 278.6, 557.2} -}; - -/* -========================================================== - local functions -========================================================== -*/ - -/* */ -/* Forward lazy transform (horizontal). */ -/* */ -static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas) { - int i; - for (i=0; i */ -/* Forward lazy transform (vertical). */ -/* */ -static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas) { - int i; - for (i=0; i */ -/* Inverse lazy transform (horizontal). */ -/* */ -static void dwt_interleave_h(dwt_t* h, int *a) { - int *ai = a; - int *bi = h->mem + h->cas; - int i = h->sn; - while( i-- ) { - *bi = *(ai++); - bi += 2; - } - ai = a + h->sn; - bi = h->mem + 1 - h->cas; - i = h->dn ; - while( i-- ) { - *bi = *(ai++); - bi += 2; - } -} - -/* */ -/* Inverse lazy transform (vertical). */ -/* */ -static void dwt_interleave_v(dwt_t* v, int *a, int x) { - int *ai = a; - int *bi = v->mem + v->cas; - int i = v->sn; - while( i-- ) { - *bi = *ai; - bi += 2; - ai += x; - } - ai = a + (v->sn * x); - bi = v->mem + 1 - v->cas; - i = v->dn ; - while( i-- ) { - *bi = *ai; - bi += 2; - ai += x; - } -} - - -/* */ -/* Forward 5-3 wavelet transform in 1-D. */ -/* */ -static void dwt_encode_1(int *a, int dn, int sn, int cas) { - int i; - - if (!cas) { - if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ - for (i = 0; i < dn; i++) D(i) -= (S_(i) + S_(i + 1)) >> 1; - for (i = 0; i < sn; i++) S(i) += (D_(i - 1) + D_(i) + 2) >> 2; - } - } else { - if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */ - S(0) *= 2; - else { - for (i = 0; i < dn; i++) S(i) -= (DD_(i) + DD_(i - 1)) >> 1; - for (i = 0; i < sn; i++) D(i) += (SS_(i) + SS_(i + 1) + 2) >> 2; - } - } -} - -/* */ -/* Inverse 5-3 wavelet transform in 1-D. */ -/* */ -static void dwt_decode_1_(int *a, int dn, int sn, int cas) { - int i; - - if (!cas) { - if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ - for (i = 0; i < sn; i++) S(i) -= (D_(i - 1) + D_(i) + 2) >> 2; - for (i = 0; i < dn; i++) D(i) += (S_(i) + S_(i + 1)) >> 1; - } - } else { - if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */ - S(0) /= 2; - else { - for (i = 0; i < sn; i++) D(i) -= (SS_(i) + SS_(i + 1) + 2) >> 2; - for (i = 0; i < dn; i++) S(i) += (DD_(i) + DD_(i - 1)) >> 1; - } - } -} - -/* */ -/* Inverse 5-3 wavelet transform in 1-D. */ -/* */ -static void dwt_decode_1(dwt_t *v) { - dwt_decode_1_(v->mem, v->dn, v->sn, v->cas); -} - -/* */ -/* Forward 9-7 wavelet transform in 1-D. */ -/* */ -static void dwt_encode_1_real(int *a, int dn, int sn, int cas) { - int i; - if (!cas) { - if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ - for (i = 0; i < dn; i++) - D(i) -= fix_mul(S_(i) + S_(i + 1), 12993); - for (i = 0; i < sn; i++) - S(i) -= fix_mul(D_(i - 1) + D_(i), 434); - for (i = 0; i < dn; i++) - D(i) += fix_mul(S_(i) + S_(i + 1), 7233); - for (i = 0; i < sn; i++) - S(i) += fix_mul(D_(i - 1) + D_(i), 3633); - for (i = 0; i < dn; i++) - D(i) = fix_mul(D(i), 5038); /*5038 */ - for (i = 0; i < sn; i++) - S(i) = fix_mul(S(i), 6659); /*6660 */ - } - } else { - if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */ - for (i = 0; i < dn; i++) - S(i) -= fix_mul(DD_(i) + DD_(i - 1), 12993); - for (i = 0; i < sn; i++) - D(i) -= fix_mul(SS_(i) + SS_(i + 1), 434); - for (i = 0; i < dn; i++) - S(i) += fix_mul(DD_(i) + DD_(i - 1), 7233); - for (i = 0; i < sn; i++) - D(i) += fix_mul(SS_(i) + SS_(i + 1), 3633); - for (i = 0; i < dn; i++) - S(i) = fix_mul(S(i), 5038); /*5038 */ - for (i = 0; i < sn; i++) - D(i) = fix_mul(D(i), 6659); /*6660 */ - } - } -} - -static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize) { - int p, n; - p = int_floorlog2(stepsize) - 13; - n = 11 - int_floorlog2(stepsize); - bandno_stepsize->mant = (n < 0 ? stepsize >> -n : stepsize << n) & 0x7ff; - bandno_stepsize->expn = numbps - p; -} - -/* -========================================================== - DWT interface -========================================================== -*/ - -/* */ -/* Forward 5-3 wavelet transform in 2-D. */ -/* */ -void dwt_encode(opj_tcd_tilecomp_t * tilec) { - int i, j, k; - int *a = NULL; - int *aj = NULL; - int *bj = NULL; - int w, l; - - w = tilec->x1-tilec->x0; - l = tilec->numresolutions-1; - a = tilec->data; - - for (i = 0; i < l; i++) { - int rw; /* width of the resolution level computed */ - int rh; /* height of the resolution level computed */ - int rw1; /* width of the resolution level once lower than computed one */ - int rh1; /* height of the resolution level once lower than computed one */ - int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */ - int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */ - int dn, sn; - - rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0; - rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0; - rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0; - rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0; - - cas_row = tilec->resolutions[l - i].x0 % 2; - cas_col = tilec->resolutions[l - i].y0 % 2; - - sn = rh1; - dn = rh - rh1; - bj = (int*)opj_malloc(rh * sizeof(int)); - for (j = 0; j < rw; j++) { - aj = a + j; - for (k = 0; k < rh; k++) bj[k] = aj[k*w]; - dwt_encode_1(bj, dn, sn, cas_col); - dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col); - } - opj_free(bj); - - sn = rw1; - dn = rw - rw1; - bj = (int*)opj_malloc(rw * sizeof(int)); - for (j = 0; j < rh; j++) { - aj = a + j * w; - for (k = 0; k < rw; k++) bj[k] = aj[k]; - dwt_encode_1(bj, dn, sn, cas_row); - dwt_deinterleave_h(bj, aj, dn, sn, cas_row); - } - opj_free(bj); - } -} - - -/* */ -/* Inverse 5-3 wavelet transform in 2-D. */ -/* */ -void dwt_decode(opj_tcd_tilecomp_t* tilec, int numres) { - dwt_decode_tile(tilec, numres, &dwt_decode_1); -} - - -/* */ -/* Get gain of 5-3 wavelet transform. */ -/* */ -int dwt_getgain(int orient) { - if (orient == 0) - return 0; - if (orient == 1 || orient == 2) - return 1; - return 2; -} - -/* */ -/* Get norm of 5-3 wavelet. */ -/* */ -double dwt_getnorm(int level, int orient) { - return dwt_norms[orient][level]; -} - -/* */ -/* Forward 9-7 wavelet transform in 2-D. */ -/* */ - -void dwt_encode_real(opj_tcd_tilecomp_t * tilec) { - int i, j, k; - int *a = NULL; - int *aj = NULL; - int *bj = NULL; - int w, l; - - w = tilec->x1-tilec->x0; - l = tilec->numresolutions-1; - a = tilec->data; - - for (i = 0; i < l; i++) { - int rw; /* width of the resolution level computed */ - int rh; /* height of the resolution level computed */ - int rw1; /* width of the resolution level once lower than computed one */ - int rh1; /* height of the resolution level once lower than computed one */ - int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */ - int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */ - int dn, sn; - - rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0; - rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0; - rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0; - rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0; - - cas_row = tilec->resolutions[l - i].x0 % 2; - cas_col = tilec->resolutions[l - i].y0 % 2; - - sn = rh1; - dn = rh - rh1; - bj = (int*)opj_malloc(rh * sizeof(int)); - for (j = 0; j < rw; j++) { - aj = a + j; - for (k = 0; k < rh; k++) bj[k] = aj[k*w]; - dwt_encode_1_real(bj, dn, sn, cas_col); - dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col); - } - opj_free(bj); - - sn = rw1; - dn = rw - rw1; - bj = (int*)opj_malloc(rw * sizeof(int)); - for (j = 0; j < rh; j++) { - aj = a + j * w; - for (k = 0; k < rw; k++) bj[k] = aj[k]; - dwt_encode_1_real(bj, dn, sn, cas_row); - dwt_deinterleave_h(bj, aj, dn, sn, cas_row); - } - opj_free(bj); - } -} - - -/* */ -/* Get gain of 9-7 wavelet transform. */ -/* */ -int dwt_getgain_real(int orient) { - (void)orient; - return 0; -} - -/* */ -/* Get norm of 9-7 wavelet. */ -/* */ -double dwt_getnorm_real(int level, int orient) { - return dwt_norms_real[orient][level]; -} - -void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec) { - int numbands, bandno; - numbands = 3 * tccp->numresolutions - 2; - for (bandno = 0; bandno < numbands; bandno++) { - double stepsize; - int resno, level, orient, gain; - - resno = (bandno == 0) ? 0 : ((bandno - 1) / 3 + 1); - orient = (bandno == 0) ? 0 : ((bandno - 1) % 3 + 1); - level = tccp->numresolutions - 1 - resno; - gain = (tccp->qmfbid == 0) ? 0 : ((orient == 0) ? 0 : (((orient == 1) || (orient == 2)) ? 1 : 2)); - if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) { - stepsize = 1.0; - } else { - double norm = dwt_norms_real[orient][level]; - stepsize = (1 << (gain)) / norm; - } - dwt_encode_stepsize((int) floor(stepsize * 8192.0), prec + gain, &tccp->stepsizes[bandno]); - } -} - - -/* */ -/* Determine maximum computed resolution level for inverse wavelet transform */ -/* */ -static int dwt_decode_max_resolution(opj_tcd_resolution_t* restrict r, int i) { - int mr = 1; - int w; - while( --i ) { - r++; - if( mr < ( w = r->x1 - r->x0 ) ) - mr = w ; - if( mr < ( w = r->y1 - r->y0 ) ) - mr = w ; - } - return mr ; -} - - -/* */ -/* Inverse wavelet transform in 2-D. */ -/* */ -static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int numres, DWT1DFN dwt_1D) { - dwt_t h; - dwt_t v; - - opj_tcd_resolution_t* tr = tilec->resolutions; - - int rw = tr->x1 - tr->x0; /* width of the resolution level computed */ - int rh = tr->y1 - tr->y0; /* height of the resolution level computed */ - - int w = tilec->x1 - tilec->x0; - - h.mem = (int*)opj_aligned_malloc(dwt_decode_max_resolution(tr, numres) * sizeof(int)); - v.mem = h.mem; - - while( --numres) { - int * restrict tiledp = tilec->data; - int j; - - ++tr; - h.sn = rw; - v.sn = rh; - - rw = tr->x1 - tr->x0; - rh = tr->y1 - tr->y0; - - h.dn = rw - h.sn; - h.cas = tr->x0 % 2; - - for(j = 0; j < rh; ++j) { - dwt_interleave_h(&h, &tiledp[j*w]); - (dwt_1D)(&h); - memcpy(&tiledp[j*w], h.mem, rw * sizeof(int)); - } - - v.dn = rh - v.sn; - v.cas = tr->y0 % 2; - - for(j = 0; j < rw; ++j){ - int k; - dwt_interleave_v(&v, &tiledp[j], w); - (dwt_1D)(&v); - for(k = 0; k < rh; ++k) { - tiledp[k * w + j] = v.mem[k]; - } - } - } - opj_aligned_free(h.mem); -} - -static void v4dwt_interleave_h(v4dwt_t* restrict w, float* restrict a, int x, int size){ - float* restrict bi = (float*) (w->wavelet + w->cas); - int count = w->sn; - int i, k; - for(k = 0; k < 2; ++k){ - if (count + 3 * x < size && ((size_t) a & 0x0f) == 0 && ((size_t) bi & 0x0f) == 0 && (x & 0x0f) == 0) { - /* Fast code path */ - for(i = 0; i < count; ++i){ - int j = i; - bi[i*8 ] = a[j]; - j += x; - bi[i*8 + 1] = a[j]; - j += x; - bi[i*8 + 2] = a[j]; - j += x; - bi[i*8 + 3] = a[j]; - } - } else { - /* Slow code path */ - for(i = 0; i < count; ++i){ - int j = i; - bi[i*8 ] = a[j]; - j += x; - if(j > size) continue; - bi[i*8 + 1] = a[j]; - j += x; - if(j > size) continue; - bi[i*8 + 2] = a[j]; - j += x; - if(j > size) continue; - bi[i*8 + 3] = a[j]; - } - } - bi = (float*) (w->wavelet + 1 - w->cas); - a += w->sn; - size -= w->sn; - count = w->dn; - } -} - -static void v4dwt_interleave_v(v4dwt_t* restrict v , float* restrict a , int x){ - v4* restrict bi = v->wavelet + v->cas; - int i; - for(i = 0; i < v->sn; ++i){ - memcpy(&bi[i*2], &a[i*x], 4 * sizeof(float)); - } - a += v->sn * x; - bi = v->wavelet + 1 - v->cas; - for(i = 0; i < v->dn; ++i){ - memcpy(&bi[i*2], &a[i*x], 4 * sizeof(float)); - } -} - -#ifdef __SSE__ - -static void v4dwt_decode_step1_sse(v4* w, int count, const __m128 c){ - __m128* restrict vw = (__m128*) w; - int i; - /* 4x unrolled loop */ - for(i = 0; i < count >> 2; ++i){ - *vw = _mm_mul_ps(*vw, c); - vw += 2; - *vw = _mm_mul_ps(*vw, c); - vw += 2; - *vw = _mm_mul_ps(*vw, c); - vw += 2; - *vw = _mm_mul_ps(*vw, c); - vw += 2; - } - count &= 3; - for(i = 0; i < count; ++i){ - *vw = _mm_mul_ps(*vw, c); - vw += 2; - } -} - -static void v4dwt_decode_step2_sse(v4* l, v4* w, int k, int m, __m128 c){ - __m128* restrict vl = (__m128*) l; - __m128* restrict vw = (__m128*) w; - int i; - __m128 tmp1, tmp2, tmp3; - tmp1 = vl[0]; - for(i = 0; i < m; ++i){ - tmp2 = vw[-1]; - tmp3 = vw[ 0]; - vw[-1] = _mm_add_ps(tmp2, _mm_mul_ps(_mm_add_ps(tmp1, tmp3), c)); - tmp1 = tmp3; - vw += 2; - } - vl = vw - 2; - if(m >= k){ - return; - } - c = _mm_add_ps(c, c); - c = _mm_mul_ps(c, vl[0]); - for(; m < k; ++m){ - __m128 tmp = vw[-1]; - vw[-1] = _mm_add_ps(tmp, c); - vw += 2; - } -} - -#else - -static void v4dwt_decode_step1(v4* w, int count, const float c){ - float* restrict fw = (float*) w; - int i; - for(i = 0; i < count; ++i){ - float tmp1 = fw[i*8 ]; - float tmp2 = fw[i*8 + 1]; - float tmp3 = fw[i*8 + 2]; - float tmp4 = fw[i*8 + 3]; - fw[i*8 ] = tmp1 * c; - fw[i*8 + 1] = tmp2 * c; - fw[i*8 + 2] = tmp3 * c; - fw[i*8 + 3] = tmp4 * c; - } -} - -static void v4dwt_decode_step2(v4* l, v4* w, int k, int m, float c){ - float* restrict fl = (float*) l; - float* restrict fw = (float*) w; - int i; - for(i = 0; i < m; ++i){ - float tmp1_1 = fl[0]; - float tmp1_2 = fl[1]; - float tmp1_3 = fl[2]; - float tmp1_4 = fl[3]; - float tmp2_1 = fw[-4]; - float tmp2_2 = fw[-3]; - float tmp2_3 = fw[-2]; - float tmp2_4 = fw[-1]; - float tmp3_1 = fw[0]; - float tmp3_2 = fw[1]; - float tmp3_3 = fw[2]; - float tmp3_4 = fw[3]; - fw[-4] = tmp2_1 + ((tmp1_1 + tmp3_1) * c); - fw[-3] = tmp2_2 + ((tmp1_2 + tmp3_2) * c); - fw[-2] = tmp2_3 + ((tmp1_3 + tmp3_3) * c); - fw[-1] = tmp2_4 + ((tmp1_4 + tmp3_4) * c); - fl = fw; - fw += 8; - } - if(m < k){ - float c1; - float c2; - float c3; - float c4; - c += c; - c1 = fl[0] * c; - c2 = fl[1] * c; - c3 = fl[2] * c; - c4 = fl[3] * c; - for(; m < k; ++m){ - float tmp1 = fw[-4]; - float tmp2 = fw[-3]; - float tmp3 = fw[-2]; - float tmp4 = fw[-1]; - fw[-4] = tmp1 + c1; - fw[-3] = tmp2 + c2; - fw[-2] = tmp3 + c3; - fw[-1] = tmp4 + c4; - fw += 8; - } - } -} - -#endif - -/* */ -/* Inverse 9-7 wavelet transform in 1-D. */ -/* */ -static void v4dwt_decode(v4dwt_t* restrict dwt){ - int a, b; - if(dwt->cas == 0) { - if(!((dwt->dn > 0) || (dwt->sn > 1))){ - return; - } - a = 0; - b = 1; - }else{ - if(!((dwt->sn > 0) || (dwt->dn > 1))) { - return; - } - a = 1; - b = 0; - } -#ifdef __SSE__ - v4dwt_decode_step1_sse(dwt->wavelet+a, dwt->sn, _mm_set1_ps(K)); - v4dwt_decode_step1_sse(dwt->wavelet+b, dwt->dn, _mm_set1_ps(c13318)); - v4dwt_decode_step2_sse(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), _mm_set1_ps(dwt_delta)); - v4dwt_decode_step2_sse(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), _mm_set1_ps(dwt_gamma)); - v4dwt_decode_step2_sse(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), _mm_set1_ps(dwt_beta)); - v4dwt_decode_step2_sse(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), _mm_set1_ps(dwt_alpha)); -#else - v4dwt_decode_step1(dwt->wavelet+a, dwt->sn, K); - v4dwt_decode_step1(dwt->wavelet+b, dwt->dn, c13318); - v4dwt_decode_step2(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), dwt_delta); - v4dwt_decode_step2(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), dwt_gamma); - v4dwt_decode_step2(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), dwt_beta); - v4dwt_decode_step2(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), dwt_alpha); -#endif -} - -/* */ -/* Inverse 9-7 wavelet transform in 2-D. */ -/* */ -void dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, int numres){ - v4dwt_t h; - v4dwt_t v; - - opj_tcd_resolution_t* res = tilec->resolutions; - - int rw = res->x1 - res->x0; /* width of the resolution level computed */ - int rh = res->y1 - res->y0; /* height of the resolution level computed */ - - int w = tilec->x1 - tilec->x0; - - h.wavelet = (v4*) opj_aligned_malloc((dwt_decode_max_resolution(res, numres)+5) * sizeof(v4)); - v.wavelet = h.wavelet; - - while( --numres) { - float * restrict aj = (float*) tilec->data; - int bufsize = (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0); - int j; - - h.sn = rw; - v.sn = rh; - - ++res; - - rw = res->x1 - res->x0; /* width of the resolution level computed */ - rh = res->y1 - res->y0; /* height of the resolution level computed */ - - h.dn = rw - h.sn; - h.cas = res->x0 % 2; - - for(j = rh; j > 3; j -= 4){ - int k; - v4dwt_interleave_h(&h, aj, w, bufsize); - v4dwt_decode(&h); - for(k = rw; --k >= 0;){ - aj[k ] = h.wavelet[k].f[0]; - aj[k+w ] = h.wavelet[k].f[1]; - aj[k+w*2] = h.wavelet[k].f[2]; - aj[k+w*3] = h.wavelet[k].f[3]; - } - aj += w*4; - bufsize -= w*4; - } - if (rh & 0x03) { - int k; - j = rh & 0x03; - v4dwt_interleave_h(&h, aj, w, bufsize); - v4dwt_decode(&h); - for(k = rw; --k >= 0;){ - switch(j) { - case 3: aj[k+w*2] = h.wavelet[k].f[2]; - case 2: aj[k+w ] = h.wavelet[k].f[1]; - case 1: aj[k ] = h.wavelet[k].f[0]; - } - } - } - - v.dn = rh - v.sn; - v.cas = res->y0 % 2; - - aj = (float*) tilec->data; - for(j = rw; j > 3; j -= 4){ - int k; - v4dwt_interleave_v(&v, aj, w); - v4dwt_decode(&v); - for(k = 0; k < rh; ++k){ - memcpy(&aj[k*w], &v.wavelet[k], 4 * sizeof(float)); - } - aj += 4; - } - if (rw & 0x03){ - int k; - j = rw & 0x03; - v4dwt_interleave_v(&v, aj, w); - v4dwt_decode(&v); - for(k = 0; k < rh; ++k){ - memcpy(&aj[k*w], &v.wavelet[k], j * sizeof(float)); - } - } - } - - opj_aligned_free(h.wavelet); -} - +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2007, Jonathan Ballard + * Copyright (c) 2007, Callum Lerwick + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef __SSE__ +#include +#endif + +#include "opj_includes.h" + +/** @defgroup DWT DWT - Implementation of a discrete wavelet transform */ +/*@{*/ + +#define WS(i) v->mem[(i)*2] +#define WD(i) v->mem[(1+(i)*2)] + +/** @name Local data structures */ +/*@{*/ + +typedef struct dwt_local { + int* mem; + int dn; + int sn; + int cas; +} dwt_t; + +typedef union { + float f[4]; +} v4; + +typedef struct v4dwt_local { + v4* wavelet ; + int dn ; + int sn ; + int cas ; +} v4dwt_t ; + +static const float dwt_alpha = 1.586134342f; /* 12994 */ +static const float dwt_beta = 0.052980118f; /* 434 */ +static const float dwt_gamma = -0.882911075f; /* -7233 */ +static const float dwt_delta = -0.443506852f; /* -3633 */ + +static const float K = 1.230174105f; /* 10078 */ +/* FIXME: What is this constant? */ +static const float c13318 = 1.625732422f; + +/*@}*/ + +/** +Virtual function type for wavelet transform in 1-D +*/ +typedef void (*DWT1DFN)(dwt_t* v); + +/** @name Local static functions */ +/*@{*/ + +/** +Forward lazy transform (horizontal) +*/ +static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas); +/** +Forward lazy transform (vertical) +*/ +static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas); +/** +Inverse lazy transform (horizontal) +*/ +static void dwt_interleave_h(dwt_t* h, int *a); +/** +Inverse lazy transform (vertical) +*/ +static void dwt_interleave_v(dwt_t* v, int *a, int x); +/** +Forward 5-3 wavelet transform in 1-D +*/ +static void dwt_encode_1(int *a, int dn, int sn, int cas); +/** +Inverse 5-3 wavelet transform in 1-D +*/ +static void dwt_decode_1(dwt_t *v); +/** +Forward 9-7 wavelet transform in 1-D +*/ +static void dwt_encode_1_real(int *a, int dn, int sn, int cas); +/** +Explicit calculation of the Quantization Stepsizes +*/ +static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize); +/** +Inverse wavelet transform in 2-D. +*/ +static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int i, DWT1DFN fn); + +/*@}*/ + +/*@}*/ + +#define S(i) a[(i)*2] +#define D(i) a[(1+(i)*2)] +#define S_(i) ((i)<0?S(0):((i)>=sn?S(sn-1):S(i))) +#define D_(i) ((i)<0?D(0):((i)>=dn?D(dn-1):D(i))) +/* new */ +#define SS_(i) ((i)<0?S(0):((i)>=dn?S(dn-1):S(i))) +#define DD_(i) ((i)<0?D(0):((i)>=sn?D(sn-1):D(i))) + +/* */ +/* This table contains the norms of the 5-3 wavelets for different bands. */ +/* */ +static const double dwt_norms[4][10] = { + {1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3}, + {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9}, + {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9}, + {.7186, .9218, 1.586, 3.043, 6.019, 12.01, 24.00, 47.97, 95.93} +}; + +/* */ +/* This table contains the norms of the 9-7 wavelets for different bands. */ +/* */ +static const double dwt_norms_real[4][10] = { + {1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9}, + {2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0}, + {2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0}, + {2.080, 3.865, 8.307, 17.18, 34.71, 69.59, 139.3, 278.6, 557.2} +}; + +/* +========================================================== + local functions +========================================================== +*/ + +/* */ +/* Forward lazy transform (horizontal). */ +/* */ +static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas) { + int i; + for (i=0; i */ +/* Forward lazy transform (vertical). */ +/* */ +static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas) { + int i; + for (i=0; i */ +/* Inverse lazy transform (horizontal). */ +/* */ +static void dwt_interleave_h(dwt_t* h, int *a) { + int *ai = a; + int *bi = h->mem + h->cas; + int i = h->sn; + while( i-- ) { + *bi = *(ai++); + bi += 2; + } + ai = a + h->sn; + bi = h->mem + 1 - h->cas; + i = h->dn ; + while( i-- ) { + *bi = *(ai++); + bi += 2; + } +} + +/* */ +/* Inverse lazy transform (vertical). */ +/* */ +static void dwt_interleave_v(dwt_t* v, int *a, int x) { + int *ai = a; + int *bi = v->mem + v->cas; + int i = v->sn; + while( i-- ) { + *bi = *ai; + bi += 2; + ai += x; + } + ai = a + (v->sn * x); + bi = v->mem + 1 - v->cas; + i = v->dn ; + while( i-- ) { + *bi = *ai; + bi += 2; + ai += x; + } +} + + +/* */ +/* Forward 5-3 wavelet transform in 1-D. */ +/* */ +static void dwt_encode_1(int *a, int dn, int sn, int cas) { + int i; + + if (!cas) { + if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ + for (i = 0; i < dn; i++) D(i) -= (S_(i) + S_(i + 1)) >> 1; + for (i = 0; i < sn; i++) S(i) += (D_(i - 1) + D_(i) + 2) >> 2; + } + } else { + if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */ + S(0) *= 2; + else { + for (i = 0; i < dn; i++) S(i) -= (DD_(i) + DD_(i - 1)) >> 1; + for (i = 0; i < sn; i++) D(i) += (SS_(i) + SS_(i + 1) + 2) >> 2; + } + } +} + +/* */ +/* Inverse 5-3 wavelet transform in 1-D. */ +/* */ +static void dwt_decode_1_(int *a, int dn, int sn, int cas) { + int i; + + if (!cas) { + if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ + for (i = 0; i < sn; i++) S(i) -= (D_(i - 1) + D_(i) + 2) >> 2; + for (i = 0; i < dn; i++) D(i) += (S_(i) + S_(i + 1)) >> 1; + } + } else { + if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */ + S(0) /= 2; + else { + for (i = 0; i < sn; i++) D(i) -= (SS_(i) + SS_(i + 1) + 2) >> 2; + for (i = 0; i < dn; i++) S(i) += (DD_(i) + DD_(i - 1)) >> 1; + } + } +} + +/* */ +/* Inverse 5-3 wavelet transform in 1-D. */ +/* */ +static void dwt_decode_1(dwt_t *v) { + dwt_decode_1_(v->mem, v->dn, v->sn, v->cas); +} + +/* */ +/* Forward 9-7 wavelet transform in 1-D. */ +/* */ +static void dwt_encode_1_real(int *a, int dn, int sn, int cas) { + int i; + if (!cas) { + if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ + for (i = 0; i < dn; i++) + D(i) -= fix_mul(S_(i) + S_(i + 1), 12993); + for (i = 0; i < sn; i++) + S(i) -= fix_mul(D_(i - 1) + D_(i), 434); + for (i = 0; i < dn; i++) + D(i) += fix_mul(S_(i) + S_(i + 1), 7233); + for (i = 0; i < sn; i++) + S(i) += fix_mul(D_(i - 1) + D_(i), 3633); + for (i = 0; i < dn; i++) + D(i) = fix_mul(D(i), 5038); /*5038 */ + for (i = 0; i < sn; i++) + S(i) = fix_mul(S(i), 6659); /*6660 */ + } + } else { + if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */ + for (i = 0; i < dn; i++) + S(i) -= fix_mul(DD_(i) + DD_(i - 1), 12993); + for (i = 0; i < sn; i++) + D(i) -= fix_mul(SS_(i) + SS_(i + 1), 434); + for (i = 0; i < dn; i++) + S(i) += fix_mul(DD_(i) + DD_(i - 1), 7233); + for (i = 0; i < sn; i++) + D(i) += fix_mul(SS_(i) + SS_(i + 1), 3633); + for (i = 0; i < dn; i++) + S(i) = fix_mul(S(i), 5038); /*5038 */ + for (i = 0; i < sn; i++) + D(i) = fix_mul(D(i), 6659); /*6660 */ + } + } +} + +static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize) { + int p, n; + p = int_floorlog2(stepsize) - 13; + n = 11 - int_floorlog2(stepsize); + bandno_stepsize->mant = (n < 0 ? stepsize >> -n : stepsize << n) & 0x7ff; + bandno_stepsize->expn = numbps - p; +} + +/* +========================================================== + DWT interface +========================================================== +*/ + +/* */ +/* Forward 5-3 wavelet transform in 2-D. */ +/* */ +void dwt_encode(opj_tcd_tilecomp_t * tilec) { + int i, j, k; + int *a = NULL; + int *aj = NULL; + int *bj = NULL; + int w, l; + + w = tilec->x1-tilec->x0; + l = tilec->numresolutions-1; + a = tilec->data; + + for (i = 0; i < l; i++) { + int rw; /* width of the resolution level computed */ + int rh; /* height of the resolution level computed */ + int rw1; /* width of the resolution level once lower than computed one */ + int rh1; /* height of the resolution level once lower than computed one */ + int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */ + int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */ + int dn, sn; + + rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0; + rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0; + rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0; + rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0; + + cas_row = tilec->resolutions[l - i].x0 % 2; + cas_col = tilec->resolutions[l - i].y0 % 2; + + sn = rh1; + dn = rh - rh1; + bj = (int*)opj_malloc(rh * sizeof(int)); + for (j = 0; j < rw; j++) { + aj = a + j; + for (k = 0; k < rh; k++) bj[k] = aj[k*w]; + dwt_encode_1(bj, dn, sn, cas_col); + dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col); + } + opj_free(bj); + + sn = rw1; + dn = rw - rw1; + bj = (int*)opj_malloc(rw * sizeof(int)); + for (j = 0; j < rh; j++) { + aj = a + j * w; + for (k = 0; k < rw; k++) bj[k] = aj[k]; + dwt_encode_1(bj, dn, sn, cas_row); + dwt_deinterleave_h(bj, aj, dn, sn, cas_row); + } + opj_free(bj); + } +} + + +/* */ +/* Inverse 5-3 wavelet transform in 2-D. */ +/* */ +void dwt_decode(opj_tcd_tilecomp_t* tilec, int numres) { + dwt_decode_tile(tilec, numres, &dwt_decode_1); +} + + +/* */ +/* Get gain of 5-3 wavelet transform. */ +/* */ +int dwt_getgain(int orient) { + if (orient == 0) + return 0; + if (orient == 1 || orient == 2) + return 1; + return 2; +} + +/* */ +/* Get norm of 5-3 wavelet. */ +/* */ +double dwt_getnorm(int level, int orient) { + return dwt_norms[orient][level]; +} + +/* */ +/* Forward 9-7 wavelet transform in 2-D. */ +/* */ + +void dwt_encode_real(opj_tcd_tilecomp_t * tilec) { + int i, j, k; + int *a = NULL; + int *aj = NULL; + int *bj = NULL; + int w, l; + + w = tilec->x1-tilec->x0; + l = tilec->numresolutions-1; + a = tilec->data; + + for (i = 0; i < l; i++) { + int rw; /* width of the resolution level computed */ + int rh; /* height of the resolution level computed */ + int rw1; /* width of the resolution level once lower than computed one */ + int rh1; /* height of the resolution level once lower than computed one */ + int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */ + int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */ + int dn, sn; + + rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0; + rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0; + rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0; + rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0; + + cas_row = tilec->resolutions[l - i].x0 % 2; + cas_col = tilec->resolutions[l - i].y0 % 2; + + sn = rh1; + dn = rh - rh1; + bj = (int*)opj_malloc(rh * sizeof(int)); + for (j = 0; j < rw; j++) { + aj = a + j; + for (k = 0; k < rh; k++) bj[k] = aj[k*w]; + dwt_encode_1_real(bj, dn, sn, cas_col); + dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col); + } + opj_free(bj); + + sn = rw1; + dn = rw - rw1; + bj = (int*)opj_malloc(rw * sizeof(int)); + for (j = 0; j < rh; j++) { + aj = a + j * w; + for (k = 0; k < rw; k++) bj[k] = aj[k]; + dwt_encode_1_real(bj, dn, sn, cas_row); + dwt_deinterleave_h(bj, aj, dn, sn, cas_row); + } + opj_free(bj); + } +} + + +/* */ +/* Get gain of 9-7 wavelet transform. */ +/* */ +int dwt_getgain_real(int orient) { + (void)orient; + return 0; +} + +/* */ +/* Get norm of 9-7 wavelet. */ +/* */ +double dwt_getnorm_real(int level, int orient) { + return dwt_norms_real[orient][level]; +} + +void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec) { + int numbands, bandno; + numbands = 3 * tccp->numresolutions - 2; + for (bandno = 0; bandno < numbands; bandno++) { + double stepsize; + int resno, level, orient, gain; + + resno = (bandno == 0) ? 0 : ((bandno - 1) / 3 + 1); + orient = (bandno == 0) ? 0 : ((bandno - 1) % 3 + 1); + level = tccp->numresolutions - 1 - resno; + gain = (tccp->qmfbid == 0) ? 0 : ((orient == 0) ? 0 : (((orient == 1) || (orient == 2)) ? 1 : 2)); + if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) { + stepsize = 1.0; + } else { + double norm = dwt_norms_real[orient][level]; + stepsize = (1 << (gain)) / norm; + } + dwt_encode_stepsize((int) floor(stepsize * 8192.0), prec + gain, &tccp->stepsizes[bandno]); + } +} + + +/* */ +/* Determine maximum computed resolution level for inverse wavelet transform */ +/* */ +static int dwt_decode_max_resolution(opj_tcd_resolution_t* restrict r, int i) { + int mr = 1; + int w; + while( --i ) { + r++; + if( mr < ( w = r->x1 - r->x0 ) ) + mr = w ; + if( mr < ( w = r->y1 - r->y0 ) ) + mr = w ; + } + return mr ; +} + + +/* */ +/* Inverse wavelet transform in 2-D. */ +/* */ +static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int numres, DWT1DFN dwt_1D) { + dwt_t h; + dwt_t v; + + opj_tcd_resolution_t* tr = tilec->resolutions; + + int rw = tr->x1 - tr->x0; /* width of the resolution level computed */ + int rh = tr->y1 - tr->y0; /* height of the resolution level computed */ + + int w = tilec->x1 - tilec->x0; + + h.mem = (int*)opj_aligned_malloc(dwt_decode_max_resolution(tr, numres) * sizeof(int)); + v.mem = h.mem; + + while( --numres) { + int * restrict tiledp = tilec->data; + int j; + + ++tr; + h.sn = rw; + v.sn = rh; + + rw = tr->x1 - tr->x0; + rh = tr->y1 - tr->y0; + + h.dn = rw - h.sn; + h.cas = tr->x0 % 2; + + for(j = 0; j < rh; ++j) { + dwt_interleave_h(&h, &tiledp[j*w]); + (dwt_1D)(&h); + memcpy(&tiledp[j*w], h.mem, rw * sizeof(int)); + } + + v.dn = rh - v.sn; + v.cas = tr->y0 % 2; + + for(j = 0; j < rw; ++j){ + int k; + dwt_interleave_v(&v, &tiledp[j], w); + (dwt_1D)(&v); + for(k = 0; k < rh; ++k) { + tiledp[k * w + j] = v.mem[k]; + } + } + } + opj_aligned_free(h.mem); +} + +static void v4dwt_interleave_h(v4dwt_t* restrict w, float* restrict a, int x, int size){ + float* restrict bi = (float*) (w->wavelet + w->cas); + int count = w->sn; + int i, k; + for(k = 0; k < 2; ++k){ + if (count + 3 * x < size && ((size_t) a & 0x0f) == 0 && ((size_t) bi & 0x0f) == 0 && (x & 0x0f) == 0) { + /* Fast code path */ + for(i = 0; i < count; ++i){ + int j = i; + bi[i*8 ] = a[j]; + j += x; + bi[i*8 + 1] = a[j]; + j += x; + bi[i*8 + 2] = a[j]; + j += x; + bi[i*8 + 3] = a[j]; + } + } else { + /* Slow code path */ + for(i = 0; i < count; ++i){ + int j = i; + bi[i*8 ] = a[j]; + j += x; + if(j > size) continue; + bi[i*8 + 1] = a[j]; + j += x; + if(j > size) continue; + bi[i*8 + 2] = a[j]; + j += x; + if(j > size) continue; + bi[i*8 + 3] = a[j]; + } + } + bi = (float*) (w->wavelet + 1 - w->cas); + a += w->sn; + size -= w->sn; + count = w->dn; + } +} + +static void v4dwt_interleave_v(v4dwt_t* restrict v , float* restrict a , int x){ + v4* restrict bi = v->wavelet + v->cas; + int i; + for(i = 0; i < v->sn; ++i){ + memcpy(&bi[i*2], &a[i*x], 4 * sizeof(float)); + } + a += v->sn * x; + bi = v->wavelet + 1 - v->cas; + for(i = 0; i < v->dn; ++i){ + memcpy(&bi[i*2], &a[i*x], 4 * sizeof(float)); + } +} + +#ifdef __SSE__ + +static void v4dwt_decode_step1_sse(v4* w, int count, const __m128 c){ + __m128* restrict vw = (__m128*) w; + int i; + /* 4x unrolled loop */ + for(i = 0; i < count >> 2; ++i){ + *vw = _mm_mul_ps(*vw, c); + vw += 2; + *vw = _mm_mul_ps(*vw, c); + vw += 2; + *vw = _mm_mul_ps(*vw, c); + vw += 2; + *vw = _mm_mul_ps(*vw, c); + vw += 2; + } + count &= 3; + for(i = 0; i < count; ++i){ + *vw = _mm_mul_ps(*vw, c); + vw += 2; + } +} + +static void v4dwt_decode_step2_sse(v4* l, v4* w, int k, int m, __m128 c){ + __m128* restrict vl = (__m128*) l; + __m128* restrict vw = (__m128*) w; + int i; + __m128 tmp1, tmp2, tmp3; + tmp1 = vl[0]; + for(i = 0; i < m; ++i){ + tmp2 = vw[-1]; + tmp3 = vw[ 0]; + vw[-1] = _mm_add_ps(tmp2, _mm_mul_ps(_mm_add_ps(tmp1, tmp3), c)); + tmp1 = tmp3; + vw += 2; + } + vl = vw - 2; + if(m >= k){ + return; + } + c = _mm_add_ps(c, c); + c = _mm_mul_ps(c, vl[0]); + for(; m < k; ++m){ + __m128 tmp = vw[-1]; + vw[-1] = _mm_add_ps(tmp, c); + vw += 2; + } +} + +#else + +static void v4dwt_decode_step1(v4* w, int count, const float c){ + float* restrict fw = (float*) w; + int i; + for(i = 0; i < count; ++i){ + float tmp1 = fw[i*8 ]; + float tmp2 = fw[i*8 + 1]; + float tmp3 = fw[i*8 + 2]; + float tmp4 = fw[i*8 + 3]; + fw[i*8 ] = tmp1 * c; + fw[i*8 + 1] = tmp2 * c; + fw[i*8 + 2] = tmp3 * c; + fw[i*8 + 3] = tmp4 * c; + } +} + +static void v4dwt_decode_step2(v4* l, v4* w, int k, int m, float c){ + float* restrict fl = (float*) l; + float* restrict fw = (float*) w; + int i; + for(i = 0; i < m; ++i){ + float tmp1_1 = fl[0]; + float tmp1_2 = fl[1]; + float tmp1_3 = fl[2]; + float tmp1_4 = fl[3]; + float tmp2_1 = fw[-4]; + float tmp2_2 = fw[-3]; + float tmp2_3 = fw[-2]; + float tmp2_4 = fw[-1]; + float tmp3_1 = fw[0]; + float tmp3_2 = fw[1]; + float tmp3_3 = fw[2]; + float tmp3_4 = fw[3]; + fw[-4] = tmp2_1 + ((tmp1_1 + tmp3_1) * c); + fw[-3] = tmp2_2 + ((tmp1_2 + tmp3_2) * c); + fw[-2] = tmp2_3 + ((tmp1_3 + tmp3_3) * c); + fw[-1] = tmp2_4 + ((tmp1_4 + tmp3_4) * c); + fl = fw; + fw += 8; + } + if(m < k){ + float c1; + float c2; + float c3; + float c4; + c += c; + c1 = fl[0] * c; + c2 = fl[1] * c; + c3 = fl[2] * c; + c4 = fl[3] * c; + for(; m < k; ++m){ + float tmp1 = fw[-4]; + float tmp2 = fw[-3]; + float tmp3 = fw[-2]; + float tmp4 = fw[-1]; + fw[-4] = tmp1 + c1; + fw[-3] = tmp2 + c2; + fw[-2] = tmp3 + c3; + fw[-1] = tmp4 + c4; + fw += 8; + } + } +} + +#endif + +/* */ +/* Inverse 9-7 wavelet transform in 1-D. */ +/* */ +static void v4dwt_decode(v4dwt_t* restrict dwt){ + int a, b; + if(dwt->cas == 0) { + if(!((dwt->dn > 0) || (dwt->sn > 1))){ + return; + } + a = 0; + b = 1; + }else{ + if(!((dwt->sn > 0) || (dwt->dn > 1))) { + return; + } + a = 1; + b = 0; + } +#ifdef __SSE__ + v4dwt_decode_step1_sse(dwt->wavelet+a, dwt->sn, _mm_set1_ps(K)); + v4dwt_decode_step1_sse(dwt->wavelet+b, dwt->dn, _mm_set1_ps(c13318)); + v4dwt_decode_step2_sse(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), _mm_set1_ps(dwt_delta)); + v4dwt_decode_step2_sse(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), _mm_set1_ps(dwt_gamma)); + v4dwt_decode_step2_sse(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), _mm_set1_ps(dwt_beta)); + v4dwt_decode_step2_sse(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), _mm_set1_ps(dwt_alpha)); +#else + v4dwt_decode_step1(dwt->wavelet+a, dwt->sn, K); + v4dwt_decode_step1(dwt->wavelet+b, dwt->dn, c13318); + v4dwt_decode_step2(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), dwt_delta); + v4dwt_decode_step2(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), dwt_gamma); + v4dwt_decode_step2(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), dwt_beta); + v4dwt_decode_step2(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), dwt_alpha); +#endif +} + +/* */ +/* Inverse 9-7 wavelet transform in 2-D. */ +/* */ +void dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, int numres){ + v4dwt_t h; + v4dwt_t v; + + opj_tcd_resolution_t* res = tilec->resolutions; + + int rw = res->x1 - res->x0; /* width of the resolution level computed */ + int rh = res->y1 - res->y0; /* height of the resolution level computed */ + + int w = tilec->x1 - tilec->x0; + + h.wavelet = (v4*) opj_aligned_malloc((dwt_decode_max_resolution(res, numres)+5) * sizeof(v4)); + v.wavelet = h.wavelet; + + while( --numres) { + float * restrict aj = (float*) tilec->data; + int bufsize = (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0); + int j; + + h.sn = rw; + v.sn = rh; + + ++res; + + rw = res->x1 - res->x0; /* width of the resolution level computed */ + rh = res->y1 - res->y0; /* height of the resolution level computed */ + + h.dn = rw - h.sn; + h.cas = res->x0 % 2; + + for(j = rh; j > 3; j -= 4){ + int k; + v4dwt_interleave_h(&h, aj, w, bufsize); + v4dwt_decode(&h); + for(k = rw; --k >= 0;){ + aj[k ] = h.wavelet[k].f[0]; + aj[k+w ] = h.wavelet[k].f[1]; + aj[k+w*2] = h.wavelet[k].f[2]; + aj[k+w*3] = h.wavelet[k].f[3]; + } + aj += w*4; + bufsize -= w*4; + } + if (rh & 0x03) { + int k; + j = rh & 0x03; + v4dwt_interleave_h(&h, aj, w, bufsize); + v4dwt_decode(&h); + for(k = rw; --k >= 0;){ + switch(j) { + case 3: aj[k+w*2] = h.wavelet[k].f[2]; + case 2: aj[k+w ] = h.wavelet[k].f[1]; + case 1: aj[k ] = h.wavelet[k].f[0]; + } + } + } + + v.dn = rh - v.sn; + v.cas = res->y0 % 2; + + aj = (float*) tilec->data; + for(j = rw; j > 3; j -= 4){ + int k; + v4dwt_interleave_v(&v, aj, w); + v4dwt_decode(&v); + for(k = 0; k < rh; ++k){ + memcpy(&aj[k*w], &v.wavelet[k], 4 * sizeof(float)); + } + aj += 4; + } + if (rw & 0x03){ + int k; + j = rw & 0x03; + v4dwt_interleave_v(&v, aj, w); + v4dwt_decode(&v); + for(k = 0; k < rh; ++k){ + memcpy(&aj[k*w], &v.wavelet[k], j * sizeof(float)); + } + } + } + + opj_aligned_free(h.wavelet); +} + diff --git a/Source/LibOpenJPEG/dwt.h b/Source/LibOpenJPEG/dwt.h index c67c456..adf73e5 100644 --- a/Source/LibOpenJPEG/dwt.h +++ b/Source/LibOpenJPEG/dwt.h @@ -1,113 +1,113 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __DWT_H -#define __DWT_H -/** -@file dwt.h -@brief Implementation of a discrete wavelet transform (DWT) - -The functions in DWT.C have for goal to realize forward and inverse discret wavelet -transform with filter 5-3 (reversible) and filter 9-7 (irreversible). The functions in -DWT.C are used by some function in TCD.C. -*/ - -/** @defgroup DWT DWT - Implementation of a discrete wavelet transform */ -/*@{*/ - - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Forward 5-3 wavelet tranform in 2-D. -Apply a reversible DWT transform to a component of an image. -@param tilec Tile component information (current tile) -*/ -void dwt_encode(opj_tcd_tilecomp_t * tilec); -/** -Inverse 5-3 wavelet tranform in 2-D. -Apply a reversible inverse DWT transform to a component of an image. -@param tilec Tile component information (current tile) -@param numres Number of resolution levels to decode -*/ -void dwt_decode(opj_tcd_tilecomp_t* tilec, int numres); -/** -Get the gain of a subband for the reversible 5-3 DWT. -@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH) -@return Returns 0 if orient = 0, returns 1 if orient = 1 or 2, returns 2 otherwise -*/ -int dwt_getgain(int orient); -/** -Get the norm of a wavelet function of a subband at a specified level for the reversible 5-3 DWT. -@param level Level of the wavelet function -@param orient Band of the wavelet function -@return Returns the norm of the wavelet function -*/ -double dwt_getnorm(int level, int orient); -/** -Forward 9-7 wavelet transform in 2-D. -Apply an irreversible DWT transform to a component of an image. -@param tilec Tile component information (current tile) -*/ -void dwt_encode_real(opj_tcd_tilecomp_t * tilec); -/** -Inverse 9-7 wavelet transform in 2-D. -Apply an irreversible inverse DWT transform to a component of an image. -@param tilec Tile component information (current tile) -@param numres Number of resolution levels to decode -*/ -void dwt_decode_real(opj_tcd_tilecomp_t* tilec, int numres); -/** -Get the gain of a subband for the irreversible 9-7 DWT. -@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH) -@return Returns the gain of the 9-7 wavelet transform -*/ -int dwt_getgain_real(int orient); -/** -Get the norm of a wavelet function of a subband at a specified level for the irreversible 9-7 DWT -@param level Level of the wavelet function -@param orient Band of the wavelet function -@return Returns the norm of the 9-7 wavelet -*/ -double dwt_getnorm_real(int level, int orient); -/** -Explicit calculation of the Quantization Stepsizes -@param tccp Tile-component coding parameters -@param prec Precint analyzed -*/ -void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __DWT_H */ +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __DWT_H +#define __DWT_H +/** +@file dwt.h +@brief Implementation of a discrete wavelet transform (DWT) + +The functions in DWT.C have for goal to realize forward and inverse discret wavelet +transform with filter 5-3 (reversible) and filter 9-7 (irreversible). The functions in +DWT.C are used by some function in TCD.C. +*/ + +/** @defgroup DWT DWT - Implementation of a discrete wavelet transform */ +/*@{*/ + + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Forward 5-3 wavelet tranform in 2-D. +Apply a reversible DWT transform to a component of an image. +@param tilec Tile component information (current tile) +*/ +void dwt_encode(opj_tcd_tilecomp_t * tilec); +/** +Inverse 5-3 wavelet tranform in 2-D. +Apply a reversible inverse DWT transform to a component of an image. +@param tilec Tile component information (current tile) +@param numres Number of resolution levels to decode +*/ +void dwt_decode(opj_tcd_tilecomp_t* tilec, int numres); +/** +Get the gain of a subband for the reversible 5-3 DWT. +@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH) +@return Returns 0 if orient = 0, returns 1 if orient = 1 or 2, returns 2 otherwise +*/ +int dwt_getgain(int orient); +/** +Get the norm of a wavelet function of a subband at a specified level for the reversible 5-3 DWT. +@param level Level of the wavelet function +@param orient Band of the wavelet function +@return Returns the norm of the wavelet function +*/ +double dwt_getnorm(int level, int orient); +/** +Forward 9-7 wavelet transform in 2-D. +Apply an irreversible DWT transform to a component of an image. +@param tilec Tile component information (current tile) +*/ +void dwt_encode_real(opj_tcd_tilecomp_t * tilec); +/** +Inverse 9-7 wavelet transform in 2-D. +Apply an irreversible inverse DWT transform to a component of an image. +@param tilec Tile component information (current tile) +@param numres Number of resolution levels to decode +*/ +void dwt_decode_real(opj_tcd_tilecomp_t* tilec, int numres); +/** +Get the gain of a subband for the irreversible 9-7 DWT. +@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH) +@return Returns the gain of the 9-7 wavelet transform +*/ +int dwt_getgain_real(int orient); +/** +Get the norm of a wavelet function of a subband at a specified level for the irreversible 9-7 DWT +@param level Level of the wavelet function +@param orient Band of the wavelet function +@return Returns the norm of the 9-7 wavelet +*/ +double dwt_getnorm_real(int level, int orient); +/** +Explicit calculation of the Quantization Stepsizes +@param tccp Tile-component coding parameters +@param prec Precint analyzed +*/ +void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __DWT_H */ diff --git a/Source/LibOpenJPEG/event.c b/Source/LibOpenJPEG/event.c index 81bc89b..7d0607c 100644 --- a/Source/LibOpenJPEG/event.c +++ b/Source/LibOpenJPEG/event.c @@ -1,31 +1,31 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + #ifdef WIN32 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ #if !defined(vsnprintf) && !defined(NO_vsnprintf) @@ -34,97 +34,97 @@ #endif #endif #endif - -/* ========================================================== - Utility functions - ==========================================================*/ - -#ifdef OPJ_CODE_NOT_USED -#ifndef _WIN32 -static char* -i2a(unsigned i, char *a, unsigned r) { - if (i/r > 0) a = i2a(i/r,a,r); - *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r]; - return a+1; -} - -/** - Transforms integer i into an ascii string and stores the result in a; - string is encoded in the base indicated by r. - @param i Number to be converted - @param a String result - @param r Base of value; must be in the range 2 - 36 - @return Returns a -*/ -static char * -_itoa(int i, char *a, int r) { - r = ((r < 2) || (r > 36)) ? 10 : r; - if(i < 0) { - *a = '-'; - *i2a(-i, a+1, r) = 0; - } - else *i2a(i, a, r) = 0; - return a; -} - -#endif /* !_WIN32 */ -#endif -/* ----------------------------------------------------------------------- */ - -opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) { - if(cinfo) { - opj_event_mgr_t *previous = cinfo->event_mgr; - cinfo->event_mgr = event_mgr; - cinfo->client_data = context; - return previous; - } - - return NULL; -} - -opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) { -#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ - opj_msg_callback msg_handler = NULL; - - opj_event_mgr_t *event_mgr = cinfo->event_mgr; - if(event_mgr != NULL) { - switch(event_type) { - case EVT_ERROR: - msg_handler = event_mgr->error_handler; - break; - case EVT_WARNING: - msg_handler = event_mgr->warning_handler; - break; - case EVT_INFO: - msg_handler = event_mgr->info_handler; - break; - default: - break; - } - if(msg_handler == NULL) { - return OPJ_FALSE; - } - } else { - return OPJ_FALSE; - } - - if ((fmt != NULL) && (event_mgr != NULL)) { - va_list arg; - int str_length/*, i, j*/; /* UniPG */ - char message[MSG_SIZE]; - /* initialize the optional parameter list */ - va_start(arg, fmt); - /* parse the format string and put the result in 'message' */ - str_length = vsnprintf(message, MSG_SIZE, fmt, arg); /* UniPG */ - /* deinitialize the optional parameter list */ - va_end(arg); - - /* output the message to the user program */ - if( str_length > -1 && str_length < MSG_SIZE ) - msg_handler(message, cinfo->client_data); - else return OPJ_FALSE; - } - - return OPJ_TRUE; -} - + +/* ========================================================== + Utility functions + ==========================================================*/ + +#ifdef OPJ_CODE_NOT_USED +#ifndef _WIN32 +static char* +i2a(unsigned i, char *a, unsigned r) { + if (i/r > 0) a = i2a(i/r,a,r); + *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r]; + return a+1; +} + +/** + Transforms integer i into an ascii string and stores the result in a; + string is encoded in the base indicated by r. + @param i Number to be converted + @param a String result + @param r Base of value; must be in the range 2 - 36 + @return Returns a +*/ +static char * +_itoa(int i, char *a, int r) { + r = ((r < 2) || (r > 36)) ? 10 : r; + if(i < 0) { + *a = '-'; + *i2a(-i, a+1, r) = 0; + } + else *i2a(i, a, r) = 0; + return a; +} + +#endif /* !_WIN32 */ +#endif +/* ----------------------------------------------------------------------- */ + +opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) { + if(cinfo) { + opj_event_mgr_t *previous = cinfo->event_mgr; + cinfo->event_mgr = event_mgr; + cinfo->client_data = context; + return previous; + } + + return NULL; +} + +opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) { +#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ + opj_msg_callback msg_handler = NULL; + + opj_event_mgr_t *event_mgr = cinfo->event_mgr; + if(event_mgr != NULL) { + switch(event_type) { + case EVT_ERROR: + msg_handler = event_mgr->error_handler; + break; + case EVT_WARNING: + msg_handler = event_mgr->warning_handler; + break; + case EVT_INFO: + msg_handler = event_mgr->info_handler; + break; + default: + break; + } + if(msg_handler == NULL) { + return OPJ_FALSE; + } + } else { + return OPJ_FALSE; + } + + if ((fmt != NULL) && (event_mgr != NULL)) { + va_list arg; + int str_length/*, i, j*/; /* UniPG */ + char message[MSG_SIZE]; + /* initialize the optional parameter list */ + va_start(arg, fmt); + /* parse the format string and put the result in 'message' */ + str_length = vsnprintf(message, MSG_SIZE, fmt, arg); /* UniPG */ + /* deinitialize the optional parameter list */ + va_end(arg); + + /* output the message to the user program */ + if( str_length > -1 && str_length < MSG_SIZE ) + msg_handler(message, cinfo->client_data); + else return OPJ_FALSE; + } + + return OPJ_TRUE; +} + diff --git a/Source/LibOpenJPEG/event.h b/Source/LibOpenJPEG/event.h index 211acc4..9c59787 100644 --- a/Source/LibOpenJPEG/event.h +++ b/Source/LibOpenJPEG/event.h @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __EVENT_H -#define __EVENT_H -/** -@file event.h -@brief Implementation of a event callback system - -The functions in EVENT.C have for goal to send output messages (errors, warnings, debug) to the user. -*/ - -#define EVT_ERROR 1 /**< Error event type */ -#define EVT_WARNING 2 /**< Warning event type */ -#define EVT_INFO 4 /**< Debug event type */ - -/** @defgroup EVENT EVENT - Implementation of a event callback system */ -/*@{*/ - -/** @name Exported functions (see also openjpeg.h) */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Write formatted data to a string and send the string to a user callback. -@param cinfo Codec context info -@param event_type Event type or callback to use to send the message -@param fmt Format-control string (plus optionnal arguments) -@return Returns true if successful, returns false otherwise -*/ -opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __EVENT_H */ +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __EVENT_H +#define __EVENT_H +/** +@file event.h +@brief Implementation of a event callback system + +The functions in EVENT.C have for goal to send output messages (errors, warnings, debug) to the user. +*/ + +#define EVT_ERROR 1 /**< Error event type */ +#define EVT_WARNING 2 /**< Warning event type */ +#define EVT_INFO 4 /**< Debug event type */ + +/** @defgroup EVENT EVENT - Implementation of a event callback system */ +/*@{*/ + +/** @name Exported functions (see also openjpeg.h) */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Write formatted data to a string and send the string to a user callback. +@param cinfo Codec context info +@param event_type Event type or callback to use to send the message +@param fmt Format-control string (plus optionnal arguments) +@return Returns true if successful, returns false otherwise +*/ +opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __EVENT_H */ diff --git a/Source/LibOpenJPEG/fix.h b/Source/LibOpenJPEG/fix.h index 01716d4..bcb2acb 100644 --- a/Source/LibOpenJPEG/fix.h +++ b/Source/LibOpenJPEG/fix.h @@ -1,64 +1,64 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __FIX_H -#define __FIX_H - -#if defined(_MSC_VER) || defined(__BORLANDC__) -#define int64 __int64 -#else -#define int64 long long -#endif - -/** -@file fix.h -@brief Implementation of operations of specific multiplication (FIX) - -The functions in FIX.H have for goal to realize specific multiplication. -*/ - -/** @defgroup FIX FIX - Implementation of operations of specific multiplication */ -/*@{*/ - -/** -Multiply two fixed-precision rational numbers. -@param a -@param b -@return Returns a * b -*/ -static INLINE int fix_mul(int a, int b) { - int64 temp = (int64) a * (int64) b ; - temp += temp & 4096; - return (int) (temp >> 13) ; -} - -/*@}*/ - -#endif /* __FIX_H */ +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __FIX_H +#define __FIX_H + +#if defined(_MSC_VER) || defined(__BORLANDC__) +#define int64 __int64 +#else +#define int64 long long +#endif + +/** +@file fix.h +@brief Implementation of operations of specific multiplication (FIX) + +The functions in FIX.H have for goal to realize specific multiplication. +*/ + +/** @defgroup FIX FIX - Implementation of operations of specific multiplication */ +/*@{*/ + +/** +Multiply two fixed-precision rational numbers. +@param a +@param b +@return Returns a * b +*/ +static INLINE int fix_mul(int a, int b) { + int64 temp = (int64) a * (int64) b ; + temp += temp & 4096; + return (int) (temp >> 13) ; +} + +/*@}*/ + +#endif /* __FIX_H */ diff --git a/Source/LibOpenJPEG/image.c b/Source/LibOpenJPEG/image.c index b3260a3..a4d2c01 100644 --- a/Source/LibOpenJPEG/image.c +++ b/Source/LibOpenJPEG/image.c @@ -1,89 +1,89 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -opj_image_t* opj_image_create0(void) { - opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t)); - return image; -} - -opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) { - int compno; - opj_image_t *image = NULL; - - image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t)); - if(image) { - image->color_space = clrspc; - image->numcomps = numcmpts; - /* allocate memory for the per-component information */ - image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t)); - if(!image->comps) { - fprintf(stderr,"Unable to allocate memory for image.\n"); - opj_image_destroy(image); - return NULL; - } - /* create the individual image components */ - for(compno = 0; compno < numcmpts; compno++) { - opj_image_comp_t *comp = &image->comps[compno]; - comp->dx = cmptparms[compno].dx; - comp->dy = cmptparms[compno].dy; - comp->w = cmptparms[compno].w; - comp->h = cmptparms[compno].h; - comp->x0 = cmptparms[compno].x0; - comp->y0 = cmptparms[compno].y0; - comp->prec = cmptparms[compno].prec; - comp->bpp = cmptparms[compno].bpp; - comp->sgnd = cmptparms[compno].sgnd; - comp->data = (int*) opj_calloc(comp->w * comp->h, sizeof(int)); - if(!comp->data) { - fprintf(stderr,"Unable to allocate memory for image.\n"); - opj_image_destroy(image); - return NULL; - } - } - } - - return image; -} - -void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) { - int i; - if(image) { - if(image->comps) { - /* image components */ - for(i = 0; i < image->numcomps; i++) { - opj_image_comp_t *image_comp = &image->comps[i]; - if(image_comp->data) { - opj_free(image_comp->data); - } - } - opj_free(image->comps); - } - opj_free(image); - } -} - +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +opj_image_t* opj_image_create0(void) { + opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t)); + return image; +} + +opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) { + int compno; + opj_image_t *image = NULL; + + image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t)); + if(image) { + image->color_space = clrspc; + image->numcomps = numcmpts; + /* allocate memory for the per-component information */ + image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t)); + if(!image->comps) { + fprintf(stderr,"Unable to allocate memory for image.\n"); + opj_image_destroy(image); + return NULL; + } + /* create the individual image components */ + for(compno = 0; compno < numcmpts; compno++) { + opj_image_comp_t *comp = &image->comps[compno]; + comp->dx = cmptparms[compno].dx; + comp->dy = cmptparms[compno].dy; + comp->w = cmptparms[compno].w; + comp->h = cmptparms[compno].h; + comp->x0 = cmptparms[compno].x0; + comp->y0 = cmptparms[compno].y0; + comp->prec = cmptparms[compno].prec; + comp->bpp = cmptparms[compno].bpp; + comp->sgnd = cmptparms[compno].sgnd; + comp->data = (int*) opj_calloc(comp->w * comp->h, sizeof(int)); + if(!comp->data) { + fprintf(stderr,"Unable to allocate memory for image.\n"); + opj_image_destroy(image); + return NULL; + } + } + } + + return image; +} + +void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) { + int i; + if(image) { + if(image->comps) { + /* image components */ + for(i = 0; i < image->numcomps; i++) { + opj_image_comp_t *image_comp = &image->comps[i]; + if(image_comp->data) { + opj_free(image_comp->data); + } + } + opj_free(image->comps); + } + opj_free(image); + } +} + diff --git a/Source/LibOpenJPEG/image.h b/Source/LibOpenJPEG/image.h index fc02f49..f828b5b 100644 --- a/Source/LibOpenJPEG/image.h +++ b/Source/LibOpenJPEG/image.h @@ -1,48 +1,48 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __IMAGE_H -#define __IMAGE_H -/** -@file image.h -@brief Implementation of operations on images (IMAGE) - -The functions in IMAGE.C have for goal to realize operations on images. -*/ - -/** @defgroup IMAGE IMAGE - Implementation of operations on images */ -/*@{*/ - -/** -Create an empty image -@todo this function should be removed -@return returns an empty image if successful, returns NULL otherwise -*/ -opj_image_t* opj_image_create0(void); - -/*@}*/ - -#endif /* __IMAGE_H */ - +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __IMAGE_H +#define __IMAGE_H +/** +@file image.h +@brief Implementation of operations on images (IMAGE) + +The functions in IMAGE.C have for goal to realize operations on images. +*/ + +/** @defgroup IMAGE IMAGE - Implementation of operations on images */ +/*@{*/ + +/** +Create an empty image +@todo this function should be removed +@return returns an empty image if successful, returns NULL otherwise +*/ +opj_image_t* opj_image_create0(void); + +/*@}*/ + +#endif /* __IMAGE_H */ + diff --git a/Source/LibOpenJPEG/indexbox_manager.h b/Source/LibOpenJPEG/indexbox_manager.h index 33e0772..6ba167c 100644 --- a/Source/LibOpenJPEG/indexbox_manager.h +++ b/Source/LibOpenJPEG/indexbox_manager.h @@ -1,118 +1,118 @@ -/* - * $Id: indexbox_manager.h,v 1.2 2012/09/23 12:44:41 drolon Exp $ - * - * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2011, Professor Benoit Macq - * Copyright (c) 2003-2004, Yannick Verschueren - * Copyright (c) 2010-2011, Kaori Hagihara - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/*! \file - * \brief Modification of jpip.c from 2KAN indexer - */ - -#ifndef INDEXBOX_MANAGER_H_ -# define INDEXBOX_MANAGER_H_ - -#include "openjpeg.h" -#include "j2k.h" /* needed to use jp2.h */ -#include "jp2.h" - -#define JPIP_CIDX 0x63696478 /* Codestream index */ -#define JPIP_CPTR 0x63707472 /* Codestream Finder Box */ -#define JPIP_MANF 0x6d616e66 /* Manifest Box */ -#define JPIP_FAIX 0x66616978 /* Fragment array Index box */ -#define JPIP_MHIX 0x6d686978 /* Main Header Index Table */ -#define JPIP_TPIX 0x74706978 /* Tile-part Index Table box */ -#define JPIP_THIX 0x74686978 /* Tile header Index Table box */ -#define JPIP_PPIX 0x70706978 /* Precinct Packet Index Table box */ -#define JPIP_PHIX 0x70686978 /* Packet Header index Table */ -#define JPIP_FIDX 0x66696478 /* File Index */ -#define JPIP_FPTR 0x66707472 /* File Finder */ -#define JPIP_PRXY 0x70727879 /* Proxy boxes */ -#define JPIP_IPTR 0x69707472 /* Index finder box */ -#define JPIP_PHLD 0x70686c64 /* Place holder */ - - -/* - * Write tile-part Index table box (superbox) - * - * @param[in] coff offset of j2k codestream - * @param[in] cstr_info codestream information - * @param[in] j2klen length of j2k codestream - * @param[in] cio file output handle - * @return length of tpix box - */ -int write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio); - - -/* - * Write tile header index table box (superbox) - * - * @param[in] coff offset of j2k codestream - * @param[in] cstr_info codestream information pointer - * @param[in] cio file output handle - * @return length of thix box - */ -int write_thix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio); - - -/* - * Write precinct packet index table box (superbox) - * - * @param[in] coff offset of j2k codestream - * @param[in] cstr_info codestream information - * @param[in] EPHused true if EPH option used - * @param[in] j2klen length of j2k codestream - * @param[in] cio file output handle - * @return length of ppix box - */ -int write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio); - - -/* - * Write packet header index table box (superbox) - * - * @param[in] coff offset of j2k codestream - * @param[in] cstr_info codestream information - * @param[in] EPHused true if EPH option used - * @param[in] j2klen length of j2k codestream - * @param[in] cio file output handle - * @return length of ppix box - */ -int write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio); - -/* - * Wriet manifest box (box) - * - * @param[in] second number to be visited - * @param[in] v number of boxes - * @param[in] box box to be manifested - * @param[in] cio file output handle - */ -void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio); - - -#endif /* !INDEXBOX_MANAGER_H_ */ +/* + * $Id: indexbox_manager.h,v 1.2 2012/09/23 12:44:41 drolon Exp $ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2003-2004, Yannick Verschueren + * Copyright (c) 2010-2011, Kaori Hagihara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*! \file + * \brief Modification of jpip.c from 2KAN indexer + */ + +#ifndef INDEXBOX_MANAGER_H_ +# define INDEXBOX_MANAGER_H_ + +#include "openjpeg.h" +#include "j2k.h" /* needed to use jp2.h */ +#include "jp2.h" + +#define JPIP_CIDX 0x63696478 /* Codestream index */ +#define JPIP_CPTR 0x63707472 /* Codestream Finder Box */ +#define JPIP_MANF 0x6d616e66 /* Manifest Box */ +#define JPIP_FAIX 0x66616978 /* Fragment array Index box */ +#define JPIP_MHIX 0x6d686978 /* Main Header Index Table */ +#define JPIP_TPIX 0x74706978 /* Tile-part Index Table box */ +#define JPIP_THIX 0x74686978 /* Tile header Index Table box */ +#define JPIP_PPIX 0x70706978 /* Precinct Packet Index Table box */ +#define JPIP_PHIX 0x70686978 /* Packet Header index Table */ +#define JPIP_FIDX 0x66696478 /* File Index */ +#define JPIP_FPTR 0x66707472 /* File Finder */ +#define JPIP_PRXY 0x70727879 /* Proxy boxes */ +#define JPIP_IPTR 0x69707472 /* Index finder box */ +#define JPIP_PHLD 0x70686c64 /* Place holder */ + + +/* + * Write tile-part Index table box (superbox) + * + * @param[in] coff offset of j2k codestream + * @param[in] cstr_info codestream information + * @param[in] j2klen length of j2k codestream + * @param[in] cio file output handle + * @return length of tpix box + */ +int write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio); + + +/* + * Write tile header index table box (superbox) + * + * @param[in] coff offset of j2k codestream + * @param[in] cstr_info codestream information pointer + * @param[in] cio file output handle + * @return length of thix box + */ +int write_thix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio); + + +/* + * Write precinct packet index table box (superbox) + * + * @param[in] coff offset of j2k codestream + * @param[in] cstr_info codestream information + * @param[in] EPHused true if EPH option used + * @param[in] j2klen length of j2k codestream + * @param[in] cio file output handle + * @return length of ppix box + */ +int write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio); + + +/* + * Write packet header index table box (superbox) + * + * @param[in] coff offset of j2k codestream + * @param[in] cstr_info codestream information + * @param[in] EPHused true if EPH option used + * @param[in] j2klen length of j2k codestream + * @param[in] cio file output handle + * @return length of ppix box + */ +int write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio); + +/* + * Wriet manifest box (box) + * + * @param[in] second number to be visited + * @param[in] v number of boxes + * @param[in] box box to be manifested + * @param[in] cio file output handle + */ +void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio); + + +#endif /* !INDEXBOX_MANAGER_H_ */ diff --git a/Source/LibOpenJPEG/int.h b/Source/LibOpenJPEG/int.h index b650075..4e5fe08 100644 --- a/Source/LibOpenJPEG/int.h +++ b/Source/LibOpenJPEG/int.h @@ -1,119 +1,119 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __INT_H -#define __INT_H -/** -@file int.h -@brief Implementation of operations on integers (INT) - -The functions in INT.H have for goal to realize operations on integers. -*/ - -/** @defgroup INT INT - Implementation of operations on integers */ -/*@{*/ - -/** @name Exported functions (see also openjpeg.h) */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Get the minimum of two integers -@return Returns a if a < b else b -*/ -static INLINE int int_min(int a, int b) { - return a < b ? a : b; -} -/** -Get the maximum of two integers -@return Returns a if a > b else b -*/ -static INLINE int int_max(int a, int b) { - return (a > b) ? a : b; -} -/** -Clamp an integer inside an interval -@return -
    -
  • Returns a if (min < a < max) -
  • Returns max if (a > max) -
  • Returns min if (a < min) -
-*/ -static INLINE int int_clamp(int a, int min, int max) { - if (a < min) - return min; - if (a > max) - return max; - return a; -} -/** -@return Get absolute value of integer -*/ -static INLINE int int_abs(int a) { - return a < 0 ? -a : a; -} -/** -Divide an integer and round upwards -@return Returns a divided by b -*/ -static INLINE int int_ceildiv(int a, int b) { - return (a + b - 1) / b; -} -/** -Divide an integer by a power of 2 and round upwards -@return Returns a divided by 2^b -*/ -static INLINE int int_ceildivpow2(int a, int b) { - return (a + (1 << b) - 1) >> b; -} -/** -Divide an integer by a power of 2 and round downwards -@return Returns a divided by 2^b -*/ -static INLINE int int_floordivpow2(int a, int b) { - return a >> b; -} -/** -Get logarithm of an integer and round downwards -@return Returns log2(a) -*/ -static INLINE int int_floorlog2(int a) { - int l; - for (l = 0; a > 1; l++) { - a >>= 1; - } - return l; -} -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __INT_H +#define __INT_H +/** +@file int.h +@brief Implementation of operations on integers (INT) + +The functions in INT.H have for goal to realize operations on integers. +*/ + +/** @defgroup INT INT - Implementation of operations on integers */ +/*@{*/ + +/** @name Exported functions (see also openjpeg.h) */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Get the minimum of two integers +@return Returns a if a < b else b +*/ +static INLINE int int_min(int a, int b) { + return a < b ? a : b; +} +/** +Get the maximum of two integers +@return Returns a if a > b else b +*/ +static INLINE int int_max(int a, int b) { + return (a > b) ? a : b; +} +/** +Clamp an integer inside an interval +@return +
    +
  • Returns a if (min < a < max) +
  • Returns max if (a > max) +
  • Returns min if (a < min) +
+*/ +static INLINE int int_clamp(int a, int min, int max) { + if (a < min) + return min; + if (a > max) + return max; + return a; +} +/** +@return Get absolute value of integer +*/ +static INLINE int int_abs(int a) { + return a < 0 ? -a : a; +} +/** +Divide an integer and round upwards +@return Returns a divided by b +*/ +static INLINE int int_ceildiv(int a, int b) { + return (a + b - 1) / b; +} +/** +Divide an integer by a power of 2 and round upwards +@return Returns a divided by 2^b +*/ +static INLINE int int_ceildivpow2(int a, int b) { + return (a + (1 << b) - 1) >> b; +} +/** +Divide an integer by a power of 2 and round downwards +@return Returns a divided by 2^b +*/ +static INLINE int int_floordivpow2(int a, int b) { + return a >> b; +} +/** +Get logarithm of an integer and round downwards +@return Returns log2(a) +*/ +static INLINE int int_floorlog2(int a) { + int l; + for (l = 0; a > 1; l++) { + a >>= 1; + } + return l; +} +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif diff --git a/Source/LibOpenJPEG/j2k.c b/Source/LibOpenJPEG/j2k.c index dd87469..3f8e279 100644 --- a/Source/LibOpenJPEG/j2k.c +++ b/Source/LibOpenJPEG/j2k.c @@ -1,2616 +1,2616 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2006-2007, Parvatha Elangovan - * Copyright (c) 2010-2011, Kaori Hagihara - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */ -/*@{*/ - -/** @name Local static functions */ -/*@{*/ - -/** -Write the SOC marker (Start Of Codestream) -@param j2k J2K handle -*/ -static void j2k_write_soc(opj_j2k_t *j2k); -/** -Read the SOC marker (Start of Codestream) -@param j2k J2K handle -*/ -static void j2k_read_soc(opj_j2k_t *j2k); -/** -Write the SIZ marker (image and tile size) -@param j2k J2K handle -*/ -static void j2k_write_siz(opj_j2k_t *j2k); -/** -Read the SIZ marker (image and tile size) -@param j2k J2K handle -*/ -static void j2k_read_siz(opj_j2k_t *j2k); -/** -Write the COM marker (comment) -@param j2k J2K handle -*/ -static void j2k_write_com(opj_j2k_t *j2k); -/** -Read the COM marker (comment) -@param j2k J2K handle -*/ -static void j2k_read_com(opj_j2k_t *j2k); -/** -Write the value concerning the specified component in the marker COD and COC -@param j2k J2K handle -@param compno Number of the component concerned by the information written -*/ -static void j2k_write_cox(opj_j2k_t *j2k, int compno); -/** -Read the value concerning the specified component in the marker COD and COC -@param j2k J2K handle -@param compno Number of the component concerned by the information read -*/ -static void j2k_read_cox(opj_j2k_t *j2k, int compno); -/** -Write the COD marker (coding style default) -@param j2k J2K handle -*/ -static void j2k_write_cod(opj_j2k_t *j2k); -/** -Read the COD marker (coding style default) -@param j2k J2K handle -*/ -static void j2k_read_cod(opj_j2k_t *j2k); -/** -Write the COC marker (coding style component) -@param j2k J2K handle -@param compno Number of the component concerned by the information written -*/ -static void j2k_write_coc(opj_j2k_t *j2k, int compno); -/** -Read the COC marker (coding style component) -@param j2k J2K handle -*/ -static void j2k_read_coc(opj_j2k_t *j2k); -/** -Write the value concerning the specified component in the marker QCD and QCC -@param j2k J2K handle -@param compno Number of the component concerned by the information written -*/ -static void j2k_write_qcx(opj_j2k_t *j2k, int compno); -/** -Read the value concerning the specified component in the marker QCD and QCC -@param j2k J2K handle -@param compno Number of the component concern by the information read -@param len Length of the information in the QCX part of the marker QCD/QCC -*/ -static void j2k_read_qcx(opj_j2k_t *j2k, int compno, int len); -/** -Write the QCD marker (quantization default) -@param j2k J2K handle -*/ -static void j2k_write_qcd(opj_j2k_t *j2k); -/** -Read the QCD marker (quantization default) -@param j2k J2K handle -*/ -static void j2k_read_qcd(opj_j2k_t *j2k); -/** -Write the QCC marker (quantization component) -@param j2k J2K handle -@param compno Number of the component concerned by the information written -*/ -static void j2k_write_qcc(opj_j2k_t *j2k, int compno); -/** -Read the QCC marker (quantization component) -@param j2k J2K handle -*/ -static void j2k_read_qcc(opj_j2k_t *j2k); -/** -Write the POC marker (progression order change) -@param j2k J2K handle -*/ -static void j2k_write_poc(opj_j2k_t *j2k); -/** -Read the POC marker (progression order change) -@param j2k J2K handle -*/ -static void j2k_read_poc(opj_j2k_t *j2k); -/** -Read the CRG marker (component registration) -@param j2k J2K handle -*/ -static void j2k_read_crg(opj_j2k_t *j2k); -/** -Read the TLM marker (tile-part lengths) -@param j2k J2K handle -*/ -static void j2k_read_tlm(opj_j2k_t *j2k); -/** -Read the PLM marker (packet length, main header) -@param j2k J2K handle -*/ -static void j2k_read_plm(opj_j2k_t *j2k); -/** -Read the PLT marker (packet length, tile-part header) -@param j2k J2K handle -*/ -static void j2k_read_plt(opj_j2k_t *j2k); -/** -Read the PPM marker (packet packet headers, main header) -@param j2k J2K handle -*/ -static void j2k_read_ppm(opj_j2k_t *j2k); -/** -Read the PPT marker (packet packet headers, tile-part header) -@param j2k J2K handle -*/ -static void j2k_read_ppt(opj_j2k_t *j2k); -/** -Write the TLM marker (Mainheader) -@param j2k J2K handle -*/ -static void j2k_write_tlm(opj_j2k_t *j2k); -/** -Write the SOT marker (start of tile-part) -@param j2k J2K handle -*/ -static void j2k_write_sot(opj_j2k_t *j2k); -/** -Read the SOT marker (start of tile-part) -@param j2k J2K handle -*/ -static void j2k_read_sot(opj_j2k_t *j2k); -/** -Write the SOD marker (start of data) -@param j2k J2K handle -@param tile_coder Pointer to a TCD handle -*/ -static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder); -/** -Read the SOD marker (start of data) -@param j2k J2K handle -*/ -static void j2k_read_sod(opj_j2k_t *j2k); -/** -Write the RGN marker (region-of-interest) -@param j2k J2K handle -@param compno Number of the component concerned by the information written -@param tileno Number of the tile concerned by the information written -*/ -static void j2k_write_rgn(opj_j2k_t *j2k, int compno, int tileno); -/** -Read the RGN marker (region-of-interest) -@param j2k J2K handle -*/ -static void j2k_read_rgn(opj_j2k_t *j2k); -/** -Write the EOC marker (end of codestream) -@param j2k J2K handle -*/ -static void j2k_write_eoc(opj_j2k_t *j2k); -/** -Read the EOC marker (end of codestream) -@param j2k J2K handle -*/ -static void j2k_read_eoc(opj_j2k_t *j2k); -/** -Read an unknown marker -@param j2k J2K handle -*/ -static void j2k_read_unk(opj_j2k_t *j2k); -/** -Add main header marker information -@param cstr_info Codestream information structure -@param type marker type -@param pos byte offset of marker segment -@param len length of marker segment - */ -static void j2k_add_mhmarker(opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len); -/** -Add tile header marker information -@param tileno tile index number -@param cstr_info Codestream information structure -@param type marker type -@param pos byte offset of marker segment -@param len length of marker segment - */ -static void j2k_add_tlmarker( int tileno, opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len); - -/*@}*/ - -/*@}*/ - -/* ----------------------------------------------------------------------- */ -typedef struct j2k_prog_order{ - OPJ_PROG_ORDER enum_prog; - char str_prog[5]; -}j2k_prog_order_t; - -j2k_prog_order_t j2k_prog_order_list[] = { - {CPRL, "CPRL"}, - {LRCP, "LRCP"}, - {PCRL, "PCRL"}, - {RLCP, "RLCP"}, - {RPCL, "RPCL"}, - {(OPJ_PROG_ORDER)-1, ""} -}; - -char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order){ - j2k_prog_order_t *po; - for(po = j2k_prog_order_list; po->enum_prog != -1; po++ ){ - if(po->enum_prog == prg_order){ - break; - } - } - return po->str_prog; -} - -/* ----------------------------------------------------------------------- */ -static int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno){ - char *prog; - int i; - int tpnum=1,tpend=0; - opj_tcp_t *tcp = &cp->tcps[tileno]; - prog = j2k_convert_progression_order(tcp->prg); - - if(cp->tp_on == 1){ - for(i=0;i<4;i++){ - if(tpend!=1){ - if( cp->tp_flag == prog[i] ){ - tpend=1;cp->tp_pos=i; - } - switch(prog[i]){ - case 'C': - tpnum= tpnum * tcp->pocs[pino].compE; - break; - case 'R': - tpnum= tpnum * tcp->pocs[pino].resE; - break; - case 'P': - tpnum= tpnum * tcp->pocs[pino].prcE; - break; - case 'L': - tpnum= tpnum * tcp->pocs[pino].layE; - break; - } - } - } - }else{ - tpnum=1; - } - return tpnum; -} - -/** mem allocation for TLM marker*/ -int j2k_calculate_tp(opj_cp_t *cp,int img_numcomp,opj_image_t *image,opj_j2k_t *j2k ){ - int pino,tileno,totnum_tp=0; - - OPJ_ARG_NOT_USED(img_numcomp); - - j2k->cur_totnum_tp = (int *) opj_malloc(cp->tw * cp->th * sizeof(int)); - for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { - int cur_totnum_tp = 0; - opj_tcp_t *tcp = &cp->tcps[tileno]; - for(pino = 0; pino <= tcp->numpocs; pino++) { - int tp_num=0; - opj_pi_iterator_t *pi = pi_initialise_encode(image, cp, tileno,FINAL_PASS); - if(!pi) { return -1;} - tp_num = j2k_get_num_tp(cp,pino,tileno); - totnum_tp = totnum_tp + tp_num; - cur_totnum_tp = cur_totnum_tp + tp_num; - pi_destroy(pi, cp, tileno); - } - j2k->cur_totnum_tp[tileno] = cur_totnum_tp; - /* INDEX >> */ - if (j2k->cstr_info) { - j2k->cstr_info->tile[tileno].num_tps = cur_totnum_tp; - j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_malloc(cur_totnum_tp * sizeof(opj_tp_info_t)); - } - /* << INDEX */ - } - return totnum_tp; -} - -static void j2k_write_soc(opj_j2k_t *j2k) { - opj_cio_t *cio = j2k->cio; - cio_write(cio, J2K_MS_SOC, 2); - - if(j2k->cstr_info) - j2k_add_mhmarker(j2k->cstr_info, J2K_MS_SOC, cio_tell(cio), 0); - -/* UniPG>> */ -#ifdef USE_JPWL - - /* update markers struct */ - j2k_add_marker(j2k->cstr_info, J2K_MS_SOC, cio_tell(cio) - 2, 2); -#endif /* USE_JPWL */ -/* <state = J2K_STATE_MHSIZ; - /* Index */ - if (j2k->cstr_info) { - j2k->cstr_info->main_head_start = cio_tell(j2k->cio) - 2; - j2k->cstr_info->codestream_size = cio_numbytesleft(j2k->cio) + 2 - j2k->cstr_info->main_head_start; - } -} - -static void j2k_write_siz(opj_j2k_t *j2k) { - int i; - int lenp, len; - - opj_cio_t *cio = j2k->cio; - opj_image_t *image = j2k->image; - opj_cp_t *cp = j2k->cp; - - cio_write(cio, J2K_MS_SIZ, 2); /* SIZ */ - lenp = cio_tell(cio); - cio_skip(cio, 2); - cio_write(cio, cp->rsiz, 2); /* Rsiz (capabilities) */ - cio_write(cio, image->x1, 4); /* Xsiz */ - cio_write(cio, image->y1, 4); /* Ysiz */ - cio_write(cio, image->x0, 4); /* X0siz */ - cio_write(cio, image->y0, 4); /* Y0siz */ - cio_write(cio, cp->tdx, 4); /* XTsiz */ - cio_write(cio, cp->tdy, 4); /* YTsiz */ - cio_write(cio, cp->tx0, 4); /* XT0siz */ - cio_write(cio, cp->ty0, 4); /* YT0siz */ - cio_write(cio, image->numcomps, 2); /* Csiz */ - for (i = 0; i < image->numcomps; i++) { - cio_write(cio, image->comps[i].prec - 1 + (image->comps[i].sgnd << 7), 1); /* Ssiz_i */ - cio_write(cio, image->comps[i].dx, 1); /* XRsiz_i */ - cio_write(cio, image->comps[i].dy, 1); /* YRsiz_i */ - } - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Lsiz */ - cio_seek(cio, lenp + len); - - if(j2k->cstr_info) - j2k_add_mhmarker(j2k->cstr_info, J2K_MS_SIZ, lenp, len); -} - -static void j2k_read_siz(opj_j2k_t *j2k) { - int len, i; - - opj_cio_t *cio = j2k->cio; - opj_image_t *image = j2k->image; - opj_cp_t *cp = j2k->cp; - - len = cio_read(cio, 2); /* Lsiz */ - cio_read(cio, 2); /* Rsiz (capabilities) */ - image->x1 = cio_read(cio, 4); /* Xsiz */ - image->y1 = cio_read(cio, 4); /* Ysiz */ - image->x0 = cio_read(cio, 4); /* X0siz */ - image->y0 = cio_read(cio, 4); /* Y0siz */ - cp->tdx = cio_read(cio, 4); /* XTsiz */ - cp->tdy = cio_read(cio, 4); /* YTsiz */ - cp->tx0 = cio_read(cio, 4); /* XT0siz */ - cp->ty0 = cio_read(cio, 4); /* YT0siz */ - - if ((image->x0<0)||(image->x1<0)||(image->y0<0)||(image->y1<0)) { - opj_event_msg(j2k->cinfo, EVT_ERROR, - "%s: invalid image size (x0:%d, x1:%d, y0:%d, y1:%d)\n", - image->x0,image->x1,image->y0,image->y1); - return; - } - - image->numcomps = cio_read(cio, 2); /* Csiz */ - -#ifdef USE_JPWL - if (j2k->cp->correct) { - /* if JPWL is on, we check whether TX errors have damaged - too much the SIZ parameters */ - if (!(image->x1 * image->y1)) { - opj_event_msg(j2k->cinfo, EVT_ERROR, - "JPWL: bad image size (%d x %d)\n", - image->x1, image->y1); - if (!JPWL_ASSUME || JPWL_ASSUME) { - opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); - return; - } - } - if (image->numcomps != ((len - 38) / 3)) { - opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR, - "JPWL: Csiz is %d => space in SIZ only for %d comps.!!!\n", - image->numcomps, ((len - 38) / 3)); - if (!JPWL_ASSUME) { - opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); - return; - } - /* we try to correct */ - opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n"); - if (image->numcomps < ((len - 38) / 3)) { - len = 38 + 3 * image->numcomps; - opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting Lsiz to %d => HYPOTHESIS!!!\n", - len); - } else { - image->numcomps = ((len - 38) / 3); - opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting Csiz to %d => HYPOTHESIS!!!\n", - image->numcomps); - } - } - - /* update components number in the jpwl_exp_comps filed */ - cp->exp_comps = image->numcomps; - } -#endif /* USE_JPWL */ - - image->comps = (opj_image_comp_t*) opj_calloc(image->numcomps, sizeof(opj_image_comp_t)); - for (i = 0; i < image->numcomps; i++) { - int tmp, w, h; - tmp = cio_read(cio, 1); /* Ssiz_i */ - image->comps[i].prec = (tmp & 0x7f) + 1; - image->comps[i].sgnd = tmp >> 7; - image->comps[i].dx = cio_read(cio, 1); /* XRsiz_i */ - image->comps[i].dy = cio_read(cio, 1); /* YRsiz_i */ - -#ifdef USE_JPWL - if (j2k->cp->correct) { - /* if JPWL is on, we check whether TX errors have damaged - too much the SIZ parameters, again */ - if (!(image->comps[i].dx * image->comps[i].dy)) { - opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR, - "JPWL: bad XRsiz_%d/YRsiz_%d (%d x %d)\n", - i, i, image->comps[i].dx, image->comps[i].dy); - if (!JPWL_ASSUME) { - opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); - return; - } - /* we try to correct */ - opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust them\n"); - if (!image->comps[i].dx) { - image->comps[i].dx = 1; - opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting XRsiz_%d to %d => HYPOTHESIS!!!\n", - i, image->comps[i].dx); - } - if (!image->comps[i].dy) { - image->comps[i].dy = 1; - opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting YRsiz_%d to %d => HYPOTHESIS!!!\n", - i, image->comps[i].dy); - } - } - - } -#endif /* USE_JPWL */ - - /* TODO: unused ? */ - w = int_ceildiv(image->x1 - image->x0, image->comps[i].dx); - h = int_ceildiv(image->y1 - image->y0, image->comps[i].dy); - - image->comps[i].resno_decoded = 0; /* number of resolution decoded */ - image->comps[i].factor = cp->reduce; /* reducing factor per component */ - } - - cp->tw = int_ceildiv(image->x1 - cp->tx0, cp->tdx); - cp->th = int_ceildiv(image->y1 - cp->ty0, cp->tdy); - -#ifdef USE_JPWL - if (j2k->cp->correct) { - /* if JPWL is on, we check whether TX errors have damaged - too much the SIZ parameters */ - if ((cp->tw < 1) || (cp->th < 1) || (cp->tw > cp->max_tiles) || (cp->th > cp->max_tiles)) { - opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR, - "JPWL: bad number of tiles (%d x %d)\n", - cp->tw, cp->th); - if (!JPWL_ASSUME) { - opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); - return; - } - /* we try to correct */ - opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust them\n"); - if (cp->tw < 1) { - cp->tw= 1; - opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting %d tiles in x => HYPOTHESIS!!!\n", - cp->tw); - } - if (cp->tw > cp->max_tiles) { - cp->tw= 1; - opj_event_msg(j2k->cinfo, EVT_WARNING, "- too large x, increase expectance of %d\n" - "- setting %d tiles in x => HYPOTHESIS!!!\n", - cp->max_tiles, cp->tw); - } - if (cp->th < 1) { - cp->th= 1; - opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting %d tiles in y => HYPOTHESIS!!!\n", - cp->th); - } - if (cp->th > cp->max_tiles) { - cp->th= 1; - opj_event_msg(j2k->cinfo, EVT_WARNING, "- too large y, increase expectance of %d to continue\n", - "- setting %d tiles in y => HYPOTHESIS!!!\n", - cp->max_tiles, cp->th); - } - } - } -#endif /* USE_JPWL */ - - cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t)); - if (cp->tcps == NULL) - { - opj_event_msg(j2k->cinfo, EVT_ERROR, "Out of memory\n"); - return; - } - cp->tileno = (int*) opj_malloc(cp->tw * cp->th * sizeof(int)); - if (cp->tileno == NULL) - { - opj_event_msg(j2k->cinfo, EVT_ERROR, "Out of memory\n"); - return; - } - cp->tileno_size = 0; - -#ifdef USE_JPWL - if (j2k->cp->correct) { - if (!cp->tcps) { - opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR, - "JPWL: could not alloc tcps field of cp\n"); - if (!JPWL_ASSUME || JPWL_ASSUME) { - opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); - return; - } - } - } -#endif /* USE_JPWL */ - - for (i = 0; i < cp->tw * cp->th; i++) { - cp->tcps[i].POC = 0; - cp->tcps[i].numpocs = 0; - cp->tcps[i].first = 1; - } - - /* Initialization for PPM marker */ - cp->ppm = 0; - cp->ppm_data = NULL; - cp->ppm_data_first = NULL; - cp->ppm_previous = 0; - cp->ppm_store = 0; - - j2k->default_tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t)); - for (i = 0; i < cp->tw * cp->th; i++) { - cp->tcps[i].tccps = (opj_tccp_t*) opj_malloc(image->numcomps * sizeof(opj_tccp_t)); - } - j2k->tile_data = (unsigned char**) opj_calloc(cp->tw * cp->th, sizeof(unsigned char*)); - j2k->tile_len = (int*) opj_calloc(cp->tw * cp->th, sizeof(int)); - j2k->state = J2K_STATE_MH; - - /* Index */ - if (j2k->cstr_info) { - opj_codestream_info_t *cstr_info = j2k->cstr_info; - cstr_info->image_w = image->x1 - image->x0; - cstr_info->image_h = image->y1 - image->y0; - cstr_info->numcomps = image->numcomps; - cstr_info->tw = cp->tw; - cstr_info->th = cp->th; - cstr_info->tile_x = cp->tdx; - cstr_info->tile_y = cp->tdy; - cstr_info->tile_Ox = cp->tx0; - cstr_info->tile_Oy = cp->ty0; - cstr_info->tile = (opj_tile_info_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tile_info_t)); - } -} - -static void j2k_write_com(opj_j2k_t *j2k) { - unsigned int i; - int lenp, len; - - if(j2k->cp->comment) { - opj_cio_t *cio = j2k->cio; - char *comment = j2k->cp->comment; - - cio_write(cio, J2K_MS_COM, 2); - lenp = cio_tell(cio); - cio_skip(cio, 2); - cio_write(cio, 1, 2); /* General use (IS 8859-15:1999 (Latin) values) */ - for (i = 0; i < strlen(comment); i++) { - cio_write(cio, comment[i], 1); - } - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); - cio_seek(cio, lenp + len); - - - if(j2k->cstr_info) - j2k_add_mhmarker(j2k->cstr_info, J2K_MS_COM, lenp, len); - - } -} - -static void j2k_read_com(opj_j2k_t *j2k) { - int len; - - opj_cio_t *cio = j2k->cio; - - len = cio_read(cio, 2); - cio_skip(cio, len - 2); -} - -static void j2k_write_cox(opj_j2k_t *j2k, int compno) { - int i; - - opj_cp_t *cp = j2k->cp; - opj_tcp_t *tcp = &cp->tcps[j2k->curtileno]; - opj_tccp_t *tccp = &tcp->tccps[compno]; - opj_cio_t *cio = j2k->cio; - - cio_write(cio, tccp->numresolutions - 1, 1); /* SPcox (D) */ - cio_write(cio, tccp->cblkw - 2, 1); /* SPcox (E) */ - cio_write(cio, tccp->cblkh - 2, 1); /* SPcox (F) */ - cio_write(cio, tccp->cblksty, 1); /* SPcox (G) */ - cio_write(cio, tccp->qmfbid, 1); /* SPcox (H) */ - - if (tccp->csty & J2K_CCP_CSTY_PRT) { - for (i = 0; i < tccp->numresolutions; i++) { - cio_write(cio, tccp->prcw[i] + (tccp->prch[i] << 4), 1); /* SPcox (I_i) */ - } - } -} - -static void j2k_read_cox(opj_j2k_t *j2k, int compno) { - int i; - - opj_cp_t *cp = j2k->cp; - opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp; - opj_tccp_t *tccp = &tcp->tccps[compno]; - opj_cio_t *cio = j2k->cio; - - tccp->numresolutions = cio_read(cio, 1) + 1; /* SPcox (D) */ - - /* If user wants to remove more resolutions than the codestream contains, return error*/ - if (cp->reduce >= tccp->numresolutions) { - opj_event_msg(j2k->cinfo, EVT_ERROR, "Error decoding component %d.\nThe number of resolutions to remove is higher than the number " - "of resolutions of this component\nModify the cp_reduce parameter.\n\n", compno); - j2k->state |= J2K_STATE_ERR; - } - if( tccp->numresolutions > J2K_MAXRLVLS ) { - opj_event_msg(j2k->cinfo, EVT_ERROR, "Error decoding component %d.\nThe number of resolutions is too big: %d vs max= %d. Truncating.\n\n", - compno, tccp->numresolutions, J2K_MAXRLVLS); - j2k->state |= J2K_STATE_ERR; - tccp->numresolutions = J2K_MAXRLVLS; - } - - tccp->cblkw = cio_read(cio, 1) + 2; /* SPcox (E) */ - tccp->cblkh = cio_read(cio, 1) + 2; /* SPcox (F) */ - tccp->cblksty = cio_read(cio, 1); /* SPcox (G) */ - tccp->qmfbid = cio_read(cio, 1); /* SPcox (H) */ - if (tccp->csty & J2K_CP_CSTY_PRT) { - for (i = 0; i < tccp->numresolutions; i++) { - int tmp = cio_read(cio, 1); /* SPcox (I_i) */ - tccp->prcw[i] = tmp & 0xf; - tccp->prch[i] = tmp >> 4; - } - } - - /* INDEX >> */ - if(j2k->cstr_info && compno == 0) { - for (i = 0; i < tccp->numresolutions; i++) { - if (tccp->csty & J2K_CP_CSTY_PRT) { - j2k->cstr_info->tile[j2k->curtileno].pdx[i] = tccp->prcw[i]; - j2k->cstr_info->tile[j2k->curtileno].pdy[i] = tccp->prch[i]; - } - else { - j2k->cstr_info->tile[j2k->curtileno].pdx[i] = 15; - j2k->cstr_info->tile[j2k->curtileno].pdx[i] = 15; - } - } - } - /* << INDEX */ -} - -static void j2k_write_cod(opj_j2k_t *j2k) { - opj_cp_t *cp = NULL; - opj_tcp_t *tcp = NULL; - int lenp, len; - - opj_cio_t *cio = j2k->cio; - - cio_write(cio, J2K_MS_COD, 2); /* COD */ - - lenp = cio_tell(cio); - cio_skip(cio, 2); - - cp = j2k->cp; - tcp = &cp->tcps[j2k->curtileno]; - - cio_write(cio, tcp->csty, 1); /* Scod */ - cio_write(cio, tcp->prg, 1); /* SGcod (A) */ - cio_write(cio, tcp->numlayers, 2); /* SGcod (B) */ - cio_write(cio, tcp->mct, 1); /* SGcod (C) */ - - j2k_write_cox(j2k, 0); - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Lcod */ - cio_seek(cio, lenp + len); - - if(j2k->cstr_info) - j2k_add_mhmarker(j2k->cstr_info, J2K_MS_COD, lenp, len); - -} - -static void j2k_read_cod(opj_j2k_t *j2k) { - int len, i, pos; - - opj_cio_t *cio = j2k->cio; - opj_cp_t *cp = j2k->cp; - opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp; - opj_image_t *image = j2k->image; - - len = cio_read(cio, 2); /* Lcod */ - tcp->csty = cio_read(cio, 1); /* Scod */ - tcp->prg = (OPJ_PROG_ORDER)cio_read(cio, 1); /* SGcod (A) */ - tcp->numlayers = cio_read(cio, 2); /* SGcod (B) */ - tcp->mct = cio_read(cio, 1); /* SGcod (C) */ - - pos = cio_tell(cio); - for (i = 0; i < image->numcomps; i++) { - tcp->tccps[i].csty = tcp->csty & J2K_CP_CSTY_PRT; - cio_seek(cio, pos); - j2k_read_cox(j2k, i); - } - - /* Index */ - if (j2k->cstr_info) { - opj_codestream_info_t *cstr_info = j2k->cstr_info; - cstr_info->prog = tcp->prg; - cstr_info->numlayers = tcp->numlayers; - cstr_info->numdecompos = (int*) opj_malloc(image->numcomps * sizeof(int)); - for (i = 0; i < image->numcomps; i++) { - cstr_info->numdecompos[i] = tcp->tccps[i].numresolutions - 1; - } - } -} - -static void j2k_write_coc(opj_j2k_t *j2k, int compno) { - int lenp, len; - - opj_cp_t *cp = j2k->cp; - opj_tcp_t *tcp = &cp->tcps[j2k->curtileno]; - opj_image_t *image = j2k->image; - opj_cio_t *cio = j2k->cio; - - cio_write(cio, J2K_MS_COC, 2); /* COC */ - lenp = cio_tell(cio); - cio_skip(cio, 2); - cio_write(cio, compno, image->numcomps <= 256 ? 1 : 2); /* Ccoc */ - cio_write(cio, tcp->tccps[compno].csty, 1); /* Scoc */ - j2k_write_cox(j2k, compno); - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Lcoc */ - cio_seek(cio, lenp + len); -} - -static void j2k_read_coc(opj_j2k_t *j2k) { - int len, compno; - - opj_cp_t *cp = j2k->cp; - opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp; - opj_image_t *image = j2k->image; - opj_cio_t *cio = j2k->cio; - - len = cio_read(cio, 2); /* Lcoc */ - compno = cio_read(cio, image->numcomps <= 256 ? 1 : 2); /* Ccoc */ - tcp->tccps[compno].csty = cio_read(cio, 1); /* Scoc */ - j2k_read_cox(j2k, compno); -} - -static void j2k_write_qcx(opj_j2k_t *j2k, int compno) { - int bandno, numbands; - int expn, mant; - - opj_cp_t *cp = j2k->cp; - opj_tcp_t *tcp = &cp->tcps[j2k->curtileno]; - opj_tccp_t *tccp = &tcp->tccps[compno]; - opj_cio_t *cio = j2k->cio; - - cio_write(cio, tccp->qntsty + (tccp->numgbits << 5), 1); /* Sqcx */ - numbands = tccp->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : tccp->numresolutions * 3 - 2; - - for (bandno = 0; bandno < numbands; bandno++) { - expn = tccp->stepsizes[bandno].expn; - mant = tccp->stepsizes[bandno].mant; - - if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) { - cio_write(cio, expn << 3, 1); /* SPqcx_i */ - } else { - cio_write(cio, (expn << 11) + mant, 2); /* SPqcx_i */ - } - } -} - -static void j2k_read_qcx(opj_j2k_t *j2k, int compno, int len) { - int tmp; - int bandno, numbands; - - opj_cp_t *cp = j2k->cp; - opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp; - opj_tccp_t *tccp = &tcp->tccps[compno]; - opj_cio_t *cio = j2k->cio; - - tmp = cio_read(cio, 1); /* Sqcx */ - tccp->qntsty = tmp & 0x1f; - tccp->numgbits = tmp >> 5; - numbands = (tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) ? - 1 : ((tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) ? len - 1 : (len - 1) / 2); - -#ifdef USE_JPWL - if (j2k->cp->correct) { - - /* if JPWL is on, we check whether there are too many subbands */ - if ((numbands < 0) || (numbands >= J2K_MAXBANDS)) { - opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR, - "JPWL: bad number of subbands in Sqcx (%d)\n", - numbands); - if (!JPWL_ASSUME) { - opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); - return; - } - /* we try to correct */ - numbands = 1; - opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust them\n" - "- setting number of bands to %d => HYPOTHESIS!!!\n", - numbands); - }; - - }; - -#else - /* We check whether there are too many subbands */ - if ((numbands < 0) || (numbands >= J2K_MAXBANDS)) { - opj_event_msg(j2k->cinfo, EVT_WARNING , - "bad number of subbands in Sqcx (%d) regarding to J2K_MAXBANDS (%d) \n" - "- limiting number of bands to J2K_MAXBANDS and try to move to the next markers\n", numbands, J2K_MAXBANDS); - } - -#endif /* USE_JPWL */ - - for (bandno = 0; bandno < numbands; bandno++) { - int expn, mant; - if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) { - expn = cio_read(cio, 1) >> 3; /* SPqcx_i */ - mant = 0; - } else { - tmp = cio_read(cio, 2); /* SPqcx_i */ - expn = tmp >> 11; - mant = tmp & 0x7ff; - } - if (bandno < J2K_MAXBANDS){ - tccp->stepsizes[bandno].expn = expn; - tccp->stepsizes[bandno].mant = mant; - } - } - - /* Add Antonin : if scalar_derived -> compute other stepsizes */ - if (tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) { - for (bandno = 1; bandno < J2K_MAXBANDS; bandno++) { - tccp->stepsizes[bandno].expn = - ((tccp->stepsizes[0].expn) - ((bandno - 1) / 3) > 0) ? - (tccp->stepsizes[0].expn) - ((bandno - 1) / 3) : 0; - tccp->stepsizes[bandno].mant = tccp->stepsizes[0].mant; - } - } - /* ddA */ -} - -static void j2k_write_qcd(opj_j2k_t *j2k) { - int lenp, len; - - opj_cio_t *cio = j2k->cio; - - cio_write(cio, J2K_MS_QCD, 2); /* QCD */ - lenp = cio_tell(cio); - cio_skip(cio, 2); - j2k_write_qcx(j2k, 0); - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Lqcd */ - cio_seek(cio, lenp + len); - - if(j2k->cstr_info) - j2k_add_mhmarker(j2k->cstr_info, J2K_MS_QCD, lenp, len); -} - -static void j2k_read_qcd(opj_j2k_t *j2k) { - int len, i, pos; - - opj_cio_t *cio = j2k->cio; - opj_image_t *image = j2k->image; - - len = cio_read(cio, 2); /* Lqcd */ - pos = cio_tell(cio); - for (i = 0; i < image->numcomps; i++) { - cio_seek(cio, pos); - j2k_read_qcx(j2k, i, len - 2); - } -} - -static void j2k_write_qcc(opj_j2k_t *j2k, int compno) { - int lenp, len; - - opj_cio_t *cio = j2k->cio; - - cio_write(cio, J2K_MS_QCC, 2); /* QCC */ - lenp = cio_tell(cio); - cio_skip(cio, 2); - cio_write(cio, compno, j2k->image->numcomps <= 256 ? 1 : 2); /* Cqcc */ - j2k_write_qcx(j2k, compno); - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Lqcc */ - cio_seek(cio, lenp + len); -} - -static void j2k_read_qcc(opj_j2k_t *j2k) { - int len, compno; - int numcomp = j2k->image->numcomps; - opj_cio_t *cio = j2k->cio; - - len = cio_read(cio, 2); /* Lqcc */ - compno = cio_read(cio, numcomp <= 256 ? 1 : 2); /* Cqcc */ - -#ifdef USE_JPWL - if (j2k->cp->correct) { - - static int backup_compno = 0; - - /* compno is negative or larger than the number of components!!! */ - if ((compno < 0) || (compno >= numcomp)) { - opj_event_msg(j2k->cinfo, EVT_ERROR, - "JPWL: bad component number in QCC (%d out of a maximum of %d)\n", - compno, numcomp); - if (!JPWL_ASSUME) { - opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); - return; - } - /* we try to correct */ - compno = backup_compno % numcomp; - opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n" - "- setting component number to %d\n", - compno); - } - - /* keep your private count of tiles */ - backup_compno++; - }; -#endif /* USE_JPWL */ - - j2k_read_qcx(j2k, compno, len - 2 - (numcomp <= 256 ? 1 : 2)); -} - -static void j2k_write_poc(opj_j2k_t *j2k) { - int len, numpchgs, i; - - int numcomps = j2k->image->numcomps; - - opj_cp_t *cp = j2k->cp; - opj_tcp_t *tcp = &cp->tcps[j2k->curtileno]; - opj_tccp_t *tccp = &tcp->tccps[0]; - opj_cio_t *cio = j2k->cio; - - numpchgs = 1 + tcp->numpocs; - cio_write(cio, J2K_MS_POC, 2); /* POC */ - len = 2 + (5 + 2 * (numcomps <= 256 ? 1 : 2)) * numpchgs; - cio_write(cio, len, 2); /* Lpoc */ - for (i = 0; i < numpchgs; i++) { - opj_poc_t *poc = &tcp->pocs[i]; - cio_write(cio, poc->resno0, 1); /* RSpoc_i */ - cio_write(cio, poc->compno0, (numcomps <= 256 ? 1 : 2)); /* CSpoc_i */ - cio_write(cio, poc->layno1, 2); /* LYEpoc_i */ - poc->layno1 = int_min(poc->layno1, tcp->numlayers); - cio_write(cio, poc->resno1, 1); /* REpoc_i */ - poc->resno1 = int_min(poc->resno1, tccp->numresolutions); - cio_write(cio, poc->compno1, (numcomps <= 256 ? 1 : 2)); /* CEpoc_i */ - poc->compno1 = int_min(poc->compno1, numcomps); - cio_write(cio, poc->prg, 1); /* Ppoc_i */ - } -} - -static void j2k_read_poc(opj_j2k_t *j2k) { - int len, numpchgs, i, old_poc; - - int numcomps = j2k->image->numcomps; - - opj_cp_t *cp = j2k->cp; - opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp; - opj_cio_t *cio = j2k->cio; - - old_poc = tcp->POC ? tcp->numpocs + 1 : 0; - tcp->POC = 1; - len = cio_read(cio, 2); /* Lpoc */ - numpchgs = (len - 2) / (5 + 2 * (numcomps <= 256 ? 1 : 2)); - - for (i = old_poc; i < numpchgs + old_poc; i++) { - opj_poc_t *poc; - poc = &tcp->pocs[i]; - poc->resno0 = cio_read(cio, 1); /* RSpoc_i */ - poc->compno0 = cio_read(cio, numcomps <= 256 ? 1 : 2); /* CSpoc_i */ - poc->layno1 = cio_read(cio, 2); /* LYEpoc_i */ - poc->resno1 = cio_read(cio, 1); /* REpoc_i */ - poc->compno1 = int_min( - cio_read(cio, numcomps <= 256 ? 1 : 2), (unsigned int) numcomps); /* CEpoc_i */ - poc->prg = (OPJ_PROG_ORDER)cio_read(cio, 1); /* Ppoc_i */ - } - - tcp->numpocs = numpchgs + old_poc - 1; -} - -static void j2k_read_crg(opj_j2k_t *j2k) { - int len, i, Xcrg_i, Ycrg_i; - - opj_cio_t *cio = j2k->cio; - int numcomps = j2k->image->numcomps; - - len = cio_read(cio, 2); /* Lcrg */ - for (i = 0; i < numcomps; i++) { - Xcrg_i = cio_read(cio, 2); /* Xcrg_i */ - Ycrg_i = cio_read(cio, 2); /* Ycrg_i */ - } -} - -static void j2k_read_tlm(opj_j2k_t *j2k) { - int len, Ztlm, Stlm, ST, SP, tile_tlm, i; - long int Ttlm_i, Ptlm_i; - - opj_cio_t *cio = j2k->cio; - - len = cio_read(cio, 2); /* Ltlm */ - Ztlm = cio_read(cio, 1); /* Ztlm */ - Stlm = cio_read(cio, 1); /* Stlm */ - ST = ((Stlm >> 4) & 0x01) + ((Stlm >> 4) & 0x02); - SP = (Stlm >> 6) & 0x01; - tile_tlm = (len - 4) / ((SP + 1) * 2 + ST); - for (i = 0; i < tile_tlm; i++) { - Ttlm_i = cio_read(cio, ST); /* Ttlm_i */ - Ptlm_i = cio_read(cio, SP ? 4 : 2); /* Ptlm_i */ - } -} - -static void j2k_read_plm(opj_j2k_t *j2k) { - int len, i, Zplm, Nplm, add, packet_len = 0; - - opj_cio_t *cio = j2k->cio; - - len = cio_read(cio, 2); /* Lplm */ - Zplm = cio_read(cio, 1); /* Zplm */ - len -= 3; - while (len > 0) { - Nplm = cio_read(cio, 4); /* Nplm */ - len -= 4; - for (i = Nplm; i > 0; i--) { - add = cio_read(cio, 1); - len--; - packet_len = (packet_len << 7) + add; /* Iplm_ij */ - if ((add & 0x80) == 0) { - /* New packet */ - packet_len = 0; - } - if (len <= 0) - break; - } - } -} - -static void j2k_read_plt(opj_j2k_t *j2k) { - int len, i, Zplt, packet_len = 0, add; - - opj_cio_t *cio = j2k->cio; - - len = cio_read(cio, 2); /* Lplt */ - Zplt = cio_read(cio, 1); /* Zplt */ - for (i = len - 3; i > 0; i--) { - add = cio_read(cio, 1); - packet_len = (packet_len << 7) + add; /* Iplt_i */ - if ((add & 0x80) == 0) { - /* New packet */ - packet_len = 0; - } - } -} - -static void j2k_read_ppm(opj_j2k_t *j2k) { - int len, Z_ppm, i, j; - int N_ppm; - - opj_cp_t *cp = j2k->cp; - opj_cio_t *cio = j2k->cio; - - len = cio_read(cio, 2); - cp->ppm = 1; - - Z_ppm = cio_read(cio, 1); /* Z_ppm */ - len -= 3; - while (len > 0) { - if (cp->ppm_previous == 0) { - N_ppm = cio_read(cio, 4); /* N_ppm */ - len -= 4; - } else { - N_ppm = cp->ppm_previous; - } - j = cp->ppm_store; - if (Z_ppm == 0) { /* First PPM marker */ - cp->ppm_data = (unsigned char *) opj_malloc(N_ppm * sizeof(unsigned char)); - cp->ppm_data_first = cp->ppm_data; - cp->ppm_len = N_ppm; - } else { /* NON-first PPM marker */ - cp->ppm_data = (unsigned char *) opj_realloc(cp->ppm_data, (N_ppm + cp->ppm_store) * sizeof(unsigned char)); - -#ifdef USE_JPWL - /* this memory allocation check could be done even in non-JPWL cases */ - if (cp->correct) { - if (!cp->ppm_data) { - opj_event_msg(j2k->cinfo, EVT_ERROR, - "JPWL: failed memory allocation during PPM marker parsing (pos. %x)\n", - cio_tell(cio)); - if (!JPWL_ASSUME || JPWL_ASSUME) { - opj_free(cp->ppm_data); - opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); - return; - } - } - } -#endif - - cp->ppm_data_first = cp->ppm_data; - cp->ppm_len = N_ppm + cp->ppm_store; - } - for (i = N_ppm; i > 0; i--) { /* Read packet header */ - cp->ppm_data[j] = cio_read(cio, 1); - j++; - len--; - if (len == 0) - break; /* Case of non-finished packet header in present marker but finished in next one */ - } - cp->ppm_previous = i - 1; - cp->ppm_store = j; - } -} - -static void j2k_read_ppt(opj_j2k_t *j2k) { - int len, Z_ppt, i, j = 0; - - opj_cp_t *cp = j2k->cp; - opj_tcp_t *tcp = cp->tcps + j2k->curtileno; - opj_cio_t *cio = j2k->cio; - - len = cio_read(cio, 2); - Z_ppt = cio_read(cio, 1); - tcp->ppt = 1; - if (Z_ppt == 0) { /* First PPT marker */ - tcp->ppt_data = (unsigned char *) opj_malloc((len - 3) * sizeof(unsigned char)); - tcp->ppt_data_first = tcp->ppt_data; - tcp->ppt_store = 0; - tcp->ppt_len = len - 3; - } else { /* NON-first PPT marker */ - tcp->ppt_data = (unsigned char *) opj_realloc(tcp->ppt_data, (len - 3 + tcp->ppt_store) * sizeof(unsigned char)); - tcp->ppt_data_first = tcp->ppt_data; - tcp->ppt_len = len - 3 + tcp->ppt_store; - } - j = tcp->ppt_store; - for (i = len - 3; i > 0; i--) { - tcp->ppt_data[j] = cio_read(cio, 1); - j++; - } - tcp->ppt_store = j; -} - -static void j2k_write_tlm(opj_j2k_t *j2k){ - int lenp; - opj_cio_t *cio = j2k->cio; - j2k->tlm_start = cio_tell(cio); - cio_write(cio, J2K_MS_TLM, 2);/* TLM */ - lenp = 4 + (5*j2k->totnum_tp); - cio_write(cio,lenp,2); /* Ltlm */ - cio_write(cio, 0,1); /* Ztlm=0*/ - cio_write(cio,80,1); /* Stlm ST=1(8bits-255 tiles max),SP=1(Ptlm=32bits) */ - cio_skip(cio,5*j2k->totnum_tp); -} - -static void j2k_write_sot(opj_j2k_t *j2k) { - int lenp, len; - - opj_cio_t *cio = j2k->cio; - - j2k->sot_start = cio_tell(cio); - cio_write(cio, J2K_MS_SOT, 2); /* SOT */ - lenp = cio_tell(cio); - cio_skip(cio, 2); /* Lsot (further) */ - cio_write(cio, j2k->curtileno, 2); /* Isot */ - cio_skip(cio, 4); /* Psot (further in j2k_write_sod) */ - cio_write(cio, j2k->cur_tp_num , 1); /* TPsot */ - cio_write(cio, j2k->cur_totnum_tp[j2k->curtileno], 1); /* TNsot */ - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Lsot */ - cio_seek(cio, lenp + len); - - /* UniPG>> */ -#ifdef USE_JPWL - /* update markers struct */ - j2k_add_marker(j2k->cstr_info, J2K_MS_SOT, j2k->sot_start, len + 2); -#endif /* USE_JPWL */ - /* <cstr_info && j2k->cur_tp_num==0){ - j2k_add_tlmarker( j2k->curtileno, j2k->cstr_info, J2K_MS_SOT, lenp, len); - } -} - -static void j2k_read_sot(opj_j2k_t *j2k) { - int len, tileno, totlen, partno, numparts, i; - opj_tcp_t *tcp = NULL; - char status = 0; - - opj_cp_t *cp = j2k->cp; - opj_cio_t *cio = j2k->cio; - - len = cio_read(cio, 2); - tileno = cio_read(cio, 2); - -#ifdef USE_JPWL - if (j2k->cp->correct) { - - static int backup_tileno = 0; - - /* tileno is negative or larger than the number of tiles!!! */ - if ((tileno < 0) || (tileno >= (cp->tw * cp->th))) { - opj_event_msg(j2k->cinfo, EVT_ERROR, - "JPWL: bad tile number (%d out of a maximum of %d)\n", - tileno, (cp->tw * cp->th)); - if (!JPWL_ASSUME) { - opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); - return; - } - /* we try to correct */ - tileno = backup_tileno; - opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n" - "- setting tile number to %d\n", - tileno); - } - - /* keep your private count of tiles */ - backup_tileno++; - } - else -#endif /* USE_JPWL */ - { - /* tileno is negative or larger than the number of tiles!!! */ - if ((tileno < 0) || (tileno >= (cp->tw * cp->th))) { - opj_event_msg(j2k->cinfo, EVT_ERROR, - "JPWL: bad tile number (%d out of a maximum of %d)\n", - tileno, (cp->tw * cp->th)); - return; - } - } - - if (cp->tileno_size == 0) { - cp->tileno[cp->tileno_size] = tileno; - cp->tileno_size++; - } else { - i = 0; - while (i < cp->tileno_size && status == 0) { - status = cp->tileno[i] == tileno ? 1 : 0; - i++; - } - if (status == 0) { - cp->tileno[cp->tileno_size] = tileno; - cp->tileno_size++; - } - } - - totlen = cio_read(cio, 4); - -#ifdef USE_JPWL - if (j2k->cp->correct) { - - /* totlen is negative or larger than the bytes left!!! */ - if ((totlen < 0) || (totlen > (cio_numbytesleft(cio) + 8))) { - opj_event_msg(j2k->cinfo, EVT_ERROR, - "JPWL: bad tile byte size (%d bytes against %d bytes left)\n", - totlen, cio_numbytesleft(cio) + 8); - if (!JPWL_ASSUME) { - opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); - return; - } - /* we try to correct */ - totlen = 0; - opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n" - "- setting Psot to %d => assuming it is the last tile\n", - totlen); - } - - } - else -#endif /* USE_JPWL */ - { - /* totlen is negative or larger than the bytes left!!! */ - if ((totlen < 0) || (totlen > (cio_numbytesleft(cio) + 8))) { - opj_event_msg(j2k->cinfo, EVT_ERROR, - "JPWL: bad tile byte size (%d bytes against %d bytes left)\n", - totlen, cio_numbytesleft(cio) + 8); - return; - } - } - - if (!totlen) - totlen = cio_numbytesleft(cio) + 8; - - partno = cio_read(cio, 1); - numparts = cio_read(cio, 1); - - if (partno >= numparts) { - opj_event_msg(j2k->cinfo, EVT_WARNING, "SOT marker inconsistency in tile %d: tile-part index greater (%d) than number of tile-parts (%d)\n", tileno, partno, numparts); - numparts = partno+1; - } - - j2k->curtileno = tileno; - j2k->cur_tp_num = partno; - j2k->eot = cio_getbp(cio) - 12 + totlen; - j2k->state = J2K_STATE_TPH; - tcp = &cp->tcps[j2k->curtileno]; - - /* Index */ - if (j2k->cstr_info) { - if (tcp->first) { - if (tileno == 0) - j2k->cstr_info->main_head_end = cio_tell(cio) - 13; - j2k->cstr_info->tile[tileno].tileno = tileno; - j2k->cstr_info->tile[tileno].start_pos = cio_tell(cio) - 12; - j2k->cstr_info->tile[tileno].end_pos = j2k->cstr_info->tile[tileno].start_pos + totlen - 1; - } else { - j2k->cstr_info->tile[tileno].end_pos += totlen; - } - j2k->cstr_info->tile[tileno].num_tps = numparts; - if (numparts) - j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_realloc(j2k->cstr_info->tile[tileno].tp, numparts * sizeof(opj_tp_info_t)); - else - j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_realloc(j2k->cstr_info->tile[tileno].tp, 10 * sizeof(opj_tp_info_t)); /* Fixme (10)*/ - j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos = cio_tell(cio) - 12; - j2k->cstr_info->tile[tileno].tp[partno].tp_end_pos = - j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos + totlen - 1; - } - - if (tcp->first == 1) { - /* Initialization PPT */ - opj_tccp_t *tmp = tcp->tccps; - memcpy(tcp, j2k->default_tcp, sizeof(opj_tcp_t)); - tcp->ppt = 0; - tcp->ppt_data = NULL; - tcp->ppt_data_first = NULL; - tcp->tccps = tmp; - - for (i = 0; i < j2k->image->numcomps; i++) { - tcp->tccps[i] = j2k->default_tcp->tccps[i]; - } - cp->tcps[j2k->curtileno].first = 0; - } -} - -static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder) { - int l, layno; - int totlen; - opj_tcp_t *tcp = NULL; - opj_codestream_info_t *cstr_info = NULL; - - opj_tcd_t *tcd = (opj_tcd_t*)tile_coder; /* cast is needed because of conflicts in header inclusions */ - opj_cp_t *cp = j2k->cp; - opj_cio_t *cio = j2k->cio; - - tcd->tp_num = j2k->tp_num ; - tcd->cur_tp_num = j2k->cur_tp_num; - - cio_write(cio, J2K_MS_SOD, 2); - - if( j2k->cstr_info && j2k->cur_tp_num==0){ - j2k_add_tlmarker( j2k->curtileno, j2k->cstr_info, J2K_MS_SOD, cio_tell(cio), 0); - } - - if (j2k->curtileno == 0) { - j2k->sod_start = cio_tell(cio) + j2k->pos_correction; - } - - /* INDEX >> */ - cstr_info = j2k->cstr_info; - if (cstr_info) { - if (!j2k->cur_tp_num ) { - cstr_info->tile[j2k->curtileno].end_header = cio_tell(cio) + j2k->pos_correction - 1; - j2k->cstr_info->tile[j2k->curtileno].tileno = j2k->curtileno; - } - else{ - if(cstr_info->tile[j2k->curtileno].packet[cstr_info->packno - 1].end_pos < cio_tell(cio)) - cstr_info->tile[j2k->curtileno].packet[cstr_info->packno].start_pos = cio_tell(cio); - } - /* UniPG>> */ -#ifdef USE_JPWL - /* update markers struct */ - j2k_add_marker(j2k->cstr_info, J2K_MS_SOD, j2k->sod_start, 2); -#endif /* USE_JPWL */ - /* <tcps[j2k->curtileno]; - for (layno = 0; layno < tcp->numlayers; layno++) { - if (tcp->rates[layno]>(j2k->sod_start / (cp->th * cp->tw))) { - tcp->rates[layno]-=(j2k->sod_start / (cp->th * cp->tw)); - } else if (tcp->rates[layno]) { - tcp->rates[layno]=1; - } - } - if(j2k->cur_tp_num == 0){ - tcd->tcd_image->tiles->packno = 0; - if(cstr_info) - cstr_info->packno = 0; - } - - l = tcd_encode_tile(tcd, j2k->curtileno, cio_getbp(cio), cio_numbytesleft(cio) - 2, cstr_info); - - /* Writing Psot in SOT marker */ - totlen = cio_tell(cio) + l - j2k->sot_start; - cio_seek(cio, j2k->sot_start + 6); - cio_write(cio, totlen, 4); - cio_seek(cio, j2k->sot_start + totlen); - /* Writing Ttlm and Ptlm in TLM marker */ - if(cp->cinema){ - cio_seek(cio, j2k->tlm_start + 6 + (5*j2k->cur_tp_num)); - cio_write(cio, j2k->curtileno, 1); - cio_write(cio, totlen, 4); - } - cio_seek(cio, j2k->sot_start + totlen); -} - -static void j2k_read_sod(opj_j2k_t *j2k) { - int len, truncate = 0, i; - unsigned char *data = NULL, *data_ptr = NULL; - - opj_cio_t *cio = j2k->cio; - int curtileno = j2k->curtileno; - - /* Index */ - if (j2k->cstr_info) { - j2k->cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_end_header = - cio_tell(cio) + j2k->pos_correction - 1; - if (j2k->cur_tp_num == 0) - j2k->cstr_info->tile[j2k->curtileno].end_header = cio_tell(cio) + j2k->pos_correction - 1; - j2k->cstr_info->packno = 0; - } - - len = int_min(j2k->eot - cio_getbp(cio), cio_numbytesleft(cio) + 1); - - if (len == cio_numbytesleft(cio) + 1) { - truncate = 1; /* Case of a truncate codestream */ - } - - {/* chop padding bytes: */ - unsigned char *s, *e; - - s = cio_getbp(cio); - e = s + len; - - if(len > 8) s = e - 8; - - if(e[-2] == 0x00 && e[-1] == 0x00) /* padding bytes */ - { - while(e > s) - { - if(e[-2] == 0xff && e[-1] == 0xd9) break; - --len; --e; truncate = 1; - } - } - } - - data = j2k->tile_data[curtileno]; - data = (unsigned char*) opj_realloc(data, (j2k->tile_len[curtileno] + len) * sizeof(unsigned char)); - - data_ptr = data + j2k->tile_len[curtileno]; - for (i = 0; i < len; i++) { - data_ptr[i] = cio_read(cio, 1); - } - - j2k->tile_len[curtileno] += len; - j2k->tile_data[curtileno] = data; - - if (!truncate) { - j2k->state = J2K_STATE_TPHSOT; - } else { - j2k->state = J2K_STATE_NEOC; /* RAJOUTE !! */ - } - j2k->cur_tp_num++; -} - -static void j2k_write_rgn(opj_j2k_t *j2k, int compno, int tileno) { - opj_cp_t *cp = j2k->cp; - opj_tcp_t *tcp = &cp->tcps[tileno]; - opj_cio_t *cio = j2k->cio; - int numcomps = j2k->image->numcomps; - - cio_write(cio, J2K_MS_RGN, 2); /* RGN */ - cio_write(cio, numcomps <= 256 ? 5 : 6, 2); /* Lrgn */ - cio_write(cio, compno, numcomps <= 256 ? 1 : 2); /* Crgn */ - cio_write(cio, 0, 1); /* Srgn */ - cio_write(cio, tcp->tccps[compno].roishift, 1); /* SPrgn */ -} - -static void j2k_read_rgn(opj_j2k_t *j2k) { - int len, compno, roisty; - - opj_cp_t *cp = j2k->cp; - opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp; - opj_cio_t *cio = j2k->cio; - int numcomps = j2k->image->numcomps; - - len = cio_read(cio, 2); /* Lrgn */ - compno = cio_read(cio, numcomps <= 256 ? 1 : 2); /* Crgn */ - roisty = cio_read(cio, 1); /* Srgn */ - -#ifdef USE_JPWL - if (j2k->cp->correct) { - /* totlen is negative or larger than the bytes left!!! */ - if (compno >= numcomps) { - opj_event_msg(j2k->cinfo, EVT_ERROR, - "JPWL: bad component number in RGN (%d when there are only %d)\n", - compno, numcomps); - if (!JPWL_ASSUME || JPWL_ASSUME) { - opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); - return; - } - } - }; -#endif /* USE_JPWL */ - - tcp->tccps[compno].roishift = cio_read(cio, 1); /* SPrgn */ -} - -static void j2k_write_eoc(opj_j2k_t *j2k) { - opj_cio_t *cio = j2k->cio; - /* opj_event_msg(j2k->cinfo, "%.8x: EOC\n", cio_tell(cio) + j2k->pos_correction); */ - cio_write(cio, J2K_MS_EOC, 2); - -/* UniPG>> */ -#ifdef USE_JPWL - /* update markers struct */ - j2k_add_marker(j2k->cstr_info, J2K_MS_EOC, cio_tell(cio) - 2, 2); -#endif /* USE_JPWL */ -/* <cp->limit_decoding != DECODE_ALL_BUT_PACKETS) { - opj_tcd_t *tcd = tcd_create(j2k->cinfo); - tcd_malloc_decode(tcd, j2k->image, j2k->cp); - for (i = 0; i < j2k->cp->tileno_size; i++) { - tcd_malloc_decode_tile(tcd, j2k->image, j2k->cp, i, j2k->cstr_info); - if (j2k->cp->tileno[i] != -1) - { - tileno = j2k->cp->tileno[i]; - success = tcd_decode_tile(tcd, j2k->tile_data[tileno], j2k->tile_len[tileno], tileno, j2k->cstr_info); - opj_free(j2k->tile_data[tileno]); - j2k->tile_data[tileno] = NULL; - tcd_free_decode_tile(tcd, i); - } - else - success = OPJ_FALSE; - if (success == OPJ_FALSE) { - j2k->state |= J2K_STATE_ERR; - break; - } - } - tcd_free_decode(tcd); - tcd_destroy(tcd); - } - /* if packets should not be decoded */ - else { - for (i = 0; i < j2k->cp->tileno_size; i++) { - tileno = j2k->cp->tileno[i]; - opj_free(j2k->tile_data[tileno]); - j2k->tile_data[tileno] = NULL; - } - } - if (j2k->state & J2K_STATE_ERR) - j2k->state = J2K_STATE_MT + J2K_STATE_ERR; - else - j2k->state = J2K_STATE_MT; -} - -typedef struct opj_dec_mstabent { - /** marker value */ - int id; - /** value of the state when the marker can appear */ - int states; - /** action linked to the marker */ - void (*handler) (opj_j2k_t *j2k); -} opj_dec_mstabent_t; - -opj_dec_mstabent_t j2k_dec_mstab[] = { - {J2K_MS_SOC, J2K_STATE_MHSOC, j2k_read_soc}, - {J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, j2k_read_sot}, - {J2K_MS_SOD, J2K_STATE_TPH, j2k_read_sod}, - {J2K_MS_EOC, J2K_STATE_TPHSOT, j2k_read_eoc}, - {J2K_MS_SIZ, J2K_STATE_MHSIZ, j2k_read_siz}, - {J2K_MS_COD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_cod}, - {J2K_MS_COC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_coc}, - {J2K_MS_RGN, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_rgn}, - {J2K_MS_QCD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_qcd}, - {J2K_MS_QCC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_qcc}, - {J2K_MS_POC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_poc}, - {J2K_MS_TLM, J2K_STATE_MH, j2k_read_tlm}, - {J2K_MS_PLM, J2K_STATE_MH, j2k_read_plm}, - {J2K_MS_PLT, J2K_STATE_TPH, j2k_read_plt}, - {J2K_MS_PPM, J2K_STATE_MH, j2k_read_ppm}, - {J2K_MS_PPT, J2K_STATE_TPH, j2k_read_ppt}, - {J2K_MS_SOP, 0, 0}, - {J2K_MS_CRG, J2K_STATE_MH, j2k_read_crg}, - {J2K_MS_COM, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_com}, - -#ifdef USE_JPWL - {J2K_MS_EPC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_epc}, - {J2K_MS_EPB, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_epb}, - {J2K_MS_ESD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_esd}, - {J2K_MS_RED, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_red}, -#endif /* USE_JPWL */ -#ifdef USE_JPSEC - {J2K_MS_SEC, J2K_STATE_MH, j2k_read_sec}, - {J2K_MS_INSEC, 0, j2k_read_insec}, -#endif /* USE_JPSEC */ - - {0, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_unk} -}; - -static void j2k_read_unk(opj_j2k_t *j2k) { - opj_event_msg(j2k->cinfo, EVT_WARNING, "Unknown marker\n"); - -#ifdef USE_JPWL - if (j2k->cp->correct) { - int m = 0, id, i; - int min_id = 0, min_dist = 17, cur_dist = 0, tmp_id; - cio_seek(j2k->cio, cio_tell(j2k->cio) - 2); - id = cio_read(j2k->cio, 2); - opj_event_msg(j2k->cinfo, EVT_ERROR, - "JPWL: really don't know this marker %x\n", - id); - if (!JPWL_ASSUME) { - opj_event_msg(j2k->cinfo, EVT_ERROR, - "- possible synch loss due to uncorrectable codestream errors => giving up\n"); - return; - } - /* OK, activate this at your own risk!!! */ - /* we look for the marker at the minimum hamming distance from this */ - while (j2k_dec_mstab[m].id) { - - /* 1's where they differ */ - tmp_id = j2k_dec_mstab[m].id ^ id; - - /* compute the hamming distance between our id and the current */ - cur_dist = 0; - for (i = 0; i < 16; i++) { - if ((tmp_id >> i) & 0x0001) { - cur_dist++; - } - } - - /* if current distance is smaller, set the minimum */ - if (cur_dist < min_dist) { - min_dist = cur_dist; - min_id = j2k_dec_mstab[m].id; - } - - /* jump to the next marker */ - m++; - } - - /* do we substitute the marker? */ - if (min_dist < JPWL_MAXIMUM_HAMMING) { - opj_event_msg(j2k->cinfo, EVT_ERROR, - "- marker %x is at distance %d from the read %x\n", - min_id, min_dist, id); - opj_event_msg(j2k->cinfo, EVT_ERROR, - "- trying to substitute in place and crossing fingers!\n"); - cio_seek(j2k->cio, cio_tell(j2k->cio) - 2); - cio_write(j2k->cio, min_id, 2); - - /* rewind */ - cio_seek(j2k->cio, cio_tell(j2k->cio) - 2); - - } - - }; -#endif /* USE_JPWL */ - -} - -/** -Read the lookup table containing all the marker, status and action -@param id Marker value -*/ -static opj_dec_mstabent_t *j2k_dec_mstab_lookup(int id) { - opj_dec_mstabent_t *e; - for (e = j2k_dec_mstab; e->id != 0; e++) { - if (e->id == id) { - break; - } - } - return e; -} - -/* ----------------------------------------------------------------------- */ -/* J2K / JPT decoder interface */ -/* ----------------------------------------------------------------------- */ - -opj_j2k_t* j2k_create_decompress(opj_common_ptr cinfo) { - opj_j2k_t *j2k = (opj_j2k_t*) opj_calloc(1, sizeof(opj_j2k_t)); - if(!j2k) - return NULL; - - j2k->default_tcp = (opj_tcp_t*) opj_calloc(1, sizeof(opj_tcp_t)); - if(!j2k->default_tcp) { - opj_free(j2k); - return NULL; - } - - j2k->cinfo = cinfo; - j2k->tile_data = NULL; - - return j2k; -} - -void j2k_destroy_decompress(opj_j2k_t *j2k) { - int i = 0; - - if(j2k->tile_len != NULL) { - opj_free(j2k->tile_len); - } - if(j2k->tile_data != NULL) { - if(j2k->cp != NULL) { - for (i = 0; i < j2k->cp->tileno_size; i++) { - int tileno = j2k->cp->tileno[i]; - opj_free(j2k->tile_data[tileno]); - j2k->tile_data[tileno] = NULL; - } - } - - opj_free(j2k->tile_data); - } - if(j2k->default_tcp != NULL) { - opj_tcp_t *default_tcp = j2k->default_tcp; - if(default_tcp->ppt_data_first != NULL) { - opj_free(default_tcp->ppt_data_first); - } - if(j2k->default_tcp->tccps != NULL) { - opj_free(j2k->default_tcp->tccps); - } - opj_free(j2k->default_tcp); - } - if(j2k->cp != NULL) { - opj_cp_t *cp = j2k->cp; - if(cp->tcps != NULL) { - for(i = 0; i < cp->tw * cp->th; i++) { - if(cp->tcps[i].ppt_data_first != NULL) { - opj_free(cp->tcps[i].ppt_data_first); - } - if(cp->tcps[i].tccps != NULL) { - opj_free(cp->tcps[i].tccps); - } - } - opj_free(cp->tcps); - } - if(cp->ppm_data_first != NULL) { - opj_free(cp->ppm_data_first); - } - if(cp->tileno != NULL) { - opj_free(cp->tileno); - } - if(cp->comment != NULL) { - opj_free(cp->comment); - } - - opj_free(cp); - } - opj_free(j2k); -} - -void j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters) { - if(j2k && parameters) { - /* create and initialize the coding parameters structure */ - opj_cp_t *cp = (opj_cp_t*) opj_calloc(1, sizeof(opj_cp_t)); - cp->reduce = parameters->cp_reduce; - cp->layer = parameters->cp_layer; - cp->limit_decoding = parameters->cp_limit_decoding; - -#ifdef USE_JPWL - cp->correct = parameters->jpwl_correct; - cp->exp_comps = parameters->jpwl_exp_comps; - cp->max_tiles = parameters->jpwl_max_tiles; -#endif /* USE_JPWL */ - - - /* keep a link to cp so that we can destroy it later in j2k_destroy_decompress */ - j2k->cp = cp; - } -} - -opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info) { - opj_image_t *image = NULL; - - opj_common_ptr cinfo = j2k->cinfo; - - j2k->cio = cio; - j2k->cstr_info = cstr_info; - if (cstr_info) - memset(cstr_info, 0, sizeof(opj_codestream_info_t)); - - /* create an empty image */ - image = opj_image_create0(); - j2k->image = image; - - j2k->state = J2K_STATE_MHSOC; - - for (;;) { - opj_dec_mstabent_t *e; - int id = cio_read(cio, 2); - -#ifdef USE_JPWL - /* we try to honor JPWL correction power */ - if (j2k->cp->correct) { - - int orig_pos = cio_tell(cio); - opj_bool status; - - /* call the corrector */ - status = jpwl_correct(j2k); - - /* go back to where you were */ - cio_seek(cio, orig_pos - 2); - - /* re-read the marker */ - id = cio_read(cio, 2); - - /* check whether it begins with ff */ - if (id >> 8 != 0xff) { - opj_event_msg(cinfo, EVT_ERROR, - "JPWL: possible bad marker %x at %d\n", - id, cio_tell(cio) - 2); - if (!JPWL_ASSUME) { - opj_image_destroy(image); - opj_event_msg(cinfo, EVT_ERROR, "JPWL: giving up\n"); - return 0; - } - /* we try to correct */ - id = id | 0xff00; - cio_seek(cio, cio_tell(cio) - 2); - cio_write(cio, id, 2); - opj_event_msg(cinfo, EVT_WARNING, "- trying to adjust this\n" - "- setting marker to %x\n", - id); - } - - } -#endif /* USE_JPWL */ - - if (id >> 8 != 0xff) { - if(cio_numbytesleft(cio) != 0) /* not end of file reached and no EOC */ - { - opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id); - opj_image_destroy(image); - return 0; - } - opj_event_msg(cinfo, EVT_WARNING, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id); - j2k->state = J2K_STATE_NEOC; - break; - } - e = j2k_dec_mstab_lookup(id); - /* Check if the marker is known*/ - if (!(j2k->state & e->states)) { - opj_image_destroy(image); - opj_event_msg(cinfo, EVT_ERROR, "%.8x: unexpected marker %x\n", cio_tell(cio) - 2, id); - return 0; - } - /* Check if the decoding is limited to the main header*/ - if (e->id == J2K_MS_SOT && j2k->cp->limit_decoding == LIMIT_TO_MAIN_HEADER) { - opj_event_msg(cinfo, EVT_INFO, "Main Header decoded.\n"); - return image; - } - - if (e->handler) { - (*e->handler)(j2k); - } - if (j2k->state & J2K_STATE_ERR) - { - opj_image_destroy(image); - return NULL; - } - - if (j2k->state == J2K_STATE_MT) { - break; - } - if (j2k->state == J2K_STATE_NEOC) { - break; - } - } - if (j2k->state == J2K_STATE_NEOC) { - j2k_read_eoc(j2k); - } - - if (j2k->state != J2K_STATE_MT) { - opj_event_msg(cinfo, EVT_WARNING, "Incomplete bitstream\n"); - } - return image; -} - -/* -* Read a JPT-stream and decode file -* -*/ -opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info) { - opj_image_t *image = NULL; - opj_jpt_msg_header_t header; - int position; - opj_common_ptr cinfo = j2k->cinfo; - - OPJ_ARG_NOT_USED(cstr_info); - - j2k->cio = cio; - - /* create an empty image */ - image = opj_image_create0(); - j2k->image = image; - - j2k->state = J2K_STATE_MHSOC; - - /* Initialize the header */ - jpt_init_msg_header(&header); - /* Read the first header of the message */ - jpt_read_msg_header(cinfo, cio, &header); - - position = cio_tell(cio); - if (header.Class_Id != 6) { /* 6 : Main header data-bin message */ - opj_image_destroy(image); - opj_event_msg(cinfo, EVT_ERROR, "[JPT-stream] : Expecting Main header first [class_Id %d] !\n", header.Class_Id); - return 0; - } - - for (;;) { - opj_dec_mstabent_t *e = NULL; - int id; - - if (!cio_numbytesleft(cio)) { - j2k_read_eoc(j2k); - return image; - } - /* data-bin read -> need to read a new header */ - if ((unsigned int) (cio_tell(cio) - position) == header.Msg_length) { - jpt_read_msg_header(cinfo, cio, &header); - position = cio_tell(cio); - if (header.Class_Id != 4) { /* 4 : Tile data-bin message */ - opj_image_destroy(image); - opj_event_msg(cinfo, EVT_ERROR, "[JPT-stream] : Expecting Tile info !\n"); - return 0; - } - } - - id = cio_read(cio, 2); - if (id >> 8 != 0xff) { - if(cio_numbytesleft(cio) != 0) /* no end of file reached and no EOC */ - { - opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id); - opj_image_destroy(image); - return 0; - } - opj_event_msg(cinfo, EVT_WARNING, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id); - j2k->state = J2K_STATE_NEOC; - break; - } - e = j2k_dec_mstab_lookup(id); - if (!(j2k->state & e->states)) { - opj_image_destroy(image); - opj_event_msg(cinfo, EVT_ERROR, "%.8x: unexpected marker %x\n", cio_tell(cio) - 2, id); - return 0; - } - if (e->handler) { - (*e->handler)(j2k); - } - if (j2k->state == J2K_STATE_MT) { - break; - } - if (j2k->state == J2K_STATE_NEOC) { - break; - } - } - if (j2k->state == J2K_STATE_NEOC) { - j2k_read_eoc(j2k); - } - - if (j2k->state != J2K_STATE_MT) { - opj_event_msg(cinfo, EVT_WARNING, "Incomplete bitstream\n"); - } - - return image; -} - -/* ----------------------------------------------------------------------- */ -/* J2K encoder interface */ -/* ----------------------------------------------------------------------- */ - -opj_j2k_t* j2k_create_compress(opj_common_ptr cinfo) { - opj_j2k_t *j2k = (opj_j2k_t*) opj_calloc(1, sizeof(opj_j2k_t)); - if(j2k) { - j2k->cinfo = cinfo; - } - return j2k; -} - -void j2k_destroy_compress(opj_j2k_t *j2k) { - int tileno; - - if(!j2k) return; - if(j2k->cp != NULL) { - opj_cp_t *cp = j2k->cp; - - if(cp->comment) { - opj_free(cp->comment); - } - if(cp->matrice) { - opj_free(cp->matrice); - } - for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { - opj_free(cp->tcps[tileno].tccps); - } - opj_free(cp->tcps); - opj_free(cp); - } - - opj_free(j2k); -} - -void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_t *image) { - int i, j, tileno, numpocs_tile; - opj_cp_t *cp = NULL; - - if(!j2k || !parameters || ! image) { - return; - } - - /* create and initialize the coding parameters structure */ - cp = (opj_cp_t*) opj_calloc(1, sizeof(opj_cp_t)); - - /* keep a link to cp so that we can destroy it later in j2k_destroy_compress */ - j2k->cp = cp; - - /* set default values for cp */ - cp->tw = 1; - cp->th = 1; - - /* - copy user encoding parameters - */ - cp->cinema = parameters->cp_cinema; - cp->max_comp_size = parameters->max_comp_size; - cp->rsiz = parameters->cp_rsiz; - cp->disto_alloc = parameters->cp_disto_alloc; - cp->fixed_alloc = parameters->cp_fixed_alloc; - cp->fixed_quality = parameters->cp_fixed_quality; - - /* mod fixed_quality */ - if(parameters->cp_matrice) { - size_t array_size = parameters->tcp_numlayers * parameters->numresolution * 3 * sizeof(int); - cp->matrice = (int *) opj_malloc(array_size); - memcpy(cp->matrice, parameters->cp_matrice, array_size); - } - - /* tiles */ - cp->tdx = parameters->cp_tdx; - cp->tdy = parameters->cp_tdy; - - /* tile offset */ - cp->tx0 = parameters->cp_tx0; - cp->ty0 = parameters->cp_ty0; - - /* comment string */ - if(parameters->cp_comment) { - cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1); - if(cp->comment) { - strcpy(cp->comment, parameters->cp_comment); - } - } - - /* - calculate other encoding parameters - */ - - if (parameters->tile_size_on) { - cp->tw = int_ceildiv(image->x1 - cp->tx0, cp->tdx); - cp->th = int_ceildiv(image->y1 - cp->ty0, cp->tdy); - } else { - cp->tdx = image->x1 - cp->tx0; - cp->tdy = image->y1 - cp->ty0; - } - - if(parameters->tp_on){ - cp->tp_flag = parameters->tp_flag; - cp->tp_on = 1; - } - - cp->img_size = 0; - for(i=0;inumcomps ;i++){ - cp->img_size += (image->comps[i].w *image->comps[i].h * image->comps[i].prec); - } - - -#ifdef USE_JPWL - /* - calculate JPWL encoding parameters - */ - - if (parameters->jpwl_epc_on) { - int i; - - /* set JPWL on */ - cp->epc_on = OPJ_TRUE; - cp->info_on = OPJ_FALSE; /* no informative technique */ - - /* set EPB on */ - if ((parameters->jpwl_hprot_MH > 0) || (parameters->jpwl_hprot_TPH[0] > 0)) { - cp->epb_on = OPJ_TRUE; - - cp->hprot_MH = parameters->jpwl_hprot_MH; - for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) { - cp->hprot_TPH_tileno[i] = parameters->jpwl_hprot_TPH_tileno[i]; - cp->hprot_TPH[i] = parameters->jpwl_hprot_TPH[i]; - } - /* if tile specs are not specified, copy MH specs */ - if (cp->hprot_TPH[0] == -1) { - cp->hprot_TPH_tileno[0] = 0; - cp->hprot_TPH[0] = parameters->jpwl_hprot_MH; - } - for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) { - cp->pprot_tileno[i] = parameters->jpwl_pprot_tileno[i]; - cp->pprot_packno[i] = parameters->jpwl_pprot_packno[i]; - cp->pprot[i] = parameters->jpwl_pprot[i]; - } - } - - /* set ESD writing */ - if ((parameters->jpwl_sens_size == 1) || (parameters->jpwl_sens_size == 2)) { - cp->esd_on = OPJ_TRUE; - - cp->sens_size = parameters->jpwl_sens_size; - cp->sens_addr = parameters->jpwl_sens_addr; - cp->sens_range = parameters->jpwl_sens_range; - - cp->sens_MH = parameters->jpwl_sens_MH; - for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) { - cp->sens_TPH_tileno[i] = parameters->jpwl_sens_TPH_tileno[i]; - cp->sens_TPH[i] = parameters->jpwl_sens_TPH[i]; - } - } - - /* always set RED writing to false: we are at the encoder */ - cp->red_on = OPJ_FALSE; - - } else { - cp->epc_on = OPJ_FALSE; - } -#endif /* USE_JPWL */ - - - /* initialize the mutiple tiles */ - /* ---------------------------- */ - cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t)); - - for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { - opj_tcp_t *tcp = &cp->tcps[tileno]; - tcp->numlayers = parameters->tcp_numlayers; - for (j = 0; j < tcp->numlayers; j++) { - if(cp->cinema){ - if (cp->fixed_quality) { - tcp->distoratio[j] = parameters->tcp_distoratio[j]; - } - tcp->rates[j] = parameters->tcp_rates[j]; - }else{ - if (cp->fixed_quality) { /* add fixed_quality */ - tcp->distoratio[j] = parameters->tcp_distoratio[j]; - } else { - tcp->rates[j] = parameters->tcp_rates[j]; - } - } - } - tcp->csty = parameters->csty; - tcp->prg = parameters->prog_order; - tcp->mct = parameters->tcp_mct; - - numpocs_tile = 0; - tcp->POC = 0; - if (parameters->numpocs) { - /* initialisation of POC */ - tcp->POC = 1; - for (i = 0; i < parameters->numpocs; i++) { - if((tileno == parameters->POC[i].tile - 1) || (parameters->POC[i].tile == -1)) { - opj_poc_t *tcp_poc = &tcp->pocs[numpocs_tile]; - tcp_poc->resno0 = parameters->POC[numpocs_tile].resno0; - tcp_poc->compno0 = parameters->POC[numpocs_tile].compno0; - tcp_poc->layno1 = parameters->POC[numpocs_tile].layno1; - tcp_poc->resno1 = parameters->POC[numpocs_tile].resno1; - tcp_poc->compno1 = parameters->POC[numpocs_tile].compno1; - tcp_poc->prg1 = parameters->POC[numpocs_tile].prg1; - tcp_poc->tile = parameters->POC[numpocs_tile].tile; - numpocs_tile++; - } - } - tcp->numpocs = numpocs_tile -1 ; - }else{ - tcp->numpocs = 0; - } - - tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t)); - - for (i = 0; i < image->numcomps; i++) { - opj_tccp_t *tccp = &tcp->tccps[i]; - tccp->csty = parameters->csty & 0x01; /* 0 => one precinct || 1 => custom precinct */ - tccp->numresolutions = parameters->numresolution; - tccp->cblkw = int_floorlog2(parameters->cblockw_init); - tccp->cblkh = int_floorlog2(parameters->cblockh_init); - tccp->cblksty = parameters->mode; - tccp->qmfbid = parameters->irreversible ? 0 : 1; - tccp->qntsty = parameters->irreversible ? J2K_CCP_QNTSTY_SEQNT : J2K_CCP_QNTSTY_NOQNT; - tccp->numgbits = 2; - if (i == parameters->roi_compno) { - tccp->roishift = parameters->roi_shift; - } else { - tccp->roishift = 0; - } - - if(parameters->cp_cinema) - { - /*Precinct size for lowest frequency subband=128*/ - tccp->prcw[0] = 7; - tccp->prch[0] = 7; - /*Precinct size at all other resolutions = 256*/ - for (j = 1; j < tccp->numresolutions; j++) { - tccp->prcw[j] = 8; - tccp->prch[j] = 8; - } - }else{ - if (parameters->csty & J2K_CCP_CSTY_PRT) { - int p = 0; - for (j = tccp->numresolutions - 1; j >= 0; j--) { - if (p < parameters->res_spec) { - - if (parameters->prcw_init[p] < 1) { - tccp->prcw[j] = 1; - } else { - tccp->prcw[j] = int_floorlog2(parameters->prcw_init[p]); - } - - if (parameters->prch_init[p] < 1) { - tccp->prch[j] = 1; - }else { - tccp->prch[j] = int_floorlog2(parameters->prch_init[p]); - } - - } else { - int res_spec = parameters->res_spec; - int size_prcw = parameters->prcw_init[res_spec - 1] >> (p - (res_spec - 1)); - int size_prch = parameters->prch_init[res_spec - 1] >> (p - (res_spec - 1)); - - if (size_prcw < 1) { - tccp->prcw[j] = 1; - } else { - tccp->prcw[j] = int_floorlog2(size_prcw); - } - - if (size_prch < 1) { - tccp->prch[j] = 1; - } else { - tccp->prch[j] = int_floorlog2(size_prch); - } - } - p++; - /*printf("\nsize precinct for level %d : %d,%d\n", j,tccp->prcw[j], tccp->prch[j]); */ - } /*end for*/ - } else { - for (j = 0; j < tccp->numresolutions; j++) { - tccp->prcw[j] = 15; - tccp->prch[j] = 15; - } - } - } - - dwt_calc_explicit_stepsizes(tccp, image->comps[i].prec); - } - } -} - -opj_bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) { - int tileno, compno; - opj_cp_t *cp = NULL; - - opj_tcd_t *tcd = NULL; /* TCD component */ - - j2k->cio = cio; - j2k->image = image; - - cp = j2k->cp; - - /* INDEX >> */ - j2k->cstr_info = cstr_info; - if (cstr_info) { - int compno; - cstr_info->tile = (opj_tile_info_t *) opj_malloc(cp->tw * cp->th * sizeof(opj_tile_info_t)); - cstr_info->image_w = image->x1 - image->x0; - cstr_info->image_h = image->y1 - image->y0; - cstr_info->prog = (&cp->tcps[0])->prg; - cstr_info->tw = cp->tw; - cstr_info->th = cp->th; - cstr_info->tile_x = cp->tdx; /* new version parser */ - cstr_info->tile_y = cp->tdy; /* new version parser */ - cstr_info->tile_Ox = cp->tx0; /* new version parser */ - cstr_info->tile_Oy = cp->ty0; /* new version parser */ - cstr_info->numcomps = image->numcomps; - cstr_info->numlayers = (&cp->tcps[0])->numlayers; - cstr_info->numdecompos = (int*) opj_malloc(image->numcomps * sizeof(int)); - for (compno=0; compno < image->numcomps; compno++) { - cstr_info->numdecompos[compno] = (&cp->tcps[0])->tccps->numresolutions - 1; - } - cstr_info->D_max = 0.0; /* ADD Marcela */ - cstr_info->main_head_start = cio_tell(cio); /* position of SOC */ - cstr_info->maxmarknum = 100; - cstr_info->marker = (opj_marker_info_t *) opj_malloc(cstr_info->maxmarknum * sizeof(opj_marker_info_t)); - cstr_info->marknum = 0; - } - /* << INDEX */ - - j2k_write_soc(j2k); - j2k_write_siz(j2k); - j2k_write_cod(j2k); - j2k_write_qcd(j2k); - - if(cp->cinema){ - for (compno = 1; compno < image->numcomps; compno++) { - j2k_write_coc(j2k, compno); - j2k_write_qcc(j2k, compno); - } - } - - for (compno = 0; compno < image->numcomps; compno++) { - opj_tcp_t *tcp = &cp->tcps[0]; - if (tcp->tccps[compno].roishift) - j2k_write_rgn(j2k, compno, 0); - } - if (cp->comment != NULL) { - j2k_write_com(j2k); - } - - j2k->totnum_tp = j2k_calculate_tp(cp,image->numcomps,image,j2k); - /* TLM Marker*/ - if(cp->cinema){ - j2k_write_tlm(j2k); - if (cp->cinema == CINEMA4K_24) { - j2k_write_poc(j2k); - } - } - - /* uncomment only for testing JPSEC marker writing */ - /* j2k_write_sec(j2k); */ - - /* INDEX >> */ - if(cstr_info) { - cstr_info->main_head_end = cio_tell(cio) - 1; - } - /* << INDEX */ - /**** Main Header ENDS here ***/ - - /* create the tile encoder */ - tcd = tcd_create(j2k->cinfo); - - /* encode each tile */ - for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { - int pino; - int tilepartno=0; - /* UniPG>> */ - int acc_pack_num = 0; - /* <tcps[tileno]; - opj_event_msg(j2k->cinfo, EVT_INFO, "tile number %d / %d\n", tileno + 1, cp->tw * cp->th); - - j2k->curtileno = tileno; - j2k->cur_tp_num = 0; - tcd->cur_totnum_tp = j2k->cur_totnum_tp[j2k->curtileno]; - /* initialisation before tile encoding */ - if (tileno == 0) { - tcd_malloc_encode(tcd, image, cp, j2k->curtileno); - } else { - tcd_init_encode(tcd, image, cp, j2k->curtileno); - } - - /* INDEX >> */ - if(cstr_info) { - cstr_info->tile[j2k->curtileno].start_pos = cio_tell(cio) + j2k->pos_correction; - cstr_info->tile[j2k->curtileno].maxmarknum = 10; - cstr_info->tile[j2k->curtileno].marker = (opj_marker_info_t *) opj_malloc(cstr_info->tile[j2k->curtileno].maxmarknum * sizeof(opj_marker_info_t)); - cstr_info->tile[j2k->curtileno].marknum = 0; - } - /* << INDEX */ - - for(pino = 0; pino <= tcp->numpocs; pino++) { - int tot_num_tp; - tcd->cur_pino=pino; - - /*Get number of tile parts*/ - tot_num_tp = j2k_get_num_tp(cp,pino,tileno); - tcd->tp_pos = cp->tp_pos; - - for(tilepartno = 0; tilepartno < tot_num_tp ; tilepartno++){ - j2k->tp_num = tilepartno; - /* INDEX >> */ - if(cstr_info) - cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_start_pos = - cio_tell(cio) + j2k->pos_correction; - /* << INDEX */ - j2k_write_sot(j2k); - - if(j2k->cur_tp_num == 0 && cp->cinema == 0){ - for (compno = 1; compno < image->numcomps; compno++) { - j2k_write_coc(j2k, compno); - j2k_write_qcc(j2k, compno); - } - if (cp->tcps[tileno].numpocs) { - j2k_write_poc(j2k); - } - } - - /* INDEX >> */ - if(cstr_info) - cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_end_header = - cio_tell(cio) + j2k->pos_correction + 1; - /* << INDEX */ - - j2k_write_sod(j2k, tcd); - - /* INDEX >> */ - if(cstr_info) { - cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_end_pos = - cio_tell(cio) + j2k->pos_correction - 1; - cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_start_pack = - acc_pack_num; - cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_numpacks = - cstr_info->packno - acc_pack_num; - acc_pack_num = cstr_info->packno; - } - /* << INDEX */ - - j2k->cur_tp_num++; - } - } - if(cstr_info) { - cstr_info->tile[j2k->curtileno].end_pos = cio_tell(cio) + j2k->pos_correction - 1; - } - - - /* - if (tile->PPT) { // BAD PPT !!! - FILE *PPT_file; - int i; - PPT_file=fopen("PPT","rb"); - fprintf(stderr,"%c%c%c%c",255,97,tile->len_ppt/256,tile->len_ppt%256); - for (i=0;ilen_ppt;i++) { - unsigned char elmt; - fread(&elmt, 1, 1, PPT_file); - fwrite(&elmt,1,1,f); - } - fclose(PPT_file); - unlink("PPT"); - } - */ - - } - - /* destroy the tile encoder */ - tcd_free_encode(tcd); - tcd_destroy(tcd); - - opj_free(j2k->cur_totnum_tp); - - j2k_write_eoc(j2k); - - if(cstr_info) { - cstr_info->codestream_size = cio_tell(cio) + j2k->pos_correction; - /* UniPG>> */ - /* The following adjustment is done to adjust the codestream size */ - /* if SOD is not at 0 in the buffer. Useful in case of JP2, where */ - /* the first bunch of bytes is not in the codestream */ - cstr_info->codestream_size -= cstr_info->main_head_start; - /* <epc_on) { - - /* encode according to JPWL */ - jpwl_encode(j2k, cio, image); - - } -#endif /* USE_JPWL */ - - return OPJ_TRUE; -} - -static void j2k_add_mhmarker(opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len) { - - if (!cstr_info) - return; - - /* expand the list? */ - if ((cstr_info->marknum + 1) > cstr_info->maxmarknum) { - cstr_info->maxmarknum = 100 + (int) ((float) cstr_info->maxmarknum * 1.0F); - cstr_info->marker = (opj_marker_info_t*)opj_realloc(cstr_info->marker, cstr_info->maxmarknum); - } - - /* add the marker */ - cstr_info->marker[cstr_info->marknum].type = type; - cstr_info->marker[cstr_info->marknum].pos = pos; - cstr_info->marker[cstr_info->marknum].len = len; - cstr_info->marknum++; - -} - -static void j2k_add_tlmarker( int tileno, opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len) { - - opj_marker_info_t *marker; - - if (!cstr_info) - return; - - /* expand the list? */ - if ((cstr_info->tile[tileno].marknum + 1) > cstr_info->tile[tileno].maxmarknum) { - cstr_info->tile[tileno].maxmarknum = 100 + (int) ((float) cstr_info->tile[tileno].maxmarknum * 1.0F); - cstr_info->tile[tileno].marker = (opj_marker_info_t*)opj_realloc(cstr_info->tile[tileno].marker, cstr_info->maxmarknum); - } - - marker = &(cstr_info->tile[tileno].marker[cstr_info->tile[tileno].marknum]); - - /* add the marker */ - marker->type = type; - marker->pos = pos; - marker->len = len; - cstr_info->tile[tileno].marknum++; -} +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2006-2007, Parvatha Elangovan + * Copyright (c) 2010-2011, Kaori Hagihara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */ +/*@{*/ + +/** @name Local static functions */ +/*@{*/ + +/** +Write the SOC marker (Start Of Codestream) +@param j2k J2K handle +*/ +static void j2k_write_soc(opj_j2k_t *j2k); +/** +Read the SOC marker (Start of Codestream) +@param j2k J2K handle +*/ +static void j2k_read_soc(opj_j2k_t *j2k); +/** +Write the SIZ marker (image and tile size) +@param j2k J2K handle +*/ +static void j2k_write_siz(opj_j2k_t *j2k); +/** +Read the SIZ marker (image and tile size) +@param j2k J2K handle +*/ +static void j2k_read_siz(opj_j2k_t *j2k); +/** +Write the COM marker (comment) +@param j2k J2K handle +*/ +static void j2k_write_com(opj_j2k_t *j2k); +/** +Read the COM marker (comment) +@param j2k J2K handle +*/ +static void j2k_read_com(opj_j2k_t *j2k); +/** +Write the value concerning the specified component in the marker COD and COC +@param j2k J2K handle +@param compno Number of the component concerned by the information written +*/ +static void j2k_write_cox(opj_j2k_t *j2k, int compno); +/** +Read the value concerning the specified component in the marker COD and COC +@param j2k J2K handle +@param compno Number of the component concerned by the information read +*/ +static void j2k_read_cox(opj_j2k_t *j2k, int compno); +/** +Write the COD marker (coding style default) +@param j2k J2K handle +*/ +static void j2k_write_cod(opj_j2k_t *j2k); +/** +Read the COD marker (coding style default) +@param j2k J2K handle +*/ +static void j2k_read_cod(opj_j2k_t *j2k); +/** +Write the COC marker (coding style component) +@param j2k J2K handle +@param compno Number of the component concerned by the information written +*/ +static void j2k_write_coc(opj_j2k_t *j2k, int compno); +/** +Read the COC marker (coding style component) +@param j2k J2K handle +*/ +static void j2k_read_coc(opj_j2k_t *j2k); +/** +Write the value concerning the specified component in the marker QCD and QCC +@param j2k J2K handle +@param compno Number of the component concerned by the information written +*/ +static void j2k_write_qcx(opj_j2k_t *j2k, int compno); +/** +Read the value concerning the specified component in the marker QCD and QCC +@param j2k J2K handle +@param compno Number of the component concern by the information read +@param len Length of the information in the QCX part of the marker QCD/QCC +*/ +static void j2k_read_qcx(opj_j2k_t *j2k, int compno, int len); +/** +Write the QCD marker (quantization default) +@param j2k J2K handle +*/ +static void j2k_write_qcd(opj_j2k_t *j2k); +/** +Read the QCD marker (quantization default) +@param j2k J2K handle +*/ +static void j2k_read_qcd(opj_j2k_t *j2k); +/** +Write the QCC marker (quantization component) +@param j2k J2K handle +@param compno Number of the component concerned by the information written +*/ +static void j2k_write_qcc(opj_j2k_t *j2k, int compno); +/** +Read the QCC marker (quantization component) +@param j2k J2K handle +*/ +static void j2k_read_qcc(opj_j2k_t *j2k); +/** +Write the POC marker (progression order change) +@param j2k J2K handle +*/ +static void j2k_write_poc(opj_j2k_t *j2k); +/** +Read the POC marker (progression order change) +@param j2k J2K handle +*/ +static void j2k_read_poc(opj_j2k_t *j2k); +/** +Read the CRG marker (component registration) +@param j2k J2K handle +*/ +static void j2k_read_crg(opj_j2k_t *j2k); +/** +Read the TLM marker (tile-part lengths) +@param j2k J2K handle +*/ +static void j2k_read_tlm(opj_j2k_t *j2k); +/** +Read the PLM marker (packet length, main header) +@param j2k J2K handle +*/ +static void j2k_read_plm(opj_j2k_t *j2k); +/** +Read the PLT marker (packet length, tile-part header) +@param j2k J2K handle +*/ +static void j2k_read_plt(opj_j2k_t *j2k); +/** +Read the PPM marker (packet packet headers, main header) +@param j2k J2K handle +*/ +static void j2k_read_ppm(opj_j2k_t *j2k); +/** +Read the PPT marker (packet packet headers, tile-part header) +@param j2k J2K handle +*/ +static void j2k_read_ppt(opj_j2k_t *j2k); +/** +Write the TLM marker (Mainheader) +@param j2k J2K handle +*/ +static void j2k_write_tlm(opj_j2k_t *j2k); +/** +Write the SOT marker (start of tile-part) +@param j2k J2K handle +*/ +static void j2k_write_sot(opj_j2k_t *j2k); +/** +Read the SOT marker (start of tile-part) +@param j2k J2K handle +*/ +static void j2k_read_sot(opj_j2k_t *j2k); +/** +Write the SOD marker (start of data) +@param j2k J2K handle +@param tile_coder Pointer to a TCD handle +*/ +static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder); +/** +Read the SOD marker (start of data) +@param j2k J2K handle +*/ +static void j2k_read_sod(opj_j2k_t *j2k); +/** +Write the RGN marker (region-of-interest) +@param j2k J2K handle +@param compno Number of the component concerned by the information written +@param tileno Number of the tile concerned by the information written +*/ +static void j2k_write_rgn(opj_j2k_t *j2k, int compno, int tileno); +/** +Read the RGN marker (region-of-interest) +@param j2k J2K handle +*/ +static void j2k_read_rgn(opj_j2k_t *j2k); +/** +Write the EOC marker (end of codestream) +@param j2k J2K handle +*/ +static void j2k_write_eoc(opj_j2k_t *j2k); +/** +Read the EOC marker (end of codestream) +@param j2k J2K handle +*/ +static void j2k_read_eoc(opj_j2k_t *j2k); +/** +Read an unknown marker +@param j2k J2K handle +*/ +static void j2k_read_unk(opj_j2k_t *j2k); +/** +Add main header marker information +@param cstr_info Codestream information structure +@param type marker type +@param pos byte offset of marker segment +@param len length of marker segment + */ +static void j2k_add_mhmarker(opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len); +/** +Add tile header marker information +@param tileno tile index number +@param cstr_info Codestream information structure +@param type marker type +@param pos byte offset of marker segment +@param len length of marker segment + */ +static void j2k_add_tlmarker( int tileno, opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len); + +/*@}*/ + +/*@}*/ + +/* ----------------------------------------------------------------------- */ +typedef struct j2k_prog_order{ + OPJ_PROG_ORDER enum_prog; + char str_prog[5]; +}j2k_prog_order_t; + +j2k_prog_order_t j2k_prog_order_list[] = { + {CPRL, "CPRL"}, + {LRCP, "LRCP"}, + {PCRL, "PCRL"}, + {RLCP, "RLCP"}, + {RPCL, "RPCL"}, + {(OPJ_PROG_ORDER)-1, ""} +}; + +char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order){ + j2k_prog_order_t *po; + for(po = j2k_prog_order_list; po->enum_prog != -1; po++ ){ + if(po->enum_prog == prg_order){ + break; + } + } + return po->str_prog; +} + +/* ----------------------------------------------------------------------- */ +static int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno){ + char *prog; + int i; + int tpnum=1,tpend=0; + opj_tcp_t *tcp = &cp->tcps[tileno]; + prog = j2k_convert_progression_order(tcp->prg); + + if(cp->tp_on == 1){ + for(i=0;i<4;i++){ + if(tpend!=1){ + if( cp->tp_flag == prog[i] ){ + tpend=1;cp->tp_pos=i; + } + switch(prog[i]){ + case 'C': + tpnum= tpnum * tcp->pocs[pino].compE; + break; + case 'R': + tpnum= tpnum * tcp->pocs[pino].resE; + break; + case 'P': + tpnum= tpnum * tcp->pocs[pino].prcE; + break; + case 'L': + tpnum= tpnum * tcp->pocs[pino].layE; + break; + } + } + } + }else{ + tpnum=1; + } + return tpnum; +} + +/** mem allocation for TLM marker*/ +int j2k_calculate_tp(opj_cp_t *cp,int img_numcomp,opj_image_t *image,opj_j2k_t *j2k ){ + int pino,tileno,totnum_tp=0; + + OPJ_ARG_NOT_USED(img_numcomp); + + j2k->cur_totnum_tp = (int *) opj_malloc(cp->tw * cp->th * sizeof(int)); + for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { + int cur_totnum_tp = 0; + opj_tcp_t *tcp = &cp->tcps[tileno]; + for(pino = 0; pino <= tcp->numpocs; pino++) { + int tp_num=0; + opj_pi_iterator_t *pi = pi_initialise_encode(image, cp, tileno,FINAL_PASS); + if(!pi) { return -1;} + tp_num = j2k_get_num_tp(cp,pino,tileno); + totnum_tp = totnum_tp + tp_num; + cur_totnum_tp = cur_totnum_tp + tp_num; + pi_destroy(pi, cp, tileno); + } + j2k->cur_totnum_tp[tileno] = cur_totnum_tp; + /* INDEX >> */ + if (j2k->cstr_info) { + j2k->cstr_info->tile[tileno].num_tps = cur_totnum_tp; + j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_malloc(cur_totnum_tp * sizeof(opj_tp_info_t)); + } + /* << INDEX */ + } + return totnum_tp; +} + +static void j2k_write_soc(opj_j2k_t *j2k) { + opj_cio_t *cio = j2k->cio; + cio_write(cio, J2K_MS_SOC, 2); + + if(j2k->cstr_info) + j2k_add_mhmarker(j2k->cstr_info, J2K_MS_SOC, cio_tell(cio), 0); + +/* UniPG>> */ +#ifdef USE_JPWL + + /* update markers struct */ + j2k_add_marker(j2k->cstr_info, J2K_MS_SOC, cio_tell(cio) - 2, 2); +#endif /* USE_JPWL */ +/* <state = J2K_STATE_MHSIZ; + /* Index */ + if (j2k->cstr_info) { + j2k->cstr_info->main_head_start = cio_tell(j2k->cio) - 2; + j2k->cstr_info->codestream_size = cio_numbytesleft(j2k->cio) + 2 - j2k->cstr_info->main_head_start; + } +} + +static void j2k_write_siz(opj_j2k_t *j2k) { + int i; + int lenp, len; + + opj_cio_t *cio = j2k->cio; + opj_image_t *image = j2k->image; + opj_cp_t *cp = j2k->cp; + + cio_write(cio, J2K_MS_SIZ, 2); /* SIZ */ + lenp = cio_tell(cio); + cio_skip(cio, 2); + cio_write(cio, cp->rsiz, 2); /* Rsiz (capabilities) */ + cio_write(cio, image->x1, 4); /* Xsiz */ + cio_write(cio, image->y1, 4); /* Ysiz */ + cio_write(cio, image->x0, 4); /* X0siz */ + cio_write(cio, image->y0, 4); /* Y0siz */ + cio_write(cio, cp->tdx, 4); /* XTsiz */ + cio_write(cio, cp->tdy, 4); /* YTsiz */ + cio_write(cio, cp->tx0, 4); /* XT0siz */ + cio_write(cio, cp->ty0, 4); /* YT0siz */ + cio_write(cio, image->numcomps, 2); /* Csiz */ + for (i = 0; i < image->numcomps; i++) { + cio_write(cio, image->comps[i].prec - 1 + (image->comps[i].sgnd << 7), 1); /* Ssiz_i */ + cio_write(cio, image->comps[i].dx, 1); /* XRsiz_i */ + cio_write(cio, image->comps[i].dy, 1); /* YRsiz_i */ + } + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Lsiz */ + cio_seek(cio, lenp + len); + + if(j2k->cstr_info) + j2k_add_mhmarker(j2k->cstr_info, J2K_MS_SIZ, lenp, len); +} + +static void j2k_read_siz(opj_j2k_t *j2k) { + int len, i; + + opj_cio_t *cio = j2k->cio; + opj_image_t *image = j2k->image; + opj_cp_t *cp = j2k->cp; + + len = cio_read(cio, 2); /* Lsiz */ + cio_read(cio, 2); /* Rsiz (capabilities) */ + image->x1 = cio_read(cio, 4); /* Xsiz */ + image->y1 = cio_read(cio, 4); /* Ysiz */ + image->x0 = cio_read(cio, 4); /* X0siz */ + image->y0 = cio_read(cio, 4); /* Y0siz */ + cp->tdx = cio_read(cio, 4); /* XTsiz */ + cp->tdy = cio_read(cio, 4); /* YTsiz */ + cp->tx0 = cio_read(cio, 4); /* XT0siz */ + cp->ty0 = cio_read(cio, 4); /* YT0siz */ + + if ((image->x0<0)||(image->x1<0)||(image->y0<0)||(image->y1<0)) { + opj_event_msg(j2k->cinfo, EVT_ERROR, + "%s: invalid image size (x0:%d, x1:%d, y0:%d, y1:%d)\n", + image->x0,image->x1,image->y0,image->y1); + return; + } + + image->numcomps = cio_read(cio, 2); /* Csiz */ + +#ifdef USE_JPWL + if (j2k->cp->correct) { + /* if JPWL is on, we check whether TX errors have damaged + too much the SIZ parameters */ + if (!(image->x1 * image->y1)) { + opj_event_msg(j2k->cinfo, EVT_ERROR, + "JPWL: bad image size (%d x %d)\n", + image->x1, image->y1); + if (!JPWL_ASSUME || JPWL_ASSUME) { + opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); + return; + } + } + if (image->numcomps != ((len - 38) / 3)) { + opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR, + "JPWL: Csiz is %d => space in SIZ only for %d comps.!!!\n", + image->numcomps, ((len - 38) / 3)); + if (!JPWL_ASSUME) { + opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); + return; + } + /* we try to correct */ + opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n"); + if (image->numcomps < ((len - 38) / 3)) { + len = 38 + 3 * image->numcomps; + opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting Lsiz to %d => HYPOTHESIS!!!\n", + len); + } else { + image->numcomps = ((len - 38) / 3); + opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting Csiz to %d => HYPOTHESIS!!!\n", + image->numcomps); + } + } + + /* update components number in the jpwl_exp_comps filed */ + cp->exp_comps = image->numcomps; + } +#endif /* USE_JPWL */ + + image->comps = (opj_image_comp_t*) opj_calloc(image->numcomps, sizeof(opj_image_comp_t)); + for (i = 0; i < image->numcomps; i++) { + int tmp, w, h; + tmp = cio_read(cio, 1); /* Ssiz_i */ + image->comps[i].prec = (tmp & 0x7f) + 1; + image->comps[i].sgnd = tmp >> 7; + image->comps[i].dx = cio_read(cio, 1); /* XRsiz_i */ + image->comps[i].dy = cio_read(cio, 1); /* YRsiz_i */ + +#ifdef USE_JPWL + if (j2k->cp->correct) { + /* if JPWL is on, we check whether TX errors have damaged + too much the SIZ parameters, again */ + if (!(image->comps[i].dx * image->comps[i].dy)) { + opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR, + "JPWL: bad XRsiz_%d/YRsiz_%d (%d x %d)\n", + i, i, image->comps[i].dx, image->comps[i].dy); + if (!JPWL_ASSUME) { + opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); + return; + } + /* we try to correct */ + opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust them\n"); + if (!image->comps[i].dx) { + image->comps[i].dx = 1; + opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting XRsiz_%d to %d => HYPOTHESIS!!!\n", + i, image->comps[i].dx); + } + if (!image->comps[i].dy) { + image->comps[i].dy = 1; + opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting YRsiz_%d to %d => HYPOTHESIS!!!\n", + i, image->comps[i].dy); + } + } + + } +#endif /* USE_JPWL */ + + /* TODO: unused ? */ + w = int_ceildiv(image->x1 - image->x0, image->comps[i].dx); + h = int_ceildiv(image->y1 - image->y0, image->comps[i].dy); + + image->comps[i].resno_decoded = 0; /* number of resolution decoded */ + image->comps[i].factor = cp->reduce; /* reducing factor per component */ + } + + cp->tw = int_ceildiv(image->x1 - cp->tx0, cp->tdx); + cp->th = int_ceildiv(image->y1 - cp->ty0, cp->tdy); + +#ifdef USE_JPWL + if (j2k->cp->correct) { + /* if JPWL is on, we check whether TX errors have damaged + too much the SIZ parameters */ + if ((cp->tw < 1) || (cp->th < 1) || (cp->tw > cp->max_tiles) || (cp->th > cp->max_tiles)) { + opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR, + "JPWL: bad number of tiles (%d x %d)\n", + cp->tw, cp->th); + if (!JPWL_ASSUME) { + opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); + return; + } + /* we try to correct */ + opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust them\n"); + if (cp->tw < 1) { + cp->tw= 1; + opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting %d tiles in x => HYPOTHESIS!!!\n", + cp->tw); + } + if (cp->tw > cp->max_tiles) { + cp->tw= 1; + opj_event_msg(j2k->cinfo, EVT_WARNING, "- too large x, increase expectance of %d\n" + "- setting %d tiles in x => HYPOTHESIS!!!\n", + cp->max_tiles, cp->tw); + } + if (cp->th < 1) { + cp->th= 1; + opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting %d tiles in y => HYPOTHESIS!!!\n", + cp->th); + } + if (cp->th > cp->max_tiles) { + cp->th= 1; + opj_event_msg(j2k->cinfo, EVT_WARNING, "- too large y, increase expectance of %d to continue\n", + "- setting %d tiles in y => HYPOTHESIS!!!\n", + cp->max_tiles, cp->th); + } + } + } +#endif /* USE_JPWL */ + + cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t)); + if (cp->tcps == NULL) + { + opj_event_msg(j2k->cinfo, EVT_ERROR, "Out of memory\n"); + return; + } + cp->tileno = (int*) opj_malloc(cp->tw * cp->th * sizeof(int)); + if (cp->tileno == NULL) + { + opj_event_msg(j2k->cinfo, EVT_ERROR, "Out of memory\n"); + return; + } + cp->tileno_size = 0; + +#ifdef USE_JPWL + if (j2k->cp->correct) { + if (!cp->tcps) { + opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR, + "JPWL: could not alloc tcps field of cp\n"); + if (!JPWL_ASSUME || JPWL_ASSUME) { + opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); + return; + } + } + } +#endif /* USE_JPWL */ + + for (i = 0; i < cp->tw * cp->th; i++) { + cp->tcps[i].POC = 0; + cp->tcps[i].numpocs = 0; + cp->tcps[i].first = 1; + } + + /* Initialization for PPM marker */ + cp->ppm = 0; + cp->ppm_data = NULL; + cp->ppm_data_first = NULL; + cp->ppm_previous = 0; + cp->ppm_store = 0; + + j2k->default_tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t)); + for (i = 0; i < cp->tw * cp->th; i++) { + cp->tcps[i].tccps = (opj_tccp_t*) opj_malloc(image->numcomps * sizeof(opj_tccp_t)); + } + j2k->tile_data = (unsigned char**) opj_calloc(cp->tw * cp->th, sizeof(unsigned char*)); + j2k->tile_len = (int*) opj_calloc(cp->tw * cp->th, sizeof(int)); + j2k->state = J2K_STATE_MH; + + /* Index */ + if (j2k->cstr_info) { + opj_codestream_info_t *cstr_info = j2k->cstr_info; + cstr_info->image_w = image->x1 - image->x0; + cstr_info->image_h = image->y1 - image->y0; + cstr_info->numcomps = image->numcomps; + cstr_info->tw = cp->tw; + cstr_info->th = cp->th; + cstr_info->tile_x = cp->tdx; + cstr_info->tile_y = cp->tdy; + cstr_info->tile_Ox = cp->tx0; + cstr_info->tile_Oy = cp->ty0; + cstr_info->tile = (opj_tile_info_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tile_info_t)); + } +} + +static void j2k_write_com(opj_j2k_t *j2k) { + unsigned int i; + int lenp, len; + + if(j2k->cp->comment) { + opj_cio_t *cio = j2k->cio; + char *comment = j2k->cp->comment; + + cio_write(cio, J2K_MS_COM, 2); + lenp = cio_tell(cio); + cio_skip(cio, 2); + cio_write(cio, 1, 2); /* General use (IS 8859-15:1999 (Latin) values) */ + for (i = 0; i < strlen(comment); i++) { + cio_write(cio, comment[i], 1); + } + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); + cio_seek(cio, lenp + len); + + + if(j2k->cstr_info) + j2k_add_mhmarker(j2k->cstr_info, J2K_MS_COM, lenp, len); + + } +} + +static void j2k_read_com(opj_j2k_t *j2k) { + int len; + + opj_cio_t *cio = j2k->cio; + + len = cio_read(cio, 2); + cio_skip(cio, len - 2); +} + +static void j2k_write_cox(opj_j2k_t *j2k, int compno) { + int i; + + opj_cp_t *cp = j2k->cp; + opj_tcp_t *tcp = &cp->tcps[j2k->curtileno]; + opj_tccp_t *tccp = &tcp->tccps[compno]; + opj_cio_t *cio = j2k->cio; + + cio_write(cio, tccp->numresolutions - 1, 1); /* SPcox (D) */ + cio_write(cio, tccp->cblkw - 2, 1); /* SPcox (E) */ + cio_write(cio, tccp->cblkh - 2, 1); /* SPcox (F) */ + cio_write(cio, tccp->cblksty, 1); /* SPcox (G) */ + cio_write(cio, tccp->qmfbid, 1); /* SPcox (H) */ + + if (tccp->csty & J2K_CCP_CSTY_PRT) { + for (i = 0; i < tccp->numresolutions; i++) { + cio_write(cio, tccp->prcw[i] + (tccp->prch[i] << 4), 1); /* SPcox (I_i) */ + } + } +} + +static void j2k_read_cox(opj_j2k_t *j2k, int compno) { + int i; + + opj_cp_t *cp = j2k->cp; + opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp; + opj_tccp_t *tccp = &tcp->tccps[compno]; + opj_cio_t *cio = j2k->cio; + + tccp->numresolutions = cio_read(cio, 1) + 1; /* SPcox (D) */ + + /* If user wants to remove more resolutions than the codestream contains, return error*/ + if (cp->reduce >= tccp->numresolutions) { + opj_event_msg(j2k->cinfo, EVT_ERROR, "Error decoding component %d.\nThe number of resolutions to remove is higher than the number " + "of resolutions of this component\nModify the cp_reduce parameter.\n\n", compno); + j2k->state |= J2K_STATE_ERR; + } + if( tccp->numresolutions > J2K_MAXRLVLS ) { + opj_event_msg(j2k->cinfo, EVT_ERROR, "Error decoding component %d.\nThe number of resolutions is too big: %d vs max= %d. Truncating.\n\n", + compno, tccp->numresolutions, J2K_MAXRLVLS); + j2k->state |= J2K_STATE_ERR; + tccp->numresolutions = J2K_MAXRLVLS; + } + + tccp->cblkw = cio_read(cio, 1) + 2; /* SPcox (E) */ + tccp->cblkh = cio_read(cio, 1) + 2; /* SPcox (F) */ + tccp->cblksty = cio_read(cio, 1); /* SPcox (G) */ + tccp->qmfbid = cio_read(cio, 1); /* SPcox (H) */ + if (tccp->csty & J2K_CP_CSTY_PRT) { + for (i = 0; i < tccp->numresolutions; i++) { + int tmp = cio_read(cio, 1); /* SPcox (I_i) */ + tccp->prcw[i] = tmp & 0xf; + tccp->prch[i] = tmp >> 4; + } + } + + /* INDEX >> */ + if(j2k->cstr_info && compno == 0) { + for (i = 0; i < tccp->numresolutions; i++) { + if (tccp->csty & J2K_CP_CSTY_PRT) { + j2k->cstr_info->tile[j2k->curtileno].pdx[i] = tccp->prcw[i]; + j2k->cstr_info->tile[j2k->curtileno].pdy[i] = tccp->prch[i]; + } + else { + j2k->cstr_info->tile[j2k->curtileno].pdx[i] = 15; + j2k->cstr_info->tile[j2k->curtileno].pdx[i] = 15; + } + } + } + /* << INDEX */ +} + +static void j2k_write_cod(opj_j2k_t *j2k) { + opj_cp_t *cp = NULL; + opj_tcp_t *tcp = NULL; + int lenp, len; + + opj_cio_t *cio = j2k->cio; + + cio_write(cio, J2K_MS_COD, 2); /* COD */ + + lenp = cio_tell(cio); + cio_skip(cio, 2); + + cp = j2k->cp; + tcp = &cp->tcps[j2k->curtileno]; + + cio_write(cio, tcp->csty, 1); /* Scod */ + cio_write(cio, tcp->prg, 1); /* SGcod (A) */ + cio_write(cio, tcp->numlayers, 2); /* SGcod (B) */ + cio_write(cio, tcp->mct, 1); /* SGcod (C) */ + + j2k_write_cox(j2k, 0); + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Lcod */ + cio_seek(cio, lenp + len); + + if(j2k->cstr_info) + j2k_add_mhmarker(j2k->cstr_info, J2K_MS_COD, lenp, len); + +} + +static void j2k_read_cod(opj_j2k_t *j2k) { + int len, i, pos; + + opj_cio_t *cio = j2k->cio; + opj_cp_t *cp = j2k->cp; + opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp; + opj_image_t *image = j2k->image; + + len = cio_read(cio, 2); /* Lcod */ + tcp->csty = cio_read(cio, 1); /* Scod */ + tcp->prg = (OPJ_PROG_ORDER)cio_read(cio, 1); /* SGcod (A) */ + tcp->numlayers = cio_read(cio, 2); /* SGcod (B) */ + tcp->mct = cio_read(cio, 1); /* SGcod (C) */ + + pos = cio_tell(cio); + for (i = 0; i < image->numcomps; i++) { + tcp->tccps[i].csty = tcp->csty & J2K_CP_CSTY_PRT; + cio_seek(cio, pos); + j2k_read_cox(j2k, i); + } + + /* Index */ + if (j2k->cstr_info) { + opj_codestream_info_t *cstr_info = j2k->cstr_info; + cstr_info->prog = tcp->prg; + cstr_info->numlayers = tcp->numlayers; + cstr_info->numdecompos = (int*) opj_malloc(image->numcomps * sizeof(int)); + for (i = 0; i < image->numcomps; i++) { + cstr_info->numdecompos[i] = tcp->tccps[i].numresolutions - 1; + } + } +} + +static void j2k_write_coc(opj_j2k_t *j2k, int compno) { + int lenp, len; + + opj_cp_t *cp = j2k->cp; + opj_tcp_t *tcp = &cp->tcps[j2k->curtileno]; + opj_image_t *image = j2k->image; + opj_cio_t *cio = j2k->cio; + + cio_write(cio, J2K_MS_COC, 2); /* COC */ + lenp = cio_tell(cio); + cio_skip(cio, 2); + cio_write(cio, compno, image->numcomps <= 256 ? 1 : 2); /* Ccoc */ + cio_write(cio, tcp->tccps[compno].csty, 1); /* Scoc */ + j2k_write_cox(j2k, compno); + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Lcoc */ + cio_seek(cio, lenp + len); +} + +static void j2k_read_coc(opj_j2k_t *j2k) { + int len, compno; + + opj_cp_t *cp = j2k->cp; + opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp; + opj_image_t *image = j2k->image; + opj_cio_t *cio = j2k->cio; + + len = cio_read(cio, 2); /* Lcoc */ + compno = cio_read(cio, image->numcomps <= 256 ? 1 : 2); /* Ccoc */ + tcp->tccps[compno].csty = cio_read(cio, 1); /* Scoc */ + j2k_read_cox(j2k, compno); +} + +static void j2k_write_qcx(opj_j2k_t *j2k, int compno) { + int bandno, numbands; + int expn, mant; + + opj_cp_t *cp = j2k->cp; + opj_tcp_t *tcp = &cp->tcps[j2k->curtileno]; + opj_tccp_t *tccp = &tcp->tccps[compno]; + opj_cio_t *cio = j2k->cio; + + cio_write(cio, tccp->qntsty + (tccp->numgbits << 5), 1); /* Sqcx */ + numbands = tccp->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : tccp->numresolutions * 3 - 2; + + for (bandno = 0; bandno < numbands; bandno++) { + expn = tccp->stepsizes[bandno].expn; + mant = tccp->stepsizes[bandno].mant; + + if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) { + cio_write(cio, expn << 3, 1); /* SPqcx_i */ + } else { + cio_write(cio, (expn << 11) + mant, 2); /* SPqcx_i */ + } + } +} + +static void j2k_read_qcx(opj_j2k_t *j2k, int compno, int len) { + int tmp; + int bandno, numbands; + + opj_cp_t *cp = j2k->cp; + opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp; + opj_tccp_t *tccp = &tcp->tccps[compno]; + opj_cio_t *cio = j2k->cio; + + tmp = cio_read(cio, 1); /* Sqcx */ + tccp->qntsty = tmp & 0x1f; + tccp->numgbits = tmp >> 5; + numbands = (tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) ? + 1 : ((tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) ? len - 1 : (len - 1) / 2); + +#ifdef USE_JPWL + if (j2k->cp->correct) { + + /* if JPWL is on, we check whether there are too many subbands */ + if ((numbands < 0) || (numbands >= J2K_MAXBANDS)) { + opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR, + "JPWL: bad number of subbands in Sqcx (%d)\n", + numbands); + if (!JPWL_ASSUME) { + opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); + return; + } + /* we try to correct */ + numbands = 1; + opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust them\n" + "- setting number of bands to %d => HYPOTHESIS!!!\n", + numbands); + }; + + }; + +#else + /* We check whether there are too many subbands */ + if ((numbands < 0) || (numbands >= J2K_MAXBANDS)) { + opj_event_msg(j2k->cinfo, EVT_WARNING , + "bad number of subbands in Sqcx (%d) regarding to J2K_MAXBANDS (%d) \n" + "- limiting number of bands to J2K_MAXBANDS and try to move to the next markers\n", numbands, J2K_MAXBANDS); + } + +#endif /* USE_JPWL */ + + for (bandno = 0; bandno < numbands; bandno++) { + int expn, mant; + if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) { + expn = cio_read(cio, 1) >> 3; /* SPqcx_i */ + mant = 0; + } else { + tmp = cio_read(cio, 2); /* SPqcx_i */ + expn = tmp >> 11; + mant = tmp & 0x7ff; + } + if (bandno < J2K_MAXBANDS){ + tccp->stepsizes[bandno].expn = expn; + tccp->stepsizes[bandno].mant = mant; + } + } + + /* Add Antonin : if scalar_derived -> compute other stepsizes */ + if (tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) { + for (bandno = 1; bandno < J2K_MAXBANDS; bandno++) { + tccp->stepsizes[bandno].expn = + ((tccp->stepsizes[0].expn) - ((bandno - 1) / 3) > 0) ? + (tccp->stepsizes[0].expn) - ((bandno - 1) / 3) : 0; + tccp->stepsizes[bandno].mant = tccp->stepsizes[0].mant; + } + } + /* ddA */ +} + +static void j2k_write_qcd(opj_j2k_t *j2k) { + int lenp, len; + + opj_cio_t *cio = j2k->cio; + + cio_write(cio, J2K_MS_QCD, 2); /* QCD */ + lenp = cio_tell(cio); + cio_skip(cio, 2); + j2k_write_qcx(j2k, 0); + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Lqcd */ + cio_seek(cio, lenp + len); + + if(j2k->cstr_info) + j2k_add_mhmarker(j2k->cstr_info, J2K_MS_QCD, lenp, len); +} + +static void j2k_read_qcd(opj_j2k_t *j2k) { + int len, i, pos; + + opj_cio_t *cio = j2k->cio; + opj_image_t *image = j2k->image; + + len = cio_read(cio, 2); /* Lqcd */ + pos = cio_tell(cio); + for (i = 0; i < image->numcomps; i++) { + cio_seek(cio, pos); + j2k_read_qcx(j2k, i, len - 2); + } +} + +static void j2k_write_qcc(opj_j2k_t *j2k, int compno) { + int lenp, len; + + opj_cio_t *cio = j2k->cio; + + cio_write(cio, J2K_MS_QCC, 2); /* QCC */ + lenp = cio_tell(cio); + cio_skip(cio, 2); + cio_write(cio, compno, j2k->image->numcomps <= 256 ? 1 : 2); /* Cqcc */ + j2k_write_qcx(j2k, compno); + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Lqcc */ + cio_seek(cio, lenp + len); +} + +static void j2k_read_qcc(opj_j2k_t *j2k) { + int len, compno; + int numcomp = j2k->image->numcomps; + opj_cio_t *cio = j2k->cio; + + len = cio_read(cio, 2); /* Lqcc */ + compno = cio_read(cio, numcomp <= 256 ? 1 : 2); /* Cqcc */ + +#ifdef USE_JPWL + if (j2k->cp->correct) { + + static int backup_compno = 0; + + /* compno is negative or larger than the number of components!!! */ + if ((compno < 0) || (compno >= numcomp)) { + opj_event_msg(j2k->cinfo, EVT_ERROR, + "JPWL: bad component number in QCC (%d out of a maximum of %d)\n", + compno, numcomp); + if (!JPWL_ASSUME) { + opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); + return; + } + /* we try to correct */ + compno = backup_compno % numcomp; + opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n" + "- setting component number to %d\n", + compno); + } + + /* keep your private count of tiles */ + backup_compno++; + }; +#endif /* USE_JPWL */ + + j2k_read_qcx(j2k, compno, len - 2 - (numcomp <= 256 ? 1 : 2)); +} + +static void j2k_write_poc(opj_j2k_t *j2k) { + int len, numpchgs, i; + + int numcomps = j2k->image->numcomps; + + opj_cp_t *cp = j2k->cp; + opj_tcp_t *tcp = &cp->tcps[j2k->curtileno]; + opj_tccp_t *tccp = &tcp->tccps[0]; + opj_cio_t *cio = j2k->cio; + + numpchgs = 1 + tcp->numpocs; + cio_write(cio, J2K_MS_POC, 2); /* POC */ + len = 2 + (5 + 2 * (numcomps <= 256 ? 1 : 2)) * numpchgs; + cio_write(cio, len, 2); /* Lpoc */ + for (i = 0; i < numpchgs; i++) { + opj_poc_t *poc = &tcp->pocs[i]; + cio_write(cio, poc->resno0, 1); /* RSpoc_i */ + cio_write(cio, poc->compno0, (numcomps <= 256 ? 1 : 2)); /* CSpoc_i */ + cio_write(cio, poc->layno1, 2); /* LYEpoc_i */ + poc->layno1 = int_min(poc->layno1, tcp->numlayers); + cio_write(cio, poc->resno1, 1); /* REpoc_i */ + poc->resno1 = int_min(poc->resno1, tccp->numresolutions); + cio_write(cio, poc->compno1, (numcomps <= 256 ? 1 : 2)); /* CEpoc_i */ + poc->compno1 = int_min(poc->compno1, numcomps); + cio_write(cio, poc->prg, 1); /* Ppoc_i */ + } +} + +static void j2k_read_poc(opj_j2k_t *j2k) { + int len, numpchgs, i, old_poc; + + int numcomps = j2k->image->numcomps; + + opj_cp_t *cp = j2k->cp; + opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp; + opj_cio_t *cio = j2k->cio; + + old_poc = tcp->POC ? tcp->numpocs + 1 : 0; + tcp->POC = 1; + len = cio_read(cio, 2); /* Lpoc */ + numpchgs = (len - 2) / (5 + 2 * (numcomps <= 256 ? 1 : 2)); + + for (i = old_poc; i < numpchgs + old_poc; i++) { + opj_poc_t *poc; + poc = &tcp->pocs[i]; + poc->resno0 = cio_read(cio, 1); /* RSpoc_i */ + poc->compno0 = cio_read(cio, numcomps <= 256 ? 1 : 2); /* CSpoc_i */ + poc->layno1 = cio_read(cio, 2); /* LYEpoc_i */ + poc->resno1 = cio_read(cio, 1); /* REpoc_i */ + poc->compno1 = int_min( + cio_read(cio, numcomps <= 256 ? 1 : 2), (unsigned int) numcomps); /* CEpoc_i */ + poc->prg = (OPJ_PROG_ORDER)cio_read(cio, 1); /* Ppoc_i */ + } + + tcp->numpocs = numpchgs + old_poc - 1; +} + +static void j2k_read_crg(opj_j2k_t *j2k) { + int len, i, Xcrg_i, Ycrg_i; + + opj_cio_t *cio = j2k->cio; + int numcomps = j2k->image->numcomps; + + len = cio_read(cio, 2); /* Lcrg */ + for (i = 0; i < numcomps; i++) { + Xcrg_i = cio_read(cio, 2); /* Xcrg_i */ + Ycrg_i = cio_read(cio, 2); /* Ycrg_i */ + } +} + +static void j2k_read_tlm(opj_j2k_t *j2k) { + int len, Ztlm, Stlm, ST, SP, tile_tlm, i; + long int Ttlm_i, Ptlm_i; + + opj_cio_t *cio = j2k->cio; + + len = cio_read(cio, 2); /* Ltlm */ + Ztlm = cio_read(cio, 1); /* Ztlm */ + Stlm = cio_read(cio, 1); /* Stlm */ + ST = ((Stlm >> 4) & 0x01) + ((Stlm >> 4) & 0x02); + SP = (Stlm >> 6) & 0x01; + tile_tlm = (len - 4) / ((SP + 1) * 2 + ST); + for (i = 0; i < tile_tlm; i++) { + Ttlm_i = cio_read(cio, ST); /* Ttlm_i */ + Ptlm_i = cio_read(cio, SP ? 4 : 2); /* Ptlm_i */ + } +} + +static void j2k_read_plm(opj_j2k_t *j2k) { + int len, i, Zplm, Nplm, add, packet_len = 0; + + opj_cio_t *cio = j2k->cio; + + len = cio_read(cio, 2); /* Lplm */ + Zplm = cio_read(cio, 1); /* Zplm */ + len -= 3; + while (len > 0) { + Nplm = cio_read(cio, 4); /* Nplm */ + len -= 4; + for (i = Nplm; i > 0; i--) { + add = cio_read(cio, 1); + len--; + packet_len = (packet_len << 7) + add; /* Iplm_ij */ + if ((add & 0x80) == 0) { + /* New packet */ + packet_len = 0; + } + if (len <= 0) + break; + } + } +} + +static void j2k_read_plt(opj_j2k_t *j2k) { + int len, i, Zplt, packet_len = 0, add; + + opj_cio_t *cio = j2k->cio; + + len = cio_read(cio, 2); /* Lplt */ + Zplt = cio_read(cio, 1); /* Zplt */ + for (i = len - 3; i > 0; i--) { + add = cio_read(cio, 1); + packet_len = (packet_len << 7) + add; /* Iplt_i */ + if ((add & 0x80) == 0) { + /* New packet */ + packet_len = 0; + } + } +} + +static void j2k_read_ppm(opj_j2k_t *j2k) { + int len, Z_ppm, i, j; + int N_ppm; + + opj_cp_t *cp = j2k->cp; + opj_cio_t *cio = j2k->cio; + + len = cio_read(cio, 2); + cp->ppm = 1; + + Z_ppm = cio_read(cio, 1); /* Z_ppm */ + len -= 3; + while (len > 0) { + if (cp->ppm_previous == 0) { + N_ppm = cio_read(cio, 4); /* N_ppm */ + len -= 4; + } else { + N_ppm = cp->ppm_previous; + } + j = cp->ppm_store; + if (Z_ppm == 0) { /* First PPM marker */ + cp->ppm_data = (unsigned char *) opj_malloc(N_ppm * sizeof(unsigned char)); + cp->ppm_data_first = cp->ppm_data; + cp->ppm_len = N_ppm; + } else { /* NON-first PPM marker */ + cp->ppm_data = (unsigned char *) opj_realloc(cp->ppm_data, (N_ppm + cp->ppm_store) * sizeof(unsigned char)); + +#ifdef USE_JPWL + /* this memory allocation check could be done even in non-JPWL cases */ + if (cp->correct) { + if (!cp->ppm_data) { + opj_event_msg(j2k->cinfo, EVT_ERROR, + "JPWL: failed memory allocation during PPM marker parsing (pos. %x)\n", + cio_tell(cio)); + if (!JPWL_ASSUME || JPWL_ASSUME) { + opj_free(cp->ppm_data); + opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); + return; + } + } + } +#endif + + cp->ppm_data_first = cp->ppm_data; + cp->ppm_len = N_ppm + cp->ppm_store; + } + for (i = N_ppm; i > 0; i--) { /* Read packet header */ + cp->ppm_data[j] = cio_read(cio, 1); + j++; + len--; + if (len == 0) + break; /* Case of non-finished packet header in present marker but finished in next one */ + } + cp->ppm_previous = i - 1; + cp->ppm_store = j; + } +} + +static void j2k_read_ppt(opj_j2k_t *j2k) { + int len, Z_ppt, i, j = 0; + + opj_cp_t *cp = j2k->cp; + opj_tcp_t *tcp = cp->tcps + j2k->curtileno; + opj_cio_t *cio = j2k->cio; + + len = cio_read(cio, 2); + Z_ppt = cio_read(cio, 1); + tcp->ppt = 1; + if (Z_ppt == 0) { /* First PPT marker */ + tcp->ppt_data = (unsigned char *) opj_malloc((len - 3) * sizeof(unsigned char)); + tcp->ppt_data_first = tcp->ppt_data; + tcp->ppt_store = 0; + tcp->ppt_len = len - 3; + } else { /* NON-first PPT marker */ + tcp->ppt_data = (unsigned char *) opj_realloc(tcp->ppt_data, (len - 3 + tcp->ppt_store) * sizeof(unsigned char)); + tcp->ppt_data_first = tcp->ppt_data; + tcp->ppt_len = len - 3 + tcp->ppt_store; + } + j = tcp->ppt_store; + for (i = len - 3; i > 0; i--) { + tcp->ppt_data[j] = cio_read(cio, 1); + j++; + } + tcp->ppt_store = j; +} + +static void j2k_write_tlm(opj_j2k_t *j2k){ + int lenp; + opj_cio_t *cio = j2k->cio; + j2k->tlm_start = cio_tell(cio); + cio_write(cio, J2K_MS_TLM, 2);/* TLM */ + lenp = 4 + (5*j2k->totnum_tp); + cio_write(cio,lenp,2); /* Ltlm */ + cio_write(cio, 0,1); /* Ztlm=0*/ + cio_write(cio,80,1); /* Stlm ST=1(8bits-255 tiles max),SP=1(Ptlm=32bits) */ + cio_skip(cio,5*j2k->totnum_tp); +} + +static void j2k_write_sot(opj_j2k_t *j2k) { + int lenp, len; + + opj_cio_t *cio = j2k->cio; + + j2k->sot_start = cio_tell(cio); + cio_write(cio, J2K_MS_SOT, 2); /* SOT */ + lenp = cio_tell(cio); + cio_skip(cio, 2); /* Lsot (further) */ + cio_write(cio, j2k->curtileno, 2); /* Isot */ + cio_skip(cio, 4); /* Psot (further in j2k_write_sod) */ + cio_write(cio, j2k->cur_tp_num , 1); /* TPsot */ + cio_write(cio, j2k->cur_totnum_tp[j2k->curtileno], 1); /* TNsot */ + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Lsot */ + cio_seek(cio, lenp + len); + + /* UniPG>> */ +#ifdef USE_JPWL + /* update markers struct */ + j2k_add_marker(j2k->cstr_info, J2K_MS_SOT, j2k->sot_start, len + 2); +#endif /* USE_JPWL */ + /* <cstr_info && j2k->cur_tp_num==0){ + j2k_add_tlmarker( j2k->curtileno, j2k->cstr_info, J2K_MS_SOT, lenp, len); + } +} + +static void j2k_read_sot(opj_j2k_t *j2k) { + int len, tileno, totlen, partno, numparts, i; + opj_tcp_t *tcp = NULL; + char status = 0; + + opj_cp_t *cp = j2k->cp; + opj_cio_t *cio = j2k->cio; + + len = cio_read(cio, 2); + tileno = cio_read(cio, 2); + +#ifdef USE_JPWL + if (j2k->cp->correct) { + + static int backup_tileno = 0; + + /* tileno is negative or larger than the number of tiles!!! */ + if ((tileno < 0) || (tileno >= (cp->tw * cp->th))) { + opj_event_msg(j2k->cinfo, EVT_ERROR, + "JPWL: bad tile number (%d out of a maximum of %d)\n", + tileno, (cp->tw * cp->th)); + if (!JPWL_ASSUME) { + opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); + return; + } + /* we try to correct */ + tileno = backup_tileno; + opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n" + "- setting tile number to %d\n", + tileno); + } + + /* keep your private count of tiles */ + backup_tileno++; + } + else +#endif /* USE_JPWL */ + { + /* tileno is negative or larger than the number of tiles!!! */ + if ((tileno < 0) || (tileno >= (cp->tw * cp->th))) { + opj_event_msg(j2k->cinfo, EVT_ERROR, + "JPWL: bad tile number (%d out of a maximum of %d)\n", + tileno, (cp->tw * cp->th)); + return; + } + } + + if (cp->tileno_size == 0) { + cp->tileno[cp->tileno_size] = tileno; + cp->tileno_size++; + } else { + i = 0; + while (i < cp->tileno_size && status == 0) { + status = cp->tileno[i] == tileno ? 1 : 0; + i++; + } + if (status == 0) { + cp->tileno[cp->tileno_size] = tileno; + cp->tileno_size++; + } + } + + totlen = cio_read(cio, 4); + +#ifdef USE_JPWL + if (j2k->cp->correct) { + + /* totlen is negative or larger than the bytes left!!! */ + if ((totlen < 0) || (totlen > (cio_numbytesleft(cio) + 8))) { + opj_event_msg(j2k->cinfo, EVT_ERROR, + "JPWL: bad tile byte size (%d bytes against %d bytes left)\n", + totlen, cio_numbytesleft(cio) + 8); + if (!JPWL_ASSUME) { + opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); + return; + } + /* we try to correct */ + totlen = 0; + opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n" + "- setting Psot to %d => assuming it is the last tile\n", + totlen); + } + + } + else +#endif /* USE_JPWL */ + { + /* totlen is negative or larger than the bytes left!!! */ + if ((totlen < 0) || (totlen > (cio_numbytesleft(cio) + 8))) { + opj_event_msg(j2k->cinfo, EVT_ERROR, + "JPWL: bad tile byte size (%d bytes against %d bytes left)\n", + totlen, cio_numbytesleft(cio) + 8); + return; + } + } + + if (!totlen) + totlen = cio_numbytesleft(cio) + 8; + + partno = cio_read(cio, 1); + numparts = cio_read(cio, 1); + + if (partno >= numparts) { + opj_event_msg(j2k->cinfo, EVT_WARNING, "SOT marker inconsistency in tile %d: tile-part index greater (%d) than number of tile-parts (%d)\n", tileno, partno, numparts); + numparts = partno+1; + } + + j2k->curtileno = tileno; + j2k->cur_tp_num = partno; + j2k->eot = cio_getbp(cio) - 12 + totlen; + j2k->state = J2K_STATE_TPH; + tcp = &cp->tcps[j2k->curtileno]; + + /* Index */ + if (j2k->cstr_info) { + if (tcp->first) { + if (tileno == 0) + j2k->cstr_info->main_head_end = cio_tell(cio) - 13; + j2k->cstr_info->tile[tileno].tileno = tileno; + j2k->cstr_info->tile[tileno].start_pos = cio_tell(cio) - 12; + j2k->cstr_info->tile[tileno].end_pos = j2k->cstr_info->tile[tileno].start_pos + totlen - 1; + } else { + j2k->cstr_info->tile[tileno].end_pos += totlen; + } + j2k->cstr_info->tile[tileno].num_tps = numparts; + if (numparts) + j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_realloc(j2k->cstr_info->tile[tileno].tp, numparts * sizeof(opj_tp_info_t)); + else + j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_realloc(j2k->cstr_info->tile[tileno].tp, 10 * sizeof(opj_tp_info_t)); /* Fixme (10)*/ + j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos = cio_tell(cio) - 12; + j2k->cstr_info->tile[tileno].tp[partno].tp_end_pos = + j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos + totlen - 1; + } + + if (tcp->first == 1) { + /* Initialization PPT */ + opj_tccp_t *tmp = tcp->tccps; + memcpy(tcp, j2k->default_tcp, sizeof(opj_tcp_t)); + tcp->ppt = 0; + tcp->ppt_data = NULL; + tcp->ppt_data_first = NULL; + tcp->tccps = tmp; + + for (i = 0; i < j2k->image->numcomps; i++) { + tcp->tccps[i] = j2k->default_tcp->tccps[i]; + } + cp->tcps[j2k->curtileno].first = 0; + } +} + +static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder) { + int l, layno; + int totlen; + opj_tcp_t *tcp = NULL; + opj_codestream_info_t *cstr_info = NULL; + + opj_tcd_t *tcd = (opj_tcd_t*)tile_coder; /* cast is needed because of conflicts in header inclusions */ + opj_cp_t *cp = j2k->cp; + opj_cio_t *cio = j2k->cio; + + tcd->tp_num = j2k->tp_num ; + tcd->cur_tp_num = j2k->cur_tp_num; + + cio_write(cio, J2K_MS_SOD, 2); + + if( j2k->cstr_info && j2k->cur_tp_num==0){ + j2k_add_tlmarker( j2k->curtileno, j2k->cstr_info, J2K_MS_SOD, cio_tell(cio), 0); + } + + if (j2k->curtileno == 0) { + j2k->sod_start = cio_tell(cio) + j2k->pos_correction; + } + + /* INDEX >> */ + cstr_info = j2k->cstr_info; + if (cstr_info) { + if (!j2k->cur_tp_num ) { + cstr_info->tile[j2k->curtileno].end_header = cio_tell(cio) + j2k->pos_correction - 1; + j2k->cstr_info->tile[j2k->curtileno].tileno = j2k->curtileno; + } + else{ + if(cstr_info->tile[j2k->curtileno].packet[cstr_info->packno - 1].end_pos < cio_tell(cio)) + cstr_info->tile[j2k->curtileno].packet[cstr_info->packno].start_pos = cio_tell(cio); + } + /* UniPG>> */ +#ifdef USE_JPWL + /* update markers struct */ + j2k_add_marker(j2k->cstr_info, J2K_MS_SOD, j2k->sod_start, 2); +#endif /* USE_JPWL */ + /* <tcps[j2k->curtileno]; + for (layno = 0; layno < tcp->numlayers; layno++) { + if (tcp->rates[layno]>(j2k->sod_start / (cp->th * cp->tw))) { + tcp->rates[layno]-=(j2k->sod_start / (cp->th * cp->tw)); + } else if (tcp->rates[layno]) { + tcp->rates[layno]=1; + } + } + if(j2k->cur_tp_num == 0){ + tcd->tcd_image->tiles->packno = 0; + if(cstr_info) + cstr_info->packno = 0; + } + + l = tcd_encode_tile(tcd, j2k->curtileno, cio_getbp(cio), cio_numbytesleft(cio) - 2, cstr_info); + + /* Writing Psot in SOT marker */ + totlen = cio_tell(cio) + l - j2k->sot_start; + cio_seek(cio, j2k->sot_start + 6); + cio_write(cio, totlen, 4); + cio_seek(cio, j2k->sot_start + totlen); + /* Writing Ttlm and Ptlm in TLM marker */ + if(cp->cinema){ + cio_seek(cio, j2k->tlm_start + 6 + (5*j2k->cur_tp_num)); + cio_write(cio, j2k->curtileno, 1); + cio_write(cio, totlen, 4); + } + cio_seek(cio, j2k->sot_start + totlen); +} + +static void j2k_read_sod(opj_j2k_t *j2k) { + int len, truncate = 0, i; + unsigned char *data = NULL, *data_ptr = NULL; + + opj_cio_t *cio = j2k->cio; + int curtileno = j2k->curtileno; + + /* Index */ + if (j2k->cstr_info) { + j2k->cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_end_header = + cio_tell(cio) + j2k->pos_correction - 1; + if (j2k->cur_tp_num == 0) + j2k->cstr_info->tile[j2k->curtileno].end_header = cio_tell(cio) + j2k->pos_correction - 1; + j2k->cstr_info->packno = 0; + } + + len = int_min(j2k->eot - cio_getbp(cio), cio_numbytesleft(cio) + 1); + + if (len == cio_numbytesleft(cio) + 1) { + truncate = 1; /* Case of a truncate codestream */ + } + + {/* chop padding bytes: */ + unsigned char *s, *e; + + s = cio_getbp(cio); + e = s + len; + + if(len > 8) s = e - 8; + + if(e[-2] == 0x00 && e[-1] == 0x00) /* padding bytes */ + { + while(e > s) + { + if(e[-2] == 0xff && e[-1] == 0xd9) break; + --len; --e; truncate = 1; + } + } + } + + data = j2k->tile_data[curtileno]; + data = (unsigned char*) opj_realloc(data, (j2k->tile_len[curtileno] + len) * sizeof(unsigned char)); + + data_ptr = data + j2k->tile_len[curtileno]; + for (i = 0; i < len; i++) { + data_ptr[i] = cio_read(cio, 1); + } + + j2k->tile_len[curtileno] += len; + j2k->tile_data[curtileno] = data; + + if (!truncate) { + j2k->state = J2K_STATE_TPHSOT; + } else { + j2k->state = J2K_STATE_NEOC; /* RAJOUTE !! */ + } + j2k->cur_tp_num++; +} + +static void j2k_write_rgn(opj_j2k_t *j2k, int compno, int tileno) { + opj_cp_t *cp = j2k->cp; + opj_tcp_t *tcp = &cp->tcps[tileno]; + opj_cio_t *cio = j2k->cio; + int numcomps = j2k->image->numcomps; + + cio_write(cio, J2K_MS_RGN, 2); /* RGN */ + cio_write(cio, numcomps <= 256 ? 5 : 6, 2); /* Lrgn */ + cio_write(cio, compno, numcomps <= 256 ? 1 : 2); /* Crgn */ + cio_write(cio, 0, 1); /* Srgn */ + cio_write(cio, tcp->tccps[compno].roishift, 1); /* SPrgn */ +} + +static void j2k_read_rgn(opj_j2k_t *j2k) { + int len, compno, roisty; + + opj_cp_t *cp = j2k->cp; + opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp; + opj_cio_t *cio = j2k->cio; + int numcomps = j2k->image->numcomps; + + len = cio_read(cio, 2); /* Lrgn */ + compno = cio_read(cio, numcomps <= 256 ? 1 : 2); /* Crgn */ + roisty = cio_read(cio, 1); /* Srgn */ + +#ifdef USE_JPWL + if (j2k->cp->correct) { + /* totlen is negative or larger than the bytes left!!! */ + if (compno >= numcomps) { + opj_event_msg(j2k->cinfo, EVT_ERROR, + "JPWL: bad component number in RGN (%d when there are only %d)\n", + compno, numcomps); + if (!JPWL_ASSUME || JPWL_ASSUME) { + opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n"); + return; + } + } + }; +#endif /* USE_JPWL */ + + tcp->tccps[compno].roishift = cio_read(cio, 1); /* SPrgn */ +} + +static void j2k_write_eoc(opj_j2k_t *j2k) { + opj_cio_t *cio = j2k->cio; + /* opj_event_msg(j2k->cinfo, "%.8x: EOC\n", cio_tell(cio) + j2k->pos_correction); */ + cio_write(cio, J2K_MS_EOC, 2); + +/* UniPG>> */ +#ifdef USE_JPWL + /* update markers struct */ + j2k_add_marker(j2k->cstr_info, J2K_MS_EOC, cio_tell(cio) - 2, 2); +#endif /* USE_JPWL */ +/* <cp->limit_decoding != DECODE_ALL_BUT_PACKETS) { + opj_tcd_t *tcd = tcd_create(j2k->cinfo); + tcd_malloc_decode(tcd, j2k->image, j2k->cp); + for (i = 0; i < j2k->cp->tileno_size; i++) { + tcd_malloc_decode_tile(tcd, j2k->image, j2k->cp, i, j2k->cstr_info); + if (j2k->cp->tileno[i] != -1) + { + tileno = j2k->cp->tileno[i]; + success = tcd_decode_tile(tcd, j2k->tile_data[tileno], j2k->tile_len[tileno], tileno, j2k->cstr_info); + opj_free(j2k->tile_data[tileno]); + j2k->tile_data[tileno] = NULL; + tcd_free_decode_tile(tcd, i); + } + else + success = OPJ_FALSE; + if (success == OPJ_FALSE) { + j2k->state |= J2K_STATE_ERR; + break; + } + } + tcd_free_decode(tcd); + tcd_destroy(tcd); + } + /* if packets should not be decoded */ + else { + for (i = 0; i < j2k->cp->tileno_size; i++) { + tileno = j2k->cp->tileno[i]; + opj_free(j2k->tile_data[tileno]); + j2k->tile_data[tileno] = NULL; + } + } + if (j2k->state & J2K_STATE_ERR) + j2k->state = J2K_STATE_MT + J2K_STATE_ERR; + else + j2k->state = J2K_STATE_MT; +} + +typedef struct opj_dec_mstabent { + /** marker value */ + int id; + /** value of the state when the marker can appear */ + int states; + /** action linked to the marker */ + void (*handler) (opj_j2k_t *j2k); +} opj_dec_mstabent_t; + +opj_dec_mstabent_t j2k_dec_mstab[] = { + {J2K_MS_SOC, J2K_STATE_MHSOC, j2k_read_soc}, + {J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, j2k_read_sot}, + {J2K_MS_SOD, J2K_STATE_TPH, j2k_read_sod}, + {J2K_MS_EOC, J2K_STATE_TPHSOT, j2k_read_eoc}, + {J2K_MS_SIZ, J2K_STATE_MHSIZ, j2k_read_siz}, + {J2K_MS_COD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_cod}, + {J2K_MS_COC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_coc}, + {J2K_MS_RGN, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_rgn}, + {J2K_MS_QCD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_qcd}, + {J2K_MS_QCC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_qcc}, + {J2K_MS_POC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_poc}, + {J2K_MS_TLM, J2K_STATE_MH, j2k_read_tlm}, + {J2K_MS_PLM, J2K_STATE_MH, j2k_read_plm}, + {J2K_MS_PLT, J2K_STATE_TPH, j2k_read_plt}, + {J2K_MS_PPM, J2K_STATE_MH, j2k_read_ppm}, + {J2K_MS_PPT, J2K_STATE_TPH, j2k_read_ppt}, + {J2K_MS_SOP, 0, 0}, + {J2K_MS_CRG, J2K_STATE_MH, j2k_read_crg}, + {J2K_MS_COM, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_com}, + +#ifdef USE_JPWL + {J2K_MS_EPC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_epc}, + {J2K_MS_EPB, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_epb}, + {J2K_MS_ESD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_esd}, + {J2K_MS_RED, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_red}, +#endif /* USE_JPWL */ +#ifdef USE_JPSEC + {J2K_MS_SEC, J2K_STATE_MH, j2k_read_sec}, + {J2K_MS_INSEC, 0, j2k_read_insec}, +#endif /* USE_JPSEC */ + + {0, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_unk} +}; + +static void j2k_read_unk(opj_j2k_t *j2k) { + opj_event_msg(j2k->cinfo, EVT_WARNING, "Unknown marker\n"); + +#ifdef USE_JPWL + if (j2k->cp->correct) { + int m = 0, id, i; + int min_id = 0, min_dist = 17, cur_dist = 0, tmp_id; + cio_seek(j2k->cio, cio_tell(j2k->cio) - 2); + id = cio_read(j2k->cio, 2); + opj_event_msg(j2k->cinfo, EVT_ERROR, + "JPWL: really don't know this marker %x\n", + id); + if (!JPWL_ASSUME) { + opj_event_msg(j2k->cinfo, EVT_ERROR, + "- possible synch loss due to uncorrectable codestream errors => giving up\n"); + return; + } + /* OK, activate this at your own risk!!! */ + /* we look for the marker at the minimum hamming distance from this */ + while (j2k_dec_mstab[m].id) { + + /* 1's where they differ */ + tmp_id = j2k_dec_mstab[m].id ^ id; + + /* compute the hamming distance between our id and the current */ + cur_dist = 0; + for (i = 0; i < 16; i++) { + if ((tmp_id >> i) & 0x0001) { + cur_dist++; + } + } + + /* if current distance is smaller, set the minimum */ + if (cur_dist < min_dist) { + min_dist = cur_dist; + min_id = j2k_dec_mstab[m].id; + } + + /* jump to the next marker */ + m++; + } + + /* do we substitute the marker? */ + if (min_dist < JPWL_MAXIMUM_HAMMING) { + opj_event_msg(j2k->cinfo, EVT_ERROR, + "- marker %x is at distance %d from the read %x\n", + min_id, min_dist, id); + opj_event_msg(j2k->cinfo, EVT_ERROR, + "- trying to substitute in place and crossing fingers!\n"); + cio_seek(j2k->cio, cio_tell(j2k->cio) - 2); + cio_write(j2k->cio, min_id, 2); + + /* rewind */ + cio_seek(j2k->cio, cio_tell(j2k->cio) - 2); + + } + + }; +#endif /* USE_JPWL */ + +} + +/** +Read the lookup table containing all the marker, status and action +@param id Marker value +*/ +static opj_dec_mstabent_t *j2k_dec_mstab_lookup(int id) { + opj_dec_mstabent_t *e; + for (e = j2k_dec_mstab; e->id != 0; e++) { + if (e->id == id) { + break; + } + } + return e; +} + +/* ----------------------------------------------------------------------- */ +/* J2K / JPT decoder interface */ +/* ----------------------------------------------------------------------- */ + +opj_j2k_t* j2k_create_decompress(opj_common_ptr cinfo) { + opj_j2k_t *j2k = (opj_j2k_t*) opj_calloc(1, sizeof(opj_j2k_t)); + if(!j2k) + return NULL; + + j2k->default_tcp = (opj_tcp_t*) opj_calloc(1, sizeof(opj_tcp_t)); + if(!j2k->default_tcp) { + opj_free(j2k); + return NULL; + } + + j2k->cinfo = cinfo; + j2k->tile_data = NULL; + + return j2k; +} + +void j2k_destroy_decompress(opj_j2k_t *j2k) { + int i = 0; + + if(j2k->tile_len != NULL) { + opj_free(j2k->tile_len); + } + if(j2k->tile_data != NULL) { + if(j2k->cp != NULL) { + for (i = 0; i < j2k->cp->tileno_size; i++) { + int tileno = j2k->cp->tileno[i]; + opj_free(j2k->tile_data[tileno]); + j2k->tile_data[tileno] = NULL; + } + } + + opj_free(j2k->tile_data); + } + if(j2k->default_tcp != NULL) { + opj_tcp_t *default_tcp = j2k->default_tcp; + if(default_tcp->ppt_data_first != NULL) { + opj_free(default_tcp->ppt_data_first); + } + if(j2k->default_tcp->tccps != NULL) { + opj_free(j2k->default_tcp->tccps); + } + opj_free(j2k->default_tcp); + } + if(j2k->cp != NULL) { + opj_cp_t *cp = j2k->cp; + if(cp->tcps != NULL) { + for(i = 0; i < cp->tw * cp->th; i++) { + if(cp->tcps[i].ppt_data_first != NULL) { + opj_free(cp->tcps[i].ppt_data_first); + } + if(cp->tcps[i].tccps != NULL) { + opj_free(cp->tcps[i].tccps); + } + } + opj_free(cp->tcps); + } + if(cp->ppm_data_first != NULL) { + opj_free(cp->ppm_data_first); + } + if(cp->tileno != NULL) { + opj_free(cp->tileno); + } + if(cp->comment != NULL) { + opj_free(cp->comment); + } + + opj_free(cp); + } + opj_free(j2k); +} + +void j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters) { + if(j2k && parameters) { + /* create and initialize the coding parameters structure */ + opj_cp_t *cp = (opj_cp_t*) opj_calloc(1, sizeof(opj_cp_t)); + cp->reduce = parameters->cp_reduce; + cp->layer = parameters->cp_layer; + cp->limit_decoding = parameters->cp_limit_decoding; + +#ifdef USE_JPWL + cp->correct = parameters->jpwl_correct; + cp->exp_comps = parameters->jpwl_exp_comps; + cp->max_tiles = parameters->jpwl_max_tiles; +#endif /* USE_JPWL */ + + + /* keep a link to cp so that we can destroy it later in j2k_destroy_decompress */ + j2k->cp = cp; + } +} + +opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info) { + opj_image_t *image = NULL; + + opj_common_ptr cinfo = j2k->cinfo; + + j2k->cio = cio; + j2k->cstr_info = cstr_info; + if (cstr_info) + memset(cstr_info, 0, sizeof(opj_codestream_info_t)); + + /* create an empty image */ + image = opj_image_create0(); + j2k->image = image; + + j2k->state = J2K_STATE_MHSOC; + + for (;;) { + opj_dec_mstabent_t *e; + int id = cio_read(cio, 2); + +#ifdef USE_JPWL + /* we try to honor JPWL correction power */ + if (j2k->cp->correct) { + + int orig_pos = cio_tell(cio); + opj_bool status; + + /* call the corrector */ + status = jpwl_correct(j2k); + + /* go back to where you were */ + cio_seek(cio, orig_pos - 2); + + /* re-read the marker */ + id = cio_read(cio, 2); + + /* check whether it begins with ff */ + if (id >> 8 != 0xff) { + opj_event_msg(cinfo, EVT_ERROR, + "JPWL: possible bad marker %x at %d\n", + id, cio_tell(cio) - 2); + if (!JPWL_ASSUME) { + opj_image_destroy(image); + opj_event_msg(cinfo, EVT_ERROR, "JPWL: giving up\n"); + return 0; + } + /* we try to correct */ + id = id | 0xff00; + cio_seek(cio, cio_tell(cio) - 2); + cio_write(cio, id, 2); + opj_event_msg(cinfo, EVT_WARNING, "- trying to adjust this\n" + "- setting marker to %x\n", + id); + } + + } +#endif /* USE_JPWL */ + + if (id >> 8 != 0xff) { + if(cio_numbytesleft(cio) != 0) /* not end of file reached and no EOC */ + { + opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id); + opj_image_destroy(image); + return 0; + } + opj_event_msg(cinfo, EVT_WARNING, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id); + j2k->state = J2K_STATE_NEOC; + break; + } + e = j2k_dec_mstab_lookup(id); + /* Check if the marker is known*/ + if (!(j2k->state & e->states)) { + opj_image_destroy(image); + opj_event_msg(cinfo, EVT_ERROR, "%.8x: unexpected marker %x\n", cio_tell(cio) - 2, id); + return 0; + } + /* Check if the decoding is limited to the main header*/ + if (e->id == J2K_MS_SOT && j2k->cp->limit_decoding == LIMIT_TO_MAIN_HEADER) { + opj_event_msg(cinfo, EVT_INFO, "Main Header decoded.\n"); + return image; + } + + if (e->handler) { + (*e->handler)(j2k); + } + if (j2k->state & J2K_STATE_ERR) + { + opj_image_destroy(image); + return NULL; + } + + if (j2k->state == J2K_STATE_MT) { + break; + } + if (j2k->state == J2K_STATE_NEOC) { + break; + } + } + if (j2k->state == J2K_STATE_NEOC) { + j2k_read_eoc(j2k); + } + + if (j2k->state != J2K_STATE_MT) { + opj_event_msg(cinfo, EVT_WARNING, "Incomplete bitstream\n"); + } + return image; +} + +/* +* Read a JPT-stream and decode file +* +*/ +opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info) { + opj_image_t *image = NULL; + opj_jpt_msg_header_t header; + int position; + opj_common_ptr cinfo = j2k->cinfo; + + OPJ_ARG_NOT_USED(cstr_info); + + j2k->cio = cio; + + /* create an empty image */ + image = opj_image_create0(); + j2k->image = image; + + j2k->state = J2K_STATE_MHSOC; + + /* Initialize the header */ + jpt_init_msg_header(&header); + /* Read the first header of the message */ + jpt_read_msg_header(cinfo, cio, &header); + + position = cio_tell(cio); + if (header.Class_Id != 6) { /* 6 : Main header data-bin message */ + opj_image_destroy(image); + opj_event_msg(cinfo, EVT_ERROR, "[JPT-stream] : Expecting Main header first [class_Id %d] !\n", header.Class_Id); + return 0; + } + + for (;;) { + opj_dec_mstabent_t *e = NULL; + int id; + + if (!cio_numbytesleft(cio)) { + j2k_read_eoc(j2k); + return image; + } + /* data-bin read -> need to read a new header */ + if ((unsigned int) (cio_tell(cio) - position) == header.Msg_length) { + jpt_read_msg_header(cinfo, cio, &header); + position = cio_tell(cio); + if (header.Class_Id != 4) { /* 4 : Tile data-bin message */ + opj_image_destroy(image); + opj_event_msg(cinfo, EVT_ERROR, "[JPT-stream] : Expecting Tile info !\n"); + return 0; + } + } + + id = cio_read(cio, 2); + if (id >> 8 != 0xff) { + if(cio_numbytesleft(cio) != 0) /* no end of file reached and no EOC */ + { + opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id); + opj_image_destroy(image); + return 0; + } + opj_event_msg(cinfo, EVT_WARNING, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id); + j2k->state = J2K_STATE_NEOC; + break; + } + e = j2k_dec_mstab_lookup(id); + if (!(j2k->state & e->states)) { + opj_image_destroy(image); + opj_event_msg(cinfo, EVT_ERROR, "%.8x: unexpected marker %x\n", cio_tell(cio) - 2, id); + return 0; + } + if (e->handler) { + (*e->handler)(j2k); + } + if (j2k->state == J2K_STATE_MT) { + break; + } + if (j2k->state == J2K_STATE_NEOC) { + break; + } + } + if (j2k->state == J2K_STATE_NEOC) { + j2k_read_eoc(j2k); + } + + if (j2k->state != J2K_STATE_MT) { + opj_event_msg(cinfo, EVT_WARNING, "Incomplete bitstream\n"); + } + + return image; +} + +/* ----------------------------------------------------------------------- */ +/* J2K encoder interface */ +/* ----------------------------------------------------------------------- */ + +opj_j2k_t* j2k_create_compress(opj_common_ptr cinfo) { + opj_j2k_t *j2k = (opj_j2k_t*) opj_calloc(1, sizeof(opj_j2k_t)); + if(j2k) { + j2k->cinfo = cinfo; + } + return j2k; +} + +void j2k_destroy_compress(opj_j2k_t *j2k) { + int tileno; + + if(!j2k) return; + if(j2k->cp != NULL) { + opj_cp_t *cp = j2k->cp; + + if(cp->comment) { + opj_free(cp->comment); + } + if(cp->matrice) { + opj_free(cp->matrice); + } + for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { + opj_free(cp->tcps[tileno].tccps); + } + opj_free(cp->tcps); + opj_free(cp); + } + + opj_free(j2k); +} + +void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_t *image) { + int i, j, tileno, numpocs_tile; + opj_cp_t *cp = NULL; + + if(!j2k || !parameters || ! image) { + return; + } + + /* create and initialize the coding parameters structure */ + cp = (opj_cp_t*) opj_calloc(1, sizeof(opj_cp_t)); + + /* keep a link to cp so that we can destroy it later in j2k_destroy_compress */ + j2k->cp = cp; + + /* set default values for cp */ + cp->tw = 1; + cp->th = 1; + + /* + copy user encoding parameters + */ + cp->cinema = parameters->cp_cinema; + cp->max_comp_size = parameters->max_comp_size; + cp->rsiz = parameters->cp_rsiz; + cp->disto_alloc = parameters->cp_disto_alloc; + cp->fixed_alloc = parameters->cp_fixed_alloc; + cp->fixed_quality = parameters->cp_fixed_quality; + + /* mod fixed_quality */ + if(parameters->cp_matrice) { + size_t array_size = parameters->tcp_numlayers * parameters->numresolution * 3 * sizeof(int); + cp->matrice = (int *) opj_malloc(array_size); + memcpy(cp->matrice, parameters->cp_matrice, array_size); + } + + /* tiles */ + cp->tdx = parameters->cp_tdx; + cp->tdy = parameters->cp_tdy; + + /* tile offset */ + cp->tx0 = parameters->cp_tx0; + cp->ty0 = parameters->cp_ty0; + + /* comment string */ + if(parameters->cp_comment) { + cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1); + if(cp->comment) { + strcpy(cp->comment, parameters->cp_comment); + } + } + + /* + calculate other encoding parameters + */ + + if (parameters->tile_size_on) { + cp->tw = int_ceildiv(image->x1 - cp->tx0, cp->tdx); + cp->th = int_ceildiv(image->y1 - cp->ty0, cp->tdy); + } else { + cp->tdx = image->x1 - cp->tx0; + cp->tdy = image->y1 - cp->ty0; + } + + if(parameters->tp_on){ + cp->tp_flag = parameters->tp_flag; + cp->tp_on = 1; + } + + cp->img_size = 0; + for(i=0;inumcomps ;i++){ + cp->img_size += (image->comps[i].w *image->comps[i].h * image->comps[i].prec); + } + + +#ifdef USE_JPWL + /* + calculate JPWL encoding parameters + */ + + if (parameters->jpwl_epc_on) { + int i; + + /* set JPWL on */ + cp->epc_on = OPJ_TRUE; + cp->info_on = OPJ_FALSE; /* no informative technique */ + + /* set EPB on */ + if ((parameters->jpwl_hprot_MH > 0) || (parameters->jpwl_hprot_TPH[0] > 0)) { + cp->epb_on = OPJ_TRUE; + + cp->hprot_MH = parameters->jpwl_hprot_MH; + for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) { + cp->hprot_TPH_tileno[i] = parameters->jpwl_hprot_TPH_tileno[i]; + cp->hprot_TPH[i] = parameters->jpwl_hprot_TPH[i]; + } + /* if tile specs are not specified, copy MH specs */ + if (cp->hprot_TPH[0] == -1) { + cp->hprot_TPH_tileno[0] = 0; + cp->hprot_TPH[0] = parameters->jpwl_hprot_MH; + } + for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) { + cp->pprot_tileno[i] = parameters->jpwl_pprot_tileno[i]; + cp->pprot_packno[i] = parameters->jpwl_pprot_packno[i]; + cp->pprot[i] = parameters->jpwl_pprot[i]; + } + } + + /* set ESD writing */ + if ((parameters->jpwl_sens_size == 1) || (parameters->jpwl_sens_size == 2)) { + cp->esd_on = OPJ_TRUE; + + cp->sens_size = parameters->jpwl_sens_size; + cp->sens_addr = parameters->jpwl_sens_addr; + cp->sens_range = parameters->jpwl_sens_range; + + cp->sens_MH = parameters->jpwl_sens_MH; + for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) { + cp->sens_TPH_tileno[i] = parameters->jpwl_sens_TPH_tileno[i]; + cp->sens_TPH[i] = parameters->jpwl_sens_TPH[i]; + } + } + + /* always set RED writing to false: we are at the encoder */ + cp->red_on = OPJ_FALSE; + + } else { + cp->epc_on = OPJ_FALSE; + } +#endif /* USE_JPWL */ + + + /* initialize the mutiple tiles */ + /* ---------------------------- */ + cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t)); + + for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { + opj_tcp_t *tcp = &cp->tcps[tileno]; + tcp->numlayers = parameters->tcp_numlayers; + for (j = 0; j < tcp->numlayers; j++) { + if(cp->cinema){ + if (cp->fixed_quality) { + tcp->distoratio[j] = parameters->tcp_distoratio[j]; + } + tcp->rates[j] = parameters->tcp_rates[j]; + }else{ + if (cp->fixed_quality) { /* add fixed_quality */ + tcp->distoratio[j] = parameters->tcp_distoratio[j]; + } else { + tcp->rates[j] = parameters->tcp_rates[j]; + } + } + } + tcp->csty = parameters->csty; + tcp->prg = parameters->prog_order; + tcp->mct = parameters->tcp_mct; + + numpocs_tile = 0; + tcp->POC = 0; + if (parameters->numpocs) { + /* initialisation of POC */ + tcp->POC = 1; + for (i = 0; i < parameters->numpocs; i++) { + if((tileno == parameters->POC[i].tile - 1) || (parameters->POC[i].tile == -1)) { + opj_poc_t *tcp_poc = &tcp->pocs[numpocs_tile]; + tcp_poc->resno0 = parameters->POC[numpocs_tile].resno0; + tcp_poc->compno0 = parameters->POC[numpocs_tile].compno0; + tcp_poc->layno1 = parameters->POC[numpocs_tile].layno1; + tcp_poc->resno1 = parameters->POC[numpocs_tile].resno1; + tcp_poc->compno1 = parameters->POC[numpocs_tile].compno1; + tcp_poc->prg1 = parameters->POC[numpocs_tile].prg1; + tcp_poc->tile = parameters->POC[numpocs_tile].tile; + numpocs_tile++; + } + } + tcp->numpocs = numpocs_tile -1 ; + }else{ + tcp->numpocs = 0; + } + + tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t)); + + for (i = 0; i < image->numcomps; i++) { + opj_tccp_t *tccp = &tcp->tccps[i]; + tccp->csty = parameters->csty & 0x01; /* 0 => one precinct || 1 => custom precinct */ + tccp->numresolutions = parameters->numresolution; + tccp->cblkw = int_floorlog2(parameters->cblockw_init); + tccp->cblkh = int_floorlog2(parameters->cblockh_init); + tccp->cblksty = parameters->mode; + tccp->qmfbid = parameters->irreversible ? 0 : 1; + tccp->qntsty = parameters->irreversible ? J2K_CCP_QNTSTY_SEQNT : J2K_CCP_QNTSTY_NOQNT; + tccp->numgbits = 2; + if (i == parameters->roi_compno) { + tccp->roishift = parameters->roi_shift; + } else { + tccp->roishift = 0; + } + + if(parameters->cp_cinema) + { + /*Precinct size for lowest frequency subband=128*/ + tccp->prcw[0] = 7; + tccp->prch[0] = 7; + /*Precinct size at all other resolutions = 256*/ + for (j = 1; j < tccp->numresolutions; j++) { + tccp->prcw[j] = 8; + tccp->prch[j] = 8; + } + }else{ + if (parameters->csty & J2K_CCP_CSTY_PRT) { + int p = 0; + for (j = tccp->numresolutions - 1; j >= 0; j--) { + if (p < parameters->res_spec) { + + if (parameters->prcw_init[p] < 1) { + tccp->prcw[j] = 1; + } else { + tccp->prcw[j] = int_floorlog2(parameters->prcw_init[p]); + } + + if (parameters->prch_init[p] < 1) { + tccp->prch[j] = 1; + }else { + tccp->prch[j] = int_floorlog2(parameters->prch_init[p]); + } + + } else { + int res_spec = parameters->res_spec; + int size_prcw = parameters->prcw_init[res_spec - 1] >> (p - (res_spec - 1)); + int size_prch = parameters->prch_init[res_spec - 1] >> (p - (res_spec - 1)); + + if (size_prcw < 1) { + tccp->prcw[j] = 1; + } else { + tccp->prcw[j] = int_floorlog2(size_prcw); + } + + if (size_prch < 1) { + tccp->prch[j] = 1; + } else { + tccp->prch[j] = int_floorlog2(size_prch); + } + } + p++; + /*printf("\nsize precinct for level %d : %d,%d\n", j,tccp->prcw[j], tccp->prch[j]); */ + } /*end for*/ + } else { + for (j = 0; j < tccp->numresolutions; j++) { + tccp->prcw[j] = 15; + tccp->prch[j] = 15; + } + } + } + + dwt_calc_explicit_stepsizes(tccp, image->comps[i].prec); + } + } +} + +opj_bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) { + int tileno, compno; + opj_cp_t *cp = NULL; + + opj_tcd_t *tcd = NULL; /* TCD component */ + + j2k->cio = cio; + j2k->image = image; + + cp = j2k->cp; + + /* INDEX >> */ + j2k->cstr_info = cstr_info; + if (cstr_info) { + int compno; + cstr_info->tile = (opj_tile_info_t *) opj_malloc(cp->tw * cp->th * sizeof(opj_tile_info_t)); + cstr_info->image_w = image->x1 - image->x0; + cstr_info->image_h = image->y1 - image->y0; + cstr_info->prog = (&cp->tcps[0])->prg; + cstr_info->tw = cp->tw; + cstr_info->th = cp->th; + cstr_info->tile_x = cp->tdx; /* new version parser */ + cstr_info->tile_y = cp->tdy; /* new version parser */ + cstr_info->tile_Ox = cp->tx0; /* new version parser */ + cstr_info->tile_Oy = cp->ty0; /* new version parser */ + cstr_info->numcomps = image->numcomps; + cstr_info->numlayers = (&cp->tcps[0])->numlayers; + cstr_info->numdecompos = (int*) opj_malloc(image->numcomps * sizeof(int)); + for (compno=0; compno < image->numcomps; compno++) { + cstr_info->numdecompos[compno] = (&cp->tcps[0])->tccps->numresolutions - 1; + } + cstr_info->D_max = 0.0; /* ADD Marcela */ + cstr_info->main_head_start = cio_tell(cio); /* position of SOC */ + cstr_info->maxmarknum = 100; + cstr_info->marker = (opj_marker_info_t *) opj_malloc(cstr_info->maxmarknum * sizeof(opj_marker_info_t)); + cstr_info->marknum = 0; + } + /* << INDEX */ + + j2k_write_soc(j2k); + j2k_write_siz(j2k); + j2k_write_cod(j2k); + j2k_write_qcd(j2k); + + if(cp->cinema){ + for (compno = 1; compno < image->numcomps; compno++) { + j2k_write_coc(j2k, compno); + j2k_write_qcc(j2k, compno); + } + } + + for (compno = 0; compno < image->numcomps; compno++) { + opj_tcp_t *tcp = &cp->tcps[0]; + if (tcp->tccps[compno].roishift) + j2k_write_rgn(j2k, compno, 0); + } + if (cp->comment != NULL) { + j2k_write_com(j2k); + } + + j2k->totnum_tp = j2k_calculate_tp(cp,image->numcomps,image,j2k); + /* TLM Marker*/ + if(cp->cinema){ + j2k_write_tlm(j2k); + if (cp->cinema == CINEMA4K_24) { + j2k_write_poc(j2k); + } + } + + /* uncomment only for testing JPSEC marker writing */ + /* j2k_write_sec(j2k); */ + + /* INDEX >> */ + if(cstr_info) { + cstr_info->main_head_end = cio_tell(cio) - 1; + } + /* << INDEX */ + /**** Main Header ENDS here ***/ + + /* create the tile encoder */ + tcd = tcd_create(j2k->cinfo); + + /* encode each tile */ + for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { + int pino; + int tilepartno=0; + /* UniPG>> */ + int acc_pack_num = 0; + /* <tcps[tileno]; + opj_event_msg(j2k->cinfo, EVT_INFO, "tile number %d / %d\n", tileno + 1, cp->tw * cp->th); + + j2k->curtileno = tileno; + j2k->cur_tp_num = 0; + tcd->cur_totnum_tp = j2k->cur_totnum_tp[j2k->curtileno]; + /* initialisation before tile encoding */ + if (tileno == 0) { + tcd_malloc_encode(tcd, image, cp, j2k->curtileno); + } else { + tcd_init_encode(tcd, image, cp, j2k->curtileno); + } + + /* INDEX >> */ + if(cstr_info) { + cstr_info->tile[j2k->curtileno].start_pos = cio_tell(cio) + j2k->pos_correction; + cstr_info->tile[j2k->curtileno].maxmarknum = 10; + cstr_info->tile[j2k->curtileno].marker = (opj_marker_info_t *) opj_malloc(cstr_info->tile[j2k->curtileno].maxmarknum * sizeof(opj_marker_info_t)); + cstr_info->tile[j2k->curtileno].marknum = 0; + } + /* << INDEX */ + + for(pino = 0; pino <= tcp->numpocs; pino++) { + int tot_num_tp; + tcd->cur_pino=pino; + + /*Get number of tile parts*/ + tot_num_tp = j2k_get_num_tp(cp,pino,tileno); + tcd->tp_pos = cp->tp_pos; + + for(tilepartno = 0; tilepartno < tot_num_tp ; tilepartno++){ + j2k->tp_num = tilepartno; + /* INDEX >> */ + if(cstr_info) + cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_start_pos = + cio_tell(cio) + j2k->pos_correction; + /* << INDEX */ + j2k_write_sot(j2k); + + if(j2k->cur_tp_num == 0 && cp->cinema == 0){ + for (compno = 1; compno < image->numcomps; compno++) { + j2k_write_coc(j2k, compno); + j2k_write_qcc(j2k, compno); + } + if (cp->tcps[tileno].numpocs) { + j2k_write_poc(j2k); + } + } + + /* INDEX >> */ + if(cstr_info) + cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_end_header = + cio_tell(cio) + j2k->pos_correction + 1; + /* << INDEX */ + + j2k_write_sod(j2k, tcd); + + /* INDEX >> */ + if(cstr_info) { + cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_end_pos = + cio_tell(cio) + j2k->pos_correction - 1; + cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_start_pack = + acc_pack_num; + cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_numpacks = + cstr_info->packno - acc_pack_num; + acc_pack_num = cstr_info->packno; + } + /* << INDEX */ + + j2k->cur_tp_num++; + } + } + if(cstr_info) { + cstr_info->tile[j2k->curtileno].end_pos = cio_tell(cio) + j2k->pos_correction - 1; + } + + + /* + if (tile->PPT) { // BAD PPT !!! + FILE *PPT_file; + int i; + PPT_file=fopen("PPT","rb"); + fprintf(stderr,"%c%c%c%c",255,97,tile->len_ppt/256,tile->len_ppt%256); + for (i=0;ilen_ppt;i++) { + unsigned char elmt; + fread(&elmt, 1, 1, PPT_file); + fwrite(&elmt,1,1,f); + } + fclose(PPT_file); + unlink("PPT"); + } + */ + + } + + /* destroy the tile encoder */ + tcd_free_encode(tcd); + tcd_destroy(tcd); + + opj_free(j2k->cur_totnum_tp); + + j2k_write_eoc(j2k); + + if(cstr_info) { + cstr_info->codestream_size = cio_tell(cio) + j2k->pos_correction; + /* UniPG>> */ + /* The following adjustment is done to adjust the codestream size */ + /* if SOD is not at 0 in the buffer. Useful in case of JP2, where */ + /* the first bunch of bytes is not in the codestream */ + cstr_info->codestream_size -= cstr_info->main_head_start; + /* <epc_on) { + + /* encode according to JPWL */ + jpwl_encode(j2k, cio, image); + + } +#endif /* USE_JPWL */ + + return OPJ_TRUE; +} + +static void j2k_add_mhmarker(opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len) { + + if (!cstr_info) + return; + + /* expand the list? */ + if ((cstr_info->marknum + 1) > cstr_info->maxmarknum) { + cstr_info->maxmarknum = 100 + (int) ((float) cstr_info->maxmarknum * 1.0F); + cstr_info->marker = (opj_marker_info_t*)opj_realloc(cstr_info->marker, cstr_info->maxmarknum); + } + + /* add the marker */ + cstr_info->marker[cstr_info->marknum].type = type; + cstr_info->marker[cstr_info->marknum].pos = pos; + cstr_info->marker[cstr_info->marknum].len = len; + cstr_info->marknum++; + +} + +static void j2k_add_tlmarker( int tileno, opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len) { + + opj_marker_info_t *marker; + + if (!cstr_info) + return; + + /* expand the list? */ + if ((cstr_info->tile[tileno].marknum + 1) > cstr_info->tile[tileno].maxmarknum) { + cstr_info->tile[tileno].maxmarknum = 100 + (int) ((float) cstr_info->tile[tileno].maxmarknum * 1.0F); + cstr_info->tile[tileno].marker = (opj_marker_info_t*)opj_realloc(cstr_info->tile[tileno].marker, cstr_info->maxmarknum); + } + + marker = &(cstr_info->tile[tileno].marker[cstr_info->tile[tileno].marknum]); + + /* add the marker */ + marker->type = type; + marker->pos = pos; + marker->len = len; + cstr_info->tile[tileno].marknum++; +} diff --git a/Source/LibOpenJPEG/j2k.h b/Source/LibOpenJPEG/j2k.h index 00be481..6338c29 100644 --- a/Source/LibOpenJPEG/j2k.h +++ b/Source/LibOpenJPEG/j2k.h @@ -1,446 +1,446 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2006-2007, Parvatha Elangovan - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __J2K_H -#define __J2K_H -/** -@file j2k.h -@brief The JPEG-2000 Codestream Reader/Writer (J2K) - -The functions in J2K.C have for goal to read/write the several parts of the codestream: markers and data. -*/ - -/** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */ -/*@{*/ - -#define J2K_CP_CSTY_PRT 0x01 -#define J2K_CP_CSTY_SOP 0x02 -#define J2K_CP_CSTY_EPH 0x04 -#define J2K_CCP_CSTY_PRT 0x01 -#define J2K_CCP_CBLKSTY_LAZY 0x01 /**< Selective arithmetic coding bypass */ -#define J2K_CCP_CBLKSTY_RESET 0x02 /**< Reset context probabilities on coding pass boundaries */ -#define J2K_CCP_CBLKSTY_TERMALL 0x04 /**< Termination on each coding pass */ -#define J2K_CCP_CBLKSTY_VSC 0x08 /**< Vertically stripe causal context */ -#define J2K_CCP_CBLKSTY_PTERM 0x10 /**< Predictable termination */ -#define J2K_CCP_CBLKSTY_SEGSYM 0x20 /**< Segmentation symbols are used */ -#define J2K_CCP_QNTSTY_NOQNT 0 -#define J2K_CCP_QNTSTY_SIQNT 1 -#define J2K_CCP_QNTSTY_SEQNT 2 - -/* ----------------------------------------------------------------------- */ - -#define J2K_MS_SOC 0xff4f /**< SOC marker value */ -#define J2K_MS_SOT 0xff90 /**< SOT marker value */ -#define J2K_MS_SOD 0xff93 /**< SOD marker value */ -#define J2K_MS_EOC 0xffd9 /**< EOC marker value */ -#define J2K_MS_SIZ 0xff51 /**< SIZ marker value */ -#define J2K_MS_COD 0xff52 /**< COD marker value */ -#define J2K_MS_COC 0xff53 /**< COC marker value */ -#define J2K_MS_RGN 0xff5e /**< RGN marker value */ -#define J2K_MS_QCD 0xff5c /**< QCD marker value */ -#define J2K_MS_QCC 0xff5d /**< QCC marker value */ -#define J2K_MS_POC 0xff5f /**< POC marker value */ -#define J2K_MS_TLM 0xff55 /**< TLM marker value */ -#define J2K_MS_PLM 0xff57 /**< PLM marker value */ -#define J2K_MS_PLT 0xff58 /**< PLT marker value */ -#define J2K_MS_PPM 0xff60 /**< PPM marker value */ -#define J2K_MS_PPT 0xff61 /**< PPT marker value */ -#define J2K_MS_SOP 0xff91 /**< SOP marker value */ -#define J2K_MS_EPH 0xff92 /**< EPH marker value */ -#define J2K_MS_CRG 0xff63 /**< CRG marker value */ -#define J2K_MS_COM 0xff64 /**< COM marker value */ -/* UniPG>> */ -#ifdef USE_JPWL -#define J2K_MS_EPC 0xff68 /**< EPC marker value (Part 11: JPEG 2000 for Wireless) */ -#define J2K_MS_EPB 0xff66 /**< EPB marker value (Part 11: JPEG 2000 for Wireless) */ -#define J2K_MS_ESD 0xff67 /**< ESD marker value (Part 11: JPEG 2000 for Wireless) */ -#define J2K_MS_RED 0xff69 /**< RED marker value (Part 11: JPEG 2000 for Wireless) */ -#endif /* USE_JPWL */ -#ifdef USE_JPSEC -#define J2K_MS_SEC 0xff65 /**< SEC marker value (Part 8: Secure JPEG 2000) */ -#define J2K_MS_INSEC 0xff94 /**< INSEC marker value (Part 8: Secure JPEG 2000) */ -#endif /* USE_JPSEC */ -/* < there was a PPT marker for the present tile */ - int ppt; - /** used in case of multiple marker PPT (number of info already stored) */ - int ppt_store; - /** ppmbug1 */ - int ppt_len; - /** add fixed_quality */ - float distoratio[100]; - /** tile-component coding parameters */ - opj_tccp_t *tccps; -} opj_tcp_t; - -/** -Coding parameters -*/ -typedef struct opj_cp { - /** Digital cinema profile*/ - OPJ_CINEMA_MODE cinema; - /** Maximum rate for each component. If == 0, component size limitation is not considered */ - int max_comp_size; - /** Size of the image in bits*/ - int img_size; - /** Rsiz*/ - OPJ_RSIZ_CAPABILITIES rsiz; - /** Enabling Tile part generation*/ - char tp_on; - /** Flag determining tile part generation*/ - char tp_flag; - /** Position of tile part flag in progression order*/ - int tp_pos; - /** allocation by rate/distortion */ - int disto_alloc; - /** allocation by fixed layer */ - int fixed_alloc; - /** add fixed_quality */ - int fixed_quality; - /** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, image is decoded to the full resolution */ - int reduce; - /** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */ - int layer; - /** if == NO_LIMITATION, decode entire codestream; if == LIMIT_TO_MAIN_HEADER then only decode the main header */ - OPJ_LIMIT_DECODING limit_decoding; - /** XTOsiz */ - int tx0; - /** YTOsiz */ - int ty0; - /** XTsiz */ - int tdx; - /** YTsiz */ - int tdy; - /** comment for coding */ - char *comment; - /** number of tiles in width */ - int tw; - /** number of tiles in heigth */ - int th; - /** ID number of the tiles present in the codestream */ - int *tileno; - /** size of the vector tileno */ - int tileno_size; - /** packet header store there for futur use in t2_decode_packet */ - unsigned char *ppm_data; - /** pointer remaining on the first byte of the first header if ppm is used */ - unsigned char *ppm_data_first; - /** if ppm == 1 --> there was a PPM marker for the present tile */ - int ppm; - /** use in case of multiple marker PPM (number of info already store) */ - int ppm_store; - /** use in case of multiple marker PPM (case on non-finished previous info) */ - int ppm_previous; - /** ppmbug1 */ - int ppm_len; - /** tile coding parameters */ - opj_tcp_t *tcps; - /** fixed layer */ - int *matrice; -/* UniPG>> */ -#ifdef USE_JPWL - /** enables writing of EPC in MH, thus activating JPWL */ - opj_bool epc_on; - /** enables writing of EPB, in case of activated JPWL */ - opj_bool epb_on; - /** enables writing of ESD, in case of activated JPWL */ - opj_bool esd_on; - /** enables writing of informative techniques of ESD, in case of activated JPWL */ - opj_bool info_on; - /** enables writing of RED, in case of activated JPWL */ - opj_bool red_on; - /** error protection method for MH (0,1,16,32,37-128) */ - int hprot_MH; - /** tile number of header protection specification (>=0) */ - int hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS]; - /** error protection methods for TPHs (0,1,16,32,37-128) */ - int hprot_TPH[JPWL_MAX_NO_TILESPECS]; - /** tile number of packet protection specification (>=0) */ - int pprot_tileno[JPWL_MAX_NO_PACKSPECS]; - /** packet number of packet protection specification (>=0) */ - int pprot_packno[JPWL_MAX_NO_PACKSPECS]; - /** error protection methods for packets (0,1,16,32,37-128) */ - int pprot[JPWL_MAX_NO_PACKSPECS]; - /** enables writing of ESD, (0/2/4 bytes) */ - int sens_size; - /** sensitivity addressing size (0=auto/2/4 bytes) */ - int sens_addr; - /** sensitivity range (0-3) */ - int sens_range; - /** sensitivity method for MH (-1,0-7) */ - int sens_MH; - /** tile number of sensitivity specification (>=0) */ - int sens_TPH_tileno[JPWL_MAX_NO_TILESPECS]; - /** sensitivity methods for TPHs (-1,0-7) */ - int sens_TPH[JPWL_MAX_NO_TILESPECS]; - /** enables JPWL correction at the decoder */ - opj_bool correct; - /** expected number of components at the decoder */ - int exp_comps; - /** maximum number of tiles at the decoder */ - int max_tiles; -#endif /* USE_JPWL */ -/* <cp. -@param j2k J2K decompressor handle -@param parameters decompression parameters -*/ -void j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters); -/** -Decode an image from a JPEG-2000 codestream -@param j2k J2K decompressor handle -@param cio Input buffer stream -@param cstr_info Codestream information structure if required, NULL otherwise -@return Returns a decoded image if successful, returns NULL otherwise -*/ -opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info); -/** -Decode an image form a JPT-stream (JPEG 2000, JPIP) -@param j2k J2K decompressor handle -@param cio Input buffer stream -@param cstr_info Codestream information structure if required, NULL otherwise -@return Returns a decoded image if successful, returns NULL otherwise -*/ -opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info); -/** -Creates a J2K compression structure -@param cinfo Codec context info -@return Returns a handle to a J2K compressor if successful, returns NULL otherwise -*/ -opj_j2k_t* j2k_create_compress(opj_common_ptr cinfo); -/** -Destroy a J2K compressor handle -@param j2k J2K compressor handle to destroy -*/ -void j2k_destroy_compress(opj_j2k_t *j2k); -/** -Setup the encoder parameters using the current image and using user parameters. -Coding parameters are returned in j2k->cp. -@param j2k J2K compressor handle -@param parameters compression parameters -@param image input filled image -*/ -void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_t *image); -/** -Converts an enum type progression order to string type -*/ -char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order); -/** -Encode an image into a JPEG-2000 codestream -@param j2k J2K compressor handle -@param cio Output buffer stream -@param image Image to encode -@param cstr_info Codestream information structure if required, NULL otherwise -@return Returns true if successful, returns false otherwise -*/ -opj_bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info); - -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __J2K_H */ +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2006-2007, Parvatha Elangovan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __J2K_H +#define __J2K_H +/** +@file j2k.h +@brief The JPEG-2000 Codestream Reader/Writer (J2K) + +The functions in J2K.C have for goal to read/write the several parts of the codestream: markers and data. +*/ + +/** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */ +/*@{*/ + +#define J2K_CP_CSTY_PRT 0x01 +#define J2K_CP_CSTY_SOP 0x02 +#define J2K_CP_CSTY_EPH 0x04 +#define J2K_CCP_CSTY_PRT 0x01 +#define J2K_CCP_CBLKSTY_LAZY 0x01 /**< Selective arithmetic coding bypass */ +#define J2K_CCP_CBLKSTY_RESET 0x02 /**< Reset context probabilities on coding pass boundaries */ +#define J2K_CCP_CBLKSTY_TERMALL 0x04 /**< Termination on each coding pass */ +#define J2K_CCP_CBLKSTY_VSC 0x08 /**< Vertically stripe causal context */ +#define J2K_CCP_CBLKSTY_PTERM 0x10 /**< Predictable termination */ +#define J2K_CCP_CBLKSTY_SEGSYM 0x20 /**< Segmentation symbols are used */ +#define J2K_CCP_QNTSTY_NOQNT 0 +#define J2K_CCP_QNTSTY_SIQNT 1 +#define J2K_CCP_QNTSTY_SEQNT 2 + +/* ----------------------------------------------------------------------- */ + +#define J2K_MS_SOC 0xff4f /**< SOC marker value */ +#define J2K_MS_SOT 0xff90 /**< SOT marker value */ +#define J2K_MS_SOD 0xff93 /**< SOD marker value */ +#define J2K_MS_EOC 0xffd9 /**< EOC marker value */ +#define J2K_MS_SIZ 0xff51 /**< SIZ marker value */ +#define J2K_MS_COD 0xff52 /**< COD marker value */ +#define J2K_MS_COC 0xff53 /**< COC marker value */ +#define J2K_MS_RGN 0xff5e /**< RGN marker value */ +#define J2K_MS_QCD 0xff5c /**< QCD marker value */ +#define J2K_MS_QCC 0xff5d /**< QCC marker value */ +#define J2K_MS_POC 0xff5f /**< POC marker value */ +#define J2K_MS_TLM 0xff55 /**< TLM marker value */ +#define J2K_MS_PLM 0xff57 /**< PLM marker value */ +#define J2K_MS_PLT 0xff58 /**< PLT marker value */ +#define J2K_MS_PPM 0xff60 /**< PPM marker value */ +#define J2K_MS_PPT 0xff61 /**< PPT marker value */ +#define J2K_MS_SOP 0xff91 /**< SOP marker value */ +#define J2K_MS_EPH 0xff92 /**< EPH marker value */ +#define J2K_MS_CRG 0xff63 /**< CRG marker value */ +#define J2K_MS_COM 0xff64 /**< COM marker value */ +/* UniPG>> */ +#ifdef USE_JPWL +#define J2K_MS_EPC 0xff68 /**< EPC marker value (Part 11: JPEG 2000 for Wireless) */ +#define J2K_MS_EPB 0xff66 /**< EPB marker value (Part 11: JPEG 2000 for Wireless) */ +#define J2K_MS_ESD 0xff67 /**< ESD marker value (Part 11: JPEG 2000 for Wireless) */ +#define J2K_MS_RED 0xff69 /**< RED marker value (Part 11: JPEG 2000 for Wireless) */ +#endif /* USE_JPWL */ +#ifdef USE_JPSEC +#define J2K_MS_SEC 0xff65 /**< SEC marker value (Part 8: Secure JPEG 2000) */ +#define J2K_MS_INSEC 0xff94 /**< INSEC marker value (Part 8: Secure JPEG 2000) */ +#endif /* USE_JPSEC */ +/* < there was a PPT marker for the present tile */ + int ppt; + /** used in case of multiple marker PPT (number of info already stored) */ + int ppt_store; + /** ppmbug1 */ + int ppt_len; + /** add fixed_quality */ + float distoratio[100]; + /** tile-component coding parameters */ + opj_tccp_t *tccps; +} opj_tcp_t; + +/** +Coding parameters +*/ +typedef struct opj_cp { + /** Digital cinema profile*/ + OPJ_CINEMA_MODE cinema; + /** Maximum rate for each component. If == 0, component size limitation is not considered */ + int max_comp_size; + /** Size of the image in bits*/ + int img_size; + /** Rsiz*/ + OPJ_RSIZ_CAPABILITIES rsiz; + /** Enabling Tile part generation*/ + char tp_on; + /** Flag determining tile part generation*/ + char tp_flag; + /** Position of tile part flag in progression order*/ + int tp_pos; + /** allocation by rate/distortion */ + int disto_alloc; + /** allocation by fixed layer */ + int fixed_alloc; + /** add fixed_quality */ + int fixed_quality; + /** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, image is decoded to the full resolution */ + int reduce; + /** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */ + int layer; + /** if == NO_LIMITATION, decode entire codestream; if == LIMIT_TO_MAIN_HEADER then only decode the main header */ + OPJ_LIMIT_DECODING limit_decoding; + /** XTOsiz */ + int tx0; + /** YTOsiz */ + int ty0; + /** XTsiz */ + int tdx; + /** YTsiz */ + int tdy; + /** comment for coding */ + char *comment; + /** number of tiles in width */ + int tw; + /** number of tiles in heigth */ + int th; + /** ID number of the tiles present in the codestream */ + int *tileno; + /** size of the vector tileno */ + int tileno_size; + /** packet header store there for futur use in t2_decode_packet */ + unsigned char *ppm_data; + /** pointer remaining on the first byte of the first header if ppm is used */ + unsigned char *ppm_data_first; + /** if ppm == 1 --> there was a PPM marker for the present tile */ + int ppm; + /** use in case of multiple marker PPM (number of info already store) */ + int ppm_store; + /** use in case of multiple marker PPM (case on non-finished previous info) */ + int ppm_previous; + /** ppmbug1 */ + int ppm_len; + /** tile coding parameters */ + opj_tcp_t *tcps; + /** fixed layer */ + int *matrice; +/* UniPG>> */ +#ifdef USE_JPWL + /** enables writing of EPC in MH, thus activating JPWL */ + opj_bool epc_on; + /** enables writing of EPB, in case of activated JPWL */ + opj_bool epb_on; + /** enables writing of ESD, in case of activated JPWL */ + opj_bool esd_on; + /** enables writing of informative techniques of ESD, in case of activated JPWL */ + opj_bool info_on; + /** enables writing of RED, in case of activated JPWL */ + opj_bool red_on; + /** error protection method for MH (0,1,16,32,37-128) */ + int hprot_MH; + /** tile number of header protection specification (>=0) */ + int hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS]; + /** error protection methods for TPHs (0,1,16,32,37-128) */ + int hprot_TPH[JPWL_MAX_NO_TILESPECS]; + /** tile number of packet protection specification (>=0) */ + int pprot_tileno[JPWL_MAX_NO_PACKSPECS]; + /** packet number of packet protection specification (>=0) */ + int pprot_packno[JPWL_MAX_NO_PACKSPECS]; + /** error protection methods for packets (0,1,16,32,37-128) */ + int pprot[JPWL_MAX_NO_PACKSPECS]; + /** enables writing of ESD, (0/2/4 bytes) */ + int sens_size; + /** sensitivity addressing size (0=auto/2/4 bytes) */ + int sens_addr; + /** sensitivity range (0-3) */ + int sens_range; + /** sensitivity method for MH (-1,0-7) */ + int sens_MH; + /** tile number of sensitivity specification (>=0) */ + int sens_TPH_tileno[JPWL_MAX_NO_TILESPECS]; + /** sensitivity methods for TPHs (-1,0-7) */ + int sens_TPH[JPWL_MAX_NO_TILESPECS]; + /** enables JPWL correction at the decoder */ + opj_bool correct; + /** expected number of components at the decoder */ + int exp_comps; + /** maximum number of tiles at the decoder */ + int max_tiles; +#endif /* USE_JPWL */ +/* <cp. +@param j2k J2K decompressor handle +@param parameters decompression parameters +*/ +void j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters); +/** +Decode an image from a JPEG-2000 codestream +@param j2k J2K decompressor handle +@param cio Input buffer stream +@param cstr_info Codestream information structure if required, NULL otherwise +@return Returns a decoded image if successful, returns NULL otherwise +*/ +opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info); +/** +Decode an image form a JPT-stream (JPEG 2000, JPIP) +@param j2k J2K decompressor handle +@param cio Input buffer stream +@param cstr_info Codestream information structure if required, NULL otherwise +@return Returns a decoded image if successful, returns NULL otherwise +*/ +opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info); +/** +Creates a J2K compression structure +@param cinfo Codec context info +@return Returns a handle to a J2K compressor if successful, returns NULL otherwise +*/ +opj_j2k_t* j2k_create_compress(opj_common_ptr cinfo); +/** +Destroy a J2K compressor handle +@param j2k J2K compressor handle to destroy +*/ +void j2k_destroy_compress(opj_j2k_t *j2k); +/** +Setup the encoder parameters using the current image and using user parameters. +Coding parameters are returned in j2k->cp. +@param j2k J2K compressor handle +@param parameters compression parameters +@param image input filled image +*/ +void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_t *image); +/** +Converts an enum type progression order to string type +*/ +char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order); +/** +Encode an image into a JPEG-2000 codestream +@param j2k J2K compressor handle +@param cio Output buffer stream +@param image Image to encode +@param cstr_info Codestream information structure if required, NULL otherwise +@return Returns true if successful, returns false otherwise +*/ +opj_bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info); + +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __J2K_H */ diff --git a/Source/LibOpenJPEG/j2k_lib.c b/Source/LibOpenJPEG/j2k_lib.c index 5589803..a66e31e 100644 --- a/Source/LibOpenJPEG/j2k_lib.c +++ b/Source/LibOpenJPEG/j2k_lib.c @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef _WIN32 -#include -#else -#include -#include -#include -#endif /* _WIN32 */ -#include "opj_includes.h" - -double opj_clock(void) { -#ifdef _WIN32 - /* _WIN32: use QueryPerformance (very accurate) */ - LARGE_INTEGER freq , t ; - /* freq is the clock speed of the CPU */ - QueryPerformanceFrequency(&freq) ; - /* cout << "freq = " << ((double) freq.QuadPart) << endl; */ - /* t is the high resolution performance counter (see MSDN) */ - QueryPerformanceCounter ( & t ) ; - return ( t.QuadPart /(double) freq.QuadPart ) ; -#else - /* Unix or Linux: use resource usage */ - struct rusage t; - double procTime; - /* (1) Get the rusage data structure at this moment (man getrusage) */ - getrusage(0,&t); - /* (2) What is the elapsed time ? - CPU time = User time + System time */ - /* (2a) Get the seconds */ - procTime = t.ru_utime.tv_sec + t.ru_stime.tv_sec; - /* (2b) More precisely! Get the microseconds part ! */ - return ( procTime + (t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ; -#endif -} - +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef _WIN32 +#include +#else +#include +#include +#include +#endif /* _WIN32 */ +#include "opj_includes.h" + +double opj_clock(void) { +#ifdef _WIN32 + /* _WIN32: use QueryPerformance (very accurate) */ + LARGE_INTEGER freq , t ; + /* freq is the clock speed of the CPU */ + QueryPerformanceFrequency(&freq) ; + /* cout << "freq = " << ((double) freq.QuadPart) << endl; */ + /* t is the high resolution performance counter (see MSDN) */ + QueryPerformanceCounter ( & t ) ; + return ( t.QuadPart /(double) freq.QuadPart ) ; +#else + /* Unix or Linux: use resource usage */ + struct rusage t; + double procTime; + /* (1) Get the rusage data structure at this moment (man getrusage) */ + getrusage(0,&t); + /* (2) What is the elapsed time ? - CPU time = User time + System time */ + /* (2a) Get the seconds */ + procTime = t.ru_utime.tv_sec + t.ru_stime.tv_sec; + /* (2b) More precisely! Get the microseconds part ! */ + return ( procTime + (t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ; +#endif +} + diff --git a/Source/LibOpenJPEG/j2k_lib.h b/Source/LibOpenJPEG/j2k_lib.h index ea5e1e6..5f3406e 100644 --- a/Source/LibOpenJPEG/j2k_lib.h +++ b/Source/LibOpenJPEG/j2k_lib.h @@ -1,54 +1,54 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __J2K_LIB_H -#define __J2K_LIB_H -/** -@file j2k_lib.h -@brief Internal functions - -The functions in J2K_LIB.C are internal utilities mainly used for timing. -*/ - -/** @defgroup MISC MISC - Miscellaneous internal functions */ -/*@{*/ - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ - -/** -Difference in successive opj_clock() calls tells you the elapsed time -@return Returns time in seconds -*/ -double opj_clock(void); - -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __J2K_LIB_H */ - +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __J2K_LIB_H +#define __J2K_LIB_H +/** +@file j2k_lib.h +@brief Internal functions + +The functions in J2K_LIB.C are internal utilities mainly used for timing. +*/ + +/** @defgroup MISC MISC - Miscellaneous internal functions */ +/*@{*/ + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ + +/** +Difference in successive opj_clock() calls tells you the elapsed time +@return Returns time in seconds +*/ +double opj_clock(void); + +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __J2K_LIB_H */ + diff --git a/Source/LibOpenJPEG/jp2.c b/Source/LibOpenJPEG/jp2.c index ee28913..d43e70c 100644 --- a/Source/LibOpenJPEG/jp2.c +++ b/Source/LibOpenJPEG/jp2.c @@ -1,1223 +1,1223 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2010-2011, Kaori Hagihara - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#include "opj_includes.h" - -/** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */ -/*@{*/ - -/** @name Local static functions */ -/*@{*/ - -/** -Read box headers -@param cinfo Codec context info -@param cio Input stream -@param box -@return Returns true if successful, returns false otherwise -*/ -static opj_bool jp2_read_boxhdr(opj_common_ptr cinfo, opj_cio_t *cio, opj_jp2_box_t *box); -/*static void jp2_write_url(opj_cio_t *cio, char *Idx_file);*/ -/** -Read the IHDR box - Image Header box -@param jp2 JP2 handle -@param cio Input buffer stream -@return Returns true if successful, returns false otherwise -*/ -static opj_bool jp2_read_ihdr(opj_jp2_t *jp2, opj_cio_t *cio); -static void jp2_write_ihdr(opj_jp2_t *jp2, opj_cio_t *cio); -static void jp2_write_bpcc(opj_jp2_t *jp2, opj_cio_t *cio); -static opj_bool jp2_read_bpcc(opj_jp2_t *jp2, opj_cio_t *cio); -static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio); -/** -Write the FTYP box - File type box -@param jp2 JP2 handle -@param cio Output buffer stream -*/ -static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio); -/** -Read the FTYP box - File type box -@param jp2 JP2 handle -@param cio Input buffer stream -@return Returns true if successful, returns false otherwise -*/ -static opj_bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio); -static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info); -static opj_bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset); -static void jp2_write_jp(opj_cio_t *cio); -/** -Read the JP box - JPEG 2000 signature -@param jp2 JP2 handle -@param cio Input buffer stream -@return Returns true if successful, returns false otherwise -*/ -static opj_bool jp2_read_jp(opj_jp2_t *jp2, opj_cio_t *cio); -/** -Decode the structure of a JP2 file -@param jp2 JP2 handle -@param cio Input buffer stream -@param color Collector for profile, cdef and pclr data -@return Returns true if successful, returns false otherwise -*/ -static opj_bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio, - opj_jp2_color_t *color); -/** -Apply collected palette data -@param color Collector for profile, cdef and pclr data -@param image -*/ -static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image, opj_common_ptr cinfo); -/** -Collect palette data -@param jp2 JP2 handle -@param cio Input buffer stream -@param box -@param color Collector for profile, cdef and pclr data -@return Returns true if successful, returns false otherwise -*/ -static opj_bool jp2_read_pclr(opj_jp2_t *jp2, opj_cio_t *cio, - opj_jp2_box_t *box, opj_jp2_color_t *color); -/** -Collect component mapping data -@param jp2 JP2 handle -@param cio Input buffer stream -@param box -@param color Collector for profile, cdef and pclr data -@return Returns true if successful, returns false otherwise -*/ -static opj_bool jp2_read_cmap(opj_jp2_t *jp2, opj_cio_t *cio, - opj_jp2_box_t *box, opj_jp2_color_t *color); -/** -Collect colour specification data -@param jp2 JP2 handle -@param cio Input buffer stream -@param box -@param color Collector for profile, cdef and pclr data -@return Returns true if successful, returns false otherwise -*/ -static opj_bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio, - opj_jp2_box_t *box, opj_jp2_color_t *color); -/** -Write file Index (superbox) -@param[in] offset_jp2c offset of jp2c box -@param[in] length_jp2c length of jp2c box -@param[in] offset_idx offset of cidx box -@param[in] length_idx length of cidx box -@param[in] cio file output handle -@return length of fidx box -*/ -static int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio); -/** -Write index Finder box -@param[in] offset offset of fidx box -@param[in] length length of fidx box -@param[in] cio file output handle -*/ -static void write_iptr( int offset, int length, opj_cio_t *cio); -/** -Write proxy box -@param[in] offset_jp2c offset of jp2c box -@param[in] length_jp2c length of jp2c box -@param[in] offset_idx offset of cidx box -@param[in] length_idx length of cidx box -@param[in] cio file output handle -*/ -static void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio); -/*@}*/ - -/*@}*/ - -/* ----------------------------------------------------------------------- */ - -static opj_bool jp2_read_boxhdr(opj_common_ptr cinfo, opj_cio_t *cio, opj_jp2_box_t *box) { - box->init_pos = cio_tell(cio); - box->length = cio_read(cio, 4); - box->type = cio_read(cio, 4); - if (box->length == 1) { - if (cio_read(cio, 4) != 0) { - opj_event_msg(cinfo, EVT_ERROR, "Cannot handle box sizes higher than 2^32\n"); - return OPJ_FALSE; - } - box->length = cio_read(cio, 4); - if (box->length == 0) - box->length = cio_numbytesleft(cio) + 12; - } - else if (box->length == 0) { - box->length = cio_numbytesleft(cio) + 8; - } - - return OPJ_TRUE; -} - -#if 0 -static void jp2_write_url(opj_cio_t *cio, char *Idx_file) { - unsigned int i; - opj_jp2_box_t box; - - box.init_pos = cio_tell(cio); - cio_skip(cio, 4); - cio_write(cio, JP2_URL, 4); /* DBTL */ - cio_write(cio, 0, 1); /* VERS */ - cio_write(cio, 0, 3); /* FLAG */ - - if(Idx_file) { - for (i = 0; i < strlen(Idx_file); i++) { - cio_write(cio, Idx_file[i], 1); - } - } - - box.length = cio_tell(cio) - box.init_pos; - cio_seek(cio, box.init_pos); - cio_write(cio, box.length, 4); /* L */ - cio_seek(cio, box.init_pos + box.length); -} -#endif - -static opj_bool jp2_read_ihdr(opj_jp2_t *jp2, opj_cio_t *cio) { - opj_jp2_box_t box; - - opj_common_ptr cinfo = jp2->cinfo; - - if(jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) { - opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n"); - return OPJ_FALSE; - } - if (JP2_IHDR != box.type) { - opj_event_msg(cinfo, EVT_ERROR, "Expected IHDR Marker\n"); - return OPJ_FALSE; - } - - jp2->h = cio_read(cio, 4); /* HEIGHT */ - jp2->w = cio_read(cio, 4); /* WIDTH */ - jp2->numcomps = cio_read(cio, 2); /* NC */ - jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t)); - - jp2->bpc = cio_read(cio, 1); /* BPC */ - - jp2->C = cio_read(cio, 1); /* C */ - jp2->UnkC = cio_read(cio, 1); /* UnkC */ - jp2->IPR = cio_read(cio, 1); /* IPR */ - - if (cio_tell(cio) - box.init_pos != box.length) { - opj_event_msg(cinfo, EVT_ERROR, "Error with IHDR Box\n"); - return OPJ_FALSE; - } - - return OPJ_TRUE; -} - -static void jp2_write_ihdr(opj_jp2_t *jp2, opj_cio_t *cio) { - opj_jp2_box_t box; - - box.init_pos = cio_tell(cio); - cio_skip(cio, 4); - cio_write(cio, JP2_IHDR, 4); /* IHDR */ - - cio_write(cio, jp2->h, 4); /* HEIGHT */ - cio_write(cio, jp2->w, 4); /* WIDTH */ - cio_write(cio, jp2->numcomps, 2); /* NC */ - - cio_write(cio, jp2->bpc, 1); /* BPC */ - - cio_write(cio, jp2->C, 1); /* C : Always 7 */ - cio_write(cio, jp2->UnkC, 1); /* UnkC, colorspace unknown */ - cio_write(cio, jp2->IPR, 1); /* IPR, no intellectual property */ - - box.length = cio_tell(cio) - box.init_pos; - cio_seek(cio, box.init_pos); - cio_write(cio, box.length, 4); /* L */ - cio_seek(cio, box.init_pos + box.length); -} - -static void jp2_write_bpcc(opj_jp2_t *jp2, opj_cio_t *cio) { - unsigned int i; - opj_jp2_box_t box; - - box.init_pos = cio_tell(cio); - cio_skip(cio, 4); - cio_write(cio, JP2_BPCC, 4); /* BPCC */ - - for (i = 0; i < jp2->numcomps; i++) { - cio_write(cio, jp2->comps[i].bpcc, 1); - } - - box.length = cio_tell(cio) - box.init_pos; - cio_seek(cio, box.init_pos); - cio_write(cio, box.length, 4); /* L */ - cio_seek(cio, box.init_pos + box.length); -} - - -static opj_bool jp2_read_bpcc(opj_jp2_t *jp2, opj_cio_t *cio) { - unsigned int i; - opj_jp2_box_t box; - - opj_common_ptr cinfo = jp2->cinfo; - - if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) { - opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n"); - return OPJ_FALSE; - } - if (JP2_BPCC != box.type) { - opj_event_msg(cinfo, EVT_ERROR, "Expected BPCC Marker\n"); - return OPJ_FALSE; - } - - for (i = 0; i < jp2->numcomps; i++) { - jp2->comps[i].bpcc = cio_read(cio, 1); - } - - if (cio_tell(cio) - box.init_pos != box.length) { - opj_event_msg(cinfo, EVT_ERROR, "Error with BPCC Box\n"); - return OPJ_FALSE; - } - - return OPJ_TRUE; -} - -static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio) { - opj_jp2_box_t box; - - box.init_pos = cio_tell(cio); - cio_skip(cio, 4); - cio_write(cio, JP2_COLR, 4); /* COLR */ - - cio_write(cio, jp2->meth, 1); /* METH */ - cio_write(cio, jp2->precedence, 1); /* PRECEDENCE */ - cio_write(cio, jp2->approx, 1); /* APPROX */ - - if(jp2->meth == 2) - jp2->enumcs = 0; - - cio_write(cio, jp2->enumcs, 4); /* EnumCS */ - - box.length = cio_tell(cio) - box.init_pos; - cio_seek(cio, box.init_pos); - cio_write(cio, box.length, 4); /* L */ - cio_seek(cio, box.init_pos + box.length); -} - -static void jp2_free_pclr(opj_jp2_color_t *color) -{ - opj_free(color->jp2_pclr->channel_sign); - opj_free(color->jp2_pclr->channel_size); - opj_free(color->jp2_pclr->entries); - - if(color->jp2_pclr->cmap) opj_free(color->jp2_pclr->cmap); - - opj_free(color->jp2_pclr); color->jp2_pclr = NULL; -} - -static void free_color_data(opj_jp2_color_t *color) -{ - if(color->jp2_pclr) - { - jp2_free_pclr(color); - } - if(color->jp2_cdef) - { - if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info); - opj_free(color->jp2_cdef); - } - if(color->icc_profile_buf) opj_free(color->icc_profile_buf); -} - -static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image, opj_common_ptr cinfo) -{ - opj_image_comp_t *old_comps, *new_comps; - unsigned char *channel_size, *channel_sign; - unsigned int *entries; - opj_jp2_cmap_comp_t *cmap; - int *src, *dst; - unsigned int j, max; - unsigned short i, nr_channels, cmp, pcol; - int k, top_k; - - channel_size = color->jp2_pclr->channel_size; - channel_sign = color->jp2_pclr->channel_sign; - entries = color->jp2_pclr->entries; - cmap = color->jp2_pclr->cmap; - nr_channels = color->jp2_pclr->nr_channels; - - old_comps = image->comps; - new_comps = (opj_image_comp_t*) - opj_malloc(nr_channels * sizeof(opj_image_comp_t)); - - for(i = 0; i < nr_channels; ++i) - { - pcol = cmap[i].pcol; cmp = cmap[i].cmp; - - if( pcol < nr_channels ) - new_comps[pcol] = old_comps[cmp]; - else - { - opj_event_msg(cinfo, EVT_ERROR, "Error with pcol value %d (max: %d). skipping\n", pcol, nr_channels); - continue; - } - - if(cmap[i].mtyp == 0) /* Direct use */ - { - old_comps[cmp].data = NULL; continue; - } -/* Palette mapping: */ - new_comps[pcol].data = (int*) - opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(int)); - new_comps[pcol].prec = channel_size[i]; - new_comps[pcol].sgnd = channel_sign[i]; - } - top_k = color->jp2_pclr->nr_entries - 1; - - for(i = 0; i < nr_channels; ++i) - { -/* Direct use: */ - if(cmap[i].mtyp == 0) continue; - -/* Palette mapping: */ - cmp = cmap[i].cmp; pcol = cmap[i].pcol; - src = old_comps[cmp].data; - dst = new_comps[pcol].data; - max = new_comps[pcol].w * new_comps[pcol].h; - - for(j = 0; j < max; ++j) - { -/* The index */ - if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k; -/* The colour */ - dst[j] = entries[k * nr_channels + pcol]; - } - } - max = image->numcomps; - for(i = 0; i < max; ++i) - { - if(old_comps[i].data) opj_free(old_comps[i].data); - } - opj_free(old_comps); - image->comps = new_comps; - image->numcomps = nr_channels; - - jp2_free_pclr(color); - -}/* apply_pclr() */ - -static opj_bool jp2_read_pclr(opj_jp2_t *jp2, opj_cio_t *cio, - opj_jp2_box_t *box, opj_jp2_color_t *color) -{ - opj_jp2_pclr_t *jp2_pclr; - unsigned char *channel_size, *channel_sign; - unsigned int *entries; - unsigned short nr_entries, nr_channels; - unsigned short i, j; - unsigned char uc; - - OPJ_ARG_NOT_USED(box); - OPJ_ARG_NOT_USED(jp2); - -/* Part 1, I.5.3.4: 'There shall be at most one Palette box inside - * a JP2 Header box' : -*/ - if(color->jp2_pclr) return OPJ_FALSE; - - nr_entries = (unsigned short)cio_read(cio, 2); /* NE */ - nr_channels = (unsigned short)cio_read(cio, 1);/* NPC */ - - entries = (unsigned int*) - opj_malloc(nr_channels * nr_entries * sizeof(unsigned int)); - channel_size = (unsigned char*)opj_malloc(nr_channels); - channel_sign = (unsigned char*)opj_malloc(nr_channels); - - jp2_pclr = (opj_jp2_pclr_t*)opj_malloc(sizeof(opj_jp2_pclr_t)); - jp2_pclr->channel_sign = channel_sign; - jp2_pclr->channel_size = channel_size; - jp2_pclr->entries = entries; - jp2_pclr->nr_entries = nr_entries; - jp2_pclr->nr_channels = nr_channels; - jp2_pclr->cmap = NULL; - - color->jp2_pclr = jp2_pclr; - - for(i = 0; i < nr_channels; ++i) - { - uc = cio_read(cio, 1); /* Bi */ - channel_size[i] = (uc & 0x7f) + 1; - channel_sign[i] = (uc & 0x80)?1:0; - } - - for(j = 0; j < nr_entries; ++j) - { - for(i = 0; i < nr_channels; ++i) - { -/* Cji */ - *entries++ = cio_read(cio, (channel_size[i]+7)>>3); - } - } - - return OPJ_TRUE; -}/* jp2_read_pclr() */ - -static opj_bool jp2_read_cmap(opj_jp2_t *jp2, opj_cio_t *cio, - opj_jp2_box_t *box, opj_jp2_color_t *color) -{ - opj_jp2_cmap_comp_t *cmap; - unsigned short i, nr_channels; - - OPJ_ARG_NOT_USED(box); - OPJ_ARG_NOT_USED(jp2); - -/* Need nr_channels: */ - if(color->jp2_pclr == NULL) return OPJ_FALSE; - -/* Part 1, I.5.3.5: 'There shall be at most one Component Mapping box - * inside a JP2 Header box' : -*/ - if(color->jp2_pclr->cmap) return OPJ_FALSE; - - nr_channels = color->jp2_pclr->nr_channels; - cmap = (opj_jp2_cmap_comp_t*) - opj_malloc(nr_channels * sizeof(opj_jp2_cmap_comp_t)); - - for(i = 0; i < nr_channels; ++i) - { - cmap[i].cmp = (unsigned short)cio_read(cio, 2); - cmap[i].mtyp = cio_read(cio, 1); - cmap[i].pcol = cio_read(cio, 1); - - } - color->jp2_pclr->cmap = cmap; - - return OPJ_TRUE; -}/* jp2_read_cmap() */ - -static void jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color) -{ - opj_jp2_cdef_info_t *info; - int color_space; - unsigned short i, n, cn, typ, asoc, acn; - - color_space = image->color_space; - info = color->jp2_cdef->info; - n = color->jp2_cdef->n; - - for(i = 0; i < n; ++i) - { -/* WATCH: acn = asoc - 1 ! */ - if((asoc = info[i].asoc) == 0) continue; - - cn = info[i].cn; typ = info[i].typ; acn = asoc - 1; - - if(cn != acn) - { - opj_image_comp_t saved; - - memcpy(&saved, &image->comps[cn], sizeof(opj_image_comp_t)); - memcpy(&image->comps[cn], &image->comps[acn], sizeof(opj_image_comp_t)); - memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t)); - - info[i].asoc = cn + 1; - info[acn].asoc = info[acn].cn + 1; - } - } - if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info); - - opj_free(color->jp2_cdef); color->jp2_cdef = NULL; - -}/* jp2_apply_cdef() */ - -static opj_bool jp2_read_cdef(opj_jp2_t *jp2, opj_cio_t *cio, - opj_jp2_box_t *box, opj_jp2_color_t *color) -{ - opj_jp2_cdef_info_t *info; - unsigned short i, n; - - OPJ_ARG_NOT_USED(box); - OPJ_ARG_NOT_USED(jp2); - -/* Part 1, I.5.3.6: 'The shall be at most one Channel Definition box - * inside a JP2 Header box.' -*/ - if(color->jp2_cdef) return OPJ_FALSE; - - if((n = (unsigned short)cio_read(cio, 2)) == 0) return OPJ_FALSE; /* szukw000: FIXME */ - - info = (opj_jp2_cdef_info_t*) - opj_malloc(n * sizeof(opj_jp2_cdef_info_t)); - - color->jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t)); - color->jp2_cdef->info = info; - color->jp2_cdef->n = n; - - for(i = 0; i < n; ++i) - { - info[i].cn = (unsigned short)cio_read(cio, 2); - info[i].typ = (unsigned short)cio_read(cio, 2); - info[i].asoc = (unsigned short)cio_read(cio, 2); - - } - return OPJ_TRUE; -}/* jp2_read_cdef() */ - -static opj_bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio, - opj_jp2_box_t *box, opj_jp2_color_t *color) -{ - int skip_len; - opj_common_ptr cinfo; - -/* Part 1, I.5.3.3 : 'A conforming JP2 reader shall ignore all Colour - * Specification boxes after the first.' -*/ - if(color->jp2_has_colr) return OPJ_FALSE; - - cinfo = jp2->cinfo; - - jp2->meth = cio_read(cio, 1); /* METH */ - jp2->precedence = cio_read(cio, 1); /* PRECEDENCE */ - jp2->approx = cio_read(cio, 1); /* APPROX */ - - if (jp2->meth == 1) - { - jp2->enumcs = cio_read(cio, 4); /* EnumCS */ - } - else - if (jp2->meth == 2) - { -/* skip PROFILE */ - skip_len = box->init_pos + box->length - cio_tell(cio); - if (skip_len < 0) - { - opj_event_msg(cinfo, EVT_ERROR, "Error with COLR box size\n"); - return OPJ_FALSE; - } - if(skip_len > 0) - { - unsigned char *start; - - start = cio_getbp(cio); - color->icc_profile_buf = (unsigned char*)opj_malloc(skip_len); - color->icc_profile_len = skip_len; - - cio_skip(cio, box->init_pos + box->length - cio_tell(cio)); - - memcpy(color->icc_profile_buf, start, skip_len); - } - } - - if (cio_tell(cio) - box->init_pos != box->length) - { - opj_event_msg(cinfo, EVT_ERROR, "Error with COLR Box\n"); - return OPJ_FALSE; - } - color->jp2_has_colr = 1; - - return OPJ_TRUE; -}/* jp2_read_colr() */ - -opj_bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color) -{ - opj_jp2_box_t box; - int jp2h_end; - - opj_common_ptr cinfo = jp2->cinfo; - - if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; - do { - if (JP2_JP2H != box.type) - { - if (box.type == JP2_JP2C) - { - opj_event_msg(cinfo, EVT_ERROR, "Expected JP2H Marker\n"); - return OPJ_FALSE; - } - cio_skip(cio, box.length - 8); - - if(cio->bp >= cio->end) return OPJ_FALSE; - - if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; - } - } while(JP2_JP2H != box.type); - - if (!jp2_read_ihdr(jp2, cio)) - return OPJ_FALSE; - jp2h_end = box.init_pos + box.length; - - if (jp2->bpc == 255) - { - if (!jp2_read_bpcc(jp2, cio)) - return OPJ_FALSE; - } - if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; - - while(cio_tell(cio) < jp2h_end) - { - if(box.type == JP2_COLR) - { - if( !jp2_read_colr(jp2, cio, &box, color)) - { - cio_seek(cio, box.init_pos + 8); - cio_skip(cio, box.length - 8); - } - if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; - continue; - } - if(box.type == JP2_CDEF && !jp2->ignore_pclr_cmap_cdef) - { - if( !jp2_read_cdef(jp2, cio, &box, color)) - { - cio_seek(cio, box.init_pos + 8); - cio_skip(cio, box.length - 8); - } - if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; - continue; - } - if(box.type == JP2_PCLR && !jp2->ignore_pclr_cmap_cdef) - { - if( !jp2_read_pclr(jp2, cio, &box, color)) - { - cio_seek(cio, box.init_pos + 8); - cio_skip(cio, box.length - 8); - } - if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; - continue; - } - if(box.type == JP2_CMAP && !jp2->ignore_pclr_cmap_cdef) - { - if( !jp2_read_cmap(jp2, cio, &box, color)) - { - cio_seek(cio, box.init_pos + 8); - cio_skip(cio, box.length - 8); - } - if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; - continue; - } - cio_seek(cio, box.init_pos + 8); - cio_skip(cio, box.length - 8); - if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; - - }/* while(cio_tell(cio) < box_end) */ - - cio_seek(cio, jp2h_end); - - /* Part 1, I.5.3.3 : 'must contain at least one' */ - return (color->jp2_has_colr == 1); - -}/* jp2_read_jp2h() */ - -opj_image_t* opj_jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio, - opj_codestream_info_t *cstr_info) -{ - opj_common_ptr cinfo; - opj_image_t *image = NULL; - opj_jp2_color_t color; - - if(!jp2 || !cio) - { - return NULL; - } - memset(&color, 0, sizeof(opj_jp2_color_t)); - cinfo = jp2->cinfo; - -/* JP2 decoding */ - if(!jp2_read_struct(jp2, cio, &color)) - { - free_color_data(&color); - opj_event_msg(cinfo, EVT_ERROR, "Failed to decode jp2 structure\n"); - return NULL; - } - -/* J2K decoding */ - image = j2k_decode(jp2->j2k, cio, cstr_info); - - if(!image) - { - free_color_data(&color); - opj_event_msg(cinfo, EVT_ERROR, "Failed to decode J2K image\n"); - return NULL; - } - - if (!jp2->ignore_pclr_cmap_cdef){ - - /* Set Image Color Space */ - if (jp2->enumcs == 16) - image->color_space = CLRSPC_SRGB; - else if (jp2->enumcs == 17) - image->color_space = CLRSPC_GRAY; - else if (jp2->enumcs == 18) - image->color_space = CLRSPC_SYCC; - else - image->color_space = CLRSPC_UNKNOWN; - - if(color.jp2_cdef) - { - jp2_apply_cdef(image, &color); - } - if(color.jp2_pclr) - { -/* Part 1, I.5.3.4: Either both or none : */ - if( !color.jp2_pclr->cmap) - jp2_free_pclr(&color); - else - jp2_apply_pclr(&color, image, cinfo); - } - if(color.icc_profile_buf) - { - image->icc_profile_buf = color.icc_profile_buf; - color.icc_profile_buf = NULL; - image->icc_profile_len = color.icc_profile_len; - } - } - - return image; - -}/* opj_jp2_decode() */ - - -void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) { - opj_jp2_box_t box; - - box.init_pos = cio_tell(cio); - cio_skip(cio, 4); - cio_write(cio, JP2_JP2H, 4); /* JP2H */ - - jp2_write_ihdr(jp2, cio); - - if (jp2->bpc == 255) { - jp2_write_bpcc(jp2, cio); - } - jp2_write_colr(jp2, cio); - - box.length = cio_tell(cio) - box.init_pos; - cio_seek(cio, box.init_pos); - cio_write(cio, box.length, 4); /* L */ - cio_seek(cio, box.init_pos + box.length); -} - -static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) { - unsigned int i; - opj_jp2_box_t box; - - box.init_pos = cio_tell(cio); - cio_skip(cio, 4); - cio_write(cio, JP2_FTYP, 4); /* FTYP */ - - cio_write(cio, jp2->brand, 4); /* BR */ - cio_write(cio, jp2->minversion, 4); /* MinV */ - - for (i = 0; i < jp2->numcl; i++) { - cio_write(cio, jp2->cl[i], 4); /* CL */ - } - - box.length = cio_tell(cio) - box.init_pos; - cio_seek(cio, box.init_pos); - cio_write(cio, box.length, 4); /* L */ - cio_seek(cio, box.init_pos + box.length); -} - -static opj_bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) { - int i; - opj_jp2_box_t box; - - opj_common_ptr cinfo = jp2->cinfo; - - if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) { - opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n"); - return OPJ_FALSE; - } - if (JP2_FTYP != box.type) { - opj_event_msg(cinfo, EVT_ERROR, "Expected FTYP Marker\n"); - return OPJ_FALSE; - } - - jp2->brand = cio_read(cio, 4); /* BR */ - jp2->minversion = cio_read(cio, 4); /* MinV */ - jp2->numcl = (box.length - 16) / 4; - jp2->cl = (unsigned int *) opj_malloc(jp2->numcl * sizeof(unsigned int)); - - for (i = 0; i < (int)jp2->numcl; i++) { - jp2->cl[i] = cio_read(cio, 4); /* CLi */ - } - - if (cio_tell(cio) - box.init_pos != box.length) { - opj_event_msg(cinfo, EVT_ERROR, "Error with FTYP Box\n"); - return OPJ_FALSE; - } - - return OPJ_TRUE; -} - -static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) { - unsigned int j2k_codestream_offset, j2k_codestream_length; - opj_jp2_box_t box; - - opj_j2k_t *j2k = jp2->j2k; - - box.init_pos = cio_tell(cio); - cio_skip(cio, 4); - cio_write(cio, JP2_JP2C, 4); /* JP2C */ - - /* J2K encoding */ - j2k_codestream_offset = cio_tell(cio); - if(!j2k_encode(j2k, cio, image, cstr_info)) { - opj_event_msg(j2k->cinfo, EVT_ERROR, "Failed to encode image\n"); - return 0; - } - j2k_codestream_length = cio_tell(cio) - j2k_codestream_offset; - - jp2->j2k_codestream_offset = j2k_codestream_offset; - jp2->j2k_codestream_length = j2k_codestream_length; - - box.length = 8 + jp2->j2k_codestream_length; - cio_seek(cio, box.init_pos); - cio_write(cio, box.length, 4); /* L */ - cio_seek(cio, box.init_pos + box.length); - - return box.length; -} - -static opj_bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset) { - opj_jp2_box_t box; - - opj_common_ptr cinfo = jp2->cinfo; - - if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) { - opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n"); - return OPJ_FALSE; - } - do { - if(JP2_JP2C != box.type) { - cio_skip(cio, box.length - 8); - if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; - } - } while(JP2_JP2C != box.type); - - *j2k_codestream_offset = cio_tell(cio); - *j2k_codestream_length = box.length - 8; - - return OPJ_TRUE; -} - -static void jp2_write_jp(opj_cio_t *cio) { - opj_jp2_box_t box; - - box.init_pos = cio_tell(cio); - cio_skip(cio, 4); - cio_write(cio, JP2_JP, 4); /* JP2 signature */ - cio_write(cio, 0x0d0a870a, 4); - - box.length = cio_tell(cio) - box.init_pos; - cio_seek(cio, box.init_pos); - cio_write(cio, box.length, 4); /* L */ - cio_seek(cio, box.init_pos + box.length); -} - -static opj_bool jp2_read_jp(opj_jp2_t *jp2, opj_cio_t *cio) { - opj_jp2_box_t box; - - opj_common_ptr cinfo = jp2->cinfo; - - if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) { - opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n"); - return OPJ_FALSE; - } - if (JP2_JP != box.type) { - opj_event_msg(cinfo, EVT_ERROR, "Expected JP Marker\n"); - return OPJ_FALSE; - } - if (0x0d0a870a != cio_read(cio, 4)) { - opj_event_msg(cinfo, EVT_ERROR, "Error with JP Marker\n"); - return OPJ_FALSE; - } - if (cio_tell(cio) - box.init_pos != box.length) { - opj_event_msg(cinfo, EVT_ERROR, "Error with JP Box size\n"); - return OPJ_FALSE; - } - - return OPJ_TRUE; -} - - -static opj_bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio, - opj_jp2_color_t *color) { - if (!jp2_read_jp(jp2, cio)) - return OPJ_FALSE; - if (!jp2_read_ftyp(jp2, cio)) - return OPJ_FALSE; - if (!jp2_read_jp2h(jp2, cio, color)) - return OPJ_FALSE; - if (!jp2_read_jp2c(jp2, cio, &jp2->j2k_codestream_length, &jp2->j2k_codestream_offset)) - return OPJ_FALSE; - - return OPJ_TRUE; -} - - -static int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio) -{ - int len, lenp; - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_FIDX, 4); /* IPTR */ - - write_prxy( offset_jp2c, length_jp2c, offset_idx, length_idx, cio); - - len = cio_tell( cio)-lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); - - return len; -} - -static void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio) -{ - int len, lenp; - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_PRXY, 4); /* IPTR */ - - cio_write( cio, offset_jp2c, 8); /* OOFF */ - cio_write( cio, length_jp2c, 4); /* OBH part 1 */ - cio_write( cio, JP2_JP2C, 4); /* OBH part 2 */ - - cio_write( cio, 1,1); /* NI */ - - cio_write( cio, offset_idx, 8); /* IOFF */ - cio_write( cio, length_idx, 4); /* IBH part 1 */ - cio_write( cio, JPIP_CIDX, 4); /* IBH part 2 */ - - len = cio_tell( cio)-lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); -} - -static void write_iptr( int offset, int length, opj_cio_t *cio) -{ - int len, lenp; - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_IPTR, 4); /* IPTR */ - - cio_write( cio, offset, 8); - cio_write( cio, length, 8); - - len = cio_tell( cio)-lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); -} - - -/* ----------------------------------------------------------------------- */ -/* JP2 decoder interface */ -/* ----------------------------------------------------------------------- */ - -opj_jp2_t* jp2_create_decompress(opj_common_ptr cinfo) { - opj_jp2_t *jp2 = (opj_jp2_t*) opj_calloc(1, sizeof(opj_jp2_t)); - if(jp2) { - jp2->cinfo = cinfo; - /* create the J2K codec */ - jp2->j2k = j2k_create_decompress(cinfo); - if(jp2->j2k == NULL) { - jp2_destroy_decompress(jp2); - return NULL; - } - } - return jp2; -} - -void jp2_destroy_decompress(opj_jp2_t *jp2) { - if(jp2) { - /* destroy the J2K codec */ - j2k_destroy_decompress(jp2->j2k); - - if(jp2->comps) { - opj_free(jp2->comps); - } - if(jp2->cl) { - opj_free(jp2->cl); - } - opj_free(jp2); - } -} - -void jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) { - /* setup the J2K codec */ - j2k_setup_decoder(jp2->j2k, parameters); - /* further JP2 initializations go here */ - jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG; -} - -/* ----------------------------------------------------------------------- */ -/* JP2 encoder interface */ -/* ----------------------------------------------------------------------- */ - -opj_jp2_t* jp2_create_compress(opj_common_ptr cinfo) { - opj_jp2_t *jp2 = (opj_jp2_t*)opj_malloc(sizeof(opj_jp2_t)); - if(jp2) { - jp2->cinfo = cinfo; - /* create the J2K codec */ - jp2->j2k = j2k_create_compress(cinfo); - if(jp2->j2k == NULL) { - jp2_destroy_compress(jp2); - return NULL; - } - } - return jp2; -} - -void jp2_destroy_compress(opj_jp2_t *jp2) { - if(jp2) { - /* destroy the J2K codec */ - j2k_destroy_compress(jp2->j2k); - - if(jp2->comps) { - opj_free(jp2->comps); - } - if(jp2->cl) { - opj_free(jp2->cl); - } - opj_free(jp2); - } -} - -void jp2_setup_encoder(opj_jp2_t *jp2, opj_cparameters_t *parameters, opj_image_t *image) { - int i; - int depth_0, sign; - - if(!jp2 || !parameters || !image) - return; - - /* setup the J2K codec */ - /* ------------------- */ - - /* Check if number of components respects standard */ - if (image->numcomps < 1 || image->numcomps > 16384) { - opj_event_msg(jp2->cinfo, EVT_ERROR, "Invalid number of components specified while setting up JP2 encoder\n"); - return; - } - - j2k_setup_encoder(jp2->j2k, parameters, image); - - /* setup the JP2 codec */ - /* ------------------- */ - - /* Profile box */ - - jp2->brand = JP2_JP2; /* BR */ - jp2->minversion = 0; /* MinV */ - jp2->numcl = 1; - jp2->cl = (unsigned int*) opj_malloc(jp2->numcl * sizeof(unsigned int)); - jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */ - - /* Image Header box */ - - jp2->numcomps = image->numcomps; /* NC */ - jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t)); - jp2->h = image->y1 - image->y0; /* HEIGHT */ - jp2->w = image->x1 - image->x0; /* WIDTH */ - /* BPC */ - depth_0 = image->comps[0].prec - 1; - sign = image->comps[0].sgnd; - jp2->bpc = depth_0 + (sign << 7); - for (i = 1; i < image->numcomps; i++) { - int depth = image->comps[i].prec - 1; - sign = image->comps[i].sgnd; - if (depth_0 != depth) - jp2->bpc = 255; - } - jp2->C = 7; /* C : Always 7 */ - jp2->UnkC = 0; /* UnkC, colorspace specified in colr box */ - jp2->IPR = 0; /* IPR, no intellectual property */ - - /* BitsPerComponent box */ - - for (i = 0; i < image->numcomps; i++) { - jp2->comps[i].bpcc = image->comps[i].prec - 1 + (image->comps[i].sgnd << 7); - } - jp2->meth = 1; - if (image->color_space == 1) - jp2->enumcs = 16; /* sRGB as defined by IEC 61966-2.1 */ - else if (image->color_space == 2) - jp2->enumcs = 17; /* greyscale */ - else if (image->color_space == 3) - jp2->enumcs = 18; /* YUV */ - jp2->precedence = 0; /* PRECEDENCE */ - jp2->approx = 0; /* APPROX */ - - jp2->jpip_on = parameters->jpip_on; -} - -opj_bool opj_jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) { - - int pos_iptr, pos_cidx, pos_jp2c, len_jp2c, len_cidx, end_pos, pos_fidx, len_fidx; - pos_jp2c = pos_iptr = -1; /* remove a warning */ - - /* JP2 encoding */ - - /* JPEG 2000 Signature box */ - jp2_write_jp(cio); - /* File Type box */ - jp2_write_ftyp(jp2, cio); - /* JP2 Header box */ - jp2_write_jp2h(jp2, cio); - - if( jp2->jpip_on){ - pos_iptr = cio_tell( cio); - cio_skip( cio, 24); /* IPTR further ! */ - - pos_jp2c = cio_tell( cio); - } - - /* J2K encoding */ - if(!(len_jp2c = jp2_write_jp2c( jp2, cio, image, cstr_info))){ - opj_event_msg(jp2->cinfo, EVT_ERROR, "Failed to encode image\n"); - return OPJ_FALSE; - } - - if( jp2->jpip_on){ - pos_cidx = cio_tell( cio); - - len_cidx = write_cidx( pos_jp2c+8, cio, image, *cstr_info, len_jp2c-8); - - pos_fidx = cio_tell( cio); - len_fidx = write_fidx( pos_jp2c, len_jp2c, pos_cidx, len_cidx, cio); - - end_pos = cio_tell( cio); - - cio_seek( cio, pos_iptr); - write_iptr( pos_fidx, len_fidx, cio); - - cio_seek( cio, end_pos); - } - - return OPJ_TRUE; -} +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2010-2011, Kaori Hagihara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include "opj_includes.h" + +/** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */ +/*@{*/ + +/** @name Local static functions */ +/*@{*/ + +/** +Read box headers +@param cinfo Codec context info +@param cio Input stream +@param box +@return Returns true if successful, returns false otherwise +*/ +static opj_bool jp2_read_boxhdr(opj_common_ptr cinfo, opj_cio_t *cio, opj_jp2_box_t *box); +/*static void jp2_write_url(opj_cio_t *cio, char *Idx_file);*/ +/** +Read the IHDR box - Image Header box +@param jp2 JP2 handle +@param cio Input buffer stream +@return Returns true if successful, returns false otherwise +*/ +static opj_bool jp2_read_ihdr(opj_jp2_t *jp2, opj_cio_t *cio); +static void jp2_write_ihdr(opj_jp2_t *jp2, opj_cio_t *cio); +static void jp2_write_bpcc(opj_jp2_t *jp2, opj_cio_t *cio); +static opj_bool jp2_read_bpcc(opj_jp2_t *jp2, opj_cio_t *cio); +static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio); +/** +Write the FTYP box - File type box +@param jp2 JP2 handle +@param cio Output buffer stream +*/ +static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio); +/** +Read the FTYP box - File type box +@param jp2 JP2 handle +@param cio Input buffer stream +@return Returns true if successful, returns false otherwise +*/ +static opj_bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio); +static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info); +static opj_bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset); +static void jp2_write_jp(opj_cio_t *cio); +/** +Read the JP box - JPEG 2000 signature +@param jp2 JP2 handle +@param cio Input buffer stream +@return Returns true if successful, returns false otherwise +*/ +static opj_bool jp2_read_jp(opj_jp2_t *jp2, opj_cio_t *cio); +/** +Decode the structure of a JP2 file +@param jp2 JP2 handle +@param cio Input buffer stream +@param color Collector for profile, cdef and pclr data +@return Returns true if successful, returns false otherwise +*/ +static opj_bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio, + opj_jp2_color_t *color); +/** +Apply collected palette data +@param color Collector for profile, cdef and pclr data +@param image +*/ +static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image, opj_common_ptr cinfo); +/** +Collect palette data +@param jp2 JP2 handle +@param cio Input buffer stream +@param box +@param color Collector for profile, cdef and pclr data +@return Returns true if successful, returns false otherwise +*/ +static opj_bool jp2_read_pclr(opj_jp2_t *jp2, opj_cio_t *cio, + opj_jp2_box_t *box, opj_jp2_color_t *color); +/** +Collect component mapping data +@param jp2 JP2 handle +@param cio Input buffer stream +@param box +@param color Collector for profile, cdef and pclr data +@return Returns true if successful, returns false otherwise +*/ +static opj_bool jp2_read_cmap(opj_jp2_t *jp2, opj_cio_t *cio, + opj_jp2_box_t *box, opj_jp2_color_t *color); +/** +Collect colour specification data +@param jp2 JP2 handle +@param cio Input buffer stream +@param box +@param color Collector for profile, cdef and pclr data +@return Returns true if successful, returns false otherwise +*/ +static opj_bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio, + opj_jp2_box_t *box, opj_jp2_color_t *color); +/** +Write file Index (superbox) +@param[in] offset_jp2c offset of jp2c box +@param[in] length_jp2c length of jp2c box +@param[in] offset_idx offset of cidx box +@param[in] length_idx length of cidx box +@param[in] cio file output handle +@return length of fidx box +*/ +static int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio); +/** +Write index Finder box +@param[in] offset offset of fidx box +@param[in] length length of fidx box +@param[in] cio file output handle +*/ +static void write_iptr( int offset, int length, opj_cio_t *cio); +/** +Write proxy box +@param[in] offset_jp2c offset of jp2c box +@param[in] length_jp2c length of jp2c box +@param[in] offset_idx offset of cidx box +@param[in] length_idx length of cidx box +@param[in] cio file output handle +*/ +static void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio); +/*@}*/ + +/*@}*/ + +/* ----------------------------------------------------------------------- */ + +static opj_bool jp2_read_boxhdr(opj_common_ptr cinfo, opj_cio_t *cio, opj_jp2_box_t *box) { + box->init_pos = cio_tell(cio); + box->length = cio_read(cio, 4); + box->type = cio_read(cio, 4); + if (box->length == 1) { + if (cio_read(cio, 4) != 0) { + opj_event_msg(cinfo, EVT_ERROR, "Cannot handle box sizes higher than 2^32\n"); + return OPJ_FALSE; + } + box->length = cio_read(cio, 4); + if (box->length == 0) + box->length = cio_numbytesleft(cio) + 12; + } + else if (box->length == 0) { + box->length = cio_numbytesleft(cio) + 8; + } + + return OPJ_TRUE; +} + +#if 0 +static void jp2_write_url(opj_cio_t *cio, char *Idx_file) { + unsigned int i; + opj_jp2_box_t box; + + box.init_pos = cio_tell(cio); + cio_skip(cio, 4); + cio_write(cio, JP2_URL, 4); /* DBTL */ + cio_write(cio, 0, 1); /* VERS */ + cio_write(cio, 0, 3); /* FLAG */ + + if(Idx_file) { + for (i = 0; i < strlen(Idx_file); i++) { + cio_write(cio, Idx_file[i], 1); + } + } + + box.length = cio_tell(cio) - box.init_pos; + cio_seek(cio, box.init_pos); + cio_write(cio, box.length, 4); /* L */ + cio_seek(cio, box.init_pos + box.length); +} +#endif + +static opj_bool jp2_read_ihdr(opj_jp2_t *jp2, opj_cio_t *cio) { + opj_jp2_box_t box; + + opj_common_ptr cinfo = jp2->cinfo; + + if(jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) { + opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n"); + return OPJ_FALSE; + } + if (JP2_IHDR != box.type) { + opj_event_msg(cinfo, EVT_ERROR, "Expected IHDR Marker\n"); + return OPJ_FALSE; + } + + jp2->h = cio_read(cio, 4); /* HEIGHT */ + jp2->w = cio_read(cio, 4); /* WIDTH */ + jp2->numcomps = cio_read(cio, 2); /* NC */ + jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t)); + + jp2->bpc = cio_read(cio, 1); /* BPC */ + + jp2->C = cio_read(cio, 1); /* C */ + jp2->UnkC = cio_read(cio, 1); /* UnkC */ + jp2->IPR = cio_read(cio, 1); /* IPR */ + + if (cio_tell(cio) - box.init_pos != box.length) { + opj_event_msg(cinfo, EVT_ERROR, "Error with IHDR Box\n"); + return OPJ_FALSE; + } + + return OPJ_TRUE; +} + +static void jp2_write_ihdr(opj_jp2_t *jp2, opj_cio_t *cio) { + opj_jp2_box_t box; + + box.init_pos = cio_tell(cio); + cio_skip(cio, 4); + cio_write(cio, JP2_IHDR, 4); /* IHDR */ + + cio_write(cio, jp2->h, 4); /* HEIGHT */ + cio_write(cio, jp2->w, 4); /* WIDTH */ + cio_write(cio, jp2->numcomps, 2); /* NC */ + + cio_write(cio, jp2->bpc, 1); /* BPC */ + + cio_write(cio, jp2->C, 1); /* C : Always 7 */ + cio_write(cio, jp2->UnkC, 1); /* UnkC, colorspace unknown */ + cio_write(cio, jp2->IPR, 1); /* IPR, no intellectual property */ + + box.length = cio_tell(cio) - box.init_pos; + cio_seek(cio, box.init_pos); + cio_write(cio, box.length, 4); /* L */ + cio_seek(cio, box.init_pos + box.length); +} + +static void jp2_write_bpcc(opj_jp2_t *jp2, opj_cio_t *cio) { + unsigned int i; + opj_jp2_box_t box; + + box.init_pos = cio_tell(cio); + cio_skip(cio, 4); + cio_write(cio, JP2_BPCC, 4); /* BPCC */ + + for (i = 0; i < jp2->numcomps; i++) { + cio_write(cio, jp2->comps[i].bpcc, 1); + } + + box.length = cio_tell(cio) - box.init_pos; + cio_seek(cio, box.init_pos); + cio_write(cio, box.length, 4); /* L */ + cio_seek(cio, box.init_pos + box.length); +} + + +static opj_bool jp2_read_bpcc(opj_jp2_t *jp2, opj_cio_t *cio) { + unsigned int i; + opj_jp2_box_t box; + + opj_common_ptr cinfo = jp2->cinfo; + + if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) { + opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n"); + return OPJ_FALSE; + } + if (JP2_BPCC != box.type) { + opj_event_msg(cinfo, EVT_ERROR, "Expected BPCC Marker\n"); + return OPJ_FALSE; + } + + for (i = 0; i < jp2->numcomps; i++) { + jp2->comps[i].bpcc = cio_read(cio, 1); + } + + if (cio_tell(cio) - box.init_pos != box.length) { + opj_event_msg(cinfo, EVT_ERROR, "Error with BPCC Box\n"); + return OPJ_FALSE; + } + + return OPJ_TRUE; +} + +static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio) { + opj_jp2_box_t box; + + box.init_pos = cio_tell(cio); + cio_skip(cio, 4); + cio_write(cio, JP2_COLR, 4); /* COLR */ + + cio_write(cio, jp2->meth, 1); /* METH */ + cio_write(cio, jp2->precedence, 1); /* PRECEDENCE */ + cio_write(cio, jp2->approx, 1); /* APPROX */ + + if(jp2->meth == 2) + jp2->enumcs = 0; + + cio_write(cio, jp2->enumcs, 4); /* EnumCS */ + + box.length = cio_tell(cio) - box.init_pos; + cio_seek(cio, box.init_pos); + cio_write(cio, box.length, 4); /* L */ + cio_seek(cio, box.init_pos + box.length); +} + +static void jp2_free_pclr(opj_jp2_color_t *color) +{ + opj_free(color->jp2_pclr->channel_sign); + opj_free(color->jp2_pclr->channel_size); + opj_free(color->jp2_pclr->entries); + + if(color->jp2_pclr->cmap) opj_free(color->jp2_pclr->cmap); + + opj_free(color->jp2_pclr); color->jp2_pclr = NULL; +} + +static void free_color_data(opj_jp2_color_t *color) +{ + if(color->jp2_pclr) + { + jp2_free_pclr(color); + } + if(color->jp2_cdef) + { + if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info); + opj_free(color->jp2_cdef); + } + if(color->icc_profile_buf) opj_free(color->icc_profile_buf); +} + +static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image, opj_common_ptr cinfo) +{ + opj_image_comp_t *old_comps, *new_comps; + unsigned char *channel_size, *channel_sign; + unsigned int *entries; + opj_jp2_cmap_comp_t *cmap; + int *src, *dst; + unsigned int j, max; + unsigned short i, nr_channels, cmp, pcol; + int k, top_k; + + channel_size = color->jp2_pclr->channel_size; + channel_sign = color->jp2_pclr->channel_sign; + entries = color->jp2_pclr->entries; + cmap = color->jp2_pclr->cmap; + nr_channels = color->jp2_pclr->nr_channels; + + old_comps = image->comps; + new_comps = (opj_image_comp_t*) + opj_malloc(nr_channels * sizeof(opj_image_comp_t)); + + for(i = 0; i < nr_channels; ++i) + { + pcol = cmap[i].pcol; cmp = cmap[i].cmp; + + if( pcol < nr_channels ) + new_comps[pcol] = old_comps[cmp]; + else + { + opj_event_msg(cinfo, EVT_ERROR, "Error with pcol value %d (max: %d). skipping\n", pcol, nr_channels); + continue; + } + + if(cmap[i].mtyp == 0) /* Direct use */ + { + old_comps[cmp].data = NULL; continue; + } +/* Palette mapping: */ + new_comps[pcol].data = (int*) + opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(int)); + new_comps[pcol].prec = channel_size[i]; + new_comps[pcol].sgnd = channel_sign[i]; + } + top_k = color->jp2_pclr->nr_entries - 1; + + for(i = 0; i < nr_channels; ++i) + { +/* Direct use: */ + if(cmap[i].mtyp == 0) continue; + +/* Palette mapping: */ + cmp = cmap[i].cmp; pcol = cmap[i].pcol; + src = old_comps[cmp].data; + dst = new_comps[pcol].data; + max = new_comps[pcol].w * new_comps[pcol].h; + + for(j = 0; j < max; ++j) + { +/* The index */ + if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k; +/* The colour */ + dst[j] = entries[k * nr_channels + pcol]; + } + } + max = image->numcomps; + for(i = 0; i < max; ++i) + { + if(old_comps[i].data) opj_free(old_comps[i].data); + } + opj_free(old_comps); + image->comps = new_comps; + image->numcomps = nr_channels; + + jp2_free_pclr(color); + +}/* apply_pclr() */ + +static opj_bool jp2_read_pclr(opj_jp2_t *jp2, opj_cio_t *cio, + opj_jp2_box_t *box, opj_jp2_color_t *color) +{ + opj_jp2_pclr_t *jp2_pclr; + unsigned char *channel_size, *channel_sign; + unsigned int *entries; + unsigned short nr_entries, nr_channels; + unsigned short i, j; + unsigned char uc; + + OPJ_ARG_NOT_USED(box); + OPJ_ARG_NOT_USED(jp2); + +/* Part 1, I.5.3.4: 'There shall be at most one Palette box inside + * a JP2 Header box' : +*/ + if(color->jp2_pclr) return OPJ_FALSE; + + nr_entries = (unsigned short)cio_read(cio, 2); /* NE */ + nr_channels = (unsigned short)cio_read(cio, 1);/* NPC */ + + entries = (unsigned int*) + opj_malloc(nr_channels * nr_entries * sizeof(unsigned int)); + channel_size = (unsigned char*)opj_malloc(nr_channels); + channel_sign = (unsigned char*)opj_malloc(nr_channels); + + jp2_pclr = (opj_jp2_pclr_t*)opj_malloc(sizeof(opj_jp2_pclr_t)); + jp2_pclr->channel_sign = channel_sign; + jp2_pclr->channel_size = channel_size; + jp2_pclr->entries = entries; + jp2_pclr->nr_entries = nr_entries; + jp2_pclr->nr_channels = nr_channels; + jp2_pclr->cmap = NULL; + + color->jp2_pclr = jp2_pclr; + + for(i = 0; i < nr_channels; ++i) + { + uc = cio_read(cio, 1); /* Bi */ + channel_size[i] = (uc & 0x7f) + 1; + channel_sign[i] = (uc & 0x80)?1:0; + } + + for(j = 0; j < nr_entries; ++j) + { + for(i = 0; i < nr_channels; ++i) + { +/* Cji */ + *entries++ = cio_read(cio, (channel_size[i]+7)>>3); + } + } + + return OPJ_TRUE; +}/* jp2_read_pclr() */ + +static opj_bool jp2_read_cmap(opj_jp2_t *jp2, opj_cio_t *cio, + opj_jp2_box_t *box, opj_jp2_color_t *color) +{ + opj_jp2_cmap_comp_t *cmap; + unsigned short i, nr_channels; + + OPJ_ARG_NOT_USED(box); + OPJ_ARG_NOT_USED(jp2); + +/* Need nr_channels: */ + if(color->jp2_pclr == NULL) return OPJ_FALSE; + +/* Part 1, I.5.3.5: 'There shall be at most one Component Mapping box + * inside a JP2 Header box' : +*/ + if(color->jp2_pclr->cmap) return OPJ_FALSE; + + nr_channels = color->jp2_pclr->nr_channels; + cmap = (opj_jp2_cmap_comp_t*) + opj_malloc(nr_channels * sizeof(opj_jp2_cmap_comp_t)); + + for(i = 0; i < nr_channels; ++i) + { + cmap[i].cmp = (unsigned short)cio_read(cio, 2); + cmap[i].mtyp = cio_read(cio, 1); + cmap[i].pcol = cio_read(cio, 1); + + } + color->jp2_pclr->cmap = cmap; + + return OPJ_TRUE; +}/* jp2_read_cmap() */ + +static void jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color) +{ + opj_jp2_cdef_info_t *info; + int color_space; + unsigned short i, n, cn, typ, asoc, acn; + + color_space = image->color_space; + info = color->jp2_cdef->info; + n = color->jp2_cdef->n; + + for(i = 0; i < n; ++i) + { +/* WATCH: acn = asoc - 1 ! */ + if((asoc = info[i].asoc) == 0) continue; + + cn = info[i].cn; typ = info[i].typ; acn = asoc - 1; + + if(cn != acn) + { + opj_image_comp_t saved; + + memcpy(&saved, &image->comps[cn], sizeof(opj_image_comp_t)); + memcpy(&image->comps[cn], &image->comps[acn], sizeof(opj_image_comp_t)); + memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t)); + + info[i].asoc = cn + 1; + info[acn].asoc = info[acn].cn + 1; + } + } + if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info); + + opj_free(color->jp2_cdef); color->jp2_cdef = NULL; + +}/* jp2_apply_cdef() */ + +static opj_bool jp2_read_cdef(opj_jp2_t *jp2, opj_cio_t *cio, + opj_jp2_box_t *box, opj_jp2_color_t *color) +{ + opj_jp2_cdef_info_t *info; + unsigned short i, n; + + OPJ_ARG_NOT_USED(box); + OPJ_ARG_NOT_USED(jp2); + +/* Part 1, I.5.3.6: 'The shall be at most one Channel Definition box + * inside a JP2 Header box.' +*/ + if(color->jp2_cdef) return OPJ_FALSE; + + if((n = (unsigned short)cio_read(cio, 2)) == 0) return OPJ_FALSE; /* szukw000: FIXME */ + + info = (opj_jp2_cdef_info_t*) + opj_malloc(n * sizeof(opj_jp2_cdef_info_t)); + + color->jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t)); + color->jp2_cdef->info = info; + color->jp2_cdef->n = n; + + for(i = 0; i < n; ++i) + { + info[i].cn = (unsigned short)cio_read(cio, 2); + info[i].typ = (unsigned short)cio_read(cio, 2); + info[i].asoc = (unsigned short)cio_read(cio, 2); + + } + return OPJ_TRUE; +}/* jp2_read_cdef() */ + +static opj_bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio, + opj_jp2_box_t *box, opj_jp2_color_t *color) +{ + int skip_len; + opj_common_ptr cinfo; + +/* Part 1, I.5.3.3 : 'A conforming JP2 reader shall ignore all Colour + * Specification boxes after the first.' +*/ + if(color->jp2_has_colr) return OPJ_FALSE; + + cinfo = jp2->cinfo; + + jp2->meth = cio_read(cio, 1); /* METH */ + jp2->precedence = cio_read(cio, 1); /* PRECEDENCE */ + jp2->approx = cio_read(cio, 1); /* APPROX */ + + if (jp2->meth == 1) + { + jp2->enumcs = cio_read(cio, 4); /* EnumCS */ + } + else + if (jp2->meth == 2) + { +/* skip PROFILE */ + skip_len = box->init_pos + box->length - cio_tell(cio); + if (skip_len < 0) + { + opj_event_msg(cinfo, EVT_ERROR, "Error with COLR box size\n"); + return OPJ_FALSE; + } + if(skip_len > 0) + { + unsigned char *start; + + start = cio_getbp(cio); + color->icc_profile_buf = (unsigned char*)opj_malloc(skip_len); + color->icc_profile_len = skip_len; + + cio_skip(cio, box->init_pos + box->length - cio_tell(cio)); + + memcpy(color->icc_profile_buf, start, skip_len); + } + } + + if (cio_tell(cio) - box->init_pos != box->length) + { + opj_event_msg(cinfo, EVT_ERROR, "Error with COLR Box\n"); + return OPJ_FALSE; + } + color->jp2_has_colr = 1; + + return OPJ_TRUE; +}/* jp2_read_colr() */ + +opj_bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color) +{ + opj_jp2_box_t box; + int jp2h_end; + + opj_common_ptr cinfo = jp2->cinfo; + + if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; + do { + if (JP2_JP2H != box.type) + { + if (box.type == JP2_JP2C) + { + opj_event_msg(cinfo, EVT_ERROR, "Expected JP2H Marker\n"); + return OPJ_FALSE; + } + cio_skip(cio, box.length - 8); + + if(cio->bp >= cio->end) return OPJ_FALSE; + + if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; + } + } while(JP2_JP2H != box.type); + + if (!jp2_read_ihdr(jp2, cio)) + return OPJ_FALSE; + jp2h_end = box.init_pos + box.length; + + if (jp2->bpc == 255) + { + if (!jp2_read_bpcc(jp2, cio)) + return OPJ_FALSE; + } + if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; + + while(cio_tell(cio) < jp2h_end) + { + if(box.type == JP2_COLR) + { + if( !jp2_read_colr(jp2, cio, &box, color)) + { + cio_seek(cio, box.init_pos + 8); + cio_skip(cio, box.length - 8); + } + if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; + continue; + } + if(box.type == JP2_CDEF && !jp2->ignore_pclr_cmap_cdef) + { + if( !jp2_read_cdef(jp2, cio, &box, color)) + { + cio_seek(cio, box.init_pos + 8); + cio_skip(cio, box.length - 8); + } + if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; + continue; + } + if(box.type == JP2_PCLR && !jp2->ignore_pclr_cmap_cdef) + { + if( !jp2_read_pclr(jp2, cio, &box, color)) + { + cio_seek(cio, box.init_pos + 8); + cio_skip(cio, box.length - 8); + } + if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; + continue; + } + if(box.type == JP2_CMAP && !jp2->ignore_pclr_cmap_cdef) + { + if( !jp2_read_cmap(jp2, cio, &box, color)) + { + cio_seek(cio, box.init_pos + 8); + cio_skip(cio, box.length - 8); + } + if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; + continue; + } + cio_seek(cio, box.init_pos + 8); + cio_skip(cio, box.length - 8); + if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; + + }/* while(cio_tell(cio) < box_end) */ + + cio_seek(cio, jp2h_end); + + /* Part 1, I.5.3.3 : 'must contain at least one' */ + return (color->jp2_has_colr == 1); + +}/* jp2_read_jp2h() */ + +opj_image_t* opj_jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio, + opj_codestream_info_t *cstr_info) +{ + opj_common_ptr cinfo; + opj_image_t *image = NULL; + opj_jp2_color_t color; + + if(!jp2 || !cio) + { + return NULL; + } + memset(&color, 0, sizeof(opj_jp2_color_t)); + cinfo = jp2->cinfo; + +/* JP2 decoding */ + if(!jp2_read_struct(jp2, cio, &color)) + { + free_color_data(&color); + opj_event_msg(cinfo, EVT_ERROR, "Failed to decode jp2 structure\n"); + return NULL; + } + +/* J2K decoding */ + image = j2k_decode(jp2->j2k, cio, cstr_info); + + if(!image) + { + free_color_data(&color); + opj_event_msg(cinfo, EVT_ERROR, "Failed to decode J2K image\n"); + return NULL; + } + + if (!jp2->ignore_pclr_cmap_cdef){ + + /* Set Image Color Space */ + if (jp2->enumcs == 16) + image->color_space = CLRSPC_SRGB; + else if (jp2->enumcs == 17) + image->color_space = CLRSPC_GRAY; + else if (jp2->enumcs == 18) + image->color_space = CLRSPC_SYCC; + else + image->color_space = CLRSPC_UNKNOWN; + + if(color.jp2_cdef) + { + jp2_apply_cdef(image, &color); + } + if(color.jp2_pclr) + { +/* Part 1, I.5.3.4: Either both or none : */ + if( !color.jp2_pclr->cmap) + jp2_free_pclr(&color); + else + jp2_apply_pclr(&color, image, cinfo); + } + if(color.icc_profile_buf) + { + image->icc_profile_buf = color.icc_profile_buf; + color.icc_profile_buf = NULL; + image->icc_profile_len = color.icc_profile_len; + } + } + + return image; + +}/* opj_jp2_decode() */ + + +void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) { + opj_jp2_box_t box; + + box.init_pos = cio_tell(cio); + cio_skip(cio, 4); + cio_write(cio, JP2_JP2H, 4); /* JP2H */ + + jp2_write_ihdr(jp2, cio); + + if (jp2->bpc == 255) { + jp2_write_bpcc(jp2, cio); + } + jp2_write_colr(jp2, cio); + + box.length = cio_tell(cio) - box.init_pos; + cio_seek(cio, box.init_pos); + cio_write(cio, box.length, 4); /* L */ + cio_seek(cio, box.init_pos + box.length); +} + +static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) { + unsigned int i; + opj_jp2_box_t box; + + box.init_pos = cio_tell(cio); + cio_skip(cio, 4); + cio_write(cio, JP2_FTYP, 4); /* FTYP */ + + cio_write(cio, jp2->brand, 4); /* BR */ + cio_write(cio, jp2->minversion, 4); /* MinV */ + + for (i = 0; i < jp2->numcl; i++) { + cio_write(cio, jp2->cl[i], 4); /* CL */ + } + + box.length = cio_tell(cio) - box.init_pos; + cio_seek(cio, box.init_pos); + cio_write(cio, box.length, 4); /* L */ + cio_seek(cio, box.init_pos + box.length); +} + +static opj_bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) { + int i; + opj_jp2_box_t box; + + opj_common_ptr cinfo = jp2->cinfo; + + if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) { + opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n"); + return OPJ_FALSE; + } + if (JP2_FTYP != box.type) { + opj_event_msg(cinfo, EVT_ERROR, "Expected FTYP Marker\n"); + return OPJ_FALSE; + } + + jp2->brand = cio_read(cio, 4); /* BR */ + jp2->minversion = cio_read(cio, 4); /* MinV */ + jp2->numcl = (box.length - 16) / 4; + jp2->cl = (unsigned int *) opj_malloc(jp2->numcl * sizeof(unsigned int)); + + for (i = 0; i < (int)jp2->numcl; i++) { + jp2->cl[i] = cio_read(cio, 4); /* CLi */ + } + + if (cio_tell(cio) - box.init_pos != box.length) { + opj_event_msg(cinfo, EVT_ERROR, "Error with FTYP Box\n"); + return OPJ_FALSE; + } + + return OPJ_TRUE; +} + +static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) { + unsigned int j2k_codestream_offset, j2k_codestream_length; + opj_jp2_box_t box; + + opj_j2k_t *j2k = jp2->j2k; + + box.init_pos = cio_tell(cio); + cio_skip(cio, 4); + cio_write(cio, JP2_JP2C, 4); /* JP2C */ + + /* J2K encoding */ + j2k_codestream_offset = cio_tell(cio); + if(!j2k_encode(j2k, cio, image, cstr_info)) { + opj_event_msg(j2k->cinfo, EVT_ERROR, "Failed to encode image\n"); + return 0; + } + j2k_codestream_length = cio_tell(cio) - j2k_codestream_offset; + + jp2->j2k_codestream_offset = j2k_codestream_offset; + jp2->j2k_codestream_length = j2k_codestream_length; + + box.length = 8 + jp2->j2k_codestream_length; + cio_seek(cio, box.init_pos); + cio_write(cio, box.length, 4); /* L */ + cio_seek(cio, box.init_pos + box.length); + + return box.length; +} + +static opj_bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset) { + opj_jp2_box_t box; + + opj_common_ptr cinfo = jp2->cinfo; + + if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) { + opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n"); + return OPJ_FALSE; + } + do { + if(JP2_JP2C != box.type) { + cio_skip(cio, box.length - 8); + if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE; + } + } while(JP2_JP2C != box.type); + + *j2k_codestream_offset = cio_tell(cio); + *j2k_codestream_length = box.length - 8; + + return OPJ_TRUE; +} + +static void jp2_write_jp(opj_cio_t *cio) { + opj_jp2_box_t box; + + box.init_pos = cio_tell(cio); + cio_skip(cio, 4); + cio_write(cio, JP2_JP, 4); /* JP2 signature */ + cio_write(cio, 0x0d0a870a, 4); + + box.length = cio_tell(cio) - box.init_pos; + cio_seek(cio, box.init_pos); + cio_write(cio, box.length, 4); /* L */ + cio_seek(cio, box.init_pos + box.length); +} + +static opj_bool jp2_read_jp(opj_jp2_t *jp2, opj_cio_t *cio) { + opj_jp2_box_t box; + + opj_common_ptr cinfo = jp2->cinfo; + + if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) { + opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n"); + return OPJ_FALSE; + } + if (JP2_JP != box.type) { + opj_event_msg(cinfo, EVT_ERROR, "Expected JP Marker\n"); + return OPJ_FALSE; + } + if (0x0d0a870a != cio_read(cio, 4)) { + opj_event_msg(cinfo, EVT_ERROR, "Error with JP Marker\n"); + return OPJ_FALSE; + } + if (cio_tell(cio) - box.init_pos != box.length) { + opj_event_msg(cinfo, EVT_ERROR, "Error with JP Box size\n"); + return OPJ_FALSE; + } + + return OPJ_TRUE; +} + + +static opj_bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio, + opj_jp2_color_t *color) { + if (!jp2_read_jp(jp2, cio)) + return OPJ_FALSE; + if (!jp2_read_ftyp(jp2, cio)) + return OPJ_FALSE; + if (!jp2_read_jp2h(jp2, cio, color)) + return OPJ_FALSE; + if (!jp2_read_jp2c(jp2, cio, &jp2->j2k_codestream_length, &jp2->j2k_codestream_offset)) + return OPJ_FALSE; + + return OPJ_TRUE; +} + + +static int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio) +{ + int len, lenp; + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_FIDX, 4); /* IPTR */ + + write_prxy( offset_jp2c, length_jp2c, offset_idx, length_idx, cio); + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); + + return len; +} + +static void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio) +{ + int len, lenp; + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_PRXY, 4); /* IPTR */ + + cio_write( cio, offset_jp2c, 8); /* OOFF */ + cio_write( cio, length_jp2c, 4); /* OBH part 1 */ + cio_write( cio, JP2_JP2C, 4); /* OBH part 2 */ + + cio_write( cio, 1,1); /* NI */ + + cio_write( cio, offset_idx, 8); /* IOFF */ + cio_write( cio, length_idx, 4); /* IBH part 1 */ + cio_write( cio, JPIP_CIDX, 4); /* IBH part 2 */ + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); +} + +static void write_iptr( int offset, int length, opj_cio_t *cio) +{ + int len, lenp; + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_IPTR, 4); /* IPTR */ + + cio_write( cio, offset, 8); + cio_write( cio, length, 8); + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); +} + + +/* ----------------------------------------------------------------------- */ +/* JP2 decoder interface */ +/* ----------------------------------------------------------------------- */ + +opj_jp2_t* jp2_create_decompress(opj_common_ptr cinfo) { + opj_jp2_t *jp2 = (opj_jp2_t*) opj_calloc(1, sizeof(opj_jp2_t)); + if(jp2) { + jp2->cinfo = cinfo; + /* create the J2K codec */ + jp2->j2k = j2k_create_decompress(cinfo); + if(jp2->j2k == NULL) { + jp2_destroy_decompress(jp2); + return NULL; + } + } + return jp2; +} + +void jp2_destroy_decompress(opj_jp2_t *jp2) { + if(jp2) { + /* destroy the J2K codec */ + j2k_destroy_decompress(jp2->j2k); + + if(jp2->comps) { + opj_free(jp2->comps); + } + if(jp2->cl) { + opj_free(jp2->cl); + } + opj_free(jp2); + } +} + +void jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) { + /* setup the J2K codec */ + j2k_setup_decoder(jp2->j2k, parameters); + /* further JP2 initializations go here */ + jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG; +} + +/* ----------------------------------------------------------------------- */ +/* JP2 encoder interface */ +/* ----------------------------------------------------------------------- */ + +opj_jp2_t* jp2_create_compress(opj_common_ptr cinfo) { + opj_jp2_t *jp2 = (opj_jp2_t*)opj_malloc(sizeof(opj_jp2_t)); + if(jp2) { + jp2->cinfo = cinfo; + /* create the J2K codec */ + jp2->j2k = j2k_create_compress(cinfo); + if(jp2->j2k == NULL) { + jp2_destroy_compress(jp2); + return NULL; + } + } + return jp2; +} + +void jp2_destroy_compress(opj_jp2_t *jp2) { + if(jp2) { + /* destroy the J2K codec */ + j2k_destroy_compress(jp2->j2k); + + if(jp2->comps) { + opj_free(jp2->comps); + } + if(jp2->cl) { + opj_free(jp2->cl); + } + opj_free(jp2); + } +} + +void jp2_setup_encoder(opj_jp2_t *jp2, opj_cparameters_t *parameters, opj_image_t *image) { + int i; + int depth_0, sign; + + if(!jp2 || !parameters || !image) + return; + + /* setup the J2K codec */ + /* ------------------- */ + + /* Check if number of components respects standard */ + if (image->numcomps < 1 || image->numcomps > 16384) { + opj_event_msg(jp2->cinfo, EVT_ERROR, "Invalid number of components specified while setting up JP2 encoder\n"); + return; + } + + j2k_setup_encoder(jp2->j2k, parameters, image); + + /* setup the JP2 codec */ + /* ------------------- */ + + /* Profile box */ + + jp2->brand = JP2_JP2; /* BR */ + jp2->minversion = 0; /* MinV */ + jp2->numcl = 1; + jp2->cl = (unsigned int*) opj_malloc(jp2->numcl * sizeof(unsigned int)); + jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */ + + /* Image Header box */ + + jp2->numcomps = image->numcomps; /* NC */ + jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t)); + jp2->h = image->y1 - image->y0; /* HEIGHT */ + jp2->w = image->x1 - image->x0; /* WIDTH */ + /* BPC */ + depth_0 = image->comps[0].prec - 1; + sign = image->comps[0].sgnd; + jp2->bpc = depth_0 + (sign << 7); + for (i = 1; i < image->numcomps; i++) { + int depth = image->comps[i].prec - 1; + sign = image->comps[i].sgnd; + if (depth_0 != depth) + jp2->bpc = 255; + } + jp2->C = 7; /* C : Always 7 */ + jp2->UnkC = 0; /* UnkC, colorspace specified in colr box */ + jp2->IPR = 0; /* IPR, no intellectual property */ + + /* BitsPerComponent box */ + + for (i = 0; i < image->numcomps; i++) { + jp2->comps[i].bpcc = image->comps[i].prec - 1 + (image->comps[i].sgnd << 7); + } + jp2->meth = 1; + if (image->color_space == 1) + jp2->enumcs = 16; /* sRGB as defined by IEC 61966-2.1 */ + else if (image->color_space == 2) + jp2->enumcs = 17; /* greyscale */ + else if (image->color_space == 3) + jp2->enumcs = 18; /* YUV */ + jp2->precedence = 0; /* PRECEDENCE */ + jp2->approx = 0; /* APPROX */ + + jp2->jpip_on = parameters->jpip_on; +} + +opj_bool opj_jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) { + + int pos_iptr, pos_cidx, pos_jp2c, len_jp2c, len_cidx, end_pos, pos_fidx, len_fidx; + pos_jp2c = pos_iptr = -1; /* remove a warning */ + + /* JP2 encoding */ + + /* JPEG 2000 Signature box */ + jp2_write_jp(cio); + /* File Type box */ + jp2_write_ftyp(jp2, cio); + /* JP2 Header box */ + jp2_write_jp2h(jp2, cio); + + if( jp2->jpip_on){ + pos_iptr = cio_tell( cio); + cio_skip( cio, 24); /* IPTR further ! */ + + pos_jp2c = cio_tell( cio); + } + + /* J2K encoding */ + if(!(len_jp2c = jp2_write_jp2c( jp2, cio, image, cstr_info))){ + opj_event_msg(jp2->cinfo, EVT_ERROR, "Failed to encode image\n"); + return OPJ_FALSE; + } + + if( jp2->jpip_on){ + pos_cidx = cio_tell( cio); + + len_cidx = write_cidx( pos_jp2c+8, cio, image, *cstr_info, len_jp2c-8); + + pos_fidx = cio_tell( cio); + len_fidx = write_fidx( pos_jp2c, len_jp2c, pos_cidx, len_cidx, cio); + + end_pos = cio_tell( cio); + + cio_seek( cio, pos_iptr); + write_iptr( pos_fidx, len_fidx, cio); + + cio_seek( cio, end_pos); + } + + return OPJ_TRUE; +} diff --git a/Source/LibOpenJPEG/jp2.h b/Source/LibOpenJPEG/jp2.h index 94153ee..acb643c 100644 --- a/Source/LibOpenJPEG/jp2.h +++ b/Source/LibOpenJPEG/jp2.h @@ -1,234 +1,234 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __JP2_H -#define __JP2_H -/** -@file jp2.h -@brief The JPEG-2000 file format Reader/Writer (JP2) - -*/ - -/** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */ -/*@{*/ - -#define JPIP_JPIP 0x6a706970 - -#define JP2_JP 0x6a502020 /**< JPEG 2000 signature box */ -#define JP2_FTYP 0x66747970 /**< File type box */ -#define JP2_JP2H 0x6a703268 /**< JP2 header box */ -#define JP2_IHDR 0x69686472 /**< Image header box */ -#define JP2_COLR 0x636f6c72 /**< Colour specification box */ -#define JP2_JP2C 0x6a703263 /**< Contiguous codestream box */ -#define JP2_URL 0x75726c20 /**< URL box */ -#define JP2_DTBL 0x6474626c /**< Data Reference box */ -#define JP2_BPCC 0x62706363 /**< Bits per component box */ -#define JP2_JP2 0x6a703220 /**< File type fields */ -#define JP2_PCLR 0x70636c72 /**< Palette box */ -#define JP2_CMAP 0x636d6170 /**< Component Mapping box */ -#define JP2_CDEF 0x63646566 /**< Channel Definition box */ - -/* ----------------------------------------------------------------------- */ -/** -Channel description: channel index, type, assocation -*/ -typedef struct opj_jp2_cdef_info -{ - unsigned short cn, typ, asoc; -} opj_jp2_cdef_info_t; - -/** -Channel descriptions and number of descriptions -*/ -typedef struct opj_jp2_cdef -{ - opj_jp2_cdef_info_t *info; - unsigned short n; -} opj_jp2_cdef_t; - -/** -Component mappings: channel index, mapping type, palette index -*/ -typedef struct opj_jp2_cmap_comp -{ - unsigned short cmp; - unsigned char mtyp, pcol; -} opj_jp2_cmap_comp_t; - -/** -Palette data: table entries, palette columns -*/ -typedef struct opj_jp2_pclr -{ - unsigned int *entries; - unsigned char *channel_sign; - unsigned char *channel_size; - opj_jp2_cmap_comp_t *cmap; - unsigned short nr_entries, nr_channels; -} opj_jp2_pclr_t; - -/** -Collector for ICC profile, palette, component mapping, channel description -*/ -typedef struct opj_jp2_color -{ - unsigned char *icc_profile_buf; - int icc_profile_len; - - opj_jp2_cdef_t *jp2_cdef; - opj_jp2_pclr_t *jp2_pclr; - unsigned char jp2_has_colr; -} opj_jp2_color_t; - -/** -JP2 component -*/ -typedef struct opj_jp2_comps { - int depth; - int sgnd; - int bpcc; -} opj_jp2_comps_t; - -/** -JPEG-2000 file format reader/writer -*/ -typedef struct opj_jp2 { - /** codec context */ - opj_common_ptr cinfo; - /** handle to the J2K codec */ - opj_j2k_t *j2k; - unsigned int w; - unsigned int h; - unsigned int numcomps; - unsigned int bpc; - unsigned int C; - unsigned int UnkC; - unsigned int IPR; - unsigned int meth; - unsigned int approx; - unsigned int enumcs; - unsigned int precedence; - unsigned int brand; - unsigned int minversion; - unsigned int numcl; - unsigned int *cl; - opj_jp2_comps_t *comps; - unsigned int j2k_codestream_offset; - unsigned int j2k_codestream_length; - opj_bool jpip_on; - opj_bool ignore_pclr_cmap_cdef; -} opj_jp2_t; - -/** -JP2 Box -*/ -typedef struct opj_jp2_box { - int length; - int type; - int init_pos; -} opj_jp2_box_t; - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Write the JP2H box - JP2 Header box (used in MJ2) -@param jp2 JP2 handle -@param cio Output buffer stream -*/ -void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio); -/** -Read the JP2H box - JP2 Header box (used in MJ2) -@param jp2 JP2 handle -@param cio Input buffer stream -@param ext Collector for profile, cdef and pclr data -@return Returns true if successful, returns false otherwise -*/ -opj_bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color); -/** -Creates a JP2 decompression structure -@param cinfo Codec context info -@return Returns a handle to a JP2 decompressor if successful, returns NULL otherwise -*/ -opj_jp2_t* jp2_create_decompress(opj_common_ptr cinfo); -/** -Destroy a JP2 decompressor handle -@param jp2 JP2 decompressor handle to destroy -*/ -void jp2_destroy_decompress(opj_jp2_t *jp2); -/** -Setup the decoder decoding parameters using user parameters. -Decoding parameters are returned in jp2->j2k->cp. -@param jp2 JP2 decompressor handle -@param parameters decompression parameters -*/ -void jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters); -/** -Decode an image from a JPEG-2000 file stream -@param jp2 JP2 decompressor handle -@param cio Input buffer stream -@param cstr_info Codestream information structure if required, NULL otherwise -@return Returns a decoded image if successful, returns NULL otherwise -*/ -opj_image_t* opj_jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio, opj_codestream_info_t *cstr_info); -/** -Creates a JP2 compression structure -@param cinfo Codec context info -@return Returns a handle to a JP2 compressor if successful, returns NULL otherwise -*/ -opj_jp2_t* jp2_create_compress(opj_common_ptr cinfo); -/** -Destroy a JP2 compressor handle -@param jp2 JP2 compressor handle to destroy -*/ -void jp2_destroy_compress(opj_jp2_t *jp2); -/** -Setup the encoder parameters using the current image and using user parameters. -Coding parameters are returned in jp2->j2k->cp. -@param jp2 JP2 compressor handle -@param parameters compression parameters -@param image input filled image -*/ -void jp2_setup_encoder(opj_jp2_t *jp2, opj_cparameters_t *parameters, opj_image_t *image); -/** -Encode an image into a JPEG-2000 file stream -@param jp2 JP2 compressor handle -@param cio Output buffer stream -@param image Image to encode -@param cstr_info Codestream information structure if required, NULL otherwise -@return Returns true if successful, returns false otherwise -*/ -opj_bool opj_jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info); - -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __JP2_H */ - +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __JP2_H +#define __JP2_H +/** +@file jp2.h +@brief The JPEG-2000 file format Reader/Writer (JP2) + +*/ + +/** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */ +/*@{*/ + +#define JPIP_JPIP 0x6a706970 + +#define JP2_JP 0x6a502020 /**< JPEG 2000 signature box */ +#define JP2_FTYP 0x66747970 /**< File type box */ +#define JP2_JP2H 0x6a703268 /**< JP2 header box */ +#define JP2_IHDR 0x69686472 /**< Image header box */ +#define JP2_COLR 0x636f6c72 /**< Colour specification box */ +#define JP2_JP2C 0x6a703263 /**< Contiguous codestream box */ +#define JP2_URL 0x75726c20 /**< URL box */ +#define JP2_DTBL 0x6474626c /**< Data Reference box */ +#define JP2_BPCC 0x62706363 /**< Bits per component box */ +#define JP2_JP2 0x6a703220 /**< File type fields */ +#define JP2_PCLR 0x70636c72 /**< Palette box */ +#define JP2_CMAP 0x636d6170 /**< Component Mapping box */ +#define JP2_CDEF 0x63646566 /**< Channel Definition box */ + +/* ----------------------------------------------------------------------- */ +/** +Channel description: channel index, type, assocation +*/ +typedef struct opj_jp2_cdef_info +{ + unsigned short cn, typ, asoc; +} opj_jp2_cdef_info_t; + +/** +Channel descriptions and number of descriptions +*/ +typedef struct opj_jp2_cdef +{ + opj_jp2_cdef_info_t *info; + unsigned short n; +} opj_jp2_cdef_t; + +/** +Component mappings: channel index, mapping type, palette index +*/ +typedef struct opj_jp2_cmap_comp +{ + unsigned short cmp; + unsigned char mtyp, pcol; +} opj_jp2_cmap_comp_t; + +/** +Palette data: table entries, palette columns +*/ +typedef struct opj_jp2_pclr +{ + unsigned int *entries; + unsigned char *channel_sign; + unsigned char *channel_size; + opj_jp2_cmap_comp_t *cmap; + unsigned short nr_entries, nr_channels; +} opj_jp2_pclr_t; + +/** +Collector for ICC profile, palette, component mapping, channel description +*/ +typedef struct opj_jp2_color +{ + unsigned char *icc_profile_buf; + int icc_profile_len; + + opj_jp2_cdef_t *jp2_cdef; + opj_jp2_pclr_t *jp2_pclr; + unsigned char jp2_has_colr; +} opj_jp2_color_t; + +/** +JP2 component +*/ +typedef struct opj_jp2_comps { + int depth; + int sgnd; + int bpcc; +} opj_jp2_comps_t; + +/** +JPEG-2000 file format reader/writer +*/ +typedef struct opj_jp2 { + /** codec context */ + opj_common_ptr cinfo; + /** handle to the J2K codec */ + opj_j2k_t *j2k; + unsigned int w; + unsigned int h; + unsigned int numcomps; + unsigned int bpc; + unsigned int C; + unsigned int UnkC; + unsigned int IPR; + unsigned int meth; + unsigned int approx; + unsigned int enumcs; + unsigned int precedence; + unsigned int brand; + unsigned int minversion; + unsigned int numcl; + unsigned int *cl; + opj_jp2_comps_t *comps; + unsigned int j2k_codestream_offset; + unsigned int j2k_codestream_length; + opj_bool jpip_on; + opj_bool ignore_pclr_cmap_cdef; +} opj_jp2_t; + +/** +JP2 Box +*/ +typedef struct opj_jp2_box { + int length; + int type; + int init_pos; +} opj_jp2_box_t; + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Write the JP2H box - JP2 Header box (used in MJ2) +@param jp2 JP2 handle +@param cio Output buffer stream +*/ +void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio); +/** +Read the JP2H box - JP2 Header box (used in MJ2) +@param jp2 JP2 handle +@param cio Input buffer stream +@param ext Collector for profile, cdef and pclr data +@return Returns true if successful, returns false otherwise +*/ +opj_bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color); +/** +Creates a JP2 decompression structure +@param cinfo Codec context info +@return Returns a handle to a JP2 decompressor if successful, returns NULL otherwise +*/ +opj_jp2_t* jp2_create_decompress(opj_common_ptr cinfo); +/** +Destroy a JP2 decompressor handle +@param jp2 JP2 decompressor handle to destroy +*/ +void jp2_destroy_decompress(opj_jp2_t *jp2); +/** +Setup the decoder decoding parameters using user parameters. +Decoding parameters are returned in jp2->j2k->cp. +@param jp2 JP2 decompressor handle +@param parameters decompression parameters +*/ +void jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters); +/** +Decode an image from a JPEG-2000 file stream +@param jp2 JP2 decompressor handle +@param cio Input buffer stream +@param cstr_info Codestream information structure if required, NULL otherwise +@return Returns a decoded image if successful, returns NULL otherwise +*/ +opj_image_t* opj_jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio, opj_codestream_info_t *cstr_info); +/** +Creates a JP2 compression structure +@param cinfo Codec context info +@return Returns a handle to a JP2 compressor if successful, returns NULL otherwise +*/ +opj_jp2_t* jp2_create_compress(opj_common_ptr cinfo); +/** +Destroy a JP2 compressor handle +@param jp2 JP2 compressor handle to destroy +*/ +void jp2_destroy_compress(opj_jp2_t *jp2); +/** +Setup the encoder parameters using the current image and using user parameters. +Coding parameters are returned in jp2->j2k->cp. +@param jp2 JP2 compressor handle +@param parameters compression parameters +@param image input filled image +*/ +void jp2_setup_encoder(opj_jp2_t *jp2, opj_cparameters_t *parameters, opj_image_t *image); +/** +Encode an image into a JPEG-2000 file stream +@param jp2 JP2 compressor handle +@param cio Output buffer stream +@param image Image to encode +@param cstr_info Codestream information structure if required, NULL otherwise +@return Returns true if successful, returns false otherwise +*/ +opj_bool opj_jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info); + +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __JP2_H */ + diff --git a/Source/LibOpenJPEG/jpt.c b/Source/LibOpenJPEG/jpt.c index 54898ec..a2566ea 100644 --- a/Source/LibOpenJPEG/jpt.c +++ b/Source/LibOpenJPEG/jpt.c @@ -1,155 +1,155 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/* - * Read the information contains in VBAS [JPP/JPT stream message header] - * Store information (7 bits) in value - * - */ -unsigned int jpt_read_VBAS_info(opj_cio_t *cio, unsigned int value) { - unsigned char elmt; - - elmt = cio_read(cio, 1); - while ((elmt >> 7) == 1) { - value = (value << 7); - value |= (elmt & 0x7f); - elmt = cio_read(cio, 1); - } - value = (value << 7); - value |= (elmt & 0x7f); - - return value; -} - -/* - * Initialize the value of the message header structure - * - */ -void jpt_init_msg_header(opj_jpt_msg_header_t * header) { - header->Id = 0; /* In-class Identifier */ - header->last_byte = 0; /* Last byte information */ - header->Class_Id = 0; /* Class Identifier */ - header->CSn_Id = 0; /* CSn : index identifier */ - header->Msg_offset = 0; /* Message offset */ - header->Msg_length = 0; /* Message length */ - header->Layer_nb = 0; /* Auxiliary for JPP case */ -} - -/* - * Re-initialize the value of the message header structure - * - * Only parameters always present in message header - * - */ -void jpt_reinit_msg_header(opj_jpt_msg_header_t * header) { - header->Id = 0; /* In-class Identifier */ - header->last_byte = 0; /* Last byte information */ - header->Msg_offset = 0; /* Message offset */ - header->Msg_length = 0; /* Message length */ -} - -/* - * Read the message header for a JPP/JPT - stream - * - */ -void jpt_read_msg_header(opj_common_ptr cinfo, opj_cio_t *cio, opj_jpt_msg_header_t *header) { - unsigned char elmt, Class = 0, CSn = 0; - jpt_reinit_msg_header(header); - - /* ------------- */ - /* VBAS : Bin-ID */ - /* ------------- */ - elmt = cio_read(cio, 1); - - /* See for Class and CSn */ - switch ((elmt >> 5) & 0x03) { - case 0: - opj_event_msg(cinfo, EVT_ERROR, "Forbidden value encounter in message header !!\n"); - break; - case 1: - Class = 0; - CSn = 0; - break; - case 2: - Class = 1; - CSn = 0; - break; - case 3: - Class = 1; - CSn = 1; - break; - default: - break; - } - - /* see information on bits 'c' [p 10 : A.2.1 general, ISO/IEC FCD 15444-9] */ - if (((elmt >> 4) & 0x01) == 1) - header->last_byte = 1; - - /* In-class identifier */ - header->Id |= (elmt & 0x0f); - if ((elmt >> 7) == 1) - header->Id = jpt_read_VBAS_info(cio, header->Id); - - /* ------------ */ - /* VBAS : Class */ - /* ------------ */ - if (Class == 1) { - header->Class_Id = 0; - header->Class_Id = jpt_read_VBAS_info(cio, header->Class_Id); - } - - /* ---------- */ - /* VBAS : CSn */ - /* ---------- */ - if (CSn == 1) { - header->CSn_Id = 0; - header->CSn_Id = jpt_read_VBAS_info(cio, header->CSn_Id); - } - - /* ----------------- */ - /* VBAS : Msg_offset */ - /* ----------------- */ - header->Msg_offset = jpt_read_VBAS_info(cio, header->Msg_offset); - - /* ----------------- */ - /* VBAS : Msg_length */ - /* ----------------- */ - header->Msg_length = jpt_read_VBAS_info(cio, header->Msg_length); - - /* ---------- */ - /* VBAS : Aux */ - /* ---------- */ - if ((header->Class_Id & 0x01) == 1) { - header->Layer_nb = 0; - header->Layer_nb = jpt_read_VBAS_info(cio, header->Layer_nb); - } -} +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/* + * Read the information contains in VBAS [JPP/JPT stream message header] + * Store information (7 bits) in value + * + */ +unsigned int jpt_read_VBAS_info(opj_cio_t *cio, unsigned int value) { + unsigned char elmt; + + elmt = cio_read(cio, 1); + while ((elmt >> 7) == 1) { + value = (value << 7); + value |= (elmt & 0x7f); + elmt = cio_read(cio, 1); + } + value = (value << 7); + value |= (elmt & 0x7f); + + return value; +} + +/* + * Initialize the value of the message header structure + * + */ +void jpt_init_msg_header(opj_jpt_msg_header_t * header) { + header->Id = 0; /* In-class Identifier */ + header->last_byte = 0; /* Last byte information */ + header->Class_Id = 0; /* Class Identifier */ + header->CSn_Id = 0; /* CSn : index identifier */ + header->Msg_offset = 0; /* Message offset */ + header->Msg_length = 0; /* Message length */ + header->Layer_nb = 0; /* Auxiliary for JPP case */ +} + +/* + * Re-initialize the value of the message header structure + * + * Only parameters always present in message header + * + */ +void jpt_reinit_msg_header(opj_jpt_msg_header_t * header) { + header->Id = 0; /* In-class Identifier */ + header->last_byte = 0; /* Last byte information */ + header->Msg_offset = 0; /* Message offset */ + header->Msg_length = 0; /* Message length */ +} + +/* + * Read the message header for a JPP/JPT - stream + * + */ +void jpt_read_msg_header(opj_common_ptr cinfo, opj_cio_t *cio, opj_jpt_msg_header_t *header) { + unsigned char elmt, Class = 0, CSn = 0; + jpt_reinit_msg_header(header); + + /* ------------- */ + /* VBAS : Bin-ID */ + /* ------------- */ + elmt = cio_read(cio, 1); + + /* See for Class and CSn */ + switch ((elmt >> 5) & 0x03) { + case 0: + opj_event_msg(cinfo, EVT_ERROR, "Forbidden value encounter in message header !!\n"); + break; + case 1: + Class = 0; + CSn = 0; + break; + case 2: + Class = 1; + CSn = 0; + break; + case 3: + Class = 1; + CSn = 1; + break; + default: + break; + } + + /* see information on bits 'c' [p 10 : A.2.1 general, ISO/IEC FCD 15444-9] */ + if (((elmt >> 4) & 0x01) == 1) + header->last_byte = 1; + + /* In-class identifier */ + header->Id |= (elmt & 0x0f); + if ((elmt >> 7) == 1) + header->Id = jpt_read_VBAS_info(cio, header->Id); + + /* ------------ */ + /* VBAS : Class */ + /* ------------ */ + if (Class == 1) { + header->Class_Id = 0; + header->Class_Id = jpt_read_VBAS_info(cio, header->Class_Id); + } + + /* ---------- */ + /* VBAS : CSn */ + /* ---------- */ + if (CSn == 1) { + header->CSn_Id = 0; + header->CSn_Id = jpt_read_VBAS_info(cio, header->CSn_Id); + } + + /* ----------------- */ + /* VBAS : Msg_offset */ + /* ----------------- */ + header->Msg_offset = jpt_read_VBAS_info(cio, header->Msg_offset); + + /* ----------------- */ + /* VBAS : Msg_length */ + /* ----------------- */ + header->Msg_length = jpt_read_VBAS_info(cio, header->Msg_length); + + /* ---------- */ + /* VBAS : Aux */ + /* ---------- */ + if ((header->Class_Id & 0x01) == 1) { + header->Layer_nb = 0; + header->Layer_nb = jpt_read_VBAS_info(cio, header->Layer_nb); + } +} diff --git a/Source/LibOpenJPEG/jpt.h b/Source/LibOpenJPEG/jpt.h index eeac700..eb01f98 100644 --- a/Source/LibOpenJPEG/jpt.h +++ b/Source/LibOpenJPEG/jpt.h @@ -1,75 +1,75 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __JPT_H -#define __JPT_H -/** -@file jpt.h -@brief JPT-stream reader (JPEG 2000, JPIP) - -JPT-stream functions are implemented in J2K.C. -*/ - -/** -Message Header JPT stream structure -*/ -typedef struct opj_jpt_msg_header { - /** In-class Identifier */ - unsigned int Id; - /** Last byte information */ - unsigned int last_byte; - /** Class Identifier */ - unsigned int Class_Id; - /** CSn : index identifier */ - unsigned int CSn_Id; - /** Message offset */ - unsigned int Msg_offset; - /** Message length */ - unsigned int Msg_length; - /** Auxiliary for JPP case */ - unsigned int Layer_nb; -} opj_jpt_msg_header_t; - -/* ----------------------------------------------------------------------- */ - -/** -Initialize the value of the message header structure -@param header Message header structure -*/ -void jpt_init_msg_header(opj_jpt_msg_header_t * header); - -/** -Read the message header for a JPP/JPT - stream -@param cinfo Codec context info -@param cio CIO handle -@param header Message header structure -*/ -void jpt_read_msg_header(opj_common_ptr cinfo, opj_cio_t *cio, opj_jpt_msg_header_t *header); - -#endif +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __JPT_H +#define __JPT_H +/** +@file jpt.h +@brief JPT-stream reader (JPEG 2000, JPIP) + +JPT-stream functions are implemented in J2K.C. +*/ + +/** +Message Header JPT stream structure +*/ +typedef struct opj_jpt_msg_header { + /** In-class Identifier */ + unsigned int Id; + /** Last byte information */ + unsigned int last_byte; + /** Class Identifier */ + unsigned int Class_Id; + /** CSn : index identifier */ + unsigned int CSn_Id; + /** Message offset */ + unsigned int Msg_offset; + /** Message length */ + unsigned int Msg_length; + /** Auxiliary for JPP case */ + unsigned int Layer_nb; +} opj_jpt_msg_header_t; + +/* ----------------------------------------------------------------------- */ + +/** +Initialize the value of the message header structure +@param header Message header structure +*/ +void jpt_init_msg_header(opj_jpt_msg_header_t * header); + +/** +Read the message header for a JPP/JPT - stream +@param cinfo Codec context info +@param cio CIO handle +@param header Message header structure +*/ +void jpt_read_msg_header(opj_common_ptr cinfo, opj_cio_t *cio, opj_jpt_msg_header_t *header); + +#endif diff --git a/Source/LibOpenJPEG/mct.c b/Source/LibOpenJPEG/mct.c index 152a005..870993b 100644 --- a/Source/LibOpenJPEG/mct.c +++ b/Source/LibOpenJPEG/mct.c @@ -1,190 +1,190 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef __SSE__ -#include -#endif - -#include "opj_includes.h" - -/* */ -/* This table contains the norms of the basis function of the reversible MCT. */ -/* */ -static const double mct_norms[3] = { 1.732, .8292, .8292 }; - -/* */ -/* This table contains the norms of the basis function of the irreversible MCT. */ -/* */ -static const double mct_norms_real[3] = { 1.732, 1.805, 1.573 }; - -/* */ -/* Foward reversible MCT. */ -/* */ -void mct_encode( - int* restrict c0, - int* restrict c1, - int* restrict c2, - int n) -{ - int i; - for(i = 0; i < n; ++i) { - int r = c0[i]; - int g = c1[i]; - int b = c2[i]; - int y = (r + (g * 2) + b) >> 2; - int u = b - g; - int v = r - g; - c0[i] = y; - c1[i] = u; - c2[i] = v; - } -} - -/* */ -/* Inverse reversible MCT. */ -/* */ -void mct_decode( - int* restrict c0, - int* restrict c1, - int* restrict c2, - int n) -{ - int i; - for (i = 0; i < n; ++i) { - int y = c0[i]; - int u = c1[i]; - int v = c2[i]; - int g = y - ((u + v) >> 2); - int r = v + g; - int b = u + g; - c0[i] = r; - c1[i] = g; - c2[i] = b; - } -} - -/* */ -/* Get norm of basis function of reversible MCT. */ -/* */ -double mct_getnorm(int compno) { - return mct_norms[compno]; -} - -/* */ -/* Foward irreversible MCT. */ -/* */ -void mct_encode_real( - int* restrict c0, - int* restrict c1, - int* restrict c2, - int n) -{ - int i; - for(i = 0; i < n; ++i) { - int r = c0[i]; - int g = c1[i]; - int b = c2[i]; - int y = fix_mul(r, 2449) + fix_mul(g, 4809) + fix_mul(b, 934); - int u = -fix_mul(r, 1382) - fix_mul(g, 2714) + fix_mul(b, 4096); - int v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666); - c0[i] = y; - c1[i] = u; - c2[i] = v; - } -} - -/* */ -/* Inverse irreversible MCT. */ -/* */ -void mct_decode_real( - float* restrict c0, - float* restrict c1, - float* restrict c2, - int n) -{ - int i; -#ifdef __SSE__ - __m128 vrv, vgu, vgv, vbu; - vrv = _mm_set1_ps(1.402f); - vgu = _mm_set1_ps(0.34413f); - vgv = _mm_set1_ps(0.71414f); - vbu = _mm_set1_ps(1.772f); - for (i = 0; i < (n >> 3); ++i) { - __m128 vy, vu, vv; - __m128 vr, vg, vb; - - vy = _mm_load_ps(c0); - vu = _mm_load_ps(c1); - vv = _mm_load_ps(c2); - vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv)); - vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv)); - vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu)); - _mm_store_ps(c0, vr); - _mm_store_ps(c1, vg); - _mm_store_ps(c2, vb); - c0 += 4; - c1 += 4; - c2 += 4; - - vy = _mm_load_ps(c0); - vu = _mm_load_ps(c1); - vv = _mm_load_ps(c2); - vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv)); - vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv)); - vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu)); - _mm_store_ps(c0, vr); - _mm_store_ps(c1, vg); - _mm_store_ps(c2, vb); - c0 += 4; - c1 += 4; - c2 += 4; - } - n &= 7; -#endif - for(i = 0; i < n; ++i) { - float y = c0[i]; - float u = c1[i]; - float v = c2[i]; - float r = y + (v * 1.402f); - float g = y - (u * 0.34413f) - (v * (0.71414f)); - float b = y + (u * 1.772f); - c0[i] = r; - c1[i] = g; - c2[i] = b; - } -} - -/* */ -/* Get norm of basis function of irreversible MCT. */ -/* */ -double mct_getnorm_real(int compno) { - return mct_norms_real[compno]; -} +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef __SSE__ +#include +#endif + +#include "opj_includes.h" + +/* */ +/* This table contains the norms of the basis function of the reversible MCT. */ +/* */ +static const double mct_norms[3] = { 1.732, .8292, .8292 }; + +/* */ +/* This table contains the norms of the basis function of the irreversible MCT. */ +/* */ +static const double mct_norms_real[3] = { 1.732, 1.805, 1.573 }; + +/* */ +/* Foward reversible MCT. */ +/* */ +void mct_encode( + int* restrict c0, + int* restrict c1, + int* restrict c2, + int n) +{ + int i; + for(i = 0; i < n; ++i) { + int r = c0[i]; + int g = c1[i]; + int b = c2[i]; + int y = (r + (g * 2) + b) >> 2; + int u = b - g; + int v = r - g; + c0[i] = y; + c1[i] = u; + c2[i] = v; + } +} + +/* */ +/* Inverse reversible MCT. */ +/* */ +void mct_decode( + int* restrict c0, + int* restrict c1, + int* restrict c2, + int n) +{ + int i; + for (i = 0; i < n; ++i) { + int y = c0[i]; + int u = c1[i]; + int v = c2[i]; + int g = y - ((u + v) >> 2); + int r = v + g; + int b = u + g; + c0[i] = r; + c1[i] = g; + c2[i] = b; + } +} + +/* */ +/* Get norm of basis function of reversible MCT. */ +/* */ +double mct_getnorm(int compno) { + return mct_norms[compno]; +} + +/* */ +/* Foward irreversible MCT. */ +/* */ +void mct_encode_real( + int* restrict c0, + int* restrict c1, + int* restrict c2, + int n) +{ + int i; + for(i = 0; i < n; ++i) { + int r = c0[i]; + int g = c1[i]; + int b = c2[i]; + int y = fix_mul(r, 2449) + fix_mul(g, 4809) + fix_mul(b, 934); + int u = -fix_mul(r, 1382) - fix_mul(g, 2714) + fix_mul(b, 4096); + int v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666); + c0[i] = y; + c1[i] = u; + c2[i] = v; + } +} + +/* */ +/* Inverse irreversible MCT. */ +/* */ +void mct_decode_real( + float* restrict c0, + float* restrict c1, + float* restrict c2, + int n) +{ + int i; +#ifdef __SSE__ + __m128 vrv, vgu, vgv, vbu; + vrv = _mm_set1_ps(1.402f); + vgu = _mm_set1_ps(0.34413f); + vgv = _mm_set1_ps(0.71414f); + vbu = _mm_set1_ps(1.772f); + for (i = 0; i < (n >> 3); ++i) { + __m128 vy, vu, vv; + __m128 vr, vg, vb; + + vy = _mm_load_ps(c0); + vu = _mm_load_ps(c1); + vv = _mm_load_ps(c2); + vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv)); + vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv)); + vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu)); + _mm_store_ps(c0, vr); + _mm_store_ps(c1, vg); + _mm_store_ps(c2, vb); + c0 += 4; + c1 += 4; + c2 += 4; + + vy = _mm_load_ps(c0); + vu = _mm_load_ps(c1); + vv = _mm_load_ps(c2); + vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv)); + vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv)); + vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu)); + _mm_store_ps(c0, vr); + _mm_store_ps(c1, vg); + _mm_store_ps(c2, vb); + c0 += 4; + c1 += 4; + c2 += 4; + } + n &= 7; +#endif + for(i = 0; i < n; ++i) { + float y = c0[i]; + float u = c1[i]; + float v = c2[i]; + float r = y + (v * 1.402f); + float g = y - (u * 0.34413f) - (v * (0.71414f)); + float b = y + (u * 1.772f); + c0[i] = r; + c1[i] = g; + c2[i] = b; + } +} + +/* */ +/* Get norm of basis function of irreversible MCT. */ +/* */ +double mct_getnorm_real(int compno) { + return mct_norms_real[compno]; +} diff --git a/Source/LibOpenJPEG/mct.h b/Source/LibOpenJPEG/mct.h index 361388e..84e3f8a 100644 --- a/Source/LibOpenJPEG/mct.h +++ b/Source/LibOpenJPEG/mct.h @@ -1,98 +1,98 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __MCT_H -#define __MCT_H -/** -@file mct.h -@brief Implementation of a multi-component transforms (MCT) - -The functions in MCT.C have for goal to realize reversible and irreversible multicomponent -transform. The functions in MCT.C are used by some function in TCD.C. -*/ - -/** @defgroup MCT MCT - Implementation of a multi-component transform */ -/*@{*/ - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Apply a reversible multi-component transform to an image -@param c0 Samples for red component -@param c1 Samples for green component -@param c2 Samples blue component -@param n Number of samples for each component -*/ -void mct_encode(int *c0, int *c1, int *c2, int n); -/** -Apply a reversible multi-component inverse transform to an image -@param c0 Samples for luminance component -@param c1 Samples for red chrominance component -@param c2 Samples for blue chrominance component -@param n Number of samples for each component -*/ -void mct_decode(int *c0, int *c1, int *c2, int n); -/** -Get norm of the basis function used for the reversible multi-component transform -@param compno Number of the component (0->Y, 1->U, 2->V) -@return -*/ -double mct_getnorm(int compno); - -/** -Apply an irreversible multi-component transform to an image -@param c0 Samples for red component -@param c1 Samples for green component -@param c2 Samples blue component -@param n Number of samples for each component -*/ -void mct_encode_real(int *c0, int *c1, int *c2, int n); -/** -Apply an irreversible multi-component inverse transform to an image -@param c0 Samples for luminance component -@param c1 Samples for red chrominance component -@param c2 Samples for blue chrominance component -@param n Number of samples for each component -*/ -void mct_decode_real(float* c0, float* c1, float* c2, int n); -/** -Get norm of the basis function used for the irreversible multi-component transform -@param compno Number of the component (0->Y, 1->U, 2->V) -@return -*/ -double mct_getnorm_real(int compno); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __MCT_H */ +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __MCT_H +#define __MCT_H +/** +@file mct.h +@brief Implementation of a multi-component transforms (MCT) + +The functions in MCT.C have for goal to realize reversible and irreversible multicomponent +transform. The functions in MCT.C are used by some function in TCD.C. +*/ + +/** @defgroup MCT MCT - Implementation of a multi-component transform */ +/*@{*/ + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Apply a reversible multi-component transform to an image +@param c0 Samples for red component +@param c1 Samples for green component +@param c2 Samples blue component +@param n Number of samples for each component +*/ +void mct_encode(int *c0, int *c1, int *c2, int n); +/** +Apply a reversible multi-component inverse transform to an image +@param c0 Samples for luminance component +@param c1 Samples for red chrominance component +@param c2 Samples for blue chrominance component +@param n Number of samples for each component +*/ +void mct_decode(int *c0, int *c1, int *c2, int n); +/** +Get norm of the basis function used for the reversible multi-component transform +@param compno Number of the component (0->Y, 1->U, 2->V) +@return +*/ +double mct_getnorm(int compno); + +/** +Apply an irreversible multi-component transform to an image +@param c0 Samples for red component +@param c1 Samples for green component +@param c2 Samples blue component +@param n Number of samples for each component +*/ +void mct_encode_real(int *c0, int *c1, int *c2, int n); +/** +Apply an irreversible multi-component inverse transform to an image +@param c0 Samples for luminance component +@param c1 Samples for red chrominance component +@param c2 Samples for blue chrominance component +@param n Number of samples for each component +*/ +void mct_decode_real(float* c0, float* c1, float* c2, int n); +/** +Get norm of the basis function used for the irreversible multi-component transform +@param compno Number of the component (0->Y, 1->U, 2->V) +@return +*/ +double mct_getnorm_real(int compno); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __MCT_H */ diff --git a/Source/LibOpenJPEG/mqc.c b/Source/LibOpenJPEG/mqc.c index e35b539..14129fb 100644 --- a/Source/LibOpenJPEG/mqc.c +++ b/Source/LibOpenJPEG/mqc.c @@ -1,592 +1,592 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/** @defgroup MQC MQC - Implementation of an MQ-Coder */ -/*@{*/ - -/** @name Local static functions */ -/*@{*/ - -/** -Output a byte, doing bit-stuffing if necessary. -After a 0xff byte, the next byte must be smaller than 0x90. -@param mqc MQC handle -*/ -static void mqc_byteout(opj_mqc_t *mqc); -/** -Renormalize mqc->a and mqc->c while encoding, so that mqc->a stays between 0x8000 and 0x10000 -@param mqc MQC handle -*/ -static void mqc_renorme(opj_mqc_t *mqc); -/** -Encode the most probable symbol -@param mqc MQC handle -*/ -static void mqc_codemps(opj_mqc_t *mqc); -/** -Encode the most least symbol -@param mqc MQC handle -*/ -static void mqc_codelps(opj_mqc_t *mqc); -/** -Fill mqc->c with 1's for flushing -@param mqc MQC handle -*/ -static void mqc_setbits(opj_mqc_t *mqc); -/** -FIXME: documentation ??? -@param mqc MQC handle -@return -*/ -static INLINE int mqc_mpsexchange(opj_mqc_t *const mqc); -/** -FIXME: documentation ??? -@param mqc MQC handle -@return -*/ -static INLINE int mqc_lpsexchange(opj_mqc_t *const mqc); -/** -Input a byte -@param mqc MQC handle -*/ -static INLINE void mqc_bytein(opj_mqc_t *const mqc); -/** -Renormalize mqc->a and mqc->c while decoding -@param mqc MQC handle -*/ -static INLINE void mqc_renormd(opj_mqc_t *const mqc); -/*@}*/ - -/*@}*/ - -/* */ -/* This array defines all the possible states for a context. */ -/* */ -static opj_mqc_state_t mqc_states[47 * 2] = { - {0x5601, 0, &mqc_states[2], &mqc_states[3]}, - {0x5601, 1, &mqc_states[3], &mqc_states[2]}, - {0x3401, 0, &mqc_states[4], &mqc_states[12]}, - {0x3401, 1, &mqc_states[5], &mqc_states[13]}, - {0x1801, 0, &mqc_states[6], &mqc_states[18]}, - {0x1801, 1, &mqc_states[7], &mqc_states[19]}, - {0x0ac1, 0, &mqc_states[8], &mqc_states[24]}, - {0x0ac1, 1, &mqc_states[9], &mqc_states[25]}, - {0x0521, 0, &mqc_states[10], &mqc_states[58]}, - {0x0521, 1, &mqc_states[11], &mqc_states[59]}, - {0x0221, 0, &mqc_states[76], &mqc_states[66]}, - {0x0221, 1, &mqc_states[77], &mqc_states[67]}, - {0x5601, 0, &mqc_states[14], &mqc_states[13]}, - {0x5601, 1, &mqc_states[15], &mqc_states[12]}, - {0x5401, 0, &mqc_states[16], &mqc_states[28]}, - {0x5401, 1, &mqc_states[17], &mqc_states[29]}, - {0x4801, 0, &mqc_states[18], &mqc_states[28]}, - {0x4801, 1, &mqc_states[19], &mqc_states[29]}, - {0x3801, 0, &mqc_states[20], &mqc_states[28]}, - {0x3801, 1, &mqc_states[21], &mqc_states[29]}, - {0x3001, 0, &mqc_states[22], &mqc_states[34]}, - {0x3001, 1, &mqc_states[23], &mqc_states[35]}, - {0x2401, 0, &mqc_states[24], &mqc_states[36]}, - {0x2401, 1, &mqc_states[25], &mqc_states[37]}, - {0x1c01, 0, &mqc_states[26], &mqc_states[40]}, - {0x1c01, 1, &mqc_states[27], &mqc_states[41]}, - {0x1601, 0, &mqc_states[58], &mqc_states[42]}, - {0x1601, 1, &mqc_states[59], &mqc_states[43]}, - {0x5601, 0, &mqc_states[30], &mqc_states[29]}, - {0x5601, 1, &mqc_states[31], &mqc_states[28]}, - {0x5401, 0, &mqc_states[32], &mqc_states[28]}, - {0x5401, 1, &mqc_states[33], &mqc_states[29]}, - {0x5101, 0, &mqc_states[34], &mqc_states[30]}, - {0x5101, 1, &mqc_states[35], &mqc_states[31]}, - {0x4801, 0, &mqc_states[36], &mqc_states[32]}, - {0x4801, 1, &mqc_states[37], &mqc_states[33]}, - {0x3801, 0, &mqc_states[38], &mqc_states[34]}, - {0x3801, 1, &mqc_states[39], &mqc_states[35]}, - {0x3401, 0, &mqc_states[40], &mqc_states[36]}, - {0x3401, 1, &mqc_states[41], &mqc_states[37]}, - {0x3001, 0, &mqc_states[42], &mqc_states[38]}, - {0x3001, 1, &mqc_states[43], &mqc_states[39]}, - {0x2801, 0, &mqc_states[44], &mqc_states[38]}, - {0x2801, 1, &mqc_states[45], &mqc_states[39]}, - {0x2401, 0, &mqc_states[46], &mqc_states[40]}, - {0x2401, 1, &mqc_states[47], &mqc_states[41]}, - {0x2201, 0, &mqc_states[48], &mqc_states[42]}, - {0x2201, 1, &mqc_states[49], &mqc_states[43]}, - {0x1c01, 0, &mqc_states[50], &mqc_states[44]}, - {0x1c01, 1, &mqc_states[51], &mqc_states[45]}, - {0x1801, 0, &mqc_states[52], &mqc_states[46]}, - {0x1801, 1, &mqc_states[53], &mqc_states[47]}, - {0x1601, 0, &mqc_states[54], &mqc_states[48]}, - {0x1601, 1, &mqc_states[55], &mqc_states[49]}, - {0x1401, 0, &mqc_states[56], &mqc_states[50]}, - {0x1401, 1, &mqc_states[57], &mqc_states[51]}, - {0x1201, 0, &mqc_states[58], &mqc_states[52]}, - {0x1201, 1, &mqc_states[59], &mqc_states[53]}, - {0x1101, 0, &mqc_states[60], &mqc_states[54]}, - {0x1101, 1, &mqc_states[61], &mqc_states[55]}, - {0x0ac1, 0, &mqc_states[62], &mqc_states[56]}, - {0x0ac1, 1, &mqc_states[63], &mqc_states[57]}, - {0x09c1, 0, &mqc_states[64], &mqc_states[58]}, - {0x09c1, 1, &mqc_states[65], &mqc_states[59]}, - {0x08a1, 0, &mqc_states[66], &mqc_states[60]}, - {0x08a1, 1, &mqc_states[67], &mqc_states[61]}, - {0x0521, 0, &mqc_states[68], &mqc_states[62]}, - {0x0521, 1, &mqc_states[69], &mqc_states[63]}, - {0x0441, 0, &mqc_states[70], &mqc_states[64]}, - {0x0441, 1, &mqc_states[71], &mqc_states[65]}, - {0x02a1, 0, &mqc_states[72], &mqc_states[66]}, - {0x02a1, 1, &mqc_states[73], &mqc_states[67]}, - {0x0221, 0, &mqc_states[74], &mqc_states[68]}, - {0x0221, 1, &mqc_states[75], &mqc_states[69]}, - {0x0141, 0, &mqc_states[76], &mqc_states[70]}, - {0x0141, 1, &mqc_states[77], &mqc_states[71]}, - {0x0111, 0, &mqc_states[78], &mqc_states[72]}, - {0x0111, 1, &mqc_states[79], &mqc_states[73]}, - {0x0085, 0, &mqc_states[80], &mqc_states[74]}, - {0x0085, 1, &mqc_states[81], &mqc_states[75]}, - {0x0049, 0, &mqc_states[82], &mqc_states[76]}, - {0x0049, 1, &mqc_states[83], &mqc_states[77]}, - {0x0025, 0, &mqc_states[84], &mqc_states[78]}, - {0x0025, 1, &mqc_states[85], &mqc_states[79]}, - {0x0015, 0, &mqc_states[86], &mqc_states[80]}, - {0x0015, 1, &mqc_states[87], &mqc_states[81]}, - {0x0009, 0, &mqc_states[88], &mqc_states[82]}, - {0x0009, 1, &mqc_states[89], &mqc_states[83]}, - {0x0005, 0, &mqc_states[90], &mqc_states[84]}, - {0x0005, 1, &mqc_states[91], &mqc_states[85]}, - {0x0001, 0, &mqc_states[90], &mqc_states[86]}, - {0x0001, 1, &mqc_states[91], &mqc_states[87]}, - {0x5601, 0, &mqc_states[92], &mqc_states[92]}, - {0x5601, 1, &mqc_states[93], &mqc_states[93]}, -}; - -/* -========================================================== - local functions -========================================================== -*/ - -static void mqc_byteout(opj_mqc_t *mqc) { - if (*mqc->bp == 0xff) { - mqc->bp++; - *mqc->bp = mqc->c >> 20; - mqc->c &= 0xfffff; - mqc->ct = 7; - } else { - if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */ - mqc->bp++; - *mqc->bp = mqc->c >> 19; - mqc->c &= 0x7ffff; - mqc->ct = 8; - } else { - (*mqc->bp)++; - if (*mqc->bp == 0xff) { - mqc->c &= 0x7ffffff; - mqc->bp++; - *mqc->bp = mqc->c >> 20; - mqc->c &= 0xfffff; - mqc->ct = 7; - } else { - mqc->bp++; - *mqc->bp = mqc->c >> 19; - mqc->c &= 0x7ffff; - mqc->ct = 8; - } - } - } -} - -static void mqc_renorme(opj_mqc_t *mqc) { - do { - mqc->a <<= 1; - mqc->c <<= 1; - mqc->ct--; - if (mqc->ct == 0) { - mqc_byteout(mqc); - } - } while ((mqc->a & 0x8000) == 0); -} - -static void mqc_codemps(opj_mqc_t *mqc) { - mqc->a -= (*mqc->curctx)->qeval; - if ((mqc->a & 0x8000) == 0) { - if (mqc->a < (*mqc->curctx)->qeval) { - mqc->a = (*mqc->curctx)->qeval; - } else { - mqc->c += (*mqc->curctx)->qeval; - } - *mqc->curctx = (*mqc->curctx)->nmps; - mqc_renorme(mqc); - } else { - mqc->c += (*mqc->curctx)->qeval; - } -} - -static void mqc_codelps(opj_mqc_t *mqc) { - mqc->a -= (*mqc->curctx)->qeval; - if (mqc->a < (*mqc->curctx)->qeval) { - mqc->c += (*mqc->curctx)->qeval; - } else { - mqc->a = (*mqc->curctx)->qeval; - } - *mqc->curctx = (*mqc->curctx)->nlps; - mqc_renorme(mqc); -} - -static void mqc_setbits(opj_mqc_t *mqc) { - unsigned int tempc = mqc->c + mqc->a; - mqc->c |= 0xffff; - if (mqc->c >= tempc) { - mqc->c -= 0x8000; - } -} - -static INLINE int mqc_mpsexchange(opj_mqc_t *const mqc) { - int d; - if (mqc->a < (*mqc->curctx)->qeval) { - d = 1 - (*mqc->curctx)->mps; - *mqc->curctx = (*mqc->curctx)->nlps; - } else { - d = (*mqc->curctx)->mps; - *mqc->curctx = (*mqc->curctx)->nmps; - } - - return d; -} - -static INLINE int mqc_lpsexchange(opj_mqc_t *const mqc) { - int d; - if (mqc->a < (*mqc->curctx)->qeval) { - mqc->a = (*mqc->curctx)->qeval; - d = (*mqc->curctx)->mps; - *mqc->curctx = (*mqc->curctx)->nmps; - } else { - mqc->a = (*mqc->curctx)->qeval; - d = 1 - (*mqc->curctx)->mps; - *mqc->curctx = (*mqc->curctx)->nlps; - } - - return d; -} - -#ifdef MQC_PERF_OPT -static INLINE void mqc_bytein(opj_mqc_t *const mqc) { - unsigned int i = *((unsigned int *) mqc->bp); - mqc->c += i & 0xffff00; - mqc->ct = i & 0x0f; - mqc->bp += (i >> 2) & 0x04; -} -#else -static void mqc_bytein(opj_mqc_t *const mqc) { - if (mqc->bp != mqc->end) { - unsigned int c; - if (mqc->bp + 1 != mqc->end) { - c = *(mqc->bp + 1); - } else { - c = 0xff; - } - if (*mqc->bp == 0xff) { - if (c > 0x8f) { - mqc->c += 0xff00; - mqc->ct = 8; - } else { - mqc->bp++; - mqc->c += c << 9; - mqc->ct = 7; - } - } else { - mqc->bp++; - mqc->c += c << 8; - mqc->ct = 8; - } - } else { - mqc->c += 0xff00; - mqc->ct = 8; - } -} -#endif - -static INLINE void mqc_renormd(opj_mqc_t *const mqc) { - do { - if (mqc->ct == 0) { - mqc_bytein(mqc); - } - mqc->a <<= 1; - mqc->c <<= 1; - mqc->ct--; - } while (mqc->a < 0x8000); -} - -/* -========================================================== - MQ-Coder interface -========================================================== -*/ - -opj_mqc_t* mqc_create(void) { - opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t)); -#ifdef MQC_PERF_OPT - mqc->buffer = NULL; -#endif - return mqc; -} - -void mqc_destroy(opj_mqc_t *mqc) { - if(mqc) { -#ifdef MQC_PERF_OPT - if (mqc->buffer) { - opj_free(mqc->buffer); - } -#endif - opj_free(mqc); - } -} - -int mqc_numbytes(opj_mqc_t *mqc) { - return mqc->bp - mqc->start; -} - -void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp) { - mqc_setcurctx(mqc, 0); - mqc->a = 0x8000; - mqc->c = 0; - mqc->bp = bp - 1; - mqc->ct = 12; - if (*mqc->bp == 0xff) { - mqc->ct = 13; - } - mqc->start = bp; -} - -void mqc_encode(opj_mqc_t *mqc, int d) { - if ((*mqc->curctx)->mps == d) { - mqc_codemps(mqc); - } else { - mqc_codelps(mqc); - } -} - -void mqc_flush(opj_mqc_t *mqc) { - mqc_setbits(mqc); - mqc->c <<= mqc->ct; - mqc_byteout(mqc); - mqc->c <<= mqc->ct; - mqc_byteout(mqc); - - if (*mqc->bp != 0xff) { - mqc->bp++; - } -} - -void mqc_bypass_init_enc(opj_mqc_t *mqc) { - mqc->c = 0; - mqc->ct = 8; - /*if (*mqc->bp == 0xff) { - mqc->ct = 7; - } */ -} - -void mqc_bypass_enc(opj_mqc_t *mqc, int d) { - mqc->ct--; - mqc->c = mqc->c + (d << mqc->ct); - if (mqc->ct == 0) { - mqc->bp++; - *mqc->bp = mqc->c; - mqc->ct = 8; - if (*mqc->bp == 0xff) { - mqc->ct = 7; - } - mqc->c = 0; - } -} - -int mqc_bypass_flush_enc(opj_mqc_t *mqc) { - unsigned char bit_padding; - - bit_padding = 0; - - if (mqc->ct != 0) { - while (mqc->ct > 0) { - mqc->ct--; - mqc->c += bit_padding << mqc->ct; - bit_padding = (bit_padding + 1) & 0x01; - } - mqc->bp++; - *mqc->bp = mqc->c; - mqc->ct = 8; - mqc->c = 0; - } - - return 1; -} - -void mqc_reset_enc(opj_mqc_t *mqc) { - mqc_resetstates(mqc); - mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); - mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); - mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); -} - -int mqc_restart_enc(opj_mqc_t *mqc) { - int correction = 1; - - /* */ - int n = 27 - 15 - mqc->ct; - mqc->c <<= mqc->ct; - while (n > 0) { - mqc_byteout(mqc); - n -= mqc->ct; - mqc->c <<= mqc->ct; - } - mqc_byteout(mqc); - - return correction; -} - -void mqc_restart_init_enc(opj_mqc_t *mqc) { - /* */ - mqc_setcurctx(mqc, 0); - mqc->a = 0x8000; - mqc->c = 0; - mqc->ct = 12; - mqc->bp--; - if (*mqc->bp == 0xff) { - mqc->ct = 13; - } -} - -void mqc_erterm_enc(opj_mqc_t *mqc) { - int k = 11 - mqc->ct + 1; - - while (k > 0) { - mqc->c <<= mqc->ct; - mqc->ct = 0; - mqc_byteout(mqc); - k -= mqc->ct; - } - - if (*mqc->bp != 0xff) { - mqc_byteout(mqc); - } -} - -void mqc_segmark_enc(opj_mqc_t *mqc) { - int i; - mqc_setcurctx(mqc, 18); - - for (i = 1; i < 5; i++) { - mqc_encode(mqc, i % 2); - } -} - -void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) { - mqc_setcurctx(mqc, 0); - mqc->start = bp; - mqc->end = bp + len; - mqc->bp = bp; - if (len==0) mqc->c = 0xff << 16; - else mqc->c = *mqc->bp << 16; - -#ifdef MQC_PERF_OPT - { - unsigned int c; - unsigned int *ip; - unsigned char *end = mqc->end - 1; - mqc->buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(unsigned int)); - ip = (unsigned int *) mqc->buffer; - - while (bp < end) { - c = *(bp + 1); - if (*bp == 0xff) { - if (c > 0x8f) { - break; - } else { - *ip = 0x00000017 | (c << 9); - } - } else { - *ip = 0x00000018 | (c << 8); - } - bp++; - ip++; - } - - /* Handle last byte of data */ - c = 0xff; - if (*bp == 0xff) { - *ip = 0x0000ff18; - } else { - bp++; - *ip = 0x00000018 | (c << 8); - } - ip++; - - *ip = 0x0000ff08; - mqc->bp = mqc->buffer; - } -#endif - mqc_bytein(mqc); - mqc->c <<= 7; - mqc->ct -= 7; - mqc->a = 0x8000; -} - -int mqc_decode(opj_mqc_t *const mqc) { - int d; - mqc->a -= (*mqc->curctx)->qeval; - if ((mqc->c >> 16) < (*mqc->curctx)->qeval) { - d = mqc_lpsexchange(mqc); - mqc_renormd(mqc); - } else { - mqc->c -= (*mqc->curctx)->qeval << 16; - if ((mqc->a & 0x8000) == 0) { - d = mqc_mpsexchange(mqc); - mqc_renormd(mqc); - } else { - d = (*mqc->curctx)->mps; - } - } - - return d; -} - -void mqc_resetstates(opj_mqc_t *mqc) { - int i; - for (i = 0; i < MQC_NUMCTXS; i++) { - mqc->ctxs[i] = mqc_states; - } -} - -void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob) { - mqc->ctxs[ctxno] = &mqc_states[msb + (prob << 1)]; -} - - +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/** @defgroup MQC MQC - Implementation of an MQ-Coder */ +/*@{*/ + +/** @name Local static functions */ +/*@{*/ + +/** +Output a byte, doing bit-stuffing if necessary. +After a 0xff byte, the next byte must be smaller than 0x90. +@param mqc MQC handle +*/ +static void mqc_byteout(opj_mqc_t *mqc); +/** +Renormalize mqc->a and mqc->c while encoding, so that mqc->a stays between 0x8000 and 0x10000 +@param mqc MQC handle +*/ +static void mqc_renorme(opj_mqc_t *mqc); +/** +Encode the most probable symbol +@param mqc MQC handle +*/ +static void mqc_codemps(opj_mqc_t *mqc); +/** +Encode the most least symbol +@param mqc MQC handle +*/ +static void mqc_codelps(opj_mqc_t *mqc); +/** +Fill mqc->c with 1's for flushing +@param mqc MQC handle +*/ +static void mqc_setbits(opj_mqc_t *mqc); +/** +FIXME: documentation ??? +@param mqc MQC handle +@return +*/ +static INLINE int mqc_mpsexchange(opj_mqc_t *const mqc); +/** +FIXME: documentation ??? +@param mqc MQC handle +@return +*/ +static INLINE int mqc_lpsexchange(opj_mqc_t *const mqc); +/** +Input a byte +@param mqc MQC handle +*/ +static INLINE void mqc_bytein(opj_mqc_t *const mqc); +/** +Renormalize mqc->a and mqc->c while decoding +@param mqc MQC handle +*/ +static INLINE void mqc_renormd(opj_mqc_t *const mqc); +/*@}*/ + +/*@}*/ + +/* */ +/* This array defines all the possible states for a context. */ +/* */ +static opj_mqc_state_t mqc_states[47 * 2] = { + {0x5601, 0, &mqc_states[2], &mqc_states[3]}, + {0x5601, 1, &mqc_states[3], &mqc_states[2]}, + {0x3401, 0, &mqc_states[4], &mqc_states[12]}, + {0x3401, 1, &mqc_states[5], &mqc_states[13]}, + {0x1801, 0, &mqc_states[6], &mqc_states[18]}, + {0x1801, 1, &mqc_states[7], &mqc_states[19]}, + {0x0ac1, 0, &mqc_states[8], &mqc_states[24]}, + {0x0ac1, 1, &mqc_states[9], &mqc_states[25]}, + {0x0521, 0, &mqc_states[10], &mqc_states[58]}, + {0x0521, 1, &mqc_states[11], &mqc_states[59]}, + {0x0221, 0, &mqc_states[76], &mqc_states[66]}, + {0x0221, 1, &mqc_states[77], &mqc_states[67]}, + {0x5601, 0, &mqc_states[14], &mqc_states[13]}, + {0x5601, 1, &mqc_states[15], &mqc_states[12]}, + {0x5401, 0, &mqc_states[16], &mqc_states[28]}, + {0x5401, 1, &mqc_states[17], &mqc_states[29]}, + {0x4801, 0, &mqc_states[18], &mqc_states[28]}, + {0x4801, 1, &mqc_states[19], &mqc_states[29]}, + {0x3801, 0, &mqc_states[20], &mqc_states[28]}, + {0x3801, 1, &mqc_states[21], &mqc_states[29]}, + {0x3001, 0, &mqc_states[22], &mqc_states[34]}, + {0x3001, 1, &mqc_states[23], &mqc_states[35]}, + {0x2401, 0, &mqc_states[24], &mqc_states[36]}, + {0x2401, 1, &mqc_states[25], &mqc_states[37]}, + {0x1c01, 0, &mqc_states[26], &mqc_states[40]}, + {0x1c01, 1, &mqc_states[27], &mqc_states[41]}, + {0x1601, 0, &mqc_states[58], &mqc_states[42]}, + {0x1601, 1, &mqc_states[59], &mqc_states[43]}, + {0x5601, 0, &mqc_states[30], &mqc_states[29]}, + {0x5601, 1, &mqc_states[31], &mqc_states[28]}, + {0x5401, 0, &mqc_states[32], &mqc_states[28]}, + {0x5401, 1, &mqc_states[33], &mqc_states[29]}, + {0x5101, 0, &mqc_states[34], &mqc_states[30]}, + {0x5101, 1, &mqc_states[35], &mqc_states[31]}, + {0x4801, 0, &mqc_states[36], &mqc_states[32]}, + {0x4801, 1, &mqc_states[37], &mqc_states[33]}, + {0x3801, 0, &mqc_states[38], &mqc_states[34]}, + {0x3801, 1, &mqc_states[39], &mqc_states[35]}, + {0x3401, 0, &mqc_states[40], &mqc_states[36]}, + {0x3401, 1, &mqc_states[41], &mqc_states[37]}, + {0x3001, 0, &mqc_states[42], &mqc_states[38]}, + {0x3001, 1, &mqc_states[43], &mqc_states[39]}, + {0x2801, 0, &mqc_states[44], &mqc_states[38]}, + {0x2801, 1, &mqc_states[45], &mqc_states[39]}, + {0x2401, 0, &mqc_states[46], &mqc_states[40]}, + {0x2401, 1, &mqc_states[47], &mqc_states[41]}, + {0x2201, 0, &mqc_states[48], &mqc_states[42]}, + {0x2201, 1, &mqc_states[49], &mqc_states[43]}, + {0x1c01, 0, &mqc_states[50], &mqc_states[44]}, + {0x1c01, 1, &mqc_states[51], &mqc_states[45]}, + {0x1801, 0, &mqc_states[52], &mqc_states[46]}, + {0x1801, 1, &mqc_states[53], &mqc_states[47]}, + {0x1601, 0, &mqc_states[54], &mqc_states[48]}, + {0x1601, 1, &mqc_states[55], &mqc_states[49]}, + {0x1401, 0, &mqc_states[56], &mqc_states[50]}, + {0x1401, 1, &mqc_states[57], &mqc_states[51]}, + {0x1201, 0, &mqc_states[58], &mqc_states[52]}, + {0x1201, 1, &mqc_states[59], &mqc_states[53]}, + {0x1101, 0, &mqc_states[60], &mqc_states[54]}, + {0x1101, 1, &mqc_states[61], &mqc_states[55]}, + {0x0ac1, 0, &mqc_states[62], &mqc_states[56]}, + {0x0ac1, 1, &mqc_states[63], &mqc_states[57]}, + {0x09c1, 0, &mqc_states[64], &mqc_states[58]}, + {0x09c1, 1, &mqc_states[65], &mqc_states[59]}, + {0x08a1, 0, &mqc_states[66], &mqc_states[60]}, + {0x08a1, 1, &mqc_states[67], &mqc_states[61]}, + {0x0521, 0, &mqc_states[68], &mqc_states[62]}, + {0x0521, 1, &mqc_states[69], &mqc_states[63]}, + {0x0441, 0, &mqc_states[70], &mqc_states[64]}, + {0x0441, 1, &mqc_states[71], &mqc_states[65]}, + {0x02a1, 0, &mqc_states[72], &mqc_states[66]}, + {0x02a1, 1, &mqc_states[73], &mqc_states[67]}, + {0x0221, 0, &mqc_states[74], &mqc_states[68]}, + {0x0221, 1, &mqc_states[75], &mqc_states[69]}, + {0x0141, 0, &mqc_states[76], &mqc_states[70]}, + {0x0141, 1, &mqc_states[77], &mqc_states[71]}, + {0x0111, 0, &mqc_states[78], &mqc_states[72]}, + {0x0111, 1, &mqc_states[79], &mqc_states[73]}, + {0x0085, 0, &mqc_states[80], &mqc_states[74]}, + {0x0085, 1, &mqc_states[81], &mqc_states[75]}, + {0x0049, 0, &mqc_states[82], &mqc_states[76]}, + {0x0049, 1, &mqc_states[83], &mqc_states[77]}, + {0x0025, 0, &mqc_states[84], &mqc_states[78]}, + {0x0025, 1, &mqc_states[85], &mqc_states[79]}, + {0x0015, 0, &mqc_states[86], &mqc_states[80]}, + {0x0015, 1, &mqc_states[87], &mqc_states[81]}, + {0x0009, 0, &mqc_states[88], &mqc_states[82]}, + {0x0009, 1, &mqc_states[89], &mqc_states[83]}, + {0x0005, 0, &mqc_states[90], &mqc_states[84]}, + {0x0005, 1, &mqc_states[91], &mqc_states[85]}, + {0x0001, 0, &mqc_states[90], &mqc_states[86]}, + {0x0001, 1, &mqc_states[91], &mqc_states[87]}, + {0x5601, 0, &mqc_states[92], &mqc_states[92]}, + {0x5601, 1, &mqc_states[93], &mqc_states[93]}, +}; + +/* +========================================================== + local functions +========================================================== +*/ + +static void mqc_byteout(opj_mqc_t *mqc) { + if (*mqc->bp == 0xff) { + mqc->bp++; + *mqc->bp = mqc->c >> 20; + mqc->c &= 0xfffff; + mqc->ct = 7; + } else { + if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */ + mqc->bp++; + *mqc->bp = mqc->c >> 19; + mqc->c &= 0x7ffff; + mqc->ct = 8; + } else { + (*mqc->bp)++; + if (*mqc->bp == 0xff) { + mqc->c &= 0x7ffffff; + mqc->bp++; + *mqc->bp = mqc->c >> 20; + mqc->c &= 0xfffff; + mqc->ct = 7; + } else { + mqc->bp++; + *mqc->bp = mqc->c >> 19; + mqc->c &= 0x7ffff; + mqc->ct = 8; + } + } + } +} + +static void mqc_renorme(opj_mqc_t *mqc) { + do { + mqc->a <<= 1; + mqc->c <<= 1; + mqc->ct--; + if (mqc->ct == 0) { + mqc_byteout(mqc); + } + } while ((mqc->a & 0x8000) == 0); +} + +static void mqc_codemps(opj_mqc_t *mqc) { + mqc->a -= (*mqc->curctx)->qeval; + if ((mqc->a & 0x8000) == 0) { + if (mqc->a < (*mqc->curctx)->qeval) { + mqc->a = (*mqc->curctx)->qeval; + } else { + mqc->c += (*mqc->curctx)->qeval; + } + *mqc->curctx = (*mqc->curctx)->nmps; + mqc_renorme(mqc); + } else { + mqc->c += (*mqc->curctx)->qeval; + } +} + +static void mqc_codelps(opj_mqc_t *mqc) { + mqc->a -= (*mqc->curctx)->qeval; + if (mqc->a < (*mqc->curctx)->qeval) { + mqc->c += (*mqc->curctx)->qeval; + } else { + mqc->a = (*mqc->curctx)->qeval; + } + *mqc->curctx = (*mqc->curctx)->nlps; + mqc_renorme(mqc); +} + +static void mqc_setbits(opj_mqc_t *mqc) { + unsigned int tempc = mqc->c + mqc->a; + mqc->c |= 0xffff; + if (mqc->c >= tempc) { + mqc->c -= 0x8000; + } +} + +static INLINE int mqc_mpsexchange(opj_mqc_t *const mqc) { + int d; + if (mqc->a < (*mqc->curctx)->qeval) { + d = 1 - (*mqc->curctx)->mps; + *mqc->curctx = (*mqc->curctx)->nlps; + } else { + d = (*mqc->curctx)->mps; + *mqc->curctx = (*mqc->curctx)->nmps; + } + + return d; +} + +static INLINE int mqc_lpsexchange(opj_mqc_t *const mqc) { + int d; + if (mqc->a < (*mqc->curctx)->qeval) { + mqc->a = (*mqc->curctx)->qeval; + d = (*mqc->curctx)->mps; + *mqc->curctx = (*mqc->curctx)->nmps; + } else { + mqc->a = (*mqc->curctx)->qeval; + d = 1 - (*mqc->curctx)->mps; + *mqc->curctx = (*mqc->curctx)->nlps; + } + + return d; +} + +#ifdef MQC_PERF_OPT +static INLINE void mqc_bytein(opj_mqc_t *const mqc) { + unsigned int i = *((unsigned int *) mqc->bp); + mqc->c += i & 0xffff00; + mqc->ct = i & 0x0f; + mqc->bp += (i >> 2) & 0x04; +} +#else +static void mqc_bytein(opj_mqc_t *const mqc) { + if (mqc->bp != mqc->end) { + unsigned int c; + if (mqc->bp + 1 != mqc->end) { + c = *(mqc->bp + 1); + } else { + c = 0xff; + } + if (*mqc->bp == 0xff) { + if (c > 0x8f) { + mqc->c += 0xff00; + mqc->ct = 8; + } else { + mqc->bp++; + mqc->c += c << 9; + mqc->ct = 7; + } + } else { + mqc->bp++; + mqc->c += c << 8; + mqc->ct = 8; + } + } else { + mqc->c += 0xff00; + mqc->ct = 8; + } +} +#endif + +static INLINE void mqc_renormd(opj_mqc_t *const mqc) { + do { + if (mqc->ct == 0) { + mqc_bytein(mqc); + } + mqc->a <<= 1; + mqc->c <<= 1; + mqc->ct--; + } while (mqc->a < 0x8000); +} + +/* +========================================================== + MQ-Coder interface +========================================================== +*/ + +opj_mqc_t* mqc_create(void) { + opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t)); +#ifdef MQC_PERF_OPT + mqc->buffer = NULL; +#endif + return mqc; +} + +void mqc_destroy(opj_mqc_t *mqc) { + if(mqc) { +#ifdef MQC_PERF_OPT + if (mqc->buffer) { + opj_free(mqc->buffer); + } +#endif + opj_free(mqc); + } +} + +int mqc_numbytes(opj_mqc_t *mqc) { + return mqc->bp - mqc->start; +} + +void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp) { + mqc_setcurctx(mqc, 0); + mqc->a = 0x8000; + mqc->c = 0; + mqc->bp = bp - 1; + mqc->ct = 12; + if (*mqc->bp == 0xff) { + mqc->ct = 13; + } + mqc->start = bp; +} + +void mqc_encode(opj_mqc_t *mqc, int d) { + if ((*mqc->curctx)->mps == d) { + mqc_codemps(mqc); + } else { + mqc_codelps(mqc); + } +} + +void mqc_flush(opj_mqc_t *mqc) { + mqc_setbits(mqc); + mqc->c <<= mqc->ct; + mqc_byteout(mqc); + mqc->c <<= mqc->ct; + mqc_byteout(mqc); + + if (*mqc->bp != 0xff) { + mqc->bp++; + } +} + +void mqc_bypass_init_enc(opj_mqc_t *mqc) { + mqc->c = 0; + mqc->ct = 8; + /*if (*mqc->bp == 0xff) { + mqc->ct = 7; + } */ +} + +void mqc_bypass_enc(opj_mqc_t *mqc, int d) { + mqc->ct--; + mqc->c = mqc->c + (d << mqc->ct); + if (mqc->ct == 0) { + mqc->bp++; + *mqc->bp = mqc->c; + mqc->ct = 8; + if (*mqc->bp == 0xff) { + mqc->ct = 7; + } + mqc->c = 0; + } +} + +int mqc_bypass_flush_enc(opj_mqc_t *mqc) { + unsigned char bit_padding; + + bit_padding = 0; + + if (mqc->ct != 0) { + while (mqc->ct > 0) { + mqc->ct--; + mqc->c += bit_padding << mqc->ct; + bit_padding = (bit_padding + 1) & 0x01; + } + mqc->bp++; + *mqc->bp = mqc->c; + mqc->ct = 8; + mqc->c = 0; + } + + return 1; +} + +void mqc_reset_enc(opj_mqc_t *mqc) { + mqc_resetstates(mqc); + mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); + mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); + mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); +} + +int mqc_restart_enc(opj_mqc_t *mqc) { + int correction = 1; + + /* */ + int n = 27 - 15 - mqc->ct; + mqc->c <<= mqc->ct; + while (n > 0) { + mqc_byteout(mqc); + n -= mqc->ct; + mqc->c <<= mqc->ct; + } + mqc_byteout(mqc); + + return correction; +} + +void mqc_restart_init_enc(opj_mqc_t *mqc) { + /* */ + mqc_setcurctx(mqc, 0); + mqc->a = 0x8000; + mqc->c = 0; + mqc->ct = 12; + mqc->bp--; + if (*mqc->bp == 0xff) { + mqc->ct = 13; + } +} + +void mqc_erterm_enc(opj_mqc_t *mqc) { + int k = 11 - mqc->ct + 1; + + while (k > 0) { + mqc->c <<= mqc->ct; + mqc->ct = 0; + mqc_byteout(mqc); + k -= mqc->ct; + } + + if (*mqc->bp != 0xff) { + mqc_byteout(mqc); + } +} + +void mqc_segmark_enc(opj_mqc_t *mqc) { + int i; + mqc_setcurctx(mqc, 18); + + for (i = 1; i < 5; i++) { + mqc_encode(mqc, i % 2); + } +} + +void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) { + mqc_setcurctx(mqc, 0); + mqc->start = bp; + mqc->end = bp + len; + mqc->bp = bp; + if (len==0) mqc->c = 0xff << 16; + else mqc->c = *mqc->bp << 16; + +#ifdef MQC_PERF_OPT + { + unsigned int c; + unsigned int *ip; + unsigned char *end = mqc->end - 1; + mqc->buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(unsigned int)); + ip = (unsigned int *) mqc->buffer; + + while (bp < end) { + c = *(bp + 1); + if (*bp == 0xff) { + if (c > 0x8f) { + break; + } else { + *ip = 0x00000017 | (c << 9); + } + } else { + *ip = 0x00000018 | (c << 8); + } + bp++; + ip++; + } + + /* Handle last byte of data */ + c = 0xff; + if (*bp == 0xff) { + *ip = 0x0000ff18; + } else { + bp++; + *ip = 0x00000018 | (c << 8); + } + ip++; + + *ip = 0x0000ff08; + mqc->bp = mqc->buffer; + } +#endif + mqc_bytein(mqc); + mqc->c <<= 7; + mqc->ct -= 7; + mqc->a = 0x8000; +} + +int mqc_decode(opj_mqc_t *const mqc) { + int d; + mqc->a -= (*mqc->curctx)->qeval; + if ((mqc->c >> 16) < (*mqc->curctx)->qeval) { + d = mqc_lpsexchange(mqc); + mqc_renormd(mqc); + } else { + mqc->c -= (*mqc->curctx)->qeval << 16; + if ((mqc->a & 0x8000) == 0) { + d = mqc_mpsexchange(mqc); + mqc_renormd(mqc); + } else { + d = (*mqc->curctx)->mps; + } + } + + return d; +} + +void mqc_resetstates(opj_mqc_t *mqc) { + int i; + for (i = 0; i < MQC_NUMCTXS; i++) { + mqc->ctxs[i] = mqc_states; + } +} + +void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob) { + mqc->ctxs[ctxno] = &mqc_states[msb + (prob << 1)]; +} + + diff --git a/Source/LibOpenJPEG/mqc.h b/Source/LibOpenJPEG/mqc.h index 976460e..d00cd10 100644 --- a/Source/LibOpenJPEG/mqc.h +++ b/Source/LibOpenJPEG/mqc.h @@ -1,200 +1,200 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __MQC_H -#define __MQC_H -/** -@file mqc.h -@brief Implementation of an MQ-Coder (MQC) - -The functions in MQC.C have for goal to realize the MQ-coder operations. The functions -in MQC.C are used by some function in T1.C. -*/ - -/** @defgroup MQC MQC - Implementation of an MQ-Coder */ -/*@{*/ - -/** -This struct defines the state of a context. -*/ -typedef struct opj_mqc_state { - /** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */ - unsigned int qeval; - /** the Most Probable Symbol (0 or 1) */ - int mps; - /** next state if the next encoded symbol is the MPS */ - struct opj_mqc_state *nmps; - /** next state if the next encoded symbol is the LPS */ - struct opj_mqc_state *nlps; -} opj_mqc_state_t; - -#define MQC_NUMCTXS 19 - -/** -MQ coder -*/ -typedef struct opj_mqc { - unsigned int c; - unsigned int a; - unsigned int ct; - unsigned char *bp; - unsigned char *start; - unsigned char *end; - opj_mqc_state_t *ctxs[MQC_NUMCTXS]; - opj_mqc_state_t **curctx; -#ifdef MQC_PERF_OPT - unsigned char *buffer; -#endif -} opj_mqc_t; - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Create a new MQC handle -@return Returns a new MQC handle if successful, returns NULL otherwise -*/ -opj_mqc_t* mqc_create(void); -/** -Destroy a previously created MQC handle -@param mqc MQC handle to destroy -*/ -void mqc_destroy(opj_mqc_t *mqc); -/** -Return the number of bytes written/read since initialisation -@param mqc MQC handle -@return Returns the number of bytes already encoded -*/ -int mqc_numbytes(opj_mqc_t *mqc); -/** -Reset the states of all the context of the coder/decoder -(each context is set to a state where 0 and 1 are more or less equiprobable) -@param mqc MQC handle -*/ -void mqc_resetstates(opj_mqc_t *mqc); -/** -Set the state of a particular context -@param mqc MQC handle -@param ctxno Number that identifies the context -@param msb The MSB of the new state of the context -@param prob Number that identifies the probability of the symbols for the new state of the context -*/ -void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob); -/** -Initialize the encoder -@param mqc MQC handle -@param bp Pointer to the start of the buffer where the bytes will be written -*/ -void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp); -/** -Set the current context used for coding/decoding -@param mqc MQC handle -@param ctxno Number that identifies the context -*/ -#define mqc_setcurctx(mqc, ctxno) (mqc)->curctx = &(mqc)->ctxs[(int)(ctxno)] -/** -Encode a symbol using the MQ-coder -@param mqc MQC handle -@param d The symbol to be encoded (0 or 1) -*/ -void mqc_encode(opj_mqc_t *mqc, int d); -/** -Flush the encoder, so that all remaining data is written -@param mqc MQC handle -*/ -void mqc_flush(opj_mqc_t *mqc); -/** -BYPASS mode switch, initialization operation. -JPEG 2000 p 505. -

Not fully implemented and tested !!

-@param mqc MQC handle -*/ -void mqc_bypass_init_enc(opj_mqc_t *mqc); -/** -BYPASS mode switch, coding operation. -JPEG 2000 p 505. -

Not fully implemented and tested !!

-@param mqc MQC handle -@param d The symbol to be encoded (0 or 1) -*/ -void mqc_bypass_enc(opj_mqc_t *mqc, int d); -/** -BYPASS mode switch, flush operation -

Not fully implemented and tested !!

-@param mqc MQC handle -@return Returns 1 (always) -*/ -int mqc_bypass_flush_enc(opj_mqc_t *mqc); -/** -RESET mode switch -@param mqc MQC handle -*/ -void mqc_reset_enc(opj_mqc_t *mqc); -/** -RESTART mode switch (TERMALL) -@param mqc MQC handle -@return Returns 1 (always) -*/ -int mqc_restart_enc(opj_mqc_t *mqc); -/** -RESTART mode switch (TERMALL) reinitialisation -@param mqc MQC handle -*/ -void mqc_restart_init_enc(opj_mqc_t *mqc); -/** -ERTERM mode switch (PTERM) -@param mqc MQC handle -*/ -void mqc_erterm_enc(opj_mqc_t *mqc); -/** -SEGMARK mode switch (SEGSYM) -@param mqc MQC handle -*/ -void mqc_segmark_enc(opj_mqc_t *mqc); -/** -Initialize the decoder -@param mqc MQC handle -@param bp Pointer to the start of the buffer from which the bytes will be read -@param len Length of the input buffer -*/ -void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len); -/** -Decode a symbol -@param mqc MQC handle -@return Returns the decoded symbol (0 or 1) -*/ -int mqc_decode(opj_mqc_t *const mqc); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __MQC_H */ +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __MQC_H +#define __MQC_H +/** +@file mqc.h +@brief Implementation of an MQ-Coder (MQC) + +The functions in MQC.C have for goal to realize the MQ-coder operations. The functions +in MQC.C are used by some function in T1.C. +*/ + +/** @defgroup MQC MQC - Implementation of an MQ-Coder */ +/*@{*/ + +/** +This struct defines the state of a context. +*/ +typedef struct opj_mqc_state { + /** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */ + unsigned int qeval; + /** the Most Probable Symbol (0 or 1) */ + int mps; + /** next state if the next encoded symbol is the MPS */ + struct opj_mqc_state *nmps; + /** next state if the next encoded symbol is the LPS */ + struct opj_mqc_state *nlps; +} opj_mqc_state_t; + +#define MQC_NUMCTXS 19 + +/** +MQ coder +*/ +typedef struct opj_mqc { + unsigned int c; + unsigned int a; + unsigned int ct; + unsigned char *bp; + unsigned char *start; + unsigned char *end; + opj_mqc_state_t *ctxs[MQC_NUMCTXS]; + opj_mqc_state_t **curctx; +#ifdef MQC_PERF_OPT + unsigned char *buffer; +#endif +} opj_mqc_t; + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Create a new MQC handle +@return Returns a new MQC handle if successful, returns NULL otherwise +*/ +opj_mqc_t* mqc_create(void); +/** +Destroy a previously created MQC handle +@param mqc MQC handle to destroy +*/ +void mqc_destroy(opj_mqc_t *mqc); +/** +Return the number of bytes written/read since initialisation +@param mqc MQC handle +@return Returns the number of bytes already encoded +*/ +int mqc_numbytes(opj_mqc_t *mqc); +/** +Reset the states of all the context of the coder/decoder +(each context is set to a state where 0 and 1 are more or less equiprobable) +@param mqc MQC handle +*/ +void mqc_resetstates(opj_mqc_t *mqc); +/** +Set the state of a particular context +@param mqc MQC handle +@param ctxno Number that identifies the context +@param msb The MSB of the new state of the context +@param prob Number that identifies the probability of the symbols for the new state of the context +*/ +void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob); +/** +Initialize the encoder +@param mqc MQC handle +@param bp Pointer to the start of the buffer where the bytes will be written +*/ +void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp); +/** +Set the current context used for coding/decoding +@param mqc MQC handle +@param ctxno Number that identifies the context +*/ +#define mqc_setcurctx(mqc, ctxno) (mqc)->curctx = &(mqc)->ctxs[(int)(ctxno)] +/** +Encode a symbol using the MQ-coder +@param mqc MQC handle +@param d The symbol to be encoded (0 or 1) +*/ +void mqc_encode(opj_mqc_t *mqc, int d); +/** +Flush the encoder, so that all remaining data is written +@param mqc MQC handle +*/ +void mqc_flush(opj_mqc_t *mqc); +/** +BYPASS mode switch, initialization operation. +JPEG 2000 p 505. +

Not fully implemented and tested !!

+@param mqc MQC handle +*/ +void mqc_bypass_init_enc(opj_mqc_t *mqc); +/** +BYPASS mode switch, coding operation. +JPEG 2000 p 505. +

Not fully implemented and tested !!

+@param mqc MQC handle +@param d The symbol to be encoded (0 or 1) +*/ +void mqc_bypass_enc(opj_mqc_t *mqc, int d); +/** +BYPASS mode switch, flush operation +

Not fully implemented and tested !!

+@param mqc MQC handle +@return Returns 1 (always) +*/ +int mqc_bypass_flush_enc(opj_mqc_t *mqc); +/** +RESET mode switch +@param mqc MQC handle +*/ +void mqc_reset_enc(opj_mqc_t *mqc); +/** +RESTART mode switch (TERMALL) +@param mqc MQC handle +@return Returns 1 (always) +*/ +int mqc_restart_enc(opj_mqc_t *mqc); +/** +RESTART mode switch (TERMALL) reinitialisation +@param mqc MQC handle +*/ +void mqc_restart_init_enc(opj_mqc_t *mqc); +/** +ERTERM mode switch (PTERM) +@param mqc MQC handle +*/ +void mqc_erterm_enc(opj_mqc_t *mqc); +/** +SEGMARK mode switch (SEGSYM) +@param mqc MQC handle +*/ +void mqc_segmark_enc(opj_mqc_t *mqc); +/** +Initialize the decoder +@param mqc MQC handle +@param bp Pointer to the start of the buffer from which the bytes will be read +@param len Length of the input buffer +*/ +void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len); +/** +Decode a symbol +@param mqc MQC handle +@return Returns the decoded symbol (0 or 1) +*/ +int mqc_decode(opj_mqc_t *const mqc); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __MQC_H */ diff --git a/Source/LibOpenJPEG/openjpeg.c b/Source/LibOpenJPEG/openjpeg.c index 847b08d..180cc84 100644 --- a/Source/LibOpenJPEG/openjpeg.c +++ b/Source/LibOpenJPEG/openjpeg.c @@ -1,343 +1,343 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef _WIN32 -#include -#endif /* _WIN32 */ - -#include "opj_config.h" -#include "opj_includes.h" - -/* ---------------------------------------------------------------------- */ -#ifdef _WIN32 -#ifndef OPJ_STATIC -BOOL APIENTRY -DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { - - OPJ_ARG_NOT_USED(lpReserved); - OPJ_ARG_NOT_USED(hModule); - - switch (ul_reason_for_call) { - case DLL_PROCESS_ATTACH : - break; - case DLL_PROCESS_DETACH : - break; - case DLL_THREAD_ATTACH : - case DLL_THREAD_DETACH : - break; - } - - return TRUE; -} -#endif /* OPJ_STATIC */ -#endif /* _WIN32 */ - -/* ---------------------------------------------------------------------- */ - - -const char* OPJ_CALLCONV opj_version(void) { - return PACKAGE_VERSION; -} - -opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) { - opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t)); - if(!dinfo) return NULL; - dinfo->is_decompressor = OPJ_TRUE; - switch(format) { - case CODEC_J2K: - case CODEC_JPT: - /* get a J2K decoder handle */ - dinfo->j2k_handle = (void*)j2k_create_decompress((opj_common_ptr)dinfo); - if(!dinfo->j2k_handle) { - opj_free(dinfo); - return NULL; - } - break; - case CODEC_JP2: - /* get a JP2 decoder handle */ - dinfo->jp2_handle = (void*)jp2_create_decompress((opj_common_ptr)dinfo); - if(!dinfo->jp2_handle) { - opj_free(dinfo); - return NULL; - } - break; - case CODEC_UNKNOWN: - default: - opj_free(dinfo); - return NULL; - } - - dinfo->codec_format = format; - - return dinfo; -} - -void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) { - if(dinfo) { - /* destroy the codec */ - switch(dinfo->codec_format) { - case CODEC_J2K: - case CODEC_JPT: - j2k_destroy_decompress((opj_j2k_t*)dinfo->j2k_handle); - break; - case CODEC_JP2: - jp2_destroy_decompress((opj_jp2_t*)dinfo->jp2_handle); - break; - case CODEC_UNKNOWN: - default: - break; - } - /* destroy the decompressor */ - opj_free(dinfo); - } -} - -void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) { - if(parameters) { - memset(parameters, 0, sizeof(opj_dparameters_t)); - /* default decoding parameters */ - parameters->cp_layer = 0; - parameters->cp_reduce = 0; - parameters->cp_limit_decoding = NO_LIMITATION; - - parameters->decod_format = -1; - parameters->cod_format = -1; - parameters->flags = 0; -/* UniPG>> */ -#ifdef USE_JPWL - parameters->jpwl_correct = OPJ_FALSE; - parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS; - parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES; -#endif /* USE_JPWL */ -/* <codec_format) { - case CODEC_J2K: - case CODEC_JPT: - j2k_setup_decoder((opj_j2k_t*)dinfo->j2k_handle, parameters); - break; - case CODEC_JP2: - jp2_setup_decoder((opj_jp2_t*)dinfo->jp2_handle, parameters); - break; - case CODEC_UNKNOWN: - default: - break; - } - } -} - -opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) { - return opj_decode_with_info(dinfo, cio, NULL); -} - -opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info) { - if(dinfo && cio) { - switch(dinfo->codec_format) { - case CODEC_J2K: - return j2k_decode((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info); - case CODEC_JPT: - return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info); - case CODEC_JP2: - return opj_jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio, cstr_info); - case CODEC_UNKNOWN: - default: - break; - } - } - return NULL; -} - -opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) { - opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_calloc(1, sizeof(opj_cinfo_t)); - if(!cinfo) return NULL; - cinfo->is_decompressor = OPJ_FALSE; - switch(format) { - case CODEC_J2K: - /* get a J2K coder handle */ - cinfo->j2k_handle = (void*)j2k_create_compress((opj_common_ptr)cinfo); - if(!cinfo->j2k_handle) { - opj_free(cinfo); - return NULL; - } - break; - case CODEC_JP2: - /* get a JP2 coder handle */ - cinfo->jp2_handle = (void*)jp2_create_compress((opj_common_ptr)cinfo); - if(!cinfo->jp2_handle) { - opj_free(cinfo); - return NULL; - } - break; - case CODEC_JPT: - case CODEC_UNKNOWN: - default: - opj_free(cinfo); - return NULL; - } - - cinfo->codec_format = format; - - return cinfo; -} - -void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) { - if(cinfo) { - /* destroy the codec */ - switch(cinfo->codec_format) { - case CODEC_J2K: - j2k_destroy_compress((opj_j2k_t*)cinfo->j2k_handle); - break; - case CODEC_JP2: - jp2_destroy_compress((opj_jp2_t*)cinfo->jp2_handle); - break; - case CODEC_JPT: - case CODEC_UNKNOWN: - default: - break; - } - /* destroy the decompressor */ - opj_free(cinfo); - } -} - -void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) { - if(parameters) { - memset(parameters, 0, sizeof(opj_cparameters_t)); - /* default coding parameters */ - parameters->cp_cinema = OFF; - parameters->max_comp_size = 0; - parameters->numresolution = 6; - parameters->cp_rsiz = STD_RSIZ; - parameters->cblockw_init = 64; - parameters->cblockh_init = 64; - parameters->prog_order = LRCP; - parameters->roi_compno = -1; /* no ROI */ - parameters->subsampling_dx = 1; - parameters->subsampling_dy = 1; - parameters->tp_on = 0; - parameters->decod_format = -1; - parameters->cod_format = -1; - parameters->tcp_rates[0] = 0; - parameters->tcp_numlayers = 0; - parameters->cp_disto_alloc = 0; - parameters->cp_fixed_alloc = 0; - parameters->cp_fixed_quality = 0; - parameters->jpip_on = OPJ_FALSE; -/* UniPG>> */ -#ifdef USE_JPWL - parameters->jpwl_epc_on = OPJ_FALSE; - parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */ - { - int i; - for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) { - parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */ - parameters->jpwl_hprot_TPH[i] = 0; /* absent */ - } - }; - { - int i; - for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) { - parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */ - parameters->jpwl_pprot_packno[i] = -1; /* unassigned */ - parameters->jpwl_pprot[i] = 0; /* absent */ - } - }; - parameters->jpwl_sens_size = 0; /* 0 means no ESD */ - parameters->jpwl_sens_addr = 0; /* 0 means auto */ - parameters->jpwl_sens_range = 0; /* 0 means packet */ - parameters->jpwl_sens_MH = -1; /* -1 means unassigned */ - { - int i; - for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) { - parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */ - parameters->jpwl_sens_TPH[i] = -1; /* absent */ - } - }; -#endif /* USE_JPWL */ -/* <codec_format) { - case CODEC_J2K: - j2k_setup_encoder((opj_j2k_t*)cinfo->j2k_handle, parameters, image); - break; - case CODEC_JP2: - jp2_setup_encoder((opj_jp2_t*)cinfo->jp2_handle, parameters, image); - break; - case CODEC_JPT: - case CODEC_UNKNOWN: - default: - break; - } - } -} - -opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) { - if (index != NULL) - opj_event_msg((opj_common_ptr)cinfo, EVT_WARNING, "Set index to NULL when calling the opj_encode function.\n" - "To extract the index, use the opj_encode_with_info() function.\n" - "No index will be generated during this encoding\n"); - return opj_encode_with_info(cinfo, cio, image, NULL); -} - -opj_bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) { - if(cinfo && cio && image) { - switch(cinfo->codec_format) { - case CODEC_J2K: - return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, cstr_info); - case CODEC_JP2: - return opj_jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, cstr_info); - case CODEC_JPT: - case CODEC_UNKNOWN: - default: - break; - } - } - return OPJ_FALSE; -} - -void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) { - if (cstr_info) { - int tileno; - for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { - opj_tile_info_t *tile_info = &cstr_info->tile[tileno]; - opj_free(tile_info->thresh); - opj_free(tile_info->packet); - opj_free(tile_info->tp); - opj_free(tile_info->marker); - } - opj_free(cstr_info->tile); - opj_free(cstr_info->marker); - opj_free(cstr_info->numdecompos); - } -} +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef _WIN32 +#include +#endif /* _WIN32 */ + +#include "opj_config.h" +#include "opj_includes.h" + +/* ---------------------------------------------------------------------- */ +#ifdef _WIN32 +#ifndef OPJ_STATIC +BOOL APIENTRY +DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { + + OPJ_ARG_NOT_USED(lpReserved); + OPJ_ARG_NOT_USED(hModule); + + switch (ul_reason_for_call) { + case DLL_PROCESS_ATTACH : + break; + case DLL_PROCESS_DETACH : + break; + case DLL_THREAD_ATTACH : + case DLL_THREAD_DETACH : + break; + } + + return TRUE; +} +#endif /* OPJ_STATIC */ +#endif /* _WIN32 */ + +/* ---------------------------------------------------------------------- */ + + +const char* OPJ_CALLCONV opj_version(void) { + return PACKAGE_VERSION; +} + +opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) { + opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t)); + if(!dinfo) return NULL; + dinfo->is_decompressor = OPJ_TRUE; + switch(format) { + case CODEC_J2K: + case CODEC_JPT: + /* get a J2K decoder handle */ + dinfo->j2k_handle = (void*)j2k_create_decompress((opj_common_ptr)dinfo); + if(!dinfo->j2k_handle) { + opj_free(dinfo); + return NULL; + } + break; + case CODEC_JP2: + /* get a JP2 decoder handle */ + dinfo->jp2_handle = (void*)jp2_create_decompress((opj_common_ptr)dinfo); + if(!dinfo->jp2_handle) { + opj_free(dinfo); + return NULL; + } + break; + case CODEC_UNKNOWN: + default: + opj_free(dinfo); + return NULL; + } + + dinfo->codec_format = format; + + return dinfo; +} + +void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) { + if(dinfo) { + /* destroy the codec */ + switch(dinfo->codec_format) { + case CODEC_J2K: + case CODEC_JPT: + j2k_destroy_decompress((opj_j2k_t*)dinfo->j2k_handle); + break; + case CODEC_JP2: + jp2_destroy_decompress((opj_jp2_t*)dinfo->jp2_handle); + break; + case CODEC_UNKNOWN: + default: + break; + } + /* destroy the decompressor */ + opj_free(dinfo); + } +} + +void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) { + if(parameters) { + memset(parameters, 0, sizeof(opj_dparameters_t)); + /* default decoding parameters */ + parameters->cp_layer = 0; + parameters->cp_reduce = 0; + parameters->cp_limit_decoding = NO_LIMITATION; + + parameters->decod_format = -1; + parameters->cod_format = -1; + parameters->flags = 0; +/* UniPG>> */ +#ifdef USE_JPWL + parameters->jpwl_correct = OPJ_FALSE; + parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS; + parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES; +#endif /* USE_JPWL */ +/* <codec_format) { + case CODEC_J2K: + case CODEC_JPT: + j2k_setup_decoder((opj_j2k_t*)dinfo->j2k_handle, parameters); + break; + case CODEC_JP2: + jp2_setup_decoder((opj_jp2_t*)dinfo->jp2_handle, parameters); + break; + case CODEC_UNKNOWN: + default: + break; + } + } +} + +opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) { + return opj_decode_with_info(dinfo, cio, NULL); +} + +opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info) { + if(dinfo && cio) { + switch(dinfo->codec_format) { + case CODEC_J2K: + return j2k_decode((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info); + case CODEC_JPT: + return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info); + case CODEC_JP2: + return opj_jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio, cstr_info); + case CODEC_UNKNOWN: + default: + break; + } + } + return NULL; +} + +opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) { + opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_calloc(1, sizeof(opj_cinfo_t)); + if(!cinfo) return NULL; + cinfo->is_decompressor = OPJ_FALSE; + switch(format) { + case CODEC_J2K: + /* get a J2K coder handle */ + cinfo->j2k_handle = (void*)j2k_create_compress((opj_common_ptr)cinfo); + if(!cinfo->j2k_handle) { + opj_free(cinfo); + return NULL; + } + break; + case CODEC_JP2: + /* get a JP2 coder handle */ + cinfo->jp2_handle = (void*)jp2_create_compress((opj_common_ptr)cinfo); + if(!cinfo->jp2_handle) { + opj_free(cinfo); + return NULL; + } + break; + case CODEC_JPT: + case CODEC_UNKNOWN: + default: + opj_free(cinfo); + return NULL; + } + + cinfo->codec_format = format; + + return cinfo; +} + +void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) { + if(cinfo) { + /* destroy the codec */ + switch(cinfo->codec_format) { + case CODEC_J2K: + j2k_destroy_compress((opj_j2k_t*)cinfo->j2k_handle); + break; + case CODEC_JP2: + jp2_destroy_compress((opj_jp2_t*)cinfo->jp2_handle); + break; + case CODEC_JPT: + case CODEC_UNKNOWN: + default: + break; + } + /* destroy the decompressor */ + opj_free(cinfo); + } +} + +void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) { + if(parameters) { + memset(parameters, 0, sizeof(opj_cparameters_t)); + /* default coding parameters */ + parameters->cp_cinema = OFF; + parameters->max_comp_size = 0; + parameters->numresolution = 6; + parameters->cp_rsiz = STD_RSIZ; + parameters->cblockw_init = 64; + parameters->cblockh_init = 64; + parameters->prog_order = LRCP; + parameters->roi_compno = -1; /* no ROI */ + parameters->subsampling_dx = 1; + parameters->subsampling_dy = 1; + parameters->tp_on = 0; + parameters->decod_format = -1; + parameters->cod_format = -1; + parameters->tcp_rates[0] = 0; + parameters->tcp_numlayers = 0; + parameters->cp_disto_alloc = 0; + parameters->cp_fixed_alloc = 0; + parameters->cp_fixed_quality = 0; + parameters->jpip_on = OPJ_FALSE; +/* UniPG>> */ +#ifdef USE_JPWL + parameters->jpwl_epc_on = OPJ_FALSE; + parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */ + { + int i; + for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) { + parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */ + parameters->jpwl_hprot_TPH[i] = 0; /* absent */ + } + }; + { + int i; + for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) { + parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */ + parameters->jpwl_pprot_packno[i] = -1; /* unassigned */ + parameters->jpwl_pprot[i] = 0; /* absent */ + } + }; + parameters->jpwl_sens_size = 0; /* 0 means no ESD */ + parameters->jpwl_sens_addr = 0; /* 0 means auto */ + parameters->jpwl_sens_range = 0; /* 0 means packet */ + parameters->jpwl_sens_MH = -1; /* -1 means unassigned */ + { + int i; + for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) { + parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */ + parameters->jpwl_sens_TPH[i] = -1; /* absent */ + } + }; +#endif /* USE_JPWL */ +/* <codec_format) { + case CODEC_J2K: + j2k_setup_encoder((opj_j2k_t*)cinfo->j2k_handle, parameters, image); + break; + case CODEC_JP2: + jp2_setup_encoder((opj_jp2_t*)cinfo->jp2_handle, parameters, image); + break; + case CODEC_JPT: + case CODEC_UNKNOWN: + default: + break; + } + } +} + +opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) { + if (index != NULL) + opj_event_msg((opj_common_ptr)cinfo, EVT_WARNING, "Set index to NULL when calling the opj_encode function.\n" + "To extract the index, use the opj_encode_with_info() function.\n" + "No index will be generated during this encoding\n"); + return opj_encode_with_info(cinfo, cio, image, NULL); +} + +opj_bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) { + if(cinfo && cio && image) { + switch(cinfo->codec_format) { + case CODEC_J2K: + return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, cstr_info); + case CODEC_JP2: + return opj_jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, cstr_info); + case CODEC_JPT: + case CODEC_UNKNOWN: + default: + break; + } + } + return OPJ_FALSE; +} + +void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) { + if (cstr_info) { + int tileno; + for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { + opj_tile_info_t *tile_info = &cstr_info->tile[tileno]; + opj_free(tile_info->thresh); + opj_free(tile_info->packet); + opj_free(tile_info->tp); + opj_free(tile_info->marker); + } + opj_free(cstr_info->tile); + opj_free(cstr_info->marker); + opj_free(cstr_info->numdecompos); + } +} diff --git a/Source/LibOpenJPEG/openjpeg.h b/Source/LibOpenJPEG/openjpeg.h index bbc35c2..59147c8 100644 --- a/Source/LibOpenJPEG/openjpeg.h +++ b/Source/LibOpenJPEG/openjpeg.h @@ -1,914 +1,914 @@ - /* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2006-2007, Parvatha Elangovan - * Copyright (c) 2010-2011, Kaori Hagihara - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef OPENJPEG_H -#define OPENJPEG_H - - -/* -========================================================== - Compiler directives -========================================================== -*/ - -#if defined(OPJ_STATIC) || !defined(_WIN32) -#define OPJ_API -#define OPJ_CALLCONV -#else -#define OPJ_CALLCONV __stdcall -/* -The following ifdef block is the standard way of creating macros which make exporting -from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS -symbol defined on the command line. this symbol should not be defined on any project -that uses this DLL. This way any other project whose source files include this file see -OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols -defined with this macro as being exported. -*/ -#if defined(OPJ_EXPORTS) || defined(DLL_EXPORT) -#define OPJ_API __declspec(dllexport) -#else -#define OPJ_API __declspec(dllimport) -#endif /* OPJ_EXPORTS */ -#endif /* !OPJ_STATIC || !_WIN32 */ - -typedef int opj_bool; -#define OPJ_TRUE 1 -#define OPJ_FALSE 0 - -/* Avoid compile-time warning because parameter is not used */ -#define OPJ_ARG_NOT_USED(x) (void)(x) -/* -========================================================== - Useful constant definitions -========================================================== -*/ - -#define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */ - -#define J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */ -#define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */ - -/* UniPG>> */ -#define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */ -#define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */ -#define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */ -#define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */ -#define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */ -#define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */ -#define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */ -#define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */ -/* < -
  • Error messages -
  • Warning messages -
  • Debugging messages - -*/ -typedef struct opj_event_mgr { - /** Error message callback if available, NULL otherwise */ - opj_msg_callback error_handler; - /** Warning message callback if available, NULL otherwise */ - opj_msg_callback warning_handler; - /** Debug message callback if available, NULL otherwise */ - opj_msg_callback info_handler; -} opj_event_mgr_t; - - -/* -========================================================== - codec typedef definitions -========================================================== -*/ - -/** -Progression order changes -*/ -typedef struct opj_poc { - /** Resolution num start, Component num start, given by POC */ - int resno0, compno0; - /** Layer num end,Resolution num end, Component num end, given by POC */ - int layno1, resno1, compno1; - /** Layer num start,Precinct num start, Precinct num end */ - int layno0, precno0, precno1; - /** Progression order enum*/ - OPJ_PROG_ORDER prg1,prg; - /** Progression order string*/ - char progorder[5]; - /** Tile number */ - int tile; - /** Start and end values for Tile width and height*/ - int tx0,tx1,ty0,ty1; - /** Start value, initialised in pi_initialise_encode*/ - int layS, resS, compS, prcS; - /** End value, initialised in pi_initialise_encode */ - int layE, resE, compE, prcE; - /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/ - int txS,txE,tyS,tyE,dx,dy; - /** Temporary values for Tile parts, initialised in pi_create_encode */ - int lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t; -} opj_poc_t; - -/** -Compression parameters -*/ -typedef struct opj_cparameters { - /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */ - opj_bool tile_size_on; - /** XTOsiz */ - int cp_tx0; - /** YTOsiz */ - int cp_ty0; - /** XTsiz */ - int cp_tdx; - /** YTsiz */ - int cp_tdy; - /** allocation by rate/distortion */ - int cp_disto_alloc; - /** allocation by fixed layer */ - int cp_fixed_alloc; - /** add fixed_quality */ - int cp_fixed_quality; - /** fixed layer */ - int *cp_matrice; - /** comment for coding */ - char *cp_comment; - /** csty : coding style */ - int csty; - /** progression order (default LRCP) */ - OPJ_PROG_ORDER prog_order; - /** progression order changes */ - opj_poc_t POC[32]; - /** number of progression order changes (POC), default to 0 */ - int numpocs; - /** number of layers */ - int tcp_numlayers; - /** rates of layers */ - float tcp_rates[100]; - /** different psnr for successive layers */ - float tcp_distoratio[100]; - /** number of resolutions */ - int numresolution; - /** initial code block width, default to 64 */ - int cblockw_init; - /** initial code block height, default to 64 */ - int cblockh_init; - /** mode switch (cblk_style) */ - int mode; - /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */ - int irreversible; - /** region of interest: affected component in [0..3], -1 means no ROI */ - int roi_compno; - /** region of interest: upshift value */ - int roi_shift; - /* number of precinct size specifications */ - int res_spec; - /** initial precinct width */ - int prcw_init[J2K_MAXRLVLS]; - /** initial precinct height */ - int prch_init[J2K_MAXRLVLS]; - - /**@name command line encoder parameters (not used inside the library) */ - /*@{*/ - /** input file name */ - char infile[OPJ_PATH_LEN]; - /** output file name */ - char outfile[OPJ_PATH_LEN]; - /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */ - int index_on; - /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */ - char index[OPJ_PATH_LEN]; - /** subimage encoding: origin image offset in x direction */ - int image_offset_x0; - /** subimage encoding: origin image offset in y direction */ - int image_offset_y0; - /** subsampling value for dx */ - int subsampling_dx; - /** subsampling value for dy */ - int subsampling_dy; - /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/ - int decod_format; - /** output file format 0: J2K, 1: JP2, 2: JPT */ - int cod_format; - /*@}*/ - -/* UniPG>> */ - /**@name JPWL encoding parameters */ - /*@{*/ - /** enables writing of EPC in MH, thus activating JPWL */ - opj_bool jpwl_epc_on; - /** error protection method for MH (0,1,16,32,37-128) */ - int jpwl_hprot_MH; - /** tile number of header protection specification (>=0) */ - int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS]; - /** error protection methods for TPHs (0,1,16,32,37-128) */ - int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS]; - /** tile number of packet protection specification (>=0) */ - int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS]; - /** packet number of packet protection specification (>=0) */ - int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS]; - /** error protection methods for packets (0,1,16,32,37-128) */ - int jpwl_pprot[JPWL_MAX_NO_PACKSPECS]; - /** enables writing of ESD, (0=no/1/2 bytes) */ - int jpwl_sens_size; - /** sensitivity addressing size (0=auto/2/4 bytes) */ - int jpwl_sens_addr; - /** sensitivity range (0-3) */ - int jpwl_sens_range; - /** sensitivity method for MH (-1=no,0-7) */ - int jpwl_sens_MH; - /** tile number of sensitivity specification (>=0) */ - int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS]; - /** sensitivity methods for TPHs (-1=no,0-7) */ - int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS]; - /*@}*/ -/* <> */ - /**@name JPWL decoding parameters */ - /*@{*/ - /** activates the JPWL correction capabilities */ - opj_bool jpwl_correct; - /** expected number of components */ - int jpwl_exp_comps; - /** maximum number of tiles */ - int jpwl_max_tiles; - /*@}*/ -/* <> */ -/** -Marker structure -*/ -typedef struct opj_marker_info_t { - /** marker type */ - unsigned short int type; - /** position in codestream */ - int pos; - /** length, marker val included */ - int len; -} opj_marker_info_t; -/* <> */ - /** number of markers */ - int marknum; - /** list of markers */ - opj_marker_info_t *marker; - /** actual size of markers array */ - int maxmarknum; -/* <cp. -@param dinfo decompressor handle -@param parameters decompression parameters -*/ -OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters); -/** -Decode an image from a JPEG-2000 codestream -@param dinfo decompressor handle -@param cio Input buffer stream -@return Returns a decoded image if successful, returns NULL otherwise -*/ -OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio); - -/** -Decode an image from a JPEG-2000 codestream and extract the codestream information -@param dinfo decompressor handle -@param cio Input buffer stream -@param cstr_info Codestream information structure if needed afterwards, NULL otherwise -@return Returns a decoded image if successful, returns NULL otherwise -*/ -OPJ_API opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info); -/** -Creates a J2K/JP2 compression structure -@param format Coder to select -@return Returns a handle to a compressor if successful, returns NULL otherwise -*/ -OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format); -/** -Destroy a compressor handle -@param cinfo compressor handle to destroy -*/ -OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo); -/** -Set encoding parameters to default values, that means : -
      -
    • Lossless -
    • 1 tile -
    • Size of precinct : 2^15 x 2^15 (means 1 precinct) -
    • Size of code-block : 64 x 64 -
    • Number of resolutions: 6 -
    • No SOP marker in the codestream -
    • No EPH marker in the codestream -
    • No sub-sampling in x or y direction -
    • No mode switch activated -
    • Progression order: LRCP -
    • No index file -
    • No ROI upshifted -
    • No offset of the origin of the image -
    • No offset of the origin of the tiles -
    • Reversible DWT 5-3 -
    -@param parameters Compression parameters -*/ -OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters); -/** -Setup the encoder parameters using the current image and using user parameters. -@param cinfo Compressor handle -@param parameters Compression parameters -@param image Input filled image -*/ -OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image); -/** -Encode an image into a JPEG-2000 codestream -3@param cinfo compressor handle -@param cio Output buffer stream -@param image Image to encode -@param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci() -@return Returns true if successful, returns false otherwise -*/ -OPJ_API opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index); -/** -Encode an image into a JPEG-2000 codestream and extract the codestream information -@param cinfo compressor handle -@param cio Output buffer stream -@param image Image to encode -@param cstr_info Codestream information structure if needed afterwards, NULL otherwise -@return Returns true if successful, returns false otherwise -*/ -OPJ_API opj_bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info); -/** -Destroy Codestream information after compression or decompression -@param cstr_info Codestream information structure -*/ -OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info); - - -#ifdef __cplusplus -} -#endif - -#endif /* OPENJPEG_H */ + /* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2006-2007, Parvatha Elangovan + * Copyright (c) 2010-2011, Kaori Hagihara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef OPENJPEG_H +#define OPENJPEG_H + + +/* +========================================================== + Compiler directives +========================================================== +*/ + +#if defined(OPJ_STATIC) || !defined(_WIN32) +#define OPJ_API +#define OPJ_CALLCONV +#else +#define OPJ_CALLCONV __stdcall +/* +The following ifdef block is the standard way of creating macros which make exporting +from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS +symbol defined on the command line. this symbol should not be defined on any project +that uses this DLL. This way any other project whose source files include this file see +OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols +defined with this macro as being exported. +*/ +#if defined(OPJ_EXPORTS) || defined(DLL_EXPORT) +#define OPJ_API __declspec(dllexport) +#else +#define OPJ_API __declspec(dllimport) +#endif /* OPJ_EXPORTS */ +#endif /* !OPJ_STATIC || !_WIN32 */ + +typedef int opj_bool; +#define OPJ_TRUE 1 +#define OPJ_FALSE 0 + +/* Avoid compile-time warning because parameter is not used */ +#define OPJ_ARG_NOT_USED(x) (void)(x) +/* +========================================================== + Useful constant definitions +========================================================== +*/ + +#define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */ + +#define J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */ +#define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */ + +/* UniPG>> */ +#define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */ +#define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */ +#define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */ +#define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */ +#define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */ +#define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */ +#define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */ +#define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */ +/* < +
  • Error messages +
  • Warning messages +
  • Debugging messages + +*/ +typedef struct opj_event_mgr { + /** Error message callback if available, NULL otherwise */ + opj_msg_callback error_handler; + /** Warning message callback if available, NULL otherwise */ + opj_msg_callback warning_handler; + /** Debug message callback if available, NULL otherwise */ + opj_msg_callback info_handler; +} opj_event_mgr_t; + + +/* +========================================================== + codec typedef definitions +========================================================== +*/ + +/** +Progression order changes +*/ +typedef struct opj_poc { + /** Resolution num start, Component num start, given by POC */ + int resno0, compno0; + /** Layer num end,Resolution num end, Component num end, given by POC */ + int layno1, resno1, compno1; + /** Layer num start,Precinct num start, Precinct num end */ + int layno0, precno0, precno1; + /** Progression order enum*/ + OPJ_PROG_ORDER prg1,prg; + /** Progression order string*/ + char progorder[5]; + /** Tile number */ + int tile; + /** Start and end values for Tile width and height*/ + int tx0,tx1,ty0,ty1; + /** Start value, initialised in pi_initialise_encode*/ + int layS, resS, compS, prcS; + /** End value, initialised in pi_initialise_encode */ + int layE, resE, compE, prcE; + /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/ + int txS,txE,tyS,tyE,dx,dy; + /** Temporary values for Tile parts, initialised in pi_create_encode */ + int lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t; +} opj_poc_t; + +/** +Compression parameters +*/ +typedef struct opj_cparameters { + /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */ + opj_bool tile_size_on; + /** XTOsiz */ + int cp_tx0; + /** YTOsiz */ + int cp_ty0; + /** XTsiz */ + int cp_tdx; + /** YTsiz */ + int cp_tdy; + /** allocation by rate/distortion */ + int cp_disto_alloc; + /** allocation by fixed layer */ + int cp_fixed_alloc; + /** add fixed_quality */ + int cp_fixed_quality; + /** fixed layer */ + int *cp_matrice; + /** comment for coding */ + char *cp_comment; + /** csty : coding style */ + int csty; + /** progression order (default LRCP) */ + OPJ_PROG_ORDER prog_order; + /** progression order changes */ + opj_poc_t POC[32]; + /** number of progression order changes (POC), default to 0 */ + int numpocs; + /** number of layers */ + int tcp_numlayers; + /** rates of layers */ + float tcp_rates[100]; + /** different psnr for successive layers */ + float tcp_distoratio[100]; + /** number of resolutions */ + int numresolution; + /** initial code block width, default to 64 */ + int cblockw_init; + /** initial code block height, default to 64 */ + int cblockh_init; + /** mode switch (cblk_style) */ + int mode; + /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */ + int irreversible; + /** region of interest: affected component in [0..3], -1 means no ROI */ + int roi_compno; + /** region of interest: upshift value */ + int roi_shift; + /* number of precinct size specifications */ + int res_spec; + /** initial precinct width */ + int prcw_init[J2K_MAXRLVLS]; + /** initial precinct height */ + int prch_init[J2K_MAXRLVLS]; + + /**@name command line encoder parameters (not used inside the library) */ + /*@{*/ + /** input file name */ + char infile[OPJ_PATH_LEN]; + /** output file name */ + char outfile[OPJ_PATH_LEN]; + /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */ + int index_on; + /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */ + char index[OPJ_PATH_LEN]; + /** subimage encoding: origin image offset in x direction */ + int image_offset_x0; + /** subimage encoding: origin image offset in y direction */ + int image_offset_y0; + /** subsampling value for dx */ + int subsampling_dx; + /** subsampling value for dy */ + int subsampling_dy; + /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/ + int decod_format; + /** output file format 0: J2K, 1: JP2, 2: JPT */ + int cod_format; + /*@}*/ + +/* UniPG>> */ + /**@name JPWL encoding parameters */ + /*@{*/ + /** enables writing of EPC in MH, thus activating JPWL */ + opj_bool jpwl_epc_on; + /** error protection method for MH (0,1,16,32,37-128) */ + int jpwl_hprot_MH; + /** tile number of header protection specification (>=0) */ + int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS]; + /** error protection methods for TPHs (0,1,16,32,37-128) */ + int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS]; + /** tile number of packet protection specification (>=0) */ + int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS]; + /** packet number of packet protection specification (>=0) */ + int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS]; + /** error protection methods for packets (0,1,16,32,37-128) */ + int jpwl_pprot[JPWL_MAX_NO_PACKSPECS]; + /** enables writing of ESD, (0=no/1/2 bytes) */ + int jpwl_sens_size; + /** sensitivity addressing size (0=auto/2/4 bytes) */ + int jpwl_sens_addr; + /** sensitivity range (0-3) */ + int jpwl_sens_range; + /** sensitivity method for MH (-1=no,0-7) */ + int jpwl_sens_MH; + /** tile number of sensitivity specification (>=0) */ + int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS]; + /** sensitivity methods for TPHs (-1=no,0-7) */ + int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS]; + /*@}*/ +/* <> */ + /**@name JPWL decoding parameters */ + /*@{*/ + /** activates the JPWL correction capabilities */ + opj_bool jpwl_correct; + /** expected number of components */ + int jpwl_exp_comps; + /** maximum number of tiles */ + int jpwl_max_tiles; + /*@}*/ +/* <> */ +/** +Marker structure +*/ +typedef struct opj_marker_info_t { + /** marker type */ + unsigned short int type; + /** position in codestream */ + int pos; + /** length, marker val included */ + int len; +} opj_marker_info_t; +/* <> */ + /** number of markers */ + int marknum; + /** list of markers */ + opj_marker_info_t *marker; + /** actual size of markers array */ + int maxmarknum; +/* <cp. +@param dinfo decompressor handle +@param parameters decompression parameters +*/ +OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters); +/** +Decode an image from a JPEG-2000 codestream +@param dinfo decompressor handle +@param cio Input buffer stream +@return Returns a decoded image if successful, returns NULL otherwise +*/ +OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio); + +/** +Decode an image from a JPEG-2000 codestream and extract the codestream information +@param dinfo decompressor handle +@param cio Input buffer stream +@param cstr_info Codestream information structure if needed afterwards, NULL otherwise +@return Returns a decoded image if successful, returns NULL otherwise +*/ +OPJ_API opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info); +/** +Creates a J2K/JP2 compression structure +@param format Coder to select +@return Returns a handle to a compressor if successful, returns NULL otherwise +*/ +OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format); +/** +Destroy a compressor handle +@param cinfo compressor handle to destroy +*/ +OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo); +/** +Set encoding parameters to default values, that means : +
      +
    • Lossless +
    • 1 tile +
    • Size of precinct : 2^15 x 2^15 (means 1 precinct) +
    • Size of code-block : 64 x 64 +
    • Number of resolutions: 6 +
    • No SOP marker in the codestream +
    • No EPH marker in the codestream +
    • No sub-sampling in x or y direction +
    • No mode switch activated +
    • Progression order: LRCP +
    • No index file +
    • No ROI upshifted +
    • No offset of the origin of the image +
    • No offset of the origin of the tiles +
    • Reversible DWT 5-3 +
    +@param parameters Compression parameters +*/ +OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters); +/** +Setup the encoder parameters using the current image and using user parameters. +@param cinfo Compressor handle +@param parameters Compression parameters +@param image Input filled image +*/ +OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image); +/** +Encode an image into a JPEG-2000 codestream +3@param cinfo compressor handle +@param cio Output buffer stream +@param image Image to encode +@param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci() +@return Returns true if successful, returns false otherwise +*/ +OPJ_API opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index); +/** +Encode an image into a JPEG-2000 codestream and extract the codestream information +@param cinfo compressor handle +@param cio Output buffer stream +@param image Image to encode +@param cstr_info Codestream information structure if needed afterwards, NULL otherwise +@return Returns true if successful, returns false otherwise +*/ +OPJ_API opj_bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info); +/** +Destroy Codestream information after compression or decompression +@param cstr_info Codestream information structure +*/ +OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info); + + +#ifdef __cplusplus +} +#endif + +#endif /* OPENJPEG_H */ diff --git a/Source/LibOpenJPEG/opj_includes.h b/Source/LibOpenJPEG/opj_includes.h index aaca54e..2b5866a 100644 --- a/Source/LibOpenJPEG/opj_includes.h +++ b/Source/LibOpenJPEG/opj_includes.h @@ -1,140 +1,140 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef OPJ_INCLUDES_H -#define OPJ_INCLUDES_H - -/* - ========================================================== - Standard includes used by the library - ========================================================== -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - ========================================================== - OpenJPEG interface - ========================================================== - */ -#include "openjpeg.h" - -/* - ========================================================== - OpenJPEG modules - ========================================================== -*/ - -/* Ignore GCC attributes if this is not GCC */ -#ifndef __GNUC__ - #define __attribute__(x) /* __attribute__(x) */ -#endif - -/* -The inline keyword is supported by C99 but not by C90. -Most compilers implement their own version of this keyword ... -*/ -#ifndef INLINE - #if defined(_MSC_VER) - #define INLINE __forceinline - #elif defined(__GNUC__) - #define INLINE __inline__ - #elif defined(__MWERKS__) - #define INLINE inline - #else - /* add other compilers here ... */ - #define INLINE - #endif /* defined() */ -#endif /* INLINE */ - -/* Are restricted pointers available? (C99) */ -#if (__STDC_VERSION__ != 199901L) - /* Not a C99 compiler */ - #ifdef __GNUC__ - #define restrict __restrict__ - #else - #define restrict /* restrict */ - #endif -#endif - -/* MSVC and Borland C do not have lrintf */ -#if defined(_MSC_VER) || defined(__BORLANDC__) -static INLINE long lrintf(float f){ -#ifdef _M_X64 - return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); -#else - int i; - - _asm{ - fld f - fistp i - }; - - return i; -#endif -} -#endif - -#include "j2k_lib.h" -#include "opj_malloc.h" -#include "event.h" -#include "bio.h" -#include "cio.h" - -#include "image.h" -#include "j2k.h" -#include "jp2.h" -#include "jpt.h" - -#include "mqc.h" -#include "raw.h" -#include "bio.h" -#include "tgt.h" -#include "pi.h" -#include "tcd.h" -#include "t1.h" -#include "dwt.h" -#include "t2.h" -#include "mct.h" -#include "int.h" -#include "fix.h" - -#include "cidx_manager.h" -#include "indexbox_manager.h" - -/* JPWL>> */ -#ifdef USE_JPWL -#include "./jpwl/jpwl.h" -#endif /* USE_JPWL */ -/* < +#include +#include +#include +#include +#include +#include +#include +#include + +/* + ========================================================== + OpenJPEG interface + ========================================================== + */ +#include "openjpeg.h" + +/* + ========================================================== + OpenJPEG modules + ========================================================== +*/ + +/* Ignore GCC attributes if this is not GCC */ +#ifndef __GNUC__ + #define __attribute__(x) /* __attribute__(x) */ +#endif + +/* +The inline keyword is supported by C99 but not by C90. +Most compilers implement their own version of this keyword ... +*/ +#ifndef INLINE + #if defined(_MSC_VER) + #define INLINE __forceinline + #elif defined(__GNUC__) + #define INLINE __inline__ + #elif defined(__MWERKS__) + #define INLINE inline + #else + /* add other compilers here ... */ + #define INLINE + #endif /* defined() */ +#endif /* INLINE */ + +/* Are restricted pointers available? (C99) */ +#if (__STDC_VERSION__ != 199901L) + /* Not a C99 compiler */ + #ifdef __GNUC__ + #define restrict __restrict__ + #else + #define restrict /* restrict */ + #endif +#endif + +/* MSVC and Borland C do not have lrintf */ +#if defined(_MSC_VER) || defined(__BORLANDC__) +static INLINE long lrintf(float f){ +#ifdef _M_X64 + return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); +#else + int i; + + _asm{ + fld f + fistp i + }; + + return i; +#endif +} +#endif + +#include "j2k_lib.h" +#include "opj_malloc.h" +#include "event.h" +#include "bio.h" +#include "cio.h" + +#include "image.h" +#include "j2k.h" +#include "jp2.h" +#include "jpt.h" + +#include "mqc.h" +#include "raw.h" +#include "bio.h" +#include "tgt.h" +#include "pi.h" +#include "tcd.h" +#include "t1.h" +#include "dwt.h" +#include "t2.h" +#include "mct.h" +#include "int.h" +#include "fix.h" + +#include "cidx_manager.h" +#include "indexbox_manager.h" + +/* JPWL>> */ +#ifdef USE_JPWL +#include "./jpwl/jpwl.h" +#endif /* USE_JPWL */ +/* < - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __OPJ_MALLOC_H -#define __OPJ_MALLOC_H -/** -@file opj_malloc.h -@brief Internal functions - -The functions in opj_malloc.h are internal utilities used for memory management. -*/ - -/** @defgroup MISC MISC - Miscellaneous internal functions */ -/*@{*/ - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ - -/** -Allocate an uninitialized memory block -@param size Bytes to allocate -@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available -*/ -#ifdef ALLOC_PERF_OPT -void * OPJ_CALLCONV opj_malloc(size_t size); -#else -#define opj_malloc(size) malloc(size) -#endif - -/** -Allocate a memory block with elements initialized to 0 -@param num Blocks to allocate -@param size Bytes per block to allocate -@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available -*/ -#ifdef ALLOC_PERF_OPT -void * OPJ_CALLCONV opj_calloc(size_t _NumOfElements, size_t _SizeOfElements); -#else -#define opj_calloc(num, size) calloc(num, size) -#endif - -/** -Allocate memory aligned to a 16 byte boundry -@param size Bytes to allocate -@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available -*/ -/* FIXME: These should be set with cmake tests, but we're currently not requiring use of cmake */ -#ifdef _WIN32 - /* Someone should tell the mingw people that their malloc.h ought to provide _mm_malloc() */ - #ifdef __GNUC__ - #include - #define HAVE_MM_MALLOC - #else /* MSVC, Intel C++ */ - #include - #ifdef _mm_malloc - #define HAVE_MM_MALLOC - #endif - #endif -#else /* Not _WIN32 */ - #if defined(__sun) - #define HAVE_MEMALIGN - #elif defined(__FreeBSD__) - #define HAVE_POSIX_MEMALIGN - /* Linux x86_64 and OSX always align allocations to 16 bytes */ - #elif !defined(__amd64__) && !defined(__APPLE__) && !defined(_AIX) - #define HAVE_MEMALIGN - #include - #endif -#endif - -#define opj_aligned_malloc(size) malloc(size) -#define opj_aligned_free(m) free(m) - -#ifdef HAVE_MM_MALLOC - #undef opj_aligned_malloc - #define opj_aligned_malloc(size) _mm_malloc(size, 16) - #undef opj_aligned_free - #define opj_aligned_free(m) _mm_free(m) -#endif - -#ifdef HAVE_MEMALIGN - extern void* memalign(size_t, size_t); - #undef opj_aligned_malloc - #define opj_aligned_malloc(size) memalign(16, (size)) - #undef opj_aligned_free - #define opj_aligned_free(m) free(m) -#endif - -#ifdef HAVE_POSIX_MEMALIGN - #undef opj_aligned_malloc - extern int posix_memalign(void**, size_t, size_t); - - static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){ - void* mem = NULL; - posix_memalign(&mem, 16, size); - return mem; - } - #undef opj_aligned_free - #define opj_aligned_free(m) free(m) -#endif - -#ifdef ALLOC_PERF_OPT - #undef opj_aligned_malloc - #define opj_aligned_malloc(size) opj_malloc(size) - #undef opj_aligned_free - #define opj_aligned_free(m) opj_free(m) -#endif - -/** -Reallocate memory blocks. -@param m Pointer to previously allocated memory block -@param s New size in bytes -@return Returns a void pointer to the reallocated (and possibly moved) memory block -*/ -#ifdef ALLOC_PERF_OPT -void * OPJ_CALLCONV opj_realloc(void * m, size_t s); -#else -#define opj_realloc(m, s) realloc(m, s) -#endif - -/** -Deallocates or frees a memory block. -@param m Previously allocated memory block to be freed -*/ -#ifdef ALLOC_PERF_OPT -void OPJ_CALLCONV opj_free(void * m); -#else -#define opj_free(m) free(m) -#endif - -#ifdef __GNUC__ -#pragma GCC poison malloc calloc realloc free -#endif - -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __OPJ_MALLOC_H */ - +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2007, Callum Lerwick + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __OPJ_MALLOC_H +#define __OPJ_MALLOC_H +/** +@file opj_malloc.h +@brief Internal functions + +The functions in opj_malloc.h are internal utilities used for memory management. +*/ + +/** @defgroup MISC MISC - Miscellaneous internal functions */ +/*@{*/ + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ + +/** +Allocate an uninitialized memory block +@param size Bytes to allocate +@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available +*/ +#ifdef ALLOC_PERF_OPT +void * OPJ_CALLCONV opj_malloc(size_t size); +#else +#define opj_malloc(size) malloc(size) +#endif + +/** +Allocate a memory block with elements initialized to 0 +@param num Blocks to allocate +@param size Bytes per block to allocate +@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available +*/ +#ifdef ALLOC_PERF_OPT +void * OPJ_CALLCONV opj_calloc(size_t _NumOfElements, size_t _SizeOfElements); +#else +#define opj_calloc(num, size) calloc(num, size) +#endif + +/** +Allocate memory aligned to a 16 byte boundry +@param size Bytes to allocate +@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available +*/ +/* FIXME: These should be set with cmake tests, but we're currently not requiring use of cmake */ +#ifdef _WIN32 + /* Someone should tell the mingw people that their malloc.h ought to provide _mm_malloc() */ + #ifdef __GNUC__ + #include + #define HAVE_MM_MALLOC + #else /* MSVC, Intel C++ */ + #include + #ifdef _mm_malloc + #define HAVE_MM_MALLOC + #endif + #endif +#else /* Not _WIN32 */ + #if defined(__sun) + #define HAVE_MEMALIGN + #elif defined(__FreeBSD__) + #define HAVE_POSIX_MEMALIGN + /* Linux x86_64 and OSX always align allocations to 16 bytes */ + #elif !defined(__amd64__) && !defined(__APPLE__) && !defined(_AIX) + #define HAVE_MEMALIGN + #include + #endif +#endif + +#define opj_aligned_malloc(size) malloc(size) +#define opj_aligned_free(m) free(m) + +#ifdef HAVE_MM_MALLOC + #undef opj_aligned_malloc + #define opj_aligned_malloc(size) _mm_malloc(size, 16) + #undef opj_aligned_free + #define opj_aligned_free(m) _mm_free(m) +#endif + +#ifdef HAVE_MEMALIGN + extern void* memalign(size_t, size_t); + #undef opj_aligned_malloc + #define opj_aligned_malloc(size) memalign(16, (size)) + #undef opj_aligned_free + #define opj_aligned_free(m) free(m) +#endif + +#ifdef HAVE_POSIX_MEMALIGN + #undef opj_aligned_malloc + extern int posix_memalign(void**, size_t, size_t); + + static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){ + void* mem = NULL; + posix_memalign(&mem, 16, size); + return mem; + } + #undef opj_aligned_free + #define opj_aligned_free(m) free(m) +#endif + +#ifdef ALLOC_PERF_OPT + #undef opj_aligned_malloc + #define opj_aligned_malloc(size) opj_malloc(size) + #undef opj_aligned_free + #define opj_aligned_free(m) opj_free(m) +#endif + +/** +Reallocate memory blocks. +@param m Pointer to previously allocated memory block +@param s New size in bytes +@return Returns a void pointer to the reallocated (and possibly moved) memory block +*/ +#ifdef ALLOC_PERF_OPT +void * OPJ_CALLCONV opj_realloc(void * m, size_t s); +#else +#define opj_realloc(m, s) realloc(m, s) +#endif + +/** +Deallocates or frees a memory block. +@param m Previously allocated memory block to be freed +*/ +#ifdef ALLOC_PERF_OPT +void OPJ_CALLCONV opj_free(void * m); +#else +#define opj_free(m) free(m) +#endif + +#ifdef __GNUC__ +#pragma GCC poison malloc calloc realloc free +#endif + +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __OPJ_MALLOC_H */ + diff --git a/Source/LibOpenJPEG/phix_manager.c b/Source/LibOpenJPEG/phix_manager.c index f022773..4995d48 100644 --- a/Source/LibOpenJPEG/phix_manager.c +++ b/Source/LibOpenJPEG/phix_manager.c @@ -1,170 +1,170 @@ -/* - * $Id: phix_manager.c,v 1.2 2012/09/23 12:44:41 drolon Exp $ - * - * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2011, Professor Benoit Macq - * Copyright (c) 2003-2004, Yannick Verschueren - * Copyright (c) 2010-2011, Kaori Hagihara - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/*! \file - * \brief Modification of jpip.c from 2KAN indexer - */ - -#include -#include -#include "opj_includes.h" - -/* - * Write faix box of phix - * - * @param[in] coff offset of j2k codestream - * @param[in] compno component number - * @param[in] cstr_info codestream information - * @param[in] EPHused true if if EPH option used - * @param[in] j2klen length of j2k codestream - * @param[in] cio file output handle - * @return length of faix box - */ -int write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio); - -int write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio) -{ - int len, lenp=0, compno, i; - opj_jp2_box_t *box; - - box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t)); - - for( i=0;i<2;i++){ - if (i) cio_seek( cio, lenp); - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_PHIX, 4); /* PHIX */ - - write_manf( i, cstr_info.numcomps, box, cio); - - for( compno=0; compno pow( 2, 32)){ - size_of_coding = 8; - version = 1; - } - else{ - size_of_coding = 4; - version = 0; - } - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_FAIX, 4); /* FAIX */ - cio_write( cio, version,1); /* Version 0 = 4 bytes */ - - nmax = 0; - for( i=0; i<=cstr_info.numdecompos[compno]; i++) - nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers; - - cio_write( cio, nmax, size_of_coding); /* NMAX */ - cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */ - - for( tileno=0; tilenopw[resno]*tile_Idx->ph[resno]; - for( precno=0; precnopacket[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno]; - break; - case RLCP: - packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno]; - break; - case RPCL: - packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno]; - break; - case PCRL: - packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno]; - break; - case CPRL: - packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno]; - break; - default: - fprintf( stderr, "failed to ppix indexing\n"); - } - - cio_write( cio, packet.start_pos-coff, size_of_coding); /* start position */ - cio_write( cio, packet.end_ph_pos-packet.start_pos+1, size_of_coding); /* length */ - - num_packet++; - } - } - } - - /* PADDING */ - while( num_packet < nmax){ - cio_write( cio, 0, size_of_coding); /* start position */ - cio_write( cio, 0, size_of_coding); /* length */ - num_packet++; - } - } - - len = cio_tell( cio)-lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); - - return len; -} +/* + * $Id: phix_manager.c,v 1.2 2012/09/23 12:44:41 drolon Exp $ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2003-2004, Yannick Verschueren + * Copyright (c) 2010-2011, Kaori Hagihara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*! \file + * \brief Modification of jpip.c from 2KAN indexer + */ + +#include +#include +#include "opj_includes.h" + +/* + * Write faix box of phix + * + * @param[in] coff offset of j2k codestream + * @param[in] compno component number + * @param[in] cstr_info codestream information + * @param[in] EPHused true if if EPH option used + * @param[in] j2klen length of j2k codestream + * @param[in] cio file output handle + * @return length of faix box + */ +int write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio); + +int write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio) +{ + int len, lenp=0, compno, i; + opj_jp2_box_t *box; + + box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t)); + + for( i=0;i<2;i++){ + if (i) cio_seek( cio, lenp); + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_PHIX, 4); /* PHIX */ + + write_manf( i, cstr_info.numcomps, box, cio); + + for( compno=0; compno pow( 2, 32)){ + size_of_coding = 8; + version = 1; + } + else{ + size_of_coding = 4; + version = 0; + } + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_FAIX, 4); /* FAIX */ + cio_write( cio, version,1); /* Version 0 = 4 bytes */ + + nmax = 0; + for( i=0; i<=cstr_info.numdecompos[compno]; i++) + nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers; + + cio_write( cio, nmax, size_of_coding); /* NMAX */ + cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */ + + for( tileno=0; tilenopw[resno]*tile_Idx->ph[resno]; + for( precno=0; precnopacket[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno]; + break; + case RLCP: + packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno]; + break; + case RPCL: + packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno]; + break; + case PCRL: + packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno]; + break; + case CPRL: + packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno]; + break; + default: + fprintf( stderr, "failed to ppix indexing\n"); + } + + cio_write( cio, packet.start_pos-coff, size_of_coding); /* start position */ + cio_write( cio, packet.end_ph_pos-packet.start_pos+1, size_of_coding); /* length */ + + num_packet++; + } + } + } + + /* PADDING */ + while( num_packet < nmax){ + cio_write( cio, 0, size_of_coding); /* start position */ + cio_write( cio, 0, size_of_coding); /* length */ + num_packet++; + } + } + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); + + return len; +} diff --git a/Source/LibOpenJPEG/pi.c b/Source/LibOpenJPEG/pi.c index 706053b..e8e33bf 100644 --- a/Source/LibOpenJPEG/pi.c +++ b/Source/LibOpenJPEG/pi.c @@ -1,963 +1,963 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2006-2007, Parvatha Elangovan - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/** @defgroup PI PI - Implementation of a packet iterator */ -/*@{*/ - -/** @name Local static functions */ -/*@{*/ - -/** -Get next packet in layer-resolution-component-precinct order. -@param pi packet iterator to modify -@return returns false if pi pointed to the last packet or else returns true -*/ -static opj_bool pi_next_lrcp(opj_pi_iterator_t * pi); -/** -Get next packet in resolution-layer-component-precinct order. -@param pi packet iterator to modify -@return returns false if pi pointed to the last packet or else returns true -*/ -static opj_bool pi_next_rlcp(opj_pi_iterator_t * pi); -/** -Get next packet in resolution-precinct-component-layer order. -@param pi packet iterator to modify -@return returns false if pi pointed to the last packet or else returns true -*/ -static opj_bool pi_next_rpcl(opj_pi_iterator_t * pi); -/** -Get next packet in precinct-component-resolution-layer order. -@param pi packet iterator to modify -@return returns false if pi pointed to the last packet or else returns true -*/ -static opj_bool pi_next_pcrl(opj_pi_iterator_t * pi); -/** -Get next packet in component-precinct-resolution-layer order. -@param pi packet iterator to modify -@return returns false if pi pointed to the last packet or else returns true -*/ -static opj_bool pi_next_cprl(opj_pi_iterator_t * pi); - -/*@}*/ - -/*@}*/ - -/* -========================================================== - local functions -========================================================== -*/ - -static opj_bool pi_next_lrcp(opj_pi_iterator_t * pi) { - opj_pi_comp_t *comp = NULL; - opj_pi_resolution_t *res = NULL; - long index = 0; - - if (!pi->first) { - comp = &pi->comps[pi->compno]; - res = &comp->resolutions[pi->resno]; - goto LABEL_SKIP; - } else { - pi->first = 0; - } - - for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { - for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; - pi->resno++) { - for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { - comp = &pi->comps[pi->compno]; - if (pi->resno >= comp->numresolutions) { - continue; - } - res = &comp->resolutions[pi->resno]; - if (!pi->tp_on){ - pi->poc.precno1 = res->pw * res->ph; - } - for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) { - index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; - if (!pi->include[index]) { - pi->include[index] = 1; - return OPJ_TRUE; - } -LABEL_SKIP:; - } - } - } - } - - return OPJ_FALSE; -} - -static opj_bool pi_next_rlcp(opj_pi_iterator_t * pi) { - opj_pi_comp_t *comp = NULL; - opj_pi_resolution_t *res = NULL; - long index = 0; - - if (!pi->first) { - comp = &pi->comps[pi->compno]; - res = &comp->resolutions[pi->resno]; - goto LABEL_SKIP; - } else { - pi->first = 0; - } - - for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { - for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { - for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { - comp = &pi->comps[pi->compno]; - if (pi->resno >= comp->numresolutions) { - continue; - } - res = &comp->resolutions[pi->resno]; - if(!pi->tp_on){ - pi->poc.precno1 = res->pw * res->ph; - } - for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) { - index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; - if (!pi->include[index]) { - pi->include[index] = 1; - return OPJ_TRUE; - } -LABEL_SKIP:; - } - } - } - } - - return OPJ_FALSE; -} - -static opj_bool pi_next_rpcl(opj_pi_iterator_t * pi) { - opj_pi_comp_t *comp = NULL; - opj_pi_resolution_t *res = NULL; - long index = 0; - - if (!pi->first) { - goto LABEL_SKIP; - } else { - int compno, resno; - pi->first = 0; - pi->dx = 0; - pi->dy = 0; - for (compno = 0; compno < pi->numcomps; compno++) { - comp = &pi->comps[compno]; - for (resno = 0; resno < comp->numresolutions; resno++) { - int dx, dy; - res = &comp->resolutions[resno]; - dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno)); - dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno)); - pi->dx = !pi->dx ? dx : int_min(pi->dx, dx); - pi->dy = !pi->dy ? dy : int_min(pi->dy, dy); - } - } - } -if (!pi->tp_on){ - pi->poc.ty0 = pi->ty0; - pi->poc.tx0 = pi->tx0; - pi->poc.ty1 = pi->ty1; - pi->poc.tx1 = pi->tx1; - } - for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { - for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) { - for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) { - for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { - int levelno; - int trx0, try0; - int trx1, try1; - int rpx, rpy; - int prci, prcj; - comp = &pi->comps[pi->compno]; - if (pi->resno >= comp->numresolutions) { - continue; - } - res = &comp->resolutions[pi->resno]; - levelno = comp->numresolutions - 1 - pi->resno; - trx0 = int_ceildiv(pi->tx0, comp->dx << levelno); - try0 = int_ceildiv(pi->ty0, comp->dy << levelno); - trx1 = int_ceildiv(pi->tx1, comp->dx << levelno); - try1 = int_ceildiv(pi->ty1, comp->dy << levelno); - rpx = res->pdx + levelno; - rpy = res->pdy + levelno; - if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ - continue; - } - if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ - continue; - } - - if ((res->pw==0)||(res->ph==0)) continue; - - if ((trx0==trx1)||(try0==try1)) continue; - - prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx) - - int_floordivpow2(trx0, res->pdx); - prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy) - - int_floordivpow2(try0, res->pdy); - pi->precno = prci + prcj * res->pw; - for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { - index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; - if (!pi->include[index]) { - pi->include[index] = 1; - return OPJ_TRUE; - } -LABEL_SKIP:; - } - } - } - } - } - - return OPJ_FALSE; -} - -static opj_bool pi_next_pcrl(opj_pi_iterator_t * pi) { - opj_pi_comp_t *comp = NULL; - opj_pi_resolution_t *res = NULL; - long index = 0; - - if (!pi->first) { - comp = &pi->comps[pi->compno]; - goto LABEL_SKIP; - } else { - int compno, resno; - pi->first = 0; - pi->dx = 0; - pi->dy = 0; - for (compno = 0; compno < pi->numcomps; compno++) { - comp = &pi->comps[compno]; - for (resno = 0; resno < comp->numresolutions; resno++) { - int dx, dy; - res = &comp->resolutions[resno]; - dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno)); - dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno)); - pi->dx = !pi->dx ? dx : int_min(pi->dx, dx); - pi->dy = !pi->dy ? dy : int_min(pi->dy, dy); - } - } - } - if (!pi->tp_on){ - pi->poc.ty0 = pi->ty0; - pi->poc.tx0 = pi->tx0; - pi->poc.ty1 = pi->ty1; - pi->poc.tx1 = pi->tx1; - } - for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) { - for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) { - for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { - comp = &pi->comps[pi->compno]; - for (pi->resno = pi->poc.resno0; pi->resno < int_min(pi->poc.resno1, comp->numresolutions); pi->resno++) { - int levelno; - int trx0, try0; - int trx1, try1; - int rpx, rpy; - int prci, prcj; - res = &comp->resolutions[pi->resno]; - levelno = comp->numresolutions - 1 - pi->resno; - trx0 = int_ceildiv(pi->tx0, comp->dx << levelno); - try0 = int_ceildiv(pi->ty0, comp->dy << levelno); - trx1 = int_ceildiv(pi->tx1, comp->dx << levelno); - try1 = int_ceildiv(pi->ty1, comp->dy << levelno); - rpx = res->pdx + levelno; - rpy = res->pdy + levelno; - if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ - continue; - } - if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ - continue; - } - - if ((res->pw==0)||(res->ph==0)) continue; - - if ((trx0==trx1)||(try0==try1)) continue; - - prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx) - - int_floordivpow2(trx0, res->pdx); - prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy) - - int_floordivpow2(try0, res->pdy); - pi->precno = prci + prcj * res->pw; - for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { - index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; - if (!pi->include[index]) { - pi->include[index] = 1; - return OPJ_TRUE; - } -LABEL_SKIP:; - } - } - } - } - } - - return OPJ_FALSE; -} - -static opj_bool pi_next_cprl(opj_pi_iterator_t * pi) { - opj_pi_comp_t *comp = NULL; - opj_pi_resolution_t *res = NULL; - long index = 0; - - if (!pi->first) { - comp = &pi->comps[pi->compno]; - goto LABEL_SKIP; - } else { - pi->first = 0; - } - - for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { - int resno; - comp = &pi->comps[pi->compno]; - pi->dx = 0; - pi->dy = 0; - for (resno = 0; resno < comp->numresolutions; resno++) { - int dx, dy; - res = &comp->resolutions[resno]; - dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno)); - dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno)); - pi->dx = !pi->dx ? dx : int_min(pi->dx, dx); - pi->dy = !pi->dy ? dy : int_min(pi->dy, dy); - } - if (!pi->tp_on){ - pi->poc.ty0 = pi->ty0; - pi->poc.tx0 = pi->tx0; - pi->poc.ty1 = pi->ty1; - pi->poc.tx1 = pi->tx1; - } - for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) { - for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) { - for (pi->resno = pi->poc.resno0; pi->resno < int_min(pi->poc.resno1, comp->numresolutions); pi->resno++) { - int levelno; - int trx0, try0; - int trx1, try1; - int rpx, rpy; - int prci, prcj; - res = &comp->resolutions[pi->resno]; - levelno = comp->numresolutions - 1 - pi->resno; - trx0 = int_ceildiv(pi->tx0, comp->dx << levelno); - try0 = int_ceildiv(pi->ty0, comp->dy << levelno); - trx1 = int_ceildiv(pi->tx1, comp->dx << levelno); - try1 = int_ceildiv(pi->ty1, comp->dy << levelno); - rpx = res->pdx + levelno; - rpy = res->pdy + levelno; - if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ - continue; - } - if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ - continue; - } - - if ((res->pw==0)||(res->ph==0)) continue; - - if ((trx0==trx1)||(try0==try1)) continue; - - prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx) - - int_floordivpow2(trx0, res->pdx); - prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy) - - int_floordivpow2(try0, res->pdy); - pi->precno = prci + prcj * res->pw; - for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { - index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; - if (!pi->include[index]) { - pi->include[index] = 1; - return OPJ_TRUE; - } -LABEL_SKIP:; - } - } - } - } - } - - return OPJ_FALSE; -} - -/* -========================================================== - Packet iterator interface -========================================================== -*/ - -opj_pi_iterator_t *pi_create_decode(opj_image_t *image, opj_cp_t *cp, int tileno) { - int p, q; - int compno, resno, pino; - opj_pi_iterator_t *pi = NULL; - opj_tcp_t *tcp = NULL; - opj_tccp_t *tccp = NULL; - - tcp = &cp->tcps[tileno]; - - pi = (opj_pi_iterator_t*) opj_calloc((tcp->numpocs + 1), sizeof(opj_pi_iterator_t)); - if(!pi) { - /* TODO: throw an error */ - return NULL; - } - - for (pino = 0; pino < tcp->numpocs + 1; pino++) { /* change */ - int maxres = 0; - int maxprec = 0; - p = tileno % cp->tw; - q = tileno / cp->tw; - - pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, image->x0); - pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, image->y0); - pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1); - pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1); - pi[pino].numcomps = image->numcomps; - - pi[pino].comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t)); - if(!pi[pino].comps) { - /* TODO: throw an error */ - pi_destroy(pi, cp, tileno); - return NULL; - } - - for (compno = 0; compno < pi->numcomps; compno++) { - int tcx0, tcy0, tcx1, tcy1; - opj_pi_comp_t *comp = &pi[pino].comps[compno]; - tccp = &tcp->tccps[compno]; - comp->dx = image->comps[compno].dx; - comp->dy = image->comps[compno].dy; - comp->numresolutions = tccp->numresolutions; - - comp->resolutions = (opj_pi_resolution_t*) opj_calloc(comp->numresolutions, sizeof(opj_pi_resolution_t)); - if(!comp->resolutions) { - /* TODO: throw an error */ - pi_destroy(pi, cp, tileno); - return NULL; - } - - tcx0 = int_ceildiv(pi->tx0, comp->dx); - tcy0 = int_ceildiv(pi->ty0, comp->dy); - tcx1 = int_ceildiv(pi->tx1, comp->dx); - tcy1 = int_ceildiv(pi->ty1, comp->dy); - if (comp->numresolutions > maxres) { - maxres = comp->numresolutions; - } - - for (resno = 0; resno < comp->numresolutions; resno++) { - int levelno; - int rx0, ry0, rx1, ry1; - int px0, py0, px1, py1; - opj_pi_resolution_t *res = &comp->resolutions[resno]; - if (tccp->csty & J2K_CCP_CSTY_PRT) { - res->pdx = tccp->prcw[resno]; - res->pdy = tccp->prch[resno]; - } else { - res->pdx = 15; - res->pdy = 15; - } - levelno = comp->numresolutions - 1 - resno; - rx0 = int_ceildivpow2(tcx0, levelno); - ry0 = int_ceildivpow2(tcy0, levelno); - rx1 = int_ceildivpow2(tcx1, levelno); - ry1 = int_ceildivpow2(tcy1, levelno); - px0 = int_floordivpow2(rx0, res->pdx) << res->pdx; - py0 = int_floordivpow2(ry0, res->pdy) << res->pdy; - px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx; - py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy; - res->pw = (rx0==rx1)?0:((px1 - px0) >> res->pdx); - res->ph = (ry0==ry1)?0:((py1 - py0) >> res->pdy); - - if (res->pw*res->ph > maxprec) { - maxprec = res->pw*res->ph; - } - - } - } - - tccp = &tcp->tccps[0]; - pi[pino].step_p = 1; - pi[pino].step_c = maxprec * pi[pino].step_p; - pi[pino].step_r = image->numcomps * pi[pino].step_c; - pi[pino].step_l = maxres * pi[pino].step_r; - - if (pino == 0) { - pi[pino].include = (short int*) opj_calloc(image->numcomps * maxres * tcp->numlayers * maxprec, sizeof(short int)); - if(!pi[pino].include) { - /* TODO: throw an error */ - pi_destroy(pi, cp, tileno); - return NULL; - } - } - else { - pi[pino].include = pi[pino - 1].include; - } - - if (tcp->POC == 0) { - pi[pino].first = 1; - pi[pino].poc.resno0 = 0; - pi[pino].poc.compno0 = 0; - pi[pino].poc.layno1 = tcp->numlayers; - pi[pino].poc.resno1 = maxres; - pi[pino].poc.compno1 = image->numcomps; - pi[pino].poc.prg = tcp->prg; - } else { - pi[pino].first = 1; - pi[pino].poc.resno0 = tcp->pocs[pino].resno0; - pi[pino].poc.compno0 = tcp->pocs[pino].compno0; - pi[pino].poc.layno1 = tcp->pocs[pino].layno1; - pi[pino].poc.resno1 = tcp->pocs[pino].resno1; - pi[pino].poc.compno1 = tcp->pocs[pino].compno1; - pi[pino].poc.prg = tcp->pocs[pino].prg; - } - pi[pino].poc.layno0 = 0; - pi[pino].poc.precno0 = 0; - pi[pino].poc.precno1 = maxprec; - - } - - return pi; -} - - -opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int tileno, J2K_T2_MODE t2_mode){ - int p, q, pino; - int compno, resno; - int maxres = 0; - int maxprec = 0; - opj_pi_iterator_t *pi = NULL; - opj_tcp_t *tcp = NULL; - opj_tccp_t *tccp = NULL; - - tcp = &cp->tcps[tileno]; - - pi = (opj_pi_iterator_t*) opj_calloc((tcp->numpocs + 1), sizeof(opj_pi_iterator_t)); - if(!pi) { return NULL;} - pi->tp_on = cp->tp_on; - - for(pino = 0;pino < tcp->numpocs+1 ; pino ++){ - p = tileno % cp->tw; - q = tileno / cp->tw; - - pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, image->x0); - pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, image->y0); - pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1); - pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1); - pi[pino].numcomps = image->numcomps; - - pi[pino].comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t)); - if(!pi[pino].comps) { - pi_destroy(pi, cp, tileno); - return NULL; - } - - for (compno = 0; compno < pi[pino].numcomps; compno++) { - int tcx0, tcy0, tcx1, tcy1; - opj_pi_comp_t *comp = &pi[pino].comps[compno]; - tccp = &tcp->tccps[compno]; - comp->dx = image->comps[compno].dx; - comp->dy = image->comps[compno].dy; - comp->numresolutions = tccp->numresolutions; - - comp->resolutions = (opj_pi_resolution_t*) opj_malloc(comp->numresolutions * sizeof(opj_pi_resolution_t)); - if(!comp->resolutions) { - pi_destroy(pi, cp, tileno); - return NULL; - } - - tcx0 = int_ceildiv(pi[pino].tx0, comp->dx); - tcy0 = int_ceildiv(pi[pino].ty0, comp->dy); - tcx1 = int_ceildiv(pi[pino].tx1, comp->dx); - tcy1 = int_ceildiv(pi[pino].ty1, comp->dy); - if (comp->numresolutions > maxres) { - maxres = comp->numresolutions; - } - - for (resno = 0; resno < comp->numresolutions; resno++) { - int levelno; - int rx0, ry0, rx1, ry1; - int px0, py0, px1, py1; - opj_pi_resolution_t *res = &comp->resolutions[resno]; - if (tccp->csty & J2K_CCP_CSTY_PRT) { - res->pdx = tccp->prcw[resno]; - res->pdy = tccp->prch[resno]; - } else { - res->pdx = 15; - res->pdy = 15; - } - levelno = comp->numresolutions - 1 - resno; - rx0 = int_ceildivpow2(tcx0, levelno); - ry0 = int_ceildivpow2(tcy0, levelno); - rx1 = int_ceildivpow2(tcx1, levelno); - ry1 = int_ceildivpow2(tcy1, levelno); - px0 = int_floordivpow2(rx0, res->pdx) << res->pdx; - py0 = int_floordivpow2(ry0, res->pdy) << res->pdy; - px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx; - py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy; - res->pw = (rx0==rx1)?0:((px1 - px0) >> res->pdx); - res->ph = (ry0==ry1)?0:((py1 - py0) >> res->pdy); - - if (res->pw*res->ph > maxprec) { - maxprec = res->pw * res->ph; - } - } - } - - tccp = &tcp->tccps[0]; - pi[pino].step_p = 1; - pi[pino].step_c = maxprec * pi[pino].step_p; - pi[pino].step_r = image->numcomps * pi[pino].step_c; - pi[pino].step_l = maxres * pi[pino].step_r; - - for (compno = 0; compno < pi->numcomps; compno++) { - opj_pi_comp_t *comp = &pi->comps[compno]; - for (resno = 0; resno < comp->numresolutions; resno++) { - int dx, dy; - opj_pi_resolution_t *res = &comp->resolutions[resno]; - dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno)); - dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno)); - pi[pino].dx = !pi->dx ? dx : int_min(pi->dx, dx); - pi[pino].dy = !pi->dy ? dy : int_min(pi->dy, dy); - } - } - - if (pino == 0) { - pi[pino].include = (short int*) opj_calloc(tcp->numlayers * pi[pino].step_l, sizeof(short int)); - if(!pi[pino].include) { - pi_destroy(pi, cp, tileno); - return NULL; - } - } - else { - pi[pino].include = pi[pino - 1].include; - } - - /* Generation of boundaries for each prog flag*/ - if(tcp->POC && ( cp->cinema || ((!cp->cinema) && (t2_mode == FINAL_PASS)))){ - tcp->pocs[pino].compS= tcp->pocs[pino].compno0; - tcp->pocs[pino].compE= tcp->pocs[pino].compno1; - tcp->pocs[pino].resS = tcp->pocs[pino].resno0; - tcp->pocs[pino].resE = tcp->pocs[pino].resno1; - tcp->pocs[pino].layE = tcp->pocs[pino].layno1; - tcp->pocs[pino].prg = tcp->pocs[pino].prg1; - if (pino > 0) - tcp->pocs[pino].layS = (tcp->pocs[pino].layE > tcp->pocs[pino - 1].layE) ? tcp->pocs[pino - 1].layE : 0; - }else { - tcp->pocs[pino].compS= 0; - tcp->pocs[pino].compE= image->numcomps; - tcp->pocs[pino].resS = 0; - tcp->pocs[pino].resE = maxres; - tcp->pocs[pino].layS = 0; - tcp->pocs[pino].layE = tcp->numlayers; - tcp->pocs[pino].prg = tcp->prg; - } - tcp->pocs[pino].prcS = 0; - tcp->pocs[pino].prcE = maxprec;; - tcp->pocs[pino].txS = pi[pino].tx0; - tcp->pocs[pino].txE = pi[pino].tx1; - tcp->pocs[pino].tyS = pi[pino].ty0; - tcp->pocs[pino].tyE = pi[pino].ty1; - tcp->pocs[pino].dx = pi[pino].dx; - tcp->pocs[pino].dy = pi[pino].dy; - } - return pi; - } - - - -void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno) { - int compno, pino; - opj_tcp_t *tcp = &cp->tcps[tileno]; - if(pi) { - for (pino = 0; pino < tcp->numpocs + 1; pino++) { - if(pi[pino].comps) { - for (compno = 0; compno < pi->numcomps; compno++) { - opj_pi_comp_t *comp = &pi[pino].comps[compno]; - if(comp->resolutions) { - opj_free(comp->resolutions); - } - } - opj_free(pi[pino].comps); - } - } - if(pi->include) { - opj_free(pi->include); - } - opj_free(pi); - } -} - -opj_bool pi_next(opj_pi_iterator_t * pi) { - switch (pi->poc.prg) { - case LRCP: - return pi_next_lrcp(pi); - case RLCP: - return pi_next_rlcp(pi); - case RPCL: - return pi_next_rpcl(pi); - case PCRL: - return pi_next_pcrl(pi); - case CPRL: - return pi_next_cprl(pi); - case PROG_UNKNOWN: - return OPJ_FALSE; - } - - return OPJ_FALSE; -} - -opj_bool pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos, J2K_T2_MODE t2_mode,int cur_totnum_tp){ - char prog[4]; - int i; - int incr_top=1,resetX=0; - opj_tcp_t *tcps =&cp->tcps[tileno]; - opj_poc_t *tcp= &tcps->pocs[pino]; - - pi[pino].first = 1; - pi[pino].poc.prg = tcp->prg; - - switch(tcp->prg){ - case CPRL: strncpy(prog, "CPRL",4); - break; - case LRCP: strncpy(prog, "LRCP",4); - break; - case PCRL: strncpy(prog, "PCRL",4); - break; - case RLCP: strncpy(prog, "RLCP",4); - break; - case RPCL: strncpy(prog, "RPCL",4); - break; - case PROG_UNKNOWN: - return OPJ_TRUE; - } - - if(!(cp->tp_on && ((!cp->cinema && (t2_mode == FINAL_PASS)) || cp->cinema))){ - pi[pino].poc.resno0 = tcp->resS; - pi[pino].poc.resno1 = tcp->resE; - pi[pino].poc.compno0 = tcp->compS; - pi[pino].poc.compno1 = tcp->compE; - pi[pino].poc.layno0 = tcp->layS; - pi[pino].poc.layno1 = tcp->layE; - pi[pino].poc.precno0 = tcp->prcS; - pi[pino].poc.precno1 = tcp->prcE; - pi[pino].poc.tx0 = tcp->txS; - pi[pino].poc.ty0 = tcp->tyS; - pi[pino].poc.tx1 = tcp->txE; - pi[pino].poc.ty1 = tcp->tyE; - }else { - if( tpnum < cur_totnum_tp){ - for(i=3;i>=0;i--){ - switch(prog[i]){ - case 'C': - if (i > tppos){ - pi[pino].poc.compno0 = tcp->compS; - pi[pino].poc.compno1 = tcp->compE; - }else{ - if (tpnum == 0){ - tcp->comp_t = tcp->compS; - pi[pino].poc.compno0 = tcp->comp_t; - pi[pino].poc.compno1 = tcp->comp_t+1; - tcp->comp_t+=1; - }else{ - if (incr_top == 1){ - if(tcp->comp_t ==tcp->compE){ - tcp->comp_t = tcp->compS; - pi[pino].poc.compno0 = tcp->comp_t; - pi[pino].poc.compno1 = tcp->comp_t+1; - tcp->comp_t+=1; - incr_top=1; - }else{ - pi[pino].poc.compno0 = tcp->comp_t; - pi[pino].poc.compno1 = tcp->comp_t+1; - tcp->comp_t+=1; - incr_top=0; - } - }else{ - pi[pino].poc.compno0 = tcp->comp_t-1; - pi[pino].poc.compno1 = tcp->comp_t; - } - } - } - break; - - case 'R': - if (i > tppos){ - pi[pino].poc.resno0 = tcp->resS; - pi[pino].poc.resno1 = tcp->resE; - }else{ - if (tpnum == 0){ - tcp->res_t = tcp->resS; - pi[pino].poc.resno0 = tcp->res_t; - pi[pino].poc.resno1 = tcp->res_t+1; - tcp->res_t+=1; - }else{ - if (incr_top == 1){ - if(tcp->res_t==tcp->resE){ - tcp->res_t = tcp->resS; - pi[pino].poc.resno0 = tcp->res_t; - pi[pino].poc.resno1 = tcp->res_t+1; - tcp->res_t+=1; - incr_top=1; - }else{ - pi[pino].poc.resno0 = tcp->res_t; - pi[pino].poc.resno1 = tcp->res_t+1; - tcp->res_t+=1; - incr_top=0; - } - }else{ - pi[pino].poc.resno0 = tcp->res_t - 1; - pi[pino].poc.resno1 = tcp->res_t; - } - } - } - break; - - case 'L': - if (i > tppos){ - pi[pino].poc.layno0 = tcp->layS; - pi[pino].poc.layno1 = tcp->layE; - }else{ - if (tpnum == 0){ - tcp->lay_t = tcp->layS; - pi[pino].poc.layno0 = tcp->lay_t; - pi[pino].poc.layno1 = tcp->lay_t+1; - tcp->lay_t+=1; - }else{ - if (incr_top == 1){ - if(tcp->lay_t == tcp->layE){ - tcp->lay_t = tcp->layS; - pi[pino].poc.layno0 = tcp->lay_t; - pi[pino].poc.layno1 = tcp->lay_t+1; - tcp->lay_t+=1; - incr_top=1; - }else{ - pi[pino].poc.layno0 = tcp->lay_t; - pi[pino].poc.layno1 = tcp->lay_t+1; - tcp->lay_t+=1; - incr_top=0; - } - }else{ - pi[pino].poc.layno0 = tcp->lay_t - 1; - pi[pino].poc.layno1 = tcp->lay_t; - } - } - } - break; - - case 'P': - switch(tcp->prg){ - case LRCP: - case RLCP: - if (i > tppos){ - pi[pino].poc.precno0 = tcp->prcS; - pi[pino].poc.precno1 = tcp->prcE; - }else{ - if (tpnum == 0){ - tcp->prc_t = tcp->prcS; - pi[pino].poc.precno0 = tcp->prc_t; - pi[pino].poc.precno1 = tcp->prc_t+1; - tcp->prc_t+=1; - }else{ - if (incr_top == 1){ - if(tcp->prc_t == tcp->prcE){ - tcp->prc_t = tcp->prcS; - pi[pino].poc.precno0 = tcp->prc_t; - pi[pino].poc.precno1 = tcp->prc_t+1; - tcp->prc_t+=1; - incr_top=1; - }else{ - pi[pino].poc.precno0 = tcp->prc_t; - pi[pino].poc.precno1 = tcp->prc_t+1; - tcp->prc_t+=1; - incr_top=0; - } - }else{ - pi[pino].poc.precno0 = tcp->prc_t - 1; - pi[pino].poc.precno1 = tcp->prc_t; - } - } - } - break; - default: - if (i > tppos){ - pi[pino].poc.tx0 = tcp->txS; - pi[pino].poc.ty0 = tcp->tyS; - pi[pino].poc.tx1 = tcp->txE; - pi[pino].poc.ty1 = tcp->tyE; - }else{ - if (tpnum == 0){ - tcp->tx0_t = tcp->txS; - tcp->ty0_t = tcp->tyS; - pi[pino].poc.tx0 = tcp->tx0_t; - pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx); - pi[pino].poc.ty0 = tcp->ty0_t; - pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); - tcp->tx0_t = pi[pino].poc.tx1; - tcp->ty0_t = pi[pino].poc.ty1; - }else{ - if (incr_top == 1){ - if(tcp->tx0_t >= tcp->txE){ - if(tcp->ty0_t >= tcp->tyE){ - tcp->ty0_t = tcp->tyS; - pi[pino].poc.ty0 = tcp->ty0_t; - pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); - tcp->ty0_t = pi[pino].poc.ty1; - incr_top=1;resetX=1; - }else{ - pi[pino].poc.ty0 = tcp->ty0_t; - pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); - tcp->ty0_t = pi[pino].poc.ty1; - incr_top=0;resetX=1; - } - if(resetX==1){ - tcp->tx0_t = tcp->txS; - pi[pino].poc.tx0 = tcp->tx0_t; - pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx); - tcp->tx0_t = pi[pino].poc.tx1; - } - }else{ - pi[pino].poc.tx0 = tcp->tx0_t; - pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx); - tcp->tx0_t = pi[pino].poc.tx1; - pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy); - pi[pino].poc.ty1 = tcp->ty0_t ; - incr_top=0; - } - }else{ - pi[pino].poc.tx0 = tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx); - pi[pino].poc.tx1 = tcp->tx0_t ; - pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy); - pi[pino].poc.ty1 = tcp->ty0_t ; - } - } - } - break; - } - break; - } - } - } - } - return OPJ_FALSE; -} - +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2006-2007, Parvatha Elangovan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/** @defgroup PI PI - Implementation of a packet iterator */ +/*@{*/ + +/** @name Local static functions */ +/*@{*/ + +/** +Get next packet in layer-resolution-component-precinct order. +@param pi packet iterator to modify +@return returns false if pi pointed to the last packet or else returns true +*/ +static opj_bool pi_next_lrcp(opj_pi_iterator_t * pi); +/** +Get next packet in resolution-layer-component-precinct order. +@param pi packet iterator to modify +@return returns false if pi pointed to the last packet or else returns true +*/ +static opj_bool pi_next_rlcp(opj_pi_iterator_t * pi); +/** +Get next packet in resolution-precinct-component-layer order. +@param pi packet iterator to modify +@return returns false if pi pointed to the last packet or else returns true +*/ +static opj_bool pi_next_rpcl(opj_pi_iterator_t * pi); +/** +Get next packet in precinct-component-resolution-layer order. +@param pi packet iterator to modify +@return returns false if pi pointed to the last packet or else returns true +*/ +static opj_bool pi_next_pcrl(opj_pi_iterator_t * pi); +/** +Get next packet in component-precinct-resolution-layer order. +@param pi packet iterator to modify +@return returns false if pi pointed to the last packet or else returns true +*/ +static opj_bool pi_next_cprl(opj_pi_iterator_t * pi); + +/*@}*/ + +/*@}*/ + +/* +========================================================== + local functions +========================================================== +*/ + +static opj_bool pi_next_lrcp(opj_pi_iterator_t * pi) { + opj_pi_comp_t *comp = NULL; + opj_pi_resolution_t *res = NULL; + long index = 0; + + if (!pi->first) { + comp = &pi->comps[pi->compno]; + res = &comp->resolutions[pi->resno]; + goto LABEL_SKIP; + } else { + pi->first = 0; + } + + for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { + for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; + pi->resno++) { + for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { + comp = &pi->comps[pi->compno]; + if (pi->resno >= comp->numresolutions) { + continue; + } + res = &comp->resolutions[pi->resno]; + if (!pi->tp_on){ + pi->poc.precno1 = res->pw * res->ph; + } + for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) { + index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; + if (!pi->include[index]) { + pi->include[index] = 1; + return OPJ_TRUE; + } +LABEL_SKIP:; + } + } + } + } + + return OPJ_FALSE; +} + +static opj_bool pi_next_rlcp(opj_pi_iterator_t * pi) { + opj_pi_comp_t *comp = NULL; + opj_pi_resolution_t *res = NULL; + long index = 0; + + if (!pi->first) { + comp = &pi->comps[pi->compno]; + res = &comp->resolutions[pi->resno]; + goto LABEL_SKIP; + } else { + pi->first = 0; + } + + for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { + for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { + for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { + comp = &pi->comps[pi->compno]; + if (pi->resno >= comp->numresolutions) { + continue; + } + res = &comp->resolutions[pi->resno]; + if(!pi->tp_on){ + pi->poc.precno1 = res->pw * res->ph; + } + for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) { + index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; + if (!pi->include[index]) { + pi->include[index] = 1; + return OPJ_TRUE; + } +LABEL_SKIP:; + } + } + } + } + + return OPJ_FALSE; +} + +static opj_bool pi_next_rpcl(opj_pi_iterator_t * pi) { + opj_pi_comp_t *comp = NULL; + opj_pi_resolution_t *res = NULL; + long index = 0; + + if (!pi->first) { + goto LABEL_SKIP; + } else { + int compno, resno; + pi->first = 0; + pi->dx = 0; + pi->dy = 0; + for (compno = 0; compno < pi->numcomps; compno++) { + comp = &pi->comps[compno]; + for (resno = 0; resno < comp->numresolutions; resno++) { + int dx, dy; + res = &comp->resolutions[resno]; + dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno)); + dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno)); + pi->dx = !pi->dx ? dx : int_min(pi->dx, dx); + pi->dy = !pi->dy ? dy : int_min(pi->dy, dy); + } + } + } +if (!pi->tp_on){ + pi->poc.ty0 = pi->ty0; + pi->poc.tx0 = pi->tx0; + pi->poc.ty1 = pi->ty1; + pi->poc.tx1 = pi->tx1; + } + for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { + for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) { + for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) { + for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { + int levelno; + int trx0, try0; + int trx1, try1; + int rpx, rpy; + int prci, prcj; + comp = &pi->comps[pi->compno]; + if (pi->resno >= comp->numresolutions) { + continue; + } + res = &comp->resolutions[pi->resno]; + levelno = comp->numresolutions - 1 - pi->resno; + trx0 = int_ceildiv(pi->tx0, comp->dx << levelno); + try0 = int_ceildiv(pi->ty0, comp->dy << levelno); + trx1 = int_ceildiv(pi->tx1, comp->dx << levelno); + try1 = int_ceildiv(pi->ty1, comp->dy << levelno); + rpx = res->pdx + levelno; + rpy = res->pdy + levelno; + if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ + continue; + } + if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ + continue; + } + + if ((res->pw==0)||(res->ph==0)) continue; + + if ((trx0==trx1)||(try0==try1)) continue; + + prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx) + - int_floordivpow2(trx0, res->pdx); + prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy) + - int_floordivpow2(try0, res->pdy); + pi->precno = prci + prcj * res->pw; + for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { + index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; + if (!pi->include[index]) { + pi->include[index] = 1; + return OPJ_TRUE; + } +LABEL_SKIP:; + } + } + } + } + } + + return OPJ_FALSE; +} + +static opj_bool pi_next_pcrl(opj_pi_iterator_t * pi) { + opj_pi_comp_t *comp = NULL; + opj_pi_resolution_t *res = NULL; + long index = 0; + + if (!pi->first) { + comp = &pi->comps[pi->compno]; + goto LABEL_SKIP; + } else { + int compno, resno; + pi->first = 0; + pi->dx = 0; + pi->dy = 0; + for (compno = 0; compno < pi->numcomps; compno++) { + comp = &pi->comps[compno]; + for (resno = 0; resno < comp->numresolutions; resno++) { + int dx, dy; + res = &comp->resolutions[resno]; + dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno)); + dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno)); + pi->dx = !pi->dx ? dx : int_min(pi->dx, dx); + pi->dy = !pi->dy ? dy : int_min(pi->dy, dy); + } + } + } + if (!pi->tp_on){ + pi->poc.ty0 = pi->ty0; + pi->poc.tx0 = pi->tx0; + pi->poc.ty1 = pi->ty1; + pi->poc.tx1 = pi->tx1; + } + for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) { + for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) { + for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { + comp = &pi->comps[pi->compno]; + for (pi->resno = pi->poc.resno0; pi->resno < int_min(pi->poc.resno1, comp->numresolutions); pi->resno++) { + int levelno; + int trx0, try0; + int trx1, try1; + int rpx, rpy; + int prci, prcj; + res = &comp->resolutions[pi->resno]; + levelno = comp->numresolutions - 1 - pi->resno; + trx0 = int_ceildiv(pi->tx0, comp->dx << levelno); + try0 = int_ceildiv(pi->ty0, comp->dy << levelno); + trx1 = int_ceildiv(pi->tx1, comp->dx << levelno); + try1 = int_ceildiv(pi->ty1, comp->dy << levelno); + rpx = res->pdx + levelno; + rpy = res->pdy + levelno; + if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ + continue; + } + if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ + continue; + } + + if ((res->pw==0)||(res->ph==0)) continue; + + if ((trx0==trx1)||(try0==try1)) continue; + + prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx) + - int_floordivpow2(trx0, res->pdx); + prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy) + - int_floordivpow2(try0, res->pdy); + pi->precno = prci + prcj * res->pw; + for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { + index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; + if (!pi->include[index]) { + pi->include[index] = 1; + return OPJ_TRUE; + } +LABEL_SKIP:; + } + } + } + } + } + + return OPJ_FALSE; +} + +static opj_bool pi_next_cprl(opj_pi_iterator_t * pi) { + opj_pi_comp_t *comp = NULL; + opj_pi_resolution_t *res = NULL; + long index = 0; + + if (!pi->first) { + comp = &pi->comps[pi->compno]; + goto LABEL_SKIP; + } else { + pi->first = 0; + } + + for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { + int resno; + comp = &pi->comps[pi->compno]; + pi->dx = 0; + pi->dy = 0; + for (resno = 0; resno < comp->numresolutions; resno++) { + int dx, dy; + res = &comp->resolutions[resno]; + dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno)); + dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno)); + pi->dx = !pi->dx ? dx : int_min(pi->dx, dx); + pi->dy = !pi->dy ? dy : int_min(pi->dy, dy); + } + if (!pi->tp_on){ + pi->poc.ty0 = pi->ty0; + pi->poc.tx0 = pi->tx0; + pi->poc.ty1 = pi->ty1; + pi->poc.tx1 = pi->tx1; + } + for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) { + for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) { + for (pi->resno = pi->poc.resno0; pi->resno < int_min(pi->poc.resno1, comp->numresolutions); pi->resno++) { + int levelno; + int trx0, try0; + int trx1, try1; + int rpx, rpy; + int prci, prcj; + res = &comp->resolutions[pi->resno]; + levelno = comp->numresolutions - 1 - pi->resno; + trx0 = int_ceildiv(pi->tx0, comp->dx << levelno); + try0 = int_ceildiv(pi->ty0, comp->dy << levelno); + trx1 = int_ceildiv(pi->tx1, comp->dx << levelno); + try1 = int_ceildiv(pi->ty1, comp->dy << levelno); + rpx = res->pdx + levelno; + rpy = res->pdy + levelno; + if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ + continue; + } + if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ + continue; + } + + if ((res->pw==0)||(res->ph==0)) continue; + + if ((trx0==trx1)||(try0==try1)) continue; + + prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno), res->pdx) + - int_floordivpow2(trx0, res->pdx); + prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy) + - int_floordivpow2(try0, res->pdy); + pi->precno = prci + prcj * res->pw; + for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { + index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; + if (!pi->include[index]) { + pi->include[index] = 1; + return OPJ_TRUE; + } +LABEL_SKIP:; + } + } + } + } + } + + return OPJ_FALSE; +} + +/* +========================================================== + Packet iterator interface +========================================================== +*/ + +opj_pi_iterator_t *pi_create_decode(opj_image_t *image, opj_cp_t *cp, int tileno) { + int p, q; + int compno, resno, pino; + opj_pi_iterator_t *pi = NULL; + opj_tcp_t *tcp = NULL; + opj_tccp_t *tccp = NULL; + + tcp = &cp->tcps[tileno]; + + pi = (opj_pi_iterator_t*) opj_calloc((tcp->numpocs + 1), sizeof(opj_pi_iterator_t)); + if(!pi) { + /* TODO: throw an error */ + return NULL; + } + + for (pino = 0; pino < tcp->numpocs + 1; pino++) { /* change */ + int maxres = 0; + int maxprec = 0; + p = tileno % cp->tw; + q = tileno / cp->tw; + + pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, image->x0); + pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, image->y0); + pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1); + pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1); + pi[pino].numcomps = image->numcomps; + + pi[pino].comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t)); + if(!pi[pino].comps) { + /* TODO: throw an error */ + pi_destroy(pi, cp, tileno); + return NULL; + } + + for (compno = 0; compno < pi->numcomps; compno++) { + int tcx0, tcy0, tcx1, tcy1; + opj_pi_comp_t *comp = &pi[pino].comps[compno]; + tccp = &tcp->tccps[compno]; + comp->dx = image->comps[compno].dx; + comp->dy = image->comps[compno].dy; + comp->numresolutions = tccp->numresolutions; + + comp->resolutions = (opj_pi_resolution_t*) opj_calloc(comp->numresolutions, sizeof(opj_pi_resolution_t)); + if(!comp->resolutions) { + /* TODO: throw an error */ + pi_destroy(pi, cp, tileno); + return NULL; + } + + tcx0 = int_ceildiv(pi->tx0, comp->dx); + tcy0 = int_ceildiv(pi->ty0, comp->dy); + tcx1 = int_ceildiv(pi->tx1, comp->dx); + tcy1 = int_ceildiv(pi->ty1, comp->dy); + if (comp->numresolutions > maxres) { + maxres = comp->numresolutions; + } + + for (resno = 0; resno < comp->numresolutions; resno++) { + int levelno; + int rx0, ry0, rx1, ry1; + int px0, py0, px1, py1; + opj_pi_resolution_t *res = &comp->resolutions[resno]; + if (tccp->csty & J2K_CCP_CSTY_PRT) { + res->pdx = tccp->prcw[resno]; + res->pdy = tccp->prch[resno]; + } else { + res->pdx = 15; + res->pdy = 15; + } + levelno = comp->numresolutions - 1 - resno; + rx0 = int_ceildivpow2(tcx0, levelno); + ry0 = int_ceildivpow2(tcy0, levelno); + rx1 = int_ceildivpow2(tcx1, levelno); + ry1 = int_ceildivpow2(tcy1, levelno); + px0 = int_floordivpow2(rx0, res->pdx) << res->pdx; + py0 = int_floordivpow2(ry0, res->pdy) << res->pdy; + px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx; + py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy; + res->pw = (rx0==rx1)?0:((px1 - px0) >> res->pdx); + res->ph = (ry0==ry1)?0:((py1 - py0) >> res->pdy); + + if (res->pw*res->ph > maxprec) { + maxprec = res->pw*res->ph; + } + + } + } + + tccp = &tcp->tccps[0]; + pi[pino].step_p = 1; + pi[pino].step_c = maxprec * pi[pino].step_p; + pi[pino].step_r = image->numcomps * pi[pino].step_c; + pi[pino].step_l = maxres * pi[pino].step_r; + + if (pino == 0) { + pi[pino].include = (short int*) opj_calloc(image->numcomps * maxres * tcp->numlayers * maxprec, sizeof(short int)); + if(!pi[pino].include) { + /* TODO: throw an error */ + pi_destroy(pi, cp, tileno); + return NULL; + } + } + else { + pi[pino].include = pi[pino - 1].include; + } + + if (tcp->POC == 0) { + pi[pino].first = 1; + pi[pino].poc.resno0 = 0; + pi[pino].poc.compno0 = 0; + pi[pino].poc.layno1 = tcp->numlayers; + pi[pino].poc.resno1 = maxres; + pi[pino].poc.compno1 = image->numcomps; + pi[pino].poc.prg = tcp->prg; + } else { + pi[pino].first = 1; + pi[pino].poc.resno0 = tcp->pocs[pino].resno0; + pi[pino].poc.compno0 = tcp->pocs[pino].compno0; + pi[pino].poc.layno1 = tcp->pocs[pino].layno1; + pi[pino].poc.resno1 = tcp->pocs[pino].resno1; + pi[pino].poc.compno1 = tcp->pocs[pino].compno1; + pi[pino].poc.prg = tcp->pocs[pino].prg; + } + pi[pino].poc.layno0 = 0; + pi[pino].poc.precno0 = 0; + pi[pino].poc.precno1 = maxprec; + + } + + return pi; +} + + +opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int tileno, J2K_T2_MODE t2_mode){ + int p, q, pino; + int compno, resno; + int maxres = 0; + int maxprec = 0; + opj_pi_iterator_t *pi = NULL; + opj_tcp_t *tcp = NULL; + opj_tccp_t *tccp = NULL; + + tcp = &cp->tcps[tileno]; + + pi = (opj_pi_iterator_t*) opj_calloc((tcp->numpocs + 1), sizeof(opj_pi_iterator_t)); + if(!pi) { return NULL;} + pi->tp_on = cp->tp_on; + + for(pino = 0;pino < tcp->numpocs+1 ; pino ++){ + p = tileno % cp->tw; + q = tileno / cp->tw; + + pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, image->x0); + pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, image->y0); + pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1); + pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1); + pi[pino].numcomps = image->numcomps; + + pi[pino].comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t)); + if(!pi[pino].comps) { + pi_destroy(pi, cp, tileno); + return NULL; + } + + for (compno = 0; compno < pi[pino].numcomps; compno++) { + int tcx0, tcy0, tcx1, tcy1; + opj_pi_comp_t *comp = &pi[pino].comps[compno]; + tccp = &tcp->tccps[compno]; + comp->dx = image->comps[compno].dx; + comp->dy = image->comps[compno].dy; + comp->numresolutions = tccp->numresolutions; + + comp->resolutions = (opj_pi_resolution_t*) opj_malloc(comp->numresolutions * sizeof(opj_pi_resolution_t)); + if(!comp->resolutions) { + pi_destroy(pi, cp, tileno); + return NULL; + } + + tcx0 = int_ceildiv(pi[pino].tx0, comp->dx); + tcy0 = int_ceildiv(pi[pino].ty0, comp->dy); + tcx1 = int_ceildiv(pi[pino].tx1, comp->dx); + tcy1 = int_ceildiv(pi[pino].ty1, comp->dy); + if (comp->numresolutions > maxres) { + maxres = comp->numresolutions; + } + + for (resno = 0; resno < comp->numresolutions; resno++) { + int levelno; + int rx0, ry0, rx1, ry1; + int px0, py0, px1, py1; + opj_pi_resolution_t *res = &comp->resolutions[resno]; + if (tccp->csty & J2K_CCP_CSTY_PRT) { + res->pdx = tccp->prcw[resno]; + res->pdy = tccp->prch[resno]; + } else { + res->pdx = 15; + res->pdy = 15; + } + levelno = comp->numresolutions - 1 - resno; + rx0 = int_ceildivpow2(tcx0, levelno); + ry0 = int_ceildivpow2(tcy0, levelno); + rx1 = int_ceildivpow2(tcx1, levelno); + ry1 = int_ceildivpow2(tcy1, levelno); + px0 = int_floordivpow2(rx0, res->pdx) << res->pdx; + py0 = int_floordivpow2(ry0, res->pdy) << res->pdy; + px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx; + py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy; + res->pw = (rx0==rx1)?0:((px1 - px0) >> res->pdx); + res->ph = (ry0==ry1)?0:((py1 - py0) >> res->pdy); + + if (res->pw*res->ph > maxprec) { + maxprec = res->pw * res->ph; + } + } + } + + tccp = &tcp->tccps[0]; + pi[pino].step_p = 1; + pi[pino].step_c = maxprec * pi[pino].step_p; + pi[pino].step_r = image->numcomps * pi[pino].step_c; + pi[pino].step_l = maxres * pi[pino].step_r; + + for (compno = 0; compno < pi->numcomps; compno++) { + opj_pi_comp_t *comp = &pi->comps[compno]; + for (resno = 0; resno < comp->numresolutions; resno++) { + int dx, dy; + opj_pi_resolution_t *res = &comp->resolutions[resno]; + dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno)); + dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno)); + pi[pino].dx = !pi->dx ? dx : int_min(pi->dx, dx); + pi[pino].dy = !pi->dy ? dy : int_min(pi->dy, dy); + } + } + + if (pino == 0) { + pi[pino].include = (short int*) opj_calloc(tcp->numlayers * pi[pino].step_l, sizeof(short int)); + if(!pi[pino].include) { + pi_destroy(pi, cp, tileno); + return NULL; + } + } + else { + pi[pino].include = pi[pino - 1].include; + } + + /* Generation of boundaries for each prog flag*/ + if(tcp->POC && ( cp->cinema || ((!cp->cinema) && (t2_mode == FINAL_PASS)))){ + tcp->pocs[pino].compS= tcp->pocs[pino].compno0; + tcp->pocs[pino].compE= tcp->pocs[pino].compno1; + tcp->pocs[pino].resS = tcp->pocs[pino].resno0; + tcp->pocs[pino].resE = tcp->pocs[pino].resno1; + tcp->pocs[pino].layE = tcp->pocs[pino].layno1; + tcp->pocs[pino].prg = tcp->pocs[pino].prg1; + if (pino > 0) + tcp->pocs[pino].layS = (tcp->pocs[pino].layE > tcp->pocs[pino - 1].layE) ? tcp->pocs[pino - 1].layE : 0; + }else { + tcp->pocs[pino].compS= 0; + tcp->pocs[pino].compE= image->numcomps; + tcp->pocs[pino].resS = 0; + tcp->pocs[pino].resE = maxres; + tcp->pocs[pino].layS = 0; + tcp->pocs[pino].layE = tcp->numlayers; + tcp->pocs[pino].prg = tcp->prg; + } + tcp->pocs[pino].prcS = 0; + tcp->pocs[pino].prcE = maxprec;; + tcp->pocs[pino].txS = pi[pino].tx0; + tcp->pocs[pino].txE = pi[pino].tx1; + tcp->pocs[pino].tyS = pi[pino].ty0; + tcp->pocs[pino].tyE = pi[pino].ty1; + tcp->pocs[pino].dx = pi[pino].dx; + tcp->pocs[pino].dy = pi[pino].dy; + } + return pi; + } + + + +void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno) { + int compno, pino; + opj_tcp_t *tcp = &cp->tcps[tileno]; + if(pi) { + for (pino = 0; pino < tcp->numpocs + 1; pino++) { + if(pi[pino].comps) { + for (compno = 0; compno < pi->numcomps; compno++) { + opj_pi_comp_t *comp = &pi[pino].comps[compno]; + if(comp->resolutions) { + opj_free(comp->resolutions); + } + } + opj_free(pi[pino].comps); + } + } + if(pi->include) { + opj_free(pi->include); + } + opj_free(pi); + } +} + +opj_bool pi_next(opj_pi_iterator_t * pi) { + switch (pi->poc.prg) { + case LRCP: + return pi_next_lrcp(pi); + case RLCP: + return pi_next_rlcp(pi); + case RPCL: + return pi_next_rpcl(pi); + case PCRL: + return pi_next_pcrl(pi); + case CPRL: + return pi_next_cprl(pi); + case PROG_UNKNOWN: + return OPJ_FALSE; + } + + return OPJ_FALSE; +} + +opj_bool pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos, J2K_T2_MODE t2_mode,int cur_totnum_tp){ + char prog[4]; + int i; + int incr_top=1,resetX=0; + opj_tcp_t *tcps =&cp->tcps[tileno]; + opj_poc_t *tcp= &tcps->pocs[pino]; + + pi[pino].first = 1; + pi[pino].poc.prg = tcp->prg; + + switch(tcp->prg){ + case CPRL: strncpy(prog, "CPRL",4); + break; + case LRCP: strncpy(prog, "LRCP",4); + break; + case PCRL: strncpy(prog, "PCRL",4); + break; + case RLCP: strncpy(prog, "RLCP",4); + break; + case RPCL: strncpy(prog, "RPCL",4); + break; + case PROG_UNKNOWN: + return OPJ_TRUE; + } + + if(!(cp->tp_on && ((!cp->cinema && (t2_mode == FINAL_PASS)) || cp->cinema))){ + pi[pino].poc.resno0 = tcp->resS; + pi[pino].poc.resno1 = tcp->resE; + pi[pino].poc.compno0 = tcp->compS; + pi[pino].poc.compno1 = tcp->compE; + pi[pino].poc.layno0 = tcp->layS; + pi[pino].poc.layno1 = tcp->layE; + pi[pino].poc.precno0 = tcp->prcS; + pi[pino].poc.precno1 = tcp->prcE; + pi[pino].poc.tx0 = tcp->txS; + pi[pino].poc.ty0 = tcp->tyS; + pi[pino].poc.tx1 = tcp->txE; + pi[pino].poc.ty1 = tcp->tyE; + }else { + if( tpnum < cur_totnum_tp){ + for(i=3;i>=0;i--){ + switch(prog[i]){ + case 'C': + if (i > tppos){ + pi[pino].poc.compno0 = tcp->compS; + pi[pino].poc.compno1 = tcp->compE; + }else{ + if (tpnum == 0){ + tcp->comp_t = tcp->compS; + pi[pino].poc.compno0 = tcp->comp_t; + pi[pino].poc.compno1 = tcp->comp_t+1; + tcp->comp_t+=1; + }else{ + if (incr_top == 1){ + if(tcp->comp_t ==tcp->compE){ + tcp->comp_t = tcp->compS; + pi[pino].poc.compno0 = tcp->comp_t; + pi[pino].poc.compno1 = tcp->comp_t+1; + tcp->comp_t+=1; + incr_top=1; + }else{ + pi[pino].poc.compno0 = tcp->comp_t; + pi[pino].poc.compno1 = tcp->comp_t+1; + tcp->comp_t+=1; + incr_top=0; + } + }else{ + pi[pino].poc.compno0 = tcp->comp_t-1; + pi[pino].poc.compno1 = tcp->comp_t; + } + } + } + break; + + case 'R': + if (i > tppos){ + pi[pino].poc.resno0 = tcp->resS; + pi[pino].poc.resno1 = tcp->resE; + }else{ + if (tpnum == 0){ + tcp->res_t = tcp->resS; + pi[pino].poc.resno0 = tcp->res_t; + pi[pino].poc.resno1 = tcp->res_t+1; + tcp->res_t+=1; + }else{ + if (incr_top == 1){ + if(tcp->res_t==tcp->resE){ + tcp->res_t = tcp->resS; + pi[pino].poc.resno0 = tcp->res_t; + pi[pino].poc.resno1 = tcp->res_t+1; + tcp->res_t+=1; + incr_top=1; + }else{ + pi[pino].poc.resno0 = tcp->res_t; + pi[pino].poc.resno1 = tcp->res_t+1; + tcp->res_t+=1; + incr_top=0; + } + }else{ + pi[pino].poc.resno0 = tcp->res_t - 1; + pi[pino].poc.resno1 = tcp->res_t; + } + } + } + break; + + case 'L': + if (i > tppos){ + pi[pino].poc.layno0 = tcp->layS; + pi[pino].poc.layno1 = tcp->layE; + }else{ + if (tpnum == 0){ + tcp->lay_t = tcp->layS; + pi[pino].poc.layno0 = tcp->lay_t; + pi[pino].poc.layno1 = tcp->lay_t+1; + tcp->lay_t+=1; + }else{ + if (incr_top == 1){ + if(tcp->lay_t == tcp->layE){ + tcp->lay_t = tcp->layS; + pi[pino].poc.layno0 = tcp->lay_t; + pi[pino].poc.layno1 = tcp->lay_t+1; + tcp->lay_t+=1; + incr_top=1; + }else{ + pi[pino].poc.layno0 = tcp->lay_t; + pi[pino].poc.layno1 = tcp->lay_t+1; + tcp->lay_t+=1; + incr_top=0; + } + }else{ + pi[pino].poc.layno0 = tcp->lay_t - 1; + pi[pino].poc.layno1 = tcp->lay_t; + } + } + } + break; + + case 'P': + switch(tcp->prg){ + case LRCP: + case RLCP: + if (i > tppos){ + pi[pino].poc.precno0 = tcp->prcS; + pi[pino].poc.precno1 = tcp->prcE; + }else{ + if (tpnum == 0){ + tcp->prc_t = tcp->prcS; + pi[pino].poc.precno0 = tcp->prc_t; + pi[pino].poc.precno1 = tcp->prc_t+1; + tcp->prc_t+=1; + }else{ + if (incr_top == 1){ + if(tcp->prc_t == tcp->prcE){ + tcp->prc_t = tcp->prcS; + pi[pino].poc.precno0 = tcp->prc_t; + pi[pino].poc.precno1 = tcp->prc_t+1; + tcp->prc_t+=1; + incr_top=1; + }else{ + pi[pino].poc.precno0 = tcp->prc_t; + pi[pino].poc.precno1 = tcp->prc_t+1; + tcp->prc_t+=1; + incr_top=0; + } + }else{ + pi[pino].poc.precno0 = tcp->prc_t - 1; + pi[pino].poc.precno1 = tcp->prc_t; + } + } + } + break; + default: + if (i > tppos){ + pi[pino].poc.tx0 = tcp->txS; + pi[pino].poc.ty0 = tcp->tyS; + pi[pino].poc.tx1 = tcp->txE; + pi[pino].poc.ty1 = tcp->tyE; + }else{ + if (tpnum == 0){ + tcp->tx0_t = tcp->txS; + tcp->ty0_t = tcp->tyS; + pi[pino].poc.tx0 = tcp->tx0_t; + pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx); + pi[pino].poc.ty0 = tcp->ty0_t; + pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); + tcp->tx0_t = pi[pino].poc.tx1; + tcp->ty0_t = pi[pino].poc.ty1; + }else{ + if (incr_top == 1){ + if(tcp->tx0_t >= tcp->txE){ + if(tcp->ty0_t >= tcp->tyE){ + tcp->ty0_t = tcp->tyS; + pi[pino].poc.ty0 = tcp->ty0_t; + pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); + tcp->ty0_t = pi[pino].poc.ty1; + incr_top=1;resetX=1; + }else{ + pi[pino].poc.ty0 = tcp->ty0_t; + pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); + tcp->ty0_t = pi[pino].poc.ty1; + incr_top=0;resetX=1; + } + if(resetX==1){ + tcp->tx0_t = tcp->txS; + pi[pino].poc.tx0 = tcp->tx0_t; + pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx); + tcp->tx0_t = pi[pino].poc.tx1; + } + }else{ + pi[pino].poc.tx0 = tcp->tx0_t; + pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx); + tcp->tx0_t = pi[pino].poc.tx1; + pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy); + pi[pino].poc.ty1 = tcp->ty0_t ; + incr_top=0; + } + }else{ + pi[pino].poc.tx0 = tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx); + pi[pino].poc.tx1 = tcp->tx0_t ; + pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy); + pi[pino].poc.ty1 = tcp->ty0_t ; + } + } + } + break; + } + break; + } + } + } + } + return OPJ_FALSE; +} + diff --git a/Source/LibOpenJPEG/pi.h b/Source/LibOpenJPEG/pi.h index d90bf53..cf9135f 100644 --- a/Source/LibOpenJPEG/pi.h +++ b/Source/LibOpenJPEG/pi.h @@ -1,156 +1,156 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __PI_H -#define __PI_H -/** -@file pi.h -@brief Implementation of a packet iterator (PI) - -The functions in PI.C have for goal to realize a packet iterator that permits to get the next -packet following the progression order and change of it. The functions in PI.C are used -by some function in T2.C. -*/ - -/** @defgroup PI PI - Implementation of a packet iterator */ -/*@{*/ - -/** -FIXME: documentation -*/ -typedef struct opj_pi_resolution { - int pdx, pdy; - int pw, ph; -} opj_pi_resolution_t; - -/** -FIXME: documentation -*/ -typedef struct opj_pi_comp { - int dx, dy; - /** number of resolution levels */ - int numresolutions; - opj_pi_resolution_t *resolutions; -} opj_pi_comp_t; - -/** -Packet iterator -*/ -typedef struct opj_pi_iterator { - /** Enabling Tile part generation*/ - char tp_on; - /** precise if the packet has been already used (usefull for progression order change) */ - short int *include; - /** layer step used to localize the packet in the include vector */ - int step_l; - /** resolution step used to localize the packet in the include vector */ - int step_r; - /** component step used to localize the packet in the include vector */ - int step_c; - /** precinct step used to localize the packet in the include vector */ - int step_p; - /** component that identify the packet */ - int compno; - /** resolution that identify the packet */ - int resno; - /** precinct that identify the packet */ - int precno; - /** layer that identify the packet */ - int layno; - /** 0 if the first packet */ - int first; - /** progression order change information */ - opj_poc_t poc; - /** number of components in the image */ - int numcomps; - /** Components*/ - opj_pi_comp_t *comps; - int tx0, ty0, tx1, ty1; - int x, y, dx, dy; -} opj_pi_iterator_t; - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Create a packet iterator for Encoder -@param image Raw image for which the packets will be listed -@param cp Coding parameters -@param tileno Number that identifies the tile for which to list the packets -@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass -@return Returns a packet iterator that points to the first packet of the tile -@see pi_destroy -*/ -opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int tileno,J2K_T2_MODE t2_mode); -/** -Modify the packet iterator for enabling tile part generation -@param pi Handle to the packet iterator generated in pi_initialise_encode -@param cp Coding parameters -@param tileno Number that identifies the tile for which to list the packets -@param pino Iterator index for pi -@param tpnum Tile part number of the current tile -@param tppos The position of the tile part flag in the progression order -@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass -@param cur_totnum_tp The total number of tile parts in the current tile -@return Returns true if an error is detected -*/ -opj_bool pi_create_encode(opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos, J2K_T2_MODE t2_mode,int cur_totnum_tp); -/** -Create a packet iterator for Decoder -@param image Raw image for which the packets will be listed -@param cp Coding parameters -@param tileno Number that identifies the tile for which to list the packets -@return Returns a packet iterator that points to the first packet of the tile -@see pi_destroy -*/ -opj_pi_iterator_t *pi_create_decode(opj_image_t * image, opj_cp_t * cp, int tileno); - -/** -Destroy a packet iterator -@param pi Previously created packet iterator -@param cp Coding parameters -@param tileno Number that identifies the tile for which the packets were listed -@see pi_create -*/ -void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno); - -/** -Modify the packet iterator to point to the next packet -@param pi Packet iterator to modify -@return Returns false if pi pointed to the last packet or else returns true -*/ -opj_bool pi_next(opj_pi_iterator_t * pi); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __PI_H */ +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __PI_H +#define __PI_H +/** +@file pi.h +@brief Implementation of a packet iterator (PI) + +The functions in PI.C have for goal to realize a packet iterator that permits to get the next +packet following the progression order and change of it. The functions in PI.C are used +by some function in T2.C. +*/ + +/** @defgroup PI PI - Implementation of a packet iterator */ +/*@{*/ + +/** +FIXME: documentation +*/ +typedef struct opj_pi_resolution { + int pdx, pdy; + int pw, ph; +} opj_pi_resolution_t; + +/** +FIXME: documentation +*/ +typedef struct opj_pi_comp { + int dx, dy; + /** number of resolution levels */ + int numresolutions; + opj_pi_resolution_t *resolutions; +} opj_pi_comp_t; + +/** +Packet iterator +*/ +typedef struct opj_pi_iterator { + /** Enabling Tile part generation*/ + char tp_on; + /** precise if the packet has been already used (usefull for progression order change) */ + short int *include; + /** layer step used to localize the packet in the include vector */ + int step_l; + /** resolution step used to localize the packet in the include vector */ + int step_r; + /** component step used to localize the packet in the include vector */ + int step_c; + /** precinct step used to localize the packet in the include vector */ + int step_p; + /** component that identify the packet */ + int compno; + /** resolution that identify the packet */ + int resno; + /** precinct that identify the packet */ + int precno; + /** layer that identify the packet */ + int layno; + /** 0 if the first packet */ + int first; + /** progression order change information */ + opj_poc_t poc; + /** number of components in the image */ + int numcomps; + /** Components*/ + opj_pi_comp_t *comps; + int tx0, ty0, tx1, ty1; + int x, y, dx, dy; +} opj_pi_iterator_t; + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Create a packet iterator for Encoder +@param image Raw image for which the packets will be listed +@param cp Coding parameters +@param tileno Number that identifies the tile for which to list the packets +@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass +@return Returns a packet iterator that points to the first packet of the tile +@see pi_destroy +*/ +opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int tileno,J2K_T2_MODE t2_mode); +/** +Modify the packet iterator for enabling tile part generation +@param pi Handle to the packet iterator generated in pi_initialise_encode +@param cp Coding parameters +@param tileno Number that identifies the tile for which to list the packets +@param pino Iterator index for pi +@param tpnum Tile part number of the current tile +@param tppos The position of the tile part flag in the progression order +@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass +@param cur_totnum_tp The total number of tile parts in the current tile +@return Returns true if an error is detected +*/ +opj_bool pi_create_encode(opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos, J2K_T2_MODE t2_mode,int cur_totnum_tp); +/** +Create a packet iterator for Decoder +@param image Raw image for which the packets will be listed +@param cp Coding parameters +@param tileno Number that identifies the tile for which to list the packets +@return Returns a packet iterator that points to the first packet of the tile +@see pi_destroy +*/ +opj_pi_iterator_t *pi_create_decode(opj_image_t * image, opj_cp_t * cp, int tileno); + +/** +Destroy a packet iterator +@param pi Previously created packet iterator +@param cp Coding parameters +@param tileno Number that identifies the tile for which the packets were listed +@see pi_create +*/ +void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno); + +/** +Modify the packet iterator to point to the next packet +@param pi Packet iterator to modify +@return Returns false if pi pointed to the last packet or else returns true +*/ +opj_bool pi_next(opj_pi_iterator_t * pi); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __PI_H */ diff --git a/Source/LibOpenJPEG/ppix_manager.c b/Source/LibOpenJPEG/ppix_manager.c index 96e35ff..ee477c1 100644 --- a/Source/LibOpenJPEG/ppix_manager.c +++ b/Source/LibOpenJPEG/ppix_manager.c @@ -1,173 +1,173 @@ -/* - * $Id: ppix_manager.c,v 1.2 2012/09/23 12:44:41 drolon Exp $ - * - * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2011, Professor Benoit Macq - * Copyright (c) 2003-2004, Yannick Verschueren - * Copyright (c) 2010-2011, Kaori Hagihara - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/*! \file - * \brief Modification of jpip.c from 2KAN indexer - */ - -#include -#include -#include -#include "opj_includes.h" - -/* - * Write faix box of ppix - * - * @param[in] coff offset of j2k codestream - * @param[in] compno component number - * @param[in] cstr_info codestream information - * @param[in] EPHused true if if EPH option used - * @param[in] j2klen length of j2k codestream - * @param[in] cio file output handle - * @return length of faix box - */ -int write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio); - -int write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio) -{ - int len, lenp, compno, i; - opj_jp2_box_t *box; - - /* printf("cstr_info.packno %d\n", cstr_info.packno); //NMAX? */ - - lenp = -1; - box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t)); - - for (i=0;i<2;i++){ - if (i) cio_seek( cio, lenp); - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_PPIX, 4); /* PPIX */ - - write_manf( i, cstr_info.numcomps, box, cio); - - for (compno=0; compno pow( 2, 32)){ - size_of_coding = 8; - version = 1; - } - else{ - size_of_coding = 4; - version = 0; - } - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_FAIX, 4); /* FAIX */ - cio_write( cio, version, 1); /* Version 0 = 4 bytes */ - - nmax = 0; - for( i=0; i<=cstr_info.numdecompos[compno]; i++) - nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers; - - cio_write( cio, nmax, size_of_coding); /* NMAX */ - cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */ - - for( tileno=0; tilenopw[resno]*tile_Idx->ph[resno]; - for( precno=0; precnopacket[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno]; - break; - case RLCP: - packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno]; - break; - case RPCL: - packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno]; - break; - case PCRL: - packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno]; - break; - case CPRL: - packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno]; - break; - default: - fprintf( stderr, "failed to ppix indexing\n"); - } - - cio_write( cio, packet.start_pos-coff, size_of_coding); /* start position */ - cio_write( cio, packet.end_pos-packet.start_pos+1, size_of_coding); /* length */ - - num_packet++; - } - } - } - - while( num_packet < nmax){ /* PADDING */ - cio_write( cio, 0, size_of_coding); /* start position */ - cio_write( cio, 0, size_of_coding); /* length */ - num_packet++; - } - } - - len = cio_tell( cio)-lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); - - return len; -} +/* + * $Id: ppix_manager.c,v 1.2 2012/09/23 12:44:41 drolon Exp $ + * + * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2011, Professor Benoit Macq + * Copyright (c) 2003-2004, Yannick Verschueren + * Copyright (c) 2010-2011, Kaori Hagihara + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*! \file + * \brief Modification of jpip.c from 2KAN indexer + */ + +#include +#include +#include +#include "opj_includes.h" + +/* + * Write faix box of ppix + * + * @param[in] coff offset of j2k codestream + * @param[in] compno component number + * @param[in] cstr_info codestream information + * @param[in] EPHused true if if EPH option used + * @param[in] j2klen length of j2k codestream + * @param[in] cio file output handle + * @return length of faix box + */ +int write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio); + +int write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio) +{ + int len, lenp, compno, i; + opj_jp2_box_t *box; + + /* printf("cstr_info.packno %d\n", cstr_info.packno); //NMAX? */ + + lenp = -1; + box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t)); + + for (i=0;i<2;i++){ + if (i) cio_seek( cio, lenp); + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_PPIX, 4); /* PPIX */ + + write_manf( i, cstr_info.numcomps, box, cio); + + for (compno=0; compno pow( 2, 32)){ + size_of_coding = 8; + version = 1; + } + else{ + size_of_coding = 4; + version = 0; + } + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_FAIX, 4); /* FAIX */ + cio_write( cio, version, 1); /* Version 0 = 4 bytes */ + + nmax = 0; + for( i=0; i<=cstr_info.numdecompos[compno]; i++) + nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers; + + cio_write( cio, nmax, size_of_coding); /* NMAX */ + cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */ + + for( tileno=0; tilenopw[resno]*tile_Idx->ph[resno]; + for( precno=0; precnopacket[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno]; + break; + case RLCP: + packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno]; + break; + case RPCL: + packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno]; + break; + case PCRL: + packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno]; + break; + case CPRL: + packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno]; + break; + default: + fprintf( stderr, "failed to ppix indexing\n"); + } + + cio_write( cio, packet.start_pos-coff, size_of_coding); /* start position */ + cio_write( cio, packet.end_pos-packet.start_pos+1, size_of_coding); /* length */ + + num_packet++; + } + } + } + + while( num_packet < nmax){ /* PADDING */ + cio_write( cio, 0, size_of_coding); /* start position */ + cio_write( cio, 0, size_of_coding); /* length */ + num_packet++; + } + } + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); + + return len; +} diff --git a/Source/LibOpenJPEG/raw.c b/Source/LibOpenJPEG/raw.c index 265ecbd..3d231bf 100644 --- a/Source/LibOpenJPEG/raw.c +++ b/Source/LibOpenJPEG/raw.c @@ -1,87 +1,87 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/* -========================================================== - local functions -========================================================== -*/ - - -/* -========================================================== - RAW encoding interface -========================================================== -*/ - -opj_raw_t* raw_create(void) { - opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t)); - return raw; -} - -void raw_destroy(opj_raw_t *raw) { - if(raw) { - opj_free(raw); - } -} - -int raw_numbytes(opj_raw_t *raw) { - return raw->bp - raw->start; -} - -void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len) { - raw->start = bp; - raw->lenmax = len; - raw->len = 0; - raw->c = 0; - raw->ct = 0; -} - -int raw_decode(opj_raw_t *raw) { - int d; - if (raw->ct == 0) { - raw->ct = 8; - if (raw->len == raw->lenmax) { - raw->c = 0xff; - } else { - if (raw->c == 0xff) { - raw->ct = 7; - } - raw->c = *(raw->start + raw->len); - raw->len++; - } - } - raw->ct--; - d = (raw->c >> raw->ct) & 0x01; - - return d; -} - +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/* +========================================================== + local functions +========================================================== +*/ + + +/* +========================================================== + RAW encoding interface +========================================================== +*/ + +opj_raw_t* raw_create(void) { + opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t)); + return raw; +} + +void raw_destroy(opj_raw_t *raw) { + if(raw) { + opj_free(raw); + } +} + +int raw_numbytes(opj_raw_t *raw) { + return raw->bp - raw->start; +} + +void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len) { + raw->start = bp; + raw->lenmax = len; + raw->len = 0; + raw->c = 0; + raw->ct = 0; +} + +int raw_decode(opj_raw_t *raw) { + int d; + if (raw->ct == 0) { + raw->ct = 8; + if (raw->len == raw->lenmax) { + raw->c = 0xff; + } else { + if (raw->c == 0xff) { + raw->ct = 7; + } + raw->c = *(raw->start + raw->len); + raw->len++; + } + } + raw->ct--; + d = (raw->c >> raw->ct) & 0x01; + + return d; +} + diff --git a/Source/LibOpenJPEG/raw.h b/Source/LibOpenJPEG/raw.h index f873ac5..3c4b372 100644 --- a/Source/LibOpenJPEG/raw.h +++ b/Source/LibOpenJPEG/raw.h @@ -1,100 +1,100 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __RAW_H -#define __RAW_H -/** -@file raw.h -@brief Implementation of operations for raw encoding (RAW) - -The functions in RAW.C have for goal to realize the operation of raw encoding linked -with the corresponding mode switch. -*/ - -/** @defgroup RAW RAW - Implementation of operations for raw encoding */ -/*@{*/ - -/** -RAW encoding operations -*/ -typedef struct opj_raw { - /** temporary buffer where bits are coded or decoded */ - unsigned char c; - /** number of bits already read or free to write */ - unsigned int ct; - /** maximum length to decode */ - unsigned int lenmax; - /** length decoded */ - unsigned int len; - /** pointer to the current position in the buffer */ - unsigned char *bp; - /** pointer to the start of the buffer */ - unsigned char *start; - /** pointer to the end of the buffer */ - unsigned char *end; -} opj_raw_t; - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Create a new RAW handle -@return Returns a new RAW handle if successful, returns NULL otherwise -*/ -opj_raw_t* raw_create(void); -/** -Destroy a previously created RAW handle -@param raw RAW handle to destroy -*/ -void raw_destroy(opj_raw_t *raw); -/** -Return the number of bytes written/read since initialisation -@param raw RAW handle to destroy -@return Returns the number of bytes already encoded -*/ -int raw_numbytes(opj_raw_t *raw); -/** -Initialize the decoder -@param raw RAW handle -@param bp Pointer to the start of the buffer from which the bytes will be read -@param len Length of the input buffer -*/ -void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len); -/** -Decode a symbol using raw-decoder. Cfr p.506 TAUBMAN -@param raw RAW handle -@return Returns the decoded symbol (0 or 1) -*/ -int raw_decode(opj_raw_t *raw); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __RAW_H */ +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __RAW_H +#define __RAW_H +/** +@file raw.h +@brief Implementation of operations for raw encoding (RAW) + +The functions in RAW.C have for goal to realize the operation of raw encoding linked +with the corresponding mode switch. +*/ + +/** @defgroup RAW RAW - Implementation of operations for raw encoding */ +/*@{*/ + +/** +RAW encoding operations +*/ +typedef struct opj_raw { + /** temporary buffer where bits are coded or decoded */ + unsigned char c; + /** number of bits already read or free to write */ + unsigned int ct; + /** maximum length to decode */ + unsigned int lenmax; + /** length decoded */ + unsigned int len; + /** pointer to the current position in the buffer */ + unsigned char *bp; + /** pointer to the start of the buffer */ + unsigned char *start; + /** pointer to the end of the buffer */ + unsigned char *end; +} opj_raw_t; + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Create a new RAW handle +@return Returns a new RAW handle if successful, returns NULL otherwise +*/ +opj_raw_t* raw_create(void); +/** +Destroy a previously created RAW handle +@param raw RAW handle to destroy +*/ +void raw_destroy(opj_raw_t *raw); +/** +Return the number of bytes written/read since initialisation +@param raw RAW handle to destroy +@return Returns the number of bytes already encoded +*/ +int raw_numbytes(opj_raw_t *raw); +/** +Initialize the decoder +@param raw RAW handle +@param bp Pointer to the start of the buffer from which the bytes will be read +@param len Length of the input buffer +*/ +void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len); +/** +Decode a symbol using raw-decoder. Cfr p.506 TAUBMAN +@param raw RAW handle +@return Returns the decoded symbol (0 or 1) +*/ +int raw_decode(opj_raw_t *raw); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __RAW_H */ diff --git a/Source/LibOpenJPEG/t1.c b/Source/LibOpenJPEG/t1.c index 4b0f5c4..ed9cdc3 100644 --- a/Source/LibOpenJPEG/t1.c +++ b/Source/LibOpenJPEG/t1.c @@ -1,1585 +1,1585 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2007, Callum Lerwick - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" -#include "t1_luts.h" - -/** @defgroup T1 T1 - Implementation of the tier-1 coding */ -/*@{*/ - -/** @name Local static functions */ -/*@{*/ - -static INLINE char t1_getctxno_zc(int f, int orient); -static char t1_getctxno_sc(int f); -static INLINE int t1_getctxno_mag(int f); -static char t1_getspb(int f); -static short t1_getnmsedec_sig(int x, int bitpos); -static short t1_getnmsedec_ref(int x, int bitpos); -static void t1_updateflags(flag_t *flagsp, int s, int stride); -/** -Encode significant pass -*/ -static void t1_enc_sigpass_step( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int bpno, - int one, - int *nmsedec, - char type, - int vsc); -/** -Decode significant pass -*/ -static INLINE void t1_dec_sigpass_step_raw( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int oneplushalf, - int vsc); -static INLINE void t1_dec_sigpass_step_mqc( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int oneplushalf); -static INLINE void t1_dec_sigpass_step_mqc_vsc( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int oneplushalf, - int vsc); -/** -Encode significant pass -*/ -static void t1_enc_sigpass( - opj_t1_t *t1, - int bpno, - int orient, - int *nmsedec, - char type, - int cblksty); -/** -Decode significant pass -*/ -static void t1_dec_sigpass_raw( - opj_t1_t *t1, - int bpno, - int orient, - int cblksty); -static void t1_dec_sigpass_mqc( - opj_t1_t *t1, - int bpno, - int orient); -static void t1_dec_sigpass_mqc_vsc( - opj_t1_t *t1, - int bpno, - int orient); -/** -Encode refinement pass -*/ -static void t1_enc_refpass_step( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int bpno, - int one, - int *nmsedec, - char type, - int vsc); -/** -Decode refinement pass -*/ -static INLINE void t1_dec_refpass_step_raw( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int poshalf, - int neghalf, - int vsc); -static INLINE void t1_dec_refpass_step_mqc( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int poshalf, - int neghalf); -static INLINE void t1_dec_refpass_step_mqc_vsc( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int poshalf, - int neghalf, - int vsc); - -/** -Encode refinement pass -*/ -static void t1_enc_refpass( - opj_t1_t *t1, - int bpno, - int *nmsedec, - char type, - int cblksty); -/** -Decode refinement pass -*/ -static void t1_dec_refpass_raw( - opj_t1_t *t1, - int bpno, - int cblksty); -static void t1_dec_refpass_mqc( - opj_t1_t *t1, - int bpno); -static void t1_dec_refpass_mqc_vsc( - opj_t1_t *t1, - int bpno); -/** -Encode clean-up pass -*/ -static void t1_enc_clnpass_step( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int bpno, - int one, - int *nmsedec, - int partial, - int vsc); -/** -Decode clean-up pass -*/ -static void t1_dec_clnpass_step_partial( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int oneplushalf); -static void t1_dec_clnpass_step( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int oneplushalf); -static void t1_dec_clnpass_step_vsc( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int oneplushalf, - int partial, - int vsc); -/** -Encode clean-up pass -*/ -static void t1_enc_clnpass( - opj_t1_t *t1, - int bpno, - int orient, - int *nmsedec, - int cblksty); -/** -Decode clean-up pass -*/ -static void t1_dec_clnpass( - opj_t1_t *t1, - int bpno, - int orient, - int cblksty); -static double t1_getwmsedec( - int nmsedec, - int compno, - int level, - int orient, - int bpno, - int qmfbid, - double stepsize, - int numcomps, - int mct); -/** -Encode 1 code-block -@param t1 T1 handle -@param cblk Code-block coding parameters -@param orient -@param compno Component number -@param level -@param qmfbid -@param stepsize -@param cblksty Code-block style -@param numcomps -@param mct -@param tile -*/ -static void t1_encode_cblk( - opj_t1_t *t1, - opj_tcd_cblk_enc_t* cblk, - int orient, - int compno, - int level, - int qmfbid, - double stepsize, - int cblksty, - int numcomps, - int mct, - opj_tcd_tile_t * tile); -/** -Decode 1 code-block -@param t1 T1 handle -@param cblk Code-block coding parameters -@param orient -@param roishift Region of interest shifting value -@param cblksty Code-block style -*/ -static void t1_decode_cblk( - opj_t1_t *t1, - opj_tcd_cblk_dec_t* cblk, - int orient, - int roishift, - int cblksty); - -/*@}*/ - -/*@}*/ - -/* ----------------------------------------------------------------------- */ - -static char t1_getctxno_zc(int f, int orient) { - return lut_ctxno_zc[(orient << 8) | (f & T1_SIG_OTH)]; -} - -static char t1_getctxno_sc(int f) { - return lut_ctxno_sc[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; -} - -static int t1_getctxno_mag(int f) { - int tmp1 = (f & T1_SIG_OTH) ? T1_CTXNO_MAG + 1 : T1_CTXNO_MAG; - int tmp2 = (f & T1_REFINE) ? T1_CTXNO_MAG + 2 : tmp1; - return (tmp2); -} - -static char t1_getspb(int f) { - return lut_spb[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; -} - -static short t1_getnmsedec_sig(int x, int bitpos) { - if (bitpos > T1_NMSEDEC_FRACBITS) { - return lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; - } - - return lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; -} - -static short t1_getnmsedec_ref(int x, int bitpos) { - if (bitpos > T1_NMSEDEC_FRACBITS) { - return lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; - } - - return lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; -} - -static void t1_updateflags(flag_t *flagsp, int s, int stride) { - flag_t *np = flagsp - stride; - flag_t *sp = flagsp + stride; - - static const flag_t mod[] = { - T1_SIG_S, T1_SIG_S|T1_SGN_S, - T1_SIG_E, T1_SIG_E|T1_SGN_E, - T1_SIG_W, T1_SIG_W|T1_SGN_W, - T1_SIG_N, T1_SIG_N|T1_SGN_N - }; - - np[-1] |= T1_SIG_SE; - np[0] |= mod[s]; - np[1] |= T1_SIG_SW; - - flagsp[-1] |= mod[s+2]; - flagsp[0] |= T1_SIG; - flagsp[1] |= mod[s+4]; - - sp[-1] |= T1_SIG_NE; - sp[0] |= mod[s+6]; - sp[1] |= T1_SIG_NW; -} - -static void t1_enc_sigpass_step( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int bpno, - int one, - int *nmsedec, - char type, - int vsc) -{ - int v, flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); - if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { - v = int_abs(*datap) & one ? 1 : 0; - mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); /* ESSAI */ - if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - mqc_bypass_enc(mqc, v); - } else { - mqc_encode(mqc, v); - } - if (v) { - v = *datap < 0 ? 1 : 0; - *nmsedec += t1_getnmsedec_sig(int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS); - mqc_setcurctx(mqc, t1_getctxno_sc(flag)); /* ESSAI */ - if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - mqc_bypass_enc(mqc, v); - } else { - mqc_encode(mqc, v ^ t1_getspb(flag)); - } - t1_updateflags(flagsp, v, t1->flags_stride); - } - *flagsp |= T1_VISIT; - } -} - -static INLINE void t1_dec_sigpass_step_raw( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int oneplushalf, - int vsc) -{ - int v, flag; - opj_raw_t *raw = t1->raw; /* RAW component */ - - OPJ_ARG_NOT_USED(orient); - - flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); - if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { - if (raw_decode(raw)) { - v = raw_decode(raw); /* ESSAI */ - *datap = v ? -oneplushalf : oneplushalf; - t1_updateflags(flagsp, v, t1->flags_stride); - } - *flagsp |= T1_VISIT; - } -} /* VSC and BYPASS by Antonin */ - -static INLINE void t1_dec_sigpass_step_mqc( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int oneplushalf) -{ - int v, flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = *flagsp; - if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { - mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); - if (mqc_decode(mqc)) { - mqc_setcurctx(mqc, t1_getctxno_sc(flag)); - v = mqc_decode(mqc) ^ t1_getspb(flag); - *datap = v ? -oneplushalf : oneplushalf; - t1_updateflags(flagsp, v, t1->flags_stride); - } - *flagsp |= T1_VISIT; - } -} /* VSC and BYPASS by Antonin */ - -static INLINE void t1_dec_sigpass_step_mqc_vsc( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int oneplushalf, - int vsc) -{ - int v, flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); - if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { - mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); - if (mqc_decode(mqc)) { - mqc_setcurctx(mqc, t1_getctxno_sc(flag)); - v = mqc_decode(mqc) ^ t1_getspb(flag); - *datap = v ? -oneplushalf : oneplushalf; - t1_updateflags(flagsp, v, t1->flags_stride); - } - *flagsp |= T1_VISIT; - } -} /* VSC and BYPASS by Antonin */ - -static void t1_enc_sigpass( - opj_t1_t *t1, - int bpno, - int orient, - int *nmsedec, - char type, - int cblksty) -{ - int i, j, k, one, vsc; - *nmsedec = 0; - one = 1 << (bpno + T1_NMSEDEC_FRACBITS); - for (k = 0; k < t1->h; k += 4) { - for (i = 0; i < t1->w; ++i) { - for (j = k; j < k + 4 && j < t1->h; ++j) { - vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; - t1_enc_sigpass_step( - t1, - &t1->flags[((j+1) * t1->flags_stride) + i + 1], - &t1->data[(j * t1->w) + i], - orient, - bpno, - one, - nmsedec, - type, - vsc); - } - } - } -} - -static void t1_dec_sigpass_raw( - opj_t1_t *t1, - int bpno, - int orient, - int cblksty) -{ - int i, j, k, one, half, oneplushalf, vsc; - one = 1 << bpno; - half = one >> 1; - oneplushalf = one | half; - for (k = 0; k < t1->h; k += 4) { - for (i = 0; i < t1->w; ++i) { - for (j = k; j < k + 4 && j < t1->h; ++j) { - vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; - t1_dec_sigpass_step_raw( - t1, - &t1->flags[((j+1) * t1->flags_stride) + i + 1], - &t1->data[(j * t1->w) + i], - orient, - oneplushalf, - vsc); - } - } - } -} /* VSC and BYPASS by Antonin */ - -static void t1_dec_sigpass_mqc( - opj_t1_t *t1, - int bpno, - int orient) -{ - int i, j, k, one, half, oneplushalf; - int *data1 = t1->data; - flag_t *flags1 = &t1->flags[1]; - one = 1 << bpno; - half = one >> 1; - oneplushalf = one | half; - for (k = 0; k < (t1->h & ~3); k += 4) { - for (i = 0; i < t1->w; ++i) { - int *data2 = data1 + i; - flag_t *flags2 = flags1 + i; - flags2 += t1->flags_stride; - t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); - data2 += t1->w; - flags2 += t1->flags_stride; - t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); - data2 += t1->w; - flags2 += t1->flags_stride; - t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); - data2 += t1->w; - flags2 += t1->flags_stride; - t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); - data2 += t1->w; - } - data1 += t1->w << 2; - flags1 += t1->flags_stride << 2; - } - for (i = 0; i < t1->w; ++i) { - int *data2 = data1 + i; - flag_t *flags2 = flags1 + i; - for (j = k; j < t1->h; ++j) { - flags2 += t1->flags_stride; - t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); - data2 += t1->w; - } - } -} /* VSC and BYPASS by Antonin */ - -static void t1_dec_sigpass_mqc_vsc( - opj_t1_t *t1, - int bpno, - int orient) -{ - int i, j, k, one, half, oneplushalf, vsc; - one = 1 << bpno; - half = one >> 1; - oneplushalf = one | half; - for (k = 0; k < t1->h; k += 4) { - for (i = 0; i < t1->w; ++i) { - for (j = k; j < k + 4 && j < t1->h; ++j) { - vsc = (j == k + 3 || j == t1->h - 1) ? 1 : 0; - t1_dec_sigpass_step_mqc_vsc( - t1, - &t1->flags[((j+1) * t1->flags_stride) + i + 1], - &t1->data[(j * t1->w) + i], - orient, - oneplushalf, - vsc); - } - } - } -} /* VSC and BYPASS by Antonin */ - -static void t1_enc_refpass_step( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int bpno, - int one, - int *nmsedec, - char type, - int vsc) -{ - int v, flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); - if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { - *nmsedec += t1_getnmsedec_ref(int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS); - v = int_abs(*datap) & one ? 1 : 0; - mqc_setcurctx(mqc, t1_getctxno_mag(flag)); /* ESSAI */ - if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - mqc_bypass_enc(mqc, v); - } else { - mqc_encode(mqc, v); - } - *flagsp |= T1_REFINE; - } -} - -static INLINE void t1_dec_refpass_step_raw( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int poshalf, - int neghalf, - int vsc) -{ - int v, t, flag; - - opj_raw_t *raw = t1->raw; /* RAW component */ - - flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); - if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { - v = raw_decode(raw); - t = v ? poshalf : neghalf; - *datap += *datap < 0 ? -t : t; - *flagsp |= T1_REFINE; - } -} /* VSC and BYPASS by Antonin */ - -static INLINE void t1_dec_refpass_step_mqc( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int poshalf, - int neghalf) -{ - int v, t, flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = *flagsp; - if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { - mqc_setcurctx(mqc, t1_getctxno_mag(flag)); /* ESSAI */ - v = mqc_decode(mqc); - t = v ? poshalf : neghalf; - *datap += *datap < 0 ? -t : t; - *flagsp |= T1_REFINE; - } -} /* VSC and BYPASS by Antonin */ - -static INLINE void t1_dec_refpass_step_mqc_vsc( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int poshalf, - int neghalf, - int vsc) -{ - int v, t, flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); - if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { - mqc_setcurctx(mqc, t1_getctxno_mag(flag)); /* ESSAI */ - v = mqc_decode(mqc); - t = v ? poshalf : neghalf; - *datap += *datap < 0 ? -t : t; - *flagsp |= T1_REFINE; - } -} /* VSC and BYPASS by Antonin */ - -static void t1_enc_refpass( - opj_t1_t *t1, - int bpno, - int *nmsedec, - char type, - int cblksty) -{ - int i, j, k, one, vsc; - *nmsedec = 0; - one = 1 << (bpno + T1_NMSEDEC_FRACBITS); - for (k = 0; k < t1->h; k += 4) { - for (i = 0; i < t1->w; ++i) { - for (j = k; j < k + 4 && j < t1->h; ++j) { - vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; - t1_enc_refpass_step( - t1, - &t1->flags[((j+1) * t1->flags_stride) + i + 1], - &t1->data[(j * t1->w) + i], - bpno, - one, - nmsedec, - type, - vsc); - } - } - } -} - -static void t1_dec_refpass_raw( - opj_t1_t *t1, - int bpno, - int cblksty) -{ - int i, j, k, one, poshalf, neghalf; - int vsc; - one = 1 << bpno; - poshalf = one >> 1; - neghalf = bpno > 0 ? -poshalf : -1; - for (k = 0; k < t1->h; k += 4) { - for (i = 0; i < t1->w; ++i) { - for (j = k; j < k + 4 && j < t1->h; ++j) { - vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; - t1_dec_refpass_step_raw( - t1, - &t1->flags[((j+1) * t1->flags_stride) + i + 1], - &t1->data[(j * t1->w) + i], - poshalf, - neghalf, - vsc); - } - } - } -} /* VSC and BYPASS by Antonin */ - -static void t1_dec_refpass_mqc( - opj_t1_t *t1, - int bpno) -{ - int i, j, k, one, poshalf, neghalf; - int *data1 = t1->data; - flag_t *flags1 = &t1->flags[1]; - one = 1 << bpno; - poshalf = one >> 1; - neghalf = bpno > 0 ? -poshalf : -1; - for (k = 0; k < (t1->h & ~3); k += 4) { - for (i = 0; i < t1->w; ++i) { - int *data2 = data1 + i; - flag_t *flags2 = flags1 + i; - flags2 += t1->flags_stride; - t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); - data2 += t1->w; - flags2 += t1->flags_stride; - t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); - data2 += t1->w; - flags2 += t1->flags_stride; - t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); - data2 += t1->w; - flags2 += t1->flags_stride; - t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); - data2 += t1->w; - } - data1 += t1->w << 2; - flags1 += t1->flags_stride << 2; - } - for (i = 0; i < t1->w; ++i) { - int *data2 = data1 + i; - flag_t *flags2 = flags1 + i; - for (j = k; j < t1->h; ++j) { - flags2 += t1->flags_stride; - t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); - data2 += t1->w; - } - } -} /* VSC and BYPASS by Antonin */ - -static void t1_dec_refpass_mqc_vsc( - opj_t1_t *t1, - int bpno) -{ - int i, j, k, one, poshalf, neghalf; - int vsc; - one = 1 << bpno; - poshalf = one >> 1; - neghalf = bpno > 0 ? -poshalf : -1; - for (k = 0; k < t1->h; k += 4) { - for (i = 0; i < t1->w; ++i) { - for (j = k; j < k + 4 && j < t1->h; ++j) { - vsc = ((j == k + 3 || j == t1->h - 1)) ? 1 : 0; - t1_dec_refpass_step_mqc_vsc( - t1, - &t1->flags[((j+1) * t1->flags_stride) + i + 1], - &t1->data[(j * t1->w) + i], - poshalf, - neghalf, - vsc); - } - } - } -} /* VSC and BYPASS by Antonin */ - -static void t1_enc_clnpass_step( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int bpno, - int one, - int *nmsedec, - int partial, - int vsc) -{ - int v, flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); - if (partial) { - goto LABEL_PARTIAL; - } - if (!(*flagsp & (T1_SIG | T1_VISIT))) { - mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); - v = int_abs(*datap) & one ? 1 : 0; - mqc_encode(mqc, v); - if (v) { -LABEL_PARTIAL: - *nmsedec += t1_getnmsedec_sig(int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS); - mqc_setcurctx(mqc, t1_getctxno_sc(flag)); - v = *datap < 0 ? 1 : 0; - mqc_encode(mqc, v ^ t1_getspb(flag)); - t1_updateflags(flagsp, v, t1->flags_stride); - } - } - *flagsp &= ~T1_VISIT; -} - -static void t1_dec_clnpass_step_partial( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int oneplushalf) -{ - int v, flag; - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - OPJ_ARG_NOT_USED(orient); - - flag = *flagsp; - mqc_setcurctx(mqc, t1_getctxno_sc(flag)); - v = mqc_decode(mqc) ^ t1_getspb(flag); - *datap = v ? -oneplushalf : oneplushalf; - t1_updateflags(flagsp, v, t1->flags_stride); - *flagsp &= ~T1_VISIT; -} /* VSC and BYPASS by Antonin */ - -static void t1_dec_clnpass_step( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int oneplushalf) -{ - int v, flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = *flagsp; - if (!(flag & (T1_SIG | T1_VISIT))) { - mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); - if (mqc_decode(mqc)) { - mqc_setcurctx(mqc, t1_getctxno_sc(flag)); - v = mqc_decode(mqc) ^ t1_getspb(flag); - *datap = v ? -oneplushalf : oneplushalf; - t1_updateflags(flagsp, v, t1->flags_stride); - } - } - *flagsp &= ~T1_VISIT; -} /* VSC and BYPASS by Antonin */ - -static void t1_dec_clnpass_step_vsc( - opj_t1_t *t1, - flag_t *flagsp, - int *datap, - int orient, - int oneplushalf, - int partial, - int vsc) -{ - int v, flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); - if (partial) { - goto LABEL_PARTIAL; - } - if (!(flag & (T1_SIG | T1_VISIT))) { - mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); - if (mqc_decode(mqc)) { -LABEL_PARTIAL: - mqc_setcurctx(mqc, t1_getctxno_sc(flag)); - v = mqc_decode(mqc) ^ t1_getspb(flag); - *datap = v ? -oneplushalf : oneplushalf; - t1_updateflags(flagsp, v, t1->flags_stride); - } - } - *flagsp &= ~T1_VISIT; -} - -static void t1_enc_clnpass( - opj_t1_t *t1, - int bpno, - int orient, - int *nmsedec, - int cblksty) -{ - int i, j, k, one, agg, runlen, vsc; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - *nmsedec = 0; - one = 1 << (bpno + T1_NMSEDEC_FRACBITS); - for (k = 0; k < t1->h; k += 4) { - for (i = 0; i < t1->w; ++i) { - if (k + 3 < t1->h) { - if (cblksty & J2K_CCP_CBLKSTY_VSC) { - agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || (MACRO_t1_flags(1 + k + 3,1 + i) - & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); - } else { - agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || MACRO_t1_flags(1 + k + 3,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); - } - } else { - agg = 0; - } - if (agg) { - for (runlen = 0; runlen < 4; ++runlen) { - if (int_abs(t1->data[((k + runlen)*t1->w) + i]) & one) - break; - } - mqc_setcurctx(mqc, T1_CTXNO_AGG); - mqc_encode(mqc, runlen != 4); - if (runlen == 4) { - continue; - } - mqc_setcurctx(mqc, T1_CTXNO_UNI); - mqc_encode(mqc, runlen >> 1); - mqc_encode(mqc, runlen & 1); - } else { - runlen = 0; - } - for (j = k + runlen; j < k + 4 && j < t1->h; ++j) { - vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; - t1_enc_clnpass_step( - t1, - &t1->flags[((j+1) * t1->flags_stride) + i + 1], - &t1->data[(j * t1->w) + i], - orient, - bpno, - one, - nmsedec, - agg && (j == k + runlen), - vsc); - } - } - } -} - -static void t1_dec_clnpass( - opj_t1_t *t1, - int bpno, - int orient, - int cblksty) -{ - int i, j, k, one, half, oneplushalf, agg, runlen, vsc; - int segsym = cblksty & J2K_CCP_CBLKSTY_SEGSYM; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - one = 1 << bpno; - half = one >> 1; - oneplushalf = one | half; - if (cblksty & J2K_CCP_CBLKSTY_VSC) { - for (k = 0; k < t1->h; k += 4) { - for (i = 0; i < t1->w; ++i) { - if (k + 3 < t1->h) { - agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || (MACRO_t1_flags(1 + k + 3,1 + i) - & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); - } else { - agg = 0; - } - if (agg) { - mqc_setcurctx(mqc, T1_CTXNO_AGG); - if (!mqc_decode(mqc)) { - continue; - } - mqc_setcurctx(mqc, T1_CTXNO_UNI); - runlen = mqc_decode(mqc); - runlen = (runlen << 1) | mqc_decode(mqc); - } else { - runlen = 0; - } - for (j = k + runlen; j < k + 4 && j < t1->h; ++j) { - vsc = (j == k + 3 || j == t1->h - 1) ? 1 : 0; - t1_dec_clnpass_step_vsc( - t1, - &t1->flags[((j+1) * t1->flags_stride) + i + 1], - &t1->data[(j * t1->w) + i], - orient, - oneplushalf, - agg && (j == k + runlen), - vsc); - } - } - } - } else { - int *data1 = t1->data; - flag_t *flags1 = &t1->flags[1]; - for (k = 0; k < (t1->h & ~3); k += 4) { - for (i = 0; i < t1->w; ++i) { - int *data2 = data1 + i; - flag_t *flags2 = flags1 + i; - agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || MACRO_t1_flags(1 + k + 3,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); - if (agg) { - mqc_setcurctx(mqc, T1_CTXNO_AGG); - if (!mqc_decode(mqc)) { - continue; - } - mqc_setcurctx(mqc, T1_CTXNO_UNI); - runlen = mqc_decode(mqc); - runlen = (runlen << 1) | mqc_decode(mqc); - flags2 += runlen * t1->flags_stride; - data2 += runlen * t1->w; - for (j = k + runlen; j < k + 4 && j < t1->h; ++j) { - flags2 += t1->flags_stride; - if (agg && (j == k + runlen)) { - t1_dec_clnpass_step_partial(t1, flags2, data2, orient, oneplushalf); - } else { - t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); - } - data2 += t1->w; - } - } else { - flags2 += t1->flags_stride; - t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); - data2 += t1->w; - flags2 += t1->flags_stride; - t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); - data2 += t1->w; - flags2 += t1->flags_stride; - t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); - data2 += t1->w; - flags2 += t1->flags_stride; - t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); - data2 += t1->w; - } - } - data1 += t1->w << 2; - flags1 += t1->flags_stride << 2; - } - for (i = 0; i < t1->w; ++i) { - int *data2 = data1 + i; - flag_t *flags2 = flags1 + i; - for (j = k; j < t1->h; ++j) { - flags2 += t1->flags_stride; - t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); - data2 += t1->w; - } - } - } - - if (segsym) { - int v = 0; - mqc_setcurctx(mqc, T1_CTXNO_UNI); - v = mqc_decode(mqc); - v = (v << 1) | mqc_decode(mqc); - v = (v << 1) | mqc_decode(mqc); - v = (v << 1) | mqc_decode(mqc); - /* - if (v!=0xa) { - opj_event_msg(t1->cinfo, EVT_WARNING, "Bad segmentation symbol %x\n", v); - } - */ - } -} /* VSC and BYPASS by Antonin */ - - -/** mod fixed_quality */ -static double t1_getwmsedec( - int nmsedec, - int compno, - int level, - int orient, - int bpno, - int qmfbid, - double stepsize, - int numcomps, - int mct) -{ - double w1, w2, wmsedec; - if (qmfbid == 1) { - w1 = (mct && numcomps==3) ? mct_getnorm(compno) : 1.0; - w2 = dwt_getnorm(level, orient); - } else { /* if (qmfbid == 0) */ - w1 = (mct && numcomps==3) ? mct_getnorm_real(compno) : 1.0; - w2 = dwt_getnorm_real(level, orient); - } - wmsedec = w1 * w2 * stepsize * (1 << bpno); - wmsedec *= wmsedec * nmsedec / 8192.0; - - return wmsedec; -} - -static opj_bool allocate_buffers( - opj_t1_t *t1, - int w, - int h) -{ - int datasize=w * h; - int flagssize; - - if(datasize > t1->datasize){ - opj_aligned_free(t1->data); - t1->data = (int*) opj_aligned_malloc(datasize * sizeof(int)); - if(!t1->data){ - return OPJ_FALSE; - } - t1->datasize=datasize; - } - memset(t1->data,0,datasize * sizeof(int)); - - t1->flags_stride=w+2; - flagssize=t1->flags_stride * (h+2); - - if(flagssize > t1->flagssize){ - opj_aligned_free(t1->flags); - t1->flags = (flag_t*) opj_aligned_malloc(flagssize * sizeof(flag_t)); - if(!t1->flags){ - return OPJ_FALSE; - } - t1->flagssize=flagssize; - } - memset(t1->flags,0,flagssize * sizeof(flag_t)); - - t1->w=w; - t1->h=h; - - return OPJ_TRUE; -} - -/** mod fixed_quality */ -static void t1_encode_cblk( - opj_t1_t *t1, - opj_tcd_cblk_enc_t* cblk, - int orient, - int compno, - int level, - int qmfbid, - double stepsize, - int cblksty, - int numcomps, - int mct, - opj_tcd_tile_t * tile) -{ - double cumwmsedec = 0.0; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - int passno, bpno, passtype; - int nmsedec = 0; - int i, max; - char type = T1_TYPE_MQ; - double tempwmsedec; - - max = 0; - for (i = 0; i < t1->w * t1->h; ++i) { - int tmp = abs(t1->data[i]); - max = int_max(max, tmp); - } - - cblk->numbps = max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0; - - bpno = cblk->numbps - 1; - passtype = 2; - - mqc_resetstates(mqc); - mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); - mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); - mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); - mqc_init_enc(mqc, cblk->data); - - for (passno = 0; bpno >= 0; ++passno) { - opj_tcd_pass_t *pass = &cblk->passes[passno]; - int correction = 3; - type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; - - switch (passtype) { - case 0: - t1_enc_sigpass(t1, bpno, orient, &nmsedec, type, cblksty); - break; - case 1: - t1_enc_refpass(t1, bpno, &nmsedec, type, cblksty); - break; - case 2: - t1_enc_clnpass(t1, bpno, orient, &nmsedec, cblksty); - /* code switch SEGMARK (i.e. SEGSYM) */ - if (cblksty & J2K_CCP_CBLKSTY_SEGSYM) - mqc_segmark_enc(mqc); - break; - } - - /* fixed_quality */ - tempwmsedec = t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps, mct); - cumwmsedec += tempwmsedec; - tile->distotile += tempwmsedec; - - /* Code switch "RESTART" (i.e. TERMALL) */ - if ((cblksty & J2K_CCP_CBLKSTY_TERMALL) && !((passtype == 2) && (bpno - 1 < 0))) { - if (type == T1_TYPE_RAW) { - mqc_flush(mqc); - correction = 1; - /* correction = mqc_bypass_flush_enc(); */ - } else { /* correction = mqc_restart_enc(); */ - mqc_flush(mqc); - correction = 1; - } - pass->term = 1; - } else { - if (((bpno < (cblk->numbps - 4) && (passtype > 0)) - || ((bpno == (cblk->numbps - 4)) && (passtype == 2))) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) { - if (type == T1_TYPE_RAW) { - mqc_flush(mqc); - correction = 1; - /* correction = mqc_bypass_flush_enc(); */ - } else { /* correction = mqc_restart_enc(); */ - mqc_flush(mqc); - correction = 1; - } - pass->term = 1; - } else { - pass->term = 0; - } - } - - if (++passtype == 3) { - passtype = 0; - bpno--; - } - - if (pass->term && bpno > 0) { - type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; - if (type == T1_TYPE_RAW) - mqc_bypass_init_enc(mqc); - else - mqc_restart_init_enc(mqc); - } - - pass->distortiondec = cumwmsedec; - pass->rate = mqc_numbytes(mqc) + correction; /* FIXME */ - - /* Code-switch "RESET" */ - if (cblksty & J2K_CCP_CBLKSTY_RESET) - mqc_reset_enc(mqc); - } - - /* Code switch "ERTERM" (i.e. PTERM) */ - if (cblksty & J2K_CCP_CBLKSTY_PTERM) - mqc_erterm_enc(mqc); - else /* Default coding */ if (!(cblksty & J2K_CCP_CBLKSTY_LAZY)) - mqc_flush(mqc); - - cblk->totalpasses = passno; - - for (passno = 0; passnototalpasses; passno++) { - opj_tcd_pass_t *pass = &cblk->passes[passno]; - if (pass->rate > mqc_numbytes(mqc)) - pass->rate = mqc_numbytes(mqc); - /*Preventing generation of FF as last data byte of a pass*/ - if((pass->rate>1) && (cblk->data[pass->rate - 1] == 0xFF)){ - pass->rate--; - } - pass->len = pass->rate - (passno == 0 ? 0 : cblk->passes[passno - 1].rate); - } -} - -static void t1_decode_cblk( - opj_t1_t *t1, - opj_tcd_cblk_dec_t* cblk, - int orient, - int roishift, - int cblksty) -{ - opj_raw_t *raw = t1->raw; /* RAW component */ - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - int bpno, passtype; - int segno, passno; - char type = T1_TYPE_MQ; /* BYPASS mode */ - - if(!allocate_buffers( - t1, - cblk->x1 - cblk->x0, - cblk->y1 - cblk->y0)) - { - return; - } - - bpno = roishift + cblk->numbps - 1; - passtype = 2; - - mqc_resetstates(mqc); - mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); - mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); - mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); - - for (segno = 0; segno < cblk->numsegs; ++segno) { - opj_tcd_seg_t *seg = &cblk->segs[segno]; - - /* BYPASS mode */ - type = ((bpno <= (cblk->numbps - 1) - 4) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; - /* FIXME: slviewer gets here with a null pointer. Why? Partially downloaded and/or corrupt textures? */ - if(seg->data == NULL){ - continue; - } - if (type == T1_TYPE_RAW) { - raw_init_dec(raw, (*seg->data) + seg->dataindex, seg->len); - } else { - mqc_init_dec(mqc, (*seg->data) + seg->dataindex, seg->len); - } - - for (passno = 0; passno < seg->numpasses; ++passno) { - switch (passtype) { - case 0: - if (type == T1_TYPE_RAW) { - t1_dec_sigpass_raw(t1, bpno+1, orient, cblksty); - } else { - if (cblksty & J2K_CCP_CBLKSTY_VSC) { - t1_dec_sigpass_mqc_vsc(t1, bpno+1, orient); - } else { - t1_dec_sigpass_mqc(t1, bpno+1, orient); - } - } - break; - case 1: - if (type == T1_TYPE_RAW) { - t1_dec_refpass_raw(t1, bpno+1, cblksty); - } else { - if (cblksty & J2K_CCP_CBLKSTY_VSC) { - t1_dec_refpass_mqc_vsc(t1, bpno+1); - } else { - t1_dec_refpass_mqc(t1, bpno+1); - } - } - break; - case 2: - t1_dec_clnpass(t1, bpno+1, orient, cblksty); - break; - } - - if ((cblksty & J2K_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) { - mqc_resetstates(mqc); - mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); - mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); - mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); - } - if (++passtype == 3) { - passtype = 0; - bpno--; - } - } - } -} - -/* ----------------------------------------------------------------------- */ - -opj_t1_t* t1_create(opj_common_ptr cinfo) { - opj_t1_t *t1 = (opj_t1_t*) opj_malloc(sizeof(opj_t1_t)); - if(!t1) - return NULL; - - t1->cinfo = cinfo; - /* create MQC and RAW handles */ - t1->mqc = mqc_create(); - t1->raw = raw_create(); - - t1->data=NULL; - t1->flags=NULL; - t1->datasize=0; - t1->flagssize=0; - - return t1; -} - -void t1_destroy(opj_t1_t *t1) { - if(t1) { - /* destroy MQC and RAW handles */ - mqc_destroy(t1->mqc); - raw_destroy(t1->raw); - opj_aligned_free(t1->data); - opj_aligned_free(t1->flags); - opj_free(t1); - } -} - -void t1_encode_cblks( - opj_t1_t *t1, - opj_tcd_tile_t *tile, - opj_tcp_t *tcp) -{ - int compno, resno, bandno, precno, cblkno; - - tile->distotile = 0; /* fixed_quality */ - - for (compno = 0; compno < tile->numcomps; ++compno) { - opj_tcd_tilecomp_t* tilec = &tile->comps[compno]; - opj_tccp_t* tccp = &tcp->tccps[compno]; - int tile_w = tilec->x1 - tilec->x0; - - for (resno = 0; resno < tilec->numresolutions; ++resno) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - - for (bandno = 0; bandno < res->numbands; ++bandno) { - opj_tcd_band_t* restrict band = &res->bands[bandno]; - int bandconst = 8192 * 8192 / ((int) floor(band->stepsize * 8192)); - - for (precno = 0; precno < res->pw * res->ph; ++precno) { - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - for (cblkno = 0; cblkno < prc->cw * prc->ch; ++cblkno) { - opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; - int* restrict datap; - int* restrict tiledp; - int cblk_w; - int cblk_h; - int i, j; - - int x = cblk->x0 - band->x0; - int y = cblk->y0 - band->y0; - if (band->bandno & 1) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x += pres->x1 - pres->x0; - } - if (band->bandno & 2) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - y += pres->y1 - pres->y0; - } - - if(!allocate_buffers( - t1, - cblk->x1 - cblk->x0, - cblk->y1 - cblk->y0)) - { - return; - } - - datap=t1->data; - cblk_w = t1->w; - cblk_h = t1->h; - - tiledp=&tilec->data[(y * tile_w) + x]; - if (tccp->qmfbid == 1) { - for (j = 0; j < cblk_h; ++j) { - for (i = 0; i < cblk_w; ++i) { - int tmp = tiledp[(j * tile_w) + i]; - datap[(j * cblk_w) + i] = tmp << T1_NMSEDEC_FRACBITS; - } - } - } else { /* if (tccp->qmfbid == 0) */ - for (j = 0; j < cblk_h; ++j) { - for (i = 0; i < cblk_w; ++i) { - int tmp = tiledp[(j * tile_w) + i]; - datap[(j * cblk_w) + i] = - fix_mul( - tmp, - bandconst) >> (11 - T1_NMSEDEC_FRACBITS); - } - } - } - - t1_encode_cblk( - t1, - cblk, - band->bandno, - compno, - tilec->numresolutions - 1 - resno, - tccp->qmfbid, - band->stepsize, - tccp->cblksty, - tile->numcomps, - tcp->mct, - tile); - - } /* cblkno */ - } /* precno */ - } /* bandno */ - } /* resno */ - } /* compno */ -} - -void t1_decode_cblks( - opj_t1_t* t1, - opj_tcd_tilecomp_t* tilec, - opj_tccp_t* tccp) -{ - int resno, bandno, precno, cblkno; - - int tile_w = tilec->x1 - tilec->x0; - - for (resno = 0; resno < tilec->numresolutions; ++resno) { - opj_tcd_resolution_t* res = &tilec->resolutions[resno]; - - for (bandno = 0; bandno < res->numbands; ++bandno) { - opj_tcd_band_t* restrict band = &res->bands[bandno]; - - for (precno = 0; precno < res->pw * res->ph; ++precno) { - opj_tcd_precinct_t* precinct = &band->precincts[precno]; - - for (cblkno = 0; cblkno < precinct->cw * precinct->ch; ++cblkno) { - opj_tcd_cblk_dec_t* cblk = &precinct->cblks.dec[cblkno]; - int* restrict datap; - int cblk_w, cblk_h; - int x, y; - int i, j; - - t1_decode_cblk( - t1, - cblk, - band->bandno, - tccp->roishift, - tccp->cblksty); - - x = cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - if (band->bandno & 1) { - opj_tcd_resolution_t* pres = &tilec->resolutions[resno - 1]; - x += pres->x1 - pres->x0; - } - if (band->bandno & 2) { - opj_tcd_resolution_t* pres = &tilec->resolutions[resno - 1]; - y += pres->y1 - pres->y0; - } - - datap=t1->data; - cblk_w = t1->w; - cblk_h = t1->h; - - if (tccp->roishift) { - int thresh = 1 << tccp->roishift; - for (j = 0; j < cblk_h; ++j) { - for (i = 0; i < cblk_w; ++i) { - int val = datap[(j * cblk_w) + i]; - int mag = abs(val); - if (mag >= thresh) { - mag >>= tccp->roishift; - datap[(j * cblk_w) + i] = val < 0 ? -mag : mag; - } - } - } - } - - if (tccp->qmfbid == 1) { - int* restrict tiledp = &tilec->data[(y * tile_w) + x]; - for (j = 0; j < cblk_h; ++j) { - for (i = 0; i < cblk_w; ++i) { - int tmp = datap[(j * cblk_w) + i]; - ((int*)tiledp)[(j * tile_w) + i] = tmp / 2; - } - } - } else { /* if (tccp->qmfbid == 0) */ - float* restrict tiledp = (float*) &tilec->data[(y * tile_w) + x]; - for (j = 0; j < cblk_h; ++j) { - float* restrict tiledp2 = tiledp; - for (i = 0; i < cblk_w; ++i) { - float tmp = *datap * band->stepsize; - *tiledp2 = tmp; - datap++; - tiledp2++; - } - tiledp += tile_w; - } - } - opj_free(cblk->data); - opj_free(cblk->segs); - } /* cblkno */ - opj_free(precinct->cblks.dec); - precinct->cblks.dec = NULL; - } /* precno */ - } /* bandno */ - } /* resno */ -} - +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2007, Callum Lerwick + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" +#include "t1_luts.h" + +/** @defgroup T1 T1 - Implementation of the tier-1 coding */ +/*@{*/ + +/** @name Local static functions */ +/*@{*/ + +static INLINE char t1_getctxno_zc(int f, int orient); +static char t1_getctxno_sc(int f); +static INLINE int t1_getctxno_mag(int f); +static char t1_getspb(int f); +static short t1_getnmsedec_sig(int x, int bitpos); +static short t1_getnmsedec_ref(int x, int bitpos); +static void t1_updateflags(flag_t *flagsp, int s, int stride); +/** +Encode significant pass +*/ +static void t1_enc_sigpass_step( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int bpno, + int one, + int *nmsedec, + char type, + int vsc); +/** +Decode significant pass +*/ +static INLINE void t1_dec_sigpass_step_raw( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int oneplushalf, + int vsc); +static INLINE void t1_dec_sigpass_step_mqc( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int oneplushalf); +static INLINE void t1_dec_sigpass_step_mqc_vsc( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int oneplushalf, + int vsc); +/** +Encode significant pass +*/ +static void t1_enc_sigpass( + opj_t1_t *t1, + int bpno, + int orient, + int *nmsedec, + char type, + int cblksty); +/** +Decode significant pass +*/ +static void t1_dec_sigpass_raw( + opj_t1_t *t1, + int bpno, + int orient, + int cblksty); +static void t1_dec_sigpass_mqc( + opj_t1_t *t1, + int bpno, + int orient); +static void t1_dec_sigpass_mqc_vsc( + opj_t1_t *t1, + int bpno, + int orient); +/** +Encode refinement pass +*/ +static void t1_enc_refpass_step( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int bpno, + int one, + int *nmsedec, + char type, + int vsc); +/** +Decode refinement pass +*/ +static INLINE void t1_dec_refpass_step_raw( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int poshalf, + int neghalf, + int vsc); +static INLINE void t1_dec_refpass_step_mqc( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int poshalf, + int neghalf); +static INLINE void t1_dec_refpass_step_mqc_vsc( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int poshalf, + int neghalf, + int vsc); + +/** +Encode refinement pass +*/ +static void t1_enc_refpass( + opj_t1_t *t1, + int bpno, + int *nmsedec, + char type, + int cblksty); +/** +Decode refinement pass +*/ +static void t1_dec_refpass_raw( + opj_t1_t *t1, + int bpno, + int cblksty); +static void t1_dec_refpass_mqc( + opj_t1_t *t1, + int bpno); +static void t1_dec_refpass_mqc_vsc( + opj_t1_t *t1, + int bpno); +/** +Encode clean-up pass +*/ +static void t1_enc_clnpass_step( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int bpno, + int one, + int *nmsedec, + int partial, + int vsc); +/** +Decode clean-up pass +*/ +static void t1_dec_clnpass_step_partial( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int oneplushalf); +static void t1_dec_clnpass_step( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int oneplushalf); +static void t1_dec_clnpass_step_vsc( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int oneplushalf, + int partial, + int vsc); +/** +Encode clean-up pass +*/ +static void t1_enc_clnpass( + opj_t1_t *t1, + int bpno, + int orient, + int *nmsedec, + int cblksty); +/** +Decode clean-up pass +*/ +static void t1_dec_clnpass( + opj_t1_t *t1, + int bpno, + int orient, + int cblksty); +static double t1_getwmsedec( + int nmsedec, + int compno, + int level, + int orient, + int bpno, + int qmfbid, + double stepsize, + int numcomps, + int mct); +/** +Encode 1 code-block +@param t1 T1 handle +@param cblk Code-block coding parameters +@param orient +@param compno Component number +@param level +@param qmfbid +@param stepsize +@param cblksty Code-block style +@param numcomps +@param mct +@param tile +*/ +static void t1_encode_cblk( + opj_t1_t *t1, + opj_tcd_cblk_enc_t* cblk, + int orient, + int compno, + int level, + int qmfbid, + double stepsize, + int cblksty, + int numcomps, + int mct, + opj_tcd_tile_t * tile); +/** +Decode 1 code-block +@param t1 T1 handle +@param cblk Code-block coding parameters +@param orient +@param roishift Region of interest shifting value +@param cblksty Code-block style +*/ +static void t1_decode_cblk( + opj_t1_t *t1, + opj_tcd_cblk_dec_t* cblk, + int orient, + int roishift, + int cblksty); + +/*@}*/ + +/*@}*/ + +/* ----------------------------------------------------------------------- */ + +static char t1_getctxno_zc(int f, int orient) { + return lut_ctxno_zc[(orient << 8) | (f & T1_SIG_OTH)]; +} + +static char t1_getctxno_sc(int f) { + return lut_ctxno_sc[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; +} + +static int t1_getctxno_mag(int f) { + int tmp1 = (f & T1_SIG_OTH) ? T1_CTXNO_MAG + 1 : T1_CTXNO_MAG; + int tmp2 = (f & T1_REFINE) ? T1_CTXNO_MAG + 2 : tmp1; + return (tmp2); +} + +static char t1_getspb(int f) { + return lut_spb[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; +} + +static short t1_getnmsedec_sig(int x, int bitpos) { + if (bitpos > T1_NMSEDEC_FRACBITS) { + return lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; + } + + return lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; +} + +static short t1_getnmsedec_ref(int x, int bitpos) { + if (bitpos > T1_NMSEDEC_FRACBITS) { + return lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; + } + + return lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; +} + +static void t1_updateflags(flag_t *flagsp, int s, int stride) { + flag_t *np = flagsp - stride; + flag_t *sp = flagsp + stride; + + static const flag_t mod[] = { + T1_SIG_S, T1_SIG_S|T1_SGN_S, + T1_SIG_E, T1_SIG_E|T1_SGN_E, + T1_SIG_W, T1_SIG_W|T1_SGN_W, + T1_SIG_N, T1_SIG_N|T1_SGN_N + }; + + np[-1] |= T1_SIG_SE; + np[0] |= mod[s]; + np[1] |= T1_SIG_SW; + + flagsp[-1] |= mod[s+2]; + flagsp[0] |= T1_SIG; + flagsp[1] |= mod[s+4]; + + sp[-1] |= T1_SIG_NE; + sp[0] |= mod[s+6]; + sp[1] |= T1_SIG_NW; +} + +static void t1_enc_sigpass_step( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int bpno, + int one, + int *nmsedec, + char type, + int vsc) +{ + int v, flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); + if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { + v = int_abs(*datap) & one ? 1 : 0; + mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); /* ESSAI */ + if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ + mqc_bypass_enc(mqc, v); + } else { + mqc_encode(mqc, v); + } + if (v) { + v = *datap < 0 ? 1 : 0; + *nmsedec += t1_getnmsedec_sig(int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS); + mqc_setcurctx(mqc, t1_getctxno_sc(flag)); /* ESSAI */ + if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ + mqc_bypass_enc(mqc, v); + } else { + mqc_encode(mqc, v ^ t1_getspb(flag)); + } + t1_updateflags(flagsp, v, t1->flags_stride); + } + *flagsp |= T1_VISIT; + } +} + +static INLINE void t1_dec_sigpass_step_raw( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int oneplushalf, + int vsc) +{ + int v, flag; + opj_raw_t *raw = t1->raw; /* RAW component */ + + OPJ_ARG_NOT_USED(orient); + + flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); + if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { + if (raw_decode(raw)) { + v = raw_decode(raw); /* ESSAI */ + *datap = v ? -oneplushalf : oneplushalf; + t1_updateflags(flagsp, v, t1->flags_stride); + } + *flagsp |= T1_VISIT; + } +} /* VSC and BYPASS by Antonin */ + +static INLINE void t1_dec_sigpass_step_mqc( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int oneplushalf) +{ + int v, flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = *flagsp; + if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { + mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); + if (mqc_decode(mqc)) { + mqc_setcurctx(mqc, t1_getctxno_sc(flag)); + v = mqc_decode(mqc) ^ t1_getspb(flag); + *datap = v ? -oneplushalf : oneplushalf; + t1_updateflags(flagsp, v, t1->flags_stride); + } + *flagsp |= T1_VISIT; + } +} /* VSC and BYPASS by Antonin */ + +static INLINE void t1_dec_sigpass_step_mqc_vsc( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int oneplushalf, + int vsc) +{ + int v, flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); + if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { + mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); + if (mqc_decode(mqc)) { + mqc_setcurctx(mqc, t1_getctxno_sc(flag)); + v = mqc_decode(mqc) ^ t1_getspb(flag); + *datap = v ? -oneplushalf : oneplushalf; + t1_updateflags(flagsp, v, t1->flags_stride); + } + *flagsp |= T1_VISIT; + } +} /* VSC and BYPASS by Antonin */ + +static void t1_enc_sigpass( + opj_t1_t *t1, + int bpno, + int orient, + int *nmsedec, + char type, + int cblksty) +{ + int i, j, k, one, vsc; + *nmsedec = 0; + one = 1 << (bpno + T1_NMSEDEC_FRACBITS); + for (k = 0; k < t1->h; k += 4) { + for (i = 0; i < t1->w; ++i) { + for (j = k; j < k + 4 && j < t1->h; ++j) { + vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; + t1_enc_sigpass_step( + t1, + &t1->flags[((j+1) * t1->flags_stride) + i + 1], + &t1->data[(j * t1->w) + i], + orient, + bpno, + one, + nmsedec, + type, + vsc); + } + } + } +} + +static void t1_dec_sigpass_raw( + opj_t1_t *t1, + int bpno, + int orient, + int cblksty) +{ + int i, j, k, one, half, oneplushalf, vsc; + one = 1 << bpno; + half = one >> 1; + oneplushalf = one | half; + for (k = 0; k < t1->h; k += 4) { + for (i = 0; i < t1->w; ++i) { + for (j = k; j < k + 4 && j < t1->h; ++j) { + vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; + t1_dec_sigpass_step_raw( + t1, + &t1->flags[((j+1) * t1->flags_stride) + i + 1], + &t1->data[(j * t1->w) + i], + orient, + oneplushalf, + vsc); + } + } + } +} /* VSC and BYPASS by Antonin */ + +static void t1_dec_sigpass_mqc( + opj_t1_t *t1, + int bpno, + int orient) +{ + int i, j, k, one, half, oneplushalf; + int *data1 = t1->data; + flag_t *flags1 = &t1->flags[1]; + one = 1 << bpno; + half = one >> 1; + oneplushalf = one | half; + for (k = 0; k < (t1->h & ~3); k += 4) { + for (i = 0; i < t1->w; ++i) { + int *data2 = data1 + i; + flag_t *flags2 = flags1 + i; + flags2 += t1->flags_stride; + t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); + data2 += t1->w; + flags2 += t1->flags_stride; + t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); + data2 += t1->w; + flags2 += t1->flags_stride; + t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); + data2 += t1->w; + flags2 += t1->flags_stride; + t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); + data2 += t1->w; + } + data1 += t1->w << 2; + flags1 += t1->flags_stride << 2; + } + for (i = 0; i < t1->w; ++i) { + int *data2 = data1 + i; + flag_t *flags2 = flags1 + i; + for (j = k; j < t1->h; ++j) { + flags2 += t1->flags_stride; + t1_dec_sigpass_step_mqc(t1, flags2, data2, orient, oneplushalf); + data2 += t1->w; + } + } +} /* VSC and BYPASS by Antonin */ + +static void t1_dec_sigpass_mqc_vsc( + opj_t1_t *t1, + int bpno, + int orient) +{ + int i, j, k, one, half, oneplushalf, vsc; + one = 1 << bpno; + half = one >> 1; + oneplushalf = one | half; + for (k = 0; k < t1->h; k += 4) { + for (i = 0; i < t1->w; ++i) { + for (j = k; j < k + 4 && j < t1->h; ++j) { + vsc = (j == k + 3 || j == t1->h - 1) ? 1 : 0; + t1_dec_sigpass_step_mqc_vsc( + t1, + &t1->flags[((j+1) * t1->flags_stride) + i + 1], + &t1->data[(j * t1->w) + i], + orient, + oneplushalf, + vsc); + } + } + } +} /* VSC and BYPASS by Antonin */ + +static void t1_enc_refpass_step( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int bpno, + int one, + int *nmsedec, + char type, + int vsc) +{ + int v, flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); + if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { + *nmsedec += t1_getnmsedec_ref(int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS); + v = int_abs(*datap) & one ? 1 : 0; + mqc_setcurctx(mqc, t1_getctxno_mag(flag)); /* ESSAI */ + if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ + mqc_bypass_enc(mqc, v); + } else { + mqc_encode(mqc, v); + } + *flagsp |= T1_REFINE; + } +} + +static INLINE void t1_dec_refpass_step_raw( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int poshalf, + int neghalf, + int vsc) +{ + int v, t, flag; + + opj_raw_t *raw = t1->raw; /* RAW component */ + + flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); + if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { + v = raw_decode(raw); + t = v ? poshalf : neghalf; + *datap += *datap < 0 ? -t : t; + *flagsp |= T1_REFINE; + } +} /* VSC and BYPASS by Antonin */ + +static INLINE void t1_dec_refpass_step_mqc( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int poshalf, + int neghalf) +{ + int v, t, flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = *flagsp; + if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { + mqc_setcurctx(mqc, t1_getctxno_mag(flag)); /* ESSAI */ + v = mqc_decode(mqc); + t = v ? poshalf : neghalf; + *datap += *datap < 0 ? -t : t; + *flagsp |= T1_REFINE; + } +} /* VSC and BYPASS by Antonin */ + +static INLINE void t1_dec_refpass_step_mqc_vsc( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int poshalf, + int neghalf, + int vsc) +{ + int v, t, flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); + if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { + mqc_setcurctx(mqc, t1_getctxno_mag(flag)); /* ESSAI */ + v = mqc_decode(mqc); + t = v ? poshalf : neghalf; + *datap += *datap < 0 ? -t : t; + *flagsp |= T1_REFINE; + } +} /* VSC and BYPASS by Antonin */ + +static void t1_enc_refpass( + opj_t1_t *t1, + int bpno, + int *nmsedec, + char type, + int cblksty) +{ + int i, j, k, one, vsc; + *nmsedec = 0; + one = 1 << (bpno + T1_NMSEDEC_FRACBITS); + for (k = 0; k < t1->h; k += 4) { + for (i = 0; i < t1->w; ++i) { + for (j = k; j < k + 4 && j < t1->h; ++j) { + vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; + t1_enc_refpass_step( + t1, + &t1->flags[((j+1) * t1->flags_stride) + i + 1], + &t1->data[(j * t1->w) + i], + bpno, + one, + nmsedec, + type, + vsc); + } + } + } +} + +static void t1_dec_refpass_raw( + opj_t1_t *t1, + int bpno, + int cblksty) +{ + int i, j, k, one, poshalf, neghalf; + int vsc; + one = 1 << bpno; + poshalf = one >> 1; + neghalf = bpno > 0 ? -poshalf : -1; + for (k = 0; k < t1->h; k += 4) { + for (i = 0; i < t1->w; ++i) { + for (j = k; j < k + 4 && j < t1->h; ++j) { + vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; + t1_dec_refpass_step_raw( + t1, + &t1->flags[((j+1) * t1->flags_stride) + i + 1], + &t1->data[(j * t1->w) + i], + poshalf, + neghalf, + vsc); + } + } + } +} /* VSC and BYPASS by Antonin */ + +static void t1_dec_refpass_mqc( + opj_t1_t *t1, + int bpno) +{ + int i, j, k, one, poshalf, neghalf; + int *data1 = t1->data; + flag_t *flags1 = &t1->flags[1]; + one = 1 << bpno; + poshalf = one >> 1; + neghalf = bpno > 0 ? -poshalf : -1; + for (k = 0; k < (t1->h & ~3); k += 4) { + for (i = 0; i < t1->w; ++i) { + int *data2 = data1 + i; + flag_t *flags2 = flags1 + i; + flags2 += t1->flags_stride; + t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); + data2 += t1->w; + flags2 += t1->flags_stride; + t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); + data2 += t1->w; + flags2 += t1->flags_stride; + t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); + data2 += t1->w; + flags2 += t1->flags_stride; + t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); + data2 += t1->w; + } + data1 += t1->w << 2; + flags1 += t1->flags_stride << 2; + } + for (i = 0; i < t1->w; ++i) { + int *data2 = data1 + i; + flag_t *flags2 = flags1 + i; + for (j = k; j < t1->h; ++j) { + flags2 += t1->flags_stride; + t1_dec_refpass_step_mqc(t1, flags2, data2, poshalf, neghalf); + data2 += t1->w; + } + } +} /* VSC and BYPASS by Antonin */ + +static void t1_dec_refpass_mqc_vsc( + opj_t1_t *t1, + int bpno) +{ + int i, j, k, one, poshalf, neghalf; + int vsc; + one = 1 << bpno; + poshalf = one >> 1; + neghalf = bpno > 0 ? -poshalf : -1; + for (k = 0; k < t1->h; k += 4) { + for (i = 0; i < t1->w; ++i) { + for (j = k; j < k + 4 && j < t1->h; ++j) { + vsc = ((j == k + 3 || j == t1->h - 1)) ? 1 : 0; + t1_dec_refpass_step_mqc_vsc( + t1, + &t1->flags[((j+1) * t1->flags_stride) + i + 1], + &t1->data[(j * t1->w) + i], + poshalf, + neghalf, + vsc); + } + } + } +} /* VSC and BYPASS by Antonin */ + +static void t1_enc_clnpass_step( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int bpno, + int one, + int *nmsedec, + int partial, + int vsc) +{ + int v, flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); + if (partial) { + goto LABEL_PARTIAL; + } + if (!(*flagsp & (T1_SIG | T1_VISIT))) { + mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); + v = int_abs(*datap) & one ? 1 : 0; + mqc_encode(mqc, v); + if (v) { +LABEL_PARTIAL: + *nmsedec += t1_getnmsedec_sig(int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS); + mqc_setcurctx(mqc, t1_getctxno_sc(flag)); + v = *datap < 0 ? 1 : 0; + mqc_encode(mqc, v ^ t1_getspb(flag)); + t1_updateflags(flagsp, v, t1->flags_stride); + } + } + *flagsp &= ~T1_VISIT; +} + +static void t1_dec_clnpass_step_partial( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int oneplushalf) +{ + int v, flag; + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + OPJ_ARG_NOT_USED(orient); + + flag = *flagsp; + mqc_setcurctx(mqc, t1_getctxno_sc(flag)); + v = mqc_decode(mqc) ^ t1_getspb(flag); + *datap = v ? -oneplushalf : oneplushalf; + t1_updateflags(flagsp, v, t1->flags_stride); + *flagsp &= ~T1_VISIT; +} /* VSC and BYPASS by Antonin */ + +static void t1_dec_clnpass_step( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int oneplushalf) +{ + int v, flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = *flagsp; + if (!(flag & (T1_SIG | T1_VISIT))) { + mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); + if (mqc_decode(mqc)) { + mqc_setcurctx(mqc, t1_getctxno_sc(flag)); + v = mqc_decode(mqc) ^ t1_getspb(flag); + *datap = v ? -oneplushalf : oneplushalf; + t1_updateflags(flagsp, v, t1->flags_stride); + } + } + *flagsp &= ~T1_VISIT; +} /* VSC and BYPASS by Antonin */ + +static void t1_dec_clnpass_step_vsc( + opj_t1_t *t1, + flag_t *flagsp, + int *datap, + int orient, + int oneplushalf, + int partial, + int vsc) +{ + int v, flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); + if (partial) { + goto LABEL_PARTIAL; + } + if (!(flag & (T1_SIG | T1_VISIT))) { + mqc_setcurctx(mqc, t1_getctxno_zc(flag, orient)); + if (mqc_decode(mqc)) { +LABEL_PARTIAL: + mqc_setcurctx(mqc, t1_getctxno_sc(flag)); + v = mqc_decode(mqc) ^ t1_getspb(flag); + *datap = v ? -oneplushalf : oneplushalf; + t1_updateflags(flagsp, v, t1->flags_stride); + } + } + *flagsp &= ~T1_VISIT; +} + +static void t1_enc_clnpass( + opj_t1_t *t1, + int bpno, + int orient, + int *nmsedec, + int cblksty) +{ + int i, j, k, one, agg, runlen, vsc; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + *nmsedec = 0; + one = 1 << (bpno + T1_NMSEDEC_FRACBITS); + for (k = 0; k < t1->h; k += 4) { + for (i = 0; i < t1->w; ++i) { + if (k + 3 < t1->h) { + if (cblksty & J2K_CCP_CBLKSTY_VSC) { + agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || (MACRO_t1_flags(1 + k + 3,1 + i) + & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); + } else { + agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || MACRO_t1_flags(1 + k + 3,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); + } + } else { + agg = 0; + } + if (agg) { + for (runlen = 0; runlen < 4; ++runlen) { + if (int_abs(t1->data[((k + runlen)*t1->w) + i]) & one) + break; + } + mqc_setcurctx(mqc, T1_CTXNO_AGG); + mqc_encode(mqc, runlen != 4); + if (runlen == 4) { + continue; + } + mqc_setcurctx(mqc, T1_CTXNO_UNI); + mqc_encode(mqc, runlen >> 1); + mqc_encode(mqc, runlen & 1); + } else { + runlen = 0; + } + for (j = k + runlen; j < k + 4 && j < t1->h; ++j) { + vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == t1->h - 1)) ? 1 : 0; + t1_enc_clnpass_step( + t1, + &t1->flags[((j+1) * t1->flags_stride) + i + 1], + &t1->data[(j * t1->w) + i], + orient, + bpno, + one, + nmsedec, + agg && (j == k + runlen), + vsc); + } + } + } +} + +static void t1_dec_clnpass( + opj_t1_t *t1, + int bpno, + int orient, + int cblksty) +{ + int i, j, k, one, half, oneplushalf, agg, runlen, vsc; + int segsym = cblksty & J2K_CCP_CBLKSTY_SEGSYM; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + one = 1 << bpno; + half = one >> 1; + oneplushalf = one | half; + if (cblksty & J2K_CCP_CBLKSTY_VSC) { + for (k = 0; k < t1->h; k += 4) { + for (i = 0; i < t1->w; ++i) { + if (k + 3 < t1->h) { + agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || (MACRO_t1_flags(1 + k + 3,1 + i) + & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); + } else { + agg = 0; + } + if (agg) { + mqc_setcurctx(mqc, T1_CTXNO_AGG); + if (!mqc_decode(mqc)) { + continue; + } + mqc_setcurctx(mqc, T1_CTXNO_UNI); + runlen = mqc_decode(mqc); + runlen = (runlen << 1) | mqc_decode(mqc); + } else { + runlen = 0; + } + for (j = k + runlen; j < k + 4 && j < t1->h; ++j) { + vsc = (j == k + 3 || j == t1->h - 1) ? 1 : 0; + t1_dec_clnpass_step_vsc( + t1, + &t1->flags[((j+1) * t1->flags_stride) + i + 1], + &t1->data[(j * t1->w) + i], + orient, + oneplushalf, + agg && (j == k + runlen), + vsc); + } + } + } + } else { + int *data1 = t1->data; + flag_t *flags1 = &t1->flags[1]; + for (k = 0; k < (t1->h & ~3); k += 4) { + for (i = 0; i < t1->w; ++i) { + int *data2 = data1 + i; + flag_t *flags2 = flags1 + i; + agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || MACRO_t1_flags(1 + k + 3,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); + if (agg) { + mqc_setcurctx(mqc, T1_CTXNO_AGG); + if (!mqc_decode(mqc)) { + continue; + } + mqc_setcurctx(mqc, T1_CTXNO_UNI); + runlen = mqc_decode(mqc); + runlen = (runlen << 1) | mqc_decode(mqc); + flags2 += runlen * t1->flags_stride; + data2 += runlen * t1->w; + for (j = k + runlen; j < k + 4 && j < t1->h; ++j) { + flags2 += t1->flags_stride; + if (agg && (j == k + runlen)) { + t1_dec_clnpass_step_partial(t1, flags2, data2, orient, oneplushalf); + } else { + t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); + } + data2 += t1->w; + } + } else { + flags2 += t1->flags_stride; + t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); + data2 += t1->w; + flags2 += t1->flags_stride; + t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); + data2 += t1->w; + flags2 += t1->flags_stride; + t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); + data2 += t1->w; + flags2 += t1->flags_stride; + t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); + data2 += t1->w; + } + } + data1 += t1->w << 2; + flags1 += t1->flags_stride << 2; + } + for (i = 0; i < t1->w; ++i) { + int *data2 = data1 + i; + flag_t *flags2 = flags1 + i; + for (j = k; j < t1->h; ++j) { + flags2 += t1->flags_stride; + t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); + data2 += t1->w; + } + } + } + + if (segsym) { + int v = 0; + mqc_setcurctx(mqc, T1_CTXNO_UNI); + v = mqc_decode(mqc); + v = (v << 1) | mqc_decode(mqc); + v = (v << 1) | mqc_decode(mqc); + v = (v << 1) | mqc_decode(mqc); + /* + if (v!=0xa) { + opj_event_msg(t1->cinfo, EVT_WARNING, "Bad segmentation symbol %x\n", v); + } + */ + } +} /* VSC and BYPASS by Antonin */ + + +/** mod fixed_quality */ +static double t1_getwmsedec( + int nmsedec, + int compno, + int level, + int orient, + int bpno, + int qmfbid, + double stepsize, + int numcomps, + int mct) +{ + double w1, w2, wmsedec; + if (qmfbid == 1) { + w1 = (mct && numcomps==3) ? mct_getnorm(compno) : 1.0; + w2 = dwt_getnorm(level, orient); + } else { /* if (qmfbid == 0) */ + w1 = (mct && numcomps==3) ? mct_getnorm_real(compno) : 1.0; + w2 = dwt_getnorm_real(level, orient); + } + wmsedec = w1 * w2 * stepsize * (1 << bpno); + wmsedec *= wmsedec * nmsedec / 8192.0; + + return wmsedec; +} + +static opj_bool allocate_buffers( + opj_t1_t *t1, + int w, + int h) +{ + int datasize=w * h; + int flagssize; + + if(datasize > t1->datasize){ + opj_aligned_free(t1->data); + t1->data = (int*) opj_aligned_malloc(datasize * sizeof(int)); + if(!t1->data){ + return OPJ_FALSE; + } + t1->datasize=datasize; + } + memset(t1->data,0,datasize * sizeof(int)); + + t1->flags_stride=w+2; + flagssize=t1->flags_stride * (h+2); + + if(flagssize > t1->flagssize){ + opj_aligned_free(t1->flags); + t1->flags = (flag_t*) opj_aligned_malloc(flagssize * sizeof(flag_t)); + if(!t1->flags){ + return OPJ_FALSE; + } + t1->flagssize=flagssize; + } + memset(t1->flags,0,flagssize * sizeof(flag_t)); + + t1->w=w; + t1->h=h; + + return OPJ_TRUE; +} + +/** mod fixed_quality */ +static void t1_encode_cblk( + opj_t1_t *t1, + opj_tcd_cblk_enc_t* cblk, + int orient, + int compno, + int level, + int qmfbid, + double stepsize, + int cblksty, + int numcomps, + int mct, + opj_tcd_tile_t * tile) +{ + double cumwmsedec = 0.0; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + int passno, bpno, passtype; + int nmsedec = 0; + int i, max; + char type = T1_TYPE_MQ; + double tempwmsedec; + + max = 0; + for (i = 0; i < t1->w * t1->h; ++i) { + int tmp = abs(t1->data[i]); + max = int_max(max, tmp); + } + + cblk->numbps = max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0; + + bpno = cblk->numbps - 1; + passtype = 2; + + mqc_resetstates(mqc); + mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); + mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); + mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); + mqc_init_enc(mqc, cblk->data); + + for (passno = 0; bpno >= 0; ++passno) { + opj_tcd_pass_t *pass = &cblk->passes[passno]; + int correction = 3; + type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; + + switch (passtype) { + case 0: + t1_enc_sigpass(t1, bpno, orient, &nmsedec, type, cblksty); + break; + case 1: + t1_enc_refpass(t1, bpno, &nmsedec, type, cblksty); + break; + case 2: + t1_enc_clnpass(t1, bpno, orient, &nmsedec, cblksty); + /* code switch SEGMARK (i.e. SEGSYM) */ + if (cblksty & J2K_CCP_CBLKSTY_SEGSYM) + mqc_segmark_enc(mqc); + break; + } + + /* fixed_quality */ + tempwmsedec = t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps, mct); + cumwmsedec += tempwmsedec; + tile->distotile += tempwmsedec; + + /* Code switch "RESTART" (i.e. TERMALL) */ + if ((cblksty & J2K_CCP_CBLKSTY_TERMALL) && !((passtype == 2) && (bpno - 1 < 0))) { + if (type == T1_TYPE_RAW) { + mqc_flush(mqc); + correction = 1; + /* correction = mqc_bypass_flush_enc(); */ + } else { /* correction = mqc_restart_enc(); */ + mqc_flush(mqc); + correction = 1; + } + pass->term = 1; + } else { + if (((bpno < (cblk->numbps - 4) && (passtype > 0)) + || ((bpno == (cblk->numbps - 4)) && (passtype == 2))) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) { + if (type == T1_TYPE_RAW) { + mqc_flush(mqc); + correction = 1; + /* correction = mqc_bypass_flush_enc(); */ + } else { /* correction = mqc_restart_enc(); */ + mqc_flush(mqc); + correction = 1; + } + pass->term = 1; + } else { + pass->term = 0; + } + } + + if (++passtype == 3) { + passtype = 0; + bpno--; + } + + if (pass->term && bpno > 0) { + type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; + if (type == T1_TYPE_RAW) + mqc_bypass_init_enc(mqc); + else + mqc_restart_init_enc(mqc); + } + + pass->distortiondec = cumwmsedec; + pass->rate = mqc_numbytes(mqc) + correction; /* FIXME */ + + /* Code-switch "RESET" */ + if (cblksty & J2K_CCP_CBLKSTY_RESET) + mqc_reset_enc(mqc); + } + + /* Code switch "ERTERM" (i.e. PTERM) */ + if (cblksty & J2K_CCP_CBLKSTY_PTERM) + mqc_erterm_enc(mqc); + else /* Default coding */ if (!(cblksty & J2K_CCP_CBLKSTY_LAZY)) + mqc_flush(mqc); + + cblk->totalpasses = passno; + + for (passno = 0; passnototalpasses; passno++) { + opj_tcd_pass_t *pass = &cblk->passes[passno]; + if (pass->rate > mqc_numbytes(mqc)) + pass->rate = mqc_numbytes(mqc); + /*Preventing generation of FF as last data byte of a pass*/ + if((pass->rate>1) && (cblk->data[pass->rate - 1] == 0xFF)){ + pass->rate--; + } + pass->len = pass->rate - (passno == 0 ? 0 : cblk->passes[passno - 1].rate); + } +} + +static void t1_decode_cblk( + opj_t1_t *t1, + opj_tcd_cblk_dec_t* cblk, + int orient, + int roishift, + int cblksty) +{ + opj_raw_t *raw = t1->raw; /* RAW component */ + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + int bpno, passtype; + int segno, passno; + char type = T1_TYPE_MQ; /* BYPASS mode */ + + if(!allocate_buffers( + t1, + cblk->x1 - cblk->x0, + cblk->y1 - cblk->y0)) + { + return; + } + + bpno = roishift + cblk->numbps - 1; + passtype = 2; + + mqc_resetstates(mqc); + mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); + mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); + mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); + + for (segno = 0; segno < cblk->numsegs; ++segno) { + opj_tcd_seg_t *seg = &cblk->segs[segno]; + + /* BYPASS mode */ + type = ((bpno <= (cblk->numbps - 1) - 4) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; + /* FIXME: slviewer gets here with a null pointer. Why? Partially downloaded and/or corrupt textures? */ + if(seg->data == NULL){ + continue; + } + if (type == T1_TYPE_RAW) { + raw_init_dec(raw, (*seg->data) + seg->dataindex, seg->len); + } else { + mqc_init_dec(mqc, (*seg->data) + seg->dataindex, seg->len); + } + + for (passno = 0; passno < seg->numpasses; ++passno) { + switch (passtype) { + case 0: + if (type == T1_TYPE_RAW) { + t1_dec_sigpass_raw(t1, bpno+1, orient, cblksty); + } else { + if (cblksty & J2K_CCP_CBLKSTY_VSC) { + t1_dec_sigpass_mqc_vsc(t1, bpno+1, orient); + } else { + t1_dec_sigpass_mqc(t1, bpno+1, orient); + } + } + break; + case 1: + if (type == T1_TYPE_RAW) { + t1_dec_refpass_raw(t1, bpno+1, cblksty); + } else { + if (cblksty & J2K_CCP_CBLKSTY_VSC) { + t1_dec_refpass_mqc_vsc(t1, bpno+1); + } else { + t1_dec_refpass_mqc(t1, bpno+1); + } + } + break; + case 2: + t1_dec_clnpass(t1, bpno+1, orient, cblksty); + break; + } + + if ((cblksty & J2K_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) { + mqc_resetstates(mqc); + mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); + mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); + mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); + } + if (++passtype == 3) { + passtype = 0; + bpno--; + } + } + } +} + +/* ----------------------------------------------------------------------- */ + +opj_t1_t* t1_create(opj_common_ptr cinfo) { + opj_t1_t *t1 = (opj_t1_t*) opj_malloc(sizeof(opj_t1_t)); + if(!t1) + return NULL; + + t1->cinfo = cinfo; + /* create MQC and RAW handles */ + t1->mqc = mqc_create(); + t1->raw = raw_create(); + + t1->data=NULL; + t1->flags=NULL; + t1->datasize=0; + t1->flagssize=0; + + return t1; +} + +void t1_destroy(opj_t1_t *t1) { + if(t1) { + /* destroy MQC and RAW handles */ + mqc_destroy(t1->mqc); + raw_destroy(t1->raw); + opj_aligned_free(t1->data); + opj_aligned_free(t1->flags); + opj_free(t1); + } +} + +void t1_encode_cblks( + opj_t1_t *t1, + opj_tcd_tile_t *tile, + opj_tcp_t *tcp) +{ + int compno, resno, bandno, precno, cblkno; + + tile->distotile = 0; /* fixed_quality */ + + for (compno = 0; compno < tile->numcomps; ++compno) { + opj_tcd_tilecomp_t* tilec = &tile->comps[compno]; + opj_tccp_t* tccp = &tcp->tccps[compno]; + int tile_w = tilec->x1 - tilec->x0; + + for (resno = 0; resno < tilec->numresolutions; ++resno) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + + for (bandno = 0; bandno < res->numbands; ++bandno) { + opj_tcd_band_t* restrict band = &res->bands[bandno]; + int bandconst = 8192 * 8192 / ((int) floor(band->stepsize * 8192)); + + for (precno = 0; precno < res->pw * res->ph; ++precno) { + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + for (cblkno = 0; cblkno < prc->cw * prc->ch; ++cblkno) { + opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; + int* restrict datap; + int* restrict tiledp; + int cblk_w; + int cblk_h; + int i, j; + + int x = cblk->x0 - band->x0; + int y = cblk->y0 - band->y0; + if (band->bandno & 1) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x += pres->x1 - pres->x0; + } + if (band->bandno & 2) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + y += pres->y1 - pres->y0; + } + + if(!allocate_buffers( + t1, + cblk->x1 - cblk->x0, + cblk->y1 - cblk->y0)) + { + return; + } + + datap=t1->data; + cblk_w = t1->w; + cblk_h = t1->h; + + tiledp=&tilec->data[(y * tile_w) + x]; + if (tccp->qmfbid == 1) { + for (j = 0; j < cblk_h; ++j) { + for (i = 0; i < cblk_w; ++i) { + int tmp = tiledp[(j * tile_w) + i]; + datap[(j * cblk_w) + i] = tmp << T1_NMSEDEC_FRACBITS; + } + } + } else { /* if (tccp->qmfbid == 0) */ + for (j = 0; j < cblk_h; ++j) { + for (i = 0; i < cblk_w; ++i) { + int tmp = tiledp[(j * tile_w) + i]; + datap[(j * cblk_w) + i] = + fix_mul( + tmp, + bandconst) >> (11 - T1_NMSEDEC_FRACBITS); + } + } + } + + t1_encode_cblk( + t1, + cblk, + band->bandno, + compno, + tilec->numresolutions - 1 - resno, + tccp->qmfbid, + band->stepsize, + tccp->cblksty, + tile->numcomps, + tcp->mct, + tile); + + } /* cblkno */ + } /* precno */ + } /* bandno */ + } /* resno */ + } /* compno */ +} + +void t1_decode_cblks( + opj_t1_t* t1, + opj_tcd_tilecomp_t* tilec, + opj_tccp_t* tccp) +{ + int resno, bandno, precno, cblkno; + + int tile_w = tilec->x1 - tilec->x0; + + for (resno = 0; resno < tilec->numresolutions; ++resno) { + opj_tcd_resolution_t* res = &tilec->resolutions[resno]; + + for (bandno = 0; bandno < res->numbands; ++bandno) { + opj_tcd_band_t* restrict band = &res->bands[bandno]; + + for (precno = 0; precno < res->pw * res->ph; ++precno) { + opj_tcd_precinct_t* precinct = &band->precincts[precno]; + + for (cblkno = 0; cblkno < precinct->cw * precinct->ch; ++cblkno) { + opj_tcd_cblk_dec_t* cblk = &precinct->cblks.dec[cblkno]; + int* restrict datap; + int cblk_w, cblk_h; + int x, y; + int i, j; + + t1_decode_cblk( + t1, + cblk, + band->bandno, + tccp->roishift, + tccp->cblksty); + + x = cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + if (band->bandno & 1) { + opj_tcd_resolution_t* pres = &tilec->resolutions[resno - 1]; + x += pres->x1 - pres->x0; + } + if (band->bandno & 2) { + opj_tcd_resolution_t* pres = &tilec->resolutions[resno - 1]; + y += pres->y1 - pres->y0; + } + + datap=t1->data; + cblk_w = t1->w; + cblk_h = t1->h; + + if (tccp->roishift) { + int thresh = 1 << tccp->roishift; + for (j = 0; j < cblk_h; ++j) { + for (i = 0; i < cblk_w; ++i) { + int val = datap[(j * cblk_w) + i]; + int mag = abs(val); + if (mag >= thresh) { + mag >>= tccp->roishift; + datap[(j * cblk_w) + i] = val < 0 ? -mag : mag; + } + } + } + } + + if (tccp->qmfbid == 1) { + int* restrict tiledp = &tilec->data[(y * tile_w) + x]; + for (j = 0; j < cblk_h; ++j) { + for (i = 0; i < cblk_w; ++i) { + int tmp = datap[(j * cblk_w) + i]; + ((int*)tiledp)[(j * tile_w) + i] = tmp / 2; + } + } + } else { /* if (tccp->qmfbid == 0) */ + float* restrict tiledp = (float*) &tilec->data[(y * tile_w) + x]; + for (j = 0; j < cblk_h; ++j) { + float* restrict tiledp2 = tiledp; + for (i = 0; i < cblk_w; ++i) { + float tmp = *datap * band->stepsize; + *tiledp2 = tmp; + datap++; + tiledp2++; + } + tiledp += tile_w; + } + } + opj_free(cblk->data); + opj_free(cblk->segs); + } /* cblkno */ + opj_free(precinct->cblks.dec); + precinct->cblks.dec = NULL; + } /* precno */ + } /* bandno */ + } /* resno */ +} + diff --git a/Source/LibOpenJPEG/t1.h b/Source/LibOpenJPEG/t1.h index 1c93fa7..572ec88 100644 --- a/Source/LibOpenJPEG/t1.h +++ b/Source/LibOpenJPEG/t1.h @@ -1,147 +1,147 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __T1_H -#define __T1_H -/** -@file t1.h -@brief Implementation of the tier-1 coding (coding of code-block coefficients) (T1) - -The functions in T1.C have for goal to realize the tier-1 coding operation. The functions -in T1.C are used by some function in TCD.C. -*/ - -/** @defgroup T1 T1 - Implementation of the tier-1 coding */ -/*@{*/ - -/* ----------------------------------------------------------------------- */ -#define T1_NMSEDEC_BITS 7 - -#define T1_SIG_NE 0x0001 /**< Context orientation : North-East direction */ -#define T1_SIG_SE 0x0002 /**< Context orientation : South-East direction */ -#define T1_SIG_SW 0x0004 /**< Context orientation : South-West direction */ -#define T1_SIG_NW 0x0008 /**< Context orientation : North-West direction */ -#define T1_SIG_N 0x0010 /**< Context orientation : North direction */ -#define T1_SIG_E 0x0020 /**< Context orientation : East direction */ -#define T1_SIG_S 0x0040 /**< Context orientation : South direction */ -#define T1_SIG_W 0x0080 /**< Context orientation : West direction */ -#define T1_SIG_OTH (T1_SIG_N|T1_SIG_NE|T1_SIG_E|T1_SIG_SE|T1_SIG_S|T1_SIG_SW|T1_SIG_W|T1_SIG_NW) -#define T1_SIG_PRIM (T1_SIG_N|T1_SIG_E|T1_SIG_S|T1_SIG_W) - -#define T1_SGN_N 0x0100 -#define T1_SGN_E 0x0200 -#define T1_SGN_S 0x0400 -#define T1_SGN_W 0x0800 -#define T1_SGN (T1_SGN_N|T1_SGN_E|T1_SGN_S|T1_SGN_W) - -#define T1_SIG 0x1000 -#define T1_REFINE 0x2000 -#define T1_VISIT 0x4000 - -#define T1_NUMCTXS_ZC 9 -#define T1_NUMCTXS_SC 5 -#define T1_NUMCTXS_MAG 3 -#define T1_NUMCTXS_AGG 1 -#define T1_NUMCTXS_UNI 1 - -#define T1_CTXNO_ZC 0 -#define T1_CTXNO_SC (T1_CTXNO_ZC+T1_NUMCTXS_ZC) -#define T1_CTXNO_MAG (T1_CTXNO_SC+T1_NUMCTXS_SC) -#define T1_CTXNO_AGG (T1_CTXNO_MAG+T1_NUMCTXS_MAG) -#define T1_CTXNO_UNI (T1_CTXNO_AGG+T1_NUMCTXS_AGG) -#define T1_NUMCTXS (T1_CTXNO_UNI+T1_NUMCTXS_UNI) - -#define T1_NMSEDEC_FRACBITS (T1_NMSEDEC_BITS-1) - -#define T1_TYPE_MQ 0 /**< Normal coding using entropy coder */ -#define T1_TYPE_RAW 1 /**< No encoding the information is store under raw format in codestream (mode switch RAW)*/ - -/* ----------------------------------------------------------------------- */ - -typedef short flag_t; - -/** -Tier-1 coding (coding of code-block coefficients) -*/ -typedef struct opj_t1 { - /** codec context */ - opj_common_ptr cinfo; - - /** MQC component */ - opj_mqc_t *mqc; - /** RAW component */ - opj_raw_t *raw; - - int *data; - flag_t *flags; - int w; - int h; - int datasize; - int flagssize; - int flags_stride; -} opj_t1_t; - -#define MACRO_t1_flags(x,y) t1->flags[((x)*(t1->flags_stride))+(y)] - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Create a new T1 handle -and initialize the look-up tables of the Tier-1 coder/decoder -@return Returns a new T1 handle if successful, returns NULL otherwise -@see t1_init_luts -*/ -opj_t1_t* t1_create(opj_common_ptr cinfo); -/** -Destroy a previously created T1 handle -@param t1 T1 handle to destroy -*/ -void t1_destroy(opj_t1_t *t1); -/** -Encode the code-blocks of a tile -@param t1 T1 handle -@param tile The tile to encode -@param tcp Tile coding parameters -*/ -void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp); -/** -Decode the code-blocks of a tile -@param t1 T1 handle -@param tilec The tile to decode -@param tccp Tile coding parameters -*/ -void t1_decode_cblks(opj_t1_t* t1, opj_tcd_tilecomp_t* tilec, opj_tccp_t* tccp); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __T1_H */ +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __T1_H +#define __T1_H +/** +@file t1.h +@brief Implementation of the tier-1 coding (coding of code-block coefficients) (T1) + +The functions in T1.C have for goal to realize the tier-1 coding operation. The functions +in T1.C are used by some function in TCD.C. +*/ + +/** @defgroup T1 T1 - Implementation of the tier-1 coding */ +/*@{*/ + +/* ----------------------------------------------------------------------- */ +#define T1_NMSEDEC_BITS 7 + +#define T1_SIG_NE 0x0001 /**< Context orientation : North-East direction */ +#define T1_SIG_SE 0x0002 /**< Context orientation : South-East direction */ +#define T1_SIG_SW 0x0004 /**< Context orientation : South-West direction */ +#define T1_SIG_NW 0x0008 /**< Context orientation : North-West direction */ +#define T1_SIG_N 0x0010 /**< Context orientation : North direction */ +#define T1_SIG_E 0x0020 /**< Context orientation : East direction */ +#define T1_SIG_S 0x0040 /**< Context orientation : South direction */ +#define T1_SIG_W 0x0080 /**< Context orientation : West direction */ +#define T1_SIG_OTH (T1_SIG_N|T1_SIG_NE|T1_SIG_E|T1_SIG_SE|T1_SIG_S|T1_SIG_SW|T1_SIG_W|T1_SIG_NW) +#define T1_SIG_PRIM (T1_SIG_N|T1_SIG_E|T1_SIG_S|T1_SIG_W) + +#define T1_SGN_N 0x0100 +#define T1_SGN_E 0x0200 +#define T1_SGN_S 0x0400 +#define T1_SGN_W 0x0800 +#define T1_SGN (T1_SGN_N|T1_SGN_E|T1_SGN_S|T1_SGN_W) + +#define T1_SIG 0x1000 +#define T1_REFINE 0x2000 +#define T1_VISIT 0x4000 + +#define T1_NUMCTXS_ZC 9 +#define T1_NUMCTXS_SC 5 +#define T1_NUMCTXS_MAG 3 +#define T1_NUMCTXS_AGG 1 +#define T1_NUMCTXS_UNI 1 + +#define T1_CTXNO_ZC 0 +#define T1_CTXNO_SC (T1_CTXNO_ZC+T1_NUMCTXS_ZC) +#define T1_CTXNO_MAG (T1_CTXNO_SC+T1_NUMCTXS_SC) +#define T1_CTXNO_AGG (T1_CTXNO_MAG+T1_NUMCTXS_MAG) +#define T1_CTXNO_UNI (T1_CTXNO_AGG+T1_NUMCTXS_AGG) +#define T1_NUMCTXS (T1_CTXNO_UNI+T1_NUMCTXS_UNI) + +#define T1_NMSEDEC_FRACBITS (T1_NMSEDEC_BITS-1) + +#define T1_TYPE_MQ 0 /**< Normal coding using entropy coder */ +#define T1_TYPE_RAW 1 /**< No encoding the information is store under raw format in codestream (mode switch RAW)*/ + +/* ----------------------------------------------------------------------- */ + +typedef short flag_t; + +/** +Tier-1 coding (coding of code-block coefficients) +*/ +typedef struct opj_t1 { + /** codec context */ + opj_common_ptr cinfo; + + /** MQC component */ + opj_mqc_t *mqc; + /** RAW component */ + opj_raw_t *raw; + + int *data; + flag_t *flags; + int w; + int h; + int datasize; + int flagssize; + int flags_stride; +} opj_t1_t; + +#define MACRO_t1_flags(x,y) t1->flags[((x)*(t1->flags_stride))+(y)] + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Create a new T1 handle +and initialize the look-up tables of the Tier-1 coder/decoder +@return Returns a new T1 handle if successful, returns NULL otherwise +@see t1_init_luts +*/ +opj_t1_t* t1_create(opj_common_ptr cinfo); +/** +Destroy a previously created T1 handle +@param t1 T1 handle to destroy +*/ +void t1_destroy(opj_t1_t *t1); +/** +Encode the code-blocks of a tile +@param t1 T1 handle +@param tile The tile to encode +@param tcp Tile coding parameters +*/ +void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp); +/** +Decode the code-blocks of a tile +@param t1 T1 handle +@param tilec The tile to decode +@param tccp Tile coding parameters +*/ +void t1_decode_cblks(opj_t1_t* t1, opj_tcd_tilecomp_t* tilec, opj_tccp_t* tccp); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __T1_H */ diff --git a/Source/LibOpenJPEG/t2.c b/Source/LibOpenJPEG/t2.c index fe8720b..cae29f0 100644 --- a/Source/LibOpenJPEG/t2.c +++ b/Source/LibOpenJPEG/t2.c @@ -1,822 +1,822 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/** @defgroup T2 T2 - Implementation of a tier-2 coding */ -/*@{*/ - -/** @name Local static functions */ -/*@{*/ - -static void t2_putcommacode(opj_bio_t *bio, int n); -static int t2_getcommacode(opj_bio_t *bio); -/** -Variable length code for signalling delta Zil (truncation point) -@param bio Bit Input/Output component -@param n delta Zil -*/ -static void t2_putnumpasses(opj_bio_t *bio, int n); -static int t2_getnumpasses(opj_bio_t *bio); -/** -Encode a packet of a tile to a destination buffer -@param tile Tile for which to write the packets -@param tcp Tile coding parameters -@param pi Packet identity -@param dest Destination buffer -@param len Length of the destination buffer -@param cstr_info Codestream information structure -@param tileno Number of the tile encoded -@return -*/ -static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_codestream_info_t *cstr_info, int tileno); -/** -@param cblk -@param index -@param cblksty -@param first -*/ -static opj_bool t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first); -/** -Decode a packet of a tile from a source buffer -@param t2 T2 handle -@param src Source buffer -@param len Length of the source buffer -@param tile Tile for which to write the packets -@param tcp Tile coding parameters -@param pi Packet identity -@param pack_info Packet information -@return -*/ -static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, - opj_tcp_t *tcp, opj_pi_iterator_t *pi, opj_packet_info_t *pack_info); - -/*@}*/ - -/*@}*/ - -/* ----------------------------------------------------------------------- */ - -/* #define RESTART 0x04 */ - -static void t2_putcommacode(opj_bio_t *bio, int n) { - while (--n >= 0) { - bio_write(bio, 1, 1); - } - bio_write(bio, 0, 1); -} - -static int t2_getcommacode(opj_bio_t *bio) { - int n; - for (n = 0; bio_read(bio, 1); n++) { - ; - } - return n; -} - -static void t2_putnumpasses(opj_bio_t *bio, int n) { - if (n == 1) { - bio_write(bio, 0, 1); - } else if (n == 2) { - bio_write(bio, 2, 2); - } else if (n <= 5) { - bio_write(bio, 0xc | (n - 3), 4); - } else if (n <= 36) { - bio_write(bio, 0x1e0 | (n - 6), 9); - } else if (n <= 164) { - bio_write(bio, 0xff80 | (n - 37), 16); - } -} - -static int t2_getnumpasses(opj_bio_t *bio) { - int n; - if (!bio_read(bio, 1)) - return 1; - if (!bio_read(bio, 1)) - return 2; - if ((n = bio_read(bio, 2)) != 3) - return (3 + n); - if ((n = bio_read(bio, 5)) != 31) - return (6 + n); - return (37 + bio_read(bio, 7)); -} - -static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_iterator_t *pi, unsigned char *dest, int length, opj_codestream_info_t *cstr_info, int tileno) { - int bandno, cblkno; - unsigned char *c = dest; - - int compno = pi->compno; /* component value */ - int resno = pi->resno; /* resolution level value */ - int precno = pi->precno; /* precinct value */ - int layno = pi->layno; /* quality layer value */ - - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - - opj_bio_t *bio = NULL; /* BIO component */ - - /* */ - if (tcp->csty & J2K_CP_CSTY_SOP) { - c[0] = 255; - c[1] = 145; - c[2] = 0; - c[3] = 4; - c[4] = (unsigned char)((tile->packno % 65536) / 256); - c[5] = (unsigned char)((tile->packno % 65536) % 256); - c += 6; - } - /* */ - - if (!layno) { - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - opj_tcd_precinct_t *prc = &band->precincts[precno]; - tgt_reset(prc->incltree); - tgt_reset(prc->imsbtree); - for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { - opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; - cblk->numpasses = 0; - tgt_setvalue(prc->imsbtree, cblkno, band->numbps - cblk->numbps); - } - } - } - - bio = bio_create(); - bio_init_enc(bio, c, length); - bio_write(bio, 1, 1); /* Empty header bit */ - - /* Writing Packet header */ - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - opj_tcd_precinct_t *prc = &band->precincts[precno]; - for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { - opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; - opj_tcd_layer_t *layer = &cblk->layers[layno]; - if (!cblk->numpasses && layer->numpasses) { - tgt_setvalue(prc->incltree, cblkno, layno); - } - } - for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { - opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; - opj_tcd_layer_t *layer = &cblk->layers[layno]; - int increment = 0; - int nump = 0; - int len = 0, passno; - /* cblk inclusion bits */ - if (!cblk->numpasses) { - tgt_encode(bio, prc->incltree, cblkno, layno + 1); - } else { - bio_write(bio, layer->numpasses != 0, 1); - } - /* if cblk not included, go to the next cblk */ - if (!layer->numpasses) { - continue; - } - /* if first instance of cblk --> zero bit-planes information */ - if (!cblk->numpasses) { - cblk->numlenbits = 3; - tgt_encode(bio, prc->imsbtree, cblkno, 999); - } - /* number of coding passes included */ - t2_putnumpasses(bio, layer->numpasses); - - /* computation of the increase of the length indicator and insertion in the header */ - for (passno = cblk->numpasses; passno < cblk->numpasses + layer->numpasses; passno++) { - opj_tcd_pass_t *pass = &cblk->passes[passno]; - nump++; - len += pass->len; - if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { - increment = int_max(increment, int_floorlog2(len) + 1 - (cblk->numlenbits + int_floorlog2(nump))); - len = 0; - nump = 0; - } - } - t2_putcommacode(bio, increment); - - /* computation of the new Length indicator */ - cblk->numlenbits += increment; - - /* insertion of the codeword segment length */ - for (passno = cblk->numpasses; passno < cblk->numpasses + layer->numpasses; passno++) { - opj_tcd_pass_t *pass = &cblk->passes[passno]; - nump++; - len += pass->len; - if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { - bio_write(bio, len, cblk->numlenbits + int_floorlog2(nump)); - len = 0; - nump = 0; - } - } - } - } - - if (bio_flush(bio)) { - bio_destroy(bio); - return -999; /* modified to eliminate longjmp !! */ - } - - c += bio_numbytes(bio); - bio_destroy(bio); - - /* */ - if (tcp->csty & J2K_CP_CSTY_EPH) { - c[0] = 255; - c[1] = 146; - c += 2; - } - /* */ - - /* << INDEX */ - /* End of packet header position. Currently only represents the distance to start of packet - // Will be updated later by incrementing with packet start value */ - if(cstr_info && cstr_info->index_write) { - opj_packet_info_t *info_PK = &cstr_info->tile[tileno].packet[cstr_info->packno]; - info_PK->end_ph_pos = (int)(c - dest); - } - /* INDEX >> */ - - /* Writing the packet body */ - - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - opj_tcd_precinct_t *prc = &band->precincts[precno]; - for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { - opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; - opj_tcd_layer_t *layer = &cblk->layers[layno]; - if (!layer->numpasses) { - continue; - } - if (c + layer->len > dest + length) { - return -999; - } - - memcpy(c, layer->data, layer->len); - cblk->numpasses += layer->numpasses; - c += layer->len; - /* << INDEX */ - if(cstr_info && cstr_info->index_write) { - opj_packet_info_t *info_PK = &cstr_info->tile[tileno].packet[cstr_info->packno]; - info_PK->disto += layer->disto; - if (cstr_info->D_max < info_PK->disto) { - cstr_info->D_max = info_PK->disto; - } - } - /* INDEX >> */ - } - } - - return (c - dest); -} - -static opj_bool t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first) { - opj_tcd_seg_t* seg; - opj_tcd_seg_t* segs; - segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, (index + 1) * sizeof(opj_tcd_seg_t)); - - if (segs == NULL) - { - return OPJ_FALSE; - } - cblk->segs = segs; - - seg = &cblk->segs[index]; - seg->data = NULL; - seg->dataindex = 0; - seg->numpasses = 0; - seg->len = 0; - if (cblksty & J2K_CCP_CBLKSTY_TERMALL) { - seg->maxpasses = 1; - } - else if (cblksty & J2K_CCP_CBLKSTY_LAZY) { - if (first) { - seg->maxpasses = 10; - } else { - seg->maxpasses = (((seg - 1)->maxpasses == 1) || ((seg - 1)->maxpasses == 10)) ? 2 : 1; - } - } else { - seg->maxpasses = 109; - } - - return OPJ_TRUE; -} - -static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, - opj_tcp_t *tcp, opj_pi_iterator_t *pi, opj_packet_info_t *pack_info) { - int bandno, cblkno; - unsigned char *c = src; - - opj_cp_t *cp = t2->cp; - - int compno = pi->compno; /* component value */ - int resno = pi->resno; /* resolution level value */ - int precno = pi->precno; /* precinct value */ - int layno = pi->layno; /* quality layer value */ - - opj_tcd_resolution_t* res = &tile->comps[compno].resolutions[resno]; - - unsigned char *hd = NULL; - int present; - - opj_bio_t *bio = NULL; /* BIO component */ - - if (layno == 0) { - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue; - - tgt_reset(prc->incltree); - tgt_reset(prc->imsbtree); - for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { - opj_tcd_cblk_dec_t* cblk = &prc->cblks.dec[cblkno]; - cblk->numsegs = 0; - } - } - } - - /* SOP markers */ - - if (tcp->csty & J2K_CP_CSTY_SOP) { - if ((*c) != 0xff || (*(c + 1) != 0x91)) { - opj_event_msg(t2->cinfo, EVT_WARNING, "Expected SOP marker\n"); - } else { - c += 6; - } - - /** TODO : check the Nsop value */ - } - - /* - When the marker PPT/PPM is used the packet header are store in PPT/PPM marker - This part deal with this caracteristic - step 1: Read packet header in the saved structure - step 2: Return to codestream for decoding - */ - - bio = bio_create(); - - if (cp->ppm == 1) { /* PPM */ - hd = cp->ppm_data; - bio_init_dec(bio, hd, cp->ppm_len); - } else if (tcp->ppt == 1) { /* PPT */ - hd = tcp->ppt_data; - bio_init_dec(bio, hd, tcp->ppt_len); - } else { /* Normal Case */ - hd = c; - bio_init_dec(bio, hd, src+len-hd); - } - - present = bio_read(bio, 1); - - if (!present) { - bio_inalign(bio); - hd += bio_numbytes(bio); - bio_destroy(bio); - - /* EPH markers */ - - if (tcp->csty & J2K_CP_CSTY_EPH) { - if ((*hd) != 0xff || (*(hd + 1) != 0x92)) { - printf("Error : expected EPH marker\n"); - } else { - hd += 2; - } - } - - /* << INDEX */ - /* End of packet header position. Currently only represents the distance to start of packet - // Will be updated later by incrementing with packet start value*/ - if(pack_info) { - pack_info->end_ph_pos = (int)(c - src); - } - /* INDEX >> */ - - if (cp->ppm == 1) { /* PPM case */ - cp->ppm_len += cp->ppm_data-hd; - cp->ppm_data = hd; - return (c - src); - } - if (tcp->ppt == 1) { /* PPT case */ - tcp->ppt_len+=tcp->ppt_data-hd; - tcp->ppt_data = hd; - return (c - src); - } - - return (hd - src); - } - - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue; - - for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { - int included, increment, n, segno; - opj_tcd_cblk_dec_t* cblk = &prc->cblks.dec[cblkno]; - /* if cblk not yet included before --> inclusion tagtree */ - if (!cblk->numsegs) { - included = tgt_decode(bio, prc->incltree, cblkno, layno + 1); - /* else one bit */ - } else { - included = bio_read(bio, 1); - } - /* if cblk not included */ - if (!included) { - cblk->numnewpasses = 0; - continue; - } - /* if cblk not yet included --> zero-bitplane tagtree */ - if (!cblk->numsegs) { - int i, numimsbs; - for (i = 0; !tgt_decode(bio, prc->imsbtree, cblkno, i); i++) { - ; - } - numimsbs = i - 1; - cblk->numbps = band->numbps - numimsbs; - cblk->numlenbits = 3; - } - /* number of coding passes */ - cblk->numnewpasses = t2_getnumpasses(bio); - increment = t2_getcommacode(bio); - /* length indicator increment */ - cblk->numlenbits += increment; - segno = 0; - if (!cblk->numsegs) { - if (!t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 1)) - { - opj_event_msg(t2->cinfo, EVT_ERROR, "Out of memory\n"); - bio_destroy(bio); - return -999; - } - } else { - segno = cblk->numsegs - 1; - if (cblk->segs[segno].numpasses == cblk->segs[segno].maxpasses) { - ++segno; - if (!t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0)) - { - opj_event_msg(t2->cinfo, EVT_ERROR, "Out of memory\n"); - bio_destroy(bio); - return -999; - } - } - } - n = cblk->numnewpasses; - - do { - cblk->segs[segno].numnewpasses = int_min(cblk->segs[segno].maxpasses - cblk->segs[segno].numpasses, n); - cblk->segs[segno].newlen = bio_read(bio, cblk->numlenbits + int_floorlog2(cblk->segs[segno].numnewpasses)); - n -= cblk->segs[segno].numnewpasses; - if (n > 0) { - ++segno; - if (!t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0)) - { - opj_event_msg(t2->cinfo, EVT_ERROR, "Out of memory\n"); - bio_destroy(bio); - return -999; - } - } - } while (n > 0); - } - } - - if (bio_inalign(bio)) { - bio_destroy(bio); - return -999; - } - - hd += bio_numbytes(bio); - bio_destroy(bio); - - /* EPH markers */ - if (tcp->csty & J2K_CP_CSTY_EPH) { - if ((*hd) != 0xff || (*(hd + 1) != 0x92)) { - opj_event_msg(t2->cinfo, EVT_ERROR, "Expected EPH marker\n"); - return -999; - } else { - hd += 2; - } - } - - /* << INDEX */ - /* End of packet header position. Currently only represents the distance to start of packet - // Will be updated later by incrementing with packet start value*/ - if(pack_info) { - pack_info->end_ph_pos = (int)(hd - src); - } - /* INDEX >> */ - - if (cp->ppm==1) { - cp->ppm_len+=cp->ppm_data-hd; - cp->ppm_data = hd; - } else if (tcp->ppt == 1) { - tcp->ppt_len+=tcp->ppt_data-hd; - tcp->ppt_data = hd; - } else { - c=hd; - } - - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue; - - for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { - opj_tcd_cblk_dec_t* cblk = &prc->cblks.dec[cblkno]; - opj_tcd_seg_t *seg = NULL; - if (!cblk->numnewpasses) - continue; - if (!cblk->numsegs) { - seg = &cblk->segs[0]; - cblk->numsegs++; - cblk->len = 0; - } else { - seg = &cblk->segs[cblk->numsegs - 1]; - if (seg->numpasses == seg->maxpasses) { - seg++; - cblk->numsegs++; - } - } - - do { - if (c + seg->newlen > src + len) { - return -999; - } - -#ifdef USE_JPWL - /* we need here a j2k handle to verify if making a check to - the validity of cblocks parameters is selected from user (-W) */ - - /* let's check that we are not exceeding */ - if ((cblk->len + seg->newlen) > 8192) { - opj_event_msg(t2->cinfo, EVT_WARNING, - "JPWL: segment too long (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", - seg->newlen, cblkno, precno, bandno, resno, compno); - if (!JPWL_ASSUME) { - opj_event_msg(t2->cinfo, EVT_ERROR, "JPWL: giving up\n"); - return -999; - } - seg->newlen = 8192 - cblk->len; - opj_event_msg(t2->cinfo, EVT_WARNING, " - truncating segment to %d\n", seg->newlen); - break; - }; - -#endif /* USE_JPWL */ - - cblk->data = (unsigned char*) opj_realloc(cblk->data, (cblk->len + seg->newlen) * sizeof(unsigned char)); - memcpy(cblk->data + cblk->len, c, seg->newlen); - if (seg->numpasses == 0) { - seg->data = &cblk->data; - seg->dataindex = cblk->len; - } - c += seg->newlen; - cblk->len += seg->newlen; - seg->len += seg->newlen; - seg->numpasses += seg->numnewpasses; - cblk->numnewpasses -= seg->numnewpasses; - if (cblk->numnewpasses > 0) { - seg++; - cblk->numsegs++; - } - } while (cblk->numnewpasses > 0); - } - } - - return (c - src); -} - -/* ----------------------------------------------------------------------- */ - -int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_codestream_info_t *cstr_info,int tpnum, int tppos,int pino, J2K_T2_MODE t2_mode, int cur_totnum_tp){ - unsigned char *c = dest; - int e = 0; - int compno; - opj_pi_iterator_t *pi = NULL; - int poc; - opj_image_t *image = t2->image; - opj_cp_t *cp = t2->cp; - opj_tcp_t *tcp = &cp->tcps[tileno]; - int pocno = cp->cinema == CINEMA4K_24? 2: 1; - int maxcomp = cp->max_comp_size > 0 ? image->numcomps : 1; - - pi = pi_initialise_encode(image, cp, tileno, t2_mode); - if(!pi) { - /* TODO: throw an error */ - return -999; - } - - if(t2_mode == THRESH_CALC ){ /* Calculating threshold */ - for(compno = 0; compno < maxcomp; compno++ ){ - for(poc = 0; poc < pocno ; poc++){ - int comp_len = 0; - int tpnum = compno; - if (pi_create_encode(pi, cp,tileno,poc,tpnum,tppos,t2_mode,cur_totnum_tp)) { - opj_event_msg(t2->cinfo, EVT_ERROR, "Error initializing Packet Iterator\n"); - pi_destroy(pi, cp, tileno); - return -999; - } - while (pi_next(&pi[poc])) { - if (pi[poc].layno < maxlayers) { - e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[poc], c, dest + len - c, cstr_info, tileno); - comp_len = comp_len + e; - if (e == -999) { - break; - } else { - c += e; - } - } - } - if (e == -999) break; - if (cp->max_comp_size){ - if (comp_len > cp->max_comp_size){ - e = -999; - break; - } - } - } - if (e == -999) break; - } - }else{ /* t2_mode == FINAL_PASS */ - pi_create_encode(pi, cp,tileno,pino,tpnum,tppos,t2_mode,cur_totnum_tp); - while (pi_next(&pi[pino])) { - if (pi[pino].layno < maxlayers) { - e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, cstr_info, tileno); - if (e == -999) { - break; - } else { - c += e; - } - /* INDEX >> */ - if(cstr_info) { - if(cstr_info->index_write) { - opj_tile_info_t *info_TL = &cstr_info->tile[tileno]; - opj_packet_info_t *info_PK = &info_TL->packet[cstr_info->packno]; - if (!cstr_info->packno) { - info_PK->start_pos = info_TL->end_header + 1; - } else { - info_PK->start_pos = ((cp->tp_on | tcp->POC)&& info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[cstr_info->packno - 1].end_pos + 1; - } - info_PK->end_pos = info_PK->start_pos + e - 1; - info_PK->end_ph_pos += info_PK->start_pos - 1; /* End of packet header which now only represents the distance - // to start of packet is incremented by value of start of packet*/ - } - - cstr_info->packno++; - } - /* << INDEX */ - tile->packno++; - } - } - } - - pi_destroy(pi, cp, tileno); - - if (e == -999) { - return e; - } - - return (c - dest); -} - -int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile, opj_codestream_info_t *cstr_info) { - unsigned char *c = src; - opj_pi_iterator_t *pi; - int pino, e = 0; - int n = 0, curtp = 0; - int tp_start_packno; - - opj_image_t *image = t2->image; - opj_cp_t *cp = t2->cp; - - /* create a packet iterator */ - pi = pi_create_decode(image, cp, tileno); - if(!pi) { - /* TODO: throw an error */ - return -999; - } - - tp_start_packno = 0; - - for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) { - while (pi_next(&pi[pino])) { - if ((cp->layer==0) || (cp->layer>=((pi[pino].layno)+1))) { - opj_packet_info_t *pack_info; - if (cstr_info) - pack_info = &cstr_info->tile[tileno].packet[cstr_info->packno]; - else - pack_info = NULL; - e = t2_decode_packet(t2, c, src + len - c, tile, &cp->tcps[tileno], &pi[pino], pack_info); - } else { - e = 0; - } - if(e == -999) - { - pi_destroy(pi, cp, tileno); - return -999; - } - /* progression in resolution */ - image->comps[pi[pino].compno].resno_decoded = - (e > 0) ? - int_max(pi[pino].resno, image->comps[pi[pino].compno].resno_decoded) - : image->comps[pi[pino].compno].resno_decoded; - n++; - - /* INDEX >> */ - if(cstr_info) { - opj_tile_info_t *info_TL = &cstr_info->tile[tileno]; - opj_packet_info_t *info_PK = &info_TL->packet[cstr_info->packno]; - if (!cstr_info->packno) { - info_PK->start_pos = info_TL->end_header + 1; - } else if (info_TL->packet[cstr_info->packno-1].end_pos >= (int)cstr_info->tile[tileno].tp[curtp].tp_end_pos){ /* New tile part*/ - info_TL->tp[curtp].tp_numpacks = cstr_info->packno - tp_start_packno; /* Number of packets in previous tile-part*/ - info_TL->tp[curtp].tp_start_pack = tp_start_packno; - tp_start_packno = cstr_info->packno; - curtp++; - info_PK->start_pos = cstr_info->tile[tileno].tp[curtp].tp_end_header+1; - } else { - info_PK->start_pos = (cp->tp_on && info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[cstr_info->packno - 1].end_pos + 1; - } - info_PK->end_pos = info_PK->start_pos + e - 1; - info_PK->end_ph_pos += info_PK->start_pos - 1; /* End of packet header which now only represents the distance - // to start of packet is incremented by value of start of packet*/ - cstr_info->packno++; - } - /* << INDEX */ - - if (e == -999) { /* ADD */ - break; - } else { - c += e; - } - } - } - /* INDEX >> */ - if(cstr_info) { - cstr_info->tile[tileno].tp[curtp].tp_numpacks = cstr_info->packno - tp_start_packno; /* Number of packets in last tile-part*/ - cstr_info->tile[tileno].tp[curtp].tp_start_pack = tp_start_packno; - } - /* << INDEX */ - - /* don't forget to release pi */ - pi_destroy(pi, cp, tileno); - - if (e == -999) { - return e; - } - - return (c - src); -} - -/* ----------------------------------------------------------------------- */ - -opj_t2_t* t2_create(opj_common_ptr cinfo, opj_image_t *image, opj_cp_t *cp) { - /* create the tcd structure */ - opj_t2_t *t2 = (opj_t2_t*)opj_malloc(sizeof(opj_t2_t)); - if(!t2) return NULL; - t2->cinfo = cinfo; - t2->image = image; - t2->cp = cp; - - return t2; -} - -void t2_destroy(opj_t2_t *t2) { - if(t2) { - opj_free(t2); - } -} - - - - - +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/** @defgroup T2 T2 - Implementation of a tier-2 coding */ +/*@{*/ + +/** @name Local static functions */ +/*@{*/ + +static void t2_putcommacode(opj_bio_t *bio, int n); +static int t2_getcommacode(opj_bio_t *bio); +/** +Variable length code for signalling delta Zil (truncation point) +@param bio Bit Input/Output component +@param n delta Zil +*/ +static void t2_putnumpasses(opj_bio_t *bio, int n); +static int t2_getnumpasses(opj_bio_t *bio); +/** +Encode a packet of a tile to a destination buffer +@param tile Tile for which to write the packets +@param tcp Tile coding parameters +@param pi Packet identity +@param dest Destination buffer +@param len Length of the destination buffer +@param cstr_info Codestream information structure +@param tileno Number of the tile encoded +@return +*/ +static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_codestream_info_t *cstr_info, int tileno); +/** +@param cblk +@param index +@param cblksty +@param first +*/ +static opj_bool t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first); +/** +Decode a packet of a tile from a source buffer +@param t2 T2 handle +@param src Source buffer +@param len Length of the source buffer +@param tile Tile for which to write the packets +@param tcp Tile coding parameters +@param pi Packet identity +@param pack_info Packet information +@return +*/ +static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, + opj_tcp_t *tcp, opj_pi_iterator_t *pi, opj_packet_info_t *pack_info); + +/*@}*/ + +/*@}*/ + +/* ----------------------------------------------------------------------- */ + +/* #define RESTART 0x04 */ + +static void t2_putcommacode(opj_bio_t *bio, int n) { + while (--n >= 0) { + bio_write(bio, 1, 1); + } + bio_write(bio, 0, 1); +} + +static int t2_getcommacode(opj_bio_t *bio) { + int n; + for (n = 0; bio_read(bio, 1); n++) { + ; + } + return n; +} + +static void t2_putnumpasses(opj_bio_t *bio, int n) { + if (n == 1) { + bio_write(bio, 0, 1); + } else if (n == 2) { + bio_write(bio, 2, 2); + } else if (n <= 5) { + bio_write(bio, 0xc | (n - 3), 4); + } else if (n <= 36) { + bio_write(bio, 0x1e0 | (n - 6), 9); + } else if (n <= 164) { + bio_write(bio, 0xff80 | (n - 37), 16); + } +} + +static int t2_getnumpasses(opj_bio_t *bio) { + int n; + if (!bio_read(bio, 1)) + return 1; + if (!bio_read(bio, 1)) + return 2; + if ((n = bio_read(bio, 2)) != 3) + return (3 + n); + if ((n = bio_read(bio, 5)) != 31) + return (6 + n); + return (37 + bio_read(bio, 7)); +} + +static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_iterator_t *pi, unsigned char *dest, int length, opj_codestream_info_t *cstr_info, int tileno) { + int bandno, cblkno; + unsigned char *c = dest; + + int compno = pi->compno; /* component value */ + int resno = pi->resno; /* resolution level value */ + int precno = pi->precno; /* precinct value */ + int layno = pi->layno; /* quality layer value */ + + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + + opj_bio_t *bio = NULL; /* BIO component */ + + /* */ + if (tcp->csty & J2K_CP_CSTY_SOP) { + c[0] = 255; + c[1] = 145; + c[2] = 0; + c[3] = 4; + c[4] = (unsigned char)((tile->packno % 65536) / 256); + c[5] = (unsigned char)((tile->packno % 65536) % 256); + c += 6; + } + /* */ + + if (!layno) { + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + opj_tcd_precinct_t *prc = &band->precincts[precno]; + tgt_reset(prc->incltree); + tgt_reset(prc->imsbtree); + for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { + opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; + cblk->numpasses = 0; + tgt_setvalue(prc->imsbtree, cblkno, band->numbps - cblk->numbps); + } + } + } + + bio = bio_create(); + bio_init_enc(bio, c, length); + bio_write(bio, 1, 1); /* Empty header bit */ + + /* Writing Packet header */ + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + opj_tcd_precinct_t *prc = &band->precincts[precno]; + for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { + opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; + opj_tcd_layer_t *layer = &cblk->layers[layno]; + if (!cblk->numpasses && layer->numpasses) { + tgt_setvalue(prc->incltree, cblkno, layno); + } + } + for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { + opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; + opj_tcd_layer_t *layer = &cblk->layers[layno]; + int increment = 0; + int nump = 0; + int len = 0, passno; + /* cblk inclusion bits */ + if (!cblk->numpasses) { + tgt_encode(bio, prc->incltree, cblkno, layno + 1); + } else { + bio_write(bio, layer->numpasses != 0, 1); + } + /* if cblk not included, go to the next cblk */ + if (!layer->numpasses) { + continue; + } + /* if first instance of cblk --> zero bit-planes information */ + if (!cblk->numpasses) { + cblk->numlenbits = 3; + tgt_encode(bio, prc->imsbtree, cblkno, 999); + } + /* number of coding passes included */ + t2_putnumpasses(bio, layer->numpasses); + + /* computation of the increase of the length indicator and insertion in the header */ + for (passno = cblk->numpasses; passno < cblk->numpasses + layer->numpasses; passno++) { + opj_tcd_pass_t *pass = &cblk->passes[passno]; + nump++; + len += pass->len; + if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { + increment = int_max(increment, int_floorlog2(len) + 1 - (cblk->numlenbits + int_floorlog2(nump))); + len = 0; + nump = 0; + } + } + t2_putcommacode(bio, increment); + + /* computation of the new Length indicator */ + cblk->numlenbits += increment; + + /* insertion of the codeword segment length */ + for (passno = cblk->numpasses; passno < cblk->numpasses + layer->numpasses; passno++) { + opj_tcd_pass_t *pass = &cblk->passes[passno]; + nump++; + len += pass->len; + if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { + bio_write(bio, len, cblk->numlenbits + int_floorlog2(nump)); + len = 0; + nump = 0; + } + } + } + } + + if (bio_flush(bio)) { + bio_destroy(bio); + return -999; /* modified to eliminate longjmp !! */ + } + + c += bio_numbytes(bio); + bio_destroy(bio); + + /* */ + if (tcp->csty & J2K_CP_CSTY_EPH) { + c[0] = 255; + c[1] = 146; + c += 2; + } + /* */ + + /* << INDEX */ + /* End of packet header position. Currently only represents the distance to start of packet + // Will be updated later by incrementing with packet start value */ + if(cstr_info && cstr_info->index_write) { + opj_packet_info_t *info_PK = &cstr_info->tile[tileno].packet[cstr_info->packno]; + info_PK->end_ph_pos = (int)(c - dest); + } + /* INDEX >> */ + + /* Writing the packet body */ + + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + opj_tcd_precinct_t *prc = &band->precincts[precno]; + for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { + opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; + opj_tcd_layer_t *layer = &cblk->layers[layno]; + if (!layer->numpasses) { + continue; + } + if (c + layer->len > dest + length) { + return -999; + } + + memcpy(c, layer->data, layer->len); + cblk->numpasses += layer->numpasses; + c += layer->len; + /* << INDEX */ + if(cstr_info && cstr_info->index_write) { + opj_packet_info_t *info_PK = &cstr_info->tile[tileno].packet[cstr_info->packno]; + info_PK->disto += layer->disto; + if (cstr_info->D_max < info_PK->disto) { + cstr_info->D_max = info_PK->disto; + } + } + /* INDEX >> */ + } + } + + return (c - dest); +} + +static opj_bool t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first) { + opj_tcd_seg_t* seg; + opj_tcd_seg_t* segs; + segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, (index + 1) * sizeof(opj_tcd_seg_t)); + + if (segs == NULL) + { + return OPJ_FALSE; + } + cblk->segs = segs; + + seg = &cblk->segs[index]; + seg->data = NULL; + seg->dataindex = 0; + seg->numpasses = 0; + seg->len = 0; + if (cblksty & J2K_CCP_CBLKSTY_TERMALL) { + seg->maxpasses = 1; + } + else if (cblksty & J2K_CCP_CBLKSTY_LAZY) { + if (first) { + seg->maxpasses = 10; + } else { + seg->maxpasses = (((seg - 1)->maxpasses == 1) || ((seg - 1)->maxpasses == 10)) ? 2 : 1; + } + } else { + seg->maxpasses = 109; + } + + return OPJ_TRUE; +} + +static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, + opj_tcp_t *tcp, opj_pi_iterator_t *pi, opj_packet_info_t *pack_info) { + int bandno, cblkno; + unsigned char *c = src; + + opj_cp_t *cp = t2->cp; + + int compno = pi->compno; /* component value */ + int resno = pi->resno; /* resolution level value */ + int precno = pi->precno; /* precinct value */ + int layno = pi->layno; /* quality layer value */ + + opj_tcd_resolution_t* res = &tile->comps[compno].resolutions[resno]; + + unsigned char *hd = NULL; + int present; + + opj_bio_t *bio = NULL; /* BIO component */ + + if (layno == 0) { + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue; + + tgt_reset(prc->incltree); + tgt_reset(prc->imsbtree); + for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { + opj_tcd_cblk_dec_t* cblk = &prc->cblks.dec[cblkno]; + cblk->numsegs = 0; + } + } + } + + /* SOP markers */ + + if (tcp->csty & J2K_CP_CSTY_SOP) { + if ((*c) != 0xff || (*(c + 1) != 0x91)) { + opj_event_msg(t2->cinfo, EVT_WARNING, "Expected SOP marker\n"); + } else { + c += 6; + } + + /** TODO : check the Nsop value */ + } + + /* + When the marker PPT/PPM is used the packet header are store in PPT/PPM marker + This part deal with this caracteristic + step 1: Read packet header in the saved structure + step 2: Return to codestream for decoding + */ + + bio = bio_create(); + + if (cp->ppm == 1) { /* PPM */ + hd = cp->ppm_data; + bio_init_dec(bio, hd, cp->ppm_len); + } else if (tcp->ppt == 1) { /* PPT */ + hd = tcp->ppt_data; + bio_init_dec(bio, hd, tcp->ppt_len); + } else { /* Normal Case */ + hd = c; + bio_init_dec(bio, hd, src+len-hd); + } + + present = bio_read(bio, 1); + + if (!present) { + bio_inalign(bio); + hd += bio_numbytes(bio); + bio_destroy(bio); + + /* EPH markers */ + + if (tcp->csty & J2K_CP_CSTY_EPH) { + if ((*hd) != 0xff || (*(hd + 1) != 0x92)) { + printf("Error : expected EPH marker\n"); + } else { + hd += 2; + } + } + + /* << INDEX */ + /* End of packet header position. Currently only represents the distance to start of packet + // Will be updated later by incrementing with packet start value*/ + if(pack_info) { + pack_info->end_ph_pos = (int)(c - src); + } + /* INDEX >> */ + + if (cp->ppm == 1) { /* PPM case */ + cp->ppm_len += cp->ppm_data-hd; + cp->ppm_data = hd; + return (c - src); + } + if (tcp->ppt == 1) { /* PPT case */ + tcp->ppt_len+=tcp->ppt_data-hd; + tcp->ppt_data = hd; + return (c - src); + } + + return (hd - src); + } + + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue; + + for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { + int included, increment, n, segno; + opj_tcd_cblk_dec_t* cblk = &prc->cblks.dec[cblkno]; + /* if cblk not yet included before --> inclusion tagtree */ + if (!cblk->numsegs) { + included = tgt_decode(bio, prc->incltree, cblkno, layno + 1); + /* else one bit */ + } else { + included = bio_read(bio, 1); + } + /* if cblk not included */ + if (!included) { + cblk->numnewpasses = 0; + continue; + } + /* if cblk not yet included --> zero-bitplane tagtree */ + if (!cblk->numsegs) { + int i, numimsbs; + for (i = 0; !tgt_decode(bio, prc->imsbtree, cblkno, i); i++) { + ; + } + numimsbs = i - 1; + cblk->numbps = band->numbps - numimsbs; + cblk->numlenbits = 3; + } + /* number of coding passes */ + cblk->numnewpasses = t2_getnumpasses(bio); + increment = t2_getcommacode(bio); + /* length indicator increment */ + cblk->numlenbits += increment; + segno = 0; + if (!cblk->numsegs) { + if (!t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 1)) + { + opj_event_msg(t2->cinfo, EVT_ERROR, "Out of memory\n"); + bio_destroy(bio); + return -999; + } + } else { + segno = cblk->numsegs - 1; + if (cblk->segs[segno].numpasses == cblk->segs[segno].maxpasses) { + ++segno; + if (!t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0)) + { + opj_event_msg(t2->cinfo, EVT_ERROR, "Out of memory\n"); + bio_destroy(bio); + return -999; + } + } + } + n = cblk->numnewpasses; + + do { + cblk->segs[segno].numnewpasses = int_min(cblk->segs[segno].maxpasses - cblk->segs[segno].numpasses, n); + cblk->segs[segno].newlen = bio_read(bio, cblk->numlenbits + int_floorlog2(cblk->segs[segno].numnewpasses)); + n -= cblk->segs[segno].numnewpasses; + if (n > 0) { + ++segno; + if (!t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0)) + { + opj_event_msg(t2->cinfo, EVT_ERROR, "Out of memory\n"); + bio_destroy(bio); + return -999; + } + } + } while (n > 0); + } + } + + if (bio_inalign(bio)) { + bio_destroy(bio); + return -999; + } + + hd += bio_numbytes(bio); + bio_destroy(bio); + + /* EPH markers */ + if (tcp->csty & J2K_CP_CSTY_EPH) { + if ((*hd) != 0xff || (*(hd + 1) != 0x92)) { + opj_event_msg(t2->cinfo, EVT_ERROR, "Expected EPH marker\n"); + return -999; + } else { + hd += 2; + } + } + + /* << INDEX */ + /* End of packet header position. Currently only represents the distance to start of packet + // Will be updated later by incrementing with packet start value*/ + if(pack_info) { + pack_info->end_ph_pos = (int)(hd - src); + } + /* INDEX >> */ + + if (cp->ppm==1) { + cp->ppm_len+=cp->ppm_data-hd; + cp->ppm_data = hd; + } else if (tcp->ppt == 1) { + tcp->ppt_len+=tcp->ppt_data-hd; + tcp->ppt_data = hd; + } else { + c=hd; + } + + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue; + + for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { + opj_tcd_cblk_dec_t* cblk = &prc->cblks.dec[cblkno]; + opj_tcd_seg_t *seg = NULL; + if (!cblk->numnewpasses) + continue; + if (!cblk->numsegs) { + seg = &cblk->segs[0]; + cblk->numsegs++; + cblk->len = 0; + } else { + seg = &cblk->segs[cblk->numsegs - 1]; + if (seg->numpasses == seg->maxpasses) { + seg++; + cblk->numsegs++; + } + } + + do { + if (c + seg->newlen > src + len) { + return -999; + } + +#ifdef USE_JPWL + /* we need here a j2k handle to verify if making a check to + the validity of cblocks parameters is selected from user (-W) */ + + /* let's check that we are not exceeding */ + if ((cblk->len + seg->newlen) > 8192) { + opj_event_msg(t2->cinfo, EVT_WARNING, + "JPWL: segment too long (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", + seg->newlen, cblkno, precno, bandno, resno, compno); + if (!JPWL_ASSUME) { + opj_event_msg(t2->cinfo, EVT_ERROR, "JPWL: giving up\n"); + return -999; + } + seg->newlen = 8192 - cblk->len; + opj_event_msg(t2->cinfo, EVT_WARNING, " - truncating segment to %d\n", seg->newlen); + break; + }; + +#endif /* USE_JPWL */ + + cblk->data = (unsigned char*) opj_realloc(cblk->data, (cblk->len + seg->newlen) * sizeof(unsigned char)); + memcpy(cblk->data + cblk->len, c, seg->newlen); + if (seg->numpasses == 0) { + seg->data = &cblk->data; + seg->dataindex = cblk->len; + } + c += seg->newlen; + cblk->len += seg->newlen; + seg->len += seg->newlen; + seg->numpasses += seg->numnewpasses; + cblk->numnewpasses -= seg->numnewpasses; + if (cblk->numnewpasses > 0) { + seg++; + cblk->numsegs++; + } + } while (cblk->numnewpasses > 0); + } + } + + return (c - src); +} + +/* ----------------------------------------------------------------------- */ + +int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_codestream_info_t *cstr_info,int tpnum, int tppos,int pino, J2K_T2_MODE t2_mode, int cur_totnum_tp){ + unsigned char *c = dest; + int e = 0; + int compno; + opj_pi_iterator_t *pi = NULL; + int poc; + opj_image_t *image = t2->image; + opj_cp_t *cp = t2->cp; + opj_tcp_t *tcp = &cp->tcps[tileno]; + int pocno = cp->cinema == CINEMA4K_24? 2: 1; + int maxcomp = cp->max_comp_size > 0 ? image->numcomps : 1; + + pi = pi_initialise_encode(image, cp, tileno, t2_mode); + if(!pi) { + /* TODO: throw an error */ + return -999; + } + + if(t2_mode == THRESH_CALC ){ /* Calculating threshold */ + for(compno = 0; compno < maxcomp; compno++ ){ + for(poc = 0; poc < pocno ; poc++){ + int comp_len = 0; + int tpnum = compno; + if (pi_create_encode(pi, cp,tileno,poc,tpnum,tppos,t2_mode,cur_totnum_tp)) { + opj_event_msg(t2->cinfo, EVT_ERROR, "Error initializing Packet Iterator\n"); + pi_destroy(pi, cp, tileno); + return -999; + } + while (pi_next(&pi[poc])) { + if (pi[poc].layno < maxlayers) { + e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[poc], c, dest + len - c, cstr_info, tileno); + comp_len = comp_len + e; + if (e == -999) { + break; + } else { + c += e; + } + } + } + if (e == -999) break; + if (cp->max_comp_size){ + if (comp_len > cp->max_comp_size){ + e = -999; + break; + } + } + } + if (e == -999) break; + } + }else{ /* t2_mode == FINAL_PASS */ + pi_create_encode(pi, cp,tileno,pino,tpnum,tppos,t2_mode,cur_totnum_tp); + while (pi_next(&pi[pino])) { + if (pi[pino].layno < maxlayers) { + e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, cstr_info, tileno); + if (e == -999) { + break; + } else { + c += e; + } + /* INDEX >> */ + if(cstr_info) { + if(cstr_info->index_write) { + opj_tile_info_t *info_TL = &cstr_info->tile[tileno]; + opj_packet_info_t *info_PK = &info_TL->packet[cstr_info->packno]; + if (!cstr_info->packno) { + info_PK->start_pos = info_TL->end_header + 1; + } else { + info_PK->start_pos = ((cp->tp_on | tcp->POC)&& info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[cstr_info->packno - 1].end_pos + 1; + } + info_PK->end_pos = info_PK->start_pos + e - 1; + info_PK->end_ph_pos += info_PK->start_pos - 1; /* End of packet header which now only represents the distance + // to start of packet is incremented by value of start of packet*/ + } + + cstr_info->packno++; + } + /* << INDEX */ + tile->packno++; + } + } + } + + pi_destroy(pi, cp, tileno); + + if (e == -999) { + return e; + } + + return (c - dest); +} + +int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile, opj_codestream_info_t *cstr_info) { + unsigned char *c = src; + opj_pi_iterator_t *pi; + int pino, e = 0; + int n = 0, curtp = 0; + int tp_start_packno; + + opj_image_t *image = t2->image; + opj_cp_t *cp = t2->cp; + + /* create a packet iterator */ + pi = pi_create_decode(image, cp, tileno); + if(!pi) { + /* TODO: throw an error */ + return -999; + } + + tp_start_packno = 0; + + for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) { + while (pi_next(&pi[pino])) { + if ((cp->layer==0) || (cp->layer>=((pi[pino].layno)+1))) { + opj_packet_info_t *pack_info; + if (cstr_info) + pack_info = &cstr_info->tile[tileno].packet[cstr_info->packno]; + else + pack_info = NULL; + e = t2_decode_packet(t2, c, src + len - c, tile, &cp->tcps[tileno], &pi[pino], pack_info); + } else { + e = 0; + } + if(e == -999) + { + pi_destroy(pi, cp, tileno); + return -999; + } + /* progression in resolution */ + image->comps[pi[pino].compno].resno_decoded = + (e > 0) ? + int_max(pi[pino].resno, image->comps[pi[pino].compno].resno_decoded) + : image->comps[pi[pino].compno].resno_decoded; + n++; + + /* INDEX >> */ + if(cstr_info) { + opj_tile_info_t *info_TL = &cstr_info->tile[tileno]; + opj_packet_info_t *info_PK = &info_TL->packet[cstr_info->packno]; + if (!cstr_info->packno) { + info_PK->start_pos = info_TL->end_header + 1; + } else if (info_TL->packet[cstr_info->packno-1].end_pos >= (int)cstr_info->tile[tileno].tp[curtp].tp_end_pos){ /* New tile part*/ + info_TL->tp[curtp].tp_numpacks = cstr_info->packno - tp_start_packno; /* Number of packets in previous tile-part*/ + info_TL->tp[curtp].tp_start_pack = tp_start_packno; + tp_start_packno = cstr_info->packno; + curtp++; + info_PK->start_pos = cstr_info->tile[tileno].tp[curtp].tp_end_header+1; + } else { + info_PK->start_pos = (cp->tp_on && info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[cstr_info->packno - 1].end_pos + 1; + } + info_PK->end_pos = info_PK->start_pos + e - 1; + info_PK->end_ph_pos += info_PK->start_pos - 1; /* End of packet header which now only represents the distance + // to start of packet is incremented by value of start of packet*/ + cstr_info->packno++; + } + /* << INDEX */ + + if (e == -999) { /* ADD */ + break; + } else { + c += e; + } + } + } + /* INDEX >> */ + if(cstr_info) { + cstr_info->tile[tileno].tp[curtp].tp_numpacks = cstr_info->packno - tp_start_packno; /* Number of packets in last tile-part*/ + cstr_info->tile[tileno].tp[curtp].tp_start_pack = tp_start_packno; + } + /* << INDEX */ + + /* don't forget to release pi */ + pi_destroy(pi, cp, tileno); + + if (e == -999) { + return e; + } + + return (c - src); +} + +/* ----------------------------------------------------------------------- */ + +opj_t2_t* t2_create(opj_common_ptr cinfo, opj_image_t *image, opj_cp_t *cp) { + /* create the tcd structure */ + opj_t2_t *t2 = (opj_t2_t*)opj_malloc(sizeof(opj_t2_t)); + if(!t2) return NULL; + t2->cinfo = cinfo; + t2->image = image; + t2->cp = cp; + + return t2; +} + +void t2_destroy(opj_t2_t *t2) { + if(t2) { + opj_free(t2); + } +} + + + + + diff --git a/Source/LibOpenJPEG/t2.h b/Source/LibOpenJPEG/t2.h index bdb0d97..2151ba6 100644 --- a/Source/LibOpenJPEG/t2.h +++ b/Source/LibOpenJPEG/t2.h @@ -1,105 +1,105 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __T2_H -#define __T2_H -/** -@file t2.h -@brief Implementation of a tier-2 coding (packetization of code-block data) (T2) - -*/ - -/** @defgroup T2 T2 - Implementation of a tier-2 coding */ -/*@{*/ - -/** -Tier-2 coding -*/ -typedef struct opj_t2 { - /** codec context */ - opj_common_ptr cinfo; - - /** Encoding: pointer to the src image. Decoding: pointer to the dst image. */ - opj_image_t *image; - /** pointer to the image coding parameters */ - opj_cp_t *cp; -} opj_t2_t; - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ - -/** -Encode the packets of a tile to a destination buffer -@param t2 T2 handle -@param tileno number of the tile encoded -@param tile the tile for which to write the packets -@param maxlayers maximum number of layers -@param dest the destination buffer -@param len the length of the destination buffer -@param cstr_info Codestream information structure -@param tpnum Tile part number of the current tile -@param tppos The position of the tile part flag in the progression order -@param pino -@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass -@param cur_totnum_tp The total number of tile parts in the current tile -*/ -int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_codestream_info_t *cstr_info,int tpnum, int tppos,int pino,J2K_T2_MODE t2_mode,int cur_totnum_tp); -/** -Decode the packets of a tile from a source buffer -@param t2 T2 handle -@param src the source buffer -@param len length of the source buffer -@param tileno number that identifies the tile for which to decode the packets -@param tile tile for which to decode the packets -@param cstr_info Codestream information structure - */ -int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile, opj_codestream_info_t *cstr_info); - -/** -Create a T2 handle -@param cinfo Codec context info -@param image Source or destination image -@param cp Image coding parameters -@return Returns a new T2 handle if successful, returns NULL otherwise -*/ -opj_t2_t* t2_create(opj_common_ptr cinfo, opj_image_t *image, opj_cp_t *cp); -/** -Destroy a T2 handle -@param t2 T2 handle to destroy -*/ -void t2_destroy(opj_t2_t *t2); - -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __T2_H */ +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __T2_H +#define __T2_H +/** +@file t2.h +@brief Implementation of a tier-2 coding (packetization of code-block data) (T2) + +*/ + +/** @defgroup T2 T2 - Implementation of a tier-2 coding */ +/*@{*/ + +/** +Tier-2 coding +*/ +typedef struct opj_t2 { + /** codec context */ + opj_common_ptr cinfo; + + /** Encoding: pointer to the src image. Decoding: pointer to the dst image. */ + opj_image_t *image; + /** pointer to the image coding parameters */ + opj_cp_t *cp; +} opj_t2_t; + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ + +/** +Encode the packets of a tile to a destination buffer +@param t2 T2 handle +@param tileno number of the tile encoded +@param tile the tile for which to write the packets +@param maxlayers maximum number of layers +@param dest the destination buffer +@param len the length of the destination buffer +@param cstr_info Codestream information structure +@param tpnum Tile part number of the current tile +@param tppos The position of the tile part flag in the progression order +@param pino +@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass +@param cur_totnum_tp The total number of tile parts in the current tile +*/ +int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_codestream_info_t *cstr_info,int tpnum, int tppos,int pino,J2K_T2_MODE t2_mode,int cur_totnum_tp); +/** +Decode the packets of a tile from a source buffer +@param t2 T2 handle +@param src the source buffer +@param len length of the source buffer +@param tileno number that identifies the tile for which to decode the packets +@param tile tile for which to decode the packets +@param cstr_info Codestream information structure + */ +int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile, opj_codestream_info_t *cstr_info); + +/** +Create a T2 handle +@param cinfo Codec context info +@param image Source or destination image +@param cp Image coding parameters +@return Returns a new T2 handle if successful, returns NULL otherwise +*/ +opj_t2_t* t2_create(opj_common_ptr cinfo, opj_image_t *image, opj_cp_t *cp); +/** +Destroy a T2 handle +@param t2 T2 handle to destroy +*/ +void t2_destroy(opj_t2_t *t2); + +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __T2_H */ diff --git a/Source/LibOpenJPEG/tcd.c b/Source/LibOpenJPEG/tcd.c index 211ee32..ee05205 100644 --- a/Source/LibOpenJPEG/tcd.c +++ b/Source/LibOpenJPEG/tcd.c @@ -1,1574 +1,1574 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2006-2007, Parvatha Elangovan - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#define _ISOC99_SOURCE /* lrintf is C99 */ -#include "opj_includes.h" - -void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) { - int tileno, compno, resno, bandno, precno;/*, cblkno;*/ - - fprintf(fd, "image {\n"); - fprintf(fd, " tw=%d, th=%d x0=%d x1=%d y0=%d y1=%d\n", - img->tw, img->th, tcd->image->x0, tcd->image->x1, tcd->image->y0, tcd->image->y1); - - for (tileno = 0; tileno < img->th * img->tw; tileno++) { - opj_tcd_tile_t *tile = &tcd->tcd_image->tiles[tileno]; - fprintf(fd, " tile {\n"); - fprintf(fd, " x0=%d, y0=%d, x1=%d, y1=%d, numcomps=%d\n", - tile->x0, tile->y0, tile->x1, tile->y1, tile->numcomps); - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - fprintf(fd, " tilec {\n"); - fprintf(fd, - " x0=%d, y0=%d, x1=%d, y1=%d, numresolutions=%d\n", - tilec->x0, tilec->y0, tilec->x1, tilec->y1, tilec->numresolutions); - for (resno = 0; resno < tilec->numresolutions; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - fprintf(fd, "\n res {\n"); - fprintf(fd, - " x0=%d, y0=%d, x1=%d, y1=%d, pw=%d, ph=%d, numbands=%d\n", - res->x0, res->y0, res->x1, res->y1, res->pw, res->ph, res->numbands); - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - fprintf(fd, " band {\n"); - fprintf(fd, - " x0=%d, y0=%d, x1=%d, y1=%d, stepsize=%f, numbps=%d\n", - band->x0, band->y0, band->x1, band->y1, band->stepsize, band->numbps); - for (precno = 0; precno < res->pw * res->ph; precno++) { - opj_tcd_precinct_t *prec = &band->precincts[precno]; - fprintf(fd, " prec {\n"); - fprintf(fd, - " x0=%d, y0=%d, x1=%d, y1=%d, cw=%d, ch=%d\n", - prec->x0, prec->y0, prec->x1, prec->y1, prec->cw, prec->ch); - /* - for (cblkno = 0; cblkno < prec->cw * prec->ch; cblkno++) { - opj_tcd_cblk_t *cblk = &prec->cblks[cblkno]; - fprintf(fd, " cblk {\n"); - fprintf(fd, - " x0=%d, y0=%d, x1=%d, y1=%d\n", - cblk->x0, cblk->y0, cblk->x1, cblk->y1); - fprintf(fd, " }\n"); - } - */ - fprintf(fd, " }\n"); - } - fprintf(fd, " }\n"); - } - fprintf(fd, " }\n"); - } - fprintf(fd, " }\n"); - } - fprintf(fd, " }\n"); - } - fprintf(fd, "}\n"); -} - -/* ----------------------------------------------------------------------- */ - -/** -Create a new TCD handle -*/ -opj_tcd_t* tcd_create(opj_common_ptr cinfo) { - /* create the tcd structure */ - opj_tcd_t *tcd = (opj_tcd_t*)opj_malloc(sizeof(opj_tcd_t)); - if(!tcd) return NULL; - tcd->cinfo = cinfo; - tcd->tcd_image = (opj_tcd_image_t*)opj_malloc(sizeof(opj_tcd_image_t)); - if(!tcd->tcd_image) { - opj_free(tcd); - return NULL; - } - - return tcd; -} - -/** -Destroy a previously created TCD handle -*/ -void tcd_destroy(opj_tcd_t *tcd) { - if(tcd) { - opj_free(tcd->tcd_image); - opj_free(tcd); - } -} - -/* ----------------------------------------------------------------------- */ - -void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno) { - int tileno, compno, resno, bandno, precno, cblkno; - - tcd->image = image; - tcd->cp = cp; - tcd->tcd_image->tw = cp->tw; - tcd->tcd_image->th = cp->th; - tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_malloc(sizeof(opj_tcd_tile_t)); - - for (tileno = 0; tileno < 1; tileno++) { - opj_tcp_t *tcp = &cp->tcps[curtileno]; - int j; - - /* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ - int p = curtileno % cp->tw; /* si numerotation matricielle .. */ - int q = curtileno / cp->tw; /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */ - - /* opj_tcd_tile_t *tile=&tcd->tcd_image->tiles[tileno]; */ - opj_tcd_tile_t *tile = tcd->tcd_image->tiles; - - /* 4 borders of the tile rescale on the image if necessary */ - tile->x0 = int_max(cp->tx0 + p * cp->tdx, image->x0); - tile->y0 = int_max(cp->ty0 + q * cp->tdy, image->y0); - tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1); - tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1); - tile->numcomps = image->numcomps; - /* tile->PPT=image->PPT; */ - - /* Modification of the RATE >> */ - for (j = 0; j < tcp->numlayers; j++) { - tcp->rates[j] = tcp->rates[j] ? - cp->tp_on ? - (((float) (tile->numcomps - * (tile->x1 - tile->x0) - * (tile->y1 - tile->y0) - * image->comps[0].prec)) - /(tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy)) - (((tcd->cur_totnum_tp - 1) * 14 )/ tcp->numlayers) - : - ((float) (tile->numcomps - * (tile->x1 - tile->x0) - * (tile->y1 - tile->y0) - * image->comps[0].prec))/ - (tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy) - : 0; - - if (tcp->rates[j]) { - if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) { - tcp->rates[j] = tcp->rates[j - 1] + 20; - } else { - if (!j && tcp->rates[j] < 30) - tcp->rates[j] = 30; - } - - if(j == (tcp->numlayers-1)){ - tcp->rates[j] = tcp->rates[j]- 2; - } - } - } - /* << Modification of the RATE */ - - tile->comps = (opj_tcd_tilecomp_t *) opj_malloc(image->numcomps * sizeof(opj_tcd_tilecomp_t)); - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tccp_t *tccp = &tcp->tccps[compno]; - - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - - /* border of each tile component (global) */ - tilec->x0 = int_ceildiv(tile->x0, image->comps[compno].dx); - tilec->y0 = int_ceildiv(tile->y0, image->comps[compno].dy); - tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx); - tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy); - - tilec->data = (int *) opj_aligned_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * sizeof(int)); - tilec->numresolutions = tccp->numresolutions; - - tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(tilec->numresolutions * sizeof(opj_tcd_resolution_t)); - - for (resno = 0; resno < tilec->numresolutions; resno++) { - int pdx, pdy; - int levelno = tilec->numresolutions - 1 - resno; - int tlprcxstart, tlprcystart, brprcxend, brprcyend; - int tlcbgxstart, tlcbgystart, brcbgxend, brcbgyend; - int cbgwidthexpn, cbgheightexpn; - int cblkwidthexpn, cblkheightexpn; - - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - - /* border for each resolution level (global) */ - res->x0 = int_ceildivpow2(tilec->x0, levelno); - res->y0 = int_ceildivpow2(tilec->y0, levelno); - res->x1 = int_ceildivpow2(tilec->x1, levelno); - res->y1 = int_ceildivpow2(tilec->y1, levelno); - - res->numbands = resno == 0 ? 1 : 3; - /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */ - if (tccp->csty & J2K_CCP_CSTY_PRT) { - pdx = tccp->prcw[resno]; - pdy = tccp->prch[resno]; - } else { - pdx = 15; - pdy = 15; - } - /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ - tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx; - tlprcystart = int_floordivpow2(res->y0, pdy) << pdy; - - brprcxend = int_ceildivpow2(res->x1, pdx) << pdx; - brprcyend = int_ceildivpow2(res->y1, pdy) << pdy; - - res->pw = (brprcxend - tlprcxstart) >> pdx; - res->ph = (brprcyend - tlprcystart) >> pdy; - - if (resno == 0) { - tlcbgxstart = tlprcxstart; - tlcbgystart = tlprcystart; - brcbgxend = brprcxend; - brcbgyend = brprcyend; - cbgwidthexpn = pdx; - cbgheightexpn = pdy; - } else { - tlcbgxstart = int_ceildivpow2(tlprcxstart, 1); - tlcbgystart = int_ceildivpow2(tlprcystart, 1); - brcbgxend = int_ceildivpow2(brprcxend, 1); - brcbgyend = int_ceildivpow2(brprcyend, 1); - cbgwidthexpn = pdx - 1; - cbgheightexpn = pdy - 1; - } - - cblkwidthexpn = int_min(tccp->cblkw, cbgwidthexpn); - cblkheightexpn = int_min(tccp->cblkh, cbgheightexpn); - - for (bandno = 0; bandno < res->numbands; bandno++) { - int x0b, y0b, i; - int gain, numbps; - opj_stepsize_t *ss = NULL; - - opj_tcd_band_t *band = &res->bands[bandno]; - - band->bandno = resno == 0 ? 0 : bandno + 1; - x0b = (band->bandno == 1) || (band->bandno == 3) ? 1 : 0; - y0b = (band->bandno == 2) || (band->bandno == 3) ? 1 : 0; - - if (band->bandno == 0) { - /* band border (global) */ - band->x0 = int_ceildivpow2(tilec->x0, levelno); - band->y0 = int_ceildivpow2(tilec->y0, levelno); - band->x1 = int_ceildivpow2(tilec->x1, levelno); - band->y1 = int_ceildivpow2(tilec->y1, levelno); - } else { - /* band border (global) */ - band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelno) * x0b, levelno + 1); - band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelno) * y0b, levelno + 1); - band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelno) * x0b, levelno + 1); - band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelno) * y0b, levelno + 1); - } - - ss = &tccp->stepsizes[resno == 0 ? 0 : 3 * (resno - 1) + bandno + 1]; - gain = tccp->qmfbid == 0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno); - numbps = image->comps[compno].prec + gain; - - band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn)); - band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */ - - band->precincts = (opj_tcd_precinct_t *) opj_malloc(3 * res->pw * res->ph * sizeof(opj_tcd_precinct_t)); - - for (i = 0; i < res->pw * res->ph * 3; i++) { - band->precincts[i].imsbtree = NULL; - band->precincts[i].incltree = NULL; - band->precincts[i].cblks.enc = NULL; - } - - for (precno = 0; precno < res->pw * res->ph; precno++) { - int tlcblkxstart, tlcblkystart, brcblkxend, brcblkyend; - - int cbgxstart = tlcbgxstart + (precno % res->pw) * (1 << cbgwidthexpn); - int cbgystart = tlcbgystart + (precno / res->pw) * (1 << cbgheightexpn); - int cbgxend = cbgxstart + (1 << cbgwidthexpn); - int cbgyend = cbgystart + (1 << cbgheightexpn); - - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - /* precinct size (global) */ - prc->x0 = int_max(cbgxstart, band->x0); - prc->y0 = int_max(cbgystart, band->y0); - prc->x1 = int_min(cbgxend, band->x1); - prc->y1 = int_min(cbgyend, band->y1); - - tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn; - tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn; - brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn; - brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn; - prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; - prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn; - - prc->cblks.enc = (opj_tcd_cblk_enc_t*) opj_calloc((prc->cw * prc->ch), sizeof(opj_tcd_cblk_enc_t)); - prc->incltree = tgt_create(prc->cw, prc->ch); - prc->imsbtree = tgt_create(prc->cw, prc->ch); - - for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { - int cblkxstart = tlcblkxstart + (cblkno % prc->cw) * (1 << cblkwidthexpn); - int cblkystart = tlcblkystart + (cblkno / prc->cw) * (1 << cblkheightexpn); - int cblkxend = cblkxstart + (1 << cblkwidthexpn); - int cblkyend = cblkystart + (1 << cblkheightexpn); - - opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; - - /* code-block size (global) */ - cblk->x0 = int_max(cblkxstart, prc->x0); - cblk->y0 = int_max(cblkystart, prc->y0); - cblk->x1 = int_min(cblkxend, prc->x1); - cblk->y1 = int_min(cblkyend, prc->y1); - cblk->data = (unsigned char*) opj_calloc(9728+2, sizeof(unsigned char)); - /* FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? */ - cblk->data[0] = 0; - cblk->data[1] = 0; - cblk->data += 2; - cblk->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t)); - cblk->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t)); - } - } - } - } - } - } - - /* tcd_dump(stdout, tcd, &tcd->tcd_image); */ -} - -void tcd_free_encode(opj_tcd_t *tcd) { - int tileno, compno, resno, bandno, precno, cblkno; - - for (tileno = 0; tileno < 1; tileno++) { - opj_tcd_tile_t *tile = tcd->tcd_image->tiles; - - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - - for (resno = 0; resno < tilec->numresolutions; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - - for (precno = 0; precno < res->pw * res->ph; precno++) { - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - if (prc->incltree != NULL) { - tgt_destroy(prc->incltree); - prc->incltree = NULL; - } - if (prc->imsbtree != NULL) { - tgt_destroy(prc->imsbtree); - prc->imsbtree = NULL; - } - for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { - opj_free(prc->cblks.enc[cblkno].data - 2); - opj_free(prc->cblks.enc[cblkno].layers); - opj_free(prc->cblks.enc[cblkno].passes); - } - opj_free(prc->cblks.enc); - } /* for (precno */ - opj_free(band->precincts); - band->precincts = NULL; - } /* for (bandno */ - } /* for (resno */ - opj_free(tilec->resolutions); - tilec->resolutions = NULL; - } /* for (compno */ - opj_free(tile->comps); - tile->comps = NULL; - } /* for (tileno */ - opj_free(tcd->tcd_image->tiles); - tcd->tcd_image->tiles = NULL; -} - -void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno) { - int tileno, compno, resno, bandno, precno, cblkno; - - for (tileno = 0; tileno < 1; tileno++) { - opj_tcp_t *tcp = &cp->tcps[curtileno]; - int j; - /* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ - int p = curtileno % cp->tw; - int q = curtileno / cp->tw; - - opj_tcd_tile_t *tile = tcd->tcd_image->tiles; - - /* 4 borders of the tile rescale on the image if necessary */ - tile->x0 = int_max(cp->tx0 + p * cp->tdx, image->x0); - tile->y0 = int_max(cp->ty0 + q * cp->tdy, image->y0); - tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1); - tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1); - - tile->numcomps = image->numcomps; - /* tile->PPT=image->PPT; */ - - /* Modification of the RATE >> */ - for (j = 0; j < tcp->numlayers; j++) { - tcp->rates[j] = tcp->rates[j] ? - cp->tp_on ? - (((float) (tile->numcomps - * (tile->x1 - tile->x0) - * (tile->y1 - tile->y0) - * image->comps[0].prec)) - /(tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy)) - (((tcd->cur_totnum_tp - 1) * 14 )/ tcp->numlayers) - : - ((float) (tile->numcomps - * (tile->x1 - tile->x0) - * (tile->y1 - tile->y0) - * image->comps[0].prec))/ - (tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy) - : 0; - - if (tcp->rates[j]) { - if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) { - tcp->rates[j] = tcp->rates[j - 1] + 20; - } else { - if (!j && tcp->rates[j] < 30) - tcp->rates[j] = 30; - } - } - } - /* << Modification of the RATE */ - - /* tile->comps=(opj_tcd_tilecomp_t*)opj_realloc(tile->comps,image->numcomps*sizeof(opj_tcd_tilecomp_t)); */ - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tccp_t *tccp = &tcp->tccps[compno]; - - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - - /* border of each tile component (global) */ - tilec->x0 = int_ceildiv(tile->x0, image->comps[compno].dx); - tilec->y0 = int_ceildiv(tile->y0, image->comps[compno].dy); - tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx); - tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy); - - tilec->data = (int *) opj_aligned_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * sizeof(int)); - tilec->numresolutions = tccp->numresolutions; - /* tilec->resolutions=(opj_tcd_resolution_t*)opj_realloc(tilec->resolutions,tilec->numresolutions*sizeof(opj_tcd_resolution_t)); */ - for (resno = 0; resno < tilec->numresolutions; resno++) { - int pdx, pdy; - - int levelno = tilec->numresolutions - 1 - resno; - int tlprcxstart, tlprcystart, brprcxend, brprcyend; - int tlcbgxstart, tlcbgystart, brcbgxend, brcbgyend; - int cbgwidthexpn, cbgheightexpn; - int cblkwidthexpn, cblkheightexpn; - - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - - /* border for each resolution level (global) */ - res->x0 = int_ceildivpow2(tilec->x0, levelno); - res->y0 = int_ceildivpow2(tilec->y0, levelno); - res->x1 = int_ceildivpow2(tilec->x1, levelno); - res->y1 = int_ceildivpow2(tilec->y1, levelno); - res->numbands = resno == 0 ? 1 : 3; - - /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */ - if (tccp->csty & J2K_CCP_CSTY_PRT) { - pdx = tccp->prcw[resno]; - pdy = tccp->prch[resno]; - } else { - pdx = 15; - pdy = 15; - } - /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ - tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx; - tlprcystart = int_floordivpow2(res->y0, pdy) << pdy; - brprcxend = int_ceildivpow2(res->x1, pdx) << pdx; - brprcyend = int_ceildivpow2(res->y1, pdy) << pdy; - - res->pw = (brprcxend - tlprcxstart) >> pdx; - res->ph = (brprcyend - tlprcystart) >> pdy; - - if (resno == 0) { - tlcbgxstart = tlprcxstart; - tlcbgystart = tlprcystart; - brcbgxend = brprcxend; - brcbgyend = brprcyend; - cbgwidthexpn = pdx; - cbgheightexpn = pdy; - } else { - tlcbgxstart = int_ceildivpow2(tlprcxstart, 1); - tlcbgystart = int_ceildivpow2(tlprcystart, 1); - brcbgxend = int_ceildivpow2(brprcxend, 1); - brcbgyend = int_ceildivpow2(brprcyend, 1); - cbgwidthexpn = pdx - 1; - cbgheightexpn = pdy - 1; - } - - cblkwidthexpn = int_min(tccp->cblkw, cbgwidthexpn); - cblkheightexpn = int_min(tccp->cblkh, cbgheightexpn); - - for (bandno = 0; bandno < res->numbands; bandno++) { - int x0b, y0b; - int gain, numbps; - opj_stepsize_t *ss = NULL; - - opj_tcd_band_t *band = &res->bands[bandno]; - - band->bandno = resno == 0 ? 0 : bandno + 1; - x0b = (band->bandno == 1) || (band->bandno == 3) ? 1 : 0; - y0b = (band->bandno == 2) || (band->bandno == 3) ? 1 : 0; - - if (band->bandno == 0) { - /* band border */ - band->x0 = int_ceildivpow2(tilec->x0, levelno); - band->y0 = int_ceildivpow2(tilec->y0, levelno); - band->x1 = int_ceildivpow2(tilec->x1, levelno); - band->y1 = int_ceildivpow2(tilec->y1, levelno); - } else { - band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelno) * x0b, levelno + 1); - band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelno) * y0b, levelno + 1); - band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelno) * x0b, levelno + 1); - band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelno) * y0b, levelno + 1); - } - - ss = &tccp->stepsizes[resno == 0 ? 0 : 3 * (resno - 1) + bandno + 1]; - gain = tccp->qmfbid == 0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno); - numbps = image->comps[compno].prec + gain; - band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn)); - band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */ - - for (precno = 0; precno < res->pw * res->ph; precno++) { - int tlcblkxstart, tlcblkystart, brcblkxend, brcblkyend; - - int cbgxstart = tlcbgxstart + (precno % res->pw) * (1 << cbgwidthexpn); - int cbgystart = tlcbgystart + (precno / res->pw) * (1 << cbgheightexpn); - int cbgxend = cbgxstart + (1 << cbgwidthexpn); - int cbgyend = cbgystart + (1 << cbgheightexpn); - - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - /* precinct size (global) */ - prc->x0 = int_max(cbgxstart, band->x0); - prc->y0 = int_max(cbgystart, band->y0); - prc->x1 = int_min(cbgxend, band->x1); - prc->y1 = int_min(cbgyend, band->y1); - - tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn; - tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn; - brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn; - brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn; - prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; - prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn; - - opj_free(prc->cblks.enc); - prc->cblks.enc = (opj_tcd_cblk_enc_t*) opj_calloc(prc->cw * prc->ch, sizeof(opj_tcd_cblk_enc_t)); - - if (prc->incltree != NULL) { - tgt_destroy(prc->incltree); - } - if (prc->imsbtree != NULL) { - tgt_destroy(prc->imsbtree); - } - - prc->incltree = tgt_create(prc->cw, prc->ch); - prc->imsbtree = tgt_create(prc->cw, prc->ch); - - for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { - int cblkxstart = tlcblkxstart + (cblkno % prc->cw) * (1 << cblkwidthexpn); - int cblkystart = tlcblkystart + (cblkno / prc->cw) * (1 << cblkheightexpn); - int cblkxend = cblkxstart + (1 << cblkwidthexpn); - int cblkyend = cblkystart + (1 << cblkheightexpn); - - opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; - - /* code-block size (global) */ - cblk->x0 = int_max(cblkxstart, prc->x0); - cblk->y0 = int_max(cblkystart, prc->y0); - cblk->x1 = int_min(cblkxend, prc->x1); - cblk->y1 = int_min(cblkyend, prc->y1); - cblk->data = (unsigned char*) opj_calloc(8192+2, sizeof(unsigned char)); - /* FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? */ - cblk->data[0] = 0; - cblk->data[1] = 0; - cblk->data += 2; - cblk->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t)); - cblk->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t)); - } - } /* precno */ - } /* bandno */ - } /* resno */ - } /* compno */ - } /* tileno */ - - /* tcd_dump(stdout, tcd, &tcd->tcd_image); */ -} - -void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp) { - int i, j, tileno, p, q; - unsigned int x0 = 0, y0 = 0, x1 = 0, y1 = 0, w, h; - - tcd->image = image; - tcd->tcd_image->tw = cp->tw; - tcd->tcd_image->th = cp->th; - tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_calloc(cp->tw * cp->th, sizeof(opj_tcd_tile_t)); - - /* - Allocate place to store the decoded data = final image - Place limited by the tile really present in the codestream - */ - - for (j = 0; j < cp->tileno_size; j++) { - opj_tcd_tile_t *tile; - - tileno = cp->tileno[j]; - tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]); - tile->numcomps = image->numcomps; - tile->comps = (opj_tcd_tilecomp_t*) opj_calloc(image->numcomps, sizeof(opj_tcd_tilecomp_t)); - } - - for (i = 0; i < image->numcomps; i++) { - for (j = 0; j < cp->tileno_size; j++) { - opj_tcd_tile_t *tile; - opj_tcd_tilecomp_t *tilec; - - /* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ - - tileno = cp->tileno[j]; - - tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]); - tilec = &tile->comps[i]; - - p = tileno % cp->tw; /* si numerotation matricielle .. */ - q = tileno / cp->tw; /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */ - - /* 4 borders of the tile rescale on the image if necessary */ - tile->x0 = int_max(cp->tx0 + p * cp->tdx, image->x0); - tile->y0 = int_max(cp->ty0 + q * cp->tdy, image->y0); - tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1); - tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1); - - tilec->x0 = int_ceildiv(tile->x0, image->comps[i].dx); - tilec->y0 = int_ceildiv(tile->y0, image->comps[i].dy); - tilec->x1 = int_ceildiv(tile->x1, image->comps[i].dx); - tilec->y1 = int_ceildiv(tile->y1, image->comps[i].dy); - - x0 = j == 0 ? tilec->x0 : int_min(x0, (unsigned int) tilec->x0); - y0 = j == 0 ? tilec->y0 : int_min(y0, (unsigned int) tilec->y0); - x1 = j == 0 ? tilec->x1 : int_max(x1, (unsigned int) tilec->x1); - y1 = j == 0 ? tilec->y1 : int_max(y1, (unsigned int) tilec->y1); - } - - w = int_ceildivpow2(x1 - x0, image->comps[i].factor); - h = int_ceildivpow2(y1 - y0, image->comps[i].factor); - - image->comps[i].w = w; - image->comps[i].h = h; - image->comps[i].x0 = x0; - image->comps[i].y0 = y0; - } -} - -void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int tileno, opj_codestream_info_t *cstr_info) { - int compno, resno, bandno, precno, cblkno; - opj_tcp_t *tcp; - opj_tcd_tile_t *tile; - - OPJ_ARG_NOT_USED(cstr_info); - - tcd->cp = cp; - - tcp = &(cp->tcps[cp->tileno[tileno]]); - tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]); - - tileno = cp->tileno[tileno]; - - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tccp_t *tccp = &tcp->tccps[compno]; - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - - if (tccp->numresolutions <= 0) - { - cp->tileno[tileno] = -1; - return; - } - - /* border of each tile component (global) */ - tilec->x0 = int_ceildiv(tile->x0, image->comps[compno].dx); - tilec->y0 = int_ceildiv(tile->y0, image->comps[compno].dy); - tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx); - tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy); - - tilec->numresolutions = tccp->numresolutions; - tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(tilec->numresolutions * sizeof(opj_tcd_resolution_t)); - - for (resno = 0; resno < tilec->numresolutions; resno++) { - int pdx, pdy; - int levelno = tilec->numresolutions - 1 - resno; - int tlprcxstart, tlprcystart, brprcxend, brprcyend; - int tlcbgxstart, tlcbgystart, brcbgxend, brcbgyend; - int cbgwidthexpn, cbgheightexpn; - int cblkwidthexpn, cblkheightexpn; - - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - - /* border for each resolution level (global) */ - res->x0 = int_ceildivpow2(tilec->x0, levelno); - res->y0 = int_ceildivpow2(tilec->y0, levelno); - res->x1 = int_ceildivpow2(tilec->x1, levelno); - res->y1 = int_ceildivpow2(tilec->y1, levelno); - res->numbands = resno == 0 ? 1 : 3; - - /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */ - if (tccp->csty & J2K_CCP_CSTY_PRT) { - pdx = tccp->prcw[resno]; - pdy = tccp->prch[resno]; - } else { - pdx = 15; - pdy = 15; - } - - /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ - tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx; - tlprcystart = int_floordivpow2(res->y0, pdy) << pdy; - brprcxend = int_ceildivpow2(res->x1, pdx) << pdx; - brprcyend = int_ceildivpow2(res->y1, pdy) << pdy; - - res->pw = (res->x0 == res->x1) ? 0 : ((brprcxend - tlprcxstart) >> pdx); - res->ph = (res->y0 == res->y1) ? 0 : ((brprcyend - tlprcystart) >> pdy); - - if (resno == 0) { - tlcbgxstart = tlprcxstart; - tlcbgystart = tlprcystart; - brcbgxend = brprcxend; - brcbgyend = brprcyend; - cbgwidthexpn = pdx; - cbgheightexpn = pdy; - } else { - tlcbgxstart = int_ceildivpow2(tlprcxstart, 1); - tlcbgystart = int_ceildivpow2(tlprcystart, 1); - brcbgxend = int_ceildivpow2(brprcxend, 1); - brcbgyend = int_ceildivpow2(brprcyend, 1); - cbgwidthexpn = pdx - 1; - cbgheightexpn = pdy - 1; - } - - cblkwidthexpn = int_min(tccp->cblkw, cbgwidthexpn); - cblkheightexpn = int_min(tccp->cblkh, cbgheightexpn); - - for (bandno = 0; bandno < res->numbands; bandno++) { - int x0b, y0b; - int gain, numbps; - opj_stepsize_t *ss = NULL; - - opj_tcd_band_t *band = &res->bands[bandno]; - band->bandno = resno == 0 ? 0 : bandno + 1; - x0b = (band->bandno == 1) || (band->bandno == 3) ? 1 : 0; - y0b = (band->bandno == 2) || (band->bandno == 3) ? 1 : 0; - - if (band->bandno == 0) { - /* band border (global) */ - band->x0 = int_ceildivpow2(tilec->x0, levelno); - band->y0 = int_ceildivpow2(tilec->y0, levelno); - band->x1 = int_ceildivpow2(tilec->x1, levelno); - band->y1 = int_ceildivpow2(tilec->y1, levelno); - } else { - /* band border (global) */ - band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelno) * x0b, levelno + 1); - band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelno) * y0b, levelno + 1); - band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelno) * x0b, levelno + 1); - band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelno) * y0b, levelno + 1); - } - - ss = &tccp->stepsizes[resno == 0 ? 0 : 3 * (resno - 1) + bandno + 1]; - gain = tccp->qmfbid == 0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno); - numbps = image->comps[compno].prec + gain; - band->stepsize = (float)(((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn)) * 0.5); - band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */ - - band->precincts = (opj_tcd_precinct_t *) opj_malloc(res->pw * res->ph * sizeof(opj_tcd_precinct_t)); - - for (precno = 0; precno < res->pw * res->ph; precno++) { - int tlcblkxstart, tlcblkystart, brcblkxend, brcblkyend; - int cbgxstart = tlcbgxstart + (precno % res->pw) * (1 << cbgwidthexpn); - int cbgystart = tlcbgystart + (precno / res->pw) * (1 << cbgheightexpn); - int cbgxend = cbgxstart + (1 << cbgwidthexpn); - int cbgyend = cbgystart + (1 << cbgheightexpn); - - opj_tcd_precinct_t *prc = &band->precincts[precno]; - /* precinct size (global) */ - prc->x0 = int_max(cbgxstart, band->x0); - prc->y0 = int_max(cbgystart, band->y0); - prc->x1 = int_min(cbgxend, band->x1); - prc->y1 = int_min(cbgyend, band->y1); - - tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn; - tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn; - brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn; - brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn; - prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; - prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn; - - prc->cblks.dec = (opj_tcd_cblk_dec_t*) opj_malloc(prc->cw * prc->ch * sizeof(opj_tcd_cblk_dec_t)); - - prc->incltree = tgt_create(prc->cw, prc->ch); - prc->imsbtree = tgt_create(prc->cw, prc->ch); - - for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { - int cblkxstart = tlcblkxstart + (cblkno % prc->cw) * (1 << cblkwidthexpn); - int cblkystart = tlcblkystart + (cblkno / prc->cw) * (1 << cblkheightexpn); - int cblkxend = cblkxstart + (1 << cblkwidthexpn); - int cblkyend = cblkystart + (1 << cblkheightexpn); - - opj_tcd_cblk_dec_t* cblk = &prc->cblks.dec[cblkno]; - cblk->data = NULL; - cblk->segs = NULL; - /* code-block size (global) */ - cblk->x0 = int_max(cblkxstart, prc->x0); - cblk->y0 = int_max(cblkystart, prc->y0); - cblk->x1 = int_min(cblkxend, prc->x1); - cblk->y1 = int_min(cblkyend, prc->y1); - cblk->numsegs = 0; - } - } /* precno */ - } /* bandno */ - } /* resno */ - } /* compno */ - /* tcd_dump(stdout, tcd, &tcd->tcd_image); */ -} - -void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final) { - int compno, resno, bandno, precno, cblkno; - int value; /*, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolutions][3]; */ - int matrice[10][10][3]; - int i, j, k; - - opj_cp_t *cp = tcd->cp; - opj_tcd_tile_t *tcd_tile = tcd->tcd_tile; - opj_tcp_t *tcd_tcp = tcd->tcp; - - /*matrice=(int*)opj_malloc(tcd_tcp->numlayers*tcd_tile->comps[0].numresolutions*3*sizeof(int)); */ - - for (compno = 0; compno < tcd_tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; - for (i = 0; i < tcd_tcp->numlayers; i++) { - for (j = 0; j < tilec->numresolutions; j++) { - for (k = 0; k < 3; k++) { - matrice[i][j][k] = - (int) (cp->matrice[i * tilec->numresolutions * 3 + j * 3 + k] - * (float) (tcd->image->comps[compno].prec / 16.0)); - } - } - } - - for (resno = 0; resno < tilec->numresolutions; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - for (precno = 0; precno < res->pw * res->ph; precno++) { - opj_tcd_precinct_t *prc = &band->precincts[precno]; - for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { - opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno]; - opj_tcd_layer_t *layer = &cblk->layers[layno]; - int n; - int imsb = tcd->image->comps[compno].prec - cblk->numbps; /* number of bit-plan equal to zero */ - /* Correction of the matrix of coefficient to include the IMSB information */ - if (layno == 0) { - value = matrice[layno][resno][bandno]; - if (imsb >= value) { - value = 0; - } else { - value -= imsb; - } - } else { - value = matrice[layno][resno][bandno] - matrice[layno - 1][resno][bandno]; - if (imsb >= matrice[layno - 1][resno][bandno]) { - value -= (imsb - matrice[layno - 1][resno][bandno]); - if (value < 0) { - value = 0; - } - } - } - - if (layno == 0) { - cblk->numpassesinlayers = 0; - } - - n = cblk->numpassesinlayers; - if (cblk->numpassesinlayers == 0) { - if (value != 0) { - n = 3 * value - 2 + cblk->numpassesinlayers; - } else { - n = cblk->numpassesinlayers; - } - } else { - n = 3 * value + cblk->numpassesinlayers; - } - - layer->numpasses = n - cblk->numpassesinlayers; - - if (!layer->numpasses) - continue; - - if (cblk->numpassesinlayers == 0) { - layer->len = cblk->passes[n - 1].rate; - layer->data = cblk->data; - } else { - layer->len = cblk->passes[n - 1].rate - cblk->passes[cblk->numpassesinlayers - 1].rate; - layer->data = cblk->data + cblk->passes[cblk->numpassesinlayers - 1].rate; - } - if (final) - cblk->numpassesinlayers = n; - } - } - } - } - } -} - -void tcd_rateallocate_fixed(opj_tcd_t *tcd) { - int layno; - for (layno = 0; layno < tcd->tcp->numlayers; layno++) { - tcd_makelayer_fixed(tcd, layno, 1); - } -} - -void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final) { - int compno, resno, bandno, precno, cblkno, passno; - - opj_tcd_tile_t *tcd_tile = tcd->tcd_tile; - - tcd_tile->distolayer[layno] = 0; /* fixed_quality */ - - for (compno = 0; compno < tcd_tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; - for (resno = 0; resno < tilec->numresolutions; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - for (precno = 0; precno < res->pw * res->ph; precno++) { - opj_tcd_precinct_t *prc = &band->precincts[precno]; - for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { - opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno]; - opj_tcd_layer_t *layer = &cblk->layers[layno]; - - int n; - if (layno == 0) { - cblk->numpassesinlayers = 0; - } - n = cblk->numpassesinlayers; - for (passno = cblk->numpassesinlayers; passno < cblk->totalpasses; passno++) { - int dr; - double dd; - opj_tcd_pass_t *pass = &cblk->passes[passno]; - if (n == 0) { - dr = pass->rate; - dd = pass->distortiondec; - } else { - dr = pass->rate - cblk->passes[n - 1].rate; - dd = pass->distortiondec - cblk->passes[n - 1].distortiondec; - } - if (!dr) { - if (dd != 0) - n = passno + 1; - continue; - } - if (dd / dr >= thresh) - n = passno + 1; - } - layer->numpasses = n - cblk->numpassesinlayers; - - if (!layer->numpasses) { - layer->disto = 0; - continue; - } - if (cblk->numpassesinlayers == 0) { - layer->len = cblk->passes[n - 1].rate; - layer->data = cblk->data; - layer->disto = cblk->passes[n - 1].distortiondec; - } else { - layer->len = cblk->passes[n - 1].rate - cblk->passes[cblk->numpassesinlayers - 1].rate; - layer->data = cblk->data + cblk->passes[cblk->numpassesinlayers - 1].rate; - layer->disto = cblk->passes[n - 1].distortiondec - cblk->passes[cblk->numpassesinlayers - 1].distortiondec; - } - - tcd_tile->distolayer[layno] += layer->disto; /* fixed_quality */ - - if (final) - cblk->numpassesinlayers = n; - } - } - } - } - } -} - -opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) { - int compno, resno, bandno, precno, cblkno, passno, layno; - double min, max; - double cumdisto[100]; /* fixed_quality */ - const double K = 1; /* 1.1; fixed_quality */ - double maxSE = 0; - - opj_cp_t *cp = tcd->cp; - opj_tcd_tile_t *tcd_tile = tcd->tcd_tile; - opj_tcp_t *tcd_tcp = tcd->tcp; - - min = DBL_MAX; - max = 0; - - tcd_tile->numpix = 0; /* fixed_quality */ - - for (compno = 0; compno < tcd_tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; - tilec->numpix = 0; - - for (resno = 0; resno < tilec->numresolutions; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - - for (precno = 0; precno < res->pw * res->ph; precno++) { - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { - opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno]; - - for (passno = 0; passno < cblk->totalpasses; passno++) { - opj_tcd_pass_t *pass = &cblk->passes[passno]; - int dr; - double dd, rdslope; - if (passno == 0) { - dr = pass->rate; - dd = pass->distortiondec; - } else { - dr = pass->rate - cblk->passes[passno - 1].rate; - dd = pass->distortiondec - cblk->passes[passno - 1].distortiondec; - } - if (dr == 0) { - continue; - } - rdslope = dd / dr; - if (rdslope < min) { - min = rdslope; - } - if (rdslope > max) { - max = rdslope; - } - } /* passno */ - - /* fixed_quality */ - tcd_tile->numpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); - tilec->numpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); - } /* cbklno */ - } /* precno */ - } /* bandno */ - } /* resno */ - - maxSE += (((double)(1 << tcd->image->comps[compno].prec) - 1.0) - * ((double)(1 << tcd->image->comps[compno].prec) -1.0)) - * ((double)(tilec->numpix)); - } /* compno */ - - /* index file */ - if(cstr_info) { - opj_tile_info_t *tile_info = &cstr_info->tile[tcd->tcd_tileno]; - tile_info->numpix = tcd_tile->numpix; - tile_info->distotile = tcd_tile->distotile; - tile_info->thresh = (double *) opj_malloc(tcd_tcp->numlayers * sizeof(double)); - } - - for (layno = 0; layno < tcd_tcp->numlayers; layno++) { - double lo = min; - double hi = max; - int success = 0; - int maxlen = tcd_tcp->rates[layno] ? int_min(((int) ceil(tcd_tcp->rates[layno])), len) : len; - double goodthresh = 0; - double stable_thresh = 0; - int i; - double distotarget; /* fixed_quality */ - - /* fixed_quality */ - distotarget = tcd_tile->distotile - ((K * maxSE) / pow((float)10, tcd_tcp->distoratio[layno] / 10)); - - /* Don't try to find an optimal threshold but rather take everything not included yet, if - -r xx,yy,zz,0 (disto_alloc == 1 and rates == 0) - -q xx,yy,zz,0 (fixed_quality == 1 and distoratio == 0) - ==> possible to have some lossy layers and the last layer for sure lossless */ - if ( ((cp->disto_alloc==1) && (tcd_tcp->rates[layno]>0)) || ((cp->fixed_quality==1) && (tcd_tcp->distoratio[layno]>0))) { - opj_t2_t *t2 = t2_create(tcd->cinfo, tcd->image, cp); - double thresh = 0; - - for (i = 0; i < 128; i++) { - int l = 0; - double distoachieved = 0; /* fixed_quality */ - thresh = (lo + hi) / 2; - - tcd_makelayer(tcd, layno, thresh, 0); - - if (cp->fixed_quality) { /* fixed_quality */ - if(cp->cinema){ - l = t2_encode_packets(t2,tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC, tcd->cur_totnum_tp); - if (l == -999) { - lo = thresh; - continue; - }else{ - distoachieved = layno == 0 ? - tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno]; - if (distoachieved < distotarget) { - hi=thresh; - stable_thresh = thresh; - continue; - }else{ - lo=thresh; - } - } - }else{ - distoachieved = (layno == 0) ? - tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]); - if (distoachieved < distotarget) { - hi = thresh; - stable_thresh = thresh; - continue; - } - lo = thresh; - } - } else { - l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC, tcd->cur_totnum_tp); - /* TODO: what to do with l ??? seek / tell ??? */ - /* opj_event_msg(tcd->cinfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, maxlen); */ - if (l == -999) { - lo = thresh; - continue; - } - hi = thresh; - stable_thresh = thresh; - } - } - success = 1; - goodthresh = stable_thresh == 0? thresh : stable_thresh; - t2_destroy(t2); - } else { - success = 1; - goodthresh = min; - } - - if (!success) { - return OPJ_FALSE; - } - - if(cstr_info) { /* Threshold for Marcela Index */ - cstr_info->tile[tcd->tcd_tileno].thresh[layno] = goodthresh; - } - tcd_makelayer(tcd, layno, goodthresh, 1); - - /* fixed_quality */ - cumdisto[layno] = (layno == 0) ? tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]); - } - - return OPJ_TRUE; -} - -int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) { - int compno; - int l, i, numpacks = 0; - opj_tcd_tile_t *tile = NULL; - opj_tcp_t *tcd_tcp = NULL; - opj_cp_t *cp = NULL; - - opj_tcp_t *tcp = &tcd->cp->tcps[0]; - opj_tccp_t *tccp = &tcp->tccps[0]; - opj_image_t *image = tcd->image; - - opj_t1_t *t1 = NULL; /* T1 component */ - opj_t2_t *t2 = NULL; /* T2 component */ - - tcd->tcd_tileno = tileno; - tcd->tcd_tile = tcd->tcd_image->tiles; - tcd->tcp = &tcd->cp->tcps[tileno]; - - tile = tcd->tcd_tile; - tcd_tcp = tcd->tcp; - cp = tcd->cp; - - if(tcd->cur_tp_num == 0){ - tcd->encoding_time = opj_clock(); /* time needed to encode a tile */ - /* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */ - if(cstr_info) { - opj_tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /* based on component 0 */ - for (i = 0; i < tilec_idx->numresolutions; i++) { - opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[i]; - - cstr_info->tile[tileno].pw[i] = res_idx->pw; - cstr_info->tile[tileno].ph[i] = res_idx->ph; - - numpacks += res_idx->pw * res_idx->ph; - - cstr_info->tile[tileno].pdx[i] = tccp->prcw[i]; - cstr_info->tile[tileno].pdy[i] = tccp->prch[i]; - } - cstr_info->tile[tileno].packet = (opj_packet_info_t*) opj_calloc(cstr_info->numcomps * cstr_info->numlayers * numpacks, sizeof(opj_packet_info_t)); - } - /* << INDEX */ - - /*---------------TILE-------------------*/ - - for (compno = 0; compno < tile->numcomps; compno++) { - int x, y; - - int adjust = image->comps[compno].sgnd ? 0 : 1 << (image->comps[compno].prec - 1); - int offset_x = int_ceildiv(image->x0, image->comps[compno].dx); - int offset_y = int_ceildiv(image->y0, image->comps[compno].dy); - - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - int tw = tilec->x1 - tilec->x0; - int w = int_ceildiv(image->x1 - image->x0, image->comps[compno].dx); - - /* extract tile data */ - - if (tcd_tcp->tccps[compno].qmfbid == 1) { - for (y = tilec->y0; y < tilec->y1; y++) { - /* start of the src tile scanline */ - int *data = &image->comps[compno].data[(tilec->x0 - offset_x) + (y - offset_y) * w]; - /* start of the dst tile scanline */ - int *tile_data = &tilec->data[(y - tilec->y0) * tw]; - for (x = tilec->x0; x < tilec->x1; x++) { - *tile_data++ = *data++ - adjust; - } - } - } else if (tcd_tcp->tccps[compno].qmfbid == 0) { - for (y = tilec->y0; y < tilec->y1; y++) { - /* start of the src tile scanline */ - int *data = &image->comps[compno].data[(tilec->x0 - offset_x) + (y - offset_y) * w]; - /* start of the dst tile scanline */ - int *tile_data = &tilec->data[(y - tilec->y0) * tw]; - for (x = tilec->x0; x < tilec->x1; x++) { - *tile_data++ = (*data++ - adjust) << 11; - } - - } - } - } - - /*----------------MCT-------------------*/ - if (tcd_tcp->mct) { - int samples = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0); - if (tcd_tcp->tccps[0].qmfbid == 0) { - mct_encode_real(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, samples); - } else { - mct_encode(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, samples); - } - } - - /*----------------DWT---------------------*/ - - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - if (tcd_tcp->tccps[compno].qmfbid == 1) { - dwt_encode(tilec); - } else if (tcd_tcp->tccps[compno].qmfbid == 0) { - dwt_encode_real(tilec); - } - } - - /*------------------TIER1-----------------*/ - t1 = t1_create(tcd->cinfo); - t1_encode_cblks(t1, tile, tcd_tcp); - t1_destroy(t1); - - /*-----------RATE-ALLOCATE------------------*/ - - /* INDEX */ - if(cstr_info) { - cstr_info->index_write = 0; - } - if (cp->disto_alloc || cp->fixed_quality) { /* fixed_quality */ - /* Normal Rate/distortion allocation */ - tcd_rateallocate(tcd, dest, len, cstr_info); - } else { - /* Fixed layer allocation */ - tcd_rateallocate_fixed(tcd); - } - } - /*--------------TIER2------------------*/ - - /* INDEX */ - if(cstr_info) { - cstr_info->index_write = 1; - } - - t2 = t2_create(tcd->cinfo, image, cp); - l = t2_encode_packets(t2,tileno, tile, tcd_tcp->numlayers, dest, len, cstr_info,tcd->tp_num,tcd->tp_pos,tcd->cur_pino,FINAL_PASS,tcd->cur_totnum_tp); - t2_destroy(t2); - - /*---------------CLEAN-------------------*/ - - - if(tcd->cur_tp_num == tcd->cur_totnum_tp - 1){ - tcd->encoding_time = opj_clock() - tcd->encoding_time; - opj_event_msg(tcd->cinfo, EVT_INFO, "- tile encoded in %f s\n", tcd->encoding_time); - - /* cleaning memory */ - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - opj_aligned_free(tilec->data); - } - } - - return l; -} - -opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info) { - int l; - int compno; - int eof = 0; - double tile_time, t1_time, dwt_time; - opj_tcd_tile_t *tile = NULL; - - opj_t1_t *t1 = NULL; /* T1 component */ - opj_t2_t *t2 = NULL; /* T2 component */ - - tcd->tcd_tileno = tileno; - tcd->tcd_tile = &(tcd->tcd_image->tiles[tileno]); - tcd->tcp = &(tcd->cp->tcps[tileno]); - tile = tcd->tcd_tile; - - tile_time = opj_clock(); /* time needed to decode a tile */ - opj_event_msg(tcd->cinfo, EVT_INFO, "tile %d of %d\n", tileno + 1, tcd->cp->tw * tcd->cp->th); - - /* INDEX >> */ - if(cstr_info) { - int resno, compno, numprec = 0; - for (compno = 0; compno < cstr_info->numcomps; compno++) { - opj_tcp_t *tcp = &tcd->cp->tcps[0]; - opj_tccp_t *tccp = &tcp->tccps[compno]; - opj_tcd_tilecomp_t *tilec_idx = &tile->comps[compno]; - for (resno = 0; resno < tilec_idx->numresolutions; resno++) { - opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[resno]; - cstr_info->tile[tileno].pw[resno] = res_idx->pw; - cstr_info->tile[tileno].ph[resno] = res_idx->ph; - numprec += res_idx->pw * res_idx->ph; - if (tccp->csty & J2K_CP_CSTY_PRT) { - cstr_info->tile[tileno].pdx[resno] = tccp->prcw[resno]; - cstr_info->tile[tileno].pdy[resno] = tccp->prch[resno]; - } - else { - cstr_info->tile[tileno].pdx[resno] = 15; - cstr_info->tile[tileno].pdy[resno] = 15; - } - } - } - cstr_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(cstr_info->numlayers * numprec * sizeof(opj_packet_info_t)); - cstr_info->packno = 0; - } - /* << INDEX */ - - /*--------------TIER2------------------*/ - - t2 = t2_create(tcd->cinfo, tcd->image, tcd->cp); - l = t2_decode_packets(t2, src, len, tileno, tile, cstr_info); - t2_destroy(t2); - - if (l == -999) { - eof = 1; - opj_event_msg(tcd->cinfo, EVT_ERROR, "tcd_decode: incomplete bistream\n"); - } - - /*------------------TIER1-----------------*/ - - t1_time = opj_clock(); /* time needed to decode a tile */ - t1 = t1_create(tcd->cinfo); - if (t1 == NULL) - { - opj_event_msg(tcd->cinfo, EVT_ERROR, "Out of memory\n"); - t1_destroy(t1); - return OPJ_FALSE; - } - - for (compno = 0; compno < tile->numcomps; ++compno) { - opj_tcd_tilecomp_t* tilec = &tile->comps[compno]; - /* The +3 is headroom required by the vectorized DWT */ - tilec->data = (int*) opj_aligned_malloc((((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0))+3) * sizeof(int)); - if (tilec->data == NULL) - { - opj_event_msg(tcd->cinfo, EVT_ERROR, "Out of memory\n"); - return OPJ_FALSE; - } - - t1_decode_cblks(t1, tilec, &tcd->tcp->tccps[compno]); - } - t1_destroy(t1); - t1_time = opj_clock() - t1_time; - opj_event_msg(tcd->cinfo, EVT_INFO, "- tiers-1 took %f s\n", t1_time); - - /*----------------DWT---------------------*/ - - dwt_time = opj_clock(); /* time needed to decode a tile */ - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - int numres2decode; - - if (tcd->cp->reduce != 0) { - if ( tile->comps[compno].numresolutions < ( tcd->cp->reduce - 1 ) ) { - opj_event_msg(tcd->cinfo, EVT_ERROR, "Error decoding tile. The number of resolutions to remove [%d+1] is higher than the number " - " of resolutions in the original codestream [%d]\nModify the cp_reduce parameter.\n", tcd->cp->reduce, tile->comps[compno].numresolutions); - return OPJ_FALSE; - } - else { - tcd->image->comps[compno].resno_decoded = - tile->comps[compno].numresolutions - tcd->cp->reduce - 1; - } - } - - numres2decode = tcd->image->comps[compno].resno_decoded + 1; - if(numres2decode > 0){ - if (tcd->tcp->tccps[compno].qmfbid == 1) { - dwt_decode(tilec, numres2decode); - } else { - dwt_decode_real(tilec, numres2decode); - } - } - } - dwt_time = opj_clock() - dwt_time; - opj_event_msg(tcd->cinfo, EVT_INFO, "- dwt took %f s\n", dwt_time); - - /*----------------MCT-------------------*/ - - if (tcd->tcp->mct) { - int n = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0); - - if (tile->numcomps >= 3 ){ - if (tcd->tcp->tccps[0].qmfbid == 1) { - mct_decode( - tile->comps[0].data, - tile->comps[1].data, - tile->comps[2].data, - n); - } else { - mct_decode_real( - (float*)tile->comps[0].data, - (float*)tile->comps[1].data, - (float*)tile->comps[2].data, - n); - } - } else{ - opj_event_msg(tcd->cinfo, EVT_WARNING,"Number of components (%d) is inconsistent with a MCT. Skip the MCT step.\n",tile->numcomps); - } - } - - /*---------------TILE-------------------*/ - - for (compno = 0; compno < tile->numcomps; ++compno) { - opj_tcd_tilecomp_t* tilec = &tile->comps[compno]; - opj_image_comp_t* imagec = &tcd->image->comps[compno]; - opj_tcd_resolution_t* res = &tilec->resolutions[imagec->resno_decoded]; - int adjust = imagec->sgnd ? 0 : 1 << (imagec->prec - 1); - int min = imagec->sgnd ? -(1 << (imagec->prec - 1)) : 0; - int max = imagec->sgnd ? (1 << (imagec->prec - 1)) - 1 : (1 << imagec->prec) - 1; - - int tw = tilec->x1 - tilec->x0; - int w = imagec->w; - - int offset_x = int_ceildivpow2(imagec->x0, imagec->factor); - int offset_y = int_ceildivpow2(imagec->y0, imagec->factor); - - int i, j; - if(!imagec->data){ - imagec->data = (int*) opj_malloc(imagec->w * imagec->h * sizeof(int)); - } - if (!imagec->data) - { - opj_event_msg(tcd->cinfo, EVT_ERROR, "Out of memory\n"); - return OPJ_FALSE; - } - if(tcd->tcp->tccps[compno].qmfbid == 1) { - for(j = res->y0; j < res->y1; ++j) { - for(i = res->x0; i < res->x1; ++i) { - int v = tilec->data[i - res->x0 + (j - res->y0) * tw]; - v += adjust; - imagec->data[(i - offset_x) + (j - offset_y) * w] = int_clamp(v, min, max); - } - } - }else{ - for(j = res->y0; j < res->y1; ++j) { - for(i = res->x0; i < res->x1; ++i) { - float tmp = ((float*)tilec->data)[i - res->x0 + (j - res->y0) * tw]; - int v = lrintf(tmp); - v += adjust; - imagec->data[(i - offset_x) + (j - offset_y) * w] = int_clamp(v, min, max); - } - } - } - opj_aligned_free(tilec->data); - } - - tile_time = opj_clock() - tile_time; /* time needed to decode a tile */ - opj_event_msg(tcd->cinfo, EVT_INFO, "- tile decoded in %f s\n", tile_time); - - if (eof) { - return OPJ_FALSE; - } - - return OPJ_TRUE; -} - -void tcd_free_decode(opj_tcd_t *tcd) { - opj_tcd_image_t *tcd_image = tcd->tcd_image; - int i = 0; - for (i = 0; i < tcd_image->tw * tcd_image->th; i++) - { - tcd_free_decode_tile(tcd, i); - } - - opj_free(tcd_image->tiles); -} - -void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno) { - int compno,resno,bandno,precno,cblkno; - - opj_tcd_image_t *tcd_image = tcd->tcd_image; - - opj_tcd_tile_t *tile = &tcd_image->tiles[tileno]; - if (tile->comps != NULL) { - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - for (resno = 0; resno < tilec->numresolutions; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - for (precno = 0; precno < res->ph * res->pw; precno++) { - opj_tcd_precinct_t *prec = &band->precincts[precno]; - if (prec->cblks.dec != NULL) { - for (cblkno = 0; cblkno < prec->cw * prec->ch; ++cblkno) { - opj_tcd_cblk_dec_t* cblk = &prec->cblks.dec[cblkno]; - opj_free(cblk->data); - opj_free(cblk->segs); - } - opj_free(prec->cblks.dec); - } - if (prec->imsbtree != NULL) tgt_destroy(prec->imsbtree); - if (prec->incltree != NULL) tgt_destroy(prec->incltree); - - - } - opj_free(band->precincts); - } - } - opj_free(tilec->resolutions); - } - opj_free(tile->comps); - tile->comps = NULL; - } -} - - - +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2006-2007, Parvatha Elangovan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#define _ISOC99_SOURCE /* lrintf is C99 */ +#include "opj_includes.h" + +void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) { + int tileno, compno, resno, bandno, precno;/*, cblkno;*/ + + fprintf(fd, "image {\n"); + fprintf(fd, " tw=%d, th=%d x0=%d x1=%d y0=%d y1=%d\n", + img->tw, img->th, tcd->image->x0, tcd->image->x1, tcd->image->y0, tcd->image->y1); + + for (tileno = 0; tileno < img->th * img->tw; tileno++) { + opj_tcd_tile_t *tile = &tcd->tcd_image->tiles[tileno]; + fprintf(fd, " tile {\n"); + fprintf(fd, " x0=%d, y0=%d, x1=%d, y1=%d, numcomps=%d\n", + tile->x0, tile->y0, tile->x1, tile->y1, tile->numcomps); + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + fprintf(fd, " tilec {\n"); + fprintf(fd, + " x0=%d, y0=%d, x1=%d, y1=%d, numresolutions=%d\n", + tilec->x0, tilec->y0, tilec->x1, tilec->y1, tilec->numresolutions); + for (resno = 0; resno < tilec->numresolutions; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + fprintf(fd, "\n res {\n"); + fprintf(fd, + " x0=%d, y0=%d, x1=%d, y1=%d, pw=%d, ph=%d, numbands=%d\n", + res->x0, res->y0, res->x1, res->y1, res->pw, res->ph, res->numbands); + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + fprintf(fd, " band {\n"); + fprintf(fd, + " x0=%d, y0=%d, x1=%d, y1=%d, stepsize=%f, numbps=%d\n", + band->x0, band->y0, band->x1, band->y1, band->stepsize, band->numbps); + for (precno = 0; precno < res->pw * res->ph; precno++) { + opj_tcd_precinct_t *prec = &band->precincts[precno]; + fprintf(fd, " prec {\n"); + fprintf(fd, + " x0=%d, y0=%d, x1=%d, y1=%d, cw=%d, ch=%d\n", + prec->x0, prec->y0, prec->x1, prec->y1, prec->cw, prec->ch); + /* + for (cblkno = 0; cblkno < prec->cw * prec->ch; cblkno++) { + opj_tcd_cblk_t *cblk = &prec->cblks[cblkno]; + fprintf(fd, " cblk {\n"); + fprintf(fd, + " x0=%d, y0=%d, x1=%d, y1=%d\n", + cblk->x0, cblk->y0, cblk->x1, cblk->y1); + fprintf(fd, " }\n"); + } + */ + fprintf(fd, " }\n"); + } + fprintf(fd, " }\n"); + } + fprintf(fd, " }\n"); + } + fprintf(fd, " }\n"); + } + fprintf(fd, " }\n"); + } + fprintf(fd, "}\n"); +} + +/* ----------------------------------------------------------------------- */ + +/** +Create a new TCD handle +*/ +opj_tcd_t* tcd_create(opj_common_ptr cinfo) { + /* create the tcd structure */ + opj_tcd_t *tcd = (opj_tcd_t*)opj_malloc(sizeof(opj_tcd_t)); + if(!tcd) return NULL; + tcd->cinfo = cinfo; + tcd->tcd_image = (opj_tcd_image_t*)opj_malloc(sizeof(opj_tcd_image_t)); + if(!tcd->tcd_image) { + opj_free(tcd); + return NULL; + } + + return tcd; +} + +/** +Destroy a previously created TCD handle +*/ +void tcd_destroy(opj_tcd_t *tcd) { + if(tcd) { + opj_free(tcd->tcd_image); + opj_free(tcd); + } +} + +/* ----------------------------------------------------------------------- */ + +void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno) { + int tileno, compno, resno, bandno, precno, cblkno; + + tcd->image = image; + tcd->cp = cp; + tcd->tcd_image->tw = cp->tw; + tcd->tcd_image->th = cp->th; + tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_malloc(sizeof(opj_tcd_tile_t)); + + for (tileno = 0; tileno < 1; tileno++) { + opj_tcp_t *tcp = &cp->tcps[curtileno]; + int j; + + /* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ + int p = curtileno % cp->tw; /* si numerotation matricielle .. */ + int q = curtileno / cp->tw; /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */ + + /* opj_tcd_tile_t *tile=&tcd->tcd_image->tiles[tileno]; */ + opj_tcd_tile_t *tile = tcd->tcd_image->tiles; + + /* 4 borders of the tile rescale on the image if necessary */ + tile->x0 = int_max(cp->tx0 + p * cp->tdx, image->x0); + tile->y0 = int_max(cp->ty0 + q * cp->tdy, image->y0); + tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1); + tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1); + tile->numcomps = image->numcomps; + /* tile->PPT=image->PPT; */ + + /* Modification of the RATE >> */ + for (j = 0; j < tcp->numlayers; j++) { + tcp->rates[j] = tcp->rates[j] ? + cp->tp_on ? + (((float) (tile->numcomps + * (tile->x1 - tile->x0) + * (tile->y1 - tile->y0) + * image->comps[0].prec)) + /(tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy)) - (((tcd->cur_totnum_tp - 1) * 14 )/ tcp->numlayers) + : + ((float) (tile->numcomps + * (tile->x1 - tile->x0) + * (tile->y1 - tile->y0) + * image->comps[0].prec))/ + (tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy) + : 0; + + if (tcp->rates[j]) { + if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) { + tcp->rates[j] = tcp->rates[j - 1] + 20; + } else { + if (!j && tcp->rates[j] < 30) + tcp->rates[j] = 30; + } + + if(j == (tcp->numlayers-1)){ + tcp->rates[j] = tcp->rates[j]- 2; + } + } + } + /* << Modification of the RATE */ + + tile->comps = (opj_tcd_tilecomp_t *) opj_malloc(image->numcomps * sizeof(opj_tcd_tilecomp_t)); + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tccp_t *tccp = &tcp->tccps[compno]; + + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + + /* border of each tile component (global) */ + tilec->x0 = int_ceildiv(tile->x0, image->comps[compno].dx); + tilec->y0 = int_ceildiv(tile->y0, image->comps[compno].dy); + tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx); + tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy); + + tilec->data = (int *) opj_aligned_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * sizeof(int)); + tilec->numresolutions = tccp->numresolutions; + + tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(tilec->numresolutions * sizeof(opj_tcd_resolution_t)); + + for (resno = 0; resno < tilec->numresolutions; resno++) { + int pdx, pdy; + int levelno = tilec->numresolutions - 1 - resno; + int tlprcxstart, tlprcystart, brprcxend, brprcyend; + int tlcbgxstart, tlcbgystart, brcbgxend, brcbgyend; + int cbgwidthexpn, cbgheightexpn; + int cblkwidthexpn, cblkheightexpn; + + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + + /* border for each resolution level (global) */ + res->x0 = int_ceildivpow2(tilec->x0, levelno); + res->y0 = int_ceildivpow2(tilec->y0, levelno); + res->x1 = int_ceildivpow2(tilec->x1, levelno); + res->y1 = int_ceildivpow2(tilec->y1, levelno); + + res->numbands = resno == 0 ? 1 : 3; + /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */ + if (tccp->csty & J2K_CCP_CSTY_PRT) { + pdx = tccp->prcw[resno]; + pdy = tccp->prch[resno]; + } else { + pdx = 15; + pdy = 15; + } + /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ + tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx; + tlprcystart = int_floordivpow2(res->y0, pdy) << pdy; + + brprcxend = int_ceildivpow2(res->x1, pdx) << pdx; + brprcyend = int_ceildivpow2(res->y1, pdy) << pdy; + + res->pw = (brprcxend - tlprcxstart) >> pdx; + res->ph = (brprcyend - tlprcystart) >> pdy; + + if (resno == 0) { + tlcbgxstart = tlprcxstart; + tlcbgystart = tlprcystart; + brcbgxend = brprcxend; + brcbgyend = brprcyend; + cbgwidthexpn = pdx; + cbgheightexpn = pdy; + } else { + tlcbgxstart = int_ceildivpow2(tlprcxstart, 1); + tlcbgystart = int_ceildivpow2(tlprcystart, 1); + brcbgxend = int_ceildivpow2(brprcxend, 1); + brcbgyend = int_ceildivpow2(brprcyend, 1); + cbgwidthexpn = pdx - 1; + cbgheightexpn = pdy - 1; + } + + cblkwidthexpn = int_min(tccp->cblkw, cbgwidthexpn); + cblkheightexpn = int_min(tccp->cblkh, cbgheightexpn); + + for (bandno = 0; bandno < res->numbands; bandno++) { + int x0b, y0b, i; + int gain, numbps; + opj_stepsize_t *ss = NULL; + + opj_tcd_band_t *band = &res->bands[bandno]; + + band->bandno = resno == 0 ? 0 : bandno + 1; + x0b = (band->bandno == 1) || (band->bandno == 3) ? 1 : 0; + y0b = (band->bandno == 2) || (band->bandno == 3) ? 1 : 0; + + if (band->bandno == 0) { + /* band border (global) */ + band->x0 = int_ceildivpow2(tilec->x0, levelno); + band->y0 = int_ceildivpow2(tilec->y0, levelno); + band->x1 = int_ceildivpow2(tilec->x1, levelno); + band->y1 = int_ceildivpow2(tilec->y1, levelno); + } else { + /* band border (global) */ + band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelno) * x0b, levelno + 1); + band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelno) * y0b, levelno + 1); + band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelno) * x0b, levelno + 1); + band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelno) * y0b, levelno + 1); + } + + ss = &tccp->stepsizes[resno == 0 ? 0 : 3 * (resno - 1) + bandno + 1]; + gain = tccp->qmfbid == 0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno); + numbps = image->comps[compno].prec + gain; + + band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn)); + band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */ + + band->precincts = (opj_tcd_precinct_t *) opj_malloc(3 * res->pw * res->ph * sizeof(opj_tcd_precinct_t)); + + for (i = 0; i < res->pw * res->ph * 3; i++) { + band->precincts[i].imsbtree = NULL; + band->precincts[i].incltree = NULL; + band->precincts[i].cblks.enc = NULL; + } + + for (precno = 0; precno < res->pw * res->ph; precno++) { + int tlcblkxstart, tlcblkystart, brcblkxend, brcblkyend; + + int cbgxstart = tlcbgxstart + (precno % res->pw) * (1 << cbgwidthexpn); + int cbgystart = tlcbgystart + (precno / res->pw) * (1 << cbgheightexpn); + int cbgxend = cbgxstart + (1 << cbgwidthexpn); + int cbgyend = cbgystart + (1 << cbgheightexpn); + + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + /* precinct size (global) */ + prc->x0 = int_max(cbgxstart, band->x0); + prc->y0 = int_max(cbgystart, band->y0); + prc->x1 = int_min(cbgxend, band->x1); + prc->y1 = int_min(cbgyend, band->y1); + + tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn; + tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn; + brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn; + brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn; + prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; + prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn; + + prc->cblks.enc = (opj_tcd_cblk_enc_t*) opj_calloc((prc->cw * prc->ch), sizeof(opj_tcd_cblk_enc_t)); + prc->incltree = tgt_create(prc->cw, prc->ch); + prc->imsbtree = tgt_create(prc->cw, prc->ch); + + for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { + int cblkxstart = tlcblkxstart + (cblkno % prc->cw) * (1 << cblkwidthexpn); + int cblkystart = tlcblkystart + (cblkno / prc->cw) * (1 << cblkheightexpn); + int cblkxend = cblkxstart + (1 << cblkwidthexpn); + int cblkyend = cblkystart + (1 << cblkheightexpn); + + opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; + + /* code-block size (global) */ + cblk->x0 = int_max(cblkxstart, prc->x0); + cblk->y0 = int_max(cblkystart, prc->y0); + cblk->x1 = int_min(cblkxend, prc->x1); + cblk->y1 = int_min(cblkyend, prc->y1); + cblk->data = (unsigned char*) opj_calloc(9728+2, sizeof(unsigned char)); + /* FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? */ + cblk->data[0] = 0; + cblk->data[1] = 0; + cblk->data += 2; + cblk->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t)); + cblk->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t)); + } + } + } + } + } + } + + /* tcd_dump(stdout, tcd, &tcd->tcd_image); */ +} + +void tcd_free_encode(opj_tcd_t *tcd) { + int tileno, compno, resno, bandno, precno, cblkno; + + for (tileno = 0; tileno < 1; tileno++) { + opj_tcd_tile_t *tile = tcd->tcd_image->tiles; + + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + + for (resno = 0; resno < tilec->numresolutions; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + + for (precno = 0; precno < res->pw * res->ph; precno++) { + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + if (prc->incltree != NULL) { + tgt_destroy(prc->incltree); + prc->incltree = NULL; + } + if (prc->imsbtree != NULL) { + tgt_destroy(prc->imsbtree); + prc->imsbtree = NULL; + } + for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { + opj_free(prc->cblks.enc[cblkno].data - 2); + opj_free(prc->cblks.enc[cblkno].layers); + opj_free(prc->cblks.enc[cblkno].passes); + } + opj_free(prc->cblks.enc); + } /* for (precno */ + opj_free(band->precincts); + band->precincts = NULL; + } /* for (bandno */ + } /* for (resno */ + opj_free(tilec->resolutions); + tilec->resolutions = NULL; + } /* for (compno */ + opj_free(tile->comps); + tile->comps = NULL; + } /* for (tileno */ + opj_free(tcd->tcd_image->tiles); + tcd->tcd_image->tiles = NULL; +} + +void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno) { + int tileno, compno, resno, bandno, precno, cblkno; + + for (tileno = 0; tileno < 1; tileno++) { + opj_tcp_t *tcp = &cp->tcps[curtileno]; + int j; + /* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ + int p = curtileno % cp->tw; + int q = curtileno / cp->tw; + + opj_tcd_tile_t *tile = tcd->tcd_image->tiles; + + /* 4 borders of the tile rescale on the image if necessary */ + tile->x0 = int_max(cp->tx0 + p * cp->tdx, image->x0); + tile->y0 = int_max(cp->ty0 + q * cp->tdy, image->y0); + tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1); + tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1); + + tile->numcomps = image->numcomps; + /* tile->PPT=image->PPT; */ + + /* Modification of the RATE >> */ + for (j = 0; j < tcp->numlayers; j++) { + tcp->rates[j] = tcp->rates[j] ? + cp->tp_on ? + (((float) (tile->numcomps + * (tile->x1 - tile->x0) + * (tile->y1 - tile->y0) + * image->comps[0].prec)) + /(tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy)) - (((tcd->cur_totnum_tp - 1) * 14 )/ tcp->numlayers) + : + ((float) (tile->numcomps + * (tile->x1 - tile->x0) + * (tile->y1 - tile->y0) + * image->comps[0].prec))/ + (tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy) + : 0; + + if (tcp->rates[j]) { + if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) { + tcp->rates[j] = tcp->rates[j - 1] + 20; + } else { + if (!j && tcp->rates[j] < 30) + tcp->rates[j] = 30; + } + } + } + /* << Modification of the RATE */ + + /* tile->comps=(opj_tcd_tilecomp_t*)opj_realloc(tile->comps,image->numcomps*sizeof(opj_tcd_tilecomp_t)); */ + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tccp_t *tccp = &tcp->tccps[compno]; + + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + + /* border of each tile component (global) */ + tilec->x0 = int_ceildiv(tile->x0, image->comps[compno].dx); + tilec->y0 = int_ceildiv(tile->y0, image->comps[compno].dy); + tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx); + tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy); + + tilec->data = (int *) opj_aligned_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * sizeof(int)); + tilec->numresolutions = tccp->numresolutions; + /* tilec->resolutions=(opj_tcd_resolution_t*)opj_realloc(tilec->resolutions,tilec->numresolutions*sizeof(opj_tcd_resolution_t)); */ + for (resno = 0; resno < tilec->numresolutions; resno++) { + int pdx, pdy; + + int levelno = tilec->numresolutions - 1 - resno; + int tlprcxstart, tlprcystart, brprcxend, brprcyend; + int tlcbgxstart, tlcbgystart, brcbgxend, brcbgyend; + int cbgwidthexpn, cbgheightexpn; + int cblkwidthexpn, cblkheightexpn; + + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + + /* border for each resolution level (global) */ + res->x0 = int_ceildivpow2(tilec->x0, levelno); + res->y0 = int_ceildivpow2(tilec->y0, levelno); + res->x1 = int_ceildivpow2(tilec->x1, levelno); + res->y1 = int_ceildivpow2(tilec->y1, levelno); + res->numbands = resno == 0 ? 1 : 3; + + /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */ + if (tccp->csty & J2K_CCP_CSTY_PRT) { + pdx = tccp->prcw[resno]; + pdy = tccp->prch[resno]; + } else { + pdx = 15; + pdy = 15; + } + /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ + tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx; + tlprcystart = int_floordivpow2(res->y0, pdy) << pdy; + brprcxend = int_ceildivpow2(res->x1, pdx) << pdx; + brprcyend = int_ceildivpow2(res->y1, pdy) << pdy; + + res->pw = (brprcxend - tlprcxstart) >> pdx; + res->ph = (brprcyend - tlprcystart) >> pdy; + + if (resno == 0) { + tlcbgxstart = tlprcxstart; + tlcbgystart = tlprcystart; + brcbgxend = brprcxend; + brcbgyend = brprcyend; + cbgwidthexpn = pdx; + cbgheightexpn = pdy; + } else { + tlcbgxstart = int_ceildivpow2(tlprcxstart, 1); + tlcbgystart = int_ceildivpow2(tlprcystart, 1); + brcbgxend = int_ceildivpow2(brprcxend, 1); + brcbgyend = int_ceildivpow2(brprcyend, 1); + cbgwidthexpn = pdx - 1; + cbgheightexpn = pdy - 1; + } + + cblkwidthexpn = int_min(tccp->cblkw, cbgwidthexpn); + cblkheightexpn = int_min(tccp->cblkh, cbgheightexpn); + + for (bandno = 0; bandno < res->numbands; bandno++) { + int x0b, y0b; + int gain, numbps; + opj_stepsize_t *ss = NULL; + + opj_tcd_band_t *band = &res->bands[bandno]; + + band->bandno = resno == 0 ? 0 : bandno + 1; + x0b = (band->bandno == 1) || (band->bandno == 3) ? 1 : 0; + y0b = (band->bandno == 2) || (band->bandno == 3) ? 1 : 0; + + if (band->bandno == 0) { + /* band border */ + band->x0 = int_ceildivpow2(tilec->x0, levelno); + band->y0 = int_ceildivpow2(tilec->y0, levelno); + band->x1 = int_ceildivpow2(tilec->x1, levelno); + band->y1 = int_ceildivpow2(tilec->y1, levelno); + } else { + band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelno) * x0b, levelno + 1); + band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelno) * y0b, levelno + 1); + band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelno) * x0b, levelno + 1); + band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelno) * y0b, levelno + 1); + } + + ss = &tccp->stepsizes[resno == 0 ? 0 : 3 * (resno - 1) + bandno + 1]; + gain = tccp->qmfbid == 0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno); + numbps = image->comps[compno].prec + gain; + band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn)); + band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */ + + for (precno = 0; precno < res->pw * res->ph; precno++) { + int tlcblkxstart, tlcblkystart, brcblkxend, brcblkyend; + + int cbgxstart = tlcbgxstart + (precno % res->pw) * (1 << cbgwidthexpn); + int cbgystart = tlcbgystart + (precno / res->pw) * (1 << cbgheightexpn); + int cbgxend = cbgxstart + (1 << cbgwidthexpn); + int cbgyend = cbgystart + (1 << cbgheightexpn); + + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + /* precinct size (global) */ + prc->x0 = int_max(cbgxstart, band->x0); + prc->y0 = int_max(cbgystart, band->y0); + prc->x1 = int_min(cbgxend, band->x1); + prc->y1 = int_min(cbgyend, band->y1); + + tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn; + tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn; + brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn; + brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn; + prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; + prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn; + + opj_free(prc->cblks.enc); + prc->cblks.enc = (opj_tcd_cblk_enc_t*) opj_calloc(prc->cw * prc->ch, sizeof(opj_tcd_cblk_enc_t)); + + if (prc->incltree != NULL) { + tgt_destroy(prc->incltree); + } + if (prc->imsbtree != NULL) { + tgt_destroy(prc->imsbtree); + } + + prc->incltree = tgt_create(prc->cw, prc->ch); + prc->imsbtree = tgt_create(prc->cw, prc->ch); + + for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { + int cblkxstart = tlcblkxstart + (cblkno % prc->cw) * (1 << cblkwidthexpn); + int cblkystart = tlcblkystart + (cblkno / prc->cw) * (1 << cblkheightexpn); + int cblkxend = cblkxstart + (1 << cblkwidthexpn); + int cblkyend = cblkystart + (1 << cblkheightexpn); + + opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; + + /* code-block size (global) */ + cblk->x0 = int_max(cblkxstart, prc->x0); + cblk->y0 = int_max(cblkystart, prc->y0); + cblk->x1 = int_min(cblkxend, prc->x1); + cblk->y1 = int_min(cblkyend, prc->y1); + cblk->data = (unsigned char*) opj_calloc(8192+2, sizeof(unsigned char)); + /* FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? */ + cblk->data[0] = 0; + cblk->data[1] = 0; + cblk->data += 2; + cblk->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t)); + cblk->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t)); + } + } /* precno */ + } /* bandno */ + } /* resno */ + } /* compno */ + } /* tileno */ + + /* tcd_dump(stdout, tcd, &tcd->tcd_image); */ +} + +void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp) { + int i, j, tileno, p, q; + unsigned int x0 = 0, y0 = 0, x1 = 0, y1 = 0, w, h; + + tcd->image = image; + tcd->tcd_image->tw = cp->tw; + tcd->tcd_image->th = cp->th; + tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_calloc(cp->tw * cp->th, sizeof(opj_tcd_tile_t)); + + /* + Allocate place to store the decoded data = final image + Place limited by the tile really present in the codestream + */ + + for (j = 0; j < cp->tileno_size; j++) { + opj_tcd_tile_t *tile; + + tileno = cp->tileno[j]; + tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]); + tile->numcomps = image->numcomps; + tile->comps = (opj_tcd_tilecomp_t*) opj_calloc(image->numcomps, sizeof(opj_tcd_tilecomp_t)); + } + + for (i = 0; i < image->numcomps; i++) { + for (j = 0; j < cp->tileno_size; j++) { + opj_tcd_tile_t *tile; + opj_tcd_tilecomp_t *tilec; + + /* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ + + tileno = cp->tileno[j]; + + tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]); + tilec = &tile->comps[i]; + + p = tileno % cp->tw; /* si numerotation matricielle .. */ + q = tileno / cp->tw; /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */ + + /* 4 borders of the tile rescale on the image if necessary */ + tile->x0 = int_max(cp->tx0 + p * cp->tdx, image->x0); + tile->y0 = int_max(cp->ty0 + q * cp->tdy, image->y0); + tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1); + tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1); + + tilec->x0 = int_ceildiv(tile->x0, image->comps[i].dx); + tilec->y0 = int_ceildiv(tile->y0, image->comps[i].dy); + tilec->x1 = int_ceildiv(tile->x1, image->comps[i].dx); + tilec->y1 = int_ceildiv(tile->y1, image->comps[i].dy); + + x0 = j == 0 ? tilec->x0 : int_min(x0, (unsigned int) tilec->x0); + y0 = j == 0 ? tilec->y0 : int_min(y0, (unsigned int) tilec->y0); + x1 = j == 0 ? tilec->x1 : int_max(x1, (unsigned int) tilec->x1); + y1 = j == 0 ? tilec->y1 : int_max(y1, (unsigned int) tilec->y1); + } + + w = int_ceildivpow2(x1 - x0, image->comps[i].factor); + h = int_ceildivpow2(y1 - y0, image->comps[i].factor); + + image->comps[i].w = w; + image->comps[i].h = h; + image->comps[i].x0 = x0; + image->comps[i].y0 = y0; + } +} + +void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int tileno, opj_codestream_info_t *cstr_info) { + int compno, resno, bandno, precno, cblkno; + opj_tcp_t *tcp; + opj_tcd_tile_t *tile; + + OPJ_ARG_NOT_USED(cstr_info); + + tcd->cp = cp; + + tcp = &(cp->tcps[cp->tileno[tileno]]); + tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]); + + tileno = cp->tileno[tileno]; + + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tccp_t *tccp = &tcp->tccps[compno]; + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + + if (tccp->numresolutions <= 0) + { + cp->tileno[tileno] = -1; + return; + } + + /* border of each tile component (global) */ + tilec->x0 = int_ceildiv(tile->x0, image->comps[compno].dx); + tilec->y0 = int_ceildiv(tile->y0, image->comps[compno].dy); + tilec->x1 = int_ceildiv(tile->x1, image->comps[compno].dx); + tilec->y1 = int_ceildiv(tile->y1, image->comps[compno].dy); + + tilec->numresolutions = tccp->numresolutions; + tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(tilec->numresolutions * sizeof(opj_tcd_resolution_t)); + + for (resno = 0; resno < tilec->numresolutions; resno++) { + int pdx, pdy; + int levelno = tilec->numresolutions - 1 - resno; + int tlprcxstart, tlprcystart, brprcxend, brprcyend; + int tlcbgxstart, tlcbgystart, brcbgxend, brcbgyend; + int cbgwidthexpn, cbgheightexpn; + int cblkwidthexpn, cblkheightexpn; + + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + + /* border for each resolution level (global) */ + res->x0 = int_ceildivpow2(tilec->x0, levelno); + res->y0 = int_ceildivpow2(tilec->y0, levelno); + res->x1 = int_ceildivpow2(tilec->x1, levelno); + res->y1 = int_ceildivpow2(tilec->y1, levelno); + res->numbands = resno == 0 ? 1 : 3; + + /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */ + if (tccp->csty & J2K_CCP_CSTY_PRT) { + pdx = tccp->prcw[resno]; + pdy = tccp->prch[resno]; + } else { + pdx = 15; + pdy = 15; + } + + /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ + tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx; + tlprcystart = int_floordivpow2(res->y0, pdy) << pdy; + brprcxend = int_ceildivpow2(res->x1, pdx) << pdx; + brprcyend = int_ceildivpow2(res->y1, pdy) << pdy; + + res->pw = (res->x0 == res->x1) ? 0 : ((brprcxend - tlprcxstart) >> pdx); + res->ph = (res->y0 == res->y1) ? 0 : ((brprcyend - tlprcystart) >> pdy); + + if (resno == 0) { + tlcbgxstart = tlprcxstart; + tlcbgystart = tlprcystart; + brcbgxend = brprcxend; + brcbgyend = brprcyend; + cbgwidthexpn = pdx; + cbgheightexpn = pdy; + } else { + tlcbgxstart = int_ceildivpow2(tlprcxstart, 1); + tlcbgystart = int_ceildivpow2(tlprcystart, 1); + brcbgxend = int_ceildivpow2(brprcxend, 1); + brcbgyend = int_ceildivpow2(brprcyend, 1); + cbgwidthexpn = pdx - 1; + cbgheightexpn = pdy - 1; + } + + cblkwidthexpn = int_min(tccp->cblkw, cbgwidthexpn); + cblkheightexpn = int_min(tccp->cblkh, cbgheightexpn); + + for (bandno = 0; bandno < res->numbands; bandno++) { + int x0b, y0b; + int gain, numbps; + opj_stepsize_t *ss = NULL; + + opj_tcd_band_t *band = &res->bands[bandno]; + band->bandno = resno == 0 ? 0 : bandno + 1; + x0b = (band->bandno == 1) || (band->bandno == 3) ? 1 : 0; + y0b = (band->bandno == 2) || (band->bandno == 3) ? 1 : 0; + + if (band->bandno == 0) { + /* band border (global) */ + band->x0 = int_ceildivpow2(tilec->x0, levelno); + band->y0 = int_ceildivpow2(tilec->y0, levelno); + band->x1 = int_ceildivpow2(tilec->x1, levelno); + band->y1 = int_ceildivpow2(tilec->y1, levelno); + } else { + /* band border (global) */ + band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelno) * x0b, levelno + 1); + band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelno) * y0b, levelno + 1); + band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelno) * x0b, levelno + 1); + band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelno) * y0b, levelno + 1); + } + + ss = &tccp->stepsizes[resno == 0 ? 0 : 3 * (resno - 1) + bandno + 1]; + gain = tccp->qmfbid == 0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno); + numbps = image->comps[compno].prec + gain; + band->stepsize = (float)(((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn)) * 0.5); + band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */ + + band->precincts = (opj_tcd_precinct_t *) opj_malloc(res->pw * res->ph * sizeof(opj_tcd_precinct_t)); + + for (precno = 0; precno < res->pw * res->ph; precno++) { + int tlcblkxstart, tlcblkystart, brcblkxend, brcblkyend; + int cbgxstart = tlcbgxstart + (precno % res->pw) * (1 << cbgwidthexpn); + int cbgystart = tlcbgystart + (precno / res->pw) * (1 << cbgheightexpn); + int cbgxend = cbgxstart + (1 << cbgwidthexpn); + int cbgyend = cbgystart + (1 << cbgheightexpn); + + opj_tcd_precinct_t *prc = &band->precincts[precno]; + /* precinct size (global) */ + prc->x0 = int_max(cbgxstart, band->x0); + prc->y0 = int_max(cbgystart, band->y0); + prc->x1 = int_min(cbgxend, band->x1); + prc->y1 = int_min(cbgyend, band->y1); + + tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn; + tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn; + brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn; + brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn; + prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; + prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn; + + prc->cblks.dec = (opj_tcd_cblk_dec_t*) opj_malloc(prc->cw * prc->ch * sizeof(opj_tcd_cblk_dec_t)); + + prc->incltree = tgt_create(prc->cw, prc->ch); + prc->imsbtree = tgt_create(prc->cw, prc->ch); + + for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { + int cblkxstart = tlcblkxstart + (cblkno % prc->cw) * (1 << cblkwidthexpn); + int cblkystart = tlcblkystart + (cblkno / prc->cw) * (1 << cblkheightexpn); + int cblkxend = cblkxstart + (1 << cblkwidthexpn); + int cblkyend = cblkystart + (1 << cblkheightexpn); + + opj_tcd_cblk_dec_t* cblk = &prc->cblks.dec[cblkno]; + cblk->data = NULL; + cblk->segs = NULL; + /* code-block size (global) */ + cblk->x0 = int_max(cblkxstart, prc->x0); + cblk->y0 = int_max(cblkystart, prc->y0); + cblk->x1 = int_min(cblkxend, prc->x1); + cblk->y1 = int_min(cblkyend, prc->y1); + cblk->numsegs = 0; + } + } /* precno */ + } /* bandno */ + } /* resno */ + } /* compno */ + /* tcd_dump(stdout, tcd, &tcd->tcd_image); */ +} + +void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final) { + int compno, resno, bandno, precno, cblkno; + int value; /*, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolutions][3]; */ + int matrice[10][10][3]; + int i, j, k; + + opj_cp_t *cp = tcd->cp; + opj_tcd_tile_t *tcd_tile = tcd->tcd_tile; + opj_tcp_t *tcd_tcp = tcd->tcp; + + /*matrice=(int*)opj_malloc(tcd_tcp->numlayers*tcd_tile->comps[0].numresolutions*3*sizeof(int)); */ + + for (compno = 0; compno < tcd_tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; + for (i = 0; i < tcd_tcp->numlayers; i++) { + for (j = 0; j < tilec->numresolutions; j++) { + for (k = 0; k < 3; k++) { + matrice[i][j][k] = + (int) (cp->matrice[i * tilec->numresolutions * 3 + j * 3 + k] + * (float) (tcd->image->comps[compno].prec / 16.0)); + } + } + } + + for (resno = 0; resno < tilec->numresolutions; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + for (precno = 0; precno < res->pw * res->ph; precno++) { + opj_tcd_precinct_t *prc = &band->precincts[precno]; + for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { + opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno]; + opj_tcd_layer_t *layer = &cblk->layers[layno]; + int n; + int imsb = tcd->image->comps[compno].prec - cblk->numbps; /* number of bit-plan equal to zero */ + /* Correction of the matrix of coefficient to include the IMSB information */ + if (layno == 0) { + value = matrice[layno][resno][bandno]; + if (imsb >= value) { + value = 0; + } else { + value -= imsb; + } + } else { + value = matrice[layno][resno][bandno] - matrice[layno - 1][resno][bandno]; + if (imsb >= matrice[layno - 1][resno][bandno]) { + value -= (imsb - matrice[layno - 1][resno][bandno]); + if (value < 0) { + value = 0; + } + } + } + + if (layno == 0) { + cblk->numpassesinlayers = 0; + } + + n = cblk->numpassesinlayers; + if (cblk->numpassesinlayers == 0) { + if (value != 0) { + n = 3 * value - 2 + cblk->numpassesinlayers; + } else { + n = cblk->numpassesinlayers; + } + } else { + n = 3 * value + cblk->numpassesinlayers; + } + + layer->numpasses = n - cblk->numpassesinlayers; + + if (!layer->numpasses) + continue; + + if (cblk->numpassesinlayers == 0) { + layer->len = cblk->passes[n - 1].rate; + layer->data = cblk->data; + } else { + layer->len = cblk->passes[n - 1].rate - cblk->passes[cblk->numpassesinlayers - 1].rate; + layer->data = cblk->data + cblk->passes[cblk->numpassesinlayers - 1].rate; + } + if (final) + cblk->numpassesinlayers = n; + } + } + } + } + } +} + +void tcd_rateallocate_fixed(opj_tcd_t *tcd) { + int layno; + for (layno = 0; layno < tcd->tcp->numlayers; layno++) { + tcd_makelayer_fixed(tcd, layno, 1); + } +} + +void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final) { + int compno, resno, bandno, precno, cblkno, passno; + + opj_tcd_tile_t *tcd_tile = tcd->tcd_tile; + + tcd_tile->distolayer[layno] = 0; /* fixed_quality */ + + for (compno = 0; compno < tcd_tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; + for (resno = 0; resno < tilec->numresolutions; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + for (precno = 0; precno < res->pw * res->ph; precno++) { + opj_tcd_precinct_t *prc = &band->precincts[precno]; + for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { + opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno]; + opj_tcd_layer_t *layer = &cblk->layers[layno]; + + int n; + if (layno == 0) { + cblk->numpassesinlayers = 0; + } + n = cblk->numpassesinlayers; + for (passno = cblk->numpassesinlayers; passno < cblk->totalpasses; passno++) { + int dr; + double dd; + opj_tcd_pass_t *pass = &cblk->passes[passno]; + if (n == 0) { + dr = pass->rate; + dd = pass->distortiondec; + } else { + dr = pass->rate - cblk->passes[n - 1].rate; + dd = pass->distortiondec - cblk->passes[n - 1].distortiondec; + } + if (!dr) { + if (dd != 0) + n = passno + 1; + continue; + } + if (dd / dr >= thresh) + n = passno + 1; + } + layer->numpasses = n - cblk->numpassesinlayers; + + if (!layer->numpasses) { + layer->disto = 0; + continue; + } + if (cblk->numpassesinlayers == 0) { + layer->len = cblk->passes[n - 1].rate; + layer->data = cblk->data; + layer->disto = cblk->passes[n - 1].distortiondec; + } else { + layer->len = cblk->passes[n - 1].rate - cblk->passes[cblk->numpassesinlayers - 1].rate; + layer->data = cblk->data + cblk->passes[cblk->numpassesinlayers - 1].rate; + layer->disto = cblk->passes[n - 1].distortiondec - cblk->passes[cblk->numpassesinlayers - 1].distortiondec; + } + + tcd_tile->distolayer[layno] += layer->disto; /* fixed_quality */ + + if (final) + cblk->numpassesinlayers = n; + } + } + } + } + } +} + +opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) { + int compno, resno, bandno, precno, cblkno, passno, layno; + double min, max; + double cumdisto[100]; /* fixed_quality */ + const double K = 1; /* 1.1; fixed_quality */ + double maxSE = 0; + + opj_cp_t *cp = tcd->cp; + opj_tcd_tile_t *tcd_tile = tcd->tcd_tile; + opj_tcp_t *tcd_tcp = tcd->tcp; + + min = DBL_MAX; + max = 0; + + tcd_tile->numpix = 0; /* fixed_quality */ + + for (compno = 0; compno < tcd_tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; + tilec->numpix = 0; + + for (resno = 0; resno < tilec->numresolutions; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + + for (precno = 0; precno < res->pw * res->ph; precno++) { + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) { + opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno]; + + for (passno = 0; passno < cblk->totalpasses; passno++) { + opj_tcd_pass_t *pass = &cblk->passes[passno]; + int dr; + double dd, rdslope; + if (passno == 0) { + dr = pass->rate; + dd = pass->distortiondec; + } else { + dr = pass->rate - cblk->passes[passno - 1].rate; + dd = pass->distortiondec - cblk->passes[passno - 1].distortiondec; + } + if (dr == 0) { + continue; + } + rdslope = dd / dr; + if (rdslope < min) { + min = rdslope; + } + if (rdslope > max) { + max = rdslope; + } + } /* passno */ + + /* fixed_quality */ + tcd_tile->numpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); + tilec->numpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); + } /* cbklno */ + } /* precno */ + } /* bandno */ + } /* resno */ + + maxSE += (((double)(1 << tcd->image->comps[compno].prec) - 1.0) + * ((double)(1 << tcd->image->comps[compno].prec) -1.0)) + * ((double)(tilec->numpix)); + } /* compno */ + + /* index file */ + if(cstr_info) { + opj_tile_info_t *tile_info = &cstr_info->tile[tcd->tcd_tileno]; + tile_info->numpix = tcd_tile->numpix; + tile_info->distotile = tcd_tile->distotile; + tile_info->thresh = (double *) opj_malloc(tcd_tcp->numlayers * sizeof(double)); + } + + for (layno = 0; layno < tcd_tcp->numlayers; layno++) { + double lo = min; + double hi = max; + int success = 0; + int maxlen = tcd_tcp->rates[layno] ? int_min(((int) ceil(tcd_tcp->rates[layno])), len) : len; + double goodthresh = 0; + double stable_thresh = 0; + int i; + double distotarget; /* fixed_quality */ + + /* fixed_quality */ + distotarget = tcd_tile->distotile - ((K * maxSE) / pow((float)10, tcd_tcp->distoratio[layno] / 10)); + + /* Don't try to find an optimal threshold but rather take everything not included yet, if + -r xx,yy,zz,0 (disto_alloc == 1 and rates == 0) + -q xx,yy,zz,0 (fixed_quality == 1 and distoratio == 0) + ==> possible to have some lossy layers and the last layer for sure lossless */ + if ( ((cp->disto_alloc==1) && (tcd_tcp->rates[layno]>0)) || ((cp->fixed_quality==1) && (tcd_tcp->distoratio[layno]>0))) { + opj_t2_t *t2 = t2_create(tcd->cinfo, tcd->image, cp); + double thresh = 0; + + for (i = 0; i < 128; i++) { + int l = 0; + double distoachieved = 0; /* fixed_quality */ + thresh = (lo + hi) / 2; + + tcd_makelayer(tcd, layno, thresh, 0); + + if (cp->fixed_quality) { /* fixed_quality */ + if(cp->cinema){ + l = t2_encode_packets(t2,tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC, tcd->cur_totnum_tp); + if (l == -999) { + lo = thresh; + continue; + }else{ + distoachieved = layno == 0 ? + tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno]; + if (distoachieved < distotarget) { + hi=thresh; + stable_thresh = thresh; + continue; + }else{ + lo=thresh; + } + } + }else{ + distoachieved = (layno == 0) ? + tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]); + if (distoachieved < distotarget) { + hi = thresh; + stable_thresh = thresh; + continue; + } + lo = thresh; + } + } else { + l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC, tcd->cur_totnum_tp); + /* TODO: what to do with l ??? seek / tell ??? */ + /* opj_event_msg(tcd->cinfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, maxlen); */ + if (l == -999) { + lo = thresh; + continue; + } + hi = thresh; + stable_thresh = thresh; + } + } + success = 1; + goodthresh = stable_thresh == 0? thresh : stable_thresh; + t2_destroy(t2); + } else { + success = 1; + goodthresh = min; + } + + if (!success) { + return OPJ_FALSE; + } + + if(cstr_info) { /* Threshold for Marcela Index */ + cstr_info->tile[tcd->tcd_tileno].thresh[layno] = goodthresh; + } + tcd_makelayer(tcd, layno, goodthresh, 1); + + /* fixed_quality */ + cumdisto[layno] = (layno == 0) ? tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]); + } + + return OPJ_TRUE; +} + +int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) { + int compno; + int l, i, numpacks = 0; + opj_tcd_tile_t *tile = NULL; + opj_tcp_t *tcd_tcp = NULL; + opj_cp_t *cp = NULL; + + opj_tcp_t *tcp = &tcd->cp->tcps[0]; + opj_tccp_t *tccp = &tcp->tccps[0]; + opj_image_t *image = tcd->image; + + opj_t1_t *t1 = NULL; /* T1 component */ + opj_t2_t *t2 = NULL; /* T2 component */ + + tcd->tcd_tileno = tileno; + tcd->tcd_tile = tcd->tcd_image->tiles; + tcd->tcp = &tcd->cp->tcps[tileno]; + + tile = tcd->tcd_tile; + tcd_tcp = tcd->tcp; + cp = tcd->cp; + + if(tcd->cur_tp_num == 0){ + tcd->encoding_time = opj_clock(); /* time needed to encode a tile */ + /* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */ + if(cstr_info) { + opj_tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /* based on component 0 */ + for (i = 0; i < tilec_idx->numresolutions; i++) { + opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[i]; + + cstr_info->tile[tileno].pw[i] = res_idx->pw; + cstr_info->tile[tileno].ph[i] = res_idx->ph; + + numpacks += res_idx->pw * res_idx->ph; + + cstr_info->tile[tileno].pdx[i] = tccp->prcw[i]; + cstr_info->tile[tileno].pdy[i] = tccp->prch[i]; + } + cstr_info->tile[tileno].packet = (opj_packet_info_t*) opj_calloc(cstr_info->numcomps * cstr_info->numlayers * numpacks, sizeof(opj_packet_info_t)); + } + /* << INDEX */ + + /*---------------TILE-------------------*/ + + for (compno = 0; compno < tile->numcomps; compno++) { + int x, y; + + int adjust = image->comps[compno].sgnd ? 0 : 1 << (image->comps[compno].prec - 1); + int offset_x = int_ceildiv(image->x0, image->comps[compno].dx); + int offset_y = int_ceildiv(image->y0, image->comps[compno].dy); + + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + int tw = tilec->x1 - tilec->x0; + int w = int_ceildiv(image->x1 - image->x0, image->comps[compno].dx); + + /* extract tile data */ + + if (tcd_tcp->tccps[compno].qmfbid == 1) { + for (y = tilec->y0; y < tilec->y1; y++) { + /* start of the src tile scanline */ + int *data = &image->comps[compno].data[(tilec->x0 - offset_x) + (y - offset_y) * w]; + /* start of the dst tile scanline */ + int *tile_data = &tilec->data[(y - tilec->y0) * tw]; + for (x = tilec->x0; x < tilec->x1; x++) { + *tile_data++ = *data++ - adjust; + } + } + } else if (tcd_tcp->tccps[compno].qmfbid == 0) { + for (y = tilec->y0; y < tilec->y1; y++) { + /* start of the src tile scanline */ + int *data = &image->comps[compno].data[(tilec->x0 - offset_x) + (y - offset_y) * w]; + /* start of the dst tile scanline */ + int *tile_data = &tilec->data[(y - tilec->y0) * tw]; + for (x = tilec->x0; x < tilec->x1; x++) { + *tile_data++ = (*data++ - adjust) << 11; + } + + } + } + } + + /*----------------MCT-------------------*/ + if (tcd_tcp->mct) { + int samples = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0); + if (tcd_tcp->tccps[0].qmfbid == 0) { + mct_encode_real(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, samples); + } else { + mct_encode(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, samples); + } + } + + /*----------------DWT---------------------*/ + + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + if (tcd_tcp->tccps[compno].qmfbid == 1) { + dwt_encode(tilec); + } else if (tcd_tcp->tccps[compno].qmfbid == 0) { + dwt_encode_real(tilec); + } + } + + /*------------------TIER1-----------------*/ + t1 = t1_create(tcd->cinfo); + t1_encode_cblks(t1, tile, tcd_tcp); + t1_destroy(t1); + + /*-----------RATE-ALLOCATE------------------*/ + + /* INDEX */ + if(cstr_info) { + cstr_info->index_write = 0; + } + if (cp->disto_alloc || cp->fixed_quality) { /* fixed_quality */ + /* Normal Rate/distortion allocation */ + tcd_rateallocate(tcd, dest, len, cstr_info); + } else { + /* Fixed layer allocation */ + tcd_rateallocate_fixed(tcd); + } + } + /*--------------TIER2------------------*/ + + /* INDEX */ + if(cstr_info) { + cstr_info->index_write = 1; + } + + t2 = t2_create(tcd->cinfo, image, cp); + l = t2_encode_packets(t2,tileno, tile, tcd_tcp->numlayers, dest, len, cstr_info,tcd->tp_num,tcd->tp_pos,tcd->cur_pino,FINAL_PASS,tcd->cur_totnum_tp); + t2_destroy(t2); + + /*---------------CLEAN-------------------*/ + + + if(tcd->cur_tp_num == tcd->cur_totnum_tp - 1){ + tcd->encoding_time = opj_clock() - tcd->encoding_time; + opj_event_msg(tcd->cinfo, EVT_INFO, "- tile encoded in %f s\n", tcd->encoding_time); + + /* cleaning memory */ + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + opj_aligned_free(tilec->data); + } + } + + return l; +} + +opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info) { + int l; + int compno; + int eof = 0; + double tile_time, t1_time, dwt_time; + opj_tcd_tile_t *tile = NULL; + + opj_t1_t *t1 = NULL; /* T1 component */ + opj_t2_t *t2 = NULL; /* T2 component */ + + tcd->tcd_tileno = tileno; + tcd->tcd_tile = &(tcd->tcd_image->tiles[tileno]); + tcd->tcp = &(tcd->cp->tcps[tileno]); + tile = tcd->tcd_tile; + + tile_time = opj_clock(); /* time needed to decode a tile */ + opj_event_msg(tcd->cinfo, EVT_INFO, "tile %d of %d\n", tileno + 1, tcd->cp->tw * tcd->cp->th); + + /* INDEX >> */ + if(cstr_info) { + int resno, compno, numprec = 0; + for (compno = 0; compno < cstr_info->numcomps; compno++) { + opj_tcp_t *tcp = &tcd->cp->tcps[0]; + opj_tccp_t *tccp = &tcp->tccps[compno]; + opj_tcd_tilecomp_t *tilec_idx = &tile->comps[compno]; + for (resno = 0; resno < tilec_idx->numresolutions; resno++) { + opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[resno]; + cstr_info->tile[tileno].pw[resno] = res_idx->pw; + cstr_info->tile[tileno].ph[resno] = res_idx->ph; + numprec += res_idx->pw * res_idx->ph; + if (tccp->csty & J2K_CP_CSTY_PRT) { + cstr_info->tile[tileno].pdx[resno] = tccp->prcw[resno]; + cstr_info->tile[tileno].pdy[resno] = tccp->prch[resno]; + } + else { + cstr_info->tile[tileno].pdx[resno] = 15; + cstr_info->tile[tileno].pdy[resno] = 15; + } + } + } + cstr_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(cstr_info->numlayers * numprec * sizeof(opj_packet_info_t)); + cstr_info->packno = 0; + } + /* << INDEX */ + + /*--------------TIER2------------------*/ + + t2 = t2_create(tcd->cinfo, tcd->image, tcd->cp); + l = t2_decode_packets(t2, src, len, tileno, tile, cstr_info); + t2_destroy(t2); + + if (l == -999) { + eof = 1; + opj_event_msg(tcd->cinfo, EVT_ERROR, "tcd_decode: incomplete bistream\n"); + } + + /*------------------TIER1-----------------*/ + + t1_time = opj_clock(); /* time needed to decode a tile */ + t1 = t1_create(tcd->cinfo); + if (t1 == NULL) + { + opj_event_msg(tcd->cinfo, EVT_ERROR, "Out of memory\n"); + t1_destroy(t1); + return OPJ_FALSE; + } + + for (compno = 0; compno < tile->numcomps; ++compno) { + opj_tcd_tilecomp_t* tilec = &tile->comps[compno]; + /* The +3 is headroom required by the vectorized DWT */ + tilec->data = (int*) opj_aligned_malloc((((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0))+3) * sizeof(int)); + if (tilec->data == NULL) + { + opj_event_msg(tcd->cinfo, EVT_ERROR, "Out of memory\n"); + return OPJ_FALSE; + } + + t1_decode_cblks(t1, tilec, &tcd->tcp->tccps[compno]); + } + t1_destroy(t1); + t1_time = opj_clock() - t1_time; + opj_event_msg(tcd->cinfo, EVT_INFO, "- tiers-1 took %f s\n", t1_time); + + /*----------------DWT---------------------*/ + + dwt_time = opj_clock(); /* time needed to decode a tile */ + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + int numres2decode; + + if (tcd->cp->reduce != 0) { + if ( tile->comps[compno].numresolutions < ( tcd->cp->reduce - 1 ) ) { + opj_event_msg(tcd->cinfo, EVT_ERROR, "Error decoding tile. The number of resolutions to remove [%d+1] is higher than the number " + " of resolutions in the original codestream [%d]\nModify the cp_reduce parameter.\n", tcd->cp->reduce, tile->comps[compno].numresolutions); + return OPJ_FALSE; + } + else { + tcd->image->comps[compno].resno_decoded = + tile->comps[compno].numresolutions - tcd->cp->reduce - 1; + } + } + + numres2decode = tcd->image->comps[compno].resno_decoded + 1; + if(numres2decode > 0){ + if (tcd->tcp->tccps[compno].qmfbid == 1) { + dwt_decode(tilec, numres2decode); + } else { + dwt_decode_real(tilec, numres2decode); + } + } + } + dwt_time = opj_clock() - dwt_time; + opj_event_msg(tcd->cinfo, EVT_INFO, "- dwt took %f s\n", dwt_time); + + /*----------------MCT-------------------*/ + + if (tcd->tcp->mct) { + int n = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0); + + if (tile->numcomps >= 3 ){ + if (tcd->tcp->tccps[0].qmfbid == 1) { + mct_decode( + tile->comps[0].data, + tile->comps[1].data, + tile->comps[2].data, + n); + } else { + mct_decode_real( + (float*)tile->comps[0].data, + (float*)tile->comps[1].data, + (float*)tile->comps[2].data, + n); + } + } else{ + opj_event_msg(tcd->cinfo, EVT_WARNING,"Number of components (%d) is inconsistent with a MCT. Skip the MCT step.\n",tile->numcomps); + } + } + + /*---------------TILE-------------------*/ + + for (compno = 0; compno < tile->numcomps; ++compno) { + opj_tcd_tilecomp_t* tilec = &tile->comps[compno]; + opj_image_comp_t* imagec = &tcd->image->comps[compno]; + opj_tcd_resolution_t* res = &tilec->resolutions[imagec->resno_decoded]; + int adjust = imagec->sgnd ? 0 : 1 << (imagec->prec - 1); + int min = imagec->sgnd ? -(1 << (imagec->prec - 1)) : 0; + int max = imagec->sgnd ? (1 << (imagec->prec - 1)) - 1 : (1 << imagec->prec) - 1; + + int tw = tilec->x1 - tilec->x0; + int w = imagec->w; + + int offset_x = int_ceildivpow2(imagec->x0, imagec->factor); + int offset_y = int_ceildivpow2(imagec->y0, imagec->factor); + + int i, j; + if(!imagec->data){ + imagec->data = (int*) opj_malloc(imagec->w * imagec->h * sizeof(int)); + } + if (!imagec->data) + { + opj_event_msg(tcd->cinfo, EVT_ERROR, "Out of memory\n"); + return OPJ_FALSE; + } + if(tcd->tcp->tccps[compno].qmfbid == 1) { + for(j = res->y0; j < res->y1; ++j) { + for(i = res->x0; i < res->x1; ++i) { + int v = tilec->data[i - res->x0 + (j - res->y0) * tw]; + v += adjust; + imagec->data[(i - offset_x) + (j - offset_y) * w] = int_clamp(v, min, max); + } + } + }else{ + for(j = res->y0; j < res->y1; ++j) { + for(i = res->x0; i < res->x1; ++i) { + float tmp = ((float*)tilec->data)[i - res->x0 + (j - res->y0) * tw]; + int v = lrintf(tmp); + v += adjust; + imagec->data[(i - offset_x) + (j - offset_y) * w] = int_clamp(v, min, max); + } + } + } + opj_aligned_free(tilec->data); + } + + tile_time = opj_clock() - tile_time; /* time needed to decode a tile */ + opj_event_msg(tcd->cinfo, EVT_INFO, "- tile decoded in %f s\n", tile_time); + + if (eof) { + return OPJ_FALSE; + } + + return OPJ_TRUE; +} + +void tcd_free_decode(opj_tcd_t *tcd) { + opj_tcd_image_t *tcd_image = tcd->tcd_image; + int i = 0; + for (i = 0; i < tcd_image->tw * tcd_image->th; i++) + { + tcd_free_decode_tile(tcd, i); + } + + opj_free(tcd_image->tiles); +} + +void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno) { + int compno,resno,bandno,precno,cblkno; + + opj_tcd_image_t *tcd_image = tcd->tcd_image; + + opj_tcd_tile_t *tile = &tcd_image->tiles[tileno]; + if (tile->comps != NULL) { + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + for (resno = 0; resno < tilec->numresolutions; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + for (precno = 0; precno < res->ph * res->pw; precno++) { + opj_tcd_precinct_t *prec = &band->precincts[precno]; + if (prec->cblks.dec != NULL) { + for (cblkno = 0; cblkno < prec->cw * prec->ch; ++cblkno) { + opj_tcd_cblk_dec_t* cblk = &prec->cblks.dec[cblkno]; + opj_free(cblk->data); + opj_free(cblk->segs); + } + opj_free(prec->cblks.dec); + } + if (prec->imsbtree != NULL) tgt_destroy(prec->imsbtree); + if (prec->incltree != NULL) tgt_destroy(prec->incltree); + + + } + opj_free(band->precincts); + } + } + opj_free(tilec->resolutions); + } + opj_free(tile->comps); + tile->comps = NULL; + } +} + + + diff --git a/Source/LibOpenJPEG/tcd.h b/Source/LibOpenJPEG/tcd.h index 6333a73..e3f93ad 100644 --- a/Source/LibOpenJPEG/tcd.h +++ b/Source/LibOpenJPEG/tcd.h @@ -1,286 +1,286 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __TCD_H -#define __TCD_H -/** -@file tcd.h -@brief Implementation of a tile coder/decoder (TCD) - -The functions in TCD.C have for goal to encode or decode each tile independently from -each other. The functions in TCD.C are used by some function in J2K.C. -*/ - -/** @defgroup TCD TCD - Implementation of a tile coder/decoder */ -/*@{*/ - -/** -FIXME: documentation -*/ -typedef struct opj_tcd_seg { - unsigned char** data; - int dataindex; - int numpasses; - int len; - int maxpasses; - int numnewpasses; - int newlen; -} opj_tcd_seg_t; - -/** -FIXME: documentation -*/ -typedef struct opj_tcd_pass { - int rate; - double distortiondec; - int term, len; -} opj_tcd_pass_t; - -/** -FIXME: documentation -*/ -typedef struct opj_tcd_layer { - int numpasses; /* Number of passes in the layer */ - int len; /* len of information */ - double disto; /* add for index (Cfr. Marcela) */ - unsigned char *data; /* data */ -} opj_tcd_layer_t; - -/** -FIXME: documentation -*/ -typedef struct opj_tcd_cblk_enc { - unsigned char* data; /* Data */ - opj_tcd_layer_t* layers; /* layer information */ - opj_tcd_pass_t* passes; /* information about the passes */ - int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ - int numbps; - int numlenbits; - int numpasses; /* number of pass already done for the code-blocks */ - int numpassesinlayers; /* number of passes in the layer */ - int totalpasses; /* total number of passes */ -} opj_tcd_cblk_enc_t; - -typedef struct opj_tcd_cblk_dec { - unsigned char* data; /* Data */ - opj_tcd_seg_t* segs; /* segments informations */ - int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ - int numbps; - int numlenbits; - int len; /* length */ - int numnewpasses; /* number of pass added to the code-blocks */ - int numsegs; /* number of segments */ -} opj_tcd_cblk_dec_t; - -/** -FIXME: documentation -*/ -typedef struct opj_tcd_precinct { - int x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */ - int cw, ch; /* number of precinct in width and heigth */ - union{ /* code-blocks informations */ - opj_tcd_cblk_enc_t* enc; - opj_tcd_cblk_dec_t* dec; - } cblks; - opj_tgt_tree_t *incltree; /* inclusion tree */ - opj_tgt_tree_t *imsbtree; /* IMSB tree */ -} opj_tcd_precinct_t; - -/** -FIXME: documentation -*/ -typedef struct opj_tcd_band { - int x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */ - int bandno; - opj_tcd_precinct_t *precincts; /* precinct information */ - int numbps; - float stepsize; -} opj_tcd_band_t; - -/** -FIXME: documentation -*/ -typedef struct opj_tcd_resolution { - int x0, y0, x1, y1; /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */ - int pw, ph; - int numbands; /* number sub-band for the resolution level */ - opj_tcd_band_t bands[3]; /* subband information */ -} opj_tcd_resolution_t; - -/** -FIXME: documentation -*/ -typedef struct opj_tcd_tilecomp { - int x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */ - int numresolutions; /* number of resolutions level */ - opj_tcd_resolution_t *resolutions; /* resolutions information */ - int *data; /* data of the component */ - int numpix; /* add fixed_quality */ -} opj_tcd_tilecomp_t; - -/** -FIXME: documentation -*/ -typedef struct opj_tcd_tile { - int x0, y0, x1, y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */ - int numcomps; /* number of components in tile */ - opj_tcd_tilecomp_t *comps; /* Components information */ - int numpix; /* add fixed_quality */ - double distotile; /* add fixed_quality */ - double distolayer[100]; /* add fixed_quality */ - /** packet number */ - int packno; -} opj_tcd_tile_t; - -/** -FIXME: documentation -*/ -typedef struct opj_tcd_image { - int tw, th; /* number of tiles in width and heigth */ - opj_tcd_tile_t *tiles; /* Tiles information */ -} opj_tcd_image_t; - -/** -Tile coder/decoder -*/ -typedef struct opj_tcd { - /** Position of the tilepart flag in Progression order*/ - int tp_pos; - /** Tile part number*/ - int tp_num; - /** Current tile part number*/ - int cur_tp_num; - /** Total number of tileparts of the current tile*/ - int cur_totnum_tp; - /** Current Packet iterator number */ - int cur_pino; - /** codec context */ - opj_common_ptr cinfo; - - /** info on each image tile */ - opj_tcd_image_t *tcd_image; - /** image */ - opj_image_t *image; - /** coding parameters */ - opj_cp_t *cp; - /** pointer to the current encoded/decoded tile */ - opj_tcd_tile_t *tcd_tile; - /** coding/decoding parameters common to all tiles */ - opj_tcp_t *tcp; - /** current encoded/decoded tile */ - int tcd_tileno; - /** Time taken to encode a tile*/ - double encoding_time; -} opj_tcd_t; - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ - -/** -Dump the content of a tcd structure -*/ -void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t *img); -/** -Create a new TCD handle -@param cinfo Codec context info -@return Returns a new TCD handle if successful returns NULL otherwise -*/ -opj_tcd_t* tcd_create(opj_common_ptr cinfo); -/** -Destroy a previously created TCD handle -@param tcd TCD handle to destroy -*/ -void tcd_destroy(opj_tcd_t *tcd); -/** -Initialize the tile coder (allocate the memory) -@param tcd TCD handle -@param image Raw image -@param cp Coding parameters -@param curtileno Number that identifies the tile that will be encoded -*/ -void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno); -/** -Free the memory allocated for encoding -@param tcd TCD handle -*/ -void tcd_free_encode(opj_tcd_t *tcd); -/** -Initialize the tile coder (reuses the memory allocated by tcd_malloc_encode) -@param tcd TCD handle -@param image Raw image -@param cp Coding parameters -@param curtileno Number that identifies the tile that will be encoded -*/ -void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno); -/** -Initialize the tile decoder -@param tcd TCD handle -@param image Raw image -@param cp Coding parameters -*/ -void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp); -void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int tileno, opj_codestream_info_t *cstr_info); -void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final); -void tcd_rateallocate_fixed(opj_tcd_t *tcd); -void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final); -opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info); -/** -Encode a tile from the raw image into a buffer -@param tcd TCD handle -@param tileno Number that identifies one of the tiles to be encoded -@param dest Destination buffer -@param len Length of destination buffer -@param cstr_info Codestream information structure -@return -*/ -int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info); -/** -Decode a tile from a buffer into a raw image -@param tcd TCD handle -@param src Source buffer -@param len Length of source buffer -@param tileno Number that identifies one of the tiles to be decoded -@param cstr_info Codestream information structure -*/ -opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info); -/** -Free the memory allocated for decoding -@param tcd TCD handle -*/ -void tcd_free_decode(opj_tcd_t *tcd); -void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno); - -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __TCD_H */ +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __TCD_H +#define __TCD_H +/** +@file tcd.h +@brief Implementation of a tile coder/decoder (TCD) + +The functions in TCD.C have for goal to encode or decode each tile independently from +each other. The functions in TCD.C are used by some function in J2K.C. +*/ + +/** @defgroup TCD TCD - Implementation of a tile coder/decoder */ +/*@{*/ + +/** +FIXME: documentation +*/ +typedef struct opj_tcd_seg { + unsigned char** data; + int dataindex; + int numpasses; + int len; + int maxpasses; + int numnewpasses; + int newlen; +} opj_tcd_seg_t; + +/** +FIXME: documentation +*/ +typedef struct opj_tcd_pass { + int rate; + double distortiondec; + int term, len; +} opj_tcd_pass_t; + +/** +FIXME: documentation +*/ +typedef struct opj_tcd_layer { + int numpasses; /* Number of passes in the layer */ + int len; /* len of information */ + double disto; /* add for index (Cfr. Marcela) */ + unsigned char *data; /* data */ +} opj_tcd_layer_t; + +/** +FIXME: documentation +*/ +typedef struct opj_tcd_cblk_enc { + unsigned char* data; /* Data */ + opj_tcd_layer_t* layers; /* layer information */ + opj_tcd_pass_t* passes; /* information about the passes */ + int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ + int numbps; + int numlenbits; + int numpasses; /* number of pass already done for the code-blocks */ + int numpassesinlayers; /* number of passes in the layer */ + int totalpasses; /* total number of passes */ +} opj_tcd_cblk_enc_t; + +typedef struct opj_tcd_cblk_dec { + unsigned char* data; /* Data */ + opj_tcd_seg_t* segs; /* segments informations */ + int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ + int numbps; + int numlenbits; + int len; /* length */ + int numnewpasses; /* number of pass added to the code-blocks */ + int numsegs; /* number of segments */ +} opj_tcd_cblk_dec_t; + +/** +FIXME: documentation +*/ +typedef struct opj_tcd_precinct { + int x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */ + int cw, ch; /* number of precinct in width and heigth */ + union{ /* code-blocks informations */ + opj_tcd_cblk_enc_t* enc; + opj_tcd_cblk_dec_t* dec; + } cblks; + opj_tgt_tree_t *incltree; /* inclusion tree */ + opj_tgt_tree_t *imsbtree; /* IMSB tree */ +} opj_tcd_precinct_t; + +/** +FIXME: documentation +*/ +typedef struct opj_tcd_band { + int x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */ + int bandno; + opj_tcd_precinct_t *precincts; /* precinct information */ + int numbps; + float stepsize; +} opj_tcd_band_t; + +/** +FIXME: documentation +*/ +typedef struct opj_tcd_resolution { + int x0, y0, x1, y1; /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */ + int pw, ph; + int numbands; /* number sub-band for the resolution level */ + opj_tcd_band_t bands[3]; /* subband information */ +} opj_tcd_resolution_t; + +/** +FIXME: documentation +*/ +typedef struct opj_tcd_tilecomp { + int x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */ + int numresolutions; /* number of resolutions level */ + opj_tcd_resolution_t *resolutions; /* resolutions information */ + int *data; /* data of the component */ + int numpix; /* add fixed_quality */ +} opj_tcd_tilecomp_t; + +/** +FIXME: documentation +*/ +typedef struct opj_tcd_tile { + int x0, y0, x1, y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */ + int numcomps; /* number of components in tile */ + opj_tcd_tilecomp_t *comps; /* Components information */ + int numpix; /* add fixed_quality */ + double distotile; /* add fixed_quality */ + double distolayer[100]; /* add fixed_quality */ + /** packet number */ + int packno; +} opj_tcd_tile_t; + +/** +FIXME: documentation +*/ +typedef struct opj_tcd_image { + int tw, th; /* number of tiles in width and heigth */ + opj_tcd_tile_t *tiles; /* Tiles information */ +} opj_tcd_image_t; + +/** +Tile coder/decoder +*/ +typedef struct opj_tcd { + /** Position of the tilepart flag in Progression order*/ + int tp_pos; + /** Tile part number*/ + int tp_num; + /** Current tile part number*/ + int cur_tp_num; + /** Total number of tileparts of the current tile*/ + int cur_totnum_tp; + /** Current Packet iterator number */ + int cur_pino; + /** codec context */ + opj_common_ptr cinfo; + + /** info on each image tile */ + opj_tcd_image_t *tcd_image; + /** image */ + opj_image_t *image; + /** coding parameters */ + opj_cp_t *cp; + /** pointer to the current encoded/decoded tile */ + opj_tcd_tile_t *tcd_tile; + /** coding/decoding parameters common to all tiles */ + opj_tcp_t *tcp; + /** current encoded/decoded tile */ + int tcd_tileno; + /** Time taken to encode a tile*/ + double encoding_time; +} opj_tcd_t; + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ + +/** +Dump the content of a tcd structure +*/ +void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t *img); +/** +Create a new TCD handle +@param cinfo Codec context info +@return Returns a new TCD handle if successful returns NULL otherwise +*/ +opj_tcd_t* tcd_create(opj_common_ptr cinfo); +/** +Destroy a previously created TCD handle +@param tcd TCD handle to destroy +*/ +void tcd_destroy(opj_tcd_t *tcd); +/** +Initialize the tile coder (allocate the memory) +@param tcd TCD handle +@param image Raw image +@param cp Coding parameters +@param curtileno Number that identifies the tile that will be encoded +*/ +void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno); +/** +Free the memory allocated for encoding +@param tcd TCD handle +*/ +void tcd_free_encode(opj_tcd_t *tcd); +/** +Initialize the tile coder (reuses the memory allocated by tcd_malloc_encode) +@param tcd TCD handle +@param image Raw image +@param cp Coding parameters +@param curtileno Number that identifies the tile that will be encoded +*/ +void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno); +/** +Initialize the tile decoder +@param tcd TCD handle +@param image Raw image +@param cp Coding parameters +*/ +void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp); +void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int tileno, opj_codestream_info_t *cstr_info); +void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final); +void tcd_rateallocate_fixed(opj_tcd_t *tcd); +void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final); +opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info); +/** +Encode a tile from the raw image into a buffer +@param tcd TCD handle +@param tileno Number that identifies one of the tiles to be encoded +@param dest Destination buffer +@param len Length of destination buffer +@param cstr_info Codestream information structure +@return +*/ +int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info); +/** +Decode a tile from a buffer into a raw image +@param tcd TCD handle +@param src Source buffer +@param len Length of source buffer +@param tileno Number that identifies one of the tiles to be decoded +@param cstr_info Codestream information structure +*/ +opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info); +/** +Free the memory allocated for decoding +@param tcd TCD handle +*/ +void tcd_free_decode(opj_tcd_t *tcd); +void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno); + +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __TCD_H */ diff --git a/Source/LibOpenJPEG/tgt.c b/Source/LibOpenJPEG/tgt.c index f1329ca..a5dbcd3 100644 --- a/Source/LibOpenJPEG/tgt.c +++ b/Source/LibOpenJPEG/tgt.c @@ -1,213 +1,213 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/* -========================================================== - Tag-tree coder interface -========================================================== -*/ - -opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv) { - int nplh[32]; - int nplv[32]; - opj_tgt_node_t *node = NULL; - opj_tgt_node_t *parentnode = NULL; - opj_tgt_node_t *parentnode0 = NULL; - opj_tgt_tree_t *tree = NULL; - int i, j, k; - int numlvls; - int n; - - tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t)); - if(!tree) return NULL; - tree->numleafsh = numleafsh; - tree->numleafsv = numleafsv; - - numlvls = 0; - nplh[0] = numleafsh; - nplv[0] = numleafsv; - tree->numnodes = 0; - do { - n = nplh[numlvls] * nplv[numlvls]; - nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2; - nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2; - tree->numnodes += n; - ++numlvls; - } while (n > 1); - - /* ADD */ - if (tree->numnodes == 0) { - opj_free(tree); - return NULL; - } - - tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t)); - if(!tree->nodes) { - opj_free(tree); - return NULL; - } - - node = tree->nodes; - parentnode = &tree->nodes[tree->numleafsh * tree->numleafsv]; - parentnode0 = parentnode; - - for (i = 0; i < numlvls - 1; ++i) { - for (j = 0; j < nplv[i]; ++j) { - k = nplh[i]; - while (--k >= 0) { - node->parent = parentnode; - ++node; - if (--k >= 0) { - node->parent = parentnode; - ++node; - } - ++parentnode; - } - if ((j & 1) || j == nplv[i] - 1) { - parentnode0 = parentnode; - } else { - parentnode = parentnode0; - parentnode0 += nplh[i]; - } - } - } - node->parent = 0; - - tgt_reset(tree); - - return tree; -} - -void tgt_destroy(opj_tgt_tree_t *tree) { - opj_free(tree->nodes); - opj_free(tree); -} - -void tgt_reset(opj_tgt_tree_t *tree) { - int i; - - if (NULL == tree) - return; - - for (i = 0; i < tree->numnodes; i++) { - tree->nodes[i].value = 999; - tree->nodes[i].low = 0; - tree->nodes[i].known = 0; - } -} - -void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value) { - opj_tgt_node_t *node; - node = &tree->nodes[leafno]; - while (node && node->value > value) { - node->value = value; - node = node->parent; - } -} - -void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) { - opj_tgt_node_t *stk[31]; - opj_tgt_node_t **stkptr; - opj_tgt_node_t *node; - int low; - - stkptr = stk; - node = &tree->nodes[leafno]; - while (node->parent) { - *stkptr++ = node; - node = node->parent; - } - - low = 0; - for (;;) { - if (low > node->low) { - node->low = low; - } else { - low = node->low; - } - - while (low < threshold) { - if (low >= node->value) { - if (!node->known) { - bio_write(bio, 1, 1); - node->known = 1; - } - break; - } - bio_write(bio, 0, 1); - ++low; - } - - node->low = low; - if (stkptr == stk) - break; - node = *--stkptr; - } -} - -int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) { - opj_tgt_node_t *stk[31]; - opj_tgt_node_t **stkptr; - opj_tgt_node_t *node; - int low; - - stkptr = stk; - node = &tree->nodes[leafno]; - while (node->parent) { - *stkptr++ = node; - node = node->parent; - } - - low = 0; - for (;;) { - if (low > node->low) { - node->low = low; - } else { - low = node->low; - } - while (low < threshold && low < node->value) { - if (bio_read(bio, 1)) { - node->value = low; - } else { - ++low; - } - } - node->low = low; - if (stkptr == stk) { - break; - } - node = *--stkptr; - } - - return (node->value < threshold) ? 1 : 0; -} +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/* +========================================================== + Tag-tree coder interface +========================================================== +*/ + +opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv) { + int nplh[32]; + int nplv[32]; + opj_tgt_node_t *node = NULL; + opj_tgt_node_t *parentnode = NULL; + opj_tgt_node_t *parentnode0 = NULL; + opj_tgt_tree_t *tree = NULL; + int i, j, k; + int numlvls; + int n; + + tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t)); + if(!tree) return NULL; + tree->numleafsh = numleafsh; + tree->numleafsv = numleafsv; + + numlvls = 0; + nplh[0] = numleafsh; + nplv[0] = numleafsv; + tree->numnodes = 0; + do { + n = nplh[numlvls] * nplv[numlvls]; + nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2; + nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2; + tree->numnodes += n; + ++numlvls; + } while (n > 1); + + /* ADD */ + if (tree->numnodes == 0) { + opj_free(tree); + return NULL; + } + + tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t)); + if(!tree->nodes) { + opj_free(tree); + return NULL; + } + + node = tree->nodes; + parentnode = &tree->nodes[tree->numleafsh * tree->numleafsv]; + parentnode0 = parentnode; + + for (i = 0; i < numlvls - 1; ++i) { + for (j = 0; j < nplv[i]; ++j) { + k = nplh[i]; + while (--k >= 0) { + node->parent = parentnode; + ++node; + if (--k >= 0) { + node->parent = parentnode; + ++node; + } + ++parentnode; + } + if ((j & 1) || j == nplv[i] - 1) { + parentnode0 = parentnode; + } else { + parentnode = parentnode0; + parentnode0 += nplh[i]; + } + } + } + node->parent = 0; + + tgt_reset(tree); + + return tree; +} + +void tgt_destroy(opj_tgt_tree_t *tree) { + opj_free(tree->nodes); + opj_free(tree); +} + +void tgt_reset(opj_tgt_tree_t *tree) { + int i; + + if (NULL == tree) + return; + + for (i = 0; i < tree->numnodes; i++) { + tree->nodes[i].value = 999; + tree->nodes[i].low = 0; + tree->nodes[i].known = 0; + } +} + +void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value) { + opj_tgt_node_t *node; + node = &tree->nodes[leafno]; + while (node && node->value > value) { + node->value = value; + node = node->parent; + } +} + +void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) { + opj_tgt_node_t *stk[31]; + opj_tgt_node_t **stkptr; + opj_tgt_node_t *node; + int low; + + stkptr = stk; + node = &tree->nodes[leafno]; + while (node->parent) { + *stkptr++ = node; + node = node->parent; + } + + low = 0; + for (;;) { + if (low > node->low) { + node->low = low; + } else { + low = node->low; + } + + while (low < threshold) { + if (low >= node->value) { + if (!node->known) { + bio_write(bio, 1, 1); + node->known = 1; + } + break; + } + bio_write(bio, 0, 1); + ++low; + } + + node->low = low; + if (stkptr == stk) + break; + node = *--stkptr; + } +} + +int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) { + opj_tgt_node_t *stk[31]; + opj_tgt_node_t **stkptr; + opj_tgt_node_t *node; + int low; + + stkptr = stk; + node = &tree->nodes[leafno]; + while (node->parent) { + *stkptr++ = node; + node = node->parent; + } + + low = 0; + for (;;) { + if (low > node->low) { + node->low = low; + } else { + low = node->low; + } + while (low < threshold && low < node->value) { + if (bio_read(bio, 1)) { + node->value = low; + } else { + ++low; + } + } + node->low = low; + if (stkptr == stk) { + break; + } + node = *--stkptr; + } + + return (node->value < threshold) ? 1 : 0; +} diff --git a/Source/LibOpenJPEG/tgt.h b/Source/LibOpenJPEG/tgt.h index 2544767..c08c8da 100644 --- a/Source/LibOpenJPEG/tgt.h +++ b/Source/LibOpenJPEG/tgt.h @@ -1,114 +1,114 @@ -/* - * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2007, Professor Benoit Macq - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __TGT_H -#define __TGT_H -/** -@file tgt.h -@brief Implementation of a tag-tree coder (TGT) - -The functions in TGT.C have for goal to realize a tag-tree coder. The functions in TGT.C -are used by some function in T2.C. -*/ - -/** @defgroup TGT TGT - Implementation of a tag-tree coder */ -/*@{*/ - -/** -Tag node -*/ -typedef struct opj_tgt_node { - struct opj_tgt_node *parent; - int value; - int low; - int known; -} opj_tgt_node_t; - -/** -Tag tree -*/ -typedef struct opj_tgt_tree { - int numleafsh; - int numleafsv; - int numnodes; - opj_tgt_node_t *nodes; -} opj_tgt_tree_t; - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Create a tag-tree -@param numleafsh Width of the array of leafs of the tree -@param numleafsv Height of the array of leafs of the tree -@return Returns a new tag-tree if successful, returns NULL otherwise -*/ -opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv); -/** -Destroy a tag-tree, liberating memory -@param tree Tag-tree to destroy -*/ -void tgt_destroy(opj_tgt_tree_t *tree); -/** -Reset a tag-tree (set all leaves to 0) -@param tree Tag-tree to reset -*/ -void tgt_reset(opj_tgt_tree_t *tree); -/** -Set the value of a leaf of a tag-tree -@param tree Tag-tree to modify -@param leafno Number that identifies the leaf to modify -@param value New value of the leaf -*/ -void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value); -/** -Encode the value of a leaf of the tag-tree up to a given threshold -@param bio Pointer to a BIO handle -@param tree Tag-tree to modify -@param leafno Number that identifies the leaf to encode -@param threshold Threshold to use when encoding value of the leaf -*/ -void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold); -/** -Decode the value of a leaf of the tag-tree up to a given threshold -@param bio Pointer to a BIO handle -@param tree Tag-tree to decode -@param leafno Number that identifies the leaf to decode -@param threshold Threshold to use when decoding value of the leaf -@return Returns 1 if the node's value < threshold, returns 0 otherwise -*/ -int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __TGT_H */ +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __TGT_H +#define __TGT_H +/** +@file tgt.h +@brief Implementation of a tag-tree coder (TGT) + +The functions in TGT.C have for goal to realize a tag-tree coder. The functions in TGT.C +are used by some function in T2.C. +*/ + +/** @defgroup TGT TGT - Implementation of a tag-tree coder */ +/*@{*/ + +/** +Tag node +*/ +typedef struct opj_tgt_node { + struct opj_tgt_node *parent; + int value; + int low; + int known; +} opj_tgt_node_t; + +/** +Tag tree +*/ +typedef struct opj_tgt_tree { + int numleafsh; + int numleafsv; + int numnodes; + opj_tgt_node_t *nodes; +} opj_tgt_tree_t; + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Create a tag-tree +@param numleafsh Width of the array of leafs of the tree +@param numleafsv Height of the array of leafs of the tree +@return Returns a new tag-tree if successful, returns NULL otherwise +*/ +opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv); +/** +Destroy a tag-tree, liberating memory +@param tree Tag-tree to destroy +*/ +void tgt_destroy(opj_tgt_tree_t *tree); +/** +Reset a tag-tree (set all leaves to 0) +@param tree Tag-tree to reset +*/ +void tgt_reset(opj_tgt_tree_t *tree); +/** +Set the value of a leaf of a tag-tree +@param tree Tag-tree to modify +@param leafno Number that identifies the leaf to modify +@param value New value of the leaf +*/ +void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value); +/** +Encode the value of a leaf of the tag-tree up to a given threshold +@param bio Pointer to a BIO handle +@param tree Tag-tree to modify +@param leafno Number that identifies the leaf to encode +@param threshold Threshold to use when encoding value of the leaf +*/ +void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold); +/** +Decode the value of a leaf of the tag-tree up to a given threshold +@param bio Pointer to a BIO handle +@param tree Tag-tree to decode +@param leafno Number that identifies the leaf to decode +@param threshold Threshold to use when decoding value of the leaf +@return Returns 1 if the node's value < threshold, returns 0 otherwise +*/ +int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __TGT_H */ diff --git a/Source/LibOpenJPEG/thix_manager.c b/Source/LibOpenJPEG/thix_manager.c index ed6e9f9..5183178 100644 --- a/Source/LibOpenJPEG/thix_manager.c +++ b/Source/LibOpenJPEG/thix_manager.c @@ -1,120 +1,120 @@ -/* - * $Id: thix_manager.c,v 1.2 2012/09/23 12:44:41 drolon Exp $ - * - * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium - * Copyright (c) 2002-2011, Professor Benoit Macq - * Copyright (c) 2003-2004, Yannick Verschueren - * Copyright (c) 2010-2011, Kaori Hagihara - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/*! \file - * \brief Modification of jpip.c from 2KAN indexer - */ - -#include -#include -#include -#include "opj_includes.h" - -/* - * Write tile-part headers mhix box - * - * @param[in] coff offset of j2k codestream - * @param[in] cstr_info codestream information - * @param[in] tileno tile number - * @param[in] cio file output handle - * @return length of mhix box - */ -int write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_cio_t *cio); - -int write_thix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio) -{ - int len, lenp, i; - int tileno; - opj_jp2_box_t *box; - - lenp = 0; - box = (opj_jp2_box_t *)opj_calloc( cstr_info.tw*cstr_info.th, sizeof(opj_jp2_box_t)); - - for ( i = 0; i < 2 ; i++ ){ - if (i) - cio_seek( cio, lenp); - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_THIX, 4); /* THIX */ - write_manf( i, cstr_info.tw*cstr_info.th, box, cio); - - for (tileno = 0; tileno < cstr_info.tw*cstr_info.th; tileno++){ - box[tileno].length = write_tilemhix( coff, cstr_info, tileno, cio); - box[tileno].type = JPIP_MHIX; - } - - len = cio_tell( cio)-lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); - } - - opj_free(box); - - return len; -} - -int write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_cio_t *cio) -{ - int i; - opj_tile_info_t tile; - opj_tp_info_t tp; - int len, lenp; - opj_marker_info_t *marker; - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_MHIX, 4); /* MHIX */ - - tile = cstr_info.tile[tileno]; - tp = tile.tp[0]; - - cio_write( cio, tp.tp_end_header-tp.tp_start_pos+1, 8); /* TLEN */ - - marker = cstr_info.tile[tileno].marker; - - for( i=0; i +#include +#include +#include "opj_includes.h" + +/* + * Write tile-part headers mhix box + * + * @param[in] coff offset of j2k codestream + * @param[in] cstr_info codestream information + * @param[in] tileno tile number + * @param[in] cio file output handle + * @return length of mhix box + */ +int write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_cio_t *cio); + +int write_thix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio) +{ + int len, lenp, i; + int tileno; + opj_jp2_box_t *box; + + lenp = 0; + box = (opj_jp2_box_t *)opj_calloc( cstr_info.tw*cstr_info.th, sizeof(opj_jp2_box_t)); + + for ( i = 0; i < 2 ; i++ ){ + if (i) + cio_seek( cio, lenp); + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_THIX, 4); /* THIX */ + write_manf( i, cstr_info.tw*cstr_info.th, box, cio); + + for (tileno = 0; tileno < cstr_info.tw*cstr_info.th; tileno++){ + box[tileno].length = write_tilemhix( coff, cstr_info, tileno, cio); + box[tileno].type = JPIP_MHIX; + } + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); + } + + opj_free(box); + + return len; +} + +int write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_cio_t *cio) +{ + int i; + opj_tile_info_t tile; + opj_tp_info_t tp; + int len, lenp; + opj_marker_info_t *marker; + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_MHIX, 4); /* MHIX */ + + tile = cstr_info.tile[tileno]; + tp = tile.tp[0]; + + cio_write( cio, tp.tp_end_header-tp.tp_start_pos+1, 8); /* TLEN */ + + marker = cstr_info.tile[tileno].marker; + + for( i=0; i -#include "opj_includes.h" - -#define MAX(a,b) ((a)>(b)?(a):(b)) - - -/* - * Write faix box of tpix - * - * @param[in] coff offset of j2k codestream - * @param[in] compno component number - * @param[in] cstr_info codestream information - * @param[in] j2klen length of j2k codestream - * @param[in] cio file output handle - * @return length of faix box - */ -int write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio); - - -int write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio) -{ - int len, lenp; - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_TPIX, 4); /* TPIX */ - - write_tpixfaix( coff, 0, cstr_info, j2klen, cio); - - len = cio_tell( cio)-lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); - - return len; -} - - -/* - * Get number of maximum tile parts per tile - * - * @param[in] cstr_info codestream information - * @return number of maximum tile parts per tile - */ -int get_num_max_tile_parts( opj_codestream_info_t cstr_info); - -int write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio) -{ - int len, lenp; - int i, j; - int Aux; - int num_max_tile_parts; - int size_of_coding; /* 4 or 8 */ - opj_tp_info_t tp; - int version; - - num_max_tile_parts = get_num_max_tile_parts( cstr_info); - - if( j2klen > pow( 2, 32)){ - size_of_coding = 8; - version = num_max_tile_parts == 1 ? 1:3; - } - else{ - size_of_coding = 4; - version = num_max_tile_parts == 1 ? 0:2; - } - - lenp = cio_tell( cio); - cio_skip( cio, 4); /* L [at the end] */ - cio_write( cio, JPIP_FAIX, 4); /* FAIX */ - cio_write( cio, version, 1); /* Version 0 = 4 bytes */ - - cio_write( cio, num_max_tile_parts, size_of_coding); /* NMAX */ - cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */ - for (i = 0; i < cstr_info.tw*cstr_info.th; i++){ - for (j = 0; j < cstr_info.tile[i].num_tps; j++){ - tp = cstr_info.tile[i].tp[j]; - cio_write( cio, tp.tp_start_pos-coff, size_of_coding); /* start position */ - cio_write( cio, tp.tp_end_pos-tp.tp_start_pos+1, size_of_coding); /* length */ - if (version & 0x02){ - if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1) - Aux = cstr_info.numdecompos[compno] + 1; - else - Aux = j + 1; - - cio_write( cio, Aux,4); - /*cio_write(img.tile[i].tile_parts[j].num_reso_AUX,4);*/ /* Aux_i,j : Auxiliary value */ - /* fprintf(stderr,"AUX value %d\n",Aux);*/ - } - /*cio_write(0,4);*/ - } - /* PADDING */ - while (j < num_max_tile_parts){ - cio_write( cio, 0, size_of_coding); /* start position */ - cio_write( cio, 0, size_of_coding); /* length */ - if (version & 0x02) - cio_write( cio, 0,4); /* Aux_i,j : Auxiliary value */ - j++; - } - } - - len = cio_tell( cio)-lenp; - cio_seek( cio, lenp); - cio_write( cio, len, 4); /* L */ - cio_seek( cio, lenp+len); - - return len; - -} - -int get_num_max_tile_parts( opj_codestream_info_t cstr_info) -{ - int num_max_tp = 0, i; - - for( i=0; i +#include "opj_includes.h" + +#define MAX(a,b) ((a)>(b)?(a):(b)) + + +/* + * Write faix box of tpix + * + * @param[in] coff offset of j2k codestream + * @param[in] compno component number + * @param[in] cstr_info codestream information + * @param[in] j2klen length of j2k codestream + * @param[in] cio file output handle + * @return length of faix box + */ +int write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio); + + +int write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio) +{ + int len, lenp; + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_TPIX, 4); /* TPIX */ + + write_tpixfaix( coff, 0, cstr_info, j2klen, cio); + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); + + return len; +} + + +/* + * Get number of maximum tile parts per tile + * + * @param[in] cstr_info codestream information + * @return number of maximum tile parts per tile + */ +int get_num_max_tile_parts( opj_codestream_info_t cstr_info); + +int write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio) +{ + int len, lenp; + int i, j; + int Aux; + int num_max_tile_parts; + int size_of_coding; /* 4 or 8 */ + opj_tp_info_t tp; + int version; + + num_max_tile_parts = get_num_max_tile_parts( cstr_info); + + if( j2klen > pow( 2, 32)){ + size_of_coding = 8; + version = num_max_tile_parts == 1 ? 1:3; + } + else{ + size_of_coding = 4; + version = num_max_tile_parts == 1 ? 0:2; + } + + lenp = cio_tell( cio); + cio_skip( cio, 4); /* L [at the end] */ + cio_write( cio, JPIP_FAIX, 4); /* FAIX */ + cio_write( cio, version, 1); /* Version 0 = 4 bytes */ + + cio_write( cio, num_max_tile_parts, size_of_coding); /* NMAX */ + cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */ + for (i = 0; i < cstr_info.tw*cstr_info.th; i++){ + for (j = 0; j < cstr_info.tile[i].num_tps; j++){ + tp = cstr_info.tile[i].tp[j]; + cio_write( cio, tp.tp_start_pos-coff, size_of_coding); /* start position */ + cio_write( cio, tp.tp_end_pos-tp.tp_start_pos+1, size_of_coding); /* length */ + if (version & 0x02){ + if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1) + Aux = cstr_info.numdecompos[compno] + 1; + else + Aux = j + 1; + + cio_write( cio, Aux,4); + /*cio_write(img.tile[i].tile_parts[j].num_reso_AUX,4);*/ /* Aux_i,j : Auxiliary value */ + /* fprintf(stderr,"AUX value %d\n",Aux);*/ + } + /*cio_write(0,4);*/ + } + /* PADDING */ + while (j < num_max_tile_parts){ + cio_write( cio, 0, size_of_coding); /* start position */ + cio_write( cio, 0, size_of_coding); /* length */ + if (version & 0x02) + cio_write( cio, 0,4); /* Aux_i,j : Auxiliary value */ + j++; + } + } + + len = cio_tell( cio)-lenp; + cio_seek( cio, lenp); + cio_write( cio, len, 4); /* L */ + cio_seek( cio, lenp+len); + + return len; + +} + +int get_num_max_tile_parts( opj_codestream_info_t cstr_info) +{ + int num_max_tp = 0, i; + + for( i=0; i functions to be - png_set_. We now have corresponding png_get_ - functions in pngget.c to get information in info_ptr. This isolates - the application from the internal organization of png_info_struct - (good for shared library implementations). - -Version 0.96 [May, 1997] - Fixed serious bug with < 8bpp images introduced in 0.95 - Fixed 256-color transparency bug (Greg Roelofs) - Fixed up documentation (Greg Roelofs, Laszlo Nyul) - Fixed "error" in pngconf.h for Linux setjmp() behavior - Fixed DOS medium model support (Tim Wegner) - Fixed png_check_keyword() for case with error in static string text - Added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul) - Added typecasts to quiet compiler errors - Added more debugging info - -Version 0.97 [January, 1998] - Removed PNG_USE_OWN_CRC capability - Relocated png_set_crc_action from pngrutil.c to pngrtran.c - Fixed typecasts of "new_key", etc. (Andreas Dilger) - Added RFC 1152 [sic] date support - Fixed bug in gamma handling of 4-bit grayscale - Added 2-bit grayscale gamma handling (Glenn R-P) - Added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P) - Minor corrections in libpng.txt - Added simple sRGB support (Glenn R-P) - Easier conditional compiling, e.g., - define PNG_READ/WRITE_NOT_FULLY_SUPPORTED; - all configurable options can be selected from command-line instead - of having to edit pngconf.h (Glenn R-P) - Fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P) - Added more conditions for png_do_background, to avoid changing - black pixels to background when a background is supplied and - no pixels are transparent - Repaired PNG_NO_STDIO behavior - Tested NODIV support and made it default behavior (Greg Roelofs) - Added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler) - Regularized version numbering scheme and bumped shared-library major - version number to 2 to avoid problems with libpng 0.89 apps - (Greg Roelofs) - -Version 0.98 [January, 1998] - Cleaned up some typos in libpng.txt and in code documentation - Fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler) - Cosmetic change "display_gamma" to "screen_gamma" in pngrtran.c - Changed recommendation about file_gamma for PC images to .51 from .45, - in example.c and libpng.txt, added comments to distinguish between - screen_gamma, viewing_gamma, and display_gamma. - Changed all references to RFC1152 to read RFC1123 and changed the - PNG_TIME_RFC1152_SUPPORTED macro to PNG_TIME_RFC1123_SUPPORTED - Added png_invert_alpha capability (Glenn R-P -- suggestion by Jon Vincent) - Changed srgb_intent from png_byte to int to avoid compiler bugs - -Version 0.99 [January 30, 1998] - Free info_ptr->text instead of end_info_ptr->text in pngread.c (John Bowler) - Fixed a longstanding "packswap" bug in pngtrans.c - Fixed some inconsistencies in pngconf.h that prevented compiling with - PNG_READ_GAMMA_SUPPORTED and PNG_READ_hIST_SUPPORTED undefined - Fixed some typos and made other minor rearrangement of libpng.txt (Andreas) - Changed recommendation about file_gamma for PC images to .50 from .51 in - example.c and libpng.txt, and changed file_gamma for sRGB images to .45 - Added a number of functions to access information from the png structure - png_get_image_height(), etc. (Glenn R-P, suggestion by Brad Pettit) - Added TARGET_MACOS similar to zlib-1.0.8 - Define PNG_ALWAYS_EXTERN when __MWERKS__ && WIN32 are defined - Added type casting to all png_malloc() function calls - -Version 0.99a [January 31, 1998] - Added type casts and parentheses to all returns that return a value.(Tim W.) - -Version 0.99b [February 4, 1998] - Added type cast png_uint_32 on malloc function calls where needed. - Changed type of num_hist from png_uint_32 to int (same as num_palette). - Added checks for rowbytes overflow, in case png_size_t is less than 32 bits. - Renamed makefile.elf to makefile.lnx. - -Version 0.99c [February 7, 1998] - More type casting. Removed erroneous overflow test in pngmem.c. - Added png_buffered_memcpy() and png_buffered_memset(), apply them to rowbytes. - Added UNIX manual pages libpng.3 (incorporating libpng.txt) and png.5. - -Version 0.99d [February 11, 1998] - Renamed "far_to_near()" "png_far_to_near()" - Revised libpng.3 - Version 99c "buffered" operations didn't work as intended. Replaced them - with png_memcpy_check() and png_memset_check(). - Added many "if (png_ptr == NULL) return" to quell compiler warnings about - unused png_ptr, mostly in pngget.c and pngset.c. - Check for overlength tRNS chunk present when indexed-color PLTE is read. - Cleaned up spelling errors in libpng.3/libpng.txt - Corrected a problem with png_get_tRNS() which returned undefined trans array - -Version 0.99e [February 28, 1998] - Corrected png_get_tRNS() again. - Add parentheses for easier reading of pngget.c, fixed "||" should be "&&". - Touched up example.c to make more of it compileable, although the entire - file still can't be compiled (Willem van Schaik) - Fixed a bug in png_do_shift() (Bryan Tsai) - Added a space in png.h prototype for png_write_chunk_start() - Replaced pngtest.png with one created with zlib 1.1.1 - Changed pngtest to report PASS even when file size is different (Jean-loup G.) - Corrected some logic errors in png_do_invert_alpha() (Chris Patterson) - -Version 0.99f [March 5, 1998] - Corrected a bug in pngpread() introduced in version 99c (Kevin Bracey) - Moved makefiles into a "scripts" directory, and added INSTALL instruction file - Added makefile.os2 and pngos2.def (A. Zabolotny) and makefile.s2x (W. Sebok) - Added pointers to "note on libpng versions" in makefile.lnx and README - Added row callback feature when reading and writing nonprogressive rows - and added a test of this feature in pngtest.c - Added user transform callbacks, with test of the feature in pngtest.c - -Version 0.99g [March 6, 1998, morning] - Minor changes to pngtest.c to suppress compiler warnings. - Removed "beta" language from documentation. - -Version 0.99h [March 6, 1998, evening] - Minor changes to previous minor changes to pngtest.c - Changed PNG_READ_NOT_FULLY_SUPPORTED to PNG_READ_TRANSFORMS_NOT_SUPPORTED - and added PNG_PROGRESSIVE_READ_NOT_SUPPORTED macro - Added user transform capability - -Version 1.00 [March 7, 1998] - Changed several typedefs in pngrutil.c - Added makefile.wat (Pawel Mrochen), updated makefile.tc3 (Willem van Schaik) - Replaced "while(1)" with "for(;;)" - Added PNGARG() to prototypes in pngtest.c and removed some prototypes - Updated some of the makefiles (Tom Lane) - Changed some typedefs (s_start, etc.) in pngrutil.c - Fixed dimensions of "short_months" array in pngwrite.c - Replaced ansi2knr.c with the one from jpeg-v6 - -Version 1.0.0 [March 8, 1998] - Changed name from 1.00 to 1.0.0 (Adam Costello) - Added smakefile.ppc (with SCOPTIONS.ppc) for Amiga PPC (Andreas Kleinert) - -Version 1.0.0a [March 9, 1998] - Fixed three bugs in pngrtran.c to make gamma+background handling consistent - (Greg Roelofs) - Changed format of the PNG_LIBPNG_VER integer to xyyzz instead of xyz - for major, minor, and bugfix releases. This is 10001. (Adam Costello, - Tom Lane) - Make months range from 1-12 in png_convert_to_rfc1123 - -Version 1.0.0b [March 13, 1998] - Quieted compiler complaints about two empty "for" loops in pngrutil.c - Minor changes to makefile.s2x - Removed #ifdef/#endif around a png_free() in pngread.c - -Version 1.0.1 [March 14, 1998] - Changed makefile.s2x to reduce security risk of using a relative pathname - Fixed some typos in the documentation (Greg). - Fixed a problem with value of "channels" returned by png_read_update_info() - -Version 1.0.1a [April 21, 1998] - Optimized Paeth calculations by replacing abs() function calls with intrinsics - plus other loop optimizations. Improves avg decoding speed by about 20%. - Commented out i386istic "align" compiler flags in makefile.lnx. - Reduced the default warning level in some makefiles, to make them consistent. - Removed references to IJG and JPEG in the ansi2knr.c copyright statement. - Fixed a bug in png_do_strip_filler with XXRRGGBB => RRGGBB transformation. - Added grayscale and 16-bit capability to png_do_read_filler(). - Fixed a bug in pngset.c, introduced in version 0.99c, that sets rowbytes - too large when writing an image with bit_depth < 8 (Bob Dellaca). - Corrected some bugs in the experimental weighted filtering heuristics. - Moved a misplaced pngrutil code block that truncates tRNS if it has more - than num_palette entries -- test was done before num_palette was defined. - Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins). - Changed compiler flags in makefile.wat for better optimization - (Pawel Mrochen). - -Version 1.0.1b [May 2, 1998] - Relocated png_do_gray_to_rgb() within png_do_read_transformations() (Greg). - Relocated the png_composite macros from pngrtran.c to png.h (Greg). - Added makefile.sco (contributed by Mike Hopkirk). - Fixed two bugs (missing definitions of "istop") introduced in libpng-1.0.1a. - Fixed a bug in pngrtran.c that would set channels=5 under some circumstances. - More work on the Paeth-filtering, achieving imperceptible speedup - (A Kleinert). - More work on loop optimization which may help when compiled with C++ - compilers. - Added warnings when people try to use transforms they've defined out. - Collapsed 4 "i" and "c" loops into single "i" loops in pngrtran and pngwtran. - Revised paragraph about png_set_expand() in libpng.txt and libpng.3 (Greg) - -Version 1.0.1c [May 11, 1998] - Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for - filler bytes should have been 0xff instead of 0xf. - Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images. - Moved PNG_WRITE_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED - out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h - Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED, - for consistency, in pngconf.h - Added individual "ifndef PNG_NO_[CAPABILITY]" in pngconf.h to make it easier - to remove unwanted capabilities via the compile line - Made some corrections to grammar (which, it's) in documentation (Greg). - Corrected example.c, use of row_pointers in png_write_image(). - -Version 1.0.1d [May 24, 1998] - Corrected several statements that used side effects illegally in pngrutil.c - and pngtrans.c, that were introduced in version 1.0.1b - Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert) - More corrections to example.c, use of row_pointers in png_write_image() - and png_read_rows(). - Added pngdll.mak and pngdef.pas to scripts directory, contributed by - Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5 - Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.) - Changed several loops from count-down to count-up, for consistency. - -Version 1.0.1e [June 6, 1998] - Revised libpng.txt and libpng.3 description of png_set_read|write_fn(), and - added warnings when people try to set png_read_fn and png_write_fn in - the same structure. - Added a test such that png_do_gamma will be done when num_trans==0 - for truecolor images that have defined a background. This corrects an - error that was introduced in libpng-0.90 that can cause gamma processing - to be skipped. - Added tests in png.h to include "trans" and "trans_values" in structures - when PNG_READ_BACKGROUND_SUPPORTED or PNG_READ_EXPAND_SUPPORTED is defined. - Add png_free(png_ptr->time_buffer) in png_destroy_read_struct() - Moved png_convert_to_rfc_1123() from pngwrite.c to png.c - Added capability for user-provided malloc_fn() and free_fn() functions, - and revised pngtest.c to demonstrate their use, replacing the - PNGTEST_DEBUG_MEM feature. - Added makefile.w32, for Microsoft C++ 4.0 and later (Tim Wegner). - -Version 1.0.2 [June 14, 1998] - Fixed two bugs in makefile.bor . - -Version 1.0.2a [December 30, 1998] - Replaced and extended code that was removed from png_set_filler() in 1.0.1a. - Fixed a bug in png_do_filler() that made it fail to write filler bytes in - the left-most pixel of each row (Kevin Bracey). - Changed "static pngcharp tIME_string" to "static char tIME_string[30]" - in pngtest.c (Duncan Simpson). - Fixed a bug in pngtest.c that caused pngtest to try to write a tIME chunk - even when no tIME chunk was present in the source file. - Fixed a problem in pngrutil.c: gray_to_rgb didn't always work with 16-bit. - Fixed a problem in png_read_push_finish_row(), which would not skip some - passes that it should skip, for images that are less than 3 pixels high. - Interchanged the order of calls to png_do_swap() and png_do_shift() - in pngwtran.c (John Cromer). - Added #ifdef PNG_DEBUG/#endif surrounding use of PNG_DEBUG in png.h . - Changed "bad adaptive filter type" from error to warning in pngrutil.c . - Fixed a documentation error about default filtering with 8-bit indexed-color. - Separated the PNG_NO_STDIO macro into PNG_NO_STDIO and PNG_NO_CONSOLE_IO - (L. Peter Deutsch). - Added png_set_rgb_to_gray() and png_get_rgb_to_gray_status() functions. - Added png_get_copyright() and png_get_header_version() functions. - Revised comments on png_set_progressive_read_fn() in libpng.txt and example.c - Added information about debugging in libpng.txt and libpng.3 . - Changed "ln -sf" to "ln -s -f" in makefile.s2x, makefile.lnx, and - makefile.sco. - Removed lines after Dynamic Dependencies" in makefile.aco . - Revised makefile.dec to make a shared library (Jeremie Petit). - Removed trailing blanks from all files. - -Version 1.0.2a [January 6, 1999] - Removed misplaced #endif and #ifdef PNG_NO_EXTERN near the end of png.h - Added "if" tests to silence complaints about unused png_ptr in png.h and png.c - Changed "check_if_png" function in example.c to return true (nonzero) if PNG. - Changed libpng.txt to demonstrate png_sig_cmp() instead of png_check_sig() - which is obsolete. - -Version 1.0.3 [January 14, 1999] - Added makefile.hux, for Hewlett Packard HPUX 10.20 and 11.00 (Jim Rice) - Added a statement of Y2K compliance in png.h, libpng.3, and Y2KINFO. - -Version 1.0.3a [August 12, 1999] - Added check for PNG_READ_INTERLACE_SUPPORTED in pngread.c; issue a warning - if an attempt is made to read an interlaced image when it's not supported. - Added check if png_ptr->trans is defined before freeing it in pngread.c - Modified the Y2K statement to include versions back to version 0.71 - Fixed a bug in the check for valid IHDR bit_depth/color_types in pngrutil.c - Modified makefile.wat (added -zp8 flag, ".symbolic", changed some comments) - Replaced leading blanks with tab characters in makefile.hux - Changed "dworkin.wustl.edu" to "ccrc.wustl.edu" in various documents. - Changed (float)red and (float)green to (double)red, (double)green - in png_set_rgb_to_gray() to avoid "promotion" problems in AIX. - Fixed a bug in pngconf.h that omitted when PNG_DEBUG==0 (K Bracey). - Reformatted libpng.3 and libpngpf.3 with proper fonts (script by J. vanZandt). - Updated documentation to refer to the PNG-1.2 specification. - Removed ansi2knr.c and left pointers to the latest source for ansi2knr.c - in makefile.knr, INSTALL, and README (L. Peter Deutsch) - Fixed bugs in calculation of the length of rowbytes when adding alpha - channels to 16-bit images, in pngrtran.c (Chris Nokleberg) - Added function png_set_user_transform_info() to store user_transform_ptr, - user_depth, and user_channels into the png_struct, and a function - png_get_user_transform_ptr() to retrieve the pointer (Chris Nokleberg) - Added function png_set_empty_plte_permitted() to make libpng useable - in MNG applications. - Corrected the typedef for png_free_ptr in png.h (Jesse Jones). - Correct gamma with srgb is 45455 instead of 45000 in pngrutil.c, to be - consistent with PNG-1.2, and allow variance of 500 before complaining. - Added assembler code contributed by Intel in file pngvcrd.c and modified - makefile.w32 to use it (Nirav Chhatrapati, INTEL Corporation, - Gilles Vollant) - Changed "ln -s -f" to "ln -f -s" in the makefiles to make Solaris happy. - Added some aliases for png_set_expand() in pngrtran.c, namely - png_set_expand_PLTE(), png_set_expand_depth(), and png_set_expand_tRNS() - (Greg Roelofs, in "PNG: The Definitive Guide"). - Added makefile.beo for BEOS on X86, contributed by Sander Stok. - -Version 1.0.3b [August 26, 1999] - Replaced 2147483647L several places with PNG_MAX_UINT macro, defined in png.h - Changed leading blanks to tabs in all makefiles. - Define PNG_USE_PNGVCRD in makefile.w32, to get MMX assembler code. - Made alternate versions of png_set_expand() in pngrtran.c, namely - png_set_gray_1_2_4_to_8, png_set_palette_to_rgb, and png_set_tRNS_to_alpha - (Greg Roelofs, in "PNG: The Definitive Guide"). Deleted the 1.0.3a aliases. - Relocated start of 'extern "C"' block in png.h so it doesn't include pngconf.h - Revised calculation of num_blocks in pngmem.c to avoid a potentially - negative shift distance, whose results are undefined in the C language. - Added a check in pngset.c to prevent writing multiple tIME chunks. - Added a check in pngwrite.c to detect invalid small window_bits sizes. - -Version 1.0.3d [September 4, 1999] - Fixed type casting of igamma in pngrutil.c - Added new png_expand functions to scripts/pngdef.pas and pngos2.def - Added a demo read_user_transform_fn that examines the row filters in pngtest.c - -Version 1.0.4 [September 24, 1999] - Define PNG_ALWAYS_EXTERN in pngconf.h if __STDC__ is defined - Delete #define PNG_INTERNAL and include "png.h" from pngasmrd.h - Made several minor corrections to pngtest.c - Renamed the makefiles with longer but more user friendly extensions. - Copied the PNG copyright and license to a separate LICENSE file. - Revised documentation, png.h, and example.c to remove reference to - "viewing_gamma" which no longer appears in the PNG specification. - Revised pngvcrd.c to use MMX code for interlacing only on the final pass. - Updated pngvcrd.c to use the faster C filter algorithms from libpng-1.0.1a - Split makefile.win32vc into two versions, makefile.vcawin32 (uses MMX - assembler code) and makefile.vcwin32 (doesn't). - Added a CPU timing report to pngtest.c (enabled by defining PNGTEST_TIMING) - Added a copy of pngnow.png to the distribution. - -Version 1.0.4a [September 25, 1999] - Increase max_pixel_depth in pngrutil.c if a user transform needs it. - Changed several division operations to right-shifts in pngvcrd.c - -Version 1.0.4b [September 30, 1999] - Added parentheses in line 3732 of pngvcrd.c - Added a comment in makefile.linux warning about buggy -O3 in pgcc 2.95.1 - -Version 1.0.4c [October 1, 1999] - Added a "png_check_version" function in png.c and pngtest.c that will generate - a helpful compiler error if an old png.h is found in the search path. - Changed type of png_user_transform_depth|channels from int to png_byte. - -Version 1.0.4d [October 6, 1999] - Changed 0.45 to 0.45455 in png_set_sRGB() - Removed unused PLTE entries from pngnow.png - Re-enabled some parts of pngvcrd.c (png_combine_row) that work properly. - -Version 1.0.4e [October 10, 1999] - Fixed sign error in pngvcrd.c (Greg Roelofs) - Replaced some instances of memcpy with simple assignments in pngvcrd (GR-P) - -Version 1.0.4f [October 15, 1999] - Surrounded example.c code with #if 0 .. #endif to prevent people from - inadvertently trying to compile it. - Changed png_get_header_version() from a function to a macro in png.h - Added type casting mostly in pngrtran.c and pngwtran.c - Removed some pointless "ptr = NULL" in pngmem.c - Added a "contrib" directory containing the source code from Greg's book. - -Version 1.0.5 [October 15, 1999] - Minor editing of the INSTALL and README files. - -Version 1.0.5a [October 23, 1999] - Added contrib/pngsuite and contrib/pngminus (Willem van Schaik) - Fixed a typo in the png_set_sRGB() function call in example.c (Jan Nijtmans) - Further optimization and bugfix of pngvcrd.c - Revised pngset.c so that it does not allocate or free memory in the user's - text_ptr structure. Instead, it makes its own copy. - Created separate write_end_info_struct in pngtest.c for a more severe test. - Added code in pngwrite.c to free info_ptr->text[i].key to stop a memory leak. - -Version 1.0.5b [November 23, 1999] - Moved PNG_FLAG_HAVE_CHUNK_HEADER, PNG_FLAG_BACKGROUND_IS_GRAY and - PNG_FLAG_WROTE_tIME from flags to mode. - Added png_write_info_before_PLTE() function. - Fixed some typecasting in contrib/gregbook/*.c - Updated scripts/makevms.com and added makevms.com to contrib/gregbook - and contrib/pngminus (Martin Zinser) - -Version 1.0.5c [November 26, 1999] - Moved png_get_header_version from png.h to png.c, to accommodate ansi2knr. - Removed all global arrays (according to PNG_NO_GLOBAL_ARRAYS macro), to - accommodate making DLL's: Moved usr_png_ver from global variable to function - png_get_header_ver() in png.c. Moved png_sig to png_sig_bytes in png.c and - eliminated use of png_sig in pngwutil.c. Moved the various png_CHNK arrays - into pngtypes.h. Eliminated use of global png_pass arrays. Declared the - png_CHNK and png_pass arrays to be "const". Made the global arrays - available to applications (although none are used in libpng itself) when - PNG_NO_GLOBAL_ARRAYS is not defined or when PNG_GLOBAL_ARRAYS is defined. - Removed some extraneous "-I" from contrib/pngminus/makefile.std - Changed the PNG_sRGB_INTENT macros in png.h to be consistent with PNG-1.2. - Change PNG_SRGB_INTENT to PNG_sRGB_INTENT in libpng.txt and libpng.3 - -Version 1.0.5d [November 29, 1999] - Add type cast (png_const_charp) two places in png.c - Eliminated pngtypes.h; use macros instead to declare PNG_CHNK arrays. - Renamed "PNG_GLOBAL_ARRAYS" to "PNG_USE_GLOBAL_ARRAYS" and made available - to applications a macro "PNG_USE_LOCAL_ARRAYS". - comment out (with #ifdef) all the new declarations when - PNG_USE_GLOBAL_ARRAYS is defined. - Added PNG_EXPORT_VAR macro to accommodate making DLL's. - -Version 1.0.5e [November 30, 1999] - Added iCCP, iTXt, and sPLT support; added "lang" member to the png_text - structure; refactored the inflate/deflate support to make adding new chunks - with trailing compressed parts easier in the future, and added new functions - png_free_iCCP, png_free_pCAL, png_free_sPLT, png_free_text, png_get_iCCP, - png_get_spalettes, png_set_iCCP, png_set_spalettes (Eric S. Raymond). - NOTE: Applications that write text chunks MUST define png_text->lang - before calling png_set_text(). It must be set to NULL if you want to - write tEXt or zTXt chunks. If you want your application to be able to - run with older versions of libpng, use - - #ifdef PNG_iTXt_SUPPORTED - png_text[i].lang = NULL; - #endif - - Changed png_get_oFFs() and png_set_oFFs() to use signed rather than unsigned - offsets (Eric S. Raymond). - Combined PNG_READ_cHNK_SUPPORTED and PNG_WRITE_cHNK_SUPPORTED macros into - PNG_cHNK_SUPPORTED and combined the three types of PNG_text_SUPPORTED - macros, leaving the separate macros also available. - Removed comments on #endifs at the end of many short, non-nested #if-blocks. - -Version 1.0.5f [December 6, 1999] - Changed makefile.solaris to issue a warning about potential problems when - the ucb "ld" is in the path ahead of the ccs "ld". - Removed "- [date]" from the "synopsis" line in libpng.3 and libpngpf.3. - Added sCAL chunk support (Eric S. Raymond). - -Version 1.0.5g [December 7, 1999] - Fixed "png_free_spallettes" typo in png.h - Added code to handle new chunks in pngpread.c - Moved PNG_CHNK string macro definitions outside of PNG_NO_EXTERN block - Added "translated_key" to png_text structure and png_write_iTXt(). - Added code in pngwrite.c to work around a newly discovered zlib bug. - -Version 1.0.5h [December 10, 1999] - NOTE: regarding the note for version 1.0.5e, the following must also - be included in your code: - png_text[i].translated_key = NULL; - Unknown chunk handling is now supported. - Option to eliminate all floating point support was added. Some new - fixed-point functions such as png_set_gAMA_fixed() were added. - Expanded tabs and removed trailing blanks in source files. - -Version 1.0.5i [December 13, 1999] - Added some type casts to silence compiler warnings. - Renamed "png_free_spalette" to "png_free_spalettes" for consistency. - Removed leading blanks from a #define in pngvcrd.c - Added some parameters to the new png_set_keep_unknown_chunks() function. - Added a test for up->location != 0 in the first instance of writing - unknown chunks in pngwrite.c - Changed "num" to "i" in png_free_spalettes() and png_free_unknowns() to - prevent recursion. - Added png_free_hIST() function. - Various patches to fix bugs in the sCAL and integer cHRM processing, - and to add some convenience macros for use with sCAL. - -Version 1.0.5j [December 21, 1999] - Changed "unit" parameter of png_write_sCAL from png_byte to int, to work - around buggy compilers. - Added new type "png_fixed_point" for integers that hold float*100000 values - Restored backward compatibility of tEXt/zTXt chunk processing: - Restored the first four members of png_text to the same order as v.1.0.5d. - Added members "lang_key" and "itxt_length" to png_text struct. Set - text_length=0 when "text" contains iTXt data. Use the "compression" - member to distinguish among tEXt/zTXt/iTXt types. Added - PNG_ITXT_COMPRESSION_NONE (1) and PNG_ITXT_COMPRESSION_zTXt(2) macros. - The "Note" above, about backward incompatibility of libpng-1.0.5e, no - longer applies. - Fixed png_read|write_iTXt() to read|write parameters in the right order, - and to write the iTXt chunk after IDAT if it appears in the end_ptr. - Added pnggccrd.c, version of pngvcrd.c Intel assembler for gcc (Greg Roelofs) - Reversed the order of trying to write floating-point and fixed-point gAMA. - -Version 1.0.5k [December 27, 1999] - Added many parentheses, e.g., "if (a && b & c)" becomes "if (a && (b & c))" - Added png_handle_as_unknown() function (Glenn) - Added png_free_chunk_list() function and chunk_list and num_chunk_list members - of png_ptr. - Eliminated erroneous warnings about multiple sPLT chunks and sPLT-after-PLTE. - Fixed a libpng-1.0.5h bug in pngrutil.c that was issuing erroneous warnings - about ignoring incorrect gAMA with sRGB (gAMA was in fact not ignored) - Added png_free_tRNS(); png_set_tRNS() now malloc's its own trans array (ESR). - Define png_get_int_32 when oFFs chunk is supported as well as when pCAL is. - Changed type of proflen from png_int_32 to png_uint_32 in png_get_iCCP(). - -Version 1.0.5l [January 1, 2000] - Added functions png_set_read_user_chunk_fn() and png_get_user_chunk_ptr() - for setting a callback function to handle unknown chunks and for - retrieving the associated user pointer (Glenn). - -Version 1.0.5m [January 7, 2000] - Added high-level functions png_read_png(), png_write_png(), png_free_pixels(). - -Version 1.0.5n [January 9, 2000] - Added png_free_PLTE() function, and modified png_set_PLTE() to malloc its - own memory for info_ptr->palette. This makes it safe for the calling - application to free its copy of the palette any time after it calls - png_set_PLTE(). - -Version 1.0.5o [January 20, 2000] - Cosmetic changes only (removed some trailing blanks and TABs) - -Version 1.0.5p [January 31, 2000] - Renamed pngdll.mak to makefile.bd32 - Cosmetic changes in pngtest.c - -Version 1.0.5q [February 5, 2000] - Relocated the makefile.solaris warning about PATH problems. - Fixed pngvcrd.c bug by pushing/popping registers in mmxsupport (Bruce Oberg) - Revised makefile.gcmmx - Added PNG_SETJMP_SUPPORTED, PNG_SETJMP_NOT_SUPPORTED, and PNG_ABORT() macros - -Version 1.0.5r [February 7, 2000] - Removed superfluous prototype for png_get_itxt from png.h - Fixed a bug in pngrtran.c that improperly expanded the background color. - Return *num_text=0 from png_get_text() when appropriate, and fix documentation - of png_get_text() in libpng.txt/libpng.3. - -Version 1.0.5s [February 18, 2000] - Added "png_jmp_env()" macro to pngconf.h, to help people migrate to the - new error handler that's planned for the next libpng release, and changed - example.c, pngtest.c, and contrib programs to use this macro. - Revised some of the DLL-export macros in pngconf.h (Greg Roelofs) - Fixed a bug in png_read_png() that caused it to fail to expand some images - that it should have expanded. - Fixed some mistakes in the unused and undocumented INCH_CONVERSIONS functions - in pngget.c - Changed the allocation of palette, history, and trans arrays back to - the version 1.0.5 method (linking instead of copying) which restores - backward compatibility with version 1.0.5. Added some remarks about - that in example.c. Added "free_me" member to info_ptr and png_ptr - and added png_free_data() function. - Updated makefile.linux and makefile.gccmmx to make directories conditionally. - Made cosmetic changes to pngasmrd.h - Added png_set_rows() and png_get_rows(), for use with png_read|write_png(). - Modified png_read_png() to allocate info_ptr->row_pointers only if it - hasn't already been allocated. - -Version 1.0.5t [March 4, 2000] - Changed png_jmp_env() migration aiding macro to png_jmpbuf(). - Fixed "interlace" typo (should be "interlaced") in contrib/gregbook/read2-x.c - Fixed bug with use of PNG_BEFORE_IHDR bit in png_ptr->mode, introduced when - PNG_FLAG_HAVE_CHUNK_HEADER was moved into png_ptr->mode in version 1.0.5b - Files in contrib/gregbook were revised to use png_jmpbuf() and to select - a 24-bit visual if one is available, and to allow abbreviated options. - Files in contrib/pngminus were revised to use the png_jmpbuf() macro. - Removed spaces in makefile.linux and makefile.gcmmx, introduced in 1.0.5s - -Version 1.0.5u [March 5, 2000] - Simplified the code that detects old png.h in png.c and pngtest.c - Renamed png_spalette (_p, _pp) to png_sPLT_t (_tp, _tpp) - Increased precision of rgb_to_gray calculations from 8 to 15 bits and - added png_set_rgb_to_gray_fixed() function. - Added makefile.bc32 (32-bit Borland C++, C mode) - -Version 1.0.5v [March 11, 2000] - Added some parentheses to the png_jmpbuf macro definition. - Updated references to the zlib home page, which has moved to freesoftware.com. - Corrected bugs in documentation regarding png_read_row() and png_write_row(). - Updated documentation of png_rgb_to_gray calculations in libpng.3/libpng.txt. - Renamed makefile.borland,turboc3 back to makefile.bor,tc3 as in version 1.0.3, - revised borland makefiles; added makefile.ibmvac3 and makefile.gcc (Cosmin) - -Version 1.0.6 [March 20, 2000] - Minor revisions of makefile.bor, libpng.txt, and gregbook/rpng2-win.c - Added makefile.sggcc (SGI IRIX with gcc) - -Version 1.0.6d [April 7, 2000] - Changed sprintf() to strcpy() in png_write_sCAL_s() to work without STDIO - Added data_length parameter to png_decompress_chunk() function - Revised documentation to remove reference to abandoned png_free_chnk functions - Fixed an error in png_rgb_to_gray_fixed() - Revised example.c, usage of png_destroy_write_struct(). - Renamed makefile.ibmvac3 to makefile.ibmc, added libpng.icc IBM project file - Added a check for info_ptr->free_me&PNG_FREE_TEXT when freeing text in png.c - Simplify png_sig_bytes() function to remove use of non-ISO-C strdup(). - -Version 1.0.6e [April 9, 2000] - Added png_data_freer() function. - In the code that checks for over-length tRNS chunks, added check of - info_ptr->num_trans as well as png_ptr->num_trans (Matthias Benckmann) - Minor revisions of libpng.txt/libpng.3. - Check for existing data and free it if the free_me flag is set, in png_set_*() - and png_handle_*(). - Only define PNG_WEIGHTED_FILTERS_SUPPORTED when PNG_FLOATING_POINT_SUPPORTED - is defined. - Changed several instances of PNG_NO_CONSOLE_ID to PNG_NO_STDIO in pngrutil.c - and mentioned the purposes of the two macros in libpng.txt/libpng.3. - -Version 1.0.6f [April 14, 2000] - Revised png_set_iCCP() and png_set_rows() to avoid prematurely freeing data. - Add checks in png_set_text() for NULL members of the input text structure. - Revised libpng.txt/libpng.3. - Removed superfluous prototype for png_set_iTXt from png.h - Removed "else" from pngread.c, after png_error(), and changed "0" to "length". - Changed several png_errors about malformed ancillary chunks to png_warnings. - -Version 1.0.6g [April 24, 2000] - Added png_pass-* arrays to pnggccrd.c when PNG_USE_LOCAL_ARRAYS is defined. - Relocated paragraph about png_set_background() in libpng.3/libpng.txt - and other revisions (Matthias Benckmann) - Relocated info_ptr->free_me, png_ptr->free_me, and other info_ptr and - png_ptr members to restore binary compatibility with libpng-1.0.5 - (breaks compatibility with libpng-1.0.6). - -Version 1.0.6h [April 24, 2000] - Changed shared library so-number pattern from 2.x.y.z to xy.z (this builds - libpng.so.10 & libpng.so.10.6h instead of libpng.so.2 & libpng.so.2.1.0.6h) - This is a temporary change for test purposes. - -Version 1.0.6i [May 2, 2000] - Rearranged some members at the end of png_info and png_struct, to put - unknown_chunks_num and free_me within the original size of the png_structs - and free_me, png_read_user_fn, and png_free_fn within the original png_info, - because some old applications allocate the structs directly instead of - using png_create_*(). - Added documentation of user memory functions in libpng.txt/libpng.3 - Modified png_read_png so that it will use user_allocated row_pointers - if present, unless free_me directs that it be freed, and added description - of the use of png_set_rows() and png_get_rows() in libpng.txt/libpng.3. - Added PNG_LEGACY_SUPPORTED macro, and #ifdef out all new (since version - 1.00) members of png_struct and png_info, to regain binary compatibility - when you define this macro. Capabilities lost in this event - are user transforms (new in version 1.0.0),the user transform pointer - (new in version 1.0.2), rgb_to_gray (new in 1.0.5), iCCP, sCAL, sPLT, - the high-level interface, and unknown chunks support (all new in 1.0.6). - This was necessary because of old applications that allocate the structs - directly as authors were instructed to do in libpng-0.88 and earlier, - instead of using png_create_*(). - Added modes PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT which - can be used to detect codes that directly allocate the structs, and - code to check these modes in png_read_init() and png_write_init() and - generate a libpng error if the modes aren't set and PNG_LEGACY_SUPPORTED - was not defined. - Added makefile.intel and updated makefile.watcom (Pawel Mrochen) - -Version 1.0.6j [May 3, 2000] - Overloaded png_read_init() and png_write_init() with macros that convert - calls to png_read_init_2() or png_write_init_2() that check the version - and structure sizes. - -Version 1.0.7beta11 [May 7, 2000] - Removed the new PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT modes - which are no longer used. - Eliminated the three new members of png_text when PNG_LEGACY_SUPPORTED is - defined or when neither PNG_READ_iTXt_SUPPORTED nor PNG_WRITE_iTXT_SUPPORTED - is defined. - Made PNG_NO_READ|WRITE_iTXt the default setting, to avoid memory - overrun when old applications fill the info_ptr->text structure directly. - Added PNGAPI macro, and added it to the definitions of all exported functions. - Relocated version macro definitions ahead of the includes of zlib.h and - pngconf.h in png.h. - -Version 1.0.7beta12 [May 12, 2000] - Revised pngset.c to avoid a problem with expanding the png_debug macro. - Deleted some extraneous defines from pngconf.h - Made PNG_NO_CONSOLE_IO the default condition when PNG_BUILD_DLL is defined. - Use MSC _RPTn debugging instead of fprintf if _MSC_VER is defined. - Added png_access_version_number() function. - Check for mask&PNG_FREE_CHNK (for TEXT, SCAL, PCAL) in png_free_data(). - Expanded libpng.3/libpng.txt information about png_data_freer(). - -Version 1.0.7beta14 [May 17, 2000] (beta13 was not published) - Changed pnggccrd.c and pngvcrd.c to handle bad adaptive filter types as - warnings instead of errors, as pngrutil.c does. - Set the PNG_INFO_IDAT valid flag in png_set_rows() so png_write_png() - will actually write IDATs. - Made the default PNG_USE_LOCAL_ARRAYS depend on PNG_DLL instead of WIN32. - Make png_free_data() ignore its final parameter except when freeing data - that can have multiple instances (text, sPLT, unknowns). - Fixed a new bug in png_set_rows(). - Removed info_ptr->valid tests from png_free_data(), as in version 1.0.5. - Added png_set_invalid() function. - Fixed incorrect illustrations of png_destroy_write_struct() in example.c. - -Version 1.0.7beta15 [May 30, 2000] - Revised the deliberately erroneous Linux setjmp code in pngconf.h to produce - fewer error messages. - Rearranged checks for Z_OK to check the most likely path first in pngpread.c - and pngwutil.c. - Added checks in pngtest.c for png_create_*() returning NULL, and mentioned - in libpng.txt/libpng.3 the need for applications to check this. - Changed names of png_default_*() functions in pngtest to pngtest_*(). - Changed return type of png_get_x|y_offset_*() from png_uint_32 to png_int_32. - Fixed some bugs in the unused PNG_INCH_CONVERSIONS functions in pngget.c - Set each pointer to NULL after freeing it in png_free_data(). - Worked around a problem in pngconf.h; AIX's strings.h defines an "index" - macro that conflicts with libpng's png_color_16.index. (Dimitri - Papadapoulos) - Added "msvc" directory with MSVC++ project files (Simon-Pierre Cadieux). - -Version 1.0.7beta16 [June 4, 2000] - Revised the workaround of AIX string.h "index" bug. - Added a check for overlength PLTE chunk in pngrutil.c. - Added PNG_NO_POINTER_INDEXING macro to use array-indexing instead of pointer - indexing in pngrutil.c and pngwutil.c to accommodate a buggy compiler. - Added a warning in png_decompress_chunk() when it runs out of data, e.g. - when it tries to read an erroneous PhotoShop iCCP chunk. - Added PNG_USE_DLL macro. - Revised the copyright/disclaimer/license notice. - Added contrib/msvctest directory - -Version 1.0.7rc1 [June 9, 2000] - Corrected the definition of PNG_TRANSFORM_INVERT_ALPHA (0x0400 not 0x0200) - Added contrib/visupng directory (Willem van Schaik) - -Version 1.0.7beta18 [June 23, 2000] - Revised PNGAPI definition, and pngvcrd.c to work with __GCC__ - and do not redefine PNGAPI if it is passed in via a compiler directive. - Revised visupng/PngFile.c to remove returns from within the Try block. - Removed leading underscores from "_PNG_H" and "_PNG_SAVE_BSD_SOURCE" macros. - Updated contrib/visupng/cexcept.h to version 1.0.0. - Fixed bugs in pngwrite.c and pngwutil.c that prevented writing iCCP chunks. - -Version 1.0.7rc2 [June 28, 2000] - Updated license to include disclaimers required by UCITA. - Fixed "DJBPP" typo in pnggccrd.c introduced in beta18. - -Version 1.0.7 [July 1, 2000] - Revised the definition of "trans_values" in libpng.3/libpng.txt - -Version 1.0.8beta1 [July 8, 2000] - Added png_free(png_ptr, key) two places in pngpread.c to stop memory leaks. - Changed PNG_NO_STDIO to PNG_NO_CONSOLE_IO, several places in pngrutil.c and - pngwutil.c. - Changed PNG_EXPORT_VAR to use PNG_IMPEXP, in pngconf.h. - Removed unused "#include " from png.c - Added WindowsCE support. - Revised pnggccrd.c to work with gcc-2.95.2 and in the Cygwin environment. - -Version 1.0.8beta2 [July 10, 2000] - Added project files to the wince directory and made further revisions - of pngtest.c, pngrio.c, and pngwio.c in support of WindowsCE. - -Version 1.0.8beta3 [July 11, 2000] - Only set the PNG_FLAG_FREE_TRNS or PNG_FREE_TRNS flag in png_handle_tRNS() - for indexed-color input files to avoid potential double-freeing trans array - under some unusual conditions; problem was introduced in version 1.0.6f. - Further revisions to pngtest.c and files in the wince subdirectory. - -Version 1.0.8beta4 [July 14, 2000] - Added the files pngbar.png and pngbar.jpg to the distribution. - Added makefile.cygwin, and cygwin support in pngconf.h - Added PNG_NO_ZALLOC_ZERO macro (makes png_zalloc skip zeroing memory) - -Version 1.0.8rc1 [July 16, 2000] - Revised png_debug() macros and statements to eliminate compiler warnings. - -Version 1.0.8 [July 24, 2000] - Added png_flush() in pngwrite.c, after png_write_IEND(). - Updated makefile.hpux to build a shared library. - -Version 1.0.9beta1 [November 10, 2000] - Fixed typo in scripts/makefile.hpux - Updated makevms.com in scripts and contrib/* and contrib/* (Martin Zinser) - Fixed seqence-point bug in contrib/pngminus/png2pnm (Martin Zinser) - Changed "cdrom.com" in documentation to "libpng.org" - Revised pnggccrd.c to get it all working, and updated makefile.gcmmx (Greg). - Changed type of "params" from voidp to png_voidp in png_read|write_png(). - Make sure PNGAPI and PNG_IMPEXP are defined in pngconf.h. - Revised the 3 instances of WRITEFILE in pngtest.c. - Relocated "msvc" and "wince" project subdirectories into "dll" subdirectory. - Updated png.rc in dll/msvc project - Revised makefile.dec to define and use LIBPATH and INCPATH - Increased size of global png_libpng_ver[] array from 12 to 18 chars. - Made global png_libpng_ver[], png_sig[] and png_pass_*[] arrays const. - Removed duplicate png_crc_finish() from png_handle_bKGD() function. - Added a warning when application calls png_read_update_info() multiple times. - Revised makefile.cygwin - Fixed bugs in iCCP support in pngrutil.c and pngwutil.c. - Replaced png_set_empty_plte_permitted() with png_permit_mng_features(). - -Version 1.0.9beta2 [November 19, 2000] - Renamed the "dll" subdirectory "projects". - Added borland project files to "projects" subdirectory. - Set VS_FF_PRERELEASE and VS_FF_PATCHED flags in msvc/png.rc when appropriate. - Add error message in png_set_compression_buffer_size() when malloc fails. - -Version 1.0.9beta3 [November 23, 2000] - Revised PNG_LIBPNG_BUILD_TYPE macro in png.h, used in the msvc project. - Removed the png_flush() in pngwrite.c that crashes some applications - that don't set png_output_flush_fn. - Added makefile.macosx and makefile.aix to scripts directory. - -Version 1.0.9beta4 [December 1, 2000] - Change png_chunk_warning to png_warning in png_check_keyword(). - Increased the first part of msg buffer from 16 to 18 in png_chunk_error(). - -Version 1.0.9beta5 [December 15, 2000] - Added support for filter method 64 (for PNG datastreams embedded in MNG). - -Version 1.0.9beta6 [December 18, 2000] - Revised png_set_filter() to accept filter method 64 when appropriate. - Added new PNG_HAVE_PNG_SIGNATURE bit to png_ptr->mode and use it to - help prevent applications from using MNG features in PNG datastreams. - Added png_permit_mng_features() function. - Revised libpng.3/libpng.txt. Changed "filter type" to "filter method". - -Version 1.0.9rc1 [December 23, 2000] - Revised test for PNG_HAVE_PNG_SIGNATURE in pngrutil.c - Fixed error handling of unknown compression type in png_decompress_chunk(). - In pngconf.h, define __cdecl when _MSC_VER is defined. - -Version 1.0.9beta7 [December 28, 2000] - Changed PNG_TEXT_COMPRESSION_zTXt to PNG_COMPRESSION_TYPE_BASE several places. - Revised memory management in png_set_hIST and png_handle_hIST in a backward - compatible manner. PLTE and tRNS were revised similarly. - Revised the iCCP chunk reader to ignore trailing garbage. - -Version 1.0.9beta8 [January 12, 2001] - Moved pngasmrd.h into pngconf.h. - Improved handling of out-of-spec garbage iCCP chunks generated by PhotoShop. - -Version 1.0.9beta9 [January 15, 2001] - Added png_set_invalid, png_permit_mng_features, and png_mmx_supported to - wince and msvc project module definition files. - Minor revision of makefile.cygwin. - Fixed bug with progressive reading of narrow interlaced images in pngpread.c - -Version 1.0.9beta10 [January 16, 2001] - Do not typedef png_FILE_p in pngconf.h when PNG_NO_STDIO is defined. - Fixed "png_mmx_supported" typo in project definition files. - -Version 1.0.9beta11 [January 19, 2001] - Updated makefile.sgi to make shared library. - Removed png_mmx_support() function and disabled PNG_MNG_FEATURES_SUPPORTED - by default, for the benefit of DLL forward compatibility. These will - be re-enabled in version 1.2.0. - -Version 1.0.9rc2 [January 22, 2001] - Revised cygwin support. - -Version 1.0.9 [January 31, 2001] - Added check of cygwin's ALL_STATIC in pngconf.h - Added "-nommx" parameter to contrib/gregbook/rpng2-win and rpng2-x demos. - -Version 1.0.10beta1 [March 14, 2001] - Revised makefile.dec, makefile.sgi, and makefile.sggcc; added makefile.hpgcc. - Reformatted libpng.3 to eliminate bad line breaks. - Added checks for _mmx_supported in the read_filter_row function of pnggccrd.c - Added prototype for png_mmx_support() near the top of pnggccrd.c - Moved some error checking from png_handle_IHDR to png_set_IHDR. - Added PNG_NO_READ_SUPPORTED and PNG_NO_WRITE_SUPPORTED macros. - Revised png_mmx_support() function in pnggccrd.c - Restored version 1.0.8 PNG_WRITE_EMPTY_PLTE_SUPPORTED behavior in pngwutil.c - Fixed memory leak in contrib/visupng/PngFile.c - Fixed bugs in png_combine_row() in pnggccrd.c and pngvcrd.c (C version) - Added warnings when retrieving or setting gamma=0. - Increased the first part of msg buffer from 16 to 18 in png_chunk_warning(). - -Version 1.0.10rc1 [March 23, 2001] - Changed all instances of memcpy, strcpy, and strlen to png_memcpy, png_strcpy, - and png_strlen. - Revised png_mmx_supported() function in pnggccrd.c to return proper value. - Fixed bug in progressive reading (pngpread.c) with small images (height < 8). - -Version 1.0.10 [March 30, 2001] - Deleted extraneous space (introduced in 1.0.9) from line 42 of makefile.cygwin - Added beos project files (Chris Herborth) - -Version 1.0.11beta1 [April 3, 2001] - Added type casts on several png_malloc() calls (Dimitri Papadapoulos). - Removed a no-longer needed AIX work-around from pngconf.h - Changed several "//" single-line comments to C-style in pnggccrd.c - -Version 1.0.11beta2 [April 11, 2001] - Removed PNGAPI from several functions whose prototypes did not have PNGAPI. - Updated scripts/pngos2.def - -Version 1.0.11beta3 [April 14, 2001] - Added checking the results of many instances of png_malloc() for NULL - -Version 1.0.11beta4 [April 20, 2001] - Undid the changes from version 1.0.11beta3. Added a check for NULL return - from user's malloc_fn(). - Removed some useless type casts of the NULL pointer. - Added makefile.netbsd - -Version 1.0.11 [April 27, 2001] - Revised makefile.netbsd - -Version 1.0.12beta1 [May 14, 2001] - Test for Windows platform in pngconf.h when including malloc.h (Emmanuel Blot) - Updated makefile.cygwin and handling of Cygwin's ALL_STATIC in pngconf.h - Added some never-to-be-executed code in pnggccrd.c to quiet compiler warnings. - Eliminated the png_error about apps using png_read|write_init(). Instead, - libpng will reallocate the png_struct and info_struct if they are too small. - This retains future binary compatibility for old applications written for - libpng-0.88 and earlier. - -Version 1.2.0beta1 [May 6, 2001] - Bumped DLLNUM to 2. - Re-enabled PNG_MNG_FEATURES_SUPPORTED and enabled PNG_ASSEMBLER_CODE_SUPPORTED - by default. - Added runtime selection of MMX features. - Added png_set_strip_error_numbers function and related macros. - -Version 1.2.0beta2 [May 7, 2001] - Finished merging 1.2.0beta1 with version 1.0.11 - Added a check for attempts to read or write PLTE in grayscale PNG datastreams. - -Version 1.2.0beta3 [May 17, 2001] - Enabled user memory function by default. - Modified png_create_struct so it passes user mem_ptr to user memory allocator. - Increased png_mng_features flag from png_byte to png_uint_32. - Bumped shared-library (so-number) and dll-number to 3. - -Version 1.2.0beta4 [June 23, 2001] - Check for missing profile length field in iCCP chunk and free chunk_data - in case of truncated iCCP chunk. - Bumped shared-library number to 3 in makefile.sgi and makefile.sggcc - Bumped dll-number from 2 to 3 in makefile.cygwin - Revised contrib/gregbook/rpng*-x.c to avoid a memory leak and to exit cleanly - if user attempts to run it on an 8-bit display. - Updated contrib/gregbook - Use png_malloc instead of png_zalloc to allocate palette in pngset.c - Updated makefile.ibmc - Added some typecasts to eliminate gcc 3.0 warnings. Changed prototypes - of png_write_oFFS width and height from png_uint_32 to png_int_32. - Updated example.c - Revised prototypes for png_debug_malloc and png_debug_free in pngtest.c - -Version 1.2.0beta5 [August 8, 2001] - Revised contrib/gregbook - Revised makefile.gcmmx - Revised pnggccrd.c to conditionally compile some thread-unsafe code only - when PNG_THREAD_UNSAFE_OK is defined. - Added tests to prevent pngwutil.c from writing a bKGD or tRNS chunk with - value exceeding 2^bit_depth-1 - Revised makefile.sgi and makefile.sggcc - Replaced calls to fprintf(stderr,...) with png_warning() in pnggccrd.c - Removed restriction that do_invert_mono only operate on 1-bit opaque files - -Version 1.2.0 [September 1, 2001] - Changed a png_warning() to png_debug() in pnggccrd.c - Fixed contrib/gregbook/rpng-x.c, rpng2-x.c to avoid crash with XFreeGC(). - -Version 1.2.1beta1 [October 19, 2001] - Revised makefile.std in contrib/pngminus - Include background_1 in png_struct regardless of gamma support. - Revised makefile.netbsd and makefile.macosx, added makefile.darwin. - Revised example.c to provide more details about using row_callback(). - -Version 1.2.1beta2 [October 25, 2001] - Added type cast to each NULL appearing in a function call, except for - WINCE functions. - Added makefile.so9. - -Version 1.2.1beta3 [October 27, 2001] - Removed type casts from all NULLs. - Simplified png_create_struct_2(). - -Version 1.2.1beta4 [November 7, 2001] - Revised png_create_info_struct() and png_creat_struct_2(). - Added error message if png_write_info() was omitted. - Type cast NULLs appearing in function calls when _NO_PROTO or - PNG_TYPECAST_NULL is defined. - -Version 1.2.1rc1 [November 24, 2001] - Type cast NULLs appearing in function calls except when PNG_NO_TYPECAST_NULL - is defined. - Changed typecast of "size" argument to png_size_t in pngmem.c calls to - the user malloc_fn, to agree with the prototype in png.h - Added a pop/push operation to pnggccrd.c, to preserve Eflag (Maxim Sobolev) - Updated makefile.sgi to recognize LIBPATH and INCPATH. - Updated various makefiles so "make clean" does not remove previous major - version of the shared library. - -Version 1.2.1rc2 [December 4, 2001] - Always allocate 256-entry internal palette, hist, and trans arrays, to - avoid out-of-bounds memory reference caused by invalid PNG datastreams. - Added a check for prefix_length > data_length in iCCP chunk handler. - -Version 1.2.1 [December 7, 2001] - None. - -Version 1.2.2beta1 [February 22, 2002] - Fixed a bug with reading the length of iCCP profiles (Larry Reeves). - Revised makefile.linux, makefile.gcmmx, and makefile.sgi to generate - libpng.a, libpng12.so (not libpng.so.3), and libpng12/png.h - Revised makefile.darwin to remove "-undefined suppress" option. - Added checks for gamma and chromaticity values over 21474.83, which exceed - the limit for PNG unsigned 32-bit integers when encoded. - Revised calls to png_create_read_struct() and png_create_write_struct() - for simpler debugging. - Revised png_zalloc() so zlib handles errors (uses PNG_FLAG_MALLOC_NULL_MEM_OK) - -Version 1.2.2beta2 [February 23, 2002] - Check chunk_length and idat_size for invalid (over PNG_MAX_UINT) lengths. - Check for invalid image dimensions in png_get_IHDR. - Added missing "fi;" in the install target of the SGI makefiles. - Added install-static to all makefiles that make shared libraries. - Always do gamma compensation when image is partially transparent. - -Version 1.2.2beta3 [March 7, 2002] - Compute background.gray and background_1.gray even when color_type is RGB - in case image gets reduced to gray later. - Modified shared-library makefiles to install pkgconfig/libpngNN.pc. - Export (with PNGAPI) png_zalloc, png_zfree, and png_handle_as_unknown - Removed unused png_write_destroy_info prototype from png.h - Eliminated incorrect use of width_mmx from pnggccrd.c in pixel_bytes == 8 case - Added install-shared target to all makefiles that make shared libraries. - Stopped a double free of palette, hist, and trans when not using free_me. - Added makefile.32sunu for Sun Ultra 32 and makefile.64sunu for Sun Ultra 64. - -Version 1.2.2beta4 [March 8, 2002] - Compute background.gray and background_1.gray even when color_type is RGB - in case image gets reduced to gray later (Jason Summers). - Relocated a misplaced /bin/rm in the "install-shared" makefile targets - Added PNG_1_0_X macro which can be used to build a 1.0.x-compatible library. - -Version 1.2.2beta5 [March 26, 2002] - Added missing PNGAPI to several function definitions. - Check for invalid bit_depth or color_type in png_get_IHDR(), and - check for missing PLTE or IHDR in png_push_read_chunk() (Matthias Clasen). - Revised iTXt support to accept NULL for lang and lang_key. - Compute gamma for color components of background even when color_type is gray. - Changed "()" to "{}" in scripts/libpng.pc.in. - Revised makefiles to put png.h and pngconf.h only in $prefix/include/libpngNN - Revised makefiles to make symlink to libpng.so.NN in addition to libpngNN.so - -Version 1.2.2beta6 [March 31, 2002] - -Version 1.0.13beta1 [March 31, 2002] - Prevent png_zalloc() from trying to memset memory that it failed to acquire. - Add typecasts of PNG_MAX_UINT in pngset_cHRM_fixed() (Matt Holgate). - Ensure that the right function (user or default) is used to free the - png_struct after an error in png_create_read_struct_2(). - -Version 1.2.2rc1 [April 7, 2002] - -Version 1.0.13rc1 [April 7, 2002] - Save the ebx register in pnggccrd.c (Sami Farin) - Add "mem_ptr = png_ptr->mem_ptr" in png_destroy_write_struct() (Paul Gardner). - Updated makefiles to put headers in include/libpng and remove old include/*.h. - -Version 1.2.2 [April 15, 2002] - -Version 1.0.13 [April 15, 2002] - Revised description of png_set_filter() in libpng.3/libpng.txt. - Revised makefile.netbsd and added makefile.neNNbsd and makefile.freebsd - -Version 1.0.13patch01 [April 17, 2002] - -Version 1.2.2patch01 [April 17, 2002] - Changed ${PNGMAJ}.${PNGVER} bug to ${PNGVER} in makefile.sgi and - makefile.sggcc - Fixed VER -> PNGVER typo in makefile.macosx and added install-static to - install - Added install: target to makefile.32sunu and makefile.64sunu - -Version 1.0.13patch03 [April 18, 2002] - -Version 1.2.2patch03 [April 18, 2002] - Revised 15 makefiles to link libpng.a to libpngNN.a and the include libpng - subdirectory to libpngNN subdirectory without the full pathname. - Moved generation of libpng.pc from "install" to "all" in 15 makefiles. - -Version 1.2.3rc1 [April 28, 2002] - Added install-man target to 15 makefiles (Dimitri Papadopolous-Orfanos). - Added $(DESTDIR) feature to 24 makefiles (Tim Mooney) - Fixed bug with $prefix, should be $(prefix) in makefile.hpux. - Updated cygwin-specific portion of pngconf.h and revised makefile.cygwin - Added a link from libpngNN.pc to libpng.pc in 15 makefiles. - Added links from include/libpngNN/*.h to include/*.h in 24 makefiles. - Revised makefile.darwin to make relative links without full pathname. - Added setjmp() at the end of png_create_*_struct_2() in case user forgets - to put one in their application. - Restored png_zalloc() and png_zfree() prototypes to version 1.2.1 and - removed them from module definition files. - -Version 1.2.3rc2 [May 1, 2002] - Fixed bug in reporting number of channels in pngget.c and pngset.c, - that was introduced in version 1.2.2beta5. - Exported png_zalloc(), png_zfree(), png_default_read(), png_default_write(), - png_default_flush(), and png_push_fill_buffer() and included them in - module definition files. - Added "libpng.pc" dependency to the "install-shared" target in 15 makefiles. - -Version 1.2.3rc3 [May 1, 2002] - Revised prototype for png_default_flush() - Remove old libpng.pc and libpngNN.pc before installing new ones. - -Version 1.2.3rc4 [May 2, 2002] - Typos in *.def files (png_default_read|write -> png_default_read|write_data) - In makefiles, changed rm libpng.NN.pc to rm libpngNN.pc - Added libpng-config and libpngNN-config and modified makefiles to install - them. - Changed $(MANPATH) to $(DESTDIR)$(MANPATH) in makefiles - Added "Win32 DLL VB" configuration to projects/msvc/libpng.dsp - -Version 1.2.3rc5 [May 11, 2002] - Changed "error" and "message" in prototypes to "error_message" and - "warning_message" to avoid namespace conflict. - Revised 15 makefiles to build libpng-config from libpng-config-*.in - Once more restored png_zalloc and png_zfree to regular nonexported form. - Restored png_default_read|write_data, png_default_flush, png_read_fill_buffer - to nonexported form, but with PNGAPI, and removed them from module def - files. - -Version 1.2.3rc6 [May 14, 2002] - Removed "PNGAPI" from png_zalloc() and png_zfree() in png.c - Changed "Gz" to "Gd" in projects/msvc/libpng.dsp and zlib.dsp. - Removed leftover libpng-config "sed" script from four makefiles. - Revised libpng-config creating script in 16 makefiles. - -Version 1.2.3 [May 22, 2002] - Revised libpng-config target in makefile.cygwin. - Removed description of png_set_mem_fn() from documentation. - Revised makefile.freebsd. - Minor cosmetic changes to 15 makefiles, e.g., $(DI) = $(DESTDIR)/$(INCDIR). - Revised projects/msvc/README.txt - Changed -lpng to -lpngNN in LDFLAGS in several makefiles. - -Version 1.2.4beta1 [May 24, 2002] - Added libpng.pc and libpng-config to "all:" target in 16 makefiles. - Fixed bug in 16 makefiles: $(DESTDIR)/$(LIBPATH) to $(DESTDIR)$(LIBPATH) - Added missing "\" before closing double quote in makefile.gcmmx. - Plugged various memory leaks; added png_malloc_warn() and png_set_text_2() - functions. - -Version 1.2.4beta2 [June 25, 2002] - Plugged memory leak of png_ptr->current_text (Matt Holgate). - Check for buffer overflow before reading CRC in pngpread.c (Warwick Allison) - Added -soname to the loader flags in makefile.dec, makefile.sgi, and - makefile.sggcc. - Added "test-installed" target to makefile.linux, makefile.gcmmx, - makefile.sgi, and makefile.sggcc. - -Version 1.2.4beta3 [June 28, 2002] - Plugged memory leak of row_buf in pngtest.c when there is a png_error(). - Detect buffer overflow in pngpread.c when IDAT is corrupted with extra data. - Added "test-installed" target to makefile.32sunu, makefile.64sunu, - makefile.beos, makefile.darwin, makefile.dec, makefile.macosx, - makefile.solaris, makefile.hpux, makefile.hpgcc, and makefile.so9. - -Version 1.2.4rc1 and 1.0.14rc1 [July 2, 2002] - Added "test-installed" target to makefile.cygwin and makefile.sco. - Revised pnggccrd.c to be able to back out version 1.0.x via PNG_1_0_X macro. - -Version 1.2.4 and 1.0.14 [July 8, 2002] - Changed png_warning() to png_error() when width is too large to process. - -Version 1.2.4patch01 [July 20, 2002] - Revised makefile.cygwin to use DLL number 12 instead of 13. - -Version 1.2.5beta1 [August 6, 2002] - Added code to contrib/gregbook/readpng2.c to ignore unused chunks. - Replaced toucan.png in contrib/gregbook (it has been corrupt since 1.0.11) - Removed some stray *.o files from contrib/gregbook. - Changed png_error() to png_warning() about "Too much data" in pngpread.c - and about "Extra compressed data" in pngrutil.c. - Prevent png_ptr->pass from exceeding 7 in png_push_finish_row(). - Updated makefile.hpgcc - Updated png.c and pnggccrd.c handling of return from png_mmx_support() - -Version 1.2.5beta2 [August 15, 2002] - Only issue png_warning() about "Too much data" in pngpread.c when avail_in - is nonzero. - Updated makefiles to install a separate libpng.so.3 with its own rpath. - -Version 1.2.5rc1 and 1.0.15rc1 [August 24, 2002] - Revised makefiles to not remove previous minor versions of shared libraries. - -Version 1.2.5rc2 and 1.0.15rc2 [September 16, 2002] - Revised 13 makefiles to remove "-lz" and "-L$(ZLIBLIB)", etc., from shared - library loader directive. - Added missing "$OBJSDLL" line to makefile.gcmmx. - Added missing "; fi" to makefile.32sunu. - -Version 1.2.5rc3 and 1.0.15rc3 [September 18, 2002] - Revised libpng-config script. - -Version 1.2.5 and 1.0.15 [October 3, 2002] - Revised makefile.macosx, makefile.darwin, makefile.hpgcc, and makefile.hpux, - and makefile.aix. - Relocated two misplaced PNGAPI lines in pngtest.c - -Version 1.2.6beta1 [October 22, 2002] - Commented out warning about uninitialized mmx_support in pnggccrd.c. - Changed "IBMCPP__" flag to "__IBMCPP__" in pngconf.h. - Relocated two more misplaced PNGAPI lines in pngtest.c - Fixed memory overrun bug in png_do_read_filler() with 16-bit datastreams, - introduced in version 1.0.2. - Revised makefile.macosx, makefile.dec, makefile.aix, and makefile.32sunu. - -Version 1.2.6beta2 [November 1, 2002] - Added libpng-config "--ldopts" output. - Added "AR=ar" and "ARFLAGS=rc" and changed "ar rc" to "$(AR) $(ARFLAGS)" - in makefiles. - -Version 1.2.6beta3 [July 18, 2004] - Reverted makefile changes from version 1.2.6beta2 and some of the changes - from version 1.2.6beta1; these will be postponed until version 1.2.7. - Version 1.2.6 is going to be a simple bugfix release. - Changed the one instance of "ln -sf" to "ln -f -s" in each Sun makefile. - Fixed potential overrun in pngerror.c by using strncpy instead of memcpy. - Added "#!/bin/sh" at the top of configure, for recognition of the - 'x' flag under Cygwin (Cosmin). - Optimized vacuous tests that silence compiler warnings, in png.c (Cosmin). - Added support for PNG_USER_CONFIG, in pngconf.h (Cosmin). - Fixed the special memory handler for Borland C under DOS, in pngmem.c - (Cosmin). - Removed some spurious assignments in pngrutil.c (Cosmin). - Replaced 65536 with 65536L, and 0xffff with 0xffffL, to silence warnings - on 16-bit platforms (Cosmin). - Enclosed shift op expressions in parentheses, to silence warnings (Cosmin). - Used proper type png_fixed_point, to avoid problems on 16-bit platforms, - in png_handle_sRGB() (Cosmin). - Added compression_type to png_struct, and optimized the window size - inside the deflate stream (Cosmin). - Fixed definition of isnonalpha(), in pngerror.c and pngrutil.c (Cosmin). - Fixed handling of unknown chunks that come after IDAT (Cosmin). - Allowed png_error() and png_warning() to work even if png_ptr == NULL - (Cosmin). - Replaced row_info->rowbytes with row_bytes in png_write_find_filter() - (Cosmin). - Fixed definition of PNG_LIBPNG_VER_DLLNUM (Simon-Pierre). - Used PNG_LIBPNG_VER and PNG_LIBPNG_VER_STRING instead of the hardcoded - values in png.c (Simon-Pierre, Cosmin). - Initialized png_libpng_ver[] with PNG_LIBPNG_VER_STRING (Simon-Pierre). - Replaced PNG_LIBPNG_VER_MAJOR with PNG_LIBPNG_VER_DLLNUM in png.rc - (Simon-Pierre). - Moved the definition of PNG_HEADER_VERSION_STRING near the definitions - of the other PNG_LIBPNG_VER_... symbols in png.h (Cosmin). - Relocated #ifndef PNGAPI guards in pngconf.h (Simon-Pierre, Cosmin). - Updated scripts/makefile.vc(a)win32 (Cosmin). - Updated the MSVC project (Simon-Pierre, Cosmin). - Updated the Borland C++ Builder project (Cosmin). - Avoided access to asm_flags in pngvcrd.c, if PNG_1_0_X is defined (Cosmin). - Commented out warning about uninitialized mmx_support in pngvcrd.c (Cosmin). - Removed scripts/makefile.bd32 and scripts/pngdef.pas (Cosmin). - Added extra guard around inclusion of Turbo C memory headers, in pngconf.h - (Cosmin). - Renamed projects/msvc/ to projects/visualc6/, and projects/borland/ to - projects/cbuilder5/ (Cosmin). - Moved projects/visualc6/png32ms.def to scripts/pngw32.def, - and projects/visualc6/png.rc to scripts/pngw32.rc (Cosmin). - Added projects/visualc6/pngtest.dsp; removed contrib/msvctest/ (Cosmin). - Changed line endings to DOS style in cbuilder5 and visualc6 files, even - in the tar.* distributions (Cosmin). - Updated contrib/visupng/VisualPng.dsp (Cosmin). - Updated contrib/visupng/cexcept.h to version 2.0.0 (Cosmin). - Added a separate distribution with "configure" and supporting files (Junichi). - -Version 1.2.6beta4 [July 28, 2004] - Added user ability to change png_size_t via a PNG_SIZE_T macro. - Added png_sizeof() and png_convert_size() functions. - Added PNG_SIZE_MAX (maximum value of a png_size_t variable. - Added check in png_malloc_default() for (size_t)size != (png_uint_32)size - which would indicate an overflow. - Changed sPLT failure action from png_error to png_warning and abandon chunk. - Changed sCAL and iCCP failures from png_error to png_warning and abandon. - Added png_get_uint_31(png_ptr, buf) function. - Added PNG_UINT_32_MAX macro. - Renamed PNG_MAX_UINT to PNG_UINT_31_MAX. - Made png_zalloc() issue a png_warning and return NULL on potential - overflow. - Turn on PNG_NO_ZALLOC_ZERO by default in version 1.2.x - Revised "clobber list" in pnggccrd.c so it will compile under gcc-3.4. - Revised Borland portion of png_malloc() to return NULL or issue - png_error() according to setting of PNG_FLAG_MALLOC_NULL_MEM_OK. - Added PNG_NO_SEQUENTIAL_READ_SUPPORTED macro to conditionally remove - sequential read support. - Added some "#if PNG_WRITE_SUPPORTED" blocks. - Added #ifdef to remove some redundancy in png_malloc_default(). - Use png_malloc instead of png_zalloc to allocate the pallete. - -Version 1.0.16rc1 and 1.2.6rc1 [August 4, 2004] - Fixed buffer overflow vulnerability in png_handle_tRNS() - Fixed integer arithmetic overflow vulnerability in png_read_png(). - Fixed some harmless bugs in png_handle_sBIT, etc, that would cause - duplicate chunk types to go undetected. - Fixed some timestamps in the -config version - Rearranged order of processing of color types in png_handle_tRNS(). - Added ROWBYTES macro to calculate rowbytes without integer overflow. - Updated makefile.darwin and removed makefile.macosx from scripts directory. - Imposed default one million column, one-million row limits on the image - dimensions, and added png_set_user_limits() function to override them. - Revised use of PNG_SET_USER_LIMITS_SUPPORTED macro. - Fixed wrong cast of returns from png_get_user_width|height_max(). - Changed some "keep the compiler happy" from empty statements to returns, - Revised libpng.txt to remove 1.2.x stuff from the 1.0.x distribution - -Version 1.0.16rc2 and 1.2.6rc2 [August 7, 2004] - Revised makefile.darwin and makefile.solaris. Removed makefile.macosx. - Revised pngtest's png_debug_malloc() to use png_malloc() instead of - png_malloc_default() which is not supposed to be exported. - Fixed off-by-one error in one of the conversions to PNG_ROWBYTES() in - pngpread.c. Bug was introduced in 1.2.6rc1. - Fixed bug in RGB to RGBX transformation introduced in 1.2.6rc1. - Fixed old bug in RGB to Gray transformation. - Fixed problem with 64-bit compilers by casting arguments to abs() - to png_int_32. - Changed "ln -sf" to "ln -f -s" in three makefiles (solaris, sco, so9). - Changed "HANDLE_CHUNK_*" to "PNG_HANDLE_CHUNK_*" (Cosmin) - Added "-@/bin/rm -f $(DL)/$(LIBNAME).so.$(PNGMAJ)" to 15 *NIX makefiles. - Added code to update the row_info->colortype in png_do_read_filler() (MSB). - -Version 1.0.16rc3 and 1.2.6rc3 [August 9, 2004] - Eliminated use of "abs()" in testing cHRM and gAMA values, to avoid - trouble with some 64-bit compilers. Created PNG_OUT_OF_RANGE() macro. - Revised documentation of png_set_keep_unknown_chunks(). - Check handle_as_unknown status in pngpread.c, as in pngread.c previously. - Moved "PNG_HANDLE_CHUNK_*" macros out of PNG_INTERNAL section of png.h - Added "rim" definitions for CONST4 and CONST6 in pnggccrd.c - -Version 1.0.16rc4 and 1.2.6rc4 [August 10, 2004] - Fixed mistake in pngtest.c introduced in 1.2.6rc2 (declaration of - "pinfo" was out of place). - -Version 1.0.16rc5 and 1.2.6rc5 [August 10, 2004] - Moved "PNG_HANDLE_CHUNK_*" macros out of PNG_ASSEMBLER_CODE_SUPPORTED - section of png.h where they were inadvertently placed in version rc3. - -Version 1.2.6 and 1.0.16 [August 15, 2004] - Revised pngtest so memory allocation testing is only done when PNG_DEBUG==1. - -Version 1.2.7beta1 [August 26, 2004] - Removed unused pngasmrd.h file. - Removed references to uu.net for archived files. Added references to - PNG Spec (second edition) and the PNG ISO/IEC Standard. - Added "test-dd" target in 15 makefiles, to run pngtest in DESTDIR. - Fixed bug with "optimized window size" in the IDAT datastream, that - causes libpng to write PNG files with incorrect zlib header bytes. - -Version 1.2.7beta2 [August 28, 2004] - Fixed bug with sCAL chunk and big-endian machines (David Munro). - Undid new code added in 1.2.6rc2 to update the color_type in - png_set_filler(). - Added png_set_add_alpha() that updates color type. - -Version 1.0.17rc1 and 1.2.7rc1 [September 4, 2004] - Revised png_set_strip_filler() to not remove alpha if color_type has alpha. - -Version 1.2.7 and 1.0.17 [September 12, 2004] - Added makefile.hp64 - Changed projects/msvc/png32ms.def to scripts/png32ms.def in makefile.cygwin - -Version 1.2.8beta1 [November 1, 2004] - Fixed bug in png_text_compress() that would fail to complete a large block. - Fixed bug, introduced in libpng-1.2.7, that overruns a buffer during - strip alpha operation in png_do_strip_filler(). - Added PNG_1_2_X definition in pngconf.h - Use #ifdef to comment out png_info_init in png.c and png_read_init in - pngread.c (as of 1.3.0) - -Version 1.2.8beta2 [November 2, 2004] - Reduce color_type to a nonalpha type after strip alpha operation in - png_do_strip_filler(). - -Version 1.2.8beta3 [November 3, 2004] - Revised definitions of PNG_MAX_UINT_32, PNG_MAX_SIZE, and PNG_MAXSUM - -Version 1.2.8beta4 [November 12, 2004] - Fixed (again) definition of PNG_LIBPNG_VER_DLLNUM in png.h (Cosmin). - Added PNG_LIBPNG_BUILD_PRIVATE in png.h (Cosmin). - Set png_ptr->zstream.data_type to Z_BINARY, to avoid unnecessary detection - of data type in deflate (Cosmin). - Deprecated but continue to support SPECIALBUILD and PRIVATEBUILD in favor of - PNG_LIBPNG_BUILD_SPECIAL_STRING and PNG_LIBPNG_BUILD_PRIVATE_STRING. - -Version 1.2.8beta5 [November 20, 2004] - Use png_ptr->flags instead of png_ptr->transformations to pass - PNG_STRIP_ALPHA info to png_do_strip_filler(), to preserve ABI - compatibility. - Revised handling of SPECIALBUILD, PRIVATEBUILD, - PNG_LIBPNG_BUILD_SPECIAL_STRING and PNG_LIBPNG_BUILD_PRIVATE_STRING. - -Version 1.2.8rc1 [November 24, 2004] - Moved handling of BUILD macros from pngconf.h to png.h - Added definition of PNG_LIBPNG_BASE_TYPE in png.h, inadvertently - omitted from beta5. - Revised scripts/pngw32.rc - Despammed mailing addresses by masking "@" with "at". - Inadvertently installed a supposedly faster test version of pngrutil.c - -Version 1.2.8rc2 [November 26, 2004] - Added two missing "\" in png.h - Change tests in pngread.c and pngpread.c to - if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) - png_do_read_transformations(png_ptr); - -Version 1.2.8rc3 [November 28, 2004] - Reverted pngrutil.c to version libpng-1.2.8beta5. - Added scripts/makefile.elf with supporting code in pngconf.h for symbol - versioning (John Bowler). - -Version 1.2.8rc4 [November 29, 2004] - Added projects/visualc7 (Simon-pierre). - -Version 1.2.8rc5 [November 29, 2004] - Fixed new typo in scripts/pngw32.rc - -Version 1.2.8 [December 3, 2004] - Removed projects/visualc7, added projects/visualc71. - -Version 1.2.9beta1 [February 21, 2006] - Initialized some structure members in pngwutil.c to avoid gcc-4.0.0 complaints - Revised man page and libpng.txt to make it clear that one should not call - png_read_end or png_write_end after png_read_png or png_write_png. - Updated references to png-mng-implement mailing list. - Fixed an incorrect typecast in pngrutil.c - Added PNG_NO_READ_SUPPORTED conditional for making a write-only library. - Added PNG_NO_WRITE_INTERLACING_SUPPORTED conditional. - Optimized alpha-inversion loops in pngwtran.c - Moved test for nonzero gamma outside of png_build_gamma_table() in pngrtran.c - Make sure num_trans is <= 256 before copying data in png_set_tRNS(). - Make sure num_palette is <= 256 before copying data in png_set_PLTE(). - Interchanged order of write_swap_alpha and write_invert_alpha transforms. - Added parentheses in the definition of PNG_LIBPNG_BUILD_TYPE (Cosmin). - Optimized zlib window flag (CINFO) in contrib/pngsuite/*.png (Cosmin). - Updated scripts/makefile.bc32 for Borland C++ 5.6 (Cosmin). - Exported png_get_uint_32, png_save_uint_32, png_get_uint_16, png_save_uint_16, - png_get_int_32, png_save_int_32, png_get_uint_31 (Cosmin). - Added type cast (png_byte) in png_write_sCAL() (Cosmin). - Fixed scripts/makefile.cygwin (Christian Biesinger, Cosmin). - Default iTXt support was inadvertently enabled. - -Version 1.2.9beta2 [February 21, 2006] - Check for png_rgb_to_gray and png_gray_to_rgb read transformations before - checking for png_read_dither in pngrtran.c - Revised checking of chromaticity limits to accommodate extended RGB - colorspace (John Denker). - Changed line endings in some of the project files to CRLF, even in the - "Unix" tar distributions (Cosmin). - Made png_get_int_32 and png_save_int_32 always available (Cosmin). - Updated scripts/pngos2.def, scripts/pngw32.def and projects/wince/png32ce.def - with the newly exported functions. - Eliminated distributions without the "configure" script. - Updated INSTALL instructions. - -Version 1.2.9beta3 [February 24, 2006] - Fixed CRCRLF line endings in contrib/visupng/VisualPng.dsp - Made libpng.pc respect EXEC_PREFIX (D. P. Kreil, J. Bowler) - Removed reference to pngasmrd.h from Makefile.am - Renamed CHANGES to ChangeLog. - Renamed LICENSE to COPYING. - Renamed ANNOUNCE to NEWS. - Created AUTHORS file. - -Version 1.2.9beta4 [March 3, 2006] - Changed definition of PKGCONFIG from $prefix/lib to $libdir in configure.ac - Reverted to filenames LICENSE and ANNOUNCE; removed AUTHORS and COPYING. - Removed newline from the end of some error and warning messages. - Removed test for sqrt() from configure.ac and configure. - Made swap tables in pngtrans.c PNG_CONST (Carlo Bramix). - Disabled default iTXt support that was inadvertently enabled in - libpng-1.2.9beta1. - Added "OS2" to list of systems that don't need underscores, in pnggccrd.c - Removed libpng version and date from *.c files. - -Version 1.2.9beta5 [March 4, 2006] - Removed trailing blanks from source files. - Put version and date of latest change in each source file, and changed - copyright year accordingly. - More cleanup of configure.ac, Makefile.am, and associated scripts. - Restored scripts/makefile.elf which was inadvertently deleted. - -Version 1.2.9beta6 [March 6, 2006] - Fixed typo (RELEASE) in configuration files. - -Version 1.2.9beta7 [March 7, 2006] - Removed libpng.vers and libpng.sym from libpng12_la_SOURCES in Makefile.am - Fixed inconsistent #ifdef's around png_sig_bytes() and png_set_sCAL_s() - in png.h. - Updated makefile.elf as suggested by debian. - Made cosmetic changes to some makefiles, adding LN_SF and other macros. - Made some makefiles accept "exec_prefix". - -Version 1.2.9beta8 [March 9, 2006] - Fixed some "#if defined (..." which should be "#if defined(..." - Bug introduced in libpng-1.2.8. - Fixed inconsistency in definition of png_default_read_data() - Restored blank that was lost from makefile.sggcc "clean" target in beta7. - Revised calculation of "current" and "major" for irix in ltmain.sh - Changed "mkdir" to "MKDIR_P" in some makefiles. - Separated PNG_EXPAND and PNG_EXPAND_tRNS. - Added png_set_expand_gray_1_2_4_to_8() and deprecated - png_set_gray_1_2_4_to_8() which also expands tRNS to alpha. - -Version 1.2.9beta9 [March 10, 2006] - Include "config.h" in pngconf.h when available. - Added some checks for NULL png_ptr or NULL info_ptr (timeless) - -Version 1.2.9beta10 [March 20, 2006] - Removed extra CR from contrib/visualpng/VisualPng.dsw (Cosmin) - Made pnggccrd.c PIC-compliant (Christian Aichinger). - Added makefile.mingw (Wolfgang Glas). - Revised pngconf.h MMX checking. - -Version 1.2.9beta11 [March 22, 2006] - Fixed out-of-order declaration in pngwrite.c that was introduced in beta9 - Simplified some makefiles by using LIBSO, LIBSOMAJ, and LIBSOVER macros. - -Version 1.2.9rc1 [March 31, 2006] - Defined PNG_USER_PRIVATEBUILD when including "pngusr.h" (Cosmin). - Removed nonsensical assertion check from pngtest.c (Cosmin). - -Version 1.2.9 [April 14, 2006] - Revised makefile.beos and added "none" selector in ltmain.sh - -Version 1.2.10beta1 [April 15, 2006] - Renamed "config.h" to "png_conf.h" and revised Makefile.am to add - -DPNG_BUILDING_LIBPNG to compile directive, and modified pngconf.h - to include png_conf.h only when PNG_BUILDING_LIBPNG is defined. - -Version 1.2.10beta2 [April 15, 2006] - Manually updated Makefile.in and configure. Changed png_conf.h.in - back to config.h. - -Version 1.2.10beta3 [April 15, 2006] - Change png_conf.h back to config.h in pngconf.h. - -Version 1.2.10beta4 [April 16, 2006] - Change PNG_BUILDING_LIBPNG to PNG_CONFIGURE_LIBPNG in config/Makefile*. - -Version 1.2.10beta5 [April 16, 2006] - Added a configure check for compiling assembler code in pnggccrd.c - -Version 1.2.10beta6 [April 17, 2006] - Revised the configure check for pnggccrd.c - Moved -DPNG_CONFIGURE_LIBPNG into @LIBPNG_DEFINES@ - Added @LIBPNG_DEFINES@ to arguments when building libpng.sym - -Version 1.2.10beta7 [April 18, 2006] - Change "exec_prefix=$prefix" to "exec_prefix=$(prefix)" in makefiles. - -Version 1.2.10rc1 [April 19, 2006] - Ensure pngconf.h doesn't define both PNG_USE_PNGGCCRD and PNG_USE_PNGVCRD - Fixed "LN_FS" typo in makefile.sco and makefile.solaris. - -Version 1.2.10rc2 [April 20, 2006] - Added a backslash between -DPNG_CONFIGURE_LIBPNG and -DPNG_NO_ASSEMBLER_CODE - in configure.ac and configure - Made the configure warning about versioned symbols less arrogant. - -Version 1.2.10rc3 [April 21, 2006] - Added a note in libpng.txt that png_set_sig_bytes(8) can be used when - writing an embedded PNG without the 8-byte signature. - Revised makefiles and configure to avoid making links to libpng.so.* - -Version 1.2.10 [April 23, 2006] - Reverted configure to "rc2" state. - -Version 1.2.11beta1 [May 31, 2006] - scripts/libpng.pc.in contained "configure" style version info and would - not work with makefiles. - The shared-library makefiles were linking to libpng.so.0 instead of - libpng.so.3 compatibility as the library. - -Version 1.2.11beta2 [June 2, 2006] - Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid - buffer overflow. - Fixed bug in example.c (png_set_palette_rgb -> png_set_palette_to_rgb) - -Version 1.2.11beta3 [June 5, 2006] - Prepended "#! /bin/sh" to ltmail.sh and contrib/pngminus/*.sh (Cosmin). - Removed the accidental leftover Makefile.in~ (Cosmin). - Avoided potential buffer overflow and optimized buffer in - png_write_sCAL(), png_write_sCAL_s() (Cosmin). - Removed the include directories and libraries from CFLAGS and LDFLAGS - in scripts/makefile.gcc (Nelson A. de Oliveira, Cosmin). - -Version 1.2.11beta4 [June 6, 2006] - Allow zero-length IDAT chunks after the entire zlib datastream, but not - after another intervening chunk type. - -Version 1.0.19rc1, 1.2.11rc1 [June 13, 2006] - Deleted extraneous square brackets from [config.h] in configure.ac - -Version 1.0.19rc2, 1.2.11rc2 [June 14, 2006] - Added prototypes for PNG_INCH_CONVERSIONS functions to png.h - Revised INSTALL and autogen.sh - Fixed typo in several makefiles (-W1 should be -Wl) - Added typedef for png_int_32 and png_uint_32 on 64-bit systems. - -Version 1.0.19rc3, 1.2.11rc3 [June 15, 2006] - Removed the new typedefs for 64-bit systems (delay until version 1.4.0) - Added one zero element to png_gamma_shift[] array in pngrtran.c to avoid - reading out of bounds. - -Version 1.0.19rc4, 1.2.11rc4 [June 15, 2006] - Really removed the new typedefs for 64-bit systems. - -Version 1.0.19rc5, 1.2.11rc5 [June 22, 2006] - Removed png_sig_bytes entry from scripts/pngw32.def - -Version 1.0.19, 1.2.11 [June 26, 2006] - None. - -Version 1.0.20, 1.2.12 [June 27, 2006] - Really increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid - buffer overflow. - -Version 1.2.13beta1 [October 2, 2006] - Removed AC_FUNC_MALLOC from configure.ac - Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h - Change "logical" to "bitwise" throughout documentation. - Detect and fix attempt to write wrong iCCP profile length (CVE-2006-7244) - -Version 1.0.21, 1.2.13 [November 14, 2006] - Fix potential buffer overflow in sPLT chunk handler. - Fix Makefile.am to not try to link to noexistent files. - Check all exported functions for NULL png_ptr. - -Version 1.2.14beta1 [November 17, 2006] - Relocated three misplaced tests for NULL png_ptr. - Built Makefile.in with automake-1.9.6 instead of 1.9.2. - Build configure with autoconf-2.60 instead of 2.59 - -Version 1.2.14beta2 [November 17, 2006] - Added some typecasts in png_zalloc(). - -Version 1.2.14rc1 [November 20, 2006] - Changed "strtod" to "png_strtod" in pngrutil.c - -Version 1.0.22, 1.2.14 [November 27, 2006] - Added missing "$(srcdir)" in Makefile.am and Makefile.in - -Version 1.2.15beta1 [December 3, 2006] - Generated configure with autoconf-2.61 instead of 2.60 - Revised configure.ac to update libpng.pc and libpng-config. - -Version 1.2.15beta2 [December 3, 2006] - Always export MMX asm functions, just stubs if not building pnggccrd.c - -Version 1.2.15beta3 [December 4, 2006] - Add "png_bytep" typecast to profile while calculating length in pngwutil.c - -Version 1.2.15beta4 [December 7, 2006] - Added scripts/CMakeLists.txt - Changed PNG_NO_ASSEMBLER_CODE to PNG_NO_MMX_CODE in scripts, like 1.4.0beta - -Version 1.2.15beta5 [December 7, 2006] - Changed some instances of PNG_ASSEMBLER_* to PNG_MMX_* in pnggccrd.c - Revised scripts/CMakeLists.txt - -Version 1.2.15beta6 [December 13, 2006] - Revised scripts/CMakeLists.txt and configure.ac - -Version 1.2.15rc1 [December 18, 2006] - Revised scripts/CMakeLists.txt - -Version 1.2.15rc2 [December 21, 2006] - Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers. - Added scripts/makefile.nommx - -Version 1.2.15rc3 [December 25, 2006] - Fixed shared library numbering error that was introduced in 1.2.15beta6. - -Version 1.2.15rc4 [December 27, 2006] - Fixed handling of rgb_to_gray when png_ptr->color.gray isn't set. - -Version 1.2.15rc5 [December 31, 2006] - Revised handling of rgb_to_gray. - -Version 1.2.15 [January 5, 2007] - Added some (unsigned long) typecasts in pngtest.c to avoid printing errors. - -Version 1.2.16beta1 [January 6, 2007] - Fix bugs in makefile.nommx - -Version 1.2.16beta2 [January 16, 2007] - Revised scripts/CMakeLists.txt - -Version 1.2.16 [January 31, 2007] - No changes. - -Version 1.2.17beta1 [March 6, 2007] - Revised scripts/CMakeLists.txt to install both shared and static libraries. - Deleted a redundant line from pngset.c. - -Version 1.2.17beta2 [April 26, 2007] - Relocated misplaced test for png_ptr == NULL in pngpread.c - Change "==" to "&" for testing PNG_RGB_TO_GRAY_ERR & PNG_RGB_TO_GRAY_WARN - flags. - Changed remaining instances of PNG_ASSEMBLER_* to PNG_MMX_* - Added pngerror() when write_IHDR fails in deflateInit2(). - Added "const" to some array declarations. - Mention examples of libpng usage in the libpng*.txt and libpng.3 documents. - -Version 1.2.17rc1 [May 4, 2007] - No changes. - -Version 1.2.17rc2 [May 8, 2007] - Moved several PNG_HAVE_* macros out of PNG_INTERNAL because applications - calling set_unknown_chunk_location() need them. - Changed transformation flag from PNG_EXPAND_tRNS to PNG_EXPAND in - png_set_expand_gray_1_2_4_to_8(). - Added png_ptr->unknown_chunk to hold working unknown chunk data, so it - can be free'ed in case of error. Revised unknown chunk handling in - pngrutil.c and pngpread.c to use this structure. - -Version 1.2.17rc3 [May 8, 2007] - Revised symbol-handling in configure script. - -Version 1.2.17rc4 [May 10, 2007] - Revised unknown chunk handling to avoid storing unknown critical chunks. - -Version 1.0.25 [May 15, 2007] -Version 1.2.17 [May 15, 2007] - Added "png_ptr->num_trans=0" before error return in png_handle_tRNS, - to eliminate a vulnerability (CVE-2007-2445, CERT VU#684664) - -Version 1.0.26 [May 15, 2007] -Version 1.2.18 [May 15, 2007] - Reverted the libpng-1.2.17rc3 change to symbol-handling in configure script - -Version 1.2.19beta1 [May 18, 2007] - Changed "const static" to "static PNG_CONST" everywhere, mostly undoing - change of libpng-1.2.17beta2. Changed other "const" to "PNG_CONST" - Changed some handling of unused parameters, to avoid compiler warnings. - "if (unused == NULL) return;" becomes "unused = unused". - -Version 1.2.19beta2 [May 18, 2007] - Only use the valid bits of tRNS value in png_do_expand() (Brian Cartier) - -Version 1.2.19beta3 [May 19, 2007] - Add some "png_byte" typecasts in png_check_keyword() and write new_key - instead of key in zTXt chunk (Kevin Ryde). - -Version 1.2.19beta4 [May 21, 2007] - Add png_snprintf() function and use it in place of sprint() for improved - defense against buffer overflows. - -Version 1.2.19beta5 [May 21, 2007] - Fixed png_handle_tRNS() to only use the valid bits of tRNS value. - Changed handling of more unused parameters, to avoid compiler warnings. - Removed some PNG_CONST in pngwutil.c to avoid compiler warnings. - -Version 1.2.19beta6 [May 22, 2007] - Added some #ifdef PNG_MMX_CODE_SUPPORTED where needed in pngvcrd.c - Added a special "_MSC_VER" case that defines png_snprintf to _snprintf - -Version 1.2.19beta7 [May 22, 2007] - Squelched png_squelch_warnings() in pnggccrd.c and added - an #ifdef PNG_MMX_CODE_SUPPORTED block around the declarations that caused - the warnings that png_squelch_warnings was squelching. - -Version 1.2.19beta8 [May 22, 2007] - Removed __MMX__ from test in pngconf.h. - -Version 1.2.19beta9 [May 23, 2007] - Made png_squelch_warnings() available via PNG_SQUELCH_WARNINGS macro. - Revised png_squelch_warnings() so it might work. - Updated makefile.sgcc and makefile.solaris; added makefile.solaris-x86. - -Version 1.2.19beta10 [May 24, 2007] - Resquelched png_squelch_warnings(), use "__attribute__((used))" instead. - -Version 1.4.0beta1 [April 20, 2006] - Enabled iTXt support (changes png_struct, thus requires so-number change). - Cleaned up PNG_ASSEMBLER_CODE_SUPPORTED vs PNG_MMX_CODE_SUPPORTED - Eliminated PNG_1_0_X and PNG_1_2_X macros. - Removed deprecated functions png_read_init, png_write_init, png_info_init, - png_permit_empty_plte, png_set_gray_1_2_4_to_8, png_check_sig, and - removed the deprecated macro PNG_MAX_UINT. - Moved "PNG_INTERNAL" parts of png.h and pngconf.h into pngintrn.h - Removed many WIN32_WCE #ifdefs (Cosmin). - Reduced dependency on C-runtime library when on Windows (Simon-Pierre) - Replaced sprintf() with png_sprintf() (Simon-Pierre) - -Version 1.4.0beta2 [April 20, 2006] - Revised makefiles and configure to avoid making links to libpng.so.* - Moved some leftover MMX-related defines from pngconf.h to pngintrn.h - Updated scripts/pngos2.def, pngw32.def, and projects/wince/png32ce.def - -Version 1.4.0beta3 [May 10, 2006] - Updated scripts/pngw32.def to comment out MMX functions. - Added PNG_NO_GET_INT_32 and PNG_NO_SAVE_INT_32 macros. - Scripts/libpng.pc.in contained "configure" style version info and would - not work with makefiles. - Revised pngconf.h and added pngconf.h.in, so makefiles and configure can - pass defines to libpng and applications. - -Version 1.4.0beta4 [May 11, 2006] - Revised configure.ac, Makefile.am, and many of the makefiles to write - their defines in pngconf.h. - -Version 1.4.0beta5 [May 15, 2006] - Added a missing semicolon in Makefile.am and Makefile.in - Deleted extraneous square brackets from configure.ac - -Version 1.4.0beta6 [June 2, 2006] - Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid - buffer overflow. - Changed sonum from 0 to 1. - Removed unused prototype for png_check_sig() from png.h - -Version 1.4.0beta7 [June 16, 2006] - Exported png_write_sig (Cosmin). - Optimized buffer in png_handle_cHRM() (Cosmin). - Set pHYs = 2835 x 2835 pixels per meter, and added - sCAL = 0.352778e-3 x 0.352778e-3 meters, in pngtest.png (Cosmin). - Added png_set_benign_errors(), png_benign_error(), png_chunk_benign_error(). - Added typedef for png_int_32 and png_uint_32 on 64-bit systems. - Added "(unsigned long)" typecast on png_uint_32 variables in printf lists. - -Version 1.4.0beta8 [June 22, 2006] - Added demonstration of user chunk support in pngtest.c, to support the - public sTER chunk and a private vpAg chunk. - -Version 1.4.0beta9 [July 3, 2006] - Removed ordinals from scripts/pngw32.def and removed png_info_int and - png_set_gray_1_2_4_to_8 entries. - Inline call of png_get_uint_32() in png_get_uint_31(). - Use png_get_uint_31() to get vpAg width and height in pngtest.c - Removed WINCE and Netware projects. - Removed standalone Y2KINFO file. - -Version 1.4.0beta10 [July 12, 2006] - Eliminated automatic copy of pngconf.h to pngconf.h.in from configure and - some makefiles, because it was not working reliably. Instead, distribute - pngconf.h.in along with pngconf.h and cause configure and some of the - makefiles to update pngconf.h from pngconf.h.in. - Added pngconf.h to DEPENDENCIES in Makefile.am - -Version 1.4.0beta11 [August 19, 2006] - Removed AC_FUNC_MALLOC from configure.ac. - Added a warning when writing iCCP profile with mismatched profile length. - Patched pnggccrd.c to assemble on x86_64 platforms. - Moved chunk header reading into a separate function png_read_chunk_header() - in pngrutil.c. The chunk header (len+sig) is now serialized in a single - operation (Cosmin). - Implemented support for I/O states. Added png_ptr member io_state, and - functions png_get_io_chunk_name() and png_get_io_state() in pngget.c - (Cosmin). - Added png_get_io_chunk_name and png_get_io_state to scripts/*.def (Cosmin). - Renamed scripts/pngw32.* to scripts/pngwin.* (Cosmin). - Removed the include directories and libraries from CFLAGS and LDFLAGS - in scripts/makefile.gcc (Cosmin). - Used png_save_uint_32() to set vpAg width and height in pngtest.c (Cosmin). - Cast to proper type when getting/setting vpAg units in pngtest.c (Cosmin). - Added pngintrn.h to the Visual C++ projects (Cosmin). - Removed scripts/list (Cosmin). - Updated copyright year in scripts/pngwin.def (Cosmin). - Removed PNG_TYPECAST_NULL and used standard NULL consistently (Cosmin). - Disallowed the user to redefine png_size_t, and enforced a consistent use - of png_size_t across libpng (Cosmin). - Changed the type of png_ptr->rowbytes, PNG_ROWBYTES() and friends - to png_size_t (Cosmin). - Removed png_convert_size() and replaced png_sizeof with sizeof (Cosmin). - Removed some unnecessary type casts (Cosmin). - Changed prototype of png_get_compression_buffer_size() and - png_set_compression_buffer_size() to work with png_size_t instead of - png_uint_32 (Cosmin). - Removed png_memcpy_check() and png_memset_check() (Cosmin). - Fixed a typo (png_byte --> png_bytep) in libpng.3 and libpng.txt (Cosmin). - Clarified that png_zalloc() does not clear the allocated memory, - and png_zalloc() and png_zfree() cannot be PNGAPI (Cosmin). - Renamed png_mem_size_t to png_alloc_size_t, fixed its definition in - pngconf.h, and used it in all memory allocation functions (Cosmin). - Renamed pngintrn.h to pngpriv.h, added a comment at the top of the file - mentioning that the symbols declared in that file are private, and - updated the scripts and the Visual C++ projects accordingly (Cosmin). - Removed circular references between pngconf.h and pngconf.h.in in - scripts/makefile.vc*win32 (Cosmin). - Removing trailing '.' from the warning and error messages (Cosmin). - Added pngdefs.h that is built by makefile or configure, instead of - pngconf.h.in (Glenn). - Detect and fix attempt to write wrong iCCP profile length. - -Version 1.4.0beta12 [October 19, 2006] - Changed "logical" to "bitwise" in the documentation. - Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h - Add a typecast to stifle compiler warning in pngrutil.c - -Version 1.4.0beta13 [November 10, 2006] - Fix potential buffer overflow in sPLT chunk handler. - Fix Makefile.am to not try to link to noexistent files. - -Version 1.4.0beta14 [November 15, 2006] - Check all exported functions for NULL png_ptr. - -Version 1.4.0beta15 [November 17, 2006] - Relocated two misplaced tests for NULL png_ptr. - Built Makefile.in with automake-1.9.6 instead of 1.9.2. - Build configure with autoconf-2.60 instead of 2.59 - Add "install: all" in Makefile.am so "configure; make install" will work. - -Version 1.4.0beta16 [November 17, 2006] - Added a typecast in png_zalloc(). - -Version 1.4.0beta17 [December 4, 2006] - Changed "new_key[79] = '\0';" to "(*new_key)[79] = '\0';" in pngwutil.c - Add "png_bytep" typecast to profile while calculating length in pngwutil.c - -Version 1.4.0beta18 [December 7, 2006] - Added scripts/CMakeLists.txt - -Version 1.4.0beta19 [May 16, 2007] - Revised scripts/CMakeLists.txt - Rebuilt configure and Makefile.in with newer tools. - Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers. - Added scripts/makefile.nommx - -Version 1.4.0beta20 [July 9, 2008] - Moved several PNG_HAVE_* macros from pngpriv.h to png.h because applications - calling set_unknown_chunk_location() need them. - Moved several macro definitions from pngpriv.h to pngconf.h - Merge with changes to the 1.2.X branch, as of 1.2.30beta04. - Deleted all use of the MMX assembler code and Intel-licensed optimizations. - Revised makefile.mingw - -Version 1.4.0beta21 [July 21, 2008] - Moved local array "chunkdata" from pngrutil.c to the png_struct, so - it will be freed by png_read_destroy() in case of a read error (Kurt - Christensen). - -Version 1.4.0beta22 [July 21, 2008] - Change "purpose" and "buffer" to png_ptr->chunkdata to avoid memory leaking. - -Version 1.4.0beta23 [July 22, 2008] - Change "chunkdata = NULL" to "png_ptr->chunkdata = NULL" several places in - png_decompress_chunk(). - -Version 1.4.0beta24 [July 25, 2008] - Change all remaining "chunkdata" to "png_ptr->chunkdata" in - png_decompress_chunk(), and remove "chunkdata" from parameter list. - Put a call to png_check_chunk_name() in png_read_chunk_header(). - Revised png_check_chunk_name() to reject a name with a lowercase 3rd byte. - Removed two calls to png_check_chunk_name() occuring later in the process. - Define PNG_NO_ERROR_NUMBERS by default in pngconf.h - -Version 1.4.0beta25 [July 30, 2008] - Added a call to png_check_chunk_name() in pngpread.c - Reverted png_check_chunk_name() to accept a name with a lowercase 3rd byte. - Added png_push_have_buffer() function to pngpread.c - Eliminated PNG_BIG_ENDIAN_SUPPORTED and associated png_get_* macros. - Made inline expansion of png_get_*() optional with PNG_USE_READ_MACROS. - Eliminated all PNG_USELESS_TESTS and PNG_CORRECT_PALETTE_SUPPORTED code. - Synced contrib directory and configure files with libpng-1.2.30beta06. - Eliminated no-longer-used pngdefs.h (but it's still built in the makefiles) - Relocated a misplaced "#endif /* PNG_NO_WRITE_FILTER */" in pngwutil.c - -Version 1.4.0beta26 [August 4, 2008] - Removed png_push_have_buffer() function in pngpread.c. It increased the - compiled library size slightly. - Changed "-Wall" to "-W -Wall" in the CFLAGS in all makefiles (Cosmin Truta) - Declared png_ptr "volatile" in pngread.c and pngwrite.c to avoid warnings. - Updated contrib/visupng/cexcept.h to version 2.0.1 - Added PNG_LITERAL_CHARACTER macros for #, [, and ]. - -Version 1.4.0beta27 [August 5, 2008] - Revised usage of PNG_LITERAL_SHARP in pngerror.c. - Moved newline character from individual png_debug messages into the - png_debug macros. - Allow user to #define their own png_debug, png_debug1, and png_debug2. - -Version 1.4.0beta28 [August 5, 2008] - Revised usage of PNG_LITERAL_SHARP in pngerror.c. - Added PNG_STRING_NEWLINE macro - -Version 1.4.0beta29 [August 9, 2008] - Revised usage of PNG_STRING_NEWLINE to work on non-ISO compilers. - Added PNG_STRING_COPYRIGHT macro. - Added non-ISO versions of png_debug macros. - -Version 1.4.0beta30 [August 14, 2008] - Added premultiplied alpha feature (Volker Wiendl). - -Version 1.4.0beta31 [August 18, 2008] - Moved png_set_premultiply_alpha from pngtrans.c to pngrtran.c - Removed extra crc check at the end of png_handle_cHRM(). Bug introduced - in libpng-1.4.0beta20. - -Version 1.4.0beta32 [August 19, 2008] - Added PNG_WRITE_FLUSH_SUPPORTED block around new png_flush() call. - Revised PNG_NO_STDIO version of png_write_flush() - -Version 1.4.0beta33 [August 20, 2008] - Added png_get|set_chunk_cache_max() to limit the total number of sPLT, - text, and unknown chunks that can be stored. - -Version 1.4.0beta34 [September 6, 2008] - Shortened tIME_string to 29 bytes in pngtest.c - Fixed off-by-one error introduced in png_push_read_zTXt() function in - libpng-1.2.30beta04/pngpread.c (Harald van Dijk) - -Version 1.4.0beta35 [October 6, 2008] - Changed "trans_values" to "trans_color". - Changed so-number from 0 to 14. Some OS do not like 0. - Revised makefile.darwin to fix shared library numbering. - Change png_set_gray_1_2_4_to_8() to png_set_expand_gray_1_2_4_to_8() - in example.c (debian bug report) - -Version 1.4.0beta36 [October 25, 2008] - Sync with tEXt vulnerability fix in libpng-1.2.33rc02. - -Version 1.4.0beta37 [November 13, 2008] - Added png_check_cHRM in png.c and moved checking from pngget.c, pngrutil.c, - and pngwrite.c - -Version 1.4.0beta38 [November 22, 2008] - Added check for zero-area RGB cHRM triangle in png_check_cHRM() and - png_check_cHRM_fixed(). - -Version 1.4.0beta39 [November 23, 2008] - Revised png_warning() to write its message on standard output by default - when warning_fn is NULL. - -Version 1.4.0beta40 [November 24, 2008] - Eliminated png_check_cHRM(). Instead, always use png_check_cHRM_fixed(). - In png_check_cHRM_fixed(), ensure white_y is > 0, and removed redundant - check for all-zero coordinates that is detected by the triangle check. - -Version 1.4.0beta41 [November 26, 2008] - Fixed string vs pointer-to-string error in png_check_keyword(). - Rearranged test expressions in png_check_cHRM_fixed() to avoid internal - overflows. - Added PNG_NO_CHECK_cHRM conditional. - -Version 1.4.0beta42, 43 [December 1, 2008] - Merge png_debug with version 1.2.34beta04. - -Version 1.4.0beta44 [December 6, 2008] - Removed redundant check for key==NULL before calling png_check_keyword() - to ensure that new_key gets initialized and removed extra warning - (Merge with version 1.2.34beta05 -- Arvan Pritchard). - -Version 1.4.0beta45 [December 9, 2008] - In png_write_png(), respect the placement of the filler bytes in an earlier - call to png_set_filler() (Jim Barry). - -Version 1.4.0beta46 [December 10, 2008] - Undid previous change and added PNG_TRANSFORM_STRIP_FILLER_BEFORE and - PNG_TRANSFORM_STRIP_FILLER_AFTER conditionals and deprecated - PNG_TRANSFORM_STRIP_FILLER (Jim Barry). - -Version 1.4.0beta47 [December 15, 2008] - Support for dithering was disabled by default, because it has never - been well tested and doesn't work very well. The code has not - been removed, however, and can be enabled by building libpng with - PNG_READ_DITHER_SUPPORTED defined. - -Version 1.4.0beta48 [February 14, 2009] - Added new exported function png_calloc(). - Combined several instances of png_malloc(); png_memset() into png_calloc(). - Removed prototype for png_freeptr() that was added in libpng-1.4.0beta24 - but was never defined. - -Version 1.4.0beta49 [February 28, 2009] - Added png_fileno() macro to pngconf.h, used in pngwio.c - Corrected order of #ifdef's in png_debug definition in png.h - Fixed bug introduced in libpng-1.4.0beta48 with the memset arguments - for pcal_params. - Fixed order of #ifdef directives in the png_debug defines in png.h - (bug introduced in libpng-1.2.34/1.4.0beta29). - Revised comments in png_set_read_fn() and png_set_write_fn(). - -Version 1.4.0beta50 [March 18, 2009] - Use png_calloc() instead of png_malloc() to allocate big_row_buf when - reading an interlaced file, to avoid a possible UMR. - Undid revision of PNG_NO_STDIO version of png_write_flush(). Users - having trouble with fflush() can build with PNG_NO_WRITE_FLUSH defined - or supply their own flush_fn() replacement. - Revised libpng*.txt and png.h documentation about use of png_write_flush() - and png_set_write_fn(). - Removed fflush() from pngtest.c. - Added "#define PNG_NO_WRITE_FLUSH" to contrib/pngminim/encoder/pngusr.h - -Version 1.4.0beta51 [March 21, 2009] - Removed new png_fileno() macro from pngconf.h . - -Version 1.4.0beta52 [March 27, 2009] - Relocated png_do_chop() ahead of building gamma tables in pngrtran.c - This avoids building 16-bit gamma tables unnecessarily. - Removed fflush() from pngtest.c. - Added "#define PNG_NO_WRITE_FLUSH" to contrib/pngminim/encoder/pngusr.h - Added a section on differences between 1.0.x and 1.2.x to libpng.3/libpng.txt - -Version 1.4.0beta53 [April 1, 2009] - Removed some remaining MMX macros from pngpriv.h - Fixed potential memory leak of "new_name" in png_write_iCCP() (Ralph Giles) - -Version 1.4.0beta54 [April 13, 2009] - Added "ifndef PNG_SKIP_SETJMP_CHECK" block in pngconf.h to allow - application code writers to bypass the check for multiple inclusion - of setjmp.h when they know that it is safe to ignore the situation. - Eliminated internal use of setjmp() in pngread.c and pngwrite.c - Reordered ancillary chunks in pngtest.png to be the same as what - pngtest now produces, and made some cosmetic changes to pngtest output. - Eliminated deprecated png_read_init_3() and png_write_init_3() functions. - -Version 1.4.0beta55 [April 15, 2009] - Simplified error handling in pngread.c and pngwrite.c by putting - the new png_read_cleanup() and png_write_cleanup() functions inline. - -Version 1.4.0beta56 [April 25, 2009] - Renamed "user_chunk_data" to "my_user_chunk_data" in pngtest.c to suppress - "shadowed declaration" warning from gcc-4.3.3. - Renamed "gamma" to "png_gamma" in pngset.c to avoid "shadowed declaration" - warning about a global "gamma" variable in math.h on some platforms. - -Version 1.4.0beta57 [May 2, 2009] - Removed prototype for png_freeptr() that was added in libpng-1.4.0beta24 - but was never defined (again). - Rebuilt configure scripts with autoconf-2.63 instead of 2.62 - Removed pngprefs.h and MMX from makefiles - -Version 1.4.0beta58 [May 14, 2009] - Changed pngw32.def to pngwin.def in makefile.mingw (typo was introduced - in beta57). - Clarified usage of sig_bit versus sig_bit_p in example.c (Vincent Torri) - -Version 1.4.0beta59 [May 15, 2009] - Reformated sources in libpng style (3-space intentation, comment format) - Fixed typo in libpng docs (PNG_FILTER_AVE should be PNG_FILTER_AVG) - Added sections about the git repository and our coding style to the - documentation - Relocated misplaced #endif in pngwrite.c, sCAL chunk handler. - -Version 1.4.0beta60 [May 19, 2009] - Conditionally compile png_read_finish_row() which is not used by - progressive readers. - Added contrib/pngminim/preader to demonstrate building minimal progressive - decoder, based on contrib/gregbook with embedded libpng and zlib. - -Version 1.4.0beta61 [May 20, 2009] - In contrib/pngminim/*, renamed "makefile.std" to "makefile", since there - is only one makefile in those directories, and revised the README files - accordingly. - More reformatting of comments, mostly to capitalize sentences. - -Version 1.4.0beta62 [June 2, 2009] - Added "#define PNG_NO_WRITE_SWAP" to contrib/pngminim/encoder/pngusr.h - and "define PNG_NO_READ_SWAP" to decoder/pngusr.h and preader/pngusr.h - Reformatted several remaining "else statement" into two lines. - Added a section to the libpng documentation about using png_get_io_ptr() - in configure scripts to detect the presence of libpng. - -Version 1.4.0beta63 [June 15, 2009] - Revised libpng*.txt and libpng.3 to mention calling png_set_IHDR() - multiple times and to specify the sample order in the tRNS chunk, - because the ISO PNG specification has a typo in the tRNS table. - Changed several PNG_UNKNOWN_CHUNK_SUPPORTED to - PNG_HANDLE_AS_UNKNOWN_SUPPORTED, to make the png_set_keep mechanism - available for ignoring known chunks even when not saving unknown chunks. - Adopted preference for consistent use of "#ifdef" and "#ifndef" versus - "#if defined()" and "if !defined()" where possible. - -Version 1.4.0beta64 [June 24, 2009] - Eliminated PNG_LEGACY_SUPPORTED code. - Moved the various unknown chunk macro definitions outside of the - PNG_READ|WRITE_ANCILLARY_CHUNK_SUPPORTED blocks. - -Version 1.4.0beta65 [June 26, 2009] - Added a reference to the libpng license in each file. - -Version 1.4.0beta66 [June 27, 2009] - Refer to the libpng license instead of the libpng license in each file. - -Version 1.4.0beta67 [July 6, 2009] - Relocated INVERT_ALPHA within png_read_png() and png_write_png(). - Added high-level API transform PNG_TRANSFORM_GRAY_TO_RGB. - Added an "xcode" project to the projects directory (Alam Arias). - -Version 1.4.0beta68 [July 19, 2009] - Avoid some tests in filter selection in pngwutil.c - -Version 1.4.0beta69 [July 25, 2009] - Simplified the new filter-selection test. This runs faster in the - common "PNG_ALL_FILTERS" and PNG_FILTER_NONE cases. - Removed extraneous declaration from the new call to png_read_gray_to_rgb() - (bug introduced in libpng-1.4.0beta67). - Fixed up xcode project (Alam Arias) - Added a prototype for png_64bit_product() in png.c - -Version 1.4.0beta70 [July 27, 2009] - Avoid a possible NULL dereference in debug build, in png_set_text_2(). - (bug introduced in libpng-0.95, discovered by Evan Rouault) - -Version 1.4.0beta71 [July 29, 2009] - Rebuilt configure scripts with autoconf-2.64. - -Version 1.4.0beta72 [August 1, 2009] - Replaced *.tar.lzma with *.tar.xz in distribution. Get the xz codec - from . - -Version 1.4.0beta73 [August 1, 2009] - Reject attempt to write iCCP chunk with negative embedded profile length - (JD Chen) (CVE-2009-5063). - -Version 1.4.0beta74 [August 8, 2009] - Changed png_ptr and info_ptr member "trans" to "trans_alpha". - -Version 1.4.0beta75 [August 21, 2009] - Removed an extra png_debug() recently added to png_write_find_filter(). - Fixed incorrect #ifdef in pngset.c regarding unknown chunk support. - -Version 1.4.0beta76 [August 22, 2009] - Moved an incorrectly located test in png_read_row() in pngread.c - -Version 1.4.0beta77 [August 27, 2009] - Removed lpXYZ.tar.bz2 (with CRLF), KNOWNBUG, libpng-x.y.z-KNOWNBUG.txt, - and the "noconfig" files from the distribution. - Moved CMakeLists.txt from scripts into the main libpng directory. - Various bugfixes and improvements to CMakeLists.txt (Philip Lowman) - -Version 1.4.0beta78 [August 31, 2009] - Converted all PNG_NO_* tests to PNG_*_SUPPORTED everywhere except pngconf.h - Eliminated PNG_NO_FREE_ME and PNG_FREE_ME_SUPPORTED macros. - Use png_malloc plus a loop instead of png_calloc() to initialize - row_pointers in png_read_png(). - -Version 1.4.0beta79 [September 1, 2009] - Eliminated PNG_GLOBAL_ARRAYS and PNG_LOCAL_ARRAYS; always use local arrays. - Eliminated PNG_CALLOC_SUPPORTED macro and always provide png_calloc(). - -Version 1.4.0beta80 [September 17, 2009] - Removed scripts/libpng.icc - Changed typecast of filler from png_byte to png_uint_16 in png_set_filler(). - (Dennis Gustafsson) - Fixed typo introduced in beta78 in pngtest.c ("#if def " should be "#ifdef ") - -Version 1.4.0beta81 [September 23, 2009] - Eliminated unused PNG_FLAG_FREE_* defines from pngpriv.h - Expanded TAB characters in pngrtran.c - Removed PNG_CONST from all "PNG_CONST PNG_CHNK" declarations to avoid - compiler complaints about doubly declaring things "const". - Changed all "#if [!]defined(X)" to "if[n]def X" where possible. - Eliminated unused png_ptr->row_buf_size - -Version 1.4.0beta82 [September 25, 2009] - Moved redundant IHDR checking into new png_check_IHDR() in png.c - and report all errors found in the IHDR data. - Eliminated useless call to png_check_cHRM() from pngset.c - -Version 1.4.0beta83 [September 25, 2009] - Revised png_check_IHDR() to eliminate bogus complaint about filter_type. - -Version 1.4.0beta84 [September 30, 2009] - Fixed some inconsistent indentation in pngconf.h - Revised png_check_IHDR() to add a test for width variable less than 32-bit. - -Version 1.4.0beta85 [October 1, 2009] - Revised png_check_IHDR() again, to check info_ptr members instead of - the contents of the returned parameters. - -Version 1.4.0beta86 [October 9, 2009] - Updated the "xcode" project (Alam Arias). - Eliminated a shadowed declaration of "pp" in png_handle_sPLT(). - -Version 1.4.0rc01 [October 19, 2009] - Trivial cosmetic changes. - -Version 1.4.0beta87 [October 30, 2009] - Moved version 1.4.0 back into beta. - -Version 1.4.0beta88 [October 30, 2009] - Revised libpng*.txt section about differences between 1.2.x and 1.4.0 - because most of the new features have now been ported back to 1.2.41 - -Version 1.4.0beta89 [November 1, 2009] - More bugfixes and improvements to CMakeLists.txt (Philip Lowman) - Removed a harmless extra png_set_invert_alpha() from pngwrite.c - Apply png_user_chunk_cache_max within png_decompress_chunk(). - Merged libpng-1.2.41.txt with libpng-1.4.0.txt where appropriate. - -Version 1.4.0beta90 [November 2, 2009] - Removed all remaining WIN32_WCE #ifdefs except those involving the - time.h "tm" structure - -Version 1.4.0beta91 [November 3, 2009] - Updated scripts/pngw32.def and projects/wince/png32ce.def - Copied projects/wince/png32ce.def to the scripts directory. - Added scripts/makefile.wce - Patched ltmain.sh for wince support. - Added PNG_CONVERT_tIME_SUPPORTED macro. - -Version 1.4.0beta92 [November 4, 2009] - Make inclusion of time.h in pngconf.h depend on PNG_CONVERT_tIME_SUPPORTED - Make #define PNG_CONVERT_tIME_SUPPORTED depend on PNG_WRITE_tIME_SUPPORTED - Revised libpng*.txt to describe differences from 1.2.40 to 1.4.0 (instead - of differences from 1.2.41 to 1.4.0) - -Version 1.4.0beta93 [November 7, 2009] - Added PNG_DEPSTRUCT, PNG_DEPRECATED, PNG_USE_RESULT, PNG_NORETURN, and - PNG_ALLOCATED macros to detect deprecated direct access to the - png_struct or info_struct members and other deprecated usage in - applications (John Bowler). - Updated scripts/makefile* to add "-DPNG_CONFIGURE_LIBPNG" to CFLAGS, - to prevent warnings about direct access to png structs by libpng - functions while building libpng. They need to be tested, especially - those using compilers other than gcc. - Updated projects/visualc6 and visualc71 with "/d PNG_CONFIGURE_LIBPNG". - They should work but still need to be updated to remove - references to pnggccrd.c or pngvcrd.c and ASM building. - Added README.txt to the beos, cbuilder5, netware, and xcode projects warning - that they need to be updated, to remove references to pnggccrd.c and - pngvcrd.c and to depend on pngpriv.h - Removed three direct references to read_info_ptr members in pngtest.c - that were detected by the new PNG_DEPSTRUCT macro. - Moved the png_debug macro definitions and the png_read_destroy(), - png_write_destroy() and png_far_to_near() prototypes from png.h - to pngpriv.h (John Bowler) - Moved the synopsis lines for png_read_destroy(), png_write_destroy() - png_debug(), png_debug1(), and png_debug2() from libpng.3 to libpngpf.3. - -Version 1.4.0beta94 [November 9, 2009] - Removed the obsolete, unused pnggccrd.c and pngvcrd.c files. - Updated CMakeLists.txt to add "-DPNG_CONFIGURE_LIBPNG" to the definitions. - Removed dependency of pngtest.o on pngpriv.h in the makefiles. - Only #define PNG_DEPSTRUCT, etc. in pngconf.h if not already defined. - -Version 1.4.0beta95 [November 10, 2009] - Changed png_check_sig() to !png_sig_cmp() in contrib programs. - Added -DPNG_CONFIGURE_LIBPNG to contrib/pngminm/*/makefile - Changed png_check_sig() to !png_sig_cmp() in contrib programs. - Corrected the png_get_IHDR() call in contrib/gregbook/readpng2.c - Changed pngminim/*/gather.sh to stop trying to remove pnggccrd.c and pngvcrd.c - Added dependency on pngpriv.h in contrib/pngminim/*/makefile - -Version 1.4.0beta96 [November 12, 2009] - Renamed scripts/makefile.wce to scripts/makefile.cegcc - Revised Makefile.am to use libpng.sys while building libpng.so - so that only PNG_EXPORT functions are exported. - Removed the deprecated png_check_sig() function/macro. - Removed recently removed function names from scripts/*.def - Revised pngtest.png to put chunks in the same order written by pngtest - (evidently the same change made in libpng-1.0beta54 was lost). - Added PNG_PRIVATE macro definition in pngconf.h for possible future use. - -Version 1.4.0beta97 [November 13, 2009] - Restored pngtest.png to the libpng-1.4.0beta7 version. - Removed projects/beos and netware.txt; no one seems to be supporting them. - Revised Makefile.in - -Version 1.4.0beta98 [November 13, 2009] - Added the "xcode" project to zip distributions, - Fixed a typo in scripts/pngwin.def introduced in beta97. - -Version 1.4.0beta99 [November 14, 2009] - Moved libpng-config.in and libpng.pc-configure.in out of the scripts - directory, to libpng-config.in and libpng-pc.in, respectively, and - modified Makefile.am and configure.ac accordingly. Now "configure" - needs nothing from the "scripts" directory. - Avoid redefining PNG_CONST in pngconf.h - -Version 1.4.0beta100 [November 14, 2009] - Removed ASM builds from projects/visualc6 and projects/visualc71 - Removed scripts/makefile.nommx and makefile.vcawin32 - Revised CMakeLists.txt to account for new location of libpng-config.in - and libpng-pc.in - Updated INSTALL to reflect removal and relocation of files. - -Version 1.4.0beta101 [November 14, 2009] - Restored the binary files (*.jpg, *.png, some project files) that were - accidentally deleted from the zip and 7z distributions when the xcode - project was added. - -Version 1.4.0beta102 [November 18, 2009] - Added libpng-config.in and libpng-pc.in to the zip and 7z distributions. - Fixed a typo in projects/visualc6/pngtest.dsp, introduced in beta100. - Moved descriptions of makefiles and other scripts out of INSTALL into - scripts/README.txt - Updated the copyright year in scripts/pngwin.rc from 2006 to 2009. - -Version 1.4.0beta103 [November 21, 2009] - Removed obsolete comments about ASM from projects/visualc71/README_zlib.txt - Align row_buf on 16-byte boundary in memory. - Restored the PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED guard around the call - to png_flush() after png_write_IEND(). See 1.4.0beta32, 1.4.0beta50 - changes above and 1.2.30, 1.2.30rc01 and rc03 in 1.2.41 CHANGES. Someone - needs this feature. - Make the 'png_jmpbuf' macro expand to a call that records the correct - longjmp function as well as returning a pointer to the setjmp - jmp_buf buffer, and marked direct access to jmpbuf 'deprecated'. - (John Bowler) - -Version 1.4.0beta104 [November 22, 2009] - Removed png_longjmp_ptr from scripts/*.def and libpng.3 - Rebuilt configure scripts with autoconf-2.65 - -Version 1.4.0beta105 [November 25, 2009] - Use fast integer PNG_DIVIDE_BY_255() or PNG_DIVIDE_BY_65535() - to accomplish alpha premultiplication when - PNG_READ_COMPOSITE_NODIV_SUPPORTED is defined. - Changed "/255" to "/255.0" in background calculations to make it clear - that the 255 is used as a double. - -Version 1.4.0beta106 [November 27, 2009] - Removed premultiplied alpha feature. - -Version 1.4.0beta107 [December 4, 2009] - Updated README - Added "#define PNG_NO_PEDANTIC_WARNINGS" in the libpng source files. - Removed "-DPNG_CONFIGURE_LIBPNG" from the makefiles and projects. - Revised scripts/makefile.netbsd, makefile.openbsd, and makefile.sco - to put png.h and pngconf.h in $prefix/include, like the other scripts, - instead of in $prefix/include/libpng. Also revised makefile.sco - to put them in $prefix/include/libpng15 instead of in - $prefix/include/libpng/libpng15. - -Version 1.4.0beta108 [December 11, 2009] - Removed leftover "-DPNG_CONFIGURE_LIBPNG" from contrib/pngminim/*/makefile - Relocated png_do_chop() to its original position in pngrtran.c; the - change in version 1.2.41beta08 caused transparency to be handled wrong - in some 16-bit datastreams (Yusaku Sugai). - -Version 1.4.0beta109 [December 13, 2009] - Added "bit_depth" parameter to the private png_build_gamma_table() function. - Pass bit_depth=8 to png_build_gamma_table() when bit_depth is 16 but the - PNG_16_TO_8 transform has been set, to avoid unnecessary build of 16-bit - tables. - -Version 1.4.0rc02 [December 20, 2009] - Declared png_cleanup_needed "volatile" in pngread.c and pngwrite.c - -Version 1.4.0rc03 [December 22, 2009] - Renamed libpng-pc.in back to libpng.pc.in and revised CMakeLists.txt - (revising the change in 1.4.0beta99) - -Version 1.4.0rc04 [December 25, 2009] - Swapped PNG_UNKNOWN_CHUNKS_SUPPORTED and PNG_HANDLE_AS_UNKNOWN_SUPPORTED - in pngset.c to be consistent with other changes in version 1.2.38. - -Version 1.4.0rc05 [December 25, 2009] - Changed "libpng-pc.in" to "libpng.pc.in" in configure.ac, configure, and - Makefile.in to be consistent with changes in libpng-1.4.0rc03 - -Version 1.4.0rc06 [December 29, 2009] - Reverted the gamma_table changes from libpng-1.4.0beta109. - Fixed some indentation errors. - -Version 1.4.0rc07 [January 1, 2010] - Revised libpng*.txt and libpng.3 about 1.2.x->1.4.x differences. - Use png_calloc() instead of png_malloc(); png_memset() in pngrutil.c - Update copyright year to 2010. - -Version 1.4.0rc08 [January 2, 2010] - Avoid deprecated references to png_ptr-io_ptr and png_ptr->error_ptr - in pngtest.c - -Version 1.4.0 [January 3, 2010] - No changes. - -Version 1.4.1beta01 [January 8, 2010] - Updated CMakeLists.txt for consistent indentation and to avoid an - unclosed if-statement warning (Philip Lowman). - Revised Makefile.am and Makefile.in to remove references to Y2KINFO, - KNOWNBUG, and libpng.la (Robert Schwebel). - Revised the makefiles to install the same files and symbolic - links as configure, except for libpng.la and libpng14.la. - Make png_set|get_compression_buffer_size() available even when - PNG_WRITE_SUPPORTED is not enabled. - Revised Makefile.am and Makefile.in to simplify their maintenance. - Revised scripts/makefile.linux to install a link to libpng14.so.14.1 - -Version 1.4.1beta02 [January 9, 2010] - Revised the rest of the makefiles to install a link to libpng14.so.14.1 - -Version 1.4.1beta03 [January 10, 2010] - Removed png_set_premultiply_alpha() from scripts/*.def - -Version 1.4.1rc01 [January 16, 2010] - No changes. - -Version 1.4.1beta04 [January 23, 2010] - Revised png_decompress_chunk() to improve speed and memory usage when - decoding large chunks. - Added png_set|get_chunk_malloc_max() functions. - -Version 1.4.1beta05 [January 26, 2010] - Relocated "int k" declaration in pngtest.c to minimize its scope. - -Version 1.4.1beta06 [January 28, 2010] - Revised png_decompress_chunk() to use a two-pass method suggested by - John Bowler. - -Version 1.4.1beta07 [February 6, 2010] - Folded some long lines in the source files. - Added defineable PNG_USER_CHUNK_CACHE_MAX, PNG_USER_CHUNK_MALLOC_MAX, - and a PNG_USER_LIMITS_SUPPORTED flag. - Eliminated use of png_ptr->irowbytes and reused the slot in png_ptr as - png_ptr->png_user_chunk_malloc_max. - Revised png_push_save_buffer() to do fewer but larger png_malloc() calls. - -Version 1.4.1beta08 [February 6, 2010] - Minor cleanup and updating of dates and copyright year. - -Version 1.5.0beta01 [February 7, 2010] - Moved declaration of png_struct into private pngstruct.h and png_info - into pnginfo.h - -Version 1.4.1beta09 and 1.5.0beta02 [February 7, 2010] - Reverted to original png_push_save_buffer() code. - -Version 1.4.1beta10 and 1.5.0beta03 [February 8, 2010] - Return allocated "old_buffer" in png_push_save_buffer() before - calling png_error(), to avoid a potential memory leak. - Updated configure script to use SO number 15. - -Version 1.5.0beta04 [February 9, 2010] - Removed malformed "incomplete struct declaration" of png_info from png.h - -Version 1.5.0beta05 [February 12, 2010] - Removed PNG_DEPSTRUCT markup in pngstruct.h and pnginfo.h, and undid the - linewrapping that it entailed. - Revised comments in pngstruct.h and pnginfo.h and added pointers to - the libpng license. - Changed PNG_INTERNAL to PNG_EXPOSE_INTERNAL_STRUCTURES - Removed the cbuilder5 project, which has not been updated to 1.4.0. - -Version 1.4.1beta12 and 1.5.0beta06 [February 14, 2010] - Fixed type declaration of png_get_chunk_malloc_max() in pngget.c (Daisuke - Nishikawa) - -Version 1.5.0beta07 [omitted] - -Version 1.5.0beta08 [February 19, 2010] - Changed #ifdef PNG_NO_STDIO_SUPPORTED to #ifdef PNG_NO_CONSOLE_IO_SUPPORTED - wherever png_snprintf() is used to construct error and warning messages. - Noted in scripts/makefile.mingw that it expects to be run under MSYS. - Removed obsolete unused MMX-querying support from contrib/gregbook - Added exported png_longjmp() function. - Removed the AIX redefinition of jmpbuf in png.h - Added -D_ALLSOURCE in configure.ac, makefile.aix, and CMakeLists.txt - when building on AIX. - -Version 1.5.0beta09 [February 19, 2010] - Removed -D_ALLSOURCE from configure.ac, makefile.aix, and CMakeLists.txt. - Changed the name of png_ptr->jmpbuf to png_ptr->png_jmpbuf in pngstruct.h - -Version 1.5.0beta10 [February 25, 2010] - Removed unused gzio.c from contrib/pngminim gather and makefile scripts - Removed replacement error handlers from contrib/gregbook. Because of - the new png_longjmp() function they are no longer needed. - -Version 1.5.0beta11 [March 6, 2010] - Removed checking for already-included setjmp.h from pngconf.h - Fixed inconsistent indentations and made numerous cosmetic changes. - Revised the "SEE ALSO" style of libpng.3, libpngpf.3, and png.5 - -Version 1.5.0beta12 [March 9, 2010] - Moved "#include png.h" inside pngpriv.h and removed "#include png.h" from - the source files, along with "#define PNG_EXPOSE_INTERNAL_STRUCTURES" - and "#define PNG_NO_PEDANTIC_WARNINGS" (John Bowler). - Created new pngdebug.h and moved debug definitions there. - -Version 1.5.0beta13 [March 10, 2010] - Protect pngstruct.h, pnginfo.h, and pngdebug.h from being included twice. - Revise the "#ifdef" blocks in png_inflate() so it will compile when neither - PNG_USER_CHUNK_MALLOC_MAX nor PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED - is defined. - Removed unused png_measure_compressed_chunk() from pngpriv.h and libpngpf.3 - Moved the 'config.h' support from pngconf.h to pngpriv.h - Removed PNGAPI from the png_longjmp_ptr typedef. - Eliminated dependence of pngtest.c on the private pngdebug.h file. - Make all png_debug macros into *unterminated* statements or - expressions (i.e. a trailing ';' must always be added) and correct - the format statements in various png_debug messages. - -Version 1.5.0beta14 [March 14, 2010] - Removed direct access to png_ptr->io_ptr from the Windows code in pngtest.c - Revised Makefile.am to account for recent additions and replacements. - Corrected CE and OS/2 DEF files (scripts/png*def) for symbols removed and - added ordinal numbers to the Windows DEF file and corrected the duplicated - ordinal numbers on CE symbols that are commented out. - Added back in export symbols that can be present in the Windows build but - are disabled by default. - PNG_EXPORT changed to include an 'ordinal' field for DEF file generation. - PNG_CALLBACK added to make callback definitions uniform. PNGAPI split - into PNGCAPI (base C form), PNGAPI (exports) and PNGCBAPI (callbacks), - and appropriate changes made to all files. Cygwin builds re-hinged to - allow procedure call standard changes and to remove the need for the DEF - file (fixes build on Cygwin). - Enabled 'attribute' warnings that are relevant to library APIs and callbacks. - Changed rules for generation of the various symbol files and added a new - rule for a DEF file (which is also added to the distribution). - Updated the symbol file generation to stop it adding spurious spaces - to EOL (coming from preprocessor macro expansion). Added a facility - to join tokens in the output and rewrite *.dfn to use this. - Eliminated scripts/*.def in favor of libpng.def; updated projects/visualc71 - and removed scripts/makefile.cygwin. - Made PNG_BUILD_DLL safe: it can be set whenever a DLL is being built. - Removed the include of sys/types.h - apparently unnecessary now on the - platforms on which it happened (all but Mac OS and RISC OS). - Moved the Mac OS test into pngpriv.h (the only place it is used.) - -Version 1.5.0beta15 [March 17, 2010] - Added symbols.chk target to Makefile.am to validate the symbols in png.h - against the new DEF file scripts/symbols.def. - Changed the default DEF file back to pngwin.def. - Removed makefile.mingw. - Eliminated PNG_NO_EXTERN and PNG_ALL_EXTERN - -Version 1.5.0beta16 [April 1, 2010] - Make png_text_struct independent of PNG_iTXt_SUPPORTED, so that - fields are initialized in all configurations. The READ/WRITE - macros (PNG_(READ|WRITE)_iTXt_SUPPORTED) still function as - before to disable code to actually read or write iTXt chunks - and iTXt_SUPPORTED can be used to detect presence of either - read or write support (but it is probably better to check for - the one actually required - read or write.) - Combined multiple png_warning() calls for a single error. - Restored the macro definition of png_check_sig(). - -Version 1.5.0beta17 [April 17, 2010] - Added some "(long)" typecasts to printf calls in png_handle_cHRM(). - Documented the fact that png_set_dither() was disabled since libpng-1.4.0. - Reenabled png_set_dither() but renamed it to png_set_quantize() to reflect - more accurately what it actually does. At the same time, renamed - the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros to - PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS. - Added some "(long)" typecasts to printf calls in png_handle_cHRM(). - Freeze build-time only configuration in the build. - In all prior versions of libpng most configuration options - controlled by compiler #defines had to be repeated by the - application code that used libpng. This patch changes this - so that compilation options that can only be changed at build - time are frozen in the build. Options that are compiler - dependent (and those that are system dependent) are evaluated - each time - pngconf.h holds these. Options that can be changed - per-file in the application are in png.h. Frozen options are - in the new installed header file pnglibconf.h (John Bowler) - Removed the xcode project because it has not been updated to work - with libpng-1.5.0. - Removed the ability to include optional pngusr.h - -Version 1.5.0beta18 [April 17, 2010] - Restored the ability to include optional pngusr.h - Moved replacements for png_error() and png_warning() from the - contrib/pngminim project to pngerror.c, for use when warnings or - errors are disabled via PNG_NO_WARN or PNG_NO_ERROR_TEXT, to avoid - storing unneeded error/warning text. - Updated contrib/pngminim project to work with the new pnglibconf.h - Added some PNG_NO_* defines to contrib/pngminim/*/pngusr.h to save space. - -Version 1.5.0beta19 [April 24, 2010] - Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the functions - to read and write ints to be disabled independently of PNG_USE_READ_MACROS, - which allows libpng to be built with the functions even though the default - is to use the macros - this allows applications to choose at app build - time whether or not to use macros (previously impossible because the - functions weren't in the default build.) - Changed Windows calling convention back to __cdecl for API functions. - For Windows/x86 platforms only: - __stdcall is no longer needed for Visual Basic, so libpng-1.5.0 uses - __cdecl throughout (both API functions and callbacks) on Windows/x86 - platforms. - Replaced visualc6 and visualc71 projects with new vstudio project - Relaxed the overly-restrictive permissions of some files. - -Version 1.5.0beta20 [April 24, 2010] - Relaxed more overly-restrictive permissions of some files. - -Version 1.5.0beta21 [April 27, 2010] - Removed some unwanted binary bytes and changed CRLF to NEWLINE in the new - vstudio project files, and some trivial editing of some files in the - scripts directory. - Set PNG_NO_READ_BGR, PNG_NO_IO_STATE, and PNG_NO_TIME_RFC1123 in - contrib/pngminim/decoder/pngusr.h to make a smaller decoder application. - -Version 1.5.0beta22 [April 28, 2010] - Fixed dependencies of GET_INT_32 - it does not require READ_INT_FUNCTIONS - because it has a macro equivalent. - Improved the options.awk script; added an "everything off" option. - Revised contrib/pngminim to use the "everything off" option in pngusr.dfa. - -Version 1.5.0beta23 [April 29, 2010] - Corrected PNG_REMOVED macro to take five arguments. - The macro was documented with two arguments (name,ordinal), however - the symbol checking .dfn files assumed five arguments. The five - argument form seems more useful so it is changed to that. - Corrected PNG_UNKNOWN_CHUNKS_SUPPORTED to PNG_HANDLE_AS_UNKNOWN_SUPPORTED - in gregbook/readpng2.c - Corrected protection of png_get_user_transform_ptr. The API declaration in - png.h is removed if both READ and WRITE USER_TRANSFORM are turned off - but was left defined in pngtrans.c - Added logunsupported=1 to cause pnglibconf.h to document disabled options. - This makes the installed pnglibconf.h more readable but causes no - other change. The intention is that users of libpng will find it - easier to understand if an API they need is missing. - Include png_reset_zstream() in png.c only when PNG_READ_SUPPORTED is defined. - Removed dummy_inflate.c from contrib/pngminim/encoder - Removed contrib/pngminim/*/gather.sh; gathering is now done in the makefile. - -Version 1.5.0beta24 [May 7, 2010] - Use bitwise "&" instead of arithmetic mod in pngrutil.c calculation of the - offset of the png_ptr->rowbuf pointer into png_ptr->big_row_buf. - Added more blank lines for readability. - -Version 1.5.0beta25 [June 18, 2010] - In pngpread.c: png_push_have_row() add check for new_row > height - Removed the now-redundant check for out-of-bounds new_row from example.c - -Version 1.5.0beta26 [June 18, 2010] - In pngpread.c: png_push_process_row() add check for too many rows. - -Version 1.5.0beta27 [June 18, 2010] - Removed the check added in beta25 as it is now redundant. - -Version 1.5.0beta28 [June 20, 2010] - Rewrote png_process_IDAT_data to consistently treat extra data as warnings - and handle end conditions more cleanly. - Removed the new (beta26) check in png_push_process_row(). - -Version 1.5.0beta29 [June 21, 2010] - Revised scripts/options.awk to work on Sunos (but still doesn't work) - Added comment to options.awk and contrib/pngminim/*/makefile to try nawk. - -Version 1.5.0beta30 [June 22, 2010] - Stop memory leak when reading a malformed sCAL chunk. - -Version 1.5.0beta31 [June 26, 2010] - Revised pngpread.c patch of beta28 to avoid an endless loop. - Removed some trailing blanks. - -Version 1.5.0beta32 [June 26, 2010] - Removed leftover scripts/options.patch and scripts/options.rej - -Version 1.5.0beta33 [July 6, 3010] - Made FIXED and FLOATING options consistent in the APIs they enable and - disable. Corrected scripts/options.awk to handle both command line - options and options specified in the .dfa files. - Changed char *msg to PNG_CONST char *msg in pngrutil.c - Make png_set_sRGB_gAMA_and_cHRM set values using either the fixed or - floating point APIs, but not both. - Reversed patch to remove error handler when the jmp_buf is stored in the - main program structure, not the png_struct. - The error handler is needed because the default handler in libpng will - always use the jmp_buf in the library control structure; this is never - set. The gregbook code is a useful example because, even though it - uses setjmp/longjmp, it shows how error handling can be implemented - using control mechanisms not directly supported by libpng. The - technique will work correctly with mechanisms such as Microsoft - Structure Exceptions or C++ exceptions (compiler willing - note that gcc - does not by default support interworking of C and C++ error handling.) - Reverted changes to call png_longjmp in contrib/gregbook where it is not - appropriate. If mainprog->jmpbuf is used by setjmp, then png_longjmp - cannot be used. - Changed "extern PNG_EXPORT" to "PNG_EXPORT" in png.h (Jan Nijtmans) - Changed "extern" to "PNG_EXTERN" in pngpriv.h (except for the 'extern "C" {') - -Version 1.5.0beta34 [July 12, 2010] - Put #ifndef PNG_EXTERN, #endif around the define PNG_EXTERN in pngpriv.h - -Version 1.5.0beta35 [July 24, 2010] - Removed some newly-added TAB characters. - Added -DNO_PNG_SNPRINTF to CFLAGS in scripts/makefile.dj2 - Moved the definition of png_snprintf() outside of the enclosing - #ifdef blocks in pngconf.h - -Version 1.5.0beta36 [July 29, 2010] - Patches by John Bowler: - Fixed point APIs are now supported throughout (no missing APIs). - Internal fixed point arithmetic support exists for all internal floating - point operations. - sCAL validates the floating point strings it is passed. - Safe, albeit rudimentary, Watcom support is provided by PNG_API_RULE==2 - Two new APIs exist to get the number of passes without turning on the - PNG_INTERLACE transform and to get the number of rows in the current - pass. - A new test program, pngvalid.c, validates the gamma code. - Errors in the 16-bit gamma correction (overflows) have been corrected. - cHRM chunk testing is done consistently (previously the floating point - API bypassed it, because the test really didn't work on FP, now the test - is performed on the actual values to be stored in the PNG file so it - works in the FP case too.) - Most floating point APIs now simply call the fixed point APIs after - converting the values to the fixed point form used in the PNG file. - The standard headers no longer include zlib.h, which is currently only - required for pngstruct.h and can therefore be internal. - Revised png_get_int_32 to undo the PNG two's complement representation of - negative numbers. - -Version 1.5.0beta37 [July 30, 2010] - Added a typecast in png_get_int_32() in png.h and pngrutil.h to avoid - a compiler warning. - Replaced oFFs 0,0 with oFFs -10,20 in pngtest.png - -Version 1.5.0beta38 [July 31, 2010] - Implemented remaining "_fixed" functions. - Corrected a number of recently introduced warnings mostly resulting from - safe but uncast assignments to shorter integers. Also added a zlib - VStudio release library project because the latest zlib Official Windows - build does not include such a thing. - Revised png_get_int_16() to be similar to png_get_int_32(). - Restored projects/visualc71. - -Version 1.5.0beta39 [August 2, 2010] - VisualC/GCC warning fixes, VisualC build fixes - The changes include support for function attributes in VC in addition to - those already present in GCC - necessary because without these some - warnings are unavoidable. Fixes include signed/unsigned fixes in - pngvalid and checks with gcc -Wall -Wextra -Wunused. - VC requires function attributes on function definitions as well as - declarations, PNG_FUNCTION has been added to enable this and the - relevant function definitions changed. - -Version 1.5.0beta40 [August 6, 2010] - Correct use of _WINDOWS_ in pngconf.h - Removed png_mem_ #defines; they are no longer used. - Added the sRGB chunk to pngtest.png - -Version 1.5.0beta41 [August 11, 2010] - Added the cHRM chunk to pngtest.png - Don't try to use version-script with cygwin/mingw. - Revised contrib/gregbook to work under cygwin/mingw. - -Version 1.5.0beta42 [August 18, 2010] - Add .dll.a to the list of extensions to be symlinked by Makefile.am (Yaakov) - Made all API functions that have const arguments and constant string - literal pointers declare them (John Bowler). - -Version 1.5.0beta43 [August 20, 2010] - Removed spurious tabs, shorten long lines (no source change) - Also added scripts/chkfmt to validate the format of all the files that can - reasonably be validated (it is suggested to run "make distclean" before - checking, because some machine generated files have long lines.) - Reformatted the CHANGES file to be more consistent throughout. - Made changes to address various issues identified by GCC, mostly - signed/unsigned and shortening problems on assignment but also a few - difficult to optimize (for GCC) loops. - Fixed non-GCC fixed point builds. In png.c a declaration was misplaced - in an earlier update. Fixed to declare the auto variables at the head. - Use cexcept.h in pngvalid.c. - -Version 1.5.0beta44 [August 24, 2010] - Updated CMakeLists.txt to use CMAKE_INSTALL_LIBDIR variable; useful for - installing libpng in /usr/lib64 (Funda Wang). - Revised CMakeLists.txt to put the man pages in share/man/man* not man/man* - Revised CMakeLists.txt to make symlinks instead of copies when installing. - Changed PNG_LIB_NAME from pngNN to libpngNN in CMakeLists.txt (Philip Lowman) - Implemented memory checks within pngvalid - Reformatted/rearranged pngvalid.c to assist use of progressive reader. - Check interlaced images in pngvalid - Clarified pngusr.h comments in pnglibconf.dfa - Simplified the pngvalid error-handling code now that cexcept.h is in place. - Implemented progressive reader in pngvalid.c for standard tests - Implemented progressive read in pngvalid.c gamma tests - Turn on progressive reader in pngvalid.c by default and tidy code. - -Version 1.5.0beta45 [August 26, 2010] - Added an explicit make step to projects/vstudio for pnglibconf.h - Also corrected zlib.vcxproj into which Visual Studio had introduced - what it calls an "authoring error". The change to make pnglibconf.h - simply copies the file; in the future it may actually generate the - file from scripts/pnglibconf.dfa as the other build systems do. - Changed pngvalid to work when floating point APIs are disabled - Renamed the prebuilt scripts/pnglibconf.h to scripts/pnglibconf.h.prebuilt - Supply default values for PNG_USER_PRIVATEBUILD and PNG_USER_DLLFNAME_POSTFIX - in pngpriv.h in case the user neglected to define them in their pngusr.h - -Version 1.5.0beta46 [August 28, 2010] - Added new private header files to libpng_sources in CMakeLists.txt - Added PNG_READ_16BIT, PNG_WRITE_16BIT, and PNG_16BIT options. - Added reference to scripts/pnglibconf.h.prebuilt in the visualc71 project. - -Version 1.5.0beta47 [September 11, 2010] - Fixed a number of problems with 64-bit compilation reported by Visual - Studio 2010 (John Bowler). - -Version 1.5.0beta48 [October 4, 2010] - Updated CMakeLists.txt (Philip Lowman). - Revised autogen.sh to recognize and use $AUTOCONF, $AUTOMAKE, $AUTOHEADER, - $AUTOPOINT, $ACLOCAL and $LIBTOOLIZE - Fixed problem with symbols creation in Makefile.am which was assuming that - all versions of ccp write to standard output by default (Martin Banky). The - bug was introduced in libpng-1.2.9beta5. - Removed unused mkinstalldirs. - -Version 1.5.0beta49 [October 8, 2010] - Undid Makefile.am revision of 1.5.0beta48. - -Version 1.5.0beta50 [October 14, 2010] - Revised Makefile.in to account for mkinstalldirs being removed. - Added some "(unsigned long)" typecasts in printf statements in pngvalid.c. - Suppressed a compiler warning in png_handle_sPLT(). - Check for out-of-range text compression mode in png_set_text(). - -Version 1.5.0beta51 [October 15, 2010] - Changed embedded dates to "(PENDING RELEASE) in beta releases (and future - rc releases) to minimize the difference between releases. - -Version 1.5.0beta52 [October 16, 2010] - Restored some of the embedded dates (in png.h, png.c, documentation, etc.) - -Version 1.5.0beta53 [October 18, 2010] - Updated INSTALL to mention using "make maintainer-clean" and to remove - obsolete statement about a custom ltmain.sh - Disabled "color-tests" by default in Makefile.am so it will work with - automake versions earlier than 1.11.1 - Use document name "libpng-manual.txt" instead of "libpng-.txt" - to simplify version differences. - Removed obsolete remarks about setjmp handling from INSTALL. - Revised and renamed the typedef in png.h and png.c that was designed - to catch library and header mismatch. - -Version 1.5.0beta54 [November 10, 2010] - Require 48 bytes, not 64 bytes, for big_row_buf in overflow checks. - Used a consistent structure for the pngget.c functions. - -Version 1.5.0beta55 [November 21, 2010] - Revised png_get_uint_32, png_get_int_32, png_get_uint_16 (Cosmin) - Moved reading of file signature into png_read_sig (Cosmin) - Fixed atomicity of chunk header serialization (Cosmin) - Added test for io_state in pngtest.c (Cosmin) - Added "#!/bin/sh" at the top of contrib/pngminim/*/gather.sh scripts. - Changes to remove gcc warnings (John Bowler) - Certain optional gcc warning flags resulted in warnings in libpng code. - With these changes only -Wconversion and -Wcast-qual cannot be turned on. - Changes are trivial rearrangements of code. -Wconversion is not possible - for pngrutil.c (because of the widespread use of += et al on variables - smaller than (int) or (unsigned int)) and -Wcast-qual is not possible - with pngwio.c and pngwutil.c because the 'write' callback and zlib - compression both fail to declare their input buffers with 'const'. - -Version 1.5.0beta56 [December 7, 2010] - Added the private PNG_UNUSED() macro definition in pngpriv.h. - Added some commentary about PNG_EXPORT in png.h and pngconf.h - Revised PNG_EXPORT() macro and added PNG_EXPORTA() macro, with the - objective of simplifying and improving the cosmetic appearance of png.h. - Fixed some incorrect "=" macro names in pnglibconf.dfa - Included documentation of changes in 1.5.0 from 1.4.x in libpng-manual.txt - -Version 1.5.0beta57 [December 9, 2010] - Documented the pngvalid gamma error summary with additional comments and - print statements. - Improved missing symbol handling in checksym.awk; symbols missing in both - the old and new files can now be optionally ignored, treated as errors - or warnings. - Removed references to pngvcrd.c and pnggccrd.c from the vstudio project. - Updated "libpng14" to "libpng15" in the visualc71 project. - Enabled the strip16 tests in pngvalid.` - Don't display test results (except PASS/FAIL) when running "make test". - Instead put them in pngtest-log.txt - Added "--with-zprefix=" to configure.ac - Updated the prebuilt configuration files to autoconf version 2.68 - -Version 1.5.0beta58 [December 19, 2010] - Fixed interlace image handling and add test cases (John Bowler) - Fixed the clean rule in Makefile.am to remove pngtest-log.txt - Made minor changes to work around warnings in gcc 3.4 - -Version 1.5.0rc01 [December 27, 2010] - No changes. - -Version 1.5.0rc02 [December 27, 2010] - Eliminated references to the scripts/*.def files in project/visualc71. - -Version 1.5.0rc03 [December 28, 2010] - Eliminated scripts/*.def and revised Makefile.am accordingly - -Version 1.5.0rc04 [December 29, 2010] - Fixed bug in background transformation handling in pngrtran.c (it was - looking for the flag in png_ptr->transformations instead of in - png_ptr->flags) (David Raymond). - -Version 1.5.0rc05 [December 31, 2010] - Fixed typo in a comment in CMakeLists.txt (libpng14 => libpng15) (Cosmin) - -Version 1.5.0rc06 [January 4, 2011] - Changed the new configure option "zprefix=string" to "zlib-prefix=string" - -Version 1.5.0rc07 [January 4, 2011] - Updated copyright year. - -Version 1.5.0 [January 6, 2011] - No changes. - -version 1.5.1beta01 [January 8, 2011] - Added description of png_set_crc_action() to the manual. - Added a note in the manual that the type of the iCCP profile was changed - from png_charpp to png_bytepp in png_get_iCCP(). This change happened - in version 1.5.0beta36 but is not noted in the CHANGES. Similarly, - it was changed from png_charpp to png_const_bytepp in png_set_iCCP(). - Ensure that png_rgb_to_gray ignores palette mapped images, if libpng - internally happens to call it with one, and fixed a failure to handle - palette mapped images correctly. This fixes CVE-2690. - -Version 1.5.1beta02 [January 14, 2011] - Fixed a bug in handling of interlaced images (bero at arklinux.org). - Updated CMakeLists.txt (Clifford Yapp) - -Version 1.5.1beta03 [January 14, 2011] - Fixed typecasting of some png_debug() statements (Cosmin) - -Version 1.5.1beta04 [January 16, 2011] - Updated documentation of png_set|get_tRNS() (Thomas Klausner). - Mentioned in the documentation that applications must #include "zlib.h" - if they need access to anything in zlib.h, and that a number of - macros such as png_memset() are no longer accessible by applications. - Corrected pngvalid gamma test "sample" function to access all of the color - samples of each pixel, instead of sampling the red channel three times. - Prefixed variable names index, div, exp, gamma with "png_" to avoid "shadow" - warnings, and (mistakenly) changed png_exp() to exp(). - -Version 1.5.1beta05 [January 16, 2011] - Changed variable names png_index, png_div, png_exp, and png_gamma to - char_index, divisor, exp_b10, and gamma_val, respectively, and - changed exp() back to png_exp(). - -Version 1.5.1beta06 [January 20, 2011] - Prevent png_push_crc_skip() from hanging while reading an unknown chunk - or an over-large compressed zTXt chunk with the progressive reader. - Eliminated more GCC "shadow" warnings. - Revised png_fixed() in png.c to avoid compiler warning about reaching the - end without returning anything. - -Version 1.5.1beta07 [January 22, 2011] - In the manual, describe the png_get_IHDR() arguments in the correct order. - Added const_png_structp and const_png_infop types, and used them in - prototypes for most png_get_*() functions. - -Version 1.5.1beta08 [January 23, 2011] - Added png_get_io_chunk_type() and deprecated png_get_io_chunk_name() - Added synopses for the IO_STATE functions and other missing synopses - to the manual. Removed the synopses from libpngpf.3 because they - were out of date and no longer useful. Better information can be - obtained by reading the prototypes and comments in pngpriv.h - Attempted to fix cpp on Solaris with S. Studio 12 cc, fix build - Added a make macro DFNCPP that is a CPP that will accept the tokens in - a .dfn file and adds configure stuff to test for such a CPP. ./configure - should fail if one is not available. - Corrected const_png_ in png.h to png_const_ to avoid polluting the namespace. - Added png_get_current_row_number and png_get_current_pass_number for the - benefit of the user transform callback. - Added png_process_data_pause and png_process_data_skip for the benefit of - progressive readers that need to stop data processing or want to optimize - skipping of unread data (e.g., if the reader marks a chunk to be skipped.) - -Version 1.5.1beta09 [January 24, 2011] - Enhanced pngvalid, corrected an error in gray_to_rgb, corrected doc error. - pngvalid contains tests of transforms, which tests are currently disabled - because they are incompletely tested. gray_to_rgb was failing to expand - the bit depth for smaller bit depth images; this seems to be a long - standing error and resulted, apparently, in invalid output - (CVE-2011-0408, CERT VU#643140). The documentation did not accurately - describe what libpng really does when converting RGB to gray. - -Version 1.5.1beta10 [January 27, 2010] - Fixed incorrect examples of callback prototypes in the manual, that were - introduced in libpng-1.0.0. - In addition the order of the png_get_uint macros with respect to the - relevant function definitions has been reversed. This helps the - preprocessing of the symbol files be more robust. Furthermore, the - symbol file preprocessing now uses -DPNG_NO_USE_READ_MACROS even when - the library may actually be built with PNG_USE_READ_MACROS; this stops - the read macros interfering with the symbol file format. - Made the manual, synopses, and function prototypes use the function - argument names file_gamma, int_file_gamma, and srgb_intent consistently. - -Version 1.5.1beta11 [January 28, 2011] - Changed PNG_UNUSED from "param=param;" to "{if(param){}}". - Corrected local variable type in new API png_process_data_skip() - The type was self-evidently incorrect but only causes problems on 64-bit - architectures. - Added transform tests to pngvalid and simplified the arguments. - -Version 1.5.1rc01 [January 29, 2011] - No changes. - -Version 1.5.1rc02 [January 31, 2011] - Added a request in the manual that applications do not use "png_" or - "PNG_" to begin any of their own symbols. - Changed PNG_UNUSED to "(void)param;" and updated the commentary in pngpriv.h - -Version 1.5.1 [February 3, 2011] - No changes. - -Version 1.5.2beta01 [February 13, 2011] - More -Wshadow fixes for older gcc compilers. Older gcc versions apparently - check formal parameters names in function declarations (as well as - definitions) to see if they match a name in the global namespace. - Revised PNG_EXPORTA macro to not use an empty parameter, to accommodate the - old VisualC++ preprocessor. - Turned on interlace handling in png_read_png(). - Fixed gcc pendantic warnings. - Handle longjmp in Cygwin. - Fixed png_get_current_row_number() in the interlaced case. - Cleaned up ALPHA flags and transformations. - Implemented expansion to 16 bits. - -Version 1.5.2beta02 [February 19, 2011] - Fixed mistake in the descriptions of user read_transform and write_transform - function prototypes in the manual. The row_info struct is png_row_infop. - Reverted png_get_current_row_number() to previous (1.5.2beta01) behavior. - Corrected png_get_current_row_number documentation - Fixed the read/write row callback documentation. - This documents the current behavior, where the callback is called after - every row with information pertaining to the next row. - -Version 1.5.2beta03 [March 3, 2011] - Fixed scripts/makefile.vcwin32 - Updated contrib/pngsuite/README to add the word "modify". - Define PNG_ALLOCATED to blank when _MSC_VER<1300. - -Version 1.5.2rc01 [March 19, 2011] - Define remaining attributes to blank when MSC_VER<1300. - ifdef out mask arrays in pngread.c when interlacing is not supported. - -Version 1.5.2rc02 [March 22, 2011] - Added a hint to try CPP=/bin/cpp if "cpp -E" fails in scripts/pnglibconf.mak - and in contrib/pngminim/*/makefile, eg., on SunOS 5.10, and removed "strip" - from the makefiles. - Fixed a bug (present since libpng-1.0.7) that makes png_handle_sPLT() fail - to compile when PNG_NO_POINTER_INDEXING is defined (Chubanov Kirill) - -Version 1.5.2rc03 [March 24, 2011] - Don't include standard header files in png.h while building the symbol table, - to avoid cpp failure on SunOS (introduced PNG_BUILDING_SYMBOL_TABLE macro). - -Version 1.5.2 [March 31, 2011] - No changes. - -Version 1.5.3beta01 [April 1, 2011] - Re-initialize the zlib compressor before compressing non-IDAT chunks. - Added API functions (png_set_text_compression_level() and four others) to - set parameters for zlib compression of non-IDAT chunks. - -Version 1.5.3beta02 [April 3, 2011] - Updated scripts/symbols.def with new API functions. - Only compile the new zlib re-initializing code when text or iCCP is - supported, using PNG_WRITE_COMPRESSED_TEXT_SUPPORTED macro. - Improved the optimization of the zlib CMF byte (see libpng-1.2.6beta03). - Optimize the zlib CMF byte in non-IDAT compressed chunks - -Version 1.5.3beta03 [April 16, 2011] - Fixed gcc -ansi -pedantic compile. A strict ANSI system does not have - snprintf, and the "__STRICT_ANSI__" detects that condition more reliably - than __STDC__ (John Bowler). - Removed the PNG_PTR_NORETURN attribute because it too dangerous. It tells - the compiler that a user supplied callback (the error handler) does not - return, yet there is no guarantee in practice that the application code - will correctly implement the error handler because the compiler only - issues a warning if there is a mistake (John Bowler). - Removed the no-longer-used PNG_DEPSTRUCT macro. - Updated the zlib version to 1.2.5 in the VStudio project. - Fixed 64-bit builds where png_uint_32 is smaller than png_size_t in - pngwutil.c (John Bowler). - Fixed bug with stripping the filler or alpha channel when writing, that - was introduced in libpng-1.5.2beta01 (bug report by Andrew Church). - -Version 1.5.3beta04 [April 27, 2011] - Updated pngtest.png with the new zlib CMF optimization. - Cleaned up conditional compilation code and of background/gamma handling - Internal changes only except a new option to avoid compiling the - png_build_grayscale_palette API (which is not used at all internally.) - The main change is to move the transform tests (READ_TRANSFORMS, - WRITE_TRANSFORMS) up one level to the caller of the APIs. This avoids - calls to spurious functions if all transforms are disabled and slightly - simplifies those functions. Pngvalid modified to handle this. - A minor change is to stop the strip_16 and expand_16 interfaces from - disabling each other; this allows the future alpha premultiplication - code to use 16-bit intermediate values while still producing 8-bit output. - png_do_background and png_do_gamma have been simplified to take a single - pointer to the png_struct rather than pointers to every item required - from the png_struct. This makes no practical difference to the internal - code. - A serious bug in the pngvalid internal routine 'standard_display_init' has - been fixed - this failed to initialize the red channel and accidentally - initialized the alpha channel twice. - Changed png_struct jmp_buf member name from png_jmpbuf to tmp_jmpbuf to - avoid a possible clash with the png_jmpbuf macro on some platforms. - -Version 1.5.3beta05 [May 6, 2011] - Added the "_POSIX_SOURCE" feature test macro to ensure libpng sees the - correct API. _POSIX_SOURCE is defined in pngpriv.h, pngtest.c and - pngvalid.c to ensure that POSIX conformant systems disable non-POSIX APIs. - Removed png_snprintf and added formatted warning messages. This change adds - internal APIs to allow png_warning messages to have parameters without - requiring the host OS to implement snprintf. As a side effect the - dependency of the tIME-supporting RFC1132 code on stdio is removed and - PNG_NO_WARNINGS does actually work now. - Pass "" instead of '\0' to png_default_error() in png_err(). This mistake - was introduced in libpng-1.2.20beta01. This fixes CVE-2011-2691. - Added PNG_WRITE_OPTIMIZE_CMF_SUPPORTED macro to make the zlib "CMF" byte - optimization configureable. - IDAT compression failed if preceded by a compressed text chunk (bug - introduced in libpng-1.5.3beta01-02). This was because the attempt to - reset the zlib stream in png_write_IDAT happened after the first IDAT - chunk had been deflated - much too late. In this change internal - functions were added to claim/release the z_stream and, hopefully, make - the code more robust. Also deflateEnd checking is added - previously - libpng would ignore an error at the end of the stream. - -Version 1.5.3beta06 [May 8, 2011] - Removed the -D_ALL_SOURCE from definitions for AIX in CMakeLists.txt - Implemented premultiplied alpha support: png_set_alpha_mode API - -Version 1.5.3beta07 [May 11, 2011] - Added expand_16 support to the high level interface. - Added named value and 'flag' gamma support to png_set_gamma. Made a minor - change from the previous (unreleased) ABI/API to hide the exact value used - for Macs - it's not a good idea to embed this in the ABI! - Moved macro definitions for PNG_HAVE_IHDR, PNG_HAVE_PLTE, and PNG_AFTER_IDAT - from pngpriv.h to png.h because they must be visible to applications - that call png_set_unknown_chunks(). - Check for up->location !PNG_AFTER_IDAT when writing unknown chunks - before IDAT. - -Version 1.5.3beta08 [May 16, 2011] - Improved "pngvalid --speed" to exclude more of pngvalid from the time. - Documented png_set_alpha_mode(), other changes in libpng.3/libpng-manual.txt - The cHRM chunk now sets the defaults for png_set_rgb_to_gray() (when negative - parameters are supplied by the caller), while in the absence of cHRM - sRGB/Rec 709 values are still used. This introduced a divide-by-zero - bug in png_handle_cHRM(). - The bKGD chunk no longer overwrites the background value set by - png_set_background(), allowing the latter to be used before the file - header is read. It never performed any useful function to override - the default anyway. - Added memory overwrite and palette image checks to pngvalid.c - Previously palette image code was poorly checked. Since the transformation - code has a special palette path in most cases this was a severe weakness. - Minor cleanup and some extra checking in pngrutil.c and pngrtran.c. When - expanding an indexed image, always expand to RGBA if transparency is - present. - -Version 1.5.3beta09 [May 17, 2011] - Reversed earlier 1.5.3 change of transformation order; move png_expand_16 - back where it was. The change doesn't work because it requires 16-bit - gamma tables when the code only generates 8-bit ones. This fails - silently; the libpng code just doesn't do any gamma correction. Moving - the tests back leaves the old, inaccurate, 8-bit gamma calculations, but - these are clearly better than none! - -Version 1.5.3beta10 [May 20, 2011] - - png_set_background() and png_expand_16() did not work together correctly. - This problem is present in 1.5.2; if png_set_background is called with - need_expand false and the matching 16 bit color libpng erroneously just - treats it as an 8-bit color because of where png_do_expand_16 is in the - transform list. This simple fix reduces the supplied colour to 8-bits, - so it gets smashed, but this is better than the current behavior. - Added tests for expand16, more fixes for palette image tests to pngvalid. - Corrects the code for palette image tests and disables attempts to - validate palette colors. - -Version 1.5.3rc01 [June 3, 2011] - No changes. - -Version 1.5.3rc02 [June 8, 2011] - Fixed uninitialized memory read in png_format_buffer() (Bug report by - Frank Busse, CVE-2011-2501, related to CVE-2004-0421). - -Version 1.5.3beta11 [June 11, 2011] - Fixed png_handle_sCAL which is broken in 1.5. This fixes CVE 2011-2692. - Added sCAL to pngtest.png - Revised documentation about png_set_user_limits() to say that it also affects - png writing. - Revised handling of png_set_user_limits() so that it can increase the - limit beyond the PNG_USER_WIDTH|HEIGHT_MAX; previously it could only - reduce it. - Make the 16-to-8 scaling accurate. Dividing by 256 with no rounding is - wrong (high by one) 25% of the time. Dividing by 257 with rounding is - wrong in 128 out of 65536 cases. Getting the right answer all the time - without division is easy. - Added "_SUPPORTED" to the PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION macro. - Added projects/owatcom, an IDE project for OpenWatcom to replace - scripts/makefile.watcom. This project works with OpenWatcom 1.9. The - IDE autogenerates appropriate makefiles (libpng.mk) for batch processing. - The project is configurable, unlike the Visual Studio project, so long - as the developer has an awk. - Changed png_set_gAMA to limit the gamma value range so that the inverse - of the stored value cannot overflow the fixed point representation, - and changed other things OpenWatcom warns about. - Revised pngvalid.c to test PNG_ALPHA_MODE_SUPPORTED correctly. This allows - pngvalid to build when ALPHA_MODE is not supported, which is required if - it is to build on libpng 1.4. - Removed string/memory macros that are no longer used and are not - necessarily fully supportable, particularly png_strncpy and png_snprintf. - Added log option to pngvalid.c and attempted to improve gamma messages. - -Version 1.5.3 [omitted] - People found the presence of a beta release following an rc release - to be confusing; therefore we bump the version to libpng-1.5.4beta01 - and there will be no libpng-1.5.3 release. - -Version 1.5.4beta01 [June 14, 2011] - Made it possible to undefine PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED - to get the same (inaccurate) output as libpng-1.5.2 and earlier. - Moved definitions of PNG_HAVE_IHDR, PNG_AFTER_IDAT, and PNG_HAVE_PLTE - outside of an unknown-chunk block in png.h because they are also - needed for other uses. - -Version 1.5.4beta02 [June 14, 2011] - Fixed and clarified LEGACY 16-to-8 scaling code. - Added png_set_chop_16() API, to match inaccurate results from previous - libpng versions. - Removed the ACCURATE and LEGACY options (they are no longer useable) - Use the old scaling method for background if png_set_chop_16() was - called. - Made png_set_chop_16() API removeable by disabling PNG_CHOP_16_TO_8_SUPPORTED - -Version 1.5.4beta03 [June 15, 2011] - Fixed a problem in png_do_expand_palette() exposed by optimization in - 1.5.3beta06 - Also removed a spurious and confusing "trans" member ("trans") from png_info. - The palette expand optimization prevented expansion to an intermediate RGBA - form if tRNS was present but alpha was marked to be stripped; this exposed - a check for tRNS in png_do_expand_palette() which is inconsistent with the - code elsewhere in libpng. - Correction to the expand_16 code; removed extra instance of - png_set_scale_16_to_8 from pngpriv.h - -Version 1.5.4beta04 [June 16, 2011] - Added a missing "#ifdef PNG_READ_BACKGROUND_SUPPORTED/#endif" in pngrtran.c - Added PNG_TRANSFORM_CHOP_16 to the high-level read transforms. - Made PNG_READ_16_TO_8_ACCURATE_SCALE configurable again. If this is - not enabled, png_set_strip_16() and png_do_scale_16_to_8() aren't built. - Revised contrib/visupng, gregbook, and pngminim to demonstrate chop_16_to_8 - -Version 1.5.4beta05 [June 16, 2011] - Renamed png_set_strip_16() to png_set_scale_16() and renamed - png_set_chop_16() to png_set_strip(16) in an attempt to minimize the - behavior changes between libpng14 and libpng15. - -Version 1.5.4beta06 [June 18, 2011] - Fixed new bug that was causing both strip_16 and scale_16 to be applied. - -Version 1.5.4beta07 [June 19, 2011] - Fixed pngvalid, simplified macros, added checking for 0 in sCAL. - The ACCURATE scale macro is no longer defined in 1.5 - call the - png_scale_16_to_8 API. Made sure that PNG_READ_16_TO_8 is still defined - if the png_strip_16_to_8 API is present. png_check_fp_number now - maintains some state so that positive, negative and zero values are - identified. sCAL uses these to be strictly spec conformant. - -Version 1.5.4beta08 [June 23, 2011] - Fixed pngvalid if ACCURATE_SCALE is defined. - Updated scripts/pnglibconf.h.prebuilt. - -Version 1.5.4rc01 [June 30, 2011] - Define PNG_ALLOCATED to "restrict" only if MSC_VER >= 1400. - -Version 1.5.4 [July 7, 2011] - No changes. - -Version 1.5.5beta01 [July 13, 2011] - Fixed some typos and made other minor changes in the manual. - Updated contrib/pngminus/makefile.std (Samuli Souminen) - -Version 1.5.5beta02 [July 14, 2011] - Revised Makefile.am and Makefile.in to look in the right directory for - pnglibconf.h.prebuilt - -Version 1.5.5beta03 [July 27, 2011] - Enabled compilation with g++ compiler. This compiler does not recognize - the file extension, so it always compiles with C++ rules. Made minor - changes to pngrutil.c to cast results where C++ expects it but C does not. - Minor editing of libpng.3 and libpng-manual.txt. - -Version 1.5.5beta04 [July 29, 2011] - Revised CMakeLists.txt (Clifford Yapp) - Updated commentary about the png_rgb_to_gray() default coefficients - in the manual and in pngrtran.c - -Version 1.5.5beta05 [August 17, 2011] - Prevent unexpected API exports from non-libpng DLLs on Windows. The "_DLL" - is removed from the test of whether a DLL is being built (this erroneously - caused the libpng APIs to be marked as DLL exports in static builds under - Microsoft Visual Studio). Almost all of the libpng building configuration - is moved from pngconf.h to pngpriv.h, but PNG_DLL_EXPORT remains in - pngconf.h, though, so that it is colocated with the import definition (it - is no longer used anywhere in the installed headers). The VStudio project - definitions have been cleaned up: "_USRDLL" has been removed from the - static library builds (this was incorrect), and PNG_USE_DLL has been added - to pngvalid to test the functionality (pngtest does not supply it, - deliberately). The spurious "_EXPORTS" has been removed from the - libpng build (all these errors were a result of copy/paste between project - configurations.) - Added new types and internal functions for CIE RGB end point handling to - pngpriv.h (functions yet to be implemented). - -Version 1.5.5beta06 [August 26, 2011] - Ensure the CMAKE_LIBRARY_OUTPUT_DIRECTORY is set in CMakeLists.txt - (Clifford Yap) - Fixes to rgb_to_gray and cHRM XYZ APIs (John Bowler): - The rgb_to_gray code had errors when combined with gamma correction. - Some pixels were treated as true grey when they weren't and such pixels - and true grey ones were not gamma corrected (the original value of the - red component was used instead). APIs to get and set cHRM using color - space end points have been added and the rgb_to_gray code that defaults - based on cHRM, and the divide-by-zero bug in png_handle_cHRM (CERT - VU#477046, CVE-2011-3328, introduced in 1.5.4) have been corrected. - A considerable number of tests has been added to pngvalid for the - rgb_to_gray transform. - Arithmetic errors in rgb_to_gray whereby the calculated gray value was - truncated to the bit depth rather than rounded have been fixed except in - the 8-bit non-gamma-corrected case (where consistency seems more important - than correctness.) The code still has considerable inaccuracies in the - 8-bit case because 8-bit linear arithmetic is used. - -Version 1.5.5beta07 [September 7, 2011] - Added "$(ARCH)" option to makefile.darwin - Added SunOS support to configure.ac and Makefile.am - Changed png_chunk_benign_error() to png_warning() in png.c, in - png_XYZ_from_xy_checked(). - -Version 1.5.5beta08 [September 10, 2011] - Fixed 64-bit compilation errors (gcc). The errors fixed relate - to conditions where types that are 32 bits in the GCC 32-bit - world (uLong and png_size_t) become 64 bits in the 64-bit - world. This produces potential truncation errors which the - compiler correctly flags. - Relocated new HAVE_SOLARIS_LD definition in configure.ac - Constant changes for 64-bit compatibility (removal of L suffixes). The - 16-bit cases still use "L" as we don't have a 16-bit test system. - -Version 1.5.5rc01 [September 15, 2011] - Removed "L" suffixes in pngpriv.h - -Version 1.5.5 [September 22, 2011] - No changes. - -Version 1.5.6beta01 [September 22, 2011] - Fixed some 64-bit type conversion warnings in pngrtran.c - Moved row_info from png_struct to a local variable. - The various interlace mask arrays have been made into arrays of - bytes and made PNG_CONST and static (previously some arrays were - marked PNG_CONST and some weren't). - Additional checks have been added to the transform code to validate the - pixel depths after the transforms on both read and write. - Removed some redundant code from pngwrite.c, in png_destroy_write_struct(). - Changed chunk reading/writing code to use png_uint_32 instead of png_byte[4]. - This removes the need to allocate temporary strings for chunk names on - the stack in the read/write code. Unknown chunk handling still uses the - string form because this is exposed in the API. - -Version 1.5.6beta02 [September 26, 2011] - Added a note in the manual the png_read_update_info() must be called only - once with a particular info_ptr. - Fixed a typo in the definition of the new PNG_STRING_FROM_CHUNK(s,c) macro. - -Version 1.5.6beta03 [September 28, 2011] - Revised test-pngtest.sh to report FAIL when pngtest fails. - Added "--strict" option to pngtest, to report FAIL when the failure is - only because the resulting valid files are different. - Revised CMakeLists.txt to work with mingw and removed some material from - CMakeLists.txt that is no longer useful in libpng-1.5. - -Version 1.5.6beta04 [October 5, 2011] - Fixed typo in Makefile.in and Makefile.am ("-M Wl" should be "-M -Wl")." - -Version 1.5.6beta05 [October 12, 2011] - Speed up png_combine_row() for interlaced images. This reduces the generality - of the code, allowing it to be optimized for Adam7 interlace. The masks - passed to png_combine_row() are now generated internally, avoiding - some code duplication and localizing the interlace handling somewhat. - Align png_struct::row_buf - previously it was always unaligned, caused by - a bug in the code that attempted to align it; the code needs to subtract - one from the pointer to take account of the filter byte prepended to - each row. - Optimized png_combine_row() when rows are aligned. This gains a small - percentage for 16-bit and 32-bit pixels in the typical case where the - output row buffers are appropriately aligned. The optimization was not - previously possible because the png_struct buffer was always misaligned. - Fixed bug in png_write_chunk_header() debug print, introduced in 1.5.6beta01. - -Version 1.5.6beta06 [October 17, 2011] - Removed two redundant tests for unitialized row. - Fixed a relatively harmless memory overwrite in compressed text writing - with a 1 byte zlib buffer. - Add ability to call png_read_update_info multiple times to pngvalid.c. - Fixes for multiple calls to png_read_update_info. These fixes attend to - most of the errors revealed in pngvalid, however doing the gamma work - twice results in inaccuracies that can't be easily fixed. There is now - a warning in the code if this is going to happen. - Turned on multiple png_read_update_info in pngvalid transform tests. - Prevent libpng from overwriting unused bits at the end of the image when - it is not byte aligned, while reading. Prior to libpng-1.5.6 libpng would - overwrite the partial byte at the end of each row if the row width was not - an exact multiple of 8 bits and the image is not interlaced. - -Version 1.5.6beta07 [October 21, 2011] - Made png_ptr->prev_row an aligned pointer into png_ptr->big_prev_row - (Mans Rullgard). - -Version 1.5.6rc01 [October 26, 2011] - Changed misleading "Missing PLTE before cHRM" warning to "Out of place cHRM" - -Version 1.5.6rc02 [October 27, 2011] - Added LSR() macro to defend against buggy compilers that evaluate non-taken - code branches and complain about out-of-range shifts. - -Version 1.5.6rc03 [October 28, 2011] - Renamed the LSR() macro to PNG_LSR() and added PNG_LSL() macro. - Fixed compiler warnings with Intel and MSYS compilers. The logical shift - fix for Microsoft Visual C is required by other compilers, so this - enables that fix for all compilers when using compile-time constants. - Under MSYS 'byte' is a name declared in a system header file, so we - changed the name of a local variable to avoid the warnings that result. - Added #define PNG_ALIGN_TYPE PNG_ALIGN_NONE to contrib/pngminim/*/pngusr.h - -Version 1.5.6 [November 3, 2011] - No changes. - -Version 1.5.7beta01 [November 4, 2011] - Added support for ARM processor (Mans Rullgard) - Fixed bug in pngvalid on early allocation failure; fixed type cast in - pngmem.c; pngvalid would attempt to call png_error() if the allocation - of a png_struct or png_info failed. This would probably have led to a - crash. The pngmem.c implementation of png_malloc() included a cast - to png_size_t which would fail on large allocations on 16-bit systems. - Fix for the preprocessor of the Intel C compiler. The preprocessor - splits adjacent @ signs with a space; this changes the concatentation - token from @-@-@ to PNG_JOIN; that should work with all compiler - preprocessors. - Paeth filter speed improvements from work by Siarhei Siamashka. This - changes the 'Paeth' reconstruction function to improve the GCC code - generation on x86. The changes are only part of the suggested ones; - just the changes that definitely improve speed and remain simple. - The changes also slightly increase the clarity of the code. - -Version 1.5.7beta02 [November 11, 2011] - Check compression_type parameter in png_get_iCCP and remove spurious - casts. The compression_type parameter is always assigned to, so must - be non-NULL. The cast of the profile length potentially truncated the - value unnecessarily on a 16-bit int system, so the cast of the (byte) - compression type to (int) is specified by ANSI-C anyway. - Fixed FP division by zero in pngvalid.c; the 'test_pixel' code left - the sBIT fields in the test pixel as 0, which resulted in a floating - point division by zero which was irrelevant but causes systems where - FP exceptions cause a crash. Added code to pngvalid to turn on FP - exceptions if the appropriate glibc support is there to ensure this is - tested in the future. - Updated scripts/pnglibconf.mak and scripts/makefile.std to handle the - new PNG_JOIN macro. - Added versioning to pnglibconf.h comments. - Simplified read/write API initial version; basic read/write tested on - a variety of images, limited documentation (in the header file.) - Installed more accurate linear to sRGB conversion tables. The slightly - modified tables reduce the number of 16-bit values that - convert to an off-by-one 8-bit value. The "makesRGB.c" code that was used - to generate the tables is now in a contrib/sRGBtables sub-directory. - -Version 1.5.7beta03 [November 17, 2011] - Removed PNG_CONST from the sRGB table declarations in pngpriv.h and png.c - Added run-time detection of NEON support. - Added contrib/libtests; includes simplified API test and timing test and - a color conversion utility for rapid checking of failed 'pngstest' results. - Multiple transform bug fixes plus a work-round for double gamma correction. - libpng does not support more than one transform that requires linear data - at once - if this is tried typically the results is double gamma - correction. Since the simplified APIs can need rgb to gray combined with - a compose operation it is necessary to do one of these outside the main - libpng transform code. This check-in also contains fixes to various bugs - in the simplified APIs themselves and to some bugs in compose and rgb to - gray (on palette) itself. - Fixes for C++ compilation using g++ When libpng source is compiled - using g++. The compiler imposes C++ rules on the C source; thus it - is desireable to make the source work with either C or C++ rules - without throwing away useful error information. This change adds - png_voidcast to allow C semantic (void*) cases or the corresponding - C++ static_cast operation, as appropriate. - Added --noexecstack to assembler file compilation. GCC does not set - this on assembler compilation, even though it does on C compilation. - This creates security issues if assembler code is enabled; the - work-around is to set it by default in the flags for $(CCAS) - Work around compilers that don't support declaration of const data. Some - compilers fault 'extern const' data declarations (because the data is - not initialized); this turns on const-ness only for compilers where - this is known to work. - -Version 1.5.7beta04 [November 17, 2011] - Since the gcc driver does not recognize the --noexecstack flag, we must - use the -Wa prefix to have it passed through to the assembler. - Also removed a duplicate setting of this flag. - Added files that were omitted from the libpng-1.5.7beta03 zip distribution. - -Version 1.5.7beta05 [November 25, 2011] - Removed "zTXt" from warning in generic chunk decompression function. - Validate time settings passed to pngset() and png_convert_to_rfc1123() - (Frank Busse). - Added MINGW support to CMakeLists.txt - Reject invalid compression flag or method when reading the iTXt chunk. - Backed out 'simplified' API changes. The API seems too complex and there - is a lack of consensus or enthusiasm for the proposals. The API also - reveals significant bugs inside libpng (double gamma correction and the - known bug of being unable to retrieve a corrected palette). It seems - better to wait until the bugs, at least, are corrected. - Moved pngvalid.c into contrib/libtests - Rebuilt Makefile.in, configure, etc., with autoconf-2.68 - -Version 1.5.7rc01 [December 1, 2011] - Replaced an "#if" with "#ifdef" in pngrtran.c - Revised #if PNG_DO_BC block in png.c (use #ifdef and add #else) - -Version 1.5.7rc02 [December 5, 2011] - Revised project files and contrib/pngvalid/pngvalid.c to account for - the relocation of pngvalid into contrib/libtests. - Revised pngconf.h to use " __declspec(restrict)" only when MSC_VER >= 1400, - as in libpng-1.5.4. - Put CRLF line endings in the owatcom project files. - -Version 1.5.7rc03 [December 7, 2011] - Updated CMakeLists.txt to account for the relocation of pngvalid.c - -Version 1.5.7 [December 15, 2011] - Minor fixes to pngvalid.c for gcc 4.6.2 compatibility to remove warnings - reported by earlier versions. - -Version 1.5.8beta01 [January 15, 2011] - Removed '#include config.h"' from contrib/libtests/pngvalid.c. It's not - needed and causes trouble for VPATH building. - Moved AC_MSG_CHECKING([if libraries can be versioned]) later to the proper - location in configure.ac (Gilles Espinasse). - Fix bug in pngerror.c: some long warnings were being improperly truncated - (CVE-2011-3464, bug introduced in libpng-1.5.3beta05). - -Version 1.5.8rc01 [January 21, 2012] - No changes. - -Version 1.5.8rc02 [January 25, 2012] - Fixed Min/GW uninstall to remove libpng.dll.a - Conditionalize the install rules for MINGW and CYGWIN in CMakeLists.txt - -Version 1.5.8 [February 1, 2012] - No changes. - -Version 1.5.9beta01 [February 3, 2012] - Rebuilt configure scripts in the tar distributions. - -Version 1.5.9beta02 [February 16, 2012] - Removed two unused definitions from scripts/pnglibconf.h.prebuilt - Removed some unused arrays (with #ifdef) from png_read_push_finish_row(). - Removed tests for no-longer-used *_EMPTY_PLTE_SUPPORTED from pngstruct.h - -Version 1.5.9rc01 [February 17, 2012] - Fixed CVE-2011-3026 buffer overrun bug. This bug was introduced when - iCCP chunk support was added at libpng-1.0.6. Deal more correctly with the - test on iCCP chunk length. Also removed spurious casts that may hide - problems on 16-bit systems. - -Version 1.5.9 [February 18, 2012] - No changes. - -Version 1.5.10beta01 [February 24, 2012] - Removed two useless #ifdef directives from pngread.c and one from pngrutil.c - Always put the CMAKE_LIBRARY in "lib" (removed special WIN32 case). - Removed empty vstudio/pngstest directory (Clifford Yapp). - Eliminated redundant png_push_read_tEXt|zTXt|iTXt|unknown code from - pngpread.c and use the sequential png_handle_tEXt, etc., in pngrutil.c; - now that png_ptr->buffer is inaccessible to applications, the special - handling is no longer useful. - Fixed bug with png_handle_hIST with odd chunk length (Frank Busse). - Added PNG_SAFE_LIMITS feature to pnglibconf.dfa and code in pngconf.h - to reset the user limits to safe ones if PNG_SAFE_LIMITS is defined. - To enable, use "CPPFLAGS=-DPNG_SAFE_LIMITS_SUPPORTED" on the configure - command or put "#define PNG_SAFE_LIMITS_SUPPORTED" in pnglibconf.h. - Revised the SAFE_LIMITS feature to be the same as the feature in libpng16. - Added information about the new limits in the manual. - -Version 1.5.10beta02 [February 27, 2012] - Updated Makefile.in - -Version 1.5.10beta03 [March 6, 2012] - Removed unused "current_text" members of png_struct and the png_free() - of png_ptr->current_text from pngread.c - Added palette-index checking. Issue a png_warning() if an invalid index is - found. - -Version 1.5.10beta04 [March 10, 2012] - Fixed PNG_LIBPNG_BUILD_BASE_TYPE definition. - Fixed CMF optimization of non-IDAT compressed chunks, which was added at - libpng-1.5.4. It sometimes produced too small of a window. - -Version 1.5.10beta05 [March 10, 2012] - Reject all iCCP chunks after the first, even if the first one is invalid. - Issue a png_benign_error() instead of png_warning() about bad palette index. - Fixed an off-by-one error in the palette index checking function. - Revised example.c to put text strings in a temporary character array - instead of directly assigning string constants to png_textp members. - This avoids compiler warnings when -Wwrite-strings is enabled. - -Version 1.5.10 [March 29, 2012] - Prevent PNG_EXPAND+PNG_SHIFT doing the shift twice. - Revised png_set_text_2() to avoid potential memory corruption (fixes - CVE-2011-3048, also known as CVE-2012-3425). - -Version 1.5.11beta01 [April 28, 2012] - Revised scripts/makefile.darwin: use system zlib; remove quotes around - architecture list; add missing ppc architecture; add architecture options - to shared library link; don't try to create a shared lib based on missing - RELEASE variable. - Enable png_set_check_for_invalid_index() for both read and write. - Removed #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED/#endif in pngpriv.h around - declaration of png_handle_unknown(). - Added -lssp_nonshared in a comment in scripts/makefile.freebsd - and changed deprecated NOOBJ and NOPROFILE to NO_OBJ and NO_PROFILE. - -Version 1.5.11rc01 [May 23, 2012] - No changes. - -Version 1.5.11rc02 [May 29, 2012] - Fixed some typos in comments. - Revised CMakeLists.txt to not attempt to make a symlink under mingw. - Added two images to contrib/pngsuite (1-bit and 2-bit transparent grayscale), - and renamed three whose names were inconsistent with those in - pngsuite/README.txt. - -Version 1.5.11rc03 [June 4, 2012] - Do not depend upon a GCC feature macro being available for use in generating - the linker mapfile symbol prefix. - Made fixes for new optimization warnings from gcc 4.7.0. The compiler - performed an optimization which is safe but then warned about it. - Changing the type of 'palette_number' in pngvalid.c removes the warning. - -Version 1.5.11rc04 [June 6, 2012] - Improved performance of new do_check_palette_indexes() function. - -Version 1.5.11rc05 [June 7, 2012] - Don't check palette indexes if num_palette is 0 (as it can be in MNG files). - -Version 1.5.11 [June 14, 2012] - Include zlib.h in contrib/gregbook and contrib/visupng examples. - -Version 1.5.12 [July 11, 2012] - Removed scripts/makefile.cegcc from the *.zip and *.7z distributions; it - depends on configure, which is not included in those archives. - Changed "a+w" to "u+w" in Makefile.in to fix CVE-2012-3386. - -Version 1.5.13beta01 [August 8, 2012] - Do not compile PNG_DEPRECATED, PNG_ALLOC and PNG_PRIVATE when __GNUC__ < 3. - Removed references to png_zalloc() and png_zfree() from the manual. - Revised PNG_FP_EXPORT and PNG_FIXED_EXPORT macros to avoid generating - lone semicolons (patch ported from libpng-1.6.0beta11). - -Version 1.5.13beta02 [September 10, 2012] - Corrected handling of the image array and the row_pointers array in example.c - When png_set_filler is used to strip a filler channel during write, the - code prior to 1.5 would ignore the case where the output required an - alpha channel or when the output was a palettized PNG. In libpng-1.5 the - ignorance was lost and libpng proceeded to strip the channel resulting - in a bad (potential memory overwrite) failure later. This reverts - the behavior to the pre-1.5 state but issues a warning. libpng-1.6 is - expected to issue an error on the erroneous png_set_filler call. - Use png_memset() consistently (pngmem.c contained some bare "memset" calls). - -Version 1.5.13rc01 [September 17, 2012] - No changes. - -Version 1.5.13 [September 27, 2012] - No changes. - -Send comments/corrections/commendations to png-mng-implement at lists.sf.net -(subscription required; visit -https://lists.sourceforge.net/lists/listinfo/png-mng-implement -to subscribe) -or to glennrp at users.sourceforge.net - -Glenn R-P -#endif +#if 0 +CHANGES - changes for libpng + +Version 0.2 + added reader into png.h + fixed small problems in stub file + +Version 0.3 + added pull reader + split up pngwrite.c to several files + added pnglib.txt + added example.c + cleaned up writer, adding a few new transformations + fixed some bugs in writer + interfaced with zlib 0.5 + added K&R support + added check for 64 KB blocks for 16-bit machines + +Version 0.4 + cleaned up code and commented code + simplified time handling into png_time + created png_color_16 and png_color_8 to handle color needs + cleaned up color type defines + fixed various bugs + made various names more consistent + interfaced with zlib 0.71 + cleaned up zTXt reader and writer (using zlib's Reset functions) + split transformations into pngrtran.c and pngwtran.c + +Version 0.5 + interfaced with zlib 0.8 + fixed many reading and writing bugs + saved using 3 spaces instead of tabs + +Version 0.6 + added png_large_malloc() and png_large_free() + added png_size_t + cleaned up some compiler warnings + added png_start_read_image() + +Version 0.7 + cleaned up lots of bugs + finished dithering and other stuff + added test program + changed name from pnglib to libpng + +Version 0.71 [June, 1995] + changed pngtest.png for zlib 0.93 + fixed error in libpng.txt and example.c + +Version 0.8 + cleaned up some bugs + added png_set_filler() + split up pngstub.c into pngmem.c, pngio.c, and pngerror.c + added #define's to remove unwanted code + moved png_info_init() to png.c + added old_size into png_realloc() + added functions to manually set filtering and compression info + changed compression parameters based on image type + optimized filter selection code + added version info + changed external functions passing floats to doubles (k&r problems?) + put all the configurable stuff in pngconf.h + enabled png_set_shift to work with paletted images on read + added png_read_update_info() - updates info structure with transformations + +Version 0.81 [August, 1995] + incorporated Tim Wegner's medium model code (thanks, Tim) + +Version 0.82 [September, 1995] + [unspecified changes] + +Version 0.85 [December, 1995] + added more medium model code (almost everything's a far) + added i/o, error, and memory callback functions + fixed some bugs (16-bit, 4-bit interlaced, etc.) + added first run progressive reader (barely tested) + +Version 0.86 [January, 1996] + fixed bugs + improved documentation + +Version 0.87 [January, 1996] + fixed medium model bugs + fixed other bugs introduced in 0.85 and 0.86 + added some minor documentation + +Version 0.88 [January, 1996] + fixed progressive bugs + replaced tabs with spaces + cleaned up documentation + added callbacks for read/write and warning/error functions + +Version 0.89 [July, 1996] + Added new initialization API to make libpng work better with shared libs + we now have png_create_read_struct(), png_create_write_struct(), + png_create_info_struct(), png_destroy_read_struct(), and + png_destroy_write_struct() instead of the separate calls to + malloc and png_read_init(), png_info_init(), and png_write_init() + Changed warning/error callback functions to fix bug - this means you + should use the new initialization API if you were using the old + png_set_message_fn() calls, and that the old API no longer exists + so that people are aware that they need to change their code + Changed filter selection API to allow selection of multiple filters + since it didn't work in previous versions of libpng anyways + Optimized filter selection code + Fixed png_set_background() to allow using an arbitrary RGB color for + paletted images + Fixed gamma and background correction for paletted images, so + png_correct_palette is not needed unless you are correcting an + external palette (you will need to #define PNG_CORRECT_PALETTE_SUPPORTED + in pngconf.h) - if nobody uses this, it may disappear in the future. + Fixed bug with Borland 64K memory allocation (Alexander Lehmann) + Fixed bug in interlace handling (Smarasderagd, I think) + Added more error checking for writing and image to reduce invalid files + Separated read and write functions so that they won't both be linked + into a binary when only reading or writing functionality is used + New pngtest image also has interlacing and zTXt + Updated documentation to reflect new API + +Version 0.90 [January, 1997] + Made CRC errors/warnings on critical and ancillary chunks configurable + libpng will use the zlib CRC routines by (compile-time) default + Changed DOS small/medium model memory support - needs zlib 1.04 (Tim Wegner) + Added external C++ wrapper statements to png.h (Gilles Dauphin) + Allow PNG file to be read when some or all of file signature has already + been read from the beginning of the stream. ****This affects the size + of info_struct and invalidates all programs that use a shared libpng**** + Fixed png_filler() declarations + Fixed? background color conversions + Fixed order of error function pointers to match documentation + Current chunk name is now available in png_struct to reduce the number + of nearly identical error messages (will simplify multi-lingual + support when available) + Try to get ready for unknown-chunk callback functions: + - previously read critical chunks are flagged, so the chunk handling + routines can determine if the chunk is in the right place + - all chunk handling routines have the same prototypes, so we will + be able to handle all chunks via a callback mechanism + Try to fix Linux "setjmp" buffer size problems + Removed png_large_malloc, png_large_free, and png_realloc functions. + +Version 0.95 [March, 1997] + Fixed bug in pngwutil.c allocating "up_row" twice and "avg_row" never + Fixed bug in PNG file signature compares when start != 0 + Changed parameter type of png_set_filler(...filler...) from png_byte + to png_uint_32 + Added test for MACOS to ensure that both math.h and fp.h are not #included + Added macros for libpng to be compiled as a Windows DLL (Andreas Kupries) + Added "packswap" transformation, which changes the endianness of + packed-pixel bytes (Kevin Bracey) + Added "strip_alpha" transformation, which removes the alpha channel of + input images without using it (not necessarily a good idea) + Added "swap_alpha" transformation, which puts the alpha channel in front + of the color bytes instead of after + Removed all implicit variable tests which assume NULL == 0 (I think) + Changed several variables to "png_size_t" to show 16/32-bit limitations + Added new pCAL chunk read/write support + Added experimental filter selection weighting (Greg Roelofs) + Removed old png_set_rgbx() and png_set_xrgb() functions that have been + obsolete for about 2 years now (use png_set_filler() instead) + Added macros to read 16- and 32-bit ints directly from buffer, to be + used only on those systems that support it (namely PowerPC and 680x0) + With some testing, this may become the default for MACOS/PPC systems. + Only calculate CRC on data if we are going to use it + Added macros for zTXt compression type PNG_zTXt_COMPRESSION_??? + Added macros for simple libpng debugging output selectable at compile time + Removed PNG_READ_END_MODE in progressive reader (Smarasderagd) + More description of info_struct in libpng.txt and png.h + More instructions in example.c + More chunk types tested in pngtest.c + Renamed pngrcb.c to pngset.c, and all png_read_ functions to be + png_set_. We now have corresponding png_get_ + functions in pngget.c to get information in info_ptr. This isolates + the application from the internal organization of png_info_struct + (good for shared library implementations). + +Version 0.96 [May, 1997] + Fixed serious bug with < 8bpp images introduced in 0.95 + Fixed 256-color transparency bug (Greg Roelofs) + Fixed up documentation (Greg Roelofs, Laszlo Nyul) + Fixed "error" in pngconf.h for Linux setjmp() behavior + Fixed DOS medium model support (Tim Wegner) + Fixed png_check_keyword() for case with error in static string text + Added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul) + Added typecasts to quiet compiler errors + Added more debugging info + +Version 0.97 [January, 1998] + Removed PNG_USE_OWN_CRC capability + Relocated png_set_crc_action from pngrutil.c to pngrtran.c + Fixed typecasts of "new_key", etc. (Andreas Dilger) + Added RFC 1152 [sic] date support + Fixed bug in gamma handling of 4-bit grayscale + Added 2-bit grayscale gamma handling (Glenn R-P) + Added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P) + Minor corrections in libpng.txt + Added simple sRGB support (Glenn R-P) + Easier conditional compiling, e.g., + define PNG_READ/WRITE_NOT_FULLY_SUPPORTED; + all configurable options can be selected from command-line instead + of having to edit pngconf.h (Glenn R-P) + Fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P) + Added more conditions for png_do_background, to avoid changing + black pixels to background when a background is supplied and + no pixels are transparent + Repaired PNG_NO_STDIO behavior + Tested NODIV support and made it default behavior (Greg Roelofs) + Added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler) + Regularized version numbering scheme and bumped shared-library major + version number to 2 to avoid problems with libpng 0.89 apps + (Greg Roelofs) + +Version 0.98 [January, 1998] + Cleaned up some typos in libpng.txt and in code documentation + Fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler) + Cosmetic change "display_gamma" to "screen_gamma" in pngrtran.c + Changed recommendation about file_gamma for PC images to .51 from .45, + in example.c and libpng.txt, added comments to distinguish between + screen_gamma, viewing_gamma, and display_gamma. + Changed all references to RFC1152 to read RFC1123 and changed the + PNG_TIME_RFC1152_SUPPORTED macro to PNG_TIME_RFC1123_SUPPORTED + Added png_invert_alpha capability (Glenn R-P -- suggestion by Jon Vincent) + Changed srgb_intent from png_byte to int to avoid compiler bugs + +Version 0.99 [January 30, 1998] + Free info_ptr->text instead of end_info_ptr->text in pngread.c (John Bowler) + Fixed a longstanding "packswap" bug in pngtrans.c + Fixed some inconsistencies in pngconf.h that prevented compiling with + PNG_READ_GAMMA_SUPPORTED and PNG_READ_hIST_SUPPORTED undefined + Fixed some typos and made other minor rearrangement of libpng.txt (Andreas) + Changed recommendation about file_gamma for PC images to .50 from .51 in + example.c and libpng.txt, and changed file_gamma for sRGB images to .45 + Added a number of functions to access information from the png structure + png_get_image_height(), etc. (Glenn R-P, suggestion by Brad Pettit) + Added TARGET_MACOS similar to zlib-1.0.8 + Define PNG_ALWAYS_EXTERN when __MWERKS__ && WIN32 are defined + Added type casting to all png_malloc() function calls + +Version 0.99a [January 31, 1998] + Added type casts and parentheses to all returns that return a value.(Tim W.) + +Version 0.99b [February 4, 1998] + Added type cast png_uint_32 on malloc function calls where needed. + Changed type of num_hist from png_uint_32 to int (same as num_palette). + Added checks for rowbytes overflow, in case png_size_t is less than 32 bits. + Renamed makefile.elf to makefile.lnx. + +Version 0.99c [February 7, 1998] + More type casting. Removed erroneous overflow test in pngmem.c. + Added png_buffered_memcpy() and png_buffered_memset(), apply them to rowbytes. + Added UNIX manual pages libpng.3 (incorporating libpng.txt) and png.5. + +Version 0.99d [February 11, 1998] + Renamed "far_to_near()" "png_far_to_near()" + Revised libpng.3 + Version 99c "buffered" operations didn't work as intended. Replaced them + with png_memcpy_check() and png_memset_check(). + Added many "if (png_ptr == NULL) return" to quell compiler warnings about + unused png_ptr, mostly in pngget.c and pngset.c. + Check for overlength tRNS chunk present when indexed-color PLTE is read. + Cleaned up spelling errors in libpng.3/libpng.txt + Corrected a problem with png_get_tRNS() which returned undefined trans array + +Version 0.99e [February 28, 1998] + Corrected png_get_tRNS() again. + Add parentheses for easier reading of pngget.c, fixed "||" should be "&&". + Touched up example.c to make more of it compileable, although the entire + file still can't be compiled (Willem van Schaik) + Fixed a bug in png_do_shift() (Bryan Tsai) + Added a space in png.h prototype for png_write_chunk_start() + Replaced pngtest.png with one created with zlib 1.1.1 + Changed pngtest to report PASS even when file size is different (Jean-loup G.) + Corrected some logic errors in png_do_invert_alpha() (Chris Patterson) + +Version 0.99f [March 5, 1998] + Corrected a bug in pngpread() introduced in version 99c (Kevin Bracey) + Moved makefiles into a "scripts" directory, and added INSTALL instruction file + Added makefile.os2 and pngos2.def (A. Zabolotny) and makefile.s2x (W. Sebok) + Added pointers to "note on libpng versions" in makefile.lnx and README + Added row callback feature when reading and writing nonprogressive rows + and added a test of this feature in pngtest.c + Added user transform callbacks, with test of the feature in pngtest.c + +Version 0.99g [March 6, 1998, morning] + Minor changes to pngtest.c to suppress compiler warnings. + Removed "beta" language from documentation. + +Version 0.99h [March 6, 1998, evening] + Minor changes to previous minor changes to pngtest.c + Changed PNG_READ_NOT_FULLY_SUPPORTED to PNG_READ_TRANSFORMS_NOT_SUPPORTED + and added PNG_PROGRESSIVE_READ_NOT_SUPPORTED macro + Added user transform capability + +Version 1.00 [March 7, 1998] + Changed several typedefs in pngrutil.c + Added makefile.wat (Pawel Mrochen), updated makefile.tc3 (Willem van Schaik) + Replaced "while(1)" with "for(;;)" + Added PNGARG() to prototypes in pngtest.c and removed some prototypes + Updated some of the makefiles (Tom Lane) + Changed some typedefs (s_start, etc.) in pngrutil.c + Fixed dimensions of "short_months" array in pngwrite.c + Replaced ansi2knr.c with the one from jpeg-v6 + +Version 1.0.0 [March 8, 1998] + Changed name from 1.00 to 1.0.0 (Adam Costello) + Added smakefile.ppc (with SCOPTIONS.ppc) for Amiga PPC (Andreas Kleinert) + +Version 1.0.0a [March 9, 1998] + Fixed three bugs in pngrtran.c to make gamma+background handling consistent + (Greg Roelofs) + Changed format of the PNG_LIBPNG_VER integer to xyyzz instead of xyz + for major, minor, and bugfix releases. This is 10001. (Adam Costello, + Tom Lane) + Make months range from 1-12 in png_convert_to_rfc1123 + +Version 1.0.0b [March 13, 1998] + Quieted compiler complaints about two empty "for" loops in pngrutil.c + Minor changes to makefile.s2x + Removed #ifdef/#endif around a png_free() in pngread.c + +Version 1.0.1 [March 14, 1998] + Changed makefile.s2x to reduce security risk of using a relative pathname + Fixed some typos in the documentation (Greg). + Fixed a problem with value of "channels" returned by png_read_update_info() + +Version 1.0.1a [April 21, 1998] + Optimized Paeth calculations by replacing abs() function calls with intrinsics + plus other loop optimizations. Improves avg decoding speed by about 20%. + Commented out i386istic "align" compiler flags in makefile.lnx. + Reduced the default warning level in some makefiles, to make them consistent. + Removed references to IJG and JPEG in the ansi2knr.c copyright statement. + Fixed a bug in png_do_strip_filler with XXRRGGBB => RRGGBB transformation. + Added grayscale and 16-bit capability to png_do_read_filler(). + Fixed a bug in pngset.c, introduced in version 0.99c, that sets rowbytes + too large when writing an image with bit_depth < 8 (Bob Dellaca). + Corrected some bugs in the experimental weighted filtering heuristics. + Moved a misplaced pngrutil code block that truncates tRNS if it has more + than num_palette entries -- test was done before num_palette was defined. + Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins). + Changed compiler flags in makefile.wat for better optimization + (Pawel Mrochen). + +Version 1.0.1b [May 2, 1998] + Relocated png_do_gray_to_rgb() within png_do_read_transformations() (Greg). + Relocated the png_composite macros from pngrtran.c to png.h (Greg). + Added makefile.sco (contributed by Mike Hopkirk). + Fixed two bugs (missing definitions of "istop") introduced in libpng-1.0.1a. + Fixed a bug in pngrtran.c that would set channels=5 under some circumstances. + More work on the Paeth-filtering, achieving imperceptible speedup + (A Kleinert). + More work on loop optimization which may help when compiled with C++ + compilers. + Added warnings when people try to use transforms they've defined out. + Collapsed 4 "i" and "c" loops into single "i" loops in pngrtran and pngwtran. + Revised paragraph about png_set_expand() in libpng.txt and libpng.3 (Greg) + +Version 1.0.1c [May 11, 1998] + Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for + filler bytes should have been 0xff instead of 0xf. + Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images. + Moved PNG_WRITE_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED + out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h + Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED, + for consistency, in pngconf.h + Added individual "ifndef PNG_NO_[CAPABILITY]" in pngconf.h to make it easier + to remove unwanted capabilities via the compile line + Made some corrections to grammar (which, it's) in documentation (Greg). + Corrected example.c, use of row_pointers in png_write_image(). + +Version 1.0.1d [May 24, 1998] + Corrected several statements that used side effects illegally in pngrutil.c + and pngtrans.c, that were introduced in version 1.0.1b + Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert) + More corrections to example.c, use of row_pointers in png_write_image() + and png_read_rows(). + Added pngdll.mak and pngdef.pas to scripts directory, contributed by + Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5 + Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.) + Changed several loops from count-down to count-up, for consistency. + +Version 1.0.1e [June 6, 1998] + Revised libpng.txt and libpng.3 description of png_set_read|write_fn(), and + added warnings when people try to set png_read_fn and png_write_fn in + the same structure. + Added a test such that png_do_gamma will be done when num_trans==0 + for truecolor images that have defined a background. This corrects an + error that was introduced in libpng-0.90 that can cause gamma processing + to be skipped. + Added tests in png.h to include "trans" and "trans_values" in structures + when PNG_READ_BACKGROUND_SUPPORTED or PNG_READ_EXPAND_SUPPORTED is defined. + Add png_free(png_ptr->time_buffer) in png_destroy_read_struct() + Moved png_convert_to_rfc_1123() from pngwrite.c to png.c + Added capability for user-provided malloc_fn() and free_fn() functions, + and revised pngtest.c to demonstrate their use, replacing the + PNGTEST_DEBUG_MEM feature. + Added makefile.w32, for Microsoft C++ 4.0 and later (Tim Wegner). + +Version 1.0.2 [June 14, 1998] + Fixed two bugs in makefile.bor . + +Version 1.0.2a [December 30, 1998] + Replaced and extended code that was removed from png_set_filler() in 1.0.1a. + Fixed a bug in png_do_filler() that made it fail to write filler bytes in + the left-most pixel of each row (Kevin Bracey). + Changed "static pngcharp tIME_string" to "static char tIME_string[30]" + in pngtest.c (Duncan Simpson). + Fixed a bug in pngtest.c that caused pngtest to try to write a tIME chunk + even when no tIME chunk was present in the source file. + Fixed a problem in pngrutil.c: gray_to_rgb didn't always work with 16-bit. + Fixed a problem in png_read_push_finish_row(), which would not skip some + passes that it should skip, for images that are less than 3 pixels high. + Interchanged the order of calls to png_do_swap() and png_do_shift() + in pngwtran.c (John Cromer). + Added #ifdef PNG_DEBUG/#endif surrounding use of PNG_DEBUG in png.h . + Changed "bad adaptive filter type" from error to warning in pngrutil.c . + Fixed a documentation error about default filtering with 8-bit indexed-color. + Separated the PNG_NO_STDIO macro into PNG_NO_STDIO and PNG_NO_CONSOLE_IO + (L. Peter Deutsch). + Added png_set_rgb_to_gray() and png_get_rgb_to_gray_status() functions. + Added png_get_copyright() and png_get_header_version() functions. + Revised comments on png_set_progressive_read_fn() in libpng.txt and example.c + Added information about debugging in libpng.txt and libpng.3 . + Changed "ln -sf" to "ln -s -f" in makefile.s2x, makefile.lnx, and + makefile.sco. + Removed lines after Dynamic Dependencies" in makefile.aco . + Revised makefile.dec to make a shared library (Jeremie Petit). + Removed trailing blanks from all files. + +Version 1.0.2a [January 6, 1999] + Removed misplaced #endif and #ifdef PNG_NO_EXTERN near the end of png.h + Added "if" tests to silence complaints about unused png_ptr in png.h and png.c + Changed "check_if_png" function in example.c to return true (nonzero) if PNG. + Changed libpng.txt to demonstrate png_sig_cmp() instead of png_check_sig() + which is obsolete. + +Version 1.0.3 [January 14, 1999] + Added makefile.hux, for Hewlett Packard HPUX 10.20 and 11.00 (Jim Rice) + Added a statement of Y2K compliance in png.h, libpng.3, and Y2KINFO. + +Version 1.0.3a [August 12, 1999] + Added check for PNG_READ_INTERLACE_SUPPORTED in pngread.c; issue a warning + if an attempt is made to read an interlaced image when it's not supported. + Added check if png_ptr->trans is defined before freeing it in pngread.c + Modified the Y2K statement to include versions back to version 0.71 + Fixed a bug in the check for valid IHDR bit_depth/color_types in pngrutil.c + Modified makefile.wat (added -zp8 flag, ".symbolic", changed some comments) + Replaced leading blanks with tab characters in makefile.hux + Changed "dworkin.wustl.edu" to "ccrc.wustl.edu" in various documents. + Changed (float)red and (float)green to (double)red, (double)green + in png_set_rgb_to_gray() to avoid "promotion" problems in AIX. + Fixed a bug in pngconf.h that omitted when PNG_DEBUG==0 (K Bracey). + Reformatted libpng.3 and libpngpf.3 with proper fonts (script by J. vanZandt). + Updated documentation to refer to the PNG-1.2 specification. + Removed ansi2knr.c and left pointers to the latest source for ansi2knr.c + in makefile.knr, INSTALL, and README (L. Peter Deutsch) + Fixed bugs in calculation of the length of rowbytes when adding alpha + channels to 16-bit images, in pngrtran.c (Chris Nokleberg) + Added function png_set_user_transform_info() to store user_transform_ptr, + user_depth, and user_channels into the png_struct, and a function + png_get_user_transform_ptr() to retrieve the pointer (Chris Nokleberg) + Added function png_set_empty_plte_permitted() to make libpng useable + in MNG applications. + Corrected the typedef for png_free_ptr in png.h (Jesse Jones). + Correct gamma with srgb is 45455 instead of 45000 in pngrutil.c, to be + consistent with PNG-1.2, and allow variance of 500 before complaining. + Added assembler code contributed by Intel in file pngvcrd.c and modified + makefile.w32 to use it (Nirav Chhatrapati, INTEL Corporation, + Gilles Vollant) + Changed "ln -s -f" to "ln -f -s" in the makefiles to make Solaris happy. + Added some aliases for png_set_expand() in pngrtran.c, namely + png_set_expand_PLTE(), png_set_expand_depth(), and png_set_expand_tRNS() + (Greg Roelofs, in "PNG: The Definitive Guide"). + Added makefile.beo for BEOS on X86, contributed by Sander Stok. + +Version 1.0.3b [August 26, 1999] + Replaced 2147483647L several places with PNG_MAX_UINT macro, defined in png.h + Changed leading blanks to tabs in all makefiles. + Define PNG_USE_PNGVCRD in makefile.w32, to get MMX assembler code. + Made alternate versions of png_set_expand() in pngrtran.c, namely + png_set_gray_1_2_4_to_8, png_set_palette_to_rgb, and png_set_tRNS_to_alpha + (Greg Roelofs, in "PNG: The Definitive Guide"). Deleted the 1.0.3a aliases. + Relocated start of 'extern "C"' block in png.h so it doesn't include pngconf.h + Revised calculation of num_blocks in pngmem.c to avoid a potentially + negative shift distance, whose results are undefined in the C language. + Added a check in pngset.c to prevent writing multiple tIME chunks. + Added a check in pngwrite.c to detect invalid small window_bits sizes. + +Version 1.0.3d [September 4, 1999] + Fixed type casting of igamma in pngrutil.c + Added new png_expand functions to scripts/pngdef.pas and pngos2.def + Added a demo read_user_transform_fn that examines the row filters in pngtest.c + +Version 1.0.4 [September 24, 1999] + Define PNG_ALWAYS_EXTERN in pngconf.h if __STDC__ is defined + Delete #define PNG_INTERNAL and include "png.h" from pngasmrd.h + Made several minor corrections to pngtest.c + Renamed the makefiles with longer but more user friendly extensions. + Copied the PNG copyright and license to a separate LICENSE file. + Revised documentation, png.h, and example.c to remove reference to + "viewing_gamma" which no longer appears in the PNG specification. + Revised pngvcrd.c to use MMX code for interlacing only on the final pass. + Updated pngvcrd.c to use the faster C filter algorithms from libpng-1.0.1a + Split makefile.win32vc into two versions, makefile.vcawin32 (uses MMX + assembler code) and makefile.vcwin32 (doesn't). + Added a CPU timing report to pngtest.c (enabled by defining PNGTEST_TIMING) + Added a copy of pngnow.png to the distribution. + +Version 1.0.4a [September 25, 1999] + Increase max_pixel_depth in pngrutil.c if a user transform needs it. + Changed several division operations to right-shifts in pngvcrd.c + +Version 1.0.4b [September 30, 1999] + Added parentheses in line 3732 of pngvcrd.c + Added a comment in makefile.linux warning about buggy -O3 in pgcc 2.95.1 + +Version 1.0.4c [October 1, 1999] + Added a "png_check_version" function in png.c and pngtest.c that will generate + a helpful compiler error if an old png.h is found in the search path. + Changed type of png_user_transform_depth|channels from int to png_byte. + +Version 1.0.4d [October 6, 1999] + Changed 0.45 to 0.45455 in png_set_sRGB() + Removed unused PLTE entries from pngnow.png + Re-enabled some parts of pngvcrd.c (png_combine_row) that work properly. + +Version 1.0.4e [October 10, 1999] + Fixed sign error in pngvcrd.c (Greg Roelofs) + Replaced some instances of memcpy with simple assignments in pngvcrd (GR-P) + +Version 1.0.4f [October 15, 1999] + Surrounded example.c code with #if 0 .. #endif to prevent people from + inadvertently trying to compile it. + Changed png_get_header_version() from a function to a macro in png.h + Added type casting mostly in pngrtran.c and pngwtran.c + Removed some pointless "ptr = NULL" in pngmem.c + Added a "contrib" directory containing the source code from Greg's book. + +Version 1.0.5 [October 15, 1999] + Minor editing of the INSTALL and README files. + +Version 1.0.5a [October 23, 1999] + Added contrib/pngsuite and contrib/pngminus (Willem van Schaik) + Fixed a typo in the png_set_sRGB() function call in example.c (Jan Nijtmans) + Further optimization and bugfix of pngvcrd.c + Revised pngset.c so that it does not allocate or free memory in the user's + text_ptr structure. Instead, it makes its own copy. + Created separate write_end_info_struct in pngtest.c for a more severe test. + Added code in pngwrite.c to free info_ptr->text[i].key to stop a memory leak. + +Version 1.0.5b [November 23, 1999] + Moved PNG_FLAG_HAVE_CHUNK_HEADER, PNG_FLAG_BACKGROUND_IS_GRAY and + PNG_FLAG_WROTE_tIME from flags to mode. + Added png_write_info_before_PLTE() function. + Fixed some typecasting in contrib/gregbook/*.c + Updated scripts/makevms.com and added makevms.com to contrib/gregbook + and contrib/pngminus (Martin Zinser) + +Version 1.0.5c [November 26, 1999] + Moved png_get_header_version from png.h to png.c, to accommodate ansi2knr. + Removed all global arrays (according to PNG_NO_GLOBAL_ARRAYS macro), to + accommodate making DLL's: Moved usr_png_ver from global variable to function + png_get_header_ver() in png.c. Moved png_sig to png_sig_bytes in png.c and + eliminated use of png_sig in pngwutil.c. Moved the various png_CHNK arrays + into pngtypes.h. Eliminated use of global png_pass arrays. Declared the + png_CHNK and png_pass arrays to be "const". Made the global arrays + available to applications (although none are used in libpng itself) when + PNG_NO_GLOBAL_ARRAYS is not defined or when PNG_GLOBAL_ARRAYS is defined. + Removed some extraneous "-I" from contrib/pngminus/makefile.std + Changed the PNG_sRGB_INTENT macros in png.h to be consistent with PNG-1.2. + Change PNG_SRGB_INTENT to PNG_sRGB_INTENT in libpng.txt and libpng.3 + +Version 1.0.5d [November 29, 1999] + Add type cast (png_const_charp) two places in png.c + Eliminated pngtypes.h; use macros instead to declare PNG_CHNK arrays. + Renamed "PNG_GLOBAL_ARRAYS" to "PNG_USE_GLOBAL_ARRAYS" and made available + to applications a macro "PNG_USE_LOCAL_ARRAYS". + comment out (with #ifdef) all the new declarations when + PNG_USE_GLOBAL_ARRAYS is defined. + Added PNG_EXPORT_VAR macro to accommodate making DLL's. + +Version 1.0.5e [November 30, 1999] + Added iCCP, iTXt, and sPLT support; added "lang" member to the png_text + structure; refactored the inflate/deflate support to make adding new chunks + with trailing compressed parts easier in the future, and added new functions + png_free_iCCP, png_free_pCAL, png_free_sPLT, png_free_text, png_get_iCCP, + png_get_spalettes, png_set_iCCP, png_set_spalettes (Eric S. Raymond). + NOTE: Applications that write text chunks MUST define png_text->lang + before calling png_set_text(). It must be set to NULL if you want to + write tEXt or zTXt chunks. If you want your application to be able to + run with older versions of libpng, use + + #ifdef PNG_iTXt_SUPPORTED + png_text[i].lang = NULL; + #endif + + Changed png_get_oFFs() and png_set_oFFs() to use signed rather than unsigned + offsets (Eric S. Raymond). + Combined PNG_READ_cHNK_SUPPORTED and PNG_WRITE_cHNK_SUPPORTED macros into + PNG_cHNK_SUPPORTED and combined the three types of PNG_text_SUPPORTED + macros, leaving the separate macros also available. + Removed comments on #endifs at the end of many short, non-nested #if-blocks. + +Version 1.0.5f [December 6, 1999] + Changed makefile.solaris to issue a warning about potential problems when + the ucb "ld" is in the path ahead of the ccs "ld". + Removed "- [date]" from the "synopsis" line in libpng.3 and libpngpf.3. + Added sCAL chunk support (Eric S. Raymond). + +Version 1.0.5g [December 7, 1999] + Fixed "png_free_spallettes" typo in png.h + Added code to handle new chunks in pngpread.c + Moved PNG_CHNK string macro definitions outside of PNG_NO_EXTERN block + Added "translated_key" to png_text structure and png_write_iTXt(). + Added code in pngwrite.c to work around a newly discovered zlib bug. + +Version 1.0.5h [December 10, 1999] + NOTE: regarding the note for version 1.0.5e, the following must also + be included in your code: + png_text[i].translated_key = NULL; + Unknown chunk handling is now supported. + Option to eliminate all floating point support was added. Some new + fixed-point functions such as png_set_gAMA_fixed() were added. + Expanded tabs and removed trailing blanks in source files. + +Version 1.0.5i [December 13, 1999] + Added some type casts to silence compiler warnings. + Renamed "png_free_spalette" to "png_free_spalettes" for consistency. + Removed leading blanks from a #define in pngvcrd.c + Added some parameters to the new png_set_keep_unknown_chunks() function. + Added a test for up->location != 0 in the first instance of writing + unknown chunks in pngwrite.c + Changed "num" to "i" in png_free_spalettes() and png_free_unknowns() to + prevent recursion. + Added png_free_hIST() function. + Various patches to fix bugs in the sCAL and integer cHRM processing, + and to add some convenience macros for use with sCAL. + +Version 1.0.5j [December 21, 1999] + Changed "unit" parameter of png_write_sCAL from png_byte to int, to work + around buggy compilers. + Added new type "png_fixed_point" for integers that hold float*100000 values + Restored backward compatibility of tEXt/zTXt chunk processing: + Restored the first four members of png_text to the same order as v.1.0.5d. + Added members "lang_key" and "itxt_length" to png_text struct. Set + text_length=0 when "text" contains iTXt data. Use the "compression" + member to distinguish among tEXt/zTXt/iTXt types. Added + PNG_ITXT_COMPRESSION_NONE (1) and PNG_ITXT_COMPRESSION_zTXt(2) macros. + The "Note" above, about backward incompatibility of libpng-1.0.5e, no + longer applies. + Fixed png_read|write_iTXt() to read|write parameters in the right order, + and to write the iTXt chunk after IDAT if it appears in the end_ptr. + Added pnggccrd.c, version of pngvcrd.c Intel assembler for gcc (Greg Roelofs) + Reversed the order of trying to write floating-point and fixed-point gAMA. + +Version 1.0.5k [December 27, 1999] + Added many parentheses, e.g., "if (a && b & c)" becomes "if (a && (b & c))" + Added png_handle_as_unknown() function (Glenn) + Added png_free_chunk_list() function and chunk_list and num_chunk_list members + of png_ptr. + Eliminated erroneous warnings about multiple sPLT chunks and sPLT-after-PLTE. + Fixed a libpng-1.0.5h bug in pngrutil.c that was issuing erroneous warnings + about ignoring incorrect gAMA with sRGB (gAMA was in fact not ignored) + Added png_free_tRNS(); png_set_tRNS() now malloc's its own trans array (ESR). + Define png_get_int_32 when oFFs chunk is supported as well as when pCAL is. + Changed type of proflen from png_int_32 to png_uint_32 in png_get_iCCP(). + +Version 1.0.5l [January 1, 2000] + Added functions png_set_read_user_chunk_fn() and png_get_user_chunk_ptr() + for setting a callback function to handle unknown chunks and for + retrieving the associated user pointer (Glenn). + +Version 1.0.5m [January 7, 2000] + Added high-level functions png_read_png(), png_write_png(), png_free_pixels(). + +Version 1.0.5n [January 9, 2000] + Added png_free_PLTE() function, and modified png_set_PLTE() to malloc its + own memory for info_ptr->palette. This makes it safe for the calling + application to free its copy of the palette any time after it calls + png_set_PLTE(). + +Version 1.0.5o [January 20, 2000] + Cosmetic changes only (removed some trailing blanks and TABs) + +Version 1.0.5p [January 31, 2000] + Renamed pngdll.mak to makefile.bd32 + Cosmetic changes in pngtest.c + +Version 1.0.5q [February 5, 2000] + Relocated the makefile.solaris warning about PATH problems. + Fixed pngvcrd.c bug by pushing/popping registers in mmxsupport (Bruce Oberg) + Revised makefile.gcmmx + Added PNG_SETJMP_SUPPORTED, PNG_SETJMP_NOT_SUPPORTED, and PNG_ABORT() macros + +Version 1.0.5r [February 7, 2000] + Removed superfluous prototype for png_get_itxt from png.h + Fixed a bug in pngrtran.c that improperly expanded the background color. + Return *num_text=0 from png_get_text() when appropriate, and fix documentation + of png_get_text() in libpng.txt/libpng.3. + +Version 1.0.5s [February 18, 2000] + Added "png_jmp_env()" macro to pngconf.h, to help people migrate to the + new error handler that's planned for the next libpng release, and changed + example.c, pngtest.c, and contrib programs to use this macro. + Revised some of the DLL-export macros in pngconf.h (Greg Roelofs) + Fixed a bug in png_read_png() that caused it to fail to expand some images + that it should have expanded. + Fixed some mistakes in the unused and undocumented INCH_CONVERSIONS functions + in pngget.c + Changed the allocation of palette, history, and trans arrays back to + the version 1.0.5 method (linking instead of copying) which restores + backward compatibility with version 1.0.5. Added some remarks about + that in example.c. Added "free_me" member to info_ptr and png_ptr + and added png_free_data() function. + Updated makefile.linux and makefile.gccmmx to make directories conditionally. + Made cosmetic changes to pngasmrd.h + Added png_set_rows() and png_get_rows(), for use with png_read|write_png(). + Modified png_read_png() to allocate info_ptr->row_pointers only if it + hasn't already been allocated. + +Version 1.0.5t [March 4, 2000] + Changed png_jmp_env() migration aiding macro to png_jmpbuf(). + Fixed "interlace" typo (should be "interlaced") in contrib/gregbook/read2-x.c + Fixed bug with use of PNG_BEFORE_IHDR bit in png_ptr->mode, introduced when + PNG_FLAG_HAVE_CHUNK_HEADER was moved into png_ptr->mode in version 1.0.5b + Files in contrib/gregbook were revised to use png_jmpbuf() and to select + a 24-bit visual if one is available, and to allow abbreviated options. + Files in contrib/pngminus were revised to use the png_jmpbuf() macro. + Removed spaces in makefile.linux and makefile.gcmmx, introduced in 1.0.5s + +Version 1.0.5u [March 5, 2000] + Simplified the code that detects old png.h in png.c and pngtest.c + Renamed png_spalette (_p, _pp) to png_sPLT_t (_tp, _tpp) + Increased precision of rgb_to_gray calculations from 8 to 15 bits and + added png_set_rgb_to_gray_fixed() function. + Added makefile.bc32 (32-bit Borland C++, C mode) + +Version 1.0.5v [March 11, 2000] + Added some parentheses to the png_jmpbuf macro definition. + Updated references to the zlib home page, which has moved to freesoftware.com. + Corrected bugs in documentation regarding png_read_row() and png_write_row(). + Updated documentation of png_rgb_to_gray calculations in libpng.3/libpng.txt. + Renamed makefile.borland,turboc3 back to makefile.bor,tc3 as in version 1.0.3, + revised borland makefiles; added makefile.ibmvac3 and makefile.gcc (Cosmin) + +Version 1.0.6 [March 20, 2000] + Minor revisions of makefile.bor, libpng.txt, and gregbook/rpng2-win.c + Added makefile.sggcc (SGI IRIX with gcc) + +Version 1.0.6d [April 7, 2000] + Changed sprintf() to strcpy() in png_write_sCAL_s() to work without STDIO + Added data_length parameter to png_decompress_chunk() function + Revised documentation to remove reference to abandoned png_free_chnk functions + Fixed an error in png_rgb_to_gray_fixed() + Revised example.c, usage of png_destroy_write_struct(). + Renamed makefile.ibmvac3 to makefile.ibmc, added libpng.icc IBM project file + Added a check for info_ptr->free_me&PNG_FREE_TEXT when freeing text in png.c + Simplify png_sig_bytes() function to remove use of non-ISO-C strdup(). + +Version 1.0.6e [April 9, 2000] + Added png_data_freer() function. + In the code that checks for over-length tRNS chunks, added check of + info_ptr->num_trans as well as png_ptr->num_trans (Matthias Benckmann) + Minor revisions of libpng.txt/libpng.3. + Check for existing data and free it if the free_me flag is set, in png_set_*() + and png_handle_*(). + Only define PNG_WEIGHTED_FILTERS_SUPPORTED when PNG_FLOATING_POINT_SUPPORTED + is defined. + Changed several instances of PNG_NO_CONSOLE_ID to PNG_NO_STDIO in pngrutil.c + and mentioned the purposes of the two macros in libpng.txt/libpng.3. + +Version 1.0.6f [April 14, 2000] + Revised png_set_iCCP() and png_set_rows() to avoid prematurely freeing data. + Add checks in png_set_text() for NULL members of the input text structure. + Revised libpng.txt/libpng.3. + Removed superfluous prototype for png_set_iTXt from png.h + Removed "else" from pngread.c, after png_error(), and changed "0" to "length". + Changed several png_errors about malformed ancillary chunks to png_warnings. + +Version 1.0.6g [April 24, 2000] + Added png_pass-* arrays to pnggccrd.c when PNG_USE_LOCAL_ARRAYS is defined. + Relocated paragraph about png_set_background() in libpng.3/libpng.txt + and other revisions (Matthias Benckmann) + Relocated info_ptr->free_me, png_ptr->free_me, and other info_ptr and + png_ptr members to restore binary compatibility with libpng-1.0.5 + (breaks compatibility with libpng-1.0.6). + +Version 1.0.6h [April 24, 2000] + Changed shared library so-number pattern from 2.x.y.z to xy.z (this builds + libpng.so.10 & libpng.so.10.6h instead of libpng.so.2 & libpng.so.2.1.0.6h) + This is a temporary change for test purposes. + +Version 1.0.6i [May 2, 2000] + Rearranged some members at the end of png_info and png_struct, to put + unknown_chunks_num and free_me within the original size of the png_structs + and free_me, png_read_user_fn, and png_free_fn within the original png_info, + because some old applications allocate the structs directly instead of + using png_create_*(). + Added documentation of user memory functions in libpng.txt/libpng.3 + Modified png_read_png so that it will use user_allocated row_pointers + if present, unless free_me directs that it be freed, and added description + of the use of png_set_rows() and png_get_rows() in libpng.txt/libpng.3. + Added PNG_LEGACY_SUPPORTED macro, and #ifdef out all new (since version + 1.00) members of png_struct and png_info, to regain binary compatibility + when you define this macro. Capabilities lost in this event + are user transforms (new in version 1.0.0),the user transform pointer + (new in version 1.0.2), rgb_to_gray (new in 1.0.5), iCCP, sCAL, sPLT, + the high-level interface, and unknown chunks support (all new in 1.0.6). + This was necessary because of old applications that allocate the structs + directly as authors were instructed to do in libpng-0.88 and earlier, + instead of using png_create_*(). + Added modes PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT which + can be used to detect codes that directly allocate the structs, and + code to check these modes in png_read_init() and png_write_init() and + generate a libpng error if the modes aren't set and PNG_LEGACY_SUPPORTED + was not defined. + Added makefile.intel and updated makefile.watcom (Pawel Mrochen) + +Version 1.0.6j [May 3, 2000] + Overloaded png_read_init() and png_write_init() with macros that convert + calls to png_read_init_2() or png_write_init_2() that check the version + and structure sizes. + +Version 1.0.7beta11 [May 7, 2000] + Removed the new PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT modes + which are no longer used. + Eliminated the three new members of png_text when PNG_LEGACY_SUPPORTED is + defined or when neither PNG_READ_iTXt_SUPPORTED nor PNG_WRITE_iTXT_SUPPORTED + is defined. + Made PNG_NO_READ|WRITE_iTXt the default setting, to avoid memory + overrun when old applications fill the info_ptr->text structure directly. + Added PNGAPI macro, and added it to the definitions of all exported functions. + Relocated version macro definitions ahead of the includes of zlib.h and + pngconf.h in png.h. + +Version 1.0.7beta12 [May 12, 2000] + Revised pngset.c to avoid a problem with expanding the png_debug macro. + Deleted some extraneous defines from pngconf.h + Made PNG_NO_CONSOLE_IO the default condition when PNG_BUILD_DLL is defined. + Use MSC _RPTn debugging instead of fprintf if _MSC_VER is defined. + Added png_access_version_number() function. + Check for mask&PNG_FREE_CHNK (for TEXT, SCAL, PCAL) in png_free_data(). + Expanded libpng.3/libpng.txt information about png_data_freer(). + +Version 1.0.7beta14 [May 17, 2000] (beta13 was not published) + Changed pnggccrd.c and pngvcrd.c to handle bad adaptive filter types as + warnings instead of errors, as pngrutil.c does. + Set the PNG_INFO_IDAT valid flag in png_set_rows() so png_write_png() + will actually write IDATs. + Made the default PNG_USE_LOCAL_ARRAYS depend on PNG_DLL instead of WIN32. + Make png_free_data() ignore its final parameter except when freeing data + that can have multiple instances (text, sPLT, unknowns). + Fixed a new bug in png_set_rows(). + Removed info_ptr->valid tests from png_free_data(), as in version 1.0.5. + Added png_set_invalid() function. + Fixed incorrect illustrations of png_destroy_write_struct() in example.c. + +Version 1.0.7beta15 [May 30, 2000] + Revised the deliberately erroneous Linux setjmp code in pngconf.h to produce + fewer error messages. + Rearranged checks for Z_OK to check the most likely path first in pngpread.c + and pngwutil.c. + Added checks in pngtest.c for png_create_*() returning NULL, and mentioned + in libpng.txt/libpng.3 the need for applications to check this. + Changed names of png_default_*() functions in pngtest to pngtest_*(). + Changed return type of png_get_x|y_offset_*() from png_uint_32 to png_int_32. + Fixed some bugs in the unused PNG_INCH_CONVERSIONS functions in pngget.c + Set each pointer to NULL after freeing it in png_free_data(). + Worked around a problem in pngconf.h; AIX's strings.h defines an "index" + macro that conflicts with libpng's png_color_16.index. (Dimitri + Papadapoulos) + Added "msvc" directory with MSVC++ project files (Simon-Pierre Cadieux). + +Version 1.0.7beta16 [June 4, 2000] + Revised the workaround of AIX string.h "index" bug. + Added a check for overlength PLTE chunk in pngrutil.c. + Added PNG_NO_POINTER_INDEXING macro to use array-indexing instead of pointer + indexing in pngrutil.c and pngwutil.c to accommodate a buggy compiler. + Added a warning in png_decompress_chunk() when it runs out of data, e.g. + when it tries to read an erroneous PhotoShop iCCP chunk. + Added PNG_USE_DLL macro. + Revised the copyright/disclaimer/license notice. + Added contrib/msvctest directory + +Version 1.0.7rc1 [June 9, 2000] + Corrected the definition of PNG_TRANSFORM_INVERT_ALPHA (0x0400 not 0x0200) + Added contrib/visupng directory (Willem van Schaik) + +Version 1.0.7beta18 [June 23, 2000] + Revised PNGAPI definition, and pngvcrd.c to work with __GCC__ + and do not redefine PNGAPI if it is passed in via a compiler directive. + Revised visupng/PngFile.c to remove returns from within the Try block. + Removed leading underscores from "_PNG_H" and "_PNG_SAVE_BSD_SOURCE" macros. + Updated contrib/visupng/cexcept.h to version 1.0.0. + Fixed bugs in pngwrite.c and pngwutil.c that prevented writing iCCP chunks. + +Version 1.0.7rc2 [June 28, 2000] + Updated license to include disclaimers required by UCITA. + Fixed "DJBPP" typo in pnggccrd.c introduced in beta18. + +Version 1.0.7 [July 1, 2000] + Revised the definition of "trans_values" in libpng.3/libpng.txt + +Version 1.0.8beta1 [July 8, 2000] + Added png_free(png_ptr, key) two places in pngpread.c to stop memory leaks. + Changed PNG_NO_STDIO to PNG_NO_CONSOLE_IO, several places in pngrutil.c and + pngwutil.c. + Changed PNG_EXPORT_VAR to use PNG_IMPEXP, in pngconf.h. + Removed unused "#include " from png.c + Added WindowsCE support. + Revised pnggccrd.c to work with gcc-2.95.2 and in the Cygwin environment. + +Version 1.0.8beta2 [July 10, 2000] + Added project files to the wince directory and made further revisions + of pngtest.c, pngrio.c, and pngwio.c in support of WindowsCE. + +Version 1.0.8beta3 [July 11, 2000] + Only set the PNG_FLAG_FREE_TRNS or PNG_FREE_TRNS flag in png_handle_tRNS() + for indexed-color input files to avoid potential double-freeing trans array + under some unusual conditions; problem was introduced in version 1.0.6f. + Further revisions to pngtest.c and files in the wince subdirectory. + +Version 1.0.8beta4 [July 14, 2000] + Added the files pngbar.png and pngbar.jpg to the distribution. + Added makefile.cygwin, and cygwin support in pngconf.h + Added PNG_NO_ZALLOC_ZERO macro (makes png_zalloc skip zeroing memory) + +Version 1.0.8rc1 [July 16, 2000] + Revised png_debug() macros and statements to eliminate compiler warnings. + +Version 1.0.8 [July 24, 2000] + Added png_flush() in pngwrite.c, after png_write_IEND(). + Updated makefile.hpux to build a shared library. + +Version 1.0.9beta1 [November 10, 2000] + Fixed typo in scripts/makefile.hpux + Updated makevms.com in scripts and contrib/* and contrib/* (Martin Zinser) + Fixed seqence-point bug in contrib/pngminus/png2pnm (Martin Zinser) + Changed "cdrom.com" in documentation to "libpng.org" + Revised pnggccrd.c to get it all working, and updated makefile.gcmmx (Greg). + Changed type of "params" from voidp to png_voidp in png_read|write_png(). + Make sure PNGAPI and PNG_IMPEXP are defined in pngconf.h. + Revised the 3 instances of WRITEFILE in pngtest.c. + Relocated "msvc" and "wince" project subdirectories into "dll" subdirectory. + Updated png.rc in dll/msvc project + Revised makefile.dec to define and use LIBPATH and INCPATH + Increased size of global png_libpng_ver[] array from 12 to 18 chars. + Made global png_libpng_ver[], png_sig[] and png_pass_*[] arrays const. + Removed duplicate png_crc_finish() from png_handle_bKGD() function. + Added a warning when application calls png_read_update_info() multiple times. + Revised makefile.cygwin + Fixed bugs in iCCP support in pngrutil.c and pngwutil.c. + Replaced png_set_empty_plte_permitted() with png_permit_mng_features(). + +Version 1.0.9beta2 [November 19, 2000] + Renamed the "dll" subdirectory "projects". + Added borland project files to "projects" subdirectory. + Set VS_FF_PRERELEASE and VS_FF_PATCHED flags in msvc/png.rc when appropriate. + Add error message in png_set_compression_buffer_size() when malloc fails. + +Version 1.0.9beta3 [November 23, 2000] + Revised PNG_LIBPNG_BUILD_TYPE macro in png.h, used in the msvc project. + Removed the png_flush() in pngwrite.c that crashes some applications + that don't set png_output_flush_fn. + Added makefile.macosx and makefile.aix to scripts directory. + +Version 1.0.9beta4 [December 1, 2000] + Change png_chunk_warning to png_warning in png_check_keyword(). + Increased the first part of msg buffer from 16 to 18 in png_chunk_error(). + +Version 1.0.9beta5 [December 15, 2000] + Added support for filter method 64 (for PNG datastreams embedded in MNG). + +Version 1.0.9beta6 [December 18, 2000] + Revised png_set_filter() to accept filter method 64 when appropriate. + Added new PNG_HAVE_PNG_SIGNATURE bit to png_ptr->mode and use it to + help prevent applications from using MNG features in PNG datastreams. + Added png_permit_mng_features() function. + Revised libpng.3/libpng.txt. Changed "filter type" to "filter method". + +Version 1.0.9rc1 [December 23, 2000] + Revised test for PNG_HAVE_PNG_SIGNATURE in pngrutil.c + Fixed error handling of unknown compression type in png_decompress_chunk(). + In pngconf.h, define __cdecl when _MSC_VER is defined. + +Version 1.0.9beta7 [December 28, 2000] + Changed PNG_TEXT_COMPRESSION_zTXt to PNG_COMPRESSION_TYPE_BASE several places. + Revised memory management in png_set_hIST and png_handle_hIST in a backward + compatible manner. PLTE and tRNS were revised similarly. + Revised the iCCP chunk reader to ignore trailing garbage. + +Version 1.0.9beta8 [January 12, 2001] + Moved pngasmrd.h into pngconf.h. + Improved handling of out-of-spec garbage iCCP chunks generated by PhotoShop. + +Version 1.0.9beta9 [January 15, 2001] + Added png_set_invalid, png_permit_mng_features, and png_mmx_supported to + wince and msvc project module definition files. + Minor revision of makefile.cygwin. + Fixed bug with progressive reading of narrow interlaced images in pngpread.c + +Version 1.0.9beta10 [January 16, 2001] + Do not typedef png_FILE_p in pngconf.h when PNG_NO_STDIO is defined. + Fixed "png_mmx_supported" typo in project definition files. + +Version 1.0.9beta11 [January 19, 2001] + Updated makefile.sgi to make shared library. + Removed png_mmx_support() function and disabled PNG_MNG_FEATURES_SUPPORTED + by default, for the benefit of DLL forward compatibility. These will + be re-enabled in version 1.2.0. + +Version 1.0.9rc2 [January 22, 2001] + Revised cygwin support. + +Version 1.0.9 [January 31, 2001] + Added check of cygwin's ALL_STATIC in pngconf.h + Added "-nommx" parameter to contrib/gregbook/rpng2-win and rpng2-x demos. + +Version 1.0.10beta1 [March 14, 2001] + Revised makefile.dec, makefile.sgi, and makefile.sggcc; added makefile.hpgcc. + Reformatted libpng.3 to eliminate bad line breaks. + Added checks for _mmx_supported in the read_filter_row function of pnggccrd.c + Added prototype for png_mmx_support() near the top of pnggccrd.c + Moved some error checking from png_handle_IHDR to png_set_IHDR. + Added PNG_NO_READ_SUPPORTED and PNG_NO_WRITE_SUPPORTED macros. + Revised png_mmx_support() function in pnggccrd.c + Restored version 1.0.8 PNG_WRITE_EMPTY_PLTE_SUPPORTED behavior in pngwutil.c + Fixed memory leak in contrib/visupng/PngFile.c + Fixed bugs in png_combine_row() in pnggccrd.c and pngvcrd.c (C version) + Added warnings when retrieving or setting gamma=0. + Increased the first part of msg buffer from 16 to 18 in png_chunk_warning(). + +Version 1.0.10rc1 [March 23, 2001] + Changed all instances of memcpy, strcpy, and strlen to png_memcpy, png_strcpy, + and png_strlen. + Revised png_mmx_supported() function in pnggccrd.c to return proper value. + Fixed bug in progressive reading (pngpread.c) with small images (height < 8). + +Version 1.0.10 [March 30, 2001] + Deleted extraneous space (introduced in 1.0.9) from line 42 of makefile.cygwin + Added beos project files (Chris Herborth) + +Version 1.0.11beta1 [April 3, 2001] + Added type casts on several png_malloc() calls (Dimitri Papadapoulos). + Removed a no-longer needed AIX work-around from pngconf.h + Changed several "//" single-line comments to C-style in pnggccrd.c + +Version 1.0.11beta2 [April 11, 2001] + Removed PNGAPI from several functions whose prototypes did not have PNGAPI. + Updated scripts/pngos2.def + +Version 1.0.11beta3 [April 14, 2001] + Added checking the results of many instances of png_malloc() for NULL + +Version 1.0.11beta4 [April 20, 2001] + Undid the changes from version 1.0.11beta3. Added a check for NULL return + from user's malloc_fn(). + Removed some useless type casts of the NULL pointer. + Added makefile.netbsd + +Version 1.0.11 [April 27, 2001] + Revised makefile.netbsd + +Version 1.0.12beta1 [May 14, 2001] + Test for Windows platform in pngconf.h when including malloc.h (Emmanuel Blot) + Updated makefile.cygwin and handling of Cygwin's ALL_STATIC in pngconf.h + Added some never-to-be-executed code in pnggccrd.c to quiet compiler warnings. + Eliminated the png_error about apps using png_read|write_init(). Instead, + libpng will reallocate the png_struct and info_struct if they are too small. + This retains future binary compatibility for old applications written for + libpng-0.88 and earlier. + +Version 1.2.0beta1 [May 6, 2001] + Bumped DLLNUM to 2. + Re-enabled PNG_MNG_FEATURES_SUPPORTED and enabled PNG_ASSEMBLER_CODE_SUPPORTED + by default. + Added runtime selection of MMX features. + Added png_set_strip_error_numbers function and related macros. + +Version 1.2.0beta2 [May 7, 2001] + Finished merging 1.2.0beta1 with version 1.0.11 + Added a check for attempts to read or write PLTE in grayscale PNG datastreams. + +Version 1.2.0beta3 [May 17, 2001] + Enabled user memory function by default. + Modified png_create_struct so it passes user mem_ptr to user memory allocator. + Increased png_mng_features flag from png_byte to png_uint_32. + Bumped shared-library (so-number) and dll-number to 3. + +Version 1.2.0beta4 [June 23, 2001] + Check for missing profile length field in iCCP chunk and free chunk_data + in case of truncated iCCP chunk. + Bumped shared-library number to 3 in makefile.sgi and makefile.sggcc + Bumped dll-number from 2 to 3 in makefile.cygwin + Revised contrib/gregbook/rpng*-x.c to avoid a memory leak and to exit cleanly + if user attempts to run it on an 8-bit display. + Updated contrib/gregbook + Use png_malloc instead of png_zalloc to allocate palette in pngset.c + Updated makefile.ibmc + Added some typecasts to eliminate gcc 3.0 warnings. Changed prototypes + of png_write_oFFS width and height from png_uint_32 to png_int_32. + Updated example.c + Revised prototypes for png_debug_malloc and png_debug_free in pngtest.c + +Version 1.2.0beta5 [August 8, 2001] + Revised contrib/gregbook + Revised makefile.gcmmx + Revised pnggccrd.c to conditionally compile some thread-unsafe code only + when PNG_THREAD_UNSAFE_OK is defined. + Added tests to prevent pngwutil.c from writing a bKGD or tRNS chunk with + value exceeding 2^bit_depth-1 + Revised makefile.sgi and makefile.sggcc + Replaced calls to fprintf(stderr,...) with png_warning() in pnggccrd.c + Removed restriction that do_invert_mono only operate on 1-bit opaque files + +Version 1.2.0 [September 1, 2001] + Changed a png_warning() to png_debug() in pnggccrd.c + Fixed contrib/gregbook/rpng-x.c, rpng2-x.c to avoid crash with XFreeGC(). + +Version 1.2.1beta1 [October 19, 2001] + Revised makefile.std in contrib/pngminus + Include background_1 in png_struct regardless of gamma support. + Revised makefile.netbsd and makefile.macosx, added makefile.darwin. + Revised example.c to provide more details about using row_callback(). + +Version 1.2.1beta2 [October 25, 2001] + Added type cast to each NULL appearing in a function call, except for + WINCE functions. + Added makefile.so9. + +Version 1.2.1beta3 [October 27, 2001] + Removed type casts from all NULLs. + Simplified png_create_struct_2(). + +Version 1.2.1beta4 [November 7, 2001] + Revised png_create_info_struct() and png_creat_struct_2(). + Added error message if png_write_info() was omitted. + Type cast NULLs appearing in function calls when _NO_PROTO or + PNG_TYPECAST_NULL is defined. + +Version 1.2.1rc1 [November 24, 2001] + Type cast NULLs appearing in function calls except when PNG_NO_TYPECAST_NULL + is defined. + Changed typecast of "size" argument to png_size_t in pngmem.c calls to + the user malloc_fn, to agree with the prototype in png.h + Added a pop/push operation to pnggccrd.c, to preserve Eflag (Maxim Sobolev) + Updated makefile.sgi to recognize LIBPATH and INCPATH. + Updated various makefiles so "make clean" does not remove previous major + version of the shared library. + +Version 1.2.1rc2 [December 4, 2001] + Always allocate 256-entry internal palette, hist, and trans arrays, to + avoid out-of-bounds memory reference caused by invalid PNG datastreams. + Added a check for prefix_length > data_length in iCCP chunk handler. + +Version 1.2.1 [December 7, 2001] + None. + +Version 1.2.2beta1 [February 22, 2002] + Fixed a bug with reading the length of iCCP profiles (Larry Reeves). + Revised makefile.linux, makefile.gcmmx, and makefile.sgi to generate + libpng.a, libpng12.so (not libpng.so.3), and libpng12/png.h + Revised makefile.darwin to remove "-undefined suppress" option. + Added checks for gamma and chromaticity values over 21474.83, which exceed + the limit for PNG unsigned 32-bit integers when encoded. + Revised calls to png_create_read_struct() and png_create_write_struct() + for simpler debugging. + Revised png_zalloc() so zlib handles errors (uses PNG_FLAG_MALLOC_NULL_MEM_OK) + +Version 1.2.2beta2 [February 23, 2002] + Check chunk_length and idat_size for invalid (over PNG_MAX_UINT) lengths. + Check for invalid image dimensions in png_get_IHDR. + Added missing "fi;" in the install target of the SGI makefiles. + Added install-static to all makefiles that make shared libraries. + Always do gamma compensation when image is partially transparent. + +Version 1.2.2beta3 [March 7, 2002] + Compute background.gray and background_1.gray even when color_type is RGB + in case image gets reduced to gray later. + Modified shared-library makefiles to install pkgconfig/libpngNN.pc. + Export (with PNGAPI) png_zalloc, png_zfree, and png_handle_as_unknown + Removed unused png_write_destroy_info prototype from png.h + Eliminated incorrect use of width_mmx from pnggccrd.c in pixel_bytes == 8 case + Added install-shared target to all makefiles that make shared libraries. + Stopped a double free of palette, hist, and trans when not using free_me. + Added makefile.32sunu for Sun Ultra 32 and makefile.64sunu for Sun Ultra 64. + +Version 1.2.2beta4 [March 8, 2002] + Compute background.gray and background_1.gray even when color_type is RGB + in case image gets reduced to gray later (Jason Summers). + Relocated a misplaced /bin/rm in the "install-shared" makefile targets + Added PNG_1_0_X macro which can be used to build a 1.0.x-compatible library. + +Version 1.2.2beta5 [March 26, 2002] + Added missing PNGAPI to several function definitions. + Check for invalid bit_depth or color_type in png_get_IHDR(), and + check for missing PLTE or IHDR in png_push_read_chunk() (Matthias Clasen). + Revised iTXt support to accept NULL for lang and lang_key. + Compute gamma for color components of background even when color_type is gray. + Changed "()" to "{}" in scripts/libpng.pc.in. + Revised makefiles to put png.h and pngconf.h only in $prefix/include/libpngNN + Revised makefiles to make symlink to libpng.so.NN in addition to libpngNN.so + +Version 1.2.2beta6 [March 31, 2002] + +Version 1.0.13beta1 [March 31, 2002] + Prevent png_zalloc() from trying to memset memory that it failed to acquire. + Add typecasts of PNG_MAX_UINT in pngset_cHRM_fixed() (Matt Holgate). + Ensure that the right function (user or default) is used to free the + png_struct after an error in png_create_read_struct_2(). + +Version 1.2.2rc1 [April 7, 2002] + +Version 1.0.13rc1 [April 7, 2002] + Save the ebx register in pnggccrd.c (Sami Farin) + Add "mem_ptr = png_ptr->mem_ptr" in png_destroy_write_struct() (Paul Gardner). + Updated makefiles to put headers in include/libpng and remove old include/*.h. + +Version 1.2.2 [April 15, 2002] + +Version 1.0.13 [April 15, 2002] + Revised description of png_set_filter() in libpng.3/libpng.txt. + Revised makefile.netbsd and added makefile.neNNbsd and makefile.freebsd + +Version 1.0.13patch01 [April 17, 2002] + +Version 1.2.2patch01 [April 17, 2002] + Changed ${PNGMAJ}.${PNGVER} bug to ${PNGVER} in makefile.sgi and + makefile.sggcc + Fixed VER -> PNGVER typo in makefile.macosx and added install-static to + install + Added install: target to makefile.32sunu and makefile.64sunu + +Version 1.0.13patch03 [April 18, 2002] + +Version 1.2.2patch03 [April 18, 2002] + Revised 15 makefiles to link libpng.a to libpngNN.a and the include libpng + subdirectory to libpngNN subdirectory without the full pathname. + Moved generation of libpng.pc from "install" to "all" in 15 makefiles. + +Version 1.2.3rc1 [April 28, 2002] + Added install-man target to 15 makefiles (Dimitri Papadopolous-Orfanos). + Added $(DESTDIR) feature to 24 makefiles (Tim Mooney) + Fixed bug with $prefix, should be $(prefix) in makefile.hpux. + Updated cygwin-specific portion of pngconf.h and revised makefile.cygwin + Added a link from libpngNN.pc to libpng.pc in 15 makefiles. + Added links from include/libpngNN/*.h to include/*.h in 24 makefiles. + Revised makefile.darwin to make relative links without full pathname. + Added setjmp() at the end of png_create_*_struct_2() in case user forgets + to put one in their application. + Restored png_zalloc() and png_zfree() prototypes to version 1.2.1 and + removed them from module definition files. + +Version 1.2.3rc2 [May 1, 2002] + Fixed bug in reporting number of channels in pngget.c and pngset.c, + that was introduced in version 1.2.2beta5. + Exported png_zalloc(), png_zfree(), png_default_read(), png_default_write(), + png_default_flush(), and png_push_fill_buffer() and included them in + module definition files. + Added "libpng.pc" dependency to the "install-shared" target in 15 makefiles. + +Version 1.2.3rc3 [May 1, 2002] + Revised prototype for png_default_flush() + Remove old libpng.pc and libpngNN.pc before installing new ones. + +Version 1.2.3rc4 [May 2, 2002] + Typos in *.def files (png_default_read|write -> png_default_read|write_data) + In makefiles, changed rm libpng.NN.pc to rm libpngNN.pc + Added libpng-config and libpngNN-config and modified makefiles to install + them. + Changed $(MANPATH) to $(DESTDIR)$(MANPATH) in makefiles + Added "Win32 DLL VB" configuration to projects/msvc/libpng.dsp + +Version 1.2.3rc5 [May 11, 2002] + Changed "error" and "message" in prototypes to "error_message" and + "warning_message" to avoid namespace conflict. + Revised 15 makefiles to build libpng-config from libpng-config-*.in + Once more restored png_zalloc and png_zfree to regular nonexported form. + Restored png_default_read|write_data, png_default_flush, png_read_fill_buffer + to nonexported form, but with PNGAPI, and removed them from module def + files. + +Version 1.2.3rc6 [May 14, 2002] + Removed "PNGAPI" from png_zalloc() and png_zfree() in png.c + Changed "Gz" to "Gd" in projects/msvc/libpng.dsp and zlib.dsp. + Removed leftover libpng-config "sed" script from four makefiles. + Revised libpng-config creating script in 16 makefiles. + +Version 1.2.3 [May 22, 2002] + Revised libpng-config target in makefile.cygwin. + Removed description of png_set_mem_fn() from documentation. + Revised makefile.freebsd. + Minor cosmetic changes to 15 makefiles, e.g., $(DI) = $(DESTDIR)/$(INCDIR). + Revised projects/msvc/README.txt + Changed -lpng to -lpngNN in LDFLAGS in several makefiles. + +Version 1.2.4beta1 [May 24, 2002] + Added libpng.pc and libpng-config to "all:" target in 16 makefiles. + Fixed bug in 16 makefiles: $(DESTDIR)/$(LIBPATH) to $(DESTDIR)$(LIBPATH) + Added missing "\" before closing double quote in makefile.gcmmx. + Plugged various memory leaks; added png_malloc_warn() and png_set_text_2() + functions. + +Version 1.2.4beta2 [June 25, 2002] + Plugged memory leak of png_ptr->current_text (Matt Holgate). + Check for buffer overflow before reading CRC in pngpread.c (Warwick Allison) + Added -soname to the loader flags in makefile.dec, makefile.sgi, and + makefile.sggcc. + Added "test-installed" target to makefile.linux, makefile.gcmmx, + makefile.sgi, and makefile.sggcc. + +Version 1.2.4beta3 [June 28, 2002] + Plugged memory leak of row_buf in pngtest.c when there is a png_error(). + Detect buffer overflow in pngpread.c when IDAT is corrupted with extra data. + Added "test-installed" target to makefile.32sunu, makefile.64sunu, + makefile.beos, makefile.darwin, makefile.dec, makefile.macosx, + makefile.solaris, makefile.hpux, makefile.hpgcc, and makefile.so9. + +Version 1.2.4rc1 and 1.0.14rc1 [July 2, 2002] + Added "test-installed" target to makefile.cygwin and makefile.sco. + Revised pnggccrd.c to be able to back out version 1.0.x via PNG_1_0_X macro. + +Version 1.2.4 and 1.0.14 [July 8, 2002] + Changed png_warning() to png_error() when width is too large to process. + +Version 1.2.4patch01 [July 20, 2002] + Revised makefile.cygwin to use DLL number 12 instead of 13. + +Version 1.2.5beta1 [August 6, 2002] + Added code to contrib/gregbook/readpng2.c to ignore unused chunks. + Replaced toucan.png in contrib/gregbook (it has been corrupt since 1.0.11) + Removed some stray *.o files from contrib/gregbook. + Changed png_error() to png_warning() about "Too much data" in pngpread.c + and about "Extra compressed data" in pngrutil.c. + Prevent png_ptr->pass from exceeding 7 in png_push_finish_row(). + Updated makefile.hpgcc + Updated png.c and pnggccrd.c handling of return from png_mmx_support() + +Version 1.2.5beta2 [August 15, 2002] + Only issue png_warning() about "Too much data" in pngpread.c when avail_in + is nonzero. + Updated makefiles to install a separate libpng.so.3 with its own rpath. + +Version 1.2.5rc1 and 1.0.15rc1 [August 24, 2002] + Revised makefiles to not remove previous minor versions of shared libraries. + +Version 1.2.5rc2 and 1.0.15rc2 [September 16, 2002] + Revised 13 makefiles to remove "-lz" and "-L$(ZLIBLIB)", etc., from shared + library loader directive. + Added missing "$OBJSDLL" line to makefile.gcmmx. + Added missing "; fi" to makefile.32sunu. + +Version 1.2.5rc3 and 1.0.15rc3 [September 18, 2002] + Revised libpng-config script. + +Version 1.2.5 and 1.0.15 [October 3, 2002] + Revised makefile.macosx, makefile.darwin, makefile.hpgcc, and makefile.hpux, + and makefile.aix. + Relocated two misplaced PNGAPI lines in pngtest.c + +Version 1.2.6beta1 [October 22, 2002] + Commented out warning about uninitialized mmx_support in pnggccrd.c. + Changed "IBMCPP__" flag to "__IBMCPP__" in pngconf.h. + Relocated two more misplaced PNGAPI lines in pngtest.c + Fixed memory overrun bug in png_do_read_filler() with 16-bit datastreams, + introduced in version 1.0.2. + Revised makefile.macosx, makefile.dec, makefile.aix, and makefile.32sunu. + +Version 1.2.6beta2 [November 1, 2002] + Added libpng-config "--ldopts" output. + Added "AR=ar" and "ARFLAGS=rc" and changed "ar rc" to "$(AR) $(ARFLAGS)" + in makefiles. + +Version 1.2.6beta3 [July 18, 2004] + Reverted makefile changes from version 1.2.6beta2 and some of the changes + from version 1.2.6beta1; these will be postponed until version 1.2.7. + Version 1.2.6 is going to be a simple bugfix release. + Changed the one instance of "ln -sf" to "ln -f -s" in each Sun makefile. + Fixed potential overrun in pngerror.c by using strncpy instead of memcpy. + Added "#!/bin/sh" at the top of configure, for recognition of the + 'x' flag under Cygwin (Cosmin). + Optimized vacuous tests that silence compiler warnings, in png.c (Cosmin). + Added support for PNG_USER_CONFIG, in pngconf.h (Cosmin). + Fixed the special memory handler for Borland C under DOS, in pngmem.c + (Cosmin). + Removed some spurious assignments in pngrutil.c (Cosmin). + Replaced 65536 with 65536L, and 0xffff with 0xffffL, to silence warnings + on 16-bit platforms (Cosmin). + Enclosed shift op expressions in parentheses, to silence warnings (Cosmin). + Used proper type png_fixed_point, to avoid problems on 16-bit platforms, + in png_handle_sRGB() (Cosmin). + Added compression_type to png_struct, and optimized the window size + inside the deflate stream (Cosmin). + Fixed definition of isnonalpha(), in pngerror.c and pngrutil.c (Cosmin). + Fixed handling of unknown chunks that come after IDAT (Cosmin). + Allowed png_error() and png_warning() to work even if png_ptr == NULL + (Cosmin). + Replaced row_info->rowbytes with row_bytes in png_write_find_filter() + (Cosmin). + Fixed definition of PNG_LIBPNG_VER_DLLNUM (Simon-Pierre). + Used PNG_LIBPNG_VER and PNG_LIBPNG_VER_STRING instead of the hardcoded + values in png.c (Simon-Pierre, Cosmin). + Initialized png_libpng_ver[] with PNG_LIBPNG_VER_STRING (Simon-Pierre). + Replaced PNG_LIBPNG_VER_MAJOR with PNG_LIBPNG_VER_DLLNUM in png.rc + (Simon-Pierre). + Moved the definition of PNG_HEADER_VERSION_STRING near the definitions + of the other PNG_LIBPNG_VER_... symbols in png.h (Cosmin). + Relocated #ifndef PNGAPI guards in pngconf.h (Simon-Pierre, Cosmin). + Updated scripts/makefile.vc(a)win32 (Cosmin). + Updated the MSVC project (Simon-Pierre, Cosmin). + Updated the Borland C++ Builder project (Cosmin). + Avoided access to asm_flags in pngvcrd.c, if PNG_1_0_X is defined (Cosmin). + Commented out warning about uninitialized mmx_support in pngvcrd.c (Cosmin). + Removed scripts/makefile.bd32 and scripts/pngdef.pas (Cosmin). + Added extra guard around inclusion of Turbo C memory headers, in pngconf.h + (Cosmin). + Renamed projects/msvc/ to projects/visualc6/, and projects/borland/ to + projects/cbuilder5/ (Cosmin). + Moved projects/visualc6/png32ms.def to scripts/pngw32.def, + and projects/visualc6/png.rc to scripts/pngw32.rc (Cosmin). + Added projects/visualc6/pngtest.dsp; removed contrib/msvctest/ (Cosmin). + Changed line endings to DOS style in cbuilder5 and visualc6 files, even + in the tar.* distributions (Cosmin). + Updated contrib/visupng/VisualPng.dsp (Cosmin). + Updated contrib/visupng/cexcept.h to version 2.0.0 (Cosmin). + Added a separate distribution with "configure" and supporting files (Junichi). + +Version 1.2.6beta4 [July 28, 2004] + Added user ability to change png_size_t via a PNG_SIZE_T macro. + Added png_sizeof() and png_convert_size() functions. + Added PNG_SIZE_MAX (maximum value of a png_size_t variable. + Added check in png_malloc_default() for (size_t)size != (png_uint_32)size + which would indicate an overflow. + Changed sPLT failure action from png_error to png_warning and abandon chunk. + Changed sCAL and iCCP failures from png_error to png_warning and abandon. + Added png_get_uint_31(png_ptr, buf) function. + Added PNG_UINT_32_MAX macro. + Renamed PNG_MAX_UINT to PNG_UINT_31_MAX. + Made png_zalloc() issue a png_warning and return NULL on potential + overflow. + Turn on PNG_NO_ZALLOC_ZERO by default in version 1.2.x + Revised "clobber list" in pnggccrd.c so it will compile under gcc-3.4. + Revised Borland portion of png_malloc() to return NULL or issue + png_error() according to setting of PNG_FLAG_MALLOC_NULL_MEM_OK. + Added PNG_NO_SEQUENTIAL_READ_SUPPORTED macro to conditionally remove + sequential read support. + Added some "#if PNG_WRITE_SUPPORTED" blocks. + Added #ifdef to remove some redundancy in png_malloc_default(). + Use png_malloc instead of png_zalloc to allocate the pallete. + +Version 1.0.16rc1 and 1.2.6rc1 [August 4, 2004] + Fixed buffer overflow vulnerability in png_handle_tRNS() + Fixed integer arithmetic overflow vulnerability in png_read_png(). + Fixed some harmless bugs in png_handle_sBIT, etc, that would cause + duplicate chunk types to go undetected. + Fixed some timestamps in the -config version + Rearranged order of processing of color types in png_handle_tRNS(). + Added ROWBYTES macro to calculate rowbytes without integer overflow. + Updated makefile.darwin and removed makefile.macosx from scripts directory. + Imposed default one million column, one-million row limits on the image + dimensions, and added png_set_user_limits() function to override them. + Revised use of PNG_SET_USER_LIMITS_SUPPORTED macro. + Fixed wrong cast of returns from png_get_user_width|height_max(). + Changed some "keep the compiler happy" from empty statements to returns, + Revised libpng.txt to remove 1.2.x stuff from the 1.0.x distribution + +Version 1.0.16rc2 and 1.2.6rc2 [August 7, 2004] + Revised makefile.darwin and makefile.solaris. Removed makefile.macosx. + Revised pngtest's png_debug_malloc() to use png_malloc() instead of + png_malloc_default() which is not supposed to be exported. + Fixed off-by-one error in one of the conversions to PNG_ROWBYTES() in + pngpread.c. Bug was introduced in 1.2.6rc1. + Fixed bug in RGB to RGBX transformation introduced in 1.2.6rc1. + Fixed old bug in RGB to Gray transformation. + Fixed problem with 64-bit compilers by casting arguments to abs() + to png_int_32. + Changed "ln -sf" to "ln -f -s" in three makefiles (solaris, sco, so9). + Changed "HANDLE_CHUNK_*" to "PNG_HANDLE_CHUNK_*" (Cosmin) + Added "-@/bin/rm -f $(DL)/$(LIBNAME).so.$(PNGMAJ)" to 15 *NIX makefiles. + Added code to update the row_info->colortype in png_do_read_filler() (MSB). + +Version 1.0.16rc3 and 1.2.6rc3 [August 9, 2004] + Eliminated use of "abs()" in testing cHRM and gAMA values, to avoid + trouble with some 64-bit compilers. Created PNG_OUT_OF_RANGE() macro. + Revised documentation of png_set_keep_unknown_chunks(). + Check handle_as_unknown status in pngpread.c, as in pngread.c previously. + Moved "PNG_HANDLE_CHUNK_*" macros out of PNG_INTERNAL section of png.h + Added "rim" definitions for CONST4 and CONST6 in pnggccrd.c + +Version 1.0.16rc4 and 1.2.6rc4 [August 10, 2004] + Fixed mistake in pngtest.c introduced in 1.2.6rc2 (declaration of + "pinfo" was out of place). + +Version 1.0.16rc5 and 1.2.6rc5 [August 10, 2004] + Moved "PNG_HANDLE_CHUNK_*" macros out of PNG_ASSEMBLER_CODE_SUPPORTED + section of png.h where they were inadvertently placed in version rc3. + +Version 1.2.6 and 1.0.16 [August 15, 2004] + Revised pngtest so memory allocation testing is only done when PNG_DEBUG==1. + +Version 1.2.7beta1 [August 26, 2004] + Removed unused pngasmrd.h file. + Removed references to uu.net for archived files. Added references to + PNG Spec (second edition) and the PNG ISO/IEC Standard. + Added "test-dd" target in 15 makefiles, to run pngtest in DESTDIR. + Fixed bug with "optimized window size" in the IDAT datastream, that + causes libpng to write PNG files with incorrect zlib header bytes. + +Version 1.2.7beta2 [August 28, 2004] + Fixed bug with sCAL chunk and big-endian machines (David Munro). + Undid new code added in 1.2.6rc2 to update the color_type in + png_set_filler(). + Added png_set_add_alpha() that updates color type. + +Version 1.0.17rc1 and 1.2.7rc1 [September 4, 2004] + Revised png_set_strip_filler() to not remove alpha if color_type has alpha. + +Version 1.2.7 and 1.0.17 [September 12, 2004] + Added makefile.hp64 + Changed projects/msvc/png32ms.def to scripts/png32ms.def in makefile.cygwin + +Version 1.2.8beta1 [November 1, 2004] + Fixed bug in png_text_compress() that would fail to complete a large block. + Fixed bug, introduced in libpng-1.2.7, that overruns a buffer during + strip alpha operation in png_do_strip_filler(). + Added PNG_1_2_X definition in pngconf.h + Use #ifdef to comment out png_info_init in png.c and png_read_init in + pngread.c (as of 1.3.0) + +Version 1.2.8beta2 [November 2, 2004] + Reduce color_type to a nonalpha type after strip alpha operation in + png_do_strip_filler(). + +Version 1.2.8beta3 [November 3, 2004] + Revised definitions of PNG_MAX_UINT_32, PNG_MAX_SIZE, and PNG_MAXSUM + +Version 1.2.8beta4 [November 12, 2004] + Fixed (again) definition of PNG_LIBPNG_VER_DLLNUM in png.h (Cosmin). + Added PNG_LIBPNG_BUILD_PRIVATE in png.h (Cosmin). + Set png_ptr->zstream.data_type to Z_BINARY, to avoid unnecessary detection + of data type in deflate (Cosmin). + Deprecated but continue to support SPECIALBUILD and PRIVATEBUILD in favor of + PNG_LIBPNG_BUILD_SPECIAL_STRING and PNG_LIBPNG_BUILD_PRIVATE_STRING. + +Version 1.2.8beta5 [November 20, 2004] + Use png_ptr->flags instead of png_ptr->transformations to pass + PNG_STRIP_ALPHA info to png_do_strip_filler(), to preserve ABI + compatibility. + Revised handling of SPECIALBUILD, PRIVATEBUILD, + PNG_LIBPNG_BUILD_SPECIAL_STRING and PNG_LIBPNG_BUILD_PRIVATE_STRING. + +Version 1.2.8rc1 [November 24, 2004] + Moved handling of BUILD macros from pngconf.h to png.h + Added definition of PNG_LIBPNG_BASE_TYPE in png.h, inadvertently + omitted from beta5. + Revised scripts/pngw32.rc + Despammed mailing addresses by masking "@" with "at". + Inadvertently installed a supposedly faster test version of pngrutil.c + +Version 1.2.8rc2 [November 26, 2004] + Added two missing "\" in png.h + Change tests in pngread.c and pngpread.c to + if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) + png_do_read_transformations(png_ptr); + +Version 1.2.8rc3 [November 28, 2004] + Reverted pngrutil.c to version libpng-1.2.8beta5. + Added scripts/makefile.elf with supporting code in pngconf.h for symbol + versioning (John Bowler). + +Version 1.2.8rc4 [November 29, 2004] + Added projects/visualc7 (Simon-pierre). + +Version 1.2.8rc5 [November 29, 2004] + Fixed new typo in scripts/pngw32.rc + +Version 1.2.8 [December 3, 2004] + Removed projects/visualc7, added projects/visualc71. + +Version 1.2.9beta1 [February 21, 2006] + Initialized some structure members in pngwutil.c to avoid gcc-4.0.0 complaints + Revised man page and libpng.txt to make it clear that one should not call + png_read_end or png_write_end after png_read_png or png_write_png. + Updated references to png-mng-implement mailing list. + Fixed an incorrect typecast in pngrutil.c + Added PNG_NO_READ_SUPPORTED conditional for making a write-only library. + Added PNG_NO_WRITE_INTERLACING_SUPPORTED conditional. + Optimized alpha-inversion loops in pngwtran.c + Moved test for nonzero gamma outside of png_build_gamma_table() in pngrtran.c + Make sure num_trans is <= 256 before copying data in png_set_tRNS(). + Make sure num_palette is <= 256 before copying data in png_set_PLTE(). + Interchanged order of write_swap_alpha and write_invert_alpha transforms. + Added parentheses in the definition of PNG_LIBPNG_BUILD_TYPE (Cosmin). + Optimized zlib window flag (CINFO) in contrib/pngsuite/*.png (Cosmin). + Updated scripts/makefile.bc32 for Borland C++ 5.6 (Cosmin). + Exported png_get_uint_32, png_save_uint_32, png_get_uint_16, png_save_uint_16, + png_get_int_32, png_save_int_32, png_get_uint_31 (Cosmin). + Added type cast (png_byte) in png_write_sCAL() (Cosmin). + Fixed scripts/makefile.cygwin (Christian Biesinger, Cosmin). + Default iTXt support was inadvertently enabled. + +Version 1.2.9beta2 [February 21, 2006] + Check for png_rgb_to_gray and png_gray_to_rgb read transformations before + checking for png_read_dither in pngrtran.c + Revised checking of chromaticity limits to accommodate extended RGB + colorspace (John Denker). + Changed line endings in some of the project files to CRLF, even in the + "Unix" tar distributions (Cosmin). + Made png_get_int_32 and png_save_int_32 always available (Cosmin). + Updated scripts/pngos2.def, scripts/pngw32.def and projects/wince/png32ce.def + with the newly exported functions. + Eliminated distributions without the "configure" script. + Updated INSTALL instructions. + +Version 1.2.9beta3 [February 24, 2006] + Fixed CRCRLF line endings in contrib/visupng/VisualPng.dsp + Made libpng.pc respect EXEC_PREFIX (D. P. Kreil, J. Bowler) + Removed reference to pngasmrd.h from Makefile.am + Renamed CHANGES to ChangeLog. + Renamed LICENSE to COPYING. + Renamed ANNOUNCE to NEWS. + Created AUTHORS file. + +Version 1.2.9beta4 [March 3, 2006] + Changed definition of PKGCONFIG from $prefix/lib to $libdir in configure.ac + Reverted to filenames LICENSE and ANNOUNCE; removed AUTHORS and COPYING. + Removed newline from the end of some error and warning messages. + Removed test for sqrt() from configure.ac and configure. + Made swap tables in pngtrans.c PNG_CONST (Carlo Bramix). + Disabled default iTXt support that was inadvertently enabled in + libpng-1.2.9beta1. + Added "OS2" to list of systems that don't need underscores, in pnggccrd.c + Removed libpng version and date from *.c files. + +Version 1.2.9beta5 [March 4, 2006] + Removed trailing blanks from source files. + Put version and date of latest change in each source file, and changed + copyright year accordingly. + More cleanup of configure.ac, Makefile.am, and associated scripts. + Restored scripts/makefile.elf which was inadvertently deleted. + +Version 1.2.9beta6 [March 6, 2006] + Fixed typo (RELEASE) in configuration files. + +Version 1.2.9beta7 [March 7, 2006] + Removed libpng.vers and libpng.sym from libpng12_la_SOURCES in Makefile.am + Fixed inconsistent #ifdef's around png_sig_bytes() and png_set_sCAL_s() + in png.h. + Updated makefile.elf as suggested by debian. + Made cosmetic changes to some makefiles, adding LN_SF and other macros. + Made some makefiles accept "exec_prefix". + +Version 1.2.9beta8 [March 9, 2006] + Fixed some "#if defined (..." which should be "#if defined(..." + Bug introduced in libpng-1.2.8. + Fixed inconsistency in definition of png_default_read_data() + Restored blank that was lost from makefile.sggcc "clean" target in beta7. + Revised calculation of "current" and "major" for irix in ltmain.sh + Changed "mkdir" to "MKDIR_P" in some makefiles. + Separated PNG_EXPAND and PNG_EXPAND_tRNS. + Added png_set_expand_gray_1_2_4_to_8() and deprecated + png_set_gray_1_2_4_to_8() which also expands tRNS to alpha. + +Version 1.2.9beta9 [March 10, 2006] + Include "config.h" in pngconf.h when available. + Added some checks for NULL png_ptr or NULL info_ptr (timeless) + +Version 1.2.9beta10 [March 20, 2006] + Removed extra CR from contrib/visualpng/VisualPng.dsw (Cosmin) + Made pnggccrd.c PIC-compliant (Christian Aichinger). + Added makefile.mingw (Wolfgang Glas). + Revised pngconf.h MMX checking. + +Version 1.2.9beta11 [March 22, 2006] + Fixed out-of-order declaration in pngwrite.c that was introduced in beta9 + Simplified some makefiles by using LIBSO, LIBSOMAJ, and LIBSOVER macros. + +Version 1.2.9rc1 [March 31, 2006] + Defined PNG_USER_PRIVATEBUILD when including "pngusr.h" (Cosmin). + Removed nonsensical assertion check from pngtest.c (Cosmin). + +Version 1.2.9 [April 14, 2006] + Revised makefile.beos and added "none" selector in ltmain.sh + +Version 1.2.10beta1 [April 15, 2006] + Renamed "config.h" to "png_conf.h" and revised Makefile.am to add + -DPNG_BUILDING_LIBPNG to compile directive, and modified pngconf.h + to include png_conf.h only when PNG_BUILDING_LIBPNG is defined. + +Version 1.2.10beta2 [April 15, 2006] + Manually updated Makefile.in and configure. Changed png_conf.h.in + back to config.h. + +Version 1.2.10beta3 [April 15, 2006] + Change png_conf.h back to config.h in pngconf.h. + +Version 1.2.10beta4 [April 16, 2006] + Change PNG_BUILDING_LIBPNG to PNG_CONFIGURE_LIBPNG in config/Makefile*. + +Version 1.2.10beta5 [April 16, 2006] + Added a configure check for compiling assembler code in pnggccrd.c + +Version 1.2.10beta6 [April 17, 2006] + Revised the configure check for pnggccrd.c + Moved -DPNG_CONFIGURE_LIBPNG into @LIBPNG_DEFINES@ + Added @LIBPNG_DEFINES@ to arguments when building libpng.sym + +Version 1.2.10beta7 [April 18, 2006] + Change "exec_prefix=$prefix" to "exec_prefix=$(prefix)" in makefiles. + +Version 1.2.10rc1 [April 19, 2006] + Ensure pngconf.h doesn't define both PNG_USE_PNGGCCRD and PNG_USE_PNGVCRD + Fixed "LN_FS" typo in makefile.sco and makefile.solaris. + +Version 1.2.10rc2 [April 20, 2006] + Added a backslash between -DPNG_CONFIGURE_LIBPNG and -DPNG_NO_ASSEMBLER_CODE + in configure.ac and configure + Made the configure warning about versioned symbols less arrogant. + +Version 1.2.10rc3 [April 21, 2006] + Added a note in libpng.txt that png_set_sig_bytes(8) can be used when + writing an embedded PNG without the 8-byte signature. + Revised makefiles and configure to avoid making links to libpng.so.* + +Version 1.2.10 [April 23, 2006] + Reverted configure to "rc2" state. + +Version 1.2.11beta1 [May 31, 2006] + scripts/libpng.pc.in contained "configure" style version info and would + not work with makefiles. + The shared-library makefiles were linking to libpng.so.0 instead of + libpng.so.3 compatibility as the library. + +Version 1.2.11beta2 [June 2, 2006] + Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid + buffer overflow. + Fixed bug in example.c (png_set_palette_rgb -> png_set_palette_to_rgb) + +Version 1.2.11beta3 [June 5, 2006] + Prepended "#! /bin/sh" to ltmail.sh and contrib/pngminus/*.sh (Cosmin). + Removed the accidental leftover Makefile.in~ (Cosmin). + Avoided potential buffer overflow and optimized buffer in + png_write_sCAL(), png_write_sCAL_s() (Cosmin). + Removed the include directories and libraries from CFLAGS and LDFLAGS + in scripts/makefile.gcc (Nelson A. de Oliveira, Cosmin). + +Version 1.2.11beta4 [June 6, 2006] + Allow zero-length IDAT chunks after the entire zlib datastream, but not + after another intervening chunk type. + +Version 1.0.19rc1, 1.2.11rc1 [June 13, 2006] + Deleted extraneous square brackets from [config.h] in configure.ac + +Version 1.0.19rc2, 1.2.11rc2 [June 14, 2006] + Added prototypes for PNG_INCH_CONVERSIONS functions to png.h + Revised INSTALL and autogen.sh + Fixed typo in several makefiles (-W1 should be -Wl) + Added typedef for png_int_32 and png_uint_32 on 64-bit systems. + +Version 1.0.19rc3, 1.2.11rc3 [June 15, 2006] + Removed the new typedefs for 64-bit systems (delay until version 1.4.0) + Added one zero element to png_gamma_shift[] array in pngrtran.c to avoid + reading out of bounds. + +Version 1.0.19rc4, 1.2.11rc4 [June 15, 2006] + Really removed the new typedefs for 64-bit systems. + +Version 1.0.19rc5, 1.2.11rc5 [June 22, 2006] + Removed png_sig_bytes entry from scripts/pngw32.def + +Version 1.0.19, 1.2.11 [June 26, 2006] + None. + +Version 1.0.20, 1.2.12 [June 27, 2006] + Really increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid + buffer overflow. + +Version 1.2.13beta1 [October 2, 2006] + Removed AC_FUNC_MALLOC from configure.ac + Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h + Change "logical" to "bitwise" throughout documentation. + Detect and fix attempt to write wrong iCCP profile length (CVE-2006-7244) + +Version 1.0.21, 1.2.13 [November 14, 2006] + Fix potential buffer overflow in sPLT chunk handler. + Fix Makefile.am to not try to link to noexistent files. + Check all exported functions for NULL png_ptr. + +Version 1.2.14beta1 [November 17, 2006] + Relocated three misplaced tests for NULL png_ptr. + Built Makefile.in with automake-1.9.6 instead of 1.9.2. + Build configure with autoconf-2.60 instead of 2.59 + +Version 1.2.14beta2 [November 17, 2006] + Added some typecasts in png_zalloc(). + +Version 1.2.14rc1 [November 20, 2006] + Changed "strtod" to "png_strtod" in pngrutil.c + +Version 1.0.22, 1.2.14 [November 27, 2006] + Added missing "$(srcdir)" in Makefile.am and Makefile.in + +Version 1.2.15beta1 [December 3, 2006] + Generated configure with autoconf-2.61 instead of 2.60 + Revised configure.ac to update libpng.pc and libpng-config. + +Version 1.2.15beta2 [December 3, 2006] + Always export MMX asm functions, just stubs if not building pnggccrd.c + +Version 1.2.15beta3 [December 4, 2006] + Add "png_bytep" typecast to profile while calculating length in pngwutil.c + +Version 1.2.15beta4 [December 7, 2006] + Added scripts/CMakeLists.txt + Changed PNG_NO_ASSEMBLER_CODE to PNG_NO_MMX_CODE in scripts, like 1.4.0beta + +Version 1.2.15beta5 [December 7, 2006] + Changed some instances of PNG_ASSEMBLER_* to PNG_MMX_* in pnggccrd.c + Revised scripts/CMakeLists.txt + +Version 1.2.15beta6 [December 13, 2006] + Revised scripts/CMakeLists.txt and configure.ac + +Version 1.2.15rc1 [December 18, 2006] + Revised scripts/CMakeLists.txt + +Version 1.2.15rc2 [December 21, 2006] + Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers. + Added scripts/makefile.nommx + +Version 1.2.15rc3 [December 25, 2006] + Fixed shared library numbering error that was introduced in 1.2.15beta6. + +Version 1.2.15rc4 [December 27, 2006] + Fixed handling of rgb_to_gray when png_ptr->color.gray isn't set. + +Version 1.2.15rc5 [December 31, 2006] + Revised handling of rgb_to_gray. + +Version 1.2.15 [January 5, 2007] + Added some (unsigned long) typecasts in pngtest.c to avoid printing errors. + +Version 1.2.16beta1 [January 6, 2007] + Fix bugs in makefile.nommx + +Version 1.2.16beta2 [January 16, 2007] + Revised scripts/CMakeLists.txt + +Version 1.2.16 [January 31, 2007] + No changes. + +Version 1.2.17beta1 [March 6, 2007] + Revised scripts/CMakeLists.txt to install both shared and static libraries. + Deleted a redundant line from pngset.c. + +Version 1.2.17beta2 [April 26, 2007] + Relocated misplaced test for png_ptr == NULL in pngpread.c + Change "==" to "&" for testing PNG_RGB_TO_GRAY_ERR & PNG_RGB_TO_GRAY_WARN + flags. + Changed remaining instances of PNG_ASSEMBLER_* to PNG_MMX_* + Added pngerror() when write_IHDR fails in deflateInit2(). + Added "const" to some array declarations. + Mention examples of libpng usage in the libpng*.txt and libpng.3 documents. + +Version 1.2.17rc1 [May 4, 2007] + No changes. + +Version 1.2.17rc2 [May 8, 2007] + Moved several PNG_HAVE_* macros out of PNG_INTERNAL because applications + calling set_unknown_chunk_location() need them. + Changed transformation flag from PNG_EXPAND_tRNS to PNG_EXPAND in + png_set_expand_gray_1_2_4_to_8(). + Added png_ptr->unknown_chunk to hold working unknown chunk data, so it + can be free'ed in case of error. Revised unknown chunk handling in + pngrutil.c and pngpread.c to use this structure. + +Version 1.2.17rc3 [May 8, 2007] + Revised symbol-handling in configure script. + +Version 1.2.17rc4 [May 10, 2007] + Revised unknown chunk handling to avoid storing unknown critical chunks. + +Version 1.0.25 [May 15, 2007] +Version 1.2.17 [May 15, 2007] + Added "png_ptr->num_trans=0" before error return in png_handle_tRNS, + to eliminate a vulnerability (CVE-2007-2445, CERT VU#684664) + +Version 1.0.26 [May 15, 2007] +Version 1.2.18 [May 15, 2007] + Reverted the libpng-1.2.17rc3 change to symbol-handling in configure script + +Version 1.2.19beta1 [May 18, 2007] + Changed "const static" to "static PNG_CONST" everywhere, mostly undoing + change of libpng-1.2.17beta2. Changed other "const" to "PNG_CONST" + Changed some handling of unused parameters, to avoid compiler warnings. + "if (unused == NULL) return;" becomes "unused = unused". + +Version 1.2.19beta2 [May 18, 2007] + Only use the valid bits of tRNS value in png_do_expand() (Brian Cartier) + +Version 1.2.19beta3 [May 19, 2007] + Add some "png_byte" typecasts in png_check_keyword() and write new_key + instead of key in zTXt chunk (Kevin Ryde). + +Version 1.2.19beta4 [May 21, 2007] + Add png_snprintf() function and use it in place of sprint() for improved + defense against buffer overflows. + +Version 1.2.19beta5 [May 21, 2007] + Fixed png_handle_tRNS() to only use the valid bits of tRNS value. + Changed handling of more unused parameters, to avoid compiler warnings. + Removed some PNG_CONST in pngwutil.c to avoid compiler warnings. + +Version 1.2.19beta6 [May 22, 2007] + Added some #ifdef PNG_MMX_CODE_SUPPORTED where needed in pngvcrd.c + Added a special "_MSC_VER" case that defines png_snprintf to _snprintf + +Version 1.2.19beta7 [May 22, 2007] + Squelched png_squelch_warnings() in pnggccrd.c and added + an #ifdef PNG_MMX_CODE_SUPPORTED block around the declarations that caused + the warnings that png_squelch_warnings was squelching. + +Version 1.2.19beta8 [May 22, 2007] + Removed __MMX__ from test in pngconf.h. + +Version 1.2.19beta9 [May 23, 2007] + Made png_squelch_warnings() available via PNG_SQUELCH_WARNINGS macro. + Revised png_squelch_warnings() so it might work. + Updated makefile.sgcc and makefile.solaris; added makefile.solaris-x86. + +Version 1.2.19beta10 [May 24, 2007] + Resquelched png_squelch_warnings(), use "__attribute__((used))" instead. + +Version 1.4.0beta1 [April 20, 2006] + Enabled iTXt support (changes png_struct, thus requires so-number change). + Cleaned up PNG_ASSEMBLER_CODE_SUPPORTED vs PNG_MMX_CODE_SUPPORTED + Eliminated PNG_1_0_X and PNG_1_2_X macros. + Removed deprecated functions png_read_init, png_write_init, png_info_init, + png_permit_empty_plte, png_set_gray_1_2_4_to_8, png_check_sig, and + removed the deprecated macro PNG_MAX_UINT. + Moved "PNG_INTERNAL" parts of png.h and pngconf.h into pngintrn.h + Removed many WIN32_WCE #ifdefs (Cosmin). + Reduced dependency on C-runtime library when on Windows (Simon-Pierre) + Replaced sprintf() with png_sprintf() (Simon-Pierre) + +Version 1.4.0beta2 [April 20, 2006] + Revised makefiles and configure to avoid making links to libpng.so.* + Moved some leftover MMX-related defines from pngconf.h to pngintrn.h + Updated scripts/pngos2.def, pngw32.def, and projects/wince/png32ce.def + +Version 1.4.0beta3 [May 10, 2006] + Updated scripts/pngw32.def to comment out MMX functions. + Added PNG_NO_GET_INT_32 and PNG_NO_SAVE_INT_32 macros. + Scripts/libpng.pc.in contained "configure" style version info and would + not work with makefiles. + Revised pngconf.h and added pngconf.h.in, so makefiles and configure can + pass defines to libpng and applications. + +Version 1.4.0beta4 [May 11, 2006] + Revised configure.ac, Makefile.am, and many of the makefiles to write + their defines in pngconf.h. + +Version 1.4.0beta5 [May 15, 2006] + Added a missing semicolon in Makefile.am and Makefile.in + Deleted extraneous square brackets from configure.ac + +Version 1.4.0beta6 [June 2, 2006] + Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid + buffer overflow. + Changed sonum from 0 to 1. + Removed unused prototype for png_check_sig() from png.h + +Version 1.4.0beta7 [June 16, 2006] + Exported png_write_sig (Cosmin). + Optimized buffer in png_handle_cHRM() (Cosmin). + Set pHYs = 2835 x 2835 pixels per meter, and added + sCAL = 0.352778e-3 x 0.352778e-3 meters, in pngtest.png (Cosmin). + Added png_set_benign_errors(), png_benign_error(), png_chunk_benign_error(). + Added typedef for png_int_32 and png_uint_32 on 64-bit systems. + Added "(unsigned long)" typecast on png_uint_32 variables in printf lists. + +Version 1.4.0beta8 [June 22, 2006] + Added demonstration of user chunk support in pngtest.c, to support the + public sTER chunk and a private vpAg chunk. + +Version 1.4.0beta9 [July 3, 2006] + Removed ordinals from scripts/pngw32.def and removed png_info_int and + png_set_gray_1_2_4_to_8 entries. + Inline call of png_get_uint_32() in png_get_uint_31(). + Use png_get_uint_31() to get vpAg width and height in pngtest.c + Removed WINCE and Netware projects. + Removed standalone Y2KINFO file. + +Version 1.4.0beta10 [July 12, 2006] + Eliminated automatic copy of pngconf.h to pngconf.h.in from configure and + some makefiles, because it was not working reliably. Instead, distribute + pngconf.h.in along with pngconf.h and cause configure and some of the + makefiles to update pngconf.h from pngconf.h.in. + Added pngconf.h to DEPENDENCIES in Makefile.am + +Version 1.4.0beta11 [August 19, 2006] + Removed AC_FUNC_MALLOC from configure.ac. + Added a warning when writing iCCP profile with mismatched profile length. + Patched pnggccrd.c to assemble on x86_64 platforms. + Moved chunk header reading into a separate function png_read_chunk_header() + in pngrutil.c. The chunk header (len+sig) is now serialized in a single + operation (Cosmin). + Implemented support for I/O states. Added png_ptr member io_state, and + functions png_get_io_chunk_name() and png_get_io_state() in pngget.c + (Cosmin). + Added png_get_io_chunk_name and png_get_io_state to scripts/*.def (Cosmin). + Renamed scripts/pngw32.* to scripts/pngwin.* (Cosmin). + Removed the include directories and libraries from CFLAGS and LDFLAGS + in scripts/makefile.gcc (Cosmin). + Used png_save_uint_32() to set vpAg width and height in pngtest.c (Cosmin). + Cast to proper type when getting/setting vpAg units in pngtest.c (Cosmin). + Added pngintrn.h to the Visual C++ projects (Cosmin). + Removed scripts/list (Cosmin). + Updated copyright year in scripts/pngwin.def (Cosmin). + Removed PNG_TYPECAST_NULL and used standard NULL consistently (Cosmin). + Disallowed the user to redefine png_size_t, and enforced a consistent use + of png_size_t across libpng (Cosmin). + Changed the type of png_ptr->rowbytes, PNG_ROWBYTES() and friends + to png_size_t (Cosmin). + Removed png_convert_size() and replaced png_sizeof with sizeof (Cosmin). + Removed some unnecessary type casts (Cosmin). + Changed prototype of png_get_compression_buffer_size() and + png_set_compression_buffer_size() to work with png_size_t instead of + png_uint_32 (Cosmin). + Removed png_memcpy_check() and png_memset_check() (Cosmin). + Fixed a typo (png_byte --> png_bytep) in libpng.3 and libpng.txt (Cosmin). + Clarified that png_zalloc() does not clear the allocated memory, + and png_zalloc() and png_zfree() cannot be PNGAPI (Cosmin). + Renamed png_mem_size_t to png_alloc_size_t, fixed its definition in + pngconf.h, and used it in all memory allocation functions (Cosmin). + Renamed pngintrn.h to pngpriv.h, added a comment at the top of the file + mentioning that the symbols declared in that file are private, and + updated the scripts and the Visual C++ projects accordingly (Cosmin). + Removed circular references between pngconf.h and pngconf.h.in in + scripts/makefile.vc*win32 (Cosmin). + Removing trailing '.' from the warning and error messages (Cosmin). + Added pngdefs.h that is built by makefile or configure, instead of + pngconf.h.in (Glenn). + Detect and fix attempt to write wrong iCCP profile length. + +Version 1.4.0beta12 [October 19, 2006] + Changed "logical" to "bitwise" in the documentation. + Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h + Add a typecast to stifle compiler warning in pngrutil.c + +Version 1.4.0beta13 [November 10, 2006] + Fix potential buffer overflow in sPLT chunk handler. + Fix Makefile.am to not try to link to noexistent files. + +Version 1.4.0beta14 [November 15, 2006] + Check all exported functions for NULL png_ptr. + +Version 1.4.0beta15 [November 17, 2006] + Relocated two misplaced tests for NULL png_ptr. + Built Makefile.in with automake-1.9.6 instead of 1.9.2. + Build configure with autoconf-2.60 instead of 2.59 + Add "install: all" in Makefile.am so "configure; make install" will work. + +Version 1.4.0beta16 [November 17, 2006] + Added a typecast in png_zalloc(). + +Version 1.4.0beta17 [December 4, 2006] + Changed "new_key[79] = '\0';" to "(*new_key)[79] = '\0';" in pngwutil.c + Add "png_bytep" typecast to profile while calculating length in pngwutil.c + +Version 1.4.0beta18 [December 7, 2006] + Added scripts/CMakeLists.txt + +Version 1.4.0beta19 [May 16, 2007] + Revised scripts/CMakeLists.txt + Rebuilt configure and Makefile.in with newer tools. + Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers. + Added scripts/makefile.nommx + +Version 1.4.0beta20 [July 9, 2008] + Moved several PNG_HAVE_* macros from pngpriv.h to png.h because applications + calling set_unknown_chunk_location() need them. + Moved several macro definitions from pngpriv.h to pngconf.h + Merge with changes to the 1.2.X branch, as of 1.2.30beta04. + Deleted all use of the MMX assembler code and Intel-licensed optimizations. + Revised makefile.mingw + +Version 1.4.0beta21 [July 21, 2008] + Moved local array "chunkdata" from pngrutil.c to the png_struct, so + it will be freed by png_read_destroy() in case of a read error (Kurt + Christensen). + +Version 1.4.0beta22 [July 21, 2008] + Change "purpose" and "buffer" to png_ptr->chunkdata to avoid memory leaking. + +Version 1.4.0beta23 [July 22, 2008] + Change "chunkdata = NULL" to "png_ptr->chunkdata = NULL" several places in + png_decompress_chunk(). + +Version 1.4.0beta24 [July 25, 2008] + Change all remaining "chunkdata" to "png_ptr->chunkdata" in + png_decompress_chunk(), and remove "chunkdata" from parameter list. + Put a call to png_check_chunk_name() in png_read_chunk_header(). + Revised png_check_chunk_name() to reject a name with a lowercase 3rd byte. + Removed two calls to png_check_chunk_name() occuring later in the process. + Define PNG_NO_ERROR_NUMBERS by default in pngconf.h + +Version 1.4.0beta25 [July 30, 2008] + Added a call to png_check_chunk_name() in pngpread.c + Reverted png_check_chunk_name() to accept a name with a lowercase 3rd byte. + Added png_push_have_buffer() function to pngpread.c + Eliminated PNG_BIG_ENDIAN_SUPPORTED and associated png_get_* macros. + Made inline expansion of png_get_*() optional with PNG_USE_READ_MACROS. + Eliminated all PNG_USELESS_TESTS and PNG_CORRECT_PALETTE_SUPPORTED code. + Synced contrib directory and configure files with libpng-1.2.30beta06. + Eliminated no-longer-used pngdefs.h (but it's still built in the makefiles) + Relocated a misplaced "#endif /* PNG_NO_WRITE_FILTER */" in pngwutil.c + +Version 1.4.0beta26 [August 4, 2008] + Removed png_push_have_buffer() function in pngpread.c. It increased the + compiled library size slightly. + Changed "-Wall" to "-W -Wall" in the CFLAGS in all makefiles (Cosmin Truta) + Declared png_ptr "volatile" in pngread.c and pngwrite.c to avoid warnings. + Updated contrib/visupng/cexcept.h to version 2.0.1 + Added PNG_LITERAL_CHARACTER macros for #, [, and ]. + +Version 1.4.0beta27 [August 5, 2008] + Revised usage of PNG_LITERAL_SHARP in pngerror.c. + Moved newline character from individual png_debug messages into the + png_debug macros. + Allow user to #define their own png_debug, png_debug1, and png_debug2. + +Version 1.4.0beta28 [August 5, 2008] + Revised usage of PNG_LITERAL_SHARP in pngerror.c. + Added PNG_STRING_NEWLINE macro + +Version 1.4.0beta29 [August 9, 2008] + Revised usage of PNG_STRING_NEWLINE to work on non-ISO compilers. + Added PNG_STRING_COPYRIGHT macro. + Added non-ISO versions of png_debug macros. + +Version 1.4.0beta30 [August 14, 2008] + Added premultiplied alpha feature (Volker Wiendl). + +Version 1.4.0beta31 [August 18, 2008] + Moved png_set_premultiply_alpha from pngtrans.c to pngrtran.c + Removed extra crc check at the end of png_handle_cHRM(). Bug introduced + in libpng-1.4.0beta20. + +Version 1.4.0beta32 [August 19, 2008] + Added PNG_WRITE_FLUSH_SUPPORTED block around new png_flush() call. + Revised PNG_NO_STDIO version of png_write_flush() + +Version 1.4.0beta33 [August 20, 2008] + Added png_get|set_chunk_cache_max() to limit the total number of sPLT, + text, and unknown chunks that can be stored. + +Version 1.4.0beta34 [September 6, 2008] + Shortened tIME_string to 29 bytes in pngtest.c + Fixed off-by-one error introduced in png_push_read_zTXt() function in + libpng-1.2.30beta04/pngpread.c (Harald van Dijk) + +Version 1.4.0beta35 [October 6, 2008] + Changed "trans_values" to "trans_color". + Changed so-number from 0 to 14. Some OS do not like 0. + Revised makefile.darwin to fix shared library numbering. + Change png_set_gray_1_2_4_to_8() to png_set_expand_gray_1_2_4_to_8() + in example.c (debian bug report) + +Version 1.4.0beta36 [October 25, 2008] + Sync with tEXt vulnerability fix in libpng-1.2.33rc02. + +Version 1.4.0beta37 [November 13, 2008] + Added png_check_cHRM in png.c and moved checking from pngget.c, pngrutil.c, + and pngwrite.c + +Version 1.4.0beta38 [November 22, 2008] + Added check for zero-area RGB cHRM triangle in png_check_cHRM() and + png_check_cHRM_fixed(). + +Version 1.4.0beta39 [November 23, 2008] + Revised png_warning() to write its message on standard output by default + when warning_fn is NULL. + +Version 1.4.0beta40 [November 24, 2008] + Eliminated png_check_cHRM(). Instead, always use png_check_cHRM_fixed(). + In png_check_cHRM_fixed(), ensure white_y is > 0, and removed redundant + check for all-zero coordinates that is detected by the triangle check. + +Version 1.4.0beta41 [November 26, 2008] + Fixed string vs pointer-to-string error in png_check_keyword(). + Rearranged test expressions in png_check_cHRM_fixed() to avoid internal + overflows. + Added PNG_NO_CHECK_cHRM conditional. + +Version 1.4.0beta42, 43 [December 1, 2008] + Merge png_debug with version 1.2.34beta04. + +Version 1.4.0beta44 [December 6, 2008] + Removed redundant check for key==NULL before calling png_check_keyword() + to ensure that new_key gets initialized and removed extra warning + (Merge with version 1.2.34beta05 -- Arvan Pritchard). + +Version 1.4.0beta45 [December 9, 2008] + In png_write_png(), respect the placement of the filler bytes in an earlier + call to png_set_filler() (Jim Barry). + +Version 1.4.0beta46 [December 10, 2008] + Undid previous change and added PNG_TRANSFORM_STRIP_FILLER_BEFORE and + PNG_TRANSFORM_STRIP_FILLER_AFTER conditionals and deprecated + PNG_TRANSFORM_STRIP_FILLER (Jim Barry). + +Version 1.4.0beta47 [December 15, 2008] + Support for dithering was disabled by default, because it has never + been well tested and doesn't work very well. The code has not + been removed, however, and can be enabled by building libpng with + PNG_READ_DITHER_SUPPORTED defined. + +Version 1.4.0beta48 [February 14, 2009] + Added new exported function png_calloc(). + Combined several instances of png_malloc(); png_memset() into png_calloc(). + Removed prototype for png_freeptr() that was added in libpng-1.4.0beta24 + but was never defined. + +Version 1.4.0beta49 [February 28, 2009] + Added png_fileno() macro to pngconf.h, used in pngwio.c + Corrected order of #ifdef's in png_debug definition in png.h + Fixed bug introduced in libpng-1.4.0beta48 with the memset arguments + for pcal_params. + Fixed order of #ifdef directives in the png_debug defines in png.h + (bug introduced in libpng-1.2.34/1.4.0beta29). + Revised comments in png_set_read_fn() and png_set_write_fn(). + +Version 1.4.0beta50 [March 18, 2009] + Use png_calloc() instead of png_malloc() to allocate big_row_buf when + reading an interlaced file, to avoid a possible UMR. + Undid revision of PNG_NO_STDIO version of png_write_flush(). Users + having trouble with fflush() can build with PNG_NO_WRITE_FLUSH defined + or supply their own flush_fn() replacement. + Revised libpng*.txt and png.h documentation about use of png_write_flush() + and png_set_write_fn(). + Removed fflush() from pngtest.c. + Added "#define PNG_NO_WRITE_FLUSH" to contrib/pngminim/encoder/pngusr.h + +Version 1.4.0beta51 [March 21, 2009] + Removed new png_fileno() macro from pngconf.h . + +Version 1.4.0beta52 [March 27, 2009] + Relocated png_do_chop() ahead of building gamma tables in pngrtran.c + This avoids building 16-bit gamma tables unnecessarily. + Removed fflush() from pngtest.c. + Added "#define PNG_NO_WRITE_FLUSH" to contrib/pngminim/encoder/pngusr.h + Added a section on differences between 1.0.x and 1.2.x to libpng.3/libpng.txt + +Version 1.4.0beta53 [April 1, 2009] + Removed some remaining MMX macros from pngpriv.h + Fixed potential memory leak of "new_name" in png_write_iCCP() (Ralph Giles) + +Version 1.4.0beta54 [April 13, 2009] + Added "ifndef PNG_SKIP_SETJMP_CHECK" block in pngconf.h to allow + application code writers to bypass the check for multiple inclusion + of setjmp.h when they know that it is safe to ignore the situation. + Eliminated internal use of setjmp() in pngread.c and pngwrite.c + Reordered ancillary chunks in pngtest.png to be the same as what + pngtest now produces, and made some cosmetic changes to pngtest output. + Eliminated deprecated png_read_init_3() and png_write_init_3() functions. + +Version 1.4.0beta55 [April 15, 2009] + Simplified error handling in pngread.c and pngwrite.c by putting + the new png_read_cleanup() and png_write_cleanup() functions inline. + +Version 1.4.0beta56 [April 25, 2009] + Renamed "user_chunk_data" to "my_user_chunk_data" in pngtest.c to suppress + "shadowed declaration" warning from gcc-4.3.3. + Renamed "gamma" to "png_gamma" in pngset.c to avoid "shadowed declaration" + warning about a global "gamma" variable in math.h on some platforms. + +Version 1.4.0beta57 [May 2, 2009] + Removed prototype for png_freeptr() that was added in libpng-1.4.0beta24 + but was never defined (again). + Rebuilt configure scripts with autoconf-2.63 instead of 2.62 + Removed pngprefs.h and MMX from makefiles + +Version 1.4.0beta58 [May 14, 2009] + Changed pngw32.def to pngwin.def in makefile.mingw (typo was introduced + in beta57). + Clarified usage of sig_bit versus sig_bit_p in example.c (Vincent Torri) + +Version 1.4.0beta59 [May 15, 2009] + Reformated sources in libpng style (3-space intentation, comment format) + Fixed typo in libpng docs (PNG_FILTER_AVE should be PNG_FILTER_AVG) + Added sections about the git repository and our coding style to the + documentation + Relocated misplaced #endif in pngwrite.c, sCAL chunk handler. + +Version 1.4.0beta60 [May 19, 2009] + Conditionally compile png_read_finish_row() which is not used by + progressive readers. + Added contrib/pngminim/preader to demonstrate building minimal progressive + decoder, based on contrib/gregbook with embedded libpng and zlib. + +Version 1.4.0beta61 [May 20, 2009] + In contrib/pngminim/*, renamed "makefile.std" to "makefile", since there + is only one makefile in those directories, and revised the README files + accordingly. + More reformatting of comments, mostly to capitalize sentences. + +Version 1.4.0beta62 [June 2, 2009] + Added "#define PNG_NO_WRITE_SWAP" to contrib/pngminim/encoder/pngusr.h + and "define PNG_NO_READ_SWAP" to decoder/pngusr.h and preader/pngusr.h + Reformatted several remaining "else statement" into two lines. + Added a section to the libpng documentation about using png_get_io_ptr() + in configure scripts to detect the presence of libpng. + +Version 1.4.0beta63 [June 15, 2009] + Revised libpng*.txt and libpng.3 to mention calling png_set_IHDR() + multiple times and to specify the sample order in the tRNS chunk, + because the ISO PNG specification has a typo in the tRNS table. + Changed several PNG_UNKNOWN_CHUNK_SUPPORTED to + PNG_HANDLE_AS_UNKNOWN_SUPPORTED, to make the png_set_keep mechanism + available for ignoring known chunks even when not saving unknown chunks. + Adopted preference for consistent use of "#ifdef" and "#ifndef" versus + "#if defined()" and "if !defined()" where possible. + +Version 1.4.0beta64 [June 24, 2009] + Eliminated PNG_LEGACY_SUPPORTED code. + Moved the various unknown chunk macro definitions outside of the + PNG_READ|WRITE_ANCILLARY_CHUNK_SUPPORTED blocks. + +Version 1.4.0beta65 [June 26, 2009] + Added a reference to the libpng license in each file. + +Version 1.4.0beta66 [June 27, 2009] + Refer to the libpng license instead of the libpng license in each file. + +Version 1.4.0beta67 [July 6, 2009] + Relocated INVERT_ALPHA within png_read_png() and png_write_png(). + Added high-level API transform PNG_TRANSFORM_GRAY_TO_RGB. + Added an "xcode" project to the projects directory (Alam Arias). + +Version 1.4.0beta68 [July 19, 2009] + Avoid some tests in filter selection in pngwutil.c + +Version 1.4.0beta69 [July 25, 2009] + Simplified the new filter-selection test. This runs faster in the + common "PNG_ALL_FILTERS" and PNG_FILTER_NONE cases. + Removed extraneous declaration from the new call to png_read_gray_to_rgb() + (bug introduced in libpng-1.4.0beta67). + Fixed up xcode project (Alam Arias) + Added a prototype for png_64bit_product() in png.c + +Version 1.4.0beta70 [July 27, 2009] + Avoid a possible NULL dereference in debug build, in png_set_text_2(). + (bug introduced in libpng-0.95, discovered by Evan Rouault) + +Version 1.4.0beta71 [July 29, 2009] + Rebuilt configure scripts with autoconf-2.64. + +Version 1.4.0beta72 [August 1, 2009] + Replaced *.tar.lzma with *.tar.xz in distribution. Get the xz codec + from . + +Version 1.4.0beta73 [August 1, 2009] + Reject attempt to write iCCP chunk with negative embedded profile length + (JD Chen) (CVE-2009-5063). + +Version 1.4.0beta74 [August 8, 2009] + Changed png_ptr and info_ptr member "trans" to "trans_alpha". + +Version 1.4.0beta75 [August 21, 2009] + Removed an extra png_debug() recently added to png_write_find_filter(). + Fixed incorrect #ifdef in pngset.c regarding unknown chunk support. + +Version 1.4.0beta76 [August 22, 2009] + Moved an incorrectly located test in png_read_row() in pngread.c + +Version 1.4.0beta77 [August 27, 2009] + Removed lpXYZ.tar.bz2 (with CRLF), KNOWNBUG, libpng-x.y.z-KNOWNBUG.txt, + and the "noconfig" files from the distribution. + Moved CMakeLists.txt from scripts into the main libpng directory. + Various bugfixes and improvements to CMakeLists.txt (Philip Lowman) + +Version 1.4.0beta78 [August 31, 2009] + Converted all PNG_NO_* tests to PNG_*_SUPPORTED everywhere except pngconf.h + Eliminated PNG_NO_FREE_ME and PNG_FREE_ME_SUPPORTED macros. + Use png_malloc plus a loop instead of png_calloc() to initialize + row_pointers in png_read_png(). + +Version 1.4.0beta79 [September 1, 2009] + Eliminated PNG_GLOBAL_ARRAYS and PNG_LOCAL_ARRAYS; always use local arrays. + Eliminated PNG_CALLOC_SUPPORTED macro and always provide png_calloc(). + +Version 1.4.0beta80 [September 17, 2009] + Removed scripts/libpng.icc + Changed typecast of filler from png_byte to png_uint_16 in png_set_filler(). + (Dennis Gustafsson) + Fixed typo introduced in beta78 in pngtest.c ("#if def " should be "#ifdef ") + +Version 1.4.0beta81 [September 23, 2009] + Eliminated unused PNG_FLAG_FREE_* defines from pngpriv.h + Expanded TAB characters in pngrtran.c + Removed PNG_CONST from all "PNG_CONST PNG_CHNK" declarations to avoid + compiler complaints about doubly declaring things "const". + Changed all "#if [!]defined(X)" to "if[n]def X" where possible. + Eliminated unused png_ptr->row_buf_size + +Version 1.4.0beta82 [September 25, 2009] + Moved redundant IHDR checking into new png_check_IHDR() in png.c + and report all errors found in the IHDR data. + Eliminated useless call to png_check_cHRM() from pngset.c + +Version 1.4.0beta83 [September 25, 2009] + Revised png_check_IHDR() to eliminate bogus complaint about filter_type. + +Version 1.4.0beta84 [September 30, 2009] + Fixed some inconsistent indentation in pngconf.h + Revised png_check_IHDR() to add a test for width variable less than 32-bit. + +Version 1.4.0beta85 [October 1, 2009] + Revised png_check_IHDR() again, to check info_ptr members instead of + the contents of the returned parameters. + +Version 1.4.0beta86 [October 9, 2009] + Updated the "xcode" project (Alam Arias). + Eliminated a shadowed declaration of "pp" in png_handle_sPLT(). + +Version 1.4.0rc01 [October 19, 2009] + Trivial cosmetic changes. + +Version 1.4.0beta87 [October 30, 2009] + Moved version 1.4.0 back into beta. + +Version 1.4.0beta88 [October 30, 2009] + Revised libpng*.txt section about differences between 1.2.x and 1.4.0 + because most of the new features have now been ported back to 1.2.41 + +Version 1.4.0beta89 [November 1, 2009] + More bugfixes and improvements to CMakeLists.txt (Philip Lowman) + Removed a harmless extra png_set_invert_alpha() from pngwrite.c + Apply png_user_chunk_cache_max within png_decompress_chunk(). + Merged libpng-1.2.41.txt with libpng-1.4.0.txt where appropriate. + +Version 1.4.0beta90 [November 2, 2009] + Removed all remaining WIN32_WCE #ifdefs except those involving the + time.h "tm" structure + +Version 1.4.0beta91 [November 3, 2009] + Updated scripts/pngw32.def and projects/wince/png32ce.def + Copied projects/wince/png32ce.def to the scripts directory. + Added scripts/makefile.wce + Patched ltmain.sh for wince support. + Added PNG_CONVERT_tIME_SUPPORTED macro. + +Version 1.4.0beta92 [November 4, 2009] + Make inclusion of time.h in pngconf.h depend on PNG_CONVERT_tIME_SUPPORTED + Make #define PNG_CONVERT_tIME_SUPPORTED depend on PNG_WRITE_tIME_SUPPORTED + Revised libpng*.txt to describe differences from 1.2.40 to 1.4.0 (instead + of differences from 1.2.41 to 1.4.0) + +Version 1.4.0beta93 [November 7, 2009] + Added PNG_DEPSTRUCT, PNG_DEPRECATED, PNG_USE_RESULT, PNG_NORETURN, and + PNG_ALLOCATED macros to detect deprecated direct access to the + png_struct or info_struct members and other deprecated usage in + applications (John Bowler). + Updated scripts/makefile* to add "-DPNG_CONFIGURE_LIBPNG" to CFLAGS, + to prevent warnings about direct access to png structs by libpng + functions while building libpng. They need to be tested, especially + those using compilers other than gcc. + Updated projects/visualc6 and visualc71 with "/d PNG_CONFIGURE_LIBPNG". + They should work but still need to be updated to remove + references to pnggccrd.c or pngvcrd.c and ASM building. + Added README.txt to the beos, cbuilder5, netware, and xcode projects warning + that they need to be updated, to remove references to pnggccrd.c and + pngvcrd.c and to depend on pngpriv.h + Removed three direct references to read_info_ptr members in pngtest.c + that were detected by the new PNG_DEPSTRUCT macro. + Moved the png_debug macro definitions and the png_read_destroy(), + png_write_destroy() and png_far_to_near() prototypes from png.h + to pngpriv.h (John Bowler) + Moved the synopsis lines for png_read_destroy(), png_write_destroy() + png_debug(), png_debug1(), and png_debug2() from libpng.3 to libpngpf.3. + +Version 1.4.0beta94 [November 9, 2009] + Removed the obsolete, unused pnggccrd.c and pngvcrd.c files. + Updated CMakeLists.txt to add "-DPNG_CONFIGURE_LIBPNG" to the definitions. + Removed dependency of pngtest.o on pngpriv.h in the makefiles. + Only #define PNG_DEPSTRUCT, etc. in pngconf.h if not already defined. + +Version 1.4.0beta95 [November 10, 2009] + Changed png_check_sig() to !png_sig_cmp() in contrib programs. + Added -DPNG_CONFIGURE_LIBPNG to contrib/pngminm/*/makefile + Changed png_check_sig() to !png_sig_cmp() in contrib programs. + Corrected the png_get_IHDR() call in contrib/gregbook/readpng2.c + Changed pngminim/*/gather.sh to stop trying to remove pnggccrd.c and pngvcrd.c + Added dependency on pngpriv.h in contrib/pngminim/*/makefile + +Version 1.4.0beta96 [November 12, 2009] + Renamed scripts/makefile.wce to scripts/makefile.cegcc + Revised Makefile.am to use libpng.sys while building libpng.so + so that only PNG_EXPORT functions are exported. + Removed the deprecated png_check_sig() function/macro. + Removed recently removed function names from scripts/*.def + Revised pngtest.png to put chunks in the same order written by pngtest + (evidently the same change made in libpng-1.0beta54 was lost). + Added PNG_PRIVATE macro definition in pngconf.h for possible future use. + +Version 1.4.0beta97 [November 13, 2009] + Restored pngtest.png to the libpng-1.4.0beta7 version. + Removed projects/beos and netware.txt; no one seems to be supporting them. + Revised Makefile.in + +Version 1.4.0beta98 [November 13, 2009] + Added the "xcode" project to zip distributions, + Fixed a typo in scripts/pngwin.def introduced in beta97. + +Version 1.4.0beta99 [November 14, 2009] + Moved libpng-config.in and libpng.pc-configure.in out of the scripts + directory, to libpng-config.in and libpng-pc.in, respectively, and + modified Makefile.am and configure.ac accordingly. Now "configure" + needs nothing from the "scripts" directory. + Avoid redefining PNG_CONST in pngconf.h + +Version 1.4.0beta100 [November 14, 2009] + Removed ASM builds from projects/visualc6 and projects/visualc71 + Removed scripts/makefile.nommx and makefile.vcawin32 + Revised CMakeLists.txt to account for new location of libpng-config.in + and libpng-pc.in + Updated INSTALL to reflect removal and relocation of files. + +Version 1.4.0beta101 [November 14, 2009] + Restored the binary files (*.jpg, *.png, some project files) that were + accidentally deleted from the zip and 7z distributions when the xcode + project was added. + +Version 1.4.0beta102 [November 18, 2009] + Added libpng-config.in and libpng-pc.in to the zip and 7z distributions. + Fixed a typo in projects/visualc6/pngtest.dsp, introduced in beta100. + Moved descriptions of makefiles and other scripts out of INSTALL into + scripts/README.txt + Updated the copyright year in scripts/pngwin.rc from 2006 to 2009. + +Version 1.4.0beta103 [November 21, 2009] + Removed obsolete comments about ASM from projects/visualc71/README_zlib.txt + Align row_buf on 16-byte boundary in memory. + Restored the PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED guard around the call + to png_flush() after png_write_IEND(). See 1.4.0beta32, 1.4.0beta50 + changes above and 1.2.30, 1.2.30rc01 and rc03 in 1.2.41 CHANGES. Someone + needs this feature. + Make the 'png_jmpbuf' macro expand to a call that records the correct + longjmp function as well as returning a pointer to the setjmp + jmp_buf buffer, and marked direct access to jmpbuf 'deprecated'. + (John Bowler) + +Version 1.4.0beta104 [November 22, 2009] + Removed png_longjmp_ptr from scripts/*.def and libpng.3 + Rebuilt configure scripts with autoconf-2.65 + +Version 1.4.0beta105 [November 25, 2009] + Use fast integer PNG_DIVIDE_BY_255() or PNG_DIVIDE_BY_65535() + to accomplish alpha premultiplication when + PNG_READ_COMPOSITE_NODIV_SUPPORTED is defined. + Changed "/255" to "/255.0" in background calculations to make it clear + that the 255 is used as a double. + +Version 1.4.0beta106 [November 27, 2009] + Removed premultiplied alpha feature. + +Version 1.4.0beta107 [December 4, 2009] + Updated README + Added "#define PNG_NO_PEDANTIC_WARNINGS" in the libpng source files. + Removed "-DPNG_CONFIGURE_LIBPNG" from the makefiles and projects. + Revised scripts/makefile.netbsd, makefile.openbsd, and makefile.sco + to put png.h and pngconf.h in $prefix/include, like the other scripts, + instead of in $prefix/include/libpng. Also revised makefile.sco + to put them in $prefix/include/libpng15 instead of in + $prefix/include/libpng/libpng15. + +Version 1.4.0beta108 [December 11, 2009] + Removed leftover "-DPNG_CONFIGURE_LIBPNG" from contrib/pngminim/*/makefile + Relocated png_do_chop() to its original position in pngrtran.c; the + change in version 1.2.41beta08 caused transparency to be handled wrong + in some 16-bit datastreams (Yusaku Sugai). + +Version 1.4.0beta109 [December 13, 2009] + Added "bit_depth" parameter to the private png_build_gamma_table() function. + Pass bit_depth=8 to png_build_gamma_table() when bit_depth is 16 but the + PNG_16_TO_8 transform has been set, to avoid unnecessary build of 16-bit + tables. + +Version 1.4.0rc02 [December 20, 2009] + Declared png_cleanup_needed "volatile" in pngread.c and pngwrite.c + +Version 1.4.0rc03 [December 22, 2009] + Renamed libpng-pc.in back to libpng.pc.in and revised CMakeLists.txt + (revising the change in 1.4.0beta99) + +Version 1.4.0rc04 [December 25, 2009] + Swapped PNG_UNKNOWN_CHUNKS_SUPPORTED and PNG_HANDLE_AS_UNKNOWN_SUPPORTED + in pngset.c to be consistent with other changes in version 1.2.38. + +Version 1.4.0rc05 [December 25, 2009] + Changed "libpng-pc.in" to "libpng.pc.in" in configure.ac, configure, and + Makefile.in to be consistent with changes in libpng-1.4.0rc03 + +Version 1.4.0rc06 [December 29, 2009] + Reverted the gamma_table changes from libpng-1.4.0beta109. + Fixed some indentation errors. + +Version 1.4.0rc07 [January 1, 2010] + Revised libpng*.txt and libpng.3 about 1.2.x->1.4.x differences. + Use png_calloc() instead of png_malloc(); png_memset() in pngrutil.c + Update copyright year to 2010. + +Version 1.4.0rc08 [January 2, 2010] + Avoid deprecated references to png_ptr-io_ptr and png_ptr->error_ptr + in pngtest.c + +Version 1.4.0 [January 3, 2010] + No changes. + +Version 1.4.1beta01 [January 8, 2010] + Updated CMakeLists.txt for consistent indentation and to avoid an + unclosed if-statement warning (Philip Lowman). + Revised Makefile.am and Makefile.in to remove references to Y2KINFO, + KNOWNBUG, and libpng.la (Robert Schwebel). + Revised the makefiles to install the same files and symbolic + links as configure, except for libpng.la and libpng14.la. + Make png_set|get_compression_buffer_size() available even when + PNG_WRITE_SUPPORTED is not enabled. + Revised Makefile.am and Makefile.in to simplify their maintenance. + Revised scripts/makefile.linux to install a link to libpng14.so.14.1 + +Version 1.4.1beta02 [January 9, 2010] + Revised the rest of the makefiles to install a link to libpng14.so.14.1 + +Version 1.4.1beta03 [January 10, 2010] + Removed png_set_premultiply_alpha() from scripts/*.def + +Version 1.4.1rc01 [January 16, 2010] + No changes. + +Version 1.4.1beta04 [January 23, 2010] + Revised png_decompress_chunk() to improve speed and memory usage when + decoding large chunks. + Added png_set|get_chunk_malloc_max() functions. + +Version 1.4.1beta05 [January 26, 2010] + Relocated "int k" declaration in pngtest.c to minimize its scope. + +Version 1.4.1beta06 [January 28, 2010] + Revised png_decompress_chunk() to use a two-pass method suggested by + John Bowler. + +Version 1.4.1beta07 [February 6, 2010] + Folded some long lines in the source files. + Added defineable PNG_USER_CHUNK_CACHE_MAX, PNG_USER_CHUNK_MALLOC_MAX, + and a PNG_USER_LIMITS_SUPPORTED flag. + Eliminated use of png_ptr->irowbytes and reused the slot in png_ptr as + png_ptr->png_user_chunk_malloc_max. + Revised png_push_save_buffer() to do fewer but larger png_malloc() calls. + +Version 1.4.1beta08 [February 6, 2010] + Minor cleanup and updating of dates and copyright year. + +Version 1.5.0beta01 [February 7, 2010] + Moved declaration of png_struct into private pngstruct.h and png_info + into pnginfo.h + +Version 1.4.1beta09 and 1.5.0beta02 [February 7, 2010] + Reverted to original png_push_save_buffer() code. + +Version 1.4.1beta10 and 1.5.0beta03 [February 8, 2010] + Return allocated "old_buffer" in png_push_save_buffer() before + calling png_error(), to avoid a potential memory leak. + Updated configure script to use SO number 15. + +Version 1.5.0beta04 [February 9, 2010] + Removed malformed "incomplete struct declaration" of png_info from png.h + +Version 1.5.0beta05 [February 12, 2010] + Removed PNG_DEPSTRUCT markup in pngstruct.h and pnginfo.h, and undid the + linewrapping that it entailed. + Revised comments in pngstruct.h and pnginfo.h and added pointers to + the libpng license. + Changed PNG_INTERNAL to PNG_EXPOSE_INTERNAL_STRUCTURES + Removed the cbuilder5 project, which has not been updated to 1.4.0. + +Version 1.4.1beta12 and 1.5.0beta06 [February 14, 2010] + Fixed type declaration of png_get_chunk_malloc_max() in pngget.c (Daisuke + Nishikawa) + +Version 1.5.0beta07 [omitted] + +Version 1.5.0beta08 [February 19, 2010] + Changed #ifdef PNG_NO_STDIO_SUPPORTED to #ifdef PNG_NO_CONSOLE_IO_SUPPORTED + wherever png_snprintf() is used to construct error and warning messages. + Noted in scripts/makefile.mingw that it expects to be run under MSYS. + Removed obsolete unused MMX-querying support from contrib/gregbook + Added exported png_longjmp() function. + Removed the AIX redefinition of jmpbuf in png.h + Added -D_ALLSOURCE in configure.ac, makefile.aix, and CMakeLists.txt + when building on AIX. + +Version 1.5.0beta09 [February 19, 2010] + Removed -D_ALLSOURCE from configure.ac, makefile.aix, and CMakeLists.txt. + Changed the name of png_ptr->jmpbuf to png_ptr->png_jmpbuf in pngstruct.h + +Version 1.5.0beta10 [February 25, 2010] + Removed unused gzio.c from contrib/pngminim gather and makefile scripts + Removed replacement error handlers from contrib/gregbook. Because of + the new png_longjmp() function they are no longer needed. + +Version 1.5.0beta11 [March 6, 2010] + Removed checking for already-included setjmp.h from pngconf.h + Fixed inconsistent indentations and made numerous cosmetic changes. + Revised the "SEE ALSO" style of libpng.3, libpngpf.3, and png.5 + +Version 1.5.0beta12 [March 9, 2010] + Moved "#include png.h" inside pngpriv.h and removed "#include png.h" from + the source files, along with "#define PNG_EXPOSE_INTERNAL_STRUCTURES" + and "#define PNG_NO_PEDANTIC_WARNINGS" (John Bowler). + Created new pngdebug.h and moved debug definitions there. + +Version 1.5.0beta13 [March 10, 2010] + Protect pngstruct.h, pnginfo.h, and pngdebug.h from being included twice. + Revise the "#ifdef" blocks in png_inflate() so it will compile when neither + PNG_USER_CHUNK_MALLOC_MAX nor PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED + is defined. + Removed unused png_measure_compressed_chunk() from pngpriv.h and libpngpf.3 + Moved the 'config.h' support from pngconf.h to pngpriv.h + Removed PNGAPI from the png_longjmp_ptr typedef. + Eliminated dependence of pngtest.c on the private pngdebug.h file. + Make all png_debug macros into *unterminated* statements or + expressions (i.e. a trailing ';' must always be added) and correct + the format statements in various png_debug messages. + +Version 1.5.0beta14 [March 14, 2010] + Removed direct access to png_ptr->io_ptr from the Windows code in pngtest.c + Revised Makefile.am to account for recent additions and replacements. + Corrected CE and OS/2 DEF files (scripts/png*def) for symbols removed and + added ordinal numbers to the Windows DEF file and corrected the duplicated + ordinal numbers on CE symbols that are commented out. + Added back in export symbols that can be present in the Windows build but + are disabled by default. + PNG_EXPORT changed to include an 'ordinal' field for DEF file generation. + PNG_CALLBACK added to make callback definitions uniform. PNGAPI split + into PNGCAPI (base C form), PNGAPI (exports) and PNGCBAPI (callbacks), + and appropriate changes made to all files. Cygwin builds re-hinged to + allow procedure call standard changes and to remove the need for the DEF + file (fixes build on Cygwin). + Enabled 'attribute' warnings that are relevant to library APIs and callbacks. + Changed rules for generation of the various symbol files and added a new + rule for a DEF file (which is also added to the distribution). + Updated the symbol file generation to stop it adding spurious spaces + to EOL (coming from preprocessor macro expansion). Added a facility + to join tokens in the output and rewrite *.dfn to use this. + Eliminated scripts/*.def in favor of libpng.def; updated projects/visualc71 + and removed scripts/makefile.cygwin. + Made PNG_BUILD_DLL safe: it can be set whenever a DLL is being built. + Removed the include of sys/types.h - apparently unnecessary now on the + platforms on which it happened (all but Mac OS and RISC OS). + Moved the Mac OS test into pngpriv.h (the only place it is used.) + +Version 1.5.0beta15 [March 17, 2010] + Added symbols.chk target to Makefile.am to validate the symbols in png.h + against the new DEF file scripts/symbols.def. + Changed the default DEF file back to pngwin.def. + Removed makefile.mingw. + Eliminated PNG_NO_EXTERN and PNG_ALL_EXTERN + +Version 1.5.0beta16 [April 1, 2010] + Make png_text_struct independent of PNG_iTXt_SUPPORTED, so that + fields are initialized in all configurations. The READ/WRITE + macros (PNG_(READ|WRITE)_iTXt_SUPPORTED) still function as + before to disable code to actually read or write iTXt chunks + and iTXt_SUPPORTED can be used to detect presence of either + read or write support (but it is probably better to check for + the one actually required - read or write.) + Combined multiple png_warning() calls for a single error. + Restored the macro definition of png_check_sig(). + +Version 1.5.0beta17 [April 17, 2010] + Added some "(long)" typecasts to printf calls in png_handle_cHRM(). + Documented the fact that png_set_dither() was disabled since libpng-1.4.0. + Reenabled png_set_dither() but renamed it to png_set_quantize() to reflect + more accurately what it actually does. At the same time, renamed + the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros to + PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS. + Added some "(long)" typecasts to printf calls in png_handle_cHRM(). + Freeze build-time only configuration in the build. + In all prior versions of libpng most configuration options + controlled by compiler #defines had to be repeated by the + application code that used libpng. This patch changes this + so that compilation options that can only be changed at build + time are frozen in the build. Options that are compiler + dependent (and those that are system dependent) are evaluated + each time - pngconf.h holds these. Options that can be changed + per-file in the application are in png.h. Frozen options are + in the new installed header file pnglibconf.h (John Bowler) + Removed the xcode project because it has not been updated to work + with libpng-1.5.0. + Removed the ability to include optional pngusr.h + +Version 1.5.0beta18 [April 17, 2010] + Restored the ability to include optional pngusr.h + Moved replacements for png_error() and png_warning() from the + contrib/pngminim project to pngerror.c, for use when warnings or + errors are disabled via PNG_NO_WARN or PNG_NO_ERROR_TEXT, to avoid + storing unneeded error/warning text. + Updated contrib/pngminim project to work with the new pnglibconf.h + Added some PNG_NO_* defines to contrib/pngminim/*/pngusr.h to save space. + +Version 1.5.0beta19 [April 24, 2010] + Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the functions + to read and write ints to be disabled independently of PNG_USE_READ_MACROS, + which allows libpng to be built with the functions even though the default + is to use the macros - this allows applications to choose at app build + time whether or not to use macros (previously impossible because the + functions weren't in the default build.) + Changed Windows calling convention back to __cdecl for API functions. + For Windows/x86 platforms only: + __stdcall is no longer needed for Visual Basic, so libpng-1.5.0 uses + __cdecl throughout (both API functions and callbacks) on Windows/x86 + platforms. + Replaced visualc6 and visualc71 projects with new vstudio project + Relaxed the overly-restrictive permissions of some files. + +Version 1.5.0beta20 [April 24, 2010] + Relaxed more overly-restrictive permissions of some files. + +Version 1.5.0beta21 [April 27, 2010] + Removed some unwanted binary bytes and changed CRLF to NEWLINE in the new + vstudio project files, and some trivial editing of some files in the + scripts directory. + Set PNG_NO_READ_BGR, PNG_NO_IO_STATE, and PNG_NO_TIME_RFC1123 in + contrib/pngminim/decoder/pngusr.h to make a smaller decoder application. + +Version 1.5.0beta22 [April 28, 2010] + Fixed dependencies of GET_INT_32 - it does not require READ_INT_FUNCTIONS + because it has a macro equivalent. + Improved the options.awk script; added an "everything off" option. + Revised contrib/pngminim to use the "everything off" option in pngusr.dfa. + +Version 1.5.0beta23 [April 29, 2010] + Corrected PNG_REMOVED macro to take five arguments. + The macro was documented with two arguments (name,ordinal), however + the symbol checking .dfn files assumed five arguments. The five + argument form seems more useful so it is changed to that. + Corrected PNG_UNKNOWN_CHUNKS_SUPPORTED to PNG_HANDLE_AS_UNKNOWN_SUPPORTED + in gregbook/readpng2.c + Corrected protection of png_get_user_transform_ptr. The API declaration in + png.h is removed if both READ and WRITE USER_TRANSFORM are turned off + but was left defined in pngtrans.c + Added logunsupported=1 to cause pnglibconf.h to document disabled options. + This makes the installed pnglibconf.h more readable but causes no + other change. The intention is that users of libpng will find it + easier to understand if an API they need is missing. + Include png_reset_zstream() in png.c only when PNG_READ_SUPPORTED is defined. + Removed dummy_inflate.c from contrib/pngminim/encoder + Removed contrib/pngminim/*/gather.sh; gathering is now done in the makefile. + +Version 1.5.0beta24 [May 7, 2010] + Use bitwise "&" instead of arithmetic mod in pngrutil.c calculation of the + offset of the png_ptr->rowbuf pointer into png_ptr->big_row_buf. + Added more blank lines for readability. + +Version 1.5.0beta25 [June 18, 2010] + In pngpread.c: png_push_have_row() add check for new_row > height + Removed the now-redundant check for out-of-bounds new_row from example.c + +Version 1.5.0beta26 [June 18, 2010] + In pngpread.c: png_push_process_row() add check for too many rows. + +Version 1.5.0beta27 [June 18, 2010] + Removed the check added in beta25 as it is now redundant. + +Version 1.5.0beta28 [June 20, 2010] + Rewrote png_process_IDAT_data to consistently treat extra data as warnings + and handle end conditions more cleanly. + Removed the new (beta26) check in png_push_process_row(). + +Version 1.5.0beta29 [June 21, 2010] + Revised scripts/options.awk to work on Sunos (but still doesn't work) + Added comment to options.awk and contrib/pngminim/*/makefile to try nawk. + +Version 1.5.0beta30 [June 22, 2010] + Stop memory leak when reading a malformed sCAL chunk. + +Version 1.5.0beta31 [June 26, 2010] + Revised pngpread.c patch of beta28 to avoid an endless loop. + Removed some trailing blanks. + +Version 1.5.0beta32 [June 26, 2010] + Removed leftover scripts/options.patch and scripts/options.rej + +Version 1.5.0beta33 [July 6, 3010] + Made FIXED and FLOATING options consistent in the APIs they enable and + disable. Corrected scripts/options.awk to handle both command line + options and options specified in the .dfa files. + Changed char *msg to PNG_CONST char *msg in pngrutil.c + Make png_set_sRGB_gAMA_and_cHRM set values using either the fixed or + floating point APIs, but not both. + Reversed patch to remove error handler when the jmp_buf is stored in the + main program structure, not the png_struct. + The error handler is needed because the default handler in libpng will + always use the jmp_buf in the library control structure; this is never + set. The gregbook code is a useful example because, even though it + uses setjmp/longjmp, it shows how error handling can be implemented + using control mechanisms not directly supported by libpng. The + technique will work correctly with mechanisms such as Microsoft + Structure Exceptions or C++ exceptions (compiler willing - note that gcc + does not by default support interworking of C and C++ error handling.) + Reverted changes to call png_longjmp in contrib/gregbook where it is not + appropriate. If mainprog->jmpbuf is used by setjmp, then png_longjmp + cannot be used. + Changed "extern PNG_EXPORT" to "PNG_EXPORT" in png.h (Jan Nijtmans) + Changed "extern" to "PNG_EXTERN" in pngpriv.h (except for the 'extern "C" {') + +Version 1.5.0beta34 [July 12, 2010] + Put #ifndef PNG_EXTERN, #endif around the define PNG_EXTERN in pngpriv.h + +Version 1.5.0beta35 [July 24, 2010] + Removed some newly-added TAB characters. + Added -DNO_PNG_SNPRINTF to CFLAGS in scripts/makefile.dj2 + Moved the definition of png_snprintf() outside of the enclosing + #ifdef blocks in pngconf.h + +Version 1.5.0beta36 [July 29, 2010] + Patches by John Bowler: + Fixed point APIs are now supported throughout (no missing APIs). + Internal fixed point arithmetic support exists for all internal floating + point operations. + sCAL validates the floating point strings it is passed. + Safe, albeit rudimentary, Watcom support is provided by PNG_API_RULE==2 + Two new APIs exist to get the number of passes without turning on the + PNG_INTERLACE transform and to get the number of rows in the current + pass. + A new test program, pngvalid.c, validates the gamma code. + Errors in the 16-bit gamma correction (overflows) have been corrected. + cHRM chunk testing is done consistently (previously the floating point + API bypassed it, because the test really didn't work on FP, now the test + is performed on the actual values to be stored in the PNG file so it + works in the FP case too.) + Most floating point APIs now simply call the fixed point APIs after + converting the values to the fixed point form used in the PNG file. + The standard headers no longer include zlib.h, which is currently only + required for pngstruct.h and can therefore be internal. + Revised png_get_int_32 to undo the PNG two's complement representation of + negative numbers. + +Version 1.5.0beta37 [July 30, 2010] + Added a typecast in png_get_int_32() in png.h and pngrutil.h to avoid + a compiler warning. + Replaced oFFs 0,0 with oFFs -10,20 in pngtest.png + +Version 1.5.0beta38 [July 31, 2010] + Implemented remaining "_fixed" functions. + Corrected a number of recently introduced warnings mostly resulting from + safe but uncast assignments to shorter integers. Also added a zlib + VStudio release library project because the latest zlib Official Windows + build does not include such a thing. + Revised png_get_int_16() to be similar to png_get_int_32(). + Restored projects/visualc71. + +Version 1.5.0beta39 [August 2, 2010] + VisualC/GCC warning fixes, VisualC build fixes + The changes include support for function attributes in VC in addition to + those already present in GCC - necessary because without these some + warnings are unavoidable. Fixes include signed/unsigned fixes in + pngvalid and checks with gcc -Wall -Wextra -Wunused. + VC requires function attributes on function definitions as well as + declarations, PNG_FUNCTION has been added to enable this and the + relevant function definitions changed. + +Version 1.5.0beta40 [August 6, 2010] + Correct use of _WINDOWS_ in pngconf.h + Removed png_mem_ #defines; they are no longer used. + Added the sRGB chunk to pngtest.png + +Version 1.5.0beta41 [August 11, 2010] + Added the cHRM chunk to pngtest.png + Don't try to use version-script with cygwin/mingw. + Revised contrib/gregbook to work under cygwin/mingw. + +Version 1.5.0beta42 [August 18, 2010] + Add .dll.a to the list of extensions to be symlinked by Makefile.am (Yaakov) + Made all API functions that have const arguments and constant string + literal pointers declare them (John Bowler). + +Version 1.5.0beta43 [August 20, 2010] + Removed spurious tabs, shorten long lines (no source change) + Also added scripts/chkfmt to validate the format of all the files that can + reasonably be validated (it is suggested to run "make distclean" before + checking, because some machine generated files have long lines.) + Reformatted the CHANGES file to be more consistent throughout. + Made changes to address various issues identified by GCC, mostly + signed/unsigned and shortening problems on assignment but also a few + difficult to optimize (for GCC) loops. + Fixed non-GCC fixed point builds. In png.c a declaration was misplaced + in an earlier update. Fixed to declare the auto variables at the head. + Use cexcept.h in pngvalid.c. + +Version 1.5.0beta44 [August 24, 2010] + Updated CMakeLists.txt to use CMAKE_INSTALL_LIBDIR variable; useful for + installing libpng in /usr/lib64 (Funda Wang). + Revised CMakeLists.txt to put the man pages in share/man/man* not man/man* + Revised CMakeLists.txt to make symlinks instead of copies when installing. + Changed PNG_LIB_NAME from pngNN to libpngNN in CMakeLists.txt (Philip Lowman) + Implemented memory checks within pngvalid + Reformatted/rearranged pngvalid.c to assist use of progressive reader. + Check interlaced images in pngvalid + Clarified pngusr.h comments in pnglibconf.dfa + Simplified the pngvalid error-handling code now that cexcept.h is in place. + Implemented progressive reader in pngvalid.c for standard tests + Implemented progressive read in pngvalid.c gamma tests + Turn on progressive reader in pngvalid.c by default and tidy code. + +Version 1.5.0beta45 [August 26, 2010] + Added an explicit make step to projects/vstudio for pnglibconf.h + Also corrected zlib.vcxproj into which Visual Studio had introduced + what it calls an "authoring error". The change to make pnglibconf.h + simply copies the file; in the future it may actually generate the + file from scripts/pnglibconf.dfa as the other build systems do. + Changed pngvalid to work when floating point APIs are disabled + Renamed the prebuilt scripts/pnglibconf.h to scripts/pnglibconf.h.prebuilt + Supply default values for PNG_USER_PRIVATEBUILD and PNG_USER_DLLFNAME_POSTFIX + in pngpriv.h in case the user neglected to define them in their pngusr.h + +Version 1.5.0beta46 [August 28, 2010] + Added new private header files to libpng_sources in CMakeLists.txt + Added PNG_READ_16BIT, PNG_WRITE_16BIT, and PNG_16BIT options. + Added reference to scripts/pnglibconf.h.prebuilt in the visualc71 project. + +Version 1.5.0beta47 [September 11, 2010] + Fixed a number of problems with 64-bit compilation reported by Visual + Studio 2010 (John Bowler). + +Version 1.5.0beta48 [October 4, 2010] + Updated CMakeLists.txt (Philip Lowman). + Revised autogen.sh to recognize and use $AUTOCONF, $AUTOMAKE, $AUTOHEADER, + $AUTOPOINT, $ACLOCAL and $LIBTOOLIZE + Fixed problem with symbols creation in Makefile.am which was assuming that + all versions of ccp write to standard output by default (Martin Banky). The + bug was introduced in libpng-1.2.9beta5. + Removed unused mkinstalldirs. + +Version 1.5.0beta49 [October 8, 2010] + Undid Makefile.am revision of 1.5.0beta48. + +Version 1.5.0beta50 [October 14, 2010] + Revised Makefile.in to account for mkinstalldirs being removed. + Added some "(unsigned long)" typecasts in printf statements in pngvalid.c. + Suppressed a compiler warning in png_handle_sPLT(). + Check for out-of-range text compression mode in png_set_text(). + +Version 1.5.0beta51 [October 15, 2010] + Changed embedded dates to "(PENDING RELEASE) in beta releases (and future + rc releases) to minimize the difference between releases. + +Version 1.5.0beta52 [October 16, 2010] + Restored some of the embedded dates (in png.h, png.c, documentation, etc.) + +Version 1.5.0beta53 [October 18, 2010] + Updated INSTALL to mention using "make maintainer-clean" and to remove + obsolete statement about a custom ltmain.sh + Disabled "color-tests" by default in Makefile.am so it will work with + automake versions earlier than 1.11.1 + Use document name "libpng-manual.txt" instead of "libpng-.txt" + to simplify version differences. + Removed obsolete remarks about setjmp handling from INSTALL. + Revised and renamed the typedef in png.h and png.c that was designed + to catch library and header mismatch. + +Version 1.5.0beta54 [November 10, 2010] + Require 48 bytes, not 64 bytes, for big_row_buf in overflow checks. + Used a consistent structure for the pngget.c functions. + +Version 1.5.0beta55 [November 21, 2010] + Revised png_get_uint_32, png_get_int_32, png_get_uint_16 (Cosmin) + Moved reading of file signature into png_read_sig (Cosmin) + Fixed atomicity of chunk header serialization (Cosmin) + Added test for io_state in pngtest.c (Cosmin) + Added "#!/bin/sh" at the top of contrib/pngminim/*/gather.sh scripts. + Changes to remove gcc warnings (John Bowler) + Certain optional gcc warning flags resulted in warnings in libpng code. + With these changes only -Wconversion and -Wcast-qual cannot be turned on. + Changes are trivial rearrangements of code. -Wconversion is not possible + for pngrutil.c (because of the widespread use of += et al on variables + smaller than (int) or (unsigned int)) and -Wcast-qual is not possible + with pngwio.c and pngwutil.c because the 'write' callback and zlib + compression both fail to declare their input buffers with 'const'. + +Version 1.5.0beta56 [December 7, 2010] + Added the private PNG_UNUSED() macro definition in pngpriv.h. + Added some commentary about PNG_EXPORT in png.h and pngconf.h + Revised PNG_EXPORT() macro and added PNG_EXPORTA() macro, with the + objective of simplifying and improving the cosmetic appearance of png.h. + Fixed some incorrect "=" macro names in pnglibconf.dfa + Included documentation of changes in 1.5.0 from 1.4.x in libpng-manual.txt + +Version 1.5.0beta57 [December 9, 2010] + Documented the pngvalid gamma error summary with additional comments and + print statements. + Improved missing symbol handling in checksym.awk; symbols missing in both + the old and new files can now be optionally ignored, treated as errors + or warnings. + Removed references to pngvcrd.c and pnggccrd.c from the vstudio project. + Updated "libpng14" to "libpng15" in the visualc71 project. + Enabled the strip16 tests in pngvalid.` + Don't display test results (except PASS/FAIL) when running "make test". + Instead put them in pngtest-log.txt + Added "--with-zprefix=" to configure.ac + Updated the prebuilt configuration files to autoconf version 2.68 + +Version 1.5.0beta58 [December 19, 2010] + Fixed interlace image handling and add test cases (John Bowler) + Fixed the clean rule in Makefile.am to remove pngtest-log.txt + Made minor changes to work around warnings in gcc 3.4 + +Version 1.5.0rc01 [December 27, 2010] + No changes. + +Version 1.5.0rc02 [December 27, 2010] + Eliminated references to the scripts/*.def files in project/visualc71. + +Version 1.5.0rc03 [December 28, 2010] + Eliminated scripts/*.def and revised Makefile.am accordingly + +Version 1.5.0rc04 [December 29, 2010] + Fixed bug in background transformation handling in pngrtran.c (it was + looking for the flag in png_ptr->transformations instead of in + png_ptr->flags) (David Raymond). + +Version 1.5.0rc05 [December 31, 2010] + Fixed typo in a comment in CMakeLists.txt (libpng14 => libpng15) (Cosmin) + +Version 1.5.0rc06 [January 4, 2011] + Changed the new configure option "zprefix=string" to "zlib-prefix=string" + +Version 1.5.0rc07 [January 4, 2011] + Updated copyright year. + +Version 1.5.0 [January 6, 2011] + No changes. + +version 1.5.1beta01 [January 8, 2011] + Added description of png_set_crc_action() to the manual. + Added a note in the manual that the type of the iCCP profile was changed + from png_charpp to png_bytepp in png_get_iCCP(). This change happened + in version 1.5.0beta36 but is not noted in the CHANGES. Similarly, + it was changed from png_charpp to png_const_bytepp in png_set_iCCP(). + Ensure that png_rgb_to_gray ignores palette mapped images, if libpng + internally happens to call it with one, and fixed a failure to handle + palette mapped images correctly. This fixes CVE-2690. + +Version 1.5.1beta02 [January 14, 2011] + Fixed a bug in handling of interlaced images (bero at arklinux.org). + Updated CMakeLists.txt (Clifford Yapp) + +Version 1.5.1beta03 [January 14, 2011] + Fixed typecasting of some png_debug() statements (Cosmin) + +Version 1.5.1beta04 [January 16, 2011] + Updated documentation of png_set|get_tRNS() (Thomas Klausner). + Mentioned in the documentation that applications must #include "zlib.h" + if they need access to anything in zlib.h, and that a number of + macros such as png_memset() are no longer accessible by applications. + Corrected pngvalid gamma test "sample" function to access all of the color + samples of each pixel, instead of sampling the red channel three times. + Prefixed variable names index, div, exp, gamma with "png_" to avoid "shadow" + warnings, and (mistakenly) changed png_exp() to exp(). + +Version 1.5.1beta05 [January 16, 2011] + Changed variable names png_index, png_div, png_exp, and png_gamma to + char_index, divisor, exp_b10, and gamma_val, respectively, and + changed exp() back to png_exp(). + +Version 1.5.1beta06 [January 20, 2011] + Prevent png_push_crc_skip() from hanging while reading an unknown chunk + or an over-large compressed zTXt chunk with the progressive reader. + Eliminated more GCC "shadow" warnings. + Revised png_fixed() in png.c to avoid compiler warning about reaching the + end without returning anything. + +Version 1.5.1beta07 [January 22, 2011] + In the manual, describe the png_get_IHDR() arguments in the correct order. + Added const_png_structp and const_png_infop types, and used them in + prototypes for most png_get_*() functions. + +Version 1.5.1beta08 [January 23, 2011] + Added png_get_io_chunk_type() and deprecated png_get_io_chunk_name() + Added synopses for the IO_STATE functions and other missing synopses + to the manual. Removed the synopses from libpngpf.3 because they + were out of date and no longer useful. Better information can be + obtained by reading the prototypes and comments in pngpriv.h + Attempted to fix cpp on Solaris with S. Studio 12 cc, fix build + Added a make macro DFNCPP that is a CPP that will accept the tokens in + a .dfn file and adds configure stuff to test for such a CPP. ./configure + should fail if one is not available. + Corrected const_png_ in png.h to png_const_ to avoid polluting the namespace. + Added png_get_current_row_number and png_get_current_pass_number for the + benefit of the user transform callback. + Added png_process_data_pause and png_process_data_skip for the benefit of + progressive readers that need to stop data processing or want to optimize + skipping of unread data (e.g., if the reader marks a chunk to be skipped.) + +Version 1.5.1beta09 [January 24, 2011] + Enhanced pngvalid, corrected an error in gray_to_rgb, corrected doc error. + pngvalid contains tests of transforms, which tests are currently disabled + because they are incompletely tested. gray_to_rgb was failing to expand + the bit depth for smaller bit depth images; this seems to be a long + standing error and resulted, apparently, in invalid output + (CVE-2011-0408, CERT VU#643140). The documentation did not accurately + describe what libpng really does when converting RGB to gray. + +Version 1.5.1beta10 [January 27, 2010] + Fixed incorrect examples of callback prototypes in the manual, that were + introduced in libpng-1.0.0. + In addition the order of the png_get_uint macros with respect to the + relevant function definitions has been reversed. This helps the + preprocessing of the symbol files be more robust. Furthermore, the + symbol file preprocessing now uses -DPNG_NO_USE_READ_MACROS even when + the library may actually be built with PNG_USE_READ_MACROS; this stops + the read macros interfering with the symbol file format. + Made the manual, synopses, and function prototypes use the function + argument names file_gamma, int_file_gamma, and srgb_intent consistently. + +Version 1.5.1beta11 [January 28, 2011] + Changed PNG_UNUSED from "param=param;" to "{if(param){}}". + Corrected local variable type in new API png_process_data_skip() + The type was self-evidently incorrect but only causes problems on 64-bit + architectures. + Added transform tests to pngvalid and simplified the arguments. + +Version 1.5.1rc01 [January 29, 2011] + No changes. + +Version 1.5.1rc02 [January 31, 2011] + Added a request in the manual that applications do not use "png_" or + "PNG_" to begin any of their own symbols. + Changed PNG_UNUSED to "(void)param;" and updated the commentary in pngpriv.h + +Version 1.5.1 [February 3, 2011] + No changes. + +Version 1.5.2beta01 [February 13, 2011] + More -Wshadow fixes for older gcc compilers. Older gcc versions apparently + check formal parameters names in function declarations (as well as + definitions) to see if they match a name in the global namespace. + Revised PNG_EXPORTA macro to not use an empty parameter, to accommodate the + old VisualC++ preprocessor. + Turned on interlace handling in png_read_png(). + Fixed gcc pendantic warnings. + Handle longjmp in Cygwin. + Fixed png_get_current_row_number() in the interlaced case. + Cleaned up ALPHA flags and transformations. + Implemented expansion to 16 bits. + +Version 1.5.2beta02 [February 19, 2011] + Fixed mistake in the descriptions of user read_transform and write_transform + function prototypes in the manual. The row_info struct is png_row_infop. + Reverted png_get_current_row_number() to previous (1.5.2beta01) behavior. + Corrected png_get_current_row_number documentation + Fixed the read/write row callback documentation. + This documents the current behavior, where the callback is called after + every row with information pertaining to the next row. + +Version 1.5.2beta03 [March 3, 2011] + Fixed scripts/makefile.vcwin32 + Updated contrib/pngsuite/README to add the word "modify". + Define PNG_ALLOCATED to blank when _MSC_VER<1300. + +Version 1.5.2rc01 [March 19, 2011] + Define remaining attributes to blank when MSC_VER<1300. + ifdef out mask arrays in pngread.c when interlacing is not supported. + +Version 1.5.2rc02 [March 22, 2011] + Added a hint to try CPP=/bin/cpp if "cpp -E" fails in scripts/pnglibconf.mak + and in contrib/pngminim/*/makefile, eg., on SunOS 5.10, and removed "strip" + from the makefiles. + Fixed a bug (present since libpng-1.0.7) that makes png_handle_sPLT() fail + to compile when PNG_NO_POINTER_INDEXING is defined (Chubanov Kirill) + +Version 1.5.2rc03 [March 24, 2011] + Don't include standard header files in png.h while building the symbol table, + to avoid cpp failure on SunOS (introduced PNG_BUILDING_SYMBOL_TABLE macro). + +Version 1.5.2 [March 31, 2011] + No changes. + +Version 1.5.3beta01 [April 1, 2011] + Re-initialize the zlib compressor before compressing non-IDAT chunks. + Added API functions (png_set_text_compression_level() and four others) to + set parameters for zlib compression of non-IDAT chunks. + +Version 1.5.3beta02 [April 3, 2011] + Updated scripts/symbols.def with new API functions. + Only compile the new zlib re-initializing code when text or iCCP is + supported, using PNG_WRITE_COMPRESSED_TEXT_SUPPORTED macro. + Improved the optimization of the zlib CMF byte (see libpng-1.2.6beta03). + Optimize the zlib CMF byte in non-IDAT compressed chunks + +Version 1.5.3beta03 [April 16, 2011] + Fixed gcc -ansi -pedantic compile. A strict ANSI system does not have + snprintf, and the "__STRICT_ANSI__" detects that condition more reliably + than __STDC__ (John Bowler). + Removed the PNG_PTR_NORETURN attribute because it too dangerous. It tells + the compiler that a user supplied callback (the error handler) does not + return, yet there is no guarantee in practice that the application code + will correctly implement the error handler because the compiler only + issues a warning if there is a mistake (John Bowler). + Removed the no-longer-used PNG_DEPSTRUCT macro. + Updated the zlib version to 1.2.5 in the VStudio project. + Fixed 64-bit builds where png_uint_32 is smaller than png_size_t in + pngwutil.c (John Bowler). + Fixed bug with stripping the filler or alpha channel when writing, that + was introduced in libpng-1.5.2beta01 (bug report by Andrew Church). + +Version 1.5.3beta04 [April 27, 2011] + Updated pngtest.png with the new zlib CMF optimization. + Cleaned up conditional compilation code and of background/gamma handling + Internal changes only except a new option to avoid compiling the + png_build_grayscale_palette API (which is not used at all internally.) + The main change is to move the transform tests (READ_TRANSFORMS, + WRITE_TRANSFORMS) up one level to the caller of the APIs. This avoids + calls to spurious functions if all transforms are disabled and slightly + simplifies those functions. Pngvalid modified to handle this. + A minor change is to stop the strip_16 and expand_16 interfaces from + disabling each other; this allows the future alpha premultiplication + code to use 16-bit intermediate values while still producing 8-bit output. + png_do_background and png_do_gamma have been simplified to take a single + pointer to the png_struct rather than pointers to every item required + from the png_struct. This makes no practical difference to the internal + code. + A serious bug in the pngvalid internal routine 'standard_display_init' has + been fixed - this failed to initialize the red channel and accidentally + initialized the alpha channel twice. + Changed png_struct jmp_buf member name from png_jmpbuf to tmp_jmpbuf to + avoid a possible clash with the png_jmpbuf macro on some platforms. + +Version 1.5.3beta05 [May 6, 2011] + Added the "_POSIX_SOURCE" feature test macro to ensure libpng sees the + correct API. _POSIX_SOURCE is defined in pngpriv.h, pngtest.c and + pngvalid.c to ensure that POSIX conformant systems disable non-POSIX APIs. + Removed png_snprintf and added formatted warning messages. This change adds + internal APIs to allow png_warning messages to have parameters without + requiring the host OS to implement snprintf. As a side effect the + dependency of the tIME-supporting RFC1132 code on stdio is removed and + PNG_NO_WARNINGS does actually work now. + Pass "" instead of '\0' to png_default_error() in png_err(). This mistake + was introduced in libpng-1.2.20beta01. This fixes CVE-2011-2691. + Added PNG_WRITE_OPTIMIZE_CMF_SUPPORTED macro to make the zlib "CMF" byte + optimization configureable. + IDAT compression failed if preceded by a compressed text chunk (bug + introduced in libpng-1.5.3beta01-02). This was because the attempt to + reset the zlib stream in png_write_IDAT happened after the first IDAT + chunk had been deflated - much too late. In this change internal + functions were added to claim/release the z_stream and, hopefully, make + the code more robust. Also deflateEnd checking is added - previously + libpng would ignore an error at the end of the stream. + +Version 1.5.3beta06 [May 8, 2011] + Removed the -D_ALL_SOURCE from definitions for AIX in CMakeLists.txt + Implemented premultiplied alpha support: png_set_alpha_mode API + +Version 1.5.3beta07 [May 11, 2011] + Added expand_16 support to the high level interface. + Added named value and 'flag' gamma support to png_set_gamma. Made a minor + change from the previous (unreleased) ABI/API to hide the exact value used + for Macs - it's not a good idea to embed this in the ABI! + Moved macro definitions for PNG_HAVE_IHDR, PNG_HAVE_PLTE, and PNG_AFTER_IDAT + from pngpriv.h to png.h because they must be visible to applications + that call png_set_unknown_chunks(). + Check for up->location !PNG_AFTER_IDAT when writing unknown chunks + before IDAT. + +Version 1.5.3beta08 [May 16, 2011] + Improved "pngvalid --speed" to exclude more of pngvalid from the time. + Documented png_set_alpha_mode(), other changes in libpng.3/libpng-manual.txt + The cHRM chunk now sets the defaults for png_set_rgb_to_gray() (when negative + parameters are supplied by the caller), while in the absence of cHRM + sRGB/Rec 709 values are still used. This introduced a divide-by-zero + bug in png_handle_cHRM(). + The bKGD chunk no longer overwrites the background value set by + png_set_background(), allowing the latter to be used before the file + header is read. It never performed any useful function to override + the default anyway. + Added memory overwrite and palette image checks to pngvalid.c + Previously palette image code was poorly checked. Since the transformation + code has a special palette path in most cases this was a severe weakness. + Minor cleanup and some extra checking in pngrutil.c and pngrtran.c. When + expanding an indexed image, always expand to RGBA if transparency is + present. + +Version 1.5.3beta09 [May 17, 2011] + Reversed earlier 1.5.3 change of transformation order; move png_expand_16 + back where it was. The change doesn't work because it requires 16-bit + gamma tables when the code only generates 8-bit ones. This fails + silently; the libpng code just doesn't do any gamma correction. Moving + the tests back leaves the old, inaccurate, 8-bit gamma calculations, but + these are clearly better than none! + +Version 1.5.3beta10 [May 20, 2011] + + png_set_background() and png_expand_16() did not work together correctly. + This problem is present in 1.5.2; if png_set_background is called with + need_expand false and the matching 16 bit color libpng erroneously just + treats it as an 8-bit color because of where png_do_expand_16 is in the + transform list. This simple fix reduces the supplied colour to 8-bits, + so it gets smashed, but this is better than the current behavior. + Added tests for expand16, more fixes for palette image tests to pngvalid. + Corrects the code for palette image tests and disables attempts to + validate palette colors. + +Version 1.5.3rc01 [June 3, 2011] + No changes. + +Version 1.5.3rc02 [June 8, 2011] + Fixed uninitialized memory read in png_format_buffer() (Bug report by + Frank Busse, CVE-2011-2501, related to CVE-2004-0421). + +Version 1.5.3beta11 [June 11, 2011] + Fixed png_handle_sCAL which is broken in 1.5. This fixes CVE 2011-2692. + Added sCAL to pngtest.png + Revised documentation about png_set_user_limits() to say that it also affects + png writing. + Revised handling of png_set_user_limits() so that it can increase the + limit beyond the PNG_USER_WIDTH|HEIGHT_MAX; previously it could only + reduce it. + Make the 16-to-8 scaling accurate. Dividing by 256 with no rounding is + wrong (high by one) 25% of the time. Dividing by 257 with rounding is + wrong in 128 out of 65536 cases. Getting the right answer all the time + without division is easy. + Added "_SUPPORTED" to the PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION macro. + Added projects/owatcom, an IDE project for OpenWatcom to replace + scripts/makefile.watcom. This project works with OpenWatcom 1.9. The + IDE autogenerates appropriate makefiles (libpng.mk) for batch processing. + The project is configurable, unlike the Visual Studio project, so long + as the developer has an awk. + Changed png_set_gAMA to limit the gamma value range so that the inverse + of the stored value cannot overflow the fixed point representation, + and changed other things OpenWatcom warns about. + Revised pngvalid.c to test PNG_ALPHA_MODE_SUPPORTED correctly. This allows + pngvalid to build when ALPHA_MODE is not supported, which is required if + it is to build on libpng 1.4. + Removed string/memory macros that are no longer used and are not + necessarily fully supportable, particularly png_strncpy and png_snprintf. + Added log option to pngvalid.c and attempted to improve gamma messages. + +Version 1.5.3 [omitted] + People found the presence of a beta release following an rc release + to be confusing; therefore we bump the version to libpng-1.5.4beta01 + and there will be no libpng-1.5.3 release. + +Version 1.5.4beta01 [June 14, 2011] + Made it possible to undefine PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED + to get the same (inaccurate) output as libpng-1.5.2 and earlier. + Moved definitions of PNG_HAVE_IHDR, PNG_AFTER_IDAT, and PNG_HAVE_PLTE + outside of an unknown-chunk block in png.h because they are also + needed for other uses. + +Version 1.5.4beta02 [June 14, 2011] + Fixed and clarified LEGACY 16-to-8 scaling code. + Added png_set_chop_16() API, to match inaccurate results from previous + libpng versions. + Removed the ACCURATE and LEGACY options (they are no longer useable) + Use the old scaling method for background if png_set_chop_16() was + called. + Made png_set_chop_16() API removeable by disabling PNG_CHOP_16_TO_8_SUPPORTED + +Version 1.5.4beta03 [June 15, 2011] + Fixed a problem in png_do_expand_palette() exposed by optimization in + 1.5.3beta06 + Also removed a spurious and confusing "trans" member ("trans") from png_info. + The palette expand optimization prevented expansion to an intermediate RGBA + form if tRNS was present but alpha was marked to be stripped; this exposed + a check for tRNS in png_do_expand_palette() which is inconsistent with the + code elsewhere in libpng. + Correction to the expand_16 code; removed extra instance of + png_set_scale_16_to_8 from pngpriv.h + +Version 1.5.4beta04 [June 16, 2011] + Added a missing "#ifdef PNG_READ_BACKGROUND_SUPPORTED/#endif" in pngrtran.c + Added PNG_TRANSFORM_CHOP_16 to the high-level read transforms. + Made PNG_READ_16_TO_8_ACCURATE_SCALE configurable again. If this is + not enabled, png_set_strip_16() and png_do_scale_16_to_8() aren't built. + Revised contrib/visupng, gregbook, and pngminim to demonstrate chop_16_to_8 + +Version 1.5.4beta05 [June 16, 2011] + Renamed png_set_strip_16() to png_set_scale_16() and renamed + png_set_chop_16() to png_set_strip(16) in an attempt to minimize the + behavior changes between libpng14 and libpng15. + +Version 1.5.4beta06 [June 18, 2011] + Fixed new bug that was causing both strip_16 and scale_16 to be applied. + +Version 1.5.4beta07 [June 19, 2011] + Fixed pngvalid, simplified macros, added checking for 0 in sCAL. + The ACCURATE scale macro is no longer defined in 1.5 - call the + png_scale_16_to_8 API. Made sure that PNG_READ_16_TO_8 is still defined + if the png_strip_16_to_8 API is present. png_check_fp_number now + maintains some state so that positive, negative and zero values are + identified. sCAL uses these to be strictly spec conformant. + +Version 1.5.4beta08 [June 23, 2011] + Fixed pngvalid if ACCURATE_SCALE is defined. + Updated scripts/pnglibconf.h.prebuilt. + +Version 1.5.4rc01 [June 30, 2011] + Define PNG_ALLOCATED to "restrict" only if MSC_VER >= 1400. + +Version 1.5.4 [July 7, 2011] + No changes. + +Version 1.5.5beta01 [July 13, 2011] + Fixed some typos and made other minor changes in the manual. + Updated contrib/pngminus/makefile.std (Samuli Souminen) + +Version 1.5.5beta02 [July 14, 2011] + Revised Makefile.am and Makefile.in to look in the right directory for + pnglibconf.h.prebuilt + +Version 1.5.5beta03 [July 27, 2011] + Enabled compilation with g++ compiler. This compiler does not recognize + the file extension, so it always compiles with C++ rules. Made minor + changes to pngrutil.c to cast results where C++ expects it but C does not. + Minor editing of libpng.3 and libpng-manual.txt. + +Version 1.5.5beta04 [July 29, 2011] + Revised CMakeLists.txt (Clifford Yapp) + Updated commentary about the png_rgb_to_gray() default coefficients + in the manual and in pngrtran.c + +Version 1.5.5beta05 [August 17, 2011] + Prevent unexpected API exports from non-libpng DLLs on Windows. The "_DLL" + is removed from the test of whether a DLL is being built (this erroneously + caused the libpng APIs to be marked as DLL exports in static builds under + Microsoft Visual Studio). Almost all of the libpng building configuration + is moved from pngconf.h to pngpriv.h, but PNG_DLL_EXPORT remains in + pngconf.h, though, so that it is colocated with the import definition (it + is no longer used anywhere in the installed headers). The VStudio project + definitions have been cleaned up: "_USRDLL" has been removed from the + static library builds (this was incorrect), and PNG_USE_DLL has been added + to pngvalid to test the functionality (pngtest does not supply it, + deliberately). The spurious "_EXPORTS" has been removed from the + libpng build (all these errors were a result of copy/paste between project + configurations.) + Added new types and internal functions for CIE RGB end point handling to + pngpriv.h (functions yet to be implemented). + +Version 1.5.5beta06 [August 26, 2011] + Ensure the CMAKE_LIBRARY_OUTPUT_DIRECTORY is set in CMakeLists.txt + (Clifford Yap) + Fixes to rgb_to_gray and cHRM XYZ APIs (John Bowler): + The rgb_to_gray code had errors when combined with gamma correction. + Some pixels were treated as true grey when they weren't and such pixels + and true grey ones were not gamma corrected (the original value of the + red component was used instead). APIs to get and set cHRM using color + space end points have been added and the rgb_to_gray code that defaults + based on cHRM, and the divide-by-zero bug in png_handle_cHRM (CERT + VU#477046, CVE-2011-3328, introduced in 1.5.4) have been corrected. + A considerable number of tests has been added to pngvalid for the + rgb_to_gray transform. + Arithmetic errors in rgb_to_gray whereby the calculated gray value was + truncated to the bit depth rather than rounded have been fixed except in + the 8-bit non-gamma-corrected case (where consistency seems more important + than correctness.) The code still has considerable inaccuracies in the + 8-bit case because 8-bit linear arithmetic is used. + +Version 1.5.5beta07 [September 7, 2011] + Added "$(ARCH)" option to makefile.darwin + Added SunOS support to configure.ac and Makefile.am + Changed png_chunk_benign_error() to png_warning() in png.c, in + png_XYZ_from_xy_checked(). + +Version 1.5.5beta08 [September 10, 2011] + Fixed 64-bit compilation errors (gcc). The errors fixed relate + to conditions where types that are 32 bits in the GCC 32-bit + world (uLong and png_size_t) become 64 bits in the 64-bit + world. This produces potential truncation errors which the + compiler correctly flags. + Relocated new HAVE_SOLARIS_LD definition in configure.ac + Constant changes for 64-bit compatibility (removal of L suffixes). The + 16-bit cases still use "L" as we don't have a 16-bit test system. + +Version 1.5.5rc01 [September 15, 2011] + Removed "L" suffixes in pngpriv.h + +Version 1.5.5 [September 22, 2011] + No changes. + +Version 1.5.6beta01 [September 22, 2011] + Fixed some 64-bit type conversion warnings in pngrtran.c + Moved row_info from png_struct to a local variable. + The various interlace mask arrays have been made into arrays of + bytes and made PNG_CONST and static (previously some arrays were + marked PNG_CONST and some weren't). + Additional checks have been added to the transform code to validate the + pixel depths after the transforms on both read and write. + Removed some redundant code from pngwrite.c, in png_destroy_write_struct(). + Changed chunk reading/writing code to use png_uint_32 instead of png_byte[4]. + This removes the need to allocate temporary strings for chunk names on + the stack in the read/write code. Unknown chunk handling still uses the + string form because this is exposed in the API. + +Version 1.5.6beta02 [September 26, 2011] + Added a note in the manual the png_read_update_info() must be called only + once with a particular info_ptr. + Fixed a typo in the definition of the new PNG_STRING_FROM_CHUNK(s,c) macro. + +Version 1.5.6beta03 [September 28, 2011] + Revised test-pngtest.sh to report FAIL when pngtest fails. + Added "--strict" option to pngtest, to report FAIL when the failure is + only because the resulting valid files are different. + Revised CMakeLists.txt to work with mingw and removed some material from + CMakeLists.txt that is no longer useful in libpng-1.5. + +Version 1.5.6beta04 [October 5, 2011] + Fixed typo in Makefile.in and Makefile.am ("-M Wl" should be "-M -Wl")." + +Version 1.5.6beta05 [October 12, 2011] + Speed up png_combine_row() for interlaced images. This reduces the generality + of the code, allowing it to be optimized for Adam7 interlace. The masks + passed to png_combine_row() are now generated internally, avoiding + some code duplication and localizing the interlace handling somewhat. + Align png_struct::row_buf - previously it was always unaligned, caused by + a bug in the code that attempted to align it; the code needs to subtract + one from the pointer to take account of the filter byte prepended to + each row. + Optimized png_combine_row() when rows are aligned. This gains a small + percentage for 16-bit and 32-bit pixels in the typical case where the + output row buffers are appropriately aligned. The optimization was not + previously possible because the png_struct buffer was always misaligned. + Fixed bug in png_write_chunk_header() debug print, introduced in 1.5.6beta01. + +Version 1.5.6beta06 [October 17, 2011] + Removed two redundant tests for unitialized row. + Fixed a relatively harmless memory overwrite in compressed text writing + with a 1 byte zlib buffer. + Add ability to call png_read_update_info multiple times to pngvalid.c. + Fixes for multiple calls to png_read_update_info. These fixes attend to + most of the errors revealed in pngvalid, however doing the gamma work + twice results in inaccuracies that can't be easily fixed. There is now + a warning in the code if this is going to happen. + Turned on multiple png_read_update_info in pngvalid transform tests. + Prevent libpng from overwriting unused bits at the end of the image when + it is not byte aligned, while reading. Prior to libpng-1.5.6 libpng would + overwrite the partial byte at the end of each row if the row width was not + an exact multiple of 8 bits and the image is not interlaced. + +Version 1.5.6beta07 [October 21, 2011] + Made png_ptr->prev_row an aligned pointer into png_ptr->big_prev_row + (Mans Rullgard). + +Version 1.5.6rc01 [October 26, 2011] + Changed misleading "Missing PLTE before cHRM" warning to "Out of place cHRM" + +Version 1.5.6rc02 [October 27, 2011] + Added LSR() macro to defend against buggy compilers that evaluate non-taken + code branches and complain about out-of-range shifts. + +Version 1.5.6rc03 [October 28, 2011] + Renamed the LSR() macro to PNG_LSR() and added PNG_LSL() macro. + Fixed compiler warnings with Intel and MSYS compilers. The logical shift + fix for Microsoft Visual C is required by other compilers, so this + enables that fix for all compilers when using compile-time constants. + Under MSYS 'byte' is a name declared in a system header file, so we + changed the name of a local variable to avoid the warnings that result. + Added #define PNG_ALIGN_TYPE PNG_ALIGN_NONE to contrib/pngminim/*/pngusr.h + +Version 1.5.6 [November 3, 2011] + No changes. + +Version 1.5.7beta01 [November 4, 2011] + Added support for ARM processor (Mans Rullgard) + Fixed bug in pngvalid on early allocation failure; fixed type cast in + pngmem.c; pngvalid would attempt to call png_error() if the allocation + of a png_struct or png_info failed. This would probably have led to a + crash. The pngmem.c implementation of png_malloc() included a cast + to png_size_t which would fail on large allocations on 16-bit systems. + Fix for the preprocessor of the Intel C compiler. The preprocessor + splits adjacent @ signs with a space; this changes the concatentation + token from @-@-@ to PNG_JOIN; that should work with all compiler + preprocessors. + Paeth filter speed improvements from work by Siarhei Siamashka. This + changes the 'Paeth' reconstruction function to improve the GCC code + generation on x86. The changes are only part of the suggested ones; + just the changes that definitely improve speed and remain simple. + The changes also slightly increase the clarity of the code. + +Version 1.5.7beta02 [November 11, 2011] + Check compression_type parameter in png_get_iCCP and remove spurious + casts. The compression_type parameter is always assigned to, so must + be non-NULL. The cast of the profile length potentially truncated the + value unnecessarily on a 16-bit int system, so the cast of the (byte) + compression type to (int) is specified by ANSI-C anyway. + Fixed FP division by zero in pngvalid.c; the 'test_pixel' code left + the sBIT fields in the test pixel as 0, which resulted in a floating + point division by zero which was irrelevant but causes systems where + FP exceptions cause a crash. Added code to pngvalid to turn on FP + exceptions if the appropriate glibc support is there to ensure this is + tested in the future. + Updated scripts/pnglibconf.mak and scripts/makefile.std to handle the + new PNG_JOIN macro. + Added versioning to pnglibconf.h comments. + Simplified read/write API initial version; basic read/write tested on + a variety of images, limited documentation (in the header file.) + Installed more accurate linear to sRGB conversion tables. The slightly + modified tables reduce the number of 16-bit values that + convert to an off-by-one 8-bit value. The "makesRGB.c" code that was used + to generate the tables is now in a contrib/sRGBtables sub-directory. + +Version 1.5.7beta03 [November 17, 2011] + Removed PNG_CONST from the sRGB table declarations in pngpriv.h and png.c + Added run-time detection of NEON support. + Added contrib/libtests; includes simplified API test and timing test and + a color conversion utility for rapid checking of failed 'pngstest' results. + Multiple transform bug fixes plus a work-round for double gamma correction. + libpng does not support more than one transform that requires linear data + at once - if this is tried typically the results is double gamma + correction. Since the simplified APIs can need rgb to gray combined with + a compose operation it is necessary to do one of these outside the main + libpng transform code. This check-in also contains fixes to various bugs + in the simplified APIs themselves and to some bugs in compose and rgb to + gray (on palette) itself. + Fixes for C++ compilation using g++ When libpng source is compiled + using g++. The compiler imposes C++ rules on the C source; thus it + is desireable to make the source work with either C or C++ rules + without throwing away useful error information. This change adds + png_voidcast to allow C semantic (void*) cases or the corresponding + C++ static_cast operation, as appropriate. + Added --noexecstack to assembler file compilation. GCC does not set + this on assembler compilation, even though it does on C compilation. + This creates security issues if assembler code is enabled; the + work-around is to set it by default in the flags for $(CCAS) + Work around compilers that don't support declaration of const data. Some + compilers fault 'extern const' data declarations (because the data is + not initialized); this turns on const-ness only for compilers where + this is known to work. + +Version 1.5.7beta04 [November 17, 2011] + Since the gcc driver does not recognize the --noexecstack flag, we must + use the -Wa prefix to have it passed through to the assembler. + Also removed a duplicate setting of this flag. + Added files that were omitted from the libpng-1.5.7beta03 zip distribution. + +Version 1.5.7beta05 [November 25, 2011] + Removed "zTXt" from warning in generic chunk decompression function. + Validate time settings passed to pngset() and png_convert_to_rfc1123() + (Frank Busse). + Added MINGW support to CMakeLists.txt + Reject invalid compression flag or method when reading the iTXt chunk. + Backed out 'simplified' API changes. The API seems too complex and there + is a lack of consensus or enthusiasm for the proposals. The API also + reveals significant bugs inside libpng (double gamma correction and the + known bug of being unable to retrieve a corrected palette). It seems + better to wait until the bugs, at least, are corrected. + Moved pngvalid.c into contrib/libtests + Rebuilt Makefile.in, configure, etc., with autoconf-2.68 + +Version 1.5.7rc01 [December 1, 2011] + Replaced an "#if" with "#ifdef" in pngrtran.c + Revised #if PNG_DO_BC block in png.c (use #ifdef and add #else) + +Version 1.5.7rc02 [December 5, 2011] + Revised project files and contrib/pngvalid/pngvalid.c to account for + the relocation of pngvalid into contrib/libtests. + Revised pngconf.h to use " __declspec(restrict)" only when MSC_VER >= 1400, + as in libpng-1.5.4. + Put CRLF line endings in the owatcom project files. + +Version 1.5.7rc03 [December 7, 2011] + Updated CMakeLists.txt to account for the relocation of pngvalid.c + +Version 1.5.7 [December 15, 2011] + Minor fixes to pngvalid.c for gcc 4.6.2 compatibility to remove warnings + reported by earlier versions. + +Version 1.5.8beta01 [January 15, 2011] + Removed '#include config.h"' from contrib/libtests/pngvalid.c. It's not + needed and causes trouble for VPATH building. + Moved AC_MSG_CHECKING([if libraries can be versioned]) later to the proper + location in configure.ac (Gilles Espinasse). + Fix bug in pngerror.c: some long warnings were being improperly truncated + (CVE-2011-3464, bug introduced in libpng-1.5.3beta05). + +Version 1.5.8rc01 [January 21, 2012] + No changes. + +Version 1.5.8rc02 [January 25, 2012] + Fixed Min/GW uninstall to remove libpng.dll.a + Conditionalize the install rules for MINGW and CYGWIN in CMakeLists.txt + +Version 1.5.8 [February 1, 2012] + No changes. + +Version 1.5.9beta01 [February 3, 2012] + Rebuilt configure scripts in the tar distributions. + +Version 1.5.9beta02 [February 16, 2012] + Removed two unused definitions from scripts/pnglibconf.h.prebuilt + Removed some unused arrays (with #ifdef) from png_read_push_finish_row(). + Removed tests for no-longer-used *_EMPTY_PLTE_SUPPORTED from pngstruct.h + +Version 1.5.9rc01 [February 17, 2012] + Fixed CVE-2011-3026 buffer overrun bug. This bug was introduced when + iCCP chunk support was added at libpng-1.0.6. Deal more correctly with the + test on iCCP chunk length. Also removed spurious casts that may hide + problems on 16-bit systems. + +Version 1.5.9 [February 18, 2012] + No changes. + +Version 1.5.10beta01 [February 24, 2012] + Removed two useless #ifdef directives from pngread.c and one from pngrutil.c + Always put the CMAKE_LIBRARY in "lib" (removed special WIN32 case). + Removed empty vstudio/pngstest directory (Clifford Yapp). + Eliminated redundant png_push_read_tEXt|zTXt|iTXt|unknown code from + pngpread.c and use the sequential png_handle_tEXt, etc., in pngrutil.c; + now that png_ptr->buffer is inaccessible to applications, the special + handling is no longer useful. + Fixed bug with png_handle_hIST with odd chunk length (Frank Busse). + Added PNG_SAFE_LIMITS feature to pnglibconf.dfa and code in pngconf.h + to reset the user limits to safe ones if PNG_SAFE_LIMITS is defined. + To enable, use "CPPFLAGS=-DPNG_SAFE_LIMITS_SUPPORTED" on the configure + command or put "#define PNG_SAFE_LIMITS_SUPPORTED" in pnglibconf.h. + Revised the SAFE_LIMITS feature to be the same as the feature in libpng16. + Added information about the new limits in the manual. + +Version 1.5.10beta02 [February 27, 2012] + Updated Makefile.in + +Version 1.5.10beta03 [March 6, 2012] + Removed unused "current_text" members of png_struct and the png_free() + of png_ptr->current_text from pngread.c + Added palette-index checking. Issue a png_warning() if an invalid index is + found. + +Version 1.5.10beta04 [March 10, 2012] + Fixed PNG_LIBPNG_BUILD_BASE_TYPE definition. + Fixed CMF optimization of non-IDAT compressed chunks, which was added at + libpng-1.5.4. It sometimes produced too small of a window. + +Version 1.5.10beta05 [March 10, 2012] + Reject all iCCP chunks after the first, even if the first one is invalid. + Issue a png_benign_error() instead of png_warning() about bad palette index. + Fixed an off-by-one error in the palette index checking function. + Revised example.c to put text strings in a temporary character array + instead of directly assigning string constants to png_textp members. + This avoids compiler warnings when -Wwrite-strings is enabled. + +Version 1.5.10 [March 29, 2012] + Prevent PNG_EXPAND+PNG_SHIFT doing the shift twice. + Revised png_set_text_2() to avoid potential memory corruption (fixes + CVE-2011-3048, also known as CVE-2012-3425). + +Version 1.5.11beta01 [April 28, 2012] + Revised scripts/makefile.darwin: use system zlib; remove quotes around + architecture list; add missing ppc architecture; add architecture options + to shared library link; don't try to create a shared lib based on missing + RELEASE variable. + Enable png_set_check_for_invalid_index() for both read and write. + Removed #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED/#endif in pngpriv.h around + declaration of png_handle_unknown(). + Added -lssp_nonshared in a comment in scripts/makefile.freebsd + and changed deprecated NOOBJ and NOPROFILE to NO_OBJ and NO_PROFILE. + +Version 1.5.11rc01 [May 23, 2012] + No changes. + +Version 1.5.11rc02 [May 29, 2012] + Fixed some typos in comments. + Revised CMakeLists.txt to not attempt to make a symlink under mingw. + Added two images to contrib/pngsuite (1-bit and 2-bit transparent grayscale), + and renamed three whose names were inconsistent with those in + pngsuite/README.txt. + +Version 1.5.11rc03 [June 4, 2012] + Do not depend upon a GCC feature macro being available for use in generating + the linker mapfile symbol prefix. + Made fixes for new optimization warnings from gcc 4.7.0. The compiler + performed an optimization which is safe but then warned about it. + Changing the type of 'palette_number' in pngvalid.c removes the warning. + +Version 1.5.11rc04 [June 6, 2012] + Improved performance of new do_check_palette_indexes() function. + +Version 1.5.11rc05 [June 7, 2012] + Don't check palette indexes if num_palette is 0 (as it can be in MNG files). + +Version 1.5.11 [June 14, 2012] + Include zlib.h in contrib/gregbook and contrib/visupng examples. + +Version 1.5.12 [July 11, 2012] + Removed scripts/makefile.cegcc from the *.zip and *.7z distributions; it + depends on configure, which is not included in those archives. + Changed "a+w" to "u+w" in Makefile.in to fix CVE-2012-3386. + +Version 1.5.13beta01 [August 8, 2012] + Do not compile PNG_DEPRECATED, PNG_ALLOC and PNG_PRIVATE when __GNUC__ < 3. + Removed references to png_zalloc() and png_zfree() from the manual. + Revised PNG_FP_EXPORT and PNG_FIXED_EXPORT macros to avoid generating + lone semicolons (patch ported from libpng-1.6.0beta11). + +Version 1.5.13beta02 [September 10, 2012] + Corrected handling of the image array and the row_pointers array in example.c + When png_set_filler is used to strip a filler channel during write, the + code prior to 1.5 would ignore the case where the output required an + alpha channel or when the output was a palettized PNG. In libpng-1.5 the + ignorance was lost and libpng proceeded to strip the channel resulting + in a bad (potential memory overwrite) failure later. This reverts + the behavior to the pre-1.5 state but issues a warning. libpng-1.6 is + expected to issue an error on the erroneous png_set_filler call. + Use png_memset() consistently (pngmem.c contained some bare "memset" calls). + +Version 1.5.13rc01 [September 17, 2012] + No changes. + +Version 1.5.13 [September 27, 2012] + No changes. + +Send comments/corrections/commendations to png-mng-implement at lists.sf.net +(subscription required; visit +https://lists.sourceforge.net/lists/listinfo/png-mng-implement +to subscribe) +or to glennrp at users.sourceforge.net + +Glenn R-P +#endif diff --git a/Source/LibPNG/INSTALL b/Source/LibPNG/INSTALL index c2d6c9e..353bfff 100644 --- a/Source/LibPNG/INSTALL +++ b/Source/LibPNG/INSTALL @@ -1,135 +1,135 @@ - -Installing libpng - -On Unix/Linux and similar systems, you can simply type - - ./configure [--prefix=/path] - make check - make install - -and ignore the rest of this document. - -If configure does not work on your system and you have a reasonably -up-to-date set of tools, running ./autogen.sh before running ./configure -may fix the problem. You can also run the individual commands in -autogen.sh with the --force option, if supported by your version of -the tools. To be really sure that you aren't using any of the included -pre-built scripts, you can do this: - - ./configure --enable-maintainer-mode - make maintainer-clean - ./autogen.sh - ./configure [--prefix=/path] [other options] - make - make install - make check - -Instead, you can use one of the custom-built makefiles in the -"scripts" directory - - cp scripts/makefile.system makefile - make test - make install - -The files that are presently available in the scripts directory -are listed and described in scripts/README.txt. - -Or you can use one of the "projects" in the "projects" directory. - -Before installing libpng, you must first install zlib, if it -is not already on your system. zlib can usually be found -wherever you got libpng. zlib can be placed in another directory, -at the same level as libpng. - -If you want to use "cmake" (see www.cmake.org), type - - cmake . -DCMAKE_INSTALL_PREFIX=/path - make - make install - -If your system already has a preinstalled zlib you will still need -to have access to the zlib.h and zconf.h include files that -correspond to the version of zlib that's installed. - -You can rename the directories that you downloaded (they -might be called "libpng-x.y.z" or "libpngNN" and "zlib-1.2.5" -or "zlib125") so that you have directories called "zlib" and "libpng". - -Your directory structure should look like this: - - .. (the parent directory) - libpng (this directory) - INSTALL (this file) - README - *.h - *.c - CMakeLists.txt => "cmake" script - configuration files: - configure.ac, configure, Makefile.am, Makefile.in, - autogen.sh, config.guess, ltmain.sh, missing, libpng.pc.in, - libpng-config.in, aclocal.m4, config.h.in, config.sub, - depcomp, install-sh, mkinstalldirs, test-pngtest.sh - contrib - gregbook - pngminim - pngminus - pngsuite - visupng - projects - visualc71 - vstudio - scripts - makefile.* - *.def (module definition files) - etc. - pngtest.png - etc. - zlib - README - *.h - *.c - contrib - etc. - -If the line endings in the files look funny, you may wish to get the other -distribution of libpng. It is available in both tar.gz (UNIX style line -endings) and zip (DOS style line endings) formats. - -If you are building libpng with MSVC, you can enter the -libpng projects\visualc6 or visualc71 directory and follow the instructions -in README.txt. - -Otherwise enter the zlib directory and follow the instructions in zlib/README, -then come back here and run "configure" or choose the appropriate -makefile.sys in the scripts directory. - -Copy the file (or files) that you need from the -scripts directory into this directory, for example - - MSDOS example: copy scripts\makefile.msc makefile - UNIX example: cp scripts/makefile.std makefile - -Read the makefile to see if you need to change any source or -target directories to match your preferences. - -Then read pnglibconf.dfa to see if you want to make any configuration -changes. - -Then just run "make" which will create the libpng library in -this directory and "make test" which will run a quick test that reads -the "pngtest.png" file and writes a "pngout.png" file that should be -identical to it. Look for "9782 zero samples" in the output of the -test. For more confidence, you can run another test by typing -"pngtest pngnow.png" and looking for "289 zero samples" in the output. -Also, you can run "pngtest -m contrib/pngsuite/*.png" and compare -your output with the result shown in contrib/pngsuite/README. - -Most of the makefiles will allow you to run "make install" to -put the library in its final resting place (if you want to -do that, run "make install" in the zlib directory first if necessary). -Some also allow you to run "make test-installed" after you have -run "make install". - -Further information can be found in the README and libpng-manual.txt -files, in the individual makefiles, in png.h, and the manual pages -libpng.3 and png.5. + +Installing libpng + +On Unix/Linux and similar systems, you can simply type + + ./configure [--prefix=/path] + make check + make install + +and ignore the rest of this document. + +If configure does not work on your system and you have a reasonably +up-to-date set of tools, running ./autogen.sh before running ./configure +may fix the problem. You can also run the individual commands in +autogen.sh with the --force option, if supported by your version of +the tools. To be really sure that you aren't using any of the included +pre-built scripts, you can do this: + + ./configure --enable-maintainer-mode + make maintainer-clean + ./autogen.sh + ./configure [--prefix=/path] [other options] + make + make install + make check + +Instead, you can use one of the custom-built makefiles in the +"scripts" directory + + cp scripts/makefile.system makefile + make test + make install + +The files that are presently available in the scripts directory +are listed and described in scripts/README.txt. + +Or you can use one of the "projects" in the "projects" directory. + +Before installing libpng, you must first install zlib, if it +is not already on your system. zlib can usually be found +wherever you got libpng. zlib can be placed in another directory, +at the same level as libpng. + +If you want to use "cmake" (see www.cmake.org), type + + cmake . -DCMAKE_INSTALL_PREFIX=/path + make + make install + +If your system already has a preinstalled zlib you will still need +to have access to the zlib.h and zconf.h include files that +correspond to the version of zlib that's installed. + +You can rename the directories that you downloaded (they +might be called "libpng-x.y.z" or "libpngNN" and "zlib-1.2.5" +or "zlib125") so that you have directories called "zlib" and "libpng". + +Your directory structure should look like this: + + .. (the parent directory) + libpng (this directory) + INSTALL (this file) + README + *.h + *.c + CMakeLists.txt => "cmake" script + configuration files: + configure.ac, configure, Makefile.am, Makefile.in, + autogen.sh, config.guess, ltmain.sh, missing, libpng.pc.in, + libpng-config.in, aclocal.m4, config.h.in, config.sub, + depcomp, install-sh, mkinstalldirs, test-pngtest.sh + contrib + gregbook + pngminim + pngminus + pngsuite + visupng + projects + visualc71 + vstudio + scripts + makefile.* + *.def (module definition files) + etc. + pngtest.png + etc. + zlib + README + *.h + *.c + contrib + etc. + +If the line endings in the files look funny, you may wish to get the other +distribution of libpng. It is available in both tar.gz (UNIX style line +endings) and zip (DOS style line endings) formats. + +If you are building libpng with MSVC, you can enter the +libpng projects\visualc6 or visualc71 directory and follow the instructions +in README.txt. + +Otherwise enter the zlib directory and follow the instructions in zlib/README, +then come back here and run "configure" or choose the appropriate +makefile.sys in the scripts directory. + +Copy the file (or files) that you need from the +scripts directory into this directory, for example + + MSDOS example: copy scripts\makefile.msc makefile + UNIX example: cp scripts/makefile.std makefile + +Read the makefile to see if you need to change any source or +target directories to match your preferences. + +Then read pnglibconf.dfa to see if you want to make any configuration +changes. + +Then just run "make" which will create the libpng library in +this directory and "make test" which will run a quick test that reads +the "pngtest.png" file and writes a "pngout.png" file that should be +identical to it. Look for "9782 zero samples" in the output of the +test. For more confidence, you can run another test by typing +"pngtest pngnow.png" and looking for "289 zero samples" in the output. +Also, you can run "pngtest -m contrib/pngsuite/*.png" and compare +your output with the result shown in contrib/pngsuite/README. + +Most of the makefiles will allow you to run "make install" to +put the library in its final resting place (if you want to +do that, run "make install" in the zlib directory first if necessary). +Some also allow you to run "make test-installed" after you have +run "make install". + +Further information can be found in the README and libpng-manual.txt +files, in the individual makefiles, in png.h, and the manual pages +libpng.3 and png.5. diff --git a/Source/LibPNG/LICENSE b/Source/LibPNG/LICENSE index 853fb2c..16a7d9e 100644 --- a/Source/LibPNG/LICENSE +++ b/Source/LibPNG/LICENSE @@ -1,111 +1,111 @@ - -This copy of the libpng notices is provided for your convenience. In case of -any discrepancy between this copy and the notices in the file png.h that is -included in the libpng distribution, the latter shall prevail. - -COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: - -If you modify libpng you may insert additional notices immediately following -this sentence. - -This code is released under the libpng license. - -libpng versions 1.2.6, August 15, 2004, through 1.5.13, September 27, 2012, are -Copyright (c) 2004, 2006-2012 Glenn Randers-Pehrson, and are -distributed according to the same disclaimer and license as libpng-1.2.5 -with the following individual added to the list of Contributing Authors - - Cosmin Truta - -libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are -Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are -distributed according to the same disclaimer and license as libpng-1.0.6 -with the following individuals added to the list of Contributing Authors - - Simon-Pierre Cadieux - Eric S. Raymond - Gilles Vollant - -and with the following additions to the disclaimer: - - There is no warranty against interference with your enjoyment of the - library or against infringement. There is no warranty that our - efforts or the library will fulfill any of your particular purposes - or needs. This library is provided with all faults, and the entire - risk of satisfactory quality, performance, accuracy, and effort is with - the user. - -libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are -Copyright (c) 1998, 1999 Glenn Randers-Pehrson, and are -distributed according to the same disclaimer and license as libpng-0.96, -with the following individuals added to the list of Contributing Authors: - - Tom Lane - Glenn Randers-Pehrson - Willem van Schaik - -libpng versions 0.89, June 1996, through 0.96, May 1997, are -Copyright (c) 1996, 1997 Andreas Dilger -Distributed according to the same disclaimer and license as libpng-0.88, -with the following individuals added to the list of Contributing Authors: - - John Bowler - Kevin Bracey - Sam Bushell - Magnus Holmgren - Greg Roelofs - Tom Tanner - -libpng versions 0.5, May 1995, through 0.88, January 1996, are -Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. - -For the purposes of this copyright and license, "Contributing Authors" -is defined as the following set of individuals: - - Andreas Dilger - Dave Martindale - Guy Eric Schalnat - Paul Schmidt - Tim Wegner - -The PNG Reference Library is supplied "AS IS". The Contributing Authors -and Group 42, Inc. disclaim all warranties, expressed or implied, -including, without limitation, the warranties of merchantability and of -fitness for any purpose. The Contributing Authors and Group 42, Inc. -assume no liability for direct, indirect, incidental, special, exemplary, -or consequential damages, which may result from the use of the PNG -Reference Library, even if advised of the possibility of such damage. - -Permission is hereby granted to use, copy, modify, and distribute this -source code, or portions hereof, for any purpose, without fee, subject -to the following restrictions: - -1. The origin of this source code must not be misrepresented. - -2. Altered versions must be plainly marked as such and must not - be misrepresented as being the original source. - -3. This Copyright notice may not be removed or altered from any - source or altered source distribution. - -The Contributing Authors and Group 42, Inc. specifically permit, without -fee, and encourage the use of this source code as a component to -supporting the PNG file format in commercial products. If you use this -source code in a product, acknowledgment is not required but would be -appreciated. - - -A "png_get_copyright" function is available, for convenient use in "about" -boxes and the like: - - printf("%s",png_get_copyright(NULL)); - -Also, the PNG logo (in PNG format, of course) is supplied in the -files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). - -Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a -certification mark of the Open Source Initiative. - -Glenn Randers-Pehrson -glennrp at users.sourceforge.net -September 27, 2012 + +This copy of the libpng notices is provided for your convenience. In case of +any discrepancy between this copy and the notices in the file png.h that is +included in the libpng distribution, the latter shall prevail. + +COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: + +If you modify libpng you may insert additional notices immediately following +this sentence. + +This code is released under the libpng license. + +libpng versions 1.2.6, August 15, 2004, through 1.5.13, September 27, 2012, are +Copyright (c) 2004, 2006-2012 Glenn Randers-Pehrson, and are +distributed according to the same disclaimer and license as libpng-1.2.5 +with the following individual added to the list of Contributing Authors + + Cosmin Truta + +libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are +Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are +distributed according to the same disclaimer and license as libpng-1.0.6 +with the following individuals added to the list of Contributing Authors + + Simon-Pierre Cadieux + Eric S. Raymond + Gilles Vollant + +and with the following additions to the disclaimer: + + There is no warranty against interference with your enjoyment of the + library or against infringement. There is no warranty that our + efforts or the library will fulfill any of your particular purposes + or needs. This library is provided with all faults, and the entire + risk of satisfactory quality, performance, accuracy, and effort is with + the user. + +libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are +Copyright (c) 1998, 1999 Glenn Randers-Pehrson, and are +distributed according to the same disclaimer and license as libpng-0.96, +with the following individuals added to the list of Contributing Authors: + + Tom Lane + Glenn Randers-Pehrson + Willem van Schaik + +libpng versions 0.89, June 1996, through 0.96, May 1997, are +Copyright (c) 1996, 1997 Andreas Dilger +Distributed according to the same disclaimer and license as libpng-0.88, +with the following individuals added to the list of Contributing Authors: + + John Bowler + Kevin Bracey + Sam Bushell + Magnus Holmgren + Greg Roelofs + Tom Tanner + +libpng versions 0.5, May 1995, through 0.88, January 1996, are +Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. + +For the purposes of this copyright and license, "Contributing Authors" +is defined as the following set of individuals: + + Andreas Dilger + Dave Martindale + Guy Eric Schalnat + Paul Schmidt + Tim Wegner + +The PNG Reference Library is supplied "AS IS". The Contributing Authors +and Group 42, Inc. disclaim all warranties, expressed or implied, +including, without limitation, the warranties of merchantability and of +fitness for any purpose. The Contributing Authors and Group 42, Inc. +assume no liability for direct, indirect, incidental, special, exemplary, +or consequential damages, which may result from the use of the PNG +Reference Library, even if advised of the possibility of such damage. + +Permission is hereby granted to use, copy, modify, and distribute this +source code, or portions hereof, for any purpose, without fee, subject +to the following restrictions: + +1. The origin of this source code must not be misrepresented. + +2. Altered versions must be plainly marked as such and must not + be misrepresented as being the original source. + +3. This Copyright notice may not be removed or altered from any + source or altered source distribution. + +The Contributing Authors and Group 42, Inc. specifically permit, without +fee, and encourage the use of this source code as a component to +supporting the PNG file format in commercial products. If you use this +source code in a product, acknowledgment is not required but would be +appreciated. + + +A "png_get_copyright" function is available, for convenient use in "about" +boxes and the like: + + printf("%s",png_get_copyright(NULL)); + +Also, the PNG logo (in PNG format, of course) is supplied in the +files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). + +Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a +certification mark of the Open Source Initiative. + +Glenn Randers-Pehrson +glennrp at users.sourceforge.net +September 27, 2012 diff --git a/Source/LibPNG/README b/Source/LibPNG/README index 5afeae8..ca26e4b 100644 --- a/Source/LibPNG/README +++ b/Source/LibPNG/README @@ -1,202 +1,202 @@ -README for libpng version 1.5.13 - September 27, 2012 (shared library 15.0) -See the note about version numbers near the top of png.h - -See INSTALL for instructions on how to install libpng. - -Libpng comes in several distribution formats. Get libpng-*.tar.gz, -libpng-*.tar.xz or libpng-*.tar.bz2 if you want UNIX-style line endings -in the text files, or lpng*.zip if you want DOS-style line endings. - -Version 0.89 was the first official release of libpng. Don't let the -fact that it's the first release fool you. The libpng library has been in -extensive use and testing since mid-1995. By late 1997 it had -finally gotten to the stage where there hadn't been significant -changes to the API in some time, and people have a bad feeling about -libraries with versions < 1.0. Version 1.0.0 was released in -March 1998. - -**** -Note that some of the changes to the png_info structure render this -version of the library binary incompatible with libpng-0.89 or -earlier versions if you are using a shared library. The type of the -"filler" parameter for png_set_filler() has changed from png_byte to -png_uint_32, which will affect shared-library applications that use -this function. - -To avoid problems with changes to the internals of png_info_struct, -new APIs have been made available in 0.95 to avoid direct application -access to info_ptr. These functions are the png_set_ and -png_get_ functions. These functions should be used when -accessing/storing the info_struct data, rather than manipulating it -directly, to avoid such problems in the future. - -It is important to note that the APIs do not make current programs -that access the info struct directly incompatible with the new -library. However, it is strongly suggested that new programs use -the new APIs (as shown in example.c and pngtest.c), and older programs -be converted to the new format, to facilitate upgrades in the future. -**** - -Additions since 0.90 include the ability to compile libpng as a -Windows DLL, and new APIs for accessing data in the info struct. -Experimental functions include the ability to set weighting and cost -factors for row filter selection, direct reads of integers from buffers -on big-endian processors that support misaligned data access, faster -methods of doing alpha composition, and more accurate 16->8 bit color -conversion. - -The additions since 0.89 include the ability to read from a PNG stream -which has had some (or all) of the signature bytes read by the calling -application. This also allows the reading of embedded PNG streams that -do not have the PNG file signature. As well, it is now possible to set -the library action on the detection of chunk CRC errors. It is possible -to set different actions based on whether the CRC error occurred in a -critical or an ancillary chunk. - -The changes made to the library, and bugs fixed are based on discussions -on the PNG-implement mailing list and not on material submitted -privately to Guy, Andreas, or Glenn. They will forward any good -suggestions to the list. - -For a detailed description on using libpng, read libpng-manual.txt. For -examples of libpng in a program, see example.c and pngtest.c. For usage -information and restrictions (what little they are) on libpng, see -png.h. For a description on using zlib (the compression library used by -libpng) and zlib's restrictions, see zlib.h - -I have included a general makefile, as well as several machine and -compiler specific ones, but you may have to modify one for your own needs. - -You should use zlib 1.0.4 or later to run this, but it MAY work with -versions as old as zlib 0.95. Even so, there are bugs in older zlib -versions which can cause the output of invalid compression streams for -some images. You will definitely need zlib 1.0.4 or later if you are -taking advantage of the MS-DOS "far" structure allocation for the small -and medium memory models. You should also note that zlib is a -compression library that is useful for more things than just PNG files. -You can use zlib as a drop-in replacement for fread() and fwrite() if -you are so inclined. - -zlib should be available at the same place that libpng is, or at. -ftp://ftp.info-zip.org/pub/infozip/zlib - -You may also want a copy of the PNG specification. It is available -as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find -these at http://www.libpng.org/pub/png/documents/ - -This code is currently being archived at libpng.sf.net in the -[DOWNLOAD] area, and on CompuServe, Lib 20 (PNG SUPPORT) -at GO GRAPHSUP. If you can't find it in any of those places, -e-mail me, and I'll help you find it. - -If you have any code changes, requests, problems, etc., please e-mail -them to me. Also, I'd appreciate any make files or project files, -and any modifications you needed to make to get libpng to compile, -along with a #define variable to tell what compiler/system you are on. -If you needed to add transformations to libpng, or wish libpng would -provide the image in a different way, drop me a note (and code, if -possible), so I can consider supporting the transformation. -Finally, if you get any warning messages when compiling libpng -(note: not zlib), and they are easy to fix, I'd appreciate the -fix. Please mention "libpng" somewhere in the subject line. Thanks. - -This release was created and will be supported by myself (of course -based in a large way on Guy's and Andreas' earlier work), and the PNG -development group. - -Send comments/corrections/commendations to png-mng-implement at -lists.sourceforge.net (subscription required; visit -https://lists.sourceforge.net/lists/listinfo/png-mng-implement -to subscribe) or to glennrp at users.sourceforge.net - -You can't reach Guy, the original libpng author, at the addresses -given in previous versions of this document. He and Andreas will -read mail addressed to the png-implement list, however. - -Please do not send general questions about PNG. Send them to -png-mng-misc at lists.sf.net (subscription required; visit -https://lists.sourceforge.net/lists/listinfo/png-mng-misc to -subscribe). If you have a question about something -in the PNG specification that is related to using libpng, send it -to me. Send me any questions that start with "I was using libpng, -and ...". If in doubt, send questions to me. I'll bounce them -to others, if necessary. - -Please do not send suggestions on how to change PNG. We have -been discussing PNG for sixteen years now, and it is official and -finished. If you have suggestions for libpng, however, I'll -gladly listen. Even if your suggestion is not used immediately, -it may be used later. - -Files in this distribution: - - ANNOUNCE => Announcement of this version, with recent changes - CHANGES => Description of changes between libpng versions - KNOWNBUG => List of known bugs and deficiencies - LICENSE => License to use and redistribute libpng - README => This file - TODO => Things not implemented in the current library - Y2KINFO => Statement of Y2K compliance - example.c => Example code for using libpng functions - libpng.3 => manual page for libpng (includes libpng-manual.txt) - libpng-manual.txt => Description of libpng and its functions - libpngpf.3 => manual page for libpng's private functions - png.5 => manual page for the PNG format - png.c => Basic interface functions common to library - png.h => Library function and interface declarations (public) - pngpriv.h => Library function and interface declarations (private) - pngconf.h => System specific library configuration (public) - pngstruct.h => png_struct declaration (private) - pnginfo.h => png_info struct declaration (private) - pngdebug.h => debugging macros (private) - pngerror.c => Error/warning message I/O functions - pngget.c => Functions for retrieving info from struct - pngmem.c => Memory handling functions - pngbar.png => PNG logo, 88x31 - pngnow.png => PNG logo, 98x31 - pngpread.c => Progressive reading functions - pngread.c => Read data/helper high-level functions - pngrio.c => Lowest-level data read I/O functions - pngrtran.c => Read data transformation functions - pngrutil.c => Read data utility functions - pngset.c => Functions for storing data into the info_struct - pngtest.c => Library test program - pngtest.png => Library test sample image - pngtrans.c => Common data transformation functions - pngwio.c => Lowest-level write I/O functions - pngwrite.c => High-level write functions - pngwtran.c => Write data transformations - pngwutil.c => Write utility functions - contrib => Contributions - gregbook => source code for PNG reading and writing, from - Greg Roelofs' "PNG: The Definitive Guide", - O'Reilly, 1999 - msvctest => Builds and runs pngtest using a MSVC workspace - pngminus => Simple pnm2png and png2pnm programs - pngsuite => Test images - visupng => Contains a MSVC workspace for VisualPng - projects => Contains project files and workspaces for - building a DLL - cbuilder5 => Contains a Borland workspace for building - libpng and zlib - visualc6 => Contains a Microsoft Visual C++ (MSVC) - workspace for building libpng and zlib - visualc71 => Contains a Microsoft Visual C++ (MSVC) - workspace for building libpng and zlib - xcode => Contains an Apple xcode - workspace for building libpng and zlib - scripts => Directory containing scripts for building libpng: - (see scripts/README.txt for the list of scripts) - -Good luck, and happy coding. - --Glenn Randers-Pehrson (current maintainer, since 1998) - Internet: glennrp at users.sourceforge.net - --Andreas Eric Dilger (former maintainer, 1996-1997) - Internet: adilger at enel.ucalgary.ca - Web: http://www-mddsp.enel.ucalgary.ca/People/adilger/ - --Guy Eric Schalnat (original author and former maintainer, 1995-1996) - (formerly of Group 42, Inc) - Internet: gschal at infinet.com +README for libpng version 1.5.13 - September 27, 2012 (shared library 15.0) +See the note about version numbers near the top of png.h + +See INSTALL for instructions on how to install libpng. + +Libpng comes in several distribution formats. Get libpng-*.tar.gz, +libpng-*.tar.xz or libpng-*.tar.bz2 if you want UNIX-style line endings +in the text files, or lpng*.zip if you want DOS-style line endings. + +Version 0.89 was the first official release of libpng. Don't let the +fact that it's the first release fool you. The libpng library has been in +extensive use and testing since mid-1995. By late 1997 it had +finally gotten to the stage where there hadn't been significant +changes to the API in some time, and people have a bad feeling about +libraries with versions < 1.0. Version 1.0.0 was released in +March 1998. + +**** +Note that some of the changes to the png_info structure render this +version of the library binary incompatible with libpng-0.89 or +earlier versions if you are using a shared library. The type of the +"filler" parameter for png_set_filler() has changed from png_byte to +png_uint_32, which will affect shared-library applications that use +this function. + +To avoid problems with changes to the internals of png_info_struct, +new APIs have been made available in 0.95 to avoid direct application +access to info_ptr. These functions are the png_set_ and +png_get_ functions. These functions should be used when +accessing/storing the info_struct data, rather than manipulating it +directly, to avoid such problems in the future. + +It is important to note that the APIs do not make current programs +that access the info struct directly incompatible with the new +library. However, it is strongly suggested that new programs use +the new APIs (as shown in example.c and pngtest.c), and older programs +be converted to the new format, to facilitate upgrades in the future. +**** + +Additions since 0.90 include the ability to compile libpng as a +Windows DLL, and new APIs for accessing data in the info struct. +Experimental functions include the ability to set weighting and cost +factors for row filter selection, direct reads of integers from buffers +on big-endian processors that support misaligned data access, faster +methods of doing alpha composition, and more accurate 16->8 bit color +conversion. + +The additions since 0.89 include the ability to read from a PNG stream +which has had some (or all) of the signature bytes read by the calling +application. This also allows the reading of embedded PNG streams that +do not have the PNG file signature. As well, it is now possible to set +the library action on the detection of chunk CRC errors. It is possible +to set different actions based on whether the CRC error occurred in a +critical or an ancillary chunk. + +The changes made to the library, and bugs fixed are based on discussions +on the PNG-implement mailing list and not on material submitted +privately to Guy, Andreas, or Glenn. They will forward any good +suggestions to the list. + +For a detailed description on using libpng, read libpng-manual.txt. For +examples of libpng in a program, see example.c and pngtest.c. For usage +information and restrictions (what little they are) on libpng, see +png.h. For a description on using zlib (the compression library used by +libpng) and zlib's restrictions, see zlib.h + +I have included a general makefile, as well as several machine and +compiler specific ones, but you may have to modify one for your own needs. + +You should use zlib 1.0.4 or later to run this, but it MAY work with +versions as old as zlib 0.95. Even so, there are bugs in older zlib +versions which can cause the output of invalid compression streams for +some images. You will definitely need zlib 1.0.4 or later if you are +taking advantage of the MS-DOS "far" structure allocation for the small +and medium memory models. You should also note that zlib is a +compression library that is useful for more things than just PNG files. +You can use zlib as a drop-in replacement for fread() and fwrite() if +you are so inclined. + +zlib should be available at the same place that libpng is, or at. +ftp://ftp.info-zip.org/pub/infozip/zlib + +You may also want a copy of the PNG specification. It is available +as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find +these at http://www.libpng.org/pub/png/documents/ + +This code is currently being archived at libpng.sf.net in the +[DOWNLOAD] area, and on CompuServe, Lib 20 (PNG SUPPORT) +at GO GRAPHSUP. If you can't find it in any of those places, +e-mail me, and I'll help you find it. + +If you have any code changes, requests, problems, etc., please e-mail +them to me. Also, I'd appreciate any make files or project files, +and any modifications you needed to make to get libpng to compile, +along with a #define variable to tell what compiler/system you are on. +If you needed to add transformations to libpng, or wish libpng would +provide the image in a different way, drop me a note (and code, if +possible), so I can consider supporting the transformation. +Finally, if you get any warning messages when compiling libpng +(note: not zlib), and they are easy to fix, I'd appreciate the +fix. Please mention "libpng" somewhere in the subject line. Thanks. + +This release was created and will be supported by myself (of course +based in a large way on Guy's and Andreas' earlier work), and the PNG +development group. + +Send comments/corrections/commendations to png-mng-implement at +lists.sourceforge.net (subscription required; visit +https://lists.sourceforge.net/lists/listinfo/png-mng-implement +to subscribe) or to glennrp at users.sourceforge.net + +You can't reach Guy, the original libpng author, at the addresses +given in previous versions of this document. He and Andreas will +read mail addressed to the png-implement list, however. + +Please do not send general questions about PNG. Send them to +png-mng-misc at lists.sf.net (subscription required; visit +https://lists.sourceforge.net/lists/listinfo/png-mng-misc to +subscribe). If you have a question about something +in the PNG specification that is related to using libpng, send it +to me. Send me any questions that start with "I was using libpng, +and ...". If in doubt, send questions to me. I'll bounce them +to others, if necessary. + +Please do not send suggestions on how to change PNG. We have +been discussing PNG for sixteen years now, and it is official and +finished. If you have suggestions for libpng, however, I'll +gladly listen. Even if your suggestion is not used immediately, +it may be used later. + +Files in this distribution: + + ANNOUNCE => Announcement of this version, with recent changes + CHANGES => Description of changes between libpng versions + KNOWNBUG => List of known bugs and deficiencies + LICENSE => License to use and redistribute libpng + README => This file + TODO => Things not implemented in the current library + Y2KINFO => Statement of Y2K compliance + example.c => Example code for using libpng functions + libpng.3 => manual page for libpng (includes libpng-manual.txt) + libpng-manual.txt => Description of libpng and its functions + libpngpf.3 => manual page for libpng's private functions + png.5 => manual page for the PNG format + png.c => Basic interface functions common to library + png.h => Library function and interface declarations (public) + pngpriv.h => Library function and interface declarations (private) + pngconf.h => System specific library configuration (public) + pngstruct.h => png_struct declaration (private) + pnginfo.h => png_info struct declaration (private) + pngdebug.h => debugging macros (private) + pngerror.c => Error/warning message I/O functions + pngget.c => Functions for retrieving info from struct + pngmem.c => Memory handling functions + pngbar.png => PNG logo, 88x31 + pngnow.png => PNG logo, 98x31 + pngpread.c => Progressive reading functions + pngread.c => Read data/helper high-level functions + pngrio.c => Lowest-level data read I/O functions + pngrtran.c => Read data transformation functions + pngrutil.c => Read data utility functions + pngset.c => Functions for storing data into the info_struct + pngtest.c => Library test program + pngtest.png => Library test sample image + pngtrans.c => Common data transformation functions + pngwio.c => Lowest-level write I/O functions + pngwrite.c => High-level write functions + pngwtran.c => Write data transformations + pngwutil.c => Write utility functions + contrib => Contributions + gregbook => source code for PNG reading and writing, from + Greg Roelofs' "PNG: The Definitive Guide", + O'Reilly, 1999 + msvctest => Builds and runs pngtest using a MSVC workspace + pngminus => Simple pnm2png and png2pnm programs + pngsuite => Test images + visupng => Contains a MSVC workspace for VisualPng + projects => Contains project files and workspaces for + building a DLL + cbuilder5 => Contains a Borland workspace for building + libpng and zlib + visualc6 => Contains a Microsoft Visual C++ (MSVC) + workspace for building libpng and zlib + visualc71 => Contains a Microsoft Visual C++ (MSVC) + workspace for building libpng and zlib + xcode => Contains an Apple xcode + workspace for building libpng and zlib + scripts => Directory containing scripts for building libpng: + (see scripts/README.txt for the list of scripts) + +Good luck, and happy coding. + +-Glenn Randers-Pehrson (current maintainer, since 1998) + Internet: glennrp at users.sourceforge.net + +-Andreas Eric Dilger (former maintainer, 1996-1997) + Internet: adilger at enel.ucalgary.ca + Web: http://www-mddsp.enel.ucalgary.ca/People/adilger/ + +-Guy Eric Schalnat (original author and former maintainer, 1995-1996) + (formerly of Group 42, Inc) + Internet: gschal at infinet.com diff --git a/Source/LibPNG/TODO b/Source/LibPNG/TODO index b1660a4..6e1f028 100644 --- a/Source/LibPNG/TODO +++ b/Source/LibPNG/TODO @@ -1,27 +1,27 @@ -/* -TODO - list of things to do for libpng: - -Final bug fixes. -Better C++ wrapper/full C++ implementation? -Fix problem with C++ and EXTERN "C". -cHRM transformation. -Remove setjmp/longjmp usage in favor of returning error codes. -Add "grayscale->palette" transformation and "palette->grayscale" detection. -Improved dithering. -Multi-lingual error and warning message support. -Complete sRGB transformation (presently it simply uses gamma=0.45455). -Man pages for function calls. -Better documentation. -Better filter selection - (counting huffman bits/precompression? filter inertia? filter costs?). -Histogram creation. -Text conversion between different code pages (Latin-1 -> Mac and DOS). -Avoid building gamma tables whenever possible. -Use greater precision when changing to linear gamma for compositing against - background and doing rgb-to-gray transformation. -Investigate pre-incremented loop counters and other loop constructions. -Add interpolated method of handling interlacing. -Switch to the simpler zlib (zlib/libpng) license if legally possible. -Extend pngvalid.c to validate more of the libpng transformations. - -*/ +/* +TODO - list of things to do for libpng: + +Final bug fixes. +Better C++ wrapper/full C++ implementation? +Fix problem with C++ and EXTERN "C". +cHRM transformation. +Remove setjmp/longjmp usage in favor of returning error codes. +Add "grayscale->palette" transformation and "palette->grayscale" detection. +Improved dithering. +Multi-lingual error and warning message support. +Complete sRGB transformation (presently it simply uses gamma=0.45455). +Man pages for function calls. +Better documentation. +Better filter selection + (counting huffman bits/precompression? filter inertia? filter costs?). +Histogram creation. +Text conversion between different code pages (Latin-1 -> Mac and DOS). +Avoid building gamma tables whenever possible. +Use greater precision when changing to linear gamma for compositing against + background and doing rgb-to-gray transformation. +Investigate pre-incremented loop counters and other loop constructions. +Add interpolated method of handling interlacing. +Switch to the simpler zlib (zlib/libpng) license if legally possible. +Extend pngvalid.c to validate more of the libpng transformations. + +*/ diff --git a/Source/LibPNG/configure b/Source/LibPNG/configure index 218dddd..ee0ac54 100644 --- a/Source/LibPNG/configure +++ b/Source/LibPNG/configure @@ -1,19 +1,19 @@ - -echo " - There is no \"configure\" script in this distribution (*.zip or *.7z) of - libpng-1.5.13. - - Instead, please copy the appropriate makefile for your system from the - \"scripts\" directory. Read the INSTALL file for more details. - - Update, July 2004: you can get a \"configure\" based distribution - from the libpng distribution sites. Download the file - libpng-1.5.13.tar.gz, libpng-1.5.13.tar.xz, or libpng-1.5.13.tar.bz2 - - If the line endings in the files look funny, which is likely to be the - case if you were trying to run \"configure\" on a Linux machine, you may - wish to get the other distribution of libpng. It is available in both - tar.gz/tar.xz (UNIX style line endings, with \"configure\") and .7z/.zip - (DOS style line endings, without \"configure\") formats. -" - + +echo " + There is no \"configure\" script in this distribution (*.zip or *.7z) of + libpng-1.5.13. + + Instead, please copy the appropriate makefile for your system from the + \"scripts\" directory. Read the INSTALL file for more details. + + Update, July 2004: you can get a \"configure\" based distribution + from the libpng distribution sites. Download the file + libpng-1.5.13.tar.gz, libpng-1.5.13.tar.xz, or libpng-1.5.13.tar.bz2 + + If the line endings in the files look funny, which is likely to be the + case if you were trying to run \"configure\" on a Linux machine, you may + wish to get the other distribution of libpng. It is available in both + tar.gz/tar.xz (UNIX style line endings, with \"configure\") and .7z/.zip + (DOS style line endings, without \"configure\") formats. +" + diff --git a/Source/LibPNG/example.c b/Source/LibPNG/example.c index 04241ef..86068ea 100644 --- a/Source/LibPNG/example.c +++ b/Source/LibPNG/example.c @@ -1,879 +1,879 @@ - -#if 0 /* in case someone actually tries to compile this */ - -/* example.c - an example of using libpng - * Last changed in libpng 1.5.10 [March 8, 2012] - * Maintained 1998-2012 Glenn Randers-Pehrson - * Maintained 1996, 1997 Andreas Dilger - * Written 1995, 1996 Guy Eric Schalnat, Group 42, Inc. - */ - -/* This is an example of how to use libpng to read and write PNG files. - * The file libpng-manual.txt is much more verbose then this. If you have not - * read it, do so first. This was designed to be a starting point of an - * implementation. This is not officially part of libpng, is hereby placed - * in the public domain, and therefore does not require a copyright notice. - * To the extent possible under law, the authors have waived all copyright and - * related or neighboring rights to this file. - * - * This file does not currently compile, because it is missing certain - * parts, like allocating memory to hold an image. You will have to - * supply these parts to get it to compile. For an example of a minimal - * working PNG reader/writer, see pngtest.c, included in this distribution; - * see also the programs in the contrib directory. - */ - -#define _POSIX_SOURCE 1 /* libpng and zlib are POSIX-compliant. You may - * change this if your application uses non-POSIX - * extensions. */ - -#include "png.h" - - /* The png_jmpbuf() macro, used in error handling, became available in - * libpng version 1.0.6. If you want to be able to run your code with older - * versions of libpng, you must define the macro yourself (but only if it - * is not already defined by libpng!). - */ - -#ifndef png_jmpbuf -# define png_jmpbuf(png_ptr) ((png_ptr)->png_jmpbuf) -#endif - -/* Check to see if a file is a PNG file using png_sig_cmp(). png_sig_cmp() - * returns zero if the image is a PNG and nonzero if it isn't a PNG. - * - * The function check_if_png() shown here, but not used, returns nonzero (true) - * if the file can be opened and is a PNG, 0 (false) otherwise. - * - * If this call is successful, and you are going to keep the file open, - * you should call png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK); once - * you have created the png_ptr, so that libpng knows your application - * has read that many bytes from the start of the file. Make sure you - * don't call png_set_sig_bytes() with more than 8 bytes read or give it - * an incorrect number of bytes read, or you will either have read too - * many bytes (your fault), or you are telling libpng to read the wrong - * number of magic bytes (also your fault). - * - * Many applications already read the first 2 or 4 bytes from the start - * of the image to determine the file type, so it would be easiest just - * to pass the bytes to png_sig_cmp() or even skip that if you know - * you have a PNG file, and call png_set_sig_bytes(). - */ -#define PNG_BYTES_TO_CHECK 4 -int check_if_png(char *file_name, FILE **fp) -{ - char buf[PNG_BYTES_TO_CHECK]; - - /* Open the prospective PNG file. */ - if ((*fp = fopen(file_name, "rb")) == NULL) - return 0; - - /* Read in some of the signature bytes */ - if (fread(buf, 1, PNG_BYTES_TO_CHECK, *fp) != PNG_BYTES_TO_CHECK) - return 0; - - /* Compare the first PNG_BYTES_TO_CHECK bytes of the signature. - Return nonzero (true) if they match */ - - return(!png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK)); -} - -/* Read a PNG file. You may want to return an error code if the read - * fails (depending upon the failure). There are two "prototypes" given - * here - one where we are given the filename, and we need to open the - * file, and the other where we are given an open file (possibly with - * some or all of the magic bytes read - see comments above). - */ -#ifdef open_file /* prototype 1 */ -void read_png(char *file_name) /* We need to open the file */ -{ - png_structp png_ptr; - png_infop info_ptr; - unsigned int sig_read = 0; - png_uint_32 width, height; - int bit_depth, color_type, interlace_type; - FILE *fp; - - if ((fp = fopen(file_name, "rb")) == NULL) - return (ERROR); - -#else no_open_file /* prototype 2 */ -void read_png(FILE *fp, unsigned int sig_read) /* File is already open */ -{ - png_structp png_ptr; - png_infop info_ptr; - png_uint_32 width, height; - int bit_depth, color_type, interlace_type; -#endif no_open_file /* Only use one prototype! */ - - /* Create and initialize the png_struct with the desired error handler - * functions. If you want to use the default stderr and longjump method, - * you can supply NULL for the last three parameters. We also supply the - * the compiler header file version, so that we know if the application - * was compiled with a compatible version of the library. REQUIRED - */ - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, - png_voidp user_error_ptr, user_error_fn, user_warning_fn); - - if (png_ptr == NULL) - { - fclose(fp); - return (ERROR); - } - - /* Allocate/initialize the memory for image information. REQUIRED. */ - info_ptr = png_create_info_struct(png_ptr); - if (info_ptr == NULL) - { - fclose(fp); - png_destroy_read_struct(&png_ptr, NULL, NULL); - return (ERROR); - } - - /* Set error handling if you are using the setjmp/longjmp method (this is - * the normal method of doing things with libpng). REQUIRED unless you - * set up your own error handlers in the png_create_read_struct() earlier. - */ - - if (setjmp(png_jmpbuf(png_ptr))) - { - /* Free all of the memory associated with the png_ptr and info_ptr */ - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - fclose(fp); - /* If we get here, we had a problem reading the file */ - return (ERROR); - } - - /* One of the following I/O initialization methods is REQUIRED */ -#ifdef streams /* PNG file I/O method 1 */ - /* Set up the input control if you are using standard C streams */ - png_init_io(png_ptr, fp); - -#else no_streams /* PNG file I/O method 2 */ - /* If you are using replacement read functions, instead of calling - * png_init_io() here you would call: - */ - png_set_read_fn(png_ptr, (void *)user_io_ptr, user_read_fn); - /* where user_io_ptr is a structure you want available to the callbacks */ -#endif no_streams /* Use only one I/O method! */ - - /* If we have already read some of the signature */ - png_set_sig_bytes(png_ptr, sig_read); - -#ifdef hilevel - /* - * If you have enough memory to read in the entire image at once, - * and you need to specify only transforms that can be controlled - * with one of the PNG_TRANSFORM_* bits (this presently excludes - * quantizing, filling, setting background, and doing gamma - * adjustment), then you can read the entire image (including - * pixels) into the info structure with this call: - */ - png_read_png(png_ptr, info_ptr, png_transforms, NULL); - -#else - /* OK, you're doing it the hard way, with the lower-level functions */ - - /* The call to png_read_info() gives us all of the information from the - * PNG file before the first IDAT (image data chunk). REQUIRED - */ - png_read_info(png_ptr, info_ptr); - - png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, - &interlace_type, NULL, NULL); - - /* Set up the data transformations you want. Note that these are all - * optional. Only call them if you want/need them. Many of the - * transformations only work on specific types of images, and many - * are mutually exclusive. - */ - - /* Tell libpng to strip 16 bit/color files down to 8 bits/color. - * Use accurate scaling if it's available, otherwise just chop off the - * low byte. - */ -#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED - png_set_scale_16(png_ptr); -#else - png_set_strip_16(png_ptr); -#endif - - /* Strip alpha bytes from the input data without combining with the - * background (not recommended). - */ - png_set_strip_alpha(png_ptr); - - /* Extract multiple pixels with bit depths of 1, 2, and 4 from a single - * byte into separate bytes (useful for paletted and grayscale images). - */ - png_set_packing(png_ptr); - - /* Change the order of packed pixels to least significant bit first - * (not useful if you are using png_set_packing). */ - png_set_packswap(png_ptr); - - /* Expand paletted colors into true RGB triplets */ - if (color_type == PNG_COLOR_TYPE_PALETTE) - png_set_palette_to_rgb(png_ptr); - - /* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */ - if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) - png_set_expand_gray_1_2_4_to_8(png_ptr); - - /* Expand paletted or RGB images with transparency to full alpha channels - * so the data will be available as RGBA quartets. - */ - if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) - png_set_tRNS_to_alpha(png_ptr); - - /* Set the background color to draw transparent and alpha images over. - * It is possible to set the red, green, and blue components directly - * for paletted images instead of supplying a palette index. Note that - * even if the PNG file supplies a background, you are not required to - * use it - you should use the (solid) application background if it has one. - */ - - png_color_16 my_background, *image_background; - - if (png_get_bKGD(png_ptr, info_ptr, &image_background)) - png_set_background(png_ptr, image_background, - PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); - else - png_set_background(png_ptr, &my_background, - PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); - - /* Some suggestions as to how to get a screen gamma value - * - * Note that screen gamma is the display_exponent, which includes - * the CRT_exponent and any correction for viewing conditions - */ - if (/* We have a user-defined screen gamma value */) - { - screen_gamma = user-defined screen_gamma; - } - /* This is one way that applications share the same screen gamma value */ - else if ((gamma_str = getenv("SCREEN_GAMMA")) != NULL) - { - screen_gamma = atof(gamma_str); - } - /* If we don't have another value */ - else - { - screen_gamma = 2.2; /* A good guess for a PC monitor in a dimly - lit room */ - screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */ - } - - /* Tell libpng to handle the gamma conversion for you. The final call - * is a good guess for PC generated images, but it should be configurable - * by the user at run time by the user. It is strongly suggested that - * your application support gamma correction. - */ - - int intent; - - if (png_get_sRGB(png_ptr, info_ptr, &intent)) - png_set_gamma(png_ptr, screen_gamma, 0.45455); - else - { - double image_gamma; - if (png_get_gAMA(png_ptr, info_ptr, &image_gamma)) - png_set_gamma(png_ptr, screen_gamma, image_gamma); - else - png_set_gamma(png_ptr, screen_gamma, 0.45455); - } - -#ifdef PNG_READ_QUANTIZE_SUPPORTED - /* Quantize RGB files down to 8 bit palette or reduce palettes - * to the number of colors available on your screen. - */ - if (color_type & PNG_COLOR_MASK_COLOR) - { - int num_palette; - png_colorp palette; - - /* This reduces the image to the application supplied palette */ - if (/* We have our own palette */) - { - /* An array of colors to which the image should be quantized */ - png_color std_color_cube[MAX_SCREEN_COLORS]; - - png_set_quantize(png_ptr, std_color_cube, MAX_SCREEN_COLORS, - MAX_SCREEN_COLORS, NULL, 0); - } - /* This reduces the image to the palette supplied in the file */ - else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)) - { - png_uint_16p histogram = NULL; - - png_get_hIST(png_ptr, info_ptr, &histogram); - - png_set_quantize(png_ptr, palette, num_palette, - max_screen_colors, histogram, 0); - } - } -#endif /* PNG_READ_QUANTIZE_SUPPORTED */ - - /* Invert monochrome files to have 0 as white and 1 as black */ - png_set_invert_mono(png_ptr); - - /* If you want to shift the pixel values from the range [0,255] or - * [0,65535] to the original [0,7] or [0,31], or whatever range the - * colors were originally in: - */ - if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) - { - png_color_8p sig_bit_p; - - png_get_sBIT(png_ptr, info_ptr, &sig_bit_p); - png_set_shift(png_ptr, sig_bit_p); - } - - /* Flip the RGB pixels to BGR (or RGBA to BGRA) */ - if (color_type & PNG_COLOR_MASK_COLOR) - png_set_bgr(png_ptr); - - /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */ - png_set_swap_alpha(png_ptr); - - /* Swap bytes of 16 bit files to least significant byte first */ - png_set_swap(png_ptr); - - /* Add filler (or alpha) byte (before/after each RGB triplet) */ - png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); - -#ifdef PNG_READ_INTERLACING_SUPPORTED - /* Turn on interlace handling. REQUIRED if you are not using - * png_read_image(). To see how to handle interlacing passes, - * see the png_read_row() method below: - */ - number_passes = png_set_interlace_handling(png_ptr); -#else - number_passes = 1; -#endif /* PNG_READ_INTERLACING_SUPPORTED */ - - - /* Optional call to gamma correct and add the background to the palette - * and update info structure. REQUIRED if you are expecting libpng to - * update the palette for you (ie you selected such a transform above). - */ - png_read_update_info(png_ptr, info_ptr); - - /* Allocate the memory to hold the image using the fields of info_ptr. */ - - /* The easiest way to read the image: */ - png_bytep row_pointers[height]; - - /* Clear the pointer array */ - for (row = 0; row < height; row++) - row_pointers[row] = NULL; - - for (row = 0; row < height; row++) - row_pointers[row] = png_malloc(png_ptr, png_get_rowbytes(png_ptr, - info_ptr)); - - /* Now it's time to read the image. One of these methods is REQUIRED */ -#ifdef entire /* Read the entire image in one go */ - png_read_image(png_ptr, row_pointers); - -#else no_entire /* Read the image one or more scanlines at a time */ - /* The other way to read images - deal with interlacing: */ - - for (pass = 0; pass < number_passes; pass++) - { -#ifdef single /* Read the image a single row at a time */ - for (y = 0; y < height; y++) - { - png_read_rows(png_ptr, &row_pointers[y], NULL, 1); - } - -#else no_single /* Read the image several rows at a time */ - for (y = 0; y < height; y += number_of_rows) - { -#ifdef sparkle /* Read the image using the "sparkle" effect. */ - png_read_rows(png_ptr, &row_pointers[y], NULL, - number_of_rows); -#else no_sparkle /* Read the image using the "rectangle" effect */ - png_read_rows(png_ptr, NULL, &row_pointers[y], - number_of_rows); -#endif no_sparkle /* Use only one of these two methods */ - } - - /* If you want to display the image after every pass, do so here */ -#endif no_single /* Use only one of these two methods */ - } -#endif no_entire /* Use only one of these two methods */ - - /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */ - png_read_end(png_ptr, info_ptr); -#endif hilevel - - /* At this point you have read the entire image */ - - /* Clean up after the read, and free any memory allocated - REQUIRED */ - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - - /* Close the file */ - fclose(fp); - - /* That's it */ - return (OK); -} - -/* Progressively read a file */ - -int -initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr) -{ - /* Create and initialize the png_struct with the desired error handler - * functions. If you want to use the default stderr and longjump method, - * you can supply NULL for the last three parameters. We also check that - * the library version is compatible in case we are using dynamically - * linked libraries. - */ - *png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, - png_voidp user_error_ptr, user_error_fn, user_warning_fn); - - if (*png_ptr == NULL) - { - *info_ptr = NULL; - return (ERROR); - } - - *info_ptr = png_create_info_struct(png_ptr); - - if (*info_ptr == NULL) - { - png_destroy_read_struct(png_ptr, info_ptr, NULL); - return (ERROR); - } - - if (setjmp(png_jmpbuf((*png_ptr)))) - { - png_destroy_read_struct(png_ptr, info_ptr, NULL); - return (ERROR); - } - - /* This one's new. You will need to provide all three - * function callbacks, even if you aren't using them all. - * If you aren't using all functions, you can specify NULL - * parameters. Even when all three functions are NULL, - * you need to call png_set_progressive_read_fn(). - * These functions shouldn't be dependent on global or - * static variables if you are decoding several images - * simultaneously. You should store stream specific data - * in a separate struct, given as the second parameter, - * and retrieve the pointer from inside the callbacks using - * the function png_get_progressive_ptr(png_ptr). - */ - png_set_progressive_read_fn(*png_ptr, (void *)stream_data, - info_callback, row_callback, end_callback); - - return (OK); -} - -int -process_data(png_structp *png_ptr, png_infop *info_ptr, - png_bytep buffer, png_uint_32 length) -{ - if (setjmp(png_jmpbuf((*png_ptr)))) - { - /* Free the png_ptr and info_ptr memory on error */ - png_destroy_read_struct(png_ptr, info_ptr, NULL); - return (ERROR); - } - - /* This one's new also. Simply give it chunks of data as - * they arrive from the data stream (in order, of course). - * On segmented machines, don't give it any more than 64K. - * The library seems to run fine with sizes of 4K, although - * you can give it much less if necessary (I assume you can - * give it chunks of 1 byte, but I haven't tried with less - * than 256 bytes yet). When this function returns, you may - * want to display any rows that were generated in the row - * callback, if you aren't already displaying them there. - */ - png_process_data(*png_ptr, *info_ptr, buffer, length); - return (OK); -} - -info_callback(png_structp png_ptr, png_infop info) -{ - /* Do any setup here, including setting any of the transformations - * mentioned in the Reading PNG files section. For now, you _must_ - * call either png_start_read_image() or png_read_update_info() - * after all the transformations are set (even if you don't set - * any). You may start getting rows before png_process_data() - * returns, so this is your last chance to prepare for that. - */ -} - -row_callback(png_structp png_ptr, png_bytep new_row, - png_uint_32 row_num, int pass) -{ - /* - * This function is called for every row in the image. If the - * image is interlaced, and you turned on the interlace handler, - * this function will be called for every row in every pass. - * - * In this function you will receive a pointer to new row data from - * libpng called new_row that is to replace a corresponding row (of - * the same data format) in a buffer allocated by your application. - * - * The new row data pointer "new_row" may be NULL, indicating there is - * no new data to be replaced (in cases of interlace loading). - * - * If new_row is not NULL then you need to call - * png_progressive_combine_row() to replace the corresponding row as - * shown below: - */ - - /* Get pointer to corresponding row in our - * PNG read buffer. - */ - png_bytep old_row = ((png_bytep *)our_data)[row_num]; - -#ifdef PNG_READ_INTERLACING_SUPPORTED - /* If both rows are allocated then copy the new row - * data to the corresponding row data. - */ - if ((old_row != NULL) && (new_row != NULL)) - png_progressive_combine_row(png_ptr, old_row, new_row); - - /* - * The rows and passes are called in order, so you don't really - * need the row_num and pass, but I'm supplying them because it - * may make your life easier. - * - * For the non-NULL rows of interlaced images, you must call - * png_progressive_combine_row() passing in the new row and the - * old row, as demonstrated above. You can call this function for - * NULL rows (it will just return) and for non-interlaced images - * (it just does the png_memcpy for you) if it will make the code - * easier. Thus, you can just do this for all cases: - */ - - png_progressive_combine_row(png_ptr, old_row, new_row); - - /* where old_row is what was displayed for previous rows. Note - * that the first pass (pass == 0 really) will completely cover - * the old row, so the rows do not have to be initialized. After - * the first pass (and only for interlaced images), you will have - * to pass the current row as new_row, and the function will combine - * the old row and the new row. - */ -#endif /* PNG_READ_INTERLACING_SUPPORTED */ -} - -end_callback(png_structp png_ptr, png_infop info) -{ - /* This function is called when the whole image has been read, - * including any chunks after the image (up to and including - * the IEND). You will usually have the same info chunk as you - * had in the header, although some data may have been added - * to the comments and time fields. - * - * Most people won't do much here, perhaps setting a flag that - * marks the image as finished. - */ -} - -/* Write a png file */ -void write_png(char *file_name /* , ... other image information ... */) -{ - FILE *fp; - png_structp png_ptr; - png_infop info_ptr; - png_colorp palette; - - /* Open the file */ - fp = fopen(file_name, "wb"); - if (fp == NULL) - return (ERROR); - - /* Create and initialize the png_struct with the desired error handler - * functions. If you want to use the default stderr and longjump method, - * you can supply NULL for the last three parameters. We also check that - * the library version is compatible with the one used at compile time, - * in case we are using dynamically linked libraries. REQUIRED. - */ - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, - png_voidp user_error_ptr, user_error_fn, user_warning_fn); - - if (png_ptr == NULL) - { - fclose(fp); - return (ERROR); - } - - /* Allocate/initialize the image information data. REQUIRED */ - info_ptr = png_create_info_struct(png_ptr); - if (info_ptr == NULL) - { - fclose(fp); - png_destroy_write_struct(&png_ptr, NULL); - return (ERROR); - } - - /* Set error handling. REQUIRED if you aren't supplying your own - * error handling functions in the png_create_write_struct() call. - */ - if (setjmp(png_jmpbuf(png_ptr))) - { - /* If we get here, we had a problem writing the file */ - fclose(fp); - png_destroy_write_struct(&png_ptr, &info_ptr); - return (ERROR); - } - - /* One of the following I/O initialization functions is REQUIRED */ - -#ifdef streams /* I/O initialization method 1 */ - /* Set up the output control if you are using standard C streams */ - png_init_io(png_ptr, fp); - -#else no_streams /* I/O initialization method 2 */ - /* If you are using replacement write functions, instead of calling - * png_init_io() here you would call - */ - png_set_write_fn(png_ptr, (void *)user_io_ptr, user_write_fn, - user_IO_flush_function); - /* where user_io_ptr is a structure you want available to the callbacks */ -#endif no_streams /* Only use one initialization method */ - -#ifdef hilevel - /* This is the easy way. Use it if you already have all the - * image info living in the structure. You could "|" many - * PNG_TRANSFORM flags into the png_transforms integer here. - */ - png_write_png(png_ptr, info_ptr, png_transforms, NULL); - -#else - /* This is the hard way */ - - /* Set the image information here. Width and height are up to 2^31, - * bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on - * the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY, - * PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB, - * or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or - * PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST - * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED - */ - png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, PNG_COLOR_TYPE_???, - PNG_INTERLACE_????, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - - /* Set the palette if there is one. REQUIRED for indexed-color images */ - palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH - * png_sizeof(png_color)); - /* ... Set palette colors ... */ - png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH); - /* You must not free palette here, because png_set_PLTE only makes a link to - * the palette that you malloced. Wait until you are about to destroy - * the png structure. - */ - - /* Optional significant bit (sBIT) chunk */ - png_color_8 sig_bit; - - /* If we are dealing with a grayscale image then */ - sig_bit.gray = true_bit_depth; - - /* Otherwise, if we are dealing with a color image then */ - sig_bit.red = true_red_bit_depth; - sig_bit.green = true_green_bit_depth; - sig_bit.blue = true_blue_bit_depth; - - /* If the image has an alpha channel then */ - sig_bit.alpha = true_alpha_bit_depth; - - png_set_sBIT(png_ptr, info_ptr, &sig_bit); - - - /* Optional gamma chunk is strongly suggested if you have any guess - * as to the correct gamma of the image. - */ - png_set_gAMA(png_ptr, info_ptr, gamma); - - /* Optionally write comments into the image */ - { - png_text text_ptr[3]; - - char key0[]="Title"; - char text0[]="Mona Lisa"; - text_ptr[0].key = key0; - text_ptr[0].text = text0; - text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE; - text_ptr[0].itxt_length = 0; - text_ptr[0].lang = NULL; - text_ptr[0].lang_key = NULL; - - char key1[]="Author"; - char text1[]="Leonardo DaVinci"; - text_ptr[1].key = key1; - text_ptr[1].text = text1; - text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE; - text_ptr[1].itxt_length = 0; - text_ptr[1].lang = NULL; - text_ptr[1].lang_key = NULL; - - char key2[]="Description"; - char text2[]=""; - text_ptr[2].key = key2; - text_ptr[2].text = text2; - text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt; - text_ptr[2].itxt_length = 0; - text_ptr[2].lang = NULL; - text_ptr[2].lang_key = NULL; - - png_set_text(write_ptr, write_info_ptr, text_ptr, 3); - } - - /* Other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs */ - - /* Note that if sRGB is present the gAMA and cHRM chunks must be ignored - * on read and, if your application chooses to write them, they must - * be written in accordance with the sRGB profile - */ - - /* Write the file header information. REQUIRED */ - png_write_info(png_ptr, info_ptr); - - /* If you want, you can write the info in two steps, in case you need to - * write your private chunk ahead of PLTE: - * - * png_write_info_before_PLTE(write_ptr, write_info_ptr); - * write_my_chunk(); - * png_write_info(png_ptr, info_ptr); - * - * However, given the level of known- and unknown-chunk support in 1.2.0 - * and up, this should no longer be necessary. - */ - - /* Once we write out the header, the compression type on the text - * chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or - * PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again - * at the end. - */ - - /* Set up the transformations you want. Note that these are - * all optional. Only call them if you want them. - */ - - /* Invert monochrome pixels */ - png_set_invert_mono(png_ptr); - - /* Shift the pixels up to a legal bit depth and fill in - * as appropriate to correctly scale the image. - */ - png_set_shift(png_ptr, &sig_bit); - - /* Pack pixels into bytes */ - png_set_packing(png_ptr); - - /* Swap location of alpha bytes from ARGB to RGBA */ - png_set_swap_alpha(png_ptr); - - /* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into - * RGB (4 channels -> 3 channels). The second parameter is not used. - */ - png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); - - /* Flip BGR pixels to RGB */ - png_set_bgr(png_ptr); - - /* Swap bytes of 16-bit files to most significant byte first */ - png_set_swap(png_ptr); - - /* Swap bits of 1, 2, 4 bit packed pixel formats */ - png_set_packswap(png_ptr); - - /* Turn on interlace handling if you are not using png_write_image() */ - if (interlacing) - number_passes = png_set_interlace_handling(png_ptr); - - else - number_passes = 1; - - /* The easiest way to write the image (you may have a different memory - * layout, however, so choose what fits your needs best). You need to - * use the first method if you aren't handling interlacing yourself. - */ - png_uint_32 k, height, width; - - /* In this example, "image" is a one-dimensional array of bytes */ - png_byte image[height*width*bytes_per_pixel]; - - png_bytep row_pointers[height]; - - if (height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) - png_error (png_ptr, "Image is too tall to process in memory"); - - /* Set up pointers into your "image" byte array */ - for (k = 0; k < height; k++) - row_pointers[k] = image + k*width*bytes_per_pixel; - - /* One of the following output methods is REQUIRED */ - -#ifdef entire /* Write out the entire image data in one call */ - png_write_image(png_ptr, row_pointers); - - /* The other way to write the image - deal with interlacing */ - -#else no_entire /* Write out the image data by one or more scanlines */ - - /* The number of passes is either 1 for non-interlaced images, - * or 7 for interlaced images. - */ - for (pass = 0; pass < number_passes; pass++) - { - /* Write a few rows at a time. */ - png_write_rows(png_ptr, &row_pointers[first_row], number_of_rows); - - /* If you are only writing one row at a time, this works */ - for (y = 0; y < height; y++) - png_write_rows(png_ptr, &row_pointers[y], 1); - } -#endif no_entire /* Use only one output method */ - - /* You can write optional chunks like tEXt, zTXt, and tIME at the end - * as well. Shouldn't be necessary in 1.2.0 and up as all the public - * chunks are supported and you can use png_set_unknown_chunks() to - * register unknown chunks into the info structure to be written out. - */ - - /* It is REQUIRED to call this to finish writing the rest of the file */ - png_write_end(png_ptr, info_ptr); -#endif hilevel - - /* If you png_malloced a palette, free it here (don't free info_ptr->palette, - * as recommended in versions 1.0.5m and earlier of this example; if - * libpng mallocs info_ptr->palette, libpng will free it). If you - * allocated it with malloc() instead of png_malloc(), use free() instead - * of png_free(). - */ - png_free(png_ptr, palette); - palette = NULL; - - /* Similarly, if you png_malloced any data that you passed in with - * png_set_something(), such as a hist or trans array, free it here, - * when you can be sure that libpng is through with it. - */ - png_free(png_ptr, trans); - trans = NULL; - /* Whenever you use png_free() it is a good idea to set the pointer to - * NULL in case your application inadvertently tries to png_free() it - * again. When png_free() sees a NULL it returns without action, thus - * avoiding the double-free security problem. - */ - - /* Clean up after the write, and free any memory allocated */ - png_destroy_write_struct(&png_ptr, &info_ptr); - - /* Close the file */ - fclose(fp); - - /* That's it */ - return (OK); -} - -#endif /* if 0 */ + +#if 0 /* in case someone actually tries to compile this */ + +/* example.c - an example of using libpng + * Last changed in libpng 1.5.10 [March 8, 2012] + * Maintained 1998-2012 Glenn Randers-Pehrson + * Maintained 1996, 1997 Andreas Dilger + * Written 1995, 1996 Guy Eric Schalnat, Group 42, Inc. + */ + +/* This is an example of how to use libpng to read and write PNG files. + * The file libpng-manual.txt is much more verbose then this. If you have not + * read it, do so first. This was designed to be a starting point of an + * implementation. This is not officially part of libpng, is hereby placed + * in the public domain, and therefore does not require a copyright notice. + * To the extent possible under law, the authors have waived all copyright and + * related or neighboring rights to this file. + * + * This file does not currently compile, because it is missing certain + * parts, like allocating memory to hold an image. You will have to + * supply these parts to get it to compile. For an example of a minimal + * working PNG reader/writer, see pngtest.c, included in this distribution; + * see also the programs in the contrib directory. + */ + +#define _POSIX_SOURCE 1 /* libpng and zlib are POSIX-compliant. You may + * change this if your application uses non-POSIX + * extensions. */ + +#include "png.h" + + /* The png_jmpbuf() macro, used in error handling, became available in + * libpng version 1.0.6. If you want to be able to run your code with older + * versions of libpng, you must define the macro yourself (but only if it + * is not already defined by libpng!). + */ + +#ifndef png_jmpbuf +# define png_jmpbuf(png_ptr) ((png_ptr)->png_jmpbuf) +#endif + +/* Check to see if a file is a PNG file using png_sig_cmp(). png_sig_cmp() + * returns zero if the image is a PNG and nonzero if it isn't a PNG. + * + * The function check_if_png() shown here, but not used, returns nonzero (true) + * if the file can be opened and is a PNG, 0 (false) otherwise. + * + * If this call is successful, and you are going to keep the file open, + * you should call png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK); once + * you have created the png_ptr, so that libpng knows your application + * has read that many bytes from the start of the file. Make sure you + * don't call png_set_sig_bytes() with more than 8 bytes read or give it + * an incorrect number of bytes read, or you will either have read too + * many bytes (your fault), or you are telling libpng to read the wrong + * number of magic bytes (also your fault). + * + * Many applications already read the first 2 or 4 bytes from the start + * of the image to determine the file type, so it would be easiest just + * to pass the bytes to png_sig_cmp() or even skip that if you know + * you have a PNG file, and call png_set_sig_bytes(). + */ +#define PNG_BYTES_TO_CHECK 4 +int check_if_png(char *file_name, FILE **fp) +{ + char buf[PNG_BYTES_TO_CHECK]; + + /* Open the prospective PNG file. */ + if ((*fp = fopen(file_name, "rb")) == NULL) + return 0; + + /* Read in some of the signature bytes */ + if (fread(buf, 1, PNG_BYTES_TO_CHECK, *fp) != PNG_BYTES_TO_CHECK) + return 0; + + /* Compare the first PNG_BYTES_TO_CHECK bytes of the signature. + Return nonzero (true) if they match */ + + return(!png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK)); +} + +/* Read a PNG file. You may want to return an error code if the read + * fails (depending upon the failure). There are two "prototypes" given + * here - one where we are given the filename, and we need to open the + * file, and the other where we are given an open file (possibly with + * some or all of the magic bytes read - see comments above). + */ +#ifdef open_file /* prototype 1 */ +void read_png(char *file_name) /* We need to open the file */ +{ + png_structp png_ptr; + png_infop info_ptr; + unsigned int sig_read = 0; + png_uint_32 width, height; + int bit_depth, color_type, interlace_type; + FILE *fp; + + if ((fp = fopen(file_name, "rb")) == NULL) + return (ERROR); + +#else no_open_file /* prototype 2 */ +void read_png(FILE *fp, unsigned int sig_read) /* File is already open */ +{ + png_structp png_ptr; + png_infop info_ptr; + png_uint_32 width, height; + int bit_depth, color_type, interlace_type; +#endif no_open_file /* Only use one prototype! */ + + /* Create and initialize the png_struct with the desired error handler + * functions. If you want to use the default stderr and longjump method, + * you can supply NULL for the last three parameters. We also supply the + * the compiler header file version, so that we know if the application + * was compiled with a compatible version of the library. REQUIRED + */ + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, + png_voidp user_error_ptr, user_error_fn, user_warning_fn); + + if (png_ptr == NULL) + { + fclose(fp); + return (ERROR); + } + + /* Allocate/initialize the memory for image information. REQUIRED. */ + info_ptr = png_create_info_struct(png_ptr); + if (info_ptr == NULL) + { + fclose(fp); + png_destroy_read_struct(&png_ptr, NULL, NULL); + return (ERROR); + } + + /* Set error handling if you are using the setjmp/longjmp method (this is + * the normal method of doing things with libpng). REQUIRED unless you + * set up your own error handlers in the png_create_read_struct() earlier. + */ + + if (setjmp(png_jmpbuf(png_ptr))) + { + /* Free all of the memory associated with the png_ptr and info_ptr */ + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + fclose(fp); + /* If we get here, we had a problem reading the file */ + return (ERROR); + } + + /* One of the following I/O initialization methods is REQUIRED */ +#ifdef streams /* PNG file I/O method 1 */ + /* Set up the input control if you are using standard C streams */ + png_init_io(png_ptr, fp); + +#else no_streams /* PNG file I/O method 2 */ + /* If you are using replacement read functions, instead of calling + * png_init_io() here you would call: + */ + png_set_read_fn(png_ptr, (void *)user_io_ptr, user_read_fn); + /* where user_io_ptr is a structure you want available to the callbacks */ +#endif no_streams /* Use only one I/O method! */ + + /* If we have already read some of the signature */ + png_set_sig_bytes(png_ptr, sig_read); + +#ifdef hilevel + /* + * If you have enough memory to read in the entire image at once, + * and you need to specify only transforms that can be controlled + * with one of the PNG_TRANSFORM_* bits (this presently excludes + * quantizing, filling, setting background, and doing gamma + * adjustment), then you can read the entire image (including + * pixels) into the info structure with this call: + */ + png_read_png(png_ptr, info_ptr, png_transforms, NULL); + +#else + /* OK, you're doing it the hard way, with the lower-level functions */ + + /* The call to png_read_info() gives us all of the information from the + * PNG file before the first IDAT (image data chunk). REQUIRED + */ + png_read_info(png_ptr, info_ptr); + + png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, + &interlace_type, NULL, NULL); + + /* Set up the data transformations you want. Note that these are all + * optional. Only call them if you want/need them. Many of the + * transformations only work on specific types of images, and many + * are mutually exclusive. + */ + + /* Tell libpng to strip 16 bit/color files down to 8 bits/color. + * Use accurate scaling if it's available, otherwise just chop off the + * low byte. + */ +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED + png_set_scale_16(png_ptr); +#else + png_set_strip_16(png_ptr); +#endif + + /* Strip alpha bytes from the input data without combining with the + * background (not recommended). + */ + png_set_strip_alpha(png_ptr); + + /* Extract multiple pixels with bit depths of 1, 2, and 4 from a single + * byte into separate bytes (useful for paletted and grayscale images). + */ + png_set_packing(png_ptr); + + /* Change the order of packed pixels to least significant bit first + * (not useful if you are using png_set_packing). */ + png_set_packswap(png_ptr); + + /* Expand paletted colors into true RGB triplets */ + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_palette_to_rgb(png_ptr); + + /* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */ + if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) + png_set_expand_gray_1_2_4_to_8(png_ptr); + + /* Expand paletted or RGB images with transparency to full alpha channels + * so the data will be available as RGBA quartets. + */ + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) + png_set_tRNS_to_alpha(png_ptr); + + /* Set the background color to draw transparent and alpha images over. + * It is possible to set the red, green, and blue components directly + * for paletted images instead of supplying a palette index. Note that + * even if the PNG file supplies a background, you are not required to + * use it - you should use the (solid) application background if it has one. + */ + + png_color_16 my_background, *image_background; + + if (png_get_bKGD(png_ptr, info_ptr, &image_background)) + png_set_background(png_ptr, image_background, + PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); + else + png_set_background(png_ptr, &my_background, + PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); + + /* Some suggestions as to how to get a screen gamma value + * + * Note that screen gamma is the display_exponent, which includes + * the CRT_exponent and any correction for viewing conditions + */ + if (/* We have a user-defined screen gamma value */) + { + screen_gamma = user-defined screen_gamma; + } + /* This is one way that applications share the same screen gamma value */ + else if ((gamma_str = getenv("SCREEN_GAMMA")) != NULL) + { + screen_gamma = atof(gamma_str); + } + /* If we don't have another value */ + else + { + screen_gamma = 2.2; /* A good guess for a PC monitor in a dimly + lit room */ + screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */ + } + + /* Tell libpng to handle the gamma conversion for you. The final call + * is a good guess for PC generated images, but it should be configurable + * by the user at run time by the user. It is strongly suggested that + * your application support gamma correction. + */ + + int intent; + + if (png_get_sRGB(png_ptr, info_ptr, &intent)) + png_set_gamma(png_ptr, screen_gamma, 0.45455); + else + { + double image_gamma; + if (png_get_gAMA(png_ptr, info_ptr, &image_gamma)) + png_set_gamma(png_ptr, screen_gamma, image_gamma); + else + png_set_gamma(png_ptr, screen_gamma, 0.45455); + } + +#ifdef PNG_READ_QUANTIZE_SUPPORTED + /* Quantize RGB files down to 8 bit palette or reduce palettes + * to the number of colors available on your screen. + */ + if (color_type & PNG_COLOR_MASK_COLOR) + { + int num_palette; + png_colorp palette; + + /* This reduces the image to the application supplied palette */ + if (/* We have our own palette */) + { + /* An array of colors to which the image should be quantized */ + png_color std_color_cube[MAX_SCREEN_COLORS]; + + png_set_quantize(png_ptr, std_color_cube, MAX_SCREEN_COLORS, + MAX_SCREEN_COLORS, NULL, 0); + } + /* This reduces the image to the palette supplied in the file */ + else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)) + { + png_uint_16p histogram = NULL; + + png_get_hIST(png_ptr, info_ptr, &histogram); + + png_set_quantize(png_ptr, palette, num_palette, + max_screen_colors, histogram, 0); + } + } +#endif /* PNG_READ_QUANTIZE_SUPPORTED */ + + /* Invert monochrome files to have 0 as white and 1 as black */ + png_set_invert_mono(png_ptr); + + /* If you want to shift the pixel values from the range [0,255] or + * [0,65535] to the original [0,7] or [0,31], or whatever range the + * colors were originally in: + */ + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) + { + png_color_8p sig_bit_p; + + png_get_sBIT(png_ptr, info_ptr, &sig_bit_p); + png_set_shift(png_ptr, sig_bit_p); + } + + /* Flip the RGB pixels to BGR (or RGBA to BGRA) */ + if (color_type & PNG_COLOR_MASK_COLOR) + png_set_bgr(png_ptr); + + /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */ + png_set_swap_alpha(png_ptr); + + /* Swap bytes of 16 bit files to least significant byte first */ + png_set_swap(png_ptr); + + /* Add filler (or alpha) byte (before/after each RGB triplet) */ + png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); + +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* Turn on interlace handling. REQUIRED if you are not using + * png_read_image(). To see how to handle interlacing passes, + * see the png_read_row() method below: + */ + number_passes = png_set_interlace_handling(png_ptr); +#else + number_passes = 1; +#endif /* PNG_READ_INTERLACING_SUPPORTED */ + + + /* Optional call to gamma correct and add the background to the palette + * and update info structure. REQUIRED if you are expecting libpng to + * update the palette for you (ie you selected such a transform above). + */ + png_read_update_info(png_ptr, info_ptr); + + /* Allocate the memory to hold the image using the fields of info_ptr. */ + + /* The easiest way to read the image: */ + png_bytep row_pointers[height]; + + /* Clear the pointer array */ + for (row = 0; row < height; row++) + row_pointers[row] = NULL; + + for (row = 0; row < height; row++) + row_pointers[row] = png_malloc(png_ptr, png_get_rowbytes(png_ptr, + info_ptr)); + + /* Now it's time to read the image. One of these methods is REQUIRED */ +#ifdef entire /* Read the entire image in one go */ + png_read_image(png_ptr, row_pointers); + +#else no_entire /* Read the image one or more scanlines at a time */ + /* The other way to read images - deal with interlacing: */ + + for (pass = 0; pass < number_passes; pass++) + { +#ifdef single /* Read the image a single row at a time */ + for (y = 0; y < height; y++) + { + png_read_rows(png_ptr, &row_pointers[y], NULL, 1); + } + +#else no_single /* Read the image several rows at a time */ + for (y = 0; y < height; y += number_of_rows) + { +#ifdef sparkle /* Read the image using the "sparkle" effect. */ + png_read_rows(png_ptr, &row_pointers[y], NULL, + number_of_rows); +#else no_sparkle /* Read the image using the "rectangle" effect */ + png_read_rows(png_ptr, NULL, &row_pointers[y], + number_of_rows); +#endif no_sparkle /* Use only one of these two methods */ + } + + /* If you want to display the image after every pass, do so here */ +#endif no_single /* Use only one of these two methods */ + } +#endif no_entire /* Use only one of these two methods */ + + /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */ + png_read_end(png_ptr, info_ptr); +#endif hilevel + + /* At this point you have read the entire image */ + + /* Clean up after the read, and free any memory allocated - REQUIRED */ + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + + /* Close the file */ + fclose(fp); + + /* That's it */ + return (OK); +} + +/* Progressively read a file */ + +int +initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr) +{ + /* Create and initialize the png_struct with the desired error handler + * functions. If you want to use the default stderr and longjump method, + * you can supply NULL for the last three parameters. We also check that + * the library version is compatible in case we are using dynamically + * linked libraries. + */ + *png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, + png_voidp user_error_ptr, user_error_fn, user_warning_fn); + + if (*png_ptr == NULL) + { + *info_ptr = NULL; + return (ERROR); + } + + *info_ptr = png_create_info_struct(png_ptr); + + if (*info_ptr == NULL) + { + png_destroy_read_struct(png_ptr, info_ptr, NULL); + return (ERROR); + } + + if (setjmp(png_jmpbuf((*png_ptr)))) + { + png_destroy_read_struct(png_ptr, info_ptr, NULL); + return (ERROR); + } + + /* This one's new. You will need to provide all three + * function callbacks, even if you aren't using them all. + * If you aren't using all functions, you can specify NULL + * parameters. Even when all three functions are NULL, + * you need to call png_set_progressive_read_fn(). + * These functions shouldn't be dependent on global or + * static variables if you are decoding several images + * simultaneously. You should store stream specific data + * in a separate struct, given as the second parameter, + * and retrieve the pointer from inside the callbacks using + * the function png_get_progressive_ptr(png_ptr). + */ + png_set_progressive_read_fn(*png_ptr, (void *)stream_data, + info_callback, row_callback, end_callback); + + return (OK); +} + +int +process_data(png_structp *png_ptr, png_infop *info_ptr, + png_bytep buffer, png_uint_32 length) +{ + if (setjmp(png_jmpbuf((*png_ptr)))) + { + /* Free the png_ptr and info_ptr memory on error */ + png_destroy_read_struct(png_ptr, info_ptr, NULL); + return (ERROR); + } + + /* This one's new also. Simply give it chunks of data as + * they arrive from the data stream (in order, of course). + * On segmented machines, don't give it any more than 64K. + * The library seems to run fine with sizes of 4K, although + * you can give it much less if necessary (I assume you can + * give it chunks of 1 byte, but I haven't tried with less + * than 256 bytes yet). When this function returns, you may + * want to display any rows that were generated in the row + * callback, if you aren't already displaying them there. + */ + png_process_data(*png_ptr, *info_ptr, buffer, length); + return (OK); +} + +info_callback(png_structp png_ptr, png_infop info) +{ + /* Do any setup here, including setting any of the transformations + * mentioned in the Reading PNG files section. For now, you _must_ + * call either png_start_read_image() or png_read_update_info() + * after all the transformations are set (even if you don't set + * any). You may start getting rows before png_process_data() + * returns, so this is your last chance to prepare for that. + */ +} + +row_callback(png_structp png_ptr, png_bytep new_row, + png_uint_32 row_num, int pass) +{ + /* + * This function is called for every row in the image. If the + * image is interlaced, and you turned on the interlace handler, + * this function will be called for every row in every pass. + * + * In this function you will receive a pointer to new row data from + * libpng called new_row that is to replace a corresponding row (of + * the same data format) in a buffer allocated by your application. + * + * The new row data pointer "new_row" may be NULL, indicating there is + * no new data to be replaced (in cases of interlace loading). + * + * If new_row is not NULL then you need to call + * png_progressive_combine_row() to replace the corresponding row as + * shown below: + */ + + /* Get pointer to corresponding row in our + * PNG read buffer. + */ + png_bytep old_row = ((png_bytep *)our_data)[row_num]; + +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* If both rows are allocated then copy the new row + * data to the corresponding row data. + */ + if ((old_row != NULL) && (new_row != NULL)) + png_progressive_combine_row(png_ptr, old_row, new_row); + + /* + * The rows and passes are called in order, so you don't really + * need the row_num and pass, but I'm supplying them because it + * may make your life easier. + * + * For the non-NULL rows of interlaced images, you must call + * png_progressive_combine_row() passing in the new row and the + * old row, as demonstrated above. You can call this function for + * NULL rows (it will just return) and for non-interlaced images + * (it just does the png_memcpy for you) if it will make the code + * easier. Thus, you can just do this for all cases: + */ + + png_progressive_combine_row(png_ptr, old_row, new_row); + + /* where old_row is what was displayed for previous rows. Note + * that the first pass (pass == 0 really) will completely cover + * the old row, so the rows do not have to be initialized. After + * the first pass (and only for interlaced images), you will have + * to pass the current row as new_row, and the function will combine + * the old row and the new row. + */ +#endif /* PNG_READ_INTERLACING_SUPPORTED */ +} + +end_callback(png_structp png_ptr, png_infop info) +{ + /* This function is called when the whole image has been read, + * including any chunks after the image (up to and including + * the IEND). You will usually have the same info chunk as you + * had in the header, although some data may have been added + * to the comments and time fields. + * + * Most people won't do much here, perhaps setting a flag that + * marks the image as finished. + */ +} + +/* Write a png file */ +void write_png(char *file_name /* , ... other image information ... */) +{ + FILE *fp; + png_structp png_ptr; + png_infop info_ptr; + png_colorp palette; + + /* Open the file */ + fp = fopen(file_name, "wb"); + if (fp == NULL) + return (ERROR); + + /* Create and initialize the png_struct with the desired error handler + * functions. If you want to use the default stderr and longjump method, + * you can supply NULL for the last three parameters. We also check that + * the library version is compatible with the one used at compile time, + * in case we are using dynamically linked libraries. REQUIRED. + */ + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, + png_voidp user_error_ptr, user_error_fn, user_warning_fn); + + if (png_ptr == NULL) + { + fclose(fp); + return (ERROR); + } + + /* Allocate/initialize the image information data. REQUIRED */ + info_ptr = png_create_info_struct(png_ptr); + if (info_ptr == NULL) + { + fclose(fp); + png_destroy_write_struct(&png_ptr, NULL); + return (ERROR); + } + + /* Set error handling. REQUIRED if you aren't supplying your own + * error handling functions in the png_create_write_struct() call. + */ + if (setjmp(png_jmpbuf(png_ptr))) + { + /* If we get here, we had a problem writing the file */ + fclose(fp); + png_destroy_write_struct(&png_ptr, &info_ptr); + return (ERROR); + } + + /* One of the following I/O initialization functions is REQUIRED */ + +#ifdef streams /* I/O initialization method 1 */ + /* Set up the output control if you are using standard C streams */ + png_init_io(png_ptr, fp); + +#else no_streams /* I/O initialization method 2 */ + /* If you are using replacement write functions, instead of calling + * png_init_io() here you would call + */ + png_set_write_fn(png_ptr, (void *)user_io_ptr, user_write_fn, + user_IO_flush_function); + /* where user_io_ptr is a structure you want available to the callbacks */ +#endif no_streams /* Only use one initialization method */ + +#ifdef hilevel + /* This is the easy way. Use it if you already have all the + * image info living in the structure. You could "|" many + * PNG_TRANSFORM flags into the png_transforms integer here. + */ + png_write_png(png_ptr, info_ptr, png_transforms, NULL); + +#else + /* This is the hard way */ + + /* Set the image information here. Width and height are up to 2^31, + * bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on + * the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY, + * PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB, + * or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or + * PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST + * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED + */ + png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, PNG_COLOR_TYPE_???, + PNG_INTERLACE_????, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + /* Set the palette if there is one. REQUIRED for indexed-color images */ + palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH + * png_sizeof(png_color)); + /* ... Set palette colors ... */ + png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH); + /* You must not free palette here, because png_set_PLTE only makes a link to + * the palette that you malloced. Wait until you are about to destroy + * the png structure. + */ + + /* Optional significant bit (sBIT) chunk */ + png_color_8 sig_bit; + + /* If we are dealing with a grayscale image then */ + sig_bit.gray = true_bit_depth; + + /* Otherwise, if we are dealing with a color image then */ + sig_bit.red = true_red_bit_depth; + sig_bit.green = true_green_bit_depth; + sig_bit.blue = true_blue_bit_depth; + + /* If the image has an alpha channel then */ + sig_bit.alpha = true_alpha_bit_depth; + + png_set_sBIT(png_ptr, info_ptr, &sig_bit); + + + /* Optional gamma chunk is strongly suggested if you have any guess + * as to the correct gamma of the image. + */ + png_set_gAMA(png_ptr, info_ptr, gamma); + + /* Optionally write comments into the image */ + { + png_text text_ptr[3]; + + char key0[]="Title"; + char text0[]="Mona Lisa"; + text_ptr[0].key = key0; + text_ptr[0].text = text0; + text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE; + text_ptr[0].itxt_length = 0; + text_ptr[0].lang = NULL; + text_ptr[0].lang_key = NULL; + + char key1[]="Author"; + char text1[]="Leonardo DaVinci"; + text_ptr[1].key = key1; + text_ptr[1].text = text1; + text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE; + text_ptr[1].itxt_length = 0; + text_ptr[1].lang = NULL; + text_ptr[1].lang_key = NULL; + + char key2[]="Description"; + char text2[]=""; + text_ptr[2].key = key2; + text_ptr[2].text = text2; + text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt; + text_ptr[2].itxt_length = 0; + text_ptr[2].lang = NULL; + text_ptr[2].lang_key = NULL; + + png_set_text(write_ptr, write_info_ptr, text_ptr, 3); + } + + /* Other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs */ + + /* Note that if sRGB is present the gAMA and cHRM chunks must be ignored + * on read and, if your application chooses to write them, they must + * be written in accordance with the sRGB profile + */ + + /* Write the file header information. REQUIRED */ + png_write_info(png_ptr, info_ptr); + + /* If you want, you can write the info in two steps, in case you need to + * write your private chunk ahead of PLTE: + * + * png_write_info_before_PLTE(write_ptr, write_info_ptr); + * write_my_chunk(); + * png_write_info(png_ptr, info_ptr); + * + * However, given the level of known- and unknown-chunk support in 1.2.0 + * and up, this should no longer be necessary. + */ + + /* Once we write out the header, the compression type on the text + * chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or + * PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again + * at the end. + */ + + /* Set up the transformations you want. Note that these are + * all optional. Only call them if you want them. + */ + + /* Invert monochrome pixels */ + png_set_invert_mono(png_ptr); + + /* Shift the pixels up to a legal bit depth and fill in + * as appropriate to correctly scale the image. + */ + png_set_shift(png_ptr, &sig_bit); + + /* Pack pixels into bytes */ + png_set_packing(png_ptr); + + /* Swap location of alpha bytes from ARGB to RGBA */ + png_set_swap_alpha(png_ptr); + + /* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into + * RGB (4 channels -> 3 channels). The second parameter is not used. + */ + png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); + + /* Flip BGR pixels to RGB */ + png_set_bgr(png_ptr); + + /* Swap bytes of 16-bit files to most significant byte first */ + png_set_swap(png_ptr); + + /* Swap bits of 1, 2, 4 bit packed pixel formats */ + png_set_packswap(png_ptr); + + /* Turn on interlace handling if you are not using png_write_image() */ + if (interlacing) + number_passes = png_set_interlace_handling(png_ptr); + + else + number_passes = 1; + + /* The easiest way to write the image (you may have a different memory + * layout, however, so choose what fits your needs best). You need to + * use the first method if you aren't handling interlacing yourself. + */ + png_uint_32 k, height, width; + + /* In this example, "image" is a one-dimensional array of bytes */ + png_byte image[height*width*bytes_per_pixel]; + + png_bytep row_pointers[height]; + + if (height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) + png_error (png_ptr, "Image is too tall to process in memory"); + + /* Set up pointers into your "image" byte array */ + for (k = 0; k < height; k++) + row_pointers[k] = image + k*width*bytes_per_pixel; + + /* One of the following output methods is REQUIRED */ + +#ifdef entire /* Write out the entire image data in one call */ + png_write_image(png_ptr, row_pointers); + + /* The other way to write the image - deal with interlacing */ + +#else no_entire /* Write out the image data by one or more scanlines */ + + /* The number of passes is either 1 for non-interlaced images, + * or 7 for interlaced images. + */ + for (pass = 0; pass < number_passes; pass++) + { + /* Write a few rows at a time. */ + png_write_rows(png_ptr, &row_pointers[first_row], number_of_rows); + + /* If you are only writing one row at a time, this works */ + for (y = 0; y < height; y++) + png_write_rows(png_ptr, &row_pointers[y], 1); + } +#endif no_entire /* Use only one output method */ + + /* You can write optional chunks like tEXt, zTXt, and tIME at the end + * as well. Shouldn't be necessary in 1.2.0 and up as all the public + * chunks are supported and you can use png_set_unknown_chunks() to + * register unknown chunks into the info structure to be written out. + */ + + /* It is REQUIRED to call this to finish writing the rest of the file */ + png_write_end(png_ptr, info_ptr); +#endif hilevel + + /* If you png_malloced a palette, free it here (don't free info_ptr->palette, + * as recommended in versions 1.0.5m and earlier of this example; if + * libpng mallocs info_ptr->palette, libpng will free it). If you + * allocated it with malloc() instead of png_malloc(), use free() instead + * of png_free(). + */ + png_free(png_ptr, palette); + palette = NULL; + + /* Similarly, if you png_malloced any data that you passed in with + * png_set_something(), such as a hist or trans array, free it here, + * when you can be sure that libpng is through with it. + */ + png_free(png_ptr, trans); + trans = NULL; + /* Whenever you use png_free() it is a good idea to set the pointer to + * NULL in case your application inadvertently tries to png_free() it + * again. When png_free() sees a NULL it returns without action, thus + * avoiding the double-free security problem. + */ + + /* Clean up after the write, and free any memory allocated */ + png_destroy_write_struct(&png_ptr, &info_ptr); + + /* Close the file */ + fclose(fp); + + /* That's it */ + return (OK); +} + +#endif /* if 0 */ diff --git a/Source/LibPNG/libpng-manual.txt b/Source/LibPNG/libpng-manual.txt index 82afe70..5b17ba8 100644 --- a/Source/LibPNG/libpng-manual.txt +++ b/Source/LibPNG/libpng-manual.txt @@ -1,4667 +1,4667 @@ -Libpng-manual.txt - A description on how to use and modify libpng - - libpng version 1.5.13 - September 27, 2012 - Updated and distributed by Glenn Randers-Pehrson - - Copyright (c) 1998-2012 Glenn Randers-Pehrson - - This document is released under the libpng license. - For conditions of distribution and use, see the disclaimer - and license in png.h - - Based on: - - libpng versions 0.97, January 1998, through 1.5.13 - September 27, 2012 - Updated and distributed by Glenn Randers-Pehrson - Copyright (c) 1998-2012 Glenn Randers-Pehrson - - libpng 1.0 beta 6 version 0.96 May 28, 1997 - Updated and distributed by Andreas Dilger - Copyright (c) 1996, 1997 Andreas Dilger - - libpng 1.0 beta 2 - version 0.88 January 26, 1996 - For conditions of distribution and use, see copyright - notice in png.h. Copyright (c) 1995, 1996 Guy Eric - Schalnat, Group 42, Inc. - - Updated/rewritten per request in the libpng FAQ - Copyright (c) 1995, 1996 Frank J. T. Wojcik - December 18, 1995 & January 20, 1996 - -I. Introduction - -This file describes how to use and modify the PNG reference library -(known as libpng) for your own use. There are five sections to this -file: introduction, structures, reading, writing, and modification and -configuration notes for various special platforms. In addition to this -file, example.c is a good starting point for using the library, as -it is heavily commented and should include everything most people -will need. We assume that libpng is already installed; see the -INSTALL file for instructions on how to install libpng. - -For examples of libpng usage, see the files "example.c", "pngtest.c", -and the files in the "contrib" directory, all of which are included in -the libpng distribution. - -Libpng was written as a companion to the PNG specification, as a way -of reducing the amount of time and effort it takes to support the PNG -file format in application programs. - -The PNG specification (second edition), November 2003, is available as -a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at -. It is technically equivalent -to the PNG specification (second edition) but has some additional material. - -The PNG-1.0 specification is available -as RFC 2083 and as a -W3C Recommendation . - -Some additional chunks are described in the special-purpose public chunks -documents at . - -Other information -about PNG, and the latest version of libpng, can be found at the PNG home -page, . - -Most users will not have to modify the library significantly; advanced -users may want to modify it more. All attempts were made to make it as -complete as possible, while keeping the code easy to understand. -Currently, this library only supports C. Support for other languages -is being considered. - -Libpng has been designed to handle multiple sessions at one time, -to be easily modifiable, to be portable to the vast majority of -machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy -to use. The ultimate goal of libpng is to promote the acceptance of -the PNG file format in whatever way possible. While there is still -work to be done (see the TODO file), libpng should cover the -majority of the needs of its users. - -Libpng uses zlib for its compression and decompression of PNG files. -Further information about zlib, and the latest version of zlib, can -be found at the zlib home page, . -The zlib compression utility is a general purpose utility that is -useful for more than PNG files, and can be used without libpng. -See the documentation delivered with zlib for more details. -You can usually find the source files for the zlib utility wherever you -find the libpng source files. - -Libpng is thread safe, provided the threads are using different -instances of the structures. Each thread should have its own -png_struct and png_info instances, and thus its own image. -Libpng does not protect itself against two threads using the -same instance of a structure. - -II. Structures - -There are two main structures that are important to libpng, png_struct -and png_info. Both are internal structures that are no longer exposed -in the libpng interface (as of libpng 1.5.0). - -The png_info structure is designed to provide information about the -PNG file. At one time, the fields of png_info were intended to be -directly accessible to the user. However, this tended to cause problems -with applications using dynamically loaded libraries, and as a result -a set of interface functions for png_info (the png_get_*() and png_set_*() -functions) was developed, and direct access to the png_info fields was -deprecated.. - -The png_struct structure is the object used by the library to decode a -single image. As of 1.5.0 this structure is also not exposed. - -Almost all libpng APIs require a pointer to a png_struct as the first argument. -Many (in particular the png_set and png_get APIs) also require a pointer -to png_info as the second argument. Some application visible macros -defined in png.h designed for basic data access (reading and writing -integers in the PNG format) don't take a png_info pointer, but it's almost -always safe to assume that a (png_struct*) has to be passed to call an API -function. - -You can have more than one png_info structure associated with an image, -as illustrated in pngtest.c, one for information valid prior to the -IDAT chunks and another (called "end_info" below) for things after them. - -The png.h header file is an invaluable reference for programming with libpng. -And while I'm on the topic, make sure you include the libpng header file: - -#include - -and also (as of libpng-1.5.0) the zlib header file, if you need it: - -#include - -Types - -The png.h header file defines a number of integral types used by the -APIs. Most of these are fairly obvious; for example types corresponding -to integers of particular sizes and types for passing color values. - -One exception is how non-integral numbers are handled. For application -convenience most APIs that take such numbers have C (double) arguments; -however, internally PNG, and libpng, use 32 bit signed integers and encode -the value by multiplying by 100,000. As of libpng 1.5.0 a convenience -macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point) -which is simply (png_int_32). - -All APIs that take (double) arguments also have a matching API that -takes the corresponding fixed point integer arguments. The fixed point -API has the same name as the floating point one with "_fixed" appended. -The actual range of values permitted in the APIs is frequently less than -the full range of (png_fixed_point) (-21474 to +21474). When APIs require -a non-negative argument the type is recorded as png_uint_32 above. Consult -the header file and the text below for more information. - -Special care must be take with sCAL chunk handling because the chunk itself -uses non-integral values encoded as strings containing decimal floating point -numbers. See the comments in the header file. - -Configuration - -The main header file function declarations are frequently protected by C -preprocessing directives of the form: - - #ifdef PNG_feature_SUPPORTED - declare-function - #endif - ... - #ifdef PNG_feature_SUPPORTED - use-function - #endif - -The library can be built without support for these APIs, although a -standard build will have all implemented APIs. Application programs -should check the feature macros before using an API for maximum -portability. From libpng 1.5.0 the feature macros set during the build -of libpng are recorded in the header file "pnglibconf.h" and this file -is always included by png.h. - -If you don't need to change the library configuration from the default, skip to -the next section ("Reading"). - -Notice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all -of the build project files in the 'projects' directory simply copy -scripts/pnglibconf.h.prebuilt to pnglibconf.h. This means that these build -systems do not permit easy auto-configuration of the library - they only -support the default configuration. - -The easiest way to make minor changes to the libpng configuration when -auto-configuration is supported is to add definitions to the command line -using (typically) CPPFLAGS. For example: - -CPPFLAGS=-DPNG_NO_FLOATING_ARITHMETIC - -will change the internal libpng math implementation for gamma correction and -other arithmetic calculations to fixed point, avoiding the need for fast -floating point support. The result can be seen in the generated pnglibconf.h - -make sure it contains the changed feature macro setting. - -If you need to make more extensive configuration changes - more than one or two -feature macro settings - you can either add -DPNG_USER_CONFIG to the build -command line and put a list of feature macro settings in pngusr.h or you can set -DFA_XTRA (a makefile variable) to a file containing the same information in the -form of 'option' settings. - -A. Changing pnglibconf.h - -A variety of methods exist to build libpng. Not all of these support -reconfiguration of pnglibconf.h. To reconfigure pnglibconf.h it must either be -rebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand. - -Hand editing is achieved by copying scripts/pnglibconf.h.prebuilt to -pnglibconf.h and changing the lines defining the supported features, paying -very close attention to the 'option' information in scripts/pnglibconf.dfa -that describes those features and their requirements. This is easy to get -wrong. - -B. Configuration using DFA_XTRA - -Rebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later -variant such as 'nawk' or 'gawk', is available. The configure build will -automatically find an appropriate awk and build pnglibconf.h. -The scripts/pnglibconf.mak file contains a set of make rules for doing the -same thing if configure is not used, and many of the makefiles in the scripts -directory use this approach. - -When rebuilding simply write a new file containing changed options and set -DFA_XTRA to the name of this file. This causes the build to append the new file -to the end of scripts/pnglibconf.dfa. The pngusr.dfa file should contain lines -of the following forms: - -everything = off - -This turns all optional features off. Include it at the start of pngusr.dfa to -make it easier to build a minimal configuration. You will need to turn at least -some features on afterward to enable either reading or writing code, or both. - -option feature on -option feature off - -Enable or disable a single feature. This will automatically enable other -features required by a feature that is turned on or disable other features that -require a feature which is turned off. Conflicting settings will cause an error -message to be emitted by awk. - -setting feature default value - -Changes the default value of setting 'feature' to 'value'. There are a small -number of settings listed at the top of pnglibconf.h, they are documented in the -source code. Most of these values have performance implications for the library -but most of them have no visible effect on the API. Some can also be overridden -from the API. - -This method of building a customized pnglibconf.h is illustrated in -contrib/pngminim/*. See the "$(PNGCONF):" target in the makefile and -pngusr.dfa in these directories. - -C. Configuration using PNG_USR_CONFIG - -If -DPNG_USR_CONFIG is added to the CFLAGS when pnglibconf.h is built the file -pngusr.h will automatically be included before the options in -scripts/pnglibconf.dfa are processed. Your pngusr.h file should contain only -macro definitions turning features on or off or setting settings. - -Apart from the global setting "everything = off" all the options listed above -can be set using macros in pngusr.h: - -#define PNG_feature_SUPPORTED - -is equivalent to: - -option feature on - -#define PNG_NO_feature - -is equivalent to: - -option feature off - -#define PNG_feature value - -is equivalent to: - -setting feature default value - -Notice that in both cases, pngusr.dfa and pngusr.h, the contents of the -pngusr file you supply override the contents of scripts/pnglibconf.dfa - -If confusing or incomprehensible behavior results it is possible to -examine the intermediate file pnglibconf.dfn to find the full set of -dependency information for each setting and option. Simply locate the -feature in the file and read the C comments that precede it. - -This method is also illustrated in the contrib/pngminim/* makefiles and -pngusr.h. - -III. Reading - -We'll now walk you through the possible functions to call when reading -in a PNG file sequentially, briefly explaining the syntax and purpose -of each one. See example.c and png.h for more detail. While -progressive reading is covered in the next section, you will still -need some of the functions discussed in this section to read a PNG -file. - -Setup - -You will want to do the I/O initialization(*) before you get into libpng, -so if it doesn't work, you don't have much to undo. Of course, you -will also want to insure that you are, in fact, dealing with a PNG -file. Libpng provides a simple check to see if a file is a PNG file. -To use it, pass in the first 1 to 8 bytes of the file to the function -png_sig_cmp(), and it will return 0 (false) if the bytes match the -corresponding bytes of the PNG signature, or nonzero (true) otherwise. -Of course, the more bytes you pass in, the greater the accuracy of the -prediction. - -If you are intending to keep the file pointer open for use in libpng, -you must ensure you don't read more than 8 bytes from the beginning -of the file, and you also have to make a call to png_set_sig_bytes_read() -with the number of bytes you read from the beginning. Libpng will -then only check the bytes (if any) that your program didn't read. - -(*): If you are not using the standard I/O functions, you will need -to replace them with custom functions. See the discussion under -Customizing libpng. - - - FILE *fp = fopen(file_name, "rb"); - if (!fp) - { - return (ERROR); - } - - fread(header, 1, number, fp); - is_png = !png_sig_cmp(header, 0, number); - - if (!is_png) - { - return (NOT_PNG); - } - - -Next, png_struct and png_info need to be allocated and initialized. In -order to ensure that the size of these structures is correct even with a -dynamically linked libpng, there are functions to initialize and -allocate the structures. We also pass the library version, optional -pointers to error handling functions, and a pointer to a data struct for -use by the error functions, if necessary (the pointer and functions can -be NULL if the default error handlers are to be used). See the section -on Changes to Libpng below regarding the old initialization functions. -The structure allocation functions quietly return NULL if they fail to -create the structure, so your application should check for that. - - png_structp png_ptr = png_create_read_struct - (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, - user_error_fn, user_warning_fn); - - if (!png_ptr) - return (ERROR); - - png_infop info_ptr = png_create_info_struct(png_ptr); - - if (!info_ptr) - { - png_destroy_read_struct(&png_ptr, - (png_infopp)NULL, (png_infopp)NULL); - return (ERROR); - } - -If you want to use your own memory allocation routines, -use a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use -png_create_read_struct_2() instead of png_create_read_struct(): - - png_structp png_ptr = png_create_read_struct_2 - (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, - user_error_fn, user_warning_fn, (png_voidp) - user_mem_ptr, user_malloc_fn, user_free_fn); - -The error handling routines passed to png_create_read_struct() -and the memory alloc/free routines passed to png_create_struct_2() -are only necessary if you are not using the libpng supplied error -handling and memory alloc/free functions. - -When libpng encounters an error, it expects to longjmp back -to your routine. Therefore, you will need to call setjmp and pass -your png_jmpbuf(png_ptr). If you read the file from different -routines, you will need to update the longjmp buffer every time you enter -a new routine that will call a png_*() function. - -See your documentation of setjmp/longjmp for your compiler for more -information on setjmp/longjmp. See the discussion on libpng error -handling in the Customizing Libpng section below for more information -on the libpng error handling. If an error occurs, and libpng longjmp's -back to your setjmp, you will want to call png_destroy_read_struct() to -free any memory. - - if (setjmp(png_jmpbuf(png_ptr))) - { - png_destroy_read_struct(&png_ptr, &info_ptr, - &end_info); - fclose(fp); - return (ERROR); - } - -Pass (png_infopp)NULL instead of &end_info if you didn't create -an end_info structure. - -If you would rather avoid the complexity of setjmp/longjmp issues, -you can compile libpng with PNG_NO_SETJMP, in which case -errors will result in a call to PNG_ABORT() which defaults to abort(). - -You can #define PNG_ABORT() to a function that does something -more useful than abort(), as long as your function does not -return. - -Now you need to set up the input code. The default for libpng is to -use the C function fread(). If you use this, you will need to pass a -valid FILE * in the function png_init_io(). Be sure that the file is -opened in binary mode. If you wish to handle reading data in another -way, you need not call the png_init_io() function, but you must then -implement the libpng I/O methods discussed in the Customizing Libpng -section below. - - png_init_io(png_ptr, fp); - -If you had previously opened the file and read any of the signature from -the beginning in order to see if this was a PNG file, you need to let -libpng know that there are some bytes missing from the start of the file. - - png_set_sig_bytes(png_ptr, number); - -You can change the zlib compression buffer size to be used while -reading compressed data with - - png_set_compression_buffer_size(png_ptr, buffer_size); - -where the default size is 8192 bytes. Note that the buffer size -is changed immediately and the buffer is reallocated immediately, -instead of setting a flag to be acted upon later. - -If you want CRC errors to be handled in a different manner than -the default, use - - png_set_crc_action(png_ptr, crit_action, ancil_action); - -The values for png_set_crc_action() say how libpng is to handle CRC errors in -ancillary and critical chunks, and whether to use the data contained -therein. Note that it is impossible to "discard" data in a critical -chunk. - -Choices for (int) crit_action are - PNG_CRC_DEFAULT 0 error/quit - PNG_CRC_ERROR_QUIT 1 error/quit - PNG_CRC_WARN_USE 3 warn/use data - PNG_CRC_QUIET_USE 4 quiet/use data - PNG_CRC_NO_CHANGE 5 use the current value - -Choices for (int) ancil_action are - PNG_CRC_DEFAULT 0 error/quit - PNG_CRC_ERROR_QUIT 1 error/quit - PNG_CRC_WARN_DISCARD 2 warn/discard data - PNG_CRC_WARN_USE 3 warn/use data - PNG_CRC_QUIET_USE 4 quiet/use data - PNG_CRC_NO_CHANGE 5 use the current value - -Setting up callback code - -You can set up a callback function to handle any unknown chunks in the -input stream. You must supply the function - - read_chunk_callback(png_structp png_ptr, - png_unknown_chunkp chunk); - { - /* The unknown chunk structure contains your - chunk data, along with similar data for any other - unknown chunks: */ - - png_byte name[5]; - png_byte *data; - png_size_t size; - - /* Note that libpng has already taken care of - the CRC handling */ - - /* put your code here. Search for your chunk in the - unknown chunk structure, process it, and return one - of the following: */ - - return (-n); /* chunk had an error */ - return (0); /* did not recognize */ - return (n); /* success */ - } - -(You can give your function another name that you like instead of -"read_chunk_callback") - -To inform libpng about your function, use - - png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr, - read_chunk_callback); - -This names not only the callback function, but also a user pointer that -you can retrieve with - - png_get_user_chunk_ptr(png_ptr); - -If you call the png_set_read_user_chunk_fn() function, then all unknown -chunks will be saved when read, in case your callback function will need -one or more of them. This behavior can be changed with the -png_set_keep_unknown_chunks() function, described below. - -At this point, you can set up a callback function that will be -called after each row has been read, which you can use to control -a progress meter or the like. It's demonstrated in pngtest.c. -You must supply a function - - void read_row_callback(png_structp png_ptr, - png_uint_32 row, int pass); - { - /* put your code here */ - } - -(You can give it another name that you like instead of "read_row_callback") - -To inform libpng about your function, use - - png_set_read_status_fn(png_ptr, read_row_callback); - -When this function is called the row has already been completely processed and -the 'row' and 'pass' refer to the next row to be handled. For the -non-interlaced case the row that was just handled is simply one less than the -passed in row number, and pass will always be 0. For the interlaced case the -same applies unless the row value is 0, in which case the row just handled was -the last one from one of the preceding passes. Because interlacing may skip a -pass you cannot be sure that the preceding pass is just 'pass-1', if you really -need to know what the last pass is record (row,pass) from the callback and use -the last recorded value each time. - -As with the user transform you can find the output row using the -PNG_ROW_FROM_PASS_ROW macro. - -Unknown-chunk handling - -Now you get to set the way the library processes unknown chunks in the -input PNG stream. Both known and unknown chunks will be read. Normal -behavior is that known chunks will be parsed into information in -various info_ptr members while unknown chunks will be discarded. This -behavior can be wasteful if your application will never use some known -chunk types. To change this, you can call: - - png_set_keep_unknown_chunks(png_ptr, keep, - chunk_list, num_chunks); - keep - 0: default unknown chunk handling - 1: ignore; do not keep - 2: keep only if safe-to-copy - 3: keep even if unsafe-to-copy - - You can use these definitions: - PNG_HANDLE_CHUNK_AS_DEFAULT 0 - PNG_HANDLE_CHUNK_NEVER 1 - PNG_HANDLE_CHUNK_IF_SAFE 2 - PNG_HANDLE_CHUNK_ALWAYS 3 - - chunk_list - list of chunks affected (a byte string, - five bytes per chunk, NULL or '\0' if - num_chunks is 0) - - num_chunks - number of chunks affected; if 0, all - unknown chunks are affected. If nonzero, - only the chunks in the list are affected - -Unknown chunks declared in this way will be saved as raw data onto a -list of png_unknown_chunk structures. If a chunk that is normally -known to libpng is named in the list, it will be handled as unknown, -according to the "keep" directive. If a chunk is named in successive -instances of png_set_keep_unknown_chunks(), the final instance will -take precedence. The IHDR and IEND chunks should not be named in -chunk_list; if they are, libpng will process them normally anyway. -If you know that your application will never make use of some particular -chunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below. - -Here is an example of the usage of png_set_keep_unknown_chunks(), -where the private "vpAg" chunk will later be processed by a user chunk -callback function: - - png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'}; - - #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) - png_byte unused_chunks[]= - { - 104, 73, 83, 84, (png_byte) '\0', /* hIST */ - 105, 84, 88, 116, (png_byte) '\0', /* iTXt */ - 112, 67, 65, 76, (png_byte) '\0', /* pCAL */ - 115, 67, 65, 76, (png_byte) '\0', /* sCAL */ - 115, 80, 76, 84, (png_byte) '\0', /* sPLT */ - 116, 73, 77, 69, (png_byte) '\0', /* tIME */ - }; - #endif - - ... - - #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) - /* ignore all unknown chunks: */ - png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0); - - /* except for vpAg: */ - png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1); - - /* also ignore unused known chunks: */ - png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks, - (int)sizeof(unused_chunks)/5); - #endif - -User limits - -The PNG specification allows the width and height of an image to be as -large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns. -Since very few applications really need to process such large images, -we have imposed an arbitrary 1-million limit on rows and columns. -Larger images will be rejected immediately with a png_error() call. If -you wish to change this limit, you can use - - png_set_user_limits(png_ptr, width_max, height_max); - -to set your own limits, or use width_max = height_max = 0x7fffffffL -to allow all valid dimensions (libpng may reject some very large images -anyway because of potential buffer overflow conditions). - -You should put this statement after you create the PNG structure and -before calling png_read_info(), png_read_png(), or png_process_data(). - -When writing a PNG datastream, put this statement before calling -png_write_info() or png_write_png(). - -If you need to retrieve the limits that are being applied, use - - width_max = png_get_user_width_max(png_ptr); - height_max = png_get_user_height_max(png_ptr); - -The PNG specification sets no limit on the number of ancillary chunks -allowed in a PNG datastream. You can impose a limit on the total number -of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with - - png_set_chunk_cache_max(png_ptr, user_chunk_cache_max); - -where 0x7fffffffL means unlimited. You can retrieve this limit with - - chunk_cache_max = png_get_chunk_cache_max(png_ptr); - -This limit also applies to the number of buffers that can be allocated -by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks. - -You can also set a limit on the amount of memory that a compressed chunk -other than IDAT can occupy, with - - png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max); - -and you can retrieve the limit with - - chunk_malloc_max = png_get_chunk_malloc_max(png_ptr); - -Any chunks that would cause either of these limits to be exceeded will -be ignored. - -Information about your system - -If you intend to display the PNG or to incorporate it in other image data you -need to tell libpng information about your display or drawing surface so that -libpng can convert the values in the image to match the display. - -From libpng-1.5.4 this information can be set before reading the PNG file -header. In earlier versions png_set_gamma() existed but behaved incorrectly if -called before the PNG file header had been read and png_set_alpha_mode() did not -exist. - -If you need to support versions prior to libpng-1.5.4 test the version number -as illustrated below using "PNG_LIBPNG_VER >= 10504" and follow the procedures -described in the appropriate manual page. - -You give libpng the encoding expected by your system expressed as a 'gamma' -value. You can also specify a default encoding for the PNG file in -case the required information is missing from the file. By default libpng -assumes that the PNG data matches your system, to keep this default call: - - png_set_gamma(png_ptr, screen_gamma, 1/screen_gamma/*file gamma*/); - -or you can use the fixed point equivalent: - - png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma, PNG_FP_1/screen_gamma); - -If you don't know the gamma for your system it is probably 2.2 - a good -approximation to the IEC standard for display systems (sRGB). If images are -too contrasty or washed out you got the value wrong - check your system -documentation! - -Many systems permit the system gamma to be changed via a lookup table in the -display driver, a few systems, including older Macs, change the response by -default. As of 1.5.4 three special values are available to handle common -situations: - - PNG_DEFAULT_sRGB: Indicates that the system conforms to the IEC 61966-2-1 - standard. This matches almost all systems. - PNG_GAMMA_MAC_18: Indicates that the system is an older (pre Mac OS 10.6) - Apple Macintosh system with the default settings. - PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates that the - system expects data with no gamma encoding. - -You would use the linear (unencoded) value if you need to process the pixel -values further because this avoids the need to decode and reencode each -component value whenever arithmetic is performed. A lot of graphics software -uses linear values for this reason, often with higher precision component values -to preserve overall accuracy. - -The second thing you may need to tell libpng about is how your system handles -alpha channel information. Some, but not all, PNG files contain an alpha -channel. To display these files correctly you need to compose the data onto a -suitable background, as described in the PNG specification. - -Libpng only supports composing onto a single color (using png_set_background; -see below). Otherwise you must do the composition yourself and, in this case, -you may need to call png_set_alpha_mode: - - #if PNG_LIBPNG_VER >= 10504 - png_set_alpha_mode(png_ptr, mode, screen_gamma); - #else - png_set_gamma(png_ptr, screen_gamma, 1.0/screen_gamma); - #endif - -The screen_gamma value is the same as the argument to png_set_gamma; however, -how it affects the output depends on the mode. png_set_alpha_mode() sets the -file gamma default to 1/screen_gamma, so normally you don't need to call -png_set_gamma. If you need different defaults call png_set_gamma() before -png_set_alpha_mode() - if you call it after it will override the settings made -by png_set_alpha_mode(). - -The mode is as follows: - - PNG_ALPHA_PNG: The data is encoded according to the PNG specification. Red, -green and blue, or gray, components are gamma encoded color -values and are not premultiplied by the alpha value. The -alpha value is a linear measure of the contribution of the -pixel to the corresponding final output pixel. - -You should normally use this format if you intend to perform -color correction on the color values; most, maybe all, color -correction software has no handling for the alpha channel and, -anyway, the math to handle pre-multiplied component values is -unnecessarily complex. - -Before you do any arithmetic on the component values you need -to remove the gamma encoding and multiply out the alpha -channel. See the PNG specification for more detail. It is -important to note that when an image with an alpha channel is -scaled, linear encoded, pre-multiplied component values must -be used! - -The remaining modes assume you don't need to do any further color correction or -that if you do, your color correction software knows all about alpha (it -probably doesn't!) - - PNG_ALPHA_STANDARD: The data libpng produces -is encoded in the standard way -assumed by most correctly written graphics software. -The gamma encoding will be removed by libpng and the -linear component values will be pre-multiplied by the -alpha channel. - -With this format the final image must be re-encoded to -match the display gamma before the image is displayed. -If your system doesn't do that, yet still seems to -perform arithmetic on the pixels without decoding them, -it is broken - check out the modes below. - -With PNG_ALPHA_STANDARD libpng always produces linear -component values, whatever screen_gamma you supply. The -screen_gamma value is, however, used as a default for -the file gamma if the PNG file has no gamma information. - -If you call png_set_gamma() after png_set_alpha_mode() you -will override the linear encoding. Instead the -pre-multiplied pixel values will be gamma encoded but -the alpha channel will still be linear. This may -actually match the requirements of some broken software, -but it is unlikely. - -While linear 8-bit data is often used it has -insufficient precision for any image with a reasonable -dynamic range. To avoid problems, and if your software -supports it, use png_set_expand_16() to force all -components to 16 bits. - - PNG_ALPHA_OPTIMIZED: This mode is the same -as PNG_ALPHA_STANDARD except that -completely opaque pixels are gamma encoded according to -the screen_gamma value. Pixels with alpha less than 1.0 -will still have linear components. - -Use this format if you have control over your -compositing software and so don't do other arithmetic -(such as scaling) on the data you get from libpng. Your -compositing software can simply copy opaque pixels to -the output but still has linear values for the -non-opaque pixels. - -In normal compositing, where the alpha channel encodes -partial pixel coverage (as opposed to broad area -translucency), the inaccuracies of the 8-bit -representation of non-opaque pixels are irrelevant. - -You can also try this format if your software is broken; -it might look better. - - PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD; -however, all component values, -including the alpha channel are gamma encoded. This is -an appropriate format to try if your software, or more -likely hardware, is totally broken, i.e., if it performs -linear arithmetic directly on gamma encoded values. - -In most cases of broken software or hardware the bug in the final display -manifests as a subtle halo around composited parts of the image. You may not -even perceive this as a halo; the composited part of the image may simply appear -separate from the background, as though it had been cut out of paper and pasted -on afterward. - -If you don't have to deal with bugs in software or hardware, or if you can fix -them, there are three recommended ways of using png_set_alpha_mode(): - - png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG, - screen_gamma); - -You can do color correction on the result (libpng does not currently -support color correction internally). When you handle the alpha channel -you need to undo the gamma encoding and multiply out the alpha. - - png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD, - screen_gamma); - png_set_expand_16(png_ptr); - -If you are using the high level interface, don't call png_set_expand_16(); -instead pass PNG_TRANSFORM_EXPAND_16 to the interface. - -With this mode you can't do color correction, but you can do arithmetic, -including composition and scaling, on the data without further processing. - - png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED, - screen_gamma); - -You can avoid the expansion to 16-bit components with this mode, but you -lose the ability to scale the image or perform other linear arithmetic. -All you can do is compose the result onto a matching output. Since this -mode is libpng-specific you also need to write your own composition -software. - -If you don't need, or can't handle, the alpha channel you can call -png_set_background() to remove it by compositing against a fixed color. Don't -call png_set_strip_alpha() to do this - it will leave spurious pixel values in -transparent parts of this image. - - png_set_background(png_ptr, &background_color, - PNG_BACKGROUND_GAMMA_SCREEN, 0, 1); - -The background_color is an RGB or grayscale value according to the data format -libpng will produce for you. Because you don't yet know the format of the PNG -file, if you call png_set_background at this point you must arrange for the -format produced by libpng to always have 8-bit or 16-bit components and then -store the color as an 8-bit or 16-bit color as appropriate. The color contains -separate gray and RGB component values, so you can let libpng produce gray or -RGB output according to the input format, but low bit depth grayscale images -must always be converted to at least 8-bit format. (Even though low bit depth -grayscale images can't have an alpha channel they can have a transparent -color!) - -You set the transforms you need later, either as flags to the high level -interface or libpng API calls for the low level interface. For reference the -settings and API calls required are: - -8-bit values: - PNG_TRANSFORM_SCALE_16 | PNG_EXPAND - png_set_expand(png_ptr); png_set_scale_16(png_ptr); - - If you must get exactly the same inaccurate results - produced by default in versions prior to libpng-1.5.4, - use PNG_TRANSFORM_STRIP_16 and png_set_strip_16(png_ptr) - instead. - -16-bit values: - PNG_TRANSFORM_EXPAND_16 - png_set_expand_16(png_ptr); - -In either case palette image data will be expanded to RGB. If you just want -color data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr) -to the list. - -Calling png_set_background before the PNG file header is read will not work -prior to libpng-1.5.4. Because the failure may result in unexpected warnings or -errors it is therefore much safer to call png_set_background after the head has -been read. Unfortunately this means that prior to libpng-1.5.4 it cannot be -used with the high level interface. - -The high-level read interface - -At this point there are two ways to proceed; through the high-level -read interface, or through a sequence of low-level read operations. -You can use the high-level interface if (a) you are willing to read -the entire image into memory, and (b) the input transformations -you want to do are limited to the following set: - - PNG_TRANSFORM_IDENTITY No transformation - PNG_TRANSFORM_SCALE_16 Strip 16-bit samples to - 8-bit accurately - PNG_TRANSFORM_STRIP_16 Chop 16-bit samples to - 8-bit less accurately - PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel - PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit - samples to bytes - PNG_TRANSFORM_PACKSWAP Change order of packed - pixels to LSB first - PNG_TRANSFORM_EXPAND Perform set_expand() - PNG_TRANSFORM_INVERT_MONO Invert monochrome images - PNG_TRANSFORM_SHIFT Normalize pixels to the - sBIT depth - PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA - to BGRA - PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA - to AG - PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity - to transparency - PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples - PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples - to RGB (or GA to RGBA) - PNG_TRANSFORM_EXPAND_16 Expand samples to 16 bits - -(This excludes setting a background color, doing gamma transformation, -quantizing, and setting filler.) If this is the case, simply do this: - - png_read_png(png_ptr, info_ptr, png_transforms, NULL) - -where png_transforms is an integer containing the bitwise OR of some -set of transformation flags. This call is equivalent to png_read_info(), -followed the set of transformations indicated by the transform mask, -then png_read_image(), and finally png_read_end(). - -(The final parameter of this call is not yet used. Someday it might point -to transformation parameters required by some future input transform.) - -You must use png_transforms and not call any png_set_transform() functions -when you use png_read_png(). - -After you have called png_read_png(), you can retrieve the image data -with - - row_pointers = png_get_rows(png_ptr, info_ptr); - -where row_pointers is an array of pointers to the pixel data for each row: - - png_bytep row_pointers[height]; - -If you know your image size and pixel size ahead of time, you can allocate -row_pointers prior to calling png_read_png() with - - if (height > PNG_UINT_32_MAX/png_sizeof(png_byte)) - png_error (png_ptr, - "Image is too tall to process in memory"); - - if (width > PNG_UINT_32_MAX/pixel_size) - png_error (png_ptr, - "Image is too wide to process in memory"); - - row_pointers = png_malloc(png_ptr, - height*png_sizeof(png_bytep)); - - for (int i=0; i) and -png_get_(png_ptr, info_ptr, ...) functions return non-zero if the -data has been read, or zero if it is missing. The parameters to the -png_get_ are set directly if they are simple data types, or a -pointer into the info_ptr is returned for any complex types. - -The colorspace data from gAMA, cHRM, sRGB, iCCP, and sBIT chunks -is simply returned to give the application information about how the -image was encoded. Libpng itself only does transformations using the file -gamma when combining semitransparent pixels with the background color. - - png_get_PLTE(png_ptr, info_ptr, &palette, - &num_palette); - - palette - the palette for the file - (array of png_color) - - num_palette - number of entries in the palette - - png_get_gAMA(png_ptr, info_ptr, &file_gamma); - png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma); - - file_gamma - the gamma at which the file was - written (PNG_INFO_gAMA) - - int_file_gamma - 100,000 times the gamma at which the - file is written - - png_get_cHRM(png_ptr, info_ptr, &white_x, &white_y, &red_x, - &red_y, &green_x, &green_y, &blue_x, &blue_y) - png_get_cHRM_XYZ(png_ptr, info_ptr, &red_X, &red_Y, &red_Z, &green_X, - &green_Y, &green_Z, &blue_X, &blue_Y, &blue_Z) - png_get_cHRM_fixed(png_ptr, info_ptr, &int_white_x, &int_white_y, - &int_red_x, &int_red_y, &int_green_x, &int_green_y, - &int_blue_x, &int_blue_y) - png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &int_red_X, &int_red_Y, - &int_red_Z, &int_green_X, &int_green_Y, &int_green_Z, - &int_blue_X, &int_blue_Y, &int_blue_Z) - - {white,red,green,blue}_{x,y} - A color space encoding specified using the - chromaticities of the end points and the - white point. (PNG_INFO_cHRM) - - {red,green,blue}_{X,Y,Z} - A color space encoding specified using the encoding end - points - the CIE tristimulus specification of the intended - color of the red, green and blue channels in the PNG RGB - data. The white point is simply the sum of the three end - points. (PNG_INFO_cHRM) - - png_get_sRGB(png_ptr, info_ptr, &srgb_intent); - - file_srgb_intent - the rendering intent (PNG_INFO_sRGB) - The presence of the sRGB chunk - means that the pixel data is in the - sRGB color space. This chunk also - implies specific values of gAMA and - cHRM. - - png_get_iCCP(png_ptr, info_ptr, &name, - &compression_type, &profile, &proflen); - - name - The profile name. - - compression_type - The compression type; always - PNG_COMPRESSION_TYPE_BASE for PNG 1.0. - You may give NULL to this argument to - ignore it. - - profile - International Color Consortium color - profile data. May contain NULs. - - proflen - length of profile data in bytes. - - png_get_sBIT(png_ptr, info_ptr, &sig_bit); - - sig_bit - the number of significant bits for - (PNG_INFO_sBIT) each of the gray, - red, green, and blue channels, - whichever are appropriate for the - given color type (png_color_16) - - png_get_tRNS(png_ptr, info_ptr, &trans_alpha, - &num_trans, &trans_color); - - trans_alpha - array of alpha (transparency) - entries for palette (PNG_INFO_tRNS) - - num_trans - number of transparent entries - (PNG_INFO_tRNS) - - trans_color - graylevel or color sample values of - the single transparent color for - non-paletted images (PNG_INFO_tRNS) - - png_get_hIST(png_ptr, info_ptr, &hist); - (PNG_INFO_hIST) - - hist - histogram of palette (array of - png_uint_16) - - png_get_tIME(png_ptr, info_ptr, &mod_time); - - mod_time - time image was last modified - (PNG_VALID_tIME) - - png_get_bKGD(png_ptr, info_ptr, &background); - - background - background color (of type - png_color_16p) (PNG_VALID_bKGD) - valid 16-bit red, green and blue - values, regardless of color_type - - num_comments = png_get_text(png_ptr, info_ptr, - &text_ptr, &num_text); - - num_comments - number of comments - - text_ptr - array of png_text holding image - comments - - text_ptr[i].compression - type of compression used - on "text" PNG_TEXT_COMPRESSION_NONE - PNG_TEXT_COMPRESSION_zTXt - PNG_ITXT_COMPRESSION_NONE - PNG_ITXT_COMPRESSION_zTXt - - text_ptr[i].key - keyword for comment. Must contain - 1-79 characters. - - text_ptr[i].text - text comments for current - keyword. Can be empty. - - text_ptr[i].text_length - length of text string, - after decompression, 0 for iTXt - - text_ptr[i].itxt_length - length of itxt string, - after decompression, 0 for tEXt/zTXt - - text_ptr[i].lang - language of comment (empty - string for unknown). - - text_ptr[i].lang_key - keyword in UTF-8 - (empty string for unknown). - - Note that the itxt_length, lang, and lang_key - members of the text_ptr structure only exist when the - library is built with iTXt chunk support. Prior to - libpng-1.4.0 the library was built by default without - iTXt support. Also note that when iTXt is supported, - they contain NULL pointers when the "compression" - field contains PNG_TEXT_COMPRESSION_NONE or - PNG_TEXT_COMPRESSION_zTXt. - - num_text - number of comments (same as - num_comments; you can put NULL here - to avoid the duplication) - - Note while png_set_text() will accept text, language, - and translated keywords that can be NULL pointers, the - structure returned by png_get_text will always contain - regular zero-terminated C strings. They might be - empty strings but they will never be NULL pointers. - - num_spalettes = png_get_sPLT(png_ptr, info_ptr, - &palette_ptr); - - num_spalettes - number of sPLT chunks read. - - palette_ptr - array of palette structures holding - contents of one or more sPLT chunks - read. - - png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y, - &unit_type); - - offset_x - positive offset from the left edge - of the screen (can be negative) - - offset_y - positive offset from the top edge - of the screen (can be negative) - - unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER - - png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, - &unit_type); - - res_x - pixels/unit physical resolution in - x direction - - res_y - pixels/unit physical resolution in - x direction - - unit_type - PNG_RESOLUTION_UNKNOWN, - PNG_RESOLUTION_METER - - png_get_sCAL(png_ptr, info_ptr, &unit, &width, - &height) - - unit - physical scale units (an integer) - - width - width of a pixel in physical scale units - - height - height of a pixel in physical scale units - (width and height are doubles) - - png_get_sCAL_s(png_ptr, info_ptr, &unit, &width, - &height) - - unit - physical scale units (an integer) - - width - width of a pixel in physical scale units - (expressed as a string) - - height - height of a pixel in physical scale units - (width and height are strings like "2.54") - - num_unknown_chunks = png_get_unknown_chunks(png_ptr, - info_ptr, &unknowns) - - unknowns - array of png_unknown_chunk - structures holding unknown chunks - - unknowns[i].name - name of unknown chunk - - unknowns[i].data - data of unknown chunk - - unknowns[i].size - size of unknown chunk's data - - unknowns[i].location - position of chunk in file - - The value of "i" corresponds to the order in which the - chunks were read from the PNG file or inserted with the - png_set_unknown_chunks() function. - - The value of "location" is a bitwise "or" of - - PNG_HAVE_IHDR (0x01) - PNG_HAVE_PLTE (0x02) - PNG_AFTER_IDAT (0x08) - -The data from the pHYs chunk can be retrieved in several convenient -forms: - - res_x = png_get_x_pixels_per_meter(png_ptr, - info_ptr) - - res_y = png_get_y_pixels_per_meter(png_ptr, - info_ptr) - - res_x_and_y = png_get_pixels_per_meter(png_ptr, - info_ptr) - - res_x = png_get_x_pixels_per_inch(png_ptr, - info_ptr) - - res_y = png_get_y_pixels_per_inch(png_ptr, - info_ptr) - - res_x_and_y = png_get_pixels_per_inch(png_ptr, - info_ptr) - - aspect_ratio = png_get_pixel_aspect_ratio(png_ptr, - info_ptr) - - Each of these returns 0 [signifying "unknown"] if - the data is not present or if res_x is 0; - res_x_and_y is 0 if res_x != res_y - - Note that because of the way the resolutions are - stored internally, the inch conversions won't - come out to exactly even number. For example, - 72 dpi is stored as 0.28346 pixels/meter, and - when this is retrieved it is 71.9988 dpi, so - be sure to round the returned value appropriately - if you want to display a reasonable-looking result. - -The data from the oFFs chunk can be retrieved in several convenient -forms: - - x_offset = png_get_x_offset_microns(png_ptr, info_ptr); - - y_offset = png_get_y_offset_microns(png_ptr, info_ptr); - - x_offset = png_get_x_offset_inches(png_ptr, info_ptr); - - y_offset = png_get_y_offset_inches(png_ptr, info_ptr); - - Each of these returns 0 [signifying "unknown" if both - x and y are 0] if the data is not present or if the - chunk is present but the unit is the pixel. The - remark about inexact inch conversions applies here - as well, because a value in inches can't always be - converted to microns and back without some loss - of precision. - -For more information, see the -PNG specification for chunk contents. Be careful with trusting -rowbytes, as some of the transformations could increase the space -needed to hold a row (expand, filler, gray_to_rgb, etc.). -See png_read_update_info(), below. - -A quick word about text_ptr and num_text. PNG stores comments in -keyword/text pairs, one pair per chunk, with no limit on the number -of text chunks, and a 2^31 byte limit on their size. While there are -suggested keywords, there is no requirement to restrict the use to these -strings. It is strongly suggested that keywords and text be sensible -to humans (that's the point), so don't use abbreviations. Non-printing -symbols are not allowed. See the PNG specification for more details. -There is also no requirement to have text after the keyword. - -Keywords should be limited to 79 Latin-1 characters without leading or -trailing spaces, but non-consecutive spaces are allowed within the -keyword. It is possible to have the same keyword any number of times. -The text_ptr is an array of png_text structures, each holding a -pointer to a language string, a pointer to a keyword and a pointer to -a text string. The text string, language code, and translated -keyword may be empty or NULL pointers. The keyword/text -pairs are put into the array in the order that they are received. -However, some or all of the text chunks may be after the image, so, to -make sure you have read all the text chunks, don't mess with these -until after you read the stuff after the image. This will be -mentioned again below in the discussion that goes with png_read_end(). - -Input transformations - -After you've read the header information, you can set up the library -to handle any special transformations of the image data. The various -ways to transform the data will be described in the order that they -should occur. This is important, as some of these change the color -type and/or bit depth of the data, and some others only work on -certain color types and bit depths. - -Transformations you request are ignored if they don't have any meaning for a -particular input data format. However some transformations can have an effect -as a result of a previous transformation. If you specify a contradictory set of -transformations, for example both adding and removing the alpha channel, you -cannot predict the final result. - -The color used for the transparency values should be supplied in the same -format/depth as the current image data. It is stored in the same format/depth -as the image data in a tRNS chunk, so this is what libpng expects for this data. - -The color used for the background value depends on the need_expand argument as -described below. - -Data will be decoded into the supplied row buffers packed into bytes -unless the library has been told to transform it into another format. -For example, 4 bit/pixel paletted or grayscale data will be returned -2 pixels/byte with the leftmost pixel in the high-order bits of the -byte, unless png_set_packing() is called. 8-bit RGB data will be stored -in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha() -is called to insert filler bytes, either before or after each RGB triplet. -16-bit RGB data will be returned RRGGBB RRGGBB, with the most significant -byte of the color value first, unless png_set_scale_16() is called to -transform it to regular RGB RGB triplets, or png_set_filler() or -png_set_add alpha() is called to insert filler bytes, either before or -after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can -be modified with png_set_filler(), png_set_add_alpha(), png_set_strip_16(), -or png_set_scale_16(). - -The following code transforms grayscale images of less than 8 to 8 bits, -changes paletted images to RGB, and adds a full alpha channel if there is -transparency information in a tRNS chunk. This is most useful on -grayscale images with bit depths of 2 or 4 or if there is a multiple-image -viewing application that wishes to treat all images in the same way. - - if (color_type == PNG_COLOR_TYPE_PALETTE) - png_set_palette_to_rgb(png_ptr); - - if (png_get_valid(png_ptr, info_ptr, - PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr); - - if (color_type == PNG_COLOR_TYPE_GRAY && - bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr); - -The first two functions are actually aliases for png_set_expand(), added -in libpng version 1.0.4, with the function names expanded to improve code -readability. In some future version they may actually do different -things. - -As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was -added. It expands the sample depth without changing tRNS to alpha. - -As of libpng version 1.5.2, png_set_expand_16() was added. It behaves as -png_set_expand(); however, the resultant channels have 16 bits rather than 8. -Use this when the output color or gray channels are made linear to avoid fairly -severe accuracy loss. - - if (bit_depth < 16) - png_set_expand_16(png_ptr); - -PNG can have files with 16 bits per channel. If you only can handle -8 bits per channel, this will strip the pixels down to 8-bit. - - if (bit_depth == 16) -#if PNG_LIBPNG_VER >= 10504 - png_set_scale_16(png_ptr); -#else - png_set_strip_16(png_ptr); -#endif - -(The more accurate "png_set_scale_16()" API became available in libpng version -1.5.4). - -If you need to process the alpha channel on the image separately from the image -data (for example if you convert it to a bitmap mask) it is possible to have -libpng strip the channel leaving just RGB or gray data: - - if (color_type & PNG_COLOR_MASK_ALPHA) - png_set_strip_alpha(png_ptr); - -If you strip the alpha channel you need to find some other way of dealing with -the information. If, instead, you want to convert the image to an opaque -version with no alpha channel use png_set_background; see below. - -As of libpng version 1.5.2, almost all useful expansions are supported, the -major ommissions are conversion of grayscale to indexed images (which can be -done trivially in the application) and conversion of indexed to grayscale (which -can be done by a trivial manipulation of the palette.) - -In the following table, the 01 means grayscale with depth<8, 31 means -indexed with depth<8, other numerals represent the color type, "T" means -the tRNS chunk is present, A means an alpha channel is present, and O -means tRNS or alpha is present but all pixels in the image are opaque. - - FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O - TO - 01 - [G] - - - - - - - - - - - - - - 31 [Q] Q [Q] [Q] [Q] Q Q Q Q Q Q [Q] [Q] Q Q - 0 1 G + . . G G G G G G B B GB GB - 0T lt Gt t + . Gt G G Gt G G Bt Bt GBt GBt - 0O lt Gt t . + Gt Gt G Gt Gt G Bt Bt GBt GBt - 2 C P C C C + . . C - - CB CB B B - 2T Ct - Ct C C t + t - - - CBt CBt Bt Bt - 2O Ct - Ct C C t t + - - - CBt CBt Bt Bt - 3 [Q] p [Q] [Q] [Q] Q Q Q + . . [Q] [Q] Q Q - 3T [Qt] p [Qt][Q] [Q] Qt Qt Qt t + t [Qt][Qt] Qt Qt - 3O [Qt] p [Qt][Q] [Q] Qt Qt Qt t t + [Qt][Qt] Qt Qt - 4A lA G A T T GA GT GT GA GT GT + BA G GBA - 4O lA GBA A T T GA GT GT GA GT GT BA + GBA G - 6A CA PA CA C C A T tT PA P P C CBA + BA - 6O CA PBA CA C C A tT T PA P P CBA C BA + - -Within the matrix, - "+" identifies entries where 'from' and 'to' are the same. - "-" means the transformation is not supported. - "." means nothing is necessary (a tRNS chunk can just be ignored). - "t" means the transformation is obtained by png_set_tRNS. - "A" means the transformation is obtained by png_set_add_alpha(). - "X" means the transformation is obtained by png_set_expand(). - "1" means the transformation is obtained by - png_set_expand_gray_1_2_4_to_8() (and by png_set_expand() - if there is no transparency in the original or the final - format). - "C" means the transformation is obtained by png_set_gray_to_rgb(). - "G" means the transformation is obtained by png_set_rgb_to_gray(). - "P" means the transformation is obtained by - png_set_expand_palette_to_rgb(). - "p" means the transformation is obtained by png_set_packing(). - "Q" means the transformation is obtained by png_set_quantize(). - "T" means the transformation is obtained by - png_set_tRNS_to_alpha(). - "B" means the transformation is obtained by - png_set_background(), or png_strip_alpha(). - -When an entry has multiple transforms listed all are required to cause the -right overall transformation. When two transforms are separated by a comma -either will do the job. When transforms are enclosed in [] the transform should -do the job but this is currently unimplemented - a different format will result -if the suggested transformations are used. - -In PNG files, the alpha channel in an image -is the level of opacity. If you need the alpha channel in an image to -be the level of transparency instead of opacity, you can invert the -alpha channel (or the tRNS chunk data) after it's read, so that 0 is -fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit -images) is fully transparent, with - - png_set_invert_alpha(png_ptr); - -PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as -they can, resulting in, for example, 8 pixels per byte for 1 bit -files. This code expands to 1 pixel per byte without changing the -values of the pixels: - - if (bit_depth < 8) - png_set_packing(png_ptr); - -PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels -stored in a PNG image have been "scaled" or "shifted" up to the next -higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] -to 8 bits/sample in the range [0, 255]). However, it is also possible -to convert the PNG pixel data back to the original bit depth of the -image. This call reduces the pixels back down to the original bit depth: - - png_color_8p sig_bit; - - if (png_get_sBIT(png_ptr, info_ptr, &sig_bit)) - png_set_shift(png_ptr, sig_bit); - -PNG files store 3-color pixels in red, green, blue order. This code -changes the storage of the pixels to blue, green, red: - - if (color_type == PNG_COLOR_TYPE_RGB || - color_type == PNG_COLOR_TYPE_RGB_ALPHA) - png_set_bgr(png_ptr); - -PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them -into 4 or 8 bytes for windowing systems that need them in this format: - - if (color_type == PNG_COLOR_TYPE_RGB) - png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE); - -where "filler" is the 8 or 16-bit number to fill with, and the location is -either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether -you want the filler before the RGB or after. This transformation -does not affect images that already have full alpha channels. To add an -opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which -will generate RGBA pixels. - -Note that png_set_filler() does not change the color type. If you want -to do that, you can add a true alpha channel with - - if (color_type == PNG_COLOR_TYPE_RGB || - color_type == PNG_COLOR_TYPE_GRAY) - png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER); - -where "filler" contains the alpha value to assign to each pixel. -This function was added in libpng-1.2.7. - -If you are reading an image with an alpha channel, and you need the -data as ARGB instead of the normal PNG format RGBA: - - if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) - png_set_swap_alpha(png_ptr); - -For some uses, you may want a grayscale image to be represented as -RGB. This code will do that conversion: - - if (color_type == PNG_COLOR_TYPE_GRAY || - color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - png_set_gray_to_rgb(png_ptr); - -Conversely, you can convert an RGB or RGBA image to grayscale or grayscale -with alpha. - - if (color_type == PNG_COLOR_TYPE_RGB || - color_type == PNG_COLOR_TYPE_RGB_ALPHA) - png_set_rgb_to_gray(png_ptr, error_action, - double red_weight, double green_weight); - - error_action = 1: silently do the conversion - - error_action = 2: issue a warning if the original - image has any pixel where - red != green or red != blue - - error_action = 3: issue an error and abort the - conversion if the original - image has any pixel where - red != green or red != blue - - red_weight: weight of red component - - green_weight: weight of green component - If either weight is negative, default - weights are used. - -In the corresponding fixed point API the red_weight and green_weight values are -simply scaled by 100,000: - - png_set_rgb_to_gray(png_ptr, error_action, - png_fixed_point red_weight, - png_fixed_point green_weight); - -If you have set error_action = 1 or 2, you can -later check whether the image really was gray, after processing -the image rows, with the png_get_rgb_to_gray_status(png_ptr) function. -It will return a png_byte that is zero if the image was gray or -1 if there were any non-gray pixels. Background and sBIT data -will be silently converted to grayscale, using the green channel -data for sBIT, regardless of the error_action setting. - -The default values come from the PNG file cHRM chunk if present; otherwise, the -defaults correspond to the ITU-R recommendation 709, and also the sRGB color -space, as recommended in the Charles Poynton's Colour FAQ, -, in section 9: - - - - Y = 0.2126 * R + 0.7152 * G + 0.0722 * B - -Previous versions of this document, 1998 through 2002, recommended a slightly -different formula: - - Y = 0.212671 * R + 0.715160 * G + 0.072169 * B - -Libpng uses an integer approximation: - - Y = (6968 * R + 23434 * G + 2366 * B)/32768 - -The calculation is done in a linear colorspace, if the image gamma -can be determined. - -The png_set_background() function has been described already; it tells libpng to -composite images with alpha or simple transparency against the supplied -background color. For compatibility with versions of libpng earlier than -libpng-1.5.4 it is recommended that you call the function after reading the file -header, even if you don't want to use the color in a bKGD chunk, if one exists. - -If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid), -you may use this color, or supply another color more suitable for -the current display (e.g., the background color from a web page). You -need to tell libpng how the color is represented, both the format of the -component values in the color (the number of bits) and the gamma encoding of the -color. The function takes two arguments, background_gamma_mode and need_expand -to convey this information; however, only two combinations are likely to be -useful: - - png_color_16 my_background; - png_color_16p image_background; - - if (png_get_bKGD(png_ptr, info_ptr, &image_background)) - png_set_background(png_ptr, image_background, - PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1); - else - png_set_background(png_ptr, &my_background, - PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1); - -The second call was described above - my_background is in the format of the -final, display, output produced by libpng. Because you now know the format of -the PNG it is possible to avoid the need to choose either 8-bit or 16-bit -output and to retain palette images (the palette colors will be modified -appropriately and the tRNS chunk removed.) However, if you are doing this, -take great care not to ask for transformations without checking first that -they apply! - -In the first call the background color has the original bit depth and color type -of the PNG file. So, for palette images the color is supplied as a palette -index and for low bit greyscale images the color is a reduced bit value in -image_background->gray. - -If you didn't call png_set_gamma() before reading the file header, for example -if you need your code to remain compatible with older versions of libpng prior -to libpng-1.5.4, this is the place to call it. - -Do not call it if you called png_set_alpha_mode(); doing so will damage the -settings put in place by png_set_alpha_mode(). (If png_set_alpha_mode() is -supported then you can certainly do png_set_gamma() before reading the PNG -header.) - -This API unconditionally sets the screen and file gamma values, so it will -override the value in the PNG file unless it is called before the PNG file -reading starts. For this reason you must always call it with the PNG file -value when you call it in this position: - - if (png_get_gAMA(png_ptr, info_ptr, &file_gamma)) - png_set_gamma(png_ptr, screen_gamma, file_gamma); - - else - png_set_gamma(png_ptr, screen_gamma, 0.45455); - -If you need to reduce an RGB file to a paletted file, or if a paletted -file has more entries then will fit on your screen, png_set_quantize() -will do that. Note that this is a simple match quantization that merely -finds the closest color available. This should work fairly well with -optimized palettes, but fairly badly with linear color cubes. If you -pass a palette that is larger than maximum_colors, the file will -reduce the number of colors in the palette so it will fit into -maximum_colors. If there is a histogram, libpng will use it to make -more intelligent choices when reducing the palette. If there is no -histogram, it may not do as good a job. - - if (color_type & PNG_COLOR_MASK_COLOR) - { - if (png_get_valid(png_ptr, info_ptr, - PNG_INFO_PLTE)) - { - png_uint_16p histogram = NULL; - - png_get_hIST(png_ptr, info_ptr, - &histogram); - png_set_quantize(png_ptr, palette, num_palette, - max_screen_colors, histogram, 1); - } - - else - { - png_color std_color_cube[MAX_SCREEN_COLORS] = - { ... colors ... }; - - png_set_quantize(png_ptr, std_color_cube, - MAX_SCREEN_COLORS, MAX_SCREEN_COLORS, - NULL,0); - } - } - -PNG files describe monochrome as black being zero and white being one. -The following code will reverse this (make black be one and white be -zero): - - if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY) - png_set_invert_mono(png_ptr); - -This function can also be used to invert grayscale and gray-alpha images: - - if (color_type == PNG_COLOR_TYPE_GRAY || - color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - png_set_invert_mono(png_ptr); - -PNG files store 16-bit pixels in network byte order (big-endian, -ie. most significant bits first). This code changes the storage to the -other way (little-endian, i.e. least significant bits first, the -way PCs store them): - - if (bit_depth == 16) - png_set_swap(png_ptr); - -If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you -need to change the order the pixels are packed into bytes, you can use: - - if (bit_depth < 8) - png_set_packswap(png_ptr); - -Finally, you can write your own transformation function if none of -the existing ones meets your needs. This is done by setting a callback -with - - png_set_read_user_transform_fn(png_ptr, - read_transform_fn); - -You must supply the function - - void read_transform_fn(png_structp png_ptr, png_row_infop - row_info, png_bytep data) - -See pngtest.c for a working example. Your function will be called -after all of the other transformations have been processed. Take care with -interlaced images if you do the interlace yourself - the width of the row is the -width in 'row_info', not the overall image width. - -If supported, libpng provides two information routines that you can use to find -where you are in processing the image: - - png_get_current_pass_number(png_structp png_ptr); - png_get_current_row_number(png_structp png_ptr); - -Don't try using these outside a transform callback - firstly they are only -supported if user transforms are supported, secondly they may well return -unexpected results unless the row is actually being processed at the moment they -are called. - -With interlaced -images the value returned is the row in the input sub-image image. Use -PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to -find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass). - -The discussion of interlace handling above contains more information on how to -use these values. - -You can also set up a pointer to a user structure for use by your -callback function, and you can inform libpng that your transform -function will change the number of channels or bit depth with the -function - - png_set_user_transform_info(png_ptr, user_ptr, - user_depth, user_channels); - -The user's application, not libpng, is responsible for allocating and -freeing any memory required for the user structure. - -You can retrieve the pointer via the function -png_get_user_transform_ptr(). For example: - - voidp read_user_transform_ptr = - png_get_user_transform_ptr(png_ptr); - -The last thing to handle is interlacing; this is covered in detail below, -but you must call the function here if you want libpng to handle expansion -of the interlaced image. - - number_of_passes = png_set_interlace_handling(png_ptr); - -After setting the transformations, libpng can update your png_info -structure to reflect any transformations you've requested with this -call. - - png_read_update_info(png_ptr, info_ptr); - -This is most useful to update the info structure's rowbytes -field so you can use it to allocate your image memory. This function -will also update your palette with the correct screen_gamma and -background if these have been given with the calls above. You may -only call png_read_update_info() once with a particular info_ptr. - -After you call png_read_update_info(), you can allocate any -memory you need to hold the image. The row data is simply -raw byte data for all forms of images. As the actual allocation -varies among applications, no example will be given. If you -are allocating one large chunk, you will need to build an -array of pointers to each row, as it will be needed for some -of the functions below. - -Remember: Before you call png_read_update_info(), the png_get_*() -functions return the values corresponding to the original PNG image. -After you call png_read_update_info the values refer to the image -that libpng will output. Consequently you must call all the png_set_ -functions before you call png_read_update_info(). This is particularly -important for png_set_interlace_handling() - if you are going to call -png_read_update_info() you must call png_set_interlace_handling() before -it unless you want to receive interlaced output. - -Reading image data - -After you've allocated memory, you can read the image data. -The simplest way to do this is in one function call. If you are -allocating enough memory to hold the whole image, you can just -call png_read_image() and libpng will read in all the image data -and put it in the memory area supplied. You will need to pass in -an array of pointers to each row. - -This function automatically handles interlacing, so you don't -need to call png_set_interlace_handling() (unless you call -png_read_update_info()) or call this function multiple times, or any -of that other stuff necessary with png_read_rows(). - - png_read_image(png_ptr, row_pointers); - -where row_pointers is: - - png_bytep row_pointers[height]; - -You can point to void or char or whatever you use for pixels. - -If you don't want to read in the whole image at once, you can -use png_read_rows() instead. If there is no interlacing (check -interlace_type == PNG_INTERLACE_NONE), this is simple: - - png_read_rows(png_ptr, row_pointers, NULL, - number_of_rows); - -where row_pointers is the same as in the png_read_image() call. - -If you are doing this just one row at a time, you can do this with -a single row_pointer instead of an array of row_pointers: - - png_bytep row_pointer = row; - png_read_row(png_ptr, row_pointer, NULL); - -If the file is interlaced (interlace_type != 0 in the IHDR chunk), things -get somewhat harder. The only current (PNG Specification version 1.2) -interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7); -a somewhat complicated 2D interlace scheme, known as Adam7, that -breaks down an image into seven smaller images of varying size, based -on an 8x8 grid. This number is defined (from libpng 1.5) as -PNG_INTERLACE_ADAM7_PASSES in png.h - -libpng can fill out those images or it can give them to you "as is". -It is almost always better to have libpng handle the interlacing for you. -If you want the images filled out, there are two ways to do that. The one -mentioned in the PNG specification is to expand each pixel to cover -those pixels that have not been read yet (the "rectangle" method). -This results in a blocky image for the first pass, which gradually -smooths out as more pixels are read. The other method is the "sparkle" -method, where pixels are drawn only in their final locations, with the -rest of the image remaining whatever colors they were initialized to -before the start of the read. The first method usually looks better, -but tends to be slower, as there are more pixels to put in the rows. - -If, as is likely, you want libpng to expand the images, call this before -calling png_start_read_image() or png_read_update_info(): - - if (interlace_type == PNG_INTERLACE_ADAM7) - number_of_passes - = png_set_interlace_handling(png_ptr); - -This will return the number of passes needed. Currently, this is seven, -but may change if another interlace type is added. This function can be -called even if the file is not interlaced, where it will return one pass. -You then need to read the whole image 'number_of_passes' times. Each time -will distribute the pixels from the current pass to the correct place in -the output image, so you need to supply the same rows to png_read_rows in -each pass. - -If you are not going to display the image after each pass, but are -going to wait until the entire image is read in, use the sparkle -effect. This effect is faster and the end result of either method -is exactly the same. If you are planning on displaying the image -after each pass, the "rectangle" effect is generally considered the -better looking one. - -If you only want the "sparkle" effect, just call png_read_rows() as -normal, with the third parameter NULL. Make sure you make pass over -the image number_of_passes times, and you don't change the data in the -rows between calls. You can change the locations of the data, just -not the data. Each pass only writes the pixels appropriate for that -pass, and assumes the data from previous passes is still valid. - - png_read_rows(png_ptr, row_pointers, NULL, - number_of_rows); - -If you only want the first effect (the rectangles), do the same as -before except pass the row buffer in the third parameter, and leave -the second parameter NULL. - - png_read_rows(png_ptr, NULL, row_pointers, - number_of_rows); - -If you don't want libpng to handle the interlacing details, just call -png_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images. -Each of the images is a valid image by itself; however, you will almost -certainly need to distribute the pixels from each sub-image to the -correct place. This is where everything gets very tricky. - -If you want to retrieve the separate images you must pass the correct -number of rows to each successive call of png_read_rows(). The calculation -gets pretty complicated for small images, where some sub-images may -not even exist because either their width or height ends up zero. -libpng provides two macros to help you in 1.5 and later versions: - - png_uint_32 width = PNG_PASS_COLS(image_width, pass_number); - png_uint_32 height = PNG_PASS_ROWS(image_height, pass_number); - -Respectively these tell you the width and height of the sub-image -corresponding to the numbered pass. 'pass' is in in the range 0 to 6 - -this can be confusing because the specification refers to the same passes -as 1 to 7! Be careful, you must check both the width and height before -calling png_read_rows() and not call it for that pass if either is zero. - -You can, of course, read each sub-image row by row. If you want to -produce optimal code to make a pixel-by-pixel transformation of an -interlaced image this is the best approach; read each row of each pass, -transform it, and write it out to a new interlaced image. - -If you want to de-interlace the image yourself libpng provides further -macros to help that tell you where to place the pixels in the output image. -Because the interlacing scheme is rectangular - sub-image pixels are always -arranged on a rectangular grid - all you need to know for each pass is the -starting column and row in the output image of the first pixel plus the -spacing between each pixel. As of libpng 1.5 there are four macros to -retrieve this information: - - png_uint_32 x = PNG_PASS_START_COL(pass); - png_uint_32 y = PNG_PASS_START_ROW(pass); - png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass); - png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass); - -These allow you to write the obvious loop: - - png_uint_32 input_y = 0; - png_uint_32 output_y = PNG_PASS_START_ROW(pass); - - while (output_y < output_image_height) - { - png_uint_32 input_x = 0; - png_uint_32 output_x = PNG_PASS_START_COL(pass); - - while (output_x < output_image_width) - { - image[output_y][output_x] = - subimage[pass][input_y][input_x++]; - - output_x += xStep; - } - - ++input_y; - output_y += yStep; - } - -Notice that the steps between successive output rows and columns are -returned as shifts. This is possible because the pixels in the subimages -are always a power of 2 apart - 1, 2, 4 or 8 pixels - in the original -image. In practice you may need to directly calculate the output coordinate -given an input coordinate. libpng provides two further macros for this -purpose: - - png_uint_32 output_x = PNG_COL_FROM_PASS_COL(input_x, pass); - png_uint_32 output_y = PNG_ROW_FROM_PASS_ROW(input_y, pass); - -Finally a pair of macros are provided to tell you if a particular image -row or column appears in a given pass: - - int col_in_pass = PNG_COL_IN_INTERLACE_PASS(output_x, pass); - int row_in_pass = PNG_ROW_IN_INTERLACE_PASS(output_y, pass); - -Bear in mind that you will probably also need to check the width and height -of the pass in addition to the above to be sure the pass even exists! - -With any luck you are convinced by now that you don't want to do your own -interlace handling. In reality normally the only good reason for doing this -is if you are processing PNG files on a pixel-by-pixel basis and don't want -to load the whole file into memory when it is interlaced. - -libpng includes a test program, pngvalid, that illustrates reading and -writing of interlaced images. If you can't get interlacing to work in your -code and don't want to leave it to libpng (the recommended approach), see -how pngvalid.c does it. - -Finishing a sequential read - -After you are finished reading the image through the -low-level interface, you can finish reading the file. If you are -interested in comments or time, which may be stored either before or -after the image data, you should pass the separate png_info struct if -you want to keep the comments from before and after the image -separate. - - png_infop end_info = png_create_info_struct(png_ptr); - - if (!end_info) - { - png_destroy_read_struct(&png_ptr, &info_ptr, - (png_infopp)NULL); - return (ERROR); - } - - png_read_end(png_ptr, end_info); - -If you are not interested, you should still call png_read_end() -but you can pass NULL, avoiding the need to create an end_info structure. - - png_read_end(png_ptr, (png_infop)NULL); - -If you don't call png_read_end(), then your file pointer will be -left pointing to the first chunk after the last IDAT, which is probably -not what you want if you expect to read something beyond the end of -the PNG datastream. - -When you are done, you can free all memory allocated by libpng like this: - - png_destroy_read_struct(&png_ptr, &info_ptr, - &end_info); - -or, if you didn't create an end_info structure, - - png_destroy_read_struct(&png_ptr, &info_ptr, - (png_infopp)NULL); - -It is also possible to individually free the info_ptr members that -point to libpng-allocated storage with the following function: - - png_free_data(png_ptr, info_ptr, mask, seq) - - mask - identifies data to be freed, a mask - containing the bitwise OR of one or - more of - PNG_FREE_PLTE, PNG_FREE_TRNS, - PNG_FREE_HIST, PNG_FREE_ICCP, - PNG_FREE_PCAL, PNG_FREE_ROWS, - PNG_FREE_SCAL, PNG_FREE_SPLT, - PNG_FREE_TEXT, PNG_FREE_UNKN, - or simply PNG_FREE_ALL - - seq - sequence number of item to be freed - (-1 for all items) - -This function may be safely called when the relevant storage has -already been freed, or has not yet been allocated, or was allocated -by the user and not by libpng, and will in those cases do nothing. -The "seq" parameter is ignored if only one item of the selected data -type, such as PLTE, is allowed. If "seq" is not -1, and multiple items -are allowed for the data type identified in the mask, such as text or -sPLT, only the n'th item in the structure is freed, where n is "seq". - -The default behavior is only to free data that was allocated internally -by libpng. This can be changed, so that libpng will not free the data, -or so that it will free data that was allocated by the user with png_malloc() -or png_calloc() and passed in via a png_set_*() function, with - - png_data_freer(png_ptr, info_ptr, freer, mask) - - freer - one of - PNG_DESTROY_WILL_FREE_DATA - PNG_SET_WILL_FREE_DATA - PNG_USER_WILL_FREE_DATA - - mask - which data elements are affected - same choices as in png_free_data() - -This function only affects data that has already been allocated. -You can call this function after reading the PNG data but before calling -any png_set_*() functions, to control whether the user or the png_set_*() -function is responsible for freeing any existing data that might be present, -and again after the png_set_*() functions to control whether the user -or png_destroy_*() is supposed to free the data. When the user assumes -responsibility for libpng-allocated data, the application must use -png_free() to free it, and when the user transfers responsibility to libpng -for data that the user has allocated, the user must have used png_malloc() -or png_calloc() to allocate it. - -If you allocated your row_pointers in a single block, as suggested above in -the description of the high level read interface, you must not transfer -responsibility for freeing it to the png_set_rows or png_read_destroy function, -because they would also try to free the individual row_pointers[i]. - -If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword -separately, do not transfer responsibility for freeing text_ptr to libpng, -because when libpng fills a png_text structure it combines these members with -the key member, and png_free_data() will free only text_ptr.key. Similarly, -if you transfer responsibility for free'ing text_ptr from libpng to your -application, your application must not separately free those members. - -The png_free_data() function will turn off the "valid" flag for anything -it frees. If you need to turn the flag off for a chunk that was freed by -your application instead of by libpng, you can use - - png_set_invalid(png_ptr, info_ptr, mask); - - mask - identifies the chunks to be made invalid, - containing the bitwise OR of one or - more of - PNG_INFO_gAMA, PNG_INFO_sBIT, - PNG_INFO_cHRM, PNG_INFO_PLTE, - PNG_INFO_tRNS, PNG_INFO_bKGD, - PNG_INFO_hIST, PNG_INFO_pHYs, - PNG_INFO_oFFs, PNG_INFO_tIME, - PNG_INFO_pCAL, PNG_INFO_sRGB, - PNG_INFO_iCCP, PNG_INFO_sPLT, - PNG_INFO_sCAL, PNG_INFO_IDAT - -For a more compact example of reading a PNG image, see the file example.c. - -Reading PNG files progressively - -The progressive reader is slightly different then the non-progressive -reader. Instead of calling png_read_info(), png_read_rows(), and -png_read_end(), you make one call to png_process_data(), which calls -callbacks when it has the info, a row, or the end of the image. You -set up these callbacks with png_set_progressive_read_fn(). You don't -have to worry about the input/output functions of libpng, as you are -giving the library the data directly in png_process_data(). I will -assume that you have read the section on reading PNG files above, -so I will only highlight the differences (although I will show -all of the code). - -png_structp png_ptr; -png_infop info_ptr; - - /* An example code fragment of how you would - initialize the progressive reader in your - application. */ - int - initialize_png_reader() - { - png_ptr = png_create_read_struct - (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, - user_error_fn, user_warning_fn); - - if (!png_ptr) - return (ERROR); - - info_ptr = png_create_info_struct(png_ptr); - - if (!info_ptr) - { - png_destroy_read_struct(&png_ptr, - (png_infopp)NULL, (png_infopp)NULL); - return (ERROR); - } - - if (setjmp(png_jmpbuf(png_ptr))) - { - png_destroy_read_struct(&png_ptr, &info_ptr, - (png_infopp)NULL); - return (ERROR); - } - - /* This one's new. You can provide functions - to be called when the header info is valid, - when each row is completed, and when the image - is finished. If you aren't using all functions, - you can specify NULL parameters. Even when all - three functions are NULL, you need to call - png_set_progressive_read_fn(). You can use - any struct as the user_ptr (cast to a void pointer - for the function call), and retrieve the pointer - from inside the callbacks using the function - - png_get_progressive_ptr(png_ptr); - - which will return a void pointer, which you have - to cast appropriately. - */ - png_set_progressive_read_fn(png_ptr, (void *)user_ptr, - info_callback, row_callback, end_callback); - - return 0; - } - - /* A code fragment that you call as you receive blocks - of data */ - int - process_data(png_bytep buffer, png_uint_32 length) - { - if (setjmp(png_jmpbuf(png_ptr))) - { - png_destroy_read_struct(&png_ptr, &info_ptr, - (png_infopp)NULL); - return (ERROR); - } - - /* This one's new also. Simply give it a chunk - of data from the file stream (in order, of - course). On machines with segmented memory - models machines, don't give it any more than - 64K. The library seems to run fine with sizes - of 4K. Although you can give it much less if - necessary (I assume you can give it chunks of - 1 byte, I haven't tried less then 256 bytes - yet). When this function returns, you may - want to display any rows that were generated - in the row callback if you don't already do - so there. - */ - png_process_data(png_ptr, info_ptr, buffer, length); - - /* At this point you can call png_process_data_skip if - you want to handle data the library will skip yourself; - it simply returns the number of bytes to skip (and stops - libpng skipping that number of bytes on the next - png_process_data call). - return 0; - } - - /* This function is called (as set by - png_set_progressive_read_fn() above) when enough data - has been supplied so all of the header has been - read. - */ - void - info_callback(png_structp png_ptr, png_infop info) - { - /* Do any setup here, including setting any of - the transformations mentioned in the Reading - PNG files section. For now, you _must_ call - either png_start_read_image() or - png_read_update_info() after all the - transformations are set (even if you don't set - any). You may start getting rows before - png_process_data() returns, so this is your - last chance to prepare for that. - - This is where you turn on interlace handling, - assuming you don't want to do it yourself. - - If you need to you can stop the processing of - your original input data at this point by calling - png_process_data_pause. This returns the number - of unprocessed bytes from the last png_process_data - call - it is up to you to ensure that the next call - sees these bytes again. If you don't want to bother - with this you can get libpng to cache the unread - bytes by setting the 'save' parameter (see png.h) but - then libpng will have to copy the data internally. - */ - } - - /* This function is called when each row of image - data is complete */ - void - row_callback(png_structp png_ptr, png_bytep new_row, - png_uint_32 row_num, int pass) - { - /* If the image is interlaced, and you turned - on the interlace handler, this function will - be called for every row in every pass. Some - of these rows will not be changed from the - previous pass. When the row is not changed, - the new_row variable will be NULL. The rows - and passes are called in order, so you don't - really need the row_num and pass, but I'm - supplying them because it may make your life - easier. - - If you did not turn on interlace handling then - the callback is called for each row of each - sub-image when the image is interlaced. In this - case 'row_num' is the row in the sub-image, not - the row in the output image as it is in all other - cases. - - For the non-NULL rows of interlaced images when - you have switched on libpng interlace handling, - you must call png_progressive_combine_row() - passing in the row and the old row. You can - call this function for NULL rows (it will just - return) and for non-interlaced images (it just - does the memcpy for you) if it will make the - code easier. Thus, you can just do this for - all cases if you switch on interlace handling; - */ - - png_progressive_combine_row(png_ptr, old_row, - new_row); - - /* where old_row is what was displayed for - previously for the row. Note that the first - pass (pass == 0, really) will completely cover - the old row, so the rows do not have to be - initialized. After the first pass (and only - for interlaced images), you will have to pass - the current row, and the function will combine - the old row and the new row. - - You can also call png_process_data_pause in this - callback - see above. - */ - } - - void - end_callback(png_structp png_ptr, png_infop info) - { - /* This function is called after the whole image - has been read, including any chunks after the - image (up to and including the IEND). You - will usually have the same info chunk as you - had in the header, although some data may have - been added to the comments and time fields. - - Most people won't do much here, perhaps setting - a flag that marks the image as finished. - */ - } - - - -IV. Writing - -Much of this is very similar to reading. However, everything of -importance is repeated here, so you won't have to constantly look -back up in the reading section to understand writing. - -Setup - -You will want to do the I/O initialization before you get into libpng, -so if it doesn't work, you don't have anything to undo. If you are not -using the standard I/O functions, you will need to replace them with -custom writing functions. See the discussion under Customizing libpng. - - FILE *fp = fopen(file_name, "wb"); - - if (!fp) - return (ERROR); - -Next, png_struct and png_info need to be allocated and initialized. -As these can be both relatively large, you may not want to store these -on the stack, unless you have stack space to spare. Of course, you -will want to check if they return NULL. If you are also reading, -you won't want to name your read structure and your write structure -both "png_ptr"; you can call them anything you like, such as -"read_ptr" and "write_ptr". Look at pngtest.c, for example. - - png_structp png_ptr = png_create_write_struct - (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, - user_error_fn, user_warning_fn); - - if (!png_ptr) - return (ERROR); - - png_infop info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - { - png_destroy_write_struct(&png_ptr, - (png_infopp)NULL); - return (ERROR); - } - -If you want to use your own memory allocation routines, -define PNG_USER_MEM_SUPPORTED and use -png_create_write_struct_2() instead of png_create_write_struct(): - - png_structp png_ptr = png_create_write_struct_2 - (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, - user_error_fn, user_warning_fn, (png_voidp) - user_mem_ptr, user_malloc_fn, user_free_fn); - -After you have these structures, you will need to set up the -error handling. When libpng encounters an error, it expects to -longjmp() back to your routine. Therefore, you will need to call -setjmp() and pass the png_jmpbuf(png_ptr). If you -write the file from different routines, you will need to update -the png_jmpbuf(png_ptr) every time you enter a new routine that will -call a png_*() function. See your documentation of setjmp/longjmp -for your compiler for more information on setjmp/longjmp. See -the discussion on libpng error handling in the Customizing Libpng -section below for more information on the libpng error handling. - - if (setjmp(png_jmpbuf(png_ptr))) - { - png_destroy_write_struct(&png_ptr, &info_ptr); - fclose(fp); - return (ERROR); - } - ... - return; - -If you would rather avoid the complexity of setjmp/longjmp issues, -you can compile libpng with PNG_NO_SETJMP, in which case -errors will result in a call to PNG_ABORT() which defaults to abort(). - -You can #define PNG_ABORT() to a function that does something -more useful than abort(), as long as your function does not -return. - -Now you need to set up the output code. The default for libpng is to -use the C function fwrite(). If you use this, you will need to pass a -valid FILE * in the function png_init_io(). Be sure that the file is -opened in binary mode. Again, if you wish to handle writing data in -another way, see the discussion on libpng I/O handling in the Customizing -Libpng section below. - - png_init_io(png_ptr, fp); - -If you are embedding your PNG into a datastream such as MNG, and don't -want libpng to write the 8-byte signature, or if you have already -written the signature in your application, use - - png_set_sig_bytes(png_ptr, 8); - -to inform libpng that it should not write a signature. - -Write callbacks - -At this point, you can set up a callback function that will be -called after each row has been written, which you can use to control -a progress meter or the like. It's demonstrated in pngtest.c. -You must supply a function - - void write_row_callback(png_structp png_ptr, png_uint_32 row, - int pass); - { - /* put your code here */ - } - -(You can give it another name that you like instead of "write_row_callback") - -To inform libpng about your function, use - - png_set_write_status_fn(png_ptr, write_row_callback); - -When this function is called the row has already been completely processed and -it has also been written out. The 'row' and 'pass' refer to the next row to be -handled. For the -non-interlaced case the row that was just handled is simply one less than the -passed in row number, and pass will always be 0. For the interlaced case the -same applies unless the row value is 0, in which case the row just handled was -the last one from one of the preceding passes. Because interlacing may skip a -pass you cannot be sure that the preceding pass is just 'pass-1', if you really -need to know what the last pass is record (row,pass) from the callback and use -the last recorded value each time. - -As with the user transform you can find the output row using the -PNG_ROW_FROM_PASS_ROW macro. - -You now have the option of modifying how the compression library will -run. The following functions are mainly for testing, but may be useful -in some cases, like if you need to write PNG files extremely fast and -are willing to give up some compression, or if you want to get the -maximum possible compression at the expense of slower writing. If you -have no special needs in this area, let the library do what it wants by -not calling this function at all, as it has been tuned to deliver a good -speed/compression ratio. The second parameter to png_set_filter() is -the filter method, for which the only valid values are 0 (as of the -July 1999 PNG specification, version 1.2) or 64 (if you are writing -a PNG datastream that is to be embedded in a MNG datastream). The third -parameter is a flag that indicates which filter type(s) are to be tested -for each scanline. See the PNG specification for details on the specific -filter types. - - - /* turn on or off filtering, and/or choose - specific filters. You can use either a single - PNG_FILTER_VALUE_NAME or the bitwise OR of one - or more PNG_FILTER_NAME masks. - */ - png_set_filter(png_ptr, 0, - PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE | - PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB | - PNG_FILTER_UP | PNG_FILTER_VALUE_UP | - PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG | - PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH| - PNG_ALL_FILTERS); - -If an application wants to start and stop using particular filters during -compression, it should start out with all of the filters (to ensure that -the previous row of pixels will be stored in case it's needed later), -and then add and remove them after the start of compression. - -If you are writing a PNG datastream that is to be embedded in a MNG -datastream, the second parameter can be either 0 or 64. - -The png_set_compression_*() functions interface to the zlib compression -library, and should mostly be ignored unless you really know what you are -doing. The only generally useful call is png_set_compression_level() -which changes how much time zlib spends on trying to compress the image -data. See the Compression Library (zlib.h and algorithm.txt, distributed -with zlib) for details on the compression levels. - - #include zlib.h - - /* Set the zlib compression level */ - png_set_compression_level(png_ptr, - Z_BEST_COMPRESSION); - - /* Set other zlib parameters for compressing IDAT */ - png_set_compression_mem_level(png_ptr, 8); - png_set_compression_strategy(png_ptr, - Z_DEFAULT_STRATEGY); - png_set_compression_window_bits(png_ptr, 15); - png_set_compression_method(png_ptr, 8); - png_set_compression_buffer_size(png_ptr, 8192) - - /* Set zlib parameters for text compression - * If you don't call these, the parameters - * fall back on those defined for IDAT chunks - */ - png_set_text_compression_mem_level(png_ptr, 8); - png_set_text_compression_strategy(png_ptr, - Z_DEFAULT_STRATEGY); - png_set_text_compression_window_bits(png_ptr, 15); - png_set_text_compression_method(png_ptr, 8); - -Setting the contents of info for output - -You now need to fill in the png_info structure with all the data you -wish to write before the actual image. Note that the only thing you -are allowed to write after the image is the text chunks and the time -chunk (as of PNG Specification 1.2, anyway). See png_write_end() and -the latest PNG specification for more information on that. If you -wish to write them before the image, fill them in now, and flag that -data as being valid. If you want to wait until after the data, don't -fill them until png_write_end(). For all the fields in png_info and -their data types, see png.h. For explanations of what the fields -contain, see the PNG specification. - -Some of the more important parts of the png_info are: - - png_set_IHDR(png_ptr, info_ptr, width, height, - bit_depth, color_type, interlace_type, - compression_type, filter_method) - - width - holds the width of the image - in pixels (up to 2^31). - - height - holds the height of the image - in pixels (up to 2^31). - - bit_depth - holds the bit depth of one of the - image channels. - (valid values are 1, 2, 4, 8, 16 - and depend also on the - color_type. See also significant - bits (sBIT) below). - - color_type - describes which color/alpha - channels are present. - PNG_COLOR_TYPE_GRAY - (bit depths 1, 2, 4, 8, 16) - PNG_COLOR_TYPE_GRAY_ALPHA - (bit depths 8, 16) - PNG_COLOR_TYPE_PALETTE - (bit depths 1, 2, 4, 8) - PNG_COLOR_TYPE_RGB - (bit_depths 8, 16) - PNG_COLOR_TYPE_RGB_ALPHA - (bit_depths 8, 16) - - PNG_COLOR_MASK_PALETTE - PNG_COLOR_MASK_COLOR - PNG_COLOR_MASK_ALPHA - - interlace_type - PNG_INTERLACE_NONE or - PNG_INTERLACE_ADAM7 - - compression_type - (must be - PNG_COMPRESSION_TYPE_DEFAULT) - - filter_method - (must be PNG_FILTER_TYPE_DEFAULT - or, if you are writing a PNG to - be embedded in a MNG datastream, - can also be - PNG_INTRAPIXEL_DIFFERENCING) - -If you call png_set_IHDR(), the call must appear before any of the -other png_set_*() functions, because they might require access to some of -the IHDR settings. The remaining png_set_*() functions can be called -in any order. - -If you wish, you can reset the compression_type, interlace_type, or -filter_method later by calling png_set_IHDR() again; if you do this, the -width, height, bit_depth, and color_type must be the same in each call. - - png_set_PLTE(png_ptr, info_ptr, palette, - num_palette); - - palette - the palette for the file - (array of png_color) - num_palette - number of entries in the palette - - png_set_gAMA(png_ptr, info_ptr, file_gamma); - png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma); - - file_gamma - the gamma at which the image was - created (PNG_INFO_gAMA) - - int_file_gamma - 100,000 times the gamma at which - the image was created - - png_set_cHRM(png_ptr, info_ptr, white_x, white_y, red_x, red_y, - green_x, green_y, blue_x, blue_y) - png_set_cHRM_XYZ(png_ptr, info_ptr, red_X, red_Y, red_Z, green_X, - green_Y, green_Z, blue_X, blue_Y, blue_Z) - png_set_cHRM_fixed(png_ptr, info_ptr, int_white_x, int_white_y, - int_red_x, int_red_y, int_green_x, int_green_y, - int_blue_x, int_blue_y) - png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, int_red_X, int_red_Y, - int_red_Z, int_green_X, int_green_Y, int_green_Z, - int_blue_X, int_blue_Y, int_blue_Z) - - {white,red,green,blue}_{x,y} - A color space encoding specified using the chromaticities - of the end points and the white point. - - {red,green,blue}_{X,Y,Z} - A color space encoding specified using the encoding end - points - the CIE tristimulus specification of the intended - color of the red, green and blue channels in the PNG RGB - data. The white point is simply the sum of the three end - points. - - png_set_sRGB(png_ptr, info_ptr, srgb_intent); - - srgb_intent - the rendering intent - (PNG_INFO_sRGB) The presence of - the sRGB chunk means that the pixel - data is in the sRGB color space. - This chunk also implies specific - values of gAMA and cHRM. Rendering - intent is the CSS-1 property that - has been defined by the International - Color Consortium - (http://www.color.org). - It can be one of - PNG_sRGB_INTENT_SATURATION, - PNG_sRGB_INTENT_PERCEPTUAL, - PNG_sRGB_INTENT_ABSOLUTE, or - PNG_sRGB_INTENT_RELATIVE. - - - png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, - srgb_intent); - - srgb_intent - the rendering intent - (PNG_INFO_sRGB) The presence of the - sRGB chunk means that the pixel - data is in the sRGB color space. - This function also causes gAMA and - cHRM chunks with the specific values - that are consistent with sRGB to be - written. - - png_set_iCCP(png_ptr, info_ptr, name, compression_type, - profile, proflen); - - name - The profile name. - - compression_type - The compression type; always - PNG_COMPRESSION_TYPE_BASE for PNG 1.0. - You may give NULL to this argument to - ignore it. - - profile - International Color Consortium color - profile data. May contain NULs. - - proflen - length of profile data in bytes. - - png_set_sBIT(png_ptr, info_ptr, sig_bit); - - sig_bit - the number of significant bits for - (PNG_INFO_sBIT) each of the gray, red, - green, and blue channels, whichever are - appropriate for the given color type - (png_color_16) - - png_set_tRNS(png_ptr, info_ptr, trans_alpha, - num_trans, trans_color); - - trans_alpha - array of alpha (transparency) - entries for palette (PNG_INFO_tRNS) - - num_trans - number of transparent entries - (PNG_INFO_tRNS) - - trans_color - graylevel or color sample values - (in order red, green, blue) of the - single transparent color for - non-paletted images (PNG_INFO_tRNS) - - png_set_hIST(png_ptr, info_ptr, hist); - - hist - histogram of palette (array of - png_uint_16) (PNG_INFO_hIST) - - png_set_tIME(png_ptr, info_ptr, mod_time); - - mod_time - time image was last modified - (PNG_VALID_tIME) - - png_set_bKGD(png_ptr, info_ptr, background); - - background - background color (of type - png_color_16p) (PNG_VALID_bKGD) - - png_set_text(png_ptr, info_ptr, text_ptr, num_text); - - text_ptr - array of png_text holding image - comments - - text_ptr[i].compression - type of compression used - on "text" PNG_TEXT_COMPRESSION_NONE - PNG_TEXT_COMPRESSION_zTXt - PNG_ITXT_COMPRESSION_NONE - PNG_ITXT_COMPRESSION_zTXt - text_ptr[i].key - keyword for comment. Must contain - 1-79 characters. - text_ptr[i].text - text comments for current - keyword. Can be NULL or empty. - text_ptr[i].text_length - length of text string, - after decompression, 0 for iTXt - text_ptr[i].itxt_length - length of itxt string, - after decompression, 0 for tEXt/zTXt - text_ptr[i].lang - language of comment (NULL or - empty for unknown). - text_ptr[i].translated_keyword - keyword in UTF-8 (NULL - or empty for unknown). - - Note that the itxt_length, lang, and lang_key - members of the text_ptr structure only exist when the - library is built with iTXt chunk support. Prior to - libpng-1.4.0 the library was built by default without - iTXt support. Also note that when iTXt is supported, - they contain NULL pointers when the "compression" - field contains PNG_TEXT_COMPRESSION_NONE or - PNG_TEXT_COMPRESSION_zTXt. - - num_text - number of comments - - png_set_sPLT(png_ptr, info_ptr, &palette_ptr, - num_spalettes); - - palette_ptr - array of png_sPLT_struct structures - to be added to the list of palettes - in the info structure. - num_spalettes - number of palette structures to be - added. - - png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, - unit_type); - - offset_x - positive offset from the left - edge of the screen - - offset_y - positive offset from the top - edge of the screen - - unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER - - png_set_pHYs(png_ptr, info_ptr, res_x, res_y, - unit_type); - - res_x - pixels/unit physical resolution - in x direction - - res_y - pixels/unit physical resolution - in y direction - - unit_type - PNG_RESOLUTION_UNKNOWN, - PNG_RESOLUTION_METER - - png_set_sCAL(png_ptr, info_ptr, unit, width, height) - - unit - physical scale units (an integer) - - width - width of a pixel in physical scale units - - height - height of a pixel in physical scale units - (width and height are doubles) - - png_set_sCAL_s(png_ptr, info_ptr, unit, width, height) - - unit - physical scale units (an integer) - - width - width of a pixel in physical scale units - expressed as a string - - height - height of a pixel in physical scale units - (width and height are strings like "2.54") - - png_set_unknown_chunks(png_ptr, info_ptr, &unknowns, - num_unknowns) - - unknowns - array of png_unknown_chunk - structures holding unknown chunks - unknowns[i].name - name of unknown chunk - unknowns[i].data - data of unknown chunk - unknowns[i].size - size of unknown chunk's data - unknowns[i].location - position to write chunk in file - 0: do not write chunk - PNG_HAVE_IHDR: before PLTE - PNG_HAVE_PLTE: before IDAT - PNG_AFTER_IDAT: after IDAT - -The "location" member is set automatically according to -what part of the output file has already been written. -You can change its value after calling png_set_unknown_chunks() -as demonstrated in pngtest.c. Within each of the "locations", -the chunks are sequenced according to their position in the -structure (that is, the value of "i", which is the order in which -the chunk was either read from the input file or defined with -png_set_unknown_chunks). - -A quick word about text and num_text. text is an array of png_text -structures. num_text is the number of valid structures in the array. -Each png_text structure holds a language code, a keyword, a text value, -and a compression type. - -The compression types have the same valid numbers as the compression -types of the image data. Currently, the only valid number is zero. -However, you can store text either compressed or uncompressed, unlike -images, which always have to be compressed. So if you don't want the -text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE. -Because tEXt and zTXt chunks don't have a language field, if you -specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt -any language code or translated keyword will not be written out. - -Until text gets around a few hundred bytes, it is not worth compressing it. -After the text has been written out to the file, the compression type -is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR, -so that it isn't written out again at the end (in case you are calling -png_write_end() with the same struct). - -The keywords that are given in the PNG Specification are: - - Title Short (one line) title or - caption for image - - Author Name of image's creator - - Description Description of image (possibly long) - - Copyright Copyright notice - - Creation Time Time of original image creation - (usually RFC 1123 format, see below) - - Software Software used to create the image - - Disclaimer Legal disclaimer - - Warning Warning of nature of content - - Source Device used to create the image - - Comment Miscellaneous comment; conversion - from other image format - -The keyword-text pairs work like this. Keywords should be short -simple descriptions of what the comment is about. Some typical -keywords are found in the PNG specification, as is some recommendations -on keywords. You can repeat keywords in a file. You can even write -some text before the image and some after. For example, you may want -to put a description of the image before the image, but leave the -disclaimer until after, so viewers working over modem connections -don't have to wait for the disclaimer to go over the modem before -they start seeing the image. Finally, keywords should be full -words, not abbreviations. Keywords and text are in the ISO 8859-1 -(Latin-1) character set (a superset of regular ASCII) and can not -contain NUL characters, and should not contain control or other -unprintable characters. To make the comments widely readable, stick -with basic ASCII, and avoid machine specific character set extensions -like the IBM-PC character set. The keyword must be present, but -you can leave off the text string on non-compressed pairs. -Compressed pairs must have a text string, as only the text string -is compressed anyway, so the compression would be meaningless. - -PNG supports modification time via the png_time structure. Two -conversion routines are provided, png_convert_from_time_t() for -time_t and png_convert_from_struct_tm() for struct tm. The -time_t routine uses gmtime(). You don't have to use either of -these, but if you wish to fill in the png_time structure directly, -you should provide the time in universal time (GMT) if possible -instead of your local time. Note that the year number is the full -year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and -that months start with 1. - -If you want to store the time of the original image creation, you should -use a plain tEXt chunk with the "Creation Time" keyword. This is -necessary because the "creation time" of a PNG image is somewhat vague, -depending on whether you mean the PNG file, the time the image was -created in a non-PNG format, a still photo from which the image was -scanned, or possibly the subject matter itself. In order to facilitate -machine-readable dates, it is recommended that the "Creation Time" -tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"), -although this isn't a requirement. Unlike the tIME chunk, the -"Creation Time" tEXt chunk is not expected to be automatically changed -by the software. To facilitate the use of RFC 1123 dates, a function -png_convert_to_rfc1123(png_ptr, png_timep) is provided to convert -from PNG time to an RFC 1123 format string. - -Writing unknown chunks - -You can use the png_set_unknown_chunks function to queue up chunks -for writing. You give it a chunk name, raw data, and a size; that's -all there is to it. The chunks will be written by the next following -png_write_info_before_PLTE, png_write_info, or png_write_end function. -Any chunks previously read into the info structure's unknown-chunk -list will also be written out in a sequence that satisfies the PNG -specification's ordering rules. - -The high-level write interface - -At this point there are two ways to proceed; through the high-level -write interface, or through a sequence of low-level write operations. -You can use the high-level interface if your image data is present -in the info structure. All defined output -transformations are permitted, enabled by the following masks. - - PNG_TRANSFORM_IDENTITY No transformation - PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples - PNG_TRANSFORM_PACKSWAP Change order of packed - pixels to LSB first - PNG_TRANSFORM_INVERT_MONO Invert monochrome images - PNG_TRANSFORM_SHIFT Normalize pixels to the - sBIT depth - PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA - to BGRA - PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA - to AG - PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity - to transparency - PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples - PNG_TRANSFORM_STRIP_FILLER Strip out filler - bytes (deprecated). - PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading - filler bytes - PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing - filler bytes - -If you have valid image data in the info structure (you can use -png_set_rows() to put image data in the info structure), simply do this: - - png_write_png(png_ptr, info_ptr, png_transforms, NULL) - -where png_transforms is an integer containing the bitwise OR of some set of -transformation flags. This call is equivalent to png_write_info(), -followed the set of transformations indicated by the transform mask, -then png_write_image(), and finally png_write_end(). - -(The final parameter of this call is not yet used. Someday it might point -to transformation parameters required by some future output transform.) - -You must use png_transforms and not call any png_set_transform() functions -when you use png_write_png(). - -The low-level write interface - -If you are going the low-level route instead, you are now ready to -write all the file information up to the actual image data. You do -this with a call to png_write_info(). - - png_write_info(png_ptr, info_ptr); - -Note that there is one transformation you may need to do before -png_write_info(). In PNG files, the alpha channel in an image is the -level of opacity. If your data is supplied as a level of transparency, -you can invert the alpha channel before you write it, so that 0 is -fully transparent and 255 (in 8-bit or paletted images) or 65535 -(in 16-bit images) is fully opaque, with - - png_set_invert_alpha(png_ptr); - -This must appear before png_write_info() instead of later with the -other transformations because in the case of paletted images the tRNS -chunk data has to be inverted before the tRNS chunk is written. If -your image is not a paletted image, the tRNS data (which in such cases -represents a single color to be rendered as transparent) won't need to -be changed, and you can safely do this transformation after your -png_write_info() call. - -If you need to write a private chunk that you want to appear before -the PLTE chunk when PLTE is present, you can write the PNG info in -two steps, and insert code to write your own chunk between them: - - png_write_info_before_PLTE(png_ptr, info_ptr); - png_set_unknown_chunks(png_ptr, info_ptr, ...); - png_write_info(png_ptr, info_ptr); - -After you've written the file information, you can set up the library -to handle any special transformations of the image data. The various -ways to transform the data will be described in the order that they -should occur. This is important, as some of these change the color -type and/or bit depth of the data, and some others only work on -certain color types and bit depths. Even though each transformation -checks to see if it has data that it can do something with, you should -make sure to only enable a transformation if it will be valid for the -data. For example, don't swap red and blue on grayscale data. - -PNG files store RGB pixels packed into 3 or 6 bytes. This code tells -the library to strip input data that has 4 or 8 bytes per pixel down -to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2 -bytes per pixel). - - png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); - -where the 0 is unused, and the location is either PNG_FILLER_BEFORE or -PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel -is stored XRGB or RGBX. - -PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as -they can, resulting in, for example, 8 pixels per byte for 1 bit files. -If the data is supplied at 1 pixel per byte, use this code, which will -correctly pack the pixels into a single byte: - - png_set_packing(png_ptr); - -PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your -data is of another bit depth, you can write an sBIT chunk into the -file so that decoders can recover the original data if desired. - - /* Set the true bit depth of the image data */ - if (color_type & PNG_COLOR_MASK_COLOR) - { - sig_bit.red = true_bit_depth; - sig_bit.green = true_bit_depth; - sig_bit.blue = true_bit_depth; - } - - else - { - sig_bit.gray = true_bit_depth; - } - - if (color_type & PNG_COLOR_MASK_ALPHA) - { - sig_bit.alpha = true_bit_depth; - } - - png_set_sBIT(png_ptr, info_ptr, &sig_bit); - -If the data is stored in the row buffer in a bit depth other than -one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG), -this will scale the values to appear to be the correct bit depth as -is required by PNG. - - png_set_shift(png_ptr, &sig_bit); - -PNG files store 16-bit pixels in network byte order (big-endian, -ie. most significant bits first). This code would be used if they are -supplied the other way (little-endian, i.e. least significant bits -first, the way PCs store them): - - if (bit_depth > 8) - png_set_swap(png_ptr); - -If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you -need to change the order the pixels are packed into bytes, you can use: - - if (bit_depth < 8) - png_set_packswap(png_ptr); - -PNG files store 3 color pixels in red, green, blue order. This code -would be used if they are supplied as blue, green, red: - - png_set_bgr(png_ptr); - -PNG files describe monochrome as black being zero and white being -one. This code would be used if the pixels are supplied with this reversed -(black being one and white being zero): - - png_set_invert_mono(png_ptr); - -Finally, you can write your own transformation function if none of -the existing ones meets your needs. This is done by setting a callback -with - - png_set_write_user_transform_fn(png_ptr, - write_transform_fn); - -You must supply the function - - void write_transform_fn(png_structp png_ptr, png_row_infop - row_info, png_bytep data) - -See pngtest.c for a working example. Your function will be called -before any of the other transformations are processed. If supported -libpng also supplies an information routine that may be called from -your callback: - - png_get_current_row_number(png_ptr); - png_get_current_pass_number(png_ptr); - -This returns the current row passed to the transform. With interlaced -images the value returned is the row in the input sub-image image. Use -PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to -find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass). - -The discussion of interlace handling above contains more information on how to -use these values. - -You can also set up a pointer to a user structure for use by your -callback function. - - png_set_user_transform_info(png_ptr, user_ptr, 0, 0); - -The user_channels and user_depth parameters of this function are ignored -when writing; you can set them to zero as shown. - -You can retrieve the pointer via the function png_get_user_transform_ptr(). -For example: - - voidp write_user_transform_ptr = - png_get_user_transform_ptr(png_ptr); - -It is possible to have libpng flush any pending output, either manually, -or automatically after a certain number of lines have been written. To -flush the output stream a single time call: - - png_write_flush(png_ptr); - -and to have libpng flush the output stream periodically after a certain -number of scanlines have been written, call: - - png_set_flush(png_ptr, nrows); - -Note that the distance between rows is from the last time png_write_flush() -was called, or the first row of the image if it has never been called. -So if you write 50 lines, and then png_set_flush 25, it will flush the -output on the next scanline, and every 25 lines thereafter, unless -png_write_flush() is called before 25 more lines have been written. -If nrows is too small (less than about 10 lines for a 640 pixel wide -RGB image) the image compression may decrease noticeably (although this -may be acceptable for real-time applications). Infrequent flushing will -only degrade the compression performance by a few percent over images -that do not use flushing. - -Writing the image data - -That's it for the transformations. Now you can write the image data. -The simplest way to do this is in one function call. If you have the -whole image in memory, you can just call png_write_image() and libpng -will write the image. You will need to pass in an array of pointers to -each row. This function automatically handles interlacing, so you don't -need to call png_set_interlace_handling() or call this function multiple -times, or any of that other stuff necessary with png_write_rows(). - - png_write_image(png_ptr, row_pointers); - -where row_pointers is: - - png_byte *row_pointers[height]; - -You can point to void or char or whatever you use for pixels. - -If you don't want to write the whole image at once, you can -use png_write_rows() instead. If the file is not interlaced, -this is simple: - - png_write_rows(png_ptr, row_pointers, - number_of_rows); - -row_pointers is the same as in the png_write_image() call. - -If you are just writing one row at a time, you can do this with -a single row_pointer instead of an array of row_pointers: - - png_bytep row_pointer = row; - - png_write_row(png_ptr, row_pointer); - -When the file is interlaced, things can get a good deal more complicated. -The only currently (as of the PNG Specification version 1.2, dated July -1999) defined interlacing scheme for PNG files is the "Adam7" interlace -scheme, that breaks down an image into seven smaller images of varying -size. libpng will build these images for you, or you can do them -yourself. If you want to build them yourself, see the PNG specification -for details of which pixels to write when. - -If you don't want libpng to handle the interlacing details, just -use png_set_interlace_handling() and call png_write_rows() the -correct number of times to write all the sub-images -(png_set_interlace_handling() returns the number of sub-images.) - -If you want libpng to build the sub-images, call this before you start -writing any rows: - - number_of_passes = png_set_interlace_handling(png_ptr); - -This will return the number of passes needed. Currently, this is seven, -but may change if another interlace type is added. - -Then write the complete image number_of_passes times. - - png_write_rows(png_ptr, row_pointers, number_of_rows); - -Think carefully before you write an interlaced image. Typically code that -reads such images reads all the image data into memory, uncompressed, before -doing any processing. Only code that can display an image on the fly can -take advantage of the interlacing and even then the image has to be exactly -the correct size for the output device, because scaling an image requires -adjacent pixels and these are not available until all the passes have been -read. - -If you do write an interlaced image you will hardly ever need to handle -the interlacing yourself. Call png_set_interlace_handling() and use the -approach described above. - -The only time it is conceivable that you will really need to write an -interlaced image pass-by-pass is when you have read one pass by pass and -made some pixel-by-pixel transformation to it, as described in the read -code above. In this case use the PNG_PASS_ROWS and PNG_PASS_COLS macros -to determine the size of each sub-image in turn and simply write the rows -you obtained from the read code. - -Finishing a sequential write - -After you are finished writing the image, you should finish writing -the file. If you are interested in writing comments or time, you should -pass an appropriately filled png_info pointer. If you are not interested, -you can pass NULL. - - png_write_end(png_ptr, info_ptr); - -When you are done, you can free all memory used by libpng like this: - - png_destroy_write_struct(&png_ptr, &info_ptr); - -It is also possible to individually free the info_ptr members that -point to libpng-allocated storage with the following function: - - png_free_data(png_ptr, info_ptr, mask, seq) - - mask - identifies data to be freed, a mask - containing the bitwise OR of one or - more of - PNG_FREE_PLTE, PNG_FREE_TRNS, - PNG_FREE_HIST, PNG_FREE_ICCP, - PNG_FREE_PCAL, PNG_FREE_ROWS, - PNG_FREE_SCAL, PNG_FREE_SPLT, - PNG_FREE_TEXT, PNG_FREE_UNKN, - or simply PNG_FREE_ALL - - seq - sequence number of item to be freed - (-1 for all items) - -This function may be safely called when the relevant storage has -already been freed, or has not yet been allocated, or was allocated -by the user and not by libpng, and will in those cases do nothing. -The "seq" parameter is ignored if only one item of the selected data -type, such as PLTE, is allowed. If "seq" is not -1, and multiple items -are allowed for the data type identified in the mask, such as text or -sPLT, only the n'th item in the structure is freed, where n is "seq". - -If you allocated data such as a palette that you passed in to libpng -with png_set_*, you must not free it until just before the call to -png_destroy_write_struct(). - -The default behavior is only to free data that was allocated internally -by libpng. This can be changed, so that libpng will not free the data, -or so that it will free data that was allocated by the user with png_malloc() -or png_calloc() and passed in via a png_set_*() function, with - - png_data_freer(png_ptr, info_ptr, freer, mask) - - freer - one of - PNG_DESTROY_WILL_FREE_DATA - PNG_SET_WILL_FREE_DATA - PNG_USER_WILL_FREE_DATA - - mask - which data elements are affected - same choices as in png_free_data() - -For example, to transfer responsibility for some data from a read structure -to a write structure, you could use - - png_data_freer(read_ptr, read_info_ptr, - PNG_USER_WILL_FREE_DATA, - PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST) - - png_data_freer(write_ptr, write_info_ptr, - PNG_DESTROY_WILL_FREE_DATA, - PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST) - -thereby briefly reassigning responsibility for freeing to the user but -immediately afterwards reassigning it once more to the write_destroy -function. Having done this, it would then be safe to destroy the read -structure and continue to use the PLTE, tRNS, and hIST data in the write -structure. - -This function only affects data that has already been allocated. -You can call this function before calling after the png_set_*() functions -to control whether the user or png_destroy_*() is supposed to free the data. -When the user assumes responsibility for libpng-allocated data, the -application must use -png_free() to free it, and when the user transfers responsibility to libpng -for data that the user has allocated, the user must have used png_malloc() -or png_calloc() to allocate it. - -If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword -separately, do not transfer responsibility for freeing text_ptr to libpng, -because when libpng fills a png_text structure it combines these members with -the key member, and png_free_data() will free only text_ptr.key. Similarly, -if you transfer responsibility for free'ing text_ptr from libpng to your -application, your application must not separately free those members. -For a more compact example of writing a PNG image, see the file example.c. - -V. Modifying/Customizing libpng: - -There are two issues here. The first is changing how libpng does -standard things like memory allocation, input/output, and error handling. -The second deals with more complicated things like adding new chunks, -adding new transformations, and generally changing how libpng works. -Both of those are compile-time issues; that is, they are generally -determined at the time the code is written, and there is rarely a need -to provide the user with a means of changing them. - -Memory allocation, input/output, and error handling - -All of the memory allocation, input/output, and error handling in libpng -goes through callbacks that are user-settable. The default routines are -in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change -these functions, call the appropriate png_set_*_fn() function. - -Memory allocation is done through the functions png_malloc(), png_calloc(), -and png_free(). The png_malloc() and png_free() functions currently just -call the standard C functions and png_calloc() calls png_malloc() and then -clears the newly allocated memory to zero; note that png_calloc(png_ptr, size) -is not the same as the calloc(number, size) function provided by stdlib.h. -There is limited support for certain systems with segmented memory -architectures and the types of pointers declared by png.h match this; you -will have to use appropriate pointers in your application. Since it is -unlikely that the method of handling memory allocation on a platform -will change between applications, these functions must be modified in -the library at compile time. If you prefer to use a different method -of allocating and freeing data, you can use png_create_read_struct_2() or -png_create_write_struct_2() to register your own functions as described -above. These functions also provide a void pointer that can be retrieved -via - - mem_ptr=png_get_mem_ptr(png_ptr); - -Your replacement memory functions must have prototypes as follows: - - png_voidp malloc_fn(png_structp png_ptr, - png_alloc_size_t size); - - void free_fn(png_structp png_ptr, png_voidp ptr); - -Your malloc_fn() must return NULL in case of failure. The png_malloc() -function will normally call png_error() if it receives a NULL from the -system memory allocator or from your replacement malloc_fn(). - -Your free_fn() will never be called with a NULL ptr, since libpng's -png_free() checks for NULL before calling free_fn(). - -Input/Output in libpng is done through png_read() and png_write(), -which currently just call fread() and fwrite(). The FILE * is stored in -png_struct and is initialized via png_init_io(). If you wish to change -the method of I/O, the library supplies callbacks that you can set -through the function png_set_read_fn() and png_set_write_fn() at run -time, instead of calling the png_init_io() function. These functions -also provide a void pointer that can be retrieved via the function -png_get_io_ptr(). For example: - - png_set_read_fn(png_structp read_ptr, - voidp read_io_ptr, png_rw_ptr read_data_fn) - - png_set_write_fn(png_structp write_ptr, - voidp write_io_ptr, png_rw_ptr write_data_fn, - png_flush_ptr output_flush_fn); - - voidp read_io_ptr = png_get_io_ptr(read_ptr); - voidp write_io_ptr = png_get_io_ptr(write_ptr); - -The replacement I/O functions must have prototypes as follows: - - void user_read_data(png_structp png_ptr, - png_bytep data, png_size_t length); - - void user_write_data(png_structp png_ptr, - png_bytep data, png_size_t length); - - void user_flush_data(png_structp png_ptr); - -The user_read_data() function is responsible for detecting and -handling end-of-data errors. - -Supplying NULL for the read, write, or flush functions sets them back -to using the default C stream functions, which expect the io_ptr to -point to a standard *FILE structure. It is probably a mistake -to use NULL for one of write_data_fn and output_flush_fn but not both -of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined. -It is an error to read from a write stream, and vice versa. - -Error handling in libpng is done through png_error() and png_warning(). -Errors handled through png_error() are fatal, meaning that png_error() -should never return to its caller. Currently, this is handled via -setjmp() and longjmp() (unless you have compiled libpng with -PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()), -but you could change this to do things like exit() if you should wish, -as long as your function does not return. - -On non-fatal errors, png_warning() is called -to print a warning message, and then control returns to the calling code. -By default png_error() and png_warning() print a message on stderr via -fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined -(because you don't want the messages) or PNG_NO_STDIO defined (because -fprintf() isn't available). If you wish to change the behavior of the error -functions, you will need to set up your own message callbacks. These -functions are normally supplied at the time that the png_struct is created. -It is also possible to redirect errors and warnings to your own replacement -functions after png_create_*_struct() has been called by calling: - - png_set_error_fn(png_structp png_ptr, - png_voidp error_ptr, png_error_ptr error_fn, - png_error_ptr warning_fn); - - png_voidp error_ptr = png_get_error_ptr(png_ptr); - -If NULL is supplied for either error_fn or warning_fn, then the libpng -default function will be used, calling fprintf() and/or longjmp() if a -problem is encountered. The replacement error functions should have -parameters as follows: - - void user_error_fn(png_structp png_ptr, - png_const_charp error_msg); - - void user_warning_fn(png_structp png_ptr, - png_const_charp warning_msg); - -The motivation behind using setjmp() and longjmp() is the C++ throw and -catch exception handling methods. This makes the code much easier to write, -as there is no need to check every return code of every function call. -However, there are some uncertainties about the status of local variables -after a longjmp, so the user may want to be careful about doing anything -after setjmp returns non-zero besides returning itself. Consult your -compiler documentation for more details. For an alternative approach, you -may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net), -which is illustrated in pngvalid.c and in contrib/visupng. - -Custom chunks - -If you need to read or write custom chunks, you may need to get deeper -into the libpng code. The library now has mechanisms for storing -and writing chunks of unknown type; you can even declare callbacks -for custom chunks. However, this may not be good enough if the -library code itself needs to know about interactions between your -chunk and existing `intrinsic' chunks. - -If you need to write a new intrinsic chunk, first read the PNG -specification. Acquire a first level of understanding of how it works. -Pay particular attention to the sections that describe chunk names, -and look at how other chunks were designed, so you can do things -similarly. Second, check out the sections of libpng that read and -write chunks. Try to find a chunk that is similar to yours and use -it as a template. More details can be found in the comments inside -the code. It is best to handle private or unknown chunks in a generic method, -via callback functions, instead of by modifying libpng functions. This -is illustrated in pngtest.c, which uses a callback function to handle a -private "vpAg" chunk and the new "sTER" chunk, which are both unknown to -libpng. - -If you wish to write your own transformation for the data, look through -the part of the code that does the transformations, and check out some of -the simpler ones to get an idea of how they work. Try to find a similar -transformation to the one you want to add and copy off of it. More details -can be found in the comments inside the code itself. - -Configuring for 16-bit platforms - -You will want to look into zconf.h to tell zlib (and thus libpng) that -it cannot allocate more then 64K at a time. Even if you can, the memory -won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K. - -Configuring for DOS - -For DOS users who only have access to the lower 640K, you will -have to limit zlib's memory usage via a png_set_compression_mem_level() -call. See zlib.h or zconf.h in the zlib library for more information. - -Configuring for Medium Model - -Libpng's support for medium model has been tested on most of the popular -compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets -defined, and FAR gets defined to far in pngconf.h, and you should be -all set. Everything in the library (except for zlib's structure) is -expecting far data. You must use the typedefs with the p or pp on -the end for pointers (or at least look at them and be careful). Make -note that the rows of data are defined as png_bytepp, which is -an "unsigned char far * far *". - -Configuring for gui/windowing platforms: - -You will need to write new error and warning functions that use the GUI -interface, as described previously, and set them to be the error and -warning functions at the time that png_create_*_struct() is called, -in order to have them available during the structure initialization. -They can be changed later via png_set_error_fn(). On some compilers, -you may also have to change the memory allocators (png_malloc, etc.). - -Configuring for compiler xxx: - -All includes for libpng are in pngconf.h. If you need to add, change -or delete an include, this is the place to do it. -The includes that are not needed outside libpng are placed in pngpriv.h, -which is only used by the routines inside libpng itself. -The files in libpng proper only include pngpriv.h and png.h, which -in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h. -As of libpng-1.5.0, pngpriv.h also includes three other private header -files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material -that previously appeared in the public headers. - -Configuring zlib: - -There are special functions to configure the compression. Perhaps the -most useful one changes the compression level, which currently uses -input compression values in the range 0 - 9. The library normally -uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests -have shown that for a large majority of images, compression values in -the range 3-6 compress nearly as well as higher levels, and do so much -faster. For online applications it may be desirable to have maximum speed -(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also -specify no compression (Z_NO_COMPRESSION = 0), but this would create -files larger than just storing the raw bitmap. You can specify the -compression level by calling: - - #include zlib.h - png_set_compression_level(png_ptr, level); - -Another useful one is to reduce the memory level used by the library. -The memory level defaults to 8, but it can be lowered if you are -short on memory (running DOS, for example, where you only have 640K). -Note that the memory level does have an effect on compression; among -other things, lower levels will result in sections of incompressible -data being emitted in smaller stored blocks, with a correspondingly -larger relative overhead of up to 15% in the worst case. - - #include zlib.h - png_set_compression_mem_level(png_ptr, level); - -The other functions are for configuring zlib. They are not recommended -for normal use and may result in writing an invalid PNG file. See -zlib.h for more information on what these mean. - - #include zlib.h - png_set_compression_strategy(png_ptr, - strategy); - - png_set_compression_window_bits(png_ptr, - window_bits); - - png_set_compression_method(png_ptr, method); - - png_set_compression_buffer_size(png_ptr, size); - -As of libpng version 1.5.4, additional APIs became -available to set these separately for non-IDAT -compressed chunks such as zTXt, iTXt, and iCCP: - - #include zlib.h - #if PNG_LIBPNG_VER >= 10504 - png_set_text_compression_level(png_ptr, level); - - png_set_text_compression_mem_level(png_ptr, level); - - png_set_text_compression_strategy(png_ptr, - strategy); - - png_set_text_compression_window_bits(png_ptr, - window_bits); - - png_set_text_compression_method(png_ptr, method); - #endif - -Controlling row filtering - -If you want to control whether libpng uses filtering or not, which -filters are used, and how it goes about picking row filters, you -can call one of these functions. The selection and configuration -of row filters can have a significant impact on the size and -encoding speed and a somewhat lesser impact on the decoding speed -of an image. Filtering is enabled by default for RGB and grayscale -images (with and without alpha), but not for paletted images nor -for any images with bit depths less than 8 bits/pixel. - -The 'method' parameter sets the main filtering method, which is -currently only '0' in the PNG 1.2 specification. The 'filters' -parameter sets which filter(s), if any, should be used for each -scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS -to turn filtering on and off, respectively. - -Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB, -PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise -ORed together with '|' to specify one or more filters to use. -These filters are described in more detail in the PNG specification. -If you intend to change the filter type during the course of writing -the image, you should start with flags set for all of the filters -you intend to use so that libpng can initialize its internal -structures appropriately for all of the filter types. (Note that this -means the first row must always be adaptively filtered, because libpng -currently does not allocate the filter buffers until png_write_row() -is called for the first time.) - - filters = PNG_FILTER_NONE | PNG_FILTER_SUB - PNG_FILTER_UP | PNG_FILTER_AVG | - PNG_FILTER_PAETH | PNG_ALL_FILTERS; - - png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, - filters); - The second parameter can also be - PNG_INTRAPIXEL_DIFFERENCING if you are - writing a PNG to be embedded in a MNG - datastream. This parameter must be the - same as the value of filter_method used - in png_set_IHDR(). - -It is also possible to influence how libpng chooses from among the -available filters. This is done in one or both of two ways - by -telling it how important it is to keep the same filter for successive -rows, and by telling it the relative computational costs of the filters. - - double weights[3] = {1.5, 1.3, 1.1}, - costs[PNG_FILTER_VALUE_LAST] = - {1.0, 1.3, 1.3, 1.5, 1.7}; - - png_set_filter_heuristics(png_ptr, - PNG_FILTER_HEURISTIC_WEIGHTED, 3, - weights, costs); - -The weights are multiplying factors that indicate to libpng that the -row filter should be the same for successive rows unless another row filter -is that many times better than the previous filter. In the above example, -if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a -"sum of absolute differences" 1.5 x 1.3 times higher than other filters -and still be chosen, while the NONE filter could have a sum 1.1 times -higher than other filters and still be chosen. Unspecified weights are -taken to be 1.0, and the specified weights should probably be declining -like those above in order to emphasize recent filters over older filters. - -The filter costs specify for each filter type a relative decoding cost -to be considered when selecting row filters. This means that filters -with higher costs are less likely to be chosen over filters with lower -costs, unless their "sum of absolute differences" is that much smaller. -The costs do not necessarily reflect the exact computational speeds of -the various filters, since this would unduly influence the final image -size. - -Note that the numbers above were invented purely for this example and -are given only to help explain the function usage. Little testing has -been done to find optimum values for either the costs or the weights. - -Removing unwanted object code - -There are a bunch of #define's in pngconf.h that control what parts of -libpng are compiled. All the defines end in _SUPPORTED. If you are -never going to use a capability, you can change the #define to #undef -before recompiling libpng and save yourself code and data space, or -you can turn off individual capabilities with defines that begin with -PNG_NO_. - -In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead. - -You can also turn all of the transforms and ancillary chunk capabilities -off en masse with compiler directives that define -PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS, -or all four, -along with directives to turn on any of the capabilities that you do -want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra -transformations but still leave the library fully capable of reading -and writing PNG files with all known public chunks. Use of the -PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library -that is incapable of reading or writing ancillary chunks. If you are -not using the progressive reading capability, you can turn that off -with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING -capability, which you'll still have). - -All the reading and writing specific code are in separate files, so the -linker should only grab the files it needs. However, if you want to -make sure, or if you are building a stand alone library, all the -reading files start with "pngr" and all the writing files start with "pngw". -The files that don't match either (like png.c, pngtrans.c, etc.) -are used for both reading and writing, and always need to be included. -The progressive reader is in pngpread.c - -If you are creating or distributing a dynamically linked library (a .so -or DLL file), you should not remove or disable any parts of the library, -as this will cause applications linked with different versions of the -library to fail if they call functions not available in your library. -The size of the library itself should not be an issue, because only -those sections that are actually used will be loaded into memory. - -Requesting debug printout - -The macro definition PNG_DEBUG can be used to request debugging -printout. Set it to an integer value in the range 0 to 3. Higher -numbers result in increasing amounts of debugging information. The -information is printed to the "stderr" file, unless another file -name is specified in the PNG_DEBUG_FILE macro definition. - -When PNG_DEBUG > 0, the following functions (macros) become available: - - png_debug(level, message) - png_debug1(level, message, p1) - png_debug2(level, message, p1, p2) - -in which "level" is compared to PNG_DEBUG to decide whether to print -the message, "message" is the formatted string to be printed, -and p1 and p2 are parameters that are to be embedded in the string -according to printf-style formatting directives. For example, - - png_debug1(2, "foo=%d\n", foo); - -is expanded to - - if (PNG_DEBUG > 2) - fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo); - -When PNG_DEBUG is defined but is zero, the macros aren't defined, but you -can still use PNG_DEBUG to control your own debugging: - - #ifdef PNG_DEBUG - fprintf(stderr, ... - #endif - -When PNG_DEBUG = 1, the macros are defined, but only png_debug statements -having level = 0 will be printed. There aren't any such statements in -this version of libpng, but if you insert some they will be printed. - -VI. MNG support - -The MNG specification (available at http://www.libpng.org/pub/mng) allows -certain extensions to PNG for PNG images that are embedded in MNG datastreams. -Libpng can support some of these extensions. To enable them, use the -png_permit_mng_features() function: - - feature_set = png_permit_mng_features(png_ptr, mask) - - mask is a png_uint_32 containing the bitwise OR of the - features you want to enable. These include - PNG_FLAG_MNG_EMPTY_PLTE - PNG_FLAG_MNG_FILTER_64 - PNG_ALL_MNG_FEATURES - - feature_set is a png_uint_32 that is the bitwise AND of - your mask with the set of MNG features that is - supported by the version of libpng that you are using. - -It is an error to use this function when reading or writing a standalone -PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped -in a MNG datastream. As a minimum, it must have the MNG 8-byte signature -and the MHDR and MEND chunks. Libpng does not provide support for these -or any other MNG chunks; your application must provide its own support for -them. You may wish to consider using libmng (available at -http://www.libmng.com) instead. - -VII. Changes to Libpng from version 0.88 - -It should be noted that versions of libpng later than 0.96 are not -distributed by the original libpng author, Guy Schalnat, nor by -Andreas Dilger, who had taken over from Guy during 1996 and 1997, and -distributed versions 0.89 through 0.96, but rather by another member -of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are -still alive and well, but they have moved on to other things. - -The old libpng functions png_read_init(), png_write_init(), -png_info_init(), png_read_destroy(), and png_write_destroy() have been -moved to PNG_INTERNAL in version 0.95 to discourage their use. These -functions will be removed from libpng version 1.4.0. - -The preferred method of creating and initializing the libpng structures is -via the png_create_read_struct(), png_create_write_struct(), and -png_create_info_struct() because they isolate the size of the structures -from the application, allow version error checking, and also allow the -use of custom error handling routines during the initialization, which -the old functions do not. The functions png_read_destroy() and -png_write_destroy() do not actually free the memory that libpng -allocated for these structs, but just reset the data structures, so they -can be used instead of png_destroy_read_struct() and -png_destroy_write_struct() if you feel there is too much system overhead -allocating and freeing the png_struct for each image read. - -Setting the error callbacks via png_set_message_fn() before -png_read_init() as was suggested in libpng-0.88 is no longer supported -because this caused applications that do not use custom error functions -to fail if the png_ptr was not initialized to zero. It is still possible -to set the error callbacks AFTER png_read_init(), or to change them with -png_set_error_fn(), which is essentially the same function, but with a new -name to force compilation errors with applications that try to use the old -method. - -Starting with version 1.0.7, you can find out which version of the library -you are using at run-time: - - png_uint_32 libpng_vn = png_access_version_number(); - -The number libpng_vn is constructed from the major version, minor -version with leading zero, and release number with leading zero, -(e.g., libpng_vn for version 1.0.7 is 10007). - -Note that this function does not take a png_ptr, so you can call it -before you've created one. - -You can also check which version of png.h you used when compiling your -application: - - png_uint_32 application_vn = PNG_LIBPNG_VER; - -VIII. Changes to Libpng from version 1.0.x to 1.2.x - -Support for user memory management was enabled by default. To -accomplish this, the functions png_create_read_struct_2(), -png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(), -png_malloc_default(), and png_free_default() were added. - -Support for the iTXt chunk has been enabled by default as of -version 1.2.41. - -Support for certain MNG features was enabled. - -Support for numbered error messages was added. However, we never got -around to actually numbering the error messages. The function -png_set_strip_error_numbers() was added (Note: the prototype for this -function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE -builds of libpng-1.2.15. It was restored in libpng-1.2.36). - -The png_malloc_warn() function was added at libpng-1.2.3. This issues -a png_warning and returns NULL instead of aborting when it fails to -acquire the requested memory allocation. - -Support for setting user limits on image width and height was enabled -by default. The functions png_set_user_limits(), png_get_user_width_max(), -and png_get_user_height_max() were added at libpng-1.2.6. - -The png_set_add_alpha() function was added at libpng-1.2.7. - -The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9. -Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the -tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is -deprecated. - -A number of macro definitions in support of runtime selection of -assembler code features (especially Intel MMX code support) were -added at libpng-1.2.0: - - PNG_ASM_FLAG_MMX_SUPPORT_COMPILED - PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU - PNG_ASM_FLAG_MMX_READ_COMBINE_ROW - PNG_ASM_FLAG_MMX_READ_INTERLACE - PNG_ASM_FLAG_MMX_READ_FILTER_SUB - PNG_ASM_FLAG_MMX_READ_FILTER_UP - PNG_ASM_FLAG_MMX_READ_FILTER_AVG - PNG_ASM_FLAG_MMX_READ_FILTER_PAETH - PNG_ASM_FLAGS_INITIALIZED - PNG_MMX_READ_FLAGS - PNG_MMX_FLAGS - PNG_MMX_WRITE_FLAGS - PNG_MMX_FLAGS - -We added the following functions in support of runtime -selection of assembler code features: - - png_get_mmx_flagmask() - png_set_mmx_thresholds() - png_get_asm_flags() - png_get_mmx_bitdepth_threshold() - png_get_mmx_rowbytes_threshold() - png_set_asm_flags() - -We replaced all of these functions with simple stubs in libpng-1.2.20, -when the Intel assembler code was removed due to a licensing issue. - -These macros are deprecated: - - PNG_READ_TRANSFORMS_NOT_SUPPORTED - PNG_PROGRESSIVE_READ_NOT_SUPPORTED - PNG_NO_SEQUENTIAL_READ_SUPPORTED - PNG_WRITE_TRANSFORMS_NOT_SUPPORTED - PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED - PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED - -They have been replaced, respectively, by: - - PNG_NO_READ_TRANSFORMS - PNG_NO_PROGRESSIVE_READ - PNG_NO_SEQUENTIAL_READ - PNG_NO_WRITE_TRANSFORMS - PNG_NO_READ_ANCILLARY_CHUNKS - PNG_NO_WRITE_ANCILLARY_CHUNKS - -PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been -deprecated since libpng-1.0.16 and libpng-1.2.6. - -The function - png_check_sig(sig, num) -was replaced with - !png_sig_cmp(sig, 0, num) -It has been deprecated since libpng-0.90. - -The function - png_set_gray_1_2_4_to_8() -which also expands tRNS to alpha was replaced with - png_set_expand_gray_1_2_4_to_8() -which does not. It has been deprecated since libpng-1.0.18 and 1.2.9. - -IX. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x - -Private libpng prototypes and macro definitions were moved from -png.h and pngconf.h into a new pngpriv.h header file. - -Functions png_set_benign_errors(), png_benign_error(), and -png_chunk_benign_error() were added. - -Support for setting the maximum amount of memory that the application -will allocate for reading chunks was added, as a security measure. -The functions png_set_chunk_cache_max() and png_get_chunk_cache_max() -were added to the library. - -We implemented support for I/O states by adding png_ptr member io_state -and functions png_get_io_chunk_name() and png_get_io_state() in pngget.c - -We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level -input transforms. - -Checking for and reporting of errors in the IHDR chunk is more thorough. - -Support for global arrays was removed, to improve thread safety. - -Some obsolete/deprecated macros and functions have been removed. - -Typecasted NULL definitions such as - #define png_voidp_NULL (png_voidp)NULL -were eliminated. If you used these in your application, just use -NULL instead. - -The png_struct and info_struct members "trans" and "trans_values" were -changed to "trans_alpha" and "trans_color", respectively. - -The obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles -were removed. - -The PNG_1_0_X and PNG_1_2_X macros were eliminated. - -The PNG_LEGACY_SUPPORTED macro was eliminated. - -Many WIN32_WCE #ifdefs were removed. - -The functions png_read_init(info_ptr), png_write_init(info_ptr), -png_info_init(info_ptr), png_read_destroy(), and png_write_destroy() -have been removed. They have been deprecated since libpng-0.95. - -The png_permit_empty_plte() was removed. It has been deprecated -since libpng-1.0.9. Use png_permit_mng_features() instead. - -We removed the obsolete stub functions png_get_mmx_flagmask(), -png_set_mmx_thresholds(), png_get_asm_flags(), -png_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(), -png_set_asm_flags(), and png_mmx_supported() - -We removed the obsolete png_check_sig(), png_memcpy_check(), and -png_memset_check() functions. Instead use !png_sig_cmp(), png_memcpy(), -and png_memset(), respectively. - -The function png_set_gray_1_2_4_to_8() was removed. It has been -deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with -png_set_expand_gray_1_2_4_to_8() because the former function also -expanded any tRNS chunk to an alpha channel. - -Macros for png_get_uint_16, png_get_uint_32, and png_get_int_32 -were added and are used by default instead of the corresponding -functions. Unfortunately, -from libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the -function) incorrectly returned a value of type png_uint_32. - -We changed the prototype for png_malloc() from - png_malloc(png_structp png_ptr, png_uint_32 size) -to - png_malloc(png_structp png_ptr, png_alloc_size_t size) - -This also applies to the prototype for the user replacement malloc_fn(). - -The png_calloc() function was added and is used in place of -of "png_malloc(); memset();" except in the case in png_read_png() -where the array consists of pointers; in this case a "for" loop is used -after the png_malloc() to set the pointers to NULL, to give robust. -behavior in case the application runs out of memory part-way through -the process. - -We changed the prototypes of png_get_compression_buffer_size() and -png_set_compression_buffer_size() to work with png_size_t instead of -png_uint_32. - -Support for numbered error messages was removed by default, since we -never got around to actually numbering the error messages. The function -png_set_strip_error_numbers() was removed from the library by default. - -The png_zalloc() and png_zfree() functions are no longer exported. -The png_zalloc() function no longer zeroes out the memory that it -allocates. Applications that called png_zalloc(png_ptr, number, size) -can call png_calloc(png_ptr, number*size) instead, and can call -png_free() instead of png_zfree(). - -Support for dithering was disabled by default in libpng-1.4.0, because -it has not been well tested and doesn't actually "dither". -The code was not -removed, however, and could be enabled by building libpng with -PNG_READ_DITHER_SUPPORTED defined. In libpng-1.4.2, this support -was reenabled, but the function was renamed png_set_quantize() to -reflect more accurately what it actually does. At the same time, -the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to -PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED -was renamed to PNG_READ_QUANTIZE_SUPPORTED. - -We removed the trailing '.' from the warning and error messages. - -X. Changes to Libpng from version 1.4.x to 1.5.x - -From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the -function) incorrectly returned a value of type png_uint_32. - -Checking for invalid palette index on read or write was added at libpng -1.5.10. When an invalid index is found, libpng issues a benign error. -This is enabled by default but can be disabled in each png_ptr with - - png_set_check_for_invalid_index(png_ptr, allowed); - - allowed - one of - 0: disable - 1: enable - -A. Changes that affect users of libpng - -There are no substantial API changes between the non-deprecated parts of -the 1.4.5 API and the 1.5.0 API; however, the ability to directly access -members of the main libpng control structures, png_struct and png_info, -deprecated in earlier versions of libpng, has been completely removed from -libpng 1.5. - -We no longer include zlib.h in png.h. Applications that need access -to information in zlib.h will need to add the '#include "zlib.h"' -directive. It does not matter whether it is placed prior to or after -the '"#include png.h"' directive. - -The png_sprintf(), png_strcpy(), and png_strncpy() macros are no longer used -and were removed. - -We moved the png_strlen(), png_memcpy(), png_memset(), and png_memcmp() -macros into a private header file (pngpriv.h) that is not accessible to -applications. - -In png_get_iCCP, the type of "profile" was changed from png_charpp -to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep. - -There are changes of form in png.h, including new and changed macros to -declare parts of the API. Some API functions with arguments that are -pointers to data not modified within the function have been corrected to -declare these arguments with PNG_CONST. - -Much of the internal use of C macros to control the library build has also -changed and some of this is visible in the exported header files, in -particular the use of macros to control data and API elements visible -during application compilation may require significant revision to -application code. (It is extremely rare for an application to do this.) - -Any program that compiled against libpng 1.4 and did not use deprecated -features or access internal library structures should compile and work -against libpng 1.5, except for the change in the prototype for -png_get_iCCP() and png_set_iCCP() API functions mentioned above. - -libpng 1.5.0 adds PNG_ PASS macros to help in the reading and writing of -interlaced images. The macros return the number of rows and columns in -each pass and information that can be used to de-interlace and (if -absolutely necessary) interlace an image. - -libpng 1.5.0 adds an API png_longjmp(png_ptr, value). This API calls -the application-provided png_longjmp_ptr on the internal, but application -initialized, longjmp buffer. It is provided as a convenience to avoid -the need to use the png_jmpbuf macro, which had the unnecessary side -effect of resetting the internal png_longjmp_ptr value. - -libpng 1.5.0 includes a complete fixed point API. By default this is -present along with the corresponding floating point API. In general the -fixed point API is faster and smaller than the floating point one because -the PNG file format used fixed point, not floating point. This applies -even if the library uses floating point in internal calculations. A new -macro, PNG_FLOATING_ARITHMETIC_SUPPORTED, reveals whether the library -uses floating point arithmetic (the default) or fixed point arithmetic -internally for performance critical calculations such as gamma correction. -In some cases, the gamma calculations may produce slightly different -results. This has changed the results in png_rgb_to_gray and in alpha -composition (png_set_background for example). This applies even if the -original image was already linear (gamma == 1.0) and, therefore, it is -not necessary to linearize the image. This is because libpng has *not* -been changed to optimize that case correctly, yet. - -Fixed point support for the sCAL chunk comes with an important caveat; -the sCAL specification uses a decimal encoding of floating point values -and the accuracy of PNG fixed point values is insufficient for -representation of these values. Consequently a "string" API -(png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading -arbitrary sCAL chunks in the absence of either the floating point API or -internal floating point calculations. - -Applications no longer need to include the optional distribution header -file pngusr.h or define the corresponding macros during application -build in order to see the correct variant of the libpng API. From 1.5.0 -application code can check for the corresponding _SUPPORTED macro: - -#ifdef PNG_INCH_CONVERSIONS_SUPPORTED - /* code that uses the inch conversion APIs. */ -#endif - -This macro will only be defined if the inch conversion functions have been -compiled into libpng. The full set of macros, and whether or not support -has been compiled in, are available in the header file pnglibconf.h. -This header file is specific to the libpng build. Notice that prior to -1.5.0 the _SUPPORTED macros would always have the default definition unless -reset by pngusr.h or by explicit settings on the compiler command line. -These settings may produce compiler warnings or errors in 1.5.0 because -of macro redefinition. - -From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the -function) incorrectly returned a value of type png_uint_32. libpng 1.5.0 -is consistent with the implementation in 1.4.5 and 1.2.x (where the macro -did not exist.) - -Applications can now choose whether to use these macros or to call the -corresponding function by defining PNG_USE_READ_MACROS or -PNG_NO_USE_READ_MACROS before including png.h. Notice that this is -only supported from 1.5.0 -defining PNG_NO_USE_READ_MACROS prior to 1.5.0 -will lead to a link failure. - -Prior to libpng-1.5.4, the zlib compressor used the same set of parameters -when compressing the IDAT data and textual data such as zTXt and iCCP. -In libpng-1.5.4 we reinitialized the zlib stream for each type of data. -We added five png_set_text_*() functions for setting the parameters to -use with textual data. - -Prior to libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED -option was off by default, and slightly inaccurate scaling occurred. -This option can no longer be turned off, and the choice of accurate -or inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8() -API for accurate scaling or the old png_set_strip_16_to_8() API for simple -chopping. - -Prior to libpng-1.5.4, the png_set_user_limits() function could only be -used to reduce the width and height limits from the value of -PNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX, although this document said -that it could be used to override them. Now this function will reduce or -increase the limits. - -Starting in libpng-1.5.10, the user limits can be set en masse with the -configuration option PNG_SAFE_LIMITS_SUPPORTED. If this option is enabled, -a set of "safe" limits is applied in pngpriv.h. These can be overridden by -application calls to png_set_user_limits(), png_set_user_chunk_cache_max(), -and/or png_set_user_malloc_max() that increase or decrease the limits. Also, -in libpng-1.5.10 the default width and height limits were increased -from 1,000,000 to 0x7ffffff (i.e., made unlimited). Therefore, the -limits are now - default safe - png_user_width_max 0x7fffffff 1,000,000 - png_user_height_max 0x7fffffff 1,000,000 - png_user_chunk_cache_max 0 (unlimited) 128 - png_user_chunk_malloc_max 0 (unlimited) 8,000,000 - -B. Changes to the build and configuration of libpng - -Details of internal changes to the library code can be found in the CHANGES -file and in the GIT repository logs. These will be of no concern to the vast -majority of library users or builders; however, the few who configure libpng -to a non-default feature set may need to change how this is done. - -There should be no need for library builders to alter build scripts if -these use the distributed build support - configure or the makefiles - -however, users of the makefiles may care to update their build scripts -to build pnglibconf.h where the corresponding makefile does not do so. - -Building libpng with a non-default configuration has changed completely. -The old method using pngusr.h should still work correctly even though the -way pngusr.h is used in the build has been changed; however, library -builders will probably want to examine the changes to take advantage of -new capabilities and to simplify their build system. - -B.1 Specific changes to library configuration capabilities - -The library now supports a complete fixed point implementation and can -thus be used on systems that have no floating point support or very -limited or slow support. Previously gamma correction, an essential part -of complete PNG support, required reasonably fast floating point. - -As part of this the choice of internal implementation has been made -independent of the choice of fixed versus floating point APIs and all the -missing fixed point APIs have been implemented. - -The exact mechanism used to control attributes of API functions has -changed. A single set of operating system independent macro definitions -is used and operating system specific directives are defined in -pnglibconf.h - -As part of this the mechanism used to choose procedure call standards on -those systems that allow a choice has been changed. At present this only -affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems -running on Intel processors. As before, PNGAPI is defined where required -to control the exported API functions; however, two new macros, PNGCBAPI -and PNGCAPI, are used instead for callback functions (PNGCBAPI) and -(PNGCAPI) for functions that must match a C library prototype (currently -only png_longjmp_ptr, which must match the C longjmp function.) The new -approach is documented in pngconf.h - -Despite these changes, libpng 1.5.0 only supports the native C function -calling standard on those platforms tested so far (__cdecl on Microsoft -Windows). This is because the support requirements for alternative -calling conventions seem to no longer exist. Developers who find it -necessary to set PNG_API_RULE to 1 should advise the mailing list -(png-mng-implement) of this and library builders who use Openwatcom and -therefore set PNG_API_RULE to 2 should also contact the mailing list. - -A new test program, pngvalid, is provided in addition to pngtest. -pngvalid validates the arithmetic accuracy of the gamma correction -calculations and includes a number of validations of the file format. -A subset of the full range of tests is run when "make check" is done -(in the 'configure' build.) pngvalid also allows total allocated memory -usage to be evaluated and performs additional memory overwrite validation. - -Many changes to individual feature macros have been made. The following -are the changes most likely to be noticed by library builders who -configure libpng: - -1) All feature macros now have consistent naming: - -#define PNG_NO_feature turns the feature off -#define PNG_feature_SUPPORTED turns the feature on - -pnglibconf.h contains one line for each feature macro which is either: - -#define PNG_feature_SUPPORTED - -if the feature is supported or: - -/*#undef PNG_feature_SUPPORTED*/ - -if it is not. Library code consistently checks for the 'SUPPORTED' macro. -It does not, and libpng applications should not, check for the 'NO' macro -which will not normally be defined even if the feature is not supported. -The 'NO' macros are only used internally for setting or not setting the -corresponding 'SUPPORTED' macros. - -Compatibility with the old names is provided as follows: - -PNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED - -And the following definitions disable the corresponding feature: - -PNG_SETJMP_NOT_SUPPORTED disables SETJMP -PNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS -PNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV -PNG_WRITE_TRANSFORMS_NOT_SUPPORTED disables WRITE_TRANSFORMS -PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED disables READ_ANCILLARY_CHUNKS -PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED disables WRITE_ANCILLARY_CHUNKS - -Library builders should remove use of the above, inconsistent, names. - -2) Warning and error message formatting was previously conditional on -the STDIO feature. The library has been changed to use the -CONSOLE_IO feature instead. This means that if CONSOLE_IO is disabled -the library no longer uses the printf(3) functions, even though the -default read/write implementations use (FILE) style stdio.h functions. - -3) Three feature macros now control the fixed/floating point decisions: - -PNG_FLOATING_POINT_SUPPORTED enables the floating point APIs - -PNG_FIXED_POINT_SUPPORTED enables the fixed point APIs; however, in -practice these are normally required internally anyway (because the PNG -file format is fixed point), therefore in most cases PNG_NO_FIXED_POINT -merely stops the function from being exported. - -PNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating -point implementation or the fixed point one. Typically the fixed point -implementation is larger and slower than the floating point implementation -on a system that supports floating point; however, it may be faster on a -system which lacks floating point hardware and therefore uses a software -emulation. - -4) Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the -functions to read and write ints to be disabled independently of -PNG_USE_READ_MACROS, which allows libpng to be built with the functions -even though the default is to use the macros - this allows applications -to choose at app buildtime whether or not to use macros (previously -impossible because the functions weren't in the default build.) - -B.2 Changes to the configuration mechanism - -Prior to libpng-1.5.0 library builders who needed to configure libpng -had either to modify the exported pngconf.h header file to add system -specific configuration or had to write feature selection macros into -pngusr.h and cause this to be included into pngconf.h by defining -PNG_USER_CONFIG. The latter mechanism had the disadvantage that an -application built without PNG_USER_CONFIG defined would see the -unmodified, default, libpng API and thus would probably fail to link. - -These mechanisms still work in the configure build and in any makefile -build that builds pnglibconf.h, although the feature selection macros -have changed somewhat as described above. In 1.5.0, however, pngusr.h is -processed only once, when the exported header file pnglibconf.h is built. -pngconf.h no longer includes pngusr.h, therefore pngusr.h is ignored after the -build of pnglibconf.h and it is never included in an application build. - -The rarely used alternative of adding a list of feature macros to the -CFLAGS setting in the build also still works; however, the macros will be -copied to pnglibconf.h and this may produce macro redefinition warnings -when the individual C files are compiled. - -All configuration now only works if pnglibconf.h is built from -scripts/pnglibconf.dfa. This requires the program awk. Brian Kernighan -(the original author of awk) maintains C source code of that awk and this -and all known later implementations (often called by subtly different -names - nawk and gawk for example) are adequate to build pnglibconf.h. -The Sun Microsystems (now Oracle) program 'awk' is an earlier version -and does not work; this may also apply to other systems that have a -functioning awk called 'nawk'. - -Configuration options are now documented in scripts/pnglibconf.dfa. This -file also includes dependency information that ensures a configuration is -consistent; that is, if a feature is switched off dependent features are -also removed. As a recommended alternative to using feature macros in -pngusr.h a system builder may also define equivalent options in pngusr.dfa -(or, indeed, any file) and add that to the configuration by setting -DFA_XTRA to the file name. The makefiles in contrib/pngminim illustrate -how to do this, and a case where pngusr.h is still required. - -XI. Detecting libpng - -The png_get_io_ptr() function has been present since libpng-0.88, has never -changed, and is unaffected by conditional compilation macros. It is the -best choice for use in configure scripts for detecting the presence of any -libpng version since 0.88. In an autoconf "configure.in" you could use - - AC_CHECK_LIB(png, png_get_io_ptr, ... - -XII. Source code repository - -Since about February 2009, version 1.2.34, libpng has been under "git" source -control. The git repository was built from old libpng-x.y.z.tar.gz files -going back to version 0.70. You can access the git repository (read only) -at - - git://libpng.git.sourceforge.net/gitroot/libpng - -or you can browse it via "gitweb" at - - http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng - -Patches can be sent to glennrp at users.sourceforge.net or to -png-mng-implement at lists.sourceforge.net or you can upload them to -the libpng bug tracker at - - http://libpng.sourceforge.net - -We also accept patches built from the tar or zip distributions, and -simple verbal discriptions of bug fixes, reported either to the -SourceForge bug tracker, to the png-mng-implement at lists.sf.net -mailing list, or directly to glennrp. - -XIII. Coding style - -Our coding style is similar to the "Allman" style, with curly -braces on separate lines: - - if (condition) - { - action; - } - - else if (another condition) - { - another action; - } - -The braces can be omitted from simple one-line actions: - - if (condition) - return (0); - -We use 3-space indentation, except for continued statements which -are usually indented the same as the first line of the statement -plus four more spaces. - -For macro definitions we use 2-space indentation, always leaving the "#" -in the first column. - - #ifndef PNG_NO_FEATURE - # ifndef PNG_FEATURE_SUPPORTED - # define PNG_FEATURE_SUPPORTED - # endif - #endif - -Comments appear with the leading "/*" at the same indentation as -the statement that follows the comment: - - /* Single-line comment */ - statement; - - /* This is a multiple-line - * comment. - */ - statement; - -Very short comments can be placed after the end of the statement -to which they pertain: - - statement; /* comment */ - -We don't use C++ style ("//") comments. We have, however, -used them in the past in some now-abandoned MMX assembler -code. - -Functions and their curly braces are not indented, and -exported functions are marked with PNGAPI: - - /* This is a public function that is visible to - * application programmers. It does thus-and-so. - */ - void PNGAPI - png_exported_function(png_ptr, png_info, foo) - { - body; - } - -The prototypes for all exported functions appear in png.h, -above the comment that says - - /* Maintainer: Put new public prototypes here ... */ - -We mark all non-exported functions with "/* PRIVATE */"": - - void /* PRIVATE */ - png_non_exported_function(png_ptr, png_info, foo) - { - body; - } - -The prototypes for non-exported functions (except for those in -pngtest) appear in -pngpriv.h -above the comment that says - - /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ - -To avoid polluting the global namespace, the names of all exported -functions and variables begin with "png_", and all publicly visible C -preprocessor macros begin with "PNG". We request that applications that -use libpng *not* begin any of their own symbols with either of these strings. - -We put a space after each comma and after each semicolon -in "for" statements, and we put spaces before and after each -C binary operator and after "for" or "while", and before -"?". We don't put a space between a typecast and the expression -being cast, nor do we put one between a function name and the -left parenthesis that follows it: - - for (i = 2; i > 0; --i) - y[i] = a(x) + (int)b; - -We prefer #ifdef and #ifndef to #if defined() and if !defined() -when there is only one macro being tested. - -We prefer to express integers that are used as bit masks in hex format, -with an even number of lower-case hex digits (e.g., 0x00, 0xff, 0x0100). - -We do not use the TAB character for indentation in the C sources. - -Lines do not exceed 80 characters. - -Other rules can be inferred by inspecting the libpng source. - -XIV. Y2K Compliance in libpng - -September 27, 2012 - -Since the PNG Development group is an ad-hoc body, we can't make -an official declaration. - -This is your unofficial assurance that libpng from version 0.71 and -upward through 1.5.13 are Y2K compliant. It is my belief that earlier -versions were also Y2K compliant. - -Libpng only has two year fields. One is a 2-byte unsigned integer that -will hold years up to 65535. The other holds the date in text -format, and will hold years up to 9999. - -The integer is - "png_uint_16 year" in png_time_struct. - -The string is - "char time_buffer[29]" in png_struct. This will no -longer be used in libpng-1.6.x and will be removed from libpng-1.7.0. - -There are seven time-related functions: - - png_convert_to_rfc_1123() in png.c - (formerly png_convert_to_rfc_1152() in error) - png_convert_from_struct_tm() in pngwrite.c, called - in pngwrite.c - png_convert_from_time_t() in pngwrite.c - png_get_tIME() in pngget.c - png_handle_tIME() in pngrutil.c, called in pngread.c - png_set_tIME() in pngset.c - png_write_tIME() in pngwutil.c, called in pngwrite.c - -All appear to handle dates properly in a Y2K environment. The -png_convert_from_time_t() function calls gmtime() to convert from system -clock time, which returns (year - 1900), which we properly convert to -the full 4-digit year. There is a possibility that applications using -libpng are not passing 4-digit years into the png_convert_to_rfc_1123() -function, or that they are incorrectly passing only a 2-digit year -instead of "year - 1900" into the png_convert_from_struct_tm() function, -but this is not under our control. The libpng documentation has always -stated that it works with 4-digit years, and the APIs have been -documented as such. - -The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned -integer to hold the year, and can hold years as large as 65535. - -zlib, upon which libpng depends, is also Y2K compliant. It contains -no date-related code. - - - Glenn Randers-Pehrson - libpng maintainer - PNG Development Group +Libpng-manual.txt - A description on how to use and modify libpng + + libpng version 1.5.13 - September 27, 2012 + Updated and distributed by Glenn Randers-Pehrson + + Copyright (c) 1998-2012 Glenn Randers-Pehrson + + This document is released under the libpng license. + For conditions of distribution and use, see the disclaimer + and license in png.h + + Based on: + + libpng versions 0.97, January 1998, through 1.5.13 - September 27, 2012 + Updated and distributed by Glenn Randers-Pehrson + Copyright (c) 1998-2012 Glenn Randers-Pehrson + + libpng 1.0 beta 6 version 0.96 May 28, 1997 + Updated and distributed by Andreas Dilger + Copyright (c) 1996, 1997 Andreas Dilger + + libpng 1.0 beta 2 - version 0.88 January 26, 1996 + For conditions of distribution and use, see copyright + notice in png.h. Copyright (c) 1995, 1996 Guy Eric + Schalnat, Group 42, Inc. + + Updated/rewritten per request in the libpng FAQ + Copyright (c) 1995, 1996 Frank J. T. Wojcik + December 18, 1995 & January 20, 1996 + +I. Introduction + +This file describes how to use and modify the PNG reference library +(known as libpng) for your own use. There are five sections to this +file: introduction, structures, reading, writing, and modification and +configuration notes for various special platforms. In addition to this +file, example.c is a good starting point for using the library, as +it is heavily commented and should include everything most people +will need. We assume that libpng is already installed; see the +INSTALL file for instructions on how to install libpng. + +For examples of libpng usage, see the files "example.c", "pngtest.c", +and the files in the "contrib" directory, all of which are included in +the libpng distribution. + +Libpng was written as a companion to the PNG specification, as a way +of reducing the amount of time and effort it takes to support the PNG +file format in application programs. + +The PNG specification (second edition), November 2003, is available as +a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at +. It is technically equivalent +to the PNG specification (second edition) but has some additional material. + +The PNG-1.0 specification is available +as RFC 2083 and as a +W3C Recommendation . + +Some additional chunks are described in the special-purpose public chunks +documents at . + +Other information +about PNG, and the latest version of libpng, can be found at the PNG home +page, . + +Most users will not have to modify the library significantly; advanced +users may want to modify it more. All attempts were made to make it as +complete as possible, while keeping the code easy to understand. +Currently, this library only supports C. Support for other languages +is being considered. + +Libpng has been designed to handle multiple sessions at one time, +to be easily modifiable, to be portable to the vast majority of +machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy +to use. The ultimate goal of libpng is to promote the acceptance of +the PNG file format in whatever way possible. While there is still +work to be done (see the TODO file), libpng should cover the +majority of the needs of its users. + +Libpng uses zlib for its compression and decompression of PNG files. +Further information about zlib, and the latest version of zlib, can +be found at the zlib home page, . +The zlib compression utility is a general purpose utility that is +useful for more than PNG files, and can be used without libpng. +See the documentation delivered with zlib for more details. +You can usually find the source files for the zlib utility wherever you +find the libpng source files. + +Libpng is thread safe, provided the threads are using different +instances of the structures. Each thread should have its own +png_struct and png_info instances, and thus its own image. +Libpng does not protect itself against two threads using the +same instance of a structure. + +II. Structures + +There are two main structures that are important to libpng, png_struct +and png_info. Both are internal structures that are no longer exposed +in the libpng interface (as of libpng 1.5.0). + +The png_info structure is designed to provide information about the +PNG file. At one time, the fields of png_info were intended to be +directly accessible to the user. However, this tended to cause problems +with applications using dynamically loaded libraries, and as a result +a set of interface functions for png_info (the png_get_*() and png_set_*() +functions) was developed, and direct access to the png_info fields was +deprecated.. + +The png_struct structure is the object used by the library to decode a +single image. As of 1.5.0 this structure is also not exposed. + +Almost all libpng APIs require a pointer to a png_struct as the first argument. +Many (in particular the png_set and png_get APIs) also require a pointer +to png_info as the second argument. Some application visible macros +defined in png.h designed for basic data access (reading and writing +integers in the PNG format) don't take a png_info pointer, but it's almost +always safe to assume that a (png_struct*) has to be passed to call an API +function. + +You can have more than one png_info structure associated with an image, +as illustrated in pngtest.c, one for information valid prior to the +IDAT chunks and another (called "end_info" below) for things after them. + +The png.h header file is an invaluable reference for programming with libpng. +And while I'm on the topic, make sure you include the libpng header file: + +#include + +and also (as of libpng-1.5.0) the zlib header file, if you need it: + +#include + +Types + +The png.h header file defines a number of integral types used by the +APIs. Most of these are fairly obvious; for example types corresponding +to integers of particular sizes and types for passing color values. + +One exception is how non-integral numbers are handled. For application +convenience most APIs that take such numbers have C (double) arguments; +however, internally PNG, and libpng, use 32 bit signed integers and encode +the value by multiplying by 100,000. As of libpng 1.5.0 a convenience +macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point) +which is simply (png_int_32). + +All APIs that take (double) arguments also have a matching API that +takes the corresponding fixed point integer arguments. The fixed point +API has the same name as the floating point one with "_fixed" appended. +The actual range of values permitted in the APIs is frequently less than +the full range of (png_fixed_point) (-21474 to +21474). When APIs require +a non-negative argument the type is recorded as png_uint_32 above. Consult +the header file and the text below for more information. + +Special care must be take with sCAL chunk handling because the chunk itself +uses non-integral values encoded as strings containing decimal floating point +numbers. See the comments in the header file. + +Configuration + +The main header file function declarations are frequently protected by C +preprocessing directives of the form: + + #ifdef PNG_feature_SUPPORTED + declare-function + #endif + ... + #ifdef PNG_feature_SUPPORTED + use-function + #endif + +The library can be built without support for these APIs, although a +standard build will have all implemented APIs. Application programs +should check the feature macros before using an API for maximum +portability. From libpng 1.5.0 the feature macros set during the build +of libpng are recorded in the header file "pnglibconf.h" and this file +is always included by png.h. + +If you don't need to change the library configuration from the default, skip to +the next section ("Reading"). + +Notice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all +of the build project files in the 'projects' directory simply copy +scripts/pnglibconf.h.prebuilt to pnglibconf.h. This means that these build +systems do not permit easy auto-configuration of the library - they only +support the default configuration. + +The easiest way to make minor changes to the libpng configuration when +auto-configuration is supported is to add definitions to the command line +using (typically) CPPFLAGS. For example: + +CPPFLAGS=-DPNG_NO_FLOATING_ARITHMETIC + +will change the internal libpng math implementation for gamma correction and +other arithmetic calculations to fixed point, avoiding the need for fast +floating point support. The result can be seen in the generated pnglibconf.h - +make sure it contains the changed feature macro setting. + +If you need to make more extensive configuration changes - more than one or two +feature macro settings - you can either add -DPNG_USER_CONFIG to the build +command line and put a list of feature macro settings in pngusr.h or you can set +DFA_XTRA (a makefile variable) to a file containing the same information in the +form of 'option' settings. + +A. Changing pnglibconf.h + +A variety of methods exist to build libpng. Not all of these support +reconfiguration of pnglibconf.h. To reconfigure pnglibconf.h it must either be +rebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand. + +Hand editing is achieved by copying scripts/pnglibconf.h.prebuilt to +pnglibconf.h and changing the lines defining the supported features, paying +very close attention to the 'option' information in scripts/pnglibconf.dfa +that describes those features and their requirements. This is easy to get +wrong. + +B. Configuration using DFA_XTRA + +Rebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later +variant such as 'nawk' or 'gawk', is available. The configure build will +automatically find an appropriate awk and build pnglibconf.h. +The scripts/pnglibconf.mak file contains a set of make rules for doing the +same thing if configure is not used, and many of the makefiles in the scripts +directory use this approach. + +When rebuilding simply write a new file containing changed options and set +DFA_XTRA to the name of this file. This causes the build to append the new file +to the end of scripts/pnglibconf.dfa. The pngusr.dfa file should contain lines +of the following forms: + +everything = off + +This turns all optional features off. Include it at the start of pngusr.dfa to +make it easier to build a minimal configuration. You will need to turn at least +some features on afterward to enable either reading or writing code, or both. + +option feature on +option feature off + +Enable or disable a single feature. This will automatically enable other +features required by a feature that is turned on or disable other features that +require a feature which is turned off. Conflicting settings will cause an error +message to be emitted by awk. + +setting feature default value + +Changes the default value of setting 'feature' to 'value'. There are a small +number of settings listed at the top of pnglibconf.h, they are documented in the +source code. Most of these values have performance implications for the library +but most of them have no visible effect on the API. Some can also be overridden +from the API. + +This method of building a customized pnglibconf.h is illustrated in +contrib/pngminim/*. See the "$(PNGCONF):" target in the makefile and +pngusr.dfa in these directories. + +C. Configuration using PNG_USR_CONFIG + +If -DPNG_USR_CONFIG is added to the CFLAGS when pnglibconf.h is built the file +pngusr.h will automatically be included before the options in +scripts/pnglibconf.dfa are processed. Your pngusr.h file should contain only +macro definitions turning features on or off or setting settings. + +Apart from the global setting "everything = off" all the options listed above +can be set using macros in pngusr.h: + +#define PNG_feature_SUPPORTED + +is equivalent to: + +option feature on + +#define PNG_NO_feature + +is equivalent to: + +option feature off + +#define PNG_feature value + +is equivalent to: + +setting feature default value + +Notice that in both cases, pngusr.dfa and pngusr.h, the contents of the +pngusr file you supply override the contents of scripts/pnglibconf.dfa + +If confusing or incomprehensible behavior results it is possible to +examine the intermediate file pnglibconf.dfn to find the full set of +dependency information for each setting and option. Simply locate the +feature in the file and read the C comments that precede it. + +This method is also illustrated in the contrib/pngminim/* makefiles and +pngusr.h. + +III. Reading + +We'll now walk you through the possible functions to call when reading +in a PNG file sequentially, briefly explaining the syntax and purpose +of each one. See example.c and png.h for more detail. While +progressive reading is covered in the next section, you will still +need some of the functions discussed in this section to read a PNG +file. + +Setup + +You will want to do the I/O initialization(*) before you get into libpng, +so if it doesn't work, you don't have much to undo. Of course, you +will also want to insure that you are, in fact, dealing with a PNG +file. Libpng provides a simple check to see if a file is a PNG file. +To use it, pass in the first 1 to 8 bytes of the file to the function +png_sig_cmp(), and it will return 0 (false) if the bytes match the +corresponding bytes of the PNG signature, or nonzero (true) otherwise. +Of course, the more bytes you pass in, the greater the accuracy of the +prediction. + +If you are intending to keep the file pointer open for use in libpng, +you must ensure you don't read more than 8 bytes from the beginning +of the file, and you also have to make a call to png_set_sig_bytes_read() +with the number of bytes you read from the beginning. Libpng will +then only check the bytes (if any) that your program didn't read. + +(*): If you are not using the standard I/O functions, you will need +to replace them with custom functions. See the discussion under +Customizing libpng. + + + FILE *fp = fopen(file_name, "rb"); + if (!fp) + { + return (ERROR); + } + + fread(header, 1, number, fp); + is_png = !png_sig_cmp(header, 0, number); + + if (!is_png) + { + return (NOT_PNG); + } + + +Next, png_struct and png_info need to be allocated and initialized. In +order to ensure that the size of these structures is correct even with a +dynamically linked libpng, there are functions to initialize and +allocate the structures. We also pass the library version, optional +pointers to error handling functions, and a pointer to a data struct for +use by the error functions, if necessary (the pointer and functions can +be NULL if the default error handlers are to be used). See the section +on Changes to Libpng below regarding the old initialization functions. +The structure allocation functions quietly return NULL if they fail to +create the structure, so your application should check for that. + + png_structp png_ptr = png_create_read_struct + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn); + + if (!png_ptr) + return (ERROR); + + png_infop info_ptr = png_create_info_struct(png_ptr); + + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr, + (png_infopp)NULL, (png_infopp)NULL); + return (ERROR); + } + +If you want to use your own memory allocation routines, +use a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use +png_create_read_struct_2() instead of png_create_read_struct(): + + png_structp png_ptr = png_create_read_struct_2 + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn, (png_voidp) + user_mem_ptr, user_malloc_fn, user_free_fn); + +The error handling routines passed to png_create_read_struct() +and the memory alloc/free routines passed to png_create_struct_2() +are only necessary if you are not using the libpng supplied error +handling and memory alloc/free functions. + +When libpng encounters an error, it expects to longjmp back +to your routine. Therefore, you will need to call setjmp and pass +your png_jmpbuf(png_ptr). If you read the file from different +routines, you will need to update the longjmp buffer every time you enter +a new routine that will call a png_*() function. + +See your documentation of setjmp/longjmp for your compiler for more +information on setjmp/longjmp. See the discussion on libpng error +handling in the Customizing Libpng section below for more information +on the libpng error handling. If an error occurs, and libpng longjmp's +back to your setjmp, you will want to call png_destroy_read_struct() to +free any memory. + + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + &end_info); + fclose(fp); + return (ERROR); + } + +Pass (png_infopp)NULL instead of &end_info if you didn't create +an end_info structure. + +If you would rather avoid the complexity of setjmp/longjmp issues, +you can compile libpng with PNG_NO_SETJMP, in which case +errors will result in a call to PNG_ABORT() which defaults to abort(). + +You can #define PNG_ABORT() to a function that does something +more useful than abort(), as long as your function does not +return. + +Now you need to set up the input code. The default for libpng is to +use the C function fread(). If you use this, you will need to pass a +valid FILE * in the function png_init_io(). Be sure that the file is +opened in binary mode. If you wish to handle reading data in another +way, you need not call the png_init_io() function, but you must then +implement the libpng I/O methods discussed in the Customizing Libpng +section below. + + png_init_io(png_ptr, fp); + +If you had previously opened the file and read any of the signature from +the beginning in order to see if this was a PNG file, you need to let +libpng know that there are some bytes missing from the start of the file. + + png_set_sig_bytes(png_ptr, number); + +You can change the zlib compression buffer size to be used while +reading compressed data with + + png_set_compression_buffer_size(png_ptr, buffer_size); + +where the default size is 8192 bytes. Note that the buffer size +is changed immediately and the buffer is reallocated immediately, +instead of setting a flag to be acted upon later. + +If you want CRC errors to be handled in a different manner than +the default, use + + png_set_crc_action(png_ptr, crit_action, ancil_action); + +The values for png_set_crc_action() say how libpng is to handle CRC errors in +ancillary and critical chunks, and whether to use the data contained +therein. Note that it is impossible to "discard" data in a critical +chunk. + +Choices for (int) crit_action are + PNG_CRC_DEFAULT 0 error/quit + PNG_CRC_ERROR_QUIT 1 error/quit + PNG_CRC_WARN_USE 3 warn/use data + PNG_CRC_QUIET_USE 4 quiet/use data + PNG_CRC_NO_CHANGE 5 use the current value + +Choices for (int) ancil_action are + PNG_CRC_DEFAULT 0 error/quit + PNG_CRC_ERROR_QUIT 1 error/quit + PNG_CRC_WARN_DISCARD 2 warn/discard data + PNG_CRC_WARN_USE 3 warn/use data + PNG_CRC_QUIET_USE 4 quiet/use data + PNG_CRC_NO_CHANGE 5 use the current value + +Setting up callback code + +You can set up a callback function to handle any unknown chunks in the +input stream. You must supply the function + + read_chunk_callback(png_structp png_ptr, + png_unknown_chunkp chunk); + { + /* The unknown chunk structure contains your + chunk data, along with similar data for any other + unknown chunks: */ + + png_byte name[5]; + png_byte *data; + png_size_t size; + + /* Note that libpng has already taken care of + the CRC handling */ + + /* put your code here. Search for your chunk in the + unknown chunk structure, process it, and return one + of the following: */ + + return (-n); /* chunk had an error */ + return (0); /* did not recognize */ + return (n); /* success */ + } + +(You can give your function another name that you like instead of +"read_chunk_callback") + +To inform libpng about your function, use + + png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr, + read_chunk_callback); + +This names not only the callback function, but also a user pointer that +you can retrieve with + + png_get_user_chunk_ptr(png_ptr); + +If you call the png_set_read_user_chunk_fn() function, then all unknown +chunks will be saved when read, in case your callback function will need +one or more of them. This behavior can be changed with the +png_set_keep_unknown_chunks() function, described below. + +At this point, you can set up a callback function that will be +called after each row has been read, which you can use to control +a progress meter or the like. It's demonstrated in pngtest.c. +You must supply a function + + void read_row_callback(png_structp png_ptr, + png_uint_32 row, int pass); + { + /* put your code here */ + } + +(You can give it another name that you like instead of "read_row_callback") + +To inform libpng about your function, use + + png_set_read_status_fn(png_ptr, read_row_callback); + +When this function is called the row has already been completely processed and +the 'row' and 'pass' refer to the next row to be handled. For the +non-interlaced case the row that was just handled is simply one less than the +passed in row number, and pass will always be 0. For the interlaced case the +same applies unless the row value is 0, in which case the row just handled was +the last one from one of the preceding passes. Because interlacing may skip a +pass you cannot be sure that the preceding pass is just 'pass-1', if you really +need to know what the last pass is record (row,pass) from the callback and use +the last recorded value each time. + +As with the user transform you can find the output row using the +PNG_ROW_FROM_PASS_ROW macro. + +Unknown-chunk handling + +Now you get to set the way the library processes unknown chunks in the +input PNG stream. Both known and unknown chunks will be read. Normal +behavior is that known chunks will be parsed into information in +various info_ptr members while unknown chunks will be discarded. This +behavior can be wasteful if your application will never use some known +chunk types. To change this, you can call: + + png_set_keep_unknown_chunks(png_ptr, keep, + chunk_list, num_chunks); + keep - 0: default unknown chunk handling + 1: ignore; do not keep + 2: keep only if safe-to-copy + 3: keep even if unsafe-to-copy + + You can use these definitions: + PNG_HANDLE_CHUNK_AS_DEFAULT 0 + PNG_HANDLE_CHUNK_NEVER 1 + PNG_HANDLE_CHUNK_IF_SAFE 2 + PNG_HANDLE_CHUNK_ALWAYS 3 + + chunk_list - list of chunks affected (a byte string, + five bytes per chunk, NULL or '\0' if + num_chunks is 0) + + num_chunks - number of chunks affected; if 0, all + unknown chunks are affected. If nonzero, + only the chunks in the list are affected + +Unknown chunks declared in this way will be saved as raw data onto a +list of png_unknown_chunk structures. If a chunk that is normally +known to libpng is named in the list, it will be handled as unknown, +according to the "keep" directive. If a chunk is named in successive +instances of png_set_keep_unknown_chunks(), the final instance will +take precedence. The IHDR and IEND chunks should not be named in +chunk_list; if they are, libpng will process them normally anyway. +If you know that your application will never make use of some particular +chunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below. + +Here is an example of the usage of png_set_keep_unknown_chunks(), +where the private "vpAg" chunk will later be processed by a user chunk +callback function: + + png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'}; + + #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) + png_byte unused_chunks[]= + { + 104, 73, 83, 84, (png_byte) '\0', /* hIST */ + 105, 84, 88, 116, (png_byte) '\0', /* iTXt */ + 112, 67, 65, 76, (png_byte) '\0', /* pCAL */ + 115, 67, 65, 76, (png_byte) '\0', /* sCAL */ + 115, 80, 76, 84, (png_byte) '\0', /* sPLT */ + 116, 73, 77, 69, (png_byte) '\0', /* tIME */ + }; + #endif + + ... + + #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) + /* ignore all unknown chunks: */ + png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0); + + /* except for vpAg: */ + png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1); + + /* also ignore unused known chunks: */ + png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks, + (int)sizeof(unused_chunks)/5); + #endif + +User limits + +The PNG specification allows the width and height of an image to be as +large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns. +Since very few applications really need to process such large images, +we have imposed an arbitrary 1-million limit on rows and columns. +Larger images will be rejected immediately with a png_error() call. If +you wish to change this limit, you can use + + png_set_user_limits(png_ptr, width_max, height_max); + +to set your own limits, or use width_max = height_max = 0x7fffffffL +to allow all valid dimensions (libpng may reject some very large images +anyway because of potential buffer overflow conditions). + +You should put this statement after you create the PNG structure and +before calling png_read_info(), png_read_png(), or png_process_data(). + +When writing a PNG datastream, put this statement before calling +png_write_info() or png_write_png(). + +If you need to retrieve the limits that are being applied, use + + width_max = png_get_user_width_max(png_ptr); + height_max = png_get_user_height_max(png_ptr); + +The PNG specification sets no limit on the number of ancillary chunks +allowed in a PNG datastream. You can impose a limit on the total number +of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with + + png_set_chunk_cache_max(png_ptr, user_chunk_cache_max); + +where 0x7fffffffL means unlimited. You can retrieve this limit with + + chunk_cache_max = png_get_chunk_cache_max(png_ptr); + +This limit also applies to the number of buffers that can be allocated +by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks. + +You can also set a limit on the amount of memory that a compressed chunk +other than IDAT can occupy, with + + png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max); + +and you can retrieve the limit with + + chunk_malloc_max = png_get_chunk_malloc_max(png_ptr); + +Any chunks that would cause either of these limits to be exceeded will +be ignored. + +Information about your system + +If you intend to display the PNG or to incorporate it in other image data you +need to tell libpng information about your display or drawing surface so that +libpng can convert the values in the image to match the display. + +From libpng-1.5.4 this information can be set before reading the PNG file +header. In earlier versions png_set_gamma() existed but behaved incorrectly if +called before the PNG file header had been read and png_set_alpha_mode() did not +exist. + +If you need to support versions prior to libpng-1.5.4 test the version number +as illustrated below using "PNG_LIBPNG_VER >= 10504" and follow the procedures +described in the appropriate manual page. + +You give libpng the encoding expected by your system expressed as a 'gamma' +value. You can also specify a default encoding for the PNG file in +case the required information is missing from the file. By default libpng +assumes that the PNG data matches your system, to keep this default call: + + png_set_gamma(png_ptr, screen_gamma, 1/screen_gamma/*file gamma*/); + +or you can use the fixed point equivalent: + + png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma, PNG_FP_1/screen_gamma); + +If you don't know the gamma for your system it is probably 2.2 - a good +approximation to the IEC standard for display systems (sRGB). If images are +too contrasty or washed out you got the value wrong - check your system +documentation! + +Many systems permit the system gamma to be changed via a lookup table in the +display driver, a few systems, including older Macs, change the response by +default. As of 1.5.4 three special values are available to handle common +situations: + + PNG_DEFAULT_sRGB: Indicates that the system conforms to the IEC 61966-2-1 + standard. This matches almost all systems. + PNG_GAMMA_MAC_18: Indicates that the system is an older (pre Mac OS 10.6) + Apple Macintosh system with the default settings. + PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates that the + system expects data with no gamma encoding. + +You would use the linear (unencoded) value if you need to process the pixel +values further because this avoids the need to decode and reencode each +component value whenever arithmetic is performed. A lot of graphics software +uses linear values for this reason, often with higher precision component values +to preserve overall accuracy. + +The second thing you may need to tell libpng about is how your system handles +alpha channel information. Some, but not all, PNG files contain an alpha +channel. To display these files correctly you need to compose the data onto a +suitable background, as described in the PNG specification. + +Libpng only supports composing onto a single color (using png_set_background; +see below). Otherwise you must do the composition yourself and, in this case, +you may need to call png_set_alpha_mode: + + #if PNG_LIBPNG_VER >= 10504 + png_set_alpha_mode(png_ptr, mode, screen_gamma); + #else + png_set_gamma(png_ptr, screen_gamma, 1.0/screen_gamma); + #endif + +The screen_gamma value is the same as the argument to png_set_gamma; however, +how it affects the output depends on the mode. png_set_alpha_mode() sets the +file gamma default to 1/screen_gamma, so normally you don't need to call +png_set_gamma. If you need different defaults call png_set_gamma() before +png_set_alpha_mode() - if you call it after it will override the settings made +by png_set_alpha_mode(). + +The mode is as follows: + + PNG_ALPHA_PNG: The data is encoded according to the PNG specification. Red, +green and blue, or gray, components are gamma encoded color +values and are not premultiplied by the alpha value. The +alpha value is a linear measure of the contribution of the +pixel to the corresponding final output pixel. + +You should normally use this format if you intend to perform +color correction on the color values; most, maybe all, color +correction software has no handling for the alpha channel and, +anyway, the math to handle pre-multiplied component values is +unnecessarily complex. + +Before you do any arithmetic on the component values you need +to remove the gamma encoding and multiply out the alpha +channel. See the PNG specification for more detail. It is +important to note that when an image with an alpha channel is +scaled, linear encoded, pre-multiplied component values must +be used! + +The remaining modes assume you don't need to do any further color correction or +that if you do, your color correction software knows all about alpha (it +probably doesn't!) + + PNG_ALPHA_STANDARD: The data libpng produces +is encoded in the standard way +assumed by most correctly written graphics software. +The gamma encoding will be removed by libpng and the +linear component values will be pre-multiplied by the +alpha channel. + +With this format the final image must be re-encoded to +match the display gamma before the image is displayed. +If your system doesn't do that, yet still seems to +perform arithmetic on the pixels without decoding them, +it is broken - check out the modes below. + +With PNG_ALPHA_STANDARD libpng always produces linear +component values, whatever screen_gamma you supply. The +screen_gamma value is, however, used as a default for +the file gamma if the PNG file has no gamma information. + +If you call png_set_gamma() after png_set_alpha_mode() you +will override the linear encoding. Instead the +pre-multiplied pixel values will be gamma encoded but +the alpha channel will still be linear. This may +actually match the requirements of some broken software, +but it is unlikely. + +While linear 8-bit data is often used it has +insufficient precision for any image with a reasonable +dynamic range. To avoid problems, and if your software +supports it, use png_set_expand_16() to force all +components to 16 bits. + + PNG_ALPHA_OPTIMIZED: This mode is the same +as PNG_ALPHA_STANDARD except that +completely opaque pixels are gamma encoded according to +the screen_gamma value. Pixels with alpha less than 1.0 +will still have linear components. + +Use this format if you have control over your +compositing software and so don't do other arithmetic +(such as scaling) on the data you get from libpng. Your +compositing software can simply copy opaque pixels to +the output but still has linear values for the +non-opaque pixels. + +In normal compositing, where the alpha channel encodes +partial pixel coverage (as opposed to broad area +translucency), the inaccuracies of the 8-bit +representation of non-opaque pixels are irrelevant. + +You can also try this format if your software is broken; +it might look better. + + PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD; +however, all component values, +including the alpha channel are gamma encoded. This is +an appropriate format to try if your software, or more +likely hardware, is totally broken, i.e., if it performs +linear arithmetic directly on gamma encoded values. + +In most cases of broken software or hardware the bug in the final display +manifests as a subtle halo around composited parts of the image. You may not +even perceive this as a halo; the composited part of the image may simply appear +separate from the background, as though it had been cut out of paper and pasted +on afterward. + +If you don't have to deal with bugs in software or hardware, or if you can fix +them, there are three recommended ways of using png_set_alpha_mode(): + + png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG, + screen_gamma); + +You can do color correction on the result (libpng does not currently +support color correction internally). When you handle the alpha channel +you need to undo the gamma encoding and multiply out the alpha. + + png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD, + screen_gamma); + png_set_expand_16(png_ptr); + +If you are using the high level interface, don't call png_set_expand_16(); +instead pass PNG_TRANSFORM_EXPAND_16 to the interface. + +With this mode you can't do color correction, but you can do arithmetic, +including composition and scaling, on the data without further processing. + + png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED, + screen_gamma); + +You can avoid the expansion to 16-bit components with this mode, but you +lose the ability to scale the image or perform other linear arithmetic. +All you can do is compose the result onto a matching output. Since this +mode is libpng-specific you also need to write your own composition +software. + +If you don't need, or can't handle, the alpha channel you can call +png_set_background() to remove it by compositing against a fixed color. Don't +call png_set_strip_alpha() to do this - it will leave spurious pixel values in +transparent parts of this image. + + png_set_background(png_ptr, &background_color, + PNG_BACKGROUND_GAMMA_SCREEN, 0, 1); + +The background_color is an RGB or grayscale value according to the data format +libpng will produce for you. Because you don't yet know the format of the PNG +file, if you call png_set_background at this point you must arrange for the +format produced by libpng to always have 8-bit or 16-bit components and then +store the color as an 8-bit or 16-bit color as appropriate. The color contains +separate gray and RGB component values, so you can let libpng produce gray or +RGB output according to the input format, but low bit depth grayscale images +must always be converted to at least 8-bit format. (Even though low bit depth +grayscale images can't have an alpha channel they can have a transparent +color!) + +You set the transforms you need later, either as flags to the high level +interface or libpng API calls for the low level interface. For reference the +settings and API calls required are: + +8-bit values: + PNG_TRANSFORM_SCALE_16 | PNG_EXPAND + png_set_expand(png_ptr); png_set_scale_16(png_ptr); + + If you must get exactly the same inaccurate results + produced by default in versions prior to libpng-1.5.4, + use PNG_TRANSFORM_STRIP_16 and png_set_strip_16(png_ptr) + instead. + +16-bit values: + PNG_TRANSFORM_EXPAND_16 + png_set_expand_16(png_ptr); + +In either case palette image data will be expanded to RGB. If you just want +color data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr) +to the list. + +Calling png_set_background before the PNG file header is read will not work +prior to libpng-1.5.4. Because the failure may result in unexpected warnings or +errors it is therefore much safer to call png_set_background after the head has +been read. Unfortunately this means that prior to libpng-1.5.4 it cannot be +used with the high level interface. + +The high-level read interface + +At this point there are two ways to proceed; through the high-level +read interface, or through a sequence of low-level read operations. +You can use the high-level interface if (a) you are willing to read +the entire image into memory, and (b) the input transformations +you want to do are limited to the following set: + + PNG_TRANSFORM_IDENTITY No transformation + PNG_TRANSFORM_SCALE_16 Strip 16-bit samples to + 8-bit accurately + PNG_TRANSFORM_STRIP_16 Chop 16-bit samples to + 8-bit less accurately + PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel + PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit + samples to bytes + PNG_TRANSFORM_PACKSWAP Change order of packed + pixels to LSB first + PNG_TRANSFORM_EXPAND Perform set_expand() + PNG_TRANSFORM_INVERT_MONO Invert monochrome images + PNG_TRANSFORM_SHIFT Normalize pixels to the + sBIT depth + PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA + to BGRA + PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA + to AG + PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity + to transparency + PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples + PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples + to RGB (or GA to RGBA) + PNG_TRANSFORM_EXPAND_16 Expand samples to 16 bits + +(This excludes setting a background color, doing gamma transformation, +quantizing, and setting filler.) If this is the case, simply do this: + + png_read_png(png_ptr, info_ptr, png_transforms, NULL) + +where png_transforms is an integer containing the bitwise OR of some +set of transformation flags. This call is equivalent to png_read_info(), +followed the set of transformations indicated by the transform mask, +then png_read_image(), and finally png_read_end(). + +(The final parameter of this call is not yet used. Someday it might point +to transformation parameters required by some future input transform.) + +You must use png_transforms and not call any png_set_transform() functions +when you use png_read_png(). + +After you have called png_read_png(), you can retrieve the image data +with + + row_pointers = png_get_rows(png_ptr, info_ptr); + +where row_pointers is an array of pointers to the pixel data for each row: + + png_bytep row_pointers[height]; + +If you know your image size and pixel size ahead of time, you can allocate +row_pointers prior to calling png_read_png() with + + if (height > PNG_UINT_32_MAX/png_sizeof(png_byte)) + png_error (png_ptr, + "Image is too tall to process in memory"); + + if (width > PNG_UINT_32_MAX/pixel_size) + png_error (png_ptr, + "Image is too wide to process in memory"); + + row_pointers = png_malloc(png_ptr, + height*png_sizeof(png_bytep)); + + for (int i=0; i) and +png_get_(png_ptr, info_ptr, ...) functions return non-zero if the +data has been read, or zero if it is missing. The parameters to the +png_get_ are set directly if they are simple data types, or a +pointer into the info_ptr is returned for any complex types. + +The colorspace data from gAMA, cHRM, sRGB, iCCP, and sBIT chunks +is simply returned to give the application information about how the +image was encoded. Libpng itself only does transformations using the file +gamma when combining semitransparent pixels with the background color. + + png_get_PLTE(png_ptr, info_ptr, &palette, + &num_palette); + + palette - the palette for the file + (array of png_color) + + num_palette - number of entries in the palette + + png_get_gAMA(png_ptr, info_ptr, &file_gamma); + png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma); + + file_gamma - the gamma at which the file was + written (PNG_INFO_gAMA) + + int_file_gamma - 100,000 times the gamma at which the + file is written + + png_get_cHRM(png_ptr, info_ptr, &white_x, &white_y, &red_x, + &red_y, &green_x, &green_y, &blue_x, &blue_y) + png_get_cHRM_XYZ(png_ptr, info_ptr, &red_X, &red_Y, &red_Z, &green_X, + &green_Y, &green_Z, &blue_X, &blue_Y, &blue_Z) + png_get_cHRM_fixed(png_ptr, info_ptr, &int_white_x, &int_white_y, + &int_red_x, &int_red_y, &int_green_x, &int_green_y, + &int_blue_x, &int_blue_y) + png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &int_red_X, &int_red_Y, + &int_red_Z, &int_green_X, &int_green_Y, &int_green_Z, + &int_blue_X, &int_blue_Y, &int_blue_Z) + + {white,red,green,blue}_{x,y} + A color space encoding specified using the + chromaticities of the end points and the + white point. (PNG_INFO_cHRM) + + {red,green,blue}_{X,Y,Z} + A color space encoding specified using the encoding end + points - the CIE tristimulus specification of the intended + color of the red, green and blue channels in the PNG RGB + data. The white point is simply the sum of the three end + points. (PNG_INFO_cHRM) + + png_get_sRGB(png_ptr, info_ptr, &srgb_intent); + + file_srgb_intent - the rendering intent (PNG_INFO_sRGB) + The presence of the sRGB chunk + means that the pixel data is in the + sRGB color space. This chunk also + implies specific values of gAMA and + cHRM. + + png_get_iCCP(png_ptr, info_ptr, &name, + &compression_type, &profile, &proflen); + + name - The profile name. + + compression_type - The compression type; always + PNG_COMPRESSION_TYPE_BASE for PNG 1.0. + You may give NULL to this argument to + ignore it. + + profile - International Color Consortium color + profile data. May contain NULs. + + proflen - length of profile data in bytes. + + png_get_sBIT(png_ptr, info_ptr, &sig_bit); + + sig_bit - the number of significant bits for + (PNG_INFO_sBIT) each of the gray, + red, green, and blue channels, + whichever are appropriate for the + given color type (png_color_16) + + png_get_tRNS(png_ptr, info_ptr, &trans_alpha, + &num_trans, &trans_color); + + trans_alpha - array of alpha (transparency) + entries for palette (PNG_INFO_tRNS) + + num_trans - number of transparent entries + (PNG_INFO_tRNS) + + trans_color - graylevel or color sample values of + the single transparent color for + non-paletted images (PNG_INFO_tRNS) + + png_get_hIST(png_ptr, info_ptr, &hist); + (PNG_INFO_hIST) + + hist - histogram of palette (array of + png_uint_16) + + png_get_tIME(png_ptr, info_ptr, &mod_time); + + mod_time - time image was last modified + (PNG_VALID_tIME) + + png_get_bKGD(png_ptr, info_ptr, &background); + + background - background color (of type + png_color_16p) (PNG_VALID_bKGD) + valid 16-bit red, green and blue + values, regardless of color_type + + num_comments = png_get_text(png_ptr, info_ptr, + &text_ptr, &num_text); + + num_comments - number of comments + + text_ptr - array of png_text holding image + comments + + text_ptr[i].compression - type of compression used + on "text" PNG_TEXT_COMPRESSION_NONE + PNG_TEXT_COMPRESSION_zTXt + PNG_ITXT_COMPRESSION_NONE + PNG_ITXT_COMPRESSION_zTXt + + text_ptr[i].key - keyword for comment. Must contain + 1-79 characters. + + text_ptr[i].text - text comments for current + keyword. Can be empty. + + text_ptr[i].text_length - length of text string, + after decompression, 0 for iTXt + + text_ptr[i].itxt_length - length of itxt string, + after decompression, 0 for tEXt/zTXt + + text_ptr[i].lang - language of comment (empty + string for unknown). + + text_ptr[i].lang_key - keyword in UTF-8 + (empty string for unknown). + + Note that the itxt_length, lang, and lang_key + members of the text_ptr structure only exist when the + library is built with iTXt chunk support. Prior to + libpng-1.4.0 the library was built by default without + iTXt support. Also note that when iTXt is supported, + they contain NULL pointers when the "compression" + field contains PNG_TEXT_COMPRESSION_NONE or + PNG_TEXT_COMPRESSION_zTXt. + + num_text - number of comments (same as + num_comments; you can put NULL here + to avoid the duplication) + + Note while png_set_text() will accept text, language, + and translated keywords that can be NULL pointers, the + structure returned by png_get_text will always contain + regular zero-terminated C strings. They might be + empty strings but they will never be NULL pointers. + + num_spalettes = png_get_sPLT(png_ptr, info_ptr, + &palette_ptr); + + num_spalettes - number of sPLT chunks read. + + palette_ptr - array of palette structures holding + contents of one or more sPLT chunks + read. + + png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y, + &unit_type); + + offset_x - positive offset from the left edge + of the screen (can be negative) + + offset_y - positive offset from the top edge + of the screen (can be negative) + + unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER + + png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, + &unit_type); + + res_x - pixels/unit physical resolution in + x direction + + res_y - pixels/unit physical resolution in + x direction + + unit_type - PNG_RESOLUTION_UNKNOWN, + PNG_RESOLUTION_METER + + png_get_sCAL(png_ptr, info_ptr, &unit, &width, + &height) + + unit - physical scale units (an integer) + + width - width of a pixel in physical scale units + + height - height of a pixel in physical scale units + (width and height are doubles) + + png_get_sCAL_s(png_ptr, info_ptr, &unit, &width, + &height) + + unit - physical scale units (an integer) + + width - width of a pixel in physical scale units + (expressed as a string) + + height - height of a pixel in physical scale units + (width and height are strings like "2.54") + + num_unknown_chunks = png_get_unknown_chunks(png_ptr, + info_ptr, &unknowns) + + unknowns - array of png_unknown_chunk + structures holding unknown chunks + + unknowns[i].name - name of unknown chunk + + unknowns[i].data - data of unknown chunk + + unknowns[i].size - size of unknown chunk's data + + unknowns[i].location - position of chunk in file + + The value of "i" corresponds to the order in which the + chunks were read from the PNG file or inserted with the + png_set_unknown_chunks() function. + + The value of "location" is a bitwise "or" of + + PNG_HAVE_IHDR (0x01) + PNG_HAVE_PLTE (0x02) + PNG_AFTER_IDAT (0x08) + +The data from the pHYs chunk can be retrieved in several convenient +forms: + + res_x = png_get_x_pixels_per_meter(png_ptr, + info_ptr) + + res_y = png_get_y_pixels_per_meter(png_ptr, + info_ptr) + + res_x_and_y = png_get_pixels_per_meter(png_ptr, + info_ptr) + + res_x = png_get_x_pixels_per_inch(png_ptr, + info_ptr) + + res_y = png_get_y_pixels_per_inch(png_ptr, + info_ptr) + + res_x_and_y = png_get_pixels_per_inch(png_ptr, + info_ptr) + + aspect_ratio = png_get_pixel_aspect_ratio(png_ptr, + info_ptr) + + Each of these returns 0 [signifying "unknown"] if + the data is not present or if res_x is 0; + res_x_and_y is 0 if res_x != res_y + + Note that because of the way the resolutions are + stored internally, the inch conversions won't + come out to exactly even number. For example, + 72 dpi is stored as 0.28346 pixels/meter, and + when this is retrieved it is 71.9988 dpi, so + be sure to round the returned value appropriately + if you want to display a reasonable-looking result. + +The data from the oFFs chunk can be retrieved in several convenient +forms: + + x_offset = png_get_x_offset_microns(png_ptr, info_ptr); + + y_offset = png_get_y_offset_microns(png_ptr, info_ptr); + + x_offset = png_get_x_offset_inches(png_ptr, info_ptr); + + y_offset = png_get_y_offset_inches(png_ptr, info_ptr); + + Each of these returns 0 [signifying "unknown" if both + x and y are 0] if the data is not present or if the + chunk is present but the unit is the pixel. The + remark about inexact inch conversions applies here + as well, because a value in inches can't always be + converted to microns and back without some loss + of precision. + +For more information, see the +PNG specification for chunk contents. Be careful with trusting +rowbytes, as some of the transformations could increase the space +needed to hold a row (expand, filler, gray_to_rgb, etc.). +See png_read_update_info(), below. + +A quick word about text_ptr and num_text. PNG stores comments in +keyword/text pairs, one pair per chunk, with no limit on the number +of text chunks, and a 2^31 byte limit on their size. While there are +suggested keywords, there is no requirement to restrict the use to these +strings. It is strongly suggested that keywords and text be sensible +to humans (that's the point), so don't use abbreviations. Non-printing +symbols are not allowed. See the PNG specification for more details. +There is also no requirement to have text after the keyword. + +Keywords should be limited to 79 Latin-1 characters without leading or +trailing spaces, but non-consecutive spaces are allowed within the +keyword. It is possible to have the same keyword any number of times. +The text_ptr is an array of png_text structures, each holding a +pointer to a language string, a pointer to a keyword and a pointer to +a text string. The text string, language code, and translated +keyword may be empty or NULL pointers. The keyword/text +pairs are put into the array in the order that they are received. +However, some or all of the text chunks may be after the image, so, to +make sure you have read all the text chunks, don't mess with these +until after you read the stuff after the image. This will be +mentioned again below in the discussion that goes with png_read_end(). + +Input transformations + +After you've read the header information, you can set up the library +to handle any special transformations of the image data. The various +ways to transform the data will be described in the order that they +should occur. This is important, as some of these change the color +type and/or bit depth of the data, and some others only work on +certain color types and bit depths. + +Transformations you request are ignored if they don't have any meaning for a +particular input data format. However some transformations can have an effect +as a result of a previous transformation. If you specify a contradictory set of +transformations, for example both adding and removing the alpha channel, you +cannot predict the final result. + +The color used for the transparency values should be supplied in the same +format/depth as the current image data. It is stored in the same format/depth +as the image data in a tRNS chunk, so this is what libpng expects for this data. + +The color used for the background value depends on the need_expand argument as +described below. + +Data will be decoded into the supplied row buffers packed into bytes +unless the library has been told to transform it into another format. +For example, 4 bit/pixel paletted or grayscale data will be returned +2 pixels/byte with the leftmost pixel in the high-order bits of the +byte, unless png_set_packing() is called. 8-bit RGB data will be stored +in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha() +is called to insert filler bytes, either before or after each RGB triplet. +16-bit RGB data will be returned RRGGBB RRGGBB, with the most significant +byte of the color value first, unless png_set_scale_16() is called to +transform it to regular RGB RGB triplets, or png_set_filler() or +png_set_add alpha() is called to insert filler bytes, either before or +after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can +be modified with png_set_filler(), png_set_add_alpha(), png_set_strip_16(), +or png_set_scale_16(). + +The following code transforms grayscale images of less than 8 to 8 bits, +changes paletted images to RGB, and adds a full alpha channel if there is +transparency information in a tRNS chunk. This is most useful on +grayscale images with bit depths of 2 or 4 or if there is a multiple-image +viewing application that wishes to treat all images in the same way. + + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_palette_to_rgb(png_ptr); + + if (png_get_valid(png_ptr, info_ptr, + PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr); + + if (color_type == PNG_COLOR_TYPE_GRAY && + bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr); + +The first two functions are actually aliases for png_set_expand(), added +in libpng version 1.0.4, with the function names expanded to improve code +readability. In some future version they may actually do different +things. + +As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was +added. It expands the sample depth without changing tRNS to alpha. + +As of libpng version 1.5.2, png_set_expand_16() was added. It behaves as +png_set_expand(); however, the resultant channels have 16 bits rather than 8. +Use this when the output color or gray channels are made linear to avoid fairly +severe accuracy loss. + + if (bit_depth < 16) + png_set_expand_16(png_ptr); + +PNG can have files with 16 bits per channel. If you only can handle +8 bits per channel, this will strip the pixels down to 8-bit. + + if (bit_depth == 16) +#if PNG_LIBPNG_VER >= 10504 + png_set_scale_16(png_ptr); +#else + png_set_strip_16(png_ptr); +#endif + +(The more accurate "png_set_scale_16()" API became available in libpng version +1.5.4). + +If you need to process the alpha channel on the image separately from the image +data (for example if you convert it to a bitmap mask) it is possible to have +libpng strip the channel leaving just RGB or gray data: + + if (color_type & PNG_COLOR_MASK_ALPHA) + png_set_strip_alpha(png_ptr); + +If you strip the alpha channel you need to find some other way of dealing with +the information. If, instead, you want to convert the image to an opaque +version with no alpha channel use png_set_background; see below. + +As of libpng version 1.5.2, almost all useful expansions are supported, the +major ommissions are conversion of grayscale to indexed images (which can be +done trivially in the application) and conversion of indexed to grayscale (which +can be done by a trivial manipulation of the palette.) + +In the following table, the 01 means grayscale with depth<8, 31 means +indexed with depth<8, other numerals represent the color type, "T" means +the tRNS chunk is present, A means an alpha channel is present, and O +means tRNS or alpha is present but all pixels in the image are opaque. + + FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O + TO + 01 - [G] - - - - - - - - - - - - - + 31 [Q] Q [Q] [Q] [Q] Q Q Q Q Q Q [Q] [Q] Q Q + 0 1 G + . . G G G G G G B B GB GB + 0T lt Gt t + . Gt G G Gt G G Bt Bt GBt GBt + 0O lt Gt t . + Gt Gt G Gt Gt G Bt Bt GBt GBt + 2 C P C C C + . . C - - CB CB B B + 2T Ct - Ct C C t + t - - - CBt CBt Bt Bt + 2O Ct - Ct C C t t + - - - CBt CBt Bt Bt + 3 [Q] p [Q] [Q] [Q] Q Q Q + . . [Q] [Q] Q Q + 3T [Qt] p [Qt][Q] [Q] Qt Qt Qt t + t [Qt][Qt] Qt Qt + 3O [Qt] p [Qt][Q] [Q] Qt Qt Qt t t + [Qt][Qt] Qt Qt + 4A lA G A T T GA GT GT GA GT GT + BA G GBA + 4O lA GBA A T T GA GT GT GA GT GT BA + GBA G + 6A CA PA CA C C A T tT PA P P C CBA + BA + 6O CA PBA CA C C A tT T PA P P CBA C BA + + +Within the matrix, + "+" identifies entries where 'from' and 'to' are the same. + "-" means the transformation is not supported. + "." means nothing is necessary (a tRNS chunk can just be ignored). + "t" means the transformation is obtained by png_set_tRNS. + "A" means the transformation is obtained by png_set_add_alpha(). + "X" means the transformation is obtained by png_set_expand(). + "1" means the transformation is obtained by + png_set_expand_gray_1_2_4_to_8() (and by png_set_expand() + if there is no transparency in the original or the final + format). + "C" means the transformation is obtained by png_set_gray_to_rgb(). + "G" means the transformation is obtained by png_set_rgb_to_gray(). + "P" means the transformation is obtained by + png_set_expand_palette_to_rgb(). + "p" means the transformation is obtained by png_set_packing(). + "Q" means the transformation is obtained by png_set_quantize(). + "T" means the transformation is obtained by + png_set_tRNS_to_alpha(). + "B" means the transformation is obtained by + png_set_background(), or png_strip_alpha(). + +When an entry has multiple transforms listed all are required to cause the +right overall transformation. When two transforms are separated by a comma +either will do the job. When transforms are enclosed in [] the transform should +do the job but this is currently unimplemented - a different format will result +if the suggested transformations are used. + +In PNG files, the alpha channel in an image +is the level of opacity. If you need the alpha channel in an image to +be the level of transparency instead of opacity, you can invert the +alpha channel (or the tRNS chunk data) after it's read, so that 0 is +fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit +images) is fully transparent, with + + png_set_invert_alpha(png_ptr); + +PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as +they can, resulting in, for example, 8 pixels per byte for 1 bit +files. This code expands to 1 pixel per byte without changing the +values of the pixels: + + if (bit_depth < 8) + png_set_packing(png_ptr); + +PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels +stored in a PNG image have been "scaled" or "shifted" up to the next +higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] +to 8 bits/sample in the range [0, 255]). However, it is also possible +to convert the PNG pixel data back to the original bit depth of the +image. This call reduces the pixels back down to the original bit depth: + + png_color_8p sig_bit; + + if (png_get_sBIT(png_ptr, info_ptr, &sig_bit)) + png_set_shift(png_ptr, sig_bit); + +PNG files store 3-color pixels in red, green, blue order. This code +changes the storage of the pixels to blue, green, red: + + if (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) + png_set_bgr(png_ptr); + +PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them +into 4 or 8 bytes for windowing systems that need them in this format: + + if (color_type == PNG_COLOR_TYPE_RGB) + png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE); + +where "filler" is the 8 or 16-bit number to fill with, and the location is +either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether +you want the filler before the RGB or after. This transformation +does not affect images that already have full alpha channels. To add an +opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which +will generate RGBA pixels. + +Note that png_set_filler() does not change the color type. If you want +to do that, you can add a true alpha channel with + + if (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_GRAY) + png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER); + +where "filler" contains the alpha value to assign to each pixel. +This function was added in libpng-1.2.7. + +If you are reading an image with an alpha channel, and you need the +data as ARGB instead of the normal PNG format RGBA: + + if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) + png_set_swap_alpha(png_ptr); + +For some uses, you may want a grayscale image to be represented as +RGB. This code will do that conversion: + + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_gray_to_rgb(png_ptr); + +Conversely, you can convert an RGB or RGBA image to grayscale or grayscale +with alpha. + + if (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) + png_set_rgb_to_gray(png_ptr, error_action, + double red_weight, double green_weight); + + error_action = 1: silently do the conversion + + error_action = 2: issue a warning if the original + image has any pixel where + red != green or red != blue + + error_action = 3: issue an error and abort the + conversion if the original + image has any pixel where + red != green or red != blue + + red_weight: weight of red component + + green_weight: weight of green component + If either weight is negative, default + weights are used. + +In the corresponding fixed point API the red_weight and green_weight values are +simply scaled by 100,000: + + png_set_rgb_to_gray(png_ptr, error_action, + png_fixed_point red_weight, + png_fixed_point green_weight); + +If you have set error_action = 1 or 2, you can +later check whether the image really was gray, after processing +the image rows, with the png_get_rgb_to_gray_status(png_ptr) function. +It will return a png_byte that is zero if the image was gray or +1 if there were any non-gray pixels. Background and sBIT data +will be silently converted to grayscale, using the green channel +data for sBIT, regardless of the error_action setting. + +The default values come from the PNG file cHRM chunk if present; otherwise, the +defaults correspond to the ITU-R recommendation 709, and also the sRGB color +space, as recommended in the Charles Poynton's Colour FAQ, +, in section 9: + + + + Y = 0.2126 * R + 0.7152 * G + 0.0722 * B + +Previous versions of this document, 1998 through 2002, recommended a slightly +different formula: + + Y = 0.212671 * R + 0.715160 * G + 0.072169 * B + +Libpng uses an integer approximation: + + Y = (6968 * R + 23434 * G + 2366 * B)/32768 + +The calculation is done in a linear colorspace, if the image gamma +can be determined. + +The png_set_background() function has been described already; it tells libpng to +composite images with alpha or simple transparency against the supplied +background color. For compatibility with versions of libpng earlier than +libpng-1.5.4 it is recommended that you call the function after reading the file +header, even if you don't want to use the color in a bKGD chunk, if one exists. + +If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid), +you may use this color, or supply another color more suitable for +the current display (e.g., the background color from a web page). You +need to tell libpng how the color is represented, both the format of the +component values in the color (the number of bits) and the gamma encoding of the +color. The function takes two arguments, background_gamma_mode and need_expand +to convey this information; however, only two combinations are likely to be +useful: + + png_color_16 my_background; + png_color_16p image_background; + + if (png_get_bKGD(png_ptr, info_ptr, &image_background)) + png_set_background(png_ptr, image_background, + PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1); + else + png_set_background(png_ptr, &my_background, + PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1); + +The second call was described above - my_background is in the format of the +final, display, output produced by libpng. Because you now know the format of +the PNG it is possible to avoid the need to choose either 8-bit or 16-bit +output and to retain palette images (the palette colors will be modified +appropriately and the tRNS chunk removed.) However, if you are doing this, +take great care not to ask for transformations without checking first that +they apply! + +In the first call the background color has the original bit depth and color type +of the PNG file. So, for palette images the color is supplied as a palette +index and for low bit greyscale images the color is a reduced bit value in +image_background->gray. + +If you didn't call png_set_gamma() before reading the file header, for example +if you need your code to remain compatible with older versions of libpng prior +to libpng-1.5.4, this is the place to call it. + +Do not call it if you called png_set_alpha_mode(); doing so will damage the +settings put in place by png_set_alpha_mode(). (If png_set_alpha_mode() is +supported then you can certainly do png_set_gamma() before reading the PNG +header.) + +This API unconditionally sets the screen and file gamma values, so it will +override the value in the PNG file unless it is called before the PNG file +reading starts. For this reason you must always call it with the PNG file +value when you call it in this position: + + if (png_get_gAMA(png_ptr, info_ptr, &file_gamma)) + png_set_gamma(png_ptr, screen_gamma, file_gamma); + + else + png_set_gamma(png_ptr, screen_gamma, 0.45455); + +If you need to reduce an RGB file to a paletted file, or if a paletted +file has more entries then will fit on your screen, png_set_quantize() +will do that. Note that this is a simple match quantization that merely +finds the closest color available. This should work fairly well with +optimized palettes, but fairly badly with linear color cubes. If you +pass a palette that is larger than maximum_colors, the file will +reduce the number of colors in the palette so it will fit into +maximum_colors. If there is a histogram, libpng will use it to make +more intelligent choices when reducing the palette. If there is no +histogram, it may not do as good a job. + + if (color_type & PNG_COLOR_MASK_COLOR) + { + if (png_get_valid(png_ptr, info_ptr, + PNG_INFO_PLTE)) + { + png_uint_16p histogram = NULL; + + png_get_hIST(png_ptr, info_ptr, + &histogram); + png_set_quantize(png_ptr, palette, num_palette, + max_screen_colors, histogram, 1); + } + + else + { + png_color std_color_cube[MAX_SCREEN_COLORS] = + { ... colors ... }; + + png_set_quantize(png_ptr, std_color_cube, + MAX_SCREEN_COLORS, MAX_SCREEN_COLORS, + NULL,0); + } + } + +PNG files describe monochrome as black being zero and white being one. +The following code will reverse this (make black be one and white be +zero): + + if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY) + png_set_invert_mono(png_ptr); + +This function can also be used to invert grayscale and gray-alpha images: + + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_invert_mono(png_ptr); + +PNG files store 16-bit pixels in network byte order (big-endian, +ie. most significant bits first). This code changes the storage to the +other way (little-endian, i.e. least significant bits first, the +way PCs store them): + + if (bit_depth == 16) + png_set_swap(png_ptr); + +If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you +need to change the order the pixels are packed into bytes, you can use: + + if (bit_depth < 8) + png_set_packswap(png_ptr); + +Finally, you can write your own transformation function if none of +the existing ones meets your needs. This is done by setting a callback +with + + png_set_read_user_transform_fn(png_ptr, + read_transform_fn); + +You must supply the function + + void read_transform_fn(png_structp png_ptr, png_row_infop + row_info, png_bytep data) + +See pngtest.c for a working example. Your function will be called +after all of the other transformations have been processed. Take care with +interlaced images if you do the interlace yourself - the width of the row is the +width in 'row_info', not the overall image width. + +If supported, libpng provides two information routines that you can use to find +where you are in processing the image: + + png_get_current_pass_number(png_structp png_ptr); + png_get_current_row_number(png_structp png_ptr); + +Don't try using these outside a transform callback - firstly they are only +supported if user transforms are supported, secondly they may well return +unexpected results unless the row is actually being processed at the moment they +are called. + +With interlaced +images the value returned is the row in the input sub-image image. Use +PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to +find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass). + +The discussion of interlace handling above contains more information on how to +use these values. + +You can also set up a pointer to a user structure for use by your +callback function, and you can inform libpng that your transform +function will change the number of channels or bit depth with the +function + + png_set_user_transform_info(png_ptr, user_ptr, + user_depth, user_channels); + +The user's application, not libpng, is responsible for allocating and +freeing any memory required for the user structure. + +You can retrieve the pointer via the function +png_get_user_transform_ptr(). For example: + + voidp read_user_transform_ptr = + png_get_user_transform_ptr(png_ptr); + +The last thing to handle is interlacing; this is covered in detail below, +but you must call the function here if you want libpng to handle expansion +of the interlaced image. + + number_of_passes = png_set_interlace_handling(png_ptr); + +After setting the transformations, libpng can update your png_info +structure to reflect any transformations you've requested with this +call. + + png_read_update_info(png_ptr, info_ptr); + +This is most useful to update the info structure's rowbytes +field so you can use it to allocate your image memory. This function +will also update your palette with the correct screen_gamma and +background if these have been given with the calls above. You may +only call png_read_update_info() once with a particular info_ptr. + +After you call png_read_update_info(), you can allocate any +memory you need to hold the image. The row data is simply +raw byte data for all forms of images. As the actual allocation +varies among applications, no example will be given. If you +are allocating one large chunk, you will need to build an +array of pointers to each row, as it will be needed for some +of the functions below. + +Remember: Before you call png_read_update_info(), the png_get_*() +functions return the values corresponding to the original PNG image. +After you call png_read_update_info the values refer to the image +that libpng will output. Consequently you must call all the png_set_ +functions before you call png_read_update_info(). This is particularly +important for png_set_interlace_handling() - if you are going to call +png_read_update_info() you must call png_set_interlace_handling() before +it unless you want to receive interlaced output. + +Reading image data + +After you've allocated memory, you can read the image data. +The simplest way to do this is in one function call. If you are +allocating enough memory to hold the whole image, you can just +call png_read_image() and libpng will read in all the image data +and put it in the memory area supplied. You will need to pass in +an array of pointers to each row. + +This function automatically handles interlacing, so you don't +need to call png_set_interlace_handling() (unless you call +png_read_update_info()) or call this function multiple times, or any +of that other stuff necessary with png_read_rows(). + + png_read_image(png_ptr, row_pointers); + +where row_pointers is: + + png_bytep row_pointers[height]; + +You can point to void or char or whatever you use for pixels. + +If you don't want to read in the whole image at once, you can +use png_read_rows() instead. If there is no interlacing (check +interlace_type == PNG_INTERLACE_NONE), this is simple: + + png_read_rows(png_ptr, row_pointers, NULL, + number_of_rows); + +where row_pointers is the same as in the png_read_image() call. + +If you are doing this just one row at a time, you can do this with +a single row_pointer instead of an array of row_pointers: + + png_bytep row_pointer = row; + png_read_row(png_ptr, row_pointer, NULL); + +If the file is interlaced (interlace_type != 0 in the IHDR chunk), things +get somewhat harder. The only current (PNG Specification version 1.2) +interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7); +a somewhat complicated 2D interlace scheme, known as Adam7, that +breaks down an image into seven smaller images of varying size, based +on an 8x8 grid. This number is defined (from libpng 1.5) as +PNG_INTERLACE_ADAM7_PASSES in png.h + +libpng can fill out those images or it can give them to you "as is". +It is almost always better to have libpng handle the interlacing for you. +If you want the images filled out, there are two ways to do that. The one +mentioned in the PNG specification is to expand each pixel to cover +those pixels that have not been read yet (the "rectangle" method). +This results in a blocky image for the first pass, which gradually +smooths out as more pixels are read. The other method is the "sparkle" +method, where pixels are drawn only in their final locations, with the +rest of the image remaining whatever colors they were initialized to +before the start of the read. The first method usually looks better, +but tends to be slower, as there are more pixels to put in the rows. + +If, as is likely, you want libpng to expand the images, call this before +calling png_start_read_image() or png_read_update_info(): + + if (interlace_type == PNG_INTERLACE_ADAM7) + number_of_passes + = png_set_interlace_handling(png_ptr); + +This will return the number of passes needed. Currently, this is seven, +but may change if another interlace type is added. This function can be +called even if the file is not interlaced, where it will return one pass. +You then need to read the whole image 'number_of_passes' times. Each time +will distribute the pixels from the current pass to the correct place in +the output image, so you need to supply the same rows to png_read_rows in +each pass. + +If you are not going to display the image after each pass, but are +going to wait until the entire image is read in, use the sparkle +effect. This effect is faster and the end result of either method +is exactly the same. If you are planning on displaying the image +after each pass, the "rectangle" effect is generally considered the +better looking one. + +If you only want the "sparkle" effect, just call png_read_rows() as +normal, with the third parameter NULL. Make sure you make pass over +the image number_of_passes times, and you don't change the data in the +rows between calls. You can change the locations of the data, just +not the data. Each pass only writes the pixels appropriate for that +pass, and assumes the data from previous passes is still valid. + + png_read_rows(png_ptr, row_pointers, NULL, + number_of_rows); + +If you only want the first effect (the rectangles), do the same as +before except pass the row buffer in the third parameter, and leave +the second parameter NULL. + + png_read_rows(png_ptr, NULL, row_pointers, + number_of_rows); + +If you don't want libpng to handle the interlacing details, just call +png_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images. +Each of the images is a valid image by itself; however, you will almost +certainly need to distribute the pixels from each sub-image to the +correct place. This is where everything gets very tricky. + +If you want to retrieve the separate images you must pass the correct +number of rows to each successive call of png_read_rows(). The calculation +gets pretty complicated for small images, where some sub-images may +not even exist because either their width or height ends up zero. +libpng provides two macros to help you in 1.5 and later versions: + + png_uint_32 width = PNG_PASS_COLS(image_width, pass_number); + png_uint_32 height = PNG_PASS_ROWS(image_height, pass_number); + +Respectively these tell you the width and height of the sub-image +corresponding to the numbered pass. 'pass' is in in the range 0 to 6 - +this can be confusing because the specification refers to the same passes +as 1 to 7! Be careful, you must check both the width and height before +calling png_read_rows() and not call it for that pass if either is zero. + +You can, of course, read each sub-image row by row. If you want to +produce optimal code to make a pixel-by-pixel transformation of an +interlaced image this is the best approach; read each row of each pass, +transform it, and write it out to a new interlaced image. + +If you want to de-interlace the image yourself libpng provides further +macros to help that tell you where to place the pixels in the output image. +Because the interlacing scheme is rectangular - sub-image pixels are always +arranged on a rectangular grid - all you need to know for each pass is the +starting column and row in the output image of the first pixel plus the +spacing between each pixel. As of libpng 1.5 there are four macros to +retrieve this information: + + png_uint_32 x = PNG_PASS_START_COL(pass); + png_uint_32 y = PNG_PASS_START_ROW(pass); + png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass); + png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass); + +These allow you to write the obvious loop: + + png_uint_32 input_y = 0; + png_uint_32 output_y = PNG_PASS_START_ROW(pass); + + while (output_y < output_image_height) + { + png_uint_32 input_x = 0; + png_uint_32 output_x = PNG_PASS_START_COL(pass); + + while (output_x < output_image_width) + { + image[output_y][output_x] = + subimage[pass][input_y][input_x++]; + + output_x += xStep; + } + + ++input_y; + output_y += yStep; + } + +Notice that the steps between successive output rows and columns are +returned as shifts. This is possible because the pixels in the subimages +are always a power of 2 apart - 1, 2, 4 or 8 pixels - in the original +image. In practice you may need to directly calculate the output coordinate +given an input coordinate. libpng provides two further macros for this +purpose: + + png_uint_32 output_x = PNG_COL_FROM_PASS_COL(input_x, pass); + png_uint_32 output_y = PNG_ROW_FROM_PASS_ROW(input_y, pass); + +Finally a pair of macros are provided to tell you if a particular image +row or column appears in a given pass: + + int col_in_pass = PNG_COL_IN_INTERLACE_PASS(output_x, pass); + int row_in_pass = PNG_ROW_IN_INTERLACE_PASS(output_y, pass); + +Bear in mind that you will probably also need to check the width and height +of the pass in addition to the above to be sure the pass even exists! + +With any luck you are convinced by now that you don't want to do your own +interlace handling. In reality normally the only good reason for doing this +is if you are processing PNG files on a pixel-by-pixel basis and don't want +to load the whole file into memory when it is interlaced. + +libpng includes a test program, pngvalid, that illustrates reading and +writing of interlaced images. If you can't get interlacing to work in your +code and don't want to leave it to libpng (the recommended approach), see +how pngvalid.c does it. + +Finishing a sequential read + +After you are finished reading the image through the +low-level interface, you can finish reading the file. If you are +interested in comments or time, which may be stored either before or +after the image data, you should pass the separate png_info struct if +you want to keep the comments from before and after the image +separate. + + png_infop end_info = png_create_info_struct(png_ptr); + + if (!end_info) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + return (ERROR); + } + + png_read_end(png_ptr, end_info); + +If you are not interested, you should still call png_read_end() +but you can pass NULL, avoiding the need to create an end_info structure. + + png_read_end(png_ptr, (png_infop)NULL); + +If you don't call png_read_end(), then your file pointer will be +left pointing to the first chunk after the last IDAT, which is probably +not what you want if you expect to read something beyond the end of +the PNG datastream. + +When you are done, you can free all memory allocated by libpng like this: + + png_destroy_read_struct(&png_ptr, &info_ptr, + &end_info); + +or, if you didn't create an end_info structure, + + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + +It is also possible to individually free the info_ptr members that +point to libpng-allocated storage with the following function: + + png_free_data(png_ptr, info_ptr, mask, seq) + + mask - identifies data to be freed, a mask + containing the bitwise OR of one or + more of + PNG_FREE_PLTE, PNG_FREE_TRNS, + PNG_FREE_HIST, PNG_FREE_ICCP, + PNG_FREE_PCAL, PNG_FREE_ROWS, + PNG_FREE_SCAL, PNG_FREE_SPLT, + PNG_FREE_TEXT, PNG_FREE_UNKN, + or simply PNG_FREE_ALL + + seq - sequence number of item to be freed + (-1 for all items) + +This function may be safely called when the relevant storage has +already been freed, or has not yet been allocated, or was allocated +by the user and not by libpng, and will in those cases do nothing. +The "seq" parameter is ignored if only one item of the selected data +type, such as PLTE, is allowed. If "seq" is not -1, and multiple items +are allowed for the data type identified in the mask, such as text or +sPLT, only the n'th item in the structure is freed, where n is "seq". + +The default behavior is only to free data that was allocated internally +by libpng. This can be changed, so that libpng will not free the data, +or so that it will free data that was allocated by the user with png_malloc() +or png_calloc() and passed in via a png_set_*() function, with + + png_data_freer(png_ptr, info_ptr, freer, mask) + + freer - one of + PNG_DESTROY_WILL_FREE_DATA + PNG_SET_WILL_FREE_DATA + PNG_USER_WILL_FREE_DATA + + mask - which data elements are affected + same choices as in png_free_data() + +This function only affects data that has already been allocated. +You can call this function after reading the PNG data but before calling +any png_set_*() functions, to control whether the user or the png_set_*() +function is responsible for freeing any existing data that might be present, +and again after the png_set_*() functions to control whether the user +or png_destroy_*() is supposed to free the data. When the user assumes +responsibility for libpng-allocated data, the application must use +png_free() to free it, and when the user transfers responsibility to libpng +for data that the user has allocated, the user must have used png_malloc() +or png_calloc() to allocate it. + +If you allocated your row_pointers in a single block, as suggested above in +the description of the high level read interface, you must not transfer +responsibility for freeing it to the png_set_rows or png_read_destroy function, +because they would also try to free the individual row_pointers[i]. + +If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword +separately, do not transfer responsibility for freeing text_ptr to libpng, +because when libpng fills a png_text structure it combines these members with +the key member, and png_free_data() will free only text_ptr.key. Similarly, +if you transfer responsibility for free'ing text_ptr from libpng to your +application, your application must not separately free those members. + +The png_free_data() function will turn off the "valid" flag for anything +it frees. If you need to turn the flag off for a chunk that was freed by +your application instead of by libpng, you can use + + png_set_invalid(png_ptr, info_ptr, mask); + + mask - identifies the chunks to be made invalid, + containing the bitwise OR of one or + more of + PNG_INFO_gAMA, PNG_INFO_sBIT, + PNG_INFO_cHRM, PNG_INFO_PLTE, + PNG_INFO_tRNS, PNG_INFO_bKGD, + PNG_INFO_hIST, PNG_INFO_pHYs, + PNG_INFO_oFFs, PNG_INFO_tIME, + PNG_INFO_pCAL, PNG_INFO_sRGB, + PNG_INFO_iCCP, PNG_INFO_sPLT, + PNG_INFO_sCAL, PNG_INFO_IDAT + +For a more compact example of reading a PNG image, see the file example.c. + +Reading PNG files progressively + +The progressive reader is slightly different then the non-progressive +reader. Instead of calling png_read_info(), png_read_rows(), and +png_read_end(), you make one call to png_process_data(), which calls +callbacks when it has the info, a row, or the end of the image. You +set up these callbacks with png_set_progressive_read_fn(). You don't +have to worry about the input/output functions of libpng, as you are +giving the library the data directly in png_process_data(). I will +assume that you have read the section on reading PNG files above, +so I will only highlight the differences (although I will show +all of the code). + +png_structp png_ptr; +png_infop info_ptr; + + /* An example code fragment of how you would + initialize the progressive reader in your + application. */ + int + initialize_png_reader() + { + png_ptr = png_create_read_struct + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn); + + if (!png_ptr) + return (ERROR); + + info_ptr = png_create_info_struct(png_ptr); + + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr, + (png_infopp)NULL, (png_infopp)NULL); + return (ERROR); + } + + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + return (ERROR); + } + + /* This one's new. You can provide functions + to be called when the header info is valid, + when each row is completed, and when the image + is finished. If you aren't using all functions, + you can specify NULL parameters. Even when all + three functions are NULL, you need to call + png_set_progressive_read_fn(). You can use + any struct as the user_ptr (cast to a void pointer + for the function call), and retrieve the pointer + from inside the callbacks using the function + + png_get_progressive_ptr(png_ptr); + + which will return a void pointer, which you have + to cast appropriately. + */ + png_set_progressive_read_fn(png_ptr, (void *)user_ptr, + info_callback, row_callback, end_callback); + + return 0; + } + + /* A code fragment that you call as you receive blocks + of data */ + int + process_data(png_bytep buffer, png_uint_32 length) + { + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + return (ERROR); + } + + /* This one's new also. Simply give it a chunk + of data from the file stream (in order, of + course). On machines with segmented memory + models machines, don't give it any more than + 64K. The library seems to run fine with sizes + of 4K. Although you can give it much less if + necessary (I assume you can give it chunks of + 1 byte, I haven't tried less then 256 bytes + yet). When this function returns, you may + want to display any rows that were generated + in the row callback if you don't already do + so there. + */ + png_process_data(png_ptr, info_ptr, buffer, length); + + /* At this point you can call png_process_data_skip if + you want to handle data the library will skip yourself; + it simply returns the number of bytes to skip (and stops + libpng skipping that number of bytes on the next + png_process_data call). + return 0; + } + + /* This function is called (as set by + png_set_progressive_read_fn() above) when enough data + has been supplied so all of the header has been + read. + */ + void + info_callback(png_structp png_ptr, png_infop info) + { + /* Do any setup here, including setting any of + the transformations mentioned in the Reading + PNG files section. For now, you _must_ call + either png_start_read_image() or + png_read_update_info() after all the + transformations are set (even if you don't set + any). You may start getting rows before + png_process_data() returns, so this is your + last chance to prepare for that. + + This is where you turn on interlace handling, + assuming you don't want to do it yourself. + + If you need to you can stop the processing of + your original input data at this point by calling + png_process_data_pause. This returns the number + of unprocessed bytes from the last png_process_data + call - it is up to you to ensure that the next call + sees these bytes again. If you don't want to bother + with this you can get libpng to cache the unread + bytes by setting the 'save' parameter (see png.h) but + then libpng will have to copy the data internally. + */ + } + + /* This function is called when each row of image + data is complete */ + void + row_callback(png_structp png_ptr, png_bytep new_row, + png_uint_32 row_num, int pass) + { + /* If the image is interlaced, and you turned + on the interlace handler, this function will + be called for every row in every pass. Some + of these rows will not be changed from the + previous pass. When the row is not changed, + the new_row variable will be NULL. The rows + and passes are called in order, so you don't + really need the row_num and pass, but I'm + supplying them because it may make your life + easier. + + If you did not turn on interlace handling then + the callback is called for each row of each + sub-image when the image is interlaced. In this + case 'row_num' is the row in the sub-image, not + the row in the output image as it is in all other + cases. + + For the non-NULL rows of interlaced images when + you have switched on libpng interlace handling, + you must call png_progressive_combine_row() + passing in the row and the old row. You can + call this function for NULL rows (it will just + return) and for non-interlaced images (it just + does the memcpy for you) if it will make the + code easier. Thus, you can just do this for + all cases if you switch on interlace handling; + */ + + png_progressive_combine_row(png_ptr, old_row, + new_row); + + /* where old_row is what was displayed for + previously for the row. Note that the first + pass (pass == 0, really) will completely cover + the old row, so the rows do not have to be + initialized. After the first pass (and only + for interlaced images), you will have to pass + the current row, and the function will combine + the old row and the new row. + + You can also call png_process_data_pause in this + callback - see above. + */ + } + + void + end_callback(png_structp png_ptr, png_infop info) + { + /* This function is called after the whole image + has been read, including any chunks after the + image (up to and including the IEND). You + will usually have the same info chunk as you + had in the header, although some data may have + been added to the comments and time fields. + + Most people won't do much here, perhaps setting + a flag that marks the image as finished. + */ + } + + + +IV. Writing + +Much of this is very similar to reading. However, everything of +importance is repeated here, so you won't have to constantly look +back up in the reading section to understand writing. + +Setup + +You will want to do the I/O initialization before you get into libpng, +so if it doesn't work, you don't have anything to undo. If you are not +using the standard I/O functions, you will need to replace them with +custom writing functions. See the discussion under Customizing libpng. + + FILE *fp = fopen(file_name, "wb"); + + if (!fp) + return (ERROR); + +Next, png_struct and png_info need to be allocated and initialized. +As these can be both relatively large, you may not want to store these +on the stack, unless you have stack space to spare. Of course, you +will want to check if they return NULL. If you are also reading, +you won't want to name your read structure and your write structure +both "png_ptr"; you can call them anything you like, such as +"read_ptr" and "write_ptr". Look at pngtest.c, for example. + + png_structp png_ptr = png_create_write_struct + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn); + + if (!png_ptr) + return (ERROR); + + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_write_struct(&png_ptr, + (png_infopp)NULL); + return (ERROR); + } + +If you want to use your own memory allocation routines, +define PNG_USER_MEM_SUPPORTED and use +png_create_write_struct_2() instead of png_create_write_struct(): + + png_structp png_ptr = png_create_write_struct_2 + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn, (png_voidp) + user_mem_ptr, user_malloc_fn, user_free_fn); + +After you have these structures, you will need to set up the +error handling. When libpng encounters an error, it expects to +longjmp() back to your routine. Therefore, you will need to call +setjmp() and pass the png_jmpbuf(png_ptr). If you +write the file from different routines, you will need to update +the png_jmpbuf(png_ptr) every time you enter a new routine that will +call a png_*() function. See your documentation of setjmp/longjmp +for your compiler for more information on setjmp/longjmp. See +the discussion on libpng error handling in the Customizing Libpng +section below for more information on the libpng error handling. + + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_write_struct(&png_ptr, &info_ptr); + fclose(fp); + return (ERROR); + } + ... + return; + +If you would rather avoid the complexity of setjmp/longjmp issues, +you can compile libpng with PNG_NO_SETJMP, in which case +errors will result in a call to PNG_ABORT() which defaults to abort(). + +You can #define PNG_ABORT() to a function that does something +more useful than abort(), as long as your function does not +return. + +Now you need to set up the output code. The default for libpng is to +use the C function fwrite(). If you use this, you will need to pass a +valid FILE * in the function png_init_io(). Be sure that the file is +opened in binary mode. Again, if you wish to handle writing data in +another way, see the discussion on libpng I/O handling in the Customizing +Libpng section below. + + png_init_io(png_ptr, fp); + +If you are embedding your PNG into a datastream such as MNG, and don't +want libpng to write the 8-byte signature, or if you have already +written the signature in your application, use + + png_set_sig_bytes(png_ptr, 8); + +to inform libpng that it should not write a signature. + +Write callbacks + +At this point, you can set up a callback function that will be +called after each row has been written, which you can use to control +a progress meter or the like. It's demonstrated in pngtest.c. +You must supply a function + + void write_row_callback(png_structp png_ptr, png_uint_32 row, + int pass); + { + /* put your code here */ + } + +(You can give it another name that you like instead of "write_row_callback") + +To inform libpng about your function, use + + png_set_write_status_fn(png_ptr, write_row_callback); + +When this function is called the row has already been completely processed and +it has also been written out. The 'row' and 'pass' refer to the next row to be +handled. For the +non-interlaced case the row that was just handled is simply one less than the +passed in row number, and pass will always be 0. For the interlaced case the +same applies unless the row value is 0, in which case the row just handled was +the last one from one of the preceding passes. Because interlacing may skip a +pass you cannot be sure that the preceding pass is just 'pass-1', if you really +need to know what the last pass is record (row,pass) from the callback and use +the last recorded value each time. + +As with the user transform you can find the output row using the +PNG_ROW_FROM_PASS_ROW macro. + +You now have the option of modifying how the compression library will +run. The following functions are mainly for testing, but may be useful +in some cases, like if you need to write PNG files extremely fast and +are willing to give up some compression, or if you want to get the +maximum possible compression at the expense of slower writing. If you +have no special needs in this area, let the library do what it wants by +not calling this function at all, as it has been tuned to deliver a good +speed/compression ratio. The second parameter to png_set_filter() is +the filter method, for which the only valid values are 0 (as of the +July 1999 PNG specification, version 1.2) or 64 (if you are writing +a PNG datastream that is to be embedded in a MNG datastream). The third +parameter is a flag that indicates which filter type(s) are to be tested +for each scanline. See the PNG specification for details on the specific +filter types. + + + /* turn on or off filtering, and/or choose + specific filters. You can use either a single + PNG_FILTER_VALUE_NAME or the bitwise OR of one + or more PNG_FILTER_NAME masks. + */ + png_set_filter(png_ptr, 0, + PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE | + PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB | + PNG_FILTER_UP | PNG_FILTER_VALUE_UP | + PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG | + PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH| + PNG_ALL_FILTERS); + +If an application wants to start and stop using particular filters during +compression, it should start out with all of the filters (to ensure that +the previous row of pixels will be stored in case it's needed later), +and then add and remove them after the start of compression. + +If you are writing a PNG datastream that is to be embedded in a MNG +datastream, the second parameter can be either 0 or 64. + +The png_set_compression_*() functions interface to the zlib compression +library, and should mostly be ignored unless you really know what you are +doing. The only generally useful call is png_set_compression_level() +which changes how much time zlib spends on trying to compress the image +data. See the Compression Library (zlib.h and algorithm.txt, distributed +with zlib) for details on the compression levels. + + #include zlib.h + + /* Set the zlib compression level */ + png_set_compression_level(png_ptr, + Z_BEST_COMPRESSION); + + /* Set other zlib parameters for compressing IDAT */ + png_set_compression_mem_level(png_ptr, 8); + png_set_compression_strategy(png_ptr, + Z_DEFAULT_STRATEGY); + png_set_compression_window_bits(png_ptr, 15); + png_set_compression_method(png_ptr, 8); + png_set_compression_buffer_size(png_ptr, 8192) + + /* Set zlib parameters for text compression + * If you don't call these, the parameters + * fall back on those defined for IDAT chunks + */ + png_set_text_compression_mem_level(png_ptr, 8); + png_set_text_compression_strategy(png_ptr, + Z_DEFAULT_STRATEGY); + png_set_text_compression_window_bits(png_ptr, 15); + png_set_text_compression_method(png_ptr, 8); + +Setting the contents of info for output + +You now need to fill in the png_info structure with all the data you +wish to write before the actual image. Note that the only thing you +are allowed to write after the image is the text chunks and the time +chunk (as of PNG Specification 1.2, anyway). See png_write_end() and +the latest PNG specification for more information on that. If you +wish to write them before the image, fill them in now, and flag that +data as being valid. If you want to wait until after the data, don't +fill them until png_write_end(). For all the fields in png_info and +their data types, see png.h. For explanations of what the fields +contain, see the PNG specification. + +Some of the more important parts of the png_info are: + + png_set_IHDR(png_ptr, info_ptr, width, height, + bit_depth, color_type, interlace_type, + compression_type, filter_method) + + width - holds the width of the image + in pixels (up to 2^31). + + height - holds the height of the image + in pixels (up to 2^31). + + bit_depth - holds the bit depth of one of the + image channels. + (valid values are 1, 2, 4, 8, 16 + and depend also on the + color_type. See also significant + bits (sBIT) below). + + color_type - describes which color/alpha + channels are present. + PNG_COLOR_TYPE_GRAY + (bit depths 1, 2, 4, 8, 16) + PNG_COLOR_TYPE_GRAY_ALPHA + (bit depths 8, 16) + PNG_COLOR_TYPE_PALETTE + (bit depths 1, 2, 4, 8) + PNG_COLOR_TYPE_RGB + (bit_depths 8, 16) + PNG_COLOR_TYPE_RGB_ALPHA + (bit_depths 8, 16) + + PNG_COLOR_MASK_PALETTE + PNG_COLOR_MASK_COLOR + PNG_COLOR_MASK_ALPHA + + interlace_type - PNG_INTERLACE_NONE or + PNG_INTERLACE_ADAM7 + + compression_type - (must be + PNG_COMPRESSION_TYPE_DEFAULT) + + filter_method - (must be PNG_FILTER_TYPE_DEFAULT + or, if you are writing a PNG to + be embedded in a MNG datastream, + can also be + PNG_INTRAPIXEL_DIFFERENCING) + +If you call png_set_IHDR(), the call must appear before any of the +other png_set_*() functions, because they might require access to some of +the IHDR settings. The remaining png_set_*() functions can be called +in any order. + +If you wish, you can reset the compression_type, interlace_type, or +filter_method later by calling png_set_IHDR() again; if you do this, the +width, height, bit_depth, and color_type must be the same in each call. + + png_set_PLTE(png_ptr, info_ptr, palette, + num_palette); + + palette - the palette for the file + (array of png_color) + num_palette - number of entries in the palette + + png_set_gAMA(png_ptr, info_ptr, file_gamma); + png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma); + + file_gamma - the gamma at which the image was + created (PNG_INFO_gAMA) + + int_file_gamma - 100,000 times the gamma at which + the image was created + + png_set_cHRM(png_ptr, info_ptr, white_x, white_y, red_x, red_y, + green_x, green_y, blue_x, blue_y) + png_set_cHRM_XYZ(png_ptr, info_ptr, red_X, red_Y, red_Z, green_X, + green_Y, green_Z, blue_X, blue_Y, blue_Z) + png_set_cHRM_fixed(png_ptr, info_ptr, int_white_x, int_white_y, + int_red_x, int_red_y, int_green_x, int_green_y, + int_blue_x, int_blue_y) + png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, int_red_X, int_red_Y, + int_red_Z, int_green_X, int_green_Y, int_green_Z, + int_blue_X, int_blue_Y, int_blue_Z) + + {white,red,green,blue}_{x,y} + A color space encoding specified using the chromaticities + of the end points and the white point. + + {red,green,blue}_{X,Y,Z} + A color space encoding specified using the encoding end + points - the CIE tristimulus specification of the intended + color of the red, green and blue channels in the PNG RGB + data. The white point is simply the sum of the three end + points. + + png_set_sRGB(png_ptr, info_ptr, srgb_intent); + + srgb_intent - the rendering intent + (PNG_INFO_sRGB) The presence of + the sRGB chunk means that the pixel + data is in the sRGB color space. + This chunk also implies specific + values of gAMA and cHRM. Rendering + intent is the CSS-1 property that + has been defined by the International + Color Consortium + (http://www.color.org). + It can be one of + PNG_sRGB_INTENT_SATURATION, + PNG_sRGB_INTENT_PERCEPTUAL, + PNG_sRGB_INTENT_ABSOLUTE, or + PNG_sRGB_INTENT_RELATIVE. + + + png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, + srgb_intent); + + srgb_intent - the rendering intent + (PNG_INFO_sRGB) The presence of the + sRGB chunk means that the pixel + data is in the sRGB color space. + This function also causes gAMA and + cHRM chunks with the specific values + that are consistent with sRGB to be + written. + + png_set_iCCP(png_ptr, info_ptr, name, compression_type, + profile, proflen); + + name - The profile name. + + compression_type - The compression type; always + PNG_COMPRESSION_TYPE_BASE for PNG 1.0. + You may give NULL to this argument to + ignore it. + + profile - International Color Consortium color + profile data. May contain NULs. + + proflen - length of profile data in bytes. + + png_set_sBIT(png_ptr, info_ptr, sig_bit); + + sig_bit - the number of significant bits for + (PNG_INFO_sBIT) each of the gray, red, + green, and blue channels, whichever are + appropriate for the given color type + (png_color_16) + + png_set_tRNS(png_ptr, info_ptr, trans_alpha, + num_trans, trans_color); + + trans_alpha - array of alpha (transparency) + entries for palette (PNG_INFO_tRNS) + + num_trans - number of transparent entries + (PNG_INFO_tRNS) + + trans_color - graylevel or color sample values + (in order red, green, blue) of the + single transparent color for + non-paletted images (PNG_INFO_tRNS) + + png_set_hIST(png_ptr, info_ptr, hist); + + hist - histogram of palette (array of + png_uint_16) (PNG_INFO_hIST) + + png_set_tIME(png_ptr, info_ptr, mod_time); + + mod_time - time image was last modified + (PNG_VALID_tIME) + + png_set_bKGD(png_ptr, info_ptr, background); + + background - background color (of type + png_color_16p) (PNG_VALID_bKGD) + + png_set_text(png_ptr, info_ptr, text_ptr, num_text); + + text_ptr - array of png_text holding image + comments + + text_ptr[i].compression - type of compression used + on "text" PNG_TEXT_COMPRESSION_NONE + PNG_TEXT_COMPRESSION_zTXt + PNG_ITXT_COMPRESSION_NONE + PNG_ITXT_COMPRESSION_zTXt + text_ptr[i].key - keyword for comment. Must contain + 1-79 characters. + text_ptr[i].text - text comments for current + keyword. Can be NULL or empty. + text_ptr[i].text_length - length of text string, + after decompression, 0 for iTXt + text_ptr[i].itxt_length - length of itxt string, + after decompression, 0 for tEXt/zTXt + text_ptr[i].lang - language of comment (NULL or + empty for unknown). + text_ptr[i].translated_keyword - keyword in UTF-8 (NULL + or empty for unknown). + + Note that the itxt_length, lang, and lang_key + members of the text_ptr structure only exist when the + library is built with iTXt chunk support. Prior to + libpng-1.4.0 the library was built by default without + iTXt support. Also note that when iTXt is supported, + they contain NULL pointers when the "compression" + field contains PNG_TEXT_COMPRESSION_NONE or + PNG_TEXT_COMPRESSION_zTXt. + + num_text - number of comments + + png_set_sPLT(png_ptr, info_ptr, &palette_ptr, + num_spalettes); + + palette_ptr - array of png_sPLT_struct structures + to be added to the list of palettes + in the info structure. + num_spalettes - number of palette structures to be + added. + + png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, + unit_type); + + offset_x - positive offset from the left + edge of the screen + + offset_y - positive offset from the top + edge of the screen + + unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER + + png_set_pHYs(png_ptr, info_ptr, res_x, res_y, + unit_type); + + res_x - pixels/unit physical resolution + in x direction + + res_y - pixels/unit physical resolution + in y direction + + unit_type - PNG_RESOLUTION_UNKNOWN, + PNG_RESOLUTION_METER + + png_set_sCAL(png_ptr, info_ptr, unit, width, height) + + unit - physical scale units (an integer) + + width - width of a pixel in physical scale units + + height - height of a pixel in physical scale units + (width and height are doubles) + + png_set_sCAL_s(png_ptr, info_ptr, unit, width, height) + + unit - physical scale units (an integer) + + width - width of a pixel in physical scale units + expressed as a string + + height - height of a pixel in physical scale units + (width and height are strings like "2.54") + + png_set_unknown_chunks(png_ptr, info_ptr, &unknowns, + num_unknowns) + + unknowns - array of png_unknown_chunk + structures holding unknown chunks + unknowns[i].name - name of unknown chunk + unknowns[i].data - data of unknown chunk + unknowns[i].size - size of unknown chunk's data + unknowns[i].location - position to write chunk in file + 0: do not write chunk + PNG_HAVE_IHDR: before PLTE + PNG_HAVE_PLTE: before IDAT + PNG_AFTER_IDAT: after IDAT + +The "location" member is set automatically according to +what part of the output file has already been written. +You can change its value after calling png_set_unknown_chunks() +as demonstrated in pngtest.c. Within each of the "locations", +the chunks are sequenced according to their position in the +structure (that is, the value of "i", which is the order in which +the chunk was either read from the input file or defined with +png_set_unknown_chunks). + +A quick word about text and num_text. text is an array of png_text +structures. num_text is the number of valid structures in the array. +Each png_text structure holds a language code, a keyword, a text value, +and a compression type. + +The compression types have the same valid numbers as the compression +types of the image data. Currently, the only valid number is zero. +However, you can store text either compressed or uncompressed, unlike +images, which always have to be compressed. So if you don't want the +text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE. +Because tEXt and zTXt chunks don't have a language field, if you +specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt +any language code or translated keyword will not be written out. + +Until text gets around a few hundred bytes, it is not worth compressing it. +After the text has been written out to the file, the compression type +is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR, +so that it isn't written out again at the end (in case you are calling +png_write_end() with the same struct). + +The keywords that are given in the PNG Specification are: + + Title Short (one line) title or + caption for image + + Author Name of image's creator + + Description Description of image (possibly long) + + Copyright Copyright notice + + Creation Time Time of original image creation + (usually RFC 1123 format, see below) + + Software Software used to create the image + + Disclaimer Legal disclaimer + + Warning Warning of nature of content + + Source Device used to create the image + + Comment Miscellaneous comment; conversion + from other image format + +The keyword-text pairs work like this. Keywords should be short +simple descriptions of what the comment is about. Some typical +keywords are found in the PNG specification, as is some recommendations +on keywords. You can repeat keywords in a file. You can even write +some text before the image and some after. For example, you may want +to put a description of the image before the image, but leave the +disclaimer until after, so viewers working over modem connections +don't have to wait for the disclaimer to go over the modem before +they start seeing the image. Finally, keywords should be full +words, not abbreviations. Keywords and text are in the ISO 8859-1 +(Latin-1) character set (a superset of regular ASCII) and can not +contain NUL characters, and should not contain control or other +unprintable characters. To make the comments widely readable, stick +with basic ASCII, and avoid machine specific character set extensions +like the IBM-PC character set. The keyword must be present, but +you can leave off the text string on non-compressed pairs. +Compressed pairs must have a text string, as only the text string +is compressed anyway, so the compression would be meaningless. + +PNG supports modification time via the png_time structure. Two +conversion routines are provided, png_convert_from_time_t() for +time_t and png_convert_from_struct_tm() for struct tm. The +time_t routine uses gmtime(). You don't have to use either of +these, but if you wish to fill in the png_time structure directly, +you should provide the time in universal time (GMT) if possible +instead of your local time. Note that the year number is the full +year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and +that months start with 1. + +If you want to store the time of the original image creation, you should +use a plain tEXt chunk with the "Creation Time" keyword. This is +necessary because the "creation time" of a PNG image is somewhat vague, +depending on whether you mean the PNG file, the time the image was +created in a non-PNG format, a still photo from which the image was +scanned, or possibly the subject matter itself. In order to facilitate +machine-readable dates, it is recommended that the "Creation Time" +tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"), +although this isn't a requirement. Unlike the tIME chunk, the +"Creation Time" tEXt chunk is not expected to be automatically changed +by the software. To facilitate the use of RFC 1123 dates, a function +png_convert_to_rfc1123(png_ptr, png_timep) is provided to convert +from PNG time to an RFC 1123 format string. + +Writing unknown chunks + +You can use the png_set_unknown_chunks function to queue up chunks +for writing. You give it a chunk name, raw data, and a size; that's +all there is to it. The chunks will be written by the next following +png_write_info_before_PLTE, png_write_info, or png_write_end function. +Any chunks previously read into the info structure's unknown-chunk +list will also be written out in a sequence that satisfies the PNG +specification's ordering rules. + +The high-level write interface + +At this point there are two ways to proceed; through the high-level +write interface, or through a sequence of low-level write operations. +You can use the high-level interface if your image data is present +in the info structure. All defined output +transformations are permitted, enabled by the following masks. + + PNG_TRANSFORM_IDENTITY No transformation + PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples + PNG_TRANSFORM_PACKSWAP Change order of packed + pixels to LSB first + PNG_TRANSFORM_INVERT_MONO Invert monochrome images + PNG_TRANSFORM_SHIFT Normalize pixels to the + sBIT depth + PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA + to BGRA + PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA + to AG + PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity + to transparency + PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples + PNG_TRANSFORM_STRIP_FILLER Strip out filler + bytes (deprecated). + PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading + filler bytes + PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing + filler bytes + +If you have valid image data in the info structure (you can use +png_set_rows() to put image data in the info structure), simply do this: + + png_write_png(png_ptr, info_ptr, png_transforms, NULL) + +where png_transforms is an integer containing the bitwise OR of some set of +transformation flags. This call is equivalent to png_write_info(), +followed the set of transformations indicated by the transform mask, +then png_write_image(), and finally png_write_end(). + +(The final parameter of this call is not yet used. Someday it might point +to transformation parameters required by some future output transform.) + +You must use png_transforms and not call any png_set_transform() functions +when you use png_write_png(). + +The low-level write interface + +If you are going the low-level route instead, you are now ready to +write all the file information up to the actual image data. You do +this with a call to png_write_info(). + + png_write_info(png_ptr, info_ptr); + +Note that there is one transformation you may need to do before +png_write_info(). In PNG files, the alpha channel in an image is the +level of opacity. If your data is supplied as a level of transparency, +you can invert the alpha channel before you write it, so that 0 is +fully transparent and 255 (in 8-bit or paletted images) or 65535 +(in 16-bit images) is fully opaque, with + + png_set_invert_alpha(png_ptr); + +This must appear before png_write_info() instead of later with the +other transformations because in the case of paletted images the tRNS +chunk data has to be inverted before the tRNS chunk is written. If +your image is not a paletted image, the tRNS data (which in such cases +represents a single color to be rendered as transparent) won't need to +be changed, and you can safely do this transformation after your +png_write_info() call. + +If you need to write a private chunk that you want to appear before +the PLTE chunk when PLTE is present, you can write the PNG info in +two steps, and insert code to write your own chunk between them: + + png_write_info_before_PLTE(png_ptr, info_ptr); + png_set_unknown_chunks(png_ptr, info_ptr, ...); + png_write_info(png_ptr, info_ptr); + +After you've written the file information, you can set up the library +to handle any special transformations of the image data. The various +ways to transform the data will be described in the order that they +should occur. This is important, as some of these change the color +type and/or bit depth of the data, and some others only work on +certain color types and bit depths. Even though each transformation +checks to see if it has data that it can do something with, you should +make sure to only enable a transformation if it will be valid for the +data. For example, don't swap red and blue on grayscale data. + +PNG files store RGB pixels packed into 3 or 6 bytes. This code tells +the library to strip input data that has 4 or 8 bytes per pixel down +to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2 +bytes per pixel). + + png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); + +where the 0 is unused, and the location is either PNG_FILLER_BEFORE or +PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel +is stored XRGB or RGBX. + +PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as +they can, resulting in, for example, 8 pixels per byte for 1 bit files. +If the data is supplied at 1 pixel per byte, use this code, which will +correctly pack the pixels into a single byte: + + png_set_packing(png_ptr); + +PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your +data is of another bit depth, you can write an sBIT chunk into the +file so that decoders can recover the original data if desired. + + /* Set the true bit depth of the image data */ + if (color_type & PNG_COLOR_MASK_COLOR) + { + sig_bit.red = true_bit_depth; + sig_bit.green = true_bit_depth; + sig_bit.blue = true_bit_depth; + } + + else + { + sig_bit.gray = true_bit_depth; + } + + if (color_type & PNG_COLOR_MASK_ALPHA) + { + sig_bit.alpha = true_bit_depth; + } + + png_set_sBIT(png_ptr, info_ptr, &sig_bit); + +If the data is stored in the row buffer in a bit depth other than +one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG), +this will scale the values to appear to be the correct bit depth as +is required by PNG. + + png_set_shift(png_ptr, &sig_bit); + +PNG files store 16-bit pixels in network byte order (big-endian, +ie. most significant bits first). This code would be used if they are +supplied the other way (little-endian, i.e. least significant bits +first, the way PCs store them): + + if (bit_depth > 8) + png_set_swap(png_ptr); + +If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you +need to change the order the pixels are packed into bytes, you can use: + + if (bit_depth < 8) + png_set_packswap(png_ptr); + +PNG files store 3 color pixels in red, green, blue order. This code +would be used if they are supplied as blue, green, red: + + png_set_bgr(png_ptr); + +PNG files describe monochrome as black being zero and white being +one. This code would be used if the pixels are supplied with this reversed +(black being one and white being zero): + + png_set_invert_mono(png_ptr); + +Finally, you can write your own transformation function if none of +the existing ones meets your needs. This is done by setting a callback +with + + png_set_write_user_transform_fn(png_ptr, + write_transform_fn); + +You must supply the function + + void write_transform_fn(png_structp png_ptr, png_row_infop + row_info, png_bytep data) + +See pngtest.c for a working example. Your function will be called +before any of the other transformations are processed. If supported +libpng also supplies an information routine that may be called from +your callback: + + png_get_current_row_number(png_ptr); + png_get_current_pass_number(png_ptr); + +This returns the current row passed to the transform. With interlaced +images the value returned is the row in the input sub-image image. Use +PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to +find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass). + +The discussion of interlace handling above contains more information on how to +use these values. + +You can also set up a pointer to a user structure for use by your +callback function. + + png_set_user_transform_info(png_ptr, user_ptr, 0, 0); + +The user_channels and user_depth parameters of this function are ignored +when writing; you can set them to zero as shown. + +You can retrieve the pointer via the function png_get_user_transform_ptr(). +For example: + + voidp write_user_transform_ptr = + png_get_user_transform_ptr(png_ptr); + +It is possible to have libpng flush any pending output, either manually, +or automatically after a certain number of lines have been written. To +flush the output stream a single time call: + + png_write_flush(png_ptr); + +and to have libpng flush the output stream periodically after a certain +number of scanlines have been written, call: + + png_set_flush(png_ptr, nrows); + +Note that the distance between rows is from the last time png_write_flush() +was called, or the first row of the image if it has never been called. +So if you write 50 lines, and then png_set_flush 25, it will flush the +output on the next scanline, and every 25 lines thereafter, unless +png_write_flush() is called before 25 more lines have been written. +If nrows is too small (less than about 10 lines for a 640 pixel wide +RGB image) the image compression may decrease noticeably (although this +may be acceptable for real-time applications). Infrequent flushing will +only degrade the compression performance by a few percent over images +that do not use flushing. + +Writing the image data + +That's it for the transformations. Now you can write the image data. +The simplest way to do this is in one function call. If you have the +whole image in memory, you can just call png_write_image() and libpng +will write the image. You will need to pass in an array of pointers to +each row. This function automatically handles interlacing, so you don't +need to call png_set_interlace_handling() or call this function multiple +times, or any of that other stuff necessary with png_write_rows(). + + png_write_image(png_ptr, row_pointers); + +where row_pointers is: + + png_byte *row_pointers[height]; + +You can point to void or char or whatever you use for pixels. + +If you don't want to write the whole image at once, you can +use png_write_rows() instead. If the file is not interlaced, +this is simple: + + png_write_rows(png_ptr, row_pointers, + number_of_rows); + +row_pointers is the same as in the png_write_image() call. + +If you are just writing one row at a time, you can do this with +a single row_pointer instead of an array of row_pointers: + + png_bytep row_pointer = row; + + png_write_row(png_ptr, row_pointer); + +When the file is interlaced, things can get a good deal more complicated. +The only currently (as of the PNG Specification version 1.2, dated July +1999) defined interlacing scheme for PNG files is the "Adam7" interlace +scheme, that breaks down an image into seven smaller images of varying +size. libpng will build these images for you, or you can do them +yourself. If you want to build them yourself, see the PNG specification +for details of which pixels to write when. + +If you don't want libpng to handle the interlacing details, just +use png_set_interlace_handling() and call png_write_rows() the +correct number of times to write all the sub-images +(png_set_interlace_handling() returns the number of sub-images.) + +If you want libpng to build the sub-images, call this before you start +writing any rows: + + number_of_passes = png_set_interlace_handling(png_ptr); + +This will return the number of passes needed. Currently, this is seven, +but may change if another interlace type is added. + +Then write the complete image number_of_passes times. + + png_write_rows(png_ptr, row_pointers, number_of_rows); + +Think carefully before you write an interlaced image. Typically code that +reads such images reads all the image data into memory, uncompressed, before +doing any processing. Only code that can display an image on the fly can +take advantage of the interlacing and even then the image has to be exactly +the correct size for the output device, because scaling an image requires +adjacent pixels and these are not available until all the passes have been +read. + +If you do write an interlaced image you will hardly ever need to handle +the interlacing yourself. Call png_set_interlace_handling() and use the +approach described above. + +The only time it is conceivable that you will really need to write an +interlaced image pass-by-pass is when you have read one pass by pass and +made some pixel-by-pixel transformation to it, as described in the read +code above. In this case use the PNG_PASS_ROWS and PNG_PASS_COLS macros +to determine the size of each sub-image in turn and simply write the rows +you obtained from the read code. + +Finishing a sequential write + +After you are finished writing the image, you should finish writing +the file. If you are interested in writing comments or time, you should +pass an appropriately filled png_info pointer. If you are not interested, +you can pass NULL. + + png_write_end(png_ptr, info_ptr); + +When you are done, you can free all memory used by libpng like this: + + png_destroy_write_struct(&png_ptr, &info_ptr); + +It is also possible to individually free the info_ptr members that +point to libpng-allocated storage with the following function: + + png_free_data(png_ptr, info_ptr, mask, seq) + + mask - identifies data to be freed, a mask + containing the bitwise OR of one or + more of + PNG_FREE_PLTE, PNG_FREE_TRNS, + PNG_FREE_HIST, PNG_FREE_ICCP, + PNG_FREE_PCAL, PNG_FREE_ROWS, + PNG_FREE_SCAL, PNG_FREE_SPLT, + PNG_FREE_TEXT, PNG_FREE_UNKN, + or simply PNG_FREE_ALL + + seq - sequence number of item to be freed + (-1 for all items) + +This function may be safely called when the relevant storage has +already been freed, or has not yet been allocated, or was allocated +by the user and not by libpng, and will in those cases do nothing. +The "seq" parameter is ignored if only one item of the selected data +type, such as PLTE, is allowed. If "seq" is not -1, and multiple items +are allowed for the data type identified in the mask, such as text or +sPLT, only the n'th item in the structure is freed, where n is "seq". + +If you allocated data such as a palette that you passed in to libpng +with png_set_*, you must not free it until just before the call to +png_destroy_write_struct(). + +The default behavior is only to free data that was allocated internally +by libpng. This can be changed, so that libpng will not free the data, +or so that it will free data that was allocated by the user with png_malloc() +or png_calloc() and passed in via a png_set_*() function, with + + png_data_freer(png_ptr, info_ptr, freer, mask) + + freer - one of + PNG_DESTROY_WILL_FREE_DATA + PNG_SET_WILL_FREE_DATA + PNG_USER_WILL_FREE_DATA + + mask - which data elements are affected + same choices as in png_free_data() + +For example, to transfer responsibility for some data from a read structure +to a write structure, you could use + + png_data_freer(read_ptr, read_info_ptr, + PNG_USER_WILL_FREE_DATA, + PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST) + + png_data_freer(write_ptr, write_info_ptr, + PNG_DESTROY_WILL_FREE_DATA, + PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST) + +thereby briefly reassigning responsibility for freeing to the user but +immediately afterwards reassigning it once more to the write_destroy +function. Having done this, it would then be safe to destroy the read +structure and continue to use the PLTE, tRNS, and hIST data in the write +structure. + +This function only affects data that has already been allocated. +You can call this function before calling after the png_set_*() functions +to control whether the user or png_destroy_*() is supposed to free the data. +When the user assumes responsibility for libpng-allocated data, the +application must use +png_free() to free it, and when the user transfers responsibility to libpng +for data that the user has allocated, the user must have used png_malloc() +or png_calloc() to allocate it. + +If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword +separately, do not transfer responsibility for freeing text_ptr to libpng, +because when libpng fills a png_text structure it combines these members with +the key member, and png_free_data() will free only text_ptr.key. Similarly, +if you transfer responsibility for free'ing text_ptr from libpng to your +application, your application must not separately free those members. +For a more compact example of writing a PNG image, see the file example.c. + +V. Modifying/Customizing libpng: + +There are two issues here. The first is changing how libpng does +standard things like memory allocation, input/output, and error handling. +The second deals with more complicated things like adding new chunks, +adding new transformations, and generally changing how libpng works. +Both of those are compile-time issues; that is, they are generally +determined at the time the code is written, and there is rarely a need +to provide the user with a means of changing them. + +Memory allocation, input/output, and error handling + +All of the memory allocation, input/output, and error handling in libpng +goes through callbacks that are user-settable. The default routines are +in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change +these functions, call the appropriate png_set_*_fn() function. + +Memory allocation is done through the functions png_malloc(), png_calloc(), +and png_free(). The png_malloc() and png_free() functions currently just +call the standard C functions and png_calloc() calls png_malloc() and then +clears the newly allocated memory to zero; note that png_calloc(png_ptr, size) +is not the same as the calloc(number, size) function provided by stdlib.h. +There is limited support for certain systems with segmented memory +architectures and the types of pointers declared by png.h match this; you +will have to use appropriate pointers in your application. Since it is +unlikely that the method of handling memory allocation on a platform +will change between applications, these functions must be modified in +the library at compile time. If you prefer to use a different method +of allocating and freeing data, you can use png_create_read_struct_2() or +png_create_write_struct_2() to register your own functions as described +above. These functions also provide a void pointer that can be retrieved +via + + mem_ptr=png_get_mem_ptr(png_ptr); + +Your replacement memory functions must have prototypes as follows: + + png_voidp malloc_fn(png_structp png_ptr, + png_alloc_size_t size); + + void free_fn(png_structp png_ptr, png_voidp ptr); + +Your malloc_fn() must return NULL in case of failure. The png_malloc() +function will normally call png_error() if it receives a NULL from the +system memory allocator or from your replacement malloc_fn(). + +Your free_fn() will never be called with a NULL ptr, since libpng's +png_free() checks for NULL before calling free_fn(). + +Input/Output in libpng is done through png_read() and png_write(), +which currently just call fread() and fwrite(). The FILE * is stored in +png_struct and is initialized via png_init_io(). If you wish to change +the method of I/O, the library supplies callbacks that you can set +through the function png_set_read_fn() and png_set_write_fn() at run +time, instead of calling the png_init_io() function. These functions +also provide a void pointer that can be retrieved via the function +png_get_io_ptr(). For example: + + png_set_read_fn(png_structp read_ptr, + voidp read_io_ptr, png_rw_ptr read_data_fn) + + png_set_write_fn(png_structp write_ptr, + voidp write_io_ptr, png_rw_ptr write_data_fn, + png_flush_ptr output_flush_fn); + + voidp read_io_ptr = png_get_io_ptr(read_ptr); + voidp write_io_ptr = png_get_io_ptr(write_ptr); + +The replacement I/O functions must have prototypes as follows: + + void user_read_data(png_structp png_ptr, + png_bytep data, png_size_t length); + + void user_write_data(png_structp png_ptr, + png_bytep data, png_size_t length); + + void user_flush_data(png_structp png_ptr); + +The user_read_data() function is responsible for detecting and +handling end-of-data errors. + +Supplying NULL for the read, write, or flush functions sets them back +to using the default C stream functions, which expect the io_ptr to +point to a standard *FILE structure. It is probably a mistake +to use NULL for one of write_data_fn and output_flush_fn but not both +of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined. +It is an error to read from a write stream, and vice versa. + +Error handling in libpng is done through png_error() and png_warning(). +Errors handled through png_error() are fatal, meaning that png_error() +should never return to its caller. Currently, this is handled via +setjmp() and longjmp() (unless you have compiled libpng with +PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()), +but you could change this to do things like exit() if you should wish, +as long as your function does not return. + +On non-fatal errors, png_warning() is called +to print a warning message, and then control returns to the calling code. +By default png_error() and png_warning() print a message on stderr via +fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined +(because you don't want the messages) or PNG_NO_STDIO defined (because +fprintf() isn't available). If you wish to change the behavior of the error +functions, you will need to set up your own message callbacks. These +functions are normally supplied at the time that the png_struct is created. +It is also possible to redirect errors and warnings to your own replacement +functions after png_create_*_struct() has been called by calling: + + png_set_error_fn(png_structp png_ptr, + png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warning_fn); + + png_voidp error_ptr = png_get_error_ptr(png_ptr); + +If NULL is supplied for either error_fn or warning_fn, then the libpng +default function will be used, calling fprintf() and/or longjmp() if a +problem is encountered. The replacement error functions should have +parameters as follows: + + void user_error_fn(png_structp png_ptr, + png_const_charp error_msg); + + void user_warning_fn(png_structp png_ptr, + png_const_charp warning_msg); + +The motivation behind using setjmp() and longjmp() is the C++ throw and +catch exception handling methods. This makes the code much easier to write, +as there is no need to check every return code of every function call. +However, there are some uncertainties about the status of local variables +after a longjmp, so the user may want to be careful about doing anything +after setjmp returns non-zero besides returning itself. Consult your +compiler documentation for more details. For an alternative approach, you +may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net), +which is illustrated in pngvalid.c and in contrib/visupng. + +Custom chunks + +If you need to read or write custom chunks, you may need to get deeper +into the libpng code. The library now has mechanisms for storing +and writing chunks of unknown type; you can even declare callbacks +for custom chunks. However, this may not be good enough if the +library code itself needs to know about interactions between your +chunk and existing `intrinsic' chunks. + +If you need to write a new intrinsic chunk, first read the PNG +specification. Acquire a first level of understanding of how it works. +Pay particular attention to the sections that describe chunk names, +and look at how other chunks were designed, so you can do things +similarly. Second, check out the sections of libpng that read and +write chunks. Try to find a chunk that is similar to yours and use +it as a template. More details can be found in the comments inside +the code. It is best to handle private or unknown chunks in a generic method, +via callback functions, instead of by modifying libpng functions. This +is illustrated in pngtest.c, which uses a callback function to handle a +private "vpAg" chunk and the new "sTER" chunk, which are both unknown to +libpng. + +If you wish to write your own transformation for the data, look through +the part of the code that does the transformations, and check out some of +the simpler ones to get an idea of how they work. Try to find a similar +transformation to the one you want to add and copy off of it. More details +can be found in the comments inside the code itself. + +Configuring for 16-bit platforms + +You will want to look into zconf.h to tell zlib (and thus libpng) that +it cannot allocate more then 64K at a time. Even if you can, the memory +won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K. + +Configuring for DOS + +For DOS users who only have access to the lower 640K, you will +have to limit zlib's memory usage via a png_set_compression_mem_level() +call. See zlib.h or zconf.h in the zlib library for more information. + +Configuring for Medium Model + +Libpng's support for medium model has been tested on most of the popular +compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets +defined, and FAR gets defined to far in pngconf.h, and you should be +all set. Everything in the library (except for zlib's structure) is +expecting far data. You must use the typedefs with the p or pp on +the end for pointers (or at least look at them and be careful). Make +note that the rows of data are defined as png_bytepp, which is +an "unsigned char far * far *". + +Configuring for gui/windowing platforms: + +You will need to write new error and warning functions that use the GUI +interface, as described previously, and set them to be the error and +warning functions at the time that png_create_*_struct() is called, +in order to have them available during the structure initialization. +They can be changed later via png_set_error_fn(). On some compilers, +you may also have to change the memory allocators (png_malloc, etc.). + +Configuring for compiler xxx: + +All includes for libpng are in pngconf.h. If you need to add, change +or delete an include, this is the place to do it. +The includes that are not needed outside libpng are placed in pngpriv.h, +which is only used by the routines inside libpng itself. +The files in libpng proper only include pngpriv.h and png.h, which +in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h. +As of libpng-1.5.0, pngpriv.h also includes three other private header +files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material +that previously appeared in the public headers. + +Configuring zlib: + +There are special functions to configure the compression. Perhaps the +most useful one changes the compression level, which currently uses +input compression values in the range 0 - 9. The library normally +uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests +have shown that for a large majority of images, compression values in +the range 3-6 compress nearly as well as higher levels, and do so much +faster. For online applications it may be desirable to have maximum speed +(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also +specify no compression (Z_NO_COMPRESSION = 0), but this would create +files larger than just storing the raw bitmap. You can specify the +compression level by calling: + + #include zlib.h + png_set_compression_level(png_ptr, level); + +Another useful one is to reduce the memory level used by the library. +The memory level defaults to 8, but it can be lowered if you are +short on memory (running DOS, for example, where you only have 640K). +Note that the memory level does have an effect on compression; among +other things, lower levels will result in sections of incompressible +data being emitted in smaller stored blocks, with a correspondingly +larger relative overhead of up to 15% in the worst case. + + #include zlib.h + png_set_compression_mem_level(png_ptr, level); + +The other functions are for configuring zlib. They are not recommended +for normal use and may result in writing an invalid PNG file. See +zlib.h for more information on what these mean. + + #include zlib.h + png_set_compression_strategy(png_ptr, + strategy); + + png_set_compression_window_bits(png_ptr, + window_bits); + + png_set_compression_method(png_ptr, method); + + png_set_compression_buffer_size(png_ptr, size); + +As of libpng version 1.5.4, additional APIs became +available to set these separately for non-IDAT +compressed chunks such as zTXt, iTXt, and iCCP: + + #include zlib.h + #if PNG_LIBPNG_VER >= 10504 + png_set_text_compression_level(png_ptr, level); + + png_set_text_compression_mem_level(png_ptr, level); + + png_set_text_compression_strategy(png_ptr, + strategy); + + png_set_text_compression_window_bits(png_ptr, + window_bits); + + png_set_text_compression_method(png_ptr, method); + #endif + +Controlling row filtering + +If you want to control whether libpng uses filtering or not, which +filters are used, and how it goes about picking row filters, you +can call one of these functions. The selection and configuration +of row filters can have a significant impact on the size and +encoding speed and a somewhat lesser impact on the decoding speed +of an image. Filtering is enabled by default for RGB and grayscale +images (with and without alpha), but not for paletted images nor +for any images with bit depths less than 8 bits/pixel. + +The 'method' parameter sets the main filtering method, which is +currently only '0' in the PNG 1.2 specification. The 'filters' +parameter sets which filter(s), if any, should be used for each +scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS +to turn filtering on and off, respectively. + +Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB, +PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise +ORed together with '|' to specify one or more filters to use. +These filters are described in more detail in the PNG specification. +If you intend to change the filter type during the course of writing +the image, you should start with flags set for all of the filters +you intend to use so that libpng can initialize its internal +structures appropriately for all of the filter types. (Note that this +means the first row must always be adaptively filtered, because libpng +currently does not allocate the filter buffers until png_write_row() +is called for the first time.) + + filters = PNG_FILTER_NONE | PNG_FILTER_SUB + PNG_FILTER_UP | PNG_FILTER_AVG | + PNG_FILTER_PAETH | PNG_ALL_FILTERS; + + png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, + filters); + The second parameter can also be + PNG_INTRAPIXEL_DIFFERENCING if you are + writing a PNG to be embedded in a MNG + datastream. This parameter must be the + same as the value of filter_method used + in png_set_IHDR(). + +It is also possible to influence how libpng chooses from among the +available filters. This is done in one or both of two ways - by +telling it how important it is to keep the same filter for successive +rows, and by telling it the relative computational costs of the filters. + + double weights[3] = {1.5, 1.3, 1.1}, + costs[PNG_FILTER_VALUE_LAST] = + {1.0, 1.3, 1.3, 1.5, 1.7}; + + png_set_filter_heuristics(png_ptr, + PNG_FILTER_HEURISTIC_WEIGHTED, 3, + weights, costs); + +The weights are multiplying factors that indicate to libpng that the +row filter should be the same for successive rows unless another row filter +is that many times better than the previous filter. In the above example, +if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a +"sum of absolute differences" 1.5 x 1.3 times higher than other filters +and still be chosen, while the NONE filter could have a sum 1.1 times +higher than other filters and still be chosen. Unspecified weights are +taken to be 1.0, and the specified weights should probably be declining +like those above in order to emphasize recent filters over older filters. + +The filter costs specify for each filter type a relative decoding cost +to be considered when selecting row filters. This means that filters +with higher costs are less likely to be chosen over filters with lower +costs, unless their "sum of absolute differences" is that much smaller. +The costs do not necessarily reflect the exact computational speeds of +the various filters, since this would unduly influence the final image +size. + +Note that the numbers above were invented purely for this example and +are given only to help explain the function usage. Little testing has +been done to find optimum values for either the costs or the weights. + +Removing unwanted object code + +There are a bunch of #define's in pngconf.h that control what parts of +libpng are compiled. All the defines end in _SUPPORTED. If you are +never going to use a capability, you can change the #define to #undef +before recompiling libpng and save yourself code and data space, or +you can turn off individual capabilities with defines that begin with +PNG_NO_. + +In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead. + +You can also turn all of the transforms and ancillary chunk capabilities +off en masse with compiler directives that define +PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS, +or all four, +along with directives to turn on any of the capabilities that you do +want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra +transformations but still leave the library fully capable of reading +and writing PNG files with all known public chunks. Use of the +PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library +that is incapable of reading or writing ancillary chunks. If you are +not using the progressive reading capability, you can turn that off +with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING +capability, which you'll still have). + +All the reading and writing specific code are in separate files, so the +linker should only grab the files it needs. However, if you want to +make sure, or if you are building a stand alone library, all the +reading files start with "pngr" and all the writing files start with "pngw". +The files that don't match either (like png.c, pngtrans.c, etc.) +are used for both reading and writing, and always need to be included. +The progressive reader is in pngpread.c + +If you are creating or distributing a dynamically linked library (a .so +or DLL file), you should not remove or disable any parts of the library, +as this will cause applications linked with different versions of the +library to fail if they call functions not available in your library. +The size of the library itself should not be an issue, because only +those sections that are actually used will be loaded into memory. + +Requesting debug printout + +The macro definition PNG_DEBUG can be used to request debugging +printout. Set it to an integer value in the range 0 to 3. Higher +numbers result in increasing amounts of debugging information. The +information is printed to the "stderr" file, unless another file +name is specified in the PNG_DEBUG_FILE macro definition. + +When PNG_DEBUG > 0, the following functions (macros) become available: + + png_debug(level, message) + png_debug1(level, message, p1) + png_debug2(level, message, p1, p2) + +in which "level" is compared to PNG_DEBUG to decide whether to print +the message, "message" is the formatted string to be printed, +and p1 and p2 are parameters that are to be embedded in the string +according to printf-style formatting directives. For example, + + png_debug1(2, "foo=%d\n", foo); + +is expanded to + + if (PNG_DEBUG > 2) + fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo); + +When PNG_DEBUG is defined but is zero, the macros aren't defined, but you +can still use PNG_DEBUG to control your own debugging: + + #ifdef PNG_DEBUG + fprintf(stderr, ... + #endif + +When PNG_DEBUG = 1, the macros are defined, but only png_debug statements +having level = 0 will be printed. There aren't any such statements in +this version of libpng, but if you insert some they will be printed. + +VI. MNG support + +The MNG specification (available at http://www.libpng.org/pub/mng) allows +certain extensions to PNG for PNG images that are embedded in MNG datastreams. +Libpng can support some of these extensions. To enable them, use the +png_permit_mng_features() function: + + feature_set = png_permit_mng_features(png_ptr, mask) + + mask is a png_uint_32 containing the bitwise OR of the + features you want to enable. These include + PNG_FLAG_MNG_EMPTY_PLTE + PNG_FLAG_MNG_FILTER_64 + PNG_ALL_MNG_FEATURES + + feature_set is a png_uint_32 that is the bitwise AND of + your mask with the set of MNG features that is + supported by the version of libpng that you are using. + +It is an error to use this function when reading or writing a standalone +PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped +in a MNG datastream. As a minimum, it must have the MNG 8-byte signature +and the MHDR and MEND chunks. Libpng does not provide support for these +or any other MNG chunks; your application must provide its own support for +them. You may wish to consider using libmng (available at +http://www.libmng.com) instead. + +VII. Changes to Libpng from version 0.88 + +It should be noted that versions of libpng later than 0.96 are not +distributed by the original libpng author, Guy Schalnat, nor by +Andreas Dilger, who had taken over from Guy during 1996 and 1997, and +distributed versions 0.89 through 0.96, but rather by another member +of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are +still alive and well, but they have moved on to other things. + +The old libpng functions png_read_init(), png_write_init(), +png_info_init(), png_read_destroy(), and png_write_destroy() have been +moved to PNG_INTERNAL in version 0.95 to discourage their use. These +functions will be removed from libpng version 1.4.0. + +The preferred method of creating and initializing the libpng structures is +via the png_create_read_struct(), png_create_write_struct(), and +png_create_info_struct() because they isolate the size of the structures +from the application, allow version error checking, and also allow the +use of custom error handling routines during the initialization, which +the old functions do not. The functions png_read_destroy() and +png_write_destroy() do not actually free the memory that libpng +allocated for these structs, but just reset the data structures, so they +can be used instead of png_destroy_read_struct() and +png_destroy_write_struct() if you feel there is too much system overhead +allocating and freeing the png_struct for each image read. + +Setting the error callbacks via png_set_message_fn() before +png_read_init() as was suggested in libpng-0.88 is no longer supported +because this caused applications that do not use custom error functions +to fail if the png_ptr was not initialized to zero. It is still possible +to set the error callbacks AFTER png_read_init(), or to change them with +png_set_error_fn(), which is essentially the same function, but with a new +name to force compilation errors with applications that try to use the old +method. + +Starting with version 1.0.7, you can find out which version of the library +you are using at run-time: + + png_uint_32 libpng_vn = png_access_version_number(); + +The number libpng_vn is constructed from the major version, minor +version with leading zero, and release number with leading zero, +(e.g., libpng_vn for version 1.0.7 is 10007). + +Note that this function does not take a png_ptr, so you can call it +before you've created one. + +You can also check which version of png.h you used when compiling your +application: + + png_uint_32 application_vn = PNG_LIBPNG_VER; + +VIII. Changes to Libpng from version 1.0.x to 1.2.x + +Support for user memory management was enabled by default. To +accomplish this, the functions png_create_read_struct_2(), +png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(), +png_malloc_default(), and png_free_default() were added. + +Support for the iTXt chunk has been enabled by default as of +version 1.2.41. + +Support for certain MNG features was enabled. + +Support for numbered error messages was added. However, we never got +around to actually numbering the error messages. The function +png_set_strip_error_numbers() was added (Note: the prototype for this +function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE +builds of libpng-1.2.15. It was restored in libpng-1.2.36). + +The png_malloc_warn() function was added at libpng-1.2.3. This issues +a png_warning and returns NULL instead of aborting when it fails to +acquire the requested memory allocation. + +Support for setting user limits on image width and height was enabled +by default. The functions png_set_user_limits(), png_get_user_width_max(), +and png_get_user_height_max() were added at libpng-1.2.6. + +The png_set_add_alpha() function was added at libpng-1.2.7. + +The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9. +Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the +tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is +deprecated. + +A number of macro definitions in support of runtime selection of +assembler code features (especially Intel MMX code support) were +added at libpng-1.2.0: + + PNG_ASM_FLAG_MMX_SUPPORT_COMPILED + PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU + PNG_ASM_FLAG_MMX_READ_COMBINE_ROW + PNG_ASM_FLAG_MMX_READ_INTERLACE + PNG_ASM_FLAG_MMX_READ_FILTER_SUB + PNG_ASM_FLAG_MMX_READ_FILTER_UP + PNG_ASM_FLAG_MMX_READ_FILTER_AVG + PNG_ASM_FLAG_MMX_READ_FILTER_PAETH + PNG_ASM_FLAGS_INITIALIZED + PNG_MMX_READ_FLAGS + PNG_MMX_FLAGS + PNG_MMX_WRITE_FLAGS + PNG_MMX_FLAGS + +We added the following functions in support of runtime +selection of assembler code features: + + png_get_mmx_flagmask() + png_set_mmx_thresholds() + png_get_asm_flags() + png_get_mmx_bitdepth_threshold() + png_get_mmx_rowbytes_threshold() + png_set_asm_flags() + +We replaced all of these functions with simple stubs in libpng-1.2.20, +when the Intel assembler code was removed due to a licensing issue. + +These macros are deprecated: + + PNG_READ_TRANSFORMS_NOT_SUPPORTED + PNG_PROGRESSIVE_READ_NOT_SUPPORTED + PNG_NO_SEQUENTIAL_READ_SUPPORTED + PNG_WRITE_TRANSFORMS_NOT_SUPPORTED + PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED + PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED + +They have been replaced, respectively, by: + + PNG_NO_READ_TRANSFORMS + PNG_NO_PROGRESSIVE_READ + PNG_NO_SEQUENTIAL_READ + PNG_NO_WRITE_TRANSFORMS + PNG_NO_READ_ANCILLARY_CHUNKS + PNG_NO_WRITE_ANCILLARY_CHUNKS + +PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been +deprecated since libpng-1.0.16 and libpng-1.2.6. + +The function + png_check_sig(sig, num) +was replaced with + !png_sig_cmp(sig, 0, num) +It has been deprecated since libpng-0.90. + +The function + png_set_gray_1_2_4_to_8() +which also expands tRNS to alpha was replaced with + png_set_expand_gray_1_2_4_to_8() +which does not. It has been deprecated since libpng-1.0.18 and 1.2.9. + +IX. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x + +Private libpng prototypes and macro definitions were moved from +png.h and pngconf.h into a new pngpriv.h header file. + +Functions png_set_benign_errors(), png_benign_error(), and +png_chunk_benign_error() were added. + +Support for setting the maximum amount of memory that the application +will allocate for reading chunks was added, as a security measure. +The functions png_set_chunk_cache_max() and png_get_chunk_cache_max() +were added to the library. + +We implemented support for I/O states by adding png_ptr member io_state +and functions png_get_io_chunk_name() and png_get_io_state() in pngget.c + +We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level +input transforms. + +Checking for and reporting of errors in the IHDR chunk is more thorough. + +Support for global arrays was removed, to improve thread safety. + +Some obsolete/deprecated macros and functions have been removed. + +Typecasted NULL definitions such as + #define png_voidp_NULL (png_voidp)NULL +were eliminated. If you used these in your application, just use +NULL instead. + +The png_struct and info_struct members "trans" and "trans_values" were +changed to "trans_alpha" and "trans_color", respectively. + +The obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles +were removed. + +The PNG_1_0_X and PNG_1_2_X macros were eliminated. + +The PNG_LEGACY_SUPPORTED macro was eliminated. + +Many WIN32_WCE #ifdefs were removed. + +The functions png_read_init(info_ptr), png_write_init(info_ptr), +png_info_init(info_ptr), png_read_destroy(), and png_write_destroy() +have been removed. They have been deprecated since libpng-0.95. + +The png_permit_empty_plte() was removed. It has been deprecated +since libpng-1.0.9. Use png_permit_mng_features() instead. + +We removed the obsolete stub functions png_get_mmx_flagmask(), +png_set_mmx_thresholds(), png_get_asm_flags(), +png_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(), +png_set_asm_flags(), and png_mmx_supported() + +We removed the obsolete png_check_sig(), png_memcpy_check(), and +png_memset_check() functions. Instead use !png_sig_cmp(), png_memcpy(), +and png_memset(), respectively. + +The function png_set_gray_1_2_4_to_8() was removed. It has been +deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with +png_set_expand_gray_1_2_4_to_8() because the former function also +expanded any tRNS chunk to an alpha channel. + +Macros for png_get_uint_16, png_get_uint_32, and png_get_int_32 +were added and are used by default instead of the corresponding +functions. Unfortunately, +from libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the +function) incorrectly returned a value of type png_uint_32. + +We changed the prototype for png_malloc() from + png_malloc(png_structp png_ptr, png_uint_32 size) +to + png_malloc(png_structp png_ptr, png_alloc_size_t size) + +This also applies to the prototype for the user replacement malloc_fn(). + +The png_calloc() function was added and is used in place of +of "png_malloc(); memset();" except in the case in png_read_png() +where the array consists of pointers; in this case a "for" loop is used +after the png_malloc() to set the pointers to NULL, to give robust. +behavior in case the application runs out of memory part-way through +the process. + +We changed the prototypes of png_get_compression_buffer_size() and +png_set_compression_buffer_size() to work with png_size_t instead of +png_uint_32. + +Support for numbered error messages was removed by default, since we +never got around to actually numbering the error messages. The function +png_set_strip_error_numbers() was removed from the library by default. + +The png_zalloc() and png_zfree() functions are no longer exported. +The png_zalloc() function no longer zeroes out the memory that it +allocates. Applications that called png_zalloc(png_ptr, number, size) +can call png_calloc(png_ptr, number*size) instead, and can call +png_free() instead of png_zfree(). + +Support for dithering was disabled by default in libpng-1.4.0, because +it has not been well tested and doesn't actually "dither". +The code was not +removed, however, and could be enabled by building libpng with +PNG_READ_DITHER_SUPPORTED defined. In libpng-1.4.2, this support +was reenabled, but the function was renamed png_set_quantize() to +reflect more accurately what it actually does. At the same time, +the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to +PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED +was renamed to PNG_READ_QUANTIZE_SUPPORTED. + +We removed the trailing '.' from the warning and error messages. + +X. Changes to Libpng from version 1.4.x to 1.5.x + +From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the +function) incorrectly returned a value of type png_uint_32. + +Checking for invalid palette index on read or write was added at libpng +1.5.10. When an invalid index is found, libpng issues a benign error. +This is enabled by default but can be disabled in each png_ptr with + + png_set_check_for_invalid_index(png_ptr, allowed); + + allowed - one of + 0: disable + 1: enable + +A. Changes that affect users of libpng + +There are no substantial API changes between the non-deprecated parts of +the 1.4.5 API and the 1.5.0 API; however, the ability to directly access +members of the main libpng control structures, png_struct and png_info, +deprecated in earlier versions of libpng, has been completely removed from +libpng 1.5. + +We no longer include zlib.h in png.h. Applications that need access +to information in zlib.h will need to add the '#include "zlib.h"' +directive. It does not matter whether it is placed prior to or after +the '"#include png.h"' directive. + +The png_sprintf(), png_strcpy(), and png_strncpy() macros are no longer used +and were removed. + +We moved the png_strlen(), png_memcpy(), png_memset(), and png_memcmp() +macros into a private header file (pngpriv.h) that is not accessible to +applications. + +In png_get_iCCP, the type of "profile" was changed from png_charpp +to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep. + +There are changes of form in png.h, including new and changed macros to +declare parts of the API. Some API functions with arguments that are +pointers to data not modified within the function have been corrected to +declare these arguments with PNG_CONST. + +Much of the internal use of C macros to control the library build has also +changed and some of this is visible in the exported header files, in +particular the use of macros to control data and API elements visible +during application compilation may require significant revision to +application code. (It is extremely rare for an application to do this.) + +Any program that compiled against libpng 1.4 and did not use deprecated +features or access internal library structures should compile and work +against libpng 1.5, except for the change in the prototype for +png_get_iCCP() and png_set_iCCP() API functions mentioned above. + +libpng 1.5.0 adds PNG_ PASS macros to help in the reading and writing of +interlaced images. The macros return the number of rows and columns in +each pass and information that can be used to de-interlace and (if +absolutely necessary) interlace an image. + +libpng 1.5.0 adds an API png_longjmp(png_ptr, value). This API calls +the application-provided png_longjmp_ptr on the internal, but application +initialized, longjmp buffer. It is provided as a convenience to avoid +the need to use the png_jmpbuf macro, which had the unnecessary side +effect of resetting the internal png_longjmp_ptr value. + +libpng 1.5.0 includes a complete fixed point API. By default this is +present along with the corresponding floating point API. In general the +fixed point API is faster and smaller than the floating point one because +the PNG file format used fixed point, not floating point. This applies +even if the library uses floating point in internal calculations. A new +macro, PNG_FLOATING_ARITHMETIC_SUPPORTED, reveals whether the library +uses floating point arithmetic (the default) or fixed point arithmetic +internally for performance critical calculations such as gamma correction. +In some cases, the gamma calculations may produce slightly different +results. This has changed the results in png_rgb_to_gray and in alpha +composition (png_set_background for example). This applies even if the +original image was already linear (gamma == 1.0) and, therefore, it is +not necessary to linearize the image. This is because libpng has *not* +been changed to optimize that case correctly, yet. + +Fixed point support for the sCAL chunk comes with an important caveat; +the sCAL specification uses a decimal encoding of floating point values +and the accuracy of PNG fixed point values is insufficient for +representation of these values. Consequently a "string" API +(png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading +arbitrary sCAL chunks in the absence of either the floating point API or +internal floating point calculations. + +Applications no longer need to include the optional distribution header +file pngusr.h or define the corresponding macros during application +build in order to see the correct variant of the libpng API. From 1.5.0 +application code can check for the corresponding _SUPPORTED macro: + +#ifdef PNG_INCH_CONVERSIONS_SUPPORTED + /* code that uses the inch conversion APIs. */ +#endif + +This macro will only be defined if the inch conversion functions have been +compiled into libpng. The full set of macros, and whether or not support +has been compiled in, are available in the header file pnglibconf.h. +This header file is specific to the libpng build. Notice that prior to +1.5.0 the _SUPPORTED macros would always have the default definition unless +reset by pngusr.h or by explicit settings on the compiler command line. +These settings may produce compiler warnings or errors in 1.5.0 because +of macro redefinition. + +From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the +function) incorrectly returned a value of type png_uint_32. libpng 1.5.0 +is consistent with the implementation in 1.4.5 and 1.2.x (where the macro +did not exist.) + +Applications can now choose whether to use these macros or to call the +corresponding function by defining PNG_USE_READ_MACROS or +PNG_NO_USE_READ_MACROS before including png.h. Notice that this is +only supported from 1.5.0 -defining PNG_NO_USE_READ_MACROS prior to 1.5.0 +will lead to a link failure. + +Prior to libpng-1.5.4, the zlib compressor used the same set of parameters +when compressing the IDAT data and textual data such as zTXt and iCCP. +In libpng-1.5.4 we reinitialized the zlib stream for each type of data. +We added five png_set_text_*() functions for setting the parameters to +use with textual data. + +Prior to libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED +option was off by default, and slightly inaccurate scaling occurred. +This option can no longer be turned off, and the choice of accurate +or inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8() +API for accurate scaling or the old png_set_strip_16_to_8() API for simple +chopping. + +Prior to libpng-1.5.4, the png_set_user_limits() function could only be +used to reduce the width and height limits from the value of +PNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX, although this document said +that it could be used to override them. Now this function will reduce or +increase the limits. + +Starting in libpng-1.5.10, the user limits can be set en masse with the +configuration option PNG_SAFE_LIMITS_SUPPORTED. If this option is enabled, +a set of "safe" limits is applied in pngpriv.h. These can be overridden by +application calls to png_set_user_limits(), png_set_user_chunk_cache_max(), +and/or png_set_user_malloc_max() that increase or decrease the limits. Also, +in libpng-1.5.10 the default width and height limits were increased +from 1,000,000 to 0x7ffffff (i.e., made unlimited). Therefore, the +limits are now + default safe + png_user_width_max 0x7fffffff 1,000,000 + png_user_height_max 0x7fffffff 1,000,000 + png_user_chunk_cache_max 0 (unlimited) 128 + png_user_chunk_malloc_max 0 (unlimited) 8,000,000 + +B. Changes to the build and configuration of libpng + +Details of internal changes to the library code can be found in the CHANGES +file and in the GIT repository logs. These will be of no concern to the vast +majority of library users or builders; however, the few who configure libpng +to a non-default feature set may need to change how this is done. + +There should be no need for library builders to alter build scripts if +these use the distributed build support - configure or the makefiles - +however, users of the makefiles may care to update their build scripts +to build pnglibconf.h where the corresponding makefile does not do so. + +Building libpng with a non-default configuration has changed completely. +The old method using pngusr.h should still work correctly even though the +way pngusr.h is used in the build has been changed; however, library +builders will probably want to examine the changes to take advantage of +new capabilities and to simplify their build system. + +B.1 Specific changes to library configuration capabilities + +The library now supports a complete fixed point implementation and can +thus be used on systems that have no floating point support or very +limited or slow support. Previously gamma correction, an essential part +of complete PNG support, required reasonably fast floating point. + +As part of this the choice of internal implementation has been made +independent of the choice of fixed versus floating point APIs and all the +missing fixed point APIs have been implemented. + +The exact mechanism used to control attributes of API functions has +changed. A single set of operating system independent macro definitions +is used and operating system specific directives are defined in +pnglibconf.h + +As part of this the mechanism used to choose procedure call standards on +those systems that allow a choice has been changed. At present this only +affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems +running on Intel processors. As before, PNGAPI is defined where required +to control the exported API functions; however, two new macros, PNGCBAPI +and PNGCAPI, are used instead for callback functions (PNGCBAPI) and +(PNGCAPI) for functions that must match a C library prototype (currently +only png_longjmp_ptr, which must match the C longjmp function.) The new +approach is documented in pngconf.h + +Despite these changes, libpng 1.5.0 only supports the native C function +calling standard on those platforms tested so far (__cdecl on Microsoft +Windows). This is because the support requirements for alternative +calling conventions seem to no longer exist. Developers who find it +necessary to set PNG_API_RULE to 1 should advise the mailing list +(png-mng-implement) of this and library builders who use Openwatcom and +therefore set PNG_API_RULE to 2 should also contact the mailing list. + +A new test program, pngvalid, is provided in addition to pngtest. +pngvalid validates the arithmetic accuracy of the gamma correction +calculations and includes a number of validations of the file format. +A subset of the full range of tests is run when "make check" is done +(in the 'configure' build.) pngvalid also allows total allocated memory +usage to be evaluated and performs additional memory overwrite validation. + +Many changes to individual feature macros have been made. The following +are the changes most likely to be noticed by library builders who +configure libpng: + +1) All feature macros now have consistent naming: + +#define PNG_NO_feature turns the feature off +#define PNG_feature_SUPPORTED turns the feature on + +pnglibconf.h contains one line for each feature macro which is either: + +#define PNG_feature_SUPPORTED + +if the feature is supported or: + +/*#undef PNG_feature_SUPPORTED*/ + +if it is not. Library code consistently checks for the 'SUPPORTED' macro. +It does not, and libpng applications should not, check for the 'NO' macro +which will not normally be defined even if the feature is not supported. +The 'NO' macros are only used internally for setting or not setting the +corresponding 'SUPPORTED' macros. + +Compatibility with the old names is provided as follows: + +PNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED + +And the following definitions disable the corresponding feature: + +PNG_SETJMP_NOT_SUPPORTED disables SETJMP +PNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS +PNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV +PNG_WRITE_TRANSFORMS_NOT_SUPPORTED disables WRITE_TRANSFORMS +PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED disables READ_ANCILLARY_CHUNKS +PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED disables WRITE_ANCILLARY_CHUNKS + +Library builders should remove use of the above, inconsistent, names. + +2) Warning and error message formatting was previously conditional on +the STDIO feature. The library has been changed to use the +CONSOLE_IO feature instead. This means that if CONSOLE_IO is disabled +the library no longer uses the printf(3) functions, even though the +default read/write implementations use (FILE) style stdio.h functions. + +3) Three feature macros now control the fixed/floating point decisions: + +PNG_FLOATING_POINT_SUPPORTED enables the floating point APIs + +PNG_FIXED_POINT_SUPPORTED enables the fixed point APIs; however, in +practice these are normally required internally anyway (because the PNG +file format is fixed point), therefore in most cases PNG_NO_FIXED_POINT +merely stops the function from being exported. + +PNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating +point implementation or the fixed point one. Typically the fixed point +implementation is larger and slower than the floating point implementation +on a system that supports floating point; however, it may be faster on a +system which lacks floating point hardware and therefore uses a software +emulation. + +4) Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the +functions to read and write ints to be disabled independently of +PNG_USE_READ_MACROS, which allows libpng to be built with the functions +even though the default is to use the macros - this allows applications +to choose at app buildtime whether or not to use macros (previously +impossible because the functions weren't in the default build.) + +B.2 Changes to the configuration mechanism + +Prior to libpng-1.5.0 library builders who needed to configure libpng +had either to modify the exported pngconf.h header file to add system +specific configuration or had to write feature selection macros into +pngusr.h and cause this to be included into pngconf.h by defining +PNG_USER_CONFIG. The latter mechanism had the disadvantage that an +application built without PNG_USER_CONFIG defined would see the +unmodified, default, libpng API and thus would probably fail to link. + +These mechanisms still work in the configure build and in any makefile +build that builds pnglibconf.h, although the feature selection macros +have changed somewhat as described above. In 1.5.0, however, pngusr.h is +processed only once, when the exported header file pnglibconf.h is built. +pngconf.h no longer includes pngusr.h, therefore pngusr.h is ignored after the +build of pnglibconf.h and it is never included in an application build. + +The rarely used alternative of adding a list of feature macros to the +CFLAGS setting in the build also still works; however, the macros will be +copied to pnglibconf.h and this may produce macro redefinition warnings +when the individual C files are compiled. + +All configuration now only works if pnglibconf.h is built from +scripts/pnglibconf.dfa. This requires the program awk. Brian Kernighan +(the original author of awk) maintains C source code of that awk and this +and all known later implementations (often called by subtly different +names - nawk and gawk for example) are adequate to build pnglibconf.h. +The Sun Microsystems (now Oracle) program 'awk' is an earlier version +and does not work; this may also apply to other systems that have a +functioning awk called 'nawk'. + +Configuration options are now documented in scripts/pnglibconf.dfa. This +file also includes dependency information that ensures a configuration is +consistent; that is, if a feature is switched off dependent features are +also removed. As a recommended alternative to using feature macros in +pngusr.h a system builder may also define equivalent options in pngusr.dfa +(or, indeed, any file) and add that to the configuration by setting +DFA_XTRA to the file name. The makefiles in contrib/pngminim illustrate +how to do this, and a case where pngusr.h is still required. + +XI. Detecting libpng + +The png_get_io_ptr() function has been present since libpng-0.88, has never +changed, and is unaffected by conditional compilation macros. It is the +best choice for use in configure scripts for detecting the presence of any +libpng version since 0.88. In an autoconf "configure.in" you could use + + AC_CHECK_LIB(png, png_get_io_ptr, ... + +XII. Source code repository + +Since about February 2009, version 1.2.34, libpng has been under "git" source +control. The git repository was built from old libpng-x.y.z.tar.gz files +going back to version 0.70. You can access the git repository (read only) +at + + git://libpng.git.sourceforge.net/gitroot/libpng + +or you can browse it via "gitweb" at + + http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng + +Patches can be sent to glennrp at users.sourceforge.net or to +png-mng-implement at lists.sourceforge.net or you can upload them to +the libpng bug tracker at + + http://libpng.sourceforge.net + +We also accept patches built from the tar or zip distributions, and +simple verbal discriptions of bug fixes, reported either to the +SourceForge bug tracker, to the png-mng-implement at lists.sf.net +mailing list, or directly to glennrp. + +XIII. Coding style + +Our coding style is similar to the "Allman" style, with curly +braces on separate lines: + + if (condition) + { + action; + } + + else if (another condition) + { + another action; + } + +The braces can be omitted from simple one-line actions: + + if (condition) + return (0); + +We use 3-space indentation, except for continued statements which +are usually indented the same as the first line of the statement +plus four more spaces. + +For macro definitions we use 2-space indentation, always leaving the "#" +in the first column. + + #ifndef PNG_NO_FEATURE + # ifndef PNG_FEATURE_SUPPORTED + # define PNG_FEATURE_SUPPORTED + # endif + #endif + +Comments appear with the leading "/*" at the same indentation as +the statement that follows the comment: + + /* Single-line comment */ + statement; + + /* This is a multiple-line + * comment. + */ + statement; + +Very short comments can be placed after the end of the statement +to which they pertain: + + statement; /* comment */ + +We don't use C++ style ("//") comments. We have, however, +used them in the past in some now-abandoned MMX assembler +code. + +Functions and their curly braces are not indented, and +exported functions are marked with PNGAPI: + + /* This is a public function that is visible to + * application programmers. It does thus-and-so. + */ + void PNGAPI + png_exported_function(png_ptr, png_info, foo) + { + body; + } + +The prototypes for all exported functions appear in png.h, +above the comment that says + + /* Maintainer: Put new public prototypes here ... */ + +We mark all non-exported functions with "/* PRIVATE */"": + + void /* PRIVATE */ + png_non_exported_function(png_ptr, png_info, foo) + { + body; + } + +The prototypes for non-exported functions (except for those in +pngtest) appear in +pngpriv.h +above the comment that says + + /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ + +To avoid polluting the global namespace, the names of all exported +functions and variables begin with "png_", and all publicly visible C +preprocessor macros begin with "PNG". We request that applications that +use libpng *not* begin any of their own symbols with either of these strings. + +We put a space after each comma and after each semicolon +in "for" statements, and we put spaces before and after each +C binary operator and after "for" or "while", and before +"?". We don't put a space between a typecast and the expression +being cast, nor do we put one between a function name and the +left parenthesis that follows it: + + for (i = 2; i > 0; --i) + y[i] = a(x) + (int)b; + +We prefer #ifdef and #ifndef to #if defined() and if !defined() +when there is only one macro being tested. + +We prefer to express integers that are used as bit masks in hex format, +with an even number of lower-case hex digits (e.g., 0x00, 0xff, 0x0100). + +We do not use the TAB character for indentation in the C sources. + +Lines do not exceed 80 characters. + +Other rules can be inferred by inspecting the libpng source. + +XIV. Y2K Compliance in libpng + +September 27, 2012 + +Since the PNG Development group is an ad-hoc body, we can't make +an official declaration. + +This is your unofficial assurance that libpng from version 0.71 and +upward through 1.5.13 are Y2K compliant. It is my belief that earlier +versions were also Y2K compliant. + +Libpng only has two year fields. One is a 2-byte unsigned integer that +will hold years up to 65535. The other holds the date in text +format, and will hold years up to 9999. + +The integer is + "png_uint_16 year" in png_time_struct. + +The string is + "char time_buffer[29]" in png_struct. This will no +longer be used in libpng-1.6.x and will be removed from libpng-1.7.0. + +There are seven time-related functions: + + png_convert_to_rfc_1123() in png.c + (formerly png_convert_to_rfc_1152() in error) + png_convert_from_struct_tm() in pngwrite.c, called + in pngwrite.c + png_convert_from_time_t() in pngwrite.c + png_get_tIME() in pngget.c + png_handle_tIME() in pngrutil.c, called in pngread.c + png_set_tIME() in pngset.c + png_write_tIME() in pngwutil.c, called in pngwrite.c + +All appear to handle dates properly in a Y2K environment. The +png_convert_from_time_t() function calls gmtime() to convert from system +clock time, which returns (year - 1900), which we properly convert to +the full 4-digit year. There is a possibility that applications using +libpng are not passing 4-digit years into the png_convert_to_rfc_1123() +function, or that they are incorrectly passing only a 2-digit year +instead of "year - 1900" into the png_convert_from_struct_tm() function, +but this is not under our control. The libpng documentation has always +stated that it works with 4-digit years, and the APIs have been +documented as such. + +The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned +integer to hold the year, and can hold years as large as 65535. + +zlib, upon which libpng depends, is also Y2K compliant. It contains +no date-related code. + + + Glenn Randers-Pehrson + libpng maintainer + PNG Development Group diff --git a/Source/LibPNG/libpng.3 b/Source/LibPNG/libpng.3 index e0e0aec..6cfd7c6 100644 --- a/Source/LibPNG/libpng.3 +++ b/Source/LibPNG/libpng.3 @@ -1,5996 +1,5996 @@ -.TH LIBPNG 3 "September 27, 2012" -.SH NAME -libpng \- Portable Network Graphics (PNG) Reference Library 1.5.13 -.SH SYNOPSIS -\fI\fB - -\fB#include \fP - -\fI\fB - -\fBpng_uint_32 png_access_version_number \fI(void\fP\fB);\fP - -\fI\fB - -\fBvoid png_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP - -\fI\fB - -\fBvoid png_build_grayscale_palette (int \fP\fIbit_depth\fP\fB, png_colorp \fIpalette\fP\fB);\fP - -\fI\fB - -\fBpng_voidp png_calloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP - -\fI\fB - -\fBvoid png_chunk_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP - -\fI\fB - -\fBvoid png_chunk_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP - -\fI\fB - -\fBvoid png_chunk_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP - -\fI\fB - -\fBvoid png_convert_from_struct_tm (png_timep \fP\fIptime\fP\fB, struct tm FAR * \fIttime\fP\fB);\fP - -\fI\fB - -\fBvoid png_convert_from_time_t (png_timep \fP\fIptime\fP\fB, time_t \fIttime\fP\fB);\fP - -\fI\fB - -\fBpng_charp png_convert_to_rfc1123 (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fIptime\fP\fB);\fP - -\fI\fB - -\fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_structp png_create_read_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP - -\fI\fB - -\fBpng_structp png_create_read_struct_2 (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP - -\fI\fB - -\fBpng_structp png_create_write_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP - -\fI\fB - -\fBpng_structp png_create_write_struct_2 (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP - -\fI\fB - -\fBvoid png_data_freer (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIfreer\fP\fB, png_uint_32 \fImask)\fP\fB);\fP - -\fI\fB - -\fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_destroy_read_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fP\fIinfo_ptr_ptr\fP\fB, png_infopp \fIend_info_ptr_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_err (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP - -\fI\fB - -\fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_free_default (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_free_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum\fP\fB);\fP - -\fI\fB - -\fBpng_byte png_get_bit_depth (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_bKGD (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fI*background\fP\fB);\fP - -\fI\fB - -\fBpng_byte png_get_channels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_cHRM (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*white_x\fP\fB, double \fP\fI*white_y\fP\fB, double \fP\fI*red_x\fP\fB, double \fP\fI*red_y\fP\fB, double \fP\fI*green_x\fP\fB, double \fP\fI*green_y\fP\fB, double \fP\fI*blue_x\fP\fB, double \fI*blue_y\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_cHRM_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*white_x\fP\fB, png_uint_32 \fP\fI*white_y\fP\fB, png_uint_32 \fP\fI*red_x\fP\fB, png_uint_32 \fP\fI*red_y\fP\fB, png_uint_32 \fP\fI*green_x\fP\fB, png_uint_32 \fP\fI*green_y\fP\fB, png_uint_32 \fP\fI*blue_x\fP\fB, png_uint_32 \fI*blue_y\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_cHRM_XYZ (png_structp \fIpng_ptr, - -\fBpng_const_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*red_X\fP\fB, double \fP\fI*red_Y\fP\fB, double \fI*red_Z, - -\fBdouble \fP\fI*green_X\fP\fB, double \fP\fI*green_Y\fP\fB, double \fP\fI*green_Z\fP\fB, double \fI*blue_X, - -\fBdouble \fP\fI*blue_Y\fP\fB, double \fI*blue_Z\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_cHRM_XYZ_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_fixed_point \fP\fI*int_red_X\fP\fB, png_fixed_point \fP\fI*int_red_Y\fP\fB, png_fixed_point \fP\fI*int_red_Z\fP\fB, png_fixed_point \fP\fI*int_green_X\fP\fB, png_fixed_point \fP\fI*int_green_Y\fP\fB, png_fixed_point \fP\fI*int_green_Z\fP\fB, png_fixed_point \fP\fI*int_blue_X\fP\fB, png_fixed_point \fP\fI*int_blue_Y\fP\fB, png_fixed_point \fI*int_blue_Z\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_chunk_cache_max (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_alloc_size_t png_get_chunk_malloc_max (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_byte png_get_color_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_compression_buffer_size (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_byte png_get_compression_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_byte png_get_copyright (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_current_row_number \fI(png_const_structp\fP\fB);\fP - -\fI\fB - -\fBpng_byte png_get_current_pass_number \fI(png_const_structp\fP\fB);\fP - -\fI\fB - -\fBpng_voidp png_get_error_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_byte png_get_filter_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_gAMA (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, double \fI*file_gamma\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_gAMA_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fI*int_file_gamma\fP\fB);\fP - -\fI\fB - -\fBpng_byte png_get_header_ver (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_byte png_get_header_version (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_hIST (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fI*hist\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_iCCP (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_charpp \fP\fIname\fP\fB, int \fP\fI*compression_type\fP\fB, png_bytepp \fP\fIprofile\fP\fB, png_uint_32 \fI*proflen\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*width\fP\fB, png_uint_32 \fP\fI*height\fP\fB, int \fP\fI*bit_depth\fP\fB, int \fP\fI*color_type\fP\fB, int \fP\fI*interlace_type\fP\fB, int \fP\fI*compression_type\fP\fB, int \fI*filter_type\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_image_height (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_image_width (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP - -\fI\fB - -\fBpng_byte png_get_interlace_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_const_bytep png_get_io_chunk_name (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_io_chunk_type (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_io_state (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_byte png_get_libpng_ver (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_voidp png_get_mem_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_oFFs (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*offset_x\fP\fB, png_uint_32 \fP\fI*offset_y\fP\fB, int \fI*unit_type\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_pCAL (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fI*purpose\fP\fB, png_int_32 \fP\fI*X0\fP\fB, png_int_32 \fP\fI*X1\fP\fB, int \fP\fI*type\fP\fB, int \fP\fI*nparams\fP\fB, png_charp \fP\fI*units\fP\fB, png_charpp \fI*params\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_pHYs (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP - -\fI\fB - -\fBfloat png_get_pixel_aspect_ratio (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_pHYs_dpi (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP - -\fI\fB - -\fBpng_fixed_point png_get_pixel_aspect_ratio_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_voidp png_get_progressive_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_PLTE (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fI*palette\fP\fB, int \fI*num_palette\fP\fB);\fP - -\fI\fB - -\fBpng_byte png_get_rgb_to_gray_status (png_const_structp \fIpng_ptr) - -\fBpng_uint_32 png_get_rowbytes (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_bytepp png_get_rows (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_sBIT (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP - -\fI\fB - -\fBvoid png_get_sCAL (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, double* \fP\fIwidth\fP\fB, double* \fIheight\fP\fB);\fP - -\fI\fB - -\fBvoid png_get_sCAL_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, png_fixed_pointp \fP\fIwidth\fP\fB, png_fixed_pointp \fIheight\fP\fB);\fP - -\fI\fB - -\fBvoid png_get_sCAL_s (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, png_charpp \fP\fIwidth\fP\fB, png_charpp \fIheight\fP\fB);\fP - -\fI\fB - -\fBpng_bytep png_get_signature (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_sPLT (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fI*splt_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_sRGB (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int \fI*file_srgb_intent\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_text (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fI*text_ptr\fP\fB, int \fI*num_text\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_tIME (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fI*mod_time\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_tRNS (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fI*trans_alpha\fP\fB, int \fP\fI*num_trans\fP\fB, png_color_16p \fI*trans_color\fP\fB);\fP - -\fI\fB - -\fB/* This function is really an inline macro. \fI*/ - -\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_uint_31 (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIbuf\fP\fB);\fP - -\fI\fB - -\fB/* This function is really an inline macro. \fI*/ - -\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_unknown_chunks (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkpp \fIunknowns\fP\fB);\fP - -\fI\fB - -\fBpng_voidp png_get_user_chunk_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_user_height_max (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_voidp png_get_user_transform_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_user_width_max (png_const_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_valid (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIflag\fP\fB);\fP - -\fI\fB - -\fBfloat png_get_x_offset_inches (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_fixed_point png_get_x_offset_inches_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_int_32 png_get_x_offset_microns (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_int_32 png_get_x_offset_pixels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_x_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_x_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBfloat png_get_y_offset_inches (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_fixed_point png_get_y_offset_inches_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_int_32 png_get_y_offset_microns (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_int_32 png_get_y_offset_pixels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_y_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_get_y_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP - -\fI\fB - -\fBvoid png_info_init_3 (png_infopp \fP\fIinfo_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP - -\fI\fB - -\fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP - -\fI\fB - -\fBvoid png_longjmp (png_structp \fP\fIpng_ptr\fP\fB, int \fIval\fP\fB);\fP - -\fI\fB - -\fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP - -\fI\fB - -\fBpng_voidp png_malloc_default (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP - -\fI\fB - -\fBpng_voidp png_malloc_warn (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_permit_mng_features (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fImng_features_permitted\fP\fB);\fP - -\fI\fB - -\fBvoid png_process_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_size\fP\fB);\fP - -\fI\fB - -\fBpng_size_t png_process_data_pause \fP\fI(png_structp\fP\fB, int \fIsave\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_process_data_skip \fI(png_structp\fP\fB);\fP - -\fI\fB - -\fBvoid png_progressive_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIold_row\fP\fB, png_bytep \fInew_row\fP\fB);\fP - -\fI\fB - -\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP - -\fI\fB - -\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_read_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP - -\fI\fB - -\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP - -\fI\fB - -\fBvoid png_read_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_bytepp \fP\fIdisplay_row\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP - -\fI\fB - -\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBint png_reset_zstream (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP - -\fI\fB - -\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP - -\fI\fB - -\fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_alpha_mode (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImode\fP\fB, double \fIoutput_gamma\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_alpha_mode_fixed (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImode\fP\fB, png_fixed_point \fIoutput_gamma\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_background (png_structp \fP\fIpng_ptr\fP\fB, png_color_16p \fP\fIbackground_color\fP\fB, int \fP\fIbackground_gamma_code\fP\fB, int \fP\fIneed_expand\fP\fB, double \fIbackground_gamma\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_background_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_color_16p \fP\fIbackground_color\fP\fB, int \fP\fIbackground_gamma_code\fP\fB, int \fP\fIneed_expand\fP\fB, png_uint_32 \fIbackground_gamma\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_benign_errors (png_structp \fP\fIpng_ptr\fP\fB, int \fIallowed\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fIbackground\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_check_for_invalid_index(png_structrp \fP\fIpng_ptr\fP\fB, int \fIallowed\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fIwhite_x\fP\fB, double \fP\fIwhite_y\fP\fB, double \fP\fIred_x\fP\fB, double \fP\fIred_y\fP\fB, double \fP\fIgreen_x\fP\fB, double \fP\fIgreen_y\fP\fB, double \fP\fIblue_x\fP\fB, double \fIblue_y\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwhite_x\fP\fB, png_uint_32 \fP\fIwhite_y\fP\fB, png_uint_32 \fP\fIred_x\fP\fB, png_uint_32 \fP\fIred_y\fP\fB, png_uint_32 \fP\fIgreen_x\fP\fB, png_uint_32 \fP\fIgreen_y\fP\fB, png_uint_32 \fP\fIblue_x\fP\fB, png_uint_32 \fIblue_y\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_cHRM_XYZ (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fIred_X\fP\fB, double \fP\fIred_Y\fP\fB, double \fP\fIred_Z\fP\fB, double \fP\fIgreen_X\fP\fB, double \fIgreen_Y, - -\fBdouble \fP\fIgreen_Z\fP\fB, double \fP\fIblue_X\fP\fB, double \fP\fIblue_Y\fP\fB, double \fIblue_Z\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_cHRM_XYZ_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_fixed_point \fP\fIint_red_X\fP\fB, png_fixed_point \fP\fIint_red_Y\fP\fB, png_fixed_point \fP\fIint_red_Z\fP\fB, png_fixed_point \fP\fIint_green_X\fP\fB, png_fixed_point \fP\fIint_green_Y\fP\fB, png_fixed_point \fP\fIint_green_Z\fP\fB, png_fixed_point \fP\fIint_blue_X\fP\fB, png_fixed_point \fP\fIint_blue_Y\fP\fB, png_fixed_point \fIint_blue_Z\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_chunk_cache_max (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIuser_chunk_cache_max\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_crc_action (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcrit_action\fP\fB, int \fIancil_action\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_error_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarning_fn\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_expand_16 (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_expand_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_filler (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_filter (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImethod\fP\fB, int \fIfilters\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_filter_heuristics (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIheuristic_method\fP\fB, int \fP\fInum_weights\fP\fB, png_doublep \fP\fIfilter_weights\fP\fB, png_doublep \fIfilter_costs\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_filter_heuristics_fixed (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIheuristic_method\fP\fB, int \fP\fInum_weights\fP\fB, png_fixed_point_p \fP\fIfilter_weights\fP\fB, png_fixed_point_p \fIfilter_costs\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_gamma (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIscreen_gamma\fP\fB, double \fIdefault_file_gamma\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_gamma_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIscreen_gamma\fP\fB, png_uint_32 \fIdefault_file_gamma\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIfile_gamma\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fIhist\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_const_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_const_bytep \fP\fIprofile\fP\fB, png_uint_32 \fIproflen\fP\fB);\fP - -\fI\fB - -\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIinterlace_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fIfilter_type\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_keep_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIkeep\fP\fB, png_bytep \fP\fIchunk_list\fP\fB, int \fInum_chunks\fP\fB);\fP - -\fI\fB - -\fBjmp_buf* png_set_longjmp_fn (png_structp \fP\fIpng_ptr\fP\fB, png_longjmp_ptr \fP\fIlongjmp_fn\fP\fB, size_t \fIjmp_buf_size\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_chunk_malloc_max (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIuser_chunk_cache_max\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_compression_buffer_size (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_mem_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIoffset_x\fP\fB, png_uint_32 \fP\fIoffset_y\fP\fB, int \fIunit_type\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_palette_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIpurpose\fP\fB, png_int_32 \fP\fIX0\fP\fB, png_int_32 \fP\fIX1\fP\fB, int \fP\fItype\fP\fB, int \fP\fInparams\fP\fB, png_charp \fP\fIunits\fP\fB, png_charpp \fIparams\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIres_x\fP\fB, png_uint_32 \fP\fIres_y\fP\fB, int \fIunit_type\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_progressive_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIprogressive_ptr\fP\fB, png_progressive_info_ptr \fP\fIinfo_fn\fP\fB, png_progressive_row_ptr \fP\fIrow_fn\fP\fB, png_progressive_end_ptr \fIend_fn\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fInum_palette\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_quantize (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fP\fInum_palette\fP\fB, int \fP\fImaximum_colors\fP\fB, png_uint_16p \fP\fIhistogram\fP\fB, int \fIfull_quantize\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fIread_data_fn\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_read_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_read_status_ptr \fIread_row_fn\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_read_user_chunk_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_chunk_ptr\fP\fB, png_user_chunk_ptr \fIread_user_chunk_fn\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_read_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIread_user_transform_fn\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_rgb_to_gray (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIerror_action\fP\fB, double \fP\fIred\fP\fB, double \fIgreen\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_rgb_to_gray_fixed (png_structp \fP\fIpng_ptr\fP\fB, int error_action png_uint_32 \fP\fIred\fP\fB, png_uint_32 \fIgreen\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytepp \fIrow_pointers\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fIsig_bit\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_sCAL_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, png_fixed_point \fP\fIwidth\fP\fB, png_fixed_point \fIheight\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_sCAL_s (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, png_charp \fP\fIwidth\fP\fB, png_charp \fIheight\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_scale_16 (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_shift (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fItrue_bits\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_sig_bytes (png_structp \fP\fIpng_ptr\fP\fB, int \fInum_bytes\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fP\fIsplt_ptr\fP\fB, int \fInum_spalettes\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIsrgb_intent\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_sRGB_gAMA_and_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIsrgb_intent\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_strip_error_numbers (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIstrip_mode\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fItext_ptr\fP\fB, int \fInum_text\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_text_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_text_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_text_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_text_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP - -\fI\fB - -\fBvoid \fP\fIpng_set_text_compression_method\fP\fB, (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod)\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fImod_time\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fItrans_alpha\fP\fB, int \fP\fInum_trans\fP\fB, png_color_16p \fItrans_color\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_tRNS_to_alpha (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBpng_uint_32 png_set_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkp \fP\fIunknowns\fP\fB, int \fP\fInum\fP\fB, int \fIlocation\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_unknown_chunk_location (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIchunk\fP\fB, int \fIlocation\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_user_limits (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIuser_width_max\fP\fB, png_uint_32 \fIuser_height_max\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_user_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_transform_ptr\fP\fB, int \fP\fIuser_transform_depth\fP\fB, int \fIuser_transform_channels\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_write_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fP\fIwrite_data_fn\fP\fB, png_flush_ptr \fIoutput_flush_fn\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_write_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_write_status_ptr \fIwrite_row_fn\fP\fB);\fP - -\fI\fB - -\fBvoid png_set_write_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIwrite_user_transform_fn\fP\fB);\fP - -\fI\fB - -\fBint png_sig_cmp (png_bytep \fP\fIsig\fP\fB, png_size_t \fP\fIstart\fP\fB, png_size_t \fInum_to_check\fP\fB);\fP - -\fI\fB - -\fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP - -\fI\fB - -\fBvoid png_write_chunk (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP - -\fI\fB - -\fBvoid png_write_chunk_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP - -\fI\fB - -\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_write_chunk_start (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_uint_32 \fIlength\fP\fB);\fP - -\fI\fB - -\fBvoid png_write_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_write_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP - -\fI\fB - -\fBvoid png_write_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP - -\fI\fB - -\fBvoid png_write_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP - -\fI\fB - -\fBvoid png_write_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP - -\fI\fB - -\fBvoid png_write_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP - -\fI\fB - -\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP - -\fI\fB - -.SH DESCRIPTION -The -.I libpng -library supports encoding, decoding, and various manipulations of -the Portable Network Graphics (PNG) format image files. It uses the -.IR zlib(3) -compression library. -Following is a copy of the libpng-manual.txt file that accompanies libpng. -.SH LIBPNG.TXT -Libpng-manual.txt - A description on how to use and modify libpng - - libpng version 1.5.13 - September 27, 2012 - Updated and distributed by Glenn Randers-Pehrson - - Copyright (c) 1998-2012 Glenn Randers-Pehrson - - This document is released under the libpng license. - For conditions of distribution and use, see the disclaimer - and license in png.h - - Based on: - - libpng versions 0.97, January 1998, through 1.5.13 - September 27, 2012 - Updated and distributed by Glenn Randers-Pehrson - Copyright (c) 1998-2012 Glenn Randers-Pehrson - - libpng 1.0 beta 6 version 0.96 May 28, 1997 - Updated and distributed by Andreas Dilger - Copyright (c) 1996, 1997 Andreas Dilger - - libpng 1.0 beta 2 - version 0.88 January 26, 1996 - For conditions of distribution and use, see copyright - notice in png.h. Copyright (c) 1995, 1996 Guy Eric - Schalnat, Group 42, Inc. - - Updated/rewritten per request in the libpng FAQ - Copyright (c) 1995, 1996 Frank J. T. Wojcik - December 18, 1995 & January 20, 1996 - -.SH I. Introduction - -This file describes how to use and modify the PNG reference library -(known as libpng) for your own use. There are five sections to this -file: introduction, structures, reading, writing, and modification and -configuration notes for various special platforms. In addition to this -file, example.c is a good starting point for using the library, as -it is heavily commented and should include everything most people -will need. We assume that libpng is already installed; see the -INSTALL file for instructions on how to install libpng. - -For examples of libpng usage, see the files "example.c", "pngtest.c", -and the files in the "contrib" directory, all of which are included in -the libpng distribution. - -Libpng was written as a companion to the PNG specification, as a way -of reducing the amount of time and effort it takes to support the PNG -file format in application programs. - -The PNG specification (second edition), November 2003, is available as -a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at -. It is technically equivalent -to the PNG specification (second edition) but has some additional material. - -The PNG-1.0 specification is available -as RFC 2083 and as a -W3C Recommendation . - -Some additional chunks are described in the special-purpose public chunks -documents at . - -Other information -about PNG, and the latest version of libpng, can be found at the PNG home -page, . - -Most users will not have to modify the library significantly; advanced -users may want to modify it more. All attempts were made to make it as -complete as possible, while keeping the code easy to understand. -Currently, this library only supports C. Support for other languages -is being considered. - -Libpng has been designed to handle multiple sessions at one time, -to be easily modifiable, to be portable to the vast majority of -machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy -to use. The ultimate goal of libpng is to promote the acceptance of -the PNG file format in whatever way possible. While there is still -work to be done (see the TODO file), libpng should cover the -majority of the needs of its users. - -Libpng uses zlib for its compression and decompression of PNG files. -Further information about zlib, and the latest version of zlib, can -be found at the zlib home page, . -The zlib compression utility is a general purpose utility that is -useful for more than PNG files, and can be used without libpng. -See the documentation delivered with zlib for more details. -You can usually find the source files for the zlib utility wherever you -find the libpng source files. - -Libpng is thread safe, provided the threads are using different -instances of the structures. Each thread should have its own -png_struct and png_info instances, and thus its own image. -Libpng does not protect itself against two threads using the -same instance of a structure. - -.SH II. Structures - -There are two main structures that are important to libpng, png_struct -and png_info. Both are internal structures that are no longer exposed -in the libpng interface (as of libpng 1.5.0). - -The png_info structure is designed to provide information about the -PNG file. At one time, the fields of png_info were intended to be -directly accessible to the user. However, this tended to cause problems -with applications using dynamically loaded libraries, and as a result -a set of interface functions for png_info (the png_get_*() and png_set_*() -functions) was developed, and direct access to the png_info fields was -deprecated.. - -The png_struct structure is the object used by the library to decode a -single image. As of 1.5.0 this structure is also not exposed. - -Almost all libpng APIs require a pointer to a png_struct as the first argument. -Many (in particular the png_set and png_get APIs) also require a pointer -to png_info as the second argument. Some application visible macros -defined in png.h designed for basic data access (reading and writing -integers in the PNG format) don't take a png_info pointer, but it's almost -always safe to assume that a (png_struct*) has to be passed to call an API -function. - -You can have more than one png_info structure associated with an image, -as illustrated in pngtest.c, one for information valid prior to the -IDAT chunks and another (called "end_info" below) for things after them. - -The png.h header file is an invaluable reference for programming with libpng. -And while I'm on the topic, make sure you include the libpng header file: - -#include - -and also (as of libpng-1.5.0) the zlib header file, if you need it: - -#include - -.SS Types - -The png.h header file defines a number of integral types used by the -APIs. Most of these are fairly obvious; for example types corresponding -to integers of particular sizes and types for passing color values. - -One exception is how non-integral numbers are handled. For application -convenience most APIs that take such numbers have C (double) arguments; -however, internally PNG, and libpng, use 32 bit signed integers and encode -the value by multiplying by 100,000. As of libpng 1.5.0 a convenience -macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point) -which is simply (png_int_32). - -All APIs that take (double) arguments also have a matching API that -takes the corresponding fixed point integer arguments. The fixed point -API has the same name as the floating point one with "_fixed" appended. -The actual range of values permitted in the APIs is frequently less than -the full range of (png_fixed_point) (-21474 to +21474). When APIs require -a non-negative argument the type is recorded as png_uint_32 above. Consult -the header file and the text below for more information. - -Special care must be take with sCAL chunk handling because the chunk itself -uses non-integral values encoded as strings containing decimal floating point -numbers. See the comments in the header file. - -.SS Configuration - -The main header file function declarations are frequently protected by C -preprocessing directives of the form: - - #ifdef PNG_feature_SUPPORTED - declare-function - #endif - ... - #ifdef PNG_feature_SUPPORTED - use-function - #endif - -The library can be built without support for these APIs, although a -standard build will have all implemented APIs. Application programs -should check the feature macros before using an API for maximum -portability. From libpng 1.5.0 the feature macros set during the build -of libpng are recorded in the header file "pnglibconf.h" and this file -is always included by png.h. - -If you don't need to change the library configuration from the default, skip to -the next section ("Reading"). - -Notice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all -of the build project files in the 'projects' directory simply copy -scripts/pnglibconf.h.prebuilt to pnglibconf.h. This means that these build -systems do not permit easy auto-configuration of the library - they only -support the default configuration. - -The easiest way to make minor changes to the libpng configuration when -auto-configuration is supported is to add definitions to the command line -using (typically) CPPFLAGS. For example: - -CPPFLAGS=-DPNG_NO_FLOATING_ARITHMETIC - -will change the internal libpng math implementation for gamma correction and -other arithmetic calculations to fixed point, avoiding the need for fast -floating point support. The result can be seen in the generated pnglibconf.h - -make sure it contains the changed feature macro setting. - -If you need to make more extensive configuration changes - more than one or two -feature macro settings - you can either add -DPNG_USER_CONFIG to the build -command line and put a list of feature macro settings in pngusr.h or you can set -DFA_XTRA (a makefile variable) to a file containing the same information in the -form of 'option' settings. - -A. Changing pnglibconf.h - -A variety of methods exist to build libpng. Not all of these support -reconfiguration of pnglibconf.h. To reconfigure pnglibconf.h it must either be -rebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand. - -Hand editing is achieved by copying scripts/pnglibconf.h.prebuilt to -pnglibconf.h and changing the lines defining the supported features, paying -very close attention to the 'option' information in scripts/pnglibconf.dfa -that describes those features and their requirements. This is easy to get -wrong. - -B. Configuration using DFA_XTRA - -Rebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later -variant such as 'nawk' or 'gawk', is available. The configure build will -automatically find an appropriate awk and build pnglibconf.h. -The scripts/pnglibconf.mak file contains a set of make rules for doing the -same thing if configure is not used, and many of the makefiles in the scripts -directory use this approach. - -When rebuilding simply write a new file containing changed options and set -DFA_XTRA to the name of this file. This causes the build to append the new file -to the end of scripts/pnglibconf.dfa. The pngusr.dfa file should contain lines -of the following forms: - -everything = off - -This turns all optional features off. Include it at the start of pngusr.dfa to -make it easier to build a minimal configuration. You will need to turn at least -some features on afterward to enable either reading or writing code, or both. - -option feature on -option feature off - -Enable or disable a single feature. This will automatically enable other -features required by a feature that is turned on or disable other features that -require a feature which is turned off. Conflicting settings will cause an error -message to be emitted by awk. - -setting feature default value - -Changes the default value of setting 'feature' to 'value'. There are a small -number of settings listed at the top of pnglibconf.h, they are documented in the -source code. Most of these values have performance implications for the library -but most of them have no visible effect on the API. Some can also be overridden -from the API. - -This method of building a customized pnglibconf.h is illustrated in -contrib/pngminim/*. See the "$(PNGCONF):" target in the makefile and -pngusr.dfa in these directories. - -C. Configuration using PNG_USR_CONFIG - -If -DPNG_USR_CONFIG is added to the CFLAGS when pnglibconf.h is built the file -pngusr.h will automatically be included before the options in -scripts/pnglibconf.dfa are processed. Your pngusr.h file should contain only -macro definitions turning features on or off or setting settings. - -Apart from the global setting "everything = off" all the options listed above -can be set using macros in pngusr.h: - -#define PNG_feature_SUPPORTED - -is equivalent to: - -option feature on - -#define PNG_NO_feature - -is equivalent to: - -option feature off - -#define PNG_feature value - -is equivalent to: - -setting feature default value - -Notice that in both cases, pngusr.dfa and pngusr.h, the contents of the -pngusr file you supply override the contents of scripts/pnglibconf.dfa - -If confusing or incomprehensible behavior results it is possible to -examine the intermediate file pnglibconf.dfn to find the full set of -dependency information for each setting and option. Simply locate the -feature in the file and read the C comments that precede it. - -This method is also illustrated in the contrib/pngminim/* makefiles and -pngusr.h. - -.SH III. Reading - -We'll now walk you through the possible functions to call when reading -in a PNG file sequentially, briefly explaining the syntax and purpose -of each one. See example.c and png.h for more detail. While -progressive reading is covered in the next section, you will still -need some of the functions discussed in this section to read a PNG -file. - -.SS Setup - -You will want to do the I/O initialization(*) before you get into libpng, -so if it doesn't work, you don't have much to undo. Of course, you -will also want to insure that you are, in fact, dealing with a PNG -file. Libpng provides a simple check to see if a file is a PNG file. -To use it, pass in the first 1 to 8 bytes of the file to the function -png_sig_cmp(), and it will return 0 (false) if the bytes match the -corresponding bytes of the PNG signature, or nonzero (true) otherwise. -Of course, the more bytes you pass in, the greater the accuracy of the -prediction. - -If you are intending to keep the file pointer open for use in libpng, -you must ensure you don't read more than 8 bytes from the beginning -of the file, and you also have to make a call to png_set_sig_bytes_read() -with the number of bytes you read from the beginning. Libpng will -then only check the bytes (if any) that your program didn't read. - -(*): If you are not using the standard I/O functions, you will need -to replace them with custom functions. See the discussion under -Customizing libpng. - - - FILE *fp = fopen(file_name, "rb"); - if (!fp) - { - return (ERROR); - } - - fread(header, 1, number, fp); - is_png = !png_sig_cmp(header, 0, number); - - if (!is_png) - { - return (NOT_PNG); - } - - -Next, png_struct and png_info need to be allocated and initialized. In -order to ensure that the size of these structures is correct even with a -dynamically linked libpng, there are functions to initialize and -allocate the structures. We also pass the library version, optional -pointers to error handling functions, and a pointer to a data struct for -use by the error functions, if necessary (the pointer and functions can -be NULL if the default error handlers are to be used). See the section -on Changes to Libpng below regarding the old initialization functions. -The structure allocation functions quietly return NULL if they fail to -create the structure, so your application should check for that. - - png_structp png_ptr = png_create_read_struct - (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, - user_error_fn, user_warning_fn); - - if (!png_ptr) - return (ERROR); - - png_infop info_ptr = png_create_info_struct(png_ptr); - - if (!info_ptr) - { - png_destroy_read_struct(&png_ptr, - (png_infopp)NULL, (png_infopp)NULL); - return (ERROR); - } - -If you want to use your own memory allocation routines, -use a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use -png_create_read_struct_2() instead of png_create_read_struct(): - - png_structp png_ptr = png_create_read_struct_2 - (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, - user_error_fn, user_warning_fn, (png_voidp) - user_mem_ptr, user_malloc_fn, user_free_fn); - -The error handling routines passed to png_create_read_struct() -and the memory alloc/free routines passed to png_create_struct_2() -are only necessary if you are not using the libpng supplied error -handling and memory alloc/free functions. - -When libpng encounters an error, it expects to longjmp back -to your routine. Therefore, you will need to call setjmp and pass -your png_jmpbuf(png_ptr). If you read the file from different -routines, you will need to update the longjmp buffer every time you enter -a new routine that will call a png_*() function. - -See your documentation of setjmp/longjmp for your compiler for more -information on setjmp/longjmp. See the discussion on libpng error -handling in the Customizing Libpng section below for more information -on the libpng error handling. If an error occurs, and libpng longjmp's -back to your setjmp, you will want to call png_destroy_read_struct() to -free any memory. - - if (setjmp(png_jmpbuf(png_ptr))) - { - png_destroy_read_struct(&png_ptr, &info_ptr, - &end_info); - fclose(fp); - return (ERROR); - } - -Pass (png_infopp)NULL instead of &end_info if you didn't create -an end_info structure. - -If you would rather avoid the complexity of setjmp/longjmp issues, -you can compile libpng with PNG_NO_SETJMP, in which case -errors will result in a call to PNG_ABORT() which defaults to abort(). - -You can #define PNG_ABORT() to a function that does something -more useful than abort(), as long as your function does not -return. - -Now you need to set up the input code. The default for libpng is to -use the C function fread(). If you use this, you will need to pass a -valid FILE * in the function png_init_io(). Be sure that the file is -opened in binary mode. If you wish to handle reading data in another -way, you need not call the png_init_io() function, but you must then -implement the libpng I/O methods discussed in the Customizing Libpng -section below. - - png_init_io(png_ptr, fp); - -If you had previously opened the file and read any of the signature from -the beginning in order to see if this was a PNG file, you need to let -libpng know that there are some bytes missing from the start of the file. - - png_set_sig_bytes(png_ptr, number); - -You can change the zlib compression buffer size to be used while -reading compressed data with - - png_set_compression_buffer_size(png_ptr, buffer_size); - -where the default size is 8192 bytes. Note that the buffer size -is changed immediately and the buffer is reallocated immediately, -instead of setting a flag to be acted upon later. - -If you want CRC errors to be handled in a different manner than -the default, use - - png_set_crc_action(png_ptr, crit_action, ancil_action); - -The values for png_set_crc_action() say how libpng is to handle CRC errors in -ancillary and critical chunks, and whether to use the data contained -therein. Note that it is impossible to "discard" data in a critical -chunk. - -Choices for (int) crit_action are - PNG_CRC_DEFAULT 0 error/quit - PNG_CRC_ERROR_QUIT 1 error/quit - PNG_CRC_WARN_USE 3 warn/use data - PNG_CRC_QUIET_USE 4 quiet/use data - PNG_CRC_NO_CHANGE 5 use the current value - -Choices for (int) ancil_action are - PNG_CRC_DEFAULT 0 error/quit - PNG_CRC_ERROR_QUIT 1 error/quit - PNG_CRC_WARN_DISCARD 2 warn/discard data - PNG_CRC_WARN_USE 3 warn/use data - PNG_CRC_QUIET_USE 4 quiet/use data - PNG_CRC_NO_CHANGE 5 use the current value - -.SS Setting up callback code - -You can set up a callback function to handle any unknown chunks in the -input stream. You must supply the function - - read_chunk_callback(png_structp png_ptr, - png_unknown_chunkp chunk); - { - /* The unknown chunk structure contains your - chunk data, along with similar data for any other - unknown chunks: */ - - png_byte name[5]; - png_byte *data; - png_size_t size; - - /* Note that libpng has already taken care of - the CRC handling */ - - /* put your code here. Search for your chunk in the - unknown chunk structure, process it, and return one - of the following: */ - - return (-n); /* chunk had an error */ - return (0); /* did not recognize */ - return (n); /* success */ - } - -(You can give your function another name that you like instead of -"read_chunk_callback") - -To inform libpng about your function, use - - png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr, - read_chunk_callback); - -This names not only the callback function, but also a user pointer that -you can retrieve with - - png_get_user_chunk_ptr(png_ptr); - -If you call the png_set_read_user_chunk_fn() function, then all unknown -chunks will be saved when read, in case your callback function will need -one or more of them. This behavior can be changed with the -png_set_keep_unknown_chunks() function, described below. - -At this point, you can set up a callback function that will be -called after each row has been read, which you can use to control -a progress meter or the like. It's demonstrated in pngtest.c. -You must supply a function - - void read_row_callback(png_structp png_ptr, - png_uint_32 row, int pass); - { - /* put your code here */ - } - -(You can give it another name that you like instead of "read_row_callback") - -To inform libpng about your function, use - - png_set_read_status_fn(png_ptr, read_row_callback); - -When this function is called the row has already been completely processed and -the 'row' and 'pass' refer to the next row to be handled. For the -non-interlaced case the row that was just handled is simply one less than the -passed in row number, and pass will always be 0. For the interlaced case the -same applies unless the row value is 0, in which case the row just handled was -the last one from one of the preceding passes. Because interlacing may skip a -pass you cannot be sure that the preceding pass is just 'pass-1', if you really -need to know what the last pass is record (row,pass) from the callback and use -the last recorded value each time. - -As with the user transform you can find the output row using the -PNG_ROW_FROM_PASS_ROW macro. - -.SS Unknown-chunk handling - -Now you get to set the way the library processes unknown chunks in the -input PNG stream. Both known and unknown chunks will be read. Normal -behavior is that known chunks will be parsed into information in -various info_ptr members while unknown chunks will be discarded. This -behavior can be wasteful if your application will never use some known -chunk types. To change this, you can call: - - png_set_keep_unknown_chunks(png_ptr, keep, - chunk_list, num_chunks); - keep - 0: default unknown chunk handling - 1: ignore; do not keep - 2: keep only if safe-to-copy - 3: keep even if unsafe-to-copy - - You can use these definitions: - PNG_HANDLE_CHUNK_AS_DEFAULT 0 - PNG_HANDLE_CHUNK_NEVER 1 - PNG_HANDLE_CHUNK_IF_SAFE 2 - PNG_HANDLE_CHUNK_ALWAYS 3 - - chunk_list - list of chunks affected (a byte string, - five bytes per chunk, NULL or '\0' if - num_chunks is 0) - - num_chunks - number of chunks affected; if 0, all - unknown chunks are affected. If nonzero, - only the chunks in the list are affected - -Unknown chunks declared in this way will be saved as raw data onto a -list of png_unknown_chunk structures. If a chunk that is normally -known to libpng is named in the list, it will be handled as unknown, -according to the "keep" directive. If a chunk is named in successive -instances of png_set_keep_unknown_chunks(), the final instance will -take precedence. The IHDR and IEND chunks should not be named in -chunk_list; if they are, libpng will process them normally anyway. -If you know that your application will never make use of some particular -chunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below. - -Here is an example of the usage of png_set_keep_unknown_chunks(), -where the private "vpAg" chunk will later be processed by a user chunk -callback function: - - png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'}; - - #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) - png_byte unused_chunks[]= - { - 104, 73, 83, 84, (png_byte) '\0', /* hIST */ - 105, 84, 88, 116, (png_byte) '\0', /* iTXt */ - 112, 67, 65, 76, (png_byte) '\0', /* pCAL */ - 115, 67, 65, 76, (png_byte) '\0', /* sCAL */ - 115, 80, 76, 84, (png_byte) '\0', /* sPLT */ - 116, 73, 77, 69, (png_byte) '\0', /* tIME */ - }; - #endif - - ... - - #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) - /* ignore all unknown chunks: */ - png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0); - - /* except for vpAg: */ - png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1); - - /* also ignore unused known chunks: */ - png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks, - (int)sizeof(unused_chunks)/5); - #endif - -.SS User limits - -The PNG specification allows the width and height of an image to be as -large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns. -Since very few applications really need to process such large images, -we have imposed an arbitrary 1-million limit on rows and columns. -Larger images will be rejected immediately with a png_error() call. If -you wish to change this limit, you can use - - png_set_user_limits(png_ptr, width_max, height_max); - -to set your own limits, or use width_max = height_max = 0x7fffffffL -to allow all valid dimensions (libpng may reject some very large images -anyway because of potential buffer overflow conditions). - -You should put this statement after you create the PNG structure and -before calling png_read_info(), png_read_png(), or png_process_data(). - -When writing a PNG datastream, put this statement before calling -png_write_info() or png_write_png(). - -If you need to retrieve the limits that are being applied, use - - width_max = png_get_user_width_max(png_ptr); - height_max = png_get_user_height_max(png_ptr); - -The PNG specification sets no limit on the number of ancillary chunks -allowed in a PNG datastream. You can impose a limit on the total number -of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with - - png_set_chunk_cache_max(png_ptr, user_chunk_cache_max); - -where 0x7fffffffL means unlimited. You can retrieve this limit with - - chunk_cache_max = png_get_chunk_cache_max(png_ptr); - -This limit also applies to the number of buffers that can be allocated -by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks. - -You can also set a limit on the amount of memory that a compressed chunk -other than IDAT can occupy, with - - png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max); - -and you can retrieve the limit with - - chunk_malloc_max = png_get_chunk_malloc_max(png_ptr); - -Any chunks that would cause either of these limits to be exceeded will -be ignored. - -.SS Information about your system - -If you intend to display the PNG or to incorporate it in other image data you -need to tell libpng information about your display or drawing surface so that -libpng can convert the values in the image to match the display. - -From libpng-1.5.4 this information can be set before reading the PNG file -header. In earlier versions png_set_gamma() existed but behaved incorrectly if -called before the PNG file header had been read and png_set_alpha_mode() did not -exist. - -If you need to support versions prior to libpng-1.5.4 test the version number -as illustrated below using "PNG_LIBPNG_VER >= 10504" and follow the procedures -described in the appropriate manual page. - -You give libpng the encoding expected by your system expressed as a 'gamma' -value. You can also specify a default encoding for the PNG file in -case the required information is missing from the file. By default libpng -assumes that the PNG data matches your system, to keep this default call: - - png_set_gamma(png_ptr, screen_gamma, 1/screen_gamma/*file gamma*/); - -or you can use the fixed point equivalent: - - png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma, PNG_FP_1/screen_gamma); - -If you don't know the gamma for your system it is probably 2.2 - a good -approximation to the IEC standard for display systems (sRGB). If images are -too contrasty or washed out you got the value wrong - check your system -documentation! - -Many systems permit the system gamma to be changed via a lookup table in the -display driver, a few systems, including older Macs, change the response by -default. As of 1.5.4 three special values are available to handle common -situations: - - PNG_DEFAULT_sRGB: Indicates that the system conforms to the IEC 61966-2-1 - standard. This matches almost all systems. - PNG_GAMMA_MAC_18: Indicates that the system is an older (pre Mac OS 10.6) - Apple Macintosh system with the default settings. - PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates that the - system expects data with no gamma encoding. - -You would use the linear (unencoded) value if you need to process the pixel -values further because this avoids the need to decode and reencode each -component value whenever arithmetic is performed. A lot of graphics software -uses linear values for this reason, often with higher precision component values -to preserve overall accuracy. - -The second thing you may need to tell libpng about is how your system handles -alpha channel information. Some, but not all, PNG files contain an alpha -channel. To display these files correctly you need to compose the data onto a -suitable background, as described in the PNG specification. - -Libpng only supports composing onto a single color (using png_set_background; -see below). Otherwise you must do the composition yourself and, in this case, -you may need to call png_set_alpha_mode: - - #if PNG_LIBPNG_VER >= 10504 - png_set_alpha_mode(png_ptr, mode, screen_gamma); - #else - png_set_gamma(png_ptr, screen_gamma, 1.0/screen_gamma); - #endif - -The screen_gamma value is the same as the argument to png_set_gamma; however, -how it affects the output depends on the mode. png_set_alpha_mode() sets the -file gamma default to 1/screen_gamma, so normally you don't need to call -png_set_gamma. If you need different defaults call png_set_gamma() before -png_set_alpha_mode() - if you call it after it will override the settings made -by png_set_alpha_mode(). - -The mode is as follows: - - PNG_ALPHA_PNG: The data is encoded according to the PNG specification. Red, -green and blue, or gray, components are gamma encoded color -values and are not premultiplied by the alpha value. The -alpha value is a linear measure of the contribution of the -pixel to the corresponding final output pixel. - -You should normally use this format if you intend to perform -color correction on the color values; most, maybe all, color -correction software has no handling for the alpha channel and, -anyway, the math to handle pre-multiplied component values is -unnecessarily complex. - -Before you do any arithmetic on the component values you need -to remove the gamma encoding and multiply out the alpha -channel. See the PNG specification for more detail. It is -important to note that when an image with an alpha channel is -scaled, linear encoded, pre-multiplied component values must -be used! - -The remaining modes assume you don't need to do any further color correction or -that if you do, your color correction software knows all about alpha (it -probably doesn't!) - - PNG_ALPHA_STANDARD: The data libpng produces -is encoded in the standard way -assumed by most correctly written graphics software. -The gamma encoding will be removed by libpng and the -linear component values will be pre-multiplied by the -alpha channel. - -With this format the final image must be re-encoded to -match the display gamma before the image is displayed. -If your system doesn't do that, yet still seems to -perform arithmetic on the pixels without decoding them, -it is broken - check out the modes below. - -With PNG_ALPHA_STANDARD libpng always produces linear -component values, whatever screen_gamma you supply. The -screen_gamma value is, however, used as a default for -the file gamma if the PNG file has no gamma information. - -If you call png_set_gamma() after png_set_alpha_mode() you -will override the linear encoding. Instead the -pre-multiplied pixel values will be gamma encoded but -the alpha channel will still be linear. This may -actually match the requirements of some broken software, -but it is unlikely. - -While linear 8-bit data is often used it has -insufficient precision for any image with a reasonable -dynamic range. To avoid problems, and if your software -supports it, use png_set_expand_16() to force all -components to 16 bits. - - PNG_ALPHA_OPTIMIZED: This mode is the same -as PNG_ALPHA_STANDARD except that -completely opaque pixels are gamma encoded according to -the screen_gamma value. Pixels with alpha less than 1.0 -will still have linear components. - -Use this format if you have control over your -compositing software and so don't do other arithmetic -(such as scaling) on the data you get from libpng. Your -compositing software can simply copy opaque pixels to -the output but still has linear values for the -non-opaque pixels. - -In normal compositing, where the alpha channel encodes -partial pixel coverage (as opposed to broad area -translucency), the inaccuracies of the 8-bit -representation of non-opaque pixels are irrelevant. - -You can also try this format if your software is broken; -it might look better. - - PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD; -however, all component values, -including the alpha channel are gamma encoded. This is -an appropriate format to try if your software, or more -likely hardware, is totally broken, i.e., if it performs -linear arithmetic directly on gamma encoded values. - -In most cases of broken software or hardware the bug in the final display -manifests as a subtle halo around composited parts of the image. You may not -even perceive this as a halo; the composited part of the image may simply appear -separate from the background, as though it had been cut out of paper and pasted -on afterward. - -If you don't have to deal with bugs in software or hardware, or if you can fix -them, there are three recommended ways of using png_set_alpha_mode(): - - png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG, - screen_gamma); - -You can do color correction on the result (libpng does not currently -support color correction internally). When you handle the alpha channel -you need to undo the gamma encoding and multiply out the alpha. - - png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD, - screen_gamma); - png_set_expand_16(png_ptr); - -If you are using the high level interface, don't call png_set_expand_16(); -instead pass PNG_TRANSFORM_EXPAND_16 to the interface. - -With this mode you can't do color correction, but you can do arithmetic, -including composition and scaling, on the data without further processing. - - png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED, - screen_gamma); - -You can avoid the expansion to 16-bit components with this mode, but you -lose the ability to scale the image or perform other linear arithmetic. -All you can do is compose the result onto a matching output. Since this -mode is libpng-specific you also need to write your own composition -software. - -If you don't need, or can't handle, the alpha channel you can call -png_set_background() to remove it by compositing against a fixed color. Don't -call png_set_strip_alpha() to do this - it will leave spurious pixel values in -transparent parts of this image. - - png_set_background(png_ptr, &background_color, - PNG_BACKGROUND_GAMMA_SCREEN, 0, 1); - -The background_color is an RGB or grayscale value according to the data format -libpng will produce for you. Because you don't yet know the format of the PNG -file, if you call png_set_background at this point you must arrange for the -format produced by libpng to always have 8-bit or 16-bit components and then -store the color as an 8-bit or 16-bit color as appropriate. The color contains -separate gray and RGB component values, so you can let libpng produce gray or -RGB output according to the input format, but low bit depth grayscale images -must always be converted to at least 8-bit format. (Even though low bit depth -grayscale images can't have an alpha channel they can have a transparent -color!) - -You set the transforms you need later, either as flags to the high level -interface or libpng API calls for the low level interface. For reference the -settings and API calls required are: - -8-bit values: - PNG_TRANSFORM_SCALE_16 | PNG_EXPAND - png_set_expand(png_ptr); png_set_scale_16(png_ptr); - - If you must get exactly the same inaccurate results - produced by default in versions prior to libpng-1.5.4, - use PNG_TRANSFORM_STRIP_16 and png_set_strip_16(png_ptr) - instead. - -16-bit values: - PNG_TRANSFORM_EXPAND_16 - png_set_expand_16(png_ptr); - -In either case palette image data will be expanded to RGB. If you just want -color data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr) -to the list. - -Calling png_set_background before the PNG file header is read will not work -prior to libpng-1.5.4. Because the failure may result in unexpected warnings or -errors it is therefore much safer to call png_set_background after the head has -been read. Unfortunately this means that prior to libpng-1.5.4 it cannot be -used with the high level interface. - -.SS The high-level read interface - -At this point there are two ways to proceed; through the high-level -read interface, or through a sequence of low-level read operations. -You can use the high-level interface if (a) you are willing to read -the entire image into memory, and (b) the input transformations -you want to do are limited to the following set: - - PNG_TRANSFORM_IDENTITY No transformation - PNG_TRANSFORM_SCALE_16 Strip 16-bit samples to - 8-bit accurately - PNG_TRANSFORM_STRIP_16 Chop 16-bit samples to - 8-bit less accurately - PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel - PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit - samples to bytes - PNG_TRANSFORM_PACKSWAP Change order of packed - pixels to LSB first - PNG_TRANSFORM_EXPAND Perform set_expand() - PNG_TRANSFORM_INVERT_MONO Invert monochrome images - PNG_TRANSFORM_SHIFT Normalize pixels to the - sBIT depth - PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA - to BGRA - PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA - to AG - PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity - to transparency - PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples - PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples - to RGB (or GA to RGBA) - PNG_TRANSFORM_EXPAND_16 Expand samples to 16 bits - -(This excludes setting a background color, doing gamma transformation, -quantizing, and setting filler.) If this is the case, simply do this: - - png_read_png(png_ptr, info_ptr, png_transforms, NULL) - -where png_transforms is an integer containing the bitwise OR of some -set of transformation flags. This call is equivalent to png_read_info(), -followed the set of transformations indicated by the transform mask, -then png_read_image(), and finally png_read_end(). - -(The final parameter of this call is not yet used. Someday it might point -to transformation parameters required by some future input transform.) - -You must use png_transforms and not call any png_set_transform() functions -when you use png_read_png(). - -After you have called png_read_png(), you can retrieve the image data -with - - row_pointers = png_get_rows(png_ptr, info_ptr); - -where row_pointers is an array of pointers to the pixel data for each row: - - png_bytep row_pointers[height]; - -If you know your image size and pixel size ahead of time, you can allocate -row_pointers prior to calling png_read_png() with - - if (height > PNG_UINT_32_MAX/png_sizeof(png_byte)) - png_error (png_ptr, - "Image is too tall to process in memory"); - - if (width > PNG_UINT_32_MAX/pixel_size) - png_error (png_ptr, - "Image is too wide to process in memory"); - - row_pointers = png_malloc(png_ptr, - height*png_sizeof(png_bytep)); - - for (int i=0; i) and -png_get_(png_ptr, info_ptr, ...) functions return non-zero if the -data has been read, or zero if it is missing. The parameters to the -png_get_ are set directly if they are simple data types, or a -pointer into the info_ptr is returned for any complex types. - -The colorspace data from gAMA, cHRM, sRGB, iCCP, and sBIT chunks -is simply returned to give the application information about how the -image was encoded. Libpng itself only does transformations using the file -gamma when combining semitransparent pixels with the background color. - - png_get_PLTE(png_ptr, info_ptr, &palette, - &num_palette); - - palette - the palette for the file - (array of png_color) - - num_palette - number of entries in the palette - - png_get_gAMA(png_ptr, info_ptr, &file_gamma); - png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma); - - file_gamma - the gamma at which the file was - written (PNG_INFO_gAMA) - - int_file_gamma - 100,000 times the gamma at which the - file is written - - png_get_cHRM(png_ptr, info_ptr, &white_x, &white_y, &red_x, - &red_y, &green_x, &green_y, &blue_x, &blue_y) - png_get_cHRM_XYZ(png_ptr, info_ptr, &red_X, &red_Y, &red_Z, &green_X, - &green_Y, &green_Z, &blue_X, &blue_Y, &blue_Z) - png_get_cHRM_fixed(png_ptr, info_ptr, &int_white_x, &int_white_y, - &int_red_x, &int_red_y, &int_green_x, &int_green_y, - &int_blue_x, &int_blue_y) - png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &int_red_X, &int_red_Y, - &int_red_Z, &int_green_X, &int_green_Y, &int_green_Z, - &int_blue_X, &int_blue_Y, &int_blue_Z) - - {white,red,green,blue}_{x,y} - A color space encoding specified using the - chromaticities of the end points and the - white point. (PNG_INFO_cHRM) - - {red,green,blue}_{X,Y,Z} - A color space encoding specified using the encoding end - points - the CIE tristimulus specification of the intended - color of the red, green and blue channels in the PNG RGB - data. The white point is simply the sum of the three end - points. (PNG_INFO_cHRM) - - png_get_sRGB(png_ptr, info_ptr, &srgb_intent); - - file_srgb_intent - the rendering intent (PNG_INFO_sRGB) - The presence of the sRGB chunk - means that the pixel data is in the - sRGB color space. This chunk also - implies specific values of gAMA and - cHRM. - - png_get_iCCP(png_ptr, info_ptr, &name, - &compression_type, &profile, &proflen); - - name - The profile name. - - compression_type - The compression type; always - PNG_COMPRESSION_TYPE_BASE for PNG 1.0. - You may give NULL to this argument to - ignore it. - - profile - International Color Consortium color - profile data. May contain NULs. - - proflen - length of profile data in bytes. - - png_get_sBIT(png_ptr, info_ptr, &sig_bit); - - sig_bit - the number of significant bits for - (PNG_INFO_sBIT) each of the gray, - red, green, and blue channels, - whichever are appropriate for the - given color type (png_color_16) - - png_get_tRNS(png_ptr, info_ptr, &trans_alpha, - &num_trans, &trans_color); - - trans_alpha - array of alpha (transparency) - entries for palette (PNG_INFO_tRNS) - - num_trans - number of transparent entries - (PNG_INFO_tRNS) - - trans_color - graylevel or color sample values of - the single transparent color for - non-paletted images (PNG_INFO_tRNS) - - png_get_hIST(png_ptr, info_ptr, &hist); - (PNG_INFO_hIST) - - hist - histogram of palette (array of - png_uint_16) - - png_get_tIME(png_ptr, info_ptr, &mod_time); - - mod_time - time image was last modified - (PNG_VALID_tIME) - - png_get_bKGD(png_ptr, info_ptr, &background); - - background - background color (of type - png_color_16p) (PNG_VALID_bKGD) - valid 16-bit red, green and blue - values, regardless of color_type - - num_comments = png_get_text(png_ptr, info_ptr, - &text_ptr, &num_text); - - num_comments - number of comments - - text_ptr - array of png_text holding image - comments - - text_ptr[i].compression - type of compression used - on "text" PNG_TEXT_COMPRESSION_NONE - PNG_TEXT_COMPRESSION_zTXt - PNG_ITXT_COMPRESSION_NONE - PNG_ITXT_COMPRESSION_zTXt - - text_ptr[i].key - keyword for comment. Must contain - 1-79 characters. - - text_ptr[i].text - text comments for current - keyword. Can be empty. - - text_ptr[i].text_length - length of text string, - after decompression, 0 for iTXt - - text_ptr[i].itxt_length - length of itxt string, - after decompression, 0 for tEXt/zTXt - - text_ptr[i].lang - language of comment (empty - string for unknown). - - text_ptr[i].lang_key - keyword in UTF-8 - (empty string for unknown). - - Note that the itxt_length, lang, and lang_key - members of the text_ptr structure only exist when the - library is built with iTXt chunk support. Prior to - libpng-1.4.0 the library was built by default without - iTXt support. Also note that when iTXt is supported, - they contain NULL pointers when the "compression" - field contains PNG_TEXT_COMPRESSION_NONE or - PNG_TEXT_COMPRESSION_zTXt. - - num_text - number of comments (same as - num_comments; you can put NULL here - to avoid the duplication) - - Note while png_set_text() will accept text, language, - and translated keywords that can be NULL pointers, the - structure returned by png_get_text will always contain - regular zero-terminated C strings. They might be - empty strings but they will never be NULL pointers. - - num_spalettes = png_get_sPLT(png_ptr, info_ptr, - &palette_ptr); - - num_spalettes - number of sPLT chunks read. - - palette_ptr - array of palette structures holding - contents of one or more sPLT chunks - read. - - png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y, - &unit_type); - - offset_x - positive offset from the left edge - of the screen (can be negative) - - offset_y - positive offset from the top edge - of the screen (can be negative) - - unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER - - png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, - &unit_type); - - res_x - pixels/unit physical resolution in - x direction - - res_y - pixels/unit physical resolution in - x direction - - unit_type - PNG_RESOLUTION_UNKNOWN, - PNG_RESOLUTION_METER - - png_get_sCAL(png_ptr, info_ptr, &unit, &width, - &height) - - unit - physical scale units (an integer) - - width - width of a pixel in physical scale units - - height - height of a pixel in physical scale units - (width and height are doubles) - - png_get_sCAL_s(png_ptr, info_ptr, &unit, &width, - &height) - - unit - physical scale units (an integer) - - width - width of a pixel in physical scale units - (expressed as a string) - - height - height of a pixel in physical scale units - (width and height are strings like "2.54") - - num_unknown_chunks = png_get_unknown_chunks(png_ptr, - info_ptr, &unknowns) - - unknowns - array of png_unknown_chunk - structures holding unknown chunks - - unknowns[i].name - name of unknown chunk - - unknowns[i].data - data of unknown chunk - - unknowns[i].size - size of unknown chunk's data - - unknowns[i].location - position of chunk in file - - The value of "i" corresponds to the order in which the - chunks were read from the PNG file or inserted with the - png_set_unknown_chunks() function. - - The value of "location" is a bitwise "or" of - - PNG_HAVE_IHDR (0x01) - PNG_HAVE_PLTE (0x02) - PNG_AFTER_IDAT (0x08) - -The data from the pHYs chunk can be retrieved in several convenient -forms: - - res_x = png_get_x_pixels_per_meter(png_ptr, - info_ptr) - - res_y = png_get_y_pixels_per_meter(png_ptr, - info_ptr) - - res_x_and_y = png_get_pixels_per_meter(png_ptr, - info_ptr) - - res_x = png_get_x_pixels_per_inch(png_ptr, - info_ptr) - - res_y = png_get_y_pixels_per_inch(png_ptr, - info_ptr) - - res_x_and_y = png_get_pixels_per_inch(png_ptr, - info_ptr) - - aspect_ratio = png_get_pixel_aspect_ratio(png_ptr, - info_ptr) - - Each of these returns 0 [signifying "unknown"] if - the data is not present or if res_x is 0; - res_x_and_y is 0 if res_x != res_y - - Note that because of the way the resolutions are - stored internally, the inch conversions won't - come out to exactly even number. For example, - 72 dpi is stored as 0.28346 pixels/meter, and - when this is retrieved it is 71.9988 dpi, so - be sure to round the returned value appropriately - if you want to display a reasonable-looking result. - -The data from the oFFs chunk can be retrieved in several convenient -forms: - - x_offset = png_get_x_offset_microns(png_ptr, info_ptr); - - y_offset = png_get_y_offset_microns(png_ptr, info_ptr); - - x_offset = png_get_x_offset_inches(png_ptr, info_ptr); - - y_offset = png_get_y_offset_inches(png_ptr, info_ptr); - - Each of these returns 0 [signifying "unknown" if both - x and y are 0] if the data is not present or if the - chunk is present but the unit is the pixel. The - remark about inexact inch conversions applies here - as well, because a value in inches can't always be - converted to microns and back without some loss - of precision. - -For more information, see the -PNG specification for chunk contents. Be careful with trusting -rowbytes, as some of the transformations could increase the space -needed to hold a row (expand, filler, gray_to_rgb, etc.). -See png_read_update_info(), below. - -A quick word about text_ptr and num_text. PNG stores comments in -keyword/text pairs, one pair per chunk, with no limit on the number -of text chunks, and a 2^31 byte limit on their size. While there are -suggested keywords, there is no requirement to restrict the use to these -strings. It is strongly suggested that keywords and text be sensible -to humans (that's the point), so don't use abbreviations. Non-printing -symbols are not allowed. See the PNG specification for more details. -There is also no requirement to have text after the keyword. - -Keywords should be limited to 79 Latin-1 characters without leading or -trailing spaces, but non-consecutive spaces are allowed within the -keyword. It is possible to have the same keyword any number of times. -The text_ptr is an array of png_text structures, each holding a -pointer to a language string, a pointer to a keyword and a pointer to -a text string. The text string, language code, and translated -keyword may be empty or NULL pointers. The keyword/text -pairs are put into the array in the order that they are received. -However, some or all of the text chunks may be after the image, so, to -make sure you have read all the text chunks, don't mess with these -until after you read the stuff after the image. This will be -mentioned again below in the discussion that goes with png_read_end(). - -.SS Input transformations - -After you've read the header information, you can set up the library -to handle any special transformations of the image data. The various -ways to transform the data will be described in the order that they -should occur. This is important, as some of these change the color -type and/or bit depth of the data, and some others only work on -certain color types and bit depths. - -Transformations you request are ignored if they don't have any meaning for a -particular input data format. However some transformations can have an effect -as a result of a previous transformation. If you specify a contradictory set of -transformations, for example both adding and removing the alpha channel, you -cannot predict the final result. - -The color used for the transparency values should be supplied in the same -format/depth as the current image data. It is stored in the same format/depth -as the image data in a tRNS chunk, so this is what libpng expects for this data. - -The color used for the background value depends on the need_expand argument as -described below. - -Data will be decoded into the supplied row buffers packed into bytes -unless the library has been told to transform it into another format. -For example, 4 bit/pixel paletted or grayscale data will be returned -2 pixels/byte with the leftmost pixel in the high-order bits of the -byte, unless png_set_packing() is called. 8-bit RGB data will be stored -in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha() -is called to insert filler bytes, either before or after each RGB triplet. -16-bit RGB data will be returned RRGGBB RRGGBB, with the most significant -byte of the color value first, unless png_set_scale_16() is called to -transform it to regular RGB RGB triplets, or png_set_filler() or -png_set_add alpha() is called to insert filler bytes, either before or -after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can -be modified with png_set_filler(), png_set_add_alpha(), png_set_strip_16(), -or png_set_scale_16(). - -The following code transforms grayscale images of less than 8 to 8 bits, -changes paletted images to RGB, and adds a full alpha channel if there is -transparency information in a tRNS chunk. This is most useful on -grayscale images with bit depths of 2 or 4 or if there is a multiple-image -viewing application that wishes to treat all images in the same way. - - if (color_type == PNG_COLOR_TYPE_PALETTE) - png_set_palette_to_rgb(png_ptr); - - if (png_get_valid(png_ptr, info_ptr, - PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr); - - if (color_type == PNG_COLOR_TYPE_GRAY && - bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr); - -The first two functions are actually aliases for png_set_expand(), added -in libpng version 1.0.4, with the function names expanded to improve code -readability. In some future version they may actually do different -things. - -As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was -added. It expands the sample depth without changing tRNS to alpha. - -As of libpng version 1.5.2, png_set_expand_16() was added. It behaves as -png_set_expand(); however, the resultant channels have 16 bits rather than 8. -Use this when the output color or gray channels are made linear to avoid fairly -severe accuracy loss. - - if (bit_depth < 16) - png_set_expand_16(png_ptr); - -PNG can have files with 16 bits per channel. If you only can handle -8 bits per channel, this will strip the pixels down to 8-bit. - - if (bit_depth == 16) -#if PNG_LIBPNG_VER >= 10504 - png_set_scale_16(png_ptr); -#else - png_set_strip_16(png_ptr); -#endif - -(The more accurate "png_set_scale_16()" API became available in libpng version -1.5.4). - -If you need to process the alpha channel on the image separately from the image -data (for example if you convert it to a bitmap mask) it is possible to have -libpng strip the channel leaving just RGB or gray data: - - if (color_type & PNG_COLOR_MASK_ALPHA) - png_set_strip_alpha(png_ptr); - -If you strip the alpha channel you need to find some other way of dealing with -the information. If, instead, you want to convert the image to an opaque -version with no alpha channel use png_set_background; see below. - -As of libpng version 1.5.2, almost all useful expansions are supported, the -major ommissions are conversion of grayscale to indexed images (which can be -done trivially in the application) and conversion of indexed to grayscale (which -can be done by a trivial manipulation of the palette.) - -In the following table, the 01 means grayscale with depth<8, 31 means -indexed with depth<8, other numerals represent the color type, "T" means -the tRNS chunk is present, A means an alpha channel is present, and O -means tRNS or alpha is present but all pixels in the image are opaque. - - FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O - TO - 01 - [G] - - - - - - - - - - - - - - 31 [Q] Q [Q] [Q] [Q] Q Q Q Q Q Q [Q] [Q] Q Q - 0 1 G + . . G G G G G G B B GB GB - 0T lt Gt t + . Gt G G Gt G G Bt Bt GBt GBt - 0O lt Gt t . + Gt Gt G Gt Gt G Bt Bt GBt GBt - 2 C P C C C + . . C - - CB CB B B - 2T Ct - Ct C C t + t - - - CBt CBt Bt Bt - 2O Ct - Ct C C t t + - - - CBt CBt Bt Bt - 3 [Q] p [Q] [Q] [Q] Q Q Q + . . [Q] [Q] Q Q - 3T [Qt] p [Qt][Q] [Q] Qt Qt Qt t + t [Qt][Qt] Qt Qt - 3O [Qt] p [Qt][Q] [Q] Qt Qt Qt t t + [Qt][Qt] Qt Qt - 4A lA G A T T GA GT GT GA GT GT + BA G GBA - 4O lA GBA A T T GA GT GT GA GT GT BA + GBA G - 6A CA PA CA C C A T tT PA P P C CBA + BA - 6O CA PBA CA C C A tT T PA P P CBA C BA + - -Within the matrix, - "+" identifies entries where 'from' and 'to' are the same. - "-" means the transformation is not supported. - "." means nothing is necessary (a tRNS chunk can just be ignored). - "t" means the transformation is obtained by png_set_tRNS. - "A" means the transformation is obtained by png_set_add_alpha(). - "X" means the transformation is obtained by png_set_expand(). - "1" means the transformation is obtained by - png_set_expand_gray_1_2_4_to_8() (and by png_set_expand() - if there is no transparency in the original or the final - format). - "C" means the transformation is obtained by png_set_gray_to_rgb(). - "G" means the transformation is obtained by png_set_rgb_to_gray(). - "P" means the transformation is obtained by - png_set_expand_palette_to_rgb(). - "p" means the transformation is obtained by png_set_packing(). - "Q" means the transformation is obtained by png_set_quantize(). - "T" means the transformation is obtained by - png_set_tRNS_to_alpha(). - "B" means the transformation is obtained by - png_set_background(), or png_strip_alpha(). - -When an entry has multiple transforms listed all are required to cause the -right overall transformation. When two transforms are separated by a comma -either will do the job. When transforms are enclosed in [] the transform should -do the job but this is currently unimplemented - a different format will result -if the suggested transformations are used. - -In PNG files, the alpha channel in an image -is the level of opacity. If you need the alpha channel in an image to -be the level of transparency instead of opacity, you can invert the -alpha channel (or the tRNS chunk data) after it's read, so that 0 is -fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit -images) is fully transparent, with - - png_set_invert_alpha(png_ptr); - -PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as -they can, resulting in, for example, 8 pixels per byte for 1 bit -files. This code expands to 1 pixel per byte without changing the -values of the pixels: - - if (bit_depth < 8) - png_set_packing(png_ptr); - -PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels -stored in a PNG image have been "scaled" or "shifted" up to the next -higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] -to 8 bits/sample in the range [0, 255]). However, it is also possible -to convert the PNG pixel data back to the original bit depth of the -image. This call reduces the pixels back down to the original bit depth: - - png_color_8p sig_bit; - - if (png_get_sBIT(png_ptr, info_ptr, &sig_bit)) - png_set_shift(png_ptr, sig_bit); - -PNG files store 3-color pixels in red, green, blue order. This code -changes the storage of the pixels to blue, green, red: - - if (color_type == PNG_COLOR_TYPE_RGB || - color_type == PNG_COLOR_TYPE_RGB_ALPHA) - png_set_bgr(png_ptr); - -PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them -into 4 or 8 bytes for windowing systems that need them in this format: - - if (color_type == PNG_COLOR_TYPE_RGB) - png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE); - -where "filler" is the 8 or 16-bit number to fill with, and the location is -either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether -you want the filler before the RGB or after. This transformation -does not affect images that already have full alpha channels. To add an -opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which -will generate RGBA pixels. - -Note that png_set_filler() does not change the color type. If you want -to do that, you can add a true alpha channel with - - if (color_type == PNG_COLOR_TYPE_RGB || - color_type == PNG_COLOR_TYPE_GRAY) - png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER); - -where "filler" contains the alpha value to assign to each pixel. -This function was added in libpng-1.2.7. - -If you are reading an image with an alpha channel, and you need the -data as ARGB instead of the normal PNG format RGBA: - - if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) - png_set_swap_alpha(png_ptr); - -For some uses, you may want a grayscale image to be represented as -RGB. This code will do that conversion: - - if (color_type == PNG_COLOR_TYPE_GRAY || - color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - png_set_gray_to_rgb(png_ptr); - -Conversely, you can convert an RGB or RGBA image to grayscale or grayscale -with alpha. - - if (color_type == PNG_COLOR_TYPE_RGB || - color_type == PNG_COLOR_TYPE_RGB_ALPHA) - png_set_rgb_to_gray(png_ptr, error_action, - double red_weight, double green_weight); - - error_action = 1: silently do the conversion - - error_action = 2: issue a warning if the original - image has any pixel where - red != green or red != blue - - error_action = 3: issue an error and abort the - conversion if the original - image has any pixel where - red != green or red != blue - - red_weight: weight of red component - - green_weight: weight of green component - If either weight is negative, default - weights are used. - -In the corresponding fixed point API the red_weight and green_weight values are -simply scaled by 100,000: - - png_set_rgb_to_gray(png_ptr, error_action, - png_fixed_point red_weight, - png_fixed_point green_weight); - -If you have set error_action = 1 or 2, you can -later check whether the image really was gray, after processing -the image rows, with the png_get_rgb_to_gray_status(png_ptr) function. -It will return a png_byte that is zero if the image was gray or -1 if there were any non-gray pixels. Background and sBIT data -will be silently converted to grayscale, using the green channel -data for sBIT, regardless of the error_action setting. - -The default values come from the PNG file cHRM chunk if present; otherwise, the -defaults correspond to the ITU-R recommendation 709, and also the sRGB color -space, as recommended in the Charles Poynton's Colour FAQ, -, in section 9: - - - - Y = 0.2126 * R + 0.7152 * G + 0.0722 * B - -Previous versions of this document, 1998 through 2002, recommended a slightly -different formula: - - Y = 0.212671 * R + 0.715160 * G + 0.072169 * B - -Libpng uses an integer approximation: - - Y = (6968 * R + 23434 * G + 2366 * B)/32768 - -The calculation is done in a linear colorspace, if the image gamma -can be determined. - -The png_set_background() function has been described already; it tells libpng to -composite images with alpha or simple transparency against the supplied -background color. For compatibility with versions of libpng earlier than -libpng-1.5.4 it is recommended that you call the function after reading the file -header, even if you don't want to use the color in a bKGD chunk, if one exists. - -If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid), -you may use this color, or supply another color more suitable for -the current display (e.g., the background color from a web page). You -need to tell libpng how the color is represented, both the format of the -component values in the color (the number of bits) and the gamma encoding of the -color. The function takes two arguments, background_gamma_mode and need_expand -to convey this information; however, only two combinations are likely to be -useful: - - png_color_16 my_background; - png_color_16p image_background; - - if (png_get_bKGD(png_ptr, info_ptr, &image_background)) - png_set_background(png_ptr, image_background, - PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1); - else - png_set_background(png_ptr, &my_background, - PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1); - -The second call was described above - my_background is in the format of the -final, display, output produced by libpng. Because you now know the format of -the PNG it is possible to avoid the need to choose either 8-bit or 16-bit -output and to retain palette images (the palette colors will be modified -appropriately and the tRNS chunk removed.) However, if you are doing this, -take great care not to ask for transformations without checking first that -they apply! - -In the first call the background color has the original bit depth and color type -of the PNG file. So, for palette images the color is supplied as a palette -index and for low bit greyscale images the color is a reduced bit value in -image_background->gray. - -If you didn't call png_set_gamma() before reading the file header, for example -if you need your code to remain compatible with older versions of libpng prior -to libpng-1.5.4, this is the place to call it. - -Do not call it if you called png_set_alpha_mode(); doing so will damage the -settings put in place by png_set_alpha_mode(). (If png_set_alpha_mode() is -supported then you can certainly do png_set_gamma() before reading the PNG -header.) - -This API unconditionally sets the screen and file gamma values, so it will -override the value in the PNG file unless it is called before the PNG file -reading starts. For this reason you must always call it with the PNG file -value when you call it in this position: - - if (png_get_gAMA(png_ptr, info_ptr, &file_gamma)) - png_set_gamma(png_ptr, screen_gamma, file_gamma); - - else - png_set_gamma(png_ptr, screen_gamma, 0.45455); - -If you need to reduce an RGB file to a paletted file, or if a paletted -file has more entries then will fit on your screen, png_set_quantize() -will do that. Note that this is a simple match quantization that merely -finds the closest color available. This should work fairly well with -optimized palettes, but fairly badly with linear color cubes. If you -pass a palette that is larger than maximum_colors, the file will -reduce the number of colors in the palette so it will fit into -maximum_colors. If there is a histogram, libpng will use it to make -more intelligent choices when reducing the palette. If there is no -histogram, it may not do as good a job. - - if (color_type & PNG_COLOR_MASK_COLOR) - { - if (png_get_valid(png_ptr, info_ptr, - PNG_INFO_PLTE)) - { - png_uint_16p histogram = NULL; - - png_get_hIST(png_ptr, info_ptr, - &histogram); - png_set_quantize(png_ptr, palette, num_palette, - max_screen_colors, histogram, 1); - } - - else - { - png_color std_color_cube[MAX_SCREEN_COLORS] = - { ... colors ... }; - - png_set_quantize(png_ptr, std_color_cube, - MAX_SCREEN_COLORS, MAX_SCREEN_COLORS, - NULL,0); - } - } - -PNG files describe monochrome as black being zero and white being one. -The following code will reverse this (make black be one and white be -zero): - - if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY) - png_set_invert_mono(png_ptr); - -This function can also be used to invert grayscale and gray-alpha images: - - if (color_type == PNG_COLOR_TYPE_GRAY || - color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - png_set_invert_mono(png_ptr); - -PNG files store 16-bit pixels in network byte order (big-endian, -ie. most significant bits first). This code changes the storage to the -other way (little-endian, i.e. least significant bits first, the -way PCs store them): - - if (bit_depth == 16) - png_set_swap(png_ptr); - -If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you -need to change the order the pixels are packed into bytes, you can use: - - if (bit_depth < 8) - png_set_packswap(png_ptr); - -Finally, you can write your own transformation function if none of -the existing ones meets your needs. This is done by setting a callback -with - - png_set_read_user_transform_fn(png_ptr, - read_transform_fn); - -You must supply the function - - void read_transform_fn(png_structp png_ptr, png_row_infop - row_info, png_bytep data) - -See pngtest.c for a working example. Your function will be called -after all of the other transformations have been processed. Take care with -interlaced images if you do the interlace yourself - the width of the row is the -width in 'row_info', not the overall image width. - -If supported, libpng provides two information routines that you can use to find -where you are in processing the image: - - png_get_current_pass_number(png_structp png_ptr); - png_get_current_row_number(png_structp png_ptr); - -Don't try using these outside a transform callback - firstly they are only -supported if user transforms are supported, secondly they may well return -unexpected results unless the row is actually being processed at the moment they -are called. - -With interlaced -images the value returned is the row in the input sub-image image. Use -PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to -find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass). - -The discussion of interlace handling above contains more information on how to -use these values. - -You can also set up a pointer to a user structure for use by your -callback function, and you can inform libpng that your transform -function will change the number of channels or bit depth with the -function - - png_set_user_transform_info(png_ptr, user_ptr, - user_depth, user_channels); - -The user's application, not libpng, is responsible for allocating and -freeing any memory required for the user structure. - -You can retrieve the pointer via the function -png_get_user_transform_ptr(). For example: - - voidp read_user_transform_ptr = - png_get_user_transform_ptr(png_ptr); - -The last thing to handle is interlacing; this is covered in detail below, -but you must call the function here if you want libpng to handle expansion -of the interlaced image. - - number_of_passes = png_set_interlace_handling(png_ptr); - -After setting the transformations, libpng can update your png_info -structure to reflect any transformations you've requested with this -call. - - png_read_update_info(png_ptr, info_ptr); - -This is most useful to update the info structure's rowbytes -field so you can use it to allocate your image memory. This function -will also update your palette with the correct screen_gamma and -background if these have been given with the calls above. You may -only call png_read_update_info() once with a particular info_ptr. - -After you call png_read_update_info(), you can allocate any -memory you need to hold the image. The row data is simply -raw byte data for all forms of images. As the actual allocation -varies among applications, no example will be given. If you -are allocating one large chunk, you will need to build an -array of pointers to each row, as it will be needed for some -of the functions below. - -Remember: Before you call png_read_update_info(), the png_get_*() -functions return the values corresponding to the original PNG image. -After you call png_read_update_info the values refer to the image -that libpng will output. Consequently you must call all the png_set_ -functions before you call png_read_update_info(). This is particularly -important for png_set_interlace_handling() - if you are going to call -png_read_update_info() you must call png_set_interlace_handling() before -it unless you want to receive interlaced output. - -.SS Reading image data - -After you've allocated memory, you can read the image data. -The simplest way to do this is in one function call. If you are -allocating enough memory to hold the whole image, you can just -call png_read_image() and libpng will read in all the image data -and put it in the memory area supplied. You will need to pass in -an array of pointers to each row. - -This function automatically handles interlacing, so you don't -need to call png_set_interlace_handling() (unless you call -png_read_update_info()) or call this function multiple times, or any -of that other stuff necessary with png_read_rows(). - - png_read_image(png_ptr, row_pointers); - -where row_pointers is: - - png_bytep row_pointers[height]; - -You can point to void or char or whatever you use for pixels. - -If you don't want to read in the whole image at once, you can -use png_read_rows() instead. If there is no interlacing (check -interlace_type == PNG_INTERLACE_NONE), this is simple: - - png_read_rows(png_ptr, row_pointers, NULL, - number_of_rows); - -where row_pointers is the same as in the png_read_image() call. - -If you are doing this just one row at a time, you can do this with -a single row_pointer instead of an array of row_pointers: - - png_bytep row_pointer = row; - png_read_row(png_ptr, row_pointer, NULL); - -If the file is interlaced (interlace_type != 0 in the IHDR chunk), things -get somewhat harder. The only current (PNG Specification version 1.2) -interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7); -a somewhat complicated 2D interlace scheme, known as Adam7, that -breaks down an image into seven smaller images of varying size, based -on an 8x8 grid. This number is defined (from libpng 1.5) as -PNG_INTERLACE_ADAM7_PASSES in png.h - -libpng can fill out those images or it can give them to you "as is". -It is almost always better to have libpng handle the interlacing for you. -If you want the images filled out, there are two ways to do that. The one -mentioned in the PNG specification is to expand each pixel to cover -those pixels that have not been read yet (the "rectangle" method). -This results in a blocky image for the first pass, which gradually -smooths out as more pixels are read. The other method is the "sparkle" -method, where pixels are drawn only in their final locations, with the -rest of the image remaining whatever colors they were initialized to -before the start of the read. The first method usually looks better, -but tends to be slower, as there are more pixels to put in the rows. - -If, as is likely, you want libpng to expand the images, call this before -calling png_start_read_image() or png_read_update_info(): - - if (interlace_type == PNG_INTERLACE_ADAM7) - number_of_passes - = png_set_interlace_handling(png_ptr); - -This will return the number of passes needed. Currently, this is seven, -but may change if another interlace type is added. This function can be -called even if the file is not interlaced, where it will return one pass. -You then need to read the whole image 'number_of_passes' times. Each time -will distribute the pixels from the current pass to the correct place in -the output image, so you need to supply the same rows to png_read_rows in -each pass. - -If you are not going to display the image after each pass, but are -going to wait until the entire image is read in, use the sparkle -effect. This effect is faster and the end result of either method -is exactly the same. If you are planning on displaying the image -after each pass, the "rectangle" effect is generally considered the -better looking one. - -If you only want the "sparkle" effect, just call png_read_rows() as -normal, with the third parameter NULL. Make sure you make pass over -the image number_of_passes times, and you don't change the data in the -rows between calls. You can change the locations of the data, just -not the data. Each pass only writes the pixels appropriate for that -pass, and assumes the data from previous passes is still valid. - - png_read_rows(png_ptr, row_pointers, NULL, - number_of_rows); - -If you only want the first effect (the rectangles), do the same as -before except pass the row buffer in the third parameter, and leave -the second parameter NULL. - - png_read_rows(png_ptr, NULL, row_pointers, - number_of_rows); - -If you don't want libpng to handle the interlacing details, just call -png_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images. -Each of the images is a valid image by itself; however, you will almost -certainly need to distribute the pixels from each sub-image to the -correct place. This is where everything gets very tricky. - -If you want to retrieve the separate images you must pass the correct -number of rows to each successive call of png_read_rows(). The calculation -gets pretty complicated for small images, where some sub-images may -not even exist because either their width or height ends up zero. -libpng provides two macros to help you in 1.5 and later versions: - - png_uint_32 width = PNG_PASS_COLS(image_width, pass_number); - png_uint_32 height = PNG_PASS_ROWS(image_height, pass_number); - -Respectively these tell you the width and height of the sub-image -corresponding to the numbered pass. 'pass' is in in the range 0 to 6 - -this can be confusing because the specification refers to the same passes -as 1 to 7! Be careful, you must check both the width and height before -calling png_read_rows() and not call it for that pass if either is zero. - -You can, of course, read each sub-image row by row. If you want to -produce optimal code to make a pixel-by-pixel transformation of an -interlaced image this is the best approach; read each row of each pass, -transform it, and write it out to a new interlaced image. - -If you want to de-interlace the image yourself libpng provides further -macros to help that tell you where to place the pixels in the output image. -Because the interlacing scheme is rectangular - sub-image pixels are always -arranged on a rectangular grid - all you need to know for each pass is the -starting column and row in the output image of the first pixel plus the -spacing between each pixel. As of libpng 1.5 there are four macros to -retrieve this information: - - png_uint_32 x = PNG_PASS_START_COL(pass); - png_uint_32 y = PNG_PASS_START_ROW(pass); - png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass); - png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass); - -These allow you to write the obvious loop: - - png_uint_32 input_y = 0; - png_uint_32 output_y = PNG_PASS_START_ROW(pass); - - while (output_y < output_image_height) - { - png_uint_32 input_x = 0; - png_uint_32 output_x = PNG_PASS_START_COL(pass); - - while (output_x < output_image_width) - { - image[output_y][output_x] = - subimage[pass][input_y][input_x++]; - - output_x += xStep; - } - - ++input_y; - output_y += yStep; - } - -Notice that the steps between successive output rows and columns are -returned as shifts. This is possible because the pixels in the subimages -are always a power of 2 apart - 1, 2, 4 or 8 pixels - in the original -image. In practice you may need to directly calculate the output coordinate -given an input coordinate. libpng provides two further macros for this -purpose: - - png_uint_32 output_x = PNG_COL_FROM_PASS_COL(input_x, pass); - png_uint_32 output_y = PNG_ROW_FROM_PASS_ROW(input_y, pass); - -Finally a pair of macros are provided to tell you if a particular image -row or column appears in a given pass: - - int col_in_pass = PNG_COL_IN_INTERLACE_PASS(output_x, pass); - int row_in_pass = PNG_ROW_IN_INTERLACE_PASS(output_y, pass); - -Bear in mind that you will probably also need to check the width and height -of the pass in addition to the above to be sure the pass even exists! - -With any luck you are convinced by now that you don't want to do your own -interlace handling. In reality normally the only good reason for doing this -is if you are processing PNG files on a pixel-by-pixel basis and don't want -to load the whole file into memory when it is interlaced. - -libpng includes a test program, pngvalid, that illustrates reading and -writing of interlaced images. If you can't get interlacing to work in your -code and don't want to leave it to libpng (the recommended approach), see -how pngvalid.c does it. - -.SS Finishing a sequential read - -After you are finished reading the image through the -low-level interface, you can finish reading the file. If you are -interested in comments or time, which may be stored either before or -after the image data, you should pass the separate png_info struct if -you want to keep the comments from before and after the image -separate. - - png_infop end_info = png_create_info_struct(png_ptr); - - if (!end_info) - { - png_destroy_read_struct(&png_ptr, &info_ptr, - (png_infopp)NULL); - return (ERROR); - } - - png_read_end(png_ptr, end_info); - -If you are not interested, you should still call png_read_end() -but you can pass NULL, avoiding the need to create an end_info structure. - - png_read_end(png_ptr, (png_infop)NULL); - -If you don't call png_read_end(), then your file pointer will be -left pointing to the first chunk after the last IDAT, which is probably -not what you want if you expect to read something beyond the end of -the PNG datastream. - -When you are done, you can free all memory allocated by libpng like this: - - png_destroy_read_struct(&png_ptr, &info_ptr, - &end_info); - -or, if you didn't create an end_info structure, - - png_destroy_read_struct(&png_ptr, &info_ptr, - (png_infopp)NULL); - -It is also possible to individually free the info_ptr members that -point to libpng-allocated storage with the following function: - - png_free_data(png_ptr, info_ptr, mask, seq) - - mask - identifies data to be freed, a mask - containing the bitwise OR of one or - more of - PNG_FREE_PLTE, PNG_FREE_TRNS, - PNG_FREE_HIST, PNG_FREE_ICCP, - PNG_FREE_PCAL, PNG_FREE_ROWS, - PNG_FREE_SCAL, PNG_FREE_SPLT, - PNG_FREE_TEXT, PNG_FREE_UNKN, - or simply PNG_FREE_ALL - - seq - sequence number of item to be freed - (-1 for all items) - -This function may be safely called when the relevant storage has -already been freed, or has not yet been allocated, or was allocated -by the user and not by libpng, and will in those cases do nothing. -The "seq" parameter is ignored if only one item of the selected data -type, such as PLTE, is allowed. If "seq" is not -1, and multiple items -are allowed for the data type identified in the mask, such as text or -sPLT, only the n'th item in the structure is freed, where n is "seq". - -The default behavior is only to free data that was allocated internally -by libpng. This can be changed, so that libpng will not free the data, -or so that it will free data that was allocated by the user with png_malloc() -or png_calloc() and passed in via a png_set_*() function, with - - png_data_freer(png_ptr, info_ptr, freer, mask) - - freer - one of - PNG_DESTROY_WILL_FREE_DATA - PNG_SET_WILL_FREE_DATA - PNG_USER_WILL_FREE_DATA - - mask - which data elements are affected - same choices as in png_free_data() - -This function only affects data that has already been allocated. -You can call this function after reading the PNG data but before calling -any png_set_*() functions, to control whether the user or the png_set_*() -function is responsible for freeing any existing data that might be present, -and again after the png_set_*() functions to control whether the user -or png_destroy_*() is supposed to free the data. When the user assumes -responsibility for libpng-allocated data, the application must use -png_free() to free it, and when the user transfers responsibility to libpng -for data that the user has allocated, the user must have used png_malloc() -or png_calloc() to allocate it. - -If you allocated your row_pointers in a single block, as suggested above in -the description of the high level read interface, you must not transfer -responsibility for freeing it to the png_set_rows or png_read_destroy function, -because they would also try to free the individual row_pointers[i]. - -If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword -separately, do not transfer responsibility for freeing text_ptr to libpng, -because when libpng fills a png_text structure it combines these members with -the key member, and png_free_data() will free only text_ptr.key. Similarly, -if you transfer responsibility for free'ing text_ptr from libpng to your -application, your application must not separately free those members. - -The png_free_data() function will turn off the "valid" flag for anything -it frees. If you need to turn the flag off for a chunk that was freed by -your application instead of by libpng, you can use - - png_set_invalid(png_ptr, info_ptr, mask); - - mask - identifies the chunks to be made invalid, - containing the bitwise OR of one or - more of - PNG_INFO_gAMA, PNG_INFO_sBIT, - PNG_INFO_cHRM, PNG_INFO_PLTE, - PNG_INFO_tRNS, PNG_INFO_bKGD, - PNG_INFO_hIST, PNG_INFO_pHYs, - PNG_INFO_oFFs, PNG_INFO_tIME, - PNG_INFO_pCAL, PNG_INFO_sRGB, - PNG_INFO_iCCP, PNG_INFO_sPLT, - PNG_INFO_sCAL, PNG_INFO_IDAT - -For a more compact example of reading a PNG image, see the file example.c. - -.SS Reading PNG files progressively - -The progressive reader is slightly different then the non-progressive -reader. Instead of calling png_read_info(), png_read_rows(), and -png_read_end(), you make one call to png_process_data(), which calls -callbacks when it has the info, a row, or the end of the image. You -set up these callbacks with png_set_progressive_read_fn(). You don't -have to worry about the input/output functions of libpng, as you are -giving the library the data directly in png_process_data(). I will -assume that you have read the section on reading PNG files above, -so I will only highlight the differences (although I will show -all of the code). - -png_structp png_ptr; -png_infop info_ptr; - - /* An example code fragment of how you would - initialize the progressive reader in your - application. */ - int - initialize_png_reader() - { - png_ptr = png_create_read_struct - (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, - user_error_fn, user_warning_fn); - - if (!png_ptr) - return (ERROR); - - info_ptr = png_create_info_struct(png_ptr); - - if (!info_ptr) - { - png_destroy_read_struct(&png_ptr, - (png_infopp)NULL, (png_infopp)NULL); - return (ERROR); - } - - if (setjmp(png_jmpbuf(png_ptr))) - { - png_destroy_read_struct(&png_ptr, &info_ptr, - (png_infopp)NULL); - return (ERROR); - } - - /* This one's new. You can provide functions - to be called when the header info is valid, - when each row is completed, and when the image - is finished. If you aren't using all functions, - you can specify NULL parameters. Even when all - three functions are NULL, you need to call - png_set_progressive_read_fn(). You can use - any struct as the user_ptr (cast to a void pointer - for the function call), and retrieve the pointer - from inside the callbacks using the function - - png_get_progressive_ptr(png_ptr); - - which will return a void pointer, which you have - to cast appropriately. - */ - png_set_progressive_read_fn(png_ptr, (void *)user_ptr, - info_callback, row_callback, end_callback); - - return 0; - } - - /* A code fragment that you call as you receive blocks - of data */ - int - process_data(png_bytep buffer, png_uint_32 length) - { - if (setjmp(png_jmpbuf(png_ptr))) - { - png_destroy_read_struct(&png_ptr, &info_ptr, - (png_infopp)NULL); - return (ERROR); - } - - /* This one's new also. Simply give it a chunk - of data from the file stream (in order, of - course). On machines with segmented memory - models machines, don't give it any more than - 64K. The library seems to run fine with sizes - of 4K. Although you can give it much less if - necessary (I assume you can give it chunks of - 1 byte, I haven't tried less then 256 bytes - yet). When this function returns, you may - want to display any rows that were generated - in the row callback if you don't already do - so there. - */ - png_process_data(png_ptr, info_ptr, buffer, length); - - /* At this point you can call png_process_data_skip if - you want to handle data the library will skip yourself; - it simply returns the number of bytes to skip (and stops - libpng skipping that number of bytes on the next - png_process_data call). - return 0; - } - - /* This function is called (as set by - png_set_progressive_read_fn() above) when enough data - has been supplied so all of the header has been - read. - */ - void - info_callback(png_structp png_ptr, png_infop info) - { - /* Do any setup here, including setting any of - the transformations mentioned in the Reading - PNG files section. For now, you _must_ call - either png_start_read_image() or - png_read_update_info() after all the - transformations are set (even if you don't set - any). You may start getting rows before - png_process_data() returns, so this is your - last chance to prepare for that. - - This is where you turn on interlace handling, - assuming you don't want to do it yourself. - - If you need to you can stop the processing of - your original input data at this point by calling - png_process_data_pause. This returns the number - of unprocessed bytes from the last png_process_data - call - it is up to you to ensure that the next call - sees these bytes again. If you don't want to bother - with this you can get libpng to cache the unread - bytes by setting the 'save' parameter (see png.h) but - then libpng will have to copy the data internally. - */ - } - - /* This function is called when each row of image - data is complete */ - void - row_callback(png_structp png_ptr, png_bytep new_row, - png_uint_32 row_num, int pass) - { - /* If the image is interlaced, and you turned - on the interlace handler, this function will - be called for every row in every pass. Some - of these rows will not be changed from the - previous pass. When the row is not changed, - the new_row variable will be NULL. The rows - and passes are called in order, so you don't - really need the row_num and pass, but I'm - supplying them because it may make your life - easier. - - If you did not turn on interlace handling then - the callback is called for each row of each - sub-image when the image is interlaced. In this - case 'row_num' is the row in the sub-image, not - the row in the output image as it is in all other - cases. - - For the non-NULL rows of interlaced images when - you have switched on libpng interlace handling, - you must call png_progressive_combine_row() - passing in the row and the old row. You can - call this function for NULL rows (it will just - return) and for non-interlaced images (it just - does the memcpy for you) if it will make the - code easier. Thus, you can just do this for - all cases if you switch on interlace handling; - */ - - png_progressive_combine_row(png_ptr, old_row, - new_row); - - /* where old_row is what was displayed for - previously for the row. Note that the first - pass (pass == 0, really) will completely cover - the old row, so the rows do not have to be - initialized. After the first pass (and only - for interlaced images), you will have to pass - the current row, and the function will combine - the old row and the new row. - - You can also call png_process_data_pause in this - callback - see above. - */ - } - - void - end_callback(png_structp png_ptr, png_infop info) - { - /* This function is called after the whole image - has been read, including any chunks after the - image (up to and including the IEND). You - will usually have the same info chunk as you - had in the header, although some data may have - been added to the comments and time fields. - - Most people won't do much here, perhaps setting - a flag that marks the image as finished. - */ - } - - - -.SH IV. Writing - -Much of this is very similar to reading. However, everything of -importance is repeated here, so you won't have to constantly look -back up in the reading section to understand writing. - -.SS Setup - -You will want to do the I/O initialization before you get into libpng, -so if it doesn't work, you don't have anything to undo. If you are not -using the standard I/O functions, you will need to replace them with -custom writing functions. See the discussion under Customizing libpng. - - FILE *fp = fopen(file_name, "wb"); - - if (!fp) - return (ERROR); - -Next, png_struct and png_info need to be allocated and initialized. -As these can be both relatively large, you may not want to store these -on the stack, unless you have stack space to spare. Of course, you -will want to check if they return NULL. If you are also reading, -you won't want to name your read structure and your write structure -both "png_ptr"; you can call them anything you like, such as -"read_ptr" and "write_ptr". Look at pngtest.c, for example. - - png_structp png_ptr = png_create_write_struct - (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, - user_error_fn, user_warning_fn); - - if (!png_ptr) - return (ERROR); - - png_infop info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - { - png_destroy_write_struct(&png_ptr, - (png_infopp)NULL); - return (ERROR); - } - -If you want to use your own memory allocation routines, -define PNG_USER_MEM_SUPPORTED and use -png_create_write_struct_2() instead of png_create_write_struct(): - - png_structp png_ptr = png_create_write_struct_2 - (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, - user_error_fn, user_warning_fn, (png_voidp) - user_mem_ptr, user_malloc_fn, user_free_fn); - -After you have these structures, you will need to set up the -error handling. When libpng encounters an error, it expects to -longjmp() back to your routine. Therefore, you will need to call -setjmp() and pass the png_jmpbuf(png_ptr). If you -write the file from different routines, you will need to update -the png_jmpbuf(png_ptr) every time you enter a new routine that will -call a png_*() function. See your documentation of setjmp/longjmp -for your compiler for more information on setjmp/longjmp. See -the discussion on libpng error handling in the Customizing Libpng -section below for more information on the libpng error handling. - - if (setjmp(png_jmpbuf(png_ptr))) - { - png_destroy_write_struct(&png_ptr, &info_ptr); - fclose(fp); - return (ERROR); - } - ... - return; - -If you would rather avoid the complexity of setjmp/longjmp issues, -you can compile libpng with PNG_NO_SETJMP, in which case -errors will result in a call to PNG_ABORT() which defaults to abort(). - -You can #define PNG_ABORT() to a function that does something -more useful than abort(), as long as your function does not -return. - -Now you need to set up the output code. The default for libpng is to -use the C function fwrite(). If you use this, you will need to pass a -valid FILE * in the function png_init_io(). Be sure that the file is -opened in binary mode. Again, if you wish to handle writing data in -another way, see the discussion on libpng I/O handling in the Customizing -Libpng section below. - - png_init_io(png_ptr, fp); - -If you are embedding your PNG into a datastream such as MNG, and don't -want libpng to write the 8-byte signature, or if you have already -written the signature in your application, use - - png_set_sig_bytes(png_ptr, 8); - -to inform libpng that it should not write a signature. - -.SS Write callbacks - -At this point, you can set up a callback function that will be -called after each row has been written, which you can use to control -a progress meter or the like. It's demonstrated in pngtest.c. -You must supply a function - - void write_row_callback(png_structp png_ptr, png_uint_32 row, - int pass); - { - /* put your code here */ - } - -(You can give it another name that you like instead of "write_row_callback") - -To inform libpng about your function, use - - png_set_write_status_fn(png_ptr, write_row_callback); - -When this function is called the row has already been completely processed and -it has also been written out. The 'row' and 'pass' refer to the next row to be -handled. For the -non-interlaced case the row that was just handled is simply one less than the -passed in row number, and pass will always be 0. For the interlaced case the -same applies unless the row value is 0, in which case the row just handled was -the last one from one of the preceding passes. Because interlacing may skip a -pass you cannot be sure that the preceding pass is just 'pass-1', if you really -need to know what the last pass is record (row,pass) from the callback and use -the last recorded value each time. - -As with the user transform you can find the output row using the -PNG_ROW_FROM_PASS_ROW macro. - -You now have the option of modifying how the compression library will -run. The following functions are mainly for testing, but may be useful -in some cases, like if you need to write PNG files extremely fast and -are willing to give up some compression, or if you want to get the -maximum possible compression at the expense of slower writing. If you -have no special needs in this area, let the library do what it wants by -not calling this function at all, as it has been tuned to deliver a good -speed/compression ratio. The second parameter to png_set_filter() is -the filter method, for which the only valid values are 0 (as of the -July 1999 PNG specification, version 1.2) or 64 (if you are writing -a PNG datastream that is to be embedded in a MNG datastream). The third -parameter is a flag that indicates which filter type(s) are to be tested -for each scanline. See the PNG specification for details on the specific -filter types. - - - /* turn on or off filtering, and/or choose - specific filters. You can use either a single - PNG_FILTER_VALUE_NAME or the bitwise OR of one - or more PNG_FILTER_NAME masks. - */ - png_set_filter(png_ptr, 0, - PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE | - PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB | - PNG_FILTER_UP | PNG_FILTER_VALUE_UP | - PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG | - PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH| - PNG_ALL_FILTERS); - -If an application wants to start and stop using particular filters during -compression, it should start out with all of the filters (to ensure that -the previous row of pixels will be stored in case it's needed later), -and then add and remove them after the start of compression. - -If you are writing a PNG datastream that is to be embedded in a MNG -datastream, the second parameter can be either 0 or 64. - -The png_set_compression_*() functions interface to the zlib compression -library, and should mostly be ignored unless you really know what you are -doing. The only generally useful call is png_set_compression_level() -which changes how much time zlib spends on trying to compress the image -data. See the Compression Library (zlib.h and algorithm.txt, distributed -with zlib) for details on the compression levels. - - #include zlib.h - - /* Set the zlib compression level */ - png_set_compression_level(png_ptr, - Z_BEST_COMPRESSION); - - /* Set other zlib parameters for compressing IDAT */ - png_set_compression_mem_level(png_ptr, 8); - png_set_compression_strategy(png_ptr, - Z_DEFAULT_STRATEGY); - png_set_compression_window_bits(png_ptr, 15); - png_set_compression_method(png_ptr, 8); - png_set_compression_buffer_size(png_ptr, 8192) - - /* Set zlib parameters for text compression - * If you don't call these, the parameters - * fall back on those defined for IDAT chunks - */ - png_set_text_compression_mem_level(png_ptr, 8); - png_set_text_compression_strategy(png_ptr, - Z_DEFAULT_STRATEGY); - png_set_text_compression_window_bits(png_ptr, 15); - png_set_text_compression_method(png_ptr, 8); - -.SS Setting the contents of info for output - -You now need to fill in the png_info structure with all the data you -wish to write before the actual image. Note that the only thing you -are allowed to write after the image is the text chunks and the time -chunk (as of PNG Specification 1.2, anyway). See png_write_end() and -the latest PNG specification for more information on that. If you -wish to write them before the image, fill them in now, and flag that -data as being valid. If you want to wait until after the data, don't -fill them until png_write_end(). For all the fields in png_info and -their data types, see png.h. For explanations of what the fields -contain, see the PNG specification. - -Some of the more important parts of the png_info are: - - png_set_IHDR(png_ptr, info_ptr, width, height, - bit_depth, color_type, interlace_type, - compression_type, filter_method) - - width - holds the width of the image - in pixels (up to 2^31). - - height - holds the height of the image - in pixels (up to 2^31). - - bit_depth - holds the bit depth of one of the - image channels. - (valid values are 1, 2, 4, 8, 16 - and depend also on the - color_type. See also significant - bits (sBIT) below). - - color_type - describes which color/alpha - channels are present. - PNG_COLOR_TYPE_GRAY - (bit depths 1, 2, 4, 8, 16) - PNG_COLOR_TYPE_GRAY_ALPHA - (bit depths 8, 16) - PNG_COLOR_TYPE_PALETTE - (bit depths 1, 2, 4, 8) - PNG_COLOR_TYPE_RGB - (bit_depths 8, 16) - PNG_COLOR_TYPE_RGB_ALPHA - (bit_depths 8, 16) - - PNG_COLOR_MASK_PALETTE - PNG_COLOR_MASK_COLOR - PNG_COLOR_MASK_ALPHA - - interlace_type - PNG_INTERLACE_NONE or - PNG_INTERLACE_ADAM7 - - compression_type - (must be - PNG_COMPRESSION_TYPE_DEFAULT) - - filter_method - (must be PNG_FILTER_TYPE_DEFAULT - or, if you are writing a PNG to - be embedded in a MNG datastream, - can also be - PNG_INTRAPIXEL_DIFFERENCING) - -If you call png_set_IHDR(), the call must appear before any of the -other png_set_*() functions, because they might require access to some of -the IHDR settings. The remaining png_set_*() functions can be called -in any order. - -If you wish, you can reset the compression_type, interlace_type, or -filter_method later by calling png_set_IHDR() again; if you do this, the -width, height, bit_depth, and color_type must be the same in each call. - - png_set_PLTE(png_ptr, info_ptr, palette, - num_palette); - - palette - the palette for the file - (array of png_color) - num_palette - number of entries in the palette - - png_set_gAMA(png_ptr, info_ptr, file_gamma); - png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma); - - file_gamma - the gamma at which the image was - created (PNG_INFO_gAMA) - - int_file_gamma - 100,000 times the gamma at which - the image was created - - png_set_cHRM(png_ptr, info_ptr, white_x, white_y, red_x, red_y, - green_x, green_y, blue_x, blue_y) - png_set_cHRM_XYZ(png_ptr, info_ptr, red_X, red_Y, red_Z, green_X, - green_Y, green_Z, blue_X, blue_Y, blue_Z) - png_set_cHRM_fixed(png_ptr, info_ptr, int_white_x, int_white_y, - int_red_x, int_red_y, int_green_x, int_green_y, - int_blue_x, int_blue_y) - png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, int_red_X, int_red_Y, - int_red_Z, int_green_X, int_green_Y, int_green_Z, - int_blue_X, int_blue_Y, int_blue_Z) - - {white,red,green,blue}_{x,y} - A color space encoding specified using the chromaticities - of the end points and the white point. - - {red,green,blue}_{X,Y,Z} - A color space encoding specified using the encoding end - points - the CIE tristimulus specification of the intended - color of the red, green and blue channels in the PNG RGB - data. The white point is simply the sum of the three end - points. - - png_set_sRGB(png_ptr, info_ptr, srgb_intent); - - srgb_intent - the rendering intent - (PNG_INFO_sRGB) The presence of - the sRGB chunk means that the pixel - data is in the sRGB color space. - This chunk also implies specific - values of gAMA and cHRM. Rendering - intent is the CSS-1 property that - has been defined by the International - Color Consortium - (http://www.color.org). - It can be one of - PNG_sRGB_INTENT_SATURATION, - PNG_sRGB_INTENT_PERCEPTUAL, - PNG_sRGB_INTENT_ABSOLUTE, or - PNG_sRGB_INTENT_RELATIVE. - - - png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, - srgb_intent); - - srgb_intent - the rendering intent - (PNG_INFO_sRGB) The presence of the - sRGB chunk means that the pixel - data is in the sRGB color space. - This function also causes gAMA and - cHRM chunks with the specific values - that are consistent with sRGB to be - written. - - png_set_iCCP(png_ptr, info_ptr, name, compression_type, - profile, proflen); - - name - The profile name. - - compression_type - The compression type; always - PNG_COMPRESSION_TYPE_BASE for PNG 1.0. - You may give NULL to this argument to - ignore it. - - profile - International Color Consortium color - profile data. May contain NULs. - - proflen - length of profile data in bytes. - - png_set_sBIT(png_ptr, info_ptr, sig_bit); - - sig_bit - the number of significant bits for - (PNG_INFO_sBIT) each of the gray, red, - green, and blue channels, whichever are - appropriate for the given color type - (png_color_16) - - png_set_tRNS(png_ptr, info_ptr, trans_alpha, - num_trans, trans_color); - - trans_alpha - array of alpha (transparency) - entries for palette (PNG_INFO_tRNS) - - num_trans - number of transparent entries - (PNG_INFO_tRNS) - - trans_color - graylevel or color sample values - (in order red, green, blue) of the - single transparent color for - non-paletted images (PNG_INFO_tRNS) - - png_set_hIST(png_ptr, info_ptr, hist); - - hist - histogram of palette (array of - png_uint_16) (PNG_INFO_hIST) - - png_set_tIME(png_ptr, info_ptr, mod_time); - - mod_time - time image was last modified - (PNG_VALID_tIME) - - png_set_bKGD(png_ptr, info_ptr, background); - - background - background color (of type - png_color_16p) (PNG_VALID_bKGD) - - png_set_text(png_ptr, info_ptr, text_ptr, num_text); - - text_ptr - array of png_text holding image - comments - - text_ptr[i].compression - type of compression used - on "text" PNG_TEXT_COMPRESSION_NONE - PNG_TEXT_COMPRESSION_zTXt - PNG_ITXT_COMPRESSION_NONE - PNG_ITXT_COMPRESSION_zTXt - text_ptr[i].key - keyword for comment. Must contain - 1-79 characters. - text_ptr[i].text - text comments for current - keyword. Can be NULL or empty. - text_ptr[i].text_length - length of text string, - after decompression, 0 for iTXt - text_ptr[i].itxt_length - length of itxt string, - after decompression, 0 for tEXt/zTXt - text_ptr[i].lang - language of comment (NULL or - empty for unknown). - text_ptr[i].translated_keyword - keyword in UTF-8 (NULL - or empty for unknown). - - Note that the itxt_length, lang, and lang_key - members of the text_ptr structure only exist when the - library is built with iTXt chunk support. Prior to - libpng-1.4.0 the library was built by default without - iTXt support. Also note that when iTXt is supported, - they contain NULL pointers when the "compression" - field contains PNG_TEXT_COMPRESSION_NONE or - PNG_TEXT_COMPRESSION_zTXt. - - num_text - number of comments - - png_set_sPLT(png_ptr, info_ptr, &palette_ptr, - num_spalettes); - - palette_ptr - array of png_sPLT_struct structures - to be added to the list of palettes - in the info structure. - num_spalettes - number of palette structures to be - added. - - png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, - unit_type); - - offset_x - positive offset from the left - edge of the screen - - offset_y - positive offset from the top - edge of the screen - - unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER - - png_set_pHYs(png_ptr, info_ptr, res_x, res_y, - unit_type); - - res_x - pixels/unit physical resolution - in x direction - - res_y - pixels/unit physical resolution - in y direction - - unit_type - PNG_RESOLUTION_UNKNOWN, - PNG_RESOLUTION_METER - - png_set_sCAL(png_ptr, info_ptr, unit, width, height) - - unit - physical scale units (an integer) - - width - width of a pixel in physical scale units - - height - height of a pixel in physical scale units - (width and height are doubles) - - png_set_sCAL_s(png_ptr, info_ptr, unit, width, height) - - unit - physical scale units (an integer) - - width - width of a pixel in physical scale units - expressed as a string - - height - height of a pixel in physical scale units - (width and height are strings like "2.54") - - png_set_unknown_chunks(png_ptr, info_ptr, &unknowns, - num_unknowns) - - unknowns - array of png_unknown_chunk - structures holding unknown chunks - unknowns[i].name - name of unknown chunk - unknowns[i].data - data of unknown chunk - unknowns[i].size - size of unknown chunk's data - unknowns[i].location - position to write chunk in file - 0: do not write chunk - PNG_HAVE_IHDR: before PLTE - PNG_HAVE_PLTE: before IDAT - PNG_AFTER_IDAT: after IDAT - -The "location" member is set automatically according to -what part of the output file has already been written. -You can change its value after calling png_set_unknown_chunks() -as demonstrated in pngtest.c. Within each of the "locations", -the chunks are sequenced according to their position in the -structure (that is, the value of "i", which is the order in which -the chunk was either read from the input file or defined with -png_set_unknown_chunks). - -A quick word about text and num_text. text is an array of png_text -structures. num_text is the number of valid structures in the array. -Each png_text structure holds a language code, a keyword, a text value, -and a compression type. - -The compression types have the same valid numbers as the compression -types of the image data. Currently, the only valid number is zero. -However, you can store text either compressed or uncompressed, unlike -images, which always have to be compressed. So if you don't want the -text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE. -Because tEXt and zTXt chunks don't have a language field, if you -specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt -any language code or translated keyword will not be written out. - -Until text gets around a few hundred bytes, it is not worth compressing it. -After the text has been written out to the file, the compression type -is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR, -so that it isn't written out again at the end (in case you are calling -png_write_end() with the same struct). - -The keywords that are given in the PNG Specification are: - - Title Short (one line) title or - caption for image - - Author Name of image's creator - - Description Description of image (possibly long) - - Copyright Copyright notice - - Creation Time Time of original image creation - (usually RFC 1123 format, see below) - - Software Software used to create the image - - Disclaimer Legal disclaimer - - Warning Warning of nature of content - - Source Device used to create the image - - Comment Miscellaneous comment; conversion - from other image format - -The keyword-text pairs work like this. Keywords should be short -simple descriptions of what the comment is about. Some typical -keywords are found in the PNG specification, as is some recommendations -on keywords. You can repeat keywords in a file. You can even write -some text before the image and some after. For example, you may want -to put a description of the image before the image, but leave the -disclaimer until after, so viewers working over modem connections -don't have to wait for the disclaimer to go over the modem before -they start seeing the image. Finally, keywords should be full -words, not abbreviations. Keywords and text are in the ISO 8859-1 -(Latin-1) character set (a superset of regular ASCII) and can not -contain NUL characters, and should not contain control or other -unprintable characters. To make the comments widely readable, stick -with basic ASCII, and avoid machine specific character set extensions -like the IBM-PC character set. The keyword must be present, but -you can leave off the text string on non-compressed pairs. -Compressed pairs must have a text string, as only the text string -is compressed anyway, so the compression would be meaningless. - -PNG supports modification time via the png_time structure. Two -conversion routines are provided, png_convert_from_time_t() for -time_t and png_convert_from_struct_tm() for struct tm. The -time_t routine uses gmtime(). You don't have to use either of -these, but if you wish to fill in the png_time structure directly, -you should provide the time in universal time (GMT) if possible -instead of your local time. Note that the year number is the full -year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and -that months start with 1. - -If you want to store the time of the original image creation, you should -use a plain tEXt chunk with the "Creation Time" keyword. This is -necessary because the "creation time" of a PNG image is somewhat vague, -depending on whether you mean the PNG file, the time the image was -created in a non-PNG format, a still photo from which the image was -scanned, or possibly the subject matter itself. In order to facilitate -machine-readable dates, it is recommended that the "Creation Time" -tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"), -although this isn't a requirement. Unlike the tIME chunk, the -"Creation Time" tEXt chunk is not expected to be automatically changed -by the software. To facilitate the use of RFC 1123 dates, a function -png_convert_to_rfc1123(png_ptr, png_timep) is provided to convert -from PNG time to an RFC 1123 format string. - -.SS Writing unknown chunks - -You can use the png_set_unknown_chunks function to queue up chunks -for writing. You give it a chunk name, raw data, and a size; that's -all there is to it. The chunks will be written by the next following -png_write_info_before_PLTE, png_write_info, or png_write_end function. -Any chunks previously read into the info structure's unknown-chunk -list will also be written out in a sequence that satisfies the PNG -specification's ordering rules. - -.SS The high-level write interface - -At this point there are two ways to proceed; through the high-level -write interface, or through a sequence of low-level write operations. -You can use the high-level interface if your image data is present -in the info structure. All defined output -transformations are permitted, enabled by the following masks. - - PNG_TRANSFORM_IDENTITY No transformation - PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples - PNG_TRANSFORM_PACKSWAP Change order of packed - pixels to LSB first - PNG_TRANSFORM_INVERT_MONO Invert monochrome images - PNG_TRANSFORM_SHIFT Normalize pixels to the - sBIT depth - PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA - to BGRA - PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA - to AG - PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity - to transparency - PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples - PNG_TRANSFORM_STRIP_FILLER Strip out filler - bytes (deprecated). - PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading - filler bytes - PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing - filler bytes - -If you have valid image data in the info structure (you can use -png_set_rows() to put image data in the info structure), simply do this: - - png_write_png(png_ptr, info_ptr, png_transforms, NULL) - -where png_transforms is an integer containing the bitwise OR of some set of -transformation flags. This call is equivalent to png_write_info(), -followed the set of transformations indicated by the transform mask, -then png_write_image(), and finally png_write_end(). - -(The final parameter of this call is not yet used. Someday it might point -to transformation parameters required by some future output transform.) - -You must use png_transforms and not call any png_set_transform() functions -when you use png_write_png(). - -.SS The low-level write interface - -If you are going the low-level route instead, you are now ready to -write all the file information up to the actual image data. You do -this with a call to png_write_info(). - - png_write_info(png_ptr, info_ptr); - -Note that there is one transformation you may need to do before -png_write_info(). In PNG files, the alpha channel in an image is the -level of opacity. If your data is supplied as a level of transparency, -you can invert the alpha channel before you write it, so that 0 is -fully transparent and 255 (in 8-bit or paletted images) or 65535 -(in 16-bit images) is fully opaque, with - - png_set_invert_alpha(png_ptr); - -This must appear before png_write_info() instead of later with the -other transformations because in the case of paletted images the tRNS -chunk data has to be inverted before the tRNS chunk is written. If -your image is not a paletted image, the tRNS data (which in such cases -represents a single color to be rendered as transparent) won't need to -be changed, and you can safely do this transformation after your -png_write_info() call. - -If you need to write a private chunk that you want to appear before -the PLTE chunk when PLTE is present, you can write the PNG info in -two steps, and insert code to write your own chunk between them: - - png_write_info_before_PLTE(png_ptr, info_ptr); - png_set_unknown_chunks(png_ptr, info_ptr, ...); - png_write_info(png_ptr, info_ptr); - -After you've written the file information, you can set up the library -to handle any special transformations of the image data. The various -ways to transform the data will be described in the order that they -should occur. This is important, as some of these change the color -type and/or bit depth of the data, and some others only work on -certain color types and bit depths. Even though each transformation -checks to see if it has data that it can do something with, you should -make sure to only enable a transformation if it will be valid for the -data. For example, don't swap red and blue on grayscale data. - -PNG files store RGB pixels packed into 3 or 6 bytes. This code tells -the library to strip input data that has 4 or 8 bytes per pixel down -to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2 -bytes per pixel). - - png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); - -where the 0 is unused, and the location is either PNG_FILLER_BEFORE or -PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel -is stored XRGB or RGBX. - -PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as -they can, resulting in, for example, 8 pixels per byte for 1 bit files. -If the data is supplied at 1 pixel per byte, use this code, which will -correctly pack the pixels into a single byte: - - png_set_packing(png_ptr); - -PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your -data is of another bit depth, you can write an sBIT chunk into the -file so that decoders can recover the original data if desired. - - /* Set the true bit depth of the image data */ - if (color_type & PNG_COLOR_MASK_COLOR) - { - sig_bit.red = true_bit_depth; - sig_bit.green = true_bit_depth; - sig_bit.blue = true_bit_depth; - } - - else - { - sig_bit.gray = true_bit_depth; - } - - if (color_type & PNG_COLOR_MASK_ALPHA) - { - sig_bit.alpha = true_bit_depth; - } - - png_set_sBIT(png_ptr, info_ptr, &sig_bit); - -If the data is stored in the row buffer in a bit depth other than -one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG), -this will scale the values to appear to be the correct bit depth as -is required by PNG. - - png_set_shift(png_ptr, &sig_bit); - -PNG files store 16-bit pixels in network byte order (big-endian, -ie. most significant bits first). This code would be used if they are -supplied the other way (little-endian, i.e. least significant bits -first, the way PCs store them): - - if (bit_depth > 8) - png_set_swap(png_ptr); - -If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you -need to change the order the pixels are packed into bytes, you can use: - - if (bit_depth < 8) - png_set_packswap(png_ptr); - -PNG files store 3 color pixels in red, green, blue order. This code -would be used if they are supplied as blue, green, red: - - png_set_bgr(png_ptr); - -PNG files describe monochrome as black being zero and white being -one. This code would be used if the pixels are supplied with this reversed -(black being one and white being zero): - - png_set_invert_mono(png_ptr); - -Finally, you can write your own transformation function if none of -the existing ones meets your needs. This is done by setting a callback -with - - png_set_write_user_transform_fn(png_ptr, - write_transform_fn); - -You must supply the function - - void write_transform_fn(png_structp png_ptr, png_row_infop - row_info, png_bytep data) - -See pngtest.c for a working example. Your function will be called -before any of the other transformations are processed. If supported -libpng also supplies an information routine that may be called from -your callback: - - png_get_current_row_number(png_ptr); - png_get_current_pass_number(png_ptr); - -This returns the current row passed to the transform. With interlaced -images the value returned is the row in the input sub-image image. Use -PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to -find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass). - -The discussion of interlace handling above contains more information on how to -use these values. - -You can also set up a pointer to a user structure for use by your -callback function. - - png_set_user_transform_info(png_ptr, user_ptr, 0, 0); - -The user_channels and user_depth parameters of this function are ignored -when writing; you can set them to zero as shown. - -You can retrieve the pointer via the function png_get_user_transform_ptr(). -For example: - - voidp write_user_transform_ptr = - png_get_user_transform_ptr(png_ptr); - -It is possible to have libpng flush any pending output, either manually, -or automatically after a certain number of lines have been written. To -flush the output stream a single time call: - - png_write_flush(png_ptr); - -and to have libpng flush the output stream periodically after a certain -number of scanlines have been written, call: - - png_set_flush(png_ptr, nrows); - -Note that the distance between rows is from the last time png_write_flush() -was called, or the first row of the image if it has never been called. -So if you write 50 lines, and then png_set_flush 25, it will flush the -output on the next scanline, and every 25 lines thereafter, unless -png_write_flush() is called before 25 more lines have been written. -If nrows is too small (less than about 10 lines for a 640 pixel wide -RGB image) the image compression may decrease noticeably (although this -may be acceptable for real-time applications). Infrequent flushing will -only degrade the compression performance by a few percent over images -that do not use flushing. - -.SS Writing the image data - -That's it for the transformations. Now you can write the image data. -The simplest way to do this is in one function call. If you have the -whole image in memory, you can just call png_write_image() and libpng -will write the image. You will need to pass in an array of pointers to -each row. This function automatically handles interlacing, so you don't -need to call png_set_interlace_handling() or call this function multiple -times, or any of that other stuff necessary with png_write_rows(). - - png_write_image(png_ptr, row_pointers); - -where row_pointers is: - - png_byte *row_pointers[height]; - -You can point to void or char or whatever you use for pixels. - -If you don't want to write the whole image at once, you can -use png_write_rows() instead. If the file is not interlaced, -this is simple: - - png_write_rows(png_ptr, row_pointers, - number_of_rows); - -row_pointers is the same as in the png_write_image() call. - -If you are just writing one row at a time, you can do this with -a single row_pointer instead of an array of row_pointers: - - png_bytep row_pointer = row; - - png_write_row(png_ptr, row_pointer); - -When the file is interlaced, things can get a good deal more complicated. -The only currently (as of the PNG Specification version 1.2, dated July -1999) defined interlacing scheme for PNG files is the "Adam7" interlace -scheme, that breaks down an image into seven smaller images of varying -size. libpng will build these images for you, or you can do them -yourself. If you want to build them yourself, see the PNG specification -for details of which pixels to write when. - -If you don't want libpng to handle the interlacing details, just -use png_set_interlace_handling() and call png_write_rows() the -correct number of times to write all the sub-images -(png_set_interlace_handling() returns the number of sub-images.) - -If you want libpng to build the sub-images, call this before you start -writing any rows: - - number_of_passes = png_set_interlace_handling(png_ptr); - -This will return the number of passes needed. Currently, this is seven, -but may change if another interlace type is added. - -Then write the complete image number_of_passes times. - - png_write_rows(png_ptr, row_pointers, number_of_rows); - -Think carefully before you write an interlaced image. Typically code that -reads such images reads all the image data into memory, uncompressed, before -doing any processing. Only code that can display an image on the fly can -take advantage of the interlacing and even then the image has to be exactly -the correct size for the output device, because scaling an image requires -adjacent pixels and these are not available until all the passes have been -read. - -If you do write an interlaced image you will hardly ever need to handle -the interlacing yourself. Call png_set_interlace_handling() and use the -approach described above. - -The only time it is conceivable that you will really need to write an -interlaced image pass-by-pass is when you have read one pass by pass and -made some pixel-by-pixel transformation to it, as described in the read -code above. In this case use the PNG_PASS_ROWS and PNG_PASS_COLS macros -to determine the size of each sub-image in turn and simply write the rows -you obtained from the read code. - -.SS Finishing a sequential write - -After you are finished writing the image, you should finish writing -the file. If you are interested in writing comments or time, you should -pass an appropriately filled png_info pointer. If you are not interested, -you can pass NULL. - - png_write_end(png_ptr, info_ptr); - -When you are done, you can free all memory used by libpng like this: - - png_destroy_write_struct(&png_ptr, &info_ptr); - -It is also possible to individually free the info_ptr members that -point to libpng-allocated storage with the following function: - - png_free_data(png_ptr, info_ptr, mask, seq) - - mask - identifies data to be freed, a mask - containing the bitwise OR of one or - more of - PNG_FREE_PLTE, PNG_FREE_TRNS, - PNG_FREE_HIST, PNG_FREE_ICCP, - PNG_FREE_PCAL, PNG_FREE_ROWS, - PNG_FREE_SCAL, PNG_FREE_SPLT, - PNG_FREE_TEXT, PNG_FREE_UNKN, - or simply PNG_FREE_ALL - - seq - sequence number of item to be freed - (-1 for all items) - -This function may be safely called when the relevant storage has -already been freed, or has not yet been allocated, or was allocated -by the user and not by libpng, and will in those cases do nothing. -The "seq" parameter is ignored if only one item of the selected data -type, such as PLTE, is allowed. If "seq" is not -1, and multiple items -are allowed for the data type identified in the mask, such as text or -sPLT, only the n'th item in the structure is freed, where n is "seq". - -If you allocated data such as a palette that you passed in to libpng -with png_set_*, you must not free it until just before the call to -png_destroy_write_struct(). - -The default behavior is only to free data that was allocated internally -by libpng. This can be changed, so that libpng will not free the data, -or so that it will free data that was allocated by the user with png_malloc() -or png_calloc() and passed in via a png_set_*() function, with - - png_data_freer(png_ptr, info_ptr, freer, mask) - - freer - one of - PNG_DESTROY_WILL_FREE_DATA - PNG_SET_WILL_FREE_DATA - PNG_USER_WILL_FREE_DATA - - mask - which data elements are affected - same choices as in png_free_data() - -For example, to transfer responsibility for some data from a read structure -to a write structure, you could use - - png_data_freer(read_ptr, read_info_ptr, - PNG_USER_WILL_FREE_DATA, - PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST) - - png_data_freer(write_ptr, write_info_ptr, - PNG_DESTROY_WILL_FREE_DATA, - PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST) - -thereby briefly reassigning responsibility for freeing to the user but -immediately afterwards reassigning it once more to the write_destroy -function. Having done this, it would then be safe to destroy the read -structure and continue to use the PLTE, tRNS, and hIST data in the write -structure. - -This function only affects data that has already been allocated. -You can call this function before calling after the png_set_*() functions -to control whether the user or png_destroy_*() is supposed to free the data. -When the user assumes responsibility for libpng-allocated data, the -application must use -png_free() to free it, and when the user transfers responsibility to libpng -for data that the user has allocated, the user must have used png_malloc() -or png_calloc() to allocate it. - -If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword -separately, do not transfer responsibility for freeing text_ptr to libpng, -because when libpng fills a png_text structure it combines these members with -the key member, and png_free_data() will free only text_ptr.key. Similarly, -if you transfer responsibility for free'ing text_ptr from libpng to your -application, your application must not separately free those members. -For a more compact example of writing a PNG image, see the file example.c. - -.SH V. Modifying/Customizing libpng: - -There are two issues here. The first is changing how libpng does -standard things like memory allocation, input/output, and error handling. -The second deals with more complicated things like adding new chunks, -adding new transformations, and generally changing how libpng works. -Both of those are compile-time issues; that is, they are generally -determined at the time the code is written, and there is rarely a need -to provide the user with a means of changing them. - -Memory allocation, input/output, and error handling - -All of the memory allocation, input/output, and error handling in libpng -goes through callbacks that are user-settable. The default routines are -in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change -these functions, call the appropriate png_set_*_fn() function. - -Memory allocation is done through the functions png_malloc(), png_calloc(), -and png_free(). The png_malloc() and png_free() functions currently just -call the standard C functions and png_calloc() calls png_malloc() and then -clears the newly allocated memory to zero; note that png_calloc(png_ptr, size) -is not the same as the calloc(number, size) function provided by stdlib.h. -There is limited support for certain systems with segmented memory -architectures and the types of pointers declared by png.h match this; you -will have to use appropriate pointers in your application. Since it is -unlikely that the method of handling memory allocation on a platform -will change between applications, these functions must be modified in -the library at compile time. If you prefer to use a different method -of allocating and freeing data, you can use png_create_read_struct_2() or -png_create_write_struct_2() to register your own functions as described -above. These functions also provide a void pointer that can be retrieved -via - - mem_ptr=png_get_mem_ptr(png_ptr); - -Your replacement memory functions must have prototypes as follows: - - png_voidp malloc_fn(png_structp png_ptr, - png_alloc_size_t size); - - void free_fn(png_structp png_ptr, png_voidp ptr); - -Your malloc_fn() must return NULL in case of failure. The png_malloc() -function will normally call png_error() if it receives a NULL from the -system memory allocator or from your replacement malloc_fn(). - -Your free_fn() will never be called with a NULL ptr, since libpng's -png_free() checks for NULL before calling free_fn(). - -Input/Output in libpng is done through png_read() and png_write(), -which currently just call fread() and fwrite(). The FILE * is stored in -png_struct and is initialized via png_init_io(). If you wish to change -the method of I/O, the library supplies callbacks that you can set -through the function png_set_read_fn() and png_set_write_fn() at run -time, instead of calling the png_init_io() function. These functions -also provide a void pointer that can be retrieved via the function -png_get_io_ptr(). For example: - - png_set_read_fn(png_structp read_ptr, - voidp read_io_ptr, png_rw_ptr read_data_fn) - - png_set_write_fn(png_structp write_ptr, - voidp write_io_ptr, png_rw_ptr write_data_fn, - png_flush_ptr output_flush_fn); - - voidp read_io_ptr = png_get_io_ptr(read_ptr); - voidp write_io_ptr = png_get_io_ptr(write_ptr); - -The replacement I/O functions must have prototypes as follows: - - void user_read_data(png_structp png_ptr, - png_bytep data, png_size_t length); - - void user_write_data(png_structp png_ptr, - png_bytep data, png_size_t length); - - void user_flush_data(png_structp png_ptr); - -The user_read_data() function is responsible for detecting and -handling end-of-data errors. - -Supplying NULL for the read, write, or flush functions sets them back -to using the default C stream functions, which expect the io_ptr to -point to a standard *FILE structure. It is probably a mistake -to use NULL for one of write_data_fn and output_flush_fn but not both -of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined. -It is an error to read from a write stream, and vice versa. - -Error handling in libpng is done through png_error() and png_warning(). -Errors handled through png_error() are fatal, meaning that png_error() -should never return to its caller. Currently, this is handled via -setjmp() and longjmp() (unless you have compiled libpng with -PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()), -but you could change this to do things like exit() if you should wish, -as long as your function does not return. - -On non-fatal errors, png_warning() is called -to print a warning message, and then control returns to the calling code. -By default png_error() and png_warning() print a message on stderr via -fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined -(because you don't want the messages) or PNG_NO_STDIO defined (because -fprintf() isn't available). If you wish to change the behavior of the error -functions, you will need to set up your own message callbacks. These -functions are normally supplied at the time that the png_struct is created. -It is also possible to redirect errors and warnings to your own replacement -functions after png_create_*_struct() has been called by calling: - - png_set_error_fn(png_structp png_ptr, - png_voidp error_ptr, png_error_ptr error_fn, - png_error_ptr warning_fn); - - png_voidp error_ptr = png_get_error_ptr(png_ptr); - -If NULL is supplied for either error_fn or warning_fn, then the libpng -default function will be used, calling fprintf() and/or longjmp() if a -problem is encountered. The replacement error functions should have -parameters as follows: - - void user_error_fn(png_structp png_ptr, - png_const_charp error_msg); - - void user_warning_fn(png_structp png_ptr, - png_const_charp warning_msg); - -The motivation behind using setjmp() and longjmp() is the C++ throw and -catch exception handling methods. This makes the code much easier to write, -as there is no need to check every return code of every function call. -However, there are some uncertainties about the status of local variables -after a longjmp, so the user may want to be careful about doing anything -after setjmp returns non-zero besides returning itself. Consult your -compiler documentation for more details. For an alternative approach, you -may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net), -which is illustrated in pngvalid.c and in contrib/visupng. - -.SS Custom chunks - -If you need to read or write custom chunks, you may need to get deeper -into the libpng code. The library now has mechanisms for storing -and writing chunks of unknown type; you can even declare callbacks -for custom chunks. However, this may not be good enough if the -library code itself needs to know about interactions between your -chunk and existing `intrinsic' chunks. - -If you need to write a new intrinsic chunk, first read the PNG -specification. Acquire a first level of understanding of how it works. -Pay particular attention to the sections that describe chunk names, -and look at how other chunks were designed, so you can do things -similarly. Second, check out the sections of libpng that read and -write chunks. Try to find a chunk that is similar to yours and use -it as a template. More details can be found in the comments inside -the code. It is best to handle private or unknown chunks in a generic method, -via callback functions, instead of by modifying libpng functions. This -is illustrated in pngtest.c, which uses a callback function to handle a -private "vpAg" chunk and the new "sTER" chunk, which are both unknown to -libpng. - -If you wish to write your own transformation for the data, look through -the part of the code that does the transformations, and check out some of -the simpler ones to get an idea of how they work. Try to find a similar -transformation to the one you want to add and copy off of it. More details -can be found in the comments inside the code itself. - -.SS Configuring for 16-bit platforms - -You will want to look into zconf.h to tell zlib (and thus libpng) that -it cannot allocate more then 64K at a time. Even if you can, the memory -won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K. - -.SS Configuring for DOS - -For DOS users who only have access to the lower 640K, you will -have to limit zlib's memory usage via a png_set_compression_mem_level() -call. See zlib.h or zconf.h in the zlib library for more information. - -.SS Configuring for Medium Model - -Libpng's support for medium model has been tested on most of the popular -compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets -defined, and FAR gets defined to far in pngconf.h, and you should be -all set. Everything in the library (except for zlib's structure) is -expecting far data. You must use the typedefs with the p or pp on -the end for pointers (or at least look at them and be careful). Make -note that the rows of data are defined as png_bytepp, which is -an "unsigned char far * far *". - -.SS Configuring for gui/windowing platforms: - -You will need to write new error and warning functions that use the GUI -interface, as described previously, and set them to be the error and -warning functions at the time that png_create_*_struct() is called, -in order to have them available during the structure initialization. -They can be changed later via png_set_error_fn(). On some compilers, -you may also have to change the memory allocators (png_malloc, etc.). - -.SS Configuring for compiler xxx: - -All includes for libpng are in pngconf.h. If you need to add, change -or delete an include, this is the place to do it. -The includes that are not needed outside libpng are placed in pngpriv.h, -which is only used by the routines inside libpng itself. -The files in libpng proper only include pngpriv.h and png.h, which -%14%in turn includes pngconf.h. -in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h. -As of libpng-1.5.0, pngpriv.h also includes three other private header -files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material -that previously appeared in the public headers. - -.SS Configuring zlib: - -There are special functions to configure the compression. Perhaps the -most useful one changes the compression level, which currently uses -input compression values in the range 0 - 9. The library normally -uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests -have shown that for a large majority of images, compression values in -the range 3-6 compress nearly as well as higher levels, and do so much -faster. For online applications it may be desirable to have maximum speed -(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also -specify no compression (Z_NO_COMPRESSION = 0), but this would create -files larger than just storing the raw bitmap. You can specify the -compression level by calling: - - #include zlib.h - png_set_compression_level(png_ptr, level); - -Another useful one is to reduce the memory level used by the library. -The memory level defaults to 8, but it can be lowered if you are -short on memory (running DOS, for example, where you only have 640K). -Note that the memory level does have an effect on compression; among -other things, lower levels will result in sections of incompressible -data being emitted in smaller stored blocks, with a correspondingly -larger relative overhead of up to 15% in the worst case. - - #include zlib.h - png_set_compression_mem_level(png_ptr, level); - -The other functions are for configuring zlib. They are not recommended -for normal use and may result in writing an invalid PNG file. See -zlib.h for more information on what these mean. - - #include zlib.h - png_set_compression_strategy(png_ptr, - strategy); - - png_set_compression_window_bits(png_ptr, - window_bits); - - png_set_compression_method(png_ptr, method); - - png_set_compression_buffer_size(png_ptr, size); - -As of libpng version 1.5.4, additional APIs became -available to set these separately for non-IDAT -compressed chunks such as zTXt, iTXt, and iCCP: - - #include zlib.h - #if PNG_LIBPNG_VER >= 10504 - png_set_text_compression_level(png_ptr, level); - - png_set_text_compression_mem_level(png_ptr, level); - - png_set_text_compression_strategy(png_ptr, - strategy); - - png_set_text_compression_window_bits(png_ptr, - window_bits); - - png_set_text_compression_method(png_ptr, method); - #endif - -.SS Controlling row filtering - -If you want to control whether libpng uses filtering or not, which -filters are used, and how it goes about picking row filters, you -can call one of these functions. The selection and configuration -of row filters can have a significant impact on the size and -encoding speed and a somewhat lesser impact on the decoding speed -of an image. Filtering is enabled by default for RGB and grayscale -images (with and without alpha), but not for paletted images nor -for any images with bit depths less than 8 bits/pixel. - -The 'method' parameter sets the main filtering method, which is -currently only '0' in the PNG 1.2 specification. The 'filters' -parameter sets which filter(s), if any, should be used for each -scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS -to turn filtering on and off, respectively. - -Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB, -PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise -ORed together with '|' to specify one or more filters to use. -These filters are described in more detail in the PNG specification. -If you intend to change the filter type during the course of writing -the image, you should start with flags set for all of the filters -you intend to use so that libpng can initialize its internal -structures appropriately for all of the filter types. (Note that this -means the first row must always be adaptively filtered, because libpng -currently does not allocate the filter buffers until png_write_row() -is called for the first time.) - - filters = PNG_FILTER_NONE | PNG_FILTER_SUB - PNG_FILTER_UP | PNG_FILTER_AVG | - PNG_FILTER_PAETH | PNG_ALL_FILTERS; - - png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, - filters); - The second parameter can also be - PNG_INTRAPIXEL_DIFFERENCING if you are - writing a PNG to be embedded in a MNG - datastream. This parameter must be the - same as the value of filter_method used - in png_set_IHDR(). - -It is also possible to influence how libpng chooses from among the -available filters. This is done in one or both of two ways - by -telling it how important it is to keep the same filter for successive -rows, and by telling it the relative computational costs of the filters. - - double weights[3] = {1.5, 1.3, 1.1}, - costs[PNG_FILTER_VALUE_LAST] = - {1.0, 1.3, 1.3, 1.5, 1.7}; - - png_set_filter_heuristics(png_ptr, - PNG_FILTER_HEURISTIC_WEIGHTED, 3, - weights, costs); - -The weights are multiplying factors that indicate to libpng that the -row filter should be the same for successive rows unless another row filter -is that many times better than the previous filter. In the above example, -if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a -"sum of absolute differences" 1.5 x 1.3 times higher than other filters -and still be chosen, while the NONE filter could have a sum 1.1 times -higher than other filters and still be chosen. Unspecified weights are -taken to be 1.0, and the specified weights should probably be declining -like those above in order to emphasize recent filters over older filters. - -The filter costs specify for each filter type a relative decoding cost -to be considered when selecting row filters. This means that filters -with higher costs are less likely to be chosen over filters with lower -costs, unless their "sum of absolute differences" is that much smaller. -The costs do not necessarily reflect the exact computational speeds of -the various filters, since this would unduly influence the final image -size. - -Note that the numbers above were invented purely for this example and -are given only to help explain the function usage. Little testing has -been done to find optimum values for either the costs or the weights. - -.SS Removing unwanted object code - -There are a bunch of #define's in pngconf.h that control what parts of -libpng are compiled. All the defines end in _SUPPORTED. If you are -never going to use a capability, you can change the #define to #undef -before recompiling libpng and save yourself code and data space, or -you can turn off individual capabilities with defines that begin with -PNG_NO_. - -In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead. - -You can also turn all of the transforms and ancillary chunk capabilities -off en masse with compiler directives that define -PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS, -or all four, -along with directives to turn on any of the capabilities that you do -want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra -transformations but still leave the library fully capable of reading -and writing PNG files with all known public chunks. Use of the -PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library -that is incapable of reading or writing ancillary chunks. If you are -not using the progressive reading capability, you can turn that off -with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING -capability, which you'll still have). - -All the reading and writing specific code are in separate files, so the -linker should only grab the files it needs. However, if you want to -make sure, or if you are building a stand alone library, all the -reading files start with "pngr" and all the writing files start with "pngw". -The files that don't match either (like png.c, pngtrans.c, etc.) -are used for both reading and writing, and always need to be included. -The progressive reader is in pngpread.c - -If you are creating or distributing a dynamically linked library (a .so -or DLL file), you should not remove or disable any parts of the library, -as this will cause applications linked with different versions of the -library to fail if they call functions not available in your library. -The size of the library itself should not be an issue, because only -those sections that are actually used will be loaded into memory. - -.SS Requesting debug printout - -The macro definition PNG_DEBUG can be used to request debugging -printout. Set it to an integer value in the range 0 to 3. Higher -numbers result in increasing amounts of debugging information. The -information is printed to the "stderr" file, unless another file -name is specified in the PNG_DEBUG_FILE macro definition. - -When PNG_DEBUG > 0, the following functions (macros) become available: - - png_debug(level, message) - png_debug1(level, message, p1) - png_debug2(level, message, p1, p2) - -in which "level" is compared to PNG_DEBUG to decide whether to print -the message, "message" is the formatted string to be printed, -and p1 and p2 are parameters that are to be embedded in the string -according to printf-style formatting directives. For example, - - png_debug1(2, "foo=%d\n", foo); - -is expanded to - - if (PNG_DEBUG > 2) - fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo); - -When PNG_DEBUG is defined but is zero, the macros aren't defined, but you -can still use PNG_DEBUG to control your own debugging: - - #ifdef PNG_DEBUG - fprintf(stderr, ... - #endif - -When PNG_DEBUG = 1, the macros are defined, but only png_debug statements -having level = 0 will be printed. There aren't any such statements in -this version of libpng, but if you insert some they will be printed. - -.SH VI. MNG support - -The MNG specification (available at http://www.libpng.org/pub/mng) allows -certain extensions to PNG for PNG images that are embedded in MNG datastreams. -Libpng can support some of these extensions. To enable them, use the -png_permit_mng_features() function: - - feature_set = png_permit_mng_features(png_ptr, mask) - - mask is a png_uint_32 containing the bitwise OR of the - features you want to enable. These include - PNG_FLAG_MNG_EMPTY_PLTE - PNG_FLAG_MNG_FILTER_64 - PNG_ALL_MNG_FEATURES - - feature_set is a png_uint_32 that is the bitwise AND of - your mask with the set of MNG features that is - supported by the version of libpng that you are using. - -It is an error to use this function when reading or writing a standalone -PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped -in a MNG datastream. As a minimum, it must have the MNG 8-byte signature -and the MHDR and MEND chunks. Libpng does not provide support for these -or any other MNG chunks; your application must provide its own support for -them. You may wish to consider using libmng (available at -http://www.libmng.com) instead. - -.SH VII. Changes to Libpng from version 0.88 - -It should be noted that versions of libpng later than 0.96 are not -distributed by the original libpng author, Guy Schalnat, nor by -Andreas Dilger, who had taken over from Guy during 1996 and 1997, and -distributed versions 0.89 through 0.96, but rather by another member -of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are -still alive and well, but they have moved on to other things. - -The old libpng functions png_read_init(), png_write_init(), -png_info_init(), png_read_destroy(), and png_write_destroy() have been -moved to PNG_INTERNAL in version 0.95 to discourage their use. These -functions will be removed from libpng version 1.4.0. - -The preferred method of creating and initializing the libpng structures is -via the png_create_read_struct(), png_create_write_struct(), and -png_create_info_struct() because they isolate the size of the structures -from the application, allow version error checking, and also allow the -use of custom error handling routines during the initialization, which -the old functions do not. The functions png_read_destroy() and -png_write_destroy() do not actually free the memory that libpng -allocated for these structs, but just reset the data structures, so they -can be used instead of png_destroy_read_struct() and -png_destroy_write_struct() if you feel there is too much system overhead -allocating and freeing the png_struct for each image read. - -Setting the error callbacks via png_set_message_fn() before -png_read_init() as was suggested in libpng-0.88 is no longer supported -because this caused applications that do not use custom error functions -to fail if the png_ptr was not initialized to zero. It is still possible -to set the error callbacks AFTER png_read_init(), or to change them with -png_set_error_fn(), which is essentially the same function, but with a new -name to force compilation errors with applications that try to use the old -method. - -Starting with version 1.0.7, you can find out which version of the library -you are using at run-time: - - png_uint_32 libpng_vn = png_access_version_number(); - -The number libpng_vn is constructed from the major version, minor -version with leading zero, and release number with leading zero, -(e.g., libpng_vn for version 1.0.7 is 10007). - -Note that this function does not take a png_ptr, so you can call it -before you've created one. - -You can also check which version of png.h you used when compiling your -application: - - png_uint_32 application_vn = PNG_LIBPNG_VER; - -.SH VIII. Changes to Libpng from version 1.0.x to 1.2.x - -Support for user memory management was enabled by default. To -accomplish this, the functions png_create_read_struct_2(), -png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(), -png_malloc_default(), and png_free_default() were added. - -Support for the iTXt chunk has been enabled by default as of -version 1.2.41. - -Support for certain MNG features was enabled. - -Support for numbered error messages was added. However, we never got -around to actually numbering the error messages. The function -png_set_strip_error_numbers() was added (Note: the prototype for this -function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE -builds of libpng-1.2.15. It was restored in libpng-1.2.36). - -The png_malloc_warn() function was added at libpng-1.2.3. This issues -a png_warning and returns NULL instead of aborting when it fails to -acquire the requested memory allocation. - -Support for setting user limits on image width and height was enabled -by default. The functions png_set_user_limits(), png_get_user_width_max(), -and png_get_user_height_max() were added at libpng-1.2.6. - -The png_set_add_alpha() function was added at libpng-1.2.7. - -The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9. -Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the -tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is -deprecated. - -A number of macro definitions in support of runtime selection of -assembler code features (especially Intel MMX code support) were -added at libpng-1.2.0: - - PNG_ASM_FLAG_MMX_SUPPORT_COMPILED - PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU - PNG_ASM_FLAG_MMX_READ_COMBINE_ROW - PNG_ASM_FLAG_MMX_READ_INTERLACE - PNG_ASM_FLAG_MMX_READ_FILTER_SUB - PNG_ASM_FLAG_MMX_READ_FILTER_UP - PNG_ASM_FLAG_MMX_READ_FILTER_AVG - PNG_ASM_FLAG_MMX_READ_FILTER_PAETH - PNG_ASM_FLAGS_INITIALIZED - PNG_MMX_READ_FLAGS - PNG_MMX_FLAGS - PNG_MMX_WRITE_FLAGS - PNG_MMX_FLAGS - -We added the following functions in support of runtime -selection of assembler code features: - - png_get_mmx_flagmask() - png_set_mmx_thresholds() - png_get_asm_flags() - png_get_mmx_bitdepth_threshold() - png_get_mmx_rowbytes_threshold() - png_set_asm_flags() - -We replaced all of these functions with simple stubs in libpng-1.2.20, -when the Intel assembler code was removed due to a licensing issue. - -These macros are deprecated: - - PNG_READ_TRANSFORMS_NOT_SUPPORTED - PNG_PROGRESSIVE_READ_NOT_SUPPORTED - PNG_NO_SEQUENTIAL_READ_SUPPORTED - PNG_WRITE_TRANSFORMS_NOT_SUPPORTED - PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED - PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED - -They have been replaced, respectively, by: - - PNG_NO_READ_TRANSFORMS - PNG_NO_PROGRESSIVE_READ - PNG_NO_SEQUENTIAL_READ - PNG_NO_WRITE_TRANSFORMS - PNG_NO_READ_ANCILLARY_CHUNKS - PNG_NO_WRITE_ANCILLARY_CHUNKS - -PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been -deprecated since libpng-1.0.16 and libpng-1.2.6. - -The function - png_check_sig(sig, num) -was replaced with - !png_sig_cmp(sig, 0, num) -It has been deprecated since libpng-0.90. - -The function - png_set_gray_1_2_4_to_8() -which also expands tRNS to alpha was replaced with - png_set_expand_gray_1_2_4_to_8() -which does not. It has been deprecated since libpng-1.0.18 and 1.2.9. - -.SH IX. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x - -Private libpng prototypes and macro definitions were moved from -png.h and pngconf.h into a new pngpriv.h header file. - -Functions png_set_benign_errors(), png_benign_error(), and -png_chunk_benign_error() were added. - -Support for setting the maximum amount of memory that the application -will allocate for reading chunks was added, as a security measure. -The functions png_set_chunk_cache_max() and png_get_chunk_cache_max() -were added to the library. - -We implemented support for I/O states by adding png_ptr member io_state -and functions png_get_io_chunk_name() and png_get_io_state() in pngget.c - -We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level -input transforms. - -Checking for and reporting of errors in the IHDR chunk is more thorough. - -Support for global arrays was removed, to improve thread safety. - -Some obsolete/deprecated macros and functions have been removed. - -Typecasted NULL definitions such as - #define png_voidp_NULL (png_voidp)NULL -were eliminated. If you used these in your application, just use -NULL instead. - -The png_struct and info_struct members "trans" and "trans_values" were -changed to "trans_alpha" and "trans_color", respectively. - -The obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles -were removed. - -The PNG_1_0_X and PNG_1_2_X macros were eliminated. - -The PNG_LEGACY_SUPPORTED macro was eliminated. - -Many WIN32_WCE #ifdefs were removed. - -The functions png_read_init(info_ptr), png_write_init(info_ptr), -png_info_init(info_ptr), png_read_destroy(), and png_write_destroy() -have been removed. They have been deprecated since libpng-0.95. - -The png_permit_empty_plte() was removed. It has been deprecated -since libpng-1.0.9. Use png_permit_mng_features() instead. - -We removed the obsolete stub functions png_get_mmx_flagmask(), -png_set_mmx_thresholds(), png_get_asm_flags(), -png_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(), -png_set_asm_flags(), and png_mmx_supported() - -We removed the obsolete png_check_sig(), png_memcpy_check(), and -png_memset_check() functions. Instead use !png_sig_cmp(), png_memcpy(), -and png_memset(), respectively. - -The function png_set_gray_1_2_4_to_8() was removed. It has been -deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with -png_set_expand_gray_1_2_4_to_8() because the former function also -expanded any tRNS chunk to an alpha channel. - -Macros for png_get_uint_16, png_get_uint_32, and png_get_int_32 -were added and are used by default instead of the corresponding -functions. Unfortunately, -from libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the -function) incorrectly returned a value of type png_uint_32. - -We changed the prototype for png_malloc() from - png_malloc(png_structp png_ptr, png_uint_32 size) -to - png_malloc(png_structp png_ptr, png_alloc_size_t size) - -This also applies to the prototype for the user replacement malloc_fn(). - -The png_calloc() function was added and is used in place of -of "png_malloc(); memset();" except in the case in png_read_png() -where the array consists of pointers; in this case a "for" loop is used -after the png_malloc() to set the pointers to NULL, to give robust. -behavior in case the application runs out of memory part-way through -the process. - -We changed the prototypes of png_get_compression_buffer_size() and -png_set_compression_buffer_size() to work with png_size_t instead of -png_uint_32. - -Support for numbered error messages was removed by default, since we -never got around to actually numbering the error messages. The function -png_set_strip_error_numbers() was removed from the library by default. - -The png_zalloc() and png_zfree() functions are no longer exported. -The png_zalloc() function no longer zeroes out the memory that it -allocates. Applications that called png_zalloc(png_ptr, number, size) -can call png_calloc(png_ptr, number*size) instead, and can call -png_free() instead of png_zfree(). - -Support for dithering was disabled by default in libpng-1.4.0, because -it has not been well tested and doesn't actually "dither". -The code was not -removed, however, and could be enabled by building libpng with -PNG_READ_DITHER_SUPPORTED defined. In libpng-1.4.2, this support -was reenabled, but the function was renamed png_set_quantize() to -reflect more accurately what it actually does. At the same time, -the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to -PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED -was renamed to PNG_READ_QUANTIZE_SUPPORTED. - -We removed the trailing '.' from the warning and error messages. - -.SH X. Changes to Libpng from version 1.4.x to 1.5.x - -From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the -function) incorrectly returned a value of type png_uint_32. - -Checking for invalid palette index on read or write was added at libpng -1.5.10. When an invalid index is found, libpng issues a benign error. -This is enabled by default but can be disabled in each png_ptr with - - png_set_check_for_invalid_index(png_ptr, allowed); - - allowed - one of - 0: disable - 1: enable - -A. Changes that affect users of libpng - -There are no substantial API changes between the non-deprecated parts of -the 1.4.5 API and the 1.5.0 API; however, the ability to directly access -members of the main libpng control structures, png_struct and png_info, -deprecated in earlier versions of libpng, has been completely removed from -libpng 1.5. - -We no longer include zlib.h in png.h. Applications that need access -to information in zlib.h will need to add the '#include "zlib.h"' -directive. It does not matter whether it is placed prior to or after -the '"#include png.h"' directive. - -The png_sprintf(), png_strcpy(), and png_strncpy() macros are no longer used -and were removed. - -We moved the png_strlen(), png_memcpy(), png_memset(), and png_memcmp() -macros into a private header file (pngpriv.h) that is not accessible to -applications. - -In png_get_iCCP, the type of "profile" was changed from png_charpp -to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep. - -There are changes of form in png.h, including new and changed macros to -declare parts of the API. Some API functions with arguments that are -pointers to data not modified within the function have been corrected to -declare these arguments with PNG_CONST. - -Much of the internal use of C macros to control the library build has also -changed and some of this is visible in the exported header files, in -particular the use of macros to control data and API elements visible -during application compilation may require significant revision to -application code. (It is extremely rare for an application to do this.) - -Any program that compiled against libpng 1.4 and did not use deprecated -features or access internal library structures should compile and work -against libpng 1.5, except for the change in the prototype for -png_get_iCCP() and png_set_iCCP() API functions mentioned above. - -libpng 1.5.0 adds PNG_ PASS macros to help in the reading and writing of -interlaced images. The macros return the number of rows and columns in -each pass and information that can be used to de-interlace and (if -absolutely necessary) interlace an image. - -libpng 1.5.0 adds an API png_longjmp(png_ptr, value). This API calls -the application-provided png_longjmp_ptr on the internal, but application -initialized, longjmp buffer. It is provided as a convenience to avoid -the need to use the png_jmpbuf macro, which had the unnecessary side -effect of resetting the internal png_longjmp_ptr value. - -libpng 1.5.0 includes a complete fixed point API. By default this is -present along with the corresponding floating point API. In general the -fixed point API is faster and smaller than the floating point one because -the PNG file format used fixed point, not floating point. This applies -even if the library uses floating point in internal calculations. A new -macro, PNG_FLOATING_ARITHMETIC_SUPPORTED, reveals whether the library -uses floating point arithmetic (the default) or fixed point arithmetic -internally for performance critical calculations such as gamma correction. -In some cases, the gamma calculations may produce slightly different -results. This has changed the results in png_rgb_to_gray and in alpha -composition (png_set_background for example). This applies even if the -original image was already linear (gamma == 1.0) and, therefore, it is -not necessary to linearize the image. This is because libpng has *not* -been changed to optimize that case correctly, yet. - -Fixed point support for the sCAL chunk comes with an important caveat; -the sCAL specification uses a decimal encoding of floating point values -and the accuracy of PNG fixed point values is insufficient for -representation of these values. Consequently a "string" API -(png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading -arbitrary sCAL chunks in the absence of either the floating point API or -internal floating point calculations. - -Applications no longer need to include the optional distribution header -file pngusr.h or define the corresponding macros during application -build in order to see the correct variant of the libpng API. From 1.5.0 -application code can check for the corresponding _SUPPORTED macro: - -#ifdef PNG_INCH_CONVERSIONS_SUPPORTED - /* code that uses the inch conversion APIs. */ -#endif - -This macro will only be defined if the inch conversion functions have been -compiled into libpng. The full set of macros, and whether or not support -has been compiled in, are available in the header file pnglibconf.h. -This header file is specific to the libpng build. Notice that prior to -1.5.0 the _SUPPORTED macros would always have the default definition unless -reset by pngusr.h or by explicit settings on the compiler command line. -These settings may produce compiler warnings or errors in 1.5.0 because -of macro redefinition. - -From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the -function) incorrectly returned a value of type png_uint_32. libpng 1.5.0 -is consistent with the implementation in 1.4.5 and 1.2.x (where the macro -did not exist.) - -Applications can now choose whether to use these macros or to call the -corresponding function by defining PNG_USE_READ_MACROS or -PNG_NO_USE_READ_MACROS before including png.h. Notice that this is -only supported from 1.5.0 -defining PNG_NO_USE_READ_MACROS prior to 1.5.0 -will lead to a link failure. - -Prior to libpng-1.5.4, the zlib compressor used the same set of parameters -when compressing the IDAT data and textual data such as zTXt and iCCP. -In libpng-1.5.4 we reinitialized the zlib stream for each type of data. -We added five png_set_text_*() functions for setting the parameters to -use with textual data. - -Prior to libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED -option was off by default, and slightly inaccurate scaling occurred. -This option can no longer be turned off, and the choice of accurate -or inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8() -API for accurate scaling or the old png_set_strip_16_to_8() API for simple -chopping. - -Prior to libpng-1.5.4, the png_set_user_limits() function could only be -used to reduce the width and height limits from the value of -PNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX, although this document said -that it could be used to override them. Now this function will reduce or -increase the limits. - -Starting in libpng-1.5.10, the user limits can be set en masse with the -configuration option PNG_SAFE_LIMITS_SUPPORTED. If this option is enabled, -a set of "safe" limits is applied in pngpriv.h. These can be overridden by -application calls to png_set_user_limits(), png_set_user_chunk_cache_max(), -and/or png_set_user_malloc_max() that increase or decrease the limits. Also, -in libpng-1.5.10 the default width and height limits were increased -from 1,000,000 to 0x7ffffff (i.e., made unlimited). Therefore, the -limits are now - default safe - png_user_width_max 0x7fffffff 1,000,000 - png_user_height_max 0x7fffffff 1,000,000 - png_user_chunk_cache_max 0 (unlimited) 128 - png_user_chunk_malloc_max 0 (unlimited) 8,000,000 - -B. Changes to the build and configuration of libpng - -Details of internal changes to the library code can be found in the CHANGES -file and in the GIT repository logs. These will be of no concern to the vast -majority of library users or builders; however, the few who configure libpng -to a non-default feature set may need to change how this is done. - -There should be no need for library builders to alter build scripts if -these use the distributed build support - configure or the makefiles - -however, users of the makefiles may care to update their build scripts -to build pnglibconf.h where the corresponding makefile does not do so. - -Building libpng with a non-default configuration has changed completely. -The old method using pngusr.h should still work correctly even though the -way pngusr.h is used in the build has been changed; however, library -builders will probably want to examine the changes to take advantage of -new capabilities and to simplify their build system. - -B.1 Specific changes to library configuration capabilities - -The library now supports a complete fixed point implementation and can -thus be used on systems that have no floating point support or very -limited or slow support. Previously gamma correction, an essential part -of complete PNG support, required reasonably fast floating point. - -As part of this the choice of internal implementation has been made -independent of the choice of fixed versus floating point APIs and all the -missing fixed point APIs have been implemented. - -The exact mechanism used to control attributes of API functions has -changed. A single set of operating system independent macro definitions -is used and operating system specific directives are defined in -pnglibconf.h - -As part of this the mechanism used to choose procedure call standards on -those systems that allow a choice has been changed. At present this only -affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems -running on Intel processors. As before, PNGAPI is defined where required -to control the exported API functions; however, two new macros, PNGCBAPI -and PNGCAPI, are used instead for callback functions (PNGCBAPI) and -(PNGCAPI) for functions that must match a C library prototype (currently -only png_longjmp_ptr, which must match the C longjmp function.) The new -approach is documented in pngconf.h - -Despite these changes, libpng 1.5.0 only supports the native C function -calling standard on those platforms tested so far (__cdecl on Microsoft -Windows). This is because the support requirements for alternative -calling conventions seem to no longer exist. Developers who find it -necessary to set PNG_API_RULE to 1 should advise the mailing list -(png-mng-implement) of this and library builders who use Openwatcom and -therefore set PNG_API_RULE to 2 should also contact the mailing list. - -A new test program, pngvalid, is provided in addition to pngtest. -pngvalid validates the arithmetic accuracy of the gamma correction -calculations and includes a number of validations of the file format. -A subset of the full range of tests is run when "make check" is done -(in the 'configure' build.) pngvalid also allows total allocated memory -usage to be evaluated and performs additional memory overwrite validation. - -Many changes to individual feature macros have been made. The following -are the changes most likely to be noticed by library builders who -configure libpng: - -1) All feature macros now have consistent naming: - -#define PNG_NO_feature turns the feature off -#define PNG_feature_SUPPORTED turns the feature on - -pnglibconf.h contains one line for each feature macro which is either: - -#define PNG_feature_SUPPORTED - -if the feature is supported or: - -/*#undef PNG_feature_SUPPORTED*/ - -if it is not. Library code consistently checks for the 'SUPPORTED' macro. -It does not, and libpng applications should not, check for the 'NO' macro -which will not normally be defined even if the feature is not supported. -The 'NO' macros are only used internally for setting or not setting the -corresponding 'SUPPORTED' macros. - -Compatibility with the old names is provided as follows: - -PNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED - -And the following definitions disable the corresponding feature: - -PNG_SETJMP_NOT_SUPPORTED disables SETJMP -PNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS -PNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV -PNG_WRITE_TRANSFORMS_NOT_SUPPORTED disables WRITE_TRANSFORMS -PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED disables READ_ANCILLARY_CHUNKS -PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED disables WRITE_ANCILLARY_CHUNKS - -Library builders should remove use of the above, inconsistent, names. - -2) Warning and error message formatting was previously conditional on -the STDIO feature. The library has been changed to use the -CONSOLE_IO feature instead. This means that if CONSOLE_IO is disabled -the library no longer uses the printf(3) functions, even though the -default read/write implementations use (FILE) style stdio.h functions. - -3) Three feature macros now control the fixed/floating point decisions: - -PNG_FLOATING_POINT_SUPPORTED enables the floating point APIs - -PNG_FIXED_POINT_SUPPORTED enables the fixed point APIs; however, in -practice these are normally required internally anyway (because the PNG -file format is fixed point), therefore in most cases PNG_NO_FIXED_POINT -merely stops the function from being exported. - -PNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating -point implementation or the fixed point one. Typically the fixed point -implementation is larger and slower than the floating point implementation -on a system that supports floating point; however, it may be faster on a -system which lacks floating point hardware and therefore uses a software -emulation. - -4) Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the -functions to read and write ints to be disabled independently of -PNG_USE_READ_MACROS, which allows libpng to be built with the functions -even though the default is to use the macros - this allows applications -to choose at app buildtime whether or not to use macros (previously -impossible because the functions weren't in the default build.) - -B.2 Changes to the configuration mechanism - -Prior to libpng-1.5.0 library builders who needed to configure libpng -had either to modify the exported pngconf.h header file to add system -specific configuration or had to write feature selection macros into -pngusr.h and cause this to be included into pngconf.h by defining -PNG_USER_CONFIG. The latter mechanism had the disadvantage that an -application built without PNG_USER_CONFIG defined would see the -unmodified, default, libpng API and thus would probably fail to link. - -These mechanisms still work in the configure build and in any makefile -build that builds pnglibconf.h, although the feature selection macros -have changed somewhat as described above. In 1.5.0, however, pngusr.h is -processed only once, when the exported header file pnglibconf.h is built. -pngconf.h no longer includes pngusr.h, therefore pngusr.h is ignored after the -build of pnglibconf.h and it is never included in an application build. - -The rarely used alternative of adding a list of feature macros to the -CFLAGS setting in the build also still works; however, the macros will be -copied to pnglibconf.h and this may produce macro redefinition warnings -when the individual C files are compiled. - -All configuration now only works if pnglibconf.h is built from -scripts/pnglibconf.dfa. This requires the program awk. Brian Kernighan -(the original author of awk) maintains C source code of that awk and this -and all known later implementations (often called by subtly different -names - nawk and gawk for example) are adequate to build pnglibconf.h. -The Sun Microsystems (now Oracle) program 'awk' is an earlier version -and does not work; this may also apply to other systems that have a -functioning awk called 'nawk'. - -Configuration options are now documented in scripts/pnglibconf.dfa. This -file also includes dependency information that ensures a configuration is -consistent; that is, if a feature is switched off dependent features are -also removed. As a recommended alternative to using feature macros in -pngusr.h a system builder may also define equivalent options in pngusr.dfa -(or, indeed, any file) and add that to the configuration by setting -DFA_XTRA to the file name. The makefiles in contrib/pngminim illustrate -how to do this, and a case where pngusr.h is still required. - -.SH XI. Detecting libpng - -The png_get_io_ptr() function has been present since libpng-0.88, has never -changed, and is unaffected by conditional compilation macros. It is the -best choice for use in configure scripts for detecting the presence of any -libpng version since 0.88. In an autoconf "configure.in" you could use - - AC_CHECK_LIB(png, png_get_io_ptr, ... - -.SH XII. Source code repository - -Since about February 2009, version 1.2.34, libpng has been under "git" source -control. The git repository was built from old libpng-x.y.z.tar.gz files -going back to version 0.70. You can access the git repository (read only) -at - - git://libpng.git.sourceforge.net/gitroot/libpng - -or you can browse it via "gitweb" at - - http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng - -Patches can be sent to glennrp at users.sourceforge.net or to -png-mng-implement at lists.sourceforge.net or you can upload them to -the libpng bug tracker at - - http://libpng.sourceforge.net - -We also accept patches built from the tar or zip distributions, and -simple verbal discriptions of bug fixes, reported either to the -SourceForge bug tracker, to the png-mng-implement at lists.sf.net -mailing list, or directly to glennrp. - -.SH XIII. Coding style - -Our coding style is similar to the "Allman" style, with curly -braces on separate lines: - - if (condition) - { - action; - } - - else if (another condition) - { - another action; - } - -The braces can be omitted from simple one-line actions: - - if (condition) - return (0); - -We use 3-space indentation, except for continued statements which -are usually indented the same as the first line of the statement -plus four more spaces. - -For macro definitions we use 2-space indentation, always leaving the "#" -in the first column. - - #ifndef PNG_NO_FEATURE - # ifndef PNG_FEATURE_SUPPORTED - # define PNG_FEATURE_SUPPORTED - # endif - #endif - -Comments appear with the leading "/*" at the same indentation as -the statement that follows the comment: - - /* Single-line comment */ - statement; - - /* This is a multiple-line - * comment. - */ - statement; - -Very short comments can be placed after the end of the statement -to which they pertain: - - statement; /* comment */ - -We don't use C++ style ("//") comments. We have, however, -used them in the past in some now-abandoned MMX assembler -code. - -Functions and their curly braces are not indented, and -exported functions are marked with PNGAPI: - - /* This is a public function that is visible to - * application programmers. It does thus-and-so. - */ - void PNGAPI - png_exported_function(png_ptr, png_info, foo) - { - body; - } - -The prototypes for all exported functions appear in png.h, -above the comment that says - - /* Maintainer: Put new public prototypes here ... */ - -We mark all non-exported functions with "/* PRIVATE */"": - - void /* PRIVATE */ - png_non_exported_function(png_ptr, png_info, foo) - { - body; - } - -The prototypes for non-exported functions (except for those in -pngtest) appear in -pngpriv.h -above the comment that says - - /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ - -To avoid polluting the global namespace, the names of all exported -functions and variables begin with "png_", and all publicly visible C -preprocessor macros begin with "PNG". We request that applications that -use libpng *not* begin any of their own symbols with either of these strings. - -We put a space after each comma and after each semicolon -in "for" statements, and we put spaces before and after each -C binary operator and after "for" or "while", and before -"?". We don't put a space between a typecast and the expression -being cast, nor do we put one between a function name and the -left parenthesis that follows it: - - for (i = 2; i > 0; --i) - y[i] = a(x) + (int)b; - -We prefer #ifdef and #ifndef to #if defined() and if !defined() -when there is only one macro being tested. - -We prefer to express integers that are used as bit masks in hex format, -with an even number of lower-case hex digits (e.g., 0x00, 0xff, 0x0100). - -We do not use the TAB character for indentation in the C sources. - -Lines do not exceed 80 characters. - -Other rules can be inferred by inspecting the libpng source. - -.SH XIV. Y2K Compliance in libpng - -September 27, 2012 - -Since the PNG Development group is an ad-hoc body, we can't make -an official declaration. - -This is your unofficial assurance that libpng from version 0.71 and -upward through 1.5.13 are Y2K compliant. It is my belief that earlier -versions were also Y2K compliant. - -Libpng only has two year fields. One is a 2-byte unsigned integer that -will hold years up to 65535. The other holds the date in text -format, and will hold years up to 9999. - -The integer is - "png_uint_16 year" in png_time_struct. - -The string is - "char time_buffer[29]" in png_struct. This will no -longer be used in libpng-1.6.x and will be removed from libpng-1.7.0. - -There are seven time-related functions: - - png_convert_to_rfc_1123() in png.c - (formerly png_convert_to_rfc_1152() in error) - png_convert_from_struct_tm() in pngwrite.c, called - in pngwrite.c - png_convert_from_time_t() in pngwrite.c - png_get_tIME() in pngget.c - png_handle_tIME() in pngrutil.c, called in pngread.c - png_set_tIME() in pngset.c - png_write_tIME() in pngwutil.c, called in pngwrite.c - -All appear to handle dates properly in a Y2K environment. The -png_convert_from_time_t() function calls gmtime() to convert from system -clock time, which returns (year - 1900), which we properly convert to -the full 4-digit year. There is a possibility that applications using -libpng are not passing 4-digit years into the png_convert_to_rfc_1123() -function, or that they are incorrectly passing only a 2-digit year -instead of "year - 1900" into the png_convert_from_struct_tm() function, -but this is not under our control. The libpng documentation has always -stated that it works with 4-digit years, and the APIs have been -documented as such. - -The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned -integer to hold the year, and can hold years as large as 65535. - -zlib, upon which libpng depends, is also Y2K compliant. It contains -no date-related code. - - - Glenn Randers-Pehrson - libpng maintainer - PNG Development Group - -.SH NOTE - -Note about libpng version numbers: - -Due to various miscommunications, unforeseen code incompatibilities -and occasional factors outside the authors' control, version numbering -on the library has not always been consistent and straightforward. -The following table summarizes matters since version 0.89c, which was -the first widely used release: - - source png.h png.h shared-lib - version string int version - ------- ------ ----- ---------- - 0.89c ("beta 3") 0.89 89 1.0.89 - 0.90 ("beta 4") 0.90 90 0.90 - 0.95 ("beta 5") 0.95 95 0.95 - 0.96 ("beta 6") 0.96 96 0.96 - 0.97b ("beta 7") 1.00.97 97 1.0.1 - 0.97c 0.97 97 2.0.97 - 0.98 0.98 98 2.0.98 - 0.99 0.99 98 2.0.99 - 0.99a-m 0.99 99 2.0.99 - 1.00 1.00 100 2.1.0 - 1.0.0 1.0.0 100 2.1.0 - 1.0.0 (from here on, the 100 2.1.0 - 1.0.1 png.h string is 10001 2.1.0 - 1.0.1a-e identical to the 10002 from here on, the - 1.0.2 source version) 10002 shared library is 2.V - 1.0.2a-b 10003 where V is the source - 1.0.1 10001 code version except as - 1.0.1a-e 10002 2.1.0.1a-e noted. - 1.0.2 10002 2.1.0.2 - 1.0.2a-b 10003 2.1.0.2a-b - 1.0.3 10003 2.1.0.3 - 1.0.3a-d 10004 2.1.0.3a-d - 1.0.4 10004 2.1.0.4 - 1.0.4a-f 10005 2.1.0.4a-f - 1.0.5 (+ 2 patches) 10005 2.1.0.5 - 1.0.5a-d 10006 2.1.0.5a-d - 1.0.5e-r 10100 2.1.0.5e-r - 1.0.5s-v 10006 2.1.0.5s-v - 1.0.6 (+ 3 patches) 10006 2.1.0.6 - 1.0.6d-g 10007 2.1.0.6d-g - 1.0.6h 10007 10.6h - 1.0.6i 10007 10.6i - 1.0.6j 10007 2.1.0.6j - 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14 - 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 - 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 - 1.0.7 1 10007 2.1.0.7 - 1.0.8beta1-4 1 10008 2.1.0.8beta1-4 - 1.0.8rc1 1 10008 2.1.0.8rc1 - 1.0.8 1 10008 2.1.0.8 - 1.0.9beta1-6 1 10009 2.1.0.9beta1-6 - 1.0.9rc1 1 10009 2.1.0.9rc1 - 1.0.9beta7-10 1 10009 2.1.0.9beta7-10 - 1.0.9rc2 1 10009 2.1.0.9rc2 - 1.0.9 1 10009 2.1.0.9 - 1.0.10beta1 1 10010 2.1.0.10beta1 - 1.0.10rc1 1 10010 2.1.0.10rc1 - 1.0.10 1 10010 2.1.0.10 - 1.0.11beta1-3 1 10011 2.1.0.11beta1-3 - 1.0.11rc1 1 10011 2.1.0.11rc1 - 1.0.11 1 10011 2.1.0.11 - 1.0.12beta1-2 2 10012 2.1.0.12beta1-2 - 1.0.12rc1 2 10012 2.1.0.12rc1 - 1.0.12 2 10012 2.1.0.12 - 1.1.0a-f - 10100 2.1.1.0a-f abandoned - 1.2.0beta1-2 2 10200 2.1.2.0beta1-2 - 1.2.0beta3-5 3 10200 3.1.2.0beta3-5 - 1.2.0rc1 3 10200 3.1.2.0rc1 - 1.2.0 3 10200 3.1.2.0 - 1.2.1beta-4 3 10201 3.1.2.1beta1-4 - 1.2.1rc1-2 3 10201 3.1.2.1rc1-2 - 1.2.1 3 10201 3.1.2.1 - 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6 - 1.0.13beta1 10 10013 10.so.0.1.0.13beta1 - 1.0.13rc1 10 10013 10.so.0.1.0.13rc1 - 1.2.2rc1 12 10202 12.so.0.1.2.2rc1 - 1.0.13 10 10013 10.so.0.1.0.13 - 1.2.2 12 10202 12.so.0.1.2.2 - 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6 - 1.2.3 12 10203 12.so.0.1.2.3 - 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3 - 1.2.4rc1 13 10204 12.so.0.1.2.4rc1 - 1.0.14 10 10014 10.so.0.1.0.14 - 1.2.4 13 10204 12.so.0.1.2.4 - 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2 - 1.0.15rc1 10 10015 10.so.0.1.0.15rc1 - 1.0.15 10 10015 10.so.0.1.0.15 - 1.2.5 13 10205 12.so.0.1.2.5 - 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4 - 1.2.6rc1-5 13 10206 12.so.0.1.2.6rc1-5 - 1.0.16 10 10016 10.so.0.1.0.16 - 1.2.6 13 10206 12.so.0.1.2.6 - 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2 - 1.0.17rc1 10 10017 12.so.0.1.0.17rc1 - 1.2.7rc1 13 10207 12.so.0.1.2.7rc1 - 1.0.17 10 10017 12.so.0.1.0.17 - 1.2.7 13 10207 12.so.0.1.2.7 - 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5 - 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5 - 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5 - 1.0.18 10 10018 12.so.0.1.0.18 - 1.2.8 13 10208 12.so.0.1.2.8 - 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3 - 1.2.9beta4-11 13 10209 12.so.0.9[.0] - 1.2.9rc1 13 10209 12.so.0.9[.0] - 1.2.9 13 10209 12.so.0.9[.0] - 1.2.10beta1-7 13 10210 12.so.0.10[.0] - 1.2.10rc1-2 13 10210 12.so.0.10[.0] - 1.2.10 13 10210 12.so.0.10[.0] - 1.4.0beta1-6 14 10400 14.so.0.0[.0] - 1.2.11beta1-4 13 10210 12.so.0.11[.0] - 1.4.0beta7-8 14 10400 14.so.0.0[.0] - 1.2.11 13 10211 12.so.0.11[.0] - 1.2.12 13 10212 12.so.0.12[.0] - 1.4.0beta9-14 14 10400 14.so.0.0[.0] - 1.2.13 13 10213 12.so.0.13[.0] - 1.4.0beta15-36 14 10400 14.so.0.0[.0] - 1.4.0beta37-87 14 10400 14.so.14.0[.0] - 1.4.0rc01 14 10400 14.so.14.0[.0] - 1.4.0beta88-109 14 10400 14.so.14.0[.0] - 1.4.0rc02-08 14 10400 14.so.14.0[.0] - 1.4.0 14 10400 14.so.14.0[.0] - 1.4.1beta01-03 14 10401 14.so.14.1[.0] - 1.4.1rc01 14 10401 14.so.14.1[.0] - 1.4.1beta04-12 14 10401 14.so.14.1[.0] - 1.4.1 14 10401 14.so.14.1[.0] - 1.4.2 14 10402 14.so.14.2[.0] - 1.4.3 14 10403 14.so.14.3[.0] - 1.4.4 14 10404 14.so.14.4[.0] - 1.5.0beta01-58 15 10500 15.so.15.0[.0] - 1.5.0rc01-07 15 10500 15.so.15.0[.0] - 1.5.0 15 10500 15.so.15.0[.0] - 1.5.1beta01-11 15 10501 15.so.15.1[.0] - 1.5.1rc01-02 15 10501 15.so.15.1[.0] - 1.5.1 15 10501 15.so.15.1[.0] - 1.5.2beta01-03 15 10502 15.so.15.2[.0] - 1.5.2rc01-03 15 10502 15.so.15.2[.0] - 1.5.2 15 10502 15.so.15.2[.0] - 1.5.3beta01-10 15 10503 15.so.15.3[.0] - 1.5.3rc01-02 15 10503 15.so.15.3[.0] - 1.5.3beta11 15 10503 15.so.15.3[.0] - 1.5.3 [omitted] - 1.5.4beta01-08 15 10504 15.so.15.4[.0] - 1.5.4rc01 15 10504 15.so.15.4[.0] - 1.5.4 15 10504 15.so.15.4[.0] - 1.5.5beta01-08 15 10505 15.so.15.5[.0] - 1.5.5rc01 15 10505 15.so.15.5[.0] - 1.5.5 15 10505 15.so.15.5[.0] - 1.5.6beta01-07 15 10506 15.so.15.6[.0] - 1.5.6rc01-03 15 10506 15.so.15.6[.0] - 1.5.6 15 10506 15.so.15.6[.0] - 1.5.7beta01-05 15 10507 15.so.15.7[.0] - 1.5.7rc01-03 15 10507 15.so.15.7[.0] - 1.5.7 15 10507 15.so.15.7[.0] - 1.5.8beta01 15 10508 15.so.15.8[.0] - 1.5.8rc01 15 10508 15.so.15.8[.0] - 1.5.8 15 10508 15.so.15.8[.0] - 1.5.9beta01-02 15 10509 15.so.15.9[.0] - 1.5.9rc01 15 10509 15.so.15.9[.0] - 1.5.9 15 10509 15.so.15.9[.0] - 1.5.10beta01-05 15 10510 15.so.15.10[.0] - 1.5.10 15 10510 15.so.15.10[.0] - 1.5.11beta01 15 10511 15.so.15.11[.0] - 1.5.11rc01-05 15 10511 15.so.15.11[.0] - 1.5.11 15 10511 15.so.15.11[.0] - 1.5.12 15 10512 15.so.15.12[.0] - 1.5.13beta01-02 15 10513 15.so.15.13[.0] - 1.5.13rc01 15 10513 15.so.15.13[.0] - 1.5.13 15 10513 15.so.15.13[.0] - -Henceforth the source version will match the shared-library minor -and patch numbers; the shared-library major version number will be -used for changes in backward compatibility, as it is intended. The -PNG_PNGLIB_VER macro, which is not used within libpng but is available -for applications, is an unsigned integer of the form xyyzz corresponding -to the source version x.y.z (leading zeros in y and z). Beta versions -were given the previous public release number plus a letter, until -version 1.0.6j; from then on they were given the upcoming public -release number plus "betaNN" or "rcN". - -.SH "SEE ALSO" -.BR "png"(5), " libpngpf"(3), " zlib"(3), " deflate"(5), " " and " zlib"(5) - -.LP -.IR libpng : -.IP -http://libpng.sourceforge.net (follow the [DOWNLOAD] link) -http://www.libpng.org/pub/png - -.LP -.IR zlib : -.IP -(generally) at the same location as -.I libpng -or at -.br -ftp://ftp.info-zip.org/pub/infozip/zlib - -.LP -.IR PNG specification: RFC 2083 -.IP -(generally) at the same location as -.I libpng -or at -.br -ftp://ds.internic.net/rfc/rfc2083.txt -.br -or (as a W3C Recommendation) at -.br -http://www.w3.org/TR/REC-png.html - -.LP -In the case of any inconsistency between the PNG specification -and this library, the specification takes precedence. - -.SH AUTHORS -This man page: Glenn Randers-Pehrson - - -The contributing authors would like to thank all those who helped -with testing, bug fixes, and patience. This wouldn't have been -possible without all of you. - -Thanks to Frank J. T. Wojcik for helping with the documentation. - -Libpng version 1.5.13 - September 27, 2012: -Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc. -Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net). - -Supported by the PNG development group -.br -png-mng-implement at lists.sf.net -(subscription required; visit -png-mng-implement at lists.sourceforge.net (subscription required; visit -https://lists.sourceforge.net/lists/listinfo/png-mng-implement -to subscribe). - -.SH COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: - -(This copy of the libpng notices is provided for your convenience. In case of -any discrepancy between this copy and the notices in the file png.h that is -included in the libpng distribution, the latter shall prevail.) - -If you modify libpng you may insert additional notices immediately following -this sentence. - -This code is released under the libpng license. - -libpng versions 1.2.6, August 15, 2004, through 1.5.13, September 27, 2012, are -Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are -distributed according to the same disclaimer and license as libpng-1.2.5 -with the following individual added to the list of Contributing Authors - - Cosmin Truta - -libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are -Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are -distributed according to the same disclaimer and license as libpng-1.0.6 -with the following individuals added to the list of Contributing Authors - - Simon-Pierre Cadieux - Eric S. Raymond - Gilles Vollant - -and with the following additions to the disclaimer: - - There is no warranty against interference with your - enjoyment of the library or against infringement. - There is no warranty that our efforts or the library - will fulfill any of your particular purposes or needs. - This library is provided with all faults, and the entire - risk of satisfactory quality, performance, accuracy, and - effort is with the user. - -libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are -Copyright (c) 1998, 1999 Glenn Randers-Pehrson -Distributed according to the same disclaimer and license as libpng-0.96, -with the following individuals added to the list of Contributing Authors: - - Tom Lane - Glenn Randers-Pehrson - Willem van Schaik - -libpng versions 0.89, June 1996, through 0.96, May 1997, are -Copyright (c) 1996, 1997 Andreas Dilger -Distributed according to the same disclaimer and license as libpng-0.88, -with the following individuals added to the list of Contributing Authors: - - John Bowler - Kevin Bracey - Sam Bushell - Magnus Holmgren - Greg Roelofs - Tom Tanner - -libpng versions 0.5, May 1995, through 0.88, January 1996, are -Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. - -For the purposes of this copyright and license, "Contributing Authors" -is defined as the following set of individuals: - - Andreas Dilger - Dave Martindale - Guy Eric Schalnat - Paul Schmidt - Tim Wegner - -The PNG Reference Library is supplied "AS IS". The Contributing Authors -and Group 42, Inc. disclaim all warranties, expressed or implied, -including, without limitation, the warranties of merchantability and of -fitness for any purpose. The Contributing Authors and Group 42, Inc. -assume no liability for direct, indirect, incidental, special, exemplary, -or consequential damages, which may result from the use of the PNG -Reference Library, even if advised of the possibility of such damage. - -Permission is hereby granted to use, copy, modify, and distribute this -source code, or portions hereof, for any purpose, without fee, subject -to the following restrictions: - -1. The origin of this source code must not be misrepresented. - -2. Altered versions must be plainly marked as such and - must not be misrepresented as being the original source. - -3. This Copyright notice may not be removed or altered from - any source or altered source distribution. - -The Contributing Authors and Group 42, Inc. specifically permit, without -fee, and encourage the use of this source code as a component to -supporting the PNG file format in commercial products. If you use this -source code in a product, acknowledgment is not required but would be -appreciated. - - -A "png_get_copyright" function is available, for convenient use in "about" -boxes and the like: - - printf("%s",png_get_copyright(NULL)); - -Also, the PNG logo (in PNG format, of course) is supplied in the -files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). - -Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a -certification mark of the Open Source Initiative. - -Glenn Randers-Pehrson -glennrp at users.sourceforge.net -September 27, 2012 - -.\" end of man page - +.TH LIBPNG 3 "September 27, 2012" +.SH NAME +libpng \- Portable Network Graphics (PNG) Reference Library 1.5.13 +.SH SYNOPSIS +\fI\fB + +\fB#include \fP + +\fI\fB + +\fBpng_uint_32 png_access_version_number \fI(void\fP\fB);\fP + +\fI\fB + +\fBvoid png_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP + +\fI\fB + +\fBvoid png_build_grayscale_palette (int \fP\fIbit_depth\fP\fB, png_colorp \fIpalette\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_calloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP + +\fI\fB + +\fBvoid png_chunk_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP + +\fI\fB + +\fBvoid png_chunk_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP + +\fI\fB + +\fBvoid png_chunk_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP + +\fI\fB + +\fBvoid png_convert_from_struct_tm (png_timep \fP\fIptime\fP\fB, struct tm FAR * \fIttime\fP\fB);\fP + +\fI\fB + +\fBvoid png_convert_from_time_t (png_timep \fP\fIptime\fP\fB, time_t \fIttime\fP\fB);\fP + +\fI\fB + +\fBpng_charp png_convert_to_rfc1123 (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fIptime\fP\fB);\fP + +\fI\fB + +\fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_structp png_create_read_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP + +\fI\fB + +\fBpng_structp png_create_read_struct_2 (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP + +\fI\fB + +\fBpng_structp png_create_write_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP + +\fI\fB + +\fBpng_structp png_create_write_struct_2 (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_data_freer (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIfreer\fP\fB, png_uint_32 \fImask)\fP\fB);\fP + +\fI\fB + +\fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_destroy_read_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fP\fIinfo_ptr_ptr\fP\fB, png_infopp \fIend_info_ptr_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_err (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP + +\fI\fB + +\fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_free_default (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_free_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_bit_depth (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_bKGD (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fI*background\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_channels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_cHRM (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*white_x\fP\fB, double \fP\fI*white_y\fP\fB, double \fP\fI*red_x\fP\fB, double \fP\fI*red_y\fP\fB, double \fP\fI*green_x\fP\fB, double \fP\fI*green_y\fP\fB, double \fP\fI*blue_x\fP\fB, double \fI*blue_y\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_cHRM_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*white_x\fP\fB, png_uint_32 \fP\fI*white_y\fP\fB, png_uint_32 \fP\fI*red_x\fP\fB, png_uint_32 \fP\fI*red_y\fP\fB, png_uint_32 \fP\fI*green_x\fP\fB, png_uint_32 \fP\fI*green_y\fP\fB, png_uint_32 \fP\fI*blue_x\fP\fB, png_uint_32 \fI*blue_y\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_cHRM_XYZ (png_structp \fIpng_ptr, + +\fBpng_const_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*red_X\fP\fB, double \fP\fI*red_Y\fP\fB, double \fI*red_Z, + +\fBdouble \fP\fI*green_X\fP\fB, double \fP\fI*green_Y\fP\fB, double \fP\fI*green_Z\fP\fB, double \fI*blue_X, + +\fBdouble \fP\fI*blue_Y\fP\fB, double \fI*blue_Z\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_cHRM_XYZ_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_fixed_point \fP\fI*int_red_X\fP\fB, png_fixed_point \fP\fI*int_red_Y\fP\fB, png_fixed_point \fP\fI*int_red_Z\fP\fB, png_fixed_point \fP\fI*int_green_X\fP\fB, png_fixed_point \fP\fI*int_green_Y\fP\fB, png_fixed_point \fP\fI*int_green_Z\fP\fB, png_fixed_point \fP\fI*int_blue_X\fP\fB, png_fixed_point \fP\fI*int_blue_Y\fP\fB, png_fixed_point \fI*int_blue_Z\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_chunk_cache_max (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_alloc_size_t png_get_chunk_malloc_max (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_color_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_compression_buffer_size (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_compression_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_copyright (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_current_row_number \fI(png_const_structp\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_current_pass_number \fI(png_const_structp\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_get_error_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_filter_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_gAMA (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, double \fI*file_gamma\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_gAMA_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fI*int_file_gamma\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_header_ver (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_header_version (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_hIST (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fI*hist\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_iCCP (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_charpp \fP\fIname\fP\fB, int \fP\fI*compression_type\fP\fB, png_bytepp \fP\fIprofile\fP\fB, png_uint_32 \fI*proflen\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*width\fP\fB, png_uint_32 \fP\fI*height\fP\fB, int \fP\fI*bit_depth\fP\fB, int \fP\fI*color_type\fP\fB, int \fP\fI*interlace_type\fP\fB, int \fP\fI*compression_type\fP\fB, int \fI*filter_type\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_image_height (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_image_width (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_interlace_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_const_bytep png_get_io_chunk_name (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_io_chunk_type (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_io_state (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_libpng_ver (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_get_mem_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_oFFs (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*offset_x\fP\fB, png_uint_32 \fP\fI*offset_y\fP\fB, int \fI*unit_type\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_pCAL (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fI*purpose\fP\fB, png_int_32 \fP\fI*X0\fP\fB, png_int_32 \fP\fI*X1\fP\fB, int \fP\fI*type\fP\fB, int \fP\fI*nparams\fP\fB, png_charp \fP\fI*units\fP\fB, png_charpp \fI*params\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_pHYs (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP + +\fI\fB + +\fBfloat png_get_pixel_aspect_ratio (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_pHYs_dpi (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP + +\fI\fB + +\fBpng_fixed_point png_get_pixel_aspect_ratio_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_get_progressive_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_PLTE (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fI*palette\fP\fB, int \fI*num_palette\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_rgb_to_gray_status (png_const_structp \fIpng_ptr) + +\fBpng_uint_32 png_get_rowbytes (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_bytepp png_get_rows (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_sBIT (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP + +\fI\fB + +\fBvoid png_get_sCAL (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, double* \fP\fIwidth\fP\fB, double* \fIheight\fP\fB);\fP + +\fI\fB + +\fBvoid png_get_sCAL_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, png_fixed_pointp \fP\fIwidth\fP\fB, png_fixed_pointp \fIheight\fP\fB);\fP + +\fI\fB + +\fBvoid png_get_sCAL_s (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, png_charpp \fP\fIwidth\fP\fB, png_charpp \fIheight\fP\fB);\fP + +\fI\fB + +\fBpng_bytep png_get_signature (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_sPLT (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fI*splt_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_sRGB (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int \fI*file_srgb_intent\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_text (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fI*text_ptr\fP\fB, int \fI*num_text\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_tIME (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fI*mod_time\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_tRNS (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fI*trans_alpha\fP\fB, int \fP\fI*num_trans\fP\fB, png_color_16p \fI*trans_color\fP\fB);\fP + +\fI\fB + +\fB/* This function is really an inline macro. \fI*/ + +\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_uint_31 (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIbuf\fP\fB);\fP + +\fI\fB + +\fB/* This function is really an inline macro. \fI*/ + +\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_unknown_chunks (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkpp \fIunknowns\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_get_user_chunk_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_user_height_max (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_get_user_transform_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_user_width_max (png_const_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_valid (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIflag\fP\fB);\fP + +\fI\fB + +\fBfloat png_get_x_offset_inches (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_fixed_point png_get_x_offset_inches_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_int_32 png_get_x_offset_microns (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_int_32 png_get_x_offset_pixels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_x_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_x_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBfloat png_get_y_offset_inches (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_fixed_point png_get_y_offset_inches_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_int_32 png_get_y_offset_microns (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_int_32 png_get_y_offset_pixels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_y_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_y_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP + +\fI\fB + +\fBvoid png_info_init_3 (png_infopp \fP\fIinfo_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP + +\fI\fB + +\fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP + +\fI\fB + +\fBvoid png_longjmp (png_structp \fP\fIpng_ptr\fP\fB, int \fIval\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_malloc_default (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_malloc_warn (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_permit_mng_features (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fImng_features_permitted\fP\fB);\fP + +\fI\fB + +\fBvoid png_process_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_size\fP\fB);\fP + +\fI\fB + +\fBpng_size_t png_process_data_pause \fP\fI(png_structp\fP\fB, int \fIsave\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_process_data_skip \fI(png_structp\fP\fB);\fP + +\fI\fB + +\fBvoid png_progressive_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIold_row\fP\fB, png_bytep \fInew_row\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_bytepp \fP\fIdisplay_row\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBint png_reset_zstream (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP + +\fI\fB + +\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP + +\fI\fB + +\fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_alpha_mode (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImode\fP\fB, double \fIoutput_gamma\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_alpha_mode_fixed (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImode\fP\fB, png_fixed_point \fIoutput_gamma\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_background (png_structp \fP\fIpng_ptr\fP\fB, png_color_16p \fP\fIbackground_color\fP\fB, int \fP\fIbackground_gamma_code\fP\fB, int \fP\fIneed_expand\fP\fB, double \fIbackground_gamma\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_background_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_color_16p \fP\fIbackground_color\fP\fB, int \fP\fIbackground_gamma_code\fP\fB, int \fP\fIneed_expand\fP\fB, png_uint_32 \fIbackground_gamma\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_benign_errors (png_structp \fP\fIpng_ptr\fP\fB, int \fIallowed\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fIbackground\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_check_for_invalid_index(png_structrp \fP\fIpng_ptr\fP\fB, int \fIallowed\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fIwhite_x\fP\fB, double \fP\fIwhite_y\fP\fB, double \fP\fIred_x\fP\fB, double \fP\fIred_y\fP\fB, double \fP\fIgreen_x\fP\fB, double \fP\fIgreen_y\fP\fB, double \fP\fIblue_x\fP\fB, double \fIblue_y\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwhite_x\fP\fB, png_uint_32 \fP\fIwhite_y\fP\fB, png_uint_32 \fP\fIred_x\fP\fB, png_uint_32 \fP\fIred_y\fP\fB, png_uint_32 \fP\fIgreen_x\fP\fB, png_uint_32 \fP\fIgreen_y\fP\fB, png_uint_32 \fP\fIblue_x\fP\fB, png_uint_32 \fIblue_y\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_cHRM_XYZ (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fIred_X\fP\fB, double \fP\fIred_Y\fP\fB, double \fP\fIred_Z\fP\fB, double \fP\fIgreen_X\fP\fB, double \fIgreen_Y, + +\fBdouble \fP\fIgreen_Z\fP\fB, double \fP\fIblue_X\fP\fB, double \fP\fIblue_Y\fP\fB, double \fIblue_Z\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_cHRM_XYZ_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_fixed_point \fP\fIint_red_X\fP\fB, png_fixed_point \fP\fIint_red_Y\fP\fB, png_fixed_point \fP\fIint_red_Z\fP\fB, png_fixed_point \fP\fIint_green_X\fP\fB, png_fixed_point \fP\fIint_green_Y\fP\fB, png_fixed_point \fP\fIint_green_Z\fP\fB, png_fixed_point \fP\fIint_blue_X\fP\fB, png_fixed_point \fP\fIint_blue_Y\fP\fB, png_fixed_point \fIint_blue_Z\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_chunk_cache_max (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIuser_chunk_cache_max\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_crc_action (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcrit_action\fP\fB, int \fIancil_action\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_error_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarning_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_expand_16 (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_expand_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_filler (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_filter (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImethod\fP\fB, int \fIfilters\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_filter_heuristics (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIheuristic_method\fP\fB, int \fP\fInum_weights\fP\fB, png_doublep \fP\fIfilter_weights\fP\fB, png_doublep \fIfilter_costs\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_filter_heuristics_fixed (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIheuristic_method\fP\fB, int \fP\fInum_weights\fP\fB, png_fixed_point_p \fP\fIfilter_weights\fP\fB, png_fixed_point_p \fIfilter_costs\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_gamma (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIscreen_gamma\fP\fB, double \fIdefault_file_gamma\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_gamma_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIscreen_gamma\fP\fB, png_uint_32 \fIdefault_file_gamma\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIfile_gamma\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fIhist\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_const_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_const_bytep \fP\fIprofile\fP\fB, png_uint_32 \fIproflen\fP\fB);\fP + +\fI\fB + +\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIinterlace_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fIfilter_type\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_keep_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIkeep\fP\fB, png_bytep \fP\fIchunk_list\fP\fB, int \fInum_chunks\fP\fB);\fP + +\fI\fB + +\fBjmp_buf* png_set_longjmp_fn (png_structp \fP\fIpng_ptr\fP\fB, png_longjmp_ptr \fP\fIlongjmp_fn\fP\fB, size_t \fIjmp_buf_size\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_chunk_malloc_max (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIuser_chunk_cache_max\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_compression_buffer_size (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_mem_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIoffset_x\fP\fB, png_uint_32 \fP\fIoffset_y\fP\fB, int \fIunit_type\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_palette_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIpurpose\fP\fB, png_int_32 \fP\fIX0\fP\fB, png_int_32 \fP\fIX1\fP\fB, int \fP\fItype\fP\fB, int \fP\fInparams\fP\fB, png_charp \fP\fIunits\fP\fB, png_charpp \fIparams\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIres_x\fP\fB, png_uint_32 \fP\fIres_y\fP\fB, int \fIunit_type\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_progressive_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIprogressive_ptr\fP\fB, png_progressive_info_ptr \fP\fIinfo_fn\fP\fB, png_progressive_row_ptr \fP\fIrow_fn\fP\fB, png_progressive_end_ptr \fIend_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fInum_palette\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_quantize (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fP\fInum_palette\fP\fB, int \fP\fImaximum_colors\fP\fB, png_uint_16p \fP\fIhistogram\fP\fB, int \fIfull_quantize\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fIread_data_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_read_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_read_status_ptr \fIread_row_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_read_user_chunk_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_chunk_ptr\fP\fB, png_user_chunk_ptr \fIread_user_chunk_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_read_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIread_user_transform_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_rgb_to_gray (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIerror_action\fP\fB, double \fP\fIred\fP\fB, double \fIgreen\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_rgb_to_gray_fixed (png_structp \fP\fIpng_ptr\fP\fB, int error_action png_uint_32 \fP\fIred\fP\fB, png_uint_32 \fIgreen\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytepp \fIrow_pointers\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fIsig_bit\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_sCAL_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, png_fixed_point \fP\fIwidth\fP\fB, png_fixed_point \fIheight\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_sCAL_s (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, png_charp \fP\fIwidth\fP\fB, png_charp \fIheight\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_scale_16 (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_shift (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fItrue_bits\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_sig_bytes (png_structp \fP\fIpng_ptr\fP\fB, int \fInum_bytes\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fP\fIsplt_ptr\fP\fB, int \fInum_spalettes\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIsrgb_intent\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_sRGB_gAMA_and_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIsrgb_intent\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_strip_error_numbers (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIstrip_mode\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fItext_ptr\fP\fB, int \fInum_text\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_text_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_text_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_text_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_text_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP + +\fI\fB + +\fBvoid \fP\fIpng_set_text_compression_method\fP\fB, (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod)\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fImod_time\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fItrans_alpha\fP\fB, int \fP\fInum_trans\fP\fB, png_color_16p \fItrans_color\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_tRNS_to_alpha (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_set_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkp \fP\fIunknowns\fP\fB, int \fP\fInum\fP\fB, int \fIlocation\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_unknown_chunk_location (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIchunk\fP\fB, int \fIlocation\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_user_limits (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIuser_width_max\fP\fB, png_uint_32 \fIuser_height_max\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_user_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_transform_ptr\fP\fB, int \fP\fIuser_transform_depth\fP\fB, int \fIuser_transform_channels\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_write_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fP\fIwrite_data_fn\fP\fB, png_flush_ptr \fIoutput_flush_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_write_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_write_status_ptr \fIwrite_row_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_write_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIwrite_user_transform_fn\fP\fB);\fP + +\fI\fB + +\fBint png_sig_cmp (png_bytep \fP\fIsig\fP\fB, png_size_t \fP\fIstart\fP\fB, png_size_t \fInum_to_check\fP\fB);\fP + +\fI\fB + +\fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_chunk (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_chunk_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_chunk_start (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +.SH DESCRIPTION +The +.I libpng +library supports encoding, decoding, and various manipulations of +the Portable Network Graphics (PNG) format image files. It uses the +.IR zlib(3) +compression library. +Following is a copy of the libpng-manual.txt file that accompanies libpng. +.SH LIBPNG.TXT +Libpng-manual.txt - A description on how to use and modify libpng + + libpng version 1.5.13 - September 27, 2012 + Updated and distributed by Glenn Randers-Pehrson + + Copyright (c) 1998-2012 Glenn Randers-Pehrson + + This document is released under the libpng license. + For conditions of distribution and use, see the disclaimer + and license in png.h + + Based on: + + libpng versions 0.97, January 1998, through 1.5.13 - September 27, 2012 + Updated and distributed by Glenn Randers-Pehrson + Copyright (c) 1998-2012 Glenn Randers-Pehrson + + libpng 1.0 beta 6 version 0.96 May 28, 1997 + Updated and distributed by Andreas Dilger + Copyright (c) 1996, 1997 Andreas Dilger + + libpng 1.0 beta 2 - version 0.88 January 26, 1996 + For conditions of distribution and use, see copyright + notice in png.h. Copyright (c) 1995, 1996 Guy Eric + Schalnat, Group 42, Inc. + + Updated/rewritten per request in the libpng FAQ + Copyright (c) 1995, 1996 Frank J. T. Wojcik + December 18, 1995 & January 20, 1996 + +.SH I. Introduction + +This file describes how to use and modify the PNG reference library +(known as libpng) for your own use. There are five sections to this +file: introduction, structures, reading, writing, and modification and +configuration notes for various special platforms. In addition to this +file, example.c is a good starting point for using the library, as +it is heavily commented and should include everything most people +will need. We assume that libpng is already installed; see the +INSTALL file for instructions on how to install libpng. + +For examples of libpng usage, see the files "example.c", "pngtest.c", +and the files in the "contrib" directory, all of which are included in +the libpng distribution. + +Libpng was written as a companion to the PNG specification, as a way +of reducing the amount of time and effort it takes to support the PNG +file format in application programs. + +The PNG specification (second edition), November 2003, is available as +a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at +. It is technically equivalent +to the PNG specification (second edition) but has some additional material. + +The PNG-1.0 specification is available +as RFC 2083 and as a +W3C Recommendation . + +Some additional chunks are described in the special-purpose public chunks +documents at . + +Other information +about PNG, and the latest version of libpng, can be found at the PNG home +page, . + +Most users will not have to modify the library significantly; advanced +users may want to modify it more. All attempts were made to make it as +complete as possible, while keeping the code easy to understand. +Currently, this library only supports C. Support for other languages +is being considered. + +Libpng has been designed to handle multiple sessions at one time, +to be easily modifiable, to be portable to the vast majority of +machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy +to use. The ultimate goal of libpng is to promote the acceptance of +the PNG file format in whatever way possible. While there is still +work to be done (see the TODO file), libpng should cover the +majority of the needs of its users. + +Libpng uses zlib for its compression and decompression of PNG files. +Further information about zlib, and the latest version of zlib, can +be found at the zlib home page, . +The zlib compression utility is a general purpose utility that is +useful for more than PNG files, and can be used without libpng. +See the documentation delivered with zlib for more details. +You can usually find the source files for the zlib utility wherever you +find the libpng source files. + +Libpng is thread safe, provided the threads are using different +instances of the structures. Each thread should have its own +png_struct and png_info instances, and thus its own image. +Libpng does not protect itself against two threads using the +same instance of a structure. + +.SH II. Structures + +There are two main structures that are important to libpng, png_struct +and png_info. Both are internal structures that are no longer exposed +in the libpng interface (as of libpng 1.5.0). + +The png_info structure is designed to provide information about the +PNG file. At one time, the fields of png_info were intended to be +directly accessible to the user. However, this tended to cause problems +with applications using dynamically loaded libraries, and as a result +a set of interface functions for png_info (the png_get_*() and png_set_*() +functions) was developed, and direct access to the png_info fields was +deprecated.. + +The png_struct structure is the object used by the library to decode a +single image. As of 1.5.0 this structure is also not exposed. + +Almost all libpng APIs require a pointer to a png_struct as the first argument. +Many (in particular the png_set and png_get APIs) also require a pointer +to png_info as the second argument. Some application visible macros +defined in png.h designed for basic data access (reading and writing +integers in the PNG format) don't take a png_info pointer, but it's almost +always safe to assume that a (png_struct*) has to be passed to call an API +function. + +You can have more than one png_info structure associated with an image, +as illustrated in pngtest.c, one for information valid prior to the +IDAT chunks and another (called "end_info" below) for things after them. + +The png.h header file is an invaluable reference for programming with libpng. +And while I'm on the topic, make sure you include the libpng header file: + +#include + +and also (as of libpng-1.5.0) the zlib header file, if you need it: + +#include + +.SS Types + +The png.h header file defines a number of integral types used by the +APIs. Most of these are fairly obvious; for example types corresponding +to integers of particular sizes and types for passing color values. + +One exception is how non-integral numbers are handled. For application +convenience most APIs that take such numbers have C (double) arguments; +however, internally PNG, and libpng, use 32 bit signed integers and encode +the value by multiplying by 100,000. As of libpng 1.5.0 a convenience +macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point) +which is simply (png_int_32). + +All APIs that take (double) arguments also have a matching API that +takes the corresponding fixed point integer arguments. The fixed point +API has the same name as the floating point one with "_fixed" appended. +The actual range of values permitted in the APIs is frequently less than +the full range of (png_fixed_point) (-21474 to +21474). When APIs require +a non-negative argument the type is recorded as png_uint_32 above. Consult +the header file and the text below for more information. + +Special care must be take with sCAL chunk handling because the chunk itself +uses non-integral values encoded as strings containing decimal floating point +numbers. See the comments in the header file. + +.SS Configuration + +The main header file function declarations are frequently protected by C +preprocessing directives of the form: + + #ifdef PNG_feature_SUPPORTED + declare-function + #endif + ... + #ifdef PNG_feature_SUPPORTED + use-function + #endif + +The library can be built without support for these APIs, although a +standard build will have all implemented APIs. Application programs +should check the feature macros before using an API for maximum +portability. From libpng 1.5.0 the feature macros set during the build +of libpng are recorded in the header file "pnglibconf.h" and this file +is always included by png.h. + +If you don't need to change the library configuration from the default, skip to +the next section ("Reading"). + +Notice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all +of the build project files in the 'projects' directory simply copy +scripts/pnglibconf.h.prebuilt to pnglibconf.h. This means that these build +systems do not permit easy auto-configuration of the library - they only +support the default configuration. + +The easiest way to make minor changes to the libpng configuration when +auto-configuration is supported is to add definitions to the command line +using (typically) CPPFLAGS. For example: + +CPPFLAGS=-DPNG_NO_FLOATING_ARITHMETIC + +will change the internal libpng math implementation for gamma correction and +other arithmetic calculations to fixed point, avoiding the need for fast +floating point support. The result can be seen in the generated pnglibconf.h - +make sure it contains the changed feature macro setting. + +If you need to make more extensive configuration changes - more than one or two +feature macro settings - you can either add -DPNG_USER_CONFIG to the build +command line and put a list of feature macro settings in pngusr.h or you can set +DFA_XTRA (a makefile variable) to a file containing the same information in the +form of 'option' settings. + +A. Changing pnglibconf.h + +A variety of methods exist to build libpng. Not all of these support +reconfiguration of pnglibconf.h. To reconfigure pnglibconf.h it must either be +rebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand. + +Hand editing is achieved by copying scripts/pnglibconf.h.prebuilt to +pnglibconf.h and changing the lines defining the supported features, paying +very close attention to the 'option' information in scripts/pnglibconf.dfa +that describes those features and their requirements. This is easy to get +wrong. + +B. Configuration using DFA_XTRA + +Rebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later +variant such as 'nawk' or 'gawk', is available. The configure build will +automatically find an appropriate awk and build pnglibconf.h. +The scripts/pnglibconf.mak file contains a set of make rules for doing the +same thing if configure is not used, and many of the makefiles in the scripts +directory use this approach. + +When rebuilding simply write a new file containing changed options and set +DFA_XTRA to the name of this file. This causes the build to append the new file +to the end of scripts/pnglibconf.dfa. The pngusr.dfa file should contain lines +of the following forms: + +everything = off + +This turns all optional features off. Include it at the start of pngusr.dfa to +make it easier to build a minimal configuration. You will need to turn at least +some features on afterward to enable either reading or writing code, or both. + +option feature on +option feature off + +Enable or disable a single feature. This will automatically enable other +features required by a feature that is turned on or disable other features that +require a feature which is turned off. Conflicting settings will cause an error +message to be emitted by awk. + +setting feature default value + +Changes the default value of setting 'feature' to 'value'. There are a small +number of settings listed at the top of pnglibconf.h, they are documented in the +source code. Most of these values have performance implications for the library +but most of them have no visible effect on the API. Some can also be overridden +from the API. + +This method of building a customized pnglibconf.h is illustrated in +contrib/pngminim/*. See the "$(PNGCONF):" target in the makefile and +pngusr.dfa in these directories. + +C. Configuration using PNG_USR_CONFIG + +If -DPNG_USR_CONFIG is added to the CFLAGS when pnglibconf.h is built the file +pngusr.h will automatically be included before the options in +scripts/pnglibconf.dfa are processed. Your pngusr.h file should contain only +macro definitions turning features on or off or setting settings. + +Apart from the global setting "everything = off" all the options listed above +can be set using macros in pngusr.h: + +#define PNG_feature_SUPPORTED + +is equivalent to: + +option feature on + +#define PNG_NO_feature + +is equivalent to: + +option feature off + +#define PNG_feature value + +is equivalent to: + +setting feature default value + +Notice that in both cases, pngusr.dfa and pngusr.h, the contents of the +pngusr file you supply override the contents of scripts/pnglibconf.dfa + +If confusing or incomprehensible behavior results it is possible to +examine the intermediate file pnglibconf.dfn to find the full set of +dependency information for each setting and option. Simply locate the +feature in the file and read the C comments that precede it. + +This method is also illustrated in the contrib/pngminim/* makefiles and +pngusr.h. + +.SH III. Reading + +We'll now walk you through the possible functions to call when reading +in a PNG file sequentially, briefly explaining the syntax and purpose +of each one. See example.c and png.h for more detail. While +progressive reading is covered in the next section, you will still +need some of the functions discussed in this section to read a PNG +file. + +.SS Setup + +You will want to do the I/O initialization(*) before you get into libpng, +so if it doesn't work, you don't have much to undo. Of course, you +will also want to insure that you are, in fact, dealing with a PNG +file. Libpng provides a simple check to see if a file is a PNG file. +To use it, pass in the first 1 to 8 bytes of the file to the function +png_sig_cmp(), and it will return 0 (false) if the bytes match the +corresponding bytes of the PNG signature, or nonzero (true) otherwise. +Of course, the more bytes you pass in, the greater the accuracy of the +prediction. + +If you are intending to keep the file pointer open for use in libpng, +you must ensure you don't read more than 8 bytes from the beginning +of the file, and you also have to make a call to png_set_sig_bytes_read() +with the number of bytes you read from the beginning. Libpng will +then only check the bytes (if any) that your program didn't read. + +(*): If you are not using the standard I/O functions, you will need +to replace them with custom functions. See the discussion under +Customizing libpng. + + + FILE *fp = fopen(file_name, "rb"); + if (!fp) + { + return (ERROR); + } + + fread(header, 1, number, fp); + is_png = !png_sig_cmp(header, 0, number); + + if (!is_png) + { + return (NOT_PNG); + } + + +Next, png_struct and png_info need to be allocated and initialized. In +order to ensure that the size of these structures is correct even with a +dynamically linked libpng, there are functions to initialize and +allocate the structures. We also pass the library version, optional +pointers to error handling functions, and a pointer to a data struct for +use by the error functions, if necessary (the pointer and functions can +be NULL if the default error handlers are to be used). See the section +on Changes to Libpng below regarding the old initialization functions. +The structure allocation functions quietly return NULL if they fail to +create the structure, so your application should check for that. + + png_structp png_ptr = png_create_read_struct + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn); + + if (!png_ptr) + return (ERROR); + + png_infop info_ptr = png_create_info_struct(png_ptr); + + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr, + (png_infopp)NULL, (png_infopp)NULL); + return (ERROR); + } + +If you want to use your own memory allocation routines, +use a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use +png_create_read_struct_2() instead of png_create_read_struct(): + + png_structp png_ptr = png_create_read_struct_2 + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn, (png_voidp) + user_mem_ptr, user_malloc_fn, user_free_fn); + +The error handling routines passed to png_create_read_struct() +and the memory alloc/free routines passed to png_create_struct_2() +are only necessary if you are not using the libpng supplied error +handling and memory alloc/free functions. + +When libpng encounters an error, it expects to longjmp back +to your routine. Therefore, you will need to call setjmp and pass +your png_jmpbuf(png_ptr). If you read the file from different +routines, you will need to update the longjmp buffer every time you enter +a new routine that will call a png_*() function. + +See your documentation of setjmp/longjmp for your compiler for more +information on setjmp/longjmp. See the discussion on libpng error +handling in the Customizing Libpng section below for more information +on the libpng error handling. If an error occurs, and libpng longjmp's +back to your setjmp, you will want to call png_destroy_read_struct() to +free any memory. + + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + &end_info); + fclose(fp); + return (ERROR); + } + +Pass (png_infopp)NULL instead of &end_info if you didn't create +an end_info structure. + +If you would rather avoid the complexity of setjmp/longjmp issues, +you can compile libpng with PNG_NO_SETJMP, in which case +errors will result in a call to PNG_ABORT() which defaults to abort(). + +You can #define PNG_ABORT() to a function that does something +more useful than abort(), as long as your function does not +return. + +Now you need to set up the input code. The default for libpng is to +use the C function fread(). If you use this, you will need to pass a +valid FILE * in the function png_init_io(). Be sure that the file is +opened in binary mode. If you wish to handle reading data in another +way, you need not call the png_init_io() function, but you must then +implement the libpng I/O methods discussed in the Customizing Libpng +section below. + + png_init_io(png_ptr, fp); + +If you had previously opened the file and read any of the signature from +the beginning in order to see if this was a PNG file, you need to let +libpng know that there are some bytes missing from the start of the file. + + png_set_sig_bytes(png_ptr, number); + +You can change the zlib compression buffer size to be used while +reading compressed data with + + png_set_compression_buffer_size(png_ptr, buffer_size); + +where the default size is 8192 bytes. Note that the buffer size +is changed immediately and the buffer is reallocated immediately, +instead of setting a flag to be acted upon later. + +If you want CRC errors to be handled in a different manner than +the default, use + + png_set_crc_action(png_ptr, crit_action, ancil_action); + +The values for png_set_crc_action() say how libpng is to handle CRC errors in +ancillary and critical chunks, and whether to use the data contained +therein. Note that it is impossible to "discard" data in a critical +chunk. + +Choices for (int) crit_action are + PNG_CRC_DEFAULT 0 error/quit + PNG_CRC_ERROR_QUIT 1 error/quit + PNG_CRC_WARN_USE 3 warn/use data + PNG_CRC_QUIET_USE 4 quiet/use data + PNG_CRC_NO_CHANGE 5 use the current value + +Choices for (int) ancil_action are + PNG_CRC_DEFAULT 0 error/quit + PNG_CRC_ERROR_QUIT 1 error/quit + PNG_CRC_WARN_DISCARD 2 warn/discard data + PNG_CRC_WARN_USE 3 warn/use data + PNG_CRC_QUIET_USE 4 quiet/use data + PNG_CRC_NO_CHANGE 5 use the current value + +.SS Setting up callback code + +You can set up a callback function to handle any unknown chunks in the +input stream. You must supply the function + + read_chunk_callback(png_structp png_ptr, + png_unknown_chunkp chunk); + { + /* The unknown chunk structure contains your + chunk data, along with similar data for any other + unknown chunks: */ + + png_byte name[5]; + png_byte *data; + png_size_t size; + + /* Note that libpng has already taken care of + the CRC handling */ + + /* put your code here. Search for your chunk in the + unknown chunk structure, process it, and return one + of the following: */ + + return (-n); /* chunk had an error */ + return (0); /* did not recognize */ + return (n); /* success */ + } + +(You can give your function another name that you like instead of +"read_chunk_callback") + +To inform libpng about your function, use + + png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr, + read_chunk_callback); + +This names not only the callback function, but also a user pointer that +you can retrieve with + + png_get_user_chunk_ptr(png_ptr); + +If you call the png_set_read_user_chunk_fn() function, then all unknown +chunks will be saved when read, in case your callback function will need +one or more of them. This behavior can be changed with the +png_set_keep_unknown_chunks() function, described below. + +At this point, you can set up a callback function that will be +called after each row has been read, which you can use to control +a progress meter or the like. It's demonstrated in pngtest.c. +You must supply a function + + void read_row_callback(png_structp png_ptr, + png_uint_32 row, int pass); + { + /* put your code here */ + } + +(You can give it another name that you like instead of "read_row_callback") + +To inform libpng about your function, use + + png_set_read_status_fn(png_ptr, read_row_callback); + +When this function is called the row has already been completely processed and +the 'row' and 'pass' refer to the next row to be handled. For the +non-interlaced case the row that was just handled is simply one less than the +passed in row number, and pass will always be 0. For the interlaced case the +same applies unless the row value is 0, in which case the row just handled was +the last one from one of the preceding passes. Because interlacing may skip a +pass you cannot be sure that the preceding pass is just 'pass-1', if you really +need to know what the last pass is record (row,pass) from the callback and use +the last recorded value each time. + +As with the user transform you can find the output row using the +PNG_ROW_FROM_PASS_ROW macro. + +.SS Unknown-chunk handling + +Now you get to set the way the library processes unknown chunks in the +input PNG stream. Both known and unknown chunks will be read. Normal +behavior is that known chunks will be parsed into information in +various info_ptr members while unknown chunks will be discarded. This +behavior can be wasteful if your application will never use some known +chunk types. To change this, you can call: + + png_set_keep_unknown_chunks(png_ptr, keep, + chunk_list, num_chunks); + keep - 0: default unknown chunk handling + 1: ignore; do not keep + 2: keep only if safe-to-copy + 3: keep even if unsafe-to-copy + + You can use these definitions: + PNG_HANDLE_CHUNK_AS_DEFAULT 0 + PNG_HANDLE_CHUNK_NEVER 1 + PNG_HANDLE_CHUNK_IF_SAFE 2 + PNG_HANDLE_CHUNK_ALWAYS 3 + + chunk_list - list of chunks affected (a byte string, + five bytes per chunk, NULL or '\0' if + num_chunks is 0) + + num_chunks - number of chunks affected; if 0, all + unknown chunks are affected. If nonzero, + only the chunks in the list are affected + +Unknown chunks declared in this way will be saved as raw data onto a +list of png_unknown_chunk structures. If a chunk that is normally +known to libpng is named in the list, it will be handled as unknown, +according to the "keep" directive. If a chunk is named in successive +instances of png_set_keep_unknown_chunks(), the final instance will +take precedence. The IHDR and IEND chunks should not be named in +chunk_list; if they are, libpng will process them normally anyway. +If you know that your application will never make use of some particular +chunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below. + +Here is an example of the usage of png_set_keep_unknown_chunks(), +where the private "vpAg" chunk will later be processed by a user chunk +callback function: + + png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'}; + + #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) + png_byte unused_chunks[]= + { + 104, 73, 83, 84, (png_byte) '\0', /* hIST */ + 105, 84, 88, 116, (png_byte) '\0', /* iTXt */ + 112, 67, 65, 76, (png_byte) '\0', /* pCAL */ + 115, 67, 65, 76, (png_byte) '\0', /* sCAL */ + 115, 80, 76, 84, (png_byte) '\0', /* sPLT */ + 116, 73, 77, 69, (png_byte) '\0', /* tIME */ + }; + #endif + + ... + + #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) + /* ignore all unknown chunks: */ + png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0); + + /* except for vpAg: */ + png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1); + + /* also ignore unused known chunks: */ + png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks, + (int)sizeof(unused_chunks)/5); + #endif + +.SS User limits + +The PNG specification allows the width and height of an image to be as +large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns. +Since very few applications really need to process such large images, +we have imposed an arbitrary 1-million limit on rows and columns. +Larger images will be rejected immediately with a png_error() call. If +you wish to change this limit, you can use + + png_set_user_limits(png_ptr, width_max, height_max); + +to set your own limits, or use width_max = height_max = 0x7fffffffL +to allow all valid dimensions (libpng may reject some very large images +anyway because of potential buffer overflow conditions). + +You should put this statement after you create the PNG structure and +before calling png_read_info(), png_read_png(), or png_process_data(). + +When writing a PNG datastream, put this statement before calling +png_write_info() or png_write_png(). + +If you need to retrieve the limits that are being applied, use + + width_max = png_get_user_width_max(png_ptr); + height_max = png_get_user_height_max(png_ptr); + +The PNG specification sets no limit on the number of ancillary chunks +allowed in a PNG datastream. You can impose a limit on the total number +of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with + + png_set_chunk_cache_max(png_ptr, user_chunk_cache_max); + +where 0x7fffffffL means unlimited. You can retrieve this limit with + + chunk_cache_max = png_get_chunk_cache_max(png_ptr); + +This limit also applies to the number of buffers that can be allocated +by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks. + +You can also set a limit on the amount of memory that a compressed chunk +other than IDAT can occupy, with + + png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max); + +and you can retrieve the limit with + + chunk_malloc_max = png_get_chunk_malloc_max(png_ptr); + +Any chunks that would cause either of these limits to be exceeded will +be ignored. + +.SS Information about your system + +If you intend to display the PNG or to incorporate it in other image data you +need to tell libpng information about your display or drawing surface so that +libpng can convert the values in the image to match the display. + +From libpng-1.5.4 this information can be set before reading the PNG file +header. In earlier versions png_set_gamma() existed but behaved incorrectly if +called before the PNG file header had been read and png_set_alpha_mode() did not +exist. + +If you need to support versions prior to libpng-1.5.4 test the version number +as illustrated below using "PNG_LIBPNG_VER >= 10504" and follow the procedures +described in the appropriate manual page. + +You give libpng the encoding expected by your system expressed as a 'gamma' +value. You can also specify a default encoding for the PNG file in +case the required information is missing from the file. By default libpng +assumes that the PNG data matches your system, to keep this default call: + + png_set_gamma(png_ptr, screen_gamma, 1/screen_gamma/*file gamma*/); + +or you can use the fixed point equivalent: + + png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma, PNG_FP_1/screen_gamma); + +If you don't know the gamma for your system it is probably 2.2 - a good +approximation to the IEC standard for display systems (sRGB). If images are +too contrasty or washed out you got the value wrong - check your system +documentation! + +Many systems permit the system gamma to be changed via a lookup table in the +display driver, a few systems, including older Macs, change the response by +default. As of 1.5.4 three special values are available to handle common +situations: + + PNG_DEFAULT_sRGB: Indicates that the system conforms to the IEC 61966-2-1 + standard. This matches almost all systems. + PNG_GAMMA_MAC_18: Indicates that the system is an older (pre Mac OS 10.6) + Apple Macintosh system with the default settings. + PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates that the + system expects data with no gamma encoding. + +You would use the linear (unencoded) value if you need to process the pixel +values further because this avoids the need to decode and reencode each +component value whenever arithmetic is performed. A lot of graphics software +uses linear values for this reason, often with higher precision component values +to preserve overall accuracy. + +The second thing you may need to tell libpng about is how your system handles +alpha channel information. Some, but not all, PNG files contain an alpha +channel. To display these files correctly you need to compose the data onto a +suitable background, as described in the PNG specification. + +Libpng only supports composing onto a single color (using png_set_background; +see below). Otherwise you must do the composition yourself and, in this case, +you may need to call png_set_alpha_mode: + + #if PNG_LIBPNG_VER >= 10504 + png_set_alpha_mode(png_ptr, mode, screen_gamma); + #else + png_set_gamma(png_ptr, screen_gamma, 1.0/screen_gamma); + #endif + +The screen_gamma value is the same as the argument to png_set_gamma; however, +how it affects the output depends on the mode. png_set_alpha_mode() sets the +file gamma default to 1/screen_gamma, so normally you don't need to call +png_set_gamma. If you need different defaults call png_set_gamma() before +png_set_alpha_mode() - if you call it after it will override the settings made +by png_set_alpha_mode(). + +The mode is as follows: + + PNG_ALPHA_PNG: The data is encoded according to the PNG specification. Red, +green and blue, or gray, components are gamma encoded color +values and are not premultiplied by the alpha value. The +alpha value is a linear measure of the contribution of the +pixel to the corresponding final output pixel. + +You should normally use this format if you intend to perform +color correction on the color values; most, maybe all, color +correction software has no handling for the alpha channel and, +anyway, the math to handle pre-multiplied component values is +unnecessarily complex. + +Before you do any arithmetic on the component values you need +to remove the gamma encoding and multiply out the alpha +channel. See the PNG specification for more detail. It is +important to note that when an image with an alpha channel is +scaled, linear encoded, pre-multiplied component values must +be used! + +The remaining modes assume you don't need to do any further color correction or +that if you do, your color correction software knows all about alpha (it +probably doesn't!) + + PNG_ALPHA_STANDARD: The data libpng produces +is encoded in the standard way +assumed by most correctly written graphics software. +The gamma encoding will be removed by libpng and the +linear component values will be pre-multiplied by the +alpha channel. + +With this format the final image must be re-encoded to +match the display gamma before the image is displayed. +If your system doesn't do that, yet still seems to +perform arithmetic on the pixels without decoding them, +it is broken - check out the modes below. + +With PNG_ALPHA_STANDARD libpng always produces linear +component values, whatever screen_gamma you supply. The +screen_gamma value is, however, used as a default for +the file gamma if the PNG file has no gamma information. + +If you call png_set_gamma() after png_set_alpha_mode() you +will override the linear encoding. Instead the +pre-multiplied pixel values will be gamma encoded but +the alpha channel will still be linear. This may +actually match the requirements of some broken software, +but it is unlikely. + +While linear 8-bit data is often used it has +insufficient precision for any image with a reasonable +dynamic range. To avoid problems, and if your software +supports it, use png_set_expand_16() to force all +components to 16 bits. + + PNG_ALPHA_OPTIMIZED: This mode is the same +as PNG_ALPHA_STANDARD except that +completely opaque pixels are gamma encoded according to +the screen_gamma value. Pixels with alpha less than 1.0 +will still have linear components. + +Use this format if you have control over your +compositing software and so don't do other arithmetic +(such as scaling) on the data you get from libpng. Your +compositing software can simply copy opaque pixels to +the output but still has linear values for the +non-opaque pixels. + +In normal compositing, where the alpha channel encodes +partial pixel coverage (as opposed to broad area +translucency), the inaccuracies of the 8-bit +representation of non-opaque pixels are irrelevant. + +You can also try this format if your software is broken; +it might look better. + + PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD; +however, all component values, +including the alpha channel are gamma encoded. This is +an appropriate format to try if your software, or more +likely hardware, is totally broken, i.e., if it performs +linear arithmetic directly on gamma encoded values. + +In most cases of broken software or hardware the bug in the final display +manifests as a subtle halo around composited parts of the image. You may not +even perceive this as a halo; the composited part of the image may simply appear +separate from the background, as though it had been cut out of paper and pasted +on afterward. + +If you don't have to deal with bugs in software or hardware, or if you can fix +them, there are three recommended ways of using png_set_alpha_mode(): + + png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG, + screen_gamma); + +You can do color correction on the result (libpng does not currently +support color correction internally). When you handle the alpha channel +you need to undo the gamma encoding and multiply out the alpha. + + png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD, + screen_gamma); + png_set_expand_16(png_ptr); + +If you are using the high level interface, don't call png_set_expand_16(); +instead pass PNG_TRANSFORM_EXPAND_16 to the interface. + +With this mode you can't do color correction, but you can do arithmetic, +including composition and scaling, on the data without further processing. + + png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED, + screen_gamma); + +You can avoid the expansion to 16-bit components with this mode, but you +lose the ability to scale the image or perform other linear arithmetic. +All you can do is compose the result onto a matching output. Since this +mode is libpng-specific you also need to write your own composition +software. + +If you don't need, or can't handle, the alpha channel you can call +png_set_background() to remove it by compositing against a fixed color. Don't +call png_set_strip_alpha() to do this - it will leave spurious pixel values in +transparent parts of this image. + + png_set_background(png_ptr, &background_color, + PNG_BACKGROUND_GAMMA_SCREEN, 0, 1); + +The background_color is an RGB or grayscale value according to the data format +libpng will produce for you. Because you don't yet know the format of the PNG +file, if you call png_set_background at this point you must arrange for the +format produced by libpng to always have 8-bit or 16-bit components and then +store the color as an 8-bit or 16-bit color as appropriate. The color contains +separate gray and RGB component values, so you can let libpng produce gray or +RGB output according to the input format, but low bit depth grayscale images +must always be converted to at least 8-bit format. (Even though low bit depth +grayscale images can't have an alpha channel they can have a transparent +color!) + +You set the transforms you need later, either as flags to the high level +interface or libpng API calls for the low level interface. For reference the +settings and API calls required are: + +8-bit values: + PNG_TRANSFORM_SCALE_16 | PNG_EXPAND + png_set_expand(png_ptr); png_set_scale_16(png_ptr); + + If you must get exactly the same inaccurate results + produced by default in versions prior to libpng-1.5.4, + use PNG_TRANSFORM_STRIP_16 and png_set_strip_16(png_ptr) + instead. + +16-bit values: + PNG_TRANSFORM_EXPAND_16 + png_set_expand_16(png_ptr); + +In either case palette image data will be expanded to RGB. If you just want +color data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr) +to the list. + +Calling png_set_background before the PNG file header is read will not work +prior to libpng-1.5.4. Because the failure may result in unexpected warnings or +errors it is therefore much safer to call png_set_background after the head has +been read. Unfortunately this means that prior to libpng-1.5.4 it cannot be +used with the high level interface. + +.SS The high-level read interface + +At this point there are two ways to proceed; through the high-level +read interface, or through a sequence of low-level read operations. +You can use the high-level interface if (a) you are willing to read +the entire image into memory, and (b) the input transformations +you want to do are limited to the following set: + + PNG_TRANSFORM_IDENTITY No transformation + PNG_TRANSFORM_SCALE_16 Strip 16-bit samples to + 8-bit accurately + PNG_TRANSFORM_STRIP_16 Chop 16-bit samples to + 8-bit less accurately + PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel + PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit + samples to bytes + PNG_TRANSFORM_PACKSWAP Change order of packed + pixels to LSB first + PNG_TRANSFORM_EXPAND Perform set_expand() + PNG_TRANSFORM_INVERT_MONO Invert monochrome images + PNG_TRANSFORM_SHIFT Normalize pixels to the + sBIT depth + PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA + to BGRA + PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA + to AG + PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity + to transparency + PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples + PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples + to RGB (or GA to RGBA) + PNG_TRANSFORM_EXPAND_16 Expand samples to 16 bits + +(This excludes setting a background color, doing gamma transformation, +quantizing, and setting filler.) If this is the case, simply do this: + + png_read_png(png_ptr, info_ptr, png_transforms, NULL) + +where png_transforms is an integer containing the bitwise OR of some +set of transformation flags. This call is equivalent to png_read_info(), +followed the set of transformations indicated by the transform mask, +then png_read_image(), and finally png_read_end(). + +(The final parameter of this call is not yet used. Someday it might point +to transformation parameters required by some future input transform.) + +You must use png_transforms and not call any png_set_transform() functions +when you use png_read_png(). + +After you have called png_read_png(), you can retrieve the image data +with + + row_pointers = png_get_rows(png_ptr, info_ptr); + +where row_pointers is an array of pointers to the pixel data for each row: + + png_bytep row_pointers[height]; + +If you know your image size and pixel size ahead of time, you can allocate +row_pointers prior to calling png_read_png() with + + if (height > PNG_UINT_32_MAX/png_sizeof(png_byte)) + png_error (png_ptr, + "Image is too tall to process in memory"); + + if (width > PNG_UINT_32_MAX/pixel_size) + png_error (png_ptr, + "Image is too wide to process in memory"); + + row_pointers = png_malloc(png_ptr, + height*png_sizeof(png_bytep)); + + for (int i=0; i) and +png_get_(png_ptr, info_ptr, ...) functions return non-zero if the +data has been read, or zero if it is missing. The parameters to the +png_get_ are set directly if they are simple data types, or a +pointer into the info_ptr is returned for any complex types. + +The colorspace data from gAMA, cHRM, sRGB, iCCP, and sBIT chunks +is simply returned to give the application information about how the +image was encoded. Libpng itself only does transformations using the file +gamma when combining semitransparent pixels with the background color. + + png_get_PLTE(png_ptr, info_ptr, &palette, + &num_palette); + + palette - the palette for the file + (array of png_color) + + num_palette - number of entries in the palette + + png_get_gAMA(png_ptr, info_ptr, &file_gamma); + png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma); + + file_gamma - the gamma at which the file was + written (PNG_INFO_gAMA) + + int_file_gamma - 100,000 times the gamma at which the + file is written + + png_get_cHRM(png_ptr, info_ptr, &white_x, &white_y, &red_x, + &red_y, &green_x, &green_y, &blue_x, &blue_y) + png_get_cHRM_XYZ(png_ptr, info_ptr, &red_X, &red_Y, &red_Z, &green_X, + &green_Y, &green_Z, &blue_X, &blue_Y, &blue_Z) + png_get_cHRM_fixed(png_ptr, info_ptr, &int_white_x, &int_white_y, + &int_red_x, &int_red_y, &int_green_x, &int_green_y, + &int_blue_x, &int_blue_y) + png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &int_red_X, &int_red_Y, + &int_red_Z, &int_green_X, &int_green_Y, &int_green_Z, + &int_blue_X, &int_blue_Y, &int_blue_Z) + + {white,red,green,blue}_{x,y} + A color space encoding specified using the + chromaticities of the end points and the + white point. (PNG_INFO_cHRM) + + {red,green,blue}_{X,Y,Z} + A color space encoding specified using the encoding end + points - the CIE tristimulus specification of the intended + color of the red, green and blue channels in the PNG RGB + data. The white point is simply the sum of the three end + points. (PNG_INFO_cHRM) + + png_get_sRGB(png_ptr, info_ptr, &srgb_intent); + + file_srgb_intent - the rendering intent (PNG_INFO_sRGB) + The presence of the sRGB chunk + means that the pixel data is in the + sRGB color space. This chunk also + implies specific values of gAMA and + cHRM. + + png_get_iCCP(png_ptr, info_ptr, &name, + &compression_type, &profile, &proflen); + + name - The profile name. + + compression_type - The compression type; always + PNG_COMPRESSION_TYPE_BASE for PNG 1.0. + You may give NULL to this argument to + ignore it. + + profile - International Color Consortium color + profile data. May contain NULs. + + proflen - length of profile data in bytes. + + png_get_sBIT(png_ptr, info_ptr, &sig_bit); + + sig_bit - the number of significant bits for + (PNG_INFO_sBIT) each of the gray, + red, green, and blue channels, + whichever are appropriate for the + given color type (png_color_16) + + png_get_tRNS(png_ptr, info_ptr, &trans_alpha, + &num_trans, &trans_color); + + trans_alpha - array of alpha (transparency) + entries for palette (PNG_INFO_tRNS) + + num_trans - number of transparent entries + (PNG_INFO_tRNS) + + trans_color - graylevel or color sample values of + the single transparent color for + non-paletted images (PNG_INFO_tRNS) + + png_get_hIST(png_ptr, info_ptr, &hist); + (PNG_INFO_hIST) + + hist - histogram of palette (array of + png_uint_16) + + png_get_tIME(png_ptr, info_ptr, &mod_time); + + mod_time - time image was last modified + (PNG_VALID_tIME) + + png_get_bKGD(png_ptr, info_ptr, &background); + + background - background color (of type + png_color_16p) (PNG_VALID_bKGD) + valid 16-bit red, green and blue + values, regardless of color_type + + num_comments = png_get_text(png_ptr, info_ptr, + &text_ptr, &num_text); + + num_comments - number of comments + + text_ptr - array of png_text holding image + comments + + text_ptr[i].compression - type of compression used + on "text" PNG_TEXT_COMPRESSION_NONE + PNG_TEXT_COMPRESSION_zTXt + PNG_ITXT_COMPRESSION_NONE + PNG_ITXT_COMPRESSION_zTXt + + text_ptr[i].key - keyword for comment. Must contain + 1-79 characters. + + text_ptr[i].text - text comments for current + keyword. Can be empty. + + text_ptr[i].text_length - length of text string, + after decompression, 0 for iTXt + + text_ptr[i].itxt_length - length of itxt string, + after decompression, 0 for tEXt/zTXt + + text_ptr[i].lang - language of comment (empty + string for unknown). + + text_ptr[i].lang_key - keyword in UTF-8 + (empty string for unknown). + + Note that the itxt_length, lang, and lang_key + members of the text_ptr structure only exist when the + library is built with iTXt chunk support. Prior to + libpng-1.4.0 the library was built by default without + iTXt support. Also note that when iTXt is supported, + they contain NULL pointers when the "compression" + field contains PNG_TEXT_COMPRESSION_NONE or + PNG_TEXT_COMPRESSION_zTXt. + + num_text - number of comments (same as + num_comments; you can put NULL here + to avoid the duplication) + + Note while png_set_text() will accept text, language, + and translated keywords that can be NULL pointers, the + structure returned by png_get_text will always contain + regular zero-terminated C strings. They might be + empty strings but they will never be NULL pointers. + + num_spalettes = png_get_sPLT(png_ptr, info_ptr, + &palette_ptr); + + num_spalettes - number of sPLT chunks read. + + palette_ptr - array of palette structures holding + contents of one or more sPLT chunks + read. + + png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y, + &unit_type); + + offset_x - positive offset from the left edge + of the screen (can be negative) + + offset_y - positive offset from the top edge + of the screen (can be negative) + + unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER + + png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, + &unit_type); + + res_x - pixels/unit physical resolution in + x direction + + res_y - pixels/unit physical resolution in + x direction + + unit_type - PNG_RESOLUTION_UNKNOWN, + PNG_RESOLUTION_METER + + png_get_sCAL(png_ptr, info_ptr, &unit, &width, + &height) + + unit - physical scale units (an integer) + + width - width of a pixel in physical scale units + + height - height of a pixel in physical scale units + (width and height are doubles) + + png_get_sCAL_s(png_ptr, info_ptr, &unit, &width, + &height) + + unit - physical scale units (an integer) + + width - width of a pixel in physical scale units + (expressed as a string) + + height - height of a pixel in physical scale units + (width and height are strings like "2.54") + + num_unknown_chunks = png_get_unknown_chunks(png_ptr, + info_ptr, &unknowns) + + unknowns - array of png_unknown_chunk + structures holding unknown chunks + + unknowns[i].name - name of unknown chunk + + unknowns[i].data - data of unknown chunk + + unknowns[i].size - size of unknown chunk's data + + unknowns[i].location - position of chunk in file + + The value of "i" corresponds to the order in which the + chunks were read from the PNG file or inserted with the + png_set_unknown_chunks() function. + + The value of "location" is a bitwise "or" of + + PNG_HAVE_IHDR (0x01) + PNG_HAVE_PLTE (0x02) + PNG_AFTER_IDAT (0x08) + +The data from the pHYs chunk can be retrieved in several convenient +forms: + + res_x = png_get_x_pixels_per_meter(png_ptr, + info_ptr) + + res_y = png_get_y_pixels_per_meter(png_ptr, + info_ptr) + + res_x_and_y = png_get_pixels_per_meter(png_ptr, + info_ptr) + + res_x = png_get_x_pixels_per_inch(png_ptr, + info_ptr) + + res_y = png_get_y_pixels_per_inch(png_ptr, + info_ptr) + + res_x_and_y = png_get_pixels_per_inch(png_ptr, + info_ptr) + + aspect_ratio = png_get_pixel_aspect_ratio(png_ptr, + info_ptr) + + Each of these returns 0 [signifying "unknown"] if + the data is not present or if res_x is 0; + res_x_and_y is 0 if res_x != res_y + + Note that because of the way the resolutions are + stored internally, the inch conversions won't + come out to exactly even number. For example, + 72 dpi is stored as 0.28346 pixels/meter, and + when this is retrieved it is 71.9988 dpi, so + be sure to round the returned value appropriately + if you want to display a reasonable-looking result. + +The data from the oFFs chunk can be retrieved in several convenient +forms: + + x_offset = png_get_x_offset_microns(png_ptr, info_ptr); + + y_offset = png_get_y_offset_microns(png_ptr, info_ptr); + + x_offset = png_get_x_offset_inches(png_ptr, info_ptr); + + y_offset = png_get_y_offset_inches(png_ptr, info_ptr); + + Each of these returns 0 [signifying "unknown" if both + x and y are 0] if the data is not present or if the + chunk is present but the unit is the pixel. The + remark about inexact inch conversions applies here + as well, because a value in inches can't always be + converted to microns and back without some loss + of precision. + +For more information, see the +PNG specification for chunk contents. Be careful with trusting +rowbytes, as some of the transformations could increase the space +needed to hold a row (expand, filler, gray_to_rgb, etc.). +See png_read_update_info(), below. + +A quick word about text_ptr and num_text. PNG stores comments in +keyword/text pairs, one pair per chunk, with no limit on the number +of text chunks, and a 2^31 byte limit on their size. While there are +suggested keywords, there is no requirement to restrict the use to these +strings. It is strongly suggested that keywords and text be sensible +to humans (that's the point), so don't use abbreviations. Non-printing +symbols are not allowed. See the PNG specification for more details. +There is also no requirement to have text after the keyword. + +Keywords should be limited to 79 Latin-1 characters without leading or +trailing spaces, but non-consecutive spaces are allowed within the +keyword. It is possible to have the same keyword any number of times. +The text_ptr is an array of png_text structures, each holding a +pointer to a language string, a pointer to a keyword and a pointer to +a text string. The text string, language code, and translated +keyword may be empty or NULL pointers. The keyword/text +pairs are put into the array in the order that they are received. +However, some or all of the text chunks may be after the image, so, to +make sure you have read all the text chunks, don't mess with these +until after you read the stuff after the image. This will be +mentioned again below in the discussion that goes with png_read_end(). + +.SS Input transformations + +After you've read the header information, you can set up the library +to handle any special transformations of the image data. The various +ways to transform the data will be described in the order that they +should occur. This is important, as some of these change the color +type and/or bit depth of the data, and some others only work on +certain color types and bit depths. + +Transformations you request are ignored if they don't have any meaning for a +particular input data format. However some transformations can have an effect +as a result of a previous transformation. If you specify a contradictory set of +transformations, for example both adding and removing the alpha channel, you +cannot predict the final result. + +The color used for the transparency values should be supplied in the same +format/depth as the current image data. It is stored in the same format/depth +as the image data in a tRNS chunk, so this is what libpng expects for this data. + +The color used for the background value depends on the need_expand argument as +described below. + +Data will be decoded into the supplied row buffers packed into bytes +unless the library has been told to transform it into another format. +For example, 4 bit/pixel paletted or grayscale data will be returned +2 pixels/byte with the leftmost pixel in the high-order bits of the +byte, unless png_set_packing() is called. 8-bit RGB data will be stored +in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha() +is called to insert filler bytes, either before or after each RGB triplet. +16-bit RGB data will be returned RRGGBB RRGGBB, with the most significant +byte of the color value first, unless png_set_scale_16() is called to +transform it to regular RGB RGB triplets, or png_set_filler() or +png_set_add alpha() is called to insert filler bytes, either before or +after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can +be modified with png_set_filler(), png_set_add_alpha(), png_set_strip_16(), +or png_set_scale_16(). + +The following code transforms grayscale images of less than 8 to 8 bits, +changes paletted images to RGB, and adds a full alpha channel if there is +transparency information in a tRNS chunk. This is most useful on +grayscale images with bit depths of 2 or 4 or if there is a multiple-image +viewing application that wishes to treat all images in the same way. + + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_palette_to_rgb(png_ptr); + + if (png_get_valid(png_ptr, info_ptr, + PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr); + + if (color_type == PNG_COLOR_TYPE_GRAY && + bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr); + +The first two functions are actually aliases for png_set_expand(), added +in libpng version 1.0.4, with the function names expanded to improve code +readability. In some future version they may actually do different +things. + +As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was +added. It expands the sample depth without changing tRNS to alpha. + +As of libpng version 1.5.2, png_set_expand_16() was added. It behaves as +png_set_expand(); however, the resultant channels have 16 bits rather than 8. +Use this when the output color or gray channels are made linear to avoid fairly +severe accuracy loss. + + if (bit_depth < 16) + png_set_expand_16(png_ptr); + +PNG can have files with 16 bits per channel. If you only can handle +8 bits per channel, this will strip the pixels down to 8-bit. + + if (bit_depth == 16) +#if PNG_LIBPNG_VER >= 10504 + png_set_scale_16(png_ptr); +#else + png_set_strip_16(png_ptr); +#endif + +(The more accurate "png_set_scale_16()" API became available in libpng version +1.5.4). + +If you need to process the alpha channel on the image separately from the image +data (for example if you convert it to a bitmap mask) it is possible to have +libpng strip the channel leaving just RGB or gray data: + + if (color_type & PNG_COLOR_MASK_ALPHA) + png_set_strip_alpha(png_ptr); + +If you strip the alpha channel you need to find some other way of dealing with +the information. If, instead, you want to convert the image to an opaque +version with no alpha channel use png_set_background; see below. + +As of libpng version 1.5.2, almost all useful expansions are supported, the +major ommissions are conversion of grayscale to indexed images (which can be +done trivially in the application) and conversion of indexed to grayscale (which +can be done by a trivial manipulation of the palette.) + +In the following table, the 01 means grayscale with depth<8, 31 means +indexed with depth<8, other numerals represent the color type, "T" means +the tRNS chunk is present, A means an alpha channel is present, and O +means tRNS or alpha is present but all pixels in the image are opaque. + + FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O + TO + 01 - [G] - - - - - - - - - - - - - + 31 [Q] Q [Q] [Q] [Q] Q Q Q Q Q Q [Q] [Q] Q Q + 0 1 G + . . G G G G G G B B GB GB + 0T lt Gt t + . Gt G G Gt G G Bt Bt GBt GBt + 0O lt Gt t . + Gt Gt G Gt Gt G Bt Bt GBt GBt + 2 C P C C C + . . C - - CB CB B B + 2T Ct - Ct C C t + t - - - CBt CBt Bt Bt + 2O Ct - Ct C C t t + - - - CBt CBt Bt Bt + 3 [Q] p [Q] [Q] [Q] Q Q Q + . . [Q] [Q] Q Q + 3T [Qt] p [Qt][Q] [Q] Qt Qt Qt t + t [Qt][Qt] Qt Qt + 3O [Qt] p [Qt][Q] [Q] Qt Qt Qt t t + [Qt][Qt] Qt Qt + 4A lA G A T T GA GT GT GA GT GT + BA G GBA + 4O lA GBA A T T GA GT GT GA GT GT BA + GBA G + 6A CA PA CA C C A T tT PA P P C CBA + BA + 6O CA PBA CA C C A tT T PA P P CBA C BA + + +Within the matrix, + "+" identifies entries where 'from' and 'to' are the same. + "-" means the transformation is not supported. + "." means nothing is necessary (a tRNS chunk can just be ignored). + "t" means the transformation is obtained by png_set_tRNS. + "A" means the transformation is obtained by png_set_add_alpha(). + "X" means the transformation is obtained by png_set_expand(). + "1" means the transformation is obtained by + png_set_expand_gray_1_2_4_to_8() (and by png_set_expand() + if there is no transparency in the original or the final + format). + "C" means the transformation is obtained by png_set_gray_to_rgb(). + "G" means the transformation is obtained by png_set_rgb_to_gray(). + "P" means the transformation is obtained by + png_set_expand_palette_to_rgb(). + "p" means the transformation is obtained by png_set_packing(). + "Q" means the transformation is obtained by png_set_quantize(). + "T" means the transformation is obtained by + png_set_tRNS_to_alpha(). + "B" means the transformation is obtained by + png_set_background(), or png_strip_alpha(). + +When an entry has multiple transforms listed all are required to cause the +right overall transformation. When two transforms are separated by a comma +either will do the job. When transforms are enclosed in [] the transform should +do the job but this is currently unimplemented - a different format will result +if the suggested transformations are used. + +In PNG files, the alpha channel in an image +is the level of opacity. If you need the alpha channel in an image to +be the level of transparency instead of opacity, you can invert the +alpha channel (or the tRNS chunk data) after it's read, so that 0 is +fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit +images) is fully transparent, with + + png_set_invert_alpha(png_ptr); + +PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as +they can, resulting in, for example, 8 pixels per byte for 1 bit +files. This code expands to 1 pixel per byte without changing the +values of the pixels: + + if (bit_depth < 8) + png_set_packing(png_ptr); + +PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels +stored in a PNG image have been "scaled" or "shifted" up to the next +higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] +to 8 bits/sample in the range [0, 255]). However, it is also possible +to convert the PNG pixel data back to the original bit depth of the +image. This call reduces the pixels back down to the original bit depth: + + png_color_8p sig_bit; + + if (png_get_sBIT(png_ptr, info_ptr, &sig_bit)) + png_set_shift(png_ptr, sig_bit); + +PNG files store 3-color pixels in red, green, blue order. This code +changes the storage of the pixels to blue, green, red: + + if (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) + png_set_bgr(png_ptr); + +PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them +into 4 or 8 bytes for windowing systems that need them in this format: + + if (color_type == PNG_COLOR_TYPE_RGB) + png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE); + +where "filler" is the 8 or 16-bit number to fill with, and the location is +either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether +you want the filler before the RGB or after. This transformation +does not affect images that already have full alpha channels. To add an +opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which +will generate RGBA pixels. + +Note that png_set_filler() does not change the color type. If you want +to do that, you can add a true alpha channel with + + if (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_GRAY) + png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER); + +where "filler" contains the alpha value to assign to each pixel. +This function was added in libpng-1.2.7. + +If you are reading an image with an alpha channel, and you need the +data as ARGB instead of the normal PNG format RGBA: + + if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) + png_set_swap_alpha(png_ptr); + +For some uses, you may want a grayscale image to be represented as +RGB. This code will do that conversion: + + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_gray_to_rgb(png_ptr); + +Conversely, you can convert an RGB or RGBA image to grayscale or grayscale +with alpha. + + if (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) + png_set_rgb_to_gray(png_ptr, error_action, + double red_weight, double green_weight); + + error_action = 1: silently do the conversion + + error_action = 2: issue a warning if the original + image has any pixel where + red != green or red != blue + + error_action = 3: issue an error and abort the + conversion if the original + image has any pixel where + red != green or red != blue + + red_weight: weight of red component + + green_weight: weight of green component + If either weight is negative, default + weights are used. + +In the corresponding fixed point API the red_weight and green_weight values are +simply scaled by 100,000: + + png_set_rgb_to_gray(png_ptr, error_action, + png_fixed_point red_weight, + png_fixed_point green_weight); + +If you have set error_action = 1 or 2, you can +later check whether the image really was gray, after processing +the image rows, with the png_get_rgb_to_gray_status(png_ptr) function. +It will return a png_byte that is zero if the image was gray or +1 if there were any non-gray pixels. Background and sBIT data +will be silently converted to grayscale, using the green channel +data for sBIT, regardless of the error_action setting. + +The default values come from the PNG file cHRM chunk if present; otherwise, the +defaults correspond to the ITU-R recommendation 709, and also the sRGB color +space, as recommended in the Charles Poynton's Colour FAQ, +, in section 9: + + + + Y = 0.2126 * R + 0.7152 * G + 0.0722 * B + +Previous versions of this document, 1998 through 2002, recommended a slightly +different formula: + + Y = 0.212671 * R + 0.715160 * G + 0.072169 * B + +Libpng uses an integer approximation: + + Y = (6968 * R + 23434 * G + 2366 * B)/32768 + +The calculation is done in a linear colorspace, if the image gamma +can be determined. + +The png_set_background() function has been described already; it tells libpng to +composite images with alpha or simple transparency against the supplied +background color. For compatibility with versions of libpng earlier than +libpng-1.5.4 it is recommended that you call the function after reading the file +header, even if you don't want to use the color in a bKGD chunk, if one exists. + +If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid), +you may use this color, or supply another color more suitable for +the current display (e.g., the background color from a web page). You +need to tell libpng how the color is represented, both the format of the +component values in the color (the number of bits) and the gamma encoding of the +color. The function takes two arguments, background_gamma_mode and need_expand +to convey this information; however, only two combinations are likely to be +useful: + + png_color_16 my_background; + png_color_16p image_background; + + if (png_get_bKGD(png_ptr, info_ptr, &image_background)) + png_set_background(png_ptr, image_background, + PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1); + else + png_set_background(png_ptr, &my_background, + PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1); + +The second call was described above - my_background is in the format of the +final, display, output produced by libpng. Because you now know the format of +the PNG it is possible to avoid the need to choose either 8-bit or 16-bit +output and to retain palette images (the palette colors will be modified +appropriately and the tRNS chunk removed.) However, if you are doing this, +take great care not to ask for transformations without checking first that +they apply! + +In the first call the background color has the original bit depth and color type +of the PNG file. So, for palette images the color is supplied as a palette +index and for low bit greyscale images the color is a reduced bit value in +image_background->gray. + +If you didn't call png_set_gamma() before reading the file header, for example +if you need your code to remain compatible with older versions of libpng prior +to libpng-1.5.4, this is the place to call it. + +Do not call it if you called png_set_alpha_mode(); doing so will damage the +settings put in place by png_set_alpha_mode(). (If png_set_alpha_mode() is +supported then you can certainly do png_set_gamma() before reading the PNG +header.) + +This API unconditionally sets the screen and file gamma values, so it will +override the value in the PNG file unless it is called before the PNG file +reading starts. For this reason you must always call it with the PNG file +value when you call it in this position: + + if (png_get_gAMA(png_ptr, info_ptr, &file_gamma)) + png_set_gamma(png_ptr, screen_gamma, file_gamma); + + else + png_set_gamma(png_ptr, screen_gamma, 0.45455); + +If you need to reduce an RGB file to a paletted file, or if a paletted +file has more entries then will fit on your screen, png_set_quantize() +will do that. Note that this is a simple match quantization that merely +finds the closest color available. This should work fairly well with +optimized palettes, but fairly badly with linear color cubes. If you +pass a palette that is larger than maximum_colors, the file will +reduce the number of colors in the palette so it will fit into +maximum_colors. If there is a histogram, libpng will use it to make +more intelligent choices when reducing the palette. If there is no +histogram, it may not do as good a job. + + if (color_type & PNG_COLOR_MASK_COLOR) + { + if (png_get_valid(png_ptr, info_ptr, + PNG_INFO_PLTE)) + { + png_uint_16p histogram = NULL; + + png_get_hIST(png_ptr, info_ptr, + &histogram); + png_set_quantize(png_ptr, palette, num_palette, + max_screen_colors, histogram, 1); + } + + else + { + png_color std_color_cube[MAX_SCREEN_COLORS] = + { ... colors ... }; + + png_set_quantize(png_ptr, std_color_cube, + MAX_SCREEN_COLORS, MAX_SCREEN_COLORS, + NULL,0); + } + } + +PNG files describe monochrome as black being zero and white being one. +The following code will reverse this (make black be one and white be +zero): + + if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY) + png_set_invert_mono(png_ptr); + +This function can also be used to invert grayscale and gray-alpha images: + + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_invert_mono(png_ptr); + +PNG files store 16-bit pixels in network byte order (big-endian, +ie. most significant bits first). This code changes the storage to the +other way (little-endian, i.e. least significant bits first, the +way PCs store them): + + if (bit_depth == 16) + png_set_swap(png_ptr); + +If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you +need to change the order the pixels are packed into bytes, you can use: + + if (bit_depth < 8) + png_set_packswap(png_ptr); + +Finally, you can write your own transformation function if none of +the existing ones meets your needs. This is done by setting a callback +with + + png_set_read_user_transform_fn(png_ptr, + read_transform_fn); + +You must supply the function + + void read_transform_fn(png_structp png_ptr, png_row_infop + row_info, png_bytep data) + +See pngtest.c for a working example. Your function will be called +after all of the other transformations have been processed. Take care with +interlaced images if you do the interlace yourself - the width of the row is the +width in 'row_info', not the overall image width. + +If supported, libpng provides two information routines that you can use to find +where you are in processing the image: + + png_get_current_pass_number(png_structp png_ptr); + png_get_current_row_number(png_structp png_ptr); + +Don't try using these outside a transform callback - firstly they are only +supported if user transforms are supported, secondly they may well return +unexpected results unless the row is actually being processed at the moment they +are called. + +With interlaced +images the value returned is the row in the input sub-image image. Use +PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to +find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass). + +The discussion of interlace handling above contains more information on how to +use these values. + +You can also set up a pointer to a user structure for use by your +callback function, and you can inform libpng that your transform +function will change the number of channels or bit depth with the +function + + png_set_user_transform_info(png_ptr, user_ptr, + user_depth, user_channels); + +The user's application, not libpng, is responsible for allocating and +freeing any memory required for the user structure. + +You can retrieve the pointer via the function +png_get_user_transform_ptr(). For example: + + voidp read_user_transform_ptr = + png_get_user_transform_ptr(png_ptr); + +The last thing to handle is interlacing; this is covered in detail below, +but you must call the function here if you want libpng to handle expansion +of the interlaced image. + + number_of_passes = png_set_interlace_handling(png_ptr); + +After setting the transformations, libpng can update your png_info +structure to reflect any transformations you've requested with this +call. + + png_read_update_info(png_ptr, info_ptr); + +This is most useful to update the info structure's rowbytes +field so you can use it to allocate your image memory. This function +will also update your palette with the correct screen_gamma and +background if these have been given with the calls above. You may +only call png_read_update_info() once with a particular info_ptr. + +After you call png_read_update_info(), you can allocate any +memory you need to hold the image. The row data is simply +raw byte data for all forms of images. As the actual allocation +varies among applications, no example will be given. If you +are allocating one large chunk, you will need to build an +array of pointers to each row, as it will be needed for some +of the functions below. + +Remember: Before you call png_read_update_info(), the png_get_*() +functions return the values corresponding to the original PNG image. +After you call png_read_update_info the values refer to the image +that libpng will output. Consequently you must call all the png_set_ +functions before you call png_read_update_info(). This is particularly +important for png_set_interlace_handling() - if you are going to call +png_read_update_info() you must call png_set_interlace_handling() before +it unless you want to receive interlaced output. + +.SS Reading image data + +After you've allocated memory, you can read the image data. +The simplest way to do this is in one function call. If you are +allocating enough memory to hold the whole image, you can just +call png_read_image() and libpng will read in all the image data +and put it in the memory area supplied. You will need to pass in +an array of pointers to each row. + +This function automatically handles interlacing, so you don't +need to call png_set_interlace_handling() (unless you call +png_read_update_info()) or call this function multiple times, or any +of that other stuff necessary with png_read_rows(). + + png_read_image(png_ptr, row_pointers); + +where row_pointers is: + + png_bytep row_pointers[height]; + +You can point to void or char or whatever you use for pixels. + +If you don't want to read in the whole image at once, you can +use png_read_rows() instead. If there is no interlacing (check +interlace_type == PNG_INTERLACE_NONE), this is simple: + + png_read_rows(png_ptr, row_pointers, NULL, + number_of_rows); + +where row_pointers is the same as in the png_read_image() call. + +If you are doing this just one row at a time, you can do this with +a single row_pointer instead of an array of row_pointers: + + png_bytep row_pointer = row; + png_read_row(png_ptr, row_pointer, NULL); + +If the file is interlaced (interlace_type != 0 in the IHDR chunk), things +get somewhat harder. The only current (PNG Specification version 1.2) +interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7); +a somewhat complicated 2D interlace scheme, known as Adam7, that +breaks down an image into seven smaller images of varying size, based +on an 8x8 grid. This number is defined (from libpng 1.5) as +PNG_INTERLACE_ADAM7_PASSES in png.h + +libpng can fill out those images or it can give them to you "as is". +It is almost always better to have libpng handle the interlacing for you. +If you want the images filled out, there are two ways to do that. The one +mentioned in the PNG specification is to expand each pixel to cover +those pixels that have not been read yet (the "rectangle" method). +This results in a blocky image for the first pass, which gradually +smooths out as more pixels are read. The other method is the "sparkle" +method, where pixels are drawn only in their final locations, with the +rest of the image remaining whatever colors they were initialized to +before the start of the read. The first method usually looks better, +but tends to be slower, as there are more pixels to put in the rows. + +If, as is likely, you want libpng to expand the images, call this before +calling png_start_read_image() or png_read_update_info(): + + if (interlace_type == PNG_INTERLACE_ADAM7) + number_of_passes + = png_set_interlace_handling(png_ptr); + +This will return the number of passes needed. Currently, this is seven, +but may change if another interlace type is added. This function can be +called even if the file is not interlaced, where it will return one pass. +You then need to read the whole image 'number_of_passes' times. Each time +will distribute the pixels from the current pass to the correct place in +the output image, so you need to supply the same rows to png_read_rows in +each pass. + +If you are not going to display the image after each pass, but are +going to wait until the entire image is read in, use the sparkle +effect. This effect is faster and the end result of either method +is exactly the same. If you are planning on displaying the image +after each pass, the "rectangle" effect is generally considered the +better looking one. + +If you only want the "sparkle" effect, just call png_read_rows() as +normal, with the third parameter NULL. Make sure you make pass over +the image number_of_passes times, and you don't change the data in the +rows between calls. You can change the locations of the data, just +not the data. Each pass only writes the pixels appropriate for that +pass, and assumes the data from previous passes is still valid. + + png_read_rows(png_ptr, row_pointers, NULL, + number_of_rows); + +If you only want the first effect (the rectangles), do the same as +before except pass the row buffer in the third parameter, and leave +the second parameter NULL. + + png_read_rows(png_ptr, NULL, row_pointers, + number_of_rows); + +If you don't want libpng to handle the interlacing details, just call +png_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images. +Each of the images is a valid image by itself; however, you will almost +certainly need to distribute the pixels from each sub-image to the +correct place. This is where everything gets very tricky. + +If you want to retrieve the separate images you must pass the correct +number of rows to each successive call of png_read_rows(). The calculation +gets pretty complicated for small images, where some sub-images may +not even exist because either their width or height ends up zero. +libpng provides two macros to help you in 1.5 and later versions: + + png_uint_32 width = PNG_PASS_COLS(image_width, pass_number); + png_uint_32 height = PNG_PASS_ROWS(image_height, pass_number); + +Respectively these tell you the width and height of the sub-image +corresponding to the numbered pass. 'pass' is in in the range 0 to 6 - +this can be confusing because the specification refers to the same passes +as 1 to 7! Be careful, you must check both the width and height before +calling png_read_rows() and not call it for that pass if either is zero. + +You can, of course, read each sub-image row by row. If you want to +produce optimal code to make a pixel-by-pixel transformation of an +interlaced image this is the best approach; read each row of each pass, +transform it, and write it out to a new interlaced image. + +If you want to de-interlace the image yourself libpng provides further +macros to help that tell you where to place the pixels in the output image. +Because the interlacing scheme is rectangular - sub-image pixels are always +arranged on a rectangular grid - all you need to know for each pass is the +starting column and row in the output image of the first pixel plus the +spacing between each pixel. As of libpng 1.5 there are four macros to +retrieve this information: + + png_uint_32 x = PNG_PASS_START_COL(pass); + png_uint_32 y = PNG_PASS_START_ROW(pass); + png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass); + png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass); + +These allow you to write the obvious loop: + + png_uint_32 input_y = 0; + png_uint_32 output_y = PNG_PASS_START_ROW(pass); + + while (output_y < output_image_height) + { + png_uint_32 input_x = 0; + png_uint_32 output_x = PNG_PASS_START_COL(pass); + + while (output_x < output_image_width) + { + image[output_y][output_x] = + subimage[pass][input_y][input_x++]; + + output_x += xStep; + } + + ++input_y; + output_y += yStep; + } + +Notice that the steps between successive output rows and columns are +returned as shifts. This is possible because the pixels in the subimages +are always a power of 2 apart - 1, 2, 4 or 8 pixels - in the original +image. In practice you may need to directly calculate the output coordinate +given an input coordinate. libpng provides two further macros for this +purpose: + + png_uint_32 output_x = PNG_COL_FROM_PASS_COL(input_x, pass); + png_uint_32 output_y = PNG_ROW_FROM_PASS_ROW(input_y, pass); + +Finally a pair of macros are provided to tell you if a particular image +row or column appears in a given pass: + + int col_in_pass = PNG_COL_IN_INTERLACE_PASS(output_x, pass); + int row_in_pass = PNG_ROW_IN_INTERLACE_PASS(output_y, pass); + +Bear in mind that you will probably also need to check the width and height +of the pass in addition to the above to be sure the pass even exists! + +With any luck you are convinced by now that you don't want to do your own +interlace handling. In reality normally the only good reason for doing this +is if you are processing PNG files on a pixel-by-pixel basis and don't want +to load the whole file into memory when it is interlaced. + +libpng includes a test program, pngvalid, that illustrates reading and +writing of interlaced images. If you can't get interlacing to work in your +code and don't want to leave it to libpng (the recommended approach), see +how pngvalid.c does it. + +.SS Finishing a sequential read + +After you are finished reading the image through the +low-level interface, you can finish reading the file. If you are +interested in comments or time, which may be stored either before or +after the image data, you should pass the separate png_info struct if +you want to keep the comments from before and after the image +separate. + + png_infop end_info = png_create_info_struct(png_ptr); + + if (!end_info) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + return (ERROR); + } + + png_read_end(png_ptr, end_info); + +If you are not interested, you should still call png_read_end() +but you can pass NULL, avoiding the need to create an end_info structure. + + png_read_end(png_ptr, (png_infop)NULL); + +If you don't call png_read_end(), then your file pointer will be +left pointing to the first chunk after the last IDAT, which is probably +not what you want if you expect to read something beyond the end of +the PNG datastream. + +When you are done, you can free all memory allocated by libpng like this: + + png_destroy_read_struct(&png_ptr, &info_ptr, + &end_info); + +or, if you didn't create an end_info structure, + + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + +It is also possible to individually free the info_ptr members that +point to libpng-allocated storage with the following function: + + png_free_data(png_ptr, info_ptr, mask, seq) + + mask - identifies data to be freed, a mask + containing the bitwise OR of one or + more of + PNG_FREE_PLTE, PNG_FREE_TRNS, + PNG_FREE_HIST, PNG_FREE_ICCP, + PNG_FREE_PCAL, PNG_FREE_ROWS, + PNG_FREE_SCAL, PNG_FREE_SPLT, + PNG_FREE_TEXT, PNG_FREE_UNKN, + or simply PNG_FREE_ALL + + seq - sequence number of item to be freed + (-1 for all items) + +This function may be safely called when the relevant storage has +already been freed, or has not yet been allocated, or was allocated +by the user and not by libpng, and will in those cases do nothing. +The "seq" parameter is ignored if only one item of the selected data +type, such as PLTE, is allowed. If "seq" is not -1, and multiple items +are allowed for the data type identified in the mask, such as text or +sPLT, only the n'th item in the structure is freed, where n is "seq". + +The default behavior is only to free data that was allocated internally +by libpng. This can be changed, so that libpng will not free the data, +or so that it will free data that was allocated by the user with png_malloc() +or png_calloc() and passed in via a png_set_*() function, with + + png_data_freer(png_ptr, info_ptr, freer, mask) + + freer - one of + PNG_DESTROY_WILL_FREE_DATA + PNG_SET_WILL_FREE_DATA + PNG_USER_WILL_FREE_DATA + + mask - which data elements are affected + same choices as in png_free_data() + +This function only affects data that has already been allocated. +You can call this function after reading the PNG data but before calling +any png_set_*() functions, to control whether the user or the png_set_*() +function is responsible for freeing any existing data that might be present, +and again after the png_set_*() functions to control whether the user +or png_destroy_*() is supposed to free the data. When the user assumes +responsibility for libpng-allocated data, the application must use +png_free() to free it, and when the user transfers responsibility to libpng +for data that the user has allocated, the user must have used png_malloc() +or png_calloc() to allocate it. + +If you allocated your row_pointers in a single block, as suggested above in +the description of the high level read interface, you must not transfer +responsibility for freeing it to the png_set_rows or png_read_destroy function, +because they would also try to free the individual row_pointers[i]. + +If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword +separately, do not transfer responsibility for freeing text_ptr to libpng, +because when libpng fills a png_text structure it combines these members with +the key member, and png_free_data() will free only text_ptr.key. Similarly, +if you transfer responsibility for free'ing text_ptr from libpng to your +application, your application must not separately free those members. + +The png_free_data() function will turn off the "valid" flag for anything +it frees. If you need to turn the flag off for a chunk that was freed by +your application instead of by libpng, you can use + + png_set_invalid(png_ptr, info_ptr, mask); + + mask - identifies the chunks to be made invalid, + containing the bitwise OR of one or + more of + PNG_INFO_gAMA, PNG_INFO_sBIT, + PNG_INFO_cHRM, PNG_INFO_PLTE, + PNG_INFO_tRNS, PNG_INFO_bKGD, + PNG_INFO_hIST, PNG_INFO_pHYs, + PNG_INFO_oFFs, PNG_INFO_tIME, + PNG_INFO_pCAL, PNG_INFO_sRGB, + PNG_INFO_iCCP, PNG_INFO_sPLT, + PNG_INFO_sCAL, PNG_INFO_IDAT + +For a more compact example of reading a PNG image, see the file example.c. + +.SS Reading PNG files progressively + +The progressive reader is slightly different then the non-progressive +reader. Instead of calling png_read_info(), png_read_rows(), and +png_read_end(), you make one call to png_process_data(), which calls +callbacks when it has the info, a row, or the end of the image. You +set up these callbacks with png_set_progressive_read_fn(). You don't +have to worry about the input/output functions of libpng, as you are +giving the library the data directly in png_process_data(). I will +assume that you have read the section on reading PNG files above, +so I will only highlight the differences (although I will show +all of the code). + +png_structp png_ptr; +png_infop info_ptr; + + /* An example code fragment of how you would + initialize the progressive reader in your + application. */ + int + initialize_png_reader() + { + png_ptr = png_create_read_struct + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn); + + if (!png_ptr) + return (ERROR); + + info_ptr = png_create_info_struct(png_ptr); + + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr, + (png_infopp)NULL, (png_infopp)NULL); + return (ERROR); + } + + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + return (ERROR); + } + + /* This one's new. You can provide functions + to be called when the header info is valid, + when each row is completed, and when the image + is finished. If you aren't using all functions, + you can specify NULL parameters. Even when all + three functions are NULL, you need to call + png_set_progressive_read_fn(). You can use + any struct as the user_ptr (cast to a void pointer + for the function call), and retrieve the pointer + from inside the callbacks using the function + + png_get_progressive_ptr(png_ptr); + + which will return a void pointer, which you have + to cast appropriately. + */ + png_set_progressive_read_fn(png_ptr, (void *)user_ptr, + info_callback, row_callback, end_callback); + + return 0; + } + + /* A code fragment that you call as you receive blocks + of data */ + int + process_data(png_bytep buffer, png_uint_32 length) + { + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + return (ERROR); + } + + /* This one's new also. Simply give it a chunk + of data from the file stream (in order, of + course). On machines with segmented memory + models machines, don't give it any more than + 64K. The library seems to run fine with sizes + of 4K. Although you can give it much less if + necessary (I assume you can give it chunks of + 1 byte, I haven't tried less then 256 bytes + yet). When this function returns, you may + want to display any rows that were generated + in the row callback if you don't already do + so there. + */ + png_process_data(png_ptr, info_ptr, buffer, length); + + /* At this point you can call png_process_data_skip if + you want to handle data the library will skip yourself; + it simply returns the number of bytes to skip (and stops + libpng skipping that number of bytes on the next + png_process_data call). + return 0; + } + + /* This function is called (as set by + png_set_progressive_read_fn() above) when enough data + has been supplied so all of the header has been + read. + */ + void + info_callback(png_structp png_ptr, png_infop info) + { + /* Do any setup here, including setting any of + the transformations mentioned in the Reading + PNG files section. For now, you _must_ call + either png_start_read_image() or + png_read_update_info() after all the + transformations are set (even if you don't set + any). You may start getting rows before + png_process_data() returns, so this is your + last chance to prepare for that. + + This is where you turn on interlace handling, + assuming you don't want to do it yourself. + + If you need to you can stop the processing of + your original input data at this point by calling + png_process_data_pause. This returns the number + of unprocessed bytes from the last png_process_data + call - it is up to you to ensure that the next call + sees these bytes again. If you don't want to bother + with this you can get libpng to cache the unread + bytes by setting the 'save' parameter (see png.h) but + then libpng will have to copy the data internally. + */ + } + + /* This function is called when each row of image + data is complete */ + void + row_callback(png_structp png_ptr, png_bytep new_row, + png_uint_32 row_num, int pass) + { + /* If the image is interlaced, and you turned + on the interlace handler, this function will + be called for every row in every pass. Some + of these rows will not be changed from the + previous pass. When the row is not changed, + the new_row variable will be NULL. The rows + and passes are called in order, so you don't + really need the row_num and pass, but I'm + supplying them because it may make your life + easier. + + If you did not turn on interlace handling then + the callback is called for each row of each + sub-image when the image is interlaced. In this + case 'row_num' is the row in the sub-image, not + the row in the output image as it is in all other + cases. + + For the non-NULL rows of interlaced images when + you have switched on libpng interlace handling, + you must call png_progressive_combine_row() + passing in the row and the old row. You can + call this function for NULL rows (it will just + return) and for non-interlaced images (it just + does the memcpy for you) if it will make the + code easier. Thus, you can just do this for + all cases if you switch on interlace handling; + */ + + png_progressive_combine_row(png_ptr, old_row, + new_row); + + /* where old_row is what was displayed for + previously for the row. Note that the first + pass (pass == 0, really) will completely cover + the old row, so the rows do not have to be + initialized. After the first pass (and only + for interlaced images), you will have to pass + the current row, and the function will combine + the old row and the new row. + + You can also call png_process_data_pause in this + callback - see above. + */ + } + + void + end_callback(png_structp png_ptr, png_infop info) + { + /* This function is called after the whole image + has been read, including any chunks after the + image (up to and including the IEND). You + will usually have the same info chunk as you + had in the header, although some data may have + been added to the comments and time fields. + + Most people won't do much here, perhaps setting + a flag that marks the image as finished. + */ + } + + + +.SH IV. Writing + +Much of this is very similar to reading. However, everything of +importance is repeated here, so you won't have to constantly look +back up in the reading section to understand writing. + +.SS Setup + +You will want to do the I/O initialization before you get into libpng, +so if it doesn't work, you don't have anything to undo. If you are not +using the standard I/O functions, you will need to replace them with +custom writing functions. See the discussion under Customizing libpng. + + FILE *fp = fopen(file_name, "wb"); + + if (!fp) + return (ERROR); + +Next, png_struct and png_info need to be allocated and initialized. +As these can be both relatively large, you may not want to store these +on the stack, unless you have stack space to spare. Of course, you +will want to check if they return NULL. If you are also reading, +you won't want to name your read structure and your write structure +both "png_ptr"; you can call them anything you like, such as +"read_ptr" and "write_ptr". Look at pngtest.c, for example. + + png_structp png_ptr = png_create_write_struct + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn); + + if (!png_ptr) + return (ERROR); + + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_write_struct(&png_ptr, + (png_infopp)NULL); + return (ERROR); + } + +If you want to use your own memory allocation routines, +define PNG_USER_MEM_SUPPORTED and use +png_create_write_struct_2() instead of png_create_write_struct(): + + png_structp png_ptr = png_create_write_struct_2 + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn, (png_voidp) + user_mem_ptr, user_malloc_fn, user_free_fn); + +After you have these structures, you will need to set up the +error handling. When libpng encounters an error, it expects to +longjmp() back to your routine. Therefore, you will need to call +setjmp() and pass the png_jmpbuf(png_ptr). If you +write the file from different routines, you will need to update +the png_jmpbuf(png_ptr) every time you enter a new routine that will +call a png_*() function. See your documentation of setjmp/longjmp +for your compiler for more information on setjmp/longjmp. See +the discussion on libpng error handling in the Customizing Libpng +section below for more information on the libpng error handling. + + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_write_struct(&png_ptr, &info_ptr); + fclose(fp); + return (ERROR); + } + ... + return; + +If you would rather avoid the complexity of setjmp/longjmp issues, +you can compile libpng with PNG_NO_SETJMP, in which case +errors will result in a call to PNG_ABORT() which defaults to abort(). + +You can #define PNG_ABORT() to a function that does something +more useful than abort(), as long as your function does not +return. + +Now you need to set up the output code. The default for libpng is to +use the C function fwrite(). If you use this, you will need to pass a +valid FILE * in the function png_init_io(). Be sure that the file is +opened in binary mode. Again, if you wish to handle writing data in +another way, see the discussion on libpng I/O handling in the Customizing +Libpng section below. + + png_init_io(png_ptr, fp); + +If you are embedding your PNG into a datastream such as MNG, and don't +want libpng to write the 8-byte signature, or if you have already +written the signature in your application, use + + png_set_sig_bytes(png_ptr, 8); + +to inform libpng that it should not write a signature. + +.SS Write callbacks + +At this point, you can set up a callback function that will be +called after each row has been written, which you can use to control +a progress meter or the like. It's demonstrated in pngtest.c. +You must supply a function + + void write_row_callback(png_structp png_ptr, png_uint_32 row, + int pass); + { + /* put your code here */ + } + +(You can give it another name that you like instead of "write_row_callback") + +To inform libpng about your function, use + + png_set_write_status_fn(png_ptr, write_row_callback); + +When this function is called the row has already been completely processed and +it has also been written out. The 'row' and 'pass' refer to the next row to be +handled. For the +non-interlaced case the row that was just handled is simply one less than the +passed in row number, and pass will always be 0. For the interlaced case the +same applies unless the row value is 0, in which case the row just handled was +the last one from one of the preceding passes. Because interlacing may skip a +pass you cannot be sure that the preceding pass is just 'pass-1', if you really +need to know what the last pass is record (row,pass) from the callback and use +the last recorded value each time. + +As with the user transform you can find the output row using the +PNG_ROW_FROM_PASS_ROW macro. + +You now have the option of modifying how the compression library will +run. The following functions are mainly for testing, but may be useful +in some cases, like if you need to write PNG files extremely fast and +are willing to give up some compression, or if you want to get the +maximum possible compression at the expense of slower writing. If you +have no special needs in this area, let the library do what it wants by +not calling this function at all, as it has been tuned to deliver a good +speed/compression ratio. The second parameter to png_set_filter() is +the filter method, for which the only valid values are 0 (as of the +July 1999 PNG specification, version 1.2) or 64 (if you are writing +a PNG datastream that is to be embedded in a MNG datastream). The third +parameter is a flag that indicates which filter type(s) are to be tested +for each scanline. See the PNG specification for details on the specific +filter types. + + + /* turn on or off filtering, and/or choose + specific filters. You can use either a single + PNG_FILTER_VALUE_NAME or the bitwise OR of one + or more PNG_FILTER_NAME masks. + */ + png_set_filter(png_ptr, 0, + PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE | + PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB | + PNG_FILTER_UP | PNG_FILTER_VALUE_UP | + PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG | + PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH| + PNG_ALL_FILTERS); + +If an application wants to start and stop using particular filters during +compression, it should start out with all of the filters (to ensure that +the previous row of pixels will be stored in case it's needed later), +and then add and remove them after the start of compression. + +If you are writing a PNG datastream that is to be embedded in a MNG +datastream, the second parameter can be either 0 or 64. + +The png_set_compression_*() functions interface to the zlib compression +library, and should mostly be ignored unless you really know what you are +doing. The only generally useful call is png_set_compression_level() +which changes how much time zlib spends on trying to compress the image +data. See the Compression Library (zlib.h and algorithm.txt, distributed +with zlib) for details on the compression levels. + + #include zlib.h + + /* Set the zlib compression level */ + png_set_compression_level(png_ptr, + Z_BEST_COMPRESSION); + + /* Set other zlib parameters for compressing IDAT */ + png_set_compression_mem_level(png_ptr, 8); + png_set_compression_strategy(png_ptr, + Z_DEFAULT_STRATEGY); + png_set_compression_window_bits(png_ptr, 15); + png_set_compression_method(png_ptr, 8); + png_set_compression_buffer_size(png_ptr, 8192) + + /* Set zlib parameters for text compression + * If you don't call these, the parameters + * fall back on those defined for IDAT chunks + */ + png_set_text_compression_mem_level(png_ptr, 8); + png_set_text_compression_strategy(png_ptr, + Z_DEFAULT_STRATEGY); + png_set_text_compression_window_bits(png_ptr, 15); + png_set_text_compression_method(png_ptr, 8); + +.SS Setting the contents of info for output + +You now need to fill in the png_info structure with all the data you +wish to write before the actual image. Note that the only thing you +are allowed to write after the image is the text chunks and the time +chunk (as of PNG Specification 1.2, anyway). See png_write_end() and +the latest PNG specification for more information on that. If you +wish to write them before the image, fill them in now, and flag that +data as being valid. If you want to wait until after the data, don't +fill them until png_write_end(). For all the fields in png_info and +their data types, see png.h. For explanations of what the fields +contain, see the PNG specification. + +Some of the more important parts of the png_info are: + + png_set_IHDR(png_ptr, info_ptr, width, height, + bit_depth, color_type, interlace_type, + compression_type, filter_method) + + width - holds the width of the image + in pixels (up to 2^31). + + height - holds the height of the image + in pixels (up to 2^31). + + bit_depth - holds the bit depth of one of the + image channels. + (valid values are 1, 2, 4, 8, 16 + and depend also on the + color_type. See also significant + bits (sBIT) below). + + color_type - describes which color/alpha + channels are present. + PNG_COLOR_TYPE_GRAY + (bit depths 1, 2, 4, 8, 16) + PNG_COLOR_TYPE_GRAY_ALPHA + (bit depths 8, 16) + PNG_COLOR_TYPE_PALETTE + (bit depths 1, 2, 4, 8) + PNG_COLOR_TYPE_RGB + (bit_depths 8, 16) + PNG_COLOR_TYPE_RGB_ALPHA + (bit_depths 8, 16) + + PNG_COLOR_MASK_PALETTE + PNG_COLOR_MASK_COLOR + PNG_COLOR_MASK_ALPHA + + interlace_type - PNG_INTERLACE_NONE or + PNG_INTERLACE_ADAM7 + + compression_type - (must be + PNG_COMPRESSION_TYPE_DEFAULT) + + filter_method - (must be PNG_FILTER_TYPE_DEFAULT + or, if you are writing a PNG to + be embedded in a MNG datastream, + can also be + PNG_INTRAPIXEL_DIFFERENCING) + +If you call png_set_IHDR(), the call must appear before any of the +other png_set_*() functions, because they might require access to some of +the IHDR settings. The remaining png_set_*() functions can be called +in any order. + +If you wish, you can reset the compression_type, interlace_type, or +filter_method later by calling png_set_IHDR() again; if you do this, the +width, height, bit_depth, and color_type must be the same in each call. + + png_set_PLTE(png_ptr, info_ptr, palette, + num_palette); + + palette - the palette for the file + (array of png_color) + num_palette - number of entries in the palette + + png_set_gAMA(png_ptr, info_ptr, file_gamma); + png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma); + + file_gamma - the gamma at which the image was + created (PNG_INFO_gAMA) + + int_file_gamma - 100,000 times the gamma at which + the image was created + + png_set_cHRM(png_ptr, info_ptr, white_x, white_y, red_x, red_y, + green_x, green_y, blue_x, blue_y) + png_set_cHRM_XYZ(png_ptr, info_ptr, red_X, red_Y, red_Z, green_X, + green_Y, green_Z, blue_X, blue_Y, blue_Z) + png_set_cHRM_fixed(png_ptr, info_ptr, int_white_x, int_white_y, + int_red_x, int_red_y, int_green_x, int_green_y, + int_blue_x, int_blue_y) + png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, int_red_X, int_red_Y, + int_red_Z, int_green_X, int_green_Y, int_green_Z, + int_blue_X, int_blue_Y, int_blue_Z) + + {white,red,green,blue}_{x,y} + A color space encoding specified using the chromaticities + of the end points and the white point. + + {red,green,blue}_{X,Y,Z} + A color space encoding specified using the encoding end + points - the CIE tristimulus specification of the intended + color of the red, green and blue channels in the PNG RGB + data. The white point is simply the sum of the three end + points. + + png_set_sRGB(png_ptr, info_ptr, srgb_intent); + + srgb_intent - the rendering intent + (PNG_INFO_sRGB) The presence of + the sRGB chunk means that the pixel + data is in the sRGB color space. + This chunk also implies specific + values of gAMA and cHRM. Rendering + intent is the CSS-1 property that + has been defined by the International + Color Consortium + (http://www.color.org). + It can be one of + PNG_sRGB_INTENT_SATURATION, + PNG_sRGB_INTENT_PERCEPTUAL, + PNG_sRGB_INTENT_ABSOLUTE, or + PNG_sRGB_INTENT_RELATIVE. + + + png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, + srgb_intent); + + srgb_intent - the rendering intent + (PNG_INFO_sRGB) The presence of the + sRGB chunk means that the pixel + data is in the sRGB color space. + This function also causes gAMA and + cHRM chunks with the specific values + that are consistent with sRGB to be + written. + + png_set_iCCP(png_ptr, info_ptr, name, compression_type, + profile, proflen); + + name - The profile name. + + compression_type - The compression type; always + PNG_COMPRESSION_TYPE_BASE for PNG 1.0. + You may give NULL to this argument to + ignore it. + + profile - International Color Consortium color + profile data. May contain NULs. + + proflen - length of profile data in bytes. + + png_set_sBIT(png_ptr, info_ptr, sig_bit); + + sig_bit - the number of significant bits for + (PNG_INFO_sBIT) each of the gray, red, + green, and blue channels, whichever are + appropriate for the given color type + (png_color_16) + + png_set_tRNS(png_ptr, info_ptr, trans_alpha, + num_trans, trans_color); + + trans_alpha - array of alpha (transparency) + entries for palette (PNG_INFO_tRNS) + + num_trans - number of transparent entries + (PNG_INFO_tRNS) + + trans_color - graylevel or color sample values + (in order red, green, blue) of the + single transparent color for + non-paletted images (PNG_INFO_tRNS) + + png_set_hIST(png_ptr, info_ptr, hist); + + hist - histogram of palette (array of + png_uint_16) (PNG_INFO_hIST) + + png_set_tIME(png_ptr, info_ptr, mod_time); + + mod_time - time image was last modified + (PNG_VALID_tIME) + + png_set_bKGD(png_ptr, info_ptr, background); + + background - background color (of type + png_color_16p) (PNG_VALID_bKGD) + + png_set_text(png_ptr, info_ptr, text_ptr, num_text); + + text_ptr - array of png_text holding image + comments + + text_ptr[i].compression - type of compression used + on "text" PNG_TEXT_COMPRESSION_NONE + PNG_TEXT_COMPRESSION_zTXt + PNG_ITXT_COMPRESSION_NONE + PNG_ITXT_COMPRESSION_zTXt + text_ptr[i].key - keyword for comment. Must contain + 1-79 characters. + text_ptr[i].text - text comments for current + keyword. Can be NULL or empty. + text_ptr[i].text_length - length of text string, + after decompression, 0 for iTXt + text_ptr[i].itxt_length - length of itxt string, + after decompression, 0 for tEXt/zTXt + text_ptr[i].lang - language of comment (NULL or + empty for unknown). + text_ptr[i].translated_keyword - keyword in UTF-8 (NULL + or empty for unknown). + + Note that the itxt_length, lang, and lang_key + members of the text_ptr structure only exist when the + library is built with iTXt chunk support. Prior to + libpng-1.4.0 the library was built by default without + iTXt support. Also note that when iTXt is supported, + they contain NULL pointers when the "compression" + field contains PNG_TEXT_COMPRESSION_NONE or + PNG_TEXT_COMPRESSION_zTXt. + + num_text - number of comments + + png_set_sPLT(png_ptr, info_ptr, &palette_ptr, + num_spalettes); + + palette_ptr - array of png_sPLT_struct structures + to be added to the list of palettes + in the info structure. + num_spalettes - number of palette structures to be + added. + + png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, + unit_type); + + offset_x - positive offset from the left + edge of the screen + + offset_y - positive offset from the top + edge of the screen + + unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER + + png_set_pHYs(png_ptr, info_ptr, res_x, res_y, + unit_type); + + res_x - pixels/unit physical resolution + in x direction + + res_y - pixels/unit physical resolution + in y direction + + unit_type - PNG_RESOLUTION_UNKNOWN, + PNG_RESOLUTION_METER + + png_set_sCAL(png_ptr, info_ptr, unit, width, height) + + unit - physical scale units (an integer) + + width - width of a pixel in physical scale units + + height - height of a pixel in physical scale units + (width and height are doubles) + + png_set_sCAL_s(png_ptr, info_ptr, unit, width, height) + + unit - physical scale units (an integer) + + width - width of a pixel in physical scale units + expressed as a string + + height - height of a pixel in physical scale units + (width and height are strings like "2.54") + + png_set_unknown_chunks(png_ptr, info_ptr, &unknowns, + num_unknowns) + + unknowns - array of png_unknown_chunk + structures holding unknown chunks + unknowns[i].name - name of unknown chunk + unknowns[i].data - data of unknown chunk + unknowns[i].size - size of unknown chunk's data + unknowns[i].location - position to write chunk in file + 0: do not write chunk + PNG_HAVE_IHDR: before PLTE + PNG_HAVE_PLTE: before IDAT + PNG_AFTER_IDAT: after IDAT + +The "location" member is set automatically according to +what part of the output file has already been written. +You can change its value after calling png_set_unknown_chunks() +as demonstrated in pngtest.c. Within each of the "locations", +the chunks are sequenced according to their position in the +structure (that is, the value of "i", which is the order in which +the chunk was either read from the input file or defined with +png_set_unknown_chunks). + +A quick word about text and num_text. text is an array of png_text +structures. num_text is the number of valid structures in the array. +Each png_text structure holds a language code, a keyword, a text value, +and a compression type. + +The compression types have the same valid numbers as the compression +types of the image data. Currently, the only valid number is zero. +However, you can store text either compressed or uncompressed, unlike +images, which always have to be compressed. So if you don't want the +text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE. +Because tEXt and zTXt chunks don't have a language field, if you +specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt +any language code or translated keyword will not be written out. + +Until text gets around a few hundred bytes, it is not worth compressing it. +After the text has been written out to the file, the compression type +is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR, +so that it isn't written out again at the end (in case you are calling +png_write_end() with the same struct). + +The keywords that are given in the PNG Specification are: + + Title Short (one line) title or + caption for image + + Author Name of image's creator + + Description Description of image (possibly long) + + Copyright Copyright notice + + Creation Time Time of original image creation + (usually RFC 1123 format, see below) + + Software Software used to create the image + + Disclaimer Legal disclaimer + + Warning Warning of nature of content + + Source Device used to create the image + + Comment Miscellaneous comment; conversion + from other image format + +The keyword-text pairs work like this. Keywords should be short +simple descriptions of what the comment is about. Some typical +keywords are found in the PNG specification, as is some recommendations +on keywords. You can repeat keywords in a file. You can even write +some text before the image and some after. For example, you may want +to put a description of the image before the image, but leave the +disclaimer until after, so viewers working over modem connections +don't have to wait for the disclaimer to go over the modem before +they start seeing the image. Finally, keywords should be full +words, not abbreviations. Keywords and text are in the ISO 8859-1 +(Latin-1) character set (a superset of regular ASCII) and can not +contain NUL characters, and should not contain control or other +unprintable characters. To make the comments widely readable, stick +with basic ASCII, and avoid machine specific character set extensions +like the IBM-PC character set. The keyword must be present, but +you can leave off the text string on non-compressed pairs. +Compressed pairs must have a text string, as only the text string +is compressed anyway, so the compression would be meaningless. + +PNG supports modification time via the png_time structure. Two +conversion routines are provided, png_convert_from_time_t() for +time_t and png_convert_from_struct_tm() for struct tm. The +time_t routine uses gmtime(). You don't have to use either of +these, but if you wish to fill in the png_time structure directly, +you should provide the time in universal time (GMT) if possible +instead of your local time. Note that the year number is the full +year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and +that months start with 1. + +If you want to store the time of the original image creation, you should +use a plain tEXt chunk with the "Creation Time" keyword. This is +necessary because the "creation time" of a PNG image is somewhat vague, +depending on whether you mean the PNG file, the time the image was +created in a non-PNG format, a still photo from which the image was +scanned, or possibly the subject matter itself. In order to facilitate +machine-readable dates, it is recommended that the "Creation Time" +tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"), +although this isn't a requirement. Unlike the tIME chunk, the +"Creation Time" tEXt chunk is not expected to be automatically changed +by the software. To facilitate the use of RFC 1123 dates, a function +png_convert_to_rfc1123(png_ptr, png_timep) is provided to convert +from PNG time to an RFC 1123 format string. + +.SS Writing unknown chunks + +You can use the png_set_unknown_chunks function to queue up chunks +for writing. You give it a chunk name, raw data, and a size; that's +all there is to it. The chunks will be written by the next following +png_write_info_before_PLTE, png_write_info, or png_write_end function. +Any chunks previously read into the info structure's unknown-chunk +list will also be written out in a sequence that satisfies the PNG +specification's ordering rules. + +.SS The high-level write interface + +At this point there are two ways to proceed; through the high-level +write interface, or through a sequence of low-level write operations. +You can use the high-level interface if your image data is present +in the info structure. All defined output +transformations are permitted, enabled by the following masks. + + PNG_TRANSFORM_IDENTITY No transformation + PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples + PNG_TRANSFORM_PACKSWAP Change order of packed + pixels to LSB first + PNG_TRANSFORM_INVERT_MONO Invert monochrome images + PNG_TRANSFORM_SHIFT Normalize pixels to the + sBIT depth + PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA + to BGRA + PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA + to AG + PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity + to transparency + PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples + PNG_TRANSFORM_STRIP_FILLER Strip out filler + bytes (deprecated). + PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading + filler bytes + PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing + filler bytes + +If you have valid image data in the info structure (you can use +png_set_rows() to put image data in the info structure), simply do this: + + png_write_png(png_ptr, info_ptr, png_transforms, NULL) + +where png_transforms is an integer containing the bitwise OR of some set of +transformation flags. This call is equivalent to png_write_info(), +followed the set of transformations indicated by the transform mask, +then png_write_image(), and finally png_write_end(). + +(The final parameter of this call is not yet used. Someday it might point +to transformation parameters required by some future output transform.) + +You must use png_transforms and not call any png_set_transform() functions +when you use png_write_png(). + +.SS The low-level write interface + +If you are going the low-level route instead, you are now ready to +write all the file information up to the actual image data. You do +this with a call to png_write_info(). + + png_write_info(png_ptr, info_ptr); + +Note that there is one transformation you may need to do before +png_write_info(). In PNG files, the alpha channel in an image is the +level of opacity. If your data is supplied as a level of transparency, +you can invert the alpha channel before you write it, so that 0 is +fully transparent and 255 (in 8-bit or paletted images) or 65535 +(in 16-bit images) is fully opaque, with + + png_set_invert_alpha(png_ptr); + +This must appear before png_write_info() instead of later with the +other transformations because in the case of paletted images the tRNS +chunk data has to be inverted before the tRNS chunk is written. If +your image is not a paletted image, the tRNS data (which in such cases +represents a single color to be rendered as transparent) won't need to +be changed, and you can safely do this transformation after your +png_write_info() call. + +If you need to write a private chunk that you want to appear before +the PLTE chunk when PLTE is present, you can write the PNG info in +two steps, and insert code to write your own chunk between them: + + png_write_info_before_PLTE(png_ptr, info_ptr); + png_set_unknown_chunks(png_ptr, info_ptr, ...); + png_write_info(png_ptr, info_ptr); + +After you've written the file information, you can set up the library +to handle any special transformations of the image data. The various +ways to transform the data will be described in the order that they +should occur. This is important, as some of these change the color +type and/or bit depth of the data, and some others only work on +certain color types and bit depths. Even though each transformation +checks to see if it has data that it can do something with, you should +make sure to only enable a transformation if it will be valid for the +data. For example, don't swap red and blue on grayscale data. + +PNG files store RGB pixels packed into 3 or 6 bytes. This code tells +the library to strip input data that has 4 or 8 bytes per pixel down +to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2 +bytes per pixel). + + png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); + +where the 0 is unused, and the location is either PNG_FILLER_BEFORE or +PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel +is stored XRGB or RGBX. + +PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as +they can, resulting in, for example, 8 pixels per byte for 1 bit files. +If the data is supplied at 1 pixel per byte, use this code, which will +correctly pack the pixels into a single byte: + + png_set_packing(png_ptr); + +PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your +data is of another bit depth, you can write an sBIT chunk into the +file so that decoders can recover the original data if desired. + + /* Set the true bit depth of the image data */ + if (color_type & PNG_COLOR_MASK_COLOR) + { + sig_bit.red = true_bit_depth; + sig_bit.green = true_bit_depth; + sig_bit.blue = true_bit_depth; + } + + else + { + sig_bit.gray = true_bit_depth; + } + + if (color_type & PNG_COLOR_MASK_ALPHA) + { + sig_bit.alpha = true_bit_depth; + } + + png_set_sBIT(png_ptr, info_ptr, &sig_bit); + +If the data is stored in the row buffer in a bit depth other than +one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG), +this will scale the values to appear to be the correct bit depth as +is required by PNG. + + png_set_shift(png_ptr, &sig_bit); + +PNG files store 16-bit pixels in network byte order (big-endian, +ie. most significant bits first). This code would be used if they are +supplied the other way (little-endian, i.e. least significant bits +first, the way PCs store them): + + if (bit_depth > 8) + png_set_swap(png_ptr); + +If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you +need to change the order the pixels are packed into bytes, you can use: + + if (bit_depth < 8) + png_set_packswap(png_ptr); + +PNG files store 3 color pixels in red, green, blue order. This code +would be used if they are supplied as blue, green, red: + + png_set_bgr(png_ptr); + +PNG files describe monochrome as black being zero and white being +one. This code would be used if the pixels are supplied with this reversed +(black being one and white being zero): + + png_set_invert_mono(png_ptr); + +Finally, you can write your own transformation function if none of +the existing ones meets your needs. This is done by setting a callback +with + + png_set_write_user_transform_fn(png_ptr, + write_transform_fn); + +You must supply the function + + void write_transform_fn(png_structp png_ptr, png_row_infop + row_info, png_bytep data) + +See pngtest.c for a working example. Your function will be called +before any of the other transformations are processed. If supported +libpng also supplies an information routine that may be called from +your callback: + + png_get_current_row_number(png_ptr); + png_get_current_pass_number(png_ptr); + +This returns the current row passed to the transform. With interlaced +images the value returned is the row in the input sub-image image. Use +PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to +find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass). + +The discussion of interlace handling above contains more information on how to +use these values. + +You can also set up a pointer to a user structure for use by your +callback function. + + png_set_user_transform_info(png_ptr, user_ptr, 0, 0); + +The user_channels and user_depth parameters of this function are ignored +when writing; you can set them to zero as shown. + +You can retrieve the pointer via the function png_get_user_transform_ptr(). +For example: + + voidp write_user_transform_ptr = + png_get_user_transform_ptr(png_ptr); + +It is possible to have libpng flush any pending output, either manually, +or automatically after a certain number of lines have been written. To +flush the output stream a single time call: + + png_write_flush(png_ptr); + +and to have libpng flush the output stream periodically after a certain +number of scanlines have been written, call: + + png_set_flush(png_ptr, nrows); + +Note that the distance between rows is from the last time png_write_flush() +was called, or the first row of the image if it has never been called. +So if you write 50 lines, and then png_set_flush 25, it will flush the +output on the next scanline, and every 25 lines thereafter, unless +png_write_flush() is called before 25 more lines have been written. +If nrows is too small (less than about 10 lines for a 640 pixel wide +RGB image) the image compression may decrease noticeably (although this +may be acceptable for real-time applications). Infrequent flushing will +only degrade the compression performance by a few percent over images +that do not use flushing. + +.SS Writing the image data + +That's it for the transformations. Now you can write the image data. +The simplest way to do this is in one function call. If you have the +whole image in memory, you can just call png_write_image() and libpng +will write the image. You will need to pass in an array of pointers to +each row. This function automatically handles interlacing, so you don't +need to call png_set_interlace_handling() or call this function multiple +times, or any of that other stuff necessary with png_write_rows(). + + png_write_image(png_ptr, row_pointers); + +where row_pointers is: + + png_byte *row_pointers[height]; + +You can point to void or char or whatever you use for pixels. + +If you don't want to write the whole image at once, you can +use png_write_rows() instead. If the file is not interlaced, +this is simple: + + png_write_rows(png_ptr, row_pointers, + number_of_rows); + +row_pointers is the same as in the png_write_image() call. + +If you are just writing one row at a time, you can do this with +a single row_pointer instead of an array of row_pointers: + + png_bytep row_pointer = row; + + png_write_row(png_ptr, row_pointer); + +When the file is interlaced, things can get a good deal more complicated. +The only currently (as of the PNG Specification version 1.2, dated July +1999) defined interlacing scheme for PNG files is the "Adam7" interlace +scheme, that breaks down an image into seven smaller images of varying +size. libpng will build these images for you, or you can do them +yourself. If you want to build them yourself, see the PNG specification +for details of which pixels to write when. + +If you don't want libpng to handle the interlacing details, just +use png_set_interlace_handling() and call png_write_rows() the +correct number of times to write all the sub-images +(png_set_interlace_handling() returns the number of sub-images.) + +If you want libpng to build the sub-images, call this before you start +writing any rows: + + number_of_passes = png_set_interlace_handling(png_ptr); + +This will return the number of passes needed. Currently, this is seven, +but may change if another interlace type is added. + +Then write the complete image number_of_passes times. + + png_write_rows(png_ptr, row_pointers, number_of_rows); + +Think carefully before you write an interlaced image. Typically code that +reads such images reads all the image data into memory, uncompressed, before +doing any processing. Only code that can display an image on the fly can +take advantage of the interlacing and even then the image has to be exactly +the correct size for the output device, because scaling an image requires +adjacent pixels and these are not available until all the passes have been +read. + +If you do write an interlaced image you will hardly ever need to handle +the interlacing yourself. Call png_set_interlace_handling() and use the +approach described above. + +The only time it is conceivable that you will really need to write an +interlaced image pass-by-pass is when you have read one pass by pass and +made some pixel-by-pixel transformation to it, as described in the read +code above. In this case use the PNG_PASS_ROWS and PNG_PASS_COLS macros +to determine the size of each sub-image in turn and simply write the rows +you obtained from the read code. + +.SS Finishing a sequential write + +After you are finished writing the image, you should finish writing +the file. If you are interested in writing comments or time, you should +pass an appropriately filled png_info pointer. If you are not interested, +you can pass NULL. + + png_write_end(png_ptr, info_ptr); + +When you are done, you can free all memory used by libpng like this: + + png_destroy_write_struct(&png_ptr, &info_ptr); + +It is also possible to individually free the info_ptr members that +point to libpng-allocated storage with the following function: + + png_free_data(png_ptr, info_ptr, mask, seq) + + mask - identifies data to be freed, a mask + containing the bitwise OR of one or + more of + PNG_FREE_PLTE, PNG_FREE_TRNS, + PNG_FREE_HIST, PNG_FREE_ICCP, + PNG_FREE_PCAL, PNG_FREE_ROWS, + PNG_FREE_SCAL, PNG_FREE_SPLT, + PNG_FREE_TEXT, PNG_FREE_UNKN, + or simply PNG_FREE_ALL + + seq - sequence number of item to be freed + (-1 for all items) + +This function may be safely called when the relevant storage has +already been freed, or has not yet been allocated, or was allocated +by the user and not by libpng, and will in those cases do nothing. +The "seq" parameter is ignored if only one item of the selected data +type, such as PLTE, is allowed. If "seq" is not -1, and multiple items +are allowed for the data type identified in the mask, such as text or +sPLT, only the n'th item in the structure is freed, where n is "seq". + +If you allocated data such as a palette that you passed in to libpng +with png_set_*, you must not free it until just before the call to +png_destroy_write_struct(). + +The default behavior is only to free data that was allocated internally +by libpng. This can be changed, so that libpng will not free the data, +or so that it will free data that was allocated by the user with png_malloc() +or png_calloc() and passed in via a png_set_*() function, with + + png_data_freer(png_ptr, info_ptr, freer, mask) + + freer - one of + PNG_DESTROY_WILL_FREE_DATA + PNG_SET_WILL_FREE_DATA + PNG_USER_WILL_FREE_DATA + + mask - which data elements are affected + same choices as in png_free_data() + +For example, to transfer responsibility for some data from a read structure +to a write structure, you could use + + png_data_freer(read_ptr, read_info_ptr, + PNG_USER_WILL_FREE_DATA, + PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST) + + png_data_freer(write_ptr, write_info_ptr, + PNG_DESTROY_WILL_FREE_DATA, + PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST) + +thereby briefly reassigning responsibility for freeing to the user but +immediately afterwards reassigning it once more to the write_destroy +function. Having done this, it would then be safe to destroy the read +structure and continue to use the PLTE, tRNS, and hIST data in the write +structure. + +This function only affects data that has already been allocated. +You can call this function before calling after the png_set_*() functions +to control whether the user or png_destroy_*() is supposed to free the data. +When the user assumes responsibility for libpng-allocated data, the +application must use +png_free() to free it, and when the user transfers responsibility to libpng +for data that the user has allocated, the user must have used png_malloc() +or png_calloc() to allocate it. + +If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword +separately, do not transfer responsibility for freeing text_ptr to libpng, +because when libpng fills a png_text structure it combines these members with +the key member, and png_free_data() will free only text_ptr.key. Similarly, +if you transfer responsibility for free'ing text_ptr from libpng to your +application, your application must not separately free those members. +For a more compact example of writing a PNG image, see the file example.c. + +.SH V. Modifying/Customizing libpng: + +There are two issues here. The first is changing how libpng does +standard things like memory allocation, input/output, and error handling. +The second deals with more complicated things like adding new chunks, +adding new transformations, and generally changing how libpng works. +Both of those are compile-time issues; that is, they are generally +determined at the time the code is written, and there is rarely a need +to provide the user with a means of changing them. + +Memory allocation, input/output, and error handling + +All of the memory allocation, input/output, and error handling in libpng +goes through callbacks that are user-settable. The default routines are +in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change +these functions, call the appropriate png_set_*_fn() function. + +Memory allocation is done through the functions png_malloc(), png_calloc(), +and png_free(). The png_malloc() and png_free() functions currently just +call the standard C functions and png_calloc() calls png_malloc() and then +clears the newly allocated memory to zero; note that png_calloc(png_ptr, size) +is not the same as the calloc(number, size) function provided by stdlib.h. +There is limited support for certain systems with segmented memory +architectures and the types of pointers declared by png.h match this; you +will have to use appropriate pointers in your application. Since it is +unlikely that the method of handling memory allocation on a platform +will change between applications, these functions must be modified in +the library at compile time. If you prefer to use a different method +of allocating and freeing data, you can use png_create_read_struct_2() or +png_create_write_struct_2() to register your own functions as described +above. These functions also provide a void pointer that can be retrieved +via + + mem_ptr=png_get_mem_ptr(png_ptr); + +Your replacement memory functions must have prototypes as follows: + + png_voidp malloc_fn(png_structp png_ptr, + png_alloc_size_t size); + + void free_fn(png_structp png_ptr, png_voidp ptr); + +Your malloc_fn() must return NULL in case of failure. The png_malloc() +function will normally call png_error() if it receives a NULL from the +system memory allocator or from your replacement malloc_fn(). + +Your free_fn() will never be called with a NULL ptr, since libpng's +png_free() checks for NULL before calling free_fn(). + +Input/Output in libpng is done through png_read() and png_write(), +which currently just call fread() and fwrite(). The FILE * is stored in +png_struct and is initialized via png_init_io(). If you wish to change +the method of I/O, the library supplies callbacks that you can set +through the function png_set_read_fn() and png_set_write_fn() at run +time, instead of calling the png_init_io() function. These functions +also provide a void pointer that can be retrieved via the function +png_get_io_ptr(). For example: + + png_set_read_fn(png_structp read_ptr, + voidp read_io_ptr, png_rw_ptr read_data_fn) + + png_set_write_fn(png_structp write_ptr, + voidp write_io_ptr, png_rw_ptr write_data_fn, + png_flush_ptr output_flush_fn); + + voidp read_io_ptr = png_get_io_ptr(read_ptr); + voidp write_io_ptr = png_get_io_ptr(write_ptr); + +The replacement I/O functions must have prototypes as follows: + + void user_read_data(png_structp png_ptr, + png_bytep data, png_size_t length); + + void user_write_data(png_structp png_ptr, + png_bytep data, png_size_t length); + + void user_flush_data(png_structp png_ptr); + +The user_read_data() function is responsible for detecting and +handling end-of-data errors. + +Supplying NULL for the read, write, or flush functions sets them back +to using the default C stream functions, which expect the io_ptr to +point to a standard *FILE structure. It is probably a mistake +to use NULL for one of write_data_fn and output_flush_fn but not both +of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined. +It is an error to read from a write stream, and vice versa. + +Error handling in libpng is done through png_error() and png_warning(). +Errors handled through png_error() are fatal, meaning that png_error() +should never return to its caller. Currently, this is handled via +setjmp() and longjmp() (unless you have compiled libpng with +PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()), +but you could change this to do things like exit() if you should wish, +as long as your function does not return. + +On non-fatal errors, png_warning() is called +to print a warning message, and then control returns to the calling code. +By default png_error() and png_warning() print a message on stderr via +fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined +(because you don't want the messages) or PNG_NO_STDIO defined (because +fprintf() isn't available). If you wish to change the behavior of the error +functions, you will need to set up your own message callbacks. These +functions are normally supplied at the time that the png_struct is created. +It is also possible to redirect errors and warnings to your own replacement +functions after png_create_*_struct() has been called by calling: + + png_set_error_fn(png_structp png_ptr, + png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warning_fn); + + png_voidp error_ptr = png_get_error_ptr(png_ptr); + +If NULL is supplied for either error_fn or warning_fn, then the libpng +default function will be used, calling fprintf() and/or longjmp() if a +problem is encountered. The replacement error functions should have +parameters as follows: + + void user_error_fn(png_structp png_ptr, + png_const_charp error_msg); + + void user_warning_fn(png_structp png_ptr, + png_const_charp warning_msg); + +The motivation behind using setjmp() and longjmp() is the C++ throw and +catch exception handling methods. This makes the code much easier to write, +as there is no need to check every return code of every function call. +However, there are some uncertainties about the status of local variables +after a longjmp, so the user may want to be careful about doing anything +after setjmp returns non-zero besides returning itself. Consult your +compiler documentation for more details. For an alternative approach, you +may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net), +which is illustrated in pngvalid.c and in contrib/visupng. + +.SS Custom chunks + +If you need to read or write custom chunks, you may need to get deeper +into the libpng code. The library now has mechanisms for storing +and writing chunks of unknown type; you can even declare callbacks +for custom chunks. However, this may not be good enough if the +library code itself needs to know about interactions between your +chunk and existing `intrinsic' chunks. + +If you need to write a new intrinsic chunk, first read the PNG +specification. Acquire a first level of understanding of how it works. +Pay particular attention to the sections that describe chunk names, +and look at how other chunks were designed, so you can do things +similarly. Second, check out the sections of libpng that read and +write chunks. Try to find a chunk that is similar to yours and use +it as a template. More details can be found in the comments inside +the code. It is best to handle private or unknown chunks in a generic method, +via callback functions, instead of by modifying libpng functions. This +is illustrated in pngtest.c, which uses a callback function to handle a +private "vpAg" chunk and the new "sTER" chunk, which are both unknown to +libpng. + +If you wish to write your own transformation for the data, look through +the part of the code that does the transformations, and check out some of +the simpler ones to get an idea of how they work. Try to find a similar +transformation to the one you want to add and copy off of it. More details +can be found in the comments inside the code itself. + +.SS Configuring for 16-bit platforms + +You will want to look into zconf.h to tell zlib (and thus libpng) that +it cannot allocate more then 64K at a time. Even if you can, the memory +won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K. + +.SS Configuring for DOS + +For DOS users who only have access to the lower 640K, you will +have to limit zlib's memory usage via a png_set_compression_mem_level() +call. See zlib.h or zconf.h in the zlib library for more information. + +.SS Configuring for Medium Model + +Libpng's support for medium model has been tested on most of the popular +compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets +defined, and FAR gets defined to far in pngconf.h, and you should be +all set. Everything in the library (except for zlib's structure) is +expecting far data. You must use the typedefs with the p or pp on +the end for pointers (or at least look at them and be careful). Make +note that the rows of data are defined as png_bytepp, which is +an "unsigned char far * far *". + +.SS Configuring for gui/windowing platforms: + +You will need to write new error and warning functions that use the GUI +interface, as described previously, and set them to be the error and +warning functions at the time that png_create_*_struct() is called, +in order to have them available during the structure initialization. +They can be changed later via png_set_error_fn(). On some compilers, +you may also have to change the memory allocators (png_malloc, etc.). + +.SS Configuring for compiler xxx: + +All includes for libpng are in pngconf.h. If you need to add, change +or delete an include, this is the place to do it. +The includes that are not needed outside libpng are placed in pngpriv.h, +which is only used by the routines inside libpng itself. +The files in libpng proper only include pngpriv.h and png.h, which +%14%in turn includes pngconf.h. +in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h. +As of libpng-1.5.0, pngpriv.h also includes three other private header +files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material +that previously appeared in the public headers. + +.SS Configuring zlib: + +There are special functions to configure the compression. Perhaps the +most useful one changes the compression level, which currently uses +input compression values in the range 0 - 9. The library normally +uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests +have shown that for a large majority of images, compression values in +the range 3-6 compress nearly as well as higher levels, and do so much +faster. For online applications it may be desirable to have maximum speed +(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also +specify no compression (Z_NO_COMPRESSION = 0), but this would create +files larger than just storing the raw bitmap. You can specify the +compression level by calling: + + #include zlib.h + png_set_compression_level(png_ptr, level); + +Another useful one is to reduce the memory level used by the library. +The memory level defaults to 8, but it can be lowered if you are +short on memory (running DOS, for example, where you only have 640K). +Note that the memory level does have an effect on compression; among +other things, lower levels will result in sections of incompressible +data being emitted in smaller stored blocks, with a correspondingly +larger relative overhead of up to 15% in the worst case. + + #include zlib.h + png_set_compression_mem_level(png_ptr, level); + +The other functions are for configuring zlib. They are not recommended +for normal use and may result in writing an invalid PNG file. See +zlib.h for more information on what these mean. + + #include zlib.h + png_set_compression_strategy(png_ptr, + strategy); + + png_set_compression_window_bits(png_ptr, + window_bits); + + png_set_compression_method(png_ptr, method); + + png_set_compression_buffer_size(png_ptr, size); + +As of libpng version 1.5.4, additional APIs became +available to set these separately for non-IDAT +compressed chunks such as zTXt, iTXt, and iCCP: + + #include zlib.h + #if PNG_LIBPNG_VER >= 10504 + png_set_text_compression_level(png_ptr, level); + + png_set_text_compression_mem_level(png_ptr, level); + + png_set_text_compression_strategy(png_ptr, + strategy); + + png_set_text_compression_window_bits(png_ptr, + window_bits); + + png_set_text_compression_method(png_ptr, method); + #endif + +.SS Controlling row filtering + +If you want to control whether libpng uses filtering or not, which +filters are used, and how it goes about picking row filters, you +can call one of these functions. The selection and configuration +of row filters can have a significant impact on the size and +encoding speed and a somewhat lesser impact on the decoding speed +of an image. Filtering is enabled by default for RGB and grayscale +images (with and without alpha), but not for paletted images nor +for any images with bit depths less than 8 bits/pixel. + +The 'method' parameter sets the main filtering method, which is +currently only '0' in the PNG 1.2 specification. The 'filters' +parameter sets which filter(s), if any, should be used for each +scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS +to turn filtering on and off, respectively. + +Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB, +PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise +ORed together with '|' to specify one or more filters to use. +These filters are described in more detail in the PNG specification. +If you intend to change the filter type during the course of writing +the image, you should start with flags set for all of the filters +you intend to use so that libpng can initialize its internal +structures appropriately for all of the filter types. (Note that this +means the first row must always be adaptively filtered, because libpng +currently does not allocate the filter buffers until png_write_row() +is called for the first time.) + + filters = PNG_FILTER_NONE | PNG_FILTER_SUB + PNG_FILTER_UP | PNG_FILTER_AVG | + PNG_FILTER_PAETH | PNG_ALL_FILTERS; + + png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, + filters); + The second parameter can also be + PNG_INTRAPIXEL_DIFFERENCING if you are + writing a PNG to be embedded in a MNG + datastream. This parameter must be the + same as the value of filter_method used + in png_set_IHDR(). + +It is also possible to influence how libpng chooses from among the +available filters. This is done in one or both of two ways - by +telling it how important it is to keep the same filter for successive +rows, and by telling it the relative computational costs of the filters. + + double weights[3] = {1.5, 1.3, 1.1}, + costs[PNG_FILTER_VALUE_LAST] = + {1.0, 1.3, 1.3, 1.5, 1.7}; + + png_set_filter_heuristics(png_ptr, + PNG_FILTER_HEURISTIC_WEIGHTED, 3, + weights, costs); + +The weights are multiplying factors that indicate to libpng that the +row filter should be the same for successive rows unless another row filter +is that many times better than the previous filter. In the above example, +if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a +"sum of absolute differences" 1.5 x 1.3 times higher than other filters +and still be chosen, while the NONE filter could have a sum 1.1 times +higher than other filters and still be chosen. Unspecified weights are +taken to be 1.0, and the specified weights should probably be declining +like those above in order to emphasize recent filters over older filters. + +The filter costs specify for each filter type a relative decoding cost +to be considered when selecting row filters. This means that filters +with higher costs are less likely to be chosen over filters with lower +costs, unless their "sum of absolute differences" is that much smaller. +The costs do not necessarily reflect the exact computational speeds of +the various filters, since this would unduly influence the final image +size. + +Note that the numbers above were invented purely for this example and +are given only to help explain the function usage. Little testing has +been done to find optimum values for either the costs or the weights. + +.SS Removing unwanted object code + +There are a bunch of #define's in pngconf.h that control what parts of +libpng are compiled. All the defines end in _SUPPORTED. If you are +never going to use a capability, you can change the #define to #undef +before recompiling libpng and save yourself code and data space, or +you can turn off individual capabilities with defines that begin with +PNG_NO_. + +In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead. + +You can also turn all of the transforms and ancillary chunk capabilities +off en masse with compiler directives that define +PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS, +or all four, +along with directives to turn on any of the capabilities that you do +want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra +transformations but still leave the library fully capable of reading +and writing PNG files with all known public chunks. Use of the +PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library +that is incapable of reading or writing ancillary chunks. If you are +not using the progressive reading capability, you can turn that off +with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING +capability, which you'll still have). + +All the reading and writing specific code are in separate files, so the +linker should only grab the files it needs. However, if you want to +make sure, or if you are building a stand alone library, all the +reading files start with "pngr" and all the writing files start with "pngw". +The files that don't match either (like png.c, pngtrans.c, etc.) +are used for both reading and writing, and always need to be included. +The progressive reader is in pngpread.c + +If you are creating or distributing a dynamically linked library (a .so +or DLL file), you should not remove or disable any parts of the library, +as this will cause applications linked with different versions of the +library to fail if they call functions not available in your library. +The size of the library itself should not be an issue, because only +those sections that are actually used will be loaded into memory. + +.SS Requesting debug printout + +The macro definition PNG_DEBUG can be used to request debugging +printout. Set it to an integer value in the range 0 to 3. Higher +numbers result in increasing amounts of debugging information. The +information is printed to the "stderr" file, unless another file +name is specified in the PNG_DEBUG_FILE macro definition. + +When PNG_DEBUG > 0, the following functions (macros) become available: + + png_debug(level, message) + png_debug1(level, message, p1) + png_debug2(level, message, p1, p2) + +in which "level" is compared to PNG_DEBUG to decide whether to print +the message, "message" is the formatted string to be printed, +and p1 and p2 are parameters that are to be embedded in the string +according to printf-style formatting directives. For example, + + png_debug1(2, "foo=%d\n", foo); + +is expanded to + + if (PNG_DEBUG > 2) + fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo); + +When PNG_DEBUG is defined but is zero, the macros aren't defined, but you +can still use PNG_DEBUG to control your own debugging: + + #ifdef PNG_DEBUG + fprintf(stderr, ... + #endif + +When PNG_DEBUG = 1, the macros are defined, but only png_debug statements +having level = 0 will be printed. There aren't any such statements in +this version of libpng, but if you insert some they will be printed. + +.SH VI. MNG support + +The MNG specification (available at http://www.libpng.org/pub/mng) allows +certain extensions to PNG for PNG images that are embedded in MNG datastreams. +Libpng can support some of these extensions. To enable them, use the +png_permit_mng_features() function: + + feature_set = png_permit_mng_features(png_ptr, mask) + + mask is a png_uint_32 containing the bitwise OR of the + features you want to enable. These include + PNG_FLAG_MNG_EMPTY_PLTE + PNG_FLAG_MNG_FILTER_64 + PNG_ALL_MNG_FEATURES + + feature_set is a png_uint_32 that is the bitwise AND of + your mask with the set of MNG features that is + supported by the version of libpng that you are using. + +It is an error to use this function when reading or writing a standalone +PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped +in a MNG datastream. As a minimum, it must have the MNG 8-byte signature +and the MHDR and MEND chunks. Libpng does not provide support for these +or any other MNG chunks; your application must provide its own support for +them. You may wish to consider using libmng (available at +http://www.libmng.com) instead. + +.SH VII. Changes to Libpng from version 0.88 + +It should be noted that versions of libpng later than 0.96 are not +distributed by the original libpng author, Guy Schalnat, nor by +Andreas Dilger, who had taken over from Guy during 1996 and 1997, and +distributed versions 0.89 through 0.96, but rather by another member +of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are +still alive and well, but they have moved on to other things. + +The old libpng functions png_read_init(), png_write_init(), +png_info_init(), png_read_destroy(), and png_write_destroy() have been +moved to PNG_INTERNAL in version 0.95 to discourage their use. These +functions will be removed from libpng version 1.4.0. + +The preferred method of creating and initializing the libpng structures is +via the png_create_read_struct(), png_create_write_struct(), and +png_create_info_struct() because they isolate the size of the structures +from the application, allow version error checking, and also allow the +use of custom error handling routines during the initialization, which +the old functions do not. The functions png_read_destroy() and +png_write_destroy() do not actually free the memory that libpng +allocated for these structs, but just reset the data structures, so they +can be used instead of png_destroy_read_struct() and +png_destroy_write_struct() if you feel there is too much system overhead +allocating and freeing the png_struct for each image read. + +Setting the error callbacks via png_set_message_fn() before +png_read_init() as was suggested in libpng-0.88 is no longer supported +because this caused applications that do not use custom error functions +to fail if the png_ptr was not initialized to zero. It is still possible +to set the error callbacks AFTER png_read_init(), or to change them with +png_set_error_fn(), which is essentially the same function, but with a new +name to force compilation errors with applications that try to use the old +method. + +Starting with version 1.0.7, you can find out which version of the library +you are using at run-time: + + png_uint_32 libpng_vn = png_access_version_number(); + +The number libpng_vn is constructed from the major version, minor +version with leading zero, and release number with leading zero, +(e.g., libpng_vn for version 1.0.7 is 10007). + +Note that this function does not take a png_ptr, so you can call it +before you've created one. + +You can also check which version of png.h you used when compiling your +application: + + png_uint_32 application_vn = PNG_LIBPNG_VER; + +.SH VIII. Changes to Libpng from version 1.0.x to 1.2.x + +Support for user memory management was enabled by default. To +accomplish this, the functions png_create_read_struct_2(), +png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(), +png_malloc_default(), and png_free_default() were added. + +Support for the iTXt chunk has been enabled by default as of +version 1.2.41. + +Support for certain MNG features was enabled. + +Support for numbered error messages was added. However, we never got +around to actually numbering the error messages. The function +png_set_strip_error_numbers() was added (Note: the prototype for this +function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE +builds of libpng-1.2.15. It was restored in libpng-1.2.36). + +The png_malloc_warn() function was added at libpng-1.2.3. This issues +a png_warning and returns NULL instead of aborting when it fails to +acquire the requested memory allocation. + +Support for setting user limits on image width and height was enabled +by default. The functions png_set_user_limits(), png_get_user_width_max(), +and png_get_user_height_max() were added at libpng-1.2.6. + +The png_set_add_alpha() function was added at libpng-1.2.7. + +The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9. +Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the +tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is +deprecated. + +A number of macro definitions in support of runtime selection of +assembler code features (especially Intel MMX code support) were +added at libpng-1.2.0: + + PNG_ASM_FLAG_MMX_SUPPORT_COMPILED + PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU + PNG_ASM_FLAG_MMX_READ_COMBINE_ROW + PNG_ASM_FLAG_MMX_READ_INTERLACE + PNG_ASM_FLAG_MMX_READ_FILTER_SUB + PNG_ASM_FLAG_MMX_READ_FILTER_UP + PNG_ASM_FLAG_MMX_READ_FILTER_AVG + PNG_ASM_FLAG_MMX_READ_FILTER_PAETH + PNG_ASM_FLAGS_INITIALIZED + PNG_MMX_READ_FLAGS + PNG_MMX_FLAGS + PNG_MMX_WRITE_FLAGS + PNG_MMX_FLAGS + +We added the following functions in support of runtime +selection of assembler code features: + + png_get_mmx_flagmask() + png_set_mmx_thresholds() + png_get_asm_flags() + png_get_mmx_bitdepth_threshold() + png_get_mmx_rowbytes_threshold() + png_set_asm_flags() + +We replaced all of these functions with simple stubs in libpng-1.2.20, +when the Intel assembler code was removed due to a licensing issue. + +These macros are deprecated: + + PNG_READ_TRANSFORMS_NOT_SUPPORTED + PNG_PROGRESSIVE_READ_NOT_SUPPORTED + PNG_NO_SEQUENTIAL_READ_SUPPORTED + PNG_WRITE_TRANSFORMS_NOT_SUPPORTED + PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED + PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED + +They have been replaced, respectively, by: + + PNG_NO_READ_TRANSFORMS + PNG_NO_PROGRESSIVE_READ + PNG_NO_SEQUENTIAL_READ + PNG_NO_WRITE_TRANSFORMS + PNG_NO_READ_ANCILLARY_CHUNKS + PNG_NO_WRITE_ANCILLARY_CHUNKS + +PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been +deprecated since libpng-1.0.16 and libpng-1.2.6. + +The function + png_check_sig(sig, num) +was replaced with + !png_sig_cmp(sig, 0, num) +It has been deprecated since libpng-0.90. + +The function + png_set_gray_1_2_4_to_8() +which also expands tRNS to alpha was replaced with + png_set_expand_gray_1_2_4_to_8() +which does not. It has been deprecated since libpng-1.0.18 and 1.2.9. + +.SH IX. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x + +Private libpng prototypes and macro definitions were moved from +png.h and pngconf.h into a new pngpriv.h header file. + +Functions png_set_benign_errors(), png_benign_error(), and +png_chunk_benign_error() were added. + +Support for setting the maximum amount of memory that the application +will allocate for reading chunks was added, as a security measure. +The functions png_set_chunk_cache_max() and png_get_chunk_cache_max() +were added to the library. + +We implemented support for I/O states by adding png_ptr member io_state +and functions png_get_io_chunk_name() and png_get_io_state() in pngget.c + +We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level +input transforms. + +Checking for and reporting of errors in the IHDR chunk is more thorough. + +Support for global arrays was removed, to improve thread safety. + +Some obsolete/deprecated macros and functions have been removed. + +Typecasted NULL definitions such as + #define png_voidp_NULL (png_voidp)NULL +were eliminated. If you used these in your application, just use +NULL instead. + +The png_struct and info_struct members "trans" and "trans_values" were +changed to "trans_alpha" and "trans_color", respectively. + +The obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles +were removed. + +The PNG_1_0_X and PNG_1_2_X macros were eliminated. + +The PNG_LEGACY_SUPPORTED macro was eliminated. + +Many WIN32_WCE #ifdefs were removed. + +The functions png_read_init(info_ptr), png_write_init(info_ptr), +png_info_init(info_ptr), png_read_destroy(), and png_write_destroy() +have been removed. They have been deprecated since libpng-0.95. + +The png_permit_empty_plte() was removed. It has been deprecated +since libpng-1.0.9. Use png_permit_mng_features() instead. + +We removed the obsolete stub functions png_get_mmx_flagmask(), +png_set_mmx_thresholds(), png_get_asm_flags(), +png_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(), +png_set_asm_flags(), and png_mmx_supported() + +We removed the obsolete png_check_sig(), png_memcpy_check(), and +png_memset_check() functions. Instead use !png_sig_cmp(), png_memcpy(), +and png_memset(), respectively. + +The function png_set_gray_1_2_4_to_8() was removed. It has been +deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with +png_set_expand_gray_1_2_4_to_8() because the former function also +expanded any tRNS chunk to an alpha channel. + +Macros for png_get_uint_16, png_get_uint_32, and png_get_int_32 +were added and are used by default instead of the corresponding +functions. Unfortunately, +from libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the +function) incorrectly returned a value of type png_uint_32. + +We changed the prototype for png_malloc() from + png_malloc(png_structp png_ptr, png_uint_32 size) +to + png_malloc(png_structp png_ptr, png_alloc_size_t size) + +This also applies to the prototype for the user replacement malloc_fn(). + +The png_calloc() function was added and is used in place of +of "png_malloc(); memset();" except in the case in png_read_png() +where the array consists of pointers; in this case a "for" loop is used +after the png_malloc() to set the pointers to NULL, to give robust. +behavior in case the application runs out of memory part-way through +the process. + +We changed the prototypes of png_get_compression_buffer_size() and +png_set_compression_buffer_size() to work with png_size_t instead of +png_uint_32. + +Support for numbered error messages was removed by default, since we +never got around to actually numbering the error messages. The function +png_set_strip_error_numbers() was removed from the library by default. + +The png_zalloc() and png_zfree() functions are no longer exported. +The png_zalloc() function no longer zeroes out the memory that it +allocates. Applications that called png_zalloc(png_ptr, number, size) +can call png_calloc(png_ptr, number*size) instead, and can call +png_free() instead of png_zfree(). + +Support for dithering was disabled by default in libpng-1.4.0, because +it has not been well tested and doesn't actually "dither". +The code was not +removed, however, and could be enabled by building libpng with +PNG_READ_DITHER_SUPPORTED defined. In libpng-1.4.2, this support +was reenabled, but the function was renamed png_set_quantize() to +reflect more accurately what it actually does. At the same time, +the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to +PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED +was renamed to PNG_READ_QUANTIZE_SUPPORTED. + +We removed the trailing '.' from the warning and error messages. + +.SH X. Changes to Libpng from version 1.4.x to 1.5.x + +From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the +function) incorrectly returned a value of type png_uint_32. + +Checking for invalid palette index on read or write was added at libpng +1.5.10. When an invalid index is found, libpng issues a benign error. +This is enabled by default but can be disabled in each png_ptr with + + png_set_check_for_invalid_index(png_ptr, allowed); + + allowed - one of + 0: disable + 1: enable + +A. Changes that affect users of libpng + +There are no substantial API changes between the non-deprecated parts of +the 1.4.5 API and the 1.5.0 API; however, the ability to directly access +members of the main libpng control structures, png_struct and png_info, +deprecated in earlier versions of libpng, has been completely removed from +libpng 1.5. + +We no longer include zlib.h in png.h. Applications that need access +to information in zlib.h will need to add the '#include "zlib.h"' +directive. It does not matter whether it is placed prior to or after +the '"#include png.h"' directive. + +The png_sprintf(), png_strcpy(), and png_strncpy() macros are no longer used +and were removed. + +We moved the png_strlen(), png_memcpy(), png_memset(), and png_memcmp() +macros into a private header file (pngpriv.h) that is not accessible to +applications. + +In png_get_iCCP, the type of "profile" was changed from png_charpp +to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep. + +There are changes of form in png.h, including new and changed macros to +declare parts of the API. Some API functions with arguments that are +pointers to data not modified within the function have been corrected to +declare these arguments with PNG_CONST. + +Much of the internal use of C macros to control the library build has also +changed and some of this is visible in the exported header files, in +particular the use of macros to control data and API elements visible +during application compilation may require significant revision to +application code. (It is extremely rare for an application to do this.) + +Any program that compiled against libpng 1.4 and did not use deprecated +features or access internal library structures should compile and work +against libpng 1.5, except for the change in the prototype for +png_get_iCCP() and png_set_iCCP() API functions mentioned above. + +libpng 1.5.0 adds PNG_ PASS macros to help in the reading and writing of +interlaced images. The macros return the number of rows and columns in +each pass and information that can be used to de-interlace and (if +absolutely necessary) interlace an image. + +libpng 1.5.0 adds an API png_longjmp(png_ptr, value). This API calls +the application-provided png_longjmp_ptr on the internal, but application +initialized, longjmp buffer. It is provided as a convenience to avoid +the need to use the png_jmpbuf macro, which had the unnecessary side +effect of resetting the internal png_longjmp_ptr value. + +libpng 1.5.0 includes a complete fixed point API. By default this is +present along with the corresponding floating point API. In general the +fixed point API is faster and smaller than the floating point one because +the PNG file format used fixed point, not floating point. This applies +even if the library uses floating point in internal calculations. A new +macro, PNG_FLOATING_ARITHMETIC_SUPPORTED, reveals whether the library +uses floating point arithmetic (the default) or fixed point arithmetic +internally for performance critical calculations such as gamma correction. +In some cases, the gamma calculations may produce slightly different +results. This has changed the results in png_rgb_to_gray and in alpha +composition (png_set_background for example). This applies even if the +original image was already linear (gamma == 1.0) and, therefore, it is +not necessary to linearize the image. This is because libpng has *not* +been changed to optimize that case correctly, yet. + +Fixed point support for the sCAL chunk comes with an important caveat; +the sCAL specification uses a decimal encoding of floating point values +and the accuracy of PNG fixed point values is insufficient for +representation of these values. Consequently a "string" API +(png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading +arbitrary sCAL chunks in the absence of either the floating point API or +internal floating point calculations. + +Applications no longer need to include the optional distribution header +file pngusr.h or define the corresponding macros during application +build in order to see the correct variant of the libpng API. From 1.5.0 +application code can check for the corresponding _SUPPORTED macro: + +#ifdef PNG_INCH_CONVERSIONS_SUPPORTED + /* code that uses the inch conversion APIs. */ +#endif + +This macro will only be defined if the inch conversion functions have been +compiled into libpng. The full set of macros, and whether or not support +has been compiled in, are available in the header file pnglibconf.h. +This header file is specific to the libpng build. Notice that prior to +1.5.0 the _SUPPORTED macros would always have the default definition unless +reset by pngusr.h or by explicit settings on the compiler command line. +These settings may produce compiler warnings or errors in 1.5.0 because +of macro redefinition. + +From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the +function) incorrectly returned a value of type png_uint_32. libpng 1.5.0 +is consistent with the implementation in 1.4.5 and 1.2.x (where the macro +did not exist.) + +Applications can now choose whether to use these macros or to call the +corresponding function by defining PNG_USE_READ_MACROS or +PNG_NO_USE_READ_MACROS before including png.h. Notice that this is +only supported from 1.5.0 -defining PNG_NO_USE_READ_MACROS prior to 1.5.0 +will lead to a link failure. + +Prior to libpng-1.5.4, the zlib compressor used the same set of parameters +when compressing the IDAT data and textual data such as zTXt and iCCP. +In libpng-1.5.4 we reinitialized the zlib stream for each type of data. +We added five png_set_text_*() functions for setting the parameters to +use with textual data. + +Prior to libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED +option was off by default, and slightly inaccurate scaling occurred. +This option can no longer be turned off, and the choice of accurate +or inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8() +API for accurate scaling or the old png_set_strip_16_to_8() API for simple +chopping. + +Prior to libpng-1.5.4, the png_set_user_limits() function could only be +used to reduce the width and height limits from the value of +PNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX, although this document said +that it could be used to override them. Now this function will reduce or +increase the limits. + +Starting in libpng-1.5.10, the user limits can be set en masse with the +configuration option PNG_SAFE_LIMITS_SUPPORTED. If this option is enabled, +a set of "safe" limits is applied in pngpriv.h. These can be overridden by +application calls to png_set_user_limits(), png_set_user_chunk_cache_max(), +and/or png_set_user_malloc_max() that increase or decrease the limits. Also, +in libpng-1.5.10 the default width and height limits were increased +from 1,000,000 to 0x7ffffff (i.e., made unlimited). Therefore, the +limits are now + default safe + png_user_width_max 0x7fffffff 1,000,000 + png_user_height_max 0x7fffffff 1,000,000 + png_user_chunk_cache_max 0 (unlimited) 128 + png_user_chunk_malloc_max 0 (unlimited) 8,000,000 + +B. Changes to the build and configuration of libpng + +Details of internal changes to the library code can be found in the CHANGES +file and in the GIT repository logs. These will be of no concern to the vast +majority of library users or builders; however, the few who configure libpng +to a non-default feature set may need to change how this is done. + +There should be no need for library builders to alter build scripts if +these use the distributed build support - configure or the makefiles - +however, users of the makefiles may care to update their build scripts +to build pnglibconf.h where the corresponding makefile does not do so. + +Building libpng with a non-default configuration has changed completely. +The old method using pngusr.h should still work correctly even though the +way pngusr.h is used in the build has been changed; however, library +builders will probably want to examine the changes to take advantage of +new capabilities and to simplify their build system. + +B.1 Specific changes to library configuration capabilities + +The library now supports a complete fixed point implementation and can +thus be used on systems that have no floating point support or very +limited or slow support. Previously gamma correction, an essential part +of complete PNG support, required reasonably fast floating point. + +As part of this the choice of internal implementation has been made +independent of the choice of fixed versus floating point APIs and all the +missing fixed point APIs have been implemented. + +The exact mechanism used to control attributes of API functions has +changed. A single set of operating system independent macro definitions +is used and operating system specific directives are defined in +pnglibconf.h + +As part of this the mechanism used to choose procedure call standards on +those systems that allow a choice has been changed. At present this only +affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems +running on Intel processors. As before, PNGAPI is defined where required +to control the exported API functions; however, two new macros, PNGCBAPI +and PNGCAPI, are used instead for callback functions (PNGCBAPI) and +(PNGCAPI) for functions that must match a C library prototype (currently +only png_longjmp_ptr, which must match the C longjmp function.) The new +approach is documented in pngconf.h + +Despite these changes, libpng 1.5.0 only supports the native C function +calling standard on those platforms tested so far (__cdecl on Microsoft +Windows). This is because the support requirements for alternative +calling conventions seem to no longer exist. Developers who find it +necessary to set PNG_API_RULE to 1 should advise the mailing list +(png-mng-implement) of this and library builders who use Openwatcom and +therefore set PNG_API_RULE to 2 should also contact the mailing list. + +A new test program, pngvalid, is provided in addition to pngtest. +pngvalid validates the arithmetic accuracy of the gamma correction +calculations and includes a number of validations of the file format. +A subset of the full range of tests is run when "make check" is done +(in the 'configure' build.) pngvalid also allows total allocated memory +usage to be evaluated and performs additional memory overwrite validation. + +Many changes to individual feature macros have been made. The following +are the changes most likely to be noticed by library builders who +configure libpng: + +1) All feature macros now have consistent naming: + +#define PNG_NO_feature turns the feature off +#define PNG_feature_SUPPORTED turns the feature on + +pnglibconf.h contains one line for each feature macro which is either: + +#define PNG_feature_SUPPORTED + +if the feature is supported or: + +/*#undef PNG_feature_SUPPORTED*/ + +if it is not. Library code consistently checks for the 'SUPPORTED' macro. +It does not, and libpng applications should not, check for the 'NO' macro +which will not normally be defined even if the feature is not supported. +The 'NO' macros are only used internally for setting or not setting the +corresponding 'SUPPORTED' macros. + +Compatibility with the old names is provided as follows: + +PNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED + +And the following definitions disable the corresponding feature: + +PNG_SETJMP_NOT_SUPPORTED disables SETJMP +PNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS +PNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV +PNG_WRITE_TRANSFORMS_NOT_SUPPORTED disables WRITE_TRANSFORMS +PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED disables READ_ANCILLARY_CHUNKS +PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED disables WRITE_ANCILLARY_CHUNKS + +Library builders should remove use of the above, inconsistent, names. + +2) Warning and error message formatting was previously conditional on +the STDIO feature. The library has been changed to use the +CONSOLE_IO feature instead. This means that if CONSOLE_IO is disabled +the library no longer uses the printf(3) functions, even though the +default read/write implementations use (FILE) style stdio.h functions. + +3) Three feature macros now control the fixed/floating point decisions: + +PNG_FLOATING_POINT_SUPPORTED enables the floating point APIs + +PNG_FIXED_POINT_SUPPORTED enables the fixed point APIs; however, in +practice these are normally required internally anyway (because the PNG +file format is fixed point), therefore in most cases PNG_NO_FIXED_POINT +merely stops the function from being exported. + +PNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating +point implementation or the fixed point one. Typically the fixed point +implementation is larger and slower than the floating point implementation +on a system that supports floating point; however, it may be faster on a +system which lacks floating point hardware and therefore uses a software +emulation. + +4) Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the +functions to read and write ints to be disabled independently of +PNG_USE_READ_MACROS, which allows libpng to be built with the functions +even though the default is to use the macros - this allows applications +to choose at app buildtime whether or not to use macros (previously +impossible because the functions weren't in the default build.) + +B.2 Changes to the configuration mechanism + +Prior to libpng-1.5.0 library builders who needed to configure libpng +had either to modify the exported pngconf.h header file to add system +specific configuration or had to write feature selection macros into +pngusr.h and cause this to be included into pngconf.h by defining +PNG_USER_CONFIG. The latter mechanism had the disadvantage that an +application built without PNG_USER_CONFIG defined would see the +unmodified, default, libpng API and thus would probably fail to link. + +These mechanisms still work in the configure build and in any makefile +build that builds pnglibconf.h, although the feature selection macros +have changed somewhat as described above. In 1.5.0, however, pngusr.h is +processed only once, when the exported header file pnglibconf.h is built. +pngconf.h no longer includes pngusr.h, therefore pngusr.h is ignored after the +build of pnglibconf.h and it is never included in an application build. + +The rarely used alternative of adding a list of feature macros to the +CFLAGS setting in the build also still works; however, the macros will be +copied to pnglibconf.h and this may produce macro redefinition warnings +when the individual C files are compiled. + +All configuration now only works if pnglibconf.h is built from +scripts/pnglibconf.dfa. This requires the program awk. Brian Kernighan +(the original author of awk) maintains C source code of that awk and this +and all known later implementations (often called by subtly different +names - nawk and gawk for example) are adequate to build pnglibconf.h. +The Sun Microsystems (now Oracle) program 'awk' is an earlier version +and does not work; this may also apply to other systems that have a +functioning awk called 'nawk'. + +Configuration options are now documented in scripts/pnglibconf.dfa. This +file also includes dependency information that ensures a configuration is +consistent; that is, if a feature is switched off dependent features are +also removed. As a recommended alternative to using feature macros in +pngusr.h a system builder may also define equivalent options in pngusr.dfa +(or, indeed, any file) and add that to the configuration by setting +DFA_XTRA to the file name. The makefiles in contrib/pngminim illustrate +how to do this, and a case where pngusr.h is still required. + +.SH XI. Detecting libpng + +The png_get_io_ptr() function has been present since libpng-0.88, has never +changed, and is unaffected by conditional compilation macros. It is the +best choice for use in configure scripts for detecting the presence of any +libpng version since 0.88. In an autoconf "configure.in" you could use + + AC_CHECK_LIB(png, png_get_io_ptr, ... + +.SH XII. Source code repository + +Since about February 2009, version 1.2.34, libpng has been under "git" source +control. The git repository was built from old libpng-x.y.z.tar.gz files +going back to version 0.70. You can access the git repository (read only) +at + + git://libpng.git.sourceforge.net/gitroot/libpng + +or you can browse it via "gitweb" at + + http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng + +Patches can be sent to glennrp at users.sourceforge.net or to +png-mng-implement at lists.sourceforge.net or you can upload them to +the libpng bug tracker at + + http://libpng.sourceforge.net + +We also accept patches built from the tar or zip distributions, and +simple verbal discriptions of bug fixes, reported either to the +SourceForge bug tracker, to the png-mng-implement at lists.sf.net +mailing list, or directly to glennrp. + +.SH XIII. Coding style + +Our coding style is similar to the "Allman" style, with curly +braces on separate lines: + + if (condition) + { + action; + } + + else if (another condition) + { + another action; + } + +The braces can be omitted from simple one-line actions: + + if (condition) + return (0); + +We use 3-space indentation, except for continued statements which +are usually indented the same as the first line of the statement +plus four more spaces. + +For macro definitions we use 2-space indentation, always leaving the "#" +in the first column. + + #ifndef PNG_NO_FEATURE + # ifndef PNG_FEATURE_SUPPORTED + # define PNG_FEATURE_SUPPORTED + # endif + #endif + +Comments appear with the leading "/*" at the same indentation as +the statement that follows the comment: + + /* Single-line comment */ + statement; + + /* This is a multiple-line + * comment. + */ + statement; + +Very short comments can be placed after the end of the statement +to which they pertain: + + statement; /* comment */ + +We don't use C++ style ("//") comments. We have, however, +used them in the past in some now-abandoned MMX assembler +code. + +Functions and their curly braces are not indented, and +exported functions are marked with PNGAPI: + + /* This is a public function that is visible to + * application programmers. It does thus-and-so. + */ + void PNGAPI + png_exported_function(png_ptr, png_info, foo) + { + body; + } + +The prototypes for all exported functions appear in png.h, +above the comment that says + + /* Maintainer: Put new public prototypes here ... */ + +We mark all non-exported functions with "/* PRIVATE */"": + + void /* PRIVATE */ + png_non_exported_function(png_ptr, png_info, foo) + { + body; + } + +The prototypes for non-exported functions (except for those in +pngtest) appear in +pngpriv.h +above the comment that says + + /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ + +To avoid polluting the global namespace, the names of all exported +functions and variables begin with "png_", and all publicly visible C +preprocessor macros begin with "PNG". We request that applications that +use libpng *not* begin any of their own symbols with either of these strings. + +We put a space after each comma and after each semicolon +in "for" statements, and we put spaces before and after each +C binary operator and after "for" or "while", and before +"?". We don't put a space between a typecast and the expression +being cast, nor do we put one between a function name and the +left parenthesis that follows it: + + for (i = 2; i > 0; --i) + y[i] = a(x) + (int)b; + +We prefer #ifdef and #ifndef to #if defined() and if !defined() +when there is only one macro being tested. + +We prefer to express integers that are used as bit masks in hex format, +with an even number of lower-case hex digits (e.g., 0x00, 0xff, 0x0100). + +We do not use the TAB character for indentation in the C sources. + +Lines do not exceed 80 characters. + +Other rules can be inferred by inspecting the libpng source. + +.SH XIV. Y2K Compliance in libpng + +September 27, 2012 + +Since the PNG Development group is an ad-hoc body, we can't make +an official declaration. + +This is your unofficial assurance that libpng from version 0.71 and +upward through 1.5.13 are Y2K compliant. It is my belief that earlier +versions were also Y2K compliant. + +Libpng only has two year fields. One is a 2-byte unsigned integer that +will hold years up to 65535. The other holds the date in text +format, and will hold years up to 9999. + +The integer is + "png_uint_16 year" in png_time_struct. + +The string is + "char time_buffer[29]" in png_struct. This will no +longer be used in libpng-1.6.x and will be removed from libpng-1.7.0. + +There are seven time-related functions: + + png_convert_to_rfc_1123() in png.c + (formerly png_convert_to_rfc_1152() in error) + png_convert_from_struct_tm() in pngwrite.c, called + in pngwrite.c + png_convert_from_time_t() in pngwrite.c + png_get_tIME() in pngget.c + png_handle_tIME() in pngrutil.c, called in pngread.c + png_set_tIME() in pngset.c + png_write_tIME() in pngwutil.c, called in pngwrite.c + +All appear to handle dates properly in a Y2K environment. The +png_convert_from_time_t() function calls gmtime() to convert from system +clock time, which returns (year - 1900), which we properly convert to +the full 4-digit year. There is a possibility that applications using +libpng are not passing 4-digit years into the png_convert_to_rfc_1123() +function, or that they are incorrectly passing only a 2-digit year +instead of "year - 1900" into the png_convert_from_struct_tm() function, +but this is not under our control. The libpng documentation has always +stated that it works with 4-digit years, and the APIs have been +documented as such. + +The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned +integer to hold the year, and can hold years as large as 65535. + +zlib, upon which libpng depends, is also Y2K compliant. It contains +no date-related code. + + + Glenn Randers-Pehrson + libpng maintainer + PNG Development Group + +.SH NOTE + +Note about libpng version numbers: + +Due to various miscommunications, unforeseen code incompatibilities +and occasional factors outside the authors' control, version numbering +on the library has not always been consistent and straightforward. +The following table summarizes matters since version 0.89c, which was +the first widely used release: + + source png.h png.h shared-lib + version string int version + ------- ------ ----- ---------- + 0.89c ("beta 3") 0.89 89 1.0.89 + 0.90 ("beta 4") 0.90 90 0.90 + 0.95 ("beta 5") 0.95 95 0.95 + 0.96 ("beta 6") 0.96 96 0.96 + 0.97b ("beta 7") 1.00.97 97 1.0.1 + 0.97c 0.97 97 2.0.97 + 0.98 0.98 98 2.0.98 + 0.99 0.99 98 2.0.99 + 0.99a-m 0.99 99 2.0.99 + 1.00 1.00 100 2.1.0 + 1.0.0 1.0.0 100 2.1.0 + 1.0.0 (from here on, the 100 2.1.0 + 1.0.1 png.h string is 10001 2.1.0 + 1.0.1a-e identical to the 10002 from here on, the + 1.0.2 source version) 10002 shared library is 2.V + 1.0.2a-b 10003 where V is the source + 1.0.1 10001 code version except as + 1.0.1a-e 10002 2.1.0.1a-e noted. + 1.0.2 10002 2.1.0.2 + 1.0.2a-b 10003 2.1.0.2a-b + 1.0.3 10003 2.1.0.3 + 1.0.3a-d 10004 2.1.0.3a-d + 1.0.4 10004 2.1.0.4 + 1.0.4a-f 10005 2.1.0.4a-f + 1.0.5 (+ 2 patches) 10005 2.1.0.5 + 1.0.5a-d 10006 2.1.0.5a-d + 1.0.5e-r 10100 2.1.0.5e-r + 1.0.5s-v 10006 2.1.0.5s-v + 1.0.6 (+ 3 patches) 10006 2.1.0.6 + 1.0.6d-g 10007 2.1.0.6d-g + 1.0.6h 10007 10.6h + 1.0.6i 10007 10.6i + 1.0.6j 10007 2.1.0.6j + 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14 + 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 + 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 + 1.0.7 1 10007 2.1.0.7 + 1.0.8beta1-4 1 10008 2.1.0.8beta1-4 + 1.0.8rc1 1 10008 2.1.0.8rc1 + 1.0.8 1 10008 2.1.0.8 + 1.0.9beta1-6 1 10009 2.1.0.9beta1-6 + 1.0.9rc1 1 10009 2.1.0.9rc1 + 1.0.9beta7-10 1 10009 2.1.0.9beta7-10 + 1.0.9rc2 1 10009 2.1.0.9rc2 + 1.0.9 1 10009 2.1.0.9 + 1.0.10beta1 1 10010 2.1.0.10beta1 + 1.0.10rc1 1 10010 2.1.0.10rc1 + 1.0.10 1 10010 2.1.0.10 + 1.0.11beta1-3 1 10011 2.1.0.11beta1-3 + 1.0.11rc1 1 10011 2.1.0.11rc1 + 1.0.11 1 10011 2.1.0.11 + 1.0.12beta1-2 2 10012 2.1.0.12beta1-2 + 1.0.12rc1 2 10012 2.1.0.12rc1 + 1.0.12 2 10012 2.1.0.12 + 1.1.0a-f - 10100 2.1.1.0a-f abandoned + 1.2.0beta1-2 2 10200 2.1.2.0beta1-2 + 1.2.0beta3-5 3 10200 3.1.2.0beta3-5 + 1.2.0rc1 3 10200 3.1.2.0rc1 + 1.2.0 3 10200 3.1.2.0 + 1.2.1beta-4 3 10201 3.1.2.1beta1-4 + 1.2.1rc1-2 3 10201 3.1.2.1rc1-2 + 1.2.1 3 10201 3.1.2.1 + 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6 + 1.0.13beta1 10 10013 10.so.0.1.0.13beta1 + 1.0.13rc1 10 10013 10.so.0.1.0.13rc1 + 1.2.2rc1 12 10202 12.so.0.1.2.2rc1 + 1.0.13 10 10013 10.so.0.1.0.13 + 1.2.2 12 10202 12.so.0.1.2.2 + 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6 + 1.2.3 12 10203 12.so.0.1.2.3 + 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3 + 1.2.4rc1 13 10204 12.so.0.1.2.4rc1 + 1.0.14 10 10014 10.so.0.1.0.14 + 1.2.4 13 10204 12.so.0.1.2.4 + 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2 + 1.0.15rc1 10 10015 10.so.0.1.0.15rc1 + 1.0.15 10 10015 10.so.0.1.0.15 + 1.2.5 13 10205 12.so.0.1.2.5 + 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4 + 1.2.6rc1-5 13 10206 12.so.0.1.2.6rc1-5 + 1.0.16 10 10016 10.so.0.1.0.16 + 1.2.6 13 10206 12.so.0.1.2.6 + 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2 + 1.0.17rc1 10 10017 12.so.0.1.0.17rc1 + 1.2.7rc1 13 10207 12.so.0.1.2.7rc1 + 1.0.17 10 10017 12.so.0.1.0.17 + 1.2.7 13 10207 12.so.0.1.2.7 + 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5 + 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5 + 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5 + 1.0.18 10 10018 12.so.0.1.0.18 + 1.2.8 13 10208 12.so.0.1.2.8 + 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3 + 1.2.9beta4-11 13 10209 12.so.0.9[.0] + 1.2.9rc1 13 10209 12.so.0.9[.0] + 1.2.9 13 10209 12.so.0.9[.0] + 1.2.10beta1-7 13 10210 12.so.0.10[.0] + 1.2.10rc1-2 13 10210 12.so.0.10[.0] + 1.2.10 13 10210 12.so.0.10[.0] + 1.4.0beta1-6 14 10400 14.so.0.0[.0] + 1.2.11beta1-4 13 10210 12.so.0.11[.0] + 1.4.0beta7-8 14 10400 14.so.0.0[.0] + 1.2.11 13 10211 12.so.0.11[.0] + 1.2.12 13 10212 12.so.0.12[.0] + 1.4.0beta9-14 14 10400 14.so.0.0[.0] + 1.2.13 13 10213 12.so.0.13[.0] + 1.4.0beta15-36 14 10400 14.so.0.0[.0] + 1.4.0beta37-87 14 10400 14.so.14.0[.0] + 1.4.0rc01 14 10400 14.so.14.0[.0] + 1.4.0beta88-109 14 10400 14.so.14.0[.0] + 1.4.0rc02-08 14 10400 14.so.14.0[.0] + 1.4.0 14 10400 14.so.14.0[.0] + 1.4.1beta01-03 14 10401 14.so.14.1[.0] + 1.4.1rc01 14 10401 14.so.14.1[.0] + 1.4.1beta04-12 14 10401 14.so.14.1[.0] + 1.4.1 14 10401 14.so.14.1[.0] + 1.4.2 14 10402 14.so.14.2[.0] + 1.4.3 14 10403 14.so.14.3[.0] + 1.4.4 14 10404 14.so.14.4[.0] + 1.5.0beta01-58 15 10500 15.so.15.0[.0] + 1.5.0rc01-07 15 10500 15.so.15.0[.0] + 1.5.0 15 10500 15.so.15.0[.0] + 1.5.1beta01-11 15 10501 15.so.15.1[.0] + 1.5.1rc01-02 15 10501 15.so.15.1[.0] + 1.5.1 15 10501 15.so.15.1[.0] + 1.5.2beta01-03 15 10502 15.so.15.2[.0] + 1.5.2rc01-03 15 10502 15.so.15.2[.0] + 1.5.2 15 10502 15.so.15.2[.0] + 1.5.3beta01-10 15 10503 15.so.15.3[.0] + 1.5.3rc01-02 15 10503 15.so.15.3[.0] + 1.5.3beta11 15 10503 15.so.15.3[.0] + 1.5.3 [omitted] + 1.5.4beta01-08 15 10504 15.so.15.4[.0] + 1.5.4rc01 15 10504 15.so.15.4[.0] + 1.5.4 15 10504 15.so.15.4[.0] + 1.5.5beta01-08 15 10505 15.so.15.5[.0] + 1.5.5rc01 15 10505 15.so.15.5[.0] + 1.5.5 15 10505 15.so.15.5[.0] + 1.5.6beta01-07 15 10506 15.so.15.6[.0] + 1.5.6rc01-03 15 10506 15.so.15.6[.0] + 1.5.6 15 10506 15.so.15.6[.0] + 1.5.7beta01-05 15 10507 15.so.15.7[.0] + 1.5.7rc01-03 15 10507 15.so.15.7[.0] + 1.5.7 15 10507 15.so.15.7[.0] + 1.5.8beta01 15 10508 15.so.15.8[.0] + 1.5.8rc01 15 10508 15.so.15.8[.0] + 1.5.8 15 10508 15.so.15.8[.0] + 1.5.9beta01-02 15 10509 15.so.15.9[.0] + 1.5.9rc01 15 10509 15.so.15.9[.0] + 1.5.9 15 10509 15.so.15.9[.0] + 1.5.10beta01-05 15 10510 15.so.15.10[.0] + 1.5.10 15 10510 15.so.15.10[.0] + 1.5.11beta01 15 10511 15.so.15.11[.0] + 1.5.11rc01-05 15 10511 15.so.15.11[.0] + 1.5.11 15 10511 15.so.15.11[.0] + 1.5.12 15 10512 15.so.15.12[.0] + 1.5.13beta01-02 15 10513 15.so.15.13[.0] + 1.5.13rc01 15 10513 15.so.15.13[.0] + 1.5.13 15 10513 15.so.15.13[.0] + +Henceforth the source version will match the shared-library minor +and patch numbers; the shared-library major version number will be +used for changes in backward compatibility, as it is intended. The +PNG_PNGLIB_VER macro, which is not used within libpng but is available +for applications, is an unsigned integer of the form xyyzz corresponding +to the source version x.y.z (leading zeros in y and z). Beta versions +were given the previous public release number plus a letter, until +version 1.0.6j; from then on they were given the upcoming public +release number plus "betaNN" or "rcN". + +.SH "SEE ALSO" +.BR "png"(5), " libpngpf"(3), " zlib"(3), " deflate"(5), " " and " zlib"(5) + +.LP +.IR libpng : +.IP +http://libpng.sourceforge.net (follow the [DOWNLOAD] link) +http://www.libpng.org/pub/png + +.LP +.IR zlib : +.IP +(generally) at the same location as +.I libpng +or at +.br +ftp://ftp.info-zip.org/pub/infozip/zlib + +.LP +.IR PNG specification: RFC 2083 +.IP +(generally) at the same location as +.I libpng +or at +.br +ftp://ds.internic.net/rfc/rfc2083.txt +.br +or (as a W3C Recommendation) at +.br +http://www.w3.org/TR/REC-png.html + +.LP +In the case of any inconsistency between the PNG specification +and this library, the specification takes precedence. + +.SH AUTHORS +This man page: Glenn Randers-Pehrson + + +The contributing authors would like to thank all those who helped +with testing, bug fixes, and patience. This wouldn't have been +possible without all of you. + +Thanks to Frank J. T. Wojcik for helping with the documentation. + +Libpng version 1.5.13 - September 27, 2012: +Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc. +Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net). + +Supported by the PNG development group +.br +png-mng-implement at lists.sf.net +(subscription required; visit +png-mng-implement at lists.sourceforge.net (subscription required; visit +https://lists.sourceforge.net/lists/listinfo/png-mng-implement +to subscribe). + +.SH COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: + +(This copy of the libpng notices is provided for your convenience. In case of +any discrepancy between this copy and the notices in the file png.h that is +included in the libpng distribution, the latter shall prevail.) + +If you modify libpng you may insert additional notices immediately following +this sentence. + +This code is released under the libpng license. + +libpng versions 1.2.6, August 15, 2004, through 1.5.13, September 27, 2012, are +Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are +distributed according to the same disclaimer and license as libpng-1.2.5 +with the following individual added to the list of Contributing Authors + + Cosmin Truta + +libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are +Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are +distributed according to the same disclaimer and license as libpng-1.0.6 +with the following individuals added to the list of Contributing Authors + + Simon-Pierre Cadieux + Eric S. Raymond + Gilles Vollant + +and with the following additions to the disclaimer: + + There is no warranty against interference with your + enjoyment of the library or against infringement. + There is no warranty that our efforts or the library + will fulfill any of your particular purposes or needs. + This library is provided with all faults, and the entire + risk of satisfactory quality, performance, accuracy, and + effort is with the user. + +libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are +Copyright (c) 1998, 1999 Glenn Randers-Pehrson +Distributed according to the same disclaimer and license as libpng-0.96, +with the following individuals added to the list of Contributing Authors: + + Tom Lane + Glenn Randers-Pehrson + Willem van Schaik + +libpng versions 0.89, June 1996, through 0.96, May 1997, are +Copyright (c) 1996, 1997 Andreas Dilger +Distributed according to the same disclaimer and license as libpng-0.88, +with the following individuals added to the list of Contributing Authors: + + John Bowler + Kevin Bracey + Sam Bushell + Magnus Holmgren + Greg Roelofs + Tom Tanner + +libpng versions 0.5, May 1995, through 0.88, January 1996, are +Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. + +For the purposes of this copyright and license, "Contributing Authors" +is defined as the following set of individuals: + + Andreas Dilger + Dave Martindale + Guy Eric Schalnat + Paul Schmidt + Tim Wegner + +The PNG Reference Library is supplied "AS IS". The Contributing Authors +and Group 42, Inc. disclaim all warranties, expressed or implied, +including, without limitation, the warranties of merchantability and of +fitness for any purpose. The Contributing Authors and Group 42, Inc. +assume no liability for direct, indirect, incidental, special, exemplary, +or consequential damages, which may result from the use of the PNG +Reference Library, even if advised of the possibility of such damage. + +Permission is hereby granted to use, copy, modify, and distribute this +source code, or portions hereof, for any purpose, without fee, subject +to the following restrictions: + +1. The origin of this source code must not be misrepresented. + +2. Altered versions must be plainly marked as such and + must not be misrepresented as being the original source. + +3. This Copyright notice may not be removed or altered from + any source or altered source distribution. + +The Contributing Authors and Group 42, Inc. specifically permit, without +fee, and encourage the use of this source code as a component to +supporting the PNG file format in commercial products. If you use this +source code in a product, acknowledgment is not required but would be +appreciated. + + +A "png_get_copyright" function is available, for convenient use in "about" +boxes and the like: + + printf("%s",png_get_copyright(NULL)); + +Also, the PNG logo (in PNG format, of course) is supplied in the +files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). + +Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a +certification mark of the Open Source Initiative. + +Glenn Randers-Pehrson +glennrp at users.sourceforge.net +September 27, 2012 + +.\" end of man page + diff --git a/Source/LibPNG/libpngpf.3 b/Source/LibPNG/libpngpf.3 index f6b62a0..9353eee 100644 --- a/Source/LibPNG/libpngpf.3 +++ b/Source/LibPNG/libpngpf.3 @@ -1,28 +1,28 @@ -.TH LIBPNGPF 3 "September 27, 2012" -.SH NAME -libpng \- Portable Network Graphics (PNG) Reference Library 1.5.13 -(private functions) -.SH SYNOPSIS -\fB#include \fI"pngpriv.h" - -\fI\fB - -\fBAs of libpng version \fP\fI1.5.1\fP\fB, this section is no longer \fP\fImaintained\fP\fB, now \fIthat - -\fBthe private function prototypes are hidden in pngpriv.h and not \fIaccessible - -\fBto applications. Look in pngpriv.h for the prototypes and a short \fIdescription - -\fBof each \fIfunction. - -\fI\fB - -.SH DESCRIPTION -The functions previously listed here are used privately by libpng -and are not recommended for use by applications. They are -not "exported" to applications using shared libraries. - -.SH SEE ALSO -.BR "png"(5), " libpng"(3), " zlib"(3), " deflate"(5), " " and " zlib"(5) -.SH AUTHOR -Glenn Randers-Pehrson +.TH LIBPNGPF 3 "September 27, 2012" +.SH NAME +libpng \- Portable Network Graphics (PNG) Reference Library 1.5.13 +(private functions) +.SH SYNOPSIS +\fB#include \fI"pngpriv.h" + +\fI\fB + +\fBAs of libpng version \fP\fI1.5.1\fP\fB, this section is no longer \fP\fImaintained\fP\fB, now \fIthat + +\fBthe private function prototypes are hidden in pngpriv.h and not \fIaccessible + +\fBto applications. Look in pngpriv.h for the prototypes and a short \fIdescription + +\fBof each \fIfunction. + +\fI\fB + +.SH DESCRIPTION +The functions previously listed here are used privately by libpng +and are not recommended for use by applications. They are +not "exported" to applications using shared libraries. + +.SH SEE ALSO +.BR "png"(5), " libpng"(3), " zlib"(3), " deflate"(5), " " and " zlib"(5) +.SH AUTHOR +Glenn Randers-Pehrson diff --git a/Source/LibPNG/png.5 b/Source/LibPNG/png.5 index cfd109f..8898820 100644 --- a/Source/LibPNG/png.5 +++ b/Source/LibPNG/png.5 @@ -1,74 +1,74 @@ -.TH PNG 5 "September 27, 2012" -.SH NAME -png \- Portable Network Graphics (PNG) format -.SH DESCRIPTION -PNG (Portable Network Graphics) is an extensible file format for the -lossless, portable, well-compressed storage of raster images. PNG provides -a patent-free replacement for GIF and can also replace many -common uses of TIFF. Indexed-color, grayscale, and truecolor images are -supported, plus an optional alpha channel. Sample depths range from -1 to 16 bits. -.br - -PNG is designed to work well in online viewing applications, such as the -World Wide Web, so it is fully streamable with a progressive display -option. PNG is robust, providing both full file integrity checking and -fast, simple detection of common transmission errors. Also, PNG can store -gamma and chromaticity data for improved color matching on heterogeneous -platforms. - -.SH "SEE ALSO" -.BR "libpng"(3), " libpngpf"(3), " zlib"(3), " deflate"(5), " " and " zlib"(5) -.LP -PNG specification (second edition), November 2003: -.IP -.br - 8) - png_error(png_ptr, "Too many bytes for PNG signature"); - - png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes); -} - -/* Checks whether the supplied bytes match the PNG signature. We allow - * checking less than the full 8-byte signature so that those apps that - * already read the first few bytes of a file to determine the file type - * can simply check the remaining bytes for extra assurance. Returns - * an integer less than, equal to, or greater than zero if sig is found, - * respectively, to be less than, to match, or be greater than the correct - * PNG signature (this is the same behavior as strcmp, memcmp, etc). - */ -int PNGAPI -png_sig_cmp(png_const_bytep sig, png_size_t start, png_size_t num_to_check) -{ - png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; - - if (num_to_check > 8) - num_to_check = 8; - - else if (num_to_check < 1) - return (-1); - - if (start > 7) - return (-1); - - if (start + num_to_check > 8) - num_to_check = 8 - start; - - return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check))); -} - -#endif /* PNG_READ_SUPPORTED */ - -#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) -/* Function to allocate memory for zlib */ -PNG_FUNCTION(voidpf /* PRIVATE */, -png_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED) -{ - png_voidp ptr; - png_structp p=(png_structp)png_ptr; - png_uint_32 save_flags=p->flags; - png_alloc_size_t num_bytes; - - if (png_ptr == NULL) - return (NULL); - - if (items > PNG_UINT_32_MAX/size) - { - png_warning (p, "Potential overflow in png_zalloc()"); - return (NULL); - } - num_bytes = (png_alloc_size_t)items * size; - - p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; - ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes); - p->flags=save_flags; - - return ((voidpf)ptr); -} - -/* Function to free memory for zlib */ -void /* PRIVATE */ -png_zfree(voidpf png_ptr, voidpf ptr) -{ - png_free((png_structp)png_ptr, (png_voidp)ptr); -} - -/* Reset the CRC variable to 32 bits of 1's. Care must be taken - * in case CRC is > 32 bits to leave the top bits 0. - */ -void /* PRIVATE */ -png_reset_crc(png_structp png_ptr) -{ - /* The cast is safe because the crc is a 32 bit value. */ - png_ptr->crc = (png_uint_32)crc32(0, Z_NULL, 0); -} - -/* Calculate the CRC over a section of data. We can only pass as - * much data to this routine as the largest single buffer size. We - * also check that this data will actually be used before going to the - * trouble of calculating it. - */ -void /* PRIVATE */ -png_calculate_crc(png_structp png_ptr, png_const_bytep ptr, png_size_t length) -{ - int need_crc = 1; - - if (PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name)) - { - if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) == - (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN)) - need_crc = 0; - } - - else /* critical */ - { - if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) - need_crc = 0; - } - - /* 'uLong' is defined as unsigned long, this means that on some systems it is - * a 64 bit value. crc32, however, returns 32 bits so the following cast is - * safe. 'uInt' may be no more than 16 bits, so it is necessary to perform a - * loop here. - */ - if (need_crc && length > 0) - { - uLong crc = png_ptr->crc; /* Should never issue a warning */ - - do - { - uInt safeLength = (uInt)length; - if (safeLength == 0) - safeLength = (uInt)-1; /* evil, but safe */ - - crc = crc32(crc, ptr, safeLength); - - /* The following should never issue compiler warnings, if they do the - * target system has characteristics that will probably violate other - * assumptions within the libpng code. - */ - ptr += safeLength; - length -= safeLength; - } - while (length > 0); - - /* And the following is always safe because the crc is only 32 bits. */ - png_ptr->crc = (png_uint_32)crc; - } -} - -/* Check a user supplied version number, called from both read and write - * functions that create a png_struct - */ -int -png_user_version_check(png_structp png_ptr, png_const_charp user_png_ver) -{ - if (user_png_ver) - { - int i = 0; - - do - { - if (user_png_ver[i] != png_libpng_ver[i]) - png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; - } while (png_libpng_ver[i++]); - } - - else - png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; - - if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) - { - /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so - * we must recompile any applications that use any older library version. - * For versions after libpng 1.0, we will be compatible, so we need - * only check the first digit. - */ - if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || - (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || - (user_png_ver[0] == '0' && user_png_ver[2] < '9')) - { -#ifdef PNG_WARNINGS_SUPPORTED - size_t pos = 0; - char m[128]; - - pos = png_safecat(m, sizeof m, pos, "Application built with libpng-"); - pos = png_safecat(m, sizeof m, pos, user_png_ver); - pos = png_safecat(m, sizeof m, pos, " but running with "); - pos = png_safecat(m, sizeof m, pos, png_libpng_ver); - - png_warning(png_ptr, m); -#endif - -#ifdef PNG_ERROR_NUMBERS_SUPPORTED - png_ptr->flags = 0; -#endif - - return 0; - } - } - - /* Success return. */ - return 1; -} - -/* Allocate the memory for an info_struct for the application. We don't - * really need the png_ptr, but it could potentially be useful in the - * future. This should be used in favour of malloc(png_sizeof(png_info)) - * and png_info_init() so that applications that want to use a shared - * libpng don't have to be recompiled if png_info changes size. - */ -PNG_FUNCTION(png_infop,PNGAPI -png_create_info_struct,(png_structp png_ptr),PNG_ALLOCATED) -{ - png_infop info_ptr; - - png_debug(1, "in png_create_info_struct"); - - if (png_ptr == NULL) - return (NULL); - -#ifdef PNG_USER_MEM_SUPPORTED - info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, - png_ptr->malloc_fn, png_ptr->mem_ptr); -#else - info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); -#endif - if (info_ptr != NULL) - png_info_init_3(&info_ptr, png_sizeof(png_info)); - - return (info_ptr); -} - -/* This function frees the memory associated with a single info struct. - * Normally, one would use either png_destroy_read_struct() or - * png_destroy_write_struct() to free an info struct, but this may be - * useful for some applications. - */ -void PNGAPI -png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) -{ - png_infop info_ptr = NULL; - - png_debug(1, "in png_destroy_info_struct"); - - if (png_ptr == NULL) - return; - - if (info_ptr_ptr != NULL) - info_ptr = *info_ptr_ptr; - - if (info_ptr != NULL) - { - png_info_destroy(png_ptr, info_ptr); - -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn, - png_ptr->mem_ptr); -#else - png_destroy_struct((png_voidp)info_ptr); -#endif - *info_ptr_ptr = NULL; - } -} - -/* Initialize the info structure. This is now an internal function (0.89) - * and applications using it are urged to use png_create_info_struct() - * instead. - */ - -void PNGAPI -png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) -{ - png_infop info_ptr = *ptr_ptr; - - png_debug(1, "in png_info_init_3"); - - if (info_ptr == NULL) - return; - - if (png_sizeof(png_info) > png_info_struct_size) - { - png_destroy_struct(info_ptr); - info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); - *ptr_ptr = info_ptr; - } - - /* Set everything to 0 */ - png_memset(info_ptr, 0, png_sizeof(png_info)); -} - -void PNGAPI -png_data_freer(png_structp png_ptr, png_infop info_ptr, - int freer, png_uint_32 mask) -{ - png_debug(1, "in png_data_freer"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - if (freer == PNG_DESTROY_WILL_FREE_DATA) - info_ptr->free_me |= mask; - - else if (freer == PNG_USER_WILL_FREE_DATA) - info_ptr->free_me &= ~mask; - - else - png_warning(png_ptr, - "Unknown freer parameter in png_data_freer"); -} - -void PNGAPI -png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, - int num) -{ - png_debug(1, "in png_free_data"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - -#ifdef PNG_TEXT_SUPPORTED - /* Free text item num or (if num == -1) all text items */ - if ((mask & PNG_FREE_TEXT) & info_ptr->free_me) - { - if (num != -1) - { - if (info_ptr->text && info_ptr->text[num].key) - { - png_free(png_ptr, info_ptr->text[num].key); - info_ptr->text[num].key = NULL; - } - } - - else - { - int i; - for (i = 0; i < info_ptr->num_text; i++) - png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i); - png_free(png_ptr, info_ptr->text); - info_ptr->text = NULL; - info_ptr->num_text=0; - } - } -#endif - -#ifdef PNG_tRNS_SUPPORTED - /* Free any tRNS entry */ - if ((mask & PNG_FREE_TRNS) & info_ptr->free_me) - { - png_free(png_ptr, info_ptr->trans_alpha); - info_ptr->trans_alpha = NULL; - info_ptr->valid &= ~PNG_INFO_tRNS; - } -#endif - -#ifdef PNG_sCAL_SUPPORTED - /* Free any sCAL entry */ - if ((mask & PNG_FREE_SCAL) & info_ptr->free_me) - { - png_free(png_ptr, info_ptr->scal_s_width); - png_free(png_ptr, info_ptr->scal_s_height); - info_ptr->scal_s_width = NULL; - info_ptr->scal_s_height = NULL; - info_ptr->valid &= ~PNG_INFO_sCAL; - } -#endif - -#ifdef PNG_pCAL_SUPPORTED - /* Free any pCAL entry */ - if ((mask & PNG_FREE_PCAL) & info_ptr->free_me) - { - png_free(png_ptr, info_ptr->pcal_purpose); - png_free(png_ptr, info_ptr->pcal_units); - info_ptr->pcal_purpose = NULL; - info_ptr->pcal_units = NULL; - if (info_ptr->pcal_params != NULL) - { - int i; - for (i = 0; i < (int)info_ptr->pcal_nparams; i++) - { - png_free(png_ptr, info_ptr->pcal_params[i]); - info_ptr->pcal_params[i] = NULL; - } - png_free(png_ptr, info_ptr->pcal_params); - info_ptr->pcal_params = NULL; - } - info_ptr->valid &= ~PNG_INFO_pCAL; - } -#endif - -#ifdef PNG_iCCP_SUPPORTED - /* Free any iCCP entry */ - if ((mask & PNG_FREE_ICCP) & info_ptr->free_me) - { - png_free(png_ptr, info_ptr->iccp_name); - png_free(png_ptr, info_ptr->iccp_profile); - info_ptr->iccp_name = NULL; - info_ptr->iccp_profile = NULL; - info_ptr->valid &= ~PNG_INFO_iCCP; - } -#endif - -#ifdef PNG_sPLT_SUPPORTED - /* Free a given sPLT entry, or (if num == -1) all sPLT entries */ - if ((mask & PNG_FREE_SPLT) & info_ptr->free_me) - { - if (num != -1) - { - if (info_ptr->splt_palettes) - { - png_free(png_ptr, info_ptr->splt_palettes[num].name); - png_free(png_ptr, info_ptr->splt_palettes[num].entries); - info_ptr->splt_palettes[num].name = NULL; - info_ptr->splt_palettes[num].entries = NULL; - } - } - - else - { - if (info_ptr->splt_palettes_num) - { - int i; - for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) - png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i); - - png_free(png_ptr, info_ptr->splt_palettes); - info_ptr->splt_palettes = NULL; - info_ptr->splt_palettes_num = 0; - } - info_ptr->valid &= ~PNG_INFO_sPLT; - } - } -#endif - -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED - if (png_ptr->unknown_chunk.data) - { - png_free(png_ptr, png_ptr->unknown_chunk.data); - png_ptr->unknown_chunk.data = NULL; - } - - if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) - { - if (num != -1) - { - if (info_ptr->unknown_chunks) - { - png_free(png_ptr, info_ptr->unknown_chunks[num].data); - info_ptr->unknown_chunks[num].data = NULL; - } - } - - else - { - int i; - - if (info_ptr->unknown_chunks_num) - { - for (i = 0; i < info_ptr->unknown_chunks_num; i++) - png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i); - - png_free(png_ptr, info_ptr->unknown_chunks); - info_ptr->unknown_chunks = NULL; - info_ptr->unknown_chunks_num = 0; - } - } - } -#endif - -#ifdef PNG_hIST_SUPPORTED - /* Free any hIST entry */ - if ((mask & PNG_FREE_HIST) & info_ptr->free_me) - { - png_free(png_ptr, info_ptr->hist); - info_ptr->hist = NULL; - info_ptr->valid &= ~PNG_INFO_hIST; - } -#endif - - /* Free any PLTE entry that was internally allocated */ - if ((mask & PNG_FREE_PLTE) & info_ptr->free_me) - { - png_zfree(png_ptr, info_ptr->palette); - info_ptr->palette = NULL; - info_ptr->valid &= ~PNG_INFO_PLTE; - info_ptr->num_palette = 0; - } - -#ifdef PNG_INFO_IMAGE_SUPPORTED - /* Free any image bits attached to the info structure */ - if ((mask & PNG_FREE_ROWS) & info_ptr->free_me) - { - if (info_ptr->row_pointers) - { - int row; - for (row = 0; row < (int)info_ptr->height; row++) - { - png_free(png_ptr, info_ptr->row_pointers[row]); - info_ptr->row_pointers[row] = NULL; - } - png_free(png_ptr, info_ptr->row_pointers); - info_ptr->row_pointers = NULL; - } - info_ptr->valid &= ~PNG_INFO_IDAT; - } -#endif - - if (num != -1) - mask &= ~PNG_FREE_MUL; - - info_ptr->free_me &= ~mask; -} - -/* This is an internal routine to free any memory that the info struct is - * pointing to before re-using it or freeing the struct itself. Recall - * that png_free() checks for NULL pointers for us. - */ -void /* PRIVATE */ -png_info_destroy(png_structp png_ptr, png_infop info_ptr) -{ - png_debug(1, "in png_info_destroy"); - - png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); - -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - if (png_ptr->num_chunk_list) - { - png_free(png_ptr, png_ptr->chunk_list); - png_ptr->chunk_list = NULL; - png_ptr->num_chunk_list = 0; - } -#endif - - png_info_init_3(&info_ptr, png_sizeof(png_info)); -} -#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ - -/* This function returns a pointer to the io_ptr associated with the user - * functions. The application should free any memory associated with this - * pointer before png_write_destroy() or png_read_destroy() are called. - */ -png_voidp PNGAPI -png_get_io_ptr(png_structp png_ptr) -{ - if (png_ptr == NULL) - return (NULL); - - return (png_ptr->io_ptr); -} - -#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) -# ifdef PNG_STDIO_SUPPORTED -/* Initialize the default input/output functions for the PNG file. If you - * use your own read or write routines, you can call either png_set_read_fn() - * or png_set_write_fn() instead of png_init_io(). If you have defined - * PNG_NO_STDIO or otherwise disabled PNG_STDIO_SUPPORTED, you must use a - * function of your own because "FILE *" isn't necessarily available. - */ -void PNGAPI -png_init_io(png_structp png_ptr, png_FILE_p fp) -{ - png_debug(1, "in png_init_io"); - - if (png_ptr == NULL) - return; - - png_ptr->io_ptr = (png_voidp)fp; -} -# endif - -# ifdef PNG_TIME_RFC1123_SUPPORTED -/* Convert the supplied time into an RFC 1123 string suitable for use in - * a "Creation Time" or other text-based time string. - */ -png_const_charp PNGAPI -png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime) -{ - static PNG_CONST char short_months[12][4] = - {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - - if (png_ptr == NULL) - return (NULL); - - if (ptime->year > 9999 /* RFC1123 limitation */ || - ptime->month == 0 || ptime->month > 12 || - ptime->day == 0 || ptime->day > 31 || - ptime->hour > 23 || ptime->minute > 59 || - ptime->second > 60) - { - png_warning(png_ptr, "Ignoring invalid time value"); - return (NULL); - } - - { - size_t pos = 0; - char number_buf[5]; /* enough for a four-digit year */ - -# define APPEND_STRING(string)\ - pos = png_safecat(png_ptr->time_buffer, sizeof png_ptr->time_buffer,\ - pos, (string)) -# define APPEND_NUMBER(format, value)\ - APPEND_STRING(PNG_FORMAT_NUMBER(number_buf, format, (value))) -# define APPEND(ch)\ - if (pos < (sizeof png_ptr->time_buffer)-1)\ - png_ptr->time_buffer[pos++] = (ch) - - APPEND_NUMBER(PNG_NUMBER_FORMAT_u, (unsigned)ptime->day); - APPEND(' '); - APPEND_STRING(short_months[(ptime->month - 1)]); - APPEND(' '); - APPEND_NUMBER(PNG_NUMBER_FORMAT_u, ptime->year); - APPEND(' '); - APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->hour); - APPEND(':'); - APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->minute); - APPEND(':'); - APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->second); - APPEND_STRING(" +0000"); /* This reliably terminates the buffer */ - -# undef APPEND -# undef APPEND_NUMBER -# undef APPEND_STRING - } - - return png_ptr->time_buffer; -} -# endif /* PNG_TIME_RFC1123_SUPPORTED */ - -#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ - -png_const_charp PNGAPI -png_get_copyright(png_const_structp png_ptr) -{ - PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ -#ifdef PNG_STRING_COPYRIGHT - return PNG_STRING_COPYRIGHT -#else -# ifdef __STDC__ - return PNG_STRING_NEWLINE \ - "libpng version 1.5.13 - September 27, 2012" PNG_STRING_NEWLINE \ - "Copyright (c) 1998-2012 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ - "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ - "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ - PNG_STRING_NEWLINE; -# else - return "libpng version 1.5.13 - September 27, 2012\ - Copyright (c) 1998-2012 Glenn Randers-Pehrson\ - Copyright (c) 1996-1997 Andreas Dilger\ - Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; -# endif -#endif -} - -/* The following return the library version as a short string in the - * format 1.0.0 through 99.99.99zz. To get the version of *.h files - * used with your application, print out PNG_LIBPNG_VER_STRING, which - * is defined in png.h. - * Note: now there is no difference between png_get_libpng_ver() and - * png_get_header_ver(). Due to the version_nn_nn_nn typedef guard, - * it is guaranteed that png.c uses the correct version of png.h. - */ -png_const_charp PNGAPI -png_get_libpng_ver(png_const_structp png_ptr) -{ - /* Version of *.c files used when building libpng */ - return png_get_header_ver(png_ptr); -} - -png_const_charp PNGAPI -png_get_header_ver(png_const_structp png_ptr) -{ - /* Version of *.h files used when building libpng */ - PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ - return PNG_LIBPNG_VER_STRING; -} - -png_const_charp PNGAPI -png_get_header_version(png_const_structp png_ptr) -{ - /* Returns longer string containing both version and date */ - PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ -#ifdef __STDC__ - return PNG_HEADER_VERSION_STRING -# ifndef PNG_READ_SUPPORTED - " (NO READ SUPPORT)" -# endif - PNG_STRING_NEWLINE; -#else - return PNG_HEADER_VERSION_STRING; -#endif -} - -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED -int PNGAPI -png_handle_as_unknown(png_structp png_ptr, png_const_bytep chunk_name) -{ - /* Check chunk_name and return "keep" value if it's on the list, else 0 */ - png_const_bytep p, p_end; - - if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list <= 0) - return PNG_HANDLE_CHUNK_AS_DEFAULT; - - p_end = png_ptr->chunk_list; - p = p_end + png_ptr->num_chunk_list*5; /* beyond end */ - - /* The code is the fifth byte after each four byte string. Historically this - * code was always searched from the end of the list, so it should continue - * to do so in case there are duplicated entries. - */ - do /* num_chunk_list > 0, so at least one */ - { - p -= 5; - if (!png_memcmp(chunk_name, p, 4)) - return p[4]; - } - while (p > p_end); - - return PNG_HANDLE_CHUNK_AS_DEFAULT; -} - -int /* PRIVATE */ -png_chunk_unknown_handling(png_structp png_ptr, png_uint_32 chunk_name) -{ - png_byte chunk_string[5]; - - PNG_CSTRING_FROM_CHUNK(chunk_string, chunk_name); - return png_handle_as_unknown(png_ptr, chunk_string); -} -#endif - -#ifdef PNG_READ_SUPPORTED -/* This function, added to libpng-1.0.6g, is untested. */ -int PNGAPI -png_reset_zstream(png_structp png_ptr) -{ - if (png_ptr == NULL) - return Z_STREAM_ERROR; - - return (inflateReset(&png_ptr->zstream)); -} -#endif /* PNG_READ_SUPPORTED */ - -/* This function was added to libpng-1.0.7 */ -png_uint_32 PNGAPI -png_access_version_number(void) -{ - /* Version of *.c files used when building libpng */ - return((png_uint_32)PNG_LIBPNG_VER); -} - - - -#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) -/* png_convert_size: a PNGAPI but no longer in png.h, so deleted - * at libpng 1.5.5! - */ - -/* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */ -# ifdef PNG_CHECK_cHRM_SUPPORTED - -int /* PRIVATE */ -png_check_cHRM_fixed(png_structp png_ptr, - png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, - png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, - png_fixed_point blue_x, png_fixed_point blue_y) -{ - int ret = 1; - unsigned long xy_hi,xy_lo,yx_hi,yx_lo; - - png_debug(1, "in function png_check_cHRM_fixed"); - - if (png_ptr == NULL) - return 0; - - /* (x,y,z) values are first limited to 0..100000 (PNG_FP_1), the white - * y must also be greater than 0. To test for the upper limit calculate - * (PNG_FP_1-y) - x must be <= to this for z to be >= 0 (and the expression - * cannot overflow.) At this point we know x and y are >= 0 and (x+y) is - * <= PNG_FP_1. The previous test on PNG_MAX_UINT_31 is removed because it - * pointless (and it produces compiler warnings!) - */ - if (white_x < 0 || white_y <= 0 || - red_x < 0 || red_y < 0 || - green_x < 0 || green_y < 0 || - blue_x < 0 || blue_y < 0) - { - png_warning(png_ptr, - "Ignoring attempt to set negative chromaticity value"); - ret = 0; - } - /* And (x+y) must be <= PNG_FP_1 (so z is >= 0) */ - if (white_x > PNG_FP_1 - white_y) - { - png_warning(png_ptr, "Invalid cHRM white point"); - ret = 0; - } - - if (red_x > PNG_FP_1 - red_y) - { - png_warning(png_ptr, "Invalid cHRM red point"); - ret = 0; - } - - if (green_x > PNG_FP_1 - green_y) - { - png_warning(png_ptr, "Invalid cHRM green point"); - ret = 0; - } - - if (blue_x > PNG_FP_1 - blue_y) - { - png_warning(png_ptr, "Invalid cHRM blue point"); - ret = 0; - } - - png_64bit_product(green_x - red_x, blue_y - red_y, &xy_hi, &xy_lo); - png_64bit_product(green_y - red_y, blue_x - red_x, &yx_hi, &yx_lo); - - if (xy_hi == yx_hi && xy_lo == yx_lo) - { - png_warning(png_ptr, - "Ignoring attempt to set cHRM RGB triangle with zero area"); - ret = 0; - } - - return ret; -} -# endif /* PNG_CHECK_cHRM_SUPPORTED */ - -#ifdef PNG_cHRM_SUPPORTED -/* Added at libpng-1.5.5 to support read and write of true CIEXYZ values for - * cHRM, as opposed to using chromaticities. These internal APIs return - * non-zero on a parameter error. The X, Y and Z values are required to be - * positive and less than 1.0. - */ -int png_xy_from_XYZ(png_xy *xy, png_XYZ XYZ) -{ - png_int_32 d, dwhite, whiteX, whiteY; - - d = XYZ.redX + XYZ.redY + XYZ.redZ; - if (!png_muldiv(&xy->redx, XYZ.redX, PNG_FP_1, d)) return 1; - if (!png_muldiv(&xy->redy, XYZ.redY, PNG_FP_1, d)) return 1; - dwhite = d; - whiteX = XYZ.redX; - whiteY = XYZ.redY; - - d = XYZ.greenX + XYZ.greenY + XYZ.greenZ; - if (!png_muldiv(&xy->greenx, XYZ.greenX, PNG_FP_1, d)) return 1; - if (!png_muldiv(&xy->greeny, XYZ.greenY, PNG_FP_1, d)) return 1; - dwhite += d; - whiteX += XYZ.greenX; - whiteY += XYZ.greenY; - - d = XYZ.blueX + XYZ.blueY + XYZ.blueZ; - if (!png_muldiv(&xy->bluex, XYZ.blueX, PNG_FP_1, d)) return 1; - if (!png_muldiv(&xy->bluey, XYZ.blueY, PNG_FP_1, d)) return 1; - dwhite += d; - whiteX += XYZ.blueX; - whiteY += XYZ.blueY; - - /* The reference white is simply the same of the end-point (X,Y,Z) vectors, - * thus: - */ - if (!png_muldiv(&xy->whitex, whiteX, PNG_FP_1, dwhite)) return 1; - if (!png_muldiv(&xy->whitey, whiteY, PNG_FP_1, dwhite)) return 1; - - return 0; -} - -int png_XYZ_from_xy(png_XYZ *XYZ, png_xy xy) -{ - png_fixed_point red_inverse, green_inverse, blue_scale; - png_fixed_point left, right, denominator; - - /* Check xy and, implicitly, z. Note that wide gamut color spaces typically - * have end points with 0 tristimulus values (these are impossible end - * points, but they are used to cover the possible colors.) - */ - if (xy.redx < 0 || xy.redx > PNG_FP_1) return 1; - if (xy.redy < 0 || xy.redy > PNG_FP_1-xy.redx) return 1; - if (xy.greenx < 0 || xy.greenx > PNG_FP_1) return 1; - if (xy.greeny < 0 || xy.greeny > PNG_FP_1-xy.greenx) return 1; - if (xy.bluex < 0 || xy.bluex > PNG_FP_1) return 1; - if (xy.bluey < 0 || xy.bluey > PNG_FP_1-xy.bluex) return 1; - if (xy.whitex < 0 || xy.whitex > PNG_FP_1) return 1; - if (xy.whitey < 0 || xy.whitey > PNG_FP_1-xy.whitex) return 1; - - /* The reverse calculation is more difficult because the original tristimulus - * value had 9 independent values (red,green,blue)x(X,Y,Z) however only 8 - * derived values were recorded in the cHRM chunk; - * (red,green,blue,white)x(x,y). This loses one degree of freedom and - * therefore an arbitrary ninth value has to be introduced to undo the - * original transformations. - * - * Think of the original end-points as points in (X,Y,Z) space. The - * chromaticity values (c) have the property: - * - * C - * c = --------- - * X + Y + Z - * - * For each c (x,y,z) from the corresponding original C (X,Y,Z). Thus the - * three chromaticity values (x,y,z) for each end-point obey the - * relationship: - * - * x + y + z = 1 - * - * This describes the plane in (X,Y,Z) space that intersects each axis at the - * value 1.0; call this the chromaticity plane. Thus the chromaticity - * calculation has scaled each end-point so that it is on the x+y+z=1 plane - * and chromaticity is the intersection of the vector from the origin to the - * (X,Y,Z) value with the chromaticity plane. - * - * To fully invert the chromaticity calculation we would need the three - * end-point scale factors, (red-scale, green-scale, blue-scale), but these - * were not recorded. Instead we calculated the reference white (X,Y,Z) and - * recorded the chromaticity of this. The reference white (X,Y,Z) would have - * given all three of the scale factors since: - * - * color-C = color-c * color-scale - * white-C = red-C + green-C + blue-C - * = red-c*red-scale + green-c*green-scale + blue-c*blue-scale - * - * But cHRM records only white-x and white-y, so we have lost the white scale - * factor: - * - * white-C = white-c*white-scale - * - * To handle this the inverse transformation makes an arbitrary assumption - * about white-scale: - * - * Assume: white-Y = 1.0 - * Hence: white-scale = 1/white-y - * Or: red-Y + green-Y + blue-Y = 1.0 - * - * Notice the last statement of the assumption gives an equation in three of - * the nine values we want to calculate. 8 more equations come from the - * above routine as summarised at the top above (the chromaticity - * calculation): - * - * Given: color-x = color-X / (color-X + color-Y + color-Z) - * Hence: (color-x - 1)*color-X + color.x*color-Y + color.x*color-Z = 0 - * - * This is 9 simultaneous equations in the 9 variables "color-C" and can be - * solved by Cramer's rule. Cramer's rule requires calculating 10 9x9 matrix - * determinants, however this is not as bad as it seems because only 28 of - * the total of 90 terms in the various matrices are non-zero. Nevertheless - * Cramer's rule is notoriously numerically unstable because the determinant - * calculation involves the difference of large, but similar, numbers. It is - * difficult to be sure that the calculation is stable for real world values - * and it is certain that it becomes unstable where the end points are close - * together. - * - * So this code uses the perhaps slightly less optimal but more - * understandable and totally obvious approach of calculating color-scale. - * - * This algorithm depends on the precision in white-scale and that is - * (1/white-y), so we can immediately see that as white-y approaches 0 the - * accuracy inherent in the cHRM chunk drops off substantially. - * - * libpng arithmetic: a simple invertion of the above equations - * ------------------------------------------------------------ - * - * white_scale = 1/white-y - * white-X = white-x * white-scale - * white-Y = 1.0 - * white-Z = (1 - white-x - white-y) * white_scale - * - * white-C = red-C + green-C + blue-C - * = red-c*red-scale + green-c*green-scale + blue-c*blue-scale - * - * This gives us three equations in (red-scale,green-scale,blue-scale) where - * all the coefficients are now known: - * - * red-x*red-scale + green-x*green-scale + blue-x*blue-scale - * = white-x/white-y - * red-y*red-scale + green-y*green-scale + blue-y*blue-scale = 1 - * red-z*red-scale + green-z*green-scale + blue-z*blue-scale - * = (1 - white-x - white-y)/white-y - * - * In the last equation color-z is (1 - color-x - color-y) so we can add all - * three equations together to get an alternative third: - * - * red-scale + green-scale + blue-scale = 1/white-y = white-scale - * - * So now we have a Cramer's rule solution where the determinants are just - * 3x3 - far more tractible. Unfortunately 3x3 determinants still involve - * multiplication of three coefficients so we can't guarantee to avoid - * overflow in the libpng fixed point representation. Using Cramer's rule in - * floating point is probably a good choice here, but it's not an option for - * fixed point. Instead proceed to simplify the first two equations by - * eliminating what is likely to be the largest value, blue-scale: - * - * blue-scale = white-scale - red-scale - green-scale - * - * Hence: - * - * (red-x - blue-x)*red-scale + (green-x - blue-x)*green-scale = - * (white-x - blue-x)*white-scale - * - * (red-y - blue-y)*red-scale + (green-y - blue-y)*green-scale = - * 1 - blue-y*white-scale - * - * And now we can trivially solve for (red-scale,green-scale): - * - * green-scale = - * (white-x - blue-x)*white-scale - (red-x - blue-x)*red-scale - * ----------------------------------------------------------- - * green-x - blue-x - * - * red-scale = - * 1 - blue-y*white-scale - (green-y - blue-y) * green-scale - * --------------------------------------------------------- - * red-y - blue-y - * - * Hence: - * - * red-scale = - * ( (green-x - blue-x) * (white-y - blue-y) - - * (green-y - blue-y) * (white-x - blue-x) ) / white-y - * ------------------------------------------------------------------------- - * (green-x - blue-x)*(red-y - blue-y)-(green-y - blue-y)*(red-x - blue-x) - * - * green-scale = - * ( (red-y - blue-y) * (white-x - blue-x) - - * (red-x - blue-x) * (white-y - blue-y) ) / white-y - * ------------------------------------------------------------------------- - * (green-x - blue-x)*(red-y - blue-y)-(green-y - blue-y)*(red-x - blue-x) - * - * Accuracy: - * The input values have 5 decimal digits of accuracy. The values are all in - * the range 0 < value < 1, so simple products are in the same range but may - * need up to 10 decimal digits to preserve the original precision and avoid - * underflow. Because we are using a 32-bit signed representation we cannot - * match this; the best is a little over 9 decimal digits, less than 10. - * - * The approach used here is to preserve the maximum precision within the - * signed representation. Because the red-scale calculation above uses the - * difference between two products of values that must be in the range -1..+1 - * it is sufficient to divide the product by 7; ceil(100,000/32767*2). The - * factor is irrelevant in the calculation because it is applied to both - * numerator and denominator. - * - * Note that the values of the differences of the products of the - * chromaticities in the above equations tend to be small, for example for - * the sRGB chromaticities they are: - * - * red numerator: -0.04751 - * green numerator: -0.08788 - * denominator: -0.2241 (without white-y multiplication) - * - * The resultant Y coefficients from the chromaticities of some widely used - * color space definitions are (to 15 decimal places): - * - * sRGB - * 0.212639005871510 0.715168678767756 0.072192315360734 - * Kodak ProPhoto - * 0.288071128229293 0.711843217810102 0.000085653960605 - * Adobe RGB - * 0.297344975250536 0.627363566255466 0.075291458493998 - * Adobe Wide Gamut RGB - * 0.258728243040113 0.724682314948566 0.016589442011321 - */ - /* By the argument, above overflow should be impossible here. The return - * value of 2 indicates an internal error to the caller. - */ - if (!png_muldiv(&left, xy.greenx-xy.bluex, xy.redy - xy.bluey, 7)) return 2; - if (!png_muldiv(&right, xy.greeny-xy.bluey, xy.redx - xy.bluex, 7)) return 2; - denominator = left - right; - - /* Now find the red numerator. */ - if (!png_muldiv(&left, xy.greenx-xy.bluex, xy.whitey-xy.bluey, 7)) return 2; - if (!png_muldiv(&right, xy.greeny-xy.bluey, xy.whitex-xy.bluex, 7)) return 2; - - /* Overflow is possible here and it indicates an extreme set of PNG cHRM - * chunk values. This calculation actually returns the reciprocal of the - * scale value because this allows us to delay the multiplication of white-y - * into the denominator, which tends to produce a small number. - */ - if (!png_muldiv(&red_inverse, xy.whitey, denominator, left-right) || - red_inverse <= xy.whitey /* r+g+b scales = white scale */) - return 1; - - /* Similarly for green_inverse: */ - if (!png_muldiv(&left, xy.redy-xy.bluey, xy.whitex-xy.bluex, 7)) return 2; - if (!png_muldiv(&right, xy.redx-xy.bluex, xy.whitey-xy.bluey, 7)) return 2; - if (!png_muldiv(&green_inverse, xy.whitey, denominator, left-right) || - green_inverse <= xy.whitey) - return 1; - - /* And the blue scale, the checks above guarantee this can't overflow but it - * can still produce 0 for extreme cHRM values. - */ - blue_scale = png_reciprocal(xy.whitey) - png_reciprocal(red_inverse) - - png_reciprocal(green_inverse); - if (blue_scale <= 0) return 1; - - - /* And fill in the png_XYZ: */ - if (!png_muldiv(&XYZ->redX, xy.redx, PNG_FP_1, red_inverse)) return 1; - if (!png_muldiv(&XYZ->redY, xy.redy, PNG_FP_1, red_inverse)) return 1; - if (!png_muldiv(&XYZ->redZ, PNG_FP_1 - xy.redx - xy.redy, PNG_FP_1, - red_inverse)) - return 1; - - if (!png_muldiv(&XYZ->greenX, xy.greenx, PNG_FP_1, green_inverse)) return 1; - if (!png_muldiv(&XYZ->greenY, xy.greeny, PNG_FP_1, green_inverse)) return 1; - if (!png_muldiv(&XYZ->greenZ, PNG_FP_1 - xy.greenx - xy.greeny, PNG_FP_1, - green_inverse)) - return 1; - - if (!png_muldiv(&XYZ->blueX, xy.bluex, blue_scale, PNG_FP_1)) return 1; - if (!png_muldiv(&XYZ->blueY, xy.bluey, blue_scale, PNG_FP_1)) return 1; - if (!png_muldiv(&XYZ->blueZ, PNG_FP_1 - xy.bluex - xy.bluey, blue_scale, - PNG_FP_1)) - return 1; - - return 0; /*success*/ -} - -int png_XYZ_from_xy_checked(png_structp png_ptr, png_XYZ *XYZ, png_xy xy) -{ - switch (png_XYZ_from_xy(XYZ, xy)) - { - case 0: /* success */ - return 1; - - case 1: - /* The chunk may be technically valid, but we got png_fixed_point - * overflow while trying to get XYZ values out of it. This is - * entirely benign - the cHRM chunk is pretty extreme. - */ - png_warning(png_ptr, - "extreme cHRM chunk cannot be converted to tristimulus values"); - break; - - default: - /* libpng is broken; this should be a warning but if it happens we - * want error reports so for the moment it is an error. - */ - png_error(png_ptr, "internal error in png_XYZ_from_xy"); - break; - } - - /* ERROR RETURN */ - return 0; -} -#endif - -void /* PRIVATE */ -png_check_IHDR(png_structp png_ptr, - png_uint_32 width, png_uint_32 height, int bit_depth, - int color_type, int interlace_type, int compression_type, - int filter_type) -{ - int error = 0; - - /* Check for width and height valid values */ - if (width == 0) - { - png_warning(png_ptr, "Image width is zero in IHDR"); - error = 1; - } - - if (height == 0) - { - png_warning(png_ptr, "Image height is zero in IHDR"); - error = 1; - } - -# ifdef PNG_SET_USER_LIMITS_SUPPORTED - if (width > png_ptr->user_width_max) - -# else - if (width > PNG_USER_WIDTH_MAX) -# endif - { - png_warning(png_ptr, "Image width exceeds user limit in IHDR"); - error = 1; - } - -# ifdef PNG_SET_USER_LIMITS_SUPPORTED - if (height > png_ptr->user_height_max) -# else - if (height > PNG_USER_HEIGHT_MAX) -# endif - { - png_warning(png_ptr, "Image height exceeds user limit in IHDR"); - error = 1; - } - - if (width > PNG_UINT_31_MAX) - { - png_warning(png_ptr, "Invalid image width in IHDR"); - error = 1; - } - - if (height > PNG_UINT_31_MAX) - { - png_warning(png_ptr, "Invalid image height in IHDR"); - error = 1; - } - - if (width > (PNG_UINT_32_MAX - >> 3) /* 8-byte RGBA pixels */ - - 48 /* bigrowbuf hack */ - - 1 /* filter byte */ - - 7*8 /* rounding of width to multiple of 8 pixels */ - - 8) /* extra max_pixel_depth pad */ - png_warning(png_ptr, "Width is too large for libpng to process pixels"); - - /* Check other values */ - if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && - bit_depth != 8 && bit_depth != 16) - { - png_warning(png_ptr, "Invalid bit depth in IHDR"); - error = 1; - } - - if (color_type < 0 || color_type == 1 || - color_type == 5 || color_type > 6) - { - png_warning(png_ptr, "Invalid color type in IHDR"); - error = 1; - } - - if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || - ((color_type == PNG_COLOR_TYPE_RGB || - color_type == PNG_COLOR_TYPE_GRAY_ALPHA || - color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) - { - png_warning(png_ptr, "Invalid color type/bit depth combination in IHDR"); - error = 1; - } - - if (interlace_type >= PNG_INTERLACE_LAST) - { - png_warning(png_ptr, "Unknown interlace method in IHDR"); - error = 1; - } - - if (compression_type != PNG_COMPRESSION_TYPE_BASE) - { - png_warning(png_ptr, "Unknown compression method in IHDR"); - error = 1; - } - -# ifdef PNG_MNG_FEATURES_SUPPORTED - /* Accept filter_method 64 (intrapixel differencing) only if - * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and - * 2. Libpng did not read a PNG signature (this filter_method is only - * used in PNG datastreams that are embedded in MNG datastreams) and - * 3. The application called png_permit_mng_features with a mask that - * included PNG_FLAG_MNG_FILTER_64 and - * 4. The filter_method is 64 and - * 5. The color_type is RGB or RGBA - */ - if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) && - png_ptr->mng_features_permitted) - png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); - - if (filter_type != PNG_FILTER_TYPE_BASE) - { - if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && - (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && - ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) && - (color_type == PNG_COLOR_TYPE_RGB || - color_type == PNG_COLOR_TYPE_RGB_ALPHA))) - { - png_warning(png_ptr, "Unknown filter method in IHDR"); - error = 1; - } - - if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) - { - png_warning(png_ptr, "Invalid filter method in IHDR"); - error = 1; - } - } - -# else - if (filter_type != PNG_FILTER_TYPE_BASE) - { - png_warning(png_ptr, "Unknown filter method in IHDR"); - error = 1; - } -# endif - - if (error == 1) - png_error(png_ptr, "Invalid IHDR data"); -} - -#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) -/* ASCII to fp functions */ -/* Check an ASCII formated floating point value, see the more detailed - * comments in pngpriv.h - */ -/* The following is used internally to preserve the sticky flags */ -#define png_fp_add(state, flags) ((state) |= (flags)) -#define png_fp_set(state, value) ((state) = (value) | ((state) & PNG_FP_STICKY)) - -int /* PRIVATE */ -png_check_fp_number(png_const_charp string, png_size_t size, int *statep, - png_size_tp whereami) -{ - int state = *statep; - png_size_t i = *whereami; - - while (i < size) - { - int type; - /* First find the type of the next character */ - switch (string[i]) - { - case 43: type = PNG_FP_SAW_SIGN; break; - case 45: type = PNG_FP_SAW_SIGN + PNG_FP_NEGATIVE; break; - case 46: type = PNG_FP_SAW_DOT; break; - case 48: type = PNG_FP_SAW_DIGIT; break; - case 49: case 50: case 51: case 52: - case 53: case 54: case 55: case 56: - case 57: type = PNG_FP_SAW_DIGIT + PNG_FP_NONZERO; break; - case 69: - case 101: type = PNG_FP_SAW_E; break; - default: goto PNG_FP_End; - } - - /* Now deal with this type according to the current - * state, the type is arranged to not overlap the - * bits of the PNG_FP_STATE. - */ - switch ((state & PNG_FP_STATE) + (type & PNG_FP_SAW_ANY)) - { - case PNG_FP_INTEGER + PNG_FP_SAW_SIGN: - if (state & PNG_FP_SAW_ANY) - goto PNG_FP_End; /* not a part of the number */ - - png_fp_add(state, type); - break; - - case PNG_FP_INTEGER + PNG_FP_SAW_DOT: - /* Ok as trailer, ok as lead of fraction. */ - if (state & PNG_FP_SAW_DOT) /* two dots */ - goto PNG_FP_End; - - else if (state & PNG_FP_SAW_DIGIT) /* trailing dot? */ - png_fp_add(state, type); - - else - png_fp_set(state, PNG_FP_FRACTION | type); - - break; - - case PNG_FP_INTEGER + PNG_FP_SAW_DIGIT: - if (state & PNG_FP_SAW_DOT) /* delayed fraction */ - png_fp_set(state, PNG_FP_FRACTION | PNG_FP_SAW_DOT); - - png_fp_add(state, type | PNG_FP_WAS_VALID); - - break; - - case PNG_FP_INTEGER + PNG_FP_SAW_E: - if ((state & PNG_FP_SAW_DIGIT) == 0) - goto PNG_FP_End; - - png_fp_set(state, PNG_FP_EXPONENT); - - break; - - /* case PNG_FP_FRACTION + PNG_FP_SAW_SIGN: - goto PNG_FP_End; ** no sign in fraction */ - - /* case PNG_FP_FRACTION + PNG_FP_SAW_DOT: - goto PNG_FP_End; ** Because SAW_DOT is always set */ - - case PNG_FP_FRACTION + PNG_FP_SAW_DIGIT: - png_fp_add(state, type | PNG_FP_WAS_VALID); - break; - - case PNG_FP_FRACTION + PNG_FP_SAW_E: - /* This is correct because the trailing '.' on an - * integer is handled above - so we can only get here - * with the sequence ".E" (with no preceding digits). - */ - if ((state & PNG_FP_SAW_DIGIT) == 0) - goto PNG_FP_End; - - png_fp_set(state, PNG_FP_EXPONENT); - - break; - - case PNG_FP_EXPONENT + PNG_FP_SAW_SIGN: - if (state & PNG_FP_SAW_ANY) - goto PNG_FP_End; /* not a part of the number */ - - png_fp_add(state, PNG_FP_SAW_SIGN); - - break; - - /* case PNG_FP_EXPONENT + PNG_FP_SAW_DOT: - goto PNG_FP_End; */ - - case PNG_FP_EXPONENT + PNG_FP_SAW_DIGIT: - png_fp_add(state, PNG_FP_SAW_DIGIT | PNG_FP_WAS_VALID); - - break; - - /* case PNG_FP_EXPONEXT + PNG_FP_SAW_E: - goto PNG_FP_End; */ - - default: goto PNG_FP_End; /* I.e. break 2 */ - } - - /* The character seems ok, continue. */ - ++i; - } - -PNG_FP_End: - /* Here at the end, update the state and return the correct - * return code. - */ - *statep = state; - *whereami = i; - - return (state & PNG_FP_SAW_DIGIT) != 0; -} - - -/* The same but for a complete string. */ -int -png_check_fp_string(png_const_charp string, png_size_t size) -{ - int state=0; - png_size_t char_index=0; - - if (png_check_fp_number(string, size, &state, &char_index) && - (char_index == size || string[char_index] == 0)) - return state /* must be non-zero - see above */; - - return 0; /* i.e. fail */ -} -#endif /* pCAL or sCAL */ - -#ifdef PNG_READ_sCAL_SUPPORTED -# ifdef PNG_FLOATING_POINT_SUPPORTED -/* Utility used below - a simple accurate power of ten from an integral - * exponent. - */ -static double -png_pow10(int power) -{ - int recip = 0; - double d = 1.0; - - /* Handle negative exponent with a reciprocal at the end because - * 10 is exact whereas .1 is inexact in base 2 - */ - if (power < 0) - { - if (power < DBL_MIN_10_EXP) return 0; - recip = 1, power = -power; - } - - if (power > 0) - { - /* Decompose power bitwise. */ - double mult = 10.0; - do - { - if (power & 1) d *= mult; - mult *= mult; - power >>= 1; - } - while (power > 0); - - if (recip) d = 1/d; - } - /* else power is 0 and d is 1 */ - - return d; -} - -/* Function to format a floating point value in ASCII with a given - * precision. - */ -void /* PRIVATE */ -png_ascii_from_fp(png_structp png_ptr, png_charp ascii, png_size_t size, - double fp, unsigned int precision) -{ - /* We use standard functions from math.h, but not printf because - * that would require stdio. The caller must supply a buffer of - * sufficient size or we will png_error. The tests on size and - * the space in ascii[] consumed are indicated below. - */ - if (precision < 1) - precision = DBL_DIG; - - /* Enforce the limit of the implementation precision too. */ - if (precision > DBL_DIG+1) - precision = DBL_DIG+1; - - /* Basic sanity checks */ - if (size >= precision+5) /* See the requirements below. */ - { - if (fp < 0) - { - fp = -fp; - *ascii++ = 45; /* '-' PLUS 1 TOTAL 1 */ - --size; - } - - if (fp >= DBL_MIN && fp <= DBL_MAX) - { - int exp_b10; /* A base 10 exponent */ - double base; /* 10^exp_b10 */ - - /* First extract a base 10 exponent of the number, - * the calculation below rounds down when converting - * from base 2 to base 10 (multiply by log10(2) - - * 0.3010, but 77/256 is 0.3008, so exp_b10 needs to - * be increased. Note that the arithmetic shift - * performs a floor() unlike C arithmetic - using a - * C multiply would break the following for negative - * exponents. - */ - (void)frexp(fp, &exp_b10); /* exponent to base 2 */ - - exp_b10 = (exp_b10 * 77) >> 8; /* <= exponent to base 10 */ - - /* Avoid underflow here. */ - base = png_pow10(exp_b10); /* May underflow */ - - while (base < DBL_MIN || base < fp) - { - /* And this may overflow. */ - double test = png_pow10(exp_b10+1); - - if (test <= DBL_MAX) - ++exp_b10, base = test; - - else - break; - } - - /* Normalize fp and correct exp_b10, after this fp is in the - * range [.1,1) and exp_b10 is both the exponent and the digit - * *before* which the decimal point should be inserted - * (starting with 0 for the first digit). Note that this - * works even if 10^exp_b10 is out of range because of the - * test on DBL_MAX above. - */ - fp /= base; - while (fp >= 1) fp /= 10, ++exp_b10; - - /* Because of the code above fp may, at this point, be - * less than .1, this is ok because the code below can - * handle the leading zeros this generates, so no attempt - * is made to correct that here. - */ - - { - int czero, clead, cdigits; - char exponent[10]; - - /* Allow up to two leading zeros - this will not lengthen - * the number compared to using E-n. - */ - if (exp_b10 < 0 && exp_b10 > -3) /* PLUS 3 TOTAL 4 */ - { - czero = -exp_b10; /* PLUS 2 digits: TOTAL 3 */ - exp_b10 = 0; /* Dot added below before first output. */ - } - else - czero = 0; /* No zeros to add */ - - /* Generate the digit list, stripping trailing zeros and - * inserting a '.' before a digit if the exponent is 0. - */ - clead = czero; /* Count of leading zeros */ - cdigits = 0; /* Count of digits in list. */ - - do - { - double d; - - fp *= 10.0; - - /* Use modf here, not floor and subtract, so that - * the separation is done in one step. At the end - * of the loop don't break the number into parts so - * that the final digit is rounded. - */ - if (cdigits+czero-clead+1 < (int)precision) - fp = modf(fp, &d); - - else - { - d = floor(fp + .5); - - if (d > 9.0) - { - /* Rounding up to 10, handle that here. */ - if (czero > 0) - { - --czero, d = 1; - if (cdigits == 0) --clead; - } - - else - { - while (cdigits > 0 && d > 9.0) - { - int ch = *--ascii; - - if (exp_b10 != (-1)) - ++exp_b10; - - else if (ch == 46) - { - ch = *--ascii, ++size; - /* Advance exp_b10 to '1', so that the - * decimal point happens after the - * previous digit. - */ - exp_b10 = 1; - } - - --cdigits; - d = ch - 47; /* I.e. 1+(ch-48) */ - } - - /* Did we reach the beginning? If so adjust the - * exponent but take into account the leading - * decimal point. - */ - if (d > 9.0) /* cdigits == 0 */ - { - if (exp_b10 == (-1)) - { - /* Leading decimal point (plus zeros?), if - * we lose the decimal point here it must - * be reentered below. - */ - int ch = *--ascii; - - if (ch == 46) - ++size, exp_b10 = 1; - - /* Else lost a leading zero, so 'exp_b10' is - * still ok at (-1) - */ - } - else - ++exp_b10; - - /* In all cases we output a '1' */ - d = 1.0; - } - } - } - fp = 0; /* Guarantees termination below. */ - } - - if (d == 0.0) - { - ++czero; - if (cdigits == 0) ++clead; - } - - else - { - /* Included embedded zeros in the digit count. */ - cdigits += czero - clead; - clead = 0; - - while (czero > 0) - { - /* exp_b10 == (-1) means we just output the decimal - * place - after the DP don't adjust 'exp_b10' any - * more! - */ - if (exp_b10 != (-1)) - { - if (exp_b10 == 0) *ascii++ = 46, --size; - /* PLUS 1: TOTAL 4 */ - --exp_b10; - } - *ascii++ = 48, --czero; - } - - if (exp_b10 != (-1)) - { - if (exp_b10 == 0) *ascii++ = 46, --size; /* counted - above */ - --exp_b10; - } - - *ascii++ = (char)(48 + (int)d), ++cdigits; - } - } - while (cdigits+czero-clead < (int)precision && fp > DBL_MIN); - - /* The total output count (max) is now 4+precision */ - - /* Check for an exponent, if we don't need one we are - * done and just need to terminate the string. At - * this point exp_b10==(-1) is effectively if flag - it got - * to '-1' because of the decrement after outputing - * the decimal point above (the exponent required is - * *not* -1!) - */ - if (exp_b10 >= (-1) && exp_b10 <= 2) - { - /* The following only happens if we didn't output the - * leading zeros above for negative exponent, so this - * doest add to the digit requirement. Note that the - * two zeros here can only be output if the two leading - * zeros were *not* output, so this doesn't increase - * the output count. - */ - while (--exp_b10 >= 0) *ascii++ = 48; - - *ascii = 0; - - /* Total buffer requirement (including the '\0') is - * 5+precision - see check at the start. - */ - return; - } - - /* Here if an exponent is required, adjust size for - * the digits we output but did not count. The total - * digit output here so far is at most 1+precision - no - * decimal point and no leading or trailing zeros have - * been output. - */ - size -= cdigits; - - *ascii++ = 69, --size; /* 'E': PLUS 1 TOTAL 2+precision */ - - /* The following use of an unsigned temporary avoids ambiguities in - * the signed arithmetic on exp_b10 and permits GCC at least to do - * better optimization. - */ - { - unsigned int uexp_b10; - - if (exp_b10 < 0) - { - *ascii++ = 45, --size; /* '-': PLUS 1 TOTAL 3+precision */ - uexp_b10 = -exp_b10; - } - - else - uexp_b10 = exp_b10; - - cdigits = 0; - - while (uexp_b10 > 0) - { - exponent[cdigits++] = (char)(48 + uexp_b10 % 10); - uexp_b10 /= 10; - } - } - - /* Need another size check here for the exponent digits, so - * this need not be considered above. - */ - if ((int)size > cdigits) - { - while (cdigits > 0) *ascii++ = exponent[--cdigits]; - - *ascii = 0; - - return; - } - } - } - else if (!(fp >= DBL_MIN)) - { - *ascii++ = 48; /* '0' */ - *ascii = 0; - return; - } - else - { - *ascii++ = 105; /* 'i' */ - *ascii++ = 110; /* 'n' */ - *ascii++ = 102; /* 'f' */ - *ascii = 0; - return; - } - } - - /* Here on buffer too small. */ - png_error(png_ptr, "ASCII conversion buffer too small"); -} - -# endif /* FLOATING_POINT */ - -# ifdef PNG_FIXED_POINT_SUPPORTED -/* Function to format a fixed point value in ASCII. - */ -void /* PRIVATE */ -png_ascii_from_fixed(png_structp png_ptr, png_charp ascii, png_size_t size, - png_fixed_point fp) -{ - /* Require space for 10 decimal digits, a decimal point, a minus sign and a - * trailing \0, 13 characters: - */ - if (size > 12) - { - png_uint_32 num; - - /* Avoid overflow here on the minimum integer. */ - if (fp < 0) - *ascii++ = 45, --size, num = -fp; - else - num = fp; - - if (num <= 0x80000000) /* else overflowed */ - { - unsigned int ndigits = 0, first = 16 /* flag value */; - char digits[10]; - - while (num) - { - /* Split the low digit off num: */ - unsigned int tmp = num/10; - num -= tmp*10; - digits[ndigits++] = (char)(48 + num); - /* Record the first non-zero digit, note that this is a number - * starting at 1, it's not actually the array index. - */ - if (first == 16 && num > 0) - first = ndigits; - num = tmp; - } - - if (ndigits > 0) - { - while (ndigits > 5) *ascii++ = digits[--ndigits]; - /* The remaining digits are fractional digits, ndigits is '5' or - * smaller at this point. It is certainly not zero. Check for a - * non-zero fractional digit: - */ - if (first <= 5) - { - unsigned int i; - *ascii++ = 46; /* decimal point */ - /* ndigits may be <5 for small numbers, output leading zeros - * then ndigits digits to first: - */ - i = 5; - while (ndigits < i) *ascii++ = 48, --i; - while (ndigits >= first) *ascii++ = digits[--ndigits]; - /* Don't output the trailing zeros! */ - } - } - else - *ascii++ = 48; - - /* And null terminate the string: */ - *ascii = 0; - return; - } - } - - /* Here on buffer too small. */ - png_error(png_ptr, "ASCII conversion buffer too small"); -} -# endif /* FIXED_POINT */ -#endif /* READ_SCAL */ - -#if defined(PNG_FLOATING_POINT_SUPPORTED) && \ - !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) -png_fixed_point -png_fixed(png_structp png_ptr, double fp, png_const_charp text) -{ - double r = floor(100000 * fp + .5); - - if (r > 2147483647. || r < -2147483648.) - png_fixed_error(png_ptr, text); - - return (png_fixed_point)r; -} -#endif - -#if defined(PNG_READ_GAMMA_SUPPORTED) || \ - defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG__READ_pHYs_SUPPORTED) -/* muldiv functions */ -/* This API takes signed arguments and rounds the result to the nearest - * integer (or, for a fixed point number - the standard argument - to - * the nearest .00001). Overflow and divide by zero are signalled in - * the result, a boolean - true on success, false on overflow. - */ -int -png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times, - png_int_32 divisor) -{ - /* Return a * times / divisor, rounded. */ - if (divisor != 0) - { - if (a == 0 || times == 0) - { - *res = 0; - return 1; - } - else - { -#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED - double r = a; - r *= times; - r /= divisor; - r = floor(r+.5); - - /* A png_fixed_point is a 32-bit integer. */ - if (r <= 2147483647. && r >= -2147483648.) - { - *res = (png_fixed_point)r; - return 1; - } -#else - int negative = 0; - png_uint_32 A, T, D; - png_uint_32 s16, s32, s00; - - if (a < 0) - negative = 1, A = -a; - else - A = a; - - if (times < 0) - negative = !negative, T = -times; - else - T = times; - - if (divisor < 0) - negative = !negative, D = -divisor; - else - D = divisor; - - /* Following can't overflow because the arguments only - * have 31 bits each, however the result may be 32 bits. - */ - s16 = (A >> 16) * (T & 0xffff) + - (A & 0xffff) * (T >> 16); - /* Can't overflow because the a*times bit is only 30 - * bits at most. - */ - s32 = (A >> 16) * (T >> 16) + (s16 >> 16); - s00 = (A & 0xffff) * (T & 0xffff); - - s16 = (s16 & 0xffff) << 16; - s00 += s16; - - if (s00 < s16) - ++s32; /* carry */ - - if (s32 < D) /* else overflow */ - { - /* s32.s00 is now the 64-bit product, do a standard - * division, we know that s32 < D, so the maximum - * required shift is 31. - */ - int bitshift = 32; - png_fixed_point result = 0; /* NOTE: signed */ - - while (--bitshift >= 0) - { - png_uint_32 d32, d00; - - if (bitshift > 0) - d32 = D >> (32-bitshift), d00 = D << bitshift; - - else - d32 = 0, d00 = D; - - if (s32 > d32) - { - if (s00 < d00) --s32; /* carry */ - s32 -= d32, s00 -= d00, result += 1<= d00) - s32 = 0, s00 -= d00, result += 1<= (D >> 1)) - ++result; - - if (negative) - result = -result; - - /* Check for overflow. */ - if ((negative && result <= 0) || (!negative && result >= 0)) - { - *res = result; - return 1; - } - } -#endif - } - } - - return 0; -} -#endif /* READ_GAMMA || INCH_CONVERSIONS */ - -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED) -/* The following is for when the caller doesn't much care about the - * result. - */ -png_fixed_point -png_muldiv_warn(png_structp png_ptr, png_fixed_point a, png_int_32 times, - png_int_32 divisor) -{ - png_fixed_point result; - - if (png_muldiv(&result, a, times, divisor)) - return result; - - png_warning(png_ptr, "fixed point overflow ignored"); - return 0; -} -#endif - -#ifdef PNG_READ_GAMMA_SUPPORTED /* more fixed point functions for gamma */ -/* Calculate a reciprocal, return 0 on div-by-zero or overflow. */ -png_fixed_point -png_reciprocal(png_fixed_point a) -{ -#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED - double r = floor(1E10/a+.5); - - if (r <= 2147483647. && r >= -2147483648.) - return (png_fixed_point)r; -#else - png_fixed_point res; - - if (png_muldiv(&res, 100000, 100000, a)) - return res; -#endif - - return 0; /* error/overflow */ -} - -/* A local convenience routine. */ -static png_fixed_point -png_product2(png_fixed_point a, png_fixed_point b) -{ - /* The required result is 1/a * 1/b; the following preserves accuracy. */ -#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED - double r = a * 1E-5; - r *= b; - r = floor(r+.5); - - if (r <= 2147483647. && r >= -2147483648.) - return (png_fixed_point)r; -#else - png_fixed_point res; - - if (png_muldiv(&res, a, b, 100000)) - return res; -#endif - - return 0; /* overflow */ -} - -/* The inverse of the above. */ -png_fixed_point -png_reciprocal2(png_fixed_point a, png_fixed_point b) -{ - /* The required result is 1/a * 1/b; the following preserves accuracy. */ -#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED - double r = 1E15/a; - r /= b; - r = floor(r+.5); - - if (r <= 2147483647. && r >= -2147483648.) - return (png_fixed_point)r; -#else - /* This may overflow because the range of png_fixed_point isn't symmetric, - * but this API is only used for the product of file and screen gamma so it - * doesn't matter that the smallest number it can produce is 1/21474, not - * 1/100000 - */ - png_fixed_point res = png_product2(a, b); - - if (res != 0) - return png_reciprocal(res); -#endif - - return 0; /* overflow */ -} -#endif /* READ_GAMMA */ - -#ifdef PNG_CHECK_cHRM_SUPPORTED -/* Added at libpng version 1.2.34 (Dec 8, 2008) and 1.4.0 (Jan 2, - * 2010: moved from pngset.c) */ -/* - * Multiply two 32-bit numbers, V1 and V2, using 32-bit - * arithmetic, to produce a 64-bit result in the HI/LO words. - * - * A B - * x C D - * ------ - * AD || BD - * AC || CB || 0 - * - * where A and B are the high and low 16-bit words of V1, - * C and D are the 16-bit words of V2, AD is the product of - * A and D, and X || Y is (X << 16) + Y. -*/ - -void /* PRIVATE */ -png_64bit_product (long v1, long v2, unsigned long *hi_product, - unsigned long *lo_product) -{ - int a, b, c, d; - long lo, hi, x, y; - - a = (v1 >> 16) & 0xffff; - b = v1 & 0xffff; - c = (v2 >> 16) & 0xffff; - d = v2 & 0xffff; - - lo = b * d; /* BD */ - x = a * d + c * b; /* AD + CB */ - y = ((lo >> 16) & 0xffff) + x; - - lo = (lo & 0xffff) | ((y & 0xffff) << 16); - hi = (y >> 16) & 0xffff; - - hi += a * c; /* AC */ - - *hi_product = (unsigned long)hi; - *lo_product = (unsigned long)lo; -} -#endif /* CHECK_cHRM */ - -#ifdef PNG_READ_GAMMA_SUPPORTED /* gamma table code */ -#ifndef PNG_FLOATING_ARITHMETIC_SUPPORTED -/* Fixed point gamma. - * - * To calculate gamma this code implements fast log() and exp() calls using only - * fixed point arithmetic. This code has sufficient precision for either 8-bit - * or 16-bit sample values. - * - * The tables used here were calculated using simple 'bc' programs, but C double - * precision floating point arithmetic would work fine. The programs are given - * at the head of each table. - * - * 8-bit log table - * This is a table of -log(value/255)/log(2) for 'value' in the range 128 to - * 255, so it's the base 2 logarithm of a normalized 8-bit floating point - * mantissa. The numbers are 32-bit fractions. - */ -static png_uint_32 -png_8bit_l2[128] = -{ -# ifdef PNG_DO_BC - for (i=128;i<256;++i) { .5 - l(i/255)/l(2)*65536*65536; } -# else - 4270715492U, 4222494797U, 4174646467U, 4127164793U, 4080044201U, 4033279239U, - 3986864580U, 3940795015U, 3895065449U, 3849670902U, 3804606499U, 3759867474U, - 3715449162U, 3671346997U, 3627556511U, 3584073329U, 3540893168U, 3498011834U, - 3455425220U, 3413129301U, 3371120137U, 3329393864U, 3287946700U, 3246774933U, - 3205874930U, 3165243125U, 3124876025U, 3084770202U, 3044922296U, 3005329011U, - 2965987113U, 2926893432U, 2888044853U, 2849438323U, 2811070844U, 2772939474U, - 2735041326U, 2697373562U, 2659933400U, 2622718104U, 2585724991U, 2548951424U, - 2512394810U, 2476052606U, 2439922311U, 2404001468U, 2368287663U, 2332778523U, - 2297471715U, 2262364947U, 2227455964U, 2192742551U, 2158222529U, 2123893754U, - 2089754119U, 2055801552U, 2022034013U, 1988449497U, 1955046031U, 1921821672U, - 1888774511U, 1855902668U, 1823204291U, 1790677560U, 1758320682U, 1726131893U, - 1694109454U, 1662251657U, 1630556815U, 1599023271U, 1567649391U, 1536433567U, - 1505374214U, 1474469770U, 1443718700U, 1413119487U, 1382670639U, 1352370686U, - 1322218179U, 1292211689U, 1262349810U, 1232631153U, 1203054352U, 1173618059U, - 1144320946U, 1115161701U, 1086139034U, 1057251672U, 1028498358U, 999877854U, - 971388940U, 943030410U, 914801076U, 886699767U, 858725327U, 830876614U, - 803152505U, 775551890U, 748073672U, 720716771U, 693480120U, 666362667U, - 639363374U, 612481215U, 585715177U, 559064263U, 532527486U, 506103872U, - 479792461U, 453592303U, 427502463U, 401522014U, 375650043U, 349885648U, - 324227938U, 298676034U, 273229066U, 247886176U, 222646516U, 197509248U, - 172473545U, 147538590U, 122703574U, 97967701U, 73330182U, 48790236U, - 24347096U, 0U -# endif - -#if 0 - /* The following are the values for 16-bit tables - these work fine for the - * 8-bit conversions but produce very slightly larger errors in the 16-bit - * log (about 1.2 as opposed to 0.7 absolute error in the final value). To - * use these all the shifts below must be adjusted appropriately. - */ - 65166, 64430, 63700, 62976, 62257, 61543, 60835, 60132, 59434, 58741, 58054, - 57371, 56693, 56020, 55352, 54689, 54030, 53375, 52726, 52080, 51439, 50803, - 50170, 49542, 48918, 48298, 47682, 47070, 46462, 45858, 45257, 44661, 44068, - 43479, 42894, 42312, 41733, 41159, 40587, 40020, 39455, 38894, 38336, 37782, - 37230, 36682, 36137, 35595, 35057, 34521, 33988, 33459, 32932, 32408, 31887, - 31369, 30854, 30341, 29832, 29325, 28820, 28319, 27820, 27324, 26830, 26339, - 25850, 25364, 24880, 24399, 23920, 23444, 22970, 22499, 22029, 21562, 21098, - 20636, 20175, 19718, 19262, 18808, 18357, 17908, 17461, 17016, 16573, 16132, - 15694, 15257, 14822, 14390, 13959, 13530, 13103, 12678, 12255, 11834, 11415, - 10997, 10582, 10168, 9756, 9346, 8937, 8531, 8126, 7723, 7321, 6921, 6523, - 6127, 5732, 5339, 4947, 4557, 4169, 3782, 3397, 3014, 2632, 2251, 1872, 1495, - 1119, 744, 372 -#endif -}; - -PNG_STATIC png_int_32 -png_log8bit(unsigned int x) -{ - unsigned int lg2 = 0; - /* Each time 'x' is multiplied by 2, 1 must be subtracted off the final log, - * because the log is actually negate that means adding 1. The final - * returned value thus has the range 0 (for 255 input) to 7.994 (for 1 - * input), return 7.99998 for the overflow (log 0) case - so the result is - * always at most 19 bits. - */ - if ((x &= 0xff) == 0) - return 0xffffffff; - - if ((x & 0xf0) == 0) - lg2 = 4, x <<= 4; - - if ((x & 0xc0) == 0) - lg2 += 2, x <<= 2; - - if ((x & 0x80) == 0) - lg2 += 1, x <<= 1; - - /* result is at most 19 bits, so this cast is safe: */ - return (png_int_32)((lg2 << 16) + ((png_8bit_l2[x-128]+32768)>>16)); -} - -/* The above gives exact (to 16 binary places) log2 values for 8-bit images, - * for 16-bit images we use the most significant 8 bits of the 16-bit value to - * get an approximation then multiply the approximation by a correction factor - * determined by the remaining up to 8 bits. This requires an additional step - * in the 16-bit case. - * - * We want log2(value/65535), we have log2(v'/255), where: - * - * value = v' * 256 + v'' - * = v' * f - * - * So f is value/v', which is equal to (256+v''/v') since v' is in the range 128 - * to 255 and v'' is in the range 0 to 255 f will be in the range 256 to less - * than 258. The final factor also needs to correct for the fact that our 8-bit - * value is scaled by 255, whereas the 16-bit values must be scaled by 65535. - * - * This gives a final formula using a calculated value 'x' which is value/v' and - * scaling by 65536 to match the above table: - * - * log2(x/257) * 65536 - * - * Since these numbers are so close to '1' we can use simple linear - * interpolation between the two end values 256/257 (result -368.61) and 258/257 - * (result 367.179). The values used below are scaled by a further 64 to give - * 16-bit precision in the interpolation: - * - * Start (256): -23591 - * Zero (257): 0 - * End (258): 23499 - */ -PNG_STATIC png_int_32 -png_log16bit(png_uint_32 x) -{ - unsigned int lg2 = 0; - - /* As above, but now the input has 16 bits. */ - if ((x &= 0xffff) == 0) - return 0xffffffff; - - if ((x & 0xff00) == 0) - lg2 = 8, x <<= 8; - - if ((x & 0xf000) == 0) - lg2 += 4, x <<= 4; - - if ((x & 0xc000) == 0) - lg2 += 2, x <<= 2; - - if ((x & 0x8000) == 0) - lg2 += 1, x <<= 1; - - /* Calculate the base logarithm from the top 8 bits as a 28-bit fractional - * value. - */ - lg2 <<= 28; - lg2 += (png_8bit_l2[(x>>8)-128]+8) >> 4; - - /* Now we need to interpolate the factor, this requires a division by the top - * 8 bits. Do this with maximum precision. - */ - x = ((x << 16) + (x >> 9)) / (x >> 8); - - /* Since we divided by the top 8 bits of 'x' there will be a '1' at 1<<24, - * the value at 1<<16 (ignoring this) will be 0 or 1; this gives us exactly - * 16 bits to interpolate to get the low bits of the result. Round the - * answer. Note that the end point values are scaled by 64 to retain overall - * precision and that 'lg2' is current scaled by an extra 12 bits, so adjust - * the overall scaling by 6-12. Round at every step. - */ - x -= 1U << 24; - - if (x <= 65536U) /* <= '257' */ - lg2 += ((23591U * (65536U-x)) + (1U << (16+6-12-1))) >> (16+6-12); - - else - lg2 -= ((23499U * (x-65536U)) + (1U << (16+6-12-1))) >> (16+6-12); - - /* Safe, because the result can't have more than 20 bits: */ - return (png_int_32)((lg2 + 2048) >> 12); -} - -/* The 'exp()' case must invert the above, taking a 20-bit fixed point - * logarithmic value and returning a 16 or 8-bit number as appropriate. In - * each case only the low 16 bits are relevant - the fraction - since the - * integer bits (the top 4) simply determine a shift. - * - * The worst case is the 16-bit distinction between 65535 and 65534, this - * requires perhaps spurious accuracy in the decoding of the logarithm to - * distinguish log2(65535/65534.5) - 10^-5 or 17 bits. There is little chance - * of getting this accuracy in practice. - * - * To deal with this the following exp() function works out the exponent of the - * frational part of the logarithm by using an accurate 32-bit value from the - * top four fractional bits then multiplying in the remaining bits. - */ -static png_uint_32 -png_32bit_exp[16] = -{ -# ifdef PNG_DO_BC - for (i=0;i<16;++i) { .5 + e(-i/16*l(2))*2^32; } -# else - /* NOTE: the first entry is deliberately set to the maximum 32-bit value. */ - 4294967295U, 4112874773U, 3938502376U, 3771522796U, 3611622603U, 3458501653U, - 3311872529U, 3171459999U, 3037000500U, 2908241642U, 2784941738U, 2666869345U, - 2553802834U, 2445529972U, 2341847524U, 2242560872U -# endif -}; - -/* Adjustment table; provided to explain the numbers in the code below. */ -#ifdef PNG_DO_BC -for (i=11;i>=0;--i){ print i, " ", (1 - e(-(2^i)/65536*l(2))) * 2^(32-i), "\n"} - 11 44937.64284865548751208448 - 10 45180.98734845585101160448 - 9 45303.31936980687359311872 - 8 45364.65110595323018870784 - 7 45395.35850361789624614912 - 6 45410.72259715102037508096 - 5 45418.40724413220722311168 - 4 45422.25021786898173001728 - 3 45424.17186732298419044352 - 2 45425.13273269940811464704 - 1 45425.61317555035558641664 - 0 45425.85339951654943850496 -#endif - -PNG_STATIC png_uint_32 -png_exp(png_fixed_point x) -{ - if (x > 0 && x <= 0xfffff) /* Else overflow or zero (underflow) */ - { - /* Obtain a 4-bit approximation */ - png_uint_32 e = png_32bit_exp[(x >> 12) & 0xf]; - - /* Incorporate the low 12 bits - these decrease the returned value by - * multiplying by a number less than 1 if the bit is set. The multiplier - * is determined by the above table and the shift. Notice that the values - * converge on 45426 and this is used to allow linear interpolation of the - * low bits. - */ - if (x & 0x800) - e -= (((e >> 16) * 44938U) + 16U) >> 5; - - if (x & 0x400) - e -= (((e >> 16) * 45181U) + 32U) >> 6; - - if (x & 0x200) - e -= (((e >> 16) * 45303U) + 64U) >> 7; - - if (x & 0x100) - e -= (((e >> 16) * 45365U) + 128U) >> 8; - - if (x & 0x080) - e -= (((e >> 16) * 45395U) + 256U) >> 9; - - if (x & 0x040) - e -= (((e >> 16) * 45410U) + 512U) >> 10; - - /* And handle the low 6 bits in a single block. */ - e -= (((e >> 16) * 355U * (x & 0x3fU)) + 256U) >> 9; - - /* Handle the upper bits of x. */ - e >>= x >> 16; - return e; - } - - /* Check for overflow */ - if (x <= 0) - return png_32bit_exp[0]; - - /* Else underflow */ - return 0; -} - -PNG_STATIC png_byte -png_exp8bit(png_fixed_point lg2) -{ - /* Get a 32-bit value: */ - png_uint_32 x = png_exp(lg2); - - /* Convert the 32-bit value to 0..255 by multiplying by 256-1, note that the - * second, rounding, step can't overflow because of the first, subtraction, - * step. - */ - x -= x >> 8; - return (png_byte)((x + 0x7fffffU) >> 24); -} - -PNG_STATIC png_uint_16 -png_exp16bit(png_fixed_point lg2) -{ - /* Get a 32-bit value: */ - png_uint_32 x = png_exp(lg2); - - /* Convert the 32-bit value to 0..65535 by multiplying by 65536-1: */ - x -= x >> 16; - return (png_uint_16)((x + 32767U) >> 16); -} -#endif /* FLOATING_ARITHMETIC */ - -png_byte -png_gamma_8bit_correct(unsigned int value, png_fixed_point gamma_val) -{ - if (value > 0 && value < 255) - { -# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED - double r = floor(255*pow(value/255.,gamma_val*.00001)+.5); - return (png_byte)r; -# else - png_int_32 lg2 = png_log8bit(value); - png_fixed_point res; - - if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1)) - return png_exp8bit(res); - - /* Overflow. */ - value = 0; -# endif - } - - return (png_byte)value; -} - -png_uint_16 -png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val) -{ - if (value > 0 && value < 65535) - { -# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED - double r = floor(65535*pow(value/65535.,gamma_val*.00001)+.5); - return (png_uint_16)r; -# else - png_int_32 lg2 = png_log16bit(value); - png_fixed_point res; - - if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1)) - return png_exp16bit(res); - - /* Overflow. */ - value = 0; -# endif - } - - return (png_uint_16)value; -} - -/* This does the right thing based on the bit_depth field of the - * png_struct, interpreting values as 8-bit or 16-bit. While the result - * is nominally a 16-bit value if bit depth is 8 then the result is - * 8-bit (as are the arguments.) - */ -png_uint_16 /* PRIVATE */ -png_gamma_correct(png_structp png_ptr, unsigned int value, - png_fixed_point gamma_val) -{ - if (png_ptr->bit_depth == 8) - return png_gamma_8bit_correct(value, gamma_val); - - else - return png_gamma_16bit_correct(value, gamma_val); -} - -/* This is the shared test on whether a gamma value is 'significant' - whether - * it is worth doing gamma correction. - */ -int /* PRIVATE */ -png_gamma_significant(png_fixed_point gamma_val) -{ - return gamma_val < PNG_FP_1 - PNG_GAMMA_THRESHOLD_FIXED || - gamma_val > PNG_FP_1 + PNG_GAMMA_THRESHOLD_FIXED; -} - -/* Internal function to build a single 16-bit table - the table consists of - * 'num' 256-entry subtables, where 'num' is determined by 'shift' - the amount - * to shift the input values right (or 16-number_of_signifiant_bits). - * - * The caller is responsible for ensuring that the table gets cleaned up on - * png_error (i.e. if one of the mallocs below fails) - i.e. the *table argument - * should be somewhere that will be cleaned. - */ -static void -png_build_16bit_table(png_structp png_ptr, png_uint_16pp *ptable, - PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val) -{ - /* Various values derived from 'shift': */ - PNG_CONST unsigned int num = 1U << (8U - shift); - PNG_CONST unsigned int max = (1U << (16U - shift))-1U; - PNG_CONST unsigned int max_by_2 = 1U << (15U-shift); - unsigned int i; - - png_uint_16pp table = *ptable = - (png_uint_16pp)png_calloc(png_ptr, num * png_sizeof(png_uint_16p)); - - for (i = 0; i < num; i++) - { - png_uint_16p sub_table = table[i] = - (png_uint_16p)png_malloc(png_ptr, 256 * png_sizeof(png_uint_16)); - - /* The 'threshold' test is repeated here because it can arise for one of - * the 16-bit tables even if the others don't hit it. - */ - if (png_gamma_significant(gamma_val)) - { - /* The old code would overflow at the end and this would cause the - * 'pow' function to return a result >1, resulting in an - * arithmetic error. This code follows the spec exactly; ig is - * the recovered input sample, it always has 8-16 bits. - * - * We want input * 65535/max, rounded, the arithmetic fits in 32 - * bits (unsigned) so long as max <= 32767. - */ - unsigned int j; - for (j = 0; j < 256; j++) - { - png_uint_32 ig = (j << (8-shift)) + i; -# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED - /* Inline the 'max' scaling operation: */ - double d = floor(65535*pow(ig/(double)max, gamma_val*.00001)+.5); - sub_table[j] = (png_uint_16)d; -# else - if (shift) - ig = (ig * 65535U + max_by_2)/max; - - sub_table[j] = png_gamma_16bit_correct(ig, gamma_val); -# endif - } - } - else - { - /* We must still build a table, but do it the fast way. */ - unsigned int j; - - for (j = 0; j < 256; j++) - { - png_uint_32 ig = (j << (8-shift)) + i; - - if (shift) - ig = (ig * 65535U + max_by_2)/max; - - sub_table[j] = (png_uint_16)ig; - } - } - } -} - -/* NOTE: this function expects the *inverse* of the overall gamma transformation - * required. - */ -static void -png_build_16to8_table(png_structp png_ptr, png_uint_16pp *ptable, - PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val) -{ - PNG_CONST unsigned int num = 1U << (8U - shift); - PNG_CONST unsigned int max = (1U << (16U - shift))-1U; - unsigned int i; - png_uint_32 last; - - png_uint_16pp table = *ptable = - (png_uint_16pp)png_calloc(png_ptr, num * png_sizeof(png_uint_16p)); - - /* 'num' is the number of tables and also the number of low bits of the - * input 16-bit value used to select a table. Each table is itself indexed - * by the high 8 bits of the value. - */ - for (i = 0; i < num; i++) - table[i] = (png_uint_16p)png_malloc(png_ptr, - 256 * png_sizeof(png_uint_16)); - - /* 'gamma_val' is set to the reciprocal of the value calculated above, so - * pow(out,g) is an *input* value. 'last' is the last input value set. - * - * In the loop 'i' is used to find output values. Since the output is - * 8-bit there are only 256 possible values. The tables are set up to - * select the closest possible output value for each input by finding - * the input value at the boundary between each pair of output values - * and filling the table up to that boundary with the lower output - * value. - * - * The boundary values are 0.5,1.5..253.5,254.5. Since these are 9-bit - * values the code below uses a 16-bit value in i; the values start at - * 128.5 (for 0.5) and step by 257, for a total of 254 values (the last - * entries are filled with 255). Start i at 128 and fill all 'last' - * table entries <= 'max' - */ - last = 0; - for (i = 0; i < 255; ++i) /* 8-bit output value */ - { - /* Find the corresponding maximum input value */ - png_uint_16 out = (png_uint_16)(i * 257U); /* 16-bit output value */ - - /* Find the boundary value in 16 bits: */ - png_uint_32 bound = png_gamma_16bit_correct(out+128U, gamma_val); - - /* Adjust (round) to (16-shift) bits: */ - bound = (bound * max + 32768U)/65535U + 1U; - - while (last < bound) - { - table[last & (0xffU >> shift)][last >> (8U - shift)] = out; - last++; - } - } - - /* And fill in the final entries. */ - while (last < (num << 8)) - { - table[last & (0xff >> shift)][last >> (8U - shift)] = 65535U; - last++; - } -} - -/* Build a single 8-bit table: same as the 16-bit case but much simpler (and - * typically much faster). Note that libpng currently does no sBIT processing - * (apparently contrary to the spec) so a 256-entry table is always generated. - */ -static void -png_build_8bit_table(png_structp png_ptr, png_bytepp ptable, - PNG_CONST png_fixed_point gamma_val) -{ - unsigned int i; - png_bytep table = *ptable = (png_bytep)png_malloc(png_ptr, 256); - - if (png_gamma_significant(gamma_val)) for (i=0; i<256; i++) - table[i] = png_gamma_8bit_correct(i, gamma_val); - - else for (i=0; i<256; ++i) - table[i] = (png_byte)i; -} - -/* Used from png_read_destroy and below to release the memory used by the gamma - * tables. - */ -void /* PRIVATE */ -png_destroy_gamma_table(png_structp png_ptr) -{ - png_free(png_ptr, png_ptr->gamma_table); - png_ptr->gamma_table = NULL; - - if (png_ptr->gamma_16_table != NULL) - { - int i; - int istop = (1 << (8 - png_ptr->gamma_shift)); - for (i = 0; i < istop; i++) - { - png_free(png_ptr, png_ptr->gamma_16_table[i]); - } - png_free(png_ptr, png_ptr->gamma_16_table); - png_ptr->gamma_16_table = NULL; - } - -#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ - defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ - defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) - png_free(png_ptr, png_ptr->gamma_from_1); - png_ptr->gamma_from_1 = NULL; - png_free(png_ptr, png_ptr->gamma_to_1); - png_ptr->gamma_to_1 = NULL; - - if (png_ptr->gamma_16_from_1 != NULL) - { - int i; - int istop = (1 << (8 - png_ptr->gamma_shift)); - for (i = 0; i < istop; i++) - { - png_free(png_ptr, png_ptr->gamma_16_from_1[i]); - } - png_free(png_ptr, png_ptr->gamma_16_from_1); - png_ptr->gamma_16_from_1 = NULL; - } - if (png_ptr->gamma_16_to_1 != NULL) - { - int i; - int istop = (1 << (8 - png_ptr->gamma_shift)); - for (i = 0; i < istop; i++) - { - png_free(png_ptr, png_ptr->gamma_16_to_1[i]); - } - png_free(png_ptr, png_ptr->gamma_16_to_1); - png_ptr->gamma_16_to_1 = NULL; - } -#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ -} - -/* We build the 8- or 16-bit gamma tables here. Note that for 16-bit - * tables, we don't make a full table if we are reducing to 8-bit in - * the future. Note also how the gamma_16 tables are segmented so that - * we don't need to allocate > 64K chunks for a full 16-bit table. - */ -void /* PRIVATE */ -png_build_gamma_table(png_structp png_ptr, int bit_depth) -{ - png_debug(1, "in png_build_gamma_table"); - - /* Remove any existing table; this copes with multiple calls to - * png_read_update_info. The warning is because building the gamma tables - * multiple times is a performance hit - it's harmless but the ability to call - * png_read_update_info() multiple times is new in 1.5.6 so it seems sensible - * to warn if the app introduces such a hit. - */ - if (png_ptr->gamma_table != NULL || png_ptr->gamma_16_table != NULL) - { - png_warning(png_ptr, "gamma table being rebuilt"); - png_destroy_gamma_table(png_ptr); - } - - if (bit_depth <= 8) - { - png_build_8bit_table(png_ptr, &png_ptr->gamma_table, - png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->gamma, - png_ptr->screen_gamma) : PNG_FP_1); - -#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ - defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ - defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) - if (png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) - { - png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1, - png_reciprocal(png_ptr->gamma)); - - png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1, - png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) : - png_ptr->gamma/* Probably doing rgb_to_gray */); - } -#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ - } - else - { - png_byte shift, sig_bit; - - if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) - { - sig_bit = png_ptr->sig_bit.red; - - if (png_ptr->sig_bit.green > sig_bit) - sig_bit = png_ptr->sig_bit.green; - - if (png_ptr->sig_bit.blue > sig_bit) - sig_bit = png_ptr->sig_bit.blue; - } - else - sig_bit = png_ptr->sig_bit.gray; - - /* 16-bit gamma code uses this equation: - * - * ov = table[(iv & 0xff) >> gamma_shift][iv >> 8] - * - * Where 'iv' is the input color value and 'ov' is the output value - - * pow(iv, gamma). - * - * Thus the gamma table consists of up to 256 256-entry tables. The table - * is selected by the (8-gamma_shift) most significant of the low 8 bits of - * the color value then indexed by the upper 8 bits: - * - * table[low bits][high 8 bits] - * - * So the table 'n' corresponds to all those 'iv' of: - * - * ..<(n+1 << gamma_shift)-1> - * - */ - if (sig_bit > 0 && sig_bit < 16U) - shift = (png_byte)(16U - sig_bit); /* shift == insignificant bits */ - - else - shift = 0; /* keep all 16 bits */ - - if (png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) - { - /* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively - * the significant bits in the *input* when the output will - * eventually be 8 bits. By default it is 11. - */ - if (shift < (16U - PNG_MAX_GAMMA_8)) - shift = (16U - PNG_MAX_GAMMA_8); - } - - if (shift > 8U) - shift = 8U; /* Guarantees at least one table! */ - - png_ptr->gamma_shift = shift; - -#ifdef PNG_16BIT_SUPPORTED - /* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now - * PNG_COMPOSE). This effectively smashed the background calculation for - * 16-bit output because the 8-bit table assumes the result will be reduced - * to 8 bits. - */ - if (png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) -#endif - png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift, - png_ptr->screen_gamma > 0 ? png_product2(png_ptr->gamma, - png_ptr->screen_gamma) : PNG_FP_1); - -#ifdef PNG_16BIT_SUPPORTED - else - png_build_16bit_table(png_ptr, &png_ptr->gamma_16_table, shift, - png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->gamma, - png_ptr->screen_gamma) : PNG_FP_1); -#endif - -#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ - defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ - defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) - if (png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) - { - png_build_16bit_table(png_ptr, &png_ptr->gamma_16_to_1, shift, - png_reciprocal(png_ptr->gamma)); - - /* Notice that the '16 from 1' table should be full precision, however - * the lookup on this table still uses gamma_shift, so it can't be. - * TODO: fix this. - */ - png_build_16bit_table(png_ptr, &png_ptr->gamma_16_from_1, shift, - png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) : - png_ptr->gamma/* Probably doing rgb_to_gray */); - } -#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ - } -} -#endif /* READ_GAMMA */ -#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ + +/* png.c - location for general purpose libpng functions + * + * Last changed in libpng 1.5.11 [June 14, 2012] + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "pngpriv.h" + +/* Generate a compiler error if there is an old png.h in the search path. */ +typedef png_libpng_version_1_5_13 Your_png_h_is_not_version_1_5_13; + +/* Tells libpng that we have already handled the first "num_bytes" bytes + * of the PNG file signature. If the PNG data is embedded into another + * stream we can set num_bytes = 8 so that libpng will not attempt to read + * or write any of the magic bytes before it starts on the IHDR. + */ + +#ifdef PNG_READ_SUPPORTED +void PNGAPI +png_set_sig_bytes(png_structp png_ptr, int num_bytes) +{ + png_debug(1, "in png_set_sig_bytes"); + + if (png_ptr == NULL) + return; + + if (num_bytes > 8) + png_error(png_ptr, "Too many bytes for PNG signature"); + + png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes); +} + +/* Checks whether the supplied bytes match the PNG signature. We allow + * checking less than the full 8-byte signature so that those apps that + * already read the first few bytes of a file to determine the file type + * can simply check the remaining bytes for extra assurance. Returns + * an integer less than, equal to, or greater than zero if sig is found, + * respectively, to be less than, to match, or be greater than the correct + * PNG signature (this is the same behavior as strcmp, memcmp, etc). + */ +int PNGAPI +png_sig_cmp(png_const_bytep sig, png_size_t start, png_size_t num_to_check) +{ + png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; + + if (num_to_check > 8) + num_to_check = 8; + + else if (num_to_check < 1) + return (-1); + + if (start > 7) + return (-1); + + if (start + num_to_check > 8) + num_to_check = 8 - start; + + return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check))); +} + +#endif /* PNG_READ_SUPPORTED */ + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +/* Function to allocate memory for zlib */ +PNG_FUNCTION(voidpf /* PRIVATE */, +png_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED) +{ + png_voidp ptr; + png_structp p=(png_structp)png_ptr; + png_uint_32 save_flags=p->flags; + png_alloc_size_t num_bytes; + + if (png_ptr == NULL) + return (NULL); + + if (items > PNG_UINT_32_MAX/size) + { + png_warning (p, "Potential overflow in png_zalloc()"); + return (NULL); + } + num_bytes = (png_alloc_size_t)items * size; + + p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; + ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes); + p->flags=save_flags; + + return ((voidpf)ptr); +} + +/* Function to free memory for zlib */ +void /* PRIVATE */ +png_zfree(voidpf png_ptr, voidpf ptr) +{ + png_free((png_structp)png_ptr, (png_voidp)ptr); +} + +/* Reset the CRC variable to 32 bits of 1's. Care must be taken + * in case CRC is > 32 bits to leave the top bits 0. + */ +void /* PRIVATE */ +png_reset_crc(png_structp png_ptr) +{ + /* The cast is safe because the crc is a 32 bit value. */ + png_ptr->crc = (png_uint_32)crc32(0, Z_NULL, 0); +} + +/* Calculate the CRC over a section of data. We can only pass as + * much data to this routine as the largest single buffer size. We + * also check that this data will actually be used before going to the + * trouble of calculating it. + */ +void /* PRIVATE */ +png_calculate_crc(png_structp png_ptr, png_const_bytep ptr, png_size_t length) +{ + int need_crc = 1; + + if (PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name)) + { + if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) == + (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN)) + need_crc = 0; + } + + else /* critical */ + { + if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) + need_crc = 0; + } + + /* 'uLong' is defined as unsigned long, this means that on some systems it is + * a 64 bit value. crc32, however, returns 32 bits so the following cast is + * safe. 'uInt' may be no more than 16 bits, so it is necessary to perform a + * loop here. + */ + if (need_crc && length > 0) + { + uLong crc = png_ptr->crc; /* Should never issue a warning */ + + do + { + uInt safeLength = (uInt)length; + if (safeLength == 0) + safeLength = (uInt)-1; /* evil, but safe */ + + crc = crc32(crc, ptr, safeLength); + + /* The following should never issue compiler warnings, if they do the + * target system has characteristics that will probably violate other + * assumptions within the libpng code. + */ + ptr += safeLength; + length -= safeLength; + } + while (length > 0); + + /* And the following is always safe because the crc is only 32 bits. */ + png_ptr->crc = (png_uint_32)crc; + } +} + +/* Check a user supplied version number, called from both read and write + * functions that create a png_struct + */ +int +png_user_version_check(png_structp png_ptr, png_const_charp user_png_ver) +{ + if (user_png_ver) + { + int i = 0; + + do + { + if (user_png_ver[i] != png_libpng_ver[i]) + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; + } while (png_libpng_ver[i++]); + } + + else + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; + + if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) + { + /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so + * we must recompile any applications that use any older library version. + * For versions after libpng 1.0, we will be compatible, so we need + * only check the first digit. + */ + if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || + (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || + (user_png_ver[0] == '0' && user_png_ver[2] < '9')) + { +#ifdef PNG_WARNINGS_SUPPORTED + size_t pos = 0; + char m[128]; + + pos = png_safecat(m, sizeof m, pos, "Application built with libpng-"); + pos = png_safecat(m, sizeof m, pos, user_png_ver); + pos = png_safecat(m, sizeof m, pos, " but running with "); + pos = png_safecat(m, sizeof m, pos, png_libpng_ver); + + png_warning(png_ptr, m); +#endif + +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags = 0; +#endif + + return 0; + } + } + + /* Success return. */ + return 1; +} + +/* Allocate the memory for an info_struct for the application. We don't + * really need the png_ptr, but it could potentially be useful in the + * future. This should be used in favour of malloc(png_sizeof(png_info)) + * and png_info_init() so that applications that want to use a shared + * libpng don't have to be recompiled if png_info changes size. + */ +PNG_FUNCTION(png_infop,PNGAPI +png_create_info_struct,(png_structp png_ptr),PNG_ALLOCATED) +{ + png_infop info_ptr; + + png_debug(1, "in png_create_info_struct"); + + if (png_ptr == NULL) + return (NULL); + +#ifdef PNG_USER_MEM_SUPPORTED + info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, + png_ptr->malloc_fn, png_ptr->mem_ptr); +#else + info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); +#endif + if (info_ptr != NULL) + png_info_init_3(&info_ptr, png_sizeof(png_info)); + + return (info_ptr); +} + +/* This function frees the memory associated with a single info struct. + * Normally, one would use either png_destroy_read_struct() or + * png_destroy_write_struct() to free an info struct, but this may be + * useful for some applications. + */ +void PNGAPI +png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) +{ + png_infop info_ptr = NULL; + + png_debug(1, "in png_destroy_info_struct"); + + if (png_ptr == NULL) + return; + + if (info_ptr_ptr != NULL) + info_ptr = *info_ptr_ptr; + + if (info_ptr != NULL) + { + png_info_destroy(png_ptr, info_ptr); + +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn, + png_ptr->mem_ptr); +#else + png_destroy_struct((png_voidp)info_ptr); +#endif + *info_ptr_ptr = NULL; + } +} + +/* Initialize the info structure. This is now an internal function (0.89) + * and applications using it are urged to use png_create_info_struct() + * instead. + */ + +void PNGAPI +png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) +{ + png_infop info_ptr = *ptr_ptr; + + png_debug(1, "in png_info_init_3"); + + if (info_ptr == NULL) + return; + + if (png_sizeof(png_info) > png_info_struct_size) + { + png_destroy_struct(info_ptr); + info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); + *ptr_ptr = info_ptr; + } + + /* Set everything to 0 */ + png_memset(info_ptr, 0, png_sizeof(png_info)); +} + +void PNGAPI +png_data_freer(png_structp png_ptr, png_infop info_ptr, + int freer, png_uint_32 mask) +{ + png_debug(1, "in png_data_freer"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (freer == PNG_DESTROY_WILL_FREE_DATA) + info_ptr->free_me |= mask; + + else if (freer == PNG_USER_WILL_FREE_DATA) + info_ptr->free_me &= ~mask; + + else + png_warning(png_ptr, + "Unknown freer parameter in png_data_freer"); +} + +void PNGAPI +png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, + int num) +{ + png_debug(1, "in png_free_data"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + +#ifdef PNG_TEXT_SUPPORTED + /* Free text item num or (if num == -1) all text items */ + if ((mask & PNG_FREE_TEXT) & info_ptr->free_me) + { + if (num != -1) + { + if (info_ptr->text && info_ptr->text[num].key) + { + png_free(png_ptr, info_ptr->text[num].key); + info_ptr->text[num].key = NULL; + } + } + + else + { + int i; + for (i = 0; i < info_ptr->num_text; i++) + png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i); + png_free(png_ptr, info_ptr->text); + info_ptr->text = NULL; + info_ptr->num_text=0; + } + } +#endif + +#ifdef PNG_tRNS_SUPPORTED + /* Free any tRNS entry */ + if ((mask & PNG_FREE_TRNS) & info_ptr->free_me) + { + png_free(png_ptr, info_ptr->trans_alpha); + info_ptr->trans_alpha = NULL; + info_ptr->valid &= ~PNG_INFO_tRNS; + } +#endif + +#ifdef PNG_sCAL_SUPPORTED + /* Free any sCAL entry */ + if ((mask & PNG_FREE_SCAL) & info_ptr->free_me) + { + png_free(png_ptr, info_ptr->scal_s_width); + png_free(png_ptr, info_ptr->scal_s_height); + info_ptr->scal_s_width = NULL; + info_ptr->scal_s_height = NULL; + info_ptr->valid &= ~PNG_INFO_sCAL; + } +#endif + +#ifdef PNG_pCAL_SUPPORTED + /* Free any pCAL entry */ + if ((mask & PNG_FREE_PCAL) & info_ptr->free_me) + { + png_free(png_ptr, info_ptr->pcal_purpose); + png_free(png_ptr, info_ptr->pcal_units); + info_ptr->pcal_purpose = NULL; + info_ptr->pcal_units = NULL; + if (info_ptr->pcal_params != NULL) + { + int i; + for (i = 0; i < (int)info_ptr->pcal_nparams; i++) + { + png_free(png_ptr, info_ptr->pcal_params[i]); + info_ptr->pcal_params[i] = NULL; + } + png_free(png_ptr, info_ptr->pcal_params); + info_ptr->pcal_params = NULL; + } + info_ptr->valid &= ~PNG_INFO_pCAL; + } +#endif + +#ifdef PNG_iCCP_SUPPORTED + /* Free any iCCP entry */ + if ((mask & PNG_FREE_ICCP) & info_ptr->free_me) + { + png_free(png_ptr, info_ptr->iccp_name); + png_free(png_ptr, info_ptr->iccp_profile); + info_ptr->iccp_name = NULL; + info_ptr->iccp_profile = NULL; + info_ptr->valid &= ~PNG_INFO_iCCP; + } +#endif + +#ifdef PNG_sPLT_SUPPORTED + /* Free a given sPLT entry, or (if num == -1) all sPLT entries */ + if ((mask & PNG_FREE_SPLT) & info_ptr->free_me) + { + if (num != -1) + { + if (info_ptr->splt_palettes) + { + png_free(png_ptr, info_ptr->splt_palettes[num].name); + png_free(png_ptr, info_ptr->splt_palettes[num].entries); + info_ptr->splt_palettes[num].name = NULL; + info_ptr->splt_palettes[num].entries = NULL; + } + } + + else + { + if (info_ptr->splt_palettes_num) + { + int i; + for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) + png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i); + + png_free(png_ptr, info_ptr->splt_palettes); + info_ptr->splt_palettes = NULL; + info_ptr->splt_palettes_num = 0; + } + info_ptr->valid &= ~PNG_INFO_sPLT; + } + } +#endif + +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED + if (png_ptr->unknown_chunk.data) + { + png_free(png_ptr, png_ptr->unknown_chunk.data); + png_ptr->unknown_chunk.data = NULL; + } + + if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) + { + if (num != -1) + { + if (info_ptr->unknown_chunks) + { + png_free(png_ptr, info_ptr->unknown_chunks[num].data); + info_ptr->unknown_chunks[num].data = NULL; + } + } + + else + { + int i; + + if (info_ptr->unknown_chunks_num) + { + for (i = 0; i < info_ptr->unknown_chunks_num; i++) + png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i); + + png_free(png_ptr, info_ptr->unknown_chunks); + info_ptr->unknown_chunks = NULL; + info_ptr->unknown_chunks_num = 0; + } + } + } +#endif + +#ifdef PNG_hIST_SUPPORTED + /* Free any hIST entry */ + if ((mask & PNG_FREE_HIST) & info_ptr->free_me) + { + png_free(png_ptr, info_ptr->hist); + info_ptr->hist = NULL; + info_ptr->valid &= ~PNG_INFO_hIST; + } +#endif + + /* Free any PLTE entry that was internally allocated */ + if ((mask & PNG_FREE_PLTE) & info_ptr->free_me) + { + png_zfree(png_ptr, info_ptr->palette); + info_ptr->palette = NULL; + info_ptr->valid &= ~PNG_INFO_PLTE; + info_ptr->num_palette = 0; + } + +#ifdef PNG_INFO_IMAGE_SUPPORTED + /* Free any image bits attached to the info structure */ + if ((mask & PNG_FREE_ROWS) & info_ptr->free_me) + { + if (info_ptr->row_pointers) + { + int row; + for (row = 0; row < (int)info_ptr->height; row++) + { + png_free(png_ptr, info_ptr->row_pointers[row]); + info_ptr->row_pointers[row] = NULL; + } + png_free(png_ptr, info_ptr->row_pointers); + info_ptr->row_pointers = NULL; + } + info_ptr->valid &= ~PNG_INFO_IDAT; + } +#endif + + if (num != -1) + mask &= ~PNG_FREE_MUL; + + info_ptr->free_me &= ~mask; +} + +/* This is an internal routine to free any memory that the info struct is + * pointing to before re-using it or freeing the struct itself. Recall + * that png_free() checks for NULL pointers for us. + */ +void /* PRIVATE */ +png_info_destroy(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_info_destroy"); + + png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + if (png_ptr->num_chunk_list) + { + png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list = NULL; + png_ptr->num_chunk_list = 0; + } +#endif + + png_info_init_3(&info_ptr, png_sizeof(png_info)); +} +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ + +/* This function returns a pointer to the io_ptr associated with the user + * functions. The application should free any memory associated with this + * pointer before png_write_destroy() or png_read_destroy() are called. + */ +png_voidp PNGAPI +png_get_io_ptr(png_structp png_ptr) +{ + if (png_ptr == NULL) + return (NULL); + + return (png_ptr->io_ptr); +} + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +# ifdef PNG_STDIO_SUPPORTED +/* Initialize the default input/output functions for the PNG file. If you + * use your own read or write routines, you can call either png_set_read_fn() + * or png_set_write_fn() instead of png_init_io(). If you have defined + * PNG_NO_STDIO or otherwise disabled PNG_STDIO_SUPPORTED, you must use a + * function of your own because "FILE *" isn't necessarily available. + */ +void PNGAPI +png_init_io(png_structp png_ptr, png_FILE_p fp) +{ + png_debug(1, "in png_init_io"); + + if (png_ptr == NULL) + return; + + png_ptr->io_ptr = (png_voidp)fp; +} +# endif + +# ifdef PNG_TIME_RFC1123_SUPPORTED +/* Convert the supplied time into an RFC 1123 string suitable for use in + * a "Creation Time" or other text-based time string. + */ +png_const_charp PNGAPI +png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime) +{ + static PNG_CONST char short_months[12][4] = + {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + + if (png_ptr == NULL) + return (NULL); + + if (ptime->year > 9999 /* RFC1123 limitation */ || + ptime->month == 0 || ptime->month > 12 || + ptime->day == 0 || ptime->day > 31 || + ptime->hour > 23 || ptime->minute > 59 || + ptime->second > 60) + { + png_warning(png_ptr, "Ignoring invalid time value"); + return (NULL); + } + + { + size_t pos = 0; + char number_buf[5]; /* enough for a four-digit year */ + +# define APPEND_STRING(string)\ + pos = png_safecat(png_ptr->time_buffer, sizeof png_ptr->time_buffer,\ + pos, (string)) +# define APPEND_NUMBER(format, value)\ + APPEND_STRING(PNG_FORMAT_NUMBER(number_buf, format, (value))) +# define APPEND(ch)\ + if (pos < (sizeof png_ptr->time_buffer)-1)\ + png_ptr->time_buffer[pos++] = (ch) + + APPEND_NUMBER(PNG_NUMBER_FORMAT_u, (unsigned)ptime->day); + APPEND(' '); + APPEND_STRING(short_months[(ptime->month - 1)]); + APPEND(' '); + APPEND_NUMBER(PNG_NUMBER_FORMAT_u, ptime->year); + APPEND(' '); + APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->hour); + APPEND(':'); + APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->minute); + APPEND(':'); + APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->second); + APPEND_STRING(" +0000"); /* This reliably terminates the buffer */ + +# undef APPEND +# undef APPEND_NUMBER +# undef APPEND_STRING + } + + return png_ptr->time_buffer; +} +# endif /* PNG_TIME_RFC1123_SUPPORTED */ + +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ + +png_const_charp PNGAPI +png_get_copyright(png_const_structp png_ptr) +{ + PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ +#ifdef PNG_STRING_COPYRIGHT + return PNG_STRING_COPYRIGHT +#else +# ifdef __STDC__ + return PNG_STRING_NEWLINE \ + "libpng version 1.5.13 - September 27, 2012" PNG_STRING_NEWLINE \ + "Copyright (c) 1998-2012 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ + "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ + "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ + PNG_STRING_NEWLINE; +# else + return "libpng version 1.5.13 - September 27, 2012\ + Copyright (c) 1998-2012 Glenn Randers-Pehrson\ + Copyright (c) 1996-1997 Andreas Dilger\ + Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; +# endif +#endif +} + +/* The following return the library version as a short string in the + * format 1.0.0 through 99.99.99zz. To get the version of *.h files + * used with your application, print out PNG_LIBPNG_VER_STRING, which + * is defined in png.h. + * Note: now there is no difference between png_get_libpng_ver() and + * png_get_header_ver(). Due to the version_nn_nn_nn typedef guard, + * it is guaranteed that png.c uses the correct version of png.h. + */ +png_const_charp PNGAPI +png_get_libpng_ver(png_const_structp png_ptr) +{ + /* Version of *.c files used when building libpng */ + return png_get_header_ver(png_ptr); +} + +png_const_charp PNGAPI +png_get_header_ver(png_const_structp png_ptr) +{ + /* Version of *.h files used when building libpng */ + PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ + return PNG_LIBPNG_VER_STRING; +} + +png_const_charp PNGAPI +png_get_header_version(png_const_structp png_ptr) +{ + /* Returns longer string containing both version and date */ + PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ +#ifdef __STDC__ + return PNG_HEADER_VERSION_STRING +# ifndef PNG_READ_SUPPORTED + " (NO READ SUPPORT)" +# endif + PNG_STRING_NEWLINE; +#else + return PNG_HEADER_VERSION_STRING; +#endif +} + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +int PNGAPI +png_handle_as_unknown(png_structp png_ptr, png_const_bytep chunk_name) +{ + /* Check chunk_name and return "keep" value if it's on the list, else 0 */ + png_const_bytep p, p_end; + + if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list <= 0) + return PNG_HANDLE_CHUNK_AS_DEFAULT; + + p_end = png_ptr->chunk_list; + p = p_end + png_ptr->num_chunk_list*5; /* beyond end */ + + /* The code is the fifth byte after each four byte string. Historically this + * code was always searched from the end of the list, so it should continue + * to do so in case there are duplicated entries. + */ + do /* num_chunk_list > 0, so at least one */ + { + p -= 5; + if (!png_memcmp(chunk_name, p, 4)) + return p[4]; + } + while (p > p_end); + + return PNG_HANDLE_CHUNK_AS_DEFAULT; +} + +int /* PRIVATE */ +png_chunk_unknown_handling(png_structp png_ptr, png_uint_32 chunk_name) +{ + png_byte chunk_string[5]; + + PNG_CSTRING_FROM_CHUNK(chunk_string, chunk_name); + return png_handle_as_unknown(png_ptr, chunk_string); +} +#endif + +#ifdef PNG_READ_SUPPORTED +/* This function, added to libpng-1.0.6g, is untested. */ +int PNGAPI +png_reset_zstream(png_structp png_ptr) +{ + if (png_ptr == NULL) + return Z_STREAM_ERROR; + + return (inflateReset(&png_ptr->zstream)); +} +#endif /* PNG_READ_SUPPORTED */ + +/* This function was added to libpng-1.0.7 */ +png_uint_32 PNGAPI +png_access_version_number(void) +{ + /* Version of *.c files used when building libpng */ + return((png_uint_32)PNG_LIBPNG_VER); +} + + + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +/* png_convert_size: a PNGAPI but no longer in png.h, so deleted + * at libpng 1.5.5! + */ + +/* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */ +# ifdef PNG_CHECK_cHRM_SUPPORTED + +int /* PRIVATE */ +png_check_cHRM_fixed(png_structp png_ptr, + png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, + png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, + png_fixed_point blue_x, png_fixed_point blue_y) +{ + int ret = 1; + unsigned long xy_hi,xy_lo,yx_hi,yx_lo; + + png_debug(1, "in function png_check_cHRM_fixed"); + + if (png_ptr == NULL) + return 0; + + /* (x,y,z) values are first limited to 0..100000 (PNG_FP_1), the white + * y must also be greater than 0. To test for the upper limit calculate + * (PNG_FP_1-y) - x must be <= to this for z to be >= 0 (and the expression + * cannot overflow.) At this point we know x and y are >= 0 and (x+y) is + * <= PNG_FP_1. The previous test on PNG_MAX_UINT_31 is removed because it + * pointless (and it produces compiler warnings!) + */ + if (white_x < 0 || white_y <= 0 || + red_x < 0 || red_y < 0 || + green_x < 0 || green_y < 0 || + blue_x < 0 || blue_y < 0) + { + png_warning(png_ptr, + "Ignoring attempt to set negative chromaticity value"); + ret = 0; + } + /* And (x+y) must be <= PNG_FP_1 (so z is >= 0) */ + if (white_x > PNG_FP_1 - white_y) + { + png_warning(png_ptr, "Invalid cHRM white point"); + ret = 0; + } + + if (red_x > PNG_FP_1 - red_y) + { + png_warning(png_ptr, "Invalid cHRM red point"); + ret = 0; + } + + if (green_x > PNG_FP_1 - green_y) + { + png_warning(png_ptr, "Invalid cHRM green point"); + ret = 0; + } + + if (blue_x > PNG_FP_1 - blue_y) + { + png_warning(png_ptr, "Invalid cHRM blue point"); + ret = 0; + } + + png_64bit_product(green_x - red_x, blue_y - red_y, &xy_hi, &xy_lo); + png_64bit_product(green_y - red_y, blue_x - red_x, &yx_hi, &yx_lo); + + if (xy_hi == yx_hi && xy_lo == yx_lo) + { + png_warning(png_ptr, + "Ignoring attempt to set cHRM RGB triangle with zero area"); + ret = 0; + } + + return ret; +} +# endif /* PNG_CHECK_cHRM_SUPPORTED */ + +#ifdef PNG_cHRM_SUPPORTED +/* Added at libpng-1.5.5 to support read and write of true CIEXYZ values for + * cHRM, as opposed to using chromaticities. These internal APIs return + * non-zero on a parameter error. The X, Y and Z values are required to be + * positive and less than 1.0. + */ +int png_xy_from_XYZ(png_xy *xy, png_XYZ XYZ) +{ + png_int_32 d, dwhite, whiteX, whiteY; + + d = XYZ.redX + XYZ.redY + XYZ.redZ; + if (!png_muldiv(&xy->redx, XYZ.redX, PNG_FP_1, d)) return 1; + if (!png_muldiv(&xy->redy, XYZ.redY, PNG_FP_1, d)) return 1; + dwhite = d; + whiteX = XYZ.redX; + whiteY = XYZ.redY; + + d = XYZ.greenX + XYZ.greenY + XYZ.greenZ; + if (!png_muldiv(&xy->greenx, XYZ.greenX, PNG_FP_1, d)) return 1; + if (!png_muldiv(&xy->greeny, XYZ.greenY, PNG_FP_1, d)) return 1; + dwhite += d; + whiteX += XYZ.greenX; + whiteY += XYZ.greenY; + + d = XYZ.blueX + XYZ.blueY + XYZ.blueZ; + if (!png_muldiv(&xy->bluex, XYZ.blueX, PNG_FP_1, d)) return 1; + if (!png_muldiv(&xy->bluey, XYZ.blueY, PNG_FP_1, d)) return 1; + dwhite += d; + whiteX += XYZ.blueX; + whiteY += XYZ.blueY; + + /* The reference white is simply the same of the end-point (X,Y,Z) vectors, + * thus: + */ + if (!png_muldiv(&xy->whitex, whiteX, PNG_FP_1, dwhite)) return 1; + if (!png_muldiv(&xy->whitey, whiteY, PNG_FP_1, dwhite)) return 1; + + return 0; +} + +int png_XYZ_from_xy(png_XYZ *XYZ, png_xy xy) +{ + png_fixed_point red_inverse, green_inverse, blue_scale; + png_fixed_point left, right, denominator; + + /* Check xy and, implicitly, z. Note that wide gamut color spaces typically + * have end points with 0 tristimulus values (these are impossible end + * points, but they are used to cover the possible colors.) + */ + if (xy.redx < 0 || xy.redx > PNG_FP_1) return 1; + if (xy.redy < 0 || xy.redy > PNG_FP_1-xy.redx) return 1; + if (xy.greenx < 0 || xy.greenx > PNG_FP_1) return 1; + if (xy.greeny < 0 || xy.greeny > PNG_FP_1-xy.greenx) return 1; + if (xy.bluex < 0 || xy.bluex > PNG_FP_1) return 1; + if (xy.bluey < 0 || xy.bluey > PNG_FP_1-xy.bluex) return 1; + if (xy.whitex < 0 || xy.whitex > PNG_FP_1) return 1; + if (xy.whitey < 0 || xy.whitey > PNG_FP_1-xy.whitex) return 1; + + /* The reverse calculation is more difficult because the original tristimulus + * value had 9 independent values (red,green,blue)x(X,Y,Z) however only 8 + * derived values were recorded in the cHRM chunk; + * (red,green,blue,white)x(x,y). This loses one degree of freedom and + * therefore an arbitrary ninth value has to be introduced to undo the + * original transformations. + * + * Think of the original end-points as points in (X,Y,Z) space. The + * chromaticity values (c) have the property: + * + * C + * c = --------- + * X + Y + Z + * + * For each c (x,y,z) from the corresponding original C (X,Y,Z). Thus the + * three chromaticity values (x,y,z) for each end-point obey the + * relationship: + * + * x + y + z = 1 + * + * This describes the plane in (X,Y,Z) space that intersects each axis at the + * value 1.0; call this the chromaticity plane. Thus the chromaticity + * calculation has scaled each end-point so that it is on the x+y+z=1 plane + * and chromaticity is the intersection of the vector from the origin to the + * (X,Y,Z) value with the chromaticity plane. + * + * To fully invert the chromaticity calculation we would need the three + * end-point scale factors, (red-scale, green-scale, blue-scale), but these + * were not recorded. Instead we calculated the reference white (X,Y,Z) and + * recorded the chromaticity of this. The reference white (X,Y,Z) would have + * given all three of the scale factors since: + * + * color-C = color-c * color-scale + * white-C = red-C + green-C + blue-C + * = red-c*red-scale + green-c*green-scale + blue-c*blue-scale + * + * But cHRM records only white-x and white-y, so we have lost the white scale + * factor: + * + * white-C = white-c*white-scale + * + * To handle this the inverse transformation makes an arbitrary assumption + * about white-scale: + * + * Assume: white-Y = 1.0 + * Hence: white-scale = 1/white-y + * Or: red-Y + green-Y + blue-Y = 1.0 + * + * Notice the last statement of the assumption gives an equation in three of + * the nine values we want to calculate. 8 more equations come from the + * above routine as summarised at the top above (the chromaticity + * calculation): + * + * Given: color-x = color-X / (color-X + color-Y + color-Z) + * Hence: (color-x - 1)*color-X + color.x*color-Y + color.x*color-Z = 0 + * + * This is 9 simultaneous equations in the 9 variables "color-C" and can be + * solved by Cramer's rule. Cramer's rule requires calculating 10 9x9 matrix + * determinants, however this is not as bad as it seems because only 28 of + * the total of 90 terms in the various matrices are non-zero. Nevertheless + * Cramer's rule is notoriously numerically unstable because the determinant + * calculation involves the difference of large, but similar, numbers. It is + * difficult to be sure that the calculation is stable for real world values + * and it is certain that it becomes unstable where the end points are close + * together. + * + * So this code uses the perhaps slightly less optimal but more + * understandable and totally obvious approach of calculating color-scale. + * + * This algorithm depends on the precision in white-scale and that is + * (1/white-y), so we can immediately see that as white-y approaches 0 the + * accuracy inherent in the cHRM chunk drops off substantially. + * + * libpng arithmetic: a simple invertion of the above equations + * ------------------------------------------------------------ + * + * white_scale = 1/white-y + * white-X = white-x * white-scale + * white-Y = 1.0 + * white-Z = (1 - white-x - white-y) * white_scale + * + * white-C = red-C + green-C + blue-C + * = red-c*red-scale + green-c*green-scale + blue-c*blue-scale + * + * This gives us three equations in (red-scale,green-scale,blue-scale) where + * all the coefficients are now known: + * + * red-x*red-scale + green-x*green-scale + blue-x*blue-scale + * = white-x/white-y + * red-y*red-scale + green-y*green-scale + blue-y*blue-scale = 1 + * red-z*red-scale + green-z*green-scale + blue-z*blue-scale + * = (1 - white-x - white-y)/white-y + * + * In the last equation color-z is (1 - color-x - color-y) so we can add all + * three equations together to get an alternative third: + * + * red-scale + green-scale + blue-scale = 1/white-y = white-scale + * + * So now we have a Cramer's rule solution where the determinants are just + * 3x3 - far more tractible. Unfortunately 3x3 determinants still involve + * multiplication of three coefficients so we can't guarantee to avoid + * overflow in the libpng fixed point representation. Using Cramer's rule in + * floating point is probably a good choice here, but it's not an option for + * fixed point. Instead proceed to simplify the first two equations by + * eliminating what is likely to be the largest value, blue-scale: + * + * blue-scale = white-scale - red-scale - green-scale + * + * Hence: + * + * (red-x - blue-x)*red-scale + (green-x - blue-x)*green-scale = + * (white-x - blue-x)*white-scale + * + * (red-y - blue-y)*red-scale + (green-y - blue-y)*green-scale = + * 1 - blue-y*white-scale + * + * And now we can trivially solve for (red-scale,green-scale): + * + * green-scale = + * (white-x - blue-x)*white-scale - (red-x - blue-x)*red-scale + * ----------------------------------------------------------- + * green-x - blue-x + * + * red-scale = + * 1 - blue-y*white-scale - (green-y - blue-y) * green-scale + * --------------------------------------------------------- + * red-y - blue-y + * + * Hence: + * + * red-scale = + * ( (green-x - blue-x) * (white-y - blue-y) - + * (green-y - blue-y) * (white-x - blue-x) ) / white-y + * ------------------------------------------------------------------------- + * (green-x - blue-x)*(red-y - blue-y)-(green-y - blue-y)*(red-x - blue-x) + * + * green-scale = + * ( (red-y - blue-y) * (white-x - blue-x) - + * (red-x - blue-x) * (white-y - blue-y) ) / white-y + * ------------------------------------------------------------------------- + * (green-x - blue-x)*(red-y - blue-y)-(green-y - blue-y)*(red-x - blue-x) + * + * Accuracy: + * The input values have 5 decimal digits of accuracy. The values are all in + * the range 0 < value < 1, so simple products are in the same range but may + * need up to 10 decimal digits to preserve the original precision and avoid + * underflow. Because we are using a 32-bit signed representation we cannot + * match this; the best is a little over 9 decimal digits, less than 10. + * + * The approach used here is to preserve the maximum precision within the + * signed representation. Because the red-scale calculation above uses the + * difference between two products of values that must be in the range -1..+1 + * it is sufficient to divide the product by 7; ceil(100,000/32767*2). The + * factor is irrelevant in the calculation because it is applied to both + * numerator and denominator. + * + * Note that the values of the differences of the products of the + * chromaticities in the above equations tend to be small, for example for + * the sRGB chromaticities they are: + * + * red numerator: -0.04751 + * green numerator: -0.08788 + * denominator: -0.2241 (without white-y multiplication) + * + * The resultant Y coefficients from the chromaticities of some widely used + * color space definitions are (to 15 decimal places): + * + * sRGB + * 0.212639005871510 0.715168678767756 0.072192315360734 + * Kodak ProPhoto + * 0.288071128229293 0.711843217810102 0.000085653960605 + * Adobe RGB + * 0.297344975250536 0.627363566255466 0.075291458493998 + * Adobe Wide Gamut RGB + * 0.258728243040113 0.724682314948566 0.016589442011321 + */ + /* By the argument, above overflow should be impossible here. The return + * value of 2 indicates an internal error to the caller. + */ + if (!png_muldiv(&left, xy.greenx-xy.bluex, xy.redy - xy.bluey, 7)) return 2; + if (!png_muldiv(&right, xy.greeny-xy.bluey, xy.redx - xy.bluex, 7)) return 2; + denominator = left - right; + + /* Now find the red numerator. */ + if (!png_muldiv(&left, xy.greenx-xy.bluex, xy.whitey-xy.bluey, 7)) return 2; + if (!png_muldiv(&right, xy.greeny-xy.bluey, xy.whitex-xy.bluex, 7)) return 2; + + /* Overflow is possible here and it indicates an extreme set of PNG cHRM + * chunk values. This calculation actually returns the reciprocal of the + * scale value because this allows us to delay the multiplication of white-y + * into the denominator, which tends to produce a small number. + */ + if (!png_muldiv(&red_inverse, xy.whitey, denominator, left-right) || + red_inverse <= xy.whitey /* r+g+b scales = white scale */) + return 1; + + /* Similarly for green_inverse: */ + if (!png_muldiv(&left, xy.redy-xy.bluey, xy.whitex-xy.bluex, 7)) return 2; + if (!png_muldiv(&right, xy.redx-xy.bluex, xy.whitey-xy.bluey, 7)) return 2; + if (!png_muldiv(&green_inverse, xy.whitey, denominator, left-right) || + green_inverse <= xy.whitey) + return 1; + + /* And the blue scale, the checks above guarantee this can't overflow but it + * can still produce 0 for extreme cHRM values. + */ + blue_scale = png_reciprocal(xy.whitey) - png_reciprocal(red_inverse) - + png_reciprocal(green_inverse); + if (blue_scale <= 0) return 1; + + + /* And fill in the png_XYZ: */ + if (!png_muldiv(&XYZ->redX, xy.redx, PNG_FP_1, red_inverse)) return 1; + if (!png_muldiv(&XYZ->redY, xy.redy, PNG_FP_1, red_inverse)) return 1; + if (!png_muldiv(&XYZ->redZ, PNG_FP_1 - xy.redx - xy.redy, PNG_FP_1, + red_inverse)) + return 1; + + if (!png_muldiv(&XYZ->greenX, xy.greenx, PNG_FP_1, green_inverse)) return 1; + if (!png_muldiv(&XYZ->greenY, xy.greeny, PNG_FP_1, green_inverse)) return 1; + if (!png_muldiv(&XYZ->greenZ, PNG_FP_1 - xy.greenx - xy.greeny, PNG_FP_1, + green_inverse)) + return 1; + + if (!png_muldiv(&XYZ->blueX, xy.bluex, blue_scale, PNG_FP_1)) return 1; + if (!png_muldiv(&XYZ->blueY, xy.bluey, blue_scale, PNG_FP_1)) return 1; + if (!png_muldiv(&XYZ->blueZ, PNG_FP_1 - xy.bluex - xy.bluey, blue_scale, + PNG_FP_1)) + return 1; + + return 0; /*success*/ +} + +int png_XYZ_from_xy_checked(png_structp png_ptr, png_XYZ *XYZ, png_xy xy) +{ + switch (png_XYZ_from_xy(XYZ, xy)) + { + case 0: /* success */ + return 1; + + case 1: + /* The chunk may be technically valid, but we got png_fixed_point + * overflow while trying to get XYZ values out of it. This is + * entirely benign - the cHRM chunk is pretty extreme. + */ + png_warning(png_ptr, + "extreme cHRM chunk cannot be converted to tristimulus values"); + break; + + default: + /* libpng is broken; this should be a warning but if it happens we + * want error reports so for the moment it is an error. + */ + png_error(png_ptr, "internal error in png_XYZ_from_xy"); + break; + } + + /* ERROR RETURN */ + return 0; +} +#endif + +void /* PRIVATE */ +png_check_IHDR(png_structp png_ptr, + png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_type, int compression_type, + int filter_type) +{ + int error = 0; + + /* Check for width and height valid values */ + if (width == 0) + { + png_warning(png_ptr, "Image width is zero in IHDR"); + error = 1; + } + + if (height == 0) + { + png_warning(png_ptr, "Image height is zero in IHDR"); + error = 1; + } + +# ifdef PNG_SET_USER_LIMITS_SUPPORTED + if (width > png_ptr->user_width_max) + +# else + if (width > PNG_USER_WIDTH_MAX) +# endif + { + png_warning(png_ptr, "Image width exceeds user limit in IHDR"); + error = 1; + } + +# ifdef PNG_SET_USER_LIMITS_SUPPORTED + if (height > png_ptr->user_height_max) +# else + if (height > PNG_USER_HEIGHT_MAX) +# endif + { + png_warning(png_ptr, "Image height exceeds user limit in IHDR"); + error = 1; + } + + if (width > PNG_UINT_31_MAX) + { + png_warning(png_ptr, "Invalid image width in IHDR"); + error = 1; + } + + if (height > PNG_UINT_31_MAX) + { + png_warning(png_ptr, "Invalid image height in IHDR"); + error = 1; + } + + if (width > (PNG_UINT_32_MAX + >> 3) /* 8-byte RGBA pixels */ + - 48 /* bigrowbuf hack */ + - 1 /* filter byte */ + - 7*8 /* rounding of width to multiple of 8 pixels */ + - 8) /* extra max_pixel_depth pad */ + png_warning(png_ptr, "Width is too large for libpng to process pixels"); + + /* Check other values */ + if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && + bit_depth != 8 && bit_depth != 16) + { + png_warning(png_ptr, "Invalid bit depth in IHDR"); + error = 1; + } + + if (color_type < 0 || color_type == 1 || + color_type == 5 || color_type > 6) + { + png_warning(png_ptr, "Invalid color type in IHDR"); + error = 1; + } + + if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || + ((color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) + { + png_warning(png_ptr, "Invalid color type/bit depth combination in IHDR"); + error = 1; + } + + if (interlace_type >= PNG_INTERLACE_LAST) + { + png_warning(png_ptr, "Unknown interlace method in IHDR"); + error = 1; + } + + if (compression_type != PNG_COMPRESSION_TYPE_BASE) + { + png_warning(png_ptr, "Unknown compression method in IHDR"); + error = 1; + } + +# ifdef PNG_MNG_FEATURES_SUPPORTED + /* Accept filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not read a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ + if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) && + png_ptr->mng_features_permitted) + png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); + + if (filter_type != PNG_FILTER_TYPE_BASE) + { + if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && + ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) && + (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA))) + { + png_warning(png_ptr, "Unknown filter method in IHDR"); + error = 1; + } + + if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) + { + png_warning(png_ptr, "Invalid filter method in IHDR"); + error = 1; + } + } + +# else + if (filter_type != PNG_FILTER_TYPE_BASE) + { + png_warning(png_ptr, "Unknown filter method in IHDR"); + error = 1; + } +# endif + + if (error == 1) + png_error(png_ptr, "Invalid IHDR data"); +} + +#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) +/* ASCII to fp functions */ +/* Check an ASCII formated floating point value, see the more detailed + * comments in pngpriv.h + */ +/* The following is used internally to preserve the sticky flags */ +#define png_fp_add(state, flags) ((state) |= (flags)) +#define png_fp_set(state, value) ((state) = (value) | ((state) & PNG_FP_STICKY)) + +int /* PRIVATE */ +png_check_fp_number(png_const_charp string, png_size_t size, int *statep, + png_size_tp whereami) +{ + int state = *statep; + png_size_t i = *whereami; + + while (i < size) + { + int type; + /* First find the type of the next character */ + switch (string[i]) + { + case 43: type = PNG_FP_SAW_SIGN; break; + case 45: type = PNG_FP_SAW_SIGN + PNG_FP_NEGATIVE; break; + case 46: type = PNG_FP_SAW_DOT; break; + case 48: type = PNG_FP_SAW_DIGIT; break; + case 49: case 50: case 51: case 52: + case 53: case 54: case 55: case 56: + case 57: type = PNG_FP_SAW_DIGIT + PNG_FP_NONZERO; break; + case 69: + case 101: type = PNG_FP_SAW_E; break; + default: goto PNG_FP_End; + } + + /* Now deal with this type according to the current + * state, the type is arranged to not overlap the + * bits of the PNG_FP_STATE. + */ + switch ((state & PNG_FP_STATE) + (type & PNG_FP_SAW_ANY)) + { + case PNG_FP_INTEGER + PNG_FP_SAW_SIGN: + if (state & PNG_FP_SAW_ANY) + goto PNG_FP_End; /* not a part of the number */ + + png_fp_add(state, type); + break; + + case PNG_FP_INTEGER + PNG_FP_SAW_DOT: + /* Ok as trailer, ok as lead of fraction. */ + if (state & PNG_FP_SAW_DOT) /* two dots */ + goto PNG_FP_End; + + else if (state & PNG_FP_SAW_DIGIT) /* trailing dot? */ + png_fp_add(state, type); + + else + png_fp_set(state, PNG_FP_FRACTION | type); + + break; + + case PNG_FP_INTEGER + PNG_FP_SAW_DIGIT: + if (state & PNG_FP_SAW_DOT) /* delayed fraction */ + png_fp_set(state, PNG_FP_FRACTION | PNG_FP_SAW_DOT); + + png_fp_add(state, type | PNG_FP_WAS_VALID); + + break; + + case PNG_FP_INTEGER + PNG_FP_SAW_E: + if ((state & PNG_FP_SAW_DIGIT) == 0) + goto PNG_FP_End; + + png_fp_set(state, PNG_FP_EXPONENT); + + break; + + /* case PNG_FP_FRACTION + PNG_FP_SAW_SIGN: + goto PNG_FP_End; ** no sign in fraction */ + + /* case PNG_FP_FRACTION + PNG_FP_SAW_DOT: + goto PNG_FP_End; ** Because SAW_DOT is always set */ + + case PNG_FP_FRACTION + PNG_FP_SAW_DIGIT: + png_fp_add(state, type | PNG_FP_WAS_VALID); + break; + + case PNG_FP_FRACTION + PNG_FP_SAW_E: + /* This is correct because the trailing '.' on an + * integer is handled above - so we can only get here + * with the sequence ".E" (with no preceding digits). + */ + if ((state & PNG_FP_SAW_DIGIT) == 0) + goto PNG_FP_End; + + png_fp_set(state, PNG_FP_EXPONENT); + + break; + + case PNG_FP_EXPONENT + PNG_FP_SAW_SIGN: + if (state & PNG_FP_SAW_ANY) + goto PNG_FP_End; /* not a part of the number */ + + png_fp_add(state, PNG_FP_SAW_SIGN); + + break; + + /* case PNG_FP_EXPONENT + PNG_FP_SAW_DOT: + goto PNG_FP_End; */ + + case PNG_FP_EXPONENT + PNG_FP_SAW_DIGIT: + png_fp_add(state, PNG_FP_SAW_DIGIT | PNG_FP_WAS_VALID); + + break; + + /* case PNG_FP_EXPONEXT + PNG_FP_SAW_E: + goto PNG_FP_End; */ + + default: goto PNG_FP_End; /* I.e. break 2 */ + } + + /* The character seems ok, continue. */ + ++i; + } + +PNG_FP_End: + /* Here at the end, update the state and return the correct + * return code. + */ + *statep = state; + *whereami = i; + + return (state & PNG_FP_SAW_DIGIT) != 0; +} + + +/* The same but for a complete string. */ +int +png_check_fp_string(png_const_charp string, png_size_t size) +{ + int state=0; + png_size_t char_index=0; + + if (png_check_fp_number(string, size, &state, &char_index) && + (char_index == size || string[char_index] == 0)) + return state /* must be non-zero - see above */; + + return 0; /* i.e. fail */ +} +#endif /* pCAL or sCAL */ + +#ifdef PNG_READ_sCAL_SUPPORTED +# ifdef PNG_FLOATING_POINT_SUPPORTED +/* Utility used below - a simple accurate power of ten from an integral + * exponent. + */ +static double +png_pow10(int power) +{ + int recip = 0; + double d = 1.0; + + /* Handle negative exponent with a reciprocal at the end because + * 10 is exact whereas .1 is inexact in base 2 + */ + if (power < 0) + { + if (power < DBL_MIN_10_EXP) return 0; + recip = 1, power = -power; + } + + if (power > 0) + { + /* Decompose power bitwise. */ + double mult = 10.0; + do + { + if (power & 1) d *= mult; + mult *= mult; + power >>= 1; + } + while (power > 0); + + if (recip) d = 1/d; + } + /* else power is 0 and d is 1 */ + + return d; +} + +/* Function to format a floating point value in ASCII with a given + * precision. + */ +void /* PRIVATE */ +png_ascii_from_fp(png_structp png_ptr, png_charp ascii, png_size_t size, + double fp, unsigned int precision) +{ + /* We use standard functions from math.h, but not printf because + * that would require stdio. The caller must supply a buffer of + * sufficient size or we will png_error. The tests on size and + * the space in ascii[] consumed are indicated below. + */ + if (precision < 1) + precision = DBL_DIG; + + /* Enforce the limit of the implementation precision too. */ + if (precision > DBL_DIG+1) + precision = DBL_DIG+1; + + /* Basic sanity checks */ + if (size >= precision+5) /* See the requirements below. */ + { + if (fp < 0) + { + fp = -fp; + *ascii++ = 45; /* '-' PLUS 1 TOTAL 1 */ + --size; + } + + if (fp >= DBL_MIN && fp <= DBL_MAX) + { + int exp_b10; /* A base 10 exponent */ + double base; /* 10^exp_b10 */ + + /* First extract a base 10 exponent of the number, + * the calculation below rounds down when converting + * from base 2 to base 10 (multiply by log10(2) - + * 0.3010, but 77/256 is 0.3008, so exp_b10 needs to + * be increased. Note that the arithmetic shift + * performs a floor() unlike C arithmetic - using a + * C multiply would break the following for negative + * exponents. + */ + (void)frexp(fp, &exp_b10); /* exponent to base 2 */ + + exp_b10 = (exp_b10 * 77) >> 8; /* <= exponent to base 10 */ + + /* Avoid underflow here. */ + base = png_pow10(exp_b10); /* May underflow */ + + while (base < DBL_MIN || base < fp) + { + /* And this may overflow. */ + double test = png_pow10(exp_b10+1); + + if (test <= DBL_MAX) + ++exp_b10, base = test; + + else + break; + } + + /* Normalize fp and correct exp_b10, after this fp is in the + * range [.1,1) and exp_b10 is both the exponent and the digit + * *before* which the decimal point should be inserted + * (starting with 0 for the first digit). Note that this + * works even if 10^exp_b10 is out of range because of the + * test on DBL_MAX above. + */ + fp /= base; + while (fp >= 1) fp /= 10, ++exp_b10; + + /* Because of the code above fp may, at this point, be + * less than .1, this is ok because the code below can + * handle the leading zeros this generates, so no attempt + * is made to correct that here. + */ + + { + int czero, clead, cdigits; + char exponent[10]; + + /* Allow up to two leading zeros - this will not lengthen + * the number compared to using E-n. + */ + if (exp_b10 < 0 && exp_b10 > -3) /* PLUS 3 TOTAL 4 */ + { + czero = -exp_b10; /* PLUS 2 digits: TOTAL 3 */ + exp_b10 = 0; /* Dot added below before first output. */ + } + else + czero = 0; /* No zeros to add */ + + /* Generate the digit list, stripping trailing zeros and + * inserting a '.' before a digit if the exponent is 0. + */ + clead = czero; /* Count of leading zeros */ + cdigits = 0; /* Count of digits in list. */ + + do + { + double d; + + fp *= 10.0; + + /* Use modf here, not floor and subtract, so that + * the separation is done in one step. At the end + * of the loop don't break the number into parts so + * that the final digit is rounded. + */ + if (cdigits+czero-clead+1 < (int)precision) + fp = modf(fp, &d); + + else + { + d = floor(fp + .5); + + if (d > 9.0) + { + /* Rounding up to 10, handle that here. */ + if (czero > 0) + { + --czero, d = 1; + if (cdigits == 0) --clead; + } + + else + { + while (cdigits > 0 && d > 9.0) + { + int ch = *--ascii; + + if (exp_b10 != (-1)) + ++exp_b10; + + else if (ch == 46) + { + ch = *--ascii, ++size; + /* Advance exp_b10 to '1', so that the + * decimal point happens after the + * previous digit. + */ + exp_b10 = 1; + } + + --cdigits; + d = ch - 47; /* I.e. 1+(ch-48) */ + } + + /* Did we reach the beginning? If so adjust the + * exponent but take into account the leading + * decimal point. + */ + if (d > 9.0) /* cdigits == 0 */ + { + if (exp_b10 == (-1)) + { + /* Leading decimal point (plus zeros?), if + * we lose the decimal point here it must + * be reentered below. + */ + int ch = *--ascii; + + if (ch == 46) + ++size, exp_b10 = 1; + + /* Else lost a leading zero, so 'exp_b10' is + * still ok at (-1) + */ + } + else + ++exp_b10; + + /* In all cases we output a '1' */ + d = 1.0; + } + } + } + fp = 0; /* Guarantees termination below. */ + } + + if (d == 0.0) + { + ++czero; + if (cdigits == 0) ++clead; + } + + else + { + /* Included embedded zeros in the digit count. */ + cdigits += czero - clead; + clead = 0; + + while (czero > 0) + { + /* exp_b10 == (-1) means we just output the decimal + * place - after the DP don't adjust 'exp_b10' any + * more! + */ + if (exp_b10 != (-1)) + { + if (exp_b10 == 0) *ascii++ = 46, --size; + /* PLUS 1: TOTAL 4 */ + --exp_b10; + } + *ascii++ = 48, --czero; + } + + if (exp_b10 != (-1)) + { + if (exp_b10 == 0) *ascii++ = 46, --size; /* counted + above */ + --exp_b10; + } + + *ascii++ = (char)(48 + (int)d), ++cdigits; + } + } + while (cdigits+czero-clead < (int)precision && fp > DBL_MIN); + + /* The total output count (max) is now 4+precision */ + + /* Check for an exponent, if we don't need one we are + * done and just need to terminate the string. At + * this point exp_b10==(-1) is effectively if flag - it got + * to '-1' because of the decrement after outputing + * the decimal point above (the exponent required is + * *not* -1!) + */ + if (exp_b10 >= (-1) && exp_b10 <= 2) + { + /* The following only happens if we didn't output the + * leading zeros above for negative exponent, so this + * doest add to the digit requirement. Note that the + * two zeros here can only be output if the two leading + * zeros were *not* output, so this doesn't increase + * the output count. + */ + while (--exp_b10 >= 0) *ascii++ = 48; + + *ascii = 0; + + /* Total buffer requirement (including the '\0') is + * 5+precision - see check at the start. + */ + return; + } + + /* Here if an exponent is required, adjust size for + * the digits we output but did not count. The total + * digit output here so far is at most 1+precision - no + * decimal point and no leading or trailing zeros have + * been output. + */ + size -= cdigits; + + *ascii++ = 69, --size; /* 'E': PLUS 1 TOTAL 2+precision */ + + /* The following use of an unsigned temporary avoids ambiguities in + * the signed arithmetic on exp_b10 and permits GCC at least to do + * better optimization. + */ + { + unsigned int uexp_b10; + + if (exp_b10 < 0) + { + *ascii++ = 45, --size; /* '-': PLUS 1 TOTAL 3+precision */ + uexp_b10 = -exp_b10; + } + + else + uexp_b10 = exp_b10; + + cdigits = 0; + + while (uexp_b10 > 0) + { + exponent[cdigits++] = (char)(48 + uexp_b10 % 10); + uexp_b10 /= 10; + } + } + + /* Need another size check here for the exponent digits, so + * this need not be considered above. + */ + if ((int)size > cdigits) + { + while (cdigits > 0) *ascii++ = exponent[--cdigits]; + + *ascii = 0; + + return; + } + } + } + else if (!(fp >= DBL_MIN)) + { + *ascii++ = 48; /* '0' */ + *ascii = 0; + return; + } + else + { + *ascii++ = 105; /* 'i' */ + *ascii++ = 110; /* 'n' */ + *ascii++ = 102; /* 'f' */ + *ascii = 0; + return; + } + } + + /* Here on buffer too small. */ + png_error(png_ptr, "ASCII conversion buffer too small"); +} + +# endif /* FLOATING_POINT */ + +# ifdef PNG_FIXED_POINT_SUPPORTED +/* Function to format a fixed point value in ASCII. + */ +void /* PRIVATE */ +png_ascii_from_fixed(png_structp png_ptr, png_charp ascii, png_size_t size, + png_fixed_point fp) +{ + /* Require space for 10 decimal digits, a decimal point, a minus sign and a + * trailing \0, 13 characters: + */ + if (size > 12) + { + png_uint_32 num; + + /* Avoid overflow here on the minimum integer. */ + if (fp < 0) + *ascii++ = 45, --size, num = -fp; + else + num = fp; + + if (num <= 0x80000000) /* else overflowed */ + { + unsigned int ndigits = 0, first = 16 /* flag value */; + char digits[10]; + + while (num) + { + /* Split the low digit off num: */ + unsigned int tmp = num/10; + num -= tmp*10; + digits[ndigits++] = (char)(48 + num); + /* Record the first non-zero digit, note that this is a number + * starting at 1, it's not actually the array index. + */ + if (first == 16 && num > 0) + first = ndigits; + num = tmp; + } + + if (ndigits > 0) + { + while (ndigits > 5) *ascii++ = digits[--ndigits]; + /* The remaining digits are fractional digits, ndigits is '5' or + * smaller at this point. It is certainly not zero. Check for a + * non-zero fractional digit: + */ + if (first <= 5) + { + unsigned int i; + *ascii++ = 46; /* decimal point */ + /* ndigits may be <5 for small numbers, output leading zeros + * then ndigits digits to first: + */ + i = 5; + while (ndigits < i) *ascii++ = 48, --i; + while (ndigits >= first) *ascii++ = digits[--ndigits]; + /* Don't output the trailing zeros! */ + } + } + else + *ascii++ = 48; + + /* And null terminate the string: */ + *ascii = 0; + return; + } + } + + /* Here on buffer too small. */ + png_error(png_ptr, "ASCII conversion buffer too small"); +} +# endif /* FIXED_POINT */ +#endif /* READ_SCAL */ + +#if defined(PNG_FLOATING_POINT_SUPPORTED) && \ + !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) +png_fixed_point +png_fixed(png_structp png_ptr, double fp, png_const_charp text) +{ + double r = floor(100000 * fp + .5); + + if (r > 2147483647. || r < -2147483648.) + png_fixed_error(png_ptr, text); + + return (png_fixed_point)r; +} +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) || \ + defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG__READ_pHYs_SUPPORTED) +/* muldiv functions */ +/* This API takes signed arguments and rounds the result to the nearest + * integer (or, for a fixed point number - the standard argument - to + * the nearest .00001). Overflow and divide by zero are signalled in + * the result, a boolean - true on success, false on overflow. + */ +int +png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times, + png_int_32 divisor) +{ + /* Return a * times / divisor, rounded. */ + if (divisor != 0) + { + if (a == 0 || times == 0) + { + *res = 0; + return 1; + } + else + { +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + double r = a; + r *= times; + r /= divisor; + r = floor(r+.5); + + /* A png_fixed_point is a 32-bit integer. */ + if (r <= 2147483647. && r >= -2147483648.) + { + *res = (png_fixed_point)r; + return 1; + } +#else + int negative = 0; + png_uint_32 A, T, D; + png_uint_32 s16, s32, s00; + + if (a < 0) + negative = 1, A = -a; + else + A = a; + + if (times < 0) + negative = !negative, T = -times; + else + T = times; + + if (divisor < 0) + negative = !negative, D = -divisor; + else + D = divisor; + + /* Following can't overflow because the arguments only + * have 31 bits each, however the result may be 32 bits. + */ + s16 = (A >> 16) * (T & 0xffff) + + (A & 0xffff) * (T >> 16); + /* Can't overflow because the a*times bit is only 30 + * bits at most. + */ + s32 = (A >> 16) * (T >> 16) + (s16 >> 16); + s00 = (A & 0xffff) * (T & 0xffff); + + s16 = (s16 & 0xffff) << 16; + s00 += s16; + + if (s00 < s16) + ++s32; /* carry */ + + if (s32 < D) /* else overflow */ + { + /* s32.s00 is now the 64-bit product, do a standard + * division, we know that s32 < D, so the maximum + * required shift is 31. + */ + int bitshift = 32; + png_fixed_point result = 0; /* NOTE: signed */ + + while (--bitshift >= 0) + { + png_uint_32 d32, d00; + + if (bitshift > 0) + d32 = D >> (32-bitshift), d00 = D << bitshift; + + else + d32 = 0, d00 = D; + + if (s32 > d32) + { + if (s00 < d00) --s32; /* carry */ + s32 -= d32, s00 -= d00, result += 1<= d00) + s32 = 0, s00 -= d00, result += 1<= (D >> 1)) + ++result; + + if (negative) + result = -result; + + /* Check for overflow. */ + if ((negative && result <= 0) || (!negative && result >= 0)) + { + *res = result; + return 1; + } + } +#endif + } + } + + return 0; +} +#endif /* READ_GAMMA || INCH_CONVERSIONS */ + +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED) +/* The following is for when the caller doesn't much care about the + * result. + */ +png_fixed_point +png_muldiv_warn(png_structp png_ptr, png_fixed_point a, png_int_32 times, + png_int_32 divisor) +{ + png_fixed_point result; + + if (png_muldiv(&result, a, times, divisor)) + return result; + + png_warning(png_ptr, "fixed point overflow ignored"); + return 0; +} +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED /* more fixed point functions for gamma */ +/* Calculate a reciprocal, return 0 on div-by-zero or overflow. */ +png_fixed_point +png_reciprocal(png_fixed_point a) +{ +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + double r = floor(1E10/a+.5); + + if (r <= 2147483647. && r >= -2147483648.) + return (png_fixed_point)r; +#else + png_fixed_point res; + + if (png_muldiv(&res, 100000, 100000, a)) + return res; +#endif + + return 0; /* error/overflow */ +} + +/* A local convenience routine. */ +static png_fixed_point +png_product2(png_fixed_point a, png_fixed_point b) +{ + /* The required result is 1/a * 1/b; the following preserves accuracy. */ +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + double r = a * 1E-5; + r *= b; + r = floor(r+.5); + + if (r <= 2147483647. && r >= -2147483648.) + return (png_fixed_point)r; +#else + png_fixed_point res; + + if (png_muldiv(&res, a, b, 100000)) + return res; +#endif + + return 0; /* overflow */ +} + +/* The inverse of the above. */ +png_fixed_point +png_reciprocal2(png_fixed_point a, png_fixed_point b) +{ + /* The required result is 1/a * 1/b; the following preserves accuracy. */ +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + double r = 1E15/a; + r /= b; + r = floor(r+.5); + + if (r <= 2147483647. && r >= -2147483648.) + return (png_fixed_point)r; +#else + /* This may overflow because the range of png_fixed_point isn't symmetric, + * but this API is only used for the product of file and screen gamma so it + * doesn't matter that the smallest number it can produce is 1/21474, not + * 1/100000 + */ + png_fixed_point res = png_product2(a, b); + + if (res != 0) + return png_reciprocal(res); +#endif + + return 0; /* overflow */ +} +#endif /* READ_GAMMA */ + +#ifdef PNG_CHECK_cHRM_SUPPORTED +/* Added at libpng version 1.2.34 (Dec 8, 2008) and 1.4.0 (Jan 2, + * 2010: moved from pngset.c) */ +/* + * Multiply two 32-bit numbers, V1 and V2, using 32-bit + * arithmetic, to produce a 64-bit result in the HI/LO words. + * + * A B + * x C D + * ------ + * AD || BD + * AC || CB || 0 + * + * where A and B are the high and low 16-bit words of V1, + * C and D are the 16-bit words of V2, AD is the product of + * A and D, and X || Y is (X << 16) + Y. +*/ + +void /* PRIVATE */ +png_64bit_product (long v1, long v2, unsigned long *hi_product, + unsigned long *lo_product) +{ + int a, b, c, d; + long lo, hi, x, y; + + a = (v1 >> 16) & 0xffff; + b = v1 & 0xffff; + c = (v2 >> 16) & 0xffff; + d = v2 & 0xffff; + + lo = b * d; /* BD */ + x = a * d + c * b; /* AD + CB */ + y = ((lo >> 16) & 0xffff) + x; + + lo = (lo & 0xffff) | ((y & 0xffff) << 16); + hi = (y >> 16) & 0xffff; + + hi += a * c; /* AC */ + + *hi_product = (unsigned long)hi; + *lo_product = (unsigned long)lo; +} +#endif /* CHECK_cHRM */ + +#ifdef PNG_READ_GAMMA_SUPPORTED /* gamma table code */ +#ifndef PNG_FLOATING_ARITHMETIC_SUPPORTED +/* Fixed point gamma. + * + * To calculate gamma this code implements fast log() and exp() calls using only + * fixed point arithmetic. This code has sufficient precision for either 8-bit + * or 16-bit sample values. + * + * The tables used here were calculated using simple 'bc' programs, but C double + * precision floating point arithmetic would work fine. The programs are given + * at the head of each table. + * + * 8-bit log table + * This is a table of -log(value/255)/log(2) for 'value' in the range 128 to + * 255, so it's the base 2 logarithm of a normalized 8-bit floating point + * mantissa. The numbers are 32-bit fractions. + */ +static png_uint_32 +png_8bit_l2[128] = +{ +# ifdef PNG_DO_BC + for (i=128;i<256;++i) { .5 - l(i/255)/l(2)*65536*65536; } +# else + 4270715492U, 4222494797U, 4174646467U, 4127164793U, 4080044201U, 4033279239U, + 3986864580U, 3940795015U, 3895065449U, 3849670902U, 3804606499U, 3759867474U, + 3715449162U, 3671346997U, 3627556511U, 3584073329U, 3540893168U, 3498011834U, + 3455425220U, 3413129301U, 3371120137U, 3329393864U, 3287946700U, 3246774933U, + 3205874930U, 3165243125U, 3124876025U, 3084770202U, 3044922296U, 3005329011U, + 2965987113U, 2926893432U, 2888044853U, 2849438323U, 2811070844U, 2772939474U, + 2735041326U, 2697373562U, 2659933400U, 2622718104U, 2585724991U, 2548951424U, + 2512394810U, 2476052606U, 2439922311U, 2404001468U, 2368287663U, 2332778523U, + 2297471715U, 2262364947U, 2227455964U, 2192742551U, 2158222529U, 2123893754U, + 2089754119U, 2055801552U, 2022034013U, 1988449497U, 1955046031U, 1921821672U, + 1888774511U, 1855902668U, 1823204291U, 1790677560U, 1758320682U, 1726131893U, + 1694109454U, 1662251657U, 1630556815U, 1599023271U, 1567649391U, 1536433567U, + 1505374214U, 1474469770U, 1443718700U, 1413119487U, 1382670639U, 1352370686U, + 1322218179U, 1292211689U, 1262349810U, 1232631153U, 1203054352U, 1173618059U, + 1144320946U, 1115161701U, 1086139034U, 1057251672U, 1028498358U, 999877854U, + 971388940U, 943030410U, 914801076U, 886699767U, 858725327U, 830876614U, + 803152505U, 775551890U, 748073672U, 720716771U, 693480120U, 666362667U, + 639363374U, 612481215U, 585715177U, 559064263U, 532527486U, 506103872U, + 479792461U, 453592303U, 427502463U, 401522014U, 375650043U, 349885648U, + 324227938U, 298676034U, 273229066U, 247886176U, 222646516U, 197509248U, + 172473545U, 147538590U, 122703574U, 97967701U, 73330182U, 48790236U, + 24347096U, 0U +# endif + +#if 0 + /* The following are the values for 16-bit tables - these work fine for the + * 8-bit conversions but produce very slightly larger errors in the 16-bit + * log (about 1.2 as opposed to 0.7 absolute error in the final value). To + * use these all the shifts below must be adjusted appropriately. + */ + 65166, 64430, 63700, 62976, 62257, 61543, 60835, 60132, 59434, 58741, 58054, + 57371, 56693, 56020, 55352, 54689, 54030, 53375, 52726, 52080, 51439, 50803, + 50170, 49542, 48918, 48298, 47682, 47070, 46462, 45858, 45257, 44661, 44068, + 43479, 42894, 42312, 41733, 41159, 40587, 40020, 39455, 38894, 38336, 37782, + 37230, 36682, 36137, 35595, 35057, 34521, 33988, 33459, 32932, 32408, 31887, + 31369, 30854, 30341, 29832, 29325, 28820, 28319, 27820, 27324, 26830, 26339, + 25850, 25364, 24880, 24399, 23920, 23444, 22970, 22499, 22029, 21562, 21098, + 20636, 20175, 19718, 19262, 18808, 18357, 17908, 17461, 17016, 16573, 16132, + 15694, 15257, 14822, 14390, 13959, 13530, 13103, 12678, 12255, 11834, 11415, + 10997, 10582, 10168, 9756, 9346, 8937, 8531, 8126, 7723, 7321, 6921, 6523, + 6127, 5732, 5339, 4947, 4557, 4169, 3782, 3397, 3014, 2632, 2251, 1872, 1495, + 1119, 744, 372 +#endif +}; + +PNG_STATIC png_int_32 +png_log8bit(unsigned int x) +{ + unsigned int lg2 = 0; + /* Each time 'x' is multiplied by 2, 1 must be subtracted off the final log, + * because the log is actually negate that means adding 1. The final + * returned value thus has the range 0 (for 255 input) to 7.994 (for 1 + * input), return 7.99998 for the overflow (log 0) case - so the result is + * always at most 19 bits. + */ + if ((x &= 0xff) == 0) + return 0xffffffff; + + if ((x & 0xf0) == 0) + lg2 = 4, x <<= 4; + + if ((x & 0xc0) == 0) + lg2 += 2, x <<= 2; + + if ((x & 0x80) == 0) + lg2 += 1, x <<= 1; + + /* result is at most 19 bits, so this cast is safe: */ + return (png_int_32)((lg2 << 16) + ((png_8bit_l2[x-128]+32768)>>16)); +} + +/* The above gives exact (to 16 binary places) log2 values for 8-bit images, + * for 16-bit images we use the most significant 8 bits of the 16-bit value to + * get an approximation then multiply the approximation by a correction factor + * determined by the remaining up to 8 bits. This requires an additional step + * in the 16-bit case. + * + * We want log2(value/65535), we have log2(v'/255), where: + * + * value = v' * 256 + v'' + * = v' * f + * + * So f is value/v', which is equal to (256+v''/v') since v' is in the range 128 + * to 255 and v'' is in the range 0 to 255 f will be in the range 256 to less + * than 258. The final factor also needs to correct for the fact that our 8-bit + * value is scaled by 255, whereas the 16-bit values must be scaled by 65535. + * + * This gives a final formula using a calculated value 'x' which is value/v' and + * scaling by 65536 to match the above table: + * + * log2(x/257) * 65536 + * + * Since these numbers are so close to '1' we can use simple linear + * interpolation between the two end values 256/257 (result -368.61) and 258/257 + * (result 367.179). The values used below are scaled by a further 64 to give + * 16-bit precision in the interpolation: + * + * Start (256): -23591 + * Zero (257): 0 + * End (258): 23499 + */ +PNG_STATIC png_int_32 +png_log16bit(png_uint_32 x) +{ + unsigned int lg2 = 0; + + /* As above, but now the input has 16 bits. */ + if ((x &= 0xffff) == 0) + return 0xffffffff; + + if ((x & 0xff00) == 0) + lg2 = 8, x <<= 8; + + if ((x & 0xf000) == 0) + lg2 += 4, x <<= 4; + + if ((x & 0xc000) == 0) + lg2 += 2, x <<= 2; + + if ((x & 0x8000) == 0) + lg2 += 1, x <<= 1; + + /* Calculate the base logarithm from the top 8 bits as a 28-bit fractional + * value. + */ + lg2 <<= 28; + lg2 += (png_8bit_l2[(x>>8)-128]+8) >> 4; + + /* Now we need to interpolate the factor, this requires a division by the top + * 8 bits. Do this with maximum precision. + */ + x = ((x << 16) + (x >> 9)) / (x >> 8); + + /* Since we divided by the top 8 bits of 'x' there will be a '1' at 1<<24, + * the value at 1<<16 (ignoring this) will be 0 or 1; this gives us exactly + * 16 bits to interpolate to get the low bits of the result. Round the + * answer. Note that the end point values are scaled by 64 to retain overall + * precision and that 'lg2' is current scaled by an extra 12 bits, so adjust + * the overall scaling by 6-12. Round at every step. + */ + x -= 1U << 24; + + if (x <= 65536U) /* <= '257' */ + lg2 += ((23591U * (65536U-x)) + (1U << (16+6-12-1))) >> (16+6-12); + + else + lg2 -= ((23499U * (x-65536U)) + (1U << (16+6-12-1))) >> (16+6-12); + + /* Safe, because the result can't have more than 20 bits: */ + return (png_int_32)((lg2 + 2048) >> 12); +} + +/* The 'exp()' case must invert the above, taking a 20-bit fixed point + * logarithmic value and returning a 16 or 8-bit number as appropriate. In + * each case only the low 16 bits are relevant - the fraction - since the + * integer bits (the top 4) simply determine a shift. + * + * The worst case is the 16-bit distinction between 65535 and 65534, this + * requires perhaps spurious accuracy in the decoding of the logarithm to + * distinguish log2(65535/65534.5) - 10^-5 or 17 bits. There is little chance + * of getting this accuracy in practice. + * + * To deal with this the following exp() function works out the exponent of the + * frational part of the logarithm by using an accurate 32-bit value from the + * top four fractional bits then multiplying in the remaining bits. + */ +static png_uint_32 +png_32bit_exp[16] = +{ +# ifdef PNG_DO_BC + for (i=0;i<16;++i) { .5 + e(-i/16*l(2))*2^32; } +# else + /* NOTE: the first entry is deliberately set to the maximum 32-bit value. */ + 4294967295U, 4112874773U, 3938502376U, 3771522796U, 3611622603U, 3458501653U, + 3311872529U, 3171459999U, 3037000500U, 2908241642U, 2784941738U, 2666869345U, + 2553802834U, 2445529972U, 2341847524U, 2242560872U +# endif +}; + +/* Adjustment table; provided to explain the numbers in the code below. */ +#ifdef PNG_DO_BC +for (i=11;i>=0;--i){ print i, " ", (1 - e(-(2^i)/65536*l(2))) * 2^(32-i), "\n"} + 11 44937.64284865548751208448 + 10 45180.98734845585101160448 + 9 45303.31936980687359311872 + 8 45364.65110595323018870784 + 7 45395.35850361789624614912 + 6 45410.72259715102037508096 + 5 45418.40724413220722311168 + 4 45422.25021786898173001728 + 3 45424.17186732298419044352 + 2 45425.13273269940811464704 + 1 45425.61317555035558641664 + 0 45425.85339951654943850496 +#endif + +PNG_STATIC png_uint_32 +png_exp(png_fixed_point x) +{ + if (x > 0 && x <= 0xfffff) /* Else overflow or zero (underflow) */ + { + /* Obtain a 4-bit approximation */ + png_uint_32 e = png_32bit_exp[(x >> 12) & 0xf]; + + /* Incorporate the low 12 bits - these decrease the returned value by + * multiplying by a number less than 1 if the bit is set. The multiplier + * is determined by the above table and the shift. Notice that the values + * converge on 45426 and this is used to allow linear interpolation of the + * low bits. + */ + if (x & 0x800) + e -= (((e >> 16) * 44938U) + 16U) >> 5; + + if (x & 0x400) + e -= (((e >> 16) * 45181U) + 32U) >> 6; + + if (x & 0x200) + e -= (((e >> 16) * 45303U) + 64U) >> 7; + + if (x & 0x100) + e -= (((e >> 16) * 45365U) + 128U) >> 8; + + if (x & 0x080) + e -= (((e >> 16) * 45395U) + 256U) >> 9; + + if (x & 0x040) + e -= (((e >> 16) * 45410U) + 512U) >> 10; + + /* And handle the low 6 bits in a single block. */ + e -= (((e >> 16) * 355U * (x & 0x3fU)) + 256U) >> 9; + + /* Handle the upper bits of x. */ + e >>= x >> 16; + return e; + } + + /* Check for overflow */ + if (x <= 0) + return png_32bit_exp[0]; + + /* Else underflow */ + return 0; +} + +PNG_STATIC png_byte +png_exp8bit(png_fixed_point lg2) +{ + /* Get a 32-bit value: */ + png_uint_32 x = png_exp(lg2); + + /* Convert the 32-bit value to 0..255 by multiplying by 256-1, note that the + * second, rounding, step can't overflow because of the first, subtraction, + * step. + */ + x -= x >> 8; + return (png_byte)((x + 0x7fffffU) >> 24); +} + +PNG_STATIC png_uint_16 +png_exp16bit(png_fixed_point lg2) +{ + /* Get a 32-bit value: */ + png_uint_32 x = png_exp(lg2); + + /* Convert the 32-bit value to 0..65535 by multiplying by 65536-1: */ + x -= x >> 16; + return (png_uint_16)((x + 32767U) >> 16); +} +#endif /* FLOATING_ARITHMETIC */ + +png_byte +png_gamma_8bit_correct(unsigned int value, png_fixed_point gamma_val) +{ + if (value > 0 && value < 255) + { +# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + double r = floor(255*pow(value/255.,gamma_val*.00001)+.5); + return (png_byte)r; +# else + png_int_32 lg2 = png_log8bit(value); + png_fixed_point res; + + if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1)) + return png_exp8bit(res); + + /* Overflow. */ + value = 0; +# endif + } + + return (png_byte)value; +} + +png_uint_16 +png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val) +{ + if (value > 0 && value < 65535) + { +# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + double r = floor(65535*pow(value/65535.,gamma_val*.00001)+.5); + return (png_uint_16)r; +# else + png_int_32 lg2 = png_log16bit(value); + png_fixed_point res; + + if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1)) + return png_exp16bit(res); + + /* Overflow. */ + value = 0; +# endif + } + + return (png_uint_16)value; +} + +/* This does the right thing based on the bit_depth field of the + * png_struct, interpreting values as 8-bit or 16-bit. While the result + * is nominally a 16-bit value if bit depth is 8 then the result is + * 8-bit (as are the arguments.) + */ +png_uint_16 /* PRIVATE */ +png_gamma_correct(png_structp png_ptr, unsigned int value, + png_fixed_point gamma_val) +{ + if (png_ptr->bit_depth == 8) + return png_gamma_8bit_correct(value, gamma_val); + + else + return png_gamma_16bit_correct(value, gamma_val); +} + +/* This is the shared test on whether a gamma value is 'significant' - whether + * it is worth doing gamma correction. + */ +int /* PRIVATE */ +png_gamma_significant(png_fixed_point gamma_val) +{ + return gamma_val < PNG_FP_1 - PNG_GAMMA_THRESHOLD_FIXED || + gamma_val > PNG_FP_1 + PNG_GAMMA_THRESHOLD_FIXED; +} + +/* Internal function to build a single 16-bit table - the table consists of + * 'num' 256-entry subtables, where 'num' is determined by 'shift' - the amount + * to shift the input values right (or 16-number_of_signifiant_bits). + * + * The caller is responsible for ensuring that the table gets cleaned up on + * png_error (i.e. if one of the mallocs below fails) - i.e. the *table argument + * should be somewhere that will be cleaned. + */ +static void +png_build_16bit_table(png_structp png_ptr, png_uint_16pp *ptable, + PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val) +{ + /* Various values derived from 'shift': */ + PNG_CONST unsigned int num = 1U << (8U - shift); + PNG_CONST unsigned int max = (1U << (16U - shift))-1U; + PNG_CONST unsigned int max_by_2 = 1U << (15U-shift); + unsigned int i; + + png_uint_16pp table = *ptable = + (png_uint_16pp)png_calloc(png_ptr, num * png_sizeof(png_uint_16p)); + + for (i = 0; i < num; i++) + { + png_uint_16p sub_table = table[i] = + (png_uint_16p)png_malloc(png_ptr, 256 * png_sizeof(png_uint_16)); + + /* The 'threshold' test is repeated here because it can arise for one of + * the 16-bit tables even if the others don't hit it. + */ + if (png_gamma_significant(gamma_val)) + { + /* The old code would overflow at the end and this would cause the + * 'pow' function to return a result >1, resulting in an + * arithmetic error. This code follows the spec exactly; ig is + * the recovered input sample, it always has 8-16 bits. + * + * We want input * 65535/max, rounded, the arithmetic fits in 32 + * bits (unsigned) so long as max <= 32767. + */ + unsigned int j; + for (j = 0; j < 256; j++) + { + png_uint_32 ig = (j << (8-shift)) + i; +# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED + /* Inline the 'max' scaling operation: */ + double d = floor(65535*pow(ig/(double)max, gamma_val*.00001)+.5); + sub_table[j] = (png_uint_16)d; +# else + if (shift) + ig = (ig * 65535U + max_by_2)/max; + + sub_table[j] = png_gamma_16bit_correct(ig, gamma_val); +# endif + } + } + else + { + /* We must still build a table, but do it the fast way. */ + unsigned int j; + + for (j = 0; j < 256; j++) + { + png_uint_32 ig = (j << (8-shift)) + i; + + if (shift) + ig = (ig * 65535U + max_by_2)/max; + + sub_table[j] = (png_uint_16)ig; + } + } + } +} + +/* NOTE: this function expects the *inverse* of the overall gamma transformation + * required. + */ +static void +png_build_16to8_table(png_structp png_ptr, png_uint_16pp *ptable, + PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val) +{ + PNG_CONST unsigned int num = 1U << (8U - shift); + PNG_CONST unsigned int max = (1U << (16U - shift))-1U; + unsigned int i; + png_uint_32 last; + + png_uint_16pp table = *ptable = + (png_uint_16pp)png_calloc(png_ptr, num * png_sizeof(png_uint_16p)); + + /* 'num' is the number of tables and also the number of low bits of the + * input 16-bit value used to select a table. Each table is itself indexed + * by the high 8 bits of the value. + */ + for (i = 0; i < num; i++) + table[i] = (png_uint_16p)png_malloc(png_ptr, + 256 * png_sizeof(png_uint_16)); + + /* 'gamma_val' is set to the reciprocal of the value calculated above, so + * pow(out,g) is an *input* value. 'last' is the last input value set. + * + * In the loop 'i' is used to find output values. Since the output is + * 8-bit there are only 256 possible values. The tables are set up to + * select the closest possible output value for each input by finding + * the input value at the boundary between each pair of output values + * and filling the table up to that boundary with the lower output + * value. + * + * The boundary values are 0.5,1.5..253.5,254.5. Since these are 9-bit + * values the code below uses a 16-bit value in i; the values start at + * 128.5 (for 0.5) and step by 257, for a total of 254 values (the last + * entries are filled with 255). Start i at 128 and fill all 'last' + * table entries <= 'max' + */ + last = 0; + for (i = 0; i < 255; ++i) /* 8-bit output value */ + { + /* Find the corresponding maximum input value */ + png_uint_16 out = (png_uint_16)(i * 257U); /* 16-bit output value */ + + /* Find the boundary value in 16 bits: */ + png_uint_32 bound = png_gamma_16bit_correct(out+128U, gamma_val); + + /* Adjust (round) to (16-shift) bits: */ + bound = (bound * max + 32768U)/65535U + 1U; + + while (last < bound) + { + table[last & (0xffU >> shift)][last >> (8U - shift)] = out; + last++; + } + } + + /* And fill in the final entries. */ + while (last < (num << 8)) + { + table[last & (0xff >> shift)][last >> (8U - shift)] = 65535U; + last++; + } +} + +/* Build a single 8-bit table: same as the 16-bit case but much simpler (and + * typically much faster). Note that libpng currently does no sBIT processing + * (apparently contrary to the spec) so a 256-entry table is always generated. + */ +static void +png_build_8bit_table(png_structp png_ptr, png_bytepp ptable, + PNG_CONST png_fixed_point gamma_val) +{ + unsigned int i; + png_bytep table = *ptable = (png_bytep)png_malloc(png_ptr, 256); + + if (png_gamma_significant(gamma_val)) for (i=0; i<256; i++) + table[i] = png_gamma_8bit_correct(i, gamma_val); + + else for (i=0; i<256; ++i) + table[i] = (png_byte)i; +} + +/* Used from png_read_destroy and below to release the memory used by the gamma + * tables. + */ +void /* PRIVATE */ +png_destroy_gamma_table(png_structp png_ptr) +{ + png_free(png_ptr, png_ptr->gamma_table); + png_ptr->gamma_table = NULL; + + if (png_ptr->gamma_16_table != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_table[i]); + } + png_free(png_ptr, png_ptr->gamma_16_table); + png_ptr->gamma_16_table = NULL; + } + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + png_free(png_ptr, png_ptr->gamma_from_1); + png_ptr->gamma_from_1 = NULL; + png_free(png_ptr, png_ptr->gamma_to_1); + png_ptr->gamma_to_1 = NULL; + + if (png_ptr->gamma_16_from_1 != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_from_1[i]); + } + png_free(png_ptr, png_ptr->gamma_16_from_1); + png_ptr->gamma_16_from_1 = NULL; + } + if (png_ptr->gamma_16_to_1 != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_to_1[i]); + } + png_free(png_ptr, png_ptr->gamma_16_to_1); + png_ptr->gamma_16_to_1 = NULL; + } +#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ +} + +/* We build the 8- or 16-bit gamma tables here. Note that for 16-bit + * tables, we don't make a full table if we are reducing to 8-bit in + * the future. Note also how the gamma_16 tables are segmented so that + * we don't need to allocate > 64K chunks for a full 16-bit table. + */ +void /* PRIVATE */ +png_build_gamma_table(png_structp png_ptr, int bit_depth) +{ + png_debug(1, "in png_build_gamma_table"); + + /* Remove any existing table; this copes with multiple calls to + * png_read_update_info. The warning is because building the gamma tables + * multiple times is a performance hit - it's harmless but the ability to call + * png_read_update_info() multiple times is new in 1.5.6 so it seems sensible + * to warn if the app introduces such a hit. + */ + if (png_ptr->gamma_table != NULL || png_ptr->gamma_16_table != NULL) + { + png_warning(png_ptr, "gamma table being rebuilt"); + png_destroy_gamma_table(png_ptr); + } + + if (bit_depth <= 8) + { + png_build_8bit_table(png_ptr, &png_ptr->gamma_table, + png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->gamma, + png_ptr->screen_gamma) : PNG_FP_1); + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + if (png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) + { + png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1, + png_reciprocal(png_ptr->gamma)); + + png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1, + png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) : + png_ptr->gamma/* Probably doing rgb_to_gray */); + } +#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ + } + else + { + png_byte shift, sig_bit; + + if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) + { + sig_bit = png_ptr->sig_bit.red; + + if (png_ptr->sig_bit.green > sig_bit) + sig_bit = png_ptr->sig_bit.green; + + if (png_ptr->sig_bit.blue > sig_bit) + sig_bit = png_ptr->sig_bit.blue; + } + else + sig_bit = png_ptr->sig_bit.gray; + + /* 16-bit gamma code uses this equation: + * + * ov = table[(iv & 0xff) >> gamma_shift][iv >> 8] + * + * Where 'iv' is the input color value and 'ov' is the output value - + * pow(iv, gamma). + * + * Thus the gamma table consists of up to 256 256-entry tables. The table + * is selected by the (8-gamma_shift) most significant of the low 8 bits of + * the color value then indexed by the upper 8 bits: + * + * table[low bits][high 8 bits] + * + * So the table 'n' corresponds to all those 'iv' of: + * + * ..<(n+1 << gamma_shift)-1> + * + */ + if (sig_bit > 0 && sig_bit < 16U) + shift = (png_byte)(16U - sig_bit); /* shift == insignificant bits */ + + else + shift = 0; /* keep all 16 bits */ + + if (png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) + { + /* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively + * the significant bits in the *input* when the output will + * eventually be 8 bits. By default it is 11. + */ + if (shift < (16U - PNG_MAX_GAMMA_8)) + shift = (16U - PNG_MAX_GAMMA_8); + } + + if (shift > 8U) + shift = 8U; /* Guarantees at least one table! */ + + png_ptr->gamma_shift = shift; + +#ifdef PNG_16BIT_SUPPORTED + /* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now + * PNG_COMPOSE). This effectively smashed the background calculation for + * 16-bit output because the 8-bit table assumes the result will be reduced + * to 8 bits. + */ + if (png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) +#endif + png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift, + png_ptr->screen_gamma > 0 ? png_product2(png_ptr->gamma, + png_ptr->screen_gamma) : PNG_FP_1); + +#ifdef PNG_16BIT_SUPPORTED + else + png_build_16bit_table(png_ptr, &png_ptr->gamma_16_table, shift, + png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->gamma, + png_ptr->screen_gamma) : PNG_FP_1); +#endif + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + if (png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) + { + png_build_16bit_table(png_ptr, &png_ptr->gamma_16_to_1, shift, + png_reciprocal(png_ptr->gamma)); + + /* Notice that the '16 from 1' table should be full precision, however + * the lookup on this table still uses gamma_shift, so it can't be. + * TODO: fix this. + */ + png_build_16bit_table(png_ptr, &png_ptr->gamma_16_from_1, shift, + png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) : + png_ptr->gamma/* Probably doing rgb_to_gray */); + } +#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ + } +} +#endif /* READ_GAMMA */ +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ diff --git a/Source/LibPNG/png.h b/Source/LibPNG/png.h index 6d762fc..7b74433 100644 --- a/Source/LibPNG/png.h +++ b/Source/LibPNG/png.h @@ -1,2674 +1,2674 @@ - -/* png.h - header file for PNG reference library - * - * libpng version 1.5.13 - September 27, 2012 - * Copyright (c) 1998-2012 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license (See LICENSE, below) - * - * Authors and maintainers: - * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat - * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger - * libpng versions 0.97, January 1998, through 1.5.13 - September 27, 2012: Glenn - * See also "Contributing Authors", below. - * - * Note about libpng version numbers: - * - * Due to various miscommunications, unforeseen code incompatibilities - * and occasional factors outside the authors' control, version numbering - * on the library has not always been consistent and straightforward. - * The following table summarizes matters since version 0.89c, which was - * the first widely used release: - * - * source png.h png.h shared-lib - * version string int version - * ------- ------ ----- ---------- - * 0.89c "1.0 beta 3" 0.89 89 1.0.89 - * 0.90 "1.0 beta 4" 0.90 90 0.90 [should have been 2.0.90] - * 0.95 "1.0 beta 5" 0.95 95 0.95 [should have been 2.0.95] - * 0.96 "1.0 beta 6" 0.96 96 0.96 [should have been 2.0.96] - * 0.97b "1.00.97 beta 7" 1.00.97 97 1.0.1 [should have been 2.0.97] - * 0.97c 0.97 97 2.0.97 - * 0.98 0.98 98 2.0.98 - * 0.99 0.99 98 2.0.99 - * 0.99a-m 0.99 99 2.0.99 - * 1.00 1.00 100 2.1.0 [100 should be 10000] - * 1.0.0 (from here on, the 100 2.1.0 [100 should be 10000] - * 1.0.1 png.h string is 10001 2.1.0 - * 1.0.1a-e identical to the 10002 from here on, the shared library - * 1.0.2 source version) 10002 is 2.V where V is the source code - * 1.0.2a-b 10003 version, except as noted. - * 1.0.3 10003 - * 1.0.3a-d 10004 - * 1.0.4 10004 - * 1.0.4a-f 10005 - * 1.0.5 (+ 2 patches) 10005 - * 1.0.5a-d 10006 - * 1.0.5e-r 10100 (not source compatible) - * 1.0.5s-v 10006 (not binary compatible) - * 1.0.6 (+ 3 patches) 10006 (still binary incompatible) - * 1.0.6d-f 10007 (still binary incompatible) - * 1.0.6g 10007 - * 1.0.6h 10007 10.6h (testing xy.z so-numbering) - * 1.0.6i 10007 10.6i - * 1.0.6j 10007 2.1.0.6j (incompatible with 1.0.0) - * 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14 (binary compatible) - * 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 (binary compatible) - * 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 (binary compatible) - * 1.0.7 1 10007 (still compatible) - * 1.0.8beta1-4 1 10008 2.1.0.8beta1-4 - * 1.0.8rc1 1 10008 2.1.0.8rc1 - * 1.0.8 1 10008 2.1.0.8 - * 1.0.9beta1-6 1 10009 2.1.0.9beta1-6 - * 1.0.9rc1 1 10009 2.1.0.9rc1 - * 1.0.9beta7-10 1 10009 2.1.0.9beta7-10 - * 1.0.9rc2 1 10009 2.1.0.9rc2 - * 1.0.9 1 10009 2.1.0.9 - * 1.0.10beta1 1 10010 2.1.0.10beta1 - * 1.0.10rc1 1 10010 2.1.0.10rc1 - * 1.0.10 1 10010 2.1.0.10 - * 1.0.11beta1-3 1 10011 2.1.0.11beta1-3 - * 1.0.11rc1 1 10011 2.1.0.11rc1 - * 1.0.11 1 10011 2.1.0.11 - * 1.0.12beta1-2 2 10012 2.1.0.12beta1-2 - * 1.0.12rc1 2 10012 2.1.0.12rc1 - * 1.0.12 2 10012 2.1.0.12 - * 1.1.0a-f - 10100 2.1.1.0a-f (branch abandoned) - * 1.2.0beta1-2 2 10200 2.1.2.0beta1-2 - * 1.2.0beta3-5 3 10200 3.1.2.0beta3-5 - * 1.2.0rc1 3 10200 3.1.2.0rc1 - * 1.2.0 3 10200 3.1.2.0 - * 1.2.1beta1-4 3 10201 3.1.2.1beta1-4 - * 1.2.1rc1-2 3 10201 3.1.2.1rc1-2 - * 1.2.1 3 10201 3.1.2.1 - * 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6 - * 1.0.13beta1 10 10013 10.so.0.1.0.13beta1 - * 1.0.13rc1 10 10013 10.so.0.1.0.13rc1 - * 1.2.2rc1 12 10202 12.so.0.1.2.2rc1 - * 1.0.13 10 10013 10.so.0.1.0.13 - * 1.2.2 12 10202 12.so.0.1.2.2 - * 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6 - * 1.2.3 12 10203 12.so.0.1.2.3 - * 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3 - * 1.0.14rc1 13 10014 10.so.0.1.0.14rc1 - * 1.2.4rc1 13 10204 12.so.0.1.2.4rc1 - * 1.0.14 10 10014 10.so.0.1.0.14 - * 1.2.4 13 10204 12.so.0.1.2.4 - * 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2 - * 1.0.15rc1-3 10 10015 10.so.0.1.0.15rc1-3 - * 1.2.5rc1-3 13 10205 12.so.0.1.2.5rc1-3 - * 1.0.15 10 10015 10.so.0.1.0.15 - * 1.2.5 13 10205 12.so.0.1.2.5 - * 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4 - * 1.0.16 10 10016 10.so.0.1.0.16 - * 1.2.6 13 10206 12.so.0.1.2.6 - * 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2 - * 1.0.17rc1 10 10017 12.so.0.1.0.17rc1 - * 1.2.7rc1 13 10207 12.so.0.1.2.7rc1 - * 1.0.17 10 10017 12.so.0.1.0.17 - * 1.2.7 13 10207 12.so.0.1.2.7 - * 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5 - * 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5 - * 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5 - * 1.0.18 10 10018 12.so.0.1.0.18 - * 1.2.8 13 10208 12.so.0.1.2.8 - * 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3 - * 1.2.9beta4-11 13 10209 12.so.0.9[.0] - * 1.2.9rc1 13 10209 12.so.0.9[.0] - * 1.2.9 13 10209 12.so.0.9[.0] - * 1.2.10beta1-7 13 10210 12.so.0.10[.0] - * 1.2.10rc1-2 13 10210 12.so.0.10[.0] - * 1.2.10 13 10210 12.so.0.10[.0] - * 1.4.0beta1-5 14 10400 14.so.0.0[.0] - * 1.2.11beta1-4 13 10211 12.so.0.11[.0] - * 1.4.0beta7-8 14 10400 14.so.0.0[.0] - * 1.2.11 13 10211 12.so.0.11[.0] - * 1.2.12 13 10212 12.so.0.12[.0] - * 1.4.0beta9-14 14 10400 14.so.0.0[.0] - * 1.2.13 13 10213 12.so.0.13[.0] - * 1.4.0beta15-36 14 10400 14.so.0.0[.0] - * 1.4.0beta37-87 14 10400 14.so.14.0[.0] - * 1.4.0rc01 14 10400 14.so.14.0[.0] - * 1.4.0beta88-109 14 10400 14.so.14.0[.0] - * 1.4.0rc02-08 14 10400 14.so.14.0[.0] - * 1.4.0 14 10400 14.so.14.0[.0] - * 1.4.1beta01-03 14 10401 14.so.14.1[.0] - * 1.4.1rc01 14 10401 14.so.14.1[.0] - * 1.4.1beta04-12 14 10401 14.so.14.1[.0] - * 1.4.1 14 10401 14.so.14.1[.0] - * 1.4.2 14 10402 14.so.14.2[.0] - * 1.4.3 14 10403 14.so.14.3[.0] - * 1.4.4 14 10404 14.so.14.4[.0] - * 1.5.0beta01-58 15 10500 15.so.15.0[.0] - * 1.5.0rc01-07 15 10500 15.so.15.0[.0] - * 1.5.0 15 10500 15.so.15.0[.0] - * 1.5.1beta01-11 15 10501 15.so.15.1[.0] - * 1.5.1rc01-02 15 10501 15.so.15.1[.0] - * 1.5.1 15 10501 15.so.15.1[.0] - * 1.5.2beta01-03 15 10502 15.so.15.2[.0] - * 1.5.2rc01-03 15 10502 15.so.15.2[.0] - * 1.5.2 15 10502 15.so.15.2[.0] - * 1.5.3beta01-10 15 10503 15.so.15.3[.0] - * 1.5.3rc01-02 15 10503 15.so.15.3[.0] - * 1.5.3beta11 15 10503 15.so.15.3[.0] - * 1.5.3 [omitted] - * 1.5.4beta01-08 15 10504 15.so.15.4[.0] - * 1.5.4rc01 15 10504 15.so.15.4[.0] - * 1.5.4 15 10504 15.so.15.4[.0] - * 1.5.5beta01-08 15 10505 15.so.15.5[.0] - * 1.5.5rc01 15 10505 15.so.15.5[.0] - * 1.5.5 15 10505 15.so.15.5[.0] - * 1.5.6beta01-07 15 10506 15.so.15.6[.0] - * 1.5.6rc01-03 15 10506 15.so.15.6[.0] - * 1.5.6 15 10506 15.so.15.6[.0] - * 1.5.7beta01-05 15 10507 15.so.15.7[.0] - * 1.5.7rc01-03 15 10507 15.so.15.7[.0] - * 1.5.7 15 10507 15.so.15.7[.0] - * 1.5.8beta01 15 10508 15.so.15.8[.0] - * 1.5.8rc01 15 10508 15.so.15.8[.0] - * 1.5.8 15 10508 15.so.15.8[.0] - * 1.5.9beta01-02 15 10509 15.so.15.9[.0] - * 1.5.9rc01 15 10509 15.so.15.9[.0] - * 1.5.9 15 10509 15.so.15.9[.0] - * 1.5.10beta01-05 15 10510 15.so.15.10[.0] - * 1.5.10 15 10510 15.so.15.10[.0] - * 1.5.11beta01 15 10511 15.so.15.11[.0] - * 1.5.11rc01-05 15 10511 15.so.15.11[.0] - * 1.5.11 15 10511 15.so.15.11[.0] - * 1.5.12 15 10512 15.so.15.12[.0] - * 1.5.13beta01-02 15 10513 15.so.15.13[.0] - * 1.5.13rc01 15 10513 15.so.15.13[.0] - * 1.5.13 15 10513 15.so.15.13[.0] - * - * Henceforth the source version will match the shared-library major - * and minor numbers; the shared-library major version number will be - * used for changes in backward compatibility, as it is intended. The - * PNG_LIBPNG_VER macro, which is not used within libpng but is available - * for applications, is an unsigned integer of the form xyyzz corresponding - * to the source version x.y.z (leading zeros in y and z). Beta versions - * were given the previous public release number plus a letter, until - * version 1.0.6j; from then on they were given the upcoming public - * release number plus "betaNN" or "rcNN". - * - * Binary incompatibility exists only when applications make direct access - * to the info_ptr or png_ptr members through png.h, and the compiled - * application is loaded with a different version of the library. - * - * DLLNUM will change each time there are forward or backward changes - * in binary compatibility (e.g., when a new feature is added). - * - * See libpng-manual.txt or libpng.3 for more information. The PNG - * specification is available as a W3C Recommendation and as an ISO - * Specification, -# endif - - /* Need the time information for converting tIME chunks, it - * defines struct tm: - */ -# ifdef PNG_CONVERT_tIME_SUPPORTED - /* "time.h" functions are not supported on all operating systems */ -# include -# endif -# endif - -/* Machine specific configuration. */ -# include "pngconf.h" -#endif - -/* - * Added at libpng-1.2.8 - * - * Ref MSDN: Private as priority over Special - * VS_FF_PRIVATEBUILD File *was not* built using standard release - * procedures. If this value is given, the StringFileInfo block must - * contain a PrivateBuild string. - * - * VS_FF_SPECIALBUILD File *was* built by the original company using - * standard release procedures but is a variation of the standard - * file of the same version number. If this value is given, the - * StringFileInfo block must contain a SpecialBuild string. - */ - -#ifdef PNG_USER_PRIVATEBUILD /* From pnglibconf.h */ -# define PNG_LIBPNG_BUILD_TYPE \ - (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE) -#else -# ifdef PNG_LIBPNG_SPECIALBUILD -# define PNG_LIBPNG_BUILD_TYPE \ - (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL) -# else -# define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE) -# endif -#endif - -#ifndef PNG_VERSION_INFO_ONLY - -/* Inhibit C++ name-mangling for libpng functions but not for system calls. */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* Version information for C files, stored in png.c. This had better match - * the version above. - */ -#define png_libpng_ver png_get_header_ver(NULL) - -/* This file is arranged in several sections: - * - * 1. Any configuration options that can be specified by for the application - * code when it is built. (Build time configuration is in pnglibconf.h) - * 2. Type definitions (base types are defined in pngconf.h), structure - * definitions. - * 3. Exported library functions. - * - * The library source code has additional files (principally pngpriv.h) that - * allow configuration of the library. - */ -/* Section 1: run time configuration - * See pnglibconf.h for build time configuration - * - * Run time configuration allows the application to choose between - * implementations of certain arithmetic APIs. The default is set - * at build time and recorded in pnglibconf.h, but it is safe to - * override these (and only these) settings. Note that this won't - * change what the library does, only application code, and the - * settings can (and probably should) be made on a per-file basis - * by setting the #defines before including png.h - * - * Use macros to read integers from PNG data or use the exported - * functions? - * PNG_USE_READ_MACROS: use the macros (see below) Note that - * the macros evaluate their argument multiple times. - * PNG_NO_USE_READ_MACROS: call the relevant library function. - * - * Use the alternative algorithm for compositing alpha samples that - * does not use division? - * PNG_READ_COMPOSITE_NODIV_SUPPORTED: use the 'no division' - * algorithm. - * PNG_NO_READ_COMPOSITE_NODIV: use the 'division' algorithm. - * - * How to handle benign errors if PNG_ALLOW_BENIGN_ERRORS is - * false? - * PNG_ALLOW_BENIGN_ERRORS: map calls to the benign error - * APIs to png_warning. - * Otherwise the calls are mapped to png_error. - */ - -/* Section 2: type definitions, including structures and compile time - * constants. - * See pngconf.h for base types that vary by machine/system - */ - -/* This triggers a compiler error in png.c, if png.c and png.h - * do not agree upon the version number. - */ -typedef char* png_libpng_version_1_5_13; - -/* Three color definitions. The order of the red, green, and blue, (and the - * exact size) is not important, although the size of the fields need to - * be png_byte or png_uint_16 (as defined below). - */ -typedef struct png_color_struct -{ - png_byte red; - png_byte green; - png_byte blue; -} png_color; -typedef png_color FAR * png_colorp; -typedef PNG_CONST png_color FAR * png_const_colorp; -typedef png_color FAR * FAR * png_colorpp; - -typedef struct png_color_16_struct -{ - png_byte index; /* used for palette files */ - png_uint_16 red; /* for use in red green blue files */ - png_uint_16 green; - png_uint_16 blue; - png_uint_16 gray; /* for use in grayscale files */ -} png_color_16; -typedef png_color_16 FAR * png_color_16p; -typedef PNG_CONST png_color_16 FAR * png_const_color_16p; -typedef png_color_16 FAR * FAR * png_color_16pp; - -typedef struct png_color_8_struct -{ - png_byte red; /* for use in red green blue files */ - png_byte green; - png_byte blue; - png_byte gray; /* for use in grayscale files */ - png_byte alpha; /* for alpha channel files */ -} png_color_8; -typedef png_color_8 FAR * png_color_8p; -typedef PNG_CONST png_color_8 FAR * png_const_color_8p; -typedef png_color_8 FAR * FAR * png_color_8pp; - -/* - * The following two structures are used for the in-core representation - * of sPLT chunks. - */ -typedef struct png_sPLT_entry_struct -{ - png_uint_16 red; - png_uint_16 green; - png_uint_16 blue; - png_uint_16 alpha; - png_uint_16 frequency; -} png_sPLT_entry; -typedef png_sPLT_entry FAR * png_sPLT_entryp; -typedef PNG_CONST png_sPLT_entry FAR * png_const_sPLT_entryp; -typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp; - -/* When the depth of the sPLT palette is 8 bits, the color and alpha samples - * occupy the LSB of their respective members, and the MSB of each member - * is zero-filled. The frequency member always occupies the full 16 bits. - */ - -typedef struct png_sPLT_struct -{ - png_charp name; /* palette name */ - png_byte depth; /* depth of palette samples */ - png_sPLT_entryp entries; /* palette entries */ - png_int_32 nentries; /* number of palette entries */ -} png_sPLT_t; -typedef png_sPLT_t FAR * png_sPLT_tp; -typedef PNG_CONST png_sPLT_t FAR * png_const_sPLT_tp; -typedef png_sPLT_t FAR * FAR * png_sPLT_tpp; - -#ifdef PNG_TEXT_SUPPORTED -/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file, - * and whether that contents is compressed or not. The "key" field - * points to a regular zero-terminated C string. The "text" fields can be a - * regular C string, an empty string, or a NULL pointer. - * However, the structure returned by png_get_text() will always contain - * the "text" field as a regular zero-terminated C string (possibly - * empty), never a NULL pointer, so it can be safely used in printf() and - * other string-handling functions. Note that the "itxt_length", "lang", and - * "lang_key" members of the structure only exist when the library is built - * with iTXt chunk support. Prior to libpng-1.4.0 the library was built by - * default without iTXt support. Also note that when iTXt *is* supported, - * the "lang" and "lang_key" fields contain NULL pointers when the - * "compression" field contains * PNG_TEXT_COMPRESSION_NONE or - * PNG_TEXT_COMPRESSION_zTXt. Note that the "compression value" is not the - * same as what appears in the PNG tEXt/zTXt/iTXt chunk's "compression flag" - * which is always 0 or 1, or its "compression method" which is always 0. - */ -typedef struct png_text_struct -{ - int compression; /* compression value: - -1: tEXt, none - 0: zTXt, deflate - 1: iTXt, none - 2: iTXt, deflate */ - png_charp key; /* keyword, 1-79 character description of "text" */ - png_charp text; /* comment, may be an empty string (ie "") - or a NULL pointer */ - png_size_t text_length; /* length of the text string */ - png_size_t itxt_length; /* length of the itxt string */ - png_charp lang; /* language code, 0-79 characters - or a NULL pointer */ - png_charp lang_key; /* keyword translated UTF-8 string, 0 or more - chars or a NULL pointer */ -} png_text; -typedef png_text FAR * png_textp; -typedef PNG_CONST png_text FAR * png_const_textp; -typedef png_text FAR * FAR * png_textpp; -#endif - -/* Supported compression types for text in PNG files (tEXt, and zTXt). - * The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed. */ -#define PNG_TEXT_COMPRESSION_NONE_WR -3 -#define PNG_TEXT_COMPRESSION_zTXt_WR -2 -#define PNG_TEXT_COMPRESSION_NONE -1 -#define PNG_TEXT_COMPRESSION_zTXt 0 -#define PNG_ITXT_COMPRESSION_NONE 1 -#define PNG_ITXT_COMPRESSION_zTXt 2 -#define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */ - -/* png_time is a way to hold the time in an machine independent way. - * Two conversions are provided, both from time_t and struct tm. There - * is no portable way to convert to either of these structures, as far - * as I know. If you know of a portable way, send it to me. As a side - * note - PNG has always been Year 2000 compliant! - */ -typedef struct png_time_struct -{ - png_uint_16 year; /* full year, as in, 1995 */ - png_byte month; /* month of year, 1 - 12 */ - png_byte day; /* day of month, 1 - 31 */ - png_byte hour; /* hour of day, 0 - 23 */ - png_byte minute; /* minute of hour, 0 - 59 */ - png_byte second; /* second of minute, 0 - 60 (for leap seconds) */ -} png_time; -typedef png_time FAR * png_timep; -typedef PNG_CONST png_time FAR * png_const_timep; -typedef png_time FAR * FAR * png_timepp; - -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \ - defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) -/* png_unknown_chunk is a structure to hold queued chunks for which there is - * no specific support. The idea is that we can use this to queue - * up private chunks for output even though the library doesn't actually - * know about their semantics. - */ -typedef struct png_unknown_chunk_t -{ - png_byte name[5]; - png_byte *data; - png_size_t size; - - /* libpng-using applications should NOT directly modify this byte. */ - png_byte location; /* mode of operation at read time */ -} - - -png_unknown_chunk; -typedef png_unknown_chunk FAR * png_unknown_chunkp; -typedef PNG_CONST png_unknown_chunk FAR * png_const_unknown_chunkp; -typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp; -#endif - -/* Values for the unknown chunk location byte */ - -#define PNG_HAVE_IHDR 0x01 -#define PNG_HAVE_PLTE 0x02 -#define PNG_AFTER_IDAT 0x08 - -/* The complete definition of png_info has, as of libpng-1.5.0, - * been moved into a separate header file that is not accessible to - * applications. Read libpng-manual.txt or libpng.3 for more info. - */ -typedef struct png_info_def png_info; -typedef png_info FAR * png_infop; -typedef PNG_CONST png_info FAR * png_const_infop; -typedef png_info FAR * FAR * png_infopp; - -/* Maximum positive integer used in PNG is (2^31)-1 */ -#define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL) -#define PNG_UINT_32_MAX ((png_uint_32)(-1)) -#define PNG_SIZE_MAX ((png_size_t)(-1)) - -/* These are constants for fixed point values encoded in the - * PNG specification manner (x100000) - */ -#define PNG_FP_1 100000 -#define PNG_FP_HALF 50000 -#define PNG_FP_MAX ((png_fixed_point)0x7fffffffL) -#define PNG_FP_MIN (-PNG_FP_MAX) - -/* These describe the color_type field in png_info. */ -/* color type masks */ -#define PNG_COLOR_MASK_PALETTE 1 -#define PNG_COLOR_MASK_COLOR 2 -#define PNG_COLOR_MASK_ALPHA 4 - -/* color types. Note that not all combinations are legal */ -#define PNG_COLOR_TYPE_GRAY 0 -#define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE) -#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR) -#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA) -#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA) -/* aliases */ -#define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA -#define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA - -/* This is for compression type. PNG 1.0-1.2 only define the single type. */ -#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */ -#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE - -/* This is for filter type. PNG 1.0-1.2 only define the single type. */ -#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */ -#define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */ -#define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE - -/* These are for the interlacing type. These values should NOT be changed. */ -#define PNG_INTERLACE_NONE 0 /* Non-interlaced image */ -#define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */ -#define PNG_INTERLACE_LAST 2 /* Not a valid value */ - -/* These are for the oFFs chunk. These values should NOT be changed. */ -#define PNG_OFFSET_PIXEL 0 /* Offset in pixels */ -#define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */ -#define PNG_OFFSET_LAST 2 /* Not a valid value */ - -/* These are for the pCAL chunk. These values should NOT be changed. */ -#define PNG_EQUATION_LINEAR 0 /* Linear transformation */ -#define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */ -#define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */ -#define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */ -#define PNG_EQUATION_LAST 4 /* Not a valid value */ - -/* These are for the sCAL chunk. These values should NOT be changed. */ -#define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */ -#define PNG_SCALE_METER 1 /* meters per pixel */ -#define PNG_SCALE_RADIAN 2 /* radians per pixel */ -#define PNG_SCALE_LAST 3 /* Not a valid value */ - -/* These are for the pHYs chunk. These values should NOT be changed. */ -#define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */ -#define PNG_RESOLUTION_METER 1 /* pixels/meter */ -#define PNG_RESOLUTION_LAST 2 /* Not a valid value */ - -/* These are for the sRGB chunk. These values should NOT be changed. */ -#define PNG_sRGB_INTENT_PERCEPTUAL 0 -#define PNG_sRGB_INTENT_RELATIVE 1 -#define PNG_sRGB_INTENT_SATURATION 2 -#define PNG_sRGB_INTENT_ABSOLUTE 3 -#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */ - -/* This is for text chunks */ -#define PNG_KEYWORD_MAX_LENGTH 79 - -/* Maximum number of entries in PLTE/sPLT/tRNS arrays */ -#define PNG_MAX_PALETTE_LENGTH 256 - -/* These determine if an ancillary chunk's data has been successfully read - * from the PNG header, or if the application has filled in the corresponding - * data in the info_struct to be written into the output file. The values - * of the PNG_INFO_ defines should NOT be changed. - */ -#define PNG_INFO_gAMA 0x0001 -#define PNG_INFO_sBIT 0x0002 -#define PNG_INFO_cHRM 0x0004 -#define PNG_INFO_PLTE 0x0008 -#define PNG_INFO_tRNS 0x0010 -#define PNG_INFO_bKGD 0x0020 -#define PNG_INFO_hIST 0x0040 -#define PNG_INFO_pHYs 0x0080 -#define PNG_INFO_oFFs 0x0100 -#define PNG_INFO_tIME 0x0200 -#define PNG_INFO_pCAL 0x0400 -#define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */ -#define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */ -#define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */ -#define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */ -#define PNG_INFO_IDAT 0x8000 /* ESR, 1.0.6 */ - -/* This is used for the transformation routines, as some of them - * change these values for the row. It also should enable using - * the routines for other purposes. - */ -typedef struct png_row_info_struct -{ - png_uint_32 width; /* width of row */ - png_size_t rowbytes; /* number of bytes in row */ - png_byte color_type; /* color type of row */ - png_byte bit_depth; /* bit depth of row */ - png_byte channels; /* number of channels (1, 2, 3, or 4) */ - png_byte pixel_depth; /* bits per pixel (depth * channels) */ -} png_row_info; - -typedef png_row_info FAR * png_row_infop; -typedef png_row_info FAR * FAR * png_row_infopp; - -/* The complete definition of png_struct has, as of libpng-1.5.0, - * been moved into a separate header file that is not accessible to - * applications. Read libpng-manual.txt or libpng.3 for more info. - */ -typedef struct png_struct_def png_struct; -typedef PNG_CONST png_struct FAR * png_const_structp; -typedef png_struct FAR * png_structp; - -/* These are the function types for the I/O functions and for the functions - * that allow the user to override the default I/O functions with his or her - * own. The png_error_ptr type should match that of user-supplied warning - * and error functions, while the png_rw_ptr type should match that of the - * user read/write data functions. Note that the 'write' function must not - * modify the buffer it is passed. The 'read' function, on the other hand, is - * expected to return the read data in the buffer. - */ -typedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp)); -typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, png_size_t)); -typedef PNG_CALLBACK(void, *png_flush_ptr, (png_structp)); -typedef PNG_CALLBACK(void, *png_read_status_ptr, (png_structp, png_uint_32, - int)); -typedef PNG_CALLBACK(void, *png_write_status_ptr, (png_structp, png_uint_32, - int)); - -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED -typedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop)); -typedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop)); - -/* The following callback receives png_uint_32 row_number, int pass for the - * png_bytep data of the row. When transforming an interlaced image the - * row number is the row number within the sub-image of the interlace pass, so - * the value will increase to the height of the sub-image (not the full image) - * then reset to 0 for the next pass. - * - * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to - * find the output pixel (x,y) given an interlaced sub-image pixel - * (row,col,pass). (See below for these macros.) - */ -typedef PNG_CALLBACK(void, *png_progressive_row_ptr, (png_structp, png_bytep, - png_uint_32, int)); -#endif - -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) -typedef PNG_CALLBACK(void, *png_user_transform_ptr, (png_structp, png_row_infop, - png_bytep)); -#endif - -#ifdef PNG_USER_CHUNKS_SUPPORTED -typedef PNG_CALLBACK(int, *png_user_chunk_ptr, (png_structp, - png_unknown_chunkp)); -#endif -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED -typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp)); -#endif - -#ifdef PNG_SETJMP_SUPPORTED -/* This must match the function definition in , and the application - * must include this before png.h to obtain the definition of jmp_buf. The - * function is required to be PNG_NORETURN, but this is not checked. If the - * function does return the application will crash via an abort() or similar - * system level call. - * - * If you get a warning here while building the library you may need to make - * changes to ensure that pnglibconf.h records the calling convention used by - * your compiler. This may be very difficult - try using a different compiler - * to build the library! - */ -PNG_FUNCTION(void, (PNGCAPI *png_longjmp_ptr), PNGARG((jmp_buf, int)), typedef); -#endif - -/* Transform masks for the high-level interface */ -#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */ -#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */ -#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */ -#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */ -#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */ -#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */ -#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */ -#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */ -#define PNG_TRANSFORM_BGR 0x0080 /* read and write */ -#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */ -#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */ -#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */ -#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* write only */ -/* Added to libpng-1.2.34 */ -#define PNG_TRANSFORM_STRIP_FILLER_BEFORE PNG_TRANSFORM_STRIP_FILLER -#define PNG_TRANSFORM_STRIP_FILLER_AFTER 0x1000 /* write only */ -/* Added to libpng-1.4.0 */ -#define PNG_TRANSFORM_GRAY_TO_RGB 0x2000 /* read only */ -/* Added to libpng-1.5.4 */ -#define PNG_TRANSFORM_EXPAND_16 0x4000 /* read only */ -#define PNG_TRANSFORM_SCALE_16 0x8000 /* read only */ - -/* Flags for MNG supported features */ -#define PNG_FLAG_MNG_EMPTY_PLTE 0x01 -#define PNG_FLAG_MNG_FILTER_64 0x04 -#define PNG_ALL_MNG_FEATURES 0x05 - -/* NOTE: prior to 1.5 these functions had no 'API' style declaration, - * this allowed the zlib default functions to be used on Windows - * platforms. In 1.5 the zlib default malloc (which just calls malloc and - * ignores the first argument) should be completely compatible with the - * following. - */ -typedef PNG_CALLBACK(png_voidp, *png_malloc_ptr, (png_structp, - png_alloc_size_t)); -typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp)); - -typedef png_struct FAR * FAR * png_structpp; - -/* Section 3: exported functions - * Here are the function definitions most commonly used. This is not - * the place to find out how to use libpng. See libpng-manual.txt for the - * full explanation, see example.c for the summary. This just provides - * a simple one line description of the use of each function. - * - * The PNG_EXPORT() and PNG_EXPORTA() macros used below are defined in - * pngconf.h and in the *.dfn files in the scripts directory. - * - * PNG_EXPORT(ordinal, type, name, (args)); - * - * ordinal: ordinal that is used while building - * *.def files. The ordinal value is only - * relevant when preprocessing png.h with - * the *.dfn files for building symbol table - * entries, and are removed by pngconf.h. - * type: return type of the function - * name: function name - * args: function arguments, with types - * - * When we wish to append attributes to a function prototype we use - * the PNG_EXPORTA() macro instead. - * - * PNG_EXPORTA(ordinal, type, name, (args), attributes); - * - * ordinal, type, name, and args: same as in PNG_EXPORT(). - * attributes: function attributes - */ - -/* Returns the version number of the library */ -PNG_EXPORT(1, png_uint_32, png_access_version_number, (void)); - -/* Tell lib we have already handled the first magic bytes. - * Handling more than 8 bytes from the beginning of the file is an error. - */ -PNG_EXPORT(2, void, png_set_sig_bytes, (png_structp png_ptr, int num_bytes)); - -/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a - * PNG file. Returns zero if the supplied bytes match the 8-byte PNG - * signature, and non-zero otherwise. Having num_to_check == 0 or - * start > 7 will always fail (ie return non-zero). - */ -PNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, png_size_t start, - png_size_t num_to_check)); - -/* Simple signature checking function. This is the same as calling - * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n). - */ -#define png_check_sig(sig, n) !png_sig_cmp((sig), 0, (n)) - -/* Allocate and initialize png_ptr struct for reading, and any other memory. */ -PNG_EXPORTA(4, png_structp, png_create_read_struct, - (png_const_charp user_png_ver, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warn_fn), - PNG_ALLOCATED); - -/* Allocate and initialize png_ptr struct for writing, and any other memory */ -PNG_EXPORTA(5, png_structp, png_create_write_struct, - (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, - png_error_ptr warn_fn), - PNG_ALLOCATED); - -PNG_EXPORT(6, png_size_t, png_get_compression_buffer_size, - (png_const_structp png_ptr)); - -PNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structp png_ptr, - png_size_t size)); - -/* Moved from pngconf.h in 1.4.0 and modified to ensure setjmp/longjmp - * match up. - */ -#ifdef PNG_SETJMP_SUPPORTED -/* This function returns the jmp_buf built in to *png_ptr. It must be - * supplied with an appropriate 'longjmp' function to use on that jmp_buf - * unless the default error function is overridden in which case NULL is - * acceptable. The size of the jmp_buf is checked against the actual size - * allocated by the library - the call will return NULL on a mismatch - * indicating an ABI mismatch. - */ -PNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structp png_ptr, - png_longjmp_ptr longjmp_fn, size_t jmp_buf_size)); -# define png_jmpbuf(png_ptr) \ - (*png_set_longjmp_fn((png_ptr), longjmp, sizeof (jmp_buf))) -#else -# define png_jmpbuf(png_ptr) \ - (LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP) -#endif -/* This function should be used by libpng applications in place of - * longjmp(png_ptr->jmpbuf, val). If longjmp_fn() has been set, it - * will use it; otherwise it will call PNG_ABORT(). This function was - * added in libpng-1.5.0. - */ -PNG_EXPORTA(9, void, png_longjmp, (png_structp png_ptr, int val), - PNG_NORETURN); - -#ifdef PNG_READ_SUPPORTED -/* Reset the compression stream */ -PNG_EXPORT(10, int, png_reset_zstream, (png_structp png_ptr)); -#endif - -/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */ -#ifdef PNG_USER_MEM_SUPPORTED -PNG_EXPORTA(11, png_structp, png_create_read_struct_2, - (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, - png_error_ptr warn_fn, - png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn), - PNG_ALLOCATED); -PNG_EXPORTA(12, png_structp, png_create_write_struct_2, - (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, - png_error_ptr warn_fn, - png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn), - PNG_ALLOCATED); -#endif - -/* Write the PNG file signature. */ -PNG_EXPORT(13, void, png_write_sig, (png_structp png_ptr)); - -/* Write a PNG chunk - size, type, (optional) data, CRC. */ -PNG_EXPORT(14, void, png_write_chunk, (png_structp png_ptr, png_const_bytep - chunk_name, png_const_bytep data, png_size_t length)); - -/* Write the start of a PNG chunk - length and chunk name. */ -PNG_EXPORT(15, void, png_write_chunk_start, (png_structp png_ptr, - png_const_bytep chunk_name, png_uint_32 length)); - -/* Write the data of a PNG chunk started with png_write_chunk_start(). */ -PNG_EXPORT(16, void, png_write_chunk_data, (png_structp png_ptr, - png_const_bytep data, png_size_t length)); - -/* Finish a chunk started with png_write_chunk_start() (includes CRC). */ -PNG_EXPORT(17, void, png_write_chunk_end, (png_structp png_ptr)); - -/* Allocate and initialize the info structure */ -PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_structp png_ptr), - PNG_ALLOCATED); - -PNG_EXPORT(19, void, png_info_init_3, (png_infopp info_ptr, - png_size_t png_info_struct_size)); - -/* Writes all the PNG information before the image. */ -PNG_EXPORT(20, void, png_write_info_before_PLTE, - (png_structp png_ptr, png_infop info_ptr)); -PNG_EXPORT(21, void, png_write_info, - (png_structp png_ptr, png_infop info_ptr)); - -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED -/* Read the information before the actual image data. */ -PNG_EXPORT(22, void, png_read_info, - (png_structp png_ptr, png_infop info_ptr)); -#endif - -#ifdef PNG_TIME_RFC1123_SUPPORTED -PNG_EXPORT(23, png_const_charp, png_convert_to_rfc1123, - (png_structp png_ptr, - png_const_timep ptime)); -#endif - -#ifdef PNG_CONVERT_tIME_SUPPORTED -/* Convert from a struct tm to png_time */ -PNG_EXPORT(24, void, png_convert_from_struct_tm, (png_timep ptime, - PNG_CONST struct tm FAR * ttime)); - -/* Convert from time_t to png_time. Uses gmtime() */ -PNG_EXPORT(25, void, png_convert_from_time_t, - (png_timep ptime, time_t ttime)); -#endif /* PNG_CONVERT_tIME_SUPPORTED */ - -#ifdef PNG_READ_EXPAND_SUPPORTED -/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */ -PNG_EXPORT(26, void, png_set_expand, (png_structp png_ptr)); -PNG_EXPORT(27, void, png_set_expand_gray_1_2_4_to_8, (png_structp png_ptr)); -PNG_EXPORT(28, void, png_set_palette_to_rgb, (png_structp png_ptr)); -PNG_EXPORT(29, void, png_set_tRNS_to_alpha, (png_structp png_ptr)); -#endif - -#ifdef PNG_READ_EXPAND_16_SUPPORTED -/* Expand to 16-bit channels, forces conversion of palette to RGB and expansion - * of a tRNS chunk if present. - */ -PNG_EXPORT(221, void, png_set_expand_16, (png_structp png_ptr)); -#endif - -#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) -/* Use blue, green, red order for pixels. */ -PNG_EXPORT(30, void, png_set_bgr, (png_structp png_ptr)); -#endif - -#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED -/* Expand the grayscale to 24-bit RGB if necessary. */ -PNG_EXPORT(31, void, png_set_gray_to_rgb, (png_structp png_ptr)); -#endif - -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED -/* Reduce RGB to grayscale. */ -#define PNG_ERROR_ACTION_NONE 1 -#define PNG_ERROR_ACTION_WARN 2 -#define PNG_ERROR_ACTION_ERROR 3 -#define PNG_RGB_TO_GRAY_DEFAULT (-1)/*for red/green coefficients*/ - -PNG_FP_EXPORT(32, void, png_set_rgb_to_gray, (png_structp png_ptr, - int error_action, double red, double green)) -PNG_FIXED_EXPORT(33, void, png_set_rgb_to_gray_fixed, (png_structp png_ptr, - int error_action, png_fixed_point red, png_fixed_point green)) - -PNG_EXPORT(34, png_byte, png_get_rgb_to_gray_status, (png_const_structp - png_ptr)); -#endif - -#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED -PNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth, - png_colorp palette)); -#endif - -#ifdef PNG_READ_ALPHA_MODE_SUPPORTED -/* How the alpha channel is interpreted - this affects how the color channels of - * a PNG file are returned when an alpha channel, or tRNS chunk in a palette - * file, is present. - * - * This has no effect on the way pixels are written into a PNG output - * datastream. The color samples in a PNG datastream are never premultiplied - * with the alpha samples. - * - * The default is to return data according to the PNG specification: the alpha - * channel is a linear measure of the contribution of the pixel to the - * corresponding composited pixel. The gamma encoded color channels must be - * scaled according to the contribution and to do this it is necessary to undo - * the encoding, scale the color values, perform the composition and reencode - * the values. This is the 'PNG' mode. - * - * The alternative is to 'associate' the alpha with the color information by - * storing color channel values that have been scaled by the alpha. The - * advantage is that the color channels can be resampled (the image can be - * scaled) in this form. The disadvantage is that normal practice is to store - * linear, not (gamma) encoded, values and this requires 16-bit channels for - * still images rather than the 8-bit channels that are just about sufficient if - * gamma encoding is used. In addition all non-transparent pixel values, - * including completely opaque ones, must be gamma encoded to produce the final - * image. This is the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' mode (the - * latter being the two common names for associated alpha color channels.) - * - * Since it is not necessary to perform arithmetic on opaque color values so - * long as they are not to be resampled and are in the final color space it is - * possible to optimize the handling of alpha by storing the opaque pixels in - * the PNG format (adjusted for the output color space) while storing partially - * opaque pixels in the standard, linear, format. The accuracy required for - * standard alpha composition is relatively low, because the pixels are - * isolated, therefore typically the accuracy loss in storing 8-bit linear - * values is acceptable. (This is not true if the alpha channel is used to - * simulate transparency over large areas - use 16 bits or the PNG mode in - * this case!) This is the 'OPTIMIZED' mode. For this mode a pixel is - * treated as opaque only if the alpha value is equal to the maximum value. - * - * The final choice is to gamma encode the alpha channel as well. This is - * broken because, in practice, no implementation that uses this choice - * correctly undoes the encoding before handling alpha composition. Use this - * choice only if other serious errors in the software or hardware you use - * mandate it; the typical serious error is for dark halos to appear around - * opaque areas of the composited PNG image because of arithmetic overflow. - * - * The API function png_set_alpha_mode specifies which of these choices to use - * with an enumerated 'mode' value and the gamma of the required output: - */ -#define PNG_ALPHA_PNG 0 /* according to the PNG standard */ -#define PNG_ALPHA_STANDARD 1 /* according to Porter/Duff */ -#define PNG_ALPHA_ASSOCIATED 1 /* as above; this is the normal practice */ -#define PNG_ALPHA_PREMULTIPLIED 1 /* as above */ -#define PNG_ALPHA_OPTIMIZED 2 /* 'PNG' for opaque pixels, else 'STANDARD' */ -#define PNG_ALPHA_BROKEN 3 /* the alpha channel is gamma encoded */ - -PNG_FP_EXPORT(227, void, png_set_alpha_mode, (png_structp png_ptr, int mode, - double output_gamma)) -PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structp png_ptr, - int mode, png_fixed_point output_gamma)) -#endif - -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_ALPHA_MODE_SUPPORTED) -/* The output_gamma value is a screen gamma in libpng terminology: it expresses - * how to decode the output values, not how they are encoded. The values used - * correspond to the normal numbers used to describe the overall gamma of a - * computer display system; for example 2.2 for an sRGB conformant system. The - * values are scaled by 100000 in the _fixed version of the API (so 220000 for - * sRGB.) - * - * The inverse of the value is always used to provide a default for the PNG file - * encoding if it has no gAMA chunk and if png_set_gamma() has not been called - * to override the PNG gamma information. - * - * When the ALPHA_OPTIMIZED mode is selected the output gamma is used to encode - * opaque pixels however pixels with lower alpha values are not encoded, - * regardless of the output gamma setting. - * - * When the standard Porter Duff handling is requested with mode 1 the output - * encoding is set to be linear and the output_gamma value is only relevant - * as a default for input data that has no gamma information. The linear output - * encoding will be overridden if png_set_gamma() is called - the results may be - * highly unexpected! - * - * The following numbers are derived from the sRGB standard and the research - * behind it. sRGB is defined to be approximated by a PNG gAMA chunk value of - * 0.45455 (1/2.2) for PNG. The value implicitly includes any viewing - * correction required to take account of any differences in the color - * environment of the original scene and the intended display environment; the - * value expresses how to *decode* the image for display, not how the original - * data was *encoded*. - * - * sRGB provides a peg for the PNG standard by defining a viewing environment. - * sRGB itself, and earlier TV standards, actually use a more complex transform - * (a linear portion then a gamma 2.4 power law) than PNG can express. (PNG is - * limited to simple power laws.) By saying that an image for direct display on - * an sRGB conformant system should be stored with a gAMA chunk value of 45455 - * (11.3.3.2 and 11.3.3.5 of the ISO PNG specification) the PNG specification - * makes it possible to derive values for other display systems and - * environments. - * - * The Mac value is deduced from the sRGB based on an assumption that the actual - * extra viewing correction used in early Mac display systems was implemented as - * a power 1.45 lookup table. - * - * Any system where a programmable lookup table is used or where the behavior of - * the final display device characteristics can be changed requires system - * specific code to obtain the current characteristic. However this can be - * difficult and most PNG gamma correction only requires an approximate value. - * - * By default, if png_set_alpha_mode() is not called, libpng assumes that all - * values are unencoded, linear, values and that the output device also has a - * linear characteristic. This is only very rarely correct - it is invariably - * better to call png_set_alpha_mode() with PNG_DEFAULT_sRGB than rely on the - * default if you don't know what the right answer is! - * - * The special value PNG_GAMMA_MAC_18 indicates an older Mac system (pre Mac OS - * 10.6) which used a correction table to implement a somewhat lower gamma on an - * otherwise sRGB system. - * - * Both these values are reserved (not simple gamma values) in order to allow - * more precise correction internally in the future. - * - * NOTE: the following values can be passed to either the fixed or floating - * point APIs, but the floating point API will also accept floating point - * values. - */ -#define PNG_DEFAULT_sRGB -1 /* sRGB gamma and color space */ -#define PNG_GAMMA_MAC_18 -2 /* Old Mac '1.8' gamma and color space */ -#define PNG_GAMMA_sRGB 220000 /* Television standards--matches sRGB gamma */ -#define PNG_GAMMA_LINEAR PNG_FP_1 /* Linear */ -#endif - -/* The following are examples of calls to png_set_alpha_mode to achieve the - * required overall gamma correction and, where necessary, alpha - * premultiplication. - * - * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB); - * This is the default libpng handling of the alpha channel - it is not - * pre-multiplied into the color components. In addition the call states - * that the output is for a sRGB system and causes all PNG files without gAMA - * chunks to be assumed to be encoded using sRGB. - * - * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC); - * In this case the output is assumed to be something like an sRGB conformant - * display preceeded by a power-law lookup table of power 1.45. This is how - * early Mac systems behaved. - * - * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR); - * This is the classic Jim Blinn approach and will work in academic - * environments where everything is done by the book. It has the shortcoming - * of assuming that input PNG data with no gamma information is linear - this - * is unlikely to be correct unless the PNG files where generated locally. - * Most of the time the output precision will be so low as to show - * significant banding in dark areas of the image. - * - * png_set_expand_16(pp); - * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_DEFAULT_sRGB); - * This is a somewhat more realistic Jim Blinn inspired approach. PNG files - * are assumed to have the sRGB encoding if not marked with a gamma value and - * the output is always 16 bits per component. This permits accurate scaling - * and processing of the data. If you know that your input PNG files were - * generated locally you might need to replace PNG_DEFAULT_sRGB with the - * correct value for your system. - * - * png_set_alpha_mode(pp, PNG_ALPHA_OPTIMIZED, PNG_DEFAULT_sRGB); - * If you just need to composite the PNG image onto an existing background - * and if you control the code that does this you can use the optimization - * setting. In this case you just copy completely opaque pixels to the - * output. For pixels that are not completely transparent (you just skip - * those) you do the composition math using png_composite or png_composite_16 - * below then encode the resultant 8-bit or 16-bit values to match the output - * encoding. - * - * Other cases - * If neither the PNG nor the standard linear encoding work for you because - * of the software or hardware you use then you have a big problem. The PNG - * case will probably result in halos around the image. The linear encoding - * will probably result in a washed out, too bright, image (it's actually too - * contrasty.) Try the ALPHA_OPTIMIZED mode above - this will probably - * substantially reduce the halos. Alternatively try: - * - * png_set_alpha_mode(pp, PNG_ALPHA_BROKEN, PNG_DEFAULT_sRGB); - * This option will also reduce the halos, but there will be slight dark - * halos round the opaque parts of the image where the background is light. - * In the OPTIMIZED mode the halos will be light halos where the background - * is dark. Take your pick - the halos are unavoidable unless you can get - * your hardware/software fixed! (The OPTIMIZED approach is slightly - * faster.) - * - * When the default gamma of PNG files doesn't match the output gamma. - * If you have PNG files with no gamma information png_set_alpha_mode allows - * you to provide a default gamma, but it also sets the ouput gamma to the - * matching value. If you know your PNG files have a gamma that doesn't - * match the output you can take advantage of the fact that - * png_set_alpha_mode always sets the output gamma but only sets the PNG - * default if it is not already set: - * - * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB); - * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC); - * The first call sets both the default and the output gamma values, the - * second call overrides the output gamma without changing the default. This - * is easier than achieving the same effect with png_set_gamma. You must use - * PNG_ALPHA_PNG for the first call - internal checking in png_set_alpha will - * fire if more than one call to png_set_alpha_mode and png_set_background is - * made in the same read operation, however multiple calls with PNG_ALPHA_PNG - * are ignored. - */ - -#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED -PNG_EXPORT(36, void, png_set_strip_alpha, (png_structp png_ptr)); -#endif - -#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ - defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) -PNG_EXPORT(37, void, png_set_swap_alpha, (png_structp png_ptr)); -#endif - -#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ - defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) -PNG_EXPORT(38, void, png_set_invert_alpha, (png_structp png_ptr)); -#endif - -#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) -/* Add a filler byte to 8-bit Gray or 24-bit RGB images. */ -PNG_EXPORT(39, void, png_set_filler, (png_structp png_ptr, png_uint_32 filler, - int flags)); -/* The values of the PNG_FILLER_ defines should NOT be changed */ -# define PNG_FILLER_BEFORE 0 -# define PNG_FILLER_AFTER 1 -/* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */ -PNG_EXPORT(40, void, png_set_add_alpha, - (png_structp png_ptr, png_uint_32 filler, - int flags)); -#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */ - -#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) -/* Swap bytes in 16-bit depth files. */ -PNG_EXPORT(41, void, png_set_swap, (png_structp png_ptr)); -#endif - -#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) -/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */ -PNG_EXPORT(42, void, png_set_packing, (png_structp png_ptr)); -#endif - -#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \ - defined(PNG_WRITE_PACKSWAP_SUPPORTED) -/* Swap packing order of pixels in bytes. */ -PNG_EXPORT(43, void, png_set_packswap, (png_structp png_ptr)); -#endif - -#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) -/* Converts files to legal bit depths. */ -PNG_EXPORT(44, void, png_set_shift, (png_structp png_ptr, png_const_color_8p - true_bits)); -#endif - -#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ - defined(PNG_WRITE_INTERLACING_SUPPORTED) -/* Have the code handle the interlacing. Returns the number of passes. - * MUST be called before png_read_update_info or png_start_read_image, - * otherwise it will not have the desired effect. Note that it is still - * necessary to call png_read_row or png_read_rows png_get_image_height - * times for each pass. -*/ -PNG_EXPORT(45, int, png_set_interlace_handling, (png_structp png_ptr)); -#endif - -#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) -/* Invert monochrome files */ -PNG_EXPORT(46, void, png_set_invert_mono, (png_structp png_ptr)); -#endif - -#ifdef PNG_READ_BACKGROUND_SUPPORTED -/* Handle alpha and tRNS by replacing with a background color. Prior to - * libpng-1.5.4 this API must not be called before the PNG file header has been - * read. Doing so will result in unexpected behavior and possible warnings or - * errors if the PNG file contains a bKGD chunk. - */ -PNG_FP_EXPORT(47, void, png_set_background, (png_structp png_ptr, - png_const_color_16p background_color, int background_gamma_code, - int need_expand, double background_gamma)) -PNG_FIXED_EXPORT(215, void, png_set_background_fixed, (png_structp png_ptr, - png_const_color_16p background_color, int background_gamma_code, - int need_expand, png_fixed_point background_gamma)) -#endif -#ifdef PNG_READ_BACKGROUND_SUPPORTED -# define PNG_BACKGROUND_GAMMA_UNKNOWN 0 -# define PNG_BACKGROUND_GAMMA_SCREEN 1 -# define PNG_BACKGROUND_GAMMA_FILE 2 -# define PNG_BACKGROUND_GAMMA_UNIQUE 3 -#endif - -#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED -/* Scale a 16-bit depth file down to 8-bit, accurately. */ -PNG_EXPORT(229, void, png_set_scale_16, (png_structp png_ptr)); -#endif - -#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED -#define PNG_READ_16_TO_8 SUPPORTED /* Name prior to 1.5.4 */ -/* Strip the second byte of information from a 16-bit depth file. */ -PNG_EXPORT(48, void, png_set_strip_16, (png_structp png_ptr)); -#endif - -#ifdef PNG_READ_QUANTIZE_SUPPORTED -/* Turn on quantizing, and reduce the palette to the number of colors - * available. - */ -PNG_EXPORT(49, void, png_set_quantize, - (png_structp png_ptr, png_colorp palette, - int num_palette, int maximum_colors, png_const_uint_16p histogram, - int full_quantize)); -#endif - -#ifdef PNG_READ_GAMMA_SUPPORTED -/* The threshold on gamma processing is configurable but hard-wired into the - * library. The following is the floating point variant. - */ -#define PNG_GAMMA_THRESHOLD (PNG_GAMMA_THRESHOLD_FIXED*.00001) - -/* Handle gamma correction. Screen_gamma=(display_exponent). - * NOTE: this API simply sets the screen and file gamma values. It will - * therefore override the value for gamma in a PNG file if it is called after - * the file header has been read - use with care - call before reading the PNG - * file for best results! - * - * These routines accept the same gamma values as png_set_alpha_mode (described - * above). The PNG_GAMMA_ defines and PNG_DEFAULT_sRGB can be passed to either - * API (floating point or fixed.) Notice, however, that the 'file_gamma' value - * is the inverse of a 'screen gamma' value. - */ -PNG_FP_EXPORT(50, void, png_set_gamma, - (png_structp png_ptr, double screen_gamma, - double override_file_gamma)) -PNG_FIXED_EXPORT(208, void, png_set_gamma_fixed, (png_structp png_ptr, - png_fixed_point screen_gamma, png_fixed_point override_file_gamma)) -#endif - -#ifdef PNG_WRITE_FLUSH_SUPPORTED -/* Set how many lines between output flushes - 0 for no flushing */ -PNG_EXPORT(51, void, png_set_flush, (png_structp png_ptr, int nrows)); -/* Flush the current PNG output buffer */ -PNG_EXPORT(52, void, png_write_flush, (png_structp png_ptr)); -#endif - -/* Optional update palette with requested transformations */ -PNG_EXPORT(53, void, png_start_read_image, (png_structp png_ptr)); - -/* Optional call to update the users info structure */ -PNG_EXPORT(54, void, png_read_update_info, - (png_structp png_ptr, png_infop info_ptr)); - -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED -/* Read one or more rows of image data. */ -PNG_EXPORT(55, void, png_read_rows, (png_structp png_ptr, png_bytepp row, - png_bytepp display_row, png_uint_32 num_rows)); -#endif - -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED -/* Read a row of data. */ -PNG_EXPORT(56, void, png_read_row, (png_structp png_ptr, png_bytep row, - png_bytep display_row)); -#endif - -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED -/* Read the whole image into memory at once. */ -PNG_EXPORT(57, void, png_read_image, (png_structp png_ptr, png_bytepp image)); -#endif - -/* Write a row of image data */ -PNG_EXPORT(58, void, png_write_row, - (png_structp png_ptr, png_const_bytep row)); - -/* Write a few rows of image data: (*row) is not written; however, the type - * is declared as writeable to maintain compatibility with previous versions - * of libpng and to allow the 'display_row' array from read_rows to be passed - * unchanged to write_rows. - */ -PNG_EXPORT(59, void, png_write_rows, (png_structp png_ptr, png_bytepp row, - png_uint_32 num_rows)); - -/* Write the image data */ -PNG_EXPORT(60, void, png_write_image, - (png_structp png_ptr, png_bytepp image)); - -/* Write the end of the PNG file. */ -PNG_EXPORT(61, void, png_write_end, - (png_structp png_ptr, png_infop info_ptr)); - -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED -/* Read the end of the PNG file. */ -PNG_EXPORT(62, void, png_read_end, (png_structp png_ptr, png_infop info_ptr)); -#endif - -/* Free any memory associated with the png_info_struct */ -PNG_EXPORT(63, void, png_destroy_info_struct, (png_structp png_ptr, - png_infopp info_ptr_ptr)); - -/* Free any memory associated with the png_struct and the png_info_structs */ -PNG_EXPORT(64, void, png_destroy_read_struct, (png_structpp png_ptr_ptr, - png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr)); - -/* Free any memory associated with the png_struct and the png_info_structs */ -PNG_EXPORT(65, void, png_destroy_write_struct, (png_structpp png_ptr_ptr, - png_infopp info_ptr_ptr)); - -/* Set the libpng method of handling chunk CRC errors */ -PNG_EXPORT(66, void, png_set_crc_action, - (png_structp png_ptr, int crit_action, int ancil_action)); - -/* Values for png_set_crc_action() say how to handle CRC errors in - * ancillary and critical chunks, and whether to use the data contained - * therein. Note that it is impossible to "discard" data in a critical - * chunk. For versions prior to 0.90, the action was always error/quit, - * whereas in version 0.90 and later, the action for CRC errors in ancillary - * chunks is warn/discard. These values should NOT be changed. - * - * value action:critical action:ancillary - */ -#define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */ -#define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */ -#define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */ -#define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */ -#define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */ -#define PNG_CRC_NO_CHANGE 5 /* use current value use current value */ - -/* These functions give the user control over the scan-line filtering in - * libpng and the compression methods used by zlib. These functions are - * mainly useful for testing, as the defaults should work with most users. - * Those users who are tight on memory or want faster performance at the - * expense of compression can modify them. See the compression library - * header file (zlib.h) for an explination of the compression functions. - */ - -/* Set the filtering method(s) used by libpng. Currently, the only valid - * value for "method" is 0. - */ -PNG_EXPORT(67, void, png_set_filter, - (png_structp png_ptr, int method, int filters)); - -/* Flags for png_set_filter() to say which filters to use. The flags - * are chosen so that they don't conflict with real filter types - * below, in case they are supplied instead of the #defined constants. - * These values should NOT be changed. - */ -#define PNG_NO_FILTERS 0x00 -#define PNG_FILTER_NONE 0x08 -#define PNG_FILTER_SUB 0x10 -#define PNG_FILTER_UP 0x20 -#define PNG_FILTER_AVG 0x40 -#define PNG_FILTER_PAETH 0x80 -#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \ - PNG_FILTER_AVG | PNG_FILTER_PAETH) - -/* Filter values (not flags) - used in pngwrite.c, pngwutil.c for now. - * These defines should NOT be changed. - */ -#define PNG_FILTER_VALUE_NONE 0 -#define PNG_FILTER_VALUE_SUB 1 -#define PNG_FILTER_VALUE_UP 2 -#define PNG_FILTER_VALUE_AVG 3 -#define PNG_FILTER_VALUE_PAETH 4 -#define PNG_FILTER_VALUE_LAST 5 - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* EXPERIMENTAL */ -/* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_ - * defines, either the default (minimum-sum-of-absolute-differences), or - * the experimental method (weighted-minimum-sum-of-absolute-differences). - * - * Weights are factors >= 1.0, indicating how important it is to keep the - * filter type consistent between rows. Larger numbers mean the current - * filter is that many times as likely to be the same as the "num_weights" - * previous filters. This is cumulative for each previous row with a weight. - * There needs to be "num_weights" values in "filter_weights", or it can be - * NULL if the weights aren't being specified. Weights have no influence on - * the selection of the first row filter. Well chosen weights can (in theory) - * improve the compression for a given image. - * - * Costs are factors >= 1.0 indicating the relative decoding costs of a - * filter type. Higher costs indicate more decoding expense, and are - * therefore less likely to be selected over a filter with lower computational - * costs. There needs to be a value in "filter_costs" for each valid filter - * type (given by PNG_FILTER_VALUE_LAST), or it can be NULL if you aren't - * setting the costs. Costs try to improve the speed of decompression without - * unduly increasing the compressed image size. - * - * A negative weight or cost indicates the default value is to be used, and - * values in the range [0.0, 1.0) indicate the value is to remain unchanged. - * The default values for both weights and costs are currently 1.0, but may - * change if good general weighting/cost heuristics can be found. If both - * the weights and costs are set to 1.0, this degenerates the WEIGHTED method - * to the UNWEIGHTED method, but with added encoding time/computation. - */ -PNG_FP_EXPORT(68, void, png_set_filter_heuristics, (png_structp png_ptr, - int heuristic_method, int num_weights, png_const_doublep filter_weights, - png_const_doublep filter_costs)) -PNG_FIXED_EXPORT(209, void, png_set_filter_heuristics_fixed, - (png_structp png_ptr, - int heuristic_method, int num_weights, png_const_fixed_point_p - filter_weights, png_const_fixed_point_p filter_costs)) -#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ - -/* Heuristic used for row filter selection. These defines should NOT be - * changed. - */ -#define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */ -#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */ -#define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */ -#define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */ - -#ifdef PNG_WRITE_SUPPORTED -/* Set the library compression level. Currently, valid values range from - * 0 - 9, corresponding directly to the zlib compression levels 0 - 9 - * (0 - no compression, 9 - "maximal" compression). Note that tests have - * shown that zlib compression levels 3-6 usually perform as well as level 9 - * for PNG images, and do considerably fewer caclulations. In the future, - * these values may not correspond directly to the zlib compression levels. - */ -PNG_EXPORT(69, void, png_set_compression_level, - (png_structp png_ptr, int level)); - -PNG_EXPORT(70, void, png_set_compression_mem_level, (png_structp png_ptr, - int mem_level)); - -PNG_EXPORT(71, void, png_set_compression_strategy, (png_structp png_ptr, - int strategy)); - -/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a - * smaller value of window_bits if it can do so safely. - */ -PNG_EXPORT(72, void, png_set_compression_window_bits, (png_structp png_ptr, - int window_bits)); - -PNG_EXPORT(73, void, png_set_compression_method, (png_structp png_ptr, - int method)); -#endif - -#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED -/* Also set zlib parameters for compressing non-IDAT chunks */ -PNG_EXPORT(222, void, png_set_text_compression_level, - (png_structp png_ptr, int level)); - -PNG_EXPORT(223, void, png_set_text_compression_mem_level, (png_structp png_ptr, - int mem_level)); - -PNG_EXPORT(224, void, png_set_text_compression_strategy, (png_structp png_ptr, - int strategy)); - -/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a - * smaller value of window_bits if it can do so safely. - */ -PNG_EXPORT(225, void, png_set_text_compression_window_bits, (png_structp - png_ptr, int window_bits)); - -PNG_EXPORT(226, void, png_set_text_compression_method, (png_structp png_ptr, - int method)); -#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */ - -/* These next functions are called for input/output, memory, and error - * handling. They are in the file pngrio.c, pngwio.c, and pngerror.c, - * and call standard C I/O routines such as fread(), fwrite(), and - * fprintf(). These functions can be made to use other I/O routines - * at run time for those applications that need to handle I/O in a - * different manner by calling png_set_???_fn(). See libpng-manual.txt for - * more information. - */ - -#ifdef PNG_STDIO_SUPPORTED -/* Initialize the input/output for the PNG file to the default functions. */ -PNG_EXPORT(74, void, png_init_io, (png_structp png_ptr, png_FILE_p fp)); -#endif - -/* Replace the (error and abort), and warning functions with user - * supplied functions. If no messages are to be printed you must still - * write and use replacement functions. The replacement error_fn should - * still do a longjmp to the last setjmp location if you are using this - * method of error handling. If error_fn or warning_fn is NULL, the - * default function will be used. - */ - -PNG_EXPORT(75, void, png_set_error_fn, - (png_structp png_ptr, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warning_fn)); - -/* Return the user pointer associated with the error functions */ -PNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_const_structp png_ptr)); - -/* Replace the default data output functions with a user supplied one(s). - * If buffered output is not used, then output_flush_fn can be set to NULL. - * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time - * output_flush_fn will be ignored (and thus can be NULL). - * It is probably a mistake to use NULL for output_flush_fn if - * write_data_fn is not also NULL unless you have built libpng with - * PNG_WRITE_FLUSH_SUPPORTED undefined, because in this case libpng's - * default flush function, which uses the standard *FILE structure, will - * be used. - */ -PNG_EXPORT(77, void, png_set_write_fn, (png_structp png_ptr, png_voidp io_ptr, - png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)); - -/* Replace the default data input function with a user supplied one. */ -PNG_EXPORT(78, void, png_set_read_fn, (png_structp png_ptr, png_voidp io_ptr, - png_rw_ptr read_data_fn)); - -/* Return the user pointer associated with the I/O functions */ -PNG_EXPORT(79, png_voidp, png_get_io_ptr, (png_structp png_ptr)); - -PNG_EXPORT(80, void, png_set_read_status_fn, (png_structp png_ptr, - png_read_status_ptr read_row_fn)); - -PNG_EXPORT(81, void, png_set_write_status_fn, (png_structp png_ptr, - png_write_status_ptr write_row_fn)); - -#ifdef PNG_USER_MEM_SUPPORTED -/* Replace the default memory allocation functions with user supplied one(s). */ -PNG_EXPORT(82, void, png_set_mem_fn, (png_structp png_ptr, png_voidp mem_ptr, - png_malloc_ptr malloc_fn, png_free_ptr free_fn)); -/* Return the user pointer associated with the memory functions */ -PNG_EXPORT(83, png_voidp, png_get_mem_ptr, (png_const_structp png_ptr)); -#endif - -#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED -PNG_EXPORT(84, void, png_set_read_user_transform_fn, (png_structp png_ptr, - png_user_transform_ptr read_user_transform_fn)); -#endif - -#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED -PNG_EXPORT(85, void, png_set_write_user_transform_fn, (png_structp png_ptr, - png_user_transform_ptr write_user_transform_fn)); -#endif - -#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED -PNG_EXPORT(86, void, png_set_user_transform_info, (png_structp png_ptr, - png_voidp user_transform_ptr, int user_transform_depth, - int user_transform_channels)); -/* Return the user pointer associated with the user transform functions */ -PNG_EXPORT(87, png_voidp, png_get_user_transform_ptr, - (png_const_structp png_ptr)); -#endif - -#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED -/* Return information about the row currently being processed. Note that these - * APIs do not fail but will return unexpected results if called outside a user - * transform callback. Also note that when transforming an interlaced image the - * row number is the row number within the sub-image of the interlace pass, so - * the value will increase to the height of the sub-image (not the full image) - * then reset to 0 for the next pass. - * - * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to - * find the output pixel (x,y) given an interlaced sub-image pixel - * (row,col,pass). (See below for these macros.) - */ -PNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structp)); -PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structp)); -#endif - -#ifdef PNG_USER_CHUNKS_SUPPORTED -PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structp png_ptr, - png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn)); -PNG_EXPORT(89, png_voidp, png_get_user_chunk_ptr, (png_const_structp png_ptr)); -#endif - -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED -/* Sets the function callbacks for the push reader, and a pointer to a - * user-defined structure available to the callback functions. - */ -PNG_EXPORT(90, void, png_set_progressive_read_fn, (png_structp png_ptr, - png_voidp progressive_ptr, png_progressive_info_ptr info_fn, - png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn)); - -/* Returns the user pointer associated with the push read functions */ -PNG_EXPORT(91, png_voidp, png_get_progressive_ptr, (png_const_structp png_ptr)); - -/* Function to be called when data becomes available */ -PNG_EXPORT(92, void, png_process_data, - (png_structp png_ptr, png_infop info_ptr, - png_bytep buffer, png_size_t buffer_size)); - -/* A function which may be called *only* within png_process_data to stop the - * processing of any more data. The function returns the number of bytes - * remaining, excluding any that libpng has cached internally. A subsequent - * call to png_process_data must supply these bytes again. If the argument - * 'save' is set to true the routine will first save all the pending data and - * will always return 0. - */ -PNG_EXPORT(219, png_size_t, png_process_data_pause, (png_structp, int save)); - -/* A function which may be called *only* outside (after) a call to - * png_process_data. It returns the number of bytes of data to skip in the - * input. Normally it will return 0, but if it returns a non-zero value the - * application must skip than number of bytes of input data and pass the - * following data to the next call to png_process_data. - */ -PNG_EXPORT(220, png_uint_32, png_process_data_skip, (png_structp)); - -#ifdef PNG_READ_INTERLACING_SUPPORTED -/* Function that combines rows. 'new_row' is a flag that should come from - * the callback and be non-NULL if anything needs to be done; the library - * stores its own version of the new data internally and ignores the passed - * in value. - */ -PNG_EXPORT(93, void, png_progressive_combine_row, (png_structp png_ptr, - png_bytep old_row, png_const_bytep new_row)); -#endif /* PNG_READ_INTERLACING_SUPPORTED */ -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ - -PNG_EXPORTA(94, png_voidp, png_malloc, - (png_structp png_ptr, png_alloc_size_t size), - PNG_ALLOCATED); -/* Added at libpng version 1.4.0 */ -PNG_EXPORTA(95, png_voidp, png_calloc, - (png_structp png_ptr, png_alloc_size_t size), - PNG_ALLOCATED); - -/* Added at libpng version 1.2.4 */ -PNG_EXPORTA(96, png_voidp, png_malloc_warn, (png_structp png_ptr, - png_alloc_size_t size), PNG_ALLOCATED); - -/* Frees a pointer allocated by png_malloc() */ -PNG_EXPORT(97, void, png_free, (png_structp png_ptr, png_voidp ptr)); - -/* Free data that was allocated internally */ -PNG_EXPORT(98, void, png_free_data, - (png_structp png_ptr, png_infop info_ptr, png_uint_32 free_me, int num)); - -/* Reassign responsibility for freeing existing data, whether allocated - * by libpng or by the application */ -PNG_EXPORT(99, void, png_data_freer, - (png_structp png_ptr, png_infop info_ptr, int freer, png_uint_32 mask)); - -/* Assignments for png_data_freer */ -#define PNG_DESTROY_WILL_FREE_DATA 1 -#define PNG_SET_WILL_FREE_DATA 1 -#define PNG_USER_WILL_FREE_DATA 2 -/* Flags for png_ptr->free_me and info_ptr->free_me */ -#define PNG_FREE_HIST 0x0008 -#define PNG_FREE_ICCP 0x0010 -#define PNG_FREE_SPLT 0x0020 -#define PNG_FREE_ROWS 0x0040 -#define PNG_FREE_PCAL 0x0080 -#define PNG_FREE_SCAL 0x0100 -#define PNG_FREE_UNKN 0x0200 -#define PNG_FREE_LIST 0x0400 -#define PNG_FREE_PLTE 0x1000 -#define PNG_FREE_TRNS 0x2000 -#define PNG_FREE_TEXT 0x4000 -#define PNG_FREE_ALL 0x7fff -#define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */ - -#ifdef PNG_USER_MEM_SUPPORTED -PNG_EXPORTA(100, png_voidp, png_malloc_default, (png_structp png_ptr, - png_alloc_size_t size), PNG_ALLOCATED); -PNG_EXPORT(101, void, png_free_default, (png_structp png_ptr, png_voidp ptr)); -#endif - -#ifdef PNG_ERROR_TEXT_SUPPORTED -/* Fatal error in PNG image of libpng - can't continue */ -PNG_EXPORTA(102, void, png_error, - (png_structp png_ptr, png_const_charp error_message), - PNG_NORETURN); - -/* The same, but the chunk name is prepended to the error string. */ -PNG_EXPORTA(103, void, png_chunk_error, (png_structp png_ptr, - png_const_charp error_message), PNG_NORETURN); - -#else -/* Fatal error in PNG image of libpng - can't continue */ -PNG_EXPORTA(104, void, png_err, (png_structp png_ptr), PNG_NORETURN); -#endif - -#ifdef PNG_WARNINGS_SUPPORTED -/* Non-fatal error in libpng. Can continue, but may have a problem. */ -PNG_EXPORT(105, void, png_warning, (png_structp png_ptr, - png_const_charp warning_message)); - -/* Non-fatal error in libpng, chunk name is prepended to message. */ -PNG_EXPORT(106, void, png_chunk_warning, (png_structp png_ptr, - png_const_charp warning_message)); -#endif - -#ifdef PNG_BENIGN_ERRORS_SUPPORTED -/* Benign error in libpng. Can continue, but may have a problem. - * User can choose whether to handle as a fatal error or as a warning. */ -# undef png_benign_error -PNG_EXPORT(107, void, png_benign_error, (png_structp png_ptr, - png_const_charp warning_message)); - -/* Same, chunk name is prepended to message. */ -# undef png_chunk_benign_error -PNG_EXPORT(108, void, png_chunk_benign_error, (png_structp png_ptr, - png_const_charp warning_message)); - -PNG_EXPORT(109, void, png_set_benign_errors, - (png_structp png_ptr, int allowed)); -#else -# ifdef PNG_ALLOW_BENIGN_ERRORS -# define png_benign_error png_warning -# define png_chunk_benign_error png_chunk_warning -# else -# define png_benign_error png_error -# define png_chunk_benign_error png_chunk_error -# endif -#endif - -/* The png_set_ functions are for storing values in the png_info_struct. - * Similarly, the png_get_ calls are used to read values from the - * png_info_struct, either storing the parameters in the passed variables, or - * setting pointers into the png_info_struct where the data is stored. The - * png_get_ functions return a non-zero value if the data was available - * in info_ptr, or return zero and do not change any of the parameters if the - * data was not available. - * - * These functions should be used instead of directly accessing png_info - * to avoid problems with future changes in the size and internal layout of - * png_info_struct. - */ -/* Returns "flag" if chunk data is valid in info_ptr. */ -PNG_EXPORT(110, png_uint_32, png_get_valid, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_uint_32 flag)); - -/* Returns number of bytes needed to hold a transformed row. */ -PNG_EXPORT(111, png_size_t, png_get_rowbytes, (png_const_structp png_ptr, - png_const_infop info_ptr)); - -#ifdef PNG_INFO_IMAGE_SUPPORTED -/* Returns row_pointers, which is an array of pointers to scanlines that was - * returned from png_read_png(). - */ -PNG_EXPORT(112, png_bytepp, png_get_rows, - (png_const_structp png_ptr, png_const_infop info_ptr)); -/* Set row_pointers, which is an array of pointers to scanlines for use - * by png_write_png(). - */ -PNG_EXPORT(113, void, png_set_rows, (png_structp png_ptr, - png_infop info_ptr, png_bytepp row_pointers)); -#endif - -/* Returns number of color channels in image. */ -PNG_EXPORT(114, png_byte, png_get_channels, - (png_const_structp png_ptr, png_const_infop info_ptr)); - -#ifdef PNG_EASY_ACCESS_SUPPORTED -/* Returns image width in pixels. */ -PNG_EXPORT(115, png_uint_32, png_get_image_width, (png_const_structp png_ptr, - png_const_infop info_ptr)); - -/* Returns image height in pixels. */ -PNG_EXPORT(116, png_uint_32, png_get_image_height, (png_const_structp png_ptr, - png_const_infop info_ptr)); - -/* Returns image bit_depth. */ -PNG_EXPORT(117, png_byte, png_get_bit_depth, - (png_const_structp png_ptr, png_const_infop info_ptr)); - -/* Returns image color_type. */ -PNG_EXPORT(118, png_byte, png_get_color_type, (png_const_structp png_ptr, - png_const_infop info_ptr)); - -/* Returns image filter_type. */ -PNG_EXPORT(119, png_byte, png_get_filter_type, (png_const_structp png_ptr, - png_const_infop info_ptr)); - -/* Returns image interlace_type. */ -PNG_EXPORT(120, png_byte, png_get_interlace_type, (png_const_structp png_ptr, - png_const_infop info_ptr)); - -/* Returns image compression_type. */ -PNG_EXPORT(121, png_byte, png_get_compression_type, (png_const_structp png_ptr, - png_const_infop info_ptr)); - -/* Returns image resolution in pixels per meter, from pHYs chunk data. */ -PNG_EXPORT(122, png_uint_32, png_get_pixels_per_meter, - (png_const_structp png_ptr, png_const_infop info_ptr)); -PNG_EXPORT(123, png_uint_32, png_get_x_pixels_per_meter, - (png_const_structp png_ptr, png_const_infop info_ptr)); -PNG_EXPORT(124, png_uint_32, png_get_y_pixels_per_meter, - (png_const_structp png_ptr, png_const_infop info_ptr)); - -/* Returns pixel aspect ratio, computed from pHYs chunk data. */ -PNG_FP_EXPORT(125, float, png_get_pixel_aspect_ratio, - (png_const_structp png_ptr, png_const_infop info_ptr)) -PNG_FIXED_EXPORT(210, png_fixed_point, png_get_pixel_aspect_ratio_fixed, - (png_const_structp png_ptr, png_const_infop info_ptr)) - -/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */ -PNG_EXPORT(126, png_int_32, png_get_x_offset_pixels, - (png_const_structp png_ptr, png_const_infop info_ptr)); -PNG_EXPORT(127, png_int_32, png_get_y_offset_pixels, - (png_const_structp png_ptr, png_const_infop info_ptr)); -PNG_EXPORT(128, png_int_32, png_get_x_offset_microns, - (png_const_structp png_ptr, png_const_infop info_ptr)); -PNG_EXPORT(129, png_int_32, png_get_y_offset_microns, - (png_const_structp png_ptr, png_const_infop info_ptr)); - -#endif /* PNG_EASY_ACCESS_SUPPORTED */ - -/* Returns pointer to signature string read from PNG header */ -PNG_EXPORT(130, png_const_bytep, png_get_signature, - (png_const_structp png_ptr, png_infop info_ptr)); - -#ifdef PNG_bKGD_SUPPORTED -PNG_EXPORT(131, png_uint_32, png_get_bKGD, - (png_const_structp png_ptr, png_infop info_ptr, - png_color_16p *background)); -#endif - -#ifdef PNG_bKGD_SUPPORTED -PNG_EXPORT(132, void, png_set_bKGD, (png_structp png_ptr, png_infop info_ptr, - png_const_color_16p background)); -#endif - -#ifdef PNG_cHRM_SUPPORTED -PNG_FP_EXPORT(133, png_uint_32, png_get_cHRM, (png_const_structp png_ptr, - png_const_infop info_ptr, double *white_x, double *white_y, double *red_x, - double *red_y, double *green_x, double *green_y, double *blue_x, - double *blue_y)) -PNG_FP_EXPORT(230, png_uint_32, png_get_cHRM_XYZ, (png_structp png_ptr, - png_const_infop info_ptr, double *red_X, double *red_Y, double *red_Z, - double *green_X, double *green_Y, double *green_Z, double *blue_X, - double *blue_Y, double *blue_Z)) -#ifdef PNG_FIXED_POINT_SUPPORTED /* Otherwise not implemented */ -PNG_FIXED_EXPORT(134, png_uint_32, png_get_cHRM_fixed, - (png_const_structp png_ptr, - png_const_infop info_ptr, png_fixed_point *int_white_x, - png_fixed_point *int_white_y, png_fixed_point *int_red_x, - png_fixed_point *int_red_y, png_fixed_point *int_green_x, - png_fixed_point *int_green_y, png_fixed_point *int_blue_x, - png_fixed_point *int_blue_y)) -#endif -PNG_FIXED_EXPORT(231, png_uint_32, png_get_cHRM_XYZ_fixed, - (png_structp png_ptr, png_const_infop info_ptr, - png_fixed_point *int_red_X, png_fixed_point *int_red_Y, - png_fixed_point *int_red_Z, png_fixed_point *int_green_X, - png_fixed_point *int_green_Y, png_fixed_point *int_green_Z, - png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y, - png_fixed_point *int_blue_Z)) -#endif - -#ifdef PNG_cHRM_SUPPORTED -PNG_FP_EXPORT(135, void, png_set_cHRM, - (png_structp png_ptr, png_infop info_ptr, - double white_x, double white_y, double red_x, double red_y, double green_x, - double green_y, double blue_x, double blue_y)) -PNG_FP_EXPORT(232, void, png_set_cHRM_XYZ, (png_structp png_ptr, - png_infop info_ptr, double red_X, double red_Y, double red_Z, - double green_X, double green_Y, double green_Z, double blue_X, - double blue_Y, double blue_Z)) -PNG_FIXED_EXPORT(136, void, png_set_cHRM_fixed, (png_structp png_ptr, - png_infop info_ptr, png_fixed_point int_white_x, - png_fixed_point int_white_y, png_fixed_point int_red_x, - png_fixed_point int_red_y, png_fixed_point int_green_x, - png_fixed_point int_green_y, png_fixed_point int_blue_x, - png_fixed_point int_blue_y)) -PNG_FIXED_EXPORT(233, void, png_set_cHRM_XYZ_fixed, (png_structp png_ptr, - png_infop info_ptr, png_fixed_point int_red_X, png_fixed_point int_red_Y, - png_fixed_point int_red_Z, png_fixed_point int_green_X, - png_fixed_point int_green_Y, png_fixed_point int_green_Z, - png_fixed_point int_blue_X, png_fixed_point int_blue_Y, - png_fixed_point int_blue_Z)) -#endif - -#ifdef PNG_gAMA_SUPPORTED -PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, - (png_const_structp png_ptr, png_const_infop info_ptr, - double *file_gamma)) -PNG_FIXED_EXPORT(138, png_uint_32, png_get_gAMA_fixed, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_fixed_point *int_file_gamma)) -#endif - -#ifdef PNG_gAMA_SUPPORTED -PNG_FP_EXPORT(139, void, png_set_gAMA, (png_structp png_ptr, - png_infop info_ptr, double file_gamma)) -PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_structp png_ptr, - png_infop info_ptr, png_fixed_point int_file_gamma)) -#endif - -#ifdef PNG_hIST_SUPPORTED -PNG_EXPORT(141, png_uint_32, png_get_hIST, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_uint_16p *hist)); -#endif - -#ifdef PNG_hIST_SUPPORTED -PNG_EXPORT(142, void, png_set_hIST, (png_structp png_ptr, - png_infop info_ptr, png_const_uint_16p hist)); -#endif - -PNG_EXPORT(143, png_uint_32, png_get_IHDR, - (png_structp png_ptr, png_infop info_ptr, - png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, - int *interlace_method, int *compression_method, int *filter_method)); - -PNG_EXPORT(144, void, png_set_IHDR, - (png_structp png_ptr, png_infop info_ptr, - png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, - int interlace_method, int compression_method, int filter_method)); - -#ifdef PNG_oFFs_SUPPORTED -PNG_EXPORT(145, png_uint_32, png_get_oFFs, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)); -#endif - -#ifdef PNG_oFFs_SUPPORTED -PNG_EXPORT(146, void, png_set_oFFs, - (png_structp png_ptr, png_infop info_ptr, - png_int_32 offset_x, png_int_32 offset_y, int unit_type)); -#endif - -#ifdef PNG_pCAL_SUPPORTED -PNG_EXPORT(147, png_uint_32, png_get_pCAL, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, - int *nparams, - png_charp *units, png_charpp *params)); -#endif - -#ifdef PNG_pCAL_SUPPORTED -PNG_EXPORT(148, void, png_set_pCAL, (png_structp png_ptr, - png_infop info_ptr, - png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, - int nparams, png_const_charp units, png_charpp params)); -#endif - -#ifdef PNG_pHYs_SUPPORTED -PNG_EXPORT(149, png_uint_32, png_get_pHYs, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); -#endif - -#ifdef PNG_pHYs_SUPPORTED -PNG_EXPORT(150, void, png_set_pHYs, - (png_structp png_ptr, png_infop info_ptr, - png_uint_32 res_x, png_uint_32 res_y, int unit_type)); -#endif - -PNG_EXPORT(151, png_uint_32, png_get_PLTE, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_colorp *palette, int *num_palette)); - -PNG_EXPORT(152, void, png_set_PLTE, - (png_structp png_ptr, png_infop info_ptr, - png_const_colorp palette, int num_palette)); - -#ifdef PNG_sBIT_SUPPORTED -PNG_EXPORT(153, png_uint_32, png_get_sBIT, - (png_const_structp png_ptr, png_infop info_ptr, - png_color_8p *sig_bit)); -#endif - -#ifdef PNG_sBIT_SUPPORTED -PNG_EXPORT(154, void, png_set_sBIT, - (png_structp png_ptr, png_infop info_ptr, png_const_color_8p sig_bit)); -#endif - -#ifdef PNG_sRGB_SUPPORTED -PNG_EXPORT(155, png_uint_32, png_get_sRGB, (png_const_structp png_ptr, - png_const_infop info_ptr, int *file_srgb_intent)); -#endif - -#ifdef PNG_sRGB_SUPPORTED -PNG_EXPORT(156, void, png_set_sRGB, - (png_structp png_ptr, png_infop info_ptr, int srgb_intent)); -PNG_EXPORT(157, void, png_set_sRGB_gAMA_and_cHRM, (png_structp png_ptr, - png_infop info_ptr, int srgb_intent)); -#endif - -#ifdef PNG_iCCP_SUPPORTED -PNG_EXPORT(158, png_uint_32, png_get_iCCP, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_charpp name, int *compression_type, png_bytepp profile, - png_uint_32 *proflen)); -#endif - -#ifdef PNG_iCCP_SUPPORTED -PNG_EXPORT(159, void, png_set_iCCP, - (png_structp png_ptr, png_infop info_ptr, - png_const_charp name, int compression_type, png_const_bytep profile, - png_uint_32 proflen)); -#endif - -#ifdef PNG_sPLT_SUPPORTED -PNG_EXPORT(160, png_uint_32, png_get_sPLT, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_sPLT_tpp entries)); -#endif - -#ifdef PNG_sPLT_SUPPORTED -PNG_EXPORT(161, void, png_set_sPLT, - (png_structp png_ptr, png_infop info_ptr, - png_const_sPLT_tp entries, int nentries)); -#endif - -#ifdef PNG_TEXT_SUPPORTED -/* png_get_text also returns the number of text chunks in *num_text */ -PNG_EXPORT(162, png_uint_32, png_get_text, - (png_const_structp png_ptr, png_const_infop info_ptr, - png_textp *text_ptr, int *num_text)); -#endif - -/* Note while png_set_text() will accept a structure whose text, - * language, and translated keywords are NULL pointers, the structure - * returned by png_get_text will always contain regular - * zero-terminated C strings. They might be empty strings but - * they will never be NULL pointers. - */ - -#ifdef PNG_TEXT_SUPPORTED -PNG_EXPORT(163, void, png_set_text, - (png_structp png_ptr, png_infop info_ptr, - png_const_textp text_ptr, int num_text)); -#endif - -#ifdef PNG_tIME_SUPPORTED -PNG_EXPORT(164, png_uint_32, png_get_tIME, - (png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time)); -#endif - -#ifdef PNG_tIME_SUPPORTED -PNG_EXPORT(165, void, png_set_tIME, - (png_structp png_ptr, png_infop info_ptr, png_const_timep mod_time)); -#endif - -#ifdef PNG_tRNS_SUPPORTED -PNG_EXPORT(166, png_uint_32, png_get_tRNS, - (png_const_structp png_ptr, png_infop info_ptr, - png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)); -#endif - -#ifdef PNG_tRNS_SUPPORTED -PNG_EXPORT(167, void, png_set_tRNS, - (png_structp png_ptr, png_infop info_ptr, - png_const_bytep trans_alpha, int num_trans, - png_const_color_16p trans_color)); -#endif - -#ifdef PNG_sCAL_SUPPORTED -PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, - (png_const_structp png_ptr, png_const_infop info_ptr, - int *unit, double *width, double *height)) -#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED -/* NOTE: this API is currently implemented using floating point arithmetic, - * consequently it can only be used on systems with floating point support. - * In any case the range of values supported by png_fixed_point is small and it - * is highly recommended that png_get_sCAL_s be used instead. - */ -PNG_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed, - (png_structp png_ptr, png_const_infop info_ptr, int *unit, - png_fixed_point *width, - png_fixed_point *height)) -#endif -PNG_EXPORT(169, png_uint_32, png_get_sCAL_s, - (png_const_structp png_ptr, png_const_infop info_ptr, - int *unit, png_charpp swidth, png_charpp sheight)); - -PNG_FP_EXPORT(170, void, png_set_sCAL, - (png_structp png_ptr, png_infop info_ptr, - int unit, double width, double height)) -PNG_FIXED_EXPORT(213, void, png_set_sCAL_fixed, (png_structp png_ptr, - png_infop info_ptr, int unit, png_fixed_point width, - png_fixed_point height)) -PNG_EXPORT(171, void, png_set_sCAL_s, - (png_structp png_ptr, png_infop info_ptr, - int unit, png_const_charp swidth, png_const_charp sheight)); -#endif /* PNG_sCAL_SUPPORTED */ - -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED -/* Provide a list of chunks and how they are to be handled, if the built-in - handling or default unknown chunk handling is not desired. Any chunks not - listed will be handled in the default manner. The IHDR and IEND chunks - must not be listed. Because this turns off the default handling for chunks - that would otherwise be recognized the behavior of libpng transformations may - well become incorrect! - keep = 0: PNG_HANDLE_CHUNK_AS_DEFAULT: follow default behavior - = 1: PNG_HANDLE_CHUNK_NEVER: do not keep - = 2: PNG_HANDLE_CHUNK_IF_SAFE: keep only if safe-to-copy - = 3: PNG_HANDLE_CHUNK_ALWAYS: keep even if unsafe-to-copy -*/ -PNG_EXPORT(172, void, png_set_keep_unknown_chunks, - (png_structp png_ptr, int keep, - png_const_bytep chunk_list, int num_chunks)); - -/* The handling code is returned; the result is therefore true (non-zero) if - * special handling is required, false for the default handling. - */ -PNG_EXPORT(173, int, png_handle_as_unknown, (png_structp png_ptr, - png_const_bytep chunk_name)); -#endif -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED -PNG_EXPORT(174, void, png_set_unknown_chunks, (png_structp png_ptr, - png_infop info_ptr, png_const_unknown_chunkp unknowns, - int num_unknowns)); -PNG_EXPORT(175, void, png_set_unknown_chunk_location, - (png_structp png_ptr, png_infop info_ptr, int chunk, int location)); -PNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structp png_ptr, - png_const_infop info_ptr, png_unknown_chunkpp entries)); -#endif - -/* Png_free_data() will turn off the "valid" flag for anything it frees. - * If you need to turn it off for a chunk that your application has freed, - * you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK); - */ -PNG_EXPORT(177, void, png_set_invalid, - (png_structp png_ptr, png_infop info_ptr, int mask)); - -#ifdef PNG_INFO_IMAGE_SUPPORTED -/* The "params" pointer is currently not used and is for future expansion. */ -PNG_EXPORT(178, void, png_read_png, (png_structp png_ptr, png_infop info_ptr, - int transforms, png_voidp params)); -PNG_EXPORT(179, void, png_write_png, (png_structp png_ptr, png_infop info_ptr, - int transforms, png_voidp params)); -#endif - -PNG_EXPORT(180, png_const_charp, png_get_copyright, - (png_const_structp png_ptr)); -PNG_EXPORT(181, png_const_charp, png_get_header_ver, - (png_const_structp png_ptr)); -PNG_EXPORT(182, png_const_charp, png_get_header_version, - (png_const_structp png_ptr)); -PNG_EXPORT(183, png_const_charp, png_get_libpng_ver, - (png_const_structp png_ptr)); - -#ifdef PNG_MNG_FEATURES_SUPPORTED -PNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structp png_ptr, - png_uint_32 mng_features_permitted)); -#endif - -/* For use in png_set_keep_unknown, added to version 1.2.6 */ -#define PNG_HANDLE_CHUNK_AS_DEFAULT 0 -#define PNG_HANDLE_CHUNK_NEVER 1 -#define PNG_HANDLE_CHUNK_IF_SAFE 2 -#define PNG_HANDLE_CHUNK_ALWAYS 3 - -/* Strip the prepended error numbers ("#nnn ") from error and warning - * messages before passing them to the error or warning handler. - */ -#ifdef PNG_ERROR_NUMBERS_SUPPORTED -PNG_EXPORT(185, void, png_set_strip_error_numbers, - (png_structp png_ptr, - png_uint_32 strip_mode)); -#endif - -/* Added in libpng-1.2.6 */ -#ifdef PNG_SET_USER_LIMITS_SUPPORTED -PNG_EXPORT(186, void, png_set_user_limits, (png_structp png_ptr, - png_uint_32 user_width_max, png_uint_32 user_height_max)); -PNG_EXPORT(187, png_uint_32, png_get_user_width_max, - (png_const_structp png_ptr)); -PNG_EXPORT(188, png_uint_32, png_get_user_height_max, - (png_const_structp png_ptr)); -/* Added in libpng-1.4.0 */ -PNG_EXPORT(189, void, png_set_chunk_cache_max, (png_structp png_ptr, - png_uint_32 user_chunk_cache_max)); -PNG_EXPORT(190, png_uint_32, png_get_chunk_cache_max, - (png_const_structp png_ptr)); -/* Added in libpng-1.4.1 */ -PNG_EXPORT(191, void, png_set_chunk_malloc_max, (png_structp png_ptr, - png_alloc_size_t user_chunk_cache_max)); -PNG_EXPORT(192, png_alloc_size_t, png_get_chunk_malloc_max, - (png_const_structp png_ptr)); -#endif - -#if defined(PNG_INCH_CONVERSIONS_SUPPORTED) -PNG_EXPORT(193, png_uint_32, png_get_pixels_per_inch, - (png_const_structp png_ptr, png_const_infop info_ptr)); - -PNG_EXPORT(194, png_uint_32, png_get_x_pixels_per_inch, - (png_const_structp png_ptr, png_const_infop info_ptr)); - -PNG_EXPORT(195, png_uint_32, png_get_y_pixels_per_inch, - (png_const_structp png_ptr, png_const_infop info_ptr)); - -PNG_FP_EXPORT(196, float, png_get_x_offset_inches, - (png_const_structp png_ptr, png_const_infop info_ptr)) -#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */ -PNG_FIXED_EXPORT(211, png_fixed_point, png_get_x_offset_inches_fixed, - (png_structp png_ptr, png_const_infop info_ptr)) -#endif - -PNG_FP_EXPORT(197, float, png_get_y_offset_inches, (png_const_structp png_ptr, - png_const_infop info_ptr)) -#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */ -PNG_FIXED_EXPORT(212, png_fixed_point, png_get_y_offset_inches_fixed, - (png_structp png_ptr, png_const_infop info_ptr)) -#endif - -# ifdef PNG_pHYs_SUPPORTED -PNG_EXPORT(198, png_uint_32, png_get_pHYs_dpi, (png_const_structp png_ptr, - png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, - int *unit_type)); -# endif /* PNG_pHYs_SUPPORTED */ -#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */ - -/* Added in libpng-1.4.0 */ -#ifdef PNG_IO_STATE_SUPPORTED -PNG_EXPORT(199, png_uint_32, png_get_io_state, (png_structp png_ptr)); - -PNG_EXPORTA(200, png_const_bytep, png_get_io_chunk_name, - (png_structp png_ptr), PNG_DEPRECATED); -PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type, - (png_const_structp png_ptr)); - -/* The flags returned by png_get_io_state() are the following: */ -# define PNG_IO_NONE 0x0000 /* no I/O at this moment */ -# define PNG_IO_READING 0x0001 /* currently reading */ -# define PNG_IO_WRITING 0x0002 /* currently writing */ -# define PNG_IO_SIGNATURE 0x0010 /* currently at the file signature */ -# define PNG_IO_CHUNK_HDR 0x0020 /* currently at the chunk header */ -# define PNG_IO_CHUNK_DATA 0x0040 /* currently at the chunk data */ -# define PNG_IO_CHUNK_CRC 0x0080 /* currently at the chunk crc */ -# define PNG_IO_MASK_OP 0x000f /* current operation: reading/writing */ -# define PNG_IO_MASK_LOC 0x00f0 /* current location: sig/hdr/data/crc */ -#endif /* ?PNG_IO_STATE_SUPPORTED */ - -/* Interlace support. The following macros are always defined so that if - * libpng interlace handling is turned off the macros may be used to handle - * interlaced images within the application. - */ -#define PNG_INTERLACE_ADAM7_PASSES 7 - -/* Two macros to return the first row and first column of the original, - * full, image which appears in a given pass. 'pass' is in the range 0 - * to 6 and the result is in the range 0 to 7. - */ -#define PNG_PASS_START_ROW(pass) (((1&~(pass))<<(3-((pass)>>1)))&7) -#define PNG_PASS_START_COL(pass) (((1& (pass))<<(3-(((pass)+1)>>1)))&7) - -/* A macro to return the offset between pixels in the output row for a pair of - * pixels in the input - effectively the inverse of the 'COL_SHIFT' macro that - * follows. Note that ROW_OFFSET is the offset from one row to the next whereas - * COL_OFFSET is from one column to the next, within a row. - */ -#define PNG_PASS_ROW_OFFSET(pass) ((pass)>2?(8>>(((pass)-1)>>1)):8) -#define PNG_PASS_COL_OFFSET(pass) (1<<((7-(pass))>>1)) - -/* Two macros to help evaluate the number of rows or columns in each - * pass. This is expressed as a shift - effectively log2 of the number or - * rows or columns in each 8x8 tile of the original image. - */ -#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3) -#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3) - -/* Hence two macros to determine the number of rows or columns in a given - * pass of an image given its height or width. In fact these macros may - * return non-zero even though the sub-image is empty, because the other - * dimension may be empty for a small image. - */ -#define PNG_PASS_ROWS(height, pass) (((height)+(((1<>PNG_PASS_ROW_SHIFT(pass)) -#define PNG_PASS_COLS(width, pass) (((width)+(((1<>PNG_PASS_COL_SHIFT(pass)) - -/* For the reader row callbacks (both progressive and sequential) it is - * necessary to find the row in the output image given a row in an interlaced - * image, so two more macros: - */ -#define PNG_ROW_FROM_PASS_ROW(yIn, pass) \ - (((yIn)<>(((7-(off))-(pass))<<2)) & 0xF) | \ - ((0x01145AF0>>(((7-(off))-(pass))<<2)) & 0xF0)) - -#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \ - ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1) -#define PNG_COL_IN_INTERLACE_PASS(x, pass) \ - ((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1) - -#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED -/* With these routines we avoid an integer divide, which will be slower on - * most machines. However, it does take more operations than the corresponding - * divide method, so it may be slower on a few RISC systems. There are two - * shifts (by 8 or 16 bits) and an addition, versus a single integer divide. - * - * Note that the rounding factors are NOT supposed to be the same! 128 and - * 32768 are correct for the NODIV code; 127 and 32767 are correct for the - * standard method. - * - * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ] - */ - - /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */ - -# define png_composite(composite, fg, alpha, bg) \ - { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) \ - * (png_uint_16)(alpha) \ - + (png_uint_16)(bg)*(png_uint_16)(255 \ - - (png_uint_16)(alpha)) + 128); \ - (composite) = (png_byte)((temp + (temp >> 8)) >> 8); } - -# define png_composite_16(composite, fg, alpha, bg) \ - { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) \ - * (png_uint_32)(alpha) \ - + (png_uint_32)(bg)*(65535 \ - - (png_uint_32)(alpha)) + 32768); \ - (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); } - -#else /* Standard method using integer division */ - -# define png_composite(composite, fg, alpha, bg) \ - (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \ - (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \ - 127) / 255) - -# define png_composite_16(composite, fg, alpha, bg) \ - (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \ - (png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) + \ - 32767) / 65535) -#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */ - -#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED -PNG_EXPORT(201, png_uint_32, png_get_uint_32, (png_const_bytep buf)); -PNG_EXPORT(202, png_uint_16, png_get_uint_16, (png_const_bytep buf)); -PNG_EXPORT(203, png_int_32, png_get_int_32, (png_const_bytep buf)); -#endif - -PNG_EXPORT(204, png_uint_32, png_get_uint_31, (png_structp png_ptr, - png_const_bytep buf)); -/* No png_get_int_16 -- may be added if there's a real need for it. */ - -/* Place a 32-bit number into a buffer in PNG byte order (big-endian). */ -#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED -PNG_EXPORT(205, void, png_save_uint_32, (png_bytep buf, png_uint_32 i)); -#endif -#ifdef PNG_SAVE_INT_32_SUPPORTED -PNG_EXPORT(206, void, png_save_int_32, (png_bytep buf, png_int_32 i)); -#endif - -/* Place a 16-bit number into a buffer in PNG byte order. - * The parameter is declared unsigned int, not png_uint_16, - * just to avoid potential problems on pre-ANSI C compilers. - */ -#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED -PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i)); -/* No png_save_int_16 -- may be added if there's a real need for it. */ -#endif - -#ifdef PNG_USE_READ_MACROS -/* Inline macros to do direct reads of bytes from the input buffer. - * The png_get_int_32() routine assumes we are using two's complement - * format for negative values, which is almost certainly true. - */ -# define png_get_uint_32(buf) \ - (((png_uint_32)(*(buf)) << 24) + \ - ((png_uint_32)(*((buf) + 1)) << 16) + \ - ((png_uint_32)(*((buf) + 2)) << 8) + \ - ((png_uint_32)(*((buf) + 3)))) - - /* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the - * function) incorrectly returned a value of type png_uint_32. - */ -# define png_get_uint_16(buf) \ - ((png_uint_16) \ - (((unsigned int)(*(buf)) << 8) + \ - ((unsigned int)(*((buf) + 1))))) - -# define png_get_int_32(buf) \ - ((png_int_32)((*(buf) & 0x80) \ - ? -((png_int_32)((png_get_uint_32(buf) ^ 0xffffffffL) + 1)) \ - : (png_int_32)png_get_uint_32(buf))) -#endif - -#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \ - defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED) -PNG_EXPORT(234, void, png_set_check_for_invalid_index, (png_structp png_ptr, - int allowed)); -#endif - -/* Maintainer: Put new public prototypes here ^, in libpng.3, and project - * defs - */ - -/* The last ordinal number (this is the *last* one already used; the next - * one to use is one more than this.) Maintainer, remember to add an entry to - * scripts/symbols.def as well. - */ -#ifdef PNG_EXPORT_LAST_ORDINAL - PNG_EXPORT_LAST_ORDINAL(234); -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* PNG_VERSION_INFO_ONLY */ -/* Do not put anything past this line */ -#endif /* PNG_H */ + +/* png.h - header file for PNG reference library + * + * libpng version 1.5.13 - September 27, 2012 + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license (See LICENSE, below) + * + * Authors and maintainers: + * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat + * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger + * libpng versions 0.97, January 1998, through 1.5.13 - September 27, 2012: Glenn + * See also "Contributing Authors", below. + * + * Note about libpng version numbers: + * + * Due to various miscommunications, unforeseen code incompatibilities + * and occasional factors outside the authors' control, version numbering + * on the library has not always been consistent and straightforward. + * The following table summarizes matters since version 0.89c, which was + * the first widely used release: + * + * source png.h png.h shared-lib + * version string int version + * ------- ------ ----- ---------- + * 0.89c "1.0 beta 3" 0.89 89 1.0.89 + * 0.90 "1.0 beta 4" 0.90 90 0.90 [should have been 2.0.90] + * 0.95 "1.0 beta 5" 0.95 95 0.95 [should have been 2.0.95] + * 0.96 "1.0 beta 6" 0.96 96 0.96 [should have been 2.0.96] + * 0.97b "1.00.97 beta 7" 1.00.97 97 1.0.1 [should have been 2.0.97] + * 0.97c 0.97 97 2.0.97 + * 0.98 0.98 98 2.0.98 + * 0.99 0.99 98 2.0.99 + * 0.99a-m 0.99 99 2.0.99 + * 1.00 1.00 100 2.1.0 [100 should be 10000] + * 1.0.0 (from here on, the 100 2.1.0 [100 should be 10000] + * 1.0.1 png.h string is 10001 2.1.0 + * 1.0.1a-e identical to the 10002 from here on, the shared library + * 1.0.2 source version) 10002 is 2.V where V is the source code + * 1.0.2a-b 10003 version, except as noted. + * 1.0.3 10003 + * 1.0.3a-d 10004 + * 1.0.4 10004 + * 1.0.4a-f 10005 + * 1.0.5 (+ 2 patches) 10005 + * 1.0.5a-d 10006 + * 1.0.5e-r 10100 (not source compatible) + * 1.0.5s-v 10006 (not binary compatible) + * 1.0.6 (+ 3 patches) 10006 (still binary incompatible) + * 1.0.6d-f 10007 (still binary incompatible) + * 1.0.6g 10007 + * 1.0.6h 10007 10.6h (testing xy.z so-numbering) + * 1.0.6i 10007 10.6i + * 1.0.6j 10007 2.1.0.6j (incompatible with 1.0.0) + * 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14 (binary compatible) + * 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 (binary compatible) + * 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 (binary compatible) + * 1.0.7 1 10007 (still compatible) + * 1.0.8beta1-4 1 10008 2.1.0.8beta1-4 + * 1.0.8rc1 1 10008 2.1.0.8rc1 + * 1.0.8 1 10008 2.1.0.8 + * 1.0.9beta1-6 1 10009 2.1.0.9beta1-6 + * 1.0.9rc1 1 10009 2.1.0.9rc1 + * 1.0.9beta7-10 1 10009 2.1.0.9beta7-10 + * 1.0.9rc2 1 10009 2.1.0.9rc2 + * 1.0.9 1 10009 2.1.0.9 + * 1.0.10beta1 1 10010 2.1.0.10beta1 + * 1.0.10rc1 1 10010 2.1.0.10rc1 + * 1.0.10 1 10010 2.1.0.10 + * 1.0.11beta1-3 1 10011 2.1.0.11beta1-3 + * 1.0.11rc1 1 10011 2.1.0.11rc1 + * 1.0.11 1 10011 2.1.0.11 + * 1.0.12beta1-2 2 10012 2.1.0.12beta1-2 + * 1.0.12rc1 2 10012 2.1.0.12rc1 + * 1.0.12 2 10012 2.1.0.12 + * 1.1.0a-f - 10100 2.1.1.0a-f (branch abandoned) + * 1.2.0beta1-2 2 10200 2.1.2.0beta1-2 + * 1.2.0beta3-5 3 10200 3.1.2.0beta3-5 + * 1.2.0rc1 3 10200 3.1.2.0rc1 + * 1.2.0 3 10200 3.1.2.0 + * 1.2.1beta1-4 3 10201 3.1.2.1beta1-4 + * 1.2.1rc1-2 3 10201 3.1.2.1rc1-2 + * 1.2.1 3 10201 3.1.2.1 + * 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6 + * 1.0.13beta1 10 10013 10.so.0.1.0.13beta1 + * 1.0.13rc1 10 10013 10.so.0.1.0.13rc1 + * 1.2.2rc1 12 10202 12.so.0.1.2.2rc1 + * 1.0.13 10 10013 10.so.0.1.0.13 + * 1.2.2 12 10202 12.so.0.1.2.2 + * 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6 + * 1.2.3 12 10203 12.so.0.1.2.3 + * 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3 + * 1.0.14rc1 13 10014 10.so.0.1.0.14rc1 + * 1.2.4rc1 13 10204 12.so.0.1.2.4rc1 + * 1.0.14 10 10014 10.so.0.1.0.14 + * 1.2.4 13 10204 12.so.0.1.2.4 + * 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2 + * 1.0.15rc1-3 10 10015 10.so.0.1.0.15rc1-3 + * 1.2.5rc1-3 13 10205 12.so.0.1.2.5rc1-3 + * 1.0.15 10 10015 10.so.0.1.0.15 + * 1.2.5 13 10205 12.so.0.1.2.5 + * 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4 + * 1.0.16 10 10016 10.so.0.1.0.16 + * 1.2.6 13 10206 12.so.0.1.2.6 + * 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2 + * 1.0.17rc1 10 10017 12.so.0.1.0.17rc1 + * 1.2.7rc1 13 10207 12.so.0.1.2.7rc1 + * 1.0.17 10 10017 12.so.0.1.0.17 + * 1.2.7 13 10207 12.so.0.1.2.7 + * 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5 + * 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5 + * 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5 + * 1.0.18 10 10018 12.so.0.1.0.18 + * 1.2.8 13 10208 12.so.0.1.2.8 + * 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3 + * 1.2.9beta4-11 13 10209 12.so.0.9[.0] + * 1.2.9rc1 13 10209 12.so.0.9[.0] + * 1.2.9 13 10209 12.so.0.9[.0] + * 1.2.10beta1-7 13 10210 12.so.0.10[.0] + * 1.2.10rc1-2 13 10210 12.so.0.10[.0] + * 1.2.10 13 10210 12.so.0.10[.0] + * 1.4.0beta1-5 14 10400 14.so.0.0[.0] + * 1.2.11beta1-4 13 10211 12.so.0.11[.0] + * 1.4.0beta7-8 14 10400 14.so.0.0[.0] + * 1.2.11 13 10211 12.so.0.11[.0] + * 1.2.12 13 10212 12.so.0.12[.0] + * 1.4.0beta9-14 14 10400 14.so.0.0[.0] + * 1.2.13 13 10213 12.so.0.13[.0] + * 1.4.0beta15-36 14 10400 14.so.0.0[.0] + * 1.4.0beta37-87 14 10400 14.so.14.0[.0] + * 1.4.0rc01 14 10400 14.so.14.0[.0] + * 1.4.0beta88-109 14 10400 14.so.14.0[.0] + * 1.4.0rc02-08 14 10400 14.so.14.0[.0] + * 1.4.0 14 10400 14.so.14.0[.0] + * 1.4.1beta01-03 14 10401 14.so.14.1[.0] + * 1.4.1rc01 14 10401 14.so.14.1[.0] + * 1.4.1beta04-12 14 10401 14.so.14.1[.0] + * 1.4.1 14 10401 14.so.14.1[.0] + * 1.4.2 14 10402 14.so.14.2[.0] + * 1.4.3 14 10403 14.so.14.3[.0] + * 1.4.4 14 10404 14.so.14.4[.0] + * 1.5.0beta01-58 15 10500 15.so.15.0[.0] + * 1.5.0rc01-07 15 10500 15.so.15.0[.0] + * 1.5.0 15 10500 15.so.15.0[.0] + * 1.5.1beta01-11 15 10501 15.so.15.1[.0] + * 1.5.1rc01-02 15 10501 15.so.15.1[.0] + * 1.5.1 15 10501 15.so.15.1[.0] + * 1.5.2beta01-03 15 10502 15.so.15.2[.0] + * 1.5.2rc01-03 15 10502 15.so.15.2[.0] + * 1.5.2 15 10502 15.so.15.2[.0] + * 1.5.3beta01-10 15 10503 15.so.15.3[.0] + * 1.5.3rc01-02 15 10503 15.so.15.3[.0] + * 1.5.3beta11 15 10503 15.so.15.3[.0] + * 1.5.3 [omitted] + * 1.5.4beta01-08 15 10504 15.so.15.4[.0] + * 1.5.4rc01 15 10504 15.so.15.4[.0] + * 1.5.4 15 10504 15.so.15.4[.0] + * 1.5.5beta01-08 15 10505 15.so.15.5[.0] + * 1.5.5rc01 15 10505 15.so.15.5[.0] + * 1.5.5 15 10505 15.so.15.5[.0] + * 1.5.6beta01-07 15 10506 15.so.15.6[.0] + * 1.5.6rc01-03 15 10506 15.so.15.6[.0] + * 1.5.6 15 10506 15.so.15.6[.0] + * 1.5.7beta01-05 15 10507 15.so.15.7[.0] + * 1.5.7rc01-03 15 10507 15.so.15.7[.0] + * 1.5.7 15 10507 15.so.15.7[.0] + * 1.5.8beta01 15 10508 15.so.15.8[.0] + * 1.5.8rc01 15 10508 15.so.15.8[.0] + * 1.5.8 15 10508 15.so.15.8[.0] + * 1.5.9beta01-02 15 10509 15.so.15.9[.0] + * 1.5.9rc01 15 10509 15.so.15.9[.0] + * 1.5.9 15 10509 15.so.15.9[.0] + * 1.5.10beta01-05 15 10510 15.so.15.10[.0] + * 1.5.10 15 10510 15.so.15.10[.0] + * 1.5.11beta01 15 10511 15.so.15.11[.0] + * 1.5.11rc01-05 15 10511 15.so.15.11[.0] + * 1.5.11 15 10511 15.so.15.11[.0] + * 1.5.12 15 10512 15.so.15.12[.0] + * 1.5.13beta01-02 15 10513 15.so.15.13[.0] + * 1.5.13rc01 15 10513 15.so.15.13[.0] + * 1.5.13 15 10513 15.so.15.13[.0] + * + * Henceforth the source version will match the shared-library major + * and minor numbers; the shared-library major version number will be + * used for changes in backward compatibility, as it is intended. The + * PNG_LIBPNG_VER macro, which is not used within libpng but is available + * for applications, is an unsigned integer of the form xyyzz corresponding + * to the source version x.y.z (leading zeros in y and z). Beta versions + * were given the previous public release number plus a letter, until + * version 1.0.6j; from then on they were given the upcoming public + * release number plus "betaNN" or "rcNN". + * + * Binary incompatibility exists only when applications make direct access + * to the info_ptr or png_ptr members through png.h, and the compiled + * application is loaded with a different version of the library. + * + * DLLNUM will change each time there are forward or backward changes + * in binary compatibility (e.g., when a new feature is added). + * + * See libpng-manual.txt or libpng.3 for more information. The PNG + * specification is available as a W3C Recommendation and as an ISO + * Specification, +# endif + + /* Need the time information for converting tIME chunks, it + * defines struct tm: + */ +# ifdef PNG_CONVERT_tIME_SUPPORTED + /* "time.h" functions are not supported on all operating systems */ +# include +# endif +# endif + +/* Machine specific configuration. */ +# include "pngconf.h" +#endif + +/* + * Added at libpng-1.2.8 + * + * Ref MSDN: Private as priority over Special + * VS_FF_PRIVATEBUILD File *was not* built using standard release + * procedures. If this value is given, the StringFileInfo block must + * contain a PrivateBuild string. + * + * VS_FF_SPECIALBUILD File *was* built by the original company using + * standard release procedures but is a variation of the standard + * file of the same version number. If this value is given, the + * StringFileInfo block must contain a SpecialBuild string. + */ + +#ifdef PNG_USER_PRIVATEBUILD /* From pnglibconf.h */ +# define PNG_LIBPNG_BUILD_TYPE \ + (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE) +#else +# ifdef PNG_LIBPNG_SPECIALBUILD +# define PNG_LIBPNG_BUILD_TYPE \ + (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL) +# else +# define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE) +# endif +#endif + +#ifndef PNG_VERSION_INFO_ONLY + +/* Inhibit C++ name-mangling for libpng functions but not for system calls. */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Version information for C files, stored in png.c. This had better match + * the version above. + */ +#define png_libpng_ver png_get_header_ver(NULL) + +/* This file is arranged in several sections: + * + * 1. Any configuration options that can be specified by for the application + * code when it is built. (Build time configuration is in pnglibconf.h) + * 2. Type definitions (base types are defined in pngconf.h), structure + * definitions. + * 3. Exported library functions. + * + * The library source code has additional files (principally pngpriv.h) that + * allow configuration of the library. + */ +/* Section 1: run time configuration + * See pnglibconf.h for build time configuration + * + * Run time configuration allows the application to choose between + * implementations of certain arithmetic APIs. The default is set + * at build time and recorded in pnglibconf.h, but it is safe to + * override these (and only these) settings. Note that this won't + * change what the library does, only application code, and the + * settings can (and probably should) be made on a per-file basis + * by setting the #defines before including png.h + * + * Use macros to read integers from PNG data or use the exported + * functions? + * PNG_USE_READ_MACROS: use the macros (see below) Note that + * the macros evaluate their argument multiple times. + * PNG_NO_USE_READ_MACROS: call the relevant library function. + * + * Use the alternative algorithm for compositing alpha samples that + * does not use division? + * PNG_READ_COMPOSITE_NODIV_SUPPORTED: use the 'no division' + * algorithm. + * PNG_NO_READ_COMPOSITE_NODIV: use the 'division' algorithm. + * + * How to handle benign errors if PNG_ALLOW_BENIGN_ERRORS is + * false? + * PNG_ALLOW_BENIGN_ERRORS: map calls to the benign error + * APIs to png_warning. + * Otherwise the calls are mapped to png_error. + */ + +/* Section 2: type definitions, including structures and compile time + * constants. + * See pngconf.h for base types that vary by machine/system + */ + +/* This triggers a compiler error in png.c, if png.c and png.h + * do not agree upon the version number. + */ +typedef char* png_libpng_version_1_5_13; + +/* Three color definitions. The order of the red, green, and blue, (and the + * exact size) is not important, although the size of the fields need to + * be png_byte or png_uint_16 (as defined below). + */ +typedef struct png_color_struct +{ + png_byte red; + png_byte green; + png_byte blue; +} png_color; +typedef png_color FAR * png_colorp; +typedef PNG_CONST png_color FAR * png_const_colorp; +typedef png_color FAR * FAR * png_colorpp; + +typedef struct png_color_16_struct +{ + png_byte index; /* used for palette files */ + png_uint_16 red; /* for use in red green blue files */ + png_uint_16 green; + png_uint_16 blue; + png_uint_16 gray; /* for use in grayscale files */ +} png_color_16; +typedef png_color_16 FAR * png_color_16p; +typedef PNG_CONST png_color_16 FAR * png_const_color_16p; +typedef png_color_16 FAR * FAR * png_color_16pp; + +typedef struct png_color_8_struct +{ + png_byte red; /* for use in red green blue files */ + png_byte green; + png_byte blue; + png_byte gray; /* for use in grayscale files */ + png_byte alpha; /* for alpha channel files */ +} png_color_8; +typedef png_color_8 FAR * png_color_8p; +typedef PNG_CONST png_color_8 FAR * png_const_color_8p; +typedef png_color_8 FAR * FAR * png_color_8pp; + +/* + * The following two structures are used for the in-core representation + * of sPLT chunks. + */ +typedef struct png_sPLT_entry_struct +{ + png_uint_16 red; + png_uint_16 green; + png_uint_16 blue; + png_uint_16 alpha; + png_uint_16 frequency; +} png_sPLT_entry; +typedef png_sPLT_entry FAR * png_sPLT_entryp; +typedef PNG_CONST png_sPLT_entry FAR * png_const_sPLT_entryp; +typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp; + +/* When the depth of the sPLT palette is 8 bits, the color and alpha samples + * occupy the LSB of their respective members, and the MSB of each member + * is zero-filled. The frequency member always occupies the full 16 bits. + */ + +typedef struct png_sPLT_struct +{ + png_charp name; /* palette name */ + png_byte depth; /* depth of palette samples */ + png_sPLT_entryp entries; /* palette entries */ + png_int_32 nentries; /* number of palette entries */ +} png_sPLT_t; +typedef png_sPLT_t FAR * png_sPLT_tp; +typedef PNG_CONST png_sPLT_t FAR * png_const_sPLT_tp; +typedef png_sPLT_t FAR * FAR * png_sPLT_tpp; + +#ifdef PNG_TEXT_SUPPORTED +/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file, + * and whether that contents is compressed or not. The "key" field + * points to a regular zero-terminated C string. The "text" fields can be a + * regular C string, an empty string, or a NULL pointer. + * However, the structure returned by png_get_text() will always contain + * the "text" field as a regular zero-terminated C string (possibly + * empty), never a NULL pointer, so it can be safely used in printf() and + * other string-handling functions. Note that the "itxt_length", "lang", and + * "lang_key" members of the structure only exist when the library is built + * with iTXt chunk support. Prior to libpng-1.4.0 the library was built by + * default without iTXt support. Also note that when iTXt *is* supported, + * the "lang" and "lang_key" fields contain NULL pointers when the + * "compression" field contains * PNG_TEXT_COMPRESSION_NONE or + * PNG_TEXT_COMPRESSION_zTXt. Note that the "compression value" is not the + * same as what appears in the PNG tEXt/zTXt/iTXt chunk's "compression flag" + * which is always 0 or 1, or its "compression method" which is always 0. + */ +typedef struct png_text_struct +{ + int compression; /* compression value: + -1: tEXt, none + 0: zTXt, deflate + 1: iTXt, none + 2: iTXt, deflate */ + png_charp key; /* keyword, 1-79 character description of "text" */ + png_charp text; /* comment, may be an empty string (ie "") + or a NULL pointer */ + png_size_t text_length; /* length of the text string */ + png_size_t itxt_length; /* length of the itxt string */ + png_charp lang; /* language code, 0-79 characters + or a NULL pointer */ + png_charp lang_key; /* keyword translated UTF-8 string, 0 or more + chars or a NULL pointer */ +} png_text; +typedef png_text FAR * png_textp; +typedef PNG_CONST png_text FAR * png_const_textp; +typedef png_text FAR * FAR * png_textpp; +#endif + +/* Supported compression types for text in PNG files (tEXt, and zTXt). + * The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed. */ +#define PNG_TEXT_COMPRESSION_NONE_WR -3 +#define PNG_TEXT_COMPRESSION_zTXt_WR -2 +#define PNG_TEXT_COMPRESSION_NONE -1 +#define PNG_TEXT_COMPRESSION_zTXt 0 +#define PNG_ITXT_COMPRESSION_NONE 1 +#define PNG_ITXT_COMPRESSION_zTXt 2 +#define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */ + +/* png_time is a way to hold the time in an machine independent way. + * Two conversions are provided, both from time_t and struct tm. There + * is no portable way to convert to either of these structures, as far + * as I know. If you know of a portable way, send it to me. As a side + * note - PNG has always been Year 2000 compliant! + */ +typedef struct png_time_struct +{ + png_uint_16 year; /* full year, as in, 1995 */ + png_byte month; /* month of year, 1 - 12 */ + png_byte day; /* day of month, 1 - 31 */ + png_byte hour; /* hour of day, 0 - 23 */ + png_byte minute; /* minute of hour, 0 - 59 */ + png_byte second; /* second of minute, 0 - 60 (for leap seconds) */ +} png_time; +typedef png_time FAR * png_timep; +typedef PNG_CONST png_time FAR * png_const_timep; +typedef png_time FAR * FAR * png_timepp; + +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \ + defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) +/* png_unknown_chunk is a structure to hold queued chunks for which there is + * no specific support. The idea is that we can use this to queue + * up private chunks for output even though the library doesn't actually + * know about their semantics. + */ +typedef struct png_unknown_chunk_t +{ + png_byte name[5]; + png_byte *data; + png_size_t size; + + /* libpng-using applications should NOT directly modify this byte. */ + png_byte location; /* mode of operation at read time */ +} + + +png_unknown_chunk; +typedef png_unknown_chunk FAR * png_unknown_chunkp; +typedef PNG_CONST png_unknown_chunk FAR * png_const_unknown_chunkp; +typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp; +#endif + +/* Values for the unknown chunk location byte */ + +#define PNG_HAVE_IHDR 0x01 +#define PNG_HAVE_PLTE 0x02 +#define PNG_AFTER_IDAT 0x08 + +/* The complete definition of png_info has, as of libpng-1.5.0, + * been moved into a separate header file that is not accessible to + * applications. Read libpng-manual.txt or libpng.3 for more info. + */ +typedef struct png_info_def png_info; +typedef png_info FAR * png_infop; +typedef PNG_CONST png_info FAR * png_const_infop; +typedef png_info FAR * FAR * png_infopp; + +/* Maximum positive integer used in PNG is (2^31)-1 */ +#define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL) +#define PNG_UINT_32_MAX ((png_uint_32)(-1)) +#define PNG_SIZE_MAX ((png_size_t)(-1)) + +/* These are constants for fixed point values encoded in the + * PNG specification manner (x100000) + */ +#define PNG_FP_1 100000 +#define PNG_FP_HALF 50000 +#define PNG_FP_MAX ((png_fixed_point)0x7fffffffL) +#define PNG_FP_MIN (-PNG_FP_MAX) + +/* These describe the color_type field in png_info. */ +/* color type masks */ +#define PNG_COLOR_MASK_PALETTE 1 +#define PNG_COLOR_MASK_COLOR 2 +#define PNG_COLOR_MASK_ALPHA 4 + +/* color types. Note that not all combinations are legal */ +#define PNG_COLOR_TYPE_GRAY 0 +#define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE) +#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR) +#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA) +#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA) +/* aliases */ +#define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA +#define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA + +/* This is for compression type. PNG 1.0-1.2 only define the single type. */ +#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */ +#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE + +/* This is for filter type. PNG 1.0-1.2 only define the single type. */ +#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */ +#define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */ +#define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE + +/* These are for the interlacing type. These values should NOT be changed. */ +#define PNG_INTERLACE_NONE 0 /* Non-interlaced image */ +#define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */ +#define PNG_INTERLACE_LAST 2 /* Not a valid value */ + +/* These are for the oFFs chunk. These values should NOT be changed. */ +#define PNG_OFFSET_PIXEL 0 /* Offset in pixels */ +#define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */ +#define PNG_OFFSET_LAST 2 /* Not a valid value */ + +/* These are for the pCAL chunk. These values should NOT be changed. */ +#define PNG_EQUATION_LINEAR 0 /* Linear transformation */ +#define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */ +#define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */ +#define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */ +#define PNG_EQUATION_LAST 4 /* Not a valid value */ + +/* These are for the sCAL chunk. These values should NOT be changed. */ +#define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */ +#define PNG_SCALE_METER 1 /* meters per pixel */ +#define PNG_SCALE_RADIAN 2 /* radians per pixel */ +#define PNG_SCALE_LAST 3 /* Not a valid value */ + +/* These are for the pHYs chunk. These values should NOT be changed. */ +#define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */ +#define PNG_RESOLUTION_METER 1 /* pixels/meter */ +#define PNG_RESOLUTION_LAST 2 /* Not a valid value */ + +/* These are for the sRGB chunk. These values should NOT be changed. */ +#define PNG_sRGB_INTENT_PERCEPTUAL 0 +#define PNG_sRGB_INTENT_RELATIVE 1 +#define PNG_sRGB_INTENT_SATURATION 2 +#define PNG_sRGB_INTENT_ABSOLUTE 3 +#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */ + +/* This is for text chunks */ +#define PNG_KEYWORD_MAX_LENGTH 79 + +/* Maximum number of entries in PLTE/sPLT/tRNS arrays */ +#define PNG_MAX_PALETTE_LENGTH 256 + +/* These determine if an ancillary chunk's data has been successfully read + * from the PNG header, or if the application has filled in the corresponding + * data in the info_struct to be written into the output file. The values + * of the PNG_INFO_ defines should NOT be changed. + */ +#define PNG_INFO_gAMA 0x0001 +#define PNG_INFO_sBIT 0x0002 +#define PNG_INFO_cHRM 0x0004 +#define PNG_INFO_PLTE 0x0008 +#define PNG_INFO_tRNS 0x0010 +#define PNG_INFO_bKGD 0x0020 +#define PNG_INFO_hIST 0x0040 +#define PNG_INFO_pHYs 0x0080 +#define PNG_INFO_oFFs 0x0100 +#define PNG_INFO_tIME 0x0200 +#define PNG_INFO_pCAL 0x0400 +#define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */ +#define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */ +#define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */ +#define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */ +#define PNG_INFO_IDAT 0x8000 /* ESR, 1.0.6 */ + +/* This is used for the transformation routines, as some of them + * change these values for the row. It also should enable using + * the routines for other purposes. + */ +typedef struct png_row_info_struct +{ + png_uint_32 width; /* width of row */ + png_size_t rowbytes; /* number of bytes in row */ + png_byte color_type; /* color type of row */ + png_byte bit_depth; /* bit depth of row */ + png_byte channels; /* number of channels (1, 2, 3, or 4) */ + png_byte pixel_depth; /* bits per pixel (depth * channels) */ +} png_row_info; + +typedef png_row_info FAR * png_row_infop; +typedef png_row_info FAR * FAR * png_row_infopp; + +/* The complete definition of png_struct has, as of libpng-1.5.0, + * been moved into a separate header file that is not accessible to + * applications. Read libpng-manual.txt or libpng.3 for more info. + */ +typedef struct png_struct_def png_struct; +typedef PNG_CONST png_struct FAR * png_const_structp; +typedef png_struct FAR * png_structp; + +/* These are the function types for the I/O functions and for the functions + * that allow the user to override the default I/O functions with his or her + * own. The png_error_ptr type should match that of user-supplied warning + * and error functions, while the png_rw_ptr type should match that of the + * user read/write data functions. Note that the 'write' function must not + * modify the buffer it is passed. The 'read' function, on the other hand, is + * expected to return the read data in the buffer. + */ +typedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp)); +typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, png_size_t)); +typedef PNG_CALLBACK(void, *png_flush_ptr, (png_structp)); +typedef PNG_CALLBACK(void, *png_read_status_ptr, (png_structp, png_uint_32, + int)); +typedef PNG_CALLBACK(void, *png_write_status_ptr, (png_structp, png_uint_32, + int)); + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +typedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop)); +typedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop)); + +/* The following callback receives png_uint_32 row_number, int pass for the + * png_bytep data of the row. When transforming an interlaced image the + * row number is the row number within the sub-image of the interlace pass, so + * the value will increase to the height of the sub-image (not the full image) + * then reset to 0 for the next pass. + * + * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to + * find the output pixel (x,y) given an interlaced sub-image pixel + * (row,col,pass). (See below for these macros.) + */ +typedef PNG_CALLBACK(void, *png_progressive_row_ptr, (png_structp, png_bytep, + png_uint_32, int)); +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +typedef PNG_CALLBACK(void, *png_user_transform_ptr, (png_structp, png_row_infop, + png_bytep)); +#endif + +#ifdef PNG_USER_CHUNKS_SUPPORTED +typedef PNG_CALLBACK(int, *png_user_chunk_ptr, (png_structp, + png_unknown_chunkp)); +#endif +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED +typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp)); +#endif + +#ifdef PNG_SETJMP_SUPPORTED +/* This must match the function definition in , and the application + * must include this before png.h to obtain the definition of jmp_buf. The + * function is required to be PNG_NORETURN, but this is not checked. If the + * function does return the application will crash via an abort() or similar + * system level call. + * + * If you get a warning here while building the library you may need to make + * changes to ensure that pnglibconf.h records the calling convention used by + * your compiler. This may be very difficult - try using a different compiler + * to build the library! + */ +PNG_FUNCTION(void, (PNGCAPI *png_longjmp_ptr), PNGARG((jmp_buf, int)), typedef); +#endif + +/* Transform masks for the high-level interface */ +#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */ +#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */ +#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */ +#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */ +#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */ +#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */ +#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */ +#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */ +#define PNG_TRANSFORM_BGR 0x0080 /* read and write */ +#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */ +#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */ +#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */ +#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* write only */ +/* Added to libpng-1.2.34 */ +#define PNG_TRANSFORM_STRIP_FILLER_BEFORE PNG_TRANSFORM_STRIP_FILLER +#define PNG_TRANSFORM_STRIP_FILLER_AFTER 0x1000 /* write only */ +/* Added to libpng-1.4.0 */ +#define PNG_TRANSFORM_GRAY_TO_RGB 0x2000 /* read only */ +/* Added to libpng-1.5.4 */ +#define PNG_TRANSFORM_EXPAND_16 0x4000 /* read only */ +#define PNG_TRANSFORM_SCALE_16 0x8000 /* read only */ + +/* Flags for MNG supported features */ +#define PNG_FLAG_MNG_EMPTY_PLTE 0x01 +#define PNG_FLAG_MNG_FILTER_64 0x04 +#define PNG_ALL_MNG_FEATURES 0x05 + +/* NOTE: prior to 1.5 these functions had no 'API' style declaration, + * this allowed the zlib default functions to be used on Windows + * platforms. In 1.5 the zlib default malloc (which just calls malloc and + * ignores the first argument) should be completely compatible with the + * following. + */ +typedef PNG_CALLBACK(png_voidp, *png_malloc_ptr, (png_structp, + png_alloc_size_t)); +typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp)); + +typedef png_struct FAR * FAR * png_structpp; + +/* Section 3: exported functions + * Here are the function definitions most commonly used. This is not + * the place to find out how to use libpng. See libpng-manual.txt for the + * full explanation, see example.c for the summary. This just provides + * a simple one line description of the use of each function. + * + * The PNG_EXPORT() and PNG_EXPORTA() macros used below are defined in + * pngconf.h and in the *.dfn files in the scripts directory. + * + * PNG_EXPORT(ordinal, type, name, (args)); + * + * ordinal: ordinal that is used while building + * *.def files. The ordinal value is only + * relevant when preprocessing png.h with + * the *.dfn files for building symbol table + * entries, and are removed by pngconf.h. + * type: return type of the function + * name: function name + * args: function arguments, with types + * + * When we wish to append attributes to a function prototype we use + * the PNG_EXPORTA() macro instead. + * + * PNG_EXPORTA(ordinal, type, name, (args), attributes); + * + * ordinal, type, name, and args: same as in PNG_EXPORT(). + * attributes: function attributes + */ + +/* Returns the version number of the library */ +PNG_EXPORT(1, png_uint_32, png_access_version_number, (void)); + +/* Tell lib we have already handled the first magic bytes. + * Handling more than 8 bytes from the beginning of the file is an error. + */ +PNG_EXPORT(2, void, png_set_sig_bytes, (png_structp png_ptr, int num_bytes)); + +/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a + * PNG file. Returns zero if the supplied bytes match the 8-byte PNG + * signature, and non-zero otherwise. Having num_to_check == 0 or + * start > 7 will always fail (ie return non-zero). + */ +PNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, png_size_t start, + png_size_t num_to_check)); + +/* Simple signature checking function. This is the same as calling + * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n). + */ +#define png_check_sig(sig, n) !png_sig_cmp((sig), 0, (n)) + +/* Allocate and initialize png_ptr struct for reading, and any other memory. */ +PNG_EXPORTA(4, png_structp, png_create_read_struct, + (png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn), + PNG_ALLOCATED); + +/* Allocate and initialize png_ptr struct for writing, and any other memory */ +PNG_EXPORTA(5, png_structp, png_create_write_struct, + (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warn_fn), + PNG_ALLOCATED); + +PNG_EXPORT(6, png_size_t, png_get_compression_buffer_size, + (png_const_structp png_ptr)); + +PNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structp png_ptr, + png_size_t size)); + +/* Moved from pngconf.h in 1.4.0 and modified to ensure setjmp/longjmp + * match up. + */ +#ifdef PNG_SETJMP_SUPPORTED +/* This function returns the jmp_buf built in to *png_ptr. It must be + * supplied with an appropriate 'longjmp' function to use on that jmp_buf + * unless the default error function is overridden in which case NULL is + * acceptable. The size of the jmp_buf is checked against the actual size + * allocated by the library - the call will return NULL on a mismatch + * indicating an ABI mismatch. + */ +PNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structp png_ptr, + png_longjmp_ptr longjmp_fn, size_t jmp_buf_size)); +# define png_jmpbuf(png_ptr) \ + (*png_set_longjmp_fn((png_ptr), longjmp, sizeof (jmp_buf))) +#else +# define png_jmpbuf(png_ptr) \ + (LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP) +#endif +/* This function should be used by libpng applications in place of + * longjmp(png_ptr->jmpbuf, val). If longjmp_fn() has been set, it + * will use it; otherwise it will call PNG_ABORT(). This function was + * added in libpng-1.5.0. + */ +PNG_EXPORTA(9, void, png_longjmp, (png_structp png_ptr, int val), + PNG_NORETURN); + +#ifdef PNG_READ_SUPPORTED +/* Reset the compression stream */ +PNG_EXPORT(10, int, png_reset_zstream, (png_structp png_ptr)); +#endif + +/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */ +#ifdef PNG_USER_MEM_SUPPORTED +PNG_EXPORTA(11, png_structp, png_create_read_struct_2, + (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warn_fn, + png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn), + PNG_ALLOCATED); +PNG_EXPORTA(12, png_structp, png_create_write_struct_2, + (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warn_fn, + png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn), + PNG_ALLOCATED); +#endif + +/* Write the PNG file signature. */ +PNG_EXPORT(13, void, png_write_sig, (png_structp png_ptr)); + +/* Write a PNG chunk - size, type, (optional) data, CRC. */ +PNG_EXPORT(14, void, png_write_chunk, (png_structp png_ptr, png_const_bytep + chunk_name, png_const_bytep data, png_size_t length)); + +/* Write the start of a PNG chunk - length and chunk name. */ +PNG_EXPORT(15, void, png_write_chunk_start, (png_structp png_ptr, + png_const_bytep chunk_name, png_uint_32 length)); + +/* Write the data of a PNG chunk started with png_write_chunk_start(). */ +PNG_EXPORT(16, void, png_write_chunk_data, (png_structp png_ptr, + png_const_bytep data, png_size_t length)); + +/* Finish a chunk started with png_write_chunk_start() (includes CRC). */ +PNG_EXPORT(17, void, png_write_chunk_end, (png_structp png_ptr)); + +/* Allocate and initialize the info structure */ +PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_structp png_ptr), + PNG_ALLOCATED); + +PNG_EXPORT(19, void, png_info_init_3, (png_infopp info_ptr, + png_size_t png_info_struct_size)); + +/* Writes all the PNG information before the image. */ +PNG_EXPORT(20, void, png_write_info_before_PLTE, + (png_structp png_ptr, png_infop info_ptr)); +PNG_EXPORT(21, void, png_write_info, + (png_structp png_ptr, png_infop info_ptr)); + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the information before the actual image data. */ +PNG_EXPORT(22, void, png_read_info, + (png_structp png_ptr, png_infop info_ptr)); +#endif + +#ifdef PNG_TIME_RFC1123_SUPPORTED +PNG_EXPORT(23, png_const_charp, png_convert_to_rfc1123, + (png_structp png_ptr, + png_const_timep ptime)); +#endif + +#ifdef PNG_CONVERT_tIME_SUPPORTED +/* Convert from a struct tm to png_time */ +PNG_EXPORT(24, void, png_convert_from_struct_tm, (png_timep ptime, + PNG_CONST struct tm FAR * ttime)); + +/* Convert from time_t to png_time. Uses gmtime() */ +PNG_EXPORT(25, void, png_convert_from_time_t, + (png_timep ptime, time_t ttime)); +#endif /* PNG_CONVERT_tIME_SUPPORTED */ + +#ifdef PNG_READ_EXPAND_SUPPORTED +/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */ +PNG_EXPORT(26, void, png_set_expand, (png_structp png_ptr)); +PNG_EXPORT(27, void, png_set_expand_gray_1_2_4_to_8, (png_structp png_ptr)); +PNG_EXPORT(28, void, png_set_palette_to_rgb, (png_structp png_ptr)); +PNG_EXPORT(29, void, png_set_tRNS_to_alpha, (png_structp png_ptr)); +#endif + +#ifdef PNG_READ_EXPAND_16_SUPPORTED +/* Expand to 16-bit channels, forces conversion of palette to RGB and expansion + * of a tRNS chunk if present. + */ +PNG_EXPORT(221, void, png_set_expand_16, (png_structp png_ptr)); +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +/* Use blue, green, red order for pixels. */ +PNG_EXPORT(30, void, png_set_bgr, (png_structp png_ptr)); +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +/* Expand the grayscale to 24-bit RGB if necessary. */ +PNG_EXPORT(31, void, png_set_gray_to_rgb, (png_structp png_ptr)); +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +/* Reduce RGB to grayscale. */ +#define PNG_ERROR_ACTION_NONE 1 +#define PNG_ERROR_ACTION_WARN 2 +#define PNG_ERROR_ACTION_ERROR 3 +#define PNG_RGB_TO_GRAY_DEFAULT (-1)/*for red/green coefficients*/ + +PNG_FP_EXPORT(32, void, png_set_rgb_to_gray, (png_structp png_ptr, + int error_action, double red, double green)) +PNG_FIXED_EXPORT(33, void, png_set_rgb_to_gray_fixed, (png_structp png_ptr, + int error_action, png_fixed_point red, png_fixed_point green)) + +PNG_EXPORT(34, png_byte, png_get_rgb_to_gray_status, (png_const_structp + png_ptr)); +#endif + +#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED +PNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth, + png_colorp palette)); +#endif + +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED +/* How the alpha channel is interpreted - this affects how the color channels of + * a PNG file are returned when an alpha channel, or tRNS chunk in a palette + * file, is present. + * + * This has no effect on the way pixels are written into a PNG output + * datastream. The color samples in a PNG datastream are never premultiplied + * with the alpha samples. + * + * The default is to return data according to the PNG specification: the alpha + * channel is a linear measure of the contribution of the pixel to the + * corresponding composited pixel. The gamma encoded color channels must be + * scaled according to the contribution and to do this it is necessary to undo + * the encoding, scale the color values, perform the composition and reencode + * the values. This is the 'PNG' mode. + * + * The alternative is to 'associate' the alpha with the color information by + * storing color channel values that have been scaled by the alpha. The + * advantage is that the color channels can be resampled (the image can be + * scaled) in this form. The disadvantage is that normal practice is to store + * linear, not (gamma) encoded, values and this requires 16-bit channels for + * still images rather than the 8-bit channels that are just about sufficient if + * gamma encoding is used. In addition all non-transparent pixel values, + * including completely opaque ones, must be gamma encoded to produce the final + * image. This is the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' mode (the + * latter being the two common names for associated alpha color channels.) + * + * Since it is not necessary to perform arithmetic on opaque color values so + * long as they are not to be resampled and are in the final color space it is + * possible to optimize the handling of alpha by storing the opaque pixels in + * the PNG format (adjusted for the output color space) while storing partially + * opaque pixels in the standard, linear, format. The accuracy required for + * standard alpha composition is relatively low, because the pixels are + * isolated, therefore typically the accuracy loss in storing 8-bit linear + * values is acceptable. (This is not true if the alpha channel is used to + * simulate transparency over large areas - use 16 bits or the PNG mode in + * this case!) This is the 'OPTIMIZED' mode. For this mode a pixel is + * treated as opaque only if the alpha value is equal to the maximum value. + * + * The final choice is to gamma encode the alpha channel as well. This is + * broken because, in practice, no implementation that uses this choice + * correctly undoes the encoding before handling alpha composition. Use this + * choice only if other serious errors in the software or hardware you use + * mandate it; the typical serious error is for dark halos to appear around + * opaque areas of the composited PNG image because of arithmetic overflow. + * + * The API function png_set_alpha_mode specifies which of these choices to use + * with an enumerated 'mode' value and the gamma of the required output: + */ +#define PNG_ALPHA_PNG 0 /* according to the PNG standard */ +#define PNG_ALPHA_STANDARD 1 /* according to Porter/Duff */ +#define PNG_ALPHA_ASSOCIATED 1 /* as above; this is the normal practice */ +#define PNG_ALPHA_PREMULTIPLIED 1 /* as above */ +#define PNG_ALPHA_OPTIMIZED 2 /* 'PNG' for opaque pixels, else 'STANDARD' */ +#define PNG_ALPHA_BROKEN 3 /* the alpha channel is gamma encoded */ + +PNG_FP_EXPORT(227, void, png_set_alpha_mode, (png_structp png_ptr, int mode, + double output_gamma)) +PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structp png_ptr, + int mode, png_fixed_point output_gamma)) +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_ALPHA_MODE_SUPPORTED) +/* The output_gamma value is a screen gamma in libpng terminology: it expresses + * how to decode the output values, not how they are encoded. The values used + * correspond to the normal numbers used to describe the overall gamma of a + * computer display system; for example 2.2 for an sRGB conformant system. The + * values are scaled by 100000 in the _fixed version of the API (so 220000 for + * sRGB.) + * + * The inverse of the value is always used to provide a default for the PNG file + * encoding if it has no gAMA chunk and if png_set_gamma() has not been called + * to override the PNG gamma information. + * + * When the ALPHA_OPTIMIZED mode is selected the output gamma is used to encode + * opaque pixels however pixels with lower alpha values are not encoded, + * regardless of the output gamma setting. + * + * When the standard Porter Duff handling is requested with mode 1 the output + * encoding is set to be linear and the output_gamma value is only relevant + * as a default for input data that has no gamma information. The linear output + * encoding will be overridden if png_set_gamma() is called - the results may be + * highly unexpected! + * + * The following numbers are derived from the sRGB standard and the research + * behind it. sRGB is defined to be approximated by a PNG gAMA chunk value of + * 0.45455 (1/2.2) for PNG. The value implicitly includes any viewing + * correction required to take account of any differences in the color + * environment of the original scene and the intended display environment; the + * value expresses how to *decode* the image for display, not how the original + * data was *encoded*. + * + * sRGB provides a peg for the PNG standard by defining a viewing environment. + * sRGB itself, and earlier TV standards, actually use a more complex transform + * (a linear portion then a gamma 2.4 power law) than PNG can express. (PNG is + * limited to simple power laws.) By saying that an image for direct display on + * an sRGB conformant system should be stored with a gAMA chunk value of 45455 + * (11.3.3.2 and 11.3.3.5 of the ISO PNG specification) the PNG specification + * makes it possible to derive values for other display systems and + * environments. + * + * The Mac value is deduced from the sRGB based on an assumption that the actual + * extra viewing correction used in early Mac display systems was implemented as + * a power 1.45 lookup table. + * + * Any system where a programmable lookup table is used or where the behavior of + * the final display device characteristics can be changed requires system + * specific code to obtain the current characteristic. However this can be + * difficult and most PNG gamma correction only requires an approximate value. + * + * By default, if png_set_alpha_mode() is not called, libpng assumes that all + * values are unencoded, linear, values and that the output device also has a + * linear characteristic. This is only very rarely correct - it is invariably + * better to call png_set_alpha_mode() with PNG_DEFAULT_sRGB than rely on the + * default if you don't know what the right answer is! + * + * The special value PNG_GAMMA_MAC_18 indicates an older Mac system (pre Mac OS + * 10.6) which used a correction table to implement a somewhat lower gamma on an + * otherwise sRGB system. + * + * Both these values are reserved (not simple gamma values) in order to allow + * more precise correction internally in the future. + * + * NOTE: the following values can be passed to either the fixed or floating + * point APIs, but the floating point API will also accept floating point + * values. + */ +#define PNG_DEFAULT_sRGB -1 /* sRGB gamma and color space */ +#define PNG_GAMMA_MAC_18 -2 /* Old Mac '1.8' gamma and color space */ +#define PNG_GAMMA_sRGB 220000 /* Television standards--matches sRGB gamma */ +#define PNG_GAMMA_LINEAR PNG_FP_1 /* Linear */ +#endif + +/* The following are examples of calls to png_set_alpha_mode to achieve the + * required overall gamma correction and, where necessary, alpha + * premultiplication. + * + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB); + * This is the default libpng handling of the alpha channel - it is not + * pre-multiplied into the color components. In addition the call states + * that the output is for a sRGB system and causes all PNG files without gAMA + * chunks to be assumed to be encoded using sRGB. + * + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC); + * In this case the output is assumed to be something like an sRGB conformant + * display preceeded by a power-law lookup table of power 1.45. This is how + * early Mac systems behaved. + * + * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR); + * This is the classic Jim Blinn approach and will work in academic + * environments where everything is done by the book. It has the shortcoming + * of assuming that input PNG data with no gamma information is linear - this + * is unlikely to be correct unless the PNG files where generated locally. + * Most of the time the output precision will be so low as to show + * significant banding in dark areas of the image. + * + * png_set_expand_16(pp); + * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_DEFAULT_sRGB); + * This is a somewhat more realistic Jim Blinn inspired approach. PNG files + * are assumed to have the sRGB encoding if not marked with a gamma value and + * the output is always 16 bits per component. This permits accurate scaling + * and processing of the data. If you know that your input PNG files were + * generated locally you might need to replace PNG_DEFAULT_sRGB with the + * correct value for your system. + * + * png_set_alpha_mode(pp, PNG_ALPHA_OPTIMIZED, PNG_DEFAULT_sRGB); + * If you just need to composite the PNG image onto an existing background + * and if you control the code that does this you can use the optimization + * setting. In this case you just copy completely opaque pixels to the + * output. For pixels that are not completely transparent (you just skip + * those) you do the composition math using png_composite or png_composite_16 + * below then encode the resultant 8-bit or 16-bit values to match the output + * encoding. + * + * Other cases + * If neither the PNG nor the standard linear encoding work for you because + * of the software or hardware you use then you have a big problem. The PNG + * case will probably result in halos around the image. The linear encoding + * will probably result in a washed out, too bright, image (it's actually too + * contrasty.) Try the ALPHA_OPTIMIZED mode above - this will probably + * substantially reduce the halos. Alternatively try: + * + * png_set_alpha_mode(pp, PNG_ALPHA_BROKEN, PNG_DEFAULT_sRGB); + * This option will also reduce the halos, but there will be slight dark + * halos round the opaque parts of the image where the background is light. + * In the OPTIMIZED mode the halos will be light halos where the background + * is dark. Take your pick - the halos are unavoidable unless you can get + * your hardware/software fixed! (The OPTIMIZED approach is slightly + * faster.) + * + * When the default gamma of PNG files doesn't match the output gamma. + * If you have PNG files with no gamma information png_set_alpha_mode allows + * you to provide a default gamma, but it also sets the ouput gamma to the + * matching value. If you know your PNG files have a gamma that doesn't + * match the output you can take advantage of the fact that + * png_set_alpha_mode always sets the output gamma but only sets the PNG + * default if it is not already set: + * + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB); + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC); + * The first call sets both the default and the output gamma values, the + * second call overrides the output gamma without changing the default. This + * is easier than achieving the same effect with png_set_gamma. You must use + * PNG_ALPHA_PNG for the first call - internal checking in png_set_alpha will + * fire if more than one call to png_set_alpha_mode and png_set_background is + * made in the same read operation, however multiple calls with PNG_ALPHA_PNG + * are ignored. + */ + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED +PNG_EXPORT(36, void, png_set_strip_alpha, (png_structp png_ptr)); +#endif + +#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) +PNG_EXPORT(37, void, png_set_swap_alpha, (png_structp png_ptr)); +#endif + +#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) +PNG_EXPORT(38, void, png_set_invert_alpha, (png_structp png_ptr)); +#endif + +#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) +/* Add a filler byte to 8-bit Gray or 24-bit RGB images. */ +PNG_EXPORT(39, void, png_set_filler, (png_structp png_ptr, png_uint_32 filler, + int flags)); +/* The values of the PNG_FILLER_ defines should NOT be changed */ +# define PNG_FILLER_BEFORE 0 +# define PNG_FILLER_AFTER 1 +/* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */ +PNG_EXPORT(40, void, png_set_add_alpha, + (png_structp png_ptr, png_uint_32 filler, + int flags)); +#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */ + +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +/* Swap bytes in 16-bit depth files. */ +PNG_EXPORT(41, void, png_set_swap, (png_structp png_ptr)); +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) +/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */ +PNG_EXPORT(42, void, png_set_packing, (png_structp png_ptr)); +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \ + defined(PNG_WRITE_PACKSWAP_SUPPORTED) +/* Swap packing order of pixels in bytes. */ +PNG_EXPORT(43, void, png_set_packswap, (png_structp png_ptr)); +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) +/* Converts files to legal bit depths. */ +PNG_EXPORT(44, void, png_set_shift, (png_structp png_ptr, png_const_color_8p + true_bits)); +#endif + +#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ + defined(PNG_WRITE_INTERLACING_SUPPORTED) +/* Have the code handle the interlacing. Returns the number of passes. + * MUST be called before png_read_update_info or png_start_read_image, + * otherwise it will not have the desired effect. Note that it is still + * necessary to call png_read_row or png_read_rows png_get_image_height + * times for each pass. +*/ +PNG_EXPORT(45, int, png_set_interlace_handling, (png_structp png_ptr)); +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) +/* Invert monochrome files */ +PNG_EXPORT(46, void, png_set_invert_mono, (png_structp png_ptr)); +#endif + +#ifdef PNG_READ_BACKGROUND_SUPPORTED +/* Handle alpha and tRNS by replacing with a background color. Prior to + * libpng-1.5.4 this API must not be called before the PNG file header has been + * read. Doing so will result in unexpected behavior and possible warnings or + * errors if the PNG file contains a bKGD chunk. + */ +PNG_FP_EXPORT(47, void, png_set_background, (png_structp png_ptr, + png_const_color_16p background_color, int background_gamma_code, + int need_expand, double background_gamma)) +PNG_FIXED_EXPORT(215, void, png_set_background_fixed, (png_structp png_ptr, + png_const_color_16p background_color, int background_gamma_code, + int need_expand, png_fixed_point background_gamma)) +#endif +#ifdef PNG_READ_BACKGROUND_SUPPORTED +# define PNG_BACKGROUND_GAMMA_UNKNOWN 0 +# define PNG_BACKGROUND_GAMMA_SCREEN 1 +# define PNG_BACKGROUND_GAMMA_FILE 2 +# define PNG_BACKGROUND_GAMMA_UNIQUE 3 +#endif + +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED +/* Scale a 16-bit depth file down to 8-bit, accurately. */ +PNG_EXPORT(229, void, png_set_scale_16, (png_structp png_ptr)); +#endif + +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED +#define PNG_READ_16_TO_8 SUPPORTED /* Name prior to 1.5.4 */ +/* Strip the second byte of information from a 16-bit depth file. */ +PNG_EXPORT(48, void, png_set_strip_16, (png_structp png_ptr)); +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED +/* Turn on quantizing, and reduce the palette to the number of colors + * available. + */ +PNG_EXPORT(49, void, png_set_quantize, + (png_structp png_ptr, png_colorp palette, + int num_palette, int maximum_colors, png_const_uint_16p histogram, + int full_quantize)); +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED +/* The threshold on gamma processing is configurable but hard-wired into the + * library. The following is the floating point variant. + */ +#define PNG_GAMMA_THRESHOLD (PNG_GAMMA_THRESHOLD_FIXED*.00001) + +/* Handle gamma correction. Screen_gamma=(display_exponent). + * NOTE: this API simply sets the screen and file gamma values. It will + * therefore override the value for gamma in a PNG file if it is called after + * the file header has been read - use with care - call before reading the PNG + * file for best results! + * + * These routines accept the same gamma values as png_set_alpha_mode (described + * above). The PNG_GAMMA_ defines and PNG_DEFAULT_sRGB can be passed to either + * API (floating point or fixed.) Notice, however, that the 'file_gamma' value + * is the inverse of a 'screen gamma' value. + */ +PNG_FP_EXPORT(50, void, png_set_gamma, + (png_structp png_ptr, double screen_gamma, + double override_file_gamma)) +PNG_FIXED_EXPORT(208, void, png_set_gamma_fixed, (png_structp png_ptr, + png_fixed_point screen_gamma, png_fixed_point override_file_gamma)) +#endif + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +/* Set how many lines between output flushes - 0 for no flushing */ +PNG_EXPORT(51, void, png_set_flush, (png_structp png_ptr, int nrows)); +/* Flush the current PNG output buffer */ +PNG_EXPORT(52, void, png_write_flush, (png_structp png_ptr)); +#endif + +/* Optional update palette with requested transformations */ +PNG_EXPORT(53, void, png_start_read_image, (png_structp png_ptr)); + +/* Optional call to update the users info structure */ +PNG_EXPORT(54, void, png_read_update_info, + (png_structp png_ptr, png_infop info_ptr)); + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read one or more rows of image data. */ +PNG_EXPORT(55, void, png_read_rows, (png_structp png_ptr, png_bytepp row, + png_bytepp display_row, png_uint_32 num_rows)); +#endif + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read a row of data. */ +PNG_EXPORT(56, void, png_read_row, (png_structp png_ptr, png_bytep row, + png_bytep display_row)); +#endif + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the whole image into memory at once. */ +PNG_EXPORT(57, void, png_read_image, (png_structp png_ptr, png_bytepp image)); +#endif + +/* Write a row of image data */ +PNG_EXPORT(58, void, png_write_row, + (png_structp png_ptr, png_const_bytep row)); + +/* Write a few rows of image data: (*row) is not written; however, the type + * is declared as writeable to maintain compatibility with previous versions + * of libpng and to allow the 'display_row' array from read_rows to be passed + * unchanged to write_rows. + */ +PNG_EXPORT(59, void, png_write_rows, (png_structp png_ptr, png_bytepp row, + png_uint_32 num_rows)); + +/* Write the image data */ +PNG_EXPORT(60, void, png_write_image, + (png_structp png_ptr, png_bytepp image)); + +/* Write the end of the PNG file. */ +PNG_EXPORT(61, void, png_write_end, + (png_structp png_ptr, png_infop info_ptr)); + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the end of the PNG file. */ +PNG_EXPORT(62, void, png_read_end, (png_structp png_ptr, png_infop info_ptr)); +#endif + +/* Free any memory associated with the png_info_struct */ +PNG_EXPORT(63, void, png_destroy_info_struct, (png_structp png_ptr, + png_infopp info_ptr_ptr)); + +/* Free any memory associated with the png_struct and the png_info_structs */ +PNG_EXPORT(64, void, png_destroy_read_struct, (png_structpp png_ptr_ptr, + png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr)); + +/* Free any memory associated with the png_struct and the png_info_structs */ +PNG_EXPORT(65, void, png_destroy_write_struct, (png_structpp png_ptr_ptr, + png_infopp info_ptr_ptr)); + +/* Set the libpng method of handling chunk CRC errors */ +PNG_EXPORT(66, void, png_set_crc_action, + (png_structp png_ptr, int crit_action, int ancil_action)); + +/* Values for png_set_crc_action() say how to handle CRC errors in + * ancillary and critical chunks, and whether to use the data contained + * therein. Note that it is impossible to "discard" data in a critical + * chunk. For versions prior to 0.90, the action was always error/quit, + * whereas in version 0.90 and later, the action for CRC errors in ancillary + * chunks is warn/discard. These values should NOT be changed. + * + * value action:critical action:ancillary + */ +#define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */ +#define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */ +#define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */ +#define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */ +#define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */ +#define PNG_CRC_NO_CHANGE 5 /* use current value use current value */ + +/* These functions give the user control over the scan-line filtering in + * libpng and the compression methods used by zlib. These functions are + * mainly useful for testing, as the defaults should work with most users. + * Those users who are tight on memory or want faster performance at the + * expense of compression can modify them. See the compression library + * header file (zlib.h) for an explination of the compression functions. + */ + +/* Set the filtering method(s) used by libpng. Currently, the only valid + * value for "method" is 0. + */ +PNG_EXPORT(67, void, png_set_filter, + (png_structp png_ptr, int method, int filters)); + +/* Flags for png_set_filter() to say which filters to use. The flags + * are chosen so that they don't conflict with real filter types + * below, in case they are supplied instead of the #defined constants. + * These values should NOT be changed. + */ +#define PNG_NO_FILTERS 0x00 +#define PNG_FILTER_NONE 0x08 +#define PNG_FILTER_SUB 0x10 +#define PNG_FILTER_UP 0x20 +#define PNG_FILTER_AVG 0x40 +#define PNG_FILTER_PAETH 0x80 +#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \ + PNG_FILTER_AVG | PNG_FILTER_PAETH) + +/* Filter values (not flags) - used in pngwrite.c, pngwutil.c for now. + * These defines should NOT be changed. + */ +#define PNG_FILTER_VALUE_NONE 0 +#define PNG_FILTER_VALUE_SUB 1 +#define PNG_FILTER_VALUE_UP 2 +#define PNG_FILTER_VALUE_AVG 3 +#define PNG_FILTER_VALUE_PAETH 4 +#define PNG_FILTER_VALUE_LAST 5 + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* EXPERIMENTAL */ +/* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_ + * defines, either the default (minimum-sum-of-absolute-differences), or + * the experimental method (weighted-minimum-sum-of-absolute-differences). + * + * Weights are factors >= 1.0, indicating how important it is to keep the + * filter type consistent between rows. Larger numbers mean the current + * filter is that many times as likely to be the same as the "num_weights" + * previous filters. This is cumulative for each previous row with a weight. + * There needs to be "num_weights" values in "filter_weights", or it can be + * NULL if the weights aren't being specified. Weights have no influence on + * the selection of the first row filter. Well chosen weights can (in theory) + * improve the compression for a given image. + * + * Costs are factors >= 1.0 indicating the relative decoding costs of a + * filter type. Higher costs indicate more decoding expense, and are + * therefore less likely to be selected over a filter with lower computational + * costs. There needs to be a value in "filter_costs" for each valid filter + * type (given by PNG_FILTER_VALUE_LAST), or it can be NULL if you aren't + * setting the costs. Costs try to improve the speed of decompression without + * unduly increasing the compressed image size. + * + * A negative weight or cost indicates the default value is to be used, and + * values in the range [0.0, 1.0) indicate the value is to remain unchanged. + * The default values for both weights and costs are currently 1.0, but may + * change if good general weighting/cost heuristics can be found. If both + * the weights and costs are set to 1.0, this degenerates the WEIGHTED method + * to the UNWEIGHTED method, but with added encoding time/computation. + */ +PNG_FP_EXPORT(68, void, png_set_filter_heuristics, (png_structp png_ptr, + int heuristic_method, int num_weights, png_const_doublep filter_weights, + png_const_doublep filter_costs)) +PNG_FIXED_EXPORT(209, void, png_set_filter_heuristics_fixed, + (png_structp png_ptr, + int heuristic_method, int num_weights, png_const_fixed_point_p + filter_weights, png_const_fixed_point_p filter_costs)) +#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ + +/* Heuristic used for row filter selection. These defines should NOT be + * changed. + */ +#define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */ +#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */ +#define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */ +#define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */ + +#ifdef PNG_WRITE_SUPPORTED +/* Set the library compression level. Currently, valid values range from + * 0 - 9, corresponding directly to the zlib compression levels 0 - 9 + * (0 - no compression, 9 - "maximal" compression). Note that tests have + * shown that zlib compression levels 3-6 usually perform as well as level 9 + * for PNG images, and do considerably fewer caclulations. In the future, + * these values may not correspond directly to the zlib compression levels. + */ +PNG_EXPORT(69, void, png_set_compression_level, + (png_structp png_ptr, int level)); + +PNG_EXPORT(70, void, png_set_compression_mem_level, (png_structp png_ptr, + int mem_level)); + +PNG_EXPORT(71, void, png_set_compression_strategy, (png_structp png_ptr, + int strategy)); + +/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a + * smaller value of window_bits if it can do so safely. + */ +PNG_EXPORT(72, void, png_set_compression_window_bits, (png_structp png_ptr, + int window_bits)); + +PNG_EXPORT(73, void, png_set_compression_method, (png_structp png_ptr, + int method)); +#endif + +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED +/* Also set zlib parameters for compressing non-IDAT chunks */ +PNG_EXPORT(222, void, png_set_text_compression_level, + (png_structp png_ptr, int level)); + +PNG_EXPORT(223, void, png_set_text_compression_mem_level, (png_structp png_ptr, + int mem_level)); + +PNG_EXPORT(224, void, png_set_text_compression_strategy, (png_structp png_ptr, + int strategy)); + +/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a + * smaller value of window_bits if it can do so safely. + */ +PNG_EXPORT(225, void, png_set_text_compression_window_bits, (png_structp + png_ptr, int window_bits)); + +PNG_EXPORT(226, void, png_set_text_compression_method, (png_structp png_ptr, + int method)); +#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */ + +/* These next functions are called for input/output, memory, and error + * handling. They are in the file pngrio.c, pngwio.c, and pngerror.c, + * and call standard C I/O routines such as fread(), fwrite(), and + * fprintf(). These functions can be made to use other I/O routines + * at run time for those applications that need to handle I/O in a + * different manner by calling png_set_???_fn(). See libpng-manual.txt for + * more information. + */ + +#ifdef PNG_STDIO_SUPPORTED +/* Initialize the input/output for the PNG file to the default functions. */ +PNG_EXPORT(74, void, png_init_io, (png_structp png_ptr, png_FILE_p fp)); +#endif + +/* Replace the (error and abort), and warning functions with user + * supplied functions. If no messages are to be printed you must still + * write and use replacement functions. The replacement error_fn should + * still do a longjmp to the last setjmp location if you are using this + * method of error handling. If error_fn or warning_fn is NULL, the + * default function will be used. + */ + +PNG_EXPORT(75, void, png_set_error_fn, + (png_structp png_ptr, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warning_fn)); + +/* Return the user pointer associated with the error functions */ +PNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_const_structp png_ptr)); + +/* Replace the default data output functions with a user supplied one(s). + * If buffered output is not used, then output_flush_fn can be set to NULL. + * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time + * output_flush_fn will be ignored (and thus can be NULL). + * It is probably a mistake to use NULL for output_flush_fn if + * write_data_fn is not also NULL unless you have built libpng with + * PNG_WRITE_FLUSH_SUPPORTED undefined, because in this case libpng's + * default flush function, which uses the standard *FILE structure, will + * be used. + */ +PNG_EXPORT(77, void, png_set_write_fn, (png_structp png_ptr, png_voidp io_ptr, + png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)); + +/* Replace the default data input function with a user supplied one. */ +PNG_EXPORT(78, void, png_set_read_fn, (png_structp png_ptr, png_voidp io_ptr, + png_rw_ptr read_data_fn)); + +/* Return the user pointer associated with the I/O functions */ +PNG_EXPORT(79, png_voidp, png_get_io_ptr, (png_structp png_ptr)); + +PNG_EXPORT(80, void, png_set_read_status_fn, (png_structp png_ptr, + png_read_status_ptr read_row_fn)); + +PNG_EXPORT(81, void, png_set_write_status_fn, (png_structp png_ptr, + png_write_status_ptr write_row_fn)); + +#ifdef PNG_USER_MEM_SUPPORTED +/* Replace the default memory allocation functions with user supplied one(s). */ +PNG_EXPORT(82, void, png_set_mem_fn, (png_structp png_ptr, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn)); +/* Return the user pointer associated with the memory functions */ +PNG_EXPORT(83, png_voidp, png_get_mem_ptr, (png_const_structp png_ptr)); +#endif + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED +PNG_EXPORT(84, void, png_set_read_user_transform_fn, (png_structp png_ptr, + png_user_transform_ptr read_user_transform_fn)); +#endif + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED +PNG_EXPORT(85, void, png_set_write_user_transform_fn, (png_structp png_ptr, + png_user_transform_ptr write_user_transform_fn)); +#endif + +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED +PNG_EXPORT(86, void, png_set_user_transform_info, (png_structp png_ptr, + png_voidp user_transform_ptr, int user_transform_depth, + int user_transform_channels)); +/* Return the user pointer associated with the user transform functions */ +PNG_EXPORT(87, png_voidp, png_get_user_transform_ptr, + (png_const_structp png_ptr)); +#endif + +#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED +/* Return information about the row currently being processed. Note that these + * APIs do not fail but will return unexpected results if called outside a user + * transform callback. Also note that when transforming an interlaced image the + * row number is the row number within the sub-image of the interlace pass, so + * the value will increase to the height of the sub-image (not the full image) + * then reset to 0 for the next pass. + * + * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to + * find the output pixel (x,y) given an interlaced sub-image pixel + * (row,col,pass). (See below for these macros.) + */ +PNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structp)); +PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structp)); +#endif + +#ifdef PNG_USER_CHUNKS_SUPPORTED +PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structp png_ptr, + png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn)); +PNG_EXPORT(89, png_voidp, png_get_user_chunk_ptr, (png_const_structp png_ptr)); +#endif + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +/* Sets the function callbacks for the push reader, and a pointer to a + * user-defined structure available to the callback functions. + */ +PNG_EXPORT(90, void, png_set_progressive_read_fn, (png_structp png_ptr, + png_voidp progressive_ptr, png_progressive_info_ptr info_fn, + png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn)); + +/* Returns the user pointer associated with the push read functions */ +PNG_EXPORT(91, png_voidp, png_get_progressive_ptr, (png_const_structp png_ptr)); + +/* Function to be called when data becomes available */ +PNG_EXPORT(92, void, png_process_data, + (png_structp png_ptr, png_infop info_ptr, + png_bytep buffer, png_size_t buffer_size)); + +/* A function which may be called *only* within png_process_data to stop the + * processing of any more data. The function returns the number of bytes + * remaining, excluding any that libpng has cached internally. A subsequent + * call to png_process_data must supply these bytes again. If the argument + * 'save' is set to true the routine will first save all the pending data and + * will always return 0. + */ +PNG_EXPORT(219, png_size_t, png_process_data_pause, (png_structp, int save)); + +/* A function which may be called *only* outside (after) a call to + * png_process_data. It returns the number of bytes of data to skip in the + * input. Normally it will return 0, but if it returns a non-zero value the + * application must skip than number of bytes of input data and pass the + * following data to the next call to png_process_data. + */ +PNG_EXPORT(220, png_uint_32, png_process_data_skip, (png_structp)); + +#ifdef PNG_READ_INTERLACING_SUPPORTED +/* Function that combines rows. 'new_row' is a flag that should come from + * the callback and be non-NULL if anything needs to be done; the library + * stores its own version of the new data internally and ignores the passed + * in value. + */ +PNG_EXPORT(93, void, png_progressive_combine_row, (png_structp png_ptr, + png_bytep old_row, png_const_bytep new_row)); +#endif /* PNG_READ_INTERLACING_SUPPORTED */ +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ + +PNG_EXPORTA(94, png_voidp, png_malloc, + (png_structp png_ptr, png_alloc_size_t size), + PNG_ALLOCATED); +/* Added at libpng version 1.4.0 */ +PNG_EXPORTA(95, png_voidp, png_calloc, + (png_structp png_ptr, png_alloc_size_t size), + PNG_ALLOCATED); + +/* Added at libpng version 1.2.4 */ +PNG_EXPORTA(96, png_voidp, png_malloc_warn, (png_structp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED); + +/* Frees a pointer allocated by png_malloc() */ +PNG_EXPORT(97, void, png_free, (png_structp png_ptr, png_voidp ptr)); + +/* Free data that was allocated internally */ +PNG_EXPORT(98, void, png_free_data, + (png_structp png_ptr, png_infop info_ptr, png_uint_32 free_me, int num)); + +/* Reassign responsibility for freeing existing data, whether allocated + * by libpng or by the application */ +PNG_EXPORT(99, void, png_data_freer, + (png_structp png_ptr, png_infop info_ptr, int freer, png_uint_32 mask)); + +/* Assignments for png_data_freer */ +#define PNG_DESTROY_WILL_FREE_DATA 1 +#define PNG_SET_WILL_FREE_DATA 1 +#define PNG_USER_WILL_FREE_DATA 2 +/* Flags for png_ptr->free_me and info_ptr->free_me */ +#define PNG_FREE_HIST 0x0008 +#define PNG_FREE_ICCP 0x0010 +#define PNG_FREE_SPLT 0x0020 +#define PNG_FREE_ROWS 0x0040 +#define PNG_FREE_PCAL 0x0080 +#define PNG_FREE_SCAL 0x0100 +#define PNG_FREE_UNKN 0x0200 +#define PNG_FREE_LIST 0x0400 +#define PNG_FREE_PLTE 0x1000 +#define PNG_FREE_TRNS 0x2000 +#define PNG_FREE_TEXT 0x4000 +#define PNG_FREE_ALL 0x7fff +#define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */ + +#ifdef PNG_USER_MEM_SUPPORTED +PNG_EXPORTA(100, png_voidp, png_malloc_default, (png_structp png_ptr, + png_alloc_size_t size), PNG_ALLOCATED); +PNG_EXPORT(101, void, png_free_default, (png_structp png_ptr, png_voidp ptr)); +#endif + +#ifdef PNG_ERROR_TEXT_SUPPORTED +/* Fatal error in PNG image of libpng - can't continue */ +PNG_EXPORTA(102, void, png_error, + (png_structp png_ptr, png_const_charp error_message), + PNG_NORETURN); + +/* The same, but the chunk name is prepended to the error string. */ +PNG_EXPORTA(103, void, png_chunk_error, (png_structp png_ptr, + png_const_charp error_message), PNG_NORETURN); + +#else +/* Fatal error in PNG image of libpng - can't continue */ +PNG_EXPORTA(104, void, png_err, (png_structp png_ptr), PNG_NORETURN); +#endif + +#ifdef PNG_WARNINGS_SUPPORTED +/* Non-fatal error in libpng. Can continue, but may have a problem. */ +PNG_EXPORT(105, void, png_warning, (png_structp png_ptr, + png_const_charp warning_message)); + +/* Non-fatal error in libpng, chunk name is prepended to message. */ +PNG_EXPORT(106, void, png_chunk_warning, (png_structp png_ptr, + png_const_charp warning_message)); +#endif + +#ifdef PNG_BENIGN_ERRORS_SUPPORTED +/* Benign error in libpng. Can continue, but may have a problem. + * User can choose whether to handle as a fatal error or as a warning. */ +# undef png_benign_error +PNG_EXPORT(107, void, png_benign_error, (png_structp png_ptr, + png_const_charp warning_message)); + +/* Same, chunk name is prepended to message. */ +# undef png_chunk_benign_error +PNG_EXPORT(108, void, png_chunk_benign_error, (png_structp png_ptr, + png_const_charp warning_message)); + +PNG_EXPORT(109, void, png_set_benign_errors, + (png_structp png_ptr, int allowed)); +#else +# ifdef PNG_ALLOW_BENIGN_ERRORS +# define png_benign_error png_warning +# define png_chunk_benign_error png_chunk_warning +# else +# define png_benign_error png_error +# define png_chunk_benign_error png_chunk_error +# endif +#endif + +/* The png_set_ functions are for storing values in the png_info_struct. + * Similarly, the png_get_ calls are used to read values from the + * png_info_struct, either storing the parameters in the passed variables, or + * setting pointers into the png_info_struct where the data is stored. The + * png_get_ functions return a non-zero value if the data was available + * in info_ptr, or return zero and do not change any of the parameters if the + * data was not available. + * + * These functions should be used instead of directly accessing png_info + * to avoid problems with future changes in the size and internal layout of + * png_info_struct. + */ +/* Returns "flag" if chunk data is valid in info_ptr. */ +PNG_EXPORT(110, png_uint_32, png_get_valid, + (png_const_structp png_ptr, png_const_infop info_ptr, + png_uint_32 flag)); + +/* Returns number of bytes needed to hold a transformed row. */ +PNG_EXPORT(111, png_size_t, png_get_rowbytes, (png_const_structp png_ptr, + png_const_infop info_ptr)); + +#ifdef PNG_INFO_IMAGE_SUPPORTED +/* Returns row_pointers, which is an array of pointers to scanlines that was + * returned from png_read_png(). + */ +PNG_EXPORT(112, png_bytepp, png_get_rows, + (png_const_structp png_ptr, png_const_infop info_ptr)); +/* Set row_pointers, which is an array of pointers to scanlines for use + * by png_write_png(). + */ +PNG_EXPORT(113, void, png_set_rows, (png_structp png_ptr, + png_infop info_ptr, png_bytepp row_pointers)); +#endif + +/* Returns number of color channels in image. */ +PNG_EXPORT(114, png_byte, png_get_channels, + (png_const_structp png_ptr, png_const_infop info_ptr)); + +#ifdef PNG_EASY_ACCESS_SUPPORTED +/* Returns image width in pixels. */ +PNG_EXPORT(115, png_uint_32, png_get_image_width, (png_const_structp png_ptr, + png_const_infop info_ptr)); + +/* Returns image height in pixels. */ +PNG_EXPORT(116, png_uint_32, png_get_image_height, (png_const_structp png_ptr, + png_const_infop info_ptr)); + +/* Returns image bit_depth. */ +PNG_EXPORT(117, png_byte, png_get_bit_depth, + (png_const_structp png_ptr, png_const_infop info_ptr)); + +/* Returns image color_type. */ +PNG_EXPORT(118, png_byte, png_get_color_type, (png_const_structp png_ptr, + png_const_infop info_ptr)); + +/* Returns image filter_type. */ +PNG_EXPORT(119, png_byte, png_get_filter_type, (png_const_structp png_ptr, + png_const_infop info_ptr)); + +/* Returns image interlace_type. */ +PNG_EXPORT(120, png_byte, png_get_interlace_type, (png_const_structp png_ptr, + png_const_infop info_ptr)); + +/* Returns image compression_type. */ +PNG_EXPORT(121, png_byte, png_get_compression_type, (png_const_structp png_ptr, + png_const_infop info_ptr)); + +/* Returns image resolution in pixels per meter, from pHYs chunk data. */ +PNG_EXPORT(122, png_uint_32, png_get_pixels_per_meter, + (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(123, png_uint_32, png_get_x_pixels_per_meter, + (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(124, png_uint_32, png_get_y_pixels_per_meter, + (png_const_structp png_ptr, png_const_infop info_ptr)); + +/* Returns pixel aspect ratio, computed from pHYs chunk data. */ +PNG_FP_EXPORT(125, float, png_get_pixel_aspect_ratio, + (png_const_structp png_ptr, png_const_infop info_ptr)) +PNG_FIXED_EXPORT(210, png_fixed_point, png_get_pixel_aspect_ratio_fixed, + (png_const_structp png_ptr, png_const_infop info_ptr)) + +/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */ +PNG_EXPORT(126, png_int_32, png_get_x_offset_pixels, + (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(127, png_int_32, png_get_y_offset_pixels, + (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(128, png_int_32, png_get_x_offset_microns, + (png_const_structp png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(129, png_int_32, png_get_y_offset_microns, + (png_const_structp png_ptr, png_const_infop info_ptr)); + +#endif /* PNG_EASY_ACCESS_SUPPORTED */ + +/* Returns pointer to signature string read from PNG header */ +PNG_EXPORT(130, png_const_bytep, png_get_signature, + (png_const_structp png_ptr, png_infop info_ptr)); + +#ifdef PNG_bKGD_SUPPORTED +PNG_EXPORT(131, png_uint_32, png_get_bKGD, + (png_const_structp png_ptr, png_infop info_ptr, + png_color_16p *background)); +#endif + +#ifdef PNG_bKGD_SUPPORTED +PNG_EXPORT(132, void, png_set_bKGD, (png_structp png_ptr, png_infop info_ptr, + png_const_color_16p background)); +#endif + +#ifdef PNG_cHRM_SUPPORTED +PNG_FP_EXPORT(133, png_uint_32, png_get_cHRM, (png_const_structp png_ptr, + png_const_infop info_ptr, double *white_x, double *white_y, double *red_x, + double *red_y, double *green_x, double *green_y, double *blue_x, + double *blue_y)) +PNG_FP_EXPORT(230, png_uint_32, png_get_cHRM_XYZ, (png_structp png_ptr, + png_const_infop info_ptr, double *red_X, double *red_Y, double *red_Z, + double *green_X, double *green_Y, double *green_Z, double *blue_X, + double *blue_Y, double *blue_Z)) +#ifdef PNG_FIXED_POINT_SUPPORTED /* Otherwise not implemented */ +PNG_FIXED_EXPORT(134, png_uint_32, png_get_cHRM_fixed, + (png_const_structp png_ptr, + png_const_infop info_ptr, png_fixed_point *int_white_x, + png_fixed_point *int_white_y, png_fixed_point *int_red_x, + png_fixed_point *int_red_y, png_fixed_point *int_green_x, + png_fixed_point *int_green_y, png_fixed_point *int_blue_x, + png_fixed_point *int_blue_y)) +#endif +PNG_FIXED_EXPORT(231, png_uint_32, png_get_cHRM_XYZ_fixed, + (png_structp png_ptr, png_const_infop info_ptr, + png_fixed_point *int_red_X, png_fixed_point *int_red_Y, + png_fixed_point *int_red_Z, png_fixed_point *int_green_X, + png_fixed_point *int_green_Y, png_fixed_point *int_green_Z, + png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y, + png_fixed_point *int_blue_Z)) +#endif + +#ifdef PNG_cHRM_SUPPORTED +PNG_FP_EXPORT(135, void, png_set_cHRM, + (png_structp png_ptr, png_infop info_ptr, + double white_x, double white_y, double red_x, double red_y, double green_x, + double green_y, double blue_x, double blue_y)) +PNG_FP_EXPORT(232, void, png_set_cHRM_XYZ, (png_structp png_ptr, + png_infop info_ptr, double red_X, double red_Y, double red_Z, + double green_X, double green_Y, double green_Z, double blue_X, + double blue_Y, double blue_Z)) +PNG_FIXED_EXPORT(136, void, png_set_cHRM_fixed, (png_structp png_ptr, + png_infop info_ptr, png_fixed_point int_white_x, + png_fixed_point int_white_y, png_fixed_point int_red_x, + png_fixed_point int_red_y, png_fixed_point int_green_x, + png_fixed_point int_green_y, png_fixed_point int_blue_x, + png_fixed_point int_blue_y)) +PNG_FIXED_EXPORT(233, void, png_set_cHRM_XYZ_fixed, (png_structp png_ptr, + png_infop info_ptr, png_fixed_point int_red_X, png_fixed_point int_red_Y, + png_fixed_point int_red_Z, png_fixed_point int_green_X, + png_fixed_point int_green_Y, png_fixed_point int_green_Z, + png_fixed_point int_blue_X, png_fixed_point int_blue_Y, + png_fixed_point int_blue_Z)) +#endif + +#ifdef PNG_gAMA_SUPPORTED +PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, + (png_const_structp png_ptr, png_const_infop info_ptr, + double *file_gamma)) +PNG_FIXED_EXPORT(138, png_uint_32, png_get_gAMA_fixed, + (png_const_structp png_ptr, png_const_infop info_ptr, + png_fixed_point *int_file_gamma)) +#endif + +#ifdef PNG_gAMA_SUPPORTED +PNG_FP_EXPORT(139, void, png_set_gAMA, (png_structp png_ptr, + png_infop info_ptr, double file_gamma)) +PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_structp png_ptr, + png_infop info_ptr, png_fixed_point int_file_gamma)) +#endif + +#ifdef PNG_hIST_SUPPORTED +PNG_EXPORT(141, png_uint_32, png_get_hIST, + (png_const_structp png_ptr, png_const_infop info_ptr, + png_uint_16p *hist)); +#endif + +#ifdef PNG_hIST_SUPPORTED +PNG_EXPORT(142, void, png_set_hIST, (png_structp png_ptr, + png_infop info_ptr, png_const_uint_16p hist)); +#endif + +PNG_EXPORT(143, png_uint_32, png_get_IHDR, + (png_structp png_ptr, png_infop info_ptr, + png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, + int *interlace_method, int *compression_method, int *filter_method)); + +PNG_EXPORT(144, void, png_set_IHDR, + (png_structp png_ptr, png_infop info_ptr, + png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, + int interlace_method, int compression_method, int filter_method)); + +#ifdef PNG_oFFs_SUPPORTED +PNG_EXPORT(145, png_uint_32, png_get_oFFs, + (png_const_structp png_ptr, png_const_infop info_ptr, + png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)); +#endif + +#ifdef PNG_oFFs_SUPPORTED +PNG_EXPORT(146, void, png_set_oFFs, + (png_structp png_ptr, png_infop info_ptr, + png_int_32 offset_x, png_int_32 offset_y, int unit_type)); +#endif + +#ifdef PNG_pCAL_SUPPORTED +PNG_EXPORT(147, png_uint_32, png_get_pCAL, + (png_const_structp png_ptr, png_const_infop info_ptr, + png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, + int *nparams, + png_charp *units, png_charpp *params)); +#endif + +#ifdef PNG_pCAL_SUPPORTED +PNG_EXPORT(148, void, png_set_pCAL, (png_structp png_ptr, + png_infop info_ptr, + png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, + int nparams, png_const_charp units, png_charpp params)); +#endif + +#ifdef PNG_pHYs_SUPPORTED +PNG_EXPORT(149, png_uint_32, png_get_pHYs, + (png_const_structp png_ptr, png_const_infop info_ptr, + png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); +#endif + +#ifdef PNG_pHYs_SUPPORTED +PNG_EXPORT(150, void, png_set_pHYs, + (png_structp png_ptr, png_infop info_ptr, + png_uint_32 res_x, png_uint_32 res_y, int unit_type)); +#endif + +PNG_EXPORT(151, png_uint_32, png_get_PLTE, + (png_const_structp png_ptr, png_const_infop info_ptr, + png_colorp *palette, int *num_palette)); + +PNG_EXPORT(152, void, png_set_PLTE, + (png_structp png_ptr, png_infop info_ptr, + png_const_colorp palette, int num_palette)); + +#ifdef PNG_sBIT_SUPPORTED +PNG_EXPORT(153, png_uint_32, png_get_sBIT, + (png_const_structp png_ptr, png_infop info_ptr, + png_color_8p *sig_bit)); +#endif + +#ifdef PNG_sBIT_SUPPORTED +PNG_EXPORT(154, void, png_set_sBIT, + (png_structp png_ptr, png_infop info_ptr, png_const_color_8p sig_bit)); +#endif + +#ifdef PNG_sRGB_SUPPORTED +PNG_EXPORT(155, png_uint_32, png_get_sRGB, (png_const_structp png_ptr, + png_const_infop info_ptr, int *file_srgb_intent)); +#endif + +#ifdef PNG_sRGB_SUPPORTED +PNG_EXPORT(156, void, png_set_sRGB, + (png_structp png_ptr, png_infop info_ptr, int srgb_intent)); +PNG_EXPORT(157, void, png_set_sRGB_gAMA_and_cHRM, (png_structp png_ptr, + png_infop info_ptr, int srgb_intent)); +#endif + +#ifdef PNG_iCCP_SUPPORTED +PNG_EXPORT(158, png_uint_32, png_get_iCCP, + (png_const_structp png_ptr, png_const_infop info_ptr, + png_charpp name, int *compression_type, png_bytepp profile, + png_uint_32 *proflen)); +#endif + +#ifdef PNG_iCCP_SUPPORTED +PNG_EXPORT(159, void, png_set_iCCP, + (png_structp png_ptr, png_infop info_ptr, + png_const_charp name, int compression_type, png_const_bytep profile, + png_uint_32 proflen)); +#endif + +#ifdef PNG_sPLT_SUPPORTED +PNG_EXPORT(160, png_uint_32, png_get_sPLT, + (png_const_structp png_ptr, png_const_infop info_ptr, + png_sPLT_tpp entries)); +#endif + +#ifdef PNG_sPLT_SUPPORTED +PNG_EXPORT(161, void, png_set_sPLT, + (png_structp png_ptr, png_infop info_ptr, + png_const_sPLT_tp entries, int nentries)); +#endif + +#ifdef PNG_TEXT_SUPPORTED +/* png_get_text also returns the number of text chunks in *num_text */ +PNG_EXPORT(162, png_uint_32, png_get_text, + (png_const_structp png_ptr, png_const_infop info_ptr, + png_textp *text_ptr, int *num_text)); +#endif + +/* Note while png_set_text() will accept a structure whose text, + * language, and translated keywords are NULL pointers, the structure + * returned by png_get_text will always contain regular + * zero-terminated C strings. They might be empty strings but + * they will never be NULL pointers. + */ + +#ifdef PNG_TEXT_SUPPORTED +PNG_EXPORT(163, void, png_set_text, + (png_structp png_ptr, png_infop info_ptr, + png_const_textp text_ptr, int num_text)); +#endif + +#ifdef PNG_tIME_SUPPORTED +PNG_EXPORT(164, png_uint_32, png_get_tIME, + (png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time)); +#endif + +#ifdef PNG_tIME_SUPPORTED +PNG_EXPORT(165, void, png_set_tIME, + (png_structp png_ptr, png_infop info_ptr, png_const_timep mod_time)); +#endif + +#ifdef PNG_tRNS_SUPPORTED +PNG_EXPORT(166, png_uint_32, png_get_tRNS, + (png_const_structp png_ptr, png_infop info_ptr, + png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)); +#endif + +#ifdef PNG_tRNS_SUPPORTED +PNG_EXPORT(167, void, png_set_tRNS, + (png_structp png_ptr, png_infop info_ptr, + png_const_bytep trans_alpha, int num_trans, + png_const_color_16p trans_color)); +#endif + +#ifdef PNG_sCAL_SUPPORTED +PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, + (png_const_structp png_ptr, png_const_infop info_ptr, + int *unit, double *width, double *height)) +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED +/* NOTE: this API is currently implemented using floating point arithmetic, + * consequently it can only be used on systems with floating point support. + * In any case the range of values supported by png_fixed_point is small and it + * is highly recommended that png_get_sCAL_s be used instead. + */ +PNG_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed, + (png_structp png_ptr, png_const_infop info_ptr, int *unit, + png_fixed_point *width, + png_fixed_point *height)) +#endif +PNG_EXPORT(169, png_uint_32, png_get_sCAL_s, + (png_const_structp png_ptr, png_const_infop info_ptr, + int *unit, png_charpp swidth, png_charpp sheight)); + +PNG_FP_EXPORT(170, void, png_set_sCAL, + (png_structp png_ptr, png_infop info_ptr, + int unit, double width, double height)) +PNG_FIXED_EXPORT(213, void, png_set_sCAL_fixed, (png_structp png_ptr, + png_infop info_ptr, int unit, png_fixed_point width, + png_fixed_point height)) +PNG_EXPORT(171, void, png_set_sCAL_s, + (png_structp png_ptr, png_infop info_ptr, + int unit, png_const_charp swidth, png_const_charp sheight)); +#endif /* PNG_sCAL_SUPPORTED */ + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +/* Provide a list of chunks and how they are to be handled, if the built-in + handling or default unknown chunk handling is not desired. Any chunks not + listed will be handled in the default manner. The IHDR and IEND chunks + must not be listed. Because this turns off the default handling for chunks + that would otherwise be recognized the behavior of libpng transformations may + well become incorrect! + keep = 0: PNG_HANDLE_CHUNK_AS_DEFAULT: follow default behavior + = 1: PNG_HANDLE_CHUNK_NEVER: do not keep + = 2: PNG_HANDLE_CHUNK_IF_SAFE: keep only if safe-to-copy + = 3: PNG_HANDLE_CHUNK_ALWAYS: keep even if unsafe-to-copy +*/ +PNG_EXPORT(172, void, png_set_keep_unknown_chunks, + (png_structp png_ptr, int keep, + png_const_bytep chunk_list, int num_chunks)); + +/* The handling code is returned; the result is therefore true (non-zero) if + * special handling is required, false for the default handling. + */ +PNG_EXPORT(173, int, png_handle_as_unknown, (png_structp png_ptr, + png_const_bytep chunk_name)); +#endif +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED +PNG_EXPORT(174, void, png_set_unknown_chunks, (png_structp png_ptr, + png_infop info_ptr, png_const_unknown_chunkp unknowns, + int num_unknowns)); +PNG_EXPORT(175, void, png_set_unknown_chunk_location, + (png_structp png_ptr, png_infop info_ptr, int chunk, int location)); +PNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structp png_ptr, + png_const_infop info_ptr, png_unknown_chunkpp entries)); +#endif + +/* Png_free_data() will turn off the "valid" flag for anything it frees. + * If you need to turn it off for a chunk that your application has freed, + * you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK); + */ +PNG_EXPORT(177, void, png_set_invalid, + (png_structp png_ptr, png_infop info_ptr, int mask)); + +#ifdef PNG_INFO_IMAGE_SUPPORTED +/* The "params" pointer is currently not used and is for future expansion. */ +PNG_EXPORT(178, void, png_read_png, (png_structp png_ptr, png_infop info_ptr, + int transforms, png_voidp params)); +PNG_EXPORT(179, void, png_write_png, (png_structp png_ptr, png_infop info_ptr, + int transforms, png_voidp params)); +#endif + +PNG_EXPORT(180, png_const_charp, png_get_copyright, + (png_const_structp png_ptr)); +PNG_EXPORT(181, png_const_charp, png_get_header_ver, + (png_const_structp png_ptr)); +PNG_EXPORT(182, png_const_charp, png_get_header_version, + (png_const_structp png_ptr)); +PNG_EXPORT(183, png_const_charp, png_get_libpng_ver, + (png_const_structp png_ptr)); + +#ifdef PNG_MNG_FEATURES_SUPPORTED +PNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structp png_ptr, + png_uint_32 mng_features_permitted)); +#endif + +/* For use in png_set_keep_unknown, added to version 1.2.6 */ +#define PNG_HANDLE_CHUNK_AS_DEFAULT 0 +#define PNG_HANDLE_CHUNK_NEVER 1 +#define PNG_HANDLE_CHUNK_IF_SAFE 2 +#define PNG_HANDLE_CHUNK_ALWAYS 3 + +/* Strip the prepended error numbers ("#nnn ") from error and warning + * messages before passing them to the error or warning handler. + */ +#ifdef PNG_ERROR_NUMBERS_SUPPORTED +PNG_EXPORT(185, void, png_set_strip_error_numbers, + (png_structp png_ptr, + png_uint_32 strip_mode)); +#endif + +/* Added in libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED +PNG_EXPORT(186, void, png_set_user_limits, (png_structp png_ptr, + png_uint_32 user_width_max, png_uint_32 user_height_max)); +PNG_EXPORT(187, png_uint_32, png_get_user_width_max, + (png_const_structp png_ptr)); +PNG_EXPORT(188, png_uint_32, png_get_user_height_max, + (png_const_structp png_ptr)); +/* Added in libpng-1.4.0 */ +PNG_EXPORT(189, void, png_set_chunk_cache_max, (png_structp png_ptr, + png_uint_32 user_chunk_cache_max)); +PNG_EXPORT(190, png_uint_32, png_get_chunk_cache_max, + (png_const_structp png_ptr)); +/* Added in libpng-1.4.1 */ +PNG_EXPORT(191, void, png_set_chunk_malloc_max, (png_structp png_ptr, + png_alloc_size_t user_chunk_cache_max)); +PNG_EXPORT(192, png_alloc_size_t, png_get_chunk_malloc_max, + (png_const_structp png_ptr)); +#endif + +#if defined(PNG_INCH_CONVERSIONS_SUPPORTED) +PNG_EXPORT(193, png_uint_32, png_get_pixels_per_inch, + (png_const_structp png_ptr, png_const_infop info_ptr)); + +PNG_EXPORT(194, png_uint_32, png_get_x_pixels_per_inch, + (png_const_structp png_ptr, png_const_infop info_ptr)); + +PNG_EXPORT(195, png_uint_32, png_get_y_pixels_per_inch, + (png_const_structp png_ptr, png_const_infop info_ptr)); + +PNG_FP_EXPORT(196, float, png_get_x_offset_inches, + (png_const_structp png_ptr, png_const_infop info_ptr)) +#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */ +PNG_FIXED_EXPORT(211, png_fixed_point, png_get_x_offset_inches_fixed, + (png_structp png_ptr, png_const_infop info_ptr)) +#endif + +PNG_FP_EXPORT(197, float, png_get_y_offset_inches, (png_const_structp png_ptr, + png_const_infop info_ptr)) +#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */ +PNG_FIXED_EXPORT(212, png_fixed_point, png_get_y_offset_inches_fixed, + (png_structp png_ptr, png_const_infop info_ptr)) +#endif + +# ifdef PNG_pHYs_SUPPORTED +PNG_EXPORT(198, png_uint_32, png_get_pHYs_dpi, (png_const_structp png_ptr, + png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, + int *unit_type)); +# endif /* PNG_pHYs_SUPPORTED */ +#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */ + +/* Added in libpng-1.4.0 */ +#ifdef PNG_IO_STATE_SUPPORTED +PNG_EXPORT(199, png_uint_32, png_get_io_state, (png_structp png_ptr)); + +PNG_EXPORTA(200, png_const_bytep, png_get_io_chunk_name, + (png_structp png_ptr), PNG_DEPRECATED); +PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type, + (png_const_structp png_ptr)); + +/* The flags returned by png_get_io_state() are the following: */ +# define PNG_IO_NONE 0x0000 /* no I/O at this moment */ +# define PNG_IO_READING 0x0001 /* currently reading */ +# define PNG_IO_WRITING 0x0002 /* currently writing */ +# define PNG_IO_SIGNATURE 0x0010 /* currently at the file signature */ +# define PNG_IO_CHUNK_HDR 0x0020 /* currently at the chunk header */ +# define PNG_IO_CHUNK_DATA 0x0040 /* currently at the chunk data */ +# define PNG_IO_CHUNK_CRC 0x0080 /* currently at the chunk crc */ +# define PNG_IO_MASK_OP 0x000f /* current operation: reading/writing */ +# define PNG_IO_MASK_LOC 0x00f0 /* current location: sig/hdr/data/crc */ +#endif /* ?PNG_IO_STATE_SUPPORTED */ + +/* Interlace support. The following macros are always defined so that if + * libpng interlace handling is turned off the macros may be used to handle + * interlaced images within the application. + */ +#define PNG_INTERLACE_ADAM7_PASSES 7 + +/* Two macros to return the first row and first column of the original, + * full, image which appears in a given pass. 'pass' is in the range 0 + * to 6 and the result is in the range 0 to 7. + */ +#define PNG_PASS_START_ROW(pass) (((1&~(pass))<<(3-((pass)>>1)))&7) +#define PNG_PASS_START_COL(pass) (((1& (pass))<<(3-(((pass)+1)>>1)))&7) + +/* A macro to return the offset between pixels in the output row for a pair of + * pixels in the input - effectively the inverse of the 'COL_SHIFT' macro that + * follows. Note that ROW_OFFSET is the offset from one row to the next whereas + * COL_OFFSET is from one column to the next, within a row. + */ +#define PNG_PASS_ROW_OFFSET(pass) ((pass)>2?(8>>(((pass)-1)>>1)):8) +#define PNG_PASS_COL_OFFSET(pass) (1<<((7-(pass))>>1)) + +/* Two macros to help evaluate the number of rows or columns in each + * pass. This is expressed as a shift - effectively log2 of the number or + * rows or columns in each 8x8 tile of the original image. + */ +#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3) +#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3) + +/* Hence two macros to determine the number of rows or columns in a given + * pass of an image given its height or width. In fact these macros may + * return non-zero even though the sub-image is empty, because the other + * dimension may be empty for a small image. + */ +#define PNG_PASS_ROWS(height, pass) (((height)+(((1<>PNG_PASS_ROW_SHIFT(pass)) +#define PNG_PASS_COLS(width, pass) (((width)+(((1<>PNG_PASS_COL_SHIFT(pass)) + +/* For the reader row callbacks (both progressive and sequential) it is + * necessary to find the row in the output image given a row in an interlaced + * image, so two more macros: + */ +#define PNG_ROW_FROM_PASS_ROW(yIn, pass) \ + (((yIn)<>(((7-(off))-(pass))<<2)) & 0xF) | \ + ((0x01145AF0>>(((7-(off))-(pass))<<2)) & 0xF0)) + +#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \ + ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1) +#define PNG_COL_IN_INTERLACE_PASS(x, pass) \ + ((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1) + +#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED +/* With these routines we avoid an integer divide, which will be slower on + * most machines. However, it does take more operations than the corresponding + * divide method, so it may be slower on a few RISC systems. There are two + * shifts (by 8 or 16 bits) and an addition, versus a single integer divide. + * + * Note that the rounding factors are NOT supposed to be the same! 128 and + * 32768 are correct for the NODIV code; 127 and 32767 are correct for the + * standard method. + * + * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ] + */ + + /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */ + +# define png_composite(composite, fg, alpha, bg) \ + { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) \ + * (png_uint_16)(alpha) \ + + (png_uint_16)(bg)*(png_uint_16)(255 \ + - (png_uint_16)(alpha)) + 128); \ + (composite) = (png_byte)((temp + (temp >> 8)) >> 8); } + +# define png_composite_16(composite, fg, alpha, bg) \ + { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) \ + * (png_uint_32)(alpha) \ + + (png_uint_32)(bg)*(65535 \ + - (png_uint_32)(alpha)) + 32768); \ + (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); } + +#else /* Standard method using integer division */ + +# define png_composite(composite, fg, alpha, bg) \ + (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \ + (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \ + 127) / 255) + +# define png_composite_16(composite, fg, alpha, bg) \ + (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \ + (png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) + \ + 32767) / 65535) +#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */ + +#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED +PNG_EXPORT(201, png_uint_32, png_get_uint_32, (png_const_bytep buf)); +PNG_EXPORT(202, png_uint_16, png_get_uint_16, (png_const_bytep buf)); +PNG_EXPORT(203, png_int_32, png_get_int_32, (png_const_bytep buf)); +#endif + +PNG_EXPORT(204, png_uint_32, png_get_uint_31, (png_structp png_ptr, + png_const_bytep buf)); +/* No png_get_int_16 -- may be added if there's a real need for it. */ + +/* Place a 32-bit number into a buffer in PNG byte order (big-endian). */ +#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED +PNG_EXPORT(205, void, png_save_uint_32, (png_bytep buf, png_uint_32 i)); +#endif +#ifdef PNG_SAVE_INT_32_SUPPORTED +PNG_EXPORT(206, void, png_save_int_32, (png_bytep buf, png_int_32 i)); +#endif + +/* Place a 16-bit number into a buffer in PNG byte order. + * The parameter is declared unsigned int, not png_uint_16, + * just to avoid potential problems on pre-ANSI C compilers. + */ +#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED +PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i)); +/* No png_save_int_16 -- may be added if there's a real need for it. */ +#endif + +#ifdef PNG_USE_READ_MACROS +/* Inline macros to do direct reads of bytes from the input buffer. + * The png_get_int_32() routine assumes we are using two's complement + * format for negative values, which is almost certainly true. + */ +# define png_get_uint_32(buf) \ + (((png_uint_32)(*(buf)) << 24) + \ + ((png_uint_32)(*((buf) + 1)) << 16) + \ + ((png_uint_32)(*((buf) + 2)) << 8) + \ + ((png_uint_32)(*((buf) + 3)))) + + /* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the + * function) incorrectly returned a value of type png_uint_32. + */ +# define png_get_uint_16(buf) \ + ((png_uint_16) \ + (((unsigned int)(*(buf)) << 8) + \ + ((unsigned int)(*((buf) + 1))))) + +# define png_get_int_32(buf) \ + ((png_int_32)((*(buf) & 0x80) \ + ? -((png_int_32)((png_get_uint_32(buf) ^ 0xffffffffL) + 1)) \ + : (png_int_32)png_get_uint_32(buf))) +#endif + +#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \ + defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED) +PNG_EXPORT(234, void, png_set_check_for_invalid_index, (png_structp png_ptr, + int allowed)); +#endif + +/* Maintainer: Put new public prototypes here ^, in libpng.3, and project + * defs + */ + +/* The last ordinal number (this is the *last* one already used; the next + * one to use is one more than this.) Maintainer, remember to add an entry to + * scripts/symbols.def as well. + */ +#ifdef PNG_EXPORT_LAST_ORDINAL + PNG_EXPORT_LAST_ORDINAL(234); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* PNG_VERSION_INFO_ONLY */ +/* Do not put anything past this line */ +#endif /* PNG_H */ diff --git a/Source/LibPNG/pngconf.h b/Source/LibPNG/pngconf.h index 5298e66..a364928 100644 --- a/Source/LibPNG/pngconf.h +++ b/Source/LibPNG/pngconf.h @@ -1,598 +1,598 @@ - -/* pngconf.h - machine configurable file for libpng - * - * libpng version 1.5.13 - September 27, 2012 - * - * Copyright (c) 1998-2012 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - * - */ - -/* Any machine specific code is near the front of this file, so if you - * are configuring libpng for a machine, you may want to read the section - * starting here down to where it starts to typedef png_color, png_text, - * and png_info. - */ - -#ifndef PNGCONF_H -#define PNGCONF_H - -#ifndef PNG_BUILDING_SYMBOL_TABLE -/* PNG_NO_LIMITS_H may be used to turn off the use of the standard C - * definition file for machine specific limits, this may impact the - * correctness of the definitions below (see uses of INT_MAX). - */ -# ifndef PNG_NO_LIMITS_H -# include -# endif - -/* For the memory copy APIs (i.e. the standard definitions of these), - * because this file defines png_memcpy and so on the base APIs must - * be defined here. - */ -# ifdef BSD -# include -# else -# include -# endif - -/* For png_FILE_p - this provides the standard definition of a - * FILE - */ -# ifdef PNG_STDIO_SUPPORTED -# include -# endif -#endif - -/* This controls optimization of the reading of 16 and 32 bit values - * from PNG files. It can be set on a per-app-file basis - it - * just changes whether a macro is used when the function is called. - * The library builder sets the default; if read functions are not - * built into the library the macro implementation is forced on. - */ -#ifndef PNG_READ_INT_FUNCTIONS_SUPPORTED -# define PNG_USE_READ_MACROS -#endif -#if !defined(PNG_NO_USE_READ_MACROS) && !defined(PNG_USE_READ_MACROS) -# if PNG_DEFAULT_READ_MACROS -# define PNG_USE_READ_MACROS -# endif -#endif - -/* COMPILER SPECIFIC OPTIONS. - * - * These options are provided so that a variety of difficult compilers - * can be used. Some are fixed at build time (e.g. PNG_API_RULE - * below) but still have compiler specific implementations, others - * may be changed on a per-file basis when compiling against libpng. - */ - -/* The PNGARG macro protects us against machines that don't have function - * prototypes (ie K&R style headers). If your compiler does not handle - * function prototypes, define this macro and use the included ansi2knr. - * I've always been able to use _NO_PROTO as the indicator, but you may - * need to drag the empty declaration out in front of here, or change the - * ifdef to suit your own needs. - */ -#ifndef PNGARG - -# ifdef OF /* zlib prototype munger */ -# define PNGARG(arglist) OF(arglist) -# else - -# ifdef _NO_PROTO -# define PNGARG(arglist) () -# else -# define PNGARG(arglist) arglist -# endif /* _NO_PROTO */ - -# endif /* OF */ - -#endif /* PNGARG */ - -/* Function calling conventions. - * ============================= - * Normally it is not necessary to specify to the compiler how to call - * a function - it just does it - however on x86 systems derived from - * Microsoft and Borland C compilers ('IBM PC', 'DOS', 'Windows' systems - * and some others) there are multiple ways to call a function and the - * default can be changed on the compiler command line. For this reason - * libpng specifies the calling convention of every exported function and - * every function called via a user supplied function pointer. This is - * done in this file by defining the following macros: - * - * PNGAPI Calling convention for exported functions. - * PNGCBAPI Calling convention for user provided (callback) functions. - * PNGCAPI Calling convention used by the ANSI-C library (required - * for longjmp callbacks and sometimes used internally to - * specify the calling convention for zlib). - * - * These macros should never be overridden. If it is necessary to - * change calling convention in a private build this can be done - * by setting PNG_API_RULE (which defaults to 0) to one of the values - * below to select the correct 'API' variants. - * - * PNG_API_RULE=0 Use PNGCAPI - the 'C' calling convention - throughout. - * This is correct in every known environment. - * PNG_API_RULE=1 Use the operating system convention for PNGAPI and - * the 'C' calling convention (from PNGCAPI) for - * callbacks (PNGCBAPI). This is no longer required - * in any known environment - if it has to be used - * please post an explanation of the problem to the - * libpng mailing list. - * - * These cases only differ if the operating system does not use the C - * calling convention, at present this just means the above cases - * (x86 DOS/Windows sytems) and, even then, this does not apply to - * Cygwin running on those systems. - * - * Note that the value must be defined in pnglibconf.h so that what - * the application uses to call the library matches the conventions - * set when building the library. - */ - -/* Symbol export - * ============= - * When building a shared library it is almost always necessary to tell - * the compiler which symbols to export. The png.h macro 'PNG_EXPORT' - * is used to mark the symbols. On some systems these symbols can be - * extracted at link time and need no special processing by the compiler, - * on other systems the symbols are flagged by the compiler and just - * the declaration requires a special tag applied (unfortunately) in a - * compiler dependent way. Some systems can do either. - * - * A small number of older systems also require a symbol from a DLL to - * be flagged to the program that calls it. This is a problem because - * we do not know in the header file included by application code that - * the symbol will come from a shared library, as opposed to a statically - * linked one. For this reason the application must tell us by setting - * the magic flag PNG_USE_DLL to turn on the special processing before - * it includes png.h. - * - * Four additional macros are used to make this happen: - * - * PNG_IMPEXP The magic (if any) to cause a symbol to be exported from - * the build or imported if PNG_USE_DLL is set - compiler - * and system specific. - * - * PNG_EXPORT_TYPE(type) A macro that pre or appends PNG_IMPEXP to - * 'type', compiler specific. - * - * PNG_DLL_EXPORT Set to the magic to use during a libpng build to - * make a symbol exported from the DLL. Not used in the - * public header files; see pngpriv.h for how it is used - * in the libpng build. - * - * PNG_DLL_IMPORT Set to the magic to force the libpng symbols to come - * from a DLL - used to define PNG_IMPEXP when - * PNG_USE_DLL is set. - */ - -/* System specific discovery. - * ========================== - * This code is used at build time to find PNG_IMPEXP, the API settings - * and PNG_EXPORT_TYPE(), it may also set a macro to indicate the DLL - * import processing is possible. On Windows/x86 systems it also sets - * compiler-specific macros to the values required to change the calling - * conventions of the various functions. - */ -#if ( defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\ - defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) ) &&\ - ( defined(_X86_) || defined(_X64_) || defined(_M_IX86) ||\ - defined(_M_X64) || defined(_M_IA64) ) - /* Windows system (DOS doesn't support DLLs) running on x86/x64. Includes - * builds under Cygwin or MinGW. Also includes Watcom builds but these need - * special treatment because they are not compatible with GCC or Visual C - * because of different calling conventions. - */ -# if PNG_API_RULE == 2 - /* If this line results in an error, either because __watcall is not - * understood or because of a redefine just below you cannot use *this* - * build of the library with the compiler you are using. *This* build was - * build using Watcom and applications must also be built using Watcom! - */ -# define PNGCAPI __watcall -# endif - -# if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800)) -# define PNGCAPI __cdecl -# if PNG_API_RULE == 1 -# define PNGAPI __stdcall -# endif -# else - /* An older compiler, or one not detected (erroneously) above, - * if necessary override on the command line to get the correct - * variants for the compiler. - */ -# ifndef PNGCAPI -# define PNGCAPI _cdecl -# endif -# if PNG_API_RULE == 1 && !defined(PNGAPI) -# define PNGAPI _stdcall -# endif -# endif /* compiler/api */ - /* NOTE: PNGCBAPI always defaults to PNGCAPI. */ - -# if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD) - ERROR: PNG_USER_PRIVATEBUILD must be defined if PNGAPI is changed -# endif - -# if (defined(_MSC_VER) && _MSC_VER < 800) ||\ - (defined(__BORLANDC__) && __BORLANDC__ < 0x500) - /* older Borland and MSC - * compilers used '__export' and required this to be after - * the type. - */ -# ifndef PNG_EXPORT_TYPE -# define PNG_EXPORT_TYPE(type) type PNG_IMPEXP -# endif -# define PNG_DLL_EXPORT __export -# else /* newer compiler */ -# define PNG_DLL_EXPORT __declspec(dllexport) -# ifndef PNG_DLL_IMPORT -# define PNG_DLL_IMPORT __declspec(dllimport) -# endif -# endif /* compiler */ - -#else /* !Windows/x86 */ -# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__) -# define PNGAPI _System -# else /* !Windows/x86 && !OS/2 */ - /* Use the defaults, or define PNG*API on the command line (but - * this will have to be done for every compile!) - */ -# endif /* other system, !OS/2 */ -#endif /* !Windows/x86 */ - -/* Now do all the defaulting . */ -#ifndef PNGCAPI -# define PNGCAPI -#endif -#ifndef PNGCBAPI -# define PNGCBAPI PNGCAPI -#endif -#ifndef PNGAPI -# define PNGAPI PNGCAPI -#endif - -/* PNG_IMPEXP may be set on the compilation system command line or (if not set) - * then in an internal header file when building the library, otherwise (when - * using the library) it is set here. - */ -#ifndef PNG_IMPEXP -# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT) - /* This forces use of a DLL, disallowing static linking */ -# define PNG_IMPEXP PNG_DLL_IMPORT -# endif - -# ifndef PNG_IMPEXP -# define PNG_IMPEXP -# endif -#endif - -/* In 1.5.2 the definition of PNG_FUNCTION has been changed to always treat - * 'attributes' as a storage class - the attributes go at the start of the - * function definition, and attributes are always appended regardless of the - * compiler. This considerably simplifies these macros but may cause problems - * if any compilers both need function attributes and fail to handle them as - * a storage class (this is unlikely.) - */ -#ifndef PNG_FUNCTION -# define PNG_FUNCTION(type, name, args, attributes) attributes type name args -#endif - -#ifndef PNG_EXPORT_TYPE -# define PNG_EXPORT_TYPE(type) PNG_IMPEXP type -#endif - - /* The ordinal value is only relevant when preprocessing png.h for symbol - * table entries, so we discard it here. See the .dfn files in the - * scripts directory. - */ -#ifndef PNG_EXPORTA - -# define PNG_EXPORTA(ordinal, type, name, args, attributes)\ - PNG_FUNCTION(PNG_EXPORT_TYPE(type),(PNGAPI name),PNGARG(args), \ - extern attributes) -#endif - -/* ANSI-C (C90) does not permit a macro to be invoked with an empty argument, - * so make something non-empty to satisfy the requirement: - */ -#define PNG_EMPTY /*empty list*/ - -#define PNG_EXPORT(ordinal, type, name, args)\ - PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY) - -/* Use PNG_REMOVED to comment out a removed interface. */ -#ifndef PNG_REMOVED -# define PNG_REMOVED(ordinal, type, name, args, attributes) -#endif - -#ifndef PNG_CALLBACK -# define PNG_CALLBACK(type, name, args) type (PNGCBAPI name) PNGARG(args) -#endif - -/* Support for compiler specific function attributes. These are used - * so that where compiler support is available incorrect use of API - * functions in png.h will generate compiler warnings. - * - * Added at libpng-1.2.41. - */ - -#ifndef PNG_NO_PEDANTIC_WARNINGS -# ifndef PNG_PEDANTIC_WARNINGS_SUPPORTED -# define PNG_PEDANTIC_WARNINGS_SUPPORTED -# endif -#endif - -#ifdef PNG_PEDANTIC_WARNINGS_SUPPORTED - /* Support for compiler specific function attributes. These are used - * so that where compiler support is available incorrect use of API - * functions in png.h will generate compiler warnings. Added at libpng - * version 1.2.41. - */ -# if defined(__GNUC__) -# ifndef PNG_USE_RESULT -# define PNG_USE_RESULT __attribute__((__warn_unused_result__)) -# endif -# ifndef PNG_NORETURN -# define PNG_NORETURN __attribute__((__noreturn__)) -# endif -# if __GNUC__ >= 3 -# ifndef PNG_ALLOCATED -# define PNG_ALLOCATED __attribute__((__malloc__)) -# endif -# ifndef PNG_DEPRECATED -# define PNG_DEPRECATED __attribute__((__deprecated__)) -# endif -# ifndef PNG_PRIVATE -# if 0 /* Doesn't work so we use deprecated instead*/ -# define PNG_PRIVATE \ - __attribute__((warning("This function is not exported by libpng."))) -# else -# define PNG_PRIVATE \ - __attribute__((__deprecated__)) -# endif -# endif -# endif /* __GNUC__ >= 3 */ -# endif /* __GNUC__ */ - -# if defined(_MSC_VER) && (_MSC_VER >= 1300) -# ifndef PNG_USE_RESULT -# define PNG_USE_RESULT /* not supported */ -# endif -# ifndef PNG_NORETURN -# define PNG_NORETURN __declspec(noreturn) -# endif -# ifndef PNG_ALLOCATED -# if (_MSC_VER >= 1400) -# define PNG_ALLOCATED __declspec(restrict) -# endif -# endif -# ifndef PNG_DEPRECATED -# define PNG_DEPRECATED __declspec(deprecated) -# endif -# ifndef PNG_PRIVATE -# define PNG_PRIVATE __declspec(deprecated) -# endif -# endif /* _MSC_VER */ -#endif /* PNG_PEDANTIC_WARNINGS */ - -#ifndef PNG_DEPRECATED -# define PNG_DEPRECATED /* Use of this function is deprecated */ -#endif -#ifndef PNG_USE_RESULT -# define PNG_USE_RESULT /* The result of this function must be checked */ -#endif -#ifndef PNG_NORETURN -# define PNG_NORETURN /* This function does not return */ -#endif -#ifndef PNG_ALLOCATED -# define PNG_ALLOCATED /* The result of the function is new memory */ -#endif -#ifndef PNG_PRIVATE -# define PNG_PRIVATE /* This is a private libpng function */ -#endif -#ifndef PNG_FP_EXPORT /* A floating point API. */ -# ifdef PNG_FLOATING_POINT_SUPPORTED -# define PNG_FP_EXPORT(ordinal, type, name, args)\ - PNG_EXPORT(ordinal, type, name, args); -# else /* No floating point APIs */ -# define PNG_FP_EXPORT(ordinal, type, name, args) -# endif -#endif -#ifndef PNG_FIXED_EXPORT /* A fixed point API. */ -# ifdef PNG_FIXED_POINT_SUPPORTED -# define PNG_FIXED_EXPORT(ordinal, type, name, args)\ - PNG_EXPORT(ordinal, type, name, args); -# else /* No fixed point APIs */ -# define PNG_FIXED_EXPORT(ordinal, type, name, args) -# endif -#endif - -/* The following uses const char * instead of char * for error - * and warning message functions, so some compilers won't complain. - * If you do not want to use const, define PNG_NO_CONST here. - * - * This should not change how the APIs are called, so it can be done - * on a per-file basis in the application. - */ -#ifndef PNG_CONST -# ifndef PNG_NO_CONST -# define PNG_CONST const -# else -# define PNG_CONST -# endif -#endif - -/* Some typedefs to get us started. These should be safe on most of the - * common platforms. The typedefs should be at least as large as the - * numbers suggest (a png_uint_32 must be at least 32 bits long), but they - * don't have to be exactly that size. Some compilers dislike passing - * unsigned shorts as function parameters, so you may be better off using - * unsigned int for png_uint_16. - */ - -#if defined(INT_MAX) && (INT_MAX > 0x7ffffffeL) -typedef unsigned int png_uint_32; -typedef int png_int_32; -#else -typedef unsigned long png_uint_32; -typedef long png_int_32; -#endif -typedef unsigned short png_uint_16; -typedef short png_int_16; -typedef unsigned char png_byte; - -#ifdef PNG_NO_SIZE_T -typedef unsigned int png_size_t; -#else -typedef size_t png_size_t; -#endif -#define png_sizeof(x) (sizeof (x)) - -/* The following is needed for medium model support. It cannot be in the - * pngpriv.h header. Needs modification for other compilers besides - * MSC. Model independent support declares all arrays and pointers to be - * large using the far keyword. The zlib version used must also support - * model independent data. As of version zlib 1.0.4, the necessary changes - * have been made in zlib. The USE_FAR_KEYWORD define triggers other - * changes that are needed. (Tim Wegner) - */ - -/* Separate compiler dependencies (problem here is that zlib.h always - * defines FAR. (SJT) - */ -#ifdef __BORLANDC__ -# if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__) -# define LDATA 1 -# else -# define LDATA 0 -# endif - /* GRR: why is Cygwin in here? Cygwin is not Borland C... */ -# if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__) -# define PNG_MAX_MALLOC_64K /* only used in build */ -# if (LDATA != 1) -# ifndef FAR -# define FAR __far -# endif -# define USE_FAR_KEYWORD -# endif /* LDATA != 1 */ - /* Possibly useful for moving data out of default segment. - * Uncomment it if you want. Could also define FARDATA as - * const if your compiler supports it. (SJT) -# define FARDATA FAR - */ -# endif /* __WIN32__, __FLAT__, __CYGWIN__ */ -#endif /* __BORLANDC__ */ - - -/* Suggest testing for specific compiler first before testing for - * FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM, - * making reliance oncertain keywords suspect. (SJT) - */ - -/* MSC Medium model */ -#ifdef FAR -# ifdef M_I86MM -# define USE_FAR_KEYWORD -# define FARDATA FAR -# include -# endif -#endif - -/* SJT: default case */ -#ifndef FAR -# define FAR -#endif - -/* At this point FAR is always defined */ -#ifndef FARDATA -# define FARDATA -#endif - -/* Typedef for floating-point numbers that are converted - * to fixed-point with a multiple of 100,000, e.g., gamma - */ -typedef png_int_32 png_fixed_point; - -/* Add typedefs for pointers */ -typedef void FAR * png_voidp; -typedef PNG_CONST void FAR * png_const_voidp; -typedef png_byte FAR * png_bytep; -typedef PNG_CONST png_byte FAR * png_const_bytep; -typedef png_uint_32 FAR * png_uint_32p; -typedef PNG_CONST png_uint_32 FAR * png_const_uint_32p; -typedef png_int_32 FAR * png_int_32p; -typedef PNG_CONST png_int_32 FAR * png_const_int_32p; -typedef png_uint_16 FAR * png_uint_16p; -typedef PNG_CONST png_uint_16 FAR * png_const_uint_16p; -typedef png_int_16 FAR * png_int_16p; -typedef PNG_CONST png_int_16 FAR * png_const_int_16p; -typedef char FAR * png_charp; -typedef PNG_CONST char FAR * png_const_charp; -typedef png_fixed_point FAR * png_fixed_point_p; -typedef PNG_CONST png_fixed_point FAR * png_const_fixed_point_p; -typedef png_size_t FAR * png_size_tp; -typedef PNG_CONST png_size_t FAR * png_const_size_tp; - -#ifdef PNG_STDIO_SUPPORTED -typedef FILE * png_FILE_p; -#endif - -#ifdef PNG_FLOATING_POINT_SUPPORTED -typedef double FAR * png_doublep; -typedef PNG_CONST double FAR * png_const_doublep; -#endif - -/* Pointers to pointers; i.e. arrays */ -typedef png_byte FAR * FAR * png_bytepp; -typedef png_uint_32 FAR * FAR * png_uint_32pp; -typedef png_int_32 FAR * FAR * png_int_32pp; -typedef png_uint_16 FAR * FAR * png_uint_16pp; -typedef png_int_16 FAR * FAR * png_int_16pp; -typedef PNG_CONST char FAR * FAR * png_const_charpp; -typedef char FAR * FAR * png_charpp; -typedef png_fixed_point FAR * FAR * png_fixed_point_pp; -#ifdef PNG_FLOATING_POINT_SUPPORTED -typedef double FAR * FAR * png_doublepp; -#endif - -/* Pointers to pointers to pointers; i.e., pointer to array */ -typedef char FAR * FAR * FAR * png_charppp; - -/* png_alloc_size_t is guaranteed to be no smaller than png_size_t, - * and no smaller than png_uint_32. Casts from png_size_t or png_uint_32 - * to png_alloc_size_t are not necessary; in fact, it is recommended - * not to use them at all so that the compiler can complain when something - * turns out to be problematic. - * Casts in the other direction (from png_alloc_size_t to png_size_t or - * png_uint_32) should be explicitly applied; however, we do not expect - * to encounter practical situations that require such conversions. - */ -#if defined(__TURBOC__) && !defined(__FLAT__) - typedef unsigned long png_alloc_size_t; -#else -# if defined(_MSC_VER) && defined(MAXSEG_64K) - typedef unsigned long png_alloc_size_t; -# else - /* This is an attempt to detect an old Windows system where (int) is - * actually 16 bits, in that case png_malloc must have an argument with a - * bigger size to accomodate the requirements of the library. - */ -# if (defined(_Windows) || defined(_WINDOWS) || defined(_WINDOWS_)) && \ - (!defined(INT_MAX) || INT_MAX <= 0x7ffffffeL) - typedef DWORD png_alloc_size_t; -# else - typedef png_size_t png_alloc_size_t; -# endif -# endif -#endif - -#endif /* PNGCONF_H */ + +/* pngconf.h - machine configurable file for libpng + * + * libpng version 1.5.13 - September 27, 2012 + * + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + */ + +/* Any machine specific code is near the front of this file, so if you + * are configuring libpng for a machine, you may want to read the section + * starting here down to where it starts to typedef png_color, png_text, + * and png_info. + */ + +#ifndef PNGCONF_H +#define PNGCONF_H + +#ifndef PNG_BUILDING_SYMBOL_TABLE +/* PNG_NO_LIMITS_H may be used to turn off the use of the standard C + * definition file for machine specific limits, this may impact the + * correctness of the definitions below (see uses of INT_MAX). + */ +# ifndef PNG_NO_LIMITS_H +# include +# endif + +/* For the memory copy APIs (i.e. the standard definitions of these), + * because this file defines png_memcpy and so on the base APIs must + * be defined here. + */ +# ifdef BSD +# include +# else +# include +# endif + +/* For png_FILE_p - this provides the standard definition of a + * FILE + */ +# ifdef PNG_STDIO_SUPPORTED +# include +# endif +#endif + +/* This controls optimization of the reading of 16 and 32 bit values + * from PNG files. It can be set on a per-app-file basis - it + * just changes whether a macro is used when the function is called. + * The library builder sets the default; if read functions are not + * built into the library the macro implementation is forced on. + */ +#ifndef PNG_READ_INT_FUNCTIONS_SUPPORTED +# define PNG_USE_READ_MACROS +#endif +#if !defined(PNG_NO_USE_READ_MACROS) && !defined(PNG_USE_READ_MACROS) +# if PNG_DEFAULT_READ_MACROS +# define PNG_USE_READ_MACROS +# endif +#endif + +/* COMPILER SPECIFIC OPTIONS. + * + * These options are provided so that a variety of difficult compilers + * can be used. Some are fixed at build time (e.g. PNG_API_RULE + * below) but still have compiler specific implementations, others + * may be changed on a per-file basis when compiling against libpng. + */ + +/* The PNGARG macro protects us against machines that don't have function + * prototypes (ie K&R style headers). If your compiler does not handle + * function prototypes, define this macro and use the included ansi2knr. + * I've always been able to use _NO_PROTO as the indicator, but you may + * need to drag the empty declaration out in front of here, or change the + * ifdef to suit your own needs. + */ +#ifndef PNGARG + +# ifdef OF /* zlib prototype munger */ +# define PNGARG(arglist) OF(arglist) +# else + +# ifdef _NO_PROTO +# define PNGARG(arglist) () +# else +# define PNGARG(arglist) arglist +# endif /* _NO_PROTO */ + +# endif /* OF */ + +#endif /* PNGARG */ + +/* Function calling conventions. + * ============================= + * Normally it is not necessary to specify to the compiler how to call + * a function - it just does it - however on x86 systems derived from + * Microsoft and Borland C compilers ('IBM PC', 'DOS', 'Windows' systems + * and some others) there are multiple ways to call a function and the + * default can be changed on the compiler command line. For this reason + * libpng specifies the calling convention of every exported function and + * every function called via a user supplied function pointer. This is + * done in this file by defining the following macros: + * + * PNGAPI Calling convention for exported functions. + * PNGCBAPI Calling convention for user provided (callback) functions. + * PNGCAPI Calling convention used by the ANSI-C library (required + * for longjmp callbacks and sometimes used internally to + * specify the calling convention for zlib). + * + * These macros should never be overridden. If it is necessary to + * change calling convention in a private build this can be done + * by setting PNG_API_RULE (which defaults to 0) to one of the values + * below to select the correct 'API' variants. + * + * PNG_API_RULE=0 Use PNGCAPI - the 'C' calling convention - throughout. + * This is correct in every known environment. + * PNG_API_RULE=1 Use the operating system convention for PNGAPI and + * the 'C' calling convention (from PNGCAPI) for + * callbacks (PNGCBAPI). This is no longer required + * in any known environment - if it has to be used + * please post an explanation of the problem to the + * libpng mailing list. + * + * These cases only differ if the operating system does not use the C + * calling convention, at present this just means the above cases + * (x86 DOS/Windows sytems) and, even then, this does not apply to + * Cygwin running on those systems. + * + * Note that the value must be defined in pnglibconf.h so that what + * the application uses to call the library matches the conventions + * set when building the library. + */ + +/* Symbol export + * ============= + * When building a shared library it is almost always necessary to tell + * the compiler which symbols to export. The png.h macro 'PNG_EXPORT' + * is used to mark the symbols. On some systems these symbols can be + * extracted at link time and need no special processing by the compiler, + * on other systems the symbols are flagged by the compiler and just + * the declaration requires a special tag applied (unfortunately) in a + * compiler dependent way. Some systems can do either. + * + * A small number of older systems also require a symbol from a DLL to + * be flagged to the program that calls it. This is a problem because + * we do not know in the header file included by application code that + * the symbol will come from a shared library, as opposed to a statically + * linked one. For this reason the application must tell us by setting + * the magic flag PNG_USE_DLL to turn on the special processing before + * it includes png.h. + * + * Four additional macros are used to make this happen: + * + * PNG_IMPEXP The magic (if any) to cause a symbol to be exported from + * the build or imported if PNG_USE_DLL is set - compiler + * and system specific. + * + * PNG_EXPORT_TYPE(type) A macro that pre or appends PNG_IMPEXP to + * 'type', compiler specific. + * + * PNG_DLL_EXPORT Set to the magic to use during a libpng build to + * make a symbol exported from the DLL. Not used in the + * public header files; see pngpriv.h for how it is used + * in the libpng build. + * + * PNG_DLL_IMPORT Set to the magic to force the libpng symbols to come + * from a DLL - used to define PNG_IMPEXP when + * PNG_USE_DLL is set. + */ + +/* System specific discovery. + * ========================== + * This code is used at build time to find PNG_IMPEXP, the API settings + * and PNG_EXPORT_TYPE(), it may also set a macro to indicate the DLL + * import processing is possible. On Windows/x86 systems it also sets + * compiler-specific macros to the values required to change the calling + * conventions of the various functions. + */ +#if ( defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\ + defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) ) &&\ + ( defined(_X86_) || defined(_X64_) || defined(_M_IX86) ||\ + defined(_M_X64) || defined(_M_IA64) ) + /* Windows system (DOS doesn't support DLLs) running on x86/x64. Includes + * builds under Cygwin or MinGW. Also includes Watcom builds but these need + * special treatment because they are not compatible with GCC or Visual C + * because of different calling conventions. + */ +# if PNG_API_RULE == 2 + /* If this line results in an error, either because __watcall is not + * understood or because of a redefine just below you cannot use *this* + * build of the library with the compiler you are using. *This* build was + * build using Watcom and applications must also be built using Watcom! + */ +# define PNGCAPI __watcall +# endif + +# if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800)) +# define PNGCAPI __cdecl +# if PNG_API_RULE == 1 +# define PNGAPI __stdcall +# endif +# else + /* An older compiler, or one not detected (erroneously) above, + * if necessary override on the command line to get the correct + * variants for the compiler. + */ +# ifndef PNGCAPI +# define PNGCAPI _cdecl +# endif +# if PNG_API_RULE == 1 && !defined(PNGAPI) +# define PNGAPI _stdcall +# endif +# endif /* compiler/api */ + /* NOTE: PNGCBAPI always defaults to PNGCAPI. */ + +# if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD) + ERROR: PNG_USER_PRIVATEBUILD must be defined if PNGAPI is changed +# endif + +# if (defined(_MSC_VER) && _MSC_VER < 800) ||\ + (defined(__BORLANDC__) && __BORLANDC__ < 0x500) + /* older Borland and MSC + * compilers used '__export' and required this to be after + * the type. + */ +# ifndef PNG_EXPORT_TYPE +# define PNG_EXPORT_TYPE(type) type PNG_IMPEXP +# endif +# define PNG_DLL_EXPORT __export +# else /* newer compiler */ +# define PNG_DLL_EXPORT __declspec(dllexport) +# ifndef PNG_DLL_IMPORT +# define PNG_DLL_IMPORT __declspec(dllimport) +# endif +# endif /* compiler */ + +#else /* !Windows/x86 */ +# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__) +# define PNGAPI _System +# else /* !Windows/x86 && !OS/2 */ + /* Use the defaults, or define PNG*API on the command line (but + * this will have to be done for every compile!) + */ +# endif /* other system, !OS/2 */ +#endif /* !Windows/x86 */ + +/* Now do all the defaulting . */ +#ifndef PNGCAPI +# define PNGCAPI +#endif +#ifndef PNGCBAPI +# define PNGCBAPI PNGCAPI +#endif +#ifndef PNGAPI +# define PNGAPI PNGCAPI +#endif + +/* PNG_IMPEXP may be set on the compilation system command line or (if not set) + * then in an internal header file when building the library, otherwise (when + * using the library) it is set here. + */ +#ifndef PNG_IMPEXP +# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT) + /* This forces use of a DLL, disallowing static linking */ +# define PNG_IMPEXP PNG_DLL_IMPORT +# endif + +# ifndef PNG_IMPEXP +# define PNG_IMPEXP +# endif +#endif + +/* In 1.5.2 the definition of PNG_FUNCTION has been changed to always treat + * 'attributes' as a storage class - the attributes go at the start of the + * function definition, and attributes are always appended regardless of the + * compiler. This considerably simplifies these macros but may cause problems + * if any compilers both need function attributes and fail to handle them as + * a storage class (this is unlikely.) + */ +#ifndef PNG_FUNCTION +# define PNG_FUNCTION(type, name, args, attributes) attributes type name args +#endif + +#ifndef PNG_EXPORT_TYPE +# define PNG_EXPORT_TYPE(type) PNG_IMPEXP type +#endif + + /* The ordinal value is only relevant when preprocessing png.h for symbol + * table entries, so we discard it here. See the .dfn files in the + * scripts directory. + */ +#ifndef PNG_EXPORTA + +# define PNG_EXPORTA(ordinal, type, name, args, attributes)\ + PNG_FUNCTION(PNG_EXPORT_TYPE(type),(PNGAPI name),PNGARG(args), \ + extern attributes) +#endif + +/* ANSI-C (C90) does not permit a macro to be invoked with an empty argument, + * so make something non-empty to satisfy the requirement: + */ +#define PNG_EMPTY /*empty list*/ + +#define PNG_EXPORT(ordinal, type, name, args)\ + PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY) + +/* Use PNG_REMOVED to comment out a removed interface. */ +#ifndef PNG_REMOVED +# define PNG_REMOVED(ordinal, type, name, args, attributes) +#endif + +#ifndef PNG_CALLBACK +# define PNG_CALLBACK(type, name, args) type (PNGCBAPI name) PNGARG(args) +#endif + +/* Support for compiler specific function attributes. These are used + * so that where compiler support is available incorrect use of API + * functions in png.h will generate compiler warnings. + * + * Added at libpng-1.2.41. + */ + +#ifndef PNG_NO_PEDANTIC_WARNINGS +# ifndef PNG_PEDANTIC_WARNINGS_SUPPORTED +# define PNG_PEDANTIC_WARNINGS_SUPPORTED +# endif +#endif + +#ifdef PNG_PEDANTIC_WARNINGS_SUPPORTED + /* Support for compiler specific function attributes. These are used + * so that where compiler support is available incorrect use of API + * functions in png.h will generate compiler warnings. Added at libpng + * version 1.2.41. + */ +# if defined(__GNUC__) +# ifndef PNG_USE_RESULT +# define PNG_USE_RESULT __attribute__((__warn_unused_result__)) +# endif +# ifndef PNG_NORETURN +# define PNG_NORETURN __attribute__((__noreturn__)) +# endif +# if __GNUC__ >= 3 +# ifndef PNG_ALLOCATED +# define PNG_ALLOCATED __attribute__((__malloc__)) +# endif +# ifndef PNG_DEPRECATED +# define PNG_DEPRECATED __attribute__((__deprecated__)) +# endif +# ifndef PNG_PRIVATE +# if 0 /* Doesn't work so we use deprecated instead*/ +# define PNG_PRIVATE \ + __attribute__((warning("This function is not exported by libpng."))) +# else +# define PNG_PRIVATE \ + __attribute__((__deprecated__)) +# endif +# endif +# endif /* __GNUC__ >= 3 */ +# endif /* __GNUC__ */ + +# if defined(_MSC_VER) && (_MSC_VER >= 1300) +# ifndef PNG_USE_RESULT +# define PNG_USE_RESULT /* not supported */ +# endif +# ifndef PNG_NORETURN +# define PNG_NORETURN __declspec(noreturn) +# endif +# ifndef PNG_ALLOCATED +# if (_MSC_VER >= 1400) +# define PNG_ALLOCATED __declspec(restrict) +# endif +# endif +# ifndef PNG_DEPRECATED +# define PNG_DEPRECATED __declspec(deprecated) +# endif +# ifndef PNG_PRIVATE +# define PNG_PRIVATE __declspec(deprecated) +# endif +# endif /* _MSC_VER */ +#endif /* PNG_PEDANTIC_WARNINGS */ + +#ifndef PNG_DEPRECATED +# define PNG_DEPRECATED /* Use of this function is deprecated */ +#endif +#ifndef PNG_USE_RESULT +# define PNG_USE_RESULT /* The result of this function must be checked */ +#endif +#ifndef PNG_NORETURN +# define PNG_NORETURN /* This function does not return */ +#endif +#ifndef PNG_ALLOCATED +# define PNG_ALLOCATED /* The result of the function is new memory */ +#endif +#ifndef PNG_PRIVATE +# define PNG_PRIVATE /* This is a private libpng function */ +#endif +#ifndef PNG_FP_EXPORT /* A floating point API. */ +# ifdef PNG_FLOATING_POINT_SUPPORTED +# define PNG_FP_EXPORT(ordinal, type, name, args)\ + PNG_EXPORT(ordinal, type, name, args); +# else /* No floating point APIs */ +# define PNG_FP_EXPORT(ordinal, type, name, args) +# endif +#endif +#ifndef PNG_FIXED_EXPORT /* A fixed point API. */ +# ifdef PNG_FIXED_POINT_SUPPORTED +# define PNG_FIXED_EXPORT(ordinal, type, name, args)\ + PNG_EXPORT(ordinal, type, name, args); +# else /* No fixed point APIs */ +# define PNG_FIXED_EXPORT(ordinal, type, name, args) +# endif +#endif + +/* The following uses const char * instead of char * for error + * and warning message functions, so some compilers won't complain. + * If you do not want to use const, define PNG_NO_CONST here. + * + * This should not change how the APIs are called, so it can be done + * on a per-file basis in the application. + */ +#ifndef PNG_CONST +# ifndef PNG_NO_CONST +# define PNG_CONST const +# else +# define PNG_CONST +# endif +#endif + +/* Some typedefs to get us started. These should be safe on most of the + * common platforms. The typedefs should be at least as large as the + * numbers suggest (a png_uint_32 must be at least 32 bits long), but they + * don't have to be exactly that size. Some compilers dislike passing + * unsigned shorts as function parameters, so you may be better off using + * unsigned int for png_uint_16. + */ + +#if defined(INT_MAX) && (INT_MAX > 0x7ffffffeL) +typedef unsigned int png_uint_32; +typedef int png_int_32; +#else +typedef unsigned long png_uint_32; +typedef long png_int_32; +#endif +typedef unsigned short png_uint_16; +typedef short png_int_16; +typedef unsigned char png_byte; + +#ifdef PNG_NO_SIZE_T +typedef unsigned int png_size_t; +#else +typedef size_t png_size_t; +#endif +#define png_sizeof(x) (sizeof (x)) + +/* The following is needed for medium model support. It cannot be in the + * pngpriv.h header. Needs modification for other compilers besides + * MSC. Model independent support declares all arrays and pointers to be + * large using the far keyword. The zlib version used must also support + * model independent data. As of version zlib 1.0.4, the necessary changes + * have been made in zlib. The USE_FAR_KEYWORD define triggers other + * changes that are needed. (Tim Wegner) + */ + +/* Separate compiler dependencies (problem here is that zlib.h always + * defines FAR. (SJT) + */ +#ifdef __BORLANDC__ +# if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__) +# define LDATA 1 +# else +# define LDATA 0 +# endif + /* GRR: why is Cygwin in here? Cygwin is not Borland C... */ +# if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__) +# define PNG_MAX_MALLOC_64K /* only used in build */ +# if (LDATA != 1) +# ifndef FAR +# define FAR __far +# endif +# define USE_FAR_KEYWORD +# endif /* LDATA != 1 */ + /* Possibly useful for moving data out of default segment. + * Uncomment it if you want. Could also define FARDATA as + * const if your compiler supports it. (SJT) +# define FARDATA FAR + */ +# endif /* __WIN32__, __FLAT__, __CYGWIN__ */ +#endif /* __BORLANDC__ */ + + +/* Suggest testing for specific compiler first before testing for + * FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM, + * making reliance oncertain keywords suspect. (SJT) + */ + +/* MSC Medium model */ +#ifdef FAR +# ifdef M_I86MM +# define USE_FAR_KEYWORD +# define FARDATA FAR +# include +# endif +#endif + +/* SJT: default case */ +#ifndef FAR +# define FAR +#endif + +/* At this point FAR is always defined */ +#ifndef FARDATA +# define FARDATA +#endif + +/* Typedef for floating-point numbers that are converted + * to fixed-point with a multiple of 100,000, e.g., gamma + */ +typedef png_int_32 png_fixed_point; + +/* Add typedefs for pointers */ +typedef void FAR * png_voidp; +typedef PNG_CONST void FAR * png_const_voidp; +typedef png_byte FAR * png_bytep; +typedef PNG_CONST png_byte FAR * png_const_bytep; +typedef png_uint_32 FAR * png_uint_32p; +typedef PNG_CONST png_uint_32 FAR * png_const_uint_32p; +typedef png_int_32 FAR * png_int_32p; +typedef PNG_CONST png_int_32 FAR * png_const_int_32p; +typedef png_uint_16 FAR * png_uint_16p; +typedef PNG_CONST png_uint_16 FAR * png_const_uint_16p; +typedef png_int_16 FAR * png_int_16p; +typedef PNG_CONST png_int_16 FAR * png_const_int_16p; +typedef char FAR * png_charp; +typedef PNG_CONST char FAR * png_const_charp; +typedef png_fixed_point FAR * png_fixed_point_p; +typedef PNG_CONST png_fixed_point FAR * png_const_fixed_point_p; +typedef png_size_t FAR * png_size_tp; +typedef PNG_CONST png_size_t FAR * png_const_size_tp; + +#ifdef PNG_STDIO_SUPPORTED +typedef FILE * png_FILE_p; +#endif + +#ifdef PNG_FLOATING_POINT_SUPPORTED +typedef double FAR * png_doublep; +typedef PNG_CONST double FAR * png_const_doublep; +#endif + +/* Pointers to pointers; i.e. arrays */ +typedef png_byte FAR * FAR * png_bytepp; +typedef png_uint_32 FAR * FAR * png_uint_32pp; +typedef png_int_32 FAR * FAR * png_int_32pp; +typedef png_uint_16 FAR * FAR * png_uint_16pp; +typedef png_int_16 FAR * FAR * png_int_16pp; +typedef PNG_CONST char FAR * FAR * png_const_charpp; +typedef char FAR * FAR * png_charpp; +typedef png_fixed_point FAR * FAR * png_fixed_point_pp; +#ifdef PNG_FLOATING_POINT_SUPPORTED +typedef double FAR * FAR * png_doublepp; +#endif + +/* Pointers to pointers to pointers; i.e., pointer to array */ +typedef char FAR * FAR * FAR * png_charppp; + +/* png_alloc_size_t is guaranteed to be no smaller than png_size_t, + * and no smaller than png_uint_32. Casts from png_size_t or png_uint_32 + * to png_alloc_size_t are not necessary; in fact, it is recommended + * not to use them at all so that the compiler can complain when something + * turns out to be problematic. + * Casts in the other direction (from png_alloc_size_t to png_size_t or + * png_uint_32) should be explicitly applied; however, we do not expect + * to encounter practical situations that require such conversions. + */ +#if defined(__TURBOC__) && !defined(__FLAT__) + typedef unsigned long png_alloc_size_t; +#else +# if defined(_MSC_VER) && defined(MAXSEG_64K) + typedef unsigned long png_alloc_size_t; +# else + /* This is an attempt to detect an old Windows system where (int) is + * actually 16 bits, in that case png_malloc must have an argument with a + * bigger size to accomodate the requirements of the library. + */ +# if (defined(_Windows) || defined(_WINDOWS) || defined(_WINDOWS_)) && \ + (!defined(INT_MAX) || INT_MAX <= 0x7ffffffeL) + typedef DWORD png_alloc_size_t; +# else + typedef png_size_t png_alloc_size_t; +# endif +# endif +#endif + +#endif /* PNGCONF_H */ diff --git a/Source/LibPNG/pngdebug.h b/Source/LibPNG/pngdebug.h index 96c1ea4..16f81fd 100644 --- a/Source/LibPNG/pngdebug.h +++ b/Source/LibPNG/pngdebug.h @@ -1,157 +1,157 @@ - -/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c - * - * Copyright (c) 1998-2011 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * Last changed in libpng 1.5.0 [January 6, 2011] - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - */ - -/* Define PNG_DEBUG at compile time for debugging information. Higher - * numbers for PNG_DEBUG mean more debugging information. This has - * only been added since version 0.95 so it is not implemented throughout - * libpng yet, but more support will be added as needed. - * - * png_debug[1-2]?(level, message ,arg{0-2}) - * Expands to a statement (either a simple expression or a compound - * do..while(0) statement) that outputs a message with parameter - * substitution if PNG_DEBUG is defined to 2 or more. If PNG_DEBUG - * is undefined, 0 or 1 every png_debug expands to a simple expression - * (actually ((void)0)). - * - * level: level of detail of message, starting at 0. A level 'n' - * message is preceded by 'n' tab characters (not implemented - * on Microsoft compilers unless PNG_DEBUG_FILE is also - * defined, to allow debug DLL compilation with no standard IO). - * message: a printf(3) style text string. A trailing '\n' is added - * to the message. - * arg: 0 to 2 arguments for printf(3) style substitution in message. - */ -#ifndef PNGDEBUG_H -#define PNGDEBUG_H -/* These settings control the formatting of messages in png.c and pngerror.c */ -/* Moved to pngdebug.h at 1.5.0 */ -# ifndef PNG_LITERAL_SHARP -# define PNG_LITERAL_SHARP 0x23 -# endif -# ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET -# define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b -# endif -# ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET -# define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d -# endif -# ifndef PNG_STRING_NEWLINE -# define PNG_STRING_NEWLINE "\n" -# endif - -#ifdef PNG_DEBUG -# if (PNG_DEBUG > 0) -# if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER) -# include -# if (PNG_DEBUG > 1) -# ifndef _DEBUG -# define _DEBUG -# endif -# ifndef png_debug -# define png_debug(l,m) _RPT0(_CRT_WARN,m PNG_STRING_NEWLINE) -# endif -# ifndef png_debug1 -# define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m PNG_STRING_NEWLINE,p1) -# endif -# ifndef png_debug2 -# define png_debug2(l,m,p1,p2) \ - _RPT2(_CRT_WARN,m PNG_STRING_NEWLINE,p1,p2) -# endif -# endif -# else /* PNG_DEBUG_FILE || !_MSC_VER */ -# ifndef PNG_STDIO_SUPPORTED -# include /* not included yet */ -# endif -# ifndef PNG_DEBUG_FILE -# define PNG_DEBUG_FILE stderr -# endif /* PNG_DEBUG_FILE */ - -# if (PNG_DEBUG > 1) -/* Note: ["%s"m PNG_STRING_NEWLINE] probably does not work on - * non-ISO compilers - */ -# ifdef __STDC__ -# ifndef png_debug -# define png_debug(l,m) \ - do { \ - int num_tabs=l; \ - fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \ - (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \ - } while (0) -# endif -# ifndef png_debug1 -# define png_debug1(l,m,p1) \ - do { \ - int num_tabs=l; \ - fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \ - (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \ - } while (0) -# endif -# ifndef png_debug2 -# define png_debug2(l,m,p1,p2) \ - do { \ - int num_tabs=l; \ - fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \ - (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \ - } while (0) -# endif -# else /* __STDC __ */ -# ifndef png_debug -# define png_debug(l,m) \ - do { \ - int num_tabs=l; \ - char format[256]; \ - snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ - (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ - m,PNG_STRING_NEWLINE); \ - fprintf(PNG_DEBUG_FILE,format); \ - } while (0) -# endif -# ifndef png_debug1 -# define png_debug1(l,m,p1) \ - do { \ - int num_tabs=l; \ - char format[256]; \ - snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ - (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ - m,PNG_STRING_NEWLINE); \ - fprintf(PNG_DEBUG_FILE,format,p1); \ - } while (0) -# endif -# ifndef png_debug2 -# define png_debug2(l,m,p1,p2) \ - do { \ - int num_tabs=l; \ - char format[256]; \ - snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ - (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ - m,PNG_STRING_NEWLINE); \ - fprintf(PNG_DEBUG_FILE,format,p1,p2); \ - } while (0) -# endif -# endif /* __STDC __ */ -# endif /* (PNG_DEBUG > 1) */ - -# endif /* _MSC_VER */ -# endif /* (PNG_DEBUG > 0) */ -#endif /* PNG_DEBUG */ -#ifndef png_debug -# define png_debug(l, m) ((void)0) -#endif -#ifndef png_debug1 -# define png_debug1(l, m, p1) ((void)0) -#endif -#ifndef png_debug2 -# define png_debug2(l, m, p1, p2) ((void)0) -#endif -#endif /* PNGDEBUG_H */ + +/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c + * + * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * Last changed in libpng 1.5.0 [January 6, 2011] + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +/* Define PNG_DEBUG at compile time for debugging information. Higher + * numbers for PNG_DEBUG mean more debugging information. This has + * only been added since version 0.95 so it is not implemented throughout + * libpng yet, but more support will be added as needed. + * + * png_debug[1-2]?(level, message ,arg{0-2}) + * Expands to a statement (either a simple expression or a compound + * do..while(0) statement) that outputs a message with parameter + * substitution if PNG_DEBUG is defined to 2 or more. If PNG_DEBUG + * is undefined, 0 or 1 every png_debug expands to a simple expression + * (actually ((void)0)). + * + * level: level of detail of message, starting at 0. A level 'n' + * message is preceded by 'n' tab characters (not implemented + * on Microsoft compilers unless PNG_DEBUG_FILE is also + * defined, to allow debug DLL compilation with no standard IO). + * message: a printf(3) style text string. A trailing '\n' is added + * to the message. + * arg: 0 to 2 arguments for printf(3) style substitution in message. + */ +#ifndef PNGDEBUG_H +#define PNGDEBUG_H +/* These settings control the formatting of messages in png.c and pngerror.c */ +/* Moved to pngdebug.h at 1.5.0 */ +# ifndef PNG_LITERAL_SHARP +# define PNG_LITERAL_SHARP 0x23 +# endif +# ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET +# define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b +# endif +# ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET +# define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d +# endif +# ifndef PNG_STRING_NEWLINE +# define PNG_STRING_NEWLINE "\n" +# endif + +#ifdef PNG_DEBUG +# if (PNG_DEBUG > 0) +# if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER) +# include +# if (PNG_DEBUG > 1) +# ifndef _DEBUG +# define _DEBUG +# endif +# ifndef png_debug +# define png_debug(l,m) _RPT0(_CRT_WARN,m PNG_STRING_NEWLINE) +# endif +# ifndef png_debug1 +# define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m PNG_STRING_NEWLINE,p1) +# endif +# ifndef png_debug2 +# define png_debug2(l,m,p1,p2) \ + _RPT2(_CRT_WARN,m PNG_STRING_NEWLINE,p1,p2) +# endif +# endif +# else /* PNG_DEBUG_FILE || !_MSC_VER */ +# ifndef PNG_STDIO_SUPPORTED +# include /* not included yet */ +# endif +# ifndef PNG_DEBUG_FILE +# define PNG_DEBUG_FILE stderr +# endif /* PNG_DEBUG_FILE */ + +# if (PNG_DEBUG > 1) +/* Note: ["%s"m PNG_STRING_NEWLINE] probably does not work on + * non-ISO compilers + */ +# ifdef __STDC__ +# ifndef png_debug +# define png_debug(l,m) \ + do { \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \ + } while (0) +# endif +# ifndef png_debug1 +# define png_debug1(l,m,p1) \ + do { \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \ + } while (0) +# endif +# ifndef png_debug2 +# define png_debug2(l,m,p1,p2) \ + do { \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \ + } while (0) +# endif +# else /* __STDC __ */ +# ifndef png_debug +# define png_debug(l,m) \ + do { \ + int num_tabs=l; \ + char format[256]; \ + snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ + m,PNG_STRING_NEWLINE); \ + fprintf(PNG_DEBUG_FILE,format); \ + } while (0) +# endif +# ifndef png_debug1 +# define png_debug1(l,m,p1) \ + do { \ + int num_tabs=l; \ + char format[256]; \ + snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ + m,PNG_STRING_NEWLINE); \ + fprintf(PNG_DEBUG_FILE,format,p1); \ + } while (0) +# endif +# ifndef png_debug2 +# define png_debug2(l,m,p1,p2) \ + do { \ + int num_tabs=l; \ + char format[256]; \ + snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ + m,PNG_STRING_NEWLINE); \ + fprintf(PNG_DEBUG_FILE,format,p1,p2); \ + } while (0) +# endif +# endif /* __STDC __ */ +# endif /* (PNG_DEBUG > 1) */ + +# endif /* _MSC_VER */ +# endif /* (PNG_DEBUG > 0) */ +#endif /* PNG_DEBUG */ +#ifndef png_debug +# define png_debug(l, m) ((void)0) +#endif +#ifndef png_debug1 +# define png_debug1(l, m, p1) ((void)0) +#endif +#ifndef png_debug2 +# define png_debug2(l, m, p1, p2) ((void)0) +#endif +#endif /* PNGDEBUG_H */ diff --git a/Source/LibPNG/pngerror.c b/Source/LibPNG/pngerror.c index ef60d55..e0585a8 100644 --- a/Source/LibPNG/pngerror.c +++ b/Source/LibPNG/pngerror.c @@ -1,685 +1,685 @@ - -/* pngerror.c - stub functions for i/o and memory allocation - * - * Last changed in libpng 1.5.8 [February 1, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - * - * This file provides a location for all error handling. Users who - * need special error handling are expected to write replacement functions - * and use png_set_error_fn() to use those functions. See the instructions - * at each function. - */ - -#include "pngpriv.h" - -#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) - -static PNG_FUNCTION(void, png_default_error,PNGARG((png_structp png_ptr, - png_const_charp error_message)),PNG_NORETURN); - -#ifdef PNG_WARNINGS_SUPPORTED -static void /* PRIVATE */ -png_default_warning PNGARG((png_structp png_ptr, - png_const_charp warning_message)); -#endif /* PNG_WARNINGS_SUPPORTED */ - -/* This function is called whenever there is a fatal error. This function - * should not be changed. If there is a need to handle errors differently, - * you should supply a replacement error function and use png_set_error_fn() - * to replace the error function at run-time. - */ -#ifdef PNG_ERROR_TEXT_SUPPORTED -PNG_FUNCTION(void,PNGAPI -png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN) -{ -#ifdef PNG_ERROR_NUMBERS_SUPPORTED - char msg[16]; - if (png_ptr != NULL) - { - if (png_ptr->flags& - (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) - { - if (*error_message == PNG_LITERAL_SHARP) - { - /* Strip "#nnnn " from beginning of error message. */ - int offset; - for (offset = 1; offset<15; offset++) - if (error_message[offset] == ' ') - break; - - if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) - { - int i; - for (i = 0; i < offset - 1; i++) - msg[i] = error_message[i + 1]; - msg[i - 1] = '\0'; - error_message = msg; - } - - else - error_message += offset; - } - - else - { - if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) - { - msg[0] = '0'; - msg[1] = '\0'; - error_message = msg; - } - } - } - } -#endif - if (png_ptr != NULL && png_ptr->error_fn != NULL) - (*(png_ptr->error_fn))(png_ptr, error_message); - - /* If the custom handler doesn't exist, or if it returns, - use the default handler, which will not return. */ - png_default_error(png_ptr, error_message); -} -#else -PNG_FUNCTION(void,PNGAPI -png_err,(png_structp png_ptr),PNG_NORETURN) -{ - /* Prior to 1.5.2 the error_fn received a NULL pointer, expressed - * erroneously as '\0', instead of the empty string "". This was - * apparently an error, introduced in libpng-1.2.20, and png_default_error - * will crash in this case. - */ - if (png_ptr != NULL && png_ptr->error_fn != NULL) - (*(png_ptr->error_fn))(png_ptr, ""); - - /* If the custom handler doesn't exist, or if it returns, - use the default handler, which will not return. */ - png_default_error(png_ptr, ""); -} -#endif /* PNG_ERROR_TEXT_SUPPORTED */ - -/* Utility to safely appends strings to a buffer. This never errors out so - * error checking is not required in the caller. - */ -size_t -png_safecat(png_charp buffer, size_t bufsize, size_t pos, - png_const_charp string) -{ - if (buffer != NULL && pos < bufsize) - { - if (string != NULL) - while (*string != '\0' && pos < bufsize-1) - buffer[pos++] = *string++; - - buffer[pos] = '\0'; - } - - return pos; -} - -#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED) -/* Utility to dump an unsigned value into a buffer, given a start pointer and - * and end pointer (which should point just *beyond* the end of the buffer!) - * Returns the pointer to the start of the formatted string. - */ -png_charp -png_format_number(png_const_charp start, png_charp end, int format, - png_alloc_size_t number) -{ - int count = 0; /* number of digits output */ - int mincount = 1; /* minimum number required */ - int output = 0; /* digit output (for the fixed point format) */ - - *--end = '\0'; - - /* This is written so that the loop always runs at least once, even with - * number zero. - */ - while (end > start && (number != 0 || count < mincount)) - { - - static const char digits[] = "0123456789ABCDEF"; - - switch (format) - { - case PNG_NUMBER_FORMAT_fixed: - /* Needs five digits (the fraction) */ - mincount = 5; - if (output || number % 10 != 0) - { - *--end = digits[number % 10]; - output = 1; - } - number /= 10; - break; - - case PNG_NUMBER_FORMAT_02u: - /* Expects at least 2 digits. */ - mincount = 2; - /* fall through */ - - case PNG_NUMBER_FORMAT_u: - *--end = digits[number % 10]; - number /= 10; - break; - - case PNG_NUMBER_FORMAT_02x: - /* This format expects at least two digits */ - mincount = 2; - /* fall through */ - - case PNG_NUMBER_FORMAT_x: - *--end = digits[number & 0xf]; - number >>= 4; - break; - - default: /* an error */ - number = 0; - break; - } - - /* Keep track of the number of digits added */ - ++count; - - /* Float a fixed number here: */ - if (format == PNG_NUMBER_FORMAT_fixed) if (count == 5) if (end > start) - { - /* End of the fraction, but maybe nothing was output? In that case - * drop the decimal point. If the number is a true zero handle that - * here. - */ - if (output) - *--end = '.'; - else if (number == 0) /* and !output */ - *--end = '0'; - } - } - - return end; -} -#endif - -#ifdef PNG_WARNINGS_SUPPORTED -/* This function is called whenever there is a non-fatal error. This function - * should not be changed. If there is a need to handle warnings differently, - * you should supply a replacement warning function and use - * png_set_error_fn() to replace the warning function at run-time. - */ -void PNGAPI -png_warning(png_structp png_ptr, png_const_charp warning_message) -{ - int offset = 0; - if (png_ptr != NULL) - { -#ifdef PNG_ERROR_NUMBERS_SUPPORTED - if (png_ptr->flags& - (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) -#endif - { - if (*warning_message == PNG_LITERAL_SHARP) - { - for (offset = 1; offset < 15; offset++) - if (warning_message[offset] == ' ') - break; - } - } - } - if (png_ptr != NULL && png_ptr->warning_fn != NULL) - (*(png_ptr->warning_fn))(png_ptr, warning_message + offset); - else - png_default_warning(png_ptr, warning_message + offset); -} - -/* These functions support 'formatted' warning messages with up to - * PNG_WARNING_PARAMETER_COUNT parameters. In the format string the parameter - * is introduced by @, where 'number' starts at 1. This follows the - * standard established by X/Open for internationalizable error messages. - */ -void -png_warning_parameter(png_warning_parameters p, int number, - png_const_charp string) -{ - if (number > 0 && number <= PNG_WARNING_PARAMETER_COUNT) - (void)png_safecat(p[number-1], (sizeof p[number-1]), 0, string); -} - -void -png_warning_parameter_unsigned(png_warning_parameters p, int number, int format, - png_alloc_size_t value) -{ - char buffer[PNG_NUMBER_BUFFER_SIZE]; - png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value)); -} - -void -png_warning_parameter_signed(png_warning_parameters p, int number, int format, - png_int_32 value) -{ - png_alloc_size_t u; - png_charp str; - char buffer[PNG_NUMBER_BUFFER_SIZE]; - - /* Avoid overflow by doing the negate in a png_alloc_size_t: */ - u = (png_alloc_size_t)value; - if (value < 0) - u = ~u + 1; - - str = PNG_FORMAT_NUMBER(buffer, format, u); - - if (value < 0 && str > buffer) - *--str = '-'; - - png_warning_parameter(p, number, str); -} - -void -png_formatted_warning(png_structp png_ptr, png_warning_parameters p, - png_const_charp message) -{ - /* The internal buffer is just 192 bytes - enough for all our messages, - * overflow doesn't happen because this code checks! If someone figures - * out how to send us a message longer than 192 bytes, all that will - * happen is that the message will be truncated appropriately. - */ - size_t i = 0; /* Index in the msg[] buffer: */ - char msg[192]; - - /* Each iteration through the following loop writes at most one character - * to msg[i++] then returns here to validate that there is still space for - * the trailing '\0'. It may (in the case of a parameter) read more than - * one character from message[]; it must check for '\0' and continue to the - * test if it finds the end of string. - */ - while (i<(sizeof msg)-1 && *message != '\0') - { - /* '@' at end of string is now just printed (previously it was skipped); - * it is an error in the calling code to terminate the string with @. - */ - if (p != NULL && *message == '@' && message[1] != '\0') - { - int parameter_char = *++message; /* Consume the '@' */ - static const char valid_parameters[] = "123456789"; - int parameter = 0; - - /* Search for the parameter digit, the index in the string is the - * parameter to use. - */ - while (valid_parameters[parameter] != parameter_char && - valid_parameters[parameter] != '\0') - ++parameter; - - /* If the parameter digit is out of range it will just get printed. */ - if (parameter < PNG_WARNING_PARAMETER_COUNT) - { - /* Append this parameter */ - png_const_charp parm = p[parameter]; - png_const_charp pend = p[parameter] + (sizeof p[parameter]); - - /* No need to copy the trailing '\0' here, but there is no guarantee - * that parm[] has been initialized, so there is no guarantee of a - * trailing '\0': - */ - while (i<(sizeof msg)-1 && *parm != '\0' && parm < pend) - msg[i++] = *parm++; - - /* Consume the parameter digit too: */ - ++message; - continue; - } - - /* else not a parameter and there is a character after the @ sign; just - * copy that. This is known not to be '\0' because of the test above. - */ - } - - /* At this point *message can't be '\0', even in the bad parameter case - * above where there is a lone '@' at the end of the message string. - */ - msg[i++] = *message++; - } - - /* i is always less than (sizeof msg), so: */ - msg[i] = '\0'; - - /* And this is the formatted message, it may be larger than - * PNG_MAX_ERROR_TEXT, but that is only used for 'chunk' errors and these are - * not (currently) formatted. - */ - png_warning(png_ptr, msg); -} -#endif /* PNG_WARNINGS_SUPPORTED */ - -#ifdef PNG_BENIGN_ERRORS_SUPPORTED -void PNGAPI -png_benign_error(png_structp png_ptr, png_const_charp error_message) -{ - if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) - png_warning(png_ptr, error_message); - else - png_error(png_ptr, error_message); -} -#endif - -/* These utilities are used internally to build an error message that relates - * to the current chunk. The chunk name comes from png_ptr->chunk_name, - * this is used to prefix the message. The message is limited in length - * to 63 bytes, the name characters are output as hex digits wrapped in [] - * if the character is invalid. - */ -#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) -static PNG_CONST char png_digit[16] = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'A', 'B', 'C', 'D', 'E', 'F' -}; - -#define PNG_MAX_ERROR_TEXT 64 -#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED) -static void /* PRIVATE */ -png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp - error_message) -{ - png_uint_32 chunk_name = png_ptr->chunk_name; - int iout = 0, ishift = 24; - - while (ishift >= 0) - { - int c = (int)(chunk_name >> ishift) & 0xff; - - ishift -= 8; - if (isnonalpha(c)) - { - buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET; - buffer[iout++] = png_digit[(c & 0xf0) >> 4]; - buffer[iout++] = png_digit[c & 0x0f]; - buffer[iout++] = PNG_LITERAL_RIGHT_SQUARE_BRACKET; - } - - else - { - buffer[iout++] = (char)c; - } - } - - if (error_message == NULL) - buffer[iout] = '\0'; - - else - { - int iin = 0; - - buffer[iout++] = ':'; - buffer[iout++] = ' '; - - while (iin < PNG_MAX_ERROR_TEXT-1 && error_message[iin] != '\0') - buffer[iout++] = error_message[iin++]; - - /* iin < PNG_MAX_ERROR_TEXT, so the following is safe: */ - buffer[iout] = '\0'; - } -} -#endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */ - -#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) -PNG_FUNCTION(void,PNGAPI -png_chunk_error,(png_structp png_ptr, png_const_charp error_message), - PNG_NORETURN) -{ - char msg[18+PNG_MAX_ERROR_TEXT]; - if (png_ptr == NULL) - png_error(png_ptr, error_message); - - else - { - png_format_buffer(png_ptr, msg, error_message); - png_error(png_ptr, msg); - } -} -#endif /* PNG_READ_SUPPORTED && PNG_ERROR_TEXT_SUPPORTED */ - -#ifdef PNG_WARNINGS_SUPPORTED -void PNGAPI -png_chunk_warning(png_structp png_ptr, png_const_charp warning_message) -{ - char msg[18+PNG_MAX_ERROR_TEXT]; - if (png_ptr == NULL) - png_warning(png_ptr, warning_message); - - else - { - png_format_buffer(png_ptr, msg, warning_message); - png_warning(png_ptr, msg); - } -} -#endif /* PNG_WARNINGS_SUPPORTED */ - -#ifdef PNG_READ_SUPPORTED -#ifdef PNG_BENIGN_ERRORS_SUPPORTED -void PNGAPI -png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message) -{ - if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) - png_chunk_warning(png_ptr, error_message); - - else - png_chunk_error(png_ptr, error_message); -} -#endif -#endif /* PNG_READ_SUPPORTED */ - -#ifdef PNG_ERROR_TEXT_SUPPORTED -#ifdef PNG_FLOATING_POINT_SUPPORTED -PNG_FUNCTION(void, -png_fixed_error,(png_structp png_ptr, png_const_charp name),PNG_NORETURN) -{ -# define fixed_message "fixed point overflow in " -# define fixed_message_ln ((sizeof fixed_message)-1) - int iin; - char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT]; - png_memcpy(msg, fixed_message, fixed_message_ln); - iin = 0; - if (name != NULL) while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0) - { - msg[fixed_message_ln + iin] = name[iin]; - ++iin; - } - msg[fixed_message_ln + iin] = 0; - png_error(png_ptr, msg); -} -#endif -#endif - -#ifdef PNG_SETJMP_SUPPORTED -/* This API only exists if ANSI-C style error handling is used, - * otherwise it is necessary for png_default_error to be overridden. - */ -jmp_buf* PNGAPI -png_set_longjmp_fn(png_structp png_ptr, png_longjmp_ptr longjmp_fn, - size_t jmp_buf_size) -{ - if (png_ptr == NULL || jmp_buf_size != png_sizeof(jmp_buf)) - return NULL; - - png_ptr->longjmp_fn = longjmp_fn; - return &png_ptr->longjmp_buffer; -} -#endif - -/* This is the default error handling function. Note that replacements for - * this function MUST NOT RETURN, or the program will likely crash. This - * function is used by default, or if the program supplies NULL for the - * error function pointer in png_set_error_fn(). - */ -static PNG_FUNCTION(void /* PRIVATE */, -png_default_error,(png_structp png_ptr, png_const_charp error_message), - PNG_NORETURN) -{ -#ifdef PNG_CONSOLE_IO_SUPPORTED -#ifdef PNG_ERROR_NUMBERS_SUPPORTED - /* Check on NULL only added in 1.5.4 */ - if (error_message != NULL && *error_message == PNG_LITERAL_SHARP) - { - /* Strip "#nnnn " from beginning of error message. */ - int offset; - char error_number[16]; - for (offset = 0; offset<15; offset++) - { - error_number[offset] = error_message[offset + 1]; - if (error_message[offset] == ' ') - break; - } - - if ((offset > 1) && (offset < 15)) - { - error_number[offset - 1] = '\0'; - fprintf(stderr, "libpng error no. %s: %s", - error_number, error_message + offset + 1); - fprintf(stderr, PNG_STRING_NEWLINE); - } - - else - { - fprintf(stderr, "libpng error: %s, offset=%d", - error_message, offset); - fprintf(stderr, PNG_STRING_NEWLINE); - } - } - else -#endif - { - fprintf(stderr, "libpng error: %s", error_message ? error_message : - "undefined"); - fprintf(stderr, PNG_STRING_NEWLINE); - } -#else - PNG_UNUSED(error_message) /* Make compiler happy */ -#endif - png_longjmp(png_ptr, 1); -} - -PNG_FUNCTION(void,PNGAPI -png_longjmp,(png_structp png_ptr, int val),PNG_NORETURN) -{ -#ifdef PNG_SETJMP_SUPPORTED - if (png_ptr && png_ptr->longjmp_fn) - { -# ifdef USE_FAR_KEYWORD - { - jmp_buf tmp_jmpbuf; - png_memcpy(tmp_jmpbuf, png_ptr->longjmp_buffer, png_sizeof(jmp_buf)); - png_ptr->longjmp_fn(tmp_jmpbuf, val); - } - -# else - png_ptr->longjmp_fn(png_ptr->longjmp_buffer, val); -# endif - } -#endif - /* Here if not setjmp support or if png_ptr is null. */ - PNG_ABORT(); -} - -#ifdef PNG_WARNINGS_SUPPORTED -/* This function is called when there is a warning, but the library thinks - * it can continue anyway. Replacement functions don't have to do anything - * here if you don't want them to. In the default configuration, png_ptr is - * not used, but it is passed in case it may be useful. - */ -static void /* PRIVATE */ -png_default_warning(png_structp png_ptr, png_const_charp warning_message) -{ -#ifdef PNG_CONSOLE_IO_SUPPORTED -# ifdef PNG_ERROR_NUMBERS_SUPPORTED - if (*warning_message == PNG_LITERAL_SHARP) - { - int offset; - char warning_number[16]; - for (offset = 0; offset < 15; offset++) - { - warning_number[offset] = warning_message[offset + 1]; - if (warning_message[offset] == ' ') - break; - } - - if ((offset > 1) && (offset < 15)) - { - warning_number[offset + 1] = '\0'; - fprintf(stderr, "libpng warning no. %s: %s", - warning_number, warning_message + offset); - fprintf(stderr, PNG_STRING_NEWLINE); - } - - else - { - fprintf(stderr, "libpng warning: %s", - warning_message); - fprintf(stderr, PNG_STRING_NEWLINE); - } - } - else -# endif - - { - fprintf(stderr, "libpng warning: %s", warning_message); - fprintf(stderr, PNG_STRING_NEWLINE); - } -#else - PNG_UNUSED(warning_message) /* Make compiler happy */ -#endif - PNG_UNUSED(png_ptr) /* Make compiler happy */ -} -#endif /* PNG_WARNINGS_SUPPORTED */ - -/* This function is called when the application wants to use another method - * of handling errors and warnings. Note that the error function MUST NOT - * return to the calling routine or serious problems will occur. The return - * method used in the default routine calls longjmp(png_ptr->longjmp_buffer, 1) - */ -void PNGAPI -png_set_error_fn(png_structp png_ptr, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warning_fn) -{ - if (png_ptr == NULL) - return; - - png_ptr->error_ptr = error_ptr; - png_ptr->error_fn = error_fn; -#ifdef PNG_WARNINGS_SUPPORTED - png_ptr->warning_fn = warning_fn; -#else - PNG_UNUSED(warning_fn) -#endif -} - - -/* This function returns a pointer to the error_ptr associated with the user - * functions. The application should free any memory associated with this - * pointer before png_write_destroy and png_read_destroy are called. - */ -png_voidp PNGAPI -png_get_error_ptr(png_const_structp png_ptr) -{ - if (png_ptr == NULL) - return NULL; - - return ((png_voidp)png_ptr->error_ptr); -} - - -#ifdef PNG_ERROR_NUMBERS_SUPPORTED -void PNGAPI -png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode) -{ - if (png_ptr != NULL) - { - png_ptr->flags &= - ((~(PNG_FLAG_STRIP_ERROR_NUMBERS | - PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode); - } -} -#endif -#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ + +/* pngerror.c - stub functions for i/o and memory allocation + * + * Last changed in libpng 1.5.8 [February 1, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file provides a location for all error handling. Users who + * need special error handling are expected to write replacement functions + * and use png_set_error_fn() to use those functions. See the instructions + * at each function. + */ + +#include "pngpriv.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +static PNG_FUNCTION(void, png_default_error,PNGARG((png_structp png_ptr, + png_const_charp error_message)),PNG_NORETURN); + +#ifdef PNG_WARNINGS_SUPPORTED +static void /* PRIVATE */ +png_default_warning PNGARG((png_structp png_ptr, + png_const_charp warning_message)); +#endif /* PNG_WARNINGS_SUPPORTED */ + +/* This function is called whenever there is a fatal error. This function + * should not be changed. If there is a need to handle errors differently, + * you should supply a replacement error function and use png_set_error_fn() + * to replace the error function at run-time. + */ +#ifdef PNG_ERROR_TEXT_SUPPORTED +PNG_FUNCTION(void,PNGAPI +png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN) +{ +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + char msg[16]; + if (png_ptr != NULL) + { + if (png_ptr->flags& + (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) + { + if (*error_message == PNG_LITERAL_SHARP) + { + /* Strip "#nnnn " from beginning of error message. */ + int offset; + for (offset = 1; offset<15; offset++) + if (error_message[offset] == ' ') + break; + + if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) + { + int i; + for (i = 0; i < offset - 1; i++) + msg[i] = error_message[i + 1]; + msg[i - 1] = '\0'; + error_message = msg; + } + + else + error_message += offset; + } + + else + { + if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) + { + msg[0] = '0'; + msg[1] = '\0'; + error_message = msg; + } + } + } + } +#endif + if (png_ptr != NULL && png_ptr->error_fn != NULL) + (*(png_ptr->error_fn))(png_ptr, error_message); + + /* If the custom handler doesn't exist, or if it returns, + use the default handler, which will not return. */ + png_default_error(png_ptr, error_message); +} +#else +PNG_FUNCTION(void,PNGAPI +png_err,(png_structp png_ptr),PNG_NORETURN) +{ + /* Prior to 1.5.2 the error_fn received a NULL pointer, expressed + * erroneously as '\0', instead of the empty string "". This was + * apparently an error, introduced in libpng-1.2.20, and png_default_error + * will crash in this case. + */ + if (png_ptr != NULL && png_ptr->error_fn != NULL) + (*(png_ptr->error_fn))(png_ptr, ""); + + /* If the custom handler doesn't exist, or if it returns, + use the default handler, which will not return. */ + png_default_error(png_ptr, ""); +} +#endif /* PNG_ERROR_TEXT_SUPPORTED */ + +/* Utility to safely appends strings to a buffer. This never errors out so + * error checking is not required in the caller. + */ +size_t +png_safecat(png_charp buffer, size_t bufsize, size_t pos, + png_const_charp string) +{ + if (buffer != NULL && pos < bufsize) + { + if (string != NULL) + while (*string != '\0' && pos < bufsize-1) + buffer[pos++] = *string++; + + buffer[pos] = '\0'; + } + + return pos; +} + +#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED) +/* Utility to dump an unsigned value into a buffer, given a start pointer and + * and end pointer (which should point just *beyond* the end of the buffer!) + * Returns the pointer to the start of the formatted string. + */ +png_charp +png_format_number(png_const_charp start, png_charp end, int format, + png_alloc_size_t number) +{ + int count = 0; /* number of digits output */ + int mincount = 1; /* minimum number required */ + int output = 0; /* digit output (for the fixed point format) */ + + *--end = '\0'; + + /* This is written so that the loop always runs at least once, even with + * number zero. + */ + while (end > start && (number != 0 || count < mincount)) + { + + static const char digits[] = "0123456789ABCDEF"; + + switch (format) + { + case PNG_NUMBER_FORMAT_fixed: + /* Needs five digits (the fraction) */ + mincount = 5; + if (output || number % 10 != 0) + { + *--end = digits[number % 10]; + output = 1; + } + number /= 10; + break; + + case PNG_NUMBER_FORMAT_02u: + /* Expects at least 2 digits. */ + mincount = 2; + /* fall through */ + + case PNG_NUMBER_FORMAT_u: + *--end = digits[number % 10]; + number /= 10; + break; + + case PNG_NUMBER_FORMAT_02x: + /* This format expects at least two digits */ + mincount = 2; + /* fall through */ + + case PNG_NUMBER_FORMAT_x: + *--end = digits[number & 0xf]; + number >>= 4; + break; + + default: /* an error */ + number = 0; + break; + } + + /* Keep track of the number of digits added */ + ++count; + + /* Float a fixed number here: */ + if (format == PNG_NUMBER_FORMAT_fixed) if (count == 5) if (end > start) + { + /* End of the fraction, but maybe nothing was output? In that case + * drop the decimal point. If the number is a true zero handle that + * here. + */ + if (output) + *--end = '.'; + else if (number == 0) /* and !output */ + *--end = '0'; + } + } + + return end; +} +#endif + +#ifdef PNG_WARNINGS_SUPPORTED +/* This function is called whenever there is a non-fatal error. This function + * should not be changed. If there is a need to handle warnings differently, + * you should supply a replacement warning function and use + * png_set_error_fn() to replace the warning function at run-time. + */ +void PNGAPI +png_warning(png_structp png_ptr, png_const_charp warning_message) +{ + int offset = 0; + if (png_ptr != NULL) + { +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + if (png_ptr->flags& + (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) +#endif + { + if (*warning_message == PNG_LITERAL_SHARP) + { + for (offset = 1; offset < 15; offset++) + if (warning_message[offset] == ' ') + break; + } + } + } + if (png_ptr != NULL && png_ptr->warning_fn != NULL) + (*(png_ptr->warning_fn))(png_ptr, warning_message + offset); + else + png_default_warning(png_ptr, warning_message + offset); +} + +/* These functions support 'formatted' warning messages with up to + * PNG_WARNING_PARAMETER_COUNT parameters. In the format string the parameter + * is introduced by @, where 'number' starts at 1. This follows the + * standard established by X/Open for internationalizable error messages. + */ +void +png_warning_parameter(png_warning_parameters p, int number, + png_const_charp string) +{ + if (number > 0 && number <= PNG_WARNING_PARAMETER_COUNT) + (void)png_safecat(p[number-1], (sizeof p[number-1]), 0, string); +} + +void +png_warning_parameter_unsigned(png_warning_parameters p, int number, int format, + png_alloc_size_t value) +{ + char buffer[PNG_NUMBER_BUFFER_SIZE]; + png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value)); +} + +void +png_warning_parameter_signed(png_warning_parameters p, int number, int format, + png_int_32 value) +{ + png_alloc_size_t u; + png_charp str; + char buffer[PNG_NUMBER_BUFFER_SIZE]; + + /* Avoid overflow by doing the negate in a png_alloc_size_t: */ + u = (png_alloc_size_t)value; + if (value < 0) + u = ~u + 1; + + str = PNG_FORMAT_NUMBER(buffer, format, u); + + if (value < 0 && str > buffer) + *--str = '-'; + + png_warning_parameter(p, number, str); +} + +void +png_formatted_warning(png_structp png_ptr, png_warning_parameters p, + png_const_charp message) +{ + /* The internal buffer is just 192 bytes - enough for all our messages, + * overflow doesn't happen because this code checks! If someone figures + * out how to send us a message longer than 192 bytes, all that will + * happen is that the message will be truncated appropriately. + */ + size_t i = 0; /* Index in the msg[] buffer: */ + char msg[192]; + + /* Each iteration through the following loop writes at most one character + * to msg[i++] then returns here to validate that there is still space for + * the trailing '\0'. It may (in the case of a parameter) read more than + * one character from message[]; it must check for '\0' and continue to the + * test if it finds the end of string. + */ + while (i<(sizeof msg)-1 && *message != '\0') + { + /* '@' at end of string is now just printed (previously it was skipped); + * it is an error in the calling code to terminate the string with @. + */ + if (p != NULL && *message == '@' && message[1] != '\0') + { + int parameter_char = *++message; /* Consume the '@' */ + static const char valid_parameters[] = "123456789"; + int parameter = 0; + + /* Search for the parameter digit, the index in the string is the + * parameter to use. + */ + while (valid_parameters[parameter] != parameter_char && + valid_parameters[parameter] != '\0') + ++parameter; + + /* If the parameter digit is out of range it will just get printed. */ + if (parameter < PNG_WARNING_PARAMETER_COUNT) + { + /* Append this parameter */ + png_const_charp parm = p[parameter]; + png_const_charp pend = p[parameter] + (sizeof p[parameter]); + + /* No need to copy the trailing '\0' here, but there is no guarantee + * that parm[] has been initialized, so there is no guarantee of a + * trailing '\0': + */ + while (i<(sizeof msg)-1 && *parm != '\0' && parm < pend) + msg[i++] = *parm++; + + /* Consume the parameter digit too: */ + ++message; + continue; + } + + /* else not a parameter and there is a character after the @ sign; just + * copy that. This is known not to be '\0' because of the test above. + */ + } + + /* At this point *message can't be '\0', even in the bad parameter case + * above where there is a lone '@' at the end of the message string. + */ + msg[i++] = *message++; + } + + /* i is always less than (sizeof msg), so: */ + msg[i] = '\0'; + + /* And this is the formatted message, it may be larger than + * PNG_MAX_ERROR_TEXT, but that is only used for 'chunk' errors and these are + * not (currently) formatted. + */ + png_warning(png_ptr, msg); +} +#endif /* PNG_WARNINGS_SUPPORTED */ + +#ifdef PNG_BENIGN_ERRORS_SUPPORTED +void PNGAPI +png_benign_error(png_structp png_ptr, png_const_charp error_message) +{ + if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) + png_warning(png_ptr, error_message); + else + png_error(png_ptr, error_message); +} +#endif + +/* These utilities are used internally to build an error message that relates + * to the current chunk. The chunk name comes from png_ptr->chunk_name, + * this is used to prefix the message. The message is limited in length + * to 63 bytes, the name characters are output as hex digits wrapped in [] + * if the character is invalid. + */ +#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) +static PNG_CONST char png_digit[16] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F' +}; + +#define PNG_MAX_ERROR_TEXT 64 +#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED) +static void /* PRIVATE */ +png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp + error_message) +{ + png_uint_32 chunk_name = png_ptr->chunk_name; + int iout = 0, ishift = 24; + + while (ishift >= 0) + { + int c = (int)(chunk_name >> ishift) & 0xff; + + ishift -= 8; + if (isnonalpha(c)) + { + buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET; + buffer[iout++] = png_digit[(c & 0xf0) >> 4]; + buffer[iout++] = png_digit[c & 0x0f]; + buffer[iout++] = PNG_LITERAL_RIGHT_SQUARE_BRACKET; + } + + else + { + buffer[iout++] = (char)c; + } + } + + if (error_message == NULL) + buffer[iout] = '\0'; + + else + { + int iin = 0; + + buffer[iout++] = ':'; + buffer[iout++] = ' '; + + while (iin < PNG_MAX_ERROR_TEXT-1 && error_message[iin] != '\0') + buffer[iout++] = error_message[iin++]; + + /* iin < PNG_MAX_ERROR_TEXT, so the following is safe: */ + buffer[iout] = '\0'; + } +} +#endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */ + +#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) +PNG_FUNCTION(void,PNGAPI +png_chunk_error,(png_structp png_ptr, png_const_charp error_message), + PNG_NORETURN) +{ + char msg[18+PNG_MAX_ERROR_TEXT]; + if (png_ptr == NULL) + png_error(png_ptr, error_message); + + else + { + png_format_buffer(png_ptr, msg, error_message); + png_error(png_ptr, msg); + } +} +#endif /* PNG_READ_SUPPORTED && PNG_ERROR_TEXT_SUPPORTED */ + +#ifdef PNG_WARNINGS_SUPPORTED +void PNGAPI +png_chunk_warning(png_structp png_ptr, png_const_charp warning_message) +{ + char msg[18+PNG_MAX_ERROR_TEXT]; + if (png_ptr == NULL) + png_warning(png_ptr, warning_message); + + else + { + png_format_buffer(png_ptr, msg, warning_message); + png_warning(png_ptr, msg); + } +} +#endif /* PNG_WARNINGS_SUPPORTED */ + +#ifdef PNG_READ_SUPPORTED +#ifdef PNG_BENIGN_ERRORS_SUPPORTED +void PNGAPI +png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message) +{ + if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) + png_chunk_warning(png_ptr, error_message); + + else + png_chunk_error(png_ptr, error_message); +} +#endif +#endif /* PNG_READ_SUPPORTED */ + +#ifdef PNG_ERROR_TEXT_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +PNG_FUNCTION(void, +png_fixed_error,(png_structp png_ptr, png_const_charp name),PNG_NORETURN) +{ +# define fixed_message "fixed point overflow in " +# define fixed_message_ln ((sizeof fixed_message)-1) + int iin; + char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT]; + png_memcpy(msg, fixed_message, fixed_message_ln); + iin = 0; + if (name != NULL) while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0) + { + msg[fixed_message_ln + iin] = name[iin]; + ++iin; + } + msg[fixed_message_ln + iin] = 0; + png_error(png_ptr, msg); +} +#endif +#endif + +#ifdef PNG_SETJMP_SUPPORTED +/* This API only exists if ANSI-C style error handling is used, + * otherwise it is necessary for png_default_error to be overridden. + */ +jmp_buf* PNGAPI +png_set_longjmp_fn(png_structp png_ptr, png_longjmp_ptr longjmp_fn, + size_t jmp_buf_size) +{ + if (png_ptr == NULL || jmp_buf_size != png_sizeof(jmp_buf)) + return NULL; + + png_ptr->longjmp_fn = longjmp_fn; + return &png_ptr->longjmp_buffer; +} +#endif + +/* This is the default error handling function. Note that replacements for + * this function MUST NOT RETURN, or the program will likely crash. This + * function is used by default, or if the program supplies NULL for the + * error function pointer in png_set_error_fn(). + */ +static PNG_FUNCTION(void /* PRIVATE */, +png_default_error,(png_structp png_ptr, png_const_charp error_message), + PNG_NORETURN) +{ +#ifdef PNG_CONSOLE_IO_SUPPORTED +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + /* Check on NULL only added in 1.5.4 */ + if (error_message != NULL && *error_message == PNG_LITERAL_SHARP) + { + /* Strip "#nnnn " from beginning of error message. */ + int offset; + char error_number[16]; + for (offset = 0; offset<15; offset++) + { + error_number[offset] = error_message[offset + 1]; + if (error_message[offset] == ' ') + break; + } + + if ((offset > 1) && (offset < 15)) + { + error_number[offset - 1] = '\0'; + fprintf(stderr, "libpng error no. %s: %s", + error_number, error_message + offset + 1); + fprintf(stderr, PNG_STRING_NEWLINE); + } + + else + { + fprintf(stderr, "libpng error: %s, offset=%d", + error_message, offset); + fprintf(stderr, PNG_STRING_NEWLINE); + } + } + else +#endif + { + fprintf(stderr, "libpng error: %s", error_message ? error_message : + "undefined"); + fprintf(stderr, PNG_STRING_NEWLINE); + } +#else + PNG_UNUSED(error_message) /* Make compiler happy */ +#endif + png_longjmp(png_ptr, 1); +} + +PNG_FUNCTION(void,PNGAPI +png_longjmp,(png_structp png_ptr, int val),PNG_NORETURN) +{ +#ifdef PNG_SETJMP_SUPPORTED + if (png_ptr && png_ptr->longjmp_fn) + { +# ifdef USE_FAR_KEYWORD + { + jmp_buf tmp_jmpbuf; + png_memcpy(tmp_jmpbuf, png_ptr->longjmp_buffer, png_sizeof(jmp_buf)); + png_ptr->longjmp_fn(tmp_jmpbuf, val); + } + +# else + png_ptr->longjmp_fn(png_ptr->longjmp_buffer, val); +# endif + } +#endif + /* Here if not setjmp support or if png_ptr is null. */ + PNG_ABORT(); +} + +#ifdef PNG_WARNINGS_SUPPORTED +/* This function is called when there is a warning, but the library thinks + * it can continue anyway. Replacement functions don't have to do anything + * here if you don't want them to. In the default configuration, png_ptr is + * not used, but it is passed in case it may be useful. + */ +static void /* PRIVATE */ +png_default_warning(png_structp png_ptr, png_const_charp warning_message) +{ +#ifdef PNG_CONSOLE_IO_SUPPORTED +# ifdef PNG_ERROR_NUMBERS_SUPPORTED + if (*warning_message == PNG_LITERAL_SHARP) + { + int offset; + char warning_number[16]; + for (offset = 0; offset < 15; offset++) + { + warning_number[offset] = warning_message[offset + 1]; + if (warning_message[offset] == ' ') + break; + } + + if ((offset > 1) && (offset < 15)) + { + warning_number[offset + 1] = '\0'; + fprintf(stderr, "libpng warning no. %s: %s", + warning_number, warning_message + offset); + fprintf(stderr, PNG_STRING_NEWLINE); + } + + else + { + fprintf(stderr, "libpng warning: %s", + warning_message); + fprintf(stderr, PNG_STRING_NEWLINE); + } + } + else +# endif + + { + fprintf(stderr, "libpng warning: %s", warning_message); + fprintf(stderr, PNG_STRING_NEWLINE); + } +#else + PNG_UNUSED(warning_message) /* Make compiler happy */ +#endif + PNG_UNUSED(png_ptr) /* Make compiler happy */ +} +#endif /* PNG_WARNINGS_SUPPORTED */ + +/* This function is called when the application wants to use another method + * of handling errors and warnings. Note that the error function MUST NOT + * return to the calling routine or serious problems will occur. The return + * method used in the default routine calls longjmp(png_ptr->longjmp_buffer, 1) + */ +void PNGAPI +png_set_error_fn(png_structp png_ptr, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warning_fn) +{ + if (png_ptr == NULL) + return; + + png_ptr->error_ptr = error_ptr; + png_ptr->error_fn = error_fn; +#ifdef PNG_WARNINGS_SUPPORTED + png_ptr->warning_fn = warning_fn; +#else + PNG_UNUSED(warning_fn) +#endif +} + + +/* This function returns a pointer to the error_ptr associated with the user + * functions. The application should free any memory associated with this + * pointer before png_write_destroy and png_read_destroy are called. + */ +png_voidp PNGAPI +png_get_error_ptr(png_const_structp png_ptr) +{ + if (png_ptr == NULL) + return NULL; + + return ((png_voidp)png_ptr->error_ptr); +} + + +#ifdef PNG_ERROR_NUMBERS_SUPPORTED +void PNGAPI +png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode) +{ + if (png_ptr != NULL) + { + png_ptr->flags &= + ((~(PNG_FLAG_STRIP_ERROR_NUMBERS | + PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode); + } +} +#endif +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff --git a/Source/LibPNG/pngget.c b/Source/LibPNG/pngget.c index 1889e99..43400cd 100644 --- a/Source/LibPNG/pngget.c +++ b/Source/LibPNG/pngget.c @@ -1,1124 +1,1124 @@ - -/* pngget.c - retrieval of values from info struct - * - * Last changed in libpng 1.5.7 [December 15, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - * - */ - -#include "pngpriv.h" - -#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) - -png_uint_32 PNGAPI -png_get_valid(png_const_structp png_ptr, png_const_infop info_ptr, - png_uint_32 flag) -{ - if (png_ptr != NULL && info_ptr != NULL) - return(info_ptr->valid & flag); - - return(0); -} - -png_size_t PNGAPI -png_get_rowbytes(png_const_structp png_ptr, png_const_infop info_ptr) -{ - if (png_ptr != NULL && info_ptr != NULL) - return(info_ptr->rowbytes); - - return(0); -} - -#ifdef PNG_INFO_IMAGE_SUPPORTED -png_bytepp PNGAPI -png_get_rows(png_const_structp png_ptr, png_const_infop info_ptr) -{ - if (png_ptr != NULL && info_ptr != NULL) - return(info_ptr->row_pointers); - - return(0); -} -#endif - -#ifdef PNG_EASY_ACCESS_SUPPORTED -/* Easy access to info, added in libpng-0.99 */ -png_uint_32 PNGAPI -png_get_image_width(png_const_structp png_ptr, png_const_infop info_ptr) -{ - if (png_ptr != NULL && info_ptr != NULL) - return info_ptr->width; - - return (0); -} - -png_uint_32 PNGAPI -png_get_image_height(png_const_structp png_ptr, png_const_infop info_ptr) -{ - if (png_ptr != NULL && info_ptr != NULL) - return info_ptr->height; - - return (0); -} - -png_byte PNGAPI -png_get_bit_depth(png_const_structp png_ptr, png_const_infop info_ptr) -{ - if (png_ptr != NULL && info_ptr != NULL) - return info_ptr->bit_depth; - - return (0); -} - -png_byte PNGAPI -png_get_color_type(png_const_structp png_ptr, png_const_infop info_ptr) -{ - if (png_ptr != NULL && info_ptr != NULL) - return info_ptr->color_type; - - return (0); -} - -png_byte PNGAPI -png_get_filter_type(png_const_structp png_ptr, png_const_infop info_ptr) -{ - if (png_ptr != NULL && info_ptr != NULL) - return info_ptr->filter_type; - - return (0); -} - -png_byte PNGAPI -png_get_interlace_type(png_const_structp png_ptr, png_const_infop info_ptr) -{ - if (png_ptr != NULL && info_ptr != NULL) - return info_ptr->interlace_type; - - return (0); -} - -png_byte PNGAPI -png_get_compression_type(png_const_structp png_ptr, png_const_infop info_ptr) -{ - if (png_ptr != NULL && info_ptr != NULL) - return info_ptr->compression_type; - - return (0); -} - -png_uint_32 PNGAPI -png_get_x_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) -{ -#ifdef PNG_pHYs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) - { - png_debug1(1, "in %s retrieval function", - "png_get_x_pixels_per_meter"); - - if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) - return (info_ptr->x_pixels_per_unit); - } -#endif - - return (0); -} - -png_uint_32 PNGAPI -png_get_y_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) -{ -#ifdef PNG_pHYs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) - { - png_debug1(1, "in %s retrieval function", - "png_get_y_pixels_per_meter"); - - if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) - return (info_ptr->y_pixels_per_unit); - } -#endif - - return (0); -} - -png_uint_32 PNGAPI -png_get_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) -{ -#ifdef PNG_pHYs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) - { - png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter"); - - if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER && - info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit) - return (info_ptr->x_pixels_per_unit); - } -#endif - - return (0); -} - -#ifdef PNG_FLOATING_POINT_SUPPORTED -float PNGAPI -png_get_pixel_aspect_ratio(png_const_structp png_ptr, png_const_infop info_ptr) -{ -#ifdef PNG_READ_pHYs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) - { - png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio"); - - if (info_ptr->x_pixels_per_unit != 0) - return ((float)((float)info_ptr->y_pixels_per_unit - /(float)info_ptr->x_pixels_per_unit)); - } -#endif - - return ((float)0.0); -} -#endif - -#ifdef PNG_FIXED_POINT_SUPPORTED -png_fixed_point PNGAPI -png_get_pixel_aspect_ratio_fixed(png_const_structp png_ptr, - png_const_infop info_ptr) -{ -#ifdef PNG_READ_pHYs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs) - && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 - && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX - && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX) - { - png_fixed_point res; - - png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed"); - - /* The following casts work because a PNG 4 byte integer only has a valid - * range of 0..2^31-1; otherwise the cast might overflow. - */ - if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1, - (png_int_32)info_ptr->x_pixels_per_unit)) - return res; - } -#endif - - return 0; -} -#endif - -png_int_32 PNGAPI -png_get_x_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr) -{ -#ifdef PNG_oFFs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) - { - png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns"); - - if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) - return (info_ptr->x_offset); - } -#endif - - return (0); -} - -png_int_32 PNGAPI -png_get_y_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr) -{ -#ifdef PNG_oFFs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) - { - png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns"); - - if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) - return (info_ptr->y_offset); - } -#endif - - return (0); -} - -png_int_32 PNGAPI -png_get_x_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr) -{ -#ifdef PNG_oFFs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) - { - png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels"); - - if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) - return (info_ptr->x_offset); - } -#endif - - return (0); -} - -png_int_32 PNGAPI -png_get_y_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr) -{ -#ifdef PNG_oFFs_SUPPORTED - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) - { - png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels"); - - if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) - return (info_ptr->y_offset); - } -#endif - - return (0); -} - -#ifdef PNG_INCH_CONVERSIONS_SUPPORTED -static png_uint_32 -ppi_from_ppm(png_uint_32 ppm) -{ -#if 0 - /* The conversion is *(2.54/100), in binary (32 digits): - * .00000110100000001001110101001001 - */ - png_uint_32 t1001, t1101; - ppm >>= 1; /* .1 */ - t1001 = ppm + (ppm >> 3); /* .1001 */ - t1101 = t1001 + (ppm >> 1); /* .1101 */ - ppm >>= 20; /* .000000000000000000001 */ - t1101 += t1101 >> 15; /* .1101000000000001101 */ - t1001 >>= 11; /* .000000000001001 */ - t1001 += t1001 >> 12; /* .000000000001001000000001001 */ - ppm += t1001; /* .000000000001001000001001001 */ - ppm += t1101; /* .110100000001001110101001001 */ - return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */ -#else - /* The argument is a PNG unsigned integer, so it is not permitted - * to be bigger than 2^31. - */ - png_fixed_point result; - if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127, - 5000)) - return result; - - /* Overflow. */ - return 0; -#endif -} - -png_uint_32 PNGAPI -png_get_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) -{ - return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr)); -} - -png_uint_32 PNGAPI -png_get_x_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) -{ - return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr)); -} - -png_uint_32 PNGAPI -png_get_y_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) -{ - return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr)); -} - -#ifdef PNG_FIXED_POINT_SUPPORTED -static png_fixed_point -png_fixed_inches_from_microns(png_structp png_ptr, png_int_32 microns) -{ - /* Convert from metres * 1,000,000 to inches * 100,000, meters to - * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127. - * Notice that this can overflow - a warning is output and 0 is - * returned. - */ - return png_muldiv_warn(png_ptr, microns, 500, 127); -} - -png_fixed_point PNGAPI -png_get_x_offset_inches_fixed(png_structp png_ptr, - png_const_infop info_ptr) -{ - return png_fixed_inches_from_microns(png_ptr, - png_get_x_offset_microns(png_ptr, info_ptr)); -} -#endif - -#ifdef PNG_FIXED_POINT_SUPPORTED -png_fixed_point PNGAPI -png_get_y_offset_inches_fixed(png_structp png_ptr, - png_const_infop info_ptr) -{ - return png_fixed_inches_from_microns(png_ptr, - png_get_y_offset_microns(png_ptr, info_ptr)); -} -#endif - -#ifdef PNG_FLOATING_POINT_SUPPORTED -float PNGAPI -png_get_x_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr) -{ - /* To avoid the overflow do the conversion directly in floating - * point. - */ - return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937); -} -#endif - -#ifdef PNG_FLOATING_POINT_SUPPORTED -float PNGAPI -png_get_y_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr) -{ - /* To avoid the overflow do the conversion directly in floating - * point. - */ - return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937); -} -#endif - -#ifdef PNG_pHYs_SUPPORTED -png_uint_32 PNGAPI -png_get_pHYs_dpi(png_const_structp png_ptr, png_const_infop info_ptr, - png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) -{ - png_uint_32 retval = 0; - - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) - { - png_debug1(1, "in %s retrieval function", "pHYs"); - - if (res_x != NULL) - { - *res_x = info_ptr->x_pixels_per_unit; - retval |= PNG_INFO_pHYs; - } - - if (res_y != NULL) - { - *res_y = info_ptr->y_pixels_per_unit; - retval |= PNG_INFO_pHYs; - } - - if (unit_type != NULL) - { - *unit_type = (int)info_ptr->phys_unit_type; - retval |= PNG_INFO_pHYs; - - if (*unit_type == 1) - { - if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50); - if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50); - } - } - } - - return (retval); -} -#endif /* PNG_pHYs_SUPPORTED */ -#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */ - -/* png_get_channels really belongs in here, too, but it's been around longer */ - -#endif /* PNG_EASY_ACCESS_SUPPORTED */ - -png_byte PNGAPI -png_get_channels(png_const_structp png_ptr, png_const_infop info_ptr) -{ - if (png_ptr != NULL && info_ptr != NULL) - return(info_ptr->channels); - - return (0); -} - -png_const_bytep PNGAPI -png_get_signature(png_const_structp png_ptr, png_infop info_ptr) -{ - if (png_ptr != NULL && info_ptr != NULL) - return(info_ptr->signature); - - return (NULL); -} - -#ifdef PNG_bKGD_SUPPORTED -png_uint_32 PNGAPI -png_get_bKGD(png_const_structp png_ptr, png_infop info_ptr, - png_color_16p *background) -{ - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) - && background != NULL) - { - png_debug1(1, "in %s retrieval function", "bKGD"); - - *background = &(info_ptr->background); - return (PNG_INFO_bKGD); - } - - return (0); -} -#endif - -#ifdef PNG_cHRM_SUPPORTED -/* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the - * same time to correct the rgb grayscale coefficient defaults obtained from the - * cHRM chunk in 1.5.4 - */ -png_uint_32 PNGFAPI -png_get_cHRM_XYZ_fixed(png_structp png_ptr, png_const_infop info_ptr, - png_fixed_point *int_red_X, png_fixed_point *int_red_Y, - png_fixed_point *int_red_Z, png_fixed_point *int_green_X, - png_fixed_point *int_green_Y, png_fixed_point *int_green_Z, - png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y, - png_fixed_point *int_blue_Z) -{ - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) - { - png_xy xy; - png_XYZ XYZ; - - png_debug1(1, "in %s retrieval function", "cHRM_XYZ"); - - xy.whitex = info_ptr->x_white; - xy.whitey = info_ptr->y_white; - xy.redx = info_ptr->x_red; - xy.redy = info_ptr->y_red; - xy.greenx = info_ptr->x_green; - xy.greeny = info_ptr->y_green; - xy.bluex = info_ptr->x_blue; - xy.bluey = info_ptr->y_blue; - - /* The *_checked function handles error reporting, so just return 0 if - * there is a failure here. - */ - if (png_XYZ_from_xy_checked(png_ptr, &XYZ, xy)) - { - if (int_red_X != NULL) - *int_red_X = XYZ.redX; - if (int_red_Y != NULL) - *int_red_Y = XYZ.redY; - if (int_red_Z != NULL) - *int_red_Z = XYZ.redZ; - if (int_green_X != NULL) - *int_green_X = XYZ.greenX; - if (int_green_Y != NULL) - *int_green_Y = XYZ.greenY; - if (int_green_Z != NULL) - *int_green_Z = XYZ.greenZ; - if (int_blue_X != NULL) - *int_blue_X = XYZ.blueX; - if (int_blue_Y != NULL) - *int_blue_Y = XYZ.blueY; - if (int_blue_Z != NULL) - *int_blue_Z = XYZ.blueZ; - - return (PNG_INFO_cHRM); - } - } - - return (0); -} - -# ifdef PNG_FLOATING_POINT_SUPPORTED -png_uint_32 PNGAPI -png_get_cHRM(png_const_structp png_ptr, png_const_infop info_ptr, - double *white_x, double *white_y, double *red_x, double *red_y, - double *green_x, double *green_y, double *blue_x, double *blue_y) -{ - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) - { - png_debug1(1, "in %s retrieval function", "cHRM"); - - if (white_x != NULL) - *white_x = png_float(png_ptr, info_ptr->x_white, "cHRM white X"); - if (white_y != NULL) - *white_y = png_float(png_ptr, info_ptr->y_white, "cHRM white Y"); - if (red_x != NULL) - *red_x = png_float(png_ptr, info_ptr->x_red, "cHRM red X"); - if (red_y != NULL) - *red_y = png_float(png_ptr, info_ptr->y_red, "cHRM red Y"); - if (green_x != NULL) - *green_x = png_float(png_ptr, info_ptr->x_green, "cHRM green X"); - if (green_y != NULL) - *green_y = png_float(png_ptr, info_ptr->y_green, "cHRM green Y"); - if (blue_x != NULL) - *blue_x = png_float(png_ptr, info_ptr->x_blue, "cHRM blue X"); - if (blue_y != NULL) - *blue_y = png_float(png_ptr, info_ptr->y_blue, "cHRM blue Y"); - return (PNG_INFO_cHRM); - } - - return (0); -} - -png_uint_32 PNGAPI -png_get_cHRM_XYZ(png_structp png_ptr, png_const_infop info_ptr, - double *red_X, double *red_Y, double *red_Z, double *green_X, - double *green_Y, double *green_Z, double *blue_X, double *blue_Y, - double *blue_Z) -{ - png_XYZ XYZ; - - if (png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, - &XYZ.redX, &XYZ.redY, &XYZ.redZ, &XYZ.greenX, &XYZ.greenY, &XYZ.greenZ, - &XYZ.blueX, &XYZ.blueY, &XYZ.blueZ) & PNG_INFO_cHRM) - { - if (red_X != NULL) - *red_X = png_float(png_ptr, XYZ.redX, "cHRM red X"); - if (red_Y != NULL) - *red_Y = png_float(png_ptr, XYZ.redY, "cHRM red Y"); - if (red_Z != NULL) - *red_Z = png_float(png_ptr, XYZ.redZ, "cHRM red Z"); - if (green_X != NULL) - *green_X = png_float(png_ptr, XYZ.greenX, "cHRM green X"); - if (green_Y != NULL) - *green_Y = png_float(png_ptr, XYZ.greenY, "cHRM green Y"); - if (green_Z != NULL) - *green_Z = png_float(png_ptr, XYZ.greenZ, "cHRM green Z"); - if (blue_X != NULL) - *blue_X = png_float(png_ptr, XYZ.blueX, "cHRM blue X"); - if (blue_Y != NULL) - *blue_Y = png_float(png_ptr, XYZ.blueY, "cHRM blue Y"); - if (blue_Z != NULL) - *blue_Z = png_float(png_ptr, XYZ.blueZ, "cHRM blue Z"); - return (PNG_INFO_cHRM); - } - - return (0); -} -# endif - -# ifdef PNG_FIXED_POINT_SUPPORTED -png_uint_32 PNGAPI -png_get_cHRM_fixed(png_const_structp png_ptr, png_const_infop info_ptr, - png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, - png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, - png_fixed_point *blue_x, png_fixed_point *blue_y) -{ - png_debug1(1, "in %s retrieval function", "cHRM"); - - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) - { - if (white_x != NULL) - *white_x = info_ptr->x_white; - if (white_y != NULL) - *white_y = info_ptr->y_white; - if (red_x != NULL) - *red_x = info_ptr->x_red; - if (red_y != NULL) - *red_y = info_ptr->y_red; - if (green_x != NULL) - *green_x = info_ptr->x_green; - if (green_y != NULL) - *green_y = info_ptr->y_green; - if (blue_x != NULL) - *blue_x = info_ptr->x_blue; - if (blue_y != NULL) - *blue_y = info_ptr->y_blue; - return (PNG_INFO_cHRM); - } - - return (0); -} -# endif -#endif - -#ifdef PNG_gAMA_SUPPORTED -png_uint_32 PNGFAPI -png_get_gAMA_fixed(png_const_structp png_ptr, png_const_infop info_ptr, - png_fixed_point *file_gamma) -{ - png_debug1(1, "in %s retrieval function", "gAMA"); - - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) - && file_gamma != NULL) - { - *file_gamma = info_ptr->gamma; - return (PNG_INFO_gAMA); - } - - return (0); -} -# ifdef PNG_FLOATING_POINT_SUPPORTED -png_uint_32 PNGAPI -png_get_gAMA(png_const_structp png_ptr, png_const_infop info_ptr, - double *file_gamma) -{ - png_fixed_point igamma; - png_uint_32 ok = png_get_gAMA_fixed(png_ptr, info_ptr, &igamma); - - if (ok) - *file_gamma = png_float(png_ptr, igamma, "png_get_gAMA"); - - return ok; -} - -# endif -#endif - -#ifdef PNG_sRGB_SUPPORTED -png_uint_32 PNGAPI -png_get_sRGB(png_const_structp png_ptr, png_const_infop info_ptr, - int *file_srgb_intent) -{ - png_debug1(1, "in %s retrieval function", "sRGB"); - - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) - && file_srgb_intent != NULL) - { - *file_srgb_intent = (int)info_ptr->srgb_intent; - return (PNG_INFO_sRGB); - } - - return (0); -} -#endif - -#ifdef PNG_iCCP_SUPPORTED -png_uint_32 PNGAPI -png_get_iCCP(png_const_structp png_ptr, png_const_infop info_ptr, - png_charpp name, int *compression_type, - png_bytepp profile, png_uint_32 *proflen) -{ - png_debug1(1, "in %s retrieval function", "iCCP"); - - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) - && name != NULL && compression_type != NULL && profile != NULL && - proflen != NULL) - { - *name = info_ptr->iccp_name; - *profile = info_ptr->iccp_profile; - /* Compression_type is a dummy so the API won't have to change - * if we introduce multiple compression types later. - */ - *proflen = info_ptr->iccp_proflen; - *compression_type = info_ptr->iccp_compression; - return (PNG_INFO_iCCP); - } - - return (0); -} -#endif - -#ifdef PNG_sPLT_SUPPORTED -png_uint_32 PNGAPI -png_get_sPLT(png_const_structp png_ptr, png_const_infop info_ptr, - png_sPLT_tpp spalettes) -{ - if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) - { - *spalettes = info_ptr->splt_palettes; - return ((png_uint_32)info_ptr->splt_palettes_num); - } - - return (0); -} -#endif - -#ifdef PNG_hIST_SUPPORTED -png_uint_32 PNGAPI -png_get_hIST(png_const_structp png_ptr, png_const_infop info_ptr, - png_uint_16p *hist) -{ - png_debug1(1, "in %s retrieval function", "hIST"); - - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) - && hist != NULL) - { - *hist = info_ptr->hist; - return (PNG_INFO_hIST); - } - - return (0); -} -#endif - -png_uint_32 PNGAPI -png_get_IHDR(png_structp png_ptr, png_infop info_ptr, - png_uint_32 *width, png_uint_32 *height, int *bit_depth, - int *color_type, int *interlace_type, int *compression_type, - int *filter_type) - -{ - png_debug1(1, "in %s retrieval function", "IHDR"); - - if (png_ptr == NULL || info_ptr == NULL || width == NULL || - height == NULL || bit_depth == NULL || color_type == NULL) - return (0); - - *width = info_ptr->width; - *height = info_ptr->height; - *bit_depth = info_ptr->bit_depth; - *color_type = info_ptr->color_type; - - if (compression_type != NULL) - *compression_type = info_ptr->compression_type; - - if (filter_type != NULL) - *filter_type = info_ptr->filter_type; - - if (interlace_type != NULL) - *interlace_type = info_ptr->interlace_type; - - /* This is redundant if we can be sure that the info_ptr values were all - * assigned in png_set_IHDR(). We do the check anyhow in case an - * application has ignored our advice not to mess with the members - * of info_ptr directly. - */ - png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, - info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, - info_ptr->compression_type, info_ptr->filter_type); - - return (1); -} - -#ifdef PNG_oFFs_SUPPORTED -png_uint_32 PNGAPI -png_get_oFFs(png_const_structp png_ptr, png_const_infop info_ptr, - png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) -{ - png_debug1(1, "in %s retrieval function", "oFFs"); - - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) - && offset_x != NULL && offset_y != NULL && unit_type != NULL) - { - *offset_x = info_ptr->x_offset; - *offset_y = info_ptr->y_offset; - *unit_type = (int)info_ptr->offset_unit_type; - return (PNG_INFO_oFFs); - } - - return (0); -} -#endif - -#ifdef PNG_pCAL_SUPPORTED -png_uint_32 PNGAPI -png_get_pCAL(png_const_structp png_ptr, png_const_infop info_ptr, - png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, - png_charp *units, png_charpp *params) -{ - png_debug1(1, "in %s retrieval function", "pCAL"); - - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) - && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && - nparams != NULL && units != NULL && params != NULL) - { - *purpose = info_ptr->pcal_purpose; - *X0 = info_ptr->pcal_X0; - *X1 = info_ptr->pcal_X1; - *type = (int)info_ptr->pcal_type; - *nparams = (int)info_ptr->pcal_nparams; - *units = info_ptr->pcal_units; - *params = info_ptr->pcal_params; - return (PNG_INFO_pCAL); - } - - return (0); -} -#endif - -#ifdef PNG_sCAL_SUPPORTED -# ifdef PNG_FIXED_POINT_SUPPORTED -# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED -png_uint_32 PNGAPI -png_get_sCAL_fixed(png_structp png_ptr, png_const_infop info_ptr, - int *unit, png_fixed_point *width, png_fixed_point *height) -{ - if (png_ptr != NULL && info_ptr != NULL && - (info_ptr->valid & PNG_INFO_sCAL)) - { - *unit = info_ptr->scal_unit; - /*TODO: make this work without FP support */ - *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width"); - *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height), - "sCAL height"); - return (PNG_INFO_sCAL); - } - - return(0); -} -# endif /* FLOATING_ARITHMETIC */ -# endif /* FIXED_POINT */ -# ifdef PNG_FLOATING_POINT_SUPPORTED -png_uint_32 PNGAPI -png_get_sCAL(png_const_structp png_ptr, png_const_infop info_ptr, - int *unit, double *width, double *height) -{ - if (png_ptr != NULL && info_ptr != NULL && - (info_ptr->valid & PNG_INFO_sCAL)) - { - *unit = info_ptr->scal_unit; - *width = atof(info_ptr->scal_s_width); - *height = atof(info_ptr->scal_s_height); - return (PNG_INFO_sCAL); - } - - return(0); -} -# endif /* FLOATING POINT */ -png_uint_32 PNGAPI -png_get_sCAL_s(png_const_structp png_ptr, png_const_infop info_ptr, - int *unit, png_charpp width, png_charpp height) -{ - if (png_ptr != NULL && info_ptr != NULL && - (info_ptr->valid & PNG_INFO_sCAL)) - { - *unit = info_ptr->scal_unit; - *width = info_ptr->scal_s_width; - *height = info_ptr->scal_s_height; - return (PNG_INFO_sCAL); - } - - return(0); -} -#endif /* sCAL */ - -#ifdef PNG_pHYs_SUPPORTED -png_uint_32 PNGAPI -png_get_pHYs(png_const_structp png_ptr, png_const_infop info_ptr, - png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) -{ - png_uint_32 retval = 0; - - png_debug1(1, "in %s retrieval function", "pHYs"); - - if (png_ptr != NULL && info_ptr != NULL && - (info_ptr->valid & PNG_INFO_pHYs)) - { - if (res_x != NULL) - { - *res_x = info_ptr->x_pixels_per_unit; - retval |= PNG_INFO_pHYs; - } - - if (res_y != NULL) - { - *res_y = info_ptr->y_pixels_per_unit; - retval |= PNG_INFO_pHYs; - } - - if (unit_type != NULL) - { - *unit_type = (int)info_ptr->phys_unit_type; - retval |= PNG_INFO_pHYs; - } - } - - return (retval); -} -#endif /* pHYs */ - -png_uint_32 PNGAPI -png_get_PLTE(png_const_structp png_ptr, png_const_infop info_ptr, - png_colorp *palette, int *num_palette) -{ - png_debug1(1, "in %s retrieval function", "PLTE"); - - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) - && palette != NULL) - { - *palette = info_ptr->palette; - *num_palette = info_ptr->num_palette; - png_debug1(3, "num_palette = %d", *num_palette); - return (PNG_INFO_PLTE); - } - - return (0); -} - -#ifdef PNG_sBIT_SUPPORTED -png_uint_32 PNGAPI -png_get_sBIT(png_const_structp png_ptr, png_infop info_ptr, - png_color_8p *sig_bit) -{ - png_debug1(1, "in %s retrieval function", "sBIT"); - - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) - && sig_bit != NULL) - { - *sig_bit = &(info_ptr->sig_bit); - return (PNG_INFO_sBIT); - } - - return (0); -} -#endif - -#ifdef PNG_TEXT_SUPPORTED -png_uint_32 PNGAPI -png_get_text(png_const_structp png_ptr, png_const_infop info_ptr, - png_textp *text_ptr, int *num_text) -{ - if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) - { - png_debug1(1, "in 0x%lx retrieval function", - (unsigned long)png_ptr->chunk_name); - - if (text_ptr != NULL) - *text_ptr = info_ptr->text; - - if (num_text != NULL) - *num_text = info_ptr->num_text; - - return ((png_uint_32)info_ptr->num_text); - } - - if (num_text != NULL) - *num_text = 0; - - return(0); -} -#endif - -#ifdef PNG_tIME_SUPPORTED -png_uint_32 PNGAPI -png_get_tIME(png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time) -{ - png_debug1(1, "in %s retrieval function", "tIME"); - - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) - && mod_time != NULL) - { - *mod_time = &(info_ptr->mod_time); - return (PNG_INFO_tIME); - } - - return (0); -} -#endif - -#ifdef PNG_tRNS_SUPPORTED -png_uint_32 PNGAPI -png_get_tRNS(png_const_structp png_ptr, png_infop info_ptr, - png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color) -{ - png_uint_32 retval = 0; - if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) - { - png_debug1(1, "in %s retrieval function", "tRNS"); - - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - { - if (trans_alpha != NULL) - { - *trans_alpha = info_ptr->trans_alpha; - retval |= PNG_INFO_tRNS; - } - - if (trans_color != NULL) - *trans_color = &(info_ptr->trans_color); - } - - else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ - { - if (trans_color != NULL) - { - *trans_color = &(info_ptr->trans_color); - retval |= PNG_INFO_tRNS; - } - - if (trans_alpha != NULL) - *trans_alpha = NULL; - } - - if (num_trans != NULL) - { - *num_trans = info_ptr->num_trans; - retval |= PNG_INFO_tRNS; - } - } - - return (retval); -} -#endif - -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED -int PNGAPI -png_get_unknown_chunks(png_const_structp png_ptr, png_const_infop info_ptr, - png_unknown_chunkpp unknowns) -{ - if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) - { - *unknowns = info_ptr->unknown_chunks; - return info_ptr->unknown_chunks_num; - } - - return (0); -} -#endif - -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED -png_byte PNGAPI -png_get_rgb_to_gray_status (png_const_structp png_ptr) -{ - return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0); -} -#endif - -#ifdef PNG_USER_CHUNKS_SUPPORTED -png_voidp PNGAPI -png_get_user_chunk_ptr(png_const_structp png_ptr) -{ - return (png_ptr ? png_ptr->user_chunk_ptr : NULL); -} -#endif - -png_size_t PNGAPI -png_get_compression_buffer_size(png_const_structp png_ptr) -{ - return (png_ptr ? png_ptr->zbuf_size : 0); -} - -#ifdef PNG_SET_USER_LIMITS_SUPPORTED -/* These functions were added to libpng 1.2.6 and were enabled - * by default in libpng-1.4.0 */ -png_uint_32 PNGAPI -png_get_user_width_max (png_const_structp png_ptr) -{ - return (png_ptr ? png_ptr->user_width_max : 0); -} - -png_uint_32 PNGAPI -png_get_user_height_max (png_const_structp png_ptr) -{ - return (png_ptr ? png_ptr->user_height_max : 0); -} - -/* This function was added to libpng 1.4.0 */ -png_uint_32 PNGAPI -png_get_chunk_cache_max (png_const_structp png_ptr) -{ - return (png_ptr ? png_ptr->user_chunk_cache_max : 0); -} - -/* This function was added to libpng 1.4.1 */ -png_alloc_size_t PNGAPI -png_get_chunk_malloc_max (png_const_structp png_ptr) -{ - return (png_ptr ? png_ptr->user_chunk_malloc_max : 0); -} -#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ - -/* These functions were added to libpng 1.4.0 */ -#ifdef PNG_IO_STATE_SUPPORTED -png_uint_32 PNGAPI -png_get_io_state (png_structp png_ptr) -{ - return png_ptr->io_state; -} - -png_uint_32 PNGAPI -png_get_io_chunk_type (png_const_structp png_ptr) -{ - return png_ptr->chunk_name; -} - -png_const_bytep PNGAPI -png_get_io_chunk_name (png_structp png_ptr) -{ - PNG_CSTRING_FROM_CHUNK(png_ptr->io_chunk_string, png_ptr->chunk_name); - return png_ptr->io_chunk_string; -} -#endif /* ?PNG_IO_STATE_SUPPORTED */ - -#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ + +/* pngget.c - retrieval of values from info struct + * + * Last changed in libpng 1.5.7 [December 15, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + */ + +#include "pngpriv.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +png_uint_32 PNGAPI +png_get_valid(png_const_structp png_ptr, png_const_infop info_ptr, + png_uint_32 flag) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->valid & flag); + + return(0); +} + +png_size_t PNGAPI +png_get_rowbytes(png_const_structp png_ptr, png_const_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->rowbytes); + + return(0); +} + +#ifdef PNG_INFO_IMAGE_SUPPORTED +png_bytepp PNGAPI +png_get_rows(png_const_structp png_ptr, png_const_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->row_pointers); + + return(0); +} +#endif + +#ifdef PNG_EASY_ACCESS_SUPPORTED +/* Easy access to info, added in libpng-0.99 */ +png_uint_32 PNGAPI +png_get_image_width(png_const_structp png_ptr, png_const_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->width; + + return (0); +} + +png_uint_32 PNGAPI +png_get_image_height(png_const_structp png_ptr, png_const_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->height; + + return (0); +} + +png_byte PNGAPI +png_get_bit_depth(png_const_structp png_ptr, png_const_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->bit_depth; + + return (0); +} + +png_byte PNGAPI +png_get_color_type(png_const_structp png_ptr, png_const_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->color_type; + + return (0); +} + +png_byte PNGAPI +png_get_filter_type(png_const_structp png_ptr, png_const_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->filter_type; + + return (0); +} + +png_byte PNGAPI +png_get_interlace_type(png_const_structp png_ptr, png_const_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->interlace_type; + + return (0); +} + +png_byte PNGAPI +png_get_compression_type(png_const_structp png_ptr, png_const_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->compression_type; + + return (0); +} + +png_uint_32 PNGAPI +png_get_x_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) +{ +#ifdef PNG_pHYs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + { + png_debug1(1, "in %s retrieval function", + "png_get_x_pixels_per_meter"); + + if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) + return (info_ptr->x_pixels_per_unit); + } +#endif + + return (0); +} + +png_uint_32 PNGAPI +png_get_y_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) +{ +#ifdef PNG_pHYs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + { + png_debug1(1, "in %s retrieval function", + "png_get_y_pixels_per_meter"); + + if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) + return (info_ptr->y_pixels_per_unit); + } +#endif + + return (0); +} + +png_uint_32 PNGAPI +png_get_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) +{ +#ifdef PNG_pHYs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + { + png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter"); + + if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER && + info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit) + return (info_ptr->x_pixels_per_unit); + } +#endif + + return (0); +} + +#ifdef PNG_FLOATING_POINT_SUPPORTED +float PNGAPI +png_get_pixel_aspect_ratio(png_const_structp png_ptr, png_const_infop info_ptr) +{ +#ifdef PNG_READ_pHYs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + { + png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio"); + + if (info_ptr->x_pixels_per_unit != 0) + return ((float)((float)info_ptr->y_pixels_per_unit + /(float)info_ptr->x_pixels_per_unit)); + } +#endif + + return ((float)0.0); +} +#endif + +#ifdef PNG_FIXED_POINT_SUPPORTED +png_fixed_point PNGAPI +png_get_pixel_aspect_ratio_fixed(png_const_structp png_ptr, + png_const_infop info_ptr) +{ +#ifdef PNG_READ_pHYs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs) + && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 + && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX + && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX) + { + png_fixed_point res; + + png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed"); + + /* The following casts work because a PNG 4 byte integer only has a valid + * range of 0..2^31-1; otherwise the cast might overflow. + */ + if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1, + (png_int_32)info_ptr->x_pixels_per_unit)) + return res; + } +#endif + + return 0; +} +#endif + +png_int_32 PNGAPI +png_get_x_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr) +{ +#ifdef PNG_oFFs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) + { + png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns"); + + if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) + return (info_ptr->x_offset); + } +#endif + + return (0); +} + +png_int_32 PNGAPI +png_get_y_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr) +{ +#ifdef PNG_oFFs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) + { + png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns"); + + if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) + return (info_ptr->y_offset); + } +#endif + + return (0); +} + +png_int_32 PNGAPI +png_get_x_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr) +{ +#ifdef PNG_oFFs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) + { + png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels"); + + if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) + return (info_ptr->x_offset); + } +#endif + + return (0); +} + +png_int_32 PNGAPI +png_get_y_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr) +{ +#ifdef PNG_oFFs_SUPPORTED + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) + { + png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels"); + + if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) + return (info_ptr->y_offset); + } +#endif + + return (0); +} + +#ifdef PNG_INCH_CONVERSIONS_SUPPORTED +static png_uint_32 +ppi_from_ppm(png_uint_32 ppm) +{ +#if 0 + /* The conversion is *(2.54/100), in binary (32 digits): + * .00000110100000001001110101001001 + */ + png_uint_32 t1001, t1101; + ppm >>= 1; /* .1 */ + t1001 = ppm + (ppm >> 3); /* .1001 */ + t1101 = t1001 + (ppm >> 1); /* .1101 */ + ppm >>= 20; /* .000000000000000000001 */ + t1101 += t1101 >> 15; /* .1101000000000001101 */ + t1001 >>= 11; /* .000000000001001 */ + t1001 += t1001 >> 12; /* .000000000001001000000001001 */ + ppm += t1001; /* .000000000001001000001001001 */ + ppm += t1101; /* .110100000001001110101001001 */ + return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */ +#else + /* The argument is a PNG unsigned integer, so it is not permitted + * to be bigger than 2^31. + */ + png_fixed_point result; + if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127, + 5000)) + return result; + + /* Overflow. */ + return 0; +#endif +} + +png_uint_32 PNGAPI +png_get_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) +{ + return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr)); +} + +png_uint_32 PNGAPI +png_get_x_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) +{ + return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr)); +} + +png_uint_32 PNGAPI +png_get_y_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) +{ + return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr)); +} + +#ifdef PNG_FIXED_POINT_SUPPORTED +static png_fixed_point +png_fixed_inches_from_microns(png_structp png_ptr, png_int_32 microns) +{ + /* Convert from metres * 1,000,000 to inches * 100,000, meters to + * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127. + * Notice that this can overflow - a warning is output and 0 is + * returned. + */ + return png_muldiv_warn(png_ptr, microns, 500, 127); +} + +png_fixed_point PNGAPI +png_get_x_offset_inches_fixed(png_structp png_ptr, + png_const_infop info_ptr) +{ + return png_fixed_inches_from_microns(png_ptr, + png_get_x_offset_microns(png_ptr, info_ptr)); +} +#endif + +#ifdef PNG_FIXED_POINT_SUPPORTED +png_fixed_point PNGAPI +png_get_y_offset_inches_fixed(png_structp png_ptr, + png_const_infop info_ptr) +{ + return png_fixed_inches_from_microns(png_ptr, + png_get_y_offset_microns(png_ptr, info_ptr)); +} +#endif + +#ifdef PNG_FLOATING_POINT_SUPPORTED +float PNGAPI +png_get_x_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr) +{ + /* To avoid the overflow do the conversion directly in floating + * point. + */ + return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937); +} +#endif + +#ifdef PNG_FLOATING_POINT_SUPPORTED +float PNGAPI +png_get_y_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr) +{ + /* To avoid the overflow do the conversion directly in floating + * point. + */ + return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937); +} +#endif + +#ifdef PNG_pHYs_SUPPORTED +png_uint_32 PNGAPI +png_get_pHYs_dpi(png_const_structp png_ptr, png_const_infop info_ptr, + png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) +{ + png_uint_32 retval = 0; + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + { + png_debug1(1, "in %s retrieval function", "pHYs"); + + if (res_x != NULL) + { + *res_x = info_ptr->x_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + + if (res_y != NULL) + { + *res_y = info_ptr->y_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + + if (unit_type != NULL) + { + *unit_type = (int)info_ptr->phys_unit_type; + retval |= PNG_INFO_pHYs; + + if (*unit_type == 1) + { + if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50); + if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50); + } + } + } + + return (retval); +} +#endif /* PNG_pHYs_SUPPORTED */ +#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */ + +/* png_get_channels really belongs in here, too, but it's been around longer */ + +#endif /* PNG_EASY_ACCESS_SUPPORTED */ + +png_byte PNGAPI +png_get_channels(png_const_structp png_ptr, png_const_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->channels); + + return (0); +} + +png_const_bytep PNGAPI +png_get_signature(png_const_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->signature); + + return (NULL); +} + +#ifdef PNG_bKGD_SUPPORTED +png_uint_32 PNGAPI +png_get_bKGD(png_const_structp png_ptr, png_infop info_ptr, + png_color_16p *background) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) + && background != NULL) + { + png_debug1(1, "in %s retrieval function", "bKGD"); + + *background = &(info_ptr->background); + return (PNG_INFO_bKGD); + } + + return (0); +} +#endif + +#ifdef PNG_cHRM_SUPPORTED +/* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the + * same time to correct the rgb grayscale coefficient defaults obtained from the + * cHRM chunk in 1.5.4 + */ +png_uint_32 PNGFAPI +png_get_cHRM_XYZ_fixed(png_structp png_ptr, png_const_infop info_ptr, + png_fixed_point *int_red_X, png_fixed_point *int_red_Y, + png_fixed_point *int_red_Z, png_fixed_point *int_green_X, + png_fixed_point *int_green_Y, png_fixed_point *int_green_Z, + png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y, + png_fixed_point *int_blue_Z) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) + { + png_xy xy; + png_XYZ XYZ; + + png_debug1(1, "in %s retrieval function", "cHRM_XYZ"); + + xy.whitex = info_ptr->x_white; + xy.whitey = info_ptr->y_white; + xy.redx = info_ptr->x_red; + xy.redy = info_ptr->y_red; + xy.greenx = info_ptr->x_green; + xy.greeny = info_ptr->y_green; + xy.bluex = info_ptr->x_blue; + xy.bluey = info_ptr->y_blue; + + /* The *_checked function handles error reporting, so just return 0 if + * there is a failure here. + */ + if (png_XYZ_from_xy_checked(png_ptr, &XYZ, xy)) + { + if (int_red_X != NULL) + *int_red_X = XYZ.redX; + if (int_red_Y != NULL) + *int_red_Y = XYZ.redY; + if (int_red_Z != NULL) + *int_red_Z = XYZ.redZ; + if (int_green_X != NULL) + *int_green_X = XYZ.greenX; + if (int_green_Y != NULL) + *int_green_Y = XYZ.greenY; + if (int_green_Z != NULL) + *int_green_Z = XYZ.greenZ; + if (int_blue_X != NULL) + *int_blue_X = XYZ.blueX; + if (int_blue_Y != NULL) + *int_blue_Y = XYZ.blueY; + if (int_blue_Z != NULL) + *int_blue_Z = XYZ.blueZ; + + return (PNG_INFO_cHRM); + } + } + + return (0); +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_cHRM(png_const_structp png_ptr, png_const_infop info_ptr, + double *white_x, double *white_y, double *red_x, double *red_y, + double *green_x, double *green_y, double *blue_x, double *blue_y) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) + { + png_debug1(1, "in %s retrieval function", "cHRM"); + + if (white_x != NULL) + *white_x = png_float(png_ptr, info_ptr->x_white, "cHRM white X"); + if (white_y != NULL) + *white_y = png_float(png_ptr, info_ptr->y_white, "cHRM white Y"); + if (red_x != NULL) + *red_x = png_float(png_ptr, info_ptr->x_red, "cHRM red X"); + if (red_y != NULL) + *red_y = png_float(png_ptr, info_ptr->y_red, "cHRM red Y"); + if (green_x != NULL) + *green_x = png_float(png_ptr, info_ptr->x_green, "cHRM green X"); + if (green_y != NULL) + *green_y = png_float(png_ptr, info_ptr->y_green, "cHRM green Y"); + if (blue_x != NULL) + *blue_x = png_float(png_ptr, info_ptr->x_blue, "cHRM blue X"); + if (blue_y != NULL) + *blue_y = png_float(png_ptr, info_ptr->y_blue, "cHRM blue Y"); + return (PNG_INFO_cHRM); + } + + return (0); +} + +png_uint_32 PNGAPI +png_get_cHRM_XYZ(png_structp png_ptr, png_const_infop info_ptr, + double *red_X, double *red_Y, double *red_Z, double *green_X, + double *green_Y, double *green_Z, double *blue_X, double *blue_Y, + double *blue_Z) +{ + png_XYZ XYZ; + + if (png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, + &XYZ.redX, &XYZ.redY, &XYZ.redZ, &XYZ.greenX, &XYZ.greenY, &XYZ.greenZ, + &XYZ.blueX, &XYZ.blueY, &XYZ.blueZ) & PNG_INFO_cHRM) + { + if (red_X != NULL) + *red_X = png_float(png_ptr, XYZ.redX, "cHRM red X"); + if (red_Y != NULL) + *red_Y = png_float(png_ptr, XYZ.redY, "cHRM red Y"); + if (red_Z != NULL) + *red_Z = png_float(png_ptr, XYZ.redZ, "cHRM red Z"); + if (green_X != NULL) + *green_X = png_float(png_ptr, XYZ.greenX, "cHRM green X"); + if (green_Y != NULL) + *green_Y = png_float(png_ptr, XYZ.greenY, "cHRM green Y"); + if (green_Z != NULL) + *green_Z = png_float(png_ptr, XYZ.greenZ, "cHRM green Z"); + if (blue_X != NULL) + *blue_X = png_float(png_ptr, XYZ.blueX, "cHRM blue X"); + if (blue_Y != NULL) + *blue_Y = png_float(png_ptr, XYZ.blueY, "cHRM blue Y"); + if (blue_Z != NULL) + *blue_Z = png_float(png_ptr, XYZ.blueZ, "cHRM blue Z"); + return (PNG_INFO_cHRM); + } + + return (0); +} +# endif + +# ifdef PNG_FIXED_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_cHRM_fixed(png_const_structp png_ptr, png_const_infop info_ptr, + png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, + png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, + png_fixed_point *blue_x, png_fixed_point *blue_y) +{ + png_debug1(1, "in %s retrieval function", "cHRM"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) + { + if (white_x != NULL) + *white_x = info_ptr->x_white; + if (white_y != NULL) + *white_y = info_ptr->y_white; + if (red_x != NULL) + *red_x = info_ptr->x_red; + if (red_y != NULL) + *red_y = info_ptr->y_red; + if (green_x != NULL) + *green_x = info_ptr->x_green; + if (green_y != NULL) + *green_y = info_ptr->y_green; + if (blue_x != NULL) + *blue_x = info_ptr->x_blue; + if (blue_y != NULL) + *blue_y = info_ptr->y_blue; + return (PNG_INFO_cHRM); + } + + return (0); +} +# endif +#endif + +#ifdef PNG_gAMA_SUPPORTED +png_uint_32 PNGFAPI +png_get_gAMA_fixed(png_const_structp png_ptr, png_const_infop info_ptr, + png_fixed_point *file_gamma) +{ + png_debug1(1, "in %s retrieval function", "gAMA"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) + && file_gamma != NULL) + { + *file_gamma = info_ptr->gamma; + return (PNG_INFO_gAMA); + } + + return (0); +} +# ifdef PNG_FLOATING_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_gAMA(png_const_structp png_ptr, png_const_infop info_ptr, + double *file_gamma) +{ + png_fixed_point igamma; + png_uint_32 ok = png_get_gAMA_fixed(png_ptr, info_ptr, &igamma); + + if (ok) + *file_gamma = png_float(png_ptr, igamma, "png_get_gAMA"); + + return ok; +} + +# endif +#endif + +#ifdef PNG_sRGB_SUPPORTED +png_uint_32 PNGAPI +png_get_sRGB(png_const_structp png_ptr, png_const_infop info_ptr, + int *file_srgb_intent) +{ + png_debug1(1, "in %s retrieval function", "sRGB"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) + && file_srgb_intent != NULL) + { + *file_srgb_intent = (int)info_ptr->srgb_intent; + return (PNG_INFO_sRGB); + } + + return (0); +} +#endif + +#ifdef PNG_iCCP_SUPPORTED +png_uint_32 PNGAPI +png_get_iCCP(png_const_structp png_ptr, png_const_infop info_ptr, + png_charpp name, int *compression_type, + png_bytepp profile, png_uint_32 *proflen) +{ + png_debug1(1, "in %s retrieval function", "iCCP"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) + && name != NULL && compression_type != NULL && profile != NULL && + proflen != NULL) + { + *name = info_ptr->iccp_name; + *profile = info_ptr->iccp_profile; + /* Compression_type is a dummy so the API won't have to change + * if we introduce multiple compression types later. + */ + *proflen = info_ptr->iccp_proflen; + *compression_type = info_ptr->iccp_compression; + return (PNG_INFO_iCCP); + } + + return (0); +} +#endif + +#ifdef PNG_sPLT_SUPPORTED +png_uint_32 PNGAPI +png_get_sPLT(png_const_structp png_ptr, png_const_infop info_ptr, + png_sPLT_tpp spalettes) +{ + if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) + { + *spalettes = info_ptr->splt_palettes; + return ((png_uint_32)info_ptr->splt_palettes_num); + } + + return (0); +} +#endif + +#ifdef PNG_hIST_SUPPORTED +png_uint_32 PNGAPI +png_get_hIST(png_const_structp png_ptr, png_const_infop info_ptr, + png_uint_16p *hist) +{ + png_debug1(1, "in %s retrieval function", "hIST"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) + && hist != NULL) + { + *hist = info_ptr->hist; + return (PNG_INFO_hIST); + } + + return (0); +} +#endif + +png_uint_32 PNGAPI +png_get_IHDR(png_structp png_ptr, png_infop info_ptr, + png_uint_32 *width, png_uint_32 *height, int *bit_depth, + int *color_type, int *interlace_type, int *compression_type, + int *filter_type) + +{ + png_debug1(1, "in %s retrieval function", "IHDR"); + + if (png_ptr == NULL || info_ptr == NULL || width == NULL || + height == NULL || bit_depth == NULL || color_type == NULL) + return (0); + + *width = info_ptr->width; + *height = info_ptr->height; + *bit_depth = info_ptr->bit_depth; + *color_type = info_ptr->color_type; + + if (compression_type != NULL) + *compression_type = info_ptr->compression_type; + + if (filter_type != NULL) + *filter_type = info_ptr->filter_type; + + if (interlace_type != NULL) + *interlace_type = info_ptr->interlace_type; + + /* This is redundant if we can be sure that the info_ptr values were all + * assigned in png_set_IHDR(). We do the check anyhow in case an + * application has ignored our advice not to mess with the members + * of info_ptr directly. + */ + png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, + info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, + info_ptr->compression_type, info_ptr->filter_type); + + return (1); +} + +#ifdef PNG_oFFs_SUPPORTED +png_uint_32 PNGAPI +png_get_oFFs(png_const_structp png_ptr, png_const_infop info_ptr, + png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) +{ + png_debug1(1, "in %s retrieval function", "oFFs"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) + && offset_x != NULL && offset_y != NULL && unit_type != NULL) + { + *offset_x = info_ptr->x_offset; + *offset_y = info_ptr->y_offset; + *unit_type = (int)info_ptr->offset_unit_type; + return (PNG_INFO_oFFs); + } + + return (0); +} +#endif + +#ifdef PNG_pCAL_SUPPORTED +png_uint_32 PNGAPI +png_get_pCAL(png_const_structp png_ptr, png_const_infop info_ptr, + png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, + png_charp *units, png_charpp *params) +{ + png_debug1(1, "in %s retrieval function", "pCAL"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) + && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && + nparams != NULL && units != NULL && params != NULL) + { + *purpose = info_ptr->pcal_purpose; + *X0 = info_ptr->pcal_X0; + *X1 = info_ptr->pcal_X1; + *type = (int)info_ptr->pcal_type; + *nparams = (int)info_ptr->pcal_nparams; + *units = info_ptr->pcal_units; + *params = info_ptr->pcal_params; + return (PNG_INFO_pCAL); + } + + return (0); +} +#endif + +#ifdef PNG_sCAL_SUPPORTED +# ifdef PNG_FIXED_POINT_SUPPORTED +# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED +png_uint_32 PNGAPI +png_get_sCAL_fixed(png_structp png_ptr, png_const_infop info_ptr, + int *unit, png_fixed_point *width, png_fixed_point *height) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sCAL)) + { + *unit = info_ptr->scal_unit; + /*TODO: make this work without FP support */ + *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width"); + *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height), + "sCAL height"); + return (PNG_INFO_sCAL); + } + + return(0); +} +# endif /* FLOATING_ARITHMETIC */ +# endif /* FIXED_POINT */ +# ifdef PNG_FLOATING_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_sCAL(png_const_structp png_ptr, png_const_infop info_ptr, + int *unit, double *width, double *height) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sCAL)) + { + *unit = info_ptr->scal_unit; + *width = atof(info_ptr->scal_s_width); + *height = atof(info_ptr->scal_s_height); + return (PNG_INFO_sCAL); + } + + return(0); +} +# endif /* FLOATING POINT */ +png_uint_32 PNGAPI +png_get_sCAL_s(png_const_structp png_ptr, png_const_infop info_ptr, + int *unit, png_charpp width, png_charpp height) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sCAL)) + { + *unit = info_ptr->scal_unit; + *width = info_ptr->scal_s_width; + *height = info_ptr->scal_s_height; + return (PNG_INFO_sCAL); + } + + return(0); +} +#endif /* sCAL */ + +#ifdef PNG_pHYs_SUPPORTED +png_uint_32 PNGAPI +png_get_pHYs(png_const_structp png_ptr, png_const_infop info_ptr, + png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) +{ + png_uint_32 retval = 0; + + png_debug1(1, "in %s retrieval function", "pHYs"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs)) + { + if (res_x != NULL) + { + *res_x = info_ptr->x_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + + if (res_y != NULL) + { + *res_y = info_ptr->y_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + + if (unit_type != NULL) + { + *unit_type = (int)info_ptr->phys_unit_type; + retval |= PNG_INFO_pHYs; + } + } + + return (retval); +} +#endif /* pHYs */ + +png_uint_32 PNGAPI +png_get_PLTE(png_const_structp png_ptr, png_const_infop info_ptr, + png_colorp *palette, int *num_palette) +{ + png_debug1(1, "in %s retrieval function", "PLTE"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) + && palette != NULL) + { + *palette = info_ptr->palette; + *num_palette = info_ptr->num_palette; + png_debug1(3, "num_palette = %d", *num_palette); + return (PNG_INFO_PLTE); + } + + return (0); +} + +#ifdef PNG_sBIT_SUPPORTED +png_uint_32 PNGAPI +png_get_sBIT(png_const_structp png_ptr, png_infop info_ptr, + png_color_8p *sig_bit) +{ + png_debug1(1, "in %s retrieval function", "sBIT"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) + && sig_bit != NULL) + { + *sig_bit = &(info_ptr->sig_bit); + return (PNG_INFO_sBIT); + } + + return (0); +} +#endif + +#ifdef PNG_TEXT_SUPPORTED +png_uint_32 PNGAPI +png_get_text(png_const_structp png_ptr, png_const_infop info_ptr, + png_textp *text_ptr, int *num_text) +{ + if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) + { + png_debug1(1, "in 0x%lx retrieval function", + (unsigned long)png_ptr->chunk_name); + + if (text_ptr != NULL) + *text_ptr = info_ptr->text; + + if (num_text != NULL) + *num_text = info_ptr->num_text; + + return ((png_uint_32)info_ptr->num_text); + } + + if (num_text != NULL) + *num_text = 0; + + return(0); +} +#endif + +#ifdef PNG_tIME_SUPPORTED +png_uint_32 PNGAPI +png_get_tIME(png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time) +{ + png_debug1(1, "in %s retrieval function", "tIME"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) + && mod_time != NULL) + { + *mod_time = &(info_ptr->mod_time); + return (PNG_INFO_tIME); + } + + return (0); +} +#endif + +#ifdef PNG_tRNS_SUPPORTED +png_uint_32 PNGAPI +png_get_tRNS(png_const_structp png_ptr, png_infop info_ptr, + png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color) +{ + png_uint_32 retval = 0; + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) + { + png_debug1(1, "in %s retrieval function", "tRNS"); + + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (trans_alpha != NULL) + { + *trans_alpha = info_ptr->trans_alpha; + retval |= PNG_INFO_tRNS; + } + + if (trans_color != NULL) + *trans_color = &(info_ptr->trans_color); + } + + else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ + { + if (trans_color != NULL) + { + *trans_color = &(info_ptr->trans_color); + retval |= PNG_INFO_tRNS; + } + + if (trans_alpha != NULL) + *trans_alpha = NULL; + } + + if (num_trans != NULL) + { + *num_trans = info_ptr->num_trans; + retval |= PNG_INFO_tRNS; + } + } + + return (retval); +} +#endif + +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED +int PNGAPI +png_get_unknown_chunks(png_const_structp png_ptr, png_const_infop info_ptr, + png_unknown_chunkpp unknowns) +{ + if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) + { + *unknowns = info_ptr->unknown_chunks; + return info_ptr->unknown_chunks_num; + } + + return (0); +} +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +png_byte PNGAPI +png_get_rgb_to_gray_status (png_const_structp png_ptr) +{ + return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0); +} +#endif + +#ifdef PNG_USER_CHUNKS_SUPPORTED +png_voidp PNGAPI +png_get_user_chunk_ptr(png_const_structp png_ptr) +{ + return (png_ptr ? png_ptr->user_chunk_ptr : NULL); +} +#endif + +png_size_t PNGAPI +png_get_compression_buffer_size(png_const_structp png_ptr) +{ + return (png_ptr ? png_ptr->zbuf_size : 0); +} + +#ifdef PNG_SET_USER_LIMITS_SUPPORTED +/* These functions were added to libpng 1.2.6 and were enabled + * by default in libpng-1.4.0 */ +png_uint_32 PNGAPI +png_get_user_width_max (png_const_structp png_ptr) +{ + return (png_ptr ? png_ptr->user_width_max : 0); +} + +png_uint_32 PNGAPI +png_get_user_height_max (png_const_structp png_ptr) +{ + return (png_ptr ? png_ptr->user_height_max : 0); +} + +/* This function was added to libpng 1.4.0 */ +png_uint_32 PNGAPI +png_get_chunk_cache_max (png_const_structp png_ptr) +{ + return (png_ptr ? png_ptr->user_chunk_cache_max : 0); +} + +/* This function was added to libpng 1.4.1 */ +png_alloc_size_t PNGAPI +png_get_chunk_malloc_max (png_const_structp png_ptr) +{ + return (png_ptr ? png_ptr->user_chunk_malloc_max : 0); +} +#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ + +/* These functions were added to libpng 1.4.0 */ +#ifdef PNG_IO_STATE_SUPPORTED +png_uint_32 PNGAPI +png_get_io_state (png_structp png_ptr) +{ + return png_ptr->io_state; +} + +png_uint_32 PNGAPI +png_get_io_chunk_type (png_const_structp png_ptr) +{ + return png_ptr->chunk_name; +} + +png_const_bytep PNGAPI +png_get_io_chunk_name (png_structp png_ptr) +{ + PNG_CSTRING_FROM_CHUNK(png_ptr->io_chunk_string, png_ptr->chunk_name); + return png_ptr->io_chunk_string; +} +#endif /* ?PNG_IO_STATE_SUPPORTED */ + +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff --git a/Source/LibPNG/pnginfo.h b/Source/LibPNG/pnginfo.h index bbfb105..a33bfab 100644 --- a/Source/LibPNG/pnginfo.h +++ b/Source/LibPNG/pnginfo.h @@ -1,269 +1,269 @@ - -/* pnginfo.h - header file for PNG reference library - * - * Copyright (c) 1998-2011 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * Last changed in libpng 1.5.0 [January 6, 2011] - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - */ - - /* png_info is a structure that holds the information in a PNG file so - * that the application can find out the characteristics of the image. - * If you are reading the file, this structure will tell you what is - * in the PNG file. If you are writing the file, fill in the information - * you want to put into the PNG file, using png_set_*() functions, then - * call png_write_info(). - * - * The names chosen should be very close to the PNG specification, so - * consult that document for information about the meaning of each field. - * - * With libpng < 0.95, it was only possible to directly set and read the - * the values in the png_info_struct, which meant that the contents and - * order of the values had to remain fixed. With libpng 0.95 and later, - * however, there are now functions that abstract the contents of - * png_info_struct from the application, so this makes it easier to use - * libpng with dynamic libraries, and even makes it possible to use - * libraries that don't have all of the libpng ancillary chunk-handing - * functionality. In libpng-1.5.0 this was moved into a separate private - * file that is not visible to applications. - * - * The following members may have allocated storage attached that should be - * cleaned up before the structure is discarded: palette, trans, text, - * pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile, - * splt_palettes, scal_unit, row_pointers, and unknowns. By default, these - * are automatically freed when the info structure is deallocated, if they were - * allocated internally by libpng. This behavior can be changed by means - * of the png_data_freer() function. - * - * More allocation details: all the chunk-reading functions that - * change these members go through the corresponding png_set_* - * functions. A function to clear these members is available: see - * png_free_data(). The png_set_* functions do not depend on being - * able to point info structure members to any of the storage they are - * passed (they make their own copies), EXCEPT that the png_set_text - * functions use the same storage passed to them in the text_ptr or - * itxt_ptr structure argument, and the png_set_rows and png_set_unknowns - * functions do not make their own copies. - */ -#ifndef PNGINFO_H -#define PNGINFO_H - -struct png_info_def -{ - /* the following are necessary for every PNG file */ - png_uint_32 width; /* width of image in pixels (from IHDR) */ - png_uint_32 height; /* height of image in pixels (from IHDR) */ - png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */ - png_size_t rowbytes; /* bytes needed to hold an untransformed row */ - png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */ - png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */ - png_uint_16 num_trans; /* number of transparent palette color (tRNS) */ - png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */ - png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */ - /* The following three should have been named *_method not *_type */ - png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */ - png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */ - png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ - - /* The following is informational only on read, and not used on writes. */ - png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */ - png_byte pixel_depth; /* number of bits per pixel */ - png_byte spare_byte; /* to align the data, and for future use */ - png_byte signature[8]; /* magic bytes read by libpng from start of file */ - - /* The rest of the data is optional. If you are reading, check the - * valid field to see if the information in these are valid. If you - * are writing, set the valid field to those chunks you want written, - * and initialize the appropriate fields below. - */ - -#if defined(PNG_gAMA_SUPPORTED) - /* The gAMA chunk describes the gamma characteristics of the system - * on which the image was created, normally in the range [1.0, 2.5]. - * Data is valid if (valid & PNG_INFO_gAMA) is non-zero. - */ - png_fixed_point gamma; -#endif - -#ifdef PNG_sRGB_SUPPORTED - /* GR-P, 0.96a */ - /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */ - png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */ -#endif - -#ifdef PNG_TEXT_SUPPORTED - /* The tEXt, and zTXt chunks contain human-readable textual data in - * uncompressed, compressed, and optionally compressed forms, respectively. - * The data in "text" is an array of pointers to uncompressed, - * null-terminated C strings. Each chunk has a keyword that describes the - * textual data contained in that chunk. Keywords are not required to be - * unique, and the text string may be empty. Any number of text chunks may - * be in an image. - */ - int num_text; /* number of comments read or comments to write */ - int max_text; /* current size of text array */ - png_textp text; /* array of comments read or comments to write */ -#endif /* PNG_TEXT_SUPPORTED */ - -#ifdef PNG_tIME_SUPPORTED - /* The tIME chunk holds the last time the displayed image data was - * modified. See the png_time struct for the contents of this struct. - */ - png_time mod_time; -#endif - -#ifdef PNG_sBIT_SUPPORTED - /* The sBIT chunk specifies the number of significant high-order bits - * in the pixel data. Values are in the range [1, bit_depth], and are - * only specified for the channels in the pixel data. The contents of - * the low-order bits is not specified. Data is valid if - * (valid & PNG_INFO_sBIT) is non-zero. - */ - png_color_8 sig_bit; /* significant bits in color channels */ -#endif - -#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \ -defined(PNG_READ_BACKGROUND_SUPPORTED) - /* The tRNS chunk supplies transparency data for paletted images and - * other image types that don't need a full alpha channel. There are - * "num_trans" transparency values for a paletted image, stored in the - * same order as the palette colors, starting from index 0. Values - * for the data are in the range [0, 255], ranging from fully transparent - * to fully opaque, respectively. For non-paletted images, there is a - * single color specified that should be treated as fully transparent. - * Data is valid if (valid & PNG_INFO_tRNS) is non-zero. - */ - png_bytep trans_alpha; /* alpha values for paletted image */ - png_color_16 trans_color; /* transparent color for non-palette image */ -#endif - -#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - /* The bKGD chunk gives the suggested image background color if the - * display program does not have its own background color and the image - * is needs to composited onto a background before display. The colors - * in "background" are normally in the same color space/depth as the - * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero. - */ - png_color_16 background; -#endif - -#ifdef PNG_oFFs_SUPPORTED - /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards - * and downwards from the top-left corner of the display, page, or other - * application-specific co-ordinate space. See the PNG_OFFSET_ defines - * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero. - */ - png_int_32 x_offset; /* x offset on page */ - png_int_32 y_offset; /* y offset on page */ - png_byte offset_unit_type; /* offset units type */ -#endif - -#ifdef PNG_pHYs_SUPPORTED - /* The pHYs chunk gives the physical pixel density of the image for - * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_ - * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero. - */ - png_uint_32 x_pixels_per_unit; /* horizontal pixel density */ - png_uint_32 y_pixels_per_unit; /* vertical pixel density */ - png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */ -#endif - -#ifdef PNG_hIST_SUPPORTED - /* The hIST chunk contains the relative frequency or importance of the - * various palette entries, so that a viewer can intelligently select a - * reduced-color palette, if required. Data is an array of "num_palette" - * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST) - * is non-zero. - */ - png_uint_16p hist; -#endif - -#ifdef PNG_cHRM_SUPPORTED - /* The cHRM chunk describes the CIE color characteristics of the monitor - * on which the PNG was created. This data allows the viewer to do gamut - * mapping of the input image to ensure that the viewer sees the same - * colors in the image as the creator. Values are in the range - * [0.0, 0.8]. Data valid if (valid & PNG_INFO_cHRM) non-zero. - */ - png_fixed_point x_white; - png_fixed_point y_white; - png_fixed_point x_red; - png_fixed_point y_red; - png_fixed_point x_green; - png_fixed_point y_green; - png_fixed_point x_blue; - png_fixed_point y_blue; -#endif - -#ifdef PNG_pCAL_SUPPORTED - /* The pCAL chunk describes a transformation between the stored pixel - * values and original physical data values used to create the image. - * The integer range [0, 2^bit_depth - 1] maps to the floating-point - * range given by [pcal_X0, pcal_X1], and are further transformed by a - * (possibly non-linear) transformation function given by "pcal_type" - * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_ - * defines below, and the PNG-Group's PNG extensions document for a - * complete description of the transformations and how they should be - * implemented, and for a description of the ASCII parameter strings. - * Data values are valid if (valid & PNG_INFO_pCAL) non-zero. - */ - png_charp pcal_purpose; /* pCAL chunk description string */ - png_int_32 pcal_X0; /* minimum value */ - png_int_32 pcal_X1; /* maximum value */ - png_charp pcal_units; /* Latin-1 string giving physical units */ - png_charpp pcal_params; /* ASCII strings containing parameter values */ - png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */ - png_byte pcal_nparams; /* number of parameters given in pcal_params */ -#endif - -/* New members added in libpng-1.0.6 */ - png_uint_32 free_me; /* flags items libpng is responsible for freeing */ - -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \ - defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) - /* Storage for unknown chunks that the library doesn't recognize. */ - png_unknown_chunkp unknown_chunks; - int unknown_chunks_num; -#endif - -#ifdef PNG_iCCP_SUPPORTED - /* iCCP chunk data. */ - png_charp iccp_name; /* profile name */ - png_bytep iccp_profile; /* International Color Consortium profile data */ - png_uint_32 iccp_proflen; /* ICC profile data length */ - png_byte iccp_compression; /* Always zero */ -#endif - -#ifdef PNG_sPLT_SUPPORTED - /* Data on sPLT chunks (there may be more than one). */ - png_sPLT_tp splt_palettes; - png_uint_32 splt_palettes_num; -#endif - -#ifdef PNG_sCAL_SUPPORTED - /* The sCAL chunk describes the actual physical dimensions of the - * subject matter of the graphic. The chunk contains a unit specification - * a byte value, and two ASCII strings representing floating-point - * values. The values are width and height corresponsing to one pixel - * in the image. Data values are valid if (valid & PNG_INFO_sCAL) is - * non-zero. - */ - png_byte scal_unit; /* unit of physical scale */ - png_charp scal_s_width; /* string containing height */ - png_charp scal_s_height; /* string containing width */ -#endif - -#ifdef PNG_INFO_IMAGE_SUPPORTED - /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS) - non-zero */ - /* Data valid if (valid & PNG_INFO_IDAT) non-zero */ - png_bytepp row_pointers; /* the image bits */ -#endif - -}; -#endif /* PNGINFO_H */ + +/* pnginfo.h - header file for PNG reference library + * + * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * Last changed in libpng 1.5.0 [January 6, 2011] + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + + /* png_info is a structure that holds the information in a PNG file so + * that the application can find out the characteristics of the image. + * If you are reading the file, this structure will tell you what is + * in the PNG file. If you are writing the file, fill in the information + * you want to put into the PNG file, using png_set_*() functions, then + * call png_write_info(). + * + * The names chosen should be very close to the PNG specification, so + * consult that document for information about the meaning of each field. + * + * With libpng < 0.95, it was only possible to directly set and read the + * the values in the png_info_struct, which meant that the contents and + * order of the values had to remain fixed. With libpng 0.95 and later, + * however, there are now functions that abstract the contents of + * png_info_struct from the application, so this makes it easier to use + * libpng with dynamic libraries, and even makes it possible to use + * libraries that don't have all of the libpng ancillary chunk-handing + * functionality. In libpng-1.5.0 this was moved into a separate private + * file that is not visible to applications. + * + * The following members may have allocated storage attached that should be + * cleaned up before the structure is discarded: palette, trans, text, + * pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile, + * splt_palettes, scal_unit, row_pointers, and unknowns. By default, these + * are automatically freed when the info structure is deallocated, if they were + * allocated internally by libpng. This behavior can be changed by means + * of the png_data_freer() function. + * + * More allocation details: all the chunk-reading functions that + * change these members go through the corresponding png_set_* + * functions. A function to clear these members is available: see + * png_free_data(). The png_set_* functions do not depend on being + * able to point info structure members to any of the storage they are + * passed (they make their own copies), EXCEPT that the png_set_text + * functions use the same storage passed to them in the text_ptr or + * itxt_ptr structure argument, and the png_set_rows and png_set_unknowns + * functions do not make their own copies. + */ +#ifndef PNGINFO_H +#define PNGINFO_H + +struct png_info_def +{ + /* the following are necessary for every PNG file */ + png_uint_32 width; /* width of image in pixels (from IHDR) */ + png_uint_32 height; /* height of image in pixels (from IHDR) */ + png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */ + png_size_t rowbytes; /* bytes needed to hold an untransformed row */ + png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */ + png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */ + png_uint_16 num_trans; /* number of transparent palette color (tRNS) */ + png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */ + png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */ + /* The following three should have been named *_method not *_type */ + png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */ + png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */ + png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ + + /* The following is informational only on read, and not used on writes. */ + png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */ + png_byte pixel_depth; /* number of bits per pixel */ + png_byte spare_byte; /* to align the data, and for future use */ + png_byte signature[8]; /* magic bytes read by libpng from start of file */ + + /* The rest of the data is optional. If you are reading, check the + * valid field to see if the information in these are valid. If you + * are writing, set the valid field to those chunks you want written, + * and initialize the appropriate fields below. + */ + +#if defined(PNG_gAMA_SUPPORTED) + /* The gAMA chunk describes the gamma characteristics of the system + * on which the image was created, normally in the range [1.0, 2.5]. + * Data is valid if (valid & PNG_INFO_gAMA) is non-zero. + */ + png_fixed_point gamma; +#endif + +#ifdef PNG_sRGB_SUPPORTED + /* GR-P, 0.96a */ + /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */ + png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */ +#endif + +#ifdef PNG_TEXT_SUPPORTED + /* The tEXt, and zTXt chunks contain human-readable textual data in + * uncompressed, compressed, and optionally compressed forms, respectively. + * The data in "text" is an array of pointers to uncompressed, + * null-terminated C strings. Each chunk has a keyword that describes the + * textual data contained in that chunk. Keywords are not required to be + * unique, and the text string may be empty. Any number of text chunks may + * be in an image. + */ + int num_text; /* number of comments read or comments to write */ + int max_text; /* current size of text array */ + png_textp text; /* array of comments read or comments to write */ +#endif /* PNG_TEXT_SUPPORTED */ + +#ifdef PNG_tIME_SUPPORTED + /* The tIME chunk holds the last time the displayed image data was + * modified. See the png_time struct for the contents of this struct. + */ + png_time mod_time; +#endif + +#ifdef PNG_sBIT_SUPPORTED + /* The sBIT chunk specifies the number of significant high-order bits + * in the pixel data. Values are in the range [1, bit_depth], and are + * only specified for the channels in the pixel data. The contents of + * the low-order bits is not specified. Data is valid if + * (valid & PNG_INFO_sBIT) is non-zero. + */ + png_color_8 sig_bit; /* significant bits in color channels */ +#endif + +#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \ +defined(PNG_READ_BACKGROUND_SUPPORTED) + /* The tRNS chunk supplies transparency data for paletted images and + * other image types that don't need a full alpha channel. There are + * "num_trans" transparency values for a paletted image, stored in the + * same order as the palette colors, starting from index 0. Values + * for the data are in the range [0, 255], ranging from fully transparent + * to fully opaque, respectively. For non-paletted images, there is a + * single color specified that should be treated as fully transparent. + * Data is valid if (valid & PNG_INFO_tRNS) is non-zero. + */ + png_bytep trans_alpha; /* alpha values for paletted image */ + png_color_16 trans_color; /* transparent color for non-palette image */ +#endif + +#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + /* The bKGD chunk gives the suggested image background color if the + * display program does not have its own background color and the image + * is needs to composited onto a background before display. The colors + * in "background" are normally in the same color space/depth as the + * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero. + */ + png_color_16 background; +#endif + +#ifdef PNG_oFFs_SUPPORTED + /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards + * and downwards from the top-left corner of the display, page, or other + * application-specific co-ordinate space. See the PNG_OFFSET_ defines + * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero. + */ + png_int_32 x_offset; /* x offset on page */ + png_int_32 y_offset; /* y offset on page */ + png_byte offset_unit_type; /* offset units type */ +#endif + +#ifdef PNG_pHYs_SUPPORTED + /* The pHYs chunk gives the physical pixel density of the image for + * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_ + * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero. + */ + png_uint_32 x_pixels_per_unit; /* horizontal pixel density */ + png_uint_32 y_pixels_per_unit; /* vertical pixel density */ + png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */ +#endif + +#ifdef PNG_hIST_SUPPORTED + /* The hIST chunk contains the relative frequency or importance of the + * various palette entries, so that a viewer can intelligently select a + * reduced-color palette, if required. Data is an array of "num_palette" + * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST) + * is non-zero. + */ + png_uint_16p hist; +#endif + +#ifdef PNG_cHRM_SUPPORTED + /* The cHRM chunk describes the CIE color characteristics of the monitor + * on which the PNG was created. This data allows the viewer to do gamut + * mapping of the input image to ensure that the viewer sees the same + * colors in the image as the creator. Values are in the range + * [0.0, 0.8]. Data valid if (valid & PNG_INFO_cHRM) non-zero. + */ + png_fixed_point x_white; + png_fixed_point y_white; + png_fixed_point x_red; + png_fixed_point y_red; + png_fixed_point x_green; + png_fixed_point y_green; + png_fixed_point x_blue; + png_fixed_point y_blue; +#endif + +#ifdef PNG_pCAL_SUPPORTED + /* The pCAL chunk describes a transformation between the stored pixel + * values and original physical data values used to create the image. + * The integer range [0, 2^bit_depth - 1] maps to the floating-point + * range given by [pcal_X0, pcal_X1], and are further transformed by a + * (possibly non-linear) transformation function given by "pcal_type" + * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_ + * defines below, and the PNG-Group's PNG extensions document for a + * complete description of the transformations and how they should be + * implemented, and for a description of the ASCII parameter strings. + * Data values are valid if (valid & PNG_INFO_pCAL) non-zero. + */ + png_charp pcal_purpose; /* pCAL chunk description string */ + png_int_32 pcal_X0; /* minimum value */ + png_int_32 pcal_X1; /* maximum value */ + png_charp pcal_units; /* Latin-1 string giving physical units */ + png_charpp pcal_params; /* ASCII strings containing parameter values */ + png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */ + png_byte pcal_nparams; /* number of parameters given in pcal_params */ +#endif + +/* New members added in libpng-1.0.6 */ + png_uint_32 free_me; /* flags items libpng is responsible for freeing */ + +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \ + defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) + /* Storage for unknown chunks that the library doesn't recognize. */ + png_unknown_chunkp unknown_chunks; + int unknown_chunks_num; +#endif + +#ifdef PNG_iCCP_SUPPORTED + /* iCCP chunk data. */ + png_charp iccp_name; /* profile name */ + png_bytep iccp_profile; /* International Color Consortium profile data */ + png_uint_32 iccp_proflen; /* ICC profile data length */ + png_byte iccp_compression; /* Always zero */ +#endif + +#ifdef PNG_sPLT_SUPPORTED + /* Data on sPLT chunks (there may be more than one). */ + png_sPLT_tp splt_palettes; + png_uint_32 splt_palettes_num; +#endif + +#ifdef PNG_sCAL_SUPPORTED + /* The sCAL chunk describes the actual physical dimensions of the + * subject matter of the graphic. The chunk contains a unit specification + * a byte value, and two ASCII strings representing floating-point + * values. The values are width and height corresponsing to one pixel + * in the image. Data values are valid if (valid & PNG_INFO_sCAL) is + * non-zero. + */ + png_byte scal_unit; /* unit of physical scale */ + png_charp scal_s_width; /* string containing height */ + png_charp scal_s_height; /* string containing width */ +#endif + +#ifdef PNG_INFO_IMAGE_SUPPORTED + /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS) + non-zero */ + /* Data valid if (valid & PNG_INFO_IDAT) non-zero */ + png_bytepp row_pointers; /* the image bits */ +#endif + +}; +#endif /* PNGINFO_H */ diff --git a/Source/LibPNG/pngmem.c b/Source/LibPNG/pngmem.c index 3099246..f885533 100644 --- a/Source/LibPNG/pngmem.c +++ b/Source/LibPNG/pngmem.c @@ -1,667 +1,667 @@ - -/* pngmem.c - stub functions for memory allocation - * - * Last changed in libpng 1.5.13 [September 27, 2012] - * Copyright (c) 1998-2012 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - * - * This file provides a location for all memory allocation. Users who - * need special memory handling are expected to supply replacement - * functions for png_malloc() and png_free(), and to use - * png_create_read_struct_2() and png_create_write_struct_2() to - * identify the replacement functions. - */ - -#include "pngpriv.h" - -#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) - -/* Borland DOS special memory handler */ -#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) -/* If you change this, be sure to change the one in png.h also */ - -/* Allocate memory for a png_struct. The malloc and memset can be replaced - by a single call to calloc() if this is thought to improve performance. */ -PNG_FUNCTION(png_voidp /* PRIVATE */, -png_create_struct,(int type),PNG_ALLOCATED) -{ -# ifdef PNG_USER_MEM_SUPPORTED - return (png_create_struct_2(type, NULL, NULL)); -} - -/* Alternate version of png_create_struct, for use with user-defined malloc. */ -PNG_FUNCTION(png_voidp /* PRIVATE */, -png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr), - PNG_ALLOCATED) -{ -# endif /* PNG_USER_MEM_SUPPORTED */ - png_size_t size; - png_voidp struct_ptr; - - if (type == PNG_STRUCT_INFO) - size = png_sizeof(png_info); - - else if (type == PNG_STRUCT_PNG) - size = png_sizeof(png_struct); - - else - return (png_get_copyright(NULL)); - -# ifdef PNG_USER_MEM_SUPPORTED - if (malloc_fn != NULL) - { - png_struct dummy_struct; - png_memset(&dummy_struct, 0, sizeof dummy_struct); - dummy_struct.mem_ptr=mem_ptr; - struct_ptr = (*(malloc_fn))(&dummy_struct, (png_alloc_size_t)size); - } - - else -# endif /* PNG_USER_MEM_SUPPORTED */ - struct_ptr = (png_voidp)farmalloc(size); - if (struct_ptr != NULL) - png_memset(struct_ptr, 0, size); - - return (struct_ptr); -} - -/* Free memory allocated by a png_create_struct() call */ -void /* PRIVATE */ -png_destroy_struct(png_voidp struct_ptr) -{ -# ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2(struct_ptr, NULL, NULL); -} - -/* Free memory allocated by a png_create_struct() call */ -void /* PRIVATE */ -png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, - png_voidp mem_ptr) -{ -# endif - if (struct_ptr != NULL) - { -# ifdef PNG_USER_MEM_SUPPORTED - if (free_fn != NULL) - { - png_struct dummy_struct; - png_memset(&dummy_struct, 0, sizeof dummy_struct); - dummy_struct.mem_ptr=mem_ptr; - (*(free_fn))(&dummy_struct, struct_ptr); - return; - } - -# endif /* PNG_USER_MEM_SUPPORTED */ - farfree (struct_ptr); - } -} - -/* Allocate memory. For reasonable files, size should never exceed - * 64K. However, zlib may allocate more then 64K if you don't tell - * it not to. See zconf.h and png.h for more information. zlib does - * need to allocate exactly 64K, so whatever you call here must - * have the ability to do that. - * - * Borland seems to have a problem in DOS mode for exactly 64K. - * It gives you a segment with an offset of 8 (perhaps to store its - * memory stuff). zlib doesn't like this at all, so we have to - * detect and deal with it. This code should not be needed in - * Windows or OS/2 modes, and only in 16 bit mode. This code has - * been updated by Alexander Lehmann for version 0.89 to waste less - * memory. - * - * Note that we can't use png_size_t for the "size" declaration, - * since on some systems a png_size_t is a 16-bit quantity, and as a - * result, we would be truncating potentially larger memory requests - * (which should cause a fatal error) and introducing major problems. - */ -PNG_FUNCTION(png_voidp,PNGAPI -png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) -{ - png_voidp ret; - - ret = (png_malloc(png_ptr, size)); - - if (ret != NULL) - png_memset(ret,0,(png_size_t)size); - - return (ret); -} - -PNG_FUNCTION(png_voidp,PNGAPI -png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) -{ - png_voidp ret; - - if (png_ptr == NULL || size == 0) - return (NULL); - -# ifdef PNG_USER_MEM_SUPPORTED - if (png_ptr->malloc_fn != NULL) - ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size)); - - else - ret = (png_malloc_default(png_ptr, size)); - - if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of memory"); - - return (ret); -} - -PNG_FUNCTION(png_voidp,PNGAPI -png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) -{ - png_voidp ret; -# endif /* PNG_USER_MEM_SUPPORTED */ - - if (png_ptr == NULL || size == 0) - return (NULL); - -# ifdef PNG_MAX_MALLOC_64K - if (size > (png_uint_32)65536L) - { - png_warning(png_ptr, "Cannot Allocate > 64K"); - ret = NULL; - } - - else -# endif - - if (size != (size_t)size) - ret = NULL; - - else if (size == (png_uint_32)65536L) - { - if (png_ptr->offset_table == NULL) - { - /* Try to see if we need to do any of this fancy stuff */ - ret = farmalloc(size); - if (ret == NULL || ((png_size_t)ret & 0xffff)) - { - int num_blocks; - png_uint_32 total_size; - png_bytep table; - int i, mem_level, window_bits; - png_byte huge * hptr; - int window_bits - - if (ret != NULL) - { - farfree(ret); - ret = NULL; - } - - window_bits = - png_ptr->zlib_window_bits >= png_ptr->zlib_text_window_bits ? - png_ptr->zlib_window_bits : png_ptr->zlib_text_window_bits; - - if (window_bits > 14) - num_blocks = (int)(1 << (window_bits - 14)); - - else - num_blocks = 1; - - mem_level = - png_ptr->zlib_mem_level >= png_ptr->zlib_text_mem_level ? - png_ptr->zlib_mem_level : png_ptr->zlib_text_mem_level; - - if (mem_level >= 7) - num_blocks += (int)(1 << (mem_level - 7)); - - else - num_blocks++; - - total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16; - - table = farmalloc(total_size); - - if (table == NULL) - { -# ifndef PNG_USER_MEM_SUPPORTED - if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out Of Memory"); /* Note "O", "M" */ - - else - png_warning(png_ptr, "Out Of Memory"); -# endif - return (NULL); - } - - if ((png_size_t)table & 0xfff0) - { -# ifndef PNG_USER_MEM_SUPPORTED - if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, - "Farmalloc didn't return normalized pointer"); - - else - png_warning(png_ptr, - "Farmalloc didn't return normalized pointer"); -# endif - return (NULL); - } - - png_ptr->offset_table = table; - png_ptr->offset_table_ptr = farmalloc(num_blocks * - png_sizeof(png_bytep)); - - if (png_ptr->offset_table_ptr == NULL) - { -# ifndef PNG_USER_MEM_SUPPORTED - if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out Of memory"); /* Note "O", "m" */ - - else - png_warning(png_ptr, "Out Of memory"); -# endif - return (NULL); - } - - hptr = (png_byte huge *)table; - if ((png_size_t)hptr & 0xf) - { - hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L); - hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */ - } - - for (i = 0; i < num_blocks; i++) - { - png_ptr->offset_table_ptr[i] = (png_bytep)hptr; - hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */ - } - - png_ptr->offset_table_number = num_blocks; - png_ptr->offset_table_count = 0; - png_ptr->offset_table_count_free = 0; - } - } - - if (png_ptr->offset_table_count >= png_ptr->offset_table_number) - { -# ifndef PNG_USER_MEM_SUPPORTED - if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of Memory"); /* Note "O" and "M" */ - - else - png_warning(png_ptr, "Out of Memory"); -# endif - return (NULL); - } - - ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++]; - } - - else - ret = farmalloc(size); - -# ifndef PNG_USER_MEM_SUPPORTED - if (ret == NULL) - { - if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of memory"); /* Note "o" and "m" */ - - else - png_warning(png_ptr, "Out of memory"); /* Note "o" and "m" */ - } -# endif - - return (ret); -} - -/* Free a pointer allocated by png_malloc(). In the default - * configuration, png_ptr is not used, but is passed in case it - * is needed. If ptr is NULL, return without taking any action. - */ -void PNGAPI -png_free(png_structp png_ptr, png_voidp ptr) -{ - if (png_ptr == NULL || ptr == NULL) - return; - -# ifdef PNG_USER_MEM_SUPPORTED - if (png_ptr->free_fn != NULL) - { - (*(png_ptr->free_fn))(png_ptr, ptr); - return; - } - - else - png_free_default(png_ptr, ptr); -} - -void PNGAPI -png_free_default(png_structp png_ptr, png_voidp ptr) -{ -# endif /* PNG_USER_MEM_SUPPORTED */ - - if (png_ptr == NULL || ptr == NULL) - return; - - if (png_ptr->offset_table != NULL) - { - int i; - - for (i = 0; i < png_ptr->offset_table_count; i++) - { - if (ptr == png_ptr->offset_table_ptr[i]) - { - ptr = NULL; - png_ptr->offset_table_count_free++; - break; - } - } - if (png_ptr->offset_table_count_free == png_ptr->offset_table_count) - { - farfree(png_ptr->offset_table); - farfree(png_ptr->offset_table_ptr); - png_ptr->offset_table = NULL; - png_ptr->offset_table_ptr = NULL; - } - } - - if (ptr != NULL) - farfree(ptr); -} - -#else /* Not the Borland DOS special memory handler */ - -/* Allocate memory for a png_struct or a png_info. The malloc and - memset can be replaced by a single call to calloc() if this is thought - to improve performance noticably. */ -PNG_FUNCTION(png_voidp /* PRIVATE */, -png_create_struct,(int type),PNG_ALLOCATED) -{ -# ifdef PNG_USER_MEM_SUPPORTED - return (png_create_struct_2(type, NULL, NULL)); -} - -/* Allocate memory for a png_struct or a png_info. The malloc and - memset can be replaced by a single call to calloc() if this is thought - to improve performance noticably. */ -PNG_FUNCTION(png_voidp /* PRIVATE */, -png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr), - PNG_ALLOCATED) -{ -# endif /* PNG_USER_MEM_SUPPORTED */ - png_size_t size; - png_voidp struct_ptr; - - if (type == PNG_STRUCT_INFO) - size = png_sizeof(png_info); - - else if (type == PNG_STRUCT_PNG) - size = png_sizeof(png_struct); - - else - return (NULL); - -# ifdef PNG_USER_MEM_SUPPORTED - if (malloc_fn != NULL) - { - png_struct dummy_struct; - png_structp png_ptr = &dummy_struct; - png_ptr->mem_ptr=mem_ptr; - struct_ptr = (*(malloc_fn))(png_ptr, size); - - if (struct_ptr != NULL) - png_memset(struct_ptr, 0, size); - - return (struct_ptr); - } -# endif /* PNG_USER_MEM_SUPPORTED */ - -# if defined(__TURBOC__) && !defined(__FLAT__) - struct_ptr = (png_voidp)farmalloc(size); -# else -# if defined(_MSC_VER) && defined(MAXSEG_64K) - struct_ptr = (png_voidp)halloc(size, 1); -# else - struct_ptr = (png_voidp)malloc(size); -# endif -# endif - - if (struct_ptr != NULL) - png_memset(struct_ptr, 0, size); - - return (struct_ptr); -} - - -/* Free memory allocated by a png_create_struct() call */ -void /* PRIVATE */ -png_destroy_struct(png_voidp struct_ptr) -{ -# ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2(struct_ptr, NULL, NULL); -} - -/* Free memory allocated by a png_create_struct() call */ -void /* PRIVATE */ -png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, - png_voidp mem_ptr) -{ -# endif /* PNG_USER_MEM_SUPPORTED */ - if (struct_ptr != NULL) - { -# ifdef PNG_USER_MEM_SUPPORTED - if (free_fn != NULL) - { - png_struct dummy_struct; - png_structp png_ptr = &dummy_struct; - png_ptr->mem_ptr=mem_ptr; - (*(free_fn))(png_ptr, struct_ptr); - return; - } -# endif /* PNG_USER_MEM_SUPPORTED */ -# if defined(__TURBOC__) && !defined(__FLAT__) - farfree(struct_ptr); - -# else -# if defined(_MSC_VER) && defined(MAXSEG_64K) - hfree(struct_ptr); - -# else - free(struct_ptr); - -# endif -# endif - } -} - -/* Allocate memory. For reasonable files, size should never exceed - * 64K. However, zlib may allocate more then 64K if you don't tell - * it not to. See zconf.h and png.h for more information. zlib does - * need to allocate exactly 64K, so whatever you call here must - * have the ability to do that. - */ - -PNG_FUNCTION(png_voidp,PNGAPI -png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) -{ - png_voidp ret; - - ret = (png_malloc(png_ptr, size)); - - if (ret != NULL) - png_memset(ret,0,(png_size_t)size); - - return (ret); -} - -PNG_FUNCTION(png_voidp,PNGAPI -png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) -{ - png_voidp ret; - -# ifdef PNG_USER_MEM_SUPPORTED - if (png_ptr == NULL || size == 0) - return (NULL); - - if (png_ptr->malloc_fn != NULL) - ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size)); - - else - ret = (png_malloc_default(png_ptr, size)); - - if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of Memory"); - - return (ret); -} - -PNG_FUNCTION(png_voidp,PNGAPI -png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) -{ - png_voidp ret; -# endif /* PNG_USER_MEM_SUPPORTED */ - - if (png_ptr == NULL || size == 0) - return (NULL); - -# ifdef PNG_MAX_MALLOC_64K - if (size > (png_uint_32)65536L) - { -# ifndef PNG_USER_MEM_SUPPORTED - if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Cannot Allocate > 64K"); - - else -# endif - return NULL; - } -# endif - - /* Check for overflow */ -# if defined(__TURBOC__) && !defined(__FLAT__) - - if (size != (unsigned long)size) - ret = NULL; - - else - ret = farmalloc(size); - -# else -# if defined(_MSC_VER) && defined(MAXSEG_64K) - if (size != (unsigned long)size) - ret = NULL; - - else - ret = halloc(size, 1); - -# else - if (size != (size_t)size) - ret = NULL; - - else - ret = malloc((size_t)size); -# endif -# endif - -# ifndef PNG_USER_MEM_SUPPORTED - if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) - png_error(png_ptr, "Out of Memory"); -# endif - - return (ret); -} - -/* Free a pointer allocated by png_malloc(). If ptr is NULL, return - * without taking any action. - */ -void PNGAPI -png_free(png_structp png_ptr, png_voidp ptr) -{ - if (png_ptr == NULL || ptr == NULL) - return; - -# ifdef PNG_USER_MEM_SUPPORTED - if (png_ptr->free_fn != NULL) - { - (*(png_ptr->free_fn))(png_ptr, ptr); - return; - } - - else - png_free_default(png_ptr, ptr); -} - -void PNGAPI -png_free_default(png_structp png_ptr, png_voidp ptr) -{ - if (png_ptr == NULL || ptr == NULL) - return; - -# endif /* PNG_USER_MEM_SUPPORTED */ - -# if defined(__TURBOC__) && !defined(__FLAT__) - farfree(ptr); - -# else -# if defined(_MSC_VER) && defined(MAXSEG_64K) - hfree(ptr); - -# else - free(ptr); - -# endif -# endif -} -#endif /* Not Borland DOS special memory handler */ - -/* This function was added at libpng version 1.2.3. The png_malloc_warn() - * function will set up png_malloc() to issue a png_warning and return NULL - * instead of issuing a png_error, if it fails to allocate the requested - * memory. - */ -PNG_FUNCTION(png_voidp,PNGAPI -png_malloc_warn,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) -{ - png_voidp ptr; - png_uint_32 save_flags; - if (png_ptr == NULL) - return (NULL); - - save_flags = png_ptr->flags; - png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; - ptr = (png_voidp)png_malloc((png_structp)png_ptr, size); - png_ptr->flags=save_flags; - return(ptr); -} - - -#ifdef PNG_USER_MEM_SUPPORTED -/* This function is called when the application wants to use another method - * of allocating and freeing memory. - */ -void PNGAPI -png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr - malloc_fn, png_free_ptr free_fn) -{ - if (png_ptr != NULL) - { - png_ptr->mem_ptr = mem_ptr; - png_ptr->malloc_fn = malloc_fn; - png_ptr->free_fn = free_fn; - } -} - -/* This function returns a pointer to the mem_ptr associated with the user - * functions. The application should free any memory associated with this - * pointer before png_write_destroy and png_read_destroy are called. - */ -png_voidp PNGAPI -png_get_mem_ptr(png_const_structp png_ptr) -{ - if (png_ptr == NULL) - return (NULL); - - return ((png_voidp)png_ptr->mem_ptr); -} -#endif /* PNG_USER_MEM_SUPPORTED */ -#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ + +/* pngmem.c - stub functions for memory allocation + * + * Last changed in libpng 1.5.13 [September 27, 2012] + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file provides a location for all memory allocation. Users who + * need special memory handling are expected to supply replacement + * functions for png_malloc() and png_free(), and to use + * png_create_read_struct_2() and png_create_write_struct_2() to + * identify the replacement functions. + */ + +#include "pngpriv.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +/* Borland DOS special memory handler */ +#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) +/* If you change this, be sure to change the one in png.h also */ + +/* Allocate memory for a png_struct. The malloc and memset can be replaced + by a single call to calloc() if this is thought to improve performance. */ +PNG_FUNCTION(png_voidp /* PRIVATE */, +png_create_struct,(int type),PNG_ALLOCATED) +{ +# ifdef PNG_USER_MEM_SUPPORTED + return (png_create_struct_2(type, NULL, NULL)); +} + +/* Alternate version of png_create_struct, for use with user-defined malloc. */ +PNG_FUNCTION(png_voidp /* PRIVATE */, +png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr), + PNG_ALLOCATED) +{ +# endif /* PNG_USER_MEM_SUPPORTED */ + png_size_t size; + png_voidp struct_ptr; + + if (type == PNG_STRUCT_INFO) + size = png_sizeof(png_info); + + else if (type == PNG_STRUCT_PNG) + size = png_sizeof(png_struct); + + else + return (png_get_copyright(NULL)); + +# ifdef PNG_USER_MEM_SUPPORTED + if (malloc_fn != NULL) + { + png_struct dummy_struct; + png_memset(&dummy_struct, 0, sizeof dummy_struct); + dummy_struct.mem_ptr=mem_ptr; + struct_ptr = (*(malloc_fn))(&dummy_struct, (png_alloc_size_t)size); + } + + else +# endif /* PNG_USER_MEM_SUPPORTED */ + struct_ptr = (png_voidp)farmalloc(size); + if (struct_ptr != NULL) + png_memset(struct_ptr, 0, size); + + return (struct_ptr); +} + +/* Free memory allocated by a png_create_struct() call */ +void /* PRIVATE */ +png_destroy_struct(png_voidp struct_ptr) +{ +# ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2(struct_ptr, NULL, NULL); +} + +/* Free memory allocated by a png_create_struct() call */ +void /* PRIVATE */ +png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, + png_voidp mem_ptr) +{ +# endif + if (struct_ptr != NULL) + { +# ifdef PNG_USER_MEM_SUPPORTED + if (free_fn != NULL) + { + png_struct dummy_struct; + png_memset(&dummy_struct, 0, sizeof dummy_struct); + dummy_struct.mem_ptr=mem_ptr; + (*(free_fn))(&dummy_struct, struct_ptr); + return; + } + +# endif /* PNG_USER_MEM_SUPPORTED */ + farfree (struct_ptr); + } +} + +/* Allocate memory. For reasonable files, size should never exceed + * 64K. However, zlib may allocate more then 64K if you don't tell + * it not to. See zconf.h and png.h for more information. zlib does + * need to allocate exactly 64K, so whatever you call here must + * have the ability to do that. + * + * Borland seems to have a problem in DOS mode for exactly 64K. + * It gives you a segment with an offset of 8 (perhaps to store its + * memory stuff). zlib doesn't like this at all, so we have to + * detect and deal with it. This code should not be needed in + * Windows or OS/2 modes, and only in 16 bit mode. This code has + * been updated by Alexander Lehmann for version 0.89 to waste less + * memory. + * + * Note that we can't use png_size_t for the "size" declaration, + * since on some systems a png_size_t is a 16-bit quantity, and as a + * result, we would be truncating potentially larger memory requests + * (which should cause a fatal error) and introducing major problems. + */ +PNG_FUNCTION(png_voidp,PNGAPI +png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) +{ + png_voidp ret; + + ret = (png_malloc(png_ptr, size)); + + if (ret != NULL) + png_memset(ret,0,(png_size_t)size); + + return (ret); +} + +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) +{ + png_voidp ret; + + if (png_ptr == NULL || size == 0) + return (NULL); + +# ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr->malloc_fn != NULL) + ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size)); + + else + ret = (png_malloc_default(png_ptr, size)); + + if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of memory"); + + return (ret); +} + +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) +{ + png_voidp ret; +# endif /* PNG_USER_MEM_SUPPORTED */ + + if (png_ptr == NULL || size == 0) + return (NULL); + +# ifdef PNG_MAX_MALLOC_64K + if (size > (png_uint_32)65536L) + { + png_warning(png_ptr, "Cannot Allocate > 64K"); + ret = NULL; + } + + else +# endif + + if (size != (size_t)size) + ret = NULL; + + else if (size == (png_uint_32)65536L) + { + if (png_ptr->offset_table == NULL) + { + /* Try to see if we need to do any of this fancy stuff */ + ret = farmalloc(size); + if (ret == NULL || ((png_size_t)ret & 0xffff)) + { + int num_blocks; + png_uint_32 total_size; + png_bytep table; + int i, mem_level, window_bits; + png_byte huge * hptr; + int window_bits + + if (ret != NULL) + { + farfree(ret); + ret = NULL; + } + + window_bits = + png_ptr->zlib_window_bits >= png_ptr->zlib_text_window_bits ? + png_ptr->zlib_window_bits : png_ptr->zlib_text_window_bits; + + if (window_bits > 14) + num_blocks = (int)(1 << (window_bits - 14)); + + else + num_blocks = 1; + + mem_level = + png_ptr->zlib_mem_level >= png_ptr->zlib_text_mem_level ? + png_ptr->zlib_mem_level : png_ptr->zlib_text_mem_level; + + if (mem_level >= 7) + num_blocks += (int)(1 << (mem_level - 7)); + + else + num_blocks++; + + total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16; + + table = farmalloc(total_size); + + if (table == NULL) + { +# ifndef PNG_USER_MEM_SUPPORTED + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out Of Memory"); /* Note "O", "M" */ + + else + png_warning(png_ptr, "Out Of Memory"); +# endif + return (NULL); + } + + if ((png_size_t)table & 0xfff0) + { +# ifndef PNG_USER_MEM_SUPPORTED + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, + "Farmalloc didn't return normalized pointer"); + + else + png_warning(png_ptr, + "Farmalloc didn't return normalized pointer"); +# endif + return (NULL); + } + + png_ptr->offset_table = table; + png_ptr->offset_table_ptr = farmalloc(num_blocks * + png_sizeof(png_bytep)); + + if (png_ptr->offset_table_ptr == NULL) + { +# ifndef PNG_USER_MEM_SUPPORTED + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out Of memory"); /* Note "O", "m" */ + + else + png_warning(png_ptr, "Out Of memory"); +# endif + return (NULL); + } + + hptr = (png_byte huge *)table; + if ((png_size_t)hptr & 0xf) + { + hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L); + hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */ + } + + for (i = 0; i < num_blocks; i++) + { + png_ptr->offset_table_ptr[i] = (png_bytep)hptr; + hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */ + } + + png_ptr->offset_table_number = num_blocks; + png_ptr->offset_table_count = 0; + png_ptr->offset_table_count_free = 0; + } + } + + if (png_ptr->offset_table_count >= png_ptr->offset_table_number) + { +# ifndef PNG_USER_MEM_SUPPORTED + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of Memory"); /* Note "O" and "M" */ + + else + png_warning(png_ptr, "Out of Memory"); +# endif + return (NULL); + } + + ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++]; + } + + else + ret = farmalloc(size); + +# ifndef PNG_USER_MEM_SUPPORTED + if (ret == NULL) + { + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of memory"); /* Note "o" and "m" */ + + else + png_warning(png_ptr, "Out of memory"); /* Note "o" and "m" */ + } +# endif + + return (ret); +} + +/* Free a pointer allocated by png_malloc(). In the default + * configuration, png_ptr is not used, but is passed in case it + * is needed. If ptr is NULL, return without taking any action. + */ +void PNGAPI +png_free(png_structp png_ptr, png_voidp ptr) +{ + if (png_ptr == NULL || ptr == NULL) + return; + +# ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr->free_fn != NULL) + { + (*(png_ptr->free_fn))(png_ptr, ptr); + return; + } + + else + png_free_default(png_ptr, ptr); +} + +void PNGAPI +png_free_default(png_structp png_ptr, png_voidp ptr) +{ +# endif /* PNG_USER_MEM_SUPPORTED */ + + if (png_ptr == NULL || ptr == NULL) + return; + + if (png_ptr->offset_table != NULL) + { + int i; + + for (i = 0; i < png_ptr->offset_table_count; i++) + { + if (ptr == png_ptr->offset_table_ptr[i]) + { + ptr = NULL; + png_ptr->offset_table_count_free++; + break; + } + } + if (png_ptr->offset_table_count_free == png_ptr->offset_table_count) + { + farfree(png_ptr->offset_table); + farfree(png_ptr->offset_table_ptr); + png_ptr->offset_table = NULL; + png_ptr->offset_table_ptr = NULL; + } + } + + if (ptr != NULL) + farfree(ptr); +} + +#else /* Not the Borland DOS special memory handler */ + +/* Allocate memory for a png_struct or a png_info. The malloc and + memset can be replaced by a single call to calloc() if this is thought + to improve performance noticably. */ +PNG_FUNCTION(png_voidp /* PRIVATE */, +png_create_struct,(int type),PNG_ALLOCATED) +{ +# ifdef PNG_USER_MEM_SUPPORTED + return (png_create_struct_2(type, NULL, NULL)); +} + +/* Allocate memory for a png_struct or a png_info. The malloc and + memset can be replaced by a single call to calloc() if this is thought + to improve performance noticably. */ +PNG_FUNCTION(png_voidp /* PRIVATE */, +png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr), + PNG_ALLOCATED) +{ +# endif /* PNG_USER_MEM_SUPPORTED */ + png_size_t size; + png_voidp struct_ptr; + + if (type == PNG_STRUCT_INFO) + size = png_sizeof(png_info); + + else if (type == PNG_STRUCT_PNG) + size = png_sizeof(png_struct); + + else + return (NULL); + +# ifdef PNG_USER_MEM_SUPPORTED + if (malloc_fn != NULL) + { + png_struct dummy_struct; + png_structp png_ptr = &dummy_struct; + png_ptr->mem_ptr=mem_ptr; + struct_ptr = (*(malloc_fn))(png_ptr, size); + + if (struct_ptr != NULL) + png_memset(struct_ptr, 0, size); + + return (struct_ptr); + } +# endif /* PNG_USER_MEM_SUPPORTED */ + +# if defined(__TURBOC__) && !defined(__FLAT__) + struct_ptr = (png_voidp)farmalloc(size); +# else +# if defined(_MSC_VER) && defined(MAXSEG_64K) + struct_ptr = (png_voidp)halloc(size, 1); +# else + struct_ptr = (png_voidp)malloc(size); +# endif +# endif + + if (struct_ptr != NULL) + png_memset(struct_ptr, 0, size); + + return (struct_ptr); +} + + +/* Free memory allocated by a png_create_struct() call */ +void /* PRIVATE */ +png_destroy_struct(png_voidp struct_ptr) +{ +# ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2(struct_ptr, NULL, NULL); +} + +/* Free memory allocated by a png_create_struct() call */ +void /* PRIVATE */ +png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, + png_voidp mem_ptr) +{ +# endif /* PNG_USER_MEM_SUPPORTED */ + if (struct_ptr != NULL) + { +# ifdef PNG_USER_MEM_SUPPORTED + if (free_fn != NULL) + { + png_struct dummy_struct; + png_structp png_ptr = &dummy_struct; + png_ptr->mem_ptr=mem_ptr; + (*(free_fn))(png_ptr, struct_ptr); + return; + } +# endif /* PNG_USER_MEM_SUPPORTED */ +# if defined(__TURBOC__) && !defined(__FLAT__) + farfree(struct_ptr); + +# else +# if defined(_MSC_VER) && defined(MAXSEG_64K) + hfree(struct_ptr); + +# else + free(struct_ptr); + +# endif +# endif + } +} + +/* Allocate memory. For reasonable files, size should never exceed + * 64K. However, zlib may allocate more then 64K if you don't tell + * it not to. See zconf.h and png.h for more information. zlib does + * need to allocate exactly 64K, so whatever you call here must + * have the ability to do that. + */ + +PNG_FUNCTION(png_voidp,PNGAPI +png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) +{ + png_voidp ret; + + ret = (png_malloc(png_ptr, size)); + + if (ret != NULL) + png_memset(ret,0,(png_size_t)size); + + return (ret); +} + +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) +{ + png_voidp ret; + +# ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr == NULL || size == 0) + return (NULL); + + if (png_ptr->malloc_fn != NULL) + ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size)); + + else + ret = (png_malloc_default(png_ptr, size)); + + if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of Memory"); + + return (ret); +} + +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) +{ + png_voidp ret; +# endif /* PNG_USER_MEM_SUPPORTED */ + + if (png_ptr == NULL || size == 0) + return (NULL); + +# ifdef PNG_MAX_MALLOC_64K + if (size > (png_uint_32)65536L) + { +# ifndef PNG_USER_MEM_SUPPORTED + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Cannot Allocate > 64K"); + + else +# endif + return NULL; + } +# endif + + /* Check for overflow */ +# if defined(__TURBOC__) && !defined(__FLAT__) + + if (size != (unsigned long)size) + ret = NULL; + + else + ret = farmalloc(size); + +# else +# if defined(_MSC_VER) && defined(MAXSEG_64K) + if (size != (unsigned long)size) + ret = NULL; + + else + ret = halloc(size, 1); + +# else + if (size != (size_t)size) + ret = NULL; + + else + ret = malloc((size_t)size); +# endif +# endif + +# ifndef PNG_USER_MEM_SUPPORTED + if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of Memory"); +# endif + + return (ret); +} + +/* Free a pointer allocated by png_malloc(). If ptr is NULL, return + * without taking any action. + */ +void PNGAPI +png_free(png_structp png_ptr, png_voidp ptr) +{ + if (png_ptr == NULL || ptr == NULL) + return; + +# ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr->free_fn != NULL) + { + (*(png_ptr->free_fn))(png_ptr, ptr); + return; + } + + else + png_free_default(png_ptr, ptr); +} + +void PNGAPI +png_free_default(png_structp png_ptr, png_voidp ptr) +{ + if (png_ptr == NULL || ptr == NULL) + return; + +# endif /* PNG_USER_MEM_SUPPORTED */ + +# if defined(__TURBOC__) && !defined(__FLAT__) + farfree(ptr); + +# else +# if defined(_MSC_VER) && defined(MAXSEG_64K) + hfree(ptr); + +# else + free(ptr); + +# endif +# endif +} +#endif /* Not Borland DOS special memory handler */ + +/* This function was added at libpng version 1.2.3. The png_malloc_warn() + * function will set up png_malloc() to issue a png_warning and return NULL + * instead of issuing a png_error, if it fails to allocate the requested + * memory. + */ +PNG_FUNCTION(png_voidp,PNGAPI +png_malloc_warn,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED) +{ + png_voidp ptr; + png_uint_32 save_flags; + if (png_ptr == NULL) + return (NULL); + + save_flags = png_ptr->flags; + png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; + ptr = (png_voidp)png_malloc((png_structp)png_ptr, size); + png_ptr->flags=save_flags; + return(ptr); +} + + +#ifdef PNG_USER_MEM_SUPPORTED +/* This function is called when the application wants to use another method + * of allocating and freeing memory. + */ +void PNGAPI +png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr + malloc_fn, png_free_ptr free_fn) +{ + if (png_ptr != NULL) + { + png_ptr->mem_ptr = mem_ptr; + png_ptr->malloc_fn = malloc_fn; + png_ptr->free_fn = free_fn; + } +} + +/* This function returns a pointer to the mem_ptr associated with the user + * functions. The application should free any memory associated with this + * pointer before png_write_destroy and png_read_destroy are called. + */ +png_voidp PNGAPI +png_get_mem_ptr(png_const_structp png_ptr) +{ + if (png_ptr == NULL) + return (NULL); + + return ((png_voidp)png_ptr->mem_ptr); +} +#endif /* PNG_USER_MEM_SUPPORTED */ +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff --git a/Source/LibPNG/pngpread.c b/Source/LibPNG/pngpread.c index 39f8f6f..6b65ba8 100644 --- a/Source/LibPNG/pngpread.c +++ b/Source/LibPNG/pngpread.c @@ -1,1315 +1,1315 @@ - -/* pngpread.c - read a png file in push mode - * - * Last changed in libpng 1.5.11 [June 14, 2012] - * Copyright (c) 1998-2012 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - */ - -#include "pngpriv.h" - -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED - -/* Push model modes */ -#define PNG_READ_SIG_MODE 0 -#define PNG_READ_CHUNK_MODE 1 -#define PNG_READ_IDAT_MODE 2 -#define PNG_SKIP_MODE 3 -#define PNG_READ_tEXt_MODE 4 -#define PNG_READ_zTXt_MODE 5 -#define PNG_READ_DONE_MODE 6 -#define PNG_READ_iTXt_MODE 7 -#define PNG_ERROR_MODE 8 - -void PNGAPI -png_process_data(png_structp png_ptr, png_infop info_ptr, - png_bytep buffer, png_size_t buffer_size) -{ - if (png_ptr == NULL || info_ptr == NULL) - return; - - png_push_restore_buffer(png_ptr, buffer, buffer_size); - - while (png_ptr->buffer_size) - { - png_process_some_data(png_ptr, info_ptr); - } -} - -png_size_t PNGAPI -png_process_data_pause(png_structp png_ptr, int save) -{ - if (png_ptr != NULL) - { - /* It's easiest for the caller if we do the save, then the caller doesn't - * have to supply the same data again: - */ - if (save) - png_push_save_buffer(png_ptr); - else - { - /* This includes any pending saved bytes: */ - png_size_t remaining = png_ptr->buffer_size; - png_ptr->buffer_size = 0; - - /* So subtract the saved buffer size, unless all the data - * is actually 'saved', in which case we just return 0 - */ - if (png_ptr->save_buffer_size < remaining) - return remaining - png_ptr->save_buffer_size; - } - } - - return 0; -} - -png_uint_32 PNGAPI -png_process_data_skip(png_structp png_ptr) -{ - png_uint_32 remaining = 0; - - if (png_ptr != NULL && png_ptr->process_mode == PNG_SKIP_MODE && - png_ptr->skip_length > 0) - { - /* At the end of png_process_data the buffer size must be 0 (see the loop - * above) so we can detect a broken call here: - */ - if (png_ptr->buffer_size != 0) - png_error(png_ptr, - "png_process_data_skip called inside png_process_data"); - - /* If is impossible for there to be a saved buffer at this point - - * otherwise we could not be in SKIP mode. This will also happen if - * png_process_skip is called inside png_process_data (but only very - * rarely.) - */ - if (png_ptr->save_buffer_size != 0) - png_error(png_ptr, "png_process_data_skip called with saved data"); - - remaining = png_ptr->skip_length; - png_ptr->skip_length = 0; - png_ptr->process_mode = PNG_READ_CHUNK_MODE; - } - - return remaining; -} - -/* What we do with the incoming data depends on what we were previously - * doing before we ran out of data... - */ -void /* PRIVATE */ -png_process_some_data(png_structp png_ptr, png_infop info_ptr) -{ - if (png_ptr == NULL) - return; - - switch (png_ptr->process_mode) - { - case PNG_READ_SIG_MODE: - { - png_push_read_sig(png_ptr, info_ptr); - break; - } - - case PNG_READ_CHUNK_MODE: - { - png_push_read_chunk(png_ptr, info_ptr); - break; - } - - case PNG_READ_IDAT_MODE: - { - png_push_read_IDAT(png_ptr); - break; - } - - case PNG_SKIP_MODE: - { - png_push_crc_finish(png_ptr); - break; - } - - default: - { - png_ptr->buffer_size = 0; - break; - } - } -} - -/* Read any remaining signature bytes from the stream and compare them with - * the correct PNG signature. It is possible that this routine is called - * with bytes already read from the signature, either because they have been - * checked by the calling application, or because of multiple calls to this - * routine. - */ -void /* PRIVATE */ -png_push_read_sig(png_structp png_ptr, png_infop info_ptr) -{ - png_size_t num_checked = png_ptr->sig_bytes, - num_to_check = 8 - num_checked; - - if (png_ptr->buffer_size < num_to_check) - { - num_to_check = png_ptr->buffer_size; - } - - png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]), - num_to_check); - png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check); - - if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) - { - if (num_checked < 4 && - png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) - png_error(png_ptr, "Not a PNG file"); - - else - png_error(png_ptr, "PNG file corrupted by ASCII conversion"); - } - - else - { - if (png_ptr->sig_bytes >= 8) - { - png_ptr->process_mode = PNG_READ_CHUNK_MODE; - } - } -} - -void /* PRIVATE */ -png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) -{ - png_uint_32 chunk_name; - - /* First we make sure we have enough data for the 4 byte chunk name - * and the 4 byte chunk length before proceeding with decoding the - * chunk data. To fully decode each of these chunks, we also make - * sure we have enough data in the buffer for the 4 byte CRC at the - * end of every chunk (except IDAT, which is handled separately). - */ - if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) - { - png_byte chunk_length[4]; - png_byte chunk_tag[4]; - - if (png_ptr->buffer_size < 8) - { - png_push_save_buffer(png_ptr); - return; - } - - png_push_fill_buffer(png_ptr, chunk_length, 4); - png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); - png_reset_crc(png_ptr); - png_crc_read(png_ptr, chunk_tag, 4); - png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); - png_check_chunk_name(png_ptr, png_ptr->chunk_name); - png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; - } - - chunk_name = png_ptr->chunk_name; - - if (chunk_name == png_IDAT) - { - /* This is here above the if/else case statement below because if the - * unknown handling marks 'IDAT' as unknown then the IDAT handling case is - * completely skipped. - * - * TODO: there must be a better way of doing this. - */ - if (png_ptr->mode & PNG_AFTER_IDAT) - png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; - } - - if (chunk_name == png_IHDR) - { - if (png_ptr->push_length != 13) - png_error(png_ptr, "Invalid IHDR length"); - - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length); - } - - else if (chunk_name == png_IEND) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length); - - png_ptr->process_mode = PNG_READ_DONE_MODE; - png_push_have_end(png_ptr, info_ptr); - } - -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - else if (png_chunk_unknown_handling(png_ptr, chunk_name)) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - if (chunk_name == png_IDAT) - png_ptr->mode |= PNG_HAVE_IDAT; - - png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); - - if (chunk_name == png_PLTE) - png_ptr->mode |= PNG_HAVE_PLTE; - - else if (chunk_name == png_IDAT) - { - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before IDAT"); - - else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && - !(png_ptr->mode & PNG_HAVE_PLTE)) - png_error(png_ptr, "Missing PLTE before IDAT"); - } - } -#endif - - else if (chunk_name == png_PLTE) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length); - } - - else if (chunk_name == png_IDAT) - { - /* If we reach an IDAT chunk, this means we have read all of the - * header chunks, and we can start reading the image (or if this - * is called after the image has been read - we have an error). - */ - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before IDAT"); - - else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && - !(png_ptr->mode & PNG_HAVE_PLTE)) - png_error(png_ptr, "Missing PLTE before IDAT"); - - if (png_ptr->mode & PNG_HAVE_IDAT) - { - if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) - if (png_ptr->push_length == 0) - return; - - if (png_ptr->mode & PNG_AFTER_IDAT) - png_benign_error(png_ptr, "Too many IDATs found"); - } - - png_ptr->idat_size = png_ptr->push_length; - png_ptr->mode |= PNG_HAVE_IDAT; - png_ptr->process_mode = PNG_READ_IDAT_MODE; - png_push_have_info(png_ptr, info_ptr); - png_ptr->zstream.avail_out = - (uInt) PNG_ROWBYTES(png_ptr->pixel_depth, - png_ptr->iwidth) + 1; - png_ptr->zstream.next_out = png_ptr->row_buf; - return; - } - -#ifdef PNG_READ_gAMA_SUPPORTED - else if (png_ptr->chunk_name == png_gAMA) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_sBIT_SUPPORTED - else if (png_ptr->chunk_name == png_sBIT) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_cHRM_SUPPORTED - else if (png_ptr->chunk_name == png_cHRM) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_sRGB_SUPPORTED - else if (chunk_name == png_sRGB) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_iCCP_SUPPORTED - else if (png_ptr->chunk_name == png_iCCP) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_sPLT_SUPPORTED - else if (chunk_name == png_sPLT) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_tRNS_SUPPORTED - else if (chunk_name == png_tRNS) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_bKGD_SUPPORTED - else if (chunk_name == png_bKGD) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_hIST_SUPPORTED - else if (chunk_name == png_hIST) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_pHYs_SUPPORTED - else if (chunk_name == png_pHYs) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_oFFs_SUPPORTED - else if (chunk_name == png_oFFs) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length); - } -#endif - -#ifdef PNG_READ_pCAL_SUPPORTED - else if (chunk_name == png_pCAL) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_sCAL_SUPPORTED - else if (chunk_name == png_sCAL) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_tIME_SUPPORTED - else if (chunk_name == png_tIME) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_tEXt_SUPPORTED - else if (chunk_name == png_tEXt) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_zTXt_SUPPORTED - else if (chunk_name == png_zTXt) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif -#ifdef PNG_READ_iTXt_SUPPORTED - else if (chunk_name == png_iTXt) - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - - png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); - } - -#endif - - else - { - if (png_ptr->push_length + 4 > png_ptr->buffer_size) - { - png_push_save_buffer(png_ptr); - return; - } - png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); - } - - png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; -} - -void /* PRIVATE */ -png_push_crc_skip(png_structp png_ptr, png_uint_32 skip) -{ - png_ptr->process_mode = PNG_SKIP_MODE; - png_ptr->skip_length = skip; -} - -void /* PRIVATE */ -png_push_crc_finish(png_structp png_ptr) -{ - if (png_ptr->skip_length && png_ptr->save_buffer_size) - { - png_size_t save_size = png_ptr->save_buffer_size; - png_uint_32 skip_length = png_ptr->skip_length; - - /* We want the smaller of 'skip_length' and 'save_buffer_size', but - * they are of different types and we don't know which variable has the - * fewest bits. Carefully select the smaller and cast it to the type of - * the larger - this cannot overflow. Do not cast in the following test - * - it will break on either 16 or 64 bit platforms. - */ - if (skip_length < save_size) - save_size = (png_size_t)skip_length; - - else - skip_length = (png_uint_32)save_size; - - png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); - - png_ptr->skip_length -= skip_length; - png_ptr->buffer_size -= save_size; - png_ptr->save_buffer_size -= save_size; - png_ptr->save_buffer_ptr += save_size; - } - - if (png_ptr->skip_length && png_ptr->current_buffer_size) - { - png_size_t save_size = png_ptr->current_buffer_size; - png_uint_32 skip_length = png_ptr->skip_length; - - /* We want the smaller of 'skip_length' and 'current_buffer_size', here, - * the same problem exists as above and the same solution. - */ - if (skip_length < save_size) - save_size = (png_size_t)skip_length; - - else - skip_length = (png_uint_32)save_size; - - png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); - - png_ptr->skip_length -= skip_length; - png_ptr->buffer_size -= save_size; - png_ptr->current_buffer_size -= save_size; - png_ptr->current_buffer_ptr += save_size; - } - - if (!png_ptr->skip_length) - { - if (png_ptr->buffer_size < 4) - { - png_push_save_buffer(png_ptr); - return; - } - - png_crc_finish(png_ptr, 0); - png_ptr->process_mode = PNG_READ_CHUNK_MODE; - } -} - -void PNGCBAPI -png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) -{ - png_bytep ptr; - - if (png_ptr == NULL) - return; - - ptr = buffer; - - if (png_ptr->save_buffer_size) - { - png_size_t save_size; - - if (length < png_ptr->save_buffer_size) - save_size = length; - - else - save_size = png_ptr->save_buffer_size; - - png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size); - length -= save_size; - ptr += save_size; - png_ptr->buffer_size -= save_size; - png_ptr->save_buffer_size -= save_size; - png_ptr->save_buffer_ptr += save_size; - } - - if (length && png_ptr->current_buffer_size) - { - png_size_t save_size; - - if (length < png_ptr->current_buffer_size) - save_size = length; - - else - save_size = png_ptr->current_buffer_size; - - png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size); - png_ptr->buffer_size -= save_size; - png_ptr->current_buffer_size -= save_size; - png_ptr->current_buffer_ptr += save_size; - } -} - -void /* PRIVATE */ -png_push_save_buffer(png_structp png_ptr) -{ - if (png_ptr->save_buffer_size) - { - if (png_ptr->save_buffer_ptr != png_ptr->save_buffer) - { - png_size_t i, istop; - png_bytep sp; - png_bytep dp; - - istop = png_ptr->save_buffer_size; - - for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer; - i < istop; i++, sp++, dp++) - { - *dp = *sp; - } - } - } - - if (png_ptr->save_buffer_size + png_ptr->current_buffer_size > - png_ptr->save_buffer_max) - { - png_size_t new_max; - png_bytep old_buffer; - - if (png_ptr->save_buffer_size > PNG_SIZE_MAX - - (png_ptr->current_buffer_size + 256)) - { - png_error(png_ptr, "Potential overflow of save_buffer"); - } - - new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256; - old_buffer = png_ptr->save_buffer; - png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr, new_max); - - if (png_ptr->save_buffer == NULL) - { - png_free(png_ptr, old_buffer); - png_error(png_ptr, "Insufficient memory for save_buffer"); - } - - png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); - png_free(png_ptr, old_buffer); - png_ptr->save_buffer_max = new_max; - } - - if (png_ptr->current_buffer_size) - { - png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size, - png_ptr->current_buffer_ptr, png_ptr->current_buffer_size); - png_ptr->save_buffer_size += png_ptr->current_buffer_size; - png_ptr->current_buffer_size = 0; - } - - png_ptr->save_buffer_ptr = png_ptr->save_buffer; - png_ptr->buffer_size = 0; -} - -void /* PRIVATE */ -png_push_restore_buffer(png_structp png_ptr, png_bytep buffer, - png_size_t buffer_length) -{ - png_ptr->current_buffer = buffer; - png_ptr->current_buffer_size = buffer_length; - png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size; - png_ptr->current_buffer_ptr = png_ptr->current_buffer; -} - -void /* PRIVATE */ -png_push_read_IDAT(png_structp png_ptr) -{ - if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) - { - png_byte chunk_length[4]; - png_byte chunk_tag[4]; - - /* TODO: this code can be commoned up with the same code in push_read */ - if (png_ptr->buffer_size < 8) - { - png_push_save_buffer(png_ptr); - return; - } - - png_push_fill_buffer(png_ptr, chunk_length, 4); - png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); - png_reset_crc(png_ptr); - png_crc_read(png_ptr, chunk_tag, 4); - png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); - png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; - - if (png_ptr->chunk_name != png_IDAT) - { - png_ptr->process_mode = PNG_READ_CHUNK_MODE; - - if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) - png_error(png_ptr, "Not enough compressed data"); - - return; - } - - png_ptr->idat_size = png_ptr->push_length; - } - - if (png_ptr->idat_size && png_ptr->save_buffer_size) - { - png_size_t save_size = png_ptr->save_buffer_size; - png_uint_32 idat_size = png_ptr->idat_size; - - /* We want the smaller of 'idat_size' and 'current_buffer_size', but they - * are of different types and we don't know which variable has the fewest - * bits. Carefully select the smaller and cast it to the type of the - * larger - this cannot overflow. Do not cast in the following test - it - * will break on either 16 or 64 bit platforms. - */ - if (idat_size < save_size) - save_size = (png_size_t)idat_size; - - else - idat_size = (png_uint_32)save_size; - - png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); - - png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size); - - png_ptr->idat_size -= idat_size; - png_ptr->buffer_size -= save_size; - png_ptr->save_buffer_size -= save_size; - png_ptr->save_buffer_ptr += save_size; - } - - if (png_ptr->idat_size && png_ptr->current_buffer_size) - { - png_size_t save_size = png_ptr->current_buffer_size; - png_uint_32 idat_size = png_ptr->idat_size; - - /* We want the smaller of 'idat_size' and 'current_buffer_size', but they - * are of different types and we don't know which variable has the fewest - * bits. Carefully select the smaller and cast it to the type of the - * larger - this cannot overflow. - */ - if (idat_size < save_size) - save_size = (png_size_t)idat_size; - - else - idat_size = (png_uint_32)save_size; - - png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); - - png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size); - - png_ptr->idat_size -= idat_size; - png_ptr->buffer_size -= save_size; - png_ptr->current_buffer_size -= save_size; - png_ptr->current_buffer_ptr += save_size; - } - - if (!png_ptr->idat_size) - { - if (png_ptr->buffer_size < 4) - { - png_push_save_buffer(png_ptr); - return; - } - - png_crc_finish(png_ptr, 0); - png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; - png_ptr->mode |= PNG_AFTER_IDAT; - } -} - -void /* PRIVATE */ -png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, - png_size_t buffer_length) -{ - /* The caller checks for a non-zero buffer length. */ - if (!(buffer_length > 0) || buffer == NULL) - png_error(png_ptr, "No IDAT data (internal error)"); - - /* This routine must process all the data it has been given - * before returning, calling the row callback as required to - * handle the uncompressed results. - */ - png_ptr->zstream.next_in = buffer; - png_ptr->zstream.avail_in = (uInt)buffer_length; - - /* Keep going until the decompressed data is all processed - * or the stream marked as finished. - */ - while (png_ptr->zstream.avail_in > 0 && - !(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) - { - int ret; - - /* We have data for zlib, but we must check that zlib - * has someplace to put the results. It doesn't matter - * if we don't expect any results -- it may be the input - * data is just the LZ end code. - */ - if (!(png_ptr->zstream.avail_out > 0)) - { - png_ptr->zstream.avail_out = - (uInt) PNG_ROWBYTES(png_ptr->pixel_depth, - png_ptr->iwidth) + 1; - - png_ptr->zstream.next_out = png_ptr->row_buf; - } - - /* Using Z_SYNC_FLUSH here means that an unterminated - * LZ stream (a stream with a missing end code) can still - * be handled, otherwise (Z_NO_FLUSH) a future zlib - * implementation might defer output and therefore - * change the current behavior (see comments in inflate.c - * for why this doesn't happen at present with zlib 1.2.5). - */ - ret = inflate(&png_ptr->zstream, Z_SYNC_FLUSH); - - /* Check for any failure before proceeding. */ - if (ret != Z_OK && ret != Z_STREAM_END) - { - /* Terminate the decompression. */ - png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; - - /* This may be a truncated stream (missing or - * damaged end code). Treat that as a warning. - */ - if (png_ptr->row_number >= png_ptr->num_rows || - png_ptr->pass > 6) - png_warning(png_ptr, "Truncated compressed data in IDAT"); - - else - png_error(png_ptr, "Decompression error in IDAT"); - - /* Skip the check on unprocessed input */ - return; - } - - /* Did inflate output any data? */ - if (png_ptr->zstream.next_out != png_ptr->row_buf) - { - /* Is this unexpected data after the last row? - * If it is, artificially terminate the LZ output - * here. - */ - if (png_ptr->row_number >= png_ptr->num_rows || - png_ptr->pass > 6) - { - /* Extra data. */ - png_warning(png_ptr, "Extra compressed data in IDAT"); - png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; - - /* Do no more processing; skip the unprocessed - * input check below. - */ - return; - } - - /* Do we have a complete row? */ - if (png_ptr->zstream.avail_out == 0) - png_push_process_row(png_ptr); - } - - /* And check for the end of the stream. */ - if (ret == Z_STREAM_END) - png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; - } - - /* All the data should have been processed, if anything - * is left at this point we have bytes of IDAT data - * after the zlib end code. - */ - if (png_ptr->zstream.avail_in > 0) - png_warning(png_ptr, "Extra compression data in IDAT"); -} - -void /* PRIVATE */ -png_push_process_row(png_structp png_ptr) -{ - /* 1.5.6: row_info moved out of png_struct to a local here. */ - png_row_info row_info; - - row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */ - row_info.color_type = png_ptr->color_type; - row_info.bit_depth = png_ptr->bit_depth; - row_info.channels = png_ptr->channels; - row_info.pixel_depth = png_ptr->pixel_depth; - row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); - - if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) - { - if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) - png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1, - png_ptr->prev_row + 1, png_ptr->row_buf[0]); - else - png_error(png_ptr, "bad adaptive filter value"); - } - - /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before - * 1.5.6, while the buffer really is this big in current versions of libpng - * it may not be in the future, so this was changed just to copy the - * interlaced row count: - */ - png_memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1); - -#ifdef PNG_READ_TRANSFORMS_SUPPORTED - if (png_ptr->transformations) - png_do_read_transformations(png_ptr, &row_info); -#endif - - /* The transformed pixel depth should match the depth now in row_info. */ - if (png_ptr->transformed_pixel_depth == 0) - { - png_ptr->transformed_pixel_depth = row_info.pixel_depth; - if (row_info.pixel_depth > png_ptr->maximum_pixel_depth) - png_error(png_ptr, "progressive row overflow"); - } - - else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth) - png_error(png_ptr, "internal progressive row size calculation error"); - - -#ifdef PNG_READ_INTERLACING_SUPPORTED - /* Blow up interlaced rows to full size */ - if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) - { - if (png_ptr->pass < 6) - png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass, - png_ptr->transformations); - - switch (png_ptr->pass) - { - case 0: - { - int i; - for (i = 0; i < 8 && png_ptr->pass == 0; i++) - { - png_push_have_row(png_ptr, png_ptr->row_buf + 1); - png_read_push_finish_row(png_ptr); /* Updates png_ptr->pass */ - } - - if (png_ptr->pass == 2) /* Pass 1 might be empty */ - { - for (i = 0; i < 4 && png_ptr->pass == 2; i++) - { - png_push_have_row(png_ptr, NULL); - png_read_push_finish_row(png_ptr); - } - } - - if (png_ptr->pass == 4 && png_ptr->height <= 4) - { - for (i = 0; i < 2 && png_ptr->pass == 4; i++) - { - png_push_have_row(png_ptr, NULL); - png_read_push_finish_row(png_ptr); - } - } - - if (png_ptr->pass == 6 && png_ptr->height <= 4) - { - png_push_have_row(png_ptr, NULL); - png_read_push_finish_row(png_ptr); - } - - break; - } - - case 1: - { - int i; - for (i = 0; i < 8 && png_ptr->pass == 1; i++) - { - png_push_have_row(png_ptr, png_ptr->row_buf + 1); - png_read_push_finish_row(png_ptr); - } - - if (png_ptr->pass == 2) /* Skip top 4 generated rows */ - { - for (i = 0; i < 4 && png_ptr->pass == 2; i++) - { - png_push_have_row(png_ptr, NULL); - png_read_push_finish_row(png_ptr); - } - } - - break; - } - - case 2: - { - int i; - - for (i = 0; i < 4 && png_ptr->pass == 2; i++) - { - png_push_have_row(png_ptr, png_ptr->row_buf + 1); - png_read_push_finish_row(png_ptr); - } - - for (i = 0; i < 4 && png_ptr->pass == 2; i++) - { - png_push_have_row(png_ptr, NULL); - png_read_push_finish_row(png_ptr); - } - - if (png_ptr->pass == 4) /* Pass 3 might be empty */ - { - for (i = 0; i < 2 && png_ptr->pass == 4; i++) - { - png_push_have_row(png_ptr, NULL); - png_read_push_finish_row(png_ptr); - } - } - - break; - } - - case 3: - { - int i; - - for (i = 0; i < 4 && png_ptr->pass == 3; i++) - { - png_push_have_row(png_ptr, png_ptr->row_buf + 1); - png_read_push_finish_row(png_ptr); - } - - if (png_ptr->pass == 4) /* Skip top two generated rows */ - { - for (i = 0; i < 2 && png_ptr->pass == 4; i++) - { - png_push_have_row(png_ptr, NULL); - png_read_push_finish_row(png_ptr); - } - } - - break; - } - - case 4: - { - int i; - - for (i = 0; i < 2 && png_ptr->pass == 4; i++) - { - png_push_have_row(png_ptr, png_ptr->row_buf + 1); - png_read_push_finish_row(png_ptr); - } - - for (i = 0; i < 2 && png_ptr->pass == 4; i++) - { - png_push_have_row(png_ptr, NULL); - png_read_push_finish_row(png_ptr); - } - - if (png_ptr->pass == 6) /* Pass 5 might be empty */ - { - png_push_have_row(png_ptr, NULL); - png_read_push_finish_row(png_ptr); - } - - break; - } - - case 5: - { - int i; - - for (i = 0; i < 2 && png_ptr->pass == 5; i++) - { - png_push_have_row(png_ptr, png_ptr->row_buf + 1); - png_read_push_finish_row(png_ptr); - } - - if (png_ptr->pass == 6) /* Skip top generated row */ - { - png_push_have_row(png_ptr, NULL); - png_read_push_finish_row(png_ptr); - } - - break; - } - - default: - case 6: - { - png_push_have_row(png_ptr, png_ptr->row_buf + 1); - png_read_push_finish_row(png_ptr); - - if (png_ptr->pass != 6) - break; - - png_push_have_row(png_ptr, NULL); - png_read_push_finish_row(png_ptr); - } - } - } - else -#endif - { - png_push_have_row(png_ptr, png_ptr->row_buf + 1); - png_read_push_finish_row(png_ptr); - } -} - -void /* PRIVATE */ -png_read_push_finish_row(png_structp png_ptr) -{ -#ifdef PNG_READ_INTERLACING_SUPPORTED - /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ - - /* Start of interlace block */ - static PNG_CONST png_byte FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; - - /* Offset to next interlace block */ - static PNG_CONST png_byte FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; - - /* Start of interlace block in the y direction */ - static PNG_CONST png_byte FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; - - /* Offset to next interlace block in the y direction */ - static PNG_CONST png_byte FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; - - /* Height of interlace block. This is not currently used - if you need - * it, uncomment it here and in png.h - static PNG_CONST png_byte FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; - */ -#endif - - png_ptr->row_number++; - if (png_ptr->row_number < png_ptr->num_rows) - return; - -#ifdef PNG_READ_INTERLACING_SUPPORTED - if (png_ptr->interlaced) - { - png_ptr->row_number = 0; - png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); - - do - { - png_ptr->pass++; - if ((png_ptr->pass == 1 && png_ptr->width < 5) || - (png_ptr->pass == 3 && png_ptr->width < 3) || - (png_ptr->pass == 5 && png_ptr->width < 2)) - png_ptr->pass++; - - if (png_ptr->pass > 7) - png_ptr->pass--; - - if (png_ptr->pass >= 7) - break; - - png_ptr->iwidth = (png_ptr->width + - png_pass_inc[png_ptr->pass] - 1 - - png_pass_start[png_ptr->pass]) / - png_pass_inc[png_ptr->pass]; - - if (png_ptr->transformations & PNG_INTERLACE) - break; - - png_ptr->num_rows = (png_ptr->height + - png_pass_yinc[png_ptr->pass] - 1 - - png_pass_ystart[png_ptr->pass]) / - png_pass_yinc[png_ptr->pass]; - - } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0); - } -#endif /* PNG_READ_INTERLACING_SUPPORTED */ -} - -void /* PRIVATE */ -png_push_have_info(png_structp png_ptr, png_infop info_ptr) -{ - if (png_ptr->info_fn != NULL) - (*(png_ptr->info_fn))(png_ptr, info_ptr); -} - -void /* PRIVATE */ -png_push_have_end(png_structp png_ptr, png_infop info_ptr) -{ - if (png_ptr->end_fn != NULL) - (*(png_ptr->end_fn))(png_ptr, info_ptr); -} - -void /* PRIVATE */ -png_push_have_row(png_structp png_ptr, png_bytep row) -{ - if (png_ptr->row_fn != NULL) - (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number, - (int)png_ptr->pass); -} - -#ifdef PNG_READ_INTERLACING_SUPPORTED -void PNGAPI -png_progressive_combine_row (png_structp png_ptr, png_bytep old_row, - png_const_bytep new_row) -{ - if (png_ptr == NULL) - return; - - /* new_row is a flag here - if it is NULL then the app callback was called - * from an empty row (see the calls to png_struct::row_fn below), otherwise - * it must be png_ptr->row_buf+1 - */ - if (new_row != NULL) - png_combine_row(png_ptr, old_row, 1/*display*/); -} -#endif /* PNG_READ_INTERLACING_SUPPORTED */ - -void PNGAPI -png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr, - png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, - png_progressive_end_ptr end_fn) -{ - if (png_ptr == NULL) - return; - - png_ptr->info_fn = info_fn; - png_ptr->row_fn = row_fn; - png_ptr->end_fn = end_fn; - - png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer); -} - -png_voidp PNGAPI -png_get_progressive_ptr(png_const_structp png_ptr) -{ - if (png_ptr == NULL) - return (NULL); - - return png_ptr->io_ptr; -} -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ + +/* pngpread.c - read a png file in push mode + * + * Last changed in libpng 1.5.11 [June 14, 2012] + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "pngpriv.h" + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED + +/* Push model modes */ +#define PNG_READ_SIG_MODE 0 +#define PNG_READ_CHUNK_MODE 1 +#define PNG_READ_IDAT_MODE 2 +#define PNG_SKIP_MODE 3 +#define PNG_READ_tEXt_MODE 4 +#define PNG_READ_zTXt_MODE 5 +#define PNG_READ_DONE_MODE 6 +#define PNG_READ_iTXt_MODE 7 +#define PNG_ERROR_MODE 8 + +void PNGAPI +png_process_data(png_structp png_ptr, png_infop info_ptr, + png_bytep buffer, png_size_t buffer_size) +{ + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_push_restore_buffer(png_ptr, buffer, buffer_size); + + while (png_ptr->buffer_size) + { + png_process_some_data(png_ptr, info_ptr); + } +} + +png_size_t PNGAPI +png_process_data_pause(png_structp png_ptr, int save) +{ + if (png_ptr != NULL) + { + /* It's easiest for the caller if we do the save, then the caller doesn't + * have to supply the same data again: + */ + if (save) + png_push_save_buffer(png_ptr); + else + { + /* This includes any pending saved bytes: */ + png_size_t remaining = png_ptr->buffer_size; + png_ptr->buffer_size = 0; + + /* So subtract the saved buffer size, unless all the data + * is actually 'saved', in which case we just return 0 + */ + if (png_ptr->save_buffer_size < remaining) + return remaining - png_ptr->save_buffer_size; + } + } + + return 0; +} + +png_uint_32 PNGAPI +png_process_data_skip(png_structp png_ptr) +{ + png_uint_32 remaining = 0; + + if (png_ptr != NULL && png_ptr->process_mode == PNG_SKIP_MODE && + png_ptr->skip_length > 0) + { + /* At the end of png_process_data the buffer size must be 0 (see the loop + * above) so we can detect a broken call here: + */ + if (png_ptr->buffer_size != 0) + png_error(png_ptr, + "png_process_data_skip called inside png_process_data"); + + /* If is impossible for there to be a saved buffer at this point - + * otherwise we could not be in SKIP mode. This will also happen if + * png_process_skip is called inside png_process_data (but only very + * rarely.) + */ + if (png_ptr->save_buffer_size != 0) + png_error(png_ptr, "png_process_data_skip called with saved data"); + + remaining = png_ptr->skip_length; + png_ptr->skip_length = 0; + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + } + + return remaining; +} + +/* What we do with the incoming data depends on what we were previously + * doing before we ran out of data... + */ +void /* PRIVATE */ +png_process_some_data(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr == NULL) + return; + + switch (png_ptr->process_mode) + { + case PNG_READ_SIG_MODE: + { + png_push_read_sig(png_ptr, info_ptr); + break; + } + + case PNG_READ_CHUNK_MODE: + { + png_push_read_chunk(png_ptr, info_ptr); + break; + } + + case PNG_READ_IDAT_MODE: + { + png_push_read_IDAT(png_ptr); + break; + } + + case PNG_SKIP_MODE: + { + png_push_crc_finish(png_ptr); + break; + } + + default: + { + png_ptr->buffer_size = 0; + break; + } + } +} + +/* Read any remaining signature bytes from the stream and compare them with + * the correct PNG signature. It is possible that this routine is called + * with bytes already read from the signature, either because they have been + * checked by the calling application, or because of multiple calls to this + * routine. + */ +void /* PRIVATE */ +png_push_read_sig(png_structp png_ptr, png_infop info_ptr) +{ + png_size_t num_checked = png_ptr->sig_bytes, + num_to_check = 8 - num_checked; + + if (png_ptr->buffer_size < num_to_check) + { + num_to_check = png_ptr->buffer_size; + } + + png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]), + num_to_check); + png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check); + + if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) + { + if (num_checked < 4 && + png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) + png_error(png_ptr, "Not a PNG file"); + + else + png_error(png_ptr, "PNG file corrupted by ASCII conversion"); + } + + else + { + if (png_ptr->sig_bytes >= 8) + { + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + } + } +} + +void /* PRIVATE */ +png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) +{ + png_uint_32 chunk_name; + + /* First we make sure we have enough data for the 4 byte chunk name + * and the 4 byte chunk length before proceeding with decoding the + * chunk data. To fully decode each of these chunks, we also make + * sure we have enough data in the buffer for the 4 byte CRC at the + * end of every chunk (except IDAT, which is handled separately). + */ + if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) + { + png_byte chunk_length[4]; + png_byte chunk_tag[4]; + + if (png_ptr->buffer_size < 8) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_fill_buffer(png_ptr, chunk_length, 4); + png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); + png_reset_crc(png_ptr); + png_crc_read(png_ptr, chunk_tag, 4); + png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); + png_check_chunk_name(png_ptr, png_ptr->chunk_name); + png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; + } + + chunk_name = png_ptr->chunk_name; + + if (chunk_name == png_IDAT) + { + /* This is here above the if/else case statement below because if the + * unknown handling marks 'IDAT' as unknown then the IDAT handling case is + * completely skipped. + * + * TODO: there must be a better way of doing this. + */ + if (png_ptr->mode & PNG_AFTER_IDAT) + png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; + } + + if (chunk_name == png_IHDR) + { + if (png_ptr->push_length != 13) + png_error(png_ptr, "Invalid IHDR length"); + + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length); + } + + else if (chunk_name == png_IEND) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length); + + png_ptr->process_mode = PNG_READ_DONE_MODE; + png_push_have_end(png_ptr, info_ptr); + } + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + else if (png_chunk_unknown_handling(png_ptr, chunk_name)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + if (chunk_name == png_IDAT) + png_ptr->mode |= PNG_HAVE_IDAT; + + png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); + + if (chunk_name == png_PLTE) + png_ptr->mode |= PNG_HAVE_PLTE; + + else if (chunk_name == png_IDAT) + { + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before IDAT"); + + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + png_error(png_ptr, "Missing PLTE before IDAT"); + } + } +#endif + + else if (chunk_name == png_PLTE) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length); + } + + else if (chunk_name == png_IDAT) + { + /* If we reach an IDAT chunk, this means we have read all of the + * header chunks, and we can start reading the image (or if this + * is called after the image has been read - we have an error). + */ + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before IDAT"); + + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + png_error(png_ptr, "Missing PLTE before IDAT"); + + if (png_ptr->mode & PNG_HAVE_IDAT) + { + if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) + if (png_ptr->push_length == 0) + return; + + if (png_ptr->mode & PNG_AFTER_IDAT) + png_benign_error(png_ptr, "Too many IDATs found"); + } + + png_ptr->idat_size = png_ptr->push_length; + png_ptr->mode |= PNG_HAVE_IDAT; + png_ptr->process_mode = PNG_READ_IDAT_MODE; + png_push_have_info(png_ptr, info_ptr); + png_ptr->zstream.avail_out = + (uInt) PNG_ROWBYTES(png_ptr->pixel_depth, + png_ptr->iwidth) + 1; + png_ptr->zstream.next_out = png_ptr->row_buf; + return; + } + +#ifdef PNG_READ_gAMA_SUPPORTED + else if (png_ptr->chunk_name == png_gAMA) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_sBIT_SUPPORTED + else if (png_ptr->chunk_name == png_sBIT) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_cHRM_SUPPORTED + else if (png_ptr->chunk_name == png_cHRM) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_sRGB_SUPPORTED + else if (chunk_name == png_sRGB) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_iCCP_SUPPORTED + else if (png_ptr->chunk_name == png_iCCP) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_sPLT_SUPPORTED + else if (chunk_name == png_sPLT) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_tRNS_SUPPORTED + else if (chunk_name == png_tRNS) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_bKGD_SUPPORTED + else if (chunk_name == png_bKGD) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_hIST_SUPPORTED + else if (chunk_name == png_hIST) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_pHYs_SUPPORTED + else if (chunk_name == png_pHYs) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_oFFs_SUPPORTED + else if (chunk_name == png_oFFs) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length); + } +#endif + +#ifdef PNG_READ_pCAL_SUPPORTED + else if (chunk_name == png_pCAL) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_sCAL_SUPPORTED + else if (chunk_name == png_sCAL) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_tIME_SUPPORTED + else if (chunk_name == png_tIME) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_tEXt_SUPPORTED + else if (chunk_name == png_tEXt) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_zTXt_SUPPORTED + else if (chunk_name == png_zTXt) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_iTXt_SUPPORTED + else if (chunk_name == png_iTXt) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif + + else + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); + } + + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; +} + +void /* PRIVATE */ +png_push_crc_skip(png_structp png_ptr, png_uint_32 skip) +{ + png_ptr->process_mode = PNG_SKIP_MODE; + png_ptr->skip_length = skip; +} + +void /* PRIVATE */ +png_push_crc_finish(png_structp png_ptr) +{ + if (png_ptr->skip_length && png_ptr->save_buffer_size) + { + png_size_t save_size = png_ptr->save_buffer_size; + png_uint_32 skip_length = png_ptr->skip_length; + + /* We want the smaller of 'skip_length' and 'save_buffer_size', but + * they are of different types and we don't know which variable has the + * fewest bits. Carefully select the smaller and cast it to the type of + * the larger - this cannot overflow. Do not cast in the following test + * - it will break on either 16 or 64 bit platforms. + */ + if (skip_length < save_size) + save_size = (png_size_t)skip_length; + + else + skip_length = (png_uint_32)save_size; + + png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); + + png_ptr->skip_length -= skip_length; + png_ptr->buffer_size -= save_size; + png_ptr->save_buffer_size -= save_size; + png_ptr->save_buffer_ptr += save_size; + } + + if (png_ptr->skip_length && png_ptr->current_buffer_size) + { + png_size_t save_size = png_ptr->current_buffer_size; + png_uint_32 skip_length = png_ptr->skip_length; + + /* We want the smaller of 'skip_length' and 'current_buffer_size', here, + * the same problem exists as above and the same solution. + */ + if (skip_length < save_size) + save_size = (png_size_t)skip_length; + + else + skip_length = (png_uint_32)save_size; + + png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); + + png_ptr->skip_length -= skip_length; + png_ptr->buffer_size -= save_size; + png_ptr->current_buffer_size -= save_size; + png_ptr->current_buffer_ptr += save_size; + } + + if (!png_ptr->skip_length) + { + if (png_ptr->buffer_size < 4) + { + png_push_save_buffer(png_ptr); + return; + } + + png_crc_finish(png_ptr, 0); + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + } +} + +void PNGCBAPI +png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) +{ + png_bytep ptr; + + if (png_ptr == NULL) + return; + + ptr = buffer; + + if (png_ptr->save_buffer_size) + { + png_size_t save_size; + + if (length < png_ptr->save_buffer_size) + save_size = length; + + else + save_size = png_ptr->save_buffer_size; + + png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size); + length -= save_size; + ptr += save_size; + png_ptr->buffer_size -= save_size; + png_ptr->save_buffer_size -= save_size; + png_ptr->save_buffer_ptr += save_size; + } + + if (length && png_ptr->current_buffer_size) + { + png_size_t save_size; + + if (length < png_ptr->current_buffer_size) + save_size = length; + + else + save_size = png_ptr->current_buffer_size; + + png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size); + png_ptr->buffer_size -= save_size; + png_ptr->current_buffer_size -= save_size; + png_ptr->current_buffer_ptr += save_size; + } +} + +void /* PRIVATE */ +png_push_save_buffer(png_structp png_ptr) +{ + if (png_ptr->save_buffer_size) + { + if (png_ptr->save_buffer_ptr != png_ptr->save_buffer) + { + png_size_t i, istop; + png_bytep sp; + png_bytep dp; + + istop = png_ptr->save_buffer_size; + + for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer; + i < istop; i++, sp++, dp++) + { + *dp = *sp; + } + } + } + + if (png_ptr->save_buffer_size + png_ptr->current_buffer_size > + png_ptr->save_buffer_max) + { + png_size_t new_max; + png_bytep old_buffer; + + if (png_ptr->save_buffer_size > PNG_SIZE_MAX - + (png_ptr->current_buffer_size + 256)) + { + png_error(png_ptr, "Potential overflow of save_buffer"); + } + + new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256; + old_buffer = png_ptr->save_buffer; + png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr, new_max); + + if (png_ptr->save_buffer == NULL) + { + png_free(png_ptr, old_buffer); + png_error(png_ptr, "Insufficient memory for save_buffer"); + } + + png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); + png_free(png_ptr, old_buffer); + png_ptr->save_buffer_max = new_max; + } + + if (png_ptr->current_buffer_size) + { + png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size, + png_ptr->current_buffer_ptr, png_ptr->current_buffer_size); + png_ptr->save_buffer_size += png_ptr->current_buffer_size; + png_ptr->current_buffer_size = 0; + } + + png_ptr->save_buffer_ptr = png_ptr->save_buffer; + png_ptr->buffer_size = 0; +} + +void /* PRIVATE */ +png_push_restore_buffer(png_structp png_ptr, png_bytep buffer, + png_size_t buffer_length) +{ + png_ptr->current_buffer = buffer; + png_ptr->current_buffer_size = buffer_length; + png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size; + png_ptr->current_buffer_ptr = png_ptr->current_buffer; +} + +void /* PRIVATE */ +png_push_read_IDAT(png_structp png_ptr) +{ + if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) + { + png_byte chunk_length[4]; + png_byte chunk_tag[4]; + + /* TODO: this code can be commoned up with the same code in push_read */ + if (png_ptr->buffer_size < 8) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_fill_buffer(png_ptr, chunk_length, 4); + png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); + png_reset_crc(png_ptr); + png_crc_read(png_ptr, chunk_tag, 4); + png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); + png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; + + if (png_ptr->chunk_name != png_IDAT) + { + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + + if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) + png_error(png_ptr, "Not enough compressed data"); + + return; + } + + png_ptr->idat_size = png_ptr->push_length; + } + + if (png_ptr->idat_size && png_ptr->save_buffer_size) + { + png_size_t save_size = png_ptr->save_buffer_size; + png_uint_32 idat_size = png_ptr->idat_size; + + /* We want the smaller of 'idat_size' and 'current_buffer_size', but they + * are of different types and we don't know which variable has the fewest + * bits. Carefully select the smaller and cast it to the type of the + * larger - this cannot overflow. Do not cast in the following test - it + * will break on either 16 or 64 bit platforms. + */ + if (idat_size < save_size) + save_size = (png_size_t)idat_size; + + else + idat_size = (png_uint_32)save_size; + + png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); + + png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size); + + png_ptr->idat_size -= idat_size; + png_ptr->buffer_size -= save_size; + png_ptr->save_buffer_size -= save_size; + png_ptr->save_buffer_ptr += save_size; + } + + if (png_ptr->idat_size && png_ptr->current_buffer_size) + { + png_size_t save_size = png_ptr->current_buffer_size; + png_uint_32 idat_size = png_ptr->idat_size; + + /* We want the smaller of 'idat_size' and 'current_buffer_size', but they + * are of different types and we don't know which variable has the fewest + * bits. Carefully select the smaller and cast it to the type of the + * larger - this cannot overflow. + */ + if (idat_size < save_size) + save_size = (png_size_t)idat_size; + + else + idat_size = (png_uint_32)save_size; + + png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); + + png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size); + + png_ptr->idat_size -= idat_size; + png_ptr->buffer_size -= save_size; + png_ptr->current_buffer_size -= save_size; + png_ptr->current_buffer_ptr += save_size; + } + + if (!png_ptr->idat_size) + { + if (png_ptr->buffer_size < 4) + { + png_push_save_buffer(png_ptr); + return; + } + + png_crc_finish(png_ptr, 0); + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; + png_ptr->mode |= PNG_AFTER_IDAT; + } +} + +void /* PRIVATE */ +png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, + png_size_t buffer_length) +{ + /* The caller checks for a non-zero buffer length. */ + if (!(buffer_length > 0) || buffer == NULL) + png_error(png_ptr, "No IDAT data (internal error)"); + + /* This routine must process all the data it has been given + * before returning, calling the row callback as required to + * handle the uncompressed results. + */ + png_ptr->zstream.next_in = buffer; + png_ptr->zstream.avail_in = (uInt)buffer_length; + + /* Keep going until the decompressed data is all processed + * or the stream marked as finished. + */ + while (png_ptr->zstream.avail_in > 0 && + !(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) + { + int ret; + + /* We have data for zlib, but we must check that zlib + * has someplace to put the results. It doesn't matter + * if we don't expect any results -- it may be the input + * data is just the LZ end code. + */ + if (!(png_ptr->zstream.avail_out > 0)) + { + png_ptr->zstream.avail_out = + (uInt) PNG_ROWBYTES(png_ptr->pixel_depth, + png_ptr->iwidth) + 1; + + png_ptr->zstream.next_out = png_ptr->row_buf; + } + + /* Using Z_SYNC_FLUSH here means that an unterminated + * LZ stream (a stream with a missing end code) can still + * be handled, otherwise (Z_NO_FLUSH) a future zlib + * implementation might defer output and therefore + * change the current behavior (see comments in inflate.c + * for why this doesn't happen at present with zlib 1.2.5). + */ + ret = inflate(&png_ptr->zstream, Z_SYNC_FLUSH); + + /* Check for any failure before proceeding. */ + if (ret != Z_OK && ret != Z_STREAM_END) + { + /* Terminate the decompression. */ + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + + /* This may be a truncated stream (missing or + * damaged end code). Treat that as a warning. + */ + if (png_ptr->row_number >= png_ptr->num_rows || + png_ptr->pass > 6) + png_warning(png_ptr, "Truncated compressed data in IDAT"); + + else + png_error(png_ptr, "Decompression error in IDAT"); + + /* Skip the check on unprocessed input */ + return; + } + + /* Did inflate output any data? */ + if (png_ptr->zstream.next_out != png_ptr->row_buf) + { + /* Is this unexpected data after the last row? + * If it is, artificially terminate the LZ output + * here. + */ + if (png_ptr->row_number >= png_ptr->num_rows || + png_ptr->pass > 6) + { + /* Extra data. */ + png_warning(png_ptr, "Extra compressed data in IDAT"); + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + + /* Do no more processing; skip the unprocessed + * input check below. + */ + return; + } + + /* Do we have a complete row? */ + if (png_ptr->zstream.avail_out == 0) + png_push_process_row(png_ptr); + } + + /* And check for the end of the stream. */ + if (ret == Z_STREAM_END) + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + } + + /* All the data should have been processed, if anything + * is left at this point we have bytes of IDAT data + * after the zlib end code. + */ + if (png_ptr->zstream.avail_in > 0) + png_warning(png_ptr, "Extra compression data in IDAT"); +} + +void /* PRIVATE */ +png_push_process_row(png_structp png_ptr) +{ + /* 1.5.6: row_info moved out of png_struct to a local here. */ + png_row_info row_info; + + row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */ + row_info.color_type = png_ptr->color_type; + row_info.bit_depth = png_ptr->bit_depth; + row_info.channels = png_ptr->channels; + row_info.pixel_depth = png_ptr->pixel_depth; + row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); + + if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) + { + if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) + png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1, + png_ptr->prev_row + 1, png_ptr->row_buf[0]); + else + png_error(png_ptr, "bad adaptive filter value"); + } + + /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before + * 1.5.6, while the buffer really is this big in current versions of libpng + * it may not be in the future, so this was changed just to copy the + * interlaced row count: + */ + png_memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1); + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED + if (png_ptr->transformations) + png_do_read_transformations(png_ptr, &row_info); +#endif + + /* The transformed pixel depth should match the depth now in row_info. */ + if (png_ptr->transformed_pixel_depth == 0) + { + png_ptr->transformed_pixel_depth = row_info.pixel_depth; + if (row_info.pixel_depth > png_ptr->maximum_pixel_depth) + png_error(png_ptr, "progressive row overflow"); + } + + else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth) + png_error(png_ptr, "internal progressive row size calculation error"); + + +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* Blow up interlaced rows to full size */ + if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) + { + if (png_ptr->pass < 6) + png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass, + png_ptr->transformations); + + switch (png_ptr->pass) + { + case 0: + { + int i; + for (i = 0; i < 8 && png_ptr->pass == 0; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); /* Updates png_ptr->pass */ + } + + if (png_ptr->pass == 2) /* Pass 1 might be empty */ + { + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } + + if (png_ptr->pass == 4 && png_ptr->height <= 4) + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } + + if (png_ptr->pass == 6 && png_ptr->height <= 4) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + + break; + } + + case 1: + { + int i; + for (i = 0; i < 8 && png_ptr->pass == 1; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 2) /* Skip top 4 generated rows */ + { + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } + + break; + } + + case 2: + { + int i; + + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 4) /* Pass 3 might be empty */ + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } + + break; + } + + case 3: + { + int i; + + for (i = 0; i < 4 && png_ptr->pass == 3; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 4) /* Skip top two generated rows */ + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } + + break; + } + + case 4: + { + int i; + + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 6) /* Pass 5 might be empty */ + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + + break; + } + + case 5: + { + int i; + + for (i = 0; i < 2 && png_ptr->pass == 5; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 6) /* Skip top generated row */ + { + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + + break; + } + + default: + case 6: + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + + if (png_ptr->pass != 6) + break; + + png_push_have_row(png_ptr, NULL); + png_read_push_finish_row(png_ptr); + } + } + } + else +#endif + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } +} + +void /* PRIVATE */ +png_read_push_finish_row(png_structp png_ptr) +{ +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + static PNG_CONST png_byte FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + static PNG_CONST png_byte FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + static PNG_CONST png_byte FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + static PNG_CONST png_byte FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; + + /* Height of interlace block. This is not currently used - if you need + * it, uncomment it here and in png.h + static PNG_CONST png_byte FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; + */ +#endif + + png_ptr->row_number++; + if (png_ptr->row_number < png_ptr->num_rows) + return; + +#ifdef PNG_READ_INTERLACING_SUPPORTED + if (png_ptr->interlaced) + { + png_ptr->row_number = 0; + png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); + + do + { + png_ptr->pass++; + if ((png_ptr->pass == 1 && png_ptr->width < 5) || + (png_ptr->pass == 3 && png_ptr->width < 3) || + (png_ptr->pass == 5 && png_ptr->width < 2)) + png_ptr->pass++; + + if (png_ptr->pass > 7) + png_ptr->pass--; + + if (png_ptr->pass >= 7) + break; + + png_ptr->iwidth = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + + if (png_ptr->transformations & PNG_INTERLACE) + break; + + png_ptr->num_rows = (png_ptr->height + + png_pass_yinc[png_ptr->pass] - 1 - + png_pass_ystart[png_ptr->pass]) / + png_pass_yinc[png_ptr->pass]; + + } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0); + } +#endif /* PNG_READ_INTERLACING_SUPPORTED */ +} + +void /* PRIVATE */ +png_push_have_info(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr->info_fn != NULL) + (*(png_ptr->info_fn))(png_ptr, info_ptr); +} + +void /* PRIVATE */ +png_push_have_end(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr->end_fn != NULL) + (*(png_ptr->end_fn))(png_ptr, info_ptr); +} + +void /* PRIVATE */ +png_push_have_row(png_structp png_ptr, png_bytep row) +{ + if (png_ptr->row_fn != NULL) + (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number, + (int)png_ptr->pass); +} + +#ifdef PNG_READ_INTERLACING_SUPPORTED +void PNGAPI +png_progressive_combine_row (png_structp png_ptr, png_bytep old_row, + png_const_bytep new_row) +{ + if (png_ptr == NULL) + return; + + /* new_row is a flag here - if it is NULL then the app callback was called + * from an empty row (see the calls to png_struct::row_fn below), otherwise + * it must be png_ptr->row_buf+1 + */ + if (new_row != NULL) + png_combine_row(png_ptr, old_row, 1/*display*/); +} +#endif /* PNG_READ_INTERLACING_SUPPORTED */ + +void PNGAPI +png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr, + png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, + png_progressive_end_ptr end_fn) +{ + if (png_ptr == NULL) + return; + + png_ptr->info_fn = info_fn; + png_ptr->row_fn = row_fn; + png_ptr->end_fn = end_fn; + + png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer); +} + +png_voidp PNGAPI +png_get_progressive_ptr(png_const_structp png_ptr) +{ + if (png_ptr == NULL) + return (NULL); + + return png_ptr->io_ptr; +} +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ diff --git a/Source/LibPNG/pngpriv.h b/Source/LibPNG/pngpriv.h index 3863f1f..dd35e52 100644 --- a/Source/LibPNG/pngpriv.h +++ b/Source/LibPNG/pngpriv.h @@ -1,1675 +1,1675 @@ - -/* pngpriv.h - private declarations for use inside libpng - * - * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2012 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * Last changed in libpng 1.5.10 [March 29, 2012] - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - */ - -/* The symbols declared in this file (including the functions declared - * as PNG_EXTERN) are PRIVATE. They are not part of the libpng public - * interface, and are not recommended for use by regular applications. - * Some of them may become public in the future; others may stay private, - * change in an incompatible way, or even disappear. - * Although the libpng users are not forbidden to include this header, - * they should be well aware of the issues that may arise from doing so. - */ - -#ifndef PNGPRIV_H -#define PNGPRIV_H - -/* Feature Test Macros. The following are defined here to ensure that correctly - * implemented libraries reveal the APIs libpng needs to build and hide those - * that are not needed and potentially damaging to the compilation. - * - * Feature Test Macros must be defined before any system header is included (see - * POSIX 1003.1 2.8.2 "POSIX Symbols." - * - * These macros only have an effect if the operating system supports either - * POSIX 1003.1 or C99, or both. On other operating systems (particularly - * Windows/Visual Studio) there is no effect; the OS specific tests below are - * still required (as of 2011-05-02.) - */ -#define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */ - -/* This is required for the definition of abort(), used as a last ditch - * error handler when all else fails. - */ -#include - -/* This is used to find 'offsetof', used below for alignment tests. */ -#include - -#define PNGLIB_BUILD /*libpng is being built, not used*/ - -#ifdef PNG_USER_CONFIG -# include "pngusr.h" - /* These should have been defined in pngusr.h */ -# ifndef PNG_USER_PRIVATEBUILD -# define PNG_USER_PRIVATEBUILD "Custom libpng build" -# endif -# ifndef PNG_USER_DLLFNAME_POSTFIX -# define PNG_USER_DLLFNAME_POSTFIX "Cb" -# endif -#endif - -/* Is this a build of a DLL where compilation of the object modules requires - * different preprocessor settings to those required for a simple library? If - * so PNG_BUILD_DLL must be set. - * - * If libpng is used inside a DLL but that DLL does not export the libpng APIs - * PNG_BUILD_DLL must not be set. To avoid the code below kicking in build a - * static library of libpng then link the DLL against that. - */ -#ifndef PNG_BUILD_DLL -# ifdef DLL_EXPORT - /* This is set by libtool when files are compiled for a DLL; libtool - * always compiles twice, even on systems where it isn't necessary. Set - * PNG_BUILD_DLL in case it is necessary: - */ -# define PNG_BUILD_DLL -# else -# ifdef _WINDLL - /* This is set by the Microsoft Visual Studio IDE in projects that - * build a DLL. It can't easily be removed from those projects (it - * isn't visible in the Visual Studio UI) so it is a fairly reliable - * indication that PNG_IMPEXP needs to be set to the DLL export - * attributes. - */ -# define PNG_BUILD_DLL -# else -# ifdef __DLL__ - /* This is set by the Borland C system when compiling for a DLL - * (as above.) - */ -# define PNG_BUILD_DLL -# else - /* Add additional compiler cases here. */ -# endif -# endif -# endif -#endif /* Setting PNG_BUILD_DLL if required */ - -/* See pngconf.h for more details: the builder of the library may set this on - * the command line to the right thing for the specific compilation system or it - * may be automagically set above (at present we know of no system where it does - * need to be set on the command line.) - * - * PNG_IMPEXP must be set here when building the library to prevent pngconf.h - * setting it to the "import" setting for a DLL build. - */ -#ifndef PNG_IMPEXP -# ifdef PNG_BUILD_DLL -# define PNG_IMPEXP PNG_DLL_EXPORT -# else - /* Not building a DLL, or the DLL doesn't require specific export - * definitions. - */ -# define PNG_IMPEXP -# endif -#endif - -/* No warnings for private or deprecated functions in the build: */ -#ifndef PNG_DEPRECATED -# define PNG_DEPRECATED -#endif -#ifndef PNG_PRIVATE -# define PNG_PRIVATE -#endif - -#include "png.h" -#include "pnginfo.h" -#include "pngstruct.h" - -/* pngconf.h does not set PNG_DLL_EXPORT unless it is required, so: */ -#ifndef PNG_DLL_EXPORT -# define PNG_DLL_EXPORT -#endif - -/* SECURITY and SAFETY: - * - * By default libpng is built without any internal limits on image size, - * individual heap (png_malloc) allocations or the total amount of memory used. - * If PNG_SAFE_LIMITS_SUPPORTED is defined, however, the limits below are used - * (unless individually overridden). These limits are believed to be fairly - * safe, but builders of secure systems should verify the values against the - * real system capabilities. - */ - -#ifdef PNG_SAFE_LIMITS_SUPPORTED - /* 'safe' limits */ -# ifndef PNG_USER_WIDTH_MAX -# define PNG_USER_WIDTH_MAX 1000000 -# endif -# ifndef PNG_USER_HEIGHT_MAX -# define PNG_USER_HEIGHT_MAX 1000000 -# endif -# ifndef PNG_USER_CHUNK_CACHE_MAX -# define PNG_USER_CHUNK_CACHE_MAX 128 -# endif -# ifndef PNG_USER_CHUNK_MALLOC_MAX -# define PNG_USER_CHUNK_MALLOC_MAX 8000000 -# endif -#else - /* values for no limits */ -# ifndef PNG_USER_WIDTH_MAX -# define PNG_USER_WIDTH_MAX 0x7fffffff -# endif -# ifndef PNG_USER_HEIGHT_MAX -# define PNG_USER_HEIGHT_MAX 0x7fffffff -# endif -# ifndef PNG_USER_CHUNK_CACHE_MAX -# define PNG_USER_CHUNK_CACHE_MAX 0 -# endif -# ifndef PNG_USER_CHUNK_MALLOC_MAX -# define PNG_USER_CHUNK_MALLOC_MAX 0 -# endif -#endif - -/* This is used for 16 bit gamma tables - only the top level pointers are const, - * this could be changed: - */ -typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; - -/* Added at libpng-1.2.9 */ -/* Moved to pngpriv.h at libpng-1.5.0 */ - -/* config.h is created by and PNG_CONFIGURE_LIBPNG is set by the "configure" - * script. We may need it here to get the correct configuration on things - * like limits. - */ -#ifdef PNG_CONFIGURE_LIBPNG -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif -#endif - -/* Moved to pngpriv.h at libpng-1.5.0 */ -/* NOTE: some of these may have been used in external applications as - * these definitions were exposed in pngconf.h prior to 1.5. - */ - -/* If you are running on a machine where you cannot allocate more - * than 64K of memory at once, uncomment this. While libpng will not - * normally need that much memory in a chunk (unless you load up a very - * large file), zlib needs to know how big of a chunk it can use, and - * libpng thus makes sure to check any memory allocation to verify it - * will fit into memory. - * - * zlib provides 'MAXSEG_64K' which, if defined, indicates the - * same limit and pngconf.h (already included) sets the limit - * if certain operating systems are detected. - */ -#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) -# define PNG_MAX_MALLOC_64K -#endif - -#ifndef PNG_UNUSED -/* Unused formal parameter warnings are silenced using the following macro - * which is expected to have no bad effects on performance (optimizing - * compilers will probably remove it entirely). Note that if you replace - * it with something other than whitespace, you must include the terminating - * semicolon. - */ -# define PNG_UNUSED(param) (void)param; -#endif - -/* Just a little check that someone hasn't tried to define something - * contradictory. - */ -#if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K) -# undef PNG_ZBUF_SIZE -# define PNG_ZBUF_SIZE 65536L -#endif - -/* PNG_STATIC is used to mark internal file scope functions if they need to be - * accessed for implementation tests (see the code in tests/?*). - */ -#ifndef PNG_STATIC -# define PNG_STATIC static -#endif - -/* C99 restrict is used where possible, to do this 'restrict' is defined as - * empty if we can't be sure it is supported. configure builds have already - * done this work. - */ -#ifdef PNG_CONFIGURE_LIBPNG -# define PNG_RESTRICT restrict -#else - /* Modern compilers support restrict, but assume not for anything not - * recognized here: - */ -# if defined __GNUC__ || defined _MSC_VER || defined __WATCOMC__ -# define PNG_RESTRICT restrict -# else -# define PNG_RESTRICT -# endif -#endif - -/* If warnings or errors are turned off the code is disabled or redirected here. - * From 1.5.4 functions have been added to allow very limited formatting of - * error and warning messages - this code will also be disabled here. - */ -#ifdef PNG_WARNINGS_SUPPORTED -# define PNG_WARNING_PARAMETERS(p) png_warning_parameters p; -#else -# define png_warning(s1,s2) ((void)(s1)) -# define png_chunk_warning(s1,s2) ((void)(s1)) -# define png_warning_parameter(p,number,string) ((void)0) -# define png_warning_parameter_unsigned(p,number,format,value) ((void)0) -# define png_warning_parameter_signed(p,number,format,value) ((void)0) -# define png_formatted_warning(pp,p,message) ((void)(pp)) -# define PNG_WARNING_PARAMETERS(p) -#endif -#ifndef PNG_ERROR_TEXT_SUPPORTED -# define png_error(s1,s2) png_err(s1) -# define png_chunk_error(s1,s2) png_err(s1) -# define png_fixed_error(s1,s2) png_err(s1) -#endif - -/* C allows up-casts from (void*) to any pointer and (const void*) to any - * pointer to a const object. C++ regards this as a type error and requires an - * explicit, static, cast and provides the static_cast<> rune to ensure that - * const is not cast away. - */ -#ifdef __cplusplus -# define png_voidcast(type, value) static_cast(value) -#else -# define png_voidcast(type, value) (value) -#endif /* __cplusplus */ - -#ifndef PNG_EXTERN -/* The functions exported by PNG_EXTERN are internal functions, which - * aren't usually used outside the library (as far as I know), so it is - * debatable if they should be exported at all. In the future, when it - * is possible to have run-time registry of chunk-handling functions, - * some of these might be made available again. - * - * 1.5.7: turned the use of 'extern' back on, since it is localized to pngpriv.h - * it should be safe now (it is unclear why it was turned off.) - */ -# define PNG_EXTERN extern -#endif - -/* Some fixed point APIs are still required even if not exported because - * they get used by the corresponding floating point APIs. This magic - * deals with this: - */ -#ifdef PNG_FIXED_POINT_SUPPORTED -# define PNGFAPI PNGAPI -#else -# define PNGFAPI /* PRIVATE */ -#endif - -/* Other defines specific to compilers can go here. Try to keep - * them inside an appropriate ifdef/endif pair for portability. - */ -#if defined(PNG_FLOATING_POINT_SUPPORTED) ||\ - defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) - /* png.c requires the following ANSI-C constants if the conversion of - * floating point to ASCII is implemented therein: - * - * DBL_DIG Maximum number of decimal digits (can be set to any constant) - * DBL_MIN Smallest normalized fp number (can be set to an arbitrary value) - * DBL_MAX Maximum floating point number (can be set to an arbitrary value) - */ -# include - -# if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \ - defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC) - /* We need to check that hasn't already been included earlier - * as it seems it doesn't agree with , yet we should really use - * if possible. - */ -# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__) -# include -# endif -# else -# include -# endif -# if defined(_AMIGA) && defined(__SASC) && defined(_M68881) - /* Amiga SAS/C: We must include builtin FPU functions when compiling using - * MATH=68881 - */ -# include -# endif -#endif - -/* This provides the non-ANSI (far) memory allocation routines. */ -#if defined(__TURBOC__) && defined(__MSDOS__) -# include -# include -#endif - -#if defined(WIN32) || defined(_Windows) || defined(_WINDOWS) || \ - defined(_WIN32) || defined(__WIN32__) -# include /* defines _WINDOWS_ macro */ -#endif - -/* Moved here around 1.5.0beta36 from pngconf.h */ -/* Users may want to use these so they are not private. Any library - * functions that are passed far data must be model-independent. - */ - -/* Memory model/platform independent fns */ -#ifndef PNG_ABORT -# ifdef _WINDOWS_ -# define PNG_ABORT() ExitProcess(0) -# else -# define PNG_ABORT() abort() -# endif -#endif - -#ifdef USE_FAR_KEYWORD -/* Use this to make far-to-near assignments */ -# define CHECK 1 -# define NOCHECK 0 -# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK)) -# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK)) -# define png_strlen _fstrlen -# define png_memcmp _fmemcmp /* SJT: added */ -# define png_memcpy _fmemcpy -# define png_memset _fmemset -#else -# ifdef _WINDOWS_ /* Favor Windows over C runtime fns */ -# define CVT_PTR(ptr) (ptr) -# define CVT_PTR_NOCHECK(ptr) (ptr) -# define png_strlen lstrlenA -# define png_memcmp memcmp -# define png_memcpy CopyMemory -# define png_memset memset -# else -# define CVT_PTR(ptr) (ptr) -# define CVT_PTR_NOCHECK(ptr) (ptr) -# define png_strlen strlen -# define png_memcmp memcmp /* SJT: added */ -# define png_memcpy memcpy -# define png_memset memset -# endif -#endif - -/* These macros may need to be architecture dependent. */ -#define PNG_ALIGN_NONE 0 /* do not use data alignment */ -#define PNG_ALIGN_ALWAYS 1 /* assume unaligned accesses are OK */ -#ifdef offsetof -# define PNG_ALIGN_OFFSET 2 /* use offsetof to determine alignment */ -#else -# define PNG_ALIGN_OFFSET -1 /* prevent the use of this */ -#endif -#define PNG_ALIGN_SIZE 3 /* use sizeof to determine alignment */ - -#ifndef PNG_ALIGN_TYPE - /* Default to using aligned access optimizations and requiring alignment to a - * multiple of the data type size. Override in a compiler specific fashion - * if necessary by inserting tests here: - */ -# define PNG_ALIGN_TYPE PNG_ALIGN_SIZE -#endif - -#if PNG_ALIGN_TYPE == PNG_ALIGN_SIZE - /* This is used because in some compiler implementations non-aligned - * structure members are supported, so the offsetof approach below fails. - * Set PNG_ALIGN_TO_SIZE=0 for compiler combinations where unaligned access - * is good for performance. Do not do this unless you have tested the result - * and understand it. - */ -# define png_alignof(type) (sizeof (type)) -#else -# if PNG_ALIGN_TYPE == PNG_ALIGN_OFFSET -# define png_alignof(type) offsetof(struct{char c; type t;}, t) -# else -# if PNG_ALIGN_TYPE == PNG_ALIGN_ALWAYS -# define png_alignof(type) (1) -# endif - /* Else leave png_alignof undefined to prevent use thereof */ -# endif -#endif - -/* This implicitly assumes alignment is always to a power of 2. */ -#ifdef png_alignof -# define png_isaligned(ptr, type)\ - ((((const char*)ptr-(const char*)0) & (png_alignof(type)-1)) == 0) -#else -# define png_isaligned(ptr, type) 0 -#endif - -/* End of memory model/platform independent support */ -/* End of 1.5.0beta36 move from pngconf.h */ - -/* CONSTANTS and UTILITY MACROS - * These are used internally by libpng and not exposed in the API - */ - -/* Various modes of operation. Note that after an init, mode is set to - * zero automatically when the structure is created. Three of these - * are defined in png.h because they need to be visible to applications - * that call png_set_unknown_chunk(). - */ -/* #define PNG_HAVE_IHDR 0x01 (defined in png.h) */ -/* #define PNG_HAVE_PLTE 0x02 (defined in png.h) */ -#define PNG_HAVE_IDAT 0x04 -/* #define PNG_AFTER_IDAT 0x08 (defined in png.h) */ -#define PNG_HAVE_IEND 0x10 -#define PNG_HAVE_gAMA 0x20 -#define PNG_HAVE_cHRM 0x40 -#define PNG_HAVE_sRGB 0x80 -#define PNG_HAVE_CHUNK_HEADER 0x100 -#define PNG_WROTE_tIME 0x200 -#define PNG_WROTE_INFO_BEFORE_PLTE 0x400 -#define PNG_BACKGROUND_IS_GRAY 0x800 -#define PNG_HAVE_PNG_SIGNATURE 0x1000 -#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */ -#define PNG_HAVE_iCCP 0x4000 - -/* Flags for the transformations the PNG library does on the image data */ -#define PNG_BGR 0x0001 -#define PNG_INTERLACE 0x0002 -#define PNG_PACK 0x0004 -#define PNG_SHIFT 0x0008 -#define PNG_SWAP_BYTES 0x0010 -#define PNG_INVERT_MONO 0x0020 -#define PNG_QUANTIZE 0x0040 -#define PNG_COMPOSE 0x0080 /* Was PNG_BACKGROUND */ -#define PNG_BACKGROUND_EXPAND 0x0100 -#define PNG_EXPAND_16 0x0200 /* Added to libpng 1.5.2 */ -#define PNG_16_TO_8 0x0400 /* Becomes 'chop' in 1.5.4 */ -#define PNG_RGBA 0x0800 -#define PNG_EXPAND 0x1000 -#define PNG_GAMMA 0x2000 -#define PNG_GRAY_TO_RGB 0x4000 -#define PNG_FILLER 0x8000 -#define PNG_PACKSWAP 0x10000 -#define PNG_SWAP_ALPHA 0x20000 -#define PNG_STRIP_ALPHA 0x40000 -#define PNG_INVERT_ALPHA 0x80000 -#define PNG_USER_TRANSFORM 0x100000 -#define PNG_RGB_TO_GRAY_ERR 0x200000 -#define PNG_RGB_TO_GRAY_WARN 0x400000 -#define PNG_RGB_TO_GRAY 0x600000 /* two bits, RGB_TO_GRAY_ERR|WARN */ -#define PNG_ENCODE_ALPHA 0x800000 /* Added to libpng-1.5.4 */ -#define PNG_ADD_ALPHA 0x1000000 /* Added to libpng-1.2.7 */ -#define PNG_EXPAND_tRNS 0x2000000 /* Added to libpng-1.2.9 */ -#define PNG_SCALE_16_TO_8 0x4000000 /* Added to libpng-1.5.4 */ - /* 0x8000000 unused */ - /* 0x10000000 unused */ - /* 0x20000000 unused */ - /* 0x40000000 unused */ -/* Flags for png_create_struct */ -#define PNG_STRUCT_PNG 0x0001 -#define PNG_STRUCT_INFO 0x0002 - -/* Scaling factor for filter heuristic weighting calculations */ -#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT)) -#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT)) - -/* Flags for the png_ptr->flags rather than declaring a byte for each one */ -#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001 -#define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002 -#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004 -#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008 -#define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010 -#define PNG_FLAG_ZLIB_FINISHED 0x0020 -#define PNG_FLAG_ROW_INIT 0x0040 -#define PNG_FLAG_FILLER_AFTER 0x0080 -#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100 -#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200 -#define PNG_FLAG_CRC_CRITICAL_USE 0x0400 -#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800 -#define PNG_FLAG_ASSUME_sRGB 0x1000 /* Added to libpng-1.5.4 */ -#define PNG_FLAG_OPTIMIZE_ALPHA 0x2000 /* Added to libpng-1.5.4 */ -#define PNG_FLAG_DETECT_UNINITIALIZED 0x4000 /* Added to libpng-1.5.4 */ -#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000 -#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000 -#define PNG_FLAG_LIBRARY_MISMATCH 0x20000 -#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000 -#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000 -#define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000 - /* 0x200000 unused */ - /* 0x400000 unused */ -#define PNG_FLAG_BENIGN_ERRORS_WARN 0x800000 /* Added to libpng-1.4.0 */ -#define PNG_FLAG_ZTXT_CUSTOM_STRATEGY 0x1000000 /* 5 lines added */ -#define PNG_FLAG_ZTXT_CUSTOM_LEVEL 0x2000000 /* to libpng-1.5.4 */ -#define PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL 0x4000000 -#define PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS 0x8000000 -#define PNG_FLAG_ZTXT_CUSTOM_METHOD 0x10000000 - /* 0x20000000 unused */ - /* 0x40000000 unused */ - -#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ - PNG_FLAG_CRC_ANCILLARY_NOWARN) - -#define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \ - PNG_FLAG_CRC_CRITICAL_IGNORE) - -#define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \ - PNG_FLAG_CRC_CRITICAL_MASK) - -/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib - * can handle at once. This type need be no larger than 16 bits (so maximum of - * 65535), this define allows us to discover how big it is, but limited by the - * maximuum for png_size_t. The value can be overriden in a library build - * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably - * lower value (e.g. 255 works). A lower value may help memory usage (slightly) - * and may even improve performance on some systems (and degrade it on others.) - */ -#ifndef ZLIB_IO_MAX -# define ZLIB_IO_MAX ((uInt)-1) -#endif - -/* Save typing and make code easier to understand */ - -#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \ - abs((int)((c1).green) - (int)((c2).green)) + \ - abs((int)((c1).blue) - (int)((c2).blue))) - -/* Added to libpng-1.2.6 JB */ -#define PNG_ROWBYTES(pixel_bits, width) \ - ((pixel_bits) >= 8 ? \ - ((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \ - (( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) ) - -/* PNG_OUT_OF_RANGE returns true if value is outside the range - * ideal-delta..ideal+delta. Each argument is evaluated twice. - * "ideal" and "delta" should be constants, normally simple - * integers, "value" a variable. Added to libpng-1.2.6 JB - */ -#define PNG_OUT_OF_RANGE(value, ideal, delta) \ - ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) ) - -/* Conversions between fixed and floating point, only defined if - * required (to make sure the code doesn't accidentally use float - * when it is supposedly disabled.) - */ -#ifdef PNG_FLOATING_POINT_SUPPORTED -/* The floating point conversion can't overflow, though it can and - * does lose accuracy relative to the original fixed point value. - * In practice this doesn't matter because png_fixed_point only - * stores numbers with very low precision. The png_ptr and s - * arguments are unused by default but are there in case error - * checking becomes a requirement. - */ -#define png_float(png_ptr, fixed, s) (.00001 * (fixed)) - -/* The fixed point conversion performs range checking and evaluates - * its argument multiple times, so must be used with care. The - * range checking uses the PNG specification values for a signed - * 32 bit fixed point value except that the values are deliberately - * rounded-to-zero to an integral value - 21474 (21474.83 is roughly - * (2^31-1) * 100000). 's' is a string that describes the value being - * converted. - * - * NOTE: this macro will raise a png_error if the range check fails, - * therefore it is normally only appropriate to use this on values - * that come from API calls or other sources where an out of range - * error indicates a programming error, not a data error! - * - * NOTE: by default this is off - the macro is not used - because the - * function call saves a lot of code. - */ -#ifdef PNG_FIXED_POINT_MACRO_SUPPORTED -#define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\ - ((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0)) -#else -PNG_EXTERN png_fixed_point png_fixed PNGARG((png_structp png_ptr, double fp, - png_const_charp text)); -#endif -#endif - -/* Constants for known chunk types. If you need to add a chunk, define the name - * here. For historical reasons these constants have the form png_; i.e. - * the prefix is lower case. Please use decimal values as the parameters to - * match the ISO PNG specification and to avoid relying on the C locale - * interpretation of character values. - * - * Prior to 1.5.6 these constants were strings, as of 1.5.6 png_uint_32 values - * are computed and a new macro (PNG_STRING_FROM_CHUNK) added to allow a string - * to be generated if required. - * - * PNG_32b correctly produces a value shifted by up to 24 bits, even on - * architectures where (int) is only 16 bits. - */ -#define PNG_32b(b,s) ((png_uint_32)(b) << (s)) -#define PNG_CHUNK(b1,b2,b3,b4) \ - (PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0)) - -#define png_IHDR PNG_CHUNK( 73, 72, 68, 82) -#define png_IDAT PNG_CHUNK( 73, 68, 65, 84) -#define png_IEND PNG_CHUNK( 73, 69, 78, 68) -#define png_PLTE PNG_CHUNK( 80, 76, 84, 69) -#define png_bKGD PNG_CHUNK( 98, 75, 71, 68) -#define png_cHRM PNG_CHUNK( 99, 72, 82, 77) -#define png_gAMA PNG_CHUNK(103, 65, 77, 65) -#define png_hIST PNG_CHUNK(104, 73, 83, 84) -#define png_iCCP PNG_CHUNK(105, 67, 67, 80) -#define png_iTXt PNG_CHUNK(105, 84, 88, 116) -#define png_oFFs PNG_CHUNK(111, 70, 70, 115) -#define png_pCAL PNG_CHUNK(112, 67, 65, 76) -#define png_sCAL PNG_CHUNK(115, 67, 65, 76) -#define png_pHYs PNG_CHUNK(112, 72, 89, 115) -#define png_sBIT PNG_CHUNK(115, 66, 73, 84) -#define png_sPLT PNG_CHUNK(115, 80, 76, 84) -#define png_sRGB PNG_CHUNK(115, 82, 71, 66) -#define png_sTER PNG_CHUNK(115, 84, 69, 82) -#define png_tEXt PNG_CHUNK(116, 69, 88, 116) -#define png_tIME PNG_CHUNK(116, 73, 77, 69) -#define png_tRNS PNG_CHUNK(116, 82, 78, 83) -#define png_zTXt PNG_CHUNK(122, 84, 88, 116) - -/* The following will work on (signed char*) strings, whereas the get_uint_32 - * macro will fail on top-bit-set values because of the sign extension. - */ -#define PNG_CHUNK_FROM_STRING(s)\ - PNG_CHUNK(0xff&(s)[0], 0xff&(s)[1], 0xff&(s)[2], 0xff&(s)[3]) - -/* This uses (char), not (png_byte) to avoid warnings on systems where (char) is - * signed and the argument is a (char[]) This macro will fail miserably on - * systems where (char) is more than 8 bits. - */ -#define PNG_STRING_FROM_CHUNK(s,c)\ - (void)(((char*)(s))[0]=(char)((c)>>24), ((char*)(s))[1]=(char)((c)>>16),\ - ((char*)(s))[2]=(char)((c)>>8), ((char*)(s))[3]=(char)((c))) - -/* Do the same but terminate with a null character. */ -#define PNG_CSTRING_FROM_CHUNK(s,c)\ - (void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0) - -/* Test on flag values as defined in the spec (section 5.4): */ -#define PNG_CHUNK_ANCILLIARY(c) (1 & ((c) >> 29)) -#define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLIARY(c)) -#define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21)) -#define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13)) -#define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5)) - -/* Gamma values (new at libpng-1.5.4): */ -#define PNG_GAMMA_MAC_OLD 151724 /* Assume '1.8' is really 2.2/1.45! */ -#define PNG_GAMMA_MAC_INVERSE 65909 -#define PNG_GAMMA_sRGB_INVERSE 45455 - - -/* Inhibit C++ name-mangling for libpng functions but not for system calls. */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* These functions are used internally in the code. They generally - * shouldn't be used unless you are writing code to add or replace some - * functionality in libpng. More information about most functions can - * be found in the files where the functions are located. - */ - -/* Check the user version string for compatibility, returns false if the version - * numbers aren't compatible. - */ -PNG_EXTERN int png_user_version_check(png_structp png_ptr, - png_const_charp user_png_ver); - -/* Allocate memory for an internal libpng struct */ -PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct,PNGARG((int type)), - PNG_ALLOCATED); - -/* Free memory from internal libpng struct */ -PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr)); - -PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct_2, - PNGARG((int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)), - PNG_ALLOCATED); -PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr, - png_free_ptr free_fn, png_voidp mem_ptr)); - -/* Free any memory that info_ptr points to and reset struct. */ -PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr, - png_infop info_ptr)); - -/* Function to allocate memory for zlib. PNGAPI is disallowed. */ -PNG_EXTERN PNG_FUNCTION(voidpf,png_zalloc,PNGARG((voidpf png_ptr, uInt items, - uInt size)),PNG_ALLOCATED); - -/* Function to free memory for zlib. PNGAPI is disallowed. */ -PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr)); - -/* Next four functions are used internally as callbacks. PNGCBAPI is required - * but not PNG_EXPORT. PNGAPI added at libpng version 1.2.3, changed to - * PNGCBAPI at 1.5.0 - */ - -PNG_EXTERN void PNGCBAPI png_default_read_data PNGARG((png_structp png_ptr, - png_bytep data, png_size_t length)); - -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED -PNG_EXTERN void PNGCBAPI png_push_fill_buffer PNGARG((png_structp png_ptr, - png_bytep buffer, png_size_t length)); -#endif - -PNG_EXTERN void PNGCBAPI png_default_write_data PNGARG((png_structp png_ptr, - png_bytep data, png_size_t length)); - -#ifdef PNG_WRITE_FLUSH_SUPPORTED -# ifdef PNG_STDIO_SUPPORTED -PNG_EXTERN void PNGCBAPI png_default_flush PNGARG((png_structp png_ptr)); -# endif -#endif - -/* Reset the CRC variable */ -PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr)); - -/* Write the "data" buffer to whatever output you are using */ -PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, - png_const_bytep data, png_size_t length)); - -/* Read and check the PNG file signature */ -PNG_EXTERN void png_read_sig PNGARG((png_structp png_ptr, png_infop info_ptr)); - -/* Read the chunk header (length + type name) */ -PNG_EXTERN png_uint_32 png_read_chunk_header PNGARG((png_structp png_ptr)); - -/* Read data from whatever input you are using into the "data" buffer */ -PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data, - png_size_t length)); - -/* Read bytes into buf, and update png_ptr->crc */ -PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf, - png_size_t length)); - -/* Decompress data in a chunk that uses compression */ -#if defined(PNG_READ_COMPRESSED_TEXT_SUPPORTED) -PNG_EXTERN void png_decompress_chunk PNGARG((png_structp png_ptr, - int comp_type, png_size_t chunklength, png_size_t prefix_length, - png_size_t *data_length)); -#endif - -/* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */ -PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip)); - -/* Read the CRC from the file and compare it to the libpng calculated CRC */ -PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr)); - -/* Calculate the CRC over a section of data. Note that we are only - * passing a maximum of 64K on systems that have this as a memory limit, - * since this is the maximum buffer size we can specify. - */ -PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, - png_const_bytep ptr, png_size_t length)); - -#ifdef PNG_WRITE_FLUSH_SUPPORTED -PNG_EXTERN void png_flush PNGARG((png_structp png_ptr)); -#endif - -/* Write various chunks */ - -/* Write the IHDR chunk, and update the png_struct with the necessary - * information. - */ -PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width, - png_uint_32 height, - int bit_depth, int color_type, int compression_method, int filter_method, - int interlace_method)); - -PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, - png_const_colorp palette, png_uint_32 num_pal)); - -PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data, - png_size_t length)); - -PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr)); - -#ifdef PNG_WRITE_gAMA_SUPPORTED -# ifdef PNG_FLOATING_POINT_SUPPORTED -PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma)); -# endif -# ifdef PNG_FIXED_POINT_SUPPORTED -PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, - png_fixed_point file_gamma)); -# endif -#endif - -#ifdef PNG_WRITE_sBIT_SUPPORTED -PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, - png_const_color_8p sbit, int color_type)); -#endif - -#ifdef PNG_WRITE_cHRM_SUPPORTED -# ifdef PNG_FLOATING_POINT_SUPPORTED -PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr, - double white_x, double white_y, - double red_x, double red_y, double green_x, double green_y, - double blue_x, double blue_y)); -# endif -PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr, - png_fixed_point int_white_x, png_fixed_point int_white_y, - png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point - int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, - png_fixed_point int_blue_y)); -#endif - -#ifdef PNG_WRITE_sRGB_SUPPORTED -PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr, - int intent)); -#endif - -#ifdef PNG_WRITE_iCCP_SUPPORTED -PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr, - png_const_charp name, int compression_type, - png_const_charp profile, int proflen)); - /* Note to maintainer: profile should be png_bytep */ -#endif - -#ifdef PNG_WRITE_sPLT_SUPPORTED -PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr, - png_const_sPLT_tp palette)); -#endif - -#ifdef PNG_WRITE_tRNS_SUPPORTED -PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, - png_const_bytep trans, png_const_color_16p values, int number, - int color_type)); -#endif - -#ifdef PNG_WRITE_bKGD_SUPPORTED -PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr, - png_const_color_16p values, int color_type)); -#endif - -#ifdef PNG_WRITE_hIST_SUPPORTED -PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, - png_const_uint_16p hist, int num_hist)); -#endif - -/* Chunks that have keywords */ -#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ - defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) -PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr, - png_const_charp key, png_charpp new_key)); -#endif - -#ifdef PNG_WRITE_tEXt_SUPPORTED -PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_const_charp key, - png_const_charp text, png_size_t text_len)); -#endif - -#ifdef PNG_WRITE_zTXt_SUPPORTED -PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_const_charp key, - png_const_charp text, png_size_t text_len, int compression)); -#endif - -#ifdef PNG_WRITE_iTXt_SUPPORTED -PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr, - int compression, png_const_charp key, png_const_charp lang, - png_const_charp lang_key, png_const_charp text)); -#endif - -#ifdef PNG_TEXT_SUPPORTED /* Added at version 1.0.14 and 1.2.4 */ -PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr, - png_infop info_ptr, png_const_textp text_ptr, int num_text)); -#endif - -#ifdef PNG_WRITE_oFFs_SUPPORTED -PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr, - png_int_32 x_offset, png_int_32 y_offset, int unit_type)); -#endif - -#ifdef PNG_WRITE_pCAL_SUPPORTED -PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose, - png_int_32 X0, png_int_32 X1, int type, int nparams, - png_const_charp units, png_charpp params)); -#endif - -#ifdef PNG_WRITE_pHYs_SUPPORTED -PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr, - png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit, - int unit_type)); -#endif - -#ifdef PNG_WRITE_tIME_SUPPORTED -PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr, - png_const_timep mod_time)); -#endif - -#ifdef PNG_WRITE_sCAL_SUPPORTED -PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr, - int unit, png_const_charp width, png_const_charp height)); -#endif - -/* Called when finished processing a row of data */ -PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr)); - -/* Internal use only. Called before first row of data */ -PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr)); - -/* Combine a row of data, dealing with alpha, etc. if requested. 'row' is an - * array of png_ptr->width pixels. If the image is not interlaced or this - * is the final pass this just does a png_memcpy, otherwise the "display" flag - * is used to determine whether to copy pixels that are not in the current pass. - * - * Because 'png_do_read_interlace' (below) replicates pixels this allows this - * function to achieve the documented 'blocky' appearance during interlaced read - * if display is 1 and the 'sparkle' appearance, where existing pixels in 'row' - * are not changed if they are not in the current pass, when display is 0. - * - * 'display' must be 0 or 1, otherwise the memcpy will be done regardless. - * - * The API always reads from the png_struct row buffer and always assumes that - * it is full width (png_do_read_interlace has already been called.) - * - * This function is only ever used to write to row buffers provided by the - * caller of the relevant libpng API and the row must have already been - * transformed by the read transformations. - * - * The PNG_USE_COMPILE_TIME_MASKS option causes generation of pre-computed - * bitmasks for use within the code, otherwise runtime generated masks are used. - * The default is compile time masks. - */ -#ifndef PNG_USE_COMPILE_TIME_MASKS -# define PNG_USE_COMPILE_TIME_MASKS 1 -#endif -PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row, - int display)); - -#ifdef PNG_READ_INTERLACING_SUPPORTED -/* Expand an interlaced row: the 'row_info' describes the pass data that has - * been read in and must correspond to the pixels in 'row', the pixels are - * expanded (moved apart) in 'row' to match the final layout, when doing this - * the pixels are *replicated* to the intervening space. This is essential for - * the correct operation of png_combine_row, above. - */ -PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info, - png_bytep row, int pass, png_uint_32 transformations)); -#endif - -/* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */ - -#ifdef PNG_WRITE_INTERLACING_SUPPORTED -/* Grab pixels out of a row for an interlaced pass */ -PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info, - png_bytep row, int pass)); -#endif - -/* Unfilter a row: check the filter value before calling this, there is no point - * calling it for PNG_FILTER_VALUE_NONE. - */ -PNG_EXTERN void png_read_filter_row PNGARG((png_structp pp, png_row_infop - row_info, png_bytep row, png_const_bytep prev_row, int filter)); - -PNG_EXTERN void png_read_filter_row_up_neon PNGARG((png_row_infop row_info, - png_bytep row, png_const_bytep prev_row)); -PNG_EXTERN void png_read_filter_row_sub3_neon PNGARG((png_row_infop row_info, - png_bytep row, png_const_bytep prev_row)); -PNG_EXTERN void png_read_filter_row_sub4_neon PNGARG((png_row_infop row_info, - png_bytep row, png_const_bytep prev_row)); -PNG_EXTERN void png_read_filter_row_avg3_neon PNGARG((png_row_infop row_info, - png_bytep row, png_const_bytep prev_row)); -PNG_EXTERN void png_read_filter_row_avg4_neon PNGARG((png_row_infop row_info, - png_bytep row, png_const_bytep prev_row)); -PNG_EXTERN void png_read_filter_row_paeth3_neon PNGARG((png_row_infop row_info, - png_bytep row, png_const_bytep prev_row)); -PNG_EXTERN void png_read_filter_row_paeth4_neon PNGARG((png_row_infop row_info, - png_bytep row, png_const_bytep prev_row)); - -/* Choose the best filter to use and filter the row data */ -PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr, - png_row_infop row_info)); - -/* Finish a row while reading, dealing with interlacing passes, etc. */ -PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr)); - -/* Initialize the row buffers, etc. */ -PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr)); - -#ifdef PNG_READ_TRANSFORMS_SUPPORTED -/* Optional call to update the users info structure */ -PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr, - png_infop info_ptr)); -#endif - -/* These are the functions that do the transformations */ -#ifdef PNG_READ_FILLER_SUPPORTED -PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info, - png_bytep row, png_uint_32 filler, png_uint_32 flags)); -#endif - -#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED -PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED -PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED -PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED -PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#if defined(PNG_WRITE_FILLER_SUPPORTED) || \ - defined(PNG_READ_STRIP_ALPHA_SUPPORTED) -PNG_EXTERN void png_do_strip_channel PNGARG((png_row_infop row_info, - png_bytep row, int at_start)); -#endif - -#ifdef PNG_16BIT_SUPPORTED -#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) -PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, - png_bytep row)); -#endif -#endif - -#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \ - defined(PNG_WRITE_PACKSWAP_SUPPORTED) -PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED -PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, - png_row_infop row_info, png_bytep row)); -#endif - -#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED -PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_PACK_SUPPORTED -PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_SHIFT_SUPPORTED -PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, - png_bytep row, png_const_color_8p sig_bits)); -#endif - -#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) -PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED -PNG_EXTERN void png_do_scale_16_to_8 PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED -PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_READ_QUANTIZE_SUPPORTED -PNG_EXTERN void png_do_quantize PNGARG((png_row_infop row_info, - png_bytep row, png_const_bytep palette_lookup, - png_const_bytep quantize_lookup)); - -# ifdef PNG_CORRECT_PALETTE_SUPPORTED -PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr, - png_colorp palette, int num_palette)); -# endif -#endif - -#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) -PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -#ifdef PNG_WRITE_PACK_SUPPORTED -PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info, - png_bytep row, png_uint_32 bit_depth)); -#endif - -#ifdef PNG_WRITE_SHIFT_SUPPORTED -PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, - png_bytep row, png_const_color_8p bit_depth)); -#endif - -#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ - defined(PNG_READ_ALPHA_MODE_SUPPORTED) -PNG_EXTERN void png_do_compose PNGARG((png_row_infop row_info, - png_bytep row, png_structp png_ptr)); -#endif - -#ifdef PNG_READ_GAMMA_SUPPORTED -PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, - png_bytep row, png_structp png_ptr)); -#endif - -#ifdef PNG_READ_ALPHA_MODE_SUPPORTED -PNG_EXTERN void png_do_encode_alpha PNGARG((png_row_infop row_info, - png_bytep row, png_structp png_ptr)); -#endif - -#ifdef PNG_READ_EXPAND_SUPPORTED -PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info, - png_bytep row, png_const_colorp palette, png_const_bytep trans, - int num_trans)); -PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info, - png_bytep row, png_const_color_16p trans_color)); -#endif - -#ifdef PNG_READ_EXPAND_16_SUPPORTED -PNG_EXTERN void png_do_expand_16 PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -/* The following decodes the appropriate chunks, and does error correction, - * then calls the appropriate callback for the chunk if it is valid. - */ - -/* Decode the IHDR chunk */ -PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); - -#ifdef PNG_READ_bKGD_SUPPORTED -PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_cHRM_SUPPORTED -PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_gAMA_SUPPORTED -PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_hIST_SUPPORTED -PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_iCCP_SUPPORTED -PNG_EXTERN void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif /* PNG_READ_iCCP_SUPPORTED */ - -#ifdef PNG_READ_iTXt_SUPPORTED -PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_oFFs_SUPPORTED -PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_pCAL_SUPPORTED -PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_pHYs_SUPPORTED -PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_sBIT_SUPPORTED -PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_sCAL_SUPPORTED -PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_sPLT_SUPPORTED -PNG_EXTERN void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif /* PNG_READ_sPLT_SUPPORTED */ - -#ifdef PNG_READ_sRGB_SUPPORTED -PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_tEXt_SUPPORTED -PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_tIME_SUPPORTED -PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_tRNS_SUPPORTED -PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -#ifdef PNG_READ_zTXt_SUPPORTED -PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr, - png_uint_32 length)); -#endif - -PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); - -PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr, - png_uint_32 chunk_name)); - -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED -/* Exactly as png_handle_as_unknown() except that the argument is a 32-bit chunk - * name, not a string. - */ -PNG_EXTERN int png_chunk_unknown_handling PNGARG((png_structp png_ptr, - png_uint_32 chunk_name)); -#endif - -/* Handle the transformations for reading and writing */ -#ifdef PNG_READ_TRANSFORMS_SUPPORTED -PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr, - png_row_infop row_info)); -#endif -#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED -PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr, - png_row_infop row_info)); -#endif - -#ifdef PNG_READ_TRANSFORMS_SUPPORTED -PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr)); -#endif - -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED -PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr, - png_uint_32 length)); -PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr, - png_bytep buffer, png_size_t buffer_length)); -PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr, - png_bytep buffer, png_size_t buffer_length)); -PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row)); -PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr, - png_infop info_ptr)); -PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr)); -# ifdef PNG_READ_tEXt_SUPPORTED -PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr, - png_infop info_ptr)); -# endif -# ifdef PNG_READ_zTXt_SUPPORTED -PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr, - png_infop info_ptr)); -# endif -# ifdef PNG_READ_iTXt_SUPPORTED -PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr, - png_infop info_ptr)); -# endif - -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ - -#ifdef PNG_MNG_FEATURES_SUPPORTED -PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info, - png_bytep row)); -PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info, - png_bytep row)); -#endif - -/* Added at libpng version 1.4.0 */ -#ifdef PNG_CHECK_cHRM_SUPPORTED -PNG_EXTERN int png_check_cHRM_fixed PNGARG((png_structp png_ptr, - png_fixed_point int_white_x, png_fixed_point int_white_y, - png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point - int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, - png_fixed_point int_blue_y)); -#endif - -#ifdef PNG_CHECK_cHRM_SUPPORTED -/* Added at libpng version 1.2.34 and 1.4.0 */ -/* Currently only used by png_check_cHRM_fixed */ -PNG_EXTERN void png_64bit_product PNGARG((long v1, long v2, - unsigned long *hi_product, unsigned long *lo_product)); -#endif - -#ifdef PNG_cHRM_SUPPORTED -/* Added at libpng version 1.5.5 */ -typedef struct png_xy -{ - png_fixed_point redx, redy; - png_fixed_point greenx, greeny; - png_fixed_point bluex, bluey; - png_fixed_point whitex, whitey; -} png_xy; - -typedef struct png_XYZ -{ - png_fixed_point redX, redY, redZ; - png_fixed_point greenX, greenY, greenZ; - png_fixed_point blueX, blueY, blueZ; -} png_XYZ; - -/* The conversion APIs return 0 on success, non-zero on a parameter error. They - * allow conversion between the above representations of a color encoding. When - * converting from XYZ end points to chromaticities the absolute magnitude of - * the end points is lost, when converting back the sum of the Y values of the - * three end points will be 1.0 - */ -PNG_EXTERN int png_xy_from_XYZ PNGARG((png_xy *xy, png_XYZ XYZ)); -PNG_EXTERN int png_XYZ_from_xy PNGARG((png_XYZ *XYZ, png_xy xy)); -PNG_EXTERN int png_XYZ_from_xy_checked PNGARG((png_structp png_ptr, - png_XYZ *XYZ, png_xy xy)); -#endif - -/* Added at libpng version 1.4.0 */ -PNG_EXTERN void png_check_IHDR PNGARG((png_structp png_ptr, - png_uint_32 width, png_uint_32 height, int bit_depth, - int color_type, int interlace_type, int compression_type, - int filter_type)); - -/* Added at libpng version 1.5.10 */ -#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \ - defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED) -PNG_EXTERN void png_do_check_palette_indexes PNGARG((png_structp png_ptr, - png_row_infop row_info)); -#endif - -/* Free all memory used by the read (old method - NOT DLL EXPORTED) */ -PNG_EXTERN void png_read_destroy PNGARG((png_structp png_ptr, - png_infop info_ptr, png_infop end_info_ptr)); - -/* Free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */ -PNG_EXTERN void png_write_destroy PNGARG((png_structp png_ptr)); - -#ifdef USE_FAR_KEYWORD /* memory model conversion function */ -PNG_EXTERN void *png_far_to_near PNGARG((png_structp png_ptr, png_voidp ptr, - int check)); -#endif /* USE_FAR_KEYWORD */ - -#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) -PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_structp png_ptr, - png_const_charp name),PNG_NORETURN); -#endif - -/* Puts 'string' into 'buffer' at buffer[pos], taking care never to overwrite - * the end. Always leaves the buffer nul terminated. Never errors out (and - * there is no error code.) - */ -PNG_EXTERN size_t png_safecat(png_charp buffer, size_t bufsize, size_t pos, - png_const_charp string); - -/* Various internal functions to handle formatted warning messages, currently - * only implemented for warnings. - */ -#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED) -/* Utility to dump an unsigned value into a buffer, given a start pointer and - * and end pointer (which should point just *beyond* the end of the buffer!) - * Returns the pointer to the start of the formatted string. This utility only - * does unsigned values. - */ -PNG_EXTERN png_charp png_format_number(png_const_charp start, png_charp end, - int format, png_alloc_size_t number); - -/* Convenience macro that takes an array: */ -#define PNG_FORMAT_NUMBER(buffer,format,number) \ - png_format_number(buffer, buffer + (sizeof buffer), format, number) - -/* Suggested size for a number buffer (enough for 64 bits and a sign!) */ -#define PNG_NUMBER_BUFFER_SIZE 24 - -/* These are the integer formats currently supported, the name is formed from - * the standard printf(3) format string. - */ -#define PNG_NUMBER_FORMAT_u 1 /* chose unsigned API! */ -#define PNG_NUMBER_FORMAT_02u 2 -#define PNG_NUMBER_FORMAT_d 1 /* chose signed API! */ -#define PNG_NUMBER_FORMAT_02d 2 -#define PNG_NUMBER_FORMAT_x 3 -#define PNG_NUMBER_FORMAT_02x 4 -#define PNG_NUMBER_FORMAT_fixed 5 /* choose the signed API */ -#endif - -#ifdef PNG_WARNINGS_SUPPORTED -/* New defines and members adding in libpng-1.5.4 */ -# define PNG_WARNING_PARAMETER_SIZE 32 -# define PNG_WARNING_PARAMETER_COUNT 8 - -/* An l-value of this type has to be passed to the APIs below to cache the - * values of the parameters to a formatted warning message. - */ -typedef char png_warning_parameters[PNG_WARNING_PARAMETER_COUNT][ - PNG_WARNING_PARAMETER_SIZE]; - -PNG_EXTERN void png_warning_parameter(png_warning_parameters p, int number, - png_const_charp string); - /* Parameters are limited in size to PNG_WARNING_PARAMETER_SIZE characters, - * including the trailing '\0'. - */ -PNG_EXTERN void png_warning_parameter_unsigned(png_warning_parameters p, - int number, int format, png_alloc_size_t value); - /* Use png_alloc_size_t because it is an unsigned type as big as any we - * need to output. Use the following for a signed value. - */ -PNG_EXTERN void png_warning_parameter_signed(png_warning_parameters p, - int number, int format, png_int_32 value); - -PNG_EXTERN void png_formatted_warning(png_structp png_ptr, - png_warning_parameters p, png_const_charp message); - /* 'message' follows the X/Open approach of using @1, @2 to insert - * parameters previously supplied using the above functions. Errors in - * specifying the paramters will simple result in garbage substitutions. - */ -#endif - -/* ASCII to FP interfaces, currently only implemented if sCAL - * support is required. - */ -#if defined(PNG_READ_sCAL_SUPPORTED) -/* MAX_DIGITS is actually the maximum number of characters in an sCAL - * width or height, derived from the precision (number of significant - * digits - a build time settable option) and assumpitions about the - * maximum ridiculous exponent. - */ -#define PNG_sCAL_MAX_DIGITS (PNG_sCAL_PRECISION+1/*.*/+1/*E*/+10/*exponent*/) - -#ifdef PNG_FLOATING_POINT_SUPPORTED -PNG_EXTERN void png_ascii_from_fp PNGARG((png_structp png_ptr, png_charp ascii, - png_size_t size, double fp, unsigned int precision)); -#endif /* FLOATING_POINT */ - -#ifdef PNG_FIXED_POINT_SUPPORTED -PNG_EXTERN void png_ascii_from_fixed PNGARG((png_structp png_ptr, - png_charp ascii, png_size_t size, png_fixed_point fp)); -#endif /* FIXED_POINT */ -#endif /* READ_sCAL */ - -#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) -/* An internal API to validate the format of a floating point number. - * The result is the index of the next character. If the number is - * not valid it will be the index of a character in the supposed number. - * - * The format of a number is defined in the PNG extensions specification - * and this API is strictly conformant to that spec, not anyone elses! - * - * The format as a regular expression is: - * - * [+-]?[0-9]+.?([Ee][+-]?[0-9]+)? - * - * or: - * - * [+-]?.[0-9]+(.[0-9]+)?([Ee][+-]?[0-9]+)? - * - * The complexity is that either integer or fraction must be present and the - * fraction is permitted to have no digits only if the integer is present. - * - * NOTE: The dangling E problem. - * There is a PNG valid floating point number in the following: - * - * PNG floating point numb1.ers are not greedy. - * - * Working this out requires *TWO* character lookahead (because of the - * sign), the parser does not do this - it will fail at the 'r' - this - * doesn't matter for PNG sCAL chunk values, but it requires more care - * if the value were ever to be embedded in something more complex. Use - * ANSI-C strtod if you need the lookahead. - */ -/* State table for the parser. */ -#define PNG_FP_INTEGER 0 /* before or in integer */ -#define PNG_FP_FRACTION 1 /* before or in fraction */ -#define PNG_FP_EXPONENT 2 /* before or in exponent */ -#define PNG_FP_STATE 3 /* mask for the above */ -#define PNG_FP_SAW_SIGN 4 /* Saw +/- in current state */ -#define PNG_FP_SAW_DIGIT 8 /* Saw a digit in current state */ -#define PNG_FP_SAW_DOT 16 /* Saw a dot in current state */ -#define PNG_FP_SAW_E 32 /* Saw an E (or e) in current state */ -#define PNG_FP_SAW_ANY 60 /* Saw any of the above 4 */ - -/* These three values don't affect the parser. They are set but not used. - */ -#define PNG_FP_WAS_VALID 64 /* Preceding substring is a valid fp number */ -#define PNG_FP_NEGATIVE 128 /* A negative number, including "-0" */ -#define PNG_FP_NONZERO 256 /* A non-zero value */ -#define PNG_FP_STICKY 448 /* The above three flags */ - -/* This is available for the caller to store in 'state' if required. Do not - * call the parser after setting it (the parser sometimes clears it.) - */ -#define PNG_FP_INVALID 512 /* Available for callers as a distinct value */ - -/* Result codes for the parser (boolean - true meants ok, false means - * not ok yet.) - */ -#define PNG_FP_MAYBE 0 /* The number may be valid in the future */ -#define PNG_FP_OK 1 /* The number is valid */ - -/* Tests on the sticky non-zero and negative flags. To pass these checks - * the state must also indicate that the whole number is valid - this is - * achieved by testing PNG_FP_SAW_DIGIT (see the implementation for why this - * is equivalent to PNG_FP_OK above.) - */ -#define PNG_FP_NZ_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NEGATIVE | PNG_FP_NONZERO) - /* NZ_MASK: the string is valid and a non-zero negative value */ -#define PNG_FP_Z_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NONZERO) - /* Z MASK: the string is valid and a non-zero value. */ - /* PNG_FP_SAW_DIGIT: the string is valid. */ -#define PNG_FP_IS_ZERO(state) (((state) & PNG_FP_Z_MASK) == PNG_FP_SAW_DIGIT) -#define PNG_FP_IS_POSITIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_Z_MASK) -#define PNG_FP_IS_NEGATIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_NZ_MASK) - -/* The actual parser. This can be called repeatedly, it updates - * the index into the string and the state variable (which must - * be initialzed to 0). It returns a result code, as above. There - * is no point calling the parser any more if it fails to advance to - * the end of the string - it is stuck on an invalid character (or - * terminated by '\0'). - * - * Note that the pointer will consume an E or even an E+ then leave - * a 'maybe' state even though a preceding integer.fraction is valid. - * The PNG_FP_WAS_VALID flag indicates that a preceding substring was - * a valid number. It's possible to recover from this by calling - * the parser again (from the start, with state 0) but with a string - * that omits the last character (i.e. set the size to the index of - * the problem character.) This has not been tested within libpng. - */ -PNG_EXTERN int png_check_fp_number PNGARG((png_const_charp string, - png_size_t size, int *statep, png_size_tp whereami)); - -/* This is the same but it checks a complete string and returns true - * only if it just contains a floating point number. As of 1.5.4 this - * function also returns the state at the end of parsing the number if - * it was valid (otherwise it returns 0.) This can be used for testing - * for negative or zero values using the sticky flag. - */ -PNG_EXTERN int png_check_fp_string PNGARG((png_const_charp string, - png_size_t size)); -#endif /* pCAL || sCAL */ - -#if defined(PNG_READ_GAMMA_SUPPORTED) ||\ - defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED) -/* Added at libpng version 1.5.0 */ -/* This is a utility to provide a*times/div (rounded) and indicate - * if there is an overflow. The result is a boolean - false (0) - * for overflow, true (1) if no overflow, in which case *res - * holds the result. - */ -PNG_EXTERN int png_muldiv PNGARG((png_fixed_point_p res, png_fixed_point a, - png_int_32 multiplied_by, png_int_32 divided_by)); -#endif - -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED) -/* Same deal, but issue a warning on overflow and return 0. */ -PNG_EXTERN png_fixed_point png_muldiv_warn PNGARG((png_structp png_ptr, - png_fixed_point a, png_int_32 multiplied_by, png_int_32 divided_by)); -#endif - -#ifdef PNG_READ_GAMMA_SUPPORTED -/* Calculate a reciprocal - used for gamma values. This returns - * 0 if the argument is 0 in order to maintain an undefined value, - * there are no warnings. - */ -PNG_EXTERN png_fixed_point png_reciprocal PNGARG((png_fixed_point a)); - -/* The same but gives a reciprocal of the product of two fixed point - * values. Accuracy is suitable for gamma calculations but this is - * not exact - use png_muldiv for that. - */ -PNG_EXTERN png_fixed_point png_reciprocal2 PNGARG((png_fixed_point a, - png_fixed_point b)); -#endif - -#ifdef PNG_READ_GAMMA_SUPPORTED -/* Internal fixed point gamma correction. These APIs are called as - * required to convert single values - they don't need to be fast, - * they are not used when processing image pixel values. - * - * While the input is an 'unsigned' value it must actually be the - * correct bit value - 0..255 or 0..65535 as required. - */ -PNG_EXTERN png_uint_16 png_gamma_correct PNGARG((png_structp png_ptr, - unsigned int value, png_fixed_point gamma_value)); -PNG_EXTERN int png_gamma_significant PNGARG((png_fixed_point gamma_value)); -PNG_EXTERN png_uint_16 png_gamma_16bit_correct PNGARG((unsigned int value, - png_fixed_point gamma_value)); -PNG_EXTERN png_byte png_gamma_8bit_correct PNGARG((unsigned int value, - png_fixed_point gamma_value)); -PNG_EXTERN void png_destroy_gamma_table(png_structp png_ptr); -PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr, - int bit_depth)); -#endif - -/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ - -#include "pngdebug.h" - -#ifdef __cplusplus -} -#endif - -#endif /* PNGPRIV_H */ + +/* pngpriv.h - private declarations for use inside libpng + * + * For conditions of distribution and use, see copyright notice in png.h + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * Last changed in libpng 1.5.10 [March 29, 2012] + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +/* The symbols declared in this file (including the functions declared + * as PNG_EXTERN) are PRIVATE. They are not part of the libpng public + * interface, and are not recommended for use by regular applications. + * Some of them may become public in the future; others may stay private, + * change in an incompatible way, or even disappear. + * Although the libpng users are not forbidden to include this header, + * they should be well aware of the issues that may arise from doing so. + */ + +#ifndef PNGPRIV_H +#define PNGPRIV_H + +/* Feature Test Macros. The following are defined here to ensure that correctly + * implemented libraries reveal the APIs libpng needs to build and hide those + * that are not needed and potentially damaging to the compilation. + * + * Feature Test Macros must be defined before any system header is included (see + * POSIX 1003.1 2.8.2 "POSIX Symbols." + * + * These macros only have an effect if the operating system supports either + * POSIX 1003.1 or C99, or both. On other operating systems (particularly + * Windows/Visual Studio) there is no effect; the OS specific tests below are + * still required (as of 2011-05-02.) + */ +#define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */ + +/* This is required for the definition of abort(), used as a last ditch + * error handler when all else fails. + */ +#include + +/* This is used to find 'offsetof', used below for alignment tests. */ +#include + +#define PNGLIB_BUILD /*libpng is being built, not used*/ + +#ifdef PNG_USER_CONFIG +# include "pngusr.h" + /* These should have been defined in pngusr.h */ +# ifndef PNG_USER_PRIVATEBUILD +# define PNG_USER_PRIVATEBUILD "Custom libpng build" +# endif +# ifndef PNG_USER_DLLFNAME_POSTFIX +# define PNG_USER_DLLFNAME_POSTFIX "Cb" +# endif +#endif + +/* Is this a build of a DLL where compilation of the object modules requires + * different preprocessor settings to those required for a simple library? If + * so PNG_BUILD_DLL must be set. + * + * If libpng is used inside a DLL but that DLL does not export the libpng APIs + * PNG_BUILD_DLL must not be set. To avoid the code below kicking in build a + * static library of libpng then link the DLL against that. + */ +#ifndef PNG_BUILD_DLL +# ifdef DLL_EXPORT + /* This is set by libtool when files are compiled for a DLL; libtool + * always compiles twice, even on systems where it isn't necessary. Set + * PNG_BUILD_DLL in case it is necessary: + */ +# define PNG_BUILD_DLL +# else +# ifdef _WINDLL + /* This is set by the Microsoft Visual Studio IDE in projects that + * build a DLL. It can't easily be removed from those projects (it + * isn't visible in the Visual Studio UI) so it is a fairly reliable + * indication that PNG_IMPEXP needs to be set to the DLL export + * attributes. + */ +# define PNG_BUILD_DLL +# else +# ifdef __DLL__ + /* This is set by the Borland C system when compiling for a DLL + * (as above.) + */ +# define PNG_BUILD_DLL +# else + /* Add additional compiler cases here. */ +# endif +# endif +# endif +#endif /* Setting PNG_BUILD_DLL if required */ + +/* See pngconf.h for more details: the builder of the library may set this on + * the command line to the right thing for the specific compilation system or it + * may be automagically set above (at present we know of no system where it does + * need to be set on the command line.) + * + * PNG_IMPEXP must be set here when building the library to prevent pngconf.h + * setting it to the "import" setting for a DLL build. + */ +#ifndef PNG_IMPEXP +# ifdef PNG_BUILD_DLL +# define PNG_IMPEXP PNG_DLL_EXPORT +# else + /* Not building a DLL, or the DLL doesn't require specific export + * definitions. + */ +# define PNG_IMPEXP +# endif +#endif + +/* No warnings for private or deprecated functions in the build: */ +#ifndef PNG_DEPRECATED +# define PNG_DEPRECATED +#endif +#ifndef PNG_PRIVATE +# define PNG_PRIVATE +#endif + +#include "png.h" +#include "pnginfo.h" +#include "pngstruct.h" + +/* pngconf.h does not set PNG_DLL_EXPORT unless it is required, so: */ +#ifndef PNG_DLL_EXPORT +# define PNG_DLL_EXPORT +#endif + +/* SECURITY and SAFETY: + * + * By default libpng is built without any internal limits on image size, + * individual heap (png_malloc) allocations or the total amount of memory used. + * If PNG_SAFE_LIMITS_SUPPORTED is defined, however, the limits below are used + * (unless individually overridden). These limits are believed to be fairly + * safe, but builders of secure systems should verify the values against the + * real system capabilities. + */ + +#ifdef PNG_SAFE_LIMITS_SUPPORTED + /* 'safe' limits */ +# ifndef PNG_USER_WIDTH_MAX +# define PNG_USER_WIDTH_MAX 1000000 +# endif +# ifndef PNG_USER_HEIGHT_MAX +# define PNG_USER_HEIGHT_MAX 1000000 +# endif +# ifndef PNG_USER_CHUNK_CACHE_MAX +# define PNG_USER_CHUNK_CACHE_MAX 128 +# endif +# ifndef PNG_USER_CHUNK_MALLOC_MAX +# define PNG_USER_CHUNK_MALLOC_MAX 8000000 +# endif +#else + /* values for no limits */ +# ifndef PNG_USER_WIDTH_MAX +# define PNG_USER_WIDTH_MAX 0x7fffffff +# endif +# ifndef PNG_USER_HEIGHT_MAX +# define PNG_USER_HEIGHT_MAX 0x7fffffff +# endif +# ifndef PNG_USER_CHUNK_CACHE_MAX +# define PNG_USER_CHUNK_CACHE_MAX 0 +# endif +# ifndef PNG_USER_CHUNK_MALLOC_MAX +# define PNG_USER_CHUNK_MALLOC_MAX 0 +# endif +#endif + +/* This is used for 16 bit gamma tables - only the top level pointers are const, + * this could be changed: + */ +typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; + +/* Added at libpng-1.2.9 */ +/* Moved to pngpriv.h at libpng-1.5.0 */ + +/* config.h is created by and PNG_CONFIGURE_LIBPNG is set by the "configure" + * script. We may need it here to get the correct configuration on things + * like limits. + */ +#ifdef PNG_CONFIGURE_LIBPNG +# ifdef HAVE_CONFIG_H +# include "config.h" +# endif +#endif + +/* Moved to pngpriv.h at libpng-1.5.0 */ +/* NOTE: some of these may have been used in external applications as + * these definitions were exposed in pngconf.h prior to 1.5. + */ + +/* If you are running on a machine where you cannot allocate more + * than 64K of memory at once, uncomment this. While libpng will not + * normally need that much memory in a chunk (unless you load up a very + * large file), zlib needs to know how big of a chunk it can use, and + * libpng thus makes sure to check any memory allocation to verify it + * will fit into memory. + * + * zlib provides 'MAXSEG_64K' which, if defined, indicates the + * same limit and pngconf.h (already included) sets the limit + * if certain operating systems are detected. + */ +#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) +# define PNG_MAX_MALLOC_64K +#endif + +#ifndef PNG_UNUSED +/* Unused formal parameter warnings are silenced using the following macro + * which is expected to have no bad effects on performance (optimizing + * compilers will probably remove it entirely). Note that if you replace + * it with something other than whitespace, you must include the terminating + * semicolon. + */ +# define PNG_UNUSED(param) (void)param; +#endif + +/* Just a little check that someone hasn't tried to define something + * contradictory. + */ +#if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K) +# undef PNG_ZBUF_SIZE +# define PNG_ZBUF_SIZE 65536L +#endif + +/* PNG_STATIC is used to mark internal file scope functions if they need to be + * accessed for implementation tests (see the code in tests/?*). + */ +#ifndef PNG_STATIC +# define PNG_STATIC static +#endif + +/* C99 restrict is used where possible, to do this 'restrict' is defined as + * empty if we can't be sure it is supported. configure builds have already + * done this work. + */ +#ifdef PNG_CONFIGURE_LIBPNG +# define PNG_RESTRICT restrict +#else + /* Modern compilers support restrict, but assume not for anything not + * recognized here: + */ +# if defined __GNUC__ || defined _MSC_VER || defined __WATCOMC__ +# define PNG_RESTRICT restrict +# else +# define PNG_RESTRICT +# endif +#endif + +/* If warnings or errors are turned off the code is disabled or redirected here. + * From 1.5.4 functions have been added to allow very limited formatting of + * error and warning messages - this code will also be disabled here. + */ +#ifdef PNG_WARNINGS_SUPPORTED +# define PNG_WARNING_PARAMETERS(p) png_warning_parameters p; +#else +# define png_warning(s1,s2) ((void)(s1)) +# define png_chunk_warning(s1,s2) ((void)(s1)) +# define png_warning_parameter(p,number,string) ((void)0) +# define png_warning_parameter_unsigned(p,number,format,value) ((void)0) +# define png_warning_parameter_signed(p,number,format,value) ((void)0) +# define png_formatted_warning(pp,p,message) ((void)(pp)) +# define PNG_WARNING_PARAMETERS(p) +#endif +#ifndef PNG_ERROR_TEXT_SUPPORTED +# define png_error(s1,s2) png_err(s1) +# define png_chunk_error(s1,s2) png_err(s1) +# define png_fixed_error(s1,s2) png_err(s1) +#endif + +/* C allows up-casts from (void*) to any pointer and (const void*) to any + * pointer to a const object. C++ regards this as a type error and requires an + * explicit, static, cast and provides the static_cast<> rune to ensure that + * const is not cast away. + */ +#ifdef __cplusplus +# define png_voidcast(type, value) static_cast(value) +#else +# define png_voidcast(type, value) (value) +#endif /* __cplusplus */ + +#ifndef PNG_EXTERN +/* The functions exported by PNG_EXTERN are internal functions, which + * aren't usually used outside the library (as far as I know), so it is + * debatable if they should be exported at all. In the future, when it + * is possible to have run-time registry of chunk-handling functions, + * some of these might be made available again. + * + * 1.5.7: turned the use of 'extern' back on, since it is localized to pngpriv.h + * it should be safe now (it is unclear why it was turned off.) + */ +# define PNG_EXTERN extern +#endif + +/* Some fixed point APIs are still required even if not exported because + * they get used by the corresponding floating point APIs. This magic + * deals with this: + */ +#ifdef PNG_FIXED_POINT_SUPPORTED +# define PNGFAPI PNGAPI +#else +# define PNGFAPI /* PRIVATE */ +#endif + +/* Other defines specific to compilers can go here. Try to keep + * them inside an appropriate ifdef/endif pair for portability. + */ +#if defined(PNG_FLOATING_POINT_SUPPORTED) ||\ + defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) + /* png.c requires the following ANSI-C constants if the conversion of + * floating point to ASCII is implemented therein: + * + * DBL_DIG Maximum number of decimal digits (can be set to any constant) + * DBL_MIN Smallest normalized fp number (can be set to an arbitrary value) + * DBL_MAX Maximum floating point number (can be set to an arbitrary value) + */ +# include + +# if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \ + defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC) + /* We need to check that hasn't already been included earlier + * as it seems it doesn't agree with , yet we should really use + * if possible. + */ +# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__) +# include +# endif +# else +# include +# endif +# if defined(_AMIGA) && defined(__SASC) && defined(_M68881) + /* Amiga SAS/C: We must include builtin FPU functions when compiling using + * MATH=68881 + */ +# include +# endif +#endif + +/* This provides the non-ANSI (far) memory allocation routines. */ +#if defined(__TURBOC__) && defined(__MSDOS__) +# include +# include +#endif + +#if defined(WIN32) || defined(_Windows) || defined(_WINDOWS) || \ + defined(_WIN32) || defined(__WIN32__) +# include /* defines _WINDOWS_ macro */ +#endif + +/* Moved here around 1.5.0beta36 from pngconf.h */ +/* Users may want to use these so they are not private. Any library + * functions that are passed far data must be model-independent. + */ + +/* Memory model/platform independent fns */ +#ifndef PNG_ABORT +# ifdef _WINDOWS_ +# define PNG_ABORT() ExitProcess(0) +# else +# define PNG_ABORT() abort() +# endif +#endif + +#ifdef USE_FAR_KEYWORD +/* Use this to make far-to-near assignments */ +# define CHECK 1 +# define NOCHECK 0 +# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK)) +# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK)) +# define png_strlen _fstrlen +# define png_memcmp _fmemcmp /* SJT: added */ +# define png_memcpy _fmemcpy +# define png_memset _fmemset +#else +# ifdef _WINDOWS_ /* Favor Windows over C runtime fns */ +# define CVT_PTR(ptr) (ptr) +# define CVT_PTR_NOCHECK(ptr) (ptr) +# define png_strlen lstrlenA +# define png_memcmp memcmp +# define png_memcpy CopyMemory +# define png_memset memset +# else +# define CVT_PTR(ptr) (ptr) +# define CVT_PTR_NOCHECK(ptr) (ptr) +# define png_strlen strlen +# define png_memcmp memcmp /* SJT: added */ +# define png_memcpy memcpy +# define png_memset memset +# endif +#endif + +/* These macros may need to be architecture dependent. */ +#define PNG_ALIGN_NONE 0 /* do not use data alignment */ +#define PNG_ALIGN_ALWAYS 1 /* assume unaligned accesses are OK */ +#ifdef offsetof +# define PNG_ALIGN_OFFSET 2 /* use offsetof to determine alignment */ +#else +# define PNG_ALIGN_OFFSET -1 /* prevent the use of this */ +#endif +#define PNG_ALIGN_SIZE 3 /* use sizeof to determine alignment */ + +#ifndef PNG_ALIGN_TYPE + /* Default to using aligned access optimizations and requiring alignment to a + * multiple of the data type size. Override in a compiler specific fashion + * if necessary by inserting tests here: + */ +# define PNG_ALIGN_TYPE PNG_ALIGN_SIZE +#endif + +#if PNG_ALIGN_TYPE == PNG_ALIGN_SIZE + /* This is used because in some compiler implementations non-aligned + * structure members are supported, so the offsetof approach below fails. + * Set PNG_ALIGN_TO_SIZE=0 for compiler combinations where unaligned access + * is good for performance. Do not do this unless you have tested the result + * and understand it. + */ +# define png_alignof(type) (sizeof (type)) +#else +# if PNG_ALIGN_TYPE == PNG_ALIGN_OFFSET +# define png_alignof(type) offsetof(struct{char c; type t;}, t) +# else +# if PNG_ALIGN_TYPE == PNG_ALIGN_ALWAYS +# define png_alignof(type) (1) +# endif + /* Else leave png_alignof undefined to prevent use thereof */ +# endif +#endif + +/* This implicitly assumes alignment is always to a power of 2. */ +#ifdef png_alignof +# define png_isaligned(ptr, type)\ + ((((const char*)ptr-(const char*)0) & (png_alignof(type)-1)) == 0) +#else +# define png_isaligned(ptr, type) 0 +#endif + +/* End of memory model/platform independent support */ +/* End of 1.5.0beta36 move from pngconf.h */ + +/* CONSTANTS and UTILITY MACROS + * These are used internally by libpng and not exposed in the API + */ + +/* Various modes of operation. Note that after an init, mode is set to + * zero automatically when the structure is created. Three of these + * are defined in png.h because they need to be visible to applications + * that call png_set_unknown_chunk(). + */ +/* #define PNG_HAVE_IHDR 0x01 (defined in png.h) */ +/* #define PNG_HAVE_PLTE 0x02 (defined in png.h) */ +#define PNG_HAVE_IDAT 0x04 +/* #define PNG_AFTER_IDAT 0x08 (defined in png.h) */ +#define PNG_HAVE_IEND 0x10 +#define PNG_HAVE_gAMA 0x20 +#define PNG_HAVE_cHRM 0x40 +#define PNG_HAVE_sRGB 0x80 +#define PNG_HAVE_CHUNK_HEADER 0x100 +#define PNG_WROTE_tIME 0x200 +#define PNG_WROTE_INFO_BEFORE_PLTE 0x400 +#define PNG_BACKGROUND_IS_GRAY 0x800 +#define PNG_HAVE_PNG_SIGNATURE 0x1000 +#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */ +#define PNG_HAVE_iCCP 0x4000 + +/* Flags for the transformations the PNG library does on the image data */ +#define PNG_BGR 0x0001 +#define PNG_INTERLACE 0x0002 +#define PNG_PACK 0x0004 +#define PNG_SHIFT 0x0008 +#define PNG_SWAP_BYTES 0x0010 +#define PNG_INVERT_MONO 0x0020 +#define PNG_QUANTIZE 0x0040 +#define PNG_COMPOSE 0x0080 /* Was PNG_BACKGROUND */ +#define PNG_BACKGROUND_EXPAND 0x0100 +#define PNG_EXPAND_16 0x0200 /* Added to libpng 1.5.2 */ +#define PNG_16_TO_8 0x0400 /* Becomes 'chop' in 1.5.4 */ +#define PNG_RGBA 0x0800 +#define PNG_EXPAND 0x1000 +#define PNG_GAMMA 0x2000 +#define PNG_GRAY_TO_RGB 0x4000 +#define PNG_FILLER 0x8000 +#define PNG_PACKSWAP 0x10000 +#define PNG_SWAP_ALPHA 0x20000 +#define PNG_STRIP_ALPHA 0x40000 +#define PNG_INVERT_ALPHA 0x80000 +#define PNG_USER_TRANSFORM 0x100000 +#define PNG_RGB_TO_GRAY_ERR 0x200000 +#define PNG_RGB_TO_GRAY_WARN 0x400000 +#define PNG_RGB_TO_GRAY 0x600000 /* two bits, RGB_TO_GRAY_ERR|WARN */ +#define PNG_ENCODE_ALPHA 0x800000 /* Added to libpng-1.5.4 */ +#define PNG_ADD_ALPHA 0x1000000 /* Added to libpng-1.2.7 */ +#define PNG_EXPAND_tRNS 0x2000000 /* Added to libpng-1.2.9 */ +#define PNG_SCALE_16_TO_8 0x4000000 /* Added to libpng-1.5.4 */ + /* 0x8000000 unused */ + /* 0x10000000 unused */ + /* 0x20000000 unused */ + /* 0x40000000 unused */ +/* Flags for png_create_struct */ +#define PNG_STRUCT_PNG 0x0001 +#define PNG_STRUCT_INFO 0x0002 + +/* Scaling factor for filter heuristic weighting calculations */ +#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT)) +#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT)) + +/* Flags for the png_ptr->flags rather than declaring a byte for each one */ +#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001 +#define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002 +#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004 +#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008 +#define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010 +#define PNG_FLAG_ZLIB_FINISHED 0x0020 +#define PNG_FLAG_ROW_INIT 0x0040 +#define PNG_FLAG_FILLER_AFTER 0x0080 +#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100 +#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200 +#define PNG_FLAG_CRC_CRITICAL_USE 0x0400 +#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800 +#define PNG_FLAG_ASSUME_sRGB 0x1000 /* Added to libpng-1.5.4 */ +#define PNG_FLAG_OPTIMIZE_ALPHA 0x2000 /* Added to libpng-1.5.4 */ +#define PNG_FLAG_DETECT_UNINITIALIZED 0x4000 /* Added to libpng-1.5.4 */ +#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000 +#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000 +#define PNG_FLAG_LIBRARY_MISMATCH 0x20000 +#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000 +#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000 +#define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000 + /* 0x200000 unused */ + /* 0x400000 unused */ +#define PNG_FLAG_BENIGN_ERRORS_WARN 0x800000 /* Added to libpng-1.4.0 */ +#define PNG_FLAG_ZTXT_CUSTOM_STRATEGY 0x1000000 /* 5 lines added */ +#define PNG_FLAG_ZTXT_CUSTOM_LEVEL 0x2000000 /* to libpng-1.5.4 */ +#define PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL 0x4000000 +#define PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS 0x8000000 +#define PNG_FLAG_ZTXT_CUSTOM_METHOD 0x10000000 + /* 0x20000000 unused */ + /* 0x40000000 unused */ + +#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ + PNG_FLAG_CRC_ANCILLARY_NOWARN) + +#define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \ + PNG_FLAG_CRC_CRITICAL_IGNORE) + +#define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \ + PNG_FLAG_CRC_CRITICAL_MASK) + +/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib + * can handle at once. This type need be no larger than 16 bits (so maximum of + * 65535), this define allows us to discover how big it is, but limited by the + * maximuum for png_size_t. The value can be overriden in a library build + * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably + * lower value (e.g. 255 works). A lower value may help memory usage (slightly) + * and may even improve performance on some systems (and degrade it on others.) + */ +#ifndef ZLIB_IO_MAX +# define ZLIB_IO_MAX ((uInt)-1) +#endif + +/* Save typing and make code easier to understand */ + +#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \ + abs((int)((c1).green) - (int)((c2).green)) + \ + abs((int)((c1).blue) - (int)((c2).blue))) + +/* Added to libpng-1.2.6 JB */ +#define PNG_ROWBYTES(pixel_bits, width) \ + ((pixel_bits) >= 8 ? \ + ((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \ + (( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) ) + +/* PNG_OUT_OF_RANGE returns true if value is outside the range + * ideal-delta..ideal+delta. Each argument is evaluated twice. + * "ideal" and "delta" should be constants, normally simple + * integers, "value" a variable. Added to libpng-1.2.6 JB + */ +#define PNG_OUT_OF_RANGE(value, ideal, delta) \ + ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) ) + +/* Conversions between fixed and floating point, only defined if + * required (to make sure the code doesn't accidentally use float + * when it is supposedly disabled.) + */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +/* The floating point conversion can't overflow, though it can and + * does lose accuracy relative to the original fixed point value. + * In practice this doesn't matter because png_fixed_point only + * stores numbers with very low precision. The png_ptr and s + * arguments are unused by default but are there in case error + * checking becomes a requirement. + */ +#define png_float(png_ptr, fixed, s) (.00001 * (fixed)) + +/* The fixed point conversion performs range checking and evaluates + * its argument multiple times, so must be used with care. The + * range checking uses the PNG specification values for a signed + * 32 bit fixed point value except that the values are deliberately + * rounded-to-zero to an integral value - 21474 (21474.83 is roughly + * (2^31-1) * 100000). 's' is a string that describes the value being + * converted. + * + * NOTE: this macro will raise a png_error if the range check fails, + * therefore it is normally only appropriate to use this on values + * that come from API calls or other sources where an out of range + * error indicates a programming error, not a data error! + * + * NOTE: by default this is off - the macro is not used - because the + * function call saves a lot of code. + */ +#ifdef PNG_FIXED_POINT_MACRO_SUPPORTED +#define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\ + ((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0)) +#else +PNG_EXTERN png_fixed_point png_fixed PNGARG((png_structp png_ptr, double fp, + png_const_charp text)); +#endif +#endif + +/* Constants for known chunk types. If you need to add a chunk, define the name + * here. For historical reasons these constants have the form png_; i.e. + * the prefix is lower case. Please use decimal values as the parameters to + * match the ISO PNG specification and to avoid relying on the C locale + * interpretation of character values. + * + * Prior to 1.5.6 these constants were strings, as of 1.5.6 png_uint_32 values + * are computed and a new macro (PNG_STRING_FROM_CHUNK) added to allow a string + * to be generated if required. + * + * PNG_32b correctly produces a value shifted by up to 24 bits, even on + * architectures where (int) is only 16 bits. + */ +#define PNG_32b(b,s) ((png_uint_32)(b) << (s)) +#define PNG_CHUNK(b1,b2,b3,b4) \ + (PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0)) + +#define png_IHDR PNG_CHUNK( 73, 72, 68, 82) +#define png_IDAT PNG_CHUNK( 73, 68, 65, 84) +#define png_IEND PNG_CHUNK( 73, 69, 78, 68) +#define png_PLTE PNG_CHUNK( 80, 76, 84, 69) +#define png_bKGD PNG_CHUNK( 98, 75, 71, 68) +#define png_cHRM PNG_CHUNK( 99, 72, 82, 77) +#define png_gAMA PNG_CHUNK(103, 65, 77, 65) +#define png_hIST PNG_CHUNK(104, 73, 83, 84) +#define png_iCCP PNG_CHUNK(105, 67, 67, 80) +#define png_iTXt PNG_CHUNK(105, 84, 88, 116) +#define png_oFFs PNG_CHUNK(111, 70, 70, 115) +#define png_pCAL PNG_CHUNK(112, 67, 65, 76) +#define png_sCAL PNG_CHUNK(115, 67, 65, 76) +#define png_pHYs PNG_CHUNK(112, 72, 89, 115) +#define png_sBIT PNG_CHUNK(115, 66, 73, 84) +#define png_sPLT PNG_CHUNK(115, 80, 76, 84) +#define png_sRGB PNG_CHUNK(115, 82, 71, 66) +#define png_sTER PNG_CHUNK(115, 84, 69, 82) +#define png_tEXt PNG_CHUNK(116, 69, 88, 116) +#define png_tIME PNG_CHUNK(116, 73, 77, 69) +#define png_tRNS PNG_CHUNK(116, 82, 78, 83) +#define png_zTXt PNG_CHUNK(122, 84, 88, 116) + +/* The following will work on (signed char*) strings, whereas the get_uint_32 + * macro will fail on top-bit-set values because of the sign extension. + */ +#define PNG_CHUNK_FROM_STRING(s)\ + PNG_CHUNK(0xff&(s)[0], 0xff&(s)[1], 0xff&(s)[2], 0xff&(s)[3]) + +/* This uses (char), not (png_byte) to avoid warnings on systems where (char) is + * signed and the argument is a (char[]) This macro will fail miserably on + * systems where (char) is more than 8 bits. + */ +#define PNG_STRING_FROM_CHUNK(s,c)\ + (void)(((char*)(s))[0]=(char)((c)>>24), ((char*)(s))[1]=(char)((c)>>16),\ + ((char*)(s))[2]=(char)((c)>>8), ((char*)(s))[3]=(char)((c))) + +/* Do the same but terminate with a null character. */ +#define PNG_CSTRING_FROM_CHUNK(s,c)\ + (void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0) + +/* Test on flag values as defined in the spec (section 5.4): */ +#define PNG_CHUNK_ANCILLIARY(c) (1 & ((c) >> 29)) +#define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLIARY(c)) +#define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21)) +#define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13)) +#define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5)) + +/* Gamma values (new at libpng-1.5.4): */ +#define PNG_GAMMA_MAC_OLD 151724 /* Assume '1.8' is really 2.2/1.45! */ +#define PNG_GAMMA_MAC_INVERSE 65909 +#define PNG_GAMMA_sRGB_INVERSE 45455 + + +/* Inhibit C++ name-mangling for libpng functions but not for system calls. */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* These functions are used internally in the code. They generally + * shouldn't be used unless you are writing code to add or replace some + * functionality in libpng. More information about most functions can + * be found in the files where the functions are located. + */ + +/* Check the user version string for compatibility, returns false if the version + * numbers aren't compatible. + */ +PNG_EXTERN int png_user_version_check(png_structp png_ptr, + png_const_charp user_png_ver); + +/* Allocate memory for an internal libpng struct */ +PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct,PNGARG((int type)), + PNG_ALLOCATED); + +/* Free memory from internal libpng struct */ +PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr)); + +PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct_2, + PNGARG((int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)), + PNG_ALLOCATED); +PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr, + png_free_ptr free_fn, png_voidp mem_ptr)); + +/* Free any memory that info_ptr points to and reset struct. */ +PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr, + png_infop info_ptr)); + +/* Function to allocate memory for zlib. PNGAPI is disallowed. */ +PNG_EXTERN PNG_FUNCTION(voidpf,png_zalloc,PNGARG((voidpf png_ptr, uInt items, + uInt size)),PNG_ALLOCATED); + +/* Function to free memory for zlib. PNGAPI is disallowed. */ +PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr)); + +/* Next four functions are used internally as callbacks. PNGCBAPI is required + * but not PNG_EXPORT. PNGAPI added at libpng version 1.2.3, changed to + * PNGCBAPI at 1.5.0 + */ + +PNG_EXTERN void PNGCBAPI png_default_read_data PNGARG((png_structp png_ptr, + png_bytep data, png_size_t length)); + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +PNG_EXTERN void PNGCBAPI png_push_fill_buffer PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t length)); +#endif + +PNG_EXTERN void PNGCBAPI png_default_write_data PNGARG((png_structp png_ptr, + png_bytep data, png_size_t length)); + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +# ifdef PNG_STDIO_SUPPORTED +PNG_EXTERN void PNGCBAPI png_default_flush PNGARG((png_structp png_ptr)); +# endif +#endif + +/* Reset the CRC variable */ +PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr)); + +/* Write the "data" buffer to whatever output you are using */ +PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, + png_const_bytep data, png_size_t length)); + +/* Read and check the PNG file signature */ +PNG_EXTERN void png_read_sig PNGARG((png_structp png_ptr, png_infop info_ptr)); + +/* Read the chunk header (length + type name) */ +PNG_EXTERN png_uint_32 png_read_chunk_header PNGARG((png_structp png_ptr)); + +/* Read data from whatever input you are using into the "data" buffer */ +PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data, + png_size_t length)); + +/* Read bytes into buf, and update png_ptr->crc */ +PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf, + png_size_t length)); + +/* Decompress data in a chunk that uses compression */ +#if defined(PNG_READ_COMPRESSED_TEXT_SUPPORTED) +PNG_EXTERN void png_decompress_chunk PNGARG((png_structp png_ptr, + int comp_type, png_size_t chunklength, png_size_t prefix_length, + png_size_t *data_length)); +#endif + +/* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */ +PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip)); + +/* Read the CRC from the file and compare it to the libpng calculated CRC */ +PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr)); + +/* Calculate the CRC over a section of data. Note that we are only + * passing a maximum of 64K on systems that have this as a memory limit, + * since this is the maximum buffer size we can specify. + */ +PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, + png_const_bytep ptr, png_size_t length)); + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +PNG_EXTERN void png_flush PNGARG((png_structp png_ptr)); +#endif + +/* Write various chunks */ + +/* Write the IHDR chunk, and update the png_struct with the necessary + * information. + */ +PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width, + png_uint_32 height, + int bit_depth, int color_type, int compression_method, int filter_method, + int interlace_method)); + +PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, + png_const_colorp palette, png_uint_32 num_pal)); + +PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data, + png_size_t length)); + +PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr)); + +#ifdef PNG_WRITE_gAMA_SUPPORTED +# ifdef PNG_FLOATING_POINT_SUPPORTED +PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma)); +# endif +# ifdef PNG_FIXED_POINT_SUPPORTED +PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, + png_fixed_point file_gamma)); +# endif +#endif + +#ifdef PNG_WRITE_sBIT_SUPPORTED +PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, + png_const_color_8p sbit, int color_type)); +#endif + +#ifdef PNG_WRITE_cHRM_SUPPORTED +# ifdef PNG_FLOATING_POINT_SUPPORTED +PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr, + double white_x, double white_y, + double red_x, double red_y, double green_x, double green_y, + double blue_x, double blue_y)); +# endif +PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr, + png_fixed_point int_white_x, png_fixed_point int_white_y, + png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point + int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, + png_fixed_point int_blue_y)); +#endif + +#ifdef PNG_WRITE_sRGB_SUPPORTED +PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr, + int intent)); +#endif + +#ifdef PNG_WRITE_iCCP_SUPPORTED +PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr, + png_const_charp name, int compression_type, + png_const_charp profile, int proflen)); + /* Note to maintainer: profile should be png_bytep */ +#endif + +#ifdef PNG_WRITE_sPLT_SUPPORTED +PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr, + png_const_sPLT_tp palette)); +#endif + +#ifdef PNG_WRITE_tRNS_SUPPORTED +PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, + png_const_bytep trans, png_const_color_16p values, int number, + int color_type)); +#endif + +#ifdef PNG_WRITE_bKGD_SUPPORTED +PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr, + png_const_color_16p values, int color_type)); +#endif + +#ifdef PNG_WRITE_hIST_SUPPORTED +PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, + png_const_uint_16p hist, int num_hist)); +#endif + +/* Chunks that have keywords */ +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ + defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) +PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr, + png_const_charp key, png_charpp new_key)); +#endif + +#ifdef PNG_WRITE_tEXt_SUPPORTED +PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_const_charp key, + png_const_charp text, png_size_t text_len)); +#endif + +#ifdef PNG_WRITE_zTXt_SUPPORTED +PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_const_charp key, + png_const_charp text, png_size_t text_len, int compression)); +#endif + +#ifdef PNG_WRITE_iTXt_SUPPORTED +PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr, + int compression, png_const_charp key, png_const_charp lang, + png_const_charp lang_key, png_const_charp text)); +#endif + +#ifdef PNG_TEXT_SUPPORTED /* Added at version 1.0.14 and 1.2.4 */ +PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr, + png_infop info_ptr, png_const_textp text_ptr, int num_text)); +#endif + +#ifdef PNG_WRITE_oFFs_SUPPORTED +PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr, + png_int_32 x_offset, png_int_32 y_offset, int unit_type)); +#endif + +#ifdef PNG_WRITE_pCAL_SUPPORTED +PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose, + png_int_32 X0, png_int_32 X1, int type, int nparams, + png_const_charp units, png_charpp params)); +#endif + +#ifdef PNG_WRITE_pHYs_SUPPORTED +PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr, + png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit, + int unit_type)); +#endif + +#ifdef PNG_WRITE_tIME_SUPPORTED +PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr, + png_const_timep mod_time)); +#endif + +#ifdef PNG_WRITE_sCAL_SUPPORTED +PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr, + int unit, png_const_charp width, png_const_charp height)); +#endif + +/* Called when finished processing a row of data */ +PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr)); + +/* Internal use only. Called before first row of data */ +PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr)); + +/* Combine a row of data, dealing with alpha, etc. if requested. 'row' is an + * array of png_ptr->width pixels. If the image is not interlaced or this + * is the final pass this just does a png_memcpy, otherwise the "display" flag + * is used to determine whether to copy pixels that are not in the current pass. + * + * Because 'png_do_read_interlace' (below) replicates pixels this allows this + * function to achieve the documented 'blocky' appearance during interlaced read + * if display is 1 and the 'sparkle' appearance, where existing pixels in 'row' + * are not changed if they are not in the current pass, when display is 0. + * + * 'display' must be 0 or 1, otherwise the memcpy will be done regardless. + * + * The API always reads from the png_struct row buffer and always assumes that + * it is full width (png_do_read_interlace has already been called.) + * + * This function is only ever used to write to row buffers provided by the + * caller of the relevant libpng API and the row must have already been + * transformed by the read transformations. + * + * The PNG_USE_COMPILE_TIME_MASKS option causes generation of pre-computed + * bitmasks for use within the code, otherwise runtime generated masks are used. + * The default is compile time masks. + */ +#ifndef PNG_USE_COMPILE_TIME_MASKS +# define PNG_USE_COMPILE_TIME_MASKS 1 +#endif +PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row, + int display)); + +#ifdef PNG_READ_INTERLACING_SUPPORTED +/* Expand an interlaced row: the 'row_info' describes the pass data that has + * been read in and must correspond to the pixels in 'row', the pixels are + * expanded (moved apart) in 'row' to match the final layout, when doing this + * the pixels are *replicated* to the intervening space. This is essential for + * the correct operation of png_combine_row, above. + */ +PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info, + png_bytep row, int pass, png_uint_32 transformations)); +#endif + +/* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */ + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED +/* Grab pixels out of a row for an interlaced pass */ +PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info, + png_bytep row, int pass)); +#endif + +/* Unfilter a row: check the filter value before calling this, there is no point + * calling it for PNG_FILTER_VALUE_NONE. + */ +PNG_EXTERN void png_read_filter_row PNGARG((png_structp pp, png_row_infop + row_info, png_bytep row, png_const_bytep prev_row, int filter)); + +PNG_EXTERN void png_read_filter_row_up_neon PNGARG((png_row_infop row_info, + png_bytep row, png_const_bytep prev_row)); +PNG_EXTERN void png_read_filter_row_sub3_neon PNGARG((png_row_infop row_info, + png_bytep row, png_const_bytep prev_row)); +PNG_EXTERN void png_read_filter_row_sub4_neon PNGARG((png_row_infop row_info, + png_bytep row, png_const_bytep prev_row)); +PNG_EXTERN void png_read_filter_row_avg3_neon PNGARG((png_row_infop row_info, + png_bytep row, png_const_bytep prev_row)); +PNG_EXTERN void png_read_filter_row_avg4_neon PNGARG((png_row_infop row_info, + png_bytep row, png_const_bytep prev_row)); +PNG_EXTERN void png_read_filter_row_paeth3_neon PNGARG((png_row_infop row_info, + png_bytep row, png_const_bytep prev_row)); +PNG_EXTERN void png_read_filter_row_paeth4_neon PNGARG((png_row_infop row_info, + png_bytep row, png_const_bytep prev_row)); + +/* Choose the best filter to use and filter the row data */ +PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr, + png_row_infop row_info)); + +/* Finish a row while reading, dealing with interlacing passes, etc. */ +PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr)); + +/* Initialize the row buffers, etc. */ +PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr)); + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED +/* Optional call to update the users info structure */ +PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr, + png_infop info_ptr)); +#endif + +/* These are the functions that do the transformations */ +#ifdef PNG_READ_FILLER_SUPPORTED +PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info, + png_bytep row, png_uint_32 filler, png_uint_32 flags)); +#endif + +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED +PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED +PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED +PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED +PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#if defined(PNG_WRITE_FILLER_SUPPORTED) || \ + defined(PNG_READ_STRIP_ALPHA_SUPPORTED) +PNG_EXTERN void png_do_strip_channel PNGARG((png_row_infop row_info, + png_bytep row, int at_start)); +#endif + +#ifdef PNG_16BIT_SUPPORTED +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, + png_bytep row)); +#endif +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \ + defined(PNG_WRITE_PACKSWAP_SUPPORTED) +PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, + png_row_infop row_info, png_bytep row)); +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_READ_PACK_SUPPORTED +PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_READ_SHIFT_SUPPORTED +PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, + png_bytep row, png_const_color_8p sig_bits)); +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) +PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED +PNG_EXTERN void png_do_scale_16_to_8 PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED +PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED +PNG_EXTERN void png_do_quantize PNGARG((png_row_infop row_info, + png_bytep row, png_const_bytep palette_lookup, + png_const_bytep quantize_lookup)); + +# ifdef PNG_CORRECT_PALETTE_SUPPORTED +PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr, + png_colorp palette, int num_palette)); +# endif +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +#ifdef PNG_WRITE_PACK_SUPPORTED +PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info, + png_bytep row, png_uint_32 bit_depth)); +#endif + +#ifdef PNG_WRITE_SHIFT_SUPPORTED +PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, + png_bytep row, png_const_color_8p bit_depth)); +#endif + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) +PNG_EXTERN void png_do_compose PNGARG((png_row_infop row_info, + png_bytep row, png_structp png_ptr)); +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED +PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, + png_bytep row, png_structp png_ptr)); +#endif + +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED +PNG_EXTERN void png_do_encode_alpha PNGARG((png_row_infop row_info, + png_bytep row, png_structp png_ptr)); +#endif + +#ifdef PNG_READ_EXPAND_SUPPORTED +PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info, + png_bytep row, png_const_colorp palette, png_const_bytep trans, + int num_trans)); +PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info, + png_bytep row, png_const_color_16p trans_color)); +#endif + +#ifdef PNG_READ_EXPAND_16_SUPPORTED +PNG_EXTERN void png_do_expand_16 PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +/* The following decodes the appropriate chunks, and does error correction, + * then calls the appropriate callback for the chunk if it is valid. + */ + +/* Decode the IHDR chunk */ +PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); + +#ifdef PNG_READ_bKGD_SUPPORTED +PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_cHRM_SUPPORTED +PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_gAMA_SUPPORTED +PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_hIST_SUPPORTED +PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_iCCP_SUPPORTED +PNG_EXTERN void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif /* PNG_READ_iCCP_SUPPORTED */ + +#ifdef PNG_READ_iTXt_SUPPORTED +PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_oFFs_SUPPORTED +PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_pCAL_SUPPORTED +PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_pHYs_SUPPORTED +PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_sBIT_SUPPORTED +PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_sCAL_SUPPORTED +PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_sPLT_SUPPORTED +PNG_EXTERN void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif /* PNG_READ_sPLT_SUPPORTED */ + +#ifdef PNG_READ_sRGB_SUPPORTED +PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_tEXt_SUPPORTED +PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_tIME_SUPPORTED +PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_tRNS_SUPPORTED +PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +#ifdef PNG_READ_zTXt_SUPPORTED +PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif + +PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); + +PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr, + png_uint_32 chunk_name)); + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +/* Exactly as png_handle_as_unknown() except that the argument is a 32-bit chunk + * name, not a string. + */ +PNG_EXTERN int png_chunk_unknown_handling PNGARG((png_structp png_ptr, + png_uint_32 chunk_name)); +#endif + +/* Handle the transformations for reading and writing */ +#ifdef PNG_READ_TRANSFORMS_SUPPORTED +PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr, + png_row_infop row_info)); +#endif +#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED +PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr, + png_row_infop row_info)); +#endif + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED +PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr)); +#endif + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr, + png_uint_32 length)); +PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t buffer_length)); +PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t buffer_length)); +PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); +PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row)); +PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr)); +# ifdef PNG_READ_tEXt_SUPPORTED +PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); +PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr, + png_infop info_ptr)); +# endif +# ifdef PNG_READ_zTXt_SUPPORTED +PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); +PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr, + png_infop info_ptr)); +# endif +# ifdef PNG_READ_iTXt_SUPPORTED +PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)); +PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr, + png_infop info_ptr)); +# endif + +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ + +#ifdef PNG_MNG_FEATURES_SUPPORTED +PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info, + png_bytep row)); +PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info, + png_bytep row)); +#endif + +/* Added at libpng version 1.4.0 */ +#ifdef PNG_CHECK_cHRM_SUPPORTED +PNG_EXTERN int png_check_cHRM_fixed PNGARG((png_structp png_ptr, + png_fixed_point int_white_x, png_fixed_point int_white_y, + png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point + int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, + png_fixed_point int_blue_y)); +#endif + +#ifdef PNG_CHECK_cHRM_SUPPORTED +/* Added at libpng version 1.2.34 and 1.4.0 */ +/* Currently only used by png_check_cHRM_fixed */ +PNG_EXTERN void png_64bit_product PNGARG((long v1, long v2, + unsigned long *hi_product, unsigned long *lo_product)); +#endif + +#ifdef PNG_cHRM_SUPPORTED +/* Added at libpng version 1.5.5 */ +typedef struct png_xy +{ + png_fixed_point redx, redy; + png_fixed_point greenx, greeny; + png_fixed_point bluex, bluey; + png_fixed_point whitex, whitey; +} png_xy; + +typedef struct png_XYZ +{ + png_fixed_point redX, redY, redZ; + png_fixed_point greenX, greenY, greenZ; + png_fixed_point blueX, blueY, blueZ; +} png_XYZ; + +/* The conversion APIs return 0 on success, non-zero on a parameter error. They + * allow conversion between the above representations of a color encoding. When + * converting from XYZ end points to chromaticities the absolute magnitude of + * the end points is lost, when converting back the sum of the Y values of the + * three end points will be 1.0 + */ +PNG_EXTERN int png_xy_from_XYZ PNGARG((png_xy *xy, png_XYZ XYZ)); +PNG_EXTERN int png_XYZ_from_xy PNGARG((png_XYZ *XYZ, png_xy xy)); +PNG_EXTERN int png_XYZ_from_xy_checked PNGARG((png_structp png_ptr, + png_XYZ *XYZ, png_xy xy)); +#endif + +/* Added at libpng version 1.4.0 */ +PNG_EXTERN void png_check_IHDR PNGARG((png_structp png_ptr, + png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_type, int compression_type, + int filter_type)); + +/* Added at libpng version 1.5.10 */ +#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \ + defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED) +PNG_EXTERN void png_do_check_palette_indexes PNGARG((png_structp png_ptr, + png_row_infop row_info)); +#endif + +/* Free all memory used by the read (old method - NOT DLL EXPORTED) */ +PNG_EXTERN void png_read_destroy PNGARG((png_structp png_ptr, + png_infop info_ptr, png_infop end_info_ptr)); + +/* Free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */ +PNG_EXTERN void png_write_destroy PNGARG((png_structp png_ptr)); + +#ifdef USE_FAR_KEYWORD /* memory model conversion function */ +PNG_EXTERN void *png_far_to_near PNGARG((png_structp png_ptr, png_voidp ptr, + int check)); +#endif /* USE_FAR_KEYWORD */ + +#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) +PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_structp png_ptr, + png_const_charp name),PNG_NORETURN); +#endif + +/* Puts 'string' into 'buffer' at buffer[pos], taking care never to overwrite + * the end. Always leaves the buffer nul terminated. Never errors out (and + * there is no error code.) + */ +PNG_EXTERN size_t png_safecat(png_charp buffer, size_t bufsize, size_t pos, + png_const_charp string); + +/* Various internal functions to handle formatted warning messages, currently + * only implemented for warnings. + */ +#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED) +/* Utility to dump an unsigned value into a buffer, given a start pointer and + * and end pointer (which should point just *beyond* the end of the buffer!) + * Returns the pointer to the start of the formatted string. This utility only + * does unsigned values. + */ +PNG_EXTERN png_charp png_format_number(png_const_charp start, png_charp end, + int format, png_alloc_size_t number); + +/* Convenience macro that takes an array: */ +#define PNG_FORMAT_NUMBER(buffer,format,number) \ + png_format_number(buffer, buffer + (sizeof buffer), format, number) + +/* Suggested size for a number buffer (enough for 64 bits and a sign!) */ +#define PNG_NUMBER_BUFFER_SIZE 24 + +/* These are the integer formats currently supported, the name is formed from + * the standard printf(3) format string. + */ +#define PNG_NUMBER_FORMAT_u 1 /* chose unsigned API! */ +#define PNG_NUMBER_FORMAT_02u 2 +#define PNG_NUMBER_FORMAT_d 1 /* chose signed API! */ +#define PNG_NUMBER_FORMAT_02d 2 +#define PNG_NUMBER_FORMAT_x 3 +#define PNG_NUMBER_FORMAT_02x 4 +#define PNG_NUMBER_FORMAT_fixed 5 /* choose the signed API */ +#endif + +#ifdef PNG_WARNINGS_SUPPORTED +/* New defines and members adding in libpng-1.5.4 */ +# define PNG_WARNING_PARAMETER_SIZE 32 +# define PNG_WARNING_PARAMETER_COUNT 8 + +/* An l-value of this type has to be passed to the APIs below to cache the + * values of the parameters to a formatted warning message. + */ +typedef char png_warning_parameters[PNG_WARNING_PARAMETER_COUNT][ + PNG_WARNING_PARAMETER_SIZE]; + +PNG_EXTERN void png_warning_parameter(png_warning_parameters p, int number, + png_const_charp string); + /* Parameters are limited in size to PNG_WARNING_PARAMETER_SIZE characters, + * including the trailing '\0'. + */ +PNG_EXTERN void png_warning_parameter_unsigned(png_warning_parameters p, + int number, int format, png_alloc_size_t value); + /* Use png_alloc_size_t because it is an unsigned type as big as any we + * need to output. Use the following for a signed value. + */ +PNG_EXTERN void png_warning_parameter_signed(png_warning_parameters p, + int number, int format, png_int_32 value); + +PNG_EXTERN void png_formatted_warning(png_structp png_ptr, + png_warning_parameters p, png_const_charp message); + /* 'message' follows the X/Open approach of using @1, @2 to insert + * parameters previously supplied using the above functions. Errors in + * specifying the paramters will simple result in garbage substitutions. + */ +#endif + +/* ASCII to FP interfaces, currently only implemented if sCAL + * support is required. + */ +#if defined(PNG_READ_sCAL_SUPPORTED) +/* MAX_DIGITS is actually the maximum number of characters in an sCAL + * width or height, derived from the precision (number of significant + * digits - a build time settable option) and assumpitions about the + * maximum ridiculous exponent. + */ +#define PNG_sCAL_MAX_DIGITS (PNG_sCAL_PRECISION+1/*.*/+1/*E*/+10/*exponent*/) + +#ifdef PNG_FLOATING_POINT_SUPPORTED +PNG_EXTERN void png_ascii_from_fp PNGARG((png_structp png_ptr, png_charp ascii, + png_size_t size, double fp, unsigned int precision)); +#endif /* FLOATING_POINT */ + +#ifdef PNG_FIXED_POINT_SUPPORTED +PNG_EXTERN void png_ascii_from_fixed PNGARG((png_structp png_ptr, + png_charp ascii, png_size_t size, png_fixed_point fp)); +#endif /* FIXED_POINT */ +#endif /* READ_sCAL */ + +#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) +/* An internal API to validate the format of a floating point number. + * The result is the index of the next character. If the number is + * not valid it will be the index of a character in the supposed number. + * + * The format of a number is defined in the PNG extensions specification + * and this API is strictly conformant to that spec, not anyone elses! + * + * The format as a regular expression is: + * + * [+-]?[0-9]+.?([Ee][+-]?[0-9]+)? + * + * or: + * + * [+-]?.[0-9]+(.[0-9]+)?([Ee][+-]?[0-9]+)? + * + * The complexity is that either integer or fraction must be present and the + * fraction is permitted to have no digits only if the integer is present. + * + * NOTE: The dangling E problem. + * There is a PNG valid floating point number in the following: + * + * PNG floating point numb1.ers are not greedy. + * + * Working this out requires *TWO* character lookahead (because of the + * sign), the parser does not do this - it will fail at the 'r' - this + * doesn't matter for PNG sCAL chunk values, but it requires more care + * if the value were ever to be embedded in something more complex. Use + * ANSI-C strtod if you need the lookahead. + */ +/* State table for the parser. */ +#define PNG_FP_INTEGER 0 /* before or in integer */ +#define PNG_FP_FRACTION 1 /* before or in fraction */ +#define PNG_FP_EXPONENT 2 /* before or in exponent */ +#define PNG_FP_STATE 3 /* mask for the above */ +#define PNG_FP_SAW_SIGN 4 /* Saw +/- in current state */ +#define PNG_FP_SAW_DIGIT 8 /* Saw a digit in current state */ +#define PNG_FP_SAW_DOT 16 /* Saw a dot in current state */ +#define PNG_FP_SAW_E 32 /* Saw an E (or e) in current state */ +#define PNG_FP_SAW_ANY 60 /* Saw any of the above 4 */ + +/* These three values don't affect the parser. They are set but not used. + */ +#define PNG_FP_WAS_VALID 64 /* Preceding substring is a valid fp number */ +#define PNG_FP_NEGATIVE 128 /* A negative number, including "-0" */ +#define PNG_FP_NONZERO 256 /* A non-zero value */ +#define PNG_FP_STICKY 448 /* The above three flags */ + +/* This is available for the caller to store in 'state' if required. Do not + * call the parser after setting it (the parser sometimes clears it.) + */ +#define PNG_FP_INVALID 512 /* Available for callers as a distinct value */ + +/* Result codes for the parser (boolean - true meants ok, false means + * not ok yet.) + */ +#define PNG_FP_MAYBE 0 /* The number may be valid in the future */ +#define PNG_FP_OK 1 /* The number is valid */ + +/* Tests on the sticky non-zero and negative flags. To pass these checks + * the state must also indicate that the whole number is valid - this is + * achieved by testing PNG_FP_SAW_DIGIT (see the implementation for why this + * is equivalent to PNG_FP_OK above.) + */ +#define PNG_FP_NZ_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NEGATIVE | PNG_FP_NONZERO) + /* NZ_MASK: the string is valid and a non-zero negative value */ +#define PNG_FP_Z_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NONZERO) + /* Z MASK: the string is valid and a non-zero value. */ + /* PNG_FP_SAW_DIGIT: the string is valid. */ +#define PNG_FP_IS_ZERO(state) (((state) & PNG_FP_Z_MASK) == PNG_FP_SAW_DIGIT) +#define PNG_FP_IS_POSITIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_Z_MASK) +#define PNG_FP_IS_NEGATIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_NZ_MASK) + +/* The actual parser. This can be called repeatedly, it updates + * the index into the string and the state variable (which must + * be initialzed to 0). It returns a result code, as above. There + * is no point calling the parser any more if it fails to advance to + * the end of the string - it is stuck on an invalid character (or + * terminated by '\0'). + * + * Note that the pointer will consume an E or even an E+ then leave + * a 'maybe' state even though a preceding integer.fraction is valid. + * The PNG_FP_WAS_VALID flag indicates that a preceding substring was + * a valid number. It's possible to recover from this by calling + * the parser again (from the start, with state 0) but with a string + * that omits the last character (i.e. set the size to the index of + * the problem character.) This has not been tested within libpng. + */ +PNG_EXTERN int png_check_fp_number PNGARG((png_const_charp string, + png_size_t size, int *statep, png_size_tp whereami)); + +/* This is the same but it checks a complete string and returns true + * only if it just contains a floating point number. As of 1.5.4 this + * function also returns the state at the end of parsing the number if + * it was valid (otherwise it returns 0.) This can be used for testing + * for negative or zero values using the sticky flag. + */ +PNG_EXTERN int png_check_fp_string PNGARG((png_const_charp string, + png_size_t size)); +#endif /* pCAL || sCAL */ + +#if defined(PNG_READ_GAMMA_SUPPORTED) ||\ + defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED) +/* Added at libpng version 1.5.0 */ +/* This is a utility to provide a*times/div (rounded) and indicate + * if there is an overflow. The result is a boolean - false (0) + * for overflow, true (1) if no overflow, in which case *res + * holds the result. + */ +PNG_EXTERN int png_muldiv PNGARG((png_fixed_point_p res, png_fixed_point a, + png_int_32 multiplied_by, png_int_32 divided_by)); +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED) +/* Same deal, but issue a warning on overflow and return 0. */ +PNG_EXTERN png_fixed_point png_muldiv_warn PNGARG((png_structp png_ptr, + png_fixed_point a, png_int_32 multiplied_by, png_int_32 divided_by)); +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED +/* Calculate a reciprocal - used for gamma values. This returns + * 0 if the argument is 0 in order to maintain an undefined value, + * there are no warnings. + */ +PNG_EXTERN png_fixed_point png_reciprocal PNGARG((png_fixed_point a)); + +/* The same but gives a reciprocal of the product of two fixed point + * values. Accuracy is suitable for gamma calculations but this is + * not exact - use png_muldiv for that. + */ +PNG_EXTERN png_fixed_point png_reciprocal2 PNGARG((png_fixed_point a, + png_fixed_point b)); +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED +/* Internal fixed point gamma correction. These APIs are called as + * required to convert single values - they don't need to be fast, + * they are not used when processing image pixel values. + * + * While the input is an 'unsigned' value it must actually be the + * correct bit value - 0..255 or 0..65535 as required. + */ +PNG_EXTERN png_uint_16 png_gamma_correct PNGARG((png_structp png_ptr, + unsigned int value, png_fixed_point gamma_value)); +PNG_EXTERN int png_gamma_significant PNGARG((png_fixed_point gamma_value)); +PNG_EXTERN png_uint_16 png_gamma_16bit_correct PNGARG((unsigned int value, + png_fixed_point gamma_value)); +PNG_EXTERN png_byte png_gamma_8bit_correct PNGARG((unsigned int value, + png_fixed_point gamma_value)); +PNG_EXTERN void png_destroy_gamma_table(png_structp png_ptr); +PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr, + int bit_depth)); +#endif + +/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ + +#include "pngdebug.h" + +#ifdef __cplusplus +} +#endif + +#endif /* PNGPRIV_H */ diff --git a/Source/LibPNG/pngread.c b/Source/LibPNG/pngread.c index 96a2a56..1d8c6b3 100644 --- a/Source/LibPNG/pngread.c +++ b/Source/LibPNG/pngread.c @@ -1,1305 +1,1305 @@ - -/* pngread.c - read a PNG file - * - * Last changed in libpng 1.5.10 [March 8, 2012] - * Copyright (c) 1998-2012 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - * - * This file contains routines that an application calls directly to - * read a PNG file or stream. - */ - -#include "pngpriv.h" - -#ifdef PNG_READ_SUPPORTED - -/* Create a PNG structure for reading, and allocate any memory needed. */ -PNG_FUNCTION(png_structp,PNGAPI -png_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED) -{ - -#ifdef PNG_USER_MEM_SUPPORTED - return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn, - warn_fn, NULL, NULL, NULL)); -} - -/* Alternate create PNG structure for reading, and allocate any memory - * needed. - */ -PNG_FUNCTION(png_structp,PNGAPI -png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, - png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED) -{ -#endif /* PNG_USER_MEM_SUPPORTED */ - -#ifdef PNG_SETJMP_SUPPORTED - volatile -#endif - png_structp png_ptr; - volatile int png_cleanup_needed = 0; - -#ifdef PNG_SETJMP_SUPPORTED -#ifdef USE_FAR_KEYWORD - jmp_buf tmp_jmpbuf; -#endif -#endif - - png_debug(1, "in png_create_read_struct"); - -#ifdef PNG_USER_MEM_SUPPORTED - png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, - malloc_fn, mem_ptr); -#else - png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); -#endif - if (png_ptr == NULL) - return (NULL); - - /* Added at libpng-1.2.6 */ -#ifdef PNG_USER_LIMITS_SUPPORTED - png_ptr->user_width_max = PNG_USER_WIDTH_MAX; - png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; - - /* Added at libpng-1.2.43 and 1.4.0 */ - png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; - - /* Added at libpng-1.2.43 and 1.4.1 */ - png_ptr->user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX; -#endif - -#ifdef PNG_SETJMP_SUPPORTED -/* Applications that neglect to set up their own setjmp() and then - * encounter a png_error() will longjmp here. Since the jmpbuf is - * then meaningless we abort instead of returning. - */ -#ifdef USE_FAR_KEYWORD - if (setjmp(tmp_jmpbuf)) -#else - if (setjmp(png_jmpbuf(png_ptr))) /* Sets longjmp to match setjmp */ -#endif - PNG_ABORT(); -#ifdef USE_FAR_KEYWORD - png_memcpy(png_jmpbuf(png_ptr), tmp_jmpbuf, png_sizeof(jmp_buf)); -#endif -#endif /* PNG_SETJMP_SUPPORTED */ - -#ifdef PNG_USER_MEM_SUPPORTED - png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); -#endif - - png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); - - /* Call the general version checker (shared with read and write code): */ - if (!png_user_version_check(png_ptr, user_png_ver)) - png_cleanup_needed = 1; - - if (!png_cleanup_needed) - { - /* Initialize zbuf - compression buffer */ - png_ptr->zbuf_size = PNG_ZBUF_SIZE; - png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, png_ptr->zbuf_size); - - if (png_ptr->zbuf == NULL) - png_cleanup_needed = 1; - } - - png_ptr->zstream.zalloc = png_zalloc; - png_ptr->zstream.zfree = png_zfree; - png_ptr->zstream.opaque = (voidpf)png_ptr; - - if (!png_cleanup_needed) - { - switch (inflateInit(&png_ptr->zstream)) - { - case Z_OK: - break; /* Do nothing */ - - case Z_MEM_ERROR: - png_warning(png_ptr, "zlib memory error"); - png_cleanup_needed = 1; - break; - - case Z_STREAM_ERROR: - png_warning(png_ptr, "zlib stream error"); - png_cleanup_needed = 1; - break; - - case Z_VERSION_ERROR: - png_warning(png_ptr, "zlib version error"); - png_cleanup_needed = 1; - break; - - default: png_warning(png_ptr, "Unknown zlib error"); - png_cleanup_needed = 1; - } - } - - if (png_cleanup_needed) - { - /* Clean up PNG structure and deallocate any memory. */ - png_free(png_ptr, png_ptr->zbuf); - png_ptr->zbuf = NULL; -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)png_ptr, - (png_free_ptr)free_fn, (png_voidp)mem_ptr); -#else - png_destroy_struct((png_voidp)png_ptr); -#endif - return (NULL); - } - - png_ptr->zstream.next_out = png_ptr->zbuf; - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - - png_set_read_fn(png_ptr, NULL, NULL); - - - return (png_ptr); -} - - -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED -/* Read the information before the actual image data. This has been - * changed in v0.90 to allow reading a file that already has the magic - * bytes read from the stream. You can tell libpng how many bytes have - * been read from the beginning of the stream (up to the maximum of 8) - * via png_set_sig_bytes(), and we will only check the remaining bytes - * here. The application can then have access to the signature bytes we - * read if it is determined that this isn't a valid PNG file. - */ -void PNGAPI -png_read_info(png_structp png_ptr, png_infop info_ptr) -{ - png_debug(1, "in png_read_info"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - /* Read and check the PNG file signature. */ - png_read_sig(png_ptr, info_ptr); - - for (;;) - { - png_uint_32 length = png_read_chunk_header(png_ptr); - png_uint_32 chunk_name = png_ptr->chunk_name; - - /* This should be a binary subdivision search or a hash for - * matching the chunk name rather than a linear search. - */ - if (chunk_name == png_IDAT) - if (png_ptr->mode & PNG_AFTER_IDAT) - png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; - - if (chunk_name == png_IHDR) - png_handle_IHDR(png_ptr, info_ptr, length); - - else if (chunk_name == png_IEND) - png_handle_IEND(png_ptr, info_ptr, length); - -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - else if (png_chunk_unknown_handling(png_ptr, chunk_name) != - PNG_HANDLE_CHUNK_AS_DEFAULT) - { - if (chunk_name == png_IDAT) - png_ptr->mode |= PNG_HAVE_IDAT; - - png_handle_unknown(png_ptr, info_ptr, length); - - if (chunk_name == png_PLTE) - png_ptr->mode |= PNG_HAVE_PLTE; - - else if (chunk_name == png_IDAT) - { - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before IDAT"); - - else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && - !(png_ptr->mode & PNG_HAVE_PLTE)) - png_error(png_ptr, "Missing PLTE before IDAT"); - - break; - } - } -#endif - else if (chunk_name == png_PLTE) - png_handle_PLTE(png_ptr, info_ptr, length); - - else if (chunk_name == png_IDAT) - { - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before IDAT"); - - else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && - !(png_ptr->mode & PNG_HAVE_PLTE)) - png_error(png_ptr, "Missing PLTE before IDAT"); - - png_ptr->idat_size = length; - png_ptr->mode |= PNG_HAVE_IDAT; - break; - } - -#ifdef PNG_READ_bKGD_SUPPORTED - else if (chunk_name == png_bKGD) - png_handle_bKGD(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_cHRM_SUPPORTED - else if (chunk_name == png_cHRM) - png_handle_cHRM(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_gAMA_SUPPORTED - else if (chunk_name == png_gAMA) - png_handle_gAMA(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_hIST_SUPPORTED - else if (chunk_name == png_hIST) - png_handle_hIST(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_oFFs_SUPPORTED - else if (chunk_name == png_oFFs) - png_handle_oFFs(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_pCAL_SUPPORTED - else if (chunk_name == png_pCAL) - png_handle_pCAL(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_sCAL_SUPPORTED - else if (chunk_name == png_sCAL) - png_handle_sCAL(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_pHYs_SUPPORTED - else if (chunk_name == png_pHYs) - png_handle_pHYs(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_sBIT_SUPPORTED - else if (chunk_name == png_sBIT) - png_handle_sBIT(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_sRGB_SUPPORTED - else if (chunk_name == png_sRGB) - png_handle_sRGB(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_iCCP_SUPPORTED - else if (chunk_name == png_iCCP) - png_handle_iCCP(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_sPLT_SUPPORTED - else if (chunk_name == png_sPLT) - png_handle_sPLT(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_tEXt_SUPPORTED - else if (chunk_name == png_tEXt) - png_handle_tEXt(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_tIME_SUPPORTED - else if (chunk_name == png_tIME) - png_handle_tIME(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_tRNS_SUPPORTED - else if (chunk_name == png_tRNS) - png_handle_tRNS(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_zTXt_SUPPORTED - else if (chunk_name == png_zTXt) - png_handle_zTXt(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_iTXt_SUPPORTED - else if (chunk_name == png_iTXt) - png_handle_iTXt(png_ptr, info_ptr, length); -#endif - - else - png_handle_unknown(png_ptr, info_ptr, length); - } -} -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ - -/* Optional call to update the users info_ptr structure */ -void PNGAPI -png_read_update_info(png_structp png_ptr, png_infop info_ptr) -{ - png_debug(1, "in png_read_update_info"); - - if (png_ptr == NULL) - return; - - png_read_start_row(png_ptr); - -#ifdef PNG_READ_TRANSFORMS_SUPPORTED - png_read_transform_info(png_ptr, info_ptr); -#else - PNG_UNUSED(info_ptr) -#endif -} - -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED -/* Initialize palette, background, etc, after transformations - * are set, but before any reading takes place. This allows - * the user to obtain a gamma-corrected palette, for example. - * If the user doesn't call this, we will do it ourselves. - */ -void PNGAPI -png_start_read_image(png_structp png_ptr) -{ - png_debug(1, "in png_start_read_image"); - - if (png_ptr != NULL) - png_read_start_row(png_ptr); -} -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ - -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED -void PNGAPI -png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) -{ - int ret; - - png_row_info row_info; - - if (png_ptr == NULL) - return; - - png_debug2(1, "in png_read_row (row %lu, pass %d)", - (unsigned long)png_ptr->row_number, png_ptr->pass); - - /* png_read_start_row sets the information (in particular iwidth) for this - * interlace pass. - */ - if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) - png_read_start_row(png_ptr); - - /* 1.5.6: row_info moved out of png_struct to a local here. */ - row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */ - row_info.color_type = png_ptr->color_type; - row_info.bit_depth = png_ptr->bit_depth; - row_info.channels = png_ptr->channels; - row_info.pixel_depth = png_ptr->pixel_depth; - row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); - - if (png_ptr->row_number == 0 && png_ptr->pass == 0) - { - /* Check for transforms that have been set but were defined out */ -#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) - if (png_ptr->transformations & PNG_INVERT_MONO) - png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined"); -#endif - -#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED) - if (png_ptr->transformations & PNG_FILLER) - png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined"); -#endif - -#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \ - !defined(PNG_READ_PACKSWAP_SUPPORTED) - if (png_ptr->transformations & PNG_PACKSWAP) - png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined"); -#endif - -#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED) - if (png_ptr->transformations & PNG_PACK) - png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined"); -#endif - -#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) - if (png_ptr->transformations & PNG_SHIFT) - png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined"); -#endif - -#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED) - if (png_ptr->transformations & PNG_BGR) - png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined"); -#endif - -#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED) - if (png_ptr->transformations & PNG_SWAP_BYTES) - png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined"); -#endif - } - -#ifdef PNG_READ_INTERLACING_SUPPORTED - /* If interlaced and we do not need a new row, combine row and return. - * Notice that the pixels we have from previous rows have been transformed - * already; we can only combine like with like (transformed or - * untransformed) and, because of the libpng API for interlaced images, this - * means we must transform before de-interlacing. - */ - if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) - { - switch (png_ptr->pass) - { - case 0: - if (png_ptr->row_number & 0x07) - { - if (dsp_row != NULL) - png_combine_row(png_ptr, dsp_row, 1/*display*/); - png_read_finish_row(png_ptr); - return; - } - break; - - case 1: - if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) - { - if (dsp_row != NULL) - png_combine_row(png_ptr, dsp_row, 1/*display*/); - - png_read_finish_row(png_ptr); - return; - } - break; - - case 2: - if ((png_ptr->row_number & 0x07) != 4) - { - if (dsp_row != NULL && (png_ptr->row_number & 4)) - png_combine_row(png_ptr, dsp_row, 1/*display*/); - - png_read_finish_row(png_ptr); - return; - } - break; - - case 3: - if ((png_ptr->row_number & 3) || png_ptr->width < 3) - { - if (dsp_row != NULL) - png_combine_row(png_ptr, dsp_row, 1/*display*/); - - png_read_finish_row(png_ptr); - return; - } - break; - - case 4: - if ((png_ptr->row_number & 3) != 2) - { - if (dsp_row != NULL && (png_ptr->row_number & 2)) - png_combine_row(png_ptr, dsp_row, 1/*display*/); - - png_read_finish_row(png_ptr); - return; - } - break; - case 5: - if ((png_ptr->row_number & 1) || png_ptr->width < 2) - { - if (dsp_row != NULL) - png_combine_row(png_ptr, dsp_row, 1/*display*/); - - png_read_finish_row(png_ptr); - return; - } - break; - - default: - case 6: - if (!(png_ptr->row_number & 1)) - { - png_read_finish_row(png_ptr); - return; - } - break; - } - } -#endif - - if (!(png_ptr->mode & PNG_HAVE_IDAT)) - png_error(png_ptr, "Invalid attempt to read row data"); - - png_ptr->zstream.next_out = png_ptr->row_buf; - png_ptr->zstream.avail_out = - (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth, - png_ptr->iwidth) + 1); - - do - { - if (!(png_ptr->zstream.avail_in)) - { - while (!png_ptr->idat_size) - { - png_crc_finish(png_ptr, 0); - - png_ptr->idat_size = png_read_chunk_header(png_ptr); - if (png_ptr->chunk_name != png_IDAT) - png_error(png_ptr, "Not enough image data"); - } - png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; - png_ptr->zstream.next_in = png_ptr->zbuf; - if (png_ptr->zbuf_size > png_ptr->idat_size) - png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; - png_crc_read(png_ptr, png_ptr->zbuf, - (png_size_t)png_ptr->zstream.avail_in); - png_ptr->idat_size -= png_ptr->zstream.avail_in; - } - - ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); - - if (ret == Z_STREAM_END) - { - if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in || - png_ptr->idat_size) - png_benign_error(png_ptr, "Extra compressed data"); - png_ptr->mode |= PNG_AFTER_IDAT; - png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; - break; - } - - if (ret != Z_OK) - png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg : - "Decompression error"); - - } while (png_ptr->zstream.avail_out); - - if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) - { - if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) - png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1, - png_ptr->prev_row + 1, png_ptr->row_buf[0]); - else - png_error(png_ptr, "bad adaptive filter value"); - } - - /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before - * 1.5.6, while the buffer really is this big in current versions of libpng - * it may not be in the future, so this was changed just to copy the - * interlaced count: - */ - png_memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1); - -#ifdef PNG_MNG_FEATURES_SUPPORTED - if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && - (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) - { - /* Intrapixel differencing */ - png_do_read_intrapixel(&row_info, png_ptr->row_buf + 1); - } -#endif - - -#ifdef PNG_READ_TRANSFORMS_SUPPORTED - if (png_ptr->transformations) - png_do_read_transformations(png_ptr, &row_info); -#endif - - /* The transformed pixel depth should match the depth now in row_info. */ - if (png_ptr->transformed_pixel_depth == 0) - { - png_ptr->transformed_pixel_depth = row_info.pixel_depth; - if (row_info.pixel_depth > png_ptr->maximum_pixel_depth) - png_error(png_ptr, "sequential row overflow"); - } - - else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth) - png_error(png_ptr, "internal sequential row size calculation error"); - -#ifdef PNG_READ_INTERLACING_SUPPORTED - /* Blow up interlaced rows to full size */ - if (png_ptr->interlaced && - (png_ptr->transformations & PNG_INTERLACE)) - { - if (png_ptr->pass < 6) - png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass, - png_ptr->transformations); - - if (dsp_row != NULL) - png_combine_row(png_ptr, dsp_row, 1/*display*/); - - if (row != NULL) - png_combine_row(png_ptr, row, 0/*row*/); - } - - else -#endif - { - if (row != NULL) - png_combine_row(png_ptr, row, -1/*ignored*/); - - if (dsp_row != NULL) - png_combine_row(png_ptr, dsp_row, -1/*ignored*/); - } - png_read_finish_row(png_ptr); - - if (png_ptr->read_row_fn != NULL) - (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); -} -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ - -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED -/* Read one or more rows of image data. If the image is interlaced, - * and png_set_interlace_handling() has been called, the rows need to - * contain the contents of the rows from the previous pass. If the - * image has alpha or transparency, and png_handle_alpha()[*] has been - * called, the rows contents must be initialized to the contents of the - * screen. - * - * "row" holds the actual image, and pixels are placed in it - * as they arrive. If the image is displayed after each pass, it will - * appear to "sparkle" in. "display_row" can be used to display a - * "chunky" progressive image, with finer detail added as it becomes - * available. If you do not want this "chunky" display, you may pass - * NULL for display_row. If you do not want the sparkle display, and - * you have not called png_handle_alpha(), you may pass NULL for rows. - * If you have called png_handle_alpha(), and the image has either an - * alpha channel or a transparency chunk, you must provide a buffer for - * rows. In this case, you do not have to provide a display_row buffer - * also, but you may. If the image is not interlaced, or if you have - * not called png_set_interlace_handling(), the display_row buffer will - * be ignored, so pass NULL to it. - * - * [*] png_handle_alpha() does not exist yet, as of this version of libpng - */ - -void PNGAPI -png_read_rows(png_structp png_ptr, png_bytepp row, - png_bytepp display_row, png_uint_32 num_rows) -{ - png_uint_32 i; - png_bytepp rp; - png_bytepp dp; - - png_debug(1, "in png_read_rows"); - - if (png_ptr == NULL) - return; - - rp = row; - dp = display_row; - if (rp != NULL && dp != NULL) - for (i = 0; i < num_rows; i++) - { - png_bytep rptr = *rp++; - png_bytep dptr = *dp++; - - png_read_row(png_ptr, rptr, dptr); - } - - else if (rp != NULL) - for (i = 0; i < num_rows; i++) - { - png_bytep rptr = *rp; - png_read_row(png_ptr, rptr, NULL); - rp++; - } - - else if (dp != NULL) - for (i = 0; i < num_rows; i++) - { - png_bytep dptr = *dp; - png_read_row(png_ptr, NULL, dptr); - dp++; - } -} -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ - -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED -/* Read the entire image. If the image has an alpha channel or a tRNS - * chunk, and you have called png_handle_alpha()[*], you will need to - * initialize the image to the current image that PNG will be overlaying. - * We set the num_rows again here, in case it was incorrectly set in - * png_read_start_row() by a call to png_read_update_info() or - * png_start_read_image() if png_set_interlace_handling() wasn't called - * prior to either of these functions like it should have been. You can - * only call this function once. If you desire to have an image for - * each pass of a interlaced image, use png_read_rows() instead. - * - * [*] png_handle_alpha() does not exist yet, as of this version of libpng - */ -void PNGAPI -png_read_image(png_structp png_ptr, png_bytepp image) -{ - png_uint_32 i, image_height; - int pass, j; - png_bytepp rp; - - png_debug(1, "in png_read_image"); - - if (png_ptr == NULL) - return; - -#ifdef PNG_READ_INTERLACING_SUPPORTED - if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) - { - pass = png_set_interlace_handling(png_ptr); - /* And make sure transforms are initialized. */ - png_start_read_image(png_ptr); - } - else - { - if (png_ptr->interlaced && !(png_ptr->transformations & PNG_INTERLACE)) - { - /* Caller called png_start_read_image or png_read_update_info without - * first turning on the PNG_INTERLACE transform. We can fix this here, - * but the caller should do it! - */ - png_warning(png_ptr, "Interlace handling should be turned on when " - "using png_read_image"); - /* Make sure this is set correctly */ - png_ptr->num_rows = png_ptr->height; - } - - /* Obtain the pass number, which also turns on the PNG_INTERLACE flag in - * the above error case. - */ - pass = png_set_interlace_handling(png_ptr); - } -#else - if (png_ptr->interlaced) - png_error(png_ptr, - "Cannot read interlaced image -- interlace handler disabled"); - - pass = 1; -#endif - - image_height=png_ptr->height; - - for (j = 0; j < pass; j++) - { - rp = image; - for (i = 0; i < image_height; i++) - { - png_read_row(png_ptr, *rp, NULL); - rp++; - } - } -} -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ - -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED -/* Read the end of the PNG file. Will not read past the end of the - * file, will verify the end is accurate, and will read any comments - * or time information at the end of the file, if info is not NULL. - */ -void PNGAPI -png_read_end(png_structp png_ptr, png_infop info_ptr) -{ - png_debug(1, "in png_read_end"); - - if (png_ptr == NULL) - return; - - png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ - -#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED - /* Report invalid palette index; added at libng-1.5.10 */ - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && - png_ptr->num_palette_max > png_ptr->num_palette) - png_benign_error(png_ptr, "Read palette index exceeding num_palette"); -#endif - - do - { - png_uint_32 length = png_read_chunk_header(png_ptr); - png_uint_32 chunk_name = png_ptr->chunk_name; - - if (chunk_name == png_IHDR) - png_handle_IHDR(png_ptr, info_ptr, length); - - else if (chunk_name == png_IEND) - png_handle_IEND(png_ptr, info_ptr, length); - -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - else if (png_chunk_unknown_handling(png_ptr, chunk_name) != - PNG_HANDLE_CHUNK_AS_DEFAULT) - { - if (chunk_name == png_IDAT) - { - if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) - png_benign_error(png_ptr, "Too many IDATs found"); - } - png_handle_unknown(png_ptr, info_ptr, length); - if (chunk_name == png_PLTE) - png_ptr->mode |= PNG_HAVE_PLTE; - } -#endif - - else if (chunk_name == png_IDAT) - { - /* Zero length IDATs are legal after the last IDAT has been - * read, but not after other chunks have been read. - */ - if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) - png_benign_error(png_ptr, "Too many IDATs found"); - - png_crc_finish(png_ptr, length); - } - else if (chunk_name == png_PLTE) - png_handle_PLTE(png_ptr, info_ptr, length); - -#ifdef PNG_READ_bKGD_SUPPORTED - else if (chunk_name == png_bKGD) - png_handle_bKGD(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_cHRM_SUPPORTED - else if (chunk_name == png_cHRM) - png_handle_cHRM(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_gAMA_SUPPORTED - else if (chunk_name == png_gAMA) - png_handle_gAMA(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_hIST_SUPPORTED - else if (chunk_name == png_hIST) - png_handle_hIST(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_oFFs_SUPPORTED - else if (chunk_name == png_oFFs) - png_handle_oFFs(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_pCAL_SUPPORTED - else if (chunk_name == png_pCAL) - png_handle_pCAL(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_sCAL_SUPPORTED - else if (chunk_name == png_sCAL) - png_handle_sCAL(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_pHYs_SUPPORTED - else if (chunk_name == png_pHYs) - png_handle_pHYs(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_sBIT_SUPPORTED - else if (chunk_name == png_sBIT) - png_handle_sBIT(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_sRGB_SUPPORTED - else if (chunk_name == png_sRGB) - png_handle_sRGB(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_iCCP_SUPPORTED - else if (chunk_name == png_iCCP) - png_handle_iCCP(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_sPLT_SUPPORTED - else if (chunk_name == png_sPLT) - png_handle_sPLT(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_tEXt_SUPPORTED - else if (chunk_name == png_tEXt) - png_handle_tEXt(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_tIME_SUPPORTED - else if (chunk_name == png_tIME) - png_handle_tIME(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_tRNS_SUPPORTED - else if (chunk_name == png_tRNS) - png_handle_tRNS(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_zTXt_SUPPORTED - else if (chunk_name == png_zTXt) - png_handle_zTXt(png_ptr, info_ptr, length); -#endif - -#ifdef PNG_READ_iTXt_SUPPORTED - else if (chunk_name == png_iTXt) - png_handle_iTXt(png_ptr, info_ptr, length); -#endif - - else - png_handle_unknown(png_ptr, info_ptr, length); - } while (!(png_ptr->mode & PNG_HAVE_IEND)); -} -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ - -/* Free all memory used by the read */ -void PNGAPI -png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, - png_infopp end_info_ptr_ptr) -{ - png_structp png_ptr = NULL; - png_infop info_ptr = NULL, end_info_ptr = NULL; -#ifdef PNG_USER_MEM_SUPPORTED - png_free_ptr free_fn = NULL; - png_voidp mem_ptr = NULL; -#endif - - png_debug(1, "in png_destroy_read_struct"); - - if (png_ptr_ptr != NULL) - png_ptr = *png_ptr_ptr; - if (png_ptr == NULL) - return; - -#ifdef PNG_USER_MEM_SUPPORTED - free_fn = png_ptr->free_fn; - mem_ptr = png_ptr->mem_ptr; -#endif - - if (info_ptr_ptr != NULL) - info_ptr = *info_ptr_ptr; - - if (end_info_ptr_ptr != NULL) - end_info_ptr = *end_info_ptr_ptr; - - png_read_destroy(png_ptr, info_ptr, end_info_ptr); - - if (info_ptr != NULL) - { -#ifdef PNG_TEXT_SUPPORTED - png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1); -#endif - -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, - (png_voidp)mem_ptr); -#else - png_destroy_struct((png_voidp)info_ptr); -#endif - *info_ptr_ptr = NULL; - } - - if (end_info_ptr != NULL) - { -#ifdef PNG_READ_TEXT_SUPPORTED - png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1); -#endif -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn, - (png_voidp)mem_ptr); -#else - png_destroy_struct((png_voidp)end_info_ptr); -#endif - *end_info_ptr_ptr = NULL; - } - - if (png_ptr != NULL) - { -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, - (png_voidp)mem_ptr); -#else - png_destroy_struct((png_voidp)png_ptr); -#endif - *png_ptr_ptr = NULL; - } -} - -/* Free all memory used by the read (old method) */ -void /* PRIVATE */ -png_read_destroy(png_structp png_ptr, png_infop info_ptr, - png_infop end_info_ptr) -{ -#ifdef PNG_SETJMP_SUPPORTED - jmp_buf tmp_jmp; -#endif - png_error_ptr error_fn; -#ifdef PNG_WARNINGS_SUPPORTED - png_error_ptr warning_fn; -#endif - png_voidp error_ptr; -#ifdef PNG_USER_MEM_SUPPORTED - png_free_ptr free_fn; -#endif - - png_debug(1, "in png_read_destroy"); - - if (info_ptr != NULL) - png_info_destroy(png_ptr, info_ptr); - - if (end_info_ptr != NULL) - png_info_destroy(png_ptr, end_info_ptr); - -#ifdef PNG_READ_GAMMA_SUPPORTED - png_destroy_gamma_table(png_ptr); -#endif - - png_free(png_ptr, png_ptr->zbuf); - png_free(png_ptr, png_ptr->big_row_buf); - png_free(png_ptr, png_ptr->big_prev_row); - png_free(png_ptr, png_ptr->chunkdata); - -#ifdef PNG_READ_QUANTIZE_SUPPORTED - png_free(png_ptr, png_ptr->palette_lookup); - png_free(png_ptr, png_ptr->quantize_index); -#endif - - if (png_ptr->free_me & PNG_FREE_PLTE) - png_zfree(png_ptr, png_ptr->palette); - png_ptr->free_me &= ~PNG_FREE_PLTE; - -#if defined(PNG_tRNS_SUPPORTED) || \ - defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - if (png_ptr->free_me & PNG_FREE_TRNS) - png_free(png_ptr, png_ptr->trans_alpha); - png_ptr->free_me &= ~PNG_FREE_TRNS; -#endif - -#ifdef PNG_READ_hIST_SUPPORTED - if (png_ptr->free_me & PNG_FREE_HIST) - png_free(png_ptr, png_ptr->hist); - png_ptr->free_me &= ~PNG_FREE_HIST; -#endif - - inflateEnd(&png_ptr->zstream); - -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED - png_free(png_ptr, png_ptr->save_buffer); -#endif - - /* Save the important info out of the png_struct, in case it is - * being used again. - */ -#ifdef PNG_SETJMP_SUPPORTED - png_memcpy(tmp_jmp, png_ptr->longjmp_buffer, png_sizeof(jmp_buf)); -#endif - - error_fn = png_ptr->error_fn; -#ifdef PNG_WARNINGS_SUPPORTED - warning_fn = png_ptr->warning_fn; -#endif - error_ptr = png_ptr->error_ptr; -#ifdef PNG_USER_MEM_SUPPORTED - free_fn = png_ptr->free_fn; -#endif - - png_memset(png_ptr, 0, png_sizeof(png_struct)); - - png_ptr->error_fn = error_fn; -#ifdef PNG_WARNINGS_SUPPORTED - png_ptr->warning_fn = warning_fn; -#endif - png_ptr->error_ptr = error_ptr; -#ifdef PNG_USER_MEM_SUPPORTED - png_ptr->free_fn = free_fn; -#endif - -#ifdef PNG_SETJMP_SUPPORTED - png_memcpy(png_ptr->longjmp_buffer, tmp_jmp, png_sizeof(jmp_buf)); -#endif - -} - -void PNGAPI -png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) -{ - if (png_ptr == NULL) - return; - - png_ptr->read_row_fn = read_row_fn; -} - - -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED -#ifdef PNG_INFO_IMAGE_SUPPORTED -void PNGAPI -png_read_png(png_structp png_ptr, png_infop info_ptr, - int transforms, - voidp params) -{ - int row; - - if (png_ptr == NULL || info_ptr == NULL) - return; - - /* png_read_info() gives us all of the information from the - * PNG file before the first IDAT (image data chunk). - */ - png_read_info(png_ptr, info_ptr); - if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) - png_error(png_ptr, "Image is too high to process with png_read_png()"); - - /* -------------- image transformations start here ------------------- */ - -#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED - /* Tell libpng to strip 16-bit/color files down to 8 bits per color. - */ - if (transforms & PNG_TRANSFORM_SCALE_16) - { - /* Added at libpng-1.5.4. "strip_16" produces the same result that it - * did in earlier versions, while "scale_16" is now more accurate. - */ - png_set_scale_16(png_ptr); - } -#endif - -#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED - /* If both SCALE and STRIP are required pngrtran will effectively cancel the - * latter by doing SCALE first. This is ok and allows apps not to check for - * which is supported to get the right answer. - */ - if (transforms & PNG_TRANSFORM_STRIP_16) - png_set_strip_16(png_ptr); -#endif - -#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED - /* Strip alpha bytes from the input data without combining with - * the background (not recommended). - */ - if (transforms & PNG_TRANSFORM_STRIP_ALPHA) - png_set_strip_alpha(png_ptr); -#endif - -#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED) - /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single - * byte into separate bytes (useful for paletted and grayscale images). - */ - if (transforms & PNG_TRANSFORM_PACKING) - png_set_packing(png_ptr); -#endif - -#ifdef PNG_READ_PACKSWAP_SUPPORTED - /* Change the order of packed pixels to least significant bit first - * (not useful if you are using png_set_packing). - */ - if (transforms & PNG_TRANSFORM_PACKSWAP) - png_set_packswap(png_ptr); -#endif - -#ifdef PNG_READ_EXPAND_SUPPORTED - /* Expand paletted colors into true RGB triplets - * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel - * Expand paletted or RGB images with transparency to full alpha - * channels so the data will be available as RGBA quartets. - */ - if (transforms & PNG_TRANSFORM_EXPAND) - if ((png_ptr->bit_depth < 8) || - (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) || - (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))) - png_set_expand(png_ptr); -#endif - - /* We don't handle background color or gamma transformation or quantizing. - */ - -#ifdef PNG_READ_INVERT_SUPPORTED - /* Invert monochrome files to have 0 as white and 1 as black - */ - if (transforms & PNG_TRANSFORM_INVERT_MONO) - png_set_invert_mono(png_ptr); -#endif - -#ifdef PNG_READ_SHIFT_SUPPORTED - /* If you want to shift the pixel values from the range [0,255] or - * [0,65535] to the original [0,7] or [0,31], or whatever range the - * colors were originally in: - */ - if ((transforms & PNG_TRANSFORM_SHIFT) - && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) - { - png_color_8p sig_bit; - - png_get_sBIT(png_ptr, info_ptr, &sig_bit); - png_set_shift(png_ptr, sig_bit); - } -#endif - -#ifdef PNG_READ_BGR_SUPPORTED - /* Flip the RGB pixels to BGR (or RGBA to BGRA) */ - if (transforms & PNG_TRANSFORM_BGR) - png_set_bgr(png_ptr); -#endif - -#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED - /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */ - if (transforms & PNG_TRANSFORM_SWAP_ALPHA) - png_set_swap_alpha(png_ptr); -#endif - -#ifdef PNG_READ_SWAP_SUPPORTED - /* Swap bytes of 16-bit files to least significant byte first */ - if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) - png_set_swap(png_ptr); -#endif - -/* Added at libpng-1.2.41 */ -#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED - /* Invert the alpha channel from opacity to transparency */ - if (transforms & PNG_TRANSFORM_INVERT_ALPHA) - png_set_invert_alpha(png_ptr); -#endif - -/* Added at libpng-1.2.41 */ -#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED - /* Expand grayscale image to RGB */ - if (transforms & PNG_TRANSFORM_GRAY_TO_RGB) - png_set_gray_to_rgb(png_ptr); -#endif - -/* Added at libpng-1.5.4 */ -#ifdef PNG_READ_EXPAND_16_SUPPORTED - if (transforms & PNG_TRANSFORM_EXPAND_16) - png_set_expand_16(png_ptr); -#endif - - /* We don't handle adding filler bytes */ - - /* We use png_read_image and rely on that for interlace handling, but we also - * call png_read_update_info therefore must turn on interlace handling now: - */ - (void)png_set_interlace_handling(png_ptr); - - /* Optional call to gamma correct and add the background to the palette - * and update info structure. REQUIRED if you are expecting libpng to - * update the palette for you (i.e., you selected such a transform above). - */ - png_read_update_info(png_ptr, info_ptr); - - /* -------------- image transformations end here ------------------- */ - - png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); - if (info_ptr->row_pointers == NULL) - { - png_uint_32 iptr; - - info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr, - info_ptr->height * png_sizeof(png_bytep)); - for (iptr=0; iptrheight; iptr++) - info_ptr->row_pointers[iptr] = NULL; - - info_ptr->free_me |= PNG_FREE_ROWS; - - for (row = 0; row < (int)info_ptr->height; row++) - info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, - png_get_rowbytes(png_ptr, info_ptr)); - } - - png_read_image(png_ptr, info_ptr->row_pointers); - info_ptr->valid |= PNG_INFO_IDAT; - - /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */ - png_read_end(png_ptr, info_ptr); - - PNG_UNUSED(transforms) /* Quiet compiler warnings */ - PNG_UNUSED(params) - -} -#endif /* PNG_INFO_IMAGE_SUPPORTED */ -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ -#endif /* PNG_READ_SUPPORTED */ + +/* pngread.c - read a PNG file + * + * Last changed in libpng 1.5.10 [March 8, 2012] + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file contains routines that an application calls directly to + * read a PNG file or stream. + */ + +#include "pngpriv.h" + +#ifdef PNG_READ_SUPPORTED + +/* Create a PNG structure for reading, and allocate any memory needed. */ +PNG_FUNCTION(png_structp,PNGAPI +png_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED) +{ + +#ifdef PNG_USER_MEM_SUPPORTED + return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn, + warn_fn, NULL, NULL, NULL)); +} + +/* Alternate create PNG structure for reading, and allocate any memory + * needed. + */ +PNG_FUNCTION(png_structp,PNGAPI +png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED) +{ +#endif /* PNG_USER_MEM_SUPPORTED */ + +#ifdef PNG_SETJMP_SUPPORTED + volatile +#endif + png_structp png_ptr; + volatile int png_cleanup_needed = 0; + +#ifdef PNG_SETJMP_SUPPORTED +#ifdef USE_FAR_KEYWORD + jmp_buf tmp_jmpbuf; +#endif +#endif + + png_debug(1, "in png_create_read_struct"); + +#ifdef PNG_USER_MEM_SUPPORTED + png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, + malloc_fn, mem_ptr); +#else + png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); +#endif + if (png_ptr == NULL) + return (NULL); + + /* Added at libpng-1.2.6 */ +#ifdef PNG_USER_LIMITS_SUPPORTED + png_ptr->user_width_max = PNG_USER_WIDTH_MAX; + png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; + + /* Added at libpng-1.2.43 and 1.4.0 */ + png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; + + /* Added at libpng-1.2.43 and 1.4.1 */ + png_ptr->user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX; +#endif + +#ifdef PNG_SETJMP_SUPPORTED +/* Applications that neglect to set up their own setjmp() and then + * encounter a png_error() will longjmp here. Since the jmpbuf is + * then meaningless we abort instead of returning. + */ +#ifdef USE_FAR_KEYWORD + if (setjmp(tmp_jmpbuf)) +#else + if (setjmp(png_jmpbuf(png_ptr))) /* Sets longjmp to match setjmp */ +#endif + PNG_ABORT(); +#ifdef USE_FAR_KEYWORD + png_memcpy(png_jmpbuf(png_ptr), tmp_jmpbuf, png_sizeof(jmp_buf)); +#endif +#endif /* PNG_SETJMP_SUPPORTED */ + +#ifdef PNG_USER_MEM_SUPPORTED + png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); +#endif + + png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); + + /* Call the general version checker (shared with read and write code): */ + if (!png_user_version_check(png_ptr, user_png_ver)) + png_cleanup_needed = 1; + + if (!png_cleanup_needed) + { + /* Initialize zbuf - compression buffer */ + png_ptr->zbuf_size = PNG_ZBUF_SIZE; + png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, png_ptr->zbuf_size); + + if (png_ptr->zbuf == NULL) + png_cleanup_needed = 1; + } + + png_ptr->zstream.zalloc = png_zalloc; + png_ptr->zstream.zfree = png_zfree; + png_ptr->zstream.opaque = (voidpf)png_ptr; + + if (!png_cleanup_needed) + { + switch (inflateInit(&png_ptr->zstream)) + { + case Z_OK: + break; /* Do nothing */ + + case Z_MEM_ERROR: + png_warning(png_ptr, "zlib memory error"); + png_cleanup_needed = 1; + break; + + case Z_STREAM_ERROR: + png_warning(png_ptr, "zlib stream error"); + png_cleanup_needed = 1; + break; + + case Z_VERSION_ERROR: + png_warning(png_ptr, "zlib version error"); + png_cleanup_needed = 1; + break; + + default: png_warning(png_ptr, "Unknown zlib error"); + png_cleanup_needed = 1; + } + } + + if (png_cleanup_needed) + { + /* Clean up PNG structure and deallocate any memory. */ + png_free(png_ptr, png_ptr->zbuf); + png_ptr->zbuf = NULL; +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)png_ptr, + (png_free_ptr)free_fn, (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)png_ptr); +#endif + return (NULL); + } + + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + + png_set_read_fn(png_ptr, NULL, NULL); + + + return (png_ptr); +} + + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the information before the actual image data. This has been + * changed in v0.90 to allow reading a file that already has the magic + * bytes read from the stream. You can tell libpng how many bytes have + * been read from the beginning of the stream (up to the maximum of 8) + * via png_set_sig_bytes(), and we will only check the remaining bytes + * here. The application can then have access to the signature bytes we + * read if it is determined that this isn't a valid PNG file. + */ +void PNGAPI +png_read_info(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_read_info"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + /* Read and check the PNG file signature. */ + png_read_sig(png_ptr, info_ptr); + + for (;;) + { + png_uint_32 length = png_read_chunk_header(png_ptr); + png_uint_32 chunk_name = png_ptr->chunk_name; + + /* This should be a binary subdivision search or a hash for + * matching the chunk name rather than a linear search. + */ + if (chunk_name == png_IDAT) + if (png_ptr->mode & PNG_AFTER_IDAT) + png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; + + if (chunk_name == png_IHDR) + png_handle_IHDR(png_ptr, info_ptr, length); + + else if (chunk_name == png_IEND) + png_handle_IEND(png_ptr, info_ptr, length); + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + else if (png_chunk_unknown_handling(png_ptr, chunk_name) != + PNG_HANDLE_CHUNK_AS_DEFAULT) + { + if (chunk_name == png_IDAT) + png_ptr->mode |= PNG_HAVE_IDAT; + + png_handle_unknown(png_ptr, info_ptr, length); + + if (chunk_name == png_PLTE) + png_ptr->mode |= PNG_HAVE_PLTE; + + else if (chunk_name == png_IDAT) + { + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before IDAT"); + + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + png_error(png_ptr, "Missing PLTE before IDAT"); + + break; + } + } +#endif + else if (chunk_name == png_PLTE) + png_handle_PLTE(png_ptr, info_ptr, length); + + else if (chunk_name == png_IDAT) + { + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before IDAT"); + + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + png_error(png_ptr, "Missing PLTE before IDAT"); + + png_ptr->idat_size = length; + png_ptr->mode |= PNG_HAVE_IDAT; + break; + } + +#ifdef PNG_READ_bKGD_SUPPORTED + else if (chunk_name == png_bKGD) + png_handle_bKGD(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_cHRM_SUPPORTED + else if (chunk_name == png_cHRM) + png_handle_cHRM(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_gAMA_SUPPORTED + else if (chunk_name == png_gAMA) + png_handle_gAMA(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_hIST_SUPPORTED + else if (chunk_name == png_hIST) + png_handle_hIST(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_oFFs_SUPPORTED + else if (chunk_name == png_oFFs) + png_handle_oFFs(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_pCAL_SUPPORTED + else if (chunk_name == png_pCAL) + png_handle_pCAL(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sCAL_SUPPORTED + else if (chunk_name == png_sCAL) + png_handle_sCAL(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_pHYs_SUPPORTED + else if (chunk_name == png_pHYs) + png_handle_pHYs(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sBIT_SUPPORTED + else if (chunk_name == png_sBIT) + png_handle_sBIT(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sRGB_SUPPORTED + else if (chunk_name == png_sRGB) + png_handle_sRGB(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_iCCP_SUPPORTED + else if (chunk_name == png_iCCP) + png_handle_iCCP(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sPLT_SUPPORTED + else if (chunk_name == png_sPLT) + png_handle_sPLT(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_tEXt_SUPPORTED + else if (chunk_name == png_tEXt) + png_handle_tEXt(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_tIME_SUPPORTED + else if (chunk_name == png_tIME) + png_handle_tIME(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_tRNS_SUPPORTED + else if (chunk_name == png_tRNS) + png_handle_tRNS(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_zTXt_SUPPORTED + else if (chunk_name == png_zTXt) + png_handle_zTXt(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_iTXt_SUPPORTED + else if (chunk_name == png_iTXt) + png_handle_iTXt(png_ptr, info_ptr, length); +#endif + + else + png_handle_unknown(png_ptr, info_ptr, length); + } +} +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ + +/* Optional call to update the users info_ptr structure */ +void PNGAPI +png_read_update_info(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_read_update_info"); + + if (png_ptr == NULL) + return; + + png_read_start_row(png_ptr); + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED + png_read_transform_info(png_ptr, info_ptr); +#else + PNG_UNUSED(info_ptr) +#endif +} + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Initialize palette, background, etc, after transformations + * are set, but before any reading takes place. This allows + * the user to obtain a gamma-corrected palette, for example. + * If the user doesn't call this, we will do it ourselves. + */ +void PNGAPI +png_start_read_image(png_structp png_ptr) +{ + png_debug(1, "in png_start_read_image"); + + if (png_ptr != NULL) + png_read_start_row(png_ptr); +} +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +void PNGAPI +png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) +{ + int ret; + + png_row_info row_info; + + if (png_ptr == NULL) + return; + + png_debug2(1, "in png_read_row (row %lu, pass %d)", + (unsigned long)png_ptr->row_number, png_ptr->pass); + + /* png_read_start_row sets the information (in particular iwidth) for this + * interlace pass. + */ + if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) + png_read_start_row(png_ptr); + + /* 1.5.6: row_info moved out of png_struct to a local here. */ + row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */ + row_info.color_type = png_ptr->color_type; + row_info.bit_depth = png_ptr->bit_depth; + row_info.channels = png_ptr->channels; + row_info.pixel_depth = png_ptr->pixel_depth; + row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); + + if (png_ptr->row_number == 0 && png_ptr->pass == 0) + { + /* Check for transforms that have been set but were defined out */ +#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) + if (png_ptr->transformations & PNG_INVERT_MONO) + png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined"); +#endif + +#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED) + if (png_ptr->transformations & PNG_FILLER) + png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined"); +#endif + +#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \ + !defined(PNG_READ_PACKSWAP_SUPPORTED) + if (png_ptr->transformations & PNG_PACKSWAP) + png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined"); +#endif + +#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED) + if (png_ptr->transformations & PNG_PACK) + png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined"); +#endif + +#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) + if (png_ptr->transformations & PNG_SHIFT) + png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined"); +#endif + +#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED) + if (png_ptr->transformations & PNG_BGR) + png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined"); +#endif + +#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED) + if (png_ptr->transformations & PNG_SWAP_BYTES) + png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined"); +#endif + } + +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* If interlaced and we do not need a new row, combine row and return. + * Notice that the pixels we have from previous rows have been transformed + * already; we can only combine like with like (transformed or + * untransformed) and, because of the libpng API for interlaced images, this + * means we must transform before de-interlacing. + */ + if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) + { + switch (png_ptr->pass) + { + case 0: + if (png_ptr->row_number & 0x07) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, 1/*display*/); + png_read_finish_row(png_ptr); + return; + } + break; + + case 1: + if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, 1/*display*/); + + png_read_finish_row(png_ptr); + return; + } + break; + + case 2: + if ((png_ptr->row_number & 0x07) != 4) + { + if (dsp_row != NULL && (png_ptr->row_number & 4)) + png_combine_row(png_ptr, dsp_row, 1/*display*/); + + png_read_finish_row(png_ptr); + return; + } + break; + + case 3: + if ((png_ptr->row_number & 3) || png_ptr->width < 3) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, 1/*display*/); + + png_read_finish_row(png_ptr); + return; + } + break; + + case 4: + if ((png_ptr->row_number & 3) != 2) + { + if (dsp_row != NULL && (png_ptr->row_number & 2)) + png_combine_row(png_ptr, dsp_row, 1/*display*/); + + png_read_finish_row(png_ptr); + return; + } + break; + case 5: + if ((png_ptr->row_number & 1) || png_ptr->width < 2) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, 1/*display*/); + + png_read_finish_row(png_ptr); + return; + } + break; + + default: + case 6: + if (!(png_ptr->row_number & 1)) + { + png_read_finish_row(png_ptr); + return; + } + break; + } + } +#endif + + if (!(png_ptr->mode & PNG_HAVE_IDAT)) + png_error(png_ptr, "Invalid attempt to read row data"); + + png_ptr->zstream.next_out = png_ptr->row_buf; + png_ptr->zstream.avail_out = + (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth, + png_ptr->iwidth) + 1); + + do + { + if (!(png_ptr->zstream.avail_in)) + { + while (!png_ptr->idat_size) + { + png_crc_finish(png_ptr, 0); + + png_ptr->idat_size = png_read_chunk_header(png_ptr); + if (png_ptr->chunk_name != png_IDAT) + png_error(png_ptr, "Not enough image data"); + } + png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_in = png_ptr->zbuf; + if (png_ptr->zbuf_size > png_ptr->idat_size) + png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; + png_crc_read(png_ptr, png_ptr->zbuf, + (png_size_t)png_ptr->zstream.avail_in); + png_ptr->idat_size -= png_ptr->zstream.avail_in; + } + + ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); + + if (ret == Z_STREAM_END) + { + if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in || + png_ptr->idat_size) + png_benign_error(png_ptr, "Extra compressed data"); + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + break; + } + + if (ret != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg : + "Decompression error"); + + } while (png_ptr->zstream.avail_out); + + if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) + { + if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) + png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1, + png_ptr->prev_row + 1, png_ptr->row_buf[0]); + else + png_error(png_ptr, "bad adaptive filter value"); + } + + /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before + * 1.5.6, while the buffer really is this big in current versions of libpng + * it may not be in the future, so this was changed just to copy the + * interlaced count: + */ + png_memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1); + +#ifdef PNG_MNG_FEATURES_SUPPORTED + if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) + { + /* Intrapixel differencing */ + png_do_read_intrapixel(&row_info, png_ptr->row_buf + 1); + } +#endif + + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED + if (png_ptr->transformations) + png_do_read_transformations(png_ptr, &row_info); +#endif + + /* The transformed pixel depth should match the depth now in row_info. */ + if (png_ptr->transformed_pixel_depth == 0) + { + png_ptr->transformed_pixel_depth = row_info.pixel_depth; + if (row_info.pixel_depth > png_ptr->maximum_pixel_depth) + png_error(png_ptr, "sequential row overflow"); + } + + else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth) + png_error(png_ptr, "internal sequential row size calculation error"); + +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* Blow up interlaced rows to full size */ + if (png_ptr->interlaced && + (png_ptr->transformations & PNG_INTERLACE)) + { + if (png_ptr->pass < 6) + png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass, + png_ptr->transformations); + + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, 1/*display*/); + + if (row != NULL) + png_combine_row(png_ptr, row, 0/*row*/); + } + + else +#endif + { + if (row != NULL) + png_combine_row(png_ptr, row, -1/*ignored*/); + + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, -1/*ignored*/); + } + png_read_finish_row(png_ptr); + + if (png_ptr->read_row_fn != NULL) + (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); +} +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read one or more rows of image data. If the image is interlaced, + * and png_set_interlace_handling() has been called, the rows need to + * contain the contents of the rows from the previous pass. If the + * image has alpha or transparency, and png_handle_alpha()[*] has been + * called, the rows contents must be initialized to the contents of the + * screen. + * + * "row" holds the actual image, and pixels are placed in it + * as they arrive. If the image is displayed after each pass, it will + * appear to "sparkle" in. "display_row" can be used to display a + * "chunky" progressive image, with finer detail added as it becomes + * available. If you do not want this "chunky" display, you may pass + * NULL for display_row. If you do not want the sparkle display, and + * you have not called png_handle_alpha(), you may pass NULL for rows. + * If you have called png_handle_alpha(), and the image has either an + * alpha channel or a transparency chunk, you must provide a buffer for + * rows. In this case, you do not have to provide a display_row buffer + * also, but you may. If the image is not interlaced, or if you have + * not called png_set_interlace_handling(), the display_row buffer will + * be ignored, so pass NULL to it. + * + * [*] png_handle_alpha() does not exist yet, as of this version of libpng + */ + +void PNGAPI +png_read_rows(png_structp png_ptr, png_bytepp row, + png_bytepp display_row, png_uint_32 num_rows) +{ + png_uint_32 i; + png_bytepp rp; + png_bytepp dp; + + png_debug(1, "in png_read_rows"); + + if (png_ptr == NULL) + return; + + rp = row; + dp = display_row; + if (rp != NULL && dp != NULL) + for (i = 0; i < num_rows; i++) + { + png_bytep rptr = *rp++; + png_bytep dptr = *dp++; + + png_read_row(png_ptr, rptr, dptr); + } + + else if (rp != NULL) + for (i = 0; i < num_rows; i++) + { + png_bytep rptr = *rp; + png_read_row(png_ptr, rptr, NULL); + rp++; + } + + else if (dp != NULL) + for (i = 0; i < num_rows; i++) + { + png_bytep dptr = *dp; + png_read_row(png_ptr, NULL, dptr); + dp++; + } +} +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the entire image. If the image has an alpha channel or a tRNS + * chunk, and you have called png_handle_alpha()[*], you will need to + * initialize the image to the current image that PNG will be overlaying. + * We set the num_rows again here, in case it was incorrectly set in + * png_read_start_row() by a call to png_read_update_info() or + * png_start_read_image() if png_set_interlace_handling() wasn't called + * prior to either of these functions like it should have been. You can + * only call this function once. If you desire to have an image for + * each pass of a interlaced image, use png_read_rows() instead. + * + * [*] png_handle_alpha() does not exist yet, as of this version of libpng + */ +void PNGAPI +png_read_image(png_structp png_ptr, png_bytepp image) +{ + png_uint_32 i, image_height; + int pass, j; + png_bytepp rp; + + png_debug(1, "in png_read_image"); + + if (png_ptr == NULL) + return; + +#ifdef PNG_READ_INTERLACING_SUPPORTED + if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) + { + pass = png_set_interlace_handling(png_ptr); + /* And make sure transforms are initialized. */ + png_start_read_image(png_ptr); + } + else + { + if (png_ptr->interlaced && !(png_ptr->transformations & PNG_INTERLACE)) + { + /* Caller called png_start_read_image or png_read_update_info without + * first turning on the PNG_INTERLACE transform. We can fix this here, + * but the caller should do it! + */ + png_warning(png_ptr, "Interlace handling should be turned on when " + "using png_read_image"); + /* Make sure this is set correctly */ + png_ptr->num_rows = png_ptr->height; + } + + /* Obtain the pass number, which also turns on the PNG_INTERLACE flag in + * the above error case. + */ + pass = png_set_interlace_handling(png_ptr); + } +#else + if (png_ptr->interlaced) + png_error(png_ptr, + "Cannot read interlaced image -- interlace handler disabled"); + + pass = 1; +#endif + + image_height=png_ptr->height; + + for (j = 0; j < pass; j++) + { + rp = image; + for (i = 0; i < image_height; i++) + { + png_read_row(png_ptr, *rp, NULL); + rp++; + } + } +} +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the end of the PNG file. Will not read past the end of the + * file, will verify the end is accurate, and will read any comments + * or time information at the end of the file, if info is not NULL. + */ +void PNGAPI +png_read_end(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_read_end"); + + if (png_ptr == NULL) + return; + + png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ + +#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED + /* Report invalid palette index; added at libng-1.5.10 */ + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + png_ptr->num_palette_max > png_ptr->num_palette) + png_benign_error(png_ptr, "Read palette index exceeding num_palette"); +#endif + + do + { + png_uint_32 length = png_read_chunk_header(png_ptr); + png_uint_32 chunk_name = png_ptr->chunk_name; + + if (chunk_name == png_IHDR) + png_handle_IHDR(png_ptr, info_ptr, length); + + else if (chunk_name == png_IEND) + png_handle_IEND(png_ptr, info_ptr, length); + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + else if (png_chunk_unknown_handling(png_ptr, chunk_name) != + PNG_HANDLE_CHUNK_AS_DEFAULT) + { + if (chunk_name == png_IDAT) + { + if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) + png_benign_error(png_ptr, "Too many IDATs found"); + } + png_handle_unknown(png_ptr, info_ptr, length); + if (chunk_name == png_PLTE) + png_ptr->mode |= PNG_HAVE_PLTE; + } +#endif + + else if (chunk_name == png_IDAT) + { + /* Zero length IDATs are legal after the last IDAT has been + * read, but not after other chunks have been read. + */ + if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) + png_benign_error(png_ptr, "Too many IDATs found"); + + png_crc_finish(png_ptr, length); + } + else if (chunk_name == png_PLTE) + png_handle_PLTE(png_ptr, info_ptr, length); + +#ifdef PNG_READ_bKGD_SUPPORTED + else if (chunk_name == png_bKGD) + png_handle_bKGD(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_cHRM_SUPPORTED + else if (chunk_name == png_cHRM) + png_handle_cHRM(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_gAMA_SUPPORTED + else if (chunk_name == png_gAMA) + png_handle_gAMA(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_hIST_SUPPORTED + else if (chunk_name == png_hIST) + png_handle_hIST(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_oFFs_SUPPORTED + else if (chunk_name == png_oFFs) + png_handle_oFFs(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_pCAL_SUPPORTED + else if (chunk_name == png_pCAL) + png_handle_pCAL(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sCAL_SUPPORTED + else if (chunk_name == png_sCAL) + png_handle_sCAL(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_pHYs_SUPPORTED + else if (chunk_name == png_pHYs) + png_handle_pHYs(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sBIT_SUPPORTED + else if (chunk_name == png_sBIT) + png_handle_sBIT(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sRGB_SUPPORTED + else if (chunk_name == png_sRGB) + png_handle_sRGB(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_iCCP_SUPPORTED + else if (chunk_name == png_iCCP) + png_handle_iCCP(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_sPLT_SUPPORTED + else if (chunk_name == png_sPLT) + png_handle_sPLT(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_tEXt_SUPPORTED + else if (chunk_name == png_tEXt) + png_handle_tEXt(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_tIME_SUPPORTED + else if (chunk_name == png_tIME) + png_handle_tIME(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_tRNS_SUPPORTED + else if (chunk_name == png_tRNS) + png_handle_tRNS(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_zTXt_SUPPORTED + else if (chunk_name == png_zTXt) + png_handle_zTXt(png_ptr, info_ptr, length); +#endif + +#ifdef PNG_READ_iTXt_SUPPORTED + else if (chunk_name == png_iTXt) + png_handle_iTXt(png_ptr, info_ptr, length); +#endif + + else + png_handle_unknown(png_ptr, info_ptr, length); + } while (!(png_ptr->mode & PNG_HAVE_IEND)); +} +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ + +/* Free all memory used by the read */ +void PNGAPI +png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, + png_infopp end_info_ptr_ptr) +{ + png_structp png_ptr = NULL; + png_infop info_ptr = NULL, end_info_ptr = NULL; +#ifdef PNG_USER_MEM_SUPPORTED + png_free_ptr free_fn = NULL; + png_voidp mem_ptr = NULL; +#endif + + png_debug(1, "in png_destroy_read_struct"); + + if (png_ptr_ptr != NULL) + png_ptr = *png_ptr_ptr; + if (png_ptr == NULL) + return; + +#ifdef PNG_USER_MEM_SUPPORTED + free_fn = png_ptr->free_fn; + mem_ptr = png_ptr->mem_ptr; +#endif + + if (info_ptr_ptr != NULL) + info_ptr = *info_ptr_ptr; + + if (end_info_ptr_ptr != NULL) + end_info_ptr = *end_info_ptr_ptr; + + png_read_destroy(png_ptr, info_ptr, end_info_ptr); + + if (info_ptr != NULL) + { +#ifdef PNG_TEXT_SUPPORTED + png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1); +#endif + +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)info_ptr); +#endif + *info_ptr_ptr = NULL; + } + + if (end_info_ptr != NULL) + { +#ifdef PNG_READ_TEXT_SUPPORTED + png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1); +#endif +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)end_info_ptr); +#endif + *end_info_ptr_ptr = NULL; + } + + if (png_ptr != NULL) + { +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)png_ptr); +#endif + *png_ptr_ptr = NULL; + } +} + +/* Free all memory used by the read (old method) */ +void /* PRIVATE */ +png_read_destroy(png_structp png_ptr, png_infop info_ptr, + png_infop end_info_ptr) +{ +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf tmp_jmp; +#endif + png_error_ptr error_fn; +#ifdef PNG_WARNINGS_SUPPORTED + png_error_ptr warning_fn; +#endif + png_voidp error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + png_free_ptr free_fn; +#endif + + png_debug(1, "in png_read_destroy"); + + if (info_ptr != NULL) + png_info_destroy(png_ptr, info_ptr); + + if (end_info_ptr != NULL) + png_info_destroy(png_ptr, end_info_ptr); + +#ifdef PNG_READ_GAMMA_SUPPORTED + png_destroy_gamma_table(png_ptr); +#endif + + png_free(png_ptr, png_ptr->zbuf); + png_free(png_ptr, png_ptr->big_row_buf); + png_free(png_ptr, png_ptr->big_prev_row); + png_free(png_ptr, png_ptr->chunkdata); + +#ifdef PNG_READ_QUANTIZE_SUPPORTED + png_free(png_ptr, png_ptr->palette_lookup); + png_free(png_ptr, png_ptr->quantize_index); +#endif + + if (png_ptr->free_me & PNG_FREE_PLTE) + png_zfree(png_ptr, png_ptr->palette); + png_ptr->free_me &= ~PNG_FREE_PLTE; + +#if defined(PNG_tRNS_SUPPORTED) || \ + defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr->free_me & PNG_FREE_TRNS) + png_free(png_ptr, png_ptr->trans_alpha); + png_ptr->free_me &= ~PNG_FREE_TRNS; +#endif + +#ifdef PNG_READ_hIST_SUPPORTED + if (png_ptr->free_me & PNG_FREE_HIST) + png_free(png_ptr, png_ptr->hist); + png_ptr->free_me &= ~PNG_FREE_HIST; +#endif + + inflateEnd(&png_ptr->zstream); + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED + png_free(png_ptr, png_ptr->save_buffer); +#endif + + /* Save the important info out of the png_struct, in case it is + * being used again. + */ +#ifdef PNG_SETJMP_SUPPORTED + png_memcpy(tmp_jmp, png_ptr->longjmp_buffer, png_sizeof(jmp_buf)); +#endif + + error_fn = png_ptr->error_fn; +#ifdef PNG_WARNINGS_SUPPORTED + warning_fn = png_ptr->warning_fn; +#endif + error_ptr = png_ptr->error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + free_fn = png_ptr->free_fn; +#endif + + png_memset(png_ptr, 0, png_sizeof(png_struct)); + + png_ptr->error_fn = error_fn; +#ifdef PNG_WARNINGS_SUPPORTED + png_ptr->warning_fn = warning_fn; +#endif + png_ptr->error_ptr = error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + png_ptr->free_fn = free_fn; +#endif + +#ifdef PNG_SETJMP_SUPPORTED + png_memcpy(png_ptr->longjmp_buffer, tmp_jmp, png_sizeof(jmp_buf)); +#endif + +} + +void PNGAPI +png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) +{ + if (png_ptr == NULL) + return; + + png_ptr->read_row_fn = read_row_fn; +} + + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +#ifdef PNG_INFO_IMAGE_SUPPORTED +void PNGAPI +png_read_png(png_structp png_ptr, png_infop info_ptr, + int transforms, + voidp params) +{ + int row; + + if (png_ptr == NULL || info_ptr == NULL) + return; + + /* png_read_info() gives us all of the information from the + * PNG file before the first IDAT (image data chunk). + */ + png_read_info(png_ptr, info_ptr); + if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) + png_error(png_ptr, "Image is too high to process with png_read_png()"); + + /* -------------- image transformations start here ------------------- */ + +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED + /* Tell libpng to strip 16-bit/color files down to 8 bits per color. + */ + if (transforms & PNG_TRANSFORM_SCALE_16) + { + /* Added at libpng-1.5.4. "strip_16" produces the same result that it + * did in earlier versions, while "scale_16" is now more accurate. + */ + png_set_scale_16(png_ptr); + } +#endif + +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED + /* If both SCALE and STRIP are required pngrtran will effectively cancel the + * latter by doing SCALE first. This is ok and allows apps not to check for + * which is supported to get the right answer. + */ + if (transforms & PNG_TRANSFORM_STRIP_16) + png_set_strip_16(png_ptr); +#endif + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + /* Strip alpha bytes from the input data without combining with + * the background (not recommended). + */ + if (transforms & PNG_TRANSFORM_STRIP_ALPHA) + png_set_strip_alpha(png_ptr); +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED) + /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single + * byte into separate bytes (useful for paletted and grayscale images). + */ + if (transforms & PNG_TRANSFORM_PACKING) + png_set_packing(png_ptr); +#endif + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + /* Change the order of packed pixels to least significant bit first + * (not useful if you are using png_set_packing). + */ + if (transforms & PNG_TRANSFORM_PACKSWAP) + png_set_packswap(png_ptr); +#endif + +#ifdef PNG_READ_EXPAND_SUPPORTED + /* Expand paletted colors into true RGB triplets + * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel + * Expand paletted or RGB images with transparency to full alpha + * channels so the data will be available as RGBA quartets. + */ + if (transforms & PNG_TRANSFORM_EXPAND) + if ((png_ptr->bit_depth < 8) || + (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) || + (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))) + png_set_expand(png_ptr); +#endif + + /* We don't handle background color or gamma transformation or quantizing. + */ + +#ifdef PNG_READ_INVERT_SUPPORTED + /* Invert monochrome files to have 0 as white and 1 as black + */ + if (transforms & PNG_TRANSFORM_INVERT_MONO) + png_set_invert_mono(png_ptr); +#endif + +#ifdef PNG_READ_SHIFT_SUPPORTED + /* If you want to shift the pixel values from the range [0,255] or + * [0,65535] to the original [0,7] or [0,31], or whatever range the + * colors were originally in: + */ + if ((transforms & PNG_TRANSFORM_SHIFT) + && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) + { + png_color_8p sig_bit; + + png_get_sBIT(png_ptr, info_ptr, &sig_bit); + png_set_shift(png_ptr, sig_bit); + } +#endif + +#ifdef PNG_READ_BGR_SUPPORTED + /* Flip the RGB pixels to BGR (or RGBA to BGRA) */ + if (transforms & PNG_TRANSFORM_BGR) + png_set_bgr(png_ptr); +#endif + +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED + /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */ + if (transforms & PNG_TRANSFORM_SWAP_ALPHA) + png_set_swap_alpha(png_ptr); +#endif + +#ifdef PNG_READ_SWAP_SUPPORTED + /* Swap bytes of 16-bit files to least significant byte first */ + if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) + png_set_swap(png_ptr); +#endif + +/* Added at libpng-1.2.41 */ +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED + /* Invert the alpha channel from opacity to transparency */ + if (transforms & PNG_TRANSFORM_INVERT_ALPHA) + png_set_invert_alpha(png_ptr); +#endif + +/* Added at libpng-1.2.41 */ +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + /* Expand grayscale image to RGB */ + if (transforms & PNG_TRANSFORM_GRAY_TO_RGB) + png_set_gray_to_rgb(png_ptr); +#endif + +/* Added at libpng-1.5.4 */ +#ifdef PNG_READ_EXPAND_16_SUPPORTED + if (transforms & PNG_TRANSFORM_EXPAND_16) + png_set_expand_16(png_ptr); +#endif + + /* We don't handle adding filler bytes */ + + /* We use png_read_image and rely on that for interlace handling, but we also + * call png_read_update_info therefore must turn on interlace handling now: + */ + (void)png_set_interlace_handling(png_ptr); + + /* Optional call to gamma correct and add the background to the palette + * and update info structure. REQUIRED if you are expecting libpng to + * update the palette for you (i.e., you selected such a transform above). + */ + png_read_update_info(png_ptr, info_ptr); + + /* -------------- image transformations end here ------------------- */ + + png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); + if (info_ptr->row_pointers == NULL) + { + png_uint_32 iptr; + + info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr, + info_ptr->height * png_sizeof(png_bytep)); + for (iptr=0; iptrheight; iptr++) + info_ptr->row_pointers[iptr] = NULL; + + info_ptr->free_me |= PNG_FREE_ROWS; + + for (row = 0; row < (int)info_ptr->height; row++) + info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, + png_get_rowbytes(png_ptr, info_ptr)); + } + + png_read_image(png_ptr, info_ptr->row_pointers); + info_ptr->valid |= PNG_INFO_IDAT; + + /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */ + png_read_end(png_ptr, info_ptr); + + PNG_UNUSED(transforms) /* Quiet compiler warnings */ + PNG_UNUSED(params) + +} +#endif /* PNG_INFO_IMAGE_SUPPORTED */ +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ +#endif /* PNG_READ_SUPPORTED */ diff --git a/Source/LibPNG/pngrio.c b/Source/LibPNG/pngrio.c index d0d9d8a..e9c381c 100644 --- a/Source/LibPNG/pngrio.c +++ b/Source/LibPNG/pngrio.c @@ -1,176 +1,176 @@ - -/* pngrio.c - functions for data input - * - * Last changed in libpng 1.5.0 [January 6, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - * - * This file provides a location for all input. Users who need - * special handling are expected to write a function that has the same - * arguments as this and performs a similar function, but that possibly - * has a different input method. Note that you shouldn't change this - * function, but rather write a replacement function and then make - * libpng use it at run time with png_set_read_fn(...). - */ - -#include "pngpriv.h" - -#ifdef PNG_READ_SUPPORTED - -/* Read the data from whatever input you are using. The default routine - * reads from a file pointer. Note that this routine sometimes gets called - * with very small lengths, so you should implement some kind of simple - * buffering if you are using unbuffered reads. This should never be asked - * to read more then 64K on a 16 bit machine. - */ -void /* PRIVATE */ -png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) -{ - png_debug1(4, "reading %d bytes", (int)length); - - if (png_ptr->read_data_fn != NULL) - (*(png_ptr->read_data_fn))(png_ptr, data, length); - - else - png_error(png_ptr, "Call to NULL read function"); -} - -#ifdef PNG_STDIO_SUPPORTED -/* This is the function that does the actual reading of data. If you are - * not reading from a standard C stream, you should create a replacement - * read_data function and use it at run time with png_set_read_fn(), rather - * than changing the library. - */ -# ifndef USE_FAR_KEYWORD -void PNGCBAPI -png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) -{ - png_size_t check; - - if (png_ptr == NULL) - return; - - /* fread() returns 0 on error, so it is OK to store this in a png_size_t - * instead of an int, which is what fread() actually returns. - */ - check = fread(data, 1, length, (png_FILE_p)png_ptr->io_ptr); - - if (check != length) - png_error(png_ptr, "Read Error"); -} -# else -/* This is the model-independent version. Since the standard I/O library - can't handle far buffers in the medium and small models, we have to copy - the data. -*/ - -#define NEAR_BUF_SIZE 1024 -#define MIN(a,b) (a <= b ? a : b) - -static void PNGCBAPI -png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) -{ - png_size_t check; - png_byte *n_data; - png_FILE_p io_ptr; - - if (png_ptr == NULL) - return; - - /* Check if data really is near. If so, use usual code. */ - n_data = (png_byte *)CVT_PTR_NOCHECK(data); - io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); - - if ((png_bytep)n_data == data) - { - check = fread(n_data, 1, length, io_ptr); - } - - else - { - png_byte buf[NEAR_BUF_SIZE]; - png_size_t read, remaining, err; - check = 0; - remaining = length; - - do - { - read = MIN(NEAR_BUF_SIZE, remaining); - err = fread(buf, 1, read, io_ptr); - png_memcpy(data, buf, read); /* copy far buffer to near buffer */ - - if (err != read) - break; - - else - check += err; - - data += read; - remaining -= read; - } - while (remaining != 0); - } - - if ((png_uint_32)check != (png_uint_32)length) - png_error(png_ptr, "read Error"); -} -# endif -#endif - -/* This function allows the application to supply a new input function - * for libpng if standard C streams aren't being used. - * - * This function takes as its arguments: - * - * png_ptr - pointer to a png input data structure - * - * io_ptr - pointer to user supplied structure containing info about - * the input functions. May be NULL. - * - * read_data_fn - pointer to a new input function that takes as its - * arguments a pointer to a png_struct, a pointer to - * a location where input data can be stored, and a 32-bit - * unsigned int that is the number of bytes to be read. - * To exit and output any fatal error messages the new write - * function should call png_error(png_ptr, "Error msg"). - * May be NULL, in which case libpng's default function will - * be used. - */ -void PNGAPI -png_set_read_fn(png_structp png_ptr, png_voidp io_ptr, - png_rw_ptr read_data_fn) -{ - if (png_ptr == NULL) - return; - - png_ptr->io_ptr = io_ptr; - -#ifdef PNG_STDIO_SUPPORTED - if (read_data_fn != NULL) - png_ptr->read_data_fn = read_data_fn; - - else - png_ptr->read_data_fn = png_default_read_data; -#else - png_ptr->read_data_fn = read_data_fn; -#endif - - /* It is an error to write to a read device */ - if (png_ptr->write_data_fn != NULL) - { - png_ptr->write_data_fn = NULL; - png_warning(png_ptr, - "Can't set both read_data_fn and write_data_fn in the" - " same structure"); - } - -#ifdef PNG_WRITE_FLUSH_SUPPORTED - png_ptr->output_flush_fn = NULL; -#endif -} -#endif /* PNG_READ_SUPPORTED */ + +/* pngrio.c - functions for data input + * + * Last changed in libpng 1.5.0 [January 6, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file provides a location for all input. Users who need + * special handling are expected to write a function that has the same + * arguments as this and performs a similar function, but that possibly + * has a different input method. Note that you shouldn't change this + * function, but rather write a replacement function and then make + * libpng use it at run time with png_set_read_fn(...). + */ + +#include "pngpriv.h" + +#ifdef PNG_READ_SUPPORTED + +/* Read the data from whatever input you are using. The default routine + * reads from a file pointer. Note that this routine sometimes gets called + * with very small lengths, so you should implement some kind of simple + * buffering if you are using unbuffered reads. This should never be asked + * to read more then 64K on a 16 bit machine. + */ +void /* PRIVATE */ +png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_debug1(4, "reading %d bytes", (int)length); + + if (png_ptr->read_data_fn != NULL) + (*(png_ptr->read_data_fn))(png_ptr, data, length); + + else + png_error(png_ptr, "Call to NULL read function"); +} + +#ifdef PNG_STDIO_SUPPORTED +/* This is the function that does the actual reading of data. If you are + * not reading from a standard C stream, you should create a replacement + * read_data function and use it at run time with png_set_read_fn(), rather + * than changing the library. + */ +# ifndef USE_FAR_KEYWORD +void PNGCBAPI +png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_size_t check; + + if (png_ptr == NULL) + return; + + /* fread() returns 0 on error, so it is OK to store this in a png_size_t + * instead of an int, which is what fread() actually returns. + */ + check = fread(data, 1, length, (png_FILE_p)png_ptr->io_ptr); + + if (check != length) + png_error(png_ptr, "Read Error"); +} +# else +/* This is the model-independent version. Since the standard I/O library + can't handle far buffers in the medium and small models, we have to copy + the data. +*/ + +#define NEAR_BUF_SIZE 1024 +#define MIN(a,b) (a <= b ? a : b) + +static void PNGCBAPI +png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_size_t check; + png_byte *n_data; + png_FILE_p io_ptr; + + if (png_ptr == NULL) + return; + + /* Check if data really is near. If so, use usual code. */ + n_data = (png_byte *)CVT_PTR_NOCHECK(data); + io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); + + if ((png_bytep)n_data == data) + { + check = fread(n_data, 1, length, io_ptr); + } + + else + { + png_byte buf[NEAR_BUF_SIZE]; + png_size_t read, remaining, err; + check = 0; + remaining = length; + + do + { + read = MIN(NEAR_BUF_SIZE, remaining); + err = fread(buf, 1, read, io_ptr); + png_memcpy(data, buf, read); /* copy far buffer to near buffer */ + + if (err != read) + break; + + else + check += err; + + data += read; + remaining -= read; + } + while (remaining != 0); + } + + if ((png_uint_32)check != (png_uint_32)length) + png_error(png_ptr, "read Error"); +} +# endif +#endif + +/* This function allows the application to supply a new input function + * for libpng if standard C streams aren't being used. + * + * This function takes as its arguments: + * + * png_ptr - pointer to a png input data structure + * + * io_ptr - pointer to user supplied structure containing info about + * the input functions. May be NULL. + * + * read_data_fn - pointer to a new input function that takes as its + * arguments a pointer to a png_struct, a pointer to + * a location where input data can be stored, and a 32-bit + * unsigned int that is the number of bytes to be read. + * To exit and output any fatal error messages the new write + * function should call png_error(png_ptr, "Error msg"). + * May be NULL, in which case libpng's default function will + * be used. + */ +void PNGAPI +png_set_read_fn(png_structp png_ptr, png_voidp io_ptr, + png_rw_ptr read_data_fn) +{ + if (png_ptr == NULL) + return; + + png_ptr->io_ptr = io_ptr; + +#ifdef PNG_STDIO_SUPPORTED + if (read_data_fn != NULL) + png_ptr->read_data_fn = read_data_fn; + + else + png_ptr->read_data_fn = png_default_read_data; +#else + png_ptr->read_data_fn = read_data_fn; +#endif + + /* It is an error to write to a read device */ + if (png_ptr->write_data_fn != NULL) + { + png_ptr->write_data_fn = NULL; + png_warning(png_ptr, + "Can't set both read_data_fn and write_data_fn in the" + " same structure"); + } + +#ifdef PNG_WRITE_FLUSH_SUPPORTED + png_ptr->output_flush_fn = NULL; +#endif +} +#endif /* PNG_READ_SUPPORTED */ diff --git a/Source/LibPNG/pngrtran.c b/Source/LibPNG/pngrtran.c index 4a40495..1e31c75 100644 --- a/Source/LibPNG/pngrtran.c +++ b/Source/LibPNG/pngrtran.c @@ -1,5054 +1,5054 @@ - -/* pngrtran.c - transforms the data in a row for PNG readers - * - * Last changed in libpng 1.5.11 [June 14, 2012] - * Copyright (c) 1998-2012 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - * - * This file contains functions optionally called by an application - * in order to tell libpng how to handle data when reading a PNG. - * Transformations that are used in both reading and writing are - * in pngtrans.c. - */ - -#include "pngpriv.h" - -#ifdef PNG_READ_SUPPORTED - -/* Set the action on getting a CRC error for an ancillary or critical chunk. */ -void PNGAPI -png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) -{ - png_debug(1, "in png_set_crc_action"); - - if (png_ptr == NULL) - return; - - /* Tell libpng how we react to CRC errors in critical chunks */ - switch (crit_action) - { - case PNG_CRC_NO_CHANGE: /* Leave setting as is */ - break; - - case PNG_CRC_WARN_USE: /* Warn/use data */ - png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; - png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE; - break; - - case PNG_CRC_QUIET_USE: /* Quiet/use data */ - png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; - png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE | - PNG_FLAG_CRC_CRITICAL_IGNORE; - break; - - case PNG_CRC_WARN_DISCARD: /* Not a valid action for critical data */ - png_warning(png_ptr, - "Can't discard critical data on CRC error"); - case PNG_CRC_ERROR_QUIT: /* Error/quit */ - - case PNG_CRC_DEFAULT: - default: - png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; - break; - } - - /* Tell libpng how we react to CRC errors in ancillary chunks */ - switch (ancil_action) - { - case PNG_CRC_NO_CHANGE: /* Leave setting as is */ - break; - - case PNG_CRC_WARN_USE: /* Warn/use data */ - png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; - png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE; - break; - - case PNG_CRC_QUIET_USE: /* Quiet/use data */ - png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; - png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE | - PNG_FLAG_CRC_ANCILLARY_NOWARN; - break; - - case PNG_CRC_ERROR_QUIT: /* Error/quit */ - png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; - png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN; - break; - - case PNG_CRC_WARN_DISCARD: /* Warn/discard data */ - - case PNG_CRC_DEFAULT: - default: - png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; - break; - } -} - -#ifdef PNG_READ_BACKGROUND_SUPPORTED -/* Handle alpha and tRNS via a background color */ -void PNGFAPI -png_set_background_fixed(png_structp png_ptr, - png_const_color_16p background_color, int background_gamma_code, - int need_expand, png_fixed_point background_gamma) -{ - png_debug(1, "in png_set_background_fixed"); - - if (png_ptr == NULL) - return; - - if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN) - { - png_warning(png_ptr, "Application must supply a known background gamma"); - return; - } - - png_ptr->transformations |= PNG_COMPOSE | PNG_STRIP_ALPHA; - png_ptr->transformations &= ~PNG_ENCODE_ALPHA; - png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; - - png_memcpy(&(png_ptr->background), background_color, - png_sizeof(png_color_16)); - png_ptr->background_gamma = background_gamma; - png_ptr->background_gamma_type = (png_byte)(background_gamma_code); - if (need_expand) - png_ptr->transformations |= PNG_BACKGROUND_EXPAND; - else - png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND; -} - -# ifdef PNG_FLOATING_POINT_SUPPORTED -void PNGAPI -png_set_background(png_structp png_ptr, - png_const_color_16p background_color, int background_gamma_code, - int need_expand, double background_gamma) -{ - png_set_background_fixed(png_ptr, background_color, background_gamma_code, - need_expand, png_fixed(png_ptr, background_gamma, "png_set_background")); -} -# endif /* FLOATING_POINT */ -#endif /* READ_BACKGROUND */ - -/* Scale 16-bit depth files to 8-bit depth. If both of these are set then the - * one that pngrtran does first (scale) happens. This is necessary to allow the - * TRANSFORM and API behavior to be somewhat consistent, and it's simpler. - */ -#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED -void PNGAPI -png_set_scale_16(png_structp png_ptr) -{ - png_debug(1, "in png_set_scale_16"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= PNG_SCALE_16_TO_8; -} -#endif - -#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED -/* Chop 16-bit depth files to 8-bit depth */ -void PNGAPI -png_set_strip_16(png_structp png_ptr) -{ - png_debug(1, "in png_set_strip_16"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= PNG_16_TO_8; -} -#endif - -#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED -void PNGAPI -png_set_strip_alpha(png_structp png_ptr) -{ - png_debug(1, "in png_set_strip_alpha"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= PNG_STRIP_ALPHA; -} -#endif - -#if defined(PNG_READ_ALPHA_MODE_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED) -static png_fixed_point -translate_gamma_flags(png_structp png_ptr, png_fixed_point output_gamma, - int is_screen) -{ - /* Check for flag values. The main reason for having the old Mac value as a - * flag is that it is pretty near impossible to work out what the correct - * value is from Apple documentation - a working Mac system is needed to - * discover the value! - */ - if (output_gamma == PNG_DEFAULT_sRGB || - output_gamma == PNG_FP_1 / PNG_DEFAULT_sRGB) - { - /* If there is no sRGB support this just sets the gamma to the standard - * sRGB value. (This is a side effect of using this function!) - */ -# ifdef PNG_READ_sRGB_SUPPORTED - png_ptr->flags |= PNG_FLAG_ASSUME_sRGB; -# endif - if (is_screen) - output_gamma = PNG_GAMMA_sRGB; - else - output_gamma = PNG_GAMMA_sRGB_INVERSE; - } - - else if (output_gamma == PNG_GAMMA_MAC_18 || - output_gamma == PNG_FP_1 / PNG_GAMMA_MAC_18) - { - if (is_screen) - output_gamma = PNG_GAMMA_MAC_OLD; - else - output_gamma = PNG_GAMMA_MAC_INVERSE; - } - - return output_gamma; -} - -# ifdef PNG_FLOATING_POINT_SUPPORTED -static png_fixed_point -convert_gamma_value(png_structp png_ptr, double output_gamma) -{ - /* The following silently ignores cases where fixed point (times 100,000) - * gamma values are passed to the floating point API. This is safe and it - * means the fixed point constants work just fine with the floating point - * API. The alternative would just lead to undetected errors and spurious - * bug reports. Negative values fail inside the _fixed API unless they - * correspond to the flag values. - */ - if (output_gamma > 0 && output_gamma < 128) - output_gamma *= PNG_FP_1; - - /* This preserves -1 and -2 exactly: */ - output_gamma = floor(output_gamma + .5); - - if (output_gamma > PNG_FP_MAX || output_gamma < PNG_FP_MIN) - png_fixed_error(png_ptr, "gamma value"); - - return (png_fixed_point)output_gamma; -} -# endif -#endif /* READ_ALPHA_MODE || READ_GAMMA */ - -#ifdef PNG_READ_ALPHA_MODE_SUPPORTED -void PNGFAPI -png_set_alpha_mode_fixed(png_structp png_ptr, int mode, - png_fixed_point output_gamma) -{ - int compose = 0; - png_fixed_point file_gamma; - - png_debug(1, "in png_set_alpha_mode"); - - if (png_ptr == NULL) - return; - - output_gamma = translate_gamma_flags(png_ptr, output_gamma, 1/*screen*/); - - /* Validate the value to ensure it is in a reasonable range. The value - * is expected to be 1 or greater, but this range test allows for some - * viewing correction values. The intent is to weed out users of this API - * who use the inverse of the gamma value accidentally! Since some of these - * values are reasonable this may have to be changed. - */ - if (output_gamma < 70000 || output_gamma > 300000) - png_error(png_ptr, "output gamma out of expected range"); - - /* The default file gamma is the inverse of the output gamma; the output - * gamma may be changed below so get the file value first: - */ - file_gamma = png_reciprocal(output_gamma); - - /* There are really 8 possibilities here, composed of any combination - * of: - * - * premultiply the color channels - * do not encode non-opaque pixels - * encode the alpha as well as the color channels - * - * The differences disappear if the input/output ('screen') gamma is 1.0, - * because then the encoding is a no-op and there is only the choice of - * premultiplying the color channels or not. - * - * png_set_alpha_mode and png_set_background interact because both use - * png_compose to do the work. Calling both is only useful when - * png_set_alpha_mode is used to set the default mode - PNG_ALPHA_PNG - along - * with a default gamma value. Otherwise PNG_COMPOSE must not be set. - */ - switch (mode) - { - case PNG_ALPHA_PNG: /* default: png standard */ - /* No compose, but it may be set by png_set_background! */ - png_ptr->transformations &= ~PNG_ENCODE_ALPHA; - png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; - break; - - case PNG_ALPHA_ASSOCIATED: /* color channels premultiplied */ - compose = 1; - png_ptr->transformations &= ~PNG_ENCODE_ALPHA; - png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; - /* The output is linear: */ - output_gamma = PNG_FP_1; - break; - - case PNG_ALPHA_OPTIMIZED: /* associated, non-opaque pixels linear */ - compose = 1; - png_ptr->transformations &= ~PNG_ENCODE_ALPHA; - png_ptr->flags |= PNG_FLAG_OPTIMIZE_ALPHA; - /* output_gamma records the encoding of opaque pixels! */ - break; - - case PNG_ALPHA_BROKEN: /* associated, non-linear, alpha encoded */ - compose = 1; - png_ptr->transformations |= PNG_ENCODE_ALPHA; - png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; - break; - - default: - png_error(png_ptr, "invalid alpha mode"); - } - - /* Only set the default gamma if the file gamma has not been set (this has - * the side effect that the gamma in a second call to png_set_alpha_mode will - * be ignored.) - */ - if (png_ptr->gamma == 0) - png_ptr->gamma = file_gamma; - - /* But always set the output gamma: */ - png_ptr->screen_gamma = output_gamma; - - /* Finally, if pre-multiplying, set the background fields to achieve the - * desired result. - */ - if (compose) - { - /* And obtain alpha pre-multiplication by composing on black: */ - png_memset(&png_ptr->background, 0, sizeof png_ptr->background); - png_ptr->background_gamma = png_ptr->gamma; /* just in case */ - png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_FILE; - png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND; - - if (png_ptr->transformations & PNG_COMPOSE) - png_error(png_ptr, - "conflicting calls to set alpha mode and background"); - - png_ptr->transformations |= PNG_COMPOSE; - } - - /* New API, make sure apps call the correct initializers: */ - png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED; -} - -# ifdef PNG_FLOATING_POINT_SUPPORTED -void PNGAPI -png_set_alpha_mode(png_structp png_ptr, int mode, double output_gamma) -{ - png_set_alpha_mode_fixed(png_ptr, mode, convert_gamma_value(png_ptr, - output_gamma)); -} -# endif -#endif - -#ifdef PNG_READ_QUANTIZE_SUPPORTED -/* Dither file to 8-bit. Supply a palette, the current number - * of elements in the palette, the maximum number of elements - * allowed, and a histogram if possible. If the current number - * of colors is greater then the maximum number, the palette will be - * modified to fit in the maximum number. "full_quantize" indicates - * whether we need a quantizing cube set up for RGB images, or if we - * simply are reducing the number of colors in a paletted image. - */ - -typedef struct png_dsort_struct -{ - struct png_dsort_struct FAR * next; - png_byte left; - png_byte right; -} png_dsort; -typedef png_dsort FAR * png_dsortp; -typedef png_dsort FAR * FAR * png_dsortpp; - -void PNGAPI -png_set_quantize(png_structp png_ptr, png_colorp palette, - int num_palette, int maximum_colors, png_const_uint_16p histogram, - int full_quantize) -{ - png_debug(1, "in png_set_quantize"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= PNG_QUANTIZE; - - if (!full_quantize) - { - int i; - - png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr, - (png_uint_32)(num_palette * png_sizeof(png_byte))); - for (i = 0; i < num_palette; i++) - png_ptr->quantize_index[i] = (png_byte)i; - } - - if (num_palette > maximum_colors) - { - if (histogram != NULL) - { - /* This is easy enough, just throw out the least used colors. - * Perhaps not the best solution, but good enough. - */ - - int i; - - /* Initialize an array to sort colors */ - png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr, - (png_uint_32)(num_palette * png_sizeof(png_byte))); - - /* Initialize the quantize_sort array */ - for (i = 0; i < num_palette; i++) - png_ptr->quantize_sort[i] = (png_byte)i; - - /* Find the least used palette entries by starting a - * bubble sort, and running it until we have sorted - * out enough colors. Note that we don't care about - * sorting all the colors, just finding which are - * least used. - */ - - for (i = num_palette - 1; i >= maximum_colors; i--) - { - int done; /* To stop early if the list is pre-sorted */ - int j; - - done = 1; - for (j = 0; j < i; j++) - { - if (histogram[png_ptr->quantize_sort[j]] - < histogram[png_ptr->quantize_sort[j + 1]]) - { - png_byte t; - - t = png_ptr->quantize_sort[j]; - png_ptr->quantize_sort[j] = png_ptr->quantize_sort[j + 1]; - png_ptr->quantize_sort[j + 1] = t; - done = 0; - } - } - - if (done) - break; - } - - /* Swap the palette around, and set up a table, if necessary */ - if (full_quantize) - { - int j = num_palette; - - /* Put all the useful colors within the max, but don't - * move the others. - */ - for (i = 0; i < maximum_colors; i++) - { - if ((int)png_ptr->quantize_sort[i] >= maximum_colors) - { - do - j--; - while ((int)png_ptr->quantize_sort[j] >= maximum_colors); - - palette[i] = palette[j]; - } - } - } - else - { - int j = num_palette; - - /* Move all the used colors inside the max limit, and - * develop a translation table. - */ - for (i = 0; i < maximum_colors; i++) - { - /* Only move the colors we need to */ - if ((int)png_ptr->quantize_sort[i] >= maximum_colors) - { - png_color tmp_color; - - do - j--; - while ((int)png_ptr->quantize_sort[j] >= maximum_colors); - - tmp_color = palette[j]; - palette[j] = palette[i]; - palette[i] = tmp_color; - /* Indicate where the color went */ - png_ptr->quantize_index[j] = (png_byte)i; - png_ptr->quantize_index[i] = (png_byte)j; - } - } - - /* Find closest color for those colors we are not using */ - for (i = 0; i < num_palette; i++) - { - if ((int)png_ptr->quantize_index[i] >= maximum_colors) - { - int min_d, k, min_k, d_index; - - /* Find the closest color to one we threw out */ - d_index = png_ptr->quantize_index[i]; - min_d = PNG_COLOR_DIST(palette[d_index], palette[0]); - for (k = 1, min_k = 0; k < maximum_colors; k++) - { - int d; - - d = PNG_COLOR_DIST(palette[d_index], palette[k]); - - if (d < min_d) - { - min_d = d; - min_k = k; - } - } - /* Point to closest color */ - png_ptr->quantize_index[i] = (png_byte)min_k; - } - } - } - png_free(png_ptr, png_ptr->quantize_sort); - png_ptr->quantize_sort = NULL; - } - else - { - /* This is much harder to do simply (and quickly). Perhaps - * we need to go through a median cut routine, but those - * don't always behave themselves with only a few colors - * as input. So we will just find the closest two colors, - * and throw out one of them (chosen somewhat randomly). - * [We don't understand this at all, so if someone wants to - * work on improving it, be our guest - AED, GRP] - */ - int i; - int max_d; - int num_new_palette; - png_dsortp t; - png_dsortpp hash; - - t = NULL; - - /* Initialize palette index arrays */ - png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr, - (png_uint_32)(num_palette * png_sizeof(png_byte))); - png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr, - (png_uint_32)(num_palette * png_sizeof(png_byte))); - - /* Initialize the sort array */ - for (i = 0; i < num_palette; i++) - { - png_ptr->index_to_palette[i] = (png_byte)i; - png_ptr->palette_to_index[i] = (png_byte)i; - } - - hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 * - png_sizeof(png_dsortp))); - - num_new_palette = num_palette; - - /* Initial wild guess at how far apart the farthest pixel - * pair we will be eliminating will be. Larger - * numbers mean more areas will be allocated, Smaller - * numbers run the risk of not saving enough data, and - * having to do this all over again. - * - * I have not done extensive checking on this number. - */ - max_d = 96; - - while (num_new_palette > maximum_colors) - { - for (i = 0; i < num_new_palette - 1; i++) - { - int j; - - for (j = i + 1; j < num_new_palette; j++) - { - int d; - - d = PNG_COLOR_DIST(palette[i], palette[j]); - - if (d <= max_d) - { - - t = (png_dsortp)png_malloc_warn(png_ptr, - (png_uint_32)(png_sizeof(png_dsort))); - - if (t == NULL) - break; - - t->next = hash[d]; - t->left = (png_byte)i; - t->right = (png_byte)j; - hash[d] = t; - } - } - if (t == NULL) - break; - } - - if (t != NULL) - for (i = 0; i <= max_d; i++) - { - if (hash[i] != NULL) - { - png_dsortp p; - - for (p = hash[i]; p; p = p->next) - { - if ((int)png_ptr->index_to_palette[p->left] - < num_new_palette && - (int)png_ptr->index_to_palette[p->right] - < num_new_palette) - { - int j, next_j; - - if (num_new_palette & 0x01) - { - j = p->left; - next_j = p->right; - } - else - { - j = p->right; - next_j = p->left; - } - - num_new_palette--; - palette[png_ptr->index_to_palette[j]] - = palette[num_new_palette]; - if (!full_quantize) - { - int k; - - for (k = 0; k < num_palette; k++) - { - if (png_ptr->quantize_index[k] == - png_ptr->index_to_palette[j]) - png_ptr->quantize_index[k] = - png_ptr->index_to_palette[next_j]; - - if ((int)png_ptr->quantize_index[k] == - num_new_palette) - png_ptr->quantize_index[k] = - png_ptr->index_to_palette[j]; - } - } - - png_ptr->index_to_palette[png_ptr->palette_to_index - [num_new_palette]] = png_ptr->index_to_palette[j]; - - png_ptr->palette_to_index[png_ptr->index_to_palette[j]] - = png_ptr->palette_to_index[num_new_palette]; - - png_ptr->index_to_palette[j] = - (png_byte)num_new_palette; - - png_ptr->palette_to_index[num_new_palette] = - (png_byte)j; - } - if (num_new_palette <= maximum_colors) - break; - } - if (num_new_palette <= maximum_colors) - break; - } - } - - for (i = 0; i < 769; i++) - { - if (hash[i] != NULL) - { - png_dsortp p = hash[i]; - while (p) - { - t = p->next; - png_free(png_ptr, p); - p = t; - } - } - hash[i] = 0; - } - max_d += 96; - } - png_free(png_ptr, hash); - png_free(png_ptr, png_ptr->palette_to_index); - png_free(png_ptr, png_ptr->index_to_palette); - png_ptr->palette_to_index = NULL; - png_ptr->index_to_palette = NULL; - } - num_palette = maximum_colors; - } - if (png_ptr->palette == NULL) - { - png_ptr->palette = palette; - } - png_ptr->num_palette = (png_uint_16)num_palette; - - if (full_quantize) - { - int i; - png_bytep distance; - int total_bits = PNG_QUANTIZE_RED_BITS + PNG_QUANTIZE_GREEN_BITS + - PNG_QUANTIZE_BLUE_BITS; - int num_red = (1 << PNG_QUANTIZE_RED_BITS); - int num_green = (1 << PNG_QUANTIZE_GREEN_BITS); - int num_blue = (1 << PNG_QUANTIZE_BLUE_BITS); - png_size_t num_entries = ((png_size_t)1 << total_bits); - - png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr, - (png_uint_32)(num_entries * png_sizeof(png_byte))); - - distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries * - png_sizeof(png_byte))); - - png_memset(distance, 0xff, num_entries * png_sizeof(png_byte)); - - for (i = 0; i < num_palette; i++) - { - int ir, ig, ib; - int r = (palette[i].red >> (8 - PNG_QUANTIZE_RED_BITS)); - int g = (palette[i].green >> (8 - PNG_QUANTIZE_GREEN_BITS)); - int b = (palette[i].blue >> (8 - PNG_QUANTIZE_BLUE_BITS)); - - for (ir = 0; ir < num_red; ir++) - { - /* int dr = abs(ir - r); */ - int dr = ((ir > r) ? ir - r : r - ir); - int index_r = (ir << (PNG_QUANTIZE_BLUE_BITS + - PNG_QUANTIZE_GREEN_BITS)); - - for (ig = 0; ig < num_green; ig++) - { - /* int dg = abs(ig - g); */ - int dg = ((ig > g) ? ig - g : g - ig); - int dt = dr + dg; - int dm = ((dr > dg) ? dr : dg); - int index_g = index_r | (ig << PNG_QUANTIZE_BLUE_BITS); - - for (ib = 0; ib < num_blue; ib++) - { - int d_index = index_g | ib; - /* int db = abs(ib - b); */ - int db = ((ib > b) ? ib - b : b - ib); - int dmax = ((dm > db) ? dm : db); - int d = dmax + dt + db; - - if (d < (int)distance[d_index]) - { - distance[d_index] = (png_byte)d; - png_ptr->palette_lookup[d_index] = (png_byte)i; - } - } - } - } - } - - png_free(png_ptr, distance); - } -} -#endif /* PNG_READ_QUANTIZE_SUPPORTED */ - -#ifdef PNG_READ_GAMMA_SUPPORTED -void PNGFAPI -png_set_gamma_fixed(png_structp png_ptr, png_fixed_point scrn_gamma, - png_fixed_point file_gamma) -{ - png_debug(1, "in png_set_gamma_fixed"); - - if (png_ptr == NULL) - return; - - /* New in libpng-1.5.4 - reserve particular negative values as flags. */ - scrn_gamma = translate_gamma_flags(png_ptr, scrn_gamma, 1/*screen*/); - file_gamma = translate_gamma_flags(png_ptr, file_gamma, 0/*file*/); - -#if PNG_LIBPNG_VER >= 10600 - /* Checking the gamma values for being >0 was added in 1.5.4 along with the - * premultiplied alpha support; this actually hides an undocumented feature - * of the previous implementation which allowed gamma processing to be - * disabled in background handling. There is no evidence (so far) that this - * was being used; however, png_set_background itself accepted and must still - * accept '0' for the gamma value it takes, because it isn't always used. - * - * Since this is an API change (albeit a very minor one that removes an - * undocumented API feature) it will not be made until libpng-1.6.0. - */ - if (file_gamma <= 0) - png_error(png_ptr, "invalid file gamma in png_set_gamma"); - - if (scrn_gamma <= 0) - png_error(png_ptr, "invalid screen gamma in png_set_gamma"); -#endif - - /* Set the gamma values unconditionally - this overrides the value in the PNG - * file if a gAMA chunk was present. png_set_alpha_mode provides a - * different, easier, way to default the file gamma. - */ - png_ptr->gamma = file_gamma; - png_ptr->screen_gamma = scrn_gamma; -} - -# ifdef PNG_FLOATING_POINT_SUPPORTED -void PNGAPI -png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma) -{ - png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma), - convert_gamma_value(png_ptr, file_gamma)); -} -# endif /* FLOATING_POINT_SUPPORTED */ -#endif /* READ_GAMMA */ - -#ifdef PNG_READ_EXPAND_SUPPORTED -/* Expand paletted images to RGB, expand grayscale images of - * less than 8-bit depth to 8-bit depth, and expand tRNS chunks - * to alpha channels. - */ -void PNGAPI -png_set_expand(png_structp png_ptr) -{ - png_debug(1, "in png_set_expand"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); - png_ptr->flags &= ~PNG_FLAG_ROW_INIT; -} - -/* GRR 19990627: the following three functions currently are identical - * to png_set_expand(). However, it is entirely reasonable that someone - * might wish to expand an indexed image to RGB but *not* expand a single, - * fully transparent palette entry to a full alpha channel--perhaps instead - * convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace - * the transparent color with a particular RGB value, or drop tRNS entirely. - * IOW, a future version of the library may make the transformations flag - * a bit more fine-grained, with separate bits for each of these three - * functions. - * - * More to the point, these functions make it obvious what libpng will be - * doing, whereas "expand" can (and does) mean any number of things. - * - * GRP 20060307: In libpng-1.2.9, png_set_gray_1_2_4_to_8() was modified - * to expand only the sample depth but not to expand the tRNS to alpha - * and its name was changed to png_set_expand_gray_1_2_4_to_8(). - */ - -/* Expand paletted images to RGB. */ -void PNGAPI -png_set_palette_to_rgb(png_structp png_ptr) -{ - png_debug(1, "in png_set_palette_to_rgb"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); - png_ptr->flags &= ~PNG_FLAG_ROW_INIT; -} - -/* Expand grayscale images of less than 8-bit depth to 8 bits. */ -void PNGAPI -png_set_expand_gray_1_2_4_to_8(png_structp png_ptr) -{ - png_debug(1, "in png_set_expand_gray_1_2_4_to_8"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= PNG_EXPAND; - png_ptr->flags &= ~PNG_FLAG_ROW_INIT; -} - - - -/* Expand tRNS chunks to alpha channels. */ -void PNGAPI -png_set_tRNS_to_alpha(png_structp png_ptr) -{ - png_debug(1, "in png_set_tRNS_to_alpha"); - - png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); - png_ptr->flags &= ~PNG_FLAG_ROW_INIT; -} -#endif /* defined(PNG_READ_EXPAND_SUPPORTED) */ - -#ifdef PNG_READ_EXPAND_16_SUPPORTED -/* Expand to 16-bit channels, expand the tRNS chunk too (because otherwise - * it may not work correctly.) - */ -void PNGAPI -png_set_expand_16(png_structp png_ptr) -{ - png_debug(1, "in png_set_expand_16"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= (PNG_EXPAND_16 | PNG_EXPAND | PNG_EXPAND_tRNS); - png_ptr->flags &= ~PNG_FLAG_ROW_INIT; - - /* New API, make sure apps call the correct initializers: */ - png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED; -} -#endif - -#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED -void PNGAPI -png_set_gray_to_rgb(png_structp png_ptr) -{ - png_debug(1, "in png_set_gray_to_rgb"); - - if (png_ptr != NULL) - { - /* Because rgb must be 8 bits or more: */ - png_set_expand_gray_1_2_4_to_8(png_ptr); - png_ptr->transformations |= PNG_GRAY_TO_RGB; - png_ptr->flags &= ~PNG_FLAG_ROW_INIT; - } -} -#endif - -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED -void PNGFAPI -png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, - png_fixed_point red, png_fixed_point green) -{ - png_debug(1, "in png_set_rgb_to_gray"); - - if (png_ptr == NULL) - return; - - switch(error_action) - { - case PNG_ERROR_ACTION_NONE: - png_ptr->transformations |= PNG_RGB_TO_GRAY; - break; - - case PNG_ERROR_ACTION_WARN: - png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN; - break; - - case PNG_ERROR_ACTION_ERROR: - png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR; - break; - - default: - png_error(png_ptr, "invalid error action to rgb_to_gray"); - break; - } - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) -#ifdef PNG_READ_EXPAND_SUPPORTED - png_ptr->transformations |= PNG_EXPAND; -#else - { - png_warning(png_ptr, - "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED"); - - png_ptr->transformations &= ~PNG_RGB_TO_GRAY; - } -#endif - { - if (red >= 0 && green >= 0 && red + green <= PNG_FP_1) - { - png_uint_16 red_int, green_int; - - /* NOTE: this calculation does not round, but this behavior is retained - * for consistency, the inaccuracy is very small. The code here always - * overwrites the coefficients, regardless of whether they have been - * defaulted or set already. - */ - red_int = (png_uint_16)(((png_uint_32)red*32768)/100000); - green_int = (png_uint_16)(((png_uint_32)green*32768)/100000); - - png_ptr->rgb_to_gray_red_coeff = red_int; - png_ptr->rgb_to_gray_green_coeff = green_int; - png_ptr->rgb_to_gray_coefficients_set = 1; - } - - else - { - if (red >= 0 && green >= 0) - png_warning(png_ptr, - "ignoring out of range rgb_to_gray coefficients"); - - /* Use the defaults, from the cHRM chunk if set, else the historical - * values which are close to the sRGB/HDTV/ITU-Rec 709 values. See - * png_do_rgb_to_gray for more discussion of the values. In this case - * the coefficients are not marked as 'set' and are not overwritten if - * something has already provided a default. - */ - if (png_ptr->rgb_to_gray_red_coeff == 0 && - png_ptr->rgb_to_gray_green_coeff == 0) - { - png_ptr->rgb_to_gray_red_coeff = 6968; - png_ptr->rgb_to_gray_green_coeff = 23434; - /* png_ptr->rgb_to_gray_blue_coeff = 2366; */ - } - } - } -} - -#ifdef PNG_FLOATING_POINT_SUPPORTED -/* Convert a RGB image to a grayscale of the same width. This allows us, - * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image. - */ - -void PNGAPI -png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red, - double green) -{ - if (png_ptr == NULL) - return; - - png_set_rgb_to_gray_fixed(png_ptr, error_action, - png_fixed(png_ptr, red, "rgb to gray red coefficient"), - png_fixed(png_ptr, green, "rgb to gray green coefficient")); -} -#endif /* FLOATING POINT */ - -#endif - -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) -void PNGAPI -png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr - read_user_transform_fn) -{ - png_debug(1, "in png_set_read_user_transform_fn"); - - if (png_ptr == NULL) - return; - -#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED - png_ptr->transformations |= PNG_USER_TRANSFORM; - png_ptr->read_user_transform_fn = read_user_transform_fn; -#endif -} -#endif - -#ifdef PNG_READ_TRANSFORMS_SUPPORTED -#ifdef PNG_READ_GAMMA_SUPPORTED -/* In the case of gamma transformations only do transformations on images where - * the [file] gamma and screen_gamma are not close reciprocals, otherwise it - * slows things down slightly, and also needlessly introduces small errors. - */ -static int /* PRIVATE */ -png_gamma_threshold(png_fixed_point screen_gamma, png_fixed_point file_gamma) -{ - /* PNG_GAMMA_THRESHOLD is the threshold for performing gamma - * correction as a difference of the overall transform from 1.0 - * - * We want to compare the threshold with s*f - 1, if we get - * overflow here it is because of wacky gamma values so we - * turn on processing anyway. - */ - png_fixed_point gtest; - return !png_muldiv(>est, screen_gamma, file_gamma, PNG_FP_1) || - png_gamma_significant(gtest); -} -#endif - -/* Initialize everything needed for the read. This includes modifying - * the palette. - */ - -/*For the moment 'png_init_palette_transformations' and - * 'png_init_rgb_transformations' only do some flag canceling optimizations. - * The intent is that these two routines should have palette or rgb operations - * extracted from 'png_init_read_transformations'. - */ -static void /* PRIVATE */ -png_init_palette_transformations(png_structp png_ptr) -{ - /* Called to handle the (input) palette case. In png_do_read_transformations - * the first step is to expand the palette if requested, so this code must - * take care to only make changes that are invariant with respect to the - * palette expansion, or only do them if there is no expansion. - * - * STRIP_ALPHA has already been handled in the caller (by setting num_trans - * to 0.) - */ - int input_has_alpha = 0; - int input_has_transparency = 0; - - if (png_ptr->num_trans > 0) - { - int i; - - /* Ignore if all the entries are opaque (unlikely!) */ - for (i=0; inum_trans; ++i) - if (png_ptr->trans_alpha[i] == 255) - continue; - else if (png_ptr->trans_alpha[i] == 0) - input_has_transparency = 1; - else - input_has_alpha = 1; - } - - /* If no alpha we can optimize. */ - if (!input_has_alpha) - { - /* Any alpha means background and associative alpha processing is - * required, however if the alpha is 0 or 1 throughout OPTIIMIZE_ALPHA - * and ENCODE_ALPHA are irrelevant. - */ - png_ptr->transformations &= ~PNG_ENCODE_ALPHA; - png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; - - if (!input_has_transparency) - png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND); - } - -#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) - /* png_set_background handling - deals with the complexity of whether the - * background color is in the file format or the screen format in the case - * where an 'expand' will happen. - */ - - /* The following code cannot be entered in the alpha pre-multiplication case - * because PNG_BACKGROUND_EXPAND is cancelled below. - */ - if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) && - (png_ptr->transformations & PNG_EXPAND)) - { - { - png_ptr->background.red = - png_ptr->palette[png_ptr->background.index].red; - png_ptr->background.green = - png_ptr->palette[png_ptr->background.index].green; - png_ptr->background.blue = - png_ptr->palette[png_ptr->background.index].blue; - -#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED - if (png_ptr->transformations & PNG_INVERT_ALPHA) - { - if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) - { - /* Invert the alpha channel (in tRNS) unless the pixels are - * going to be expanded, in which case leave it for later - */ - int i, istop = png_ptr->num_trans; - - for (i=0; itrans_alpha[i] = (png_byte)(255 - - png_ptr->trans_alpha[i]); - } - } -#endif /* PNG_READ_INVERT_ALPHA_SUPPORTED */ - } - } /* background expand and (therefore) no alpha association. */ -#endif /* PNG_READ_EXPAND_SUPPORTED && PNG_READ_BACKGROUND_SUPPORTED */ -} - -static void /* PRIVATE */ -png_init_rgb_transformations(png_structp png_ptr) -{ - /* Added to libpng-1.5.4: check the color type to determine whether there - * is any alpha or transparency in the image and simply cancel the - * background and alpha mode stuff if there isn't. - */ - int input_has_alpha = (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0; - int input_has_transparency = png_ptr->num_trans > 0; - - /* If no alpha we can optimize. */ - if (!input_has_alpha) - { - /* Any alpha means background and associative alpha processing is - * required, however if the alpha is 0 or 1 throughout OPTIIMIZE_ALPHA - * and ENCODE_ALPHA are irrelevant. - */ -# ifdef PNG_READ_ALPHA_MODE_SUPPORTED - png_ptr->transformations &= ~PNG_ENCODE_ALPHA; - png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; -# endif - - if (!input_has_transparency) - png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND); - } - -#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) - /* png_set_background handling - deals with the complexity of whether the - * background color is in the file format or the screen format in the case - * where an 'expand' will happen. - */ - - /* The following code cannot be entered in the alpha pre-multiplication case - * because PNG_BACKGROUND_EXPAND is cancelled below. - */ - if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) && - (png_ptr->transformations & PNG_EXPAND) && - !(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) - /* i.e., GRAY or GRAY_ALPHA */ - { - { - /* Expand background and tRNS chunks */ - int gray = png_ptr->background.gray; - int trans_gray = png_ptr->trans_color.gray; - - switch (png_ptr->bit_depth) - { - case 1: - gray *= 0xff; - trans_gray *= 0xff; - break; - - case 2: - gray *= 0x55; - trans_gray *= 0x55; - break; - - case 4: - gray *= 0x11; - trans_gray *= 0x11; - break; - - default: - - case 8: - /* Already 8 bits, fall through */ - - case 16: - /* Already a full 16 bits */ - break; - } - - png_ptr->background.red = png_ptr->background.green = - png_ptr->background.blue = (png_uint_16)gray; - - if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) - { - png_ptr->trans_color.red = png_ptr->trans_color.green = - png_ptr->trans_color.blue = (png_uint_16)trans_gray; - } - } - } /* background expand and (therefore) no alpha association. */ -#endif /* PNG_READ_EXPAND_SUPPORTED && PNG_READ_BACKGROUND_SUPPORTED */ -} - -void /* PRIVATE */ -png_init_read_transformations(png_structp png_ptr) -{ - png_debug(1, "in png_init_read_transformations"); - - /* This internal function is called from png_read_start_row in pngrutil.c - * and it is called before the 'rowbytes' calculation is done, so the code - * in here can change or update the transformations flags. - * - * First do updates that do not depend on the details of the PNG image data - * being processed. - */ - -#ifdef PNG_READ_GAMMA_SUPPORTED - /* Prior to 1.5.4 these tests were performed from png_set_gamma, 1.5.4 adds - * png_set_alpha_mode and this is another source for a default file gamma so - * the test needs to be performed later - here. In addition prior to 1.5.4 - * the tests were repeated for the PALETTE color type here - this is no - * longer necessary (and doesn't seem to have been necessary before.) - */ - { - /* The following temporary indicates if overall gamma correction is - * required. - */ - int gamma_correction = 0; - - if (png_ptr->gamma != 0) /* has been set */ - { - if (png_ptr->screen_gamma != 0) /* screen set too */ - gamma_correction = png_gamma_threshold(png_ptr->gamma, - png_ptr->screen_gamma); - - else - /* Assume the output matches the input; a long time default behavior - * of libpng, although the standard has nothing to say about this. - */ - png_ptr->screen_gamma = png_reciprocal(png_ptr->gamma); - } - - else if (png_ptr->screen_gamma != 0) - /* The converse - assume the file matches the screen, note that this - * perhaps undesireable default can (from 1.5.4) be changed by calling - * png_set_alpha_mode (even if the alpha handling mode isn't required - * or isn't changed from the default.) - */ - png_ptr->gamma = png_reciprocal(png_ptr->screen_gamma); - - else /* neither are set */ - /* Just in case the following prevents any processing - file and screen - * are both assumed to be linear and there is no way to introduce a - * third gamma value other than png_set_background with 'UNIQUE', and, - * prior to 1.5.4 - */ - png_ptr->screen_gamma = png_ptr->gamma = PNG_FP_1; - - /* Now turn the gamma transformation on or off as appropriate. Notice - * that PNG_GAMMA just refers to the file->screen correction. Alpha - * composition may independently cause gamma correction because it needs - * linear data (e.g. if the file has a gAMA chunk but the screen gamma - * hasn't been specified.) In any case this flag may get turned off in - * the code immediately below if the transform can be handled outside the - * row loop. - */ - if (gamma_correction) - png_ptr->transformations |= PNG_GAMMA; - - else - png_ptr->transformations &= ~PNG_GAMMA; - } -#endif - - /* Certain transformations have the effect of preventing other - * transformations that happen afterward in png_do_read_transformations, - * resolve the interdependencies here. From the code of - * png_do_read_transformations the order is: - * - * 1) PNG_EXPAND (including PNG_EXPAND_tRNS) - * 2) PNG_STRIP_ALPHA (if no compose) - * 3) PNG_RGB_TO_GRAY - * 4) PNG_GRAY_TO_RGB iff !PNG_BACKGROUND_IS_GRAY - * 5) PNG_COMPOSE - * 6) PNG_GAMMA - * 7) PNG_STRIP_ALPHA (if compose) - * 8) PNG_ENCODE_ALPHA - * 9) PNG_SCALE_16_TO_8 - * 10) PNG_16_TO_8 - * 11) PNG_QUANTIZE (converts to palette) - * 12) PNG_EXPAND_16 - * 13) PNG_GRAY_TO_RGB iff PNG_BACKGROUND_IS_GRAY - * 14) PNG_INVERT_MONO - * 15) PNG_SHIFT - * 16) PNG_PACK - * 17) PNG_BGR - * 18) PNG_PACKSWAP - * 19) PNG_FILLER (includes PNG_ADD_ALPHA) - * 20) PNG_INVERT_ALPHA - * 21) PNG_SWAP_ALPHA - * 22) PNG_SWAP_BYTES - * 23) PNG_USER_TRANSFORM [must be last] - */ -#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED - if ((png_ptr->transformations & PNG_STRIP_ALPHA) && - !(png_ptr->transformations & PNG_COMPOSE)) - { - /* Stripping the alpha channel happens immediately after the 'expand' - * transformations, before all other transformation, so it cancels out - * the alpha handling. It has the side effect negating the effect of - * PNG_EXPAND_tRNS too: - */ - png_ptr->transformations &= ~(PNG_BACKGROUND_EXPAND | PNG_ENCODE_ALPHA | - PNG_EXPAND_tRNS); - png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; - - /* Kill the tRNS chunk itself too. Prior to 1.5.4 this did not happen - * so transparency information would remain just so long as it wasn't - * expanded. This produces unexpected API changes if the set of things - * that do PNG_EXPAND_tRNS changes (perfectly possible given the - * documentation - which says ask for what you want, accept what you - * get.) This makes the behavior consistent from 1.5.4: - */ - png_ptr->num_trans = 0; - } -#endif /* STRIP_ALPHA supported, no COMPOSE */ - -#ifdef PNG_READ_ALPHA_MODE_SUPPORTED - /* If the screen gamma is about 1.0 then the OPTIMIZE_ALPHA and ENCODE_ALPHA - * settings will have no effect. - */ - if (!png_gamma_significant(png_ptr->screen_gamma)) - { - png_ptr->transformations &= ~PNG_ENCODE_ALPHA; - png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; - } -#endif - -#if defined(PNG_READ_EXPAND_SUPPORTED) && \ - defined(PNG_READ_BACKGROUND_SUPPORTED) && \ - defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) - /* Detect gray background and attempt to enable optimization for - * gray --> RGB case. - * - * Note: if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or - * RGB_ALPHA (in which case need_expand is superfluous anyway), the - * background color might actually be gray yet not be flagged as such. - * This is not a problem for the current code, which uses - * PNG_BACKGROUND_IS_GRAY only to decide when to do the - * png_do_gray_to_rgb() transformation. - * - * TODO: this code needs to be revised to avoid the complexity and - * interdependencies. The color type of the background should be recorded in - * png_set_background, along with the bit depth, then the code has a record - * of exactly what color space the background is currently in. - */ - if (png_ptr->transformations & PNG_BACKGROUND_EXPAND) - { - /* PNG_BACKGROUND_EXPAND: the background is in the file color space, so if - * the file was grayscale the background value is gray. - */ - if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) - png_ptr->mode |= PNG_BACKGROUND_IS_GRAY; - } - - else if (png_ptr->transformations & PNG_COMPOSE) - { - /* PNG_COMPOSE: png_set_background was called with need_expand false, - * so the color is in the color space of the output or png_set_alpha_mode - * was called and the color is black. Ignore RGB_TO_GRAY because that - * happens before GRAY_TO_RGB. - */ - if (png_ptr->transformations & PNG_GRAY_TO_RGB) - { - if (png_ptr->background.red == png_ptr->background.green && - png_ptr->background.red == png_ptr->background.blue) - { - png_ptr->mode |= PNG_BACKGROUND_IS_GRAY; - png_ptr->background.gray = png_ptr->background.red; - } - } - } -#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED (etc) */ - - /* For indexed PNG data (PNG_COLOR_TYPE_PALETTE) many of the transformations - * can be performed directly on the palette, and some (such as rgb to gray) - * can be optimized inside the palette. This is particularly true of the - * composite (background and alpha) stuff, which can be pretty much all done - * in the palette even if the result is expanded to RGB or gray afterward. - * - * NOTE: this is Not Yet Implemented, the code behaves as in 1.5.1 and - * earlier and the palette stuff is actually handled on the first row. This - * leads to the reported bug that the palette returned by png_get_PLTE is not - * updated. - */ - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - png_init_palette_transformations(png_ptr); - - else - png_init_rgb_transformations(png_ptr); - -#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ - defined(PNG_READ_EXPAND_16_SUPPORTED) - if ((png_ptr->transformations & PNG_EXPAND_16) && - (png_ptr->transformations & PNG_COMPOSE) && - !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) && - png_ptr->bit_depth != 16) - { - /* TODO: fix this. Because the expand_16 operation is after the compose - * handling the background color must be 8, not 16, bits deep, but the - * application will supply a 16-bit value so reduce it here. - * - * The PNG_BACKGROUND_EXPAND code above does not expand to 16 bits at - * present, so that case is ok (until do_expand_16 is moved.) - * - * NOTE: this discards the low 16 bits of the user supplied background - * color, but until expand_16 works properly there is no choice! - */ -# define CHOP(x) (x)=((png_uint_16)(((png_uint_32)(x)*255+32895) >> 16)) - CHOP(png_ptr->background.red); - CHOP(png_ptr->background.green); - CHOP(png_ptr->background.blue); - CHOP(png_ptr->background.gray); -# undef CHOP - } -#endif /* PNG_READ_BACKGROUND_SUPPORTED && PNG_READ_EXPAND_16_SUPPORTED */ - -#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ - (defined(PNG_READ_SCALE_16_TO_8_SUPPORTED) || \ - defined(PNG_READ_STRIP_16_TO_8_SUPPORTED)) - if ((png_ptr->transformations & (PNG_16_TO_8|PNG_SCALE_16_TO_8)) && - (png_ptr->transformations & PNG_COMPOSE) && - !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) && - png_ptr->bit_depth == 16) - { - /* On the other hand, if a 16-bit file is to be reduced to 8-bits per - * component this will also happen after PNG_COMPOSE and so the background - * color must be pre-expanded here. - * - * TODO: fix this too. - */ - png_ptr->background.red = (png_uint_16)(png_ptr->background.red * 257); - png_ptr->background.green = - (png_uint_16)(png_ptr->background.green * 257); - png_ptr->background.blue = (png_uint_16)(png_ptr->background.blue * 257); - png_ptr->background.gray = (png_uint_16)(png_ptr->background.gray * 257); - } -#endif - - /* NOTE: below 'PNG_READ_ALPHA_MODE_SUPPORTED' is presumed to also enable the - * background support (see the comments in scripts/pnglibconf.dfa), this - * allows pre-multiplication of the alpha channel to be implemented as - * compositing on black. This is probably sub-optimal and has been done in - * 1.5.4 betas simply to enable external critique and testing (i.e. to - * implement the new API quickly, without lots of internal changes.) - */ - -#ifdef PNG_READ_GAMMA_SUPPORTED -# ifdef PNG_READ_BACKGROUND_SUPPORTED - /* Includes ALPHA_MODE */ - png_ptr->background_1 = png_ptr->background; -# endif - - /* This needs to change - in the palette image case a whole set of tables are - * built when it would be quicker to just calculate the correct value for - * each palette entry directly. Also, the test is too tricky - why check - * PNG_RGB_TO_GRAY if PNG_GAMMA is not set? The answer seems to be that - * PNG_GAMMA is cancelled even if the gamma is known? The test excludes the - * PNG_COMPOSE case, so apparently if there is no *overall* gamma correction - * the gamma tables will not be built even if composition is required on a - * gamma encoded value. - * - * In 1.5.4 this is addressed below by an additional check on the individual - * file gamma - if it is not 1.0 both RGB_TO_GRAY and COMPOSE need the - * tables. - */ - if ((png_ptr->transformations & PNG_GAMMA) - || ((png_ptr->transformations & PNG_RGB_TO_GRAY) - && (png_gamma_significant(png_ptr->gamma) || - png_gamma_significant(png_ptr->screen_gamma))) - || ((png_ptr->transformations & PNG_COMPOSE) - && (png_gamma_significant(png_ptr->gamma) - || png_gamma_significant(png_ptr->screen_gamma) -# ifdef PNG_READ_BACKGROUND_SUPPORTED - || (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_UNIQUE - && png_gamma_significant(png_ptr->background_gamma)) -# endif - )) || ((png_ptr->transformations & PNG_ENCODE_ALPHA) - && png_gamma_significant(png_ptr->screen_gamma)) - ) - { - png_build_gamma_table(png_ptr, png_ptr->bit_depth); - -#ifdef PNG_READ_BACKGROUND_SUPPORTED - if (png_ptr->transformations & PNG_COMPOSE) - { - /* Issue a warning about this combination: because RGB_TO_GRAY is - * optimized to do the gamma transform if present yet do_background has - * to do the same thing if both options are set a - * double-gamma-correction happens. This is true in all versions of - * libpng to date. - */ - if (png_ptr->transformations & PNG_RGB_TO_GRAY) - png_warning(png_ptr, - "libpng does not support gamma+background+rgb_to_gray"); - - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - { - /* We don't get to here unless there is a tRNS chunk with non-opaque - * entries - see the checking code at the start of this function. - */ - png_color back, back_1; - png_colorp palette = png_ptr->palette; - int num_palette = png_ptr->num_palette; - int i; - if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE) - { - - back.red = png_ptr->gamma_table[png_ptr->background.red]; - back.green = png_ptr->gamma_table[png_ptr->background.green]; - back.blue = png_ptr->gamma_table[png_ptr->background.blue]; - - back_1.red = png_ptr->gamma_to_1[png_ptr->background.red]; - back_1.green = png_ptr->gamma_to_1[png_ptr->background.green]; - back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue]; - } - else - { - png_fixed_point g, gs; - - switch (png_ptr->background_gamma_type) - { - case PNG_BACKGROUND_GAMMA_SCREEN: - g = (png_ptr->screen_gamma); - gs = PNG_FP_1; - break; - - case PNG_BACKGROUND_GAMMA_FILE: - g = png_reciprocal(png_ptr->gamma); - gs = png_reciprocal2(png_ptr->gamma, - png_ptr->screen_gamma); - break; - - case PNG_BACKGROUND_GAMMA_UNIQUE: - g = png_reciprocal(png_ptr->background_gamma); - gs = png_reciprocal2(png_ptr->background_gamma, - png_ptr->screen_gamma); - break; - default: - g = PNG_FP_1; /* back_1 */ - gs = PNG_FP_1; /* back */ - break; - } - - if (png_gamma_significant(gs)) - { - back.red = png_gamma_8bit_correct(png_ptr->background.red, - gs); - back.green = png_gamma_8bit_correct(png_ptr->background.green, - gs); - back.blue = png_gamma_8bit_correct(png_ptr->background.blue, - gs); - } - - else - { - back.red = (png_byte)png_ptr->background.red; - back.green = (png_byte)png_ptr->background.green; - back.blue = (png_byte)png_ptr->background.blue; - } - - if (png_gamma_significant(g)) - { - back_1.red = png_gamma_8bit_correct(png_ptr->background.red, - g); - back_1.green = png_gamma_8bit_correct( - png_ptr->background.green, g); - back_1.blue = png_gamma_8bit_correct(png_ptr->background.blue, - g); - } - - else - { - back_1.red = (png_byte)png_ptr->background.red; - back_1.green = (png_byte)png_ptr->background.green; - back_1.blue = (png_byte)png_ptr->background.blue; - } - } - - for (i = 0; i < num_palette; i++) - { - if (i < (int)png_ptr->num_trans && - png_ptr->trans_alpha[i] != 0xff) - { - if (png_ptr->trans_alpha[i] == 0) - { - palette[i] = back; - } - else /* if (png_ptr->trans_alpha[i] != 0xff) */ - { - png_byte v, w; - - v = png_ptr->gamma_to_1[palette[i].red]; - png_composite(w, v, png_ptr->trans_alpha[i], back_1.red); - palette[i].red = png_ptr->gamma_from_1[w]; - - v = png_ptr->gamma_to_1[palette[i].green]; - png_composite(w, v, png_ptr->trans_alpha[i], back_1.green); - palette[i].green = png_ptr->gamma_from_1[w]; - - v = png_ptr->gamma_to_1[palette[i].blue]; - png_composite(w, v, png_ptr->trans_alpha[i], back_1.blue); - palette[i].blue = png_ptr->gamma_from_1[w]; - } - } - else - { - palette[i].red = png_ptr->gamma_table[palette[i].red]; - palette[i].green = png_ptr->gamma_table[palette[i].green]; - palette[i].blue = png_ptr->gamma_table[palette[i].blue]; - } - } - - /* Prevent the transformations being done again. - * - * NOTE: this is highly dubious; it removes the transformations in - * place. This seems inconsistent with the general treatment of the - * transformations elsewhere. - */ - png_ptr->transformations &= ~(PNG_COMPOSE | PNG_GAMMA); - } /* color_type == PNG_COLOR_TYPE_PALETTE */ - - /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */ - else /* color_type != PNG_COLOR_TYPE_PALETTE */ - { - int gs_sig, g_sig; - png_fixed_point g = PNG_FP_1; /* Correction to linear */ - png_fixed_point gs = PNG_FP_1; /* Correction to screen */ - - switch (png_ptr->background_gamma_type) - { - case PNG_BACKGROUND_GAMMA_SCREEN: - g = png_ptr->screen_gamma; - /* gs = PNG_FP_1; */ - break; - - case PNG_BACKGROUND_GAMMA_FILE: - g = png_reciprocal(png_ptr->gamma); - gs = png_reciprocal2(png_ptr->gamma, png_ptr->screen_gamma); - break; - - case PNG_BACKGROUND_GAMMA_UNIQUE: - g = png_reciprocal(png_ptr->background_gamma); - gs = png_reciprocal2(png_ptr->background_gamma, - png_ptr->screen_gamma); - break; - - default: - png_error(png_ptr, "invalid background gamma type"); - } - - g_sig = png_gamma_significant(g); - gs_sig = png_gamma_significant(gs); - - if (g_sig) - png_ptr->background_1.gray = png_gamma_correct(png_ptr, - png_ptr->background.gray, g); - - if (gs_sig) - png_ptr->background.gray = png_gamma_correct(png_ptr, - png_ptr->background.gray, gs); - - if ((png_ptr->background.red != png_ptr->background.green) || - (png_ptr->background.red != png_ptr->background.blue) || - (png_ptr->background.red != png_ptr->background.gray)) - { - /* RGB or RGBA with color background */ - if (g_sig) - { - png_ptr->background_1.red = png_gamma_correct(png_ptr, - png_ptr->background.red, g); - - png_ptr->background_1.green = png_gamma_correct(png_ptr, - png_ptr->background.green, g); - - png_ptr->background_1.blue = png_gamma_correct(png_ptr, - png_ptr->background.blue, g); - } - - if (gs_sig) - { - png_ptr->background.red = png_gamma_correct(png_ptr, - png_ptr->background.red, gs); - - png_ptr->background.green = png_gamma_correct(png_ptr, - png_ptr->background.green, gs); - - png_ptr->background.blue = png_gamma_correct(png_ptr, - png_ptr->background.blue, gs); - } - } - - else - { - /* GRAY, GRAY ALPHA, RGB, or RGBA with gray background */ - png_ptr->background_1.red = png_ptr->background_1.green - = png_ptr->background_1.blue = png_ptr->background_1.gray; - - png_ptr->background.red = png_ptr->background.green - = png_ptr->background.blue = png_ptr->background.gray; - } - - /* The background is now in screen gamma: */ - png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_SCREEN; - } /* color_type != PNG_COLOR_TYPE_PALETTE */ - }/* png_ptr->transformations & PNG_BACKGROUND */ - - else - /* Transformation does not include PNG_BACKGROUND */ -#endif /* PNG_READ_BACKGROUND_SUPPORTED */ - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED - /* RGB_TO_GRAY needs to have non-gamma-corrected values! */ - && ((png_ptr->transformations & PNG_EXPAND) == 0 || - (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0) -#endif - ) - { - png_colorp palette = png_ptr->palette; - int num_palette = png_ptr->num_palette; - int i; - - /* NOTE: there are other transformations that should probably be in - * here too. - */ - for (i = 0; i < num_palette; i++) - { - palette[i].red = png_ptr->gamma_table[palette[i].red]; - palette[i].green = png_ptr->gamma_table[palette[i].green]; - palette[i].blue = png_ptr->gamma_table[palette[i].blue]; - } - - /* Done the gamma correction. */ - png_ptr->transformations &= ~PNG_GAMMA; - } /* color_type == PALETTE && !PNG_BACKGROUND transformation */ - } -#ifdef PNG_READ_BACKGROUND_SUPPORTED - else -#endif -#endif /* PNG_READ_GAMMA_SUPPORTED */ - -#ifdef PNG_READ_BACKGROUND_SUPPORTED - /* No GAMMA transformation (see the hanging else 4 lines above) */ - if ((png_ptr->transformations & PNG_COMPOSE) && - (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) - { - int i; - int istop = (int)png_ptr->num_trans; - png_color back; - png_colorp palette = png_ptr->palette; - - back.red = (png_byte)png_ptr->background.red; - back.green = (png_byte)png_ptr->background.green; - back.blue = (png_byte)png_ptr->background.blue; - - for (i = 0; i < istop; i++) - { - if (png_ptr->trans_alpha[i] == 0) - { - palette[i] = back; - } - - else if (png_ptr->trans_alpha[i] != 0xff) - { - /* The png_composite() macro is defined in png.h */ - png_composite(palette[i].red, palette[i].red, - png_ptr->trans_alpha[i], back.red); - - png_composite(palette[i].green, palette[i].green, - png_ptr->trans_alpha[i], back.green); - - png_composite(palette[i].blue, palette[i].blue, - png_ptr->trans_alpha[i], back.blue); - } - } - - png_ptr->transformations &= ~PNG_COMPOSE; - } -#endif /* PNG_READ_BACKGROUND_SUPPORTED */ - -#ifdef PNG_READ_SHIFT_SUPPORTED - if ((png_ptr->transformations & PNG_SHIFT) && - !(png_ptr->transformations & PNG_EXPAND) && - (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) - { - int i; - int istop = png_ptr->num_palette; - int shift = 8 - png_ptr->sig_bit.red; - - png_ptr->transformations &= ~PNG_SHIFT; - - /* significant bits can be in the range 1 to 7 for a meaninful result, if - * the number of significant bits is 0 then no shift is done (this is an - * error condition which is silently ignored.) - */ - if (shift > 0 && shift < 8) for (i=0; ipalette[i].red; - - component >>= shift; - png_ptr->palette[i].red = (png_byte)component; - } - - shift = 8 - png_ptr->sig_bit.green; - if (shift > 0 && shift < 8) for (i=0; ipalette[i].green; - - component >>= shift; - png_ptr->palette[i].green = (png_byte)component; - } - - shift = 8 - png_ptr->sig_bit.blue; - if (shift > 0 && shift < 8) for (i=0; ipalette[i].blue; - - component >>= shift; - png_ptr->palette[i].blue = (png_byte)component; - } - } -#endif /* PNG_READ_SHIFT_SUPPORTED */ -} - -/* Modify the info structure to reflect the transformations. The - * info should be updated so a PNG file could be written with it, - * assuming the transformations result in valid PNG data. - */ -void /* PRIVATE */ -png_read_transform_info(png_structp png_ptr, png_infop info_ptr) -{ - png_debug(1, "in png_read_transform_info"); - -#ifdef PNG_READ_EXPAND_SUPPORTED - if (png_ptr->transformations & PNG_EXPAND) - { - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - { - /* This check must match what actually happens in - * png_do_expand_palette; if it ever checks the tRNS chunk to see if - * it is all opaque we must do the same (at present it does not.) - */ - if (png_ptr->num_trans > 0) - info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA; - - else - info_ptr->color_type = PNG_COLOR_TYPE_RGB; - - info_ptr->bit_depth = 8; - info_ptr->num_trans = 0; - } - else - { - if (png_ptr->num_trans) - { - if (png_ptr->transformations & PNG_EXPAND_tRNS) - info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; - } - if (info_ptr->bit_depth < 8) - info_ptr->bit_depth = 8; - - info_ptr->num_trans = 0; - } - } -#endif - -#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ - defined(PNG_READ_ALPHA_MODE_SUPPORTED) - /* The following is almost certainly wrong unless the background value is in - * the screen space! - */ - if (png_ptr->transformations & PNG_COMPOSE) - info_ptr->background = png_ptr->background; -#endif - -#ifdef PNG_READ_GAMMA_SUPPORTED - /* The following used to be conditional on PNG_GAMMA (prior to 1.5.4), - * however it seems that the code in png_init_read_transformations, which has - * been called before this from png_read_update_info->png_read_start_row - * sometimes does the gamma transform and cancels the flag. - */ - info_ptr->gamma = png_ptr->gamma; -#endif - - if (info_ptr->bit_depth == 16) - { -# ifdef PNG_READ_16BIT_SUPPORTED -# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED - if (png_ptr->transformations & PNG_SCALE_16_TO_8) - info_ptr->bit_depth = 8; -# endif - -# ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED - if (png_ptr->transformations & PNG_16_TO_8) - info_ptr->bit_depth = 8; -# endif - -# else - /* No 16 bit support: force chopping 16-bit input down to 8, in this case - * the app program can chose if both APIs are available by setting the - * correct scaling to use. - */ -# ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED - /* For compatibility with previous versions use the strip method by - * default. This code works because if PNG_SCALE_16_TO_8 is already - * set the code below will do that in preference to the chop. - */ - png_ptr->transformations |= PNG_16_TO_8; - info_ptr->bit_depth = 8; -# else - -# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED - png_ptr->transformations |= PNG_SCALE_16_TO_8; - info_ptr->bit_depth = 8; -# else - - CONFIGURATION ERROR: you must enable at least one 16 to 8 method -# endif -# endif -#endif /* !READ_16BIT_SUPPORTED */ - } - -#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED - if (png_ptr->transformations & PNG_GRAY_TO_RGB) - info_ptr->color_type = (png_byte)(info_ptr->color_type | - PNG_COLOR_MASK_COLOR); -#endif - -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED - if (png_ptr->transformations & PNG_RGB_TO_GRAY) - info_ptr->color_type = (png_byte)(info_ptr->color_type & - ~PNG_COLOR_MASK_COLOR); -#endif - -#ifdef PNG_READ_QUANTIZE_SUPPORTED - if (png_ptr->transformations & PNG_QUANTIZE) - { - if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || - (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) && - png_ptr->palette_lookup && info_ptr->bit_depth == 8) - { - info_ptr->color_type = PNG_COLOR_TYPE_PALETTE; - } - } -#endif - -#ifdef PNG_READ_EXPAND_16_SUPPORTED - if (png_ptr->transformations & PNG_EXPAND_16 && info_ptr->bit_depth == 8 && - info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) - { - info_ptr->bit_depth = 16; - } -#endif - -#ifdef PNG_READ_PACK_SUPPORTED - if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8)) - info_ptr->bit_depth = 8; -#endif - - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - info_ptr->channels = 1; - - else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) - info_ptr->channels = 3; - - else - info_ptr->channels = 1; - -#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED - if (png_ptr->transformations & PNG_STRIP_ALPHA) - { - info_ptr->color_type = (png_byte)(info_ptr->color_type & - ~PNG_COLOR_MASK_ALPHA); - info_ptr->num_trans = 0; - } -#endif - - if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) - info_ptr->channels++; - -#ifdef PNG_READ_FILLER_SUPPORTED - /* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */ - if ((png_ptr->transformations & PNG_FILLER) && - ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || - (info_ptr->color_type == PNG_COLOR_TYPE_GRAY))) - { - info_ptr->channels++; - /* If adding a true alpha channel not just filler */ - if (png_ptr->transformations & PNG_ADD_ALPHA) - info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; - } -#endif - -#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \ -defined(PNG_READ_USER_TRANSFORM_SUPPORTED) - if (png_ptr->transformations & PNG_USER_TRANSFORM) - { - if (info_ptr->bit_depth < png_ptr->user_transform_depth) - info_ptr->bit_depth = png_ptr->user_transform_depth; - - if (info_ptr->channels < png_ptr->user_transform_channels) - info_ptr->channels = png_ptr->user_transform_channels; - } -#endif - - info_ptr->pixel_depth = (png_byte)(info_ptr->channels * - info_ptr->bit_depth); - - info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width); - - /* Adding in 1.5.4: cache the above value in png_struct so that we can later - * check in png_rowbytes that the user buffer won't get overwritten. Note - * that the field is not always set - if png_read_update_info isn't called - * the application has to either not do any transforms or get the calculation - * right itself. - */ - png_ptr->info_rowbytes = info_ptr->rowbytes; - -#ifndef PNG_READ_EXPAND_SUPPORTED - if (png_ptr) - return; -#endif -} - -/* Transform the row. The order of transformations is significant, - * and is very touchy. If you add a transformation, take care to - * decide how it fits in with the other transformations here. - */ -void /* PRIVATE */ -png_do_read_transformations(png_structp png_ptr, png_row_infop row_info) -{ - png_debug(1, "in png_do_read_transformations"); - - if (png_ptr->row_buf == NULL) - { - /* Prior to 1.5.4 this output row/pass where the NULL pointer is, but this - * error is incredibly rare and incredibly easy to debug without this - * information. - */ - png_error(png_ptr, "NULL row buffer"); - } - - /* The following is debugging; prior to 1.5.4 the code was never compiled in; - * in 1.5.4 PNG_FLAG_DETECT_UNINITIALIZED was added and the macro - * PNG_WARN_UNINITIALIZED_ROW removed. In 1.5 the new flag is set only for - * selected new APIs to ensure that there is no API change. - */ - if ((png_ptr->flags & PNG_FLAG_DETECT_UNINITIALIZED) != 0 && - !(png_ptr->flags & PNG_FLAG_ROW_INIT)) - { - /* Application has failed to call either png_read_start_image() or - * png_read_update_info() after setting transforms that expand pixels. - * This check added to libpng-1.2.19 (but not enabled until 1.5.4). - */ - png_error(png_ptr, "Uninitialized row"); - } - -#ifdef PNG_READ_EXPAND_SUPPORTED - if (png_ptr->transformations & PNG_EXPAND) - { - if (row_info->color_type == PNG_COLOR_TYPE_PALETTE) - { - png_do_expand_palette(row_info, png_ptr->row_buf + 1, - png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans); - } - - else - { - if (png_ptr->num_trans && - (png_ptr->transformations & PNG_EXPAND_tRNS)) - png_do_expand(row_info, png_ptr->row_buf + 1, - &(png_ptr->trans_color)); - - else - png_do_expand(row_info, png_ptr->row_buf + 1, - NULL); - } - } -#endif - -#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED - if ((png_ptr->transformations & PNG_STRIP_ALPHA) && - !(png_ptr->transformations & PNG_COMPOSE) && - (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA || - row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) - png_do_strip_channel(row_info, png_ptr->row_buf + 1, - 0 /* at_start == false, because SWAP_ALPHA happens later */); -#endif - -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED - if (png_ptr->transformations & PNG_RGB_TO_GRAY) - { - int rgb_error = - png_do_rgb_to_gray(png_ptr, row_info, - png_ptr->row_buf + 1); - - if (rgb_error) - { - png_ptr->rgb_to_gray_status=1; - if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == - PNG_RGB_TO_GRAY_WARN) - png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel"); - - if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == - PNG_RGB_TO_GRAY_ERR) - png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel"); - } - } -#endif - -/* From Andreas Dilger e-mail to png-implement, 26 March 1998: - * - * In most cases, the "simple transparency" should be done prior to doing - * gray-to-RGB, or you will have to test 3x as many bytes to check if a - * pixel is transparent. You would also need to make sure that the - * transparency information is upgraded to RGB. - * - * To summarize, the current flow is: - * - Gray + simple transparency -> compare 1 or 2 gray bytes and composite - * with background "in place" if transparent, - * convert to RGB if necessary - * - Gray + alpha -> composite with gray background and remove alpha bytes, - * convert to RGB if necessary - * - * To support RGB backgrounds for gray images we need: - * - Gray + simple transparency -> convert to RGB + simple transparency, - * compare 3 or 6 bytes and composite with - * background "in place" if transparent - * (3x compare/pixel compared to doing - * composite with gray bkgrnd) - * - Gray + alpha -> convert to RGB + alpha, composite with background and - * remove alpha bytes (3x float - * operations/pixel compared with composite - * on gray background) - * - * Greg's change will do this. The reason it wasn't done before is for - * performance, as this increases the per-pixel operations. If we would check - * in advance if the background was gray or RGB, and position the gray-to-RGB - * transform appropriately, then it would save a lot of work/time. - */ - -#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED - /* If gray -> RGB, do so now only if background is non-gray; else do later - * for performance reasons - */ - if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && - !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) - png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1); -#endif - -#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\ - (defined PNG_READ_ALPHA_MODE_SUPPORTED) - if (png_ptr->transformations & PNG_COMPOSE) - png_do_compose(row_info, png_ptr->row_buf + 1, png_ptr); -#endif - -#ifdef PNG_READ_GAMMA_SUPPORTED - if ((png_ptr->transformations & PNG_GAMMA) && -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED - /* Because RGB_TO_GRAY does the gamma transform. */ - !(png_ptr->transformations & PNG_RGB_TO_GRAY) && -#endif -#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\ - (defined PNG_READ_ALPHA_MODE_SUPPORTED) - /* Because PNG_COMPOSE does the gamma transform if there is something to - * do (if there is an alpha channel or transparency.) - */ - !((png_ptr->transformations & PNG_COMPOSE) && - ((png_ptr->num_trans != 0) || - (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) && -#endif - /* Because png_init_read_transformations transforms the palette, unless - * RGB_TO_GRAY will do the transform. - */ - (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)) - png_do_gamma(row_info, png_ptr->row_buf + 1, png_ptr); -#endif - -#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED - if ((png_ptr->transformations & PNG_STRIP_ALPHA) && - (png_ptr->transformations & PNG_COMPOSE) && - (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA || - row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) - png_do_strip_channel(row_info, png_ptr->row_buf + 1, - 0 /* at_start == false, because SWAP_ALPHA happens later */); -#endif - -#ifdef PNG_READ_ALPHA_MODE_SUPPORTED - if ((png_ptr->transformations & PNG_ENCODE_ALPHA) && - (row_info->color_type & PNG_COLOR_MASK_ALPHA)) - png_do_encode_alpha(row_info, png_ptr->row_buf + 1, png_ptr); -#endif - -#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED - if (png_ptr->transformations & PNG_SCALE_16_TO_8) - png_do_scale_16_to_8(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED - /* There is no harm in doing both of these because only one has any effect, - * by putting the 'scale' option first if the app asks for scale (either by - * calling the API or in a TRANSFORM flag) this is what happens. - */ - if (png_ptr->transformations & PNG_16_TO_8) - png_do_chop(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_QUANTIZE_SUPPORTED - if (png_ptr->transformations & PNG_QUANTIZE) - { - png_do_quantize(row_info, png_ptr->row_buf + 1, - png_ptr->palette_lookup, png_ptr->quantize_index); - - if (row_info->rowbytes == 0) - png_error(png_ptr, "png_do_quantize returned rowbytes=0"); - } -#endif /* PNG_READ_QUANTIZE_SUPPORTED */ - -#ifdef PNG_READ_EXPAND_16_SUPPORTED - /* Do the expansion now, after all the arithmetic has been done. Notice - * that previous transformations can handle the PNG_EXPAND_16 flag if this - * is efficient (particularly true in the case of gamma correction, where - * better accuracy results faster!) - */ - if (png_ptr->transformations & PNG_EXPAND_16) - png_do_expand_16(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED - /* NOTE: moved here in 1.5.4 (from much later in this list.) */ - if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && - (png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) - png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_INVERT_SUPPORTED - if (png_ptr->transformations & PNG_INVERT_MONO) - png_do_invert(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_SHIFT_SUPPORTED - if (png_ptr->transformations & PNG_SHIFT) - png_do_unshift(row_info, png_ptr->row_buf + 1, - &(png_ptr->shift)); -#endif - -#ifdef PNG_READ_PACK_SUPPORTED - if (png_ptr->transformations & PNG_PACK) - png_do_unpack(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED - /* Added at libpng-1.5.10 */ - if (row_info->color_type == PNG_COLOR_TYPE_PALETTE && - png_ptr->num_palette_max >= 0) - png_do_check_palette_indexes(png_ptr, row_info); -#endif - -#ifdef PNG_READ_BGR_SUPPORTED - if (png_ptr->transformations & PNG_BGR) - png_do_bgr(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_PACKSWAP_SUPPORTED - if (png_ptr->transformations & PNG_PACKSWAP) - png_do_packswap(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_FILLER_SUPPORTED - if (png_ptr->transformations & PNG_FILLER) - png_do_read_filler(row_info, png_ptr->row_buf + 1, - (png_uint_32)png_ptr->filler, png_ptr->flags); -#endif - -#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED - if (png_ptr->transformations & PNG_INVERT_ALPHA) - png_do_read_invert_alpha(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED - if (png_ptr->transformations & PNG_SWAP_ALPHA) - png_do_read_swap_alpha(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_READ_16BIT_SUPPORTED -#ifdef PNG_READ_SWAP_SUPPORTED - if (png_ptr->transformations & PNG_SWAP_BYTES) - png_do_swap(row_info, png_ptr->row_buf + 1); -#endif -#endif - -#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED - if (png_ptr->transformations & PNG_USER_TRANSFORM) - { - if (png_ptr->read_user_transform_fn != NULL) - (*(png_ptr->read_user_transform_fn)) /* User read transform function */ - (png_ptr, /* png_ptr */ - row_info, /* row_info: */ - /* png_uint_32 width; width of row */ - /* png_size_t rowbytes; number of bytes in row */ - /* png_byte color_type; color type of pixels */ - /* png_byte bit_depth; bit depth of samples */ - /* png_byte channels; number of channels (1-4) */ - /* png_byte pixel_depth; bits per pixel (depth*channels) */ - png_ptr->row_buf + 1); /* start of pixel data for row */ -#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED - if (png_ptr->user_transform_depth) - row_info->bit_depth = png_ptr->user_transform_depth; - - if (png_ptr->user_transform_channels) - row_info->channels = png_ptr->user_transform_channels; -#endif - row_info->pixel_depth = (png_byte)(row_info->bit_depth * - row_info->channels); - - row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->width); - } -#endif -} - -#ifdef PNG_READ_PACK_SUPPORTED -/* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel, - * without changing the actual values. Thus, if you had a row with - * a bit depth of 1, you would end up with bytes that only contained - * the numbers 0 or 1. If you would rather they contain 0 and 255, use - * png_do_shift() after this. - */ -void /* PRIVATE */ -png_do_unpack(png_row_infop row_info, png_bytep row) -{ - png_debug(1, "in png_do_unpack"); - - if (row_info->bit_depth < 8) - { - png_uint_32 i; - png_uint_32 row_width=row_info->width; - - switch (row_info->bit_depth) - { - case 1: - { - png_bytep sp = row + (png_size_t)((row_width - 1) >> 3); - png_bytep dp = row + (png_size_t)row_width - 1; - png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07); - for (i = 0; i < row_width; i++) - { - *dp = (png_byte)((*sp >> shift) & 0x01); - - if (shift == 7) - { - shift = 0; - sp--; - } - - else - shift++; - - dp--; - } - break; - } - - case 2: - { - - png_bytep sp = row + (png_size_t)((row_width - 1) >> 2); - png_bytep dp = row + (png_size_t)row_width - 1; - png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); - for (i = 0; i < row_width; i++) - { - *dp = (png_byte)((*sp >> shift) & 0x03); - - if (shift == 6) - { - shift = 0; - sp--; - } - - else - shift += 2; - - dp--; - } - break; - } - - case 4: - { - png_bytep sp = row + (png_size_t)((row_width - 1) >> 1); - png_bytep dp = row + (png_size_t)row_width - 1; - png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2); - for (i = 0; i < row_width; i++) - { - *dp = (png_byte)((*sp >> shift) & 0x0f); - - if (shift == 4) - { - shift = 0; - sp--; - } - - else - shift = 4; - - dp--; - } - break; - } - - default: - break; - } - row_info->bit_depth = 8; - row_info->pixel_depth = (png_byte)(8 * row_info->channels); - row_info->rowbytes = row_width * row_info->channels; - } -} -#endif - -#ifdef PNG_READ_SHIFT_SUPPORTED -/* Reverse the effects of png_do_shift. This routine merely shifts the - * pixels back to their significant bits values. Thus, if you have - * a row of bit depth 8, but only 5 are significant, this will shift - * the values back to 0 through 31. - */ -void /* PRIVATE */ -png_do_unshift(png_row_infop row_info, png_bytep row, - png_const_color_8p sig_bits) -{ - int color_type; - - png_debug(1, "in png_do_unshift"); - - /* The palette case has already been handled in the _init routine. */ - color_type = row_info->color_type; - - if (color_type != PNG_COLOR_TYPE_PALETTE) - { - int shift[4]; - int channels = 0; - int bit_depth = row_info->bit_depth; - - if (color_type & PNG_COLOR_MASK_COLOR) - { - shift[channels++] = bit_depth - sig_bits->red; - shift[channels++] = bit_depth - sig_bits->green; - shift[channels++] = bit_depth - sig_bits->blue; - } - - else - { - shift[channels++] = bit_depth - sig_bits->gray; - } - - if (color_type & PNG_COLOR_MASK_ALPHA) - { - shift[channels++] = bit_depth - sig_bits->alpha; - } - - { - int c, have_shift; - - for (c = have_shift = 0; c < channels; ++c) - { - /* A shift of more than the bit depth is an error condition but it - * gets ignored here. - */ - if (shift[c] <= 0 || shift[c] >= bit_depth) - shift[c] = 0; - - else - have_shift = 1; - } - - if (!have_shift) - return; - } - - switch (bit_depth) - { - default: - /* Must be 1bpp gray: should not be here! */ - /* NOTREACHED */ - break; - - case 2: - /* Must be 2bpp gray */ - /* assert(channels == 1 && shift[0] == 1) */ - { - png_bytep bp = row; - png_bytep bp_end = bp + row_info->rowbytes; - - while (bp < bp_end) - { - int b = (*bp >> 1) & 0x55; - *bp++ = (png_byte)b; - } - break; - } - - case 4: - /* Must be 4bpp gray */ - /* assert(channels == 1) */ - { - png_bytep bp = row; - png_bytep bp_end = bp + row_info->rowbytes; - int gray_shift = shift[0]; - int mask = 0xf >> gray_shift; - - mask |= mask << 4; - - while (bp < bp_end) - { - int b = (*bp >> gray_shift) & mask; - *bp++ = (png_byte)b; - } - break; - } - - case 8: - /* Single byte components, G, GA, RGB, RGBA */ - { - png_bytep bp = row; - png_bytep bp_end = bp + row_info->rowbytes; - int channel = 0; - - while (bp < bp_end) - { - int b = *bp >> shift[channel]; - if (++channel >= channels) - channel = 0; - *bp++ = (png_byte)b; - } - break; - } - -#ifdef PNG_READ_16BIT_SUPPORTED - case 16: - /* Double byte components, G, GA, RGB, RGBA */ - { - png_bytep bp = row; - png_bytep bp_end = bp + row_info->rowbytes; - int channel = 0; - - while (bp < bp_end) - { - int value = (bp[0] << 8) + bp[1]; - - value >>= shift[channel]; - if (++channel >= channels) - channel = 0; - *bp++ = (png_byte)(value >> 8); - *bp++ = (png_byte)(value & 0xff); - } - break; - } -#endif - } - } -} -#endif - -#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED -/* Scale rows of bit depth 16 down to 8 accurately */ -void /* PRIVATE */ -png_do_scale_16_to_8(png_row_infop row_info, png_bytep row) -{ - png_debug(1, "in png_do_scale_16_to_8"); - - if (row_info->bit_depth == 16) - { - png_bytep sp = row; /* source */ - png_bytep dp = row; /* destination */ - png_bytep ep = sp + row_info->rowbytes; /* end+1 */ - - while (sp < ep) - { - /* The input is an array of 16 bit components, these must be scaled to - * 8 bits each. For a 16 bit value V the required value (from the PNG - * specification) is: - * - * (V * 255) / 65535 - * - * This reduces to round(V / 257), or floor((V + 128.5)/257) - * - * Represent V as the two byte value vhi.vlo. Make a guess that the - * result is the top byte of V, vhi, then the correction to this value - * is: - * - * error = floor(((V-vhi.vhi) + 128.5) / 257) - * = floor(((vlo-vhi) + 128.5) / 257) - * - * This can be approximated using integer arithmetic (and a signed - * shift): - * - * error = (vlo-vhi+128) >> 8; - * - * The approximate differs from the exact answer only when (vlo-vhi) is - * 128; it then gives a correction of +1 when the exact correction is - * 0. This gives 128 errors. The exact answer (correct for all 16 bit - * input values) is: - * - * error = (vlo-vhi+128)*65535 >> 24; - * - * An alternative arithmetic calculation which also gives no errors is: - * - * (V * 255 + 32895) >> 16 - */ - - png_int_32 tmp = *sp++; /* must be signed! */ - tmp += (((int)*sp++ - tmp + 128) * 65535) >> 24; - *dp++ = (png_byte)tmp; - } - - row_info->bit_depth = 8; - row_info->pixel_depth = (png_byte)(8 * row_info->channels); - row_info->rowbytes = row_info->width * row_info->channels; - } -} -#endif - -#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED -void /* PRIVATE */ -/* Simply discard the low byte. This was the default behavior prior - * to libpng-1.5.4. - */ -png_do_chop(png_row_infop row_info, png_bytep row) -{ - png_debug(1, "in png_do_chop"); - - if (row_info->bit_depth == 16) - { - png_bytep sp = row; /* source */ - png_bytep dp = row; /* destination */ - png_bytep ep = sp + row_info->rowbytes; /* end+1 */ - - while (sp < ep) - { - *dp++ = *sp; - sp += 2; /* skip low byte */ - } - - row_info->bit_depth = 8; - row_info->pixel_depth = (png_byte)(8 * row_info->channels); - row_info->rowbytes = row_info->width * row_info->channels; - } -} -#endif - -#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED -void /* PRIVATE */ -png_do_read_swap_alpha(png_row_infop row_info, png_bytep row) -{ - png_debug(1, "in png_do_read_swap_alpha"); - - { - png_uint_32 row_width = row_info->width; - if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - { - /* This converts from RGBA to ARGB */ - if (row_info->bit_depth == 8) - { - png_bytep sp = row + row_info->rowbytes; - png_bytep dp = sp; - png_byte save; - png_uint_32 i; - - for (i = 0; i < row_width; i++) - { - save = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = save; - } - } - -#ifdef PNG_READ_16BIT_SUPPORTED - /* This converts from RRGGBBAA to AARRGGBB */ - else - { - png_bytep sp = row + row_info->rowbytes; - png_bytep dp = sp; - png_byte save[2]; - png_uint_32 i; - - for (i = 0; i < row_width; i++) - { - save[0] = *(--sp); - save[1] = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = save[0]; - *(--dp) = save[1]; - } - } -#endif - } - - else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - { - /* This converts from GA to AG */ - if (row_info->bit_depth == 8) - { - png_bytep sp = row + row_info->rowbytes; - png_bytep dp = sp; - png_byte save; - png_uint_32 i; - - for (i = 0; i < row_width; i++) - { - save = *(--sp); - *(--dp) = *(--sp); - *(--dp) = save; - } - } - -#ifdef PNG_READ_16BIT_SUPPORTED - /* This converts from GGAA to AAGG */ - else - { - png_bytep sp = row + row_info->rowbytes; - png_bytep dp = sp; - png_byte save[2]; - png_uint_32 i; - - for (i = 0; i < row_width; i++) - { - save[0] = *(--sp); - save[1] = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = save[0]; - *(--dp) = save[1]; - } - } -#endif - } - } -} -#endif - -#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED -void /* PRIVATE */ -png_do_read_invert_alpha(png_row_infop row_info, png_bytep row) -{ - png_uint_32 row_width; - png_debug(1, "in png_do_read_invert_alpha"); - - row_width = row_info->width; - if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - { - if (row_info->bit_depth == 8) - { - /* This inverts the alpha channel in RGBA */ - png_bytep sp = row + row_info->rowbytes; - png_bytep dp = sp; - png_uint_32 i; - - for (i = 0; i < row_width; i++) - { - *(--dp) = (png_byte)(255 - *(--sp)); - -/* This does nothing: - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - We can replace it with: -*/ - sp-=3; - dp=sp; - } - } - -#ifdef PNG_READ_16BIT_SUPPORTED - /* This inverts the alpha channel in RRGGBBAA */ - else - { - png_bytep sp = row + row_info->rowbytes; - png_bytep dp = sp; - png_uint_32 i; - - for (i = 0; i < row_width; i++) - { - *(--dp) = (png_byte)(255 - *(--sp)); - *(--dp) = (png_byte)(255 - *(--sp)); - -/* This does nothing: - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - We can replace it with: -*/ - sp-=6; - dp=sp; - } - } -#endif - } - else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - { - if (row_info->bit_depth == 8) - { - /* This inverts the alpha channel in GA */ - png_bytep sp = row + row_info->rowbytes; - png_bytep dp = sp; - png_uint_32 i; - - for (i = 0; i < row_width; i++) - { - *(--dp) = (png_byte)(255 - *(--sp)); - *(--dp) = *(--sp); - } - } - -#ifdef PNG_READ_16BIT_SUPPORTED - else - { - /* This inverts the alpha channel in GGAA */ - png_bytep sp = row + row_info->rowbytes; - png_bytep dp = sp; - png_uint_32 i; - - for (i = 0; i < row_width; i++) - { - *(--dp) = (png_byte)(255 - *(--sp)); - *(--dp) = (png_byte)(255 - *(--sp)); -/* - *(--dp) = *(--sp); - *(--dp) = *(--sp); -*/ - sp-=2; - dp=sp; - } - } -#endif - } -} -#endif - -#ifdef PNG_READ_FILLER_SUPPORTED -/* Add filler channel if we have RGB color */ -void /* PRIVATE */ -png_do_read_filler(png_row_infop row_info, png_bytep row, - png_uint_32 filler, png_uint_32 flags) -{ - png_uint_32 i; - png_uint_32 row_width = row_info->width; - -#ifdef PNG_READ_16BIT_SUPPORTED - png_byte hi_filler = (png_byte)((filler>>8) & 0xff); -#endif - png_byte lo_filler = (png_byte)(filler & 0xff); - - png_debug(1, "in png_do_read_filler"); - - if ( - row_info->color_type == PNG_COLOR_TYPE_GRAY) - { - if (row_info->bit_depth == 8) - { - if (flags & PNG_FLAG_FILLER_AFTER) - { - /* This changes the data from G to GX */ - png_bytep sp = row + (png_size_t)row_width; - png_bytep dp = sp + (png_size_t)row_width; - for (i = 1; i < row_width; i++) - { - *(--dp) = lo_filler; - *(--dp) = *(--sp); - } - *(--dp) = lo_filler; - row_info->channels = 2; - row_info->pixel_depth = 16; - row_info->rowbytes = row_width * 2; - } - - else - { - /* This changes the data from G to XG */ - png_bytep sp = row + (png_size_t)row_width; - png_bytep dp = sp + (png_size_t)row_width; - for (i = 0; i < row_width; i++) - { - *(--dp) = *(--sp); - *(--dp) = lo_filler; - } - row_info->channels = 2; - row_info->pixel_depth = 16; - row_info->rowbytes = row_width * 2; - } - } - -#ifdef PNG_READ_16BIT_SUPPORTED - else if (row_info->bit_depth == 16) - { - if (flags & PNG_FLAG_FILLER_AFTER) - { - /* This changes the data from GG to GGXX */ - png_bytep sp = row + (png_size_t)row_width * 2; - png_bytep dp = sp + (png_size_t)row_width * 2; - for (i = 1; i < row_width; i++) - { - *(--dp) = hi_filler; - *(--dp) = lo_filler; - *(--dp) = *(--sp); - *(--dp) = *(--sp); - } - *(--dp) = hi_filler; - *(--dp) = lo_filler; - row_info->channels = 2; - row_info->pixel_depth = 32; - row_info->rowbytes = row_width * 4; - } - - else - { - /* This changes the data from GG to XXGG */ - png_bytep sp = row + (png_size_t)row_width * 2; - png_bytep dp = sp + (png_size_t)row_width * 2; - for (i = 0; i < row_width; i++) - { - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = hi_filler; - *(--dp) = lo_filler; - } - row_info->channels = 2; - row_info->pixel_depth = 32; - row_info->rowbytes = row_width * 4; - } - } -#endif - } /* COLOR_TYPE == GRAY */ - else if (row_info->color_type == PNG_COLOR_TYPE_RGB) - { - if (row_info->bit_depth == 8) - { - if (flags & PNG_FLAG_FILLER_AFTER) - { - /* This changes the data from RGB to RGBX */ - png_bytep sp = row + (png_size_t)row_width * 3; - png_bytep dp = sp + (png_size_t)row_width; - for (i = 1; i < row_width; i++) - { - *(--dp) = lo_filler; - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - } - *(--dp) = lo_filler; - row_info->channels = 4; - row_info->pixel_depth = 32; - row_info->rowbytes = row_width * 4; - } - - else - { - /* This changes the data from RGB to XRGB */ - png_bytep sp = row + (png_size_t)row_width * 3; - png_bytep dp = sp + (png_size_t)row_width; - for (i = 0; i < row_width; i++) - { - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = lo_filler; - } - row_info->channels = 4; - row_info->pixel_depth = 32; - row_info->rowbytes = row_width * 4; - } - } - -#ifdef PNG_READ_16BIT_SUPPORTED - else if (row_info->bit_depth == 16) - { - if (flags & PNG_FLAG_FILLER_AFTER) - { - /* This changes the data from RRGGBB to RRGGBBXX */ - png_bytep sp = row + (png_size_t)row_width * 6; - png_bytep dp = sp + (png_size_t)row_width * 2; - for (i = 1; i < row_width; i++) - { - *(--dp) = hi_filler; - *(--dp) = lo_filler; - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - } - *(--dp) = hi_filler; - *(--dp) = lo_filler; - row_info->channels = 4; - row_info->pixel_depth = 64; - row_info->rowbytes = row_width * 8; - } - - else - { - /* This changes the data from RRGGBB to XXRRGGBB */ - png_bytep sp = row + (png_size_t)row_width * 6; - png_bytep dp = sp + (png_size_t)row_width * 2; - for (i = 0; i < row_width; i++) - { - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = *(--sp); - *(--dp) = hi_filler; - *(--dp) = lo_filler; - } - - row_info->channels = 4; - row_info->pixel_depth = 64; - row_info->rowbytes = row_width * 8; - } - } -#endif - } /* COLOR_TYPE == RGB */ -} -#endif - -#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED -/* Expand grayscale files to RGB, with or without alpha */ -void /* PRIVATE */ -png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) -{ - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - png_debug(1, "in png_do_gray_to_rgb"); - - if (row_info->bit_depth >= 8 && - !(row_info->color_type & PNG_COLOR_MASK_COLOR)) - { - if (row_info->color_type == PNG_COLOR_TYPE_GRAY) - { - if (row_info->bit_depth == 8) - { - /* This changes G to RGB */ - png_bytep sp = row + (png_size_t)row_width - 1; - png_bytep dp = sp + (png_size_t)row_width * 2; - for (i = 0; i < row_width; i++) - { - *(dp--) = *sp; - *(dp--) = *sp; - *(dp--) = *(sp--); - } - } - - else - { - /* This changes GG to RRGGBB */ - png_bytep sp = row + (png_size_t)row_width * 2 - 1; - png_bytep dp = sp + (png_size_t)row_width * 4; - for (i = 0; i < row_width; i++) - { - *(dp--) = *sp; - *(dp--) = *(sp - 1); - *(dp--) = *sp; - *(dp--) = *(sp - 1); - *(dp--) = *(sp--); - *(dp--) = *(sp--); - } - } - } - - else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - { - if (row_info->bit_depth == 8) - { - /* This changes GA to RGBA */ - png_bytep sp = row + (png_size_t)row_width * 2 - 1; - png_bytep dp = sp + (png_size_t)row_width * 2; - for (i = 0; i < row_width; i++) - { - *(dp--) = *(sp--); - *(dp--) = *sp; - *(dp--) = *sp; - *(dp--) = *(sp--); - } - } - - else - { - /* This changes GGAA to RRGGBBAA */ - png_bytep sp = row + (png_size_t)row_width * 4 - 1; - png_bytep dp = sp + (png_size_t)row_width * 4; - for (i = 0; i < row_width; i++) - { - *(dp--) = *(sp--); - *(dp--) = *(sp--); - *(dp--) = *sp; - *(dp--) = *(sp - 1); - *(dp--) = *sp; - *(dp--) = *(sp - 1); - *(dp--) = *(sp--); - *(dp--) = *(sp--); - } - } - } - row_info->channels = (png_byte)(row_info->channels + 2); - row_info->color_type |= PNG_COLOR_MASK_COLOR; - row_info->pixel_depth = (png_byte)(row_info->channels * - row_info->bit_depth); - row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); - } -} -#endif - -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED -/* Reduce RGB files to grayscale, with or without alpha - * using the equation given in Poynton's ColorFAQ of 1998-01-04 at - * (THIS LINK IS DEAD June 2008 but - * versions dated 1998 through November 2002 have been archived at - * http://web.archive.org/web/20000816232553/http://www.inforamp.net/ - * ~poynton/notes/colour_and_gamma/ColorFAQ.txt ) - * Charles Poynton poynton at poynton.com - * - * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B - * - * which can be expressed with integers as - * - * Y = (6969 * R + 23434 * G + 2365 * B)/32768 - * - * Poynton's current link (as of January 2003 through July 2011): - * - * has changed the numbers slightly: - * - * Y = 0.2126*R + 0.7152*G + 0.0722*B - * - * which can be expressed with integers as - * - * Y = (6966 * R + 23436 * G + 2366 * B)/32768 - * - * Historically, however, libpng uses numbers derived from the ITU-R Rec 709 - * end point chromaticities and the D65 white point. Depending on the - * precision used for the D65 white point this produces a variety of different - * numbers, however if the four decimal place value used in ITU-R Rec 709 is - * used (0.3127,0.3290) the Y calculation would be: - * - * Y = (6968 * R + 23435 * G + 2366 * B)/32768 - * - * While this is correct the rounding results in an overflow for white, because - * the sum of the rounded coefficients is 32769, not 32768. Consequently - * libpng uses, instead, the closest non-overflowing approximation: - * - * Y = (6968 * R + 23434 * G + 2366 * B)/32768 - * - * Starting with libpng-1.5.5, if the image being converted has a cHRM chunk - * (including an sRGB chunk) then the chromaticities are used to calculate the - * coefficients. See the chunk handling in pngrutil.c for more information. - * - * In all cases the calculation is to be done in a linear colorspace. If no - * gamma information is available to correct the encoding of the original RGB - * values this results in an implicit assumption that the original PNG RGB - * values were linear. - * - * Other integer coefficents can be used via png_set_rgb_to_gray(). Because - * the API takes just red and green coefficients the blue coefficient is - * calculated to make the sum 32768. This will result in different rounding - * to that used above. - */ -int /* PRIVATE */ -png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row) - -{ - int rgb_error = 0; - - png_debug(1, "in png_do_rgb_to_gray"); - - if (!(row_info->color_type & PNG_COLOR_MASK_PALETTE) && - (row_info->color_type & PNG_COLOR_MASK_COLOR)) - { - PNG_CONST png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff; - PNG_CONST png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff; - PNG_CONST png_uint_32 bc = 32768 - rc - gc; - PNG_CONST png_uint_32 row_width = row_info->width; - PNG_CONST int have_alpha = - (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0; - - if (row_info->bit_depth == 8) - { -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - /* Notice that gamma to/from 1 are not necessarily inverses (if - * there is an overall gamma correction). Prior to 1.5.5 this code - * checked the linearized values for equality; this doesn't match - * the documentation, the original values must be checked. - */ - if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL) - { - png_bytep sp = row; - png_bytep dp = row; - png_uint_32 i; - - for (i = 0; i < row_width; i++) - { - png_byte red = *(sp++); - png_byte green = *(sp++); - png_byte blue = *(sp++); - - if (red != green || red != blue) - { - red = png_ptr->gamma_to_1[red]; - green = png_ptr->gamma_to_1[green]; - blue = png_ptr->gamma_to_1[blue]; - - rgb_error |= 1; - *(dp++) = png_ptr->gamma_from_1[ - (rc*red + gc*green + bc*blue + 16384)>>15]; - } - - else - { - /* If there is no overall correction the table will not be - * set. - */ - if (png_ptr->gamma_table != NULL) - red = png_ptr->gamma_table[red]; - - *(dp++) = red; - } - - if (have_alpha) - *(dp++) = *(sp++); - } - } - else -#endif - { - png_bytep sp = row; - png_bytep dp = row; - png_uint_32 i; - - for (i = 0; i < row_width; i++) - { - png_byte red = *(sp++); - png_byte green = *(sp++); - png_byte blue = *(sp++); - - if (red != green || red != blue) - { - rgb_error |= 1; - /* NOTE: this is the historical approach which simply - * truncates the results. - */ - *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15); - } - - else - *(dp++) = red; - - if (have_alpha) - *(dp++) = *(sp++); - } - } - } - - else /* RGB bit_depth == 16 */ - { -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - if (png_ptr->gamma_16_to_1 != NULL && png_ptr->gamma_16_from_1 != NULL) - { - png_bytep sp = row; - png_bytep dp = row; - png_uint_32 i; - - for (i = 0; i < row_width; i++) - { - png_uint_16 red, green, blue, w; - - red = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - blue = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - - if (red == green && red == blue) - { - if (png_ptr->gamma_16_table != NULL) - w = png_ptr->gamma_16_table[(red&0xff) - >> png_ptr->gamma_shift][red>>8]; - - else - w = red; - } - - else - { - png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) - >> png_ptr->gamma_shift][red>>8]; - png_uint_16 green_1 = - png_ptr->gamma_16_to_1[(green&0xff) >> - png_ptr->gamma_shift][green>>8]; - png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) - >> png_ptr->gamma_shift][blue>>8]; - png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1 - + bc*blue_1 + 16384)>>15); - w = png_ptr->gamma_16_from_1[(gray16&0xff) >> - png_ptr->gamma_shift][gray16 >> 8]; - rgb_error |= 1; - } - - *(dp++) = (png_byte)((w>>8) & 0xff); - *(dp++) = (png_byte)(w & 0xff); - - if (have_alpha) - { - *(dp++) = *(sp++); - *(dp++) = *(sp++); - } - } - } - else -#endif - { - png_bytep sp = row; - png_bytep dp = row; - png_uint_32 i; - - for (i = 0; i < row_width; i++) - { - png_uint_16 red, green, blue, gray16; - - red = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - blue = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; - - if (red != green || red != blue) - rgb_error |= 1; - - /* From 1.5.5 in the 16 bit case do the accurate conversion even - * in the 'fast' case - this is because this is where the code - * ends up when handling linear 16 bit data. - */ - gray16 = (png_uint_16)((rc*red + gc*green + bc*blue + 16384) >> - 15); - *(dp++) = (png_byte)((gray16>>8) & 0xff); - *(dp++) = (png_byte)(gray16 & 0xff); - - if (have_alpha) - { - *(dp++) = *(sp++); - *(dp++) = *(sp++); - } - } - } - } - - row_info->channels = (png_byte)(row_info->channels - 2); - row_info->color_type = (png_byte)(row_info->color_type & - ~PNG_COLOR_MASK_COLOR); - row_info->pixel_depth = (png_byte)(row_info->channels * - row_info->bit_depth); - row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); - } - return rgb_error; -} -#endif -#endif /* PNG_READ_TRANSFORMS_SUPPORTED */ - -#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED -/* Build a grayscale palette. Palette is assumed to be 1 << bit_depth - * large of png_color. This lets grayscale images be treated as - * paletted. Most useful for gamma correction and simplification - * of code. This API is not used internally. - */ -void PNGAPI -png_build_grayscale_palette(int bit_depth, png_colorp palette) -{ - int num_palette; - int color_inc; - int i; - int v; - - png_debug(1, "in png_do_build_grayscale_palette"); - - if (palette == NULL) - return; - - switch (bit_depth) - { - case 1: - num_palette = 2; - color_inc = 0xff; - break; - - case 2: - num_palette = 4; - color_inc = 0x55; - break; - - case 4: - num_palette = 16; - color_inc = 0x11; - break; - - case 8: - num_palette = 256; - color_inc = 1; - break; - - default: - num_palette = 0; - color_inc = 0; - break; - } - - for (i = 0, v = 0; i < num_palette; i++, v += color_inc) - { - palette[i].red = (png_byte)v; - palette[i].green = (png_byte)v; - palette[i].blue = (png_byte)v; - } -} -#endif - - -#ifdef PNG_READ_TRANSFORMS_SUPPORTED -#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\ - (defined PNG_READ_ALPHA_MODE_SUPPORTED) -/* Replace any alpha or transparency with the supplied background color. - * "background" is already in the screen gamma, while "background_1" is - * at a gamma of 1.0. Paletted files have already been taken care of. - */ -void /* PRIVATE */ -png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) -{ -#ifdef PNG_READ_GAMMA_SUPPORTED - png_const_bytep gamma_table = png_ptr->gamma_table; - png_const_bytep gamma_from_1 = png_ptr->gamma_from_1; - png_const_bytep gamma_to_1 = png_ptr->gamma_to_1; - png_const_uint_16pp gamma_16 = png_ptr->gamma_16_table; - png_const_uint_16pp gamma_16_from_1 = png_ptr->gamma_16_from_1; - png_const_uint_16pp gamma_16_to_1 = png_ptr->gamma_16_to_1; - int gamma_shift = png_ptr->gamma_shift; -#endif - - png_bytep sp; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - int optimize = (png_ptr->flags & PNG_FLAG_OPTIMIZE_ALPHA) != 0; - int shift; - - png_debug(1, "in png_do_compose"); - - { - switch (row_info->color_type) - { - case PNG_COLOR_TYPE_GRAY: - { - switch (row_info->bit_depth) - { - case 1: - { - sp = row; - shift = 7; - for (i = 0; i < row_width; i++) - { - if ((png_uint_16)((*sp >> shift) & 0x01) - == png_ptr->trans_color.gray) - { - *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff); - *sp |= (png_byte)(png_ptr->background.gray << shift); - } - - if (!shift) - { - shift = 7; - sp++; - } - - else - shift--; - } - break; - } - - case 2: - { -#ifdef PNG_READ_GAMMA_SUPPORTED - if (gamma_table != NULL) - { - sp = row; - shift = 6; - for (i = 0; i < row_width; i++) - { - if ((png_uint_16)((*sp >> shift) & 0x03) - == png_ptr->trans_color.gray) - { - *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); - *sp |= (png_byte)(png_ptr->background.gray << shift); - } - - else - { - png_byte p = (png_byte)((*sp >> shift) & 0x03); - png_byte g = (png_byte)((gamma_table [p | (p << 2) | - (p << 4) | (p << 6)] >> 6) & 0x03); - *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); - *sp |= (png_byte)(g << shift); - } - - if (!shift) - { - shift = 6; - sp++; - } - - else - shift -= 2; - } - } - - else -#endif - { - sp = row; - shift = 6; - for (i = 0; i < row_width; i++) - { - if ((png_uint_16)((*sp >> shift) & 0x03) - == png_ptr->trans_color.gray) - { - *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); - *sp |= (png_byte)(png_ptr->background.gray << shift); - } - - if (!shift) - { - shift = 6; - sp++; - } - - else - shift -= 2; - } - } - break; - } - - case 4: - { -#ifdef PNG_READ_GAMMA_SUPPORTED - if (gamma_table != NULL) - { - sp = row; - shift = 4; - for (i = 0; i < row_width; i++) - { - if ((png_uint_16)((*sp >> shift) & 0x0f) - == png_ptr->trans_color.gray) - { - *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); - *sp |= (png_byte)(png_ptr->background.gray << shift); - } - - else - { - png_byte p = (png_byte)((*sp >> shift) & 0x0f); - png_byte g = (png_byte)((gamma_table[p | - (p << 4)] >> 4) & 0x0f); - *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); - *sp |= (png_byte)(g << shift); - } - - if (!shift) - { - shift = 4; - sp++; - } - - else - shift -= 4; - } - } - - else -#endif - { - sp = row; - shift = 4; - for (i = 0; i < row_width; i++) - { - if ((png_uint_16)((*sp >> shift) & 0x0f) - == png_ptr->trans_color.gray) - { - *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); - *sp |= (png_byte)(png_ptr->background.gray << shift); - } - - if (!shift) - { - shift = 4; - sp++; - } - - else - shift -= 4; - } - } - break; - } - - case 8: - { -#ifdef PNG_READ_GAMMA_SUPPORTED - if (gamma_table != NULL) - { - sp = row; - for (i = 0; i < row_width; i++, sp++) - { - if (*sp == png_ptr->trans_color.gray) - *sp = (png_byte)png_ptr->background.gray; - - else - *sp = gamma_table[*sp]; - } - } - else -#endif - { - sp = row; - for (i = 0; i < row_width; i++, sp++) - { - if (*sp == png_ptr->trans_color.gray) - *sp = (png_byte)png_ptr->background.gray; - } - } - break; - } - - case 16: - { -#ifdef PNG_READ_GAMMA_SUPPORTED - if (gamma_16 != NULL) - { - sp = row; - for (i = 0; i < row_width; i++, sp += 2) - { - png_uint_16 v; - - v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); - - if (v == png_ptr->trans_color.gray) - { - /* Background is already in screen gamma */ - *sp = (png_byte)((png_ptr->background.gray >> 8) - & 0xff); - *(sp + 1) = (png_byte)(png_ptr->background.gray - & 0xff); - } - - else - { - v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; - *sp = (png_byte)((v >> 8) & 0xff); - *(sp + 1) = (png_byte)(v & 0xff); - } - } - } - else -#endif - { - sp = row; - for (i = 0; i < row_width; i++, sp += 2) - { - png_uint_16 v; - - v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); - - if (v == png_ptr->trans_color.gray) - { - *sp = (png_byte)((png_ptr->background.gray >> 8) - & 0xff); - *(sp + 1) = (png_byte)(png_ptr->background.gray - & 0xff); - } - } - } - break; - } - - default: - break; - } - break; - } - - case PNG_COLOR_TYPE_RGB: - { - if (row_info->bit_depth == 8) - { -#ifdef PNG_READ_GAMMA_SUPPORTED - if (gamma_table != NULL) - { - sp = row; - for (i = 0; i < row_width; i++, sp += 3) - { - if (*sp == png_ptr->trans_color.red && - *(sp + 1) == png_ptr->trans_color.green && - *(sp + 2) == png_ptr->trans_color.blue) - { - *sp = (png_byte)png_ptr->background.red; - *(sp + 1) = (png_byte)png_ptr->background.green; - *(sp + 2) = (png_byte)png_ptr->background.blue; - } - - else - { - *sp = gamma_table[*sp]; - *(sp + 1) = gamma_table[*(sp + 1)]; - *(sp + 2) = gamma_table[*(sp + 2)]; - } - } - } - else -#endif - { - sp = row; - for (i = 0; i < row_width; i++, sp += 3) - { - if (*sp == png_ptr->trans_color.red && - *(sp + 1) == png_ptr->trans_color.green && - *(sp + 2) == png_ptr->trans_color.blue) - { - *sp = (png_byte)png_ptr->background.red; - *(sp + 1) = (png_byte)png_ptr->background.green; - *(sp + 2) = (png_byte)png_ptr->background.blue; - } - } - } - } - else /* if (row_info->bit_depth == 16) */ - { -#ifdef PNG_READ_GAMMA_SUPPORTED - if (gamma_16 != NULL) - { - sp = row; - for (i = 0; i < row_width; i++, sp += 6) - { - png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); - - png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8) - + *(sp + 3)); - - png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8) - + *(sp + 5)); - - if (r == png_ptr->trans_color.red && - g == png_ptr->trans_color.green && - b == png_ptr->trans_color.blue) - { - /* Background is already in screen gamma */ - *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); - *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); - *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) - & 0xff); - *(sp + 3) = (png_byte)(png_ptr->background.green - & 0xff); - *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) - & 0xff); - *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); - } - - else - { - png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; - *sp = (png_byte)((v >> 8) & 0xff); - *(sp + 1) = (png_byte)(v & 0xff); - - v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)]; - *(sp + 2) = (png_byte)((v >> 8) & 0xff); - *(sp + 3) = (png_byte)(v & 0xff); - - v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)]; - *(sp + 4) = (png_byte)((v >> 8) & 0xff); - *(sp + 5) = (png_byte)(v & 0xff); - } - } - } - - else -#endif - { - sp = row; - for (i = 0; i < row_width; i++, sp += 6) - { - png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); - - png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8) - + *(sp + 3)); - - png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8) - + *(sp + 5)); - - if (r == png_ptr->trans_color.red && - g == png_ptr->trans_color.green && - b == png_ptr->trans_color.blue) - { - *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); - *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); - *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) - & 0xff); - *(sp + 3) = (png_byte)(png_ptr->background.green - & 0xff); - *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) - & 0xff); - *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); - } - } - } - } - break; - } - - case PNG_COLOR_TYPE_GRAY_ALPHA: - { - if (row_info->bit_depth == 8) - { -#ifdef PNG_READ_GAMMA_SUPPORTED - if (gamma_to_1 != NULL && gamma_from_1 != NULL && - gamma_table != NULL) - { - sp = row; - for (i = 0; i < row_width; i++, sp += 2) - { - png_uint_16 a = *(sp + 1); - - if (a == 0xff) - *sp = gamma_table[*sp]; - - else if (a == 0) - { - /* Background is already in screen gamma */ - *sp = (png_byte)png_ptr->background.gray; - } - - else - { - png_byte v, w; - - v = gamma_to_1[*sp]; - png_composite(w, v, a, png_ptr->background_1.gray); - if (!optimize) - w = gamma_from_1[w]; - *sp = w; - } - } - } - else -#endif - { - sp = row; - for (i = 0; i < row_width; i++, sp += 2) - { - png_byte a = *(sp + 1); - - if (a == 0) - *sp = (png_byte)png_ptr->background.gray; - - else if (a < 0xff) - png_composite(*sp, *sp, a, png_ptr->background_1.gray); - } - } - } - else /* if (png_ptr->bit_depth == 16) */ - { -#ifdef PNG_READ_GAMMA_SUPPORTED - if (gamma_16 != NULL && gamma_16_from_1 != NULL && - gamma_16_to_1 != NULL) - { - sp = row; - for (i = 0; i < row_width; i++, sp += 4) - { - png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8) - + *(sp + 3)); - - if (a == (png_uint_16)0xffff) - { - png_uint_16 v; - - v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; - *sp = (png_byte)((v >> 8) & 0xff); - *(sp + 1) = (png_byte)(v & 0xff); - } - - else if (a == 0) - { - /* Background is already in screen gamma */ - *sp = (png_byte)((png_ptr->background.gray >> 8) - & 0xff); - *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff); - } - - else - { - png_uint_16 g, v, w; - - g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; - png_composite_16(v, g, a, png_ptr->background_1.gray); - if (optimize) - w = v; - else - w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8]; - *sp = (png_byte)((w >> 8) & 0xff); - *(sp + 1) = (png_byte)(w & 0xff); - } - } - } - else -#endif - { - sp = row; - for (i = 0; i < row_width; i++, sp += 4) - { - png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8) - + *(sp + 3)); - - if (a == 0) - { - *sp = (png_byte)((png_ptr->background.gray >> 8) - & 0xff); - *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff); - } - - else if (a < 0xffff) - { - png_uint_16 g, v; - - g = (png_uint_16)(((*sp) << 8) + *(sp + 1)); - png_composite_16(v, g, a, png_ptr->background_1.gray); - *sp = (png_byte)((v >> 8) & 0xff); - *(sp + 1) = (png_byte)(v & 0xff); - } - } - } - } - break; - } - - case PNG_COLOR_TYPE_RGB_ALPHA: - { - if (row_info->bit_depth == 8) - { -#ifdef PNG_READ_GAMMA_SUPPORTED - if (gamma_to_1 != NULL && gamma_from_1 != NULL && - gamma_table != NULL) - { - sp = row; - for (i = 0; i < row_width; i++, sp += 4) - { - png_byte a = *(sp + 3); - - if (a == 0xff) - { - *sp = gamma_table[*sp]; - *(sp + 1) = gamma_table[*(sp + 1)]; - *(sp + 2) = gamma_table[*(sp + 2)]; - } - - else if (a == 0) - { - /* Background is already in screen gamma */ - *sp = (png_byte)png_ptr->background.red; - *(sp + 1) = (png_byte)png_ptr->background.green; - *(sp + 2) = (png_byte)png_ptr->background.blue; - } - - else - { - png_byte v, w; - - v = gamma_to_1[*sp]; - png_composite(w, v, a, png_ptr->background_1.red); - if (!optimize) w = gamma_from_1[w]; - *sp = w; - - v = gamma_to_1[*(sp + 1)]; - png_composite(w, v, a, png_ptr->background_1.green); - if (!optimize) w = gamma_from_1[w]; - *(sp + 1) = w; - - v = gamma_to_1[*(sp + 2)]; - png_composite(w, v, a, png_ptr->background_1.blue); - if (!optimize) w = gamma_from_1[w]; - *(sp + 2) = w; - } - } - } - else -#endif - { - sp = row; - for (i = 0; i < row_width; i++, sp += 4) - { - png_byte a = *(sp + 3); - - if (a == 0) - { - *sp = (png_byte)png_ptr->background.red; - *(sp + 1) = (png_byte)png_ptr->background.green; - *(sp + 2) = (png_byte)png_ptr->background.blue; - } - - else if (a < 0xff) - { - png_composite(*sp, *sp, a, png_ptr->background.red); - - png_composite(*(sp + 1), *(sp + 1), a, - png_ptr->background.green); - - png_composite(*(sp + 2), *(sp + 2), a, - png_ptr->background.blue); - } - } - } - } - else /* if (row_info->bit_depth == 16) */ - { -#ifdef PNG_READ_GAMMA_SUPPORTED - if (gamma_16 != NULL && gamma_16_from_1 != NULL && - gamma_16_to_1 != NULL) - { - sp = row; - for (i = 0; i < row_width; i++, sp += 8) - { - png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6)) - << 8) + (png_uint_16)(*(sp + 7))); - - if (a == (png_uint_16)0xffff) - { - png_uint_16 v; - - v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; - *sp = (png_byte)((v >> 8) & 0xff); - *(sp + 1) = (png_byte)(v & 0xff); - - v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)]; - *(sp + 2) = (png_byte)((v >> 8) & 0xff); - *(sp + 3) = (png_byte)(v & 0xff); - - v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)]; - *(sp + 4) = (png_byte)((v >> 8) & 0xff); - *(sp + 5) = (png_byte)(v & 0xff); - } - - else if (a == 0) - { - /* Background is already in screen gamma */ - *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); - *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); - *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) - & 0xff); - *(sp + 3) = (png_byte)(png_ptr->background.green - & 0xff); - *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) - & 0xff); - *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); - } - - else - { - png_uint_16 v, w; - - v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; - png_composite_16(w, v, a, png_ptr->background_1.red); - if (!optimize) - w = gamma_16_from_1[((w&0xff) >> gamma_shift)] - [w >> 8]; - *sp = (png_byte)((w >> 8) & 0xff); - *(sp + 1) = (png_byte)(w & 0xff); - - v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)]; - png_composite_16(w, v, a, png_ptr->background_1.green); - if (!optimize) - w = gamma_16_from_1[((w&0xff) >> gamma_shift)] - [w >> 8]; - - *(sp + 2) = (png_byte)((w >> 8) & 0xff); - *(sp + 3) = (png_byte)(w & 0xff); - - v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)]; - png_composite_16(w, v, a, png_ptr->background_1.blue); - if (!optimize) - w = gamma_16_from_1[((w&0xff) >> gamma_shift)] - [w >> 8]; - - *(sp + 4) = (png_byte)((w >> 8) & 0xff); - *(sp + 5) = (png_byte)(w & 0xff); - } - } - } - - else -#endif - { - sp = row; - for (i = 0; i < row_width; i++, sp += 8) - { - png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6)) - << 8) + (png_uint_16)(*(sp + 7))); - - if (a == 0) - { - *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); - *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); - *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) - & 0xff); - *(sp + 3) = (png_byte)(png_ptr->background.green - & 0xff); - *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) - & 0xff); - *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); - } - - else if (a < 0xffff) - { - png_uint_16 v; - - png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); - png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8) - + *(sp + 3)); - png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8) - + *(sp + 5)); - - png_composite_16(v, r, a, png_ptr->background.red); - *sp = (png_byte)((v >> 8) & 0xff); - *(sp + 1) = (png_byte)(v & 0xff); - - png_composite_16(v, g, a, png_ptr->background.green); - *(sp + 2) = (png_byte)((v >> 8) & 0xff); - *(sp + 3) = (png_byte)(v & 0xff); - - png_composite_16(v, b, a, png_ptr->background.blue); - *(sp + 4) = (png_byte)((v >> 8) & 0xff); - *(sp + 5) = (png_byte)(v & 0xff); - } - } - } - } - break; - } - - default: - break; - } - } -} -#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_READ_ALPHA_MODE_SUPPORTED */ - -#ifdef PNG_READ_GAMMA_SUPPORTED -/* Gamma correct the image, avoiding the alpha channel. Make sure - * you do this after you deal with the transparency issue on grayscale - * or RGB images. If your bit depth is 8, use gamma_table, if it - * is 16, use gamma_16_table and gamma_shift. Build these with - * build_gamma_table(). - */ -void /* PRIVATE */ -png_do_gamma(png_row_infop row_info, png_bytep row, png_structp png_ptr) -{ - png_const_bytep gamma_table = png_ptr->gamma_table; - png_const_uint_16pp gamma_16_table = png_ptr->gamma_16_table; - int gamma_shift = png_ptr->gamma_shift; - - png_bytep sp; - png_uint_32 i; - png_uint_32 row_width=row_info->width; - - png_debug(1, "in png_do_gamma"); - - if (((row_info->bit_depth <= 8 && gamma_table != NULL) || - (row_info->bit_depth == 16 && gamma_16_table != NULL))) - { - switch (row_info->color_type) - { - case PNG_COLOR_TYPE_RGB: - { - if (row_info->bit_depth == 8) - { - sp = row; - for (i = 0; i < row_width; i++) - { - *sp = gamma_table[*sp]; - sp++; - *sp = gamma_table[*sp]; - sp++; - *sp = gamma_table[*sp]; - sp++; - } - } - - else /* if (row_info->bit_depth == 16) */ - { - sp = row; - for (i = 0; i < row_width; i++) - { - png_uint_16 v; - - v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; - *sp = (png_byte)((v >> 8) & 0xff); - *(sp + 1) = (png_byte)(v & 0xff); - sp += 2; - - v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; - *sp = (png_byte)((v >> 8) & 0xff); - *(sp + 1) = (png_byte)(v & 0xff); - sp += 2; - - v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; - *sp = (png_byte)((v >> 8) & 0xff); - *(sp + 1) = (png_byte)(v & 0xff); - sp += 2; - } - } - break; - } - - case PNG_COLOR_TYPE_RGB_ALPHA: - { - if (row_info->bit_depth == 8) - { - sp = row; - for (i = 0; i < row_width; i++) - { - *sp = gamma_table[*sp]; - sp++; - - *sp = gamma_table[*sp]; - sp++; - - *sp = gamma_table[*sp]; - sp++; - - sp++; - } - } - - else /* if (row_info->bit_depth == 16) */ - { - sp = row; - for (i = 0; i < row_width; i++) - { - png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; - *sp = (png_byte)((v >> 8) & 0xff); - *(sp + 1) = (png_byte)(v & 0xff); - sp += 2; - - v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; - *sp = (png_byte)((v >> 8) & 0xff); - *(sp + 1) = (png_byte)(v & 0xff); - sp += 2; - - v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; - *sp = (png_byte)((v >> 8) & 0xff); - *(sp + 1) = (png_byte)(v & 0xff); - sp += 4; - } - } - break; - } - - case PNG_COLOR_TYPE_GRAY_ALPHA: - { - if (row_info->bit_depth == 8) - { - sp = row; - for (i = 0; i < row_width; i++) - { - *sp = gamma_table[*sp]; - sp += 2; - } - } - - else /* if (row_info->bit_depth == 16) */ - { - sp = row; - for (i = 0; i < row_width; i++) - { - png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; - *sp = (png_byte)((v >> 8) & 0xff); - *(sp + 1) = (png_byte)(v & 0xff); - sp += 4; - } - } - break; - } - - case PNG_COLOR_TYPE_GRAY: - { - if (row_info->bit_depth == 2) - { - sp = row; - for (i = 0; i < row_width; i += 4) - { - int a = *sp & 0xc0; - int b = *sp & 0x30; - int c = *sp & 0x0c; - int d = *sp & 0x03; - - *sp = (png_byte)( - ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)| - ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)| - ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)| - ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) )); - sp++; - } - } - - if (row_info->bit_depth == 4) - { - sp = row; - for (i = 0; i < row_width; i += 2) - { - int msb = *sp & 0xf0; - int lsb = *sp & 0x0f; - - *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0) - | (((int)gamma_table[(lsb << 4) | lsb]) >> 4)); - sp++; - } - } - - else if (row_info->bit_depth == 8) - { - sp = row; - for (i = 0; i < row_width; i++) - { - *sp = gamma_table[*sp]; - sp++; - } - } - - else if (row_info->bit_depth == 16) - { - sp = row; - for (i = 0; i < row_width; i++) - { - png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; - *sp = (png_byte)((v >> 8) & 0xff); - *(sp + 1) = (png_byte)(v & 0xff); - sp += 2; - } - } - break; - } - - default: - break; - } - } -} -#endif - -#ifdef PNG_READ_ALPHA_MODE_SUPPORTED -/* Encode the alpha channel to the output gamma (the input channel is always - * linear.) Called only with color types that have an alpha channel. Needs the - * from_1 tables. - */ -void /* PRIVATE */ -png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structp png_ptr) -{ - png_uint_32 row_width = row_info->width; - - png_debug(1, "in png_do_encode_alpha"); - - if (row_info->color_type & PNG_COLOR_MASK_ALPHA) - { - if (row_info->bit_depth == 8) - { - PNG_CONST png_bytep table = png_ptr->gamma_from_1; - - if (table != NULL) - { - PNG_CONST int step = - (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 4 : 2; - - /* The alpha channel is the last component: */ - row += step - 1; - - for (; row_width > 0; --row_width, row += step) - *row = table[*row]; - - return; - } - } - - else if (row_info->bit_depth == 16) - { - PNG_CONST png_uint_16pp table = png_ptr->gamma_16_from_1; - PNG_CONST int gamma_shift = png_ptr->gamma_shift; - - if (table != NULL) - { - PNG_CONST int step = - (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 8 : 4; - - /* The alpha channel is the last component: */ - row += step - 2; - - for (; row_width > 0; --row_width, row += step) - { - png_uint_16 v; - - v = table[*(row + 1) >> gamma_shift][*row]; - *row = (png_byte)((v >> 8) & 0xff); - *(row + 1) = (png_byte)(v & 0xff); - } - - return; - } - } - } - - /* Only get to here if called with a weird row_info; no harm has been done, - * so just issue a warning. - */ - png_warning(png_ptr, "png_do_encode_alpha: unexpected call"); -} -#endif - -#ifdef PNG_READ_EXPAND_SUPPORTED -/* Expands a palette row to an RGB or RGBA row depending - * upon whether you supply trans and num_trans. - */ -void /* PRIVATE */ -png_do_expand_palette(png_row_infop row_info, png_bytep row, - png_const_colorp palette, png_const_bytep trans_alpha, int num_trans) -{ - int shift, value; - png_bytep sp, dp; - png_uint_32 i; - png_uint_32 row_width=row_info->width; - - png_debug(1, "in png_do_expand_palette"); - - if (row_info->color_type == PNG_COLOR_TYPE_PALETTE) - { - if (row_info->bit_depth < 8) - { - switch (row_info->bit_depth) - { - case 1: - { - sp = row + (png_size_t)((row_width - 1) >> 3); - dp = row + (png_size_t)row_width - 1; - shift = 7 - (int)((row_width + 7) & 0x07); - for (i = 0; i < row_width; i++) - { - if ((*sp >> shift) & 0x01) - *dp = 1; - - else - *dp = 0; - - if (shift == 7) - { - shift = 0; - sp--; - } - - else - shift++; - - dp--; - } - break; - } - - case 2: - { - sp = row + (png_size_t)((row_width - 1) >> 2); - dp = row + (png_size_t)row_width - 1; - shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); - for (i = 0; i < row_width; i++) - { - value = (*sp >> shift) & 0x03; - *dp = (png_byte)value; - if (shift == 6) - { - shift = 0; - sp--; - } - - else - shift += 2; - - dp--; - } - break; - } - - case 4: - { - sp = row + (png_size_t)((row_width - 1) >> 1); - dp = row + (png_size_t)row_width - 1; - shift = (int)((row_width & 0x01) << 2); - for (i = 0; i < row_width; i++) - { - value = (*sp >> shift) & 0x0f; - *dp = (png_byte)value; - if (shift == 4) - { - shift = 0; - sp--; - } - - else - shift += 4; - - dp--; - } - break; - } - - default: - break; - } - row_info->bit_depth = 8; - row_info->pixel_depth = 8; - row_info->rowbytes = row_width; - } - - if (row_info->bit_depth == 8) - { - { - if (num_trans > 0) - { - sp = row + (png_size_t)row_width - 1; - dp = row + (png_size_t)(row_width << 2) - 1; - - for (i = 0; i < row_width; i++) - { - if ((int)(*sp) >= num_trans) - *dp-- = 0xff; - - else - *dp-- = trans_alpha[*sp]; - - *dp-- = palette[*sp].blue; - *dp-- = palette[*sp].green; - *dp-- = palette[*sp].red; - sp--; - } - row_info->bit_depth = 8; - row_info->pixel_depth = 32; - row_info->rowbytes = row_width * 4; - row_info->color_type = 6; - row_info->channels = 4; - } - - else - { - sp = row + (png_size_t)row_width - 1; - dp = row + (png_size_t)(row_width * 3) - 1; - - for (i = 0; i < row_width; i++) - { - *dp-- = palette[*sp].blue; - *dp-- = palette[*sp].green; - *dp-- = palette[*sp].red; - sp--; - } - - row_info->bit_depth = 8; - row_info->pixel_depth = 24; - row_info->rowbytes = row_width * 3; - row_info->color_type = 2; - row_info->channels = 3; - } - } - } - } -} - -/* If the bit depth < 8, it is expanded to 8. Also, if the already - * expanded transparency value is supplied, an alpha channel is built. - */ -void /* PRIVATE */ -png_do_expand(png_row_infop row_info, png_bytep row, - png_const_color_16p trans_color) -{ - int shift, value; - png_bytep sp, dp; - png_uint_32 i; - png_uint_32 row_width=row_info->width; - - png_debug(1, "in png_do_expand"); - - { - if (row_info->color_type == PNG_COLOR_TYPE_GRAY) - { - png_uint_16 gray = (png_uint_16)(trans_color ? trans_color->gray : 0); - - if (row_info->bit_depth < 8) - { - switch (row_info->bit_depth) - { - case 1: - { - gray = (png_uint_16)((gray & 0x01) * 0xff); - sp = row + (png_size_t)((row_width - 1) >> 3); - dp = row + (png_size_t)row_width - 1; - shift = 7 - (int)((row_width + 7) & 0x07); - for (i = 0; i < row_width; i++) - { - if ((*sp >> shift) & 0x01) - *dp = 0xff; - - else - *dp = 0; - - if (shift == 7) - { - shift = 0; - sp--; - } - - else - shift++; - - dp--; - } - break; - } - - case 2: - { - gray = (png_uint_16)((gray & 0x03) * 0x55); - sp = row + (png_size_t)((row_width - 1) >> 2); - dp = row + (png_size_t)row_width - 1; - shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); - for (i = 0; i < row_width; i++) - { - value = (*sp >> shift) & 0x03; - *dp = (png_byte)(value | (value << 2) | (value << 4) | - (value << 6)); - if (shift == 6) - { - shift = 0; - sp--; - } - - else - shift += 2; - - dp--; - } - break; - } - - case 4: - { - gray = (png_uint_16)((gray & 0x0f) * 0x11); - sp = row + (png_size_t)((row_width - 1) >> 1); - dp = row + (png_size_t)row_width - 1; - shift = (int)((1 - ((row_width + 1) & 0x01)) << 2); - for (i = 0; i < row_width; i++) - { - value = (*sp >> shift) & 0x0f; - *dp = (png_byte)(value | (value << 4)); - if (shift == 4) - { - shift = 0; - sp--; - } - - else - shift = 4; - - dp--; - } - break; - } - - default: - break; - } - - row_info->bit_depth = 8; - row_info->pixel_depth = 8; - row_info->rowbytes = row_width; - } - - if (trans_color != NULL) - { - if (row_info->bit_depth == 8) - { - gray = gray & 0xff; - sp = row + (png_size_t)row_width - 1; - dp = row + (png_size_t)(row_width << 1) - 1; - - for (i = 0; i < row_width; i++) - { - if (*sp == gray) - *dp-- = 0; - - else - *dp-- = 0xff; - - *dp-- = *sp--; - } - } - - else if (row_info->bit_depth == 16) - { - png_byte gray_high = (png_byte)((gray >> 8) & 0xff); - png_byte gray_low = (png_byte)(gray & 0xff); - sp = row + row_info->rowbytes - 1; - dp = row + (row_info->rowbytes << 1) - 1; - for (i = 0; i < row_width; i++) - { - if (*(sp - 1) == gray_high && *(sp) == gray_low) - { - *dp-- = 0; - *dp-- = 0; - } - - else - { - *dp-- = 0xff; - *dp-- = 0xff; - } - - *dp-- = *sp--; - *dp-- = *sp--; - } - } - - row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA; - row_info->channels = 2; - row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1); - row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, - row_width); - } - } - else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_color) - { - if (row_info->bit_depth == 8) - { - png_byte red = (png_byte)(trans_color->red & 0xff); - png_byte green = (png_byte)(trans_color->green & 0xff); - png_byte blue = (png_byte)(trans_color->blue & 0xff); - sp = row + (png_size_t)row_info->rowbytes - 1; - dp = row + (png_size_t)(row_width << 2) - 1; - for (i = 0; i < row_width; i++) - { - if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue) - *dp-- = 0; - - else - *dp-- = 0xff; - - *dp-- = *sp--; - *dp-- = *sp--; - *dp-- = *sp--; - } - } - else if (row_info->bit_depth == 16) - { - png_byte red_high = (png_byte)((trans_color->red >> 8) & 0xff); - png_byte green_high = (png_byte)((trans_color->green >> 8) & 0xff); - png_byte blue_high = (png_byte)((trans_color->blue >> 8) & 0xff); - png_byte red_low = (png_byte)(trans_color->red & 0xff); - png_byte green_low = (png_byte)(trans_color->green & 0xff); - png_byte blue_low = (png_byte)(trans_color->blue & 0xff); - sp = row + row_info->rowbytes - 1; - dp = row + (png_size_t)(row_width << 3) - 1; - for (i = 0; i < row_width; i++) - { - if (*(sp - 5) == red_high && - *(sp - 4) == red_low && - *(sp - 3) == green_high && - *(sp - 2) == green_low && - *(sp - 1) == blue_high && - *(sp ) == blue_low) - { - *dp-- = 0; - *dp-- = 0; - } - - else - { - *dp-- = 0xff; - *dp-- = 0xff; - } - - *dp-- = *sp--; - *dp-- = *sp--; - *dp-- = *sp--; - *dp-- = *sp--; - *dp-- = *sp--; - *dp-- = *sp--; - } - } - row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA; - row_info->channels = 4; - row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2); - row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); - } - } -} -#endif - -#ifdef PNG_READ_EXPAND_16_SUPPORTED -/* If the bit depth is 8 and the color type is not a palette type expand the - * whole row to 16 bits. Has no effect otherwise. - */ -void /* PRIVATE */ -png_do_expand_16(png_row_infop row_info, png_bytep row) -{ - if (row_info->bit_depth == 8 && - row_info->color_type != PNG_COLOR_TYPE_PALETTE) - { - /* The row have a sequence of bytes containing [0..255] and we need - * to turn it into another row containing [0..65535], to do this we - * calculate: - * - * (input / 255) * 65535 - * - * Which happens to be exactly input * 257 and this can be achieved - * simply by byte replication in place (copying backwards). - */ - png_byte *sp = row + row_info->rowbytes; /* source, last byte + 1 */ - png_byte *dp = sp + row_info->rowbytes; /* destination, end + 1 */ - while (dp > sp) - dp[-2] = dp[-1] = *--sp, dp -= 2; - - row_info->rowbytes *= 2; - row_info->bit_depth = 16; - row_info->pixel_depth = (png_byte)(row_info->channels * 16); - } -} -#endif - -#ifdef PNG_READ_QUANTIZE_SUPPORTED -void /* PRIVATE */ -png_do_quantize(png_row_infop row_info, png_bytep row, - png_const_bytep palette_lookup, png_const_bytep quantize_lookup) -{ - png_bytep sp, dp; - png_uint_32 i; - png_uint_32 row_width=row_info->width; - - png_debug(1, "in png_do_quantize"); - - if (row_info->bit_depth == 8) - { - if (row_info->color_type == PNG_COLOR_TYPE_RGB && palette_lookup) - { - int r, g, b, p; - sp = row; - dp = row; - for (i = 0; i < row_width; i++) - { - r = *sp++; - g = *sp++; - b = *sp++; - - /* This looks real messy, but the compiler will reduce - * it down to a reasonable formula. For example, with - * 5 bits per color, we get: - * p = (((r >> 3) & 0x1f) << 10) | - * (((g >> 3) & 0x1f) << 5) | - * ((b >> 3) & 0x1f); - */ - p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) & - ((1 << PNG_QUANTIZE_RED_BITS) - 1)) << - (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) | - (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) & - ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) << - (PNG_QUANTIZE_BLUE_BITS)) | - ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) & - ((1 << PNG_QUANTIZE_BLUE_BITS) - 1)); - - *dp++ = palette_lookup[p]; - } - - row_info->color_type = PNG_COLOR_TYPE_PALETTE; - row_info->channels = 1; - row_info->pixel_depth = row_info->bit_depth; - row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); - } - - else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA && - palette_lookup != NULL) - { - int r, g, b, p; - sp = row; - dp = row; - for (i = 0; i < row_width; i++) - { - r = *sp++; - g = *sp++; - b = *sp++; - sp++; - - p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) & - ((1 << PNG_QUANTIZE_RED_BITS) - 1)) << - (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) | - (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) & - ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) << - (PNG_QUANTIZE_BLUE_BITS)) | - ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) & - ((1 << PNG_QUANTIZE_BLUE_BITS) - 1)); - - *dp++ = palette_lookup[p]; - } - - row_info->color_type = PNG_COLOR_TYPE_PALETTE; - row_info->channels = 1; - row_info->pixel_depth = row_info->bit_depth; - row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); - } - - else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE && - quantize_lookup) - { - sp = row; - - for (i = 0; i < row_width; i++, sp++) - { - *sp = quantize_lookup[*sp]; - } - } - } -} -#endif /* PNG_READ_QUANTIZE_SUPPORTED */ -#endif /* PNG_READ_TRANSFORMS_SUPPORTED */ - -#ifdef PNG_MNG_FEATURES_SUPPORTED -/* Undoes intrapixel differencing */ -void /* PRIVATE */ -png_do_read_intrapixel(png_row_infop row_info, png_bytep row) -{ - png_debug(1, "in png_do_read_intrapixel"); - - if ( - (row_info->color_type & PNG_COLOR_MASK_COLOR)) - { - int bytes_per_pixel; - png_uint_32 row_width = row_info->width; - - if (row_info->bit_depth == 8) - { - png_bytep rp; - png_uint_32 i; - - if (row_info->color_type == PNG_COLOR_TYPE_RGB) - bytes_per_pixel = 3; - - else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - bytes_per_pixel = 4; - - else - return; - - for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) - { - *(rp) = (png_byte)((256 + *rp + *(rp + 1)) & 0xff); - *(rp+2) = (png_byte)((256 + *(rp + 2) + *(rp + 1)) & 0xff); - } - } - else if (row_info->bit_depth == 16) - { - png_bytep rp; - png_uint_32 i; - - if (row_info->color_type == PNG_COLOR_TYPE_RGB) - bytes_per_pixel = 6; - - else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - bytes_per_pixel = 8; - - else - return; - - for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) - { - png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1); - png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3); - png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5); - png_uint_32 red = (s0 + s1 + 65536) & 0xffff; - png_uint_32 blue = (s2 + s1 + 65536) & 0xffff; - *(rp ) = (png_byte)((red >> 8) & 0xff); - *(rp + 1) = (png_byte)(red & 0xff); - *(rp + 4) = (png_byte)((blue >> 8) & 0xff); - *(rp + 5) = (png_byte)(blue & 0xff); - } - } - } -} -#endif /* PNG_MNG_FEATURES_SUPPORTED */ -#endif /* PNG_READ_SUPPORTED */ + +/* pngrtran.c - transforms the data in a row for PNG readers + * + * Last changed in libpng 1.5.11 [June 14, 2012] + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file contains functions optionally called by an application + * in order to tell libpng how to handle data when reading a PNG. + * Transformations that are used in both reading and writing are + * in pngtrans.c. + */ + +#include "pngpriv.h" + +#ifdef PNG_READ_SUPPORTED + +/* Set the action on getting a CRC error for an ancillary or critical chunk. */ +void PNGAPI +png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) +{ + png_debug(1, "in png_set_crc_action"); + + if (png_ptr == NULL) + return; + + /* Tell libpng how we react to CRC errors in critical chunks */ + switch (crit_action) + { + case PNG_CRC_NO_CHANGE: /* Leave setting as is */ + break; + + case PNG_CRC_WARN_USE: /* Warn/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; + png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE; + break; + + case PNG_CRC_QUIET_USE: /* Quiet/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; + png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE | + PNG_FLAG_CRC_CRITICAL_IGNORE; + break; + + case PNG_CRC_WARN_DISCARD: /* Not a valid action for critical data */ + png_warning(png_ptr, + "Can't discard critical data on CRC error"); + case PNG_CRC_ERROR_QUIT: /* Error/quit */ + + case PNG_CRC_DEFAULT: + default: + png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; + break; + } + + /* Tell libpng how we react to CRC errors in ancillary chunks */ + switch (ancil_action) + { + case PNG_CRC_NO_CHANGE: /* Leave setting as is */ + break; + + case PNG_CRC_WARN_USE: /* Warn/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE; + break; + + case PNG_CRC_QUIET_USE: /* Quiet/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE | + PNG_FLAG_CRC_ANCILLARY_NOWARN; + break; + + case PNG_CRC_ERROR_QUIT: /* Error/quit */ + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN; + break; + + case PNG_CRC_WARN_DISCARD: /* Warn/discard data */ + + case PNG_CRC_DEFAULT: + default: + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + break; + } +} + +#ifdef PNG_READ_BACKGROUND_SUPPORTED +/* Handle alpha and tRNS via a background color */ +void PNGFAPI +png_set_background_fixed(png_structp png_ptr, + png_const_color_16p background_color, int background_gamma_code, + int need_expand, png_fixed_point background_gamma) +{ + png_debug(1, "in png_set_background_fixed"); + + if (png_ptr == NULL) + return; + + if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN) + { + png_warning(png_ptr, "Application must supply a known background gamma"); + return; + } + + png_ptr->transformations |= PNG_COMPOSE | PNG_STRIP_ALPHA; + png_ptr->transformations &= ~PNG_ENCODE_ALPHA; + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; + + png_memcpy(&(png_ptr->background), background_color, + png_sizeof(png_color_16)); + png_ptr->background_gamma = background_gamma; + png_ptr->background_gamma_type = (png_byte)(background_gamma_code); + if (need_expand) + png_ptr->transformations |= PNG_BACKGROUND_EXPAND; + else + png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND; +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_background(png_structp png_ptr, + png_const_color_16p background_color, int background_gamma_code, + int need_expand, double background_gamma) +{ + png_set_background_fixed(png_ptr, background_color, background_gamma_code, + need_expand, png_fixed(png_ptr, background_gamma, "png_set_background")); +} +# endif /* FLOATING_POINT */ +#endif /* READ_BACKGROUND */ + +/* Scale 16-bit depth files to 8-bit depth. If both of these are set then the + * one that pngrtran does first (scale) happens. This is necessary to allow the + * TRANSFORM and API behavior to be somewhat consistent, and it's simpler. + */ +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED +void PNGAPI +png_set_scale_16(png_structp png_ptr) +{ + png_debug(1, "in png_set_scale_16"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_SCALE_16_TO_8; +} +#endif + +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED +/* Chop 16-bit depth files to 8-bit depth */ +void PNGAPI +png_set_strip_16(png_structp png_ptr) +{ + png_debug(1, "in png_set_strip_16"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_16_TO_8; +} +#endif + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED +void PNGAPI +png_set_strip_alpha(png_structp png_ptr) +{ + png_debug(1, "in png_set_strip_alpha"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_STRIP_ALPHA; +} +#endif + +#if defined(PNG_READ_ALPHA_MODE_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED) +static png_fixed_point +translate_gamma_flags(png_structp png_ptr, png_fixed_point output_gamma, + int is_screen) +{ + /* Check for flag values. The main reason for having the old Mac value as a + * flag is that it is pretty near impossible to work out what the correct + * value is from Apple documentation - a working Mac system is needed to + * discover the value! + */ + if (output_gamma == PNG_DEFAULT_sRGB || + output_gamma == PNG_FP_1 / PNG_DEFAULT_sRGB) + { + /* If there is no sRGB support this just sets the gamma to the standard + * sRGB value. (This is a side effect of using this function!) + */ +# ifdef PNG_READ_sRGB_SUPPORTED + png_ptr->flags |= PNG_FLAG_ASSUME_sRGB; +# endif + if (is_screen) + output_gamma = PNG_GAMMA_sRGB; + else + output_gamma = PNG_GAMMA_sRGB_INVERSE; + } + + else if (output_gamma == PNG_GAMMA_MAC_18 || + output_gamma == PNG_FP_1 / PNG_GAMMA_MAC_18) + { + if (is_screen) + output_gamma = PNG_GAMMA_MAC_OLD; + else + output_gamma = PNG_GAMMA_MAC_INVERSE; + } + + return output_gamma; +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +static png_fixed_point +convert_gamma_value(png_structp png_ptr, double output_gamma) +{ + /* The following silently ignores cases where fixed point (times 100,000) + * gamma values are passed to the floating point API. This is safe and it + * means the fixed point constants work just fine with the floating point + * API. The alternative would just lead to undetected errors and spurious + * bug reports. Negative values fail inside the _fixed API unless they + * correspond to the flag values. + */ + if (output_gamma > 0 && output_gamma < 128) + output_gamma *= PNG_FP_1; + + /* This preserves -1 and -2 exactly: */ + output_gamma = floor(output_gamma + .5); + + if (output_gamma > PNG_FP_MAX || output_gamma < PNG_FP_MIN) + png_fixed_error(png_ptr, "gamma value"); + + return (png_fixed_point)output_gamma; +} +# endif +#endif /* READ_ALPHA_MODE || READ_GAMMA */ + +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED +void PNGFAPI +png_set_alpha_mode_fixed(png_structp png_ptr, int mode, + png_fixed_point output_gamma) +{ + int compose = 0; + png_fixed_point file_gamma; + + png_debug(1, "in png_set_alpha_mode"); + + if (png_ptr == NULL) + return; + + output_gamma = translate_gamma_flags(png_ptr, output_gamma, 1/*screen*/); + + /* Validate the value to ensure it is in a reasonable range. The value + * is expected to be 1 or greater, but this range test allows for some + * viewing correction values. The intent is to weed out users of this API + * who use the inverse of the gamma value accidentally! Since some of these + * values are reasonable this may have to be changed. + */ + if (output_gamma < 70000 || output_gamma > 300000) + png_error(png_ptr, "output gamma out of expected range"); + + /* The default file gamma is the inverse of the output gamma; the output + * gamma may be changed below so get the file value first: + */ + file_gamma = png_reciprocal(output_gamma); + + /* There are really 8 possibilities here, composed of any combination + * of: + * + * premultiply the color channels + * do not encode non-opaque pixels + * encode the alpha as well as the color channels + * + * The differences disappear if the input/output ('screen') gamma is 1.0, + * because then the encoding is a no-op and there is only the choice of + * premultiplying the color channels or not. + * + * png_set_alpha_mode and png_set_background interact because both use + * png_compose to do the work. Calling both is only useful when + * png_set_alpha_mode is used to set the default mode - PNG_ALPHA_PNG - along + * with a default gamma value. Otherwise PNG_COMPOSE must not be set. + */ + switch (mode) + { + case PNG_ALPHA_PNG: /* default: png standard */ + /* No compose, but it may be set by png_set_background! */ + png_ptr->transformations &= ~PNG_ENCODE_ALPHA; + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; + break; + + case PNG_ALPHA_ASSOCIATED: /* color channels premultiplied */ + compose = 1; + png_ptr->transformations &= ~PNG_ENCODE_ALPHA; + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; + /* The output is linear: */ + output_gamma = PNG_FP_1; + break; + + case PNG_ALPHA_OPTIMIZED: /* associated, non-opaque pixels linear */ + compose = 1; + png_ptr->transformations &= ~PNG_ENCODE_ALPHA; + png_ptr->flags |= PNG_FLAG_OPTIMIZE_ALPHA; + /* output_gamma records the encoding of opaque pixels! */ + break; + + case PNG_ALPHA_BROKEN: /* associated, non-linear, alpha encoded */ + compose = 1; + png_ptr->transformations |= PNG_ENCODE_ALPHA; + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; + break; + + default: + png_error(png_ptr, "invalid alpha mode"); + } + + /* Only set the default gamma if the file gamma has not been set (this has + * the side effect that the gamma in a second call to png_set_alpha_mode will + * be ignored.) + */ + if (png_ptr->gamma == 0) + png_ptr->gamma = file_gamma; + + /* But always set the output gamma: */ + png_ptr->screen_gamma = output_gamma; + + /* Finally, if pre-multiplying, set the background fields to achieve the + * desired result. + */ + if (compose) + { + /* And obtain alpha pre-multiplication by composing on black: */ + png_memset(&png_ptr->background, 0, sizeof png_ptr->background); + png_ptr->background_gamma = png_ptr->gamma; /* just in case */ + png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_FILE; + png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND; + + if (png_ptr->transformations & PNG_COMPOSE) + png_error(png_ptr, + "conflicting calls to set alpha mode and background"); + + png_ptr->transformations |= PNG_COMPOSE; + } + + /* New API, make sure apps call the correct initializers: */ + png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED; +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_alpha_mode(png_structp png_ptr, int mode, double output_gamma) +{ + png_set_alpha_mode_fixed(png_ptr, mode, convert_gamma_value(png_ptr, + output_gamma)); +} +# endif +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED +/* Dither file to 8-bit. Supply a palette, the current number + * of elements in the palette, the maximum number of elements + * allowed, and a histogram if possible. If the current number + * of colors is greater then the maximum number, the palette will be + * modified to fit in the maximum number. "full_quantize" indicates + * whether we need a quantizing cube set up for RGB images, or if we + * simply are reducing the number of colors in a paletted image. + */ + +typedef struct png_dsort_struct +{ + struct png_dsort_struct FAR * next; + png_byte left; + png_byte right; +} png_dsort; +typedef png_dsort FAR * png_dsortp; +typedef png_dsort FAR * FAR * png_dsortpp; + +void PNGAPI +png_set_quantize(png_structp png_ptr, png_colorp palette, + int num_palette, int maximum_colors, png_const_uint_16p histogram, + int full_quantize) +{ + png_debug(1, "in png_set_quantize"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_QUANTIZE; + + if (!full_quantize) + { + int i; + + png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(num_palette * png_sizeof(png_byte))); + for (i = 0; i < num_palette; i++) + png_ptr->quantize_index[i] = (png_byte)i; + } + + if (num_palette > maximum_colors) + { + if (histogram != NULL) + { + /* This is easy enough, just throw out the least used colors. + * Perhaps not the best solution, but good enough. + */ + + int i; + + /* Initialize an array to sort colors */ + png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(num_palette * png_sizeof(png_byte))); + + /* Initialize the quantize_sort array */ + for (i = 0; i < num_palette; i++) + png_ptr->quantize_sort[i] = (png_byte)i; + + /* Find the least used palette entries by starting a + * bubble sort, and running it until we have sorted + * out enough colors. Note that we don't care about + * sorting all the colors, just finding which are + * least used. + */ + + for (i = num_palette - 1; i >= maximum_colors; i--) + { + int done; /* To stop early if the list is pre-sorted */ + int j; + + done = 1; + for (j = 0; j < i; j++) + { + if (histogram[png_ptr->quantize_sort[j]] + < histogram[png_ptr->quantize_sort[j + 1]]) + { + png_byte t; + + t = png_ptr->quantize_sort[j]; + png_ptr->quantize_sort[j] = png_ptr->quantize_sort[j + 1]; + png_ptr->quantize_sort[j + 1] = t; + done = 0; + } + } + + if (done) + break; + } + + /* Swap the palette around, and set up a table, if necessary */ + if (full_quantize) + { + int j = num_palette; + + /* Put all the useful colors within the max, but don't + * move the others. + */ + for (i = 0; i < maximum_colors; i++) + { + if ((int)png_ptr->quantize_sort[i] >= maximum_colors) + { + do + j--; + while ((int)png_ptr->quantize_sort[j] >= maximum_colors); + + palette[i] = palette[j]; + } + } + } + else + { + int j = num_palette; + + /* Move all the used colors inside the max limit, and + * develop a translation table. + */ + for (i = 0; i < maximum_colors; i++) + { + /* Only move the colors we need to */ + if ((int)png_ptr->quantize_sort[i] >= maximum_colors) + { + png_color tmp_color; + + do + j--; + while ((int)png_ptr->quantize_sort[j] >= maximum_colors); + + tmp_color = palette[j]; + palette[j] = palette[i]; + palette[i] = tmp_color; + /* Indicate where the color went */ + png_ptr->quantize_index[j] = (png_byte)i; + png_ptr->quantize_index[i] = (png_byte)j; + } + } + + /* Find closest color for those colors we are not using */ + for (i = 0; i < num_palette; i++) + { + if ((int)png_ptr->quantize_index[i] >= maximum_colors) + { + int min_d, k, min_k, d_index; + + /* Find the closest color to one we threw out */ + d_index = png_ptr->quantize_index[i]; + min_d = PNG_COLOR_DIST(palette[d_index], palette[0]); + for (k = 1, min_k = 0; k < maximum_colors; k++) + { + int d; + + d = PNG_COLOR_DIST(palette[d_index], palette[k]); + + if (d < min_d) + { + min_d = d; + min_k = k; + } + } + /* Point to closest color */ + png_ptr->quantize_index[i] = (png_byte)min_k; + } + } + } + png_free(png_ptr, png_ptr->quantize_sort); + png_ptr->quantize_sort = NULL; + } + else + { + /* This is much harder to do simply (and quickly). Perhaps + * we need to go through a median cut routine, but those + * don't always behave themselves with only a few colors + * as input. So we will just find the closest two colors, + * and throw out one of them (chosen somewhat randomly). + * [We don't understand this at all, so if someone wants to + * work on improving it, be our guest - AED, GRP] + */ + int i; + int max_d; + int num_new_palette; + png_dsortp t; + png_dsortpp hash; + + t = NULL; + + /* Initialize palette index arrays */ + png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(num_palette * png_sizeof(png_byte))); + png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(num_palette * png_sizeof(png_byte))); + + /* Initialize the sort array */ + for (i = 0; i < num_palette; i++) + { + png_ptr->index_to_palette[i] = (png_byte)i; + png_ptr->palette_to_index[i] = (png_byte)i; + } + + hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 * + png_sizeof(png_dsortp))); + + num_new_palette = num_palette; + + /* Initial wild guess at how far apart the farthest pixel + * pair we will be eliminating will be. Larger + * numbers mean more areas will be allocated, Smaller + * numbers run the risk of not saving enough data, and + * having to do this all over again. + * + * I have not done extensive checking on this number. + */ + max_d = 96; + + while (num_new_palette > maximum_colors) + { + for (i = 0; i < num_new_palette - 1; i++) + { + int j; + + for (j = i + 1; j < num_new_palette; j++) + { + int d; + + d = PNG_COLOR_DIST(palette[i], palette[j]); + + if (d <= max_d) + { + + t = (png_dsortp)png_malloc_warn(png_ptr, + (png_uint_32)(png_sizeof(png_dsort))); + + if (t == NULL) + break; + + t->next = hash[d]; + t->left = (png_byte)i; + t->right = (png_byte)j; + hash[d] = t; + } + } + if (t == NULL) + break; + } + + if (t != NULL) + for (i = 0; i <= max_d; i++) + { + if (hash[i] != NULL) + { + png_dsortp p; + + for (p = hash[i]; p; p = p->next) + { + if ((int)png_ptr->index_to_palette[p->left] + < num_new_palette && + (int)png_ptr->index_to_palette[p->right] + < num_new_palette) + { + int j, next_j; + + if (num_new_palette & 0x01) + { + j = p->left; + next_j = p->right; + } + else + { + j = p->right; + next_j = p->left; + } + + num_new_palette--; + palette[png_ptr->index_to_palette[j]] + = palette[num_new_palette]; + if (!full_quantize) + { + int k; + + for (k = 0; k < num_palette; k++) + { + if (png_ptr->quantize_index[k] == + png_ptr->index_to_palette[j]) + png_ptr->quantize_index[k] = + png_ptr->index_to_palette[next_j]; + + if ((int)png_ptr->quantize_index[k] == + num_new_palette) + png_ptr->quantize_index[k] = + png_ptr->index_to_palette[j]; + } + } + + png_ptr->index_to_palette[png_ptr->palette_to_index + [num_new_palette]] = png_ptr->index_to_palette[j]; + + png_ptr->palette_to_index[png_ptr->index_to_palette[j]] + = png_ptr->palette_to_index[num_new_palette]; + + png_ptr->index_to_palette[j] = + (png_byte)num_new_palette; + + png_ptr->palette_to_index[num_new_palette] = + (png_byte)j; + } + if (num_new_palette <= maximum_colors) + break; + } + if (num_new_palette <= maximum_colors) + break; + } + } + + for (i = 0; i < 769; i++) + { + if (hash[i] != NULL) + { + png_dsortp p = hash[i]; + while (p) + { + t = p->next; + png_free(png_ptr, p); + p = t; + } + } + hash[i] = 0; + } + max_d += 96; + } + png_free(png_ptr, hash); + png_free(png_ptr, png_ptr->palette_to_index); + png_free(png_ptr, png_ptr->index_to_palette); + png_ptr->palette_to_index = NULL; + png_ptr->index_to_palette = NULL; + } + num_palette = maximum_colors; + } + if (png_ptr->palette == NULL) + { + png_ptr->palette = palette; + } + png_ptr->num_palette = (png_uint_16)num_palette; + + if (full_quantize) + { + int i; + png_bytep distance; + int total_bits = PNG_QUANTIZE_RED_BITS + PNG_QUANTIZE_GREEN_BITS + + PNG_QUANTIZE_BLUE_BITS; + int num_red = (1 << PNG_QUANTIZE_RED_BITS); + int num_green = (1 << PNG_QUANTIZE_GREEN_BITS); + int num_blue = (1 << PNG_QUANTIZE_BLUE_BITS); + png_size_t num_entries = ((png_size_t)1 << total_bits); + + png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr, + (png_uint_32)(num_entries * png_sizeof(png_byte))); + + distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries * + png_sizeof(png_byte))); + + png_memset(distance, 0xff, num_entries * png_sizeof(png_byte)); + + for (i = 0; i < num_palette; i++) + { + int ir, ig, ib; + int r = (palette[i].red >> (8 - PNG_QUANTIZE_RED_BITS)); + int g = (palette[i].green >> (8 - PNG_QUANTIZE_GREEN_BITS)); + int b = (palette[i].blue >> (8 - PNG_QUANTIZE_BLUE_BITS)); + + for (ir = 0; ir < num_red; ir++) + { + /* int dr = abs(ir - r); */ + int dr = ((ir > r) ? ir - r : r - ir); + int index_r = (ir << (PNG_QUANTIZE_BLUE_BITS + + PNG_QUANTIZE_GREEN_BITS)); + + for (ig = 0; ig < num_green; ig++) + { + /* int dg = abs(ig - g); */ + int dg = ((ig > g) ? ig - g : g - ig); + int dt = dr + dg; + int dm = ((dr > dg) ? dr : dg); + int index_g = index_r | (ig << PNG_QUANTIZE_BLUE_BITS); + + for (ib = 0; ib < num_blue; ib++) + { + int d_index = index_g | ib; + /* int db = abs(ib - b); */ + int db = ((ib > b) ? ib - b : b - ib); + int dmax = ((dm > db) ? dm : db); + int d = dmax + dt + db; + + if (d < (int)distance[d_index]) + { + distance[d_index] = (png_byte)d; + png_ptr->palette_lookup[d_index] = (png_byte)i; + } + } + } + } + } + + png_free(png_ptr, distance); + } +} +#endif /* PNG_READ_QUANTIZE_SUPPORTED */ + +#ifdef PNG_READ_GAMMA_SUPPORTED +void PNGFAPI +png_set_gamma_fixed(png_structp png_ptr, png_fixed_point scrn_gamma, + png_fixed_point file_gamma) +{ + png_debug(1, "in png_set_gamma_fixed"); + + if (png_ptr == NULL) + return; + + /* New in libpng-1.5.4 - reserve particular negative values as flags. */ + scrn_gamma = translate_gamma_flags(png_ptr, scrn_gamma, 1/*screen*/); + file_gamma = translate_gamma_flags(png_ptr, file_gamma, 0/*file*/); + +#if PNG_LIBPNG_VER >= 10600 + /* Checking the gamma values for being >0 was added in 1.5.4 along with the + * premultiplied alpha support; this actually hides an undocumented feature + * of the previous implementation which allowed gamma processing to be + * disabled in background handling. There is no evidence (so far) that this + * was being used; however, png_set_background itself accepted and must still + * accept '0' for the gamma value it takes, because it isn't always used. + * + * Since this is an API change (albeit a very minor one that removes an + * undocumented API feature) it will not be made until libpng-1.6.0. + */ + if (file_gamma <= 0) + png_error(png_ptr, "invalid file gamma in png_set_gamma"); + + if (scrn_gamma <= 0) + png_error(png_ptr, "invalid screen gamma in png_set_gamma"); +#endif + + /* Set the gamma values unconditionally - this overrides the value in the PNG + * file if a gAMA chunk was present. png_set_alpha_mode provides a + * different, easier, way to default the file gamma. + */ + png_ptr->gamma = file_gamma; + png_ptr->screen_gamma = scrn_gamma; +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma) +{ + png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma), + convert_gamma_value(png_ptr, file_gamma)); +} +# endif /* FLOATING_POINT_SUPPORTED */ +#endif /* READ_GAMMA */ + +#ifdef PNG_READ_EXPAND_SUPPORTED +/* Expand paletted images to RGB, expand grayscale images of + * less than 8-bit depth to 8-bit depth, and expand tRNS chunks + * to alpha channels. + */ +void PNGAPI +png_set_expand(png_structp png_ptr) +{ + png_debug(1, "in png_set_expand"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); + png_ptr->flags &= ~PNG_FLAG_ROW_INIT; +} + +/* GRR 19990627: the following three functions currently are identical + * to png_set_expand(). However, it is entirely reasonable that someone + * might wish to expand an indexed image to RGB but *not* expand a single, + * fully transparent palette entry to a full alpha channel--perhaps instead + * convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace + * the transparent color with a particular RGB value, or drop tRNS entirely. + * IOW, a future version of the library may make the transformations flag + * a bit more fine-grained, with separate bits for each of these three + * functions. + * + * More to the point, these functions make it obvious what libpng will be + * doing, whereas "expand" can (and does) mean any number of things. + * + * GRP 20060307: In libpng-1.2.9, png_set_gray_1_2_4_to_8() was modified + * to expand only the sample depth but not to expand the tRNS to alpha + * and its name was changed to png_set_expand_gray_1_2_4_to_8(). + */ + +/* Expand paletted images to RGB. */ +void PNGAPI +png_set_palette_to_rgb(png_structp png_ptr) +{ + png_debug(1, "in png_set_palette_to_rgb"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); + png_ptr->flags &= ~PNG_FLAG_ROW_INIT; +} + +/* Expand grayscale images of less than 8-bit depth to 8 bits. */ +void PNGAPI +png_set_expand_gray_1_2_4_to_8(png_structp png_ptr) +{ + png_debug(1, "in png_set_expand_gray_1_2_4_to_8"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_EXPAND; + png_ptr->flags &= ~PNG_FLAG_ROW_INIT; +} + + + +/* Expand tRNS chunks to alpha channels. */ +void PNGAPI +png_set_tRNS_to_alpha(png_structp png_ptr) +{ + png_debug(1, "in png_set_tRNS_to_alpha"); + + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); + png_ptr->flags &= ~PNG_FLAG_ROW_INIT; +} +#endif /* defined(PNG_READ_EXPAND_SUPPORTED) */ + +#ifdef PNG_READ_EXPAND_16_SUPPORTED +/* Expand to 16-bit channels, expand the tRNS chunk too (because otherwise + * it may not work correctly.) + */ +void PNGAPI +png_set_expand_16(png_structp png_ptr) +{ + png_debug(1, "in png_set_expand_16"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= (PNG_EXPAND_16 | PNG_EXPAND | PNG_EXPAND_tRNS); + png_ptr->flags &= ~PNG_FLAG_ROW_INIT; + + /* New API, make sure apps call the correct initializers: */ + png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED; +} +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +void PNGAPI +png_set_gray_to_rgb(png_structp png_ptr) +{ + png_debug(1, "in png_set_gray_to_rgb"); + + if (png_ptr != NULL) + { + /* Because rgb must be 8 bits or more: */ + png_set_expand_gray_1_2_4_to_8(png_ptr); + png_ptr->transformations |= PNG_GRAY_TO_RGB; + png_ptr->flags &= ~PNG_FLAG_ROW_INIT; + } +} +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +void PNGFAPI +png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, + png_fixed_point red, png_fixed_point green) +{ + png_debug(1, "in png_set_rgb_to_gray"); + + if (png_ptr == NULL) + return; + + switch(error_action) + { + case PNG_ERROR_ACTION_NONE: + png_ptr->transformations |= PNG_RGB_TO_GRAY; + break; + + case PNG_ERROR_ACTION_WARN: + png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN; + break; + + case PNG_ERROR_ACTION_ERROR: + png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR; + break; + + default: + png_error(png_ptr, "invalid error action to rgb_to_gray"); + break; + } + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) +#ifdef PNG_READ_EXPAND_SUPPORTED + png_ptr->transformations |= PNG_EXPAND; +#else + { + png_warning(png_ptr, + "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED"); + + png_ptr->transformations &= ~PNG_RGB_TO_GRAY; + } +#endif + { + if (red >= 0 && green >= 0 && red + green <= PNG_FP_1) + { + png_uint_16 red_int, green_int; + + /* NOTE: this calculation does not round, but this behavior is retained + * for consistency, the inaccuracy is very small. The code here always + * overwrites the coefficients, regardless of whether they have been + * defaulted or set already. + */ + red_int = (png_uint_16)(((png_uint_32)red*32768)/100000); + green_int = (png_uint_16)(((png_uint_32)green*32768)/100000); + + png_ptr->rgb_to_gray_red_coeff = red_int; + png_ptr->rgb_to_gray_green_coeff = green_int; + png_ptr->rgb_to_gray_coefficients_set = 1; + } + + else + { + if (red >= 0 && green >= 0) + png_warning(png_ptr, + "ignoring out of range rgb_to_gray coefficients"); + + /* Use the defaults, from the cHRM chunk if set, else the historical + * values which are close to the sRGB/HDTV/ITU-Rec 709 values. See + * png_do_rgb_to_gray for more discussion of the values. In this case + * the coefficients are not marked as 'set' and are not overwritten if + * something has already provided a default. + */ + if (png_ptr->rgb_to_gray_red_coeff == 0 && + png_ptr->rgb_to_gray_green_coeff == 0) + { + png_ptr->rgb_to_gray_red_coeff = 6968; + png_ptr->rgb_to_gray_green_coeff = 23434; + /* png_ptr->rgb_to_gray_blue_coeff = 2366; */ + } + } + } +} + +#ifdef PNG_FLOATING_POINT_SUPPORTED +/* Convert a RGB image to a grayscale of the same width. This allows us, + * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image. + */ + +void PNGAPI +png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red, + double green) +{ + if (png_ptr == NULL) + return; + + png_set_rgb_to_gray_fixed(png_ptr, error_action, + png_fixed(png_ptr, red, "rgb to gray red coefficient"), + png_fixed(png_ptr, green, "rgb to gray green coefficient")); +} +#endif /* FLOATING POINT */ + +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +void PNGAPI +png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr + read_user_transform_fn) +{ + png_debug(1, "in png_set_read_user_transform_fn"); + + if (png_ptr == NULL) + return; + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + png_ptr->transformations |= PNG_USER_TRANSFORM; + png_ptr->read_user_transform_fn = read_user_transform_fn; +#endif +} +#endif + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED +#ifdef PNG_READ_GAMMA_SUPPORTED +/* In the case of gamma transformations only do transformations on images where + * the [file] gamma and screen_gamma are not close reciprocals, otherwise it + * slows things down slightly, and also needlessly introduces small errors. + */ +static int /* PRIVATE */ +png_gamma_threshold(png_fixed_point screen_gamma, png_fixed_point file_gamma) +{ + /* PNG_GAMMA_THRESHOLD is the threshold for performing gamma + * correction as a difference of the overall transform from 1.0 + * + * We want to compare the threshold with s*f - 1, if we get + * overflow here it is because of wacky gamma values so we + * turn on processing anyway. + */ + png_fixed_point gtest; + return !png_muldiv(>est, screen_gamma, file_gamma, PNG_FP_1) || + png_gamma_significant(gtest); +} +#endif + +/* Initialize everything needed for the read. This includes modifying + * the palette. + */ + +/*For the moment 'png_init_palette_transformations' and + * 'png_init_rgb_transformations' only do some flag canceling optimizations. + * The intent is that these two routines should have palette or rgb operations + * extracted from 'png_init_read_transformations'. + */ +static void /* PRIVATE */ +png_init_palette_transformations(png_structp png_ptr) +{ + /* Called to handle the (input) palette case. In png_do_read_transformations + * the first step is to expand the palette if requested, so this code must + * take care to only make changes that are invariant with respect to the + * palette expansion, or only do them if there is no expansion. + * + * STRIP_ALPHA has already been handled in the caller (by setting num_trans + * to 0.) + */ + int input_has_alpha = 0; + int input_has_transparency = 0; + + if (png_ptr->num_trans > 0) + { + int i; + + /* Ignore if all the entries are opaque (unlikely!) */ + for (i=0; inum_trans; ++i) + if (png_ptr->trans_alpha[i] == 255) + continue; + else if (png_ptr->trans_alpha[i] == 0) + input_has_transparency = 1; + else + input_has_alpha = 1; + } + + /* If no alpha we can optimize. */ + if (!input_has_alpha) + { + /* Any alpha means background and associative alpha processing is + * required, however if the alpha is 0 or 1 throughout OPTIIMIZE_ALPHA + * and ENCODE_ALPHA are irrelevant. + */ + png_ptr->transformations &= ~PNG_ENCODE_ALPHA; + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; + + if (!input_has_transparency) + png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND); + } + +#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) + /* png_set_background handling - deals with the complexity of whether the + * background color is in the file format or the screen format in the case + * where an 'expand' will happen. + */ + + /* The following code cannot be entered in the alpha pre-multiplication case + * because PNG_BACKGROUND_EXPAND is cancelled below. + */ + if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) && + (png_ptr->transformations & PNG_EXPAND)) + { + { + png_ptr->background.red = + png_ptr->palette[png_ptr->background.index].red; + png_ptr->background.green = + png_ptr->palette[png_ptr->background.index].green; + png_ptr->background.blue = + png_ptr->palette[png_ptr->background.index].blue; + +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED + if (png_ptr->transformations & PNG_INVERT_ALPHA) + { + if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) + { + /* Invert the alpha channel (in tRNS) unless the pixels are + * going to be expanded, in which case leave it for later + */ + int i, istop = png_ptr->num_trans; + + for (i=0; itrans_alpha[i] = (png_byte)(255 - + png_ptr->trans_alpha[i]); + } + } +#endif /* PNG_READ_INVERT_ALPHA_SUPPORTED */ + } + } /* background expand and (therefore) no alpha association. */ +#endif /* PNG_READ_EXPAND_SUPPORTED && PNG_READ_BACKGROUND_SUPPORTED */ +} + +static void /* PRIVATE */ +png_init_rgb_transformations(png_structp png_ptr) +{ + /* Added to libpng-1.5.4: check the color type to determine whether there + * is any alpha or transparency in the image and simply cancel the + * background and alpha mode stuff if there isn't. + */ + int input_has_alpha = (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0; + int input_has_transparency = png_ptr->num_trans > 0; + + /* If no alpha we can optimize. */ + if (!input_has_alpha) + { + /* Any alpha means background and associative alpha processing is + * required, however if the alpha is 0 or 1 throughout OPTIIMIZE_ALPHA + * and ENCODE_ALPHA are irrelevant. + */ +# ifdef PNG_READ_ALPHA_MODE_SUPPORTED + png_ptr->transformations &= ~PNG_ENCODE_ALPHA; + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; +# endif + + if (!input_has_transparency) + png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND); + } + +#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) + /* png_set_background handling - deals with the complexity of whether the + * background color is in the file format or the screen format in the case + * where an 'expand' will happen. + */ + + /* The following code cannot be entered in the alpha pre-multiplication case + * because PNG_BACKGROUND_EXPAND is cancelled below. + */ + if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) && + (png_ptr->transformations & PNG_EXPAND) && + !(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) + /* i.e., GRAY or GRAY_ALPHA */ + { + { + /* Expand background and tRNS chunks */ + int gray = png_ptr->background.gray; + int trans_gray = png_ptr->trans_color.gray; + + switch (png_ptr->bit_depth) + { + case 1: + gray *= 0xff; + trans_gray *= 0xff; + break; + + case 2: + gray *= 0x55; + trans_gray *= 0x55; + break; + + case 4: + gray *= 0x11; + trans_gray *= 0x11; + break; + + default: + + case 8: + /* Already 8 bits, fall through */ + + case 16: + /* Already a full 16 bits */ + break; + } + + png_ptr->background.red = png_ptr->background.green = + png_ptr->background.blue = (png_uint_16)gray; + + if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) + { + png_ptr->trans_color.red = png_ptr->trans_color.green = + png_ptr->trans_color.blue = (png_uint_16)trans_gray; + } + } + } /* background expand and (therefore) no alpha association. */ +#endif /* PNG_READ_EXPAND_SUPPORTED && PNG_READ_BACKGROUND_SUPPORTED */ +} + +void /* PRIVATE */ +png_init_read_transformations(png_structp png_ptr) +{ + png_debug(1, "in png_init_read_transformations"); + + /* This internal function is called from png_read_start_row in pngrutil.c + * and it is called before the 'rowbytes' calculation is done, so the code + * in here can change or update the transformations flags. + * + * First do updates that do not depend on the details of the PNG image data + * being processed. + */ + +#ifdef PNG_READ_GAMMA_SUPPORTED + /* Prior to 1.5.4 these tests were performed from png_set_gamma, 1.5.4 adds + * png_set_alpha_mode and this is another source for a default file gamma so + * the test needs to be performed later - here. In addition prior to 1.5.4 + * the tests were repeated for the PALETTE color type here - this is no + * longer necessary (and doesn't seem to have been necessary before.) + */ + { + /* The following temporary indicates if overall gamma correction is + * required. + */ + int gamma_correction = 0; + + if (png_ptr->gamma != 0) /* has been set */ + { + if (png_ptr->screen_gamma != 0) /* screen set too */ + gamma_correction = png_gamma_threshold(png_ptr->gamma, + png_ptr->screen_gamma); + + else + /* Assume the output matches the input; a long time default behavior + * of libpng, although the standard has nothing to say about this. + */ + png_ptr->screen_gamma = png_reciprocal(png_ptr->gamma); + } + + else if (png_ptr->screen_gamma != 0) + /* The converse - assume the file matches the screen, note that this + * perhaps undesireable default can (from 1.5.4) be changed by calling + * png_set_alpha_mode (even if the alpha handling mode isn't required + * or isn't changed from the default.) + */ + png_ptr->gamma = png_reciprocal(png_ptr->screen_gamma); + + else /* neither are set */ + /* Just in case the following prevents any processing - file and screen + * are both assumed to be linear and there is no way to introduce a + * third gamma value other than png_set_background with 'UNIQUE', and, + * prior to 1.5.4 + */ + png_ptr->screen_gamma = png_ptr->gamma = PNG_FP_1; + + /* Now turn the gamma transformation on or off as appropriate. Notice + * that PNG_GAMMA just refers to the file->screen correction. Alpha + * composition may independently cause gamma correction because it needs + * linear data (e.g. if the file has a gAMA chunk but the screen gamma + * hasn't been specified.) In any case this flag may get turned off in + * the code immediately below if the transform can be handled outside the + * row loop. + */ + if (gamma_correction) + png_ptr->transformations |= PNG_GAMMA; + + else + png_ptr->transformations &= ~PNG_GAMMA; + } +#endif + + /* Certain transformations have the effect of preventing other + * transformations that happen afterward in png_do_read_transformations, + * resolve the interdependencies here. From the code of + * png_do_read_transformations the order is: + * + * 1) PNG_EXPAND (including PNG_EXPAND_tRNS) + * 2) PNG_STRIP_ALPHA (if no compose) + * 3) PNG_RGB_TO_GRAY + * 4) PNG_GRAY_TO_RGB iff !PNG_BACKGROUND_IS_GRAY + * 5) PNG_COMPOSE + * 6) PNG_GAMMA + * 7) PNG_STRIP_ALPHA (if compose) + * 8) PNG_ENCODE_ALPHA + * 9) PNG_SCALE_16_TO_8 + * 10) PNG_16_TO_8 + * 11) PNG_QUANTIZE (converts to palette) + * 12) PNG_EXPAND_16 + * 13) PNG_GRAY_TO_RGB iff PNG_BACKGROUND_IS_GRAY + * 14) PNG_INVERT_MONO + * 15) PNG_SHIFT + * 16) PNG_PACK + * 17) PNG_BGR + * 18) PNG_PACKSWAP + * 19) PNG_FILLER (includes PNG_ADD_ALPHA) + * 20) PNG_INVERT_ALPHA + * 21) PNG_SWAP_ALPHA + * 22) PNG_SWAP_BYTES + * 23) PNG_USER_TRANSFORM [must be last] + */ +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_STRIP_ALPHA) && + !(png_ptr->transformations & PNG_COMPOSE)) + { + /* Stripping the alpha channel happens immediately after the 'expand' + * transformations, before all other transformation, so it cancels out + * the alpha handling. It has the side effect negating the effect of + * PNG_EXPAND_tRNS too: + */ + png_ptr->transformations &= ~(PNG_BACKGROUND_EXPAND | PNG_ENCODE_ALPHA | + PNG_EXPAND_tRNS); + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; + + /* Kill the tRNS chunk itself too. Prior to 1.5.4 this did not happen + * so transparency information would remain just so long as it wasn't + * expanded. This produces unexpected API changes if the set of things + * that do PNG_EXPAND_tRNS changes (perfectly possible given the + * documentation - which says ask for what you want, accept what you + * get.) This makes the behavior consistent from 1.5.4: + */ + png_ptr->num_trans = 0; + } +#endif /* STRIP_ALPHA supported, no COMPOSE */ + +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED + /* If the screen gamma is about 1.0 then the OPTIMIZE_ALPHA and ENCODE_ALPHA + * settings will have no effect. + */ + if (!png_gamma_significant(png_ptr->screen_gamma)) + { + png_ptr->transformations &= ~PNG_ENCODE_ALPHA; + png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA; + } +#endif + +#if defined(PNG_READ_EXPAND_SUPPORTED) && \ + defined(PNG_READ_BACKGROUND_SUPPORTED) && \ + defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) + /* Detect gray background and attempt to enable optimization for + * gray --> RGB case. + * + * Note: if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or + * RGB_ALPHA (in which case need_expand is superfluous anyway), the + * background color might actually be gray yet not be flagged as such. + * This is not a problem for the current code, which uses + * PNG_BACKGROUND_IS_GRAY only to decide when to do the + * png_do_gray_to_rgb() transformation. + * + * TODO: this code needs to be revised to avoid the complexity and + * interdependencies. The color type of the background should be recorded in + * png_set_background, along with the bit depth, then the code has a record + * of exactly what color space the background is currently in. + */ + if (png_ptr->transformations & PNG_BACKGROUND_EXPAND) + { + /* PNG_BACKGROUND_EXPAND: the background is in the file color space, so if + * the file was grayscale the background value is gray. + */ + if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) + png_ptr->mode |= PNG_BACKGROUND_IS_GRAY; + } + + else if (png_ptr->transformations & PNG_COMPOSE) + { + /* PNG_COMPOSE: png_set_background was called with need_expand false, + * so the color is in the color space of the output or png_set_alpha_mode + * was called and the color is black. Ignore RGB_TO_GRAY because that + * happens before GRAY_TO_RGB. + */ + if (png_ptr->transformations & PNG_GRAY_TO_RGB) + { + if (png_ptr->background.red == png_ptr->background.green && + png_ptr->background.red == png_ptr->background.blue) + { + png_ptr->mode |= PNG_BACKGROUND_IS_GRAY; + png_ptr->background.gray = png_ptr->background.red; + } + } + } +#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED (etc) */ + + /* For indexed PNG data (PNG_COLOR_TYPE_PALETTE) many of the transformations + * can be performed directly on the palette, and some (such as rgb to gray) + * can be optimized inside the palette. This is particularly true of the + * composite (background and alpha) stuff, which can be pretty much all done + * in the palette even if the result is expanded to RGB or gray afterward. + * + * NOTE: this is Not Yet Implemented, the code behaves as in 1.5.1 and + * earlier and the palette stuff is actually handled on the first row. This + * leads to the reported bug that the palette returned by png_get_PLTE is not + * updated. + */ + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + png_init_palette_transformations(png_ptr); + + else + png_init_rgb_transformations(png_ptr); + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ + defined(PNG_READ_EXPAND_16_SUPPORTED) + if ((png_ptr->transformations & PNG_EXPAND_16) && + (png_ptr->transformations & PNG_COMPOSE) && + !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) && + png_ptr->bit_depth != 16) + { + /* TODO: fix this. Because the expand_16 operation is after the compose + * handling the background color must be 8, not 16, bits deep, but the + * application will supply a 16-bit value so reduce it here. + * + * The PNG_BACKGROUND_EXPAND code above does not expand to 16 bits at + * present, so that case is ok (until do_expand_16 is moved.) + * + * NOTE: this discards the low 16 bits of the user supplied background + * color, but until expand_16 works properly there is no choice! + */ +# define CHOP(x) (x)=((png_uint_16)(((png_uint_32)(x)*255+32895) >> 16)) + CHOP(png_ptr->background.red); + CHOP(png_ptr->background.green); + CHOP(png_ptr->background.blue); + CHOP(png_ptr->background.gray); +# undef CHOP + } +#endif /* PNG_READ_BACKGROUND_SUPPORTED && PNG_READ_EXPAND_16_SUPPORTED */ + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ + (defined(PNG_READ_SCALE_16_TO_8_SUPPORTED) || \ + defined(PNG_READ_STRIP_16_TO_8_SUPPORTED)) + if ((png_ptr->transformations & (PNG_16_TO_8|PNG_SCALE_16_TO_8)) && + (png_ptr->transformations & PNG_COMPOSE) && + !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) && + png_ptr->bit_depth == 16) + { + /* On the other hand, if a 16-bit file is to be reduced to 8-bits per + * component this will also happen after PNG_COMPOSE and so the background + * color must be pre-expanded here. + * + * TODO: fix this too. + */ + png_ptr->background.red = (png_uint_16)(png_ptr->background.red * 257); + png_ptr->background.green = + (png_uint_16)(png_ptr->background.green * 257); + png_ptr->background.blue = (png_uint_16)(png_ptr->background.blue * 257); + png_ptr->background.gray = (png_uint_16)(png_ptr->background.gray * 257); + } +#endif + + /* NOTE: below 'PNG_READ_ALPHA_MODE_SUPPORTED' is presumed to also enable the + * background support (see the comments in scripts/pnglibconf.dfa), this + * allows pre-multiplication of the alpha channel to be implemented as + * compositing on black. This is probably sub-optimal and has been done in + * 1.5.4 betas simply to enable external critique and testing (i.e. to + * implement the new API quickly, without lots of internal changes.) + */ + +#ifdef PNG_READ_GAMMA_SUPPORTED +# ifdef PNG_READ_BACKGROUND_SUPPORTED + /* Includes ALPHA_MODE */ + png_ptr->background_1 = png_ptr->background; +# endif + + /* This needs to change - in the palette image case a whole set of tables are + * built when it would be quicker to just calculate the correct value for + * each palette entry directly. Also, the test is too tricky - why check + * PNG_RGB_TO_GRAY if PNG_GAMMA is not set? The answer seems to be that + * PNG_GAMMA is cancelled even if the gamma is known? The test excludes the + * PNG_COMPOSE case, so apparently if there is no *overall* gamma correction + * the gamma tables will not be built even if composition is required on a + * gamma encoded value. + * + * In 1.5.4 this is addressed below by an additional check on the individual + * file gamma - if it is not 1.0 both RGB_TO_GRAY and COMPOSE need the + * tables. + */ + if ((png_ptr->transformations & PNG_GAMMA) + || ((png_ptr->transformations & PNG_RGB_TO_GRAY) + && (png_gamma_significant(png_ptr->gamma) || + png_gamma_significant(png_ptr->screen_gamma))) + || ((png_ptr->transformations & PNG_COMPOSE) + && (png_gamma_significant(png_ptr->gamma) + || png_gamma_significant(png_ptr->screen_gamma) +# ifdef PNG_READ_BACKGROUND_SUPPORTED + || (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_UNIQUE + && png_gamma_significant(png_ptr->background_gamma)) +# endif + )) || ((png_ptr->transformations & PNG_ENCODE_ALPHA) + && png_gamma_significant(png_ptr->screen_gamma)) + ) + { + png_build_gamma_table(png_ptr, png_ptr->bit_depth); + +#ifdef PNG_READ_BACKGROUND_SUPPORTED + if (png_ptr->transformations & PNG_COMPOSE) + { + /* Issue a warning about this combination: because RGB_TO_GRAY is + * optimized to do the gamma transform if present yet do_background has + * to do the same thing if both options are set a + * double-gamma-correction happens. This is true in all versions of + * libpng to date. + */ + if (png_ptr->transformations & PNG_RGB_TO_GRAY) + png_warning(png_ptr, + "libpng does not support gamma+background+rgb_to_gray"); + + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + /* We don't get to here unless there is a tRNS chunk with non-opaque + * entries - see the checking code at the start of this function. + */ + png_color back, back_1; + png_colorp palette = png_ptr->palette; + int num_palette = png_ptr->num_palette; + int i; + if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE) + { + + back.red = png_ptr->gamma_table[png_ptr->background.red]; + back.green = png_ptr->gamma_table[png_ptr->background.green]; + back.blue = png_ptr->gamma_table[png_ptr->background.blue]; + + back_1.red = png_ptr->gamma_to_1[png_ptr->background.red]; + back_1.green = png_ptr->gamma_to_1[png_ptr->background.green]; + back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue]; + } + else + { + png_fixed_point g, gs; + + switch (png_ptr->background_gamma_type) + { + case PNG_BACKGROUND_GAMMA_SCREEN: + g = (png_ptr->screen_gamma); + gs = PNG_FP_1; + break; + + case PNG_BACKGROUND_GAMMA_FILE: + g = png_reciprocal(png_ptr->gamma); + gs = png_reciprocal2(png_ptr->gamma, + png_ptr->screen_gamma); + break; + + case PNG_BACKGROUND_GAMMA_UNIQUE: + g = png_reciprocal(png_ptr->background_gamma); + gs = png_reciprocal2(png_ptr->background_gamma, + png_ptr->screen_gamma); + break; + default: + g = PNG_FP_1; /* back_1 */ + gs = PNG_FP_1; /* back */ + break; + } + + if (png_gamma_significant(gs)) + { + back.red = png_gamma_8bit_correct(png_ptr->background.red, + gs); + back.green = png_gamma_8bit_correct(png_ptr->background.green, + gs); + back.blue = png_gamma_8bit_correct(png_ptr->background.blue, + gs); + } + + else + { + back.red = (png_byte)png_ptr->background.red; + back.green = (png_byte)png_ptr->background.green; + back.blue = (png_byte)png_ptr->background.blue; + } + + if (png_gamma_significant(g)) + { + back_1.red = png_gamma_8bit_correct(png_ptr->background.red, + g); + back_1.green = png_gamma_8bit_correct( + png_ptr->background.green, g); + back_1.blue = png_gamma_8bit_correct(png_ptr->background.blue, + g); + } + + else + { + back_1.red = (png_byte)png_ptr->background.red; + back_1.green = (png_byte)png_ptr->background.green; + back_1.blue = (png_byte)png_ptr->background.blue; + } + } + + for (i = 0; i < num_palette; i++) + { + if (i < (int)png_ptr->num_trans && + png_ptr->trans_alpha[i] != 0xff) + { + if (png_ptr->trans_alpha[i] == 0) + { + palette[i] = back; + } + else /* if (png_ptr->trans_alpha[i] != 0xff) */ + { + png_byte v, w; + + v = png_ptr->gamma_to_1[palette[i].red]; + png_composite(w, v, png_ptr->trans_alpha[i], back_1.red); + palette[i].red = png_ptr->gamma_from_1[w]; + + v = png_ptr->gamma_to_1[palette[i].green]; + png_composite(w, v, png_ptr->trans_alpha[i], back_1.green); + palette[i].green = png_ptr->gamma_from_1[w]; + + v = png_ptr->gamma_to_1[palette[i].blue]; + png_composite(w, v, png_ptr->trans_alpha[i], back_1.blue); + palette[i].blue = png_ptr->gamma_from_1[w]; + } + } + else + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + } + + /* Prevent the transformations being done again. + * + * NOTE: this is highly dubious; it removes the transformations in + * place. This seems inconsistent with the general treatment of the + * transformations elsewhere. + */ + png_ptr->transformations &= ~(PNG_COMPOSE | PNG_GAMMA); + } /* color_type == PNG_COLOR_TYPE_PALETTE */ + + /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */ + else /* color_type != PNG_COLOR_TYPE_PALETTE */ + { + int gs_sig, g_sig; + png_fixed_point g = PNG_FP_1; /* Correction to linear */ + png_fixed_point gs = PNG_FP_1; /* Correction to screen */ + + switch (png_ptr->background_gamma_type) + { + case PNG_BACKGROUND_GAMMA_SCREEN: + g = png_ptr->screen_gamma; + /* gs = PNG_FP_1; */ + break; + + case PNG_BACKGROUND_GAMMA_FILE: + g = png_reciprocal(png_ptr->gamma); + gs = png_reciprocal2(png_ptr->gamma, png_ptr->screen_gamma); + break; + + case PNG_BACKGROUND_GAMMA_UNIQUE: + g = png_reciprocal(png_ptr->background_gamma); + gs = png_reciprocal2(png_ptr->background_gamma, + png_ptr->screen_gamma); + break; + + default: + png_error(png_ptr, "invalid background gamma type"); + } + + g_sig = png_gamma_significant(g); + gs_sig = png_gamma_significant(gs); + + if (g_sig) + png_ptr->background_1.gray = png_gamma_correct(png_ptr, + png_ptr->background.gray, g); + + if (gs_sig) + png_ptr->background.gray = png_gamma_correct(png_ptr, + png_ptr->background.gray, gs); + + if ((png_ptr->background.red != png_ptr->background.green) || + (png_ptr->background.red != png_ptr->background.blue) || + (png_ptr->background.red != png_ptr->background.gray)) + { + /* RGB or RGBA with color background */ + if (g_sig) + { + png_ptr->background_1.red = png_gamma_correct(png_ptr, + png_ptr->background.red, g); + + png_ptr->background_1.green = png_gamma_correct(png_ptr, + png_ptr->background.green, g); + + png_ptr->background_1.blue = png_gamma_correct(png_ptr, + png_ptr->background.blue, g); + } + + if (gs_sig) + { + png_ptr->background.red = png_gamma_correct(png_ptr, + png_ptr->background.red, gs); + + png_ptr->background.green = png_gamma_correct(png_ptr, + png_ptr->background.green, gs); + + png_ptr->background.blue = png_gamma_correct(png_ptr, + png_ptr->background.blue, gs); + } + } + + else + { + /* GRAY, GRAY ALPHA, RGB, or RGBA with gray background */ + png_ptr->background_1.red = png_ptr->background_1.green + = png_ptr->background_1.blue = png_ptr->background_1.gray; + + png_ptr->background.red = png_ptr->background.green + = png_ptr->background.blue = png_ptr->background.gray; + } + + /* The background is now in screen gamma: */ + png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_SCREEN; + } /* color_type != PNG_COLOR_TYPE_PALETTE */ + }/* png_ptr->transformations & PNG_BACKGROUND */ + + else + /* Transformation does not include PNG_BACKGROUND */ +#endif /* PNG_READ_BACKGROUND_SUPPORTED */ + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + /* RGB_TO_GRAY needs to have non-gamma-corrected values! */ + && ((png_ptr->transformations & PNG_EXPAND) == 0 || + (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0) +#endif + ) + { + png_colorp palette = png_ptr->palette; + int num_palette = png_ptr->num_palette; + int i; + + /* NOTE: there are other transformations that should probably be in + * here too. + */ + for (i = 0; i < num_palette; i++) + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + + /* Done the gamma correction. */ + png_ptr->transformations &= ~PNG_GAMMA; + } /* color_type == PALETTE && !PNG_BACKGROUND transformation */ + } +#ifdef PNG_READ_BACKGROUND_SUPPORTED + else +#endif +#endif /* PNG_READ_GAMMA_SUPPORTED */ + +#ifdef PNG_READ_BACKGROUND_SUPPORTED + /* No GAMMA transformation (see the hanging else 4 lines above) */ + if ((png_ptr->transformations & PNG_COMPOSE) && + (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) + { + int i; + int istop = (int)png_ptr->num_trans; + png_color back; + png_colorp palette = png_ptr->palette; + + back.red = (png_byte)png_ptr->background.red; + back.green = (png_byte)png_ptr->background.green; + back.blue = (png_byte)png_ptr->background.blue; + + for (i = 0; i < istop; i++) + { + if (png_ptr->trans_alpha[i] == 0) + { + palette[i] = back; + } + + else if (png_ptr->trans_alpha[i] != 0xff) + { + /* The png_composite() macro is defined in png.h */ + png_composite(palette[i].red, palette[i].red, + png_ptr->trans_alpha[i], back.red); + + png_composite(palette[i].green, palette[i].green, + png_ptr->trans_alpha[i], back.green); + + png_composite(palette[i].blue, palette[i].blue, + png_ptr->trans_alpha[i], back.blue); + } + } + + png_ptr->transformations &= ~PNG_COMPOSE; + } +#endif /* PNG_READ_BACKGROUND_SUPPORTED */ + +#ifdef PNG_READ_SHIFT_SUPPORTED + if ((png_ptr->transformations & PNG_SHIFT) && + !(png_ptr->transformations & PNG_EXPAND) && + (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) + { + int i; + int istop = png_ptr->num_palette; + int shift = 8 - png_ptr->sig_bit.red; + + png_ptr->transformations &= ~PNG_SHIFT; + + /* significant bits can be in the range 1 to 7 for a meaninful result, if + * the number of significant bits is 0 then no shift is done (this is an + * error condition which is silently ignored.) + */ + if (shift > 0 && shift < 8) for (i=0; ipalette[i].red; + + component >>= shift; + png_ptr->palette[i].red = (png_byte)component; + } + + shift = 8 - png_ptr->sig_bit.green; + if (shift > 0 && shift < 8) for (i=0; ipalette[i].green; + + component >>= shift; + png_ptr->palette[i].green = (png_byte)component; + } + + shift = 8 - png_ptr->sig_bit.blue; + if (shift > 0 && shift < 8) for (i=0; ipalette[i].blue; + + component >>= shift; + png_ptr->palette[i].blue = (png_byte)component; + } + } +#endif /* PNG_READ_SHIFT_SUPPORTED */ +} + +/* Modify the info structure to reflect the transformations. The + * info should be updated so a PNG file could be written with it, + * assuming the transformations result in valid PNG data. + */ +void /* PRIVATE */ +png_read_transform_info(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_read_transform_info"); + +#ifdef PNG_READ_EXPAND_SUPPORTED + if (png_ptr->transformations & PNG_EXPAND) + { + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + /* This check must match what actually happens in + * png_do_expand_palette; if it ever checks the tRNS chunk to see if + * it is all opaque we must do the same (at present it does not.) + */ + if (png_ptr->num_trans > 0) + info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA; + + else + info_ptr->color_type = PNG_COLOR_TYPE_RGB; + + info_ptr->bit_depth = 8; + info_ptr->num_trans = 0; + } + else + { + if (png_ptr->num_trans) + { + if (png_ptr->transformations & PNG_EXPAND_tRNS) + info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; + } + if (info_ptr->bit_depth < 8) + info_ptr->bit_depth = 8; + + info_ptr->num_trans = 0; + } + } +#endif + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) + /* The following is almost certainly wrong unless the background value is in + * the screen space! + */ + if (png_ptr->transformations & PNG_COMPOSE) + info_ptr->background = png_ptr->background; +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED + /* The following used to be conditional on PNG_GAMMA (prior to 1.5.4), + * however it seems that the code in png_init_read_transformations, which has + * been called before this from png_read_update_info->png_read_start_row + * sometimes does the gamma transform and cancels the flag. + */ + info_ptr->gamma = png_ptr->gamma; +#endif + + if (info_ptr->bit_depth == 16) + { +# ifdef PNG_READ_16BIT_SUPPORTED +# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED + if (png_ptr->transformations & PNG_SCALE_16_TO_8) + info_ptr->bit_depth = 8; +# endif + +# ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED + if (png_ptr->transformations & PNG_16_TO_8) + info_ptr->bit_depth = 8; +# endif + +# else + /* No 16 bit support: force chopping 16-bit input down to 8, in this case + * the app program can chose if both APIs are available by setting the + * correct scaling to use. + */ +# ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED + /* For compatibility with previous versions use the strip method by + * default. This code works because if PNG_SCALE_16_TO_8 is already + * set the code below will do that in preference to the chop. + */ + png_ptr->transformations |= PNG_16_TO_8; + info_ptr->bit_depth = 8; +# else + +# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED + png_ptr->transformations |= PNG_SCALE_16_TO_8; + info_ptr->bit_depth = 8; +# else + + CONFIGURATION ERROR: you must enable at least one 16 to 8 method +# endif +# endif +#endif /* !READ_16BIT_SUPPORTED */ + } + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + if (png_ptr->transformations & PNG_GRAY_TO_RGB) + info_ptr->color_type = (png_byte)(info_ptr->color_type | + PNG_COLOR_MASK_COLOR); +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + if (png_ptr->transformations & PNG_RGB_TO_GRAY) + info_ptr->color_type = (png_byte)(info_ptr->color_type & + ~PNG_COLOR_MASK_COLOR); +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED + if (png_ptr->transformations & PNG_QUANTIZE) + { + if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || + (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) && + png_ptr->palette_lookup && info_ptr->bit_depth == 8) + { + info_ptr->color_type = PNG_COLOR_TYPE_PALETTE; + } + } +#endif + +#ifdef PNG_READ_EXPAND_16_SUPPORTED + if (png_ptr->transformations & PNG_EXPAND_16 && info_ptr->bit_depth == 8 && + info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) + { + info_ptr->bit_depth = 16; + } +#endif + +#ifdef PNG_READ_PACK_SUPPORTED + if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8)) + info_ptr->bit_depth = 8; +#endif + + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + info_ptr->channels = 1; + + else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) + info_ptr->channels = 3; + + else + info_ptr->channels = 1; + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + if (png_ptr->transformations & PNG_STRIP_ALPHA) + { + info_ptr->color_type = (png_byte)(info_ptr->color_type & + ~PNG_COLOR_MASK_ALPHA); + info_ptr->num_trans = 0; + } +#endif + + if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) + info_ptr->channels++; + +#ifdef PNG_READ_FILLER_SUPPORTED + /* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */ + if ((png_ptr->transformations & PNG_FILLER) && + ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || + (info_ptr->color_type == PNG_COLOR_TYPE_GRAY))) + { + info_ptr->channels++; + /* If adding a true alpha channel not just filler */ + if (png_ptr->transformations & PNG_ADD_ALPHA) + info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; + } +#endif + +#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \ +defined(PNG_READ_USER_TRANSFORM_SUPPORTED) + if (png_ptr->transformations & PNG_USER_TRANSFORM) + { + if (info_ptr->bit_depth < png_ptr->user_transform_depth) + info_ptr->bit_depth = png_ptr->user_transform_depth; + + if (info_ptr->channels < png_ptr->user_transform_channels) + info_ptr->channels = png_ptr->user_transform_channels; + } +#endif + + info_ptr->pixel_depth = (png_byte)(info_ptr->channels * + info_ptr->bit_depth); + + info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width); + + /* Adding in 1.5.4: cache the above value in png_struct so that we can later + * check in png_rowbytes that the user buffer won't get overwritten. Note + * that the field is not always set - if png_read_update_info isn't called + * the application has to either not do any transforms or get the calculation + * right itself. + */ + png_ptr->info_rowbytes = info_ptr->rowbytes; + +#ifndef PNG_READ_EXPAND_SUPPORTED + if (png_ptr) + return; +#endif +} + +/* Transform the row. The order of transformations is significant, + * and is very touchy. If you add a transformation, take care to + * decide how it fits in with the other transformations here. + */ +void /* PRIVATE */ +png_do_read_transformations(png_structp png_ptr, png_row_infop row_info) +{ + png_debug(1, "in png_do_read_transformations"); + + if (png_ptr->row_buf == NULL) + { + /* Prior to 1.5.4 this output row/pass where the NULL pointer is, but this + * error is incredibly rare and incredibly easy to debug without this + * information. + */ + png_error(png_ptr, "NULL row buffer"); + } + + /* The following is debugging; prior to 1.5.4 the code was never compiled in; + * in 1.5.4 PNG_FLAG_DETECT_UNINITIALIZED was added and the macro + * PNG_WARN_UNINITIALIZED_ROW removed. In 1.5 the new flag is set only for + * selected new APIs to ensure that there is no API change. + */ + if ((png_ptr->flags & PNG_FLAG_DETECT_UNINITIALIZED) != 0 && + !(png_ptr->flags & PNG_FLAG_ROW_INIT)) + { + /* Application has failed to call either png_read_start_image() or + * png_read_update_info() after setting transforms that expand pixels. + * This check added to libpng-1.2.19 (but not enabled until 1.5.4). + */ + png_error(png_ptr, "Uninitialized row"); + } + +#ifdef PNG_READ_EXPAND_SUPPORTED + if (png_ptr->transformations & PNG_EXPAND) + { + if (row_info->color_type == PNG_COLOR_TYPE_PALETTE) + { + png_do_expand_palette(row_info, png_ptr->row_buf + 1, + png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans); + } + + else + { + if (png_ptr->num_trans && + (png_ptr->transformations & PNG_EXPAND_tRNS)) + png_do_expand(row_info, png_ptr->row_buf + 1, + &(png_ptr->trans_color)); + + else + png_do_expand(row_info, png_ptr->row_buf + 1, + NULL); + } + } +#endif + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_STRIP_ALPHA) && + !(png_ptr->transformations & PNG_COMPOSE) && + (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA || + row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) + png_do_strip_channel(row_info, png_ptr->row_buf + 1, + 0 /* at_start == false, because SWAP_ALPHA happens later */); +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + if (png_ptr->transformations & PNG_RGB_TO_GRAY) + { + int rgb_error = + png_do_rgb_to_gray(png_ptr, row_info, + png_ptr->row_buf + 1); + + if (rgb_error) + { + png_ptr->rgb_to_gray_status=1; + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == + PNG_RGB_TO_GRAY_WARN) + png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel"); + + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == + PNG_RGB_TO_GRAY_ERR) + png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel"); + } + } +#endif + +/* From Andreas Dilger e-mail to png-implement, 26 March 1998: + * + * In most cases, the "simple transparency" should be done prior to doing + * gray-to-RGB, or you will have to test 3x as many bytes to check if a + * pixel is transparent. You would also need to make sure that the + * transparency information is upgraded to RGB. + * + * To summarize, the current flow is: + * - Gray + simple transparency -> compare 1 or 2 gray bytes and composite + * with background "in place" if transparent, + * convert to RGB if necessary + * - Gray + alpha -> composite with gray background and remove alpha bytes, + * convert to RGB if necessary + * + * To support RGB backgrounds for gray images we need: + * - Gray + simple transparency -> convert to RGB + simple transparency, + * compare 3 or 6 bytes and composite with + * background "in place" if transparent + * (3x compare/pixel compared to doing + * composite with gray bkgrnd) + * - Gray + alpha -> convert to RGB + alpha, composite with background and + * remove alpha bytes (3x float + * operations/pixel compared with composite + * on gray background) + * + * Greg's change will do this. The reason it wasn't done before is for + * performance, as this increases the per-pixel operations. If we would check + * in advance if the background was gray or RGB, and position the gray-to-RGB + * transform appropriately, then it would save a lot of work/time. + */ + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + /* If gray -> RGB, do so now only if background is non-gray; else do later + * for performance reasons + */ + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && + !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) + png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1); +#endif + +#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\ + (defined PNG_READ_ALPHA_MODE_SUPPORTED) + if (png_ptr->transformations & PNG_COMPOSE) + png_do_compose(row_info, png_ptr->row_buf + 1, png_ptr); +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED + if ((png_ptr->transformations & PNG_GAMMA) && +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + /* Because RGB_TO_GRAY does the gamma transform. */ + !(png_ptr->transformations & PNG_RGB_TO_GRAY) && +#endif +#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\ + (defined PNG_READ_ALPHA_MODE_SUPPORTED) + /* Because PNG_COMPOSE does the gamma transform if there is something to + * do (if there is an alpha channel or transparency.) + */ + !((png_ptr->transformations & PNG_COMPOSE) && + ((png_ptr->num_trans != 0) || + (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) && +#endif + /* Because png_init_read_transformations transforms the palette, unless + * RGB_TO_GRAY will do the transform. + */ + (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)) + png_do_gamma(row_info, png_ptr->row_buf + 1, png_ptr); +#endif + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + if ((png_ptr->transformations & PNG_STRIP_ALPHA) && + (png_ptr->transformations & PNG_COMPOSE) && + (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA || + row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) + png_do_strip_channel(row_info, png_ptr->row_buf + 1, + 0 /* at_start == false, because SWAP_ALPHA happens later */); +#endif + +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED + if ((png_ptr->transformations & PNG_ENCODE_ALPHA) && + (row_info->color_type & PNG_COLOR_MASK_ALPHA)) + png_do_encode_alpha(row_info, png_ptr->row_buf + 1, png_ptr); +#endif + +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED + if (png_ptr->transformations & PNG_SCALE_16_TO_8) + png_do_scale_16_to_8(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED + /* There is no harm in doing both of these because only one has any effect, + * by putting the 'scale' option first if the app asks for scale (either by + * calling the API or in a TRANSFORM flag) this is what happens. + */ + if (png_ptr->transformations & PNG_16_TO_8) + png_do_chop(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED + if (png_ptr->transformations & PNG_QUANTIZE) + { + png_do_quantize(row_info, png_ptr->row_buf + 1, + png_ptr->palette_lookup, png_ptr->quantize_index); + + if (row_info->rowbytes == 0) + png_error(png_ptr, "png_do_quantize returned rowbytes=0"); + } +#endif /* PNG_READ_QUANTIZE_SUPPORTED */ + +#ifdef PNG_READ_EXPAND_16_SUPPORTED + /* Do the expansion now, after all the arithmetic has been done. Notice + * that previous transformations can handle the PNG_EXPAND_16 flag if this + * is efficient (particularly true in the case of gamma correction, where + * better accuracy results faster!) + */ + if (png_ptr->transformations & PNG_EXPAND_16) + png_do_expand_16(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + /* NOTE: moved here in 1.5.4 (from much later in this list.) */ + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && + (png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) + png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_INVERT_SUPPORTED + if (png_ptr->transformations & PNG_INVERT_MONO) + png_do_invert(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_SHIFT_SUPPORTED + if (png_ptr->transformations & PNG_SHIFT) + png_do_unshift(row_info, png_ptr->row_buf + 1, + &(png_ptr->shift)); +#endif + +#ifdef PNG_READ_PACK_SUPPORTED + if (png_ptr->transformations & PNG_PACK) + png_do_unpack(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED + /* Added at libpng-1.5.10 */ + if (row_info->color_type == PNG_COLOR_TYPE_PALETTE && + png_ptr->num_palette_max >= 0) + png_do_check_palette_indexes(png_ptr, row_info); +#endif + +#ifdef PNG_READ_BGR_SUPPORTED + if (png_ptr->transformations & PNG_BGR) + png_do_bgr(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if (png_ptr->transformations & PNG_PACKSWAP) + png_do_packswap(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_FILLER_SUPPORTED + if (png_ptr->transformations & PNG_FILLER) + png_do_read_filler(row_info, png_ptr->row_buf + 1, + (png_uint_32)png_ptr->filler, png_ptr->flags); +#endif + +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED + if (png_ptr->transformations & PNG_INVERT_ALPHA) + png_do_read_invert_alpha(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED + if (png_ptr->transformations & PNG_SWAP_ALPHA) + png_do_read_swap_alpha(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_16BIT_SUPPORTED +#ifdef PNG_READ_SWAP_SUPPORTED + if (png_ptr->transformations & PNG_SWAP_BYTES) + png_do_swap(row_info, png_ptr->row_buf + 1); +#endif +#endif + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + if (png_ptr->transformations & PNG_USER_TRANSFORM) + { + if (png_ptr->read_user_transform_fn != NULL) + (*(png_ptr->read_user_transform_fn)) /* User read transform function */ + (png_ptr, /* png_ptr */ + row_info, /* row_info: */ + /* png_uint_32 width; width of row */ + /* png_size_t rowbytes; number of bytes in row */ + /* png_byte color_type; color type of pixels */ + /* png_byte bit_depth; bit depth of samples */ + /* png_byte channels; number of channels (1-4) */ + /* png_byte pixel_depth; bits per pixel (depth*channels) */ + png_ptr->row_buf + 1); /* start of pixel data for row */ +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED + if (png_ptr->user_transform_depth) + row_info->bit_depth = png_ptr->user_transform_depth; + + if (png_ptr->user_transform_channels) + row_info->channels = png_ptr->user_transform_channels; +#endif + row_info->pixel_depth = (png_byte)(row_info->bit_depth * + row_info->channels); + + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->width); + } +#endif +} + +#ifdef PNG_READ_PACK_SUPPORTED +/* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel, + * without changing the actual values. Thus, if you had a row with + * a bit depth of 1, you would end up with bytes that only contained + * the numbers 0 or 1. If you would rather they contain 0 and 255, use + * png_do_shift() after this. + */ +void /* PRIVATE */ +png_do_unpack(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_unpack"); + + if (row_info->bit_depth < 8) + { + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + switch (row_info->bit_depth) + { + case 1: + { + png_bytep sp = row + (png_size_t)((row_width - 1) >> 3); + png_bytep dp = row + (png_size_t)row_width - 1; + png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07); + for (i = 0; i < row_width; i++) + { + *dp = (png_byte)((*sp >> shift) & 0x01); + + if (shift == 7) + { + shift = 0; + sp--; + } + + else + shift++; + + dp--; + } + break; + } + + case 2: + { + + png_bytep sp = row + (png_size_t)((row_width - 1) >> 2); + png_bytep dp = row + (png_size_t)row_width - 1; + png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); + for (i = 0; i < row_width; i++) + { + *dp = (png_byte)((*sp >> shift) & 0x03); + + if (shift == 6) + { + shift = 0; + sp--; + } + + else + shift += 2; + + dp--; + } + break; + } + + case 4: + { + png_bytep sp = row + (png_size_t)((row_width - 1) >> 1); + png_bytep dp = row + (png_size_t)row_width - 1; + png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2); + for (i = 0; i < row_width; i++) + { + *dp = (png_byte)((*sp >> shift) & 0x0f); + + if (shift == 4) + { + shift = 0; + sp--; + } + + else + shift = 4; + + dp--; + } + break; + } + + default: + break; + } + row_info->bit_depth = 8; + row_info->pixel_depth = (png_byte)(8 * row_info->channels); + row_info->rowbytes = row_width * row_info->channels; + } +} +#endif + +#ifdef PNG_READ_SHIFT_SUPPORTED +/* Reverse the effects of png_do_shift. This routine merely shifts the + * pixels back to their significant bits values. Thus, if you have + * a row of bit depth 8, but only 5 are significant, this will shift + * the values back to 0 through 31. + */ +void /* PRIVATE */ +png_do_unshift(png_row_infop row_info, png_bytep row, + png_const_color_8p sig_bits) +{ + int color_type; + + png_debug(1, "in png_do_unshift"); + + /* The palette case has already been handled in the _init routine. */ + color_type = row_info->color_type; + + if (color_type != PNG_COLOR_TYPE_PALETTE) + { + int shift[4]; + int channels = 0; + int bit_depth = row_info->bit_depth; + + if (color_type & PNG_COLOR_MASK_COLOR) + { + shift[channels++] = bit_depth - sig_bits->red; + shift[channels++] = bit_depth - sig_bits->green; + shift[channels++] = bit_depth - sig_bits->blue; + } + + else + { + shift[channels++] = bit_depth - sig_bits->gray; + } + + if (color_type & PNG_COLOR_MASK_ALPHA) + { + shift[channels++] = bit_depth - sig_bits->alpha; + } + + { + int c, have_shift; + + for (c = have_shift = 0; c < channels; ++c) + { + /* A shift of more than the bit depth is an error condition but it + * gets ignored here. + */ + if (shift[c] <= 0 || shift[c] >= bit_depth) + shift[c] = 0; + + else + have_shift = 1; + } + + if (!have_shift) + return; + } + + switch (bit_depth) + { + default: + /* Must be 1bpp gray: should not be here! */ + /* NOTREACHED */ + break; + + case 2: + /* Must be 2bpp gray */ + /* assert(channels == 1 && shift[0] == 1) */ + { + png_bytep bp = row; + png_bytep bp_end = bp + row_info->rowbytes; + + while (bp < bp_end) + { + int b = (*bp >> 1) & 0x55; + *bp++ = (png_byte)b; + } + break; + } + + case 4: + /* Must be 4bpp gray */ + /* assert(channels == 1) */ + { + png_bytep bp = row; + png_bytep bp_end = bp + row_info->rowbytes; + int gray_shift = shift[0]; + int mask = 0xf >> gray_shift; + + mask |= mask << 4; + + while (bp < bp_end) + { + int b = (*bp >> gray_shift) & mask; + *bp++ = (png_byte)b; + } + break; + } + + case 8: + /* Single byte components, G, GA, RGB, RGBA */ + { + png_bytep bp = row; + png_bytep bp_end = bp + row_info->rowbytes; + int channel = 0; + + while (bp < bp_end) + { + int b = *bp >> shift[channel]; + if (++channel >= channels) + channel = 0; + *bp++ = (png_byte)b; + } + break; + } + +#ifdef PNG_READ_16BIT_SUPPORTED + case 16: + /* Double byte components, G, GA, RGB, RGBA */ + { + png_bytep bp = row; + png_bytep bp_end = bp + row_info->rowbytes; + int channel = 0; + + while (bp < bp_end) + { + int value = (bp[0] << 8) + bp[1]; + + value >>= shift[channel]; + if (++channel >= channels) + channel = 0; + *bp++ = (png_byte)(value >> 8); + *bp++ = (png_byte)(value & 0xff); + } + break; + } +#endif + } + } +} +#endif + +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED +/* Scale rows of bit depth 16 down to 8 accurately */ +void /* PRIVATE */ +png_do_scale_16_to_8(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_scale_16_to_8"); + + if (row_info->bit_depth == 16) + { + png_bytep sp = row; /* source */ + png_bytep dp = row; /* destination */ + png_bytep ep = sp + row_info->rowbytes; /* end+1 */ + + while (sp < ep) + { + /* The input is an array of 16 bit components, these must be scaled to + * 8 bits each. For a 16 bit value V the required value (from the PNG + * specification) is: + * + * (V * 255) / 65535 + * + * This reduces to round(V / 257), or floor((V + 128.5)/257) + * + * Represent V as the two byte value vhi.vlo. Make a guess that the + * result is the top byte of V, vhi, then the correction to this value + * is: + * + * error = floor(((V-vhi.vhi) + 128.5) / 257) + * = floor(((vlo-vhi) + 128.5) / 257) + * + * This can be approximated using integer arithmetic (and a signed + * shift): + * + * error = (vlo-vhi+128) >> 8; + * + * The approximate differs from the exact answer only when (vlo-vhi) is + * 128; it then gives a correction of +1 when the exact correction is + * 0. This gives 128 errors. The exact answer (correct for all 16 bit + * input values) is: + * + * error = (vlo-vhi+128)*65535 >> 24; + * + * An alternative arithmetic calculation which also gives no errors is: + * + * (V * 255 + 32895) >> 16 + */ + + png_int_32 tmp = *sp++; /* must be signed! */ + tmp += (((int)*sp++ - tmp + 128) * 65535) >> 24; + *dp++ = (png_byte)tmp; + } + + row_info->bit_depth = 8; + row_info->pixel_depth = (png_byte)(8 * row_info->channels); + row_info->rowbytes = row_info->width * row_info->channels; + } +} +#endif + +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED +void /* PRIVATE */ +/* Simply discard the low byte. This was the default behavior prior + * to libpng-1.5.4. + */ +png_do_chop(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_chop"); + + if (row_info->bit_depth == 16) + { + png_bytep sp = row; /* source */ + png_bytep dp = row; /* destination */ + png_bytep ep = sp + row_info->rowbytes; /* end+1 */ + + while (sp < ep) + { + *dp++ = *sp; + sp += 2; /* skip low byte */ + } + + row_info->bit_depth = 8; + row_info->pixel_depth = (png_byte)(8 * row_info->channels); + row_info->rowbytes = row_info->width * row_info->channels; + } +} +#endif + +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED +void /* PRIVATE */ +png_do_read_swap_alpha(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_read_swap_alpha"); + + { + png_uint_32 row_width = row_info->width; + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + /* This converts from RGBA to ARGB */ + if (row_info->bit_depth == 8) + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save; + } + } + +#ifdef PNG_READ_16BIT_SUPPORTED + /* This converts from RRGGBBAA to AARRGGBB */ + else + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save[2]; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save[0] = *(--sp); + save[1] = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save[0]; + *(--dp) = save[1]; + } + } +#endif + } + + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + /* This converts from GA to AG */ + if (row_info->bit_depth == 8) + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save; + } + } + +#ifdef PNG_READ_16BIT_SUPPORTED + /* This converts from GGAA to AAGG */ + else + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save[2]; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save[0] = *(--sp); + save[1] = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save[0]; + *(--dp) = save[1]; + } + } +#endif + } + } +} +#endif + +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED +void /* PRIVATE */ +png_do_read_invert_alpha(png_row_infop row_info, png_bytep row) +{ + png_uint_32 row_width; + png_debug(1, "in png_do_read_invert_alpha"); + + row_width = row_info->width; + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + if (row_info->bit_depth == 8) + { + /* This inverts the alpha channel in RGBA */ + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + +/* This does nothing: + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + We can replace it with: +*/ + sp-=3; + dp=sp; + } + } + +#ifdef PNG_READ_16BIT_SUPPORTED + /* This inverts the alpha channel in RRGGBBAA */ + else + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + *(--dp) = (png_byte)(255 - *(--sp)); + +/* This does nothing: + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + We can replace it with: +*/ + sp-=6; + dp=sp; + } + } +#endif + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + if (row_info->bit_depth == 8) + { + /* This inverts the alpha channel in GA */ + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + *(--dp) = *(--sp); + } + } + +#ifdef PNG_READ_16BIT_SUPPORTED + else + { + /* This inverts the alpha channel in GGAA */ + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + *(--dp) = (png_byte)(255 - *(--sp)); +/* + *(--dp) = *(--sp); + *(--dp) = *(--sp); +*/ + sp-=2; + dp=sp; + } + } +#endif + } +} +#endif + +#ifdef PNG_READ_FILLER_SUPPORTED +/* Add filler channel if we have RGB color */ +void /* PRIVATE */ +png_do_read_filler(png_row_infop row_info, png_bytep row, + png_uint_32 filler, png_uint_32 flags) +{ + png_uint_32 i; + png_uint_32 row_width = row_info->width; + +#ifdef PNG_READ_16BIT_SUPPORTED + png_byte hi_filler = (png_byte)((filler>>8) & 0xff); +#endif + png_byte lo_filler = (png_byte)(filler & 0xff); + + png_debug(1, "in png_do_read_filler"); + + if ( + row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + if (row_info->bit_depth == 8) + { + if (flags & PNG_FLAG_FILLER_AFTER) + { + /* This changes the data from G to GX */ + png_bytep sp = row + (png_size_t)row_width; + png_bytep dp = sp + (png_size_t)row_width; + for (i = 1; i < row_width; i++) + { + *(--dp) = lo_filler; + *(--dp) = *(--sp); + } + *(--dp) = lo_filler; + row_info->channels = 2; + row_info->pixel_depth = 16; + row_info->rowbytes = row_width * 2; + } + + else + { + /* This changes the data from G to XG */ + png_bytep sp = row + (png_size_t)row_width; + png_bytep dp = sp + (png_size_t)row_width; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = lo_filler; + } + row_info->channels = 2; + row_info->pixel_depth = 16; + row_info->rowbytes = row_width * 2; + } + } + +#ifdef PNG_READ_16BIT_SUPPORTED + else if (row_info->bit_depth == 16) + { + if (flags & PNG_FLAG_FILLER_AFTER) + { + /* This changes the data from GG to GGXX */ + png_bytep sp = row + (png_size_t)row_width * 2; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 1; i < row_width; i++) + { + *(--dp) = hi_filler; + *(--dp) = lo_filler; + *(--dp) = *(--sp); + *(--dp) = *(--sp); + } + *(--dp) = hi_filler; + *(--dp) = lo_filler; + row_info->channels = 2; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + + else + { + /* This changes the data from GG to XXGG */ + png_bytep sp = row + (png_size_t)row_width * 2; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = hi_filler; + *(--dp) = lo_filler; + } + row_info->channels = 2; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + } +#endif + } /* COLOR_TYPE == GRAY */ + else if (row_info->color_type == PNG_COLOR_TYPE_RGB) + { + if (row_info->bit_depth == 8) + { + if (flags & PNG_FLAG_FILLER_AFTER) + { + /* This changes the data from RGB to RGBX */ + png_bytep sp = row + (png_size_t)row_width * 3; + png_bytep dp = sp + (png_size_t)row_width; + for (i = 1; i < row_width; i++) + { + *(--dp) = lo_filler; + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + } + *(--dp) = lo_filler; + row_info->channels = 4; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + + else + { + /* This changes the data from RGB to XRGB */ + png_bytep sp = row + (png_size_t)row_width * 3; + png_bytep dp = sp + (png_size_t)row_width; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = lo_filler; + } + row_info->channels = 4; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + } + +#ifdef PNG_READ_16BIT_SUPPORTED + else if (row_info->bit_depth == 16) + { + if (flags & PNG_FLAG_FILLER_AFTER) + { + /* This changes the data from RRGGBB to RRGGBBXX */ + png_bytep sp = row + (png_size_t)row_width * 6; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 1; i < row_width; i++) + { + *(--dp) = hi_filler; + *(--dp) = lo_filler; + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + } + *(--dp) = hi_filler; + *(--dp) = lo_filler; + row_info->channels = 4; + row_info->pixel_depth = 64; + row_info->rowbytes = row_width * 8; + } + + else + { + /* This changes the data from RRGGBB to XXRRGGBB */ + png_bytep sp = row + (png_size_t)row_width * 6; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = hi_filler; + *(--dp) = lo_filler; + } + + row_info->channels = 4; + row_info->pixel_depth = 64; + row_info->rowbytes = row_width * 8; + } + } +#endif + } /* COLOR_TYPE == RGB */ +} +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +/* Expand grayscale files to RGB, with or without alpha */ +void /* PRIVATE */ +png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) +{ + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + png_debug(1, "in png_do_gray_to_rgb"); + + if (row_info->bit_depth >= 8 && + !(row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + if (row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + if (row_info->bit_depth == 8) + { + /* This changes G to RGB */ + png_bytep sp = row + (png_size_t)row_width - 1; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(dp--) = *sp; + *(dp--) = *sp; + *(dp--) = *(sp--); + } + } + + else + { + /* This changes GG to RRGGBB */ + png_bytep sp = row + (png_size_t)row_width * 2 - 1; + png_bytep dp = sp + (png_size_t)row_width * 4; + for (i = 0; i < row_width; i++) + { + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *(sp--); + *(dp--) = *(sp--); + } + } + } + + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + if (row_info->bit_depth == 8) + { + /* This changes GA to RGBA */ + png_bytep sp = row + (png_size_t)row_width * 2 - 1; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(dp--) = *(sp--); + *(dp--) = *sp; + *(dp--) = *sp; + *(dp--) = *(sp--); + } + } + + else + { + /* This changes GGAA to RRGGBBAA */ + png_bytep sp = row + (png_size_t)row_width * 4 - 1; + png_bytep dp = sp + (png_size_t)row_width * 4; + for (i = 0; i < row_width; i++) + { + *(dp--) = *(sp--); + *(dp--) = *(sp--); + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *(sp--); + *(dp--) = *(sp--); + } + } + } + row_info->channels = (png_byte)(row_info->channels + 2); + row_info->color_type |= PNG_COLOR_MASK_COLOR; + row_info->pixel_depth = (png_byte)(row_info->channels * + row_info->bit_depth); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } +} +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +/* Reduce RGB files to grayscale, with or without alpha + * using the equation given in Poynton's ColorFAQ of 1998-01-04 at + * (THIS LINK IS DEAD June 2008 but + * versions dated 1998 through November 2002 have been archived at + * http://web.archive.org/web/20000816232553/http://www.inforamp.net/ + * ~poynton/notes/colour_and_gamma/ColorFAQ.txt ) + * Charles Poynton poynton at poynton.com + * + * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B + * + * which can be expressed with integers as + * + * Y = (6969 * R + 23434 * G + 2365 * B)/32768 + * + * Poynton's current link (as of January 2003 through July 2011): + * + * has changed the numbers slightly: + * + * Y = 0.2126*R + 0.7152*G + 0.0722*B + * + * which can be expressed with integers as + * + * Y = (6966 * R + 23436 * G + 2366 * B)/32768 + * + * Historically, however, libpng uses numbers derived from the ITU-R Rec 709 + * end point chromaticities and the D65 white point. Depending on the + * precision used for the D65 white point this produces a variety of different + * numbers, however if the four decimal place value used in ITU-R Rec 709 is + * used (0.3127,0.3290) the Y calculation would be: + * + * Y = (6968 * R + 23435 * G + 2366 * B)/32768 + * + * While this is correct the rounding results in an overflow for white, because + * the sum of the rounded coefficients is 32769, not 32768. Consequently + * libpng uses, instead, the closest non-overflowing approximation: + * + * Y = (6968 * R + 23434 * G + 2366 * B)/32768 + * + * Starting with libpng-1.5.5, if the image being converted has a cHRM chunk + * (including an sRGB chunk) then the chromaticities are used to calculate the + * coefficients. See the chunk handling in pngrutil.c for more information. + * + * In all cases the calculation is to be done in a linear colorspace. If no + * gamma information is available to correct the encoding of the original RGB + * values this results in an implicit assumption that the original PNG RGB + * values were linear. + * + * Other integer coefficents can be used via png_set_rgb_to_gray(). Because + * the API takes just red and green coefficients the blue coefficient is + * calculated to make the sum 32768. This will result in different rounding + * to that used above. + */ +int /* PRIVATE */ +png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row) + +{ + int rgb_error = 0; + + png_debug(1, "in png_do_rgb_to_gray"); + + if (!(row_info->color_type & PNG_COLOR_MASK_PALETTE) && + (row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + PNG_CONST png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff; + PNG_CONST png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff; + PNG_CONST png_uint_32 bc = 32768 - rc - gc; + PNG_CONST png_uint_32 row_width = row_info->width; + PNG_CONST int have_alpha = + (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0; + + if (row_info->bit_depth == 8) + { +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + /* Notice that gamma to/from 1 are not necessarily inverses (if + * there is an overall gamma correction). Prior to 1.5.5 this code + * checked the linearized values for equality; this doesn't match + * the documentation, the original values must be checked. + */ + if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL) + { + png_bytep sp = row; + png_bytep dp = row; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + png_byte red = *(sp++); + png_byte green = *(sp++); + png_byte blue = *(sp++); + + if (red != green || red != blue) + { + red = png_ptr->gamma_to_1[red]; + green = png_ptr->gamma_to_1[green]; + blue = png_ptr->gamma_to_1[blue]; + + rgb_error |= 1; + *(dp++) = png_ptr->gamma_from_1[ + (rc*red + gc*green + bc*blue + 16384)>>15]; + } + + else + { + /* If there is no overall correction the table will not be + * set. + */ + if (png_ptr->gamma_table != NULL) + red = png_ptr->gamma_table[red]; + + *(dp++) = red; + } + + if (have_alpha) + *(dp++) = *(sp++); + } + } + else +#endif + { + png_bytep sp = row; + png_bytep dp = row; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + png_byte red = *(sp++); + png_byte green = *(sp++); + png_byte blue = *(sp++); + + if (red != green || red != blue) + { + rgb_error |= 1; + /* NOTE: this is the historical approach which simply + * truncates the results. + */ + *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15); + } + + else + *(dp++) = red; + + if (have_alpha) + *(dp++) = *(sp++); + } + } + } + + else /* RGB bit_depth == 16 */ + { +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr->gamma_16_to_1 != NULL && png_ptr->gamma_16_from_1 != NULL) + { + png_bytep sp = row; + png_bytep dp = row; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + png_uint_16 red, green, blue, w; + + red = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; + green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; + blue = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; + + if (red == green && red == blue) + { + if (png_ptr->gamma_16_table != NULL) + w = png_ptr->gamma_16_table[(red&0xff) + >> png_ptr->gamma_shift][red>>8]; + + else + w = red; + } + + else + { + png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) + >> png_ptr->gamma_shift][red>>8]; + png_uint_16 green_1 = + png_ptr->gamma_16_to_1[(green&0xff) >> + png_ptr->gamma_shift][green>>8]; + png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) + >> png_ptr->gamma_shift][blue>>8]; + png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1 + + bc*blue_1 + 16384)>>15); + w = png_ptr->gamma_16_from_1[(gray16&0xff) >> + png_ptr->gamma_shift][gray16 >> 8]; + rgb_error |= 1; + } + + *(dp++) = (png_byte)((w>>8) & 0xff); + *(dp++) = (png_byte)(w & 0xff); + + if (have_alpha) + { + *(dp++) = *(sp++); + *(dp++) = *(sp++); + } + } + } + else +#endif + { + png_bytep sp = row; + png_bytep dp = row; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + png_uint_16 red, green, blue, gray16; + + red = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; + green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; + blue = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2; + + if (red != green || red != blue) + rgb_error |= 1; + + /* From 1.5.5 in the 16 bit case do the accurate conversion even + * in the 'fast' case - this is because this is where the code + * ends up when handling linear 16 bit data. + */ + gray16 = (png_uint_16)((rc*red + gc*green + bc*blue + 16384) >> + 15); + *(dp++) = (png_byte)((gray16>>8) & 0xff); + *(dp++) = (png_byte)(gray16 & 0xff); + + if (have_alpha) + { + *(dp++) = *(sp++); + *(dp++) = *(sp++); + } + } + } + } + + row_info->channels = (png_byte)(row_info->channels - 2); + row_info->color_type = (png_byte)(row_info->color_type & + ~PNG_COLOR_MASK_COLOR); + row_info->pixel_depth = (png_byte)(row_info->channels * + row_info->bit_depth); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } + return rgb_error; +} +#endif +#endif /* PNG_READ_TRANSFORMS_SUPPORTED */ + +#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED +/* Build a grayscale palette. Palette is assumed to be 1 << bit_depth + * large of png_color. This lets grayscale images be treated as + * paletted. Most useful for gamma correction and simplification + * of code. This API is not used internally. + */ +void PNGAPI +png_build_grayscale_palette(int bit_depth, png_colorp palette) +{ + int num_palette; + int color_inc; + int i; + int v; + + png_debug(1, "in png_do_build_grayscale_palette"); + + if (palette == NULL) + return; + + switch (bit_depth) + { + case 1: + num_palette = 2; + color_inc = 0xff; + break; + + case 2: + num_palette = 4; + color_inc = 0x55; + break; + + case 4: + num_palette = 16; + color_inc = 0x11; + break; + + case 8: + num_palette = 256; + color_inc = 1; + break; + + default: + num_palette = 0; + color_inc = 0; + break; + } + + for (i = 0, v = 0; i < num_palette; i++, v += color_inc) + { + palette[i].red = (png_byte)v; + palette[i].green = (png_byte)v; + palette[i].blue = (png_byte)v; + } +} +#endif + + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED +#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\ + (defined PNG_READ_ALPHA_MODE_SUPPORTED) +/* Replace any alpha or transparency with the supplied background color. + * "background" is already in the screen gamma, while "background_1" is + * at a gamma of 1.0. Paletted files have already been taken care of. + */ +void /* PRIVATE */ +png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr) +{ +#ifdef PNG_READ_GAMMA_SUPPORTED + png_const_bytep gamma_table = png_ptr->gamma_table; + png_const_bytep gamma_from_1 = png_ptr->gamma_from_1; + png_const_bytep gamma_to_1 = png_ptr->gamma_to_1; + png_const_uint_16pp gamma_16 = png_ptr->gamma_16_table; + png_const_uint_16pp gamma_16_from_1 = png_ptr->gamma_16_from_1; + png_const_uint_16pp gamma_16_to_1 = png_ptr->gamma_16_to_1; + int gamma_shift = png_ptr->gamma_shift; +#endif + + png_bytep sp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + int optimize = (png_ptr->flags & PNG_FLAG_OPTIMIZE_ALPHA) != 0; + int shift; + + png_debug(1, "in png_do_compose"); + + { + switch (row_info->color_type) + { + case PNG_COLOR_TYPE_GRAY: + { + switch (row_info->bit_depth) + { + case 1: + { + sp = row; + shift = 7; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x01) + == png_ptr->trans_color.gray) + { + *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff); + *sp |= (png_byte)(png_ptr->background.gray << shift); + } + + if (!shift) + { + shift = 7; + sp++; + } + + else + shift--; + } + break; + } + + case 2: + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_table != NULL) + { + sp = row; + shift = 6; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x03) + == png_ptr->trans_color.gray) + { + *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); + *sp |= (png_byte)(png_ptr->background.gray << shift); + } + + else + { + png_byte p = (png_byte)((*sp >> shift) & 0x03); + png_byte g = (png_byte)((gamma_table [p | (p << 2) | + (p << 4) | (p << 6)] >> 6) & 0x03); + *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); + *sp |= (png_byte)(g << shift); + } + + if (!shift) + { + shift = 6; + sp++; + } + + else + shift -= 2; + } + } + + else +#endif + { + sp = row; + shift = 6; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x03) + == png_ptr->trans_color.gray) + { + *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); + *sp |= (png_byte)(png_ptr->background.gray << shift); + } + + if (!shift) + { + shift = 6; + sp++; + } + + else + shift -= 2; + } + } + break; + } + + case 4: + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_table != NULL) + { + sp = row; + shift = 4; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x0f) + == png_ptr->trans_color.gray) + { + *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); + *sp |= (png_byte)(png_ptr->background.gray << shift); + } + + else + { + png_byte p = (png_byte)((*sp >> shift) & 0x0f); + png_byte g = (png_byte)((gamma_table[p | + (p << 4)] >> 4) & 0x0f); + *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); + *sp |= (png_byte)(g << shift); + } + + if (!shift) + { + shift = 4; + sp++; + } + + else + shift -= 4; + } + } + + else +#endif + { + sp = row; + shift = 4; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x0f) + == png_ptr->trans_color.gray) + { + *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); + *sp |= (png_byte)(png_ptr->background.gray << shift); + } + + if (!shift) + { + shift = 4; + sp++; + } + + else + shift -= 4; + } + } + break; + } + + case 8: + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_table != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp++) + { + if (*sp == png_ptr->trans_color.gray) + *sp = (png_byte)png_ptr->background.gray; + + else + *sp = gamma_table[*sp]; + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp++) + { + if (*sp == png_ptr->trans_color.gray) + *sp = (png_byte)png_ptr->background.gray; + } + } + break; + } + + case 16: + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_16 != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 2) + { + png_uint_16 v; + + v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + + if (v == png_ptr->trans_color.gray) + { + /* Background is already in screen gamma */ + *sp = (png_byte)((png_ptr->background.gray >> 8) + & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.gray + & 0xff); + } + + else + { + v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 2) + { + png_uint_16 v; + + v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + + if (v == png_ptr->trans_color.gray) + { + *sp = (png_byte)((png_ptr->background.gray >> 8) + & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.gray + & 0xff); + } + } + } + break; + } + + default: + break; + } + break; + } + + case PNG_COLOR_TYPE_RGB: + { + if (row_info->bit_depth == 8) + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_table != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 3) + { + if (*sp == png_ptr->trans_color.red && + *(sp + 1) == png_ptr->trans_color.green && + *(sp + 2) == png_ptr->trans_color.blue) + { + *sp = (png_byte)png_ptr->background.red; + *(sp + 1) = (png_byte)png_ptr->background.green; + *(sp + 2) = (png_byte)png_ptr->background.blue; + } + + else + { + *sp = gamma_table[*sp]; + *(sp + 1) = gamma_table[*(sp + 1)]; + *(sp + 2) = gamma_table[*(sp + 2)]; + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 3) + { + if (*sp == png_ptr->trans_color.red && + *(sp + 1) == png_ptr->trans_color.green && + *(sp + 2) == png_ptr->trans_color.blue) + { + *sp = (png_byte)png_ptr->background.red; + *(sp + 1) = (png_byte)png_ptr->background.green; + *(sp + 2) = (png_byte)png_ptr->background.blue; + } + } + } + } + else /* if (row_info->bit_depth == 16) */ + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_16 != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 6) + { + png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + + png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8) + + *(sp + 3)); + + png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8) + + *(sp + 5)); + + if (r == png_ptr->trans_color.red && + g == png_ptr->trans_color.green && + b == png_ptr->trans_color.blue) + { + /* Background is already in screen gamma */ + *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); + *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) + & 0xff); + *(sp + 3) = (png_byte)(png_ptr->background.green + & 0xff); + *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) + & 0xff); + *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); + } + + else + { + png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + + v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)]; + *(sp + 2) = (png_byte)((v >> 8) & 0xff); + *(sp + 3) = (png_byte)(v & 0xff); + + v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)]; + *(sp + 4) = (png_byte)((v >> 8) & 0xff); + *(sp + 5) = (png_byte)(v & 0xff); + } + } + } + + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 6) + { + png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + + png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8) + + *(sp + 3)); + + png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8) + + *(sp + 5)); + + if (r == png_ptr->trans_color.red && + g == png_ptr->trans_color.green && + b == png_ptr->trans_color.blue) + { + *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); + *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) + & 0xff); + *(sp + 3) = (png_byte)(png_ptr->background.green + & 0xff); + *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) + & 0xff); + *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); + } + } + } + } + break; + } + + case PNG_COLOR_TYPE_GRAY_ALPHA: + { + if (row_info->bit_depth == 8) + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_to_1 != NULL && gamma_from_1 != NULL && + gamma_table != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 2) + { + png_uint_16 a = *(sp + 1); + + if (a == 0xff) + *sp = gamma_table[*sp]; + + else if (a == 0) + { + /* Background is already in screen gamma */ + *sp = (png_byte)png_ptr->background.gray; + } + + else + { + png_byte v, w; + + v = gamma_to_1[*sp]; + png_composite(w, v, a, png_ptr->background_1.gray); + if (!optimize) + w = gamma_from_1[w]; + *sp = w; + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 2) + { + png_byte a = *(sp + 1); + + if (a == 0) + *sp = (png_byte)png_ptr->background.gray; + + else if (a < 0xff) + png_composite(*sp, *sp, a, png_ptr->background_1.gray); + } + } + } + else /* if (png_ptr->bit_depth == 16) */ + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_16 != NULL && gamma_16_from_1 != NULL && + gamma_16_to_1 != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 4) + { + png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8) + + *(sp + 3)); + + if (a == (png_uint_16)0xffff) + { + png_uint_16 v; + + v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + } + + else if (a == 0) + { + /* Background is already in screen gamma */ + *sp = (png_byte)((png_ptr->background.gray >> 8) + & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff); + } + + else + { + png_uint_16 g, v, w; + + g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; + png_composite_16(v, g, a, png_ptr->background_1.gray); + if (optimize) + w = v; + else + w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8]; + *sp = (png_byte)((w >> 8) & 0xff); + *(sp + 1) = (png_byte)(w & 0xff); + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 4) + { + png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8) + + *(sp + 3)); + + if (a == 0) + { + *sp = (png_byte)((png_ptr->background.gray >> 8) + & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff); + } + + else if (a < 0xffff) + { + png_uint_16 g, v; + + g = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + png_composite_16(v, g, a, png_ptr->background_1.gray); + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + } + } + } + } + break; + } + + case PNG_COLOR_TYPE_RGB_ALPHA: + { + if (row_info->bit_depth == 8) + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_to_1 != NULL && gamma_from_1 != NULL && + gamma_table != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 4) + { + png_byte a = *(sp + 3); + + if (a == 0xff) + { + *sp = gamma_table[*sp]; + *(sp + 1) = gamma_table[*(sp + 1)]; + *(sp + 2) = gamma_table[*(sp + 2)]; + } + + else if (a == 0) + { + /* Background is already in screen gamma */ + *sp = (png_byte)png_ptr->background.red; + *(sp + 1) = (png_byte)png_ptr->background.green; + *(sp + 2) = (png_byte)png_ptr->background.blue; + } + + else + { + png_byte v, w; + + v = gamma_to_1[*sp]; + png_composite(w, v, a, png_ptr->background_1.red); + if (!optimize) w = gamma_from_1[w]; + *sp = w; + + v = gamma_to_1[*(sp + 1)]; + png_composite(w, v, a, png_ptr->background_1.green); + if (!optimize) w = gamma_from_1[w]; + *(sp + 1) = w; + + v = gamma_to_1[*(sp + 2)]; + png_composite(w, v, a, png_ptr->background_1.blue); + if (!optimize) w = gamma_from_1[w]; + *(sp + 2) = w; + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 4) + { + png_byte a = *(sp + 3); + + if (a == 0) + { + *sp = (png_byte)png_ptr->background.red; + *(sp + 1) = (png_byte)png_ptr->background.green; + *(sp + 2) = (png_byte)png_ptr->background.blue; + } + + else if (a < 0xff) + { + png_composite(*sp, *sp, a, png_ptr->background.red); + + png_composite(*(sp + 1), *(sp + 1), a, + png_ptr->background.green); + + png_composite(*(sp + 2), *(sp + 2), a, + png_ptr->background.blue); + } + } + } + } + else /* if (row_info->bit_depth == 16) */ + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_16 != NULL && gamma_16_from_1 != NULL && + gamma_16_to_1 != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 8) + { + png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6)) + << 8) + (png_uint_16)(*(sp + 7))); + + if (a == (png_uint_16)0xffff) + { + png_uint_16 v; + + v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + + v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)]; + *(sp + 2) = (png_byte)((v >> 8) & 0xff); + *(sp + 3) = (png_byte)(v & 0xff); + + v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)]; + *(sp + 4) = (png_byte)((v >> 8) & 0xff); + *(sp + 5) = (png_byte)(v & 0xff); + } + + else if (a == 0) + { + /* Background is already in screen gamma */ + *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); + *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) + & 0xff); + *(sp + 3) = (png_byte)(png_ptr->background.green + & 0xff); + *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) + & 0xff); + *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); + } + + else + { + png_uint_16 v, w; + + v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; + png_composite_16(w, v, a, png_ptr->background_1.red); + if (!optimize) + w = gamma_16_from_1[((w&0xff) >> gamma_shift)] + [w >> 8]; + *sp = (png_byte)((w >> 8) & 0xff); + *(sp + 1) = (png_byte)(w & 0xff); + + v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)]; + png_composite_16(w, v, a, png_ptr->background_1.green); + if (!optimize) + w = gamma_16_from_1[((w&0xff) >> gamma_shift)] + [w >> 8]; + + *(sp + 2) = (png_byte)((w >> 8) & 0xff); + *(sp + 3) = (png_byte)(w & 0xff); + + v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)]; + png_composite_16(w, v, a, png_ptr->background_1.blue); + if (!optimize) + w = gamma_16_from_1[((w&0xff) >> gamma_shift)] + [w >> 8]; + + *(sp + 4) = (png_byte)((w >> 8) & 0xff); + *(sp + 5) = (png_byte)(w & 0xff); + } + } + } + + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 8) + { + png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6)) + << 8) + (png_uint_16)(*(sp + 7))); + + if (a == 0) + { + *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff); + *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff); + *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) + & 0xff); + *(sp + 3) = (png_byte)(png_ptr->background.green + & 0xff); + *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) + & 0xff); + *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff); + } + + else if (a < 0xffff) + { + png_uint_16 v; + + png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8) + + *(sp + 3)); + png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8) + + *(sp + 5)); + + png_composite_16(v, r, a, png_ptr->background.red); + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + + png_composite_16(v, g, a, png_ptr->background.green); + *(sp + 2) = (png_byte)((v >> 8) & 0xff); + *(sp + 3) = (png_byte)(v & 0xff); + + png_composite_16(v, b, a, png_ptr->background.blue); + *(sp + 4) = (png_byte)((v >> 8) & 0xff); + *(sp + 5) = (png_byte)(v & 0xff); + } + } + } + } + break; + } + + default: + break; + } + } +} +#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_READ_ALPHA_MODE_SUPPORTED */ + +#ifdef PNG_READ_GAMMA_SUPPORTED +/* Gamma correct the image, avoiding the alpha channel. Make sure + * you do this after you deal with the transparency issue on grayscale + * or RGB images. If your bit depth is 8, use gamma_table, if it + * is 16, use gamma_16_table and gamma_shift. Build these with + * build_gamma_table(). + */ +void /* PRIVATE */ +png_do_gamma(png_row_infop row_info, png_bytep row, png_structp png_ptr) +{ + png_const_bytep gamma_table = png_ptr->gamma_table; + png_const_uint_16pp gamma_16_table = png_ptr->gamma_16_table; + int gamma_shift = png_ptr->gamma_shift; + + png_bytep sp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_gamma"); + + if (((row_info->bit_depth <= 8 && gamma_table != NULL) || + (row_info->bit_depth == 16 && gamma_16_table != NULL))) + { + switch (row_info->color_type) + { + case PNG_COLOR_TYPE_RGB: + { + if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp++; + *sp = gamma_table[*sp]; + sp++; + *sp = gamma_table[*sp]; + sp++; + } + } + + else /* if (row_info->bit_depth == 16) */ + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v; + + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + } + } + break; + } + + case PNG_COLOR_TYPE_RGB_ALPHA: + { + if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp++; + + *sp = gamma_table[*sp]; + sp++; + + *sp = gamma_table[*sp]; + sp++; + + sp++; + } + } + + else /* if (row_info->bit_depth == 16) */ + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 4; + } + } + break; + } + + case PNG_COLOR_TYPE_GRAY_ALPHA: + { + if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp += 2; + } + } + + else /* if (row_info->bit_depth == 16) */ + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 4; + } + } + break; + } + + case PNG_COLOR_TYPE_GRAY: + { + if (row_info->bit_depth == 2) + { + sp = row; + for (i = 0; i < row_width; i += 4) + { + int a = *sp & 0xc0; + int b = *sp & 0x30; + int c = *sp & 0x0c; + int d = *sp & 0x03; + + *sp = (png_byte)( + ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)| + ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)| + ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)| + ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) )); + sp++; + } + } + + if (row_info->bit_depth == 4) + { + sp = row; + for (i = 0; i < row_width; i += 2) + { + int msb = *sp & 0xf0; + int lsb = *sp & 0x0f; + + *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0) + | (((int)gamma_table[(lsb << 4) | lsb]) >> 4)); + sp++; + } + } + + else if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp++; + } + } + + else if (row_info->bit_depth == 16) + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + } + } + break; + } + + default: + break; + } + } +} +#endif + +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED +/* Encode the alpha channel to the output gamma (the input channel is always + * linear.) Called only with color types that have an alpha channel. Needs the + * from_1 tables. + */ +void /* PRIVATE */ +png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structp png_ptr) +{ + png_uint_32 row_width = row_info->width; + + png_debug(1, "in png_do_encode_alpha"); + + if (row_info->color_type & PNG_COLOR_MASK_ALPHA) + { + if (row_info->bit_depth == 8) + { + PNG_CONST png_bytep table = png_ptr->gamma_from_1; + + if (table != NULL) + { + PNG_CONST int step = + (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 4 : 2; + + /* The alpha channel is the last component: */ + row += step - 1; + + for (; row_width > 0; --row_width, row += step) + *row = table[*row]; + + return; + } + } + + else if (row_info->bit_depth == 16) + { + PNG_CONST png_uint_16pp table = png_ptr->gamma_16_from_1; + PNG_CONST int gamma_shift = png_ptr->gamma_shift; + + if (table != NULL) + { + PNG_CONST int step = + (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 8 : 4; + + /* The alpha channel is the last component: */ + row += step - 2; + + for (; row_width > 0; --row_width, row += step) + { + png_uint_16 v; + + v = table[*(row + 1) >> gamma_shift][*row]; + *row = (png_byte)((v >> 8) & 0xff); + *(row + 1) = (png_byte)(v & 0xff); + } + + return; + } + } + } + + /* Only get to here if called with a weird row_info; no harm has been done, + * so just issue a warning. + */ + png_warning(png_ptr, "png_do_encode_alpha: unexpected call"); +} +#endif + +#ifdef PNG_READ_EXPAND_SUPPORTED +/* Expands a palette row to an RGB or RGBA row depending + * upon whether you supply trans and num_trans. + */ +void /* PRIVATE */ +png_do_expand_palette(png_row_infop row_info, png_bytep row, + png_const_colorp palette, png_const_bytep trans_alpha, int num_trans) +{ + int shift, value; + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_expand_palette"); + + if (row_info->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (row_info->bit_depth < 8) + { + switch (row_info->bit_depth) + { + case 1: + { + sp = row + (png_size_t)((row_width - 1) >> 3); + dp = row + (png_size_t)row_width - 1; + shift = 7 - (int)((row_width + 7) & 0x07); + for (i = 0; i < row_width; i++) + { + if ((*sp >> shift) & 0x01) + *dp = 1; + + else + *dp = 0; + + if (shift == 7) + { + shift = 0; + sp--; + } + + else + shift++; + + dp--; + } + break; + } + + case 2: + { + sp = row + (png_size_t)((row_width - 1) >> 2); + dp = row + (png_size_t)row_width - 1; + shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x03; + *dp = (png_byte)value; + if (shift == 6) + { + shift = 0; + sp--; + } + + else + shift += 2; + + dp--; + } + break; + } + + case 4: + { + sp = row + (png_size_t)((row_width - 1) >> 1); + dp = row + (png_size_t)row_width - 1; + shift = (int)((row_width & 0x01) << 2); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x0f; + *dp = (png_byte)value; + if (shift == 4) + { + shift = 0; + sp--; + } + + else + shift += 4; + + dp--; + } + break; + } + + default: + break; + } + row_info->bit_depth = 8; + row_info->pixel_depth = 8; + row_info->rowbytes = row_width; + } + + if (row_info->bit_depth == 8) + { + { + if (num_trans > 0) + { + sp = row + (png_size_t)row_width - 1; + dp = row + (png_size_t)(row_width << 2) - 1; + + for (i = 0; i < row_width; i++) + { + if ((int)(*sp) >= num_trans) + *dp-- = 0xff; + + else + *dp-- = trans_alpha[*sp]; + + *dp-- = palette[*sp].blue; + *dp-- = palette[*sp].green; + *dp-- = palette[*sp].red; + sp--; + } + row_info->bit_depth = 8; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + row_info->color_type = 6; + row_info->channels = 4; + } + + else + { + sp = row + (png_size_t)row_width - 1; + dp = row + (png_size_t)(row_width * 3) - 1; + + for (i = 0; i < row_width; i++) + { + *dp-- = palette[*sp].blue; + *dp-- = palette[*sp].green; + *dp-- = palette[*sp].red; + sp--; + } + + row_info->bit_depth = 8; + row_info->pixel_depth = 24; + row_info->rowbytes = row_width * 3; + row_info->color_type = 2; + row_info->channels = 3; + } + } + } + } +} + +/* If the bit depth < 8, it is expanded to 8. Also, if the already + * expanded transparency value is supplied, an alpha channel is built. + */ +void /* PRIVATE */ +png_do_expand(png_row_infop row_info, png_bytep row, + png_const_color_16p trans_color) +{ + int shift, value; + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_expand"); + + { + if (row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + png_uint_16 gray = (png_uint_16)(trans_color ? trans_color->gray : 0); + + if (row_info->bit_depth < 8) + { + switch (row_info->bit_depth) + { + case 1: + { + gray = (png_uint_16)((gray & 0x01) * 0xff); + sp = row + (png_size_t)((row_width - 1) >> 3); + dp = row + (png_size_t)row_width - 1; + shift = 7 - (int)((row_width + 7) & 0x07); + for (i = 0; i < row_width; i++) + { + if ((*sp >> shift) & 0x01) + *dp = 0xff; + + else + *dp = 0; + + if (shift == 7) + { + shift = 0; + sp--; + } + + else + shift++; + + dp--; + } + break; + } + + case 2: + { + gray = (png_uint_16)((gray & 0x03) * 0x55); + sp = row + (png_size_t)((row_width - 1) >> 2); + dp = row + (png_size_t)row_width - 1; + shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x03; + *dp = (png_byte)(value | (value << 2) | (value << 4) | + (value << 6)); + if (shift == 6) + { + shift = 0; + sp--; + } + + else + shift += 2; + + dp--; + } + break; + } + + case 4: + { + gray = (png_uint_16)((gray & 0x0f) * 0x11); + sp = row + (png_size_t)((row_width - 1) >> 1); + dp = row + (png_size_t)row_width - 1; + shift = (int)((1 - ((row_width + 1) & 0x01)) << 2); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x0f; + *dp = (png_byte)(value | (value << 4)); + if (shift == 4) + { + shift = 0; + sp--; + } + + else + shift = 4; + + dp--; + } + break; + } + + default: + break; + } + + row_info->bit_depth = 8; + row_info->pixel_depth = 8; + row_info->rowbytes = row_width; + } + + if (trans_color != NULL) + { + if (row_info->bit_depth == 8) + { + gray = gray & 0xff; + sp = row + (png_size_t)row_width - 1; + dp = row + (png_size_t)(row_width << 1) - 1; + + for (i = 0; i < row_width; i++) + { + if (*sp == gray) + *dp-- = 0; + + else + *dp-- = 0xff; + + *dp-- = *sp--; + } + } + + else if (row_info->bit_depth == 16) + { + png_byte gray_high = (png_byte)((gray >> 8) & 0xff); + png_byte gray_low = (png_byte)(gray & 0xff); + sp = row + row_info->rowbytes - 1; + dp = row + (row_info->rowbytes << 1) - 1; + for (i = 0; i < row_width; i++) + { + if (*(sp - 1) == gray_high && *(sp) == gray_low) + { + *dp-- = 0; + *dp-- = 0; + } + + else + { + *dp-- = 0xff; + *dp-- = 0xff; + } + + *dp-- = *sp--; + *dp-- = *sp--; + } + } + + row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA; + row_info->channels = 2; + row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, + row_width); + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_color) + { + if (row_info->bit_depth == 8) + { + png_byte red = (png_byte)(trans_color->red & 0xff); + png_byte green = (png_byte)(trans_color->green & 0xff); + png_byte blue = (png_byte)(trans_color->blue & 0xff); + sp = row + (png_size_t)row_info->rowbytes - 1; + dp = row + (png_size_t)(row_width << 2) - 1; + for (i = 0; i < row_width; i++) + { + if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue) + *dp-- = 0; + + else + *dp-- = 0xff; + + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + } + } + else if (row_info->bit_depth == 16) + { + png_byte red_high = (png_byte)((trans_color->red >> 8) & 0xff); + png_byte green_high = (png_byte)((trans_color->green >> 8) & 0xff); + png_byte blue_high = (png_byte)((trans_color->blue >> 8) & 0xff); + png_byte red_low = (png_byte)(trans_color->red & 0xff); + png_byte green_low = (png_byte)(trans_color->green & 0xff); + png_byte blue_low = (png_byte)(trans_color->blue & 0xff); + sp = row + row_info->rowbytes - 1; + dp = row + (png_size_t)(row_width << 3) - 1; + for (i = 0; i < row_width; i++) + { + if (*(sp - 5) == red_high && + *(sp - 4) == red_low && + *(sp - 3) == green_high && + *(sp - 2) == green_low && + *(sp - 1) == blue_high && + *(sp ) == blue_low) + { + *dp-- = 0; + *dp-- = 0; + } + + else + { + *dp-- = 0xff; + *dp-- = 0xff; + } + + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + } + } + row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA; + row_info->channels = 4; + row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } + } +} +#endif + +#ifdef PNG_READ_EXPAND_16_SUPPORTED +/* If the bit depth is 8 and the color type is not a palette type expand the + * whole row to 16 bits. Has no effect otherwise. + */ +void /* PRIVATE */ +png_do_expand_16(png_row_infop row_info, png_bytep row) +{ + if (row_info->bit_depth == 8 && + row_info->color_type != PNG_COLOR_TYPE_PALETTE) + { + /* The row have a sequence of bytes containing [0..255] and we need + * to turn it into another row containing [0..65535], to do this we + * calculate: + * + * (input / 255) * 65535 + * + * Which happens to be exactly input * 257 and this can be achieved + * simply by byte replication in place (copying backwards). + */ + png_byte *sp = row + row_info->rowbytes; /* source, last byte + 1 */ + png_byte *dp = sp + row_info->rowbytes; /* destination, end + 1 */ + while (dp > sp) + dp[-2] = dp[-1] = *--sp, dp -= 2; + + row_info->rowbytes *= 2; + row_info->bit_depth = 16; + row_info->pixel_depth = (png_byte)(row_info->channels * 16); + } +} +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED +void /* PRIVATE */ +png_do_quantize(png_row_infop row_info, png_bytep row, + png_const_bytep palette_lookup, png_const_bytep quantize_lookup) +{ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_quantize"); + + if (row_info->bit_depth == 8) + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB && palette_lookup) + { + int r, g, b, p; + sp = row; + dp = row; + for (i = 0; i < row_width; i++) + { + r = *sp++; + g = *sp++; + b = *sp++; + + /* This looks real messy, but the compiler will reduce + * it down to a reasonable formula. For example, with + * 5 bits per color, we get: + * p = (((r >> 3) & 0x1f) << 10) | + * (((g >> 3) & 0x1f) << 5) | + * ((b >> 3) & 0x1f); + */ + p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) & + ((1 << PNG_QUANTIZE_RED_BITS) - 1)) << + (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) | + (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) & + ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) << + (PNG_QUANTIZE_BLUE_BITS)) | + ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) & + ((1 << PNG_QUANTIZE_BLUE_BITS) - 1)); + + *dp++ = palette_lookup[p]; + } + + row_info->color_type = PNG_COLOR_TYPE_PALETTE; + row_info->channels = 1; + row_info->pixel_depth = row_info->bit_depth; + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA && + palette_lookup != NULL) + { + int r, g, b, p; + sp = row; + dp = row; + for (i = 0; i < row_width; i++) + { + r = *sp++; + g = *sp++; + b = *sp++; + sp++; + + p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) & + ((1 << PNG_QUANTIZE_RED_BITS) - 1)) << + (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) | + (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) & + ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) << + (PNG_QUANTIZE_BLUE_BITS)) | + ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) & + ((1 << PNG_QUANTIZE_BLUE_BITS) - 1)); + + *dp++ = palette_lookup[p]; + } + + row_info->color_type = PNG_COLOR_TYPE_PALETTE; + row_info->channels = 1; + row_info->pixel_depth = row_info->bit_depth; + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } + + else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE && + quantize_lookup) + { + sp = row; + + for (i = 0; i < row_width; i++, sp++) + { + *sp = quantize_lookup[*sp]; + } + } + } +} +#endif /* PNG_READ_QUANTIZE_SUPPORTED */ +#endif /* PNG_READ_TRANSFORMS_SUPPORTED */ + +#ifdef PNG_MNG_FEATURES_SUPPORTED +/* Undoes intrapixel differencing */ +void /* PRIVATE */ +png_do_read_intrapixel(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_read_intrapixel"); + + if ( + (row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + int bytes_per_pixel; + png_uint_32 row_width = row_info->width; + + if (row_info->bit_depth == 8) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 3; + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 4; + + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + *(rp) = (png_byte)((256 + *rp + *(rp + 1)) & 0xff); + *(rp+2) = (png_byte)((256 + *(rp + 2) + *(rp + 1)) & 0xff); + } + } + else if (row_info->bit_depth == 16) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 6; + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 8; + + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1); + png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3); + png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5); + png_uint_32 red = (s0 + s1 + 65536) & 0xffff; + png_uint_32 blue = (s2 + s1 + 65536) & 0xffff; + *(rp ) = (png_byte)((red >> 8) & 0xff); + *(rp + 1) = (png_byte)(red & 0xff); + *(rp + 4) = (png_byte)((blue >> 8) & 0xff); + *(rp + 5) = (png_byte)(blue & 0xff); + } + } + } +} +#endif /* PNG_MNG_FEATURES_SUPPORTED */ +#endif /* PNG_READ_SUPPORTED */ diff --git a/Source/LibPNG/pngrutil.c b/Source/LibPNG/pngrutil.c index b9c3905..4ef05fe 100644 --- a/Source/LibPNG/pngrutil.c +++ b/Source/LibPNG/pngrutil.c @@ -1,4159 +1,4159 @@ - -/* pngrutil.c - utilities to read a PNG file - * - * Last changed in libpng 1.5.10 [March 8, 2012] - * Copyright (c) 1998-2012 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - * - * This file contains routines that are only called from within - * libpng itself during the course of reading an image. - */ - -#include "pngpriv.h" - -#ifdef PNG_READ_SUPPORTED - -#define png_strtod(p,a,b) strtod(a,b) - -png_uint_32 PNGAPI -png_get_uint_31(png_structp png_ptr, png_const_bytep buf) -{ - png_uint_32 uval = png_get_uint_32(buf); - - if (uval > PNG_UINT_31_MAX) - png_error(png_ptr, "PNG unsigned integer out of range"); - - return (uval); -} - -#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_READ_cHRM_SUPPORTED) -/* The following is a variation on the above for use with the fixed - * point values used for gAMA and cHRM. Instead of png_error it - * issues a warning and returns (-1) - an invalid value because both - * gAMA and cHRM use *unsigned* integers for fixed point values. - */ -#define PNG_FIXED_ERROR (-1) - -static png_fixed_point /* PRIVATE */ -png_get_fixed_point(png_structp png_ptr, png_const_bytep buf) -{ - png_uint_32 uval = png_get_uint_32(buf); - - if (uval <= PNG_UINT_31_MAX) - return (png_fixed_point)uval; /* known to be in range */ - - /* The caller can turn off the warning by passing NULL. */ - if (png_ptr != NULL) - png_warning(png_ptr, "PNG fixed point integer out of range"); - - return PNG_FIXED_ERROR; -} -#endif - -#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED -/* NOTE: the read macros will obscure these definitions, so that if - * PNG_USE_READ_MACROS is set the library will not use them internally, - * but the APIs will still be available externally. - * - * The parentheses around "PNGAPI function_name" in the following three - * functions are necessary because they allow the macros to co-exist with - * these (unused but exported) functions. - */ - -/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */ -png_uint_32 (PNGAPI -png_get_uint_32)(png_const_bytep buf) -{ - png_uint_32 uval = - ((png_uint_32)(*(buf )) << 24) + - ((png_uint_32)(*(buf + 1)) << 16) + - ((png_uint_32)(*(buf + 2)) << 8) + - ((png_uint_32)(*(buf + 3)) ) ; - - return uval; -} - -/* Grab a signed 32-bit integer from a buffer in big-endian format. The - * data is stored in the PNG file in two's complement format and there - * is no guarantee that a 'png_int_32' is exactly 32 bits, therefore - * the following code does a two's complement to native conversion. - */ -png_int_32 (PNGAPI -png_get_int_32)(png_const_bytep buf) -{ - png_uint_32 uval = png_get_uint_32(buf); - if ((uval & 0x80000000) == 0) /* non-negative */ - return uval; - - uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */ - return -(png_int_32)uval; -} - -/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */ -png_uint_16 (PNGAPI -png_get_uint_16)(png_const_bytep buf) -{ - /* ANSI-C requires an int value to accomodate at least 16 bits so this - * works and allows the compiler not to worry about possible narrowing - * on 32 bit systems. (Pre-ANSI systems did not make integers smaller - * than 16 bits either.) - */ - unsigned int val = - ((unsigned int)(*buf) << 8) + - ((unsigned int)(*(buf + 1))); - - return (png_uint_16)val; -} - -#endif /* PNG_READ_INT_FUNCTIONS_SUPPORTED */ - -/* Read and check the PNG file signature */ -void /* PRIVATE */ -png_read_sig(png_structp png_ptr, png_infop info_ptr) -{ - png_size_t num_checked, num_to_check; - - /* Exit if the user application does not expect a signature. */ - if (png_ptr->sig_bytes >= 8) - return; - - num_checked = png_ptr->sig_bytes; - num_to_check = 8 - num_checked; - -#ifdef PNG_IO_STATE_SUPPORTED - png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE; -#endif - - /* The signature must be serialized in a single I/O call. */ - png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check); - png_ptr->sig_bytes = 8; - - if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) - { - if (num_checked < 4 && - png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) - png_error(png_ptr, "Not a PNG file"); - else - png_error(png_ptr, "PNG file corrupted by ASCII conversion"); - } - if (num_checked < 3) - png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; -} - -/* Read the chunk header (length + type name). - * Put the type name into png_ptr->chunk_name, and return the length. - */ -png_uint_32 /* PRIVATE */ -png_read_chunk_header(png_structp png_ptr) -{ - png_byte buf[8]; - png_uint_32 length; - -#ifdef PNG_IO_STATE_SUPPORTED - png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_HDR; -#endif - - /* Read the length and the chunk name. - * This must be performed in a single I/O call. - */ - png_read_data(png_ptr, buf, 8); - length = png_get_uint_31(png_ptr, buf); - - /* Put the chunk name into png_ptr->chunk_name. */ - png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(buf+4); - - png_debug2(0, "Reading %lx chunk, length = %lu", - (unsigned long)png_ptr->chunk_name, (unsigned long)length); - - /* Reset the crc and run it over the chunk name. */ - png_reset_crc(png_ptr); - png_calculate_crc(png_ptr, buf + 4, 4); - - /* Check to see if chunk name is valid. */ - png_check_chunk_name(png_ptr, png_ptr->chunk_name); - -#ifdef PNG_IO_STATE_SUPPORTED - png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA; -#endif - - return length; -} - -/* Read data, and (optionally) run it through the CRC. */ -void /* PRIVATE */ -png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length) -{ - if (png_ptr == NULL) - return; - - png_read_data(png_ptr, buf, length); - png_calculate_crc(png_ptr, buf, length); -} - -/* Optionally skip data and then check the CRC. Depending on whether we - * are reading a ancillary or critical chunk, and how the program has set - * things up, we may calculate the CRC on the data and print a message. - * Returns '1' if there was a CRC error, '0' otherwise. - */ -int /* PRIVATE */ -png_crc_finish(png_structp png_ptr, png_uint_32 skip) -{ - png_size_t i; - png_size_t istop = png_ptr->zbuf_size; - - for (i = (png_size_t)skip; i > istop; i -= istop) - { - png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); - } - - if (i) - { - png_crc_read(png_ptr, png_ptr->zbuf, i); - } - - if (png_crc_error(png_ptr)) - { - if (PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name) ? - !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) : - (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)) - { - png_chunk_warning(png_ptr, "CRC error"); - } - - else - { - png_chunk_benign_error(png_ptr, "CRC error"); - return (0); - } - - return (1); - } - - return (0); -} - -/* Compare the CRC stored in the PNG file with that calculated by libpng from - * the data it has read thus far. - */ -int /* PRIVATE */ -png_crc_error(png_structp png_ptr) -{ - png_byte crc_bytes[4]; - png_uint_32 crc; - int need_crc = 1; - - if (PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name)) - { - if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) == - (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN)) - need_crc = 0; - } - - else /* critical */ - { - if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) - need_crc = 0; - } - -#ifdef PNG_IO_STATE_SUPPORTED - png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_CRC; -#endif - - /* The chunk CRC must be serialized in a single I/O call. */ - png_read_data(png_ptr, crc_bytes, 4); - - if (need_crc) - { - crc = png_get_uint_32(crc_bytes); - return ((int)(crc != png_ptr->crc)); - } - - else - return (0); -} - -#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED -static png_size_t -png_inflate(png_structp png_ptr, png_bytep data, png_size_t size, - png_bytep output, png_size_t output_size) -{ - png_size_t count = 0; - - /* zlib can't necessarily handle more than 65535 bytes at once (i.e. it can't - * even necessarily handle 65536 bytes) because the type uInt is "16 bits or - * more". Consequently it is necessary to chunk the input to zlib. This - * code uses ZLIB_IO_MAX, from pngpriv.h, as the maximum (the maximum value - * that can be stored in a uInt.) It is possible to set ZLIB_IO_MAX to a - * lower value in pngpriv.h and this may sometimes have a performance - * advantage, because it forces access of the input data to be separated from - * at least some of the use by some period of time. - */ - png_ptr->zstream.next_in = data; - /* avail_in is set below from 'size' */ - png_ptr->zstream.avail_in = 0; - - while (1) - { - int ret, avail; - - /* The setting of 'avail_in' used to be outside the loop; by setting it - * inside it is possible to chunk the input to zlib and simply rely on - * zlib to advance the 'next_in' pointer. This allows arbitrary amounts o - * data to be passed through zlib at the unavoidable cost of requiring a - * window save (memcpy of up to 32768 output bytes) every ZLIB_IO_MAX - * input bytes. - */ - if (png_ptr->zstream.avail_in == 0 && size > 0) - { - if (size <= ZLIB_IO_MAX) - { - /* The value is less than ZLIB_IO_MAX so the cast is safe: */ - png_ptr->zstream.avail_in = (uInt)size; - size = 0; - } - - else - { - png_ptr->zstream.avail_in = ZLIB_IO_MAX; - size -= ZLIB_IO_MAX; - } - } - - /* Reset the output buffer each time round - we empty it - * after every inflate call. - */ - png_ptr->zstream.next_out = png_ptr->zbuf; - png_ptr->zstream.avail_out = png_ptr->zbuf_size; - - ret = inflate(&png_ptr->zstream, Z_NO_FLUSH); - avail = png_ptr->zbuf_size - png_ptr->zstream.avail_out; - - /* First copy/count any new output - but only if we didn't - * get an error code. - */ - if ((ret == Z_OK || ret == Z_STREAM_END) && avail > 0) - { - png_size_t space = avail; /* > 0, see above */ - - if (output != 0 && output_size > count) - { - png_size_t copy = output_size - count; - - if (space < copy) - copy = space; - - png_memcpy(output + count, png_ptr->zbuf, copy); - } - count += space; - } - - if (ret == Z_OK) - continue; - - /* Termination conditions - always reset the zstream, it - * must be left in inflateInit state. - */ - png_ptr->zstream.avail_in = 0; - inflateReset(&png_ptr->zstream); - - if (ret == Z_STREAM_END) - return count; /* NOTE: may be zero. */ - - /* Now handle the error codes - the API always returns 0 - * and the error message is dumped into the uncompressed - * buffer if available. - */ -# ifdef PNG_WARNINGS_SUPPORTED - { - png_const_charp msg; - - if (png_ptr->zstream.msg != 0) - msg = png_ptr->zstream.msg; - - else switch (ret) - { - case Z_BUF_ERROR: - msg = "Buffer error in compressed datastream"; - break; - - case Z_DATA_ERROR: - msg = "Data error in compressed datastream"; - break; - - default: - msg = "Incomplete compressed datastream"; - break; - } - - png_chunk_warning(png_ptr, msg); - } -# endif - - /* 0 means an error - notice that this code simply ignores - * zero length compressed chunks as a result. - */ - return 0; - } -} - -/* - * Decompress trailing data in a chunk. The assumption is that chunkdata - * points at an allocated area holding the contents of a chunk with a - * trailing compressed part. What we get back is an allocated area - * holding the original prefix part and an uncompressed version of the - * trailing part (the malloc area passed in is freed). - */ -void /* PRIVATE */ -png_decompress_chunk(png_structp png_ptr, int comp_type, - png_size_t chunklength, - png_size_t prefix_size, png_size_t *newlength) -{ - /* The caller should guarantee this */ - if (prefix_size > chunklength) - { - /* The recovery is to delete the chunk. */ - png_warning(png_ptr, "invalid chunklength"); - prefix_size = 0; /* To delete everything */ - } - - else if (comp_type == PNG_COMPRESSION_TYPE_BASE) - { - png_size_t expanded_size = png_inflate(png_ptr, - (png_bytep)(png_ptr->chunkdata + prefix_size), - chunklength - prefix_size, - 0, /* output */ - 0); /* output size */ - - /* Now check the limits on this chunk - if the limit fails the - * compressed data will be removed, the prefix will remain. - */ - if (prefix_size >= (~(png_size_t)0) - 1 || - expanded_size >= (~(png_size_t)0) - 1 - prefix_size -#ifdef PNG_USER_LIMITS_SUPPORTED - || (png_ptr->user_chunk_malloc_max && - (prefix_size + expanded_size >= png_ptr->user_chunk_malloc_max - 1)) -#else - || ((PNG_USER_CHUNK_MALLOC_MAX > 0) && - prefix_size + expanded_size >= PNG_USER_CHUNK_MALLOC_MAX - 1) -#endif - ) - png_warning(png_ptr, "Exceeded size limit while expanding chunk"); - - /* If the size is zero either there was an error and a message - * has already been output (warning) or the size really is zero - * and we have nothing to do - the code will exit through the - * error case below. - */ - else if (expanded_size > 0) - { - /* Success (maybe) - really uncompress the chunk. */ - png_size_t new_size = 0; - png_charp text = (png_charp)png_malloc_warn(png_ptr, - prefix_size + expanded_size + 1); - - if (text != NULL) - { - png_memcpy(text, png_ptr->chunkdata, prefix_size); - new_size = png_inflate(png_ptr, - (png_bytep)(png_ptr->chunkdata + prefix_size), - chunklength - prefix_size, - (png_bytep)(text + prefix_size), expanded_size); - text[prefix_size + expanded_size] = 0; /* just in case */ - - if (new_size == expanded_size) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = text; - *newlength = prefix_size + expanded_size; - return; /* The success return! */ - } - - png_warning(png_ptr, "png_inflate logic error"); - png_free(png_ptr, text); - } - - else - png_warning(png_ptr, "Not enough memory to decompress chunk"); - } - } - - else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */ - { - PNG_WARNING_PARAMETERS(p) - png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, comp_type); - png_formatted_warning(png_ptr, p, "Unknown compression type @1"); - - /* The recovery is to simply drop the data. */ - } - - /* Generic error return - leave the prefix, delete the compressed - * data, reallocate the chunkdata to remove the potentially large - * amount of compressed data. - */ - { - png_charp text = (png_charp)png_malloc_warn(png_ptr, prefix_size + 1); - - if (text != NULL) - { - if (prefix_size > 0) - png_memcpy(text, png_ptr->chunkdata, prefix_size); - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = text; - - /* This is an extra zero in the 'uncompressed' part. */ - *(png_ptr->chunkdata + prefix_size) = 0x00; - } - /* Ignore a malloc error here - it is safe. */ - } - - *newlength = prefix_size; -} -#endif /* PNG_READ_COMPRESSED_TEXT_SUPPORTED */ - -/* Read and check the IDHR chunk */ -void /* PRIVATE */ -png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_byte buf[13]; - png_uint_32 width, height; - int bit_depth, color_type, compression_type, filter_type; - int interlace_type; - - png_debug(1, "in png_handle_IHDR"); - - if (png_ptr->mode & PNG_HAVE_IHDR) - png_error(png_ptr, "Out of place IHDR"); - - /* Check the length */ - if (length != 13) - png_error(png_ptr, "Invalid IHDR chunk"); - - png_ptr->mode |= PNG_HAVE_IHDR; - - png_crc_read(png_ptr, buf, 13); - png_crc_finish(png_ptr, 0); - - width = png_get_uint_31(png_ptr, buf); - height = png_get_uint_31(png_ptr, buf + 4); - bit_depth = buf[8]; - color_type = buf[9]; - compression_type = buf[10]; - filter_type = buf[11]; - interlace_type = buf[12]; - - /* Set internal variables */ - png_ptr->width = width; - png_ptr->height = height; - png_ptr->bit_depth = (png_byte)bit_depth; - png_ptr->interlaced = (png_byte)interlace_type; - png_ptr->color_type = (png_byte)color_type; -#ifdef PNG_MNG_FEATURES_SUPPORTED - png_ptr->filter_type = (png_byte)filter_type; -#endif - png_ptr->compression_type = (png_byte)compression_type; - - /* Find number of channels */ - switch (png_ptr->color_type) - { - default: /* invalid, png_set_IHDR calls png_error */ - case PNG_COLOR_TYPE_GRAY: - case PNG_COLOR_TYPE_PALETTE: - png_ptr->channels = 1; - break; - - case PNG_COLOR_TYPE_RGB: - png_ptr->channels = 3; - break; - - case PNG_COLOR_TYPE_GRAY_ALPHA: - png_ptr->channels = 2; - break; - - case PNG_COLOR_TYPE_RGB_ALPHA: - png_ptr->channels = 4; - break; - } - - /* Set up other useful info */ - png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * - png_ptr->channels); - png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width); - png_debug1(3, "bit_depth = %d", png_ptr->bit_depth); - png_debug1(3, "channels = %d", png_ptr->channels); - png_debug1(3, "rowbytes = %lu", (unsigned long)png_ptr->rowbytes); - png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, - color_type, interlace_type, compression_type, filter_type); -} - -/* Read and check the palette */ -void /* PRIVATE */ -png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_color palette[PNG_MAX_PALETTE_LENGTH]; - int num, i; -#ifdef PNG_POINTER_INDEXING_SUPPORTED - png_colorp pal_ptr; -#endif - - png_debug(1, "in png_handle_PLTE"); - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before PLTE"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) - { - png_warning(png_ptr, "Invalid PLTE after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (png_ptr->mode & PNG_HAVE_PLTE) - png_error(png_ptr, "Duplicate PLTE chunk"); - - png_ptr->mode |= PNG_HAVE_PLTE; - - if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) - { - png_warning(png_ptr, - "Ignoring PLTE chunk in grayscale PNG"); - png_crc_finish(png_ptr, length); - return; - } - -#ifndef PNG_READ_OPT_PLTE_SUPPORTED - if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) - { - png_crc_finish(png_ptr, length); - return; - } -#endif - - if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3) - { - if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) - { - png_warning(png_ptr, "Invalid palette chunk"); - png_crc_finish(png_ptr, length); - return; - } - - else - { - png_error(png_ptr, "Invalid palette chunk"); - } - } - - num = (int)length / 3; - -#ifdef PNG_POINTER_INDEXING_SUPPORTED - for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++) - { - png_byte buf[3]; - - png_crc_read(png_ptr, buf, 3); - pal_ptr->red = buf[0]; - pal_ptr->green = buf[1]; - pal_ptr->blue = buf[2]; - } -#else - for (i = 0; i < num; i++) - { - png_byte buf[3]; - - png_crc_read(png_ptr, buf, 3); - /* Don't depend upon png_color being any order */ - palette[i].red = buf[0]; - palette[i].green = buf[1]; - palette[i].blue = buf[2]; - } -#endif - - /* If we actually need the PLTE chunk (ie for a paletted image), we do - * whatever the normal CRC configuration tells us. However, if we - * have an RGB image, the PLTE can be considered ancillary, so - * we will act as though it is. - */ -#ifndef PNG_READ_OPT_PLTE_SUPPORTED - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) -#endif - { - png_crc_finish(png_ptr, 0); - } - -#ifndef PNG_READ_OPT_PLTE_SUPPORTED - else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */ - { - /* If we don't want to use the data from an ancillary chunk, - * we have two options: an error abort, or a warning and we - * ignore the data in this chunk (which should be OK, since - * it's considered ancillary for a RGB or RGBA image). - */ - if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE)) - { - if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) - { - png_chunk_benign_error(png_ptr, "CRC error"); - } - - else - { - png_chunk_warning(png_ptr, "CRC error"); - return; - } - } - - /* Otherwise, we (optionally) emit a warning and use the chunk. */ - else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) - { - png_chunk_warning(png_ptr, "CRC error"); - } - } -#endif - - png_set_PLTE(png_ptr, info_ptr, palette, num); - -#ifdef PNG_READ_tRNS_SUPPORTED - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - { - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) - { - if (png_ptr->num_trans > (png_uint_16)num) - { - png_warning(png_ptr, "Truncating incorrect tRNS chunk length"); - png_ptr->num_trans = (png_uint_16)num; - } - - if (info_ptr->num_trans > (png_uint_16)num) - { - png_warning(png_ptr, "Truncating incorrect info tRNS chunk length"); - info_ptr->num_trans = (png_uint_16)num; - } - } - } -#endif - -} - -void /* PRIVATE */ -png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_debug(1, "in png_handle_IEND"); - - if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT)) - { - png_error(png_ptr, "No image in file"); - } - - png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND); - - if (length != 0) - { - png_warning(png_ptr, "Incorrect IEND chunk length"); - } - - png_crc_finish(png_ptr, length); - - PNG_UNUSED(info_ptr) /* Quiet compiler warnings about unused info_ptr */ -} - -#ifdef PNG_READ_gAMA_SUPPORTED -void /* PRIVATE */ -png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_fixed_point igamma; - png_byte buf[4]; - - png_debug(1, "in png_handle_gAMA"); - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before gAMA"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) - { - png_warning(png_ptr, "Invalid gAMA after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (png_ptr->mode & PNG_HAVE_PLTE) - /* Should be an error, but we can cope with it */ - png_warning(png_ptr, "Out of place gAMA chunk"); - - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) -#ifdef PNG_READ_sRGB_SUPPORTED - && !(info_ptr->valid & PNG_INFO_sRGB) -#endif - ) - { - png_warning(png_ptr, "Duplicate gAMA chunk"); - png_crc_finish(png_ptr, length); - return; - } - - if (length != 4) - { - png_warning(png_ptr, "Incorrect gAMA chunk length"); - png_crc_finish(png_ptr, length); - return; - } - - png_crc_read(png_ptr, buf, 4); - - if (png_crc_finish(png_ptr, 0)) - return; - - igamma = png_get_fixed_point(NULL, buf); - - /* Check for zero gamma or an error. */ - if (igamma <= 0) - { - png_warning(png_ptr, - "Ignoring gAMA chunk with out of range gamma"); - - return; - } - -# ifdef PNG_READ_sRGB_SUPPORTED - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) - { - if (PNG_OUT_OF_RANGE(igamma, 45500, 500)) - { - PNG_WARNING_PARAMETERS(p) - png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed, igamma); - png_formatted_warning(png_ptr, p, - "Ignoring incorrect gAMA value @1 when sRGB is also present"); - return; - } - } -# endif /* PNG_READ_sRGB_SUPPORTED */ - -# ifdef PNG_READ_GAMMA_SUPPORTED - /* Gamma correction on read is supported. */ - png_ptr->gamma = igamma; -# endif - /* And set the 'info' structure members. */ - png_set_gAMA_fixed(png_ptr, info_ptr, igamma); -} -#endif - -#ifdef PNG_READ_sBIT_SUPPORTED -void /* PRIVATE */ -png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_size_t truelen; - png_byte buf[4]; - - png_debug(1, "in png_handle_sBIT"); - - buf[0] = buf[1] = buf[2] = buf[3] = 0; - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before sBIT"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) - { - png_warning(png_ptr, "Invalid sBIT after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (png_ptr->mode & PNG_HAVE_PLTE) - { - /* Should be an error, but we can cope with it */ - png_warning(png_ptr, "Out of place sBIT chunk"); - } - - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)) - { - png_warning(png_ptr, "Duplicate sBIT chunk"); - png_crc_finish(png_ptr, length); - return; - } - - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - truelen = 3; - - else - truelen = (png_size_t)png_ptr->channels; - - if (length != truelen || length > 4) - { - png_warning(png_ptr, "Incorrect sBIT chunk length"); - png_crc_finish(png_ptr, length); - return; - } - - png_crc_read(png_ptr, buf, truelen); - - if (png_crc_finish(png_ptr, 0)) - return; - - if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) - { - png_ptr->sig_bit.red = buf[0]; - png_ptr->sig_bit.green = buf[1]; - png_ptr->sig_bit.blue = buf[2]; - png_ptr->sig_bit.alpha = buf[3]; - } - - else - { - png_ptr->sig_bit.gray = buf[0]; - png_ptr->sig_bit.red = buf[0]; - png_ptr->sig_bit.green = buf[0]; - png_ptr->sig_bit.blue = buf[0]; - png_ptr->sig_bit.alpha = buf[1]; - } - - png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit)); -} -#endif - -#ifdef PNG_READ_cHRM_SUPPORTED -void /* PRIVATE */ -png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_byte buf[32]; - png_fixed_point x_white, y_white, x_red, y_red, x_green, y_green, x_blue, - y_blue; - - png_debug(1, "in png_handle_cHRM"); - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before cHRM"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) - { - png_warning(png_ptr, "Invalid cHRM after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (png_ptr->mode & PNG_HAVE_PLTE) - /* Should be an error, but we can cope with it */ - png_warning(png_ptr, "Out of place cHRM chunk"); - - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM) -# ifdef PNG_READ_sRGB_SUPPORTED - && !(info_ptr->valid & PNG_INFO_sRGB) -# endif - ) - { - png_warning(png_ptr, "Duplicate cHRM chunk"); - png_crc_finish(png_ptr, length); - return; - } - - if (length != 32) - { - png_warning(png_ptr, "Incorrect cHRM chunk length"); - png_crc_finish(png_ptr, length); - return; - } - - png_crc_read(png_ptr, buf, 32); - - if (png_crc_finish(png_ptr, 0)) - return; - - x_white = png_get_fixed_point(NULL, buf); - y_white = png_get_fixed_point(NULL, buf + 4); - x_red = png_get_fixed_point(NULL, buf + 8); - y_red = png_get_fixed_point(NULL, buf + 12); - x_green = png_get_fixed_point(NULL, buf + 16); - y_green = png_get_fixed_point(NULL, buf + 20); - x_blue = png_get_fixed_point(NULL, buf + 24); - y_blue = png_get_fixed_point(NULL, buf + 28); - - if (x_white == PNG_FIXED_ERROR || - y_white == PNG_FIXED_ERROR || - x_red == PNG_FIXED_ERROR || - y_red == PNG_FIXED_ERROR || - x_green == PNG_FIXED_ERROR || - y_green == PNG_FIXED_ERROR || - x_blue == PNG_FIXED_ERROR || - y_blue == PNG_FIXED_ERROR) - { - png_warning(png_ptr, "Ignoring cHRM chunk with negative chromaticities"); - return; - } - -#ifdef PNG_READ_sRGB_SUPPORTED - if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB)) - { - if (PNG_OUT_OF_RANGE(x_white, 31270, 1000) || - PNG_OUT_OF_RANGE(y_white, 32900, 1000) || - PNG_OUT_OF_RANGE(x_red, 64000, 1000) || - PNG_OUT_OF_RANGE(y_red, 33000, 1000) || - PNG_OUT_OF_RANGE(x_green, 30000, 1000) || - PNG_OUT_OF_RANGE(y_green, 60000, 1000) || - PNG_OUT_OF_RANGE(x_blue, 15000, 1000) || - PNG_OUT_OF_RANGE(y_blue, 6000, 1000)) - { - PNG_WARNING_PARAMETERS(p) - - png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed, x_white); - png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_fixed, y_white); - png_warning_parameter_signed(p, 3, PNG_NUMBER_FORMAT_fixed, x_red); - png_warning_parameter_signed(p, 4, PNG_NUMBER_FORMAT_fixed, y_red); - png_warning_parameter_signed(p, 5, PNG_NUMBER_FORMAT_fixed, x_green); - png_warning_parameter_signed(p, 6, PNG_NUMBER_FORMAT_fixed, y_green); - png_warning_parameter_signed(p, 7, PNG_NUMBER_FORMAT_fixed, x_blue); - png_warning_parameter_signed(p, 8, PNG_NUMBER_FORMAT_fixed, y_blue); - - png_formatted_warning(png_ptr, p, - "Ignoring incorrect cHRM white(@1,@2) r(@3,@4)g(@5,@6)b(@7,@8) " - "when sRGB is also present"); - } - return; - } -#endif /* PNG_READ_sRGB_SUPPORTED */ - -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED - /* Store the _white values as default coefficients for the rgb to gray - * operation if it is supported. Check if the transform is already set to - * avoid destroying the transform values. - */ - if (!png_ptr->rgb_to_gray_coefficients_set) - { - /* png_set_background has not been called and we haven't seen an sRGB - * chunk yet. Find the XYZ of the three end points. - */ - png_XYZ XYZ; - png_xy xy; - - xy.redx = x_red; - xy.redy = y_red; - xy.greenx = x_green; - xy.greeny = y_green; - xy.bluex = x_blue; - xy.bluey = y_blue; - xy.whitex = x_white; - xy.whitey = y_white; - - if (png_XYZ_from_xy_checked(png_ptr, &XYZ, xy)) - { - /* The success case, because XYZ_from_xy normalises to a reference - * white Y of 1.0 we just need to scale the numbers. This should - * always work just fine. It is an internal error if this overflows. - */ - { - png_fixed_point r, g, b; - if (png_muldiv(&r, XYZ.redY, 32768, PNG_FP_1) && - r >= 0 && r <= 32768 && - png_muldiv(&g, XYZ.greenY, 32768, PNG_FP_1) && - g >= 0 && g <= 32768 && - png_muldiv(&b, XYZ.blueY, 32768, PNG_FP_1) && - b >= 0 && b <= 32768 && - r+g+b <= 32769) - { - /* We allow 0 coefficients here. r+g+b may be 32769 if two or - * all of the coefficients were rounded up. Handle this by - * reducing the *largest* coefficient by 1; this matches the - * approach used for the default coefficients in pngrtran.c - */ - int add = 0; - - if (r+g+b > 32768) - add = -1; - else if (r+g+b < 32768) - add = 1; - - if (add != 0) - { - if (g >= r && g >= b) - g += add; - else if (r >= g && r >= b) - r += add; - else - b += add; - } - - /* Check for an internal error. */ - if (r+g+b != 32768) - png_error(png_ptr, - "internal error handling cHRM coefficients"); - - png_ptr->rgb_to_gray_red_coeff = (png_uint_16)r; - png_ptr->rgb_to_gray_green_coeff = (png_uint_16)g; - } - - /* This is a png_error at present even though it could be ignored - - * it should never happen, but it is important that if it does, the - * bug is fixed. - */ - else - png_error(png_ptr, "internal error handling cHRM->XYZ"); - } - } - } -#endif - - png_set_cHRM_fixed(png_ptr, info_ptr, x_white, y_white, x_red, y_red, - x_green, y_green, x_blue, y_blue); -} -#endif - -#ifdef PNG_READ_sRGB_SUPPORTED -void /* PRIVATE */ -png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - int intent; - png_byte buf[1]; - - png_debug(1, "in png_handle_sRGB"); - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before sRGB"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) - { - png_warning(png_ptr, "Invalid sRGB after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (png_ptr->mode & PNG_HAVE_PLTE) - /* Should be an error, but we can cope with it */ - png_warning(png_ptr, "Out of place sRGB chunk"); - - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) - { - png_warning(png_ptr, "Duplicate sRGB chunk"); - png_crc_finish(png_ptr, length); - return; - } - - if (length != 1) - { - png_warning(png_ptr, "Incorrect sRGB chunk length"); - png_crc_finish(png_ptr, length); - return; - } - - png_crc_read(png_ptr, buf, 1); - - if (png_crc_finish(png_ptr, 0)) - return; - - intent = buf[0]; - - /* Check for bad intent */ - if (intent >= PNG_sRGB_INTENT_LAST) - { - png_warning(png_ptr, "Unknown sRGB intent"); - return; - } - -#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)) - { - if (PNG_OUT_OF_RANGE(info_ptr->gamma, 45500, 500)) - { - PNG_WARNING_PARAMETERS(p) - - png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed, - info_ptr->gamma); - - png_formatted_warning(png_ptr, p, - "Ignoring incorrect gAMA value @1 when sRGB is also present"); - } - } -#endif /* PNG_READ_gAMA_SUPPORTED */ - -#ifdef PNG_READ_cHRM_SUPPORTED - if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) - if (PNG_OUT_OF_RANGE(info_ptr->x_white, 31270, 1000) || - PNG_OUT_OF_RANGE(info_ptr->y_white, 32900, 1000) || - PNG_OUT_OF_RANGE(info_ptr->x_red, 64000, 1000) || - PNG_OUT_OF_RANGE(info_ptr->y_red, 33000, 1000) || - PNG_OUT_OF_RANGE(info_ptr->x_green, 30000, 1000) || - PNG_OUT_OF_RANGE(info_ptr->y_green, 60000, 1000) || - PNG_OUT_OF_RANGE(info_ptr->x_blue, 15000, 1000) || - PNG_OUT_OF_RANGE(info_ptr->y_blue, 6000, 1000)) - { - png_warning(png_ptr, - "Ignoring incorrect cHRM value when sRGB is also present"); - } -#endif /* PNG_READ_cHRM_SUPPORTED */ - - /* This is recorded for use when handling the cHRM chunk above. An sRGB - * chunk unconditionally overwrites the coefficients for grayscale conversion - * too. - */ - png_ptr->is_sRGB = 1; - -# ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED - /* Don't overwrite user supplied values: */ - if (!png_ptr->rgb_to_gray_coefficients_set) - { - /* These numbers come from the sRGB specification (or, since one has to - * pay much money to get a copy, the wikipedia sRGB page) the - * chromaticity values quoted have been inverted to get the reverse - * transformation from RGB to XYZ and the 'Y' coefficients scaled by - * 32768 (then rounded). - * - * sRGB and ITU Rec-709 both truncate the values for the D65 white - * point to four digits and, even though it actually stores five - * digits, the PNG spec gives the truncated value. - * - * This means that when the chromaticities are converted back to XYZ - * end points we end up with (6968,23435,2366), which, as described in - * pngrtran.c, would overflow. If the five digit precision and up is - * used we get, instead: - * - * 6968*R + 23435*G + 2365*B - * - * (Notice that this rounds the blue coefficient down, rather than the - * choice used in pngrtran.c which is to round the green one down.) - */ - png_ptr->rgb_to_gray_red_coeff = 6968; /* 0.212639005871510 */ - png_ptr->rgb_to_gray_green_coeff = 23434; /* 0.715168678767756 */ - /* png_ptr->rgb_to_gray_blue_coeff = 2366; 0.072192315360734 */ - - /* The following keeps the cHRM chunk from destroying the - * coefficients again in the event that it follows the sRGB chunk. - */ - png_ptr->rgb_to_gray_coefficients_set = 1; - } -# endif - - png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent); -} -#endif /* PNG_READ_sRGB_SUPPORTED */ - -#ifdef PNG_READ_iCCP_SUPPORTED -void /* PRIVATE */ -png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -/* Note: this does not properly handle chunks that are > 64K under DOS */ -{ - png_byte compression_type; - png_bytep pC; - png_charp profile; - png_uint_32 skip = 0; - png_uint_32 profile_size; - png_alloc_size_t profile_length; - png_size_t slength, prefix_length, data_length; - - png_debug(1, "in png_handle_iCCP"); - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before iCCP"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) - { - png_warning(png_ptr, "Invalid iCCP after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (png_ptr->mode & PNG_HAVE_PLTE) - /* Should be an error, but we can cope with it */ - png_warning(png_ptr, "Out of place iCCP chunk"); - - if ((png_ptr->mode & PNG_HAVE_iCCP) || (info_ptr != NULL && - (info_ptr->valid & (PNG_INFO_iCCP|PNG_INFO_sRGB)))) - { - png_warning(png_ptr, "Duplicate iCCP chunk"); - png_crc_finish(png_ptr, length); - return; - } - - png_ptr->mode |= PNG_HAVE_iCCP; - -#ifdef PNG_MAX_MALLOC_64K - if (length > (png_uint_32)65535L) - { - png_warning(png_ptr, "iCCP chunk too large to fit in memory"); - skip = length - (png_uint_32)65535L; - length = (png_uint_32)65535L; - } -#endif - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1); - slength = length; - png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); - - if (png_crc_finish(png_ptr, skip)) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - png_ptr->chunkdata[slength] = 0x00; - - for (profile = png_ptr->chunkdata; *profile; profile++) - /* Empty loop to find end of name */ ; - - ++profile; - - /* There should be at least one zero (the compression type byte) - * following the separator, and we should be on it - */ - if (profile >= png_ptr->chunkdata + slength - 1) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - png_warning(png_ptr, "Malformed iCCP chunk"); - return; - } - - /* Compression_type should always be zero */ - compression_type = *profile++; - - if (compression_type) - { - png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk"); - compression_type = 0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8 - wrote nonzero) */ - } - - prefix_length = profile - png_ptr->chunkdata; - png_decompress_chunk(png_ptr, compression_type, - slength, prefix_length, &data_length); - - profile_length = data_length - prefix_length; - - if (prefix_length > data_length || profile_length < 4) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - png_warning(png_ptr, "Profile size field missing from iCCP chunk"); - return; - } - - /* Check the profile_size recorded in the first 32 bits of the ICC profile */ - pC = (png_bytep)(png_ptr->chunkdata + prefix_length); - profile_size = ((*(pC )) << 24) | - ((*(pC + 1)) << 16) | - ((*(pC + 2)) << 8) | - ((*(pC + 3)) ); - - /* NOTE: the following guarantees that 'profile_length' fits into 32 bits, - * because profile_size is a 32 bit value. - */ - if (profile_size < profile_length) - profile_length = profile_size; - - /* And the following guarantees that profile_size == profile_length. */ - if (profile_size > profile_length) - { - PNG_WARNING_PARAMETERS(p) - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - - png_warning_parameter_unsigned(p, 1, PNG_NUMBER_FORMAT_u, profile_size); - png_warning_parameter_unsigned(p, 2, PNG_NUMBER_FORMAT_u, profile_length); - png_formatted_warning(png_ptr, p, - "Ignoring iCCP chunk with declared size = @1 and actual length = @2"); - return; - } - - png_set_iCCP(png_ptr, info_ptr, png_ptr->chunkdata, - compression_type, (png_bytep)png_ptr->chunkdata + prefix_length, - profile_size); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; -} -#endif /* PNG_READ_iCCP_SUPPORTED */ - -#ifdef PNG_READ_sPLT_SUPPORTED -void /* PRIVATE */ -png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -/* Note: this does not properly handle chunks that are > 64K under DOS */ -{ - png_bytep entry_start; - png_sPLT_t new_palette; - png_sPLT_entryp pp; - png_uint_32 data_length; - int entry_size, i; - png_uint_32 skip = 0; - png_size_t slength; - png_uint_32 dl; - png_size_t max_dl; - - png_debug(1, "in png_handle_sPLT"); - -#ifdef PNG_USER_LIMITS_SUPPORTED - - if (png_ptr->user_chunk_cache_max != 0) - { - if (png_ptr->user_chunk_cache_max == 1) - { - png_crc_finish(png_ptr, length); - return; - } - - if (--png_ptr->user_chunk_cache_max == 1) - { - png_warning(png_ptr, "No space in chunk cache for sPLT"); - png_crc_finish(png_ptr, length); - return; - } - } -#endif - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before sPLT"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) - { - png_warning(png_ptr, "Invalid sPLT after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - -#ifdef PNG_MAX_MALLOC_64K - if (length > (png_uint_32)65535L) - { - png_warning(png_ptr, "sPLT chunk too large to fit in memory"); - skip = length - (png_uint_32)65535L; - length = (png_uint_32)65535L; - } -#endif - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1); - - /* WARNING: this may break if size_t is less than 32 bits; it is assumed - * that the PNG_MAX_MALLOC_64K test is enabled in this case, but this is a - * potential breakage point if the types in pngconf.h aren't exactly right. - */ - slength = length; - png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); - - if (png_crc_finish(png_ptr, skip)) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - png_ptr->chunkdata[slength] = 0x00; - - for (entry_start = (png_bytep)png_ptr->chunkdata; *entry_start; - entry_start++) - /* Empty loop to find end of name */ ; - - ++entry_start; - - /* A sample depth should follow the separator, and we should be on it */ - if (entry_start > (png_bytep)png_ptr->chunkdata + slength - 2) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - png_warning(png_ptr, "malformed sPLT chunk"); - return; - } - - new_palette.depth = *entry_start++; - entry_size = (new_palette.depth == 8 ? 6 : 10); - /* This must fit in a png_uint_32 because it is derived from the original - * chunk data length (and use 'length', not 'slength' here for clarity - - * they are guaranteed to be the same, see the tests above.) - */ - data_length = length - (png_uint_32)(entry_start - - (png_bytep)png_ptr->chunkdata); - - /* Integrity-check the data length */ - if (data_length % entry_size) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - png_warning(png_ptr, "sPLT chunk has bad length"); - return; - } - - dl = (png_int_32)(data_length / entry_size); - max_dl = PNG_SIZE_MAX / png_sizeof(png_sPLT_entry); - - if (dl > max_dl) - { - png_warning(png_ptr, "sPLT chunk too long"); - return; - } - - new_palette.nentries = (png_int_32)(data_length / entry_size); - - new_palette.entries = (png_sPLT_entryp)png_malloc_warn( - png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry)); - - if (new_palette.entries == NULL) - { - png_warning(png_ptr, "sPLT chunk requires too much memory"); - return; - } - -#ifdef PNG_POINTER_INDEXING_SUPPORTED - for (i = 0; i < new_palette.nentries; i++) - { - pp = new_palette.entries + i; - - if (new_palette.depth == 8) - { - pp->red = *entry_start++; - pp->green = *entry_start++; - pp->blue = *entry_start++; - pp->alpha = *entry_start++; - } - - else - { - pp->red = png_get_uint_16(entry_start); entry_start += 2; - pp->green = png_get_uint_16(entry_start); entry_start += 2; - pp->blue = png_get_uint_16(entry_start); entry_start += 2; - pp->alpha = png_get_uint_16(entry_start); entry_start += 2; - } - - pp->frequency = png_get_uint_16(entry_start); entry_start += 2; - } -#else - pp = new_palette.entries; - - for (i = 0; i < new_palette.nentries; i++) - { - - if (new_palette.depth == 8) - { - pp[i].red = *entry_start++; - pp[i].green = *entry_start++; - pp[i].blue = *entry_start++; - pp[i].alpha = *entry_start++; - } - - else - { - pp[i].red = png_get_uint_16(entry_start); entry_start += 2; - pp[i].green = png_get_uint_16(entry_start); entry_start += 2; - pp[i].blue = png_get_uint_16(entry_start); entry_start += 2; - pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2; - } - - pp[i].frequency = png_get_uint_16(entry_start); entry_start += 2; - } -#endif - - /* Discard all chunk data except the name and stash that */ - new_palette.name = png_ptr->chunkdata; - - png_set_sPLT(png_ptr, info_ptr, &new_palette, 1); - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - png_free(png_ptr, new_palette.entries); -} -#endif /* PNG_READ_sPLT_SUPPORTED */ - -#ifdef PNG_READ_tRNS_SUPPORTED -void /* PRIVATE */ -png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_byte readbuf[PNG_MAX_PALETTE_LENGTH]; - - png_debug(1, "in png_handle_tRNS"); - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before tRNS"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) - { - png_warning(png_ptr, "Invalid tRNS after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) - { - png_warning(png_ptr, "Duplicate tRNS chunk"); - png_crc_finish(png_ptr, length); - return; - } - - if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) - { - png_byte buf[2]; - - if (length != 2) - { - png_warning(png_ptr, "Incorrect tRNS chunk length"); - png_crc_finish(png_ptr, length); - return; - } - - png_crc_read(png_ptr, buf, 2); - png_ptr->num_trans = 1; - png_ptr->trans_color.gray = png_get_uint_16(buf); - } - - else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) - { - png_byte buf[6]; - - if (length != 6) - { - png_warning(png_ptr, "Incorrect tRNS chunk length"); - png_crc_finish(png_ptr, length); - return; - } - - png_crc_read(png_ptr, buf, (png_size_t)length); - png_ptr->num_trans = 1; - png_ptr->trans_color.red = png_get_uint_16(buf); - png_ptr->trans_color.green = png_get_uint_16(buf + 2); - png_ptr->trans_color.blue = png_get_uint_16(buf + 4); - } - - else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - { - if (!(png_ptr->mode & PNG_HAVE_PLTE)) - { - /* Should be an error, but we can cope with it. */ - png_warning(png_ptr, "Missing PLTE before tRNS"); - } - - if (length > (png_uint_32)png_ptr->num_palette || - length > PNG_MAX_PALETTE_LENGTH) - { - png_warning(png_ptr, "Incorrect tRNS chunk length"); - png_crc_finish(png_ptr, length); - return; - } - - if (length == 0) - { - png_warning(png_ptr, "Zero length tRNS chunk"); - png_crc_finish(png_ptr, length); - return; - } - - png_crc_read(png_ptr, readbuf, (png_size_t)length); - png_ptr->num_trans = (png_uint_16)length; - } - - else - { - png_warning(png_ptr, "tRNS chunk not allowed with alpha channel"); - png_crc_finish(png_ptr, length); - return; - } - - if (png_crc_finish(png_ptr, 0)) - { - png_ptr->num_trans = 0; - return; - } - - png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans, - &(png_ptr->trans_color)); -} -#endif - -#ifdef PNG_READ_bKGD_SUPPORTED -void /* PRIVATE */ -png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_size_t truelen; - png_byte buf[6]; - png_color_16 background; - - png_debug(1, "in png_handle_bKGD"); - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before bKGD"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) - { - png_warning(png_ptr, "Invalid bKGD after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && - !(png_ptr->mode & PNG_HAVE_PLTE)) - { - png_warning(png_ptr, "Missing PLTE before bKGD"); - png_crc_finish(png_ptr, length); - return; - } - - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)) - { - png_warning(png_ptr, "Duplicate bKGD chunk"); - png_crc_finish(png_ptr, length); - return; - } - - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - truelen = 1; - - else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) - truelen = 6; - - else - truelen = 2; - - if (length != truelen) - { - png_warning(png_ptr, "Incorrect bKGD chunk length"); - png_crc_finish(png_ptr, length); - return; - } - - png_crc_read(png_ptr, buf, truelen); - - if (png_crc_finish(png_ptr, 0)) - return; - - /* We convert the index value into RGB components so that we can allow - * arbitrary RGB values for background when we have transparency, and - * so it is easy to determine the RGB values of the background color - * from the info_ptr struct. - */ - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - { - background.index = buf[0]; - - if (info_ptr && info_ptr->num_palette) - { - if (buf[0] >= info_ptr->num_palette) - { - png_warning(png_ptr, "Incorrect bKGD chunk index value"); - return; - } - - background.red = (png_uint_16)png_ptr->palette[buf[0]].red; - background.green = (png_uint_16)png_ptr->palette[buf[0]].green; - background.blue = (png_uint_16)png_ptr->palette[buf[0]].blue; - } - - else - background.red = background.green = background.blue = 0; - - background.gray = 0; - } - - else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */ - { - background.index = 0; - background.red = - background.green = - background.blue = - background.gray = png_get_uint_16(buf); - } - - else - { - background.index = 0; - background.red = png_get_uint_16(buf); - background.green = png_get_uint_16(buf + 2); - background.blue = png_get_uint_16(buf + 4); - background.gray = 0; - } - - png_set_bKGD(png_ptr, info_ptr, &background); -} -#endif - -#ifdef PNG_READ_hIST_SUPPORTED -void /* PRIVATE */ -png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - unsigned int num, i; - png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH]; - - png_debug(1, "in png_handle_hIST"); - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before hIST"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) - { - png_warning(png_ptr, "Invalid hIST after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (!(png_ptr->mode & PNG_HAVE_PLTE)) - { - png_warning(png_ptr, "Missing PLTE before hIST"); - png_crc_finish(png_ptr, length); - return; - } - - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)) - { - png_warning(png_ptr, "Duplicate hIST chunk"); - png_crc_finish(png_ptr, length); - return; - } - - if (length > 2*PNG_MAX_PALETTE_LENGTH || - length != (unsigned int) (2*png_ptr->num_palette)) - { - png_warning(png_ptr, "Incorrect hIST chunk length"); - png_crc_finish(png_ptr, length); - return; - } - - num = length / 2 ; - - for (i = 0; i < num; i++) - { - png_byte buf[2]; - - png_crc_read(png_ptr, buf, 2); - readbuf[i] = png_get_uint_16(buf); - } - - if (png_crc_finish(png_ptr, 0)) - return; - - png_set_hIST(png_ptr, info_ptr, readbuf); -} -#endif - -#ifdef PNG_READ_pHYs_SUPPORTED -void /* PRIVATE */ -png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_byte buf[9]; - png_uint_32 res_x, res_y; - int unit_type; - - png_debug(1, "in png_handle_pHYs"); - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before pHYs"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) - { - png_warning(png_ptr, "Invalid pHYs after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) - { - png_warning(png_ptr, "Duplicate pHYs chunk"); - png_crc_finish(png_ptr, length); - return; - } - - if (length != 9) - { - png_warning(png_ptr, "Incorrect pHYs chunk length"); - png_crc_finish(png_ptr, length); - return; - } - - png_crc_read(png_ptr, buf, 9); - - if (png_crc_finish(png_ptr, 0)) - return; - - res_x = png_get_uint_32(buf); - res_y = png_get_uint_32(buf + 4); - unit_type = buf[8]; - png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type); -} -#endif - -#ifdef PNG_READ_oFFs_SUPPORTED -void /* PRIVATE */ -png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_byte buf[9]; - png_int_32 offset_x, offset_y; - int unit_type; - - png_debug(1, "in png_handle_oFFs"); - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before oFFs"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) - { - png_warning(png_ptr, "Invalid oFFs after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) - { - png_warning(png_ptr, "Duplicate oFFs chunk"); - png_crc_finish(png_ptr, length); - return; - } - - if (length != 9) - { - png_warning(png_ptr, "Incorrect oFFs chunk length"); - png_crc_finish(png_ptr, length); - return; - } - - png_crc_read(png_ptr, buf, 9); - - if (png_crc_finish(png_ptr, 0)) - return; - - offset_x = png_get_int_32(buf); - offset_y = png_get_int_32(buf + 4); - unit_type = buf[8]; - png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type); -} -#endif - -#ifdef PNG_READ_pCAL_SUPPORTED -/* Read the pCAL chunk (described in the PNG Extensions document) */ -void /* PRIVATE */ -png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_int_32 X0, X1; - png_byte type, nparams; - png_charp buf, units, endptr; - png_charpp params; - png_size_t slength; - int i; - - png_debug(1, "in png_handle_pCAL"); - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before pCAL"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) - { - png_warning(png_ptr, "Invalid pCAL after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)) - { - png_warning(png_ptr, "Duplicate pCAL chunk"); - png_crc_finish(png_ptr, length); - return; - } - - png_debug1(2, "Allocating and reading pCAL chunk data (%u bytes)", - length + 1); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); - - if (png_ptr->chunkdata == NULL) - { - png_warning(png_ptr, "No memory for pCAL purpose"); - return; - } - - slength = length; - png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); - - if (png_crc_finish(png_ptr, 0)) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */ - - png_debug(3, "Finding end of pCAL purpose string"); - for (buf = png_ptr->chunkdata; *buf; buf++) - /* Empty loop */ ; - - endptr = png_ptr->chunkdata + slength; - - /* We need to have at least 12 bytes after the purpose string - * in order to get the parameter information. - */ - if (endptr <= buf + 12) - { - png_warning(png_ptr, "Invalid pCAL data"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - png_debug(3, "Reading pCAL X0, X1, type, nparams, and units"); - X0 = png_get_int_32((png_bytep)buf+1); - X1 = png_get_int_32((png_bytep)buf+5); - type = buf[9]; - nparams = buf[10]; - units = buf + 11; - - png_debug(3, "Checking pCAL equation type and number of parameters"); - /* Check that we have the right number of parameters for known - * equation types. - */ - if ((type == PNG_EQUATION_LINEAR && nparams != 2) || - (type == PNG_EQUATION_BASE_E && nparams != 3) || - (type == PNG_EQUATION_ARBITRARY && nparams != 3) || - (type == PNG_EQUATION_HYPERBOLIC && nparams != 4)) - { - png_warning(png_ptr, "Invalid pCAL parameters for equation type"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - else if (type >= PNG_EQUATION_LAST) - { - png_warning(png_ptr, "Unrecognized equation type for pCAL chunk"); - } - - for (buf = units; *buf; buf++) - /* Empty loop to move past the units string. */ ; - - png_debug(3, "Allocating pCAL parameters array"); - - params = (png_charpp)png_malloc_warn(png_ptr, - (png_size_t)(nparams * png_sizeof(png_charp))); - - if (params == NULL) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - png_warning(png_ptr, "No memory for pCAL params"); - return; - } - - /* Get pointers to the start of each parameter string. */ - for (i = 0; i < (int)nparams; i++) - { - buf++; /* Skip the null string terminator from previous parameter. */ - - png_debug1(3, "Reading pCAL parameter %d", i); - - for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++) - /* Empty loop to move past each parameter string */ ; - - /* Make sure we haven't run out of data yet */ - if (buf > endptr) - { - png_warning(png_ptr, "Invalid pCAL data"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - png_free(png_ptr, params); - return; - } - } - - png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams, - units, params); - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - png_free(png_ptr, params); -} -#endif - -#ifdef PNG_READ_sCAL_SUPPORTED -/* Read the sCAL chunk */ -void /* PRIVATE */ -png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_size_t slength, i; - int state; - - png_debug(1, "in png_handle_sCAL"); - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before sCAL"); - - else if (png_ptr->mode & PNG_HAVE_IDAT) - { - png_warning(png_ptr, "Invalid sCAL after IDAT"); - png_crc_finish(png_ptr, length); - return; - } - - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL)) - { - png_warning(png_ptr, "Duplicate sCAL chunk"); - png_crc_finish(png_ptr, length); - return; - } - - /* Need unit type, width, \0, height: minimum 4 bytes */ - else if (length < 4) - { - png_warning(png_ptr, "sCAL chunk too short"); - png_crc_finish(png_ptr, length); - return; - } - - png_debug1(2, "Allocating and reading sCAL chunk data (%u bytes)", - length + 1); - - png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); - - if (png_ptr->chunkdata == NULL) - { - png_warning(png_ptr, "Out of memory while processing sCAL chunk"); - png_crc_finish(png_ptr, length); - return; - } - - slength = length; - png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); - png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */ - - if (png_crc_finish(png_ptr, 0)) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - /* Validate the unit. */ - if (png_ptr->chunkdata[0] != 1 && png_ptr->chunkdata[0] != 2) - { - png_warning(png_ptr, "Invalid sCAL ignored: invalid unit"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - /* Validate the ASCII numbers, need two ASCII numbers separated by - * a '\0' and they need to fit exactly in the chunk data. - */ - i = 1; - state = 0; - - if (!png_check_fp_number(png_ptr->chunkdata, slength, &state, &i) || - i >= slength || png_ptr->chunkdata[i++] != 0) - png_warning(png_ptr, "Invalid sCAL chunk ignored: bad width format"); - - else if (!PNG_FP_IS_POSITIVE(state)) - png_warning(png_ptr, "Invalid sCAL chunk ignored: non-positive width"); - - else - { - png_size_t heighti = i; - - state = 0; - if (!png_check_fp_number(png_ptr->chunkdata, slength, &state, &i) || - i != slength) - png_warning(png_ptr, "Invalid sCAL chunk ignored: bad height format"); - - else if (!PNG_FP_IS_POSITIVE(state)) - png_warning(png_ptr, - "Invalid sCAL chunk ignored: non-positive height"); - - else - /* This is the (only) success case. */ - png_set_sCAL_s(png_ptr, info_ptr, png_ptr->chunkdata[0], - png_ptr->chunkdata+1, png_ptr->chunkdata+heighti); - } - - /* Clean up - just free the temporarily allocated buffer. */ - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; -} -#endif - -#ifdef PNG_READ_tIME_SUPPORTED -void /* PRIVATE */ -png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_byte buf[7]; - png_time mod_time; - - png_debug(1, "in png_handle_tIME"); - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Out of place tIME chunk"); - - else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)) - { - png_warning(png_ptr, "Duplicate tIME chunk"); - png_crc_finish(png_ptr, length); - return; - } - - if (png_ptr->mode & PNG_HAVE_IDAT) - png_ptr->mode |= PNG_AFTER_IDAT; - - if (length != 7) - { - png_warning(png_ptr, "Incorrect tIME chunk length"); - png_crc_finish(png_ptr, length); - return; - } - - png_crc_read(png_ptr, buf, 7); - - if (png_crc_finish(png_ptr, 0)) - return; - - mod_time.second = buf[6]; - mod_time.minute = buf[5]; - mod_time.hour = buf[4]; - mod_time.day = buf[3]; - mod_time.month = buf[2]; - mod_time.year = png_get_uint_16(buf); - - png_set_tIME(png_ptr, info_ptr, &mod_time); -} -#endif - -#ifdef PNG_READ_tEXt_SUPPORTED -/* Note: this does not properly handle chunks that are > 64K under DOS */ -void /* PRIVATE */ -png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_textp text_ptr; - png_charp key; - png_charp text; - png_uint_32 skip = 0; - png_size_t slength; - int ret; - - png_debug(1, "in png_handle_tEXt"); - -#ifdef PNG_USER_LIMITS_SUPPORTED - if (png_ptr->user_chunk_cache_max != 0) - { - if (png_ptr->user_chunk_cache_max == 1) - { - png_crc_finish(png_ptr, length); - return; - } - - if (--png_ptr->user_chunk_cache_max == 1) - { - png_warning(png_ptr, "No space in chunk cache for tEXt"); - png_crc_finish(png_ptr, length); - return; - } - } -#endif - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before tEXt"); - - if (png_ptr->mode & PNG_HAVE_IDAT) - png_ptr->mode |= PNG_AFTER_IDAT; - -#ifdef PNG_MAX_MALLOC_64K - if (length > (png_uint_32)65535L) - { - png_warning(png_ptr, "tEXt chunk too large to fit in memory"); - skip = length - (png_uint_32)65535L; - length = (png_uint_32)65535L; - } -#endif - - png_free(png_ptr, png_ptr->chunkdata); - - png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); - - if (png_ptr->chunkdata == NULL) - { - png_warning(png_ptr, "No memory to process text chunk"); - return; - } - - slength = length; - png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); - - if (png_crc_finish(png_ptr, skip)) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - key = png_ptr->chunkdata; - - key[slength] = 0x00; - - for (text = key; *text; text++) - /* Empty loop to find end of key */ ; - - if (text != key + slength) - text++; - - text_ptr = (png_textp)png_malloc_warn(png_ptr, - png_sizeof(png_text)); - - if (text_ptr == NULL) - { - png_warning(png_ptr, "Not enough memory to process text chunk"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - text_ptr->compression = PNG_TEXT_COMPRESSION_NONE; - text_ptr->key = key; - text_ptr->lang = NULL; - text_ptr->lang_key = NULL; - text_ptr->itxt_length = 0; - text_ptr->text = text; - text_ptr->text_length = png_strlen(text); - - ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - png_free(png_ptr, text_ptr); - - if (ret) - png_warning(png_ptr, "Insufficient memory to process text chunk"); -} -#endif - -#ifdef PNG_READ_zTXt_SUPPORTED -/* Note: this does not correctly handle chunks that are > 64K under DOS */ -void /* PRIVATE */ -png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_textp text_ptr; - png_charp text; - int comp_type; - int ret; - png_size_t slength, prefix_len, data_len; - - png_debug(1, "in png_handle_zTXt"); - -#ifdef PNG_USER_LIMITS_SUPPORTED - if (png_ptr->user_chunk_cache_max != 0) - { - if (png_ptr->user_chunk_cache_max == 1) - { - png_crc_finish(png_ptr, length); - return; - } - - if (--png_ptr->user_chunk_cache_max == 1) - { - png_warning(png_ptr, "No space in chunk cache for zTXt"); - png_crc_finish(png_ptr, length); - return; - } - } -#endif - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before zTXt"); - - if (png_ptr->mode & PNG_HAVE_IDAT) - png_ptr->mode |= PNG_AFTER_IDAT; - -#ifdef PNG_MAX_MALLOC_64K - /* We will no doubt have problems with chunks even half this size, but - * there is no hard and fast rule to tell us where to stop. - */ - if (length > (png_uint_32)65535L) - { - png_warning(png_ptr, "zTXt chunk too large to fit in memory"); - png_crc_finish(png_ptr, length); - return; - } -#endif - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); - - if (png_ptr->chunkdata == NULL) - { - png_warning(png_ptr, "Out of memory processing zTXt chunk"); - return; - } - - slength = length; - png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); - - if (png_crc_finish(png_ptr, 0)) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - png_ptr->chunkdata[slength] = 0x00; - - for (text = png_ptr->chunkdata; *text; text++) - /* Empty loop */ ; - - /* zTXt must have some text after the chunkdataword */ - if (text >= png_ptr->chunkdata + slength - 2) - { - png_warning(png_ptr, "Truncated zTXt chunk"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - else - { - comp_type = *(++text); - - if (comp_type != PNG_TEXT_COMPRESSION_zTXt) - { - png_warning(png_ptr, "Unknown compression type in zTXt chunk"); - comp_type = PNG_TEXT_COMPRESSION_zTXt; - } - - text++; /* Skip the compression_method byte */ - } - - prefix_len = text - png_ptr->chunkdata; - - png_decompress_chunk(png_ptr, comp_type, - (png_size_t)length, prefix_len, &data_len); - - text_ptr = (png_textp)png_malloc_warn(png_ptr, - png_sizeof(png_text)); - - if (text_ptr == NULL) - { - png_warning(png_ptr, "Not enough memory to process zTXt chunk"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - text_ptr->compression = comp_type; - text_ptr->key = png_ptr->chunkdata; - text_ptr->lang = NULL; - text_ptr->lang_key = NULL; - text_ptr->itxt_length = 0; - text_ptr->text = png_ptr->chunkdata + prefix_len; - text_ptr->text_length = data_len; - - ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); - - png_free(png_ptr, text_ptr); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - - if (ret) - png_error(png_ptr, "Insufficient memory to store zTXt chunk"); -} -#endif - -#ifdef PNG_READ_iTXt_SUPPORTED -/* Note: this does not correctly handle chunks that are > 64K under DOS */ -void /* PRIVATE */ -png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_textp text_ptr; - png_charp key, lang, text, lang_key; - int comp_flag; - int comp_type = 0; - int ret; - png_size_t slength, prefix_len, data_len; - - png_debug(1, "in png_handle_iTXt"); - -#ifdef PNG_USER_LIMITS_SUPPORTED - if (png_ptr->user_chunk_cache_max != 0) - { - if (png_ptr->user_chunk_cache_max == 1) - { - png_crc_finish(png_ptr, length); - return; - } - - if (--png_ptr->user_chunk_cache_max == 1) - { - png_warning(png_ptr, "No space in chunk cache for iTXt"); - png_crc_finish(png_ptr, length); - return; - } - } -#endif - - if (!(png_ptr->mode & PNG_HAVE_IHDR)) - png_error(png_ptr, "Missing IHDR before iTXt"); - - if (png_ptr->mode & PNG_HAVE_IDAT) - png_ptr->mode |= PNG_AFTER_IDAT; - -#ifdef PNG_MAX_MALLOC_64K - /* We will no doubt have problems with chunks even half this size, but - * there is no hard and fast rule to tell us where to stop. - */ - if (length > (png_uint_32)65535L) - { - png_warning(png_ptr, "iTXt chunk too large to fit in memory"); - png_crc_finish(png_ptr, length); - return; - } -#endif - - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); - - if (png_ptr->chunkdata == NULL) - { - png_warning(png_ptr, "No memory to process iTXt chunk"); - return; - } - - slength = length; - png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); - - if (png_crc_finish(png_ptr, 0)) - { - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - png_ptr->chunkdata[slength] = 0x00; - - for (lang = png_ptr->chunkdata; *lang; lang++) - /* Empty loop */ ; - - lang++; /* Skip NUL separator */ - - /* iTXt must have a language tag (possibly empty), two compression bytes, - * translated keyword (possibly empty), and possibly some text after the - * keyword - */ - - if (lang >= png_ptr->chunkdata + slength - 3) - { - png_warning(png_ptr, "Truncated iTXt chunk"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - else - { - comp_flag = *lang++; - comp_type = *lang++; - } - - if (comp_type || (comp_flag && comp_flag != PNG_TEXT_COMPRESSION_zTXt)) - { - png_warning(png_ptr, "Unknown iTXt compression type or method"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - for (lang_key = lang; *lang_key; lang_key++) - /* Empty loop */ ; - - lang_key++; /* Skip NUL separator */ - - if (lang_key >= png_ptr->chunkdata + slength) - { - png_warning(png_ptr, "Truncated iTXt chunk"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - for (text = lang_key; *text; text++) - /* Empty loop */ ; - - text++; /* Skip NUL separator */ - - if (text >= png_ptr->chunkdata + slength) - { - png_warning(png_ptr, "Malformed iTXt chunk"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - prefix_len = text - png_ptr->chunkdata; - - key=png_ptr->chunkdata; - - if (comp_flag) - png_decompress_chunk(png_ptr, comp_type, - (size_t)length, prefix_len, &data_len); - - else - data_len = png_strlen(png_ptr->chunkdata + prefix_len); - - text_ptr = (png_textp)png_malloc_warn(png_ptr, - png_sizeof(png_text)); - - if (text_ptr == NULL) - { - png_warning(png_ptr, "Not enough memory to process iTXt chunk"); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - return; - } - - text_ptr->compression = (int)comp_flag + 1; - text_ptr->lang_key = png_ptr->chunkdata + (lang_key - key); - text_ptr->lang = png_ptr->chunkdata + (lang - key); - text_ptr->itxt_length = data_len; - text_ptr->text_length = 0; - text_ptr->key = png_ptr->chunkdata; - text_ptr->text = png_ptr->chunkdata + prefix_len; - - ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); - - png_free(png_ptr, text_ptr); - png_free(png_ptr, png_ptr->chunkdata); - png_ptr->chunkdata = NULL; - - if (ret) - png_error(png_ptr, "Insufficient memory to store iTXt chunk"); -} -#endif - -/* This function is called when we haven't found a handler for a - * chunk. If there isn't a problem with the chunk itself (ie bad - * chunk name, CRC, or a critical chunk), the chunk is silently ignored - * -- unless the PNG_FLAG_UNKNOWN_CHUNKS_SUPPORTED flag is on in which - * case it will be saved away to be written out later. - */ -void /* PRIVATE */ -png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) -{ - png_uint_32 skip = 0; - - png_debug(1, "in png_handle_unknown"); - -#ifdef PNG_USER_LIMITS_SUPPORTED - if (png_ptr->user_chunk_cache_max != 0) - { - if (png_ptr->user_chunk_cache_max == 1) - { - png_crc_finish(png_ptr, length); - return; - } - - if (--png_ptr->user_chunk_cache_max == 1) - { - png_warning(png_ptr, "No space in chunk cache for unknown chunk"); - png_crc_finish(png_ptr, length); - return; - } - } -#endif - - if (png_ptr->mode & PNG_HAVE_IDAT) - { - if (png_ptr->chunk_name != png_IDAT) - png_ptr->mode |= PNG_AFTER_IDAT; - } - - if (PNG_CHUNK_CRITICAL(png_ptr->chunk_name)) - { -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - if (png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name) != - PNG_HANDLE_CHUNK_ALWAYS -#ifdef PNG_READ_USER_CHUNKS_SUPPORTED - && png_ptr->read_user_chunk_fn == NULL -#endif - ) -#endif - png_chunk_error(png_ptr, "unknown critical chunk"); - } - -#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED - if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) -#ifdef PNG_READ_USER_CHUNKS_SUPPORTED - || (png_ptr->read_user_chunk_fn != NULL) -#endif - ) - { -#ifdef PNG_MAX_MALLOC_64K - if (length > 65535) - { - png_warning(png_ptr, "unknown chunk too large to fit in memory"); - skip = length - 65535; - length = 65535; - } -#endif - - /* TODO: this code is very close to the unknown handling in pngpread.c, - * maybe it can be put into a common utility routine? - * png_struct::unknown_chunk is just used as a temporary variable, along - * with the data into which the chunk is read. These can be eliminated. - */ - PNG_CSTRING_FROM_CHUNK(png_ptr->unknown_chunk.name, png_ptr->chunk_name); - png_ptr->unknown_chunk.size = (png_size_t)length; - - if (length == 0) - png_ptr->unknown_chunk.data = NULL; - - else - { - png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length); - png_crc_read(png_ptr, png_ptr->unknown_chunk.data, length); - } - -#ifdef PNG_READ_USER_CHUNKS_SUPPORTED - if (png_ptr->read_user_chunk_fn != NULL) - { - /* Callback to user unknown chunk handler */ - int ret; - - ret = (*(png_ptr->read_user_chunk_fn)) - (png_ptr, &png_ptr->unknown_chunk); - - if (ret < 0) - png_chunk_error(png_ptr, "error in user chunk"); - - if (ret == 0) - { - if (PNG_CHUNK_CRITICAL(png_ptr->chunk_name)) - { -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - if (png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name) != - PNG_HANDLE_CHUNK_ALWAYS) -#endif - png_chunk_error(png_ptr, "unknown critical chunk"); - } - - png_set_unknown_chunks(png_ptr, info_ptr, - &png_ptr->unknown_chunk, 1); - } - } - - else -#endif - png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1); - - png_free(png_ptr, png_ptr->unknown_chunk.data); - png_ptr->unknown_chunk.data = NULL; - } - - else -#endif - skip = length; - - png_crc_finish(png_ptr, skip); - -#ifndef PNG_READ_USER_CHUNKS_SUPPORTED - PNG_UNUSED(info_ptr) /* Quiet compiler warnings about unused info_ptr */ -#endif -} - -/* This function is called to verify that a chunk name is valid. - * This function can't have the "critical chunk check" incorporated - * into it, since in the future we will need to be able to call user - * functions to handle unknown critical chunks after we check that - * the chunk name itself is valid. - */ - -/* Bit hacking: the test for an invalid byte in the 4 byte chunk name is: - * - * ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) - */ - -void /* PRIVATE */ -png_check_chunk_name(png_structp png_ptr, png_uint_32 chunk_name) -{ - int i; - - png_debug(1, "in png_check_chunk_name"); - - for (i=1; i<=4; ++i) - { - int c = chunk_name & 0xff; - - if (c < 65 || c > 122 || (c > 90 && c < 97)) - png_chunk_error(png_ptr, "invalid chunk type"); - - chunk_name >>= 8; - } -} - -/* Combines the row recently read in with the existing pixels in the row. This - * routine takes care of alpha and transparency if requested. This routine also - * handles the two methods of progressive display of interlaced images, - * depending on the 'display' value; if 'display' is true then the whole row - * (dp) is filled from the start by replicating the available pixels. If - * 'display' is false only those pixels present in the pass are filled in. - */ -void /* PRIVATE */ -png_combine_row(png_structp png_ptr, png_bytep dp, int display) -{ - unsigned int pixel_depth = png_ptr->transformed_pixel_depth; - png_const_bytep sp = png_ptr->row_buf + 1; - png_uint_32 row_width = png_ptr->width; - unsigned int pass = png_ptr->pass; - png_bytep end_ptr = 0; - png_byte end_byte = 0; - unsigned int end_mask; - - png_debug(1, "in png_combine_row"); - - /* Added in 1.5.6: it should not be possible to enter this routine until at - * least one row has been read from the PNG data and transformed. - */ - if (pixel_depth == 0) - png_error(png_ptr, "internal row logic error"); - - /* Added in 1.5.4: the pixel depth should match the information returned by - * any call to png_read_update_info at this point. Do not continue if we got - * this wrong. - */ - if (png_ptr->info_rowbytes != 0 && png_ptr->info_rowbytes != - PNG_ROWBYTES(pixel_depth, row_width)) - png_error(png_ptr, "internal row size calculation error"); - - /* Don't expect this to ever happen: */ - if (row_width == 0) - png_error(png_ptr, "internal row width error"); - - /* Preserve the last byte in cases where only part of it will be overwritten, - * the multiply below may overflow, we don't care because ANSI-C guarantees - * we get the low bits. - */ - end_mask = (pixel_depth * row_width) & 7; - if (end_mask != 0) - { - /* end_ptr == NULL is a flag to say do nothing */ - end_ptr = dp + PNG_ROWBYTES(pixel_depth, row_width) - 1; - end_byte = *end_ptr; -# ifdef PNG_READ_PACKSWAP_SUPPORTED - if (png_ptr->transformations & PNG_PACKSWAP) /* little-endian byte */ - end_mask = 0xff << end_mask; - - else /* big-endian byte */ -# endif - end_mask = 0xff >> end_mask; - /* end_mask is now the bits to *keep* from the destination row */ - } - - /* For non-interlaced images this reduces to a png_memcpy(). A png_memcpy() - * will also happen if interlacing isn't supported or if the application - * does not call png_set_interlace_handling(). In the latter cases the - * caller just gets a sequence of the unexpanded rows from each interlace - * pass. - */ -#ifdef PNG_READ_INTERLACING_SUPPORTED - if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE) && - pass < 6 && (display == 0 || - /* The following copies everything for 'display' on passes 0, 2 and 4. */ - (display == 1 && (pass & 1) != 0))) - { - /* Narrow images may have no bits in a pass; the caller should handle - * this, but this test is cheap: - */ - if (row_width <= PNG_PASS_START_COL(pass)) - return; - - if (pixel_depth < 8) - { - /* For pixel depths up to 4 bpp the 8-pixel mask can be expanded to fit - * into 32 bits, then a single loop over the bytes using the four byte - * values in the 32-bit mask can be used. For the 'display' option the - * expanded mask may also not require any masking within a byte. To - * make this work the PACKSWAP option must be taken into account - it - * simply requires the pixels to be reversed in each byte. - * - * The 'regular' case requires a mask for each of the first 6 passes, - * the 'display' case does a copy for the even passes in the range - * 0..6. This has already been handled in the test above. - * - * The masks are arranged as four bytes with the first byte to use in - * the lowest bits (little-endian) regardless of the order (PACKSWAP or - * not) of the pixels in each byte. - * - * NOTE: the whole of this logic depends on the caller of this function - * only calling it on rows appropriate to the pass. This function only - * understands the 'x' logic; the 'y' logic is handled by the caller. - * - * The following defines allow generation of compile time constant bit - * masks for each pixel depth and each possibility of swapped or not - * swapped bytes. Pass 'p' is in the range 0..6; 'x', a pixel index, - * is in the range 0..7; and the result is 1 if the pixel is to be - * copied in the pass, 0 if not. 'S' is for the sparkle method, 'B' - * for the block method. - * - * With some compilers a compile time expression of the general form: - * - * (shift >= 32) ? (a >> (shift-32)) : (b >> shift) - * - * Produces warnings with values of 'shift' in the range 33 to 63 - * because the right hand side of the ?: expression is evaluated by - * the compiler even though it isn't used. Microsoft Visual C (various - * versions) and the Intel C compiler are known to do this. To avoid - * this the following macros are used in 1.5.6. This is a temporary - * solution to avoid destabilizing the code during the release process. - */ -# if PNG_USE_COMPILE_TIME_MASKS -# define PNG_LSR(x,s) ((x)>>((s) & 0x1f)) -# define PNG_LSL(x,s) ((x)<<((s) & 0x1f)) -# else -# define PNG_LSR(x,s) ((x)>>(s)) -# define PNG_LSL(x,s) ((x)<<(s)) -# endif -# define S_COPY(p,x) (((p)<4 ? PNG_LSR(0x80088822,(3-(p))*8+(7-(x))) :\ - PNG_LSR(0xaa55ff00,(7-(p))*8+(7-(x)))) & 1) -# define B_COPY(p,x) (((p)<4 ? PNG_LSR(0xff0fff33,(3-(p))*8+(7-(x))) :\ - PNG_LSR(0xff55ff00,(7-(p))*8+(7-(x)))) & 1) - - /* Return a mask for pass 'p' pixel 'x' at depth 'd'. The mask is - * little endian - the first pixel is at bit 0 - however the extra - * parameter 's' can be set to cause the mask position to be swapped - * within each byte, to match the PNG format. This is done by XOR of - * the shift with 7, 6 or 4 for bit depths 1, 2 and 4. - */ -# define PIXEL_MASK(p,x,d,s) \ - (PNG_LSL(((PNG_LSL(1U,(d)))-1),(((x)*(d))^((s)?8-(d):0)))) - - /* Hence generate the appropriate 'block' or 'sparkle' pixel copy mask. - */ -# define S_MASKx(p,x,d,s) (S_COPY(p,x)?PIXEL_MASK(p,x,d,s):0) -# define B_MASKx(p,x,d,s) (B_COPY(p,x)?PIXEL_MASK(p,x,d,s):0) - - /* Combine 8 of these to get the full mask. For the 1-bpp and 2-bpp - * cases the result needs replicating, for the 4-bpp case the above - * generates a full 32 bits. - */ -# define MASK_EXPAND(m,d) ((m)*((d)==1?0x01010101:((d)==2?0x00010001:1))) - -# define S_MASK(p,d,s) MASK_EXPAND(S_MASKx(p,0,d,s) + S_MASKx(p,1,d,s) +\ - S_MASKx(p,2,d,s) + S_MASKx(p,3,d,s) + S_MASKx(p,4,d,s) +\ - S_MASKx(p,5,d,s) + S_MASKx(p,6,d,s) + S_MASKx(p,7,d,s), d) - -# define B_MASK(p,d,s) MASK_EXPAND(B_MASKx(p,0,d,s) + B_MASKx(p,1,d,s) +\ - B_MASKx(p,2,d,s) + B_MASKx(p,3,d,s) + B_MASKx(p,4,d,s) +\ - B_MASKx(p,5,d,s) + B_MASKx(p,6,d,s) + B_MASKx(p,7,d,s), d) - -#if PNG_USE_COMPILE_TIME_MASKS - /* Utility macros to construct all the masks for a depth/swap - * combination. The 's' parameter says whether the format is PNG - * (big endian bytes) or not. Only the three odd-numbered passes are - * required for the display/block algorithm. - */ -# define S_MASKS(d,s) { S_MASK(0,d,s), S_MASK(1,d,s), S_MASK(2,d,s),\ - S_MASK(3,d,s), S_MASK(4,d,s), S_MASK(5,d,s) } - -# define B_MASKS(d,s) { B_MASK(1,d,s), S_MASK(3,d,s), S_MASK(5,d,s) } - -# define DEPTH_INDEX(d) ((d)==1?0:((d)==2?1:2)) - - /* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and - * then pass: - */ - static PNG_CONST png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] = - { - /* Little-endian byte masks for PACKSWAP */ - { S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) }, - /* Normal (big-endian byte) masks - PNG format */ - { S_MASKS(1,1), S_MASKS(2,1), S_MASKS(4,1) } - }; - - /* display_mask has only three entries for the odd passes, so index by - * pass>>1. - */ - static PNG_CONST png_uint_32 display_mask[2][3][3] = - { - /* Little-endian byte masks for PACKSWAP */ - { B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) }, - /* Normal (big-endian byte) masks - PNG format */ - { B_MASKS(1,1), B_MASKS(2,1), B_MASKS(4,1) } - }; - -# define MASK(pass,depth,display,png)\ - ((display)?display_mask[png][DEPTH_INDEX(depth)][pass>>1]:\ - row_mask[png][DEPTH_INDEX(depth)][pass]) - -#else /* !PNG_USE_COMPILE_TIME_MASKS */ - /* This is the runtime alternative: it seems unlikely that this will - * ever be either smaller or faster than the compile time approach. - */ -# define MASK(pass,depth,display,png)\ - ((display)?B_MASK(pass,depth,png):S_MASK(pass,depth,png)) -#endif /* !PNG_USE_COMPILE_TIME_MASKS */ - - /* Use the appropriate mask to copy the required bits. In some cases - * the byte mask will be 0 or 0xff, optimize these cases. row_width is - * the number of pixels, but the code copies bytes, so it is necessary - * to special case the end. - */ - png_uint_32 pixels_per_byte = 8 / pixel_depth; - png_uint_32 mask; - -# ifdef PNG_READ_PACKSWAP_SUPPORTED - if (png_ptr->transformations & PNG_PACKSWAP) - mask = MASK(pass, pixel_depth, display, 0); - - else -# endif - mask = MASK(pass, pixel_depth, display, 1); - - for (;;) - { - png_uint_32 m; - - /* It doesn't matter in the following if png_uint_32 has more than - * 32 bits because the high bits always match those in m<<24; it is, - * however, essential to use OR here, not +, because of this. - */ - m = mask; - mask = (m >> 8) | (m << 24); /* rotate right to good compilers */ - m &= 0xff; - - if (m != 0) /* something to copy */ - { - if (m != 0xff) - *dp = (png_byte)((*dp & ~m) | (*sp & m)); - else - *dp = *sp; - } - - /* NOTE: this may overwrite the last byte with garbage if the image - * is not an exact number of bytes wide; libpng has always done - * this. - */ - if (row_width <= pixels_per_byte) - break; /* May need to restore part of the last byte */ - - row_width -= pixels_per_byte; - ++dp; - ++sp; - } - } - - else /* pixel_depth >= 8 */ - { - unsigned int bytes_to_copy, bytes_to_jump; - - /* Validate the depth - it must be a multiple of 8 */ - if (pixel_depth & 7) - png_error(png_ptr, "invalid user transform pixel depth"); - - pixel_depth >>= 3; /* now in bytes */ - row_width *= pixel_depth; - - /* Regardless of pass number the Adam 7 interlace always results in a - * fixed number of pixels to copy then to skip. There may be a - * different number of pixels to skip at the start though. - */ - { - unsigned int offset = PNG_PASS_START_COL(pass) * pixel_depth; - - row_width -= offset; - dp += offset; - sp += offset; - } - - /* Work out the bytes to copy. */ - if (display) - { - /* When doing the 'block' algorithm the pixel in the pass gets - * replicated to adjacent pixels. This is why the even (0,2,4,6) - * passes are skipped above - the entire expanded row is copied. - */ - bytes_to_copy = (1<<((6-pass)>>1)) * pixel_depth; - - /* But don't allow this number to exceed the actual row width. */ - if (bytes_to_copy > row_width) - bytes_to_copy = row_width; - } - - else /* normal row; Adam7 only ever gives us one pixel to copy. */ - bytes_to_copy = pixel_depth; - - /* In Adam7 there is a constant offset between where the pixels go. */ - bytes_to_jump = PNG_PASS_COL_OFFSET(pass) * pixel_depth; - - /* And simply copy these bytes. Some optimization is possible here, - * depending on the value of 'bytes_to_copy'. Special case the low - * byte counts, which we know to be frequent. - * - * Notice that these cases all 'return' rather than 'break' - this - * avoids an unnecessary test on whether to restore the last byte - * below. - */ - switch (bytes_to_copy) - { - case 1: - for (;;) - { - *dp = *sp; - - if (row_width <= bytes_to_jump) - return; - - dp += bytes_to_jump; - sp += bytes_to_jump; - row_width -= bytes_to_jump; - } - - case 2: - /* There is a possibility of a partial copy at the end here; this - * slows the code down somewhat. - */ - do - { - dp[0] = sp[0], dp[1] = sp[1]; - - if (row_width <= bytes_to_jump) - return; - - sp += bytes_to_jump; - dp += bytes_to_jump; - row_width -= bytes_to_jump; - } - while (row_width > 1); - - /* And there can only be one byte left at this point: */ - *dp = *sp; - return; - - case 3: - /* This can only be the RGB case, so each copy is exactly one - * pixel and it is not necessary to check for a partial copy. - */ - for(;;) - { - dp[0] = sp[0], dp[1] = sp[1], dp[2] = sp[2]; - - if (row_width <= bytes_to_jump) - return; - - sp += bytes_to_jump; - dp += bytes_to_jump; - row_width -= bytes_to_jump; - } - - default: -#if PNG_ALIGN_TYPE != PNG_ALIGN_NONE - /* Check for double byte alignment and, if possible, use a - * 16-bit copy. Don't attempt this for narrow images - ones that - * are less than an interlace panel wide. Don't attempt it for - * wide bytes_to_copy either - use the png_memcpy there. - */ - if (bytes_to_copy < 16 /*else use png_memcpy*/ && - png_isaligned(dp, png_uint_16) && - png_isaligned(sp, png_uint_16) && - bytes_to_copy % sizeof (png_uint_16) == 0 && - bytes_to_jump % sizeof (png_uint_16) == 0) - { - /* Everything is aligned for png_uint_16 copies, but try for - * png_uint_32 first. - */ - if (png_isaligned(dp, png_uint_32) && - png_isaligned(sp, png_uint_32) && - bytes_to_copy % sizeof (png_uint_32) == 0 && - bytes_to_jump % sizeof (png_uint_32) == 0) - { - png_uint_32p dp32 = (png_uint_32p)dp; - png_const_uint_32p sp32 = (png_const_uint_32p)sp; - unsigned int skip = (bytes_to_jump-bytes_to_copy) / - sizeof (png_uint_32); - - do - { - size_t c = bytes_to_copy; - do - { - *dp32++ = *sp32++; - c -= sizeof (png_uint_32); - } - while (c > 0); - - if (row_width <= bytes_to_jump) - return; - - dp32 += skip; - sp32 += skip; - row_width -= bytes_to_jump; - } - while (bytes_to_copy <= row_width); - - /* Get to here when the row_width truncates the final copy. - * There will be 1-3 bytes left to copy, so don't try the - * 16-bit loop below. - */ - dp = (png_bytep)dp32; - sp = (png_const_bytep)sp32; - do - *dp++ = *sp++; - while (--row_width > 0); - return; - } - - /* Else do it in 16-bit quantities, but only if the size is - * not too large. - */ - else - { - png_uint_16p dp16 = (png_uint_16p)dp; - png_const_uint_16p sp16 = (png_const_uint_16p)sp; - unsigned int skip = (bytes_to_jump-bytes_to_copy) / - sizeof (png_uint_16); - - do - { - size_t c = bytes_to_copy; - do - { - *dp16++ = *sp16++; - c -= sizeof (png_uint_16); - } - while (c > 0); - - if (row_width <= bytes_to_jump) - return; - - dp16 += skip; - sp16 += skip; - row_width -= bytes_to_jump; - } - while (bytes_to_copy <= row_width); - - /* End of row - 1 byte left, bytes_to_copy > row_width: */ - dp = (png_bytep)dp16; - sp = (png_const_bytep)sp16; - do - *dp++ = *sp++; - while (--row_width > 0); - return; - } - } -#endif /* PNG_ALIGN_ code */ - - /* The true default - use a png_memcpy: */ - for (;;) - { - png_memcpy(dp, sp, bytes_to_copy); - - if (row_width <= bytes_to_jump) - return; - - sp += bytes_to_jump; - dp += bytes_to_jump; - row_width -= bytes_to_jump; - if (bytes_to_copy > row_width) - bytes_to_copy = row_width; - } - } - - /* NOT REACHED*/ - } /* pixel_depth >= 8 */ - - /* Here if pixel_depth < 8 to check 'end_ptr' below. */ - } - else -#endif - - /* If here then the switch above wasn't used so just png_memcpy the whole row - * from the temporary row buffer (notice that this overwrites the end of the - * destination row if it is a partial byte.) - */ - png_memcpy(dp, sp, PNG_ROWBYTES(pixel_depth, row_width)); - - /* Restore the overwritten bits from the last byte if necessary. */ - if (end_ptr != NULL) - *end_ptr = (png_byte)((end_byte & end_mask) | (*end_ptr & ~end_mask)); -} - -#ifdef PNG_READ_INTERLACING_SUPPORTED -void /* PRIVATE */ -png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, - png_uint_32 transformations /* Because these may affect the byte layout */) -{ - /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ - /* Offset to next interlace block */ - static PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; - - png_debug(1, "in png_do_read_interlace"); - if (row != NULL && row_info != NULL) - { - png_uint_32 final_width; - - final_width = row_info->width * png_pass_inc[pass]; - - switch (row_info->pixel_depth) - { - case 1: - { - png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3); - png_bytep dp = row + (png_size_t)((final_width - 1) >> 3); - int sshift, dshift; - int s_start, s_end, s_inc; - int jstop = png_pass_inc[pass]; - png_byte v; - png_uint_32 i; - int j; - -#ifdef PNG_READ_PACKSWAP_SUPPORTED - if (transformations & PNG_PACKSWAP) - { - sshift = (int)((row_info->width + 7) & 0x07); - dshift = (int)((final_width + 7) & 0x07); - s_start = 7; - s_end = 0; - s_inc = -1; - } - - else -#endif - { - sshift = 7 - (int)((row_info->width + 7) & 0x07); - dshift = 7 - (int)((final_width + 7) & 0x07); - s_start = 0; - s_end = 7; - s_inc = 1; - } - - for (i = 0; i < row_info->width; i++) - { - v = (png_byte)((*sp >> sshift) & 0x01); - for (j = 0; j < jstop; j++) - { - *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff); - *dp |= (png_byte)(v << dshift); - - if (dshift == s_end) - { - dshift = s_start; - dp--; - } - - else - dshift += s_inc; - } - - if (sshift == s_end) - { - sshift = s_start; - sp--; - } - - else - sshift += s_inc; - } - break; - } - - case 2: - { - png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2); - png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2); - int sshift, dshift; - int s_start, s_end, s_inc; - int jstop = png_pass_inc[pass]; - png_uint_32 i; - -#ifdef PNG_READ_PACKSWAP_SUPPORTED - if (transformations & PNG_PACKSWAP) - { - sshift = (int)(((row_info->width + 3) & 0x03) << 1); - dshift = (int)(((final_width + 3) & 0x03) << 1); - s_start = 6; - s_end = 0; - s_inc = -2; - } - - else -#endif - { - sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1); - dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1); - s_start = 0; - s_end = 6; - s_inc = 2; - } - - for (i = 0; i < row_info->width; i++) - { - png_byte v; - int j; - - v = (png_byte)((*sp >> sshift) & 0x03); - for (j = 0; j < jstop; j++) - { - *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff); - *dp |= (png_byte)(v << dshift); - - if (dshift == s_end) - { - dshift = s_start; - dp--; - } - - else - dshift += s_inc; - } - - if (sshift == s_end) - { - sshift = s_start; - sp--; - } - - else - sshift += s_inc; - } - break; - } - - case 4: - { - png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1); - png_bytep dp = row + (png_size_t)((final_width - 1) >> 1); - int sshift, dshift; - int s_start, s_end, s_inc; - png_uint_32 i; - int jstop = png_pass_inc[pass]; - -#ifdef PNG_READ_PACKSWAP_SUPPORTED - if (transformations & PNG_PACKSWAP) - { - sshift = (int)(((row_info->width + 1) & 0x01) << 2); - dshift = (int)(((final_width + 1) & 0x01) << 2); - s_start = 4; - s_end = 0; - s_inc = -4; - } - - else -#endif - { - sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2); - dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2); - s_start = 0; - s_end = 4; - s_inc = 4; - } - - for (i = 0; i < row_info->width; i++) - { - png_byte v = (png_byte)((*sp >> sshift) & 0x0f); - int j; - - for (j = 0; j < jstop; j++) - { - *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff); - *dp |= (png_byte)(v << dshift); - - if (dshift == s_end) - { - dshift = s_start; - dp--; - } - - else - dshift += s_inc; - } - - if (sshift == s_end) - { - sshift = s_start; - sp--; - } - - else - sshift += s_inc; - } - break; - } - - default: - { - png_size_t pixel_bytes = (row_info->pixel_depth >> 3); - - png_bytep sp = row + (png_size_t)(row_info->width - 1) - * pixel_bytes; - - png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes; - - int jstop = png_pass_inc[pass]; - png_uint_32 i; - - for (i = 0; i < row_info->width; i++) - { - png_byte v[8]; - int j; - - png_memcpy(v, sp, pixel_bytes); - - for (j = 0; j < jstop; j++) - { - png_memcpy(dp, v, pixel_bytes); - dp -= pixel_bytes; - } - - sp -= pixel_bytes; - } - break; - } - } - - row_info->width = final_width; - row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width); - } -#ifndef PNG_READ_PACKSWAP_SUPPORTED - PNG_UNUSED(transformations) /* Silence compiler warning */ -#endif -} -#endif /* PNG_READ_INTERLACING_SUPPORTED */ - -static void -png_read_filter_row_sub(png_row_infop row_info, png_bytep row, - png_const_bytep prev_row) -{ - png_size_t i; - png_size_t istop = row_info->rowbytes; - unsigned int bpp = (row_info->pixel_depth + 7) >> 3; - png_bytep rp = row + bpp; - - PNG_UNUSED(prev_row) - - for (i = bpp; i < istop; i++) - { - *rp = (png_byte)(((int)(*rp) + (int)(*(rp-bpp))) & 0xff); - rp++; - } -} - -static void -png_read_filter_row_up(png_row_infop row_info, png_bytep row, - png_const_bytep prev_row) -{ - png_size_t i; - png_size_t istop = row_info->rowbytes; - png_bytep rp = row; - png_const_bytep pp = prev_row; - - for (i = 0; i < istop; i++) - { - *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff); - rp++; - } -} - -static void -png_read_filter_row_avg(png_row_infop row_info, png_bytep row, - png_const_bytep prev_row) -{ - png_size_t i; - png_bytep rp = row; - png_const_bytep pp = prev_row; - unsigned int bpp = (row_info->pixel_depth + 7) >> 3; - png_size_t istop = row_info->rowbytes - bpp; - - for (i = 0; i < bpp; i++) - { - *rp = (png_byte)(((int)(*rp) + - ((int)(*pp++) / 2 )) & 0xff); - - rp++; - } - - for (i = 0; i < istop; i++) - { - *rp = (png_byte)(((int)(*rp) + - (int)(*pp++ + *(rp-bpp)) / 2 ) & 0xff); - - rp++; - } -} - -static void -png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row, - png_const_bytep prev_row) -{ - png_bytep rp_end = row + row_info->rowbytes; - int a, c; - - /* First pixel/byte */ - c = *prev_row++; - a = *row + c; - *row++ = (png_byte)a; - - /* Remainder */ - while (row < rp_end) - { - int b, pa, pb, pc, p; - - a &= 0xff; /* From previous iteration or start */ - b = *prev_row++; - - p = b - c; - pc = a - c; - -# ifdef PNG_USE_ABS - pa = abs(p); - pb = abs(pc); - pc = abs(p + pc); -# else - pa = p < 0 ? -p : p; - pb = pc < 0 ? -pc : pc; - pc = (p + pc) < 0 ? -(p + pc) : p + pc; -# endif - - /* Find the best predictor, the least of pa, pb, pc favoring the earlier - * ones in the case of a tie. - */ - if (pb < pa) pa = pb, a = b; - if (pc < pa) a = c; - - /* Calculate the current pixel in a, and move the previous row pixel to c - * for the next time round the loop - */ - c = b; - a += *row; - *row++ = (png_byte)a; - } -} - -static void -png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row, - png_const_bytep prev_row) -{ - int bpp = (row_info->pixel_depth + 7) >> 3; - png_bytep rp_end = row + bpp; - - /* Process the first pixel in the row completely (this is the same as 'up' - * because there is only one candidate predictor for the first row). - */ - while (row < rp_end) - { - int a = *row + *prev_row++; - *row++ = (png_byte)a; - } - - /* Remainder */ - rp_end += row_info->rowbytes - bpp; - - while (row < rp_end) - { - int a, b, c, pa, pb, pc, p; - - c = *(prev_row - bpp); - a = *(row - bpp); - b = *prev_row++; - - p = b - c; - pc = a - c; - -# ifdef PNG_USE_ABS - pa = abs(p); - pb = abs(pc); - pc = abs(p + pc); -# else - pa = p < 0 ? -p : p; - pb = pc < 0 ? -pc : pc; - pc = (p + pc) < 0 ? -(p + pc) : p + pc; -# endif - - if (pb < pa) pa = pb, a = b; - if (pc < pa) a = c; - - c = b; - a += *row; - *row++ = (png_byte)a; - } -} - -#ifdef PNG_ARM_NEON - -#ifdef __linux__ -#include -#include -#include - -static int png_have_hwcap(unsigned cap) -{ - FILE *f = fopen("/proc/self/auxv", "r"); - Elf32_auxv_t aux; - int have_cap = 0; - - if (!f) - return 0; - - while (fread(&aux, sizeof(aux), 1, f) > 0) - { - if (aux.a_type == AT_HWCAP && - aux.a_un.a_val & cap) - { - have_cap = 1; - break; - } - } - - fclose(f); - - return have_cap; -} -#endif /* __linux__ */ - -static void -png_init_filter_functions_neon(png_structp pp, unsigned int bpp) -{ -#ifdef __linux__ - if (!png_have_hwcap(HWCAP_NEON)) - return; -#endif - - pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon; - - if (bpp == 3) - { - pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_neon; - pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_neon; - pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = - png_read_filter_row_paeth3_neon; - } - - else if (bpp == 4) - { - pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_neon; - pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_neon; - pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = - png_read_filter_row_paeth4_neon; - } -} -#endif /* PNG_ARM_NEON */ - -static void -png_init_filter_functions(png_structp pp) -{ - unsigned int bpp = (pp->pixel_depth + 7) >> 3; - - pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub; - pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up; - pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg; - if (bpp == 1) - pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = - png_read_filter_row_paeth_1byte_pixel; - else - pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = - png_read_filter_row_paeth_multibyte_pixel; - -#ifdef PNG_ARM_NEON - png_init_filter_functions_neon(pp, bpp); -#endif -} - -void /* PRIVATE */ -png_read_filter_row(png_structp pp, png_row_infop row_info, png_bytep row, - png_const_bytep prev_row, int filter) -{ - if (pp->read_filter[0] == NULL) - png_init_filter_functions(pp); - if (filter > PNG_FILTER_VALUE_NONE && filter < PNG_FILTER_VALUE_LAST) - pp->read_filter[filter-1](row_info, row, prev_row); -} - -#ifdef PNG_SEQUENTIAL_READ_SUPPORTED -void /* PRIVATE */ -png_read_finish_row(png_structp png_ptr) -{ -#ifdef PNG_READ_INTERLACING_SUPPORTED - /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ - - /* Start of interlace block */ - static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; - - /* Offset to next interlace block */ - static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; - - /* Start of interlace block in the y direction */ - static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; - - /* Offset to next interlace block in the y direction */ - static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; -#endif /* PNG_READ_INTERLACING_SUPPORTED */ - - png_debug(1, "in png_read_finish_row"); - png_ptr->row_number++; - if (png_ptr->row_number < png_ptr->num_rows) - return; - -#ifdef PNG_READ_INTERLACING_SUPPORTED - if (png_ptr->interlaced) - { - png_ptr->row_number = 0; - - /* TO DO: don't do this if prev_row isn't needed (requires - * read-ahead of the next row's filter byte. - */ - png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); - - do - { - png_ptr->pass++; - - if (png_ptr->pass >= 7) - break; - - png_ptr->iwidth = (png_ptr->width + - png_pass_inc[png_ptr->pass] - 1 - - png_pass_start[png_ptr->pass]) / - png_pass_inc[png_ptr->pass]; - - if (!(png_ptr->transformations & PNG_INTERLACE)) - { - png_ptr->num_rows = (png_ptr->height + - png_pass_yinc[png_ptr->pass] - 1 - - png_pass_ystart[png_ptr->pass]) / - png_pass_yinc[png_ptr->pass]; - } - - else /* if (png_ptr->transformations & PNG_INTERLACE) */ - break; /* libpng deinterlacing sees every row */ - - } while (png_ptr->num_rows == 0 || png_ptr->iwidth == 0); - - if (png_ptr->pass < 7) - return; - } -#endif /* PNG_READ_INTERLACING_SUPPORTED */ - - if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) - { - char extra; - int ret; - - png_ptr->zstream.next_out = (Byte *)&extra; - png_ptr->zstream.avail_out = (uInt)1; - - for (;;) - { - if (!(png_ptr->zstream.avail_in)) - { - while (!png_ptr->idat_size) - { - png_crc_finish(png_ptr, 0); - png_ptr->idat_size = png_read_chunk_header(png_ptr); - if (png_ptr->chunk_name != png_IDAT) - png_error(png_ptr, "Not enough image data"); - } - - png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; - png_ptr->zstream.next_in = png_ptr->zbuf; - - if (png_ptr->zbuf_size > png_ptr->idat_size) - png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; - - png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in); - png_ptr->idat_size -= png_ptr->zstream.avail_in; - } - - ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); - - if (ret == Z_STREAM_END) - { - if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in || - png_ptr->idat_size) - png_warning(png_ptr, "Extra compressed data"); - - png_ptr->mode |= PNG_AFTER_IDAT; - png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; - break; - } - - if (ret != Z_OK) - png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg : - "Decompression Error"); - - if (!(png_ptr->zstream.avail_out)) - { - png_warning(png_ptr, "Extra compressed data"); - png_ptr->mode |= PNG_AFTER_IDAT; - png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; - break; - } - - } - png_ptr->zstream.avail_out = 0; - } - - if (png_ptr->idat_size || png_ptr->zstream.avail_in) - png_warning(png_ptr, "Extra compression data"); - - inflateReset(&png_ptr->zstream); - - png_ptr->mode |= PNG_AFTER_IDAT; -} -#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ - -void /* PRIVATE */ -png_read_start_row(png_structp png_ptr) -{ -#ifdef PNG_READ_INTERLACING_SUPPORTED - /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ - - /* Start of interlace block */ - static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; - - /* Offset to next interlace block */ - static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; - - /* Start of interlace block in the y direction */ - static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; - - /* Offset to next interlace block in the y direction */ - static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; -#endif - - int max_pixel_depth; - png_size_t row_bytes; - - png_debug(1, "in png_read_start_row"); - png_ptr->zstream.avail_in = 0; -#ifdef PNG_READ_TRANSFORMS_SUPPORTED - png_init_read_transformations(png_ptr); -#endif -#ifdef PNG_READ_INTERLACING_SUPPORTED - if (png_ptr->interlaced) - { - if (!(png_ptr->transformations & PNG_INTERLACE)) - png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - - png_pass_ystart[0]) / png_pass_yinc[0]; - - else - png_ptr->num_rows = png_ptr->height; - - png_ptr->iwidth = (png_ptr->width + - png_pass_inc[png_ptr->pass] - 1 - - png_pass_start[png_ptr->pass]) / - png_pass_inc[png_ptr->pass]; - } - - else -#endif /* PNG_READ_INTERLACING_SUPPORTED */ - { - png_ptr->num_rows = png_ptr->height; - png_ptr->iwidth = png_ptr->width; - } - - max_pixel_depth = png_ptr->pixel_depth; - - /* WARNING: * png_read_transform_info (pngrtran.c) performs a simpliar set of - * calculations to calculate the final pixel depth, then - * png_do_read_transforms actually does the transforms. This means that the - * code which effectively calculates this value is actually repeated in three - * separate places. They must all match. Innocent changes to the order of - * transformations can and will break libpng in a way that causes memory - * overwrites. - * - * TODO: fix this. - */ -#ifdef PNG_READ_PACK_SUPPORTED - if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8) - max_pixel_depth = 8; -#endif - -#ifdef PNG_READ_EXPAND_SUPPORTED - if (png_ptr->transformations & PNG_EXPAND) - { - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - { - if (png_ptr->num_trans) - max_pixel_depth = 32; - - else - max_pixel_depth = 24; - } - - else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) - { - if (max_pixel_depth < 8) - max_pixel_depth = 8; - - if (png_ptr->num_trans) - max_pixel_depth *= 2; - } - - else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) - { - if (png_ptr->num_trans) - { - max_pixel_depth *= 4; - max_pixel_depth /= 3; - } - } - } -#endif - -#ifdef PNG_READ_EXPAND_16_SUPPORTED - if (png_ptr->transformations & PNG_EXPAND_16) - { -# ifdef PNG_READ_EXPAND_SUPPORTED - /* In fact it is an error if it isn't supported, but checking is - * the safe way. - */ - if (png_ptr->transformations & PNG_EXPAND) - { - if (png_ptr->bit_depth < 16) - max_pixel_depth *= 2; - } - else -# endif - png_ptr->transformations &= ~PNG_EXPAND_16; - } -#endif - -#ifdef PNG_READ_FILLER_SUPPORTED - if (png_ptr->transformations & (PNG_FILLER)) - { - if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) - { - if (max_pixel_depth <= 8) - max_pixel_depth = 16; - - else - max_pixel_depth = 32; - } - - else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB || - png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - { - if (max_pixel_depth <= 32) - max_pixel_depth = 32; - - else - max_pixel_depth = 64; - } - } -#endif - -#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED - if (png_ptr->transformations & PNG_GRAY_TO_RGB) - { - if ( -#ifdef PNG_READ_EXPAND_SUPPORTED - (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) || -#endif -#ifdef PNG_READ_FILLER_SUPPORTED - (png_ptr->transformations & (PNG_FILLER)) || -#endif - png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - { - if (max_pixel_depth <= 16) - max_pixel_depth = 32; - - else - max_pixel_depth = 64; - } - - else - { - if (max_pixel_depth <= 8) - { - if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - max_pixel_depth = 32; - - else - max_pixel_depth = 24; - } - - else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - max_pixel_depth = 64; - - else - max_pixel_depth = 48; - } - } -#endif - -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \ -defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) - if (png_ptr->transformations & PNG_USER_TRANSFORM) - { - int user_pixel_depth = png_ptr->user_transform_depth * - png_ptr->user_transform_channels; - - if (user_pixel_depth > max_pixel_depth) - max_pixel_depth = user_pixel_depth; - } -#endif - - /* This value is stored in png_struct and double checked in the row read - * code. - */ - png_ptr->maximum_pixel_depth = (png_byte)max_pixel_depth; - png_ptr->transformed_pixel_depth = 0; /* calculated on demand */ - - /* Align the width on the next larger 8 pixels. Mainly used - * for interlacing - */ - row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7)); - /* Calculate the maximum bytes needed, adding a byte and a pixel - * for safety's sake - */ - row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) + - 1 + ((max_pixel_depth + 7) >> 3); - -#ifdef PNG_MAX_MALLOC_64K - if (row_bytes > (png_uint_32)65536L) - png_error(png_ptr, "This image requires a row greater than 64KB"); -#endif - - if (row_bytes + 48 > png_ptr->old_big_row_buf_size) - { - png_free(png_ptr, png_ptr->big_row_buf); - png_free(png_ptr, png_ptr->big_prev_row); - - if (png_ptr->interlaced) - png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr, - row_bytes + 48); - - else - png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48); - - png_ptr->big_prev_row = (png_bytep)png_malloc(png_ptr, row_bytes + 48); - -#ifdef PNG_ALIGNED_MEMORY_SUPPORTED - /* Use 16-byte aligned memory for row_buf with at least 16 bytes - * of padding before and after row_buf; treat prev_row similarly. - * NOTE: the alignment is to the start of the pixels, one beyond the start - * of the buffer, because of the filter byte. Prior to libpng 1.5.6 this - * was incorrect; the filter byte was aligned, which had the exact - * opposite effect of that intended. - */ - { - png_bytep temp = png_ptr->big_row_buf + 32; - int extra = (int)((temp - (png_bytep)0) & 0x0f); - png_ptr->row_buf = temp - extra - 1/*filter byte*/; - - temp = png_ptr->big_prev_row + 32; - extra = (int)((temp - (png_bytep)0) & 0x0f); - png_ptr->prev_row = temp - extra - 1/*filter byte*/; - } - -#else - /* Use 31 bytes of padding before and 17 bytes after row_buf. */ - png_ptr->row_buf = png_ptr->big_row_buf + 31; - png_ptr->prev_row = png_ptr->big_prev_row + 31; -#endif - png_ptr->old_big_row_buf_size = row_bytes + 48; - } - -#ifdef PNG_MAX_MALLOC_64K - if (png_ptr->rowbytes > 65535) - png_error(png_ptr, "This image requires a row greater than 64KB"); - -#endif - if (png_ptr->rowbytes > (PNG_SIZE_MAX - 1)) - png_error(png_ptr, "Row has too many bytes to allocate in memory"); - - png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); - - png_debug1(3, "width = %u,", png_ptr->width); - png_debug1(3, "height = %u,", png_ptr->height); - png_debug1(3, "iwidth = %u,", png_ptr->iwidth); - png_debug1(3, "num_rows = %u,", png_ptr->num_rows); - png_debug1(3, "rowbytes = %lu,", (unsigned long)png_ptr->rowbytes); - png_debug1(3, "irowbytes = %lu", - (unsigned long)PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1); - - png_ptr->flags |= PNG_FLAG_ROW_INIT; -} -#endif /* PNG_READ_SUPPORTED */ + +/* pngrutil.c - utilities to read a PNG file + * + * Last changed in libpng 1.5.10 [March 8, 2012] + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file contains routines that are only called from within + * libpng itself during the course of reading an image. + */ + +#include "pngpriv.h" + +#ifdef PNG_READ_SUPPORTED + +#define png_strtod(p,a,b) strtod(a,b) + +png_uint_32 PNGAPI +png_get_uint_31(png_structp png_ptr, png_const_bytep buf) +{ + png_uint_32 uval = png_get_uint_32(buf); + + if (uval > PNG_UINT_31_MAX) + png_error(png_ptr, "PNG unsigned integer out of range"); + + return (uval); +} + +#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_READ_cHRM_SUPPORTED) +/* The following is a variation on the above for use with the fixed + * point values used for gAMA and cHRM. Instead of png_error it + * issues a warning and returns (-1) - an invalid value because both + * gAMA and cHRM use *unsigned* integers for fixed point values. + */ +#define PNG_FIXED_ERROR (-1) + +static png_fixed_point /* PRIVATE */ +png_get_fixed_point(png_structp png_ptr, png_const_bytep buf) +{ + png_uint_32 uval = png_get_uint_32(buf); + + if (uval <= PNG_UINT_31_MAX) + return (png_fixed_point)uval; /* known to be in range */ + + /* The caller can turn off the warning by passing NULL. */ + if (png_ptr != NULL) + png_warning(png_ptr, "PNG fixed point integer out of range"); + + return PNG_FIXED_ERROR; +} +#endif + +#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED +/* NOTE: the read macros will obscure these definitions, so that if + * PNG_USE_READ_MACROS is set the library will not use them internally, + * but the APIs will still be available externally. + * + * The parentheses around "PNGAPI function_name" in the following three + * functions are necessary because they allow the macros to co-exist with + * these (unused but exported) functions. + */ + +/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */ +png_uint_32 (PNGAPI +png_get_uint_32)(png_const_bytep buf) +{ + png_uint_32 uval = + ((png_uint_32)(*(buf )) << 24) + + ((png_uint_32)(*(buf + 1)) << 16) + + ((png_uint_32)(*(buf + 2)) << 8) + + ((png_uint_32)(*(buf + 3)) ) ; + + return uval; +} + +/* Grab a signed 32-bit integer from a buffer in big-endian format. The + * data is stored in the PNG file in two's complement format and there + * is no guarantee that a 'png_int_32' is exactly 32 bits, therefore + * the following code does a two's complement to native conversion. + */ +png_int_32 (PNGAPI +png_get_int_32)(png_const_bytep buf) +{ + png_uint_32 uval = png_get_uint_32(buf); + if ((uval & 0x80000000) == 0) /* non-negative */ + return uval; + + uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */ + return -(png_int_32)uval; +} + +/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */ +png_uint_16 (PNGAPI +png_get_uint_16)(png_const_bytep buf) +{ + /* ANSI-C requires an int value to accomodate at least 16 bits so this + * works and allows the compiler not to worry about possible narrowing + * on 32 bit systems. (Pre-ANSI systems did not make integers smaller + * than 16 bits either.) + */ + unsigned int val = + ((unsigned int)(*buf) << 8) + + ((unsigned int)(*(buf + 1))); + + return (png_uint_16)val; +} + +#endif /* PNG_READ_INT_FUNCTIONS_SUPPORTED */ + +/* Read and check the PNG file signature */ +void /* PRIVATE */ +png_read_sig(png_structp png_ptr, png_infop info_ptr) +{ + png_size_t num_checked, num_to_check; + + /* Exit if the user application does not expect a signature. */ + if (png_ptr->sig_bytes >= 8) + return; + + num_checked = png_ptr->sig_bytes; + num_to_check = 8 - num_checked; + +#ifdef PNG_IO_STATE_SUPPORTED + png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE; +#endif + + /* The signature must be serialized in a single I/O call. */ + png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check); + png_ptr->sig_bytes = 8; + + if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) + { + if (num_checked < 4 && + png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) + png_error(png_ptr, "Not a PNG file"); + else + png_error(png_ptr, "PNG file corrupted by ASCII conversion"); + } + if (num_checked < 3) + png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; +} + +/* Read the chunk header (length + type name). + * Put the type name into png_ptr->chunk_name, and return the length. + */ +png_uint_32 /* PRIVATE */ +png_read_chunk_header(png_structp png_ptr) +{ + png_byte buf[8]; + png_uint_32 length; + +#ifdef PNG_IO_STATE_SUPPORTED + png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_HDR; +#endif + + /* Read the length and the chunk name. + * This must be performed in a single I/O call. + */ + png_read_data(png_ptr, buf, 8); + length = png_get_uint_31(png_ptr, buf); + + /* Put the chunk name into png_ptr->chunk_name. */ + png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(buf+4); + + png_debug2(0, "Reading %lx chunk, length = %lu", + (unsigned long)png_ptr->chunk_name, (unsigned long)length); + + /* Reset the crc and run it over the chunk name. */ + png_reset_crc(png_ptr); + png_calculate_crc(png_ptr, buf + 4, 4); + + /* Check to see if chunk name is valid. */ + png_check_chunk_name(png_ptr, png_ptr->chunk_name); + +#ifdef PNG_IO_STATE_SUPPORTED + png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA; +#endif + + return length; +} + +/* Read data, and (optionally) run it through the CRC. */ +void /* PRIVATE */ +png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length) +{ + if (png_ptr == NULL) + return; + + png_read_data(png_ptr, buf, length); + png_calculate_crc(png_ptr, buf, length); +} + +/* Optionally skip data and then check the CRC. Depending on whether we + * are reading a ancillary or critical chunk, and how the program has set + * things up, we may calculate the CRC on the data and print a message. + * Returns '1' if there was a CRC error, '0' otherwise. + */ +int /* PRIVATE */ +png_crc_finish(png_structp png_ptr, png_uint_32 skip) +{ + png_size_t i; + png_size_t istop = png_ptr->zbuf_size; + + for (i = (png_size_t)skip; i > istop; i -= istop) + { + png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); + } + + if (i) + { + png_crc_read(png_ptr, png_ptr->zbuf, i); + } + + if (png_crc_error(png_ptr)) + { + if (PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name) ? + !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) : + (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)) + { + png_chunk_warning(png_ptr, "CRC error"); + } + + else + { + png_chunk_benign_error(png_ptr, "CRC error"); + return (0); + } + + return (1); + } + + return (0); +} + +/* Compare the CRC stored in the PNG file with that calculated by libpng from + * the data it has read thus far. + */ +int /* PRIVATE */ +png_crc_error(png_structp png_ptr) +{ + png_byte crc_bytes[4]; + png_uint_32 crc; + int need_crc = 1; + + if (PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name)) + { + if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) == + (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN)) + need_crc = 0; + } + + else /* critical */ + { + if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) + need_crc = 0; + } + +#ifdef PNG_IO_STATE_SUPPORTED + png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_CRC; +#endif + + /* The chunk CRC must be serialized in a single I/O call. */ + png_read_data(png_ptr, crc_bytes, 4); + + if (need_crc) + { + crc = png_get_uint_32(crc_bytes); + return ((int)(crc != png_ptr->crc)); + } + + else + return (0); +} + +#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED +static png_size_t +png_inflate(png_structp png_ptr, png_bytep data, png_size_t size, + png_bytep output, png_size_t output_size) +{ + png_size_t count = 0; + + /* zlib can't necessarily handle more than 65535 bytes at once (i.e. it can't + * even necessarily handle 65536 bytes) because the type uInt is "16 bits or + * more". Consequently it is necessary to chunk the input to zlib. This + * code uses ZLIB_IO_MAX, from pngpriv.h, as the maximum (the maximum value + * that can be stored in a uInt.) It is possible to set ZLIB_IO_MAX to a + * lower value in pngpriv.h and this may sometimes have a performance + * advantage, because it forces access of the input data to be separated from + * at least some of the use by some period of time. + */ + png_ptr->zstream.next_in = data; + /* avail_in is set below from 'size' */ + png_ptr->zstream.avail_in = 0; + + while (1) + { + int ret, avail; + + /* The setting of 'avail_in' used to be outside the loop; by setting it + * inside it is possible to chunk the input to zlib and simply rely on + * zlib to advance the 'next_in' pointer. This allows arbitrary amounts o + * data to be passed through zlib at the unavoidable cost of requiring a + * window save (memcpy of up to 32768 output bytes) every ZLIB_IO_MAX + * input bytes. + */ + if (png_ptr->zstream.avail_in == 0 && size > 0) + { + if (size <= ZLIB_IO_MAX) + { + /* The value is less than ZLIB_IO_MAX so the cast is safe: */ + png_ptr->zstream.avail_in = (uInt)size; + size = 0; + } + + else + { + png_ptr->zstream.avail_in = ZLIB_IO_MAX; + size -= ZLIB_IO_MAX; + } + } + + /* Reset the output buffer each time round - we empty it + * after every inflate call. + */ + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = png_ptr->zbuf_size; + + ret = inflate(&png_ptr->zstream, Z_NO_FLUSH); + avail = png_ptr->zbuf_size - png_ptr->zstream.avail_out; + + /* First copy/count any new output - but only if we didn't + * get an error code. + */ + if ((ret == Z_OK || ret == Z_STREAM_END) && avail > 0) + { + png_size_t space = avail; /* > 0, see above */ + + if (output != 0 && output_size > count) + { + png_size_t copy = output_size - count; + + if (space < copy) + copy = space; + + png_memcpy(output + count, png_ptr->zbuf, copy); + } + count += space; + } + + if (ret == Z_OK) + continue; + + /* Termination conditions - always reset the zstream, it + * must be left in inflateInit state. + */ + png_ptr->zstream.avail_in = 0; + inflateReset(&png_ptr->zstream); + + if (ret == Z_STREAM_END) + return count; /* NOTE: may be zero. */ + + /* Now handle the error codes - the API always returns 0 + * and the error message is dumped into the uncompressed + * buffer if available. + */ +# ifdef PNG_WARNINGS_SUPPORTED + { + png_const_charp msg; + + if (png_ptr->zstream.msg != 0) + msg = png_ptr->zstream.msg; + + else switch (ret) + { + case Z_BUF_ERROR: + msg = "Buffer error in compressed datastream"; + break; + + case Z_DATA_ERROR: + msg = "Data error in compressed datastream"; + break; + + default: + msg = "Incomplete compressed datastream"; + break; + } + + png_chunk_warning(png_ptr, msg); + } +# endif + + /* 0 means an error - notice that this code simply ignores + * zero length compressed chunks as a result. + */ + return 0; + } +} + +/* + * Decompress trailing data in a chunk. The assumption is that chunkdata + * points at an allocated area holding the contents of a chunk with a + * trailing compressed part. What we get back is an allocated area + * holding the original prefix part and an uncompressed version of the + * trailing part (the malloc area passed in is freed). + */ +void /* PRIVATE */ +png_decompress_chunk(png_structp png_ptr, int comp_type, + png_size_t chunklength, + png_size_t prefix_size, png_size_t *newlength) +{ + /* The caller should guarantee this */ + if (prefix_size > chunklength) + { + /* The recovery is to delete the chunk. */ + png_warning(png_ptr, "invalid chunklength"); + prefix_size = 0; /* To delete everything */ + } + + else if (comp_type == PNG_COMPRESSION_TYPE_BASE) + { + png_size_t expanded_size = png_inflate(png_ptr, + (png_bytep)(png_ptr->chunkdata + prefix_size), + chunklength - prefix_size, + 0, /* output */ + 0); /* output size */ + + /* Now check the limits on this chunk - if the limit fails the + * compressed data will be removed, the prefix will remain. + */ + if (prefix_size >= (~(png_size_t)0) - 1 || + expanded_size >= (~(png_size_t)0) - 1 - prefix_size +#ifdef PNG_USER_LIMITS_SUPPORTED + || (png_ptr->user_chunk_malloc_max && + (prefix_size + expanded_size >= png_ptr->user_chunk_malloc_max - 1)) +#else + || ((PNG_USER_CHUNK_MALLOC_MAX > 0) && + prefix_size + expanded_size >= PNG_USER_CHUNK_MALLOC_MAX - 1) +#endif + ) + png_warning(png_ptr, "Exceeded size limit while expanding chunk"); + + /* If the size is zero either there was an error and a message + * has already been output (warning) or the size really is zero + * and we have nothing to do - the code will exit through the + * error case below. + */ + else if (expanded_size > 0) + { + /* Success (maybe) - really uncompress the chunk. */ + png_size_t new_size = 0; + png_charp text = (png_charp)png_malloc_warn(png_ptr, + prefix_size + expanded_size + 1); + + if (text != NULL) + { + png_memcpy(text, png_ptr->chunkdata, prefix_size); + new_size = png_inflate(png_ptr, + (png_bytep)(png_ptr->chunkdata + prefix_size), + chunklength - prefix_size, + (png_bytep)(text + prefix_size), expanded_size); + text[prefix_size + expanded_size] = 0; /* just in case */ + + if (new_size == expanded_size) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = text; + *newlength = prefix_size + expanded_size; + return; /* The success return! */ + } + + png_warning(png_ptr, "png_inflate logic error"); + png_free(png_ptr, text); + } + + else + png_warning(png_ptr, "Not enough memory to decompress chunk"); + } + } + + else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */ + { + PNG_WARNING_PARAMETERS(p) + png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, comp_type); + png_formatted_warning(png_ptr, p, "Unknown compression type @1"); + + /* The recovery is to simply drop the data. */ + } + + /* Generic error return - leave the prefix, delete the compressed + * data, reallocate the chunkdata to remove the potentially large + * amount of compressed data. + */ + { + png_charp text = (png_charp)png_malloc_warn(png_ptr, prefix_size + 1); + + if (text != NULL) + { + if (prefix_size > 0) + png_memcpy(text, png_ptr->chunkdata, prefix_size); + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = text; + + /* This is an extra zero in the 'uncompressed' part. */ + *(png_ptr->chunkdata + prefix_size) = 0x00; + } + /* Ignore a malloc error here - it is safe. */ + } + + *newlength = prefix_size; +} +#endif /* PNG_READ_COMPRESSED_TEXT_SUPPORTED */ + +/* Read and check the IDHR chunk */ +void /* PRIVATE */ +png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[13]; + png_uint_32 width, height; + int bit_depth, color_type, compression_type, filter_type; + int interlace_type; + + png_debug(1, "in png_handle_IHDR"); + + if (png_ptr->mode & PNG_HAVE_IHDR) + png_error(png_ptr, "Out of place IHDR"); + + /* Check the length */ + if (length != 13) + png_error(png_ptr, "Invalid IHDR chunk"); + + png_ptr->mode |= PNG_HAVE_IHDR; + + png_crc_read(png_ptr, buf, 13); + png_crc_finish(png_ptr, 0); + + width = png_get_uint_31(png_ptr, buf); + height = png_get_uint_31(png_ptr, buf + 4); + bit_depth = buf[8]; + color_type = buf[9]; + compression_type = buf[10]; + filter_type = buf[11]; + interlace_type = buf[12]; + + /* Set internal variables */ + png_ptr->width = width; + png_ptr->height = height; + png_ptr->bit_depth = (png_byte)bit_depth; + png_ptr->interlaced = (png_byte)interlace_type; + png_ptr->color_type = (png_byte)color_type; +#ifdef PNG_MNG_FEATURES_SUPPORTED + png_ptr->filter_type = (png_byte)filter_type; +#endif + png_ptr->compression_type = (png_byte)compression_type; + + /* Find number of channels */ + switch (png_ptr->color_type) + { + default: /* invalid, png_set_IHDR calls png_error */ + case PNG_COLOR_TYPE_GRAY: + case PNG_COLOR_TYPE_PALETTE: + png_ptr->channels = 1; + break; + + case PNG_COLOR_TYPE_RGB: + png_ptr->channels = 3; + break; + + case PNG_COLOR_TYPE_GRAY_ALPHA: + png_ptr->channels = 2; + break; + + case PNG_COLOR_TYPE_RGB_ALPHA: + png_ptr->channels = 4; + break; + } + + /* Set up other useful info */ + png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * + png_ptr->channels); + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width); + png_debug1(3, "bit_depth = %d", png_ptr->bit_depth); + png_debug1(3, "channels = %d", png_ptr->channels); + png_debug1(3, "rowbytes = %lu", (unsigned long)png_ptr->rowbytes); + png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, + color_type, interlace_type, compression_type, filter_type); +} + +/* Read and check the palette */ +void /* PRIVATE */ +png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_color palette[PNG_MAX_PALETTE_LENGTH]; + int num, i; +#ifdef PNG_POINTER_INDEXING_SUPPORTED + png_colorp pal_ptr; +#endif + + png_debug(1, "in png_handle_PLTE"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before PLTE"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid PLTE after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + + else if (png_ptr->mode & PNG_HAVE_PLTE) + png_error(png_ptr, "Duplicate PLTE chunk"); + + png_ptr->mode |= PNG_HAVE_PLTE; + + if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) + { + png_warning(png_ptr, + "Ignoring PLTE chunk in grayscale PNG"); + png_crc_finish(png_ptr, length); + return; + } + +#ifndef PNG_READ_OPT_PLTE_SUPPORTED + if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) + { + png_crc_finish(png_ptr, length); + return; + } +#endif + + if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3) + { + if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) + { + png_warning(png_ptr, "Invalid palette chunk"); + png_crc_finish(png_ptr, length); + return; + } + + else + { + png_error(png_ptr, "Invalid palette chunk"); + } + } + + num = (int)length / 3; + +#ifdef PNG_POINTER_INDEXING_SUPPORTED + for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++) + { + png_byte buf[3]; + + png_crc_read(png_ptr, buf, 3); + pal_ptr->red = buf[0]; + pal_ptr->green = buf[1]; + pal_ptr->blue = buf[2]; + } +#else + for (i = 0; i < num; i++) + { + png_byte buf[3]; + + png_crc_read(png_ptr, buf, 3); + /* Don't depend upon png_color being any order */ + palette[i].red = buf[0]; + palette[i].green = buf[1]; + palette[i].blue = buf[2]; + } +#endif + + /* If we actually need the PLTE chunk (ie for a paletted image), we do + * whatever the normal CRC configuration tells us. However, if we + * have an RGB image, the PLTE can be considered ancillary, so + * we will act as though it is. + */ +#ifndef PNG_READ_OPT_PLTE_SUPPORTED + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) +#endif + { + png_crc_finish(png_ptr, 0); + } + +#ifndef PNG_READ_OPT_PLTE_SUPPORTED + else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */ + { + /* If we don't want to use the data from an ancillary chunk, + * we have two options: an error abort, or a warning and we + * ignore the data in this chunk (which should be OK, since + * it's considered ancillary for a RGB or RGBA image). + */ + if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE)) + { + if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) + { + png_chunk_benign_error(png_ptr, "CRC error"); + } + + else + { + png_chunk_warning(png_ptr, "CRC error"); + return; + } + } + + /* Otherwise, we (optionally) emit a warning and use the chunk. */ + else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) + { + png_chunk_warning(png_ptr, "CRC error"); + } + } +#endif + + png_set_PLTE(png_ptr, info_ptr, palette, num); + +#ifdef PNG_READ_tRNS_SUPPORTED + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) + { + if (png_ptr->num_trans > (png_uint_16)num) + { + png_warning(png_ptr, "Truncating incorrect tRNS chunk length"); + png_ptr->num_trans = (png_uint_16)num; + } + + if (info_ptr->num_trans > (png_uint_16)num) + { + png_warning(png_ptr, "Truncating incorrect info tRNS chunk length"); + info_ptr->num_trans = (png_uint_16)num; + } + } + } +#endif + +} + +void /* PRIVATE */ +png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_debug(1, "in png_handle_IEND"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT)) + { + png_error(png_ptr, "No image in file"); + } + + png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND); + + if (length != 0) + { + png_warning(png_ptr, "Incorrect IEND chunk length"); + } + + png_crc_finish(png_ptr, length); + + PNG_UNUSED(info_ptr) /* Quiet compiler warnings about unused info_ptr */ +} + +#ifdef PNG_READ_gAMA_SUPPORTED +void /* PRIVATE */ +png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_fixed_point igamma; + png_byte buf[4]; + + png_debug(1, "in png_handle_gAMA"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before gAMA"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid gAMA after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + + else if (png_ptr->mode & PNG_HAVE_PLTE) + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Out of place gAMA chunk"); + + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) +#ifdef PNG_READ_sRGB_SUPPORTED + && !(info_ptr->valid & PNG_INFO_sRGB) +#endif + ) + { + png_warning(png_ptr, "Duplicate gAMA chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 4) + { + png_warning(png_ptr, "Incorrect gAMA chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 4); + + if (png_crc_finish(png_ptr, 0)) + return; + + igamma = png_get_fixed_point(NULL, buf); + + /* Check for zero gamma or an error. */ + if (igamma <= 0) + { + png_warning(png_ptr, + "Ignoring gAMA chunk with out of range gamma"); + + return; + } + +# ifdef PNG_READ_sRGB_SUPPORTED + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) + { + if (PNG_OUT_OF_RANGE(igamma, 45500, 500)) + { + PNG_WARNING_PARAMETERS(p) + png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed, igamma); + png_formatted_warning(png_ptr, p, + "Ignoring incorrect gAMA value @1 when sRGB is also present"); + return; + } + } +# endif /* PNG_READ_sRGB_SUPPORTED */ + +# ifdef PNG_READ_GAMMA_SUPPORTED + /* Gamma correction on read is supported. */ + png_ptr->gamma = igamma; +# endif + /* And set the 'info' structure members. */ + png_set_gAMA_fixed(png_ptr, info_ptr, igamma); +} +#endif + +#ifdef PNG_READ_sBIT_SUPPORTED +void /* PRIVATE */ +png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_size_t truelen; + png_byte buf[4]; + + png_debug(1, "in png_handle_sBIT"); + + buf[0] = buf[1] = buf[2] = buf[3] = 0; + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before sBIT"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid sBIT after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + + else if (png_ptr->mode & PNG_HAVE_PLTE) + { + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Out of place sBIT chunk"); + } + + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)) + { + png_warning(png_ptr, "Duplicate sBIT chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + truelen = 3; + + else + truelen = (png_size_t)png_ptr->channels; + + if (length != truelen || length > 4) + { + png_warning(png_ptr, "Incorrect sBIT chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, truelen); + + if (png_crc_finish(png_ptr, 0)) + return; + + if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) + { + png_ptr->sig_bit.red = buf[0]; + png_ptr->sig_bit.green = buf[1]; + png_ptr->sig_bit.blue = buf[2]; + png_ptr->sig_bit.alpha = buf[3]; + } + + else + { + png_ptr->sig_bit.gray = buf[0]; + png_ptr->sig_bit.red = buf[0]; + png_ptr->sig_bit.green = buf[0]; + png_ptr->sig_bit.blue = buf[0]; + png_ptr->sig_bit.alpha = buf[1]; + } + + png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit)); +} +#endif + +#ifdef PNG_READ_cHRM_SUPPORTED +void /* PRIVATE */ +png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[32]; + png_fixed_point x_white, y_white, x_red, y_red, x_green, y_green, x_blue, + y_blue; + + png_debug(1, "in png_handle_cHRM"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before cHRM"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid cHRM after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + + else if (png_ptr->mode & PNG_HAVE_PLTE) + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Out of place cHRM chunk"); + + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM) +# ifdef PNG_READ_sRGB_SUPPORTED + && !(info_ptr->valid & PNG_INFO_sRGB) +# endif + ) + { + png_warning(png_ptr, "Duplicate cHRM chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 32) + { + png_warning(png_ptr, "Incorrect cHRM chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 32); + + if (png_crc_finish(png_ptr, 0)) + return; + + x_white = png_get_fixed_point(NULL, buf); + y_white = png_get_fixed_point(NULL, buf + 4); + x_red = png_get_fixed_point(NULL, buf + 8); + y_red = png_get_fixed_point(NULL, buf + 12); + x_green = png_get_fixed_point(NULL, buf + 16); + y_green = png_get_fixed_point(NULL, buf + 20); + x_blue = png_get_fixed_point(NULL, buf + 24); + y_blue = png_get_fixed_point(NULL, buf + 28); + + if (x_white == PNG_FIXED_ERROR || + y_white == PNG_FIXED_ERROR || + x_red == PNG_FIXED_ERROR || + y_red == PNG_FIXED_ERROR || + x_green == PNG_FIXED_ERROR || + y_green == PNG_FIXED_ERROR || + x_blue == PNG_FIXED_ERROR || + y_blue == PNG_FIXED_ERROR) + { + png_warning(png_ptr, "Ignoring cHRM chunk with negative chromaticities"); + return; + } + +#ifdef PNG_READ_sRGB_SUPPORTED + if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB)) + { + if (PNG_OUT_OF_RANGE(x_white, 31270, 1000) || + PNG_OUT_OF_RANGE(y_white, 32900, 1000) || + PNG_OUT_OF_RANGE(x_red, 64000, 1000) || + PNG_OUT_OF_RANGE(y_red, 33000, 1000) || + PNG_OUT_OF_RANGE(x_green, 30000, 1000) || + PNG_OUT_OF_RANGE(y_green, 60000, 1000) || + PNG_OUT_OF_RANGE(x_blue, 15000, 1000) || + PNG_OUT_OF_RANGE(y_blue, 6000, 1000)) + { + PNG_WARNING_PARAMETERS(p) + + png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed, x_white); + png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_fixed, y_white); + png_warning_parameter_signed(p, 3, PNG_NUMBER_FORMAT_fixed, x_red); + png_warning_parameter_signed(p, 4, PNG_NUMBER_FORMAT_fixed, y_red); + png_warning_parameter_signed(p, 5, PNG_NUMBER_FORMAT_fixed, x_green); + png_warning_parameter_signed(p, 6, PNG_NUMBER_FORMAT_fixed, y_green); + png_warning_parameter_signed(p, 7, PNG_NUMBER_FORMAT_fixed, x_blue); + png_warning_parameter_signed(p, 8, PNG_NUMBER_FORMAT_fixed, y_blue); + + png_formatted_warning(png_ptr, p, + "Ignoring incorrect cHRM white(@1,@2) r(@3,@4)g(@5,@6)b(@7,@8) " + "when sRGB is also present"); + } + return; + } +#endif /* PNG_READ_sRGB_SUPPORTED */ + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + /* Store the _white values as default coefficients for the rgb to gray + * operation if it is supported. Check if the transform is already set to + * avoid destroying the transform values. + */ + if (!png_ptr->rgb_to_gray_coefficients_set) + { + /* png_set_background has not been called and we haven't seen an sRGB + * chunk yet. Find the XYZ of the three end points. + */ + png_XYZ XYZ; + png_xy xy; + + xy.redx = x_red; + xy.redy = y_red; + xy.greenx = x_green; + xy.greeny = y_green; + xy.bluex = x_blue; + xy.bluey = y_blue; + xy.whitex = x_white; + xy.whitey = y_white; + + if (png_XYZ_from_xy_checked(png_ptr, &XYZ, xy)) + { + /* The success case, because XYZ_from_xy normalises to a reference + * white Y of 1.0 we just need to scale the numbers. This should + * always work just fine. It is an internal error if this overflows. + */ + { + png_fixed_point r, g, b; + if (png_muldiv(&r, XYZ.redY, 32768, PNG_FP_1) && + r >= 0 && r <= 32768 && + png_muldiv(&g, XYZ.greenY, 32768, PNG_FP_1) && + g >= 0 && g <= 32768 && + png_muldiv(&b, XYZ.blueY, 32768, PNG_FP_1) && + b >= 0 && b <= 32768 && + r+g+b <= 32769) + { + /* We allow 0 coefficients here. r+g+b may be 32769 if two or + * all of the coefficients were rounded up. Handle this by + * reducing the *largest* coefficient by 1; this matches the + * approach used for the default coefficients in pngrtran.c + */ + int add = 0; + + if (r+g+b > 32768) + add = -1; + else if (r+g+b < 32768) + add = 1; + + if (add != 0) + { + if (g >= r && g >= b) + g += add; + else if (r >= g && r >= b) + r += add; + else + b += add; + } + + /* Check for an internal error. */ + if (r+g+b != 32768) + png_error(png_ptr, + "internal error handling cHRM coefficients"); + + png_ptr->rgb_to_gray_red_coeff = (png_uint_16)r; + png_ptr->rgb_to_gray_green_coeff = (png_uint_16)g; + } + + /* This is a png_error at present even though it could be ignored - + * it should never happen, but it is important that if it does, the + * bug is fixed. + */ + else + png_error(png_ptr, "internal error handling cHRM->XYZ"); + } + } + } +#endif + + png_set_cHRM_fixed(png_ptr, info_ptr, x_white, y_white, x_red, y_red, + x_green, y_green, x_blue, y_blue); +} +#endif + +#ifdef PNG_READ_sRGB_SUPPORTED +void /* PRIVATE */ +png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + int intent; + png_byte buf[1]; + + png_debug(1, "in png_handle_sRGB"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before sRGB"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid sRGB after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + + else if (png_ptr->mode & PNG_HAVE_PLTE) + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Out of place sRGB chunk"); + + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) + { + png_warning(png_ptr, "Duplicate sRGB chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 1) + { + png_warning(png_ptr, "Incorrect sRGB chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 1); + + if (png_crc_finish(png_ptr, 0)) + return; + + intent = buf[0]; + + /* Check for bad intent */ + if (intent >= PNG_sRGB_INTENT_LAST) + { + png_warning(png_ptr, "Unknown sRGB intent"); + return; + } + +#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)) + { + if (PNG_OUT_OF_RANGE(info_ptr->gamma, 45500, 500)) + { + PNG_WARNING_PARAMETERS(p) + + png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed, + info_ptr->gamma); + + png_formatted_warning(png_ptr, p, + "Ignoring incorrect gAMA value @1 when sRGB is also present"); + } + } +#endif /* PNG_READ_gAMA_SUPPORTED */ + +#ifdef PNG_READ_cHRM_SUPPORTED + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) + if (PNG_OUT_OF_RANGE(info_ptr->x_white, 31270, 1000) || + PNG_OUT_OF_RANGE(info_ptr->y_white, 32900, 1000) || + PNG_OUT_OF_RANGE(info_ptr->x_red, 64000, 1000) || + PNG_OUT_OF_RANGE(info_ptr->y_red, 33000, 1000) || + PNG_OUT_OF_RANGE(info_ptr->x_green, 30000, 1000) || + PNG_OUT_OF_RANGE(info_ptr->y_green, 60000, 1000) || + PNG_OUT_OF_RANGE(info_ptr->x_blue, 15000, 1000) || + PNG_OUT_OF_RANGE(info_ptr->y_blue, 6000, 1000)) + { + png_warning(png_ptr, + "Ignoring incorrect cHRM value when sRGB is also present"); + } +#endif /* PNG_READ_cHRM_SUPPORTED */ + + /* This is recorded for use when handling the cHRM chunk above. An sRGB + * chunk unconditionally overwrites the coefficients for grayscale conversion + * too. + */ + png_ptr->is_sRGB = 1; + +# ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + /* Don't overwrite user supplied values: */ + if (!png_ptr->rgb_to_gray_coefficients_set) + { + /* These numbers come from the sRGB specification (or, since one has to + * pay much money to get a copy, the wikipedia sRGB page) the + * chromaticity values quoted have been inverted to get the reverse + * transformation from RGB to XYZ and the 'Y' coefficients scaled by + * 32768 (then rounded). + * + * sRGB and ITU Rec-709 both truncate the values for the D65 white + * point to four digits and, even though it actually stores five + * digits, the PNG spec gives the truncated value. + * + * This means that when the chromaticities are converted back to XYZ + * end points we end up with (6968,23435,2366), which, as described in + * pngrtran.c, would overflow. If the five digit precision and up is + * used we get, instead: + * + * 6968*R + 23435*G + 2365*B + * + * (Notice that this rounds the blue coefficient down, rather than the + * choice used in pngrtran.c which is to round the green one down.) + */ + png_ptr->rgb_to_gray_red_coeff = 6968; /* 0.212639005871510 */ + png_ptr->rgb_to_gray_green_coeff = 23434; /* 0.715168678767756 */ + /* png_ptr->rgb_to_gray_blue_coeff = 2366; 0.072192315360734 */ + + /* The following keeps the cHRM chunk from destroying the + * coefficients again in the event that it follows the sRGB chunk. + */ + png_ptr->rgb_to_gray_coefficients_set = 1; + } +# endif + + png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent); +} +#endif /* PNG_READ_sRGB_SUPPORTED */ + +#ifdef PNG_READ_iCCP_SUPPORTED +void /* PRIVATE */ +png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +/* Note: this does not properly handle chunks that are > 64K under DOS */ +{ + png_byte compression_type; + png_bytep pC; + png_charp profile; + png_uint_32 skip = 0; + png_uint_32 profile_size; + png_alloc_size_t profile_length; + png_size_t slength, prefix_length, data_length; + + png_debug(1, "in png_handle_iCCP"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before iCCP"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid iCCP after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + + else if (png_ptr->mode & PNG_HAVE_PLTE) + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Out of place iCCP chunk"); + + if ((png_ptr->mode & PNG_HAVE_iCCP) || (info_ptr != NULL && + (info_ptr->valid & (PNG_INFO_iCCP|PNG_INFO_sRGB)))) + { + png_warning(png_ptr, "Duplicate iCCP chunk"); + png_crc_finish(png_ptr, length); + return; + } + + png_ptr->mode |= PNG_HAVE_iCCP; + +#ifdef PNG_MAX_MALLOC_64K + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "iCCP chunk too large to fit in memory"); + skip = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1); + slength = length; + png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + + if (png_crc_finish(png_ptr, skip)) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + png_ptr->chunkdata[slength] = 0x00; + + for (profile = png_ptr->chunkdata; *profile; profile++) + /* Empty loop to find end of name */ ; + + ++profile; + + /* There should be at least one zero (the compression type byte) + * following the separator, and we should be on it + */ + if (profile >= png_ptr->chunkdata + slength - 1) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_warning(png_ptr, "Malformed iCCP chunk"); + return; + } + + /* Compression_type should always be zero */ + compression_type = *profile++; + + if (compression_type) + { + png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk"); + compression_type = 0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8 + wrote nonzero) */ + } + + prefix_length = profile - png_ptr->chunkdata; + png_decompress_chunk(png_ptr, compression_type, + slength, prefix_length, &data_length); + + profile_length = data_length - prefix_length; + + if (prefix_length > data_length || profile_length < 4) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_warning(png_ptr, "Profile size field missing from iCCP chunk"); + return; + } + + /* Check the profile_size recorded in the first 32 bits of the ICC profile */ + pC = (png_bytep)(png_ptr->chunkdata + prefix_length); + profile_size = ((*(pC )) << 24) | + ((*(pC + 1)) << 16) | + ((*(pC + 2)) << 8) | + ((*(pC + 3)) ); + + /* NOTE: the following guarantees that 'profile_length' fits into 32 bits, + * because profile_size is a 32 bit value. + */ + if (profile_size < profile_length) + profile_length = profile_size; + + /* And the following guarantees that profile_size == profile_length. */ + if (profile_size > profile_length) + { + PNG_WARNING_PARAMETERS(p) + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + + png_warning_parameter_unsigned(p, 1, PNG_NUMBER_FORMAT_u, profile_size); + png_warning_parameter_unsigned(p, 2, PNG_NUMBER_FORMAT_u, profile_length); + png_formatted_warning(png_ptr, p, + "Ignoring iCCP chunk with declared size = @1 and actual length = @2"); + return; + } + + png_set_iCCP(png_ptr, info_ptr, png_ptr->chunkdata, + compression_type, (png_bytep)png_ptr->chunkdata + prefix_length, + profile_size); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; +} +#endif /* PNG_READ_iCCP_SUPPORTED */ + +#ifdef PNG_READ_sPLT_SUPPORTED +void /* PRIVATE */ +png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +/* Note: this does not properly handle chunks that are > 64K under DOS */ +{ + png_bytep entry_start; + png_sPLT_t new_palette; + png_sPLT_entryp pp; + png_uint_32 data_length; + int entry_size, i; + png_uint_32 skip = 0; + png_size_t slength; + png_uint_32 dl; + png_size_t max_dl; + + png_debug(1, "in png_handle_sPLT"); + +#ifdef PNG_USER_LIMITS_SUPPORTED + + if (png_ptr->user_chunk_cache_max != 0) + { + if (png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + return; + } + + if (--png_ptr->user_chunk_cache_max == 1) + { + png_warning(png_ptr, "No space in chunk cache for sPLT"); + png_crc_finish(png_ptr, length); + return; + } + } +#endif + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before sPLT"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid sPLT after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + +#ifdef PNG_MAX_MALLOC_64K + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "sPLT chunk too large to fit in memory"); + skip = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1); + + /* WARNING: this may break if size_t is less than 32 bits; it is assumed + * that the PNG_MAX_MALLOC_64K test is enabled in this case, but this is a + * potential breakage point if the types in pngconf.h aren't exactly right. + */ + slength = length; + png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + + if (png_crc_finish(png_ptr, skip)) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + png_ptr->chunkdata[slength] = 0x00; + + for (entry_start = (png_bytep)png_ptr->chunkdata; *entry_start; + entry_start++) + /* Empty loop to find end of name */ ; + + ++entry_start; + + /* A sample depth should follow the separator, and we should be on it */ + if (entry_start > (png_bytep)png_ptr->chunkdata + slength - 2) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_warning(png_ptr, "malformed sPLT chunk"); + return; + } + + new_palette.depth = *entry_start++; + entry_size = (new_palette.depth == 8 ? 6 : 10); + /* This must fit in a png_uint_32 because it is derived from the original + * chunk data length (and use 'length', not 'slength' here for clarity - + * they are guaranteed to be the same, see the tests above.) + */ + data_length = length - (png_uint_32)(entry_start - + (png_bytep)png_ptr->chunkdata); + + /* Integrity-check the data length */ + if (data_length % entry_size) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_warning(png_ptr, "sPLT chunk has bad length"); + return; + } + + dl = (png_int_32)(data_length / entry_size); + max_dl = PNG_SIZE_MAX / png_sizeof(png_sPLT_entry); + + if (dl > max_dl) + { + png_warning(png_ptr, "sPLT chunk too long"); + return; + } + + new_palette.nentries = (png_int_32)(data_length / entry_size); + + new_palette.entries = (png_sPLT_entryp)png_malloc_warn( + png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry)); + + if (new_palette.entries == NULL) + { + png_warning(png_ptr, "sPLT chunk requires too much memory"); + return; + } + +#ifdef PNG_POINTER_INDEXING_SUPPORTED + for (i = 0; i < new_palette.nentries; i++) + { + pp = new_palette.entries + i; + + if (new_palette.depth == 8) + { + pp->red = *entry_start++; + pp->green = *entry_start++; + pp->blue = *entry_start++; + pp->alpha = *entry_start++; + } + + else + { + pp->red = png_get_uint_16(entry_start); entry_start += 2; + pp->green = png_get_uint_16(entry_start); entry_start += 2; + pp->blue = png_get_uint_16(entry_start); entry_start += 2; + pp->alpha = png_get_uint_16(entry_start); entry_start += 2; + } + + pp->frequency = png_get_uint_16(entry_start); entry_start += 2; + } +#else + pp = new_palette.entries; + + for (i = 0; i < new_palette.nentries; i++) + { + + if (new_palette.depth == 8) + { + pp[i].red = *entry_start++; + pp[i].green = *entry_start++; + pp[i].blue = *entry_start++; + pp[i].alpha = *entry_start++; + } + + else + { + pp[i].red = png_get_uint_16(entry_start); entry_start += 2; + pp[i].green = png_get_uint_16(entry_start); entry_start += 2; + pp[i].blue = png_get_uint_16(entry_start); entry_start += 2; + pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2; + } + + pp[i].frequency = png_get_uint_16(entry_start); entry_start += 2; + } +#endif + + /* Discard all chunk data except the name and stash that */ + new_palette.name = png_ptr->chunkdata; + + png_set_sPLT(png_ptr, info_ptr, &new_palette, 1); + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_free(png_ptr, new_palette.entries); +} +#endif /* PNG_READ_sPLT_SUPPORTED */ + +#ifdef PNG_READ_tRNS_SUPPORTED +void /* PRIVATE */ +png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte readbuf[PNG_MAX_PALETTE_LENGTH]; + + png_debug(1, "in png_handle_tRNS"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before tRNS"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid tRNS after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) + { + png_warning(png_ptr, "Duplicate tRNS chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) + { + png_byte buf[2]; + + if (length != 2) + { + png_warning(png_ptr, "Incorrect tRNS chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 2); + png_ptr->num_trans = 1; + png_ptr->trans_color.gray = png_get_uint_16(buf); + } + + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) + { + png_byte buf[6]; + + if (length != 6) + { + png_warning(png_ptr, "Incorrect tRNS chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, (png_size_t)length); + png_ptr->num_trans = 1; + png_ptr->trans_color.red = png_get_uint_16(buf); + png_ptr->trans_color.green = png_get_uint_16(buf + 2); + png_ptr->trans_color.blue = png_get_uint_16(buf + 4); + } + + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (!(png_ptr->mode & PNG_HAVE_PLTE)) + { + /* Should be an error, but we can cope with it. */ + png_warning(png_ptr, "Missing PLTE before tRNS"); + } + + if (length > (png_uint_32)png_ptr->num_palette || + length > PNG_MAX_PALETTE_LENGTH) + { + png_warning(png_ptr, "Incorrect tRNS chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + if (length == 0) + { + png_warning(png_ptr, "Zero length tRNS chunk"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, readbuf, (png_size_t)length); + png_ptr->num_trans = (png_uint_16)length; + } + + else + { + png_warning(png_ptr, "tRNS chunk not allowed with alpha channel"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_crc_finish(png_ptr, 0)) + { + png_ptr->num_trans = 0; + return; + } + + png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans, + &(png_ptr->trans_color)); +} +#endif + +#ifdef PNG_READ_bKGD_SUPPORTED +void /* PRIVATE */ +png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_size_t truelen; + png_byte buf[6]; + png_color_16 background; + + png_debug(1, "in png_handle_bKGD"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before bKGD"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid bKGD after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + { + png_warning(png_ptr, "Missing PLTE before bKGD"); + png_crc_finish(png_ptr, length); + return; + } + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)) + { + png_warning(png_ptr, "Duplicate bKGD chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + truelen = 1; + + else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) + truelen = 6; + + else + truelen = 2; + + if (length != truelen) + { + png_warning(png_ptr, "Incorrect bKGD chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, truelen); + + if (png_crc_finish(png_ptr, 0)) + return; + + /* We convert the index value into RGB components so that we can allow + * arbitrary RGB values for background when we have transparency, and + * so it is easy to determine the RGB values of the background color + * from the info_ptr struct. + */ + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + background.index = buf[0]; + + if (info_ptr && info_ptr->num_palette) + { + if (buf[0] >= info_ptr->num_palette) + { + png_warning(png_ptr, "Incorrect bKGD chunk index value"); + return; + } + + background.red = (png_uint_16)png_ptr->palette[buf[0]].red; + background.green = (png_uint_16)png_ptr->palette[buf[0]].green; + background.blue = (png_uint_16)png_ptr->palette[buf[0]].blue; + } + + else + background.red = background.green = background.blue = 0; + + background.gray = 0; + } + + else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */ + { + background.index = 0; + background.red = + background.green = + background.blue = + background.gray = png_get_uint_16(buf); + } + + else + { + background.index = 0; + background.red = png_get_uint_16(buf); + background.green = png_get_uint_16(buf + 2); + background.blue = png_get_uint_16(buf + 4); + background.gray = 0; + } + + png_set_bKGD(png_ptr, info_ptr, &background); +} +#endif + +#ifdef PNG_READ_hIST_SUPPORTED +void /* PRIVATE */ +png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + unsigned int num, i; + png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH]; + + png_debug(1, "in png_handle_hIST"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before hIST"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid hIST after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + + else if (!(png_ptr->mode & PNG_HAVE_PLTE)) + { + png_warning(png_ptr, "Missing PLTE before hIST"); + png_crc_finish(png_ptr, length); + return; + } + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)) + { + png_warning(png_ptr, "Duplicate hIST chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length > 2*PNG_MAX_PALETTE_LENGTH || + length != (unsigned int) (2*png_ptr->num_palette)) + { + png_warning(png_ptr, "Incorrect hIST chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + num = length / 2 ; + + for (i = 0; i < num; i++) + { + png_byte buf[2]; + + png_crc_read(png_ptr, buf, 2); + readbuf[i] = png_get_uint_16(buf); + } + + if (png_crc_finish(png_ptr, 0)) + return; + + png_set_hIST(png_ptr, info_ptr, readbuf); +} +#endif + +#ifdef PNG_READ_pHYs_SUPPORTED +void /* PRIVATE */ +png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[9]; + png_uint_32 res_x, res_y; + int unit_type; + + png_debug(1, "in png_handle_pHYs"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before pHYs"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid pHYs after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + { + png_warning(png_ptr, "Duplicate pHYs chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 9) + { + png_warning(png_ptr, "Incorrect pHYs chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 9); + + if (png_crc_finish(png_ptr, 0)) + return; + + res_x = png_get_uint_32(buf); + res_y = png_get_uint_32(buf + 4); + unit_type = buf[8]; + png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type); +} +#endif + +#ifdef PNG_READ_oFFs_SUPPORTED +void /* PRIVATE */ +png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[9]; + png_int_32 offset_x, offset_y; + int unit_type; + + png_debug(1, "in png_handle_oFFs"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before oFFs"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid oFFs after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) + { + png_warning(png_ptr, "Duplicate oFFs chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 9) + { + png_warning(png_ptr, "Incorrect oFFs chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 9); + + if (png_crc_finish(png_ptr, 0)) + return; + + offset_x = png_get_int_32(buf); + offset_y = png_get_int_32(buf + 4); + unit_type = buf[8]; + png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type); +} +#endif + +#ifdef PNG_READ_pCAL_SUPPORTED +/* Read the pCAL chunk (described in the PNG Extensions document) */ +void /* PRIVATE */ +png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_int_32 X0, X1; + png_byte type, nparams; + png_charp buf, units, endptr; + png_charpp params; + png_size_t slength; + int i; + + png_debug(1, "in png_handle_pCAL"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before pCAL"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid pCAL after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)) + { + png_warning(png_ptr, "Duplicate pCAL chunk"); + png_crc_finish(png_ptr, length); + return; + } + + png_debug1(2, "Allocating and reading pCAL chunk data (%u bytes)", + length + 1); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); + + if (png_ptr->chunkdata == NULL) + { + png_warning(png_ptr, "No memory for pCAL purpose"); + return; + } + + slength = length; + png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + + if (png_crc_finish(png_ptr, 0)) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */ + + png_debug(3, "Finding end of pCAL purpose string"); + for (buf = png_ptr->chunkdata; *buf; buf++) + /* Empty loop */ ; + + endptr = png_ptr->chunkdata + slength; + + /* We need to have at least 12 bytes after the purpose string + * in order to get the parameter information. + */ + if (endptr <= buf + 12) + { + png_warning(png_ptr, "Invalid pCAL data"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + png_debug(3, "Reading pCAL X0, X1, type, nparams, and units"); + X0 = png_get_int_32((png_bytep)buf+1); + X1 = png_get_int_32((png_bytep)buf+5); + type = buf[9]; + nparams = buf[10]; + units = buf + 11; + + png_debug(3, "Checking pCAL equation type and number of parameters"); + /* Check that we have the right number of parameters for known + * equation types. + */ + if ((type == PNG_EQUATION_LINEAR && nparams != 2) || + (type == PNG_EQUATION_BASE_E && nparams != 3) || + (type == PNG_EQUATION_ARBITRARY && nparams != 3) || + (type == PNG_EQUATION_HYPERBOLIC && nparams != 4)) + { + png_warning(png_ptr, "Invalid pCAL parameters for equation type"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + else if (type >= PNG_EQUATION_LAST) + { + png_warning(png_ptr, "Unrecognized equation type for pCAL chunk"); + } + + for (buf = units; *buf; buf++) + /* Empty loop to move past the units string. */ ; + + png_debug(3, "Allocating pCAL parameters array"); + + params = (png_charpp)png_malloc_warn(png_ptr, + (png_size_t)(nparams * png_sizeof(png_charp))); + + if (params == NULL) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_warning(png_ptr, "No memory for pCAL params"); + return; + } + + /* Get pointers to the start of each parameter string. */ + for (i = 0; i < (int)nparams; i++) + { + buf++; /* Skip the null string terminator from previous parameter. */ + + png_debug1(3, "Reading pCAL parameter %d", i); + + for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++) + /* Empty loop to move past each parameter string */ ; + + /* Make sure we haven't run out of data yet */ + if (buf > endptr) + { + png_warning(png_ptr, "Invalid pCAL data"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_free(png_ptr, params); + return; + } + } + + png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams, + units, params); + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_free(png_ptr, params); +} +#endif + +#ifdef PNG_READ_sCAL_SUPPORTED +/* Read the sCAL chunk */ +void /* PRIVATE */ +png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_size_t slength, i; + int state; + + png_debug(1, "in png_handle_sCAL"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before sCAL"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid sCAL after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL)) + { + png_warning(png_ptr, "Duplicate sCAL chunk"); + png_crc_finish(png_ptr, length); + return; + } + + /* Need unit type, width, \0, height: minimum 4 bytes */ + else if (length < 4) + { + png_warning(png_ptr, "sCAL chunk too short"); + png_crc_finish(png_ptr, length); + return; + } + + png_debug1(2, "Allocating and reading sCAL chunk data (%u bytes)", + length + 1); + + png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); + + if (png_ptr->chunkdata == NULL) + { + png_warning(png_ptr, "Out of memory while processing sCAL chunk"); + png_crc_finish(png_ptr, length); + return; + } + + slength = length; + png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */ + + if (png_crc_finish(png_ptr, 0)) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + /* Validate the unit. */ + if (png_ptr->chunkdata[0] != 1 && png_ptr->chunkdata[0] != 2) + { + png_warning(png_ptr, "Invalid sCAL ignored: invalid unit"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + /* Validate the ASCII numbers, need two ASCII numbers separated by + * a '\0' and they need to fit exactly in the chunk data. + */ + i = 1; + state = 0; + + if (!png_check_fp_number(png_ptr->chunkdata, slength, &state, &i) || + i >= slength || png_ptr->chunkdata[i++] != 0) + png_warning(png_ptr, "Invalid sCAL chunk ignored: bad width format"); + + else if (!PNG_FP_IS_POSITIVE(state)) + png_warning(png_ptr, "Invalid sCAL chunk ignored: non-positive width"); + + else + { + png_size_t heighti = i; + + state = 0; + if (!png_check_fp_number(png_ptr->chunkdata, slength, &state, &i) || + i != slength) + png_warning(png_ptr, "Invalid sCAL chunk ignored: bad height format"); + + else if (!PNG_FP_IS_POSITIVE(state)) + png_warning(png_ptr, + "Invalid sCAL chunk ignored: non-positive height"); + + else + /* This is the (only) success case. */ + png_set_sCAL_s(png_ptr, info_ptr, png_ptr->chunkdata[0], + png_ptr->chunkdata+1, png_ptr->chunkdata+heighti); + } + + /* Clean up - just free the temporarily allocated buffer. */ + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; +} +#endif + +#ifdef PNG_READ_tIME_SUPPORTED +void /* PRIVATE */ +png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[7]; + png_time mod_time; + + png_debug(1, "in png_handle_tIME"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Out of place tIME chunk"); + + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)) + { + png_warning(png_ptr, "Duplicate tIME chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_ptr->mode & PNG_HAVE_IDAT) + png_ptr->mode |= PNG_AFTER_IDAT; + + if (length != 7) + { + png_warning(png_ptr, "Incorrect tIME chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 7); + + if (png_crc_finish(png_ptr, 0)) + return; + + mod_time.second = buf[6]; + mod_time.minute = buf[5]; + mod_time.hour = buf[4]; + mod_time.day = buf[3]; + mod_time.month = buf[2]; + mod_time.year = png_get_uint_16(buf); + + png_set_tIME(png_ptr, info_ptr, &mod_time); +} +#endif + +#ifdef PNG_READ_tEXt_SUPPORTED +/* Note: this does not properly handle chunks that are > 64K under DOS */ +void /* PRIVATE */ +png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_textp text_ptr; + png_charp key; + png_charp text; + png_uint_32 skip = 0; + png_size_t slength; + int ret; + + png_debug(1, "in png_handle_tEXt"); + +#ifdef PNG_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_cache_max != 0) + { + if (png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + return; + } + + if (--png_ptr->user_chunk_cache_max == 1) + { + png_warning(png_ptr, "No space in chunk cache for tEXt"); + png_crc_finish(png_ptr, length); + return; + } + } +#endif + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before tEXt"); + + if (png_ptr->mode & PNG_HAVE_IDAT) + png_ptr->mode |= PNG_AFTER_IDAT; + +#ifdef PNG_MAX_MALLOC_64K + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "tEXt chunk too large to fit in memory"); + skip = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + + png_free(png_ptr, png_ptr->chunkdata); + + png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); + + if (png_ptr->chunkdata == NULL) + { + png_warning(png_ptr, "No memory to process text chunk"); + return; + } + + slength = length; + png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + + if (png_crc_finish(png_ptr, skip)) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + key = png_ptr->chunkdata; + + key[slength] = 0x00; + + for (text = key; *text; text++) + /* Empty loop to find end of key */ ; + + if (text != key + slength) + text++; + + text_ptr = (png_textp)png_malloc_warn(png_ptr, + png_sizeof(png_text)); + + if (text_ptr == NULL) + { + png_warning(png_ptr, "Not enough memory to process text chunk"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + text_ptr->compression = PNG_TEXT_COMPRESSION_NONE; + text_ptr->key = key; + text_ptr->lang = NULL; + text_ptr->lang_key = NULL; + text_ptr->itxt_length = 0; + text_ptr->text = text; + text_ptr->text_length = png_strlen(text); + + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_free(png_ptr, text_ptr); + + if (ret) + png_warning(png_ptr, "Insufficient memory to process text chunk"); +} +#endif + +#ifdef PNG_READ_zTXt_SUPPORTED +/* Note: this does not correctly handle chunks that are > 64K under DOS */ +void /* PRIVATE */ +png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_textp text_ptr; + png_charp text; + int comp_type; + int ret; + png_size_t slength, prefix_len, data_len; + + png_debug(1, "in png_handle_zTXt"); + +#ifdef PNG_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_cache_max != 0) + { + if (png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + return; + } + + if (--png_ptr->user_chunk_cache_max == 1) + { + png_warning(png_ptr, "No space in chunk cache for zTXt"); + png_crc_finish(png_ptr, length); + return; + } + } +#endif + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before zTXt"); + + if (png_ptr->mode & PNG_HAVE_IDAT) + png_ptr->mode |= PNG_AFTER_IDAT; + +#ifdef PNG_MAX_MALLOC_64K + /* We will no doubt have problems with chunks even half this size, but + * there is no hard and fast rule to tell us where to stop. + */ + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "zTXt chunk too large to fit in memory"); + png_crc_finish(png_ptr, length); + return; + } +#endif + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); + + if (png_ptr->chunkdata == NULL) + { + png_warning(png_ptr, "Out of memory processing zTXt chunk"); + return; + } + + slength = length; + png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + + if (png_crc_finish(png_ptr, 0)) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + png_ptr->chunkdata[slength] = 0x00; + + for (text = png_ptr->chunkdata; *text; text++) + /* Empty loop */ ; + + /* zTXt must have some text after the chunkdataword */ + if (text >= png_ptr->chunkdata + slength - 2) + { + png_warning(png_ptr, "Truncated zTXt chunk"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + else + { + comp_type = *(++text); + + if (comp_type != PNG_TEXT_COMPRESSION_zTXt) + { + png_warning(png_ptr, "Unknown compression type in zTXt chunk"); + comp_type = PNG_TEXT_COMPRESSION_zTXt; + } + + text++; /* Skip the compression_method byte */ + } + + prefix_len = text - png_ptr->chunkdata; + + png_decompress_chunk(png_ptr, comp_type, + (png_size_t)length, prefix_len, &data_len); + + text_ptr = (png_textp)png_malloc_warn(png_ptr, + png_sizeof(png_text)); + + if (text_ptr == NULL) + { + png_warning(png_ptr, "Not enough memory to process zTXt chunk"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + text_ptr->compression = comp_type; + text_ptr->key = png_ptr->chunkdata; + text_ptr->lang = NULL; + text_ptr->lang_key = NULL; + text_ptr->itxt_length = 0; + text_ptr->text = png_ptr->chunkdata + prefix_len; + text_ptr->text_length = data_len; + + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_free(png_ptr, text_ptr); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + + if (ret) + png_error(png_ptr, "Insufficient memory to store zTXt chunk"); +} +#endif + +#ifdef PNG_READ_iTXt_SUPPORTED +/* Note: this does not correctly handle chunks that are > 64K under DOS */ +void /* PRIVATE */ +png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_textp text_ptr; + png_charp key, lang, text, lang_key; + int comp_flag; + int comp_type = 0; + int ret; + png_size_t slength, prefix_len, data_len; + + png_debug(1, "in png_handle_iTXt"); + +#ifdef PNG_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_cache_max != 0) + { + if (png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + return; + } + + if (--png_ptr->user_chunk_cache_max == 1) + { + png_warning(png_ptr, "No space in chunk cache for iTXt"); + png_crc_finish(png_ptr, length); + return; + } + } +#endif + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before iTXt"); + + if (png_ptr->mode & PNG_HAVE_IDAT) + png_ptr->mode |= PNG_AFTER_IDAT; + +#ifdef PNG_MAX_MALLOC_64K + /* We will no doubt have problems with chunks even half this size, but + * there is no hard and fast rule to tell us where to stop. + */ + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "iTXt chunk too large to fit in memory"); + png_crc_finish(png_ptr, length); + return; + } +#endif + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); + + if (png_ptr->chunkdata == NULL) + { + png_warning(png_ptr, "No memory to process iTXt chunk"); + return; + } + + slength = length; + png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + + if (png_crc_finish(png_ptr, 0)) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + png_ptr->chunkdata[slength] = 0x00; + + for (lang = png_ptr->chunkdata; *lang; lang++) + /* Empty loop */ ; + + lang++; /* Skip NUL separator */ + + /* iTXt must have a language tag (possibly empty), two compression bytes, + * translated keyword (possibly empty), and possibly some text after the + * keyword + */ + + if (lang >= png_ptr->chunkdata + slength - 3) + { + png_warning(png_ptr, "Truncated iTXt chunk"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + else + { + comp_flag = *lang++; + comp_type = *lang++; + } + + if (comp_type || (comp_flag && comp_flag != PNG_TEXT_COMPRESSION_zTXt)) + { + png_warning(png_ptr, "Unknown iTXt compression type or method"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + for (lang_key = lang; *lang_key; lang_key++) + /* Empty loop */ ; + + lang_key++; /* Skip NUL separator */ + + if (lang_key >= png_ptr->chunkdata + slength) + { + png_warning(png_ptr, "Truncated iTXt chunk"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + for (text = lang_key; *text; text++) + /* Empty loop */ ; + + text++; /* Skip NUL separator */ + + if (text >= png_ptr->chunkdata + slength) + { + png_warning(png_ptr, "Malformed iTXt chunk"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + prefix_len = text - png_ptr->chunkdata; + + key=png_ptr->chunkdata; + + if (comp_flag) + png_decompress_chunk(png_ptr, comp_type, + (size_t)length, prefix_len, &data_len); + + else + data_len = png_strlen(png_ptr->chunkdata + prefix_len); + + text_ptr = (png_textp)png_malloc_warn(png_ptr, + png_sizeof(png_text)); + + if (text_ptr == NULL) + { + png_warning(png_ptr, "Not enough memory to process iTXt chunk"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + text_ptr->compression = (int)comp_flag + 1; + text_ptr->lang_key = png_ptr->chunkdata + (lang_key - key); + text_ptr->lang = png_ptr->chunkdata + (lang - key); + text_ptr->itxt_length = data_len; + text_ptr->text_length = 0; + text_ptr->key = png_ptr->chunkdata; + text_ptr->text = png_ptr->chunkdata + prefix_len; + + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_free(png_ptr, text_ptr); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + + if (ret) + png_error(png_ptr, "Insufficient memory to store iTXt chunk"); +} +#endif + +/* This function is called when we haven't found a handler for a + * chunk. If there isn't a problem with the chunk itself (ie bad + * chunk name, CRC, or a critical chunk), the chunk is silently ignored + * -- unless the PNG_FLAG_UNKNOWN_CHUNKS_SUPPORTED flag is on in which + * case it will be saved away to be written out later. + */ +void /* PRIVATE */ +png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_uint_32 skip = 0; + + png_debug(1, "in png_handle_unknown"); + +#ifdef PNG_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_cache_max != 0) + { + if (png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + return; + } + + if (--png_ptr->user_chunk_cache_max == 1) + { + png_warning(png_ptr, "No space in chunk cache for unknown chunk"); + png_crc_finish(png_ptr, length); + return; + } + } +#endif + + if (png_ptr->mode & PNG_HAVE_IDAT) + { + if (png_ptr->chunk_name != png_IDAT) + png_ptr->mode |= PNG_AFTER_IDAT; + } + + if (PNG_CHUNK_CRITICAL(png_ptr->chunk_name)) + { +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + if (png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name) != + PNG_HANDLE_CHUNK_ALWAYS +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED + && png_ptr->read_user_chunk_fn == NULL +#endif + ) +#endif + png_chunk_error(png_ptr, "unknown critical chunk"); + } + +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED + if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED + || (png_ptr->read_user_chunk_fn != NULL) +#endif + ) + { +#ifdef PNG_MAX_MALLOC_64K + if (length > 65535) + { + png_warning(png_ptr, "unknown chunk too large to fit in memory"); + skip = length - 65535; + length = 65535; + } +#endif + + /* TODO: this code is very close to the unknown handling in pngpread.c, + * maybe it can be put into a common utility routine? + * png_struct::unknown_chunk is just used as a temporary variable, along + * with the data into which the chunk is read. These can be eliminated. + */ + PNG_CSTRING_FROM_CHUNK(png_ptr->unknown_chunk.name, png_ptr->chunk_name); + png_ptr->unknown_chunk.size = (png_size_t)length; + + if (length == 0) + png_ptr->unknown_chunk.data = NULL; + + else + { + png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length); + png_crc_read(png_ptr, png_ptr->unknown_chunk.data, length); + } + +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED + if (png_ptr->read_user_chunk_fn != NULL) + { + /* Callback to user unknown chunk handler */ + int ret; + + ret = (*(png_ptr->read_user_chunk_fn)) + (png_ptr, &png_ptr->unknown_chunk); + + if (ret < 0) + png_chunk_error(png_ptr, "error in user chunk"); + + if (ret == 0) + { + if (PNG_CHUNK_CRITICAL(png_ptr->chunk_name)) + { +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + if (png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name) != + PNG_HANDLE_CHUNK_ALWAYS) +#endif + png_chunk_error(png_ptr, "unknown critical chunk"); + } + + png_set_unknown_chunks(png_ptr, info_ptr, + &png_ptr->unknown_chunk, 1); + } + } + + else +#endif + png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1); + + png_free(png_ptr, png_ptr->unknown_chunk.data); + png_ptr->unknown_chunk.data = NULL; + } + + else +#endif + skip = length; + + png_crc_finish(png_ptr, skip); + +#ifndef PNG_READ_USER_CHUNKS_SUPPORTED + PNG_UNUSED(info_ptr) /* Quiet compiler warnings about unused info_ptr */ +#endif +} + +/* This function is called to verify that a chunk name is valid. + * This function can't have the "critical chunk check" incorporated + * into it, since in the future we will need to be able to call user + * functions to handle unknown critical chunks after we check that + * the chunk name itself is valid. + */ + +/* Bit hacking: the test for an invalid byte in the 4 byte chunk name is: + * + * ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) + */ + +void /* PRIVATE */ +png_check_chunk_name(png_structp png_ptr, png_uint_32 chunk_name) +{ + int i; + + png_debug(1, "in png_check_chunk_name"); + + for (i=1; i<=4; ++i) + { + int c = chunk_name & 0xff; + + if (c < 65 || c > 122 || (c > 90 && c < 97)) + png_chunk_error(png_ptr, "invalid chunk type"); + + chunk_name >>= 8; + } +} + +/* Combines the row recently read in with the existing pixels in the row. This + * routine takes care of alpha and transparency if requested. This routine also + * handles the two methods of progressive display of interlaced images, + * depending on the 'display' value; if 'display' is true then the whole row + * (dp) is filled from the start by replicating the available pixels. If + * 'display' is false only those pixels present in the pass are filled in. + */ +void /* PRIVATE */ +png_combine_row(png_structp png_ptr, png_bytep dp, int display) +{ + unsigned int pixel_depth = png_ptr->transformed_pixel_depth; + png_const_bytep sp = png_ptr->row_buf + 1; + png_uint_32 row_width = png_ptr->width; + unsigned int pass = png_ptr->pass; + png_bytep end_ptr = 0; + png_byte end_byte = 0; + unsigned int end_mask; + + png_debug(1, "in png_combine_row"); + + /* Added in 1.5.6: it should not be possible to enter this routine until at + * least one row has been read from the PNG data and transformed. + */ + if (pixel_depth == 0) + png_error(png_ptr, "internal row logic error"); + + /* Added in 1.5.4: the pixel depth should match the information returned by + * any call to png_read_update_info at this point. Do not continue if we got + * this wrong. + */ + if (png_ptr->info_rowbytes != 0 && png_ptr->info_rowbytes != + PNG_ROWBYTES(pixel_depth, row_width)) + png_error(png_ptr, "internal row size calculation error"); + + /* Don't expect this to ever happen: */ + if (row_width == 0) + png_error(png_ptr, "internal row width error"); + + /* Preserve the last byte in cases where only part of it will be overwritten, + * the multiply below may overflow, we don't care because ANSI-C guarantees + * we get the low bits. + */ + end_mask = (pixel_depth * row_width) & 7; + if (end_mask != 0) + { + /* end_ptr == NULL is a flag to say do nothing */ + end_ptr = dp + PNG_ROWBYTES(pixel_depth, row_width) - 1; + end_byte = *end_ptr; +# ifdef PNG_READ_PACKSWAP_SUPPORTED + if (png_ptr->transformations & PNG_PACKSWAP) /* little-endian byte */ + end_mask = 0xff << end_mask; + + else /* big-endian byte */ +# endif + end_mask = 0xff >> end_mask; + /* end_mask is now the bits to *keep* from the destination row */ + } + + /* For non-interlaced images this reduces to a png_memcpy(). A png_memcpy() + * will also happen if interlacing isn't supported or if the application + * does not call png_set_interlace_handling(). In the latter cases the + * caller just gets a sequence of the unexpanded rows from each interlace + * pass. + */ +#ifdef PNG_READ_INTERLACING_SUPPORTED + if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE) && + pass < 6 && (display == 0 || + /* The following copies everything for 'display' on passes 0, 2 and 4. */ + (display == 1 && (pass & 1) != 0))) + { + /* Narrow images may have no bits in a pass; the caller should handle + * this, but this test is cheap: + */ + if (row_width <= PNG_PASS_START_COL(pass)) + return; + + if (pixel_depth < 8) + { + /* For pixel depths up to 4 bpp the 8-pixel mask can be expanded to fit + * into 32 bits, then a single loop over the bytes using the four byte + * values in the 32-bit mask can be used. For the 'display' option the + * expanded mask may also not require any masking within a byte. To + * make this work the PACKSWAP option must be taken into account - it + * simply requires the pixels to be reversed in each byte. + * + * The 'regular' case requires a mask for each of the first 6 passes, + * the 'display' case does a copy for the even passes in the range + * 0..6. This has already been handled in the test above. + * + * The masks are arranged as four bytes with the first byte to use in + * the lowest bits (little-endian) regardless of the order (PACKSWAP or + * not) of the pixels in each byte. + * + * NOTE: the whole of this logic depends on the caller of this function + * only calling it on rows appropriate to the pass. This function only + * understands the 'x' logic; the 'y' logic is handled by the caller. + * + * The following defines allow generation of compile time constant bit + * masks for each pixel depth and each possibility of swapped or not + * swapped bytes. Pass 'p' is in the range 0..6; 'x', a pixel index, + * is in the range 0..7; and the result is 1 if the pixel is to be + * copied in the pass, 0 if not. 'S' is for the sparkle method, 'B' + * for the block method. + * + * With some compilers a compile time expression of the general form: + * + * (shift >= 32) ? (a >> (shift-32)) : (b >> shift) + * + * Produces warnings with values of 'shift' in the range 33 to 63 + * because the right hand side of the ?: expression is evaluated by + * the compiler even though it isn't used. Microsoft Visual C (various + * versions) and the Intel C compiler are known to do this. To avoid + * this the following macros are used in 1.5.6. This is a temporary + * solution to avoid destabilizing the code during the release process. + */ +# if PNG_USE_COMPILE_TIME_MASKS +# define PNG_LSR(x,s) ((x)>>((s) & 0x1f)) +# define PNG_LSL(x,s) ((x)<<((s) & 0x1f)) +# else +# define PNG_LSR(x,s) ((x)>>(s)) +# define PNG_LSL(x,s) ((x)<<(s)) +# endif +# define S_COPY(p,x) (((p)<4 ? PNG_LSR(0x80088822,(3-(p))*8+(7-(x))) :\ + PNG_LSR(0xaa55ff00,(7-(p))*8+(7-(x)))) & 1) +# define B_COPY(p,x) (((p)<4 ? PNG_LSR(0xff0fff33,(3-(p))*8+(7-(x))) :\ + PNG_LSR(0xff55ff00,(7-(p))*8+(7-(x)))) & 1) + + /* Return a mask for pass 'p' pixel 'x' at depth 'd'. The mask is + * little endian - the first pixel is at bit 0 - however the extra + * parameter 's' can be set to cause the mask position to be swapped + * within each byte, to match the PNG format. This is done by XOR of + * the shift with 7, 6 or 4 for bit depths 1, 2 and 4. + */ +# define PIXEL_MASK(p,x,d,s) \ + (PNG_LSL(((PNG_LSL(1U,(d)))-1),(((x)*(d))^((s)?8-(d):0)))) + + /* Hence generate the appropriate 'block' or 'sparkle' pixel copy mask. + */ +# define S_MASKx(p,x,d,s) (S_COPY(p,x)?PIXEL_MASK(p,x,d,s):0) +# define B_MASKx(p,x,d,s) (B_COPY(p,x)?PIXEL_MASK(p,x,d,s):0) + + /* Combine 8 of these to get the full mask. For the 1-bpp and 2-bpp + * cases the result needs replicating, for the 4-bpp case the above + * generates a full 32 bits. + */ +# define MASK_EXPAND(m,d) ((m)*((d)==1?0x01010101:((d)==2?0x00010001:1))) + +# define S_MASK(p,d,s) MASK_EXPAND(S_MASKx(p,0,d,s) + S_MASKx(p,1,d,s) +\ + S_MASKx(p,2,d,s) + S_MASKx(p,3,d,s) + S_MASKx(p,4,d,s) +\ + S_MASKx(p,5,d,s) + S_MASKx(p,6,d,s) + S_MASKx(p,7,d,s), d) + +# define B_MASK(p,d,s) MASK_EXPAND(B_MASKx(p,0,d,s) + B_MASKx(p,1,d,s) +\ + B_MASKx(p,2,d,s) + B_MASKx(p,3,d,s) + B_MASKx(p,4,d,s) +\ + B_MASKx(p,5,d,s) + B_MASKx(p,6,d,s) + B_MASKx(p,7,d,s), d) + +#if PNG_USE_COMPILE_TIME_MASKS + /* Utility macros to construct all the masks for a depth/swap + * combination. The 's' parameter says whether the format is PNG + * (big endian bytes) or not. Only the three odd-numbered passes are + * required for the display/block algorithm. + */ +# define S_MASKS(d,s) { S_MASK(0,d,s), S_MASK(1,d,s), S_MASK(2,d,s),\ + S_MASK(3,d,s), S_MASK(4,d,s), S_MASK(5,d,s) } + +# define B_MASKS(d,s) { B_MASK(1,d,s), S_MASK(3,d,s), S_MASK(5,d,s) } + +# define DEPTH_INDEX(d) ((d)==1?0:((d)==2?1:2)) + + /* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and + * then pass: + */ + static PNG_CONST png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] = + { + /* Little-endian byte masks for PACKSWAP */ + { S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) }, + /* Normal (big-endian byte) masks - PNG format */ + { S_MASKS(1,1), S_MASKS(2,1), S_MASKS(4,1) } + }; + + /* display_mask has only three entries for the odd passes, so index by + * pass>>1. + */ + static PNG_CONST png_uint_32 display_mask[2][3][3] = + { + /* Little-endian byte masks for PACKSWAP */ + { B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) }, + /* Normal (big-endian byte) masks - PNG format */ + { B_MASKS(1,1), B_MASKS(2,1), B_MASKS(4,1) } + }; + +# define MASK(pass,depth,display,png)\ + ((display)?display_mask[png][DEPTH_INDEX(depth)][pass>>1]:\ + row_mask[png][DEPTH_INDEX(depth)][pass]) + +#else /* !PNG_USE_COMPILE_TIME_MASKS */ + /* This is the runtime alternative: it seems unlikely that this will + * ever be either smaller or faster than the compile time approach. + */ +# define MASK(pass,depth,display,png)\ + ((display)?B_MASK(pass,depth,png):S_MASK(pass,depth,png)) +#endif /* !PNG_USE_COMPILE_TIME_MASKS */ + + /* Use the appropriate mask to copy the required bits. In some cases + * the byte mask will be 0 or 0xff, optimize these cases. row_width is + * the number of pixels, but the code copies bytes, so it is necessary + * to special case the end. + */ + png_uint_32 pixels_per_byte = 8 / pixel_depth; + png_uint_32 mask; + +# ifdef PNG_READ_PACKSWAP_SUPPORTED + if (png_ptr->transformations & PNG_PACKSWAP) + mask = MASK(pass, pixel_depth, display, 0); + + else +# endif + mask = MASK(pass, pixel_depth, display, 1); + + for (;;) + { + png_uint_32 m; + + /* It doesn't matter in the following if png_uint_32 has more than + * 32 bits because the high bits always match those in m<<24; it is, + * however, essential to use OR here, not +, because of this. + */ + m = mask; + mask = (m >> 8) | (m << 24); /* rotate right to good compilers */ + m &= 0xff; + + if (m != 0) /* something to copy */ + { + if (m != 0xff) + *dp = (png_byte)((*dp & ~m) | (*sp & m)); + else + *dp = *sp; + } + + /* NOTE: this may overwrite the last byte with garbage if the image + * is not an exact number of bytes wide; libpng has always done + * this. + */ + if (row_width <= pixels_per_byte) + break; /* May need to restore part of the last byte */ + + row_width -= pixels_per_byte; + ++dp; + ++sp; + } + } + + else /* pixel_depth >= 8 */ + { + unsigned int bytes_to_copy, bytes_to_jump; + + /* Validate the depth - it must be a multiple of 8 */ + if (pixel_depth & 7) + png_error(png_ptr, "invalid user transform pixel depth"); + + pixel_depth >>= 3; /* now in bytes */ + row_width *= pixel_depth; + + /* Regardless of pass number the Adam 7 interlace always results in a + * fixed number of pixels to copy then to skip. There may be a + * different number of pixels to skip at the start though. + */ + { + unsigned int offset = PNG_PASS_START_COL(pass) * pixel_depth; + + row_width -= offset; + dp += offset; + sp += offset; + } + + /* Work out the bytes to copy. */ + if (display) + { + /* When doing the 'block' algorithm the pixel in the pass gets + * replicated to adjacent pixels. This is why the even (0,2,4,6) + * passes are skipped above - the entire expanded row is copied. + */ + bytes_to_copy = (1<<((6-pass)>>1)) * pixel_depth; + + /* But don't allow this number to exceed the actual row width. */ + if (bytes_to_copy > row_width) + bytes_to_copy = row_width; + } + + else /* normal row; Adam7 only ever gives us one pixel to copy. */ + bytes_to_copy = pixel_depth; + + /* In Adam7 there is a constant offset between where the pixels go. */ + bytes_to_jump = PNG_PASS_COL_OFFSET(pass) * pixel_depth; + + /* And simply copy these bytes. Some optimization is possible here, + * depending on the value of 'bytes_to_copy'. Special case the low + * byte counts, which we know to be frequent. + * + * Notice that these cases all 'return' rather than 'break' - this + * avoids an unnecessary test on whether to restore the last byte + * below. + */ + switch (bytes_to_copy) + { + case 1: + for (;;) + { + *dp = *sp; + + if (row_width <= bytes_to_jump) + return; + + dp += bytes_to_jump; + sp += bytes_to_jump; + row_width -= bytes_to_jump; + } + + case 2: + /* There is a possibility of a partial copy at the end here; this + * slows the code down somewhat. + */ + do + { + dp[0] = sp[0], dp[1] = sp[1]; + + if (row_width <= bytes_to_jump) + return; + + sp += bytes_to_jump; + dp += bytes_to_jump; + row_width -= bytes_to_jump; + } + while (row_width > 1); + + /* And there can only be one byte left at this point: */ + *dp = *sp; + return; + + case 3: + /* This can only be the RGB case, so each copy is exactly one + * pixel and it is not necessary to check for a partial copy. + */ + for(;;) + { + dp[0] = sp[0], dp[1] = sp[1], dp[2] = sp[2]; + + if (row_width <= bytes_to_jump) + return; + + sp += bytes_to_jump; + dp += bytes_to_jump; + row_width -= bytes_to_jump; + } + + default: +#if PNG_ALIGN_TYPE != PNG_ALIGN_NONE + /* Check for double byte alignment and, if possible, use a + * 16-bit copy. Don't attempt this for narrow images - ones that + * are less than an interlace panel wide. Don't attempt it for + * wide bytes_to_copy either - use the png_memcpy there. + */ + if (bytes_to_copy < 16 /*else use png_memcpy*/ && + png_isaligned(dp, png_uint_16) && + png_isaligned(sp, png_uint_16) && + bytes_to_copy % sizeof (png_uint_16) == 0 && + bytes_to_jump % sizeof (png_uint_16) == 0) + { + /* Everything is aligned for png_uint_16 copies, but try for + * png_uint_32 first. + */ + if (png_isaligned(dp, png_uint_32) && + png_isaligned(sp, png_uint_32) && + bytes_to_copy % sizeof (png_uint_32) == 0 && + bytes_to_jump % sizeof (png_uint_32) == 0) + { + png_uint_32p dp32 = (png_uint_32p)dp; + png_const_uint_32p sp32 = (png_const_uint_32p)sp; + unsigned int skip = (bytes_to_jump-bytes_to_copy) / + sizeof (png_uint_32); + + do + { + size_t c = bytes_to_copy; + do + { + *dp32++ = *sp32++; + c -= sizeof (png_uint_32); + } + while (c > 0); + + if (row_width <= bytes_to_jump) + return; + + dp32 += skip; + sp32 += skip; + row_width -= bytes_to_jump; + } + while (bytes_to_copy <= row_width); + + /* Get to here when the row_width truncates the final copy. + * There will be 1-3 bytes left to copy, so don't try the + * 16-bit loop below. + */ + dp = (png_bytep)dp32; + sp = (png_const_bytep)sp32; + do + *dp++ = *sp++; + while (--row_width > 0); + return; + } + + /* Else do it in 16-bit quantities, but only if the size is + * not too large. + */ + else + { + png_uint_16p dp16 = (png_uint_16p)dp; + png_const_uint_16p sp16 = (png_const_uint_16p)sp; + unsigned int skip = (bytes_to_jump-bytes_to_copy) / + sizeof (png_uint_16); + + do + { + size_t c = bytes_to_copy; + do + { + *dp16++ = *sp16++; + c -= sizeof (png_uint_16); + } + while (c > 0); + + if (row_width <= bytes_to_jump) + return; + + dp16 += skip; + sp16 += skip; + row_width -= bytes_to_jump; + } + while (bytes_to_copy <= row_width); + + /* End of row - 1 byte left, bytes_to_copy > row_width: */ + dp = (png_bytep)dp16; + sp = (png_const_bytep)sp16; + do + *dp++ = *sp++; + while (--row_width > 0); + return; + } + } +#endif /* PNG_ALIGN_ code */ + + /* The true default - use a png_memcpy: */ + for (;;) + { + png_memcpy(dp, sp, bytes_to_copy); + + if (row_width <= bytes_to_jump) + return; + + sp += bytes_to_jump; + dp += bytes_to_jump; + row_width -= bytes_to_jump; + if (bytes_to_copy > row_width) + bytes_to_copy = row_width; + } + } + + /* NOT REACHED*/ + } /* pixel_depth >= 8 */ + + /* Here if pixel_depth < 8 to check 'end_ptr' below. */ + } + else +#endif + + /* If here then the switch above wasn't used so just png_memcpy the whole row + * from the temporary row buffer (notice that this overwrites the end of the + * destination row if it is a partial byte.) + */ + png_memcpy(dp, sp, PNG_ROWBYTES(pixel_depth, row_width)); + + /* Restore the overwritten bits from the last byte if necessary. */ + if (end_ptr != NULL) + *end_ptr = (png_byte)((end_byte & end_mask) | (*end_ptr & ~end_mask)); +} + +#ifdef PNG_READ_INTERLACING_SUPPORTED +void /* PRIVATE */ +png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, + png_uint_32 transformations /* Because these may affect the byte layout */) +{ + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + /* Offset to next interlace block */ + static PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + png_debug(1, "in png_do_read_interlace"); + if (row != NULL && row_info != NULL) + { + png_uint_32 final_width; + + final_width = row_info->width * png_pass_inc[pass]; + + switch (row_info->pixel_depth) + { + case 1: + { + png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3); + png_bytep dp = row + (png_size_t)((final_width - 1) >> 3); + int sshift, dshift; + int s_start, s_end, s_inc; + int jstop = png_pass_inc[pass]; + png_byte v; + png_uint_32 i; + int j; + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if (transformations & PNG_PACKSWAP) + { + sshift = (int)((row_info->width + 7) & 0x07); + dshift = (int)((final_width + 7) & 0x07); + s_start = 7; + s_end = 0; + s_inc = -1; + } + + else +#endif + { + sshift = 7 - (int)((row_info->width + 7) & 0x07); + dshift = 7 - (int)((final_width + 7) & 0x07); + s_start = 0; + s_end = 7; + s_inc = 1; + } + + for (i = 0; i < row_info->width; i++) + { + v = (png_byte)((*sp >> sshift) & 0x01); + for (j = 0; j < jstop; j++) + { + *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff); + *dp |= (png_byte)(v << dshift); + + if (dshift == s_end) + { + dshift = s_start; + dp--; + } + + else + dshift += s_inc; + } + + if (sshift == s_end) + { + sshift = s_start; + sp--; + } + + else + sshift += s_inc; + } + break; + } + + case 2: + { + png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2); + png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2); + int sshift, dshift; + int s_start, s_end, s_inc; + int jstop = png_pass_inc[pass]; + png_uint_32 i; + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if (transformations & PNG_PACKSWAP) + { + sshift = (int)(((row_info->width + 3) & 0x03) << 1); + dshift = (int)(((final_width + 3) & 0x03) << 1); + s_start = 6; + s_end = 0; + s_inc = -2; + } + + else +#endif + { + sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1); + dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1); + s_start = 0; + s_end = 6; + s_inc = 2; + } + + for (i = 0; i < row_info->width; i++) + { + png_byte v; + int j; + + v = (png_byte)((*sp >> sshift) & 0x03); + for (j = 0; j < jstop; j++) + { + *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff); + *dp |= (png_byte)(v << dshift); + + if (dshift == s_end) + { + dshift = s_start; + dp--; + } + + else + dshift += s_inc; + } + + if (sshift == s_end) + { + sshift = s_start; + sp--; + } + + else + sshift += s_inc; + } + break; + } + + case 4: + { + png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1); + png_bytep dp = row + (png_size_t)((final_width - 1) >> 1); + int sshift, dshift; + int s_start, s_end, s_inc; + png_uint_32 i; + int jstop = png_pass_inc[pass]; + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if (transformations & PNG_PACKSWAP) + { + sshift = (int)(((row_info->width + 1) & 0x01) << 2); + dshift = (int)(((final_width + 1) & 0x01) << 2); + s_start = 4; + s_end = 0; + s_inc = -4; + } + + else +#endif + { + sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2); + dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2); + s_start = 0; + s_end = 4; + s_inc = 4; + } + + for (i = 0; i < row_info->width; i++) + { + png_byte v = (png_byte)((*sp >> sshift) & 0x0f); + int j; + + for (j = 0; j < jstop; j++) + { + *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff); + *dp |= (png_byte)(v << dshift); + + if (dshift == s_end) + { + dshift = s_start; + dp--; + } + + else + dshift += s_inc; + } + + if (sshift == s_end) + { + sshift = s_start; + sp--; + } + + else + sshift += s_inc; + } + break; + } + + default: + { + png_size_t pixel_bytes = (row_info->pixel_depth >> 3); + + png_bytep sp = row + (png_size_t)(row_info->width - 1) + * pixel_bytes; + + png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes; + + int jstop = png_pass_inc[pass]; + png_uint_32 i; + + for (i = 0; i < row_info->width; i++) + { + png_byte v[8]; + int j; + + png_memcpy(v, sp, pixel_bytes); + + for (j = 0; j < jstop; j++) + { + png_memcpy(dp, v, pixel_bytes); + dp -= pixel_bytes; + } + + sp -= pixel_bytes; + } + break; + } + } + + row_info->width = final_width; + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width); + } +#ifndef PNG_READ_PACKSWAP_SUPPORTED + PNG_UNUSED(transformations) /* Silence compiler warning */ +#endif +} +#endif /* PNG_READ_INTERLACING_SUPPORTED */ + +static void +png_read_filter_row_sub(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_size_t i; + png_size_t istop = row_info->rowbytes; + unsigned int bpp = (row_info->pixel_depth + 7) >> 3; + png_bytep rp = row + bpp; + + PNG_UNUSED(prev_row) + + for (i = bpp; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + (int)(*(rp-bpp))) & 0xff); + rp++; + } +} + +static void +png_read_filter_row_up(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_size_t i; + png_size_t istop = row_info->rowbytes; + png_bytep rp = row; + png_const_bytep pp = prev_row; + + for (i = 0; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff); + rp++; + } +} + +static void +png_read_filter_row_avg(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_size_t i; + png_bytep rp = row; + png_const_bytep pp = prev_row; + unsigned int bpp = (row_info->pixel_depth + 7) >> 3; + png_size_t istop = row_info->rowbytes - bpp; + + for (i = 0; i < bpp; i++) + { + *rp = (png_byte)(((int)(*rp) + + ((int)(*pp++) / 2 )) & 0xff); + + rp++; + } + + for (i = 0; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + + (int)(*pp++ + *(rp-bpp)) / 2 ) & 0xff); + + rp++; + } +} + +static void +png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + png_bytep rp_end = row + row_info->rowbytes; + int a, c; + + /* First pixel/byte */ + c = *prev_row++; + a = *row + c; + *row++ = (png_byte)a; + + /* Remainder */ + while (row < rp_end) + { + int b, pa, pb, pc, p; + + a &= 0xff; /* From previous iteration or start */ + b = *prev_row++; + + p = b - c; + pc = a - c; + +# ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +# else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +# endif + + /* Find the best predictor, the least of pa, pb, pc favoring the earlier + * ones in the case of a tie. + */ + if (pb < pa) pa = pb, a = b; + if (pc < pa) a = c; + + /* Calculate the current pixel in a, and move the previous row pixel to c + * for the next time round the loop + */ + c = b; + a += *row; + *row++ = (png_byte)a; + } +} + +static void +png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row, + png_const_bytep prev_row) +{ + int bpp = (row_info->pixel_depth + 7) >> 3; + png_bytep rp_end = row + bpp; + + /* Process the first pixel in the row completely (this is the same as 'up' + * because there is only one candidate predictor for the first row). + */ + while (row < rp_end) + { + int a = *row + *prev_row++; + *row++ = (png_byte)a; + } + + /* Remainder */ + rp_end += row_info->rowbytes - bpp; + + while (row < rp_end) + { + int a, b, c, pa, pb, pc, p; + + c = *(prev_row - bpp); + a = *(row - bpp); + b = *prev_row++; + + p = b - c; + pc = a - c; + +# ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +# else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +# endif + + if (pb < pa) pa = pb, a = b; + if (pc < pa) a = c; + + c = b; + a += *row; + *row++ = (png_byte)a; + } +} + +#ifdef PNG_ARM_NEON + +#ifdef __linux__ +#include +#include +#include + +static int png_have_hwcap(unsigned cap) +{ + FILE *f = fopen("/proc/self/auxv", "r"); + Elf32_auxv_t aux; + int have_cap = 0; + + if (!f) + return 0; + + while (fread(&aux, sizeof(aux), 1, f) > 0) + { + if (aux.a_type == AT_HWCAP && + aux.a_un.a_val & cap) + { + have_cap = 1; + break; + } + } + + fclose(f); + + return have_cap; +} +#endif /* __linux__ */ + +static void +png_init_filter_functions_neon(png_structp pp, unsigned int bpp) +{ +#ifdef __linux__ + if (!png_have_hwcap(HWCAP_NEON)) + return; +#endif + + pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon; + + if (bpp == 3) + { + pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_neon; + pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_neon; + pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = + png_read_filter_row_paeth3_neon; + } + + else if (bpp == 4) + { + pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_neon; + pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_neon; + pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = + png_read_filter_row_paeth4_neon; + } +} +#endif /* PNG_ARM_NEON */ + +static void +png_init_filter_functions(png_structp pp) +{ + unsigned int bpp = (pp->pixel_depth + 7) >> 3; + + pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub; + pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up; + pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg; + if (bpp == 1) + pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = + png_read_filter_row_paeth_1byte_pixel; + else + pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = + png_read_filter_row_paeth_multibyte_pixel; + +#ifdef PNG_ARM_NEON + png_init_filter_functions_neon(pp, bpp); +#endif +} + +void /* PRIVATE */ +png_read_filter_row(png_structp pp, png_row_infop row_info, png_bytep row, + png_const_bytep prev_row, int filter) +{ + if (pp->read_filter[0] == NULL) + png_init_filter_functions(pp); + if (filter > PNG_FILTER_VALUE_NONE && filter < PNG_FILTER_VALUE_LAST) + pp->read_filter[filter-1](row_info, row, prev_row); +} + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +void /* PRIVATE */ +png_read_finish_row(png_structp png_ptr) +{ +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif /* PNG_READ_INTERLACING_SUPPORTED */ + + png_debug(1, "in png_read_finish_row"); + png_ptr->row_number++; + if (png_ptr->row_number < png_ptr->num_rows) + return; + +#ifdef PNG_READ_INTERLACING_SUPPORTED + if (png_ptr->interlaced) + { + png_ptr->row_number = 0; + + /* TO DO: don't do this if prev_row isn't needed (requires + * read-ahead of the next row's filter byte. + */ + png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); + + do + { + png_ptr->pass++; + + if (png_ptr->pass >= 7) + break; + + png_ptr->iwidth = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + + if (!(png_ptr->transformations & PNG_INTERLACE)) + { + png_ptr->num_rows = (png_ptr->height + + png_pass_yinc[png_ptr->pass] - 1 - + png_pass_ystart[png_ptr->pass]) / + png_pass_yinc[png_ptr->pass]; + } + + else /* if (png_ptr->transformations & PNG_INTERLACE) */ + break; /* libpng deinterlacing sees every row */ + + } while (png_ptr->num_rows == 0 || png_ptr->iwidth == 0); + + if (png_ptr->pass < 7) + return; + } +#endif /* PNG_READ_INTERLACING_SUPPORTED */ + + if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) + { + char extra; + int ret; + + png_ptr->zstream.next_out = (Byte *)&extra; + png_ptr->zstream.avail_out = (uInt)1; + + for (;;) + { + if (!(png_ptr->zstream.avail_in)) + { + while (!png_ptr->idat_size) + { + png_crc_finish(png_ptr, 0); + png_ptr->idat_size = png_read_chunk_header(png_ptr); + if (png_ptr->chunk_name != png_IDAT) + png_error(png_ptr, "Not enough image data"); + } + + png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_in = png_ptr->zbuf; + + if (png_ptr->zbuf_size > png_ptr->idat_size) + png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; + + png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in); + png_ptr->idat_size -= png_ptr->zstream.avail_in; + } + + ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); + + if (ret == Z_STREAM_END) + { + if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in || + png_ptr->idat_size) + png_warning(png_ptr, "Extra compressed data"); + + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + break; + } + + if (ret != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg : + "Decompression Error"); + + if (!(png_ptr->zstream.avail_out)) + { + png_warning(png_ptr, "Extra compressed data"); + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + break; + } + + } + png_ptr->zstream.avail_out = 0; + } + + if (png_ptr->idat_size || png_ptr->zstream.avail_in) + png_warning(png_ptr, "Extra compression data"); + + inflateReset(&png_ptr->zstream); + + png_ptr->mode |= PNG_AFTER_IDAT; +} +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ + +void /* PRIVATE */ +png_read_start_row(png_structp png_ptr) +{ +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif + + int max_pixel_depth; + png_size_t row_bytes; + + png_debug(1, "in png_read_start_row"); + png_ptr->zstream.avail_in = 0; +#ifdef PNG_READ_TRANSFORMS_SUPPORTED + png_init_read_transformations(png_ptr); +#endif +#ifdef PNG_READ_INTERLACING_SUPPORTED + if (png_ptr->interlaced) + { + if (!(png_ptr->transformations & PNG_INTERLACE)) + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - + png_pass_ystart[0]) / png_pass_yinc[0]; + + else + png_ptr->num_rows = png_ptr->height; + + png_ptr->iwidth = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + } + + else +#endif /* PNG_READ_INTERLACING_SUPPORTED */ + { + png_ptr->num_rows = png_ptr->height; + png_ptr->iwidth = png_ptr->width; + } + + max_pixel_depth = png_ptr->pixel_depth; + + /* WARNING: * png_read_transform_info (pngrtran.c) performs a simpliar set of + * calculations to calculate the final pixel depth, then + * png_do_read_transforms actually does the transforms. This means that the + * code which effectively calculates this value is actually repeated in three + * separate places. They must all match. Innocent changes to the order of + * transformations can and will break libpng in a way that causes memory + * overwrites. + * + * TODO: fix this. + */ +#ifdef PNG_READ_PACK_SUPPORTED + if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8) + max_pixel_depth = 8; +#endif + +#ifdef PNG_READ_EXPAND_SUPPORTED + if (png_ptr->transformations & PNG_EXPAND) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (png_ptr->num_trans) + max_pixel_depth = 32; + + else + max_pixel_depth = 24; + } + + else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) + { + if (max_pixel_depth < 8) + max_pixel_depth = 8; + + if (png_ptr->num_trans) + max_pixel_depth *= 2; + } + + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) + { + if (png_ptr->num_trans) + { + max_pixel_depth *= 4; + max_pixel_depth /= 3; + } + } + } +#endif + +#ifdef PNG_READ_EXPAND_16_SUPPORTED + if (png_ptr->transformations & PNG_EXPAND_16) + { +# ifdef PNG_READ_EXPAND_SUPPORTED + /* In fact it is an error if it isn't supported, but checking is + * the safe way. + */ + if (png_ptr->transformations & PNG_EXPAND) + { + if (png_ptr->bit_depth < 16) + max_pixel_depth *= 2; + } + else +# endif + png_ptr->transformations &= ~PNG_EXPAND_16; + } +#endif + +#ifdef PNG_READ_FILLER_SUPPORTED + if (png_ptr->transformations & (PNG_FILLER)) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) + { + if (max_pixel_depth <= 8) + max_pixel_depth = 16; + + else + max_pixel_depth = 32; + } + + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB || + png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (max_pixel_depth <= 32) + max_pixel_depth = 32; + + else + max_pixel_depth = 64; + } + } +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + if (png_ptr->transformations & PNG_GRAY_TO_RGB) + { + if ( +#ifdef PNG_READ_EXPAND_SUPPORTED + (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) || +#endif +#ifdef PNG_READ_FILLER_SUPPORTED + (png_ptr->transformations & (PNG_FILLER)) || +#endif + png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + if (max_pixel_depth <= 16) + max_pixel_depth = 32; + + else + max_pixel_depth = 64; + } + + else + { + if (max_pixel_depth <= 8) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + max_pixel_depth = 32; + + else + max_pixel_depth = 24; + } + + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + max_pixel_depth = 64; + + else + max_pixel_depth = 48; + } + } +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \ +defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) + if (png_ptr->transformations & PNG_USER_TRANSFORM) + { + int user_pixel_depth = png_ptr->user_transform_depth * + png_ptr->user_transform_channels; + + if (user_pixel_depth > max_pixel_depth) + max_pixel_depth = user_pixel_depth; + } +#endif + + /* This value is stored in png_struct and double checked in the row read + * code. + */ + png_ptr->maximum_pixel_depth = (png_byte)max_pixel_depth; + png_ptr->transformed_pixel_depth = 0; /* calculated on demand */ + + /* Align the width on the next larger 8 pixels. Mainly used + * for interlacing + */ + row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7)); + /* Calculate the maximum bytes needed, adding a byte and a pixel + * for safety's sake + */ + row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) + + 1 + ((max_pixel_depth + 7) >> 3); + +#ifdef PNG_MAX_MALLOC_64K + if (row_bytes > (png_uint_32)65536L) + png_error(png_ptr, "This image requires a row greater than 64KB"); +#endif + + if (row_bytes + 48 > png_ptr->old_big_row_buf_size) + { + png_free(png_ptr, png_ptr->big_row_buf); + png_free(png_ptr, png_ptr->big_prev_row); + + if (png_ptr->interlaced) + png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr, + row_bytes + 48); + + else + png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48); + + png_ptr->big_prev_row = (png_bytep)png_malloc(png_ptr, row_bytes + 48); + +#ifdef PNG_ALIGNED_MEMORY_SUPPORTED + /* Use 16-byte aligned memory for row_buf with at least 16 bytes + * of padding before and after row_buf; treat prev_row similarly. + * NOTE: the alignment is to the start of the pixels, one beyond the start + * of the buffer, because of the filter byte. Prior to libpng 1.5.6 this + * was incorrect; the filter byte was aligned, which had the exact + * opposite effect of that intended. + */ + { + png_bytep temp = png_ptr->big_row_buf + 32; + int extra = (int)((temp - (png_bytep)0) & 0x0f); + png_ptr->row_buf = temp - extra - 1/*filter byte*/; + + temp = png_ptr->big_prev_row + 32; + extra = (int)((temp - (png_bytep)0) & 0x0f); + png_ptr->prev_row = temp - extra - 1/*filter byte*/; + } + +#else + /* Use 31 bytes of padding before and 17 bytes after row_buf. */ + png_ptr->row_buf = png_ptr->big_row_buf + 31; + png_ptr->prev_row = png_ptr->big_prev_row + 31; +#endif + png_ptr->old_big_row_buf_size = row_bytes + 48; + } + +#ifdef PNG_MAX_MALLOC_64K + if (png_ptr->rowbytes > 65535) + png_error(png_ptr, "This image requires a row greater than 64KB"); + +#endif + if (png_ptr->rowbytes > (PNG_SIZE_MAX - 1)) + png_error(png_ptr, "Row has too many bytes to allocate in memory"); + + png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); + + png_debug1(3, "width = %u,", png_ptr->width); + png_debug1(3, "height = %u,", png_ptr->height); + png_debug1(3, "iwidth = %u,", png_ptr->iwidth); + png_debug1(3, "num_rows = %u,", png_ptr->num_rows); + png_debug1(3, "rowbytes = %lu,", (unsigned long)png_ptr->rowbytes); + png_debug1(3, "irowbytes = %lu", + (unsigned long)PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1); + + png_ptr->flags |= PNG_FLAG_ROW_INIT; +} +#endif /* PNG_READ_SUPPORTED */ diff --git a/Source/LibPNG/pngset.c b/Source/LibPNG/pngset.c index fc99f5f..8c07eec 100644 --- a/Source/LibPNG/pngset.c +++ b/Source/LibPNG/pngset.c @@ -1,1311 +1,1311 @@ - -/* pngset.c - storage of image information into info struct - * - * Last changed in libpng 1.5.11 [June 14, 2012] - * Copyright (c) 1998-2012 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - * - * The functions here are used during reads to store data from the file - * into the info struct, and during writes to store application data - * into the info struct for writing into the file. This abstracts the - * info struct and allows us to change the structure in the future. - */ - -#include "pngpriv.h" - -#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) - -#ifdef PNG_bKGD_SUPPORTED -void PNGAPI -png_set_bKGD(png_structp png_ptr, png_infop info_ptr, - png_const_color_16p background) -{ - png_debug1(1, "in %s storage function", "bKGD"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16)); - info_ptr->valid |= PNG_INFO_bKGD; -} -#endif - -#ifdef PNG_cHRM_SUPPORTED -void PNGFAPI -png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, - png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, - png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, - png_fixed_point blue_x, png_fixed_point blue_y) -{ - png_debug1(1, "in %s storage function", "cHRM fixed"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - -# ifdef PNG_CHECK_cHRM_SUPPORTED - if (png_check_cHRM_fixed(png_ptr, - white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y)) -# endif - { - info_ptr->x_white = white_x; - info_ptr->y_white = white_y; - info_ptr->x_red = red_x; - info_ptr->y_red = red_y; - info_ptr->x_green = green_x; - info_ptr->y_green = green_y; - info_ptr->x_blue = blue_x; - info_ptr->y_blue = blue_y; - info_ptr->valid |= PNG_INFO_cHRM; - } -} - -void PNGFAPI -png_set_cHRM_XYZ_fixed(png_structp png_ptr, png_infop info_ptr, - png_fixed_point int_red_X, png_fixed_point int_red_Y, - png_fixed_point int_red_Z, png_fixed_point int_green_X, - png_fixed_point int_green_Y, png_fixed_point int_green_Z, - png_fixed_point int_blue_X, png_fixed_point int_blue_Y, - png_fixed_point int_blue_Z) -{ - png_XYZ XYZ; - png_xy xy; - - png_debug1(1, "in %s storage function", "cHRM XYZ fixed"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - XYZ.redX = int_red_X; - XYZ.redY = int_red_Y; - XYZ.redZ = int_red_Z; - XYZ.greenX = int_green_X; - XYZ.greenY = int_green_Y; - XYZ.greenZ = int_green_Z; - XYZ.blueX = int_blue_X; - XYZ.blueY = int_blue_Y; - XYZ.blueZ = int_blue_Z; - - if (png_xy_from_XYZ(&xy, XYZ)) - png_error(png_ptr, "XYZ values out of representable range"); - - png_set_cHRM_fixed(png_ptr, info_ptr, xy.whitex, xy.whitey, xy.redx, xy.redy, - xy.greenx, xy.greeny, xy.bluex, xy.bluey); -} - -# ifdef PNG_FLOATING_POINT_SUPPORTED -void PNGAPI -png_set_cHRM(png_structp png_ptr, png_infop info_ptr, - double white_x, double white_y, double red_x, double red_y, - double green_x, double green_y, double blue_x, double blue_y) -{ - png_set_cHRM_fixed(png_ptr, info_ptr, - png_fixed(png_ptr, white_x, "cHRM White X"), - png_fixed(png_ptr, white_y, "cHRM White Y"), - png_fixed(png_ptr, red_x, "cHRM Red X"), - png_fixed(png_ptr, red_y, "cHRM Red Y"), - png_fixed(png_ptr, green_x, "cHRM Green X"), - png_fixed(png_ptr, green_y, "cHRM Green Y"), - png_fixed(png_ptr, blue_x, "cHRM Blue X"), - png_fixed(png_ptr, blue_y, "cHRM Blue Y")); -} - -void PNGAPI -png_set_cHRM_XYZ(png_structp png_ptr, png_infop info_ptr, double red_X, - double red_Y, double red_Z, double green_X, double green_Y, double green_Z, - double blue_X, double blue_Y, double blue_Z) -{ - png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, - png_fixed(png_ptr, red_X, "cHRM Red X"), - png_fixed(png_ptr, red_Y, "cHRM Red Y"), - png_fixed(png_ptr, red_Z, "cHRM Red Z"), - png_fixed(png_ptr, green_X, "cHRM Red X"), - png_fixed(png_ptr, green_Y, "cHRM Red Y"), - png_fixed(png_ptr, green_Z, "cHRM Red Z"), - png_fixed(png_ptr, blue_X, "cHRM Red X"), - png_fixed(png_ptr, blue_Y, "cHRM Red Y"), - png_fixed(png_ptr, blue_Z, "cHRM Red Z")); -} -# endif /* PNG_FLOATING_POINT_SUPPORTED */ - -#endif /* PNG_cHRM_SUPPORTED */ - -#ifdef PNG_gAMA_SUPPORTED -void PNGFAPI -png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point - file_gamma) -{ - png_debug1(1, "in %s storage function", "gAMA"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - /* Changed in libpng-1.5.4 to limit the values to ensure overflow can't - * occur. Since the fixed point representation is assymetrical it is - * possible for 1/gamma to overflow the limit of 21474 and this means the - * gamma value must be at least 5/100000 and hence at most 20000.0. For - * safety the limits here are a little narrower. The values are 0.00016 to - * 6250.0, which are truly ridiculous gamma values (and will produce - * displays that are all black or all white.) - */ - if (file_gamma < 16 || file_gamma > 625000000) - png_warning(png_ptr, "Out of range gamma value ignored"); - - else - { - info_ptr->gamma = file_gamma; - info_ptr->valid |= PNG_INFO_gAMA; - } -} - -# ifdef PNG_FLOATING_POINT_SUPPORTED -void PNGAPI -png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) -{ - png_set_gAMA_fixed(png_ptr, info_ptr, png_fixed(png_ptr, file_gamma, - "png_set_gAMA")); -} -# endif -#endif - -#ifdef PNG_hIST_SUPPORTED -void PNGAPI -png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_const_uint_16p hist) -{ - int i; - - png_debug1(1, "in %s storage function", "hIST"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - if (info_ptr->num_palette == 0 || info_ptr->num_palette - > PNG_MAX_PALETTE_LENGTH) - { - png_warning(png_ptr, - "Invalid palette size, hIST allocation skipped"); - - return; - } - - png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0); - - /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in - * version 1.2.1 - */ - png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr, - PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16)); - - if (png_ptr->hist == NULL) - { - png_warning(png_ptr, "Insufficient memory for hIST chunk data"); - return; - } - - for (i = 0; i < info_ptr->num_palette; i++) - png_ptr->hist[i] = hist[i]; - - info_ptr->hist = png_ptr->hist; - info_ptr->valid |= PNG_INFO_hIST; - info_ptr->free_me |= PNG_FREE_HIST; -} -#endif - -void PNGAPI -png_set_IHDR(png_structp png_ptr, png_infop info_ptr, - png_uint_32 width, png_uint_32 height, int bit_depth, - int color_type, int interlace_type, int compression_type, - int filter_type) -{ - png_debug1(1, "in %s storage function", "IHDR"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - info_ptr->width = width; - info_ptr->height = height; - info_ptr->bit_depth = (png_byte)bit_depth; - info_ptr->color_type = (png_byte)color_type; - info_ptr->compression_type = (png_byte)compression_type; - info_ptr->filter_type = (png_byte)filter_type; - info_ptr->interlace_type = (png_byte)interlace_type; - - png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, - info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, - info_ptr->compression_type, info_ptr->filter_type); - - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - info_ptr->channels = 1; - - else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) - info_ptr->channels = 3; - - else - info_ptr->channels = 1; - - if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) - info_ptr->channels++; - - info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); - - /* Check for potential overflow */ - if (width > - (PNG_UINT_32_MAX >> 3) /* 8-byte RRGGBBAA pixels */ - - 48 /* bigrowbuf hack */ - - 1 /* filter byte */ - - 7*8 /* rounding of width to multiple of 8 pixels */ - - 8) /* extra max_pixel_depth pad */ - info_ptr->rowbytes = 0; - else - info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); -} - -#ifdef PNG_oFFs_SUPPORTED -void PNGAPI -png_set_oFFs(png_structp png_ptr, png_infop info_ptr, - png_int_32 offset_x, png_int_32 offset_y, int unit_type) -{ - png_debug1(1, "in %s storage function", "oFFs"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - info_ptr->x_offset = offset_x; - info_ptr->y_offset = offset_y; - info_ptr->offset_unit_type = (png_byte)unit_type; - info_ptr->valid |= PNG_INFO_oFFs; -} -#endif - -#ifdef PNG_pCAL_SUPPORTED -void PNGAPI -png_set_pCAL(png_structp png_ptr, png_infop info_ptr, - png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, - int nparams, png_const_charp units, png_charpp params) -{ - png_size_t length; - int i; - - png_debug1(1, "in %s storage function", "pCAL"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - length = png_strlen(purpose) + 1; - png_debug1(3, "allocating purpose for info (%lu bytes)", - (unsigned long)length); - - /* TODO: validate format of calibration name and unit name */ - - /* Check that the type matches the specification. */ - if (type < 0 || type > 3) - png_error(png_ptr, "Invalid pCAL equation type"); - - /* Validate params[nparams] */ - for (i=0; ipcal_purpose = (png_charp)png_malloc_warn(png_ptr, length); - - if (info_ptr->pcal_purpose == NULL) - { - png_warning(png_ptr, "Insufficient memory for pCAL purpose"); - return; - } - - png_memcpy(info_ptr->pcal_purpose, purpose, length); - - png_debug(3, "storing X0, X1, type, and nparams in info"); - info_ptr->pcal_X0 = X0; - info_ptr->pcal_X1 = X1; - info_ptr->pcal_type = (png_byte)type; - info_ptr->pcal_nparams = (png_byte)nparams; - - length = png_strlen(units) + 1; - png_debug1(3, "allocating units for info (%lu bytes)", - (unsigned long)length); - - info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length); - - if (info_ptr->pcal_units == NULL) - { - png_warning(png_ptr, "Insufficient memory for pCAL units"); - return; - } - - png_memcpy(info_ptr->pcal_units, units, length); - - info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr, - (png_size_t)((nparams + 1) * png_sizeof(png_charp))); - - if (info_ptr->pcal_params == NULL) - { - png_warning(png_ptr, "Insufficient memory for pCAL params"); - return; - } - - png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp)); - - for (i = 0; i < nparams; i++) - { - length = png_strlen(params[i]) + 1; - png_debug2(3, "allocating parameter %d for info (%lu bytes)", i, - (unsigned long)length); - - info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length); - - if (info_ptr->pcal_params[i] == NULL) - { - png_warning(png_ptr, "Insufficient memory for pCAL parameter"); - return; - } - - png_memcpy(info_ptr->pcal_params[i], params[i], length); - } - - info_ptr->valid |= PNG_INFO_pCAL; - info_ptr->free_me |= PNG_FREE_PCAL; -} -#endif - -#ifdef PNG_sCAL_SUPPORTED -void PNGAPI -png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, - int unit, png_const_charp swidth, png_const_charp sheight) -{ - png_size_t lengthw = 0, lengthh = 0; - - png_debug1(1, "in %s storage function", "sCAL"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - /* Double check the unit (should never get here with an invalid - * unit unless this is an API call.) - */ - if (unit != 1 && unit != 2) - png_error(png_ptr, "Invalid sCAL unit"); - - if (swidth == NULL || (lengthw = png_strlen(swidth)) == 0 || - swidth[0] == 45 /* '-' */ || !png_check_fp_string(swidth, lengthw)) - png_error(png_ptr, "Invalid sCAL width"); - - if (sheight == NULL || (lengthh = png_strlen(sheight)) == 0 || - sheight[0] == 45 /* '-' */ || !png_check_fp_string(sheight, lengthh)) - png_error(png_ptr, "Invalid sCAL height"); - - info_ptr->scal_unit = (png_byte)unit; - - ++lengthw; - - png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw); - - info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, lengthw); - - if (info_ptr->scal_s_width == NULL) - { - png_warning(png_ptr, "Memory allocation failed while processing sCAL"); - return; - } - - png_memcpy(info_ptr->scal_s_width, swidth, lengthw); - - ++lengthh; - - png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh); - - info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, lengthh); - - if (info_ptr->scal_s_height == NULL) - { - png_free (png_ptr, info_ptr->scal_s_width); - info_ptr->scal_s_width = NULL; - - png_warning(png_ptr, "Memory allocation failed while processing sCAL"); - return; - } - - png_memcpy(info_ptr->scal_s_height, sheight, lengthh); - - info_ptr->valid |= PNG_INFO_sCAL; - info_ptr->free_me |= PNG_FREE_SCAL; -} - -# ifdef PNG_FLOATING_POINT_SUPPORTED -void PNGAPI -png_set_sCAL(png_structp png_ptr, png_infop info_ptr, int unit, double width, - double height) -{ - png_debug1(1, "in %s storage function", "sCAL"); - - /* Check the arguments. */ - if (width <= 0) - png_warning(png_ptr, "Invalid sCAL width ignored"); - - else if (height <= 0) - png_warning(png_ptr, "Invalid sCAL height ignored"); - - else - { - /* Convert 'width' and 'height' to ASCII. */ - char swidth[PNG_sCAL_MAX_DIGITS+1]; - char sheight[PNG_sCAL_MAX_DIGITS+1]; - - png_ascii_from_fp(png_ptr, swidth, sizeof swidth, width, - PNG_sCAL_PRECISION); - png_ascii_from_fp(png_ptr, sheight, sizeof sheight, height, - PNG_sCAL_PRECISION); - - png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight); - } -} -# endif - -# ifdef PNG_FIXED_POINT_SUPPORTED -void PNGAPI -png_set_sCAL_fixed(png_structp png_ptr, png_infop info_ptr, int unit, - png_fixed_point width, png_fixed_point height) -{ - png_debug1(1, "in %s storage function", "sCAL"); - - /* Check the arguments. */ - if (width <= 0) - png_warning(png_ptr, "Invalid sCAL width ignored"); - - else if (height <= 0) - png_warning(png_ptr, "Invalid sCAL height ignored"); - - else - { - /* Convert 'width' and 'height' to ASCII. */ - char swidth[PNG_sCAL_MAX_DIGITS+1]; - char sheight[PNG_sCAL_MAX_DIGITS+1]; - - png_ascii_from_fixed(png_ptr, swidth, sizeof swidth, width); - png_ascii_from_fixed(png_ptr, sheight, sizeof sheight, height); - - png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight); - } -} -# endif -#endif - -#ifdef PNG_pHYs_SUPPORTED -void PNGAPI -png_set_pHYs(png_structp png_ptr, png_infop info_ptr, - png_uint_32 res_x, png_uint_32 res_y, int unit_type) -{ - png_debug1(1, "in %s storage function", "pHYs"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - info_ptr->x_pixels_per_unit = res_x; - info_ptr->y_pixels_per_unit = res_y; - info_ptr->phys_unit_type = (png_byte)unit_type; - info_ptr->valid |= PNG_INFO_pHYs; -} -#endif - -void PNGAPI -png_set_PLTE(png_structp png_ptr, png_infop info_ptr, - png_const_colorp palette, int num_palette) -{ - - png_debug1(1, "in %s storage function", "PLTE"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH) - { - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - png_error(png_ptr, "Invalid palette length"); - - else - { - png_warning(png_ptr, "Invalid palette length"); - return; - } - } - - /* It may not actually be necessary to set png_ptr->palette here; - * we do it for backward compatibility with the way the png_handle_tRNS - * function used to do the allocation. - */ - png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); - - /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead - * of num_palette entries, in case of an invalid PNG file that has - * too-large sample values. - */ - png_ptr->palette = (png_colorp)png_calloc(png_ptr, - PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); - - png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color)); - info_ptr->palette = png_ptr->palette; - info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; - - info_ptr->free_me |= PNG_FREE_PLTE; - - info_ptr->valid |= PNG_INFO_PLTE; -} - -#ifdef PNG_sBIT_SUPPORTED -void PNGAPI -png_set_sBIT(png_structp png_ptr, png_infop info_ptr, - png_const_color_8p sig_bit) -{ - png_debug1(1, "in %s storage function", "sBIT"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8)); - info_ptr->valid |= PNG_INFO_sBIT; -} -#endif - -#ifdef PNG_sRGB_SUPPORTED -void PNGAPI -png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int srgb_intent) -{ - png_debug1(1, "in %s storage function", "sRGB"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - info_ptr->srgb_intent = (png_byte)srgb_intent; - info_ptr->valid |= PNG_INFO_sRGB; -} - -void PNGAPI -png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, - int srgb_intent) -{ - png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - png_set_sRGB(png_ptr, info_ptr, srgb_intent); - -# ifdef PNG_gAMA_SUPPORTED - png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_sRGB_INVERSE); -# endif - -# ifdef PNG_cHRM_SUPPORTED - png_set_cHRM_fixed(png_ptr, info_ptr, - /* color x y */ - /* white */ 31270, 32900, - /* red */ 64000, 33000, - /* green */ 30000, 60000, - /* blue */ 15000, 6000 - ); -# endif /* cHRM */ -} -#endif /* sRGB */ - - -#ifdef PNG_iCCP_SUPPORTED -void PNGAPI -png_set_iCCP(png_structp png_ptr, png_infop info_ptr, - png_const_charp name, int compression_type, - png_const_bytep profile, png_uint_32 proflen) -{ - png_charp new_iccp_name; - png_bytep new_iccp_profile; - png_size_t length; - - png_debug1(1, "in %s storage function", "iCCP"); - - if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL) - return; - - length = png_strlen(name)+1; - new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length); - - if (new_iccp_name == NULL) - { - png_warning(png_ptr, "Insufficient memory to process iCCP chunk"); - return; - } - - png_memcpy(new_iccp_name, name, length); - new_iccp_profile = (png_bytep)png_malloc_warn(png_ptr, proflen); - - if (new_iccp_profile == NULL) - { - png_free (png_ptr, new_iccp_name); - png_warning(png_ptr, - "Insufficient memory to process iCCP profile"); - return; - } - - png_memcpy(new_iccp_profile, profile, (png_size_t)proflen); - - png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0); - - info_ptr->iccp_proflen = proflen; - info_ptr->iccp_name = new_iccp_name; - info_ptr->iccp_profile = new_iccp_profile; - /* Compression is always zero but is here so the API and info structure - * does not have to change if we introduce multiple compression types - */ - info_ptr->iccp_compression = (png_byte)compression_type; - info_ptr->free_me |= PNG_FREE_ICCP; - info_ptr->valid |= PNG_INFO_iCCP; -} -#endif - -#ifdef PNG_TEXT_SUPPORTED -void PNGAPI -png_set_text(png_structp png_ptr, png_infop info_ptr, png_const_textp text_ptr, - int num_text) -{ - int ret; - ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text); - - if (ret) - png_error(png_ptr, "Insufficient memory to store text"); -} - -int /* PRIVATE */ -png_set_text_2(png_structp png_ptr, png_infop info_ptr, - png_const_textp text_ptr, int num_text) -{ - int i; - - png_debug1(1, "in %lx storage function", png_ptr == NULL ? "unexpected" : - (unsigned long)png_ptr->chunk_name); - - if (png_ptr == NULL || info_ptr == NULL || num_text == 0) - return(0); - - /* Make sure we have enough space in the "text" array in info_struct - * to hold all of the incoming text_ptr objects. - */ - if (info_ptr->num_text + num_text > info_ptr->max_text) - { - int old_max_text = info_ptr->max_text; - int old_num_text = info_ptr->num_text; - - if (info_ptr->text != NULL) - { - png_textp old_text; - - info_ptr->max_text = info_ptr->num_text + num_text + 8; - old_text = info_ptr->text; - - info_ptr->text = (png_textp)png_malloc_warn(png_ptr, - (png_size_t)(info_ptr->max_text * png_sizeof(png_text))); - - if (info_ptr->text == NULL) - { - /* Restore to previous condition */ - info_ptr->max_text = old_max_text; - info_ptr->text = old_text; - return(1); - } - - png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max_text * - png_sizeof(png_text))); - png_free(png_ptr, old_text); - } - - else - { - info_ptr->max_text = num_text + 8; - info_ptr->num_text = 0; - info_ptr->text = (png_textp)png_malloc_warn(png_ptr, - (png_size_t)(info_ptr->max_text * png_sizeof(png_text))); - if (info_ptr->text == NULL) - { - /* Restore to previous condition */ - info_ptr->num_text = old_num_text; - info_ptr->max_text = old_max_text; - return(1); - } - info_ptr->free_me |= PNG_FREE_TEXT; - } - - png_debug1(3, "allocated %d entries for info_ptr->text", - info_ptr->max_text); - } - for (i = 0; i < num_text; i++) - { - png_size_t text_length, key_len; - png_size_t lang_len, lang_key_len; - png_textp textp = &(info_ptr->text[info_ptr->num_text]); - - if (text_ptr[i].key == NULL) - continue; - - if (text_ptr[i].compression < PNG_TEXT_COMPRESSION_NONE || - text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST) - { - png_warning(png_ptr, "text compression mode is out of range"); - continue; - } - - key_len = png_strlen(text_ptr[i].key); - - if (text_ptr[i].compression <= 0) - { - lang_len = 0; - lang_key_len = 0; - } - - else -# ifdef PNG_iTXt_SUPPORTED - { - /* Set iTXt data */ - - if (text_ptr[i].lang != NULL) - lang_len = png_strlen(text_ptr[i].lang); - - else - lang_len = 0; - - if (text_ptr[i].lang_key != NULL) - lang_key_len = png_strlen(text_ptr[i].lang_key); - - else - lang_key_len = 0; - } -# else /* PNG_iTXt_SUPPORTED */ - { - png_warning(png_ptr, "iTXt chunk not supported"); - continue; - } -# endif - - if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0') - { - text_length = 0; -# ifdef PNG_iTXt_SUPPORTED - if (text_ptr[i].compression > 0) - textp->compression = PNG_ITXT_COMPRESSION_NONE; - - else -# endif - textp->compression = PNG_TEXT_COMPRESSION_NONE; - } - - else - { - text_length = png_strlen(text_ptr[i].text); - textp->compression = text_ptr[i].compression; - } - - textp->key = (png_charp)png_malloc_warn(png_ptr, - (png_size_t) - (key_len + text_length + lang_len + lang_key_len + 4)); - - if (textp->key == NULL) - return(1); - - png_debug2(2, "Allocated %lu bytes at %p in png_set_text", - (unsigned long)(png_uint_32) - (key_len + lang_len + lang_key_len + text_length + 4), - textp->key); - - png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len)); - *(textp->key + key_len) = '\0'; - - if (text_ptr[i].compression > 0) - { - textp->lang = textp->key + key_len + 1; - png_memcpy(textp->lang, text_ptr[i].lang, lang_len); - *(textp->lang + lang_len) = '\0'; - textp->lang_key = textp->lang + lang_len + 1; - png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len); - *(textp->lang_key + lang_key_len) = '\0'; - textp->text = textp->lang_key + lang_key_len + 1; - } - - else - { - textp->lang=NULL; - textp->lang_key=NULL; - textp->text = textp->key + key_len + 1; - } - - if (text_length) - png_memcpy(textp->text, text_ptr[i].text, - (png_size_t)(text_length)); - - *(textp->text + text_length) = '\0'; - -# ifdef PNG_iTXt_SUPPORTED - if (textp->compression > 0) - { - textp->text_length = 0; - textp->itxt_length = text_length; - } - - else -# endif - { - textp->text_length = text_length; - textp->itxt_length = 0; - } - - info_ptr->num_text++; - png_debug1(3, "transferred text chunk %d", info_ptr->num_text); - } - return(0); -} -#endif - -#ifdef PNG_tIME_SUPPORTED -void PNGAPI -png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_const_timep mod_time) -{ - png_debug1(1, "in %s storage function", "tIME"); - - if (png_ptr == NULL || info_ptr == NULL || - (png_ptr->mode & PNG_WROTE_tIME)) - return; - - if (mod_time->month == 0 || mod_time->month > 12 || - mod_time->day == 0 || mod_time->day > 31 || - mod_time->hour > 23 || mod_time->minute > 59 || - mod_time->second > 60) - { - png_warning(png_ptr, "Ignoring invalid time value"); - return; - } - - png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time)); - info_ptr->valid |= PNG_INFO_tIME; -} -#endif - -#ifdef PNG_tRNS_SUPPORTED -void PNGAPI -png_set_tRNS(png_structp png_ptr, png_infop info_ptr, - png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color) -{ - png_debug1(1, "in %s storage function", "tRNS"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - if (trans_alpha != NULL) - { - /* It may not actually be necessary to set png_ptr->trans_alpha here; - * we do it for backward compatibility with the way the png_handle_tRNS - * function used to do the allocation. - */ - - png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); - - /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ - png_ptr->trans_alpha = info_ptr->trans_alpha = - (png_bytep)png_malloc(png_ptr, (png_size_t)PNG_MAX_PALETTE_LENGTH); - - if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH) - png_memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans); - } - - if (trans_color != NULL) - { - int sample_max = (1 << info_ptr->bit_depth); - - if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY && - (int)trans_color->gray > sample_max) || - (info_ptr->color_type == PNG_COLOR_TYPE_RGB && - ((int)trans_color->red > sample_max || - (int)trans_color->green > sample_max || - (int)trans_color->blue > sample_max))) - png_warning(png_ptr, - "tRNS chunk has out-of-range samples for bit_depth"); - - png_memcpy(&(info_ptr->trans_color), trans_color, - png_sizeof(png_color_16)); - - if (num_trans == 0) - num_trans = 1; - } - - info_ptr->num_trans = (png_uint_16)num_trans; - - if (num_trans != 0) - { - info_ptr->valid |= PNG_INFO_tRNS; - info_ptr->free_me |= PNG_FREE_TRNS; - } -} -#endif - -#ifdef PNG_sPLT_SUPPORTED -void PNGAPI -png_set_sPLT(png_structp png_ptr, - png_infop info_ptr, png_const_sPLT_tp entries, int nentries) -/* - * entries - array of png_sPLT_t structures - * to be added to the list of palettes - * in the info structure. - * - * nentries - number of palette structures to be - * added. - */ -{ - png_sPLT_tp np; - int i; - - if (png_ptr == NULL || info_ptr == NULL) - return; - - np = (png_sPLT_tp)png_malloc_warn(png_ptr, - (info_ptr->splt_palettes_num + nentries) * - (png_size_t)png_sizeof(png_sPLT_t)); - - if (np == NULL) - { - png_warning(png_ptr, "No memory for sPLT palettes"); - return; - } - - png_memcpy(np, info_ptr->splt_palettes, - info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t)); - - png_free(png_ptr, info_ptr->splt_palettes); - info_ptr->splt_palettes=NULL; - - for (i = 0; i < nentries; i++) - { - png_sPLT_tp to = np + info_ptr->splt_palettes_num + i; - png_const_sPLT_tp from = entries + i; - png_size_t length; - - length = png_strlen(from->name) + 1; - to->name = (png_charp)png_malloc_warn(png_ptr, length); - - if (to->name == NULL) - { - png_warning(png_ptr, - "Out of memory while processing sPLT chunk"); - continue; - } - - png_memcpy(to->name, from->name, length); - to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr, - from->nentries * png_sizeof(png_sPLT_entry)); - - if (to->entries == NULL) - { - png_warning(png_ptr, - "Out of memory while processing sPLT chunk"); - png_free(png_ptr, to->name); - to->name = NULL; - continue; - } - - png_memcpy(to->entries, from->entries, - from->nentries * png_sizeof(png_sPLT_entry)); - - to->nentries = from->nentries; - to->depth = from->depth; - } - - info_ptr->splt_palettes = np; - info_ptr->splt_palettes_num += nentries; - info_ptr->valid |= PNG_INFO_sPLT; - info_ptr->free_me |= PNG_FREE_SPLT; -} -#endif /* PNG_sPLT_SUPPORTED */ - -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED -void PNGAPI -png_set_unknown_chunks(png_structp png_ptr, - png_infop info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns) -{ - png_unknown_chunkp np; - int i; - - if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0) - return; - - np = (png_unknown_chunkp)png_malloc_warn(png_ptr, - (png_size_t)(info_ptr->unknown_chunks_num + num_unknowns) * - png_sizeof(png_unknown_chunk)); - - if (np == NULL) - { - png_warning(png_ptr, - "Out of memory while processing unknown chunk"); - return; - } - - png_memcpy(np, info_ptr->unknown_chunks, - (png_size_t)info_ptr->unknown_chunks_num * - png_sizeof(png_unknown_chunk)); - - png_free(png_ptr, info_ptr->unknown_chunks); - info_ptr->unknown_chunks = NULL; - - for (i = 0; i < num_unknowns; i++) - { - png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i; - png_const_unknown_chunkp from = unknowns + i; - - png_memcpy(to->name, from->name, png_sizeof(from->name)); - to->name[png_sizeof(to->name)-1] = '\0'; - to->size = from->size; - - /* Note our location in the read or write sequence */ - to->location = (png_byte)(png_ptr->mode & 0xff); - - if (from->size == 0) - to->data=NULL; - - else - { - to->data = (png_bytep)png_malloc_warn(png_ptr, - (png_size_t)from->size); - - if (to->data == NULL) - { - png_warning(png_ptr, - "Out of memory while processing unknown chunk"); - to->size = 0; - } - - else - png_memcpy(to->data, from->data, from->size); - } - } - - info_ptr->unknown_chunks = np; - info_ptr->unknown_chunks_num += num_unknowns; - info_ptr->free_me |= PNG_FREE_UNKN; -} - -void PNGAPI -png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr, - int chunk, int location) -{ - if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk < - info_ptr->unknown_chunks_num) - info_ptr->unknown_chunks[chunk].location = (png_byte)location; -} -#endif - - -#ifdef PNG_MNG_FEATURES_SUPPORTED -png_uint_32 PNGAPI -png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features) -{ - png_debug(1, "in png_permit_mng_features"); - - if (png_ptr == NULL) - return (png_uint_32)0; - - png_ptr->mng_features_permitted = - (png_byte)(mng_features & PNG_ALL_MNG_FEATURES); - - return (png_uint_32)png_ptr->mng_features_permitted; -} -#endif - -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED -void PNGAPI -png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_const_bytep - chunk_list, int num_chunks) -{ - png_bytep new_list, p; - int i, old_num_chunks; - if (png_ptr == NULL) - return; - - if (num_chunks == 0) - { - if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE) - png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS; - - else - png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS; - - if (keep == PNG_HANDLE_CHUNK_ALWAYS) - png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS; - - else - png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS; - - return; - } - - if (chunk_list == NULL) - return; - - old_num_chunks = png_ptr->num_chunk_list; - new_list=(png_bytep)png_malloc(png_ptr, - (png_size_t)(5*(num_chunks + old_num_chunks))); - - if (png_ptr->chunk_list != NULL) - { - png_memcpy(new_list, png_ptr->chunk_list, - (png_size_t)(5*old_num_chunks)); - png_free(png_ptr, png_ptr->chunk_list); - png_ptr->chunk_list=NULL; - } - - png_memcpy(new_list + 5*old_num_chunks, chunk_list, - (png_size_t)(5*num_chunks)); - - for (p = new_list + 5*old_num_chunks + 4, i = 0; inum_chunk_list = old_num_chunks + num_chunks; - png_ptr->chunk_list = new_list; - png_ptr->free_me |= PNG_FREE_LIST; -} -#endif - -#ifdef PNG_READ_USER_CHUNKS_SUPPORTED -void PNGAPI -png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr, - png_user_chunk_ptr read_user_chunk_fn) -{ - png_debug(1, "in png_set_read_user_chunk_fn"); - - if (png_ptr == NULL) - return; - - png_ptr->read_user_chunk_fn = read_user_chunk_fn; - png_ptr->user_chunk_ptr = user_chunk_ptr; -} -#endif - -#ifdef PNG_INFO_IMAGE_SUPPORTED -void PNGAPI -png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers) -{ - png_debug1(1, "in %s storage function", "rows"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers)) - png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); - - info_ptr->row_pointers = row_pointers; - - if (row_pointers) - info_ptr->valid |= PNG_INFO_IDAT; -} -#endif - -void PNGAPI -png_set_compression_buffer_size(png_structp png_ptr, png_size_t size) -{ - if (png_ptr == NULL) - return; - - png_free(png_ptr, png_ptr->zbuf); - - if (size > ZLIB_IO_MAX) - { - png_warning(png_ptr, "Attempt to set buffer size beyond max ignored"); - png_ptr->zbuf_size = ZLIB_IO_MAX; - size = ZLIB_IO_MAX; /* must fit */ - } - - else - png_ptr->zbuf_size = (uInt)size; - - png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size); - - /* The following ensures a relatively safe failure if this gets called while - * the buffer is actually in use. - */ - png_ptr->zstream.next_out = png_ptr->zbuf; - png_ptr->zstream.avail_out = 0; - png_ptr->zstream.avail_in = 0; -} - -void PNGAPI -png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) -{ - if (png_ptr && info_ptr) - info_ptr->valid &= ~mask; -} - - - -#ifdef PNG_SET_USER_LIMITS_SUPPORTED -/* This function was added to libpng 1.2.6 */ -void PNGAPI -png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, - png_uint_32 user_height_max) -{ - /* Images with dimensions larger than these limits will be - * rejected by png_set_IHDR(). To accept any PNG datastream - * regardless of dimensions, set both limits to 0x7ffffffL. - */ - if (png_ptr == NULL) - return; - - png_ptr->user_width_max = user_width_max; - png_ptr->user_height_max = user_height_max; -} - -/* This function was added to libpng 1.4.0 */ -void PNGAPI -png_set_chunk_cache_max (png_structp png_ptr, - png_uint_32 user_chunk_cache_max) -{ - if (png_ptr) - png_ptr->user_chunk_cache_max = user_chunk_cache_max; -} - -/* This function was added to libpng 1.4.1 */ -void PNGAPI -png_set_chunk_malloc_max (png_structp png_ptr, - png_alloc_size_t user_chunk_malloc_max) -{ - if (png_ptr) - png_ptr->user_chunk_malloc_max = user_chunk_malloc_max; -} -#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ - - -#ifdef PNG_BENIGN_ERRORS_SUPPORTED -void PNGAPI -png_set_benign_errors(png_structp png_ptr, int allowed) -{ - png_debug(1, "in png_set_benign_errors"); - - if (allowed) - png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; - - else - png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN; -} -#endif /* PNG_BENIGN_ERRORS_SUPPORTED */ - -#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED -/* Whether to report invalid palette index; added at libng-1.5.10 - * allowed - one of 0: disable; 1: enable - */ -void PNGAPI -png_set_check_for_invalid_index(png_structp png_ptr, int allowed) -{ - png_debug(1, "in png_set_check_for_invalid_index"); - - if (allowed) - png_ptr->num_palette_max = 0; - - else - png_ptr->num_palette_max = -1; -} -#endif - -#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ + +/* pngset.c - storage of image information into info struct + * + * Last changed in libpng 1.5.11 [June 14, 2012] + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * The functions here are used during reads to store data from the file + * into the info struct, and during writes to store application data + * into the info struct for writing into the file. This abstracts the + * info struct and allows us to change the structure in the future. + */ + +#include "pngpriv.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +#ifdef PNG_bKGD_SUPPORTED +void PNGAPI +png_set_bKGD(png_structp png_ptr, png_infop info_ptr, + png_const_color_16p background) +{ + png_debug1(1, "in %s storage function", "bKGD"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16)); + info_ptr->valid |= PNG_INFO_bKGD; +} +#endif + +#ifdef PNG_cHRM_SUPPORTED +void PNGFAPI +png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, + png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, + png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, + png_fixed_point blue_x, png_fixed_point blue_y) +{ + png_debug1(1, "in %s storage function", "cHRM fixed"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + +# ifdef PNG_CHECK_cHRM_SUPPORTED + if (png_check_cHRM_fixed(png_ptr, + white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y)) +# endif + { + info_ptr->x_white = white_x; + info_ptr->y_white = white_y; + info_ptr->x_red = red_x; + info_ptr->y_red = red_y; + info_ptr->x_green = green_x; + info_ptr->y_green = green_y; + info_ptr->x_blue = blue_x; + info_ptr->y_blue = blue_y; + info_ptr->valid |= PNG_INFO_cHRM; + } +} + +void PNGFAPI +png_set_cHRM_XYZ_fixed(png_structp png_ptr, png_infop info_ptr, + png_fixed_point int_red_X, png_fixed_point int_red_Y, + png_fixed_point int_red_Z, png_fixed_point int_green_X, + png_fixed_point int_green_Y, png_fixed_point int_green_Z, + png_fixed_point int_blue_X, png_fixed_point int_blue_Y, + png_fixed_point int_blue_Z) +{ + png_XYZ XYZ; + png_xy xy; + + png_debug1(1, "in %s storage function", "cHRM XYZ fixed"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + XYZ.redX = int_red_X; + XYZ.redY = int_red_Y; + XYZ.redZ = int_red_Z; + XYZ.greenX = int_green_X; + XYZ.greenY = int_green_Y; + XYZ.greenZ = int_green_Z; + XYZ.blueX = int_blue_X; + XYZ.blueY = int_blue_Y; + XYZ.blueZ = int_blue_Z; + + if (png_xy_from_XYZ(&xy, XYZ)) + png_error(png_ptr, "XYZ values out of representable range"); + + png_set_cHRM_fixed(png_ptr, info_ptr, xy.whitex, xy.whitey, xy.redx, xy.redy, + xy.greenx, xy.greeny, xy.bluex, xy.bluey); +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_cHRM(png_structp png_ptr, png_infop info_ptr, + double white_x, double white_y, double red_x, double red_y, + double green_x, double green_y, double blue_x, double blue_y) +{ + png_set_cHRM_fixed(png_ptr, info_ptr, + png_fixed(png_ptr, white_x, "cHRM White X"), + png_fixed(png_ptr, white_y, "cHRM White Y"), + png_fixed(png_ptr, red_x, "cHRM Red X"), + png_fixed(png_ptr, red_y, "cHRM Red Y"), + png_fixed(png_ptr, green_x, "cHRM Green X"), + png_fixed(png_ptr, green_y, "cHRM Green Y"), + png_fixed(png_ptr, blue_x, "cHRM Blue X"), + png_fixed(png_ptr, blue_y, "cHRM Blue Y")); +} + +void PNGAPI +png_set_cHRM_XYZ(png_structp png_ptr, png_infop info_ptr, double red_X, + double red_Y, double red_Z, double green_X, double green_Y, double green_Z, + double blue_X, double blue_Y, double blue_Z) +{ + png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, + png_fixed(png_ptr, red_X, "cHRM Red X"), + png_fixed(png_ptr, red_Y, "cHRM Red Y"), + png_fixed(png_ptr, red_Z, "cHRM Red Z"), + png_fixed(png_ptr, green_X, "cHRM Red X"), + png_fixed(png_ptr, green_Y, "cHRM Red Y"), + png_fixed(png_ptr, green_Z, "cHRM Red Z"), + png_fixed(png_ptr, blue_X, "cHRM Red X"), + png_fixed(png_ptr, blue_Y, "cHRM Red Y"), + png_fixed(png_ptr, blue_Z, "cHRM Red Z")); +} +# endif /* PNG_FLOATING_POINT_SUPPORTED */ + +#endif /* PNG_cHRM_SUPPORTED */ + +#ifdef PNG_gAMA_SUPPORTED +void PNGFAPI +png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point + file_gamma) +{ + png_debug1(1, "in %s storage function", "gAMA"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + /* Changed in libpng-1.5.4 to limit the values to ensure overflow can't + * occur. Since the fixed point representation is assymetrical it is + * possible for 1/gamma to overflow the limit of 21474 and this means the + * gamma value must be at least 5/100000 and hence at most 20000.0. For + * safety the limits here are a little narrower. The values are 0.00016 to + * 6250.0, which are truly ridiculous gamma values (and will produce + * displays that are all black or all white.) + */ + if (file_gamma < 16 || file_gamma > 625000000) + png_warning(png_ptr, "Out of range gamma value ignored"); + + else + { + info_ptr->gamma = file_gamma; + info_ptr->valid |= PNG_INFO_gAMA; + } +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) +{ + png_set_gAMA_fixed(png_ptr, info_ptr, png_fixed(png_ptr, file_gamma, + "png_set_gAMA")); +} +# endif +#endif + +#ifdef PNG_hIST_SUPPORTED +void PNGAPI +png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_const_uint_16p hist) +{ + int i; + + png_debug1(1, "in %s storage function", "hIST"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (info_ptr->num_palette == 0 || info_ptr->num_palette + > PNG_MAX_PALETTE_LENGTH) + { + png_warning(png_ptr, + "Invalid palette size, hIST allocation skipped"); + + return; + } + + png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0); + + /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in + * version 1.2.1 + */ + png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr, + PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16)); + + if (png_ptr->hist == NULL) + { + png_warning(png_ptr, "Insufficient memory for hIST chunk data"); + return; + } + + for (i = 0; i < info_ptr->num_palette; i++) + png_ptr->hist[i] = hist[i]; + + info_ptr->hist = png_ptr->hist; + info_ptr->valid |= PNG_INFO_hIST; + info_ptr->free_me |= PNG_FREE_HIST; +} +#endif + +void PNGAPI +png_set_IHDR(png_structp png_ptr, png_infop info_ptr, + png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_type, int compression_type, + int filter_type) +{ + png_debug1(1, "in %s storage function", "IHDR"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->width = width; + info_ptr->height = height; + info_ptr->bit_depth = (png_byte)bit_depth; + info_ptr->color_type = (png_byte)color_type; + info_ptr->compression_type = (png_byte)compression_type; + info_ptr->filter_type = (png_byte)filter_type; + info_ptr->interlace_type = (png_byte)interlace_type; + + png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, + info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, + info_ptr->compression_type, info_ptr->filter_type); + + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + info_ptr->channels = 1; + + else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) + info_ptr->channels = 3; + + else + info_ptr->channels = 1; + + if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) + info_ptr->channels++; + + info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); + + /* Check for potential overflow */ + if (width > + (PNG_UINT_32_MAX >> 3) /* 8-byte RRGGBBAA pixels */ + - 48 /* bigrowbuf hack */ + - 1 /* filter byte */ + - 7*8 /* rounding of width to multiple of 8 pixels */ + - 8) /* extra max_pixel_depth pad */ + info_ptr->rowbytes = 0; + else + info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); +} + +#ifdef PNG_oFFs_SUPPORTED +void PNGAPI +png_set_oFFs(png_structp png_ptr, png_infop info_ptr, + png_int_32 offset_x, png_int_32 offset_y, int unit_type) +{ + png_debug1(1, "in %s storage function", "oFFs"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->x_offset = offset_x; + info_ptr->y_offset = offset_y; + info_ptr->offset_unit_type = (png_byte)unit_type; + info_ptr->valid |= PNG_INFO_oFFs; +} +#endif + +#ifdef PNG_pCAL_SUPPORTED +void PNGAPI +png_set_pCAL(png_structp png_ptr, png_infop info_ptr, + png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type, + int nparams, png_const_charp units, png_charpp params) +{ + png_size_t length; + int i; + + png_debug1(1, "in %s storage function", "pCAL"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + length = png_strlen(purpose) + 1; + png_debug1(3, "allocating purpose for info (%lu bytes)", + (unsigned long)length); + + /* TODO: validate format of calibration name and unit name */ + + /* Check that the type matches the specification. */ + if (type < 0 || type > 3) + png_error(png_ptr, "Invalid pCAL equation type"); + + /* Validate params[nparams] */ + for (i=0; ipcal_purpose = (png_charp)png_malloc_warn(png_ptr, length); + + if (info_ptr->pcal_purpose == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL purpose"); + return; + } + + png_memcpy(info_ptr->pcal_purpose, purpose, length); + + png_debug(3, "storing X0, X1, type, and nparams in info"); + info_ptr->pcal_X0 = X0; + info_ptr->pcal_X1 = X1; + info_ptr->pcal_type = (png_byte)type; + info_ptr->pcal_nparams = (png_byte)nparams; + + length = png_strlen(units) + 1; + png_debug1(3, "allocating units for info (%lu bytes)", + (unsigned long)length); + + info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length); + + if (info_ptr->pcal_units == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL units"); + return; + } + + png_memcpy(info_ptr->pcal_units, units, length); + + info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr, + (png_size_t)((nparams + 1) * png_sizeof(png_charp))); + + if (info_ptr->pcal_params == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL params"); + return; + } + + png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp)); + + for (i = 0; i < nparams; i++) + { + length = png_strlen(params[i]) + 1; + png_debug2(3, "allocating parameter %d for info (%lu bytes)", i, + (unsigned long)length); + + info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length); + + if (info_ptr->pcal_params[i] == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL parameter"); + return; + } + + png_memcpy(info_ptr->pcal_params[i], params[i], length); + } + + info_ptr->valid |= PNG_INFO_pCAL; + info_ptr->free_me |= PNG_FREE_PCAL; +} +#endif + +#ifdef PNG_sCAL_SUPPORTED +void PNGAPI +png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, + int unit, png_const_charp swidth, png_const_charp sheight) +{ + png_size_t lengthw = 0, lengthh = 0; + + png_debug1(1, "in %s storage function", "sCAL"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + /* Double check the unit (should never get here with an invalid + * unit unless this is an API call.) + */ + if (unit != 1 && unit != 2) + png_error(png_ptr, "Invalid sCAL unit"); + + if (swidth == NULL || (lengthw = png_strlen(swidth)) == 0 || + swidth[0] == 45 /* '-' */ || !png_check_fp_string(swidth, lengthw)) + png_error(png_ptr, "Invalid sCAL width"); + + if (sheight == NULL || (lengthh = png_strlen(sheight)) == 0 || + sheight[0] == 45 /* '-' */ || !png_check_fp_string(sheight, lengthh)) + png_error(png_ptr, "Invalid sCAL height"); + + info_ptr->scal_unit = (png_byte)unit; + + ++lengthw; + + png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw); + + info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, lengthw); + + if (info_ptr->scal_s_width == NULL) + { + png_warning(png_ptr, "Memory allocation failed while processing sCAL"); + return; + } + + png_memcpy(info_ptr->scal_s_width, swidth, lengthw); + + ++lengthh; + + png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh); + + info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, lengthh); + + if (info_ptr->scal_s_height == NULL) + { + png_free (png_ptr, info_ptr->scal_s_width); + info_ptr->scal_s_width = NULL; + + png_warning(png_ptr, "Memory allocation failed while processing sCAL"); + return; + } + + png_memcpy(info_ptr->scal_s_height, sheight, lengthh); + + info_ptr->valid |= PNG_INFO_sCAL; + info_ptr->free_me |= PNG_FREE_SCAL; +} + +# ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_sCAL(png_structp png_ptr, png_infop info_ptr, int unit, double width, + double height) +{ + png_debug1(1, "in %s storage function", "sCAL"); + + /* Check the arguments. */ + if (width <= 0) + png_warning(png_ptr, "Invalid sCAL width ignored"); + + else if (height <= 0) + png_warning(png_ptr, "Invalid sCAL height ignored"); + + else + { + /* Convert 'width' and 'height' to ASCII. */ + char swidth[PNG_sCAL_MAX_DIGITS+1]; + char sheight[PNG_sCAL_MAX_DIGITS+1]; + + png_ascii_from_fp(png_ptr, swidth, sizeof swidth, width, + PNG_sCAL_PRECISION); + png_ascii_from_fp(png_ptr, sheight, sizeof sheight, height, + PNG_sCAL_PRECISION); + + png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight); + } +} +# endif + +# ifdef PNG_FIXED_POINT_SUPPORTED +void PNGAPI +png_set_sCAL_fixed(png_structp png_ptr, png_infop info_ptr, int unit, + png_fixed_point width, png_fixed_point height) +{ + png_debug1(1, "in %s storage function", "sCAL"); + + /* Check the arguments. */ + if (width <= 0) + png_warning(png_ptr, "Invalid sCAL width ignored"); + + else if (height <= 0) + png_warning(png_ptr, "Invalid sCAL height ignored"); + + else + { + /* Convert 'width' and 'height' to ASCII. */ + char swidth[PNG_sCAL_MAX_DIGITS+1]; + char sheight[PNG_sCAL_MAX_DIGITS+1]; + + png_ascii_from_fixed(png_ptr, swidth, sizeof swidth, width); + png_ascii_from_fixed(png_ptr, sheight, sizeof sheight, height); + + png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight); + } +} +# endif +#endif + +#ifdef PNG_pHYs_SUPPORTED +void PNGAPI +png_set_pHYs(png_structp png_ptr, png_infop info_ptr, + png_uint_32 res_x, png_uint_32 res_y, int unit_type) +{ + png_debug1(1, "in %s storage function", "pHYs"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->x_pixels_per_unit = res_x; + info_ptr->y_pixels_per_unit = res_y; + info_ptr->phys_unit_type = (png_byte)unit_type; + info_ptr->valid |= PNG_INFO_pHYs; +} +#endif + +void PNGAPI +png_set_PLTE(png_structp png_ptr, png_infop info_ptr, + png_const_colorp palette, int num_palette) +{ + + png_debug1(1, "in %s storage function", "PLTE"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH) + { + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + png_error(png_ptr, "Invalid palette length"); + + else + { + png_warning(png_ptr, "Invalid palette length"); + return; + } + } + + /* It may not actually be necessary to set png_ptr->palette here; + * we do it for backward compatibility with the way the png_handle_tRNS + * function used to do the allocation. + */ + png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); + + /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead + * of num_palette entries, in case of an invalid PNG file that has + * too-large sample values. + */ + png_ptr->palette = (png_colorp)png_calloc(png_ptr, + PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); + + png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color)); + info_ptr->palette = png_ptr->palette; + info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; + + info_ptr->free_me |= PNG_FREE_PLTE; + + info_ptr->valid |= PNG_INFO_PLTE; +} + +#ifdef PNG_sBIT_SUPPORTED +void PNGAPI +png_set_sBIT(png_structp png_ptr, png_infop info_ptr, + png_const_color_8p sig_bit) +{ + png_debug1(1, "in %s storage function", "sBIT"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8)); + info_ptr->valid |= PNG_INFO_sBIT; +} +#endif + +#ifdef PNG_sRGB_SUPPORTED +void PNGAPI +png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int srgb_intent) +{ + png_debug1(1, "in %s storage function", "sRGB"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->srgb_intent = (png_byte)srgb_intent; + info_ptr->valid |= PNG_INFO_sRGB; +} + +void PNGAPI +png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, + int srgb_intent) +{ + png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_set_sRGB(png_ptr, info_ptr, srgb_intent); + +# ifdef PNG_gAMA_SUPPORTED + png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_sRGB_INVERSE); +# endif + +# ifdef PNG_cHRM_SUPPORTED + png_set_cHRM_fixed(png_ptr, info_ptr, + /* color x y */ + /* white */ 31270, 32900, + /* red */ 64000, 33000, + /* green */ 30000, 60000, + /* blue */ 15000, 6000 + ); +# endif /* cHRM */ +} +#endif /* sRGB */ + + +#ifdef PNG_iCCP_SUPPORTED +void PNGAPI +png_set_iCCP(png_structp png_ptr, png_infop info_ptr, + png_const_charp name, int compression_type, + png_const_bytep profile, png_uint_32 proflen) +{ + png_charp new_iccp_name; + png_bytep new_iccp_profile; + png_size_t length; + + png_debug1(1, "in %s storage function", "iCCP"); + + if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL) + return; + + length = png_strlen(name)+1; + new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length); + + if (new_iccp_name == NULL) + { + png_warning(png_ptr, "Insufficient memory to process iCCP chunk"); + return; + } + + png_memcpy(new_iccp_name, name, length); + new_iccp_profile = (png_bytep)png_malloc_warn(png_ptr, proflen); + + if (new_iccp_profile == NULL) + { + png_free (png_ptr, new_iccp_name); + png_warning(png_ptr, + "Insufficient memory to process iCCP profile"); + return; + } + + png_memcpy(new_iccp_profile, profile, (png_size_t)proflen); + + png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0); + + info_ptr->iccp_proflen = proflen; + info_ptr->iccp_name = new_iccp_name; + info_ptr->iccp_profile = new_iccp_profile; + /* Compression is always zero but is here so the API and info structure + * does not have to change if we introduce multiple compression types + */ + info_ptr->iccp_compression = (png_byte)compression_type; + info_ptr->free_me |= PNG_FREE_ICCP; + info_ptr->valid |= PNG_INFO_iCCP; +} +#endif + +#ifdef PNG_TEXT_SUPPORTED +void PNGAPI +png_set_text(png_structp png_ptr, png_infop info_ptr, png_const_textp text_ptr, + int num_text) +{ + int ret; + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text); + + if (ret) + png_error(png_ptr, "Insufficient memory to store text"); +} + +int /* PRIVATE */ +png_set_text_2(png_structp png_ptr, png_infop info_ptr, + png_const_textp text_ptr, int num_text) +{ + int i; + + png_debug1(1, "in %lx storage function", png_ptr == NULL ? "unexpected" : + (unsigned long)png_ptr->chunk_name); + + if (png_ptr == NULL || info_ptr == NULL || num_text == 0) + return(0); + + /* Make sure we have enough space in the "text" array in info_struct + * to hold all of the incoming text_ptr objects. + */ + if (info_ptr->num_text + num_text > info_ptr->max_text) + { + int old_max_text = info_ptr->max_text; + int old_num_text = info_ptr->num_text; + + if (info_ptr->text != NULL) + { + png_textp old_text; + + info_ptr->max_text = info_ptr->num_text + num_text + 8; + old_text = info_ptr->text; + + info_ptr->text = (png_textp)png_malloc_warn(png_ptr, + (png_size_t)(info_ptr->max_text * png_sizeof(png_text))); + + if (info_ptr->text == NULL) + { + /* Restore to previous condition */ + info_ptr->max_text = old_max_text; + info_ptr->text = old_text; + return(1); + } + + png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max_text * + png_sizeof(png_text))); + png_free(png_ptr, old_text); + } + + else + { + info_ptr->max_text = num_text + 8; + info_ptr->num_text = 0; + info_ptr->text = (png_textp)png_malloc_warn(png_ptr, + (png_size_t)(info_ptr->max_text * png_sizeof(png_text))); + if (info_ptr->text == NULL) + { + /* Restore to previous condition */ + info_ptr->num_text = old_num_text; + info_ptr->max_text = old_max_text; + return(1); + } + info_ptr->free_me |= PNG_FREE_TEXT; + } + + png_debug1(3, "allocated %d entries for info_ptr->text", + info_ptr->max_text); + } + for (i = 0; i < num_text; i++) + { + png_size_t text_length, key_len; + png_size_t lang_len, lang_key_len; + png_textp textp = &(info_ptr->text[info_ptr->num_text]); + + if (text_ptr[i].key == NULL) + continue; + + if (text_ptr[i].compression < PNG_TEXT_COMPRESSION_NONE || + text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST) + { + png_warning(png_ptr, "text compression mode is out of range"); + continue; + } + + key_len = png_strlen(text_ptr[i].key); + + if (text_ptr[i].compression <= 0) + { + lang_len = 0; + lang_key_len = 0; + } + + else +# ifdef PNG_iTXt_SUPPORTED + { + /* Set iTXt data */ + + if (text_ptr[i].lang != NULL) + lang_len = png_strlen(text_ptr[i].lang); + + else + lang_len = 0; + + if (text_ptr[i].lang_key != NULL) + lang_key_len = png_strlen(text_ptr[i].lang_key); + + else + lang_key_len = 0; + } +# else /* PNG_iTXt_SUPPORTED */ + { + png_warning(png_ptr, "iTXt chunk not supported"); + continue; + } +# endif + + if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0') + { + text_length = 0; +# ifdef PNG_iTXt_SUPPORTED + if (text_ptr[i].compression > 0) + textp->compression = PNG_ITXT_COMPRESSION_NONE; + + else +# endif + textp->compression = PNG_TEXT_COMPRESSION_NONE; + } + + else + { + text_length = png_strlen(text_ptr[i].text); + textp->compression = text_ptr[i].compression; + } + + textp->key = (png_charp)png_malloc_warn(png_ptr, + (png_size_t) + (key_len + text_length + lang_len + lang_key_len + 4)); + + if (textp->key == NULL) + return(1); + + png_debug2(2, "Allocated %lu bytes at %p in png_set_text", + (unsigned long)(png_uint_32) + (key_len + lang_len + lang_key_len + text_length + 4), + textp->key); + + png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len)); + *(textp->key + key_len) = '\0'; + + if (text_ptr[i].compression > 0) + { + textp->lang = textp->key + key_len + 1; + png_memcpy(textp->lang, text_ptr[i].lang, lang_len); + *(textp->lang + lang_len) = '\0'; + textp->lang_key = textp->lang + lang_len + 1; + png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len); + *(textp->lang_key + lang_key_len) = '\0'; + textp->text = textp->lang_key + lang_key_len + 1; + } + + else + { + textp->lang=NULL; + textp->lang_key=NULL; + textp->text = textp->key + key_len + 1; + } + + if (text_length) + png_memcpy(textp->text, text_ptr[i].text, + (png_size_t)(text_length)); + + *(textp->text + text_length) = '\0'; + +# ifdef PNG_iTXt_SUPPORTED + if (textp->compression > 0) + { + textp->text_length = 0; + textp->itxt_length = text_length; + } + + else +# endif + { + textp->text_length = text_length; + textp->itxt_length = 0; + } + + info_ptr->num_text++; + png_debug1(3, "transferred text chunk %d", info_ptr->num_text); + } + return(0); +} +#endif + +#ifdef PNG_tIME_SUPPORTED +void PNGAPI +png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_const_timep mod_time) +{ + png_debug1(1, "in %s storage function", "tIME"); + + if (png_ptr == NULL || info_ptr == NULL || + (png_ptr->mode & PNG_WROTE_tIME)) + return; + + if (mod_time->month == 0 || mod_time->month > 12 || + mod_time->day == 0 || mod_time->day > 31 || + mod_time->hour > 23 || mod_time->minute > 59 || + mod_time->second > 60) + { + png_warning(png_ptr, "Ignoring invalid time value"); + return; + } + + png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time)); + info_ptr->valid |= PNG_INFO_tIME; +} +#endif + +#ifdef PNG_tRNS_SUPPORTED +void PNGAPI +png_set_tRNS(png_structp png_ptr, png_infop info_ptr, + png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color) +{ + png_debug1(1, "in %s storage function", "tRNS"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (trans_alpha != NULL) + { + /* It may not actually be necessary to set png_ptr->trans_alpha here; + * we do it for backward compatibility with the way the png_handle_tRNS + * function used to do the allocation. + */ + + png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); + + /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ + png_ptr->trans_alpha = info_ptr->trans_alpha = + (png_bytep)png_malloc(png_ptr, (png_size_t)PNG_MAX_PALETTE_LENGTH); + + if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH) + png_memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans); + } + + if (trans_color != NULL) + { + int sample_max = (1 << info_ptr->bit_depth); + + if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY && + (int)trans_color->gray > sample_max) || + (info_ptr->color_type == PNG_COLOR_TYPE_RGB && + ((int)trans_color->red > sample_max || + (int)trans_color->green > sample_max || + (int)trans_color->blue > sample_max))) + png_warning(png_ptr, + "tRNS chunk has out-of-range samples for bit_depth"); + + png_memcpy(&(info_ptr->trans_color), trans_color, + png_sizeof(png_color_16)); + + if (num_trans == 0) + num_trans = 1; + } + + info_ptr->num_trans = (png_uint_16)num_trans; + + if (num_trans != 0) + { + info_ptr->valid |= PNG_INFO_tRNS; + info_ptr->free_me |= PNG_FREE_TRNS; + } +} +#endif + +#ifdef PNG_sPLT_SUPPORTED +void PNGAPI +png_set_sPLT(png_structp png_ptr, + png_infop info_ptr, png_const_sPLT_tp entries, int nentries) +/* + * entries - array of png_sPLT_t structures + * to be added to the list of palettes + * in the info structure. + * + * nentries - number of palette structures to be + * added. + */ +{ + png_sPLT_tp np; + int i; + + if (png_ptr == NULL || info_ptr == NULL) + return; + + np = (png_sPLT_tp)png_malloc_warn(png_ptr, + (info_ptr->splt_palettes_num + nentries) * + (png_size_t)png_sizeof(png_sPLT_t)); + + if (np == NULL) + { + png_warning(png_ptr, "No memory for sPLT palettes"); + return; + } + + png_memcpy(np, info_ptr->splt_palettes, + info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t)); + + png_free(png_ptr, info_ptr->splt_palettes); + info_ptr->splt_palettes=NULL; + + for (i = 0; i < nentries; i++) + { + png_sPLT_tp to = np + info_ptr->splt_palettes_num + i; + png_const_sPLT_tp from = entries + i; + png_size_t length; + + length = png_strlen(from->name) + 1; + to->name = (png_charp)png_malloc_warn(png_ptr, length); + + if (to->name == NULL) + { + png_warning(png_ptr, + "Out of memory while processing sPLT chunk"); + continue; + } + + png_memcpy(to->name, from->name, length); + to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr, + from->nentries * png_sizeof(png_sPLT_entry)); + + if (to->entries == NULL) + { + png_warning(png_ptr, + "Out of memory while processing sPLT chunk"); + png_free(png_ptr, to->name); + to->name = NULL; + continue; + } + + png_memcpy(to->entries, from->entries, + from->nentries * png_sizeof(png_sPLT_entry)); + + to->nentries = from->nentries; + to->depth = from->depth; + } + + info_ptr->splt_palettes = np; + info_ptr->splt_palettes_num += nentries; + info_ptr->valid |= PNG_INFO_sPLT; + info_ptr->free_me |= PNG_FREE_SPLT; +} +#endif /* PNG_sPLT_SUPPORTED */ + +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED +void PNGAPI +png_set_unknown_chunks(png_structp png_ptr, + png_infop info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns) +{ + png_unknown_chunkp np; + int i; + + if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0) + return; + + np = (png_unknown_chunkp)png_malloc_warn(png_ptr, + (png_size_t)(info_ptr->unknown_chunks_num + num_unknowns) * + png_sizeof(png_unknown_chunk)); + + if (np == NULL) + { + png_warning(png_ptr, + "Out of memory while processing unknown chunk"); + return; + } + + png_memcpy(np, info_ptr->unknown_chunks, + (png_size_t)info_ptr->unknown_chunks_num * + png_sizeof(png_unknown_chunk)); + + png_free(png_ptr, info_ptr->unknown_chunks); + info_ptr->unknown_chunks = NULL; + + for (i = 0; i < num_unknowns; i++) + { + png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i; + png_const_unknown_chunkp from = unknowns + i; + + png_memcpy(to->name, from->name, png_sizeof(from->name)); + to->name[png_sizeof(to->name)-1] = '\0'; + to->size = from->size; + + /* Note our location in the read or write sequence */ + to->location = (png_byte)(png_ptr->mode & 0xff); + + if (from->size == 0) + to->data=NULL; + + else + { + to->data = (png_bytep)png_malloc_warn(png_ptr, + (png_size_t)from->size); + + if (to->data == NULL) + { + png_warning(png_ptr, + "Out of memory while processing unknown chunk"); + to->size = 0; + } + + else + png_memcpy(to->data, from->data, from->size); + } + } + + info_ptr->unknown_chunks = np; + info_ptr->unknown_chunks_num += num_unknowns; + info_ptr->free_me |= PNG_FREE_UNKN; +} + +void PNGAPI +png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr, + int chunk, int location) +{ + if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk < + info_ptr->unknown_chunks_num) + info_ptr->unknown_chunks[chunk].location = (png_byte)location; +} +#endif + + +#ifdef PNG_MNG_FEATURES_SUPPORTED +png_uint_32 PNGAPI +png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features) +{ + png_debug(1, "in png_permit_mng_features"); + + if (png_ptr == NULL) + return (png_uint_32)0; + + png_ptr->mng_features_permitted = + (png_byte)(mng_features & PNG_ALL_MNG_FEATURES); + + return (png_uint_32)png_ptr->mng_features_permitted; +} +#endif + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +void PNGAPI +png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_const_bytep + chunk_list, int num_chunks) +{ + png_bytep new_list, p; + int i, old_num_chunks; + if (png_ptr == NULL) + return; + + if (num_chunks == 0) + { + if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE) + png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS; + + else + png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS; + + if (keep == PNG_HANDLE_CHUNK_ALWAYS) + png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS; + + else + png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS; + + return; + } + + if (chunk_list == NULL) + return; + + old_num_chunks = png_ptr->num_chunk_list; + new_list=(png_bytep)png_malloc(png_ptr, + (png_size_t)(5*(num_chunks + old_num_chunks))); + + if (png_ptr->chunk_list != NULL) + { + png_memcpy(new_list, png_ptr->chunk_list, + (png_size_t)(5*old_num_chunks)); + png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list=NULL; + } + + png_memcpy(new_list + 5*old_num_chunks, chunk_list, + (png_size_t)(5*num_chunks)); + + for (p = new_list + 5*old_num_chunks + 4, i = 0; inum_chunk_list = old_num_chunks + num_chunks; + png_ptr->chunk_list = new_list; + png_ptr->free_me |= PNG_FREE_LIST; +} +#endif + +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED +void PNGAPI +png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr, + png_user_chunk_ptr read_user_chunk_fn) +{ + png_debug(1, "in png_set_read_user_chunk_fn"); + + if (png_ptr == NULL) + return; + + png_ptr->read_user_chunk_fn = read_user_chunk_fn; + png_ptr->user_chunk_ptr = user_chunk_ptr; +} +#endif + +#ifdef PNG_INFO_IMAGE_SUPPORTED +void PNGAPI +png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers) +{ + png_debug1(1, "in %s storage function", "rows"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers)) + png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); + + info_ptr->row_pointers = row_pointers; + + if (row_pointers) + info_ptr->valid |= PNG_INFO_IDAT; +} +#endif + +void PNGAPI +png_set_compression_buffer_size(png_structp png_ptr, png_size_t size) +{ + if (png_ptr == NULL) + return; + + png_free(png_ptr, png_ptr->zbuf); + + if (size > ZLIB_IO_MAX) + { + png_warning(png_ptr, "Attempt to set buffer size beyond max ignored"); + png_ptr->zbuf_size = ZLIB_IO_MAX; + size = ZLIB_IO_MAX; /* must fit */ + } + + else + png_ptr->zbuf_size = (uInt)size; + + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size); + + /* The following ensures a relatively safe failure if this gets called while + * the buffer is actually in use. + */ + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = 0; + png_ptr->zstream.avail_in = 0; +} + +void PNGAPI +png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) +{ + if (png_ptr && info_ptr) + info_ptr->valid &= ~mask; +} + + + +#ifdef PNG_SET_USER_LIMITS_SUPPORTED +/* This function was added to libpng 1.2.6 */ +void PNGAPI +png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, + png_uint_32 user_height_max) +{ + /* Images with dimensions larger than these limits will be + * rejected by png_set_IHDR(). To accept any PNG datastream + * regardless of dimensions, set both limits to 0x7ffffffL. + */ + if (png_ptr == NULL) + return; + + png_ptr->user_width_max = user_width_max; + png_ptr->user_height_max = user_height_max; +} + +/* This function was added to libpng 1.4.0 */ +void PNGAPI +png_set_chunk_cache_max (png_structp png_ptr, + png_uint_32 user_chunk_cache_max) +{ + if (png_ptr) + png_ptr->user_chunk_cache_max = user_chunk_cache_max; +} + +/* This function was added to libpng 1.4.1 */ +void PNGAPI +png_set_chunk_malloc_max (png_structp png_ptr, + png_alloc_size_t user_chunk_malloc_max) +{ + if (png_ptr) + png_ptr->user_chunk_malloc_max = user_chunk_malloc_max; +} +#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ + + +#ifdef PNG_BENIGN_ERRORS_SUPPORTED +void PNGAPI +png_set_benign_errors(png_structp png_ptr, int allowed) +{ + png_debug(1, "in png_set_benign_errors"); + + if (allowed) + png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; + + else + png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN; +} +#endif /* PNG_BENIGN_ERRORS_SUPPORTED */ + +#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED +/* Whether to report invalid palette index; added at libng-1.5.10 + * allowed - one of 0: disable; 1: enable + */ +void PNGAPI +png_set_check_for_invalid_index(png_structp png_ptr, int allowed) +{ + png_debug(1, "in png_set_check_for_invalid_index"); + + if (allowed) + png_ptr->num_palette_max = 0; + + else + png_ptr->num_palette_max = -1; +} +#endif + +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff --git a/Source/LibPNG/pngstruct.h b/Source/LibPNG/pngstruct.h index 73d7114..db0d4e4 100644 --- a/Source/LibPNG/pngstruct.h +++ b/Source/LibPNG/pngstruct.h @@ -1,358 +1,358 @@ - -/* pngstruct.h - header file for PNG reference library - * - * Copyright (c) 1998-2012 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * Last changed in libpng 1.5.9 [February 18, 2012] - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - */ - -/* The structure that holds the information to read and write PNG files. - * The only people who need to care about what is inside of this are the - * people who will be modifying the library for their own special needs. - * It should NOT be accessed directly by an application. - */ - -#ifndef PNGSTRUCT_H -#define PNGSTRUCT_H -/* zlib.h defines the structure z_stream, an instance of which is included - * in this structure and is required for decompressing the LZ compressed - * data in PNG files. - */ -#include "zlib.h" - -struct png_struct_def -{ -#ifdef PNG_SETJMP_SUPPORTED - jmp_buf longjmp_buffer; /* used in png_error */ - png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */ -#endif - png_error_ptr error_fn; /* function for printing errors and aborting */ -#ifdef PNG_WARNINGS_SUPPORTED - png_error_ptr warning_fn; /* function for printing warnings */ -#endif - png_voidp error_ptr; /* user supplied struct for error functions */ - png_rw_ptr write_data_fn; /* function for writing output data */ - png_rw_ptr read_data_fn; /* function for reading input data */ - png_voidp io_ptr; /* ptr to application struct for I/O functions */ - -#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED - png_user_transform_ptr read_user_transform_fn; /* user read transform */ -#endif - -#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED - png_user_transform_ptr write_user_transform_fn; /* user write transform */ -#endif - -/* These were added in libpng-1.0.2 */ -#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) - png_voidp user_transform_ptr; /* user supplied struct for user transform */ - png_byte user_transform_depth; /* bit depth of user transformed pixels */ - png_byte user_transform_channels; /* channels in user transformed pixels */ -#endif -#endif - - png_uint_32 mode; /* tells us where we are in the PNG file */ - png_uint_32 flags; /* flags indicating various things to libpng */ - png_uint_32 transformations; /* which transformations to perform */ - - z_stream zstream; /* pointer to decompression structure (below) */ - png_bytep zbuf; /* buffer for zlib */ - uInt zbuf_size; /* size of zbuf (typically 65536) */ -#ifdef PNG_WRITE_SUPPORTED - -/* Added in 1.5.4: state to keep track of whether the zstream has been - * initialized and if so whether it is for IDAT or some other chunk. - */ -#define PNG_ZLIB_UNINITIALIZED 0 -#define PNG_ZLIB_FOR_IDAT 1 -#define PNG_ZLIB_FOR_TEXT 2 /* anything other than IDAT */ -#define PNG_ZLIB_USE_MASK 3 /* bottom two bits */ -#define PNG_ZLIB_IN_USE 4 /* a flag value */ - - png_uint_32 zlib_state; /* State of zlib initialization */ -/* End of material added at libpng 1.5.4 */ - - int zlib_level; /* holds zlib compression level */ - int zlib_method; /* holds zlib compression method */ - int zlib_window_bits; /* holds zlib compression window bits */ - int zlib_mem_level; /* holds zlib compression memory level */ - int zlib_strategy; /* holds zlib compression strategy */ -#endif -/* Added at libpng 1.5.4 */ -#if defined(PNG_WRITE_COMPRESSED_TEXT_SUPPORTED) || \ - defined(PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED) - int zlib_text_level; /* holds zlib compression level */ - int zlib_text_method; /* holds zlib compression method */ - int zlib_text_window_bits; /* holds zlib compression window bits */ - int zlib_text_mem_level; /* holds zlib compression memory level */ - int zlib_text_strategy; /* holds zlib compression strategy */ -#endif -/* End of material added at libpng 1.5.4 */ - - png_uint_32 width; /* width of image in pixels */ - png_uint_32 height; /* height of image in pixels */ - png_uint_32 num_rows; /* number of rows in current pass */ - png_uint_32 usr_width; /* width of row at start of write */ - png_size_t rowbytes; /* size of row in bytes */ - png_uint_32 iwidth; /* width of current interlaced row in pixels */ - png_uint_32 row_number; /* current row in interlace pass */ - png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */ - png_bytep prev_row; /* buffer to save previous (unfiltered) row. - * This is a pointer into big_prev_row - */ - png_bytep row_buf; /* buffer to save current (unfiltered) row. - * This is a pointer into big_row_buf - */ - png_bytep sub_row; /* buffer to save "sub" row when filtering */ - png_bytep up_row; /* buffer to save "up" row when filtering */ - png_bytep avg_row; /* buffer to save "avg" row when filtering */ - png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */ - png_size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */ - - png_uint_32 idat_size; /* current IDAT size for read */ - png_uint_32 crc; /* current chunk CRC value */ - png_colorp palette; /* palette from the input file */ - png_uint_16 num_palette; /* number of color entries in palette */ - -/* Added at libpng-1.5.10 */ -#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED - int num_palette_max; /* maximum palette index found in IDAT */ -#endif - - png_uint_16 num_trans; /* number of transparency values */ - png_byte compression; /* file compression type (always 0) */ - png_byte filter; /* file filter type (always 0) */ - png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ - png_byte pass; /* current interlace pass (0 - 6) */ - png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */ - png_byte color_type; /* color type of file */ - png_byte bit_depth; /* bit depth of file */ - png_byte usr_bit_depth; /* bit depth of users row: write only */ - png_byte pixel_depth; /* number of bits per pixel */ - png_byte channels; /* number of channels in file */ - png_byte usr_channels; /* channels at start of write: write only */ - png_byte sig_bytes; /* magic bytes read/written from start of file */ - png_byte maximum_pixel_depth; - /* pixel depth used for the row buffers */ - png_byte transformed_pixel_depth; - /* pixel depth after read/write transforms */ - png_byte io_chunk_string[5]; - /* string name of chunk */ - -#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) - png_uint_16 filler; /* filler bytes for pixel expansion */ -#endif - -#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ - defined(PNG_READ_ALPHA_MODE_SUPPORTED) - png_byte background_gamma_type; - png_fixed_point background_gamma; - png_color_16 background; /* background color in screen gamma space */ -#ifdef PNG_READ_GAMMA_SUPPORTED - png_color_16 background_1; /* background normalized to gamma 1.0 */ -#endif -#endif /* PNG_bKGD_SUPPORTED */ - -#ifdef PNG_WRITE_FLUSH_SUPPORTED - png_flush_ptr output_flush_fn; /* Function for flushing output */ - png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */ - png_uint_32 flush_rows; /* number of rows written since last flush */ -#endif - -#ifdef PNG_READ_GAMMA_SUPPORTED - int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */ - png_fixed_point gamma; /* file gamma value */ - png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */ - - png_bytep gamma_table; /* gamma table for 8-bit depth files */ - png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */ -#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ - defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ - defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) - png_bytep gamma_from_1; /* converts from 1.0 to screen */ - png_bytep gamma_to_1; /* converts from file to 1.0 */ - png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */ - png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */ -#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ -#endif - -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED) - png_color_8 sig_bit; /* significant bits in each available channel */ -#endif - -#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) - png_color_8 shift; /* shift for significant bit tranformation */ -#endif - -#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \ - || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) - png_bytep trans_alpha; /* alpha values for paletted files */ - png_color_16 trans_color; /* transparent color for non-paletted files */ -#endif - - png_read_status_ptr read_row_fn; /* called after each row is decoded */ - png_write_status_ptr write_row_fn; /* called after each row is encoded */ -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED - png_progressive_info_ptr info_fn; /* called after header data fully read */ - png_progressive_row_ptr row_fn; /* called after a prog. row is decoded */ - png_progressive_end_ptr end_fn; /* called after image is complete */ - png_bytep save_buffer_ptr; /* current location in save_buffer */ - png_bytep save_buffer; /* buffer for previously read data */ - png_bytep current_buffer_ptr; /* current location in current_buffer */ - png_bytep current_buffer; /* buffer for recently used data */ - png_uint_32 push_length; /* size of current input chunk */ - png_uint_32 skip_length; /* bytes to skip in input data */ - png_size_t save_buffer_size; /* amount of data now in save_buffer */ - png_size_t save_buffer_max; /* total size of save_buffer */ - png_size_t buffer_size; /* total amount of available input data */ - png_size_t current_buffer_size; /* amount of data now in current_buffer */ - int process_mode; /* what push library is currently doing */ - int cur_palette; /* current push library palette index */ - -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ - -#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) -/* For the Borland special 64K segment handler */ - png_bytepp offset_table_ptr; - png_bytep offset_table; - png_uint_16 offset_table_number; - png_uint_16 offset_table_count; - png_uint_16 offset_table_count_free; -#endif - -#ifdef PNG_READ_QUANTIZE_SUPPORTED - png_bytep palette_lookup; /* lookup table for quantizing */ - png_bytep quantize_index; /* index translation for palette files */ -#endif - -#if defined(PNG_READ_QUANTIZE_SUPPORTED) || defined(PNG_hIST_SUPPORTED) - png_uint_16p hist; /* histogram */ -#endif - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - png_byte heuristic_method; /* heuristic for row filter selection */ - png_byte num_prev_filters; /* number of weights for previous rows */ - png_bytep prev_filters; /* filter type(s) of previous row(s) */ - png_uint_16p filter_weights; /* weight(s) for previous line(s) */ - png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */ - png_uint_16p filter_costs; /* relative filter calculation cost */ - png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */ -#endif - -#ifdef PNG_TIME_RFC1123_SUPPORTED - /* This is going to be unused in libpng16 and removed from libpng17 */ - char time_buffer[29]; /* String to hold RFC 1123 time text */ -#endif - -/* New members added in libpng-1.0.6 */ - - png_uint_32 free_me; /* flags items libpng is responsible for freeing */ - -#ifdef PNG_USER_CHUNKS_SUPPORTED - png_voidp user_chunk_ptr; - png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */ -#endif - -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - int num_chunk_list; - png_bytep chunk_list; -#endif - -#ifdef PNG_READ_sRGB_SUPPORTED - /* Added in 1.5.5 to record an sRGB chunk in the png. */ - png_byte is_sRGB; -#endif - -/* New members added in libpng-1.0.3 */ -#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED - png_byte rgb_to_gray_status; - /* Added in libpng 1.5.5 to record setting of coefficients: */ - png_byte rgb_to_gray_coefficients_set; - /* These were changed from png_byte in libpng-1.0.6 */ - png_uint_16 rgb_to_gray_red_coeff; - png_uint_16 rgb_to_gray_green_coeff; - /* deleted in 1.5.5: rgb_to_gray_blue_coeff; */ -#endif - -/* New member added in libpng-1.0.4 (renamed in 1.0.9) */ -#if defined(PNG_MNG_FEATURES_SUPPORTED) -/* Changed from png_byte to png_uint_32 at version 1.2.0 */ - png_uint_32 mng_features_permitted; -#endif - -/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */ -#ifdef PNG_MNG_FEATURES_SUPPORTED - png_byte filter_type; -#endif - -/* New members added in libpng-1.2.0 */ - -/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */ -#ifdef PNG_USER_MEM_SUPPORTED - png_voidp mem_ptr; /* user supplied struct for mem functions */ - png_malloc_ptr malloc_fn; /* function for allocating memory */ - png_free_ptr free_fn; /* function for freeing memory */ -#endif - -/* New member added in libpng-1.0.13 and 1.2.0 */ - png_bytep big_row_buf; /* buffer to save current (unfiltered) row */ - -#ifdef PNG_READ_QUANTIZE_SUPPORTED -/* The following three members were added at version 1.0.14 and 1.2.4 */ - png_bytep quantize_sort; /* working sort array */ - png_bytep index_to_palette; /* where the original index currently is - in the palette */ - png_bytep palette_to_index; /* which original index points to this - palette color */ -#endif - -/* New members added in libpng-1.0.16 and 1.2.6 */ - png_byte compression_type; - -#ifdef PNG_USER_LIMITS_SUPPORTED - png_uint_32 user_width_max; - png_uint_32 user_height_max; - - /* Added in libpng-1.4.0: Total number of sPLT, text, and unknown - * chunks that can be stored (0 means unlimited). - */ - png_uint_32 user_chunk_cache_max; - - /* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk - * can occupy when decompressed. 0 means unlimited. - */ - png_alloc_size_t user_chunk_malloc_max; -#endif - -/* New member added in libpng-1.0.25 and 1.2.17 */ -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED - /* Storage for unknown chunk that the library doesn't recognize. */ - png_unknown_chunk unknown_chunk; -#endif - -/* New member added in libpng-1.2.26 */ - png_size_t old_big_row_buf_size; - -/* New member added in libpng-1.2.30 */ - png_charp chunkdata; /* buffer for reading chunk data */ - -#ifdef PNG_IO_STATE_SUPPORTED -/* New member added in libpng-1.4.0 */ - png_uint_32 io_state; -#endif - -/* New member added in libpng-1.5.6 */ - png_bytep big_prev_row; - - void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info, - png_bytep row, png_const_bytep prev_row); -}; -#endif /* PNGSTRUCT_H */ + +/* pngstruct.h - header file for PNG reference library + * + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * Last changed in libpng 1.5.9 [February 18, 2012] + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +/* The structure that holds the information to read and write PNG files. + * The only people who need to care about what is inside of this are the + * people who will be modifying the library for their own special needs. + * It should NOT be accessed directly by an application. + */ + +#ifndef PNGSTRUCT_H +#define PNGSTRUCT_H +/* zlib.h defines the structure z_stream, an instance of which is included + * in this structure and is required for decompressing the LZ compressed + * data in PNG files. + */ +#include "zlib.h" + +struct png_struct_def +{ +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf longjmp_buffer; /* used in png_error */ + png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */ +#endif + png_error_ptr error_fn; /* function for printing errors and aborting */ +#ifdef PNG_WARNINGS_SUPPORTED + png_error_ptr warning_fn; /* function for printing warnings */ +#endif + png_voidp error_ptr; /* user supplied struct for error functions */ + png_rw_ptr write_data_fn; /* function for writing output data */ + png_rw_ptr read_data_fn; /* function for reading input data */ + png_voidp io_ptr; /* ptr to application struct for I/O functions */ + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + png_user_transform_ptr read_user_transform_fn; /* user read transform */ +#endif + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED + png_user_transform_ptr write_user_transform_fn; /* user write transform */ +#endif + +/* These were added in libpng-1.0.2 */ +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) + png_voidp user_transform_ptr; /* user supplied struct for user transform */ + png_byte user_transform_depth; /* bit depth of user transformed pixels */ + png_byte user_transform_channels; /* channels in user transformed pixels */ +#endif +#endif + + png_uint_32 mode; /* tells us where we are in the PNG file */ + png_uint_32 flags; /* flags indicating various things to libpng */ + png_uint_32 transformations; /* which transformations to perform */ + + z_stream zstream; /* pointer to decompression structure (below) */ + png_bytep zbuf; /* buffer for zlib */ + uInt zbuf_size; /* size of zbuf (typically 65536) */ +#ifdef PNG_WRITE_SUPPORTED + +/* Added in 1.5.4: state to keep track of whether the zstream has been + * initialized and if so whether it is for IDAT or some other chunk. + */ +#define PNG_ZLIB_UNINITIALIZED 0 +#define PNG_ZLIB_FOR_IDAT 1 +#define PNG_ZLIB_FOR_TEXT 2 /* anything other than IDAT */ +#define PNG_ZLIB_USE_MASK 3 /* bottom two bits */ +#define PNG_ZLIB_IN_USE 4 /* a flag value */ + + png_uint_32 zlib_state; /* State of zlib initialization */ +/* End of material added at libpng 1.5.4 */ + + int zlib_level; /* holds zlib compression level */ + int zlib_method; /* holds zlib compression method */ + int zlib_window_bits; /* holds zlib compression window bits */ + int zlib_mem_level; /* holds zlib compression memory level */ + int zlib_strategy; /* holds zlib compression strategy */ +#endif +/* Added at libpng 1.5.4 */ +#if defined(PNG_WRITE_COMPRESSED_TEXT_SUPPORTED) || \ + defined(PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED) + int zlib_text_level; /* holds zlib compression level */ + int zlib_text_method; /* holds zlib compression method */ + int zlib_text_window_bits; /* holds zlib compression window bits */ + int zlib_text_mem_level; /* holds zlib compression memory level */ + int zlib_text_strategy; /* holds zlib compression strategy */ +#endif +/* End of material added at libpng 1.5.4 */ + + png_uint_32 width; /* width of image in pixels */ + png_uint_32 height; /* height of image in pixels */ + png_uint_32 num_rows; /* number of rows in current pass */ + png_uint_32 usr_width; /* width of row at start of write */ + png_size_t rowbytes; /* size of row in bytes */ + png_uint_32 iwidth; /* width of current interlaced row in pixels */ + png_uint_32 row_number; /* current row in interlace pass */ + png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */ + png_bytep prev_row; /* buffer to save previous (unfiltered) row. + * This is a pointer into big_prev_row + */ + png_bytep row_buf; /* buffer to save current (unfiltered) row. + * This is a pointer into big_row_buf + */ + png_bytep sub_row; /* buffer to save "sub" row when filtering */ + png_bytep up_row; /* buffer to save "up" row when filtering */ + png_bytep avg_row; /* buffer to save "avg" row when filtering */ + png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */ + png_size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */ + + png_uint_32 idat_size; /* current IDAT size for read */ + png_uint_32 crc; /* current chunk CRC value */ + png_colorp palette; /* palette from the input file */ + png_uint_16 num_palette; /* number of color entries in palette */ + +/* Added at libpng-1.5.10 */ +#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED + int num_palette_max; /* maximum palette index found in IDAT */ +#endif + + png_uint_16 num_trans; /* number of transparency values */ + png_byte compression; /* file compression type (always 0) */ + png_byte filter; /* file filter type (always 0) */ + png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ + png_byte pass; /* current interlace pass (0 - 6) */ + png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */ + png_byte color_type; /* color type of file */ + png_byte bit_depth; /* bit depth of file */ + png_byte usr_bit_depth; /* bit depth of users row: write only */ + png_byte pixel_depth; /* number of bits per pixel */ + png_byte channels; /* number of channels in file */ + png_byte usr_channels; /* channels at start of write: write only */ + png_byte sig_bytes; /* magic bytes read/written from start of file */ + png_byte maximum_pixel_depth; + /* pixel depth used for the row buffers */ + png_byte transformed_pixel_depth; + /* pixel depth after read/write transforms */ + png_byte io_chunk_string[5]; + /* string name of chunk */ + +#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) + png_uint_16 filler; /* filler bytes for pixel expansion */ +#endif + +#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) ||\ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) + png_byte background_gamma_type; + png_fixed_point background_gamma; + png_color_16 background; /* background color in screen gamma space */ +#ifdef PNG_READ_GAMMA_SUPPORTED + png_color_16 background_1; /* background normalized to gamma 1.0 */ +#endif +#endif /* PNG_bKGD_SUPPORTED */ + +#ifdef PNG_WRITE_FLUSH_SUPPORTED + png_flush_ptr output_flush_fn; /* Function for flushing output */ + png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */ + png_uint_32 flush_rows; /* number of rows written since last flush */ +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED + int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */ + png_fixed_point gamma; /* file gamma value */ + png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */ + + png_bytep gamma_table; /* gamma table for 8-bit depth files */ + png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */ +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + png_bytep gamma_from_1; /* converts from 1.0 to screen */ + png_bytep gamma_to_1; /* converts from file to 1.0 */ + png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */ + png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */ +#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */ +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED) + png_color_8 sig_bit; /* significant bits in each available channel */ +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) + png_color_8 shift; /* shift for significant bit tranformation */ +#endif + +#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \ + || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + png_bytep trans_alpha; /* alpha values for paletted files */ + png_color_16 trans_color; /* transparent color for non-paletted files */ +#endif + + png_read_status_ptr read_row_fn; /* called after each row is decoded */ + png_write_status_ptr write_row_fn; /* called after each row is encoded */ +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED + png_progressive_info_ptr info_fn; /* called after header data fully read */ + png_progressive_row_ptr row_fn; /* called after a prog. row is decoded */ + png_progressive_end_ptr end_fn; /* called after image is complete */ + png_bytep save_buffer_ptr; /* current location in save_buffer */ + png_bytep save_buffer; /* buffer for previously read data */ + png_bytep current_buffer_ptr; /* current location in current_buffer */ + png_bytep current_buffer; /* buffer for recently used data */ + png_uint_32 push_length; /* size of current input chunk */ + png_uint_32 skip_length; /* bytes to skip in input data */ + png_size_t save_buffer_size; /* amount of data now in save_buffer */ + png_size_t save_buffer_max; /* total size of save_buffer */ + png_size_t buffer_size; /* total amount of available input data */ + png_size_t current_buffer_size; /* amount of data now in current_buffer */ + int process_mode; /* what push library is currently doing */ + int cur_palette; /* current push library palette index */ + +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ + +#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) +/* For the Borland special 64K segment handler */ + png_bytepp offset_table_ptr; + png_bytep offset_table; + png_uint_16 offset_table_number; + png_uint_16 offset_table_count; + png_uint_16 offset_table_count_free; +#endif + +#ifdef PNG_READ_QUANTIZE_SUPPORTED + png_bytep palette_lookup; /* lookup table for quantizing */ + png_bytep quantize_index; /* index translation for palette files */ +#endif + +#if defined(PNG_READ_QUANTIZE_SUPPORTED) || defined(PNG_hIST_SUPPORTED) + png_uint_16p hist; /* histogram */ +#endif + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + png_byte heuristic_method; /* heuristic for row filter selection */ + png_byte num_prev_filters; /* number of weights for previous rows */ + png_bytep prev_filters; /* filter type(s) of previous row(s) */ + png_uint_16p filter_weights; /* weight(s) for previous line(s) */ + png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */ + png_uint_16p filter_costs; /* relative filter calculation cost */ + png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */ +#endif + +#ifdef PNG_TIME_RFC1123_SUPPORTED + /* This is going to be unused in libpng16 and removed from libpng17 */ + char time_buffer[29]; /* String to hold RFC 1123 time text */ +#endif + +/* New members added in libpng-1.0.6 */ + + png_uint_32 free_me; /* flags items libpng is responsible for freeing */ + +#ifdef PNG_USER_CHUNKS_SUPPORTED + png_voidp user_chunk_ptr; + png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */ +#endif + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + int num_chunk_list; + png_bytep chunk_list; +#endif + +#ifdef PNG_READ_sRGB_SUPPORTED + /* Added in 1.5.5 to record an sRGB chunk in the png. */ + png_byte is_sRGB; +#endif + +/* New members added in libpng-1.0.3 */ +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + png_byte rgb_to_gray_status; + /* Added in libpng 1.5.5 to record setting of coefficients: */ + png_byte rgb_to_gray_coefficients_set; + /* These were changed from png_byte in libpng-1.0.6 */ + png_uint_16 rgb_to_gray_red_coeff; + png_uint_16 rgb_to_gray_green_coeff; + /* deleted in 1.5.5: rgb_to_gray_blue_coeff; */ +#endif + +/* New member added in libpng-1.0.4 (renamed in 1.0.9) */ +#if defined(PNG_MNG_FEATURES_SUPPORTED) +/* Changed from png_byte to png_uint_32 at version 1.2.0 */ + png_uint_32 mng_features_permitted; +#endif + +/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */ +#ifdef PNG_MNG_FEATURES_SUPPORTED + png_byte filter_type; +#endif + +/* New members added in libpng-1.2.0 */ + +/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */ +#ifdef PNG_USER_MEM_SUPPORTED + png_voidp mem_ptr; /* user supplied struct for mem functions */ + png_malloc_ptr malloc_fn; /* function for allocating memory */ + png_free_ptr free_fn; /* function for freeing memory */ +#endif + +/* New member added in libpng-1.0.13 and 1.2.0 */ + png_bytep big_row_buf; /* buffer to save current (unfiltered) row */ + +#ifdef PNG_READ_QUANTIZE_SUPPORTED +/* The following three members were added at version 1.0.14 and 1.2.4 */ + png_bytep quantize_sort; /* working sort array */ + png_bytep index_to_palette; /* where the original index currently is + in the palette */ + png_bytep palette_to_index; /* which original index points to this + palette color */ +#endif + +/* New members added in libpng-1.0.16 and 1.2.6 */ + png_byte compression_type; + +#ifdef PNG_USER_LIMITS_SUPPORTED + png_uint_32 user_width_max; + png_uint_32 user_height_max; + + /* Added in libpng-1.4.0: Total number of sPLT, text, and unknown + * chunks that can be stored (0 means unlimited). + */ + png_uint_32 user_chunk_cache_max; + + /* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk + * can occupy when decompressed. 0 means unlimited. + */ + png_alloc_size_t user_chunk_malloc_max; +#endif + +/* New member added in libpng-1.0.25 and 1.2.17 */ +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED + /* Storage for unknown chunk that the library doesn't recognize. */ + png_unknown_chunk unknown_chunk; +#endif + +/* New member added in libpng-1.2.26 */ + png_size_t old_big_row_buf_size; + +/* New member added in libpng-1.2.30 */ + png_charp chunkdata; /* buffer for reading chunk data */ + +#ifdef PNG_IO_STATE_SUPPORTED +/* New member added in libpng-1.4.0 */ + png_uint_32 io_state; +#endif + +/* New member added in libpng-1.5.6 */ + png_bytep big_prev_row; + + void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info, + png_bytep row, png_const_bytep prev_row); +}; +#endif /* PNGSTRUCT_H */ diff --git a/Source/LibPNG/pngtest.c b/Source/LibPNG/pngtest.c index 5594333..1a06cd1 100644 --- a/Source/LibPNG/pngtest.c +++ b/Source/LibPNG/pngtest.c @@ -1,1820 +1,1820 @@ - -/* pngtest.c - a simple test program to test libpng - * - * Last changed in libpng 1.5.6 [November 3, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - * - * This program reads in a PNG image, writes it out again, and then - * compares the two files. If the files are identical, this shows that - * the basic chunk handling, filtering, and (de)compression code is working - * properly. It does not currently test all of the transforms, although - * it probably should. - * - * The program will report "FAIL" in certain legitimate cases: - * 1) when the compression level or filter selection method is changed. - * 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192. - * 3) unknown unsafe-to-copy ancillary chunks or unknown critical chunks - * exist in the input file. - * 4) others not listed here... - * In these cases, it is best to check with another tool such as "pngcheck" - * to see what the differences between the two files are. - * - * If a filename is given on the command-line, then this file is used - * for the input, rather than the default "pngtest.png". This allows - * testing a wide variety of files easily. You can also test a number - * of files at once by typing "pngtest -m file1.png file2.png ..." - */ - -#define _POSIX_SOURCE 1 - -#include "zlib.h" -#include "png.h" -/* Copied from pngpriv.h but only used in error messages below. */ -#ifndef PNG_ZBUF_SIZE -# define PNG_ZBUF_SIZE 8192 -#endif -# include -# include -# include -# define FCLOSE(file) fclose(file) - -#ifndef PNG_STDIO_SUPPORTED -typedef FILE * png_FILE_p; -#endif - -/* Makes pngtest verbose so we can find problems. */ -#ifndef PNG_DEBUG -# define PNG_DEBUG 0 -#endif - -#if PNG_DEBUG > 1 -# define pngtest_debug(m) ((void)fprintf(stderr, m "\n")) -# define pngtest_debug1(m,p1) ((void)fprintf(stderr, m "\n", p1)) -# define pngtest_debug2(m,p1,p2) ((void)fprintf(stderr, m "\n", p1, p2)) -#else -# define pngtest_debug(m) ((void)0) -# define pngtest_debug1(m,p1) ((void)0) -# define pngtest_debug2(m,p1,p2) ((void)0) -#endif - -#if !PNG_DEBUG -# define SINGLE_ROWBUF_ALLOC /* Makes buffer overruns easier to nail */ -#endif - -/* The code uses memcmp and memcpy on large objects (typically row pointers) so - * it is necessary to do soemthing special on certain architectures, note that - * the actual support for this was effectively removed in 1.4, so only the - * memory remains in this program: - */ -#define CVT_PTR(ptr) (ptr) -#define CVT_PTR_NOCHECK(ptr) (ptr) -#define png_memcmp memcmp -#define png_memcpy memcpy -#define png_memset memset - -/* Turn on CPU timing -#define PNGTEST_TIMING -*/ - -#ifndef PNG_FLOATING_POINT_SUPPORTED -#undef PNGTEST_TIMING -#endif - -#ifdef PNGTEST_TIMING -static float t_start, t_stop, t_decode, t_encode, t_misc; -#include -#endif - -#ifdef PNG_TIME_RFC1123_SUPPORTED -#define PNG_tIME_STRING_LENGTH 29 -static int tIME_chunk_present = 0; -static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present"; -#endif - -static int verbose = 0; -static int strict = 0; - -int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname)); - -#ifdef __TURBOC__ -#include -#endif - -/* Defined so I can write to a file on gui/windowing platforms */ -/* #define STDERR stderr */ -#define STDERR stdout /* For DOS */ - -/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */ -#ifndef png_jmpbuf -# define png_jmpbuf(png_ptr) png_ptr->jmpbuf -#endif - -/* Example of using row callbacks to make a simple progress meter */ -static int status_pass = 1; -static int status_dots_requested = 0; -static int status_dots = 1; - -void PNGCBAPI -read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); -void PNGCBAPI -read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) -{ - if (png_ptr == NULL || row_number > PNG_UINT_31_MAX) - return; - - if (status_pass != pass) - { - fprintf(stdout, "\n Pass %d: ", pass); - status_pass = pass; - status_dots = 31; - } - - status_dots--; - - if (status_dots == 0) - { - fprintf(stdout, "\n "); - status_dots=30; - } - - fprintf(stdout, "r"); -} - -void PNGCBAPI -write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); -void PNGCBAPI -write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) -{ - if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7) - return; - - fprintf(stdout, "w"); -} - - -#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED -/* Example of using user transform callback (we don't transform anything, - * but merely examine the row filters. We set this to 256 rather than - * 5 in case illegal filter values are present.) - */ -static png_uint_32 filters_used[256]; -void PNGCBAPI -count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data); -void PNGCBAPI -count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data) -{ - if (png_ptr != NULL && row_info != NULL) - ++filters_used[*(data - 1)]; -} -#endif - -#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED -/* Example of using user transform callback (we don't transform anything, - * but merely count the zero samples) - */ - -static png_uint_32 zero_samples; - -void PNGCBAPI -count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data); -void PNGCBAPI -count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data) -{ - png_bytep dp = data; - if (png_ptr == NULL) - return; - - /* Contents of row_info: - * png_uint_32 width width of row - * png_uint_32 rowbytes number of bytes in row - * png_byte color_type color type of pixels - * png_byte bit_depth bit depth of samples - * png_byte channels number of channels (1-4) - * png_byte pixel_depth bits per pixel (depth*channels) - */ - - /* Counts the number of zero samples (or zero pixels if color_type is 3 */ - - if (row_info->color_type == 0 || row_info->color_type == 3) - { - int pos = 0; - png_uint_32 n, nstop; - - for (n = 0, nstop=row_info->width; nbit_depth == 1) - { - if (((*dp << pos++ ) & 0x80) == 0) - zero_samples++; - - if (pos == 8) - { - pos = 0; - dp++; - } - } - - if (row_info->bit_depth == 2) - { - if (((*dp << (pos+=2)) & 0xc0) == 0) - zero_samples++; - - if (pos == 8) - { - pos = 0; - dp++; - } - } - - if (row_info->bit_depth == 4) - { - if (((*dp << (pos+=4)) & 0xf0) == 0) - zero_samples++; - - if (pos == 8) - { - pos = 0; - dp++; - } - } - - if (row_info->bit_depth == 8) - if (*dp++ == 0) - zero_samples++; - - if (row_info->bit_depth == 16) - { - if ((*dp | *(dp+1)) == 0) - zero_samples++; - dp+=2; - } - } - } - else /* Other color types */ - { - png_uint_32 n, nstop; - int channel; - int color_channels = row_info->channels; - if (row_info->color_type > 3)color_channels--; - - for (n = 0, nstop=row_info->width; nbit_depth == 8) - if (*dp++ == 0) - zero_samples++; - - if (row_info->bit_depth == 16) - { - if ((*dp | *(dp+1)) == 0) - zero_samples++; - - dp+=2; - } - } - if (row_info->color_type > 3) - { - dp++; - if (row_info->bit_depth == 16) - dp++; - } - } - } -} -#endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */ - -static int wrote_question = 0; - -#ifndef PNG_STDIO_SUPPORTED -/* START of code to validate stdio-free compilation */ -/* These copies of the default read/write functions come from pngrio.c and - * pngwio.c. They allow "don't include stdio" testing of the library. - * This is the function that does the actual reading of data. If you are - * not reading from a standard C stream, you should create a replacement - * read_data function and use it at run time with png_set_read_fn(), rather - * than changing the library. - */ - -#ifdef PNG_IO_STATE_SUPPORTED -void -pngtest_check_io_state(png_structp png_ptr, png_size_t data_length, - png_uint_32 io_op); -void -pngtest_check_io_state(png_structp png_ptr, png_size_t data_length, - png_uint_32 io_op) -{ - png_uint_32 io_state = png_get_io_state(png_ptr); - int err = 0; - - /* Check if the current operation (reading / writing) is as expected. */ - if ((io_state & PNG_IO_MASK_OP) != io_op) - png_error(png_ptr, "Incorrect operation in I/O state"); - - /* Check if the buffer size specific to the current location - * (file signature / header / data / crc) is as expected. - */ - switch (io_state & PNG_IO_MASK_LOC) - { - case PNG_IO_SIGNATURE: - if (data_length > 8) - err = 1; - break; - case PNG_IO_CHUNK_HDR: - if (data_length != 8) - err = 1; - break; - case PNG_IO_CHUNK_DATA: - break; /* no restrictions here */ - case PNG_IO_CHUNK_CRC: - if (data_length != 4) - err = 1; - break; - default: - err = 1; /* uninitialized */ - } - if (err) - png_error(png_ptr, "Bad I/O state or buffer size"); -} -#endif - -#ifndef USE_FAR_KEYWORD -static void PNGCBAPI -pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) -{ - png_size_t check = 0; - png_voidp io_ptr; - - /* fread() returns 0 on error, so it is OK to store this in a png_size_t - * instead of an int, which is what fread() actually returns. - */ - io_ptr = png_get_io_ptr(png_ptr); - if (io_ptr != NULL) - { - check = fread(data, 1, length, (png_FILE_p)io_ptr); - } - - if (check != length) - { - png_error(png_ptr, "Read Error"); - } - -#ifdef PNG_IO_STATE_SUPPORTED - pngtest_check_io_state(png_ptr, length, PNG_IO_READING); -#endif -} -#else -/* This is the model-independent version. Since the standard I/O library - can't handle far buffers in the medium and small models, we have to copy - the data. -*/ - -#define NEAR_BUF_SIZE 1024 -#define MIN(a,b) (a <= b ? a : b) - -static void PNGCBAPI -pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) -{ - png_size_t check; - png_byte *n_data; - png_FILE_p io_ptr; - - /* Check if data really is near. If so, use usual code. */ - n_data = (png_byte *)CVT_PTR_NOCHECK(data); - io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr)); - if ((png_bytep)n_data == data) - { - check = fread(n_data, 1, length, io_ptr); - } - else - { - png_byte buf[NEAR_BUF_SIZE]; - png_size_t read, remaining, err; - check = 0; - remaining = length; - - do - { - read = MIN(NEAR_BUF_SIZE, remaining); - err = fread(buf, 1, 1, io_ptr); - png_memcpy(data, buf, read); /* Copy far buffer to near buffer */ - if (err != read) - break; - else - check += err; - data += read; - remaining -= read; - } - while (remaining != 0); - } - - if (check != length) - png_error(png_ptr, "Read Error"); - -#ifdef PNG_IO_STATE_SUPPORTED - pngtest_check_io_state(png_ptr, length, PNG_IO_READING); -#endif -} -#endif /* USE_FAR_KEYWORD */ - -#ifdef PNG_WRITE_FLUSH_SUPPORTED -static void PNGCBAPI -pngtest_flush(png_structp png_ptr) -{ - /* Do nothing; fflush() is said to be just a waste of energy. */ - PNG_UNUSED(png_ptr) /* Stifle compiler warning */ -} -#endif - -/* This is the function that does the actual writing of data. If you are - * not writing to a standard C stream, you should create a replacement - * write_data function and use it at run time with png_set_write_fn(), rather - * than changing the library. - */ -#ifndef USE_FAR_KEYWORD -static void PNGCBAPI -pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) -{ - png_size_t check; - - check = fwrite(data, 1, length, (png_FILE_p)png_get_io_ptr(png_ptr)); - - if (check != length) - { - png_error(png_ptr, "Write Error"); - } - -#ifdef PNG_IO_STATE_SUPPORTED - pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING); -#endif -} -#else -/* This is the model-independent version. Since the standard I/O library - can't handle far buffers in the medium and small models, we have to copy - the data. -*/ - -#define NEAR_BUF_SIZE 1024 -#define MIN(a,b) (a <= b ? a : b) - -static void PNGCBAPI -pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) -{ - png_size_t check; - png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ - png_FILE_p io_ptr; - - /* Check if data really is near. If so, use usual code. */ - near_data = (png_byte *)CVT_PTR_NOCHECK(data); - io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr)); - - if ((png_bytep)near_data == data) - { - check = fwrite(near_data, 1, length, io_ptr); - } - - else - { - png_byte buf[NEAR_BUF_SIZE]; - png_size_t written, remaining, err; - check = 0; - remaining = length; - - do - { - written = MIN(NEAR_BUF_SIZE, remaining); - png_memcpy(buf, data, written); /* Copy far buffer to near buffer */ - err = fwrite(buf, 1, written, io_ptr); - if (err != written) - break; - else - check += err; - data += written; - remaining -= written; - } - while (remaining != 0); - } - - if (check != length) - { - png_error(png_ptr, "Write Error"); - } - -#ifdef PNG_IO_STATE_SUPPORTED - pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING); -#endif -} -#endif /* USE_FAR_KEYWORD */ - -/* This function is called when there is a warning, but the library thinks - * it can continue anyway. Replacement functions don't have to do anything - * here if you don't want to. In the default configuration, png_ptr is - * not used, but it is passed in case it may be useful. - */ -static void PNGCBAPI -pngtest_warning(png_structp png_ptr, png_const_charp message) -{ - PNG_CONST char *name = "UNKNOWN (ERROR!)"; - char *test; - test = png_get_error_ptr(png_ptr); - - if (test == NULL) - fprintf(STDERR, "%s: libpng warning: %s\n", name, message); - - else - fprintf(STDERR, "%s: libpng warning: %s\n", test, message); -} - -/* This is the default error handling function. Note that replacements for - * this function MUST NOT RETURN, or the program will likely crash. This - * function is used by default, or if the program supplies NULL for the - * error function pointer in png_set_error_fn(). - */ -static void PNGCBAPI -pngtest_error(png_structp png_ptr, png_const_charp message) -{ - pngtest_warning(png_ptr, message); - /* We can return because png_error calls the default handler, which is - * actually OK in this case. - */ -} -#endif /* !PNG_STDIO_SUPPORTED */ -/* END of code to validate stdio-free compilation */ - -/* START of code to validate memory allocation and deallocation */ -#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG - -/* Allocate memory. For reasonable files, size should never exceed - * 64K. However, zlib may allocate more then 64K if you don't tell - * it not to. See zconf.h and png.h for more information. zlib does - * need to allocate exactly 64K, so whatever you call here must - * have the ability to do that. - * - * This piece of code can be compiled to validate max 64K allocations - * by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. - */ -typedef struct memory_information -{ - png_alloc_size_t size; - png_voidp pointer; - struct memory_information FAR *next; -} memory_information; -typedef memory_information FAR *memory_infop; - -static memory_infop pinformation = NULL; -static int current_allocation = 0; -static int maximum_allocation = 0; -static int total_allocation = 0; -static int num_allocations = 0; - -png_voidp PNGCBAPI png_debug_malloc PNGARG((png_structp png_ptr, - png_alloc_size_t size)); -void PNGCBAPI png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr)); - -png_voidp -PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size) -{ - - /* png_malloc has already tested for NULL; png_create_struct calls - * png_debug_malloc directly, with png_ptr == NULL which is OK - */ - - if (size == 0) - return (NULL); - - /* This calls the library allocator twice, once to get the requested - buffer and once to get a new free list entry. */ - { - /* Disable malloc_fn and free_fn */ - memory_infop pinfo; - png_set_mem_fn(png_ptr, NULL, NULL, NULL); - pinfo = (memory_infop)png_malloc(png_ptr, - png_sizeof(*pinfo)); - pinfo->size = size; - current_allocation += size; - total_allocation += size; - num_allocations ++; - - if (current_allocation > maximum_allocation) - maximum_allocation = current_allocation; - - pinfo->pointer = png_malloc(png_ptr, size); - /* Restore malloc_fn and free_fn */ - - png_set_mem_fn(png_ptr, - NULL, png_debug_malloc, png_debug_free); - - if (size != 0 && pinfo->pointer == NULL) - { - current_allocation -= size; - total_allocation -= size; - png_error(png_ptr, - "out of memory in pngtest->png_debug_malloc"); - } - - pinfo->next = pinformation; - pinformation = pinfo; - /* Make sure the caller isn't assuming zeroed memory. */ - png_memset(pinfo->pointer, 0xdd, pinfo->size); - - if (verbose) - printf("png_malloc %lu bytes at %p\n", (unsigned long)size, - pinfo->pointer); - - return (png_voidp)(pinfo->pointer); - } -} - -/* Free a pointer. It is removed from the list at the same time. */ -void PNGCBAPI -png_debug_free(png_structp png_ptr, png_voidp ptr) -{ - if (png_ptr == NULL) - fprintf(STDERR, "NULL pointer to png_debug_free.\n"); - - if (ptr == 0) - { -#if 0 /* This happens all the time. */ - fprintf(STDERR, "WARNING: freeing NULL pointer\n"); -#endif - return; - } - - /* Unlink the element from the list. */ - { - memory_infop FAR *ppinfo = &pinformation; - - for (;;) - { - memory_infop pinfo = *ppinfo; - - if (pinfo->pointer == ptr) - { - *ppinfo = pinfo->next; - current_allocation -= pinfo->size; - if (current_allocation < 0) - fprintf(STDERR, "Duplicate free of memory\n"); - /* We must free the list element too, but first kill - the memory that is to be freed. */ - png_memset(ptr, 0x55, pinfo->size); - png_free_default(png_ptr, pinfo); - pinfo = NULL; - break; - } - - if (pinfo->next == NULL) - { - fprintf(STDERR, "Pointer %x not found\n", (unsigned int)ptr); - break; - } - - ppinfo = &pinfo->next; - } - } - - /* Finally free the data. */ - if (verbose) - printf("Freeing %p\n", ptr); - - png_free_default(png_ptr, ptr); - ptr = NULL; -} -#endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */ -/* END of code to test memory allocation/deallocation */ - - -/* Demonstration of user chunk support of the sTER and vpAg chunks */ -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED - -/* (sTER is a public chunk not yet known by libpng. vpAg is a private -chunk used in ImageMagick to store "virtual page" size). */ - -static png_uint_32 user_chunk_data[4]; - - /* 0: sTER mode + 1 - * 1: vpAg width - * 2: vpAg height - * 3: vpAg units - */ - -static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr, - png_unknown_chunkp chunk) -{ - png_uint_32 - *my_user_chunk_data; - - /* Return one of the following: - * return (-n); chunk had an error - * return (0); did not recognize - * return (n); success - * - * The unknown chunk structure contains the chunk data: - * png_byte name[5]; - * png_byte *data; - * png_size_t size; - * - * Note that libpng has already taken care of the CRC handling. - */ - - if (chunk->name[0] == 115 && chunk->name[1] == 84 && /* s T */ - chunk->name[2] == 69 && chunk->name[3] == 82) /* E R */ - { - /* Found sTER chunk */ - if (chunk->size != 1) - return (-1); /* Error return */ - - if (chunk->data[0] != 0 && chunk->data[0] != 1) - return (-1); /* Invalid mode */ - - my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr); - my_user_chunk_data[0]=chunk->data[0]+1; - return (1); - } - - if (chunk->name[0] != 118 || chunk->name[1] != 112 || /* v p */ - chunk->name[2] != 65 || chunk->name[3] != 103) /* A g */ - return (0); /* Did not recognize */ - - /* Found ImageMagick vpAg chunk */ - - if (chunk->size != 9) - return (-1); /* Error return */ - - my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr); - - my_user_chunk_data[1]=png_get_uint_31(png_ptr, chunk->data); - my_user_chunk_data[2]=png_get_uint_31(png_ptr, chunk->data + 4); - my_user_chunk_data[3]=(png_uint_32)chunk->data[8]; - - return (1); - -} -#endif -/* END of code to demonstrate user chunk support */ - -/* Test one file */ -int -test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) -{ - static png_FILE_p fpin; - static png_FILE_p fpout; /* "static" prevents setjmp corruption */ - png_structp read_ptr; - png_infop read_info_ptr, end_info_ptr; -#ifdef PNG_WRITE_SUPPORTED - png_structp write_ptr; - png_infop write_info_ptr; - png_infop write_end_info_ptr; -#else - png_structp write_ptr = NULL; - png_infop write_info_ptr = NULL; - png_infop write_end_info_ptr = NULL; -#endif - png_bytep row_buf; - png_uint_32 y; - png_uint_32 width, height; - int num_pass, pass; - int bit_depth, color_type; -#ifdef PNG_SETJMP_SUPPORTED -#ifdef USE_FAR_KEYWORD - jmp_buf tmp_jmpbuf; -#endif -#endif - - char inbuf[256], outbuf[256]; - - row_buf = NULL; - - if ((fpin = fopen(inname, "rb")) == NULL) - { - fprintf(STDERR, "Could not find input file %s\n", inname); - return (1); - } - - if ((fpout = fopen(outname, "wb")) == NULL) - { - fprintf(STDERR, "Could not open output file %s\n", outname); - FCLOSE(fpin); - return (1); - } - - pngtest_debug("Allocating read and write structures"); -#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG - read_ptr = - png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL, - NULL, NULL, NULL, png_debug_malloc, png_debug_free); -#else - read_ptr = - png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); -#endif -#ifndef PNG_STDIO_SUPPORTED - png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error, - pngtest_warning); -#endif - -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED - user_chunk_data[0] = 0; - user_chunk_data[1] = 0; - user_chunk_data[2] = 0; - user_chunk_data[3] = 0; - png_set_read_user_chunk_fn(read_ptr, user_chunk_data, - read_user_chunk_callback); - -#endif -#ifdef PNG_WRITE_SUPPORTED -#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG - write_ptr = - png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL, - NULL, NULL, NULL, png_debug_malloc, png_debug_free); -#else - write_ptr = - png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); -#endif -#ifndef PNG_STDIO_SUPPORTED - png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error, - pngtest_warning); -#endif -#endif - pngtest_debug("Allocating read_info, write_info and end_info structures"); - read_info_ptr = png_create_info_struct(read_ptr); - end_info_ptr = png_create_info_struct(read_ptr); -#ifdef PNG_WRITE_SUPPORTED - write_info_ptr = png_create_info_struct(write_ptr); - write_end_info_ptr = png_create_info_struct(write_ptr); -#endif - -#ifdef PNG_SETJMP_SUPPORTED - pngtest_debug("Setting jmpbuf for read struct"); -#ifdef USE_FAR_KEYWORD - if (setjmp(tmp_jmpbuf)) -#else - if (setjmp(png_jmpbuf(read_ptr))) -#endif - { - fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname); - png_free(read_ptr, row_buf); - row_buf = NULL; - png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); -#ifdef PNG_WRITE_SUPPORTED - png_destroy_info_struct(write_ptr, &write_end_info_ptr); - png_destroy_write_struct(&write_ptr, &write_info_ptr); -#endif - FCLOSE(fpin); - FCLOSE(fpout); - return (1); - } -#ifdef USE_FAR_KEYWORD - png_memcpy(png_jmpbuf(read_ptr), tmp_jmpbuf, png_sizeof(jmp_buf)); -#endif - -#ifdef PNG_WRITE_SUPPORTED - pngtest_debug("Setting jmpbuf for write struct"); -#ifdef USE_FAR_KEYWORD - - if (setjmp(tmp_jmpbuf)) -#else - if (setjmp(png_jmpbuf(write_ptr))) -#endif - { - fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname); - png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); - png_destroy_info_struct(write_ptr, &write_end_info_ptr); -#ifdef PNG_WRITE_SUPPORTED - png_destroy_write_struct(&write_ptr, &write_info_ptr); -#endif - FCLOSE(fpin); - FCLOSE(fpout); - return (1); - } - -#ifdef USE_FAR_KEYWORD - png_memcpy(png_jmpbuf(write_ptr), tmp_jmpbuf, png_sizeof(jmp_buf)); -#endif -#endif -#endif - - pngtest_debug("Initializing input and output streams"); -#ifdef PNG_STDIO_SUPPORTED - png_init_io(read_ptr, fpin); -# ifdef PNG_WRITE_SUPPORTED - png_init_io(write_ptr, fpout); -# endif -#else - png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data); -# ifdef PNG_WRITE_SUPPORTED - png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data, -# ifdef PNG_WRITE_FLUSH_SUPPORTED - pngtest_flush); -# else - NULL); -# endif -# endif -#endif - -#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED - /* Normally one would use Z_DEFAULT_STRATEGY for text compression. - * This is here just to make pngtest replicate the results from libpng - * versions prior to 1.5.4, and to test this new API. - */ - png_set_text_compression_strategy(write_ptr, Z_FILTERED); -#endif - - if (status_dots_requested == 1) - { -#ifdef PNG_WRITE_SUPPORTED - png_set_write_status_fn(write_ptr, write_row_callback); -#endif - png_set_read_status_fn(read_ptr, read_row_callback); - } - - else - { -#ifdef PNG_WRITE_SUPPORTED - png_set_write_status_fn(write_ptr, NULL); -#endif - png_set_read_status_fn(read_ptr, NULL); - } - -#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED - { - int i; - - for (i = 0; i<256; i++) - filters_used[i] = 0; - - png_set_read_user_transform_fn(read_ptr, count_filters); - } -#endif -#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED - zero_samples = 0; - png_set_write_user_transform_fn(write_ptr, count_zero_samples); -#endif - -#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED -# ifndef PNG_HANDLE_CHUNK_ALWAYS -# define PNG_HANDLE_CHUNK_ALWAYS 3 -# endif - png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS, - NULL, 0); -#endif -#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED -# ifndef PNG_HANDLE_CHUNK_IF_SAFE -# define PNG_HANDLE_CHUNK_IF_SAFE 2 -# endif - png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE, - NULL, 0); -#endif - - pngtest_debug("Reading info struct"); - png_read_info(read_ptr, read_info_ptr); - - pngtest_debug("Transferring info struct"); - { - int interlace_type, compression_type, filter_type; - - if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth, - &color_type, &interlace_type, &compression_type, &filter_type)) - { - png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth, -#ifdef PNG_WRITE_INTERLACING_SUPPORTED - color_type, interlace_type, compression_type, filter_type); -#else - color_type, PNG_INTERLACE_NONE, compression_type, filter_type); -#endif - } - } -#ifdef PNG_FIXED_POINT_SUPPORTED -#ifdef PNG_cHRM_SUPPORTED - { - png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x, - blue_y; - - if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y, - &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y)) - { - png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x, - red_y, green_x, green_y, blue_x, blue_y); - } - } -#endif -#ifdef PNG_gAMA_SUPPORTED - { - png_fixed_point gamma; - - if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma)) - png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma); - } -#endif -#else /* Use floating point versions */ -#ifdef PNG_FLOATING_POINT_SUPPORTED -#ifdef PNG_cHRM_SUPPORTED - { - double white_x, white_y, red_x, red_y, green_x, green_y, blue_x, - blue_y; - - if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x, - &red_y, &green_x, &green_y, &blue_x, &blue_y)) - { - png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x, - red_y, green_x, green_y, blue_x, blue_y); - } - } -#endif -#ifdef PNG_gAMA_SUPPORTED - { - double gamma; - - if (png_get_gAMA(read_ptr, read_info_ptr, &gamma)) - png_set_gAMA(write_ptr, write_info_ptr, gamma); - } -#endif -#endif /* Floating point */ -#endif /* Fixed point */ -#ifdef PNG_iCCP_SUPPORTED - { - png_charp name; - png_bytep profile; - png_uint_32 proflen; - int compression_type; - - if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type, - &profile, &proflen)) - { - png_set_iCCP(write_ptr, write_info_ptr, name, compression_type, - profile, proflen); - } - } -#endif -#ifdef PNG_sRGB_SUPPORTED - { - int intent; - - if (png_get_sRGB(read_ptr, read_info_ptr, &intent)) - png_set_sRGB(write_ptr, write_info_ptr, intent); - } -#endif - { - png_colorp palette; - int num_palette; - - if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette)) - png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); - } -#ifdef PNG_bKGD_SUPPORTED - { - png_color_16p background; - - if (png_get_bKGD(read_ptr, read_info_ptr, &background)) - { - png_set_bKGD(write_ptr, write_info_ptr, background); - } - } -#endif -#ifdef PNG_hIST_SUPPORTED - { - png_uint_16p hist; - - if (png_get_hIST(read_ptr, read_info_ptr, &hist)) - png_set_hIST(write_ptr, write_info_ptr, hist); - } -#endif -#ifdef PNG_oFFs_SUPPORTED - { - png_int_32 offset_x, offset_y; - int unit_type; - - if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y, - &unit_type)) - { - png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type); - } - } -#endif -#ifdef PNG_pCAL_SUPPORTED - { - png_charp purpose, units; - png_charpp params; - png_int_32 X0, X1; - int type, nparams; - - if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type, - &nparams, &units, ¶ms)) - { - png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type, - nparams, units, params); - } - } -#endif -#ifdef PNG_pHYs_SUPPORTED - { - png_uint_32 res_x, res_y; - int unit_type; - - if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type)) - png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type); - } -#endif -#ifdef PNG_sBIT_SUPPORTED - { - png_color_8p sig_bit; - - if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit)) - png_set_sBIT(write_ptr, write_info_ptr, sig_bit); - } -#endif -#ifdef PNG_sCAL_SUPPORTED -#ifdef PNG_FLOATING_POINT_SUPPORTED - { - int unit; - double scal_width, scal_height; - - if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width, - &scal_height)) - { - png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height); - } - } -#else -#ifdef PNG_FIXED_POINT_SUPPORTED - { - int unit; - png_charp scal_width, scal_height; - - if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width, - &scal_height)) - { - png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width, - scal_height); - } - } -#endif -#endif -#endif -#ifdef PNG_TEXT_SUPPORTED - { - png_textp text_ptr; - int num_text; - - if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0) - { - pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text); - - if (verbose) - printf("\n Text compression=%d\n", text_ptr->compression); - - png_set_text(write_ptr, write_info_ptr, text_ptr, num_text); - } - } -#endif -#ifdef PNG_tIME_SUPPORTED - { - png_timep mod_time; - - if (png_get_tIME(read_ptr, read_info_ptr, &mod_time)) - { - png_set_tIME(write_ptr, write_info_ptr, mod_time); -#ifdef PNG_TIME_RFC1123_SUPPORTED - /* We have to use png_memcpy instead of "=" because the string - * pointed to by png_convert_to_rfc1123() gets free'ed before - * we use it. - */ - png_memcpy(tIME_string, - png_convert_to_rfc1123(read_ptr, mod_time), - png_sizeof(tIME_string)); - - tIME_string[png_sizeof(tIME_string) - 1] = '\0'; - tIME_chunk_present++; -#endif /* PNG_TIME_RFC1123_SUPPORTED */ - } - } -#endif -#ifdef PNG_tRNS_SUPPORTED - { - png_bytep trans_alpha; - int num_trans; - png_color_16p trans_color; - - if (png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans, - &trans_color)) - { - int sample_max = (1 << bit_depth); - /* libpng doesn't reject a tRNS chunk with out-of-range samples */ - if (!((color_type == PNG_COLOR_TYPE_GRAY && - (int)trans_color->gray > sample_max) || - (color_type == PNG_COLOR_TYPE_RGB && - ((int)trans_color->red > sample_max || - (int)trans_color->green > sample_max || - (int)trans_color->blue > sample_max)))) - png_set_tRNS(write_ptr, write_info_ptr, trans_alpha, num_trans, - trans_color); - } - } -#endif -#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED - { - png_unknown_chunkp unknowns; - int num_unknowns = png_get_unknown_chunks(read_ptr, read_info_ptr, - &unknowns); - - if (num_unknowns) - { - int i; - png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns, - num_unknowns); - /* Copy the locations from the read_info_ptr. The automatically - * generated locations in write_info_ptr are wrong because we - * haven't written anything yet. - */ - for (i = 0; i < num_unknowns; i++) - png_set_unknown_chunk_location(write_ptr, write_info_ptr, i, - unknowns[i].location); - } - } -#endif - -#ifdef PNG_WRITE_SUPPORTED - pngtest_debug("Writing info struct"); - -/* If we wanted, we could write info in two steps: - * png_write_info_before_PLTE(write_ptr, write_info_ptr); - */ - png_write_info(write_ptr, write_info_ptr); - -#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED - if (user_chunk_data[0] != 0) - { - png_byte png_sTER[5] = {115, 84, 69, 82, '\0'}; - - unsigned char - ster_chunk_data[1]; - - if (verbose) - fprintf(STDERR, "\n stereo mode = %lu\n", - (unsigned long)(user_chunk_data[0] - 1)); - - ster_chunk_data[0]=(unsigned char)(user_chunk_data[0] - 1); - png_write_chunk(write_ptr, png_sTER, ster_chunk_data, 1); - } - - if (user_chunk_data[1] != 0 || user_chunk_data[2] != 0) - { - png_byte png_vpAg[5] = {118, 112, 65, 103, '\0'}; - - unsigned char - vpag_chunk_data[9]; - - if (verbose) - fprintf(STDERR, " vpAg = %lu x %lu, units = %lu\n", - (unsigned long)user_chunk_data[1], - (unsigned long)user_chunk_data[2], - (unsigned long)user_chunk_data[3]); - - png_save_uint_32(vpag_chunk_data, user_chunk_data[1]); - png_save_uint_32(vpag_chunk_data + 4, user_chunk_data[2]); - vpag_chunk_data[8] = (unsigned char)(user_chunk_data[3] & 0xff); - png_write_chunk(write_ptr, png_vpAg, vpag_chunk_data, 9); - } - -#endif -#endif - -#ifdef SINGLE_ROWBUF_ALLOC - pngtest_debug("Allocating row buffer..."); - row_buf = (png_bytep)png_malloc(read_ptr, - png_get_rowbytes(read_ptr, read_info_ptr)); - - pngtest_debug1("\t0x%08lx", (unsigned long)row_buf); -#endif /* SINGLE_ROWBUF_ALLOC */ - pngtest_debug("Writing row data"); - -#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ - defined(PNG_WRITE_INTERLACING_SUPPORTED) - num_pass = png_set_interlace_handling(read_ptr); -# ifdef PNG_WRITE_SUPPORTED - png_set_interlace_handling(write_ptr); -# endif -#else - num_pass = 1; -#endif - -#ifdef PNGTEST_TIMING - t_stop = (float)clock(); - t_misc += (t_stop - t_start); - t_start = t_stop; -#endif - for (pass = 0; pass < num_pass; pass++) - { - pngtest_debug1("Writing row data for pass %d", pass); - for (y = 0; y < height; y++) - { -#ifndef SINGLE_ROWBUF_ALLOC - pngtest_debug2("Allocating row buffer (pass %d, y = %u)...", pass, y); - row_buf = (png_bytep)png_malloc(read_ptr, - png_get_rowbytes(read_ptr, read_info_ptr)); - - pngtest_debug2("\t0x%08lx (%u bytes)", (unsigned long)row_buf, - png_get_rowbytes(read_ptr, read_info_ptr)); - -#endif /* !SINGLE_ROWBUF_ALLOC */ - png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1); - -#ifdef PNG_WRITE_SUPPORTED -#ifdef PNGTEST_TIMING - t_stop = (float)clock(); - t_decode += (t_stop - t_start); - t_start = t_stop; -#endif - png_write_rows(write_ptr, (png_bytepp)&row_buf, 1); -#ifdef PNGTEST_TIMING - t_stop = (float)clock(); - t_encode += (t_stop - t_start); - t_start = t_stop; -#endif -#endif /* PNG_WRITE_SUPPORTED */ - -#ifndef SINGLE_ROWBUF_ALLOC - pngtest_debug2("Freeing row buffer (pass %d, y = %u)", pass, y); - png_free(read_ptr, row_buf); - row_buf = NULL; -#endif /* !SINGLE_ROWBUF_ALLOC */ - } - } - -#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED - png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1); -#endif -#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED - png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1); -#endif - - pngtest_debug("Reading and writing end_info data"); - - png_read_end(read_ptr, end_info_ptr); -#ifdef PNG_TEXT_SUPPORTED - { - png_textp text_ptr; - int num_text; - - if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0) - { - pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text); - png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text); - } - } -#endif -#ifdef PNG_tIME_SUPPORTED - { - png_timep mod_time; - - if (png_get_tIME(read_ptr, end_info_ptr, &mod_time)) - { - png_set_tIME(write_ptr, write_end_info_ptr, mod_time); -#ifdef PNG_TIME_RFC1123_SUPPORTED - /* We have to use png_memcpy instead of "=" because the string - pointed to by png_convert_to_rfc1123() gets free'ed before - we use it */ - png_memcpy(tIME_string, - png_convert_to_rfc1123(read_ptr, mod_time), - png_sizeof(tIME_string)); - - tIME_string[png_sizeof(tIME_string) - 1] = '\0'; - tIME_chunk_present++; -#endif /* PNG_TIME_RFC1123_SUPPORTED */ - } - } -#endif -#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED - { - png_unknown_chunkp unknowns; - int num_unknowns = png_get_unknown_chunks(read_ptr, end_info_ptr, - &unknowns); - - if (num_unknowns) - { - int i; - png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns, - num_unknowns); - /* Copy the locations from the read_info_ptr. The automatically - * generated locations in write_end_info_ptr are wrong because we - * haven't written the end_info yet. - */ - for (i = 0; i < num_unknowns; i++) - png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i, - unknowns[i].location); - } - } -#endif -#ifdef PNG_WRITE_SUPPORTED - png_write_end(write_ptr, write_end_info_ptr); -#endif - -#ifdef PNG_EASY_ACCESS_SUPPORTED - if (verbose) - { - png_uint_32 iwidth, iheight; - iwidth = png_get_image_width(write_ptr, write_info_ptr); - iheight = png_get_image_height(write_ptr, write_info_ptr); - fprintf(STDERR, "\n Image width = %lu, height = %lu\n", - (unsigned long)iwidth, (unsigned long)iheight); - } -#endif - - pngtest_debug("Destroying data structs"); -#ifdef SINGLE_ROWBUF_ALLOC - pngtest_debug("destroying row_buf for read_ptr"); - png_free(read_ptr, row_buf); - row_buf = NULL; -#endif /* SINGLE_ROWBUF_ALLOC */ - pngtest_debug("destroying read_ptr, read_info_ptr, end_info_ptr"); - png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); -#ifdef PNG_WRITE_SUPPORTED - pngtest_debug("destroying write_end_info_ptr"); - png_destroy_info_struct(write_ptr, &write_end_info_ptr); - pngtest_debug("destroying write_ptr, write_info_ptr"); - png_destroy_write_struct(&write_ptr, &write_info_ptr); -#endif - pngtest_debug("Destruction complete."); - - FCLOSE(fpin); - FCLOSE(fpout); - - pngtest_debug("Opening files for comparison"); - if ((fpin = fopen(inname, "rb")) == NULL) - { - fprintf(STDERR, "Could not find file %s\n", inname); - return (1); - } - - if ((fpout = fopen(outname, "rb")) == NULL) - { - fprintf(STDERR, "Could not find file %s\n", outname); - FCLOSE(fpin); - return (1); - } - - for (;;) - { - png_size_t num_in, num_out; - - num_in = fread(inbuf, 1, 1, fpin); - num_out = fread(outbuf, 1, 1, fpout); - - if (num_in != num_out) - { - fprintf(STDERR, "\nFiles %s and %s are of a different size\n", - inname, outname); - - if (wrote_question == 0) - { - fprintf(STDERR, - " Was %s written with the same maximum IDAT chunk size (%d bytes),", - inname, PNG_ZBUF_SIZE); - fprintf(STDERR, - "\n filtering heuristic (libpng default), compression"); - fprintf(STDERR, - " level (zlib default),\n and zlib version (%s)?\n\n", - ZLIB_VERSION); - wrote_question = 1; - } - - FCLOSE(fpin); - FCLOSE(fpout); - - if (strict != 0) - return (1); - - else - return (0); - } - - if (!num_in) - break; - - if (png_memcmp(inbuf, outbuf, num_in)) - { - fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname); - - if (wrote_question == 0) - { - fprintf(STDERR, - " Was %s written with the same maximum IDAT chunk size (%d bytes),", - inname, PNG_ZBUF_SIZE); - fprintf(STDERR, - "\n filtering heuristic (libpng default), compression"); - fprintf(STDERR, - " level (zlib default),\n and zlib version (%s)?\n\n", - ZLIB_VERSION); - wrote_question = 1; - } - - FCLOSE(fpin); - FCLOSE(fpout); - - if (strict != 0) - return (1); - - else - return (0); - } - } - - FCLOSE(fpin); - FCLOSE(fpout); - - return (0); -} - -/* Input and output filenames */ -#ifdef RISCOS -static PNG_CONST char *inname = "pngtest/png"; -static PNG_CONST char *outname = "pngout/png"; -#else -static PNG_CONST char *inname = "pngtest.png"; -static PNG_CONST char *outname = "pngout.png"; -#endif - -int -main(int argc, char *argv[]) -{ - int multiple = 0; - int ierror = 0; - - fprintf(STDERR, "\n Testing libpng version %s\n", PNG_LIBPNG_VER_STRING); - fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION); - fprintf(STDERR, "%s", png_get_copyright(NULL)); - /* Show the version of libpng used in building the library */ - fprintf(STDERR, " library (%lu):%s", - (unsigned long)png_access_version_number(), - png_get_header_version(NULL)); - - /* Show the version of libpng used in building the application */ - fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER, - PNG_HEADER_VERSION_STRING); - - /* Do some consistency checking on the memory allocation settings, I'm - * not sure this matters, but it is nice to know, the first of these - * tests should be impossible because of the way the macros are set - * in pngconf.h - */ -#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) - fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n"); -#endif - /* I think the following can happen. */ -#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K) - fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n"); -#endif - - if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING)) - { - fprintf(STDERR, - "Warning: versions are different between png.h and png.c\n"); - fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING); - fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver); - ++ierror; - } - - if (argc > 1) - { - if (strcmp(argv[1], "-m") == 0) - { - multiple = 1; - status_dots_requested = 0; - } - - else if (strcmp(argv[1], "-mv") == 0 || - strcmp(argv[1], "-vm") == 0 ) - { - multiple = 1; - verbose = 1; - status_dots_requested = 1; - } - - else if (strcmp(argv[1], "-v") == 0) - { - verbose = 1; - status_dots_requested = 1; - inname = argv[2]; - } - - else if (strcmp(argv[1], "--strict") == 0) - { - status_dots_requested = 0; - verbose = 1; - inname = argv[2]; - strict++; - } - - else - { - inname = argv[1]; - status_dots_requested = 0; - } - } - - if (!multiple && argc == 3 + verbose) - outname = argv[2 + verbose]; - - if ((!multiple && argc > 3 + verbose) || (multiple && argc < 2)) - { - fprintf(STDERR, - "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n", - argv[0], argv[0]); - fprintf(STDERR, - " reads/writes one PNG file (without -m) or multiple files (-m)\n"); - fprintf(STDERR, - " with -m %s is used as a temporary file\n", outname); - exit(1); - } - - if (multiple) - { - int i; -#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG - int allocation_now = current_allocation; -#endif - for (i=2; isize, - (unsigned int)pinfo->pointer); - pinfo = pinfo->next; - } - } -#endif - } -#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG - fprintf(STDERR, " Current memory allocation: %10d bytes\n", - current_allocation); - fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", - maximum_allocation); - fprintf(STDERR, " Total memory allocation: %10d bytes\n", - total_allocation); - fprintf(STDERR, " Number of allocations: %10d\n", - num_allocations); -#endif - } - - else - { - int i; - for (i = 0; i<3; ++i) - { - int kerror; -#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG - int allocation_now = current_allocation; -#endif - if (i == 1) - status_dots_requested = 1; - - else if (verbose == 0) - status_dots_requested = 0; - - if (i == 0 || verbose == 1 || ierror != 0) - fprintf(STDERR, "\n Testing %s:", inname); - - kerror = test_one_file(inname, outname); - - if (kerror == 0) - { - if (verbose == 1 || i == 2) - { -#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED - int k; -#endif -#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED - fprintf(STDERR, "\n PASS (%lu zero samples)\n", - (unsigned long)zero_samples); -#else - fprintf(STDERR, " PASS\n"); -#endif -#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED - for (k = 0; k<256; k++) - if (filters_used[k]) - fprintf(STDERR, " Filter %d was used %lu times\n", - k, (unsigned long)filters_used[k]); -#endif -#ifdef PNG_TIME_RFC1123_SUPPORTED - if (tIME_chunk_present != 0) - fprintf(STDERR, " tIME = %s\n", tIME_string); -#endif /* PNG_TIME_RFC1123_SUPPORTED */ - } - } - - else - { - if (verbose == 0 && i != 2) - fprintf(STDERR, "\n Testing %s:", inname); - - fprintf(STDERR, " FAIL\n"); - ierror += kerror; - } -#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG - if (allocation_now != current_allocation) - fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", - current_allocation - allocation_now); - - if (current_allocation != 0) - { - memory_infop pinfo = pinformation; - - fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", - current_allocation); - - while (pinfo != NULL) - { - fprintf(STDERR, " %lu bytes at %x\n", - (unsigned long)pinfo->size, (unsigned int)pinfo->pointer); - pinfo = pinfo->next; - } - } -#endif - } -#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG - fprintf(STDERR, " Current memory allocation: %10d bytes\n", - current_allocation); - fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", - maximum_allocation); - fprintf(STDERR, " Total memory allocation: %10d bytes\n", - total_allocation); - fprintf(STDERR, " Number of allocations: %10d\n", - num_allocations); -#endif - } - -#ifdef PNGTEST_TIMING - t_stop = (float)clock(); - t_misc += (t_stop - t_start); - t_start = t_stop; - fprintf(STDERR, " CPU time used = %.3f seconds", - (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC); - fprintf(STDERR, " (decoding %.3f,\n", - t_decode/(float)CLOCKS_PER_SEC); - fprintf(STDERR, " encoding %.3f ,", - t_encode/(float)CLOCKS_PER_SEC); - fprintf(STDERR, " other %.3f seconds)\n\n", - t_misc/(float)CLOCKS_PER_SEC); -#endif - - if (ierror == 0) - fprintf(STDERR, " libpng passes test\n"); - - else - fprintf(STDERR, " libpng FAILS test\n"); - - return (int)(ierror != 0); -} - -/* Generate a compiler error if there is an old png.h in the search path. */ -typedef png_libpng_version_1_5_13 Your_png_h_is_not_version_1_5_13; + +/* pngtest.c - a simple test program to test libpng + * + * Last changed in libpng 1.5.6 [November 3, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This program reads in a PNG image, writes it out again, and then + * compares the two files. If the files are identical, this shows that + * the basic chunk handling, filtering, and (de)compression code is working + * properly. It does not currently test all of the transforms, although + * it probably should. + * + * The program will report "FAIL" in certain legitimate cases: + * 1) when the compression level or filter selection method is changed. + * 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192. + * 3) unknown unsafe-to-copy ancillary chunks or unknown critical chunks + * exist in the input file. + * 4) others not listed here... + * In these cases, it is best to check with another tool such as "pngcheck" + * to see what the differences between the two files are. + * + * If a filename is given on the command-line, then this file is used + * for the input, rather than the default "pngtest.png". This allows + * testing a wide variety of files easily. You can also test a number + * of files at once by typing "pngtest -m file1.png file2.png ..." + */ + +#define _POSIX_SOURCE 1 + +#include "zlib.h" +#include "png.h" +/* Copied from pngpriv.h but only used in error messages below. */ +#ifndef PNG_ZBUF_SIZE +# define PNG_ZBUF_SIZE 8192 +#endif +# include +# include +# include +# define FCLOSE(file) fclose(file) + +#ifndef PNG_STDIO_SUPPORTED +typedef FILE * png_FILE_p; +#endif + +/* Makes pngtest verbose so we can find problems. */ +#ifndef PNG_DEBUG +# define PNG_DEBUG 0 +#endif + +#if PNG_DEBUG > 1 +# define pngtest_debug(m) ((void)fprintf(stderr, m "\n")) +# define pngtest_debug1(m,p1) ((void)fprintf(stderr, m "\n", p1)) +# define pngtest_debug2(m,p1,p2) ((void)fprintf(stderr, m "\n", p1, p2)) +#else +# define pngtest_debug(m) ((void)0) +# define pngtest_debug1(m,p1) ((void)0) +# define pngtest_debug2(m,p1,p2) ((void)0) +#endif + +#if !PNG_DEBUG +# define SINGLE_ROWBUF_ALLOC /* Makes buffer overruns easier to nail */ +#endif + +/* The code uses memcmp and memcpy on large objects (typically row pointers) so + * it is necessary to do soemthing special on certain architectures, note that + * the actual support for this was effectively removed in 1.4, so only the + * memory remains in this program: + */ +#define CVT_PTR(ptr) (ptr) +#define CVT_PTR_NOCHECK(ptr) (ptr) +#define png_memcmp memcmp +#define png_memcpy memcpy +#define png_memset memset + +/* Turn on CPU timing +#define PNGTEST_TIMING +*/ + +#ifndef PNG_FLOATING_POINT_SUPPORTED +#undef PNGTEST_TIMING +#endif + +#ifdef PNGTEST_TIMING +static float t_start, t_stop, t_decode, t_encode, t_misc; +#include +#endif + +#ifdef PNG_TIME_RFC1123_SUPPORTED +#define PNG_tIME_STRING_LENGTH 29 +static int tIME_chunk_present = 0; +static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present"; +#endif + +static int verbose = 0; +static int strict = 0; + +int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname)); + +#ifdef __TURBOC__ +#include +#endif + +/* Defined so I can write to a file on gui/windowing platforms */ +/* #define STDERR stderr */ +#define STDERR stdout /* For DOS */ + +/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */ +#ifndef png_jmpbuf +# define png_jmpbuf(png_ptr) png_ptr->jmpbuf +#endif + +/* Example of using row callbacks to make a simple progress meter */ +static int status_pass = 1; +static int status_dots_requested = 0; +static int status_dots = 1; + +void PNGCBAPI +read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); +void PNGCBAPI +read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) +{ + if (png_ptr == NULL || row_number > PNG_UINT_31_MAX) + return; + + if (status_pass != pass) + { + fprintf(stdout, "\n Pass %d: ", pass); + status_pass = pass; + status_dots = 31; + } + + status_dots--; + + if (status_dots == 0) + { + fprintf(stdout, "\n "); + status_dots=30; + } + + fprintf(stdout, "r"); +} + +void PNGCBAPI +write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); +void PNGCBAPI +write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) +{ + if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7) + return; + + fprintf(stdout, "w"); +} + + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED +/* Example of using user transform callback (we don't transform anything, + * but merely examine the row filters. We set this to 256 rather than + * 5 in case illegal filter values are present.) + */ +static png_uint_32 filters_used[256]; +void PNGCBAPI +count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data); +void PNGCBAPI +count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data) +{ + if (png_ptr != NULL && row_info != NULL) + ++filters_used[*(data - 1)]; +} +#endif + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED +/* Example of using user transform callback (we don't transform anything, + * but merely count the zero samples) + */ + +static png_uint_32 zero_samples; + +void PNGCBAPI +count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data); +void PNGCBAPI +count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data) +{ + png_bytep dp = data; + if (png_ptr == NULL) + return; + + /* Contents of row_info: + * png_uint_32 width width of row + * png_uint_32 rowbytes number of bytes in row + * png_byte color_type color type of pixels + * png_byte bit_depth bit depth of samples + * png_byte channels number of channels (1-4) + * png_byte pixel_depth bits per pixel (depth*channels) + */ + + /* Counts the number of zero samples (or zero pixels if color_type is 3 */ + + if (row_info->color_type == 0 || row_info->color_type == 3) + { + int pos = 0; + png_uint_32 n, nstop; + + for (n = 0, nstop=row_info->width; nbit_depth == 1) + { + if (((*dp << pos++ ) & 0x80) == 0) + zero_samples++; + + if (pos == 8) + { + pos = 0; + dp++; + } + } + + if (row_info->bit_depth == 2) + { + if (((*dp << (pos+=2)) & 0xc0) == 0) + zero_samples++; + + if (pos == 8) + { + pos = 0; + dp++; + } + } + + if (row_info->bit_depth == 4) + { + if (((*dp << (pos+=4)) & 0xf0) == 0) + zero_samples++; + + if (pos == 8) + { + pos = 0; + dp++; + } + } + + if (row_info->bit_depth == 8) + if (*dp++ == 0) + zero_samples++; + + if (row_info->bit_depth == 16) + { + if ((*dp | *(dp+1)) == 0) + zero_samples++; + dp+=2; + } + } + } + else /* Other color types */ + { + png_uint_32 n, nstop; + int channel; + int color_channels = row_info->channels; + if (row_info->color_type > 3)color_channels--; + + for (n = 0, nstop=row_info->width; nbit_depth == 8) + if (*dp++ == 0) + zero_samples++; + + if (row_info->bit_depth == 16) + { + if ((*dp | *(dp+1)) == 0) + zero_samples++; + + dp+=2; + } + } + if (row_info->color_type > 3) + { + dp++; + if (row_info->bit_depth == 16) + dp++; + } + } + } +} +#endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */ + +static int wrote_question = 0; + +#ifndef PNG_STDIO_SUPPORTED +/* START of code to validate stdio-free compilation */ +/* These copies of the default read/write functions come from pngrio.c and + * pngwio.c. They allow "don't include stdio" testing of the library. + * This is the function that does the actual reading of data. If you are + * not reading from a standard C stream, you should create a replacement + * read_data function and use it at run time with png_set_read_fn(), rather + * than changing the library. + */ + +#ifdef PNG_IO_STATE_SUPPORTED +void +pngtest_check_io_state(png_structp png_ptr, png_size_t data_length, + png_uint_32 io_op); +void +pngtest_check_io_state(png_structp png_ptr, png_size_t data_length, + png_uint_32 io_op) +{ + png_uint_32 io_state = png_get_io_state(png_ptr); + int err = 0; + + /* Check if the current operation (reading / writing) is as expected. */ + if ((io_state & PNG_IO_MASK_OP) != io_op) + png_error(png_ptr, "Incorrect operation in I/O state"); + + /* Check if the buffer size specific to the current location + * (file signature / header / data / crc) is as expected. + */ + switch (io_state & PNG_IO_MASK_LOC) + { + case PNG_IO_SIGNATURE: + if (data_length > 8) + err = 1; + break; + case PNG_IO_CHUNK_HDR: + if (data_length != 8) + err = 1; + break; + case PNG_IO_CHUNK_DATA: + break; /* no restrictions here */ + case PNG_IO_CHUNK_CRC: + if (data_length != 4) + err = 1; + break; + default: + err = 1; /* uninitialized */ + } + if (err) + png_error(png_ptr, "Bad I/O state or buffer size"); +} +#endif + +#ifndef USE_FAR_KEYWORD +static void PNGCBAPI +pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_size_t check = 0; + png_voidp io_ptr; + + /* fread() returns 0 on error, so it is OK to store this in a png_size_t + * instead of an int, which is what fread() actually returns. + */ + io_ptr = png_get_io_ptr(png_ptr); + if (io_ptr != NULL) + { + check = fread(data, 1, length, (png_FILE_p)io_ptr); + } + + if (check != length) + { + png_error(png_ptr, "Read Error"); + } + +#ifdef PNG_IO_STATE_SUPPORTED + pngtest_check_io_state(png_ptr, length, PNG_IO_READING); +#endif +} +#else +/* This is the model-independent version. Since the standard I/O library + can't handle far buffers in the medium and small models, we have to copy + the data. +*/ + +#define NEAR_BUF_SIZE 1024 +#define MIN(a,b) (a <= b ? a : b) + +static void PNGCBAPI +pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_size_t check; + png_byte *n_data; + png_FILE_p io_ptr; + + /* Check if data really is near. If so, use usual code. */ + n_data = (png_byte *)CVT_PTR_NOCHECK(data); + io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr)); + if ((png_bytep)n_data == data) + { + check = fread(n_data, 1, length, io_ptr); + } + else + { + png_byte buf[NEAR_BUF_SIZE]; + png_size_t read, remaining, err; + check = 0; + remaining = length; + + do + { + read = MIN(NEAR_BUF_SIZE, remaining); + err = fread(buf, 1, 1, io_ptr); + png_memcpy(data, buf, read); /* Copy far buffer to near buffer */ + if (err != read) + break; + else + check += err; + data += read; + remaining -= read; + } + while (remaining != 0); + } + + if (check != length) + png_error(png_ptr, "Read Error"); + +#ifdef PNG_IO_STATE_SUPPORTED + pngtest_check_io_state(png_ptr, length, PNG_IO_READING); +#endif +} +#endif /* USE_FAR_KEYWORD */ + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +static void PNGCBAPI +pngtest_flush(png_structp png_ptr) +{ + /* Do nothing; fflush() is said to be just a waste of energy. */ + PNG_UNUSED(png_ptr) /* Stifle compiler warning */ +} +#endif + +/* This is the function that does the actual writing of data. If you are + * not writing to a standard C stream, you should create a replacement + * write_data function and use it at run time with png_set_write_fn(), rather + * than changing the library. + */ +#ifndef USE_FAR_KEYWORD +static void PNGCBAPI +pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_size_t check; + + check = fwrite(data, 1, length, (png_FILE_p)png_get_io_ptr(png_ptr)); + + if (check != length) + { + png_error(png_ptr, "Write Error"); + } + +#ifdef PNG_IO_STATE_SUPPORTED + pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING); +#endif +} +#else +/* This is the model-independent version. Since the standard I/O library + can't handle far buffers in the medium and small models, we have to copy + the data. +*/ + +#define NEAR_BUF_SIZE 1024 +#define MIN(a,b) (a <= b ? a : b) + +static void PNGCBAPI +pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_size_t check; + png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ + png_FILE_p io_ptr; + + /* Check if data really is near. If so, use usual code. */ + near_data = (png_byte *)CVT_PTR_NOCHECK(data); + io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr)); + + if ((png_bytep)near_data == data) + { + check = fwrite(near_data, 1, length, io_ptr); + } + + else + { + png_byte buf[NEAR_BUF_SIZE]; + png_size_t written, remaining, err; + check = 0; + remaining = length; + + do + { + written = MIN(NEAR_BUF_SIZE, remaining); + png_memcpy(buf, data, written); /* Copy far buffer to near buffer */ + err = fwrite(buf, 1, written, io_ptr); + if (err != written) + break; + else + check += err; + data += written; + remaining -= written; + } + while (remaining != 0); + } + + if (check != length) + { + png_error(png_ptr, "Write Error"); + } + +#ifdef PNG_IO_STATE_SUPPORTED + pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING); +#endif +} +#endif /* USE_FAR_KEYWORD */ + +/* This function is called when there is a warning, but the library thinks + * it can continue anyway. Replacement functions don't have to do anything + * here if you don't want to. In the default configuration, png_ptr is + * not used, but it is passed in case it may be useful. + */ +static void PNGCBAPI +pngtest_warning(png_structp png_ptr, png_const_charp message) +{ + PNG_CONST char *name = "UNKNOWN (ERROR!)"; + char *test; + test = png_get_error_ptr(png_ptr); + + if (test == NULL) + fprintf(STDERR, "%s: libpng warning: %s\n", name, message); + + else + fprintf(STDERR, "%s: libpng warning: %s\n", test, message); +} + +/* This is the default error handling function. Note that replacements for + * this function MUST NOT RETURN, or the program will likely crash. This + * function is used by default, or if the program supplies NULL for the + * error function pointer in png_set_error_fn(). + */ +static void PNGCBAPI +pngtest_error(png_structp png_ptr, png_const_charp message) +{ + pngtest_warning(png_ptr, message); + /* We can return because png_error calls the default handler, which is + * actually OK in this case. + */ +} +#endif /* !PNG_STDIO_SUPPORTED */ +/* END of code to validate stdio-free compilation */ + +/* START of code to validate memory allocation and deallocation */ +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + +/* Allocate memory. For reasonable files, size should never exceed + * 64K. However, zlib may allocate more then 64K if you don't tell + * it not to. See zconf.h and png.h for more information. zlib does + * need to allocate exactly 64K, so whatever you call here must + * have the ability to do that. + * + * This piece of code can be compiled to validate max 64K allocations + * by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. + */ +typedef struct memory_information +{ + png_alloc_size_t size; + png_voidp pointer; + struct memory_information FAR *next; +} memory_information; +typedef memory_information FAR *memory_infop; + +static memory_infop pinformation = NULL; +static int current_allocation = 0; +static int maximum_allocation = 0; +static int total_allocation = 0; +static int num_allocations = 0; + +png_voidp PNGCBAPI png_debug_malloc PNGARG((png_structp png_ptr, + png_alloc_size_t size)); +void PNGCBAPI png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr)); + +png_voidp +PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size) +{ + + /* png_malloc has already tested for NULL; png_create_struct calls + * png_debug_malloc directly, with png_ptr == NULL which is OK + */ + + if (size == 0) + return (NULL); + + /* This calls the library allocator twice, once to get the requested + buffer and once to get a new free list entry. */ + { + /* Disable malloc_fn and free_fn */ + memory_infop pinfo; + png_set_mem_fn(png_ptr, NULL, NULL, NULL); + pinfo = (memory_infop)png_malloc(png_ptr, + png_sizeof(*pinfo)); + pinfo->size = size; + current_allocation += size; + total_allocation += size; + num_allocations ++; + + if (current_allocation > maximum_allocation) + maximum_allocation = current_allocation; + + pinfo->pointer = png_malloc(png_ptr, size); + /* Restore malloc_fn and free_fn */ + + png_set_mem_fn(png_ptr, + NULL, png_debug_malloc, png_debug_free); + + if (size != 0 && pinfo->pointer == NULL) + { + current_allocation -= size; + total_allocation -= size; + png_error(png_ptr, + "out of memory in pngtest->png_debug_malloc"); + } + + pinfo->next = pinformation; + pinformation = pinfo; + /* Make sure the caller isn't assuming zeroed memory. */ + png_memset(pinfo->pointer, 0xdd, pinfo->size); + + if (verbose) + printf("png_malloc %lu bytes at %p\n", (unsigned long)size, + pinfo->pointer); + + return (png_voidp)(pinfo->pointer); + } +} + +/* Free a pointer. It is removed from the list at the same time. */ +void PNGCBAPI +png_debug_free(png_structp png_ptr, png_voidp ptr) +{ + if (png_ptr == NULL) + fprintf(STDERR, "NULL pointer to png_debug_free.\n"); + + if (ptr == 0) + { +#if 0 /* This happens all the time. */ + fprintf(STDERR, "WARNING: freeing NULL pointer\n"); +#endif + return; + } + + /* Unlink the element from the list. */ + { + memory_infop FAR *ppinfo = &pinformation; + + for (;;) + { + memory_infop pinfo = *ppinfo; + + if (pinfo->pointer == ptr) + { + *ppinfo = pinfo->next; + current_allocation -= pinfo->size; + if (current_allocation < 0) + fprintf(STDERR, "Duplicate free of memory\n"); + /* We must free the list element too, but first kill + the memory that is to be freed. */ + png_memset(ptr, 0x55, pinfo->size); + png_free_default(png_ptr, pinfo); + pinfo = NULL; + break; + } + + if (pinfo->next == NULL) + { + fprintf(STDERR, "Pointer %x not found\n", (unsigned int)ptr); + break; + } + + ppinfo = &pinfo->next; + } + } + + /* Finally free the data. */ + if (verbose) + printf("Freeing %p\n", ptr); + + png_free_default(png_ptr, ptr); + ptr = NULL; +} +#endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */ +/* END of code to test memory allocation/deallocation */ + + +/* Demonstration of user chunk support of the sTER and vpAg chunks */ +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED + +/* (sTER is a public chunk not yet known by libpng. vpAg is a private +chunk used in ImageMagick to store "virtual page" size). */ + +static png_uint_32 user_chunk_data[4]; + + /* 0: sTER mode + 1 + * 1: vpAg width + * 2: vpAg height + * 3: vpAg units + */ + +static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr, + png_unknown_chunkp chunk) +{ + png_uint_32 + *my_user_chunk_data; + + /* Return one of the following: + * return (-n); chunk had an error + * return (0); did not recognize + * return (n); success + * + * The unknown chunk structure contains the chunk data: + * png_byte name[5]; + * png_byte *data; + * png_size_t size; + * + * Note that libpng has already taken care of the CRC handling. + */ + + if (chunk->name[0] == 115 && chunk->name[1] == 84 && /* s T */ + chunk->name[2] == 69 && chunk->name[3] == 82) /* E R */ + { + /* Found sTER chunk */ + if (chunk->size != 1) + return (-1); /* Error return */ + + if (chunk->data[0] != 0 && chunk->data[0] != 1) + return (-1); /* Invalid mode */ + + my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr); + my_user_chunk_data[0]=chunk->data[0]+1; + return (1); + } + + if (chunk->name[0] != 118 || chunk->name[1] != 112 || /* v p */ + chunk->name[2] != 65 || chunk->name[3] != 103) /* A g */ + return (0); /* Did not recognize */ + + /* Found ImageMagick vpAg chunk */ + + if (chunk->size != 9) + return (-1); /* Error return */ + + my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr); + + my_user_chunk_data[1]=png_get_uint_31(png_ptr, chunk->data); + my_user_chunk_data[2]=png_get_uint_31(png_ptr, chunk->data + 4); + my_user_chunk_data[3]=(png_uint_32)chunk->data[8]; + + return (1); + +} +#endif +/* END of code to demonstrate user chunk support */ + +/* Test one file */ +int +test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) +{ + static png_FILE_p fpin; + static png_FILE_p fpout; /* "static" prevents setjmp corruption */ + png_structp read_ptr; + png_infop read_info_ptr, end_info_ptr; +#ifdef PNG_WRITE_SUPPORTED + png_structp write_ptr; + png_infop write_info_ptr; + png_infop write_end_info_ptr; +#else + png_structp write_ptr = NULL; + png_infop write_info_ptr = NULL; + png_infop write_end_info_ptr = NULL; +#endif + png_bytep row_buf; + png_uint_32 y; + png_uint_32 width, height; + int num_pass, pass; + int bit_depth, color_type; +#ifdef PNG_SETJMP_SUPPORTED +#ifdef USE_FAR_KEYWORD + jmp_buf tmp_jmpbuf; +#endif +#endif + + char inbuf[256], outbuf[256]; + + row_buf = NULL; + + if ((fpin = fopen(inname, "rb")) == NULL) + { + fprintf(STDERR, "Could not find input file %s\n", inname); + return (1); + } + + if ((fpout = fopen(outname, "wb")) == NULL) + { + fprintf(STDERR, "Could not open output file %s\n", outname); + FCLOSE(fpin); + return (1); + } + + pngtest_debug("Allocating read and write structures"); +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + read_ptr = + png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL, + NULL, NULL, NULL, png_debug_malloc, png_debug_free); +#else + read_ptr = + png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); +#endif +#ifndef PNG_STDIO_SUPPORTED + png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error, + pngtest_warning); +#endif + +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED + user_chunk_data[0] = 0; + user_chunk_data[1] = 0; + user_chunk_data[2] = 0; + user_chunk_data[3] = 0; + png_set_read_user_chunk_fn(read_ptr, user_chunk_data, + read_user_chunk_callback); + +#endif +#ifdef PNG_WRITE_SUPPORTED +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + write_ptr = + png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL, + NULL, NULL, NULL, png_debug_malloc, png_debug_free); +#else + write_ptr = + png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); +#endif +#ifndef PNG_STDIO_SUPPORTED + png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error, + pngtest_warning); +#endif +#endif + pngtest_debug("Allocating read_info, write_info and end_info structures"); + read_info_ptr = png_create_info_struct(read_ptr); + end_info_ptr = png_create_info_struct(read_ptr); +#ifdef PNG_WRITE_SUPPORTED + write_info_ptr = png_create_info_struct(write_ptr); + write_end_info_ptr = png_create_info_struct(write_ptr); +#endif + +#ifdef PNG_SETJMP_SUPPORTED + pngtest_debug("Setting jmpbuf for read struct"); +#ifdef USE_FAR_KEYWORD + if (setjmp(tmp_jmpbuf)) +#else + if (setjmp(png_jmpbuf(read_ptr))) +#endif + { + fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname); + png_free(read_ptr, row_buf); + row_buf = NULL; + png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); +#ifdef PNG_WRITE_SUPPORTED + png_destroy_info_struct(write_ptr, &write_end_info_ptr); + png_destroy_write_struct(&write_ptr, &write_info_ptr); +#endif + FCLOSE(fpin); + FCLOSE(fpout); + return (1); + } +#ifdef USE_FAR_KEYWORD + png_memcpy(png_jmpbuf(read_ptr), tmp_jmpbuf, png_sizeof(jmp_buf)); +#endif + +#ifdef PNG_WRITE_SUPPORTED + pngtest_debug("Setting jmpbuf for write struct"); +#ifdef USE_FAR_KEYWORD + + if (setjmp(tmp_jmpbuf)) +#else + if (setjmp(png_jmpbuf(write_ptr))) +#endif + { + fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname); + png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); + png_destroy_info_struct(write_ptr, &write_end_info_ptr); +#ifdef PNG_WRITE_SUPPORTED + png_destroy_write_struct(&write_ptr, &write_info_ptr); +#endif + FCLOSE(fpin); + FCLOSE(fpout); + return (1); + } + +#ifdef USE_FAR_KEYWORD + png_memcpy(png_jmpbuf(write_ptr), tmp_jmpbuf, png_sizeof(jmp_buf)); +#endif +#endif +#endif + + pngtest_debug("Initializing input and output streams"); +#ifdef PNG_STDIO_SUPPORTED + png_init_io(read_ptr, fpin); +# ifdef PNG_WRITE_SUPPORTED + png_init_io(write_ptr, fpout); +# endif +#else + png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data); +# ifdef PNG_WRITE_SUPPORTED + png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data, +# ifdef PNG_WRITE_FLUSH_SUPPORTED + pngtest_flush); +# else + NULL); +# endif +# endif +#endif + +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED + /* Normally one would use Z_DEFAULT_STRATEGY for text compression. + * This is here just to make pngtest replicate the results from libpng + * versions prior to 1.5.4, and to test this new API. + */ + png_set_text_compression_strategy(write_ptr, Z_FILTERED); +#endif + + if (status_dots_requested == 1) + { +#ifdef PNG_WRITE_SUPPORTED + png_set_write_status_fn(write_ptr, write_row_callback); +#endif + png_set_read_status_fn(read_ptr, read_row_callback); + } + + else + { +#ifdef PNG_WRITE_SUPPORTED + png_set_write_status_fn(write_ptr, NULL); +#endif + png_set_read_status_fn(read_ptr, NULL); + } + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + { + int i; + + for (i = 0; i<256; i++) + filters_used[i] = 0; + + png_set_read_user_transform_fn(read_ptr, count_filters); + } +#endif +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED + zero_samples = 0; + png_set_write_user_transform_fn(write_ptr, count_zero_samples); +#endif + +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED +# ifndef PNG_HANDLE_CHUNK_ALWAYS +# define PNG_HANDLE_CHUNK_ALWAYS 3 +# endif + png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS, + NULL, 0); +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED +# ifndef PNG_HANDLE_CHUNK_IF_SAFE +# define PNG_HANDLE_CHUNK_IF_SAFE 2 +# endif + png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE, + NULL, 0); +#endif + + pngtest_debug("Reading info struct"); + png_read_info(read_ptr, read_info_ptr); + + pngtest_debug("Transferring info struct"); + { + int interlace_type, compression_type, filter_type; + + if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth, + &color_type, &interlace_type, &compression_type, &filter_type)) + { + png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth, +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + color_type, interlace_type, compression_type, filter_type); +#else + color_type, PNG_INTERLACE_NONE, compression_type, filter_type); +#endif + } + } +#ifdef PNG_FIXED_POINT_SUPPORTED +#ifdef PNG_cHRM_SUPPORTED + { + png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x, + blue_y; + + if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y, + &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y)) + { + png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x, + red_y, green_x, green_y, blue_x, blue_y); + } + } +#endif +#ifdef PNG_gAMA_SUPPORTED + { + png_fixed_point gamma; + + if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma)) + png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma); + } +#endif +#else /* Use floating point versions */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +#ifdef PNG_cHRM_SUPPORTED + { + double white_x, white_y, red_x, red_y, green_x, green_y, blue_x, + blue_y; + + if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x, + &red_y, &green_x, &green_y, &blue_x, &blue_y)) + { + png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x, + red_y, green_x, green_y, blue_x, blue_y); + } + } +#endif +#ifdef PNG_gAMA_SUPPORTED + { + double gamma; + + if (png_get_gAMA(read_ptr, read_info_ptr, &gamma)) + png_set_gAMA(write_ptr, write_info_ptr, gamma); + } +#endif +#endif /* Floating point */ +#endif /* Fixed point */ +#ifdef PNG_iCCP_SUPPORTED + { + png_charp name; + png_bytep profile; + png_uint_32 proflen; + int compression_type; + + if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type, + &profile, &proflen)) + { + png_set_iCCP(write_ptr, write_info_ptr, name, compression_type, + profile, proflen); + } + } +#endif +#ifdef PNG_sRGB_SUPPORTED + { + int intent; + + if (png_get_sRGB(read_ptr, read_info_ptr, &intent)) + png_set_sRGB(write_ptr, write_info_ptr, intent); + } +#endif + { + png_colorp palette; + int num_palette; + + if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette)) + png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); + } +#ifdef PNG_bKGD_SUPPORTED + { + png_color_16p background; + + if (png_get_bKGD(read_ptr, read_info_ptr, &background)) + { + png_set_bKGD(write_ptr, write_info_ptr, background); + } + } +#endif +#ifdef PNG_hIST_SUPPORTED + { + png_uint_16p hist; + + if (png_get_hIST(read_ptr, read_info_ptr, &hist)) + png_set_hIST(write_ptr, write_info_ptr, hist); + } +#endif +#ifdef PNG_oFFs_SUPPORTED + { + png_int_32 offset_x, offset_y; + int unit_type; + + if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y, + &unit_type)) + { + png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type); + } + } +#endif +#ifdef PNG_pCAL_SUPPORTED + { + png_charp purpose, units; + png_charpp params; + png_int_32 X0, X1; + int type, nparams; + + if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type, + &nparams, &units, ¶ms)) + { + png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type, + nparams, units, params); + } + } +#endif +#ifdef PNG_pHYs_SUPPORTED + { + png_uint_32 res_x, res_y; + int unit_type; + + if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type)) + png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type); + } +#endif +#ifdef PNG_sBIT_SUPPORTED + { + png_color_8p sig_bit; + + if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit)) + png_set_sBIT(write_ptr, write_info_ptr, sig_bit); + } +#endif +#ifdef PNG_sCAL_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED + { + int unit; + double scal_width, scal_height; + + if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width, + &scal_height)) + { + png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height); + } + } +#else +#ifdef PNG_FIXED_POINT_SUPPORTED + { + int unit; + png_charp scal_width, scal_height; + + if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width, + &scal_height)) + { + png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width, + scal_height); + } + } +#endif +#endif +#endif +#ifdef PNG_TEXT_SUPPORTED + { + png_textp text_ptr; + int num_text; + + if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0) + { + pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text); + + if (verbose) + printf("\n Text compression=%d\n", text_ptr->compression); + + png_set_text(write_ptr, write_info_ptr, text_ptr, num_text); + } + } +#endif +#ifdef PNG_tIME_SUPPORTED + { + png_timep mod_time; + + if (png_get_tIME(read_ptr, read_info_ptr, &mod_time)) + { + png_set_tIME(write_ptr, write_info_ptr, mod_time); +#ifdef PNG_TIME_RFC1123_SUPPORTED + /* We have to use png_memcpy instead of "=" because the string + * pointed to by png_convert_to_rfc1123() gets free'ed before + * we use it. + */ + png_memcpy(tIME_string, + png_convert_to_rfc1123(read_ptr, mod_time), + png_sizeof(tIME_string)); + + tIME_string[png_sizeof(tIME_string) - 1] = '\0'; + tIME_chunk_present++; +#endif /* PNG_TIME_RFC1123_SUPPORTED */ + } + } +#endif +#ifdef PNG_tRNS_SUPPORTED + { + png_bytep trans_alpha; + int num_trans; + png_color_16p trans_color; + + if (png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans, + &trans_color)) + { + int sample_max = (1 << bit_depth); + /* libpng doesn't reject a tRNS chunk with out-of-range samples */ + if (!((color_type == PNG_COLOR_TYPE_GRAY && + (int)trans_color->gray > sample_max) || + (color_type == PNG_COLOR_TYPE_RGB && + ((int)trans_color->red > sample_max || + (int)trans_color->green > sample_max || + (int)trans_color->blue > sample_max)))) + png_set_tRNS(write_ptr, write_info_ptr, trans_alpha, num_trans, + trans_color); + } + } +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + { + png_unknown_chunkp unknowns; + int num_unknowns = png_get_unknown_chunks(read_ptr, read_info_ptr, + &unknowns); + + if (num_unknowns) + { + int i; + png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns, + num_unknowns); + /* Copy the locations from the read_info_ptr. The automatically + * generated locations in write_info_ptr are wrong because we + * haven't written anything yet. + */ + for (i = 0; i < num_unknowns; i++) + png_set_unknown_chunk_location(write_ptr, write_info_ptr, i, + unknowns[i].location); + } + } +#endif + +#ifdef PNG_WRITE_SUPPORTED + pngtest_debug("Writing info struct"); + +/* If we wanted, we could write info in two steps: + * png_write_info_before_PLTE(write_ptr, write_info_ptr); + */ + png_write_info(write_ptr, write_info_ptr); + +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED + if (user_chunk_data[0] != 0) + { + png_byte png_sTER[5] = {115, 84, 69, 82, '\0'}; + + unsigned char + ster_chunk_data[1]; + + if (verbose) + fprintf(STDERR, "\n stereo mode = %lu\n", + (unsigned long)(user_chunk_data[0] - 1)); + + ster_chunk_data[0]=(unsigned char)(user_chunk_data[0] - 1); + png_write_chunk(write_ptr, png_sTER, ster_chunk_data, 1); + } + + if (user_chunk_data[1] != 0 || user_chunk_data[2] != 0) + { + png_byte png_vpAg[5] = {118, 112, 65, 103, '\0'}; + + unsigned char + vpag_chunk_data[9]; + + if (verbose) + fprintf(STDERR, " vpAg = %lu x %lu, units = %lu\n", + (unsigned long)user_chunk_data[1], + (unsigned long)user_chunk_data[2], + (unsigned long)user_chunk_data[3]); + + png_save_uint_32(vpag_chunk_data, user_chunk_data[1]); + png_save_uint_32(vpag_chunk_data + 4, user_chunk_data[2]); + vpag_chunk_data[8] = (unsigned char)(user_chunk_data[3] & 0xff); + png_write_chunk(write_ptr, png_vpAg, vpag_chunk_data, 9); + } + +#endif +#endif + +#ifdef SINGLE_ROWBUF_ALLOC + pngtest_debug("Allocating row buffer..."); + row_buf = (png_bytep)png_malloc(read_ptr, + png_get_rowbytes(read_ptr, read_info_ptr)); + + pngtest_debug1("\t0x%08lx", (unsigned long)row_buf); +#endif /* SINGLE_ROWBUF_ALLOC */ + pngtest_debug("Writing row data"); + +#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ + defined(PNG_WRITE_INTERLACING_SUPPORTED) + num_pass = png_set_interlace_handling(read_ptr); +# ifdef PNG_WRITE_SUPPORTED + png_set_interlace_handling(write_ptr); +# endif +#else + num_pass = 1; +#endif + +#ifdef PNGTEST_TIMING + t_stop = (float)clock(); + t_misc += (t_stop - t_start); + t_start = t_stop; +#endif + for (pass = 0; pass < num_pass; pass++) + { + pngtest_debug1("Writing row data for pass %d", pass); + for (y = 0; y < height; y++) + { +#ifndef SINGLE_ROWBUF_ALLOC + pngtest_debug2("Allocating row buffer (pass %d, y = %u)...", pass, y); + row_buf = (png_bytep)png_malloc(read_ptr, + png_get_rowbytes(read_ptr, read_info_ptr)); + + pngtest_debug2("\t0x%08lx (%u bytes)", (unsigned long)row_buf, + png_get_rowbytes(read_ptr, read_info_ptr)); + +#endif /* !SINGLE_ROWBUF_ALLOC */ + png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1); + +#ifdef PNG_WRITE_SUPPORTED +#ifdef PNGTEST_TIMING + t_stop = (float)clock(); + t_decode += (t_stop - t_start); + t_start = t_stop; +#endif + png_write_rows(write_ptr, (png_bytepp)&row_buf, 1); +#ifdef PNGTEST_TIMING + t_stop = (float)clock(); + t_encode += (t_stop - t_start); + t_start = t_stop; +#endif +#endif /* PNG_WRITE_SUPPORTED */ + +#ifndef SINGLE_ROWBUF_ALLOC + pngtest_debug2("Freeing row buffer (pass %d, y = %u)", pass, y); + png_free(read_ptr, row_buf); + row_buf = NULL; +#endif /* !SINGLE_ROWBUF_ALLOC */ + } + } + +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED + png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1); +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1); +#endif + + pngtest_debug("Reading and writing end_info data"); + + png_read_end(read_ptr, end_info_ptr); +#ifdef PNG_TEXT_SUPPORTED + { + png_textp text_ptr; + int num_text; + + if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0) + { + pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text); + png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text); + } + } +#endif +#ifdef PNG_tIME_SUPPORTED + { + png_timep mod_time; + + if (png_get_tIME(read_ptr, end_info_ptr, &mod_time)) + { + png_set_tIME(write_ptr, write_end_info_ptr, mod_time); +#ifdef PNG_TIME_RFC1123_SUPPORTED + /* We have to use png_memcpy instead of "=" because the string + pointed to by png_convert_to_rfc1123() gets free'ed before + we use it */ + png_memcpy(tIME_string, + png_convert_to_rfc1123(read_ptr, mod_time), + png_sizeof(tIME_string)); + + tIME_string[png_sizeof(tIME_string) - 1] = '\0'; + tIME_chunk_present++; +#endif /* PNG_TIME_RFC1123_SUPPORTED */ + } + } +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + { + png_unknown_chunkp unknowns; + int num_unknowns = png_get_unknown_chunks(read_ptr, end_info_ptr, + &unknowns); + + if (num_unknowns) + { + int i; + png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns, + num_unknowns); + /* Copy the locations from the read_info_ptr. The automatically + * generated locations in write_end_info_ptr are wrong because we + * haven't written the end_info yet. + */ + for (i = 0; i < num_unknowns; i++) + png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i, + unknowns[i].location); + } + } +#endif +#ifdef PNG_WRITE_SUPPORTED + png_write_end(write_ptr, write_end_info_ptr); +#endif + +#ifdef PNG_EASY_ACCESS_SUPPORTED + if (verbose) + { + png_uint_32 iwidth, iheight; + iwidth = png_get_image_width(write_ptr, write_info_ptr); + iheight = png_get_image_height(write_ptr, write_info_ptr); + fprintf(STDERR, "\n Image width = %lu, height = %lu\n", + (unsigned long)iwidth, (unsigned long)iheight); + } +#endif + + pngtest_debug("Destroying data structs"); +#ifdef SINGLE_ROWBUF_ALLOC + pngtest_debug("destroying row_buf for read_ptr"); + png_free(read_ptr, row_buf); + row_buf = NULL; +#endif /* SINGLE_ROWBUF_ALLOC */ + pngtest_debug("destroying read_ptr, read_info_ptr, end_info_ptr"); + png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); +#ifdef PNG_WRITE_SUPPORTED + pngtest_debug("destroying write_end_info_ptr"); + png_destroy_info_struct(write_ptr, &write_end_info_ptr); + pngtest_debug("destroying write_ptr, write_info_ptr"); + png_destroy_write_struct(&write_ptr, &write_info_ptr); +#endif + pngtest_debug("Destruction complete."); + + FCLOSE(fpin); + FCLOSE(fpout); + + pngtest_debug("Opening files for comparison"); + if ((fpin = fopen(inname, "rb")) == NULL) + { + fprintf(STDERR, "Could not find file %s\n", inname); + return (1); + } + + if ((fpout = fopen(outname, "rb")) == NULL) + { + fprintf(STDERR, "Could not find file %s\n", outname); + FCLOSE(fpin); + return (1); + } + + for (;;) + { + png_size_t num_in, num_out; + + num_in = fread(inbuf, 1, 1, fpin); + num_out = fread(outbuf, 1, 1, fpout); + + if (num_in != num_out) + { + fprintf(STDERR, "\nFiles %s and %s are of a different size\n", + inname, outname); + + if (wrote_question == 0) + { + fprintf(STDERR, + " Was %s written with the same maximum IDAT chunk size (%d bytes),", + inname, PNG_ZBUF_SIZE); + fprintf(STDERR, + "\n filtering heuristic (libpng default), compression"); + fprintf(STDERR, + " level (zlib default),\n and zlib version (%s)?\n\n", + ZLIB_VERSION); + wrote_question = 1; + } + + FCLOSE(fpin); + FCLOSE(fpout); + + if (strict != 0) + return (1); + + else + return (0); + } + + if (!num_in) + break; + + if (png_memcmp(inbuf, outbuf, num_in)) + { + fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname); + + if (wrote_question == 0) + { + fprintf(STDERR, + " Was %s written with the same maximum IDAT chunk size (%d bytes),", + inname, PNG_ZBUF_SIZE); + fprintf(STDERR, + "\n filtering heuristic (libpng default), compression"); + fprintf(STDERR, + " level (zlib default),\n and zlib version (%s)?\n\n", + ZLIB_VERSION); + wrote_question = 1; + } + + FCLOSE(fpin); + FCLOSE(fpout); + + if (strict != 0) + return (1); + + else + return (0); + } + } + + FCLOSE(fpin); + FCLOSE(fpout); + + return (0); +} + +/* Input and output filenames */ +#ifdef RISCOS +static PNG_CONST char *inname = "pngtest/png"; +static PNG_CONST char *outname = "pngout/png"; +#else +static PNG_CONST char *inname = "pngtest.png"; +static PNG_CONST char *outname = "pngout.png"; +#endif + +int +main(int argc, char *argv[]) +{ + int multiple = 0; + int ierror = 0; + + fprintf(STDERR, "\n Testing libpng version %s\n", PNG_LIBPNG_VER_STRING); + fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION); + fprintf(STDERR, "%s", png_get_copyright(NULL)); + /* Show the version of libpng used in building the library */ + fprintf(STDERR, " library (%lu):%s", + (unsigned long)png_access_version_number(), + png_get_header_version(NULL)); + + /* Show the version of libpng used in building the application */ + fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER, + PNG_HEADER_VERSION_STRING); + + /* Do some consistency checking on the memory allocation settings, I'm + * not sure this matters, but it is nice to know, the first of these + * tests should be impossible because of the way the macros are set + * in pngconf.h + */ +#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) + fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n"); +#endif + /* I think the following can happen. */ +#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K) + fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n"); +#endif + + if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING)) + { + fprintf(STDERR, + "Warning: versions are different between png.h and png.c\n"); + fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING); + fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver); + ++ierror; + } + + if (argc > 1) + { + if (strcmp(argv[1], "-m") == 0) + { + multiple = 1; + status_dots_requested = 0; + } + + else if (strcmp(argv[1], "-mv") == 0 || + strcmp(argv[1], "-vm") == 0 ) + { + multiple = 1; + verbose = 1; + status_dots_requested = 1; + } + + else if (strcmp(argv[1], "-v") == 0) + { + verbose = 1; + status_dots_requested = 1; + inname = argv[2]; + } + + else if (strcmp(argv[1], "--strict") == 0) + { + status_dots_requested = 0; + verbose = 1; + inname = argv[2]; + strict++; + } + + else + { + inname = argv[1]; + status_dots_requested = 0; + } + } + + if (!multiple && argc == 3 + verbose) + outname = argv[2 + verbose]; + + if ((!multiple && argc > 3 + verbose) || (multiple && argc < 2)) + { + fprintf(STDERR, + "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n", + argv[0], argv[0]); + fprintf(STDERR, + " reads/writes one PNG file (without -m) or multiple files (-m)\n"); + fprintf(STDERR, + " with -m %s is used as a temporary file\n", outname); + exit(1); + } + + if (multiple) + { + int i; +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + int allocation_now = current_allocation; +#endif + for (i=2; isize, + (unsigned int)pinfo->pointer); + pinfo = pinfo->next; + } + } +#endif + } +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + fprintf(STDERR, " Current memory allocation: %10d bytes\n", + current_allocation); + fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", + maximum_allocation); + fprintf(STDERR, " Total memory allocation: %10d bytes\n", + total_allocation); + fprintf(STDERR, " Number of allocations: %10d\n", + num_allocations); +#endif + } + + else + { + int i; + for (i = 0; i<3; ++i) + { + int kerror; +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + int allocation_now = current_allocation; +#endif + if (i == 1) + status_dots_requested = 1; + + else if (verbose == 0) + status_dots_requested = 0; + + if (i == 0 || verbose == 1 || ierror != 0) + fprintf(STDERR, "\n Testing %s:", inname); + + kerror = test_one_file(inname, outname); + + if (kerror == 0) + { + if (verbose == 1 || i == 2) + { +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + int k; +#endif +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED + fprintf(STDERR, "\n PASS (%lu zero samples)\n", + (unsigned long)zero_samples); +#else + fprintf(STDERR, " PASS\n"); +#endif +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + for (k = 0; k<256; k++) + if (filters_used[k]) + fprintf(STDERR, " Filter %d was used %lu times\n", + k, (unsigned long)filters_used[k]); +#endif +#ifdef PNG_TIME_RFC1123_SUPPORTED + if (tIME_chunk_present != 0) + fprintf(STDERR, " tIME = %s\n", tIME_string); +#endif /* PNG_TIME_RFC1123_SUPPORTED */ + } + } + + else + { + if (verbose == 0 && i != 2) + fprintf(STDERR, "\n Testing %s:", inname); + + fprintf(STDERR, " FAIL\n"); + ierror += kerror; + } +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + if (allocation_now != current_allocation) + fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", + current_allocation - allocation_now); + + if (current_allocation != 0) + { + memory_infop pinfo = pinformation; + + fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", + current_allocation); + + while (pinfo != NULL) + { + fprintf(STDERR, " %lu bytes at %x\n", + (unsigned long)pinfo->size, (unsigned int)pinfo->pointer); + pinfo = pinfo->next; + } + } +#endif + } +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + fprintf(STDERR, " Current memory allocation: %10d bytes\n", + current_allocation); + fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", + maximum_allocation); + fprintf(STDERR, " Total memory allocation: %10d bytes\n", + total_allocation); + fprintf(STDERR, " Number of allocations: %10d\n", + num_allocations); +#endif + } + +#ifdef PNGTEST_TIMING + t_stop = (float)clock(); + t_misc += (t_stop - t_start); + t_start = t_stop; + fprintf(STDERR, " CPU time used = %.3f seconds", + (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC); + fprintf(STDERR, " (decoding %.3f,\n", + t_decode/(float)CLOCKS_PER_SEC); + fprintf(STDERR, " encoding %.3f ,", + t_encode/(float)CLOCKS_PER_SEC); + fprintf(STDERR, " other %.3f seconds)\n\n", + t_misc/(float)CLOCKS_PER_SEC); +#endif + + if (ierror == 0) + fprintf(STDERR, " libpng passes test\n"); + + else + fprintf(STDERR, " libpng FAILS test\n"); + + return (int)(ierror != 0); +} + +/* Generate a compiler error if there is an old png.h in the search path. */ +typedef png_libpng_version_1_5_13 Your_png_h_is_not_version_1_5_13; diff --git a/Source/LibPNG/pngtrans.c b/Source/LibPNG/pngtrans.c index d562eb0..ee60957 100644 --- a/Source/LibPNG/pngtrans.c +++ b/Source/LibPNG/pngtrans.c @@ -1,781 +1,781 @@ - -/* pngtrans.c - transforms the data in a row (used by both readers and writers) - * - * Last changed in libpng 1.5.11 [June 14, 2012] - * Copyright (c) 1998-2012 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - */ - -#include "pngpriv.h" - -#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) - -#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) -/* Turn on BGR-to-RGB mapping */ -void PNGAPI -png_set_bgr(png_structp png_ptr) -{ - png_debug(1, "in png_set_bgr"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= PNG_BGR; -} -#endif - -#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) -/* Turn on 16 bit byte swapping */ -void PNGAPI -png_set_swap(png_structp png_ptr) -{ - png_debug(1, "in png_set_swap"); - - if (png_ptr == NULL) - return; - - if (png_ptr->bit_depth == 16) - png_ptr->transformations |= PNG_SWAP_BYTES; -} -#endif - -#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) -/* Turn on pixel packing */ -void PNGAPI -png_set_packing(png_structp png_ptr) -{ - png_debug(1, "in png_set_packing"); - - if (png_ptr == NULL) - return; - - if (png_ptr->bit_depth < 8) - { - png_ptr->transformations |= PNG_PACK; - png_ptr->usr_bit_depth = 8; - } -} -#endif - -#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) -/* Turn on packed pixel swapping */ -void PNGAPI -png_set_packswap(png_structp png_ptr) -{ - png_debug(1, "in png_set_packswap"); - - if (png_ptr == NULL) - return; - - if (png_ptr->bit_depth < 8) - png_ptr->transformations |= PNG_PACKSWAP; -} -#endif - -#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) -void PNGAPI -png_set_shift(png_structp png_ptr, png_const_color_8p true_bits) -{ - png_debug(1, "in png_set_shift"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= PNG_SHIFT; - png_ptr->shift = *true_bits; -} -#endif - -#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ - defined(PNG_WRITE_INTERLACING_SUPPORTED) -int PNGAPI -png_set_interlace_handling(png_structp png_ptr) -{ - png_debug(1, "in png_set_interlace handling"); - - if (png_ptr && png_ptr->interlaced) - { - png_ptr->transformations |= PNG_INTERLACE; - return (7); - } - - return (1); -} -#endif - -#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) -/* Add a filler byte on read, or remove a filler or alpha byte on write. - * The filler type has changed in v0.95 to allow future 2-byte fillers - * for 48-bit input data, as well as to avoid problems with some compilers - * that don't like bytes as parameters. - */ -void PNGAPI -png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc) -{ - png_debug(1, "in png_set_filler"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= PNG_FILLER; - png_ptr->filler = (png_uint_16)filler; - - if (filler_loc == PNG_FILLER_AFTER) - png_ptr->flags |= PNG_FLAG_FILLER_AFTER; - - else - png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER; - - /* This should probably go in the "do_read_filler" routine. - * I attempted to do that in libpng-1.0.1a but that caused problems - * so I restored it in libpng-1.0.2a - */ - - if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) - { - png_ptr->usr_channels = 4; - } - - /* Also I added this in libpng-1.0.2a (what happens when we expand - * a less-than-8-bit grayscale to GA?) */ - - if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8) - { - png_ptr->usr_channels = 2; - } -} - -/* Added to libpng-1.2.7 */ -void PNGAPI -png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) -{ - png_debug(1, "in png_set_add_alpha"); - - if (png_ptr == NULL) - return; - - png_set_filler(png_ptr, filler, filler_loc); - png_ptr->transformations |= PNG_ADD_ALPHA; -} - -#endif - -#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ - defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) -void PNGAPI -png_set_swap_alpha(png_structp png_ptr) -{ - png_debug(1, "in png_set_swap_alpha"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= PNG_SWAP_ALPHA; -} -#endif - -#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ - defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) -void PNGAPI -png_set_invert_alpha(png_structp png_ptr) -{ - png_debug(1, "in png_set_invert_alpha"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= PNG_INVERT_ALPHA; -} -#endif - -#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) -void PNGAPI -png_set_invert_mono(png_structp png_ptr) -{ - png_debug(1, "in png_set_invert_mono"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= PNG_INVERT_MONO; -} - -/* Invert monochrome grayscale data */ -void /* PRIVATE */ -png_do_invert(png_row_infop row_info, png_bytep row) -{ - png_debug(1, "in png_do_invert"); - - /* This test removed from libpng version 1.0.13 and 1.2.0: - * if (row_info->bit_depth == 1 && - */ - if (row_info->color_type == PNG_COLOR_TYPE_GRAY) - { - png_bytep rp = row; - png_size_t i; - png_size_t istop = row_info->rowbytes; - - for (i = 0; i < istop; i++) - { - *rp = (png_byte)(~(*rp)); - rp++; - } - } - - else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && - row_info->bit_depth == 8) - { - png_bytep rp = row; - png_size_t i; - png_size_t istop = row_info->rowbytes; - - for (i = 0; i < istop; i += 2) - { - *rp = (png_byte)(~(*rp)); - rp += 2; - } - } - -#ifdef PNG_16BIT_SUPPORTED - else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && - row_info->bit_depth == 16) - { - png_bytep rp = row; - png_size_t i; - png_size_t istop = row_info->rowbytes; - - for (i = 0; i < istop; i += 4) - { - *rp = (png_byte)(~(*rp)); - *(rp + 1) = (png_byte)(~(*(rp + 1))); - rp += 4; - } - } -#endif -} -#endif - -#ifdef PNG_16BIT_SUPPORTED -#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) -/* Swaps byte order on 16 bit depth images */ -void /* PRIVATE */ -png_do_swap(png_row_infop row_info, png_bytep row) -{ - png_debug(1, "in png_do_swap"); - - if (row_info->bit_depth == 16) - { - png_bytep rp = row; - png_uint_32 i; - png_uint_32 istop= row_info->width * row_info->channels; - - for (i = 0; i < istop; i++, rp += 2) - { - png_byte t = *rp; - *rp = *(rp + 1); - *(rp + 1) = t; - } - } -} -#endif -#endif - -#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) -static PNG_CONST png_byte onebppswaptable[256] = { - 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, - 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, - 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, - 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, - 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, - 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, - 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, - 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, - 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, - 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, - 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, - 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, - 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, - 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, - 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, - 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, - 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, - 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, - 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, - 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, - 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, - 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, - 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, - 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, - 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, - 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, - 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, - 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, - 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, - 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, - 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, - 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF -}; - -static PNG_CONST png_byte twobppswaptable[256] = { - 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0, - 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0, - 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4, - 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4, - 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8, - 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8, - 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC, - 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC, - 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1, - 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1, - 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5, - 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5, - 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9, - 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9, - 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD, - 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD, - 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2, - 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2, - 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6, - 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6, - 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA, - 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA, - 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE, - 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE, - 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3, - 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3, - 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7, - 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7, - 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB, - 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB, - 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF, - 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF -}; - -static PNG_CONST png_byte fourbppswaptable[256] = { - 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, - 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0, - 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71, - 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1, - 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72, - 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2, - 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73, - 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3, - 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74, - 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4, - 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75, - 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5, - 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76, - 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6, - 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77, - 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7, - 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78, - 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8, - 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79, - 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9, - 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A, - 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA, - 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B, - 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB, - 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C, - 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC, - 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D, - 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD, - 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E, - 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE, - 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F, - 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF -}; - -/* Swaps pixel packing order within bytes */ -void /* PRIVATE */ -png_do_packswap(png_row_infop row_info, png_bytep row) -{ - png_debug(1, "in png_do_packswap"); - - if (row_info->bit_depth < 8) - { - png_bytep rp; - png_const_bytep end, table; - - end = row + row_info->rowbytes; - - if (row_info->bit_depth == 1) - table = onebppswaptable; - - else if (row_info->bit_depth == 2) - table = twobppswaptable; - - else if (row_info->bit_depth == 4) - table = fourbppswaptable; - - else - return; - - for (rp = row; rp < end; rp++) - *rp = table[*rp]; - } -} -#endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */ - -#if defined(PNG_WRITE_FILLER_SUPPORTED) || \ - defined(PNG_READ_STRIP_ALPHA_SUPPORTED) -/* Remove a channel - this used to be 'png_do_strip_filler' but it used a - * somewhat weird combination of flags to determine what to do. All the calls - * to png_do_strip_filler are changed in 1.5.2 to call this instead with the - * correct arguments. - * - * The routine isn't general - the channel must be the channel at the start or - * end (not in the middle) of each pixel. - */ -void /* PRIVATE */ -png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start) -{ - png_bytep sp = row; /* source pointer */ - png_bytep dp = row; /* destination pointer */ - png_bytep ep = row + row_info->rowbytes; /* One beyond end of row */ - - /* At the start sp will point to the first byte to copy and dp to where - * it is copied to. ep always points just beyond the end of the row, so - * the loop simply copies (channels-1) channels until sp reaches ep. - * - * at_start: 0 -- convert AG, XG, ARGB, XRGB, AAGG, XXGG, etc. - * nonzero -- convert GA, GX, RGBA, RGBX, GGAA, RRGGBBXX, etc. - */ - - /* GA, GX, XG cases */ - if (row_info->channels == 2) - { - if (row_info->bit_depth == 8) - { - if (at_start) /* Skip initial filler */ - ++sp; - else /* Skip initial channel and, for sp, the filler */ - sp += 2, ++dp; - - /* For a 1 pixel wide image there is nothing to do */ - while (sp < ep) - *dp++ = *sp, sp += 2; - - row_info->pixel_depth = 8; - } - - else if (row_info->bit_depth == 16) - { - if (at_start) /* Skip initial filler */ - sp += 2; - else /* Skip initial channel and, for sp, the filler */ - sp += 4, dp += 2; - - while (sp < ep) - *dp++ = *sp++, *dp++ = *sp, sp += 3; - - row_info->pixel_depth = 16; - } - - else - return; /* bad bit depth */ - - row_info->channels = 1; - - /* Finally fix the color type if it records an alpha channel */ - if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - row_info->color_type = PNG_COLOR_TYPE_GRAY; - } - - /* RGBA, RGBX, XRGB cases */ - else if (row_info->channels == 4) - { - if (row_info->bit_depth == 8) - { - if (at_start) /* Skip initial filler */ - ++sp; - else /* Skip initial channels and, for sp, the filler */ - sp += 4, dp += 3; - - /* Note that the loop adds 3 to dp and 4 to sp each time. */ - while (sp < ep) - *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2; - - row_info->pixel_depth = 24; - } - - else if (row_info->bit_depth == 16) - { - if (at_start) /* Skip initial filler */ - sp += 2; - else /* Skip initial channels and, for sp, the filler */ - sp += 8, dp += 6; - - while (sp < ep) - { - /* Copy 6 bytes, skip 2 */ - *dp++ = *sp++, *dp++ = *sp++; - *dp++ = *sp++, *dp++ = *sp++; - *dp++ = *sp++, *dp++ = *sp, sp += 3; - } - - row_info->pixel_depth = 48; - } - - else - return; /* bad bit depth */ - - row_info->channels = 3; - - /* Finally fix the color type if it records an alpha channel */ - if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - row_info->color_type = PNG_COLOR_TYPE_RGB; - } - - else - return; /* The filler channel has gone already */ - - /* Fix the rowbytes value. */ - row_info->rowbytes = dp-row; -} -#endif - -#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) -/* Swaps red and blue bytes within a pixel */ -void /* PRIVATE */ -png_do_bgr(png_row_infop row_info, png_bytep row) -{ - png_debug(1, "in png_do_bgr"); - - if ((row_info->color_type & PNG_COLOR_MASK_COLOR)) - { - png_uint_32 row_width = row_info->width; - if (row_info->bit_depth == 8) - { - if (row_info->color_type == PNG_COLOR_TYPE_RGB) - { - png_bytep rp; - png_uint_32 i; - - for (i = 0, rp = row; i < row_width; i++, rp += 3) - { - png_byte save = *rp; - *rp = *(rp + 2); - *(rp + 2) = save; - } - } - - else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - { - png_bytep rp; - png_uint_32 i; - - for (i = 0, rp = row; i < row_width; i++, rp += 4) - { - png_byte save = *rp; - *rp = *(rp + 2); - *(rp + 2) = save; - } - } - } - -#ifdef PNG_16BIT_SUPPORTED - else if (row_info->bit_depth == 16) - { - if (row_info->color_type == PNG_COLOR_TYPE_RGB) - { - png_bytep rp; - png_uint_32 i; - - for (i = 0, rp = row; i < row_width; i++, rp += 6) - { - png_byte save = *rp; - *rp = *(rp + 4); - *(rp + 4) = save; - save = *(rp + 1); - *(rp + 1) = *(rp + 5); - *(rp + 5) = save; - } - } - - else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - { - png_bytep rp; - png_uint_32 i; - - for (i = 0, rp = row; i < row_width; i++, rp += 8) - { - png_byte save = *rp; - *rp = *(rp + 4); - *(rp + 4) = save; - save = *(rp + 1); - *(rp + 1) = *(rp + 5); - *(rp + 5) = save; - } - } - } -#endif - } -} -#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ - -#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \ - defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED) -/* Added at libpng-1.5.10 */ -void /* PRIVATE */ -png_do_check_palette_indexes(png_structp png_ptr, png_row_infop row_info) -{ - if (png_ptr->num_palette < (1 << row_info->bit_depth) && - png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */ - { - /* Calculations moved outside switch in an attempt to stop different - * compiler warnings. 'padding' is in *bits* within the last byte, it is - * an 'int' because pixel_depth becomes an 'int' in the expression below, - * and this calculation is used because it avoids warnings that other - * forms produced on either GCC or MSVC. - */ - int padding = (-row_info->pixel_depth * row_info->width) & 7; - png_bytep rp = png_ptr->row_buf + row_info->rowbytes; - - switch (row_info->bit_depth) - { - case 1: - { - /* in this case, all bytes must be 0 so we don't need - * to unpack the pixels except for the rightmost one. - */ - for (; rp > png_ptr->row_buf; rp--) - { - if (*rp >> padding != 0) - png_ptr->num_palette_max = 1; - padding = 0; - } - - break; - } - - case 2: - { - for (; rp > png_ptr->row_buf; rp--) - { - int i = ((*rp >> padding) & 0x03); - - if (i > png_ptr->num_palette_max) - png_ptr->num_palette_max = i; - - i = (((*rp >> padding) >> 2) & 0x03); - - if (i > png_ptr->num_palette_max) - png_ptr->num_palette_max = i; - - i = (((*rp >> padding) >> 4) & 0x03); - - if (i > png_ptr->num_palette_max) - png_ptr->num_palette_max = i; - - i = (((*rp >> padding) >> 6) & 0x03); - - if (i > png_ptr->num_palette_max) - png_ptr->num_palette_max = i; - - padding = 0; - } - - break; - } - - case 4: - { - for (; rp > png_ptr->row_buf; rp--) - { - int i = ((*rp >> padding) & 0x0f); - - if (i > png_ptr->num_palette_max) - png_ptr->num_palette_max = i; - - i = (((*rp >> padding) >> 4) & 0x0f); - - if (i > png_ptr->num_palette_max) - png_ptr->num_palette_max = i; - - padding = 0; - } - - break; - } - - case 8: - { - for (; rp > png_ptr->row_buf; rp--) - { - if (*rp > png_ptr->num_palette_max) - png_ptr->num_palette_max = (int) *rp; - } - - break; - } - - default: - break; - } - } -} -#endif /* PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED */ - -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ - defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) -#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED -void PNGAPI -png_set_user_transform_info(png_structp png_ptr, png_voidp - user_transform_ptr, int user_transform_depth, int user_transform_channels) -{ - png_debug(1, "in png_set_user_transform_info"); - - if (png_ptr == NULL) - return; - png_ptr->user_transform_ptr = user_transform_ptr; - png_ptr->user_transform_depth = (png_byte)user_transform_depth; - png_ptr->user_transform_channels = (png_byte)user_transform_channels; -} -#endif - -/* This function returns a pointer to the user_transform_ptr associated with - * the user transform functions. The application should free any memory - * associated with this pointer before png_write_destroy and png_read_destroy - * are called. - */ -#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED -png_voidp PNGAPI -png_get_user_transform_ptr(png_const_structp png_ptr) -{ - if (png_ptr == NULL) - return (NULL); - - return ((png_voidp)png_ptr->user_transform_ptr); -} -#endif - -#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED -png_uint_32 PNGAPI -png_get_current_row_number(png_const_structp png_ptr) -{ - /* See the comments in png.h - this is the sub-image row when reading and - * interlaced image. - */ - if (png_ptr != NULL) - return png_ptr->row_number; - - return PNG_UINT_32_MAX; /* help the app not to fail silently */ -} - -png_byte PNGAPI -png_get_current_pass_number(png_const_structp png_ptr) -{ - if (png_ptr != NULL) - return png_ptr->pass; - return 8; /* invalid */ -} -#endif /* PNG_USER_TRANSFORM_INFO_SUPPORTED */ -#endif /* PNG_READ_USER_TRANSFORM_SUPPORTED || - PNG_WRITE_USER_TRANSFORM_SUPPORTED */ -#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ + +/* pngtrans.c - transforms the data in a row (used by both readers and writers) + * + * Last changed in libpng 1.5.11 [June 14, 2012] + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "pngpriv.h" + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +/* Turn on BGR-to-RGB mapping */ +void PNGAPI +png_set_bgr(png_structp png_ptr) +{ + png_debug(1, "in png_set_bgr"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_BGR; +} +#endif + +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +/* Turn on 16 bit byte swapping */ +void PNGAPI +png_set_swap(png_structp png_ptr) +{ + png_debug(1, "in png_set_swap"); + + if (png_ptr == NULL) + return; + + if (png_ptr->bit_depth == 16) + png_ptr->transformations |= PNG_SWAP_BYTES; +} +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) +/* Turn on pixel packing */ +void PNGAPI +png_set_packing(png_structp png_ptr) +{ + png_debug(1, "in png_set_packing"); + + if (png_ptr == NULL) + return; + + if (png_ptr->bit_depth < 8) + { + png_ptr->transformations |= PNG_PACK; + png_ptr->usr_bit_depth = 8; + } +} +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) +/* Turn on packed pixel swapping */ +void PNGAPI +png_set_packswap(png_structp png_ptr) +{ + png_debug(1, "in png_set_packswap"); + + if (png_ptr == NULL) + return; + + if (png_ptr->bit_depth < 8) + png_ptr->transformations |= PNG_PACKSWAP; +} +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) +void PNGAPI +png_set_shift(png_structp png_ptr, png_const_color_8p true_bits) +{ + png_debug(1, "in png_set_shift"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_SHIFT; + png_ptr->shift = *true_bits; +} +#endif + +#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ + defined(PNG_WRITE_INTERLACING_SUPPORTED) +int PNGAPI +png_set_interlace_handling(png_structp png_ptr) +{ + png_debug(1, "in png_set_interlace handling"); + + if (png_ptr && png_ptr->interlaced) + { + png_ptr->transformations |= PNG_INTERLACE; + return (7); + } + + return (1); +} +#endif + +#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) +/* Add a filler byte on read, or remove a filler or alpha byte on write. + * The filler type has changed in v0.95 to allow future 2-byte fillers + * for 48-bit input data, as well as to avoid problems with some compilers + * that don't like bytes as parameters. + */ +void PNGAPI +png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc) +{ + png_debug(1, "in png_set_filler"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_FILLER; + png_ptr->filler = (png_uint_16)filler; + + if (filler_loc == PNG_FILLER_AFTER) + png_ptr->flags |= PNG_FLAG_FILLER_AFTER; + + else + png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER; + + /* This should probably go in the "do_read_filler" routine. + * I attempted to do that in libpng-1.0.1a but that caused problems + * so I restored it in libpng-1.0.2a + */ + + if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) + { + png_ptr->usr_channels = 4; + } + + /* Also I added this in libpng-1.0.2a (what happens when we expand + * a less-than-8-bit grayscale to GA?) */ + + if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8) + { + png_ptr->usr_channels = 2; + } +} + +/* Added to libpng-1.2.7 */ +void PNGAPI +png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) +{ + png_debug(1, "in png_set_add_alpha"); + + if (png_ptr == NULL) + return; + + png_set_filler(png_ptr, filler, filler_loc); + png_ptr->transformations |= PNG_ADD_ALPHA; +} + +#endif + +#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) +void PNGAPI +png_set_swap_alpha(png_structp png_ptr) +{ + png_debug(1, "in png_set_swap_alpha"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_SWAP_ALPHA; +} +#endif + +#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) +void PNGAPI +png_set_invert_alpha(png_structp png_ptr) +{ + png_debug(1, "in png_set_invert_alpha"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_INVERT_ALPHA; +} +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) +void PNGAPI +png_set_invert_mono(png_structp png_ptr) +{ + png_debug(1, "in png_set_invert_mono"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_INVERT_MONO; +} + +/* Invert monochrome grayscale data */ +void /* PRIVATE */ +png_do_invert(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_invert"); + + /* This test removed from libpng version 1.0.13 and 1.2.0: + * if (row_info->bit_depth == 1 && + */ + if (row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + png_bytep rp = row; + png_size_t i; + png_size_t istop = row_info->rowbytes; + + for (i = 0; i < istop; i++) + { + *rp = (png_byte)(~(*rp)); + rp++; + } + } + + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && + row_info->bit_depth == 8) + { + png_bytep rp = row; + png_size_t i; + png_size_t istop = row_info->rowbytes; + + for (i = 0; i < istop; i += 2) + { + *rp = (png_byte)(~(*rp)); + rp += 2; + } + } + +#ifdef PNG_16BIT_SUPPORTED + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && + row_info->bit_depth == 16) + { + png_bytep rp = row; + png_size_t i; + png_size_t istop = row_info->rowbytes; + + for (i = 0; i < istop; i += 4) + { + *rp = (png_byte)(~(*rp)); + *(rp + 1) = (png_byte)(~(*(rp + 1))); + rp += 4; + } + } +#endif +} +#endif + +#ifdef PNG_16BIT_SUPPORTED +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +/* Swaps byte order on 16 bit depth images */ +void /* PRIVATE */ +png_do_swap(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_swap"); + + if (row_info->bit_depth == 16) + { + png_bytep rp = row; + png_uint_32 i; + png_uint_32 istop= row_info->width * row_info->channels; + + for (i = 0; i < istop; i++, rp += 2) + { + png_byte t = *rp; + *rp = *(rp + 1); + *(rp + 1) = t; + } + } +} +#endif +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) +static PNG_CONST png_byte onebppswaptable[256] = { + 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, + 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, + 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, + 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, + 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, + 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, + 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, + 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, + 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, + 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, + 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, + 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, + 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, + 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, + 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, + 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, + 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, + 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, + 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, + 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, + 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, + 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, + 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, + 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, + 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, + 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, + 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, + 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, + 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, + 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, + 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, + 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF +}; + +static PNG_CONST png_byte twobppswaptable[256] = { + 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0, + 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0, + 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4, + 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4, + 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8, + 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8, + 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC, + 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC, + 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1, + 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1, + 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5, + 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5, + 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9, + 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9, + 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD, + 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD, + 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2, + 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2, + 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6, + 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6, + 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA, + 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA, + 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE, + 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE, + 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3, + 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3, + 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7, + 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7, + 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB, + 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB, + 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF, + 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF +}; + +static PNG_CONST png_byte fourbppswaptable[256] = { + 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, + 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0, + 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71, + 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1, + 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72, + 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2, + 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73, + 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3, + 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74, + 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4, + 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75, + 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5, + 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76, + 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6, + 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77, + 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7, + 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78, + 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8, + 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79, + 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9, + 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A, + 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA, + 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B, + 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB, + 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C, + 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC, + 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D, + 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD, + 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E, + 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE, + 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F, + 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF +}; + +/* Swaps pixel packing order within bytes */ +void /* PRIVATE */ +png_do_packswap(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_packswap"); + + if (row_info->bit_depth < 8) + { + png_bytep rp; + png_const_bytep end, table; + + end = row + row_info->rowbytes; + + if (row_info->bit_depth == 1) + table = onebppswaptable; + + else if (row_info->bit_depth == 2) + table = twobppswaptable; + + else if (row_info->bit_depth == 4) + table = fourbppswaptable; + + else + return; + + for (rp = row; rp < end; rp++) + *rp = table[*rp]; + } +} +#endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */ + +#if defined(PNG_WRITE_FILLER_SUPPORTED) || \ + defined(PNG_READ_STRIP_ALPHA_SUPPORTED) +/* Remove a channel - this used to be 'png_do_strip_filler' but it used a + * somewhat weird combination of flags to determine what to do. All the calls + * to png_do_strip_filler are changed in 1.5.2 to call this instead with the + * correct arguments. + * + * The routine isn't general - the channel must be the channel at the start or + * end (not in the middle) of each pixel. + */ +void /* PRIVATE */ +png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start) +{ + png_bytep sp = row; /* source pointer */ + png_bytep dp = row; /* destination pointer */ + png_bytep ep = row + row_info->rowbytes; /* One beyond end of row */ + + /* At the start sp will point to the first byte to copy and dp to where + * it is copied to. ep always points just beyond the end of the row, so + * the loop simply copies (channels-1) channels until sp reaches ep. + * + * at_start: 0 -- convert AG, XG, ARGB, XRGB, AAGG, XXGG, etc. + * nonzero -- convert GA, GX, RGBA, RGBX, GGAA, RRGGBBXX, etc. + */ + + /* GA, GX, XG cases */ + if (row_info->channels == 2) + { + if (row_info->bit_depth == 8) + { + if (at_start) /* Skip initial filler */ + ++sp; + else /* Skip initial channel and, for sp, the filler */ + sp += 2, ++dp; + + /* For a 1 pixel wide image there is nothing to do */ + while (sp < ep) + *dp++ = *sp, sp += 2; + + row_info->pixel_depth = 8; + } + + else if (row_info->bit_depth == 16) + { + if (at_start) /* Skip initial filler */ + sp += 2; + else /* Skip initial channel and, for sp, the filler */ + sp += 4, dp += 2; + + while (sp < ep) + *dp++ = *sp++, *dp++ = *sp, sp += 3; + + row_info->pixel_depth = 16; + } + + else + return; /* bad bit depth */ + + row_info->channels = 1; + + /* Finally fix the color type if it records an alpha channel */ + if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + row_info->color_type = PNG_COLOR_TYPE_GRAY; + } + + /* RGBA, RGBX, XRGB cases */ + else if (row_info->channels == 4) + { + if (row_info->bit_depth == 8) + { + if (at_start) /* Skip initial filler */ + ++sp; + else /* Skip initial channels and, for sp, the filler */ + sp += 4, dp += 3; + + /* Note that the loop adds 3 to dp and 4 to sp each time. */ + while (sp < ep) + *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2; + + row_info->pixel_depth = 24; + } + + else if (row_info->bit_depth == 16) + { + if (at_start) /* Skip initial filler */ + sp += 2; + else /* Skip initial channels and, for sp, the filler */ + sp += 8, dp += 6; + + while (sp < ep) + { + /* Copy 6 bytes, skip 2 */ + *dp++ = *sp++, *dp++ = *sp++; + *dp++ = *sp++, *dp++ = *sp++; + *dp++ = *sp++, *dp++ = *sp, sp += 3; + } + + row_info->pixel_depth = 48; + } + + else + return; /* bad bit depth */ + + row_info->channels = 3; + + /* Finally fix the color type if it records an alpha channel */ + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + row_info->color_type = PNG_COLOR_TYPE_RGB; + } + + else + return; /* The filler channel has gone already */ + + /* Fix the rowbytes value. */ + row_info->rowbytes = dp-row; +} +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +/* Swaps red and blue bytes within a pixel */ +void /* PRIVATE */ +png_do_bgr(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_bgr"); + + if ((row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + png_uint_32 row_width = row_info->width; + if (row_info->bit_depth == 8) + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 3) + { + png_byte save = *rp; + *rp = *(rp + 2); + *(rp + 2) = save; + } + } + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 4) + { + png_byte save = *rp; + *rp = *(rp + 2); + *(rp + 2) = save; + } + } + } + +#ifdef PNG_16BIT_SUPPORTED + else if (row_info->bit_depth == 16) + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 6) + { + png_byte save = *rp; + *rp = *(rp + 4); + *(rp + 4) = save; + save = *(rp + 1); + *(rp + 1) = *(rp + 5); + *(rp + 5) = save; + } + } + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 8) + { + png_byte save = *rp; + *rp = *(rp + 4); + *(rp + 4) = save; + save = *(rp + 1); + *(rp + 1) = *(rp + 5); + *(rp + 5) = save; + } + } + } +#endif + } +} +#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ + +#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \ + defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED) +/* Added at libpng-1.5.10 */ +void /* PRIVATE */ +png_do_check_palette_indexes(png_structp png_ptr, png_row_infop row_info) +{ + if (png_ptr->num_palette < (1 << row_info->bit_depth) && + png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */ + { + /* Calculations moved outside switch in an attempt to stop different + * compiler warnings. 'padding' is in *bits* within the last byte, it is + * an 'int' because pixel_depth becomes an 'int' in the expression below, + * and this calculation is used because it avoids warnings that other + * forms produced on either GCC or MSVC. + */ + int padding = (-row_info->pixel_depth * row_info->width) & 7; + png_bytep rp = png_ptr->row_buf + row_info->rowbytes; + + switch (row_info->bit_depth) + { + case 1: + { + /* in this case, all bytes must be 0 so we don't need + * to unpack the pixels except for the rightmost one. + */ + for (; rp > png_ptr->row_buf; rp--) + { + if (*rp >> padding != 0) + png_ptr->num_palette_max = 1; + padding = 0; + } + + break; + } + + case 2: + { + for (; rp > png_ptr->row_buf; rp--) + { + int i = ((*rp >> padding) & 0x03); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + i = (((*rp >> padding) >> 2) & 0x03); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + i = (((*rp >> padding) >> 4) & 0x03); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + i = (((*rp >> padding) >> 6) & 0x03); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + padding = 0; + } + + break; + } + + case 4: + { + for (; rp > png_ptr->row_buf; rp--) + { + int i = ((*rp >> padding) & 0x0f); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + i = (((*rp >> padding) >> 4) & 0x0f); + + if (i > png_ptr->num_palette_max) + png_ptr->num_palette_max = i; + + padding = 0; + } + + break; + } + + case 8: + { + for (; rp > png_ptr->row_buf; rp--) + { + if (*rp > png_ptr->num_palette_max) + png_ptr->num_palette_max = (int) *rp; + } + + break; + } + + default: + break; + } + } +} +#endif /* PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED */ + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED +void PNGAPI +png_set_user_transform_info(png_structp png_ptr, png_voidp + user_transform_ptr, int user_transform_depth, int user_transform_channels) +{ + png_debug(1, "in png_set_user_transform_info"); + + if (png_ptr == NULL) + return; + png_ptr->user_transform_ptr = user_transform_ptr; + png_ptr->user_transform_depth = (png_byte)user_transform_depth; + png_ptr->user_transform_channels = (png_byte)user_transform_channels; +} +#endif + +/* This function returns a pointer to the user_transform_ptr associated with + * the user transform functions. The application should free any memory + * associated with this pointer before png_write_destroy and png_read_destroy + * are called. + */ +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED +png_voidp PNGAPI +png_get_user_transform_ptr(png_const_structp png_ptr) +{ + if (png_ptr == NULL) + return (NULL); + + return ((png_voidp)png_ptr->user_transform_ptr); +} +#endif + +#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED +png_uint_32 PNGAPI +png_get_current_row_number(png_const_structp png_ptr) +{ + /* See the comments in png.h - this is the sub-image row when reading and + * interlaced image. + */ + if (png_ptr != NULL) + return png_ptr->row_number; + + return PNG_UINT_32_MAX; /* help the app not to fail silently */ +} + +png_byte PNGAPI +png_get_current_pass_number(png_const_structp png_ptr) +{ + if (png_ptr != NULL) + return png_ptr->pass; + return 8; /* invalid */ +} +#endif /* PNG_USER_TRANSFORM_INFO_SUPPORTED */ +#endif /* PNG_READ_USER_TRANSFORM_SUPPORTED || + PNG_WRITE_USER_TRANSFORM_SUPPORTED */ +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff --git a/Source/LibPNG/pngwio.c b/Source/LibPNG/pngwio.c index 8eacf9f..95ffb34 100644 --- a/Source/LibPNG/pngwio.c +++ b/Source/LibPNG/pngwio.c @@ -1,254 +1,254 @@ - -/* pngwio.c - functions for data output - * - * Last changed in libpng 1.5.0 [January 6, 2011] - * Copyright (c) 1998-2011 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - * - * This file provides a location for all output. Users who need - * special handling are expected to write functions that have the same - * arguments as these and perform similar functions, but that possibly - * use different output methods. Note that you shouldn't change these - * functions, but rather write replacement functions and then change - * them at run time with png_set_write_fn(...). - */ - -#include "pngpriv.h" - -#ifdef PNG_WRITE_SUPPORTED - -/* Write the data to whatever output you are using. The default routine - * writes to a file pointer. Note that this routine sometimes gets called - * with very small lengths, so you should implement some kind of simple - * buffering if you are using unbuffered writes. This should never be asked - * to write more than 64K on a 16 bit machine. - */ - -void /* PRIVATE */ -png_write_data(png_structp png_ptr, png_const_bytep data, png_size_t length) -{ - /* NOTE: write_data_fn must not change the buffer! */ - if (png_ptr->write_data_fn != NULL ) - (*(png_ptr->write_data_fn))(png_ptr, (png_bytep)data, length); - - else - png_error(png_ptr, "Call to NULL write function"); -} - -#ifdef PNG_STDIO_SUPPORTED -/* This is the function that does the actual writing of data. If you are - * not writing to a standard C stream, you should create a replacement - * write_data function and use it at run time with png_set_write_fn(), rather - * than changing the library. - */ -#ifndef USE_FAR_KEYWORD -void PNGCBAPI -png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) -{ - png_size_t check; - - if (png_ptr == NULL) - return; - - check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr)); - - if (check != length) - png_error(png_ptr, "Write Error"); -} -#else -/* This is the model-independent version. Since the standard I/O library - * can't handle far buffers in the medium and small models, we have to copy - * the data. - */ - -#define NEAR_BUF_SIZE 1024 -#define MIN(a,b) (a <= b ? a : b) - -void PNGCBAPI -png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) -{ - png_uint_32 check; - png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ - png_FILE_p io_ptr; - - if (png_ptr == NULL) - return; - - /* Check if data really is near. If so, use usual code. */ - near_data = (png_byte *)CVT_PTR_NOCHECK(data); - io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); - - if ((png_bytep)near_data == data) - { - check = fwrite(near_data, 1, length, io_ptr); - } - - else - { - png_byte buf[NEAR_BUF_SIZE]; - png_size_t written, remaining, err; - check = 0; - remaining = length; - - do - { - written = MIN(NEAR_BUF_SIZE, remaining); - png_memcpy(buf, data, written); /* Copy far buffer to near buffer */ - err = fwrite(buf, 1, written, io_ptr); - - if (err != written) - break; - - else - check += err; - - data += written; - remaining -= written; - } - while (remaining != 0); - } - - if (check != length) - png_error(png_ptr, "Write Error"); -} - -#endif -#endif - -/* This function is called to output any data pending writing (normally - * to disk). After png_flush is called, there should be no data pending - * writing in any buffers. - */ -#ifdef PNG_WRITE_FLUSH_SUPPORTED -void /* PRIVATE */ -png_flush(png_structp png_ptr) -{ - if (png_ptr->output_flush_fn != NULL) - (*(png_ptr->output_flush_fn))(png_ptr); -} - -# ifdef PNG_STDIO_SUPPORTED -void PNGCBAPI -png_default_flush(png_structp png_ptr) -{ - png_FILE_p io_ptr; - - if (png_ptr == NULL) - return; - - io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); - fflush(io_ptr); -} -# endif -#endif - -/* This function allows the application to supply new output functions for - * libpng if standard C streams aren't being used. - * - * This function takes as its arguments: - * png_ptr - pointer to a png output data structure - * io_ptr - pointer to user supplied structure containing info about - * the output functions. May be NULL. - * write_data_fn - pointer to a new output function that takes as its - * arguments a pointer to a png_struct, a pointer to - * data to be written, and a 32-bit unsigned int that is - * the number of bytes to be written. The new write - * function should call png_error(png_ptr, "Error msg") - * to exit and output any fatal error messages. May be - * NULL, in which case libpng's default function will - * be used. - * flush_data_fn - pointer to a new flush function that takes as its - * arguments a pointer to a png_struct. After a call to - * the flush function, there should be no data in any buffers - * or pending transmission. If the output method doesn't do - * any buffering of output, a function prototype must still be - * supplied although it doesn't have to do anything. If - * PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile - * time, output_flush_fn will be ignored, although it must be - * supplied for compatibility. May be NULL, in which case - * libpng's default function will be used, if - * PNG_WRITE_FLUSH_SUPPORTED is defined. This is not - * a good idea if io_ptr does not point to a standard - * *FILE structure. - */ -void PNGAPI -png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, - png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) -{ - if (png_ptr == NULL) - return; - - png_ptr->io_ptr = io_ptr; - -#ifdef PNG_STDIO_SUPPORTED - if (write_data_fn != NULL) - png_ptr->write_data_fn = write_data_fn; - - else - png_ptr->write_data_fn = png_default_write_data; -#else - png_ptr->write_data_fn = write_data_fn; -#endif - -#ifdef PNG_WRITE_FLUSH_SUPPORTED -# ifdef PNG_STDIO_SUPPORTED - - if (output_flush_fn != NULL) - png_ptr->output_flush_fn = output_flush_fn; - - else - png_ptr->output_flush_fn = png_default_flush; - -# else - png_ptr->output_flush_fn = output_flush_fn; -# endif -#endif /* PNG_WRITE_FLUSH_SUPPORTED */ - - /* It is an error to read while writing a png file */ - if (png_ptr->read_data_fn != NULL) - { - png_ptr->read_data_fn = NULL; - - png_warning(png_ptr, - "Can't set both read_data_fn and write_data_fn in the" - " same structure"); - } -} - -#ifdef USE_FAR_KEYWORD -# ifdef _MSC_VER -void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check) -{ - void *near_ptr; - void FAR *far_ptr; - FP_OFF(near_ptr) = FP_OFF(ptr); - far_ptr = (void FAR *)near_ptr; - - if (check != 0) - if (FP_SEG(ptr) != FP_SEG(far_ptr)) - png_error(png_ptr, "segment lost in conversion"); - - return(near_ptr); -} -# else -void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check) -{ - void *near_ptr; - void FAR *far_ptr; - near_ptr = (void FAR *)ptr; - far_ptr = (void FAR *)near_ptr; - - if (check != 0) - if (far_ptr != ptr) - png_error(png_ptr, "segment lost in conversion"); - - return(near_ptr); -} -# endif -#endif -#endif /* PNG_WRITE_SUPPORTED */ + +/* pngwio.c - functions for data output + * + * Last changed in libpng 1.5.0 [January 6, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file provides a location for all output. Users who need + * special handling are expected to write functions that have the same + * arguments as these and perform similar functions, but that possibly + * use different output methods. Note that you shouldn't change these + * functions, but rather write replacement functions and then change + * them at run time with png_set_write_fn(...). + */ + +#include "pngpriv.h" + +#ifdef PNG_WRITE_SUPPORTED + +/* Write the data to whatever output you are using. The default routine + * writes to a file pointer. Note that this routine sometimes gets called + * with very small lengths, so you should implement some kind of simple + * buffering if you are using unbuffered writes. This should never be asked + * to write more than 64K on a 16 bit machine. + */ + +void /* PRIVATE */ +png_write_data(png_structp png_ptr, png_const_bytep data, png_size_t length) +{ + /* NOTE: write_data_fn must not change the buffer! */ + if (png_ptr->write_data_fn != NULL ) + (*(png_ptr->write_data_fn))(png_ptr, (png_bytep)data, length); + + else + png_error(png_ptr, "Call to NULL write function"); +} + +#ifdef PNG_STDIO_SUPPORTED +/* This is the function that does the actual writing of data. If you are + * not writing to a standard C stream, you should create a replacement + * write_data function and use it at run time with png_set_write_fn(), rather + * than changing the library. + */ +#ifndef USE_FAR_KEYWORD +void PNGCBAPI +png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_size_t check; + + if (png_ptr == NULL) + return; + + check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr)); + + if (check != length) + png_error(png_ptr, "Write Error"); +} +#else +/* This is the model-independent version. Since the standard I/O library + * can't handle far buffers in the medium and small models, we have to copy + * the data. + */ + +#define NEAR_BUF_SIZE 1024 +#define MIN(a,b) (a <= b ? a : b) + +void PNGCBAPI +png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_uint_32 check; + png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ + png_FILE_p io_ptr; + + if (png_ptr == NULL) + return; + + /* Check if data really is near. If so, use usual code. */ + near_data = (png_byte *)CVT_PTR_NOCHECK(data); + io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); + + if ((png_bytep)near_data == data) + { + check = fwrite(near_data, 1, length, io_ptr); + } + + else + { + png_byte buf[NEAR_BUF_SIZE]; + png_size_t written, remaining, err; + check = 0; + remaining = length; + + do + { + written = MIN(NEAR_BUF_SIZE, remaining); + png_memcpy(buf, data, written); /* Copy far buffer to near buffer */ + err = fwrite(buf, 1, written, io_ptr); + + if (err != written) + break; + + else + check += err; + + data += written; + remaining -= written; + } + while (remaining != 0); + } + + if (check != length) + png_error(png_ptr, "Write Error"); +} + +#endif +#endif + +/* This function is called to output any data pending writing (normally + * to disk). After png_flush is called, there should be no data pending + * writing in any buffers. + */ +#ifdef PNG_WRITE_FLUSH_SUPPORTED +void /* PRIVATE */ +png_flush(png_structp png_ptr) +{ + if (png_ptr->output_flush_fn != NULL) + (*(png_ptr->output_flush_fn))(png_ptr); +} + +# ifdef PNG_STDIO_SUPPORTED +void PNGCBAPI +png_default_flush(png_structp png_ptr) +{ + png_FILE_p io_ptr; + + if (png_ptr == NULL) + return; + + io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); + fflush(io_ptr); +} +# endif +#endif + +/* This function allows the application to supply new output functions for + * libpng if standard C streams aren't being used. + * + * This function takes as its arguments: + * png_ptr - pointer to a png output data structure + * io_ptr - pointer to user supplied structure containing info about + * the output functions. May be NULL. + * write_data_fn - pointer to a new output function that takes as its + * arguments a pointer to a png_struct, a pointer to + * data to be written, and a 32-bit unsigned int that is + * the number of bytes to be written. The new write + * function should call png_error(png_ptr, "Error msg") + * to exit and output any fatal error messages. May be + * NULL, in which case libpng's default function will + * be used. + * flush_data_fn - pointer to a new flush function that takes as its + * arguments a pointer to a png_struct. After a call to + * the flush function, there should be no data in any buffers + * or pending transmission. If the output method doesn't do + * any buffering of output, a function prototype must still be + * supplied although it doesn't have to do anything. If + * PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile + * time, output_flush_fn will be ignored, although it must be + * supplied for compatibility. May be NULL, in which case + * libpng's default function will be used, if + * PNG_WRITE_FLUSH_SUPPORTED is defined. This is not + * a good idea if io_ptr does not point to a standard + * *FILE structure. + */ +void PNGAPI +png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, + png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) +{ + if (png_ptr == NULL) + return; + + png_ptr->io_ptr = io_ptr; + +#ifdef PNG_STDIO_SUPPORTED + if (write_data_fn != NULL) + png_ptr->write_data_fn = write_data_fn; + + else + png_ptr->write_data_fn = png_default_write_data; +#else + png_ptr->write_data_fn = write_data_fn; +#endif + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +# ifdef PNG_STDIO_SUPPORTED + + if (output_flush_fn != NULL) + png_ptr->output_flush_fn = output_flush_fn; + + else + png_ptr->output_flush_fn = png_default_flush; + +# else + png_ptr->output_flush_fn = output_flush_fn; +# endif +#endif /* PNG_WRITE_FLUSH_SUPPORTED */ + + /* It is an error to read while writing a png file */ + if (png_ptr->read_data_fn != NULL) + { + png_ptr->read_data_fn = NULL; + + png_warning(png_ptr, + "Can't set both read_data_fn and write_data_fn in the" + " same structure"); + } +} + +#ifdef USE_FAR_KEYWORD +# ifdef _MSC_VER +void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check) +{ + void *near_ptr; + void FAR *far_ptr; + FP_OFF(near_ptr) = FP_OFF(ptr); + far_ptr = (void FAR *)near_ptr; + + if (check != 0) + if (FP_SEG(ptr) != FP_SEG(far_ptr)) + png_error(png_ptr, "segment lost in conversion"); + + return(near_ptr); +} +# else +void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check) +{ + void *near_ptr; + void FAR *far_ptr; + near_ptr = (void FAR *)ptr; + far_ptr = (void FAR *)near_ptr; + + if (check != 0) + if (far_ptr != ptr) + png_error(png_ptr, "segment lost in conversion"); + + return(near_ptr); +} +# endif +#endif +#endif /* PNG_WRITE_SUPPORTED */ diff --git a/Source/LibPNG/pngwrite.c b/Source/LibPNG/pngwrite.c index c188439..2a72ad3 100644 --- a/Source/LibPNG/pngwrite.c +++ b/Source/LibPNG/pngwrite.c @@ -1,1668 +1,1668 @@ - -/* pngwrite.c - general routines to write a PNG file - * - * Last changed in libpng 1.5.11 [June 14, 2012] - * Copyright (c) 1998-2012 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - */ - -#include "pngpriv.h" - -#ifdef PNG_WRITE_SUPPORTED - -/* Writes all the PNG information. This is the suggested way to use the - * library. If you have a new chunk to add, make a function to write it, - * and put it in the correct location here. If you want the chunk written - * after the image data, put it in png_write_end(). I strongly encourage - * you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing - * the chunk, as that will keep the code from breaking if you want to just - * write a plain PNG file. If you have long comments, I suggest writing - * them in png_write_end(), and compressing them. - */ -void PNGAPI -png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) -{ - png_debug(1, "in png_write_info_before_PLTE"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) - { - /* Write PNG signature */ - png_write_sig(png_ptr); - -#ifdef PNG_MNG_FEATURES_SUPPORTED - if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) && \ - (png_ptr->mng_features_permitted)) - { - png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); - png_ptr->mng_features_permitted = 0; - } -#endif - - /* Write IHDR information. */ - png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, - info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, - info_ptr->filter_type, -#ifdef PNG_WRITE_INTERLACING_SUPPORTED - info_ptr->interlace_type); -#else - 0); -#endif - /* The rest of these check to see if the valid field has the appropriate - * flag set, and if it does, writes the chunk. - */ -#ifdef PNG_WRITE_gAMA_SUPPORTED - if (info_ptr->valid & PNG_INFO_gAMA) - png_write_gAMA_fixed(png_ptr, info_ptr->gamma); -#endif -#ifdef PNG_WRITE_sRGB_SUPPORTED - if (info_ptr->valid & PNG_INFO_sRGB) - png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent); -#endif - -#ifdef PNG_WRITE_iCCP_SUPPORTED - if (info_ptr->valid & PNG_INFO_iCCP) - png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE, - (png_charp)info_ptr->iccp_profile, (int)info_ptr->iccp_proflen); -#endif -#ifdef PNG_WRITE_sBIT_SUPPORTED - if (info_ptr->valid & PNG_INFO_sBIT) - png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type); -#endif -#ifdef PNG_WRITE_cHRM_SUPPORTED - if (info_ptr->valid & PNG_INFO_cHRM) - png_write_cHRM_fixed(png_ptr, - info_ptr->x_white, info_ptr->y_white, - info_ptr->x_red, info_ptr->y_red, - info_ptr->x_green, info_ptr->y_green, - info_ptr->x_blue, info_ptr->y_blue); -#endif - -#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED - if (info_ptr->unknown_chunks_num) - { - png_unknown_chunk *up; - - png_debug(5, "writing extra chunks"); - - for (up = info_ptr->unknown_chunks; - up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; - up++) - { - int keep = png_handle_as_unknown(png_ptr, up->name); - - if (keep != PNG_HANDLE_CHUNK_NEVER && - up->location && - !(up->location & PNG_HAVE_PLTE) && - !(up->location & PNG_HAVE_IDAT) && - !(up->location & PNG_AFTER_IDAT) && - ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || - (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) - { - if (up->size == 0) - png_warning(png_ptr, "Writing zero-length unknown chunk"); - - png_write_chunk(png_ptr, up->name, up->data, up->size); - } - } - } -#endif - png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE; - } -} - -void PNGAPI -png_write_info(png_structp png_ptr, png_infop info_ptr) -{ -#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) - int i; -#endif - - png_debug(1, "in png_write_info"); - - if (png_ptr == NULL || info_ptr == NULL) - return; - - png_write_info_before_PLTE(png_ptr, info_ptr); - - if (info_ptr->valid & PNG_INFO_PLTE) - png_write_PLTE(png_ptr, info_ptr->palette, - (png_uint_32)info_ptr->num_palette); - - else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - png_error(png_ptr, "Valid palette required for paletted images"); - -#ifdef PNG_WRITE_tRNS_SUPPORTED - if (info_ptr->valid & PNG_INFO_tRNS) - { -#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED - /* Invert the alpha channel (in tRNS) */ - if ((png_ptr->transformations & PNG_INVERT_ALPHA) && - info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - { - int j; - for (j = 0; j<(int)info_ptr->num_trans; j++) - info_ptr->trans_alpha[j] = - (png_byte)(255 - info_ptr->trans_alpha[j]); - } -#endif - png_write_tRNS(png_ptr, info_ptr->trans_alpha, &(info_ptr->trans_color), - info_ptr->num_trans, info_ptr->color_type); - } -#endif -#ifdef PNG_WRITE_bKGD_SUPPORTED - if (info_ptr->valid & PNG_INFO_bKGD) - png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type); -#endif - -#ifdef PNG_WRITE_hIST_SUPPORTED - if (info_ptr->valid & PNG_INFO_hIST) - png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette); -#endif - -#ifdef PNG_WRITE_oFFs_SUPPORTED - if (info_ptr->valid & PNG_INFO_oFFs) - png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset, - info_ptr->offset_unit_type); -#endif - -#ifdef PNG_WRITE_pCAL_SUPPORTED - if (info_ptr->valid & PNG_INFO_pCAL) - png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0, - info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams, - info_ptr->pcal_units, info_ptr->pcal_params); -#endif - -#ifdef PNG_WRITE_sCAL_SUPPORTED - if (info_ptr->valid & PNG_INFO_sCAL) - png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit, - info_ptr->scal_s_width, info_ptr->scal_s_height); -#endif /* sCAL */ - -#ifdef PNG_WRITE_pHYs_SUPPORTED - if (info_ptr->valid & PNG_INFO_pHYs) - png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit, - info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type); -#endif /* pHYs */ - -#ifdef PNG_WRITE_tIME_SUPPORTED - if (info_ptr->valid & PNG_INFO_tIME) - { - png_write_tIME(png_ptr, &(info_ptr->mod_time)); - png_ptr->mode |= PNG_WROTE_tIME; - } -#endif /* tIME */ - -#ifdef PNG_WRITE_sPLT_SUPPORTED - if (info_ptr->valid & PNG_INFO_sPLT) - for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) - png_write_sPLT(png_ptr, info_ptr->splt_palettes + i); -#endif /* sPLT */ - -#ifdef PNG_WRITE_TEXT_SUPPORTED - /* Check to see if we need to write text chunks */ - for (i = 0; i < info_ptr->num_text; i++) - { - png_debug2(2, "Writing header text chunk %d, type %d", i, - info_ptr->text[i].compression); - /* An internationalized chunk? */ - if (info_ptr->text[i].compression > 0) - { -#ifdef PNG_WRITE_iTXt_SUPPORTED - /* Write international chunk */ - png_write_iTXt(png_ptr, - info_ptr->text[i].compression, - info_ptr->text[i].key, - info_ptr->text[i].lang, - info_ptr->text[i].lang_key, - info_ptr->text[i].text); -#else - png_warning(png_ptr, "Unable to write international text"); -#endif - /* Mark this chunk as written */ - info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; - } - - /* If we want a compressed text chunk */ - else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt) - { -#ifdef PNG_WRITE_zTXt_SUPPORTED - /* Write compressed chunk */ - png_write_zTXt(png_ptr, info_ptr->text[i].key, - info_ptr->text[i].text, 0, - info_ptr->text[i].compression); -#else - png_warning(png_ptr, "Unable to write compressed text"); -#endif - /* Mark this chunk as written */ - info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; - } - - else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) - { -#ifdef PNG_WRITE_tEXt_SUPPORTED - /* Write uncompressed chunk */ - png_write_tEXt(png_ptr, info_ptr->text[i].key, - info_ptr->text[i].text, - 0); - /* Mark this chunk as written */ - info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; -#else - /* Can't get here */ - png_warning(png_ptr, "Unable to write uncompressed text"); -#endif - } - } -#endif /* tEXt */ - -#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED - if (info_ptr->unknown_chunks_num) - { - png_unknown_chunk *up; - - png_debug(5, "writing extra chunks"); - - for (up = info_ptr->unknown_chunks; - up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; - up++) - { - int keep = png_handle_as_unknown(png_ptr, up->name); - if (keep != PNG_HANDLE_CHUNK_NEVER && - up->location && - (up->location & PNG_HAVE_PLTE) && - !(up->location & PNG_HAVE_IDAT) && - !(up->location & PNG_AFTER_IDAT) && - ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || - (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) - { - png_write_chunk(png_ptr, up->name, up->data, up->size); - } - } - } -#endif -} - -/* Writes the end of the PNG file. If you don't want to write comments or - * time information, you can pass NULL for info. If you already wrote these - * in png_write_info(), do not write them again here. If you have long - * comments, I suggest writing them here, and compressing them. - */ -void PNGAPI -png_write_end(png_structp png_ptr, png_infop info_ptr) -{ - png_debug(1, "in png_write_end"); - - if (png_ptr == NULL) - return; - - if (!(png_ptr->mode & PNG_HAVE_IDAT)) - png_error(png_ptr, "No IDATs written into file"); - -#ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED - if (png_ptr->num_palette_max > png_ptr->num_palette) - png_benign_error(png_ptr, "Wrote palette index exceeding num_palette"); -#endif - - /* See if user wants us to write information chunks */ - if (info_ptr != NULL) - { -#ifdef PNG_WRITE_TEXT_SUPPORTED - int i; /* local index variable */ -#endif -#ifdef PNG_WRITE_tIME_SUPPORTED - /* Check to see if user has supplied a time chunk */ - if ((info_ptr->valid & PNG_INFO_tIME) && - !(png_ptr->mode & PNG_WROTE_tIME)) - png_write_tIME(png_ptr, &(info_ptr->mod_time)); - -#endif -#ifdef PNG_WRITE_TEXT_SUPPORTED - /* Loop through comment chunks */ - for (i = 0; i < info_ptr->num_text; i++) - { - png_debug2(2, "Writing trailer text chunk %d, type %d", i, - info_ptr->text[i].compression); - /* An internationalized chunk? */ - if (info_ptr->text[i].compression > 0) - { -#ifdef PNG_WRITE_iTXt_SUPPORTED - /* Write international chunk */ - png_write_iTXt(png_ptr, - info_ptr->text[i].compression, - info_ptr->text[i].key, - info_ptr->text[i].lang, - info_ptr->text[i].lang_key, - info_ptr->text[i].text); -#else - png_warning(png_ptr, "Unable to write international text"); -#endif - /* Mark this chunk as written */ - info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; - } - - else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt) - { -#ifdef PNG_WRITE_zTXt_SUPPORTED - /* Write compressed chunk */ - png_write_zTXt(png_ptr, info_ptr->text[i].key, - info_ptr->text[i].text, 0, - info_ptr->text[i].compression); -#else - png_warning(png_ptr, "Unable to write compressed text"); -#endif - /* Mark this chunk as written */ - info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; - } - - else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) - { -#ifdef PNG_WRITE_tEXt_SUPPORTED - /* Write uncompressed chunk */ - png_write_tEXt(png_ptr, info_ptr->text[i].key, - info_ptr->text[i].text, 0); -#else - png_warning(png_ptr, "Unable to write uncompressed text"); -#endif - - /* Mark this chunk as written */ - info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; - } - } -#endif -#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED - if (info_ptr->unknown_chunks_num) - { - png_unknown_chunk *up; - - png_debug(5, "writing extra chunks"); - - for (up = info_ptr->unknown_chunks; - up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; - up++) - { - int keep = png_handle_as_unknown(png_ptr, up->name); - if (keep != PNG_HANDLE_CHUNK_NEVER && - up->location && - (up->location & PNG_AFTER_IDAT) && - ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || - (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) - { - png_write_chunk(png_ptr, up->name, up->data, up->size); - } - } - } -#endif - } - - png_ptr->mode |= PNG_AFTER_IDAT; - - /* Write end of PNG file */ - png_write_IEND(png_ptr); - /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03, - * and restored again in libpng-1.2.30, may cause some applications that - * do not set png_ptr->output_flush_fn to crash. If your application - * experiences a problem, please try building libpng with - * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to - * png-mng-implement at lists.sf.net . - */ -#ifdef PNG_WRITE_FLUSH_SUPPORTED -# ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED - png_flush(png_ptr); -# endif -#endif -} - -#ifdef PNG_CONVERT_tIME_SUPPORTED -/* "tm" structure is not supported on WindowsCE */ -void PNGAPI -png_convert_from_struct_tm(png_timep ptime, PNG_CONST struct tm FAR * ttime) -{ - png_debug(1, "in png_convert_from_struct_tm"); - - ptime->year = (png_uint_16)(1900 + ttime->tm_year); - ptime->month = (png_byte)(ttime->tm_mon + 1); - ptime->day = (png_byte)ttime->tm_mday; - ptime->hour = (png_byte)ttime->tm_hour; - ptime->minute = (png_byte)ttime->tm_min; - ptime->second = (png_byte)ttime->tm_sec; -} - -void PNGAPI -png_convert_from_time_t(png_timep ptime, time_t ttime) -{ - struct tm *tbuf; - - png_debug(1, "in png_convert_from_time_t"); - - tbuf = gmtime(&ttime); - png_convert_from_struct_tm(ptime, tbuf); -} -#endif - -/* Initialize png_ptr structure, and allocate any memory needed */ -PNG_FUNCTION(png_structp,PNGAPI -png_create_write_struct,(png_const_charp user_png_ver, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED) -{ -#ifdef PNG_USER_MEM_SUPPORTED - return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn, - warn_fn, NULL, NULL, NULL)); -} - -/* Alternate initialize png_ptr structure, and allocate any memory needed */ -static void png_reset_filter_heuristics(png_structp png_ptr); /* forward decl */ - -PNG_FUNCTION(png_structp,PNGAPI -png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, - png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, - png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED) -{ -#endif /* PNG_USER_MEM_SUPPORTED */ - volatile int png_cleanup_needed = 0; -#ifdef PNG_SETJMP_SUPPORTED - volatile -#endif - png_structp png_ptr; -#ifdef PNG_SETJMP_SUPPORTED -#ifdef USE_FAR_KEYWORD - jmp_buf tmp_jmpbuf; -#endif -#endif - - png_debug(1, "in png_create_write_struct"); - -#ifdef PNG_USER_MEM_SUPPORTED - png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, - (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); -#else - png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); -#endif /* PNG_USER_MEM_SUPPORTED */ - if (png_ptr == NULL) - return (NULL); - - /* Added at libpng-1.2.6 */ -#ifdef PNG_SET_USER_LIMITS_SUPPORTED - png_ptr->user_width_max = PNG_USER_WIDTH_MAX; - png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; -#endif - -#ifdef PNG_SETJMP_SUPPORTED -/* Applications that neglect to set up their own setjmp() and then - * encounter a png_error() will longjmp here. Since the jmpbuf is - * then meaningless we abort instead of returning. - */ -#ifdef USE_FAR_KEYWORD - if (setjmp(tmp_jmpbuf)) -#else - if (setjmp(png_jmpbuf(png_ptr))) /* sets longjmp to match setjmp */ -#endif -#ifdef USE_FAR_KEYWORD - png_memcpy(png_jmpbuf(png_ptr), tmp_jmpbuf, png_sizeof(jmp_buf)); -#endif - PNG_ABORT(); -#endif - -#ifdef PNG_USER_MEM_SUPPORTED - png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); -#endif /* PNG_USER_MEM_SUPPORTED */ - png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); - - if (!png_user_version_check(png_ptr, user_png_ver)) - png_cleanup_needed = 1; - - /* Initialize zbuf - compression buffer */ - png_ptr->zbuf_size = PNG_ZBUF_SIZE; - - if (!png_cleanup_needed) - { - png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, - png_ptr->zbuf_size); - if (png_ptr->zbuf == NULL) - png_cleanup_needed = 1; - } - - if (png_cleanup_needed) - { - /* Clean up PNG structure and deallocate any memory. */ - png_free(png_ptr, png_ptr->zbuf); - png_ptr->zbuf = NULL; -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)png_ptr, - (png_free_ptr)free_fn, (png_voidp)mem_ptr); -#else - png_destroy_struct((png_voidp)png_ptr); -#endif - return (NULL); - } - - png_set_write_fn(png_ptr, NULL, NULL, NULL); - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - png_reset_filter_heuristics(png_ptr); -#endif - - return (png_ptr); -} - - -/* Write a few rows of image data. If the image is interlaced, - * either you will have to write the 7 sub images, or, if you - * have called png_set_interlace_handling(), you will have to - * "write" the image seven times. - */ -void PNGAPI -png_write_rows(png_structp png_ptr, png_bytepp row, - png_uint_32 num_rows) -{ - png_uint_32 i; /* row counter */ - png_bytepp rp; /* row pointer */ - - png_debug(1, "in png_write_rows"); - - if (png_ptr == NULL) - return; - - /* Loop through the rows */ - for (i = 0, rp = row; i < num_rows; i++, rp++) - { - png_write_row(png_ptr, *rp); - } -} - -/* Write the image. You only need to call this function once, even - * if you are writing an interlaced image. - */ -void PNGAPI -png_write_image(png_structp png_ptr, png_bytepp image) -{ - png_uint_32 i; /* row index */ - int pass, num_pass; /* pass variables */ - png_bytepp rp; /* points to current row */ - - if (png_ptr == NULL) - return; - - png_debug(1, "in png_write_image"); - -#ifdef PNG_WRITE_INTERLACING_SUPPORTED - /* Initialize interlace handling. If image is not interlaced, - * this will set pass to 1 - */ - num_pass = png_set_interlace_handling(png_ptr); -#else - num_pass = 1; -#endif - /* Loop through passes */ - for (pass = 0; pass < num_pass; pass++) - { - /* Loop through image */ - for (i = 0, rp = image; i < png_ptr->height; i++, rp++) - { - png_write_row(png_ptr, *rp); - } - } -} - -/* Called by user to write a row of image data */ -void PNGAPI -png_write_row(png_structp png_ptr, png_const_bytep row) -{ - /* 1.5.6: moved from png_struct to be a local structure: */ - png_row_info row_info; - - if (png_ptr == NULL) - return; - - png_debug2(1, "in png_write_row (row %u, pass %d)", - png_ptr->row_number, png_ptr->pass); - - /* Initialize transformations and other stuff if first time */ - if (png_ptr->row_number == 0 && png_ptr->pass == 0) - { - /* Make sure we wrote the header info */ - if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) - png_error(png_ptr, - "png_write_info was never called before png_write_row"); - - /* Check for transforms that have been set but were defined out */ -#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED) - if (png_ptr->transformations & PNG_INVERT_MONO) - png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined"); -#endif - -#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED) - if (png_ptr->transformations & PNG_FILLER) - png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined"); -#endif -#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \ - defined(PNG_READ_PACKSWAP_SUPPORTED) - if (png_ptr->transformations & PNG_PACKSWAP) - png_warning(png_ptr, - "PNG_WRITE_PACKSWAP_SUPPORTED is not defined"); -#endif - -#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED) - if (png_ptr->transformations & PNG_PACK) - png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined"); -#endif - -#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED) - if (png_ptr->transformations & PNG_SHIFT) - png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined"); -#endif - -#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED) - if (png_ptr->transformations & PNG_BGR) - png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined"); -#endif - -#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED) - if (png_ptr->transformations & PNG_SWAP_BYTES) - png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined"); -#endif - - png_write_start_row(png_ptr); - } - -#ifdef PNG_WRITE_INTERLACING_SUPPORTED - /* If interlaced and not interested in row, return */ - if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) - { - switch (png_ptr->pass) - { - case 0: - if (png_ptr->row_number & 0x07) - { - png_write_finish_row(png_ptr); - return; - } - break; - - case 1: - if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) - { - png_write_finish_row(png_ptr); - return; - } - break; - - case 2: - if ((png_ptr->row_number & 0x07) != 4) - { - png_write_finish_row(png_ptr); - return; - } - break; - - case 3: - if ((png_ptr->row_number & 0x03) || png_ptr->width < 3) - { - png_write_finish_row(png_ptr); - return; - } - break; - - case 4: - if ((png_ptr->row_number & 0x03) != 2) - { - png_write_finish_row(png_ptr); - return; - } - break; - - case 5: - if ((png_ptr->row_number & 0x01) || png_ptr->width < 2) - { - png_write_finish_row(png_ptr); - return; - } - break; - - case 6: - if (!(png_ptr->row_number & 0x01)) - { - png_write_finish_row(png_ptr); - return; - } - break; - - default: /* error: ignore it */ - break; - } - } -#endif - - /* Set up row info for transformations */ - row_info.color_type = png_ptr->color_type; - row_info.width = png_ptr->usr_width; - row_info.channels = png_ptr->usr_channels; - row_info.bit_depth = png_ptr->usr_bit_depth; - row_info.pixel_depth = (png_byte)(row_info.bit_depth * row_info.channels); - row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); - - png_debug1(3, "row_info->color_type = %d", row_info.color_type); - png_debug1(3, "row_info->width = %u", row_info.width); - png_debug1(3, "row_info->channels = %d", row_info.channels); - png_debug1(3, "row_info->bit_depth = %d", row_info.bit_depth); - png_debug1(3, "row_info->pixel_depth = %d", row_info.pixel_depth); - png_debug1(3, "row_info->rowbytes = %lu", (unsigned long)row_info.rowbytes); - - /* Copy user's row into buffer, leaving room for filter byte. */ - png_memcpy(png_ptr->row_buf + 1, row, row_info.rowbytes); - -#ifdef PNG_WRITE_INTERLACING_SUPPORTED - /* Handle interlacing */ - if (png_ptr->interlaced && png_ptr->pass < 6 && - (png_ptr->transformations & PNG_INTERLACE)) - { - png_do_write_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass); - /* This should always get caught above, but still ... */ - if (!(row_info.width)) - { - png_write_finish_row(png_ptr); - return; - } - } -#endif - -#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED - /* Handle other transformations */ - if (png_ptr->transformations) - png_do_write_transformations(png_ptr, &row_info); -#endif - - /* At this point the row_info pixel depth must match the 'transformed' depth, - * which is also the output depth. - */ - if (row_info.pixel_depth != png_ptr->pixel_depth || - row_info.pixel_depth != png_ptr->transformed_pixel_depth) - png_error(png_ptr, "internal write transform logic error"); - -#ifdef PNG_MNG_FEATURES_SUPPORTED - /* Write filter_method 64 (intrapixel differencing) only if - * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and - * 2. Libpng did not write a PNG signature (this filter_method is only - * used in PNG datastreams that are embedded in MNG datastreams) and - * 3. The application called png_permit_mng_features with a mask that - * included PNG_FLAG_MNG_FILTER_64 and - * 4. The filter_method is 64 and - * 5. The color_type is RGB or RGBA - */ - if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && - (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) - { - /* Intrapixel differencing */ - png_do_write_intrapixel(&row_info, png_ptr->row_buf + 1); - } -#endif - -/* Added at libpng-1.5.10 */ -#ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED - /* Check for out-of-range palette index */ - if (row_info.color_type == PNG_COLOR_TYPE_PALETTE && - png_ptr->num_palette_max >= 0) - png_do_check_palette_indexes(png_ptr, &row_info); -#endif - - /* Find a filter if necessary, filter the row and write it out. */ - png_write_find_filter(png_ptr, &row_info); - - if (png_ptr->write_row_fn != NULL) - (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); -} - -#ifdef PNG_WRITE_FLUSH_SUPPORTED -/* Set the automatic flush interval or 0 to turn flushing off */ -void PNGAPI -png_set_flush(png_structp png_ptr, int nrows) -{ - png_debug(1, "in png_set_flush"); - - if (png_ptr == NULL) - return; - - png_ptr->flush_dist = (nrows < 0 ? 0 : nrows); -} - -/* Flush the current output buffers now */ -void PNGAPI -png_write_flush(png_structp png_ptr) -{ - int wrote_IDAT; - - png_debug(1, "in png_write_flush"); - - if (png_ptr == NULL) - return; - - /* We have already written out all of the data */ - if (png_ptr->row_number >= png_ptr->num_rows) - return; - - do - { - int ret; - - /* Compress the data */ - ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH); - wrote_IDAT = 0; - - /* Check for compression errors */ - if (ret != Z_OK) - { - if (png_ptr->zstream.msg != NULL) - png_error(png_ptr, png_ptr->zstream.msg); - - else - png_error(png_ptr, "zlib error"); - } - - if (!(png_ptr->zstream.avail_out)) - { - /* Write the IDAT and reset the zlib output buffer */ - png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); - wrote_IDAT = 1; - } - } while (wrote_IDAT == 1); - - /* If there is any data left to be output, write it into a new IDAT */ - if (png_ptr->zbuf_size != png_ptr->zstream.avail_out) - { - /* Write the IDAT and reset the zlib output buffer */ - png_write_IDAT(png_ptr, png_ptr->zbuf, - png_ptr->zbuf_size - png_ptr->zstream.avail_out); - } - png_ptr->flush_rows = 0; - png_flush(png_ptr); -} -#endif /* PNG_WRITE_FLUSH_SUPPORTED */ - -/* Free all memory used by the write */ -void PNGAPI -png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) -{ - png_structp png_ptr = NULL; - png_infop info_ptr = NULL; -#ifdef PNG_USER_MEM_SUPPORTED - png_free_ptr free_fn = NULL; - png_voidp mem_ptr = NULL; -#endif - - png_debug(1, "in png_destroy_write_struct"); - - if (png_ptr_ptr != NULL) - png_ptr = *png_ptr_ptr; - -#ifdef PNG_USER_MEM_SUPPORTED - if (png_ptr != NULL) - { - free_fn = png_ptr->free_fn; - mem_ptr = png_ptr->mem_ptr; - } -#endif - - if (info_ptr_ptr != NULL) - info_ptr = *info_ptr_ptr; - - if (info_ptr != NULL) - { - if (png_ptr != NULL) - { - png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); - -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED - if (png_ptr->num_chunk_list) - { - png_free(png_ptr, png_ptr->chunk_list); - png_ptr->num_chunk_list = 0; - } -#endif - } - -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, - (png_voidp)mem_ptr); -#else - png_destroy_struct((png_voidp)info_ptr); -#endif - *info_ptr_ptr = NULL; - } - - if (png_ptr != NULL) - { - png_write_destroy(png_ptr); -#ifdef PNG_USER_MEM_SUPPORTED - png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, - (png_voidp)mem_ptr); -#else - png_destroy_struct((png_voidp)png_ptr); -#endif - *png_ptr_ptr = NULL; - } -} - - -/* Free any memory used in png_ptr struct (old method) */ -void /* PRIVATE */ -png_write_destroy(png_structp png_ptr) -{ -#ifdef PNG_SETJMP_SUPPORTED - jmp_buf tmp_jmp; /* Save jump buffer */ -#endif - png_error_ptr error_fn; -#ifdef PNG_WARNINGS_SUPPORTED - png_error_ptr warning_fn; -#endif - png_voidp error_ptr; -#ifdef PNG_USER_MEM_SUPPORTED - png_free_ptr free_fn; -#endif - - png_debug(1, "in png_write_destroy"); - - /* Free any memory zlib uses */ - if (png_ptr->zlib_state != PNG_ZLIB_UNINITIALIZED) - deflateEnd(&png_ptr->zstream); - - /* Free our memory. png_free checks NULL for us. */ - png_free(png_ptr, png_ptr->zbuf); - png_free(png_ptr, png_ptr->row_buf); -#ifdef PNG_WRITE_FILTER_SUPPORTED - png_free(png_ptr, png_ptr->prev_row); - png_free(png_ptr, png_ptr->sub_row); - png_free(png_ptr, png_ptr->up_row); - png_free(png_ptr, png_ptr->avg_row); - png_free(png_ptr, png_ptr->paeth_row); -#endif - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - /* Use this to save a little code space, it doesn't free the filter_costs */ - png_reset_filter_heuristics(png_ptr); - png_free(png_ptr, png_ptr->filter_costs); - png_free(png_ptr, png_ptr->inv_filter_costs); -#endif - -#ifdef PNG_SETJMP_SUPPORTED - /* Reset structure */ - png_memcpy(tmp_jmp, png_ptr->longjmp_buffer, png_sizeof(jmp_buf)); -#endif - - error_fn = png_ptr->error_fn; -#ifdef PNG_WARNINGS_SUPPORTED - warning_fn = png_ptr->warning_fn; -#endif - error_ptr = png_ptr->error_ptr; -#ifdef PNG_USER_MEM_SUPPORTED - free_fn = png_ptr->free_fn; -#endif - - png_memset(png_ptr, 0, png_sizeof(png_struct)); - - png_ptr->error_fn = error_fn; -#ifdef PNG_WARNINGS_SUPPORTED - png_ptr->warning_fn = warning_fn; -#endif - png_ptr->error_ptr = error_ptr; -#ifdef PNG_USER_MEM_SUPPORTED - png_ptr->free_fn = free_fn; -#endif - -#ifdef PNG_SETJMP_SUPPORTED - png_memcpy(png_ptr->longjmp_buffer, tmp_jmp, png_sizeof(jmp_buf)); -#endif -} - -/* Allow the application to select one or more row filters to use. */ -void PNGAPI -png_set_filter(png_structp png_ptr, int method, int filters) -{ - png_debug(1, "in png_set_filter"); - - if (png_ptr == NULL) - return; - -#ifdef PNG_MNG_FEATURES_SUPPORTED - if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && - (method == PNG_INTRAPIXEL_DIFFERENCING)) - method = PNG_FILTER_TYPE_BASE; - -#endif - if (method == PNG_FILTER_TYPE_BASE) - { - switch (filters & (PNG_ALL_FILTERS | 0x07)) - { -#ifdef PNG_WRITE_FILTER_SUPPORTED - case 5: - case 6: - case 7: png_warning(png_ptr, "Unknown row filter for method 0"); -#endif /* PNG_WRITE_FILTER_SUPPORTED */ - case PNG_FILTER_VALUE_NONE: - png_ptr->do_filter = PNG_FILTER_NONE; break; - -#ifdef PNG_WRITE_FILTER_SUPPORTED - case PNG_FILTER_VALUE_SUB: - png_ptr->do_filter = PNG_FILTER_SUB; break; - - case PNG_FILTER_VALUE_UP: - png_ptr->do_filter = PNG_FILTER_UP; break; - - case PNG_FILTER_VALUE_AVG: - png_ptr->do_filter = PNG_FILTER_AVG; break; - - case PNG_FILTER_VALUE_PAETH: - png_ptr->do_filter = PNG_FILTER_PAETH; break; - - default: - png_ptr->do_filter = (png_byte)filters; break; -#else - default: - png_warning(png_ptr, "Unknown row filter for method 0"); -#endif /* PNG_WRITE_FILTER_SUPPORTED */ - } - - /* If we have allocated the row_buf, this means we have already started - * with the image and we should have allocated all of the filter buffers - * that have been selected. If prev_row isn't already allocated, then - * it is too late to start using the filters that need it, since we - * will be missing the data in the previous row. If an application - * wants to start and stop using particular filters during compression, - * it should start out with all of the filters, and then add and - * remove them after the start of compression. - */ - if (png_ptr->row_buf != NULL) - { -#ifdef PNG_WRITE_FILTER_SUPPORTED - if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL) - { - png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, - (png_ptr->rowbytes + 1)); - png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; - } - - if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL) - { - if (png_ptr->prev_row == NULL) - { - png_warning(png_ptr, "Can't add Up filter after starting"); - png_ptr->do_filter = (png_byte)(png_ptr->do_filter & - ~PNG_FILTER_UP); - } - - else - { - png_ptr->up_row = (png_bytep)png_malloc(png_ptr, - (png_ptr->rowbytes + 1)); - png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; - } - } - - if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL) - { - if (png_ptr->prev_row == NULL) - { - png_warning(png_ptr, "Can't add Average filter after starting"); - png_ptr->do_filter = (png_byte)(png_ptr->do_filter & - ~PNG_FILTER_AVG); - } - - else - { - png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, - (png_ptr->rowbytes + 1)); - png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; - } - } - - if ((png_ptr->do_filter & PNG_FILTER_PAETH) && - png_ptr->paeth_row == NULL) - { - if (png_ptr->prev_row == NULL) - { - png_warning(png_ptr, "Can't add Paeth filter after starting"); - png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH); - } - - else - { - png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, - (png_ptr->rowbytes + 1)); - png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; - } - } - - if (png_ptr->do_filter == PNG_NO_FILTERS) -#endif /* PNG_WRITE_FILTER_SUPPORTED */ - png_ptr->do_filter = PNG_FILTER_NONE; - } - } - else - png_error(png_ptr, "Unknown custom filter method"); -} - -/* This allows us to influence the way in which libpng chooses the "best" - * filter for the current scanline. While the "minimum-sum-of-absolute- - * differences metric is relatively fast and effective, there is some - * question as to whether it can be improved upon by trying to keep the - * filtered data going to zlib more consistent, hopefully resulting in - * better compression. - */ -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* GRR 970116 */ -/* Convenience reset API. */ -static void -png_reset_filter_heuristics(png_structp png_ptr) -{ - /* Clear out any old values in the 'weights' - this must be done because if - * the app calls set_filter_heuristics multiple times with different - * 'num_weights' values we would otherwise potentially have wrong sized - * arrays. - */ - png_ptr->num_prev_filters = 0; - png_ptr->heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED; - if (png_ptr->prev_filters != NULL) - { - png_bytep old = png_ptr->prev_filters; - png_ptr->prev_filters = NULL; - png_free(png_ptr, old); - } - if (png_ptr->filter_weights != NULL) - { - png_uint_16p old = png_ptr->filter_weights; - png_ptr->filter_weights = NULL; - png_free(png_ptr, old); - } - - if (png_ptr->inv_filter_weights != NULL) - { - png_uint_16p old = png_ptr->inv_filter_weights; - png_ptr->inv_filter_weights = NULL; - png_free(png_ptr, old); - } - - /* Leave the filter_costs - this array is fixed size. */ -} - -static int -png_init_filter_heuristics(png_structp png_ptr, int heuristic_method, - int num_weights) -{ - if (png_ptr == NULL) - return 0; - - /* Clear out the arrays */ - png_reset_filter_heuristics(png_ptr); - - /* Check arguments; the 'reset' function makes the correct settings for the - * unweighted case, but we must handle the weight case by initializing the - * arrays for the caller. - */ - if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int i; - - if (num_weights > 0) - { - png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr, - (png_uint_32)(png_sizeof(png_byte) * num_weights)); - - /* To make sure that the weighting starts out fairly */ - for (i = 0; i < num_weights; i++) - { - png_ptr->prev_filters[i] = 255; - } - - png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr, - (png_uint_32)(png_sizeof(png_uint_16) * num_weights)); - - png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr, - (png_uint_32)(png_sizeof(png_uint_16) * num_weights)); - - for (i = 0; i < num_weights; i++) - { - png_ptr->inv_filter_weights[i] = - png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; - } - - /* Safe to set this now */ - png_ptr->num_prev_filters = (png_byte)num_weights; - } - - /* If, in the future, there are other filter methods, this would - * need to be based on png_ptr->filter. - */ - if (png_ptr->filter_costs == NULL) - { - png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr, - (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); - - png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr, - (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); - } - - for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) - { - png_ptr->inv_filter_costs[i] = - png_ptr->filter_costs[i] = PNG_COST_FACTOR; - } - - /* All the arrays are inited, safe to set this: */ - png_ptr->heuristic_method = PNG_FILTER_HEURISTIC_WEIGHTED; - - /* Return the 'ok' code. */ - return 1; - } - else if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT || - heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED) - { - return 1; - } - else - { - png_warning(png_ptr, "Unknown filter heuristic method"); - return 0; - } -} - -/* Provide floating and fixed point APIs */ -#ifdef PNG_FLOATING_POINT_SUPPORTED -void PNGAPI -png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, - int num_weights, png_const_doublep filter_weights, - png_const_doublep filter_costs) -{ - png_debug(1, "in png_set_filter_heuristics"); - - /* The internal API allocates all the arrays and ensures that the elements of - * those arrays are set to the default value. - */ - if (!png_init_filter_heuristics(png_ptr, heuristic_method, num_weights)) - return; - - /* If using the weighted method copy in the weights. */ - if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int i; - for (i = 0; i < num_weights; i++) - { - if (filter_weights[i] <= 0.0) - { - png_ptr->inv_filter_weights[i] = - png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; - } - - else - { - png_ptr->inv_filter_weights[i] = - (png_uint_16)(PNG_WEIGHT_FACTOR*filter_weights[i]+.5); - - png_ptr->filter_weights[i] = - (png_uint_16)(PNG_WEIGHT_FACTOR/filter_weights[i]+.5); - } - } - - /* Here is where we set the relative costs of the different filters. We - * should take the desired compression level into account when setting - * the costs, so that Paeth, for instance, has a high relative cost at low - * compression levels, while it has a lower relative cost at higher - * compression settings. The filter types are in order of increasing - * relative cost, so it would be possible to do this with an algorithm. - */ - for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) if (filter_costs[i] >= 1.0) - { - png_ptr->inv_filter_costs[i] = - (png_uint_16)(PNG_COST_FACTOR / filter_costs[i] + .5); - - png_ptr->filter_costs[i] = - (png_uint_16)(PNG_COST_FACTOR * filter_costs[i] + .5); - } - } -} -#endif /* FLOATING_POINT */ - -#ifdef PNG_FIXED_POINT_SUPPORTED -void PNGAPI -png_set_filter_heuristics_fixed(png_structp png_ptr, int heuristic_method, - int num_weights, png_const_fixed_point_p filter_weights, - png_const_fixed_point_p filter_costs) -{ - png_debug(1, "in png_set_filter_heuristics_fixed"); - - /* The internal API allocates all the arrays and ensures that the elements of - * those arrays are set to the default value. - */ - if (!png_init_filter_heuristics(png_ptr, heuristic_method, num_weights)) - return; - - /* If using the weighted method copy in the weights. */ - if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int i; - for (i = 0; i < num_weights; i++) - { - if (filter_weights[i] <= 0) - { - png_ptr->inv_filter_weights[i] = - png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; - } - - else - { - png_ptr->inv_filter_weights[i] = (png_uint_16) - ((PNG_WEIGHT_FACTOR*filter_weights[i]+PNG_FP_HALF)/PNG_FP_1); - - png_ptr->filter_weights[i] = (png_uint_16)((PNG_WEIGHT_FACTOR* - PNG_FP_1+(filter_weights[i]/2))/filter_weights[i]); - } - } - - /* Here is where we set the relative costs of the different filters. We - * should take the desired compression level into account when setting - * the costs, so that Paeth, for instance, has a high relative cost at low - * compression levels, while it has a lower relative cost at higher - * compression settings. The filter types are in order of increasing - * relative cost, so it would be possible to do this with an algorithm. - */ - for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) - if (filter_costs[i] >= PNG_FP_1) - { - png_uint_32 tmp; - - /* Use a 32 bit unsigned temporary here because otherwise the - * intermediate value will be a 32 bit *signed* integer (ANSI rules) - * and this will get the wrong answer on division. - */ - tmp = PNG_COST_FACTOR*PNG_FP_1 + (filter_costs[i]/2); - tmp /= filter_costs[i]; - - png_ptr->inv_filter_costs[i] = (png_uint_16)tmp; - - tmp = PNG_COST_FACTOR * filter_costs[i] + PNG_FP_HALF; - tmp /= PNG_FP_1; - - png_ptr->filter_costs[i] = (png_uint_16)tmp; - } - } -} -#endif /* FIXED_POINT */ -#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ - -void PNGAPI -png_set_compression_level(png_structp png_ptr, int level) -{ - png_debug(1, "in png_set_compression_level"); - - if (png_ptr == NULL) - return; - - png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL; - png_ptr->zlib_level = level; -} - -void PNGAPI -png_set_compression_mem_level(png_structp png_ptr, int mem_level) -{ - png_debug(1, "in png_set_compression_mem_level"); - - if (png_ptr == NULL) - return; - - png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL; - png_ptr->zlib_mem_level = mem_level; -} - -void PNGAPI -png_set_compression_strategy(png_structp png_ptr, int strategy) -{ - png_debug(1, "in png_set_compression_strategy"); - - if (png_ptr == NULL) - return; - - png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY; - png_ptr->zlib_strategy = strategy; -} - -/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a - * smaller value of window_bits if it can do so safely. - */ -void PNGAPI -png_set_compression_window_bits(png_structp png_ptr, int window_bits) -{ - if (png_ptr == NULL) - return; - - if (window_bits > 15) - png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); - - else if (window_bits < 8) - png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); - -#ifndef WBITS_8_OK - /* Avoid libpng bug with 256-byte windows */ - if (window_bits == 8) - { - png_warning(png_ptr, "Compression window is being reset to 512"); - window_bits = 9; - } - -#endif - png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS; - png_ptr->zlib_window_bits = window_bits; -} - -void PNGAPI -png_set_compression_method(png_structp png_ptr, int method) -{ - png_debug(1, "in png_set_compression_method"); - - if (png_ptr == NULL) - return; - - if (method != 8) - png_warning(png_ptr, "Only compression method 8 is supported by PNG"); - - png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD; - png_ptr->zlib_method = method; -} - -/* The following were added to libpng-1.5.4 */ -#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED -void PNGAPI -png_set_text_compression_level(png_structp png_ptr, int level) -{ - png_debug(1, "in png_set_text_compression_level"); - - if (png_ptr == NULL) - return; - - png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_LEVEL; - png_ptr->zlib_text_level = level; -} - -void PNGAPI -png_set_text_compression_mem_level(png_structp png_ptr, int mem_level) -{ - png_debug(1, "in png_set_text_compression_mem_level"); - - if (png_ptr == NULL) - return; - - png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL; - png_ptr->zlib_text_mem_level = mem_level; -} - -void PNGAPI -png_set_text_compression_strategy(png_structp png_ptr, int strategy) -{ - png_debug(1, "in png_set_text_compression_strategy"); - - if (png_ptr == NULL) - return; - - png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_STRATEGY; - png_ptr->zlib_text_strategy = strategy; -} - -/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a - * smaller value of window_bits if it can do so safely. - */ -void PNGAPI -png_set_text_compression_window_bits(png_structp png_ptr, int window_bits) -{ - if (png_ptr == NULL) - return; - - if (window_bits > 15) - png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); - - else if (window_bits < 8) - png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); - -#ifndef WBITS_8_OK - /* Avoid libpng bug with 256-byte windows */ - if (window_bits == 8) - { - png_warning(png_ptr, "Text compression window is being reset to 512"); - window_bits = 9; - } - -#endif - png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS; - png_ptr->zlib_text_window_bits = window_bits; -} - -void PNGAPI -png_set_text_compression_method(png_structp png_ptr, int method) -{ - png_debug(1, "in png_set_text_compression_method"); - - if (png_ptr == NULL) - return; - - if (method != 8) - png_warning(png_ptr, "Only compression method 8 is supported by PNG"); - - png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_METHOD; - png_ptr->zlib_text_method = method; -} -#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */ -/* end of API added to libpng-1.5.4 */ - -void PNGAPI -png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn) -{ - if (png_ptr == NULL) - return; - - png_ptr->write_row_fn = write_row_fn; -} - -#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED -void PNGAPI -png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr - write_user_transform_fn) -{ - png_debug(1, "in png_set_write_user_transform_fn"); - - if (png_ptr == NULL) - return; - - png_ptr->transformations |= PNG_USER_TRANSFORM; - png_ptr->write_user_transform_fn = write_user_transform_fn; -} -#endif - - -#ifdef PNG_INFO_IMAGE_SUPPORTED -void PNGAPI -png_write_png(png_structp png_ptr, png_infop info_ptr, - int transforms, voidp params) -{ - if (png_ptr == NULL || info_ptr == NULL) - return; - - /* Write the file header information. */ - png_write_info(png_ptr, info_ptr); - - /* ------ these transformations don't touch the info structure ------- */ - -#ifdef PNG_WRITE_INVERT_SUPPORTED - /* Invert monochrome pixels */ - if (transforms & PNG_TRANSFORM_INVERT_MONO) - png_set_invert_mono(png_ptr); -#endif - -#ifdef PNG_WRITE_SHIFT_SUPPORTED - /* Shift the pixels up to a legal bit depth and fill in - * as appropriate to correctly scale the image. - */ - if ((transforms & PNG_TRANSFORM_SHIFT) - && (info_ptr->valid & PNG_INFO_sBIT)) - png_set_shift(png_ptr, &info_ptr->sig_bit); -#endif - -#ifdef PNG_WRITE_PACK_SUPPORTED - /* Pack pixels into bytes */ - if (transforms & PNG_TRANSFORM_PACKING) - png_set_packing(png_ptr); -#endif - -#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED - /* Swap location of alpha bytes from ARGB to RGBA */ - if (transforms & PNG_TRANSFORM_SWAP_ALPHA) - png_set_swap_alpha(png_ptr); -#endif - -#ifdef PNG_WRITE_FILLER_SUPPORTED - /* Pack XRGB/RGBX/ARGB/RGBA into RGB (4 channels -> 3 channels) */ - if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) - png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); - - else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) - png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); -#endif - -#ifdef PNG_WRITE_BGR_SUPPORTED - /* Flip BGR pixels to RGB */ - if (transforms & PNG_TRANSFORM_BGR) - png_set_bgr(png_ptr); -#endif - -#ifdef PNG_WRITE_SWAP_SUPPORTED - /* Swap bytes of 16-bit files to most significant byte first */ - if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) - png_set_swap(png_ptr); -#endif - -#ifdef PNG_WRITE_PACKSWAP_SUPPORTED - /* Swap bits of 1, 2, 4 bit packed pixel formats */ - if (transforms & PNG_TRANSFORM_PACKSWAP) - png_set_packswap(png_ptr); -#endif - -#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED - /* Invert the alpha channel from opacity to transparency */ - if (transforms & PNG_TRANSFORM_INVERT_ALPHA) - png_set_invert_alpha(png_ptr); -#endif - - /* ----------------------- end of transformations ------------------- */ - - /* Write the bits */ - if (info_ptr->valid & PNG_INFO_IDAT) - png_write_image(png_ptr, info_ptr->row_pointers); - - /* It is REQUIRED to call this to finish writing the rest of the file */ - png_write_end(png_ptr, info_ptr); - - PNG_UNUSED(transforms) /* Quiet compiler warnings */ - PNG_UNUSED(params) -} -#endif -#endif /* PNG_WRITE_SUPPORTED */ + +/* pngwrite.c - general routines to write a PNG file + * + * Last changed in libpng 1.5.11 [June 14, 2012] + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "pngpriv.h" + +#ifdef PNG_WRITE_SUPPORTED + +/* Writes all the PNG information. This is the suggested way to use the + * library. If you have a new chunk to add, make a function to write it, + * and put it in the correct location here. If you want the chunk written + * after the image data, put it in png_write_end(). I strongly encourage + * you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing + * the chunk, as that will keep the code from breaking if you want to just + * write a plain PNG file. If you have long comments, I suggest writing + * them in png_write_end(), and compressing them. + */ +void PNGAPI +png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_write_info_before_PLTE"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) + { + /* Write PNG signature */ + png_write_sig(png_ptr); + +#ifdef PNG_MNG_FEATURES_SUPPORTED + if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) && \ + (png_ptr->mng_features_permitted)) + { + png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); + png_ptr->mng_features_permitted = 0; + } +#endif + + /* Write IHDR information. */ + png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, + info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, + info_ptr->filter_type, +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + info_ptr->interlace_type); +#else + 0); +#endif + /* The rest of these check to see if the valid field has the appropriate + * flag set, and if it does, writes the chunk. + */ +#ifdef PNG_WRITE_gAMA_SUPPORTED + if (info_ptr->valid & PNG_INFO_gAMA) + png_write_gAMA_fixed(png_ptr, info_ptr->gamma); +#endif +#ifdef PNG_WRITE_sRGB_SUPPORTED + if (info_ptr->valid & PNG_INFO_sRGB) + png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent); +#endif + +#ifdef PNG_WRITE_iCCP_SUPPORTED + if (info_ptr->valid & PNG_INFO_iCCP) + png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE, + (png_charp)info_ptr->iccp_profile, (int)info_ptr->iccp_proflen); +#endif +#ifdef PNG_WRITE_sBIT_SUPPORTED + if (info_ptr->valid & PNG_INFO_sBIT) + png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type); +#endif +#ifdef PNG_WRITE_cHRM_SUPPORTED + if (info_ptr->valid & PNG_INFO_cHRM) + png_write_cHRM_fixed(png_ptr, + info_ptr->x_white, info_ptr->y_white, + info_ptr->x_red, info_ptr->y_red, + info_ptr->x_green, info_ptr->y_green, + info_ptr->x_blue, info_ptr->y_blue); +#endif + +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + if (info_ptr->unknown_chunks_num) + { + png_unknown_chunk *up; + + png_debug(5, "writing extra chunks"); + + for (up = info_ptr->unknown_chunks; + up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; + up++) + { + int keep = png_handle_as_unknown(png_ptr, up->name); + + if (keep != PNG_HANDLE_CHUNK_NEVER && + up->location && + !(up->location & PNG_HAVE_PLTE) && + !(up->location & PNG_HAVE_IDAT) && + !(up->location & PNG_AFTER_IDAT) && + ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || + (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) + { + if (up->size == 0) + png_warning(png_ptr, "Writing zero-length unknown chunk"); + + png_write_chunk(png_ptr, up->name, up->data, up->size); + } + } + } +#endif + png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE; + } +} + +void PNGAPI +png_write_info(png_structp png_ptr, png_infop info_ptr) +{ +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) + int i; +#endif + + png_debug(1, "in png_write_info"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_write_info_before_PLTE(png_ptr, info_ptr); + + if (info_ptr->valid & PNG_INFO_PLTE) + png_write_PLTE(png_ptr, info_ptr->palette, + (png_uint_32)info_ptr->num_palette); + + else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + png_error(png_ptr, "Valid palette required for paletted images"); + +#ifdef PNG_WRITE_tRNS_SUPPORTED + if (info_ptr->valid & PNG_INFO_tRNS) + { +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED + /* Invert the alpha channel (in tRNS) */ + if ((png_ptr->transformations & PNG_INVERT_ALPHA) && + info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + int j; + for (j = 0; j<(int)info_ptr->num_trans; j++) + info_ptr->trans_alpha[j] = + (png_byte)(255 - info_ptr->trans_alpha[j]); + } +#endif + png_write_tRNS(png_ptr, info_ptr->trans_alpha, &(info_ptr->trans_color), + info_ptr->num_trans, info_ptr->color_type); + } +#endif +#ifdef PNG_WRITE_bKGD_SUPPORTED + if (info_ptr->valid & PNG_INFO_bKGD) + png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type); +#endif + +#ifdef PNG_WRITE_hIST_SUPPORTED + if (info_ptr->valid & PNG_INFO_hIST) + png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette); +#endif + +#ifdef PNG_WRITE_oFFs_SUPPORTED + if (info_ptr->valid & PNG_INFO_oFFs) + png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset, + info_ptr->offset_unit_type); +#endif + +#ifdef PNG_WRITE_pCAL_SUPPORTED + if (info_ptr->valid & PNG_INFO_pCAL) + png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0, + info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams, + info_ptr->pcal_units, info_ptr->pcal_params); +#endif + +#ifdef PNG_WRITE_sCAL_SUPPORTED + if (info_ptr->valid & PNG_INFO_sCAL) + png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit, + info_ptr->scal_s_width, info_ptr->scal_s_height); +#endif /* sCAL */ + +#ifdef PNG_WRITE_pHYs_SUPPORTED + if (info_ptr->valid & PNG_INFO_pHYs) + png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit, + info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type); +#endif /* pHYs */ + +#ifdef PNG_WRITE_tIME_SUPPORTED + if (info_ptr->valid & PNG_INFO_tIME) + { + png_write_tIME(png_ptr, &(info_ptr->mod_time)); + png_ptr->mode |= PNG_WROTE_tIME; + } +#endif /* tIME */ + +#ifdef PNG_WRITE_sPLT_SUPPORTED + if (info_ptr->valid & PNG_INFO_sPLT) + for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) + png_write_sPLT(png_ptr, info_ptr->splt_palettes + i); +#endif /* sPLT */ + +#ifdef PNG_WRITE_TEXT_SUPPORTED + /* Check to see if we need to write text chunks */ + for (i = 0; i < info_ptr->num_text; i++) + { + png_debug2(2, "Writing header text chunk %d, type %d", i, + info_ptr->text[i].compression); + /* An internationalized chunk? */ + if (info_ptr->text[i].compression > 0) + { +#ifdef PNG_WRITE_iTXt_SUPPORTED + /* Write international chunk */ + png_write_iTXt(png_ptr, + info_ptr->text[i].compression, + info_ptr->text[i].key, + info_ptr->text[i].lang, + info_ptr->text[i].lang_key, + info_ptr->text[i].text); +#else + png_warning(png_ptr, "Unable to write international text"); +#endif + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + } + + /* If we want a compressed text chunk */ + else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt) + { +#ifdef PNG_WRITE_zTXt_SUPPORTED + /* Write compressed chunk */ + png_write_zTXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, 0, + info_ptr->text[i].compression); +#else + png_warning(png_ptr, "Unable to write compressed text"); +#endif + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; + } + + else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) + { +#ifdef PNG_WRITE_tEXt_SUPPORTED + /* Write uncompressed chunk */ + png_write_tEXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, + 0); + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; +#else + /* Can't get here */ + png_warning(png_ptr, "Unable to write uncompressed text"); +#endif + } + } +#endif /* tEXt */ + +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + if (info_ptr->unknown_chunks_num) + { + png_unknown_chunk *up; + + png_debug(5, "writing extra chunks"); + + for (up = info_ptr->unknown_chunks; + up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; + up++) + { + int keep = png_handle_as_unknown(png_ptr, up->name); + if (keep != PNG_HANDLE_CHUNK_NEVER && + up->location && + (up->location & PNG_HAVE_PLTE) && + !(up->location & PNG_HAVE_IDAT) && + !(up->location & PNG_AFTER_IDAT) && + ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || + (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) + { + png_write_chunk(png_ptr, up->name, up->data, up->size); + } + } + } +#endif +} + +/* Writes the end of the PNG file. If you don't want to write comments or + * time information, you can pass NULL for info. If you already wrote these + * in png_write_info(), do not write them again here. If you have long + * comments, I suggest writing them here, and compressing them. + */ +void PNGAPI +png_write_end(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_write_end"); + + if (png_ptr == NULL) + return; + + if (!(png_ptr->mode & PNG_HAVE_IDAT)) + png_error(png_ptr, "No IDATs written into file"); + +#ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED + if (png_ptr->num_palette_max > png_ptr->num_palette) + png_benign_error(png_ptr, "Wrote palette index exceeding num_palette"); +#endif + + /* See if user wants us to write information chunks */ + if (info_ptr != NULL) + { +#ifdef PNG_WRITE_TEXT_SUPPORTED + int i; /* local index variable */ +#endif +#ifdef PNG_WRITE_tIME_SUPPORTED + /* Check to see if user has supplied a time chunk */ + if ((info_ptr->valid & PNG_INFO_tIME) && + !(png_ptr->mode & PNG_WROTE_tIME)) + png_write_tIME(png_ptr, &(info_ptr->mod_time)); + +#endif +#ifdef PNG_WRITE_TEXT_SUPPORTED + /* Loop through comment chunks */ + for (i = 0; i < info_ptr->num_text; i++) + { + png_debug2(2, "Writing trailer text chunk %d, type %d", i, + info_ptr->text[i].compression); + /* An internationalized chunk? */ + if (info_ptr->text[i].compression > 0) + { +#ifdef PNG_WRITE_iTXt_SUPPORTED + /* Write international chunk */ + png_write_iTXt(png_ptr, + info_ptr->text[i].compression, + info_ptr->text[i].key, + info_ptr->text[i].lang, + info_ptr->text[i].lang_key, + info_ptr->text[i].text); +#else + png_warning(png_ptr, "Unable to write international text"); +#endif + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + } + + else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt) + { +#ifdef PNG_WRITE_zTXt_SUPPORTED + /* Write compressed chunk */ + png_write_zTXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, 0, + info_ptr->text[i].compression); +#else + png_warning(png_ptr, "Unable to write compressed text"); +#endif + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; + } + + else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) + { +#ifdef PNG_WRITE_tEXt_SUPPORTED + /* Write uncompressed chunk */ + png_write_tEXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, 0); +#else + png_warning(png_ptr, "Unable to write uncompressed text"); +#endif + + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + } + } +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + if (info_ptr->unknown_chunks_num) + { + png_unknown_chunk *up; + + png_debug(5, "writing extra chunks"); + + for (up = info_ptr->unknown_chunks; + up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; + up++) + { + int keep = png_handle_as_unknown(png_ptr, up->name); + if (keep != PNG_HANDLE_CHUNK_NEVER && + up->location && + (up->location & PNG_AFTER_IDAT) && + ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || + (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) + { + png_write_chunk(png_ptr, up->name, up->data, up->size); + } + } + } +#endif + } + + png_ptr->mode |= PNG_AFTER_IDAT; + + /* Write end of PNG file */ + png_write_IEND(png_ptr); + /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03, + * and restored again in libpng-1.2.30, may cause some applications that + * do not set png_ptr->output_flush_fn to crash. If your application + * experiences a problem, please try building libpng with + * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to + * png-mng-implement at lists.sf.net . + */ +#ifdef PNG_WRITE_FLUSH_SUPPORTED +# ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED + png_flush(png_ptr); +# endif +#endif +} + +#ifdef PNG_CONVERT_tIME_SUPPORTED +/* "tm" structure is not supported on WindowsCE */ +void PNGAPI +png_convert_from_struct_tm(png_timep ptime, PNG_CONST struct tm FAR * ttime) +{ + png_debug(1, "in png_convert_from_struct_tm"); + + ptime->year = (png_uint_16)(1900 + ttime->tm_year); + ptime->month = (png_byte)(ttime->tm_mon + 1); + ptime->day = (png_byte)ttime->tm_mday; + ptime->hour = (png_byte)ttime->tm_hour; + ptime->minute = (png_byte)ttime->tm_min; + ptime->second = (png_byte)ttime->tm_sec; +} + +void PNGAPI +png_convert_from_time_t(png_timep ptime, time_t ttime) +{ + struct tm *tbuf; + + png_debug(1, "in png_convert_from_time_t"); + + tbuf = gmtime(&ttime); + png_convert_from_struct_tm(ptime, tbuf); +} +#endif + +/* Initialize png_ptr structure, and allocate any memory needed */ +PNG_FUNCTION(png_structp,PNGAPI +png_create_write_struct,(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED) +{ +#ifdef PNG_USER_MEM_SUPPORTED + return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn, + warn_fn, NULL, NULL, NULL)); +} + +/* Alternate initialize png_ptr structure, and allocate any memory needed */ +static void png_reset_filter_heuristics(png_structp png_ptr); /* forward decl */ + +PNG_FUNCTION(png_structp,PNGAPI +png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED) +{ +#endif /* PNG_USER_MEM_SUPPORTED */ + volatile int png_cleanup_needed = 0; +#ifdef PNG_SETJMP_SUPPORTED + volatile +#endif + png_structp png_ptr; +#ifdef PNG_SETJMP_SUPPORTED +#ifdef USE_FAR_KEYWORD + jmp_buf tmp_jmpbuf; +#endif +#endif + + png_debug(1, "in png_create_write_struct"); + +#ifdef PNG_USER_MEM_SUPPORTED + png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, + (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); +#else + png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); +#endif /* PNG_USER_MEM_SUPPORTED */ + if (png_ptr == NULL) + return (NULL); + + /* Added at libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + png_ptr->user_width_max = PNG_USER_WIDTH_MAX; + png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; +#endif + +#ifdef PNG_SETJMP_SUPPORTED +/* Applications that neglect to set up their own setjmp() and then + * encounter a png_error() will longjmp here. Since the jmpbuf is + * then meaningless we abort instead of returning. + */ +#ifdef USE_FAR_KEYWORD + if (setjmp(tmp_jmpbuf)) +#else + if (setjmp(png_jmpbuf(png_ptr))) /* sets longjmp to match setjmp */ +#endif +#ifdef USE_FAR_KEYWORD + png_memcpy(png_jmpbuf(png_ptr), tmp_jmpbuf, png_sizeof(jmp_buf)); +#endif + PNG_ABORT(); +#endif + +#ifdef PNG_USER_MEM_SUPPORTED + png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); +#endif /* PNG_USER_MEM_SUPPORTED */ + png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); + + if (!png_user_version_check(png_ptr, user_png_ver)) + png_cleanup_needed = 1; + + /* Initialize zbuf - compression buffer */ + png_ptr->zbuf_size = PNG_ZBUF_SIZE; + + if (!png_cleanup_needed) + { + png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, + png_ptr->zbuf_size); + if (png_ptr->zbuf == NULL) + png_cleanup_needed = 1; + } + + if (png_cleanup_needed) + { + /* Clean up PNG structure and deallocate any memory. */ + png_free(png_ptr, png_ptr->zbuf); + png_ptr->zbuf = NULL; +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)png_ptr, + (png_free_ptr)free_fn, (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)png_ptr); +#endif + return (NULL); + } + + png_set_write_fn(png_ptr, NULL, NULL, NULL); + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + png_reset_filter_heuristics(png_ptr); +#endif + + return (png_ptr); +} + + +/* Write a few rows of image data. If the image is interlaced, + * either you will have to write the 7 sub images, or, if you + * have called png_set_interlace_handling(), you will have to + * "write" the image seven times. + */ +void PNGAPI +png_write_rows(png_structp png_ptr, png_bytepp row, + png_uint_32 num_rows) +{ + png_uint_32 i; /* row counter */ + png_bytepp rp; /* row pointer */ + + png_debug(1, "in png_write_rows"); + + if (png_ptr == NULL) + return; + + /* Loop through the rows */ + for (i = 0, rp = row; i < num_rows; i++, rp++) + { + png_write_row(png_ptr, *rp); + } +} + +/* Write the image. You only need to call this function once, even + * if you are writing an interlaced image. + */ +void PNGAPI +png_write_image(png_structp png_ptr, png_bytepp image) +{ + png_uint_32 i; /* row index */ + int pass, num_pass; /* pass variables */ + png_bytepp rp; /* points to current row */ + + if (png_ptr == NULL) + return; + + png_debug(1, "in png_write_image"); + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* Initialize interlace handling. If image is not interlaced, + * this will set pass to 1 + */ + num_pass = png_set_interlace_handling(png_ptr); +#else + num_pass = 1; +#endif + /* Loop through passes */ + for (pass = 0; pass < num_pass; pass++) + { + /* Loop through image */ + for (i = 0, rp = image; i < png_ptr->height; i++, rp++) + { + png_write_row(png_ptr, *rp); + } + } +} + +/* Called by user to write a row of image data */ +void PNGAPI +png_write_row(png_structp png_ptr, png_const_bytep row) +{ + /* 1.5.6: moved from png_struct to be a local structure: */ + png_row_info row_info; + + if (png_ptr == NULL) + return; + + png_debug2(1, "in png_write_row (row %u, pass %d)", + png_ptr->row_number, png_ptr->pass); + + /* Initialize transformations and other stuff if first time */ + if (png_ptr->row_number == 0 && png_ptr->pass == 0) + { + /* Make sure we wrote the header info */ + if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) + png_error(png_ptr, + "png_write_info was never called before png_write_row"); + + /* Check for transforms that have been set but were defined out */ +#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED) + if (png_ptr->transformations & PNG_INVERT_MONO) + png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined"); +#endif + +#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED) + if (png_ptr->transformations & PNG_FILLER) + png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined"); +#endif +#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \ + defined(PNG_READ_PACKSWAP_SUPPORTED) + if (png_ptr->transformations & PNG_PACKSWAP) + png_warning(png_ptr, + "PNG_WRITE_PACKSWAP_SUPPORTED is not defined"); +#endif + +#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED) + if (png_ptr->transformations & PNG_PACK) + png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined"); +#endif + +#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED) + if (png_ptr->transformations & PNG_SHIFT) + png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined"); +#endif + +#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED) + if (png_ptr->transformations & PNG_BGR) + png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined"); +#endif + +#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED) + if (png_ptr->transformations & PNG_SWAP_BYTES) + png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined"); +#endif + + png_write_start_row(png_ptr); + } + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* If interlaced and not interested in row, return */ + if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) + { + switch (png_ptr->pass) + { + case 0: + if (png_ptr->row_number & 0x07) + { + png_write_finish_row(png_ptr); + return; + } + break; + + case 1: + if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) + { + png_write_finish_row(png_ptr); + return; + } + break; + + case 2: + if ((png_ptr->row_number & 0x07) != 4) + { + png_write_finish_row(png_ptr); + return; + } + break; + + case 3: + if ((png_ptr->row_number & 0x03) || png_ptr->width < 3) + { + png_write_finish_row(png_ptr); + return; + } + break; + + case 4: + if ((png_ptr->row_number & 0x03) != 2) + { + png_write_finish_row(png_ptr); + return; + } + break; + + case 5: + if ((png_ptr->row_number & 0x01) || png_ptr->width < 2) + { + png_write_finish_row(png_ptr); + return; + } + break; + + case 6: + if (!(png_ptr->row_number & 0x01)) + { + png_write_finish_row(png_ptr); + return; + } + break; + + default: /* error: ignore it */ + break; + } + } +#endif + + /* Set up row info for transformations */ + row_info.color_type = png_ptr->color_type; + row_info.width = png_ptr->usr_width; + row_info.channels = png_ptr->usr_channels; + row_info.bit_depth = png_ptr->usr_bit_depth; + row_info.pixel_depth = (png_byte)(row_info.bit_depth * row_info.channels); + row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); + + png_debug1(3, "row_info->color_type = %d", row_info.color_type); + png_debug1(3, "row_info->width = %u", row_info.width); + png_debug1(3, "row_info->channels = %d", row_info.channels); + png_debug1(3, "row_info->bit_depth = %d", row_info.bit_depth); + png_debug1(3, "row_info->pixel_depth = %d", row_info.pixel_depth); + png_debug1(3, "row_info->rowbytes = %lu", (unsigned long)row_info.rowbytes); + + /* Copy user's row into buffer, leaving room for filter byte. */ + png_memcpy(png_ptr->row_buf + 1, row, row_info.rowbytes); + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* Handle interlacing */ + if (png_ptr->interlaced && png_ptr->pass < 6 && + (png_ptr->transformations & PNG_INTERLACE)) + { + png_do_write_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass); + /* This should always get caught above, but still ... */ + if (!(row_info.width)) + { + png_write_finish_row(png_ptr); + return; + } + } +#endif + +#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED + /* Handle other transformations */ + if (png_ptr->transformations) + png_do_write_transformations(png_ptr, &row_info); +#endif + + /* At this point the row_info pixel depth must match the 'transformed' depth, + * which is also the output depth. + */ + if (row_info.pixel_depth != png_ptr->pixel_depth || + row_info.pixel_depth != png_ptr->transformed_pixel_depth) + png_error(png_ptr, "internal write transform logic error"); + +#ifdef PNG_MNG_FEATURES_SUPPORTED + /* Write filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not write a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ + if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) + { + /* Intrapixel differencing */ + png_do_write_intrapixel(&row_info, png_ptr->row_buf + 1); + } +#endif + +/* Added at libpng-1.5.10 */ +#ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED + /* Check for out-of-range palette index */ + if (row_info.color_type == PNG_COLOR_TYPE_PALETTE && + png_ptr->num_palette_max >= 0) + png_do_check_palette_indexes(png_ptr, &row_info); +#endif + + /* Find a filter if necessary, filter the row and write it out. */ + png_write_find_filter(png_ptr, &row_info); + + if (png_ptr->write_row_fn != NULL) + (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); +} + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +/* Set the automatic flush interval or 0 to turn flushing off */ +void PNGAPI +png_set_flush(png_structp png_ptr, int nrows) +{ + png_debug(1, "in png_set_flush"); + + if (png_ptr == NULL) + return; + + png_ptr->flush_dist = (nrows < 0 ? 0 : nrows); +} + +/* Flush the current output buffers now */ +void PNGAPI +png_write_flush(png_structp png_ptr) +{ + int wrote_IDAT; + + png_debug(1, "in png_write_flush"); + + if (png_ptr == NULL) + return; + + /* We have already written out all of the data */ + if (png_ptr->row_number >= png_ptr->num_rows) + return; + + do + { + int ret; + + /* Compress the data */ + ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH); + wrote_IDAT = 0; + + /* Check for compression errors */ + if (ret != Z_OK) + { + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + + else + png_error(png_ptr, "zlib error"); + } + + if (!(png_ptr->zstream.avail_out)) + { + /* Write the IDAT and reset the zlib output buffer */ + png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); + wrote_IDAT = 1; + } + } while (wrote_IDAT == 1); + + /* If there is any data left to be output, write it into a new IDAT */ + if (png_ptr->zbuf_size != png_ptr->zstream.avail_out) + { + /* Write the IDAT and reset the zlib output buffer */ + png_write_IDAT(png_ptr, png_ptr->zbuf, + png_ptr->zbuf_size - png_ptr->zstream.avail_out); + } + png_ptr->flush_rows = 0; + png_flush(png_ptr); +} +#endif /* PNG_WRITE_FLUSH_SUPPORTED */ + +/* Free all memory used by the write */ +void PNGAPI +png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) +{ + png_structp png_ptr = NULL; + png_infop info_ptr = NULL; +#ifdef PNG_USER_MEM_SUPPORTED + png_free_ptr free_fn = NULL; + png_voidp mem_ptr = NULL; +#endif + + png_debug(1, "in png_destroy_write_struct"); + + if (png_ptr_ptr != NULL) + png_ptr = *png_ptr_ptr; + +#ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr != NULL) + { + free_fn = png_ptr->free_fn; + mem_ptr = png_ptr->mem_ptr; + } +#endif + + if (info_ptr_ptr != NULL) + info_ptr = *info_ptr_ptr; + + if (info_ptr != NULL) + { + if (png_ptr != NULL) + { + png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + if (png_ptr->num_chunk_list) + { + png_free(png_ptr, png_ptr->chunk_list); + png_ptr->num_chunk_list = 0; + } +#endif + } + +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)info_ptr); +#endif + *info_ptr_ptr = NULL; + } + + if (png_ptr != NULL) + { + png_write_destroy(png_ptr); +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)png_ptr); +#endif + *png_ptr_ptr = NULL; + } +} + + +/* Free any memory used in png_ptr struct (old method) */ +void /* PRIVATE */ +png_write_destroy(png_structp png_ptr) +{ +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf tmp_jmp; /* Save jump buffer */ +#endif + png_error_ptr error_fn; +#ifdef PNG_WARNINGS_SUPPORTED + png_error_ptr warning_fn; +#endif + png_voidp error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + png_free_ptr free_fn; +#endif + + png_debug(1, "in png_write_destroy"); + + /* Free any memory zlib uses */ + if (png_ptr->zlib_state != PNG_ZLIB_UNINITIALIZED) + deflateEnd(&png_ptr->zstream); + + /* Free our memory. png_free checks NULL for us. */ + png_free(png_ptr, png_ptr->zbuf); + png_free(png_ptr, png_ptr->row_buf); +#ifdef PNG_WRITE_FILTER_SUPPORTED + png_free(png_ptr, png_ptr->prev_row); + png_free(png_ptr, png_ptr->sub_row); + png_free(png_ptr, png_ptr->up_row); + png_free(png_ptr, png_ptr->avg_row); + png_free(png_ptr, png_ptr->paeth_row); +#endif + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + /* Use this to save a little code space, it doesn't free the filter_costs */ + png_reset_filter_heuristics(png_ptr); + png_free(png_ptr, png_ptr->filter_costs); + png_free(png_ptr, png_ptr->inv_filter_costs); +#endif + +#ifdef PNG_SETJMP_SUPPORTED + /* Reset structure */ + png_memcpy(tmp_jmp, png_ptr->longjmp_buffer, png_sizeof(jmp_buf)); +#endif + + error_fn = png_ptr->error_fn; +#ifdef PNG_WARNINGS_SUPPORTED + warning_fn = png_ptr->warning_fn; +#endif + error_ptr = png_ptr->error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + free_fn = png_ptr->free_fn; +#endif + + png_memset(png_ptr, 0, png_sizeof(png_struct)); + + png_ptr->error_fn = error_fn; +#ifdef PNG_WARNINGS_SUPPORTED + png_ptr->warning_fn = warning_fn; +#endif + png_ptr->error_ptr = error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + png_ptr->free_fn = free_fn; +#endif + +#ifdef PNG_SETJMP_SUPPORTED + png_memcpy(png_ptr->longjmp_buffer, tmp_jmp, png_sizeof(jmp_buf)); +#endif +} + +/* Allow the application to select one or more row filters to use. */ +void PNGAPI +png_set_filter(png_structp png_ptr, int method, int filters) +{ + png_debug(1, "in png_set_filter"); + + if (png_ptr == NULL) + return; + +#ifdef PNG_MNG_FEATURES_SUPPORTED + if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + (method == PNG_INTRAPIXEL_DIFFERENCING)) + method = PNG_FILTER_TYPE_BASE; + +#endif + if (method == PNG_FILTER_TYPE_BASE) + { + switch (filters & (PNG_ALL_FILTERS | 0x07)) + { +#ifdef PNG_WRITE_FILTER_SUPPORTED + case 5: + case 6: + case 7: png_warning(png_ptr, "Unknown row filter for method 0"); +#endif /* PNG_WRITE_FILTER_SUPPORTED */ + case PNG_FILTER_VALUE_NONE: + png_ptr->do_filter = PNG_FILTER_NONE; break; + +#ifdef PNG_WRITE_FILTER_SUPPORTED + case PNG_FILTER_VALUE_SUB: + png_ptr->do_filter = PNG_FILTER_SUB; break; + + case PNG_FILTER_VALUE_UP: + png_ptr->do_filter = PNG_FILTER_UP; break; + + case PNG_FILTER_VALUE_AVG: + png_ptr->do_filter = PNG_FILTER_AVG; break; + + case PNG_FILTER_VALUE_PAETH: + png_ptr->do_filter = PNG_FILTER_PAETH; break; + + default: + png_ptr->do_filter = (png_byte)filters; break; +#else + default: + png_warning(png_ptr, "Unknown row filter for method 0"); +#endif /* PNG_WRITE_FILTER_SUPPORTED */ + } + + /* If we have allocated the row_buf, this means we have already started + * with the image and we should have allocated all of the filter buffers + * that have been selected. If prev_row isn't already allocated, then + * it is too late to start using the filters that need it, since we + * will be missing the data in the previous row. If an application + * wants to start and stop using particular filters during compression, + * it should start out with all of the filters, and then add and + * remove them after the start of compression. + */ + if (png_ptr->row_buf != NULL) + { +#ifdef PNG_WRITE_FILTER_SUPPORTED + if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL) + { + png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; + } + + if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL) + { + if (png_ptr->prev_row == NULL) + { + png_warning(png_ptr, "Can't add Up filter after starting"); + png_ptr->do_filter = (png_byte)(png_ptr->do_filter & + ~PNG_FILTER_UP); + } + + else + { + png_ptr->up_row = (png_bytep)png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; + } + } + + if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL) + { + if (png_ptr->prev_row == NULL) + { + png_warning(png_ptr, "Can't add Average filter after starting"); + png_ptr->do_filter = (png_byte)(png_ptr->do_filter & + ~PNG_FILTER_AVG); + } + + else + { + png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; + } + } + + if ((png_ptr->do_filter & PNG_FILTER_PAETH) && + png_ptr->paeth_row == NULL) + { + if (png_ptr->prev_row == NULL) + { + png_warning(png_ptr, "Can't add Paeth filter after starting"); + png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH); + } + + else + { + png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; + } + } + + if (png_ptr->do_filter == PNG_NO_FILTERS) +#endif /* PNG_WRITE_FILTER_SUPPORTED */ + png_ptr->do_filter = PNG_FILTER_NONE; + } + } + else + png_error(png_ptr, "Unknown custom filter method"); +} + +/* This allows us to influence the way in which libpng chooses the "best" + * filter for the current scanline. While the "minimum-sum-of-absolute- + * differences metric is relatively fast and effective, there is some + * question as to whether it can be improved upon by trying to keep the + * filtered data going to zlib more consistent, hopefully resulting in + * better compression. + */ +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* GRR 970116 */ +/* Convenience reset API. */ +static void +png_reset_filter_heuristics(png_structp png_ptr) +{ + /* Clear out any old values in the 'weights' - this must be done because if + * the app calls set_filter_heuristics multiple times with different + * 'num_weights' values we would otherwise potentially have wrong sized + * arrays. + */ + png_ptr->num_prev_filters = 0; + png_ptr->heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED; + if (png_ptr->prev_filters != NULL) + { + png_bytep old = png_ptr->prev_filters; + png_ptr->prev_filters = NULL; + png_free(png_ptr, old); + } + if (png_ptr->filter_weights != NULL) + { + png_uint_16p old = png_ptr->filter_weights; + png_ptr->filter_weights = NULL; + png_free(png_ptr, old); + } + + if (png_ptr->inv_filter_weights != NULL) + { + png_uint_16p old = png_ptr->inv_filter_weights; + png_ptr->inv_filter_weights = NULL; + png_free(png_ptr, old); + } + + /* Leave the filter_costs - this array is fixed size. */ +} + +static int +png_init_filter_heuristics(png_structp png_ptr, int heuristic_method, + int num_weights) +{ + if (png_ptr == NULL) + return 0; + + /* Clear out the arrays */ + png_reset_filter_heuristics(png_ptr); + + /* Check arguments; the 'reset' function makes the correct settings for the + * unweighted case, but we must handle the weight case by initializing the + * arrays for the caller. + */ + if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int i; + + if (num_weights > 0) + { + png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_byte) * num_weights)); + + /* To make sure that the weighting starts out fairly */ + for (i = 0; i < num_weights; i++) + { + png_ptr->prev_filters[i] = 255; + } + + png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_uint_16) * num_weights)); + + png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_uint_16) * num_weights)); + + for (i = 0; i < num_weights; i++) + { + png_ptr->inv_filter_weights[i] = + png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; + } + + /* Safe to set this now */ + png_ptr->num_prev_filters = (png_byte)num_weights; + } + + /* If, in the future, there are other filter methods, this would + * need to be based on png_ptr->filter. + */ + if (png_ptr->filter_costs == NULL) + { + png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); + + png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); + } + + for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) + { + png_ptr->inv_filter_costs[i] = + png_ptr->filter_costs[i] = PNG_COST_FACTOR; + } + + /* All the arrays are inited, safe to set this: */ + png_ptr->heuristic_method = PNG_FILTER_HEURISTIC_WEIGHTED; + + /* Return the 'ok' code. */ + return 1; + } + else if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT || + heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED) + { + return 1; + } + else + { + png_warning(png_ptr, "Unknown filter heuristic method"); + return 0; + } +} + +/* Provide floating and fixed point APIs */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, + int num_weights, png_const_doublep filter_weights, + png_const_doublep filter_costs) +{ + png_debug(1, "in png_set_filter_heuristics"); + + /* The internal API allocates all the arrays and ensures that the elements of + * those arrays are set to the default value. + */ + if (!png_init_filter_heuristics(png_ptr, heuristic_method, num_weights)) + return; + + /* If using the weighted method copy in the weights. */ + if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int i; + for (i = 0; i < num_weights; i++) + { + if (filter_weights[i] <= 0.0) + { + png_ptr->inv_filter_weights[i] = + png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; + } + + else + { + png_ptr->inv_filter_weights[i] = + (png_uint_16)(PNG_WEIGHT_FACTOR*filter_weights[i]+.5); + + png_ptr->filter_weights[i] = + (png_uint_16)(PNG_WEIGHT_FACTOR/filter_weights[i]+.5); + } + } + + /* Here is where we set the relative costs of the different filters. We + * should take the desired compression level into account when setting + * the costs, so that Paeth, for instance, has a high relative cost at low + * compression levels, while it has a lower relative cost at higher + * compression settings. The filter types are in order of increasing + * relative cost, so it would be possible to do this with an algorithm. + */ + for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) if (filter_costs[i] >= 1.0) + { + png_ptr->inv_filter_costs[i] = + (png_uint_16)(PNG_COST_FACTOR / filter_costs[i] + .5); + + png_ptr->filter_costs[i] = + (png_uint_16)(PNG_COST_FACTOR * filter_costs[i] + .5); + } + } +} +#endif /* FLOATING_POINT */ + +#ifdef PNG_FIXED_POINT_SUPPORTED +void PNGAPI +png_set_filter_heuristics_fixed(png_structp png_ptr, int heuristic_method, + int num_weights, png_const_fixed_point_p filter_weights, + png_const_fixed_point_p filter_costs) +{ + png_debug(1, "in png_set_filter_heuristics_fixed"); + + /* The internal API allocates all the arrays and ensures that the elements of + * those arrays are set to the default value. + */ + if (!png_init_filter_heuristics(png_ptr, heuristic_method, num_weights)) + return; + + /* If using the weighted method copy in the weights. */ + if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int i; + for (i = 0; i < num_weights; i++) + { + if (filter_weights[i] <= 0) + { + png_ptr->inv_filter_weights[i] = + png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; + } + + else + { + png_ptr->inv_filter_weights[i] = (png_uint_16) + ((PNG_WEIGHT_FACTOR*filter_weights[i]+PNG_FP_HALF)/PNG_FP_1); + + png_ptr->filter_weights[i] = (png_uint_16)((PNG_WEIGHT_FACTOR* + PNG_FP_1+(filter_weights[i]/2))/filter_weights[i]); + } + } + + /* Here is where we set the relative costs of the different filters. We + * should take the desired compression level into account when setting + * the costs, so that Paeth, for instance, has a high relative cost at low + * compression levels, while it has a lower relative cost at higher + * compression settings. The filter types are in order of increasing + * relative cost, so it would be possible to do this with an algorithm. + */ + for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) + if (filter_costs[i] >= PNG_FP_1) + { + png_uint_32 tmp; + + /* Use a 32 bit unsigned temporary here because otherwise the + * intermediate value will be a 32 bit *signed* integer (ANSI rules) + * and this will get the wrong answer on division. + */ + tmp = PNG_COST_FACTOR*PNG_FP_1 + (filter_costs[i]/2); + tmp /= filter_costs[i]; + + png_ptr->inv_filter_costs[i] = (png_uint_16)tmp; + + tmp = PNG_COST_FACTOR * filter_costs[i] + PNG_FP_HALF; + tmp /= PNG_FP_1; + + png_ptr->filter_costs[i] = (png_uint_16)tmp; + } + } +} +#endif /* FIXED_POINT */ +#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ + +void PNGAPI +png_set_compression_level(png_structp png_ptr, int level) +{ + png_debug(1, "in png_set_compression_level"); + + if (png_ptr == NULL) + return; + + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL; + png_ptr->zlib_level = level; +} + +void PNGAPI +png_set_compression_mem_level(png_structp png_ptr, int mem_level) +{ + png_debug(1, "in png_set_compression_mem_level"); + + if (png_ptr == NULL) + return; + + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL; + png_ptr->zlib_mem_level = mem_level; +} + +void PNGAPI +png_set_compression_strategy(png_structp png_ptr, int strategy) +{ + png_debug(1, "in png_set_compression_strategy"); + + if (png_ptr == NULL) + return; + + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY; + png_ptr->zlib_strategy = strategy; +} + +/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a + * smaller value of window_bits if it can do so safely. + */ +void PNGAPI +png_set_compression_window_bits(png_structp png_ptr, int window_bits) +{ + if (png_ptr == NULL) + return; + + if (window_bits > 15) + png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); + + else if (window_bits < 8) + png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); + +#ifndef WBITS_8_OK + /* Avoid libpng bug with 256-byte windows */ + if (window_bits == 8) + { + png_warning(png_ptr, "Compression window is being reset to 512"); + window_bits = 9; + } + +#endif + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS; + png_ptr->zlib_window_bits = window_bits; +} + +void PNGAPI +png_set_compression_method(png_structp png_ptr, int method) +{ + png_debug(1, "in png_set_compression_method"); + + if (png_ptr == NULL) + return; + + if (method != 8) + png_warning(png_ptr, "Only compression method 8 is supported by PNG"); + + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD; + png_ptr->zlib_method = method; +} + +/* The following were added to libpng-1.5.4 */ +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED +void PNGAPI +png_set_text_compression_level(png_structp png_ptr, int level) +{ + png_debug(1, "in png_set_text_compression_level"); + + if (png_ptr == NULL) + return; + + png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_LEVEL; + png_ptr->zlib_text_level = level; +} + +void PNGAPI +png_set_text_compression_mem_level(png_structp png_ptr, int mem_level) +{ + png_debug(1, "in png_set_text_compression_mem_level"); + + if (png_ptr == NULL) + return; + + png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL; + png_ptr->zlib_text_mem_level = mem_level; +} + +void PNGAPI +png_set_text_compression_strategy(png_structp png_ptr, int strategy) +{ + png_debug(1, "in png_set_text_compression_strategy"); + + if (png_ptr == NULL) + return; + + png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_STRATEGY; + png_ptr->zlib_text_strategy = strategy; +} + +/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a + * smaller value of window_bits if it can do so safely. + */ +void PNGAPI +png_set_text_compression_window_bits(png_structp png_ptr, int window_bits) +{ + if (png_ptr == NULL) + return; + + if (window_bits > 15) + png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); + + else if (window_bits < 8) + png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); + +#ifndef WBITS_8_OK + /* Avoid libpng bug with 256-byte windows */ + if (window_bits == 8) + { + png_warning(png_ptr, "Text compression window is being reset to 512"); + window_bits = 9; + } + +#endif + png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS; + png_ptr->zlib_text_window_bits = window_bits; +} + +void PNGAPI +png_set_text_compression_method(png_structp png_ptr, int method) +{ + png_debug(1, "in png_set_text_compression_method"); + + if (png_ptr == NULL) + return; + + if (method != 8) + png_warning(png_ptr, "Only compression method 8 is supported by PNG"); + + png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_METHOD; + png_ptr->zlib_text_method = method; +} +#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */ +/* end of API added to libpng-1.5.4 */ + +void PNGAPI +png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn) +{ + if (png_ptr == NULL) + return; + + png_ptr->write_row_fn = write_row_fn; +} + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED +void PNGAPI +png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr + write_user_transform_fn) +{ + png_debug(1, "in png_set_write_user_transform_fn"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_USER_TRANSFORM; + png_ptr->write_user_transform_fn = write_user_transform_fn; +} +#endif + + +#ifdef PNG_INFO_IMAGE_SUPPORTED +void PNGAPI +png_write_png(png_structp png_ptr, png_infop info_ptr, + int transforms, voidp params) +{ + if (png_ptr == NULL || info_ptr == NULL) + return; + + /* Write the file header information. */ + png_write_info(png_ptr, info_ptr); + + /* ------ these transformations don't touch the info structure ------- */ + +#ifdef PNG_WRITE_INVERT_SUPPORTED + /* Invert monochrome pixels */ + if (transforms & PNG_TRANSFORM_INVERT_MONO) + png_set_invert_mono(png_ptr); +#endif + +#ifdef PNG_WRITE_SHIFT_SUPPORTED + /* Shift the pixels up to a legal bit depth and fill in + * as appropriate to correctly scale the image. + */ + if ((transforms & PNG_TRANSFORM_SHIFT) + && (info_ptr->valid & PNG_INFO_sBIT)) + png_set_shift(png_ptr, &info_ptr->sig_bit); +#endif + +#ifdef PNG_WRITE_PACK_SUPPORTED + /* Pack pixels into bytes */ + if (transforms & PNG_TRANSFORM_PACKING) + png_set_packing(png_ptr); +#endif + +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED + /* Swap location of alpha bytes from ARGB to RGBA */ + if (transforms & PNG_TRANSFORM_SWAP_ALPHA) + png_set_swap_alpha(png_ptr); +#endif + +#ifdef PNG_WRITE_FILLER_SUPPORTED + /* Pack XRGB/RGBX/ARGB/RGBA into RGB (4 channels -> 3 channels) */ + if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) + png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); + + else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) + png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); +#endif + +#ifdef PNG_WRITE_BGR_SUPPORTED + /* Flip BGR pixels to RGB */ + if (transforms & PNG_TRANSFORM_BGR) + png_set_bgr(png_ptr); +#endif + +#ifdef PNG_WRITE_SWAP_SUPPORTED + /* Swap bytes of 16-bit files to most significant byte first */ + if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) + png_set_swap(png_ptr); +#endif + +#ifdef PNG_WRITE_PACKSWAP_SUPPORTED + /* Swap bits of 1, 2, 4 bit packed pixel formats */ + if (transforms & PNG_TRANSFORM_PACKSWAP) + png_set_packswap(png_ptr); +#endif + +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED + /* Invert the alpha channel from opacity to transparency */ + if (transforms & PNG_TRANSFORM_INVERT_ALPHA) + png_set_invert_alpha(png_ptr); +#endif + + /* ----------------------- end of transformations ------------------- */ + + /* Write the bits */ + if (info_ptr->valid & PNG_INFO_IDAT) + png_write_image(png_ptr, info_ptr->row_pointers); + + /* It is REQUIRED to call this to finish writing the rest of the file */ + png_write_end(png_ptr, info_ptr); + + PNG_UNUSED(transforms) /* Quiet compiler warnings */ + PNG_UNUSED(params) +} +#endif +#endif /* PNG_WRITE_SUPPORTED */ diff --git a/Source/LibPNG/pngwtran.c b/Source/LibPNG/pngwtran.c index e962b68..7435813 100644 --- a/Source/LibPNG/pngwtran.c +++ b/Source/LibPNG/pngwtran.c @@ -1,645 +1,645 @@ - -/* pngwtran.c - transforms the data in a row for PNG writers - * - * Last changed in libpng 1.5.13 [September 27, 2012] - * Copyright (c) 1998-2012 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - */ - -#include "pngpriv.h" - -#ifdef PNG_WRITE_SUPPORTED - -#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED -/* Transform the data according to the user's wishes. The order of - * transformations is significant. - */ -void /* PRIVATE */ -png_do_write_transformations(png_structp png_ptr, png_row_infop row_info) -{ - png_debug(1, "in png_do_write_transformations"); - - if (png_ptr == NULL) - return; - -#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED - if (png_ptr->transformations & PNG_USER_TRANSFORM) - if (png_ptr->write_user_transform_fn != NULL) - (*(png_ptr->write_user_transform_fn)) /* User write transform - function */ - (png_ptr, /* png_ptr */ - row_info, /* row_info: */ - /* png_uint_32 width; width of row */ - /* png_size_t rowbytes; number of bytes in row */ - /* png_byte color_type; color type of pixels */ - /* png_byte bit_depth; bit depth of samples */ - /* png_byte channels; number of channels (1-4) */ - /* png_byte pixel_depth; bits per pixel (depth*channels) */ - png_ptr->row_buf + 1); /* start of pixel data for row */ -#endif - -#ifdef PNG_WRITE_FILLER_SUPPORTED - if (png_ptr->transformations & PNG_FILLER) - { - if (png_ptr->color_type & (PNG_COLOR_MASK_ALPHA|PNG_COLOR_MASK_PALETTE)) - { - /* GA, RGBA or palette; in any of these cases libpng will not do the - * the correct thing (whatever that might be). - */ - png_warning(png_ptr, "incorrect png_set_filler call ignored"); - png_ptr->transformations &= ~PNG_FILLER; - } - - else - png_do_strip_channel(row_info, png_ptr->row_buf + 1, - !(png_ptr->flags & PNG_FLAG_FILLER_AFTER)); - } -#endif - -#ifdef PNG_WRITE_PACKSWAP_SUPPORTED - if (png_ptr->transformations & PNG_PACKSWAP) - png_do_packswap(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_WRITE_PACK_SUPPORTED - if (png_ptr->transformations & PNG_PACK) - png_do_pack(row_info, png_ptr->row_buf + 1, - (png_uint_32)png_ptr->bit_depth); -#endif - -#ifdef PNG_WRITE_SWAP_SUPPORTED - if (png_ptr->transformations & PNG_SWAP_BYTES) - png_do_swap(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_WRITE_SHIFT_SUPPORTED - if (png_ptr->transformations & PNG_SHIFT) - png_do_shift(row_info, png_ptr->row_buf + 1, - &(png_ptr->shift)); -#endif - -#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED - if (png_ptr->transformations & PNG_SWAP_ALPHA) - png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED - if (png_ptr->transformations & PNG_INVERT_ALPHA) - png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_WRITE_BGR_SUPPORTED - if (png_ptr->transformations & PNG_BGR) - png_do_bgr(row_info, png_ptr->row_buf + 1); -#endif - -#ifdef PNG_WRITE_INVERT_SUPPORTED - if (png_ptr->transformations & PNG_INVERT_MONO) - png_do_invert(row_info, png_ptr->row_buf + 1); -#endif -} - -#ifdef PNG_WRITE_PACK_SUPPORTED -/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The - * row_info bit depth should be 8 (one pixel per byte). The channels - * should be 1 (this only happens on grayscale and paletted images). - */ -void /* PRIVATE */ -png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) -{ - png_debug(1, "in png_do_pack"); - - if (row_info->bit_depth == 8 && - row_info->channels == 1) - { - switch ((int)bit_depth) - { - case 1: - { - png_bytep sp, dp; - int mask, v; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - sp = row; - dp = row; - mask = 0x80; - v = 0; - - for (i = 0; i < row_width; i++) - { - if (*sp != 0) - v |= mask; - - sp++; - - if (mask > 1) - mask >>= 1; - - else - { - mask = 0x80; - *dp = (png_byte)v; - dp++; - v = 0; - } - } - - if (mask != 0x80) - *dp = (png_byte)v; - - break; - } - - case 2: - { - png_bytep sp, dp; - int shift, v; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - sp = row; - dp = row; - shift = 6; - v = 0; - - for (i = 0; i < row_width; i++) - { - png_byte value; - - value = (png_byte)(*sp & 0x03); - v |= (value << shift); - - if (shift == 0) - { - shift = 6; - *dp = (png_byte)v; - dp++; - v = 0; - } - - else - shift -= 2; - - sp++; - } - - if (shift != 6) - *dp = (png_byte)v; - - break; - } - - case 4: - { - png_bytep sp, dp; - int shift, v; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - sp = row; - dp = row; - shift = 4; - v = 0; - - for (i = 0; i < row_width; i++) - { - png_byte value; - - value = (png_byte)(*sp & 0x0f); - v |= (value << shift); - - if (shift == 0) - { - shift = 4; - *dp = (png_byte)v; - dp++; - v = 0; - } - - else - shift -= 4; - - sp++; - } - - if (shift != 4) - *dp = (png_byte)v; - - break; - } - - default: - break; - } - - row_info->bit_depth = (png_byte)bit_depth; - row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels); - row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, - row_info->width); - } -} -#endif - -#ifdef PNG_WRITE_SHIFT_SUPPORTED -/* Shift pixel values to take advantage of whole range. Pass the - * true number of bits in bit_depth. The row should be packed - * according to row_info->bit_depth. Thus, if you had a row of - * bit depth 4, but the pixels only had values from 0 to 7, you - * would pass 3 as bit_depth, and this routine would translate the - * data to 0 to 15. - */ -void /* PRIVATE */ -png_do_shift(png_row_infop row_info, png_bytep row, - png_const_color_8p bit_depth) -{ - png_debug(1, "in png_do_shift"); - - if (row_info->color_type != PNG_COLOR_TYPE_PALETTE) - { - int shift_start[4], shift_dec[4]; - int channels = 0; - - if (row_info->color_type & PNG_COLOR_MASK_COLOR) - { - shift_start[channels] = row_info->bit_depth - bit_depth->red; - shift_dec[channels] = bit_depth->red; - channels++; - - shift_start[channels] = row_info->bit_depth - bit_depth->green; - shift_dec[channels] = bit_depth->green; - channels++; - - shift_start[channels] = row_info->bit_depth - bit_depth->blue; - shift_dec[channels] = bit_depth->blue; - channels++; - } - - else - { - shift_start[channels] = row_info->bit_depth - bit_depth->gray; - shift_dec[channels] = bit_depth->gray; - channels++; - } - - if (row_info->color_type & PNG_COLOR_MASK_ALPHA) - { - shift_start[channels] = row_info->bit_depth - bit_depth->alpha; - shift_dec[channels] = bit_depth->alpha; - channels++; - } - - /* With low row depths, could only be grayscale, so one channel */ - if (row_info->bit_depth < 8) - { - png_bytep bp = row; - png_size_t i; - png_byte mask; - png_size_t row_bytes = row_info->rowbytes; - - if (bit_depth->gray == 1 && row_info->bit_depth == 2) - mask = 0x55; - - else if (row_info->bit_depth == 4 && bit_depth->gray == 3) - mask = 0x11; - - else - mask = 0xff; - - for (i = 0; i < row_bytes; i++, bp++) - { - png_uint_16 v; - int j; - - v = *bp; - *bp = 0; - - for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0]) - { - if (j > 0) - *bp |= (png_byte)((v << j) & 0xff); - - else - *bp |= (png_byte)((v >> (-j)) & mask); - } - } - } - - else if (row_info->bit_depth == 8) - { - png_bytep bp = row; - png_uint_32 i; - png_uint_32 istop = channels * row_info->width; - - for (i = 0; i < istop; i++, bp++) - { - - png_uint_16 v; - int j; - int c = (int)(i%channels); - - v = *bp; - *bp = 0; - - for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) - { - if (j > 0) - *bp |= (png_byte)((v << j) & 0xff); - - else - *bp |= (png_byte)((v >> (-j)) & 0xff); - } - } - } - - else - { - png_bytep bp; - png_uint_32 i; - png_uint_32 istop = channels * row_info->width; - - for (bp = row, i = 0; i < istop; i++) - { - int c = (int)(i%channels); - png_uint_16 value, v; - int j; - - v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1)); - value = 0; - - for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) - { - if (j > 0) - value |= (png_uint_16)((v << j) & (png_uint_16)0xffff); - - else - value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff); - } - *bp++ = (png_byte)(value >> 8); - *bp++ = (png_byte)(value & 0xff); - } - } - } -} -#endif - -#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED -void /* PRIVATE */ -png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) -{ - png_debug(1, "in png_do_write_swap_alpha"); - - { - if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - { - if (row_info->bit_depth == 8) - { - /* This converts from ARGB to RGBA */ - png_bytep sp, dp; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - for (i = 0, sp = dp = row; i < row_width; i++) - { - png_byte save = *(sp++); - *(dp++) = *(sp++); - *(dp++) = *(sp++); - *(dp++) = *(sp++); - *(dp++) = save; - } - } - -#ifdef PNG_WRITE_16BIT_SUPPORTED - else - { - /* This converts from AARRGGBB to RRGGBBAA */ - png_bytep sp, dp; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - for (i = 0, sp = dp = row; i < row_width; i++) - { - png_byte save[2]; - save[0] = *(sp++); - save[1] = *(sp++); - *(dp++) = *(sp++); - *(dp++) = *(sp++); - *(dp++) = *(sp++); - *(dp++) = *(sp++); - *(dp++) = *(sp++); - *(dp++) = *(sp++); - *(dp++) = save[0]; - *(dp++) = save[1]; - } - } -#endif /* PNG_WRITE_16BIT_SUPPORTED */ - } - - else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - { - if (row_info->bit_depth == 8) - { - /* This converts from AG to GA */ - png_bytep sp, dp; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - for (i = 0, sp = dp = row; i < row_width; i++) - { - png_byte save = *(sp++); - *(dp++) = *(sp++); - *(dp++) = save; - } - } - -#ifdef PNG_WRITE_16BIT_SUPPORTED - else - { - /* This converts from AAGG to GGAA */ - png_bytep sp, dp; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - for (i = 0, sp = dp = row; i < row_width; i++) - { - png_byte save[2]; - save[0] = *(sp++); - save[1] = *(sp++); - *(dp++) = *(sp++); - *(dp++) = *(sp++); - *(dp++) = save[0]; - *(dp++) = save[1]; - } - } -#endif /* PNG_WRITE_16BIT_SUPPORTED */ - } - } -} -#endif - -#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED -void /* PRIVATE */ -png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) -{ - png_debug(1, "in png_do_write_invert_alpha"); - - { - if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - { - if (row_info->bit_depth == 8) - { - /* This inverts the alpha channel in RGBA */ - png_bytep sp, dp; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - for (i = 0, sp = dp = row; i < row_width; i++) - { - /* Does nothing - *(dp++) = *(sp++); - *(dp++) = *(sp++); - *(dp++) = *(sp++); - */ - sp+=3; dp = sp; - *(dp++) = (png_byte)(255 - *(sp++)); - } - } - -#ifdef PNG_WRITE_16BIT_SUPPORTED - else - { - /* This inverts the alpha channel in RRGGBBAA */ - png_bytep sp, dp; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - for (i = 0, sp = dp = row; i < row_width; i++) - { - /* Does nothing - *(dp++) = *(sp++); - *(dp++) = *(sp++); - *(dp++) = *(sp++); - *(dp++) = *(sp++); - *(dp++) = *(sp++); - *(dp++) = *(sp++); - */ - sp+=6; dp = sp; - *(dp++) = (png_byte)(255 - *(sp++)); - *(dp++) = (png_byte)(255 - *(sp++)); - } - } -#endif /* PNG_WRITE_16BIT_SUPPORTED */ - } - - else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - { - if (row_info->bit_depth == 8) - { - /* This inverts the alpha channel in GA */ - png_bytep sp, dp; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - for (i = 0, sp = dp = row; i < row_width; i++) - { - *(dp++) = *(sp++); - *(dp++) = (png_byte)(255 - *(sp++)); - } - } - -#ifdef PNG_WRITE_16BIT_SUPPORTED - else - { - /* This inverts the alpha channel in GGAA */ - png_bytep sp, dp; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - for (i = 0, sp = dp = row; i < row_width; i++) - { - /* Does nothing - *(dp++) = *(sp++); - *(dp++) = *(sp++); - */ - sp+=2; dp = sp; - *(dp++) = (png_byte)(255 - *(sp++)); - *(dp++) = (png_byte)(255 - *(sp++)); - } - } -#endif /* PNG_WRITE_16BIT_SUPPORTED */ - } - } -} -#endif -#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */ - -#ifdef PNG_MNG_FEATURES_SUPPORTED -/* Undoes intrapixel differencing */ -void /* PRIVATE */ -png_do_write_intrapixel(png_row_infop row_info, png_bytep row) -{ - png_debug(1, "in png_do_write_intrapixel"); - - if ((row_info->color_type & PNG_COLOR_MASK_COLOR)) - { - int bytes_per_pixel; - png_uint_32 row_width = row_info->width; - if (row_info->bit_depth == 8) - { - png_bytep rp; - png_uint_32 i; - - if (row_info->color_type == PNG_COLOR_TYPE_RGB) - bytes_per_pixel = 3; - - else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - bytes_per_pixel = 4; - - else - return; - - for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) - { - *(rp) = (png_byte)((*rp - *(rp + 1)) & 0xff); - *(rp + 2) = (png_byte)((*(rp + 2) - *(rp + 1)) & 0xff); - } - } - -#ifdef PNG_WRITE_16BIT_SUPPORTED - else if (row_info->bit_depth == 16) - { - png_bytep rp; - png_uint_32 i; - - if (row_info->color_type == PNG_COLOR_TYPE_RGB) - bytes_per_pixel = 6; - - else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - bytes_per_pixel = 8; - - else - return; - - for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) - { - png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1); - png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3); - png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5); - png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL); - png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL); - *(rp ) = (png_byte)((red >> 8) & 0xff); - *(rp + 1) = (png_byte)(red & 0xff); - *(rp + 4) = (png_byte)((blue >> 8) & 0xff); - *(rp + 5) = (png_byte)(blue & 0xff); - } - } -#endif /* PNG_WRITE_16BIT_SUPPORTED */ - } -} -#endif /* PNG_MNG_FEATURES_SUPPORTED */ -#endif /* PNG_WRITE_SUPPORTED */ + +/* pngwtran.c - transforms the data in a row for PNG writers + * + * Last changed in libpng 1.5.13 [September 27, 2012] + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "pngpriv.h" + +#ifdef PNG_WRITE_SUPPORTED + +#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED +/* Transform the data according to the user's wishes. The order of + * transformations is significant. + */ +void /* PRIVATE */ +png_do_write_transformations(png_structp png_ptr, png_row_infop row_info) +{ + png_debug(1, "in png_do_write_transformations"); + + if (png_ptr == NULL) + return; + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED + if (png_ptr->transformations & PNG_USER_TRANSFORM) + if (png_ptr->write_user_transform_fn != NULL) + (*(png_ptr->write_user_transform_fn)) /* User write transform + function */ + (png_ptr, /* png_ptr */ + row_info, /* row_info: */ + /* png_uint_32 width; width of row */ + /* png_size_t rowbytes; number of bytes in row */ + /* png_byte color_type; color type of pixels */ + /* png_byte bit_depth; bit depth of samples */ + /* png_byte channels; number of channels (1-4) */ + /* png_byte pixel_depth; bits per pixel (depth*channels) */ + png_ptr->row_buf + 1); /* start of pixel data for row */ +#endif + +#ifdef PNG_WRITE_FILLER_SUPPORTED + if (png_ptr->transformations & PNG_FILLER) + { + if (png_ptr->color_type & (PNG_COLOR_MASK_ALPHA|PNG_COLOR_MASK_PALETTE)) + { + /* GA, RGBA or palette; in any of these cases libpng will not do the + * the correct thing (whatever that might be). + */ + png_warning(png_ptr, "incorrect png_set_filler call ignored"); + png_ptr->transformations &= ~PNG_FILLER; + } + + else + png_do_strip_channel(row_info, png_ptr->row_buf + 1, + !(png_ptr->flags & PNG_FLAG_FILLER_AFTER)); + } +#endif + +#ifdef PNG_WRITE_PACKSWAP_SUPPORTED + if (png_ptr->transformations & PNG_PACKSWAP) + png_do_packswap(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_WRITE_PACK_SUPPORTED + if (png_ptr->transformations & PNG_PACK) + png_do_pack(row_info, png_ptr->row_buf + 1, + (png_uint_32)png_ptr->bit_depth); +#endif + +#ifdef PNG_WRITE_SWAP_SUPPORTED + if (png_ptr->transformations & PNG_SWAP_BYTES) + png_do_swap(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_WRITE_SHIFT_SUPPORTED + if (png_ptr->transformations & PNG_SHIFT) + png_do_shift(row_info, png_ptr->row_buf + 1, + &(png_ptr->shift)); +#endif + +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED + if (png_ptr->transformations & PNG_SWAP_ALPHA) + png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED + if (png_ptr->transformations & PNG_INVERT_ALPHA) + png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_WRITE_BGR_SUPPORTED + if (png_ptr->transformations & PNG_BGR) + png_do_bgr(row_info, png_ptr->row_buf + 1); +#endif + +#ifdef PNG_WRITE_INVERT_SUPPORTED + if (png_ptr->transformations & PNG_INVERT_MONO) + png_do_invert(row_info, png_ptr->row_buf + 1); +#endif +} + +#ifdef PNG_WRITE_PACK_SUPPORTED +/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The + * row_info bit depth should be 8 (one pixel per byte). The channels + * should be 1 (this only happens on grayscale and paletted images). + */ +void /* PRIVATE */ +png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) +{ + png_debug(1, "in png_do_pack"); + + if (row_info->bit_depth == 8 && + row_info->channels == 1) + { + switch ((int)bit_depth) + { + case 1: + { + png_bytep sp, dp; + int mask, v; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + sp = row; + dp = row; + mask = 0x80; + v = 0; + + for (i = 0; i < row_width; i++) + { + if (*sp != 0) + v |= mask; + + sp++; + + if (mask > 1) + mask >>= 1; + + else + { + mask = 0x80; + *dp = (png_byte)v; + dp++; + v = 0; + } + } + + if (mask != 0x80) + *dp = (png_byte)v; + + break; + } + + case 2: + { + png_bytep sp, dp; + int shift, v; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + sp = row; + dp = row; + shift = 6; + v = 0; + + for (i = 0; i < row_width; i++) + { + png_byte value; + + value = (png_byte)(*sp & 0x03); + v |= (value << shift); + + if (shift == 0) + { + shift = 6; + *dp = (png_byte)v; + dp++; + v = 0; + } + + else + shift -= 2; + + sp++; + } + + if (shift != 6) + *dp = (png_byte)v; + + break; + } + + case 4: + { + png_bytep sp, dp; + int shift, v; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + sp = row; + dp = row; + shift = 4; + v = 0; + + for (i = 0; i < row_width; i++) + { + png_byte value; + + value = (png_byte)(*sp & 0x0f); + v |= (value << shift); + + if (shift == 0) + { + shift = 4; + *dp = (png_byte)v; + dp++; + v = 0; + } + + else + shift -= 4; + + sp++; + } + + if (shift != 4) + *dp = (png_byte)v; + + break; + } + + default: + break; + } + + row_info->bit_depth = (png_byte)bit_depth; + row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, + row_info->width); + } +} +#endif + +#ifdef PNG_WRITE_SHIFT_SUPPORTED +/* Shift pixel values to take advantage of whole range. Pass the + * true number of bits in bit_depth. The row should be packed + * according to row_info->bit_depth. Thus, if you had a row of + * bit depth 4, but the pixels only had values from 0 to 7, you + * would pass 3 as bit_depth, and this routine would translate the + * data to 0 to 15. + */ +void /* PRIVATE */ +png_do_shift(png_row_infop row_info, png_bytep row, + png_const_color_8p bit_depth) +{ + png_debug(1, "in png_do_shift"); + + if (row_info->color_type != PNG_COLOR_TYPE_PALETTE) + { + int shift_start[4], shift_dec[4]; + int channels = 0; + + if (row_info->color_type & PNG_COLOR_MASK_COLOR) + { + shift_start[channels] = row_info->bit_depth - bit_depth->red; + shift_dec[channels] = bit_depth->red; + channels++; + + shift_start[channels] = row_info->bit_depth - bit_depth->green; + shift_dec[channels] = bit_depth->green; + channels++; + + shift_start[channels] = row_info->bit_depth - bit_depth->blue; + shift_dec[channels] = bit_depth->blue; + channels++; + } + + else + { + shift_start[channels] = row_info->bit_depth - bit_depth->gray; + shift_dec[channels] = bit_depth->gray; + channels++; + } + + if (row_info->color_type & PNG_COLOR_MASK_ALPHA) + { + shift_start[channels] = row_info->bit_depth - bit_depth->alpha; + shift_dec[channels] = bit_depth->alpha; + channels++; + } + + /* With low row depths, could only be grayscale, so one channel */ + if (row_info->bit_depth < 8) + { + png_bytep bp = row; + png_size_t i; + png_byte mask; + png_size_t row_bytes = row_info->rowbytes; + + if (bit_depth->gray == 1 && row_info->bit_depth == 2) + mask = 0x55; + + else if (row_info->bit_depth == 4 && bit_depth->gray == 3) + mask = 0x11; + + else + mask = 0xff; + + for (i = 0; i < row_bytes; i++, bp++) + { + png_uint_16 v; + int j; + + v = *bp; + *bp = 0; + + for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0]) + { + if (j > 0) + *bp |= (png_byte)((v << j) & 0xff); + + else + *bp |= (png_byte)((v >> (-j)) & mask); + } + } + } + + else if (row_info->bit_depth == 8) + { + png_bytep bp = row; + png_uint_32 i; + png_uint_32 istop = channels * row_info->width; + + for (i = 0; i < istop; i++, bp++) + { + + png_uint_16 v; + int j; + int c = (int)(i%channels); + + v = *bp; + *bp = 0; + + for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) + { + if (j > 0) + *bp |= (png_byte)((v << j) & 0xff); + + else + *bp |= (png_byte)((v >> (-j)) & 0xff); + } + } + } + + else + { + png_bytep bp; + png_uint_32 i; + png_uint_32 istop = channels * row_info->width; + + for (bp = row, i = 0; i < istop; i++) + { + int c = (int)(i%channels); + png_uint_16 value, v; + int j; + + v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1)); + value = 0; + + for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) + { + if (j > 0) + value |= (png_uint_16)((v << j) & (png_uint_16)0xffff); + + else + value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff); + } + *bp++ = (png_byte)(value >> 8); + *bp++ = (png_byte)(value & 0xff); + } + } + } +} +#endif + +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED +void /* PRIVATE */ +png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_write_swap_alpha"); + + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + if (row_info->bit_depth == 8) + { + /* This converts from ARGB to RGBA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save; + } + } + +#ifdef PNG_WRITE_16BIT_SUPPORTED + else + { + /* This converts from AARRGGBB to RRGGBBAA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save[2]; + save[0] = *(sp++); + save[1] = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save[0]; + *(dp++) = save[1]; + } + } +#endif /* PNG_WRITE_16BIT_SUPPORTED */ + } + + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + if (row_info->bit_depth == 8) + { + /* This converts from AG to GA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save; + } + } + +#ifdef PNG_WRITE_16BIT_SUPPORTED + else + { + /* This converts from AAGG to GGAA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save[2]; + save[0] = *(sp++); + save[1] = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save[0]; + *(dp++) = save[1]; + } + } +#endif /* PNG_WRITE_16BIT_SUPPORTED */ + } + } +} +#endif + +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED +void /* PRIVATE */ +png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_write_invert_alpha"); + + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + if (row_info->bit_depth == 8) + { + /* This inverts the alpha channel in RGBA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + /* Does nothing + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + */ + sp+=3; dp = sp; + *(dp++) = (png_byte)(255 - *(sp++)); + } + } + +#ifdef PNG_WRITE_16BIT_SUPPORTED + else + { + /* This inverts the alpha channel in RRGGBBAA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + /* Does nothing + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + */ + sp+=6; dp = sp; + *(dp++) = (png_byte)(255 - *(sp++)); + *(dp++) = (png_byte)(255 - *(sp++)); + } + } +#endif /* PNG_WRITE_16BIT_SUPPORTED */ + } + + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + if (row_info->bit_depth == 8) + { + /* This inverts the alpha channel in GA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + *(dp++) = *(sp++); + *(dp++) = (png_byte)(255 - *(sp++)); + } + } + +#ifdef PNG_WRITE_16BIT_SUPPORTED + else + { + /* This inverts the alpha channel in GGAA */ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + /* Does nothing + *(dp++) = *(sp++); + *(dp++) = *(sp++); + */ + sp+=2; dp = sp; + *(dp++) = (png_byte)(255 - *(sp++)); + *(dp++) = (png_byte)(255 - *(sp++)); + } + } +#endif /* PNG_WRITE_16BIT_SUPPORTED */ + } + } +} +#endif +#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */ + +#ifdef PNG_MNG_FEATURES_SUPPORTED +/* Undoes intrapixel differencing */ +void /* PRIVATE */ +png_do_write_intrapixel(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_write_intrapixel"); + + if ((row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + int bytes_per_pixel; + png_uint_32 row_width = row_info->width; + if (row_info->bit_depth == 8) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 3; + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 4; + + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + *(rp) = (png_byte)((*rp - *(rp + 1)) & 0xff); + *(rp + 2) = (png_byte)((*(rp + 2) - *(rp + 1)) & 0xff); + } + } + +#ifdef PNG_WRITE_16BIT_SUPPORTED + else if (row_info->bit_depth == 16) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 6; + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 8; + + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1); + png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3); + png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5); + png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL); + png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL); + *(rp ) = (png_byte)((red >> 8) & 0xff); + *(rp + 1) = (png_byte)(red & 0xff); + *(rp + 4) = (png_byte)((blue >> 8) & 0xff); + *(rp + 5) = (png_byte)(blue & 0xff); + } + } +#endif /* PNG_WRITE_16BIT_SUPPORTED */ + } +} +#endif /* PNG_MNG_FEATURES_SUPPORTED */ +#endif /* PNG_WRITE_SUPPORTED */ diff --git a/Source/LibPNG/pngwutil.c b/Source/LibPNG/pngwutil.c index 3cef5b2..19b75af 100644 --- a/Source/LibPNG/pngwutil.c +++ b/Source/LibPNG/pngwutil.c @@ -1,3180 +1,3180 @@ - -/* pngwutil.c - utilities to write a PNG file - * - * Last changed in libpng 1.5.10 [March 8, 2012] - * Copyright (c) 1998-2012 Glenn Randers-Pehrson - * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) - * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) - * - * This code is released under the libpng license. - * For conditions of distribution and use, see the disclaimer - * and license in png.h - */ - -#include "pngpriv.h" - -#ifdef PNG_WRITE_SUPPORTED - -#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED -/* Place a 32-bit number into a buffer in PNG byte order. We work - * with unsigned numbers for convenience, although one supported - * ancillary chunk uses signed (two's complement) numbers. - */ -void PNGAPI -png_save_uint_32(png_bytep buf, png_uint_32 i) -{ - buf[0] = (png_byte)((i >> 24) & 0xff); - buf[1] = (png_byte)((i >> 16) & 0xff); - buf[2] = (png_byte)((i >> 8) & 0xff); - buf[3] = (png_byte)(i & 0xff); -} - -#ifdef PNG_SAVE_INT_32_SUPPORTED -/* The png_save_int_32 function assumes integers are stored in two's - * complement format. If this isn't the case, then this routine needs to - * be modified to write data in two's complement format. Note that, - * the following works correctly even if png_int_32 has more than 32 bits - * (compare the more complex code required on read for sign extention.) - */ -void PNGAPI -png_save_int_32(png_bytep buf, png_int_32 i) -{ - buf[0] = (png_byte)((i >> 24) & 0xff); - buf[1] = (png_byte)((i >> 16) & 0xff); - buf[2] = (png_byte)((i >> 8) & 0xff); - buf[3] = (png_byte)(i & 0xff); -} -#endif - -/* Place a 16-bit number into a buffer in PNG byte order. - * The parameter is declared unsigned int, not png_uint_16, - * just to avoid potential problems on pre-ANSI C compilers. - */ -void PNGAPI -png_save_uint_16(png_bytep buf, unsigned int i) -{ - buf[0] = (png_byte)((i >> 8) & 0xff); - buf[1] = (png_byte)(i & 0xff); -} -#endif - -/* Simple function to write the signature. If we have already written - * the magic bytes of the signature, or more likely, the PNG stream is - * being embedded into another stream and doesn't need its own signature, - * we should call png_set_sig_bytes() to tell libpng how many of the - * bytes have already been written. - */ -void PNGAPI -png_write_sig(png_structp png_ptr) -{ - png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; - -#ifdef PNG_IO_STATE_SUPPORTED - /* Inform the I/O callback that the signature is being written */ - png_ptr->io_state = PNG_IO_WRITING | PNG_IO_SIGNATURE; -#endif - - /* Write the rest of the 8 byte signature */ - png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes], - (png_size_t)(8 - png_ptr->sig_bytes)); - - if (png_ptr->sig_bytes < 3) - png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; -} - -/* Write the start of a PNG chunk. The type is the chunk type. - * The total_length is the sum of the lengths of all the data you will be - * passing in png_write_chunk_data(). - */ -static void -png_write_chunk_header(png_structp png_ptr, png_uint_32 chunk_name, - png_uint_32 length) -{ - png_byte buf[8]; - -#if defined(PNG_DEBUG) && (PNG_DEBUG > 0) - PNG_CSTRING_FROM_CHUNK(buf, chunk_name); - png_debug2(0, "Writing %s chunk, length = %lu", buf, (unsigned long)length); -#endif - - if (png_ptr == NULL) - return; - -#ifdef PNG_IO_STATE_SUPPORTED - /* Inform the I/O callback that the chunk header is being written. - * PNG_IO_CHUNK_HDR requires a single I/O call. - */ - png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_HDR; -#endif - - /* Write the length and the chunk name */ - png_save_uint_32(buf, length); - png_save_uint_32(buf + 4, chunk_name); - png_write_data(png_ptr, buf, 8); - - /* Put the chunk name into png_ptr->chunk_name */ - png_ptr->chunk_name = chunk_name; - - /* Reset the crc and run it over the chunk name */ - png_reset_crc(png_ptr); - - png_calculate_crc(png_ptr, buf + 4, 4); - -#ifdef PNG_IO_STATE_SUPPORTED - /* Inform the I/O callback that chunk data will (possibly) be written. - * PNG_IO_CHUNK_DATA does NOT require a specific number of I/O calls. - */ - png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_DATA; -#endif -} - -void PNGAPI -png_write_chunk_start(png_structp png_ptr, png_const_bytep chunk_string, - png_uint_32 length) -{ - png_write_chunk_header(png_ptr, PNG_CHUNK_FROM_STRING(chunk_string), length); -} - -/* Write the data of a PNG chunk started with png_write_chunk_header(). - * Note that multiple calls to this function are allowed, and that the - * sum of the lengths from these calls *must* add up to the total_length - * given to png_write_chunk_header(). - */ -void PNGAPI -png_write_chunk_data(png_structp png_ptr, png_const_bytep data, - png_size_t length) -{ - /* Write the data, and run the CRC over it */ - if (png_ptr == NULL) - return; - - if (data != NULL && length > 0) - { - png_write_data(png_ptr, data, length); - - /* Update the CRC after writing the data, - * in case that the user I/O routine alters it. - */ - png_calculate_crc(png_ptr, data, length); - } -} - -/* Finish a chunk started with png_write_chunk_header(). */ -void PNGAPI -png_write_chunk_end(png_structp png_ptr) -{ - png_byte buf[4]; - - if (png_ptr == NULL) return; - -#ifdef PNG_IO_STATE_SUPPORTED - /* Inform the I/O callback that the chunk CRC is being written. - * PNG_IO_CHUNK_CRC requires a single I/O function call. - */ - png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_CRC; -#endif - - /* Write the crc in a single operation */ - png_save_uint_32(buf, png_ptr->crc); - - png_write_data(png_ptr, buf, (png_size_t)4); -} - -/* Write a PNG chunk all at once. The type is an array of ASCII characters - * representing the chunk name. The array must be at least 4 bytes in - * length, and does not need to be null terminated. To be safe, pass the - * pre-defined chunk names here, and if you need a new one, define it - * where the others are defined. The length is the length of the data. - * All the data must be present. If that is not possible, use the - * png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end() - * functions instead. - */ -static void -png_write_complete_chunk(png_structp png_ptr, png_uint_32 chunk_name, - png_const_bytep data, png_size_t length) -{ - if (png_ptr == NULL) - return; - - /* On 64 bit architectures 'length' may not fit in a png_uint_32. */ - if (length > PNG_UINT_32_MAX) - png_error(png_ptr, "length exceeds PNG maxima"); - - png_write_chunk_header(png_ptr, chunk_name, (png_uint_32)length); - png_write_chunk_data(png_ptr, data, length); - png_write_chunk_end(png_ptr); -} - -/* This is the API that calls the internal function above. */ -void PNGAPI -png_write_chunk(png_structp png_ptr, png_const_bytep chunk_string, - png_const_bytep data, png_size_t length) -{ - png_write_complete_chunk(png_ptr, PNG_CHUNK_FROM_STRING(chunk_string), data, - length); -} - -/* Initialize the compressor for the appropriate type of compression. */ -static void -png_zlib_claim(png_structp png_ptr, png_uint_32 state) -{ - if (!(png_ptr->zlib_state & PNG_ZLIB_IN_USE)) - { - /* If already initialized for 'state' do not re-init. */ - if (png_ptr->zlib_state != state) - { - int ret = Z_OK; - png_const_charp who = "-"; - - /* If actually initialized for another state do a deflateEnd. */ - if (png_ptr->zlib_state != PNG_ZLIB_UNINITIALIZED) - { - ret = deflateEnd(&png_ptr->zstream); - who = "end"; - png_ptr->zlib_state = PNG_ZLIB_UNINITIALIZED; - } - - /* zlib itself detects an incomplete state on deflateEnd */ - if (ret == Z_OK) switch (state) - { -# ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED - case PNG_ZLIB_FOR_TEXT: - ret = deflateInit2(&png_ptr->zstream, - png_ptr->zlib_text_level, png_ptr->zlib_text_method, - png_ptr->zlib_text_window_bits, - png_ptr->zlib_text_mem_level, png_ptr->zlib_text_strategy); - who = "text"; - break; -# endif - - case PNG_ZLIB_FOR_IDAT: - ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_level, - png_ptr->zlib_method, png_ptr->zlib_window_bits, - png_ptr->zlib_mem_level, png_ptr->zlib_strategy); - who = "IDAT"; - break; - - default: - png_error(png_ptr, "invalid zlib state"); - } - - if (ret == Z_OK) - png_ptr->zlib_state = state; - - else /* an error in deflateEnd or deflateInit2 */ - { - size_t pos = 0; - char msg[64]; - - pos = png_safecat(msg, sizeof msg, pos, - "zlib failed to initialize compressor ("); - pos = png_safecat(msg, sizeof msg, pos, who); - - switch (ret) - { - case Z_VERSION_ERROR: - pos = png_safecat(msg, sizeof msg, pos, ") version error"); - break; - - case Z_STREAM_ERROR: - pos = png_safecat(msg, sizeof msg, pos, ") stream error"); - break; - - case Z_MEM_ERROR: - pos = png_safecat(msg, sizeof msg, pos, ") memory error"); - break; - - default: - pos = png_safecat(msg, sizeof msg, pos, ") unknown error"); - break; - } - - png_error(png_ptr, msg); - } - } - - /* Here on success, claim the zstream: */ - png_ptr->zlib_state |= PNG_ZLIB_IN_USE; - } - - else - png_error(png_ptr, "zstream already in use (internal error)"); -} - -/* The opposite: release the stream. It is also reset, this API will warn on - * error but will not fail. - */ -static void -png_zlib_release(png_structp png_ptr) -{ - if (png_ptr->zlib_state & PNG_ZLIB_IN_USE) - { - int ret = deflateReset(&png_ptr->zstream); - - png_ptr->zlib_state &= ~PNG_ZLIB_IN_USE; - - if (ret != Z_OK) - { - png_const_charp err; - PNG_WARNING_PARAMETERS(p) - - switch (ret) - { - case Z_VERSION_ERROR: - err = "version"; - break; - - case Z_STREAM_ERROR: - err = "stream"; - break; - - case Z_MEM_ERROR: - err = "memory"; - break; - - default: - err = "unknown"; - break; - } - - png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, ret); - png_warning_parameter(p, 2, err); - - if (png_ptr->zstream.msg) - err = png_ptr->zstream.msg; - else - err = "[no zlib message]"; - - png_warning_parameter(p, 3, err); - - png_formatted_warning(png_ptr, p, - "zlib failed to reset compressor: @1(@2): @3"); - } - } - - else - png_warning(png_ptr, "zstream not in use (internal error)"); -} - -#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED -/* This pair of functions encapsulates the operation of (a) compressing a - * text string, and (b) issuing it later as a series of chunk data writes. - * The compression_state structure is shared context for these functions - * set up by the caller in order to make the whole mess thread-safe. - */ - -typedef struct -{ - png_const_bytep input; /* The uncompressed input data */ - png_size_t input_len; /* Its length */ - int num_output_ptr; /* Number of output pointers used */ - int max_output_ptr; /* Size of output_ptr */ - png_bytep *output_ptr; /* Array of pointers to output */ -} compression_state; - -/* Compress given text into storage in the png_ptr structure */ -static int /* PRIVATE */ -png_text_compress(png_structp png_ptr, - png_const_charp text, png_size_t text_len, int compression, - compression_state *comp) -{ - int ret; - - comp->num_output_ptr = 0; - comp->max_output_ptr = 0; - comp->output_ptr = NULL; - comp->input = NULL; - comp->input_len = text_len; - - /* We may just want to pass the text right through */ - if (compression == PNG_TEXT_COMPRESSION_NONE) - { - comp->input = (png_const_bytep)text; - return((int)text_len); - } - - if (compression >= PNG_TEXT_COMPRESSION_LAST) - { - PNG_WARNING_PARAMETERS(p) - - png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, - compression); - png_formatted_warning(png_ptr, p, "Unknown compression type @1"); - } - - /* We can't write the chunk until we find out how much data we have, - * which means we need to run the compressor first and save the - * output. This shouldn't be a problem, as the vast majority of - * comments should be reasonable, but we will set up an array of - * malloc'd pointers to be sure. - * - * If we knew the application was well behaved, we could simplify this - * greatly by assuming we can always malloc an output buffer large - * enough to hold the compressed text ((1001 * text_len / 1000) + 12) - * and malloc this directly. The only time this would be a bad idea is - * if we can't malloc more than 64K and we have 64K of random input - * data, or if the input string is incredibly large (although this - * wouldn't cause a failure, just a slowdown due to swapping). - */ - png_zlib_claim(png_ptr, PNG_ZLIB_FOR_TEXT); - - /* Set up the compression buffers */ - /* TODO: the following cast hides a potential overflow problem. */ - png_ptr->zstream.avail_in = (uInt)text_len; - - /* NOTE: assume zlib doesn't overwrite the input */ - png_ptr->zstream.next_in = (Bytef *)text; - png_ptr->zstream.avail_out = png_ptr->zbuf_size; - png_ptr->zstream.next_out = png_ptr->zbuf; - - /* This is the same compression loop as in png_write_row() */ - do - { - /* Compress the data */ - ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); - - if (ret != Z_OK) - { - /* Error */ - if (png_ptr->zstream.msg != NULL) - png_error(png_ptr, png_ptr->zstream.msg); - - else - png_error(png_ptr, "zlib error"); - } - - /* Check to see if we need more room */ - if (!(png_ptr->zstream.avail_out)) - { - /* Make sure the output array has room */ - if (comp->num_output_ptr >= comp->max_output_ptr) - { - int old_max; - - old_max = comp->max_output_ptr; - comp->max_output_ptr = comp->num_output_ptr + 4; - if (comp->output_ptr != NULL) - { - png_bytepp old_ptr; - - old_ptr = comp->output_ptr; - - comp->output_ptr = (png_bytepp)png_malloc(png_ptr, - (png_alloc_size_t) - (comp->max_output_ptr * png_sizeof(png_charpp))); - - png_memcpy(comp->output_ptr, old_ptr, old_max - * png_sizeof(png_charp)); - - png_free(png_ptr, old_ptr); - } - else - comp->output_ptr = (png_bytepp)png_malloc(png_ptr, - (png_alloc_size_t) - (comp->max_output_ptr * png_sizeof(png_charp))); - } - - /* Save the data */ - comp->output_ptr[comp->num_output_ptr] = - (png_bytep)png_malloc(png_ptr, - (png_alloc_size_t)png_ptr->zbuf_size); - - png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, - png_ptr->zbuf_size); - - comp->num_output_ptr++; - - /* and reset the buffer */ - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - png_ptr->zstream.next_out = png_ptr->zbuf; - } - /* Continue until we don't have any more to compress */ - } while (png_ptr->zstream.avail_in); - - /* Finish the compression */ - do - { - /* Tell zlib we are finished */ - ret = deflate(&png_ptr->zstream, Z_FINISH); - - if (ret == Z_OK) - { - /* Check to see if we need more room */ - if (!(png_ptr->zstream.avail_out)) - { - /* Check to make sure our output array has room */ - if (comp->num_output_ptr >= comp->max_output_ptr) - { - int old_max; - - old_max = comp->max_output_ptr; - comp->max_output_ptr = comp->num_output_ptr + 4; - if (comp->output_ptr != NULL) - { - png_bytepp old_ptr; - - old_ptr = comp->output_ptr; - - /* This could be optimized to realloc() */ - comp->output_ptr = (png_bytepp)png_malloc(png_ptr, - (png_alloc_size_t)(comp->max_output_ptr * - png_sizeof(png_charp))); - - png_memcpy(comp->output_ptr, old_ptr, - old_max * png_sizeof(png_charp)); - - png_free(png_ptr, old_ptr); - } - - else - comp->output_ptr = (png_bytepp)png_malloc(png_ptr, - (png_alloc_size_t)(comp->max_output_ptr * - png_sizeof(png_charp))); - } - - /* Save the data */ - comp->output_ptr[comp->num_output_ptr] = - (png_bytep)png_malloc(png_ptr, - (png_alloc_size_t)png_ptr->zbuf_size); - - png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, - png_ptr->zbuf_size); - - comp->num_output_ptr++; - - /* and reset the buffer pointers */ - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - png_ptr->zstream.next_out = png_ptr->zbuf; - } - } - else if (ret != Z_STREAM_END) - { - /* We got an error */ - if (png_ptr->zstream.msg != NULL) - png_error(png_ptr, png_ptr->zstream.msg); - - else - png_error(png_ptr, "zlib error"); - } - } while (ret != Z_STREAM_END); - - /* Text length is number of buffers plus last buffer */ - text_len = png_ptr->zbuf_size * comp->num_output_ptr; - - if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) - text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out; - - return((int)text_len); -} - -/* Ship the compressed text out via chunk writes */ -static void /* PRIVATE */ -png_write_compressed_data_out(png_structp png_ptr, compression_state *comp, - png_size_t data_len) -{ - int i; - - /* Handle the no-compression case */ - if (comp->input) - { - png_write_chunk_data(png_ptr, comp->input, data_len); - - return; - } - -#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED - /* The zbuf_size test is because the code below doesn't work if zbuf_size is - * '1'; simply skip it to avoid memory overwrite. - */ - if (data_len >= 2 && comp->input_len < 16384 && png_ptr->zbuf_size > 1) - { - unsigned int z_cmf; /* zlib compression method and flags */ - - /* Optimize the CMF field in the zlib stream. This hack of the zlib - * stream is compliant to the stream specification. - */ - - if (comp->num_output_ptr) - z_cmf = comp->output_ptr[0][0]; - else - z_cmf = png_ptr->zbuf[0]; - - if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70) - { - unsigned int z_cinfo; - unsigned int half_z_window_size; - png_size_t uncompressed_text_size = comp->input_len; - - z_cinfo = z_cmf >> 4; - half_z_window_size = 1 << (z_cinfo + 7); - - while (uncompressed_text_size <= half_z_window_size && - half_z_window_size >= 256) - { - z_cinfo--; - half_z_window_size >>= 1; - } - - z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4); - - if (comp->num_output_ptr) - { - - if (comp->output_ptr[0][0] != z_cmf) - { - int tmp; - - comp->output_ptr[0][0] = (png_byte)z_cmf; - tmp = comp->output_ptr[0][1] & 0xe0; - tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f; - comp->output_ptr[0][1] = (png_byte)tmp; - } - } - else - { - int tmp; - - png_ptr->zbuf[0] = (png_byte)z_cmf; - tmp = png_ptr->zbuf[1] & 0xe0; - tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f; - png_ptr->zbuf[1] = (png_byte)tmp; - } - } - - else - png_error(png_ptr, - "Invalid zlib compression method or flags in non-IDAT chunk"); - } -#endif /* PNG_WRITE_OPTIMIZE_CMF_SUPPORTED */ - - /* Write saved output buffers, if any */ - for (i = 0; i < comp->num_output_ptr; i++) - { - png_write_chunk_data(png_ptr, comp->output_ptr[i], - (png_size_t)png_ptr->zbuf_size); - - png_free(png_ptr, comp->output_ptr[i]); - } - - if (comp->max_output_ptr != 0) - png_free(png_ptr, comp->output_ptr); - - /* Write anything left in zbuf */ - if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size) - png_write_chunk_data(png_ptr, png_ptr->zbuf, - (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out)); - - /* Reset zlib for another zTXt/iTXt or image data */ - png_zlib_release(png_ptr); -} -#endif /* PNG_WRITE_COMPRESSED_TEXT_SUPPORTED */ - -/* Write the IHDR chunk, and update the png_struct with the necessary - * information. Note that the rest of this code depends upon this - * information being correct. - */ -void /* PRIVATE */ -png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, - int bit_depth, int color_type, int compression_type, int filter_type, - int interlace_type) -{ - png_byte buf[13]; /* Buffer to store the IHDR info */ - - png_debug(1, "in png_write_IHDR"); - - /* Check that we have valid input data from the application info */ - switch (color_type) - { - case PNG_COLOR_TYPE_GRAY: - switch (bit_depth) - { - case 1: - case 2: - case 4: - case 8: -#ifdef PNG_WRITE_16BIT_SUPPORTED - case 16: -#endif - png_ptr->channels = 1; break; - - default: - png_error(png_ptr, - "Invalid bit depth for grayscale image"); - } - break; - - case PNG_COLOR_TYPE_RGB: -#ifdef PNG_WRITE_16BIT_SUPPORTED - if (bit_depth != 8 && bit_depth != 16) -#else - if (bit_depth != 8) -#endif - png_error(png_ptr, "Invalid bit depth for RGB image"); - - png_ptr->channels = 3; - break; - - case PNG_COLOR_TYPE_PALETTE: - switch (bit_depth) - { - case 1: - case 2: - case 4: - case 8: - png_ptr->channels = 1; - break; - - default: - png_error(png_ptr, "Invalid bit depth for paletted image"); - } - break; - - case PNG_COLOR_TYPE_GRAY_ALPHA: - if (bit_depth != 8 && bit_depth != 16) - png_error(png_ptr, "Invalid bit depth for grayscale+alpha image"); - - png_ptr->channels = 2; - break; - - case PNG_COLOR_TYPE_RGB_ALPHA: -#ifdef PNG_WRITE_16BIT_SUPPORTED - if (bit_depth != 8 && bit_depth != 16) -#else - if (bit_depth != 8) -#endif - png_error(png_ptr, "Invalid bit depth for RGBA image"); - - png_ptr->channels = 4; - break; - - default: - png_error(png_ptr, "Invalid image color type specified"); - } - - if (compression_type != PNG_COMPRESSION_TYPE_BASE) - { - png_warning(png_ptr, "Invalid compression type specified"); - compression_type = PNG_COMPRESSION_TYPE_BASE; - } - - /* Write filter_method 64 (intrapixel differencing) only if - * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and - * 2. Libpng did not write a PNG signature (this filter_method is only - * used in PNG datastreams that are embedded in MNG datastreams) and - * 3. The application called png_permit_mng_features with a mask that - * included PNG_FLAG_MNG_FILTER_64 and - * 4. The filter_method is 64 and - * 5. The color_type is RGB or RGBA - */ - if ( -#ifdef PNG_MNG_FEATURES_SUPPORTED - !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && - ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && - (color_type == PNG_COLOR_TYPE_RGB || - color_type == PNG_COLOR_TYPE_RGB_ALPHA) && - (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) && -#endif - filter_type != PNG_FILTER_TYPE_BASE) - { - png_warning(png_ptr, "Invalid filter type specified"); - filter_type = PNG_FILTER_TYPE_BASE; - } - -#ifdef PNG_WRITE_INTERLACING_SUPPORTED - if (interlace_type != PNG_INTERLACE_NONE && - interlace_type != PNG_INTERLACE_ADAM7) - { - png_warning(png_ptr, "Invalid interlace type specified"); - interlace_type = PNG_INTERLACE_ADAM7; - } -#else - interlace_type=PNG_INTERLACE_NONE; -#endif - - /* Save the relevent information */ - png_ptr->bit_depth = (png_byte)bit_depth; - png_ptr->color_type = (png_byte)color_type; - png_ptr->interlaced = (png_byte)interlace_type; -#ifdef PNG_MNG_FEATURES_SUPPORTED - png_ptr->filter_type = (png_byte)filter_type; -#endif - png_ptr->compression_type = (png_byte)compression_type; - png_ptr->width = width; - png_ptr->height = height; - - png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels); - png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width); - /* Set the usr info, so any transformations can modify it */ - png_ptr->usr_width = png_ptr->width; - png_ptr->usr_bit_depth = png_ptr->bit_depth; - png_ptr->usr_channels = png_ptr->channels; - - /* Pack the header information into the buffer */ - png_save_uint_32(buf, width); - png_save_uint_32(buf + 4, height); - buf[8] = (png_byte)bit_depth; - buf[9] = (png_byte)color_type; - buf[10] = (png_byte)compression_type; - buf[11] = (png_byte)filter_type; - buf[12] = (png_byte)interlace_type; - - /* Write the chunk */ - png_write_complete_chunk(png_ptr, png_IHDR, buf, (png_size_t)13); - - /* Initialize zlib with PNG info */ - png_ptr->zstream.zalloc = png_zalloc; - png_ptr->zstream.zfree = png_zfree; - png_ptr->zstream.opaque = (voidpf)png_ptr; - - if (!(png_ptr->do_filter)) - { - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE || - png_ptr->bit_depth < 8) - png_ptr->do_filter = PNG_FILTER_NONE; - - else - png_ptr->do_filter = PNG_ALL_FILTERS; - } - - if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY)) - { - if (png_ptr->do_filter != PNG_FILTER_NONE) - png_ptr->zlib_strategy = Z_FILTERED; - - else - png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY; - } - - if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL)) - png_ptr->zlib_level = Z_DEFAULT_COMPRESSION; - - if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL)) - png_ptr->zlib_mem_level = 8; - - if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS)) - png_ptr->zlib_window_bits = 15; - - if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD)) - png_ptr->zlib_method = 8; - -#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED -#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED - if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_STRATEGY)) - png_ptr->zlib_text_strategy = Z_DEFAULT_STRATEGY; - - if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_LEVEL)) - png_ptr->zlib_text_level = png_ptr->zlib_level; - - if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL)) - png_ptr->zlib_text_mem_level = png_ptr->zlib_mem_level; - - if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS)) - png_ptr->zlib_text_window_bits = png_ptr->zlib_window_bits; - - if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_METHOD)) - png_ptr->zlib_text_method = png_ptr->zlib_method; -#else - png_ptr->zlib_text_strategy = Z_DEFAULT_STRATEGY; - png_ptr->zlib_text_level = png_ptr->zlib_level; - png_ptr->zlib_text_mem_level = png_ptr->zlib_mem_level; - png_ptr->zlib_text_window_bits = png_ptr->zlib_window_bits; - png_ptr->zlib_text_method = png_ptr->zlib_method; -#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */ -#endif /* PNG_WRITE_COMPRESSED_TEXT_SUPPORTED */ - - /* Record that the compressor has not yet been initialized. */ - png_ptr->zlib_state = PNG_ZLIB_UNINITIALIZED; - - png_ptr->mode = PNG_HAVE_IHDR; /* not READY_FOR_ZTXT */ -} - -/* Write the palette. We are careful not to trust png_color to be in the - * correct order for PNG, so people can redefine it to any convenient - * structure. - */ -void /* PRIVATE */ -png_write_PLTE(png_structp png_ptr, png_const_colorp palette, - png_uint_32 num_pal) -{ - png_uint_32 i; - png_const_colorp pal_ptr; - png_byte buf[3]; - - png_debug(1, "in png_write_PLTE"); - - if (( -#ifdef PNG_MNG_FEATURES_SUPPORTED - !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && -#endif - num_pal == 0) || num_pal > 256) - { - if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - { - png_error(png_ptr, "Invalid number of colors in palette"); - } - - else - { - png_warning(png_ptr, "Invalid number of colors in palette"); - return; - } - } - - if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) - { - png_warning(png_ptr, - "Ignoring request to write a PLTE chunk in grayscale PNG"); - - return; - } - - png_ptr->num_palette = (png_uint_16)num_pal; - png_debug1(3, "num_palette = %d", png_ptr->num_palette); - - png_write_chunk_header(png_ptr, png_PLTE, (png_uint_32)(num_pal * 3)); -#ifdef PNG_POINTER_INDEXING_SUPPORTED - - for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++) - { - buf[0] = pal_ptr->red; - buf[1] = pal_ptr->green; - buf[2] = pal_ptr->blue; - png_write_chunk_data(png_ptr, buf, (png_size_t)3); - } - -#else - /* This is a little slower but some buggy compilers need to do this - * instead - */ - pal_ptr=palette; - - for (i = 0; i < num_pal; i++) - { - buf[0] = pal_ptr[i].red; - buf[1] = pal_ptr[i].green; - buf[2] = pal_ptr[i].blue; - png_write_chunk_data(png_ptr, buf, (png_size_t)3); - } - -#endif - png_write_chunk_end(png_ptr); - png_ptr->mode |= PNG_HAVE_PLTE; -} - -/* Write an IDAT chunk */ -void /* PRIVATE */ -png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) -{ - png_debug(1, "in png_write_IDAT"); - -#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED - if (!(png_ptr->mode & PNG_HAVE_IDAT) && - png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE) - { - /* Optimize the CMF field in the zlib stream. This hack of the zlib - * stream is compliant to the stream specification. - */ - unsigned int z_cmf = data[0]; /* zlib compression method and flags */ - - if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70) - { - /* Avoid memory underflows and multiplication overflows. - * - * The conditions below are practically always satisfied; - * however, they still must be checked. - */ - if (length >= 2 && - png_ptr->height < 16384 && png_ptr->width < 16384) - { - /* Compute the maximum possible length of the datastream */ - - /* Number of pixels, plus for each row a filter byte - * and possibly a padding byte, so increase the maximum - * size to account for these. - */ - unsigned int z_cinfo; - unsigned int half_z_window_size; - png_uint_32 uncompressed_idat_size = png_ptr->height * - ((png_ptr->width * - png_ptr->channels * png_ptr->bit_depth + 15) >> 3); - - /* If it's interlaced, each block of 8 rows is sent as up to - * 14 rows, i.e., 6 additional rows, each with a filter byte - * and possibly a padding byte - */ - if (png_ptr->interlaced) - uncompressed_idat_size += ((png_ptr->height + 7)/8) * - (png_ptr->bit_depth < 8 ? 12 : 6); - - z_cinfo = z_cmf >> 4; - half_z_window_size = 1 << (z_cinfo + 7); - - while (uncompressed_idat_size <= half_z_window_size && - half_z_window_size >= 256) - { - z_cinfo--; - half_z_window_size >>= 1; - } - - z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4); - - if (data[0] != z_cmf) - { - int tmp; - data[0] = (png_byte)z_cmf; - tmp = data[1] & 0xe0; - tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f; - data[1] = (png_byte)tmp; - } - } - } - - else - png_error(png_ptr, - "Invalid zlib compression method or flags in IDAT"); - } -#endif /* PNG_WRITE_OPTIMIZE_CMF_SUPPORTED */ - - png_write_complete_chunk(png_ptr, png_IDAT, data, length); - png_ptr->mode |= PNG_HAVE_IDAT; - - /* Prior to 1.5.4 this code was replicated in every caller (except at the - * end, where it isn't technically necessary). Since this function has - * flushed the data we can safely reset the zlib output buffer here. - */ - png_ptr->zstream.next_out = png_ptr->zbuf; - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; -} - -/* Write an IEND chunk */ -void /* PRIVATE */ -png_write_IEND(png_structp png_ptr) -{ - png_debug(1, "in png_write_IEND"); - - png_write_complete_chunk(png_ptr, png_IEND, NULL, (png_size_t)0); - png_ptr->mode |= PNG_HAVE_IEND; -} - -#ifdef PNG_WRITE_gAMA_SUPPORTED -/* Write a gAMA chunk */ -void /* PRIVATE */ -png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma) -{ - png_byte buf[4]; - - png_debug(1, "in png_write_gAMA"); - - /* file_gamma is saved in 1/100,000ths */ - png_save_uint_32(buf, (png_uint_32)file_gamma); - png_write_complete_chunk(png_ptr, png_gAMA, buf, (png_size_t)4); -} -#endif - -#ifdef PNG_WRITE_sRGB_SUPPORTED -/* Write a sRGB chunk */ -void /* PRIVATE */ -png_write_sRGB(png_structp png_ptr, int srgb_intent) -{ - png_byte buf[1]; - - png_debug(1, "in png_write_sRGB"); - - if (srgb_intent >= PNG_sRGB_INTENT_LAST) - png_warning(png_ptr, - "Invalid sRGB rendering intent specified"); - - buf[0]=(png_byte)srgb_intent; - png_write_complete_chunk(png_ptr, png_sRGB, buf, (png_size_t)1); -} -#endif - -#ifdef PNG_WRITE_iCCP_SUPPORTED -/* Write an iCCP chunk */ -void /* PRIVATE */ -png_write_iCCP(png_structp png_ptr, png_const_charp name, int compression_type, - png_const_charp profile, int profile_len) -{ - png_size_t name_len; - png_charp new_name; - compression_state comp; - int embedded_profile_len = 0; - - png_debug(1, "in png_write_iCCP"); - - comp.num_output_ptr = 0; - comp.max_output_ptr = 0; - comp.output_ptr = NULL; - comp.input = NULL; - comp.input_len = 0; - - if ((name_len = png_check_keyword(png_ptr, name, &new_name)) == 0) - return; - - if (compression_type != PNG_COMPRESSION_TYPE_BASE) - png_warning(png_ptr, "Unknown compression type in iCCP chunk"); - - if (profile == NULL) - profile_len = 0; - - if (profile_len > 3) - embedded_profile_len = - ((*( (png_const_bytep)profile ))<<24) | - ((*( (png_const_bytep)profile + 1))<<16) | - ((*( (png_const_bytep)profile + 2))<< 8) | - ((*( (png_const_bytep)profile + 3)) ); - - if (embedded_profile_len < 0) - { - png_warning(png_ptr, - "Embedded profile length in iCCP chunk is negative"); - - png_free(png_ptr, new_name); - return; - } - - if (profile_len < embedded_profile_len) - { - png_warning(png_ptr, - "Embedded profile length too large in iCCP chunk"); - - png_free(png_ptr, new_name); - return; - } - - if (profile_len > embedded_profile_len) - { - png_warning(png_ptr, - "Truncating profile to actual length in iCCP chunk"); - - profile_len = embedded_profile_len; - } - - if (profile_len) - profile_len = png_text_compress(png_ptr, profile, - (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp); - - /* Make sure we include the NULL after the name and the compression type */ - png_write_chunk_header(png_ptr, png_iCCP, - (png_uint_32)(name_len + profile_len + 2)); - - new_name[name_len + 1] = 0x00; - - png_write_chunk_data(png_ptr, (png_bytep)new_name, - (png_size_t)(name_len + 2)); - - if (profile_len) - { - png_write_compressed_data_out(png_ptr, &comp, profile_len); - } - - png_write_chunk_end(png_ptr); - png_free(png_ptr, new_name); -} -#endif - -#ifdef PNG_WRITE_sPLT_SUPPORTED -/* Write a sPLT chunk */ -void /* PRIVATE */ -png_write_sPLT(png_structp png_ptr, png_const_sPLT_tp spalette) -{ - png_size_t name_len; - png_charp new_name; - png_byte entrybuf[10]; - png_size_t entry_size = (spalette->depth == 8 ? 6 : 10); - png_size_t palette_size = entry_size * spalette->nentries; - png_sPLT_entryp ep; -#ifndef PNG_POINTER_INDEXING_SUPPORTED - int i; -#endif - - png_debug(1, "in png_write_sPLT"); - - if ((name_len = png_check_keyword(png_ptr,spalette->name, &new_name))==0) - return; - - /* Make sure we include the NULL after the name */ - png_write_chunk_header(png_ptr, png_sPLT, - (png_uint_32)(name_len + 2 + palette_size)); - - png_write_chunk_data(png_ptr, (png_bytep)new_name, - (png_size_t)(name_len + 1)); - - png_write_chunk_data(png_ptr, &spalette->depth, (png_size_t)1); - - /* Loop through each palette entry, writing appropriately */ -#ifdef PNG_POINTER_INDEXING_SUPPORTED - for (ep = spalette->entries; epentries + spalette->nentries; ep++) - { - if (spalette->depth == 8) - { - entrybuf[0] = (png_byte)ep->red; - entrybuf[1] = (png_byte)ep->green; - entrybuf[2] = (png_byte)ep->blue; - entrybuf[3] = (png_byte)ep->alpha; - png_save_uint_16(entrybuf + 4, ep->frequency); - } - - else - { - png_save_uint_16(entrybuf + 0, ep->red); - png_save_uint_16(entrybuf + 2, ep->green); - png_save_uint_16(entrybuf + 4, ep->blue); - png_save_uint_16(entrybuf + 6, ep->alpha); - png_save_uint_16(entrybuf + 8, ep->frequency); - } - - png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); - } -#else - ep=spalette->entries; - for (i = 0; i>spalette->nentries; i++) - { - if (spalette->depth == 8) - { - entrybuf[0] = (png_byte)ep[i].red; - entrybuf[1] = (png_byte)ep[i].green; - entrybuf[2] = (png_byte)ep[i].blue; - entrybuf[3] = (png_byte)ep[i].alpha; - png_save_uint_16(entrybuf + 4, ep[i].frequency); - } - - else - { - png_save_uint_16(entrybuf + 0, ep[i].red); - png_save_uint_16(entrybuf + 2, ep[i].green); - png_save_uint_16(entrybuf + 4, ep[i].blue); - png_save_uint_16(entrybuf + 6, ep[i].alpha); - png_save_uint_16(entrybuf + 8, ep[i].frequency); - } - - png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); - } -#endif - - png_write_chunk_end(png_ptr); - png_free(png_ptr, new_name); -} -#endif - -#ifdef PNG_WRITE_sBIT_SUPPORTED -/* Write the sBIT chunk */ -void /* PRIVATE */ -png_write_sBIT(png_structp png_ptr, png_const_color_8p sbit, int color_type) -{ - png_byte buf[4]; - png_size_t size; - - png_debug(1, "in png_write_sBIT"); - - /* Make sure we don't depend upon the order of PNG_COLOR_8 */ - if (color_type & PNG_COLOR_MASK_COLOR) - { - png_byte maxbits; - - maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 : - png_ptr->usr_bit_depth); - - if (sbit->red == 0 || sbit->red > maxbits || - sbit->green == 0 || sbit->green > maxbits || - sbit->blue == 0 || sbit->blue > maxbits) - { - png_warning(png_ptr, "Invalid sBIT depth specified"); - return; - } - - buf[0] = sbit->red; - buf[1] = sbit->green; - buf[2] = sbit->blue; - size = 3; - } - - else - { - if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth) - { - png_warning(png_ptr, "Invalid sBIT depth specified"); - return; - } - - buf[0] = sbit->gray; - size = 1; - } - - if (color_type & PNG_COLOR_MASK_ALPHA) - { - if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth) - { - png_warning(png_ptr, "Invalid sBIT depth specified"); - return; - } - - buf[size++] = sbit->alpha; - } - - png_write_complete_chunk(png_ptr, png_sBIT, buf, size); -} -#endif - -#ifdef PNG_WRITE_cHRM_SUPPORTED -/* Write the cHRM chunk */ -void /* PRIVATE */ -png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x, - png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y, - png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x, - png_fixed_point blue_y) -{ - png_byte buf[32]; - - png_debug(1, "in png_write_cHRM"); - - /* Each value is saved in 1/100,000ths */ -#ifdef PNG_CHECK_cHRM_SUPPORTED - if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y, - green_x, green_y, blue_x, blue_y)) -#endif - { - png_save_uint_32(buf, (png_uint_32)white_x); - png_save_uint_32(buf + 4, (png_uint_32)white_y); - - png_save_uint_32(buf + 8, (png_uint_32)red_x); - png_save_uint_32(buf + 12, (png_uint_32)red_y); - - png_save_uint_32(buf + 16, (png_uint_32)green_x); - png_save_uint_32(buf + 20, (png_uint_32)green_y); - - png_save_uint_32(buf + 24, (png_uint_32)blue_x); - png_save_uint_32(buf + 28, (png_uint_32)blue_y); - - png_write_complete_chunk(png_ptr, png_cHRM, buf, (png_size_t)32); - } -} -#endif - -#ifdef PNG_WRITE_tRNS_SUPPORTED -/* Write the tRNS chunk */ -void /* PRIVATE */ -png_write_tRNS(png_structp png_ptr, png_const_bytep trans_alpha, - png_const_color_16p tran, int num_trans, int color_type) -{ - png_byte buf[6]; - - png_debug(1, "in png_write_tRNS"); - - if (color_type == PNG_COLOR_TYPE_PALETTE) - { - if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette) - { - png_warning(png_ptr, "Invalid number of transparent colors specified"); - return; - } - - /* Write the chunk out as it is */ - png_write_complete_chunk(png_ptr, png_tRNS, trans_alpha, - (png_size_t)num_trans); - } - - else if (color_type == PNG_COLOR_TYPE_GRAY) - { - /* One 16 bit value */ - if (tran->gray >= (1 << png_ptr->bit_depth)) - { - png_warning(png_ptr, - "Ignoring attempt to write tRNS chunk out-of-range for bit_depth"); - - return; - } - - png_save_uint_16(buf, tran->gray); - png_write_complete_chunk(png_ptr, png_tRNS, buf, (png_size_t)2); - } - - else if (color_type == PNG_COLOR_TYPE_RGB) - { - /* Three 16 bit values */ - png_save_uint_16(buf, tran->red); - png_save_uint_16(buf + 2, tran->green); - png_save_uint_16(buf + 4, tran->blue); -#ifdef PNG_WRITE_16BIT_SUPPORTED - if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) -#else - if (buf[0] | buf[2] | buf[4]) -#endif - { - png_warning(png_ptr, - "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8"); - return; - } - - png_write_complete_chunk(png_ptr, png_tRNS, buf, (png_size_t)6); - } - - else - { - png_warning(png_ptr, "Can't write tRNS with an alpha channel"); - } -} -#endif - -#ifdef PNG_WRITE_bKGD_SUPPORTED -/* Write the background chunk */ -void /* PRIVATE */ -png_write_bKGD(png_structp png_ptr, png_const_color_16p back, int color_type) -{ - png_byte buf[6]; - - png_debug(1, "in png_write_bKGD"); - - if (color_type == PNG_COLOR_TYPE_PALETTE) - { - if ( -#ifdef PNG_MNG_FEATURES_SUPPORTED - (png_ptr->num_palette || - (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) && -#endif - back->index >= png_ptr->num_palette) - { - png_warning(png_ptr, "Invalid background palette index"); - return; - } - - buf[0] = back->index; - png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)1); - } - - else if (color_type & PNG_COLOR_MASK_COLOR) - { - png_save_uint_16(buf, back->red); - png_save_uint_16(buf + 2, back->green); - png_save_uint_16(buf + 4, back->blue); -#ifdef PNG_WRITE_16BIT_SUPPORTED - if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) -#else - if (buf[0] | buf[2] | buf[4]) -#endif - { - png_warning(png_ptr, - "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8"); - - return; - } - - png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)6); - } - - else - { - if (back->gray >= (1 << png_ptr->bit_depth)) - { - png_warning(png_ptr, - "Ignoring attempt to write bKGD chunk out-of-range for bit_depth"); - - return; - } - - png_save_uint_16(buf, back->gray); - png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)2); - } -} -#endif - -#ifdef PNG_WRITE_hIST_SUPPORTED -/* Write the histogram */ -void /* PRIVATE */ -png_write_hIST(png_structp png_ptr, png_const_uint_16p hist, int num_hist) -{ - int i; - png_byte buf[3]; - - png_debug(1, "in png_write_hIST"); - - if (num_hist > (int)png_ptr->num_palette) - { - png_debug2(3, "num_hist = %d, num_palette = %d", num_hist, - png_ptr->num_palette); - - png_warning(png_ptr, "Invalid number of histogram entries specified"); - return; - } - - png_write_chunk_header(png_ptr, png_hIST, (png_uint_32)(num_hist * 2)); - - for (i = 0; i < num_hist; i++) - { - png_save_uint_16(buf, hist[i]); - png_write_chunk_data(png_ptr, buf, (png_size_t)2); - } - - png_write_chunk_end(png_ptr); -} -#endif - -#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ - defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) -/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification, - * and if invalid, correct the keyword rather than discarding the entire - * chunk. The PNG 1.0 specification requires keywords 1-79 characters in - * length, forbids leading or trailing whitespace, multiple internal spaces, - * and the non-break space (0x80) from ISO 8859-1. Returns keyword length. - * - * The new_key is allocated to hold the corrected keyword and must be freed - * by the calling routine. This avoids problems with trying to write to - * static keywords without having to have duplicate copies of the strings. - */ -png_size_t /* PRIVATE */ -png_check_keyword(png_structp png_ptr, png_const_charp key, png_charpp new_key) -{ - png_size_t key_len; - png_const_charp ikp; - png_charp kp, dp; - int kflag; - int kwarn=0; - - png_debug(1, "in png_check_keyword"); - - *new_key = NULL; - - if (key == NULL || (key_len = png_strlen(key)) == 0) - { - png_warning(png_ptr, "zero length keyword"); - return ((png_size_t)0); - } - - png_debug1(2, "Keyword to be checked is '%s'", key); - - *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2)); - - if (*new_key == NULL) - { - png_warning(png_ptr, "Out of memory while procesing keyword"); - return ((png_size_t)0); - } - - /* Replace non-printing characters with a blank and print a warning */ - for (ikp = key, dp = *new_key; *ikp != '\0'; ikp++, dp++) - { - if ((png_byte)*ikp < 0x20 || - ((png_byte)*ikp > 0x7E && (png_byte)*ikp < 0xA1)) - { - PNG_WARNING_PARAMETERS(p) - - png_warning_parameter_unsigned(p, 1, PNG_NUMBER_FORMAT_02x, - (png_byte)*ikp); - png_formatted_warning(png_ptr, p, "invalid keyword character 0x@1"); - *dp = ' '; - } - - else - { - *dp = *ikp; - } - } - *dp = '\0'; - - /* Remove any trailing white space. */ - kp = *new_key + key_len - 1; - if (*kp == ' ') - { - png_warning(png_ptr, "trailing spaces removed from keyword"); - - while (*kp == ' ') - { - *(kp--) = '\0'; - key_len--; - } - } - - /* Remove any leading white space. */ - kp = *new_key; - if (*kp == ' ') - { - png_warning(png_ptr, "leading spaces removed from keyword"); - - while (*kp == ' ') - { - kp++; - key_len--; - } - } - - png_debug1(2, "Checking for multiple internal spaces in '%s'", kp); - - /* Remove multiple internal spaces. */ - for (kflag = 0, dp = *new_key; *kp != '\0'; kp++) - { - if (*kp == ' ' && kflag == 0) - { - *(dp++) = *kp; - kflag = 1; - } - - else if (*kp == ' ') - { - key_len--; - kwarn = 1; - } - - else - { - *(dp++) = *kp; - kflag = 0; - } - } - *dp = '\0'; - if (kwarn) - png_warning(png_ptr, "extra interior spaces removed from keyword"); - - if (key_len == 0) - { - png_free(png_ptr, *new_key); - png_warning(png_ptr, "Zero length keyword"); - } - - if (key_len > 79) - { - png_warning(png_ptr, "keyword length must be 1 - 79 characters"); - (*new_key)[79] = '\0'; - key_len = 79; - } - - return (key_len); -} -#endif - -#ifdef PNG_WRITE_tEXt_SUPPORTED -/* Write a tEXt chunk */ -void /* PRIVATE */ -png_write_tEXt(png_structp png_ptr, png_const_charp key, png_const_charp text, - png_size_t text_len) -{ - png_size_t key_len; - png_charp new_key; - - png_debug(1, "in png_write_tEXt"); - - if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) - return; - - if (text == NULL || *text == '\0') - text_len = 0; - - else - text_len = png_strlen(text); - - /* Make sure we include the 0 after the key */ - png_write_chunk_header(png_ptr, png_tEXt, - (png_uint_32)(key_len + text_len + 1)); - /* - * We leave it to the application to meet PNG-1.0 requirements on the - * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of - * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. - * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. - */ - png_write_chunk_data(png_ptr, (png_bytep)new_key, - (png_size_t)(key_len + 1)); - - if (text_len) - png_write_chunk_data(png_ptr, (png_const_bytep)text, - (png_size_t)text_len); - - png_write_chunk_end(png_ptr); - png_free(png_ptr, new_key); -} -#endif - -#ifdef PNG_WRITE_zTXt_SUPPORTED -/* Write a compressed text chunk */ -void /* PRIVATE */ -png_write_zTXt(png_structp png_ptr, png_const_charp key, png_const_charp text, - png_size_t text_len, int compression) -{ - png_size_t key_len; - png_byte buf; - png_charp new_key; - compression_state comp; - - png_debug(1, "in png_write_zTXt"); - - comp.num_output_ptr = 0; - comp.max_output_ptr = 0; - comp.output_ptr = NULL; - comp.input = NULL; - comp.input_len = 0; - - if ((key_len = png_check_keyword(png_ptr, key, &new_key)) == 0) - { - png_free(png_ptr, new_key); - return; - } - - if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE) - { - png_write_tEXt(png_ptr, new_key, text, (png_size_t)0); - png_free(png_ptr, new_key); - return; - } - - text_len = png_strlen(text); - - /* Compute the compressed data; do it now for the length */ - text_len = png_text_compress(png_ptr, text, text_len, compression, - &comp); - - /* Write start of chunk */ - png_write_chunk_header(png_ptr, png_zTXt, - (png_uint_32)(key_len+text_len + 2)); - - /* Write key */ - png_write_chunk_data(png_ptr, (png_bytep)new_key, - (png_size_t)(key_len + 1)); - - png_free(png_ptr, new_key); - - buf = (png_byte)compression; - - /* Write compression */ - png_write_chunk_data(png_ptr, &buf, (png_size_t)1); - - /* Write the compressed data */ - png_write_compressed_data_out(png_ptr, &comp, text_len); - - /* Close the chunk */ - png_write_chunk_end(png_ptr); -} -#endif - -#ifdef PNG_WRITE_iTXt_SUPPORTED -/* Write an iTXt chunk */ -void /* PRIVATE */ -png_write_iTXt(png_structp png_ptr, int compression, png_const_charp key, - png_const_charp lang, png_const_charp lang_key, png_const_charp text) -{ - png_size_t lang_len, key_len, lang_key_len, text_len; - png_charp new_lang; - png_charp new_key = NULL; - png_byte cbuf[2]; - compression_state comp; - - png_debug(1, "in png_write_iTXt"); - - comp.num_output_ptr = 0; - comp.max_output_ptr = 0; - comp.output_ptr = NULL; - comp.input = NULL; - - if ((key_len = png_check_keyword(png_ptr, key, &new_key)) == 0) - return; - - if ((lang_len = png_check_keyword(png_ptr, lang, &new_lang)) == 0) - { - png_warning(png_ptr, "Empty language field in iTXt chunk"); - new_lang = NULL; - lang_len = 0; - } - - if (lang_key == NULL) - lang_key_len = 0; - - else - lang_key_len = png_strlen(lang_key); - - if (text == NULL) - text_len = 0; - - else - text_len = png_strlen(text); - - /* Compute the compressed data; do it now for the length */ - text_len = png_text_compress(png_ptr, text, text_len, compression - 2, - &comp); - - - /* Make sure we include the compression flag, the compression byte, - * and the NULs after the key, lang, and lang_key parts - */ - - png_write_chunk_header(png_ptr, png_iTXt, (png_uint_32)( - 5 /* comp byte, comp flag, terminators for key, lang and lang_key */ - + key_len - + lang_len - + lang_key_len - + text_len)); - - /* We leave it to the application to meet PNG-1.0 requirements on the - * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of - * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. - * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. - */ - png_write_chunk_data(png_ptr, (png_bytep)new_key, (png_size_t)(key_len + 1)); - - /* Set the compression flag */ - if (compression == PNG_ITXT_COMPRESSION_NONE || - compression == PNG_TEXT_COMPRESSION_NONE) - cbuf[0] = 0; - - else /* compression == PNG_ITXT_COMPRESSION_zTXt */ - cbuf[0] = 1; - - /* Set the compression method */ - cbuf[1] = 0; - - png_write_chunk_data(png_ptr, cbuf, (png_size_t)2); - - cbuf[0] = 0; - png_write_chunk_data(png_ptr, (new_lang ? (png_const_bytep)new_lang : cbuf), - (png_size_t)(lang_len + 1)); - - png_write_chunk_data(png_ptr, (lang_key ? (png_const_bytep)lang_key : cbuf), - (png_size_t)(lang_key_len + 1)); - - png_write_compressed_data_out(png_ptr, &comp, text_len); - - png_write_chunk_end(png_ptr); - - png_free(png_ptr, new_key); - png_free(png_ptr, new_lang); -} -#endif - -#ifdef PNG_WRITE_oFFs_SUPPORTED -/* Write the oFFs chunk */ -void /* PRIVATE */ -png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, - int unit_type) -{ - png_byte buf[9]; - - png_debug(1, "in png_write_oFFs"); - - if (unit_type >= PNG_OFFSET_LAST) - png_warning(png_ptr, "Unrecognized unit type for oFFs chunk"); - - png_save_int_32(buf, x_offset); - png_save_int_32(buf + 4, y_offset); - buf[8] = (png_byte)unit_type; - - png_write_complete_chunk(png_ptr, png_oFFs, buf, (png_size_t)9); -} -#endif -#ifdef PNG_WRITE_pCAL_SUPPORTED -/* Write the pCAL chunk (described in the PNG extensions document) */ -void /* PRIVATE */ -png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, - png_int_32 X1, int type, int nparams, png_const_charp units, - png_charpp params) -{ - png_size_t purpose_len, units_len, total_len; - png_size_tp params_len; - png_byte buf[10]; - png_charp new_purpose; - int i; - - png_debug1(1, "in png_write_pCAL (%d parameters)", nparams); - - if (type >= PNG_EQUATION_LAST) - png_warning(png_ptr, "Unrecognized equation type for pCAL chunk"); - - purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1; - png_debug1(3, "pCAL purpose length = %d", (int)purpose_len); - units_len = png_strlen(units) + (nparams == 0 ? 0 : 1); - png_debug1(3, "pCAL units length = %d", (int)units_len); - total_len = purpose_len + units_len + 10; - - params_len = (png_size_tp)png_malloc(png_ptr, - (png_alloc_size_t)(nparams * png_sizeof(png_size_t))); - - /* Find the length of each parameter, making sure we don't count the - * null terminator for the last parameter. - */ - for (i = 0; i < nparams; i++) - { - params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1); - png_debug2(3, "pCAL parameter %d length = %lu", i, - (unsigned long)params_len[i]); - total_len += params_len[i]; - } - - png_debug1(3, "pCAL total length = %d", (int)total_len); - png_write_chunk_header(png_ptr, png_pCAL, (png_uint_32)total_len); - png_write_chunk_data(png_ptr, (png_const_bytep)new_purpose, purpose_len); - png_save_int_32(buf, X0); - png_save_int_32(buf + 4, X1); - buf[8] = (png_byte)type; - buf[9] = (png_byte)nparams; - png_write_chunk_data(png_ptr, buf, (png_size_t)10); - png_write_chunk_data(png_ptr, (png_const_bytep)units, (png_size_t)units_len); - - png_free(png_ptr, new_purpose); - - for (i = 0; i < nparams; i++) - { - png_write_chunk_data(png_ptr, (png_const_bytep)params[i], params_len[i]); - } - - png_free(png_ptr, params_len); - png_write_chunk_end(png_ptr); -} -#endif - -#ifdef PNG_WRITE_sCAL_SUPPORTED -/* Write the sCAL chunk */ -void /* PRIVATE */ -png_write_sCAL_s(png_structp png_ptr, int unit, png_const_charp width, - png_const_charp height) -{ - png_byte buf[64]; - png_size_t wlen, hlen, total_len; - - png_debug(1, "in png_write_sCAL_s"); - - wlen = png_strlen(width); - hlen = png_strlen(height); - total_len = wlen + hlen + 2; - - if (total_len > 64) - { - png_warning(png_ptr, "Can't write sCAL (buffer too small)"); - return; - } - - buf[0] = (png_byte)unit; - png_memcpy(buf + 1, width, wlen + 1); /* Append the '\0' here */ - png_memcpy(buf + wlen + 2, height, hlen); /* Do NOT append the '\0' here */ - - png_debug1(3, "sCAL total length = %u", (unsigned int)total_len); - png_write_complete_chunk(png_ptr, png_sCAL, buf, total_len); -} -#endif - -#ifdef PNG_WRITE_pHYs_SUPPORTED -/* Write the pHYs chunk */ -void /* PRIVATE */ -png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, - png_uint_32 y_pixels_per_unit, - int unit_type) -{ - png_byte buf[9]; - - png_debug(1, "in png_write_pHYs"); - - if (unit_type >= PNG_RESOLUTION_LAST) - png_warning(png_ptr, "Unrecognized unit type for pHYs chunk"); - - png_save_uint_32(buf, x_pixels_per_unit); - png_save_uint_32(buf + 4, y_pixels_per_unit); - buf[8] = (png_byte)unit_type; - - png_write_complete_chunk(png_ptr, png_pHYs, buf, (png_size_t)9); -} -#endif - -#ifdef PNG_WRITE_tIME_SUPPORTED -/* Write the tIME chunk. Use either png_convert_from_struct_tm() - * or png_convert_from_time_t(), or fill in the structure yourself. - */ -void /* PRIVATE */ -png_write_tIME(png_structp png_ptr, png_const_timep mod_time) -{ - png_byte buf[7]; - - png_debug(1, "in png_write_tIME"); - - if (mod_time->month > 12 || mod_time->month < 1 || - mod_time->day > 31 || mod_time->day < 1 || - mod_time->hour > 23 || mod_time->second > 60) - { - png_warning(png_ptr, "Invalid time specified for tIME chunk"); - return; - } - - png_save_uint_16(buf, mod_time->year); - buf[2] = mod_time->month; - buf[3] = mod_time->day; - buf[4] = mod_time->hour; - buf[5] = mod_time->minute; - buf[6] = mod_time->second; - - png_write_complete_chunk(png_ptr, png_tIME, buf, (png_size_t)7); -} -#endif - -/* Initializes the row writing capability of libpng */ -void /* PRIVATE */ -png_write_start_row(png_structp png_ptr) -{ -#ifdef PNG_WRITE_INTERLACING_SUPPORTED - /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ - - /* Start of interlace block */ - static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; - - /* Offset to next interlace block */ - static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; - - /* Start of interlace block in the y direction */ - static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; - - /* Offset to next interlace block in the y direction */ - static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; -#endif - - png_alloc_size_t buf_size; - int usr_pixel_depth; - - png_debug(1, "in png_write_start_row"); - - usr_pixel_depth = png_ptr->usr_channels * png_ptr->usr_bit_depth; - buf_size = PNG_ROWBYTES(usr_pixel_depth, png_ptr->width) + 1; - - /* 1.5.6: added to allow checking in the row write code. */ - png_ptr->transformed_pixel_depth = png_ptr->pixel_depth; - png_ptr->maximum_pixel_depth = (png_byte)usr_pixel_depth; - - /* Set up row buffer */ - png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, buf_size); - - png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; - -#ifdef PNG_WRITE_FILTER_SUPPORTED - /* Set up filtering buffer, if using this filter */ - if (png_ptr->do_filter & PNG_FILTER_SUB) - { - png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1); - - png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; - } - - /* We only need to keep the previous row if we are using one of these. */ - if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) - { - /* Set up previous row buffer */ - png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, buf_size); - - if (png_ptr->do_filter & PNG_FILTER_UP) - { - png_ptr->up_row = (png_bytep)png_malloc(png_ptr, - png_ptr->rowbytes + 1); - - png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; - } - - if (png_ptr->do_filter & PNG_FILTER_AVG) - { - png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, - png_ptr->rowbytes + 1); - - png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; - } - - if (png_ptr->do_filter & PNG_FILTER_PAETH) - { - png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, - png_ptr->rowbytes + 1); - - png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; - } - } -#endif /* PNG_WRITE_FILTER_SUPPORTED */ - -#ifdef PNG_WRITE_INTERLACING_SUPPORTED - /* If interlaced, we need to set up width and height of pass */ - if (png_ptr->interlaced) - { - if (!(png_ptr->transformations & PNG_INTERLACE)) - { - png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - - png_pass_ystart[0]) / png_pass_yinc[0]; - - png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 - - png_pass_start[0]) / png_pass_inc[0]; - } - - else - { - png_ptr->num_rows = png_ptr->height; - png_ptr->usr_width = png_ptr->width; - } - } - - else -#endif - { - png_ptr->num_rows = png_ptr->height; - png_ptr->usr_width = png_ptr->width; - } - - png_zlib_claim(png_ptr, PNG_ZLIB_FOR_IDAT); - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - png_ptr->zstream.next_out = png_ptr->zbuf; -} - -/* Internal use only. Called when finished processing a row of data. */ -void /* PRIVATE */ -png_write_finish_row(png_structp png_ptr) -{ -#ifdef PNG_WRITE_INTERLACING_SUPPORTED - /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ - - /* Start of interlace block */ - static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; - - /* Offset to next interlace block */ - static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; - - /* Start of interlace block in the y direction */ - static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; - - /* Offset to next interlace block in the y direction */ - static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; -#endif - - int ret; - - png_debug(1, "in png_write_finish_row"); - - /* Next row */ - png_ptr->row_number++; - - /* See if we are done */ - if (png_ptr->row_number < png_ptr->num_rows) - return; - -#ifdef PNG_WRITE_INTERLACING_SUPPORTED - /* If interlaced, go to next pass */ - if (png_ptr->interlaced) - { - png_ptr->row_number = 0; - if (png_ptr->transformations & PNG_INTERLACE) - { - png_ptr->pass++; - } - - else - { - /* Loop until we find a non-zero width or height pass */ - do - { - png_ptr->pass++; - - if (png_ptr->pass >= 7) - break; - - png_ptr->usr_width = (png_ptr->width + - png_pass_inc[png_ptr->pass] - 1 - - png_pass_start[png_ptr->pass]) / - png_pass_inc[png_ptr->pass]; - - png_ptr->num_rows = (png_ptr->height + - png_pass_yinc[png_ptr->pass] - 1 - - png_pass_ystart[png_ptr->pass]) / - png_pass_yinc[png_ptr->pass]; - - if (png_ptr->transformations & PNG_INTERLACE) - break; - - } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0); - - } - - /* Reset the row above the image for the next pass */ - if (png_ptr->pass < 7) - { - if (png_ptr->prev_row != NULL) - png_memset(png_ptr->prev_row, 0, - (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels* - png_ptr->usr_bit_depth, png_ptr->width)) + 1); - - return; - } - } -#endif - - /* If we get here, we've just written the last row, so we need - to flush the compressor */ - do - { - /* Tell the compressor we are done */ - ret = deflate(&png_ptr->zstream, Z_FINISH); - - /* Check for an error */ - if (ret == Z_OK) - { - /* Check to see if we need more room */ - if (!(png_ptr->zstream.avail_out)) - { - png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); - png_ptr->zstream.next_out = png_ptr->zbuf; - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - } - } - - else if (ret != Z_STREAM_END) - { - if (png_ptr->zstream.msg != NULL) - png_error(png_ptr, png_ptr->zstream.msg); - - else - png_error(png_ptr, "zlib error"); - } - } while (ret != Z_STREAM_END); - - /* Write any extra space */ - if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) - { - png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size - - png_ptr->zstream.avail_out); - } - - png_zlib_release(png_ptr); - png_ptr->zstream.data_type = Z_BINARY; -} - -#ifdef PNG_WRITE_INTERLACING_SUPPORTED -/* Pick out the correct pixels for the interlace pass. - * The basic idea here is to go through the row with a source - * pointer and a destination pointer (sp and dp), and copy the - * correct pixels for the pass. As the row gets compacted, - * sp will always be >= dp, so we should never overwrite anything. - * See the default: case for the easiest code to understand. - */ -void /* PRIVATE */ -png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) -{ - /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ - - /* Start of interlace block */ - static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; - - /* Offset to next interlace block */ - static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; - - png_debug(1, "in png_do_write_interlace"); - - /* We don't have to do anything on the last pass (6) */ - if (pass < 6) - { - /* Each pixel depth is handled separately */ - switch (row_info->pixel_depth) - { - case 1: - { - png_bytep sp; - png_bytep dp; - int shift; - int d; - int value; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - dp = row; - d = 0; - shift = 7; - - for (i = png_pass_start[pass]; i < row_width; - i += png_pass_inc[pass]) - { - sp = row + (png_size_t)(i >> 3); - value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01; - d |= (value << shift); - - if (shift == 0) - { - shift = 7; - *dp++ = (png_byte)d; - d = 0; - } - - else - shift--; - - } - if (shift != 7) - *dp = (png_byte)d; - - break; - } - - case 2: - { - png_bytep sp; - png_bytep dp; - int shift; - int d; - int value; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - dp = row; - shift = 6; - d = 0; - - for (i = png_pass_start[pass]; i < row_width; - i += png_pass_inc[pass]) - { - sp = row + (png_size_t)(i >> 2); - value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03; - d |= (value << shift); - - if (shift == 0) - { - shift = 6; - *dp++ = (png_byte)d; - d = 0; - } - - else - shift -= 2; - } - if (shift != 6) - *dp = (png_byte)d; - - break; - } - - case 4: - { - png_bytep sp; - png_bytep dp; - int shift; - int d; - int value; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - - dp = row; - shift = 4; - d = 0; - for (i = png_pass_start[pass]; i < row_width; - i += png_pass_inc[pass]) - { - sp = row + (png_size_t)(i >> 1); - value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f; - d |= (value << shift); - - if (shift == 0) - { - shift = 4; - *dp++ = (png_byte)d; - d = 0; - } - - else - shift -= 4; - } - if (shift != 4) - *dp = (png_byte)d; - - break; - } - - default: - { - png_bytep sp; - png_bytep dp; - png_uint_32 i; - png_uint_32 row_width = row_info->width; - png_size_t pixel_bytes; - - /* Start at the beginning */ - dp = row; - - /* Find out how many bytes each pixel takes up */ - pixel_bytes = (row_info->pixel_depth >> 3); - - /* Loop through the row, only looking at the pixels that matter */ - for (i = png_pass_start[pass]; i < row_width; - i += png_pass_inc[pass]) - { - /* Find out where the original pixel is */ - sp = row + (png_size_t)i * pixel_bytes; - - /* Move the pixel */ - if (dp != sp) - png_memcpy(dp, sp, pixel_bytes); - - /* Next pixel */ - dp += pixel_bytes; - } - break; - } - } - /* Set new row width */ - row_info->width = (row_info->width + - png_pass_inc[pass] - 1 - - png_pass_start[pass]) / - png_pass_inc[pass]; - - row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, - row_info->width); - } -} -#endif - -/* This filters the row, chooses which filter to use, if it has not already - * been specified by the application, and then writes the row out with the - * chosen filter. - */ -static void png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row, - png_size_t row_bytes); - -#define PNG_MAXSUM (((png_uint_32)(-1)) >> 1) -#define PNG_HISHIFT 10 -#define PNG_LOMASK ((png_uint_32)0xffffL) -#define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT)) -void /* PRIVATE */ -png_write_find_filter(png_structp png_ptr, png_row_infop row_info) -{ - png_bytep best_row; -#ifdef PNG_WRITE_FILTER_SUPPORTED - png_bytep prev_row, row_buf; - png_uint_32 mins, bpp; - png_byte filter_to_do = png_ptr->do_filter; - png_size_t row_bytes = row_info->rowbytes; -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - int num_p_filters = png_ptr->num_prev_filters; -#endif - - png_debug(1, "in png_write_find_filter"); - -#ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS) - { - /* These will never be selected so we need not test them. */ - filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_PAETH); - } -#endif - - /* Find out how many bytes offset each pixel is */ - bpp = (row_info->pixel_depth + 7) >> 3; - - prev_row = png_ptr->prev_row; -#endif - best_row = png_ptr->row_buf; -#ifdef PNG_WRITE_FILTER_SUPPORTED - row_buf = best_row; - mins = PNG_MAXSUM; - - /* The prediction method we use is to find which method provides the - * smallest value when summing the absolute values of the distances - * from zero, using anything >= 128 as negative numbers. This is known - * as the "minimum sum of absolute differences" heuristic. Other - * heuristics are the "weighted minimum sum of absolute differences" - * (experimental and can in theory improve compression), and the "zlib - * predictive" method (not implemented yet), which does test compressions - * of lines using different filter methods, and then chooses the - * (series of) filter(s) that give minimum compressed data size (VERY - * computationally expensive). - * - * GRR 980525: consider also - * - * (1) minimum sum of absolute differences from running average (i.e., - * keep running sum of non-absolute differences & count of bytes) - * [track dispersion, too? restart average if dispersion too large?] - * - * (1b) minimum sum of absolute differences from sliding average, probably - * with window size <= deflate window (usually 32K) - * - * (2) minimum sum of squared differences from zero or running average - * (i.e., ~ root-mean-square approach) - */ - - - /* We don't need to test the 'no filter' case if this is the only filter - * that has been chosen, as it doesn't actually do anything to the data. - */ - if ((filter_to_do & PNG_FILTER_NONE) && filter_to_do != PNG_FILTER_NONE) - { - png_bytep rp; - png_uint_32 sum = 0; - png_size_t i; - int v; - - for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++) - { - v = *rp; - sum += (v < 128) ? v : 256 - v; - } - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - png_uint_32 sumhi, sumlo; - int j; - sumlo = sum & PNG_LOMASK; - sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */ - - /* Reduce the sum if we match any of the previous rows */ - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE) - { - sumlo = (sumlo * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - sumhi = (sumhi * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - /* Factor in the cost of this filter (this is here for completeness, - * but it makes no sense to have a "cost" for the NONE filter, as - * it has the minimum possible computational cost - none). - */ - sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >> - PNG_COST_SHIFT; - - sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >> - PNG_COST_SHIFT; - - if (sumhi > PNG_HIMASK) - sum = PNG_MAXSUM; - - else - sum = (sumhi << PNG_HISHIFT) + sumlo; - } -#endif - mins = sum; - } - - /* Sub filter */ - if (filter_to_do == PNG_FILTER_SUB) - /* It's the only filter so no testing is needed */ - { - png_bytep rp, lp, dp; - png_size_t i; - - for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp; - i++, rp++, dp++) - { - *dp = *rp; - } - - for (lp = row_buf + 1; i < row_bytes; - i++, rp++, lp++, dp++) - { - *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff); - } - - best_row = png_ptr->sub_row; - } - - else if (filter_to_do & PNG_FILTER_SUB) - { - png_bytep rp, dp, lp; - png_uint_32 sum = 0, lmins = mins; - png_size_t i; - int v; - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - /* We temporarily increase the "minimum sum" by the factor we - * would reduce the sum of this filter, so that we can do the - * early exit comparison without scaling the sum each time. - */ - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 lmhi, lmlo; - lmlo = lmins & PNG_LOMASK; - lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB) - { - lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> - PNG_COST_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> - PNG_COST_SHIFT; - - if (lmhi > PNG_HIMASK) - lmins = PNG_MAXSUM; - - else - lmins = (lmhi << PNG_HISHIFT) + lmlo; - } -#endif - - for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp; - i++, rp++, dp++) - { - v = *dp = *rp; - - sum += (v < 128) ? v : 256 - v; - } - - for (lp = row_buf + 1; i < row_bytes; - i++, rp++, lp++, dp++) - { - v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff); - - sum += (v < 128) ? v : 256 - v; - - if (sum > lmins) /* We are already worse, don't continue. */ - break; - } - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 sumhi, sumlo; - sumlo = sum & PNG_LOMASK; - sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB) - { - sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> - PNG_COST_SHIFT; - - sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> - PNG_COST_SHIFT; - - if (sumhi > PNG_HIMASK) - sum = PNG_MAXSUM; - - else - sum = (sumhi << PNG_HISHIFT) + sumlo; - } -#endif - - if (sum < mins) - { - mins = sum; - best_row = png_ptr->sub_row; - } - } - - /* Up filter */ - if (filter_to_do == PNG_FILTER_UP) - { - png_bytep rp, dp, pp; - png_size_t i; - - for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, - pp = prev_row + 1; i < row_bytes; - i++, rp++, pp++, dp++) - { - *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff); - } - - best_row = png_ptr->up_row; - } - - else if (filter_to_do & PNG_FILTER_UP) - { - png_bytep rp, dp, pp; - png_uint_32 sum = 0, lmins = mins; - png_size_t i; - int v; - - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 lmhi, lmlo; - lmlo = lmins & PNG_LOMASK; - lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP) - { - lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >> - PNG_COST_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >> - PNG_COST_SHIFT; - - if (lmhi > PNG_HIMASK) - lmins = PNG_MAXSUM; - - else - lmins = (lmhi << PNG_HISHIFT) + lmlo; - } -#endif - - for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, - pp = prev_row + 1; i < row_bytes; i++) - { - v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); - - sum += (v < 128) ? v : 256 - v; - - if (sum > lmins) /* We are already worse, don't continue. */ - break; - } - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 sumhi, sumlo; - sumlo = sum & PNG_LOMASK; - sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP) - { - sumlo = (sumlo * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - sumhi = (sumhi * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >> - PNG_COST_SHIFT; - - sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >> - PNG_COST_SHIFT; - - if (sumhi > PNG_HIMASK) - sum = PNG_MAXSUM; - - else - sum = (sumhi << PNG_HISHIFT) + sumlo; - } -#endif - - if (sum < mins) - { - mins = sum; - best_row = png_ptr->up_row; - } - } - - /* Avg filter */ - if (filter_to_do == PNG_FILTER_AVG) - { - png_bytep rp, dp, pp, lp; - png_uint_32 i; - - for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1, - pp = prev_row + 1; i < bpp; i++) - { - *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff); - } - - for (lp = row_buf + 1; i < row_bytes; i++) - { - *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) - & 0xff); - } - best_row = png_ptr->avg_row; - } - - else if (filter_to_do & PNG_FILTER_AVG) - { - png_bytep rp, dp, pp, lp; - png_uint_32 sum = 0, lmins = mins; - png_size_t i; - int v; - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 lmhi, lmlo; - lmlo = lmins & PNG_LOMASK; - lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG) - { - lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >> - PNG_COST_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >> - PNG_COST_SHIFT; - - if (lmhi > PNG_HIMASK) - lmins = PNG_MAXSUM; - - else - lmins = (lmhi << PNG_HISHIFT) + lmlo; - } -#endif - - for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1, - pp = prev_row + 1; i < bpp; i++) - { - v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff); - - sum += (v < 128) ? v : 256 - v; - } - - for (lp = row_buf + 1; i < row_bytes; i++) - { - v = *dp++ = - (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff); - - sum += (v < 128) ? v : 256 - v; - - if (sum > lmins) /* We are already worse, don't continue. */ - break; - } - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 sumhi, sumlo; - sumlo = sum & PNG_LOMASK; - sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE) - { - sumlo = (sumlo * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - sumhi = (sumhi * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >> - PNG_COST_SHIFT; - - sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >> - PNG_COST_SHIFT; - - if (sumhi > PNG_HIMASK) - sum = PNG_MAXSUM; - - else - sum = (sumhi << PNG_HISHIFT) + sumlo; - } -#endif - - if (sum < mins) - { - mins = sum; - best_row = png_ptr->avg_row; - } - } - - /* Paeth filter */ - if (filter_to_do == PNG_FILTER_PAETH) - { - png_bytep rp, dp, pp, cp, lp; - png_size_t i; - - for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, - pp = prev_row + 1; i < bpp; i++) - { - *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); - } - - for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++) - { - int a, b, c, pa, pb, pc, p; - - b = *pp++; - c = *cp++; - a = *lp++; - - p = b - c; - pc = a - c; - -#ifdef PNG_USE_ABS - pa = abs(p); - pb = abs(pc); - pc = abs(p + pc); -#else - pa = p < 0 ? -p : p; - pb = pc < 0 ? -pc : pc; - pc = (p + pc) < 0 ? -(p + pc) : p + pc; -#endif - - p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; - - *dp++ = (png_byte)(((int)*rp++ - p) & 0xff); - } - best_row = png_ptr->paeth_row; - } - - else if (filter_to_do & PNG_FILTER_PAETH) - { - png_bytep rp, dp, pp, cp, lp; - png_uint_32 sum = 0, lmins = mins; - png_size_t i; - int v; - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 lmhi, lmlo; - lmlo = lmins & PNG_LOMASK; - lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH) - { - lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >> - PNG_COST_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >> - PNG_COST_SHIFT; - - if (lmhi > PNG_HIMASK) - lmins = PNG_MAXSUM; - - else - lmins = (lmhi << PNG_HISHIFT) + lmlo; - } -#endif - - for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, - pp = prev_row + 1; i < bpp; i++) - { - v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); - - sum += (v < 128) ? v : 256 - v; - } - - for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++) - { - int a, b, c, pa, pb, pc, p; - - b = *pp++; - c = *cp++; - a = *lp++; - -#ifndef PNG_SLOW_PAETH - p = b - c; - pc = a - c; -#ifdef PNG_USE_ABS - pa = abs(p); - pb = abs(pc); - pc = abs(p + pc); -#else - pa = p < 0 ? -p : p; - pb = pc < 0 ? -pc : pc; - pc = (p + pc) < 0 ? -(p + pc) : p + pc; -#endif - p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; -#else /* PNG_SLOW_PAETH */ - p = a + b - c; - pa = abs(p - a); - pb = abs(p - b); - pc = abs(p - c); - - if (pa <= pb && pa <= pc) - p = a; - - else if (pb <= pc) - p = b; - - else - p = c; -#endif /* PNG_SLOW_PAETH */ - - v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff); - - sum += (v < 128) ? v : 256 - v; - - if (sum > lmins) /* We are already worse, don't continue. */ - break; - } - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 sumhi, sumlo; - sumlo = sum & PNG_LOMASK; - sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH) - { - sumlo = (sumlo * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - sumhi = (sumhi * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >> - PNG_COST_SHIFT; - - sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >> - PNG_COST_SHIFT; - - if (sumhi > PNG_HIMASK) - sum = PNG_MAXSUM; - - else - sum = (sumhi << PNG_HISHIFT) + sumlo; - } -#endif - - if (sum < mins) - { - best_row = png_ptr->paeth_row; - } - } -#endif /* PNG_WRITE_FILTER_SUPPORTED */ - - /* Do the actual writing of the filtered row data from the chosen filter. */ - png_write_filtered_row(png_ptr, best_row, row_info->rowbytes+1); - -#ifdef PNG_WRITE_FILTER_SUPPORTED -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - /* Save the type of filter we picked this time for future calculations */ - if (png_ptr->num_prev_filters > 0) - { - int j; - - for (j = 1; j < num_p_filters; j++) - { - png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1]; - } - - png_ptr->prev_filters[j] = best_row[0]; - } -#endif -#endif /* PNG_WRITE_FILTER_SUPPORTED */ -} - - -/* Do the actual writing of a previously filtered row. */ -static void -png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row, - png_size_t avail/*includes filter byte*/) -{ - png_debug(1, "in png_write_filtered_row"); - - png_debug1(2, "filter = %d", filtered_row[0]); - /* Set up the zlib input buffer */ - - png_ptr->zstream.next_in = filtered_row; - png_ptr->zstream.avail_in = 0; - /* Repeat until we have compressed all the data */ - do - { - int ret; /* Return of zlib */ - - /* Record the number of bytes available - zlib supports at least 65535 - * bytes at one step, depending on the size of the zlib type 'uInt', the - * maximum size zlib can write at once is ZLIB_IO_MAX (from pngpriv.h). - * Use this because on 16 bit systems 'rowbytes' can be up to 65536 (i.e. - * one more than 16 bits) and, in this case 'rowbytes+1' can overflow a - * uInt. ZLIB_IO_MAX can be safely reduced to cause zlib to be called - * with smaller chunks of data. - */ - if (png_ptr->zstream.avail_in == 0) - { - if (avail > ZLIB_IO_MAX) - { - png_ptr->zstream.avail_in = ZLIB_IO_MAX; - avail -= ZLIB_IO_MAX; - } - - else - { - /* So this will fit in the available uInt space: */ - png_ptr->zstream.avail_in = (uInt)avail; - avail = 0; - } - } - - /* Compress the data */ - ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); - - /* Check for compression errors */ - if (ret != Z_OK) - { - if (png_ptr->zstream.msg != NULL) - png_error(png_ptr, png_ptr->zstream.msg); - - else - png_error(png_ptr, "zlib error"); - } - - /* See if it is time to write another IDAT */ - if (!(png_ptr->zstream.avail_out)) - { - /* Write the IDAT and reset the zlib output buffer */ - png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); - } - /* Repeat until all data has been compressed */ - } while (avail > 0 || png_ptr->zstream.avail_in > 0); - - /* Swap the current and previous rows */ - if (png_ptr->prev_row != NULL) - { - png_bytep tptr; - - tptr = png_ptr->prev_row; - png_ptr->prev_row = png_ptr->row_buf; - png_ptr->row_buf = tptr; - } - - /* Finish row - updates counters and flushes zlib if last row */ - png_write_finish_row(png_ptr); - -#ifdef PNG_WRITE_FLUSH_SUPPORTED - png_ptr->flush_rows++; - - if (png_ptr->flush_dist > 0 && - png_ptr->flush_rows >= png_ptr->flush_dist) - { - png_write_flush(png_ptr); - } -#endif -} -#endif /* PNG_WRITE_SUPPORTED */ + +/* pngwutil.c - utilities to write a PNG file + * + * Last changed in libpng 1.5.10 [March 8, 2012] + * Copyright (c) 1998-2012 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#include "pngpriv.h" + +#ifdef PNG_WRITE_SUPPORTED + +#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED +/* Place a 32-bit number into a buffer in PNG byte order. We work + * with unsigned numbers for convenience, although one supported + * ancillary chunk uses signed (two's complement) numbers. + */ +void PNGAPI +png_save_uint_32(png_bytep buf, png_uint_32 i) +{ + buf[0] = (png_byte)((i >> 24) & 0xff); + buf[1] = (png_byte)((i >> 16) & 0xff); + buf[2] = (png_byte)((i >> 8) & 0xff); + buf[3] = (png_byte)(i & 0xff); +} + +#ifdef PNG_SAVE_INT_32_SUPPORTED +/* The png_save_int_32 function assumes integers are stored in two's + * complement format. If this isn't the case, then this routine needs to + * be modified to write data in two's complement format. Note that, + * the following works correctly even if png_int_32 has more than 32 bits + * (compare the more complex code required on read for sign extention.) + */ +void PNGAPI +png_save_int_32(png_bytep buf, png_int_32 i) +{ + buf[0] = (png_byte)((i >> 24) & 0xff); + buf[1] = (png_byte)((i >> 16) & 0xff); + buf[2] = (png_byte)((i >> 8) & 0xff); + buf[3] = (png_byte)(i & 0xff); +} +#endif + +/* Place a 16-bit number into a buffer in PNG byte order. + * The parameter is declared unsigned int, not png_uint_16, + * just to avoid potential problems on pre-ANSI C compilers. + */ +void PNGAPI +png_save_uint_16(png_bytep buf, unsigned int i) +{ + buf[0] = (png_byte)((i >> 8) & 0xff); + buf[1] = (png_byte)(i & 0xff); +} +#endif + +/* Simple function to write the signature. If we have already written + * the magic bytes of the signature, or more likely, the PNG stream is + * being embedded into another stream and doesn't need its own signature, + * we should call png_set_sig_bytes() to tell libpng how many of the + * bytes have already been written. + */ +void PNGAPI +png_write_sig(png_structp png_ptr) +{ + png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; + +#ifdef PNG_IO_STATE_SUPPORTED + /* Inform the I/O callback that the signature is being written */ + png_ptr->io_state = PNG_IO_WRITING | PNG_IO_SIGNATURE; +#endif + + /* Write the rest of the 8 byte signature */ + png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes], + (png_size_t)(8 - png_ptr->sig_bytes)); + + if (png_ptr->sig_bytes < 3) + png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; +} + +/* Write the start of a PNG chunk. The type is the chunk type. + * The total_length is the sum of the lengths of all the data you will be + * passing in png_write_chunk_data(). + */ +static void +png_write_chunk_header(png_structp png_ptr, png_uint_32 chunk_name, + png_uint_32 length) +{ + png_byte buf[8]; + +#if defined(PNG_DEBUG) && (PNG_DEBUG > 0) + PNG_CSTRING_FROM_CHUNK(buf, chunk_name); + png_debug2(0, "Writing %s chunk, length = %lu", buf, (unsigned long)length); +#endif + + if (png_ptr == NULL) + return; + +#ifdef PNG_IO_STATE_SUPPORTED + /* Inform the I/O callback that the chunk header is being written. + * PNG_IO_CHUNK_HDR requires a single I/O call. + */ + png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_HDR; +#endif + + /* Write the length and the chunk name */ + png_save_uint_32(buf, length); + png_save_uint_32(buf + 4, chunk_name); + png_write_data(png_ptr, buf, 8); + + /* Put the chunk name into png_ptr->chunk_name */ + png_ptr->chunk_name = chunk_name; + + /* Reset the crc and run it over the chunk name */ + png_reset_crc(png_ptr); + + png_calculate_crc(png_ptr, buf + 4, 4); + +#ifdef PNG_IO_STATE_SUPPORTED + /* Inform the I/O callback that chunk data will (possibly) be written. + * PNG_IO_CHUNK_DATA does NOT require a specific number of I/O calls. + */ + png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_DATA; +#endif +} + +void PNGAPI +png_write_chunk_start(png_structp png_ptr, png_const_bytep chunk_string, + png_uint_32 length) +{ + png_write_chunk_header(png_ptr, PNG_CHUNK_FROM_STRING(chunk_string), length); +} + +/* Write the data of a PNG chunk started with png_write_chunk_header(). + * Note that multiple calls to this function are allowed, and that the + * sum of the lengths from these calls *must* add up to the total_length + * given to png_write_chunk_header(). + */ +void PNGAPI +png_write_chunk_data(png_structp png_ptr, png_const_bytep data, + png_size_t length) +{ + /* Write the data, and run the CRC over it */ + if (png_ptr == NULL) + return; + + if (data != NULL && length > 0) + { + png_write_data(png_ptr, data, length); + + /* Update the CRC after writing the data, + * in case that the user I/O routine alters it. + */ + png_calculate_crc(png_ptr, data, length); + } +} + +/* Finish a chunk started with png_write_chunk_header(). */ +void PNGAPI +png_write_chunk_end(png_structp png_ptr) +{ + png_byte buf[4]; + + if (png_ptr == NULL) return; + +#ifdef PNG_IO_STATE_SUPPORTED + /* Inform the I/O callback that the chunk CRC is being written. + * PNG_IO_CHUNK_CRC requires a single I/O function call. + */ + png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_CRC; +#endif + + /* Write the crc in a single operation */ + png_save_uint_32(buf, png_ptr->crc); + + png_write_data(png_ptr, buf, (png_size_t)4); +} + +/* Write a PNG chunk all at once. The type is an array of ASCII characters + * representing the chunk name. The array must be at least 4 bytes in + * length, and does not need to be null terminated. To be safe, pass the + * pre-defined chunk names here, and if you need a new one, define it + * where the others are defined. The length is the length of the data. + * All the data must be present. If that is not possible, use the + * png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end() + * functions instead. + */ +static void +png_write_complete_chunk(png_structp png_ptr, png_uint_32 chunk_name, + png_const_bytep data, png_size_t length) +{ + if (png_ptr == NULL) + return; + + /* On 64 bit architectures 'length' may not fit in a png_uint_32. */ + if (length > PNG_UINT_32_MAX) + png_error(png_ptr, "length exceeds PNG maxima"); + + png_write_chunk_header(png_ptr, chunk_name, (png_uint_32)length); + png_write_chunk_data(png_ptr, data, length); + png_write_chunk_end(png_ptr); +} + +/* This is the API that calls the internal function above. */ +void PNGAPI +png_write_chunk(png_structp png_ptr, png_const_bytep chunk_string, + png_const_bytep data, png_size_t length) +{ + png_write_complete_chunk(png_ptr, PNG_CHUNK_FROM_STRING(chunk_string), data, + length); +} + +/* Initialize the compressor for the appropriate type of compression. */ +static void +png_zlib_claim(png_structp png_ptr, png_uint_32 state) +{ + if (!(png_ptr->zlib_state & PNG_ZLIB_IN_USE)) + { + /* If already initialized for 'state' do not re-init. */ + if (png_ptr->zlib_state != state) + { + int ret = Z_OK; + png_const_charp who = "-"; + + /* If actually initialized for another state do a deflateEnd. */ + if (png_ptr->zlib_state != PNG_ZLIB_UNINITIALIZED) + { + ret = deflateEnd(&png_ptr->zstream); + who = "end"; + png_ptr->zlib_state = PNG_ZLIB_UNINITIALIZED; + } + + /* zlib itself detects an incomplete state on deflateEnd */ + if (ret == Z_OK) switch (state) + { +# ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED + case PNG_ZLIB_FOR_TEXT: + ret = deflateInit2(&png_ptr->zstream, + png_ptr->zlib_text_level, png_ptr->zlib_text_method, + png_ptr->zlib_text_window_bits, + png_ptr->zlib_text_mem_level, png_ptr->zlib_text_strategy); + who = "text"; + break; +# endif + + case PNG_ZLIB_FOR_IDAT: + ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_level, + png_ptr->zlib_method, png_ptr->zlib_window_bits, + png_ptr->zlib_mem_level, png_ptr->zlib_strategy); + who = "IDAT"; + break; + + default: + png_error(png_ptr, "invalid zlib state"); + } + + if (ret == Z_OK) + png_ptr->zlib_state = state; + + else /* an error in deflateEnd or deflateInit2 */ + { + size_t pos = 0; + char msg[64]; + + pos = png_safecat(msg, sizeof msg, pos, + "zlib failed to initialize compressor ("); + pos = png_safecat(msg, sizeof msg, pos, who); + + switch (ret) + { + case Z_VERSION_ERROR: + pos = png_safecat(msg, sizeof msg, pos, ") version error"); + break; + + case Z_STREAM_ERROR: + pos = png_safecat(msg, sizeof msg, pos, ") stream error"); + break; + + case Z_MEM_ERROR: + pos = png_safecat(msg, sizeof msg, pos, ") memory error"); + break; + + default: + pos = png_safecat(msg, sizeof msg, pos, ") unknown error"); + break; + } + + png_error(png_ptr, msg); + } + } + + /* Here on success, claim the zstream: */ + png_ptr->zlib_state |= PNG_ZLIB_IN_USE; + } + + else + png_error(png_ptr, "zstream already in use (internal error)"); +} + +/* The opposite: release the stream. It is also reset, this API will warn on + * error but will not fail. + */ +static void +png_zlib_release(png_structp png_ptr) +{ + if (png_ptr->zlib_state & PNG_ZLIB_IN_USE) + { + int ret = deflateReset(&png_ptr->zstream); + + png_ptr->zlib_state &= ~PNG_ZLIB_IN_USE; + + if (ret != Z_OK) + { + png_const_charp err; + PNG_WARNING_PARAMETERS(p) + + switch (ret) + { + case Z_VERSION_ERROR: + err = "version"; + break; + + case Z_STREAM_ERROR: + err = "stream"; + break; + + case Z_MEM_ERROR: + err = "memory"; + break; + + default: + err = "unknown"; + break; + } + + png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, ret); + png_warning_parameter(p, 2, err); + + if (png_ptr->zstream.msg) + err = png_ptr->zstream.msg; + else + err = "[no zlib message]"; + + png_warning_parameter(p, 3, err); + + png_formatted_warning(png_ptr, p, + "zlib failed to reset compressor: @1(@2): @3"); + } + } + + else + png_warning(png_ptr, "zstream not in use (internal error)"); +} + +#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED +/* This pair of functions encapsulates the operation of (a) compressing a + * text string, and (b) issuing it later as a series of chunk data writes. + * The compression_state structure is shared context for these functions + * set up by the caller in order to make the whole mess thread-safe. + */ + +typedef struct +{ + png_const_bytep input; /* The uncompressed input data */ + png_size_t input_len; /* Its length */ + int num_output_ptr; /* Number of output pointers used */ + int max_output_ptr; /* Size of output_ptr */ + png_bytep *output_ptr; /* Array of pointers to output */ +} compression_state; + +/* Compress given text into storage in the png_ptr structure */ +static int /* PRIVATE */ +png_text_compress(png_structp png_ptr, + png_const_charp text, png_size_t text_len, int compression, + compression_state *comp) +{ + int ret; + + comp->num_output_ptr = 0; + comp->max_output_ptr = 0; + comp->output_ptr = NULL; + comp->input = NULL; + comp->input_len = text_len; + + /* We may just want to pass the text right through */ + if (compression == PNG_TEXT_COMPRESSION_NONE) + { + comp->input = (png_const_bytep)text; + return((int)text_len); + } + + if (compression >= PNG_TEXT_COMPRESSION_LAST) + { + PNG_WARNING_PARAMETERS(p) + + png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, + compression); + png_formatted_warning(png_ptr, p, "Unknown compression type @1"); + } + + /* We can't write the chunk until we find out how much data we have, + * which means we need to run the compressor first and save the + * output. This shouldn't be a problem, as the vast majority of + * comments should be reasonable, but we will set up an array of + * malloc'd pointers to be sure. + * + * If we knew the application was well behaved, we could simplify this + * greatly by assuming we can always malloc an output buffer large + * enough to hold the compressed text ((1001 * text_len / 1000) + 12) + * and malloc this directly. The only time this would be a bad idea is + * if we can't malloc more than 64K and we have 64K of random input + * data, or if the input string is incredibly large (although this + * wouldn't cause a failure, just a slowdown due to swapping). + */ + png_zlib_claim(png_ptr, PNG_ZLIB_FOR_TEXT); + + /* Set up the compression buffers */ + /* TODO: the following cast hides a potential overflow problem. */ + png_ptr->zstream.avail_in = (uInt)text_len; + + /* NOTE: assume zlib doesn't overwrite the input */ + png_ptr->zstream.next_in = (Bytef *)text; + png_ptr->zstream.avail_out = png_ptr->zbuf_size; + png_ptr->zstream.next_out = png_ptr->zbuf; + + /* This is the same compression loop as in png_write_row() */ + do + { + /* Compress the data */ + ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); + + if (ret != Z_OK) + { + /* Error */ + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + + else + png_error(png_ptr, "zlib error"); + } + + /* Check to see if we need more room */ + if (!(png_ptr->zstream.avail_out)) + { + /* Make sure the output array has room */ + if (comp->num_output_ptr >= comp->max_output_ptr) + { + int old_max; + + old_max = comp->max_output_ptr; + comp->max_output_ptr = comp->num_output_ptr + 4; + if (comp->output_ptr != NULL) + { + png_bytepp old_ptr; + + old_ptr = comp->output_ptr; + + comp->output_ptr = (png_bytepp)png_malloc(png_ptr, + (png_alloc_size_t) + (comp->max_output_ptr * png_sizeof(png_charpp))); + + png_memcpy(comp->output_ptr, old_ptr, old_max + * png_sizeof(png_charp)); + + png_free(png_ptr, old_ptr); + } + else + comp->output_ptr = (png_bytepp)png_malloc(png_ptr, + (png_alloc_size_t) + (comp->max_output_ptr * png_sizeof(png_charp))); + } + + /* Save the data */ + comp->output_ptr[comp->num_output_ptr] = + (png_bytep)png_malloc(png_ptr, + (png_alloc_size_t)png_ptr->zbuf_size); + + png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, + png_ptr->zbuf_size); + + comp->num_output_ptr++; + + /* and reset the buffer */ + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_out = png_ptr->zbuf; + } + /* Continue until we don't have any more to compress */ + } while (png_ptr->zstream.avail_in); + + /* Finish the compression */ + do + { + /* Tell zlib we are finished */ + ret = deflate(&png_ptr->zstream, Z_FINISH); + + if (ret == Z_OK) + { + /* Check to see if we need more room */ + if (!(png_ptr->zstream.avail_out)) + { + /* Check to make sure our output array has room */ + if (comp->num_output_ptr >= comp->max_output_ptr) + { + int old_max; + + old_max = comp->max_output_ptr; + comp->max_output_ptr = comp->num_output_ptr + 4; + if (comp->output_ptr != NULL) + { + png_bytepp old_ptr; + + old_ptr = comp->output_ptr; + + /* This could be optimized to realloc() */ + comp->output_ptr = (png_bytepp)png_malloc(png_ptr, + (png_alloc_size_t)(comp->max_output_ptr * + png_sizeof(png_charp))); + + png_memcpy(comp->output_ptr, old_ptr, + old_max * png_sizeof(png_charp)); + + png_free(png_ptr, old_ptr); + } + + else + comp->output_ptr = (png_bytepp)png_malloc(png_ptr, + (png_alloc_size_t)(comp->max_output_ptr * + png_sizeof(png_charp))); + } + + /* Save the data */ + comp->output_ptr[comp->num_output_ptr] = + (png_bytep)png_malloc(png_ptr, + (png_alloc_size_t)png_ptr->zbuf_size); + + png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, + png_ptr->zbuf_size); + + comp->num_output_ptr++; + + /* and reset the buffer pointers */ + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_out = png_ptr->zbuf; + } + } + else if (ret != Z_STREAM_END) + { + /* We got an error */ + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + + else + png_error(png_ptr, "zlib error"); + } + } while (ret != Z_STREAM_END); + + /* Text length is number of buffers plus last buffer */ + text_len = png_ptr->zbuf_size * comp->num_output_ptr; + + if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) + text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out; + + return((int)text_len); +} + +/* Ship the compressed text out via chunk writes */ +static void /* PRIVATE */ +png_write_compressed_data_out(png_structp png_ptr, compression_state *comp, + png_size_t data_len) +{ + int i; + + /* Handle the no-compression case */ + if (comp->input) + { + png_write_chunk_data(png_ptr, comp->input, data_len); + + return; + } + +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED + /* The zbuf_size test is because the code below doesn't work if zbuf_size is + * '1'; simply skip it to avoid memory overwrite. + */ + if (data_len >= 2 && comp->input_len < 16384 && png_ptr->zbuf_size > 1) + { + unsigned int z_cmf; /* zlib compression method and flags */ + + /* Optimize the CMF field in the zlib stream. This hack of the zlib + * stream is compliant to the stream specification. + */ + + if (comp->num_output_ptr) + z_cmf = comp->output_ptr[0][0]; + else + z_cmf = png_ptr->zbuf[0]; + + if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70) + { + unsigned int z_cinfo; + unsigned int half_z_window_size; + png_size_t uncompressed_text_size = comp->input_len; + + z_cinfo = z_cmf >> 4; + half_z_window_size = 1 << (z_cinfo + 7); + + while (uncompressed_text_size <= half_z_window_size && + half_z_window_size >= 256) + { + z_cinfo--; + half_z_window_size >>= 1; + } + + z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4); + + if (comp->num_output_ptr) + { + + if (comp->output_ptr[0][0] != z_cmf) + { + int tmp; + + comp->output_ptr[0][0] = (png_byte)z_cmf; + tmp = comp->output_ptr[0][1] & 0xe0; + tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f; + comp->output_ptr[0][1] = (png_byte)tmp; + } + } + else + { + int tmp; + + png_ptr->zbuf[0] = (png_byte)z_cmf; + tmp = png_ptr->zbuf[1] & 0xe0; + tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f; + png_ptr->zbuf[1] = (png_byte)tmp; + } + } + + else + png_error(png_ptr, + "Invalid zlib compression method or flags in non-IDAT chunk"); + } +#endif /* PNG_WRITE_OPTIMIZE_CMF_SUPPORTED */ + + /* Write saved output buffers, if any */ + for (i = 0; i < comp->num_output_ptr; i++) + { + png_write_chunk_data(png_ptr, comp->output_ptr[i], + (png_size_t)png_ptr->zbuf_size); + + png_free(png_ptr, comp->output_ptr[i]); + } + + if (comp->max_output_ptr != 0) + png_free(png_ptr, comp->output_ptr); + + /* Write anything left in zbuf */ + if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size) + png_write_chunk_data(png_ptr, png_ptr->zbuf, + (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out)); + + /* Reset zlib for another zTXt/iTXt or image data */ + png_zlib_release(png_ptr); +} +#endif /* PNG_WRITE_COMPRESSED_TEXT_SUPPORTED */ + +/* Write the IHDR chunk, and update the png_struct with the necessary + * information. Note that the rest of this code depends upon this + * information being correct. + */ +void /* PRIVATE */ +png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, + int bit_depth, int color_type, int compression_type, int filter_type, + int interlace_type) +{ + png_byte buf[13]; /* Buffer to store the IHDR info */ + + png_debug(1, "in png_write_IHDR"); + + /* Check that we have valid input data from the application info */ + switch (color_type) + { + case PNG_COLOR_TYPE_GRAY: + switch (bit_depth) + { + case 1: + case 2: + case 4: + case 8: +#ifdef PNG_WRITE_16BIT_SUPPORTED + case 16: +#endif + png_ptr->channels = 1; break; + + default: + png_error(png_ptr, + "Invalid bit depth for grayscale image"); + } + break; + + case PNG_COLOR_TYPE_RGB: +#ifdef PNG_WRITE_16BIT_SUPPORTED + if (bit_depth != 8 && bit_depth != 16) +#else + if (bit_depth != 8) +#endif + png_error(png_ptr, "Invalid bit depth for RGB image"); + + png_ptr->channels = 3; + break; + + case PNG_COLOR_TYPE_PALETTE: + switch (bit_depth) + { + case 1: + case 2: + case 4: + case 8: + png_ptr->channels = 1; + break; + + default: + png_error(png_ptr, "Invalid bit depth for paletted image"); + } + break; + + case PNG_COLOR_TYPE_GRAY_ALPHA: + if (bit_depth != 8 && bit_depth != 16) + png_error(png_ptr, "Invalid bit depth for grayscale+alpha image"); + + png_ptr->channels = 2; + break; + + case PNG_COLOR_TYPE_RGB_ALPHA: +#ifdef PNG_WRITE_16BIT_SUPPORTED + if (bit_depth != 8 && bit_depth != 16) +#else + if (bit_depth != 8) +#endif + png_error(png_ptr, "Invalid bit depth for RGBA image"); + + png_ptr->channels = 4; + break; + + default: + png_error(png_ptr, "Invalid image color type specified"); + } + + if (compression_type != PNG_COMPRESSION_TYPE_BASE) + { + png_warning(png_ptr, "Invalid compression type specified"); + compression_type = PNG_COMPRESSION_TYPE_BASE; + } + + /* Write filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not write a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ + if ( +#ifdef PNG_MNG_FEATURES_SUPPORTED + !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && + (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) && + (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) && +#endif + filter_type != PNG_FILTER_TYPE_BASE) + { + png_warning(png_ptr, "Invalid filter type specified"); + filter_type = PNG_FILTER_TYPE_BASE; + } + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + if (interlace_type != PNG_INTERLACE_NONE && + interlace_type != PNG_INTERLACE_ADAM7) + { + png_warning(png_ptr, "Invalid interlace type specified"); + interlace_type = PNG_INTERLACE_ADAM7; + } +#else + interlace_type=PNG_INTERLACE_NONE; +#endif + + /* Save the relevent information */ + png_ptr->bit_depth = (png_byte)bit_depth; + png_ptr->color_type = (png_byte)color_type; + png_ptr->interlaced = (png_byte)interlace_type; +#ifdef PNG_MNG_FEATURES_SUPPORTED + png_ptr->filter_type = (png_byte)filter_type; +#endif + png_ptr->compression_type = (png_byte)compression_type; + png_ptr->width = width; + png_ptr->height = height; + + png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels); + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width); + /* Set the usr info, so any transformations can modify it */ + png_ptr->usr_width = png_ptr->width; + png_ptr->usr_bit_depth = png_ptr->bit_depth; + png_ptr->usr_channels = png_ptr->channels; + + /* Pack the header information into the buffer */ + png_save_uint_32(buf, width); + png_save_uint_32(buf + 4, height); + buf[8] = (png_byte)bit_depth; + buf[9] = (png_byte)color_type; + buf[10] = (png_byte)compression_type; + buf[11] = (png_byte)filter_type; + buf[12] = (png_byte)interlace_type; + + /* Write the chunk */ + png_write_complete_chunk(png_ptr, png_IHDR, buf, (png_size_t)13); + + /* Initialize zlib with PNG info */ + png_ptr->zstream.zalloc = png_zalloc; + png_ptr->zstream.zfree = png_zfree; + png_ptr->zstream.opaque = (voidpf)png_ptr; + + if (!(png_ptr->do_filter)) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE || + png_ptr->bit_depth < 8) + png_ptr->do_filter = PNG_FILTER_NONE; + + else + png_ptr->do_filter = PNG_ALL_FILTERS; + } + + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY)) + { + if (png_ptr->do_filter != PNG_FILTER_NONE) + png_ptr->zlib_strategy = Z_FILTERED; + + else + png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY; + } + + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL)) + png_ptr->zlib_level = Z_DEFAULT_COMPRESSION; + + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL)) + png_ptr->zlib_mem_level = 8; + + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS)) + png_ptr->zlib_window_bits = 15; + + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD)) + png_ptr->zlib_method = 8; + +#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED + if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_STRATEGY)) + png_ptr->zlib_text_strategy = Z_DEFAULT_STRATEGY; + + if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_LEVEL)) + png_ptr->zlib_text_level = png_ptr->zlib_level; + + if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL)) + png_ptr->zlib_text_mem_level = png_ptr->zlib_mem_level; + + if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS)) + png_ptr->zlib_text_window_bits = png_ptr->zlib_window_bits; + + if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_METHOD)) + png_ptr->zlib_text_method = png_ptr->zlib_method; +#else + png_ptr->zlib_text_strategy = Z_DEFAULT_STRATEGY; + png_ptr->zlib_text_level = png_ptr->zlib_level; + png_ptr->zlib_text_mem_level = png_ptr->zlib_mem_level; + png_ptr->zlib_text_window_bits = png_ptr->zlib_window_bits; + png_ptr->zlib_text_method = png_ptr->zlib_method; +#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */ +#endif /* PNG_WRITE_COMPRESSED_TEXT_SUPPORTED */ + + /* Record that the compressor has not yet been initialized. */ + png_ptr->zlib_state = PNG_ZLIB_UNINITIALIZED; + + png_ptr->mode = PNG_HAVE_IHDR; /* not READY_FOR_ZTXT */ +} + +/* Write the palette. We are careful not to trust png_color to be in the + * correct order for PNG, so people can redefine it to any convenient + * structure. + */ +void /* PRIVATE */ +png_write_PLTE(png_structp png_ptr, png_const_colorp palette, + png_uint_32 num_pal) +{ + png_uint_32 i; + png_const_colorp pal_ptr; + png_byte buf[3]; + + png_debug(1, "in png_write_PLTE"); + + if (( +#ifdef PNG_MNG_FEATURES_SUPPORTED + !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && +#endif + num_pal == 0) || num_pal > 256) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + png_error(png_ptr, "Invalid number of colors in palette"); + } + + else + { + png_warning(png_ptr, "Invalid number of colors in palette"); + return; + } + } + + if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) + { + png_warning(png_ptr, + "Ignoring request to write a PLTE chunk in grayscale PNG"); + + return; + } + + png_ptr->num_palette = (png_uint_16)num_pal; + png_debug1(3, "num_palette = %d", png_ptr->num_palette); + + png_write_chunk_header(png_ptr, png_PLTE, (png_uint_32)(num_pal * 3)); +#ifdef PNG_POINTER_INDEXING_SUPPORTED + + for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++) + { + buf[0] = pal_ptr->red; + buf[1] = pal_ptr->green; + buf[2] = pal_ptr->blue; + png_write_chunk_data(png_ptr, buf, (png_size_t)3); + } + +#else + /* This is a little slower but some buggy compilers need to do this + * instead + */ + pal_ptr=palette; + + for (i = 0; i < num_pal; i++) + { + buf[0] = pal_ptr[i].red; + buf[1] = pal_ptr[i].green; + buf[2] = pal_ptr[i].blue; + png_write_chunk_data(png_ptr, buf, (png_size_t)3); + } + +#endif + png_write_chunk_end(png_ptr); + png_ptr->mode |= PNG_HAVE_PLTE; +} + +/* Write an IDAT chunk */ +void /* PRIVATE */ +png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_debug(1, "in png_write_IDAT"); + +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED + if (!(png_ptr->mode & PNG_HAVE_IDAT) && + png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE) + { + /* Optimize the CMF field in the zlib stream. This hack of the zlib + * stream is compliant to the stream specification. + */ + unsigned int z_cmf = data[0]; /* zlib compression method and flags */ + + if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70) + { + /* Avoid memory underflows and multiplication overflows. + * + * The conditions below are practically always satisfied; + * however, they still must be checked. + */ + if (length >= 2 && + png_ptr->height < 16384 && png_ptr->width < 16384) + { + /* Compute the maximum possible length of the datastream */ + + /* Number of pixels, plus for each row a filter byte + * and possibly a padding byte, so increase the maximum + * size to account for these. + */ + unsigned int z_cinfo; + unsigned int half_z_window_size; + png_uint_32 uncompressed_idat_size = png_ptr->height * + ((png_ptr->width * + png_ptr->channels * png_ptr->bit_depth + 15) >> 3); + + /* If it's interlaced, each block of 8 rows is sent as up to + * 14 rows, i.e., 6 additional rows, each with a filter byte + * and possibly a padding byte + */ + if (png_ptr->interlaced) + uncompressed_idat_size += ((png_ptr->height + 7)/8) * + (png_ptr->bit_depth < 8 ? 12 : 6); + + z_cinfo = z_cmf >> 4; + half_z_window_size = 1 << (z_cinfo + 7); + + while (uncompressed_idat_size <= half_z_window_size && + half_z_window_size >= 256) + { + z_cinfo--; + half_z_window_size >>= 1; + } + + z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4); + + if (data[0] != z_cmf) + { + int tmp; + data[0] = (png_byte)z_cmf; + tmp = data[1] & 0xe0; + tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f; + data[1] = (png_byte)tmp; + } + } + } + + else + png_error(png_ptr, + "Invalid zlib compression method or flags in IDAT"); + } +#endif /* PNG_WRITE_OPTIMIZE_CMF_SUPPORTED */ + + png_write_complete_chunk(png_ptr, png_IDAT, data, length); + png_ptr->mode |= PNG_HAVE_IDAT; + + /* Prior to 1.5.4 this code was replicated in every caller (except at the + * end, where it isn't technically necessary). Since this function has + * flushed the data we can safely reset the zlib output buffer here. + */ + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; +} + +/* Write an IEND chunk */ +void /* PRIVATE */ +png_write_IEND(png_structp png_ptr) +{ + png_debug(1, "in png_write_IEND"); + + png_write_complete_chunk(png_ptr, png_IEND, NULL, (png_size_t)0); + png_ptr->mode |= PNG_HAVE_IEND; +} + +#ifdef PNG_WRITE_gAMA_SUPPORTED +/* Write a gAMA chunk */ +void /* PRIVATE */ +png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma) +{ + png_byte buf[4]; + + png_debug(1, "in png_write_gAMA"); + + /* file_gamma is saved in 1/100,000ths */ + png_save_uint_32(buf, (png_uint_32)file_gamma); + png_write_complete_chunk(png_ptr, png_gAMA, buf, (png_size_t)4); +} +#endif + +#ifdef PNG_WRITE_sRGB_SUPPORTED +/* Write a sRGB chunk */ +void /* PRIVATE */ +png_write_sRGB(png_structp png_ptr, int srgb_intent) +{ + png_byte buf[1]; + + png_debug(1, "in png_write_sRGB"); + + if (srgb_intent >= PNG_sRGB_INTENT_LAST) + png_warning(png_ptr, + "Invalid sRGB rendering intent specified"); + + buf[0]=(png_byte)srgb_intent; + png_write_complete_chunk(png_ptr, png_sRGB, buf, (png_size_t)1); +} +#endif + +#ifdef PNG_WRITE_iCCP_SUPPORTED +/* Write an iCCP chunk */ +void /* PRIVATE */ +png_write_iCCP(png_structp png_ptr, png_const_charp name, int compression_type, + png_const_charp profile, int profile_len) +{ + png_size_t name_len; + png_charp new_name; + compression_state comp; + int embedded_profile_len = 0; + + png_debug(1, "in png_write_iCCP"); + + comp.num_output_ptr = 0; + comp.max_output_ptr = 0; + comp.output_ptr = NULL; + comp.input = NULL; + comp.input_len = 0; + + if ((name_len = png_check_keyword(png_ptr, name, &new_name)) == 0) + return; + + if (compression_type != PNG_COMPRESSION_TYPE_BASE) + png_warning(png_ptr, "Unknown compression type in iCCP chunk"); + + if (profile == NULL) + profile_len = 0; + + if (profile_len > 3) + embedded_profile_len = + ((*( (png_const_bytep)profile ))<<24) | + ((*( (png_const_bytep)profile + 1))<<16) | + ((*( (png_const_bytep)profile + 2))<< 8) | + ((*( (png_const_bytep)profile + 3)) ); + + if (embedded_profile_len < 0) + { + png_warning(png_ptr, + "Embedded profile length in iCCP chunk is negative"); + + png_free(png_ptr, new_name); + return; + } + + if (profile_len < embedded_profile_len) + { + png_warning(png_ptr, + "Embedded profile length too large in iCCP chunk"); + + png_free(png_ptr, new_name); + return; + } + + if (profile_len > embedded_profile_len) + { + png_warning(png_ptr, + "Truncating profile to actual length in iCCP chunk"); + + profile_len = embedded_profile_len; + } + + if (profile_len) + profile_len = png_text_compress(png_ptr, profile, + (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp); + + /* Make sure we include the NULL after the name and the compression type */ + png_write_chunk_header(png_ptr, png_iCCP, + (png_uint_32)(name_len + profile_len + 2)); + + new_name[name_len + 1] = 0x00; + + png_write_chunk_data(png_ptr, (png_bytep)new_name, + (png_size_t)(name_len + 2)); + + if (profile_len) + { + png_write_compressed_data_out(png_ptr, &comp, profile_len); + } + + png_write_chunk_end(png_ptr); + png_free(png_ptr, new_name); +} +#endif + +#ifdef PNG_WRITE_sPLT_SUPPORTED +/* Write a sPLT chunk */ +void /* PRIVATE */ +png_write_sPLT(png_structp png_ptr, png_const_sPLT_tp spalette) +{ + png_size_t name_len; + png_charp new_name; + png_byte entrybuf[10]; + png_size_t entry_size = (spalette->depth == 8 ? 6 : 10); + png_size_t palette_size = entry_size * spalette->nentries; + png_sPLT_entryp ep; +#ifndef PNG_POINTER_INDEXING_SUPPORTED + int i; +#endif + + png_debug(1, "in png_write_sPLT"); + + if ((name_len = png_check_keyword(png_ptr,spalette->name, &new_name))==0) + return; + + /* Make sure we include the NULL after the name */ + png_write_chunk_header(png_ptr, png_sPLT, + (png_uint_32)(name_len + 2 + palette_size)); + + png_write_chunk_data(png_ptr, (png_bytep)new_name, + (png_size_t)(name_len + 1)); + + png_write_chunk_data(png_ptr, &spalette->depth, (png_size_t)1); + + /* Loop through each palette entry, writing appropriately */ +#ifdef PNG_POINTER_INDEXING_SUPPORTED + for (ep = spalette->entries; epentries + spalette->nentries; ep++) + { + if (spalette->depth == 8) + { + entrybuf[0] = (png_byte)ep->red; + entrybuf[1] = (png_byte)ep->green; + entrybuf[2] = (png_byte)ep->blue; + entrybuf[3] = (png_byte)ep->alpha; + png_save_uint_16(entrybuf + 4, ep->frequency); + } + + else + { + png_save_uint_16(entrybuf + 0, ep->red); + png_save_uint_16(entrybuf + 2, ep->green); + png_save_uint_16(entrybuf + 4, ep->blue); + png_save_uint_16(entrybuf + 6, ep->alpha); + png_save_uint_16(entrybuf + 8, ep->frequency); + } + + png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); + } +#else + ep=spalette->entries; + for (i = 0; i>spalette->nentries; i++) + { + if (spalette->depth == 8) + { + entrybuf[0] = (png_byte)ep[i].red; + entrybuf[1] = (png_byte)ep[i].green; + entrybuf[2] = (png_byte)ep[i].blue; + entrybuf[3] = (png_byte)ep[i].alpha; + png_save_uint_16(entrybuf + 4, ep[i].frequency); + } + + else + { + png_save_uint_16(entrybuf + 0, ep[i].red); + png_save_uint_16(entrybuf + 2, ep[i].green); + png_save_uint_16(entrybuf + 4, ep[i].blue); + png_save_uint_16(entrybuf + 6, ep[i].alpha); + png_save_uint_16(entrybuf + 8, ep[i].frequency); + } + + png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); + } +#endif + + png_write_chunk_end(png_ptr); + png_free(png_ptr, new_name); +} +#endif + +#ifdef PNG_WRITE_sBIT_SUPPORTED +/* Write the sBIT chunk */ +void /* PRIVATE */ +png_write_sBIT(png_structp png_ptr, png_const_color_8p sbit, int color_type) +{ + png_byte buf[4]; + png_size_t size; + + png_debug(1, "in png_write_sBIT"); + + /* Make sure we don't depend upon the order of PNG_COLOR_8 */ + if (color_type & PNG_COLOR_MASK_COLOR) + { + png_byte maxbits; + + maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 : + png_ptr->usr_bit_depth); + + if (sbit->red == 0 || sbit->red > maxbits || + sbit->green == 0 || sbit->green > maxbits || + sbit->blue == 0 || sbit->blue > maxbits) + { + png_warning(png_ptr, "Invalid sBIT depth specified"); + return; + } + + buf[0] = sbit->red; + buf[1] = sbit->green; + buf[2] = sbit->blue; + size = 3; + } + + else + { + if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth) + { + png_warning(png_ptr, "Invalid sBIT depth specified"); + return; + } + + buf[0] = sbit->gray; + size = 1; + } + + if (color_type & PNG_COLOR_MASK_ALPHA) + { + if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth) + { + png_warning(png_ptr, "Invalid sBIT depth specified"); + return; + } + + buf[size++] = sbit->alpha; + } + + png_write_complete_chunk(png_ptr, png_sBIT, buf, size); +} +#endif + +#ifdef PNG_WRITE_cHRM_SUPPORTED +/* Write the cHRM chunk */ +void /* PRIVATE */ +png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x, + png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y, + png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x, + png_fixed_point blue_y) +{ + png_byte buf[32]; + + png_debug(1, "in png_write_cHRM"); + + /* Each value is saved in 1/100,000ths */ +#ifdef PNG_CHECK_cHRM_SUPPORTED + if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y, + green_x, green_y, blue_x, blue_y)) +#endif + { + png_save_uint_32(buf, (png_uint_32)white_x); + png_save_uint_32(buf + 4, (png_uint_32)white_y); + + png_save_uint_32(buf + 8, (png_uint_32)red_x); + png_save_uint_32(buf + 12, (png_uint_32)red_y); + + png_save_uint_32(buf + 16, (png_uint_32)green_x); + png_save_uint_32(buf + 20, (png_uint_32)green_y); + + png_save_uint_32(buf + 24, (png_uint_32)blue_x); + png_save_uint_32(buf + 28, (png_uint_32)blue_y); + + png_write_complete_chunk(png_ptr, png_cHRM, buf, (png_size_t)32); + } +} +#endif + +#ifdef PNG_WRITE_tRNS_SUPPORTED +/* Write the tRNS chunk */ +void /* PRIVATE */ +png_write_tRNS(png_structp png_ptr, png_const_bytep trans_alpha, + png_const_color_16p tran, int num_trans, int color_type) +{ + png_byte buf[6]; + + png_debug(1, "in png_write_tRNS"); + + if (color_type == PNG_COLOR_TYPE_PALETTE) + { + if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette) + { + png_warning(png_ptr, "Invalid number of transparent colors specified"); + return; + } + + /* Write the chunk out as it is */ + png_write_complete_chunk(png_ptr, png_tRNS, trans_alpha, + (png_size_t)num_trans); + } + + else if (color_type == PNG_COLOR_TYPE_GRAY) + { + /* One 16 bit value */ + if (tran->gray >= (1 << png_ptr->bit_depth)) + { + png_warning(png_ptr, + "Ignoring attempt to write tRNS chunk out-of-range for bit_depth"); + + return; + } + + png_save_uint_16(buf, tran->gray); + png_write_complete_chunk(png_ptr, png_tRNS, buf, (png_size_t)2); + } + + else if (color_type == PNG_COLOR_TYPE_RGB) + { + /* Three 16 bit values */ + png_save_uint_16(buf, tran->red); + png_save_uint_16(buf + 2, tran->green); + png_save_uint_16(buf + 4, tran->blue); +#ifdef PNG_WRITE_16BIT_SUPPORTED + if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) +#else + if (buf[0] | buf[2] | buf[4]) +#endif + { + png_warning(png_ptr, + "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8"); + return; + } + + png_write_complete_chunk(png_ptr, png_tRNS, buf, (png_size_t)6); + } + + else + { + png_warning(png_ptr, "Can't write tRNS with an alpha channel"); + } +} +#endif + +#ifdef PNG_WRITE_bKGD_SUPPORTED +/* Write the background chunk */ +void /* PRIVATE */ +png_write_bKGD(png_structp png_ptr, png_const_color_16p back, int color_type) +{ + png_byte buf[6]; + + png_debug(1, "in png_write_bKGD"); + + if (color_type == PNG_COLOR_TYPE_PALETTE) + { + if ( +#ifdef PNG_MNG_FEATURES_SUPPORTED + (png_ptr->num_palette || + (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) && +#endif + back->index >= png_ptr->num_palette) + { + png_warning(png_ptr, "Invalid background palette index"); + return; + } + + buf[0] = back->index; + png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)1); + } + + else if (color_type & PNG_COLOR_MASK_COLOR) + { + png_save_uint_16(buf, back->red); + png_save_uint_16(buf + 2, back->green); + png_save_uint_16(buf + 4, back->blue); +#ifdef PNG_WRITE_16BIT_SUPPORTED + if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) +#else + if (buf[0] | buf[2] | buf[4]) +#endif + { + png_warning(png_ptr, + "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8"); + + return; + } + + png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)6); + } + + else + { + if (back->gray >= (1 << png_ptr->bit_depth)) + { + png_warning(png_ptr, + "Ignoring attempt to write bKGD chunk out-of-range for bit_depth"); + + return; + } + + png_save_uint_16(buf, back->gray); + png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)2); + } +} +#endif + +#ifdef PNG_WRITE_hIST_SUPPORTED +/* Write the histogram */ +void /* PRIVATE */ +png_write_hIST(png_structp png_ptr, png_const_uint_16p hist, int num_hist) +{ + int i; + png_byte buf[3]; + + png_debug(1, "in png_write_hIST"); + + if (num_hist > (int)png_ptr->num_palette) + { + png_debug2(3, "num_hist = %d, num_palette = %d", num_hist, + png_ptr->num_palette); + + png_warning(png_ptr, "Invalid number of histogram entries specified"); + return; + } + + png_write_chunk_header(png_ptr, png_hIST, (png_uint_32)(num_hist * 2)); + + for (i = 0; i < num_hist; i++) + { + png_save_uint_16(buf, hist[i]); + png_write_chunk_data(png_ptr, buf, (png_size_t)2); + } + + png_write_chunk_end(png_ptr); +} +#endif + +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ + defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) +/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification, + * and if invalid, correct the keyword rather than discarding the entire + * chunk. The PNG 1.0 specification requires keywords 1-79 characters in + * length, forbids leading or trailing whitespace, multiple internal spaces, + * and the non-break space (0x80) from ISO 8859-1. Returns keyword length. + * + * The new_key is allocated to hold the corrected keyword and must be freed + * by the calling routine. This avoids problems with trying to write to + * static keywords without having to have duplicate copies of the strings. + */ +png_size_t /* PRIVATE */ +png_check_keyword(png_structp png_ptr, png_const_charp key, png_charpp new_key) +{ + png_size_t key_len; + png_const_charp ikp; + png_charp kp, dp; + int kflag; + int kwarn=0; + + png_debug(1, "in png_check_keyword"); + + *new_key = NULL; + + if (key == NULL || (key_len = png_strlen(key)) == 0) + { + png_warning(png_ptr, "zero length keyword"); + return ((png_size_t)0); + } + + png_debug1(2, "Keyword to be checked is '%s'", key); + + *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2)); + + if (*new_key == NULL) + { + png_warning(png_ptr, "Out of memory while procesing keyword"); + return ((png_size_t)0); + } + + /* Replace non-printing characters with a blank and print a warning */ + for (ikp = key, dp = *new_key; *ikp != '\0'; ikp++, dp++) + { + if ((png_byte)*ikp < 0x20 || + ((png_byte)*ikp > 0x7E && (png_byte)*ikp < 0xA1)) + { + PNG_WARNING_PARAMETERS(p) + + png_warning_parameter_unsigned(p, 1, PNG_NUMBER_FORMAT_02x, + (png_byte)*ikp); + png_formatted_warning(png_ptr, p, "invalid keyword character 0x@1"); + *dp = ' '; + } + + else + { + *dp = *ikp; + } + } + *dp = '\0'; + + /* Remove any trailing white space. */ + kp = *new_key + key_len - 1; + if (*kp == ' ') + { + png_warning(png_ptr, "trailing spaces removed from keyword"); + + while (*kp == ' ') + { + *(kp--) = '\0'; + key_len--; + } + } + + /* Remove any leading white space. */ + kp = *new_key; + if (*kp == ' ') + { + png_warning(png_ptr, "leading spaces removed from keyword"); + + while (*kp == ' ') + { + kp++; + key_len--; + } + } + + png_debug1(2, "Checking for multiple internal spaces in '%s'", kp); + + /* Remove multiple internal spaces. */ + for (kflag = 0, dp = *new_key; *kp != '\0'; kp++) + { + if (*kp == ' ' && kflag == 0) + { + *(dp++) = *kp; + kflag = 1; + } + + else if (*kp == ' ') + { + key_len--; + kwarn = 1; + } + + else + { + *(dp++) = *kp; + kflag = 0; + } + } + *dp = '\0'; + if (kwarn) + png_warning(png_ptr, "extra interior spaces removed from keyword"); + + if (key_len == 0) + { + png_free(png_ptr, *new_key); + png_warning(png_ptr, "Zero length keyword"); + } + + if (key_len > 79) + { + png_warning(png_ptr, "keyword length must be 1 - 79 characters"); + (*new_key)[79] = '\0'; + key_len = 79; + } + + return (key_len); +} +#endif + +#ifdef PNG_WRITE_tEXt_SUPPORTED +/* Write a tEXt chunk */ +void /* PRIVATE */ +png_write_tEXt(png_structp png_ptr, png_const_charp key, png_const_charp text, + png_size_t text_len) +{ + png_size_t key_len; + png_charp new_key; + + png_debug(1, "in png_write_tEXt"); + + if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) + return; + + if (text == NULL || *text == '\0') + text_len = 0; + + else + text_len = png_strlen(text); + + /* Make sure we include the 0 after the key */ + png_write_chunk_header(png_ptr, png_tEXt, + (png_uint_32)(key_len + text_len + 1)); + /* + * We leave it to the application to meet PNG-1.0 requirements on the + * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of + * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. + * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. + */ + png_write_chunk_data(png_ptr, (png_bytep)new_key, + (png_size_t)(key_len + 1)); + + if (text_len) + png_write_chunk_data(png_ptr, (png_const_bytep)text, + (png_size_t)text_len); + + png_write_chunk_end(png_ptr); + png_free(png_ptr, new_key); +} +#endif + +#ifdef PNG_WRITE_zTXt_SUPPORTED +/* Write a compressed text chunk */ +void /* PRIVATE */ +png_write_zTXt(png_structp png_ptr, png_const_charp key, png_const_charp text, + png_size_t text_len, int compression) +{ + png_size_t key_len; + png_byte buf; + png_charp new_key; + compression_state comp; + + png_debug(1, "in png_write_zTXt"); + + comp.num_output_ptr = 0; + comp.max_output_ptr = 0; + comp.output_ptr = NULL; + comp.input = NULL; + comp.input_len = 0; + + if ((key_len = png_check_keyword(png_ptr, key, &new_key)) == 0) + { + png_free(png_ptr, new_key); + return; + } + + if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE) + { + png_write_tEXt(png_ptr, new_key, text, (png_size_t)0); + png_free(png_ptr, new_key); + return; + } + + text_len = png_strlen(text); + + /* Compute the compressed data; do it now for the length */ + text_len = png_text_compress(png_ptr, text, text_len, compression, + &comp); + + /* Write start of chunk */ + png_write_chunk_header(png_ptr, png_zTXt, + (png_uint_32)(key_len+text_len + 2)); + + /* Write key */ + png_write_chunk_data(png_ptr, (png_bytep)new_key, + (png_size_t)(key_len + 1)); + + png_free(png_ptr, new_key); + + buf = (png_byte)compression; + + /* Write compression */ + png_write_chunk_data(png_ptr, &buf, (png_size_t)1); + + /* Write the compressed data */ + png_write_compressed_data_out(png_ptr, &comp, text_len); + + /* Close the chunk */ + png_write_chunk_end(png_ptr); +} +#endif + +#ifdef PNG_WRITE_iTXt_SUPPORTED +/* Write an iTXt chunk */ +void /* PRIVATE */ +png_write_iTXt(png_structp png_ptr, int compression, png_const_charp key, + png_const_charp lang, png_const_charp lang_key, png_const_charp text) +{ + png_size_t lang_len, key_len, lang_key_len, text_len; + png_charp new_lang; + png_charp new_key = NULL; + png_byte cbuf[2]; + compression_state comp; + + png_debug(1, "in png_write_iTXt"); + + comp.num_output_ptr = 0; + comp.max_output_ptr = 0; + comp.output_ptr = NULL; + comp.input = NULL; + + if ((key_len = png_check_keyword(png_ptr, key, &new_key)) == 0) + return; + + if ((lang_len = png_check_keyword(png_ptr, lang, &new_lang)) == 0) + { + png_warning(png_ptr, "Empty language field in iTXt chunk"); + new_lang = NULL; + lang_len = 0; + } + + if (lang_key == NULL) + lang_key_len = 0; + + else + lang_key_len = png_strlen(lang_key); + + if (text == NULL) + text_len = 0; + + else + text_len = png_strlen(text); + + /* Compute the compressed data; do it now for the length */ + text_len = png_text_compress(png_ptr, text, text_len, compression - 2, + &comp); + + + /* Make sure we include the compression flag, the compression byte, + * and the NULs after the key, lang, and lang_key parts + */ + + png_write_chunk_header(png_ptr, png_iTXt, (png_uint_32)( + 5 /* comp byte, comp flag, terminators for key, lang and lang_key */ + + key_len + + lang_len + + lang_key_len + + text_len)); + + /* We leave it to the application to meet PNG-1.0 requirements on the + * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of + * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. + * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. + */ + png_write_chunk_data(png_ptr, (png_bytep)new_key, (png_size_t)(key_len + 1)); + + /* Set the compression flag */ + if (compression == PNG_ITXT_COMPRESSION_NONE || + compression == PNG_TEXT_COMPRESSION_NONE) + cbuf[0] = 0; + + else /* compression == PNG_ITXT_COMPRESSION_zTXt */ + cbuf[0] = 1; + + /* Set the compression method */ + cbuf[1] = 0; + + png_write_chunk_data(png_ptr, cbuf, (png_size_t)2); + + cbuf[0] = 0; + png_write_chunk_data(png_ptr, (new_lang ? (png_const_bytep)new_lang : cbuf), + (png_size_t)(lang_len + 1)); + + png_write_chunk_data(png_ptr, (lang_key ? (png_const_bytep)lang_key : cbuf), + (png_size_t)(lang_key_len + 1)); + + png_write_compressed_data_out(png_ptr, &comp, text_len); + + png_write_chunk_end(png_ptr); + + png_free(png_ptr, new_key); + png_free(png_ptr, new_lang); +} +#endif + +#ifdef PNG_WRITE_oFFs_SUPPORTED +/* Write the oFFs chunk */ +void /* PRIVATE */ +png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, + int unit_type) +{ + png_byte buf[9]; + + png_debug(1, "in png_write_oFFs"); + + if (unit_type >= PNG_OFFSET_LAST) + png_warning(png_ptr, "Unrecognized unit type for oFFs chunk"); + + png_save_int_32(buf, x_offset); + png_save_int_32(buf + 4, y_offset); + buf[8] = (png_byte)unit_type; + + png_write_complete_chunk(png_ptr, png_oFFs, buf, (png_size_t)9); +} +#endif +#ifdef PNG_WRITE_pCAL_SUPPORTED +/* Write the pCAL chunk (described in the PNG extensions document) */ +void /* PRIVATE */ +png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, + png_int_32 X1, int type, int nparams, png_const_charp units, + png_charpp params) +{ + png_size_t purpose_len, units_len, total_len; + png_size_tp params_len; + png_byte buf[10]; + png_charp new_purpose; + int i; + + png_debug1(1, "in png_write_pCAL (%d parameters)", nparams); + + if (type >= PNG_EQUATION_LAST) + png_warning(png_ptr, "Unrecognized equation type for pCAL chunk"); + + purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1; + png_debug1(3, "pCAL purpose length = %d", (int)purpose_len); + units_len = png_strlen(units) + (nparams == 0 ? 0 : 1); + png_debug1(3, "pCAL units length = %d", (int)units_len); + total_len = purpose_len + units_len + 10; + + params_len = (png_size_tp)png_malloc(png_ptr, + (png_alloc_size_t)(nparams * png_sizeof(png_size_t))); + + /* Find the length of each parameter, making sure we don't count the + * null terminator for the last parameter. + */ + for (i = 0; i < nparams; i++) + { + params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1); + png_debug2(3, "pCAL parameter %d length = %lu", i, + (unsigned long)params_len[i]); + total_len += params_len[i]; + } + + png_debug1(3, "pCAL total length = %d", (int)total_len); + png_write_chunk_header(png_ptr, png_pCAL, (png_uint_32)total_len); + png_write_chunk_data(png_ptr, (png_const_bytep)new_purpose, purpose_len); + png_save_int_32(buf, X0); + png_save_int_32(buf + 4, X1); + buf[8] = (png_byte)type; + buf[9] = (png_byte)nparams; + png_write_chunk_data(png_ptr, buf, (png_size_t)10); + png_write_chunk_data(png_ptr, (png_const_bytep)units, (png_size_t)units_len); + + png_free(png_ptr, new_purpose); + + for (i = 0; i < nparams; i++) + { + png_write_chunk_data(png_ptr, (png_const_bytep)params[i], params_len[i]); + } + + png_free(png_ptr, params_len); + png_write_chunk_end(png_ptr); +} +#endif + +#ifdef PNG_WRITE_sCAL_SUPPORTED +/* Write the sCAL chunk */ +void /* PRIVATE */ +png_write_sCAL_s(png_structp png_ptr, int unit, png_const_charp width, + png_const_charp height) +{ + png_byte buf[64]; + png_size_t wlen, hlen, total_len; + + png_debug(1, "in png_write_sCAL_s"); + + wlen = png_strlen(width); + hlen = png_strlen(height); + total_len = wlen + hlen + 2; + + if (total_len > 64) + { + png_warning(png_ptr, "Can't write sCAL (buffer too small)"); + return; + } + + buf[0] = (png_byte)unit; + png_memcpy(buf + 1, width, wlen + 1); /* Append the '\0' here */ + png_memcpy(buf + wlen + 2, height, hlen); /* Do NOT append the '\0' here */ + + png_debug1(3, "sCAL total length = %u", (unsigned int)total_len); + png_write_complete_chunk(png_ptr, png_sCAL, buf, total_len); +} +#endif + +#ifdef PNG_WRITE_pHYs_SUPPORTED +/* Write the pHYs chunk */ +void /* PRIVATE */ +png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, + png_uint_32 y_pixels_per_unit, + int unit_type) +{ + png_byte buf[9]; + + png_debug(1, "in png_write_pHYs"); + + if (unit_type >= PNG_RESOLUTION_LAST) + png_warning(png_ptr, "Unrecognized unit type for pHYs chunk"); + + png_save_uint_32(buf, x_pixels_per_unit); + png_save_uint_32(buf + 4, y_pixels_per_unit); + buf[8] = (png_byte)unit_type; + + png_write_complete_chunk(png_ptr, png_pHYs, buf, (png_size_t)9); +} +#endif + +#ifdef PNG_WRITE_tIME_SUPPORTED +/* Write the tIME chunk. Use either png_convert_from_struct_tm() + * or png_convert_from_time_t(), or fill in the structure yourself. + */ +void /* PRIVATE */ +png_write_tIME(png_structp png_ptr, png_const_timep mod_time) +{ + png_byte buf[7]; + + png_debug(1, "in png_write_tIME"); + + if (mod_time->month > 12 || mod_time->month < 1 || + mod_time->day > 31 || mod_time->day < 1 || + mod_time->hour > 23 || mod_time->second > 60) + { + png_warning(png_ptr, "Invalid time specified for tIME chunk"); + return; + } + + png_save_uint_16(buf, mod_time->year); + buf[2] = mod_time->month; + buf[3] = mod_time->day; + buf[4] = mod_time->hour; + buf[5] = mod_time->minute; + buf[6] = mod_time->second; + + png_write_complete_chunk(png_ptr, png_tIME, buf, (png_size_t)7); +} +#endif + +/* Initializes the row writing capability of libpng */ +void /* PRIVATE */ +png_write_start_row(png_structp png_ptr) +{ +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif + + png_alloc_size_t buf_size; + int usr_pixel_depth; + + png_debug(1, "in png_write_start_row"); + + usr_pixel_depth = png_ptr->usr_channels * png_ptr->usr_bit_depth; + buf_size = PNG_ROWBYTES(usr_pixel_depth, png_ptr->width) + 1; + + /* 1.5.6: added to allow checking in the row write code. */ + png_ptr->transformed_pixel_depth = png_ptr->pixel_depth; + png_ptr->maximum_pixel_depth = (png_byte)usr_pixel_depth; + + /* Set up row buffer */ + png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, buf_size); + + png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; + +#ifdef PNG_WRITE_FILTER_SUPPORTED + /* Set up filtering buffer, if using this filter */ + if (png_ptr->do_filter & PNG_FILTER_SUB) + { + png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1); + + png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; + } + + /* We only need to keep the previous row if we are using one of these. */ + if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) + { + /* Set up previous row buffer */ + png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, buf_size); + + if (png_ptr->do_filter & PNG_FILTER_UP) + { + png_ptr->up_row = (png_bytep)png_malloc(png_ptr, + png_ptr->rowbytes + 1); + + png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; + } + + if (png_ptr->do_filter & PNG_FILTER_AVG) + { + png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, + png_ptr->rowbytes + 1); + + png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; + } + + if (png_ptr->do_filter & PNG_FILTER_PAETH) + { + png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, + png_ptr->rowbytes + 1); + + png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; + } + } +#endif /* PNG_WRITE_FILTER_SUPPORTED */ + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* If interlaced, we need to set up width and height of pass */ + if (png_ptr->interlaced) + { + if (!(png_ptr->transformations & PNG_INTERLACE)) + { + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - + png_pass_ystart[0]) / png_pass_yinc[0]; + + png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 - + png_pass_start[0]) / png_pass_inc[0]; + } + + else + { + png_ptr->num_rows = png_ptr->height; + png_ptr->usr_width = png_ptr->width; + } + } + + else +#endif + { + png_ptr->num_rows = png_ptr->height; + png_ptr->usr_width = png_ptr->width; + } + + png_zlib_claim(png_ptr, PNG_ZLIB_FOR_IDAT); + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_out = png_ptr->zbuf; +} + +/* Internal use only. Called when finished processing a row of data. */ +void /* PRIVATE */ +png_write_finish_row(png_structp png_ptr) +{ +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif + + int ret; + + png_debug(1, "in png_write_finish_row"); + + /* Next row */ + png_ptr->row_number++; + + /* See if we are done */ + if (png_ptr->row_number < png_ptr->num_rows) + return; + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* If interlaced, go to next pass */ + if (png_ptr->interlaced) + { + png_ptr->row_number = 0; + if (png_ptr->transformations & PNG_INTERLACE) + { + png_ptr->pass++; + } + + else + { + /* Loop until we find a non-zero width or height pass */ + do + { + png_ptr->pass++; + + if (png_ptr->pass >= 7) + break; + + png_ptr->usr_width = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + + png_ptr->num_rows = (png_ptr->height + + png_pass_yinc[png_ptr->pass] - 1 - + png_pass_ystart[png_ptr->pass]) / + png_pass_yinc[png_ptr->pass]; + + if (png_ptr->transformations & PNG_INTERLACE) + break; + + } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0); + + } + + /* Reset the row above the image for the next pass */ + if (png_ptr->pass < 7) + { + if (png_ptr->prev_row != NULL) + png_memset(png_ptr->prev_row, 0, + (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels* + png_ptr->usr_bit_depth, png_ptr->width)) + 1); + + return; + } + } +#endif + + /* If we get here, we've just written the last row, so we need + to flush the compressor */ + do + { + /* Tell the compressor we are done */ + ret = deflate(&png_ptr->zstream, Z_FINISH); + + /* Check for an error */ + if (ret == Z_OK) + { + /* Check to see if we need more room */ + if (!(png_ptr->zstream.avail_out)) + { + png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + } + } + + else if (ret != Z_STREAM_END) + { + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + + else + png_error(png_ptr, "zlib error"); + } + } while (ret != Z_STREAM_END); + + /* Write any extra space */ + if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) + { + png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size - + png_ptr->zstream.avail_out); + } + + png_zlib_release(png_ptr); + png_ptr->zstream.data_type = Z_BINARY; +} + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED +/* Pick out the correct pixels for the interlace pass. + * The basic idea here is to go through the row with a source + * pointer and a destination pointer (sp and dp), and copy the + * correct pixels for the pass. As the row gets compacted, + * sp will always be >= dp, so we should never overwrite anything. + * See the default: case for the easiest code to understand. + */ +void /* PRIVATE */ +png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) +{ + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + png_debug(1, "in png_do_write_interlace"); + + /* We don't have to do anything on the last pass (6) */ + if (pass < 6) + { + /* Each pixel depth is handled separately */ + switch (row_info->pixel_depth) + { + case 1: + { + png_bytep sp; + png_bytep dp; + int shift; + int d; + int value; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + dp = row; + d = 0; + shift = 7; + + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + sp = row + (png_size_t)(i >> 3); + value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01; + d |= (value << shift); + + if (shift == 0) + { + shift = 7; + *dp++ = (png_byte)d; + d = 0; + } + + else + shift--; + + } + if (shift != 7) + *dp = (png_byte)d; + + break; + } + + case 2: + { + png_bytep sp; + png_bytep dp; + int shift; + int d; + int value; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + dp = row; + shift = 6; + d = 0; + + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + sp = row + (png_size_t)(i >> 2); + value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03; + d |= (value << shift); + + if (shift == 0) + { + shift = 6; + *dp++ = (png_byte)d; + d = 0; + } + + else + shift -= 2; + } + if (shift != 6) + *dp = (png_byte)d; + + break; + } + + case 4: + { + png_bytep sp; + png_bytep dp; + int shift; + int d; + int value; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + dp = row; + shift = 4; + d = 0; + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + sp = row + (png_size_t)(i >> 1); + value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f; + d |= (value << shift); + + if (shift == 0) + { + shift = 4; + *dp++ = (png_byte)d; + d = 0; + } + + else + shift -= 4; + } + if (shift != 4) + *dp = (png_byte)d; + + break; + } + + default: + { + png_bytep sp; + png_bytep dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + png_size_t pixel_bytes; + + /* Start at the beginning */ + dp = row; + + /* Find out how many bytes each pixel takes up */ + pixel_bytes = (row_info->pixel_depth >> 3); + + /* Loop through the row, only looking at the pixels that matter */ + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + /* Find out where the original pixel is */ + sp = row + (png_size_t)i * pixel_bytes; + + /* Move the pixel */ + if (dp != sp) + png_memcpy(dp, sp, pixel_bytes); + + /* Next pixel */ + dp += pixel_bytes; + } + break; + } + } + /* Set new row width */ + row_info->width = (row_info->width + + png_pass_inc[pass] - 1 - + png_pass_start[pass]) / + png_pass_inc[pass]; + + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, + row_info->width); + } +} +#endif + +/* This filters the row, chooses which filter to use, if it has not already + * been specified by the application, and then writes the row out with the + * chosen filter. + */ +static void png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row, + png_size_t row_bytes); + +#define PNG_MAXSUM (((png_uint_32)(-1)) >> 1) +#define PNG_HISHIFT 10 +#define PNG_LOMASK ((png_uint_32)0xffffL) +#define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT)) +void /* PRIVATE */ +png_write_find_filter(png_structp png_ptr, png_row_infop row_info) +{ + png_bytep best_row; +#ifdef PNG_WRITE_FILTER_SUPPORTED + png_bytep prev_row, row_buf; + png_uint_32 mins, bpp; + png_byte filter_to_do = png_ptr->do_filter; + png_size_t row_bytes = row_info->rowbytes; +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + int num_p_filters = png_ptr->num_prev_filters; +#endif + + png_debug(1, "in png_write_find_filter"); + +#ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS) + { + /* These will never be selected so we need not test them. */ + filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_PAETH); + } +#endif + + /* Find out how many bytes offset each pixel is */ + bpp = (row_info->pixel_depth + 7) >> 3; + + prev_row = png_ptr->prev_row; +#endif + best_row = png_ptr->row_buf; +#ifdef PNG_WRITE_FILTER_SUPPORTED + row_buf = best_row; + mins = PNG_MAXSUM; + + /* The prediction method we use is to find which method provides the + * smallest value when summing the absolute values of the distances + * from zero, using anything >= 128 as negative numbers. This is known + * as the "minimum sum of absolute differences" heuristic. Other + * heuristics are the "weighted minimum sum of absolute differences" + * (experimental and can in theory improve compression), and the "zlib + * predictive" method (not implemented yet), which does test compressions + * of lines using different filter methods, and then chooses the + * (series of) filter(s) that give minimum compressed data size (VERY + * computationally expensive). + * + * GRR 980525: consider also + * + * (1) minimum sum of absolute differences from running average (i.e., + * keep running sum of non-absolute differences & count of bytes) + * [track dispersion, too? restart average if dispersion too large?] + * + * (1b) minimum sum of absolute differences from sliding average, probably + * with window size <= deflate window (usually 32K) + * + * (2) minimum sum of squared differences from zero or running average + * (i.e., ~ root-mean-square approach) + */ + + + /* We don't need to test the 'no filter' case if this is the only filter + * that has been chosen, as it doesn't actually do anything to the data. + */ + if ((filter_to_do & PNG_FILTER_NONE) && filter_to_do != PNG_FILTER_NONE) + { + png_bytep rp; + png_uint_32 sum = 0; + png_size_t i; + int v; + + for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++) + { + v = *rp; + sum += (v < 128) ? v : 256 - v; + } + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + png_uint_32 sumhi, sumlo; + int j; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */ + + /* Reduce the sum if we match any of the previous rows */ + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE) + { + sumlo = (sumlo * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + + sumhi = (sumhi * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + /* Factor in the cost of this filter (this is here for completeness, + * but it makes no sense to have a "cost" for the NONE filter, as + * it has the minimum possible computational cost - none). + */ + sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >> + PNG_COST_SHIFT; + + sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + mins = sum; + } + + /* Sub filter */ + if (filter_to_do == PNG_FILTER_SUB) + /* It's the only filter so no testing is needed */ + { + png_bytep rp, lp, dp; + png_size_t i; + + for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp; + i++, rp++, dp++) + { + *dp = *rp; + } + + for (lp = row_buf + 1; i < row_bytes; + i++, rp++, lp++, dp++) + { + *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff); + } + + best_row = png_ptr->sub_row; + } + + else if (filter_to_do & PNG_FILTER_SUB) + { + png_bytep rp, dp, lp; + png_uint_32 sum = 0, lmins = mins; + png_size_t i; + int v; + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + /* We temporarily increase the "minimum sum" by the factor we + * would reduce the sum of this filter, so that we can do the + * early exit comparison without scaling the sum each time. + */ + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 lmhi, lmlo; + lmlo = lmins & PNG_LOMASK; + lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB) + { + lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + + lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> + PNG_COST_SHIFT; + + lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> + PNG_COST_SHIFT; + + if (lmhi > PNG_HIMASK) + lmins = PNG_MAXSUM; + + else + lmins = (lmhi << PNG_HISHIFT) + lmlo; + } +#endif + + for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp; + i++, rp++, dp++) + { + v = *dp = *rp; + + sum += (v < 128) ? v : 256 - v; + } + + for (lp = row_buf + 1; i < row_bytes; + i++, rp++, lp++, dp++) + { + v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff); + + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 sumhi, sumlo; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB) + { + sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + + sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> + PNG_COST_SHIFT; + + sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + + if (sum < mins) + { + mins = sum; + best_row = png_ptr->sub_row; + } + } + + /* Up filter */ + if (filter_to_do == PNG_FILTER_UP) + { + png_bytep rp, dp, pp; + png_size_t i; + + for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, + pp = prev_row + 1; i < row_bytes; + i++, rp++, pp++, dp++) + { + *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff); + } + + best_row = png_ptr->up_row; + } + + else if (filter_to_do & PNG_FILTER_UP) + { + png_bytep rp, dp, pp; + png_uint_32 sum = 0, lmins = mins; + png_size_t i; + int v; + + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 lmhi, lmlo; + lmlo = lmins & PNG_LOMASK; + lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP) + { + lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + + lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >> + PNG_COST_SHIFT; + + lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >> + PNG_COST_SHIFT; + + if (lmhi > PNG_HIMASK) + lmins = PNG_MAXSUM; + + else + lmins = (lmhi << PNG_HISHIFT) + lmlo; + } +#endif + + for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, + pp = prev_row + 1; i < row_bytes; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); + + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 sumhi, sumlo; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP) + { + sumlo = (sumlo * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + + sumhi = (sumhi * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >> + PNG_COST_SHIFT; + + sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + + if (sum < mins) + { + mins = sum; + best_row = png_ptr->up_row; + } + } + + /* Avg filter */ + if (filter_to_do == PNG_FILTER_AVG) + { + png_bytep rp, dp, pp, lp; + png_uint_32 i; + + for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1, + pp = prev_row + 1; i < bpp; i++) + { + *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff); + } + + for (lp = row_buf + 1; i < row_bytes; i++) + { + *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) + & 0xff); + } + best_row = png_ptr->avg_row; + } + + else if (filter_to_do & PNG_FILTER_AVG) + { + png_bytep rp, dp, pp, lp; + png_uint_32 sum = 0, lmins = mins; + png_size_t i; + int v; + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 lmhi, lmlo; + lmlo = lmins & PNG_LOMASK; + lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG) + { + lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + + lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >> + PNG_COST_SHIFT; + + lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >> + PNG_COST_SHIFT; + + if (lmhi > PNG_HIMASK) + lmins = PNG_MAXSUM; + + else + lmins = (lmhi << PNG_HISHIFT) + lmlo; + } +#endif + + for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1, + pp = prev_row + 1; i < bpp; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff); + + sum += (v < 128) ? v : 256 - v; + } + + for (lp = row_buf + 1; i < row_bytes; i++) + { + v = *dp++ = + (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff); + + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 sumhi, sumlo; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE) + { + sumlo = (sumlo * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + + sumhi = (sumhi * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >> + PNG_COST_SHIFT; + + sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + + if (sum < mins) + { + mins = sum; + best_row = png_ptr->avg_row; + } + } + + /* Paeth filter */ + if (filter_to_do == PNG_FILTER_PAETH) + { + png_bytep rp, dp, pp, cp, lp; + png_size_t i; + + for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, + pp = prev_row + 1; i < bpp; i++) + { + *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); + } + + for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++) + { + int a, b, c, pa, pb, pc, p; + + b = *pp++; + c = *cp++; + a = *lp++; + + p = b - c; + pc = a - c; + +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif + + p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; + + *dp++ = (png_byte)(((int)*rp++ - p) & 0xff); + } + best_row = png_ptr->paeth_row; + } + + else if (filter_to_do & PNG_FILTER_PAETH) + { + png_bytep rp, dp, pp, cp, lp; + png_uint_32 sum = 0, lmins = mins; + png_size_t i; + int v; + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 lmhi, lmlo; + lmlo = lmins & PNG_LOMASK; + lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH) + { + lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + + lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >> + PNG_COST_SHIFT; + + lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >> + PNG_COST_SHIFT; + + if (lmhi > PNG_HIMASK) + lmins = PNG_MAXSUM; + + else + lmins = (lmhi << PNG_HISHIFT) + lmlo; + } +#endif + + for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, + pp = prev_row + 1; i < bpp; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); + + sum += (v < 128) ? v : 256 - v; + } + + for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++) + { + int a, b, c, pa, pb, pc, p; + + b = *pp++; + c = *cp++; + a = *lp++; + +#ifndef PNG_SLOW_PAETH + p = b - c; + pc = a - c; +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif + p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; +#else /* PNG_SLOW_PAETH */ + p = a + b - c; + pa = abs(p - a); + pb = abs(p - b); + pc = abs(p - c); + + if (pa <= pb && pa <= pc) + p = a; + + else if (pb <= pc) + p = b; + + else + p = c; +#endif /* PNG_SLOW_PAETH */ + + v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff); + + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 sumhi, sumlo; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH) + { + sumlo = (sumlo * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + + sumhi = (sumhi * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >> + PNG_COST_SHIFT; + + sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + + if (sum < mins) + { + best_row = png_ptr->paeth_row; + } + } +#endif /* PNG_WRITE_FILTER_SUPPORTED */ + + /* Do the actual writing of the filtered row data from the chosen filter. */ + png_write_filtered_row(png_ptr, best_row, row_info->rowbytes+1); + +#ifdef PNG_WRITE_FILTER_SUPPORTED +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + /* Save the type of filter we picked this time for future calculations */ + if (png_ptr->num_prev_filters > 0) + { + int j; + + for (j = 1; j < num_p_filters; j++) + { + png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1]; + } + + png_ptr->prev_filters[j] = best_row[0]; + } +#endif +#endif /* PNG_WRITE_FILTER_SUPPORTED */ +} + + +/* Do the actual writing of a previously filtered row. */ +static void +png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row, + png_size_t avail/*includes filter byte*/) +{ + png_debug(1, "in png_write_filtered_row"); + + png_debug1(2, "filter = %d", filtered_row[0]); + /* Set up the zlib input buffer */ + + png_ptr->zstream.next_in = filtered_row; + png_ptr->zstream.avail_in = 0; + /* Repeat until we have compressed all the data */ + do + { + int ret; /* Return of zlib */ + + /* Record the number of bytes available - zlib supports at least 65535 + * bytes at one step, depending on the size of the zlib type 'uInt', the + * maximum size zlib can write at once is ZLIB_IO_MAX (from pngpriv.h). + * Use this because on 16 bit systems 'rowbytes' can be up to 65536 (i.e. + * one more than 16 bits) and, in this case 'rowbytes+1' can overflow a + * uInt. ZLIB_IO_MAX can be safely reduced to cause zlib to be called + * with smaller chunks of data. + */ + if (png_ptr->zstream.avail_in == 0) + { + if (avail > ZLIB_IO_MAX) + { + png_ptr->zstream.avail_in = ZLIB_IO_MAX; + avail -= ZLIB_IO_MAX; + } + + else + { + /* So this will fit in the available uInt space: */ + png_ptr->zstream.avail_in = (uInt)avail; + avail = 0; + } + } + + /* Compress the data */ + ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); + + /* Check for compression errors */ + if (ret != Z_OK) + { + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + + else + png_error(png_ptr, "zlib error"); + } + + /* See if it is time to write another IDAT */ + if (!(png_ptr->zstream.avail_out)) + { + /* Write the IDAT and reset the zlib output buffer */ + png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); + } + /* Repeat until all data has been compressed */ + } while (avail > 0 || png_ptr->zstream.avail_in > 0); + + /* Swap the current and previous rows */ + if (png_ptr->prev_row != NULL) + { + png_bytep tptr; + + tptr = png_ptr->prev_row; + png_ptr->prev_row = png_ptr->row_buf; + png_ptr->row_buf = tptr; + } + + /* Finish row - updates counters and flushes zlib if last row */ + png_write_finish_row(png_ptr); + +#ifdef PNG_WRITE_FLUSH_SUPPORTED + png_ptr->flush_rows++; + + if (png_ptr->flush_dist > 0 && + png_ptr->flush_rows >= png_ptr->flush_dist) + { + png_write_flush(png_ptr); + } +#endif +} +#endif /* PNG_WRITE_SUPPORTED */ diff --git a/Source/LibRawLite/COPYRIGHT b/Source/LibRawLite/COPYRIGHT index e4ec2ff..884e9a3 100644 --- a/Source/LibRawLite/COPYRIGHT +++ b/Source/LibRawLite/COPYRIGHT @@ -1,23 +1,23 @@ - ** LibRaw: Raw images processing library ** - -Copyright (C) 2008-2010 LibRaw LLC (http://www.libraw.org, info@libraw.org) - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - - -LibRaw uses code from dcraw.c -- Dave Coffin's raw photo decoder, -dcraw.c is copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net. - -LibRaw uses DCB demosaic and FBDD denoise licensed under BSD-like 3-clause license -DCB and FBDD are Copyright (C) 2010, Jacek Gozdz (cuniek@kft.umcs.lublin.pl) - + ** LibRaw: Raw images processing library ** + +Copyright (C) 2008-2010 LibRaw LLC (http://www.libraw.org, info@libraw.org) + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + + +LibRaw uses code from dcraw.c -- Dave Coffin's raw photo decoder, +dcraw.c is copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net. + +LibRaw uses DCB demosaic and FBDD denoise licensed under BSD-like 3-clause license +DCB and FBDD are Copyright (C) 2010, Jacek Gozdz (cuniek@kft.umcs.lublin.pl) + diff --git a/Source/LibRawLite/Changelog.txt b/Source/LibRawLite/Changelog.txt index 76dd7a2..0b8dca9 100644 --- a/Source/LibRawLite/Changelog.txt +++ b/Source/LibRawLite/Changelog.txt @@ -1,1295 +1,1295 @@ -2012-06-27 Alex Tutubalin - * Imported dcraw 9.15 (1.449): - - New cameras supported: Canon 5D Mark III, G1 X, 1D X and Powershot SX200; - Nikon D4,D800/D800E and D3200; Fuji X-S1 and HS30EXR; Casio EX-Z8; - Olympus E-M5; Panasonic GF5; Sony NEX-F3, SLT-A37 and SLT-A57; - Samsung NX20 and NX210; - - Support for updated Samsung NX200 firmware. - * Makefile.msvc: additional compiler flags - * LibRaw 0.14.7-Release - -2012-04-11 Alex Tutubalin - * Fixed thumbnail processing (esp. for Adobe Lightroom DNGs) - -2012-04-05 Alex Tutubalin - * Casio EX-Z500 support - * (possible) I/O exceptions on file open catched in open_datastream - * Fixed possible read-after-buffer in Sony ARW2 decoder - * Fixed mingw32 errors when compiling LibRaw_windows_datastream - * Makefile.msvc: support of OpenMP and LCMS (uncomment to use) - * Fixed decoding of some Leaf Aptus II files - * LibRaw 0.14.6-Release - -2011-12-24 Alex Tutubalin - * Fixed bug (uninitialized variable) in SMAL format decoding. - - * Imported new dcraw 9.12 (1.446): support for Leica V-LUX 3, - updated color data for Canon S100, Fujifilm X10, Nikon 1 J1/V1, - Panasonic GX1, Samsung NX200, Sony NEX-7 - - * LibRaw 0.14.5-Release - -2011-12-12 Alex Tutubalin - - * Fixes to Panasonic/Leica file parser to prevent crash - on broken jpegs. - - * Fixes to include order in src/libraw_datastream.cpp to - better compile with KDEWIN - - * Floating-point DNGs are rejected on early processing stage. - - * Support for new cameras: Canon S100, Fuji X10, Panasonic GX1, - Samsung NX200, Sony NEX-7. - - * LibRaw 0.14.4-Release - - -2011-10-26 Alex Tutubalin - * Bug fixes in black level subtraction code for PhaseOne files - - * New API call LibRaw::get_internal_data_pointer() for developers - who need access to libraw_internal_data fields (i.e. - Fuji SuperCCD layout). - - * doc/API-overview fixes to reflect 0.14 changes - - * LibRaw 0.14.3-Release - -2011-10-19 Alex Tutubalin - * Fixed bug in Canon 1D and 1Ds files decoding. - * New decoder information bit DECODER_HASRAWCURVE - * LibRaw 0.14.2-Release - -2011-10-11 Alex Tutubalin - * Imported dcraw 9.11/1.445: - + Support for new cameras added: Fujifilm F600EXR, Nikon P7100, - Olympus E-PL3 and E-PM1, Panasonic DMC-FZ150, Sony NEX-5N, - A65 and A77. - + Changed color data for: Olympus E-P3, Panasonic G3 and GF3, - PhaseOne H25, P40 and P65, Sony NEX-C3, NEX-5, NEX-3, A35 and A55. - + Support for dark frame extraction on Sony cameras. - - * DCB demosaicing: reserving 6 pixels instead of 3 to suppress - colored image frame. - * LibRaw 0.14.1-Release - -2011-09-21 Alex Tutubalin - * Cosmetic changes to make Visual C++/OpenMP more happy - * Fix megapixel calculation for postprocessing_benchmark in half mode - * Shlib version number increment - * LibRaw 0.14.0-Release - -2011-09-04 Alex Tutubalin - * Fixed bug with Kodak thumbnail extraction - * raw2image_ex() always return value - * LibRaw 0.14.0-Beta2 - -2011-09-02 Alex Tutubalin - * Cosmetic changes to LibRaw_file_datastream interface - - * OpenMP speedup of postprocessing steps (up to 50% for - half mode and 4-core machine) - - * LibRaw 0.14.0-Beta1 - -2011-08-20 Alex Tutubalin - - * Patch to dcraw_emu for SunStudio compiler compatibility - - * Fixed crash in unprocessed_raw sample due to uninitialized - timestamp variable. - - * Fixed crash in raw decoding if raw_width/raw_height is - less than resulting image width/height. - - * imgdata.sizes.flip is set from user_flip only on - postprocessing and/or adjust_sizes_info_only() - - * Fixed buffer overrun for some LJPEG-compressed files - - * Most of LibRaw_datastream function bodies are moved to - separate source file - - * LibRaw_windows_datastream is merged to main sourcetree - - * LibRaw 0.14.0-Alpha5 - -2011-08-11 Alex Tutubalin - * Imported dcraw 9.10 (1.444), support for new cameras added: - ARRIRAW format, Canon SX30 IS, Leica D-LUX 5 and V-LUX2, - Olympus E-P3, Panasonic G3 and GF3, Sony NEX-C3 and SLT-A35 - - * Support for RedOne digital movie cameras (R3D format). - To enable this support you should: - + install libjasper JPEG2000 support library - - + compile LibRaw with -DUSE_JASPER compiler switch (./configure - will do it for you) - - + If you use own LibRaw_datastream implementation, you should - implement make_jas_stream() call for your datastream. See - bottom of src/libraw_cxx.cpp for implementations in datafile - and mem-buffer LibRaw streams. - - * Bugfix: green matching is turned off if output image is shrinked - due to wavelet filtering or aberration correction. - - * fixed open_file()/adjust_sizes_info_only() code path - - * Removed imgdata.sizes.bottom_margin and right_margin data fields - use imgdata.sizes.raw_width - width - left_margin to get right one, - the same with bottom_margin. - - * minor ./configure cleanup - - * Qmake files and Visual Studio Project files are updated. - - * New version check macros: - For use at runtime checks: - LIBRAW_RUNTIME_CHECK_VERSION_EXACT() - checks that runtime - major/minor version numbers are same with compile-time values. - - LIBRAW_RUNTIME_CHECK_VERSION_NOTLESS() - checks that runtime - version is not less that compile-time one. - - For use at compile-time in preprocessor directives: - LIBRAW_COMPILE_CHECK_VERSION_EXACT(major,minor) - Compile-time - check that LibRaw version is exact major.minor. - - LIBRAW_COMPILE_CHECK_VERSION_NOTLESS(major,minor) - Compile-time - check that version is not less than major.minor. - - * all client code should be recompiled due to internals change. - - * LibRaw 0.14.0-Alpha4 - -2011-07-19 Alex Tutubalin - * New sample samples/postprocessing_benchmark.cpp - This sample measures postprocessing speed. - All demosaic methods, averaged white balance, median - filtering, wavelet filtration, highlight recovery, and - cropping are supported. - - * Removed LibRaw::rotate_fuji_raw() call and corresponding C-API call. - - * The LibRaw::adjust_sizes_info_only() call may be called repeated - and mixed with dcraw_process() call. - - * Postprocessing speedup and optimization, especially if cropping set. - - * Cropping works for FujiCCD raws. For the technical reasons, the position - of top-left corner of crop area will be rounded to the nearest - multiple of 4 (the corner is shifted top-left). - - * LibRaw 0.14.0-Alpha3 - -2011-07-15 Alex Tutubalin - * imported cropping code from 0.13 branch - -2011-07-12 Alex Tutubalin - * samples/multirender_test - check for different clip settings - -2011-07-11 Alex Tutubalin - * New call LibRaw::free_image(), deallocates imgdata.image buffer. - Use this call if current postprocessing results are not - needed, but it is to early to call recycle() because - dcraw_process() may be called later. - - * New C-API calls - libraw_raw2image() - C API for LibRaw::raw2image() - libraw_free_image() - C API for LibRaw::free_image() - libraw_get_decoder_info() - C API for LibRaw::get_decoder_info() - - * Bugfix: change of params.user_flip aftee open()/unpack() - calls should work. - - * LibRaw 0.14.0-Alpha2 - -2011-07-10 Alex Tutubalin - * Multiple rendering (LibRaw::dcraw_process() calls) allowed - without re-opening RAW file thrfough the sequence of open()/unpack() - calls. - You should be able to change any processing parameters (except - shot_select parameter) between dcraw_process() calls. - - + New sample in samples/multirender_test.cpp: renders data 4 times: - in half and full modes with different white balance settings. - - + Unprocessed RAW data is stored in separate data buffer: - (2 bytes per pixel for all Bayer-pattern images, - 8 bytes per pixel for Foveon, sRAW, and other full-color raw - formats), so now LibRaw uses 25% more memory for full processing of - most common Bayer images; while for just unpack memory is reduced - 4 times. - - + New call LibRaw::raw2image() fills imgdata.image array - with fresh copy of data. - There is no need to call raw2image() separately if you use - dcraw_process() or dcraw_document_mode_processing() calls. - - + New call LibRaw::get_decoder_info() to determine raw data - storage layout. See samples/unprocessed_raw.cpp for an example - of how to use it. - - If your code uses usual open()/unpack()/dcraw_process() call - sequence, then NOTHING CHANGED: your program should produce same - results. For interactive programs you may skip open()/unpack() - calls after adjusting processing parameters, so user should see - image refreshed much faster. - - If your code uses raw data (open+unpack calls), you need to call - LibRaw::raw2image(), and imgdata.image will contain same bitmap - as in LibRaw 0.13.x - - If you code uses access to masked borders data, you need to - rewrite it. See samples/unprocessed_raw.cpp as a sample. - - Unfortunately, documentation is untouched yet. This problem will be - fixed in next Alpha release. - - Other changes: - - * No separate imgdata.masked_pixels buffers, Bayer raw formats are read - to buffer with borders. So, no ugly add_masked_border_to_bitmap() - call. - - * No filtering_mode parameter. Raw tone curve is applied - at unpack() stage; zero pixels removed on postprocesing stage. - - * unprocessed_raw and 4colors samples are adjusted to use - new RAW data storage layout. - - * all client code should be recompiled due to internals change. - - * LibRaw 0.14.0-Alpha1 - -2011-07-03 Alex Tutubalin - * Cosmetic cleanup in Libraw_memmgr code - - * Permit OpenMP support on MS VS2008 - - * More general mem_image interface: - + New call get_mem_image_format returns bitmap size and bit depth - + New call copy_mem_image can copy bitmap into buffer with - different color order (RGB/BGR) and line stride - + dcraw_make_mem_image() uses calls mentioned above - + see documentation for info on these function parameters. - - * libraw/librawwindows.h implements LibRaw_datastream class based - on Windows memory mapped files.Win32/64-only - Thanks to Linc Brookes. - - * Fixed parallel make errors in configure/Makefile.am - - * LibRaw 0.13.6-Release - - -2011-05-18 Alex Tutubalin - * Imported new dcraw 9.08/1.443: - + New color data for Canon 600D and 1100D, Fuji S200EXR - + New camera supported: Fuji HS20EXR and F550EXR, Kodak Z990, - Nikon D5100, Olympus E-PL1s and XZ-1, - Samsung NX11, Sony A230 and 290. - * LibRaw 0.13.5-Release - -2011-04-02 Alex Tutubalin - * Imported new dcraw 9.07/1.442: - + Support for Canon 600D and 1100D, Hasselblad H4D-60, - Olympus E-PL2 - * Color data for Leaf Aptus II and Canon Powershot S2 IS - * LibRaw 0.13.4-Release - -2011-03-30 Alex Tutubalin - * Preliminary support for Leaf Aptus II cameras (no color data yet): - Leaf Aptus II 6,7,8,10 and 12 are tested, Aptus II 5 should work. - * Preliminary support for Fujifilm X100 camera (again, no color data). - * Fixed possible after the end of buffer read when working with - in-memory data. - * Fixed possible loss of JPEG stream sync marks in LJPEG decoder - (this bug was found only for Leaf Aptus II RAWs). - * LibRaw 0.13.3-Release - -2011-03-08 Alex Tutubalin - * Fixed broken camera white balance reading for some Sony cameras - * LibRaw 0.13.2-Release - -2011-02-25 Alex Tutubalin - * Sony A390 support (colordata from A380) - * Leica D-LUX 4: fixed typo in camera name in colordata - -2011-02-15 Alex Tutubalin - * New -mem option for dcraw_emu: I/O via allocated buffer - * Removed debug printf from LibRaw_memory_buffer code - * Preliminary shared library support - -2011-02-12 Alex Tutubalin - * Added qmake .pro and Visual Studio 2008 sln/vcproj project files -2011-02-07 Alex Tutubalin - * dcraw_emu documentation updated - * ./configure stuff changed for correct linking on some systems - * FBDD denoising is disabled for full-color images and 4-color bayer - data (including forced 4-color via four_color_rgb option) - * LibRaw 0.13.1-Release - -2011-02-05 Alex Tutubalin - * ./configure fixes for PACKAGE_REQUIRES - * Makefile.msvc: correct compiler flags for demosaic packs - * dcraw.c 9.06/1.440 imported: - + New camera support: Canon S95, Casio EX-Z1080, Panasonic GF2 - and GH2, Samsung NX100, Sony A-580 - + New color data for: Canon G12, Nikon D3100, D7000 and P7000, - Olympus E-5, Pentax K-r and K-5, Samsung NX10 and WB2000 - * green_matching() code is disabled for half-size processing - * LibRaw 0.13.0-Release - -2011-01-15 Alex Tutubalin - * Fallback to old huffman decoder for Sony files with unspecified - data length (Sony A100) - * Fixed incomplete data fields reset in LibRaw::recycle() - * LibRaw 0.13.0-Beta3 - -2011-01-13 Alex Tutubalin - * Better parsing of unknown command-line params in dcraw_emu sample - * Brigtness table in ahd_demosaic is calculated in reversed order - to prevent possible (very unlikely) multithreaded app problem. - * New exposure correction code based on linear-cubic root combination. - New working correction range is from 0.25 (-2 stops) to 8 (+3 stops) - * LibRaw 0.13.0-Beta2 - -2011-01-10 Alex Tutubalin - * Fixed file extension in half_mt.c sample - -2011-01-10 Alex Tutubalin - * Three patches provided by Jacques Desmis: - - Exposure correction before demosaic (demosaic pack GPL3) - - OpenMP speed-up in median filters (demosaic pack GPL2) - - OpenMP speed-up in green equilibration (demosaic pack GPL3) - * Merged 0.12.2-0.12.3 changes: - - Patches for ./configure system for better LCMS2 support - - Patches for ./configure system - - math.h included before any other includes to make KDE compile - with Visual C++ happy - - Fuji FinePix S5500 size adjusted to ignore (rare?) garbage - at top of frame. - * all client code should be recompiled due to internals change. - * LibRaw 0.13.0-Beta1 - -2010-12-22 Alex Tutubalin - * Zero copy huffman buffer for LibRaw_buffer_datastream - * Fixed memory leak in compressed NEFs handling - * LibRaw 0.13.0-Alpha2 - -2010-12-20 Alex Tutubalin - * Demosaic-pack-GPL3 changes: - + New noise reduction methods before demosaic - - Banding suppression - - High-frequency noise suppression - - Green channel equalization - + New chromatic abberration correction. - All three methods are written by Emil Martinec for Raw Therapee. - Adapted to LibRaw by Jacques Desmis - - * Merged Foveon code fix from LibRaw 0.12.1 - - * LJPEG decompressor speed-up (about 1.5 times for Canon cameras - and slightly less for others). Some ideas are from RawSpeed library. - - * all client code should be recompiled due to internals change. - - * LibRaw 0.13.0-Alpha1 - -2010-12-12 Alex Tutubalin - * Thread-safe and demosaic packs support for MinGW build - * Demosaic packs support for MS VC build - * LibRaw 0.12.0-Release - -2010-12-09 Alex Tutubalin - * Fixed bug in add_masked_borders_to_bitmap() call for cameras - with odd pixels border. - * New command line options for unprocessed_raw sample: - -B - subtract black level, -M - add masked pixels to bitmap. - * Foveon-sensor cameras added to supported camera list if - compiled with demosaic pack GPL2 - * LibRaw 0.12.0-Beta4 - -2010-12-05 Alex Tutubalin - * Demosaic packs support in Makefile.dist - * Foveon support in LibRaw demosaic pack GPL2 - * all client code should be recompiled due to internals change. - * LibRaw 0.12.0-Beta3 - -2010-11-27 Alex Tutubalin - * Fixed allocation bug in lmmse_interpolation (demosaic-pack-GPL2) - * In LMMSE and AMaZE interpolators allocation changed to calloc - to make valgrind happy with uninitialized values - * Changes in distribution-making scripts - * LibRaw 0.12.0-Beta2 - -2010-11-21 Alex Tutubalin - * Fixes to green_matching code by Sergey Pavlov - -2010-11-20 Alex Tutubalin - * Update for new demosaic-pack-GPL3 - * LibRaw 0.12.0-Beta1 - -2010-11-19 Alex Tutubalin - * Demosaic pack(s) supported via ./configure - -2010-11-17 Alex Tutubalin - * LCMS2 support - * afd_interpolate(2,1) instead of (5,0) - * dcraw_emu sample command line keys added and reordered - to reflect changes in LibRaw 0.12. - * Nikon P7000: color matrix data and black level patch for ISO >=400 - Thanks to Gunnar Thorburn - * Support for several industrial cameras based on Sony ICX 625/655 - sensor: JAI BB500CL/GE, SVS625CL, ptGrey GRAS-50S5C - Thanks to kaare - -2010-11-15 Alex Tutubalin - - * Several demosaic algorithms, found in other open-source RAW processing - packages are implemented in LibRaw. - - 1) DCB demosaic and FBDD denoise by Jacek Gozdz are included in - main LibRaw source. - 2) GPL2 demosaic pack with these demosaic methods: - * AFD and LMMSE implementations from PerfectRaw by Manuel Llorens - * VCD, Modified AHD, post-demosaic refinemend and median - filters by Paul Lee - 3) GPL3 demosaic pack with AMaZe interpolation by Emil Martinec - - See more details in README.demosaic-packs - - * Current implementation of dcraw_emu sample allows only selection - of demosaic method (via -q) options. All other parameters change - will be implemented later. - - * LibRaw 0.12-alpha1 - -2010-11-11 Alex Tutubalin - * Imported 0.11(2) version changes: - + Fixed dcraw_emu command line processing code - + OpenMP is completely disabled on MacOS X if compiled with -pthread - due to well-known MacOS problem. - + dcraw 9.05 (1.439) imported, many new cameras supported: - Canon: G12, SX120, 60D, - Hasselblad H4D, Nokia X2, Olympus E-5, - Nikon: D3100, D7000, P7000, - Panasonic: FZ40, FZ100, LX5, - Pentax: K-r, K-5, 645D, - Samsung GX20, WB2000 - * LibRaw 0.12-alpha0 - -2010-11-08 Alex Tutubalin - * Fixes for Sun Studio compiler compatibility - * Fixes for Visual Studio 2010 compatibility - * All russian-language files are converted to UTF-8 - * LibRaw 0.11.0-Release - -2010-10-18 Alex Tutubalin - * Disabled OpenMP for wavelet_denoise under Mac OS X - * More Visual C++ 2003 warnings cleaned in libraw/*h files - * LibRaw 0.11-Beta7 - -2010-10-16 Alex Tutubalin - * internal/dcraw_fileio.c can be compiled with -DDCRAW_VERBOSE again - * fixed comment style in libraw_datastream.h - * LibRaw 0.11-Beta6 - -2010-10-15 Alex Tutubalin - - * New changes to I/O layer. Three LibRaw_*datastream clasees are - exists: - + LibRaw_buffer_datastream - buffer reaging - + LibRaw_file_datastream - file reading using iostreams - (large files are no supported on some systems) - + LibRaw_bigfile_datastream - FILE*-based file I/O - - * file/bigfile_datastream is selected automatically by - LibRaw::open_file based on input file size. - By default, files larger than 250Mb are opened using - bigfile interface, you may change this behaviour - by using second optional parameter of open_file() - - * There is no way to use default parameter values in C API, - so new call libraw_open_file_ex added with two parameters - (file name and minimal file size for bigfile_datastream use). - - * all client code should be recompiled due to internals change. - - * All LibRaw_abstract_datastream functions are virtual again. You may - (again) use your own I/O layer. - - * new -d key for dcraw_emu sample: print timings of processing stages - - * simple_dcraw sample simplified: no mmap code - - * LibRaw 0.11-Beta5 - -2010-10-08 Alex Tutubalin - * Fixed bug in exception handling in OpenMP sections in - AHD interpolation code. - - * LibRaw_datastreams are now C++ iostreams based instead of old - plain FILE* calls. - LibRaw::open_file() in multithreaded programs are WAY faster - on many OSes (Linux, Windows, MacOSX) because of no extra locks. - - * all client code should be recompiled due to internals change. - - * LibRaw 0.11-Beta4 - - -2010-10-01 Alex Tutubalin - * Fixed bug in LibRaw::dcraw_process() code: for half_size - processing, params.four_color_rgb was set to 1 internally - and not returned back after postprocessing. - - * Several Visual Studio 2003 compatibility fixes - - * AHD interpolation refactored. Now it is about 10% faster than - dcraw in single-process mode and up to 1.5 times faster on - 4-core and OpenMP (total execution time counted, not AHD itself) - Thanks to Adam Hooper - * AHD interpolation refactored. Now it is about 10% faster than - dcraw in single-process mode and up to 1.5 times faster on - 4-core and OpenMP (total execution time counted, not AHD itself) - Thanks to Adam Hooper - - * LibRaw 0.11-Beta3 - -2010-09-07 Alex Tutubalin - * Phase One files: LibRaw::unpack() sets colordata.black to - approximately correct value. - - * Fixed minor error in setting colordata.maximum value - for Phase One files. - - * LibRaw::subtract_black() sets colordata.black and - colordata.cblack[] to zero to preserve data integrity. - - * LibRaw 0.11-Beta2 - - -2010-09-04 Alex Tutubalin - - * It is now possible to crop output image on postprocessing - stage (dcraw_process). Coordinates and size of the output box - are set via imgdata.params.cropbox[4] parameter. Look into - LibRaw documentation for more details. - - + New fatal error code LIBRAW_BAD_CROP - - + New dcraw_emu sample command line switch: -B x y w h - (sets cropbox) - - Thanks to Patrick and Jan. - - * Processing pipeline has changed: the black level is subtracted - from data on postprocessing stage either automatically - (on dcraw_process() stage) or by special LibRaw API call: - - + New API calls: LibRaw::subtract_black() (C++ API) and - libraw_subtract_black (C API). - If you use dcraw_process() or dcraw_document_mode_processing() - calls YOU DON'T NEED to call subtract_black() directly. - - + The raw preprocessing mode LIBRAW_FILTERING_NOBLACKS - is deprecated and removed from LibRaw. - - * New ./configure script. - Use ./configure -h for usage details. - Thanks to Siddhesh Poyarekar - - * New API cals static LibRaw::dcraw_clear_mem() (C++ API) - and libraw_dcraw_clear_mem(..) (C API). - This calls are used to free memory, allocated by - dcraw_make_mem_image() and dcraw_make_mem_thumb() instead - of free() call. - - In some cases LibRaw and calling process have different - memory managers, so free() of make_mem_image() data - results to program crash (especially in Win32/VisualStudio - enviroment). - - * LibRaw::free() is now private instead of public (again). - - * Minor changes and bugfixes: - - + Memory allocation exceptions (std::bad_alloc) are caught, - so LibRaw API calls will return reasonable error codes - instead of C++ exception (possibly unhandled). - This problem is very unlikely to see in wild: if application - cannot allocate small data for internal structure, it will - always fail on allocation for RAW image data. - - + WIN32/VisualStudio 2008/2010: fopen,fscanf and sscanf calls - in Libraw_datastream code are changed to *_s (secure) ones. - - + Debug print removed from fatal error handler. - - + Mmaped I/O for dcraw_emu sample is turned on via -E switch - now (because old -B switch is used for settng cropbox). - - * all client code should be recompiled due to structures size change - - * LibRaw 0.11-Beta1 - - -2010-07-31 Alex Tutubalin - * dcraw 9.04 (1.438) imported: changes in tiff metadata parser, - fixed a typo in Canon A720 model name - * small patch in Sony ARW2 unpacking code to make valgrind happy - * LibRaw 0.10.0-Beta3. - -2010-07-05 Alex Tutubalin - * dcraw 9.03 (1.437) imported: - + New cameras: Canon SX20, Nikon D3s, Olympus E-P2, Panasoni DMC-GF1, - Samsung EX1, Sony A450 - + Color data changed for some cameras - - * LibRaw 0.10.0-Beta2. - -2010-06-06 Alex Tutubalin - * dcraw 9.01 (1.434) imported: - + Separate black levels for each color channel. - + New cameras: Canon 550D, Casio EX-Z1050, Fuji HS10/HS11, - Kodak Z981, Panasonic G2 and G10, Phase One P65, - Samsung NX-10 and WB550, Sony NEX-3 and NEX-5. - + Fixed file descriptor leak in dark frame subtraction processing - - * Fixed dcraw 9.01's bug in DNG black level processing - - * Preliminary support for Sony A450 camera. - - * New command-line switch -h in mem_image sample (half_size support) - - * Some patches by Johannes Hanika (darktable author): - + OpenMP speedup for PPG-interpolation - + green_matching - suppress of 'color maze' on cameras with - different green channel sensitivity. This option is turns on - by filed with same name in imgdata.params - - * all client code should be recompiled due to structures size - change - - * LibRaw::free() is now public instead of private. - - * LibRaw 0.10.0-Beta1. - -2010-05-15 Alex Tutubalin - * Fixed bug in 8-bit RAW processing code - * LibRaw 0.9.1-Release - -2010-04-26 Alex Tutubalin - * OpenMP support: OpenMP is possible under MinGW (untested) - * LibRaw 0.9.0-Release - -2010-04-21 Alex Tutubalin - * Finally fixed inconsistency in Fuji files processing - * New COLOR(row,col) call to get bayer color index in image[] array - * Old FC() call is deprecated and will be removed in future releases - * unprocessed_raw sample switched to COLOR() call - * LibRaw 0.9.0-Beta5 - - -2010-04-10 Alex Tutubalin - * Fixed bug in unpacking DNG files made from Fuji RAFs. - * LibRaw 0.9.0-Beta4 - -2010-04-09 Alex Tutubalin - - * Fixed typecast error (problem reported only on gcc 4.2.1/32bit) - in CRW files processing. - - * C++ API call LibRaw::adjust_maximum() is now deprecated and - de-documented, use params.adjust_maximum_thr instead (on by default) - - * C-API call libraw_adjust_maximum() removed. - - * New postprocessing parameter params.adjust_maximum_thr - This parameter replaces LibRaw::adjust_maximum(), but more flexible - Defaults are reasonable (0.75, same as in old adjust_maximum), - look into documentation for more details. - - * Removed last OpenMP warning - - * dcraw_emu's -c parameter now wants numeric (float) argument. This value - is assigned to params.adjust_maximum_thr. - Use -c 0.0 for dcraw compatibility. - - * all client code should be recompiled due to structures size - change - - * LibRaw 0.9.0-Beta3 - - -2010-03-29 Alex Tutubalin - * Fixed a bug in channel_maximum[] calculation for - Panasonic cameras. - * channel_maximum[] data now calculated for ALL cameras. - * OpenMP warnings suppressed. - * Documented the -c command-line switch for dcraw_emu sample. - * Removed extra messages from dcraw_emu sample. - * LibRaw 0.9.0-Beta2 - -2010-03-28 Alex Tutubalin - - New licensing: - - * Triple licensing (selected by LibRaw user): - - + LGPL 2.1 (http://www.gnu.org/licenses/lgpl-2.1.html) - + CDDL 1.0 (http://www.opensource.org/licenses/cddl1.txt) - + LibRaw Software License (27 March 2010 version) - (http://www.libraw.org/data/LICENSE.LibRaw.pdf) - - * There is no separate LibRaw-Lite and LibRaw-Commercial versions, - only single LibRaw. - Current LibRaw-Lite and LibRaw-Commercial users should switch - to LibRaw without loss of functionality. - It is possible to change licensig too (e.g. from LGPL to CDDL - for LibRaw-Lite users and from LibRaw License to LGPL or CDDL - for LibRaw-Commercial users). - - * No Foveon support :( - It is not possible to get good color from Foveon sensors with - *any* converter. So, there is no need to support these cameras. - Dcraw's Foveon-processing code is too strict licensed (GPL), - so we choose to drop it. - - New Features: - - * New data field colordata.channel_maximum[4] - per channel data - maximum (calculated for most cameras, 0 for others). - - * New call LibRaw::adjust_maximum() (and libraw_adjust_maximum() in C API). - This call changes hardcoded colordata.maximum value to calculated - at unpack stage. This helps suppress false color in highlights - (magenta clouds and so). - - * New command line parameter -c for dcraw_emu sample. Calls adjust_maximum() - for each processed file. - - * all client code should be recompiled due to structures size - change - - * LibRaw 0.9.0-Beta1 - -2010-02-06 Alex Tutubalin - * Fixed ambiguity in pow/sqrt calls (to make Sun C++ compiler happy) - * OpenMP is not supported under MS Visual Studio - * Masked a bug in RIFF format parser - * LibRaw 0.8.6 - -2009-12-30 Alex Tutubalin - * Fixed bug in simple_dcraw sample parameters processing - * Imported dcraw 8.99 (1.432): - + New cameras: Canon: 1D mk IV, Canon S90; Casio Z750, - Nikon D3S, Pentax K-x, Sony A-500/550, Fuji S200EXR - + New color data for Canon G11 and Sony A850 - + Changes in Canon sRAW processing - + Changes in Kodak metadata processing - + Changes in uncompressed Fuji files processing (FinePix S5xxx) - * LibRaw 0.8.5 - -2009-11-21 Alex Tutubalin - + Fixed a bug in processing of uncompressed Phase One files - * LibRaw 0.8.4 - -2009-10-24 Alex Tutubalin - + Imported dcraw 8.98/1.431: - * New Cameras: Canon 7D, Panasonic GF1, Sony A850 and A380, - Casio Z850, Nikon D300s - + changes in libraw_datastream.h to make compilers more happy - * LibRaw 0.8.3 - -2009-09-02 Alex Tutubalin - + Fixed bug in Hasselblad .3FR unpacking code - * Imported dcraw 8.97/1.428: Nikon D3000 image width fix - * LibRaw 0.8.2 - -2009-08-31 Alex Tutubalin - + Enum LibRaw_thumbnail_formats (LIBRAW_IMAGE_*) values changed to - match values in enum LibRaw_image_formats (LIBRAW_THUMBNAIL_*). - You need to recompile all sources using these constants. - -2009-08-30 Alex Tutubalin - * Imported dcraw 8.97/1.427: - + new cameras: Canon A470, Canon G11 (without color data), - Nikon D3000, Olympus E-P1, Panasonic DMC-FZ35/FZ38 - + some changes in decoding code. - * Fixes for Microsoft Visual C++ 6.0 compatibility - * C-API dcraw_make_mem_thumb() call finally exported in API - * LibRaw 0.8.1 - -2009-08-24 Alex Tutubalin - * Imported dcraw 8.96/1.426 - + New cameras: Casio EX-Z60 and EX-Z75, Kodak Z980, - Nikon D5000, Olympus X200, D560Z,C350Z,E620, - Pentax K7, Sony A330. - + New color data for many cameras - + Generalized unpacker code for Canon and Casio P&S cameras - * LibRaw 0.8.0-Release - -2009-08-13 Alex Tutubalin - * RAW files larger than 2Gb are supported on: - - Unix (all supported: FreeBSD, MacOS X, Linux) - - Windows (with C runtime version >= 8.0) - * bzero replaced with memset to make Solaris users happy - * All applications on 32-bit systems should be recompiled - due to data structures size changes. - * Minor fixes in windows makefile - * LibRaw 0.8.0-Beta5 - -2009-07-21 Alex Tutubalin - * Imported dcraw 8.95 (1.425): - + new huffman tree code - + New cameras supported: AGFAPHOTO DC-833m, Casio EX-S20, - Phase One P65, Samsung S850 - + Removed hardcoded white-balance data for many P&S cameras. - It is recommended to set params.use_camera_wb to 1 for - safe WB. - * Fixes for Nikon D5000 files: no pink stripe at - right side of frame - * C-wrapper: added missed calls - libraw_dcraw_make_mem_image - libraw_dcraw_ make_mem_thumb - * Minor fixes to make non-gcc compilers more happy - * Internal structures changed, full recompilation of all client - code is needed. - * LibRaw 0.8.0-Beta4 - -2009-06-08 Alex Tutubalin - * Fixes: gamma curve processing was not performed in - dcraw_write_mem_image() - * Fixes: gamma curve processing was not performed for - Kodak thumbnails - * LibRaw 0.8.0-Beta3 - -2009-06-05 Alex Tutubalin - * Fixes in documentation: params.gamm[] described more precisely - * Fixes in version number, 0.8-beta1 was mistakenly 0.0.0-beta1 - * LibRaw 0.8.0-Beta2 - -2009-06-04 Alex Tutubalin - * Imported dcraw 8.94 (1.423): - + New camera support: - Canon: SX1, 500D/Rebel T1i, A570, A590, SX110 - Kodak Z1015, Motorola PIXL, Olympus E30, Panasonic DMC-GH1 - + Improved color data for Nikon D3X - + New gamma curve model - + Many changes in RAW unpacking code - + Canon cameras: black level is not subtracted if set - params.document_mode > 1 - - * API changed: params.gamma_16bit field removed. Gamma curve is - set via params.gamm[0]/gamm[1] values (see documentation and - samples for details) - * LibRaw::identify() splitted to avoid MS VS2008 bug (too many - nested blocks) - - * Samples: dcraw_emu and mem_image samples supports new dcraw - 16bit/gamma semantics: - -6: set 16 bit output - -4: set 16 bit output and linear gamma curve and no auto - brighness - * LibRaw 0.8.0-Beta1 - -2009-04-28 Alex Tutubalin - * Identify sample renamed to raw-identify (name conflict - with ImageMagic) - * Copyright notice changes - * Many compiler warnings removed - -2009-04-07 Alex Tutubalin - * More accurate types conversion in libraw_datastream.h - * New postprocessing parameter auto_bright_thr: set portion of - clipped pixels for auto brightening code (instead of - dcraw-derived hardcoded 1%) - * -U option for dcraw_emu sample sets auto_bright_thr parameter - * all client code should be recompiled due to structures size - change - * LibRaw 0.7.2-Release - -2009-03-22 Alex Tutubalin - * Fixed typo in OpenMP support code - * MinGW support - * dcraw source is included in distribution - * LibRaw 0.7.1-Release - -2009-03-15 Alex Tutubalin - * Fuji SuperCCD RAWs: color channels unshuffled on RAW - read stage (moved from postprocessing stage) - - * LibRaw 0.7.0-Release - -2009-03-13 Alex Tutubalin - * dcraw 8.93/1.421 imported: - + more accurate pentax dSLR support - + fixes in Kodak 620x/720x identification - + faster identification procedure for some formats. - * LibRaw 0.7.0-Beta5 - - -2009-03-08 Alex Tutubalin - * dcraw 8.92/1.420 imported: - + user-specified gamma curve - + Pentax K2000/Km support - + Changes in Canon sRAW processing (support for 5D2 fw 1.07) - - * all client code should be recompiled - - * LibRaw 0.7.0-Beta4 - -2009-02-13 Alex Tutubalin - * bugfix: 4channels sample finally subtracts black by default - * dcraw 8.91/1.419 imported: - + fixes in RIFF files parsing - - * LibRaw 0.7.0-Beta3 - -2009-02-12 Alex Tutubalin - * Black level was not calculated for Canon RAWs in - some filtering modes - - * 4channels sample prints calculated black level - (scaled if autoscaling used). - Also output file names for this sample now includes - color channel name (R/G/B/G2 or C/M/Y/G) - - * LibRaw 0.7.0-Beta2 - -2009-02-09 Alex Tutubalin - * New sample 4channels: splits RAW color channels into four - separate TIFFs - - * LibRaw 0.7.0-Beta1 - -2009-02-07 Alex Tutubalin - * Fixed bug in external jpeg metadata reading code. - - * Cleaned some C++ warnings - - * dcraw 8.91/1.418 imported - + Hasselblad V96C support - - * You need to clean and recompile client code which - uses LibRaw_*_datastream classes. - - * LibRaw 0.7.0-Alpha6 - -2009-01-30 Alex Tutubalin - - * New data input framework is created. It is possible now to - easyly implement your own data input interface for LibRaw - (e.g. for reading RAW data from network data stream) - - * All older programs using previous LibRaw versions are - compatible at source code level. - - * LibRaw can read RAW data from memory buffer via - new LibRaw::open_buffer() API call (implemented on top of - new input framework). - This call used in sample application dcraw_emu and simple_dcraw - (with -B command-line switch) to test new API. - - * Error handling callback functions now can be called with - NULL filename passed (if underlying data stream object - does not know file name). - So, client error handling callbacks should work with NULL - filename. - - * All client code should be recompiled - - * Imported dcraw 8.90/1.417: - + Support for loading White Balance data from - Sony ARW files edited with Sony IDC software. - - * LibRaw 0.7.0-Alpha5 - -2009-01-17 Alex Tutubalin - * Raw filtering mode LIBRAW_FILTERING_NOPOSTPROCESS has renamed - to LIBRAW_FILTERING_NORAWCURVE for better reflect its purpose. - This filtering_mode bit turns off tone curve applying on - RAW data on bayer-pattern cameras with raw tone curve: - + Adobe DNG (only RAW with bayer pattern) - + Nikon compressed NEF - + Some Kodak cameras - + Sony A700/A900 (tone curve applied to 8-bit raws) - - * unprocessed_raw sample: added command-line key -N, this key - turns on LIBRAW_FILTERING_NORAWCURVE filtering mode. - - * New scheme of Fuji RAW processing (introduced in 0.7-Alpha3) - supports DNG files generated from Fuji RAF. - - * Imported dcraw 8.90/1.416: - + better support for Samsung S85 - + fixed possible integer overflow in wavelet denoising code - - * LibRaw 0.7.0-Alpha4 - - -2009-01-14 Alex Tutubalin - * Black mask extraction supported for all files with bayer data - (one component per pixel). Black mask data not avaliable - for multi-component data (Foveon, Canon sRAW, Sinar 4-shot, - Kodak YCC/YRGB). - - * Black level subtraction can be turned off for all bayer - cameras (added support for PhaseOne backs). - - * Fujifilm camera processing model changed: - + RAW data is extracted without 45-degree rotation - + dcraw-compatible rotation is performed on postptocessing stage - + it is possible to rotate RAW data without postprocessing - by LibRaw::rotate_fuji_raw() call. - - * New filtering mode setting: LIBRAW_FILTERING_NOPOSTPROCESS - This bits turns off RAW tone curve processing based on tone curve - readed from RAW metadata. - This mode supported only for PhaseOne backs now (to be supported - on all relevant cameras in nearest future releases) - - * Black level data (got from RAW data) are stored for PhaseOne backs. - - * Black level subtraction bug (derived from dcraw) fixed - for PhaseOne files. - - * Fixed processing of -s parameter for dcraw_emu sample - - * Parameter -s N (select shot number) added to - unprocessed_raw sample. - - * Imported dcraw 8.90/1.414: - + changes in QuickTake 100 metadata processing - + changes in external jpeg processing code - + Samsung S85 support - - * All client code should be recompiled - - * LibRaw 0.7.0-Alpha3 released - -2009-01-10 Alex Tutubalin - * Fixed bug in add_masked_borders: crash if output dimensions - is already larger than raw dimensions - * Fixed out of bounds in samples/unprocessed_raw.cpp for files - with non-square pixels - - * LibRaw 0.7.0-Alpha2 released - -2009-01-08 Alex Tutubalin - * Fixed bug in 0.7.0-a0: black frame size has not reset, - so in batch processing there is an error in black frame - size for files without black frame. - - * Implemented reading of black/masked pixels data for - near all cameras with masked pixels, exclding: - + Canon sRAW, Leaf (MOS), Sinar 4-shot - more than one - color component in black frame (redesign of black frame - data structures required). - + Fuji SuperCCD: need to design right methods of extraction - (should we rotate and resize black pixels as active ones??) - - * Tested for most dSLR data formats with masked pixels: 7 of 9 - untested formats are from old P&S cameras. - - * New call LibRaw::unpack_function_name() returns unpack function name - (useful for testers only) - - * New identify sample parameters (useful for test-suite builders - to check test coverage): - -u - print unpack function name - -f - print masked frame size - These parameters works only for identify run without -v parameter - - * Imported dcraw 8.89/1.411 - + changes in Panasonic FZ50 files parsing - - * LibRaw 0.7.0-Alpha1 released - - -2009-01-05 Alex Tutubalin - * It is possible to turn off RAW data filtration (black level - subtraction, zero pixels averaging): - + supported on all cameras except Foveon and Phase One - + filtraction controlled by new parameter "filtering_mode" - + it is possible to expand API by filtering procedures - built for specific camera model. - - * Black border (masked pixels) extraction: - + API (data structures) for storing black mask. - + Black mask extraction supported only for limited list of - data formats: - - Canon .CRW, .CR2 (with exception of sRAW),A600, A5 - - Adobe DNG (both converted RAW and native DNG) - - Nikon NEF (compressed only) - this list to be expanded in future LibRaw versions - * New call add_masked_borders_to_bitmap makes full bitmap - 'masked border' + image - * Usage sample for functionality listed above: - samples/unprocessed_raw - * Imported dcraw 8.89/1.410: - + fixed bugs in Hasselblad .fff decoding - + fixes in Imacon metadata decoding - * Documentation changes - * All client code should be recompiled - * LibRaw 0.7.0-Alpha0 - - -2009-01-01 Alex Tutubalin - * Fixed a bug (filedescriptor and buffer memory leak) in thumbnail - extraction when called before metadata analysis. - Thanks to Albert Astalis Cid. - * LibRaw 0.6.4 Release - -2008-12-11 Alex Tutubalin - * Imported new edition of dcraw 8.89 (version 1.409) - * Nikon NEF decoding changed - * LibRaw 0.6.3 Release - -2008-12-03 Alex Tutubalin - * fixed bug in Panasonic .RW2 processing (only for thread-safe version, - single-threaded version was not affected) - * All client code should be recompiled - * LibRaw 0.6.2 Release - -2008-12-03 Alex Tutubalin - * Imported dcraw 8.89 (version 1.407) - * New cameras: - Canon G10 & 5D Mk2, Leaf AFi 7, Leica D-LUX4, Panasonic FX150 & G1, - Fujifilm IS Pro, - * Changed camera support (color conversion tables): - Canon 50D, Nikon D90 & P6000, Panasonic LX3 & FZ28, Sony A900 - * LibRaw 0.6.2 beta - -2008-09-25 Alex Tutubalin - * Added new data field float LibRaw::imgdata.color.cam_xyz[4][3]. - This field contains constant table (different for each camera) for - Camera RGB->XYZ conversion. - * All client code should be recompiled - * LibRaw 0.6.1 Release - -2008-09-18 Alex Tutubalin - * dcraw 8.88 imported: - - new cameras (Canon 50D, Sony A900, Nikon D90 & P6000, - Panasonic LX3 FZ28) - - new method of black point subtraction for Canon cameras, - preliminary banding supression. - * Stack memory usage lowered (some thread data moved to dynamic - memory) - * some patches for MSVC compatibility - * LibRaw 0.6.0 Release - -2008-09-16 Alex Tutubalin - * Enum definitions changed to make gcc -pedantic happy - * Compiler/preprocessor flags does not affects LibRaw class field set - (i.e. structure for thread local storage is always allocated) - * Default library compilation mode (i.e. sources imported in another - project) is thread-safe - -2008-09-14 Alex Tutubalin - * OpenMP support for most CPU consuming steps of processing: - ahd_interpolation. wavelet_denoise - 10-30% speed-up of full processing pipe on 2-core CPU - OpenMP supported only on gcc (Linux/FreeBSD and Mac OS X) - - * LibRaw 0.6.0-Beta-1 - -2008-09-10 Alex Tutubalin - * All set_**handler accepts additional void* pointer, which should point to - callback private data. This pointer passed to user callback when it called. - - * LibRaw 0.6.0-alpha5 - - * All client code should be recompiled - -2008-09-10 Alex Tutubalin - * New processing stages in enum LibRaw_progress: - LIBRAW_PROGRESS_BAD_PIXELS LIBRAW_PROGRESS_DARK_FRAME - (reserved stages LIBRAW_PROGRESS_RESERVED_PRE1-PRE2 has removed) - * libraw_strprogress() - convert progress code into string - - * Added progress/cancellation user callbacks - + new fatal error code: CANCELLED_BY_CALLBACK - + sample usage in samples/dcraw_emu.cpp (try run it with -v -v -v opts) - - * LibRaw 0.6.0-alpha4 - - * All client code should be recompiled - -2008-09-08 Alex Tutubalin - * ICC-profiles support (same as in dcraw) - + input/output profiles (specified as path to 'icc' file or 'embed' for - embedded input profile) - + additional warnings - + LCMS library used - - * support of bad pixel map (caller should specify path to bad pixel file - in dcraw-compatible format) - - * dark frame subtraction support (caller should supply path to 16-bit PGM - map). samples/simple_dcraw.cpp - -4 option added for dark frame file - generation - - * support of bad pixeld map (dcraw-compatible format) - - * the dcraw_emu sample supports all new features (ICC, dark frame, bad - pixels) - - * libraw/libraw_version.h, defines, calls and macros for version checks: - + LibRaw::version(), LibRaw::versionNumber(), LIBRAW_CHECK_VERSION() - - * List of supported cameras: - + LibRaw::cameraCount() - + LibRaw::cameraList() - - * fixed error in adjust_sizes_info_only - - * documentation changes - - * LibRaw 0.6.0-alpha3 - -2008-09-07 Alex Tutubalin - * samples/mem_image.c - bitwise equal output with dcraw -4 - (PPMs outputted with network byte order) - * LibRaw 0.6.0-alpha2 - -2008-09-06 Alex Tutubalin - * Added calls dcraw_make_mem_image and dcraw_make_mem_image: - + functions (and supporting code) - + documentation changed - + new sample code samples/mem_image.cpp - * Added processing parameter LibRaw::imgdata.params.gamma_16bit - (set to 1 to make gamma correction for 16-bit output) - * LibRaw 0.6.0-alpha1 - -2008-08-28 Alex Tutubalin - * dcraw 1.404 (8.87) imported: - - 6 new cameras supported (Canon 1000D, A720, SD300; - Nikon D700, Oly E-520,Kodak C603) - * Licensing changed to GPL v2 - -2008-05-02 Alex Tutubalin - * mmap/malloc+read IO-layer removed due to no performance gain. - FILE I/O returned - -2008-05-02 Alex Tutubalin - * dcraw 1.403 imported - - changes in ljpeg decompression (index values cut to 12 bit) - - changes in parse_foveon() jpeg thumbnail extraction - * LibRaw 0.5.3 released - -2008-04-24 Alex Tutubalin - * Linux build of samples/identify fixed - * documentation editorial - * LibRaw 0.5.2 released - -2008-04-21 Alex Tutubalin - * All documentation translated to English - * English changelog started :) - * minor bug (include path) fixed in samples/half_mt - * LibRaw 0.5.1 released +2012-06-27 Alex Tutubalin + * Imported dcraw 9.15 (1.449): + - New cameras supported: Canon 5D Mark III, G1 X, 1D X and Powershot SX200; + Nikon D4,D800/D800E and D3200; Fuji X-S1 and HS30EXR; Casio EX-Z8; + Olympus E-M5; Panasonic GF5; Sony NEX-F3, SLT-A37 and SLT-A57; + Samsung NX20 and NX210; + - Support for updated Samsung NX200 firmware. + * Makefile.msvc: additional compiler flags + * LibRaw 0.14.7-Release + +2012-04-11 Alex Tutubalin + * Fixed thumbnail processing (esp. for Adobe Lightroom DNGs) + +2012-04-05 Alex Tutubalin + * Casio EX-Z500 support + * (possible) I/O exceptions on file open catched in open_datastream + * Fixed possible read-after-buffer in Sony ARW2 decoder + * Fixed mingw32 errors when compiling LibRaw_windows_datastream + * Makefile.msvc: support of OpenMP and LCMS (uncomment to use) + * Fixed decoding of some Leaf Aptus II files + * LibRaw 0.14.6-Release + +2011-12-24 Alex Tutubalin + * Fixed bug (uninitialized variable) in SMAL format decoding. + + * Imported new dcraw 9.12 (1.446): support for Leica V-LUX 3, + updated color data for Canon S100, Fujifilm X10, Nikon 1 J1/V1, + Panasonic GX1, Samsung NX200, Sony NEX-7 + + * LibRaw 0.14.5-Release + +2011-12-12 Alex Tutubalin + + * Fixes to Panasonic/Leica file parser to prevent crash + on broken jpegs. + + * Fixes to include order in src/libraw_datastream.cpp to + better compile with KDEWIN + + * Floating-point DNGs are rejected on early processing stage. + + * Support for new cameras: Canon S100, Fuji X10, Panasonic GX1, + Samsung NX200, Sony NEX-7. + + * LibRaw 0.14.4-Release + + +2011-10-26 Alex Tutubalin + * Bug fixes in black level subtraction code for PhaseOne files + + * New API call LibRaw::get_internal_data_pointer() for developers + who need access to libraw_internal_data fields (i.e. + Fuji SuperCCD layout). + + * doc/API-overview fixes to reflect 0.14 changes + + * LibRaw 0.14.3-Release + +2011-10-19 Alex Tutubalin + * Fixed bug in Canon 1D and 1Ds files decoding. + * New decoder information bit DECODER_HASRAWCURVE + * LibRaw 0.14.2-Release + +2011-10-11 Alex Tutubalin + * Imported dcraw 9.11/1.445: + + Support for new cameras added: Fujifilm F600EXR, Nikon P7100, + Olympus E-PL3 and E-PM1, Panasonic DMC-FZ150, Sony NEX-5N, + A65 and A77. + + Changed color data for: Olympus E-P3, Panasonic G3 and GF3, + PhaseOne H25, P40 and P65, Sony NEX-C3, NEX-5, NEX-3, A35 and A55. + + Support for dark frame extraction on Sony cameras. + + * DCB demosaicing: reserving 6 pixels instead of 3 to suppress + colored image frame. + * LibRaw 0.14.1-Release + +2011-09-21 Alex Tutubalin + * Cosmetic changes to make Visual C++/OpenMP more happy + * Fix megapixel calculation for postprocessing_benchmark in half mode + * Shlib version number increment + * LibRaw 0.14.0-Release + +2011-09-04 Alex Tutubalin + * Fixed bug with Kodak thumbnail extraction + * raw2image_ex() always return value + * LibRaw 0.14.0-Beta2 + +2011-09-02 Alex Tutubalin + * Cosmetic changes to LibRaw_file_datastream interface + + * OpenMP speedup of postprocessing steps (up to 50% for + half mode and 4-core machine) + + * LibRaw 0.14.0-Beta1 + +2011-08-20 Alex Tutubalin + + * Patch to dcraw_emu for SunStudio compiler compatibility + + * Fixed crash in unprocessed_raw sample due to uninitialized + timestamp variable. + + * Fixed crash in raw decoding if raw_width/raw_height is + less than resulting image width/height. + + * imgdata.sizes.flip is set from user_flip only on + postprocessing and/or adjust_sizes_info_only() + + * Fixed buffer overrun for some LJPEG-compressed files + + * Most of LibRaw_datastream function bodies are moved to + separate source file + + * LibRaw_windows_datastream is merged to main sourcetree + + * LibRaw 0.14.0-Alpha5 + +2011-08-11 Alex Tutubalin + * Imported dcraw 9.10 (1.444), support for new cameras added: + ARRIRAW format, Canon SX30 IS, Leica D-LUX 5 and V-LUX2, + Olympus E-P3, Panasonic G3 and GF3, Sony NEX-C3 and SLT-A35 + + * Support for RedOne digital movie cameras (R3D format). + To enable this support you should: + + install libjasper JPEG2000 support library + + + compile LibRaw with -DUSE_JASPER compiler switch (./configure + will do it for you) + + + If you use own LibRaw_datastream implementation, you should + implement make_jas_stream() call for your datastream. See + bottom of src/libraw_cxx.cpp for implementations in datafile + and mem-buffer LibRaw streams. + + * Bugfix: green matching is turned off if output image is shrinked + due to wavelet filtering or aberration correction. + + * fixed open_file()/adjust_sizes_info_only() code path + + * Removed imgdata.sizes.bottom_margin and right_margin data fields + use imgdata.sizes.raw_width - width - left_margin to get right one, + the same with bottom_margin. + + * minor ./configure cleanup + + * Qmake files and Visual Studio Project files are updated. + + * New version check macros: + For use at runtime checks: + LIBRAW_RUNTIME_CHECK_VERSION_EXACT() - checks that runtime + major/minor version numbers are same with compile-time values. + + LIBRAW_RUNTIME_CHECK_VERSION_NOTLESS() - checks that runtime + version is not less that compile-time one. + + For use at compile-time in preprocessor directives: + LIBRAW_COMPILE_CHECK_VERSION_EXACT(major,minor) - Compile-time + check that LibRaw version is exact major.minor. + + LIBRAW_COMPILE_CHECK_VERSION_NOTLESS(major,minor) - Compile-time + check that version is not less than major.minor. + + * all client code should be recompiled due to internals change. + + * LibRaw 0.14.0-Alpha4 + +2011-07-19 Alex Tutubalin + * New sample samples/postprocessing_benchmark.cpp + This sample measures postprocessing speed. + All demosaic methods, averaged white balance, median + filtering, wavelet filtration, highlight recovery, and + cropping are supported. + + * Removed LibRaw::rotate_fuji_raw() call and corresponding C-API call. + + * The LibRaw::adjust_sizes_info_only() call may be called repeated + and mixed with dcraw_process() call. + + * Postprocessing speedup and optimization, especially if cropping set. + + * Cropping works for FujiCCD raws. For the technical reasons, the position + of top-left corner of crop area will be rounded to the nearest + multiple of 4 (the corner is shifted top-left). + + * LibRaw 0.14.0-Alpha3 + +2011-07-15 Alex Tutubalin + * imported cropping code from 0.13 branch + +2011-07-12 Alex Tutubalin + * samples/multirender_test - check for different clip settings + +2011-07-11 Alex Tutubalin + * New call LibRaw::free_image(), deallocates imgdata.image buffer. + Use this call if current postprocessing results are not + needed, but it is to early to call recycle() because + dcraw_process() may be called later. + + * New C-API calls + libraw_raw2image() - C API for LibRaw::raw2image() + libraw_free_image() - C API for LibRaw::free_image() + libraw_get_decoder_info() - C API for LibRaw::get_decoder_info() + + * Bugfix: change of params.user_flip aftee open()/unpack() + calls should work. + + * LibRaw 0.14.0-Alpha2 + +2011-07-10 Alex Tutubalin + * Multiple rendering (LibRaw::dcraw_process() calls) allowed + without re-opening RAW file thrfough the sequence of open()/unpack() + calls. + You should be able to change any processing parameters (except + shot_select parameter) between dcraw_process() calls. + + + New sample in samples/multirender_test.cpp: renders data 4 times: + in half and full modes with different white balance settings. + + + Unprocessed RAW data is stored in separate data buffer: + (2 bytes per pixel for all Bayer-pattern images, + 8 bytes per pixel for Foveon, sRAW, and other full-color raw + formats), so now LibRaw uses 25% more memory for full processing of + most common Bayer images; while for just unpack memory is reduced + 4 times. + + + New call LibRaw::raw2image() fills imgdata.image array + with fresh copy of data. + There is no need to call raw2image() separately if you use + dcraw_process() or dcraw_document_mode_processing() calls. + + + New call LibRaw::get_decoder_info() to determine raw data + storage layout. See samples/unprocessed_raw.cpp for an example + of how to use it. + + If your code uses usual open()/unpack()/dcraw_process() call + sequence, then NOTHING CHANGED: your program should produce same + results. For interactive programs you may skip open()/unpack() + calls after adjusting processing parameters, so user should see + image refreshed much faster. + + If your code uses raw data (open+unpack calls), you need to call + LibRaw::raw2image(), and imgdata.image will contain same bitmap + as in LibRaw 0.13.x + + If you code uses access to masked borders data, you need to + rewrite it. See samples/unprocessed_raw.cpp as a sample. + + Unfortunately, documentation is untouched yet. This problem will be + fixed in next Alpha release. + + Other changes: + + * No separate imgdata.masked_pixels buffers, Bayer raw formats are read + to buffer with borders. So, no ugly add_masked_border_to_bitmap() + call. + + * No filtering_mode parameter. Raw tone curve is applied + at unpack() stage; zero pixels removed on postprocesing stage. + + * unprocessed_raw and 4colors samples are adjusted to use + new RAW data storage layout. + + * all client code should be recompiled due to internals change. + + * LibRaw 0.14.0-Alpha1 + +2011-07-03 Alex Tutubalin + * Cosmetic cleanup in Libraw_memmgr code + + * Permit OpenMP support on MS VS2008 + + * More general mem_image interface: + + New call get_mem_image_format returns bitmap size and bit depth + + New call copy_mem_image can copy bitmap into buffer with + different color order (RGB/BGR) and line stride + + dcraw_make_mem_image() uses calls mentioned above + + see documentation for info on these function parameters. + + * libraw/librawwindows.h implements LibRaw_datastream class based + on Windows memory mapped files.Win32/64-only + Thanks to Linc Brookes. + + * Fixed parallel make errors in configure/Makefile.am + + * LibRaw 0.13.6-Release + + +2011-05-18 Alex Tutubalin + * Imported new dcraw 9.08/1.443: + + New color data for Canon 600D and 1100D, Fuji S200EXR + + New camera supported: Fuji HS20EXR and F550EXR, Kodak Z990, + Nikon D5100, Olympus E-PL1s and XZ-1, + Samsung NX11, Sony A230 and 290. + * LibRaw 0.13.5-Release + +2011-04-02 Alex Tutubalin + * Imported new dcraw 9.07/1.442: + + Support for Canon 600D and 1100D, Hasselblad H4D-60, + Olympus E-PL2 + * Color data for Leaf Aptus II and Canon Powershot S2 IS + * LibRaw 0.13.4-Release + +2011-03-30 Alex Tutubalin + * Preliminary support for Leaf Aptus II cameras (no color data yet): + Leaf Aptus II 6,7,8,10 and 12 are tested, Aptus II 5 should work. + * Preliminary support for Fujifilm X100 camera (again, no color data). + * Fixed possible after the end of buffer read when working with + in-memory data. + * Fixed possible loss of JPEG stream sync marks in LJPEG decoder + (this bug was found only for Leaf Aptus II RAWs). + * LibRaw 0.13.3-Release + +2011-03-08 Alex Tutubalin + * Fixed broken camera white balance reading for some Sony cameras + * LibRaw 0.13.2-Release + +2011-02-25 Alex Tutubalin + * Sony A390 support (colordata from A380) + * Leica D-LUX 4: fixed typo in camera name in colordata + +2011-02-15 Alex Tutubalin + * New -mem option for dcraw_emu: I/O via allocated buffer + * Removed debug printf from LibRaw_memory_buffer code + * Preliminary shared library support + +2011-02-12 Alex Tutubalin + * Added qmake .pro and Visual Studio 2008 sln/vcproj project files +2011-02-07 Alex Tutubalin + * dcraw_emu documentation updated + * ./configure stuff changed for correct linking on some systems + * FBDD denoising is disabled for full-color images and 4-color bayer + data (including forced 4-color via four_color_rgb option) + * LibRaw 0.13.1-Release + +2011-02-05 Alex Tutubalin + * ./configure fixes for PACKAGE_REQUIRES + * Makefile.msvc: correct compiler flags for demosaic packs + * dcraw.c 9.06/1.440 imported: + + New camera support: Canon S95, Casio EX-Z1080, Panasonic GF2 + and GH2, Samsung NX100, Sony A-580 + + New color data for: Canon G12, Nikon D3100, D7000 and P7000, + Olympus E-5, Pentax K-r and K-5, Samsung NX10 and WB2000 + * green_matching() code is disabled for half-size processing + * LibRaw 0.13.0-Release + +2011-01-15 Alex Tutubalin + * Fallback to old huffman decoder for Sony files with unspecified + data length (Sony A100) + * Fixed incomplete data fields reset in LibRaw::recycle() + * LibRaw 0.13.0-Beta3 + +2011-01-13 Alex Tutubalin + * Better parsing of unknown command-line params in dcraw_emu sample + * Brigtness table in ahd_demosaic is calculated in reversed order + to prevent possible (very unlikely) multithreaded app problem. + * New exposure correction code based on linear-cubic root combination. + New working correction range is from 0.25 (-2 stops) to 8 (+3 stops) + * LibRaw 0.13.0-Beta2 + +2011-01-10 Alex Tutubalin + * Fixed file extension in half_mt.c sample + +2011-01-10 Alex Tutubalin + * Three patches provided by Jacques Desmis: + - Exposure correction before demosaic (demosaic pack GPL3) + - OpenMP speed-up in median filters (demosaic pack GPL2) + - OpenMP speed-up in green equilibration (demosaic pack GPL3) + * Merged 0.12.2-0.12.3 changes: + - Patches for ./configure system for better LCMS2 support + - Patches for ./configure system + - math.h included before any other includes to make KDE compile + with Visual C++ happy + - Fuji FinePix S5500 size adjusted to ignore (rare?) garbage + at top of frame. + * all client code should be recompiled due to internals change. + * LibRaw 0.13.0-Beta1 + +2010-12-22 Alex Tutubalin + * Zero copy huffman buffer for LibRaw_buffer_datastream + * Fixed memory leak in compressed NEFs handling + * LibRaw 0.13.0-Alpha2 + +2010-12-20 Alex Tutubalin + * Demosaic-pack-GPL3 changes: + + New noise reduction methods before demosaic + - Banding suppression + - High-frequency noise suppression + - Green channel equalization + + New chromatic abberration correction. + All three methods are written by Emil Martinec for Raw Therapee. + Adapted to LibRaw by Jacques Desmis + + * Merged Foveon code fix from LibRaw 0.12.1 + + * LJPEG decompressor speed-up (about 1.5 times for Canon cameras + and slightly less for others). Some ideas are from RawSpeed library. + + * all client code should be recompiled due to internals change. + + * LibRaw 0.13.0-Alpha1 + +2010-12-12 Alex Tutubalin + * Thread-safe and demosaic packs support for MinGW build + * Demosaic packs support for MS VC build + * LibRaw 0.12.0-Release + +2010-12-09 Alex Tutubalin + * Fixed bug in add_masked_borders_to_bitmap() call for cameras + with odd pixels border. + * New command line options for unprocessed_raw sample: + -B - subtract black level, -M - add masked pixels to bitmap. + * Foveon-sensor cameras added to supported camera list if + compiled with demosaic pack GPL2 + * LibRaw 0.12.0-Beta4 + +2010-12-05 Alex Tutubalin + * Demosaic packs support in Makefile.dist + * Foveon support in LibRaw demosaic pack GPL2 + * all client code should be recompiled due to internals change. + * LibRaw 0.12.0-Beta3 + +2010-11-27 Alex Tutubalin + * Fixed allocation bug in lmmse_interpolation (demosaic-pack-GPL2) + * In LMMSE and AMaZE interpolators allocation changed to calloc + to make valgrind happy with uninitialized values + * Changes in distribution-making scripts + * LibRaw 0.12.0-Beta2 + +2010-11-21 Alex Tutubalin + * Fixes to green_matching code by Sergey Pavlov + +2010-11-20 Alex Tutubalin + * Update for new demosaic-pack-GPL3 + * LibRaw 0.12.0-Beta1 + +2010-11-19 Alex Tutubalin + * Demosaic pack(s) supported via ./configure + +2010-11-17 Alex Tutubalin + * LCMS2 support + * afd_interpolate(2,1) instead of (5,0) + * dcraw_emu sample command line keys added and reordered + to reflect changes in LibRaw 0.12. + * Nikon P7000: color matrix data and black level patch for ISO >=400 + Thanks to Gunnar Thorburn + * Support for several industrial cameras based on Sony ICX 625/655 + sensor: JAI BB500CL/GE, SVS625CL, ptGrey GRAS-50S5C + Thanks to kaare + +2010-11-15 Alex Tutubalin + + * Several demosaic algorithms, found in other open-source RAW processing + packages are implemented in LibRaw. + + 1) DCB demosaic and FBDD denoise by Jacek Gozdz are included in + main LibRaw source. + 2) GPL2 demosaic pack with these demosaic methods: + * AFD and LMMSE implementations from PerfectRaw by Manuel Llorens + * VCD, Modified AHD, post-demosaic refinemend and median + filters by Paul Lee + 3) GPL3 demosaic pack with AMaZe interpolation by Emil Martinec + + See more details in README.demosaic-packs + + * Current implementation of dcraw_emu sample allows only selection + of demosaic method (via -q) options. All other parameters change + will be implemented later. + + * LibRaw 0.12-alpha1 + +2010-11-11 Alex Tutubalin + * Imported 0.11(2) version changes: + + Fixed dcraw_emu command line processing code + + OpenMP is completely disabled on MacOS X if compiled with -pthread + due to well-known MacOS problem. + + dcraw 9.05 (1.439) imported, many new cameras supported: + Canon: G12, SX120, 60D, + Hasselblad H4D, Nokia X2, Olympus E-5, + Nikon: D3100, D7000, P7000, + Panasonic: FZ40, FZ100, LX5, + Pentax: K-r, K-5, 645D, + Samsung GX20, WB2000 + * LibRaw 0.12-alpha0 + +2010-11-08 Alex Tutubalin + * Fixes for Sun Studio compiler compatibility + * Fixes for Visual Studio 2010 compatibility + * All russian-language files are converted to UTF-8 + * LibRaw 0.11.0-Release + +2010-10-18 Alex Tutubalin + * Disabled OpenMP for wavelet_denoise under Mac OS X + * More Visual C++ 2003 warnings cleaned in libraw/*h files + * LibRaw 0.11-Beta7 + +2010-10-16 Alex Tutubalin + * internal/dcraw_fileio.c can be compiled with -DDCRAW_VERBOSE again + * fixed comment style in libraw_datastream.h + * LibRaw 0.11-Beta6 + +2010-10-15 Alex Tutubalin + + * New changes to I/O layer. Three LibRaw_*datastream clasees are + exists: + + LibRaw_buffer_datastream - buffer reaging + + LibRaw_file_datastream - file reading using iostreams + (large files are no supported on some systems) + + LibRaw_bigfile_datastream - FILE*-based file I/O + + * file/bigfile_datastream is selected automatically by + LibRaw::open_file based on input file size. + By default, files larger than 250Mb are opened using + bigfile interface, you may change this behaviour + by using second optional parameter of open_file() + + * There is no way to use default parameter values in C API, + so new call libraw_open_file_ex added with two parameters + (file name and minimal file size for bigfile_datastream use). + + * all client code should be recompiled due to internals change. + + * All LibRaw_abstract_datastream functions are virtual again. You may + (again) use your own I/O layer. + + * new -d key for dcraw_emu sample: print timings of processing stages + + * simple_dcraw sample simplified: no mmap code + + * LibRaw 0.11-Beta5 + +2010-10-08 Alex Tutubalin + * Fixed bug in exception handling in OpenMP sections in + AHD interpolation code. + + * LibRaw_datastreams are now C++ iostreams based instead of old + plain FILE* calls. + LibRaw::open_file() in multithreaded programs are WAY faster + on many OSes (Linux, Windows, MacOSX) because of no extra locks. + + * all client code should be recompiled due to internals change. + + * LibRaw 0.11-Beta4 + + +2010-10-01 Alex Tutubalin + * Fixed bug in LibRaw::dcraw_process() code: for half_size + processing, params.four_color_rgb was set to 1 internally + and not returned back after postprocessing. + + * Several Visual Studio 2003 compatibility fixes + + * AHD interpolation refactored. Now it is about 10% faster than + dcraw in single-process mode and up to 1.5 times faster on + 4-core and OpenMP (total execution time counted, not AHD itself) + Thanks to Adam Hooper + * AHD interpolation refactored. Now it is about 10% faster than + dcraw in single-process mode and up to 1.5 times faster on + 4-core and OpenMP (total execution time counted, not AHD itself) + Thanks to Adam Hooper + + * LibRaw 0.11-Beta3 + +2010-09-07 Alex Tutubalin + * Phase One files: LibRaw::unpack() sets colordata.black to + approximately correct value. + + * Fixed minor error in setting colordata.maximum value + for Phase One files. + + * LibRaw::subtract_black() sets colordata.black and + colordata.cblack[] to zero to preserve data integrity. + + * LibRaw 0.11-Beta2 + + +2010-09-04 Alex Tutubalin + + * It is now possible to crop output image on postprocessing + stage (dcraw_process). Coordinates and size of the output box + are set via imgdata.params.cropbox[4] parameter. Look into + LibRaw documentation for more details. + + + New fatal error code LIBRAW_BAD_CROP + + + New dcraw_emu sample command line switch: -B x y w h + (sets cropbox) + + Thanks to Patrick and Jan. + + * Processing pipeline has changed: the black level is subtracted + from data on postprocessing stage either automatically + (on dcraw_process() stage) or by special LibRaw API call: + + + New API calls: LibRaw::subtract_black() (C++ API) and + libraw_subtract_black (C API). + If you use dcraw_process() or dcraw_document_mode_processing() + calls YOU DON'T NEED to call subtract_black() directly. + + + The raw preprocessing mode LIBRAW_FILTERING_NOBLACKS + is deprecated and removed from LibRaw. + + * New ./configure script. + Use ./configure -h for usage details. + Thanks to Siddhesh Poyarekar + + * New API cals static LibRaw::dcraw_clear_mem() (C++ API) + and libraw_dcraw_clear_mem(..) (C API). + This calls are used to free memory, allocated by + dcraw_make_mem_image() and dcraw_make_mem_thumb() instead + of free() call. + + In some cases LibRaw and calling process have different + memory managers, so free() of make_mem_image() data + results to program crash (especially in Win32/VisualStudio + enviroment). + + * LibRaw::free() is now private instead of public (again). + + * Minor changes and bugfixes: + + + Memory allocation exceptions (std::bad_alloc) are caught, + so LibRaw API calls will return reasonable error codes + instead of C++ exception (possibly unhandled). + This problem is very unlikely to see in wild: if application + cannot allocate small data for internal structure, it will + always fail on allocation for RAW image data. + + + WIN32/VisualStudio 2008/2010: fopen,fscanf and sscanf calls + in Libraw_datastream code are changed to *_s (secure) ones. + + + Debug print removed from fatal error handler. + + + Mmaped I/O for dcraw_emu sample is turned on via -E switch + now (because old -B switch is used for settng cropbox). + + * all client code should be recompiled due to structures size change + + * LibRaw 0.11-Beta1 + + +2010-07-31 Alex Tutubalin + * dcraw 9.04 (1.438) imported: changes in tiff metadata parser, + fixed a typo in Canon A720 model name + * small patch in Sony ARW2 unpacking code to make valgrind happy + * LibRaw 0.10.0-Beta3. + +2010-07-05 Alex Tutubalin + * dcraw 9.03 (1.437) imported: + + New cameras: Canon SX20, Nikon D3s, Olympus E-P2, Panasoni DMC-GF1, + Samsung EX1, Sony A450 + + Color data changed for some cameras + + * LibRaw 0.10.0-Beta2. + +2010-06-06 Alex Tutubalin + * dcraw 9.01 (1.434) imported: + + Separate black levels for each color channel. + + New cameras: Canon 550D, Casio EX-Z1050, Fuji HS10/HS11, + Kodak Z981, Panasonic G2 and G10, Phase One P65, + Samsung NX-10 and WB550, Sony NEX-3 and NEX-5. + + Fixed file descriptor leak in dark frame subtraction processing + + * Fixed dcraw 9.01's bug in DNG black level processing + + * Preliminary support for Sony A450 camera. + + * New command-line switch -h in mem_image sample (half_size support) + + * Some patches by Johannes Hanika (darktable author): + + OpenMP speedup for PPG-interpolation + + green_matching - suppress of 'color maze' on cameras with + different green channel sensitivity. This option is turns on + by filed with same name in imgdata.params + + * all client code should be recompiled due to structures size + change + + * LibRaw::free() is now public instead of private. + + * LibRaw 0.10.0-Beta1. + +2010-05-15 Alex Tutubalin + * Fixed bug in 8-bit RAW processing code + * LibRaw 0.9.1-Release + +2010-04-26 Alex Tutubalin + * OpenMP support: OpenMP is possible under MinGW (untested) + * LibRaw 0.9.0-Release + +2010-04-21 Alex Tutubalin + * Finally fixed inconsistency in Fuji files processing + * New COLOR(row,col) call to get bayer color index in image[] array + * Old FC() call is deprecated and will be removed in future releases + * unprocessed_raw sample switched to COLOR() call + * LibRaw 0.9.0-Beta5 + + +2010-04-10 Alex Tutubalin + * Fixed bug in unpacking DNG files made from Fuji RAFs. + * LibRaw 0.9.0-Beta4 + +2010-04-09 Alex Tutubalin + + * Fixed typecast error (problem reported only on gcc 4.2.1/32bit) + in CRW files processing. + + * C++ API call LibRaw::adjust_maximum() is now deprecated and + de-documented, use params.adjust_maximum_thr instead (on by default) + + * C-API call libraw_adjust_maximum() removed. + + * New postprocessing parameter params.adjust_maximum_thr + This parameter replaces LibRaw::adjust_maximum(), but more flexible + Defaults are reasonable (0.75, same as in old adjust_maximum), + look into documentation for more details. + + * Removed last OpenMP warning + + * dcraw_emu's -c parameter now wants numeric (float) argument. This value + is assigned to params.adjust_maximum_thr. + Use -c 0.0 for dcraw compatibility. + + * all client code should be recompiled due to structures size + change + + * LibRaw 0.9.0-Beta3 + + +2010-03-29 Alex Tutubalin + * Fixed a bug in channel_maximum[] calculation for + Panasonic cameras. + * channel_maximum[] data now calculated for ALL cameras. + * OpenMP warnings suppressed. + * Documented the -c command-line switch for dcraw_emu sample. + * Removed extra messages from dcraw_emu sample. + * LibRaw 0.9.0-Beta2 + +2010-03-28 Alex Tutubalin + + New licensing: + + * Triple licensing (selected by LibRaw user): + + + LGPL 2.1 (http://www.gnu.org/licenses/lgpl-2.1.html) + + CDDL 1.0 (http://www.opensource.org/licenses/cddl1.txt) + + LibRaw Software License (27 March 2010 version) + (http://www.libraw.org/data/LICENSE.LibRaw.pdf) + + * There is no separate LibRaw-Lite and LibRaw-Commercial versions, + only single LibRaw. + Current LibRaw-Lite and LibRaw-Commercial users should switch + to LibRaw without loss of functionality. + It is possible to change licensig too (e.g. from LGPL to CDDL + for LibRaw-Lite users and from LibRaw License to LGPL or CDDL + for LibRaw-Commercial users). + + * No Foveon support :( + It is not possible to get good color from Foveon sensors with + *any* converter. So, there is no need to support these cameras. + Dcraw's Foveon-processing code is too strict licensed (GPL), + so we choose to drop it. + + New Features: + + * New data field colordata.channel_maximum[4] - per channel data + maximum (calculated for most cameras, 0 for others). + + * New call LibRaw::adjust_maximum() (and libraw_adjust_maximum() in C API). + This call changes hardcoded colordata.maximum value to calculated + at unpack stage. This helps suppress false color in highlights + (magenta clouds and so). + + * New command line parameter -c for dcraw_emu sample. Calls adjust_maximum() + for each processed file. + + * all client code should be recompiled due to structures size + change + + * LibRaw 0.9.0-Beta1 + +2010-02-06 Alex Tutubalin + * Fixed ambiguity in pow/sqrt calls (to make Sun C++ compiler happy) + * OpenMP is not supported under MS Visual Studio + * Masked a bug in RIFF format parser + * LibRaw 0.8.6 + +2009-12-30 Alex Tutubalin + * Fixed bug in simple_dcraw sample parameters processing + * Imported dcraw 8.99 (1.432): + + New cameras: Canon: 1D mk IV, Canon S90; Casio Z750, + Nikon D3S, Pentax K-x, Sony A-500/550, Fuji S200EXR + + New color data for Canon G11 and Sony A850 + + Changes in Canon sRAW processing + + Changes in Kodak metadata processing + + Changes in uncompressed Fuji files processing (FinePix S5xxx) + * LibRaw 0.8.5 + +2009-11-21 Alex Tutubalin + + Fixed a bug in processing of uncompressed Phase One files + * LibRaw 0.8.4 + +2009-10-24 Alex Tutubalin + + Imported dcraw 8.98/1.431: + * New Cameras: Canon 7D, Panasonic GF1, Sony A850 and A380, + Casio Z850, Nikon D300s + + changes in libraw_datastream.h to make compilers more happy + * LibRaw 0.8.3 + +2009-09-02 Alex Tutubalin + + Fixed bug in Hasselblad .3FR unpacking code + * Imported dcraw 8.97/1.428: Nikon D3000 image width fix + * LibRaw 0.8.2 + +2009-08-31 Alex Tutubalin + + Enum LibRaw_thumbnail_formats (LIBRAW_IMAGE_*) values changed to + match values in enum LibRaw_image_formats (LIBRAW_THUMBNAIL_*). + You need to recompile all sources using these constants. + +2009-08-30 Alex Tutubalin + * Imported dcraw 8.97/1.427: + + new cameras: Canon A470, Canon G11 (without color data), + Nikon D3000, Olympus E-P1, Panasonic DMC-FZ35/FZ38 + + some changes in decoding code. + * Fixes for Microsoft Visual C++ 6.0 compatibility + * C-API dcraw_make_mem_thumb() call finally exported in API + * LibRaw 0.8.1 + +2009-08-24 Alex Tutubalin + * Imported dcraw 8.96/1.426 + + New cameras: Casio EX-Z60 and EX-Z75, Kodak Z980, + Nikon D5000, Olympus X200, D560Z,C350Z,E620, + Pentax K7, Sony A330. + + New color data for many cameras + + Generalized unpacker code for Canon and Casio P&S cameras + * LibRaw 0.8.0-Release + +2009-08-13 Alex Tutubalin + * RAW files larger than 2Gb are supported on: + - Unix (all supported: FreeBSD, MacOS X, Linux) + - Windows (with C runtime version >= 8.0) + * bzero replaced with memset to make Solaris users happy + * All applications on 32-bit systems should be recompiled + due to data structures size changes. + * Minor fixes in windows makefile + * LibRaw 0.8.0-Beta5 + +2009-07-21 Alex Tutubalin + * Imported dcraw 8.95 (1.425): + + new huffman tree code + + New cameras supported: AGFAPHOTO DC-833m, Casio EX-S20, + Phase One P65, Samsung S850 + + Removed hardcoded white-balance data for many P&S cameras. + It is recommended to set params.use_camera_wb to 1 for + safe WB. + * Fixes for Nikon D5000 files: no pink stripe at + right side of frame + * C-wrapper: added missed calls + libraw_dcraw_make_mem_image + libraw_dcraw_ make_mem_thumb + * Minor fixes to make non-gcc compilers more happy + * Internal structures changed, full recompilation of all client + code is needed. + * LibRaw 0.8.0-Beta4 + +2009-06-08 Alex Tutubalin + * Fixes: gamma curve processing was not performed in + dcraw_write_mem_image() + * Fixes: gamma curve processing was not performed for + Kodak thumbnails + * LibRaw 0.8.0-Beta3 + +2009-06-05 Alex Tutubalin + * Fixes in documentation: params.gamm[] described more precisely + * Fixes in version number, 0.8-beta1 was mistakenly 0.0.0-beta1 + * LibRaw 0.8.0-Beta2 + +2009-06-04 Alex Tutubalin + * Imported dcraw 8.94 (1.423): + + New camera support: + Canon: SX1, 500D/Rebel T1i, A570, A590, SX110 + Kodak Z1015, Motorola PIXL, Olympus E30, Panasonic DMC-GH1 + + Improved color data for Nikon D3X + + New gamma curve model + + Many changes in RAW unpacking code + + Canon cameras: black level is not subtracted if set + params.document_mode > 1 + + * API changed: params.gamma_16bit field removed. Gamma curve is + set via params.gamm[0]/gamm[1] values (see documentation and + samples for details) + * LibRaw::identify() splitted to avoid MS VS2008 bug (too many + nested blocks) + + * Samples: dcraw_emu and mem_image samples supports new dcraw + 16bit/gamma semantics: + -6: set 16 bit output + -4: set 16 bit output and linear gamma curve and no auto + brighness + * LibRaw 0.8.0-Beta1 + +2009-04-28 Alex Tutubalin + * Identify sample renamed to raw-identify (name conflict + with ImageMagic) + * Copyright notice changes + * Many compiler warnings removed + +2009-04-07 Alex Tutubalin + * More accurate types conversion in libraw_datastream.h + * New postprocessing parameter auto_bright_thr: set portion of + clipped pixels for auto brightening code (instead of + dcraw-derived hardcoded 1%) + * -U option for dcraw_emu sample sets auto_bright_thr parameter + * all client code should be recompiled due to structures size + change + * LibRaw 0.7.2-Release + +2009-03-22 Alex Tutubalin + * Fixed typo in OpenMP support code + * MinGW support + * dcraw source is included in distribution + * LibRaw 0.7.1-Release + +2009-03-15 Alex Tutubalin + * Fuji SuperCCD RAWs: color channels unshuffled on RAW + read stage (moved from postprocessing stage) + + * LibRaw 0.7.0-Release + +2009-03-13 Alex Tutubalin + * dcraw 8.93/1.421 imported: + + more accurate pentax dSLR support + + fixes in Kodak 620x/720x identification + + faster identification procedure for some formats. + * LibRaw 0.7.0-Beta5 + + +2009-03-08 Alex Tutubalin + * dcraw 8.92/1.420 imported: + + user-specified gamma curve + + Pentax K2000/Km support + + Changes in Canon sRAW processing (support for 5D2 fw 1.07) + + * all client code should be recompiled + + * LibRaw 0.7.0-Beta4 + +2009-02-13 Alex Tutubalin + * bugfix: 4channels sample finally subtracts black by default + * dcraw 8.91/1.419 imported: + + fixes in RIFF files parsing + + * LibRaw 0.7.0-Beta3 + +2009-02-12 Alex Tutubalin + * Black level was not calculated for Canon RAWs in + some filtering modes + + * 4channels sample prints calculated black level + (scaled if autoscaling used). + Also output file names for this sample now includes + color channel name (R/G/B/G2 or C/M/Y/G) + + * LibRaw 0.7.0-Beta2 + +2009-02-09 Alex Tutubalin + * New sample 4channels: splits RAW color channels into four + separate TIFFs + + * LibRaw 0.7.0-Beta1 + +2009-02-07 Alex Tutubalin + * Fixed bug in external jpeg metadata reading code. + + * Cleaned some C++ warnings + + * dcraw 8.91/1.418 imported + + Hasselblad V96C support + + * You need to clean and recompile client code which + uses LibRaw_*_datastream classes. + + * LibRaw 0.7.0-Alpha6 + +2009-01-30 Alex Tutubalin + + * New data input framework is created. It is possible now to + easyly implement your own data input interface for LibRaw + (e.g. for reading RAW data from network data stream) + + * All older programs using previous LibRaw versions are + compatible at source code level. + + * LibRaw can read RAW data from memory buffer via + new LibRaw::open_buffer() API call (implemented on top of + new input framework). + This call used in sample application dcraw_emu and simple_dcraw + (with -B command-line switch) to test new API. + + * Error handling callback functions now can be called with + NULL filename passed (if underlying data stream object + does not know file name). + So, client error handling callbacks should work with NULL + filename. + + * All client code should be recompiled + + * Imported dcraw 8.90/1.417: + + Support for loading White Balance data from + Sony ARW files edited with Sony IDC software. + + * LibRaw 0.7.0-Alpha5 + +2009-01-17 Alex Tutubalin + * Raw filtering mode LIBRAW_FILTERING_NOPOSTPROCESS has renamed + to LIBRAW_FILTERING_NORAWCURVE for better reflect its purpose. + This filtering_mode bit turns off tone curve applying on + RAW data on bayer-pattern cameras with raw tone curve: + + Adobe DNG (only RAW with bayer pattern) + + Nikon compressed NEF + + Some Kodak cameras + + Sony A700/A900 (tone curve applied to 8-bit raws) + + * unprocessed_raw sample: added command-line key -N, this key + turns on LIBRAW_FILTERING_NORAWCURVE filtering mode. + + * New scheme of Fuji RAW processing (introduced in 0.7-Alpha3) + supports DNG files generated from Fuji RAF. + + * Imported dcraw 8.90/1.416: + + better support for Samsung S85 + + fixed possible integer overflow in wavelet denoising code + + * LibRaw 0.7.0-Alpha4 + + +2009-01-14 Alex Tutubalin + * Black mask extraction supported for all files with bayer data + (one component per pixel). Black mask data not avaliable + for multi-component data (Foveon, Canon sRAW, Sinar 4-shot, + Kodak YCC/YRGB). + + * Black level subtraction can be turned off for all bayer + cameras (added support for PhaseOne backs). + + * Fujifilm camera processing model changed: + + RAW data is extracted without 45-degree rotation + + dcraw-compatible rotation is performed on postptocessing stage + + it is possible to rotate RAW data without postprocessing + by LibRaw::rotate_fuji_raw() call. + + * New filtering mode setting: LIBRAW_FILTERING_NOPOSTPROCESS + This bits turns off RAW tone curve processing based on tone curve + readed from RAW metadata. + This mode supported only for PhaseOne backs now (to be supported + on all relevant cameras in nearest future releases) + + * Black level data (got from RAW data) are stored for PhaseOne backs. + + * Black level subtraction bug (derived from dcraw) fixed + for PhaseOne files. + + * Fixed processing of -s parameter for dcraw_emu sample + + * Parameter -s N (select shot number) added to + unprocessed_raw sample. + + * Imported dcraw 8.90/1.414: + + changes in QuickTake 100 metadata processing + + changes in external jpeg processing code + + Samsung S85 support + + * All client code should be recompiled + + * LibRaw 0.7.0-Alpha3 released + +2009-01-10 Alex Tutubalin + * Fixed bug in add_masked_borders: crash if output dimensions + is already larger than raw dimensions + * Fixed out of bounds in samples/unprocessed_raw.cpp for files + with non-square pixels + + * LibRaw 0.7.0-Alpha2 released + +2009-01-08 Alex Tutubalin + * Fixed bug in 0.7.0-a0: black frame size has not reset, + so in batch processing there is an error in black frame + size for files without black frame. + + * Implemented reading of black/masked pixels data for + near all cameras with masked pixels, exclding: + + Canon sRAW, Leaf (MOS), Sinar 4-shot - more than one + color component in black frame (redesign of black frame + data structures required). + + Fuji SuperCCD: need to design right methods of extraction + (should we rotate and resize black pixels as active ones??) + + * Tested for most dSLR data formats with masked pixels: 7 of 9 + untested formats are from old P&S cameras. + + * New call LibRaw::unpack_function_name() returns unpack function name + (useful for testers only) + + * New identify sample parameters (useful for test-suite builders + to check test coverage): + -u - print unpack function name + -f - print masked frame size + These parameters works only for identify run without -v parameter + + * Imported dcraw 8.89/1.411 + + changes in Panasonic FZ50 files parsing + + * LibRaw 0.7.0-Alpha1 released + + +2009-01-05 Alex Tutubalin + * It is possible to turn off RAW data filtration (black level + subtraction, zero pixels averaging): + + supported on all cameras except Foveon and Phase One + + filtraction controlled by new parameter "filtering_mode" + + it is possible to expand API by filtering procedures + built for specific camera model. + + * Black border (masked pixels) extraction: + + API (data structures) for storing black mask. + + Black mask extraction supported only for limited list of + data formats: + - Canon .CRW, .CR2 (with exception of sRAW),A600, A5 + - Adobe DNG (both converted RAW and native DNG) + - Nikon NEF (compressed only) + this list to be expanded in future LibRaw versions + * New call add_masked_borders_to_bitmap makes full bitmap + 'masked border' + image + * Usage sample for functionality listed above: + samples/unprocessed_raw + * Imported dcraw 8.89/1.410: + + fixed bugs in Hasselblad .fff decoding + + fixes in Imacon metadata decoding + * Documentation changes + * All client code should be recompiled + * LibRaw 0.7.0-Alpha0 + + +2009-01-01 Alex Tutubalin + * Fixed a bug (filedescriptor and buffer memory leak) in thumbnail + extraction when called before metadata analysis. + Thanks to Albert Astalis Cid. + * LibRaw 0.6.4 Release + +2008-12-11 Alex Tutubalin + * Imported new edition of dcraw 8.89 (version 1.409) + * Nikon NEF decoding changed + * LibRaw 0.6.3 Release + +2008-12-03 Alex Tutubalin + * fixed bug in Panasonic .RW2 processing (only for thread-safe version, + single-threaded version was not affected) + * All client code should be recompiled + * LibRaw 0.6.2 Release + +2008-12-03 Alex Tutubalin + * Imported dcraw 8.89 (version 1.407) + * New cameras: + Canon G10 & 5D Mk2, Leaf AFi 7, Leica D-LUX4, Panasonic FX150 & G1, + Fujifilm IS Pro, + * Changed camera support (color conversion tables): + Canon 50D, Nikon D90 & P6000, Panasonic LX3 & FZ28, Sony A900 + * LibRaw 0.6.2 beta + +2008-09-25 Alex Tutubalin + * Added new data field float LibRaw::imgdata.color.cam_xyz[4][3]. + This field contains constant table (different for each camera) for + Camera RGB->XYZ conversion. + * All client code should be recompiled + * LibRaw 0.6.1 Release + +2008-09-18 Alex Tutubalin + * dcraw 8.88 imported: + - new cameras (Canon 50D, Sony A900, Nikon D90 & P6000, + Panasonic LX3 FZ28) + - new method of black point subtraction for Canon cameras, + preliminary banding supression. + * Stack memory usage lowered (some thread data moved to dynamic + memory) + * some patches for MSVC compatibility + * LibRaw 0.6.0 Release + +2008-09-16 Alex Tutubalin + * Enum definitions changed to make gcc -pedantic happy + * Compiler/preprocessor flags does not affects LibRaw class field set + (i.e. structure for thread local storage is always allocated) + * Default library compilation mode (i.e. sources imported in another + project) is thread-safe + +2008-09-14 Alex Tutubalin + * OpenMP support for most CPU consuming steps of processing: + ahd_interpolation. wavelet_denoise + 10-30% speed-up of full processing pipe on 2-core CPU + OpenMP supported only on gcc (Linux/FreeBSD and Mac OS X) + + * LibRaw 0.6.0-Beta-1 + +2008-09-10 Alex Tutubalin + * All set_**handler accepts additional void* pointer, which should point to + callback private data. This pointer passed to user callback when it called. + + * LibRaw 0.6.0-alpha5 + + * All client code should be recompiled + +2008-09-10 Alex Tutubalin + * New processing stages in enum LibRaw_progress: + LIBRAW_PROGRESS_BAD_PIXELS LIBRAW_PROGRESS_DARK_FRAME + (reserved stages LIBRAW_PROGRESS_RESERVED_PRE1-PRE2 has removed) + * libraw_strprogress() - convert progress code into string + + * Added progress/cancellation user callbacks + + new fatal error code: CANCELLED_BY_CALLBACK + + sample usage in samples/dcraw_emu.cpp (try run it with -v -v -v opts) + + * LibRaw 0.6.0-alpha4 + + * All client code should be recompiled + +2008-09-08 Alex Tutubalin + * ICC-profiles support (same as in dcraw) + + input/output profiles (specified as path to 'icc' file or 'embed' for + embedded input profile) + + additional warnings + + LCMS library used + + * support of bad pixel map (caller should specify path to bad pixel file + in dcraw-compatible format) + + * dark frame subtraction support (caller should supply path to 16-bit PGM + map). samples/simple_dcraw.cpp - -4 option added for dark frame file + generation + + * support of bad pixeld map (dcraw-compatible format) + + * the dcraw_emu sample supports all new features (ICC, dark frame, bad + pixels) + + * libraw/libraw_version.h, defines, calls and macros for version checks: + + LibRaw::version(), LibRaw::versionNumber(), LIBRAW_CHECK_VERSION() + + * List of supported cameras: + + LibRaw::cameraCount() + + LibRaw::cameraList() + + * fixed error in adjust_sizes_info_only + + * documentation changes + + * LibRaw 0.6.0-alpha3 + +2008-09-07 Alex Tutubalin + * samples/mem_image.c - bitwise equal output with dcraw -4 + (PPMs outputted with network byte order) + * LibRaw 0.6.0-alpha2 + +2008-09-06 Alex Tutubalin + * Added calls dcraw_make_mem_image and dcraw_make_mem_image: + + functions (and supporting code) + + documentation changed + + new sample code samples/mem_image.cpp + * Added processing parameter LibRaw::imgdata.params.gamma_16bit + (set to 1 to make gamma correction for 16-bit output) + * LibRaw 0.6.0-alpha1 + +2008-08-28 Alex Tutubalin + * dcraw 1.404 (8.87) imported: + - 6 new cameras supported (Canon 1000D, A720, SD300; + Nikon D700, Oly E-520,Kodak C603) + * Licensing changed to GPL v2 + +2008-05-02 Alex Tutubalin + * mmap/malloc+read IO-layer removed due to no performance gain. + FILE I/O returned + +2008-05-02 Alex Tutubalin + * dcraw 1.403 imported + - changes in ljpeg decompression (index values cut to 12 bit) + - changes in parse_foveon() jpeg thumbnail extraction + * LibRaw 0.5.3 released + +2008-04-24 Alex Tutubalin + * Linux build of samples/identify fixed + * documentation editorial + * LibRaw 0.5.2 released + +2008-04-21 Alex Tutubalin + * All documentation translated to English + * English changelog started :) + * minor bug (include path) fixed in samples/half_mt + * LibRaw 0.5.1 released diff --git a/Source/LibRawLite/LICENSE.CDDL b/Source/LibRawLite/LICENSE.CDDL index a3350cf..8ee560c 100644 --- a/Source/LibRawLite/LICENSE.CDDL +++ b/Source/LibRawLite/LICENSE.CDDL @@ -1,340 +1,340 @@ -COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - -1. Definitions. - -1.1. Contributor means each individual or entity that creates or -contributes to the creation of Modifications. - -1.2. Contributor Version means the combination of the Original -Software, prior Modifications used by a Contributor (if any), -and the Modifications made by that particular Contributor. - -1.3. Covered Software means (a) the Original Software, or (b) -Modifications, or (c) the combination of files containing -Original Software with files containing Modifications, in each -case including portions thereof. - -1.4. Executable means the Covered Software in any form other -than Source Code. - -1.5. Initial Developer means the individual or entity that first -makes Original Software available under this License. - -1.6. Larger Workmeans a work which combines Covered Software or -portions thereof with code not governed by the terms of this -License. - -1.7. License means this document. - -1.8. Licensable means having the right to grant, to the maximum -extent possible, whether at the time of the initial grant or -subsequently acquired, any and all of the rights conveyed herein. - -1.9. Modifications means the Source Code and Executable form of -any of the following: A. Any file that results from an addition -to, deletion from or modification of the contents of a file -containing Original Software or previous Modifications; B. Any -new file that contains any part of the Original Software or -previous Modification; or C. Any new file that is contributed or -otherwise made available under the terms of this License. - -1.10. Original Software means the Source Code and Executable -form of computer software code that is originally released under -this License. - -1.11. Patent Claims means any patent claim(s), now owned or -hereafter acquired, including without limitation, method, -process, and apparatus claims, in any patent Licensable by -grantor. - -1.12. Source Code means (a) the common form of computer software -code in which modifications are made and (b) associated -documentation included in or with such code. - -1.13. You (or Your) means an individual or a legal entity -exercising rights under, and complying with all of the terms of, -this License. For legal entities, You includes any entity which -controls, is controlled by, or is under common control with You. -For purposes of this definition, control means (a) the power, -direct or indirect, to cause the direction or management of such -entity, whether by contract or otherwise, or (b) ownership of -more than fifty percent (50%) of the outstanding shares or -beneficial ownership of such entity. - -2. License Grants. - -2.1. The Initial Developer Grant. Conditioned upon Your -compliance with Section 3.1 below and subject to third party -intellectual property claims, the Initial Developer hereby -grants You a world-wide, royalty-free, non-exclusive license: - -(a) under intellectual property rights (other than patent or -trademark) Licensable by Initial Developer, to use, reproduce, -modify, display, perform, sublicense and distribute the Original -Software (or portions thereof), with or without Modifications, -and/or as part of a Larger Work; and - -(b) under Patent Claims infringed by the making, using or -selling of Original Software, to make, have made, use, practice, -sell, and offer for sale, and/or otherwise dispose of the -Original Software (or portions thereof); - -(c) The licenses granted in Sections 2.1(a) and (b) are -effective on the date Initial Developer first distributes or -otherwise makes the Original Software available to a third party -under the terms of this License; - -(d) Notwithstanding Section 2.1(b) above, no patent license is -granted: (1) for code that You delete from the Original -Software, or (2) for infringements caused by: (i) the -modification of the Original Software, or (ii) the combination -of the Original Software with other software or devices. - -2.2. Contributor Grant. Conditioned upon Your compliance with -Section 3.1 below and subject to third party intellectual -property claims, each Contributor hereby grants You a -world-wide, royalty-free, non-exclusive license: - -(a) under intellectual property rights (other than patent or -trademark) Licensable by Contributor to use, reproduce, modify, -display, perform, sublicense and distribute the Modifications -created by such Contributor (or portions thereof), either on an -unmodified basis, with other Modifications, as Covered Software -and/or as part of a Larger Work; and - -(b) under Patent Claims infringed by the making, using, or -selling of Modifications made by that Contributor either alone -and/or in combination with its Contributor Version (or portions -of such combination), to make, use, sell, offer for sale, have -made, and/or otherwise dispose of: (1) Modifications made by -that Contributor (or portions thereof); and (2) the combination -of Modifications made by that Contributor with its Contributor -Version (or portions of such combination). - -(c) The licenses granted in Sections 2.2(a) and 2.2(b) -areeffective on the date Contributor first distributes or -otherwise makes the Modifications available to a third party. - -(d) Notwithstanding Section 2.2(b) above, no patent license is -granted: (1) for any code that Contributor has deleted from the -Contributor Version; (2) for infringements caused by: (i) third -party modifications of Contributor Version, or (ii) the -combination of Modifications made by that Contributor with other -software (except as part of the Contributor Version) or other -devices; or (3) under Patent Claims infringed by Covered -Software in the absence of Modifications made by that -Contributor. - -3. Distribution Obligations. - -3.1. Availability of Source Code. Any Covered Software that You -distribute or otherwise make available in Executable form must -also be made available in Source Code form and that Source Code -form must be distributed only under the terms of this License. -You must include a copy of this License with every copy of the -Source Code form of the Covered Software You distribute or -otherwise make available. You must inform recipients of any such -Covered Software in Executable form as to how they can obtain -such Covered Software in Source Code form in a reasonable manner -on or through a medium customarily used for software exchange. - -3.2. Modifications. The Modifications that You create or to -which You contribute are governed by the terms of this License. -You represent that You believe Your Modifications are Your -original creation(s) and/or You have sufficient rights to grant -the rights conveyed by this License. - -3.3. Required Notices. You must include a notice in each of Your -Modifications that identifies You as the Contributor of the -Modification. You may not remove or alter any copyright, patent -or trademark notices contained within the Covered Software, or -any notices of licensing or any descriptive text giving -attribution to any Contributor or the Initial Developer. - -3.4. Application of Additional Terms. You may not offer or -impose any terms on any Covered Software in Source Code form -that alters or restricts the applicable version of this License -or the recipients rights hereunder. You may choose to offer, and -to charge a fee for, warranty, support, indemnity or liability -obligations to one or more recipients of Covered -Software. However, you may do so only on Your own behalf, and -not on behalf of the Initial Developer or any Contributor. You -must make it absolutely clear that any such warranty, support, -indemnity or liability obligation is offered by You alone, and -You hereby agree to indemnify the Initial Developer and every -Contributor for any liability incurred by the Initial Developer -or such Contributor as a result of warranty, support, indemnity -or liability terms You offer. - -3.5. Distribution of Executable Versions. You may distribute the -Executable form of the Covered Software under the terms of this -License or under the terms of a license of Your choice, which -may contain terms different from this License, provided that You -are in compliance with the terms of this License and that the -license for the Executable form does not attempt to limit or -alter the recipients rights in the Source Code form from the -rights set forth in this License. If You distribute the Covered -Software in Executable form under a different license, You must -make it absolutely clear that any terms which differ from this -License are offered by You alone, not by the Initial Developer -or Contributor. You hereby agree to indemnify the Initial -Developer and every Contributor for any liability incurred by -the Initial Developer or such Contributor as a result of any -such terms You offer. - -3.6. Larger Works. You may create a Larger Work by combining -Covered Software with other code not governed by the terms of -this License and distribute the Larger Work as a single product. -In such a case, You must make sure the requirements of this -License are fulfilled for the Covered Software. - -4. Versions of the License. - -4.1. New Versions. Sun Microsystems, Inc. is the initial license -steward and may publish revised and/or new versions of this -License from time to time. Each version will be given a -distinguishing version number. Except as provided in Section -4.3, no one other than the license steward has the right to -modify this License. - -4.2. Effect of New Versions. You may always continue to use, -distribute or otherwise make the Covered Software available -under the terms of the version of the License under which You -originally received the Covered Software. If the Initial -Developer includes a notice in the Original Software prohibiting -it from being distributed or otherwise made available under any -subsequent version of the License, You must distribute and make -the Covered Software available under the terms of the version of -the License under which You originally received the Covered -Software. Otherwise, You may also choose to use, distribute or -otherwise make the Covered Software available under the terms of -any subsequent version of the License published by the license -steward. - -4.3. Modified Versions. When You are an Initial Developer and -You want to create a new license for Your Original Software, You -may create and use a modified version of this License if You: -(a) rename the license and remove any references to the name of -the license steward (except to note that the license differs -from this License); and (b) otherwise make it clear that the -license contains terms which differ from this License. - -5. DISCLAIMER OF WARRANTY. COVERED SOFTWARE IS PROVIDED UNDER -THIS LICENSE ON AN AS IS BASIS, WITHOUT WARRANTY OF ANY KIND, -EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, -WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, -MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. -THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE -DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY -OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, -REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN -ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE -IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. - -6. TERMINATION. - -6.1. This License and the rights granted hereunder will -terminate automatically if You fail to comply with terms herein -and fail to cure such breach within 30 days of becoming aware of -the breach. Provisions which, by their nature, must remain in -effect beyond the termination of this License shall survive. - -6.2. If You assert a patent infringement claim (excluding -declaratory judgment actions) against Initial Developer or a -Contributor (the Initial Developer or Contributor against whom -You assert such claim is referred to as Participant) alleging -that the Participant Software (meaning the Contributor Version -where the Participant is a Contributor or the Original Software -where the Participant is the Initial Developer) directly or -indirectly infringes any patent, then any and all rights granted -directly or indirectly to You by such Participant, the Initial -Developer (if the Initial Developer is not the Participant) and -all Contributors under Sections 2.1 and/or 2.2 of this License -shall, upon 60 days notice from Participant terminate -prospectively and automatically at the expiration of such 60 day -notice period, unless if within such 60 day period You withdraw -Your claim with respect to the Participant Software against such -Participant either unilaterally or pursuant to a written -agreement with Participant. - -6.3. In the event of termination under Sections 6.1 or 6.2 -above, all end user licenses that have been validly granted by -You or any distributor hereunder prior to termination (excluding -licenses granted to You by any distributor) shall survive -termination. - -7. LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES AND UNDER NO -LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR -OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY OTHER -CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY -SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY -INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY -CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOST -PROFITS, LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR -MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, -EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY -OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO -LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH -PARTYS NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH -LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR -LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS -EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. - -8. U.S. GOVERNMENT END USERS. The Covered Software is a -commercial item, as that term is defined in 48 C.F.R. 2.101 -(Oct. 1995), consisting of commercial computer software (as that -term is defined at 48 C.F.R. 252.227-7014(a)(1)) and commercial -computer software documentation as such terms are used in 48 -C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and -48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all -U.S. Government End Users acquire Covered Software with only -those rights set forth herein. This U.S. Government Rights -clause is in lieu of, and supersedes, any other FAR, DFAR, or -other clause or provision that addresses Government rights in -computer software under this License. - -9. MISCELLANEOUS. This License represents the complete agreement -concerning subject matter hereof. If any provision of this -License is held to be unenforceable, such provision shall be -reformed only to the extent necessary to make it enforceable. -This License shall be governed by the law of the jurisdiction -specified in a notice contained within the Original Software -(except to the extent applicable law, if any, provides -otherwise), excluding such jurisdictions conflict-of-law -provisions. Any litigation relating to this License shall be -subject to the jurisdiction of the courts located in the -jurisdiction and venue specified in a notice contained within -the Original Software, with the losing party responsible for -costs, including, without limitation, court costs and reasonable -attorneys fees and expenses. The application of the United -Nations Convention on Contracts for the International Sale of -Goods is expressly excluded. Any law or regulation which -provides that the language of a contract shall be construed -against the drafter shall not apply to this License. You agree -that You alone are responsible for compliance with the United -States export administration regulations (and the export control -laws and regulation of any other countries) when You use, -distribute or otherwise make available any Covered Software. - -10. RESPONSIBILITY FOR CLAIMS. As between Initial Developer and -the Contributors, each party is responsible for claims and -damages arising, directly or indirectly, out of its utilization -of rights under this License and You agree to work with Initial -Developer and Contributors to distribute such responsibility on -an equitable basis. Nothing herein is intended or shall be -deemed to constitute any admission of liability. - ----------------------------------------------------------------- - -NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND -DISTRIBUTION LICENSE (CDDL): This code is released under the -CDDL and shall be governed by the laws of the State of -California (excluding conflict-of-law provisions). Any -litigation relating to this License shall be subject to the -jurisdiction of the Federal Courts of the Northern District of -California and the state courts of the State of California, with -venue lying in Santa Clara County, California. - ----------------------------------------------------------------- - +COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + +1. Definitions. + +1.1. Contributor means each individual or entity that creates or +contributes to the creation of Modifications. + +1.2. Contributor Version means the combination of the Original +Software, prior Modifications used by a Contributor (if any), +and the Modifications made by that particular Contributor. + +1.3. Covered Software means (a) the Original Software, or (b) +Modifications, or (c) the combination of files containing +Original Software with files containing Modifications, in each +case including portions thereof. + +1.4. Executable means the Covered Software in any form other +than Source Code. + +1.5. Initial Developer means the individual or entity that first +makes Original Software available under this License. + +1.6. Larger Workmeans a work which combines Covered Software or +portions thereof with code not governed by the terms of this +License. + +1.7. License means this document. + +1.8. Licensable means having the right to grant, to the maximum +extent possible, whether at the time of the initial grant or +subsequently acquired, any and all of the rights conveyed herein. + +1.9. Modifications means the Source Code and Executable form of +any of the following: A. Any file that results from an addition +to, deletion from or modification of the contents of a file +containing Original Software or previous Modifications; B. Any +new file that contains any part of the Original Software or +previous Modification; or C. Any new file that is contributed or +otherwise made available under the terms of this License. + +1.10. Original Software means the Source Code and Executable +form of computer software code that is originally released under +this License. + +1.11. Patent Claims means any patent claim(s), now owned or +hereafter acquired, including without limitation, method, +process, and apparatus claims, in any patent Licensable by +grantor. + +1.12. Source Code means (a) the common form of computer software +code in which modifications are made and (b) associated +documentation included in or with such code. + +1.13. You (or Your) means an individual or a legal entity +exercising rights under, and complying with all of the terms of, +this License. For legal entities, You includes any entity which +controls, is controlled by, or is under common control with You. +For purposes of this definition, control means (a) the power, +direct or indirect, to cause the direction or management of such +entity, whether by contract or otherwise, or (b) ownership of +more than fifty percent (50%) of the outstanding shares or +beneficial ownership of such entity. + +2. License Grants. + +2.1. The Initial Developer Grant. Conditioned upon Your +compliance with Section 3.1 below and subject to third party +intellectual property claims, the Initial Developer hereby +grants You a world-wide, royalty-free, non-exclusive license: + +(a) under intellectual property rights (other than patent or +trademark) Licensable by Initial Developer, to use, reproduce, +modify, display, perform, sublicense and distribute the Original +Software (or portions thereof), with or without Modifications, +and/or as part of a Larger Work; and + +(b) under Patent Claims infringed by the making, using or +selling of Original Software, to make, have made, use, practice, +sell, and offer for sale, and/or otherwise dispose of the +Original Software (or portions thereof); + +(c) The licenses granted in Sections 2.1(a) and (b) are +effective on the date Initial Developer first distributes or +otherwise makes the Original Software available to a third party +under the terms of this License; + +(d) Notwithstanding Section 2.1(b) above, no patent license is +granted: (1) for code that You delete from the Original +Software, or (2) for infringements caused by: (i) the +modification of the Original Software, or (ii) the combination +of the Original Software with other software or devices. + +2.2. Contributor Grant. Conditioned upon Your compliance with +Section 3.1 below and subject to third party intellectual +property claims, each Contributor hereby grants You a +world-wide, royalty-free, non-exclusive license: + +(a) under intellectual property rights (other than patent or +trademark) Licensable by Contributor to use, reproduce, modify, +display, perform, sublicense and distribute the Modifications +created by such Contributor (or portions thereof), either on an +unmodified basis, with other Modifications, as Covered Software +and/or as part of a Larger Work; and + +(b) under Patent Claims infringed by the making, using, or +selling of Modifications made by that Contributor either alone +and/or in combination with its Contributor Version (or portions +of such combination), to make, use, sell, offer for sale, have +made, and/or otherwise dispose of: (1) Modifications made by +that Contributor (or portions thereof); and (2) the combination +of Modifications made by that Contributor with its Contributor +Version (or portions of such combination). + +(c) The licenses granted in Sections 2.2(a) and 2.2(b) +areeffective on the date Contributor first distributes or +otherwise makes the Modifications available to a third party. + +(d) Notwithstanding Section 2.2(b) above, no patent license is +granted: (1) for any code that Contributor has deleted from the +Contributor Version; (2) for infringements caused by: (i) third +party modifications of Contributor Version, or (ii) the +combination of Modifications made by that Contributor with other +software (except as part of the Contributor Version) or other +devices; or (3) under Patent Claims infringed by Covered +Software in the absence of Modifications made by that +Contributor. + +3. Distribution Obligations. + +3.1. Availability of Source Code. Any Covered Software that You +distribute or otherwise make available in Executable form must +also be made available in Source Code form and that Source Code +form must be distributed only under the terms of this License. +You must include a copy of this License with every copy of the +Source Code form of the Covered Software You distribute or +otherwise make available. You must inform recipients of any such +Covered Software in Executable form as to how they can obtain +such Covered Software in Source Code form in a reasonable manner +on or through a medium customarily used for software exchange. + +3.2. Modifications. The Modifications that You create or to +which You contribute are governed by the terms of this License. +You represent that You believe Your Modifications are Your +original creation(s) and/or You have sufficient rights to grant +the rights conveyed by this License. + +3.3. Required Notices. You must include a notice in each of Your +Modifications that identifies You as the Contributor of the +Modification. You may not remove or alter any copyright, patent +or trademark notices contained within the Covered Software, or +any notices of licensing or any descriptive text giving +attribution to any Contributor or the Initial Developer. + +3.4. Application of Additional Terms. You may not offer or +impose any terms on any Covered Software in Source Code form +that alters or restricts the applicable version of this License +or the recipients rights hereunder. You may choose to offer, and +to charge a fee for, warranty, support, indemnity or liability +obligations to one or more recipients of Covered +Software. However, you may do so only on Your own behalf, and +not on behalf of the Initial Developer or any Contributor. You +must make it absolutely clear that any such warranty, support, +indemnity or liability obligation is offered by You alone, and +You hereby agree to indemnify the Initial Developer and every +Contributor for any liability incurred by the Initial Developer +or such Contributor as a result of warranty, support, indemnity +or liability terms You offer. + +3.5. Distribution of Executable Versions. You may distribute the +Executable form of the Covered Software under the terms of this +License or under the terms of a license of Your choice, which +may contain terms different from this License, provided that You +are in compliance with the terms of this License and that the +license for the Executable form does not attempt to limit or +alter the recipients rights in the Source Code form from the +rights set forth in this License. If You distribute the Covered +Software in Executable form under a different license, You must +make it absolutely clear that any terms which differ from this +License are offered by You alone, not by the Initial Developer +or Contributor. You hereby agree to indemnify the Initial +Developer and every Contributor for any liability incurred by +the Initial Developer or such Contributor as a result of any +such terms You offer. + +3.6. Larger Works. You may create a Larger Work by combining +Covered Software with other code not governed by the terms of +this License and distribute the Larger Work as a single product. +In such a case, You must make sure the requirements of this +License are fulfilled for the Covered Software. + +4. Versions of the License. + +4.1. New Versions. Sun Microsystems, Inc. is the initial license +steward and may publish revised and/or new versions of this +License from time to time. Each version will be given a +distinguishing version number. Except as provided in Section +4.3, no one other than the license steward has the right to +modify this License. + +4.2. Effect of New Versions. You may always continue to use, +distribute or otherwise make the Covered Software available +under the terms of the version of the License under which You +originally received the Covered Software. If the Initial +Developer includes a notice in the Original Software prohibiting +it from being distributed or otherwise made available under any +subsequent version of the License, You must distribute and make +the Covered Software available under the terms of the version of +the License under which You originally received the Covered +Software. Otherwise, You may also choose to use, distribute or +otherwise make the Covered Software available under the terms of +any subsequent version of the License published by the license +steward. + +4.3. Modified Versions. When You are an Initial Developer and +You want to create a new license for Your Original Software, You +may create and use a modified version of this License if You: +(a) rename the license and remove any references to the name of +the license steward (except to note that the license differs +from this License); and (b) otherwise make it clear that the +license contains terms which differ from this License. + +5. DISCLAIMER OF WARRANTY. COVERED SOFTWARE IS PROVIDED UNDER +THIS LICENSE ON AN AS IS BASIS, WITHOUT WARRANTY OF ANY KIND, +EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, +WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, +MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. +THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE +DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY +OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, +REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN +ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE +IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. + +6. TERMINATION. + +6.1. This License and the rights granted hereunder will +terminate automatically if You fail to comply with terms herein +and fail to cure such breach within 30 days of becoming aware of +the breach. Provisions which, by their nature, must remain in +effect beyond the termination of this License shall survive. + +6.2. If You assert a patent infringement claim (excluding +declaratory judgment actions) against Initial Developer or a +Contributor (the Initial Developer or Contributor against whom +You assert such claim is referred to as Participant) alleging +that the Participant Software (meaning the Contributor Version +where the Participant is a Contributor or the Original Software +where the Participant is the Initial Developer) directly or +indirectly infringes any patent, then any and all rights granted +directly or indirectly to You by such Participant, the Initial +Developer (if the Initial Developer is not the Participant) and +all Contributors under Sections 2.1 and/or 2.2 of this License +shall, upon 60 days notice from Participant terminate +prospectively and automatically at the expiration of such 60 day +notice period, unless if within such 60 day period You withdraw +Your claim with respect to the Participant Software against such +Participant either unilaterally or pursuant to a written +agreement with Participant. + +6.3. In the event of termination under Sections 6.1 or 6.2 +above, all end user licenses that have been validly granted by +You or any distributor hereunder prior to termination (excluding +licenses granted to You by any distributor) shall survive +termination. + +7. LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES AND UNDER NO +LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR +OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY OTHER +CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY +SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY +INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY +CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOST +PROFITS, LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR +MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, +EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY +OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO +LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH +PARTYS NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH +LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR +LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS +EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. + +8. U.S. GOVERNMENT END USERS. The Covered Software is a +commercial item, as that term is defined in 48 C.F.R. 2.101 +(Oct. 1995), consisting of commercial computer software (as that +term is defined at 48 C.F.R. 252.227-7014(a)(1)) and commercial +computer software documentation as such terms are used in 48 +C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and +48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all +U.S. Government End Users acquire Covered Software with only +those rights set forth herein. This U.S. Government Rights +clause is in lieu of, and supersedes, any other FAR, DFAR, or +other clause or provision that addresses Government rights in +computer software under this License. + +9. MISCELLANEOUS. This License represents the complete agreement +concerning subject matter hereof. If any provision of this +License is held to be unenforceable, such provision shall be +reformed only to the extent necessary to make it enforceable. +This License shall be governed by the law of the jurisdiction +specified in a notice contained within the Original Software +(except to the extent applicable law, if any, provides +otherwise), excluding such jurisdictions conflict-of-law +provisions. Any litigation relating to this License shall be +subject to the jurisdiction of the courts located in the +jurisdiction and venue specified in a notice contained within +the Original Software, with the losing party responsible for +costs, including, without limitation, court costs and reasonable +attorneys fees and expenses. The application of the United +Nations Convention on Contracts for the International Sale of +Goods is expressly excluded. Any law or regulation which +provides that the language of a contract shall be construed +against the drafter shall not apply to this License. You agree +that You alone are responsible for compliance with the United +States export administration regulations (and the export control +laws and regulation of any other countries) when You use, +distribute or otherwise make available any Covered Software. + +10. RESPONSIBILITY FOR CLAIMS. As between Initial Developer and +the Contributors, each party is responsible for claims and +damages arising, directly or indirectly, out of its utilization +of rights under this License and You agree to work with Initial +Developer and Contributors to distribute such responsibility on +an equitable basis. Nothing herein is intended or shall be +deemed to constitute any admission of liability. + +---------------------------------------------------------------- + +NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND +DISTRIBUTION LICENSE (CDDL): This code is released under the +CDDL and shall be governed by the laws of the State of +California (excluding conflict-of-law provisions). Any +litigation relating to this License shall be subject to the +jurisdiction of the Federal Courts of the Northern District of +California and the state courts of the State of California, with +venue lying in Santa Clara County, California. + +---------------------------------------------------------------- + diff --git a/Source/LibRawLite/LICENSE.LGPL b/Source/LibRawLite/LICENSE.LGPL index f95d0f6..3b20440 100644 --- a/Source/LibRawLite/LICENSE.LGPL +++ b/Source/LibRawLite/LICENSE.LGPL @@ -1,458 +1,458 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS diff --git a/Source/LibRawLite/README b/Source/LibRawLite/README index 031f0ad..6f2cd3b 100644 --- a/Source/LibRawLite/README +++ b/Source/LibRawLite/README @@ -1,28 +1,28 @@ -====================== LibRaw ============================== -== Library for reading and processing of RAW digicam images == - -LibRaw is a library for reading RAW files from digital photo cameras -(CRW/CR2, NEF, RAF, DNG, MOS, KDC, DCR, etc, virtually all RAW formats are -supported). - -It pays special attention to correct retrieval of data required for subsequent -RAW conversion. - -The library is intended for embedding in RAW converters, data analyzers, and -other programs using RAW files as the initial data. - -LibRaw library, Copyright (C) 2008-2009 LibRaw LLC (info@libraw.org) -The library includes source code from - - dcraw.c, Dave Coffin's raw photo decoder - Copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net - -LibRaw is distributed for free under three different licenses: - * GNU Lesser General Public License, version 2.1 - * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - * LibRaw Software License - -You may use one of these licensing modes and switch between them. - -If you modify LibRaw source and made your changes public, you should accept -all three licensing modes for your changes/additions. +====================== LibRaw ============================== +== Library for reading and processing of RAW digicam images == + +LibRaw is a library for reading RAW files from digital photo cameras +(CRW/CR2, NEF, RAF, DNG, MOS, KDC, DCR, etc, virtually all RAW formats are +supported). + +It pays special attention to correct retrieval of data required for subsequent +RAW conversion. + +The library is intended for embedding in RAW converters, data analyzers, and +other programs using RAW files as the initial data. + +LibRaw library, Copyright (C) 2008-2009 LibRaw LLC (info@libraw.org) +The library includes source code from + + dcraw.c, Dave Coffin's raw photo decoder + Copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net + +LibRaw is distributed for free under three different licenses: + * GNU Lesser General Public License, version 2.1 + * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + * LibRaw Software License + +You may use one of these licensing modes and switch between them. + +If you modify LibRaw source and made your changes public, you should accept +all three licensing modes for your changes/additions. diff --git a/Source/LibRawLite/README.demosaic-packs b/Source/LibRawLite/README.demosaic-packs index e6385fd..e91d644 100644 --- a/Source/LibRawLite/README.demosaic-packs +++ b/Source/LibRawLite/README.demosaic-packs @@ -1,46 +1,46 @@ -======================= LibRaw demosaic pack(s) =============================== - -There are many good interpolation (demosaic) methods implemented in open-source -world. - -Unfortunately, some of these methods are distributed under the terms of -different versions of GNU General Public License (GPL). So it is not possible -to include implementation of these demosaics into the LibRaw distribution -because LibRaw is distributed under more liberal licenses (LGPL and CDDL). - -Of course, it is possible to distribute these demosaic methods in separate -packages and use within LibRaw under following conditions: - - * LibRaw is used under the terms of LGPL license which is GPL-compatible - * Resulting product (which uses LibRaw AND LibRaw-demosaic-pack) is licensed - under GPL2+ (for GPL2 demosaic-pack) or GPL3+ (if demosaic-pack-GPL3 is used). - -For now demosaic packs are available via GitHub only: - - 1) LibRaw demosaic pack GPL2+ - GitHub URL: git://github.com/LibRaw/LibRaw-demosaic-pack-GPL2.git - - This pack includes these demosaic implementations: - - * AFD and LMMSE implementations from PerfectRaw by Manuel Llorens - * VCD, Modified AHD, post-demosaic refinemend and median - filters by Paul Lee - - 2) LibRaw demosaic pack GPL3+ - GitHub URL: git://github.com/LibRaw/LibRaw-demosaic-pack-GPL3.git - - This pack includes AMaZe interpolation by Emil Martinec. - -== How To Use (developer only!) === - -1. Get LibRaw-0.12... and unpack it in some folder. - -2. Checkout one or both demosaic pack(s) in the same folder (NOT within LibRaw folder). - -3. Check Makefile settings: -CFLAGS_DP1 and CFLAGS_DP2 should point to demosaic pack(s) folder(s) -CFLAGS should have -DLIBRAW_DEMOSAIC_PACK_GPL2/-DLIBRAW_DEMOSAIC_PACK_GPL3 setting - -4. Just run make. - -./configure stuff is not supported with demosaic-pack(s) for now. +======================= LibRaw demosaic pack(s) =============================== + +There are many good interpolation (demosaic) methods implemented in open-source +world. + +Unfortunately, some of these methods are distributed under the terms of +different versions of GNU General Public License (GPL). So it is not possible +to include implementation of these demosaics into the LibRaw distribution +because LibRaw is distributed under more liberal licenses (LGPL and CDDL). + +Of course, it is possible to distribute these demosaic methods in separate +packages and use within LibRaw under following conditions: + + * LibRaw is used under the terms of LGPL license which is GPL-compatible + * Resulting product (which uses LibRaw AND LibRaw-demosaic-pack) is licensed + under GPL2+ (for GPL2 demosaic-pack) or GPL3+ (if demosaic-pack-GPL3 is used). + +For now demosaic packs are available via GitHub only: + + 1) LibRaw demosaic pack GPL2+ + GitHub URL: git://github.com/LibRaw/LibRaw-demosaic-pack-GPL2.git + + This pack includes these demosaic implementations: + + * AFD and LMMSE implementations from PerfectRaw by Manuel Llorens + * VCD, Modified AHD, post-demosaic refinemend and median + filters by Paul Lee + + 2) LibRaw demosaic pack GPL3+ + GitHub URL: git://github.com/LibRaw/LibRaw-demosaic-pack-GPL3.git + + This pack includes AMaZe interpolation by Emil Martinec. + +== How To Use (developer only!) === + +1. Get LibRaw-0.12... and unpack it in some folder. + +2. Checkout one or both demosaic pack(s) in the same folder (NOT within LibRaw folder). + +3. Check Makefile settings: +CFLAGS_DP1 and CFLAGS_DP2 should point to demosaic pack(s) folder(s) +CFLAGS should have -DLIBRAW_DEMOSAIC_PACK_GPL2/-DLIBRAW_DEMOSAIC_PACK_GPL3 setting + +4. Just run make. + +./configure stuff is not supported with demosaic-pack(s) for now. diff --git a/Source/LibRawLite/dcraw/dcraw.c b/Source/LibRawLite/dcraw/dcraw.c index 7f4e8f4..dd0e1f9 100644 --- a/Source/LibRawLite/dcraw/dcraw.c +++ b/Source/LibRawLite/dcraw/dcraw.c @@ -1,9464 +1,9464 @@ -/* - dcraw.c -- Dave Coffin's raw photo decoder - Copyright 1997-2012 by Dave Coffin, dcoffin a cybercom o net - - This is a command-line ANSI C program to convert raw photos from - any digital camera on any computer running any operating system. - - No license is required to download and use dcraw.c. However, - to lawfully redistribute dcraw, you must either (a) offer, at - no extra charge, full source code* for all executable files - containing RESTRICTED functions, (b) distribute this code under - the GPL Version 2 or later, (c) remove all RESTRICTED functions, - re-implement them, or copy them from an earlier, unrestricted - Revision of dcraw.c, or (d) purchase a license from the author. - - The functions that process Foveon images have been RESTRICTED - since Revision 1.237. All other code remains free for all uses. - - *If you have not modified dcraw.c in any way, a link to my - homepage qualifies as "full source code". - - $Revision: 1.31 $ - $Date: 2012/07/15 12:44:06 $ - */ - -#define DCRAW_VERSION "9.15" - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif -#define _USE_MATH_DEFINES -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef NODEPS -#define NO_JASPER -#define NO_JPEG -#define NO_LCMS -#endif -#ifndef NO_JASPER -#include /* Decode RED camera movies */ -#endif -#ifndef NO_JPEG -#include /* Decode compressed Kodak DC120 photos */ -#endif /* and Adobe Lossy DNGs */ -#ifndef NO_LCMS -#include /* Support color profiles */ -#endif -#ifdef LOCALEDIR -#include -#define _(String) gettext(String) -#else -#define _(String) (String) -#endif - -#if defined(DJGPP) || defined(__MINGW32__) -#define fseeko fseek -#define ftello ftell -#else -#define fgetc getc_unlocked -#endif -#ifdef __CYGWIN__ -#include -#endif -#ifdef WIN32 -#include -#include -#pragma comment(lib, "ws2_32.lib") -#define snprintf _snprintf -#define strcasecmp stricmp -#define strncasecmp strnicmp -typedef __int64 INT64; -typedef unsigned __int64 UINT64; -#else -#include -#include -#include -typedef long long INT64; -typedef unsigned long long UINT64; -#endif - -#ifdef LJPEG_DECODE -#error Please compile dcraw.c by itself. -#error Do not link it with ljpeg_decode. -#endif - -#ifndef LONG_BIT -#define LONG_BIT (8 * sizeof (long)) -#endif - -#if !defined(uchar) -#define uchar unsigned char -#endif -#if !defined(ushort) -#define ushort unsigned short -#endif - -/* - All global variables are defined here, and all functions that - access them are prefixed with "CLASS". Note that a thread-safe - C++ class cannot have non-const static local variables. - */ -FILE *ifp, *ofp; -short order; -const char *ifname; -char *meta_data; -char cdesc[5], desc[512], make[64], model[64], model2[64], artist[64]; -float flash_used, canon_ev, iso_speed, shutter, aperture, focal_len; -time_t timestamp; -unsigned shot_order, kodak_cbpp, filters, exif_cfa, unique_id; -off_t strip_offset, data_offset; -off_t thumb_offset, meta_offset, profile_offset; -unsigned thumb_length, meta_length, profile_length; -unsigned thumb_misc, *oprof, fuji_layout, shot_select=0, multi_out=0; -unsigned tiff_nifds, tiff_samples, tiff_bps, tiff_compress; -unsigned black, cblack[4], maximum, mix_green, raw_color, zero_is_bad; -unsigned zero_after_ff, is_raw, dng_version, is_foveon, data_error; -unsigned tile_width, tile_length, gpsdata[32], load_flags; -ushort raw_height, raw_width, height, width, top_margin, left_margin; -ushort shrink, iheight, iwidth, fuji_width, thumb_width, thumb_height; -ushort *raw_image, (*image)[4]; -ushort white[8][8], curve[0x10000], cr2_slice[3], sraw_mul[4]; -int mask[8][4], flip, tiff_flip, colors; -double pixel_aspect, aber[4]={1,1,1,1}, gamm[6]={ 0.45,4.5,0,0,0,0 }; -float bright=1, user_mul[4]={0,0,0,0}, threshold=0; -int half_size=0, four_color_rgb=0, document_mode=0, highlight=0; -int verbose=0, use_auto_wb=0, use_camera_wb=0, use_camera_matrix=-1; -int output_color=1, output_bps=8, output_tiff=0, med_passes=0; -int no_auto_bright=0; -unsigned greybox[4] = { 0, 0, UINT_MAX, UINT_MAX }; -float cam_mul[4], pre_mul[4], cmatrix[3][4], rgb_cam[3][4]; -const double xyz_rgb[3][3] = { /* XYZ from RGB */ - { 0.412453, 0.357580, 0.180423 }, - { 0.212671, 0.715160, 0.072169 }, - { 0.019334, 0.119193, 0.950227 } }; -const float d65_white[3] = { 0.950456, 1, 1.088754 }; -int histogram[4][0x2000]; -void (*write_thumb)(), (*write_fun)(); -void (*load_raw)(), (*thumb_load_raw)(); -jmp_buf failure; - -struct decode { - struct decode *branch[2]; - int leaf; -} first_decode[2048], *second_decode, *free_decode; - -struct tiff_ifd { - int width, height, bps, comp, phint, offset, flip, samples, bytes; - int tile_width, tile_length; -} tiff_ifd[10]; - -struct ph1 { - int format, key_off, black, black_off, split_col, tag_21a; - float tag_210; -} ph1; - -#define CLASS - -#define FORC(cnt) for (c=0; c < cnt; c++) -#define FORC3 FORC(3) -#define FORC4 FORC(4) -#define FORCC FORC(colors) - -#define SQR(x) ((x)*(x)) -#define ABS(x) (((int)(x) ^ ((int)(x) >> 31)) - ((int)(x) >> 31)) -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) > (b) ? (a) : (b)) -#define LIM(x,min,max) MAX(min,MIN(x,max)) -#define ULIM(x,y,z) ((y) < (z) ? LIM(x,y,z) : LIM(x,z,y)) -#define CLIP(x) LIM(x,0,65535) -#define SWAP(a,b) { a=a+b; b=a-b; a=a-b; } - -/* - In order to inline this calculation, I make the risky - assumption that all filter patterns can be described - by a repeating pattern of eight rows and two columns - - Do not use the FC or BAYER macros with the Leaf CatchLight, - because its pattern is 16x16, not 2x8. - - Return values are either 0/1/2/3 = G/M/C/Y or 0/1/2/3 = R/G1/B/G2 - - PowerShot 600 PowerShot A50 PowerShot Pro70 Pro90 & G1 - 0xe1e4e1e4: 0x1b4e4b1e: 0x1e4b4e1b: 0xb4b4b4b4: - - 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 - 0 G M G M G M 0 C Y C Y C Y 0 Y C Y C Y C 0 G M G M G M - 1 C Y C Y C Y 1 M G M G M G 1 M G M G M G 1 Y C Y C Y C - 2 M G M G M G 2 Y C Y C Y C 2 C Y C Y C Y - 3 C Y C Y C Y 3 G M G M G M 3 G M G M G M - 4 C Y C Y C Y 4 Y C Y C Y C - PowerShot A5 5 G M G M G M 5 G M G M G M - 0x1e4e1e4e: 6 Y C Y C Y C 6 C Y C Y C Y - 7 M G M G M G 7 M G M G M G - 0 1 2 3 4 5 - 0 C Y C Y C Y - 1 G M G M G M - 2 C Y C Y C Y - 3 M G M G M G - - All RGB cameras use one of these Bayer grids: - - 0x16161616: 0x61616161: 0x49494949: 0x94949494: - - 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 - 0 B G B G B G 0 G R G R G R 0 G B G B G B 0 R G R G R G - 1 G R G R G R 1 B G B G B G 1 R G R G R G 1 G B G B G B - 2 B G B G B G 2 G R G R G R 2 G B G B G B 2 R G R G R G - 3 G R G R G R 3 B G B G B G 3 R G R G R G 3 G B G B G B - */ - -#define RAW(row,col) \ - raw_image[(row)*raw_width+(col)] - -#define FC(row,col) \ - (filters >> ((((row) << 1 & 14) + ((col) & 1)) << 1) & 3) - -#define BAYER(row,col) \ - image[((row) >> shrink)*iwidth + ((col) >> shrink)][FC(row,col)] - -#define BAYER2(row,col) \ - image[((row) >> shrink)*iwidth + ((col) >> shrink)][fcol(row,col)] - -int CLASS fcol (int row, int col) -{ - static const char filter[16][16] = - { { 2,1,1,3,2,3,2,0,3,2,3,0,1,2,1,0 }, - { 0,3,0,2,0,1,3,1,0,1,1,2,0,3,3,2 }, - { 2,3,3,2,3,1,1,3,3,1,2,1,2,0,0,3 }, - { 0,1,0,1,0,2,0,2,2,0,3,0,1,3,2,1 }, - { 3,1,1,2,0,1,0,2,1,3,1,3,0,1,3,0 }, - { 2,0,0,3,3,2,3,1,2,0,2,0,3,2,2,1 }, - { 2,3,3,1,2,1,2,1,2,1,1,2,3,0,0,1 }, - { 1,0,0,2,3,0,0,3,0,3,0,3,2,1,2,3 }, - { 2,3,3,1,1,2,1,0,3,2,3,0,2,3,1,3 }, - { 1,0,2,0,3,0,3,2,0,1,1,2,0,1,0,2 }, - { 0,1,1,3,3,2,2,1,1,3,3,0,2,1,3,2 }, - { 2,3,2,0,0,1,3,0,2,0,1,2,3,0,1,0 }, - { 1,3,1,2,3,2,3,2,0,2,0,1,1,0,3,0 }, - { 0,2,0,3,1,0,0,1,1,3,3,2,3,2,2,1 }, - { 2,1,3,2,3,1,2,1,0,3,0,2,0,2,0,2 }, - { 0,3,1,0,0,2,0,3,2,1,3,1,1,3,1,3 } }; - static const char filter2[6][6] = - { { 1,1,0,1,1,2 }, - { 1,1,2,1,1,0 }, - { 2,0,1,0,2,1 }, - { 1,1,2,1,1,0 }, - { 1,1,0,1,1,2 }, - { 0,2,1,2,0,1 } }; - - if (filters == 1) return filter[(row+top_margin)&15][(col+left_margin)&15]; - if (filters == 2) return filter2[(row+6) % 6][(col+6) % 6]; - return FC(row,col); -} - -#ifndef __GLIBC__ -char *my_memmem (char *haystack, size_t haystacklen, - char *needle, size_t needlelen) -{ - char *c; - for (c = haystack; c <= haystack + haystacklen - needlelen; c++) - if (!memcmp (c, needle, needlelen)) - return c; - return 0; -} -#define memmem my_memmem -#endif - -void CLASS merror (void *ptr, const char *where) -{ - if (ptr) return; - fprintf (stderr,_("%s: Out of memory in %s\n"), ifname, where); - longjmp (failure, 1); -} - -void CLASS derror() -{ - if (!data_error) { - fprintf (stderr, "%s: ", ifname); - if (feof(ifp)) - fprintf (stderr,_("Unexpected end of file\n")); - else - fprintf (stderr,_("Corrupt data near 0x%llx\n"), (INT64) ftello(ifp)); - } - data_error++; -} - -ushort CLASS sget2 (uchar *s) -{ - if (order == 0x4949) /* "II" means little-endian */ - return s[0] | s[1] << 8; - else /* "MM" means big-endian */ - return s[0] << 8 | s[1]; -} - -ushort CLASS get2() -{ - uchar str[2] = { 0xff,0xff }; - fread (str, 1, 2, ifp); - return sget2(str); -} - -unsigned CLASS sget4 (uchar *s) -{ - if (order == 0x4949) - return s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24; - else - return s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]; -} -#define sget4(s) sget4((uchar *)s) - -unsigned CLASS get4() -{ - uchar str[4] = { 0xff,0xff,0xff,0xff }; - fread (str, 1, 4, ifp); - return sget4(str); -} - -unsigned CLASS getint (int type) -{ - return type == 3 ? get2() : get4(); -} - -float CLASS int_to_float (int i) -{ - union { int i; float f; } u; - u.i = i; - return u.f; -} - -double CLASS getreal (int type) -{ - union { char c[8]; double d; } u; - int i, rev; - - switch (type) { - case 3: return (unsigned short) get2(); - case 4: return (unsigned int) get4(); - case 5: u.d = (unsigned int) get4(); - return u.d / (unsigned int) get4(); - case 8: return (signed short) get2(); - case 9: return (signed int) get4(); - case 10: u.d = (signed int) get4(); - return u.d / (signed int) get4(); - case 11: return int_to_float (get4()); - case 12: - rev = 7 * ((order == 0x4949) == (ntohs(0x1234) == 0x1234)); - for (i=0; i < 8; i++) - u.c[i ^ rev] = fgetc(ifp); - return u.d; - default: return fgetc(ifp); - } -} - -void CLASS read_shorts (ushort *pixel, int count) -{ - if (fread (pixel, 2, count, ifp) < count) derror(); - if ((order == 0x4949) == (ntohs(0x1234) == 0x1234)) - swab (pixel, pixel, count*2); -} - -void CLASS canon_600_fixed_wb (int temp) -{ - static const short mul[4][5] = { - { 667, 358,397,565,452 }, - { 731, 390,367,499,517 }, - { 1119, 396,348,448,537 }, - { 1399, 485,431,508,688 } }; - int lo, hi, i; - float frac=0; - - for (lo=4; --lo; ) - if (*mul[lo] <= temp) break; - for (hi=0; hi < 3; hi++) - if (*mul[hi] >= temp) break; - if (lo != hi) - frac = (float) (temp - *mul[lo]) / (*mul[hi] - *mul[lo]); - for (i=1; i < 5; i++) - pre_mul[i-1] = 1 / (frac * mul[hi][i] + (1-frac) * mul[lo][i]); -} - -/* Return values: 0 = white 1 = near white 2 = not white */ -int CLASS canon_600_color (int ratio[2], int mar) -{ - int clipped=0, target, miss; - - if (flash_used) { - if (ratio[1] < -104) - { ratio[1] = -104; clipped = 1; } - if (ratio[1] > 12) - { ratio[1] = 12; clipped = 1; } - } else { - if (ratio[1] < -264 || ratio[1] > 461) return 2; - if (ratio[1] < -50) - { ratio[1] = -50; clipped = 1; } - if (ratio[1] > 307) - { ratio[1] = 307; clipped = 1; } - } - target = flash_used || ratio[1] < 197 - ? -38 - (398 * ratio[1] >> 10) - : -123 + (48 * ratio[1] >> 10); - if (target - mar <= ratio[0] && - target + 20 >= ratio[0] && !clipped) return 0; - miss = target - ratio[0]; - if (abs(miss) >= mar*4) return 2; - if (miss < -20) miss = -20; - if (miss > mar) miss = mar; - ratio[0] = target - miss; - return 1; -} - -void CLASS canon_600_auto_wb() -{ - int mar, row, col, i, j, st, count[] = { 0,0 }; - int test[8], total[2][8], ratio[2][2], stat[2]; - - memset (&total, 0, sizeof total); - i = canon_ev + 0.5; - if (i < 10) mar = 150; - else if (i > 12) mar = 20; - else mar = 280 - 20 * i; - if (flash_used) mar = 80; - for (row=14; row < height-14; row+=4) - for (col=10; col < width; col+=2) { - for (i=0; i < 8; i++) - test[(i & 4) + FC(row+(i >> 1),col+(i & 1))] = - BAYER(row+(i >> 1),col+(i & 1)); - for (i=0; i < 8; i++) - if (test[i] < 150 || test[i] > 1500) goto next; - for (i=0; i < 4; i++) - if (abs(test[i] - test[i+4]) > 50) goto next; - for (i=0; i < 2; i++) { - for (j=0; j < 4; j+=2) - ratio[i][j >> 1] = ((test[i*4+j+1]-test[i*4+j]) << 10) / test[i*4+j]; - stat[i] = canon_600_color (ratio[i], mar); - } - if ((st = stat[0] | stat[1]) > 1) goto next; - for (i=0; i < 2; i++) - if (stat[i]) - for (j=0; j < 2; j++) - test[i*4+j*2+1] = test[i*4+j*2] * (0x400 + ratio[i][j]) >> 10; - for (i=0; i < 8; i++) - total[st][i] += test[i]; - count[st]++; -next: ; - } - if (count[0] | count[1]) { - st = count[0]*200 < count[1]; - for (i=0; i < 4; i++) - pre_mul[i] = 1.0 / (total[st][i] + total[st][i+4]); - } -} - -void CLASS canon_600_coeff() -{ - static const short table[6][12] = { - { -190,702,-1878,2390, 1861,-1349,905,-393, -432,944,2617,-2105 }, - { -1203,1715,-1136,1648, 1388,-876,267,245, -1641,2153,3921,-3409 }, - { -615,1127,-1563,2075, 1437,-925,509,3, -756,1268,2519,-2007 }, - { -190,702,-1886,2398, 2153,-1641,763,-251, -452,964,3040,-2528 }, - { -190,702,-1878,2390, 1861,-1349,905,-393, -432,944,2617,-2105 }, - { -807,1319,-1785,2297, 1388,-876,769,-257, -230,742,2067,-1555 } }; - int t=0, i, c; - float mc, yc; - - mc = pre_mul[1] / pre_mul[2]; - yc = pre_mul[3] / pre_mul[2]; - if (mc > 1 && mc <= 1.28 && yc < 0.8789) t=1; - if (mc > 1.28 && mc <= 2) { - if (yc < 0.8789) t=3; - else if (yc <= 2) t=4; - } - if (flash_used) t=5; - for (raw_color = i=0; i < 3; i++) - FORCC rgb_cam[i][c] = table[t][i*4 + c] / 1024.0; -} - -void CLASS canon_600_load_raw() -{ - uchar data[1120], *dp; - ushort *pix; - int irow, row; - - for (irow=row=0; irow < height; irow++) { - if (fread (data, 1, 1120, ifp) < 1120) derror(); - pix = raw_image + row*raw_width; - for (dp=data; dp < data+1120; dp+=10, pix+=8) { - pix[0] = (dp[0] << 2) + (dp[1] >> 6 ); - pix[1] = (dp[2] << 2) + (dp[1] >> 4 & 3); - pix[2] = (dp[3] << 2) + (dp[1] >> 2 & 3); - pix[3] = (dp[4] << 2) + (dp[1] & 3); - pix[4] = (dp[5] << 2) + (dp[9] & 3); - pix[5] = (dp[6] << 2) + (dp[9] >> 2 & 3); - pix[6] = (dp[7] << 2) + (dp[9] >> 4 & 3); - pix[7] = (dp[8] << 2) + (dp[9] >> 6 ); - } - if ((row+=2) > height) row = 1; - } -} - -void CLASS canon_600_correct() -{ - int row, col, val; - static const short mul[4][2] = - { { 1141,1145 }, { 1128,1109 }, { 1178,1149 }, { 1128,1109 } }; - - for (row=0; row < height; row++) - for (col=0; col < width; col++) { - if ((val = BAYER(row,col) - black) < 0) val = 0; - val = val * mul[row & 3][col & 1] >> 9; - BAYER(row,col) = val; - } - canon_600_fixed_wb(1311); - canon_600_auto_wb(); - canon_600_coeff(); - maximum = (0x3ff - black) * 1109 >> 9; - black = 0; -} - -int CLASS canon_s2is() -{ - unsigned row; - - for (row=0; row < 100; row++) { - fseek (ifp, row*3340 + 3284, SEEK_SET); - if (getc(ifp) > 15) return 1; - } - return 0; -} - -/* - getbits(-1) initializes the buffer - getbits(n) where 0 <= n <= 25 returns an n-bit integer - */ -unsigned CLASS getbithuff (int nbits, ushort *huff) -{ - static unsigned bitbuf=0; - static int vbits=0, reset=0; - unsigned c; - - if (nbits == -1) - return bitbuf = vbits = reset = 0; - if (nbits == 0 || vbits < 0) return 0; - while (!reset && vbits < nbits && (c = fgetc(ifp)) != EOF && - !(reset = zero_after_ff && c == 0xff && fgetc(ifp))) { - bitbuf = (bitbuf << 8) + (uchar) c; - vbits += 8; - } - c = bitbuf << (32-vbits) >> (32-nbits); - if (huff) { - vbits -= huff[c] >> 8; - c = (uchar) huff[c]; - } else - vbits -= nbits; - if (vbits < 0) derror(); - return c; -} - -#define getbits(n) getbithuff(n,0) -#define gethuff(h) getbithuff(*h,h+1) - -/* - Construct a decode tree according the specification in *source. - The first 16 bytes specify how many codes should be 1-bit, 2-bit - 3-bit, etc. Bytes after that are the leaf values. - - For example, if the source is - - { 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0, - 0x04,0x03,0x05,0x06,0x02,0x07,0x01,0x08,0x09,0x00,0x0a,0x0b,0xff }, - - then the code is - - 00 0x04 - 010 0x03 - 011 0x05 - 100 0x06 - 101 0x02 - 1100 0x07 - 1101 0x01 - 11100 0x08 - 11101 0x09 - 11110 0x00 - 111110 0x0a - 1111110 0x0b - 1111111 0xff - */ -ushort * CLASS make_decoder_ref (const uchar **source) -{ - int max, len, h, i, j; - const uchar *count; - ushort *huff; - - count = (*source += 16) - 17; - for (max=16; max && !count[max]; max--); - huff = (ushort *) calloc (1 + (1 << max), sizeof *huff); - merror (huff, "make_decoder()"); - huff[0] = max; - for (h=len=1; len <= max; len++) - for (i=0; i < count[len]; i++, ++*source) - for (j=0; j < 1 << (max-len); j++) - if (h <= 1 << max) - huff[h++] = len << 8 | **source; - return huff; -} - -ushort * CLASS make_decoder (const uchar *source) -{ - return make_decoder_ref (&source); -} - -void CLASS crw_init_tables (unsigned table, ushort *huff[2]) -{ - static const uchar first_tree[3][29] = { - { 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0, - 0x04,0x03,0x05,0x06,0x02,0x07,0x01,0x08,0x09,0x00,0x0a,0x0b,0xff }, - { 0,2,2,3,1,1,1,1,2,0,0,0,0,0,0,0, - 0x03,0x02,0x04,0x01,0x05,0x00,0x06,0x07,0x09,0x08,0x0a,0x0b,0xff }, - { 0,0,6,3,1,1,2,0,0,0,0,0,0,0,0,0, - 0x06,0x05,0x07,0x04,0x08,0x03,0x09,0x02,0x00,0x0a,0x01,0x0b,0xff }, - }; - static const uchar second_tree[3][180] = { - { 0,2,2,2,1,4,2,1,2,5,1,1,0,0,0,139, - 0x03,0x04,0x02,0x05,0x01,0x06,0x07,0x08, - 0x12,0x13,0x11,0x14,0x09,0x15,0x22,0x00,0x21,0x16,0x0a,0xf0, - 0x23,0x17,0x24,0x31,0x32,0x18,0x19,0x33,0x25,0x41,0x34,0x42, - 0x35,0x51,0x36,0x37,0x38,0x29,0x79,0x26,0x1a,0x39,0x56,0x57, - 0x28,0x27,0x52,0x55,0x58,0x43,0x76,0x59,0x77,0x54,0x61,0xf9, - 0x71,0x78,0x75,0x96,0x97,0x49,0xb7,0x53,0xd7,0x74,0xb6,0x98, - 0x47,0x48,0x95,0x69,0x99,0x91,0xfa,0xb8,0x68,0xb5,0xb9,0xd6, - 0xf7,0xd8,0x67,0x46,0x45,0x94,0x89,0xf8,0x81,0xd5,0xf6,0xb4, - 0x88,0xb1,0x2a,0x44,0x72,0xd9,0x87,0x66,0xd4,0xf5,0x3a,0xa7, - 0x73,0xa9,0xa8,0x86,0x62,0xc7,0x65,0xc8,0xc9,0xa1,0xf4,0xd1, - 0xe9,0x5a,0x92,0x85,0xa6,0xe7,0x93,0xe8,0xc1,0xc6,0x7a,0x64, - 0xe1,0x4a,0x6a,0xe6,0xb3,0xf1,0xd3,0xa5,0x8a,0xb2,0x9a,0xba, - 0x84,0xa4,0x63,0xe5,0xc5,0xf3,0xd2,0xc4,0x82,0xaa,0xda,0xe4, - 0xf2,0xca,0x83,0xa3,0xa2,0xc3,0xea,0xc2,0xe2,0xe3,0xff,0xff }, - { 0,2,2,1,4,1,4,1,3,3,1,0,0,0,0,140, - 0x02,0x03,0x01,0x04,0x05,0x12,0x11,0x06, - 0x13,0x07,0x08,0x14,0x22,0x09,0x21,0x00,0x23,0x15,0x31,0x32, - 0x0a,0x16,0xf0,0x24,0x33,0x41,0x42,0x19,0x17,0x25,0x18,0x51, - 0x34,0x43,0x52,0x29,0x35,0x61,0x39,0x71,0x62,0x36,0x53,0x26, - 0x38,0x1a,0x37,0x81,0x27,0x91,0x79,0x55,0x45,0x28,0x72,0x59, - 0xa1,0xb1,0x44,0x69,0x54,0x58,0xd1,0xfa,0x57,0xe1,0xf1,0xb9, - 0x49,0x47,0x63,0x6a,0xf9,0x56,0x46,0xa8,0x2a,0x4a,0x78,0x99, - 0x3a,0x75,0x74,0x86,0x65,0xc1,0x76,0xb6,0x96,0xd6,0x89,0x85, - 0xc9,0xf5,0x95,0xb4,0xc7,0xf7,0x8a,0x97,0xb8,0x73,0xb7,0xd8, - 0xd9,0x87,0xa7,0x7a,0x48,0x82,0x84,0xea,0xf4,0xa6,0xc5,0x5a, - 0x94,0xa4,0xc6,0x92,0xc3,0x68,0xb5,0xc8,0xe4,0xe5,0xe6,0xe9, - 0xa2,0xa3,0xe3,0xc2,0x66,0x67,0x93,0xaa,0xd4,0xd5,0xe7,0xf8, - 0x88,0x9a,0xd7,0x77,0xc4,0x64,0xe2,0x98,0xa5,0xca,0xda,0xe8, - 0xf3,0xf6,0xa9,0xb2,0xb3,0xf2,0xd2,0x83,0xba,0xd3,0xff,0xff }, - { 0,0,6,2,1,3,3,2,5,1,2,2,8,10,0,117, - 0x04,0x05,0x03,0x06,0x02,0x07,0x01,0x08, - 0x09,0x12,0x13,0x14,0x11,0x15,0x0a,0x16,0x17,0xf0,0x00,0x22, - 0x21,0x18,0x23,0x19,0x24,0x32,0x31,0x25,0x33,0x38,0x37,0x34, - 0x35,0x36,0x39,0x79,0x57,0x58,0x59,0x28,0x56,0x78,0x27,0x41, - 0x29,0x77,0x26,0x42,0x76,0x99,0x1a,0x55,0x98,0x97,0xf9,0x48, - 0x54,0x96,0x89,0x47,0xb7,0x49,0xfa,0x75,0x68,0xb6,0x67,0x69, - 0xb9,0xb8,0xd8,0x52,0xd7,0x88,0xb5,0x74,0x51,0x46,0xd9,0xf8, - 0x3a,0xd6,0x87,0x45,0x7a,0x95,0xd5,0xf6,0x86,0xb4,0xa9,0x94, - 0x53,0x2a,0xa8,0x43,0xf5,0xf7,0xd4,0x66,0xa7,0x5a,0x44,0x8a, - 0xc9,0xe8,0xc8,0xe7,0x9a,0x6a,0x73,0x4a,0x61,0xc7,0xf4,0xc6, - 0x65,0xe9,0x72,0xe6,0x71,0x91,0x93,0xa6,0xda,0x92,0x85,0x62, - 0xf3,0xc5,0xb2,0xa4,0x84,0xba,0x64,0xa5,0xb3,0xd2,0x81,0xe5, - 0xd3,0xaa,0xc4,0xca,0xf2,0xb1,0xe4,0xd1,0x83,0x63,0xea,0xc3, - 0xe2,0x82,0xf1,0xa3,0xc2,0xa1,0xc1,0xe3,0xa2,0xe1,0xff,0xff } - }; - if (table > 2) table = 2; - huff[0] = make_decoder ( first_tree[table]); - huff[1] = make_decoder (second_tree[table]); -} - -/* - Return 0 if the image starts with compressed data, - 1 if it starts with uncompressed low-order bits. - - In Canon compressed data, 0xff is always followed by 0x00. - */ -int CLASS canon_has_lowbits() -{ - uchar test[0x4000]; - int ret=1, i; - - fseek (ifp, 0, SEEK_SET); - fread (test, 1, sizeof test, ifp); - for (i=540; i < sizeof test - 1; i++) - if (test[i] == 0xff) { - if (test[i+1]) return 1; - ret=0; - } - return ret; -} - -void CLASS canon_load_raw() -{ - ushort *pixel, *prow, *huff[2]; - int nblocks, lowbits, i, c, row, r, save, val; - int block, diffbuf[64], leaf, len, diff, carry=0, pnum=0, base[2]; - - crw_init_tables (tiff_compress, huff); - lowbits = canon_has_lowbits(); - if (!lowbits) maximum = 0x3ff; - fseek (ifp, 540 + lowbits*raw_height*raw_width/4, SEEK_SET); - zero_after_ff = 1; - getbits(-1); - for (row=0; row < raw_height; row+=8) { - pixel = raw_image + row*raw_width; - nblocks = MIN (8, raw_height-row) * raw_width >> 6; - for (block=0; block < nblocks; block++) { - memset (diffbuf, 0, sizeof diffbuf); - for (i=0; i < 64; i++ ) { - leaf = gethuff(huff[i > 0]); - if (leaf == 0 && i) break; - if (leaf == 0xff) continue; - i += leaf >> 4; - len = leaf & 15; - if (len == 0) continue; - diff = getbits(len); - if ((diff & (1 << (len-1))) == 0) - diff -= (1 << len) - 1; - if (i < 64) diffbuf[i] = diff; - } - diffbuf[0] += carry; - carry = diffbuf[0]; - for (i=0; i < 64; i++ ) { - if (pnum++ % raw_width == 0) - base[0] = base[1] = 512; - if ((pixel[(block << 6) + i] = base[i & 1] += diffbuf[i]) >> 10) - derror(); - } - } - if (lowbits) { - save = ftell(ifp); - fseek (ifp, 26 + row*raw_width/4, SEEK_SET); - for (prow=pixel, i=0; i < raw_width*2; i++) { - c = fgetc(ifp); - for (r=0; r < 8; r+=2, prow++) { - val = (*prow << 2) + ((c >> r) & 3); - if (raw_width == 2672 && val < 512) val += 2; - *prow = val; - } - } - fseek (ifp, save, SEEK_SET); - } - } - FORC(2) free (huff[c]); -} - -/* - Not a full implementation of Lossless JPEG, just - enough to decode Canon, Kodak and Adobe DNG images. - */ -struct jhead { - int bits, high, wide, clrs, sraw, psv, restart, vpred[6]; - ushort *huff[6], *free[4], *row; -}; - -int CLASS ljpeg_start (struct jhead *jh, int info_only) -{ - int c, tag, len; - uchar data[0x10000]; - const uchar *dp; - - memset (jh, 0, sizeof *jh); - jh->restart = INT_MAX; - fread (data, 2, 1, ifp); - if (data[1] != 0xd8) return 0; - do { - fread (data, 2, 2, ifp); - tag = data[0] << 8 | data[1]; - len = (data[2] << 8 | data[3]) - 2; - if (tag <= 0xff00) return 0; - fread (data, 1, len, ifp); - switch (tag) { - case 0xffc3: - jh->sraw = ((data[7] >> 4) * (data[7] & 15) - 1) & 3; - case 0xffc0: - jh->bits = data[0]; - jh->high = data[1] << 8 | data[2]; - jh->wide = data[3] << 8 | data[4]; - jh->clrs = data[5] + jh->sraw; - if (len == 9 && !dng_version) getc(ifp); - break; - case 0xffc4: - if (info_only) break; - for (dp = data; dp < data+len && (c = *dp++) < 4; ) - jh->free[c] = jh->huff[c] = make_decoder_ref (&dp); - break; - case 0xffda: - jh->psv = data[1+data[0]*2]; - jh->bits -= data[3+data[0]*2] & 15; - break; - case 0xffdd: - jh->restart = data[0] << 8 | data[1]; - } - } while (tag != 0xffda); - if (info_only) return 1; - FORC(5) if (!jh->huff[c+1]) jh->huff[c+1] = jh->huff[c]; - if (jh->sraw) { - FORC(4) jh->huff[2+c] = jh->huff[1]; - FORC(jh->sraw) jh->huff[1+c] = jh->huff[0]; - } - jh->row = (ushort *) calloc (jh->wide*jh->clrs, 4); - merror (jh->row, "ljpeg_start()"); - return zero_after_ff = 1; -} - -void CLASS ljpeg_end (struct jhead *jh) -{ - int c; - FORC4 if (jh->free[c]) free (jh->free[c]); - free (jh->row); -} - -int CLASS ljpeg_diff (ushort *huff) -{ - int len, diff; - - len = gethuff(huff); - if (len == 16 && (!dng_version || dng_version >= 0x1010000)) - return -32768; - diff = getbits(len); - if ((diff & (1 << (len-1))) == 0) - diff -= (1 << len) - 1; - return diff; -} - -ushort * CLASS ljpeg_row (int jrow, struct jhead *jh) -{ - int col, c, diff, pred, spred=0; - ushort mark=0, *row[3]; - - if (jrow * jh->wide % jh->restart == 0) { - FORC(6) jh->vpred[c] = 1 << (jh->bits-1); - if (jrow) { - fseek (ifp, -2, SEEK_CUR); - do mark = (mark << 8) + (c = fgetc(ifp)); - while (c != EOF && mark >> 4 != 0xffd); - } - getbits(-1); - } - FORC3 row[c] = jh->row + jh->wide*jh->clrs*((jrow+c) & 1); - for (col=0; col < jh->wide; col++) - FORC(jh->clrs) { - diff = ljpeg_diff (jh->huff[c]); - if (jh->sraw && c <= jh->sraw && (col | c)) - pred = spred; - else if (col) pred = row[0][-jh->clrs]; - else pred = (jh->vpred[c] += diff) - diff; - if (jrow && col) switch (jh->psv) { - case 1: break; - case 2: pred = row[1][0]; break; - case 3: pred = row[1][-jh->clrs]; break; - case 4: pred = pred + row[1][0] - row[1][-jh->clrs]; break; - case 5: pred = pred + ((row[1][0] - row[1][-jh->clrs]) >> 1); break; - case 6: pred = row[1][0] + ((pred - row[1][-jh->clrs]) >> 1); break; - case 7: pred = (pred + row[1][0]) >> 1; break; - default: pred = 0; - } - if ((**row = pred + diff) >> jh->bits) derror(); - if (c <= jh->sraw) spred = **row; - row[0]++; row[1]++; - } - return row[2]; -} - -void CLASS lossless_jpeg_load_raw() -{ - int jwide, jrow, jcol, val, jidx, i, j, row=0, col=0; - struct jhead jh; - ushort *rp; - - if (!ljpeg_start (&jh, 0)) return; - jwide = jh.wide * jh.clrs; - - for (jrow=0; jrow < jh.high; jrow++) { - rp = ljpeg_row (jrow, &jh); - if (load_flags & 1) - row = jrow & 1 ? height-1-jrow/2 : jrow/2; - for (jcol=0; jcol < jwide; jcol++) { - val = curve[*rp++]; - if (cr2_slice[0]) { - jidx = jrow*jwide + jcol; - i = jidx / (cr2_slice[1]*jh.high); - if ((j = i >= cr2_slice[0])) - i = cr2_slice[0]; - jidx -= i * (cr2_slice[1]*jh.high); - row = jidx / cr2_slice[1+j]; - col = jidx % cr2_slice[1+j] + i*cr2_slice[1]; - } - if (raw_width == 3984 && (col -= 2) < 0) - col += (row--,raw_width); - if (row >= 0) RAW(row,col) = val; - if (++col >= raw_width) - col = (row++,0); - } - } - ljpeg_end (&jh); -} - -void CLASS canon_sraw_load_raw() -{ - struct jhead jh; - short *rp=0, (*ip)[4]; - int jwide, slice, scol, ecol, row, col, jrow=0, jcol=0, pix[3], c; - int v[3]={0,0,0}, ver, hue; - char *cp; - - if (!ljpeg_start (&jh, 0)) return; - jwide = (jh.wide >>= 1) * jh.clrs; - - for (ecol=slice=0; slice <= cr2_slice[0]; slice++) { - scol = ecol; - ecol += cr2_slice[1] * 2 / jh.clrs; - if (!cr2_slice[0] || ecol > raw_width-1) ecol = raw_width & -2; - for (row=0; row < height; row += (jh.clrs >> 1) - 1) { - ip = (short (*)[4]) image + row*width; - for (col=scol; col < ecol; col+=2, jcol+=jh.clrs) { - if ((jcol %= jwide) == 0) - rp = (short *) ljpeg_row (jrow++, &jh); - if (col >= width) continue; - FORC (jh.clrs-2) - ip[col + (c >> 1)*width + (c & 1)][0] = rp[jcol+c]; - ip[col][1] = rp[jcol+jh.clrs-2] - 16384; - ip[col][2] = rp[jcol+jh.clrs-1] - 16384; - } - } - } - for (cp=model2; *cp && !isdigit(*cp); cp++); - sscanf (cp, "%d.%d.%d", v, v+1, v+2); - ver = (v[0]*1000 + v[1])*1000 + v[2]; - hue = (jh.sraw+1) << 2; - if (unique_id >= 0x80000281 || (unique_id == 0x80000218 && ver > 1000006)) - hue = jh.sraw << 1; - ip = (short (*)[4]) image; - rp = ip[0]; - for (row=0; row < height; row++, ip+=width) { - if (row & (jh.sraw >> 1)) - for (col=0; col < width; col+=2) - for (c=1; c < 3; c++) - if (row == height-1) - ip[col][c] = ip[col-width][c]; - else ip[col][c] = (ip[col-width][c] + ip[col+width][c] + 1) >> 1; - for (col=1; col < width; col+=2) - for (c=1; c < 3; c++) - if (col == width-1) - ip[col][c] = ip[col-1][c]; - else ip[col][c] = (ip[col-1][c] + ip[col+1][c] + 1) >> 1; - } - for ( ; rp < ip[0]; rp+=4) { - if (unique_id < 0x80000218) { - rp[0] -= 512; - goto next; - } else if (unique_id == 0x80000285) { -next: pix[0] = rp[0] + rp[2]; - pix[2] = rp[0] + rp[1]; - pix[1] = rp[0] + ((-778*rp[1] - (rp[2] << 11)) >> 12); - } else { - rp[1] = (rp[1] << 2) + hue; - rp[2] = (rp[2] << 2) + hue; - pix[0] = rp[0] + (( 50*rp[1] + 22929*rp[2]) >> 14); - pix[1] = rp[0] + ((-5640*rp[1] - 11751*rp[2]) >> 14); - pix[2] = rp[0] + ((29040*rp[1] - 101*rp[2]) >> 14); - } - FORC3 rp[c] = CLIP(pix[c] * sraw_mul[c] >> 10); - } - ljpeg_end (&jh); - maximum = 0x3fff; -} - -void CLASS adobe_copy_pixel (unsigned row, unsigned col, ushort **rp) -{ - int c; - - if (is_raw == 2 && shot_select) (*rp)++; - if (raw_image) { - if (row < raw_height && col < raw_width) - RAW(row,col) = curve[**rp]; - *rp += is_raw; - } else { - if (row < height && col < width) - FORC(tiff_samples) - image[row*width+col][c] = curve[(*rp)[c]]; - *rp += tiff_samples; - } - if (is_raw == 2 && shot_select) (*rp)--; -} - -void CLASS lossless_dng_load_raw() -{ - unsigned save, trow=0, tcol=0, jwide, jrow, jcol, row, col; - struct jhead jh; - ushort *rp; - - while (trow < raw_height) { - save = ftell(ifp); - if (tile_length < INT_MAX) - fseek (ifp, get4(), SEEK_SET); - if (!ljpeg_start (&jh, 0)) break; - jwide = jh.wide; - if (filters) jwide *= jh.clrs; - jwide /= is_raw; - for (row=col=jrow=0; jrow < jh.high; jrow++) { - rp = ljpeg_row (jrow, &jh); - for (jcol=0; jcol < jwide; jcol++) { - adobe_copy_pixel (trow+row, tcol+col, &rp); - if (++col >= tile_width || col >= raw_width) - row += 1 + (col = 0); - } - } - fseek (ifp, save+4, SEEK_SET); - if ((tcol += tile_width) >= raw_width) - trow += tile_length + (tcol = 0); - ljpeg_end (&jh); - } -} - -void CLASS packed_dng_load_raw() -{ - ushort *pixel, *rp; - int row, col; - - pixel = (ushort *) calloc (raw_width * tiff_samples, sizeof *pixel); - merror (pixel, "packed_dng_load_raw()"); - for (row=0; row < raw_height; row++) { - if (tiff_bps == 16) - read_shorts (pixel, raw_width * tiff_samples); - else { - getbits(-1); - for (col=0; col < raw_width * tiff_samples; col++) - pixel[col] = getbits(tiff_bps); - } - for (rp=pixel, col=0; col < raw_width; col++) - adobe_copy_pixel (row, col, &rp); - } - free (pixel); -} - -void CLASS pentax_load_raw() -{ - ushort bit[2][15], huff[4097]; - int dep, row, col, diff, c, i; - ushort vpred[2][2] = {{0,0},{0,0}}, hpred[2]; - - fseek (ifp, meta_offset, SEEK_SET); - dep = (get2() + 12) & 15; - fseek (ifp, 12, SEEK_CUR); - FORC(dep) bit[0][c] = get2(); - FORC(dep) bit[1][c] = fgetc(ifp); - FORC(dep) - for (i=bit[0][c]; i <= ((bit[0][c]+(4096 >> bit[1][c])-1) & 4095); ) - huff[++i] = bit[1][c] << 8 | c; - huff[0] = 12; - fseek (ifp, data_offset, SEEK_SET); - getbits(-1); - for (row=0; row < raw_height; row++) - for (col=0; col < raw_width; col++) { - diff = ljpeg_diff (huff); - if (col < 2) hpred[col] = vpred[row & 1][col] += diff; - else hpred[col & 1] += diff; - RAW(row,col) = hpred[col & 1]; - if (hpred[col & 1] >> tiff_bps) derror(); - } -} - -void CLASS nikon_load_raw() -{ - static const uchar nikon_tree[][32] = { - { 0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0, /* 12-bit lossy */ - 5,4,3,6,2,7,1,0,8,9,11,10,12 }, - { 0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0, /* 12-bit lossy after split */ - 0x39,0x5a,0x38,0x27,0x16,5,4,3,2,1,0,11,12,12 }, - { 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0, /* 12-bit lossless */ - 5,4,6,3,7,2,8,1,9,0,10,11,12 }, - { 0,1,4,3,1,1,1,1,1,2,0,0,0,0,0,0, /* 14-bit lossy */ - 5,6,4,7,8,3,9,2,1,0,10,11,12,13,14 }, - { 0,1,5,1,1,1,1,1,1,1,2,0,0,0,0,0, /* 14-bit lossy after split */ - 8,0x5c,0x4b,0x3a,0x29,7,6,5,4,3,2,1,0,13,14 }, - { 0,1,4,2,2,3,1,2,0,0,0,0,0,0,0,0, /* 14-bit lossless */ - 7,6,8,5,9,4,10,3,11,12,2,0,1,13,14 } }; - ushort *huff, ver0, ver1, vpred[2][2], hpred[2], csize; - int i, min, max, step=0, tree=0, split=0, row, col, len, shl, diff; - - fseek (ifp, meta_offset, SEEK_SET); - ver0 = fgetc(ifp); - ver1 = fgetc(ifp); - if (ver0 == 0x49 || ver1 == 0x58) - fseek (ifp, 2110, SEEK_CUR); - if (ver0 == 0x46) tree = 2; - if (tiff_bps == 14) tree += 3; - read_shorts (vpred[0], 4); - max = 1 << tiff_bps & 0x7fff; - if ((csize = get2()) > 1) - step = max / (csize-1); - if (ver0 == 0x44 && ver1 == 0x20 && step > 0) { - for (i=0; i < csize; i++) - curve[i*step] = get2(); - for (i=0; i < max; i++) - curve[i] = ( curve[i-i%step]*(step-i%step) + - curve[i-i%step+step]*(i%step) ) / step; - fseek (ifp, meta_offset+562, SEEK_SET); - split = get2(); - } else if (ver0 != 0x46 && csize <= 0x4001) - read_shorts (curve, max=csize); - while (curve[max-2] == curve[max-1]) max--; - huff = make_decoder (nikon_tree[tree]); - fseek (ifp, data_offset, SEEK_SET); - getbits(-1); - for (min=row=0; row < height; row++) { - if (split && row == split) { - free (huff); - huff = make_decoder (nikon_tree[tree+1]); - max += (min = 16) << 1; - } - for (col=0; col < raw_width; col++) { - i = gethuff(huff); - len = i & 15; - shl = i >> 4; - diff = ((getbits(len-shl) << 1) + 1) << shl >> 1; - if ((diff & (1 << (len-1))) == 0) - diff -= (1 << len) - !shl; - if (col < 2) hpred[col] = vpred[row & 1][col] += diff; - else hpred[col & 1] += diff; - if ((ushort)(hpred[col & 1] + min) >= max) derror(); - RAW(row,col) = curve[LIM((short)hpred[col & 1],0,0x3fff)]; - } - } - free (huff); -} - -/* - Figure out if a NEF file is compressed. These fancy heuristics - are only needed for the D100, thanks to a bug in some cameras - that tags all images as "compressed". - */ -int CLASS nikon_is_compressed() -{ - uchar test[256]; - int i; - - fseek (ifp, data_offset, SEEK_SET); - fread (test, 1, 256, ifp); - for (i=15; i < 256; i+=16) - if (test[i]) return 1; - return 0; -} - -/* - Returns 1 for a Coolpix 995, 0 for anything else. - */ -int CLASS nikon_e995() -{ - int i, histo[256]; - const uchar often[] = { 0x00, 0x55, 0xaa, 0xff }; - - memset (histo, 0, sizeof histo); - fseek (ifp, -2000, SEEK_END); - for (i=0; i < 2000; i++) - histo[fgetc(ifp)]++; - for (i=0; i < 4; i++) - if (histo[often[i]] < 200) - return 0; - return 1; -} - -/* - Returns 1 for a Coolpix 2100, 0 for anything else. - */ -int CLASS nikon_e2100() -{ - uchar t[12]; - int i; - - fseek (ifp, 0, SEEK_SET); - for (i=0; i < 1024; i++) { - fread (t, 1, 12, ifp); - if (((t[2] & t[4] & t[7] & t[9]) >> 4 - & t[1] & t[6] & t[8] & t[11] & 3) != 3) - return 0; - } - return 1; -} - -void CLASS nikon_3700() -{ - int bits, i; - uchar dp[24]; - static const struct { - int bits; - char make[12], model[15]; - } table[] = { - { 0x00, "PENTAX", "Optio 33WR" }, - { 0x03, "NIKON", "E3200" }, - { 0x32, "NIKON", "E3700" }, - { 0x33, "OLYMPUS", "C740UZ" } }; - - fseek (ifp, 3072, SEEK_SET); - fread (dp, 1, 24, ifp); - bits = (dp[8] & 3) << 4 | (dp[20] & 3); - for (i=0; i < sizeof table / sizeof *table; i++) - if (bits == table[i].bits) { - strcpy (make, table[i].make ); - strcpy (model, table[i].model); - } -} - -/* - Separates a Minolta DiMAGE Z2 from a Nikon E4300. - */ -int CLASS minolta_z2() -{ - int i, nz; - char tail[424]; - - fseek (ifp, -sizeof tail, SEEK_END); - fread (tail, 1, sizeof tail, ifp); - for (nz=i=0; i < sizeof tail; i++) - if (tail[i]) nz++; - return nz > 20; -} - -void CLASS jpeg_thumb(); - -void CLASS ppm_thumb() -{ - char *thumb; - thumb_length = thumb_width*thumb_height*3; - thumb = (char *) malloc (thumb_length); - merror (thumb, "ppm_thumb()"); - fprintf (ofp, "P6\n%d %d\n255\n", thumb_width, thumb_height); - fread (thumb, 1, thumb_length, ifp); - fwrite (thumb, 1, thumb_length, ofp); - free (thumb); -} - -void CLASS ppm16_thumb() -{ - int i; - char *thumb; - thumb_length = thumb_width*thumb_height*3; - thumb = (char *) calloc (thumb_length,2); - merror (thumb, "ppm16_thumb()"); - read_shorts ((ushort *) thumb, thumb_length); - for (i=0; i < thumb_length; i++) - thumb[i] = ((ushort *) thumb)[i] >> 8; - fprintf (ofp, "P6\n%d %d\n255\n", thumb_width, thumb_height); - fwrite (thumb, 1, thumb_length, ofp); - free (thumb); -} - -void CLASS layer_thumb() -{ - int i, c; - char *thumb, map[][4] = { "012","102" }; - - colors = thumb_misc >> 5 & 7; - thumb_length = thumb_width*thumb_height; - thumb = (char *) calloc (colors, thumb_length); - merror (thumb, "layer_thumb()"); - fprintf (ofp, "P%d\n%d %d\n255\n", - 5 + (colors >> 1), thumb_width, thumb_height); - fread (thumb, thumb_length, colors, ifp); - for (i=0; i < thumb_length; i++) - FORCC putc (thumb[i+thumb_length*(map[thumb_misc >> 8][c]-'0')], ofp); - free (thumb); -} - -void CLASS rollei_thumb() -{ - unsigned i; - ushort *thumb; - - thumb_length = thumb_width * thumb_height; - thumb = (ushort *) calloc (thumb_length, 2); - merror (thumb, "rollei_thumb()"); - fprintf (ofp, "P6\n%d %d\n255\n", thumb_width, thumb_height); - read_shorts (thumb, thumb_length); - for (i=0; i < thumb_length; i++) { - putc (thumb[i] << 3, ofp); - putc (thumb[i] >> 5 << 2, ofp); - putc (thumb[i] >> 11 << 3, ofp); - } - free (thumb); -} - -void CLASS rollei_load_raw() -{ - uchar pixel[10]; - unsigned iten=0, isix, i, buffer=0, todo[16]; - - isix = raw_width * raw_height * 5 / 8; - while (fread (pixel, 1, 10, ifp) == 10) { - for (i=0; i < 10; i+=2) { - todo[i] = iten++; - todo[i+1] = pixel[i] << 8 | pixel[i+1]; - buffer = pixel[i] >> 2 | buffer << 6; - } - for ( ; i < 16; i+=2) { - todo[i] = isix++; - todo[i+1] = buffer >> (14-i)*5; - } - for (i=0; i < 16; i+=2) - raw_image[todo[i]] = (todo[i+1] & 0x3ff); - } - maximum = 0x3ff; -} - -int CLASS raw (unsigned row, unsigned col) -{ - return (row < raw_height && col < raw_width) ? RAW(row,col) : 0; -} - -void CLASS phase_one_flat_field (int is_float, int nc) -{ - ushort head[8]; - unsigned wide, y, x, c, rend, cend, row, col; - float *mrow, num, mult[4]; - - read_shorts (head, 8); - wide = head[2] / head[4]; - mrow = (float *) calloc (nc*wide, sizeof *mrow); - merror (mrow, "phase_one_flat_field()"); - for (y=0; y < head[3] / head[5]; y++) { - for (x=0; x < wide; x++) - for (c=0; c < nc; c+=2) { - num = is_float ? getreal(11) : get2()/32768.0; - if (y==0) mrow[c*wide+x] = num; - else mrow[(c+1)*wide+x] = (num - mrow[c*wide+x]) / head[5]; - } - if (y==0) continue; - rend = head[1] + y*head[5]; - for (row = rend-head[5]; row < raw_height && row < rend; row++) { - for (x=1; x < wide; x++) { - for (c=0; c < nc; c+=2) { - mult[c] = mrow[c*wide+x-1]; - mult[c+1] = (mrow[c*wide+x] - mult[c]) / head[4]; - } - cend = head[0] + x*head[4]; - for (col = cend-head[4]; col < raw_width && col < cend; col++) { - c = nc > 2 ? FC(row-top_margin,col-left_margin) : 0; - if (!(c & 1)) { - c = RAW(row,col) * mult[c]; - RAW(row,col) = LIM(c,0,65535); - } - for (c=0; c < nc; c+=2) - mult[c] += mult[c+1]; - } - } - for (x=0; x < wide; x++) - for (c=0; c < nc; c+=2) - mrow[c*wide+x] += mrow[(c+1)*wide+x]; - } - } - free (mrow); -} - -void CLASS phase_one_correct() -{ - unsigned entries, tag, data, save, col, row, type; - int len, i, j, k, cip, val[4], dev[4], sum, max; - int head[9], diff, mindiff=INT_MAX, off_412=0; - static const signed char dir[12][2] = - { {-1,-1}, {-1,1}, {1,-1}, {1,1}, {-2,0}, {0,-2}, {0,2}, {2,0}, - {-2,-2}, {-2,2}, {2,-2}, {2,2} }; - float poly[8], num, cfrac, frac, mult[2], *yval[2]; - ushort *xval[2]; - - if (half_size || !meta_length) return; - if (verbose) fprintf (stderr,_("Phase One correction...\n")); - fseek (ifp, meta_offset, SEEK_SET); - order = get2(); - fseek (ifp, 6, SEEK_CUR); - fseek (ifp, meta_offset+get4(), SEEK_SET); - entries = get4(); get4(); - while (entries--) { - tag = get4(); - len = get4(); - data = get4(); - save = ftell(ifp); - fseek (ifp, meta_offset+data, SEEK_SET); - if (tag == 0x419) { /* Polynomial curve */ - for (get4(), i=0; i < 8; i++) - poly[i] = getreal(11); - poly[3] += (ph1.tag_210 - poly[7]) * poly[6] + 1; - for (i=0; i < 0x10000; i++) { - num = (poly[5]*i + poly[3])*i + poly[1]; - curve[i] = LIM(num,0,65535); - } goto apply; /* apply to right half */ - } else if (tag == 0x41a) { /* Polynomial curve */ - for (i=0; i < 4; i++) - poly[i] = getreal(11); - for (i=0; i < 0x10000; i++) { - for (num=0, j=4; j--; ) - num = num * i + poly[j]; - curve[i] = LIM(num+i,0,65535); - } apply: /* apply to whole image */ - for (row=0; row < raw_height; row++) - for (col = (tag & 1)*ph1.split_col; col < raw_width; col++) - RAW(row,col) = curve[RAW(row,col)]; - } else if (tag == 0x400) { /* Sensor defects */ - while ((len -= 8) >= 0) { - col = get2(); - row = get2(); - type = get2(); get2(); - if (col >= raw_width) continue; - if (type == 131) /* Bad column */ - for (row=0; row < raw_height; row++) - if (FC(row-top_margin,col-left_margin) == 1) { - for (sum=i=0; i < 4; i++) - sum += val[i] = raw (row+dir[i][0], col+dir[i][1]); - for (max=i=0; i < 4; i++) { - dev[i] = abs((val[i] << 2) - sum); - if (dev[max] < dev[i]) max = i; - } - RAW(row,col) = (sum - val[max])/3.0 + 0.5; - } else { - for (sum=0, i=8; i < 12; i++) - sum += raw (row+dir[i][0], col+dir[i][1]); - RAW(row,col) = 0.5 + sum * 0.0732233 + - (raw(row,col-2) + raw(row,col+2)) * 0.3535534; - } - else if (type == 129) { /* Bad pixel */ - if (row >= raw_height) continue; - j = (FC(row-top_margin,col-left_margin) != 1) * 4; - for (sum=0, i=j; i < j+8; i++) - sum += raw (row+dir[i][0], col+dir[i][1]); - RAW(row,col) = (sum + 4) >> 3; - } - } - } else if (tag == 0x401) { /* All-color flat fields */ - phase_one_flat_field (1, 2); - } else if (tag == 0x416 || tag == 0x410) { - phase_one_flat_field (0, 2); - } else if (tag == 0x40b) { /* Red+blue flat field */ - phase_one_flat_field (0, 4); - } else if (tag == 0x412) { - fseek (ifp, 36, SEEK_CUR); - diff = abs (get2() - ph1.tag_21a); - if (mindiff > diff) { - mindiff = diff; - off_412 = ftell(ifp) - 38; - } - } - fseek (ifp, save, SEEK_SET); - } - if (off_412) { - fseek (ifp, off_412, SEEK_SET); - for (i=0; i < 9; i++) head[i] = get4() & 0x7fff; - yval[0] = (float *) calloc (head[1]*head[3] + head[2]*head[4], 6); - merror (yval[0], "phase_one_correct()"); - yval[1] = (float *) (yval[0] + head[1]*head[3]); - xval[0] = (ushort *) (yval[1] + head[2]*head[4]); - xval[1] = (ushort *) (xval[0] + head[1]*head[3]); - get2(); - for (i=0; i < 2; i++) - for (j=0; j < head[i+1]*head[i+3]; j++) - yval[i][j] = getreal(11); - for (i=0; i < 2; i++) - for (j=0; j < head[i+1]*head[i+3]; j++) - xval[i][j] = get2(); - for (row=0; row < raw_height; row++) - for (col=0; col < raw_width; col++) { - cfrac = (float) col * head[3] / raw_width; - cfrac -= cip = cfrac; - num = RAW(row,col) * 0.5; - for (i=cip; i < cip+2; i++) { - for (k=j=0; j < head[1]; j++) - if (num < xval[0][k = head[1]*i+j]) break; - frac = (j == 0 || j == head[1]) ? 0 : - (xval[0][k] - num) / (xval[0][k] - xval[0][k-1]); - mult[i-cip] = yval[0][k-1] * frac + yval[0][k] * (1-frac); - } - i = ((mult[0] * (1-cfrac) + mult[1] * cfrac) * row + num) * 2; - RAW(row,col) = LIM(i,0,65535); - } - free (yval[0]); - } -} - -void CLASS phase_one_load_raw() -{ - int a, b, i; - ushort akey, bkey, mask; - - fseek (ifp, ph1.key_off, SEEK_SET); - akey = get2(); - bkey = get2(); - mask = ph1.format == 1 ? 0x5555:0x1354; - fseek (ifp, data_offset, SEEK_SET); - read_shorts (raw_image, raw_width*raw_height); - if (ph1.format) - for (i=0; i < raw_width*raw_height; i+=2) { - a = raw_image[i+0] ^ akey; - b = raw_image[i+1] ^ bkey; - raw_image[i+0] = (a & mask) | (b & ~mask); - raw_image[i+1] = (b & mask) | (a & ~mask); - } -} - -unsigned CLASS ph1_bithuff (int nbits, ushort *huff) -{ - static UINT64 bitbuf=0; - static int vbits=0; - unsigned c; - - if (nbits == -1) - return bitbuf = vbits = 0; - if (nbits == 0) return 0; - if (vbits < nbits) { - bitbuf = bitbuf << 32 | get4(); - vbits += 32; - } - c = bitbuf << (64-vbits) >> (64-nbits); - if (huff) { - vbits -= huff[c] >> 8; - return (uchar) huff[c]; - } - vbits -= nbits; - return c; -} -#define ph1_bits(n) ph1_bithuff(n,0) -#define ph1_huff(h) ph1_bithuff(*h,h+1) - -void CLASS phase_one_load_raw_c() -{ - static const int length[] = { 8,7,6,9,11,10,5,12,14,13 }; - int *offset, len[2], pred[2], row, col, i, j; - ushort *pixel; - short (*black)[2]; - - pixel = (ushort *) calloc (raw_width + raw_height*4, 2); - merror (pixel, "phase_one_load_raw_c()"); - offset = (int *) (pixel + raw_width); - fseek (ifp, strip_offset, SEEK_SET); - for (row=0; row < raw_height; row++) - offset[row] = get4(); - black = (short (*)[2]) offset + raw_height; - fseek (ifp, ph1.black_off, SEEK_SET); - if (ph1.black_off) - read_shorts ((ushort *) black[0], raw_height*2); - for (i=0; i < 256; i++) - curve[i] = i*i / 3.969 + 0.5; - for (row=0; row < raw_height; row++) { - fseek (ifp, data_offset + offset[row], SEEK_SET); - ph1_bits(-1); - pred[0] = pred[1] = 0; - for (col=0; col < raw_width; col++) { - if (col >= (raw_width & -8)) - len[0] = len[1] = 14; - else if ((col & 7) == 0) - for (i=0; i < 2; i++) { - for (j=0; j < 5 && !ph1_bits(1); j++); - if (j--) len[i] = length[j*2 + ph1_bits(1)]; - } - if ((i = len[col & 1]) == 14) - pixel[col] = pred[col & 1] = ph1_bits(16); - else - pixel[col] = pred[col & 1] += ph1_bits(i) + 1 - (1 << (i - 1)); - if (pred[col & 1] >> 16) derror(); - if (ph1.format == 5 && pixel[col] < 256) - pixel[col] = curve[pixel[col]]; - } - for (col=0; col < raw_width; col++) { - i = (pixel[col] << 2) - ph1.black + black[row][col >= ph1.split_col]; - if (i > 0) RAW(row,col) = i; - } - } - free (pixel); - maximum = 0xfffc - ph1.black; -} - -void CLASS hasselblad_load_raw() -{ - struct jhead jh; - int row, col, pred[2], len[2], diff, c; - - if (!ljpeg_start (&jh, 0)) return; - order = 0x4949; - ph1_bits(-1); - for (row=0; row < raw_height; row++) { - pred[0] = pred[1] = 0x8000 + load_flags; - for (col=0; col < raw_width; col+=2) { - FORC(2) len[c] = ph1_huff(jh.huff[0]); - FORC(2) { - diff = ph1_bits(len[c]); - if ((diff & (1 << (len[c]-1))) == 0) - diff -= (1 << len[c]) - 1; - if (diff == 65535) diff = -32768; - pred[c] += diff; - if (row >= 0 && (unsigned)(col+c) < width) - RAW(row,col+c) = pred[c]; - } - } - } - ljpeg_end (&jh); - maximum = 0xffff; -} - -void CLASS leaf_hdr_load_raw() -{ - ushort *pixel=0; - unsigned tile=0, r, c, row, col; - - if (!filters) { - pixel = (ushort *) calloc (raw_width, sizeof *pixel); - merror (pixel, "leaf_hdr_load_raw()"); - } - FORC(tiff_samples) - for (r=0; r < raw_height; r++) { - if (r % tile_length == 0) { - fseek (ifp, data_offset + 4*tile++, SEEK_SET); - fseek (ifp, get4(), SEEK_SET); - } - if (filters && c != shot_select) continue; - if (filters) pixel = raw_image + r*raw_width; - read_shorts (pixel, raw_width); - if (!filters && (row = r - top_margin) < height) - for (col=0; col < width; col++) - image[row*width+col][c] = pixel[col+left_margin]; - } - if (!filters) { - maximum = 0xffff; - raw_color = 1; - free (pixel); - } -} - -void CLASS unpacked_load_raw() -{ - int row, col, bits=0; - - while (1 << ++bits < maximum); - read_shorts (raw_image, raw_width*raw_height); - for (row=0; row < raw_height; row++) - for (col=0; col < raw_width; col++) - if ((RAW(row,col) >>= load_flags) >> bits - && (unsigned) (row-top_margin) < height - && (unsigned) (col-left_margin) < width) derror(); -} - -void CLASS sinar_4shot_load_raw() -{ - ushort *pixel; - unsigned shot, row, col, r, c; - - if ((shot = shot_select) || half_size) { - if (shot) shot--; - if (shot > 3) shot = 3; - fseek (ifp, data_offset + shot*4, SEEK_SET); - fseek (ifp, get4(), SEEK_SET); - unpacked_load_raw(); - return; - } - free (raw_image); - raw_image = 0; - free (image); - image = (ushort (*)[4]) - calloc ((iheight=height)*(iwidth=width), sizeof *image); - merror (image, "sinar_4shot_load_raw()"); - pixel = (ushort *) calloc (raw_width, sizeof *pixel); - merror (pixel, "sinar_4shot_load_raw()"); - for (shot=0; shot < 4; shot++) { - fseek (ifp, data_offset + shot*4, SEEK_SET); - fseek (ifp, get4(), SEEK_SET); - for (row=0; row < raw_height; row++) { - read_shorts (pixel, raw_width); - if ((r = row-top_margin - (shot >> 1 & 1)) >= height) continue; - for (col=0; col < raw_width; col++) { - if ((c = col-left_margin - (shot & 1)) >= width) continue; - image[r*width+c][FC(row,col)] = pixel[col]; - } - } - } - free (pixel); - shrink = filters = 0; -} - -void CLASS imacon_full_load_raw() -{ - int row, col; - - for (row=0; row < height; row++) - for (col=0; col < width; col++) - read_shorts (image[row*width+col], 3); -} - -void CLASS packed_load_raw() -{ - int vbits=0, bwide, pwide, rbits, bite, half, irow, row, col, val, i; - UINT64 bitbuf=0; - - if (raw_width * 8 >= width * tiff_bps) /* Is raw_width in bytes? */ - pwide = (bwide = raw_width) * 8 / tiff_bps; - else bwide = (pwide = raw_width) * tiff_bps / 8; - rbits = bwide * 8 - pwide * tiff_bps; - if (load_flags & 1) bwide = bwide * 16 / 15; - bite = 8 + (load_flags & 24); - half = (raw_height+1) >> 1; - for (irow=0; irow < raw_height; irow++) { - row = irow; - if (load_flags & 2 && - (row = irow % half * 2 + irow / half) == 1 && - load_flags & 4) { - if (vbits=0, tiff_compress) - fseek (ifp, data_offset - (-half*bwide & -2048), SEEK_SET); - else { - fseek (ifp, 0, SEEK_END); - fseek (ifp, ftell(ifp) >> 3 << 2, SEEK_SET); - } - } - for (col=0; col < pwide; col++) { - for (vbits -= tiff_bps; vbits < 0; vbits += bite) { - bitbuf <<= bite; - for (i=0; i < bite; i+=8) - bitbuf |= (unsigned) (fgetc(ifp) << i); - } - val = bitbuf << (64-tiff_bps-vbits) >> (64-tiff_bps); - RAW(row,col ^ (load_flags >> 6)) = val; - if (load_flags & 1 && (col % 10) == 9 && - fgetc(ifp) && col < width+left_margin) derror(); - } - vbits -= rbits; - } -} - -void CLASS nokia_load_raw() -{ - uchar *data, *dp; - int rev, dwide, row, col, c; - - rev = 3 * (order == 0x4949); - dwide = raw_width * 5 / 4; - data = (uchar *) malloc (dwide*2); - merror (data, "nokia_load_raw()"); - for (row=0; row < raw_height; row++) { - if (fread (data+dwide, 1, dwide, ifp) < dwide) derror(); - FORC(dwide) data[c] = data[dwide+(c ^ rev)]; - for (dp=data, col=0; col < raw_width; dp+=5, col+=4) - FORC4 RAW(row,col+c) = (dp[c] << 2) | (dp[4] >> (c << 1) & 3); - } - free (data); - maximum = 0x3ff; -} - -unsigned CLASS pana_bits (int nbits) -{ - static uchar buf[0x4000]; - static int vbits; - int byte; - - if (!nbits) return vbits=0; - if (!vbits) { - fread (buf+load_flags, 1, 0x4000-load_flags, ifp); - fread (buf, 1, load_flags, ifp); - } - vbits = (vbits - nbits) & 0x1ffff; - byte = vbits >> 3 ^ 0x3ff0; - return (buf[byte] | buf[byte+1] << 8) >> (vbits & 7) & ~(-1 << nbits); -} - -void CLASS panasonic_load_raw() -{ - int row, col, i, j, sh=0, pred[2], nonz[2]; - - pana_bits(0); - for (row=0; row < height; row++) - for (col=0; col < raw_width; col++) { - if ((i = col % 14) == 0) - pred[0] = pred[1] = nonz[0] = nonz[1] = 0; - if (i % 3 == 2) sh = 4 >> (3 - pana_bits(2)); - if (nonz[i & 1]) { - if ((j = pana_bits(8))) { - if ((pred[i & 1] -= 0x80 << sh) < 0 || sh == 4) - pred[i & 1] &= ~(-1 << sh); - pred[i & 1] += j << sh; - } - } else if ((nonz[i & 1] = pana_bits(8)) || i > 11) - pred[i & 1] = nonz[i & 1] << 4 | pana_bits(4); - if (col < width) - if ((RAW(row,col) = pred[col & 1]) > 4098) derror(); - } -} - -void CLASS olympus_load_raw() -{ - ushort huff[4096]; - int row, col, nbits, sign, low, high, i, c, w, n, nw; - int acarry[2][3], *carry, pred, diff; - - huff[n=0] = 0xc0c; - for (i=12; i--; ) - FORC(2048 >> i) huff[++n] = (i+1) << 8 | i; - fseek (ifp, 7, SEEK_CUR); - getbits(-1); - for (row=0; row < height; row++) { - memset (acarry, 0, sizeof acarry); - for (col=0; col < raw_width; col++) { - carry = acarry[col & 1]; - i = 2 * (carry[2] < 3); - for (nbits=2+i; (ushort) carry[0] >> (nbits+i); nbits++); - low = (sign = getbits(3)) & 3; - sign = sign << 29 >> 31; - if ((high = getbithuff(12,huff)) == 12) - high = getbits(16-nbits) >> 1; - carry[0] = (high << nbits) | getbits(nbits); - diff = (carry[0] ^ sign) + carry[1]; - carry[1] = (diff*3 + carry[1]) >> 5; - carry[2] = carry[0] > 16 ? 0 : carry[2]+1; - if (col >= width) continue; - if (row < 2 && col < 2) pred = 0; - else if (row < 2) pred = RAW(row,col-2); - else if (col < 2) pred = RAW(row-2,col); - else { - w = RAW(row,col-2); - n = RAW(row-2,col); - nw = RAW(row-2,col-2); - if ((w < nw && nw < n) || (n < nw && nw < w)) { - if (ABS(w-nw) > 32 || ABS(n-nw) > 32) - pred = w + n - nw; - else pred = (w + n) >> 1; - } else pred = ABS(w-nw) > ABS(n-nw) ? w : n; - } - if ((RAW(row,col) = pred + ((diff << 2) | low)) >> 12) derror(); - } - } -} - -void CLASS minolta_rd175_load_raw() -{ - uchar pixel[768]; - unsigned irow, box, row, col; - - for (irow=0; irow < 1481; irow++) { - if (fread (pixel, 1, 768, ifp) < 768) derror(); - box = irow / 82; - row = irow % 82 * 12 + ((box < 12) ? box | 1 : (box-12)*2); - switch (irow) { - case 1477: case 1479: continue; - case 1476: row = 984; break; - case 1480: row = 985; break; - case 1478: row = 985; box = 1; - } - if ((box < 12) && (box & 1)) { - for (col=0; col < 1533; col++, row ^= 1) - if (col != 1) RAW(row,col) = (col+1) & 2 ? - pixel[col/2-1] + pixel[col/2+1] : pixel[col/2] << 1; - RAW(row,1) = pixel[1] << 1; - RAW(row,1533) = pixel[765] << 1; - } else - for (col=row & 1; col < 1534; col+=2) - RAW(row,col) = pixel[col/2] << 1; - } - maximum = 0xff << 1; -} - -void CLASS quicktake_100_load_raw() -{ - uchar pixel[484][644]; - static const short gstep[16] = - { -89,-60,-44,-32,-22,-15,-8,-2,2,8,15,22,32,44,60,89 }; - static const short rstep[6][4] = - { { -3,-1,1,3 }, { -5,-1,1,5 }, { -8,-2,2,8 }, - { -13,-3,3,13 }, { -19,-4,4,19 }, { -28,-6,6,28 } }; - static const short curve[256] = - { 0,1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27, - 28,29,30,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,53, - 54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,74,75,76,77,78, - 79,80,81,82,83,84,86,88,90,92,94,97,99,101,103,105,107,110,112,114,116, - 118,120,123,125,127,129,131,134,136,138,140,142,144,147,149,151,153,155, - 158,160,162,164,166,168,171,173,175,177,179,181,184,186,188,190,192,195, - 197,199,201,203,205,208,210,212,214,216,218,221,223,226,230,235,239,244, - 248,252,257,261,265,270,274,278,283,287,291,296,300,305,309,313,318,322, - 326,331,335,339,344,348,352,357,361,365,370,374,379,383,387,392,396,400, - 405,409,413,418,422,426,431,435,440,444,448,453,457,461,466,470,474,479, - 483,487,492,496,500,508,519,531,542,553,564,575,587,598,609,620,631,643, - 654,665,676,687,698,710,721,732,743,754,766,777,788,799,810,822,833,844, - 855,866,878,889,900,911,922,933,945,956,967,978,989,1001,1012,1023 }; - int rb, row, col, sharp, val=0; - - getbits(-1); - memset (pixel, 0x80, sizeof pixel); - for (row=2; row < height+2; row++) { - for (col=2+(row & 1); col < width+2; col+=2) { - val = ((pixel[row-1][col-1] + 2*pixel[row-1][col+1] + - pixel[row][col-2]) >> 2) + gstep[getbits(4)]; - pixel[row][col] = val = LIM(val,0,255); - if (col < 4) - pixel[row][col-2] = pixel[row+1][~row & 1] = val; - if (row == 2) - pixel[row-1][col+1] = pixel[row-1][col+3] = val; - } - pixel[row][col] = val; - } - for (rb=0; rb < 2; rb++) - for (row=2+rb; row < height+2; row+=2) - for (col=3-(row & 1); col < width+2; col+=2) { - if (row < 4 || col < 4) sharp = 2; - else { - val = ABS(pixel[row-2][col] - pixel[row][col-2]) - + ABS(pixel[row-2][col] - pixel[row-2][col-2]) - + ABS(pixel[row][col-2] - pixel[row-2][col-2]); - sharp = val < 4 ? 0 : val < 8 ? 1 : val < 16 ? 2 : - val < 32 ? 3 : val < 48 ? 4 : 5; - } - val = ((pixel[row-2][col] + pixel[row][col-2]) >> 1) - + rstep[sharp][getbits(2)]; - pixel[row][col] = val = LIM(val,0,255); - if (row < 4) pixel[row-2][col+2] = val; - if (col < 4) pixel[row+2][col-2] = val; - } - for (row=2; row < height+2; row++) - for (col=3-(row & 1); col < width+2; col+=2) { - val = ((pixel[row][col-1] + (pixel[row][col] << 2) + - pixel[row][col+1]) >> 1) - 0x100; - pixel[row][col] = LIM(val,0,255); - } - for (row=0; row < height; row++) - for (col=0; col < width; col++) - RAW(row,col) = curve[pixel[row+2][col+2]]; - maximum = 0x3ff; -} - -#define radc_token(tree) ((signed char) getbithuff(8,huff[tree])) - -#define FORYX for (y=1; y < 3; y++) for (x=col+1; x >= col; x--) - -#define PREDICTOR (c ? (buf[c][y-1][x] + buf[c][y][x+1]) / 2 \ -: (buf[c][y-1][x+1] + 2*buf[c][y-1][x] + buf[c][y][x+1]) / 4) - -void CLASS kodak_radc_load_raw() -{ - static const char src[] = { - 1,1, 2,3, 3,4, 4,2, 5,7, 6,5, 7,6, 7,8, - 1,0, 2,1, 3,3, 4,4, 5,2, 6,7, 7,6, 8,5, 8,8, - 2,1, 2,3, 3,0, 3,2, 3,4, 4,6, 5,5, 6,7, 6,8, - 2,0, 2,1, 2,3, 3,2, 4,4, 5,6, 6,7, 7,5, 7,8, - 2,1, 2,4, 3,0, 3,2, 3,3, 4,7, 5,5, 6,6, 6,8, - 2,3, 3,1, 3,2, 3,4, 3,5, 3,6, 4,7, 5,0, 5,8, - 2,3, 2,6, 3,0, 3,1, 4,4, 4,5, 4,7, 5,2, 5,8, - 2,4, 2,7, 3,3, 3,6, 4,1, 4,2, 4,5, 5,0, 5,8, - 2,6, 3,1, 3,3, 3,5, 3,7, 3,8, 4,0, 5,2, 5,4, - 2,0, 2,1, 3,2, 3,3, 4,4, 4,5, 5,6, 5,7, 4,8, - 1,0, 2,2, 2,-2, - 1,-3, 1,3, - 2,-17, 2,-5, 2,5, 2,17, - 2,-7, 2,2, 2,9, 2,18, - 2,-18, 2,-9, 2,-2, 2,7, - 2,-28, 2,28, 3,-49, 3,-9, 3,9, 4,49, 5,-79, 5,79, - 2,-1, 2,13, 2,26, 3,39, 4,-16, 5,55, 6,-37, 6,76, - 2,-26, 2,-13, 2,1, 3,-39, 4,16, 5,-55, 6,-76, 6,37 - }; - ushort huff[19][256]; - int row, col, tree, nreps, rep, step, i, c, s, r, x, y, val; - short last[3] = { 16,16,16 }, mul[3], buf[3][3][386]; - static const ushort pt[] = - { 0,0, 1280,1344, 2320,3616, 3328,8000, 4095,16383, 65535,16383 }; - - for (i=2; i < 12; i+=2) - for (c=pt[i-2]; c <= pt[i]; c++) - curve[c] = (float) - (c-pt[i-2]) / (pt[i]-pt[i-2]) * (pt[i+1]-pt[i-1]) + pt[i-1] + 0.5; - for (s=i=0; i < sizeof src; i+=2) - FORC(256 >> src[i]) - huff[0][s++] = src[i] << 8 | (uchar) src[i+1]; - s = kodak_cbpp == 243 ? 2 : 3; - FORC(256) huff[18][c] = (8-s) << 8 | c >> s << s | 1 << (s-1); - getbits(-1); - for (i=0; i < sizeof(buf)/sizeof(short); i++) - buf[0][0][i] = 2048; - for (row=0; row < height; row+=4) { - FORC3 mul[c] = getbits(6); - FORC3 { - val = ((0x1000000/last[c] + 0x7ff) >> 12) * mul[c]; - s = val > 65564 ? 10:12; - x = ~(-1 << (s-1)); - val <<= 12-s; - for (i=0; i < sizeof(buf[0])/sizeof(short); i++) - buf[c][0][i] = (buf[c][0][i] * val + x) >> s; - last[c] = mul[c]; - for (r=0; r <= !c; r++) { - buf[c][1][width/2] = buf[c][2][width/2] = mul[c] << 7; - for (tree=1, col=width/2; col > 0; ) { - if ((tree = radc_token(tree))) { - col -= 2; - if (tree == 8) - FORYX buf[c][y][x] = (uchar) radc_token(18) * mul[c]; - else - FORYX buf[c][y][x] = radc_token(tree+10) * 16 + PREDICTOR; - } else - do { - nreps = (col > 2) ? radc_token(9) + 1 : 1; - for (rep=0; rep < 8 && rep < nreps && col > 0; rep++) { - col -= 2; - FORYX buf[c][y][x] = PREDICTOR; - if (rep & 1) { - step = radc_token(10) << 4; - FORYX buf[c][y][x] += step; - } - } - } while (nreps == 9); - } - for (y=0; y < 2; y++) - for (x=0; x < width/2; x++) { - val = (buf[c][y+1][x] << 4) / mul[c]; - if (val < 0) val = 0; - if (c) RAW(row+y*2+c-1,x*2+2-c) = val; - else RAW(row+r*2+y,x*2+y) = val; - } - memcpy (buf[c][0]+!c, buf[c][2], sizeof buf[c][0]-2*!c); - } - } - for (y=row; y < row+4; y++) - for (x=0; x < width; x++) - if ((x+y) & 1) { - r = x ? x-1 : x+1; - s = x+1 < width ? x+1 : x-1; - val = (RAW(y,x)-2048)*2 + (RAW(y,r)+RAW(y,s))/2; - if (val < 0) val = 0; - RAW(y,x) = val; - } - } - for (i=0; i < height*width; i++) - raw_image[i] = curve[raw_image[i]]; - maximum = 0x3fff; -} - -#undef FORYX -#undef PREDICTOR - -#ifdef NO_JPEG -void CLASS kodak_jpeg_load_raw() {} -void CLASS lossy_dng_load_raw() {} -#else - -METHODDEF(boolean) -fill_input_buffer (j_decompress_ptr cinfo) -{ - static uchar jpeg_buffer[4096]; - size_t nbytes; - - nbytes = fread (jpeg_buffer, 1, 4096, ifp); - swab (jpeg_buffer, jpeg_buffer, nbytes); - cinfo->src->next_input_byte = jpeg_buffer; - cinfo->src->bytes_in_buffer = nbytes; - return TRUE; -} - -void CLASS kodak_jpeg_load_raw() -{ - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - JSAMPARRAY buf; - JSAMPLE (*pixel)[3]; - int row, col; - - cinfo.err = jpeg_std_error (&jerr); - jpeg_create_decompress (&cinfo); - jpeg_stdio_src (&cinfo, ifp); - cinfo.src->fill_input_buffer = fill_input_buffer; - jpeg_read_header (&cinfo, TRUE); - jpeg_start_decompress (&cinfo); - if ((cinfo.output_width != width ) || - (cinfo.output_height*2 != height ) || - (cinfo.output_components != 3 )) { - fprintf (stderr,_("%s: incorrect JPEG dimensions\n"), ifname); - jpeg_destroy_decompress (&cinfo); - longjmp (failure, 3); - } - buf = (*cinfo.mem->alloc_sarray) - ((j_common_ptr) &cinfo, JPOOL_IMAGE, width*3, 1); - - while (cinfo.output_scanline < cinfo.output_height) { - row = cinfo.output_scanline * 2; - jpeg_read_scanlines (&cinfo, buf, 1); - pixel = (JSAMPLE (*)[3]) buf[0]; - for (col=0; col < width; col+=2) { - RAW(row+0,col+0) = pixel[col+0][1] << 1; - RAW(row+1,col+1) = pixel[col+1][1] << 1; - RAW(row+0,col+1) = pixel[col][0] + pixel[col+1][0]; - RAW(row+1,col+0) = pixel[col][2] + pixel[col+1][2]; - } - } - jpeg_finish_decompress (&cinfo); - jpeg_destroy_decompress (&cinfo); - maximum = 0xff << 1; -} - -void CLASS lossy_dng_load_raw() -{ - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - JSAMPARRAY buf; - JSAMPLE (*pixel)[3]; - unsigned sorder=order, ntags, opcode, deg, i, j, c; - unsigned save=data_offset-4, trow=0, tcol=0, row, col; - ushort curve[3][256]; - double coeff[9], tot; - - fseek (ifp, meta_offset, SEEK_SET); - order = 0x4d4d; - ntags = get4(); - while (ntags--) { - opcode = get4(); get4(); get4(); - if (opcode != 8) - { fseek (ifp, get4(), SEEK_CUR); continue; } - fseek (ifp, 20, SEEK_CUR); - if ((c = get4()) > 2) break; - fseek (ifp, 12, SEEK_CUR); - if ((deg = get4()) > 8) break; - for (i=0; i <= deg && i < 9; i++) - coeff[i] = getreal(12); - for (i=0; i < 256; i++) { - for (tot=j=0; j <= deg; j++) - tot += coeff[j] * pow(i/255.0, j); - curve[c][i] = tot*0xffff; - } - } - order = sorder; - cinfo.err = jpeg_std_error (&jerr); - jpeg_create_decompress (&cinfo); - while (trow < raw_height) { - fseek (ifp, save+=4, SEEK_SET); - if (tile_length < INT_MAX) - fseek (ifp, get4(), SEEK_SET); - jpeg_stdio_src (&cinfo, ifp); - jpeg_read_header (&cinfo, TRUE); - jpeg_start_decompress (&cinfo); - buf = (*cinfo.mem->alloc_sarray) - ((j_common_ptr) &cinfo, JPOOL_IMAGE, cinfo.output_width*3, 1); - while (cinfo.output_scanline < cinfo.output_height && - (row = trow + cinfo.output_scanline) < height) { - jpeg_read_scanlines (&cinfo, buf, 1); - pixel = (JSAMPLE (*)[3]) buf[0]; - for (col=0; col < cinfo.output_width && tcol+col < width; col++) { - FORC3 image[row*width+tcol+col][c] = curve[c][pixel[col][c]]; - } - } - jpeg_abort_decompress (&cinfo); - if ((tcol += tile_width) >= raw_width) - trow += tile_length + (tcol = 0); - } - jpeg_destroy_decompress (&cinfo); - maximum = 0xffff; -} -#endif - -void CLASS kodak_dc120_load_raw() -{ - static const int mul[4] = { 162, 192, 187, 92 }; - static const int add[4] = { 0, 636, 424, 212 }; - uchar pixel[848]; - int row, shift, col; - - for (row=0; row < height; row++) { - if (fread (pixel, 1, 848, ifp) < 848) derror(); - shift = row * mul[row & 3] + add[row & 3]; - for (col=0; col < width; col++) - RAW(row,col) = (ushort) pixel[(col + shift) % 848]; - } - maximum = 0xff; -} - -void CLASS eight_bit_load_raw() -{ - uchar *pixel; - unsigned row, col; - - pixel = (uchar *) calloc (raw_width, sizeof *pixel); - merror (pixel, "eight_bit_load_raw()"); - for (row=0; row < raw_height; row++) { - if (fread (pixel, 1, raw_width, ifp) < raw_width) derror(); - for (col=0; col < raw_width; col++) - RAW(row,col) = curve[pixel[col]]; - } - free (pixel); - maximum = curve[0xff]; -} - -void CLASS kodak_yrgb_load_raw() -{ - uchar *pixel; - int row, col, y, cb, cr, rgb[3], c; - - pixel = (uchar *) calloc (raw_width, 3*sizeof *pixel); - merror (pixel, "kodak_yrgb_load_raw()"); - for (row=0; row < height; row++) { - if (~row & 1) - if (fread (pixel, raw_width, 3, ifp) < 3) derror(); - for (col=0; col < raw_width; col++) { - y = pixel[width*2*(row & 1) + col]; - cb = pixel[width + (col & -2)] - 128; - cr = pixel[width + (col & -2)+1] - 128; - rgb[1] = y-((cb + cr + 2) >> 2); - rgb[2] = rgb[1] + cb; - rgb[0] = rgb[1] + cr; - FORC3 image[row*width+col][c] = curve[LIM(rgb[c],0,255)]; - } - } - free (pixel); - maximum = curve[0xff]; -} - -void CLASS kodak_262_load_raw() -{ - static const uchar kodak_tree[2][26] = - { { 0,1,5,1,1,2,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9 }, - { 0,3,1,1,1,1,1,2,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9 } }; - ushort *huff[2]; - uchar *pixel; - int *strip, ns, c, row, col, chess, pi=0, pi1, pi2, pred, val; - - FORC(2) huff[c] = make_decoder (kodak_tree[c]); - ns = (raw_height+63) >> 5; - pixel = (uchar *) malloc (raw_width*32 + ns*4); - merror (pixel, "kodak_262_load_raw()"); - strip = (int *) (pixel + raw_width*32); - order = 0x4d4d; - FORC(ns) strip[c] = get4(); - for (row=0; row < raw_height; row++) { - if ((row & 31) == 0) { - fseek (ifp, strip[row >> 5], SEEK_SET); - getbits(-1); - pi = 0; - } - for (col=0; col < raw_width; col++) { - chess = (row + col) & 1; - pi1 = chess ? pi-2 : pi-raw_width-1; - pi2 = chess ? pi-2*raw_width : pi-raw_width+1; - if (col <= chess) pi1 = -1; - if (pi1 < 0) pi1 = pi2; - if (pi2 < 0) pi2 = pi1; - if (pi1 < 0 && col > 1) pi1 = pi2 = pi-2; - pred = (pi1 < 0) ? 0 : (pixel[pi1] + pixel[pi2]) >> 1; - pixel[pi] = val = pred + ljpeg_diff (huff[chess]); - if (val >> 8) derror(); - val = curve[pixel[pi++]]; - RAW(row,col) = val; - } - } - free (pixel); - FORC(2) free (huff[c]); -} - -int CLASS kodak_65000_decode (short *out, int bsize) -{ - uchar c, blen[768]; - ushort raw[6]; - INT64 bitbuf=0; - int save, bits=0, i, j, len, diff; - - save = ftell(ifp); - bsize = (bsize + 3) & -4; - for (i=0; i < bsize; i+=2) { - c = fgetc(ifp); - if ((blen[i ] = c & 15) > 12 || - (blen[i+1] = c >> 4) > 12 ) { - fseek (ifp, save, SEEK_SET); - for (i=0; i < bsize; i+=8) { - read_shorts (raw, 6); - out[i ] = raw[0] >> 12 << 8 | raw[2] >> 12 << 4 | raw[4] >> 12; - out[i+1] = raw[1] >> 12 << 8 | raw[3] >> 12 << 4 | raw[5] >> 12; - for (j=0; j < 6; j++) - out[i+2+j] = raw[j] & 0xfff; - } - return 1; - } - } - if ((bsize & 7) == 4) { - bitbuf = fgetc(ifp) << 8; - bitbuf += fgetc(ifp); - bits = 16; - } - for (i=0; i < bsize; i++) { - len = blen[i]; - if (bits < len) { - for (j=0; j < 32; j+=8) - bitbuf += (INT64) fgetc(ifp) << (bits+(j^8)); - bits += 32; - } - diff = bitbuf & (0xffff >> (16-len)); - bitbuf >>= len; - bits -= len; - if ((diff & (1 << (len-1))) == 0) - diff -= (1 << len) - 1; - out[i] = diff; - } - return 0; -} - -void CLASS kodak_65000_load_raw() -{ - short buf[256]; - int row, col, len, pred[2], ret, i; - - for (row=0; row < height; row++) - for (col=0; col < width; col+=256) { - pred[0] = pred[1] = 0; - len = MIN (256, width-col); - ret = kodak_65000_decode (buf, len); - for (i=0; i < len; i++) - if ((RAW(row,col+i) = curve[ret ? buf[i] : - (pred[i & 1] += buf[i])]) >> 12) derror(); - } -} - -void CLASS kodak_ycbcr_load_raw() -{ - short buf[384], *bp; - int row, col, len, c, i, j, k, y[2][2], cb, cr, rgb[3]; - ushort *ip; - - for (row=0; row < height; row+=2) - for (col=0; col < width; col+=128) { - len = MIN (128, width-col); - kodak_65000_decode (buf, len*3); - y[0][1] = y[1][1] = cb = cr = 0; - for (bp=buf, i=0; i < len; i+=2, bp+=2) { - cb += bp[4]; - cr += bp[5]; - rgb[1] = -((cb + cr + 2) >> 2); - rgb[2] = rgb[1] + cb; - rgb[0] = rgb[1] + cr; - for (j=0; j < 2; j++) - for (k=0; k < 2; k++) { - if ((y[j][k] = y[j][k^1] + *bp++) >> 10) derror(); - ip = image[(row+j)*width + col+i+k]; - FORC3 ip[c] = curve[LIM(y[j][k]+rgb[c], 0, 0xfff)]; - } - } - } -} - -void CLASS kodak_rgb_load_raw() -{ - short buf[768], *bp; - int row, col, len, c, i, rgb[3]; - ushort *ip=image[0]; - - if (raw_image) free (raw_image); - raw_image = 0; - for (row=0; row < height; row++) - for (col=0; col < width; col+=256) { - len = MIN (256, width-col); - kodak_65000_decode (buf, len*3); - memset (rgb, 0, sizeof rgb); - for (bp=buf, i=0; i < len; i++, ip+=4) - FORC3 if ((ip[c] = rgb[c] += *bp++) >> 12) derror(); - } -} - -void CLASS kodak_thumb_load_raw() -{ - int row, col; - colors = thumb_misc >> 5; - for (row=0; row < height; row++) - for (col=0; col < width; col++) - read_shorts (image[row*width+col], colors); - maximum = (1 << (thumb_misc & 31)) - 1; -} - -void CLASS sony_decrypt (unsigned *data, int len, int start, int key) -{ - static unsigned pad[128], p; - - if (start) { - for (p=0; p < 4; p++) - pad[p] = key = key * 48828125 + 1; - pad[3] = pad[3] << 1 | (pad[0]^pad[2]) >> 31; - for (p=4; p < 127; p++) - pad[p] = (pad[p-4]^pad[p-2]) << 1 | (pad[p-3]^pad[p-1]) >> 31; - for (p=0; p < 127; p++) - pad[p] = htonl(pad[p]); - } - while (len--) - *data++ ^= pad[p++ & 127] = pad[(p+1) & 127] ^ pad[(p+65) & 127]; -} - -void CLASS sony_load_raw() -{ - uchar head[40]; - ushort *pixel; - unsigned i, key, row, col; - - fseek (ifp, 200896, SEEK_SET); - fseek (ifp, (unsigned) fgetc(ifp)*4 - 1, SEEK_CUR); - order = 0x4d4d; - key = get4(); - fseek (ifp, 164600, SEEK_SET); - fread (head, 1, 40, ifp); - sony_decrypt ((unsigned int *) head, 10, 1, key); - for (i=26; i-- > 22; ) - key = key << 8 | head[i]; - fseek (ifp, data_offset, SEEK_SET); - for (row=0; row < raw_height; row++) { - pixel = raw_image + row*raw_width; - if (fread (pixel, 2, raw_width, ifp) < raw_width) derror(); - sony_decrypt ((unsigned int *) pixel, raw_width/2, !row, key); - for (col=0; col < raw_width; col++) - if ((pixel[col] = ntohs(pixel[col])) >> 14) derror(); - } - maximum = 0x3ff0; -} - -void CLASS sony_arw_load_raw() -{ - ushort huff[32768]; - static const ushort tab[18] = - { 0xf11,0xf10,0xe0f,0xd0e,0xc0d,0xb0c,0xa0b,0x90a,0x809, - 0x708,0x607,0x506,0x405,0x304,0x303,0x300,0x202,0x201 }; - int i, c, n, col, row, len, diff, sum=0; - - for (n=i=0; i < 18; i++) - FORC(32768 >> (tab[i] >> 8)) huff[n++] = tab[i]; - getbits(-1); - for (col = raw_width; col--; ) - for (row=0; row < raw_height+1; row+=2) { - if (row == raw_height) row = 1; - len = getbithuff(15,huff); - diff = getbits(len); - if ((diff & (1 << (len-1))) == 0) - diff -= (1 << len) - 1; - if ((sum += diff) >> 12) derror(); - if (row < height) RAW(row,col) = sum; - } -} - -void CLASS sony_arw2_load_raw() -{ - uchar *data, *dp; - ushort pix[16]; - int row, col, val, max, min, imax, imin, sh, bit, i; - - data = (uchar *) malloc (raw_width); - merror (data, "sony_arw2_load_raw()"); - for (row=0; row < height; row++) { - fread (data, 1, raw_width, ifp); - for (dp=data, col=0; col < raw_width-30; dp+=16) { - max = 0x7ff & (val = sget4(dp)); - min = 0x7ff & val >> 11; - imax = 0x0f & val >> 22; - imin = 0x0f & val >> 26; - for (sh=0; sh < 4 && 0x80 << sh <= max-min; sh++); - for (bit=30, i=0; i < 16; i++) - if (i == imax) pix[i] = max; - else if (i == imin) pix[i] = min; - else { - pix[i] = ((sget2(dp+(bit >> 3)) >> (bit & 7) & 0x7f) << sh) + min; - if (pix[i] > 0x7ff) pix[i] = 0x7ff; - bit += 7; - } - for (i=0; i < 16; i++, col+=2) - if (col < width) RAW(row,col) = curve[pix[i] << 1] >> 2; - col -= col & 1 ? 1:31; - } - } - free (data); -} - -#define HOLE(row) ((holes >> (((row) - raw_height) & 7)) & 1) - -/* Kudos to Rich Taylor for figuring out SMaL's compression algorithm. */ -void CLASS smal_decode_segment (unsigned seg[2][2], int holes) -{ - uchar hist[3][13] = { - { 7, 7, 0, 0, 63, 55, 47, 39, 31, 23, 15, 7, 0 }, - { 7, 7, 0, 0, 63, 55, 47, 39, 31, 23, 15, 7, 0 }, - { 3, 3, 0, 0, 63, 47, 31, 15, 0 } }; - int low, high=0xff, carry=0, nbits=8; - int pix, s, count, bin, next, i, sym[3]; - uchar diff, pred[]={0,0}; - ushort data=0, range=0; - - fseek (ifp, seg[0][1]+1, SEEK_SET); - getbits(-1); - for (pix=seg[0][0]; pix < seg[1][0]; pix++) { - for (s=0; s < 3; s++) { - data = data << nbits | getbits(nbits); - if (carry < 0) - carry = (nbits += carry+1) < 1 ? nbits-1 : 0; - while (--nbits >= 0) - if ((data >> nbits & 0xff) == 0xff) break; - if (nbits > 0) - data = ((data & ((1 << (nbits-1)) - 1)) << 1) | - ((data + (((data & (1 << (nbits-1)))) << 1)) & (-1 << nbits)); - if (nbits >= 0) { - data += getbits(1); - carry = nbits - 8; - } - count = ((((data-range+1) & 0xffff) << 2) - 1) / (high >> 4); - for (bin=0; hist[s][bin+5] > count; bin++); - low = hist[s][bin+5] * (high >> 4) >> 2; - if (bin) high = hist[s][bin+4] * (high >> 4) >> 2; - high -= low; - for (nbits=0; high << nbits < 128; nbits++); - range = (range+low) << nbits; - high <<= nbits; - next = hist[s][1]; - if (++hist[s][2] > hist[s][3]) { - next = (next+1) & hist[s][0]; - hist[s][3] = (hist[s][next+4] - hist[s][next+5]) >> 2; - hist[s][2] = 1; - } - if (hist[s][hist[s][1]+4] - hist[s][hist[s][1]+5] > 1) { - if (bin < hist[s][1]) - for (i=bin; i < hist[s][1]; i++) hist[s][i+5]--; - else if (next <= bin) - for (i=hist[s][1]; i < bin; i++) hist[s][i+5]++; - } - hist[s][1] = next; - sym[s] = bin; - } - diff = sym[2] << 5 | sym[1] << 2 | (sym[0] & 3); - if (sym[0] & 4) - diff = diff ? -diff : 0x80; - if (ftell(ifp) + 12 >= seg[1][1]) - diff = 0; - raw_image[pix] = pred[pix & 1] += diff; - if (!(pix & 1) && HOLE(pix / raw_width)) pix += 2; - } - maximum = 0xff; -} - -void CLASS smal_v6_load_raw() -{ - unsigned seg[2][2]; - - fseek (ifp, 16, SEEK_SET); - seg[0][0] = 0; - seg[0][1] = get2(); - seg[1][0] = raw_width * raw_height; - seg[1][1] = INT_MAX; - smal_decode_segment (seg, 0); -} - -int CLASS median4 (int *p) -{ - int min, max, sum, i; - - min = max = sum = p[0]; - for (i=1; i < 4; i++) { - sum += p[i]; - if (min > p[i]) min = p[i]; - if (max < p[i]) max = p[i]; - } - return (sum - min - max) >> 1; -} - -void CLASS fill_holes (int holes) -{ - int row, col, val[4]; - - for (row=2; row < height-2; row++) { - if (!HOLE(row)) continue; - for (col=1; col < width-1; col+=4) { - val[0] = RAW(row-1,col-1); - val[1] = RAW(row-1,col+1); - val[2] = RAW(row+1,col-1); - val[3] = RAW(row+1,col+1); - RAW(row,col) = median4(val); - } - for (col=2; col < width-2; col+=4) - if (HOLE(row-2) || HOLE(row+2)) - RAW(row,col) = (RAW(row,col-2) + RAW(row,col+2)) >> 1; - else { - val[0] = RAW(row,col-2); - val[1] = RAW(row,col+2); - val[2] = RAW(row-2,col); - val[3] = RAW(row+2,col); - RAW(row,col) = median4(val); - } - } -} - -void CLASS smal_v9_load_raw() -{ - unsigned seg[256][2], offset, nseg, holes, i; - - fseek (ifp, 67, SEEK_SET); - offset = get4(); - nseg = fgetc(ifp); - fseek (ifp, offset, SEEK_SET); - for (i=0; i < nseg*2; i++) - seg[0][i] = get4() + data_offset*(i & 1); - fseek (ifp, 78, SEEK_SET); - holes = fgetc(ifp); - fseek (ifp, 88, SEEK_SET); - seg[nseg][0] = raw_height * raw_width; - seg[nseg][1] = get4() + data_offset; - for (i=0; i < nseg; i++) - smal_decode_segment (seg+i, holes); - if (holes) fill_holes (holes); -} - -void CLASS redcine_load_raw() -{ -#ifndef NO_JASPER - int c, row, col; - jas_stream_t *in; - jas_image_t *jimg; - jas_matrix_t *jmat; - jas_seqent_t *data; - ushort *img, *pix; - - jas_init(); - in = jas_stream_fopen (ifname, "rb"); - jas_stream_seek (in, data_offset+20, SEEK_SET); - jimg = jas_image_decode (in, -1, 0); - if (!jimg) longjmp (failure, 3); - jmat = jas_matrix_create (height/2, width/2); - merror (jmat, "redcine_load_raw()"); - img = (ushort *) calloc ((height+2)*(width+2), 2); - merror (img, "redcine_load_raw()"); - FORC4 { - jas_image_readcmpt (jimg, c, 0, 0, width/2, height/2, jmat); - data = jas_matrix_getref (jmat, 0, 0); - for (row = c >> 1; row < height; row+=2) - for (col = c & 1; col < width; col+=2) - img[(row+1)*(width+2)+col+1] = data[(row/2)*(width/2)+col/2]; - } - for (col=1; col <= width; col++) { - img[col] = img[2*(width+2)+col]; - img[(height+1)*(width+2)+col] = img[(height-1)*(width+2)+col]; - } - for (row=0; row < height+2; row++) { - img[row*(width+2)] = img[row*(width+2)+2]; - img[(row+1)*(width+2)-1] = img[(row+1)*(width+2)-3]; - } - for (row=1; row <= height; row++) { - pix = img + row*(width+2) + (col = 1 + (FC(row,1) & 1)); - for ( ; col <= width; col+=2, pix+=2) { - c = (((pix[0] - 0x800) << 3) + - pix[-(width+2)] + pix[width+2] + pix[-1] + pix[1]) >> 2; - pix[0] = LIM(c,0,4095); - } - } - for (row=0; row < height; row++) - for (col=0; col < width; col++) - RAW(row,col) = curve[img[(row+1)*(width+2)+col+1]]; - free (img); - jas_matrix_destroy (jmat); - jas_image_destroy (jimg); - jas_stream_close (in); -#endif -} - -/* RESTRICTED code starts here */ - -void CLASS foveon_decoder (unsigned size, unsigned code) -{ - static unsigned huff[1024]; - struct decode *cur; - int i, len; - - if (!code) { - for (i=0; i < size; i++) - huff[i] = get4(); - memset (first_decode, 0, sizeof first_decode); - free_decode = first_decode; - } - cur = free_decode++; - if (free_decode > first_decode+2048) { - fprintf (stderr,_("%s: decoder table overflow\n"), ifname); - longjmp (failure, 2); - } - if (code) - for (i=0; i < size; i++) - if (huff[i] == code) { - cur->leaf = i; - return; - } - if ((len = code >> 27) > 26) return; - code = (len+1) << 27 | (code & 0x3ffffff) << 1; - - cur->branch[0] = free_decode; - foveon_decoder (size, code); - cur->branch[1] = free_decode; - foveon_decoder (size, code+1); -} - -void CLASS foveon_thumb() -{ - unsigned bwide, row, col, bitbuf=0, bit=1, c, i; - char *buf; - struct decode *dindex; - short pred[3]; - - bwide = get4(); - fprintf (ofp, "P6\n%d %d\n255\n", thumb_width, thumb_height); - if (bwide > 0) { - if (bwide < thumb_width*3) return; - buf = (char *) malloc (bwide); - merror (buf, "foveon_thumb()"); - for (row=0; row < thumb_height; row++) { - fread (buf, 1, bwide, ifp); - fwrite (buf, 3, thumb_width, ofp); - } - free (buf); - return; - } - foveon_decoder (256, 0); - - for (row=0; row < thumb_height; row++) { - memset (pred, 0, sizeof pred); - if (!bit) get4(); - for (bit=col=0; col < thumb_width; col++) - FORC3 { - for (dindex=first_decode; dindex->branch[0]; ) { - if ((bit = (bit-1) & 31) == 31) - for (i=0; i < 4; i++) - bitbuf = (bitbuf << 8) + fgetc(ifp); - dindex = dindex->branch[bitbuf >> bit & 1]; - } - pred[c] += dindex->leaf; - fputc (pred[c], ofp); - } - } -} - -void CLASS foveon_sd_load_raw() -{ - struct decode *dindex; - short diff[1024]; - unsigned bitbuf=0; - int pred[3], row, col, bit=-1, c, i; - - read_shorts ((ushort *) diff, 1024); - if (!load_flags) foveon_decoder (1024, 0); - - for (row=0; row < height; row++) { - memset (pred, 0, sizeof pred); - if (!bit && !load_flags && atoi(model+2) < 14) get4(); - for (col=bit=0; col < width; col++) { - if (load_flags) { - bitbuf = get4(); - FORC3 pred[2-c] += diff[bitbuf >> c*10 & 0x3ff]; - } - else FORC3 { - for (dindex=first_decode; dindex->branch[0]; ) { - if ((bit = (bit-1) & 31) == 31) - for (i=0; i < 4; i++) - bitbuf = (bitbuf << 8) + fgetc(ifp); - dindex = dindex->branch[bitbuf >> bit & 1]; - } - pred[c] += diff[dindex->leaf]; - if (pred[c] >> 16 && ~pred[c] >> 16) derror(); - } - FORC3 image[row*width+col][c] = pred[c]; - } - } -} - -void CLASS foveon_huff (ushort *huff) -{ - int i, j, clen, code; - - huff[0] = 8; - for (i=0; i < 13; i++) { - clen = getc(ifp); - code = getc(ifp); - for (j=0; j < 256 >> clen; ) - huff[code+ ++j] = clen << 8 | i; - } - get2(); -} - -void CLASS foveon_dp_load_raw() -{ - unsigned c, roff[4], row, col, diff; - ushort huff[258], vpred, hpred; - - fseek (ifp, 8, SEEK_CUR); - foveon_huff (huff); - roff[0] = 48; - FORC3 roff[c+1] = -(-(roff[c] + get4()) & -16); - FORC3 { - fseek (ifp, data_offset+roff[c], SEEK_SET); - getbits(-1); - vpred = 1024; - for (row=0; row < height; row++) { - for (col=0; col < width; col++) { - diff = ljpeg_diff(huff); - if (col) hpred += diff; - else hpred = vpred += diff; - image[row*width+col][c] = hpred; - } - } - } -} - -void CLASS foveon_load_camf() -{ - unsigned type, wide, high, i, j, row, col, diff; - ushort huff[258], vpred[2][2] = {{512,512},{512,512}}, hpred[2]; - - fseek (ifp, meta_offset, SEEK_SET); - type = get4(); get4(); get4(); - wide = get4(); - high = get4(); - if (type == 2) { - fread (meta_data, 1, meta_length, ifp); - for (i=0; i < meta_length; i++) { - high = (high * 1597 + 51749) % 244944; - wide = high * (INT64) 301593171 >> 24; - meta_data[i] ^= ((((high << 8) - wide) >> 1) + wide) >> 17; - } - } else if (type == 4) { - free (meta_data); - meta_data = (char *) malloc (meta_length = wide*high*3/2); - merror (meta_data, "foveon_load_camf()"); - foveon_huff (huff); - get4(); - getbits(-1); - for (j=row=0; row < high; row++) { - for (col=0; col < wide; col++) { - diff = ljpeg_diff(huff); - if (col < 2) hpred[col] = vpred[row & 1][col] += diff; - else hpred[col & 1] += diff; - if (col & 1) { - meta_data[j++] = hpred[0] >> 4; - meta_data[j++] = hpred[0] << 4 | hpred[1] >> 8; - meta_data[j++] = hpred[1]; - } - } - } - } else - fprintf (stderr,_("%s has unknown CAMF type %d.\n"), ifname, type); -} - -const char * CLASS foveon_camf_param (const char *block, const char *param) -{ - unsigned idx, num; - char *pos, *cp, *dp; - - for (idx=0; idx < meta_length; idx += sget4(pos+8)) { - pos = meta_data + idx; - if (strncmp (pos, "CMb", 3)) break; - if (pos[3] != 'P') continue; - if (strcmp (block, pos+sget4(pos+12))) continue; - cp = pos + sget4(pos+16); - num = sget4(cp); - dp = pos + sget4(cp+4); - while (num--) { - cp += 8; - if (!strcmp (param, dp+sget4(cp))) - return dp+sget4(cp+4); - } - } - return 0; -} - -void * CLASS foveon_camf_matrix (unsigned dim[3], const char *name) -{ - unsigned i, idx, type, ndim, size, *mat; - char *pos, *cp, *dp; - double dsize; - - for (idx=0; idx < meta_length; idx += sget4(pos+8)) { - pos = meta_data + idx; - if (strncmp (pos, "CMb", 3)) break; - if (pos[3] != 'M') continue; - if (strcmp (name, pos+sget4(pos+12))) continue; - dim[0] = dim[1] = dim[2] = 1; - cp = pos + sget4(pos+16); - type = sget4(cp); - if ((ndim = sget4(cp+4)) > 3) break; - dp = pos + sget4(cp+8); - for (i=ndim; i--; ) { - cp += 12; - dim[i] = sget4(cp); - } - if ((dsize = (double) dim[0]*dim[1]*dim[2]) > meta_length/4) break; - mat = (unsigned *) malloc ((size = dsize) * 4); - merror (mat, "foveon_camf_matrix()"); - for (i=0; i < size; i++) - if (type && type != 6) - mat[i] = sget4(dp + i*4); - else - mat[i] = sget4(dp + i*2) & 0xffff; - return mat; - } - fprintf (stderr,_("%s: \"%s\" matrix not found!\n"), ifname, name); - return 0; -} - -int CLASS foveon_fixed (void *ptr, int size, const char *name) -{ - void *dp; - unsigned dim[3]; - - if (!name) return 0; - dp = foveon_camf_matrix (dim, name); - if (!dp) return 0; - memcpy (ptr, dp, size*4); - free (dp); - return 1; -} - -float CLASS foveon_avg (short *pix, int range[2], float cfilt) -{ - int i; - float val, min=FLT_MAX, max=-FLT_MAX, sum=0; - - for (i=range[0]; i <= range[1]; i++) { - sum += val = pix[i*4] + (pix[i*4]-pix[(i-1)*4]) * cfilt; - if (min > val) min = val; - if (max < val) max = val; - } - if (range[1] - range[0] == 1) return sum/2; - return (sum - min - max) / (range[1] - range[0] - 1); -} - -short * CLASS foveon_make_curve (double max, double mul, double filt) -{ - short *curve; - unsigned i, size; - double x; - - if (!filt) filt = 0.8; - size = 4*M_PI*max / filt; - if (size == UINT_MAX) size--; - curve = (short *) calloc (size+1, sizeof *curve); - merror (curve, "foveon_make_curve()"); - curve[0] = size; - for (i=0; i < size; i++) { - x = i*filt/max/4; - curve[i+1] = (cos(x)+1)/2 * tanh(i*filt/mul) * mul + 0.5; - } - return curve; -} - -void CLASS foveon_make_curves - (short **curvep, float dq[3], float div[3], float filt) -{ - double mul[3], max=0; - int c; - - FORC3 mul[c] = dq[c]/div[c]; - FORC3 if (max < mul[c]) max = mul[c]; - FORC3 curvep[c] = foveon_make_curve (max, mul[c], filt); -} - -int CLASS foveon_apply_curve (short *curve, int i) -{ - if (abs(i) >= curve[0]) return 0; - return i < 0 ? -curve[1-i] : curve[1+i]; -} - -#define image ((short (*)[4]) image) - -void CLASS foveon_interpolate() -{ - static const short hood[] = { -1,-1, -1,0, -1,1, 0,-1, 0,1, 1,-1, 1,0, 1,1 }; - short *pix, prev[3], *curve[8], (*shrink)[3]; - float cfilt=0, ddft[3][3][2], ppm[3][3][3]; - float cam_xyz[3][3], correct[3][3], last[3][3], trans[3][3]; - float chroma_dq[3], color_dq[3], diag[3][3], div[3]; - float (*black)[3], (*sgain)[3], (*sgrow)[3]; - float fsum[3], val, frow, num; - int row, col, c, i, j, diff, sgx, irow, sum, min, max, limit; - int dscr[2][2], dstb[4], (*smrow[7])[3], total[4], ipix[3]; - int work[3][3], smlast, smred, smred_p=0, dev[3]; - int satlev[3], keep[4], active[4]; - unsigned dim[3], *badpix; - double dsum=0, trsum[3]; - char str[128]; - const char* cp; - - if (verbose) - fprintf (stderr,_("Foveon interpolation...\n")); - - foveon_load_camf(); - foveon_fixed (dscr, 4, "DarkShieldColRange"); - foveon_fixed (ppm[0][0], 27, "PostPolyMatrix"); - foveon_fixed (satlev, 3, "SaturationLevel"); - foveon_fixed (keep, 4, "KeepImageArea"); - foveon_fixed (active, 4, "ActiveImageArea"); - foveon_fixed (chroma_dq, 3, "ChromaDQ"); - foveon_fixed (color_dq, 3, - foveon_camf_param ("IncludeBlocks", "ColorDQ") ? - "ColorDQ" : "ColorDQCamRGB"); - if (foveon_camf_param ("IncludeBlocks", "ColumnFilter")) - foveon_fixed (&cfilt, 1, "ColumnFilter"); - - memset (ddft, 0, sizeof ddft); - if (!foveon_camf_param ("IncludeBlocks", "DarkDrift") - || !foveon_fixed (ddft[1][0], 12, "DarkDrift")) - for (i=0; i < 2; i++) { - foveon_fixed (dstb, 4, i ? "DarkShieldBottom":"DarkShieldTop"); - for (row = dstb[1]; row <= dstb[3]; row++) - for (col = dstb[0]; col <= dstb[2]; col++) - FORC3 ddft[i+1][c][1] += (short) image[row*width+col][c]; - FORC3 ddft[i+1][c][1] /= (dstb[3]-dstb[1]+1) * (dstb[2]-dstb[0]+1); - } - - if (!(cp = foveon_camf_param ("WhiteBalanceIlluminants", model2))) - { fprintf (stderr,_("%s: Invalid white balance \"%s\"\n"), ifname, model2); - return; } - foveon_fixed (cam_xyz, 9, cp); - foveon_fixed (correct, 9, - foveon_camf_param ("WhiteBalanceCorrections", model2)); - memset (last, 0, sizeof last); - for (i=0; i < 3; i++) - for (j=0; j < 3; j++) - FORC3 last[i][j] += correct[i][c] * cam_xyz[c][j]; - - #define LAST(x,y) last[(i+x)%3][(c+y)%3] - for (i=0; i < 3; i++) - FORC3 diag[c][i] = LAST(1,1)*LAST(2,2) - LAST(1,2)*LAST(2,1); - #undef LAST - FORC3 div[c] = diag[c][0]*0.3127 + diag[c][1]*0.329 + diag[c][2]*0.3583; - sprintf (str, "%sRGBNeutral", model2); - if (foveon_camf_param ("IncludeBlocks", str)) - foveon_fixed (div, 3, str); - num = 0; - FORC3 if (num < div[c]) num = div[c]; - FORC3 div[c] /= num; - - memset (trans, 0, sizeof trans); - for (i=0; i < 3; i++) - for (j=0; j < 3; j++) - FORC3 trans[i][j] += rgb_cam[i][c] * last[c][j] * div[j]; - FORC3 trsum[c] = trans[c][0] + trans[c][1] + trans[c][2]; - dsum = (6*trsum[0] + 11*trsum[1] + 3*trsum[2]) / 20; - for (i=0; i < 3; i++) - FORC3 last[i][c] = trans[i][c] * dsum / trsum[i]; - memset (trans, 0, sizeof trans); - for (i=0; i < 3; i++) - for (j=0; j < 3; j++) - FORC3 trans[i][j] += (i==c ? 32 : -1) * last[c][j] / 30; - - foveon_make_curves (curve, color_dq, div, cfilt); - FORC3 chroma_dq[c] /= 3; - foveon_make_curves (curve+3, chroma_dq, div, cfilt); - FORC3 dsum += chroma_dq[c] / div[c]; - curve[6] = foveon_make_curve (dsum, dsum, cfilt); - curve[7] = foveon_make_curve (dsum*2, dsum*2, cfilt); - - sgain = (float (*)[3]) foveon_camf_matrix (dim, "SpatialGain"); - if (!sgain) return; - sgrow = (float (*)[3]) calloc (dim[1], sizeof *sgrow); - sgx = (width + dim[1]-2) / (dim[1]-1); - - black = (float (*)[3]) calloc (height, sizeof *black); - for (row=0; row < height; row++) { - for (i=0; i < 6; i++) - ddft[0][0][i] = ddft[1][0][i] + - row / (height-1.0) * (ddft[2][0][i] - ddft[1][0][i]); - FORC3 black[row][c] = - ( foveon_avg (image[row*width]+c, dscr[0], cfilt) + - foveon_avg (image[row*width]+c, dscr[1], cfilt) * 3 - - ddft[0][c][0] ) / 4 - ddft[0][c][1]; - } - memcpy (black, black+8, sizeof *black*8); - memcpy (black+height-11, black+height-22, 11*sizeof *black); - memcpy (last, black, sizeof last); - - for (row=1; row < height-1; row++) { - FORC3 if (last[1][c] > last[0][c]) { - if (last[1][c] > last[2][c]) - black[row][c] = (last[0][c] > last[2][c]) ? last[0][c]:last[2][c]; - } else - if (last[1][c] < last[2][c]) - black[row][c] = (last[0][c] < last[2][c]) ? last[0][c]:last[2][c]; - memmove (last, last+1, 2*sizeof last[0]); - memcpy (last[2], black[row+1], sizeof last[2]); - } - FORC3 black[row][c] = (last[0][c] + last[1][c])/2; - FORC3 black[0][c] = (black[1][c] + black[3][c])/2; - - val = 1 - exp(-1/24.0); - memcpy (fsum, black, sizeof fsum); - for (row=1; row < height; row++) - FORC3 fsum[c] += black[row][c] = - (black[row][c] - black[row-1][c])*val + black[row-1][c]; - memcpy (last[0], black[height-1], sizeof last[0]); - FORC3 fsum[c] /= height; - for (row = height; row--; ) - FORC3 last[0][c] = black[row][c] = - (black[row][c] - fsum[c] - last[0][c])*val + last[0][c]; - - memset (total, 0, sizeof total); - for (row=2; row < height; row+=4) - for (col=2; col < width; col+=4) { - FORC3 total[c] += (short) image[row*width+col][c]; - total[3]++; - } - for (row=0; row < height; row++) - FORC3 black[row][c] += fsum[c]/2 + total[c]/(total[3]*100.0); - - for (row=0; row < height; row++) { - for (i=0; i < 6; i++) - ddft[0][0][i] = ddft[1][0][i] + - row / (height-1.0) * (ddft[2][0][i] - ddft[1][0][i]); - pix = image[row*width]; - memcpy (prev, pix, sizeof prev); - frow = row / (height-1.0) * (dim[2]-1); - if ((irow = frow) == dim[2]-1) irow--; - frow -= irow; - for (i=0; i < dim[1]; i++) - FORC3 sgrow[i][c] = sgain[ irow *dim[1]+i][c] * (1-frow) + - sgain[(irow+1)*dim[1]+i][c] * frow; - for (col=0; col < width; col++) { - FORC3 { - diff = pix[c] - prev[c]; - prev[c] = pix[c]; - ipix[c] = pix[c] + floor ((diff + (diff*diff >> 14)) * cfilt - - ddft[0][c][1] - ddft[0][c][0] * ((float) col/width - 0.5) - - black[row][c] ); - } - FORC3 { - work[0][c] = ipix[c] * ipix[c] >> 14; - work[2][c] = ipix[c] * work[0][c] >> 14; - work[1][2-c] = ipix[(c+1) % 3] * ipix[(c+2) % 3] >> 14; - } - FORC3 { - for (val=i=0; i < 3; i++) - for ( j=0; j < 3; j++) - val += ppm[c][i][j] * work[i][j]; - ipix[c] = floor ((ipix[c] + floor(val)) * - ( sgrow[col/sgx ][c] * (sgx - col%sgx) + - sgrow[col/sgx+1][c] * (col%sgx) ) / sgx / div[c]); - if (ipix[c] > 32000) ipix[c] = 32000; - pix[c] = ipix[c]; - } - pix += 4; - } - } - free (black); - free (sgrow); - free (sgain); - - if ((badpix = (unsigned int *) foveon_camf_matrix (dim, "BadPixels"))) { - for (i=0; i < dim[0]; i++) { - col = (badpix[i] >> 8 & 0xfff) - keep[0]; - row = (badpix[i] >> 20 ) - keep[1]; - if ((unsigned)(row-1) > height-3 || (unsigned)(col-1) > width-3) - continue; - memset (fsum, 0, sizeof fsum); - for (sum=j=0; j < 8; j++) - if (badpix[i] & (1 << j)) { - FORC3 fsum[c] += (short) - image[(row+hood[j*2])*width+col+hood[j*2+1]][c]; - sum++; - } - if (sum) FORC3 image[row*width+col][c] = fsum[c]/sum; - } - free (badpix); - } - - /* Array for 5x5 Gaussian averaging of red values */ - smrow[6] = (int (*)[3]) calloc (width*5, sizeof **smrow); - merror (smrow[6], "foveon_interpolate()"); - for (i=0; i < 5; i++) - smrow[i] = smrow[6] + i*width; - - /* Sharpen the reds against these Gaussian averages */ - for (smlast=-1, row=2; row < height-2; row++) { - while (smlast < row+2) { - for (i=0; i < 6; i++) - smrow[(i+5) % 6] = smrow[i]; - pix = image[++smlast*width+2]; - for (col=2; col < width-2; col++) { - smrow[4][col][0] = - (pix[0]*6 + (pix[-4]+pix[4])*4 + pix[-8]+pix[8] + 8) >> 4; - pix += 4; - } - } - pix = image[row*width+2]; - for (col=2; col < width-2; col++) { - smred = ( 6 * smrow[2][col][0] - + 4 * (smrow[1][col][0] + smrow[3][col][0]) - + smrow[0][col][0] + smrow[4][col][0] + 8 ) >> 4; - if (col == 2) - smred_p = smred; - i = pix[0] + ((pix[0] - ((smred*7 + smred_p) >> 3)) >> 3); - if (i > 32000) i = 32000; - pix[0] = i; - smred_p = smred; - pix += 4; - } - } - - /* Adjust the brighter pixels for better linearity */ - min = 0xffff; - FORC3 { - i = satlev[c] / div[c]; - if (min > i) min = i; - } - limit = min * 9 >> 4; - for (pix=image[0]; pix < image[height*width]; pix+=4) { - if (pix[0] <= limit || pix[1] <= limit || pix[2] <= limit) - continue; - min = max = pix[0]; - for (c=1; c < 3; c++) { - if (min > pix[c]) min = pix[c]; - if (max < pix[c]) max = pix[c]; - } - if (min >= limit*2) { - pix[0] = pix[1] = pix[2] = max; - } else { - i = 0x4000 - ((min - limit) << 14) / limit; - i = 0x4000 - (i*i >> 14); - i = i*i >> 14; - FORC3 pix[c] += (max - pix[c]) * i >> 14; - } - } -/* - Because photons that miss one detector often hit another, - the sum R+G+B is much less noisy than the individual colors. - So smooth the hues without smoothing the total. - */ - for (smlast=-1, row=2; row < height-2; row++) { - while (smlast < row+2) { - for (i=0; i < 6; i++) - smrow[(i+5) % 6] = smrow[i]; - pix = image[++smlast*width+2]; - for (col=2; col < width-2; col++) { - FORC3 smrow[4][col][c] = (pix[c-4]+2*pix[c]+pix[c+4]+2) >> 2; - pix += 4; - } - } - pix = image[row*width+2]; - for (col=2; col < width-2; col++) { - FORC3 dev[c] = -foveon_apply_curve (curve[7], pix[c] - - ((smrow[1][col][c] + 2*smrow[2][col][c] + smrow[3][col][c]) >> 2)); - sum = (dev[0] + dev[1] + dev[2]) >> 3; - FORC3 pix[c] += dev[c] - sum; - pix += 4; - } - } - for (smlast=-1, row=2; row < height-2; row++) { - while (smlast < row+2) { - for (i=0; i < 6; i++) - smrow[(i+5) % 6] = smrow[i]; - pix = image[++smlast*width+2]; - for (col=2; col < width-2; col++) { - FORC3 smrow[4][col][c] = - (pix[c-8]+pix[c-4]+pix[c]+pix[c+4]+pix[c+8]+2) >> 2; - pix += 4; - } - } - pix = image[row*width+2]; - for (col=2; col < width-2; col++) { - for (total[3]=375, sum=60, c=0; c < 3; c++) { - for (total[c]=i=0; i < 5; i++) - total[c] += smrow[i][col][c]; - total[3] += total[c]; - sum += pix[c]; - } - if (sum < 0) sum = 0; - j = total[3] > 375 ? (sum << 16) / total[3] : sum * 174; - FORC3 pix[c] += foveon_apply_curve (curve[6], - ((j*total[c] + 0x8000) >> 16) - pix[c]); - pix += 4; - } - } - - /* Transform the image to a different colorspace */ - for (pix=image[0]; pix < image[height*width]; pix+=4) { - FORC3 pix[c] -= foveon_apply_curve (curve[c], pix[c]); - sum = (pix[0]+pix[1]+pix[1]+pix[2]) >> 2; - FORC3 pix[c] -= foveon_apply_curve (curve[c], pix[c]-sum); - FORC3 { - for (dsum=i=0; i < 3; i++) - dsum += trans[c][i] * pix[i]; - if (dsum < 0) dsum = 0; - if (dsum > 24000) dsum = 24000; - ipix[c] = dsum + 0.5; - } - FORC3 pix[c] = ipix[c]; - } - - /* Smooth the image bottom-to-top and save at 1/4 scale */ - shrink = (short (*)[3]) calloc ((width/4) * (height/4), sizeof *shrink); - merror (shrink, "foveon_interpolate()"); - for (row = height/4; row--; ) - for (col=0; col < width/4; col++) { - ipix[0] = ipix[1] = ipix[2] = 0; - for (i=0; i < 4; i++) - for (j=0; j < 4; j++) - FORC3 ipix[c] += image[(row*4+i)*width+col*4+j][c]; - FORC3 - if (row+2 > height/4) - shrink[row*(width/4)+col][c] = ipix[c] >> 4; - else - shrink[row*(width/4)+col][c] = - (shrink[(row+1)*(width/4)+col][c]*1840 + ipix[c]*141 + 2048) >> 12; - } - /* From the 1/4-scale image, smooth right-to-left */ - for (row=0; row < (height & ~3); row++) { - ipix[0] = ipix[1] = ipix[2] = 0; - if ((row & 3) == 0) - for (col = width & ~3 ; col--; ) - FORC3 smrow[0][col][c] = ipix[c] = - (shrink[(row/4)*(width/4)+col/4][c]*1485 + ipix[c]*6707 + 4096) >> 13; - - /* Then smooth left-to-right */ - ipix[0] = ipix[1] = ipix[2] = 0; - for (col=0; col < (width & ~3); col++) - FORC3 smrow[1][col][c] = ipix[c] = - (smrow[0][col][c]*1485 + ipix[c]*6707 + 4096) >> 13; - - /* Smooth top-to-bottom */ - if (row == 0) - memcpy (smrow[2], smrow[1], sizeof **smrow * width); - else - for (col=0; col < (width & ~3); col++) - FORC3 smrow[2][col][c] = - (smrow[2][col][c]*6707 + smrow[1][col][c]*1485 + 4096) >> 13; - - /* Adjust the chroma toward the smooth values */ - for (col=0; col < (width & ~3); col++) { - for (i=j=30, c=0; c < 3; c++) { - i += smrow[2][col][c]; - j += image[row*width+col][c]; - } - j = (j << 16) / i; - for (sum=c=0; c < 3; c++) { - ipix[c] = foveon_apply_curve (curve[c+3], - ((smrow[2][col][c] * j + 0x8000) >> 16) - image[row*width+col][c]); - sum += ipix[c]; - } - sum >>= 3; - FORC3 { - i = image[row*width+col][c] + ipix[c] - sum; - if (i < 0) i = 0; - image[row*width+col][c] = i; - } - } - } - free (shrink); - free (smrow[6]); - for (i=0; i < 8; i++) - free (curve[i]); - - /* Trim off the black border */ - active[1] -= keep[1]; - active[3] -= 2; - i = active[2] - active[0]; - for (row=0; row < active[3]-active[1]; row++) - memcpy (image[row*i], image[(row+active[1])*width+active[0]], - i * sizeof *image); - width = i; - height = row; -} -#undef image - -/* RESTRICTED code ends here */ - -void CLASS crop_masked_pixels() -{ - int row, col; - unsigned r, c, m, mblack[8], zero, val; - - if (load_raw == &CLASS phase_one_load_raw || - load_raw == &CLASS phase_one_load_raw_c) - phase_one_correct(); - if (fuji_width) { - for (row=0; row < raw_height-top_margin*2; row++) { - for (col=0; col < fuji_width << !fuji_layout; col++) { - if (fuji_layout) { - r = fuji_width - 1 - col + (row >> 1); - c = col + ((row+1) >> 1); - } else { - r = fuji_width - 1 + row - (col >> 1); - c = row + ((col+1) >> 1); - } - if (r < height && c < width) - BAYER(r,c) = RAW(row+top_margin,col+left_margin); - } - } - } else { - for (row=0; row < height; row++) - for (col=0; col < width; col++) - BAYER2(row,col) = RAW(row+top_margin,col+left_margin); - } - if (mask[0][3]) goto mask_set; - if (load_raw == &CLASS canon_load_raw || - load_raw == &CLASS lossless_jpeg_load_raw) { - mask[0][1] = mask[1][1] = 2; - mask[0][3] = -2; - goto sides; - } - if (load_raw == &CLASS sony_load_raw) { - mask[0][3] = 9; - goto sides; - } - if (load_raw == &CLASS canon_600_load_raw || - (load_raw == &CLASS eight_bit_load_raw && strncmp(model,"DC2",3)) || - load_raw == &CLASS kodak_262_load_raw || - (load_raw == &CLASS packed_load_raw && (load_flags & 32))) { -sides: - mask[0][0] = mask[1][0] = top_margin; - mask[0][2] = mask[1][2] = top_margin+height; - mask[0][3] += left_margin; - mask[1][1] += left_margin+width; - mask[1][3] += raw_width; - } - if (load_raw == &CLASS nokia_load_raw) { - mask[0][2] = top_margin; - mask[0][3] = width; - } -mask_set: - memset (mblack, 0, sizeof mblack); - for (zero=m=0; m < 8; m++) - for (row=mask[m][0]; row < mask[m][2]; row++) - for (col=mask[m][1]; col < mask[m][3]; col++) { - c = FC(row-top_margin,col-left_margin); - mblack[c] += val = RAW(row,col); - mblack[4+c]++; - zero += !val; - } - if (load_raw == &CLASS canon_600_load_raw && width < raw_width) { - black = (mblack[0]+mblack[1]+mblack[2]+mblack[3]) / - (mblack[4]+mblack[5]+mblack[6]+mblack[7]) - 4; - canon_600_correct(); - } else if (zero < mblack[4] && mblack[5] && mblack[6] && mblack[7]) - FORC4 cblack[c] = mblack[c] / mblack[4+c]; -} - -void CLASS remove_zeroes() -{ - unsigned row, col, tot, n, r, c; - - for (row=0; row < height; row++) - for (col=0; col < width; col++) - if (BAYER(row,col) == 0) { - tot = n = 0; - for (r = row-2; r <= row+2; r++) - for (c = col-2; c <= col+2; c++) - if (r < height && c < width && - FC(r,c) == FC(row,col) && BAYER(r,c)) - tot += (n++,BAYER(r,c)); - if (n) BAYER(row,col) = tot/n; - } -} - -/* - Seach from the current directory up to the root looking for - a ".badpixels" file, and fix those pixels now. - */ -void CLASS bad_pixels (const char *cfname) -{ - FILE *fp=0; - char *fname, *cp, line[128]; - int len, time, row, col, r, c, rad, tot, n, fixed=0; - - if (!filters) return; - if (cfname) - fp = fopen (cfname, "r"); - else { - for (len=32 ; ; len *= 2) { - fname = (char *) malloc (len); - if (!fname) return; - if (getcwd (fname, len-16)) break; - free (fname); - if (errno != ERANGE) return; - } -#if defined(WIN32) || defined(DJGPP) - if (fname[1] == ':') - memmove (fname, fname+2, len-2); - for (cp=fname; *cp; cp++) - if (*cp == '\\') *cp = '/'; -#endif - cp = fname + strlen(fname); - if (cp[-1] == '/') cp--; - while (*fname == '/') { - strcpy (cp, "/.badpixels"); - if ((fp = fopen (fname, "r"))) break; - if (cp == fname) break; - while (*--cp != '/'); - } - free (fname); - } - if (!fp) return; - while (fgets (line, 128, fp)) { - cp = strchr (line, '#'); - if (cp) *cp = 0; - if (sscanf (line, "%d %d %d", &col, &row, &time) != 3) continue; - if ((unsigned) col >= width || (unsigned) row >= height) continue; - if (time > timestamp) continue; - for (tot=n=0, rad=1; rad < 3 && n==0; rad++) - for (r = row-rad; r <= row+rad; r++) - for (c = col-rad; c <= col+rad; c++) - if ((unsigned) r < height && (unsigned) c < width && - (r != row || c != col) && fcol(r,c) == fcol(row,col)) { - tot += BAYER2(r,c); - n++; - } - BAYER2(row,col) = tot/n; - if (verbose) { - if (!fixed++) - fprintf (stderr,_("Fixed dead pixels at:")); - fprintf (stderr, " %d,%d", col, row); - } - } - if (fixed) fputc ('\n', stderr); - fclose (fp); -} - -void CLASS subtract (const char *fname) -{ - FILE *fp; - int dim[3]={0,0,0}, comment=0, number=0, error=0, nd=0, c, row, col; - ushort *pixel; - - if (!(fp = fopen (fname, "rb"))) { - perror (fname); return; - } - if (fgetc(fp) != 'P' || fgetc(fp) != '5') error = 1; - while (!error && nd < 3 && (c = fgetc(fp)) != EOF) { - if (c == '#') comment = 1; - if (c == '\n') comment = 0; - if (comment) continue; - if (isdigit(c)) number = 1; - if (number) { - if (isdigit(c)) dim[nd] = dim[nd]*10 + c -'0'; - else if (isspace(c)) { - number = 0; nd++; - } else error = 1; - } - } - if (error || nd < 3) { - fprintf (stderr,_("%s is not a valid PGM file!\n"), fname); - fclose (fp); return; - } else if (dim[0] != width || dim[1] != height || dim[2] != 65535) { - fprintf (stderr,_("%s has the wrong dimensions!\n"), fname); - fclose (fp); return; - } - pixel = (ushort *) calloc (width, sizeof *pixel); - merror (pixel, "subtract()"); - for (row=0; row < height; row++) { - fread (pixel, 2, width, fp); - for (col=0; col < width; col++) - BAYER(row,col) = MAX (BAYER(row,col) - ntohs(pixel[col]), 0); - } - free (pixel); - fclose (fp); - memset (cblack, 0, sizeof cblack); - black = 0; -} - -void CLASS gamma_curve (double pwr, double ts, int mode, int imax) -{ - int i; - double g[6], bnd[2]={0,0}, r; - - g[0] = pwr; - g[1] = ts; - g[2] = g[3] = g[4] = 0; - bnd[g[1] >= 1] = 1; - if (g[1] && (g[1]-1)*(g[0]-1) <= 0) { - for (i=0; i < 48; i++) { - g[2] = (bnd[0] + bnd[1])/2; - if (g[0]) bnd[(pow(g[2]/g[1],-g[0]) - 1)/g[0] - 1/g[2] > -1] = g[2]; - else bnd[g[2]/exp(1-1/g[2]) < g[1]] = g[2]; - } - g[3] = g[2] / g[1]; - if (g[0]) g[4] = g[2] * (1/g[0] - 1); - } - if (g[0]) g[5] = 1 / (g[1]*SQR(g[3])/2 - g[4]*(1 - g[3]) + - (1 - pow(g[3],1+g[0]))*(1 + g[4])/(1 + g[0])) - 1; - else g[5] = 1 / (g[1]*SQR(g[3])/2 + 1 - - g[2] - g[3] - g[2]*g[3]*(log(g[3]) - 1)) - 1; - if (!mode--) { - memcpy (gamm, g, sizeof gamm); - return; - } - for (i=0; i < 0x10000; i++) { - curve[i] = 0xffff; - if ((r = (double) i / imax) < 1) - curve[i] = 0x10000 * ( mode - ? (r < g[3] ? r*g[1] : (g[0] ? pow( r,g[0])*(1+g[4])-g[4] : log(r)*g[2]+1)) - : (r < g[2] ? r/g[1] : (g[0] ? pow((r+g[4])/(1+g[4]),1/g[0]) : exp((r-1)/g[2])))); - } -} - -void CLASS pseudoinverse (double (*in)[3], double (*out)[3], int size) -{ - double work[3][6], num; - int i, j, k; - - for (i=0; i < 3; i++) { - for (j=0; j < 6; j++) - work[i][j] = j == i+3; - for (j=0; j < 3; j++) - for (k=0; k < size; k++) - work[i][j] += in[k][i] * in[k][j]; - } - for (i=0; i < 3; i++) { - num = work[i][i]; - for (j=0; j < 6; j++) - work[i][j] /= num; - for (k=0; k < 3; k++) { - if (k==i) continue; - num = work[k][i]; - for (j=0; j < 6; j++) - work[k][j] -= work[i][j] * num; - } - } - for (i=0; i < size; i++) - for (j=0; j < 3; j++) - for (out[i][j]=k=0; k < 3; k++) - out[i][j] += work[j][k+3] * in[i][k]; -} - -void CLASS cam_xyz_coeff (double cam_xyz[4][3]) -{ - double cam_rgb[4][3], inverse[4][3], num; - int i, j, k; - - for (i=0; i < colors; i++) /* Multiply out XYZ colorspace */ - for (j=0; j < 3; j++) - for (cam_rgb[i][j] = k=0; k < 3; k++) - cam_rgb[i][j] += cam_xyz[i][k] * xyz_rgb[k][j]; - - for (i=0; i < colors; i++) { /* Normalize cam_rgb so that */ - for (num=j=0; j < 3; j++) /* cam_rgb * (1,1,1) is (1,1,1,1) */ - num += cam_rgb[i][j]; - for (j=0; j < 3; j++) - cam_rgb[i][j] /= num; - pre_mul[i] = 1 / num; - } - pseudoinverse (cam_rgb, inverse, colors); - for (raw_color = i=0; i < 3; i++) - for (j=0; j < colors; j++) - rgb_cam[i][j] = inverse[j][i]; -} - -#ifdef COLORCHECK -void CLASS colorcheck() -{ -#define NSQ 24 -// Coordinates of the GretagMacbeth ColorChecker squares -// width, height, 1st_column, 1st_row - int cut[NSQ][4]; // you must set these -// ColorChecker Chart under 6500-kelvin illumination - static const double gmb_xyY[NSQ][3] = { - { 0.400, 0.350, 10.1 }, // Dark Skin - { 0.377, 0.345, 35.8 }, // Light Skin - { 0.247, 0.251, 19.3 }, // Blue Sky - { 0.337, 0.422, 13.3 }, // Foliage - { 0.265, 0.240, 24.3 }, // Blue Flower - { 0.261, 0.343, 43.1 }, // Bluish Green - { 0.506, 0.407, 30.1 }, // Orange - { 0.211, 0.175, 12.0 }, // Purplish Blue - { 0.453, 0.306, 19.8 }, // Moderate Red - { 0.285, 0.202, 6.6 }, // Purple - { 0.380, 0.489, 44.3 }, // Yellow Green - { 0.473, 0.438, 43.1 }, // Orange Yellow - { 0.187, 0.129, 6.1 }, // Blue - { 0.305, 0.478, 23.4 }, // Green - { 0.539, 0.313, 12.0 }, // Red - { 0.448, 0.470, 59.1 }, // Yellow - { 0.364, 0.233, 19.8 }, // Magenta - { 0.196, 0.252, 19.8 }, // Cyan - { 0.310, 0.316, 90.0 }, // White - { 0.310, 0.316, 59.1 }, // Neutral 8 - { 0.310, 0.316, 36.2 }, // Neutral 6.5 - { 0.310, 0.316, 19.8 }, // Neutral 5 - { 0.310, 0.316, 9.0 }, // Neutral 3.5 - { 0.310, 0.316, 3.1 } }; // Black - double gmb_cam[NSQ][4], gmb_xyz[NSQ][3]; - double inverse[NSQ][3], cam_xyz[4][3], num; - int c, i, j, k, sq, row, col, count[4]; - - memset (gmb_cam, 0, sizeof gmb_cam); - for (sq=0; sq < NSQ; sq++) { - FORCC count[c] = 0; - for (row=cut[sq][3]; row < cut[sq][3]+cut[sq][1]; row++) - for (col=cut[sq][2]; col < cut[sq][2]+cut[sq][0]; col++) { - c = FC(row,col); - if (c >= colors) c -= 2; - gmb_cam[sq][c] += BAYER(row,col); - count[c]++; - } - FORCC gmb_cam[sq][c] = gmb_cam[sq][c]/count[c] - black; - gmb_xyz[sq][0] = gmb_xyY[sq][2] * gmb_xyY[sq][0] / gmb_xyY[sq][1]; - gmb_xyz[sq][1] = gmb_xyY[sq][2]; - gmb_xyz[sq][2] = gmb_xyY[sq][2] * - (1 - gmb_xyY[sq][0] - gmb_xyY[sq][1]) / gmb_xyY[sq][1]; - } - pseudoinverse (gmb_xyz, inverse, NSQ); - for (i=0; i < colors; i++) - for (j=0; j < 3; j++) - for (cam_xyz[i][j] = k=0; k < NSQ; k++) - cam_xyz[i][j] += gmb_cam[k][i] * inverse[k][j]; - cam_xyz_coeff (cam_xyz); - if (verbose) { - printf (" { \"%s %s\", %d,\n\t{", make, model, black); - num = 10000 / (cam_xyz[1][0] + cam_xyz[1][1] + cam_xyz[1][2]); - FORCC for (j=0; j < 3; j++) - printf ("%c%d", (c | j) ? ',':' ', (int) (cam_xyz[c][j] * num + 0.5)); - puts (" } },"); - } -#undef NSQ -} -#endif - -void CLASS hat_transform (float *temp, float *base, int st, int size, int sc) -{ - int i; - for (i=0; i < sc; i++) - temp[i] = 2*base[st*i] + base[st*(sc-i)] + base[st*(i+sc)]; - for (; i+sc < size; i++) - temp[i] = 2*base[st*i] + base[st*(i-sc)] + base[st*(i+sc)]; - for (; i < size; i++) - temp[i] = 2*base[st*i] + base[st*(i-sc)] + base[st*(2*size-2-(i+sc))]; -} - -void CLASS wavelet_denoise() -{ - float *fimg=0, *temp, thold, mul[2], avg, diff; - int scale=1, size, lev, hpass, lpass, row, col, nc, c, i, wlast, blk[2]; - ushort *window[4]; - static const float noise[] = - { 0.8002,0.2735,0.1202,0.0585,0.0291,0.0152,0.0080,0.0044 }; - - if (verbose) fprintf (stderr,_("Wavelet denoising...\n")); - - while (maximum << scale < 0x10000) scale++; - maximum <<= --scale; - black <<= scale; - FORC4 cblack[c] <<= scale; - if ((size = iheight*iwidth) < 0x15550000) - fimg = (float *) malloc ((size*3 + iheight + iwidth) * sizeof *fimg); - merror (fimg, "wavelet_denoise()"); - temp = fimg + size*3; - if ((nc = colors) == 3 && filters) nc++; - FORC(nc) { /* denoise R,G1,B,G3 individually */ - for (i=0; i < size; i++) - fimg[i] = 256 * sqrt(image[i][c] << scale); - for (hpass=lev=0; lev < 5; lev++) { - lpass = size*((lev & 1)+1); - for (row=0; row < iheight; row++) { - hat_transform (temp, fimg+hpass+row*iwidth, 1, iwidth, 1 << lev); - for (col=0; col < iwidth; col++) - fimg[lpass + row*iwidth + col] = temp[col] * 0.25; - } - for (col=0; col < iwidth; col++) { - hat_transform (temp, fimg+lpass+col, iwidth, iheight, 1 << lev); - for (row=0; row < iheight; row++) - fimg[lpass + row*iwidth + col] = temp[row] * 0.25; - } - thold = threshold * noise[lev]; - for (i=0; i < size; i++) { - fimg[hpass+i] -= fimg[lpass+i]; - if (fimg[hpass+i] < -thold) fimg[hpass+i] += thold; - else if (fimg[hpass+i] > thold) fimg[hpass+i] -= thold; - else fimg[hpass+i] = 0; - if (hpass) fimg[i] += fimg[hpass+i]; - } - hpass = lpass; - } - for (i=0; i < size; i++) - image[i][c] = CLIP(SQR(fimg[i]+fimg[lpass+i])/0x10000); - } - if (filters && colors == 3) { /* pull G1 and G3 closer together */ - for (row=0; row < 2; row++) { - mul[row] = 0.125 * pre_mul[FC(row+1,0) | 1] / pre_mul[FC(row,0) | 1]; - blk[row] = cblack[FC(row,0) | 1]; - } - for (i=0; i < 4; i++) - window[i] = (ushort *) fimg + width*i; - for (wlast=-1, row=1; row < height-1; row++) { - while (wlast < row+1) { - for (wlast++, i=0; i < 4; i++) - window[(i+3) & 3] = window[i]; - for (col = FC(wlast,1) & 1; col < width; col+=2) - window[2][col] = BAYER(wlast,col); - } - thold = threshold/512; - for (col = (FC(row,0) & 1)+1; col < width-1; col+=2) { - avg = ( window[0][col-1] + window[0][col+1] + - window[2][col-1] + window[2][col+1] - blk[~row & 1]*4 ) - * mul[row & 1] + (window[1][col] + blk[row & 1]) * 0.5; - avg = avg < 0 ? 0 : sqrt(avg); - diff = sqrt(BAYER(row,col)) - avg; - if (diff < -thold) diff += thold; - else if (diff > thold) diff -= thold; - else diff = 0; - BAYER(row,col) = CLIP(SQR(avg+diff) + 0.5); - } - } - } - free (fimg); -} - -void CLASS scale_colors() -{ - unsigned bottom, right, size, row, col, ur, uc, i, x, y, c, sum[8]; - int val, dark, sat; - double dsum[8], dmin, dmax; - float scale_mul[4], fr, fc; - ushort *img=0, *pix; - - if (user_mul[0]) - memcpy (pre_mul, user_mul, sizeof pre_mul); - if (use_auto_wb || (use_camera_wb && cam_mul[0] == -1)) { - memset (dsum, 0, sizeof dsum); - bottom = MIN (greybox[1]+greybox[3], height); - right = MIN (greybox[0]+greybox[2], width); - for (row=greybox[1]; row < bottom; row += 8) - for (col=greybox[0]; col < right; col += 8) { - memset (sum, 0, sizeof sum); - for (y=row; y < row+8 && y < bottom; y++) - for (x=col; x < col+8 && x < right; x++) - FORC4 { - if (filters) { - c = fcol(y,x); - val = BAYER2(y,x); - } else - val = image[y*width+x][c]; - if (val > maximum-25) goto skip_block; - if ((val -= cblack[c]) < 0) val = 0; - sum[c] += val; - sum[c+4]++; - if (filters) break; - } - FORC(8) dsum[c] += sum[c]; -skip_block: ; - } - FORC4 if (dsum[c]) pre_mul[c] = dsum[c+4] / dsum[c]; - } - if (use_camera_wb && cam_mul[0] != -1) { - memset (sum, 0, sizeof sum); - for (row=0; row < 8; row++) - for (col=0; col < 8; col++) { - c = FC(row,col); - if ((val = white[row][col] - cblack[c]) > 0) - sum[c] += val; - sum[c+4]++; - } - if (sum[0] && sum[1] && sum[2] && sum[3]) - FORC4 pre_mul[c] = (float) sum[c+4] / sum[c]; - else if (cam_mul[0] && cam_mul[2]) - memcpy (pre_mul, cam_mul, sizeof pre_mul); - else - fprintf (stderr,_("%s: Cannot use camera white balance.\n"), ifname); - } - if (pre_mul[3] == 0) pre_mul[3] = colors < 4 ? pre_mul[1] : 1; - dark = black; - sat = maximum; - if (threshold) wavelet_denoise(); - maximum -= black; - for (dmin=DBL_MAX, dmax=c=0; c < 4; c++) { - if (dmin > pre_mul[c]) - dmin = pre_mul[c]; - if (dmax < pre_mul[c]) - dmax = pre_mul[c]; - } - if (!highlight) dmax = dmin; - FORC4 scale_mul[c] = (pre_mul[c] /= dmax) * 65535.0 / maximum; - if (verbose) { - fprintf (stderr, - _("Scaling with darkness %d, saturation %d, and\nmultipliers"), dark, sat); - FORC4 fprintf (stderr, " %f", pre_mul[c]); - fputc ('\n', stderr); - } - size = iheight*iwidth; - for (i=0; i < size*4; i++) { - val = image[0][i]; - if (!val) continue; - val -= cblack[i & 3]; - val *= scale_mul[i & 3]; - image[0][i] = CLIP(val); - } - if ((aber[0] != 1 || aber[2] != 1) && colors == 3) { - if (verbose) - fprintf (stderr,_("Correcting chromatic aberration...\n")); - for (c=0; c < 4; c+=2) { - if (aber[c] == 1) continue; - img = (ushort *) malloc (size * sizeof *img); - merror (img, "scale_colors()"); - for (i=0; i < size; i++) - img[i] = image[i][c]; - for (row=0; row < iheight; row++) { - ur = fr = (row - iheight*0.5) * aber[c] + iheight*0.5; - if (ur > iheight-2) continue; - fr -= ur; - for (col=0; col < iwidth; col++) { - uc = fc = (col - iwidth*0.5) * aber[c] + iwidth*0.5; - if (uc > iwidth-2) continue; - fc -= uc; - pix = img + ur*iwidth + uc; - image[row*iwidth+col][c] = - (pix[ 0]*(1-fc) + pix[ 1]*fc) * (1-fr) + - (pix[iwidth]*(1-fc) + pix[iwidth+1]*fc) * fr; - } - } - free(img); - } - } -} - -void CLASS pre_interpolate() -{ - ushort (*img)[4]; - int row, col, c; - - if (shrink) { - if (half_size) { - height = iheight; - width = iwidth; - } else { - img = (ushort (*)[4]) calloc (height*width, sizeof *img); - merror (img, "pre_interpolate()"); - for (row=0; row < height; row++) - for (col=0; col < width; col++) { - c = fcol(row,col); - img[row*width+col][c] = image[(row >> 1)*iwidth+(col >> 1)][c]; - } - free (image); - image = img; - shrink = 0; - } - } - if (filters > 1000 && colors == 3) { - if (four_color_rgb && colors++) - mix_green = !half_size; - else { - for (row = FC(1,0) >> 1; row < height; row+=2) - for (col = FC(row,1) & 1; col < width; col+=2) - image[row*width+col][1] = image[row*width+col][3]; - filters &= ~((filters & 0x55555555) << 1); - } - } - if (half_size) filters = 0; -} - -void CLASS border_interpolate (int border) -{ - unsigned row, col, y, x, f, c, sum[8]; - - for (row=0; row < height; row++) - for (col=0; col < width; col++) { - if (col==border && row >= border && row < height-border) - col = width-border; - memset (sum, 0, sizeof sum); - for (y=row-1; y != row+2; y++) - for (x=col-1; x != col+2; x++) - if (y < height && x < width) { - f = fcol(y,x); - sum[f] += image[y*width+x][f]; - sum[f+4]++; - } - f = fcol(row,col); - FORCC if (c != f && sum[c+4]) - image[row*width+col][c] = sum[c] / sum[c+4]; - } -} - -void CLASS lin_interpolate() -{ - int code[16][16][32], size=16, *ip, sum[4]; - int f, c, i, x, y, row, col, shift, color; - ushort *pix; - - if (verbose) fprintf (stderr,_("Bilinear interpolation...\n")); - if (filters == 2) size = 6; - border_interpolate(1); - for (row=0; row < size; row++) - for (col=0; col < size; col++) { - ip = code[row][col]+1; - f = fcol(row,col); - memset (sum, 0, sizeof sum); - for (y=-1; y <= 1; y++) - for (x=-1; x <= 1; x++) { - shift = (y==0) + (x==0); - color = fcol(row+y,col+x); - if (color == f) continue; - *ip++ = (width*y + x)*4 + color; - *ip++ = shift; - *ip++ = color; - sum[color] += 1 << shift; - } - code[row][col][0] = (ip - code[row][col]) / 3; - FORCC - if (c != f) { - *ip++ = c; - *ip++ = 256 / sum[c]; - } - } - for (row=1; row < height-1; row++) - for (col=1; col < width-1; col++) { - pix = image[row*width+col]; - ip = code[row % size][col % size]; - memset (sum, 0, sizeof sum); - for (i=*ip++; i--; ip+=3) - sum[ip[2]] += pix[ip[0]] << ip[1]; - for (i=colors; --i; ip+=2) - pix[ip[0]] = sum[ip[0]] * ip[1] >> 8; - } -} - -/* - This algorithm is officially called: - - "Interpolation using a Threshold-based variable number of gradients" - - described in http://scien.stanford.edu/pages/labsite/1999/psych221/projects/99/tingchen/algodep/vargra.html - - I've extended the basic idea to work with non-Bayer filter arrays. - Gradients are numbered clockwise from NW=0 to W=7. - */ -void CLASS vng_interpolate() -{ - static const signed char *cp, terms[] = { - -2,-2,+0,-1,0,0x01, -2,-2,+0,+0,1,0x01, -2,-1,-1,+0,0,0x01, - -2,-1,+0,-1,0,0x02, -2,-1,+0,+0,0,0x03, -2,-1,+0,+1,1,0x01, - -2,+0,+0,-1,0,0x06, -2,+0,+0,+0,1,0x02, -2,+0,+0,+1,0,0x03, - -2,+1,-1,+0,0,0x04, -2,+1,+0,-1,1,0x04, -2,+1,+0,+0,0,0x06, - -2,+1,+0,+1,0,0x02, -2,+2,+0,+0,1,0x04, -2,+2,+0,+1,0,0x04, - -1,-2,-1,+0,0,0x80, -1,-2,+0,-1,0,0x01, -1,-2,+1,-1,0,0x01, - -1,-2,+1,+0,1,0x01, -1,-1,-1,+1,0,0x88, -1,-1,+1,-2,0,0x40, - -1,-1,+1,-1,0,0x22, -1,-1,+1,+0,0,0x33, -1,-1,+1,+1,1,0x11, - -1,+0,-1,+2,0,0x08, -1,+0,+0,-1,0,0x44, -1,+0,+0,+1,0,0x11, - -1,+0,+1,-2,1,0x40, -1,+0,+1,-1,0,0x66, -1,+0,+1,+0,1,0x22, - -1,+0,+1,+1,0,0x33, -1,+0,+1,+2,1,0x10, -1,+1,+1,-1,1,0x44, - -1,+1,+1,+0,0,0x66, -1,+1,+1,+1,0,0x22, -1,+1,+1,+2,0,0x10, - -1,+2,+0,+1,0,0x04, -1,+2,+1,+0,1,0x04, -1,+2,+1,+1,0,0x04, - +0,-2,+0,+0,1,0x80, +0,-1,+0,+1,1,0x88, +0,-1,+1,-2,0,0x40, - +0,-1,+1,+0,0,0x11, +0,-1,+2,-2,0,0x40, +0,-1,+2,-1,0,0x20, - +0,-1,+2,+0,0,0x30, +0,-1,+2,+1,1,0x10, +0,+0,+0,+2,1,0x08, - +0,+0,+2,-2,1,0x40, +0,+0,+2,-1,0,0x60, +0,+0,+2,+0,1,0x20, - +0,+0,+2,+1,0,0x30, +0,+0,+2,+2,1,0x10, +0,+1,+1,+0,0,0x44, - +0,+1,+1,+2,0,0x10, +0,+1,+2,-1,1,0x40, +0,+1,+2,+0,0,0x60, - +0,+1,+2,+1,0,0x20, +0,+1,+2,+2,0,0x10, +1,-2,+1,+0,0,0x80, - +1,-1,+1,+1,0,0x88, +1,+0,+1,+2,0,0x08, +1,+0,+2,-1,0,0x40, - +1,+0,+2,+1,0,0x10 - }, chood[] = { -1,-1, -1,0, -1,+1, 0,+1, +1,+1, +1,0, +1,-1, 0,-1 }; - ushort (*brow[5])[4], *pix; - int prow=8, pcol=2, *ip, *code[16][16], gval[8], gmin, gmax, sum[4]; - int row, col, x, y, x1, x2, y1, y2, t, weight, grads, color, diag; - int g, diff, thold, num, c; - - lin_interpolate(); - if (verbose) fprintf (stderr,_("VNG interpolation...\n")); - - if (filters == 1) prow = pcol = 16; - if (filters == 2) prow = pcol = 6; - ip = (int *) calloc (prow*pcol, 1280); - merror (ip, "vng_interpolate()"); - for (row=0; row < prow; row++) /* Precalculate for VNG */ - for (col=0; col < pcol; col++) { - code[row][col] = ip; - for (cp=terms, t=0; t < 64; t++) { - y1 = *cp++; x1 = *cp++; - y2 = *cp++; x2 = *cp++; - weight = *cp++; - grads = *cp++; - color = fcol(row+y1,col+x1); - if (fcol(row+y2,col+x2) != color) continue; - diag = (fcol(row,col+1) == color && fcol(row+1,col) == color) ? 2:1; - if (abs(y1-y2) == diag && abs(x1-x2) == diag) continue; - *ip++ = (y1*width + x1)*4 + color; - *ip++ = (y2*width + x2)*4 + color; - *ip++ = weight; - for (g=0; g < 8; g++) - if (grads & 1< gval[g]) gmin = gval[g]; - if (gmax < gval[g]) gmax = gval[g]; - } - if (gmax == 0) { - memcpy (brow[2][col], pix, sizeof *image); - continue; - } - thold = gmin + (gmax >> 1); - memset (sum, 0, sizeof sum); - color = fcol(row,col); - for (num=g=0; g < 8; g++,ip+=2) { /* Average the neighbors */ - if (gval[g] <= thold) { - FORCC - if (c == color && ip[1]) - sum[c] += (pix[c] + pix[ip[1]]) >> 1; - else - sum[c] += pix[ip[0] + c]; - num++; - } - } - FORCC { /* Save to buffer */ - t = pix[color]; - if (c != color) - t += (sum[c] - sum[color]) / num; - brow[2][col][c] = CLIP(t); - } - } - if (row > 3) /* Write buffer to image */ - memcpy (image[(row-2)*width+2], brow[0]+2, (width-4)*sizeof *image); - for (g=0; g < 4; g++) - brow[(g-1) & 3] = brow[g]; - } - memcpy (image[(row-2)*width+2], brow[0]+2, (width-4)*sizeof *image); - memcpy (image[(row-1)*width+2], brow[1]+2, (width-4)*sizeof *image); - free (brow[4]); - free (code[0][0]); -} - -/* - Patterned Pixel Grouping Interpolation by Alain Desbiolles -*/ -void CLASS ppg_interpolate() -{ - int dir[5] = { 1, width, -1, -width, 1 }; - int row, col, diff[2], guess[2], c, d, i; - ushort (*pix)[4]; - - border_interpolate(3); - if (verbose) fprintf (stderr,_("PPG interpolation...\n")); - -/* Fill in the green layer with gradients and pattern recognition: */ - for (row=3; row < height-3; row++) - for (col=3+(FC(row,3) & 1), c=FC(row,col); col < width-3; col+=2) { - pix = image + row*width+col; - for (i=0; (d=dir[i]) > 0; i++) { - guess[i] = (pix[-d][1] + pix[0][c] + pix[d][1]) * 2 - - pix[-2*d][c] - pix[2*d][c]; - diff[i] = ( ABS(pix[-2*d][c] - pix[ 0][c]) + - ABS(pix[ 2*d][c] - pix[ 0][c]) + - ABS(pix[ -d][1] - pix[ d][1]) ) * 3 + - ( ABS(pix[ 3*d][1] - pix[ d][1]) + - ABS(pix[-3*d][1] - pix[-d][1]) ) * 2; - } - d = dir[i = diff[0] > diff[1]]; - pix[0][1] = ULIM(guess[i] >> 2, pix[d][1], pix[-d][1]); - } -/* Calculate red and blue for each green pixel: */ - for (row=1; row < height-1; row++) - for (col=1+(FC(row,2) & 1), c=FC(row,col+1); col < width-1; col+=2) { - pix = image + row*width+col; - for (i=0; (d=dir[i]) > 0; c=2-c, i++) - pix[0][c] = CLIP((pix[-d][c] + pix[d][c] + 2*pix[0][1] - - pix[-d][1] - pix[d][1]) >> 1); - } -/* Calculate blue for red pixels and vice versa: */ - for (row=1; row < height-1; row++) - for (col=1+(FC(row,1) & 1), c=2-FC(row,col); col < width-1; col+=2) { - pix = image + row*width+col; - for (i=0; (d=dir[i]+dir[i+1]) > 0; i++) { - diff[i] = ABS(pix[-d][c] - pix[d][c]) + - ABS(pix[-d][1] - pix[0][1]) + - ABS(pix[ d][1] - pix[0][1]); - guess[i] = pix[-d][c] + pix[d][c] + 2*pix[0][1] - - pix[-d][1] - pix[d][1]; - } - if (diff[0] != diff[1]) - pix[0][c] = CLIP(guess[diff[0] > diff[1]] >> 1); - else - pix[0][c] = CLIP((guess[0]+guess[1]) >> 2); - } -} - -/* - Adaptive Homogeneity-Directed interpolation is based on - the work of Keigo Hirakawa, Thomas Parks, and Paul Lee. - */ -#define TS 256 /* Tile Size */ - -void CLASS ahd_interpolate() -{ - int i, j, k, top, left, row, col, tr, tc, c, d, val, hm[2]; - ushort (*pix)[4], (*rix)[3]; - static const int dir[4] = { -1, 1, -TS, TS }; - unsigned ldiff[2][4], abdiff[2][4], leps, abeps; - float r, cbrt[0x10000], xyz[3], xyz_cam[3][4]; - ushort (*rgb)[TS][TS][3]; - short (*lab)[TS][TS][3], (*lix)[3]; - char (*homo)[TS][TS], *buffer; - - if (verbose) fprintf (stderr,_("AHD interpolation...\n")); - - for (i=0; i < 0x10000; i++) { - r = i / 65535.0; - cbrt[i] = r > 0.008856 ? pow(r,1/3.0) : 7.787*r + 16/116.0; - } - for (i=0; i < 3; i++) - for (j=0; j < colors; j++) - for (xyz_cam[i][j] = k=0; k < 3; k++) - xyz_cam[i][j] += xyz_rgb[i][k] * rgb_cam[k][j] / d65_white[i]; - - border_interpolate(5); - buffer = (char *) malloc (26*TS*TS); /* 1664 kB */ - merror (buffer, "ahd_interpolate()"); - rgb = (ushort(*)[TS][TS][3]) buffer; - lab = (short (*)[TS][TS][3])(buffer + 12*TS*TS); - homo = (char (*)[TS][TS]) (buffer + 24*TS*TS); - - for (top=2; top < height-5; top += TS-6) - for (left=2; left < width-5; left += TS-6) { - -/* Interpolate green horizontally and vertically: */ - for (row = top; row < top+TS && row < height-2; row++) { - col = left + (FC(row,left) & 1); - for (c = FC(row,col); col < left+TS && col < width-2; col+=2) { - pix = image + row*width+col; - val = ((pix[-1][1] + pix[0][c] + pix[1][1]) * 2 - - pix[-2][c] - pix[2][c]) >> 2; - rgb[0][row-top][col-left][1] = ULIM(val,pix[-1][1],pix[1][1]); - val = ((pix[-width][1] + pix[0][c] + pix[width][1]) * 2 - - pix[-2*width][c] - pix[2*width][c]) >> 2; - rgb[1][row-top][col-left][1] = ULIM(val,pix[-width][1],pix[width][1]); - } - } -/* Interpolate red and blue, and convert to CIELab: */ - for (d=0; d < 2; d++) - for (row=top+1; row < top+TS-1 && row < height-3; row++) - for (col=left+1; col < left+TS-1 && col < width-3; col++) { - pix = image + row*width+col; - rix = &rgb[d][row-top][col-left]; - lix = &lab[d][row-top][col-left]; - if ((c = 2 - FC(row,col)) == 1) { - c = FC(row+1,col); - val = pix[0][1] + (( pix[-1][2-c] + pix[1][2-c] - - rix[-1][1] - rix[1][1] ) >> 1); - rix[0][2-c] = CLIP(val); - val = pix[0][1] + (( pix[-width][c] + pix[width][c] - - rix[-TS][1] - rix[TS][1] ) >> 1); - } else - val = rix[0][1] + (( pix[-width-1][c] + pix[-width+1][c] - + pix[+width-1][c] + pix[+width+1][c] - - rix[-TS-1][1] - rix[-TS+1][1] - - rix[+TS-1][1] - rix[+TS+1][1] + 1) >> 2); - rix[0][c] = CLIP(val); - c = FC(row,col); - rix[0][c] = pix[0][c]; - xyz[0] = xyz[1] = xyz[2] = 0.5; - FORCC { - xyz[0] += xyz_cam[0][c] * rix[0][c]; - xyz[1] += xyz_cam[1][c] * rix[0][c]; - xyz[2] += xyz_cam[2][c] * rix[0][c]; - } - xyz[0] = cbrt[CLIP((int) xyz[0])]; - xyz[1] = cbrt[CLIP((int) xyz[1])]; - xyz[2] = cbrt[CLIP((int) xyz[2])]; - lix[0][0] = 64 * (116 * xyz[1] - 16); - lix[0][1] = 64 * 500 * (xyz[0] - xyz[1]); - lix[0][2] = 64 * 200 * (xyz[1] - xyz[2]); - } -/* Build homogeneity maps from the CIELab images: */ - memset (homo, 0, 2*TS*TS); - for (row=top+2; row < top+TS-2 && row < height-4; row++) { - tr = row-top; - for (col=left+2; col < left+TS-2 && col < width-4; col++) { - tc = col-left; - for (d=0; d < 2; d++) { - lix = &lab[d][tr][tc]; - for (i=0; i < 4; i++) { - ldiff[d][i] = ABS(lix[0][0]-lix[dir[i]][0]); - abdiff[d][i] = SQR(lix[0][1]-lix[dir[i]][1]) - + SQR(lix[0][2]-lix[dir[i]][2]); - } - } - leps = MIN(MAX(ldiff[0][0],ldiff[0][1]), - MAX(ldiff[1][2],ldiff[1][3])); - abeps = MIN(MAX(abdiff[0][0],abdiff[0][1]), - MAX(abdiff[1][2],abdiff[1][3])); - for (d=0; d < 2; d++) - for (i=0; i < 4; i++) - if (ldiff[d][i] <= leps && abdiff[d][i] <= abeps) - homo[d][tr][tc]++; - } - } -/* Combine the most homogenous pixels for the final result: */ - for (row=top+3; row < top+TS-3 && row < height-5; row++) { - tr = row-top; - for (col=left+3; col < left+TS-3 && col < width-5; col++) { - tc = col-left; - for (d=0; d < 2; d++) - for (hm[d]=0, i=tr-1; i <= tr+1; i++) - for (j=tc-1; j <= tc+1; j++) - hm[d] += homo[d][i][j]; - if (hm[0] != hm[1]) - FORC3 image[row*width+col][c] = rgb[hm[1] > hm[0]][tr][tc][c]; - else - FORC3 image[row*width+col][c] = - (rgb[0][tr][tc][c] + rgb[1][tr][tc][c]) >> 1; - } - } - } - free (buffer); -} -#undef TS - -void CLASS median_filter() -{ - ushort (*pix)[4]; - int pass, c, i, j, k, med[9]; - static const uchar opt[] = /* Optimal 9-element median search */ - { 1,2, 4,5, 7,8, 0,1, 3,4, 6,7, 1,2, 4,5, 7,8, - 0,3, 5,8, 4,7, 3,6, 1,4, 2,5, 4,7, 4,2, 6,4, 4,2 }; - - for (pass=1; pass <= med_passes; pass++) { - if (verbose) - fprintf (stderr,_("Median filter pass %d...\n"), pass); - for (c=0; c < 3; c+=2) { - for (pix = image; pix < image+width*height; pix++) - pix[0][3] = pix[0][c]; - for (pix = image+width; pix < image+width*(height-1); pix++) { - if ((pix-image+1) % width < 2) continue; - for (k=0, i = -width; i <= width; i += width) - for (j = i-1; j <= i+1; j++) - med[k++] = pix[j][3] - pix[j][1]; - for (i=0; i < sizeof opt; i+=2) - if (med[opt[i]] > med[opt[i+1]]) - SWAP (med[opt[i]] , med[opt[i+1]]); - pix[0][c] = CLIP(med[4] + pix[0][1]); - } - } - } -} - -void CLASS blend_highlights() -{ - int clip=INT_MAX, row, col, c, i, j; - static const float trans[2][4][4] = - { { { 1,1,1 }, { 1.7320508,-1.7320508,0 }, { -1,-1,2 } }, - { { 1,1,1,1 }, { 1,-1,1,-1 }, { 1,1,-1,-1 }, { 1,-1,-1,1 } } }; - static const float itrans[2][4][4] = - { { { 1,0.8660254,-0.5 }, { 1,-0.8660254,-0.5 }, { 1,0,1 } }, - { { 1,1,1,1 }, { 1,-1,1,-1 }, { 1,1,-1,-1 }, { 1,-1,-1,1 } } }; - float cam[2][4], lab[2][4], sum[2], chratio; - - if ((unsigned) (colors-3) > 1) return; - if (verbose) fprintf (stderr,_("Blending highlights...\n")); - FORCC if (clip > (i = 65535*pre_mul[c])) clip = i; - for (row=0; row < height; row++) - for (col=0; col < width; col++) { - FORCC if (image[row*width+col][c] > clip) break; - if (c == colors) continue; - FORCC { - cam[0][c] = image[row*width+col][c]; - cam[1][c] = MIN(cam[0][c],clip); - } - for (i=0; i < 2; i++) { - FORCC for (lab[i][c]=j=0; j < colors; j++) - lab[i][c] += trans[colors-3][c][j] * cam[i][j]; - for (sum[i]=0,c=1; c < colors; c++) - sum[i] += SQR(lab[i][c]); - } - chratio = sqrt(sum[1]/sum[0]); - for (c=1; c < colors; c++) - lab[0][c] *= chratio; - FORCC for (cam[0][c]=j=0; j < colors; j++) - cam[0][c] += itrans[colors-3][c][j] * lab[0][j]; - FORCC image[row*width+col][c] = cam[0][c] / colors; - } -} - -#define SCALE (4 >> shrink) -void CLASS recover_highlights() -{ - float *map, sum, wgt, grow; - int hsat[4], count, spread, change, val, i; - unsigned high, wide, mrow, mcol, row, col, kc, c, d, y, x; - ushort *pixel; - static const signed char dir[8][2] = - { {-1,-1}, {-1,0}, {-1,1}, {0,1}, {1,1}, {1,0}, {1,-1}, {0,-1} }; - - if (verbose) fprintf (stderr,_("Rebuilding highlights...\n")); - - grow = pow (2, 4-highlight); - FORCC hsat[c] = 32000 * pre_mul[c]; - for (kc=0, c=1; c < colors; c++) - if (pre_mul[kc] < pre_mul[c]) kc = c; - high = height / SCALE; - wide = width / SCALE; - map = (float *) calloc (high*wide, sizeof *map); - merror (map, "recover_highlights()"); - FORCC if (c != kc) { - memset (map, 0, high*wide*sizeof *map); - for (mrow=0; mrow < high; mrow++) - for (mcol=0; mcol < wide; mcol++) { - sum = wgt = count = 0; - for (row = mrow*SCALE; row < (mrow+1)*SCALE; row++) - for (col = mcol*SCALE; col < (mcol+1)*SCALE; col++) { - pixel = image[row*width+col]; - if (pixel[c] / hsat[c] == 1 && pixel[kc] > 24000) { - sum += pixel[c]; - wgt += pixel[kc]; - count++; - } - } - if (count == SCALE*SCALE) - map[mrow*wide+mcol] = sum / wgt; - } - for (spread = 32/grow; spread--; ) { - for (mrow=0; mrow < high; mrow++) - for (mcol=0; mcol < wide; mcol++) { - if (map[mrow*wide+mcol]) continue; - sum = count = 0; - for (d=0; d < 8; d++) { - y = mrow + dir[d][0]; - x = mcol + dir[d][1]; - if (y < high && x < wide && map[y*wide+x] > 0) { - sum += (1 + (d & 1)) * map[y*wide+x]; - count += 1 + (d & 1); - } - } - if (count > 3) - map[mrow*wide+mcol] = - (sum+grow) / (count+grow); - } - for (change=i=0; i < high*wide; i++) - if (map[i] < 0) { - map[i] = -map[i]; - change = 1; - } - if (!change) break; - } - for (i=0; i < high*wide; i++) - if (map[i] == 0) map[i] = 1; - for (mrow=0; mrow < high; mrow++) - for (mcol=0; mcol < wide; mcol++) { - for (row = mrow*SCALE; row < (mrow+1)*SCALE; row++) - for (col = mcol*SCALE; col < (mcol+1)*SCALE; col++) { - pixel = image[row*width+col]; - if (pixel[c] / hsat[c] > 1) { - val = pixel[kc] * map[mrow*wide+mcol]; - if (pixel[c] < val) pixel[c] = CLIP(val); - } - } - } - } - free (map); -} -#undef SCALE - -void CLASS tiff_get (unsigned base, - unsigned *tag, unsigned *type, unsigned *len, unsigned *save) -{ - *tag = get2(); - *type = get2(); - *len = get4(); - *save = ftell(ifp) + 4; - if (*len * ("11124811248488"[*type < 14 ? *type:0]-'0') > 4) - fseek (ifp, get4()+base, SEEK_SET); -} - -void CLASS parse_thumb_note (int base, unsigned toff, unsigned tlen) -{ - unsigned entries, tag, type, len, save; - - entries = get2(); - while (entries--) { - tiff_get (base, &tag, &type, &len, &save); - if (tag == toff) thumb_offset = get4()+base; - if (tag == tlen) thumb_length = get4(); - fseek (ifp, save, SEEK_SET); - } -} - -int CLASS parse_tiff_ifd (int base); - -void CLASS parse_makernote (int base, int uptag) -{ - static const uchar xlat[2][256] = { - { 0xc1,0xbf,0x6d,0x0d,0x59,0xc5,0x13,0x9d,0x83,0x61,0x6b,0x4f,0xc7,0x7f,0x3d,0x3d, - 0x53,0x59,0xe3,0xc7,0xe9,0x2f,0x95,0xa7,0x95,0x1f,0xdf,0x7f,0x2b,0x29,0xc7,0x0d, - 0xdf,0x07,0xef,0x71,0x89,0x3d,0x13,0x3d,0x3b,0x13,0xfb,0x0d,0x89,0xc1,0x65,0x1f, - 0xb3,0x0d,0x6b,0x29,0xe3,0xfb,0xef,0xa3,0x6b,0x47,0x7f,0x95,0x35,0xa7,0x47,0x4f, - 0xc7,0xf1,0x59,0x95,0x35,0x11,0x29,0x61,0xf1,0x3d,0xb3,0x2b,0x0d,0x43,0x89,0xc1, - 0x9d,0x9d,0x89,0x65,0xf1,0xe9,0xdf,0xbf,0x3d,0x7f,0x53,0x97,0xe5,0xe9,0x95,0x17, - 0x1d,0x3d,0x8b,0xfb,0xc7,0xe3,0x67,0xa7,0x07,0xf1,0x71,0xa7,0x53,0xb5,0x29,0x89, - 0xe5,0x2b,0xa7,0x17,0x29,0xe9,0x4f,0xc5,0x65,0x6d,0x6b,0xef,0x0d,0x89,0x49,0x2f, - 0xb3,0x43,0x53,0x65,0x1d,0x49,0xa3,0x13,0x89,0x59,0xef,0x6b,0xef,0x65,0x1d,0x0b, - 0x59,0x13,0xe3,0x4f,0x9d,0xb3,0x29,0x43,0x2b,0x07,0x1d,0x95,0x59,0x59,0x47,0xfb, - 0xe5,0xe9,0x61,0x47,0x2f,0x35,0x7f,0x17,0x7f,0xef,0x7f,0x95,0x95,0x71,0xd3,0xa3, - 0x0b,0x71,0xa3,0xad,0x0b,0x3b,0xb5,0xfb,0xa3,0xbf,0x4f,0x83,0x1d,0xad,0xe9,0x2f, - 0x71,0x65,0xa3,0xe5,0x07,0x35,0x3d,0x0d,0xb5,0xe9,0xe5,0x47,0x3b,0x9d,0xef,0x35, - 0xa3,0xbf,0xb3,0xdf,0x53,0xd3,0x97,0x53,0x49,0x71,0x07,0x35,0x61,0x71,0x2f,0x43, - 0x2f,0x11,0xdf,0x17,0x97,0xfb,0x95,0x3b,0x7f,0x6b,0xd3,0x25,0xbf,0xad,0xc7,0xc5, - 0xc5,0xb5,0x8b,0xef,0x2f,0xd3,0x07,0x6b,0x25,0x49,0x95,0x25,0x49,0x6d,0x71,0xc7 }, - { 0xa7,0xbc,0xc9,0xad,0x91,0xdf,0x85,0xe5,0xd4,0x78,0xd5,0x17,0x46,0x7c,0x29,0x4c, - 0x4d,0x03,0xe9,0x25,0x68,0x11,0x86,0xb3,0xbd,0xf7,0x6f,0x61,0x22,0xa2,0x26,0x34, - 0x2a,0xbe,0x1e,0x46,0x14,0x68,0x9d,0x44,0x18,0xc2,0x40,0xf4,0x7e,0x5f,0x1b,0xad, - 0x0b,0x94,0xb6,0x67,0xb4,0x0b,0xe1,0xea,0x95,0x9c,0x66,0xdc,0xe7,0x5d,0x6c,0x05, - 0xda,0xd5,0xdf,0x7a,0xef,0xf6,0xdb,0x1f,0x82,0x4c,0xc0,0x68,0x47,0xa1,0xbd,0xee, - 0x39,0x50,0x56,0x4a,0xdd,0xdf,0xa5,0xf8,0xc6,0xda,0xca,0x90,0xca,0x01,0x42,0x9d, - 0x8b,0x0c,0x73,0x43,0x75,0x05,0x94,0xde,0x24,0xb3,0x80,0x34,0xe5,0x2c,0xdc,0x9b, - 0x3f,0xca,0x33,0x45,0xd0,0xdb,0x5f,0xf5,0x52,0xc3,0x21,0xda,0xe2,0x22,0x72,0x6b, - 0x3e,0xd0,0x5b,0xa8,0x87,0x8c,0x06,0x5d,0x0f,0xdd,0x09,0x19,0x93,0xd0,0xb9,0xfc, - 0x8b,0x0f,0x84,0x60,0x33,0x1c,0x9b,0x45,0xf1,0xf0,0xa3,0x94,0x3a,0x12,0x77,0x33, - 0x4d,0x44,0x78,0x28,0x3c,0x9e,0xfd,0x65,0x57,0x16,0x94,0x6b,0xfb,0x59,0xd0,0xc8, - 0x22,0x36,0xdb,0xd2,0x63,0x98,0x43,0xa1,0x04,0x87,0x86,0xf7,0xa6,0x26,0xbb,0xd6, - 0x59,0x4d,0xbf,0x6a,0x2e,0xaa,0x2b,0xef,0xe6,0x78,0xb6,0x4e,0xe0,0x2f,0xdc,0x7c, - 0xbe,0x57,0x19,0x32,0x7e,0x2a,0xd0,0xb8,0xba,0x29,0x00,0x3c,0x52,0x7d,0xa8,0x49, - 0x3b,0x2d,0xeb,0x25,0x49,0xfa,0xa3,0xaa,0x39,0xa7,0xc5,0xa7,0x50,0x11,0x36,0xfb, - 0xc6,0x67,0x4a,0xf5,0xa5,0x12,0x65,0x7e,0xb0,0xdf,0xaf,0x4e,0xb3,0x61,0x7f,0x2f } }; - unsigned offset=0, entries, tag, type, len, save, c; - unsigned ver97=0, serial=0, i, wbi=0, wb[4]={0,0,0,0}; - uchar buf97[324], ci, cj, ck; - short morder, sorder=order; - char buf[10]; -/* - The MakerNote might have its own TIFF header (possibly with - its own byte-order!), or it might just be a table. - */ - if (!strcmp(make,"Nokia")) return; - fread (buf, 1, 10, ifp); - if (!strncmp (buf,"KDK" ,3) || /* these aren't TIFF tables */ - !strncmp (buf,"VER" ,3) || - !strncmp (buf,"IIII",4) || - !strncmp (buf,"MMMM",4)) return; - if (!strncmp (buf,"KC" ,2) || /* Konica KD-400Z, KD-510Z */ - !strncmp (buf,"MLY" ,3)) { /* Minolta DiMAGE G series */ - order = 0x4d4d; - while ((i=ftell(ifp)) < data_offset && i < 16384) { - wb[0] = wb[2]; wb[2] = wb[1]; wb[1] = wb[3]; - wb[3] = get2(); - if (wb[1] == 256 && wb[3] == 256 && - wb[0] > 256 && wb[0] < 640 && wb[2] > 256 && wb[2] < 640) - FORC4 cam_mul[c] = wb[c]; - } - goto quit; - } - if (!strcmp (buf,"Nikon")) { - base = ftell(ifp); - order = get2(); - if (get2() != 42) goto quit; - offset = get4(); - fseek (ifp, offset-8, SEEK_CUR); - } else if (!strcmp (buf,"OLYMPUS")) { - base = ftell(ifp)-10; - fseek (ifp, -2, SEEK_CUR); - order = get2(); get2(); - } else if (!strncmp (buf,"SONY",4) || - !strcmp (buf,"Panasonic")) { - goto nf; - } else if (!strncmp (buf,"FUJIFILM",8)) { - base = ftell(ifp)-10; -nf: order = 0x4949; - fseek (ifp, 2, SEEK_CUR); - } else if (!strcmp (buf,"OLYMP") || - !strcmp (buf,"LEICA") || - !strcmp (buf,"Ricoh") || - !strcmp (buf,"EPSON")) - fseek (ifp, -2, SEEK_CUR); - else if (!strcmp (buf,"AOC") || - !strcmp (buf,"QVC")) - fseek (ifp, -4, SEEK_CUR); - else { - fseek (ifp, -10, SEEK_CUR); - if (!strncmp(make,"SAMSUNG",7)) - base = ftell(ifp); - } - entries = get2(); - if (entries > 1000) return; - morder = order; - while (entries--) { - order = morder; - tiff_get (base, &tag, &type, &len, &save); - tag |= uptag << 16; - if (tag == 2 && strstr(make,"NIKON") && !iso_speed) - iso_speed = (get2(),get2()); - if (tag == 4 && len > 26 && len < 35) { - if ((i=(get4(),get2())) != 0x7fff && !iso_speed) - iso_speed = 50 * pow (2, i/32.0 - 4); - if ((i=(get2(),get2())) != 0x7fff && !aperture) - aperture = pow (2, i/64.0); - if ((i=get2()) != 0xffff && !shutter) - shutter = pow (2, (short) i/-32.0); - wbi = (get2(),get2()); - shot_order = (get2(),get2()); - } - if ((tag == 4 || tag == 0x114) && !strncmp(make,"KONICA",6)) { - fseek (ifp, tag == 4 ? 140:160, SEEK_CUR); - switch (get2()) { - case 72: flip = 0; break; - case 76: flip = 6; break; - case 82: flip = 5; break; - } - } - if (tag == 7 && type == 2 && len > 20) - fgets (model2, 64, ifp); - if (tag == 8 && type == 4) - shot_order = get4(); - if (tag == 9 && !strcmp(make,"Canon")) - fread (artist, 64, 1, ifp); - if (tag == 0xc && len == 4) { - cam_mul[0] = getreal(type); - cam_mul[2] = getreal(type); - } - if (tag == 0xd && type == 7 && get2() == 0xaaaa) { - for (c=i=2; (ushort) c != 0xbbbb && i < len; i++) - c = c << 8 | fgetc(ifp); - while ((i+=4) < len-5) - if (get4() == 257 && (i=len) && (c = (get4(),fgetc(ifp))) < 3) - flip = "065"[c]-'0'; - } - if (tag == 0x10 && type == 4) - unique_id = get4(); - if (tag == 0x11 && is_raw && !strncmp(make,"NIKON",5)) { - fseek (ifp, get4()+base, SEEK_SET); - parse_tiff_ifd (base); - } - if (tag == 0x14 && type == 7) { - if (len == 2560) { - fseek (ifp, 1248, SEEK_CUR); - goto get2_256; - } - fread (buf, 1, 10, ifp); - if (!strncmp(buf,"NRW ",4)) { - fseek (ifp, strcmp(buf+4,"0100") ? 46:1546, SEEK_CUR); - cam_mul[0] = get4() << 2; - cam_mul[1] = get4() + get4(); - cam_mul[2] = get4() << 2; - } - } - if (tag == 0x15 && type == 2 && is_raw) - fread (model, 64, 1, ifp); - if (strstr(make,"PENTAX")) { - if (tag == 0x1b) tag = 0x1018; - if (tag == 0x1c) tag = 0x1017; - } - if (tag == 0x1d) - while ((c = fgetc(ifp)) && c != EOF) - serial = serial*10 + (isdigit(c) ? c - '0' : c % 10); - if (tag == 0x81 && type == 4) { - data_offset = get4(); - fseek (ifp, data_offset + 41, SEEK_SET); - raw_height = get2() * 2; - raw_width = get2(); - filters = 0x61616161; - } - if (tag == 0x29 && type == 1) { - c = wbi < 18 ? "012347800000005896"[wbi]-'0' : 0; - fseek (ifp, 8 + c*32, SEEK_CUR); - FORC4 cam_mul[c ^ (c >> 1) ^ 1] = get4(); - } - if ((tag == 0x81 && type == 7) || - (tag == 0x100 && type == 7) || - (tag == 0x280 && type == 1)) { - thumb_offset = ftell(ifp); - thumb_length = len; - } - if (tag == 0x88 && type == 4 && (thumb_offset = get4())) - thumb_offset += base; - if (tag == 0x89 && type == 4) - thumb_length = get4(); - if (tag == 0x8c || tag == 0x96) - meta_offset = ftell(ifp); - if (tag == 0x97) { - for (i=0; i < 4; i++) - ver97 = ver97 * 10 + fgetc(ifp)-'0'; - switch (ver97) { - case 100: - fseek (ifp, 68, SEEK_CUR); - FORC4 cam_mul[(c >> 1) | ((c & 1) << 1)] = get2(); - break; - case 102: - fseek (ifp, 6, SEEK_CUR); - goto get2_rggb; - case 103: - fseek (ifp, 16, SEEK_CUR); - FORC4 cam_mul[c] = get2(); - } - if (ver97 >= 200) { - if (ver97 != 205) fseek (ifp, 280, SEEK_CUR); - fread (buf97, 324, 1, ifp); - } - } - if (tag == 0xa1 && type == 7) { - order = 0x4949; - fseek (ifp, 140, SEEK_CUR); - FORC3 cam_mul[c] = get4(); - } - if (tag == 0xa4 && type == 3) { - fseek (ifp, wbi*48, SEEK_CUR); - FORC3 cam_mul[c] = get2(); - } - if (tag == 0xa7 && (unsigned) (ver97-200) < 17) { - ci = xlat[0][serial & 0xff]; - cj = xlat[1][fgetc(ifp)^fgetc(ifp)^fgetc(ifp)^fgetc(ifp)]; - ck = 0x60; - for (i=0; i < 324; i++) - buf97[i] ^= (cj += ci * ck++); - i = "66666>666;6A;:;55"[ver97-200] - '0'; - FORC4 cam_mul[c ^ (c >> 1) ^ (i & 1)] = - sget2 (buf97 + (i & -2) + c*2); - } - if (tag == 0x200 && len == 3) - shot_order = (get4(),get4()); - if (tag == 0x200 && len == 4) - FORC4 cblack[c ^ c >> 1] = get2(); - if (tag == 0x201 && len == 4) - goto get2_rggb; - if (tag == 0x220 && type == 7) - meta_offset = ftell(ifp); - if (tag == 0x401 && type == 4 && len == 4) - FORC4 cblack[c ^ c >> 1] = get4(); - if (tag == 0xe01) { /* Nikon Capture Note */ - order = 0x4949; - fseek (ifp, 22, SEEK_CUR); - for (offset=22; offset+22 < len; offset += 22+i) { - tag = get4(); - fseek (ifp, 14, SEEK_CUR); - i = get4()-4; - if (tag == 0x76a43207) flip = get2(); - else fseek (ifp, i, SEEK_CUR); - } - } - if (tag == 0xe80 && len == 256 && type == 7) { - fseek (ifp, 48, SEEK_CUR); - cam_mul[0] = get2() * 508 * 1.078 / 0x10000; - cam_mul[2] = get2() * 382 * 1.173 / 0x10000; - } - if (tag == 0xf00 && type == 7) { - if (len == 614) - fseek (ifp, 176, SEEK_CUR); - else if (len == 734 || len == 1502) - fseek (ifp, 148, SEEK_CUR); - else goto next; - goto get2_256; - } - if ((tag == 0x1011 && len == 9) || tag == 0x20400200) - for (i=0; i < 3; i++) - FORC3 cmatrix[i][c] = ((short) get2()) / 256.0; - if ((tag == 0x1012 || tag == 0x20400600) && len == 4) - FORC4 cblack[c ^ c >> 1] = get2(); - if (tag == 0x1017 || tag == 0x20400100) - cam_mul[0] = get2() / 256.0; - if (tag == 0x1018 || tag == 0x20400100) - cam_mul[2] = get2() / 256.0; - if (tag == 0x2011 && len == 2) { -get2_256: - order = 0x4d4d; - cam_mul[0] = get2() / 256.0; - cam_mul[2] = get2() / 256.0; - } - if ((tag | 0x70) == 0x2070 && type == 4) - fseek (ifp, get4()+base, SEEK_SET); - if (tag == 0x2010 && type != 7) - load_raw = &CLASS olympus_load_raw; - if (tag == 0x2020) - parse_thumb_note (base, 257, 258); - if (tag == 0x2040) - parse_makernote (base, 0x2040); - if (tag == 0xb028) { - fseek (ifp, get4()+base, SEEK_SET); - parse_thumb_note (base, 136, 137); - } - if (tag == 0x4001 && len > 500) { - i = len == 582 ? 50 : len == 653 ? 68 : len == 5120 ? 142 : 126; - fseek (ifp, i, SEEK_CUR); -get2_rggb: - FORC4 cam_mul[c ^ (c >> 1)] = get2(); - i = len == 1312 ? 112:22; - fseek (ifp, i, SEEK_CUR); - FORC4 sraw_mul[c ^ (c >> 1)] = get2(); - } - if (tag == 0xa021) - FORC4 cam_mul[c ^ (c >> 1)] = get4(); - if (tag == 0xa028) - FORC4 cam_mul[c ^ (c >> 1)] -= get4(); -next: - fseek (ifp, save, SEEK_SET); - } -quit: - order = sorder; -} - -/* - Since the TIFF DateTime string has no timezone information, - assume that the camera's clock was set to Universal Time. - */ -void CLASS get_timestamp (int reversed) -{ - struct tm t; - char str[20]; - int i; - - str[19] = 0; - if (reversed) - for (i=19; i--; ) str[i] = fgetc(ifp); - else - fread (str, 19, 1, ifp); - memset (&t, 0, sizeof t); - if (sscanf (str, "%d:%d:%d %d:%d:%d", &t.tm_year, &t.tm_mon, - &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec) != 6) - return; - t.tm_year -= 1900; - t.tm_mon -= 1; - t.tm_isdst = -1; - if (mktime(&t) > 0) - timestamp = mktime(&t); -} - -void CLASS parse_exif (int base) -{ - unsigned kodak, entries, tag, type, len, save, c; - double expo; - - kodak = !strncmp(make,"EASTMAN",7) && tiff_nifds < 3; - entries = get2(); - while (entries--) { - tiff_get (base, &tag, &type, &len, &save); - switch (tag) { - case 33434: shutter = getreal(type); break; - case 33437: aperture = getreal(type); break; - case 34855: iso_speed = get2(); break; - case 36867: - case 36868: get_timestamp(0); break; - case 37377: if ((expo = -getreal(type)) < 128) - shutter = pow (2, expo); break; - case 37378: aperture = pow (2, getreal(type)/2); break; - case 37386: focal_len = getreal(type); break; - case 37500: parse_makernote (base, 0); break; - case 40962: if (kodak) raw_width = get4(); break; - case 40963: if (kodak) raw_height = get4(); break; - case 41730: - if (get4() == 0x20002) - for (exif_cfa=c=0; c < 8; c+=2) - exif_cfa |= fgetc(ifp) * 0x01010101 << c; - } - fseek (ifp, save, SEEK_SET); - } -} - -void CLASS parse_gps (int base) -{ - unsigned entries, tag, type, len, save, c; - - entries = get2(); - while (entries--) { - tiff_get (base, &tag, &type, &len, &save); - switch (tag) { - case 1: case 3: case 5: - gpsdata[29+tag/2] = getc(ifp); break; - case 2: case 4: case 7: - FORC(6) gpsdata[tag/3*6+c] = get4(); break; - case 6: - FORC(2) gpsdata[18+c] = get4(); break; - case 18: case 29: - fgets ((char *) (gpsdata+14+tag/3), MIN(len,12), ifp); - } - fseek (ifp, save, SEEK_SET); - } -} - -void CLASS romm_coeff (float romm_cam[3][3]) -{ - static const float rgb_romm[3][3] = /* ROMM == Kodak ProPhoto */ - { { 2.034193, -0.727420, -0.306766 }, - { -0.228811, 1.231729, -0.002922 }, - { -0.008565, -0.153273, 1.161839 } }; - int i, j, k; - - for (i=0; i < 3; i++) - for (j=0; j < 3; j++) - for (cmatrix[i][j] = k=0; k < 3; k++) - cmatrix[i][j] += rgb_romm[i][k] * romm_cam[k][j]; -} - -void CLASS parse_mos (int offset) -{ - char data[40]; - int skip, from, i, c, neut[4], planes=0, frot=0; - static const char *mod[] = - { "","DCB2","Volare","Cantare","CMost","Valeo 6","Valeo 11","Valeo 22", - "Valeo 11p","Valeo 17","","Aptus 17","Aptus 22","Aptus 75","Aptus 65", - "Aptus 54S","Aptus 65S","Aptus 75S","AFi 5","AFi 6","AFi 7", - "","","","","","","","","","","","","","","","","","AFi-II 12" }; - float romm_cam[3][3]; - - fseek (ifp, offset, SEEK_SET); - while (1) { - if (get4() != 0x504b5453) break; - get4(); - fread (data, 1, 40, ifp); - skip = get4(); - from = ftell(ifp); - if (!strcmp(data,"JPEG_preview_data")) { - thumb_offset = from; - thumb_length = skip; - } - if (!strcmp(data,"icc_camera_profile")) { - profile_offset = from; - profile_length = skip; - } - if (!strcmp(data,"ShootObj_back_type")) { - fscanf (ifp, "%d", &i); - if ((unsigned) i < sizeof mod / sizeof (*mod)) - strcpy (model, mod[i]); - } - if (!strcmp(data,"icc_camera_to_tone_matrix")) { - for (i=0; i < 9; i++) - romm_cam[0][i] = int_to_float(get4()); - romm_coeff (romm_cam); - } - if (!strcmp(data,"CaptProf_color_matrix")) { - for (i=0; i < 9; i++) - fscanf (ifp, "%f", &romm_cam[0][i]); - romm_coeff (romm_cam); - } - if (!strcmp(data,"CaptProf_number_of_planes")) - fscanf (ifp, "%d", &planes); - if (!strcmp(data,"CaptProf_raw_data_rotation")) - fscanf (ifp, "%d", &flip); - if (!strcmp(data,"CaptProf_mosaic_pattern")) - FORC4 { - fscanf (ifp, "%d", &i); - if (i == 1) frot = c ^ (c >> 1); - } - if (!strcmp(data,"ImgProf_rotation_angle")) { - fscanf (ifp, "%d", &i); - flip = i - flip; - } - if (!strcmp(data,"NeutObj_neutrals") && !cam_mul[0]) { - FORC4 fscanf (ifp, "%d", neut+c); - FORC3 cam_mul[c] = (float) neut[0] / neut[c+1]; - } - if (!strcmp(data,"Rows_data")) - load_flags = get4(); - parse_mos (from); - fseek (ifp, skip+from, SEEK_SET); - } - if (planes) - filters = (planes == 1) * 0x01010101 * - (uchar) "\x94\x61\x16\x49"[(flip/90 + frot) & 3]; -} - -void CLASS linear_table (unsigned len) -{ - int i; - if (len > 0x1000) len = 0x1000; - read_shorts (curve, len); - for (i=len; i < 0x1000; i++) - curve[i] = curve[i-1]; - maximum = curve[0xfff]; -} - -void CLASS parse_kodak_ifd (int base) -{ - unsigned entries, tag, type, len, save; - int i, c, wbi=-2, wbtemp=6500; - float mul[3]={1,1,1}, num; - static const int wbtag[] = { 64037,64040,64039,64041,-1,-1,64042 }; - - entries = get2(); - if (entries > 1024) return; - while (entries--) { - tiff_get (base, &tag, &type, &len, &save); - if (tag == 1020) wbi = getint(type); - if (tag == 1021 && len == 72) { /* WB set in software */ - fseek (ifp, 40, SEEK_CUR); - FORC3 cam_mul[c] = 2048.0 / get2(); - wbi = -2; - } - if (tag == 2118) wbtemp = getint(type); - if (tag == 2130 + wbi) - FORC3 mul[c] = getreal(type); - if (tag == 2140 + wbi && wbi >= 0) - FORC3 { - for (num=i=0; i < 4; i++) - num += getreal(type) * pow (wbtemp/100.0, i); - cam_mul[c] = 2048 / (num * mul[c]); - } - if (tag == 2317) linear_table (len); - if (tag == 6020) iso_speed = getint(type); - if (tag == 64013) wbi = fgetc(ifp); - if ((unsigned) wbi < 7 && tag == wbtag[wbi]) - FORC3 cam_mul[c] = get4(); - if (tag == 64019) width = getint(type); - if (tag == 64020) height = (getint(type)+1) & -2; - fseek (ifp, save, SEEK_SET); - } -} - -void CLASS parse_minolta (int base); -int CLASS parse_tiff (int base); - -int CLASS parse_tiff_ifd (int base) -{ - unsigned entries, tag, type, len, plen=16, save; - int ifd, use_cm=0, cfa, i, j, c, ima_len=0; - int blrr=1, blrc=1, dblack[] = { 0,0,0,0 }; - char software[64], *cbuf, *cp; - uchar cfa_pat[16], cfa_pc[] = { 0,1,2,3 }, tab[256]; - double cc[4][4], cm[4][3], cam_xyz[4][3], num; - double ab[]={ 1,1,1,1 }, asn[] = { 0,0,0,0 }, xyz[] = { 1,1,1 }; - unsigned sony_curve[] = { 0,0,0,0,0,4095 }; - unsigned *buf, sony_offset=0, sony_length=0, sony_key=0; - struct jhead jh; - FILE *sfp; - - if (tiff_nifds >= sizeof tiff_ifd / sizeof tiff_ifd[0]) - return 1; - ifd = tiff_nifds++; - for (j=0; j < 4; j++) - for (i=0; i < 4; i++) - cc[j][i] = i == j; - entries = get2(); - if (entries > 512) return 1; - while (entries--) { - tiff_get (base, &tag, &type, &len, &save); - switch (tag) { - case 5: width = get2(); break; - case 6: height = get2(); break; - case 7: width += get2(); break; - case 9: filters = get2(); break; - case 17: case 18: - if (type == 3 && len == 1) - cam_mul[(tag-17)*2] = get2() / 256.0; - break; - case 23: - if (type == 3) iso_speed = get2(); - break; - case 36: case 37: case 38: - cam_mul[tag-0x24] = get2(); - break; - case 39: - if (len < 50 || cam_mul[0]) break; - fseek (ifp, 12, SEEK_CUR); - FORC3 cam_mul[c] = get2(); - break; - case 46: - if (type != 7 || fgetc(ifp) != 0xff || fgetc(ifp) != 0xd8) break; - thumb_offset = ftell(ifp) - 2; - thumb_length = len; - break; - case 61440: /* Fuji HS10 table */ - parse_tiff_ifd (base); - break; - case 2: case 256: case 61441: /* ImageWidth */ - tiff_ifd[ifd].width = getint(type); - break; - case 3: case 257: case 61442: /* ImageHeight */ - tiff_ifd[ifd].height = getint(type); - break; - case 258: /* BitsPerSample */ - case 61443: - tiff_ifd[ifd].samples = len & 7; - tiff_ifd[ifd].bps = getint(type); - break; - case 61446: - raw_height = 0; - load_raw = &CLASS packed_load_raw; - load_flags = get4() && (filters=0x16161616) ? 24:80; - break; - case 259: /* Compression */ - tiff_ifd[ifd].comp = getint(type); - break; - case 262: /* PhotometricInterpretation */ - tiff_ifd[ifd].phint = get2(); - break; - case 270: /* ImageDescription */ - fread (desc, 512, 1, ifp); - break; - case 271: /* Make */ - fgets (make, 64, ifp); - break; - case 272: /* Model */ - fgets (model, 64, ifp); - break; - case 280: /* Panasonic RW2 offset */ - if (type != 4) break; - load_raw = &CLASS panasonic_load_raw; - load_flags = 0x2008; - case 273: /* StripOffset */ - case 513: /* JpegIFOffset */ - case 61447: - tiff_ifd[ifd].offset = get4()+base; - if (!tiff_ifd[ifd].bps && tiff_ifd[ifd].offset > 0) { - fseek (ifp, tiff_ifd[ifd].offset, SEEK_SET); - if (ljpeg_start (&jh, 1)) { - tiff_ifd[ifd].comp = 6; - tiff_ifd[ifd].width = jh.wide; - tiff_ifd[ifd].height = jh.high; - tiff_ifd[ifd].bps = jh.bits; - tiff_ifd[ifd].samples = jh.clrs; - if (!(jh.sraw || (jh.clrs & 1))) - tiff_ifd[ifd].width *= jh.clrs; - i = order; - parse_tiff (tiff_ifd[ifd].offset + 12); - order = i; - } - } - break; - case 274: /* Orientation */ - tiff_ifd[ifd].flip = "50132467"[get2() & 7]-'0'; - break; - case 277: /* SamplesPerPixel */ - tiff_ifd[ifd].samples = getint(type) & 7; - break; - case 279: /* StripByteCounts */ - case 514: - case 61448: - tiff_ifd[ifd].bytes = get4(); - break; - case 61454: - FORC3 cam_mul[(4-c) % 3] = getint(type); - break; - case 305: case 11: /* Software */ - fgets (software, 64, ifp); - if (!strncmp(software,"Adobe",5) || - !strncmp(software,"dcraw",5) || - !strncmp(software,"UFRaw",5) || - !strncmp(software,"Bibble",6) || - !strncmp(software,"Nikon Scan",10) || - !strcmp (software,"Digital Photo Professional")) - is_raw = 0; - break; - case 306: /* DateTime */ - get_timestamp(0); - break; - case 315: /* Artist */ - fread (artist, 64, 1, ifp); - break; - case 322: /* TileWidth */ - tiff_ifd[ifd].tile_width = getint(type); - break; - case 323: /* TileLength */ - tiff_ifd[ifd].tile_length = getint(type); - break; - case 324: /* TileOffsets */ - tiff_ifd[ifd].offset = len > 1 ? ftell(ifp) : get4(); - if (len == 4) { - load_raw = &CLASS sinar_4shot_load_raw; - is_raw = 5; - } - break; - case 330: /* SubIFDs */ - if (!strcmp(model,"DSLR-A100") && tiff_ifd[ifd].width == 3872) { - load_raw = &CLASS sony_arw_load_raw; - data_offset = get4()+base; - ifd++; break; - } - while (len--) { - i = ftell(ifp); - fseek (ifp, get4()+base, SEEK_SET); - if (parse_tiff_ifd (base)) break; - fseek (ifp, i+4, SEEK_SET); - } - break; - case 400: - strcpy (make, "Sarnoff"); - maximum = 0xfff; - break; - case 28688: - FORC4 sony_curve[c+1] = get2() >> 2 & 0xfff; - for (i=0; i < 5; i++) - for (j = sony_curve[i]+1; j <= sony_curve[i+1]; j++) - curve[j] = curve[j-1] + (1 << i); - break; - case 29184: sony_offset = get4(); break; - case 29185: sony_length = get4(); break; - case 29217: sony_key = get4(); break; - case 29264: - parse_minolta (ftell(ifp)); - raw_width = 0; - break; - case 29443: - FORC4 cam_mul[c ^ (c < 2)] = get2(); - break; - case 29459: - FORC4 cam_mul[c] = get2(); - i = (cam_mul[1] == 1024 && cam_mul[2] == 1024) << 1; - SWAP (cam_mul[i],cam_mul[i+1]) - break; - case 33405: /* Model2 */ - fgets (model2, 64, ifp); - break; - case 33422: /* CFAPattern */ - case 64777: /* Kodak P-series */ - if ((plen=len) > 16) plen = 16; - fread (cfa_pat, 1, plen, ifp); - for (colors=cfa=i=0; i < plen; i++) { - colors += !(cfa & (1 << cfa_pat[i])); - cfa |= 1 << cfa_pat[i]; - } - if (cfa == 070) memcpy (cfa_pc,"\003\004\005",3); /* CMY */ - if (cfa == 072) memcpy (cfa_pc,"\005\003\004\001",4); /* GMCY */ - goto guess_cfa_pc; - case 33424: - case 65024: - fseek (ifp, get4()+base, SEEK_SET); - parse_kodak_ifd (base); - break; - case 33434: /* ExposureTime */ - shutter = getreal(type); - break; - case 33437: /* FNumber */ - aperture = getreal(type); - break; - case 34306: /* Leaf white balance */ - FORC4 cam_mul[c ^ 1] = 4096.0 / get2(); - break; - case 34307: /* Leaf CatchLight color matrix */ - fread (software, 1, 7, ifp); - if (strncmp(software,"MATRIX",6)) break; - colors = 4; - for (raw_color = i=0; i < 3; i++) { - FORC4 fscanf (ifp, "%f", &rgb_cam[i][c^1]); - if (!use_camera_wb) continue; - num = 0; - FORC4 num += rgb_cam[i][c]; - FORC4 rgb_cam[i][c] /= num; - } - break; - case 34310: /* Leaf metadata */ - parse_mos (ftell(ifp)); - case 34303: - strcpy (make, "Leaf"); - break; - case 34665: /* EXIF tag */ - fseek (ifp, get4()+base, SEEK_SET); - parse_exif (base); - break; - case 34853: /* GPSInfo tag */ - fseek (ifp, get4()+base, SEEK_SET); - parse_gps (base); - break; - case 34675: /* InterColorProfile */ - case 50831: /* AsShotICCProfile */ - profile_offset = ftell(ifp); - profile_length = len; - break; - case 37122: /* CompressedBitsPerPixel */ - kodak_cbpp = get4(); - break; - case 37386: /* FocalLength */ - focal_len = getreal(type); - break; - case 37393: /* ImageNumber */ - shot_order = getint(type); - break; - case 37400: /* old Kodak KDC tag */ - for (raw_color = i=0; i < 3; i++) { - getreal(type); - FORC3 rgb_cam[i][c] = getreal(type); - } - break; - case 46275: /* Imacon tags */ - strcpy (make, "Imacon"); - data_offset = ftell(ifp); - ima_len = len; - break; - case 46279: - if (!ima_len) break; - fseek (ifp, 38, SEEK_CUR); - case 46274: - fseek (ifp, 40, SEEK_CUR); - raw_width = get4(); - raw_height = get4(); - left_margin = get4() & 7; - width = raw_width - left_margin - (get4() & 7); - top_margin = get4() & 7; - height = raw_height - top_margin - (get4() & 7); - if (raw_width == 7262) { - height = 5444; - width = 7244; - left_margin = 7; - } - fseek (ifp, 52, SEEK_CUR); - FORC3 cam_mul[c] = getreal(11); - fseek (ifp, 114, SEEK_CUR); - flip = (get2() >> 7) * 90; - if (width * height * 6 == ima_len) { - if (flip % 180 == 90) SWAP(width,height); - raw_width = width; - raw_height = height; - left_margin = top_margin = filters = flip = 0; - } - sprintf (model, "Ixpress %d-Mp", height*width/1000000); - load_raw = &CLASS imacon_full_load_raw; - if (filters) { - if (left_margin & 1) filters = 0x61616161; - load_raw = &CLASS unpacked_load_raw; - } - maximum = 0xffff; - break; - case 50454: /* Sinar tag */ - case 50455: - if (!(cbuf = (char *) malloc(len))) break; - fread (cbuf, 1, len, ifp); - for (cp = cbuf-1; cp && cp < cbuf+len; cp = strchr(cp,'\n')) - if (!strncmp (++cp,"Neutral ",8)) - sscanf (cp+8, "%f %f %f", cam_mul, cam_mul+1, cam_mul+2); - free (cbuf); - break; - case 50458: - if (!make[0]) strcpy (make, "Hasselblad"); - break; - case 50459: /* Hasselblad tag */ - i = order; - j = ftell(ifp); - c = tiff_nifds; - order = get2(); - fseek (ifp, j+(get2(),get4()), SEEK_SET); - parse_tiff_ifd (j); - maximum = 0xffff; - tiff_nifds = c; - order = i; - break; - case 50706: /* DNGVersion */ - FORC4 dng_version = (dng_version << 8) + fgetc(ifp); - if (!make[0]) strcpy (make, "DNG"); - is_raw = 1; - break; - case 50710: /* CFAPlaneColor */ - if (len > 4) len = 4; - colors = len; - fread (cfa_pc, 1, colors, ifp); -guess_cfa_pc: - FORCC tab[cfa_pc[c]] = c; - cdesc[c] = 0; - for (i=16; i--; ) - filters = filters << 2 | tab[cfa_pat[i % plen]]; - break; - case 50711: /* CFALayout */ - if (get2() == 2) { - fuji_width = 1; - filters = 0x49494949; - } - break; - case 291: - case 50712: /* LinearizationTable */ - linear_table (len); - break; - case 50713: /* BlackLevelRepeatDim */ - blrr = get2(); - blrc = get2(); - break; - case 61450: - blrr = blrc = 2; - case 50714: /* BlackLevel */ - black = getreal(type); - if (!filters || !~filters) break; - dblack[0] = black; - dblack[1] = (blrc == 2) ? getreal(type):dblack[0]; - dblack[2] = (blrr == 2) ? getreal(type):dblack[0]; - dblack[3] = (blrc == 2 && blrr == 2) ? getreal(type):dblack[1]; - if (colors == 3) - filters |= ((filters >> 2 & 0x22222222) | - (filters << 2 & 0x88888888)) & filters << 1; - FORC4 cblack[filters >> (c << 1) & 3] = dblack[c]; - black = 0; - break; - case 50715: /* BlackLevelDeltaH */ - case 50716: /* BlackLevelDeltaV */ - for (num=i=0; i < len; i++) - num += getreal(type); - black += num/len + 0.5; - break; - case 50717: /* WhiteLevel */ - maximum = getint(type); - break; - case 50718: /* DefaultScale */ - pixel_aspect = getreal(type); - pixel_aspect /= getreal(type); - break; - case 50721: /* ColorMatrix1 */ - case 50722: /* ColorMatrix2 */ - FORCC for (j=0; j < 3; j++) - cm[c][j] = getreal(type); - use_cm = 1; - break; - case 50723: /* CameraCalibration1 */ - case 50724: /* CameraCalibration2 */ - for (i=0; i < colors; i++) - FORCC cc[i][c] = getreal(type); - break; - case 50727: /* AnalogBalance */ - FORCC ab[c] = getreal(type); - break; - case 50728: /* AsShotNeutral */ - FORCC asn[c] = getreal(type); - break; - case 50729: /* AsShotWhiteXY */ - xyz[0] = getreal(type); - xyz[1] = getreal(type); - xyz[2] = 1 - xyz[0] - xyz[1]; - FORC3 xyz[c] /= d65_white[c]; - break; - case 50740: /* DNGPrivateData */ - if (dng_version) break; - parse_minolta (j = get4()+base); - fseek (ifp, j, SEEK_SET); - parse_tiff_ifd (base); - break; - case 50752: - read_shorts (cr2_slice, 3); - break; - case 50829: /* ActiveArea */ - top_margin = getint(type); - left_margin = getint(type); - height = getint(type) - top_margin; - width = getint(type) - left_margin; - break; - case 50830: /* MaskedAreas */ - for (i=0; i < len && i < 32; i++) - mask[0][i] = getint(type); - black = 0; - break; - case 51009: /* OpcodeList2 */ - meta_offset = ftell(ifp); - break; - case 64772: /* Kodak P-series */ - if (len < 13) break; - fseek (ifp, 16, SEEK_CUR); - data_offset = get4(); - fseek (ifp, 28, SEEK_CUR); - data_offset += get4(); - load_raw = &CLASS packed_load_raw; - break; - case 65026: - if (type == 2) fgets (model2, 64, ifp); - } - fseek (ifp, save, SEEK_SET); - } - if (sony_length && (buf = (unsigned *) malloc(sony_length))) { - fseek (ifp, sony_offset, SEEK_SET); - fread (buf, sony_length, 1, ifp); - sony_decrypt (buf, sony_length/4, 1, sony_key); - sfp = ifp; - if ((ifp = tmpfile())) { - fwrite (buf, sony_length, 1, ifp); - fseek (ifp, 0, SEEK_SET); - parse_tiff_ifd (-sony_offset); - fclose (ifp); - } - ifp = sfp; - free (buf); - } - for (i=0; i < colors; i++) - FORCC cc[i][c] *= ab[i]; - if (use_cm) { - FORCC for (i=0; i < 3; i++) - for (cam_xyz[c][i]=j=0; j < colors; j++) - cam_xyz[c][i] += cc[c][j] * cm[j][i] * xyz[i]; - cam_xyz_coeff (cam_xyz); - } - if (asn[0]) { - cam_mul[3] = 0; - FORCC cam_mul[c] = 1 / asn[c]; - } - if (!use_cm) - FORCC pre_mul[c] /= cc[c][c]; - return 0; -} - -int CLASS parse_tiff (int base) -{ - int doff; - - fseek (ifp, base, SEEK_SET); - order = get2(); - if (order != 0x4949 && order != 0x4d4d) return 0; - get2(); - while ((doff = get4())) { - fseek (ifp, doff+base, SEEK_SET); - if (parse_tiff_ifd (base)) break; - } - return 1; -} - -void CLASS apply_tiff() -{ - int max_samp=0, raw=-1, thm=-1, i; - struct jhead jh; - - thumb_misc = 16; - if (thumb_offset) { - fseek (ifp, thumb_offset, SEEK_SET); - if (ljpeg_start (&jh, 1)) { - thumb_misc = jh.bits; - thumb_width = jh.wide; - thumb_height = jh.high; - } - } - for (i=0; i < tiff_nifds; i++) { - if (max_samp < tiff_ifd[i].samples) - max_samp = tiff_ifd[i].samples; - if (max_samp > 3) max_samp = 3; - if ((tiff_ifd[i].comp != 6 || tiff_ifd[i].samples != 3) && - (tiff_ifd[i].width | tiff_ifd[i].height) < 0x10000 && - tiff_ifd[i].width*tiff_ifd[i].height > raw_width*raw_height) { - raw_width = tiff_ifd[i].width; - raw_height = tiff_ifd[i].height; - tiff_bps = tiff_ifd[i].bps; - tiff_compress = tiff_ifd[i].comp; - data_offset = tiff_ifd[i].offset; - tiff_flip = tiff_ifd[i].flip; - tiff_samples = tiff_ifd[i].samples; - tile_width = tiff_ifd[i].tile_width; - tile_length = tiff_ifd[i].tile_length; - raw = i; - } - } - if (!tile_width ) tile_width = INT_MAX; - if (!tile_length) tile_length = INT_MAX; - for (i=tiff_nifds; i--; ) - if (tiff_ifd[i].flip) tiff_flip = tiff_ifd[i].flip; - if (raw >= 0 && !load_raw) - switch (tiff_compress) { - case 32767: - if (tiff_ifd[raw].bytes == raw_width*raw_height) { - tiff_bps = 12; - load_raw = &CLASS sony_arw2_load_raw; break; - } - if (tiff_ifd[raw].bytes*8 != raw_width*raw_height*tiff_bps) { - raw_height += 8; - load_raw = &CLASS sony_arw_load_raw; break; - } - load_flags = 79; - case 32769: - load_flags++; - case 32770: - case 32773: goto slr; - case 0: case 1: - if (tiff_ifd[raw].bytes*5 == raw_width*raw_height*8) { - load_flags = 81; - tiff_bps = 12; - } slr: - switch (tiff_bps) { - case 8: load_raw = &CLASS eight_bit_load_raw; break; - case 12: if (tiff_ifd[raw].phint == 2) - load_flags = 6; - load_raw = &CLASS packed_load_raw; break; - case 14: load_flags = 0; - case 16: load_raw = &CLASS unpacked_load_raw; break; - } - break; - case 6: case 7: case 99: - load_raw = &CLASS lossless_jpeg_load_raw; break; - case 262: - load_raw = &CLASS kodak_262_load_raw; break; - case 34713: - load_raw = &CLASS nikon_load_raw; break; - case 34892: - load_raw = &CLASS lossy_dng_load_raw; break; - case 65535: - load_raw = &CLASS pentax_load_raw; break; - case 65000: - switch (tiff_ifd[raw].phint) { - case 2: load_raw = &CLASS kodak_rgb_load_raw; filters = 0; break; - case 6: load_raw = &CLASS kodak_ycbcr_load_raw; filters = 0; break; - case 32803: load_raw = &CLASS kodak_65000_load_raw; - } - case 32867: break; - default: is_raw = 0; - } - if (!dng_version) - if ( (tiff_samples == 3 && tiff_ifd[raw].bytes && - tiff_bps != 14 && tiff_bps != 2048 && tiff_compress != 32770) - || (tiff_bps == 8 && !strstr(make,"KODAK") && !strstr(make,"Kodak") && - !strstr(model2,"DEBUG RAW"))) - is_raw = 0; - for (i=0; i < tiff_nifds; i++) - if (i != raw && tiff_ifd[i].samples == max_samp && - tiff_ifd[i].width * tiff_ifd[i].height / SQR(tiff_ifd[i].bps+1) > - thumb_width * thumb_height / SQR(thumb_misc+1) - && tiff_ifd[i].comp != 34892) { - thumb_width = tiff_ifd[i].width; - thumb_height = tiff_ifd[i].height; - thumb_offset = tiff_ifd[i].offset; - thumb_length = tiff_ifd[i].bytes; - thumb_misc = tiff_ifd[i].bps; - thm = i; - } - if (thm >= 0) { - thumb_misc |= tiff_ifd[thm].samples << 5; - switch (tiff_ifd[thm].comp) { - case 0: - write_thumb = &CLASS layer_thumb; - break; - case 1: - if (tiff_ifd[thm].bps <= 8) - write_thumb = &CLASS ppm_thumb; - else if (!strcmp(make,"Imacon")) - write_thumb = &CLASS ppm16_thumb; - else - thumb_load_raw = &CLASS kodak_thumb_load_raw; - break; - case 65000: - thumb_load_raw = tiff_ifd[thm].phint == 6 ? - &CLASS kodak_ycbcr_load_raw : &CLASS kodak_rgb_load_raw; - } - } -} - -void CLASS parse_minolta (int base) -{ - int save, tag, len, offset, high=0, wide=0, i, c; - short sorder=order; - - fseek (ifp, base, SEEK_SET); - if (fgetc(ifp) || fgetc(ifp)-'M' || fgetc(ifp)-'R') return; - order = fgetc(ifp) * 0x101; - offset = base + get4() + 8; - while ((save=ftell(ifp)) < offset) { - for (tag=i=0; i < 4; i++) - tag = tag << 8 | fgetc(ifp); - len = get4(); - switch (tag) { - case 0x505244: /* PRD */ - fseek (ifp, 8, SEEK_CUR); - high = get2(); - wide = get2(); - break; - case 0x574247: /* WBG */ - get4(); - i = strcmp(model,"DiMAGE A200") ? 0:3; - FORC4 cam_mul[c ^ (c >> 1) ^ i] = get2(); - break; - case 0x545457: /* TTW */ - parse_tiff (ftell(ifp)); - data_offset = offset; - } - fseek (ifp, save+len+8, SEEK_SET); - } - raw_height = high; - raw_width = wide; - order = sorder; -} - -/* - Many cameras have a "debug mode" that writes JPEG and raw - at the same time. The raw file has no header, so try to - to open the matching JPEG file and read its metadata. - */ -void CLASS parse_external_jpeg() -{ - const char *file, *ext; - char *jname, *jfile, *jext; - FILE *save=ifp; - - ext = strrchr (ifname, '.'); - file = strrchr (ifname, '/'); - if (!file) file = strrchr (ifname, '\\'); - if (!file) file = ifname-1; - file++; - if (!ext || strlen(ext) != 4 || ext-file != 8) return; - jname = (char *) malloc (strlen(ifname) + 1); - merror (jname, "parse_external_jpeg()"); - strcpy (jname, ifname); - jfile = file - ifname + jname; - jext = ext - ifname + jname; - if (strcasecmp (ext, ".jpg")) { - strcpy (jext, isupper(ext[1]) ? ".JPG":".jpg"); - if (isdigit(*file)) { - memcpy (jfile, file+4, 4); - memcpy (jfile+4, file, 4); - } - } else - while (isdigit(*--jext)) { - if (*jext != '9') { - (*jext)++; - break; - } - *jext = '0'; - } - if (strcmp (jname, ifname)) { - if ((ifp = fopen (jname, "rb"))) { - if (verbose) - fprintf (stderr,_("Reading metadata from %s ...\n"), jname); - parse_tiff (12); - thumb_offset = 0; - is_raw = 1; - fclose (ifp); - } - } - if (!timestamp) - fprintf (stderr,_("Failed to read metadata from %s\n"), jname); - free (jname); - ifp = save; -} - -/* - CIFF block 0x1030 contains an 8x8 white sample. - Load this into white[][] for use in scale_colors(). - */ -void CLASS ciff_block_1030() -{ - static const ushort key[] = { 0x410, 0x45f3 }; - int i, bpp, row, col, vbits=0; - unsigned long bitbuf=0; - - if ((get2(),get4()) != 0x80008 || !get4()) return; - bpp = get2(); - if (bpp != 10 && bpp != 12) return; - for (i=row=0; row < 8; row++) - for (col=0; col < 8; col++) { - if (vbits < bpp) { - bitbuf = bitbuf << 16 | (get2() ^ key[i++ & 1]); - vbits += 16; - } - white[row][col] = - bitbuf << (LONG_BIT - vbits) >> (LONG_BIT - bpp); - vbits -= bpp; - } -} - -/* - Parse a CIFF file, better known as Canon CRW format. - */ -void CLASS parse_ciff (int offset, int length) -{ - int tboff, nrecs, c, type, len, save, wbi=-1; - ushort key[] = { 0x410, 0x45f3 }; - - fseek (ifp, offset+length-4, SEEK_SET); - tboff = get4() + offset; - fseek (ifp, tboff, SEEK_SET); - nrecs = get2(); - if (nrecs > 100) return; - while (nrecs--) { - type = get2(); - len = get4(); - save = ftell(ifp) + 4; - fseek (ifp, offset+get4(), SEEK_SET); - if ((((type >> 8) + 8) | 8) == 0x38) - parse_ciff (ftell(ifp), len); /* Parse a sub-table */ - - if (type == 0x0810) - fread (artist, 64, 1, ifp); - if (type == 0x080a) { - fread (make, 64, 1, ifp); - fseek (ifp, strlen(make) - 63, SEEK_CUR); - fread (model, 64, 1, ifp); - } - if (type == 0x1810) { - fseek (ifp, 12, SEEK_CUR); - flip = get4(); - } - if (type == 0x1835) /* Get the decoder table */ - tiff_compress = get4(); - if (type == 0x2007) { - thumb_offset = ftell(ifp); - thumb_length = len; - } - if (type == 0x1818) { - shutter = pow (2, -int_to_float((get4(),get4()))); - aperture = pow (2, int_to_float(get4())/2); - } - if (type == 0x102a) { - iso_speed = pow (2, (get4(),get2())/32.0 - 4) * 50; - aperture = pow (2, (get2(),(short)get2())/64.0); - shutter = pow (2,-((short)get2())/32.0); - wbi = (get2(),get2()); - if (wbi > 17) wbi = 0; - fseek (ifp, 32, SEEK_CUR); - if (shutter > 1e6) shutter = get2()/10.0; - } - if (type == 0x102c) { - if (get2() > 512) { /* Pro90, G1 */ - fseek (ifp, 118, SEEK_CUR); - FORC4 cam_mul[c ^ 2] = get2(); - } else { /* G2, S30, S40 */ - fseek (ifp, 98, SEEK_CUR); - FORC4 cam_mul[c ^ (c >> 1) ^ 1] = get2(); - } - } - if (type == 0x0032) { - if (len == 768) { /* EOS D30 */ - fseek (ifp, 72, SEEK_CUR); - FORC4 cam_mul[c ^ (c >> 1)] = 1024.0 / get2(); - if (!wbi) cam_mul[0] = -1; /* use my auto white balance */ - } else if (!cam_mul[0]) { - if (get2() == key[0]) /* Pro1, G6, S60, S70 */ - c = (strstr(model,"Pro1") ? - "012346000000000000":"01345:000000006008")[wbi]-'0'+ 2; - else { /* G3, G5, S45, S50 */ - c = "023457000000006000"[wbi]-'0'; - key[0] = key[1] = 0; - } - fseek (ifp, 78 + c*8, SEEK_CUR); - FORC4 cam_mul[c ^ (c >> 1) ^ 1] = get2() ^ key[c & 1]; - if (!wbi) cam_mul[0] = -1; - } - } - if (type == 0x10a9) { /* D60, 10D, 300D, and clones */ - if (len > 66) wbi = "0134567028"[wbi]-'0'; - fseek (ifp, 2 + wbi*8, SEEK_CUR); - FORC4 cam_mul[c ^ (c >> 1)] = get2(); - } - if (type == 0x1030 && (0x18040 >> wbi & 1)) - ciff_block_1030(); /* all that don't have 0x10a9 */ - if (type == 0x1031) { - raw_width = (get2(),get2()); - raw_height = get2(); - } - if (type == 0x5029) { - focal_len = len >> 16; - if ((len & 0xffff) == 2) focal_len /= 32; - } - if (type == 0x5813) flash_used = int_to_float(len); - if (type == 0x5814) canon_ev = int_to_float(len); - if (type == 0x5817) shot_order = len; - if (type == 0x5834) unique_id = len; - if (type == 0x580e) timestamp = len; - if (type == 0x180e) timestamp = get4(); -#ifdef LOCALTIME - if ((type | 0x4000) == 0x580e) - timestamp = mktime (gmtime (×tamp)); -#endif - fseek (ifp, save, SEEK_SET); - } -} - -void CLASS parse_rollei() -{ - char line[128], *val; - struct tm t; - - fseek (ifp, 0, SEEK_SET); - memset (&t, 0, sizeof t); - do { - fgets (line, 128, ifp); - if ((val = strchr(line,'='))) - *val++ = 0; - else - val = line + strlen(line); - if (!strcmp(line,"DAT")) - sscanf (val, "%d.%d.%d", &t.tm_mday, &t.tm_mon, &t.tm_year); - if (!strcmp(line,"TIM")) - sscanf (val, "%d:%d:%d", &t.tm_hour, &t.tm_min, &t.tm_sec); - if (!strcmp(line,"HDR")) - thumb_offset = atoi(val); - if (!strcmp(line,"X ")) - raw_width = atoi(val); - if (!strcmp(line,"Y ")) - raw_height = atoi(val); - if (!strcmp(line,"TX ")) - thumb_width = atoi(val); - if (!strcmp(line,"TY ")) - thumb_height = atoi(val); - } while (strncmp(line,"EOHD",4)); - data_offset = thumb_offset + thumb_width * thumb_height * 2; - t.tm_year -= 1900; - t.tm_mon -= 1; - if (mktime(&t) > 0) - timestamp = mktime(&t); - strcpy (make, "Rollei"); - strcpy (model,"d530flex"); - write_thumb = &CLASS rollei_thumb; -} - -void CLASS parse_sinar_ia() -{ - int entries, off; - char str[8], *cp; - - order = 0x4949; - fseek (ifp, 4, SEEK_SET); - entries = get4(); - fseek (ifp, get4(), SEEK_SET); - while (entries--) { - off = get4(); get4(); - fread (str, 8, 1, ifp); - if (!strcmp(str,"META")) meta_offset = off; - if (!strcmp(str,"THUMB")) thumb_offset = off; - if (!strcmp(str,"RAW0")) data_offset = off; - } - fseek (ifp, meta_offset+20, SEEK_SET); - fread (make, 64, 1, ifp); - make[63] = 0; - if ((cp = strchr(make,' '))) { - strcpy (model, cp+1); - *cp = 0; - } - raw_width = get2(); - raw_height = get2(); - load_raw = &CLASS unpacked_load_raw; - thumb_width = (get4(),get2()); - thumb_height = get2(); - write_thumb = &CLASS ppm_thumb; - maximum = 0x3fff; -} - -void CLASS parse_phase_one (int base) -{ - unsigned entries, tag, type, len, data, save, i, c; - float romm_cam[3][3]; - char *cp; - - memset (&ph1, 0, sizeof ph1); - fseek (ifp, base, SEEK_SET); - order = get4() & 0xffff; - if (get4() >> 8 != 0x526177) return; /* "Raw" */ - fseek (ifp, get4()+base, SEEK_SET); - entries = get4(); - get4(); - while (entries--) { - tag = get4(); - type = get4(); - len = get4(); - data = get4(); - save = ftell(ifp); - fseek (ifp, base+data, SEEK_SET); - switch (tag) { - case 0x100: flip = "0653"[data & 3]-'0'; break; - case 0x106: - for (i=0; i < 9; i++) - romm_cam[0][i] = getreal(11); - romm_coeff (romm_cam); - break; - case 0x107: - FORC3 cam_mul[c] = getreal(11); - break; - case 0x108: raw_width = data; break; - case 0x109: raw_height = data; break; - case 0x10a: left_margin = data; break; - case 0x10b: top_margin = data; break; - case 0x10c: width = data; break; - case 0x10d: height = data; break; - case 0x10e: ph1.format = data; break; - case 0x10f: data_offset = data+base; break; - case 0x110: meta_offset = data+base; - meta_length = len; break; - case 0x112: ph1.key_off = save - 4; break; - case 0x210: ph1.tag_210 = int_to_float(data); break; - case 0x21a: ph1.tag_21a = data; break; - case 0x21c: strip_offset = data+base; break; - case 0x21d: ph1.black = data; break; - case 0x222: ph1.split_col = data; break; - case 0x223: ph1.black_off = data+base; break; - case 0x301: - model[63] = 0; - fread (model, 1, 63, ifp); - if ((cp = strstr(model," camera"))) *cp = 0; - } - fseek (ifp, save, SEEK_SET); - } - load_raw = ph1.format < 3 ? - &CLASS phase_one_load_raw : &CLASS phase_one_load_raw_c; - maximum = 0xffff; - strcpy (make, "Phase One"); - if (model[0]) return; - switch (raw_height) { - case 2060: strcpy (model,"LightPhase"); break; - case 2682: strcpy (model,"H 10"); break; - case 4128: strcpy (model,"H 20"); break; - case 5488: strcpy (model,"H 25"); break; - } -} - -void CLASS parse_fuji (int offset) -{ - unsigned entries, tag, len, save, c; - - fseek (ifp, offset, SEEK_SET); - entries = get4(); - if (entries > 255) return; - while (entries--) { - tag = get2(); - len = get2(); - save = ftell(ifp); - if (tag == 0x100) { - raw_height = get2(); - raw_width = get2(); - } else if (tag == 0x121) { - height = get2(); - if ((width = get2()) == 4284) width += 3; - } else if (tag == 0x130) { - fuji_layout = fgetc(ifp) >> 7; - fuji_width = !(fgetc(ifp) & 8); - } else if (tag == 0x2ff0) { - FORC4 cam_mul[c ^ 1] = get2(); - } else if (tag == 0xc000) { - c = order; - order = 0x4949; - width = get4(); - height = get4(); - order = c; - } - fseek (ifp, save+len, SEEK_SET); - } - height <<= fuji_layout; - width >>= fuji_layout; -} - -int CLASS parse_jpeg (int offset) -{ - int len, save, hlen, mark; - - fseek (ifp, offset, SEEK_SET); - if (fgetc(ifp) != 0xff || fgetc(ifp) != 0xd8) return 0; - - while (fgetc(ifp) == 0xff && (mark = fgetc(ifp)) != 0xda) { - order = 0x4d4d; - len = get2() - 2; - save = ftell(ifp); - if (mark == 0xc0 || mark == 0xc3) { - fgetc(ifp); - raw_height = get2(); - raw_width = get2(); - } - order = get2(); - hlen = get4(); - if (get4() == 0x48454150) /* "HEAP" */ - parse_ciff (save+hlen, len-hlen); - if (parse_tiff (save+6)) apply_tiff(); - fseek (ifp, save+len, SEEK_SET); - } - return 1; -} - -void CLASS parse_riff() -{ - unsigned i, size, end; - char tag[4], date[64], month[64]; - static const char mon[12][4] = - { "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" }; - struct tm t; - - order = 0x4949; - fread (tag, 4, 1, ifp); - size = get4(); - end = ftell(ifp) + size; - if (!memcmp(tag,"RIFF",4) || !memcmp(tag,"LIST",4)) { - get4(); - while (ftell(ifp)+7 < end) - parse_riff(); - } else if (!memcmp(tag,"nctg",4)) { - while (ftell(ifp)+7 < end) { - i = get2(); - size = get2(); - if ((i+1) >> 1 == 10 && size == 20) - get_timestamp(0); - else fseek (ifp, size, SEEK_CUR); - } - } else if (!memcmp(tag,"IDIT",4) && size < 64) { - fread (date, 64, 1, ifp); - date[size] = 0; - memset (&t, 0, sizeof t); - if (sscanf (date, "%*s %s %d %d:%d:%d %d", month, &t.tm_mday, - &t.tm_hour, &t.tm_min, &t.tm_sec, &t.tm_year) == 6) { - for (i=0; i < 12 && strcasecmp(mon[i],month); i++); - t.tm_mon = i; - t.tm_year -= 1900; - if (mktime(&t) > 0) - timestamp = mktime(&t); - } - } else - fseek (ifp, size, SEEK_CUR); -} - -void CLASS parse_smal (int offset, int fsize) -{ - int ver; - - fseek (ifp, offset+2, SEEK_SET); - order = 0x4949; - ver = fgetc(ifp); - if (ver == 6) - fseek (ifp, 5, SEEK_CUR); - if (get4() != fsize) return; - if (ver > 6) data_offset = get4(); - raw_height = height = get2(); - raw_width = width = get2(); - strcpy (make, "SMaL"); - sprintf (model, "v%d %dx%d", ver, width, height); - if (ver == 6) load_raw = &CLASS smal_v6_load_raw; - if (ver == 9) load_raw = &CLASS smal_v9_load_raw; -} - -void CLASS parse_cine() -{ - unsigned off_head, off_setup, off_image, i; - - order = 0x4949; - fseek (ifp, 4, SEEK_SET); - is_raw = get2() == 2; - fseek (ifp, 14, SEEK_CUR); - is_raw *= get4(); - off_head = get4(); - off_setup = get4(); - off_image = get4(); - timestamp = get4(); - if ((i = get4())) timestamp = i; - fseek (ifp, off_head+4, SEEK_SET); - raw_width = get4(); - raw_height = get4(); - switch (get2(),get2()) { - case 8: load_raw = &CLASS eight_bit_load_raw; break; - case 16: load_raw = &CLASS unpacked_load_raw; - } - fseek (ifp, off_setup+792, SEEK_SET); - strcpy (make, "CINE"); - sprintf (model, "%d", get4()); - fseek (ifp, 12, SEEK_CUR); - switch ((i=get4()) & 0xffffff) { - case 3: filters = 0x94949494; break; - case 4: filters = 0x49494949; break; - default: is_raw = 0; - } - fseek (ifp, 72, SEEK_CUR); - switch ((get4()+3600) % 360) { - case 270: flip = 4; break; - case 180: flip = 1; break; - case 90: flip = 7; break; - case 0: flip = 2; - } - cam_mul[0] = getreal(11); - cam_mul[2] = getreal(11); - maximum = ~(-1 << get4()); - fseek (ifp, 668, SEEK_CUR); - shutter = get4()/1000000000.0; - fseek (ifp, off_image, SEEK_SET); - if (shot_select < is_raw) - fseek (ifp, shot_select*8, SEEK_CUR); - data_offset = (INT64) get4() + 8; - data_offset += (INT64) get4() << 32; -} - -void CLASS parse_redcine() -{ - unsigned i, len, rdvo; - - order = 0x4d4d; - is_raw = 0; - fseek (ifp, 52, SEEK_SET); - width = get4(); - height = get4(); - fseek (ifp, 0, SEEK_END); - fseek (ifp, -(i = ftello(ifp) & 511), SEEK_CUR); - if (get4() != i || get4() != 0x52454f42) { - fprintf (stderr,_("%s: Tail is missing, parsing from head...\n"), ifname); - fseek (ifp, 0, SEEK_SET); - while ((len = get4()) != EOF) { - if (get4() == 0x52454456) - if (is_raw++ == shot_select) - data_offset = ftello(ifp) - 8; - fseek (ifp, len-8, SEEK_CUR); - } - } else { - rdvo = get4(); - fseek (ifp, 12, SEEK_CUR); - is_raw = get4(); - fseeko (ifp, rdvo+8 + shot_select*4, SEEK_SET); - data_offset = get4(); - } -} - -char * CLASS foveon_gets (int offset, char *str, int len) -{ - int i; - fseek (ifp, offset, SEEK_SET); - for (i=0; i < len-1; i++) - if ((str[i] = get2()) == 0) break; - str[i] = 0; - return str; -} - -void CLASS parse_foveon() -{ - int entries, img=0, off, len, tag, save, i, wide, high, pent, poff[256][2]; - char name[64], value[64]; - - order = 0x4949; /* Little-endian */ - fseek (ifp, 36, SEEK_SET); - flip = get4(); - fseek (ifp, -4, SEEK_END); - fseek (ifp, get4(), SEEK_SET); - if (get4() != 0x64434553) return; /* SECd */ - entries = (get4(),get4()); - while (entries--) { - off = get4(); - len = get4(); - tag = get4(); - save = ftell(ifp); - fseek (ifp, off, SEEK_SET); - if (get4() != (0x20434553 | (tag << 24))) return; - switch (tag) { - case 0x47414d49: /* IMAG */ - case 0x32414d49: /* IMA2 */ - fseek (ifp, 8, SEEK_CUR); - pent = get4(); - wide = get4(); - high = get4(); - if (wide > raw_width && high > raw_height) { - switch (pent) { - case 5: load_flags = 1; - case 6: load_raw = &CLASS foveon_sd_load_raw; break; - case 30: load_raw = &CLASS foveon_dp_load_raw; break; - default: load_raw = 0; - } - raw_width = wide; - raw_height = high; - data_offset = off+28; - } - fseek (ifp, off+28, SEEK_SET); - if (fgetc(ifp) == 0xff && fgetc(ifp) == 0xd8 - && thumb_length < len-28) { - thumb_offset = off+28; - thumb_length = len-28; - write_thumb = &CLASS jpeg_thumb; - } - if (++img == 2 && !thumb_length) { - thumb_offset = off+24; - thumb_width = wide; - thumb_height = high; - write_thumb = &CLASS foveon_thumb; - } - break; - case 0x464d4143: /* CAMF */ - meta_offset = off+8; - meta_length = len-28; - break; - case 0x504f5250: /* PROP */ - pent = (get4(),get4()); - fseek (ifp, 12, SEEK_CUR); - off += pent*8 + 24; - if ((unsigned) pent > 256) pent=256; - for (i=0; i < pent*2; i++) - poff[0][i] = off + get4()*2; - for (i=0; i < pent; i++) { - foveon_gets (poff[i][0], name, 64); - foveon_gets (poff[i][1], value, 64); - if (!strcmp (name, "ISO")) - iso_speed = atoi(value); - if (!strcmp (name, "CAMMANUF")) - strcpy (make, value); - if (!strcmp (name, "CAMMODEL")) - strcpy (model, value); - if (!strcmp (name, "WB_DESC")) - strcpy (model2, value); - if (!strcmp (name, "TIME")) - timestamp = atoi(value); - if (!strcmp (name, "EXPTIME")) - shutter = atoi(value) / 1000000.0; - if (!strcmp (name, "APERTURE")) - aperture = atof(value); - if (!strcmp (name, "FLENGTH")) - focal_len = atof(value); - } -#ifdef LOCALTIME - timestamp = mktime (gmtime (×tamp)); -#endif - } - fseek (ifp, save, SEEK_SET); - } - is_foveon = 1; -} - -/* - All matrices are from Adobe DNG Converter unless otherwise noted. - */ -void CLASS adobe_coeff (const char *make, const char *model) -{ - static const struct { - const char *prefix; - short black, maximum, trans[12]; - } table[] = { - { "AGFAPHOTO DC-833m", 0, 0, /* DJC */ - { 11438,-3762,-1115,-2409,9914,2497,-1227,2295,5300 } }, - { "Apple QuickTake", 0, 0, /* DJC */ - { 21392,-5653,-3353,2406,8010,-415,7166,1427,2078 } }, - { "Canon EOS D2000", 0, 0, - { 24542,-10860,-3401,-1490,11370,-297,2858,-605,3225 } }, - { "Canon EOS D6000", 0, 0, - { 20482,-7172,-3125,-1033,10410,-285,2542,226,3136 } }, - { "Canon EOS D30", 0, 0, - { 9805,-2689,-1312,-5803,13064,3068,-2438,3075,8775 } }, - { "Canon EOS D60", 0, 0xfa0, - { 6188,-1341,-890,-7168,14489,2937,-2640,3228,8483 } }, - { "Canon EOS 5D Mark III", 0, 0x3c80, - { 6722,-635,-963,-4287,12460,2028,-908,2162,5668 } }, - { "Canon EOS 5D Mark II", 0, 0x3cf0, - { 4716,603,-830,-7798,15474,2480,-1496,1937,6651 } }, - { "Canon EOS 5D", 0, 0xe6c, - { 6347,-479,-972,-8297,15954,2480,-1968,2131,7649 } }, - { "Canon EOS 7D", 0, 0x3510, - { 6844,-996,-856,-3876,11761,2396,-593,1772,6198 } }, - { "Canon EOS 10D", 0, 0xfa0, - { 8197,-2000,-1118,-6714,14335,2592,-2536,3178,8266 } }, - { "Canon EOS 20Da", 0, 0, - { 14155,-5065,-1382,-6550,14633,2039,-1623,1824,6561 } }, - { "Canon EOS 20D", 0, 0xfff, - { 6599,-537,-891,-8071,15783,2424,-1983,2234,7462 } }, - { "Canon EOS 30D", 0, 0, - { 6257,-303,-1000,-7880,15621,2396,-1714,1904,7046 } }, - { "Canon EOS 40D", 0, 0x3f60, - { 6071,-747,-856,-7653,15365,2441,-2025,2553,7315 } }, - { "Canon EOS 50D", 0, 0x3d93, - { 4920,616,-593,-6493,13964,2784,-1774,3178,7005 } }, - { "Canon EOS 60D", 0, 0x2ff7, - { 6719,-994,-925,-4408,12426,2211,-887,2129,6051 } }, - { "Canon EOS 300D", 0, 0xfa0, - { 8197,-2000,-1118,-6714,14335,2592,-2536,3178,8266 } }, - { "Canon EOS 350D", 0, 0xfff, - { 6018,-617,-965,-8645,15881,2975,-1530,1719,7642 } }, - { "Canon EOS 400D", 0, 0xe8e, - { 7054,-1501,-990,-8156,15544,2812,-1278,1414,7796 } }, - { "Canon EOS 450D", 0, 0x390d, - { 5784,-262,-821,-7539,15064,2672,-1982,2681,7427 } }, - { "Canon EOS 500D", 0, 0x3479, - { 4763,712,-646,-6821,14399,2640,-1921,3276,6561 } }, - { "Canon EOS 550D", 0, 0x3dd7, - { 6941,-1164,-857,-3825,11597,2534,-416,1540,6039 } }, - { "Canon EOS 600D", 0, 0x3510, - { 6461,-907,-882,-4300,12184,2378,-819,1944,5931 } }, - { "Canon EOS 1000D", 0, 0xe43, - { 6771,-1139,-977,-7818,15123,2928,-1244,1437,7533 } }, - { "Canon EOS 1100D", 0, 0x3510, - { 6444,-904,-893,-4563,12308,2535,-903,2016,6728 } }, - { "Canon EOS-1Ds Mark III", 0, 0x3bb0, - { 5859,-211,-930,-8255,16017,2353,-1732,1887,7448 } }, - { "Canon EOS-1Ds Mark II", 0, 0xe80, - { 6517,-602,-867,-8180,15926,2378,-1618,1771,7633 } }, - { "Canon EOS-1D Mark IV", 0, 0x3bb0, - { 6014,-220,-795,-4109,12014,2361,-561,1824,5787 } }, - { "Canon EOS-1D Mark III", 0, 0x3bb0, - { 6291,-540,-976,-8350,16145,2311,-1714,1858,7326 } }, - { "Canon EOS-1D Mark II N", 0, 0xe80, - { 6240,-466,-822,-8180,15825,2500,-1801,1938,8042 } }, - { "Canon EOS-1D Mark II", 0, 0xe80, - { 6264,-582,-724,-8312,15948,2504,-1744,1919,8664 } }, - { "Canon EOS-1DS", 0, 0xe20, - { 4374,3631,-1743,-7520,15212,2472,-2892,3632,8161 } }, - { "Canon EOS-1D X", 0, 0, - { 6847,-614,-1014,-4669,12737,2139,-1197,2488,6846 } }, - { "Canon EOS-1D", 0, 0xe20, - { 6806,-179,-1020,-8097,16415,1687,-3267,4236,7690 } }, - { "Canon EOS", 0, 0, - { 8197,-2000,-1118,-6714,14335,2592,-2536,3178,8266 } }, - { "Canon PowerShot A530", 0, 0, - { 0 } }, /* don't want the A5 matrix */ - { "Canon PowerShot A50", 0, 0, - { -5300,9846,1776,3436,684,3939,-5540,9879,6200,-1404,11175,217 } }, - { "Canon PowerShot A5", 0, 0, - { -4801,9475,1952,2926,1611,4094,-5259,10164,5947,-1554,10883,547 } }, - { "Canon PowerShot G10", 0, 0, - { 11093,-3906,-1028,-5047,12492,2879,-1003,1750,5561 } }, - { "Canon PowerShot G11", 0, 0, - { 12177,-4817,-1069,-1612,9864,2049,-98,850,4471 } }, - { "Canon PowerShot G12", 0, 0, - { 13244,-5501,-1248,-1508,9858,1935,-270,1083,4366 } }, - { "Canon PowerShot G1 X", 0, 0, - { 7378,-1255,-1043,-4088,12251,2048,-876,1946,5805 } }, - { "Canon PowerShot G1", 0, 0, - { -4778,9467,2172,4743,-1141,4344,-5146,9908,6077,-1566,11051,557 } }, - { "Canon PowerShot G2", 0, 0, - { 9087,-2693,-1049,-6715,14382,2537,-2291,2819,7790 } }, - { "Canon PowerShot G3", 0, 0, - { 9212,-2781,-1073,-6573,14189,2605,-2300,2844,7664 } }, - { "Canon PowerShot G5", 0, 0, - { 9757,-2872,-933,-5972,13861,2301,-1622,2328,7212 } }, - { "Canon PowerShot G6", 0, 0, - { 9877,-3775,-871,-7613,14807,3072,-1448,1305,7485 } }, - { "Canon PowerShot G9", 0, 0, - { 7368,-2141,-598,-5621,13254,2625,-1418,1696,5743 } }, - { "Canon PowerShot Pro1", 0, 0, - { 10062,-3522,-999,-7643,15117,2730,-765,817,7323 } }, - { "Canon PowerShot Pro70", 34, 0, - { -4155,9818,1529,3939,-25,4522,-5521,9870,6610,-2238,10873,1342 } }, - { "Canon PowerShot Pro90", 0, 0, - { -4963,9896,2235,4642,-987,4294,-5162,10011,5859,-1770,11230,577 } }, - { "Canon PowerShot S30", 0, 0, - { 10566,-3652,-1129,-6552,14662,2006,-2197,2581,7670 } }, - { "Canon PowerShot S40", 0, 0, - { 8510,-2487,-940,-6869,14231,2900,-2318,2829,9013 } }, - { "Canon PowerShot S45", 0, 0, - { 8163,-2333,-955,-6682,14174,2751,-2077,2597,8041 } }, - { "Canon PowerShot S50", 0, 0, - { 8882,-2571,-863,-6348,14234,2288,-1516,2172,6569 } }, - { "Canon PowerShot S60", 0, 0, - { 8795,-2482,-797,-7804,15403,2573,-1422,1996,7082 } }, - { "Canon PowerShot S70", 0, 0, - { 9976,-3810,-832,-7115,14463,2906,-901,989,7889 } }, - { "Canon PowerShot S90", 0, 0, - { 12374,-5016,-1049,-1677,9902,2078,-83,852,4683 } }, - { "Canon PowerShot S95", 0, 0, - { 13440,-5896,-1279,-1236,9598,1931,-180,1001,4651 } }, - { "Canon PowerShot S100", 0, 0, - { 7968,-2565,-636,-2873,10697,2513,180,667,4211 } }, - { "Canon PowerShot A470", 0, 0, /* DJC */ - { 12513,-4407,-1242,-2680,10276,2405,-878,2215,4734 } }, - { "Canon PowerShot A610", 0, 0, /* DJC */ - { 15591,-6402,-1592,-5365,13198,2168,-1300,1824,5075 } }, - { "Canon PowerShot A620", 0, 0, /* DJC */ - { 15265,-6193,-1558,-4125,12116,2010,-888,1639,5220 } }, - { "Canon PowerShot A630", 0, 0, /* DJC */ - { 14201,-5308,-1757,-6087,14472,1617,-2191,3105,5348 } }, - { "Canon PowerShot A640", 0, 0, /* DJC */ - { 13124,-5329,-1390,-3602,11658,1944,-1612,2863,4885 } }, - { "Canon PowerShot A650", 0, 0, /* DJC */ - { 9427,-3036,-959,-2581,10671,1911,-1039,1982,4430 } }, - { "Canon PowerShot A720", 0, 0, /* DJC */ - { 14573,-5482,-1546,-1266,9799,1468,-1040,1912,3810 } }, - { "Canon PowerShot S3 IS", 0, 0, /* DJC */ - { 14062,-5199,-1446,-4712,12470,2243,-1286,2028,4836 } }, - { "Canon PowerShot SX1 IS", 0, 0, - { 6578,-259,-502,-5974,13030,3309,-308,1058,4970 } }, - { "Canon PowerShot SX110 IS", 0, 0, /* DJC */ - { 14134,-5576,-1527,-1991,10719,1273,-1158,1929,3581 } }, - { "Canon PowerShot SX220", 0, 0, /* DJC */ - { 13898,-5076,-1447,-1405,10109,1297,-244,1860,3687 } }, - { "CASIO EX-S20", 0, 0, /* DJC */ - { 11634,-3924,-1128,-4968,12954,2015,-1588,2648,7206 } }, - { "CASIO EX-Z750", 0, 0, /* DJC */ - { 10819,-3873,-1099,-4903,13730,1175,-1755,3751,4632 } }, - { "CASIO EX-Z10", 128, 0xfff, /* DJC */ - { 9790,-3338,-603,-2321,10222,2099,-344,1273,4799 } }, - { "CINE 650", 0, 0, - { 3390,480,-500,-800,3610,340,-550,2336,1192 } }, - { "CINE 660", 0, 0, - { 3390,480,-500,-800,3610,340,-550,2336,1192 } }, - { "CINE", 0, 0, - { 20183,-4295,-423,-3940,15330,3985,-280,4870,9800 } }, - { "Contax N Digital", 0, 0xf1e, - { 7777,1285,-1053,-9280,16543,2916,-3677,5679,7060 } }, - { "EPSON R-D1", 0, 0, - { 6827,-1878,-732,-8429,16012,2564,-704,592,7145 } }, - { "FUJIFILM E550", 0, 0, - { 11044,-3888,-1120,-7248,15168,2208,-1531,2277,8069 } }, - { "FUJIFILM E900", 0, 0, - { 9183,-2526,-1078,-7461,15071,2574,-2022,2440,8639 } }, - { "FUJIFILM F5", 0, 0, - { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, - { "FUJIFILM F6", 0, 0, - { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, - { "FUJIFILM F77", 0, 0, - { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, - { "FUJIFILM F7", 0, 0, - { 10004,-3219,-1201,-7036,15047,2107,-1863,2565,7736 } }, - { "FUJIFILM F8", 0, 0, - { 11044,-3888,-1120,-7248,15168,2208,-1531,2277,8069 } }, - { "FUJIFILM S100FS", 514, 0, - { 11521,-4355,-1065,-6524,13767,3058,-1466,1984,6045 } }, - { "FUJIFILM S200EXR", 512, 0x3fff, - { 11401,-4498,-1312,-5088,12751,2613,-838,1568,5941 } }, - { "FUJIFILM S20Pro", 0, 0, - { 10004,-3219,-1201,-7036,15047,2107,-1863,2565,7736 } }, - { "FUJIFILM S2Pro", 128, 0, - { 12492,-4690,-1402,-7033,15423,1647,-1507,2111,7697 } }, - { "FUJIFILM S3Pro", 0, 0, - { 11807,-4612,-1294,-8927,16968,1988,-2120,2741,8006 } }, - { "FUJIFILM S5Pro", 0, 0, - { 12300,-5110,-1304,-9117,17143,1998,-1947,2448,8100 } }, - { "FUJIFILM S5000", 0, 0, - { 8754,-2732,-1019,-7204,15069,2276,-1702,2334,6982 } }, - { "FUJIFILM S5100", 0, 0, - { 11940,-4431,-1255,-6766,14428,2542,-993,1165,7421 } }, - { "FUJIFILM S5500", 0, 0, - { 11940,-4431,-1255,-6766,14428,2542,-993,1165,7421 } }, - { "FUJIFILM S5200", 0, 0, - { 9636,-2804,-988,-7442,15040,2589,-1803,2311,8621 } }, - { "FUJIFILM S5600", 0, 0, - { 9636,-2804,-988,-7442,15040,2589,-1803,2311,8621 } }, - { "FUJIFILM S6", 0, 0, - { 12628,-4887,-1401,-6861,14996,1962,-2198,2782,7091 } }, - { "FUJIFILM S7000", 0, 0, - { 10190,-3506,-1312,-7153,15051,2238,-2003,2399,7505 } }, - { "FUJIFILM S9000", 0, 0, - { 10491,-3423,-1145,-7385,15027,2538,-1809,2275,8692 } }, - { "FUJIFILM S9500", 0, 0, - { 10491,-3423,-1145,-7385,15027,2538,-1809,2275,8692 } }, - { "FUJIFILM S9100", 0, 0, - { 12343,-4515,-1285,-7165,14899,2435,-1895,2496,8800 } }, - { "FUJIFILM S9600", 0, 0, - { 12343,-4515,-1285,-7165,14899,2435,-1895,2496,8800 } }, - { "FUJIFILM IS-1", 0, 0, - { 21461,-10807,-1441,-2332,10599,1999,289,875,7703 } }, - { "FUJIFILM IS Pro", 0, 0, - { 12300,-5110,-1304,-9117,17143,1998,-1947,2448,8100 } }, - { "FUJIFILM HS10 HS11", 0, 0xf68, - { 12440,-3954,-1183,-1123,9674,1708,-83,1614,4086 } }, - { "FUJIFILM HS20EXR", 0, 0, - { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, - { "FUJIFILM HS3", 0, 0, - { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, - { "FUJIFILM X100", 0, 0, - { 12161,-4457,-1069,-5034,12874,2400,-795,1724,6904 } }, - { "FUJIFILM X10", 0, 0, - { 13509,-6199,-1254,-4430,12733,1865,-331,1441,5022 } }, - { "FUJIFILM X-Pro1", 0, 0, - { 10413,-3996,-993,-3721,11640,2361,-733,1540,6011 } }, - { "FUJIFILM X-S1", 0, 0, - { 13509,-6199,-1254,-4430,12733,1865,-331,1441,5022 } }, - { "Imacon Ixpress", 0, 0, /* DJC */ - { 7025,-1415,-704,-5188,13765,1424,-1248,2742,6038 } }, - { "KODAK NC2000", 0, 0, - { 13891,-6055,-803,-465,9919,642,2121,82,1291 } }, - { "Kodak DCS315C", 8, 0, - { 17523,-4827,-2510,756,8546,-137,6113,1649,2250 } }, - { "Kodak DCS330C", 8, 0, - { 20620,-7572,-2801,-103,10073,-396,3551,-233,2220 } }, - { "KODAK DCS420", 0, 0, - { 10868,-1852,-644,-1537,11083,484,2343,628,2216 } }, - { "KODAK DCS460", 0, 0, - { 10592,-2206,-967,-1944,11685,230,2206,670,1273 } }, - { "KODAK EOSDCS1", 0, 0, - { 10592,-2206,-967,-1944,11685,230,2206,670,1273 } }, - { "KODAK EOSDCS3B", 0, 0, - { 9898,-2700,-940,-2478,12219,206,1985,634,1031 } }, - { "Kodak DCS520C", 180, 0, - { 24542,-10860,-3401,-1490,11370,-297,2858,-605,3225 } }, - { "Kodak DCS560C", 188, 0, - { 20482,-7172,-3125,-1033,10410,-285,2542,226,3136 } }, - { "Kodak DCS620C", 180, 0, - { 23617,-10175,-3149,-2054,11749,-272,2586,-489,3453 } }, - { "Kodak DCS620X", 185, 0, - { 13095,-6231,154,12221,-21,-2137,895,4602,2258 } }, - { "Kodak DCS660C", 214, 0, - { 18244,-6351,-2739,-791,11193,-521,3711,-129,2802 } }, - { "Kodak DCS720X", 0, 0, - { 11775,-5884,950,9556,1846,-1286,-1019,6221,2728 } }, - { "Kodak DCS760C", 0, 0, - { 16623,-6309,-1411,-4344,13923,323,2285,274,2926 } }, - { "Kodak DCS Pro SLR", 0, 0, - { 5494,2393,-232,-6427,13850,2846,-1876,3997,5445 } }, - { "Kodak DCS Pro 14nx", 0, 0, - { 5494,2393,-232,-6427,13850,2846,-1876,3997,5445 } }, - { "Kodak DCS Pro 14", 0, 0, - { 7791,3128,-776,-8588,16458,2039,-2455,4006,6198 } }, - { "Kodak ProBack645", 0, 0, - { 16414,-6060,-1470,-3555,13037,473,2545,122,4948 } }, - { "Kodak ProBack", 0, 0, - { 21179,-8316,-2918,-915,11019,-165,3477,-180,4210 } }, - { "KODAK P712", 0, 0, - { 9658,-3314,-823,-5163,12695,2768,-1342,1843,6044 } }, - { "KODAK P850", 0, 0xf7c, - { 10511,-3836,-1102,-6946,14587,2558,-1481,1792,6246 } }, - { "KODAK P880", 0, 0xfff, - { 12805,-4662,-1376,-7480,15267,2360,-1626,2194,7904 } }, - { "KODAK EasyShare Z980", 0, 0, - { 11313,-3559,-1101,-3893,11891,2257,-1214,2398,4908 } }, - { "KODAK EasyShare Z981", 0, 0, - { 12729,-4717,-1188,-1367,9187,2582,274,860,4411 } }, - { "KODAK EasyShare Z990", 0, 0xfed, - { 11749,-4048,-1309,-1867,10572,1489,-138,1449,4522 } }, - { "KODAK EASYSHARE Z1015", 0, 0xef1, - { 11265,-4286,-992,-4694,12343,2647,-1090,1523,5447 } }, - { "Leaf CMost", 0, 0, - { 3952,2189,449,-6701,14585,2275,-4536,7349,6536 } }, - { "Leaf Valeo 6", 0, 0, - { 3952,2189,449,-6701,14585,2275,-4536,7349,6536 } }, - { "Leaf Aptus 54S", 0, 0, - { 8236,1746,-1314,-8251,15953,2428,-3673,5786,5771 } }, - { "Leaf Aptus 65", 0, 0, - { 7914,1414,-1190,-8777,16582,2280,-2811,4605,5562 } }, - { "Leaf Aptus 75", 0, 0, - { 7914,1414,-1190,-8777,16582,2280,-2811,4605,5562 } }, - { "Leaf", 0, 0, - { 8236,1746,-1314,-8251,15953,2428,-3673,5786,5771 } }, - { "Mamiya ZD", 0, 0, - { 7645,2579,-1363,-8689,16717,2015,-3712,5941,5961 } }, - { "Micron 2010", 110, 0, /* DJC */ - { 16695,-3761,-2151,155,9682,163,3433,951,4904 } }, - { "Minolta DiMAGE 5", 0, 0xf7d, - { 8983,-2942,-963,-6556,14476,2237,-2426,2887,8014 } }, - { "Minolta DiMAGE 7Hi", 0, 0xf7d, - { 11368,-3894,-1242,-6521,14358,2339,-2475,3056,7285 } }, - { "Minolta DiMAGE 7", 0, 0xf7d, - { 9144,-2777,-998,-6676,14556,2281,-2470,3019,7744 } }, - { "Minolta DiMAGE A1", 0, 0xf8b, - { 9274,-2547,-1167,-8220,16323,1943,-2273,2720,8340 } }, - { "MINOLTA DiMAGE A200", 0, 0, - { 8560,-2487,-986,-8112,15535,2771,-1209,1324,7743 } }, - { "Minolta DiMAGE A2", 0, 0xf8f, - { 9097,-2726,-1053,-8073,15506,2762,-966,981,7763 } }, - { "Minolta DiMAGE Z2", 0, 0, /* DJC */ - { 11280,-3564,-1370,-4655,12374,2282,-1423,2168,5396 } }, - { "MINOLTA DYNAX 5", 0, 0xffb, - { 10284,-3283,-1086,-7957,15762,2316,-829,882,6644 } }, - { "MINOLTA DYNAX 7", 0, 0xffb, - { 10239,-3104,-1099,-8037,15727,2451,-927,925,6871 } }, - { "MOTOROLA PIXL", 0, 0, /* DJC */ - { 8898,-989,-1033,-3292,11619,1674,-661,3178,5216 } }, - { "NIKON D100", 0, 0, - { 5902,-933,-782,-8983,16719,2354,-1402,1455,6464 } }, - { "NIKON D1H", 0, 0, - { 7577,-2166,-926,-7454,15592,1934,-2377,2808,8606 } }, - { "NIKON D1X", 0, 0, - { 7702,-2245,-975,-9114,17242,1875,-2679,3055,8521 } }, - { "NIKON D1", 0, 0, /* multiplied by 2.218750, 1.0, 1.148438 */ - { 16772,-4726,-2141,-7611,15713,1972,-2846,3494,9521 } }, - { "NIKON D200", 0, 0xfbc, - { 8367,-2248,-763,-8758,16447,2422,-1527,1550,8053 } }, - { "NIKON D2H", 0, 0, - { 5710,-901,-615,-8594,16617,2024,-2975,4120,6830 } }, - { "NIKON D2X", 0, 0, - { 10231,-2769,-1255,-8301,15900,2552,-797,680,7148 } }, - { "NIKON D3000", 0, 0, - { 8736,-2458,-935,-9075,16894,2251,-1354,1242,8263 } }, - { "NIKON D3100", 0, 0, - { 7911,-2167,-813,-5327,13150,2408,-1288,2483,7968 } }, - { "NIKON D3200", 0, 0, - { 7013,-1408,-635,-5268,12902,2640,-1470,2801,7379 } }, - { "NIKON D300", 0, 0, - { 9030,-1992,-715,-8465,16302,2255,-2689,3217,8069 } }, - { "NIKON D3X", 0, 0, - { 7171,-1986,-648,-8085,15555,2718,-2170,2512,7457 } }, - { "NIKON D3S", 0, 0, - { 8828,-2406,-694,-4874,12603,2541,-660,1509,7587 } }, - { "NIKON D3", 0, 0, - { 8139,-2171,-663,-8747,16541,2295,-1925,2008,8093 } }, - { "NIKON D40X", 0, 0, - { 8819,-2543,-911,-9025,16928,2151,-1329,1213,8449 } }, - { "NIKON D40", 0, 0, - { 6992,-1668,-806,-8138,15748,2543,-874,850,7897 } }, - { "NIKON D4", 0, 0, - { 8598,-2848,-857,-5618,13606,2195,-1002,1773,7137 } }, - { "NIKON D5000", 0, 0xf00, - { 7309,-1403,-519,-8474,16008,2622,-2433,2826,8064 } }, - { "NIKON D5100", 0, 0x3de6, - { 8198,-2239,-724,-4871,12389,2798,-1043,2050,7181 } }, - { "NIKON D50", 0, 0, - { 7732,-2422,-789,-8238,15884,2498,-859,783,7330 } }, - { "NIKON D60", 0, 0, - { 8736,-2458,-935,-9075,16894,2251,-1354,1242,8263 } }, - { "NIKON D7000", 0, 0, - { 8198,-2239,-724,-4871,12389,2798,-1043,2050,7181 } }, - { "NIKON D700", 0, 0, - { 8139,-2171,-663,-8747,16541,2295,-1925,2008,8093 } }, - { "NIKON D70", 0, 0, - { 7732,-2422,-789,-8238,15884,2498,-859,783,7330 } }, - { "NIKON D800", 0, 0, - { 7866,-2108,-555,-4869,12483,2681,-1176,2069,7501 } }, - { "NIKON D80", 0, 0, - { 8629,-2410,-883,-9055,16940,2171,-1490,1363,8520 } }, - { "NIKON D90", 0, 0xf00, - { 7309,-1403,-519,-8474,16008,2622,-2434,2826,8064 } }, - { "NIKON E950", 0, 0x3dd, /* DJC */ - { -3746,10611,1665,9621,-1734,2114,-2389,7082,3064,3406,6116,-244 } }, - { "NIKON E995", 0, 0, /* copied from E5000 */ - { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, - { "NIKON E2100", 0, 0, /* copied from Z2, new white balance */ - { 13142,-4152,-1596,-4655,12374,2282,-1769,2696,6711} }, - { "NIKON E2500", 0, 0, - { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, - { "NIKON E3200", 0, 0, /* DJC */ - { 9846,-2085,-1019,-3278,11109,2170,-774,2134,5745 } }, - { "NIKON E4300", 0, 0, /* copied from Minolta DiMAGE Z2 */ - { 11280,-3564,-1370,-4655,12374,2282,-1423,2168,5396 } }, - { "NIKON E4500", 0, 0, - { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, - { "NIKON E5000", 0, 0, - { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, - { "NIKON E5400", 0, 0, - { 9349,-2987,-1001,-7919,15766,2266,-2098,2680,6839 } }, - { "NIKON E5700", 0, 0, - { -5368,11478,2368,5537,-113,3148,-4969,10021,5782,778,9028,211 } }, - { "NIKON E8400", 0, 0, - { 7842,-2320,-992,-8154,15718,2599,-1098,1342,7560 } }, - { "NIKON E8700", 0, 0, - { 8489,-2583,-1036,-8051,15583,2643,-1307,1407,7354 } }, - { "NIKON E8800", 0, 0, - { 7971,-2314,-913,-8451,15762,2894,-1442,1520,7610 } }, - { "NIKON COOLPIX P6000", 0, 0, - { 9698,-3367,-914,-4706,12584,2368,-837,968,5801 } }, - { "NIKON COOLPIX P7000", 0, 0, - { 11432,-3679,-1111,-3169,11239,2202,-791,1380,4455 } }, - { "NIKON COOLPIX P7100", 0, 0, - { 11053,-4269,-1024,-1976,10182,2088,-526,1263,4469 } }, - { "NIKON 1 ", 0, 0, - { 8994,-2667,-865,-4594,12324,2552,-699,1786,6260 } }, - { "OLYMPUS C5050", 0, 0, - { 10508,-3124,-1273,-6079,14294,1901,-1653,2306,6237 } }, - { "OLYMPUS C5060", 0, 0, - { 10445,-3362,-1307,-7662,15690,2058,-1135,1176,7602 } }, - { "OLYMPUS C7070", 0, 0, - { 10252,-3531,-1095,-7114,14850,2436,-1451,1723,6365 } }, - { "OLYMPUS C70", 0, 0, - { 10793,-3791,-1146,-7498,15177,2488,-1390,1577,7321 } }, - { "OLYMPUS C80", 0, 0, - { 8606,-2509,-1014,-8238,15714,2703,-942,979,7760 } }, - { "OLYMPUS E-10", 0, 0xffc, - { 12745,-4500,-1416,-6062,14542,1580,-1934,2256,6603 } }, - { "OLYMPUS E-1", 0, 0, - { 11846,-4767,-945,-7027,15878,1089,-2699,4122,8311 } }, - { "OLYMPUS E-20", 0, 0xffc, - { 13173,-4732,-1499,-5807,14036,1895,-2045,2452,7142 } }, - { "OLYMPUS E-300", 0, 0, - { 7828,-1761,-348,-5788,14071,1830,-2853,4518,6557 } }, - { "OLYMPUS E-330", 0, 0, - { 8961,-2473,-1084,-7979,15990,2067,-2319,3035,8249 } }, - { "OLYMPUS E-30", 0, 0xfbc, - { 8144,-1861,-1111,-7763,15894,1929,-1865,2542,7607 } }, - { "OLYMPUS E-3", 0, 0xf99, - { 9487,-2875,-1115,-7533,15606,2010,-1618,2100,7389 } }, - { "OLYMPUS E-400", 0, 0, - { 6169,-1483,-21,-7107,14761,2536,-2904,3580,8568 } }, - { "OLYMPUS E-410", 0, 0xf6a, - { 8856,-2582,-1026,-7761,15766,2082,-2009,2575,7469 } }, - { "OLYMPUS E-420", 0, 0xfd7, - { 8746,-2425,-1095,-7594,15612,2073,-1780,2309,7416 } }, - { "OLYMPUS E-450", 0, 0xfd2, - { 8745,-2425,-1095,-7594,15613,2073,-1780,2309,7416 } }, - { "OLYMPUS E-500", 0, 0, - { 8136,-1968,-299,-5481,13742,1871,-2556,4205,6630 } }, - { "OLYMPUS E-510", 0, 0xf6a, - { 8785,-2529,-1033,-7639,15624,2112,-1783,2300,7817 } }, - { "OLYMPUS E-520", 0, 0xfd2, - { 8344,-2322,-1020,-7596,15635,2048,-1748,2269,7287 } }, - { "OLYMPUS E-5", 0, 0, - { 11200,-3783,-1325,-4576,12593,2206,-695,1742,7504 } }, - { "OLYMPUS E-600", 0, 0xfaf, - { 8453,-2198,-1092,-7609,15681,2008,-1725,2337,7824 } }, - { "OLYMPUS E-620", 0, 0xfaf, - { 8453,-2198,-1092,-7609,15681,2008,-1725,2337,7824 } }, - { "OLYMPUS E-P1", 0, 0xffd, - { 8343,-2050,-1021,-7715,15705,2103,-1831,2380,8235 } }, - { "OLYMPUS E-P2", 0, 0xffd, - { 8343,-2050,-1021,-7715,15705,2103,-1831,2380,8235 } }, - { "OLYMPUS E-P3", 0, 0, - { 7575,-2159,-571,-3722,11341,2725,-1434,2819,6271 } }, - { "OLYMPUS E-PL1s", 0, 0, - { 11409,-3872,-1393,-4572,12757,2003,-709,1810,7415 } }, - { "OLYMPUS E-PL1", 0, 0, - { 11408,-4289,-1215,-4286,12385,2118,-387,1467,7787 } }, - { "OLYMPUS E-PL2", 0, 0, - { 15030,-5552,-1806,-3987,12387,1767,-592,1670,7023 } }, - { "OLYMPUS E-PL3", 0, 0, - { 7575,-2159,-571,-3722,11341,2725,-1434,2819,6271 } }, - { "OLYMPUS E-PM1", 0, 0, - { 7575,-2159,-571,-3722,11341,2725,-1434,2819,6271 } }, - { "OLYMPUS E-M5", 0, 0, - { 8380,-2630,-639,-2887,10725,2496,-627,1427,5438 } }, - { "OLYMPUS SP350", 0, 0, - { 12078,-4836,-1069,-6671,14306,2578,-786,939,7418 } }, - { "OLYMPUS SP3", 0, 0, - { 11766,-4445,-1067,-6901,14421,2707,-1029,1217,7572 } }, - { "OLYMPUS SP500UZ", 0, 0xfff, - { 9493,-3415,-666,-5211,12334,3260,-1548,2262,6482 } }, - { "OLYMPUS SP510UZ", 0, 0xffe, - { 10593,-3607,-1010,-5881,13127,3084,-1200,1805,6721 } }, - { "OLYMPUS SP550UZ", 0, 0xffe, - { 11597,-4006,-1049,-5432,12799,2957,-1029,1750,6516 } }, - { "OLYMPUS SP560UZ", 0, 0xff9, - { 10915,-3677,-982,-5587,12986,2911,-1168,1968,6223 } }, - { "OLYMPUS SP570UZ", 0, 0, - { 11522,-4044,-1146,-4736,12172,2904,-988,1829,6039 } }, - { "OLYMPUS XZ-1", 0, 0, - { 10901,-4095,-1074,-1141,9208,2293,-62,1417,5158 } }, - { "PENTAX *ist DL2", 0, 0, - { 10504,-2438,-1189,-8603,16207,2531,-1022,863,12242 } }, - { "PENTAX *ist DL", 0, 0, - { 10829,-2838,-1115,-8339,15817,2696,-837,680,11939 } }, - { "PENTAX *ist DS2", 0, 0, - { 10504,-2438,-1189,-8603,16207,2531,-1022,863,12242 } }, - { "PENTAX *ist DS", 0, 0, - { 10371,-2333,-1206,-8688,16231,2602,-1230,1116,11282 } }, - { "PENTAX *ist D", 0, 0, - { 9651,-2059,-1189,-8881,16512,2487,-1460,1345,10687 } }, - { "PENTAX K10D", 0, 0, - { 9566,-2863,-803,-7170,15172,2112,-818,803,9705 } }, - { "PENTAX K1", 0, 0, - { 11095,-3157,-1324,-8377,15834,2720,-1108,947,11688 } }, - { "PENTAX K20D", 0, 0, - { 9427,-2714,-868,-7493,16092,1373,-2199,3264,7180 } }, - { "PENTAX K200D", 0, 0, - { 9186,-2678,-907,-8693,16517,2260,-1129,1094,8524 } }, - { "PENTAX K2000", 0, 0, - { 11057,-3604,-1155,-5152,13046,2329,-282,375,8104 } }, - { "PENTAX K-m", 0, 0, - { 11057,-3604,-1155,-5152,13046,2329,-282,375,8104 } }, - { "PENTAX K-x", 0, 0, - { 8843,-2837,-625,-5025,12644,2668,-411,1234,7410 } }, - { "PENTAX K-r", 0, 0, - { 9895,-3077,-850,-5304,13035,2521,-883,1768,6936 } }, - { "PENTAX K-5", 0, 0, - { 8713,-2833,-743,-4342,11900,2772,-722,1543,6247 } }, - { "PENTAX K-7", 0, 0, - { 9142,-2947,-678,-8648,16967,1663,-2224,2898,8615 } }, - { "PENTAX 645D", 0, 0x3e00, - { 10646,-3593,-1158,-3329,11699,1831,-667,2874,6287 } }, - { "Panasonic DMC-FZ8", 0, 0xf7f, - { 8986,-2755,-802,-6341,13575,3077,-1476,2144,6379 } }, - { "Panasonic DMC-FZ18", 0, 0, - { 9932,-3060,-935,-5809,13331,2753,-1267,2155,5575 } }, - { "Panasonic DMC-FZ28", 15, 0xf96, - { 10109,-3488,-993,-5412,12812,2916,-1305,2140,5543 } }, - { "Panasonic DMC-FZ30", 0, 0xf94, - { 10976,-4029,-1141,-7918,15491,2600,-1670,2071,8246 } }, - { "Panasonic DMC-FZ3", 143, 0, - { 9938,-2780,-890,-4604,12393,2480,-1117,2304,4620 } }, - { "Panasonic DMC-FZ4", 143, 0, - { 13639,-5535,-1371,-1698,9633,2430,316,1152,4108 } }, - { "Panasonic DMC-FZ50", 0, 0, - { 7906,-2709,-594,-6231,13351,3220,-1922,2631,6537 } }, - { "LEICA V-LUX1", 0, 0, - { 7906,-2709,-594,-6231,13351,3220,-1922,2631,6537 } }, - { "Panasonic DMC-L10", 15, 0xf96, - { 8025,-1942,-1050,-7920,15904,2100,-2456,3005,7039 } }, - { "Panasonic DMC-L1", 0, 0xf7f, - { 8054,-1885,-1025,-8349,16367,2040,-2805,3542,7629 } }, - { "LEICA DIGILUX 3", 0, 0xf7f, - { 8054,-1885,-1025,-8349,16367,2040,-2805,3542,7629 } }, - { "Panasonic DMC-LC1", 0, 0, - { 11340,-4069,-1275,-7555,15266,2448,-2960,3426,7685 } }, - { "LEICA DIGILUX 2", 0, 0, - { 11340,-4069,-1275,-7555,15266,2448,-2960,3426,7685 } }, - { "Panasonic DMC-LX1", 0, 0xf7f, - { 10704,-4187,-1230,-8314,15952,2501,-920,945,8927 } }, - { "LEICA D-LUX2", 0, 0xf7f, - { 10704,-4187,-1230,-8314,15952,2501,-920,945,8927 } }, - { "Panasonic DMC-LX2", 0, 0, - { 8048,-2810,-623,-6450,13519,3272,-1700,2146,7049 } }, - { "LEICA D-LUX3", 0, 0, - { 8048,-2810,-623,-6450,13519,3272,-1700,2146,7049 } }, - { "Panasonic DMC-LX3", 15, 0, - { 8128,-2668,-655,-6134,13307,3161,-1782,2568,6083 } }, - { "LEICA D-LUX 4", 15, 0, - { 8128,-2668,-655,-6134,13307,3161,-1782,2568,6083 } }, - { "Panasonic DMC-LX5", 143, 0, - { 10909,-4295,-948,-1333,9306,2399,22,1738,4582 } }, - { "LEICA D-LUX 5", 143, 0, - { 10909,-4295,-948,-1333,9306,2399,22,1738,4582 } }, - { "Panasonic DMC-FZ100", 143, 0xfff, - { 16197,-6146,-1761,-2393,10765,1869,366,2238,5248 } }, - { "LEICA V-LUX 2", 143, 0xfff, - { 16197,-6146,-1761,-2393,10765,1869,366,2238,5248 } }, - { "Panasonic DMC-FZ150", 143, 0xfff, - { 11904,-4541,-1189,-2355,10899,1662,-296,1586,4289 } }, - { "LEICA V-LUX 3", 143, 0xfff, - { 11904,-4541,-1189,-2355,10899,1662,-296,1586,4289 } }, - { "Panasonic DMC-FX150", 15, 0xfff, - { 9082,-2907,-925,-6119,13377,3058,-1797,2641,5609 } }, - { "Panasonic DMC-G10", 0, 0, - { 10113,-3400,-1114,-4765,12683,2317,-377,1437,6710 } }, - { "Panasonic DMC-G1", 15, 0xf94, - { 8199,-2065,-1056,-8124,16156,2033,-2458,3022,7220 } }, - { "Panasonic DMC-G2", 15, 0xf3c, - { 10113,-3400,-1114,-4765,12683,2317,-377,1437,6710 } }, - { "Panasonic DMC-G3", 143, 0xfff, - { 6763,-1919,-863,-3868,11515,2684,-1216,2387,5879 } }, - { "Panasonic DMC-GF1", 15, 0xf92, - { 7888,-1902,-1011,-8106,16085,2099,-2353,2866,7330 } }, - { "Panasonic DMC-GF2", 143, 0xfff, - { 7888,-1902,-1011,-8106,16085,2099,-2353,2866,7330 } }, - { "Panasonic DMC-GF3", 143, 0xfff, - { 9051,-2468,-1204,-5212,13276,2121,-1197,2510,6890 } }, - { "Panasonic DMC-GF5", 143, 0xfff, - { 8228,-2945,-660,-3938,11792,2430,-1094,2278,5793 } }, - { "Panasonic DMC-GH1", 15, 0xf92, - { 6299,-1466,-532,-6535,13852,2969,-2331,3112,5984 } }, - { "Panasonic DMC-GH2", 15, 0xf95, - { 7780,-2410,-806,-3913,11724,2484,-1018,2390,5298 } }, - { "Panasonic DMC-GX1", 143, 0, - { 6763,-1919,-863,-3868,11515,2684,-1216,2387,5879 } }, - { "Phase One H 20", 0, 0, /* DJC */ - { 1313,1855,-109,-6715,15908,808,-327,1840,6020 } }, - { "Phase One H 25", 0, 0, - { 2905,732,-237,-8134,16626,1476,-3038,4253,7517 } }, - { "Phase One P 2", 0, 0, - { 2905,732,-237,-8134,16626,1476,-3038,4253,7517 } }, - { "Phase One P 30", 0, 0, - { 4516,-245,-37,-7020,14976,2173,-3206,4671,7087 } }, - { "Phase One P 45", 0, 0, - { 5053,-24,-117,-5684,14076,1702,-2619,4492,5849 } }, - { "Phase One P40", 0, 0, - { 8035,435,-962,-6001,13872,2320,-1159,3065,5434 } }, - { "Phase One P65", 0, 0, - { 8035,435,-962,-6001,13872,2320,-1159,3065,5434 } }, - { "RED ONE", 704, 0xffff, /* DJC */ - { 21014,-7891,-2613,-3056,12201,856,-2203,5125,8042 } }, - { "SAMSUNG EX1", 0, 0x3e00, - { 8898,-2498,-994,-3144,11328,2066,-760,1381,4576 } }, - { "SAMSUNG NX2", 0, 0xfff, /* NX20, NX200, NX210 */ - { 6933,-2268,-753,-4921,13387,1647,-803,1641,6096 } }, - { "SAMSUNG NX", 0, 0, /* NX5, NX10, NX11, NX100 */ - { 10332,-3234,-1168,-6111,14639,1520,-1352,2647,8331 } }, - { "SAMSUNG WB2000", 0, 0xfff, - { 12093,-3557,-1155,-1000,9534,1733,-22,1787,4576 } }, - { "SAMSUNG GX-1", 0, 0, - { 10504,-2438,-1189,-8603,16207,2531,-1022,863,12242 } }, - { "SAMSUNG S85", 0, 0xffff, /* DJC */ - { 11885,-3968,-1473,-4214,12299,1916,-835,1655,5549 } }, - { "Sinar", 0, 0, /* DJC */ - { 16442,-2956,-2422,-2877,12128,750,-1136,6066,4559 } }, - { "SONY DSC-F828", 491, 0, - { 7924,-1910,-777,-8226,15459,2998,-1517,2199,6818,-7242,11401,3481 } }, - { "SONY DSC-R1", 512, 0, - { 8512,-2641,-694,-8042,15670,2526,-1821,2117,7414 } }, - { "SONY DSC-V3", 0, 0, - { 7511,-2571,-692,-7894,15088,3060,-948,1111,8128 } }, - { "SONY DSLR-A100", 0, 0xfeb, - { 9437,-2811,-774,-8405,16215,2290,-710,596,7181 } }, - { "SONY DSLR-A290", 0, 0, - { 6038,-1484,-579,-9145,16746,2512,-875,746,7218 } }, - { "SONY DSLR-A2", 0, 0, - { 9847,-3091,-928,-8485,16345,2225,-715,595,7103 } }, - { "SONY DSLR-A300", 0, 0, - { 9847,-3091,-928,-8485,16345,2225,-715,595,7103 } }, - { "SONY DSLR-A330", 0, 0, - { 9847,-3091,-929,-8485,16346,2225,-714,595,7103 } }, - { "SONY DSLR-A350", 0, 0xffc, - { 6038,-1484,-578,-9146,16746,2513,-875,746,7217 } }, - { "SONY DSLR-A380", 0, 0, - { 6038,-1484,-579,-9145,16746,2512,-875,746,7218 } }, - { "SONY DSLR-A390", 0, 0, - { 6038,-1484,-579,-9145,16746,2512,-875,746,7218 } }, - { "SONY DSLR-A450", 128, 0xfeb, - { 4950,-580,-103,-5228,12542,3029,-709,1435,7371 } }, - { "SONY DSLR-A580", 128, 0xfeb, - { 5932,-1492,-411,-4813,12285,2856,-741,1524,6739 } }, - { "SONY DSLR-A5", 128, 0xfeb, - { 4950,-580,-103,-5228,12542,3029,-709,1435,7371 } }, - { "SONY DSLR-A700", 126, 0, - { 5775,-805,-359,-8574,16295,2391,-1943,2341,7249 } }, - { "SONY DSLR-A850", 128, 0, - { 5413,-1162,-365,-5665,13098,2866,-608,1179,8440 } }, - { "SONY DSLR-A900", 128, 0, - { 5209,-1072,-397,-8845,16120,2919,-1618,1803,8654 } }, - { "SONY NEX-5N", 128, 0, - { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, - { "SONY NEX-3", 138, 0, /* DJC */ - { 6907,-1256,-645,-4940,12621,2320,-1710,2581,6230 } }, - { "SONY NEX-5", 116, 0, /* DJC */ - { 6807,-1350,-342,-4216,11649,2567,-1089,2001,6420 } }, - { "SONY NEX-3", 128, 0, /* Adobe */ - { 6549,-1550,-436,-4880,12435,2753,-854,1868,6976 } }, - { "SONY NEX-5", 128, 0, /* Adobe */ - { 6549,-1550,-436,-4880,12435,2753,-854,1868,6976 } }, - { "SONY NEX-7", 128, 0, - { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } }, - { "SONY NEX", 128, 0, /* NEX-C3, NEX-F3 */ - { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, - { "SONY SLT-A33", 128, 0, - { 6069,-1221,-366,-5221,12779,2734,-1024,2066,6834 } }, - { "SONY SLT-A35", 128, 0, - { 5986,-1618,-415,-4557,11820,3120,-681,1404,6971 } }, - { "SONY SLT-A37", 128, 0, - { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, - { "SONY SLT-A55", 128, 0, - { 5932,-1492,-411,-4813,12285,2856,-741,1524,6739 } }, - { "SONY SLT-A57", 128, 0, - { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, - { "SONY SLT-A65", 128, 0, - { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } }, - { "SONY SLT-A77", 128, 0, - { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } } - }; - double cam_xyz[4][3]; - char name[130]; - int i, j; - - sprintf (name, "%s %s", make, model); - for (i=0; i < sizeof table / sizeof *table; i++) - if (!strncmp (name, table[i].prefix, strlen(table[i].prefix))) { - if (table[i].black) black = (ushort) table[i].black; - if (table[i].maximum) maximum = (ushort) table[i].maximum; - if (table[i].trans[0]) { - for (j=0; j < 12; j++) - cam_xyz[0][j] = table[i].trans[j] / 10000.0; - cam_xyz_coeff (cam_xyz); - } - break; - } -} - -void CLASS simple_coeff (int index) -{ - static const float table[][12] = { - /* index 0 -- all Foveon cameras */ - { 1.4032,-0.2231,-0.1016,-0.5263,1.4816,0.017,-0.0112,0.0183,0.9113 }, - /* index 1 -- Kodak DC20 and DC25 */ - { 2.25,0.75,-1.75,-0.25,-0.25,0.75,0.75,-0.25,-0.25,-1.75,0.75,2.25 }, - /* index 2 -- Logitech Fotoman Pixtura */ - { 1.893,-0.418,-0.476,-0.495,1.773,-0.278,-1.017,-0.655,2.672 }, - /* index 3 -- Nikon E880, E900, and E990 */ - { -1.936280, 1.800443, -1.448486, 2.584324, - 1.405365, -0.524955, -0.289090, 0.408680, - -1.204965, 1.082304, 2.941367, -1.818705 } - }; - int i, c; - - for (raw_color = i=0; i < 3; i++) - FORCC rgb_cam[i][c] = table[index][i*colors+c]; -} - -short CLASS guess_byte_order (int words) -{ - uchar test[4][2]; - int t=2, msb; - double diff, sum[2] = {0,0}; - - fread (test[0], 2, 2, ifp); - for (words-=2; words--; ) { - fread (test[t], 2, 1, ifp); - for (msb=0; msb < 2; msb++) { - diff = (test[t^2][msb] << 8 | test[t^2][!msb]) - - (test[t ][msb] << 8 | test[t ][!msb]); - sum[msb] += diff*diff; - } - t = (t+1) & 3; - } - return sum[0] < sum[1] ? 0x4d4d : 0x4949; -} - -float CLASS find_green (int bps, int bite, int off0, int off1) -{ - UINT64 bitbuf=0; - int vbits, col, i, c; - ushort img[2][2064]; - double sum[]={0,0}; - - FORC(2) { - fseek (ifp, c ? off1:off0, SEEK_SET); - for (vbits=col=0; col < width; col++) { - for (vbits -= bps; vbits < 0; vbits += bite) { - bitbuf <<= bite; - for (i=0; i < bite; i+=8) - bitbuf |= (unsigned) (fgetc(ifp) << i); - } - img[c][col] = bitbuf << (64-bps-vbits) >> (64-bps); - } - } - FORC(width-1) { - sum[ c & 1] += ABS(img[0][c]-img[1][c+1]); - sum[~c & 1] += ABS(img[1][c]-img[0][c+1]); - } - return 100 * log(sum[0]/sum[1]); -} - -/* - Identify which camera created this file, and set global variables - accordingly. - */ -void CLASS identify() -{ - char head[32], *cp; - int hlen, flen, fsize, zero_fsize=1, i, c, is_canon; - struct jhead jh; - short pana[][6] = { - { 3130, 1743, 4, 0, -6, 0 }, - { 3130, 2055, 4, 0, -6, 0 }, - { 3130, 2319, 4, 0, -6, 0 }, - { 3170, 2103, 18, 0,-42, 20 }, - { 3170, 2367, 18, 13,-42,-21 }, - { 3177, 2367, 0, 0, -1, 0 }, - { 3304, 2458, 0, 0, -1, 0 }, - { 3330, 2463, 9, 0, -5, 0 }, - { 3330, 2479, 9, 0,-17, 4 }, - { 3370, 1899, 15, 0,-44, 20 }, - { 3370, 2235, 15, 0,-44, 20 }, - { 3370, 2511, 15, 10,-44,-21 }, - { 3690, 2751, 3, 0, -8, -3 }, - { 3710, 2751, 0, 0, -3, 0 }, - { 3724, 2450, 0, 0, 0, -2 }, - { 3770, 2487, 17, 0,-44, 19 }, - { 3770, 2799, 17, 15,-44,-19 }, - { 3880, 2170, 6, 0, -6, 0 }, - { 4060, 3018, 0, 0, 0, -2 }, - { 4290, 2391, 3, 0, -8, -1 }, - { 4330, 2439, 17, 15,-44,-19 }, - { 4508, 2962, 0, 0, -3, -4 }, - { 4508, 3330, 0, 0, -3, -6 } }; - static const struct { - int fsize; - char make[12], model[19], withjpeg; - } table[] = { - { 62464, "Kodak", "DC20" ,0 }, - { 124928, "Kodak", "DC20" ,0 }, - { 1652736, "Kodak", "DCS200" ,0 }, - { 4159302, "Kodak", "C330" ,0 }, - { 4162462, "Kodak", "C330" ,0 }, - { 460800, "Kodak", "C603v" ,0 }, - { 614400, "Kodak", "C603v" ,0 }, - { 6163328, "Kodak", "C603" ,0 }, - { 6166488, "Kodak", "C603" ,0 }, - { 9116448, "Kodak", "C603y" ,0 }, - { 311696, "ST Micro", "STV680 VGA" ,0 }, /* SPYz */ - { 787456, "Creative", "PC-CAM 600" ,0 }, - { 1138688, "Minolta", "RD175" ,0 }, - { 3840000, "Foculus", "531C" ,0 }, - { 307200, "Generic", "640x480" ,0 }, - { 786432, "AVT", "F-080C" ,0 }, - { 1447680, "AVT", "F-145C" ,0 }, - { 1920000, "AVT", "F-201C" ,0 }, - { 5067304, "AVT", "F-510C" ,0 }, - { 5067316, "AVT", "F-510C" ,0 }, - { 10134608, "AVT", "F-510C" ,0 }, - { 10134620, "AVT", "F-510C" ,0 }, - { 16157136, "AVT", "F-810C" ,0 }, - { 1409024, "Sony", "XCD-SX910CR" ,0 }, - { 2818048, "Sony", "XCD-SX910CR" ,0 }, - { 3884928, "Micron", "2010" ,0 }, - { 6624000, "Pixelink", "A782" ,0 }, - { 13248000, "Pixelink", "A782" ,0 }, - { 6291456, "RoverShot","3320AF" ,0 }, - { 6553440, "Canon", "PowerShot A460" ,0 }, - { 6653280, "Canon", "PowerShot A530" ,0 }, - { 6573120, "Canon", "PowerShot A610" ,0 }, - { 9219600, "Canon", "PowerShot A620" ,0 }, - { 9243240, "Canon", "PowerShot A470" ,0 }, - { 10341600, "Canon", "PowerShot A720 IS",0 }, - { 10383120, "Canon", "PowerShot A630" ,0 }, - { 12945240, "Canon", "PowerShot A640" ,0 }, - { 15636240, "Canon", "PowerShot A650" ,0 }, - { 5298000, "Canon", "PowerShot SD300" ,0 }, - { 7710960, "Canon", "PowerShot S3 IS" ,0 }, - { 15467760, "Canon", "PowerShot SX110 IS",0 }, - { 15534576, "Canon", "PowerShot SX120 IS",0 }, - { 18653760, "Canon", "PowerShot SX20 IS",0 }, - { 19131120, "Canon", "PowerShot SX220 HS",0 }, - { 21936096, "Canon", "PowerShot SX30 IS",0 }, - { 5939200, "OLYMPUS", "C770UZ" ,0 }, - { 1581060, "NIKON", "E900" ,1 }, /* or E900s,E910 */ - { 2465792, "NIKON", "E950" ,1 }, /* or E800,E700 */ - { 2940928, "NIKON", "E2100" ,1 }, /* or E2500 */ - { 4771840, "NIKON", "E990" ,1 }, /* or E995, Oly C3030Z */ - { 4775936, "NIKON", "E3700" ,1 }, /* or Optio 33WR */ - { 5869568, "NIKON", "E4300" ,1 }, /* or DiMAGE Z2 */ - { 5865472, "NIKON", "E4500" ,1 }, - { 7438336, "NIKON", "E5000" ,1 }, /* or E5700 */ - { 8998912, "NIKON", "COOLPIX S6" ,1 }, - { 1976352, "CASIO", "QV-2000UX" ,1 }, - { 3217760, "CASIO", "QV-3*00EX" ,1 }, - { 6218368, "CASIO", "QV-5700" ,1 }, - { 6054400, "CASIO", "QV-R41" ,1 }, - { 7530816, "CASIO", "QV-R51" ,1 }, - { 7684000, "CASIO", "QV-4000" ,1 }, - { 2937856, "CASIO", "EX-S20" ,1 }, - { 4948608, "CASIO", "EX-S100" ,1 }, - { 7542528, "CASIO", "EX-Z50" ,1 }, - { 7562048, "CASIO", "EX-Z500" ,1 }, - { 7753344, "CASIO", "EX-Z55" ,1 }, - { 7816704, "CASIO", "EX-Z60" ,1 }, - { 10843712, "CASIO", "EX-Z75" ,1 }, - { 10834368, "CASIO", "EX-Z750" ,1 }, - { 12310144, "CASIO", "EX-Z850" ,1 }, - { 12489984, "CASIO", "EX-Z8" ,1 }, - { 15499264, "CASIO", "EX-Z1050" ,1 }, - { 7426656, "CASIO", "EX-P505" ,1 }, - { 9313536, "CASIO", "EX-P600" ,1 }, - { 10979200, "CASIO", "EX-P700" ,1 }, - { 3178560, "PENTAX", "Optio S" ,1 }, - { 4841984, "PENTAX", "Optio S" ,1 }, - { 6114240, "PENTAX", "Optio S4" ,1 }, /* or S4i, CASIO EX-Z4 */ - { 10702848, "PENTAX", "Optio 750Z" ,1 }, - { 15980544, "AGFAPHOTO","DC-833m" ,1 }, - { 16098048, "SAMSUNG", "S85" ,1 }, - { 16215552, "SAMSUNG", "S85" ,1 }, - { 20487168, "SAMSUNG", "WB550" ,1 }, - { 24000000, "SAMSUNG", "WB550" ,1 }, - { 12582980, "Sinar", "" ,0 }, - { 33292868, "Sinar", "" ,0 }, - { 44390468, "Sinar", "" ,0 } }; - static const char *corp[] = - { "Canon", "NIKON", "EPSON", "KODAK", "Kodak", "OLYMPUS", "PENTAX", - "MINOLTA", "Minolta", "Konica", "CASIO", "Sinar", "Phase One", - "SAMSUNG", "Mamiya", "MOTOROLA", "LEICA" }; - - tiff_flip = flip = filters = -1; /* 0 is valid, so -1 is unknown */ - raw_height = raw_width = fuji_width = fuji_layout = cr2_slice[0] = 0; - maximum = height = width = top_margin = left_margin = 0; - cdesc[0] = desc[0] = artist[0] = make[0] = model[0] = model2[0] = 0; - iso_speed = shutter = aperture = focal_len = unique_id = 0; - tiff_nifds = 0; - memset (tiff_ifd, 0, sizeof tiff_ifd); - memset (gpsdata, 0, sizeof gpsdata); - memset (cblack, 0, sizeof cblack); - memset (white, 0, sizeof white); - memset (mask, 0, sizeof mask); - thumb_offset = thumb_length = thumb_width = thumb_height = 0; - load_raw = thumb_load_raw = 0; - write_thumb = &CLASS jpeg_thumb; - data_offset = meta_length = tiff_bps = tiff_compress = 0; - kodak_cbpp = zero_after_ff = dng_version = load_flags = 0; - timestamp = shot_order = tiff_samples = black = is_foveon = 0; - mix_green = profile_length = data_error = zero_is_bad = 0; - pixel_aspect = is_raw = raw_color = 1; - tile_width = tile_length = 0; - for (i=0; i < 4; i++) { - cam_mul[i] = i == 1; - pre_mul[i] = i < 3; - FORC3 cmatrix[c][i] = 0; - FORC3 rgb_cam[c][i] = c == i; - } - colors = 3; - for (i=0; i < 0x10000; i++) curve[i] = i; - - order = get2(); - hlen = get4(); - fseek (ifp, 0, SEEK_SET); - fread (head, 1, 32, ifp); - fseek (ifp, 0, SEEK_END); - flen = fsize = ftell(ifp); - if ((cp = (char *) memmem (head, 32, "MMMM", 4)) || - (cp = (char *) memmem (head, 32, "IIII", 4))) { - parse_phase_one (cp-head); - if (cp-head && parse_tiff(0)) apply_tiff(); - } else if (order == 0x4949 || order == 0x4d4d) { - if (!memcmp (head+6,"HEAPCCDR",8)) { - data_offset = hlen; - parse_ciff (hlen, flen - hlen); - } else if (parse_tiff(0)) apply_tiff(); - } else if (!memcmp (head,"\xff\xd8\xff\xe1",4) && - !memcmp (head+6,"Exif",4)) { - fseek (ifp, 4, SEEK_SET); - data_offset = 4 + get2(); - fseek (ifp, data_offset, SEEK_SET); - if (fgetc(ifp) != 0xff) - parse_tiff(12); - thumb_offset = 0; - } else if (!memcmp (head+25,"ARECOYK",7)) { - strcpy (make, "Contax"); - strcpy (model,"N Digital"); - fseek (ifp, 33, SEEK_SET); - get_timestamp(1); - fseek (ifp, 60, SEEK_SET); - FORC4 cam_mul[c ^ (c >> 1)] = get4(); - } else if (!strcmp (head, "PXN")) { - strcpy (make, "Logitech"); - strcpy (model,"Fotoman Pixtura"); - } else if (!strcmp (head, "qktk")) { - strcpy (make, "Apple"); - strcpy (model,"QuickTake 100"); - load_raw = &CLASS quicktake_100_load_raw; - } else if (!strcmp (head, "qktn")) { - strcpy (make, "Apple"); - strcpy (model,"QuickTake 150"); - load_raw = &CLASS kodak_radc_load_raw; - } else if (!memcmp (head,"FUJIFILM",8)) { - fseek (ifp, 84, SEEK_SET); - thumb_offset = get4(); - thumb_length = get4(); - fseek (ifp, 92, SEEK_SET); - parse_fuji (get4()); - if (thumb_offset > 120) { - fseek (ifp, 120, SEEK_SET); - is_raw += (i = get4()) && 1; - if (is_raw == 2 && shot_select) - parse_fuji (i); - } - load_raw = &CLASS unpacked_load_raw; - fseek (ifp, 100+28*(shot_select > 0), SEEK_SET); - parse_tiff (data_offset = get4()); - parse_tiff (thumb_offset+12); - apply_tiff(); - } else if (!memcmp (head,"RIFF",4)) { - fseek (ifp, 0, SEEK_SET); - parse_riff(); - } else if (!memcmp (head,"\0\001\0\001\0@",6)) { - fseek (ifp, 6, SEEK_SET); - fread (make, 1, 8, ifp); - fread (model, 1, 8, ifp); - fread (model2, 1, 16, ifp); - data_offset = get2(); - get2(); - raw_width = get2(); - raw_height = get2(); - load_raw = &CLASS nokia_load_raw; - filters = 0x61616161; - } else if (!memcmp (head,"NOKIARAW",8)) { - strcpy (make, "NOKIA"); - strcpy (model, "X2"); - order = 0x4949; - fseek (ifp, 300, SEEK_SET); - data_offset = get4(); - i = get4(); - width = get2(); - height = get2(); - data_offset += i - width * 5 / 4 * height; - load_raw = &CLASS nokia_load_raw; - filters = 0x61616161; - } else if (!memcmp (head,"ARRI",4)) { - order = 0x4949; - fseek (ifp, 20, SEEK_SET); - width = get4(); - height = get4(); - strcpy (make, "ARRI"); - fseek (ifp, 668, SEEK_SET); - fread (model, 1, 64, ifp); - data_offset = 4096; - load_raw = &CLASS packed_load_raw; - load_flags = 88; - filters = 0x61616161; - } else if (!memcmp (head+4,"RED1",4)) { - strcpy (make, "RED"); - strcpy (model,"ONE"); - parse_redcine(); - load_raw = &CLASS redcine_load_raw; - gamma_curve (1/2.4, 12.92, 1, 4095); - filters = 0x49494949; - } else if (!memcmp (head,"DSC-Image",9)) - parse_rollei(); - else if (!memcmp (head,"PWAD",4)) - parse_sinar_ia(); - else if (!memcmp (head,"\0MRM",4)) - parse_minolta(0); - else if (!memcmp (head,"FOVb",4)) - parse_foveon(); - else if (!memcmp (head,"CI",2)) - parse_cine(); - else - for (zero_fsize=i=0; i < sizeof table / sizeof *table; i++) - if (fsize == table[i].fsize) { - strcpy (make, table[i].make ); - strcpy (model, table[i].model); - if (table[i].withjpeg) - parse_external_jpeg(); - } - if (zero_fsize) fsize = 0; - if (make[0] == 0) parse_smal (0, flen); - if (make[0] == 0) parse_jpeg (is_raw = 0); - - for (i=0; i < sizeof corp / sizeof *corp; i++) - if (strstr (make, corp[i])) /* Simplify company names */ - strcpy (make, corp[i]); - if (!strncmp (make,"KODAK",5) && - ((cp = strstr(model," DIGITAL CAMERA")) || - (cp = strstr(model," Digital Camera")) || - (cp = strstr(model,"FILE VERSION")))) - *cp = 0; - cp = make + strlen(make); /* Remove trailing spaces */ - while (*--cp == ' ') *cp = 0; - cp = model + strlen(model); - while (*--cp == ' ') *cp = 0; - i = strlen(make); /* Remove make from model */ - if (!strncasecmp (model, make, i) && model[i++] == ' ') - memmove (model, model+i, 64-i); - if (!strncmp (model,"FinePix ",8)) - strcpy (model, model+8); - if (!strncmp (model,"Digital Camera ",15)) - strcpy (model, model+15); - desc[511] = artist[63] = make[63] = model[63] = model2[63] = 0; - if (!is_raw) goto notraw; - - if (!height) height = raw_height; - if (!width) width = raw_width; - if (height == 2624 && width == 3936) /* Pentax K10D and Samsung GX10 */ - { height = 2616; width = 3896; } - if (height == 3136 && width == 4864) /* Pentax K20D and Samsung GX20 */ - { height = 3124; width = 4688; filters = 0x16161616; } - if (width == 4352 && (!strcmp(model,"K-r") || !strcmp(model,"K-x"))) - { width = 4309; filters = 0x16161616; } - if (width >= 4960 && !strcmp(model,"K-5")) - { left_margin = 10; width = 4950; filters = 0x16161616; } - if (width == 4736 && !strcmp(model,"K-7")) - { height = 3122; width = 4684; filters = 0x16161616; top_margin = 2; } - if (width == 7424 && !strcmp(model,"645D")) - { height = 5502; width = 7328; filters = 0x61616161; top_margin = 29; - left_margin = 48; } - if (height == 3014 && width == 4096) /* Ricoh GX200 */ - width = 4014; - if (dng_version) { - if (filters == UINT_MAX) filters = 0; - if (filters) is_raw = tiff_samples; - else colors = tiff_samples; - if (tiff_compress == 1) - load_raw = &CLASS packed_dng_load_raw; - if (tiff_compress == 7) - load_raw = &CLASS lossless_dng_load_raw; - goto dng_skip; - } - if ((is_canon = !strcmp(make,"Canon"))) - load_raw = memcmp (head+6,"HEAPCCDR",8) ? - &CLASS lossless_jpeg_load_raw : &CLASS canon_load_raw; - if (!strcmp(make,"NIKON")) { - if (!load_raw) - load_raw = &CLASS packed_load_raw; - if (model[0] == 'E') - load_flags |= !data_offset << 2 | 2; - } - if (!strcmp(make,"CASIO")) { - load_raw = &CLASS packed_load_raw; - maximum = 0xf7f; - } - -/* Set parameters based on camera name (for non-DNG files). */ - - if (is_foveon) { - if (height*2 < width) pixel_aspect = 0.5; - if (height > width) pixel_aspect = 2; - filters = 0; - simple_coeff(0); - } else if (is_canon && tiff_bps == 15) { - switch (width) { - case 3344: width -= 66; - case 3872: width -= 6; - } - filters = 0; - load_raw = &CLASS canon_sraw_load_raw; - } else if (!strcmp(model,"PowerShot 600")) { - height = 613; - width = 854; - raw_width = 896; - pixel_aspect = 607/628.0; - colors = 4; - filters = 0xe1e4e1e4; - load_raw = &CLASS canon_600_load_raw; - } else if (!strcmp(model,"PowerShot A5") || - !strcmp(model,"PowerShot A5 Zoom")) { - height = 773; - width = 960; - raw_width = 992; - pixel_aspect = 256/235.0; - colors = 4; - filters = 0x1e4e1e4e; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A50")) { - height = 968; - width = 1290; - raw_width = 1320; - colors = 4; - filters = 0x1b4e4b1e; - goto canon_a5; - } else if (!strcmp(model,"PowerShot Pro70")) { - height = 1024; - width = 1552; - colors = 4; - filters = 0x1e4b4e1b; - goto canon_a5; - } else if (!strcmp(model,"PowerShot SD300")) { - height = 1752; - width = 2344; - raw_height = 1766; - raw_width = 2400; - top_margin = 12; - left_margin = 12; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A460")) { - height = 1960; - width = 2616; - raw_height = 1968; - raw_width = 2664; - top_margin = 4; - left_margin = 4; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A530")) { - height = 1984; - width = 2620; - raw_height = 1992; - raw_width = 2672; - top_margin = 6; - left_margin = 10; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A610")) { - if (canon_s2is()) strcpy (model+10, "S2 IS"); - height = 1960; - width = 2616; - raw_height = 1968; - raw_width = 2672; - top_margin = 8; - left_margin = 12; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A620")) { - height = 2328; - width = 3112; - raw_height = 2340; - raw_width = 3152; - top_margin = 12; - left_margin = 36; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A470")) { - height = 2328; - width = 3096; - raw_height = 2346; - raw_width = 3152; - top_margin = 6; - left_margin = 12; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A720 IS")) { - height = 2472; - width = 3298; - raw_height = 2480; - raw_width = 3336; - top_margin = 5; - left_margin = 6; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A630")) { - height = 2472; - width = 3288; - raw_height = 2484; - raw_width = 3344; - top_margin = 6; - left_margin = 12; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A640")) { - height = 2760; - width = 3672; - raw_height = 2772; - raw_width = 3736; - top_margin = 6; - left_margin = 12; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A650")) { - height = 3024; - width = 4032; - raw_height = 3048; - raw_width = 4104; - top_margin = 12; - left_margin = 48; - goto canon_a5; - } else if (!strcmp(model,"PowerShot S3 IS")) { - height = 2128; - width = 2840; - raw_height = 2136; - raw_width = 2888; - top_margin = 8; - left_margin = 44; -canon_a5: - tiff_bps = 10; - load_raw = &CLASS packed_load_raw; - load_flags = 40; - if (raw_width > 1600) zero_is_bad = 1; - } else if (!strcmp(model,"PowerShot SX110 IS")) { - height = 2760; - width = 3684; - raw_height = 2772; - raw_width = 3720; - top_margin = 12; - left_margin = 6; - load_raw = &CLASS packed_load_raw; - load_flags = 40; - zero_is_bad = 1; - } else if (!strcmp(model,"PowerShot SX120 IS")) { - height = 2742; - width = 3664; - raw_height = 2778; - raw_width = 3728; - top_margin = 18; - left_margin = 16; - filters = 0x49494949; - load_raw = &CLASS packed_load_raw; - load_flags = 40; - zero_is_bad = 1; - } else if (!strcmp(model,"PowerShot SX20 IS")) { - height = 3024; - width = 4032; - raw_height = 3048; - raw_width = 4080; - top_margin = 12; - left_margin = 24; - load_raw = &CLASS packed_load_raw; - load_flags = 40; - zero_is_bad = 1; - } else if (!strcmp(model,"PowerShot SX220 HS")) { - height = 3043; - width = 4072; - raw_height = 3060; - raw_width = 4168; - mask[0][0] = top_margin = 16; - mask[0][2] = top_margin + height; - mask[0][3] = left_margin = 92; - load_raw = &CLASS packed_load_raw; - load_flags = 8; - zero_is_bad = 1; - } else if (!strcmp(model,"PowerShot SX30 IS")) { - height = 3254; - width = 4366; - raw_height = 3276; - raw_width = 4464; - top_margin = 10; - left_margin = 25; - filters = 0x16161616; - load_raw = &CLASS packed_load_raw; - load_flags = 40; - zero_is_bad = 1; - } else if (!strcmp(model,"PowerShot Pro90 IS")) { - width = 1896; - colors = 4; - filters = 0xb4b4b4b4; - } else if (is_canon && raw_width == 2144) { - height = 1550; - width = 2088; - top_margin = 8; - left_margin = 4; - if (!strcmp(model,"PowerShot G1")) { - colors = 4; - filters = 0xb4b4b4b4; - } - } else if (is_canon && raw_width == 2224) { - height = 1448; - width = 2176; - top_margin = 6; - left_margin = 48; - } else if (is_canon && raw_width == 2376) { - height = 1720; - width = 2312; - top_margin = 6; - left_margin = 12; - } else if (is_canon && raw_width == 2672) { - height = 1960; - width = 2616; - top_margin = 6; - left_margin = 12; - } else if (is_canon && raw_width == 3152) { - height = 2056; - width = 3088; - top_margin = 12; - left_margin = 64; - if (unique_id == 0x80000170) - adobe_coeff ("Canon","EOS 300D"); - } else if (is_canon && raw_width == 3160) { - height = 2328; - width = 3112; - top_margin = 12; - left_margin = 44; - } else if (is_canon && raw_width == 3344) { - height = 2472; - width = 3288; - top_margin = 6; - left_margin = 4; - } else if (!strcmp(model,"EOS D2000C")) { - filters = 0x61616161; - black = curve[200]; - } else if (is_canon && raw_width == 3516) { - top_margin = 14; - left_margin = 42; - if (unique_id == 0x80000189) - adobe_coeff ("Canon","EOS 350D"); - goto canon_cr2; - } else if (is_canon && raw_width == 3596) { - top_margin = 12; - left_margin = 74; - goto canon_cr2; - } else if (is_canon && raw_width == 3744) { - height = 2760; - width = 3684; - top_margin = 16; - left_margin = 8; - if (unique_id > 0x2720000) { - top_margin = 12; - left_margin = 52; - } - } else if (is_canon && raw_width == 3944) { - height = 2602; - width = 3908; - top_margin = 18; - left_margin = 30; - } else if (is_canon && raw_width == 3948) { - top_margin = 18; - left_margin = 42; - height -= 2; - if (unique_id == 0x80000236) - adobe_coeff ("Canon","EOS 400D"); - if (unique_id == 0x80000254) - adobe_coeff ("Canon","EOS 1000D"); - goto canon_cr2; - } else if (is_canon && raw_width == 3984) { - top_margin = 20; - left_margin = 76; - height -= 2; - goto canon_cr2; - } else if (is_canon && raw_width == 4104) { - height = 3024; - width = 4032; - top_margin = 12; - left_margin = 48; - } else if (is_canon && raw_width == 4152) { - top_margin = 12; - left_margin = 192; - goto canon_cr2; - } else if (is_canon && raw_width == 4160) { - height = 3048; - width = 4048; - top_margin = 11; - left_margin = 104; - } else if (is_canon && raw_width == 4312) { - top_margin = 18; - left_margin = 22; - height -= 2; - if (unique_id == 0x80000176) - adobe_coeff ("Canon","EOS 450D"); - goto canon_cr2; - } else if (is_canon && raw_width == 4352) { - top_margin = 18; - left_margin = 62; - if (unique_id == 0x80000288) - adobe_coeff ("Canon","EOS 1100D"); - goto canon_cr2; - } else if (is_canon && raw_width == 4476) { - top_margin = 34; - left_margin = 90; - goto canon_cr2; - } else if (is_canon && raw_width == 4480) { - height = 3326; - width = 4432; - top_margin = 10; - left_margin = 12; - filters = 0x49494949; - } else if (is_canon && raw_width == 4496) { - height = 3316; - width = 4404; - top_margin = 50; - left_margin = 80; - } else if (is_canon && raw_width == 4832) { - top_margin = unique_id == 0x80000261 ? 51:26; - left_margin = 62; - if (unique_id == 0x80000252) - adobe_coeff ("Canon","EOS 500D"); - goto canon_cr2; - } else if (is_canon && raw_width == 5108) { - top_margin = 13; - left_margin = 98; - goto canon_cr2; - } else if (is_canon && raw_width == 5120) { - height -= top_margin = 45; - left_margin = 142; - width = 4916; - } else if (is_canon && raw_width == 5344) { - top_margin = 51; - left_margin = 142; - if (unique_id == 0x80000269) { - top_margin = 100; - left_margin = 126; - height -= 2; - adobe_coeff ("Canon","EOS-1D X"); - } - if (unique_id == 0x80000270) - adobe_coeff ("Canon","EOS 550D"); - if (unique_id == 0x80000286) - adobe_coeff ("Canon","EOS 600D"); - goto canon_cr2; - } else if (is_canon && raw_width == 5360) { - top_margin = 51; - left_margin = 158; - goto canon_cr2; - } else if (is_canon && raw_width == 5712) { - height = 3752; - width = 5640; - top_margin = 20; - left_margin = 62; - } else if (is_canon && raw_width == 5792) { - top_margin = 51; - left_margin = 158; -canon_cr2: - height -= top_margin; - width -= left_margin; - } else if (is_canon && raw_width == 5920) { - height = 3870; - width = 5796; - top_margin = 80; - left_margin = 122; - } else if (!strcmp(model,"D1")) { - cam_mul[0] *= 256/527.0; - cam_mul[2] *= 256/317.0; - } else if (!strcmp(model,"D1X")) { - width -= 4; - pixel_aspect = 0.5; - } else if (!strcmp(model,"D40X") || - !strcmp(model,"D60") || - !strcmp(model,"D80") || - !strcmp(model,"D3000")) { - height -= 3; - width -= 4; - } else if (!strcmp(model,"D3") || - !strcmp(model,"D3S") || - !strcmp(model,"D700")) { - width -= 4; - left_margin = 2; - } else if (!strcmp(model,"D3100")) { - width -= 28; - left_margin = 6; - } else if (!strcmp(model,"D5000") || - !strcmp(model,"D90")) { - width -= 42; - } else if (!strcmp(model,"D5100") || - !strcmp(model,"D7000")) { - width -= 44; - } else if (!strcmp(model,"D3200") || - !strcmp(model,"D800")) { - width -= 46; - } else if (!strcmp(model,"D4")) { - width -= 52; - left_margin = 2; - } else if (!strncmp(model,"D40",3) || - !strncmp(model,"D50",3) || - !strncmp(model,"D70",3)) { - width--; - } else if (!strcmp(model,"D100")) { - if (tiff_compress == 34713 && !nikon_is_compressed()) { - load_raw = &CLASS packed_load_raw; - load_flags |= 1; - raw_width = (width += 3) + 3; - } - } else if (!strcmp(model,"D200")) { - left_margin = 1; - width -= 4; - filters = 0x94949494; - } else if (!strncmp(model,"D2H",3)) { - left_margin = 6; - width -= 14; - } else if (!strncmp(model,"D2X",3)) { - if (width == 3264) width -= 32; - else width -= 8; - } else if (!strncmp(model,"D300",4)) { - width -= 32; - } else if (!strncmp(model,"COOLPIX P",9)) { - load_flags = 24; - filters = 0x94949494; - if (model[9] == '7' && iso_speed >= 400) - black = 255; - } else if (!strncmp(model,"1 ",2)) { - height -= 2; - } else if (fsize == 1581060) { - height = 963; - width = 1287; - raw_width = 1632; - maximum = 0x3f4; - colors = 4; - filters = 0x1e1e1e1e; - simple_coeff(3); - pre_mul[0] = 1.2085; - pre_mul[1] = 1.0943; - pre_mul[3] = 1.1103; - goto e900; - } else if (fsize == 2465792) { - height = 1203; - width = 1616; - raw_width = 2048; - colors = 4; - filters = 0x4b4b4b4b; - adobe_coeff ("NIKON","E950"); -e900: - tiff_bps = 10; - load_raw = &CLASS packed_load_raw; - load_flags = 6; - } else if (fsize == 4771840) { - height = 1540; - width = 2064; - colors = 4; - filters = 0xe1e1e1e1; - load_raw = &CLASS packed_load_raw; - load_flags = 6; - if (!timestamp && nikon_e995()) - strcpy (model, "E995"); - if (strcmp(model,"E995")) { - filters = 0xb4b4b4b4; - simple_coeff(3); - pre_mul[0] = 1.196; - pre_mul[1] = 1.246; - pre_mul[2] = 1.018; - } - } else if (!strcmp(model,"E2100")) { - if (!timestamp && !nikon_e2100()) goto cp_e2500; - height = 1206; - width = 1616; - load_flags = 30; - } else if (!strcmp(model,"E2500")) { -cp_e2500: - strcpy (model, "E2500"); - height = 1204; - width = 1616; - colors = 4; - filters = 0x4b4b4b4b; - } else if (fsize == 4775936) { - height = 1542; - width = 2064; - load_raw = &CLASS packed_load_raw; - load_flags = 30; - if (!timestamp) nikon_3700(); - if (model[0] == 'E' && atoi(model+1) < 3700) - filters = 0x49494949; - if (!strcmp(model,"Optio 33WR")) { - flip = 1; - filters = 0x16161616; - } - if (make[0] == 'O') { - i = find_green (12, 32, 1188864, 3576832); - c = find_green (12, 32, 2383920, 2387016); - if (abs(i) < abs(c)) { - SWAP(i,c); - load_flags = 24; - } - if (i < 0) filters = 0x61616161; - } - } else if (fsize == 5869568) { - height = 1710; - width = 2288; - filters = 0x16161616; - if (!timestamp && minolta_z2()) { - strcpy (make, "Minolta"); - strcpy (model,"DiMAGE Z2"); - } - load_raw = &CLASS packed_load_raw; - load_flags = 6 + 24*(make[0] == 'M'); - } else if (!strcmp(model,"E4500")) { - height = 1708; - width = 2288; - colors = 4; - filters = 0xb4b4b4b4; - } else if (fsize == 7438336) { - height = 1924; - width = 2576; - colors = 4; - filters = 0xb4b4b4b4; - } else if (fsize == 8998912) { - height = 2118; - width = 2832; - maximum = 0xf83; - load_raw = &CLASS packed_load_raw; - load_flags = 30; - } else if (!strcmp(make,"FUJIFILM")) { - if (!strcmp(model+7,"S2Pro")) { - strcpy (model,"S2Pro"); - height = 2144; - width = 2880; - flip = 6; - } else if (load_raw != &CLASS packed_load_raw) - maximum = (is_raw == 2 && shot_select) ? 0x2f00 : 0x3e00; - top_margin = (raw_height - height) >> 2 << 1; - left_margin = (raw_width - width ) >> 2 << 1; - if (width == 3328) { - width = 3262; - left_margin = 34; - } - if (!strcmp(model,"X10") || !strcmp(model,"X-S1")) - filters = 0x16161616; - if (!strcmp(model,"X-Pro1")) { - left_margin = 0; - filters = 2; - } - if (fuji_layout) raw_width *= is_raw; - } else if (!strcmp(model,"RD175")) { - height = 986; - width = 1534; - data_offset = 513; - filters = 0x61616161; - load_raw = &CLASS minolta_rd175_load_raw; - } else if (!strcmp(model,"KD-400Z")) { - height = 1712; - width = 2312; - raw_width = 2336; - goto konica_400z; - } else if (!strcmp(model,"KD-510Z")) { - goto konica_510z; - } else if (!strcasecmp(make,"MINOLTA")) { - load_raw = &CLASS unpacked_load_raw; - maximum = 0xfff; - if (!strncmp(model,"DiMAGE A",8)) { - if (!strcmp(model,"DiMAGE A200")) - filters = 0x49494949; - tiff_bps = 12; - load_raw = &CLASS packed_load_raw; - } else if (!strncmp(model,"ALPHA",5) || - !strncmp(model,"DYNAX",5) || - !strncmp(model,"MAXXUM",6)) { - sprintf (model+20, "DYNAX %-10s", model+6+(model[0]=='M')); - adobe_coeff (make, model+20); - load_raw = &CLASS packed_load_raw; - } else if (!strncmp(model,"DiMAGE G",8)) { - if (model[8] == '4') { - height = 1716; - width = 2304; - } else if (model[8] == '5') { -konica_510z: - height = 1956; - width = 2607; - raw_width = 2624; - } else if (model[8] == '6') { - height = 2136; - width = 2848; - } - data_offset += 14; - filters = 0x61616161; -konica_400z: - load_raw = &CLASS unpacked_load_raw; - maximum = 0x3df; - order = 0x4d4d; - } - } else if (!strcmp(model,"*ist D")) { - load_raw = &CLASS unpacked_load_raw; - data_error = -1; - } else if (!strcmp(model,"*ist DS")) { - height -= 2; - } else if (!strcmp(model,"Optio S")) { - if (fsize == 3178560) { - height = 1540; - width = 2064; - load_raw = &CLASS eight_bit_load_raw; - cam_mul[0] *= 4; - cam_mul[2] *= 4; - } else { - height = 1544; - width = 2068; - raw_width = 3136; - load_raw = &CLASS packed_load_raw; - maximum = 0xf7c; - } - } else if (fsize == 6114240) { - height = 1737; - width = 2324; - raw_width = 3520; - load_raw = &CLASS packed_load_raw; - maximum = 0xf7a; - } else if (!strcmp(model,"Optio 750Z")) { - height = 2302; - width = 3072; - load_raw = &CLASS packed_load_raw; - load_flags = 30; - } else if (!strcmp(model,"DC-833m")) { - height = 2448; - width = 3264; - order = 0x4949; - filters = 0x61616161; - load_raw = &CLASS unpacked_load_raw; - maximum = 0xfc00; - } else if (!strncmp(model,"S85",3)) { - height = 2448; - width = 3264; - raw_width = fsize/height/2; - order = 0x4d4d; - load_raw = &CLASS unpacked_load_raw; - } else if (!strncmp(model,"NX1",3)) { - height -= top_margin = 8; - width -= 2 * (left_margin = 8); - load_flags = 32; - } else if (!strcmp(model,"NX200")) { - order = 0x4949; - height = 3694; - top_margin = 2; - width = 5574 - (left_margin = 32 + tiff_bps); - if (tiff_bps == 12) load_flags = 80; - } else if (!strcmp(model,"EX1")) { - order = 0x4949; - height -= 20; - top_margin = 2; - if ((width -= 6) > 3682) { - height -= 10; - width -= 46; - top_margin = 8; - } - } else if (!strcmp(model,"WB2000")) { - order = 0x4949; - height -= 3; - top_margin = 2; - if ((width -= 10) > 3718) { - height -= 28; - width -= 56; - top_margin = 8; - } - } else if (fsize == 20487168) { - height = 2808; - width = 3648; - goto wb550; - } else if (fsize == 24000000) { - height = 3000; - width = 4000; -wb550: - strcpy (model, "WB550"); - order = 0x4d4d; - load_raw = &CLASS unpacked_load_raw; - load_flags = 6; - maximum = 0x3df; - } else if (!strcmp(model,"STV680 VGA")) { - height = 484; - width = 644; - load_raw = &CLASS eight_bit_load_raw; - flip = 2; - filters = 0x16161616; - black = 16; - } else if (!strcmp(model,"N95")) { - height = raw_height - (top_margin = 2); - } else if (!strcmp(model,"531C")) { - height = 1200; - width = 1600; - load_raw = &CLASS unpacked_load_raw; - filters = 0x49494949; - } else if (!strcmp(model,"640x480")) { - height = 480; - width = 640; - load_raw = &CLASS eight_bit_load_raw; - gamma_curve (0.45, 4.5, 1, 255); - } else if (!strcmp(model,"F-080C")) { - height = 768; - width = 1024; - load_raw = &CLASS eight_bit_load_raw; - } else if (!strcmp(model,"F-145C")) { - height = 1040; - width = 1392; - load_raw = &CLASS eight_bit_load_raw; - } else if (!strcmp(model,"F-201C")) { - height = 1200; - width = 1600; - load_raw = &CLASS eight_bit_load_raw; - } else if (!strcmp(model,"F-510C")) { - height = 1958; - width = 2588; - load_raw = fsize < 7500000 ? - &CLASS eight_bit_load_raw : &CLASS unpacked_load_raw; - data_offset = fsize - width*height*(fsize >> 22); - maximum = 0xfff0; - } else if (!strcmp(model,"F-810C")) { - height = 2469; - width = 3272; - load_raw = &CLASS unpacked_load_raw; - maximum = 0xfff0; - } else if (!strcmp(model,"XCD-SX910CR")) { - height = 1024; - width = 1375; - raw_width = 1376; - filters = 0x49494949; - maximum = 0x3ff; - load_raw = fsize < 2000000 ? - &CLASS eight_bit_load_raw : &CLASS unpacked_load_raw; - } else if (!strcmp(model,"2010")) { - height = 1207; - width = 1608; - order = 0x4949; - filters = 0x16161616; - data_offset = 3212; - maximum = 0x3ff; - load_raw = &CLASS unpacked_load_raw; - } else if (!strcmp(model,"A782")) { - height = 3000; - width = 2208; - filters = 0x61616161; - load_raw = fsize < 10000000 ? - &CLASS eight_bit_load_raw : &CLASS unpacked_load_raw; - maximum = 0xffc0; - } else if (!strcmp(model,"3320AF")) { - height = 1536; - raw_width = width = 2048; - filters = 0x61616161; - load_raw = &CLASS unpacked_load_raw; - maximum = 0x3ff; - fseek (ifp, 0x300000, SEEK_SET); - if ((order = guess_byte_order(0x10000)) == 0x4d4d) { - height -= (top_margin = 16); - width -= (left_margin = 28); - maximum = 0xf5c0; - strcpy (make, "ISG"); - model[0] = 0; - } - } else if (!strcmp(make,"Hasselblad")) { - if (load_raw == &CLASS lossless_jpeg_load_raw) - load_raw = &CLASS hasselblad_load_raw; - if (raw_width == 7262) { - height = 5444; - width = 7248; - top_margin = 4; - left_margin = 7; - filters = 0x61616161; - } else if (raw_width == 7410) { - height = 5502; - width = 7328; - top_margin = 4; - left_margin = 41; - filters = 0x61616161; - } else if (raw_width == 9044) { - height = 6716; - width = 8964; - top_margin = 8; - left_margin = 40; - black += load_flags = 256; - maximum = 0x8101; - } else if (raw_width == 4090) { - strcpy (model, "V96C"); - height -= (top_margin = 6); - width -= (left_margin = 3) + 7; - filters = 0x61616161; - } - } else if (!strcmp(make,"Sinar")) { - if (!memcmp(head,"8BPS",4)) { - fseek (ifp, 14, SEEK_SET); - height = get4(); - width = get4(); - filters = 0x61616161; - data_offset = 68; - } - if (!load_raw) load_raw = &CLASS unpacked_load_raw; - maximum = 0x3fff; - } else if (!strcmp(make,"Leaf")) { - maximum = 0x3fff; - fseek (ifp, data_offset, SEEK_SET); - if (ljpeg_start (&jh, 1) && jh.bits == 15) - maximum = 0x1fff; - if (tiff_samples > 1) filters = 0; - if (tiff_samples > 1 || tile_length < raw_height) { - load_raw = &CLASS leaf_hdr_load_raw; - raw_width = tile_width; - } - if ((width | height) == 2048) { - if (tiff_samples == 1) { - filters = 1; - strcpy (cdesc, "RBTG"); - strcpy (model, "CatchLight"); - top_margin = 8; left_margin = 18; height = 2032; width = 2016; - } else { - strcpy (model, "DCB2"); - top_margin = 10; left_margin = 16; height = 2028; width = 2022; - } - } else if (width+height == 3144+2060) { - if (!model[0]) strcpy (model, "Cantare"); - if (width > height) { - top_margin = 6; left_margin = 32; height = 2048; width = 3072; - filters = 0x61616161; - } else { - left_margin = 6; top_margin = 32; width = 2048; height = 3072; - filters = 0x16161616; - } - if (!cam_mul[0] || model[0] == 'V') filters = 0; - else is_raw = tiff_samples; - } else if (width == 2116) { - strcpy (model, "Valeo 6"); - height -= 2 * (top_margin = 30); - width -= 2 * (left_margin = 55); - filters = 0x49494949; - } else if (width == 3171) { - strcpy (model, "Valeo 6"); - height -= 2 * (top_margin = 24); - width -= 2 * (left_margin = 24); - filters = 0x16161616; - } - } else if (!strcmp(make,"LEICA") || !strcmp(make,"Panasonic")) { - if ((flen - data_offset) / (raw_width*8/7) == raw_height) - load_raw = &CLASS panasonic_load_raw; - if (!load_raw) { - load_raw = &CLASS unpacked_load_raw; - load_flags = 4; - } - zero_is_bad = 1; - if ((height += 12) > raw_height) height = raw_height; - for (i=0; i < sizeof pana / sizeof *pana; i++) - if (raw_width == pana[i][0] && raw_height == pana[i][1]) { - left_margin = pana[i][2]; - top_margin = pana[i][3]; - width += pana[i][4]; - height += pana[i][5]; - } - filters = 0x01010101 * (uchar) "\x94\x61\x49\x16" - [((filters-1) ^ (left_margin & 1) ^ (top_margin << 1)) & 3]; - } else if (!strcmp(model,"C770UZ")) { - height = 1718; - width = 2304; - filters = 0x16161616; - load_raw = &CLASS packed_load_raw; - load_flags = 30; - } else if (!strcmp(make,"OLYMPUS")) { - height += height & 1; - filters = exif_cfa; - if (width == 4100) width -= 4; - if (width == 4080) width -= 24; - if (load_raw == &CLASS unpacked_load_raw) - load_flags = 4; - tiff_bps = 12; - if (!strcmp(model,"E-300") || - !strcmp(model,"E-500")) { - width -= 20; - if (load_raw == &CLASS unpacked_load_raw) { - maximum = 0xfc3; - memset (cblack, 0, sizeof cblack); - } - } else if (!strcmp(model,"E-330")) { - width -= 30; - if (load_raw == &CLASS unpacked_load_raw) - maximum = 0xf79; - } else if (!strcmp(model,"SP550UZ")) { - thumb_length = flen - (thumb_offset = 0xa39800); - thumb_height = 480; - thumb_width = 640; - } - } else if (!strcmp(model,"N Digital")) { - height = 2047; - width = 3072; - filters = 0x61616161; - data_offset = 0x1a00; - load_raw = &CLASS packed_load_raw; - } else if (!strcmp(model,"DSC-F828")) { - width = 3288; - left_margin = 5; - data_offset = 862144; - load_raw = &CLASS sony_load_raw; - filters = 0x9c9c9c9c; - colors = 4; - strcpy (cdesc, "RGBE"); - } else if (!strcmp(model,"DSC-V3")) { - width = 3109; - left_margin = 59; - data_offset = 787392; - load_raw = &CLASS sony_load_raw; - } else if (!strcmp(make,"SONY") && raw_width == 3984) { - adobe_coeff ("SONY","DSC-R1"); - width = 3925; - order = 0x4d4d; - } else if (!strcmp(make,"SONY") && raw_width == 6048) { - width -= 24; - } else if (!strcmp(model,"DSLR-A100")) { - if (width == 3880) { - height--; - width = ++raw_width; - } else { - order = 0x4d4d; - load_flags = 2; - } - filters = 0x61616161; - } else if (!strcmp(model,"DSLR-A350")) { - height -= 4; - } else if (!strcmp(model,"PIXL")) { - height -= top_margin = 4; - width -= left_margin = 32; - gamma_curve (0, 7, 1, 255); - } else if (!strcmp(model,"C603v")) { - height = 480; - width = 640; - if (fsize < 614400 || find_green (16, 16, 3840, 5120) < 25) goto c603v; - strcpy (model,"KAI-0340"); - height -= 3; - data_offset = 3840; - order = 0x4949; - load_raw = &CLASS unpacked_load_raw; - } else if (!strcmp(model,"C603y")) { - height = 2134; - width = 2848; -c603v: - filters = 0; - load_raw = &CLASS kodak_yrgb_load_raw; - gamma_curve (0, 3.875, 1, 255); - } else if (!strcmp(model,"C603")) { - raw_height = height = 2152; - raw_width = width = 2864; - goto c603; - } else if (!strcmp(model,"C330")) { - height = 1744; - width = 2336; - raw_height = 1779; - raw_width = 2338; - top_margin = 33; - left_margin = 1; -c603: - order = 0x4949; - if ((data_offset = fsize - raw_height*raw_width)) { - fseek (ifp, 168, SEEK_SET); - read_shorts (curve, 256); - } else gamma_curve (0, 3.875, 1, 255); - load_raw = &CLASS eight_bit_load_raw; - } else if (!strncasecmp(model,"EasyShare",9)) { - data_offset = data_offset < 0x15000 ? 0x15000 : 0x17000; - load_raw = &CLASS packed_load_raw; - } else if (!strcasecmp(make,"KODAK")) { - if (filters == UINT_MAX) filters = 0x61616161; - if (!strncmp(model,"NC2000",6)) { - width -= 4; - left_margin = 2; - } else if (!strcmp(model,"EOSDCS3B")) { - width -= 4; - left_margin = 2; - } else if (!strcmp(model,"EOSDCS1")) { - width -= 4; - left_margin = 2; - } else if (!strcmp(model,"DCS420")) { - width -= 4; - left_margin = 2; - } else if (!strncmp(model,"DCS460 ",7)) { - model[6] = 0; - width -= 4; - left_margin = 2; - } else if (!strcmp(model,"DCS460A")) { - width -= 4; - left_margin = 2; - colors = 1; - filters = 0; - } else if (!strcmp(model,"DCS660M")) { - black = 214; - colors = 1; - filters = 0; - } else if (!strcmp(model,"DCS760M")) { - colors = 1; - filters = 0; - } - if (!strcmp(model+4,"20X")) - strcpy (cdesc, "MYCY"); - if (strstr(model,"DC25")) { - strcpy (model, "DC25"); - data_offset = 15424; - } - if (!strncmp(model,"DC2",3)) { - raw_height = height = 242; - if (flen < 100000) { - raw_width = 256; width = 249; - pixel_aspect = (4.0*height) / (3.0*width); - } else { - raw_width = 512; width = 501; - pixel_aspect = (493.0*height) / (373.0*width); - } - data_offset += raw_width + 1; - colors = 4; - filters = 0x8d8d8d8d; - simple_coeff(1); - pre_mul[1] = 1.179; - pre_mul[2] = 1.209; - pre_mul[3] = 1.036; - load_raw = &CLASS eight_bit_load_raw; - } else if (!strcmp(model,"40")) { - strcpy (model, "DC40"); - height = 512; - width = 768; - data_offset = 1152; - load_raw = &CLASS kodak_radc_load_raw; - } else if (strstr(model,"DC50")) { - strcpy (model, "DC50"); - height = 512; - width = 768; - data_offset = 19712; - load_raw = &CLASS kodak_radc_load_raw; - } else if (strstr(model,"DC120")) { - strcpy (model, "DC120"); - height = 976; - width = 848; - pixel_aspect = height/0.75/width; - load_raw = tiff_compress == 7 ? - &CLASS kodak_jpeg_load_raw : &CLASS kodak_dc120_load_raw; - } else if (!strcmp(model,"DCS200")) { - thumb_height = 128; - thumb_width = 192; - thumb_offset = 6144; - thumb_misc = 360; - write_thumb = &CLASS layer_thumb; - height = 1024; - width = 1536; - data_offset = 79872; - load_raw = &CLASS eight_bit_load_raw; - black = 17; - } - } else if (!strcmp(model,"Fotoman Pixtura")) { - height = 512; - width = 768; - data_offset = 3632; - load_raw = &CLASS kodak_radc_load_raw; - filters = 0x61616161; - simple_coeff(2); - } else if (!strncmp(model,"QuickTake",9)) { - if (head[5]) strcpy (model+10, "200"); - fseek (ifp, 544, SEEK_SET); - height = get2(); - width = get2(); - data_offset = (get4(),get2()) == 30 ? 738:736; - if (height > width) { - SWAP(height,width); - fseek (ifp, data_offset-6, SEEK_SET); - flip = ~get2() & 3 ? 5:6; - } - filters = 0x61616161; - } else if (!strcmp(make,"Rollei") && !load_raw) { - switch (raw_width) { - case 1316: - height = 1030; - width = 1300; - top_margin = 1; - left_margin = 6; - break; - case 2568: - height = 1960; - width = 2560; - top_margin = 2; - left_margin = 8; - } - filters = 0x16161616; - load_raw = &CLASS rollei_load_raw; - } else if (!strcmp(model,"PC-CAM 600")) { - height = 768; - data_offset = width = 1024; - filters = 0x49494949; - load_raw = &CLASS eight_bit_load_raw; - } else if (!strcmp(model,"QV-2000UX")) { - height = 1208; - width = 1632; - data_offset = width * 2; - load_raw = &CLASS eight_bit_load_raw; - } else if (fsize == 3217760) { - height = 1546; - width = 2070; - raw_width = 2080; - load_raw = &CLASS eight_bit_load_raw; - } else if (!strcmp(model,"QV-4000")) { - height = 1700; - width = 2260; - load_raw = &CLASS unpacked_load_raw; - maximum = 0xffff; - } else if (!strcmp(model,"QV-5700")) { - height = 1924; - width = 2576; - raw_width = 3232; - tiff_bps = 10; - } else if (!strcmp(model,"QV-R41")) { - height = 1720; - width = 2312; - raw_width = 3520; - left_margin = 2; - } else if (!strcmp(model,"QV-R51")) { - height = 1926; - width = 2580; - raw_width = 3904; - } else if (!strcmp(model,"EX-S20")) { - height = 1208; - width = 1620; - raw_width = 2432; - flip = 3; - } else if (!strcmp(model,"EX-S100")) { - height = 1544; - width = 2058; - raw_width = 3136; - } else if (!strcmp(model,"EX-Z50")) { - height = 1931; - width = 2570; - raw_width = 3904; - } else if (!strcmp(model,"EX-Z500")) { - height = 1937; - width = 2577; - raw_width = 3904; - filters = 0x16161616; - } else if (!strcmp(model,"EX-Z55")) { - height = 1960; - width = 2570; - raw_width = 3904; - } else if (!strcmp(model,"EX-Z60")) { - height = 2145; - width = 2833; - raw_width = 3584; - filters = 0x16161616; - tiff_bps = 10; - } else if (!strcmp(model,"EX-Z75")) { - height = 2321; - width = 3089; - raw_width = 4672; - maximum = 0xfff; - } else if (!strcmp(model,"EX-Z750")) { - height = 2319; - width = 3087; - raw_width = 4672; - maximum = 0xfff; - } else if (!strcmp(model,"EX-Z850")) { - height = 2468; - width = 3279; - raw_width = 4928; - maximum = 0xfff; - } else if (!strcmp(model,"EX-Z8")) { - height = 2467; - width = 3281; - raw_height = 2502; - raw_width = 4992; - maximum = 0xfff; - } else if (fsize == 15499264) { /* EX-Z1050 or EX-Z1080 */ - height = 2752; - width = 3672; - raw_width = 5632; - } else if (!strcmp(model,"EX-P505")) { - height = 1928; - width = 2568; - raw_width = 3852; - maximum = 0xfff; - } else if (fsize == 9313536) { /* EX-P600 or QV-R61 */ - height = 2142; - width = 2844; - raw_width = 4288; - } else if (!strcmp(model,"EX-P700")) { - height = 2318; - width = 3082; - raw_width = 4672; - } - if (!model[0]) - sprintf (model, "%dx%d", width, height); - if (filters == UINT_MAX) filters = 0x94949494; - if (raw_color) adobe_coeff (make, model); - if (load_raw == &CLASS kodak_radc_load_raw) - if (raw_color) adobe_coeff ("Apple","Quicktake"); - if (thumb_offset && !thumb_height) { - fseek (ifp, thumb_offset, SEEK_SET); - if (ljpeg_start (&jh, 1)) { - thumb_width = jh.wide; - thumb_height = jh.high; - } - } -dng_skip: - if (fuji_width) { - fuji_width = width >> !fuji_layout; - if (~fuji_width & 1) filters = 0x49494949; - width = (height >> fuji_layout) + fuji_width; - height = width - 1; - pixel_aspect = 1; - } else { - if (raw_height < height) raw_height = height; - if (raw_width < width ) raw_width = width; - } - if (!tiff_bps) tiff_bps = 12; - if (!maximum) maximum = (1 << tiff_bps) - 1; - if (!load_raw || height < 22) is_raw = 0; -#ifdef NO_JASPER - if (load_raw == &CLASS redcine_load_raw) { - fprintf (stderr,_("%s: You must link dcraw with %s!!\n"), - ifname, "libjasper"); - is_raw = 0; - } -#endif -#ifdef NO_JPEG - if (load_raw == &CLASS kodak_jpeg_load_raw || - load_raw == &CLASS lossy_dng_load_raw) { - fprintf (stderr,_("%s: You must link dcraw with %s!!\n"), - ifname, "libjpeg"); - is_raw = 0; - } -#endif - if (!cdesc[0]) - strcpy (cdesc, colors == 3 ? "RGBG":"GMCY"); - if (!raw_height) raw_height = height; - if (!raw_width ) raw_width = width; - if (filters && colors == 3) - filters |= ((filters >> 2 & 0x22222222) | - (filters << 2 & 0x88888888)) & filters << 1; -notraw: - if (flip == -1) flip = tiff_flip; - if (flip == -1) flip = 0; -} - -#ifndef NO_LCMS -void CLASS apply_profile (const char *input, const char *output) -{ - char *prof; - cmsHPROFILE hInProfile=0, hOutProfile=0; - cmsHTRANSFORM hTransform; - FILE *fp; - unsigned size; - - cmsErrorAction (LCMS_ERROR_SHOW); - if (strcmp (input, "embed")) - hInProfile = cmsOpenProfileFromFile (input, "r"); - else if (profile_length) { - prof = (char *) malloc (profile_length); - merror (prof, "apply_profile()"); - fseek (ifp, profile_offset, SEEK_SET); - fread (prof, 1, profile_length, ifp); - hInProfile = cmsOpenProfileFromMem (prof, profile_length); - free (prof); - } else - fprintf (stderr,_("%s has no embedded profile.\n"), ifname); - if (!hInProfile) return; - if (!output) - hOutProfile = cmsCreate_sRGBProfile(); - else if ((fp = fopen (output, "rb"))) { - fread (&size, 4, 1, fp); - fseek (fp, 0, SEEK_SET); - oprof = (unsigned *) malloc (size = ntohl(size)); - merror (oprof, "apply_profile()"); - fread (oprof, 1, size, fp); - fclose (fp); - if (!(hOutProfile = cmsOpenProfileFromMem (oprof, size))) { - free (oprof); - oprof = 0; - } - } else - fprintf (stderr,_("Cannot open file %s!\n"), output); - if (!hOutProfile) goto quit; - if (verbose) - fprintf (stderr,_("Applying color profile...\n")); - hTransform = cmsCreateTransform (hInProfile, TYPE_RGBA_16, - hOutProfile, TYPE_RGBA_16, INTENT_PERCEPTUAL, 0); - cmsDoTransform (hTransform, image, image, width*height); - raw_color = 1; /* Don't use rgb_cam with a profile */ - cmsDeleteTransform (hTransform); - cmsCloseProfile (hOutProfile); -quit: - cmsCloseProfile (hInProfile); -} -#endif - -void CLASS convert_to_rgb() -{ - int row, col, c, i, j, k; - ushort *img; - float out[3], out_cam[3][4]; - double num, inverse[3][3]; - static const double xyzd50_srgb[3][3] = - { { 0.436083, 0.385083, 0.143055 }, - { 0.222507, 0.716888, 0.060608 }, - { 0.013930, 0.097097, 0.714022 } }; - static const double rgb_rgb[3][3] = - { { 1,0,0 }, { 0,1,0 }, { 0,0,1 } }; - static const double adobe_rgb[3][3] = - { { 0.715146, 0.284856, 0.000000 }, - { 0.000000, 1.000000, 0.000000 }, - { 0.000000, 0.041166, 0.958839 } }; - static const double wide_rgb[3][3] = - { { 0.593087, 0.404710, 0.002206 }, - { 0.095413, 0.843149, 0.061439 }, - { 0.011621, 0.069091, 0.919288 } }; - static const double prophoto_rgb[3][3] = - { { 0.529317, 0.330092, 0.140588 }, - { 0.098368, 0.873465, 0.028169 }, - { 0.016879, 0.117663, 0.865457 } }; - static const double (*out_rgb[])[3] = - { rgb_rgb, adobe_rgb, wide_rgb, prophoto_rgb, xyz_rgb }; - static const char *name[] = - { "sRGB", "Adobe RGB (1998)", "WideGamut D65", "ProPhoto D65", "XYZ" }; - static const unsigned phead[] = - { 1024, 0, 0x2100000, 0x6d6e7472, 0x52474220, 0x58595a20, 0, 0, 0, - 0x61637370, 0, 0, 0x6e6f6e65, 0, 0, 0, 0, 0xf6d6, 0x10000, 0xd32d }; - unsigned pbody[] = - { 10, 0x63707274, 0, 36, /* cprt */ - 0x64657363, 0, 40, /* desc */ - 0x77747074, 0, 20, /* wtpt */ - 0x626b7074, 0, 20, /* bkpt */ - 0x72545243, 0, 14, /* rTRC */ - 0x67545243, 0, 14, /* gTRC */ - 0x62545243, 0, 14, /* bTRC */ - 0x7258595a, 0, 20, /* rXYZ */ - 0x6758595a, 0, 20, /* gXYZ */ - 0x6258595a, 0, 20 }; /* bXYZ */ - static const unsigned pwhite[] = { 0xf351, 0x10000, 0x116cc }; - unsigned pcurve[] = { 0x63757276, 0, 1, 0x1000000 }; - - gamma_curve (gamm[0], gamm[1], 0, 0); - memcpy (out_cam, rgb_cam, sizeof out_cam); - raw_color |= colors == 1 || document_mode || - output_color < 1 || output_color > 5; - if (!raw_color) { - oprof = (unsigned *) calloc (phead[0], 1); - merror (oprof, "convert_to_rgb()"); - memcpy (oprof, phead, sizeof phead); - if (output_color == 5) oprof[4] = oprof[5]; - oprof[0] = 132 + 12*pbody[0]; - for (i=0; i < pbody[0]; i++) { - oprof[oprof[0]/4] = i ? (i > 1 ? 0x58595a20 : 0x64657363) : 0x74657874; - pbody[i*3+2] = oprof[0]; - oprof[0] += (pbody[i*3+3] + 3) & -4; - } - memcpy (oprof+32, pbody, sizeof pbody); - oprof[pbody[5]/4+2] = strlen(name[output_color-1]) + 1; - memcpy ((char *)oprof+pbody[8]+8, pwhite, sizeof pwhite); - pcurve[3] = (short)(256/gamm[5]+0.5) << 16; - for (i=4; i < 7; i++) - memcpy ((char *)oprof+pbody[i*3+2], pcurve, sizeof pcurve); - pseudoinverse ((double (*)[3]) out_rgb[output_color-1], inverse, 3); - for (i=0; i < 3; i++) - for (j=0; j < 3; j++) { - for (num = k=0; k < 3; k++) - num += xyzd50_srgb[i][k] * inverse[j][k]; - oprof[pbody[j*3+23]/4+i+2] = num * 0x10000 + 0.5; - } - for (i=0; i < phead[0]/4; i++) - oprof[i] = htonl(oprof[i]); - strcpy ((char *)oprof+pbody[2]+8, "auto-generated by dcraw"); - strcpy ((char *)oprof+pbody[5]+12, name[output_color-1]); - for (i=0; i < 3; i++) - for (j=0; j < colors; j++) - for (out_cam[i][j] = k=0; k < 3; k++) - out_cam[i][j] += out_rgb[output_color-1][i][k] * rgb_cam[k][j]; - } - if (verbose) - fprintf (stderr, raw_color ? _("Building histograms...\n") : - _("Converting to %s colorspace...\n"), name[output_color-1]); - - memset (histogram, 0, sizeof histogram); - for (img=image[0], row=0; row < height; row++) - for (col=0; col < width; col++, img+=4) { - if (!raw_color) { - out[0] = out[1] = out[2] = 0; - FORCC { - out[0] += out_cam[0][c] * img[c]; - out[1] += out_cam[1][c] * img[c]; - out[2] += out_cam[2][c] * img[c]; - } - FORC3 img[c] = CLIP((int) out[c]); - } - else if (document_mode) - img[0] = img[fcol(row,col)]; - FORCC histogram[c][img[c] >> 3]++; - } - if (colors == 4 && output_color) colors = 3; - if (document_mode && filters) colors = 1; -} - -void CLASS fuji_rotate() -{ - int i, row, col; - double step; - float r, c, fr, fc; - unsigned ur, uc; - ushort wide, high, (*img)[4], (*pix)[4]; - - if (!fuji_width) return; - if (verbose) - fprintf (stderr,_("Rotating image 45 degrees...\n")); - fuji_width = (fuji_width - 1 + shrink) >> shrink; - step = sqrt(0.5); - wide = fuji_width / step; - high = (height - fuji_width) / step; - img = (ushort (*)[4]) calloc (wide*high, sizeof *img); - merror (img, "fuji_rotate()"); - - for (row=0; row < high; row++) - for (col=0; col < wide; col++) { - ur = r = fuji_width + (row-col)*step; - uc = c = (row+col)*step; - if (ur > height-2 || uc > width-2) continue; - fr = r - ur; - fc = c - uc; - pix = image + ur*width + uc; - for (i=0; i < colors; i++) - img[row*wide+col][i] = - (pix[ 0][i]*(1-fc) + pix[ 1][i]*fc) * (1-fr) + - (pix[width][i]*(1-fc) + pix[width+1][i]*fc) * fr; - } - free (image); - width = wide; - height = high; - image = img; - fuji_width = 0; -} - -void CLASS stretch() -{ - ushort newdim, (*img)[4], *pix0, *pix1; - int row, col, c; - double rc, frac; - - if (pixel_aspect == 1) return; - if (verbose) fprintf (stderr,_("Stretching the image...\n")); - if (pixel_aspect < 1) { - newdim = height / pixel_aspect + 0.5; - img = (ushort (*)[4]) calloc (width*newdim, sizeof *img); - merror (img, "stretch()"); - for (rc=row=0; row < newdim; row++, rc+=pixel_aspect) { - frac = rc - (c = rc); - pix0 = pix1 = image[c*width]; - if (c+1 < height) pix1 += width*4; - for (col=0; col < width; col++, pix0+=4, pix1+=4) - FORCC img[row*width+col][c] = pix0[c]*(1-frac) + pix1[c]*frac + 0.5; - } - height = newdim; - } else { - newdim = width * pixel_aspect + 0.5; - img = (ushort (*)[4]) calloc (height*newdim, sizeof *img); - merror (img, "stretch()"); - for (rc=col=0; col < newdim; col++, rc+=1/pixel_aspect) { - frac = rc - (c = rc); - pix0 = pix1 = image[c]; - if (c+1 < width) pix1 += 4; - for (row=0; row < height; row++, pix0+=width*4, pix1+=width*4) - FORCC img[row*newdim+col][c] = pix0[c]*(1-frac) + pix1[c]*frac + 0.5; - } - width = newdim; - } - free (image); - image = img; -} - -int CLASS flip_index (int row, int col) -{ - if (flip & 4) SWAP(row,col); - if (flip & 2) row = iheight - 1 - row; - if (flip & 1) col = iwidth - 1 - col; - return row * iwidth + col; -} - -struct tiff_tag { - ushort tag, type; - int count; - union { char c[4]; short s[2]; int i; } val; -}; - -struct tiff_hdr { - ushort order, magic; - int ifd; - ushort pad, ntag; - struct tiff_tag tag[23]; - int nextifd; - ushort pad2, nexif; - struct tiff_tag exif[4]; - ushort pad3, ngps; - struct tiff_tag gpst[10]; - short bps[4]; - int rat[10]; - unsigned gps[26]; - char desc[512], make[64], model[64], soft[32], date[20], artist[64]; -}; - -void CLASS tiff_set (ushort *ntag, - ushort tag, ushort type, int count, int val) -{ - struct tiff_tag *tt; - int c; - - tt = (struct tiff_tag *)(ntag+1) + (*ntag)++; - tt->tag = tag; - tt->type = type; - tt->count = count; - if (type < 3 && count <= 4) - FORC(4) tt->val.c[c] = val >> (c << 3); - else if (type == 3 && count <= 2) - FORC(2) tt->val.s[c] = val >> (c << 4); - else tt->val.i = val; -} - -#define TOFF(ptr) ((char *)(&(ptr)) - (char *)th) - -void CLASS tiff_head (struct tiff_hdr *th, int full) -{ - int c, psize=0; - struct tm *t; - - memset (th, 0, sizeof *th); - th->order = htonl(0x4d4d4949) >> 16; - th->magic = 42; - th->ifd = 10; - if (full) { - tiff_set (&th->ntag, 254, 4, 1, 0); - tiff_set (&th->ntag, 256, 4, 1, width); - tiff_set (&th->ntag, 257, 4, 1, height); - tiff_set (&th->ntag, 258, 3, colors, output_bps); - if (colors > 2) - th->tag[th->ntag-1].val.i = TOFF(th->bps); - FORC4 th->bps[c] = output_bps; - tiff_set (&th->ntag, 259, 3, 1, 1); - tiff_set (&th->ntag, 262, 3, 1, 1 + (colors > 1)); - } - tiff_set (&th->ntag, 270, 2, 512, TOFF(th->desc)); - tiff_set (&th->ntag, 271, 2, 64, TOFF(th->make)); - tiff_set (&th->ntag, 272, 2, 64, TOFF(th->model)); - if (full) { - if (oprof) psize = ntohl(oprof[0]); - tiff_set (&th->ntag, 273, 4, 1, sizeof *th + psize); - tiff_set (&th->ntag, 277, 3, 1, colors); - tiff_set (&th->ntag, 278, 4, 1, height); - tiff_set (&th->ntag, 279, 4, 1, height*width*colors*output_bps/8); - } else - tiff_set (&th->ntag, 274, 3, 1, "12435867"[flip]-'0'); - tiff_set (&th->ntag, 282, 5, 1, TOFF(th->rat[0])); - tiff_set (&th->ntag, 283, 5, 1, TOFF(th->rat[2])); - tiff_set (&th->ntag, 284, 3, 1, 1); - tiff_set (&th->ntag, 296, 3, 1, 2); - tiff_set (&th->ntag, 305, 2, 32, TOFF(th->soft)); - tiff_set (&th->ntag, 306, 2, 20, TOFF(th->date)); - tiff_set (&th->ntag, 315, 2, 64, TOFF(th->artist)); - tiff_set (&th->ntag, 34665, 4, 1, TOFF(th->nexif)); - if (psize) tiff_set (&th->ntag, 34675, 7, psize, sizeof *th); - tiff_set (&th->nexif, 33434, 5, 1, TOFF(th->rat[4])); - tiff_set (&th->nexif, 33437, 5, 1, TOFF(th->rat[6])); - tiff_set (&th->nexif, 34855, 3, 1, iso_speed); - tiff_set (&th->nexif, 37386, 5, 1, TOFF(th->rat[8])); - if (gpsdata[1]) { - tiff_set (&th->ntag, 34853, 4, 1, TOFF(th->ngps)); - tiff_set (&th->ngps, 0, 1, 4, 0x202); - tiff_set (&th->ngps, 1, 2, 2, gpsdata[29]); - tiff_set (&th->ngps, 2, 5, 3, TOFF(th->gps[0])); - tiff_set (&th->ngps, 3, 2, 2, gpsdata[30]); - tiff_set (&th->ngps, 4, 5, 3, TOFF(th->gps[6])); - tiff_set (&th->ngps, 5, 1, 1, gpsdata[31]); - tiff_set (&th->ngps, 6, 5, 1, TOFF(th->gps[18])); - tiff_set (&th->ngps, 7, 5, 3, TOFF(th->gps[12])); - tiff_set (&th->ngps, 18, 2, 12, TOFF(th->gps[20])); - tiff_set (&th->ngps, 29, 2, 12, TOFF(th->gps[23])); - memcpy (th->gps, gpsdata, sizeof th->gps); - } - th->rat[0] = th->rat[2] = 300; - th->rat[1] = th->rat[3] = 1; - FORC(6) th->rat[4+c] = 1000000; - th->rat[4] *= shutter; - th->rat[6] *= aperture; - th->rat[8] *= focal_len; - strncpy (th->desc, desc, 512); - strncpy (th->make, make, 64); - strncpy (th->model, model, 64); - strcpy (th->soft, "dcraw v"DCRAW_VERSION); - t = localtime (×tamp); - sprintf (th->date, "%04d:%02d:%02d %02d:%02d:%02d", - t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); - strncpy (th->artist, artist, 64); -} - -void CLASS jpeg_thumb() -{ - char *thumb; - ushort exif[5]; - struct tiff_hdr th; - - thumb = (char *) malloc (thumb_length); - merror (thumb, "jpeg_thumb()"); - fread (thumb, 1, thumb_length, ifp); - fputc (0xff, ofp); - fputc (0xd8, ofp); - if (strcmp (thumb+6, "Exif")) { - memcpy (exif, "\xff\xe1 Exif\0\0", 10); - exif[1] = htons (8 + sizeof th); - fwrite (exif, 1, sizeof exif, ofp); - tiff_head (&th, 0); - fwrite (&th, 1, sizeof th, ofp); - } - fwrite (thumb+2, 1, thumb_length-2, ofp); - free (thumb); -} - -void CLASS write_ppm_tiff() -{ - struct tiff_hdr th; - uchar *ppm; - ushort *ppm2; - int c, row, col, soff, rstep, cstep; - int perc, val, total, white=0x2000; - - perc = width * height * 0.01; /* 99th percentile white level */ - if (fuji_width) perc /= 2; - if (!((highlight & ~2) || no_auto_bright)) - for (white=c=0; c < colors; c++) { - for (val=0x2000, total=0; --val > 32; ) - if ((total += histogram[c][val]) > perc) break; - if (white < val) white = val; - } - gamma_curve (gamm[0], gamm[1], 2, (white << 3)/bright); - iheight = height; - iwidth = width; - if (flip & 4) SWAP(height,width); - ppm = (uchar *) calloc (width, colors*output_bps/8); - ppm2 = (ushort *) ppm; - merror (ppm, "write_ppm_tiff()"); - if (output_tiff) { - tiff_head (&th, 1); - fwrite (&th, sizeof th, 1, ofp); - if (oprof) - fwrite (oprof, ntohl(oprof[0]), 1, ofp); - } else if (colors > 3) - fprintf (ofp, - "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLTYPE %s\nENDHDR\n", - width, height, colors, (1 << output_bps)-1, cdesc); - else - fprintf (ofp, "P%d\n%d %d\n%d\n", - colors/2+5, width, height, (1 << output_bps)-1); - soff = flip_index (0, 0); - cstep = flip_index (0, 1) - soff; - rstep = flip_index (1, 0) - flip_index (0, width); - for (row=0; row < height; row++, soff += rstep) { - for (col=0; col < width; col++, soff += cstep) - if (output_bps == 8) - FORCC ppm [col*colors+c] = curve[image[soff][c]] >> 8; - else FORCC ppm2[col*colors+c] = curve[image[soff][c]]; - if (output_bps == 16 && !output_tiff && htons(0x55aa) != 0x55aa) - swab (ppm2, ppm2, width*colors*2); - fwrite (ppm, colors*output_bps/8, width, ofp); - } - free (ppm); -} - -int CLASS main (int argc, const char **argv) -{ - int arg, status=0, quality, i, c; - int timestamp_only=0, thumbnail_only=0, identify_only=0; - int user_qual=-1, user_black=-1, user_sat=-1, user_flip=-1; - int use_fuji_rotate=1, write_to_stdout=0, read_from_stdin=0; - const char *sp, *bpfile=0, *dark_frame=0, *write_ext; - char opm, opt, *ofname, *cp; - struct utimbuf ut; -#ifndef NO_LCMS - const char *cam_profile=0, *out_profile=0; -#endif - -#ifndef LOCALTIME - putenv ((char *) "TZ=UTC"); -#endif -#ifdef LOCALEDIR - setlocale (LC_CTYPE, ""); - setlocale (LC_MESSAGES, ""); - bindtextdomain ("dcraw", LOCALEDIR); - textdomain ("dcraw"); -#endif - - if (argc == 1) { - printf(_("\nRaw photo decoder \"dcraw\" v%s"), DCRAW_VERSION); - printf(_("\nby Dave Coffin, dcoffin a cybercom o net\n")); - printf(_("\nUsage: %s [OPTION]... [FILE]...\n\n"), argv[0]); - puts(_("-v Print verbose messages")); - puts(_("-c Write image data to standard output")); - puts(_("-e Extract embedded thumbnail image")); - puts(_("-i Identify files without decoding them")); - puts(_("-i -v Identify files and show metadata")); - puts(_("-z Change file dates to camera timestamp")); - puts(_("-w Use camera white balance, if possible")); - puts(_("-a Average the whole image for white balance")); - puts(_("-A Average a grey box for white balance")); - puts(_("-r Set custom white balance")); - puts(_("+M/-M Use/don't use an embedded color matrix")); - puts(_("-C Correct chromatic aberration")); - puts(_("-P Fix the dead pixels listed in this file")); - puts(_("-K Subtract dark frame (16-bit raw PGM)")); - puts(_("-k Set the darkness level")); - puts(_("-S Set the saturation level")); - puts(_("-n Set threshold for wavelet denoising")); - puts(_("-H [0-9] Highlight mode (0=clip, 1=unclip, 2=blend, 3+=rebuild)")); - puts(_("-t [0-7] Flip image (0=none, 3=180, 5=90CCW, 6=90CW)")); - puts(_("-o [0-5] Output colorspace (raw,sRGB,Adobe,Wide,ProPhoto,XYZ)")); -#ifndef NO_LCMS - puts(_("-o Apply output ICC profile from file")); - puts(_("-p Apply camera ICC profile from file or \"embed\"")); -#endif - puts(_("-d Document mode (no color, no interpolation)")); - puts(_("-D Document mode without scaling (totally raw)")); - puts(_("-j Don't stretch or rotate raw pixels")); - puts(_("-W Don't automatically brighten the image")); - puts(_("-b Adjust brightness (default = 1.0)")); - puts(_("-g

    Set custom gamma curve (default = 2.222 4.5)")); - puts(_("-q [0-3] Set the interpolation quality")); - puts(_("-h Half-size color image (twice as fast as \"-q 0\")")); - puts(_("-f Interpolate RGGB as four colors")); - puts(_("-m Apply a 3x3 median filter to R-G and B-G")); - puts(_("-s [0..N-1] Select one raw image or \"all\" from each file")); - puts(_("-6 Write 16-bit instead of 8-bit")); - puts(_("-4 Linear 16-bit, same as \"-6 -W -g 1 1\"")); - puts(_("-T Write TIFF instead of PPM")); - puts(""); - return 1; - } - argv[argc] = ""; - for (arg=1; (((opm = argv[arg][0]) - 2) | 2) == '+'; ) { - opt = argv[arg++][1]; - if ((cp = (char *) strchr (sp="nbrkStqmHACg", opt))) - for (i=0; i < "114111111422"[cp-sp]-'0'; i++) - if (!isdigit(argv[arg+i][0])) { - fprintf (stderr,_("Non-numeric argument to \"-%c\"\n"), opt); - return 1; - } - switch (opt) { - case 'n': threshold = atof(argv[arg++]); break; - case 'b': bright = atof(argv[arg++]); break; - case 'r': - FORC4 user_mul[c] = atof(argv[arg++]); break; - case 'C': aber[0] = 1 / atof(argv[arg++]); - aber[2] = 1 / atof(argv[arg++]); break; - case 'g': gamm[0] = atof(argv[arg++]); - gamm[1] = atof(argv[arg++]); - if (gamm[0]) gamm[0] = 1/gamm[0]; break; - case 'k': user_black = atoi(argv[arg++]); break; - case 'S': user_sat = atoi(argv[arg++]); break; - case 't': user_flip = atoi(argv[arg++]); break; - case 'q': user_qual = atoi(argv[arg++]); break; - case 'm': med_passes = atoi(argv[arg++]); break; - case 'H': highlight = atoi(argv[arg++]); break; - case 's': - shot_select = abs(atoi(argv[arg])); - multi_out = !strcmp(argv[arg++],"all"); - break; - case 'o': - if (isdigit(argv[arg][0]) && !argv[arg][1]) - output_color = atoi(argv[arg++]); -#ifndef NO_LCMS - else out_profile = argv[arg++]; - break; - case 'p': cam_profile = argv[arg++]; -#endif - break; - case 'P': bpfile = argv[arg++]; break; - case 'K': dark_frame = argv[arg++]; break; - case 'z': timestamp_only = 1; break; - case 'e': thumbnail_only = 1; break; - case 'i': identify_only = 1; break; - case 'c': write_to_stdout = 1; break; - case 'v': verbose = 1; break; - case 'h': half_size = 1; /* "-h" implies "-f" */ - case 'f': four_color_rgb = 1; break; - case 'A': FORC4 greybox[c] = atoi(argv[arg++]); - case 'a': use_auto_wb = 1; break; - case 'w': use_camera_wb = 1; break; - case 'M': use_camera_matrix = (opm == '+'); break; - case 'I': read_from_stdin = 1; break; - case 'E': document_mode++; - case 'D': document_mode++; - case 'd': document_mode++; - case 'j': use_fuji_rotate = 0; break; - case 'W': no_auto_bright = 1; break; - case 'T': output_tiff = 1; break; - case '4': gamm[0] = gamm[1] = - no_auto_bright = 1; - case '6': output_bps = 16; break; - default: - fprintf (stderr,_("Unknown option \"-%c\".\n"), opt); - return 1; - } - } - if (use_camera_matrix < 0) - use_camera_matrix = use_camera_wb; - if (arg == argc) { - fprintf (stderr,_("No files to process.\n")); - return 1; - } - if (write_to_stdout) { - if (isatty(1)) { - fprintf (stderr,_("Will not write an image to the terminal!\n")); - return 1; - } -#if defined(WIN32) || defined(DJGPP) || defined(__CYGWIN__) - if (setmode(1,O_BINARY) < 0) { - perror ("setmode()"); - return 1; - } -#endif - } - for ( ; arg < argc; arg++) { - status = 1; - raw_image = 0; - image = 0; - oprof = 0; - meta_data = ofname = 0; - ofp = stdout; - if (setjmp (failure)) { - if (fileno(ifp) > 2) fclose(ifp); - if (fileno(ofp) > 2) fclose(ofp); - status = 1; - goto cleanup; - } - ifname = argv[arg]; - if (!(ifp = fopen (ifname, "rb"))) { - perror (ifname); - continue; - } - status = (identify(),!is_raw); - if (user_flip >= 0) - flip = user_flip; - switch ((flip+3600) % 360) { - case 270: flip = 5; break; - case 180: flip = 3; break; - case 90: flip = 6; - } - if (timestamp_only) { - if ((status = !timestamp)) - fprintf (stderr,_("%s has no timestamp.\n"), ifname); - else if (identify_only) - printf ("%10ld%10d %s\n", (long) timestamp, shot_order, ifname); - else { - if (verbose) - fprintf (stderr,_("%s time set to %d.\n"), ifname, (int) timestamp); - ut.actime = ut.modtime = timestamp; - utime (ifname, &ut); - } - goto next; - } - write_fun = &CLASS write_ppm_tiff; - if (thumbnail_only) { - if ((status = !thumb_offset)) { - fprintf (stderr,_("%s has no thumbnail.\n"), ifname); - goto next; - } else if (thumb_load_raw) { - load_raw = thumb_load_raw; - data_offset = thumb_offset; - height = thumb_height; - width = thumb_width; - filters = 0; - } else { - fseek (ifp, thumb_offset, SEEK_SET); - write_fun = write_thumb; - goto thumbnail; - } - } - if (load_raw == &CLASS kodak_ycbcr_load_raw) { - height += height & 1; - width += width & 1; - } - if (identify_only && verbose && make[0]) { - printf (_("\nFilename: %s\n"), ifname); - printf (_("Timestamp: %s"), ctime(×tamp)); - printf (_("Camera: %s %s\n"), make, model); - if (artist[0]) - printf (_("Owner: %s\n"), artist); - if (dng_version) { - printf (_("DNG Version: ")); - for (i=24; i >= 0; i -= 8) - printf ("%d%c", dng_version >> i & 255, i ? '.':'\n'); - } - printf (_("ISO speed: %d\n"), (int) iso_speed); - printf (_("Shutter: ")); - if (shutter > 0 && shutter < 1) - shutter = (printf ("1/"), 1 / shutter); - printf (_("%0.1f sec\n"), shutter); - printf (_("Aperture: f/%0.1f\n"), aperture); - printf (_("Focal length: %0.1f mm\n"), focal_len); - printf (_("Embedded ICC profile: %s\n"), profile_length ? _("yes"):_("no")); - printf (_("Number of raw images: %d\n"), is_raw); - if (pixel_aspect != 1) - printf (_("Pixel Aspect Ratio: %0.6f\n"), pixel_aspect); - if (thumb_offset) - printf (_("Thumb size: %4d x %d\n"), thumb_width, thumb_height); - printf (_("Full size: %4d x %d\n"), raw_width, raw_height); - } else if (!is_raw) - fprintf (stderr,_("Cannot decode file %s\n"), ifname); - if (!is_raw) goto next; - shrink = filters && (half_size || (!identify_only && - (threshold || aber[0] != 1 || aber[2] != 1))); - if (document_mode == 3) { - top_margin = left_margin = fuji_width = 0; - height = raw_height; - if (width <= raw_width * 8 / tiff_bps) - width = raw_width * 8 / tiff_bps; - else width = raw_width; - } - iheight = (height + shrink) >> shrink; - iwidth = (width + shrink) >> shrink; - if (identify_only) { - if (verbose) { - if (use_fuji_rotate) { - if (fuji_width) { - fuji_width = (fuji_width - 1 + shrink) >> shrink; - iwidth = fuji_width / sqrt(0.5); - iheight = (iheight - fuji_width) / sqrt(0.5); - } else { - if (pixel_aspect < 1) iheight = iheight / pixel_aspect + 0.5; - if (pixel_aspect > 1) iwidth = iwidth * pixel_aspect + 0.5; - } - } - if (flip & 4) - SWAP(iheight,iwidth); - printf (_("Image size: %4d x %d\n"), width, height); - printf (_("Output size: %4d x %d\n"), iwidth, iheight); - printf (_("Raw colors: %d"), colors); - if (filters) { - printf (_("\nFilter pattern: ")); - for (i=0; i < 16; i++) - putchar (cdesc[fcol(i >> 1,i & 1)]); - } - printf (_("\nDaylight multipliers:")); - FORCC printf (" %f", pre_mul[c]); - if (cam_mul[0] > 0) { - printf (_("\nCamera multipliers:")); - FORC4 printf (" %f", cam_mul[c]); - } - putchar ('\n'); - } else - printf (_("%s is a %s %s image.\n"), ifname, make, model); -next: - fclose(ifp); - continue; - } - if (use_camera_matrix && cmatrix[0][0] > 0.25) { - memcpy (rgb_cam, cmatrix, sizeof cmatrix); - raw_color = 0; - } - image = (ushort (*)[4]) calloc (iheight*iwidth, sizeof *image); - merror (image, "main()"); - if (meta_length) { - meta_data = (char *) malloc (meta_length); - merror (meta_data, "main()"); - } - if (filters || colors == 1) { - raw_image = (ushort *) calloc ((raw_height+7)*raw_width, 2); - merror (raw_image, "main()"); - } - if (verbose) - fprintf (stderr,_("Loading %s %s image from %s ...\n"), - make, model, ifname); - if (shot_select >= is_raw) - fprintf (stderr,_("%s: \"-s %d\" requests a nonexistent image!\n"), - ifname, shot_select); - fseeko (ifp, data_offset, SEEK_SET); - if (raw_image && read_from_stdin) - fread (raw_image, 2, raw_height*raw_width, stdin); - else (*load_raw)(); - if (raw_image) { - crop_masked_pixels(); - free (raw_image); - } - if (zero_is_bad) remove_zeroes(); - bad_pixels (bpfile); - if (dark_frame) subtract (dark_frame); - quality = 2 + !fuji_width; - if (user_qual >= 0) quality = user_qual; - i = cblack[3]; - FORC3 if (i > cblack[c]) i = cblack[c]; - FORC4 cblack[c] -= i; - black += i; - if (user_black >= 0) black = user_black; - FORC4 cblack[c] += black; - if (user_sat > 0) maximum = user_sat; -#ifdef COLORCHECK - colorcheck(); -#endif - if (is_foveon) { - if (document_mode || model[0] == 'D') { - for (i=0; i < height*width*4; i++) - if ((short) image[0][i] < 0) image[0][i] = 0; - } else foveon_interpolate(); - } else if (document_mode < 2) - scale_colors(); - pre_interpolate(); - if (filters && !document_mode) { - if (quality == 0) - lin_interpolate(); - else if (quality == 1 || colors > 3 || filters < 1000) - vng_interpolate(); - else if (quality == 2) - ppg_interpolate(); - else ahd_interpolate(); - } - if (mix_green) - for (colors=3, i=0; i < height*width; i++) - image[i][1] = (image[i][1] + image[i][3]) >> 1; - if (!is_foveon && colors == 3) median_filter(); - if (!is_foveon && highlight == 2) blend_highlights(); - if (!is_foveon && highlight > 2) recover_highlights(); - if (use_fuji_rotate) fuji_rotate(); -#ifndef NO_LCMS - if (cam_profile) apply_profile (cam_profile, out_profile); -#endif - convert_to_rgb(); - if (use_fuji_rotate) stretch(); -thumbnail: - if (write_fun == &CLASS jpeg_thumb) - write_ext = ".jpg"; - else if (output_tiff && write_fun == &CLASS write_ppm_tiff) - write_ext = ".tiff"; - else - write_ext = ".pgm\0.ppm\0.ppm\0.pam" + colors*5-5; - ofname = (char *) malloc (strlen(ifname) + 64); - merror (ofname, "main()"); - if (write_to_stdout) - strcpy (ofname,_("standard output")); - else { - strcpy (ofname, ifname); - if ((cp = strrchr (ofname, '.'))) *cp = 0; - if (multi_out) - sprintf (ofname+strlen(ofname), "_%0*d", - snprintf(0,0,"%d",is_raw-1), shot_select); - if (thumbnail_only) - strcat (ofname, ".thumb"); - strcat (ofname, write_ext); - ofp = fopen (ofname, "wb"); - if (!ofp) { - status = 1; - perror (ofname); - goto cleanup; - } - } - if (verbose) - fprintf (stderr,_("Writing data to %s ...\n"), ofname); - (*write_fun)(); - fclose(ifp); - if (ofp != stdout) fclose(ofp); -cleanup: - if (meta_data) free (meta_data); - if (ofname) free (ofname); - if (oprof) free (oprof); - if (image) free (image); - if (multi_out) { - if (++shot_select < is_raw) arg--; - else shot_select = 0; - } - } - return status; -} +/* + dcraw.c -- Dave Coffin's raw photo decoder + Copyright 1997-2012 by Dave Coffin, dcoffin a cybercom o net + + This is a command-line ANSI C program to convert raw photos from + any digital camera on any computer running any operating system. + + No license is required to download and use dcraw.c. However, + to lawfully redistribute dcraw, you must either (a) offer, at + no extra charge, full source code* for all executable files + containing RESTRICTED functions, (b) distribute this code under + the GPL Version 2 or later, (c) remove all RESTRICTED functions, + re-implement them, or copy them from an earlier, unrestricted + Revision of dcraw.c, or (d) purchase a license from the author. + + The functions that process Foveon images have been RESTRICTED + since Revision 1.237. All other code remains free for all uses. + + *If you have not modified dcraw.c in any way, a link to my + homepage qualifies as "full source code". + + $Revision: 1.31 $ + $Date: 2012/07/15 12:44:06 $ + */ + +#define DCRAW_VERSION "9.15" + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#define _USE_MATH_DEFINES +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef NODEPS +#define NO_JASPER +#define NO_JPEG +#define NO_LCMS +#endif +#ifndef NO_JASPER +#include /* Decode RED camera movies */ +#endif +#ifndef NO_JPEG +#include /* Decode compressed Kodak DC120 photos */ +#endif /* and Adobe Lossy DNGs */ +#ifndef NO_LCMS +#include /* Support color profiles */ +#endif +#ifdef LOCALEDIR +#include +#define _(String) gettext(String) +#else +#define _(String) (String) +#endif + +#if defined(DJGPP) || defined(__MINGW32__) +#define fseeko fseek +#define ftello ftell +#else +#define fgetc getc_unlocked +#endif +#ifdef __CYGWIN__ +#include +#endif +#ifdef WIN32 +#include +#include +#pragma comment(lib, "ws2_32.lib") +#define snprintf _snprintf +#define strcasecmp stricmp +#define strncasecmp strnicmp +typedef __int64 INT64; +typedef unsigned __int64 UINT64; +#else +#include +#include +#include +typedef long long INT64; +typedef unsigned long long UINT64; +#endif + +#ifdef LJPEG_DECODE +#error Please compile dcraw.c by itself. +#error Do not link it with ljpeg_decode. +#endif + +#ifndef LONG_BIT +#define LONG_BIT (8 * sizeof (long)) +#endif + +#if !defined(uchar) +#define uchar unsigned char +#endif +#if !defined(ushort) +#define ushort unsigned short +#endif + +/* + All global variables are defined here, and all functions that + access them are prefixed with "CLASS". Note that a thread-safe + C++ class cannot have non-const static local variables. + */ +FILE *ifp, *ofp; +short order; +const char *ifname; +char *meta_data; +char cdesc[5], desc[512], make[64], model[64], model2[64], artist[64]; +float flash_used, canon_ev, iso_speed, shutter, aperture, focal_len; +time_t timestamp; +unsigned shot_order, kodak_cbpp, filters, exif_cfa, unique_id; +off_t strip_offset, data_offset; +off_t thumb_offset, meta_offset, profile_offset; +unsigned thumb_length, meta_length, profile_length; +unsigned thumb_misc, *oprof, fuji_layout, shot_select=0, multi_out=0; +unsigned tiff_nifds, tiff_samples, tiff_bps, tiff_compress; +unsigned black, cblack[4], maximum, mix_green, raw_color, zero_is_bad; +unsigned zero_after_ff, is_raw, dng_version, is_foveon, data_error; +unsigned tile_width, tile_length, gpsdata[32], load_flags; +ushort raw_height, raw_width, height, width, top_margin, left_margin; +ushort shrink, iheight, iwidth, fuji_width, thumb_width, thumb_height; +ushort *raw_image, (*image)[4]; +ushort white[8][8], curve[0x10000], cr2_slice[3], sraw_mul[4]; +int mask[8][4], flip, tiff_flip, colors; +double pixel_aspect, aber[4]={1,1,1,1}, gamm[6]={ 0.45,4.5,0,0,0,0 }; +float bright=1, user_mul[4]={0,0,0,0}, threshold=0; +int half_size=0, four_color_rgb=0, document_mode=0, highlight=0; +int verbose=0, use_auto_wb=0, use_camera_wb=0, use_camera_matrix=-1; +int output_color=1, output_bps=8, output_tiff=0, med_passes=0; +int no_auto_bright=0; +unsigned greybox[4] = { 0, 0, UINT_MAX, UINT_MAX }; +float cam_mul[4], pre_mul[4], cmatrix[3][4], rgb_cam[3][4]; +const double xyz_rgb[3][3] = { /* XYZ from RGB */ + { 0.412453, 0.357580, 0.180423 }, + { 0.212671, 0.715160, 0.072169 }, + { 0.019334, 0.119193, 0.950227 } }; +const float d65_white[3] = { 0.950456, 1, 1.088754 }; +int histogram[4][0x2000]; +void (*write_thumb)(), (*write_fun)(); +void (*load_raw)(), (*thumb_load_raw)(); +jmp_buf failure; + +struct decode { + struct decode *branch[2]; + int leaf; +} first_decode[2048], *second_decode, *free_decode; + +struct tiff_ifd { + int width, height, bps, comp, phint, offset, flip, samples, bytes; + int tile_width, tile_length; +} tiff_ifd[10]; + +struct ph1 { + int format, key_off, black, black_off, split_col, tag_21a; + float tag_210; +} ph1; + +#define CLASS + +#define FORC(cnt) for (c=0; c < cnt; c++) +#define FORC3 FORC(3) +#define FORC4 FORC(4) +#define FORCC FORC(colors) + +#define SQR(x) ((x)*(x)) +#define ABS(x) (((int)(x) ^ ((int)(x) >> 31)) - ((int)(x) >> 31)) +#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#define MAX(a,b) ((a) > (b) ? (a) : (b)) +#define LIM(x,min,max) MAX(min,MIN(x,max)) +#define ULIM(x,y,z) ((y) < (z) ? LIM(x,y,z) : LIM(x,z,y)) +#define CLIP(x) LIM(x,0,65535) +#define SWAP(a,b) { a=a+b; b=a-b; a=a-b; } + +/* + In order to inline this calculation, I make the risky + assumption that all filter patterns can be described + by a repeating pattern of eight rows and two columns + + Do not use the FC or BAYER macros with the Leaf CatchLight, + because its pattern is 16x16, not 2x8. + + Return values are either 0/1/2/3 = G/M/C/Y or 0/1/2/3 = R/G1/B/G2 + + PowerShot 600 PowerShot A50 PowerShot Pro70 Pro90 & G1 + 0xe1e4e1e4: 0x1b4e4b1e: 0x1e4b4e1b: 0xb4b4b4b4: + + 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 + 0 G M G M G M 0 C Y C Y C Y 0 Y C Y C Y C 0 G M G M G M + 1 C Y C Y C Y 1 M G M G M G 1 M G M G M G 1 Y C Y C Y C + 2 M G M G M G 2 Y C Y C Y C 2 C Y C Y C Y + 3 C Y C Y C Y 3 G M G M G M 3 G M G M G M + 4 C Y C Y C Y 4 Y C Y C Y C + PowerShot A5 5 G M G M G M 5 G M G M G M + 0x1e4e1e4e: 6 Y C Y C Y C 6 C Y C Y C Y + 7 M G M G M G 7 M G M G M G + 0 1 2 3 4 5 + 0 C Y C Y C Y + 1 G M G M G M + 2 C Y C Y C Y + 3 M G M G M G + + All RGB cameras use one of these Bayer grids: + + 0x16161616: 0x61616161: 0x49494949: 0x94949494: + + 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 + 0 B G B G B G 0 G R G R G R 0 G B G B G B 0 R G R G R G + 1 G R G R G R 1 B G B G B G 1 R G R G R G 1 G B G B G B + 2 B G B G B G 2 G R G R G R 2 G B G B G B 2 R G R G R G + 3 G R G R G R 3 B G B G B G 3 R G R G R G 3 G B G B G B + */ + +#define RAW(row,col) \ + raw_image[(row)*raw_width+(col)] + +#define FC(row,col) \ + (filters >> ((((row) << 1 & 14) + ((col) & 1)) << 1) & 3) + +#define BAYER(row,col) \ + image[((row) >> shrink)*iwidth + ((col) >> shrink)][FC(row,col)] + +#define BAYER2(row,col) \ + image[((row) >> shrink)*iwidth + ((col) >> shrink)][fcol(row,col)] + +int CLASS fcol (int row, int col) +{ + static const char filter[16][16] = + { { 2,1,1,3,2,3,2,0,3,2,3,0,1,2,1,0 }, + { 0,3,0,2,0,1,3,1,0,1,1,2,0,3,3,2 }, + { 2,3,3,2,3,1,1,3,3,1,2,1,2,0,0,3 }, + { 0,1,0,1,0,2,0,2,2,0,3,0,1,3,2,1 }, + { 3,1,1,2,0,1,0,2,1,3,1,3,0,1,3,0 }, + { 2,0,0,3,3,2,3,1,2,0,2,0,3,2,2,1 }, + { 2,3,3,1,2,1,2,1,2,1,1,2,3,0,0,1 }, + { 1,0,0,2,3,0,0,3,0,3,0,3,2,1,2,3 }, + { 2,3,3,1,1,2,1,0,3,2,3,0,2,3,1,3 }, + { 1,0,2,0,3,0,3,2,0,1,1,2,0,1,0,2 }, + { 0,1,1,3,3,2,2,1,1,3,3,0,2,1,3,2 }, + { 2,3,2,0,0,1,3,0,2,0,1,2,3,0,1,0 }, + { 1,3,1,2,3,2,3,2,0,2,0,1,1,0,3,0 }, + { 0,2,0,3,1,0,0,1,1,3,3,2,3,2,2,1 }, + { 2,1,3,2,3,1,2,1,0,3,0,2,0,2,0,2 }, + { 0,3,1,0,0,2,0,3,2,1,3,1,1,3,1,3 } }; + static const char filter2[6][6] = + { { 1,1,0,1,1,2 }, + { 1,1,2,1,1,0 }, + { 2,0,1,0,2,1 }, + { 1,1,2,1,1,0 }, + { 1,1,0,1,1,2 }, + { 0,2,1,2,0,1 } }; + + if (filters == 1) return filter[(row+top_margin)&15][(col+left_margin)&15]; + if (filters == 2) return filter2[(row+6) % 6][(col+6) % 6]; + return FC(row,col); +} + +#ifndef __GLIBC__ +char *my_memmem (char *haystack, size_t haystacklen, + char *needle, size_t needlelen) +{ + char *c; + for (c = haystack; c <= haystack + haystacklen - needlelen; c++) + if (!memcmp (c, needle, needlelen)) + return c; + return 0; +} +#define memmem my_memmem +#endif + +void CLASS merror (void *ptr, const char *where) +{ + if (ptr) return; + fprintf (stderr,_("%s: Out of memory in %s\n"), ifname, where); + longjmp (failure, 1); +} + +void CLASS derror() +{ + if (!data_error) { + fprintf (stderr, "%s: ", ifname); + if (feof(ifp)) + fprintf (stderr,_("Unexpected end of file\n")); + else + fprintf (stderr,_("Corrupt data near 0x%llx\n"), (INT64) ftello(ifp)); + } + data_error++; +} + +ushort CLASS sget2 (uchar *s) +{ + if (order == 0x4949) /* "II" means little-endian */ + return s[0] | s[1] << 8; + else /* "MM" means big-endian */ + return s[0] << 8 | s[1]; +} + +ushort CLASS get2() +{ + uchar str[2] = { 0xff,0xff }; + fread (str, 1, 2, ifp); + return sget2(str); +} + +unsigned CLASS sget4 (uchar *s) +{ + if (order == 0x4949) + return s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24; + else + return s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]; +} +#define sget4(s) sget4((uchar *)s) + +unsigned CLASS get4() +{ + uchar str[4] = { 0xff,0xff,0xff,0xff }; + fread (str, 1, 4, ifp); + return sget4(str); +} + +unsigned CLASS getint (int type) +{ + return type == 3 ? get2() : get4(); +} + +float CLASS int_to_float (int i) +{ + union { int i; float f; } u; + u.i = i; + return u.f; +} + +double CLASS getreal (int type) +{ + union { char c[8]; double d; } u; + int i, rev; + + switch (type) { + case 3: return (unsigned short) get2(); + case 4: return (unsigned int) get4(); + case 5: u.d = (unsigned int) get4(); + return u.d / (unsigned int) get4(); + case 8: return (signed short) get2(); + case 9: return (signed int) get4(); + case 10: u.d = (signed int) get4(); + return u.d / (signed int) get4(); + case 11: return int_to_float (get4()); + case 12: + rev = 7 * ((order == 0x4949) == (ntohs(0x1234) == 0x1234)); + for (i=0; i < 8; i++) + u.c[i ^ rev] = fgetc(ifp); + return u.d; + default: return fgetc(ifp); + } +} + +void CLASS read_shorts (ushort *pixel, int count) +{ + if (fread (pixel, 2, count, ifp) < count) derror(); + if ((order == 0x4949) == (ntohs(0x1234) == 0x1234)) + swab (pixel, pixel, count*2); +} + +void CLASS canon_600_fixed_wb (int temp) +{ + static const short mul[4][5] = { + { 667, 358,397,565,452 }, + { 731, 390,367,499,517 }, + { 1119, 396,348,448,537 }, + { 1399, 485,431,508,688 } }; + int lo, hi, i; + float frac=0; + + for (lo=4; --lo; ) + if (*mul[lo] <= temp) break; + for (hi=0; hi < 3; hi++) + if (*mul[hi] >= temp) break; + if (lo != hi) + frac = (float) (temp - *mul[lo]) / (*mul[hi] - *mul[lo]); + for (i=1; i < 5; i++) + pre_mul[i-1] = 1 / (frac * mul[hi][i] + (1-frac) * mul[lo][i]); +} + +/* Return values: 0 = white 1 = near white 2 = not white */ +int CLASS canon_600_color (int ratio[2], int mar) +{ + int clipped=0, target, miss; + + if (flash_used) { + if (ratio[1] < -104) + { ratio[1] = -104; clipped = 1; } + if (ratio[1] > 12) + { ratio[1] = 12; clipped = 1; } + } else { + if (ratio[1] < -264 || ratio[1] > 461) return 2; + if (ratio[1] < -50) + { ratio[1] = -50; clipped = 1; } + if (ratio[1] > 307) + { ratio[1] = 307; clipped = 1; } + } + target = flash_used || ratio[1] < 197 + ? -38 - (398 * ratio[1] >> 10) + : -123 + (48 * ratio[1] >> 10); + if (target - mar <= ratio[0] && + target + 20 >= ratio[0] && !clipped) return 0; + miss = target - ratio[0]; + if (abs(miss) >= mar*4) return 2; + if (miss < -20) miss = -20; + if (miss > mar) miss = mar; + ratio[0] = target - miss; + return 1; +} + +void CLASS canon_600_auto_wb() +{ + int mar, row, col, i, j, st, count[] = { 0,0 }; + int test[8], total[2][8], ratio[2][2], stat[2]; + + memset (&total, 0, sizeof total); + i = canon_ev + 0.5; + if (i < 10) mar = 150; + else if (i > 12) mar = 20; + else mar = 280 - 20 * i; + if (flash_used) mar = 80; + for (row=14; row < height-14; row+=4) + for (col=10; col < width; col+=2) { + for (i=0; i < 8; i++) + test[(i & 4) + FC(row+(i >> 1),col+(i & 1))] = + BAYER(row+(i >> 1),col+(i & 1)); + for (i=0; i < 8; i++) + if (test[i] < 150 || test[i] > 1500) goto next; + for (i=0; i < 4; i++) + if (abs(test[i] - test[i+4]) > 50) goto next; + for (i=0; i < 2; i++) { + for (j=0; j < 4; j+=2) + ratio[i][j >> 1] = ((test[i*4+j+1]-test[i*4+j]) << 10) / test[i*4+j]; + stat[i] = canon_600_color (ratio[i], mar); + } + if ((st = stat[0] | stat[1]) > 1) goto next; + for (i=0; i < 2; i++) + if (stat[i]) + for (j=0; j < 2; j++) + test[i*4+j*2+1] = test[i*4+j*2] * (0x400 + ratio[i][j]) >> 10; + for (i=0; i < 8; i++) + total[st][i] += test[i]; + count[st]++; +next: ; + } + if (count[0] | count[1]) { + st = count[0]*200 < count[1]; + for (i=0; i < 4; i++) + pre_mul[i] = 1.0 / (total[st][i] + total[st][i+4]); + } +} + +void CLASS canon_600_coeff() +{ + static const short table[6][12] = { + { -190,702,-1878,2390, 1861,-1349,905,-393, -432,944,2617,-2105 }, + { -1203,1715,-1136,1648, 1388,-876,267,245, -1641,2153,3921,-3409 }, + { -615,1127,-1563,2075, 1437,-925,509,3, -756,1268,2519,-2007 }, + { -190,702,-1886,2398, 2153,-1641,763,-251, -452,964,3040,-2528 }, + { -190,702,-1878,2390, 1861,-1349,905,-393, -432,944,2617,-2105 }, + { -807,1319,-1785,2297, 1388,-876,769,-257, -230,742,2067,-1555 } }; + int t=0, i, c; + float mc, yc; + + mc = pre_mul[1] / pre_mul[2]; + yc = pre_mul[3] / pre_mul[2]; + if (mc > 1 && mc <= 1.28 && yc < 0.8789) t=1; + if (mc > 1.28 && mc <= 2) { + if (yc < 0.8789) t=3; + else if (yc <= 2) t=4; + } + if (flash_used) t=5; + for (raw_color = i=0; i < 3; i++) + FORCC rgb_cam[i][c] = table[t][i*4 + c] / 1024.0; +} + +void CLASS canon_600_load_raw() +{ + uchar data[1120], *dp; + ushort *pix; + int irow, row; + + for (irow=row=0; irow < height; irow++) { + if (fread (data, 1, 1120, ifp) < 1120) derror(); + pix = raw_image + row*raw_width; + for (dp=data; dp < data+1120; dp+=10, pix+=8) { + pix[0] = (dp[0] << 2) + (dp[1] >> 6 ); + pix[1] = (dp[2] << 2) + (dp[1] >> 4 & 3); + pix[2] = (dp[3] << 2) + (dp[1] >> 2 & 3); + pix[3] = (dp[4] << 2) + (dp[1] & 3); + pix[4] = (dp[5] << 2) + (dp[9] & 3); + pix[5] = (dp[6] << 2) + (dp[9] >> 2 & 3); + pix[6] = (dp[7] << 2) + (dp[9] >> 4 & 3); + pix[7] = (dp[8] << 2) + (dp[9] >> 6 ); + } + if ((row+=2) > height) row = 1; + } +} + +void CLASS canon_600_correct() +{ + int row, col, val; + static const short mul[4][2] = + { { 1141,1145 }, { 1128,1109 }, { 1178,1149 }, { 1128,1109 } }; + + for (row=0; row < height; row++) + for (col=0; col < width; col++) { + if ((val = BAYER(row,col) - black) < 0) val = 0; + val = val * mul[row & 3][col & 1] >> 9; + BAYER(row,col) = val; + } + canon_600_fixed_wb(1311); + canon_600_auto_wb(); + canon_600_coeff(); + maximum = (0x3ff - black) * 1109 >> 9; + black = 0; +} + +int CLASS canon_s2is() +{ + unsigned row; + + for (row=0; row < 100; row++) { + fseek (ifp, row*3340 + 3284, SEEK_SET); + if (getc(ifp) > 15) return 1; + } + return 0; +} + +/* + getbits(-1) initializes the buffer + getbits(n) where 0 <= n <= 25 returns an n-bit integer + */ +unsigned CLASS getbithuff (int nbits, ushort *huff) +{ + static unsigned bitbuf=0; + static int vbits=0, reset=0; + unsigned c; + + if (nbits == -1) + return bitbuf = vbits = reset = 0; + if (nbits == 0 || vbits < 0) return 0; + while (!reset && vbits < nbits && (c = fgetc(ifp)) != EOF && + !(reset = zero_after_ff && c == 0xff && fgetc(ifp))) { + bitbuf = (bitbuf << 8) + (uchar) c; + vbits += 8; + } + c = bitbuf << (32-vbits) >> (32-nbits); + if (huff) { + vbits -= huff[c] >> 8; + c = (uchar) huff[c]; + } else + vbits -= nbits; + if (vbits < 0) derror(); + return c; +} + +#define getbits(n) getbithuff(n,0) +#define gethuff(h) getbithuff(*h,h+1) + +/* + Construct a decode tree according the specification in *source. + The first 16 bytes specify how many codes should be 1-bit, 2-bit + 3-bit, etc. Bytes after that are the leaf values. + + For example, if the source is + + { 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0, + 0x04,0x03,0x05,0x06,0x02,0x07,0x01,0x08,0x09,0x00,0x0a,0x0b,0xff }, + + then the code is + + 00 0x04 + 010 0x03 + 011 0x05 + 100 0x06 + 101 0x02 + 1100 0x07 + 1101 0x01 + 11100 0x08 + 11101 0x09 + 11110 0x00 + 111110 0x0a + 1111110 0x0b + 1111111 0xff + */ +ushort * CLASS make_decoder_ref (const uchar **source) +{ + int max, len, h, i, j; + const uchar *count; + ushort *huff; + + count = (*source += 16) - 17; + for (max=16; max && !count[max]; max--); + huff = (ushort *) calloc (1 + (1 << max), sizeof *huff); + merror (huff, "make_decoder()"); + huff[0] = max; + for (h=len=1; len <= max; len++) + for (i=0; i < count[len]; i++, ++*source) + for (j=0; j < 1 << (max-len); j++) + if (h <= 1 << max) + huff[h++] = len << 8 | **source; + return huff; +} + +ushort * CLASS make_decoder (const uchar *source) +{ + return make_decoder_ref (&source); +} + +void CLASS crw_init_tables (unsigned table, ushort *huff[2]) +{ + static const uchar first_tree[3][29] = { + { 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0, + 0x04,0x03,0x05,0x06,0x02,0x07,0x01,0x08,0x09,0x00,0x0a,0x0b,0xff }, + { 0,2,2,3,1,1,1,1,2,0,0,0,0,0,0,0, + 0x03,0x02,0x04,0x01,0x05,0x00,0x06,0x07,0x09,0x08,0x0a,0x0b,0xff }, + { 0,0,6,3,1,1,2,0,0,0,0,0,0,0,0,0, + 0x06,0x05,0x07,0x04,0x08,0x03,0x09,0x02,0x00,0x0a,0x01,0x0b,0xff }, + }; + static const uchar second_tree[3][180] = { + { 0,2,2,2,1,4,2,1,2,5,1,1,0,0,0,139, + 0x03,0x04,0x02,0x05,0x01,0x06,0x07,0x08, + 0x12,0x13,0x11,0x14,0x09,0x15,0x22,0x00,0x21,0x16,0x0a,0xf0, + 0x23,0x17,0x24,0x31,0x32,0x18,0x19,0x33,0x25,0x41,0x34,0x42, + 0x35,0x51,0x36,0x37,0x38,0x29,0x79,0x26,0x1a,0x39,0x56,0x57, + 0x28,0x27,0x52,0x55,0x58,0x43,0x76,0x59,0x77,0x54,0x61,0xf9, + 0x71,0x78,0x75,0x96,0x97,0x49,0xb7,0x53,0xd7,0x74,0xb6,0x98, + 0x47,0x48,0x95,0x69,0x99,0x91,0xfa,0xb8,0x68,0xb5,0xb9,0xd6, + 0xf7,0xd8,0x67,0x46,0x45,0x94,0x89,0xf8,0x81,0xd5,0xf6,0xb4, + 0x88,0xb1,0x2a,0x44,0x72,0xd9,0x87,0x66,0xd4,0xf5,0x3a,0xa7, + 0x73,0xa9,0xa8,0x86,0x62,0xc7,0x65,0xc8,0xc9,0xa1,0xf4,0xd1, + 0xe9,0x5a,0x92,0x85,0xa6,0xe7,0x93,0xe8,0xc1,0xc6,0x7a,0x64, + 0xe1,0x4a,0x6a,0xe6,0xb3,0xf1,0xd3,0xa5,0x8a,0xb2,0x9a,0xba, + 0x84,0xa4,0x63,0xe5,0xc5,0xf3,0xd2,0xc4,0x82,0xaa,0xda,0xe4, + 0xf2,0xca,0x83,0xa3,0xa2,0xc3,0xea,0xc2,0xe2,0xe3,0xff,0xff }, + { 0,2,2,1,4,1,4,1,3,3,1,0,0,0,0,140, + 0x02,0x03,0x01,0x04,0x05,0x12,0x11,0x06, + 0x13,0x07,0x08,0x14,0x22,0x09,0x21,0x00,0x23,0x15,0x31,0x32, + 0x0a,0x16,0xf0,0x24,0x33,0x41,0x42,0x19,0x17,0x25,0x18,0x51, + 0x34,0x43,0x52,0x29,0x35,0x61,0x39,0x71,0x62,0x36,0x53,0x26, + 0x38,0x1a,0x37,0x81,0x27,0x91,0x79,0x55,0x45,0x28,0x72,0x59, + 0xa1,0xb1,0x44,0x69,0x54,0x58,0xd1,0xfa,0x57,0xe1,0xf1,0xb9, + 0x49,0x47,0x63,0x6a,0xf9,0x56,0x46,0xa8,0x2a,0x4a,0x78,0x99, + 0x3a,0x75,0x74,0x86,0x65,0xc1,0x76,0xb6,0x96,0xd6,0x89,0x85, + 0xc9,0xf5,0x95,0xb4,0xc7,0xf7,0x8a,0x97,0xb8,0x73,0xb7,0xd8, + 0xd9,0x87,0xa7,0x7a,0x48,0x82,0x84,0xea,0xf4,0xa6,0xc5,0x5a, + 0x94,0xa4,0xc6,0x92,0xc3,0x68,0xb5,0xc8,0xe4,0xe5,0xe6,0xe9, + 0xa2,0xa3,0xe3,0xc2,0x66,0x67,0x93,0xaa,0xd4,0xd5,0xe7,0xf8, + 0x88,0x9a,0xd7,0x77,0xc4,0x64,0xe2,0x98,0xa5,0xca,0xda,0xe8, + 0xf3,0xf6,0xa9,0xb2,0xb3,0xf2,0xd2,0x83,0xba,0xd3,0xff,0xff }, + { 0,0,6,2,1,3,3,2,5,1,2,2,8,10,0,117, + 0x04,0x05,0x03,0x06,0x02,0x07,0x01,0x08, + 0x09,0x12,0x13,0x14,0x11,0x15,0x0a,0x16,0x17,0xf0,0x00,0x22, + 0x21,0x18,0x23,0x19,0x24,0x32,0x31,0x25,0x33,0x38,0x37,0x34, + 0x35,0x36,0x39,0x79,0x57,0x58,0x59,0x28,0x56,0x78,0x27,0x41, + 0x29,0x77,0x26,0x42,0x76,0x99,0x1a,0x55,0x98,0x97,0xf9,0x48, + 0x54,0x96,0x89,0x47,0xb7,0x49,0xfa,0x75,0x68,0xb6,0x67,0x69, + 0xb9,0xb8,0xd8,0x52,0xd7,0x88,0xb5,0x74,0x51,0x46,0xd9,0xf8, + 0x3a,0xd6,0x87,0x45,0x7a,0x95,0xd5,0xf6,0x86,0xb4,0xa9,0x94, + 0x53,0x2a,0xa8,0x43,0xf5,0xf7,0xd4,0x66,0xa7,0x5a,0x44,0x8a, + 0xc9,0xe8,0xc8,0xe7,0x9a,0x6a,0x73,0x4a,0x61,0xc7,0xf4,0xc6, + 0x65,0xe9,0x72,0xe6,0x71,0x91,0x93,0xa6,0xda,0x92,0x85,0x62, + 0xf3,0xc5,0xb2,0xa4,0x84,0xba,0x64,0xa5,0xb3,0xd2,0x81,0xe5, + 0xd3,0xaa,0xc4,0xca,0xf2,0xb1,0xe4,0xd1,0x83,0x63,0xea,0xc3, + 0xe2,0x82,0xf1,0xa3,0xc2,0xa1,0xc1,0xe3,0xa2,0xe1,0xff,0xff } + }; + if (table > 2) table = 2; + huff[0] = make_decoder ( first_tree[table]); + huff[1] = make_decoder (second_tree[table]); +} + +/* + Return 0 if the image starts with compressed data, + 1 if it starts with uncompressed low-order bits. + + In Canon compressed data, 0xff is always followed by 0x00. + */ +int CLASS canon_has_lowbits() +{ + uchar test[0x4000]; + int ret=1, i; + + fseek (ifp, 0, SEEK_SET); + fread (test, 1, sizeof test, ifp); + for (i=540; i < sizeof test - 1; i++) + if (test[i] == 0xff) { + if (test[i+1]) return 1; + ret=0; + } + return ret; +} + +void CLASS canon_load_raw() +{ + ushort *pixel, *prow, *huff[2]; + int nblocks, lowbits, i, c, row, r, save, val; + int block, diffbuf[64], leaf, len, diff, carry=0, pnum=0, base[2]; + + crw_init_tables (tiff_compress, huff); + lowbits = canon_has_lowbits(); + if (!lowbits) maximum = 0x3ff; + fseek (ifp, 540 + lowbits*raw_height*raw_width/4, SEEK_SET); + zero_after_ff = 1; + getbits(-1); + for (row=0; row < raw_height; row+=8) { + pixel = raw_image + row*raw_width; + nblocks = MIN (8, raw_height-row) * raw_width >> 6; + for (block=0; block < nblocks; block++) { + memset (diffbuf, 0, sizeof diffbuf); + for (i=0; i < 64; i++ ) { + leaf = gethuff(huff[i > 0]); + if (leaf == 0 && i) break; + if (leaf == 0xff) continue; + i += leaf >> 4; + len = leaf & 15; + if (len == 0) continue; + diff = getbits(len); + if ((diff & (1 << (len-1))) == 0) + diff -= (1 << len) - 1; + if (i < 64) diffbuf[i] = diff; + } + diffbuf[0] += carry; + carry = diffbuf[0]; + for (i=0; i < 64; i++ ) { + if (pnum++ % raw_width == 0) + base[0] = base[1] = 512; + if ((pixel[(block << 6) + i] = base[i & 1] += diffbuf[i]) >> 10) + derror(); + } + } + if (lowbits) { + save = ftell(ifp); + fseek (ifp, 26 + row*raw_width/4, SEEK_SET); + for (prow=pixel, i=0; i < raw_width*2; i++) { + c = fgetc(ifp); + for (r=0; r < 8; r+=2, prow++) { + val = (*prow << 2) + ((c >> r) & 3); + if (raw_width == 2672 && val < 512) val += 2; + *prow = val; + } + } + fseek (ifp, save, SEEK_SET); + } + } + FORC(2) free (huff[c]); +} + +/* + Not a full implementation of Lossless JPEG, just + enough to decode Canon, Kodak and Adobe DNG images. + */ +struct jhead { + int bits, high, wide, clrs, sraw, psv, restart, vpred[6]; + ushort *huff[6], *free[4], *row; +}; + +int CLASS ljpeg_start (struct jhead *jh, int info_only) +{ + int c, tag, len; + uchar data[0x10000]; + const uchar *dp; + + memset (jh, 0, sizeof *jh); + jh->restart = INT_MAX; + fread (data, 2, 1, ifp); + if (data[1] != 0xd8) return 0; + do { + fread (data, 2, 2, ifp); + tag = data[0] << 8 | data[1]; + len = (data[2] << 8 | data[3]) - 2; + if (tag <= 0xff00) return 0; + fread (data, 1, len, ifp); + switch (tag) { + case 0xffc3: + jh->sraw = ((data[7] >> 4) * (data[7] & 15) - 1) & 3; + case 0xffc0: + jh->bits = data[0]; + jh->high = data[1] << 8 | data[2]; + jh->wide = data[3] << 8 | data[4]; + jh->clrs = data[5] + jh->sraw; + if (len == 9 && !dng_version) getc(ifp); + break; + case 0xffc4: + if (info_only) break; + for (dp = data; dp < data+len && (c = *dp++) < 4; ) + jh->free[c] = jh->huff[c] = make_decoder_ref (&dp); + break; + case 0xffda: + jh->psv = data[1+data[0]*2]; + jh->bits -= data[3+data[0]*2] & 15; + break; + case 0xffdd: + jh->restart = data[0] << 8 | data[1]; + } + } while (tag != 0xffda); + if (info_only) return 1; + FORC(5) if (!jh->huff[c+1]) jh->huff[c+1] = jh->huff[c]; + if (jh->sraw) { + FORC(4) jh->huff[2+c] = jh->huff[1]; + FORC(jh->sraw) jh->huff[1+c] = jh->huff[0]; + } + jh->row = (ushort *) calloc (jh->wide*jh->clrs, 4); + merror (jh->row, "ljpeg_start()"); + return zero_after_ff = 1; +} + +void CLASS ljpeg_end (struct jhead *jh) +{ + int c; + FORC4 if (jh->free[c]) free (jh->free[c]); + free (jh->row); +} + +int CLASS ljpeg_diff (ushort *huff) +{ + int len, diff; + + len = gethuff(huff); + if (len == 16 && (!dng_version || dng_version >= 0x1010000)) + return -32768; + diff = getbits(len); + if ((diff & (1 << (len-1))) == 0) + diff -= (1 << len) - 1; + return diff; +} + +ushort * CLASS ljpeg_row (int jrow, struct jhead *jh) +{ + int col, c, diff, pred, spred=0; + ushort mark=0, *row[3]; + + if (jrow * jh->wide % jh->restart == 0) { + FORC(6) jh->vpred[c] = 1 << (jh->bits-1); + if (jrow) { + fseek (ifp, -2, SEEK_CUR); + do mark = (mark << 8) + (c = fgetc(ifp)); + while (c != EOF && mark >> 4 != 0xffd); + } + getbits(-1); + } + FORC3 row[c] = jh->row + jh->wide*jh->clrs*((jrow+c) & 1); + for (col=0; col < jh->wide; col++) + FORC(jh->clrs) { + diff = ljpeg_diff (jh->huff[c]); + if (jh->sraw && c <= jh->sraw && (col | c)) + pred = spred; + else if (col) pred = row[0][-jh->clrs]; + else pred = (jh->vpred[c] += diff) - diff; + if (jrow && col) switch (jh->psv) { + case 1: break; + case 2: pred = row[1][0]; break; + case 3: pred = row[1][-jh->clrs]; break; + case 4: pred = pred + row[1][0] - row[1][-jh->clrs]; break; + case 5: pred = pred + ((row[1][0] - row[1][-jh->clrs]) >> 1); break; + case 6: pred = row[1][0] + ((pred - row[1][-jh->clrs]) >> 1); break; + case 7: pred = (pred + row[1][0]) >> 1; break; + default: pred = 0; + } + if ((**row = pred + diff) >> jh->bits) derror(); + if (c <= jh->sraw) spred = **row; + row[0]++; row[1]++; + } + return row[2]; +} + +void CLASS lossless_jpeg_load_raw() +{ + int jwide, jrow, jcol, val, jidx, i, j, row=0, col=0; + struct jhead jh; + ushort *rp; + + if (!ljpeg_start (&jh, 0)) return; + jwide = jh.wide * jh.clrs; + + for (jrow=0; jrow < jh.high; jrow++) { + rp = ljpeg_row (jrow, &jh); + if (load_flags & 1) + row = jrow & 1 ? height-1-jrow/2 : jrow/2; + for (jcol=0; jcol < jwide; jcol++) { + val = curve[*rp++]; + if (cr2_slice[0]) { + jidx = jrow*jwide + jcol; + i = jidx / (cr2_slice[1]*jh.high); + if ((j = i >= cr2_slice[0])) + i = cr2_slice[0]; + jidx -= i * (cr2_slice[1]*jh.high); + row = jidx / cr2_slice[1+j]; + col = jidx % cr2_slice[1+j] + i*cr2_slice[1]; + } + if (raw_width == 3984 && (col -= 2) < 0) + col += (row--,raw_width); + if (row >= 0) RAW(row,col) = val; + if (++col >= raw_width) + col = (row++,0); + } + } + ljpeg_end (&jh); +} + +void CLASS canon_sraw_load_raw() +{ + struct jhead jh; + short *rp=0, (*ip)[4]; + int jwide, slice, scol, ecol, row, col, jrow=0, jcol=0, pix[3], c; + int v[3]={0,0,0}, ver, hue; + char *cp; + + if (!ljpeg_start (&jh, 0)) return; + jwide = (jh.wide >>= 1) * jh.clrs; + + for (ecol=slice=0; slice <= cr2_slice[0]; slice++) { + scol = ecol; + ecol += cr2_slice[1] * 2 / jh.clrs; + if (!cr2_slice[0] || ecol > raw_width-1) ecol = raw_width & -2; + for (row=0; row < height; row += (jh.clrs >> 1) - 1) { + ip = (short (*)[4]) image + row*width; + for (col=scol; col < ecol; col+=2, jcol+=jh.clrs) { + if ((jcol %= jwide) == 0) + rp = (short *) ljpeg_row (jrow++, &jh); + if (col >= width) continue; + FORC (jh.clrs-2) + ip[col + (c >> 1)*width + (c & 1)][0] = rp[jcol+c]; + ip[col][1] = rp[jcol+jh.clrs-2] - 16384; + ip[col][2] = rp[jcol+jh.clrs-1] - 16384; + } + } + } + for (cp=model2; *cp && !isdigit(*cp); cp++); + sscanf (cp, "%d.%d.%d", v, v+1, v+2); + ver = (v[0]*1000 + v[1])*1000 + v[2]; + hue = (jh.sraw+1) << 2; + if (unique_id >= 0x80000281 || (unique_id == 0x80000218 && ver > 1000006)) + hue = jh.sraw << 1; + ip = (short (*)[4]) image; + rp = ip[0]; + for (row=0; row < height; row++, ip+=width) { + if (row & (jh.sraw >> 1)) + for (col=0; col < width; col+=2) + for (c=1; c < 3; c++) + if (row == height-1) + ip[col][c] = ip[col-width][c]; + else ip[col][c] = (ip[col-width][c] + ip[col+width][c] + 1) >> 1; + for (col=1; col < width; col+=2) + for (c=1; c < 3; c++) + if (col == width-1) + ip[col][c] = ip[col-1][c]; + else ip[col][c] = (ip[col-1][c] + ip[col+1][c] + 1) >> 1; + } + for ( ; rp < ip[0]; rp+=4) { + if (unique_id < 0x80000218) { + rp[0] -= 512; + goto next; + } else if (unique_id == 0x80000285) { +next: pix[0] = rp[0] + rp[2]; + pix[2] = rp[0] + rp[1]; + pix[1] = rp[0] + ((-778*rp[1] - (rp[2] << 11)) >> 12); + } else { + rp[1] = (rp[1] << 2) + hue; + rp[2] = (rp[2] << 2) + hue; + pix[0] = rp[0] + (( 50*rp[1] + 22929*rp[2]) >> 14); + pix[1] = rp[0] + ((-5640*rp[1] - 11751*rp[2]) >> 14); + pix[2] = rp[0] + ((29040*rp[1] - 101*rp[2]) >> 14); + } + FORC3 rp[c] = CLIP(pix[c] * sraw_mul[c] >> 10); + } + ljpeg_end (&jh); + maximum = 0x3fff; +} + +void CLASS adobe_copy_pixel (unsigned row, unsigned col, ushort **rp) +{ + int c; + + if (is_raw == 2 && shot_select) (*rp)++; + if (raw_image) { + if (row < raw_height && col < raw_width) + RAW(row,col) = curve[**rp]; + *rp += is_raw; + } else { + if (row < height && col < width) + FORC(tiff_samples) + image[row*width+col][c] = curve[(*rp)[c]]; + *rp += tiff_samples; + } + if (is_raw == 2 && shot_select) (*rp)--; +} + +void CLASS lossless_dng_load_raw() +{ + unsigned save, trow=0, tcol=0, jwide, jrow, jcol, row, col; + struct jhead jh; + ushort *rp; + + while (trow < raw_height) { + save = ftell(ifp); + if (tile_length < INT_MAX) + fseek (ifp, get4(), SEEK_SET); + if (!ljpeg_start (&jh, 0)) break; + jwide = jh.wide; + if (filters) jwide *= jh.clrs; + jwide /= is_raw; + for (row=col=jrow=0; jrow < jh.high; jrow++) { + rp = ljpeg_row (jrow, &jh); + for (jcol=0; jcol < jwide; jcol++) { + adobe_copy_pixel (trow+row, tcol+col, &rp); + if (++col >= tile_width || col >= raw_width) + row += 1 + (col = 0); + } + } + fseek (ifp, save+4, SEEK_SET); + if ((tcol += tile_width) >= raw_width) + trow += tile_length + (tcol = 0); + ljpeg_end (&jh); + } +} + +void CLASS packed_dng_load_raw() +{ + ushort *pixel, *rp; + int row, col; + + pixel = (ushort *) calloc (raw_width * tiff_samples, sizeof *pixel); + merror (pixel, "packed_dng_load_raw()"); + for (row=0; row < raw_height; row++) { + if (tiff_bps == 16) + read_shorts (pixel, raw_width * tiff_samples); + else { + getbits(-1); + for (col=0; col < raw_width * tiff_samples; col++) + pixel[col] = getbits(tiff_bps); + } + for (rp=pixel, col=0; col < raw_width; col++) + adobe_copy_pixel (row, col, &rp); + } + free (pixel); +} + +void CLASS pentax_load_raw() +{ + ushort bit[2][15], huff[4097]; + int dep, row, col, diff, c, i; + ushort vpred[2][2] = {{0,0},{0,0}}, hpred[2]; + + fseek (ifp, meta_offset, SEEK_SET); + dep = (get2() + 12) & 15; + fseek (ifp, 12, SEEK_CUR); + FORC(dep) bit[0][c] = get2(); + FORC(dep) bit[1][c] = fgetc(ifp); + FORC(dep) + for (i=bit[0][c]; i <= ((bit[0][c]+(4096 >> bit[1][c])-1) & 4095); ) + huff[++i] = bit[1][c] << 8 | c; + huff[0] = 12; + fseek (ifp, data_offset, SEEK_SET); + getbits(-1); + for (row=0; row < raw_height; row++) + for (col=0; col < raw_width; col++) { + diff = ljpeg_diff (huff); + if (col < 2) hpred[col] = vpred[row & 1][col] += diff; + else hpred[col & 1] += diff; + RAW(row,col) = hpred[col & 1]; + if (hpred[col & 1] >> tiff_bps) derror(); + } +} + +void CLASS nikon_load_raw() +{ + static const uchar nikon_tree[][32] = { + { 0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0, /* 12-bit lossy */ + 5,4,3,6,2,7,1,0,8,9,11,10,12 }, + { 0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0, /* 12-bit lossy after split */ + 0x39,0x5a,0x38,0x27,0x16,5,4,3,2,1,0,11,12,12 }, + { 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0, /* 12-bit lossless */ + 5,4,6,3,7,2,8,1,9,0,10,11,12 }, + { 0,1,4,3,1,1,1,1,1,2,0,0,0,0,0,0, /* 14-bit lossy */ + 5,6,4,7,8,3,9,2,1,0,10,11,12,13,14 }, + { 0,1,5,1,1,1,1,1,1,1,2,0,0,0,0,0, /* 14-bit lossy after split */ + 8,0x5c,0x4b,0x3a,0x29,7,6,5,4,3,2,1,0,13,14 }, + { 0,1,4,2,2,3,1,2,0,0,0,0,0,0,0,0, /* 14-bit lossless */ + 7,6,8,5,9,4,10,3,11,12,2,0,1,13,14 } }; + ushort *huff, ver0, ver1, vpred[2][2], hpred[2], csize; + int i, min, max, step=0, tree=0, split=0, row, col, len, shl, diff; + + fseek (ifp, meta_offset, SEEK_SET); + ver0 = fgetc(ifp); + ver1 = fgetc(ifp); + if (ver0 == 0x49 || ver1 == 0x58) + fseek (ifp, 2110, SEEK_CUR); + if (ver0 == 0x46) tree = 2; + if (tiff_bps == 14) tree += 3; + read_shorts (vpred[0], 4); + max = 1 << tiff_bps & 0x7fff; + if ((csize = get2()) > 1) + step = max / (csize-1); + if (ver0 == 0x44 && ver1 == 0x20 && step > 0) { + for (i=0; i < csize; i++) + curve[i*step] = get2(); + for (i=0; i < max; i++) + curve[i] = ( curve[i-i%step]*(step-i%step) + + curve[i-i%step+step]*(i%step) ) / step; + fseek (ifp, meta_offset+562, SEEK_SET); + split = get2(); + } else if (ver0 != 0x46 && csize <= 0x4001) + read_shorts (curve, max=csize); + while (curve[max-2] == curve[max-1]) max--; + huff = make_decoder (nikon_tree[tree]); + fseek (ifp, data_offset, SEEK_SET); + getbits(-1); + for (min=row=0; row < height; row++) { + if (split && row == split) { + free (huff); + huff = make_decoder (nikon_tree[tree+1]); + max += (min = 16) << 1; + } + for (col=0; col < raw_width; col++) { + i = gethuff(huff); + len = i & 15; + shl = i >> 4; + diff = ((getbits(len-shl) << 1) + 1) << shl >> 1; + if ((diff & (1 << (len-1))) == 0) + diff -= (1 << len) - !shl; + if (col < 2) hpred[col] = vpred[row & 1][col] += diff; + else hpred[col & 1] += diff; + if ((ushort)(hpred[col & 1] + min) >= max) derror(); + RAW(row,col) = curve[LIM((short)hpred[col & 1],0,0x3fff)]; + } + } + free (huff); +} + +/* + Figure out if a NEF file is compressed. These fancy heuristics + are only needed for the D100, thanks to a bug in some cameras + that tags all images as "compressed". + */ +int CLASS nikon_is_compressed() +{ + uchar test[256]; + int i; + + fseek (ifp, data_offset, SEEK_SET); + fread (test, 1, 256, ifp); + for (i=15; i < 256; i+=16) + if (test[i]) return 1; + return 0; +} + +/* + Returns 1 for a Coolpix 995, 0 for anything else. + */ +int CLASS nikon_e995() +{ + int i, histo[256]; + const uchar often[] = { 0x00, 0x55, 0xaa, 0xff }; + + memset (histo, 0, sizeof histo); + fseek (ifp, -2000, SEEK_END); + for (i=0; i < 2000; i++) + histo[fgetc(ifp)]++; + for (i=0; i < 4; i++) + if (histo[often[i]] < 200) + return 0; + return 1; +} + +/* + Returns 1 for a Coolpix 2100, 0 for anything else. + */ +int CLASS nikon_e2100() +{ + uchar t[12]; + int i; + + fseek (ifp, 0, SEEK_SET); + for (i=0; i < 1024; i++) { + fread (t, 1, 12, ifp); + if (((t[2] & t[4] & t[7] & t[9]) >> 4 + & t[1] & t[6] & t[8] & t[11] & 3) != 3) + return 0; + } + return 1; +} + +void CLASS nikon_3700() +{ + int bits, i; + uchar dp[24]; + static const struct { + int bits; + char make[12], model[15]; + } table[] = { + { 0x00, "PENTAX", "Optio 33WR" }, + { 0x03, "NIKON", "E3200" }, + { 0x32, "NIKON", "E3700" }, + { 0x33, "OLYMPUS", "C740UZ" } }; + + fseek (ifp, 3072, SEEK_SET); + fread (dp, 1, 24, ifp); + bits = (dp[8] & 3) << 4 | (dp[20] & 3); + for (i=0; i < sizeof table / sizeof *table; i++) + if (bits == table[i].bits) { + strcpy (make, table[i].make ); + strcpy (model, table[i].model); + } +} + +/* + Separates a Minolta DiMAGE Z2 from a Nikon E4300. + */ +int CLASS minolta_z2() +{ + int i, nz; + char tail[424]; + + fseek (ifp, -sizeof tail, SEEK_END); + fread (tail, 1, sizeof tail, ifp); + for (nz=i=0; i < sizeof tail; i++) + if (tail[i]) nz++; + return nz > 20; +} + +void CLASS jpeg_thumb(); + +void CLASS ppm_thumb() +{ + char *thumb; + thumb_length = thumb_width*thumb_height*3; + thumb = (char *) malloc (thumb_length); + merror (thumb, "ppm_thumb()"); + fprintf (ofp, "P6\n%d %d\n255\n", thumb_width, thumb_height); + fread (thumb, 1, thumb_length, ifp); + fwrite (thumb, 1, thumb_length, ofp); + free (thumb); +} + +void CLASS ppm16_thumb() +{ + int i; + char *thumb; + thumb_length = thumb_width*thumb_height*3; + thumb = (char *) calloc (thumb_length,2); + merror (thumb, "ppm16_thumb()"); + read_shorts ((ushort *) thumb, thumb_length); + for (i=0; i < thumb_length; i++) + thumb[i] = ((ushort *) thumb)[i] >> 8; + fprintf (ofp, "P6\n%d %d\n255\n", thumb_width, thumb_height); + fwrite (thumb, 1, thumb_length, ofp); + free (thumb); +} + +void CLASS layer_thumb() +{ + int i, c; + char *thumb, map[][4] = { "012","102" }; + + colors = thumb_misc >> 5 & 7; + thumb_length = thumb_width*thumb_height; + thumb = (char *) calloc (colors, thumb_length); + merror (thumb, "layer_thumb()"); + fprintf (ofp, "P%d\n%d %d\n255\n", + 5 + (colors >> 1), thumb_width, thumb_height); + fread (thumb, thumb_length, colors, ifp); + for (i=0; i < thumb_length; i++) + FORCC putc (thumb[i+thumb_length*(map[thumb_misc >> 8][c]-'0')], ofp); + free (thumb); +} + +void CLASS rollei_thumb() +{ + unsigned i; + ushort *thumb; + + thumb_length = thumb_width * thumb_height; + thumb = (ushort *) calloc (thumb_length, 2); + merror (thumb, "rollei_thumb()"); + fprintf (ofp, "P6\n%d %d\n255\n", thumb_width, thumb_height); + read_shorts (thumb, thumb_length); + for (i=0; i < thumb_length; i++) { + putc (thumb[i] << 3, ofp); + putc (thumb[i] >> 5 << 2, ofp); + putc (thumb[i] >> 11 << 3, ofp); + } + free (thumb); +} + +void CLASS rollei_load_raw() +{ + uchar pixel[10]; + unsigned iten=0, isix, i, buffer=0, todo[16]; + + isix = raw_width * raw_height * 5 / 8; + while (fread (pixel, 1, 10, ifp) == 10) { + for (i=0; i < 10; i+=2) { + todo[i] = iten++; + todo[i+1] = pixel[i] << 8 | pixel[i+1]; + buffer = pixel[i] >> 2 | buffer << 6; + } + for ( ; i < 16; i+=2) { + todo[i] = isix++; + todo[i+1] = buffer >> (14-i)*5; + } + for (i=0; i < 16; i+=2) + raw_image[todo[i]] = (todo[i+1] & 0x3ff); + } + maximum = 0x3ff; +} + +int CLASS raw (unsigned row, unsigned col) +{ + return (row < raw_height && col < raw_width) ? RAW(row,col) : 0; +} + +void CLASS phase_one_flat_field (int is_float, int nc) +{ + ushort head[8]; + unsigned wide, y, x, c, rend, cend, row, col; + float *mrow, num, mult[4]; + + read_shorts (head, 8); + wide = head[2] / head[4]; + mrow = (float *) calloc (nc*wide, sizeof *mrow); + merror (mrow, "phase_one_flat_field()"); + for (y=0; y < head[3] / head[5]; y++) { + for (x=0; x < wide; x++) + for (c=0; c < nc; c+=2) { + num = is_float ? getreal(11) : get2()/32768.0; + if (y==0) mrow[c*wide+x] = num; + else mrow[(c+1)*wide+x] = (num - mrow[c*wide+x]) / head[5]; + } + if (y==0) continue; + rend = head[1] + y*head[5]; + for (row = rend-head[5]; row < raw_height && row < rend; row++) { + for (x=1; x < wide; x++) { + for (c=0; c < nc; c+=2) { + mult[c] = mrow[c*wide+x-1]; + mult[c+1] = (mrow[c*wide+x] - mult[c]) / head[4]; + } + cend = head[0] + x*head[4]; + for (col = cend-head[4]; col < raw_width && col < cend; col++) { + c = nc > 2 ? FC(row-top_margin,col-left_margin) : 0; + if (!(c & 1)) { + c = RAW(row,col) * mult[c]; + RAW(row,col) = LIM(c,0,65535); + } + for (c=0; c < nc; c+=2) + mult[c] += mult[c+1]; + } + } + for (x=0; x < wide; x++) + for (c=0; c < nc; c+=2) + mrow[c*wide+x] += mrow[(c+1)*wide+x]; + } + } + free (mrow); +} + +void CLASS phase_one_correct() +{ + unsigned entries, tag, data, save, col, row, type; + int len, i, j, k, cip, val[4], dev[4], sum, max; + int head[9], diff, mindiff=INT_MAX, off_412=0; + static const signed char dir[12][2] = + { {-1,-1}, {-1,1}, {1,-1}, {1,1}, {-2,0}, {0,-2}, {0,2}, {2,0}, + {-2,-2}, {-2,2}, {2,-2}, {2,2} }; + float poly[8], num, cfrac, frac, mult[2], *yval[2]; + ushort *xval[2]; + + if (half_size || !meta_length) return; + if (verbose) fprintf (stderr,_("Phase One correction...\n")); + fseek (ifp, meta_offset, SEEK_SET); + order = get2(); + fseek (ifp, 6, SEEK_CUR); + fseek (ifp, meta_offset+get4(), SEEK_SET); + entries = get4(); get4(); + while (entries--) { + tag = get4(); + len = get4(); + data = get4(); + save = ftell(ifp); + fseek (ifp, meta_offset+data, SEEK_SET); + if (tag == 0x419) { /* Polynomial curve */ + for (get4(), i=0; i < 8; i++) + poly[i] = getreal(11); + poly[3] += (ph1.tag_210 - poly[7]) * poly[6] + 1; + for (i=0; i < 0x10000; i++) { + num = (poly[5]*i + poly[3])*i + poly[1]; + curve[i] = LIM(num,0,65535); + } goto apply; /* apply to right half */ + } else if (tag == 0x41a) { /* Polynomial curve */ + for (i=0; i < 4; i++) + poly[i] = getreal(11); + for (i=0; i < 0x10000; i++) { + for (num=0, j=4; j--; ) + num = num * i + poly[j]; + curve[i] = LIM(num+i,0,65535); + } apply: /* apply to whole image */ + for (row=0; row < raw_height; row++) + for (col = (tag & 1)*ph1.split_col; col < raw_width; col++) + RAW(row,col) = curve[RAW(row,col)]; + } else if (tag == 0x400) { /* Sensor defects */ + while ((len -= 8) >= 0) { + col = get2(); + row = get2(); + type = get2(); get2(); + if (col >= raw_width) continue; + if (type == 131) /* Bad column */ + for (row=0; row < raw_height; row++) + if (FC(row-top_margin,col-left_margin) == 1) { + for (sum=i=0; i < 4; i++) + sum += val[i] = raw (row+dir[i][0], col+dir[i][1]); + for (max=i=0; i < 4; i++) { + dev[i] = abs((val[i] << 2) - sum); + if (dev[max] < dev[i]) max = i; + } + RAW(row,col) = (sum - val[max])/3.0 + 0.5; + } else { + for (sum=0, i=8; i < 12; i++) + sum += raw (row+dir[i][0], col+dir[i][1]); + RAW(row,col) = 0.5 + sum * 0.0732233 + + (raw(row,col-2) + raw(row,col+2)) * 0.3535534; + } + else if (type == 129) { /* Bad pixel */ + if (row >= raw_height) continue; + j = (FC(row-top_margin,col-left_margin) != 1) * 4; + for (sum=0, i=j; i < j+8; i++) + sum += raw (row+dir[i][0], col+dir[i][1]); + RAW(row,col) = (sum + 4) >> 3; + } + } + } else if (tag == 0x401) { /* All-color flat fields */ + phase_one_flat_field (1, 2); + } else if (tag == 0x416 || tag == 0x410) { + phase_one_flat_field (0, 2); + } else if (tag == 0x40b) { /* Red+blue flat field */ + phase_one_flat_field (0, 4); + } else if (tag == 0x412) { + fseek (ifp, 36, SEEK_CUR); + diff = abs (get2() - ph1.tag_21a); + if (mindiff > diff) { + mindiff = diff; + off_412 = ftell(ifp) - 38; + } + } + fseek (ifp, save, SEEK_SET); + } + if (off_412) { + fseek (ifp, off_412, SEEK_SET); + for (i=0; i < 9; i++) head[i] = get4() & 0x7fff; + yval[0] = (float *) calloc (head[1]*head[3] + head[2]*head[4], 6); + merror (yval[0], "phase_one_correct()"); + yval[1] = (float *) (yval[0] + head[1]*head[3]); + xval[0] = (ushort *) (yval[1] + head[2]*head[4]); + xval[1] = (ushort *) (xval[0] + head[1]*head[3]); + get2(); + for (i=0; i < 2; i++) + for (j=0; j < head[i+1]*head[i+3]; j++) + yval[i][j] = getreal(11); + for (i=0; i < 2; i++) + for (j=0; j < head[i+1]*head[i+3]; j++) + xval[i][j] = get2(); + for (row=0; row < raw_height; row++) + for (col=0; col < raw_width; col++) { + cfrac = (float) col * head[3] / raw_width; + cfrac -= cip = cfrac; + num = RAW(row,col) * 0.5; + for (i=cip; i < cip+2; i++) { + for (k=j=0; j < head[1]; j++) + if (num < xval[0][k = head[1]*i+j]) break; + frac = (j == 0 || j == head[1]) ? 0 : + (xval[0][k] - num) / (xval[0][k] - xval[0][k-1]); + mult[i-cip] = yval[0][k-1] * frac + yval[0][k] * (1-frac); + } + i = ((mult[0] * (1-cfrac) + mult[1] * cfrac) * row + num) * 2; + RAW(row,col) = LIM(i,0,65535); + } + free (yval[0]); + } +} + +void CLASS phase_one_load_raw() +{ + int a, b, i; + ushort akey, bkey, mask; + + fseek (ifp, ph1.key_off, SEEK_SET); + akey = get2(); + bkey = get2(); + mask = ph1.format == 1 ? 0x5555:0x1354; + fseek (ifp, data_offset, SEEK_SET); + read_shorts (raw_image, raw_width*raw_height); + if (ph1.format) + for (i=0; i < raw_width*raw_height; i+=2) { + a = raw_image[i+0] ^ akey; + b = raw_image[i+1] ^ bkey; + raw_image[i+0] = (a & mask) | (b & ~mask); + raw_image[i+1] = (b & mask) | (a & ~mask); + } +} + +unsigned CLASS ph1_bithuff (int nbits, ushort *huff) +{ + static UINT64 bitbuf=0; + static int vbits=0; + unsigned c; + + if (nbits == -1) + return bitbuf = vbits = 0; + if (nbits == 0) return 0; + if (vbits < nbits) { + bitbuf = bitbuf << 32 | get4(); + vbits += 32; + } + c = bitbuf << (64-vbits) >> (64-nbits); + if (huff) { + vbits -= huff[c] >> 8; + return (uchar) huff[c]; + } + vbits -= nbits; + return c; +} +#define ph1_bits(n) ph1_bithuff(n,0) +#define ph1_huff(h) ph1_bithuff(*h,h+1) + +void CLASS phase_one_load_raw_c() +{ + static const int length[] = { 8,7,6,9,11,10,5,12,14,13 }; + int *offset, len[2], pred[2], row, col, i, j; + ushort *pixel; + short (*black)[2]; + + pixel = (ushort *) calloc (raw_width + raw_height*4, 2); + merror (pixel, "phase_one_load_raw_c()"); + offset = (int *) (pixel + raw_width); + fseek (ifp, strip_offset, SEEK_SET); + for (row=0; row < raw_height; row++) + offset[row] = get4(); + black = (short (*)[2]) offset + raw_height; + fseek (ifp, ph1.black_off, SEEK_SET); + if (ph1.black_off) + read_shorts ((ushort *) black[0], raw_height*2); + for (i=0; i < 256; i++) + curve[i] = i*i / 3.969 + 0.5; + for (row=0; row < raw_height; row++) { + fseek (ifp, data_offset + offset[row], SEEK_SET); + ph1_bits(-1); + pred[0] = pred[1] = 0; + for (col=0; col < raw_width; col++) { + if (col >= (raw_width & -8)) + len[0] = len[1] = 14; + else if ((col & 7) == 0) + for (i=0; i < 2; i++) { + for (j=0; j < 5 && !ph1_bits(1); j++); + if (j--) len[i] = length[j*2 + ph1_bits(1)]; + } + if ((i = len[col & 1]) == 14) + pixel[col] = pred[col & 1] = ph1_bits(16); + else + pixel[col] = pred[col & 1] += ph1_bits(i) + 1 - (1 << (i - 1)); + if (pred[col & 1] >> 16) derror(); + if (ph1.format == 5 && pixel[col] < 256) + pixel[col] = curve[pixel[col]]; + } + for (col=0; col < raw_width; col++) { + i = (pixel[col] << 2) - ph1.black + black[row][col >= ph1.split_col]; + if (i > 0) RAW(row,col) = i; + } + } + free (pixel); + maximum = 0xfffc - ph1.black; +} + +void CLASS hasselblad_load_raw() +{ + struct jhead jh; + int row, col, pred[2], len[2], diff, c; + + if (!ljpeg_start (&jh, 0)) return; + order = 0x4949; + ph1_bits(-1); + for (row=0; row < raw_height; row++) { + pred[0] = pred[1] = 0x8000 + load_flags; + for (col=0; col < raw_width; col+=2) { + FORC(2) len[c] = ph1_huff(jh.huff[0]); + FORC(2) { + diff = ph1_bits(len[c]); + if ((diff & (1 << (len[c]-1))) == 0) + diff -= (1 << len[c]) - 1; + if (diff == 65535) diff = -32768; + pred[c] += diff; + if (row >= 0 && (unsigned)(col+c) < width) + RAW(row,col+c) = pred[c]; + } + } + } + ljpeg_end (&jh); + maximum = 0xffff; +} + +void CLASS leaf_hdr_load_raw() +{ + ushort *pixel=0; + unsigned tile=0, r, c, row, col; + + if (!filters) { + pixel = (ushort *) calloc (raw_width, sizeof *pixel); + merror (pixel, "leaf_hdr_load_raw()"); + } + FORC(tiff_samples) + for (r=0; r < raw_height; r++) { + if (r % tile_length == 0) { + fseek (ifp, data_offset + 4*tile++, SEEK_SET); + fseek (ifp, get4(), SEEK_SET); + } + if (filters && c != shot_select) continue; + if (filters) pixel = raw_image + r*raw_width; + read_shorts (pixel, raw_width); + if (!filters && (row = r - top_margin) < height) + for (col=0; col < width; col++) + image[row*width+col][c] = pixel[col+left_margin]; + } + if (!filters) { + maximum = 0xffff; + raw_color = 1; + free (pixel); + } +} + +void CLASS unpacked_load_raw() +{ + int row, col, bits=0; + + while (1 << ++bits < maximum); + read_shorts (raw_image, raw_width*raw_height); + for (row=0; row < raw_height; row++) + for (col=0; col < raw_width; col++) + if ((RAW(row,col) >>= load_flags) >> bits + && (unsigned) (row-top_margin) < height + && (unsigned) (col-left_margin) < width) derror(); +} + +void CLASS sinar_4shot_load_raw() +{ + ushort *pixel; + unsigned shot, row, col, r, c; + + if ((shot = shot_select) || half_size) { + if (shot) shot--; + if (shot > 3) shot = 3; + fseek (ifp, data_offset + shot*4, SEEK_SET); + fseek (ifp, get4(), SEEK_SET); + unpacked_load_raw(); + return; + } + free (raw_image); + raw_image = 0; + free (image); + image = (ushort (*)[4]) + calloc ((iheight=height)*(iwidth=width), sizeof *image); + merror (image, "sinar_4shot_load_raw()"); + pixel = (ushort *) calloc (raw_width, sizeof *pixel); + merror (pixel, "sinar_4shot_load_raw()"); + for (shot=0; shot < 4; shot++) { + fseek (ifp, data_offset + shot*4, SEEK_SET); + fseek (ifp, get4(), SEEK_SET); + for (row=0; row < raw_height; row++) { + read_shorts (pixel, raw_width); + if ((r = row-top_margin - (shot >> 1 & 1)) >= height) continue; + for (col=0; col < raw_width; col++) { + if ((c = col-left_margin - (shot & 1)) >= width) continue; + image[r*width+c][FC(row,col)] = pixel[col]; + } + } + } + free (pixel); + shrink = filters = 0; +} + +void CLASS imacon_full_load_raw() +{ + int row, col; + + for (row=0; row < height; row++) + for (col=0; col < width; col++) + read_shorts (image[row*width+col], 3); +} + +void CLASS packed_load_raw() +{ + int vbits=0, bwide, pwide, rbits, bite, half, irow, row, col, val, i; + UINT64 bitbuf=0; + + if (raw_width * 8 >= width * tiff_bps) /* Is raw_width in bytes? */ + pwide = (bwide = raw_width) * 8 / tiff_bps; + else bwide = (pwide = raw_width) * tiff_bps / 8; + rbits = bwide * 8 - pwide * tiff_bps; + if (load_flags & 1) bwide = bwide * 16 / 15; + bite = 8 + (load_flags & 24); + half = (raw_height+1) >> 1; + for (irow=0; irow < raw_height; irow++) { + row = irow; + if (load_flags & 2 && + (row = irow % half * 2 + irow / half) == 1 && + load_flags & 4) { + if (vbits=0, tiff_compress) + fseek (ifp, data_offset - (-half*bwide & -2048), SEEK_SET); + else { + fseek (ifp, 0, SEEK_END); + fseek (ifp, ftell(ifp) >> 3 << 2, SEEK_SET); + } + } + for (col=0; col < pwide; col++) { + for (vbits -= tiff_bps; vbits < 0; vbits += bite) { + bitbuf <<= bite; + for (i=0; i < bite; i+=8) + bitbuf |= (unsigned) (fgetc(ifp) << i); + } + val = bitbuf << (64-tiff_bps-vbits) >> (64-tiff_bps); + RAW(row,col ^ (load_flags >> 6)) = val; + if (load_flags & 1 && (col % 10) == 9 && + fgetc(ifp) && col < width+left_margin) derror(); + } + vbits -= rbits; + } +} + +void CLASS nokia_load_raw() +{ + uchar *data, *dp; + int rev, dwide, row, col, c; + + rev = 3 * (order == 0x4949); + dwide = raw_width * 5 / 4; + data = (uchar *) malloc (dwide*2); + merror (data, "nokia_load_raw()"); + for (row=0; row < raw_height; row++) { + if (fread (data+dwide, 1, dwide, ifp) < dwide) derror(); + FORC(dwide) data[c] = data[dwide+(c ^ rev)]; + for (dp=data, col=0; col < raw_width; dp+=5, col+=4) + FORC4 RAW(row,col+c) = (dp[c] << 2) | (dp[4] >> (c << 1) & 3); + } + free (data); + maximum = 0x3ff; +} + +unsigned CLASS pana_bits (int nbits) +{ + static uchar buf[0x4000]; + static int vbits; + int byte; + + if (!nbits) return vbits=0; + if (!vbits) { + fread (buf+load_flags, 1, 0x4000-load_flags, ifp); + fread (buf, 1, load_flags, ifp); + } + vbits = (vbits - nbits) & 0x1ffff; + byte = vbits >> 3 ^ 0x3ff0; + return (buf[byte] | buf[byte+1] << 8) >> (vbits & 7) & ~(-1 << nbits); +} + +void CLASS panasonic_load_raw() +{ + int row, col, i, j, sh=0, pred[2], nonz[2]; + + pana_bits(0); + for (row=0; row < height; row++) + for (col=0; col < raw_width; col++) { + if ((i = col % 14) == 0) + pred[0] = pred[1] = nonz[0] = nonz[1] = 0; + if (i % 3 == 2) sh = 4 >> (3 - pana_bits(2)); + if (nonz[i & 1]) { + if ((j = pana_bits(8))) { + if ((pred[i & 1] -= 0x80 << sh) < 0 || sh == 4) + pred[i & 1] &= ~(-1 << sh); + pred[i & 1] += j << sh; + } + } else if ((nonz[i & 1] = pana_bits(8)) || i > 11) + pred[i & 1] = nonz[i & 1] << 4 | pana_bits(4); + if (col < width) + if ((RAW(row,col) = pred[col & 1]) > 4098) derror(); + } +} + +void CLASS olympus_load_raw() +{ + ushort huff[4096]; + int row, col, nbits, sign, low, high, i, c, w, n, nw; + int acarry[2][3], *carry, pred, diff; + + huff[n=0] = 0xc0c; + for (i=12; i--; ) + FORC(2048 >> i) huff[++n] = (i+1) << 8 | i; + fseek (ifp, 7, SEEK_CUR); + getbits(-1); + for (row=0; row < height; row++) { + memset (acarry, 0, sizeof acarry); + for (col=0; col < raw_width; col++) { + carry = acarry[col & 1]; + i = 2 * (carry[2] < 3); + for (nbits=2+i; (ushort) carry[0] >> (nbits+i); nbits++); + low = (sign = getbits(3)) & 3; + sign = sign << 29 >> 31; + if ((high = getbithuff(12,huff)) == 12) + high = getbits(16-nbits) >> 1; + carry[0] = (high << nbits) | getbits(nbits); + diff = (carry[0] ^ sign) + carry[1]; + carry[1] = (diff*3 + carry[1]) >> 5; + carry[2] = carry[0] > 16 ? 0 : carry[2]+1; + if (col >= width) continue; + if (row < 2 && col < 2) pred = 0; + else if (row < 2) pred = RAW(row,col-2); + else if (col < 2) pred = RAW(row-2,col); + else { + w = RAW(row,col-2); + n = RAW(row-2,col); + nw = RAW(row-2,col-2); + if ((w < nw && nw < n) || (n < nw && nw < w)) { + if (ABS(w-nw) > 32 || ABS(n-nw) > 32) + pred = w + n - nw; + else pred = (w + n) >> 1; + } else pred = ABS(w-nw) > ABS(n-nw) ? w : n; + } + if ((RAW(row,col) = pred + ((diff << 2) | low)) >> 12) derror(); + } + } +} + +void CLASS minolta_rd175_load_raw() +{ + uchar pixel[768]; + unsigned irow, box, row, col; + + for (irow=0; irow < 1481; irow++) { + if (fread (pixel, 1, 768, ifp) < 768) derror(); + box = irow / 82; + row = irow % 82 * 12 + ((box < 12) ? box | 1 : (box-12)*2); + switch (irow) { + case 1477: case 1479: continue; + case 1476: row = 984; break; + case 1480: row = 985; break; + case 1478: row = 985; box = 1; + } + if ((box < 12) && (box & 1)) { + for (col=0; col < 1533; col++, row ^= 1) + if (col != 1) RAW(row,col) = (col+1) & 2 ? + pixel[col/2-1] + pixel[col/2+1] : pixel[col/2] << 1; + RAW(row,1) = pixel[1] << 1; + RAW(row,1533) = pixel[765] << 1; + } else + for (col=row & 1; col < 1534; col+=2) + RAW(row,col) = pixel[col/2] << 1; + } + maximum = 0xff << 1; +} + +void CLASS quicktake_100_load_raw() +{ + uchar pixel[484][644]; + static const short gstep[16] = + { -89,-60,-44,-32,-22,-15,-8,-2,2,8,15,22,32,44,60,89 }; + static const short rstep[6][4] = + { { -3,-1,1,3 }, { -5,-1,1,5 }, { -8,-2,2,8 }, + { -13,-3,3,13 }, { -19,-4,4,19 }, { -28,-6,6,28 } }; + static const short curve[256] = + { 0,1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27, + 28,29,30,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,53, + 54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,74,75,76,77,78, + 79,80,81,82,83,84,86,88,90,92,94,97,99,101,103,105,107,110,112,114,116, + 118,120,123,125,127,129,131,134,136,138,140,142,144,147,149,151,153,155, + 158,160,162,164,166,168,171,173,175,177,179,181,184,186,188,190,192,195, + 197,199,201,203,205,208,210,212,214,216,218,221,223,226,230,235,239,244, + 248,252,257,261,265,270,274,278,283,287,291,296,300,305,309,313,318,322, + 326,331,335,339,344,348,352,357,361,365,370,374,379,383,387,392,396,400, + 405,409,413,418,422,426,431,435,440,444,448,453,457,461,466,470,474,479, + 483,487,492,496,500,508,519,531,542,553,564,575,587,598,609,620,631,643, + 654,665,676,687,698,710,721,732,743,754,766,777,788,799,810,822,833,844, + 855,866,878,889,900,911,922,933,945,956,967,978,989,1001,1012,1023 }; + int rb, row, col, sharp, val=0; + + getbits(-1); + memset (pixel, 0x80, sizeof pixel); + for (row=2; row < height+2; row++) { + for (col=2+(row & 1); col < width+2; col+=2) { + val = ((pixel[row-1][col-1] + 2*pixel[row-1][col+1] + + pixel[row][col-2]) >> 2) + gstep[getbits(4)]; + pixel[row][col] = val = LIM(val,0,255); + if (col < 4) + pixel[row][col-2] = pixel[row+1][~row & 1] = val; + if (row == 2) + pixel[row-1][col+1] = pixel[row-1][col+3] = val; + } + pixel[row][col] = val; + } + for (rb=0; rb < 2; rb++) + for (row=2+rb; row < height+2; row+=2) + for (col=3-(row & 1); col < width+2; col+=2) { + if (row < 4 || col < 4) sharp = 2; + else { + val = ABS(pixel[row-2][col] - pixel[row][col-2]) + + ABS(pixel[row-2][col] - pixel[row-2][col-2]) + + ABS(pixel[row][col-2] - pixel[row-2][col-2]); + sharp = val < 4 ? 0 : val < 8 ? 1 : val < 16 ? 2 : + val < 32 ? 3 : val < 48 ? 4 : 5; + } + val = ((pixel[row-2][col] + pixel[row][col-2]) >> 1) + + rstep[sharp][getbits(2)]; + pixel[row][col] = val = LIM(val,0,255); + if (row < 4) pixel[row-2][col+2] = val; + if (col < 4) pixel[row+2][col-2] = val; + } + for (row=2; row < height+2; row++) + for (col=3-(row & 1); col < width+2; col+=2) { + val = ((pixel[row][col-1] + (pixel[row][col] << 2) + + pixel[row][col+1]) >> 1) - 0x100; + pixel[row][col] = LIM(val,0,255); + } + for (row=0; row < height; row++) + for (col=0; col < width; col++) + RAW(row,col) = curve[pixel[row+2][col+2]]; + maximum = 0x3ff; +} + +#define radc_token(tree) ((signed char) getbithuff(8,huff[tree])) + +#define FORYX for (y=1; y < 3; y++) for (x=col+1; x >= col; x--) + +#define PREDICTOR (c ? (buf[c][y-1][x] + buf[c][y][x+1]) / 2 \ +: (buf[c][y-1][x+1] + 2*buf[c][y-1][x] + buf[c][y][x+1]) / 4) + +void CLASS kodak_radc_load_raw() +{ + static const char src[] = { + 1,1, 2,3, 3,4, 4,2, 5,7, 6,5, 7,6, 7,8, + 1,0, 2,1, 3,3, 4,4, 5,2, 6,7, 7,6, 8,5, 8,8, + 2,1, 2,3, 3,0, 3,2, 3,4, 4,6, 5,5, 6,7, 6,8, + 2,0, 2,1, 2,3, 3,2, 4,4, 5,6, 6,7, 7,5, 7,8, + 2,1, 2,4, 3,0, 3,2, 3,3, 4,7, 5,5, 6,6, 6,8, + 2,3, 3,1, 3,2, 3,4, 3,5, 3,6, 4,7, 5,0, 5,8, + 2,3, 2,6, 3,0, 3,1, 4,4, 4,5, 4,7, 5,2, 5,8, + 2,4, 2,7, 3,3, 3,6, 4,1, 4,2, 4,5, 5,0, 5,8, + 2,6, 3,1, 3,3, 3,5, 3,7, 3,8, 4,0, 5,2, 5,4, + 2,0, 2,1, 3,2, 3,3, 4,4, 4,5, 5,6, 5,7, 4,8, + 1,0, 2,2, 2,-2, + 1,-3, 1,3, + 2,-17, 2,-5, 2,5, 2,17, + 2,-7, 2,2, 2,9, 2,18, + 2,-18, 2,-9, 2,-2, 2,7, + 2,-28, 2,28, 3,-49, 3,-9, 3,9, 4,49, 5,-79, 5,79, + 2,-1, 2,13, 2,26, 3,39, 4,-16, 5,55, 6,-37, 6,76, + 2,-26, 2,-13, 2,1, 3,-39, 4,16, 5,-55, 6,-76, 6,37 + }; + ushort huff[19][256]; + int row, col, tree, nreps, rep, step, i, c, s, r, x, y, val; + short last[3] = { 16,16,16 }, mul[3], buf[3][3][386]; + static const ushort pt[] = + { 0,0, 1280,1344, 2320,3616, 3328,8000, 4095,16383, 65535,16383 }; + + for (i=2; i < 12; i+=2) + for (c=pt[i-2]; c <= pt[i]; c++) + curve[c] = (float) + (c-pt[i-2]) / (pt[i]-pt[i-2]) * (pt[i+1]-pt[i-1]) + pt[i-1] + 0.5; + for (s=i=0; i < sizeof src; i+=2) + FORC(256 >> src[i]) + huff[0][s++] = src[i] << 8 | (uchar) src[i+1]; + s = kodak_cbpp == 243 ? 2 : 3; + FORC(256) huff[18][c] = (8-s) << 8 | c >> s << s | 1 << (s-1); + getbits(-1); + for (i=0; i < sizeof(buf)/sizeof(short); i++) + buf[0][0][i] = 2048; + for (row=0; row < height; row+=4) { + FORC3 mul[c] = getbits(6); + FORC3 { + val = ((0x1000000/last[c] + 0x7ff) >> 12) * mul[c]; + s = val > 65564 ? 10:12; + x = ~(-1 << (s-1)); + val <<= 12-s; + for (i=0; i < sizeof(buf[0])/sizeof(short); i++) + buf[c][0][i] = (buf[c][0][i] * val + x) >> s; + last[c] = mul[c]; + for (r=0; r <= !c; r++) { + buf[c][1][width/2] = buf[c][2][width/2] = mul[c] << 7; + for (tree=1, col=width/2; col > 0; ) { + if ((tree = radc_token(tree))) { + col -= 2; + if (tree == 8) + FORYX buf[c][y][x] = (uchar) radc_token(18) * mul[c]; + else + FORYX buf[c][y][x] = radc_token(tree+10) * 16 + PREDICTOR; + } else + do { + nreps = (col > 2) ? radc_token(9) + 1 : 1; + for (rep=0; rep < 8 && rep < nreps && col > 0; rep++) { + col -= 2; + FORYX buf[c][y][x] = PREDICTOR; + if (rep & 1) { + step = radc_token(10) << 4; + FORYX buf[c][y][x] += step; + } + } + } while (nreps == 9); + } + for (y=0; y < 2; y++) + for (x=0; x < width/2; x++) { + val = (buf[c][y+1][x] << 4) / mul[c]; + if (val < 0) val = 0; + if (c) RAW(row+y*2+c-1,x*2+2-c) = val; + else RAW(row+r*2+y,x*2+y) = val; + } + memcpy (buf[c][0]+!c, buf[c][2], sizeof buf[c][0]-2*!c); + } + } + for (y=row; y < row+4; y++) + for (x=0; x < width; x++) + if ((x+y) & 1) { + r = x ? x-1 : x+1; + s = x+1 < width ? x+1 : x-1; + val = (RAW(y,x)-2048)*2 + (RAW(y,r)+RAW(y,s))/2; + if (val < 0) val = 0; + RAW(y,x) = val; + } + } + for (i=0; i < height*width; i++) + raw_image[i] = curve[raw_image[i]]; + maximum = 0x3fff; +} + +#undef FORYX +#undef PREDICTOR + +#ifdef NO_JPEG +void CLASS kodak_jpeg_load_raw() {} +void CLASS lossy_dng_load_raw() {} +#else + +METHODDEF(boolean) +fill_input_buffer (j_decompress_ptr cinfo) +{ + static uchar jpeg_buffer[4096]; + size_t nbytes; + + nbytes = fread (jpeg_buffer, 1, 4096, ifp); + swab (jpeg_buffer, jpeg_buffer, nbytes); + cinfo->src->next_input_byte = jpeg_buffer; + cinfo->src->bytes_in_buffer = nbytes; + return TRUE; +} + +void CLASS kodak_jpeg_load_raw() +{ + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + JSAMPARRAY buf; + JSAMPLE (*pixel)[3]; + int row, col; + + cinfo.err = jpeg_std_error (&jerr); + jpeg_create_decompress (&cinfo); + jpeg_stdio_src (&cinfo, ifp); + cinfo.src->fill_input_buffer = fill_input_buffer; + jpeg_read_header (&cinfo, TRUE); + jpeg_start_decompress (&cinfo); + if ((cinfo.output_width != width ) || + (cinfo.output_height*2 != height ) || + (cinfo.output_components != 3 )) { + fprintf (stderr,_("%s: incorrect JPEG dimensions\n"), ifname); + jpeg_destroy_decompress (&cinfo); + longjmp (failure, 3); + } + buf = (*cinfo.mem->alloc_sarray) + ((j_common_ptr) &cinfo, JPOOL_IMAGE, width*3, 1); + + while (cinfo.output_scanline < cinfo.output_height) { + row = cinfo.output_scanline * 2; + jpeg_read_scanlines (&cinfo, buf, 1); + pixel = (JSAMPLE (*)[3]) buf[0]; + for (col=0; col < width; col+=2) { + RAW(row+0,col+0) = pixel[col+0][1] << 1; + RAW(row+1,col+1) = pixel[col+1][1] << 1; + RAW(row+0,col+1) = pixel[col][0] + pixel[col+1][0]; + RAW(row+1,col+0) = pixel[col][2] + pixel[col+1][2]; + } + } + jpeg_finish_decompress (&cinfo); + jpeg_destroy_decompress (&cinfo); + maximum = 0xff << 1; +} + +void CLASS lossy_dng_load_raw() +{ + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + JSAMPARRAY buf; + JSAMPLE (*pixel)[3]; + unsigned sorder=order, ntags, opcode, deg, i, j, c; + unsigned save=data_offset-4, trow=0, tcol=0, row, col; + ushort curve[3][256]; + double coeff[9], tot; + + fseek (ifp, meta_offset, SEEK_SET); + order = 0x4d4d; + ntags = get4(); + while (ntags--) { + opcode = get4(); get4(); get4(); + if (opcode != 8) + { fseek (ifp, get4(), SEEK_CUR); continue; } + fseek (ifp, 20, SEEK_CUR); + if ((c = get4()) > 2) break; + fseek (ifp, 12, SEEK_CUR); + if ((deg = get4()) > 8) break; + for (i=0; i <= deg && i < 9; i++) + coeff[i] = getreal(12); + for (i=0; i < 256; i++) { + for (tot=j=0; j <= deg; j++) + tot += coeff[j] * pow(i/255.0, j); + curve[c][i] = tot*0xffff; + } + } + order = sorder; + cinfo.err = jpeg_std_error (&jerr); + jpeg_create_decompress (&cinfo); + while (trow < raw_height) { + fseek (ifp, save+=4, SEEK_SET); + if (tile_length < INT_MAX) + fseek (ifp, get4(), SEEK_SET); + jpeg_stdio_src (&cinfo, ifp); + jpeg_read_header (&cinfo, TRUE); + jpeg_start_decompress (&cinfo); + buf = (*cinfo.mem->alloc_sarray) + ((j_common_ptr) &cinfo, JPOOL_IMAGE, cinfo.output_width*3, 1); + while (cinfo.output_scanline < cinfo.output_height && + (row = trow + cinfo.output_scanline) < height) { + jpeg_read_scanlines (&cinfo, buf, 1); + pixel = (JSAMPLE (*)[3]) buf[0]; + for (col=0; col < cinfo.output_width && tcol+col < width; col++) { + FORC3 image[row*width+tcol+col][c] = curve[c][pixel[col][c]]; + } + } + jpeg_abort_decompress (&cinfo); + if ((tcol += tile_width) >= raw_width) + trow += tile_length + (tcol = 0); + } + jpeg_destroy_decompress (&cinfo); + maximum = 0xffff; +} +#endif + +void CLASS kodak_dc120_load_raw() +{ + static const int mul[4] = { 162, 192, 187, 92 }; + static const int add[4] = { 0, 636, 424, 212 }; + uchar pixel[848]; + int row, shift, col; + + for (row=0; row < height; row++) { + if (fread (pixel, 1, 848, ifp) < 848) derror(); + shift = row * mul[row & 3] + add[row & 3]; + for (col=0; col < width; col++) + RAW(row,col) = (ushort) pixel[(col + shift) % 848]; + } + maximum = 0xff; +} + +void CLASS eight_bit_load_raw() +{ + uchar *pixel; + unsigned row, col; + + pixel = (uchar *) calloc (raw_width, sizeof *pixel); + merror (pixel, "eight_bit_load_raw()"); + for (row=0; row < raw_height; row++) { + if (fread (pixel, 1, raw_width, ifp) < raw_width) derror(); + for (col=0; col < raw_width; col++) + RAW(row,col) = curve[pixel[col]]; + } + free (pixel); + maximum = curve[0xff]; +} + +void CLASS kodak_yrgb_load_raw() +{ + uchar *pixel; + int row, col, y, cb, cr, rgb[3], c; + + pixel = (uchar *) calloc (raw_width, 3*sizeof *pixel); + merror (pixel, "kodak_yrgb_load_raw()"); + for (row=0; row < height; row++) { + if (~row & 1) + if (fread (pixel, raw_width, 3, ifp) < 3) derror(); + for (col=0; col < raw_width; col++) { + y = pixel[width*2*(row & 1) + col]; + cb = pixel[width + (col & -2)] - 128; + cr = pixel[width + (col & -2)+1] - 128; + rgb[1] = y-((cb + cr + 2) >> 2); + rgb[2] = rgb[1] + cb; + rgb[0] = rgb[1] + cr; + FORC3 image[row*width+col][c] = curve[LIM(rgb[c],0,255)]; + } + } + free (pixel); + maximum = curve[0xff]; +} + +void CLASS kodak_262_load_raw() +{ + static const uchar kodak_tree[2][26] = + { { 0,1,5,1,1,2,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9 }, + { 0,3,1,1,1,1,1,2,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9 } }; + ushort *huff[2]; + uchar *pixel; + int *strip, ns, c, row, col, chess, pi=0, pi1, pi2, pred, val; + + FORC(2) huff[c] = make_decoder (kodak_tree[c]); + ns = (raw_height+63) >> 5; + pixel = (uchar *) malloc (raw_width*32 + ns*4); + merror (pixel, "kodak_262_load_raw()"); + strip = (int *) (pixel + raw_width*32); + order = 0x4d4d; + FORC(ns) strip[c] = get4(); + for (row=0; row < raw_height; row++) { + if ((row & 31) == 0) { + fseek (ifp, strip[row >> 5], SEEK_SET); + getbits(-1); + pi = 0; + } + for (col=0; col < raw_width; col++) { + chess = (row + col) & 1; + pi1 = chess ? pi-2 : pi-raw_width-1; + pi2 = chess ? pi-2*raw_width : pi-raw_width+1; + if (col <= chess) pi1 = -1; + if (pi1 < 0) pi1 = pi2; + if (pi2 < 0) pi2 = pi1; + if (pi1 < 0 && col > 1) pi1 = pi2 = pi-2; + pred = (pi1 < 0) ? 0 : (pixel[pi1] + pixel[pi2]) >> 1; + pixel[pi] = val = pred + ljpeg_diff (huff[chess]); + if (val >> 8) derror(); + val = curve[pixel[pi++]]; + RAW(row,col) = val; + } + } + free (pixel); + FORC(2) free (huff[c]); +} + +int CLASS kodak_65000_decode (short *out, int bsize) +{ + uchar c, blen[768]; + ushort raw[6]; + INT64 bitbuf=0; + int save, bits=0, i, j, len, diff; + + save = ftell(ifp); + bsize = (bsize + 3) & -4; + for (i=0; i < bsize; i+=2) { + c = fgetc(ifp); + if ((blen[i ] = c & 15) > 12 || + (blen[i+1] = c >> 4) > 12 ) { + fseek (ifp, save, SEEK_SET); + for (i=0; i < bsize; i+=8) { + read_shorts (raw, 6); + out[i ] = raw[0] >> 12 << 8 | raw[2] >> 12 << 4 | raw[4] >> 12; + out[i+1] = raw[1] >> 12 << 8 | raw[3] >> 12 << 4 | raw[5] >> 12; + for (j=0; j < 6; j++) + out[i+2+j] = raw[j] & 0xfff; + } + return 1; + } + } + if ((bsize & 7) == 4) { + bitbuf = fgetc(ifp) << 8; + bitbuf += fgetc(ifp); + bits = 16; + } + for (i=0; i < bsize; i++) { + len = blen[i]; + if (bits < len) { + for (j=0; j < 32; j+=8) + bitbuf += (INT64) fgetc(ifp) << (bits+(j^8)); + bits += 32; + } + diff = bitbuf & (0xffff >> (16-len)); + bitbuf >>= len; + bits -= len; + if ((diff & (1 << (len-1))) == 0) + diff -= (1 << len) - 1; + out[i] = diff; + } + return 0; +} + +void CLASS kodak_65000_load_raw() +{ + short buf[256]; + int row, col, len, pred[2], ret, i; + + for (row=0; row < height; row++) + for (col=0; col < width; col+=256) { + pred[0] = pred[1] = 0; + len = MIN (256, width-col); + ret = kodak_65000_decode (buf, len); + for (i=0; i < len; i++) + if ((RAW(row,col+i) = curve[ret ? buf[i] : + (pred[i & 1] += buf[i])]) >> 12) derror(); + } +} + +void CLASS kodak_ycbcr_load_raw() +{ + short buf[384], *bp; + int row, col, len, c, i, j, k, y[2][2], cb, cr, rgb[3]; + ushort *ip; + + for (row=0; row < height; row+=2) + for (col=0; col < width; col+=128) { + len = MIN (128, width-col); + kodak_65000_decode (buf, len*3); + y[0][1] = y[1][1] = cb = cr = 0; + for (bp=buf, i=0; i < len; i+=2, bp+=2) { + cb += bp[4]; + cr += bp[5]; + rgb[1] = -((cb + cr + 2) >> 2); + rgb[2] = rgb[1] + cb; + rgb[0] = rgb[1] + cr; + for (j=0; j < 2; j++) + for (k=0; k < 2; k++) { + if ((y[j][k] = y[j][k^1] + *bp++) >> 10) derror(); + ip = image[(row+j)*width + col+i+k]; + FORC3 ip[c] = curve[LIM(y[j][k]+rgb[c], 0, 0xfff)]; + } + } + } +} + +void CLASS kodak_rgb_load_raw() +{ + short buf[768], *bp; + int row, col, len, c, i, rgb[3]; + ushort *ip=image[0]; + + if (raw_image) free (raw_image); + raw_image = 0; + for (row=0; row < height; row++) + for (col=0; col < width; col+=256) { + len = MIN (256, width-col); + kodak_65000_decode (buf, len*3); + memset (rgb, 0, sizeof rgb); + for (bp=buf, i=0; i < len; i++, ip+=4) + FORC3 if ((ip[c] = rgb[c] += *bp++) >> 12) derror(); + } +} + +void CLASS kodak_thumb_load_raw() +{ + int row, col; + colors = thumb_misc >> 5; + for (row=0; row < height; row++) + for (col=0; col < width; col++) + read_shorts (image[row*width+col], colors); + maximum = (1 << (thumb_misc & 31)) - 1; +} + +void CLASS sony_decrypt (unsigned *data, int len, int start, int key) +{ + static unsigned pad[128], p; + + if (start) { + for (p=0; p < 4; p++) + pad[p] = key = key * 48828125 + 1; + pad[3] = pad[3] << 1 | (pad[0]^pad[2]) >> 31; + for (p=4; p < 127; p++) + pad[p] = (pad[p-4]^pad[p-2]) << 1 | (pad[p-3]^pad[p-1]) >> 31; + for (p=0; p < 127; p++) + pad[p] = htonl(pad[p]); + } + while (len--) + *data++ ^= pad[p++ & 127] = pad[(p+1) & 127] ^ pad[(p+65) & 127]; +} + +void CLASS sony_load_raw() +{ + uchar head[40]; + ushort *pixel; + unsigned i, key, row, col; + + fseek (ifp, 200896, SEEK_SET); + fseek (ifp, (unsigned) fgetc(ifp)*4 - 1, SEEK_CUR); + order = 0x4d4d; + key = get4(); + fseek (ifp, 164600, SEEK_SET); + fread (head, 1, 40, ifp); + sony_decrypt ((unsigned int *) head, 10, 1, key); + for (i=26; i-- > 22; ) + key = key << 8 | head[i]; + fseek (ifp, data_offset, SEEK_SET); + for (row=0; row < raw_height; row++) { + pixel = raw_image + row*raw_width; + if (fread (pixel, 2, raw_width, ifp) < raw_width) derror(); + sony_decrypt ((unsigned int *) pixel, raw_width/2, !row, key); + for (col=0; col < raw_width; col++) + if ((pixel[col] = ntohs(pixel[col])) >> 14) derror(); + } + maximum = 0x3ff0; +} + +void CLASS sony_arw_load_raw() +{ + ushort huff[32768]; + static const ushort tab[18] = + { 0xf11,0xf10,0xe0f,0xd0e,0xc0d,0xb0c,0xa0b,0x90a,0x809, + 0x708,0x607,0x506,0x405,0x304,0x303,0x300,0x202,0x201 }; + int i, c, n, col, row, len, diff, sum=0; + + for (n=i=0; i < 18; i++) + FORC(32768 >> (tab[i] >> 8)) huff[n++] = tab[i]; + getbits(-1); + for (col = raw_width; col--; ) + for (row=0; row < raw_height+1; row+=2) { + if (row == raw_height) row = 1; + len = getbithuff(15,huff); + diff = getbits(len); + if ((diff & (1 << (len-1))) == 0) + diff -= (1 << len) - 1; + if ((sum += diff) >> 12) derror(); + if (row < height) RAW(row,col) = sum; + } +} + +void CLASS sony_arw2_load_raw() +{ + uchar *data, *dp; + ushort pix[16]; + int row, col, val, max, min, imax, imin, sh, bit, i; + + data = (uchar *) malloc (raw_width); + merror (data, "sony_arw2_load_raw()"); + for (row=0; row < height; row++) { + fread (data, 1, raw_width, ifp); + for (dp=data, col=0; col < raw_width-30; dp+=16) { + max = 0x7ff & (val = sget4(dp)); + min = 0x7ff & val >> 11; + imax = 0x0f & val >> 22; + imin = 0x0f & val >> 26; + for (sh=0; sh < 4 && 0x80 << sh <= max-min; sh++); + for (bit=30, i=0; i < 16; i++) + if (i == imax) pix[i] = max; + else if (i == imin) pix[i] = min; + else { + pix[i] = ((sget2(dp+(bit >> 3)) >> (bit & 7) & 0x7f) << sh) + min; + if (pix[i] > 0x7ff) pix[i] = 0x7ff; + bit += 7; + } + for (i=0; i < 16; i++, col+=2) + if (col < width) RAW(row,col) = curve[pix[i] << 1] >> 2; + col -= col & 1 ? 1:31; + } + } + free (data); +} + +#define HOLE(row) ((holes >> (((row) - raw_height) & 7)) & 1) + +/* Kudos to Rich Taylor for figuring out SMaL's compression algorithm. */ +void CLASS smal_decode_segment (unsigned seg[2][2], int holes) +{ + uchar hist[3][13] = { + { 7, 7, 0, 0, 63, 55, 47, 39, 31, 23, 15, 7, 0 }, + { 7, 7, 0, 0, 63, 55, 47, 39, 31, 23, 15, 7, 0 }, + { 3, 3, 0, 0, 63, 47, 31, 15, 0 } }; + int low, high=0xff, carry=0, nbits=8; + int pix, s, count, bin, next, i, sym[3]; + uchar diff, pred[]={0,0}; + ushort data=0, range=0; + + fseek (ifp, seg[0][1]+1, SEEK_SET); + getbits(-1); + for (pix=seg[0][0]; pix < seg[1][0]; pix++) { + for (s=0; s < 3; s++) { + data = data << nbits | getbits(nbits); + if (carry < 0) + carry = (nbits += carry+1) < 1 ? nbits-1 : 0; + while (--nbits >= 0) + if ((data >> nbits & 0xff) == 0xff) break; + if (nbits > 0) + data = ((data & ((1 << (nbits-1)) - 1)) << 1) | + ((data + (((data & (1 << (nbits-1)))) << 1)) & (-1 << nbits)); + if (nbits >= 0) { + data += getbits(1); + carry = nbits - 8; + } + count = ((((data-range+1) & 0xffff) << 2) - 1) / (high >> 4); + for (bin=0; hist[s][bin+5] > count; bin++); + low = hist[s][bin+5] * (high >> 4) >> 2; + if (bin) high = hist[s][bin+4] * (high >> 4) >> 2; + high -= low; + for (nbits=0; high << nbits < 128; nbits++); + range = (range+low) << nbits; + high <<= nbits; + next = hist[s][1]; + if (++hist[s][2] > hist[s][3]) { + next = (next+1) & hist[s][0]; + hist[s][3] = (hist[s][next+4] - hist[s][next+5]) >> 2; + hist[s][2] = 1; + } + if (hist[s][hist[s][1]+4] - hist[s][hist[s][1]+5] > 1) { + if (bin < hist[s][1]) + for (i=bin; i < hist[s][1]; i++) hist[s][i+5]--; + else if (next <= bin) + for (i=hist[s][1]; i < bin; i++) hist[s][i+5]++; + } + hist[s][1] = next; + sym[s] = bin; + } + diff = sym[2] << 5 | sym[1] << 2 | (sym[0] & 3); + if (sym[0] & 4) + diff = diff ? -diff : 0x80; + if (ftell(ifp) + 12 >= seg[1][1]) + diff = 0; + raw_image[pix] = pred[pix & 1] += diff; + if (!(pix & 1) && HOLE(pix / raw_width)) pix += 2; + } + maximum = 0xff; +} + +void CLASS smal_v6_load_raw() +{ + unsigned seg[2][2]; + + fseek (ifp, 16, SEEK_SET); + seg[0][0] = 0; + seg[0][1] = get2(); + seg[1][0] = raw_width * raw_height; + seg[1][1] = INT_MAX; + smal_decode_segment (seg, 0); +} + +int CLASS median4 (int *p) +{ + int min, max, sum, i; + + min = max = sum = p[0]; + for (i=1; i < 4; i++) { + sum += p[i]; + if (min > p[i]) min = p[i]; + if (max < p[i]) max = p[i]; + } + return (sum - min - max) >> 1; +} + +void CLASS fill_holes (int holes) +{ + int row, col, val[4]; + + for (row=2; row < height-2; row++) { + if (!HOLE(row)) continue; + for (col=1; col < width-1; col+=4) { + val[0] = RAW(row-1,col-1); + val[1] = RAW(row-1,col+1); + val[2] = RAW(row+1,col-1); + val[3] = RAW(row+1,col+1); + RAW(row,col) = median4(val); + } + for (col=2; col < width-2; col+=4) + if (HOLE(row-2) || HOLE(row+2)) + RAW(row,col) = (RAW(row,col-2) + RAW(row,col+2)) >> 1; + else { + val[0] = RAW(row,col-2); + val[1] = RAW(row,col+2); + val[2] = RAW(row-2,col); + val[3] = RAW(row+2,col); + RAW(row,col) = median4(val); + } + } +} + +void CLASS smal_v9_load_raw() +{ + unsigned seg[256][2], offset, nseg, holes, i; + + fseek (ifp, 67, SEEK_SET); + offset = get4(); + nseg = fgetc(ifp); + fseek (ifp, offset, SEEK_SET); + for (i=0; i < nseg*2; i++) + seg[0][i] = get4() + data_offset*(i & 1); + fseek (ifp, 78, SEEK_SET); + holes = fgetc(ifp); + fseek (ifp, 88, SEEK_SET); + seg[nseg][0] = raw_height * raw_width; + seg[nseg][1] = get4() + data_offset; + for (i=0; i < nseg; i++) + smal_decode_segment (seg+i, holes); + if (holes) fill_holes (holes); +} + +void CLASS redcine_load_raw() +{ +#ifndef NO_JASPER + int c, row, col; + jas_stream_t *in; + jas_image_t *jimg; + jas_matrix_t *jmat; + jas_seqent_t *data; + ushort *img, *pix; + + jas_init(); + in = jas_stream_fopen (ifname, "rb"); + jas_stream_seek (in, data_offset+20, SEEK_SET); + jimg = jas_image_decode (in, -1, 0); + if (!jimg) longjmp (failure, 3); + jmat = jas_matrix_create (height/2, width/2); + merror (jmat, "redcine_load_raw()"); + img = (ushort *) calloc ((height+2)*(width+2), 2); + merror (img, "redcine_load_raw()"); + FORC4 { + jas_image_readcmpt (jimg, c, 0, 0, width/2, height/2, jmat); + data = jas_matrix_getref (jmat, 0, 0); + for (row = c >> 1; row < height; row+=2) + for (col = c & 1; col < width; col+=2) + img[(row+1)*(width+2)+col+1] = data[(row/2)*(width/2)+col/2]; + } + for (col=1; col <= width; col++) { + img[col] = img[2*(width+2)+col]; + img[(height+1)*(width+2)+col] = img[(height-1)*(width+2)+col]; + } + for (row=0; row < height+2; row++) { + img[row*(width+2)] = img[row*(width+2)+2]; + img[(row+1)*(width+2)-1] = img[(row+1)*(width+2)-3]; + } + for (row=1; row <= height; row++) { + pix = img + row*(width+2) + (col = 1 + (FC(row,1) & 1)); + for ( ; col <= width; col+=2, pix+=2) { + c = (((pix[0] - 0x800) << 3) + + pix[-(width+2)] + pix[width+2] + pix[-1] + pix[1]) >> 2; + pix[0] = LIM(c,0,4095); + } + } + for (row=0; row < height; row++) + for (col=0; col < width; col++) + RAW(row,col) = curve[img[(row+1)*(width+2)+col+1]]; + free (img); + jas_matrix_destroy (jmat); + jas_image_destroy (jimg); + jas_stream_close (in); +#endif +} + +/* RESTRICTED code starts here */ + +void CLASS foveon_decoder (unsigned size, unsigned code) +{ + static unsigned huff[1024]; + struct decode *cur; + int i, len; + + if (!code) { + for (i=0; i < size; i++) + huff[i] = get4(); + memset (first_decode, 0, sizeof first_decode); + free_decode = first_decode; + } + cur = free_decode++; + if (free_decode > first_decode+2048) { + fprintf (stderr,_("%s: decoder table overflow\n"), ifname); + longjmp (failure, 2); + } + if (code) + for (i=0; i < size; i++) + if (huff[i] == code) { + cur->leaf = i; + return; + } + if ((len = code >> 27) > 26) return; + code = (len+1) << 27 | (code & 0x3ffffff) << 1; + + cur->branch[0] = free_decode; + foveon_decoder (size, code); + cur->branch[1] = free_decode; + foveon_decoder (size, code+1); +} + +void CLASS foveon_thumb() +{ + unsigned bwide, row, col, bitbuf=0, bit=1, c, i; + char *buf; + struct decode *dindex; + short pred[3]; + + bwide = get4(); + fprintf (ofp, "P6\n%d %d\n255\n", thumb_width, thumb_height); + if (bwide > 0) { + if (bwide < thumb_width*3) return; + buf = (char *) malloc (bwide); + merror (buf, "foveon_thumb()"); + for (row=0; row < thumb_height; row++) { + fread (buf, 1, bwide, ifp); + fwrite (buf, 3, thumb_width, ofp); + } + free (buf); + return; + } + foveon_decoder (256, 0); + + for (row=0; row < thumb_height; row++) { + memset (pred, 0, sizeof pred); + if (!bit) get4(); + for (bit=col=0; col < thumb_width; col++) + FORC3 { + for (dindex=first_decode; dindex->branch[0]; ) { + if ((bit = (bit-1) & 31) == 31) + for (i=0; i < 4; i++) + bitbuf = (bitbuf << 8) + fgetc(ifp); + dindex = dindex->branch[bitbuf >> bit & 1]; + } + pred[c] += dindex->leaf; + fputc (pred[c], ofp); + } + } +} + +void CLASS foveon_sd_load_raw() +{ + struct decode *dindex; + short diff[1024]; + unsigned bitbuf=0; + int pred[3], row, col, bit=-1, c, i; + + read_shorts ((ushort *) diff, 1024); + if (!load_flags) foveon_decoder (1024, 0); + + for (row=0; row < height; row++) { + memset (pred, 0, sizeof pred); + if (!bit && !load_flags && atoi(model+2) < 14) get4(); + for (col=bit=0; col < width; col++) { + if (load_flags) { + bitbuf = get4(); + FORC3 pred[2-c] += diff[bitbuf >> c*10 & 0x3ff]; + } + else FORC3 { + for (dindex=first_decode; dindex->branch[0]; ) { + if ((bit = (bit-1) & 31) == 31) + for (i=0; i < 4; i++) + bitbuf = (bitbuf << 8) + fgetc(ifp); + dindex = dindex->branch[bitbuf >> bit & 1]; + } + pred[c] += diff[dindex->leaf]; + if (pred[c] >> 16 && ~pred[c] >> 16) derror(); + } + FORC3 image[row*width+col][c] = pred[c]; + } + } +} + +void CLASS foveon_huff (ushort *huff) +{ + int i, j, clen, code; + + huff[0] = 8; + for (i=0; i < 13; i++) { + clen = getc(ifp); + code = getc(ifp); + for (j=0; j < 256 >> clen; ) + huff[code+ ++j] = clen << 8 | i; + } + get2(); +} + +void CLASS foveon_dp_load_raw() +{ + unsigned c, roff[4], row, col, diff; + ushort huff[258], vpred, hpred; + + fseek (ifp, 8, SEEK_CUR); + foveon_huff (huff); + roff[0] = 48; + FORC3 roff[c+1] = -(-(roff[c] + get4()) & -16); + FORC3 { + fseek (ifp, data_offset+roff[c], SEEK_SET); + getbits(-1); + vpred = 1024; + for (row=0; row < height; row++) { + for (col=0; col < width; col++) { + diff = ljpeg_diff(huff); + if (col) hpred += diff; + else hpred = vpred += diff; + image[row*width+col][c] = hpred; + } + } + } +} + +void CLASS foveon_load_camf() +{ + unsigned type, wide, high, i, j, row, col, diff; + ushort huff[258], vpred[2][2] = {{512,512},{512,512}}, hpred[2]; + + fseek (ifp, meta_offset, SEEK_SET); + type = get4(); get4(); get4(); + wide = get4(); + high = get4(); + if (type == 2) { + fread (meta_data, 1, meta_length, ifp); + for (i=0; i < meta_length; i++) { + high = (high * 1597 + 51749) % 244944; + wide = high * (INT64) 301593171 >> 24; + meta_data[i] ^= ((((high << 8) - wide) >> 1) + wide) >> 17; + } + } else if (type == 4) { + free (meta_data); + meta_data = (char *) malloc (meta_length = wide*high*3/2); + merror (meta_data, "foveon_load_camf()"); + foveon_huff (huff); + get4(); + getbits(-1); + for (j=row=0; row < high; row++) { + for (col=0; col < wide; col++) { + diff = ljpeg_diff(huff); + if (col < 2) hpred[col] = vpred[row & 1][col] += diff; + else hpred[col & 1] += diff; + if (col & 1) { + meta_data[j++] = hpred[0] >> 4; + meta_data[j++] = hpred[0] << 4 | hpred[1] >> 8; + meta_data[j++] = hpred[1]; + } + } + } + } else + fprintf (stderr,_("%s has unknown CAMF type %d.\n"), ifname, type); +} + +const char * CLASS foveon_camf_param (const char *block, const char *param) +{ + unsigned idx, num; + char *pos, *cp, *dp; + + for (idx=0; idx < meta_length; idx += sget4(pos+8)) { + pos = meta_data + idx; + if (strncmp (pos, "CMb", 3)) break; + if (pos[3] != 'P') continue; + if (strcmp (block, pos+sget4(pos+12))) continue; + cp = pos + sget4(pos+16); + num = sget4(cp); + dp = pos + sget4(cp+4); + while (num--) { + cp += 8; + if (!strcmp (param, dp+sget4(cp))) + return dp+sget4(cp+4); + } + } + return 0; +} + +void * CLASS foveon_camf_matrix (unsigned dim[3], const char *name) +{ + unsigned i, idx, type, ndim, size, *mat; + char *pos, *cp, *dp; + double dsize; + + for (idx=0; idx < meta_length; idx += sget4(pos+8)) { + pos = meta_data + idx; + if (strncmp (pos, "CMb", 3)) break; + if (pos[3] != 'M') continue; + if (strcmp (name, pos+sget4(pos+12))) continue; + dim[0] = dim[1] = dim[2] = 1; + cp = pos + sget4(pos+16); + type = sget4(cp); + if ((ndim = sget4(cp+4)) > 3) break; + dp = pos + sget4(cp+8); + for (i=ndim; i--; ) { + cp += 12; + dim[i] = sget4(cp); + } + if ((dsize = (double) dim[0]*dim[1]*dim[2]) > meta_length/4) break; + mat = (unsigned *) malloc ((size = dsize) * 4); + merror (mat, "foveon_camf_matrix()"); + for (i=0; i < size; i++) + if (type && type != 6) + mat[i] = sget4(dp + i*4); + else + mat[i] = sget4(dp + i*2) & 0xffff; + return mat; + } + fprintf (stderr,_("%s: \"%s\" matrix not found!\n"), ifname, name); + return 0; +} + +int CLASS foveon_fixed (void *ptr, int size, const char *name) +{ + void *dp; + unsigned dim[3]; + + if (!name) return 0; + dp = foveon_camf_matrix (dim, name); + if (!dp) return 0; + memcpy (ptr, dp, size*4); + free (dp); + return 1; +} + +float CLASS foveon_avg (short *pix, int range[2], float cfilt) +{ + int i; + float val, min=FLT_MAX, max=-FLT_MAX, sum=0; + + for (i=range[0]; i <= range[1]; i++) { + sum += val = pix[i*4] + (pix[i*4]-pix[(i-1)*4]) * cfilt; + if (min > val) min = val; + if (max < val) max = val; + } + if (range[1] - range[0] == 1) return sum/2; + return (sum - min - max) / (range[1] - range[0] - 1); +} + +short * CLASS foveon_make_curve (double max, double mul, double filt) +{ + short *curve; + unsigned i, size; + double x; + + if (!filt) filt = 0.8; + size = 4*M_PI*max / filt; + if (size == UINT_MAX) size--; + curve = (short *) calloc (size+1, sizeof *curve); + merror (curve, "foveon_make_curve()"); + curve[0] = size; + for (i=0; i < size; i++) { + x = i*filt/max/4; + curve[i+1] = (cos(x)+1)/2 * tanh(i*filt/mul) * mul + 0.5; + } + return curve; +} + +void CLASS foveon_make_curves + (short **curvep, float dq[3], float div[3], float filt) +{ + double mul[3], max=0; + int c; + + FORC3 mul[c] = dq[c]/div[c]; + FORC3 if (max < mul[c]) max = mul[c]; + FORC3 curvep[c] = foveon_make_curve (max, mul[c], filt); +} + +int CLASS foveon_apply_curve (short *curve, int i) +{ + if (abs(i) >= curve[0]) return 0; + return i < 0 ? -curve[1-i] : curve[1+i]; +} + +#define image ((short (*)[4]) image) + +void CLASS foveon_interpolate() +{ + static const short hood[] = { -1,-1, -1,0, -1,1, 0,-1, 0,1, 1,-1, 1,0, 1,1 }; + short *pix, prev[3], *curve[8], (*shrink)[3]; + float cfilt=0, ddft[3][3][2], ppm[3][3][3]; + float cam_xyz[3][3], correct[3][3], last[3][3], trans[3][3]; + float chroma_dq[3], color_dq[3], diag[3][3], div[3]; + float (*black)[3], (*sgain)[3], (*sgrow)[3]; + float fsum[3], val, frow, num; + int row, col, c, i, j, diff, sgx, irow, sum, min, max, limit; + int dscr[2][2], dstb[4], (*smrow[7])[3], total[4], ipix[3]; + int work[3][3], smlast, smred, smred_p=0, dev[3]; + int satlev[3], keep[4], active[4]; + unsigned dim[3], *badpix; + double dsum=0, trsum[3]; + char str[128]; + const char* cp; + + if (verbose) + fprintf (stderr,_("Foveon interpolation...\n")); + + foveon_load_camf(); + foveon_fixed (dscr, 4, "DarkShieldColRange"); + foveon_fixed (ppm[0][0], 27, "PostPolyMatrix"); + foveon_fixed (satlev, 3, "SaturationLevel"); + foveon_fixed (keep, 4, "KeepImageArea"); + foveon_fixed (active, 4, "ActiveImageArea"); + foveon_fixed (chroma_dq, 3, "ChromaDQ"); + foveon_fixed (color_dq, 3, + foveon_camf_param ("IncludeBlocks", "ColorDQ") ? + "ColorDQ" : "ColorDQCamRGB"); + if (foveon_camf_param ("IncludeBlocks", "ColumnFilter")) + foveon_fixed (&cfilt, 1, "ColumnFilter"); + + memset (ddft, 0, sizeof ddft); + if (!foveon_camf_param ("IncludeBlocks", "DarkDrift") + || !foveon_fixed (ddft[1][0], 12, "DarkDrift")) + for (i=0; i < 2; i++) { + foveon_fixed (dstb, 4, i ? "DarkShieldBottom":"DarkShieldTop"); + for (row = dstb[1]; row <= dstb[3]; row++) + for (col = dstb[0]; col <= dstb[2]; col++) + FORC3 ddft[i+1][c][1] += (short) image[row*width+col][c]; + FORC3 ddft[i+1][c][1] /= (dstb[3]-dstb[1]+1) * (dstb[2]-dstb[0]+1); + } + + if (!(cp = foveon_camf_param ("WhiteBalanceIlluminants", model2))) + { fprintf (stderr,_("%s: Invalid white balance \"%s\"\n"), ifname, model2); + return; } + foveon_fixed (cam_xyz, 9, cp); + foveon_fixed (correct, 9, + foveon_camf_param ("WhiteBalanceCorrections", model2)); + memset (last, 0, sizeof last); + for (i=0; i < 3; i++) + for (j=0; j < 3; j++) + FORC3 last[i][j] += correct[i][c] * cam_xyz[c][j]; + + #define LAST(x,y) last[(i+x)%3][(c+y)%3] + for (i=0; i < 3; i++) + FORC3 diag[c][i] = LAST(1,1)*LAST(2,2) - LAST(1,2)*LAST(2,1); + #undef LAST + FORC3 div[c] = diag[c][0]*0.3127 + diag[c][1]*0.329 + diag[c][2]*0.3583; + sprintf (str, "%sRGBNeutral", model2); + if (foveon_camf_param ("IncludeBlocks", str)) + foveon_fixed (div, 3, str); + num = 0; + FORC3 if (num < div[c]) num = div[c]; + FORC3 div[c] /= num; + + memset (trans, 0, sizeof trans); + for (i=0; i < 3; i++) + for (j=0; j < 3; j++) + FORC3 trans[i][j] += rgb_cam[i][c] * last[c][j] * div[j]; + FORC3 trsum[c] = trans[c][0] + trans[c][1] + trans[c][2]; + dsum = (6*trsum[0] + 11*trsum[1] + 3*trsum[2]) / 20; + for (i=0; i < 3; i++) + FORC3 last[i][c] = trans[i][c] * dsum / trsum[i]; + memset (trans, 0, sizeof trans); + for (i=0; i < 3; i++) + for (j=0; j < 3; j++) + FORC3 trans[i][j] += (i==c ? 32 : -1) * last[c][j] / 30; + + foveon_make_curves (curve, color_dq, div, cfilt); + FORC3 chroma_dq[c] /= 3; + foveon_make_curves (curve+3, chroma_dq, div, cfilt); + FORC3 dsum += chroma_dq[c] / div[c]; + curve[6] = foveon_make_curve (dsum, dsum, cfilt); + curve[7] = foveon_make_curve (dsum*2, dsum*2, cfilt); + + sgain = (float (*)[3]) foveon_camf_matrix (dim, "SpatialGain"); + if (!sgain) return; + sgrow = (float (*)[3]) calloc (dim[1], sizeof *sgrow); + sgx = (width + dim[1]-2) / (dim[1]-1); + + black = (float (*)[3]) calloc (height, sizeof *black); + for (row=0; row < height; row++) { + for (i=0; i < 6; i++) + ddft[0][0][i] = ddft[1][0][i] + + row / (height-1.0) * (ddft[2][0][i] - ddft[1][0][i]); + FORC3 black[row][c] = + ( foveon_avg (image[row*width]+c, dscr[0], cfilt) + + foveon_avg (image[row*width]+c, dscr[1], cfilt) * 3 + - ddft[0][c][0] ) / 4 - ddft[0][c][1]; + } + memcpy (black, black+8, sizeof *black*8); + memcpy (black+height-11, black+height-22, 11*sizeof *black); + memcpy (last, black, sizeof last); + + for (row=1; row < height-1; row++) { + FORC3 if (last[1][c] > last[0][c]) { + if (last[1][c] > last[2][c]) + black[row][c] = (last[0][c] > last[2][c]) ? last[0][c]:last[2][c]; + } else + if (last[1][c] < last[2][c]) + black[row][c] = (last[0][c] < last[2][c]) ? last[0][c]:last[2][c]; + memmove (last, last+1, 2*sizeof last[0]); + memcpy (last[2], black[row+1], sizeof last[2]); + } + FORC3 black[row][c] = (last[0][c] + last[1][c])/2; + FORC3 black[0][c] = (black[1][c] + black[3][c])/2; + + val = 1 - exp(-1/24.0); + memcpy (fsum, black, sizeof fsum); + for (row=1; row < height; row++) + FORC3 fsum[c] += black[row][c] = + (black[row][c] - black[row-1][c])*val + black[row-1][c]; + memcpy (last[0], black[height-1], sizeof last[0]); + FORC3 fsum[c] /= height; + for (row = height; row--; ) + FORC3 last[0][c] = black[row][c] = + (black[row][c] - fsum[c] - last[0][c])*val + last[0][c]; + + memset (total, 0, sizeof total); + for (row=2; row < height; row+=4) + for (col=2; col < width; col+=4) { + FORC3 total[c] += (short) image[row*width+col][c]; + total[3]++; + } + for (row=0; row < height; row++) + FORC3 black[row][c] += fsum[c]/2 + total[c]/(total[3]*100.0); + + for (row=0; row < height; row++) { + for (i=0; i < 6; i++) + ddft[0][0][i] = ddft[1][0][i] + + row / (height-1.0) * (ddft[2][0][i] - ddft[1][0][i]); + pix = image[row*width]; + memcpy (prev, pix, sizeof prev); + frow = row / (height-1.0) * (dim[2]-1); + if ((irow = frow) == dim[2]-1) irow--; + frow -= irow; + for (i=0; i < dim[1]; i++) + FORC3 sgrow[i][c] = sgain[ irow *dim[1]+i][c] * (1-frow) + + sgain[(irow+1)*dim[1]+i][c] * frow; + for (col=0; col < width; col++) { + FORC3 { + diff = pix[c] - prev[c]; + prev[c] = pix[c]; + ipix[c] = pix[c] + floor ((diff + (diff*diff >> 14)) * cfilt + - ddft[0][c][1] - ddft[0][c][0] * ((float) col/width - 0.5) + - black[row][c] ); + } + FORC3 { + work[0][c] = ipix[c] * ipix[c] >> 14; + work[2][c] = ipix[c] * work[0][c] >> 14; + work[1][2-c] = ipix[(c+1) % 3] * ipix[(c+2) % 3] >> 14; + } + FORC3 { + for (val=i=0; i < 3; i++) + for ( j=0; j < 3; j++) + val += ppm[c][i][j] * work[i][j]; + ipix[c] = floor ((ipix[c] + floor(val)) * + ( sgrow[col/sgx ][c] * (sgx - col%sgx) + + sgrow[col/sgx+1][c] * (col%sgx) ) / sgx / div[c]); + if (ipix[c] > 32000) ipix[c] = 32000; + pix[c] = ipix[c]; + } + pix += 4; + } + } + free (black); + free (sgrow); + free (sgain); + + if ((badpix = (unsigned int *) foveon_camf_matrix (dim, "BadPixels"))) { + for (i=0; i < dim[0]; i++) { + col = (badpix[i] >> 8 & 0xfff) - keep[0]; + row = (badpix[i] >> 20 ) - keep[1]; + if ((unsigned)(row-1) > height-3 || (unsigned)(col-1) > width-3) + continue; + memset (fsum, 0, sizeof fsum); + for (sum=j=0; j < 8; j++) + if (badpix[i] & (1 << j)) { + FORC3 fsum[c] += (short) + image[(row+hood[j*2])*width+col+hood[j*2+1]][c]; + sum++; + } + if (sum) FORC3 image[row*width+col][c] = fsum[c]/sum; + } + free (badpix); + } + + /* Array for 5x5 Gaussian averaging of red values */ + smrow[6] = (int (*)[3]) calloc (width*5, sizeof **smrow); + merror (smrow[6], "foveon_interpolate()"); + for (i=0; i < 5; i++) + smrow[i] = smrow[6] + i*width; + + /* Sharpen the reds against these Gaussian averages */ + for (smlast=-1, row=2; row < height-2; row++) { + while (smlast < row+2) { + for (i=0; i < 6; i++) + smrow[(i+5) % 6] = smrow[i]; + pix = image[++smlast*width+2]; + for (col=2; col < width-2; col++) { + smrow[4][col][0] = + (pix[0]*6 + (pix[-4]+pix[4])*4 + pix[-8]+pix[8] + 8) >> 4; + pix += 4; + } + } + pix = image[row*width+2]; + for (col=2; col < width-2; col++) { + smred = ( 6 * smrow[2][col][0] + + 4 * (smrow[1][col][0] + smrow[3][col][0]) + + smrow[0][col][0] + smrow[4][col][0] + 8 ) >> 4; + if (col == 2) + smred_p = smred; + i = pix[0] + ((pix[0] - ((smred*7 + smred_p) >> 3)) >> 3); + if (i > 32000) i = 32000; + pix[0] = i; + smred_p = smred; + pix += 4; + } + } + + /* Adjust the brighter pixels for better linearity */ + min = 0xffff; + FORC3 { + i = satlev[c] / div[c]; + if (min > i) min = i; + } + limit = min * 9 >> 4; + for (pix=image[0]; pix < image[height*width]; pix+=4) { + if (pix[0] <= limit || pix[1] <= limit || pix[2] <= limit) + continue; + min = max = pix[0]; + for (c=1; c < 3; c++) { + if (min > pix[c]) min = pix[c]; + if (max < pix[c]) max = pix[c]; + } + if (min >= limit*2) { + pix[0] = pix[1] = pix[2] = max; + } else { + i = 0x4000 - ((min - limit) << 14) / limit; + i = 0x4000 - (i*i >> 14); + i = i*i >> 14; + FORC3 pix[c] += (max - pix[c]) * i >> 14; + } + } +/* + Because photons that miss one detector often hit another, + the sum R+G+B is much less noisy than the individual colors. + So smooth the hues without smoothing the total. + */ + for (smlast=-1, row=2; row < height-2; row++) { + while (smlast < row+2) { + for (i=0; i < 6; i++) + smrow[(i+5) % 6] = smrow[i]; + pix = image[++smlast*width+2]; + for (col=2; col < width-2; col++) { + FORC3 smrow[4][col][c] = (pix[c-4]+2*pix[c]+pix[c+4]+2) >> 2; + pix += 4; + } + } + pix = image[row*width+2]; + for (col=2; col < width-2; col++) { + FORC3 dev[c] = -foveon_apply_curve (curve[7], pix[c] - + ((smrow[1][col][c] + 2*smrow[2][col][c] + smrow[3][col][c]) >> 2)); + sum = (dev[0] + dev[1] + dev[2]) >> 3; + FORC3 pix[c] += dev[c] - sum; + pix += 4; + } + } + for (smlast=-1, row=2; row < height-2; row++) { + while (smlast < row+2) { + for (i=0; i < 6; i++) + smrow[(i+5) % 6] = smrow[i]; + pix = image[++smlast*width+2]; + for (col=2; col < width-2; col++) { + FORC3 smrow[4][col][c] = + (pix[c-8]+pix[c-4]+pix[c]+pix[c+4]+pix[c+8]+2) >> 2; + pix += 4; + } + } + pix = image[row*width+2]; + for (col=2; col < width-2; col++) { + for (total[3]=375, sum=60, c=0; c < 3; c++) { + for (total[c]=i=0; i < 5; i++) + total[c] += smrow[i][col][c]; + total[3] += total[c]; + sum += pix[c]; + } + if (sum < 0) sum = 0; + j = total[3] > 375 ? (sum << 16) / total[3] : sum * 174; + FORC3 pix[c] += foveon_apply_curve (curve[6], + ((j*total[c] + 0x8000) >> 16) - pix[c]); + pix += 4; + } + } + + /* Transform the image to a different colorspace */ + for (pix=image[0]; pix < image[height*width]; pix+=4) { + FORC3 pix[c] -= foveon_apply_curve (curve[c], pix[c]); + sum = (pix[0]+pix[1]+pix[1]+pix[2]) >> 2; + FORC3 pix[c] -= foveon_apply_curve (curve[c], pix[c]-sum); + FORC3 { + for (dsum=i=0; i < 3; i++) + dsum += trans[c][i] * pix[i]; + if (dsum < 0) dsum = 0; + if (dsum > 24000) dsum = 24000; + ipix[c] = dsum + 0.5; + } + FORC3 pix[c] = ipix[c]; + } + + /* Smooth the image bottom-to-top and save at 1/4 scale */ + shrink = (short (*)[3]) calloc ((width/4) * (height/4), sizeof *shrink); + merror (shrink, "foveon_interpolate()"); + for (row = height/4; row--; ) + for (col=0; col < width/4; col++) { + ipix[0] = ipix[1] = ipix[2] = 0; + for (i=0; i < 4; i++) + for (j=0; j < 4; j++) + FORC3 ipix[c] += image[(row*4+i)*width+col*4+j][c]; + FORC3 + if (row+2 > height/4) + shrink[row*(width/4)+col][c] = ipix[c] >> 4; + else + shrink[row*(width/4)+col][c] = + (shrink[(row+1)*(width/4)+col][c]*1840 + ipix[c]*141 + 2048) >> 12; + } + /* From the 1/4-scale image, smooth right-to-left */ + for (row=0; row < (height & ~3); row++) { + ipix[0] = ipix[1] = ipix[2] = 0; + if ((row & 3) == 0) + for (col = width & ~3 ; col--; ) + FORC3 smrow[0][col][c] = ipix[c] = + (shrink[(row/4)*(width/4)+col/4][c]*1485 + ipix[c]*6707 + 4096) >> 13; + + /* Then smooth left-to-right */ + ipix[0] = ipix[1] = ipix[2] = 0; + for (col=0; col < (width & ~3); col++) + FORC3 smrow[1][col][c] = ipix[c] = + (smrow[0][col][c]*1485 + ipix[c]*6707 + 4096) >> 13; + + /* Smooth top-to-bottom */ + if (row == 0) + memcpy (smrow[2], smrow[1], sizeof **smrow * width); + else + for (col=0; col < (width & ~3); col++) + FORC3 smrow[2][col][c] = + (smrow[2][col][c]*6707 + smrow[1][col][c]*1485 + 4096) >> 13; + + /* Adjust the chroma toward the smooth values */ + for (col=0; col < (width & ~3); col++) { + for (i=j=30, c=0; c < 3; c++) { + i += smrow[2][col][c]; + j += image[row*width+col][c]; + } + j = (j << 16) / i; + for (sum=c=0; c < 3; c++) { + ipix[c] = foveon_apply_curve (curve[c+3], + ((smrow[2][col][c] * j + 0x8000) >> 16) - image[row*width+col][c]); + sum += ipix[c]; + } + sum >>= 3; + FORC3 { + i = image[row*width+col][c] + ipix[c] - sum; + if (i < 0) i = 0; + image[row*width+col][c] = i; + } + } + } + free (shrink); + free (smrow[6]); + for (i=0; i < 8; i++) + free (curve[i]); + + /* Trim off the black border */ + active[1] -= keep[1]; + active[3] -= 2; + i = active[2] - active[0]; + for (row=0; row < active[3]-active[1]; row++) + memcpy (image[row*i], image[(row+active[1])*width+active[0]], + i * sizeof *image); + width = i; + height = row; +} +#undef image + +/* RESTRICTED code ends here */ + +void CLASS crop_masked_pixels() +{ + int row, col; + unsigned r, c, m, mblack[8], zero, val; + + if (load_raw == &CLASS phase_one_load_raw || + load_raw == &CLASS phase_one_load_raw_c) + phase_one_correct(); + if (fuji_width) { + for (row=0; row < raw_height-top_margin*2; row++) { + for (col=0; col < fuji_width << !fuji_layout; col++) { + if (fuji_layout) { + r = fuji_width - 1 - col + (row >> 1); + c = col + ((row+1) >> 1); + } else { + r = fuji_width - 1 + row - (col >> 1); + c = row + ((col+1) >> 1); + } + if (r < height && c < width) + BAYER(r,c) = RAW(row+top_margin,col+left_margin); + } + } + } else { + for (row=0; row < height; row++) + for (col=0; col < width; col++) + BAYER2(row,col) = RAW(row+top_margin,col+left_margin); + } + if (mask[0][3]) goto mask_set; + if (load_raw == &CLASS canon_load_raw || + load_raw == &CLASS lossless_jpeg_load_raw) { + mask[0][1] = mask[1][1] = 2; + mask[0][3] = -2; + goto sides; + } + if (load_raw == &CLASS sony_load_raw) { + mask[0][3] = 9; + goto sides; + } + if (load_raw == &CLASS canon_600_load_raw || + (load_raw == &CLASS eight_bit_load_raw && strncmp(model,"DC2",3)) || + load_raw == &CLASS kodak_262_load_raw || + (load_raw == &CLASS packed_load_raw && (load_flags & 32))) { +sides: + mask[0][0] = mask[1][0] = top_margin; + mask[0][2] = mask[1][2] = top_margin+height; + mask[0][3] += left_margin; + mask[1][1] += left_margin+width; + mask[1][3] += raw_width; + } + if (load_raw == &CLASS nokia_load_raw) { + mask[0][2] = top_margin; + mask[0][3] = width; + } +mask_set: + memset (mblack, 0, sizeof mblack); + for (zero=m=0; m < 8; m++) + for (row=mask[m][0]; row < mask[m][2]; row++) + for (col=mask[m][1]; col < mask[m][3]; col++) { + c = FC(row-top_margin,col-left_margin); + mblack[c] += val = RAW(row,col); + mblack[4+c]++; + zero += !val; + } + if (load_raw == &CLASS canon_600_load_raw && width < raw_width) { + black = (mblack[0]+mblack[1]+mblack[2]+mblack[3]) / + (mblack[4]+mblack[5]+mblack[6]+mblack[7]) - 4; + canon_600_correct(); + } else if (zero < mblack[4] && mblack[5] && mblack[6] && mblack[7]) + FORC4 cblack[c] = mblack[c] / mblack[4+c]; +} + +void CLASS remove_zeroes() +{ + unsigned row, col, tot, n, r, c; + + for (row=0; row < height; row++) + for (col=0; col < width; col++) + if (BAYER(row,col) == 0) { + tot = n = 0; + for (r = row-2; r <= row+2; r++) + for (c = col-2; c <= col+2; c++) + if (r < height && c < width && + FC(r,c) == FC(row,col) && BAYER(r,c)) + tot += (n++,BAYER(r,c)); + if (n) BAYER(row,col) = tot/n; + } +} + +/* + Seach from the current directory up to the root looking for + a ".badpixels" file, and fix those pixels now. + */ +void CLASS bad_pixels (const char *cfname) +{ + FILE *fp=0; + char *fname, *cp, line[128]; + int len, time, row, col, r, c, rad, tot, n, fixed=0; + + if (!filters) return; + if (cfname) + fp = fopen (cfname, "r"); + else { + for (len=32 ; ; len *= 2) { + fname = (char *) malloc (len); + if (!fname) return; + if (getcwd (fname, len-16)) break; + free (fname); + if (errno != ERANGE) return; + } +#if defined(WIN32) || defined(DJGPP) + if (fname[1] == ':') + memmove (fname, fname+2, len-2); + for (cp=fname; *cp; cp++) + if (*cp == '\\') *cp = '/'; +#endif + cp = fname + strlen(fname); + if (cp[-1] == '/') cp--; + while (*fname == '/') { + strcpy (cp, "/.badpixels"); + if ((fp = fopen (fname, "r"))) break; + if (cp == fname) break; + while (*--cp != '/'); + } + free (fname); + } + if (!fp) return; + while (fgets (line, 128, fp)) { + cp = strchr (line, '#'); + if (cp) *cp = 0; + if (sscanf (line, "%d %d %d", &col, &row, &time) != 3) continue; + if ((unsigned) col >= width || (unsigned) row >= height) continue; + if (time > timestamp) continue; + for (tot=n=0, rad=1; rad < 3 && n==0; rad++) + for (r = row-rad; r <= row+rad; r++) + for (c = col-rad; c <= col+rad; c++) + if ((unsigned) r < height && (unsigned) c < width && + (r != row || c != col) && fcol(r,c) == fcol(row,col)) { + tot += BAYER2(r,c); + n++; + } + BAYER2(row,col) = tot/n; + if (verbose) { + if (!fixed++) + fprintf (stderr,_("Fixed dead pixels at:")); + fprintf (stderr, " %d,%d", col, row); + } + } + if (fixed) fputc ('\n', stderr); + fclose (fp); +} + +void CLASS subtract (const char *fname) +{ + FILE *fp; + int dim[3]={0,0,0}, comment=0, number=0, error=0, nd=0, c, row, col; + ushort *pixel; + + if (!(fp = fopen (fname, "rb"))) { + perror (fname); return; + } + if (fgetc(fp) != 'P' || fgetc(fp) != '5') error = 1; + while (!error && nd < 3 && (c = fgetc(fp)) != EOF) { + if (c == '#') comment = 1; + if (c == '\n') comment = 0; + if (comment) continue; + if (isdigit(c)) number = 1; + if (number) { + if (isdigit(c)) dim[nd] = dim[nd]*10 + c -'0'; + else if (isspace(c)) { + number = 0; nd++; + } else error = 1; + } + } + if (error || nd < 3) { + fprintf (stderr,_("%s is not a valid PGM file!\n"), fname); + fclose (fp); return; + } else if (dim[0] != width || dim[1] != height || dim[2] != 65535) { + fprintf (stderr,_("%s has the wrong dimensions!\n"), fname); + fclose (fp); return; + } + pixel = (ushort *) calloc (width, sizeof *pixel); + merror (pixel, "subtract()"); + for (row=0; row < height; row++) { + fread (pixel, 2, width, fp); + for (col=0; col < width; col++) + BAYER(row,col) = MAX (BAYER(row,col) - ntohs(pixel[col]), 0); + } + free (pixel); + fclose (fp); + memset (cblack, 0, sizeof cblack); + black = 0; +} + +void CLASS gamma_curve (double pwr, double ts, int mode, int imax) +{ + int i; + double g[6], bnd[2]={0,0}, r; + + g[0] = pwr; + g[1] = ts; + g[2] = g[3] = g[4] = 0; + bnd[g[1] >= 1] = 1; + if (g[1] && (g[1]-1)*(g[0]-1) <= 0) { + for (i=0; i < 48; i++) { + g[2] = (bnd[0] + bnd[1])/2; + if (g[0]) bnd[(pow(g[2]/g[1],-g[0]) - 1)/g[0] - 1/g[2] > -1] = g[2]; + else bnd[g[2]/exp(1-1/g[2]) < g[1]] = g[2]; + } + g[3] = g[2] / g[1]; + if (g[0]) g[4] = g[2] * (1/g[0] - 1); + } + if (g[0]) g[5] = 1 / (g[1]*SQR(g[3])/2 - g[4]*(1 - g[3]) + + (1 - pow(g[3],1+g[0]))*(1 + g[4])/(1 + g[0])) - 1; + else g[5] = 1 / (g[1]*SQR(g[3])/2 + 1 + - g[2] - g[3] - g[2]*g[3]*(log(g[3]) - 1)) - 1; + if (!mode--) { + memcpy (gamm, g, sizeof gamm); + return; + } + for (i=0; i < 0x10000; i++) { + curve[i] = 0xffff; + if ((r = (double) i / imax) < 1) + curve[i] = 0x10000 * ( mode + ? (r < g[3] ? r*g[1] : (g[0] ? pow( r,g[0])*(1+g[4])-g[4] : log(r)*g[2]+1)) + : (r < g[2] ? r/g[1] : (g[0] ? pow((r+g[4])/(1+g[4]),1/g[0]) : exp((r-1)/g[2])))); + } +} + +void CLASS pseudoinverse (double (*in)[3], double (*out)[3], int size) +{ + double work[3][6], num; + int i, j, k; + + for (i=0; i < 3; i++) { + for (j=0; j < 6; j++) + work[i][j] = j == i+3; + for (j=0; j < 3; j++) + for (k=0; k < size; k++) + work[i][j] += in[k][i] * in[k][j]; + } + for (i=0; i < 3; i++) { + num = work[i][i]; + for (j=0; j < 6; j++) + work[i][j] /= num; + for (k=0; k < 3; k++) { + if (k==i) continue; + num = work[k][i]; + for (j=0; j < 6; j++) + work[k][j] -= work[i][j] * num; + } + } + for (i=0; i < size; i++) + for (j=0; j < 3; j++) + for (out[i][j]=k=0; k < 3; k++) + out[i][j] += work[j][k+3] * in[i][k]; +} + +void CLASS cam_xyz_coeff (double cam_xyz[4][3]) +{ + double cam_rgb[4][3], inverse[4][3], num; + int i, j, k; + + for (i=0; i < colors; i++) /* Multiply out XYZ colorspace */ + for (j=0; j < 3; j++) + for (cam_rgb[i][j] = k=0; k < 3; k++) + cam_rgb[i][j] += cam_xyz[i][k] * xyz_rgb[k][j]; + + for (i=0; i < colors; i++) { /* Normalize cam_rgb so that */ + for (num=j=0; j < 3; j++) /* cam_rgb * (1,1,1) is (1,1,1,1) */ + num += cam_rgb[i][j]; + for (j=0; j < 3; j++) + cam_rgb[i][j] /= num; + pre_mul[i] = 1 / num; + } + pseudoinverse (cam_rgb, inverse, colors); + for (raw_color = i=0; i < 3; i++) + for (j=0; j < colors; j++) + rgb_cam[i][j] = inverse[j][i]; +} + +#ifdef COLORCHECK +void CLASS colorcheck() +{ +#define NSQ 24 +// Coordinates of the GretagMacbeth ColorChecker squares +// width, height, 1st_column, 1st_row + int cut[NSQ][4]; // you must set these +// ColorChecker Chart under 6500-kelvin illumination + static const double gmb_xyY[NSQ][3] = { + { 0.400, 0.350, 10.1 }, // Dark Skin + { 0.377, 0.345, 35.8 }, // Light Skin + { 0.247, 0.251, 19.3 }, // Blue Sky + { 0.337, 0.422, 13.3 }, // Foliage + { 0.265, 0.240, 24.3 }, // Blue Flower + { 0.261, 0.343, 43.1 }, // Bluish Green + { 0.506, 0.407, 30.1 }, // Orange + { 0.211, 0.175, 12.0 }, // Purplish Blue + { 0.453, 0.306, 19.8 }, // Moderate Red + { 0.285, 0.202, 6.6 }, // Purple + { 0.380, 0.489, 44.3 }, // Yellow Green + { 0.473, 0.438, 43.1 }, // Orange Yellow + { 0.187, 0.129, 6.1 }, // Blue + { 0.305, 0.478, 23.4 }, // Green + { 0.539, 0.313, 12.0 }, // Red + { 0.448, 0.470, 59.1 }, // Yellow + { 0.364, 0.233, 19.8 }, // Magenta + { 0.196, 0.252, 19.8 }, // Cyan + { 0.310, 0.316, 90.0 }, // White + { 0.310, 0.316, 59.1 }, // Neutral 8 + { 0.310, 0.316, 36.2 }, // Neutral 6.5 + { 0.310, 0.316, 19.8 }, // Neutral 5 + { 0.310, 0.316, 9.0 }, // Neutral 3.5 + { 0.310, 0.316, 3.1 } }; // Black + double gmb_cam[NSQ][4], gmb_xyz[NSQ][3]; + double inverse[NSQ][3], cam_xyz[4][3], num; + int c, i, j, k, sq, row, col, count[4]; + + memset (gmb_cam, 0, sizeof gmb_cam); + for (sq=0; sq < NSQ; sq++) { + FORCC count[c] = 0; + for (row=cut[sq][3]; row < cut[sq][3]+cut[sq][1]; row++) + for (col=cut[sq][2]; col < cut[sq][2]+cut[sq][0]; col++) { + c = FC(row,col); + if (c >= colors) c -= 2; + gmb_cam[sq][c] += BAYER(row,col); + count[c]++; + } + FORCC gmb_cam[sq][c] = gmb_cam[sq][c]/count[c] - black; + gmb_xyz[sq][0] = gmb_xyY[sq][2] * gmb_xyY[sq][0] / gmb_xyY[sq][1]; + gmb_xyz[sq][1] = gmb_xyY[sq][2]; + gmb_xyz[sq][2] = gmb_xyY[sq][2] * + (1 - gmb_xyY[sq][0] - gmb_xyY[sq][1]) / gmb_xyY[sq][1]; + } + pseudoinverse (gmb_xyz, inverse, NSQ); + for (i=0; i < colors; i++) + for (j=0; j < 3; j++) + for (cam_xyz[i][j] = k=0; k < NSQ; k++) + cam_xyz[i][j] += gmb_cam[k][i] * inverse[k][j]; + cam_xyz_coeff (cam_xyz); + if (verbose) { + printf (" { \"%s %s\", %d,\n\t{", make, model, black); + num = 10000 / (cam_xyz[1][0] + cam_xyz[1][1] + cam_xyz[1][2]); + FORCC for (j=0; j < 3; j++) + printf ("%c%d", (c | j) ? ',':' ', (int) (cam_xyz[c][j] * num + 0.5)); + puts (" } },"); + } +#undef NSQ +} +#endif + +void CLASS hat_transform (float *temp, float *base, int st, int size, int sc) +{ + int i; + for (i=0; i < sc; i++) + temp[i] = 2*base[st*i] + base[st*(sc-i)] + base[st*(i+sc)]; + for (; i+sc < size; i++) + temp[i] = 2*base[st*i] + base[st*(i-sc)] + base[st*(i+sc)]; + for (; i < size; i++) + temp[i] = 2*base[st*i] + base[st*(i-sc)] + base[st*(2*size-2-(i+sc))]; +} + +void CLASS wavelet_denoise() +{ + float *fimg=0, *temp, thold, mul[2], avg, diff; + int scale=1, size, lev, hpass, lpass, row, col, nc, c, i, wlast, blk[2]; + ushort *window[4]; + static const float noise[] = + { 0.8002,0.2735,0.1202,0.0585,0.0291,0.0152,0.0080,0.0044 }; + + if (verbose) fprintf (stderr,_("Wavelet denoising...\n")); + + while (maximum << scale < 0x10000) scale++; + maximum <<= --scale; + black <<= scale; + FORC4 cblack[c] <<= scale; + if ((size = iheight*iwidth) < 0x15550000) + fimg = (float *) malloc ((size*3 + iheight + iwidth) * sizeof *fimg); + merror (fimg, "wavelet_denoise()"); + temp = fimg + size*3; + if ((nc = colors) == 3 && filters) nc++; + FORC(nc) { /* denoise R,G1,B,G3 individually */ + for (i=0; i < size; i++) + fimg[i] = 256 * sqrt(image[i][c] << scale); + for (hpass=lev=0; lev < 5; lev++) { + lpass = size*((lev & 1)+1); + for (row=0; row < iheight; row++) { + hat_transform (temp, fimg+hpass+row*iwidth, 1, iwidth, 1 << lev); + for (col=0; col < iwidth; col++) + fimg[lpass + row*iwidth + col] = temp[col] * 0.25; + } + for (col=0; col < iwidth; col++) { + hat_transform (temp, fimg+lpass+col, iwidth, iheight, 1 << lev); + for (row=0; row < iheight; row++) + fimg[lpass + row*iwidth + col] = temp[row] * 0.25; + } + thold = threshold * noise[lev]; + for (i=0; i < size; i++) { + fimg[hpass+i] -= fimg[lpass+i]; + if (fimg[hpass+i] < -thold) fimg[hpass+i] += thold; + else if (fimg[hpass+i] > thold) fimg[hpass+i] -= thold; + else fimg[hpass+i] = 0; + if (hpass) fimg[i] += fimg[hpass+i]; + } + hpass = lpass; + } + for (i=0; i < size; i++) + image[i][c] = CLIP(SQR(fimg[i]+fimg[lpass+i])/0x10000); + } + if (filters && colors == 3) { /* pull G1 and G3 closer together */ + for (row=0; row < 2; row++) { + mul[row] = 0.125 * pre_mul[FC(row+1,0) | 1] / pre_mul[FC(row,0) | 1]; + blk[row] = cblack[FC(row,0) | 1]; + } + for (i=0; i < 4; i++) + window[i] = (ushort *) fimg + width*i; + for (wlast=-1, row=1; row < height-1; row++) { + while (wlast < row+1) { + for (wlast++, i=0; i < 4; i++) + window[(i+3) & 3] = window[i]; + for (col = FC(wlast,1) & 1; col < width; col+=2) + window[2][col] = BAYER(wlast,col); + } + thold = threshold/512; + for (col = (FC(row,0) & 1)+1; col < width-1; col+=2) { + avg = ( window[0][col-1] + window[0][col+1] + + window[2][col-1] + window[2][col+1] - blk[~row & 1]*4 ) + * mul[row & 1] + (window[1][col] + blk[row & 1]) * 0.5; + avg = avg < 0 ? 0 : sqrt(avg); + diff = sqrt(BAYER(row,col)) - avg; + if (diff < -thold) diff += thold; + else if (diff > thold) diff -= thold; + else diff = 0; + BAYER(row,col) = CLIP(SQR(avg+diff) + 0.5); + } + } + } + free (fimg); +} + +void CLASS scale_colors() +{ + unsigned bottom, right, size, row, col, ur, uc, i, x, y, c, sum[8]; + int val, dark, sat; + double dsum[8], dmin, dmax; + float scale_mul[4], fr, fc; + ushort *img=0, *pix; + + if (user_mul[0]) + memcpy (pre_mul, user_mul, sizeof pre_mul); + if (use_auto_wb || (use_camera_wb && cam_mul[0] == -1)) { + memset (dsum, 0, sizeof dsum); + bottom = MIN (greybox[1]+greybox[3], height); + right = MIN (greybox[0]+greybox[2], width); + for (row=greybox[1]; row < bottom; row += 8) + for (col=greybox[0]; col < right; col += 8) { + memset (sum, 0, sizeof sum); + for (y=row; y < row+8 && y < bottom; y++) + for (x=col; x < col+8 && x < right; x++) + FORC4 { + if (filters) { + c = fcol(y,x); + val = BAYER2(y,x); + } else + val = image[y*width+x][c]; + if (val > maximum-25) goto skip_block; + if ((val -= cblack[c]) < 0) val = 0; + sum[c] += val; + sum[c+4]++; + if (filters) break; + } + FORC(8) dsum[c] += sum[c]; +skip_block: ; + } + FORC4 if (dsum[c]) pre_mul[c] = dsum[c+4] / dsum[c]; + } + if (use_camera_wb && cam_mul[0] != -1) { + memset (sum, 0, sizeof sum); + for (row=0; row < 8; row++) + for (col=0; col < 8; col++) { + c = FC(row,col); + if ((val = white[row][col] - cblack[c]) > 0) + sum[c] += val; + sum[c+4]++; + } + if (sum[0] && sum[1] && sum[2] && sum[3]) + FORC4 pre_mul[c] = (float) sum[c+4] / sum[c]; + else if (cam_mul[0] && cam_mul[2]) + memcpy (pre_mul, cam_mul, sizeof pre_mul); + else + fprintf (stderr,_("%s: Cannot use camera white balance.\n"), ifname); + } + if (pre_mul[3] == 0) pre_mul[3] = colors < 4 ? pre_mul[1] : 1; + dark = black; + sat = maximum; + if (threshold) wavelet_denoise(); + maximum -= black; + for (dmin=DBL_MAX, dmax=c=0; c < 4; c++) { + if (dmin > pre_mul[c]) + dmin = pre_mul[c]; + if (dmax < pre_mul[c]) + dmax = pre_mul[c]; + } + if (!highlight) dmax = dmin; + FORC4 scale_mul[c] = (pre_mul[c] /= dmax) * 65535.0 / maximum; + if (verbose) { + fprintf (stderr, + _("Scaling with darkness %d, saturation %d, and\nmultipliers"), dark, sat); + FORC4 fprintf (stderr, " %f", pre_mul[c]); + fputc ('\n', stderr); + } + size = iheight*iwidth; + for (i=0; i < size*4; i++) { + val = image[0][i]; + if (!val) continue; + val -= cblack[i & 3]; + val *= scale_mul[i & 3]; + image[0][i] = CLIP(val); + } + if ((aber[0] != 1 || aber[2] != 1) && colors == 3) { + if (verbose) + fprintf (stderr,_("Correcting chromatic aberration...\n")); + for (c=0; c < 4; c+=2) { + if (aber[c] == 1) continue; + img = (ushort *) malloc (size * sizeof *img); + merror (img, "scale_colors()"); + for (i=0; i < size; i++) + img[i] = image[i][c]; + for (row=0; row < iheight; row++) { + ur = fr = (row - iheight*0.5) * aber[c] + iheight*0.5; + if (ur > iheight-2) continue; + fr -= ur; + for (col=0; col < iwidth; col++) { + uc = fc = (col - iwidth*0.5) * aber[c] + iwidth*0.5; + if (uc > iwidth-2) continue; + fc -= uc; + pix = img + ur*iwidth + uc; + image[row*iwidth+col][c] = + (pix[ 0]*(1-fc) + pix[ 1]*fc) * (1-fr) + + (pix[iwidth]*(1-fc) + pix[iwidth+1]*fc) * fr; + } + } + free(img); + } + } +} + +void CLASS pre_interpolate() +{ + ushort (*img)[4]; + int row, col, c; + + if (shrink) { + if (half_size) { + height = iheight; + width = iwidth; + } else { + img = (ushort (*)[4]) calloc (height*width, sizeof *img); + merror (img, "pre_interpolate()"); + for (row=0; row < height; row++) + for (col=0; col < width; col++) { + c = fcol(row,col); + img[row*width+col][c] = image[(row >> 1)*iwidth+(col >> 1)][c]; + } + free (image); + image = img; + shrink = 0; + } + } + if (filters > 1000 && colors == 3) { + if (four_color_rgb && colors++) + mix_green = !half_size; + else { + for (row = FC(1,0) >> 1; row < height; row+=2) + for (col = FC(row,1) & 1; col < width; col+=2) + image[row*width+col][1] = image[row*width+col][3]; + filters &= ~((filters & 0x55555555) << 1); + } + } + if (half_size) filters = 0; +} + +void CLASS border_interpolate (int border) +{ + unsigned row, col, y, x, f, c, sum[8]; + + for (row=0; row < height; row++) + for (col=0; col < width; col++) { + if (col==border && row >= border && row < height-border) + col = width-border; + memset (sum, 0, sizeof sum); + for (y=row-1; y != row+2; y++) + for (x=col-1; x != col+2; x++) + if (y < height && x < width) { + f = fcol(y,x); + sum[f] += image[y*width+x][f]; + sum[f+4]++; + } + f = fcol(row,col); + FORCC if (c != f && sum[c+4]) + image[row*width+col][c] = sum[c] / sum[c+4]; + } +} + +void CLASS lin_interpolate() +{ + int code[16][16][32], size=16, *ip, sum[4]; + int f, c, i, x, y, row, col, shift, color; + ushort *pix; + + if (verbose) fprintf (stderr,_("Bilinear interpolation...\n")); + if (filters == 2) size = 6; + border_interpolate(1); + for (row=0; row < size; row++) + for (col=0; col < size; col++) { + ip = code[row][col]+1; + f = fcol(row,col); + memset (sum, 0, sizeof sum); + for (y=-1; y <= 1; y++) + for (x=-1; x <= 1; x++) { + shift = (y==0) + (x==0); + color = fcol(row+y,col+x); + if (color == f) continue; + *ip++ = (width*y + x)*4 + color; + *ip++ = shift; + *ip++ = color; + sum[color] += 1 << shift; + } + code[row][col][0] = (ip - code[row][col]) / 3; + FORCC + if (c != f) { + *ip++ = c; + *ip++ = 256 / sum[c]; + } + } + for (row=1; row < height-1; row++) + for (col=1; col < width-1; col++) { + pix = image[row*width+col]; + ip = code[row % size][col % size]; + memset (sum, 0, sizeof sum); + for (i=*ip++; i--; ip+=3) + sum[ip[2]] += pix[ip[0]] << ip[1]; + for (i=colors; --i; ip+=2) + pix[ip[0]] = sum[ip[0]] * ip[1] >> 8; + } +} + +/* + This algorithm is officially called: + + "Interpolation using a Threshold-based variable number of gradients" + + described in http://scien.stanford.edu/pages/labsite/1999/psych221/projects/99/tingchen/algodep/vargra.html + + I've extended the basic idea to work with non-Bayer filter arrays. + Gradients are numbered clockwise from NW=0 to W=7. + */ +void CLASS vng_interpolate() +{ + static const signed char *cp, terms[] = { + -2,-2,+0,-1,0,0x01, -2,-2,+0,+0,1,0x01, -2,-1,-1,+0,0,0x01, + -2,-1,+0,-1,0,0x02, -2,-1,+0,+0,0,0x03, -2,-1,+0,+1,1,0x01, + -2,+0,+0,-1,0,0x06, -2,+0,+0,+0,1,0x02, -2,+0,+0,+1,0,0x03, + -2,+1,-1,+0,0,0x04, -2,+1,+0,-1,1,0x04, -2,+1,+0,+0,0,0x06, + -2,+1,+0,+1,0,0x02, -2,+2,+0,+0,1,0x04, -2,+2,+0,+1,0,0x04, + -1,-2,-1,+0,0,0x80, -1,-2,+0,-1,0,0x01, -1,-2,+1,-1,0,0x01, + -1,-2,+1,+0,1,0x01, -1,-1,-1,+1,0,0x88, -1,-1,+1,-2,0,0x40, + -1,-1,+1,-1,0,0x22, -1,-1,+1,+0,0,0x33, -1,-1,+1,+1,1,0x11, + -1,+0,-1,+2,0,0x08, -1,+0,+0,-1,0,0x44, -1,+0,+0,+1,0,0x11, + -1,+0,+1,-2,1,0x40, -1,+0,+1,-1,0,0x66, -1,+0,+1,+0,1,0x22, + -1,+0,+1,+1,0,0x33, -1,+0,+1,+2,1,0x10, -1,+1,+1,-1,1,0x44, + -1,+1,+1,+0,0,0x66, -1,+1,+1,+1,0,0x22, -1,+1,+1,+2,0,0x10, + -1,+2,+0,+1,0,0x04, -1,+2,+1,+0,1,0x04, -1,+2,+1,+1,0,0x04, + +0,-2,+0,+0,1,0x80, +0,-1,+0,+1,1,0x88, +0,-1,+1,-2,0,0x40, + +0,-1,+1,+0,0,0x11, +0,-1,+2,-2,0,0x40, +0,-1,+2,-1,0,0x20, + +0,-1,+2,+0,0,0x30, +0,-1,+2,+1,1,0x10, +0,+0,+0,+2,1,0x08, + +0,+0,+2,-2,1,0x40, +0,+0,+2,-1,0,0x60, +0,+0,+2,+0,1,0x20, + +0,+0,+2,+1,0,0x30, +0,+0,+2,+2,1,0x10, +0,+1,+1,+0,0,0x44, + +0,+1,+1,+2,0,0x10, +0,+1,+2,-1,1,0x40, +0,+1,+2,+0,0,0x60, + +0,+1,+2,+1,0,0x20, +0,+1,+2,+2,0,0x10, +1,-2,+1,+0,0,0x80, + +1,-1,+1,+1,0,0x88, +1,+0,+1,+2,0,0x08, +1,+0,+2,-1,0,0x40, + +1,+0,+2,+1,0,0x10 + }, chood[] = { -1,-1, -1,0, -1,+1, 0,+1, +1,+1, +1,0, +1,-1, 0,-1 }; + ushort (*brow[5])[4], *pix; + int prow=8, pcol=2, *ip, *code[16][16], gval[8], gmin, gmax, sum[4]; + int row, col, x, y, x1, x2, y1, y2, t, weight, grads, color, diag; + int g, diff, thold, num, c; + + lin_interpolate(); + if (verbose) fprintf (stderr,_("VNG interpolation...\n")); + + if (filters == 1) prow = pcol = 16; + if (filters == 2) prow = pcol = 6; + ip = (int *) calloc (prow*pcol, 1280); + merror (ip, "vng_interpolate()"); + for (row=0; row < prow; row++) /* Precalculate for VNG */ + for (col=0; col < pcol; col++) { + code[row][col] = ip; + for (cp=terms, t=0; t < 64; t++) { + y1 = *cp++; x1 = *cp++; + y2 = *cp++; x2 = *cp++; + weight = *cp++; + grads = *cp++; + color = fcol(row+y1,col+x1); + if (fcol(row+y2,col+x2) != color) continue; + diag = (fcol(row,col+1) == color && fcol(row+1,col) == color) ? 2:1; + if (abs(y1-y2) == diag && abs(x1-x2) == diag) continue; + *ip++ = (y1*width + x1)*4 + color; + *ip++ = (y2*width + x2)*4 + color; + *ip++ = weight; + for (g=0; g < 8; g++) + if (grads & 1< gval[g]) gmin = gval[g]; + if (gmax < gval[g]) gmax = gval[g]; + } + if (gmax == 0) { + memcpy (brow[2][col], pix, sizeof *image); + continue; + } + thold = gmin + (gmax >> 1); + memset (sum, 0, sizeof sum); + color = fcol(row,col); + for (num=g=0; g < 8; g++,ip+=2) { /* Average the neighbors */ + if (gval[g] <= thold) { + FORCC + if (c == color && ip[1]) + sum[c] += (pix[c] + pix[ip[1]]) >> 1; + else + sum[c] += pix[ip[0] + c]; + num++; + } + } + FORCC { /* Save to buffer */ + t = pix[color]; + if (c != color) + t += (sum[c] - sum[color]) / num; + brow[2][col][c] = CLIP(t); + } + } + if (row > 3) /* Write buffer to image */ + memcpy (image[(row-2)*width+2], brow[0]+2, (width-4)*sizeof *image); + for (g=0; g < 4; g++) + brow[(g-1) & 3] = brow[g]; + } + memcpy (image[(row-2)*width+2], brow[0]+2, (width-4)*sizeof *image); + memcpy (image[(row-1)*width+2], brow[1]+2, (width-4)*sizeof *image); + free (brow[4]); + free (code[0][0]); +} + +/* + Patterned Pixel Grouping Interpolation by Alain Desbiolles +*/ +void CLASS ppg_interpolate() +{ + int dir[5] = { 1, width, -1, -width, 1 }; + int row, col, diff[2], guess[2], c, d, i; + ushort (*pix)[4]; + + border_interpolate(3); + if (verbose) fprintf (stderr,_("PPG interpolation...\n")); + +/* Fill in the green layer with gradients and pattern recognition: */ + for (row=3; row < height-3; row++) + for (col=3+(FC(row,3) & 1), c=FC(row,col); col < width-3; col+=2) { + pix = image + row*width+col; + for (i=0; (d=dir[i]) > 0; i++) { + guess[i] = (pix[-d][1] + pix[0][c] + pix[d][1]) * 2 + - pix[-2*d][c] - pix[2*d][c]; + diff[i] = ( ABS(pix[-2*d][c] - pix[ 0][c]) + + ABS(pix[ 2*d][c] - pix[ 0][c]) + + ABS(pix[ -d][1] - pix[ d][1]) ) * 3 + + ( ABS(pix[ 3*d][1] - pix[ d][1]) + + ABS(pix[-3*d][1] - pix[-d][1]) ) * 2; + } + d = dir[i = diff[0] > diff[1]]; + pix[0][1] = ULIM(guess[i] >> 2, pix[d][1], pix[-d][1]); + } +/* Calculate red and blue for each green pixel: */ + for (row=1; row < height-1; row++) + for (col=1+(FC(row,2) & 1), c=FC(row,col+1); col < width-1; col+=2) { + pix = image + row*width+col; + for (i=0; (d=dir[i]) > 0; c=2-c, i++) + pix[0][c] = CLIP((pix[-d][c] + pix[d][c] + 2*pix[0][1] + - pix[-d][1] - pix[d][1]) >> 1); + } +/* Calculate blue for red pixels and vice versa: */ + for (row=1; row < height-1; row++) + for (col=1+(FC(row,1) & 1), c=2-FC(row,col); col < width-1; col+=2) { + pix = image + row*width+col; + for (i=0; (d=dir[i]+dir[i+1]) > 0; i++) { + diff[i] = ABS(pix[-d][c] - pix[d][c]) + + ABS(pix[-d][1] - pix[0][1]) + + ABS(pix[ d][1] - pix[0][1]); + guess[i] = pix[-d][c] + pix[d][c] + 2*pix[0][1] + - pix[-d][1] - pix[d][1]; + } + if (diff[0] != diff[1]) + pix[0][c] = CLIP(guess[diff[0] > diff[1]] >> 1); + else + pix[0][c] = CLIP((guess[0]+guess[1]) >> 2); + } +} + +/* + Adaptive Homogeneity-Directed interpolation is based on + the work of Keigo Hirakawa, Thomas Parks, and Paul Lee. + */ +#define TS 256 /* Tile Size */ + +void CLASS ahd_interpolate() +{ + int i, j, k, top, left, row, col, tr, tc, c, d, val, hm[2]; + ushort (*pix)[4], (*rix)[3]; + static const int dir[4] = { -1, 1, -TS, TS }; + unsigned ldiff[2][4], abdiff[2][4], leps, abeps; + float r, cbrt[0x10000], xyz[3], xyz_cam[3][4]; + ushort (*rgb)[TS][TS][3]; + short (*lab)[TS][TS][3], (*lix)[3]; + char (*homo)[TS][TS], *buffer; + + if (verbose) fprintf (stderr,_("AHD interpolation...\n")); + + for (i=0; i < 0x10000; i++) { + r = i / 65535.0; + cbrt[i] = r > 0.008856 ? pow(r,1/3.0) : 7.787*r + 16/116.0; + } + for (i=0; i < 3; i++) + for (j=0; j < colors; j++) + for (xyz_cam[i][j] = k=0; k < 3; k++) + xyz_cam[i][j] += xyz_rgb[i][k] * rgb_cam[k][j] / d65_white[i]; + + border_interpolate(5); + buffer = (char *) malloc (26*TS*TS); /* 1664 kB */ + merror (buffer, "ahd_interpolate()"); + rgb = (ushort(*)[TS][TS][3]) buffer; + lab = (short (*)[TS][TS][3])(buffer + 12*TS*TS); + homo = (char (*)[TS][TS]) (buffer + 24*TS*TS); + + for (top=2; top < height-5; top += TS-6) + for (left=2; left < width-5; left += TS-6) { + +/* Interpolate green horizontally and vertically: */ + for (row = top; row < top+TS && row < height-2; row++) { + col = left + (FC(row,left) & 1); + for (c = FC(row,col); col < left+TS && col < width-2; col+=2) { + pix = image + row*width+col; + val = ((pix[-1][1] + pix[0][c] + pix[1][1]) * 2 + - pix[-2][c] - pix[2][c]) >> 2; + rgb[0][row-top][col-left][1] = ULIM(val,pix[-1][1],pix[1][1]); + val = ((pix[-width][1] + pix[0][c] + pix[width][1]) * 2 + - pix[-2*width][c] - pix[2*width][c]) >> 2; + rgb[1][row-top][col-left][1] = ULIM(val,pix[-width][1],pix[width][1]); + } + } +/* Interpolate red and blue, and convert to CIELab: */ + for (d=0; d < 2; d++) + for (row=top+1; row < top+TS-1 && row < height-3; row++) + for (col=left+1; col < left+TS-1 && col < width-3; col++) { + pix = image + row*width+col; + rix = &rgb[d][row-top][col-left]; + lix = &lab[d][row-top][col-left]; + if ((c = 2 - FC(row,col)) == 1) { + c = FC(row+1,col); + val = pix[0][1] + (( pix[-1][2-c] + pix[1][2-c] + - rix[-1][1] - rix[1][1] ) >> 1); + rix[0][2-c] = CLIP(val); + val = pix[0][1] + (( pix[-width][c] + pix[width][c] + - rix[-TS][1] - rix[TS][1] ) >> 1); + } else + val = rix[0][1] + (( pix[-width-1][c] + pix[-width+1][c] + + pix[+width-1][c] + pix[+width+1][c] + - rix[-TS-1][1] - rix[-TS+1][1] + - rix[+TS-1][1] - rix[+TS+1][1] + 1) >> 2); + rix[0][c] = CLIP(val); + c = FC(row,col); + rix[0][c] = pix[0][c]; + xyz[0] = xyz[1] = xyz[2] = 0.5; + FORCC { + xyz[0] += xyz_cam[0][c] * rix[0][c]; + xyz[1] += xyz_cam[1][c] * rix[0][c]; + xyz[2] += xyz_cam[2][c] * rix[0][c]; + } + xyz[0] = cbrt[CLIP((int) xyz[0])]; + xyz[1] = cbrt[CLIP((int) xyz[1])]; + xyz[2] = cbrt[CLIP((int) xyz[2])]; + lix[0][0] = 64 * (116 * xyz[1] - 16); + lix[0][1] = 64 * 500 * (xyz[0] - xyz[1]); + lix[0][2] = 64 * 200 * (xyz[1] - xyz[2]); + } +/* Build homogeneity maps from the CIELab images: */ + memset (homo, 0, 2*TS*TS); + for (row=top+2; row < top+TS-2 && row < height-4; row++) { + tr = row-top; + for (col=left+2; col < left+TS-2 && col < width-4; col++) { + tc = col-left; + for (d=0; d < 2; d++) { + lix = &lab[d][tr][tc]; + for (i=0; i < 4; i++) { + ldiff[d][i] = ABS(lix[0][0]-lix[dir[i]][0]); + abdiff[d][i] = SQR(lix[0][1]-lix[dir[i]][1]) + + SQR(lix[0][2]-lix[dir[i]][2]); + } + } + leps = MIN(MAX(ldiff[0][0],ldiff[0][1]), + MAX(ldiff[1][2],ldiff[1][3])); + abeps = MIN(MAX(abdiff[0][0],abdiff[0][1]), + MAX(abdiff[1][2],abdiff[1][3])); + for (d=0; d < 2; d++) + for (i=0; i < 4; i++) + if (ldiff[d][i] <= leps && abdiff[d][i] <= abeps) + homo[d][tr][tc]++; + } + } +/* Combine the most homogenous pixels for the final result: */ + for (row=top+3; row < top+TS-3 && row < height-5; row++) { + tr = row-top; + for (col=left+3; col < left+TS-3 && col < width-5; col++) { + tc = col-left; + for (d=0; d < 2; d++) + for (hm[d]=0, i=tr-1; i <= tr+1; i++) + for (j=tc-1; j <= tc+1; j++) + hm[d] += homo[d][i][j]; + if (hm[0] != hm[1]) + FORC3 image[row*width+col][c] = rgb[hm[1] > hm[0]][tr][tc][c]; + else + FORC3 image[row*width+col][c] = + (rgb[0][tr][tc][c] + rgb[1][tr][tc][c]) >> 1; + } + } + } + free (buffer); +} +#undef TS + +void CLASS median_filter() +{ + ushort (*pix)[4]; + int pass, c, i, j, k, med[9]; + static const uchar opt[] = /* Optimal 9-element median search */ + { 1,2, 4,5, 7,8, 0,1, 3,4, 6,7, 1,2, 4,5, 7,8, + 0,3, 5,8, 4,7, 3,6, 1,4, 2,5, 4,7, 4,2, 6,4, 4,2 }; + + for (pass=1; pass <= med_passes; pass++) { + if (verbose) + fprintf (stderr,_("Median filter pass %d...\n"), pass); + for (c=0; c < 3; c+=2) { + for (pix = image; pix < image+width*height; pix++) + pix[0][3] = pix[0][c]; + for (pix = image+width; pix < image+width*(height-1); pix++) { + if ((pix-image+1) % width < 2) continue; + for (k=0, i = -width; i <= width; i += width) + for (j = i-1; j <= i+1; j++) + med[k++] = pix[j][3] - pix[j][1]; + for (i=0; i < sizeof opt; i+=2) + if (med[opt[i]] > med[opt[i+1]]) + SWAP (med[opt[i]] , med[opt[i+1]]); + pix[0][c] = CLIP(med[4] + pix[0][1]); + } + } + } +} + +void CLASS blend_highlights() +{ + int clip=INT_MAX, row, col, c, i, j; + static const float trans[2][4][4] = + { { { 1,1,1 }, { 1.7320508,-1.7320508,0 }, { -1,-1,2 } }, + { { 1,1,1,1 }, { 1,-1,1,-1 }, { 1,1,-1,-1 }, { 1,-1,-1,1 } } }; + static const float itrans[2][4][4] = + { { { 1,0.8660254,-0.5 }, { 1,-0.8660254,-0.5 }, { 1,0,1 } }, + { { 1,1,1,1 }, { 1,-1,1,-1 }, { 1,1,-1,-1 }, { 1,-1,-1,1 } } }; + float cam[2][4], lab[2][4], sum[2], chratio; + + if ((unsigned) (colors-3) > 1) return; + if (verbose) fprintf (stderr,_("Blending highlights...\n")); + FORCC if (clip > (i = 65535*pre_mul[c])) clip = i; + for (row=0; row < height; row++) + for (col=0; col < width; col++) { + FORCC if (image[row*width+col][c] > clip) break; + if (c == colors) continue; + FORCC { + cam[0][c] = image[row*width+col][c]; + cam[1][c] = MIN(cam[0][c],clip); + } + for (i=0; i < 2; i++) { + FORCC for (lab[i][c]=j=0; j < colors; j++) + lab[i][c] += trans[colors-3][c][j] * cam[i][j]; + for (sum[i]=0,c=1; c < colors; c++) + sum[i] += SQR(lab[i][c]); + } + chratio = sqrt(sum[1]/sum[0]); + for (c=1; c < colors; c++) + lab[0][c] *= chratio; + FORCC for (cam[0][c]=j=0; j < colors; j++) + cam[0][c] += itrans[colors-3][c][j] * lab[0][j]; + FORCC image[row*width+col][c] = cam[0][c] / colors; + } +} + +#define SCALE (4 >> shrink) +void CLASS recover_highlights() +{ + float *map, sum, wgt, grow; + int hsat[4], count, spread, change, val, i; + unsigned high, wide, mrow, mcol, row, col, kc, c, d, y, x; + ushort *pixel; + static const signed char dir[8][2] = + { {-1,-1}, {-1,0}, {-1,1}, {0,1}, {1,1}, {1,0}, {1,-1}, {0,-1} }; + + if (verbose) fprintf (stderr,_("Rebuilding highlights...\n")); + + grow = pow (2, 4-highlight); + FORCC hsat[c] = 32000 * pre_mul[c]; + for (kc=0, c=1; c < colors; c++) + if (pre_mul[kc] < pre_mul[c]) kc = c; + high = height / SCALE; + wide = width / SCALE; + map = (float *) calloc (high*wide, sizeof *map); + merror (map, "recover_highlights()"); + FORCC if (c != kc) { + memset (map, 0, high*wide*sizeof *map); + for (mrow=0; mrow < high; mrow++) + for (mcol=0; mcol < wide; mcol++) { + sum = wgt = count = 0; + for (row = mrow*SCALE; row < (mrow+1)*SCALE; row++) + for (col = mcol*SCALE; col < (mcol+1)*SCALE; col++) { + pixel = image[row*width+col]; + if (pixel[c] / hsat[c] == 1 && pixel[kc] > 24000) { + sum += pixel[c]; + wgt += pixel[kc]; + count++; + } + } + if (count == SCALE*SCALE) + map[mrow*wide+mcol] = sum / wgt; + } + for (spread = 32/grow; spread--; ) { + for (mrow=0; mrow < high; mrow++) + for (mcol=0; mcol < wide; mcol++) { + if (map[mrow*wide+mcol]) continue; + sum = count = 0; + for (d=0; d < 8; d++) { + y = mrow + dir[d][0]; + x = mcol + dir[d][1]; + if (y < high && x < wide && map[y*wide+x] > 0) { + sum += (1 + (d & 1)) * map[y*wide+x]; + count += 1 + (d & 1); + } + } + if (count > 3) + map[mrow*wide+mcol] = - (sum+grow) / (count+grow); + } + for (change=i=0; i < high*wide; i++) + if (map[i] < 0) { + map[i] = -map[i]; + change = 1; + } + if (!change) break; + } + for (i=0; i < high*wide; i++) + if (map[i] == 0) map[i] = 1; + for (mrow=0; mrow < high; mrow++) + for (mcol=0; mcol < wide; mcol++) { + for (row = mrow*SCALE; row < (mrow+1)*SCALE; row++) + for (col = mcol*SCALE; col < (mcol+1)*SCALE; col++) { + pixel = image[row*width+col]; + if (pixel[c] / hsat[c] > 1) { + val = pixel[kc] * map[mrow*wide+mcol]; + if (pixel[c] < val) pixel[c] = CLIP(val); + } + } + } + } + free (map); +} +#undef SCALE + +void CLASS tiff_get (unsigned base, + unsigned *tag, unsigned *type, unsigned *len, unsigned *save) +{ + *tag = get2(); + *type = get2(); + *len = get4(); + *save = ftell(ifp) + 4; + if (*len * ("11124811248488"[*type < 14 ? *type:0]-'0') > 4) + fseek (ifp, get4()+base, SEEK_SET); +} + +void CLASS parse_thumb_note (int base, unsigned toff, unsigned tlen) +{ + unsigned entries, tag, type, len, save; + + entries = get2(); + while (entries--) { + tiff_get (base, &tag, &type, &len, &save); + if (tag == toff) thumb_offset = get4()+base; + if (tag == tlen) thumb_length = get4(); + fseek (ifp, save, SEEK_SET); + } +} + +int CLASS parse_tiff_ifd (int base); + +void CLASS parse_makernote (int base, int uptag) +{ + static const uchar xlat[2][256] = { + { 0xc1,0xbf,0x6d,0x0d,0x59,0xc5,0x13,0x9d,0x83,0x61,0x6b,0x4f,0xc7,0x7f,0x3d,0x3d, + 0x53,0x59,0xe3,0xc7,0xe9,0x2f,0x95,0xa7,0x95,0x1f,0xdf,0x7f,0x2b,0x29,0xc7,0x0d, + 0xdf,0x07,0xef,0x71,0x89,0x3d,0x13,0x3d,0x3b,0x13,0xfb,0x0d,0x89,0xc1,0x65,0x1f, + 0xb3,0x0d,0x6b,0x29,0xe3,0xfb,0xef,0xa3,0x6b,0x47,0x7f,0x95,0x35,0xa7,0x47,0x4f, + 0xc7,0xf1,0x59,0x95,0x35,0x11,0x29,0x61,0xf1,0x3d,0xb3,0x2b,0x0d,0x43,0x89,0xc1, + 0x9d,0x9d,0x89,0x65,0xf1,0xe9,0xdf,0xbf,0x3d,0x7f,0x53,0x97,0xe5,0xe9,0x95,0x17, + 0x1d,0x3d,0x8b,0xfb,0xc7,0xe3,0x67,0xa7,0x07,0xf1,0x71,0xa7,0x53,0xb5,0x29,0x89, + 0xe5,0x2b,0xa7,0x17,0x29,0xe9,0x4f,0xc5,0x65,0x6d,0x6b,0xef,0x0d,0x89,0x49,0x2f, + 0xb3,0x43,0x53,0x65,0x1d,0x49,0xa3,0x13,0x89,0x59,0xef,0x6b,0xef,0x65,0x1d,0x0b, + 0x59,0x13,0xe3,0x4f,0x9d,0xb3,0x29,0x43,0x2b,0x07,0x1d,0x95,0x59,0x59,0x47,0xfb, + 0xe5,0xe9,0x61,0x47,0x2f,0x35,0x7f,0x17,0x7f,0xef,0x7f,0x95,0x95,0x71,0xd3,0xa3, + 0x0b,0x71,0xa3,0xad,0x0b,0x3b,0xb5,0xfb,0xa3,0xbf,0x4f,0x83,0x1d,0xad,0xe9,0x2f, + 0x71,0x65,0xa3,0xe5,0x07,0x35,0x3d,0x0d,0xb5,0xe9,0xe5,0x47,0x3b,0x9d,0xef,0x35, + 0xa3,0xbf,0xb3,0xdf,0x53,0xd3,0x97,0x53,0x49,0x71,0x07,0x35,0x61,0x71,0x2f,0x43, + 0x2f,0x11,0xdf,0x17,0x97,0xfb,0x95,0x3b,0x7f,0x6b,0xd3,0x25,0xbf,0xad,0xc7,0xc5, + 0xc5,0xb5,0x8b,0xef,0x2f,0xd3,0x07,0x6b,0x25,0x49,0x95,0x25,0x49,0x6d,0x71,0xc7 }, + { 0xa7,0xbc,0xc9,0xad,0x91,0xdf,0x85,0xe5,0xd4,0x78,0xd5,0x17,0x46,0x7c,0x29,0x4c, + 0x4d,0x03,0xe9,0x25,0x68,0x11,0x86,0xb3,0xbd,0xf7,0x6f,0x61,0x22,0xa2,0x26,0x34, + 0x2a,0xbe,0x1e,0x46,0x14,0x68,0x9d,0x44,0x18,0xc2,0x40,0xf4,0x7e,0x5f,0x1b,0xad, + 0x0b,0x94,0xb6,0x67,0xb4,0x0b,0xe1,0xea,0x95,0x9c,0x66,0xdc,0xe7,0x5d,0x6c,0x05, + 0xda,0xd5,0xdf,0x7a,0xef,0xf6,0xdb,0x1f,0x82,0x4c,0xc0,0x68,0x47,0xa1,0xbd,0xee, + 0x39,0x50,0x56,0x4a,0xdd,0xdf,0xa5,0xf8,0xc6,0xda,0xca,0x90,0xca,0x01,0x42,0x9d, + 0x8b,0x0c,0x73,0x43,0x75,0x05,0x94,0xde,0x24,0xb3,0x80,0x34,0xe5,0x2c,0xdc,0x9b, + 0x3f,0xca,0x33,0x45,0xd0,0xdb,0x5f,0xf5,0x52,0xc3,0x21,0xda,0xe2,0x22,0x72,0x6b, + 0x3e,0xd0,0x5b,0xa8,0x87,0x8c,0x06,0x5d,0x0f,0xdd,0x09,0x19,0x93,0xd0,0xb9,0xfc, + 0x8b,0x0f,0x84,0x60,0x33,0x1c,0x9b,0x45,0xf1,0xf0,0xa3,0x94,0x3a,0x12,0x77,0x33, + 0x4d,0x44,0x78,0x28,0x3c,0x9e,0xfd,0x65,0x57,0x16,0x94,0x6b,0xfb,0x59,0xd0,0xc8, + 0x22,0x36,0xdb,0xd2,0x63,0x98,0x43,0xa1,0x04,0x87,0x86,0xf7,0xa6,0x26,0xbb,0xd6, + 0x59,0x4d,0xbf,0x6a,0x2e,0xaa,0x2b,0xef,0xe6,0x78,0xb6,0x4e,0xe0,0x2f,0xdc,0x7c, + 0xbe,0x57,0x19,0x32,0x7e,0x2a,0xd0,0xb8,0xba,0x29,0x00,0x3c,0x52,0x7d,0xa8,0x49, + 0x3b,0x2d,0xeb,0x25,0x49,0xfa,0xa3,0xaa,0x39,0xa7,0xc5,0xa7,0x50,0x11,0x36,0xfb, + 0xc6,0x67,0x4a,0xf5,0xa5,0x12,0x65,0x7e,0xb0,0xdf,0xaf,0x4e,0xb3,0x61,0x7f,0x2f } }; + unsigned offset=0, entries, tag, type, len, save, c; + unsigned ver97=0, serial=0, i, wbi=0, wb[4]={0,0,0,0}; + uchar buf97[324], ci, cj, ck; + short morder, sorder=order; + char buf[10]; +/* + The MakerNote might have its own TIFF header (possibly with + its own byte-order!), or it might just be a table. + */ + if (!strcmp(make,"Nokia")) return; + fread (buf, 1, 10, ifp); + if (!strncmp (buf,"KDK" ,3) || /* these aren't TIFF tables */ + !strncmp (buf,"VER" ,3) || + !strncmp (buf,"IIII",4) || + !strncmp (buf,"MMMM",4)) return; + if (!strncmp (buf,"KC" ,2) || /* Konica KD-400Z, KD-510Z */ + !strncmp (buf,"MLY" ,3)) { /* Minolta DiMAGE G series */ + order = 0x4d4d; + while ((i=ftell(ifp)) < data_offset && i < 16384) { + wb[0] = wb[2]; wb[2] = wb[1]; wb[1] = wb[3]; + wb[3] = get2(); + if (wb[1] == 256 && wb[3] == 256 && + wb[0] > 256 && wb[0] < 640 && wb[2] > 256 && wb[2] < 640) + FORC4 cam_mul[c] = wb[c]; + } + goto quit; + } + if (!strcmp (buf,"Nikon")) { + base = ftell(ifp); + order = get2(); + if (get2() != 42) goto quit; + offset = get4(); + fseek (ifp, offset-8, SEEK_CUR); + } else if (!strcmp (buf,"OLYMPUS")) { + base = ftell(ifp)-10; + fseek (ifp, -2, SEEK_CUR); + order = get2(); get2(); + } else if (!strncmp (buf,"SONY",4) || + !strcmp (buf,"Panasonic")) { + goto nf; + } else if (!strncmp (buf,"FUJIFILM",8)) { + base = ftell(ifp)-10; +nf: order = 0x4949; + fseek (ifp, 2, SEEK_CUR); + } else if (!strcmp (buf,"OLYMP") || + !strcmp (buf,"LEICA") || + !strcmp (buf,"Ricoh") || + !strcmp (buf,"EPSON")) + fseek (ifp, -2, SEEK_CUR); + else if (!strcmp (buf,"AOC") || + !strcmp (buf,"QVC")) + fseek (ifp, -4, SEEK_CUR); + else { + fseek (ifp, -10, SEEK_CUR); + if (!strncmp(make,"SAMSUNG",7)) + base = ftell(ifp); + } + entries = get2(); + if (entries > 1000) return; + morder = order; + while (entries--) { + order = morder; + tiff_get (base, &tag, &type, &len, &save); + tag |= uptag << 16; + if (tag == 2 && strstr(make,"NIKON") && !iso_speed) + iso_speed = (get2(),get2()); + if (tag == 4 && len > 26 && len < 35) { + if ((i=(get4(),get2())) != 0x7fff && !iso_speed) + iso_speed = 50 * pow (2, i/32.0 - 4); + if ((i=(get2(),get2())) != 0x7fff && !aperture) + aperture = pow (2, i/64.0); + if ((i=get2()) != 0xffff && !shutter) + shutter = pow (2, (short) i/-32.0); + wbi = (get2(),get2()); + shot_order = (get2(),get2()); + } + if ((tag == 4 || tag == 0x114) && !strncmp(make,"KONICA",6)) { + fseek (ifp, tag == 4 ? 140:160, SEEK_CUR); + switch (get2()) { + case 72: flip = 0; break; + case 76: flip = 6; break; + case 82: flip = 5; break; + } + } + if (tag == 7 && type == 2 && len > 20) + fgets (model2, 64, ifp); + if (tag == 8 && type == 4) + shot_order = get4(); + if (tag == 9 && !strcmp(make,"Canon")) + fread (artist, 64, 1, ifp); + if (tag == 0xc && len == 4) { + cam_mul[0] = getreal(type); + cam_mul[2] = getreal(type); + } + if (tag == 0xd && type == 7 && get2() == 0xaaaa) { + for (c=i=2; (ushort) c != 0xbbbb && i < len; i++) + c = c << 8 | fgetc(ifp); + while ((i+=4) < len-5) + if (get4() == 257 && (i=len) && (c = (get4(),fgetc(ifp))) < 3) + flip = "065"[c]-'0'; + } + if (tag == 0x10 && type == 4) + unique_id = get4(); + if (tag == 0x11 && is_raw && !strncmp(make,"NIKON",5)) { + fseek (ifp, get4()+base, SEEK_SET); + parse_tiff_ifd (base); + } + if (tag == 0x14 && type == 7) { + if (len == 2560) { + fseek (ifp, 1248, SEEK_CUR); + goto get2_256; + } + fread (buf, 1, 10, ifp); + if (!strncmp(buf,"NRW ",4)) { + fseek (ifp, strcmp(buf+4,"0100") ? 46:1546, SEEK_CUR); + cam_mul[0] = get4() << 2; + cam_mul[1] = get4() + get4(); + cam_mul[2] = get4() << 2; + } + } + if (tag == 0x15 && type == 2 && is_raw) + fread (model, 64, 1, ifp); + if (strstr(make,"PENTAX")) { + if (tag == 0x1b) tag = 0x1018; + if (tag == 0x1c) tag = 0x1017; + } + if (tag == 0x1d) + while ((c = fgetc(ifp)) && c != EOF) + serial = serial*10 + (isdigit(c) ? c - '0' : c % 10); + if (tag == 0x81 && type == 4) { + data_offset = get4(); + fseek (ifp, data_offset + 41, SEEK_SET); + raw_height = get2() * 2; + raw_width = get2(); + filters = 0x61616161; + } + if (tag == 0x29 && type == 1) { + c = wbi < 18 ? "012347800000005896"[wbi]-'0' : 0; + fseek (ifp, 8 + c*32, SEEK_CUR); + FORC4 cam_mul[c ^ (c >> 1) ^ 1] = get4(); + } + if ((tag == 0x81 && type == 7) || + (tag == 0x100 && type == 7) || + (tag == 0x280 && type == 1)) { + thumb_offset = ftell(ifp); + thumb_length = len; + } + if (tag == 0x88 && type == 4 && (thumb_offset = get4())) + thumb_offset += base; + if (tag == 0x89 && type == 4) + thumb_length = get4(); + if (tag == 0x8c || tag == 0x96) + meta_offset = ftell(ifp); + if (tag == 0x97) { + for (i=0; i < 4; i++) + ver97 = ver97 * 10 + fgetc(ifp)-'0'; + switch (ver97) { + case 100: + fseek (ifp, 68, SEEK_CUR); + FORC4 cam_mul[(c >> 1) | ((c & 1) << 1)] = get2(); + break; + case 102: + fseek (ifp, 6, SEEK_CUR); + goto get2_rggb; + case 103: + fseek (ifp, 16, SEEK_CUR); + FORC4 cam_mul[c] = get2(); + } + if (ver97 >= 200) { + if (ver97 != 205) fseek (ifp, 280, SEEK_CUR); + fread (buf97, 324, 1, ifp); + } + } + if (tag == 0xa1 && type == 7) { + order = 0x4949; + fseek (ifp, 140, SEEK_CUR); + FORC3 cam_mul[c] = get4(); + } + if (tag == 0xa4 && type == 3) { + fseek (ifp, wbi*48, SEEK_CUR); + FORC3 cam_mul[c] = get2(); + } + if (tag == 0xa7 && (unsigned) (ver97-200) < 17) { + ci = xlat[0][serial & 0xff]; + cj = xlat[1][fgetc(ifp)^fgetc(ifp)^fgetc(ifp)^fgetc(ifp)]; + ck = 0x60; + for (i=0; i < 324; i++) + buf97[i] ^= (cj += ci * ck++); + i = "66666>666;6A;:;55"[ver97-200] - '0'; + FORC4 cam_mul[c ^ (c >> 1) ^ (i & 1)] = + sget2 (buf97 + (i & -2) + c*2); + } + if (tag == 0x200 && len == 3) + shot_order = (get4(),get4()); + if (tag == 0x200 && len == 4) + FORC4 cblack[c ^ c >> 1] = get2(); + if (tag == 0x201 && len == 4) + goto get2_rggb; + if (tag == 0x220 && type == 7) + meta_offset = ftell(ifp); + if (tag == 0x401 && type == 4 && len == 4) + FORC4 cblack[c ^ c >> 1] = get4(); + if (tag == 0xe01) { /* Nikon Capture Note */ + order = 0x4949; + fseek (ifp, 22, SEEK_CUR); + for (offset=22; offset+22 < len; offset += 22+i) { + tag = get4(); + fseek (ifp, 14, SEEK_CUR); + i = get4()-4; + if (tag == 0x76a43207) flip = get2(); + else fseek (ifp, i, SEEK_CUR); + } + } + if (tag == 0xe80 && len == 256 && type == 7) { + fseek (ifp, 48, SEEK_CUR); + cam_mul[0] = get2() * 508 * 1.078 / 0x10000; + cam_mul[2] = get2() * 382 * 1.173 / 0x10000; + } + if (tag == 0xf00 && type == 7) { + if (len == 614) + fseek (ifp, 176, SEEK_CUR); + else if (len == 734 || len == 1502) + fseek (ifp, 148, SEEK_CUR); + else goto next; + goto get2_256; + } + if ((tag == 0x1011 && len == 9) || tag == 0x20400200) + for (i=0; i < 3; i++) + FORC3 cmatrix[i][c] = ((short) get2()) / 256.0; + if ((tag == 0x1012 || tag == 0x20400600) && len == 4) + FORC4 cblack[c ^ c >> 1] = get2(); + if (tag == 0x1017 || tag == 0x20400100) + cam_mul[0] = get2() / 256.0; + if (tag == 0x1018 || tag == 0x20400100) + cam_mul[2] = get2() / 256.0; + if (tag == 0x2011 && len == 2) { +get2_256: + order = 0x4d4d; + cam_mul[0] = get2() / 256.0; + cam_mul[2] = get2() / 256.0; + } + if ((tag | 0x70) == 0x2070 && type == 4) + fseek (ifp, get4()+base, SEEK_SET); + if (tag == 0x2010 && type != 7) + load_raw = &CLASS olympus_load_raw; + if (tag == 0x2020) + parse_thumb_note (base, 257, 258); + if (tag == 0x2040) + parse_makernote (base, 0x2040); + if (tag == 0xb028) { + fseek (ifp, get4()+base, SEEK_SET); + parse_thumb_note (base, 136, 137); + } + if (tag == 0x4001 && len > 500) { + i = len == 582 ? 50 : len == 653 ? 68 : len == 5120 ? 142 : 126; + fseek (ifp, i, SEEK_CUR); +get2_rggb: + FORC4 cam_mul[c ^ (c >> 1)] = get2(); + i = len == 1312 ? 112:22; + fseek (ifp, i, SEEK_CUR); + FORC4 sraw_mul[c ^ (c >> 1)] = get2(); + } + if (tag == 0xa021) + FORC4 cam_mul[c ^ (c >> 1)] = get4(); + if (tag == 0xa028) + FORC4 cam_mul[c ^ (c >> 1)] -= get4(); +next: + fseek (ifp, save, SEEK_SET); + } +quit: + order = sorder; +} + +/* + Since the TIFF DateTime string has no timezone information, + assume that the camera's clock was set to Universal Time. + */ +void CLASS get_timestamp (int reversed) +{ + struct tm t; + char str[20]; + int i; + + str[19] = 0; + if (reversed) + for (i=19; i--; ) str[i] = fgetc(ifp); + else + fread (str, 19, 1, ifp); + memset (&t, 0, sizeof t); + if (sscanf (str, "%d:%d:%d %d:%d:%d", &t.tm_year, &t.tm_mon, + &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec) != 6) + return; + t.tm_year -= 1900; + t.tm_mon -= 1; + t.tm_isdst = -1; + if (mktime(&t) > 0) + timestamp = mktime(&t); +} + +void CLASS parse_exif (int base) +{ + unsigned kodak, entries, tag, type, len, save, c; + double expo; + + kodak = !strncmp(make,"EASTMAN",7) && tiff_nifds < 3; + entries = get2(); + while (entries--) { + tiff_get (base, &tag, &type, &len, &save); + switch (tag) { + case 33434: shutter = getreal(type); break; + case 33437: aperture = getreal(type); break; + case 34855: iso_speed = get2(); break; + case 36867: + case 36868: get_timestamp(0); break; + case 37377: if ((expo = -getreal(type)) < 128) + shutter = pow (2, expo); break; + case 37378: aperture = pow (2, getreal(type)/2); break; + case 37386: focal_len = getreal(type); break; + case 37500: parse_makernote (base, 0); break; + case 40962: if (kodak) raw_width = get4(); break; + case 40963: if (kodak) raw_height = get4(); break; + case 41730: + if (get4() == 0x20002) + for (exif_cfa=c=0; c < 8; c+=2) + exif_cfa |= fgetc(ifp) * 0x01010101 << c; + } + fseek (ifp, save, SEEK_SET); + } +} + +void CLASS parse_gps (int base) +{ + unsigned entries, tag, type, len, save, c; + + entries = get2(); + while (entries--) { + tiff_get (base, &tag, &type, &len, &save); + switch (tag) { + case 1: case 3: case 5: + gpsdata[29+tag/2] = getc(ifp); break; + case 2: case 4: case 7: + FORC(6) gpsdata[tag/3*6+c] = get4(); break; + case 6: + FORC(2) gpsdata[18+c] = get4(); break; + case 18: case 29: + fgets ((char *) (gpsdata+14+tag/3), MIN(len,12), ifp); + } + fseek (ifp, save, SEEK_SET); + } +} + +void CLASS romm_coeff (float romm_cam[3][3]) +{ + static const float rgb_romm[3][3] = /* ROMM == Kodak ProPhoto */ + { { 2.034193, -0.727420, -0.306766 }, + { -0.228811, 1.231729, -0.002922 }, + { -0.008565, -0.153273, 1.161839 } }; + int i, j, k; + + for (i=0; i < 3; i++) + for (j=0; j < 3; j++) + for (cmatrix[i][j] = k=0; k < 3; k++) + cmatrix[i][j] += rgb_romm[i][k] * romm_cam[k][j]; +} + +void CLASS parse_mos (int offset) +{ + char data[40]; + int skip, from, i, c, neut[4], planes=0, frot=0; + static const char *mod[] = + { "","DCB2","Volare","Cantare","CMost","Valeo 6","Valeo 11","Valeo 22", + "Valeo 11p","Valeo 17","","Aptus 17","Aptus 22","Aptus 75","Aptus 65", + "Aptus 54S","Aptus 65S","Aptus 75S","AFi 5","AFi 6","AFi 7", + "","","","","","","","","","","","","","","","","","AFi-II 12" }; + float romm_cam[3][3]; + + fseek (ifp, offset, SEEK_SET); + while (1) { + if (get4() != 0x504b5453) break; + get4(); + fread (data, 1, 40, ifp); + skip = get4(); + from = ftell(ifp); + if (!strcmp(data,"JPEG_preview_data")) { + thumb_offset = from; + thumb_length = skip; + } + if (!strcmp(data,"icc_camera_profile")) { + profile_offset = from; + profile_length = skip; + } + if (!strcmp(data,"ShootObj_back_type")) { + fscanf (ifp, "%d", &i); + if ((unsigned) i < sizeof mod / sizeof (*mod)) + strcpy (model, mod[i]); + } + if (!strcmp(data,"icc_camera_to_tone_matrix")) { + for (i=0; i < 9; i++) + romm_cam[0][i] = int_to_float(get4()); + romm_coeff (romm_cam); + } + if (!strcmp(data,"CaptProf_color_matrix")) { + for (i=0; i < 9; i++) + fscanf (ifp, "%f", &romm_cam[0][i]); + romm_coeff (romm_cam); + } + if (!strcmp(data,"CaptProf_number_of_planes")) + fscanf (ifp, "%d", &planes); + if (!strcmp(data,"CaptProf_raw_data_rotation")) + fscanf (ifp, "%d", &flip); + if (!strcmp(data,"CaptProf_mosaic_pattern")) + FORC4 { + fscanf (ifp, "%d", &i); + if (i == 1) frot = c ^ (c >> 1); + } + if (!strcmp(data,"ImgProf_rotation_angle")) { + fscanf (ifp, "%d", &i); + flip = i - flip; + } + if (!strcmp(data,"NeutObj_neutrals") && !cam_mul[0]) { + FORC4 fscanf (ifp, "%d", neut+c); + FORC3 cam_mul[c] = (float) neut[0] / neut[c+1]; + } + if (!strcmp(data,"Rows_data")) + load_flags = get4(); + parse_mos (from); + fseek (ifp, skip+from, SEEK_SET); + } + if (planes) + filters = (planes == 1) * 0x01010101 * + (uchar) "\x94\x61\x16\x49"[(flip/90 + frot) & 3]; +} + +void CLASS linear_table (unsigned len) +{ + int i; + if (len > 0x1000) len = 0x1000; + read_shorts (curve, len); + for (i=len; i < 0x1000; i++) + curve[i] = curve[i-1]; + maximum = curve[0xfff]; +} + +void CLASS parse_kodak_ifd (int base) +{ + unsigned entries, tag, type, len, save; + int i, c, wbi=-2, wbtemp=6500; + float mul[3]={1,1,1}, num; + static const int wbtag[] = { 64037,64040,64039,64041,-1,-1,64042 }; + + entries = get2(); + if (entries > 1024) return; + while (entries--) { + tiff_get (base, &tag, &type, &len, &save); + if (tag == 1020) wbi = getint(type); + if (tag == 1021 && len == 72) { /* WB set in software */ + fseek (ifp, 40, SEEK_CUR); + FORC3 cam_mul[c] = 2048.0 / get2(); + wbi = -2; + } + if (tag == 2118) wbtemp = getint(type); + if (tag == 2130 + wbi) + FORC3 mul[c] = getreal(type); + if (tag == 2140 + wbi && wbi >= 0) + FORC3 { + for (num=i=0; i < 4; i++) + num += getreal(type) * pow (wbtemp/100.0, i); + cam_mul[c] = 2048 / (num * mul[c]); + } + if (tag == 2317) linear_table (len); + if (tag == 6020) iso_speed = getint(type); + if (tag == 64013) wbi = fgetc(ifp); + if ((unsigned) wbi < 7 && tag == wbtag[wbi]) + FORC3 cam_mul[c] = get4(); + if (tag == 64019) width = getint(type); + if (tag == 64020) height = (getint(type)+1) & -2; + fseek (ifp, save, SEEK_SET); + } +} + +void CLASS parse_minolta (int base); +int CLASS parse_tiff (int base); + +int CLASS parse_tiff_ifd (int base) +{ + unsigned entries, tag, type, len, plen=16, save; + int ifd, use_cm=0, cfa, i, j, c, ima_len=0; + int blrr=1, blrc=1, dblack[] = { 0,0,0,0 }; + char software[64], *cbuf, *cp; + uchar cfa_pat[16], cfa_pc[] = { 0,1,2,3 }, tab[256]; + double cc[4][4], cm[4][3], cam_xyz[4][3], num; + double ab[]={ 1,1,1,1 }, asn[] = { 0,0,0,0 }, xyz[] = { 1,1,1 }; + unsigned sony_curve[] = { 0,0,0,0,0,4095 }; + unsigned *buf, sony_offset=0, sony_length=0, sony_key=0; + struct jhead jh; + FILE *sfp; + + if (tiff_nifds >= sizeof tiff_ifd / sizeof tiff_ifd[0]) + return 1; + ifd = tiff_nifds++; + for (j=0; j < 4; j++) + for (i=0; i < 4; i++) + cc[j][i] = i == j; + entries = get2(); + if (entries > 512) return 1; + while (entries--) { + tiff_get (base, &tag, &type, &len, &save); + switch (tag) { + case 5: width = get2(); break; + case 6: height = get2(); break; + case 7: width += get2(); break; + case 9: filters = get2(); break; + case 17: case 18: + if (type == 3 && len == 1) + cam_mul[(tag-17)*2] = get2() / 256.0; + break; + case 23: + if (type == 3) iso_speed = get2(); + break; + case 36: case 37: case 38: + cam_mul[tag-0x24] = get2(); + break; + case 39: + if (len < 50 || cam_mul[0]) break; + fseek (ifp, 12, SEEK_CUR); + FORC3 cam_mul[c] = get2(); + break; + case 46: + if (type != 7 || fgetc(ifp) != 0xff || fgetc(ifp) != 0xd8) break; + thumb_offset = ftell(ifp) - 2; + thumb_length = len; + break; + case 61440: /* Fuji HS10 table */ + parse_tiff_ifd (base); + break; + case 2: case 256: case 61441: /* ImageWidth */ + tiff_ifd[ifd].width = getint(type); + break; + case 3: case 257: case 61442: /* ImageHeight */ + tiff_ifd[ifd].height = getint(type); + break; + case 258: /* BitsPerSample */ + case 61443: + tiff_ifd[ifd].samples = len & 7; + tiff_ifd[ifd].bps = getint(type); + break; + case 61446: + raw_height = 0; + load_raw = &CLASS packed_load_raw; + load_flags = get4() && (filters=0x16161616) ? 24:80; + break; + case 259: /* Compression */ + tiff_ifd[ifd].comp = getint(type); + break; + case 262: /* PhotometricInterpretation */ + tiff_ifd[ifd].phint = get2(); + break; + case 270: /* ImageDescription */ + fread (desc, 512, 1, ifp); + break; + case 271: /* Make */ + fgets (make, 64, ifp); + break; + case 272: /* Model */ + fgets (model, 64, ifp); + break; + case 280: /* Panasonic RW2 offset */ + if (type != 4) break; + load_raw = &CLASS panasonic_load_raw; + load_flags = 0x2008; + case 273: /* StripOffset */ + case 513: /* JpegIFOffset */ + case 61447: + tiff_ifd[ifd].offset = get4()+base; + if (!tiff_ifd[ifd].bps && tiff_ifd[ifd].offset > 0) { + fseek (ifp, tiff_ifd[ifd].offset, SEEK_SET); + if (ljpeg_start (&jh, 1)) { + tiff_ifd[ifd].comp = 6; + tiff_ifd[ifd].width = jh.wide; + tiff_ifd[ifd].height = jh.high; + tiff_ifd[ifd].bps = jh.bits; + tiff_ifd[ifd].samples = jh.clrs; + if (!(jh.sraw || (jh.clrs & 1))) + tiff_ifd[ifd].width *= jh.clrs; + i = order; + parse_tiff (tiff_ifd[ifd].offset + 12); + order = i; + } + } + break; + case 274: /* Orientation */ + tiff_ifd[ifd].flip = "50132467"[get2() & 7]-'0'; + break; + case 277: /* SamplesPerPixel */ + tiff_ifd[ifd].samples = getint(type) & 7; + break; + case 279: /* StripByteCounts */ + case 514: + case 61448: + tiff_ifd[ifd].bytes = get4(); + break; + case 61454: + FORC3 cam_mul[(4-c) % 3] = getint(type); + break; + case 305: case 11: /* Software */ + fgets (software, 64, ifp); + if (!strncmp(software,"Adobe",5) || + !strncmp(software,"dcraw",5) || + !strncmp(software,"UFRaw",5) || + !strncmp(software,"Bibble",6) || + !strncmp(software,"Nikon Scan",10) || + !strcmp (software,"Digital Photo Professional")) + is_raw = 0; + break; + case 306: /* DateTime */ + get_timestamp(0); + break; + case 315: /* Artist */ + fread (artist, 64, 1, ifp); + break; + case 322: /* TileWidth */ + tiff_ifd[ifd].tile_width = getint(type); + break; + case 323: /* TileLength */ + tiff_ifd[ifd].tile_length = getint(type); + break; + case 324: /* TileOffsets */ + tiff_ifd[ifd].offset = len > 1 ? ftell(ifp) : get4(); + if (len == 4) { + load_raw = &CLASS sinar_4shot_load_raw; + is_raw = 5; + } + break; + case 330: /* SubIFDs */ + if (!strcmp(model,"DSLR-A100") && tiff_ifd[ifd].width == 3872) { + load_raw = &CLASS sony_arw_load_raw; + data_offset = get4()+base; + ifd++; break; + } + while (len--) { + i = ftell(ifp); + fseek (ifp, get4()+base, SEEK_SET); + if (parse_tiff_ifd (base)) break; + fseek (ifp, i+4, SEEK_SET); + } + break; + case 400: + strcpy (make, "Sarnoff"); + maximum = 0xfff; + break; + case 28688: + FORC4 sony_curve[c+1] = get2() >> 2 & 0xfff; + for (i=0; i < 5; i++) + for (j = sony_curve[i]+1; j <= sony_curve[i+1]; j++) + curve[j] = curve[j-1] + (1 << i); + break; + case 29184: sony_offset = get4(); break; + case 29185: sony_length = get4(); break; + case 29217: sony_key = get4(); break; + case 29264: + parse_minolta (ftell(ifp)); + raw_width = 0; + break; + case 29443: + FORC4 cam_mul[c ^ (c < 2)] = get2(); + break; + case 29459: + FORC4 cam_mul[c] = get2(); + i = (cam_mul[1] == 1024 && cam_mul[2] == 1024) << 1; + SWAP (cam_mul[i],cam_mul[i+1]) + break; + case 33405: /* Model2 */ + fgets (model2, 64, ifp); + break; + case 33422: /* CFAPattern */ + case 64777: /* Kodak P-series */ + if ((plen=len) > 16) plen = 16; + fread (cfa_pat, 1, plen, ifp); + for (colors=cfa=i=0; i < plen; i++) { + colors += !(cfa & (1 << cfa_pat[i])); + cfa |= 1 << cfa_pat[i]; + } + if (cfa == 070) memcpy (cfa_pc,"\003\004\005",3); /* CMY */ + if (cfa == 072) memcpy (cfa_pc,"\005\003\004\001",4); /* GMCY */ + goto guess_cfa_pc; + case 33424: + case 65024: + fseek (ifp, get4()+base, SEEK_SET); + parse_kodak_ifd (base); + break; + case 33434: /* ExposureTime */ + shutter = getreal(type); + break; + case 33437: /* FNumber */ + aperture = getreal(type); + break; + case 34306: /* Leaf white balance */ + FORC4 cam_mul[c ^ 1] = 4096.0 / get2(); + break; + case 34307: /* Leaf CatchLight color matrix */ + fread (software, 1, 7, ifp); + if (strncmp(software,"MATRIX",6)) break; + colors = 4; + for (raw_color = i=0; i < 3; i++) { + FORC4 fscanf (ifp, "%f", &rgb_cam[i][c^1]); + if (!use_camera_wb) continue; + num = 0; + FORC4 num += rgb_cam[i][c]; + FORC4 rgb_cam[i][c] /= num; + } + break; + case 34310: /* Leaf metadata */ + parse_mos (ftell(ifp)); + case 34303: + strcpy (make, "Leaf"); + break; + case 34665: /* EXIF tag */ + fseek (ifp, get4()+base, SEEK_SET); + parse_exif (base); + break; + case 34853: /* GPSInfo tag */ + fseek (ifp, get4()+base, SEEK_SET); + parse_gps (base); + break; + case 34675: /* InterColorProfile */ + case 50831: /* AsShotICCProfile */ + profile_offset = ftell(ifp); + profile_length = len; + break; + case 37122: /* CompressedBitsPerPixel */ + kodak_cbpp = get4(); + break; + case 37386: /* FocalLength */ + focal_len = getreal(type); + break; + case 37393: /* ImageNumber */ + shot_order = getint(type); + break; + case 37400: /* old Kodak KDC tag */ + for (raw_color = i=0; i < 3; i++) { + getreal(type); + FORC3 rgb_cam[i][c] = getreal(type); + } + break; + case 46275: /* Imacon tags */ + strcpy (make, "Imacon"); + data_offset = ftell(ifp); + ima_len = len; + break; + case 46279: + if (!ima_len) break; + fseek (ifp, 38, SEEK_CUR); + case 46274: + fseek (ifp, 40, SEEK_CUR); + raw_width = get4(); + raw_height = get4(); + left_margin = get4() & 7; + width = raw_width - left_margin - (get4() & 7); + top_margin = get4() & 7; + height = raw_height - top_margin - (get4() & 7); + if (raw_width == 7262) { + height = 5444; + width = 7244; + left_margin = 7; + } + fseek (ifp, 52, SEEK_CUR); + FORC3 cam_mul[c] = getreal(11); + fseek (ifp, 114, SEEK_CUR); + flip = (get2() >> 7) * 90; + if (width * height * 6 == ima_len) { + if (flip % 180 == 90) SWAP(width,height); + raw_width = width; + raw_height = height; + left_margin = top_margin = filters = flip = 0; + } + sprintf (model, "Ixpress %d-Mp", height*width/1000000); + load_raw = &CLASS imacon_full_load_raw; + if (filters) { + if (left_margin & 1) filters = 0x61616161; + load_raw = &CLASS unpacked_load_raw; + } + maximum = 0xffff; + break; + case 50454: /* Sinar tag */ + case 50455: + if (!(cbuf = (char *) malloc(len))) break; + fread (cbuf, 1, len, ifp); + for (cp = cbuf-1; cp && cp < cbuf+len; cp = strchr(cp,'\n')) + if (!strncmp (++cp,"Neutral ",8)) + sscanf (cp+8, "%f %f %f", cam_mul, cam_mul+1, cam_mul+2); + free (cbuf); + break; + case 50458: + if (!make[0]) strcpy (make, "Hasselblad"); + break; + case 50459: /* Hasselblad tag */ + i = order; + j = ftell(ifp); + c = tiff_nifds; + order = get2(); + fseek (ifp, j+(get2(),get4()), SEEK_SET); + parse_tiff_ifd (j); + maximum = 0xffff; + tiff_nifds = c; + order = i; + break; + case 50706: /* DNGVersion */ + FORC4 dng_version = (dng_version << 8) + fgetc(ifp); + if (!make[0]) strcpy (make, "DNG"); + is_raw = 1; + break; + case 50710: /* CFAPlaneColor */ + if (len > 4) len = 4; + colors = len; + fread (cfa_pc, 1, colors, ifp); +guess_cfa_pc: + FORCC tab[cfa_pc[c]] = c; + cdesc[c] = 0; + for (i=16; i--; ) + filters = filters << 2 | tab[cfa_pat[i % plen]]; + break; + case 50711: /* CFALayout */ + if (get2() == 2) { + fuji_width = 1; + filters = 0x49494949; + } + break; + case 291: + case 50712: /* LinearizationTable */ + linear_table (len); + break; + case 50713: /* BlackLevelRepeatDim */ + blrr = get2(); + blrc = get2(); + break; + case 61450: + blrr = blrc = 2; + case 50714: /* BlackLevel */ + black = getreal(type); + if (!filters || !~filters) break; + dblack[0] = black; + dblack[1] = (blrc == 2) ? getreal(type):dblack[0]; + dblack[2] = (blrr == 2) ? getreal(type):dblack[0]; + dblack[3] = (blrc == 2 && blrr == 2) ? getreal(type):dblack[1]; + if (colors == 3) + filters |= ((filters >> 2 & 0x22222222) | + (filters << 2 & 0x88888888)) & filters << 1; + FORC4 cblack[filters >> (c << 1) & 3] = dblack[c]; + black = 0; + break; + case 50715: /* BlackLevelDeltaH */ + case 50716: /* BlackLevelDeltaV */ + for (num=i=0; i < len; i++) + num += getreal(type); + black += num/len + 0.5; + break; + case 50717: /* WhiteLevel */ + maximum = getint(type); + break; + case 50718: /* DefaultScale */ + pixel_aspect = getreal(type); + pixel_aspect /= getreal(type); + break; + case 50721: /* ColorMatrix1 */ + case 50722: /* ColorMatrix2 */ + FORCC for (j=0; j < 3; j++) + cm[c][j] = getreal(type); + use_cm = 1; + break; + case 50723: /* CameraCalibration1 */ + case 50724: /* CameraCalibration2 */ + for (i=0; i < colors; i++) + FORCC cc[i][c] = getreal(type); + break; + case 50727: /* AnalogBalance */ + FORCC ab[c] = getreal(type); + break; + case 50728: /* AsShotNeutral */ + FORCC asn[c] = getreal(type); + break; + case 50729: /* AsShotWhiteXY */ + xyz[0] = getreal(type); + xyz[1] = getreal(type); + xyz[2] = 1 - xyz[0] - xyz[1]; + FORC3 xyz[c] /= d65_white[c]; + break; + case 50740: /* DNGPrivateData */ + if (dng_version) break; + parse_minolta (j = get4()+base); + fseek (ifp, j, SEEK_SET); + parse_tiff_ifd (base); + break; + case 50752: + read_shorts (cr2_slice, 3); + break; + case 50829: /* ActiveArea */ + top_margin = getint(type); + left_margin = getint(type); + height = getint(type) - top_margin; + width = getint(type) - left_margin; + break; + case 50830: /* MaskedAreas */ + for (i=0; i < len && i < 32; i++) + mask[0][i] = getint(type); + black = 0; + break; + case 51009: /* OpcodeList2 */ + meta_offset = ftell(ifp); + break; + case 64772: /* Kodak P-series */ + if (len < 13) break; + fseek (ifp, 16, SEEK_CUR); + data_offset = get4(); + fseek (ifp, 28, SEEK_CUR); + data_offset += get4(); + load_raw = &CLASS packed_load_raw; + break; + case 65026: + if (type == 2) fgets (model2, 64, ifp); + } + fseek (ifp, save, SEEK_SET); + } + if (sony_length && (buf = (unsigned *) malloc(sony_length))) { + fseek (ifp, sony_offset, SEEK_SET); + fread (buf, sony_length, 1, ifp); + sony_decrypt (buf, sony_length/4, 1, sony_key); + sfp = ifp; + if ((ifp = tmpfile())) { + fwrite (buf, sony_length, 1, ifp); + fseek (ifp, 0, SEEK_SET); + parse_tiff_ifd (-sony_offset); + fclose (ifp); + } + ifp = sfp; + free (buf); + } + for (i=0; i < colors; i++) + FORCC cc[i][c] *= ab[i]; + if (use_cm) { + FORCC for (i=0; i < 3; i++) + for (cam_xyz[c][i]=j=0; j < colors; j++) + cam_xyz[c][i] += cc[c][j] * cm[j][i] * xyz[i]; + cam_xyz_coeff (cam_xyz); + } + if (asn[0]) { + cam_mul[3] = 0; + FORCC cam_mul[c] = 1 / asn[c]; + } + if (!use_cm) + FORCC pre_mul[c] /= cc[c][c]; + return 0; +} + +int CLASS parse_tiff (int base) +{ + int doff; + + fseek (ifp, base, SEEK_SET); + order = get2(); + if (order != 0x4949 && order != 0x4d4d) return 0; + get2(); + while ((doff = get4())) { + fseek (ifp, doff+base, SEEK_SET); + if (parse_tiff_ifd (base)) break; + } + return 1; +} + +void CLASS apply_tiff() +{ + int max_samp=0, raw=-1, thm=-1, i; + struct jhead jh; + + thumb_misc = 16; + if (thumb_offset) { + fseek (ifp, thumb_offset, SEEK_SET); + if (ljpeg_start (&jh, 1)) { + thumb_misc = jh.bits; + thumb_width = jh.wide; + thumb_height = jh.high; + } + } + for (i=0; i < tiff_nifds; i++) { + if (max_samp < tiff_ifd[i].samples) + max_samp = tiff_ifd[i].samples; + if (max_samp > 3) max_samp = 3; + if ((tiff_ifd[i].comp != 6 || tiff_ifd[i].samples != 3) && + (tiff_ifd[i].width | tiff_ifd[i].height) < 0x10000 && + tiff_ifd[i].width*tiff_ifd[i].height > raw_width*raw_height) { + raw_width = tiff_ifd[i].width; + raw_height = tiff_ifd[i].height; + tiff_bps = tiff_ifd[i].bps; + tiff_compress = tiff_ifd[i].comp; + data_offset = tiff_ifd[i].offset; + tiff_flip = tiff_ifd[i].flip; + tiff_samples = tiff_ifd[i].samples; + tile_width = tiff_ifd[i].tile_width; + tile_length = tiff_ifd[i].tile_length; + raw = i; + } + } + if (!tile_width ) tile_width = INT_MAX; + if (!tile_length) tile_length = INT_MAX; + for (i=tiff_nifds; i--; ) + if (tiff_ifd[i].flip) tiff_flip = tiff_ifd[i].flip; + if (raw >= 0 && !load_raw) + switch (tiff_compress) { + case 32767: + if (tiff_ifd[raw].bytes == raw_width*raw_height) { + tiff_bps = 12; + load_raw = &CLASS sony_arw2_load_raw; break; + } + if (tiff_ifd[raw].bytes*8 != raw_width*raw_height*tiff_bps) { + raw_height += 8; + load_raw = &CLASS sony_arw_load_raw; break; + } + load_flags = 79; + case 32769: + load_flags++; + case 32770: + case 32773: goto slr; + case 0: case 1: + if (tiff_ifd[raw].bytes*5 == raw_width*raw_height*8) { + load_flags = 81; + tiff_bps = 12; + } slr: + switch (tiff_bps) { + case 8: load_raw = &CLASS eight_bit_load_raw; break; + case 12: if (tiff_ifd[raw].phint == 2) + load_flags = 6; + load_raw = &CLASS packed_load_raw; break; + case 14: load_flags = 0; + case 16: load_raw = &CLASS unpacked_load_raw; break; + } + break; + case 6: case 7: case 99: + load_raw = &CLASS lossless_jpeg_load_raw; break; + case 262: + load_raw = &CLASS kodak_262_load_raw; break; + case 34713: + load_raw = &CLASS nikon_load_raw; break; + case 34892: + load_raw = &CLASS lossy_dng_load_raw; break; + case 65535: + load_raw = &CLASS pentax_load_raw; break; + case 65000: + switch (tiff_ifd[raw].phint) { + case 2: load_raw = &CLASS kodak_rgb_load_raw; filters = 0; break; + case 6: load_raw = &CLASS kodak_ycbcr_load_raw; filters = 0; break; + case 32803: load_raw = &CLASS kodak_65000_load_raw; + } + case 32867: break; + default: is_raw = 0; + } + if (!dng_version) + if ( (tiff_samples == 3 && tiff_ifd[raw].bytes && + tiff_bps != 14 && tiff_bps != 2048 && tiff_compress != 32770) + || (tiff_bps == 8 && !strstr(make,"KODAK") && !strstr(make,"Kodak") && + !strstr(model2,"DEBUG RAW"))) + is_raw = 0; + for (i=0; i < tiff_nifds; i++) + if (i != raw && tiff_ifd[i].samples == max_samp && + tiff_ifd[i].width * tiff_ifd[i].height / SQR(tiff_ifd[i].bps+1) > + thumb_width * thumb_height / SQR(thumb_misc+1) + && tiff_ifd[i].comp != 34892) { + thumb_width = tiff_ifd[i].width; + thumb_height = tiff_ifd[i].height; + thumb_offset = tiff_ifd[i].offset; + thumb_length = tiff_ifd[i].bytes; + thumb_misc = tiff_ifd[i].bps; + thm = i; + } + if (thm >= 0) { + thumb_misc |= tiff_ifd[thm].samples << 5; + switch (tiff_ifd[thm].comp) { + case 0: + write_thumb = &CLASS layer_thumb; + break; + case 1: + if (tiff_ifd[thm].bps <= 8) + write_thumb = &CLASS ppm_thumb; + else if (!strcmp(make,"Imacon")) + write_thumb = &CLASS ppm16_thumb; + else + thumb_load_raw = &CLASS kodak_thumb_load_raw; + break; + case 65000: + thumb_load_raw = tiff_ifd[thm].phint == 6 ? + &CLASS kodak_ycbcr_load_raw : &CLASS kodak_rgb_load_raw; + } + } +} + +void CLASS parse_minolta (int base) +{ + int save, tag, len, offset, high=0, wide=0, i, c; + short sorder=order; + + fseek (ifp, base, SEEK_SET); + if (fgetc(ifp) || fgetc(ifp)-'M' || fgetc(ifp)-'R') return; + order = fgetc(ifp) * 0x101; + offset = base + get4() + 8; + while ((save=ftell(ifp)) < offset) { + for (tag=i=0; i < 4; i++) + tag = tag << 8 | fgetc(ifp); + len = get4(); + switch (tag) { + case 0x505244: /* PRD */ + fseek (ifp, 8, SEEK_CUR); + high = get2(); + wide = get2(); + break; + case 0x574247: /* WBG */ + get4(); + i = strcmp(model,"DiMAGE A200") ? 0:3; + FORC4 cam_mul[c ^ (c >> 1) ^ i] = get2(); + break; + case 0x545457: /* TTW */ + parse_tiff (ftell(ifp)); + data_offset = offset; + } + fseek (ifp, save+len+8, SEEK_SET); + } + raw_height = high; + raw_width = wide; + order = sorder; +} + +/* + Many cameras have a "debug mode" that writes JPEG and raw + at the same time. The raw file has no header, so try to + to open the matching JPEG file and read its metadata. + */ +void CLASS parse_external_jpeg() +{ + const char *file, *ext; + char *jname, *jfile, *jext; + FILE *save=ifp; + + ext = strrchr (ifname, '.'); + file = strrchr (ifname, '/'); + if (!file) file = strrchr (ifname, '\\'); + if (!file) file = ifname-1; + file++; + if (!ext || strlen(ext) != 4 || ext-file != 8) return; + jname = (char *) malloc (strlen(ifname) + 1); + merror (jname, "parse_external_jpeg()"); + strcpy (jname, ifname); + jfile = file - ifname + jname; + jext = ext - ifname + jname; + if (strcasecmp (ext, ".jpg")) { + strcpy (jext, isupper(ext[1]) ? ".JPG":".jpg"); + if (isdigit(*file)) { + memcpy (jfile, file+4, 4); + memcpy (jfile+4, file, 4); + } + } else + while (isdigit(*--jext)) { + if (*jext != '9') { + (*jext)++; + break; + } + *jext = '0'; + } + if (strcmp (jname, ifname)) { + if ((ifp = fopen (jname, "rb"))) { + if (verbose) + fprintf (stderr,_("Reading metadata from %s ...\n"), jname); + parse_tiff (12); + thumb_offset = 0; + is_raw = 1; + fclose (ifp); + } + } + if (!timestamp) + fprintf (stderr,_("Failed to read metadata from %s\n"), jname); + free (jname); + ifp = save; +} + +/* + CIFF block 0x1030 contains an 8x8 white sample. + Load this into white[][] for use in scale_colors(). + */ +void CLASS ciff_block_1030() +{ + static const ushort key[] = { 0x410, 0x45f3 }; + int i, bpp, row, col, vbits=0; + unsigned long bitbuf=0; + + if ((get2(),get4()) != 0x80008 || !get4()) return; + bpp = get2(); + if (bpp != 10 && bpp != 12) return; + for (i=row=0; row < 8; row++) + for (col=0; col < 8; col++) { + if (vbits < bpp) { + bitbuf = bitbuf << 16 | (get2() ^ key[i++ & 1]); + vbits += 16; + } + white[row][col] = + bitbuf << (LONG_BIT - vbits) >> (LONG_BIT - bpp); + vbits -= bpp; + } +} + +/* + Parse a CIFF file, better known as Canon CRW format. + */ +void CLASS parse_ciff (int offset, int length) +{ + int tboff, nrecs, c, type, len, save, wbi=-1; + ushort key[] = { 0x410, 0x45f3 }; + + fseek (ifp, offset+length-4, SEEK_SET); + tboff = get4() + offset; + fseek (ifp, tboff, SEEK_SET); + nrecs = get2(); + if (nrecs > 100) return; + while (nrecs--) { + type = get2(); + len = get4(); + save = ftell(ifp) + 4; + fseek (ifp, offset+get4(), SEEK_SET); + if ((((type >> 8) + 8) | 8) == 0x38) + parse_ciff (ftell(ifp), len); /* Parse a sub-table */ + + if (type == 0x0810) + fread (artist, 64, 1, ifp); + if (type == 0x080a) { + fread (make, 64, 1, ifp); + fseek (ifp, strlen(make) - 63, SEEK_CUR); + fread (model, 64, 1, ifp); + } + if (type == 0x1810) { + fseek (ifp, 12, SEEK_CUR); + flip = get4(); + } + if (type == 0x1835) /* Get the decoder table */ + tiff_compress = get4(); + if (type == 0x2007) { + thumb_offset = ftell(ifp); + thumb_length = len; + } + if (type == 0x1818) { + shutter = pow (2, -int_to_float((get4(),get4()))); + aperture = pow (2, int_to_float(get4())/2); + } + if (type == 0x102a) { + iso_speed = pow (2, (get4(),get2())/32.0 - 4) * 50; + aperture = pow (2, (get2(),(short)get2())/64.0); + shutter = pow (2,-((short)get2())/32.0); + wbi = (get2(),get2()); + if (wbi > 17) wbi = 0; + fseek (ifp, 32, SEEK_CUR); + if (shutter > 1e6) shutter = get2()/10.0; + } + if (type == 0x102c) { + if (get2() > 512) { /* Pro90, G1 */ + fseek (ifp, 118, SEEK_CUR); + FORC4 cam_mul[c ^ 2] = get2(); + } else { /* G2, S30, S40 */ + fseek (ifp, 98, SEEK_CUR); + FORC4 cam_mul[c ^ (c >> 1) ^ 1] = get2(); + } + } + if (type == 0x0032) { + if (len == 768) { /* EOS D30 */ + fseek (ifp, 72, SEEK_CUR); + FORC4 cam_mul[c ^ (c >> 1)] = 1024.0 / get2(); + if (!wbi) cam_mul[0] = -1; /* use my auto white balance */ + } else if (!cam_mul[0]) { + if (get2() == key[0]) /* Pro1, G6, S60, S70 */ + c = (strstr(model,"Pro1") ? + "012346000000000000":"01345:000000006008")[wbi]-'0'+ 2; + else { /* G3, G5, S45, S50 */ + c = "023457000000006000"[wbi]-'0'; + key[0] = key[1] = 0; + } + fseek (ifp, 78 + c*8, SEEK_CUR); + FORC4 cam_mul[c ^ (c >> 1) ^ 1] = get2() ^ key[c & 1]; + if (!wbi) cam_mul[0] = -1; + } + } + if (type == 0x10a9) { /* D60, 10D, 300D, and clones */ + if (len > 66) wbi = "0134567028"[wbi]-'0'; + fseek (ifp, 2 + wbi*8, SEEK_CUR); + FORC4 cam_mul[c ^ (c >> 1)] = get2(); + } + if (type == 0x1030 && (0x18040 >> wbi & 1)) + ciff_block_1030(); /* all that don't have 0x10a9 */ + if (type == 0x1031) { + raw_width = (get2(),get2()); + raw_height = get2(); + } + if (type == 0x5029) { + focal_len = len >> 16; + if ((len & 0xffff) == 2) focal_len /= 32; + } + if (type == 0x5813) flash_used = int_to_float(len); + if (type == 0x5814) canon_ev = int_to_float(len); + if (type == 0x5817) shot_order = len; + if (type == 0x5834) unique_id = len; + if (type == 0x580e) timestamp = len; + if (type == 0x180e) timestamp = get4(); +#ifdef LOCALTIME + if ((type | 0x4000) == 0x580e) + timestamp = mktime (gmtime (×tamp)); +#endif + fseek (ifp, save, SEEK_SET); + } +} + +void CLASS parse_rollei() +{ + char line[128], *val; + struct tm t; + + fseek (ifp, 0, SEEK_SET); + memset (&t, 0, sizeof t); + do { + fgets (line, 128, ifp); + if ((val = strchr(line,'='))) + *val++ = 0; + else + val = line + strlen(line); + if (!strcmp(line,"DAT")) + sscanf (val, "%d.%d.%d", &t.tm_mday, &t.tm_mon, &t.tm_year); + if (!strcmp(line,"TIM")) + sscanf (val, "%d:%d:%d", &t.tm_hour, &t.tm_min, &t.tm_sec); + if (!strcmp(line,"HDR")) + thumb_offset = atoi(val); + if (!strcmp(line,"X ")) + raw_width = atoi(val); + if (!strcmp(line,"Y ")) + raw_height = atoi(val); + if (!strcmp(line,"TX ")) + thumb_width = atoi(val); + if (!strcmp(line,"TY ")) + thumb_height = atoi(val); + } while (strncmp(line,"EOHD",4)); + data_offset = thumb_offset + thumb_width * thumb_height * 2; + t.tm_year -= 1900; + t.tm_mon -= 1; + if (mktime(&t) > 0) + timestamp = mktime(&t); + strcpy (make, "Rollei"); + strcpy (model,"d530flex"); + write_thumb = &CLASS rollei_thumb; +} + +void CLASS parse_sinar_ia() +{ + int entries, off; + char str[8], *cp; + + order = 0x4949; + fseek (ifp, 4, SEEK_SET); + entries = get4(); + fseek (ifp, get4(), SEEK_SET); + while (entries--) { + off = get4(); get4(); + fread (str, 8, 1, ifp); + if (!strcmp(str,"META")) meta_offset = off; + if (!strcmp(str,"THUMB")) thumb_offset = off; + if (!strcmp(str,"RAW0")) data_offset = off; + } + fseek (ifp, meta_offset+20, SEEK_SET); + fread (make, 64, 1, ifp); + make[63] = 0; + if ((cp = strchr(make,' '))) { + strcpy (model, cp+1); + *cp = 0; + } + raw_width = get2(); + raw_height = get2(); + load_raw = &CLASS unpacked_load_raw; + thumb_width = (get4(),get2()); + thumb_height = get2(); + write_thumb = &CLASS ppm_thumb; + maximum = 0x3fff; +} + +void CLASS parse_phase_one (int base) +{ + unsigned entries, tag, type, len, data, save, i, c; + float romm_cam[3][3]; + char *cp; + + memset (&ph1, 0, sizeof ph1); + fseek (ifp, base, SEEK_SET); + order = get4() & 0xffff; + if (get4() >> 8 != 0x526177) return; /* "Raw" */ + fseek (ifp, get4()+base, SEEK_SET); + entries = get4(); + get4(); + while (entries--) { + tag = get4(); + type = get4(); + len = get4(); + data = get4(); + save = ftell(ifp); + fseek (ifp, base+data, SEEK_SET); + switch (tag) { + case 0x100: flip = "0653"[data & 3]-'0'; break; + case 0x106: + for (i=0; i < 9; i++) + romm_cam[0][i] = getreal(11); + romm_coeff (romm_cam); + break; + case 0x107: + FORC3 cam_mul[c] = getreal(11); + break; + case 0x108: raw_width = data; break; + case 0x109: raw_height = data; break; + case 0x10a: left_margin = data; break; + case 0x10b: top_margin = data; break; + case 0x10c: width = data; break; + case 0x10d: height = data; break; + case 0x10e: ph1.format = data; break; + case 0x10f: data_offset = data+base; break; + case 0x110: meta_offset = data+base; + meta_length = len; break; + case 0x112: ph1.key_off = save - 4; break; + case 0x210: ph1.tag_210 = int_to_float(data); break; + case 0x21a: ph1.tag_21a = data; break; + case 0x21c: strip_offset = data+base; break; + case 0x21d: ph1.black = data; break; + case 0x222: ph1.split_col = data; break; + case 0x223: ph1.black_off = data+base; break; + case 0x301: + model[63] = 0; + fread (model, 1, 63, ifp); + if ((cp = strstr(model," camera"))) *cp = 0; + } + fseek (ifp, save, SEEK_SET); + } + load_raw = ph1.format < 3 ? + &CLASS phase_one_load_raw : &CLASS phase_one_load_raw_c; + maximum = 0xffff; + strcpy (make, "Phase One"); + if (model[0]) return; + switch (raw_height) { + case 2060: strcpy (model,"LightPhase"); break; + case 2682: strcpy (model,"H 10"); break; + case 4128: strcpy (model,"H 20"); break; + case 5488: strcpy (model,"H 25"); break; + } +} + +void CLASS parse_fuji (int offset) +{ + unsigned entries, tag, len, save, c; + + fseek (ifp, offset, SEEK_SET); + entries = get4(); + if (entries > 255) return; + while (entries--) { + tag = get2(); + len = get2(); + save = ftell(ifp); + if (tag == 0x100) { + raw_height = get2(); + raw_width = get2(); + } else if (tag == 0x121) { + height = get2(); + if ((width = get2()) == 4284) width += 3; + } else if (tag == 0x130) { + fuji_layout = fgetc(ifp) >> 7; + fuji_width = !(fgetc(ifp) & 8); + } else if (tag == 0x2ff0) { + FORC4 cam_mul[c ^ 1] = get2(); + } else if (tag == 0xc000) { + c = order; + order = 0x4949; + width = get4(); + height = get4(); + order = c; + } + fseek (ifp, save+len, SEEK_SET); + } + height <<= fuji_layout; + width >>= fuji_layout; +} + +int CLASS parse_jpeg (int offset) +{ + int len, save, hlen, mark; + + fseek (ifp, offset, SEEK_SET); + if (fgetc(ifp) != 0xff || fgetc(ifp) != 0xd8) return 0; + + while (fgetc(ifp) == 0xff && (mark = fgetc(ifp)) != 0xda) { + order = 0x4d4d; + len = get2() - 2; + save = ftell(ifp); + if (mark == 0xc0 || mark == 0xc3) { + fgetc(ifp); + raw_height = get2(); + raw_width = get2(); + } + order = get2(); + hlen = get4(); + if (get4() == 0x48454150) /* "HEAP" */ + parse_ciff (save+hlen, len-hlen); + if (parse_tiff (save+6)) apply_tiff(); + fseek (ifp, save+len, SEEK_SET); + } + return 1; +} + +void CLASS parse_riff() +{ + unsigned i, size, end; + char tag[4], date[64], month[64]; + static const char mon[12][4] = + { "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" }; + struct tm t; + + order = 0x4949; + fread (tag, 4, 1, ifp); + size = get4(); + end = ftell(ifp) + size; + if (!memcmp(tag,"RIFF",4) || !memcmp(tag,"LIST",4)) { + get4(); + while (ftell(ifp)+7 < end) + parse_riff(); + } else if (!memcmp(tag,"nctg",4)) { + while (ftell(ifp)+7 < end) { + i = get2(); + size = get2(); + if ((i+1) >> 1 == 10 && size == 20) + get_timestamp(0); + else fseek (ifp, size, SEEK_CUR); + } + } else if (!memcmp(tag,"IDIT",4) && size < 64) { + fread (date, 64, 1, ifp); + date[size] = 0; + memset (&t, 0, sizeof t); + if (sscanf (date, "%*s %s %d %d:%d:%d %d", month, &t.tm_mday, + &t.tm_hour, &t.tm_min, &t.tm_sec, &t.tm_year) == 6) { + for (i=0; i < 12 && strcasecmp(mon[i],month); i++); + t.tm_mon = i; + t.tm_year -= 1900; + if (mktime(&t) > 0) + timestamp = mktime(&t); + } + } else + fseek (ifp, size, SEEK_CUR); +} + +void CLASS parse_smal (int offset, int fsize) +{ + int ver; + + fseek (ifp, offset+2, SEEK_SET); + order = 0x4949; + ver = fgetc(ifp); + if (ver == 6) + fseek (ifp, 5, SEEK_CUR); + if (get4() != fsize) return; + if (ver > 6) data_offset = get4(); + raw_height = height = get2(); + raw_width = width = get2(); + strcpy (make, "SMaL"); + sprintf (model, "v%d %dx%d", ver, width, height); + if (ver == 6) load_raw = &CLASS smal_v6_load_raw; + if (ver == 9) load_raw = &CLASS smal_v9_load_raw; +} + +void CLASS parse_cine() +{ + unsigned off_head, off_setup, off_image, i; + + order = 0x4949; + fseek (ifp, 4, SEEK_SET); + is_raw = get2() == 2; + fseek (ifp, 14, SEEK_CUR); + is_raw *= get4(); + off_head = get4(); + off_setup = get4(); + off_image = get4(); + timestamp = get4(); + if ((i = get4())) timestamp = i; + fseek (ifp, off_head+4, SEEK_SET); + raw_width = get4(); + raw_height = get4(); + switch (get2(),get2()) { + case 8: load_raw = &CLASS eight_bit_load_raw; break; + case 16: load_raw = &CLASS unpacked_load_raw; + } + fseek (ifp, off_setup+792, SEEK_SET); + strcpy (make, "CINE"); + sprintf (model, "%d", get4()); + fseek (ifp, 12, SEEK_CUR); + switch ((i=get4()) & 0xffffff) { + case 3: filters = 0x94949494; break; + case 4: filters = 0x49494949; break; + default: is_raw = 0; + } + fseek (ifp, 72, SEEK_CUR); + switch ((get4()+3600) % 360) { + case 270: flip = 4; break; + case 180: flip = 1; break; + case 90: flip = 7; break; + case 0: flip = 2; + } + cam_mul[0] = getreal(11); + cam_mul[2] = getreal(11); + maximum = ~(-1 << get4()); + fseek (ifp, 668, SEEK_CUR); + shutter = get4()/1000000000.0; + fseek (ifp, off_image, SEEK_SET); + if (shot_select < is_raw) + fseek (ifp, shot_select*8, SEEK_CUR); + data_offset = (INT64) get4() + 8; + data_offset += (INT64) get4() << 32; +} + +void CLASS parse_redcine() +{ + unsigned i, len, rdvo; + + order = 0x4d4d; + is_raw = 0; + fseek (ifp, 52, SEEK_SET); + width = get4(); + height = get4(); + fseek (ifp, 0, SEEK_END); + fseek (ifp, -(i = ftello(ifp) & 511), SEEK_CUR); + if (get4() != i || get4() != 0x52454f42) { + fprintf (stderr,_("%s: Tail is missing, parsing from head...\n"), ifname); + fseek (ifp, 0, SEEK_SET); + while ((len = get4()) != EOF) { + if (get4() == 0x52454456) + if (is_raw++ == shot_select) + data_offset = ftello(ifp) - 8; + fseek (ifp, len-8, SEEK_CUR); + } + } else { + rdvo = get4(); + fseek (ifp, 12, SEEK_CUR); + is_raw = get4(); + fseeko (ifp, rdvo+8 + shot_select*4, SEEK_SET); + data_offset = get4(); + } +} + +char * CLASS foveon_gets (int offset, char *str, int len) +{ + int i; + fseek (ifp, offset, SEEK_SET); + for (i=0; i < len-1; i++) + if ((str[i] = get2()) == 0) break; + str[i] = 0; + return str; +} + +void CLASS parse_foveon() +{ + int entries, img=0, off, len, tag, save, i, wide, high, pent, poff[256][2]; + char name[64], value[64]; + + order = 0x4949; /* Little-endian */ + fseek (ifp, 36, SEEK_SET); + flip = get4(); + fseek (ifp, -4, SEEK_END); + fseek (ifp, get4(), SEEK_SET); + if (get4() != 0x64434553) return; /* SECd */ + entries = (get4(),get4()); + while (entries--) { + off = get4(); + len = get4(); + tag = get4(); + save = ftell(ifp); + fseek (ifp, off, SEEK_SET); + if (get4() != (0x20434553 | (tag << 24))) return; + switch (tag) { + case 0x47414d49: /* IMAG */ + case 0x32414d49: /* IMA2 */ + fseek (ifp, 8, SEEK_CUR); + pent = get4(); + wide = get4(); + high = get4(); + if (wide > raw_width && high > raw_height) { + switch (pent) { + case 5: load_flags = 1; + case 6: load_raw = &CLASS foveon_sd_load_raw; break; + case 30: load_raw = &CLASS foveon_dp_load_raw; break; + default: load_raw = 0; + } + raw_width = wide; + raw_height = high; + data_offset = off+28; + } + fseek (ifp, off+28, SEEK_SET); + if (fgetc(ifp) == 0xff && fgetc(ifp) == 0xd8 + && thumb_length < len-28) { + thumb_offset = off+28; + thumb_length = len-28; + write_thumb = &CLASS jpeg_thumb; + } + if (++img == 2 && !thumb_length) { + thumb_offset = off+24; + thumb_width = wide; + thumb_height = high; + write_thumb = &CLASS foveon_thumb; + } + break; + case 0x464d4143: /* CAMF */ + meta_offset = off+8; + meta_length = len-28; + break; + case 0x504f5250: /* PROP */ + pent = (get4(),get4()); + fseek (ifp, 12, SEEK_CUR); + off += pent*8 + 24; + if ((unsigned) pent > 256) pent=256; + for (i=0; i < pent*2; i++) + poff[0][i] = off + get4()*2; + for (i=0; i < pent; i++) { + foveon_gets (poff[i][0], name, 64); + foveon_gets (poff[i][1], value, 64); + if (!strcmp (name, "ISO")) + iso_speed = atoi(value); + if (!strcmp (name, "CAMMANUF")) + strcpy (make, value); + if (!strcmp (name, "CAMMODEL")) + strcpy (model, value); + if (!strcmp (name, "WB_DESC")) + strcpy (model2, value); + if (!strcmp (name, "TIME")) + timestamp = atoi(value); + if (!strcmp (name, "EXPTIME")) + shutter = atoi(value) / 1000000.0; + if (!strcmp (name, "APERTURE")) + aperture = atof(value); + if (!strcmp (name, "FLENGTH")) + focal_len = atof(value); + } +#ifdef LOCALTIME + timestamp = mktime (gmtime (×tamp)); +#endif + } + fseek (ifp, save, SEEK_SET); + } + is_foveon = 1; +} + +/* + All matrices are from Adobe DNG Converter unless otherwise noted. + */ +void CLASS adobe_coeff (const char *make, const char *model) +{ + static const struct { + const char *prefix; + short black, maximum, trans[12]; + } table[] = { + { "AGFAPHOTO DC-833m", 0, 0, /* DJC */ + { 11438,-3762,-1115,-2409,9914,2497,-1227,2295,5300 } }, + { "Apple QuickTake", 0, 0, /* DJC */ + { 21392,-5653,-3353,2406,8010,-415,7166,1427,2078 } }, + { "Canon EOS D2000", 0, 0, + { 24542,-10860,-3401,-1490,11370,-297,2858,-605,3225 } }, + { "Canon EOS D6000", 0, 0, + { 20482,-7172,-3125,-1033,10410,-285,2542,226,3136 } }, + { "Canon EOS D30", 0, 0, + { 9805,-2689,-1312,-5803,13064,3068,-2438,3075,8775 } }, + { "Canon EOS D60", 0, 0xfa0, + { 6188,-1341,-890,-7168,14489,2937,-2640,3228,8483 } }, + { "Canon EOS 5D Mark III", 0, 0x3c80, + { 6722,-635,-963,-4287,12460,2028,-908,2162,5668 } }, + { "Canon EOS 5D Mark II", 0, 0x3cf0, + { 4716,603,-830,-7798,15474,2480,-1496,1937,6651 } }, + { "Canon EOS 5D", 0, 0xe6c, + { 6347,-479,-972,-8297,15954,2480,-1968,2131,7649 } }, + { "Canon EOS 7D", 0, 0x3510, + { 6844,-996,-856,-3876,11761,2396,-593,1772,6198 } }, + { "Canon EOS 10D", 0, 0xfa0, + { 8197,-2000,-1118,-6714,14335,2592,-2536,3178,8266 } }, + { "Canon EOS 20Da", 0, 0, + { 14155,-5065,-1382,-6550,14633,2039,-1623,1824,6561 } }, + { "Canon EOS 20D", 0, 0xfff, + { 6599,-537,-891,-8071,15783,2424,-1983,2234,7462 } }, + { "Canon EOS 30D", 0, 0, + { 6257,-303,-1000,-7880,15621,2396,-1714,1904,7046 } }, + { "Canon EOS 40D", 0, 0x3f60, + { 6071,-747,-856,-7653,15365,2441,-2025,2553,7315 } }, + { "Canon EOS 50D", 0, 0x3d93, + { 4920,616,-593,-6493,13964,2784,-1774,3178,7005 } }, + { "Canon EOS 60D", 0, 0x2ff7, + { 6719,-994,-925,-4408,12426,2211,-887,2129,6051 } }, + { "Canon EOS 300D", 0, 0xfa0, + { 8197,-2000,-1118,-6714,14335,2592,-2536,3178,8266 } }, + { "Canon EOS 350D", 0, 0xfff, + { 6018,-617,-965,-8645,15881,2975,-1530,1719,7642 } }, + { "Canon EOS 400D", 0, 0xe8e, + { 7054,-1501,-990,-8156,15544,2812,-1278,1414,7796 } }, + { "Canon EOS 450D", 0, 0x390d, + { 5784,-262,-821,-7539,15064,2672,-1982,2681,7427 } }, + { "Canon EOS 500D", 0, 0x3479, + { 4763,712,-646,-6821,14399,2640,-1921,3276,6561 } }, + { "Canon EOS 550D", 0, 0x3dd7, + { 6941,-1164,-857,-3825,11597,2534,-416,1540,6039 } }, + { "Canon EOS 600D", 0, 0x3510, + { 6461,-907,-882,-4300,12184,2378,-819,1944,5931 } }, + { "Canon EOS 1000D", 0, 0xe43, + { 6771,-1139,-977,-7818,15123,2928,-1244,1437,7533 } }, + { "Canon EOS 1100D", 0, 0x3510, + { 6444,-904,-893,-4563,12308,2535,-903,2016,6728 } }, + { "Canon EOS-1Ds Mark III", 0, 0x3bb0, + { 5859,-211,-930,-8255,16017,2353,-1732,1887,7448 } }, + { "Canon EOS-1Ds Mark II", 0, 0xe80, + { 6517,-602,-867,-8180,15926,2378,-1618,1771,7633 } }, + { "Canon EOS-1D Mark IV", 0, 0x3bb0, + { 6014,-220,-795,-4109,12014,2361,-561,1824,5787 } }, + { "Canon EOS-1D Mark III", 0, 0x3bb0, + { 6291,-540,-976,-8350,16145,2311,-1714,1858,7326 } }, + { "Canon EOS-1D Mark II N", 0, 0xe80, + { 6240,-466,-822,-8180,15825,2500,-1801,1938,8042 } }, + { "Canon EOS-1D Mark II", 0, 0xe80, + { 6264,-582,-724,-8312,15948,2504,-1744,1919,8664 } }, + { "Canon EOS-1DS", 0, 0xe20, + { 4374,3631,-1743,-7520,15212,2472,-2892,3632,8161 } }, + { "Canon EOS-1D X", 0, 0, + { 6847,-614,-1014,-4669,12737,2139,-1197,2488,6846 } }, + { "Canon EOS-1D", 0, 0xe20, + { 6806,-179,-1020,-8097,16415,1687,-3267,4236,7690 } }, + { "Canon EOS", 0, 0, + { 8197,-2000,-1118,-6714,14335,2592,-2536,3178,8266 } }, + { "Canon PowerShot A530", 0, 0, + { 0 } }, /* don't want the A5 matrix */ + { "Canon PowerShot A50", 0, 0, + { -5300,9846,1776,3436,684,3939,-5540,9879,6200,-1404,11175,217 } }, + { "Canon PowerShot A5", 0, 0, + { -4801,9475,1952,2926,1611,4094,-5259,10164,5947,-1554,10883,547 } }, + { "Canon PowerShot G10", 0, 0, + { 11093,-3906,-1028,-5047,12492,2879,-1003,1750,5561 } }, + { "Canon PowerShot G11", 0, 0, + { 12177,-4817,-1069,-1612,9864,2049,-98,850,4471 } }, + { "Canon PowerShot G12", 0, 0, + { 13244,-5501,-1248,-1508,9858,1935,-270,1083,4366 } }, + { "Canon PowerShot G1 X", 0, 0, + { 7378,-1255,-1043,-4088,12251,2048,-876,1946,5805 } }, + { "Canon PowerShot G1", 0, 0, + { -4778,9467,2172,4743,-1141,4344,-5146,9908,6077,-1566,11051,557 } }, + { "Canon PowerShot G2", 0, 0, + { 9087,-2693,-1049,-6715,14382,2537,-2291,2819,7790 } }, + { "Canon PowerShot G3", 0, 0, + { 9212,-2781,-1073,-6573,14189,2605,-2300,2844,7664 } }, + { "Canon PowerShot G5", 0, 0, + { 9757,-2872,-933,-5972,13861,2301,-1622,2328,7212 } }, + { "Canon PowerShot G6", 0, 0, + { 9877,-3775,-871,-7613,14807,3072,-1448,1305,7485 } }, + { "Canon PowerShot G9", 0, 0, + { 7368,-2141,-598,-5621,13254,2625,-1418,1696,5743 } }, + { "Canon PowerShot Pro1", 0, 0, + { 10062,-3522,-999,-7643,15117,2730,-765,817,7323 } }, + { "Canon PowerShot Pro70", 34, 0, + { -4155,9818,1529,3939,-25,4522,-5521,9870,6610,-2238,10873,1342 } }, + { "Canon PowerShot Pro90", 0, 0, + { -4963,9896,2235,4642,-987,4294,-5162,10011,5859,-1770,11230,577 } }, + { "Canon PowerShot S30", 0, 0, + { 10566,-3652,-1129,-6552,14662,2006,-2197,2581,7670 } }, + { "Canon PowerShot S40", 0, 0, + { 8510,-2487,-940,-6869,14231,2900,-2318,2829,9013 } }, + { "Canon PowerShot S45", 0, 0, + { 8163,-2333,-955,-6682,14174,2751,-2077,2597,8041 } }, + { "Canon PowerShot S50", 0, 0, + { 8882,-2571,-863,-6348,14234,2288,-1516,2172,6569 } }, + { "Canon PowerShot S60", 0, 0, + { 8795,-2482,-797,-7804,15403,2573,-1422,1996,7082 } }, + { "Canon PowerShot S70", 0, 0, + { 9976,-3810,-832,-7115,14463,2906,-901,989,7889 } }, + { "Canon PowerShot S90", 0, 0, + { 12374,-5016,-1049,-1677,9902,2078,-83,852,4683 } }, + { "Canon PowerShot S95", 0, 0, + { 13440,-5896,-1279,-1236,9598,1931,-180,1001,4651 } }, + { "Canon PowerShot S100", 0, 0, + { 7968,-2565,-636,-2873,10697,2513,180,667,4211 } }, + { "Canon PowerShot A470", 0, 0, /* DJC */ + { 12513,-4407,-1242,-2680,10276,2405,-878,2215,4734 } }, + { "Canon PowerShot A610", 0, 0, /* DJC */ + { 15591,-6402,-1592,-5365,13198,2168,-1300,1824,5075 } }, + { "Canon PowerShot A620", 0, 0, /* DJC */ + { 15265,-6193,-1558,-4125,12116,2010,-888,1639,5220 } }, + { "Canon PowerShot A630", 0, 0, /* DJC */ + { 14201,-5308,-1757,-6087,14472,1617,-2191,3105,5348 } }, + { "Canon PowerShot A640", 0, 0, /* DJC */ + { 13124,-5329,-1390,-3602,11658,1944,-1612,2863,4885 } }, + { "Canon PowerShot A650", 0, 0, /* DJC */ + { 9427,-3036,-959,-2581,10671,1911,-1039,1982,4430 } }, + { "Canon PowerShot A720", 0, 0, /* DJC */ + { 14573,-5482,-1546,-1266,9799,1468,-1040,1912,3810 } }, + { "Canon PowerShot S3 IS", 0, 0, /* DJC */ + { 14062,-5199,-1446,-4712,12470,2243,-1286,2028,4836 } }, + { "Canon PowerShot SX1 IS", 0, 0, + { 6578,-259,-502,-5974,13030,3309,-308,1058,4970 } }, + { "Canon PowerShot SX110 IS", 0, 0, /* DJC */ + { 14134,-5576,-1527,-1991,10719,1273,-1158,1929,3581 } }, + { "Canon PowerShot SX220", 0, 0, /* DJC */ + { 13898,-5076,-1447,-1405,10109,1297,-244,1860,3687 } }, + { "CASIO EX-S20", 0, 0, /* DJC */ + { 11634,-3924,-1128,-4968,12954,2015,-1588,2648,7206 } }, + { "CASIO EX-Z750", 0, 0, /* DJC */ + { 10819,-3873,-1099,-4903,13730,1175,-1755,3751,4632 } }, + { "CASIO EX-Z10", 128, 0xfff, /* DJC */ + { 9790,-3338,-603,-2321,10222,2099,-344,1273,4799 } }, + { "CINE 650", 0, 0, + { 3390,480,-500,-800,3610,340,-550,2336,1192 } }, + { "CINE 660", 0, 0, + { 3390,480,-500,-800,3610,340,-550,2336,1192 } }, + { "CINE", 0, 0, + { 20183,-4295,-423,-3940,15330,3985,-280,4870,9800 } }, + { "Contax N Digital", 0, 0xf1e, + { 7777,1285,-1053,-9280,16543,2916,-3677,5679,7060 } }, + { "EPSON R-D1", 0, 0, + { 6827,-1878,-732,-8429,16012,2564,-704,592,7145 } }, + { "FUJIFILM E550", 0, 0, + { 11044,-3888,-1120,-7248,15168,2208,-1531,2277,8069 } }, + { "FUJIFILM E900", 0, 0, + { 9183,-2526,-1078,-7461,15071,2574,-2022,2440,8639 } }, + { "FUJIFILM F5", 0, 0, + { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, + { "FUJIFILM F6", 0, 0, + { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, + { "FUJIFILM F77", 0, 0, + { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, + { "FUJIFILM F7", 0, 0, + { 10004,-3219,-1201,-7036,15047,2107,-1863,2565,7736 } }, + { "FUJIFILM F8", 0, 0, + { 11044,-3888,-1120,-7248,15168,2208,-1531,2277,8069 } }, + { "FUJIFILM S100FS", 514, 0, + { 11521,-4355,-1065,-6524,13767,3058,-1466,1984,6045 } }, + { "FUJIFILM S200EXR", 512, 0x3fff, + { 11401,-4498,-1312,-5088,12751,2613,-838,1568,5941 } }, + { "FUJIFILM S20Pro", 0, 0, + { 10004,-3219,-1201,-7036,15047,2107,-1863,2565,7736 } }, + { "FUJIFILM S2Pro", 128, 0, + { 12492,-4690,-1402,-7033,15423,1647,-1507,2111,7697 } }, + { "FUJIFILM S3Pro", 0, 0, + { 11807,-4612,-1294,-8927,16968,1988,-2120,2741,8006 } }, + { "FUJIFILM S5Pro", 0, 0, + { 12300,-5110,-1304,-9117,17143,1998,-1947,2448,8100 } }, + { "FUJIFILM S5000", 0, 0, + { 8754,-2732,-1019,-7204,15069,2276,-1702,2334,6982 } }, + { "FUJIFILM S5100", 0, 0, + { 11940,-4431,-1255,-6766,14428,2542,-993,1165,7421 } }, + { "FUJIFILM S5500", 0, 0, + { 11940,-4431,-1255,-6766,14428,2542,-993,1165,7421 } }, + { "FUJIFILM S5200", 0, 0, + { 9636,-2804,-988,-7442,15040,2589,-1803,2311,8621 } }, + { "FUJIFILM S5600", 0, 0, + { 9636,-2804,-988,-7442,15040,2589,-1803,2311,8621 } }, + { "FUJIFILM S6", 0, 0, + { 12628,-4887,-1401,-6861,14996,1962,-2198,2782,7091 } }, + { "FUJIFILM S7000", 0, 0, + { 10190,-3506,-1312,-7153,15051,2238,-2003,2399,7505 } }, + { "FUJIFILM S9000", 0, 0, + { 10491,-3423,-1145,-7385,15027,2538,-1809,2275,8692 } }, + { "FUJIFILM S9500", 0, 0, + { 10491,-3423,-1145,-7385,15027,2538,-1809,2275,8692 } }, + { "FUJIFILM S9100", 0, 0, + { 12343,-4515,-1285,-7165,14899,2435,-1895,2496,8800 } }, + { "FUJIFILM S9600", 0, 0, + { 12343,-4515,-1285,-7165,14899,2435,-1895,2496,8800 } }, + { "FUJIFILM IS-1", 0, 0, + { 21461,-10807,-1441,-2332,10599,1999,289,875,7703 } }, + { "FUJIFILM IS Pro", 0, 0, + { 12300,-5110,-1304,-9117,17143,1998,-1947,2448,8100 } }, + { "FUJIFILM HS10 HS11", 0, 0xf68, + { 12440,-3954,-1183,-1123,9674,1708,-83,1614,4086 } }, + { "FUJIFILM HS20EXR", 0, 0, + { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, + { "FUJIFILM HS3", 0, 0, + { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, + { "FUJIFILM X100", 0, 0, + { 12161,-4457,-1069,-5034,12874,2400,-795,1724,6904 } }, + { "FUJIFILM X10", 0, 0, + { 13509,-6199,-1254,-4430,12733,1865,-331,1441,5022 } }, + { "FUJIFILM X-Pro1", 0, 0, + { 10413,-3996,-993,-3721,11640,2361,-733,1540,6011 } }, + { "FUJIFILM X-S1", 0, 0, + { 13509,-6199,-1254,-4430,12733,1865,-331,1441,5022 } }, + { "Imacon Ixpress", 0, 0, /* DJC */ + { 7025,-1415,-704,-5188,13765,1424,-1248,2742,6038 } }, + { "KODAK NC2000", 0, 0, + { 13891,-6055,-803,-465,9919,642,2121,82,1291 } }, + { "Kodak DCS315C", 8, 0, + { 17523,-4827,-2510,756,8546,-137,6113,1649,2250 } }, + { "Kodak DCS330C", 8, 0, + { 20620,-7572,-2801,-103,10073,-396,3551,-233,2220 } }, + { "KODAK DCS420", 0, 0, + { 10868,-1852,-644,-1537,11083,484,2343,628,2216 } }, + { "KODAK DCS460", 0, 0, + { 10592,-2206,-967,-1944,11685,230,2206,670,1273 } }, + { "KODAK EOSDCS1", 0, 0, + { 10592,-2206,-967,-1944,11685,230,2206,670,1273 } }, + { "KODAK EOSDCS3B", 0, 0, + { 9898,-2700,-940,-2478,12219,206,1985,634,1031 } }, + { "Kodak DCS520C", 180, 0, + { 24542,-10860,-3401,-1490,11370,-297,2858,-605,3225 } }, + { "Kodak DCS560C", 188, 0, + { 20482,-7172,-3125,-1033,10410,-285,2542,226,3136 } }, + { "Kodak DCS620C", 180, 0, + { 23617,-10175,-3149,-2054,11749,-272,2586,-489,3453 } }, + { "Kodak DCS620X", 185, 0, + { 13095,-6231,154,12221,-21,-2137,895,4602,2258 } }, + { "Kodak DCS660C", 214, 0, + { 18244,-6351,-2739,-791,11193,-521,3711,-129,2802 } }, + { "Kodak DCS720X", 0, 0, + { 11775,-5884,950,9556,1846,-1286,-1019,6221,2728 } }, + { "Kodak DCS760C", 0, 0, + { 16623,-6309,-1411,-4344,13923,323,2285,274,2926 } }, + { "Kodak DCS Pro SLR", 0, 0, + { 5494,2393,-232,-6427,13850,2846,-1876,3997,5445 } }, + { "Kodak DCS Pro 14nx", 0, 0, + { 5494,2393,-232,-6427,13850,2846,-1876,3997,5445 } }, + { "Kodak DCS Pro 14", 0, 0, + { 7791,3128,-776,-8588,16458,2039,-2455,4006,6198 } }, + { "Kodak ProBack645", 0, 0, + { 16414,-6060,-1470,-3555,13037,473,2545,122,4948 } }, + { "Kodak ProBack", 0, 0, + { 21179,-8316,-2918,-915,11019,-165,3477,-180,4210 } }, + { "KODAK P712", 0, 0, + { 9658,-3314,-823,-5163,12695,2768,-1342,1843,6044 } }, + { "KODAK P850", 0, 0xf7c, + { 10511,-3836,-1102,-6946,14587,2558,-1481,1792,6246 } }, + { "KODAK P880", 0, 0xfff, + { 12805,-4662,-1376,-7480,15267,2360,-1626,2194,7904 } }, + { "KODAK EasyShare Z980", 0, 0, + { 11313,-3559,-1101,-3893,11891,2257,-1214,2398,4908 } }, + { "KODAK EasyShare Z981", 0, 0, + { 12729,-4717,-1188,-1367,9187,2582,274,860,4411 } }, + { "KODAK EasyShare Z990", 0, 0xfed, + { 11749,-4048,-1309,-1867,10572,1489,-138,1449,4522 } }, + { "KODAK EASYSHARE Z1015", 0, 0xef1, + { 11265,-4286,-992,-4694,12343,2647,-1090,1523,5447 } }, + { "Leaf CMost", 0, 0, + { 3952,2189,449,-6701,14585,2275,-4536,7349,6536 } }, + { "Leaf Valeo 6", 0, 0, + { 3952,2189,449,-6701,14585,2275,-4536,7349,6536 } }, + { "Leaf Aptus 54S", 0, 0, + { 8236,1746,-1314,-8251,15953,2428,-3673,5786,5771 } }, + { "Leaf Aptus 65", 0, 0, + { 7914,1414,-1190,-8777,16582,2280,-2811,4605,5562 } }, + { "Leaf Aptus 75", 0, 0, + { 7914,1414,-1190,-8777,16582,2280,-2811,4605,5562 } }, + { "Leaf", 0, 0, + { 8236,1746,-1314,-8251,15953,2428,-3673,5786,5771 } }, + { "Mamiya ZD", 0, 0, + { 7645,2579,-1363,-8689,16717,2015,-3712,5941,5961 } }, + { "Micron 2010", 110, 0, /* DJC */ + { 16695,-3761,-2151,155,9682,163,3433,951,4904 } }, + { "Minolta DiMAGE 5", 0, 0xf7d, + { 8983,-2942,-963,-6556,14476,2237,-2426,2887,8014 } }, + { "Minolta DiMAGE 7Hi", 0, 0xf7d, + { 11368,-3894,-1242,-6521,14358,2339,-2475,3056,7285 } }, + { "Minolta DiMAGE 7", 0, 0xf7d, + { 9144,-2777,-998,-6676,14556,2281,-2470,3019,7744 } }, + { "Minolta DiMAGE A1", 0, 0xf8b, + { 9274,-2547,-1167,-8220,16323,1943,-2273,2720,8340 } }, + { "MINOLTA DiMAGE A200", 0, 0, + { 8560,-2487,-986,-8112,15535,2771,-1209,1324,7743 } }, + { "Minolta DiMAGE A2", 0, 0xf8f, + { 9097,-2726,-1053,-8073,15506,2762,-966,981,7763 } }, + { "Minolta DiMAGE Z2", 0, 0, /* DJC */ + { 11280,-3564,-1370,-4655,12374,2282,-1423,2168,5396 } }, + { "MINOLTA DYNAX 5", 0, 0xffb, + { 10284,-3283,-1086,-7957,15762,2316,-829,882,6644 } }, + { "MINOLTA DYNAX 7", 0, 0xffb, + { 10239,-3104,-1099,-8037,15727,2451,-927,925,6871 } }, + { "MOTOROLA PIXL", 0, 0, /* DJC */ + { 8898,-989,-1033,-3292,11619,1674,-661,3178,5216 } }, + { "NIKON D100", 0, 0, + { 5902,-933,-782,-8983,16719,2354,-1402,1455,6464 } }, + { "NIKON D1H", 0, 0, + { 7577,-2166,-926,-7454,15592,1934,-2377,2808,8606 } }, + { "NIKON D1X", 0, 0, + { 7702,-2245,-975,-9114,17242,1875,-2679,3055,8521 } }, + { "NIKON D1", 0, 0, /* multiplied by 2.218750, 1.0, 1.148438 */ + { 16772,-4726,-2141,-7611,15713,1972,-2846,3494,9521 } }, + { "NIKON D200", 0, 0xfbc, + { 8367,-2248,-763,-8758,16447,2422,-1527,1550,8053 } }, + { "NIKON D2H", 0, 0, + { 5710,-901,-615,-8594,16617,2024,-2975,4120,6830 } }, + { "NIKON D2X", 0, 0, + { 10231,-2769,-1255,-8301,15900,2552,-797,680,7148 } }, + { "NIKON D3000", 0, 0, + { 8736,-2458,-935,-9075,16894,2251,-1354,1242,8263 } }, + { "NIKON D3100", 0, 0, + { 7911,-2167,-813,-5327,13150,2408,-1288,2483,7968 } }, + { "NIKON D3200", 0, 0, + { 7013,-1408,-635,-5268,12902,2640,-1470,2801,7379 } }, + { "NIKON D300", 0, 0, + { 9030,-1992,-715,-8465,16302,2255,-2689,3217,8069 } }, + { "NIKON D3X", 0, 0, + { 7171,-1986,-648,-8085,15555,2718,-2170,2512,7457 } }, + { "NIKON D3S", 0, 0, + { 8828,-2406,-694,-4874,12603,2541,-660,1509,7587 } }, + { "NIKON D3", 0, 0, + { 8139,-2171,-663,-8747,16541,2295,-1925,2008,8093 } }, + { "NIKON D40X", 0, 0, + { 8819,-2543,-911,-9025,16928,2151,-1329,1213,8449 } }, + { "NIKON D40", 0, 0, + { 6992,-1668,-806,-8138,15748,2543,-874,850,7897 } }, + { "NIKON D4", 0, 0, + { 8598,-2848,-857,-5618,13606,2195,-1002,1773,7137 } }, + { "NIKON D5000", 0, 0xf00, + { 7309,-1403,-519,-8474,16008,2622,-2433,2826,8064 } }, + { "NIKON D5100", 0, 0x3de6, + { 8198,-2239,-724,-4871,12389,2798,-1043,2050,7181 } }, + { "NIKON D50", 0, 0, + { 7732,-2422,-789,-8238,15884,2498,-859,783,7330 } }, + { "NIKON D60", 0, 0, + { 8736,-2458,-935,-9075,16894,2251,-1354,1242,8263 } }, + { "NIKON D7000", 0, 0, + { 8198,-2239,-724,-4871,12389,2798,-1043,2050,7181 } }, + { "NIKON D700", 0, 0, + { 8139,-2171,-663,-8747,16541,2295,-1925,2008,8093 } }, + { "NIKON D70", 0, 0, + { 7732,-2422,-789,-8238,15884,2498,-859,783,7330 } }, + { "NIKON D800", 0, 0, + { 7866,-2108,-555,-4869,12483,2681,-1176,2069,7501 } }, + { "NIKON D80", 0, 0, + { 8629,-2410,-883,-9055,16940,2171,-1490,1363,8520 } }, + { "NIKON D90", 0, 0xf00, + { 7309,-1403,-519,-8474,16008,2622,-2434,2826,8064 } }, + { "NIKON E950", 0, 0x3dd, /* DJC */ + { -3746,10611,1665,9621,-1734,2114,-2389,7082,3064,3406,6116,-244 } }, + { "NIKON E995", 0, 0, /* copied from E5000 */ + { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, + { "NIKON E2100", 0, 0, /* copied from Z2, new white balance */ + { 13142,-4152,-1596,-4655,12374,2282,-1769,2696,6711} }, + { "NIKON E2500", 0, 0, + { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, + { "NIKON E3200", 0, 0, /* DJC */ + { 9846,-2085,-1019,-3278,11109,2170,-774,2134,5745 } }, + { "NIKON E4300", 0, 0, /* copied from Minolta DiMAGE Z2 */ + { 11280,-3564,-1370,-4655,12374,2282,-1423,2168,5396 } }, + { "NIKON E4500", 0, 0, + { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, + { "NIKON E5000", 0, 0, + { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, + { "NIKON E5400", 0, 0, + { 9349,-2987,-1001,-7919,15766,2266,-2098,2680,6839 } }, + { "NIKON E5700", 0, 0, + { -5368,11478,2368,5537,-113,3148,-4969,10021,5782,778,9028,211 } }, + { "NIKON E8400", 0, 0, + { 7842,-2320,-992,-8154,15718,2599,-1098,1342,7560 } }, + { "NIKON E8700", 0, 0, + { 8489,-2583,-1036,-8051,15583,2643,-1307,1407,7354 } }, + { "NIKON E8800", 0, 0, + { 7971,-2314,-913,-8451,15762,2894,-1442,1520,7610 } }, + { "NIKON COOLPIX P6000", 0, 0, + { 9698,-3367,-914,-4706,12584,2368,-837,968,5801 } }, + { "NIKON COOLPIX P7000", 0, 0, + { 11432,-3679,-1111,-3169,11239,2202,-791,1380,4455 } }, + { "NIKON COOLPIX P7100", 0, 0, + { 11053,-4269,-1024,-1976,10182,2088,-526,1263,4469 } }, + { "NIKON 1 ", 0, 0, + { 8994,-2667,-865,-4594,12324,2552,-699,1786,6260 } }, + { "OLYMPUS C5050", 0, 0, + { 10508,-3124,-1273,-6079,14294,1901,-1653,2306,6237 } }, + { "OLYMPUS C5060", 0, 0, + { 10445,-3362,-1307,-7662,15690,2058,-1135,1176,7602 } }, + { "OLYMPUS C7070", 0, 0, + { 10252,-3531,-1095,-7114,14850,2436,-1451,1723,6365 } }, + { "OLYMPUS C70", 0, 0, + { 10793,-3791,-1146,-7498,15177,2488,-1390,1577,7321 } }, + { "OLYMPUS C80", 0, 0, + { 8606,-2509,-1014,-8238,15714,2703,-942,979,7760 } }, + { "OLYMPUS E-10", 0, 0xffc, + { 12745,-4500,-1416,-6062,14542,1580,-1934,2256,6603 } }, + { "OLYMPUS E-1", 0, 0, + { 11846,-4767,-945,-7027,15878,1089,-2699,4122,8311 } }, + { "OLYMPUS E-20", 0, 0xffc, + { 13173,-4732,-1499,-5807,14036,1895,-2045,2452,7142 } }, + { "OLYMPUS E-300", 0, 0, + { 7828,-1761,-348,-5788,14071,1830,-2853,4518,6557 } }, + { "OLYMPUS E-330", 0, 0, + { 8961,-2473,-1084,-7979,15990,2067,-2319,3035,8249 } }, + { "OLYMPUS E-30", 0, 0xfbc, + { 8144,-1861,-1111,-7763,15894,1929,-1865,2542,7607 } }, + { "OLYMPUS E-3", 0, 0xf99, + { 9487,-2875,-1115,-7533,15606,2010,-1618,2100,7389 } }, + { "OLYMPUS E-400", 0, 0, + { 6169,-1483,-21,-7107,14761,2536,-2904,3580,8568 } }, + { "OLYMPUS E-410", 0, 0xf6a, + { 8856,-2582,-1026,-7761,15766,2082,-2009,2575,7469 } }, + { "OLYMPUS E-420", 0, 0xfd7, + { 8746,-2425,-1095,-7594,15612,2073,-1780,2309,7416 } }, + { "OLYMPUS E-450", 0, 0xfd2, + { 8745,-2425,-1095,-7594,15613,2073,-1780,2309,7416 } }, + { "OLYMPUS E-500", 0, 0, + { 8136,-1968,-299,-5481,13742,1871,-2556,4205,6630 } }, + { "OLYMPUS E-510", 0, 0xf6a, + { 8785,-2529,-1033,-7639,15624,2112,-1783,2300,7817 } }, + { "OLYMPUS E-520", 0, 0xfd2, + { 8344,-2322,-1020,-7596,15635,2048,-1748,2269,7287 } }, + { "OLYMPUS E-5", 0, 0, + { 11200,-3783,-1325,-4576,12593,2206,-695,1742,7504 } }, + { "OLYMPUS E-600", 0, 0xfaf, + { 8453,-2198,-1092,-7609,15681,2008,-1725,2337,7824 } }, + { "OLYMPUS E-620", 0, 0xfaf, + { 8453,-2198,-1092,-7609,15681,2008,-1725,2337,7824 } }, + { "OLYMPUS E-P1", 0, 0xffd, + { 8343,-2050,-1021,-7715,15705,2103,-1831,2380,8235 } }, + { "OLYMPUS E-P2", 0, 0xffd, + { 8343,-2050,-1021,-7715,15705,2103,-1831,2380,8235 } }, + { "OLYMPUS E-P3", 0, 0, + { 7575,-2159,-571,-3722,11341,2725,-1434,2819,6271 } }, + { "OLYMPUS E-PL1s", 0, 0, + { 11409,-3872,-1393,-4572,12757,2003,-709,1810,7415 } }, + { "OLYMPUS E-PL1", 0, 0, + { 11408,-4289,-1215,-4286,12385,2118,-387,1467,7787 } }, + { "OLYMPUS E-PL2", 0, 0, + { 15030,-5552,-1806,-3987,12387,1767,-592,1670,7023 } }, + { "OLYMPUS E-PL3", 0, 0, + { 7575,-2159,-571,-3722,11341,2725,-1434,2819,6271 } }, + { "OLYMPUS E-PM1", 0, 0, + { 7575,-2159,-571,-3722,11341,2725,-1434,2819,6271 } }, + { "OLYMPUS E-M5", 0, 0, + { 8380,-2630,-639,-2887,10725,2496,-627,1427,5438 } }, + { "OLYMPUS SP350", 0, 0, + { 12078,-4836,-1069,-6671,14306,2578,-786,939,7418 } }, + { "OLYMPUS SP3", 0, 0, + { 11766,-4445,-1067,-6901,14421,2707,-1029,1217,7572 } }, + { "OLYMPUS SP500UZ", 0, 0xfff, + { 9493,-3415,-666,-5211,12334,3260,-1548,2262,6482 } }, + { "OLYMPUS SP510UZ", 0, 0xffe, + { 10593,-3607,-1010,-5881,13127,3084,-1200,1805,6721 } }, + { "OLYMPUS SP550UZ", 0, 0xffe, + { 11597,-4006,-1049,-5432,12799,2957,-1029,1750,6516 } }, + { "OLYMPUS SP560UZ", 0, 0xff9, + { 10915,-3677,-982,-5587,12986,2911,-1168,1968,6223 } }, + { "OLYMPUS SP570UZ", 0, 0, + { 11522,-4044,-1146,-4736,12172,2904,-988,1829,6039 } }, + { "OLYMPUS XZ-1", 0, 0, + { 10901,-4095,-1074,-1141,9208,2293,-62,1417,5158 } }, + { "PENTAX *ist DL2", 0, 0, + { 10504,-2438,-1189,-8603,16207,2531,-1022,863,12242 } }, + { "PENTAX *ist DL", 0, 0, + { 10829,-2838,-1115,-8339,15817,2696,-837,680,11939 } }, + { "PENTAX *ist DS2", 0, 0, + { 10504,-2438,-1189,-8603,16207,2531,-1022,863,12242 } }, + { "PENTAX *ist DS", 0, 0, + { 10371,-2333,-1206,-8688,16231,2602,-1230,1116,11282 } }, + { "PENTAX *ist D", 0, 0, + { 9651,-2059,-1189,-8881,16512,2487,-1460,1345,10687 } }, + { "PENTAX K10D", 0, 0, + { 9566,-2863,-803,-7170,15172,2112,-818,803,9705 } }, + { "PENTAX K1", 0, 0, + { 11095,-3157,-1324,-8377,15834,2720,-1108,947,11688 } }, + { "PENTAX K20D", 0, 0, + { 9427,-2714,-868,-7493,16092,1373,-2199,3264,7180 } }, + { "PENTAX K200D", 0, 0, + { 9186,-2678,-907,-8693,16517,2260,-1129,1094,8524 } }, + { "PENTAX K2000", 0, 0, + { 11057,-3604,-1155,-5152,13046,2329,-282,375,8104 } }, + { "PENTAX K-m", 0, 0, + { 11057,-3604,-1155,-5152,13046,2329,-282,375,8104 } }, + { "PENTAX K-x", 0, 0, + { 8843,-2837,-625,-5025,12644,2668,-411,1234,7410 } }, + { "PENTAX K-r", 0, 0, + { 9895,-3077,-850,-5304,13035,2521,-883,1768,6936 } }, + { "PENTAX K-5", 0, 0, + { 8713,-2833,-743,-4342,11900,2772,-722,1543,6247 } }, + { "PENTAX K-7", 0, 0, + { 9142,-2947,-678,-8648,16967,1663,-2224,2898,8615 } }, + { "PENTAX 645D", 0, 0x3e00, + { 10646,-3593,-1158,-3329,11699,1831,-667,2874,6287 } }, + { "Panasonic DMC-FZ8", 0, 0xf7f, + { 8986,-2755,-802,-6341,13575,3077,-1476,2144,6379 } }, + { "Panasonic DMC-FZ18", 0, 0, + { 9932,-3060,-935,-5809,13331,2753,-1267,2155,5575 } }, + { "Panasonic DMC-FZ28", 15, 0xf96, + { 10109,-3488,-993,-5412,12812,2916,-1305,2140,5543 } }, + { "Panasonic DMC-FZ30", 0, 0xf94, + { 10976,-4029,-1141,-7918,15491,2600,-1670,2071,8246 } }, + { "Panasonic DMC-FZ3", 143, 0, + { 9938,-2780,-890,-4604,12393,2480,-1117,2304,4620 } }, + { "Panasonic DMC-FZ4", 143, 0, + { 13639,-5535,-1371,-1698,9633,2430,316,1152,4108 } }, + { "Panasonic DMC-FZ50", 0, 0, + { 7906,-2709,-594,-6231,13351,3220,-1922,2631,6537 } }, + { "LEICA V-LUX1", 0, 0, + { 7906,-2709,-594,-6231,13351,3220,-1922,2631,6537 } }, + { "Panasonic DMC-L10", 15, 0xf96, + { 8025,-1942,-1050,-7920,15904,2100,-2456,3005,7039 } }, + { "Panasonic DMC-L1", 0, 0xf7f, + { 8054,-1885,-1025,-8349,16367,2040,-2805,3542,7629 } }, + { "LEICA DIGILUX 3", 0, 0xf7f, + { 8054,-1885,-1025,-8349,16367,2040,-2805,3542,7629 } }, + { "Panasonic DMC-LC1", 0, 0, + { 11340,-4069,-1275,-7555,15266,2448,-2960,3426,7685 } }, + { "LEICA DIGILUX 2", 0, 0, + { 11340,-4069,-1275,-7555,15266,2448,-2960,3426,7685 } }, + { "Panasonic DMC-LX1", 0, 0xf7f, + { 10704,-4187,-1230,-8314,15952,2501,-920,945,8927 } }, + { "LEICA D-LUX2", 0, 0xf7f, + { 10704,-4187,-1230,-8314,15952,2501,-920,945,8927 } }, + { "Panasonic DMC-LX2", 0, 0, + { 8048,-2810,-623,-6450,13519,3272,-1700,2146,7049 } }, + { "LEICA D-LUX3", 0, 0, + { 8048,-2810,-623,-6450,13519,3272,-1700,2146,7049 } }, + { "Panasonic DMC-LX3", 15, 0, + { 8128,-2668,-655,-6134,13307,3161,-1782,2568,6083 } }, + { "LEICA D-LUX 4", 15, 0, + { 8128,-2668,-655,-6134,13307,3161,-1782,2568,6083 } }, + { "Panasonic DMC-LX5", 143, 0, + { 10909,-4295,-948,-1333,9306,2399,22,1738,4582 } }, + { "LEICA D-LUX 5", 143, 0, + { 10909,-4295,-948,-1333,9306,2399,22,1738,4582 } }, + { "Panasonic DMC-FZ100", 143, 0xfff, + { 16197,-6146,-1761,-2393,10765,1869,366,2238,5248 } }, + { "LEICA V-LUX 2", 143, 0xfff, + { 16197,-6146,-1761,-2393,10765,1869,366,2238,5248 } }, + { "Panasonic DMC-FZ150", 143, 0xfff, + { 11904,-4541,-1189,-2355,10899,1662,-296,1586,4289 } }, + { "LEICA V-LUX 3", 143, 0xfff, + { 11904,-4541,-1189,-2355,10899,1662,-296,1586,4289 } }, + { "Panasonic DMC-FX150", 15, 0xfff, + { 9082,-2907,-925,-6119,13377,3058,-1797,2641,5609 } }, + { "Panasonic DMC-G10", 0, 0, + { 10113,-3400,-1114,-4765,12683,2317,-377,1437,6710 } }, + { "Panasonic DMC-G1", 15, 0xf94, + { 8199,-2065,-1056,-8124,16156,2033,-2458,3022,7220 } }, + { "Panasonic DMC-G2", 15, 0xf3c, + { 10113,-3400,-1114,-4765,12683,2317,-377,1437,6710 } }, + { "Panasonic DMC-G3", 143, 0xfff, + { 6763,-1919,-863,-3868,11515,2684,-1216,2387,5879 } }, + { "Panasonic DMC-GF1", 15, 0xf92, + { 7888,-1902,-1011,-8106,16085,2099,-2353,2866,7330 } }, + { "Panasonic DMC-GF2", 143, 0xfff, + { 7888,-1902,-1011,-8106,16085,2099,-2353,2866,7330 } }, + { "Panasonic DMC-GF3", 143, 0xfff, + { 9051,-2468,-1204,-5212,13276,2121,-1197,2510,6890 } }, + { "Panasonic DMC-GF5", 143, 0xfff, + { 8228,-2945,-660,-3938,11792,2430,-1094,2278,5793 } }, + { "Panasonic DMC-GH1", 15, 0xf92, + { 6299,-1466,-532,-6535,13852,2969,-2331,3112,5984 } }, + { "Panasonic DMC-GH2", 15, 0xf95, + { 7780,-2410,-806,-3913,11724,2484,-1018,2390,5298 } }, + { "Panasonic DMC-GX1", 143, 0, + { 6763,-1919,-863,-3868,11515,2684,-1216,2387,5879 } }, + { "Phase One H 20", 0, 0, /* DJC */ + { 1313,1855,-109,-6715,15908,808,-327,1840,6020 } }, + { "Phase One H 25", 0, 0, + { 2905,732,-237,-8134,16626,1476,-3038,4253,7517 } }, + { "Phase One P 2", 0, 0, + { 2905,732,-237,-8134,16626,1476,-3038,4253,7517 } }, + { "Phase One P 30", 0, 0, + { 4516,-245,-37,-7020,14976,2173,-3206,4671,7087 } }, + { "Phase One P 45", 0, 0, + { 5053,-24,-117,-5684,14076,1702,-2619,4492,5849 } }, + { "Phase One P40", 0, 0, + { 8035,435,-962,-6001,13872,2320,-1159,3065,5434 } }, + { "Phase One P65", 0, 0, + { 8035,435,-962,-6001,13872,2320,-1159,3065,5434 } }, + { "RED ONE", 704, 0xffff, /* DJC */ + { 21014,-7891,-2613,-3056,12201,856,-2203,5125,8042 } }, + { "SAMSUNG EX1", 0, 0x3e00, + { 8898,-2498,-994,-3144,11328,2066,-760,1381,4576 } }, + { "SAMSUNG NX2", 0, 0xfff, /* NX20, NX200, NX210 */ + { 6933,-2268,-753,-4921,13387,1647,-803,1641,6096 } }, + { "SAMSUNG NX", 0, 0, /* NX5, NX10, NX11, NX100 */ + { 10332,-3234,-1168,-6111,14639,1520,-1352,2647,8331 } }, + { "SAMSUNG WB2000", 0, 0xfff, + { 12093,-3557,-1155,-1000,9534,1733,-22,1787,4576 } }, + { "SAMSUNG GX-1", 0, 0, + { 10504,-2438,-1189,-8603,16207,2531,-1022,863,12242 } }, + { "SAMSUNG S85", 0, 0xffff, /* DJC */ + { 11885,-3968,-1473,-4214,12299,1916,-835,1655,5549 } }, + { "Sinar", 0, 0, /* DJC */ + { 16442,-2956,-2422,-2877,12128,750,-1136,6066,4559 } }, + { "SONY DSC-F828", 491, 0, + { 7924,-1910,-777,-8226,15459,2998,-1517,2199,6818,-7242,11401,3481 } }, + { "SONY DSC-R1", 512, 0, + { 8512,-2641,-694,-8042,15670,2526,-1821,2117,7414 } }, + { "SONY DSC-V3", 0, 0, + { 7511,-2571,-692,-7894,15088,3060,-948,1111,8128 } }, + { "SONY DSLR-A100", 0, 0xfeb, + { 9437,-2811,-774,-8405,16215,2290,-710,596,7181 } }, + { "SONY DSLR-A290", 0, 0, + { 6038,-1484,-579,-9145,16746,2512,-875,746,7218 } }, + { "SONY DSLR-A2", 0, 0, + { 9847,-3091,-928,-8485,16345,2225,-715,595,7103 } }, + { "SONY DSLR-A300", 0, 0, + { 9847,-3091,-928,-8485,16345,2225,-715,595,7103 } }, + { "SONY DSLR-A330", 0, 0, + { 9847,-3091,-929,-8485,16346,2225,-714,595,7103 } }, + { "SONY DSLR-A350", 0, 0xffc, + { 6038,-1484,-578,-9146,16746,2513,-875,746,7217 } }, + { "SONY DSLR-A380", 0, 0, + { 6038,-1484,-579,-9145,16746,2512,-875,746,7218 } }, + { "SONY DSLR-A390", 0, 0, + { 6038,-1484,-579,-9145,16746,2512,-875,746,7218 } }, + { "SONY DSLR-A450", 128, 0xfeb, + { 4950,-580,-103,-5228,12542,3029,-709,1435,7371 } }, + { "SONY DSLR-A580", 128, 0xfeb, + { 5932,-1492,-411,-4813,12285,2856,-741,1524,6739 } }, + { "SONY DSLR-A5", 128, 0xfeb, + { 4950,-580,-103,-5228,12542,3029,-709,1435,7371 } }, + { "SONY DSLR-A700", 126, 0, + { 5775,-805,-359,-8574,16295,2391,-1943,2341,7249 } }, + { "SONY DSLR-A850", 128, 0, + { 5413,-1162,-365,-5665,13098,2866,-608,1179,8440 } }, + { "SONY DSLR-A900", 128, 0, + { 5209,-1072,-397,-8845,16120,2919,-1618,1803,8654 } }, + { "SONY NEX-5N", 128, 0, + { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, + { "SONY NEX-3", 138, 0, /* DJC */ + { 6907,-1256,-645,-4940,12621,2320,-1710,2581,6230 } }, + { "SONY NEX-5", 116, 0, /* DJC */ + { 6807,-1350,-342,-4216,11649,2567,-1089,2001,6420 } }, + { "SONY NEX-3", 128, 0, /* Adobe */ + { 6549,-1550,-436,-4880,12435,2753,-854,1868,6976 } }, + { "SONY NEX-5", 128, 0, /* Adobe */ + { 6549,-1550,-436,-4880,12435,2753,-854,1868,6976 } }, + { "SONY NEX-7", 128, 0, + { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } }, + { "SONY NEX", 128, 0, /* NEX-C3, NEX-F3 */ + { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, + { "SONY SLT-A33", 128, 0, + { 6069,-1221,-366,-5221,12779,2734,-1024,2066,6834 } }, + { "SONY SLT-A35", 128, 0, + { 5986,-1618,-415,-4557,11820,3120,-681,1404,6971 } }, + { "SONY SLT-A37", 128, 0, + { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, + { "SONY SLT-A55", 128, 0, + { 5932,-1492,-411,-4813,12285,2856,-741,1524,6739 } }, + { "SONY SLT-A57", 128, 0, + { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, + { "SONY SLT-A65", 128, 0, + { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } }, + { "SONY SLT-A77", 128, 0, + { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } } + }; + double cam_xyz[4][3]; + char name[130]; + int i, j; + + sprintf (name, "%s %s", make, model); + for (i=0; i < sizeof table / sizeof *table; i++) + if (!strncmp (name, table[i].prefix, strlen(table[i].prefix))) { + if (table[i].black) black = (ushort) table[i].black; + if (table[i].maximum) maximum = (ushort) table[i].maximum; + if (table[i].trans[0]) { + for (j=0; j < 12; j++) + cam_xyz[0][j] = table[i].trans[j] / 10000.0; + cam_xyz_coeff (cam_xyz); + } + break; + } +} + +void CLASS simple_coeff (int index) +{ + static const float table[][12] = { + /* index 0 -- all Foveon cameras */ + { 1.4032,-0.2231,-0.1016,-0.5263,1.4816,0.017,-0.0112,0.0183,0.9113 }, + /* index 1 -- Kodak DC20 and DC25 */ + { 2.25,0.75,-1.75,-0.25,-0.25,0.75,0.75,-0.25,-0.25,-1.75,0.75,2.25 }, + /* index 2 -- Logitech Fotoman Pixtura */ + { 1.893,-0.418,-0.476,-0.495,1.773,-0.278,-1.017,-0.655,2.672 }, + /* index 3 -- Nikon E880, E900, and E990 */ + { -1.936280, 1.800443, -1.448486, 2.584324, + 1.405365, -0.524955, -0.289090, 0.408680, + -1.204965, 1.082304, 2.941367, -1.818705 } + }; + int i, c; + + for (raw_color = i=0; i < 3; i++) + FORCC rgb_cam[i][c] = table[index][i*colors+c]; +} + +short CLASS guess_byte_order (int words) +{ + uchar test[4][2]; + int t=2, msb; + double diff, sum[2] = {0,0}; + + fread (test[0], 2, 2, ifp); + for (words-=2; words--; ) { + fread (test[t], 2, 1, ifp); + for (msb=0; msb < 2; msb++) { + diff = (test[t^2][msb] << 8 | test[t^2][!msb]) + - (test[t ][msb] << 8 | test[t ][!msb]); + sum[msb] += diff*diff; + } + t = (t+1) & 3; + } + return sum[0] < sum[1] ? 0x4d4d : 0x4949; +} + +float CLASS find_green (int bps, int bite, int off0, int off1) +{ + UINT64 bitbuf=0; + int vbits, col, i, c; + ushort img[2][2064]; + double sum[]={0,0}; + + FORC(2) { + fseek (ifp, c ? off1:off0, SEEK_SET); + for (vbits=col=0; col < width; col++) { + for (vbits -= bps; vbits < 0; vbits += bite) { + bitbuf <<= bite; + for (i=0; i < bite; i+=8) + bitbuf |= (unsigned) (fgetc(ifp) << i); + } + img[c][col] = bitbuf << (64-bps-vbits) >> (64-bps); + } + } + FORC(width-1) { + sum[ c & 1] += ABS(img[0][c]-img[1][c+1]); + sum[~c & 1] += ABS(img[1][c]-img[0][c+1]); + } + return 100 * log(sum[0]/sum[1]); +} + +/* + Identify which camera created this file, and set global variables + accordingly. + */ +void CLASS identify() +{ + char head[32], *cp; + int hlen, flen, fsize, zero_fsize=1, i, c, is_canon; + struct jhead jh; + short pana[][6] = { + { 3130, 1743, 4, 0, -6, 0 }, + { 3130, 2055, 4, 0, -6, 0 }, + { 3130, 2319, 4, 0, -6, 0 }, + { 3170, 2103, 18, 0,-42, 20 }, + { 3170, 2367, 18, 13,-42,-21 }, + { 3177, 2367, 0, 0, -1, 0 }, + { 3304, 2458, 0, 0, -1, 0 }, + { 3330, 2463, 9, 0, -5, 0 }, + { 3330, 2479, 9, 0,-17, 4 }, + { 3370, 1899, 15, 0,-44, 20 }, + { 3370, 2235, 15, 0,-44, 20 }, + { 3370, 2511, 15, 10,-44,-21 }, + { 3690, 2751, 3, 0, -8, -3 }, + { 3710, 2751, 0, 0, -3, 0 }, + { 3724, 2450, 0, 0, 0, -2 }, + { 3770, 2487, 17, 0,-44, 19 }, + { 3770, 2799, 17, 15,-44,-19 }, + { 3880, 2170, 6, 0, -6, 0 }, + { 4060, 3018, 0, 0, 0, -2 }, + { 4290, 2391, 3, 0, -8, -1 }, + { 4330, 2439, 17, 15,-44,-19 }, + { 4508, 2962, 0, 0, -3, -4 }, + { 4508, 3330, 0, 0, -3, -6 } }; + static const struct { + int fsize; + char make[12], model[19], withjpeg; + } table[] = { + { 62464, "Kodak", "DC20" ,0 }, + { 124928, "Kodak", "DC20" ,0 }, + { 1652736, "Kodak", "DCS200" ,0 }, + { 4159302, "Kodak", "C330" ,0 }, + { 4162462, "Kodak", "C330" ,0 }, + { 460800, "Kodak", "C603v" ,0 }, + { 614400, "Kodak", "C603v" ,0 }, + { 6163328, "Kodak", "C603" ,0 }, + { 6166488, "Kodak", "C603" ,0 }, + { 9116448, "Kodak", "C603y" ,0 }, + { 311696, "ST Micro", "STV680 VGA" ,0 }, /* SPYz */ + { 787456, "Creative", "PC-CAM 600" ,0 }, + { 1138688, "Minolta", "RD175" ,0 }, + { 3840000, "Foculus", "531C" ,0 }, + { 307200, "Generic", "640x480" ,0 }, + { 786432, "AVT", "F-080C" ,0 }, + { 1447680, "AVT", "F-145C" ,0 }, + { 1920000, "AVT", "F-201C" ,0 }, + { 5067304, "AVT", "F-510C" ,0 }, + { 5067316, "AVT", "F-510C" ,0 }, + { 10134608, "AVT", "F-510C" ,0 }, + { 10134620, "AVT", "F-510C" ,0 }, + { 16157136, "AVT", "F-810C" ,0 }, + { 1409024, "Sony", "XCD-SX910CR" ,0 }, + { 2818048, "Sony", "XCD-SX910CR" ,0 }, + { 3884928, "Micron", "2010" ,0 }, + { 6624000, "Pixelink", "A782" ,0 }, + { 13248000, "Pixelink", "A782" ,0 }, + { 6291456, "RoverShot","3320AF" ,0 }, + { 6553440, "Canon", "PowerShot A460" ,0 }, + { 6653280, "Canon", "PowerShot A530" ,0 }, + { 6573120, "Canon", "PowerShot A610" ,0 }, + { 9219600, "Canon", "PowerShot A620" ,0 }, + { 9243240, "Canon", "PowerShot A470" ,0 }, + { 10341600, "Canon", "PowerShot A720 IS",0 }, + { 10383120, "Canon", "PowerShot A630" ,0 }, + { 12945240, "Canon", "PowerShot A640" ,0 }, + { 15636240, "Canon", "PowerShot A650" ,0 }, + { 5298000, "Canon", "PowerShot SD300" ,0 }, + { 7710960, "Canon", "PowerShot S3 IS" ,0 }, + { 15467760, "Canon", "PowerShot SX110 IS",0 }, + { 15534576, "Canon", "PowerShot SX120 IS",0 }, + { 18653760, "Canon", "PowerShot SX20 IS",0 }, + { 19131120, "Canon", "PowerShot SX220 HS",0 }, + { 21936096, "Canon", "PowerShot SX30 IS",0 }, + { 5939200, "OLYMPUS", "C770UZ" ,0 }, + { 1581060, "NIKON", "E900" ,1 }, /* or E900s,E910 */ + { 2465792, "NIKON", "E950" ,1 }, /* or E800,E700 */ + { 2940928, "NIKON", "E2100" ,1 }, /* or E2500 */ + { 4771840, "NIKON", "E990" ,1 }, /* or E995, Oly C3030Z */ + { 4775936, "NIKON", "E3700" ,1 }, /* or Optio 33WR */ + { 5869568, "NIKON", "E4300" ,1 }, /* or DiMAGE Z2 */ + { 5865472, "NIKON", "E4500" ,1 }, + { 7438336, "NIKON", "E5000" ,1 }, /* or E5700 */ + { 8998912, "NIKON", "COOLPIX S6" ,1 }, + { 1976352, "CASIO", "QV-2000UX" ,1 }, + { 3217760, "CASIO", "QV-3*00EX" ,1 }, + { 6218368, "CASIO", "QV-5700" ,1 }, + { 6054400, "CASIO", "QV-R41" ,1 }, + { 7530816, "CASIO", "QV-R51" ,1 }, + { 7684000, "CASIO", "QV-4000" ,1 }, + { 2937856, "CASIO", "EX-S20" ,1 }, + { 4948608, "CASIO", "EX-S100" ,1 }, + { 7542528, "CASIO", "EX-Z50" ,1 }, + { 7562048, "CASIO", "EX-Z500" ,1 }, + { 7753344, "CASIO", "EX-Z55" ,1 }, + { 7816704, "CASIO", "EX-Z60" ,1 }, + { 10843712, "CASIO", "EX-Z75" ,1 }, + { 10834368, "CASIO", "EX-Z750" ,1 }, + { 12310144, "CASIO", "EX-Z850" ,1 }, + { 12489984, "CASIO", "EX-Z8" ,1 }, + { 15499264, "CASIO", "EX-Z1050" ,1 }, + { 7426656, "CASIO", "EX-P505" ,1 }, + { 9313536, "CASIO", "EX-P600" ,1 }, + { 10979200, "CASIO", "EX-P700" ,1 }, + { 3178560, "PENTAX", "Optio S" ,1 }, + { 4841984, "PENTAX", "Optio S" ,1 }, + { 6114240, "PENTAX", "Optio S4" ,1 }, /* or S4i, CASIO EX-Z4 */ + { 10702848, "PENTAX", "Optio 750Z" ,1 }, + { 15980544, "AGFAPHOTO","DC-833m" ,1 }, + { 16098048, "SAMSUNG", "S85" ,1 }, + { 16215552, "SAMSUNG", "S85" ,1 }, + { 20487168, "SAMSUNG", "WB550" ,1 }, + { 24000000, "SAMSUNG", "WB550" ,1 }, + { 12582980, "Sinar", "" ,0 }, + { 33292868, "Sinar", "" ,0 }, + { 44390468, "Sinar", "" ,0 } }; + static const char *corp[] = + { "Canon", "NIKON", "EPSON", "KODAK", "Kodak", "OLYMPUS", "PENTAX", + "MINOLTA", "Minolta", "Konica", "CASIO", "Sinar", "Phase One", + "SAMSUNG", "Mamiya", "MOTOROLA", "LEICA" }; + + tiff_flip = flip = filters = -1; /* 0 is valid, so -1 is unknown */ + raw_height = raw_width = fuji_width = fuji_layout = cr2_slice[0] = 0; + maximum = height = width = top_margin = left_margin = 0; + cdesc[0] = desc[0] = artist[0] = make[0] = model[0] = model2[0] = 0; + iso_speed = shutter = aperture = focal_len = unique_id = 0; + tiff_nifds = 0; + memset (tiff_ifd, 0, sizeof tiff_ifd); + memset (gpsdata, 0, sizeof gpsdata); + memset (cblack, 0, sizeof cblack); + memset (white, 0, sizeof white); + memset (mask, 0, sizeof mask); + thumb_offset = thumb_length = thumb_width = thumb_height = 0; + load_raw = thumb_load_raw = 0; + write_thumb = &CLASS jpeg_thumb; + data_offset = meta_length = tiff_bps = tiff_compress = 0; + kodak_cbpp = zero_after_ff = dng_version = load_flags = 0; + timestamp = shot_order = tiff_samples = black = is_foveon = 0; + mix_green = profile_length = data_error = zero_is_bad = 0; + pixel_aspect = is_raw = raw_color = 1; + tile_width = tile_length = 0; + for (i=0; i < 4; i++) { + cam_mul[i] = i == 1; + pre_mul[i] = i < 3; + FORC3 cmatrix[c][i] = 0; + FORC3 rgb_cam[c][i] = c == i; + } + colors = 3; + for (i=0; i < 0x10000; i++) curve[i] = i; + + order = get2(); + hlen = get4(); + fseek (ifp, 0, SEEK_SET); + fread (head, 1, 32, ifp); + fseek (ifp, 0, SEEK_END); + flen = fsize = ftell(ifp); + if ((cp = (char *) memmem (head, 32, "MMMM", 4)) || + (cp = (char *) memmem (head, 32, "IIII", 4))) { + parse_phase_one (cp-head); + if (cp-head && parse_tiff(0)) apply_tiff(); + } else if (order == 0x4949 || order == 0x4d4d) { + if (!memcmp (head+6,"HEAPCCDR",8)) { + data_offset = hlen; + parse_ciff (hlen, flen - hlen); + } else if (parse_tiff(0)) apply_tiff(); + } else if (!memcmp (head,"\xff\xd8\xff\xe1",4) && + !memcmp (head+6,"Exif",4)) { + fseek (ifp, 4, SEEK_SET); + data_offset = 4 + get2(); + fseek (ifp, data_offset, SEEK_SET); + if (fgetc(ifp) != 0xff) + parse_tiff(12); + thumb_offset = 0; + } else if (!memcmp (head+25,"ARECOYK",7)) { + strcpy (make, "Contax"); + strcpy (model,"N Digital"); + fseek (ifp, 33, SEEK_SET); + get_timestamp(1); + fseek (ifp, 60, SEEK_SET); + FORC4 cam_mul[c ^ (c >> 1)] = get4(); + } else if (!strcmp (head, "PXN")) { + strcpy (make, "Logitech"); + strcpy (model,"Fotoman Pixtura"); + } else if (!strcmp (head, "qktk")) { + strcpy (make, "Apple"); + strcpy (model,"QuickTake 100"); + load_raw = &CLASS quicktake_100_load_raw; + } else if (!strcmp (head, "qktn")) { + strcpy (make, "Apple"); + strcpy (model,"QuickTake 150"); + load_raw = &CLASS kodak_radc_load_raw; + } else if (!memcmp (head,"FUJIFILM",8)) { + fseek (ifp, 84, SEEK_SET); + thumb_offset = get4(); + thumb_length = get4(); + fseek (ifp, 92, SEEK_SET); + parse_fuji (get4()); + if (thumb_offset > 120) { + fseek (ifp, 120, SEEK_SET); + is_raw += (i = get4()) && 1; + if (is_raw == 2 && shot_select) + parse_fuji (i); + } + load_raw = &CLASS unpacked_load_raw; + fseek (ifp, 100+28*(shot_select > 0), SEEK_SET); + parse_tiff (data_offset = get4()); + parse_tiff (thumb_offset+12); + apply_tiff(); + } else if (!memcmp (head,"RIFF",4)) { + fseek (ifp, 0, SEEK_SET); + parse_riff(); + } else if (!memcmp (head,"\0\001\0\001\0@",6)) { + fseek (ifp, 6, SEEK_SET); + fread (make, 1, 8, ifp); + fread (model, 1, 8, ifp); + fread (model2, 1, 16, ifp); + data_offset = get2(); + get2(); + raw_width = get2(); + raw_height = get2(); + load_raw = &CLASS nokia_load_raw; + filters = 0x61616161; + } else if (!memcmp (head,"NOKIARAW",8)) { + strcpy (make, "NOKIA"); + strcpy (model, "X2"); + order = 0x4949; + fseek (ifp, 300, SEEK_SET); + data_offset = get4(); + i = get4(); + width = get2(); + height = get2(); + data_offset += i - width * 5 / 4 * height; + load_raw = &CLASS nokia_load_raw; + filters = 0x61616161; + } else if (!memcmp (head,"ARRI",4)) { + order = 0x4949; + fseek (ifp, 20, SEEK_SET); + width = get4(); + height = get4(); + strcpy (make, "ARRI"); + fseek (ifp, 668, SEEK_SET); + fread (model, 1, 64, ifp); + data_offset = 4096; + load_raw = &CLASS packed_load_raw; + load_flags = 88; + filters = 0x61616161; + } else if (!memcmp (head+4,"RED1",4)) { + strcpy (make, "RED"); + strcpy (model,"ONE"); + parse_redcine(); + load_raw = &CLASS redcine_load_raw; + gamma_curve (1/2.4, 12.92, 1, 4095); + filters = 0x49494949; + } else if (!memcmp (head,"DSC-Image",9)) + parse_rollei(); + else if (!memcmp (head,"PWAD",4)) + parse_sinar_ia(); + else if (!memcmp (head,"\0MRM",4)) + parse_minolta(0); + else if (!memcmp (head,"FOVb",4)) + parse_foveon(); + else if (!memcmp (head,"CI",2)) + parse_cine(); + else + for (zero_fsize=i=0; i < sizeof table / sizeof *table; i++) + if (fsize == table[i].fsize) { + strcpy (make, table[i].make ); + strcpy (model, table[i].model); + if (table[i].withjpeg) + parse_external_jpeg(); + } + if (zero_fsize) fsize = 0; + if (make[0] == 0) parse_smal (0, flen); + if (make[0] == 0) parse_jpeg (is_raw = 0); + + for (i=0; i < sizeof corp / sizeof *corp; i++) + if (strstr (make, corp[i])) /* Simplify company names */ + strcpy (make, corp[i]); + if (!strncmp (make,"KODAK",5) && + ((cp = strstr(model," DIGITAL CAMERA")) || + (cp = strstr(model," Digital Camera")) || + (cp = strstr(model,"FILE VERSION")))) + *cp = 0; + cp = make + strlen(make); /* Remove trailing spaces */ + while (*--cp == ' ') *cp = 0; + cp = model + strlen(model); + while (*--cp == ' ') *cp = 0; + i = strlen(make); /* Remove make from model */ + if (!strncasecmp (model, make, i) && model[i++] == ' ') + memmove (model, model+i, 64-i); + if (!strncmp (model,"FinePix ",8)) + strcpy (model, model+8); + if (!strncmp (model,"Digital Camera ",15)) + strcpy (model, model+15); + desc[511] = artist[63] = make[63] = model[63] = model2[63] = 0; + if (!is_raw) goto notraw; + + if (!height) height = raw_height; + if (!width) width = raw_width; + if (height == 2624 && width == 3936) /* Pentax K10D and Samsung GX10 */ + { height = 2616; width = 3896; } + if (height == 3136 && width == 4864) /* Pentax K20D and Samsung GX20 */ + { height = 3124; width = 4688; filters = 0x16161616; } + if (width == 4352 && (!strcmp(model,"K-r") || !strcmp(model,"K-x"))) + { width = 4309; filters = 0x16161616; } + if (width >= 4960 && !strcmp(model,"K-5")) + { left_margin = 10; width = 4950; filters = 0x16161616; } + if (width == 4736 && !strcmp(model,"K-7")) + { height = 3122; width = 4684; filters = 0x16161616; top_margin = 2; } + if (width == 7424 && !strcmp(model,"645D")) + { height = 5502; width = 7328; filters = 0x61616161; top_margin = 29; + left_margin = 48; } + if (height == 3014 && width == 4096) /* Ricoh GX200 */ + width = 4014; + if (dng_version) { + if (filters == UINT_MAX) filters = 0; + if (filters) is_raw = tiff_samples; + else colors = tiff_samples; + if (tiff_compress == 1) + load_raw = &CLASS packed_dng_load_raw; + if (tiff_compress == 7) + load_raw = &CLASS lossless_dng_load_raw; + goto dng_skip; + } + if ((is_canon = !strcmp(make,"Canon"))) + load_raw = memcmp (head+6,"HEAPCCDR",8) ? + &CLASS lossless_jpeg_load_raw : &CLASS canon_load_raw; + if (!strcmp(make,"NIKON")) { + if (!load_raw) + load_raw = &CLASS packed_load_raw; + if (model[0] == 'E') + load_flags |= !data_offset << 2 | 2; + } + if (!strcmp(make,"CASIO")) { + load_raw = &CLASS packed_load_raw; + maximum = 0xf7f; + } + +/* Set parameters based on camera name (for non-DNG files). */ + + if (is_foveon) { + if (height*2 < width) pixel_aspect = 0.5; + if (height > width) pixel_aspect = 2; + filters = 0; + simple_coeff(0); + } else if (is_canon && tiff_bps == 15) { + switch (width) { + case 3344: width -= 66; + case 3872: width -= 6; + } + filters = 0; + load_raw = &CLASS canon_sraw_load_raw; + } else if (!strcmp(model,"PowerShot 600")) { + height = 613; + width = 854; + raw_width = 896; + pixel_aspect = 607/628.0; + colors = 4; + filters = 0xe1e4e1e4; + load_raw = &CLASS canon_600_load_raw; + } else if (!strcmp(model,"PowerShot A5") || + !strcmp(model,"PowerShot A5 Zoom")) { + height = 773; + width = 960; + raw_width = 992; + pixel_aspect = 256/235.0; + colors = 4; + filters = 0x1e4e1e4e; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A50")) { + height = 968; + width = 1290; + raw_width = 1320; + colors = 4; + filters = 0x1b4e4b1e; + goto canon_a5; + } else if (!strcmp(model,"PowerShot Pro70")) { + height = 1024; + width = 1552; + colors = 4; + filters = 0x1e4b4e1b; + goto canon_a5; + } else if (!strcmp(model,"PowerShot SD300")) { + height = 1752; + width = 2344; + raw_height = 1766; + raw_width = 2400; + top_margin = 12; + left_margin = 12; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A460")) { + height = 1960; + width = 2616; + raw_height = 1968; + raw_width = 2664; + top_margin = 4; + left_margin = 4; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A530")) { + height = 1984; + width = 2620; + raw_height = 1992; + raw_width = 2672; + top_margin = 6; + left_margin = 10; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A610")) { + if (canon_s2is()) strcpy (model+10, "S2 IS"); + height = 1960; + width = 2616; + raw_height = 1968; + raw_width = 2672; + top_margin = 8; + left_margin = 12; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A620")) { + height = 2328; + width = 3112; + raw_height = 2340; + raw_width = 3152; + top_margin = 12; + left_margin = 36; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A470")) { + height = 2328; + width = 3096; + raw_height = 2346; + raw_width = 3152; + top_margin = 6; + left_margin = 12; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A720 IS")) { + height = 2472; + width = 3298; + raw_height = 2480; + raw_width = 3336; + top_margin = 5; + left_margin = 6; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A630")) { + height = 2472; + width = 3288; + raw_height = 2484; + raw_width = 3344; + top_margin = 6; + left_margin = 12; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A640")) { + height = 2760; + width = 3672; + raw_height = 2772; + raw_width = 3736; + top_margin = 6; + left_margin = 12; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A650")) { + height = 3024; + width = 4032; + raw_height = 3048; + raw_width = 4104; + top_margin = 12; + left_margin = 48; + goto canon_a5; + } else if (!strcmp(model,"PowerShot S3 IS")) { + height = 2128; + width = 2840; + raw_height = 2136; + raw_width = 2888; + top_margin = 8; + left_margin = 44; +canon_a5: + tiff_bps = 10; + load_raw = &CLASS packed_load_raw; + load_flags = 40; + if (raw_width > 1600) zero_is_bad = 1; + } else if (!strcmp(model,"PowerShot SX110 IS")) { + height = 2760; + width = 3684; + raw_height = 2772; + raw_width = 3720; + top_margin = 12; + left_margin = 6; + load_raw = &CLASS packed_load_raw; + load_flags = 40; + zero_is_bad = 1; + } else if (!strcmp(model,"PowerShot SX120 IS")) { + height = 2742; + width = 3664; + raw_height = 2778; + raw_width = 3728; + top_margin = 18; + left_margin = 16; + filters = 0x49494949; + load_raw = &CLASS packed_load_raw; + load_flags = 40; + zero_is_bad = 1; + } else if (!strcmp(model,"PowerShot SX20 IS")) { + height = 3024; + width = 4032; + raw_height = 3048; + raw_width = 4080; + top_margin = 12; + left_margin = 24; + load_raw = &CLASS packed_load_raw; + load_flags = 40; + zero_is_bad = 1; + } else if (!strcmp(model,"PowerShot SX220 HS")) { + height = 3043; + width = 4072; + raw_height = 3060; + raw_width = 4168; + mask[0][0] = top_margin = 16; + mask[0][2] = top_margin + height; + mask[0][3] = left_margin = 92; + load_raw = &CLASS packed_load_raw; + load_flags = 8; + zero_is_bad = 1; + } else if (!strcmp(model,"PowerShot SX30 IS")) { + height = 3254; + width = 4366; + raw_height = 3276; + raw_width = 4464; + top_margin = 10; + left_margin = 25; + filters = 0x16161616; + load_raw = &CLASS packed_load_raw; + load_flags = 40; + zero_is_bad = 1; + } else if (!strcmp(model,"PowerShot Pro90 IS")) { + width = 1896; + colors = 4; + filters = 0xb4b4b4b4; + } else if (is_canon && raw_width == 2144) { + height = 1550; + width = 2088; + top_margin = 8; + left_margin = 4; + if (!strcmp(model,"PowerShot G1")) { + colors = 4; + filters = 0xb4b4b4b4; + } + } else if (is_canon && raw_width == 2224) { + height = 1448; + width = 2176; + top_margin = 6; + left_margin = 48; + } else if (is_canon && raw_width == 2376) { + height = 1720; + width = 2312; + top_margin = 6; + left_margin = 12; + } else if (is_canon && raw_width == 2672) { + height = 1960; + width = 2616; + top_margin = 6; + left_margin = 12; + } else if (is_canon && raw_width == 3152) { + height = 2056; + width = 3088; + top_margin = 12; + left_margin = 64; + if (unique_id == 0x80000170) + adobe_coeff ("Canon","EOS 300D"); + } else if (is_canon && raw_width == 3160) { + height = 2328; + width = 3112; + top_margin = 12; + left_margin = 44; + } else if (is_canon && raw_width == 3344) { + height = 2472; + width = 3288; + top_margin = 6; + left_margin = 4; + } else if (!strcmp(model,"EOS D2000C")) { + filters = 0x61616161; + black = curve[200]; + } else if (is_canon && raw_width == 3516) { + top_margin = 14; + left_margin = 42; + if (unique_id == 0x80000189) + adobe_coeff ("Canon","EOS 350D"); + goto canon_cr2; + } else if (is_canon && raw_width == 3596) { + top_margin = 12; + left_margin = 74; + goto canon_cr2; + } else if (is_canon && raw_width == 3744) { + height = 2760; + width = 3684; + top_margin = 16; + left_margin = 8; + if (unique_id > 0x2720000) { + top_margin = 12; + left_margin = 52; + } + } else if (is_canon && raw_width == 3944) { + height = 2602; + width = 3908; + top_margin = 18; + left_margin = 30; + } else if (is_canon && raw_width == 3948) { + top_margin = 18; + left_margin = 42; + height -= 2; + if (unique_id == 0x80000236) + adobe_coeff ("Canon","EOS 400D"); + if (unique_id == 0x80000254) + adobe_coeff ("Canon","EOS 1000D"); + goto canon_cr2; + } else if (is_canon && raw_width == 3984) { + top_margin = 20; + left_margin = 76; + height -= 2; + goto canon_cr2; + } else if (is_canon && raw_width == 4104) { + height = 3024; + width = 4032; + top_margin = 12; + left_margin = 48; + } else if (is_canon && raw_width == 4152) { + top_margin = 12; + left_margin = 192; + goto canon_cr2; + } else if (is_canon && raw_width == 4160) { + height = 3048; + width = 4048; + top_margin = 11; + left_margin = 104; + } else if (is_canon && raw_width == 4312) { + top_margin = 18; + left_margin = 22; + height -= 2; + if (unique_id == 0x80000176) + adobe_coeff ("Canon","EOS 450D"); + goto canon_cr2; + } else if (is_canon && raw_width == 4352) { + top_margin = 18; + left_margin = 62; + if (unique_id == 0x80000288) + adobe_coeff ("Canon","EOS 1100D"); + goto canon_cr2; + } else if (is_canon && raw_width == 4476) { + top_margin = 34; + left_margin = 90; + goto canon_cr2; + } else if (is_canon && raw_width == 4480) { + height = 3326; + width = 4432; + top_margin = 10; + left_margin = 12; + filters = 0x49494949; + } else if (is_canon && raw_width == 4496) { + height = 3316; + width = 4404; + top_margin = 50; + left_margin = 80; + } else if (is_canon && raw_width == 4832) { + top_margin = unique_id == 0x80000261 ? 51:26; + left_margin = 62; + if (unique_id == 0x80000252) + adobe_coeff ("Canon","EOS 500D"); + goto canon_cr2; + } else if (is_canon && raw_width == 5108) { + top_margin = 13; + left_margin = 98; + goto canon_cr2; + } else if (is_canon && raw_width == 5120) { + height -= top_margin = 45; + left_margin = 142; + width = 4916; + } else if (is_canon && raw_width == 5344) { + top_margin = 51; + left_margin = 142; + if (unique_id == 0x80000269) { + top_margin = 100; + left_margin = 126; + height -= 2; + adobe_coeff ("Canon","EOS-1D X"); + } + if (unique_id == 0x80000270) + adobe_coeff ("Canon","EOS 550D"); + if (unique_id == 0x80000286) + adobe_coeff ("Canon","EOS 600D"); + goto canon_cr2; + } else if (is_canon && raw_width == 5360) { + top_margin = 51; + left_margin = 158; + goto canon_cr2; + } else if (is_canon && raw_width == 5712) { + height = 3752; + width = 5640; + top_margin = 20; + left_margin = 62; + } else if (is_canon && raw_width == 5792) { + top_margin = 51; + left_margin = 158; +canon_cr2: + height -= top_margin; + width -= left_margin; + } else if (is_canon && raw_width == 5920) { + height = 3870; + width = 5796; + top_margin = 80; + left_margin = 122; + } else if (!strcmp(model,"D1")) { + cam_mul[0] *= 256/527.0; + cam_mul[2] *= 256/317.0; + } else if (!strcmp(model,"D1X")) { + width -= 4; + pixel_aspect = 0.5; + } else if (!strcmp(model,"D40X") || + !strcmp(model,"D60") || + !strcmp(model,"D80") || + !strcmp(model,"D3000")) { + height -= 3; + width -= 4; + } else if (!strcmp(model,"D3") || + !strcmp(model,"D3S") || + !strcmp(model,"D700")) { + width -= 4; + left_margin = 2; + } else if (!strcmp(model,"D3100")) { + width -= 28; + left_margin = 6; + } else if (!strcmp(model,"D5000") || + !strcmp(model,"D90")) { + width -= 42; + } else if (!strcmp(model,"D5100") || + !strcmp(model,"D7000")) { + width -= 44; + } else if (!strcmp(model,"D3200") || + !strcmp(model,"D800")) { + width -= 46; + } else if (!strcmp(model,"D4")) { + width -= 52; + left_margin = 2; + } else if (!strncmp(model,"D40",3) || + !strncmp(model,"D50",3) || + !strncmp(model,"D70",3)) { + width--; + } else if (!strcmp(model,"D100")) { + if (tiff_compress == 34713 && !nikon_is_compressed()) { + load_raw = &CLASS packed_load_raw; + load_flags |= 1; + raw_width = (width += 3) + 3; + } + } else if (!strcmp(model,"D200")) { + left_margin = 1; + width -= 4; + filters = 0x94949494; + } else if (!strncmp(model,"D2H",3)) { + left_margin = 6; + width -= 14; + } else if (!strncmp(model,"D2X",3)) { + if (width == 3264) width -= 32; + else width -= 8; + } else if (!strncmp(model,"D300",4)) { + width -= 32; + } else if (!strncmp(model,"COOLPIX P",9)) { + load_flags = 24; + filters = 0x94949494; + if (model[9] == '7' && iso_speed >= 400) + black = 255; + } else if (!strncmp(model,"1 ",2)) { + height -= 2; + } else if (fsize == 1581060) { + height = 963; + width = 1287; + raw_width = 1632; + maximum = 0x3f4; + colors = 4; + filters = 0x1e1e1e1e; + simple_coeff(3); + pre_mul[0] = 1.2085; + pre_mul[1] = 1.0943; + pre_mul[3] = 1.1103; + goto e900; + } else if (fsize == 2465792) { + height = 1203; + width = 1616; + raw_width = 2048; + colors = 4; + filters = 0x4b4b4b4b; + adobe_coeff ("NIKON","E950"); +e900: + tiff_bps = 10; + load_raw = &CLASS packed_load_raw; + load_flags = 6; + } else if (fsize == 4771840) { + height = 1540; + width = 2064; + colors = 4; + filters = 0xe1e1e1e1; + load_raw = &CLASS packed_load_raw; + load_flags = 6; + if (!timestamp && nikon_e995()) + strcpy (model, "E995"); + if (strcmp(model,"E995")) { + filters = 0xb4b4b4b4; + simple_coeff(3); + pre_mul[0] = 1.196; + pre_mul[1] = 1.246; + pre_mul[2] = 1.018; + } + } else if (!strcmp(model,"E2100")) { + if (!timestamp && !nikon_e2100()) goto cp_e2500; + height = 1206; + width = 1616; + load_flags = 30; + } else if (!strcmp(model,"E2500")) { +cp_e2500: + strcpy (model, "E2500"); + height = 1204; + width = 1616; + colors = 4; + filters = 0x4b4b4b4b; + } else if (fsize == 4775936) { + height = 1542; + width = 2064; + load_raw = &CLASS packed_load_raw; + load_flags = 30; + if (!timestamp) nikon_3700(); + if (model[0] == 'E' && atoi(model+1) < 3700) + filters = 0x49494949; + if (!strcmp(model,"Optio 33WR")) { + flip = 1; + filters = 0x16161616; + } + if (make[0] == 'O') { + i = find_green (12, 32, 1188864, 3576832); + c = find_green (12, 32, 2383920, 2387016); + if (abs(i) < abs(c)) { + SWAP(i,c); + load_flags = 24; + } + if (i < 0) filters = 0x61616161; + } + } else if (fsize == 5869568) { + height = 1710; + width = 2288; + filters = 0x16161616; + if (!timestamp && minolta_z2()) { + strcpy (make, "Minolta"); + strcpy (model,"DiMAGE Z2"); + } + load_raw = &CLASS packed_load_raw; + load_flags = 6 + 24*(make[0] == 'M'); + } else if (!strcmp(model,"E4500")) { + height = 1708; + width = 2288; + colors = 4; + filters = 0xb4b4b4b4; + } else if (fsize == 7438336) { + height = 1924; + width = 2576; + colors = 4; + filters = 0xb4b4b4b4; + } else if (fsize == 8998912) { + height = 2118; + width = 2832; + maximum = 0xf83; + load_raw = &CLASS packed_load_raw; + load_flags = 30; + } else if (!strcmp(make,"FUJIFILM")) { + if (!strcmp(model+7,"S2Pro")) { + strcpy (model,"S2Pro"); + height = 2144; + width = 2880; + flip = 6; + } else if (load_raw != &CLASS packed_load_raw) + maximum = (is_raw == 2 && shot_select) ? 0x2f00 : 0x3e00; + top_margin = (raw_height - height) >> 2 << 1; + left_margin = (raw_width - width ) >> 2 << 1; + if (width == 3328) { + width = 3262; + left_margin = 34; + } + if (!strcmp(model,"X10") || !strcmp(model,"X-S1")) + filters = 0x16161616; + if (!strcmp(model,"X-Pro1")) { + left_margin = 0; + filters = 2; + } + if (fuji_layout) raw_width *= is_raw; + } else if (!strcmp(model,"RD175")) { + height = 986; + width = 1534; + data_offset = 513; + filters = 0x61616161; + load_raw = &CLASS minolta_rd175_load_raw; + } else if (!strcmp(model,"KD-400Z")) { + height = 1712; + width = 2312; + raw_width = 2336; + goto konica_400z; + } else if (!strcmp(model,"KD-510Z")) { + goto konica_510z; + } else if (!strcasecmp(make,"MINOLTA")) { + load_raw = &CLASS unpacked_load_raw; + maximum = 0xfff; + if (!strncmp(model,"DiMAGE A",8)) { + if (!strcmp(model,"DiMAGE A200")) + filters = 0x49494949; + tiff_bps = 12; + load_raw = &CLASS packed_load_raw; + } else if (!strncmp(model,"ALPHA",5) || + !strncmp(model,"DYNAX",5) || + !strncmp(model,"MAXXUM",6)) { + sprintf (model+20, "DYNAX %-10s", model+6+(model[0]=='M')); + adobe_coeff (make, model+20); + load_raw = &CLASS packed_load_raw; + } else if (!strncmp(model,"DiMAGE G",8)) { + if (model[8] == '4') { + height = 1716; + width = 2304; + } else if (model[8] == '5') { +konica_510z: + height = 1956; + width = 2607; + raw_width = 2624; + } else if (model[8] == '6') { + height = 2136; + width = 2848; + } + data_offset += 14; + filters = 0x61616161; +konica_400z: + load_raw = &CLASS unpacked_load_raw; + maximum = 0x3df; + order = 0x4d4d; + } + } else if (!strcmp(model,"*ist D")) { + load_raw = &CLASS unpacked_load_raw; + data_error = -1; + } else if (!strcmp(model,"*ist DS")) { + height -= 2; + } else if (!strcmp(model,"Optio S")) { + if (fsize == 3178560) { + height = 1540; + width = 2064; + load_raw = &CLASS eight_bit_load_raw; + cam_mul[0] *= 4; + cam_mul[2] *= 4; + } else { + height = 1544; + width = 2068; + raw_width = 3136; + load_raw = &CLASS packed_load_raw; + maximum = 0xf7c; + } + } else if (fsize == 6114240) { + height = 1737; + width = 2324; + raw_width = 3520; + load_raw = &CLASS packed_load_raw; + maximum = 0xf7a; + } else if (!strcmp(model,"Optio 750Z")) { + height = 2302; + width = 3072; + load_raw = &CLASS packed_load_raw; + load_flags = 30; + } else if (!strcmp(model,"DC-833m")) { + height = 2448; + width = 3264; + order = 0x4949; + filters = 0x61616161; + load_raw = &CLASS unpacked_load_raw; + maximum = 0xfc00; + } else if (!strncmp(model,"S85",3)) { + height = 2448; + width = 3264; + raw_width = fsize/height/2; + order = 0x4d4d; + load_raw = &CLASS unpacked_load_raw; + } else if (!strncmp(model,"NX1",3)) { + height -= top_margin = 8; + width -= 2 * (left_margin = 8); + load_flags = 32; + } else if (!strcmp(model,"NX200")) { + order = 0x4949; + height = 3694; + top_margin = 2; + width = 5574 - (left_margin = 32 + tiff_bps); + if (tiff_bps == 12) load_flags = 80; + } else if (!strcmp(model,"EX1")) { + order = 0x4949; + height -= 20; + top_margin = 2; + if ((width -= 6) > 3682) { + height -= 10; + width -= 46; + top_margin = 8; + } + } else if (!strcmp(model,"WB2000")) { + order = 0x4949; + height -= 3; + top_margin = 2; + if ((width -= 10) > 3718) { + height -= 28; + width -= 56; + top_margin = 8; + } + } else if (fsize == 20487168) { + height = 2808; + width = 3648; + goto wb550; + } else if (fsize == 24000000) { + height = 3000; + width = 4000; +wb550: + strcpy (model, "WB550"); + order = 0x4d4d; + load_raw = &CLASS unpacked_load_raw; + load_flags = 6; + maximum = 0x3df; + } else if (!strcmp(model,"STV680 VGA")) { + height = 484; + width = 644; + load_raw = &CLASS eight_bit_load_raw; + flip = 2; + filters = 0x16161616; + black = 16; + } else if (!strcmp(model,"N95")) { + height = raw_height - (top_margin = 2); + } else if (!strcmp(model,"531C")) { + height = 1200; + width = 1600; + load_raw = &CLASS unpacked_load_raw; + filters = 0x49494949; + } else if (!strcmp(model,"640x480")) { + height = 480; + width = 640; + load_raw = &CLASS eight_bit_load_raw; + gamma_curve (0.45, 4.5, 1, 255); + } else if (!strcmp(model,"F-080C")) { + height = 768; + width = 1024; + load_raw = &CLASS eight_bit_load_raw; + } else if (!strcmp(model,"F-145C")) { + height = 1040; + width = 1392; + load_raw = &CLASS eight_bit_load_raw; + } else if (!strcmp(model,"F-201C")) { + height = 1200; + width = 1600; + load_raw = &CLASS eight_bit_load_raw; + } else if (!strcmp(model,"F-510C")) { + height = 1958; + width = 2588; + load_raw = fsize < 7500000 ? + &CLASS eight_bit_load_raw : &CLASS unpacked_load_raw; + data_offset = fsize - width*height*(fsize >> 22); + maximum = 0xfff0; + } else if (!strcmp(model,"F-810C")) { + height = 2469; + width = 3272; + load_raw = &CLASS unpacked_load_raw; + maximum = 0xfff0; + } else if (!strcmp(model,"XCD-SX910CR")) { + height = 1024; + width = 1375; + raw_width = 1376; + filters = 0x49494949; + maximum = 0x3ff; + load_raw = fsize < 2000000 ? + &CLASS eight_bit_load_raw : &CLASS unpacked_load_raw; + } else if (!strcmp(model,"2010")) { + height = 1207; + width = 1608; + order = 0x4949; + filters = 0x16161616; + data_offset = 3212; + maximum = 0x3ff; + load_raw = &CLASS unpacked_load_raw; + } else if (!strcmp(model,"A782")) { + height = 3000; + width = 2208; + filters = 0x61616161; + load_raw = fsize < 10000000 ? + &CLASS eight_bit_load_raw : &CLASS unpacked_load_raw; + maximum = 0xffc0; + } else if (!strcmp(model,"3320AF")) { + height = 1536; + raw_width = width = 2048; + filters = 0x61616161; + load_raw = &CLASS unpacked_load_raw; + maximum = 0x3ff; + fseek (ifp, 0x300000, SEEK_SET); + if ((order = guess_byte_order(0x10000)) == 0x4d4d) { + height -= (top_margin = 16); + width -= (left_margin = 28); + maximum = 0xf5c0; + strcpy (make, "ISG"); + model[0] = 0; + } + } else if (!strcmp(make,"Hasselblad")) { + if (load_raw == &CLASS lossless_jpeg_load_raw) + load_raw = &CLASS hasselblad_load_raw; + if (raw_width == 7262) { + height = 5444; + width = 7248; + top_margin = 4; + left_margin = 7; + filters = 0x61616161; + } else if (raw_width == 7410) { + height = 5502; + width = 7328; + top_margin = 4; + left_margin = 41; + filters = 0x61616161; + } else if (raw_width == 9044) { + height = 6716; + width = 8964; + top_margin = 8; + left_margin = 40; + black += load_flags = 256; + maximum = 0x8101; + } else if (raw_width == 4090) { + strcpy (model, "V96C"); + height -= (top_margin = 6); + width -= (left_margin = 3) + 7; + filters = 0x61616161; + } + } else if (!strcmp(make,"Sinar")) { + if (!memcmp(head,"8BPS",4)) { + fseek (ifp, 14, SEEK_SET); + height = get4(); + width = get4(); + filters = 0x61616161; + data_offset = 68; + } + if (!load_raw) load_raw = &CLASS unpacked_load_raw; + maximum = 0x3fff; + } else if (!strcmp(make,"Leaf")) { + maximum = 0x3fff; + fseek (ifp, data_offset, SEEK_SET); + if (ljpeg_start (&jh, 1) && jh.bits == 15) + maximum = 0x1fff; + if (tiff_samples > 1) filters = 0; + if (tiff_samples > 1 || tile_length < raw_height) { + load_raw = &CLASS leaf_hdr_load_raw; + raw_width = tile_width; + } + if ((width | height) == 2048) { + if (tiff_samples == 1) { + filters = 1; + strcpy (cdesc, "RBTG"); + strcpy (model, "CatchLight"); + top_margin = 8; left_margin = 18; height = 2032; width = 2016; + } else { + strcpy (model, "DCB2"); + top_margin = 10; left_margin = 16; height = 2028; width = 2022; + } + } else if (width+height == 3144+2060) { + if (!model[0]) strcpy (model, "Cantare"); + if (width > height) { + top_margin = 6; left_margin = 32; height = 2048; width = 3072; + filters = 0x61616161; + } else { + left_margin = 6; top_margin = 32; width = 2048; height = 3072; + filters = 0x16161616; + } + if (!cam_mul[0] || model[0] == 'V') filters = 0; + else is_raw = tiff_samples; + } else if (width == 2116) { + strcpy (model, "Valeo 6"); + height -= 2 * (top_margin = 30); + width -= 2 * (left_margin = 55); + filters = 0x49494949; + } else if (width == 3171) { + strcpy (model, "Valeo 6"); + height -= 2 * (top_margin = 24); + width -= 2 * (left_margin = 24); + filters = 0x16161616; + } + } else if (!strcmp(make,"LEICA") || !strcmp(make,"Panasonic")) { + if ((flen - data_offset) / (raw_width*8/7) == raw_height) + load_raw = &CLASS panasonic_load_raw; + if (!load_raw) { + load_raw = &CLASS unpacked_load_raw; + load_flags = 4; + } + zero_is_bad = 1; + if ((height += 12) > raw_height) height = raw_height; + for (i=0; i < sizeof pana / sizeof *pana; i++) + if (raw_width == pana[i][0] && raw_height == pana[i][1]) { + left_margin = pana[i][2]; + top_margin = pana[i][3]; + width += pana[i][4]; + height += pana[i][5]; + } + filters = 0x01010101 * (uchar) "\x94\x61\x49\x16" + [((filters-1) ^ (left_margin & 1) ^ (top_margin << 1)) & 3]; + } else if (!strcmp(model,"C770UZ")) { + height = 1718; + width = 2304; + filters = 0x16161616; + load_raw = &CLASS packed_load_raw; + load_flags = 30; + } else if (!strcmp(make,"OLYMPUS")) { + height += height & 1; + filters = exif_cfa; + if (width == 4100) width -= 4; + if (width == 4080) width -= 24; + if (load_raw == &CLASS unpacked_load_raw) + load_flags = 4; + tiff_bps = 12; + if (!strcmp(model,"E-300") || + !strcmp(model,"E-500")) { + width -= 20; + if (load_raw == &CLASS unpacked_load_raw) { + maximum = 0xfc3; + memset (cblack, 0, sizeof cblack); + } + } else if (!strcmp(model,"E-330")) { + width -= 30; + if (load_raw == &CLASS unpacked_load_raw) + maximum = 0xf79; + } else if (!strcmp(model,"SP550UZ")) { + thumb_length = flen - (thumb_offset = 0xa39800); + thumb_height = 480; + thumb_width = 640; + } + } else if (!strcmp(model,"N Digital")) { + height = 2047; + width = 3072; + filters = 0x61616161; + data_offset = 0x1a00; + load_raw = &CLASS packed_load_raw; + } else if (!strcmp(model,"DSC-F828")) { + width = 3288; + left_margin = 5; + data_offset = 862144; + load_raw = &CLASS sony_load_raw; + filters = 0x9c9c9c9c; + colors = 4; + strcpy (cdesc, "RGBE"); + } else if (!strcmp(model,"DSC-V3")) { + width = 3109; + left_margin = 59; + data_offset = 787392; + load_raw = &CLASS sony_load_raw; + } else if (!strcmp(make,"SONY") && raw_width == 3984) { + adobe_coeff ("SONY","DSC-R1"); + width = 3925; + order = 0x4d4d; + } else if (!strcmp(make,"SONY") && raw_width == 6048) { + width -= 24; + } else if (!strcmp(model,"DSLR-A100")) { + if (width == 3880) { + height--; + width = ++raw_width; + } else { + order = 0x4d4d; + load_flags = 2; + } + filters = 0x61616161; + } else if (!strcmp(model,"DSLR-A350")) { + height -= 4; + } else if (!strcmp(model,"PIXL")) { + height -= top_margin = 4; + width -= left_margin = 32; + gamma_curve (0, 7, 1, 255); + } else if (!strcmp(model,"C603v")) { + height = 480; + width = 640; + if (fsize < 614400 || find_green (16, 16, 3840, 5120) < 25) goto c603v; + strcpy (model,"KAI-0340"); + height -= 3; + data_offset = 3840; + order = 0x4949; + load_raw = &CLASS unpacked_load_raw; + } else if (!strcmp(model,"C603y")) { + height = 2134; + width = 2848; +c603v: + filters = 0; + load_raw = &CLASS kodak_yrgb_load_raw; + gamma_curve (0, 3.875, 1, 255); + } else if (!strcmp(model,"C603")) { + raw_height = height = 2152; + raw_width = width = 2864; + goto c603; + } else if (!strcmp(model,"C330")) { + height = 1744; + width = 2336; + raw_height = 1779; + raw_width = 2338; + top_margin = 33; + left_margin = 1; +c603: + order = 0x4949; + if ((data_offset = fsize - raw_height*raw_width)) { + fseek (ifp, 168, SEEK_SET); + read_shorts (curve, 256); + } else gamma_curve (0, 3.875, 1, 255); + load_raw = &CLASS eight_bit_load_raw; + } else if (!strncasecmp(model,"EasyShare",9)) { + data_offset = data_offset < 0x15000 ? 0x15000 : 0x17000; + load_raw = &CLASS packed_load_raw; + } else if (!strcasecmp(make,"KODAK")) { + if (filters == UINT_MAX) filters = 0x61616161; + if (!strncmp(model,"NC2000",6)) { + width -= 4; + left_margin = 2; + } else if (!strcmp(model,"EOSDCS3B")) { + width -= 4; + left_margin = 2; + } else if (!strcmp(model,"EOSDCS1")) { + width -= 4; + left_margin = 2; + } else if (!strcmp(model,"DCS420")) { + width -= 4; + left_margin = 2; + } else if (!strncmp(model,"DCS460 ",7)) { + model[6] = 0; + width -= 4; + left_margin = 2; + } else if (!strcmp(model,"DCS460A")) { + width -= 4; + left_margin = 2; + colors = 1; + filters = 0; + } else if (!strcmp(model,"DCS660M")) { + black = 214; + colors = 1; + filters = 0; + } else if (!strcmp(model,"DCS760M")) { + colors = 1; + filters = 0; + } + if (!strcmp(model+4,"20X")) + strcpy (cdesc, "MYCY"); + if (strstr(model,"DC25")) { + strcpy (model, "DC25"); + data_offset = 15424; + } + if (!strncmp(model,"DC2",3)) { + raw_height = height = 242; + if (flen < 100000) { + raw_width = 256; width = 249; + pixel_aspect = (4.0*height) / (3.0*width); + } else { + raw_width = 512; width = 501; + pixel_aspect = (493.0*height) / (373.0*width); + } + data_offset += raw_width + 1; + colors = 4; + filters = 0x8d8d8d8d; + simple_coeff(1); + pre_mul[1] = 1.179; + pre_mul[2] = 1.209; + pre_mul[3] = 1.036; + load_raw = &CLASS eight_bit_load_raw; + } else if (!strcmp(model,"40")) { + strcpy (model, "DC40"); + height = 512; + width = 768; + data_offset = 1152; + load_raw = &CLASS kodak_radc_load_raw; + } else if (strstr(model,"DC50")) { + strcpy (model, "DC50"); + height = 512; + width = 768; + data_offset = 19712; + load_raw = &CLASS kodak_radc_load_raw; + } else if (strstr(model,"DC120")) { + strcpy (model, "DC120"); + height = 976; + width = 848; + pixel_aspect = height/0.75/width; + load_raw = tiff_compress == 7 ? + &CLASS kodak_jpeg_load_raw : &CLASS kodak_dc120_load_raw; + } else if (!strcmp(model,"DCS200")) { + thumb_height = 128; + thumb_width = 192; + thumb_offset = 6144; + thumb_misc = 360; + write_thumb = &CLASS layer_thumb; + height = 1024; + width = 1536; + data_offset = 79872; + load_raw = &CLASS eight_bit_load_raw; + black = 17; + } + } else if (!strcmp(model,"Fotoman Pixtura")) { + height = 512; + width = 768; + data_offset = 3632; + load_raw = &CLASS kodak_radc_load_raw; + filters = 0x61616161; + simple_coeff(2); + } else if (!strncmp(model,"QuickTake",9)) { + if (head[5]) strcpy (model+10, "200"); + fseek (ifp, 544, SEEK_SET); + height = get2(); + width = get2(); + data_offset = (get4(),get2()) == 30 ? 738:736; + if (height > width) { + SWAP(height,width); + fseek (ifp, data_offset-6, SEEK_SET); + flip = ~get2() & 3 ? 5:6; + } + filters = 0x61616161; + } else if (!strcmp(make,"Rollei") && !load_raw) { + switch (raw_width) { + case 1316: + height = 1030; + width = 1300; + top_margin = 1; + left_margin = 6; + break; + case 2568: + height = 1960; + width = 2560; + top_margin = 2; + left_margin = 8; + } + filters = 0x16161616; + load_raw = &CLASS rollei_load_raw; + } else if (!strcmp(model,"PC-CAM 600")) { + height = 768; + data_offset = width = 1024; + filters = 0x49494949; + load_raw = &CLASS eight_bit_load_raw; + } else if (!strcmp(model,"QV-2000UX")) { + height = 1208; + width = 1632; + data_offset = width * 2; + load_raw = &CLASS eight_bit_load_raw; + } else if (fsize == 3217760) { + height = 1546; + width = 2070; + raw_width = 2080; + load_raw = &CLASS eight_bit_load_raw; + } else if (!strcmp(model,"QV-4000")) { + height = 1700; + width = 2260; + load_raw = &CLASS unpacked_load_raw; + maximum = 0xffff; + } else if (!strcmp(model,"QV-5700")) { + height = 1924; + width = 2576; + raw_width = 3232; + tiff_bps = 10; + } else if (!strcmp(model,"QV-R41")) { + height = 1720; + width = 2312; + raw_width = 3520; + left_margin = 2; + } else if (!strcmp(model,"QV-R51")) { + height = 1926; + width = 2580; + raw_width = 3904; + } else if (!strcmp(model,"EX-S20")) { + height = 1208; + width = 1620; + raw_width = 2432; + flip = 3; + } else if (!strcmp(model,"EX-S100")) { + height = 1544; + width = 2058; + raw_width = 3136; + } else if (!strcmp(model,"EX-Z50")) { + height = 1931; + width = 2570; + raw_width = 3904; + } else if (!strcmp(model,"EX-Z500")) { + height = 1937; + width = 2577; + raw_width = 3904; + filters = 0x16161616; + } else if (!strcmp(model,"EX-Z55")) { + height = 1960; + width = 2570; + raw_width = 3904; + } else if (!strcmp(model,"EX-Z60")) { + height = 2145; + width = 2833; + raw_width = 3584; + filters = 0x16161616; + tiff_bps = 10; + } else if (!strcmp(model,"EX-Z75")) { + height = 2321; + width = 3089; + raw_width = 4672; + maximum = 0xfff; + } else if (!strcmp(model,"EX-Z750")) { + height = 2319; + width = 3087; + raw_width = 4672; + maximum = 0xfff; + } else if (!strcmp(model,"EX-Z850")) { + height = 2468; + width = 3279; + raw_width = 4928; + maximum = 0xfff; + } else if (!strcmp(model,"EX-Z8")) { + height = 2467; + width = 3281; + raw_height = 2502; + raw_width = 4992; + maximum = 0xfff; + } else if (fsize == 15499264) { /* EX-Z1050 or EX-Z1080 */ + height = 2752; + width = 3672; + raw_width = 5632; + } else if (!strcmp(model,"EX-P505")) { + height = 1928; + width = 2568; + raw_width = 3852; + maximum = 0xfff; + } else if (fsize == 9313536) { /* EX-P600 or QV-R61 */ + height = 2142; + width = 2844; + raw_width = 4288; + } else if (!strcmp(model,"EX-P700")) { + height = 2318; + width = 3082; + raw_width = 4672; + } + if (!model[0]) + sprintf (model, "%dx%d", width, height); + if (filters == UINT_MAX) filters = 0x94949494; + if (raw_color) adobe_coeff (make, model); + if (load_raw == &CLASS kodak_radc_load_raw) + if (raw_color) adobe_coeff ("Apple","Quicktake"); + if (thumb_offset && !thumb_height) { + fseek (ifp, thumb_offset, SEEK_SET); + if (ljpeg_start (&jh, 1)) { + thumb_width = jh.wide; + thumb_height = jh.high; + } + } +dng_skip: + if (fuji_width) { + fuji_width = width >> !fuji_layout; + if (~fuji_width & 1) filters = 0x49494949; + width = (height >> fuji_layout) + fuji_width; + height = width - 1; + pixel_aspect = 1; + } else { + if (raw_height < height) raw_height = height; + if (raw_width < width ) raw_width = width; + } + if (!tiff_bps) tiff_bps = 12; + if (!maximum) maximum = (1 << tiff_bps) - 1; + if (!load_raw || height < 22) is_raw = 0; +#ifdef NO_JASPER + if (load_raw == &CLASS redcine_load_raw) { + fprintf (stderr,_("%s: You must link dcraw with %s!!\n"), + ifname, "libjasper"); + is_raw = 0; + } +#endif +#ifdef NO_JPEG + if (load_raw == &CLASS kodak_jpeg_load_raw || + load_raw == &CLASS lossy_dng_load_raw) { + fprintf (stderr,_("%s: You must link dcraw with %s!!\n"), + ifname, "libjpeg"); + is_raw = 0; + } +#endif + if (!cdesc[0]) + strcpy (cdesc, colors == 3 ? "RGBG":"GMCY"); + if (!raw_height) raw_height = height; + if (!raw_width ) raw_width = width; + if (filters && colors == 3) + filters |= ((filters >> 2 & 0x22222222) | + (filters << 2 & 0x88888888)) & filters << 1; +notraw: + if (flip == -1) flip = tiff_flip; + if (flip == -1) flip = 0; +} + +#ifndef NO_LCMS +void CLASS apply_profile (const char *input, const char *output) +{ + char *prof; + cmsHPROFILE hInProfile=0, hOutProfile=0; + cmsHTRANSFORM hTransform; + FILE *fp; + unsigned size; + + cmsErrorAction (LCMS_ERROR_SHOW); + if (strcmp (input, "embed")) + hInProfile = cmsOpenProfileFromFile (input, "r"); + else if (profile_length) { + prof = (char *) malloc (profile_length); + merror (prof, "apply_profile()"); + fseek (ifp, profile_offset, SEEK_SET); + fread (prof, 1, profile_length, ifp); + hInProfile = cmsOpenProfileFromMem (prof, profile_length); + free (prof); + } else + fprintf (stderr,_("%s has no embedded profile.\n"), ifname); + if (!hInProfile) return; + if (!output) + hOutProfile = cmsCreate_sRGBProfile(); + else if ((fp = fopen (output, "rb"))) { + fread (&size, 4, 1, fp); + fseek (fp, 0, SEEK_SET); + oprof = (unsigned *) malloc (size = ntohl(size)); + merror (oprof, "apply_profile()"); + fread (oprof, 1, size, fp); + fclose (fp); + if (!(hOutProfile = cmsOpenProfileFromMem (oprof, size))) { + free (oprof); + oprof = 0; + } + } else + fprintf (stderr,_("Cannot open file %s!\n"), output); + if (!hOutProfile) goto quit; + if (verbose) + fprintf (stderr,_("Applying color profile...\n")); + hTransform = cmsCreateTransform (hInProfile, TYPE_RGBA_16, + hOutProfile, TYPE_RGBA_16, INTENT_PERCEPTUAL, 0); + cmsDoTransform (hTransform, image, image, width*height); + raw_color = 1; /* Don't use rgb_cam with a profile */ + cmsDeleteTransform (hTransform); + cmsCloseProfile (hOutProfile); +quit: + cmsCloseProfile (hInProfile); +} +#endif + +void CLASS convert_to_rgb() +{ + int row, col, c, i, j, k; + ushort *img; + float out[3], out_cam[3][4]; + double num, inverse[3][3]; + static const double xyzd50_srgb[3][3] = + { { 0.436083, 0.385083, 0.143055 }, + { 0.222507, 0.716888, 0.060608 }, + { 0.013930, 0.097097, 0.714022 } }; + static const double rgb_rgb[3][3] = + { { 1,0,0 }, { 0,1,0 }, { 0,0,1 } }; + static const double adobe_rgb[3][3] = + { { 0.715146, 0.284856, 0.000000 }, + { 0.000000, 1.000000, 0.000000 }, + { 0.000000, 0.041166, 0.958839 } }; + static const double wide_rgb[3][3] = + { { 0.593087, 0.404710, 0.002206 }, + { 0.095413, 0.843149, 0.061439 }, + { 0.011621, 0.069091, 0.919288 } }; + static const double prophoto_rgb[3][3] = + { { 0.529317, 0.330092, 0.140588 }, + { 0.098368, 0.873465, 0.028169 }, + { 0.016879, 0.117663, 0.865457 } }; + static const double (*out_rgb[])[3] = + { rgb_rgb, adobe_rgb, wide_rgb, prophoto_rgb, xyz_rgb }; + static const char *name[] = + { "sRGB", "Adobe RGB (1998)", "WideGamut D65", "ProPhoto D65", "XYZ" }; + static const unsigned phead[] = + { 1024, 0, 0x2100000, 0x6d6e7472, 0x52474220, 0x58595a20, 0, 0, 0, + 0x61637370, 0, 0, 0x6e6f6e65, 0, 0, 0, 0, 0xf6d6, 0x10000, 0xd32d }; + unsigned pbody[] = + { 10, 0x63707274, 0, 36, /* cprt */ + 0x64657363, 0, 40, /* desc */ + 0x77747074, 0, 20, /* wtpt */ + 0x626b7074, 0, 20, /* bkpt */ + 0x72545243, 0, 14, /* rTRC */ + 0x67545243, 0, 14, /* gTRC */ + 0x62545243, 0, 14, /* bTRC */ + 0x7258595a, 0, 20, /* rXYZ */ + 0x6758595a, 0, 20, /* gXYZ */ + 0x6258595a, 0, 20 }; /* bXYZ */ + static const unsigned pwhite[] = { 0xf351, 0x10000, 0x116cc }; + unsigned pcurve[] = { 0x63757276, 0, 1, 0x1000000 }; + + gamma_curve (gamm[0], gamm[1], 0, 0); + memcpy (out_cam, rgb_cam, sizeof out_cam); + raw_color |= colors == 1 || document_mode || + output_color < 1 || output_color > 5; + if (!raw_color) { + oprof = (unsigned *) calloc (phead[0], 1); + merror (oprof, "convert_to_rgb()"); + memcpy (oprof, phead, sizeof phead); + if (output_color == 5) oprof[4] = oprof[5]; + oprof[0] = 132 + 12*pbody[0]; + for (i=0; i < pbody[0]; i++) { + oprof[oprof[0]/4] = i ? (i > 1 ? 0x58595a20 : 0x64657363) : 0x74657874; + pbody[i*3+2] = oprof[0]; + oprof[0] += (pbody[i*3+3] + 3) & -4; + } + memcpy (oprof+32, pbody, sizeof pbody); + oprof[pbody[5]/4+2] = strlen(name[output_color-1]) + 1; + memcpy ((char *)oprof+pbody[8]+8, pwhite, sizeof pwhite); + pcurve[3] = (short)(256/gamm[5]+0.5) << 16; + for (i=4; i < 7; i++) + memcpy ((char *)oprof+pbody[i*3+2], pcurve, sizeof pcurve); + pseudoinverse ((double (*)[3]) out_rgb[output_color-1], inverse, 3); + for (i=0; i < 3; i++) + for (j=0; j < 3; j++) { + for (num = k=0; k < 3; k++) + num += xyzd50_srgb[i][k] * inverse[j][k]; + oprof[pbody[j*3+23]/4+i+2] = num * 0x10000 + 0.5; + } + for (i=0; i < phead[0]/4; i++) + oprof[i] = htonl(oprof[i]); + strcpy ((char *)oprof+pbody[2]+8, "auto-generated by dcraw"); + strcpy ((char *)oprof+pbody[5]+12, name[output_color-1]); + for (i=0; i < 3; i++) + for (j=0; j < colors; j++) + for (out_cam[i][j] = k=0; k < 3; k++) + out_cam[i][j] += out_rgb[output_color-1][i][k] * rgb_cam[k][j]; + } + if (verbose) + fprintf (stderr, raw_color ? _("Building histograms...\n") : + _("Converting to %s colorspace...\n"), name[output_color-1]); + + memset (histogram, 0, sizeof histogram); + for (img=image[0], row=0; row < height; row++) + for (col=0; col < width; col++, img+=4) { + if (!raw_color) { + out[0] = out[1] = out[2] = 0; + FORCC { + out[0] += out_cam[0][c] * img[c]; + out[1] += out_cam[1][c] * img[c]; + out[2] += out_cam[2][c] * img[c]; + } + FORC3 img[c] = CLIP((int) out[c]); + } + else if (document_mode) + img[0] = img[fcol(row,col)]; + FORCC histogram[c][img[c] >> 3]++; + } + if (colors == 4 && output_color) colors = 3; + if (document_mode && filters) colors = 1; +} + +void CLASS fuji_rotate() +{ + int i, row, col; + double step; + float r, c, fr, fc; + unsigned ur, uc; + ushort wide, high, (*img)[4], (*pix)[4]; + + if (!fuji_width) return; + if (verbose) + fprintf (stderr,_("Rotating image 45 degrees...\n")); + fuji_width = (fuji_width - 1 + shrink) >> shrink; + step = sqrt(0.5); + wide = fuji_width / step; + high = (height - fuji_width) / step; + img = (ushort (*)[4]) calloc (wide*high, sizeof *img); + merror (img, "fuji_rotate()"); + + for (row=0; row < high; row++) + for (col=0; col < wide; col++) { + ur = r = fuji_width + (row-col)*step; + uc = c = (row+col)*step; + if (ur > height-2 || uc > width-2) continue; + fr = r - ur; + fc = c - uc; + pix = image + ur*width + uc; + for (i=0; i < colors; i++) + img[row*wide+col][i] = + (pix[ 0][i]*(1-fc) + pix[ 1][i]*fc) * (1-fr) + + (pix[width][i]*(1-fc) + pix[width+1][i]*fc) * fr; + } + free (image); + width = wide; + height = high; + image = img; + fuji_width = 0; +} + +void CLASS stretch() +{ + ushort newdim, (*img)[4], *pix0, *pix1; + int row, col, c; + double rc, frac; + + if (pixel_aspect == 1) return; + if (verbose) fprintf (stderr,_("Stretching the image...\n")); + if (pixel_aspect < 1) { + newdim = height / pixel_aspect + 0.5; + img = (ushort (*)[4]) calloc (width*newdim, sizeof *img); + merror (img, "stretch()"); + for (rc=row=0; row < newdim; row++, rc+=pixel_aspect) { + frac = rc - (c = rc); + pix0 = pix1 = image[c*width]; + if (c+1 < height) pix1 += width*4; + for (col=0; col < width; col++, pix0+=4, pix1+=4) + FORCC img[row*width+col][c] = pix0[c]*(1-frac) + pix1[c]*frac + 0.5; + } + height = newdim; + } else { + newdim = width * pixel_aspect + 0.5; + img = (ushort (*)[4]) calloc (height*newdim, sizeof *img); + merror (img, "stretch()"); + for (rc=col=0; col < newdim; col++, rc+=1/pixel_aspect) { + frac = rc - (c = rc); + pix0 = pix1 = image[c]; + if (c+1 < width) pix1 += 4; + for (row=0; row < height; row++, pix0+=width*4, pix1+=width*4) + FORCC img[row*newdim+col][c] = pix0[c]*(1-frac) + pix1[c]*frac + 0.5; + } + width = newdim; + } + free (image); + image = img; +} + +int CLASS flip_index (int row, int col) +{ + if (flip & 4) SWAP(row,col); + if (flip & 2) row = iheight - 1 - row; + if (flip & 1) col = iwidth - 1 - col; + return row * iwidth + col; +} + +struct tiff_tag { + ushort tag, type; + int count; + union { char c[4]; short s[2]; int i; } val; +}; + +struct tiff_hdr { + ushort order, magic; + int ifd; + ushort pad, ntag; + struct tiff_tag tag[23]; + int nextifd; + ushort pad2, nexif; + struct tiff_tag exif[4]; + ushort pad3, ngps; + struct tiff_tag gpst[10]; + short bps[4]; + int rat[10]; + unsigned gps[26]; + char desc[512], make[64], model[64], soft[32], date[20], artist[64]; +}; + +void CLASS tiff_set (ushort *ntag, + ushort tag, ushort type, int count, int val) +{ + struct tiff_tag *tt; + int c; + + tt = (struct tiff_tag *)(ntag+1) + (*ntag)++; + tt->tag = tag; + tt->type = type; + tt->count = count; + if (type < 3 && count <= 4) + FORC(4) tt->val.c[c] = val >> (c << 3); + else if (type == 3 && count <= 2) + FORC(2) tt->val.s[c] = val >> (c << 4); + else tt->val.i = val; +} + +#define TOFF(ptr) ((char *)(&(ptr)) - (char *)th) + +void CLASS tiff_head (struct tiff_hdr *th, int full) +{ + int c, psize=0; + struct tm *t; + + memset (th, 0, sizeof *th); + th->order = htonl(0x4d4d4949) >> 16; + th->magic = 42; + th->ifd = 10; + if (full) { + tiff_set (&th->ntag, 254, 4, 1, 0); + tiff_set (&th->ntag, 256, 4, 1, width); + tiff_set (&th->ntag, 257, 4, 1, height); + tiff_set (&th->ntag, 258, 3, colors, output_bps); + if (colors > 2) + th->tag[th->ntag-1].val.i = TOFF(th->bps); + FORC4 th->bps[c] = output_bps; + tiff_set (&th->ntag, 259, 3, 1, 1); + tiff_set (&th->ntag, 262, 3, 1, 1 + (colors > 1)); + } + tiff_set (&th->ntag, 270, 2, 512, TOFF(th->desc)); + tiff_set (&th->ntag, 271, 2, 64, TOFF(th->make)); + tiff_set (&th->ntag, 272, 2, 64, TOFF(th->model)); + if (full) { + if (oprof) psize = ntohl(oprof[0]); + tiff_set (&th->ntag, 273, 4, 1, sizeof *th + psize); + tiff_set (&th->ntag, 277, 3, 1, colors); + tiff_set (&th->ntag, 278, 4, 1, height); + tiff_set (&th->ntag, 279, 4, 1, height*width*colors*output_bps/8); + } else + tiff_set (&th->ntag, 274, 3, 1, "12435867"[flip]-'0'); + tiff_set (&th->ntag, 282, 5, 1, TOFF(th->rat[0])); + tiff_set (&th->ntag, 283, 5, 1, TOFF(th->rat[2])); + tiff_set (&th->ntag, 284, 3, 1, 1); + tiff_set (&th->ntag, 296, 3, 1, 2); + tiff_set (&th->ntag, 305, 2, 32, TOFF(th->soft)); + tiff_set (&th->ntag, 306, 2, 20, TOFF(th->date)); + tiff_set (&th->ntag, 315, 2, 64, TOFF(th->artist)); + tiff_set (&th->ntag, 34665, 4, 1, TOFF(th->nexif)); + if (psize) tiff_set (&th->ntag, 34675, 7, psize, sizeof *th); + tiff_set (&th->nexif, 33434, 5, 1, TOFF(th->rat[4])); + tiff_set (&th->nexif, 33437, 5, 1, TOFF(th->rat[6])); + tiff_set (&th->nexif, 34855, 3, 1, iso_speed); + tiff_set (&th->nexif, 37386, 5, 1, TOFF(th->rat[8])); + if (gpsdata[1]) { + tiff_set (&th->ntag, 34853, 4, 1, TOFF(th->ngps)); + tiff_set (&th->ngps, 0, 1, 4, 0x202); + tiff_set (&th->ngps, 1, 2, 2, gpsdata[29]); + tiff_set (&th->ngps, 2, 5, 3, TOFF(th->gps[0])); + tiff_set (&th->ngps, 3, 2, 2, gpsdata[30]); + tiff_set (&th->ngps, 4, 5, 3, TOFF(th->gps[6])); + tiff_set (&th->ngps, 5, 1, 1, gpsdata[31]); + tiff_set (&th->ngps, 6, 5, 1, TOFF(th->gps[18])); + tiff_set (&th->ngps, 7, 5, 3, TOFF(th->gps[12])); + tiff_set (&th->ngps, 18, 2, 12, TOFF(th->gps[20])); + tiff_set (&th->ngps, 29, 2, 12, TOFF(th->gps[23])); + memcpy (th->gps, gpsdata, sizeof th->gps); + } + th->rat[0] = th->rat[2] = 300; + th->rat[1] = th->rat[3] = 1; + FORC(6) th->rat[4+c] = 1000000; + th->rat[4] *= shutter; + th->rat[6] *= aperture; + th->rat[8] *= focal_len; + strncpy (th->desc, desc, 512); + strncpy (th->make, make, 64); + strncpy (th->model, model, 64); + strcpy (th->soft, "dcraw v"DCRAW_VERSION); + t = localtime (×tamp); + sprintf (th->date, "%04d:%02d:%02d %02d:%02d:%02d", + t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); + strncpy (th->artist, artist, 64); +} + +void CLASS jpeg_thumb() +{ + char *thumb; + ushort exif[5]; + struct tiff_hdr th; + + thumb = (char *) malloc (thumb_length); + merror (thumb, "jpeg_thumb()"); + fread (thumb, 1, thumb_length, ifp); + fputc (0xff, ofp); + fputc (0xd8, ofp); + if (strcmp (thumb+6, "Exif")) { + memcpy (exif, "\xff\xe1 Exif\0\0", 10); + exif[1] = htons (8 + sizeof th); + fwrite (exif, 1, sizeof exif, ofp); + tiff_head (&th, 0); + fwrite (&th, 1, sizeof th, ofp); + } + fwrite (thumb+2, 1, thumb_length-2, ofp); + free (thumb); +} + +void CLASS write_ppm_tiff() +{ + struct tiff_hdr th; + uchar *ppm; + ushort *ppm2; + int c, row, col, soff, rstep, cstep; + int perc, val, total, white=0x2000; + + perc = width * height * 0.01; /* 99th percentile white level */ + if (fuji_width) perc /= 2; + if (!((highlight & ~2) || no_auto_bright)) + for (white=c=0; c < colors; c++) { + for (val=0x2000, total=0; --val > 32; ) + if ((total += histogram[c][val]) > perc) break; + if (white < val) white = val; + } + gamma_curve (gamm[0], gamm[1], 2, (white << 3)/bright); + iheight = height; + iwidth = width; + if (flip & 4) SWAP(height,width); + ppm = (uchar *) calloc (width, colors*output_bps/8); + ppm2 = (ushort *) ppm; + merror (ppm, "write_ppm_tiff()"); + if (output_tiff) { + tiff_head (&th, 1); + fwrite (&th, sizeof th, 1, ofp); + if (oprof) + fwrite (oprof, ntohl(oprof[0]), 1, ofp); + } else if (colors > 3) + fprintf (ofp, + "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLTYPE %s\nENDHDR\n", + width, height, colors, (1 << output_bps)-1, cdesc); + else + fprintf (ofp, "P%d\n%d %d\n%d\n", + colors/2+5, width, height, (1 << output_bps)-1); + soff = flip_index (0, 0); + cstep = flip_index (0, 1) - soff; + rstep = flip_index (1, 0) - flip_index (0, width); + for (row=0; row < height; row++, soff += rstep) { + for (col=0; col < width; col++, soff += cstep) + if (output_bps == 8) + FORCC ppm [col*colors+c] = curve[image[soff][c]] >> 8; + else FORCC ppm2[col*colors+c] = curve[image[soff][c]]; + if (output_bps == 16 && !output_tiff && htons(0x55aa) != 0x55aa) + swab (ppm2, ppm2, width*colors*2); + fwrite (ppm, colors*output_bps/8, width, ofp); + } + free (ppm); +} + +int CLASS main (int argc, const char **argv) +{ + int arg, status=0, quality, i, c; + int timestamp_only=0, thumbnail_only=0, identify_only=0; + int user_qual=-1, user_black=-1, user_sat=-1, user_flip=-1; + int use_fuji_rotate=1, write_to_stdout=0, read_from_stdin=0; + const char *sp, *bpfile=0, *dark_frame=0, *write_ext; + char opm, opt, *ofname, *cp; + struct utimbuf ut; +#ifndef NO_LCMS + const char *cam_profile=0, *out_profile=0; +#endif + +#ifndef LOCALTIME + putenv ((char *) "TZ=UTC"); +#endif +#ifdef LOCALEDIR + setlocale (LC_CTYPE, ""); + setlocale (LC_MESSAGES, ""); + bindtextdomain ("dcraw", LOCALEDIR); + textdomain ("dcraw"); +#endif + + if (argc == 1) { + printf(_("\nRaw photo decoder \"dcraw\" v%s"), DCRAW_VERSION); + printf(_("\nby Dave Coffin, dcoffin a cybercom o net\n")); + printf(_("\nUsage: %s [OPTION]... [FILE]...\n\n"), argv[0]); + puts(_("-v Print verbose messages")); + puts(_("-c Write image data to standard output")); + puts(_("-e Extract embedded thumbnail image")); + puts(_("-i Identify files without decoding them")); + puts(_("-i -v Identify files and show metadata")); + puts(_("-z Change file dates to camera timestamp")); + puts(_("-w Use camera white balance, if possible")); + puts(_("-a Average the whole image for white balance")); + puts(_("-A Average a grey box for white balance")); + puts(_("-r Set custom white balance")); + puts(_("+M/-M Use/don't use an embedded color matrix")); + puts(_("-C Correct chromatic aberration")); + puts(_("-P Fix the dead pixels listed in this file")); + puts(_("-K Subtract dark frame (16-bit raw PGM)")); + puts(_("-k Set the darkness level")); + puts(_("-S Set the saturation level")); + puts(_("-n Set threshold for wavelet denoising")); + puts(_("-H [0-9] Highlight mode (0=clip, 1=unclip, 2=blend, 3+=rebuild)")); + puts(_("-t [0-7] Flip image (0=none, 3=180, 5=90CCW, 6=90CW)")); + puts(_("-o [0-5] Output colorspace (raw,sRGB,Adobe,Wide,ProPhoto,XYZ)")); +#ifndef NO_LCMS + puts(_("-o Apply output ICC profile from file")); + puts(_("-p Apply camera ICC profile from file or \"embed\"")); +#endif + puts(_("-d Document mode (no color, no interpolation)")); + puts(_("-D Document mode without scaling (totally raw)")); + puts(_("-j Don't stretch or rotate raw pixels")); + puts(_("-W Don't automatically brighten the image")); + puts(_("-b Adjust brightness (default = 1.0)")); + puts(_("-g

    Set custom gamma curve (default = 2.222 4.5)")); + puts(_("-q [0-3] Set the interpolation quality")); + puts(_("-h Half-size color image (twice as fast as \"-q 0\")")); + puts(_("-f Interpolate RGGB as four colors")); + puts(_("-m Apply a 3x3 median filter to R-G and B-G")); + puts(_("-s [0..N-1] Select one raw image or \"all\" from each file")); + puts(_("-6 Write 16-bit instead of 8-bit")); + puts(_("-4 Linear 16-bit, same as \"-6 -W -g 1 1\"")); + puts(_("-T Write TIFF instead of PPM")); + puts(""); + return 1; + } + argv[argc] = ""; + for (arg=1; (((opm = argv[arg][0]) - 2) | 2) == '+'; ) { + opt = argv[arg++][1]; + if ((cp = (char *) strchr (sp="nbrkStqmHACg", opt))) + for (i=0; i < "114111111422"[cp-sp]-'0'; i++) + if (!isdigit(argv[arg+i][0])) { + fprintf (stderr,_("Non-numeric argument to \"-%c\"\n"), opt); + return 1; + } + switch (opt) { + case 'n': threshold = atof(argv[arg++]); break; + case 'b': bright = atof(argv[arg++]); break; + case 'r': + FORC4 user_mul[c] = atof(argv[arg++]); break; + case 'C': aber[0] = 1 / atof(argv[arg++]); + aber[2] = 1 / atof(argv[arg++]); break; + case 'g': gamm[0] = atof(argv[arg++]); + gamm[1] = atof(argv[arg++]); + if (gamm[0]) gamm[0] = 1/gamm[0]; break; + case 'k': user_black = atoi(argv[arg++]); break; + case 'S': user_sat = atoi(argv[arg++]); break; + case 't': user_flip = atoi(argv[arg++]); break; + case 'q': user_qual = atoi(argv[arg++]); break; + case 'm': med_passes = atoi(argv[arg++]); break; + case 'H': highlight = atoi(argv[arg++]); break; + case 's': + shot_select = abs(atoi(argv[arg])); + multi_out = !strcmp(argv[arg++],"all"); + break; + case 'o': + if (isdigit(argv[arg][0]) && !argv[arg][1]) + output_color = atoi(argv[arg++]); +#ifndef NO_LCMS + else out_profile = argv[arg++]; + break; + case 'p': cam_profile = argv[arg++]; +#endif + break; + case 'P': bpfile = argv[arg++]; break; + case 'K': dark_frame = argv[arg++]; break; + case 'z': timestamp_only = 1; break; + case 'e': thumbnail_only = 1; break; + case 'i': identify_only = 1; break; + case 'c': write_to_stdout = 1; break; + case 'v': verbose = 1; break; + case 'h': half_size = 1; /* "-h" implies "-f" */ + case 'f': four_color_rgb = 1; break; + case 'A': FORC4 greybox[c] = atoi(argv[arg++]); + case 'a': use_auto_wb = 1; break; + case 'w': use_camera_wb = 1; break; + case 'M': use_camera_matrix = (opm == '+'); break; + case 'I': read_from_stdin = 1; break; + case 'E': document_mode++; + case 'D': document_mode++; + case 'd': document_mode++; + case 'j': use_fuji_rotate = 0; break; + case 'W': no_auto_bright = 1; break; + case 'T': output_tiff = 1; break; + case '4': gamm[0] = gamm[1] = + no_auto_bright = 1; + case '6': output_bps = 16; break; + default: + fprintf (stderr,_("Unknown option \"-%c\".\n"), opt); + return 1; + } + } + if (use_camera_matrix < 0) + use_camera_matrix = use_camera_wb; + if (arg == argc) { + fprintf (stderr,_("No files to process.\n")); + return 1; + } + if (write_to_stdout) { + if (isatty(1)) { + fprintf (stderr,_("Will not write an image to the terminal!\n")); + return 1; + } +#if defined(WIN32) || defined(DJGPP) || defined(__CYGWIN__) + if (setmode(1,O_BINARY) < 0) { + perror ("setmode()"); + return 1; + } +#endif + } + for ( ; arg < argc; arg++) { + status = 1; + raw_image = 0; + image = 0; + oprof = 0; + meta_data = ofname = 0; + ofp = stdout; + if (setjmp (failure)) { + if (fileno(ifp) > 2) fclose(ifp); + if (fileno(ofp) > 2) fclose(ofp); + status = 1; + goto cleanup; + } + ifname = argv[arg]; + if (!(ifp = fopen (ifname, "rb"))) { + perror (ifname); + continue; + } + status = (identify(),!is_raw); + if (user_flip >= 0) + flip = user_flip; + switch ((flip+3600) % 360) { + case 270: flip = 5; break; + case 180: flip = 3; break; + case 90: flip = 6; + } + if (timestamp_only) { + if ((status = !timestamp)) + fprintf (stderr,_("%s has no timestamp.\n"), ifname); + else if (identify_only) + printf ("%10ld%10d %s\n", (long) timestamp, shot_order, ifname); + else { + if (verbose) + fprintf (stderr,_("%s time set to %d.\n"), ifname, (int) timestamp); + ut.actime = ut.modtime = timestamp; + utime (ifname, &ut); + } + goto next; + } + write_fun = &CLASS write_ppm_tiff; + if (thumbnail_only) { + if ((status = !thumb_offset)) { + fprintf (stderr,_("%s has no thumbnail.\n"), ifname); + goto next; + } else if (thumb_load_raw) { + load_raw = thumb_load_raw; + data_offset = thumb_offset; + height = thumb_height; + width = thumb_width; + filters = 0; + } else { + fseek (ifp, thumb_offset, SEEK_SET); + write_fun = write_thumb; + goto thumbnail; + } + } + if (load_raw == &CLASS kodak_ycbcr_load_raw) { + height += height & 1; + width += width & 1; + } + if (identify_only && verbose && make[0]) { + printf (_("\nFilename: %s\n"), ifname); + printf (_("Timestamp: %s"), ctime(×tamp)); + printf (_("Camera: %s %s\n"), make, model); + if (artist[0]) + printf (_("Owner: %s\n"), artist); + if (dng_version) { + printf (_("DNG Version: ")); + for (i=24; i >= 0; i -= 8) + printf ("%d%c", dng_version >> i & 255, i ? '.':'\n'); + } + printf (_("ISO speed: %d\n"), (int) iso_speed); + printf (_("Shutter: ")); + if (shutter > 0 && shutter < 1) + shutter = (printf ("1/"), 1 / shutter); + printf (_("%0.1f sec\n"), shutter); + printf (_("Aperture: f/%0.1f\n"), aperture); + printf (_("Focal length: %0.1f mm\n"), focal_len); + printf (_("Embedded ICC profile: %s\n"), profile_length ? _("yes"):_("no")); + printf (_("Number of raw images: %d\n"), is_raw); + if (pixel_aspect != 1) + printf (_("Pixel Aspect Ratio: %0.6f\n"), pixel_aspect); + if (thumb_offset) + printf (_("Thumb size: %4d x %d\n"), thumb_width, thumb_height); + printf (_("Full size: %4d x %d\n"), raw_width, raw_height); + } else if (!is_raw) + fprintf (stderr,_("Cannot decode file %s\n"), ifname); + if (!is_raw) goto next; + shrink = filters && (half_size || (!identify_only && + (threshold || aber[0] != 1 || aber[2] != 1))); + if (document_mode == 3) { + top_margin = left_margin = fuji_width = 0; + height = raw_height; + if (width <= raw_width * 8 / tiff_bps) + width = raw_width * 8 / tiff_bps; + else width = raw_width; + } + iheight = (height + shrink) >> shrink; + iwidth = (width + shrink) >> shrink; + if (identify_only) { + if (verbose) { + if (use_fuji_rotate) { + if (fuji_width) { + fuji_width = (fuji_width - 1 + shrink) >> shrink; + iwidth = fuji_width / sqrt(0.5); + iheight = (iheight - fuji_width) / sqrt(0.5); + } else { + if (pixel_aspect < 1) iheight = iheight / pixel_aspect + 0.5; + if (pixel_aspect > 1) iwidth = iwidth * pixel_aspect + 0.5; + } + } + if (flip & 4) + SWAP(iheight,iwidth); + printf (_("Image size: %4d x %d\n"), width, height); + printf (_("Output size: %4d x %d\n"), iwidth, iheight); + printf (_("Raw colors: %d"), colors); + if (filters) { + printf (_("\nFilter pattern: ")); + for (i=0; i < 16; i++) + putchar (cdesc[fcol(i >> 1,i & 1)]); + } + printf (_("\nDaylight multipliers:")); + FORCC printf (" %f", pre_mul[c]); + if (cam_mul[0] > 0) { + printf (_("\nCamera multipliers:")); + FORC4 printf (" %f", cam_mul[c]); + } + putchar ('\n'); + } else + printf (_("%s is a %s %s image.\n"), ifname, make, model); +next: + fclose(ifp); + continue; + } + if (use_camera_matrix && cmatrix[0][0] > 0.25) { + memcpy (rgb_cam, cmatrix, sizeof cmatrix); + raw_color = 0; + } + image = (ushort (*)[4]) calloc (iheight*iwidth, sizeof *image); + merror (image, "main()"); + if (meta_length) { + meta_data = (char *) malloc (meta_length); + merror (meta_data, "main()"); + } + if (filters || colors == 1) { + raw_image = (ushort *) calloc ((raw_height+7)*raw_width, 2); + merror (raw_image, "main()"); + } + if (verbose) + fprintf (stderr,_("Loading %s %s image from %s ...\n"), + make, model, ifname); + if (shot_select >= is_raw) + fprintf (stderr,_("%s: \"-s %d\" requests a nonexistent image!\n"), + ifname, shot_select); + fseeko (ifp, data_offset, SEEK_SET); + if (raw_image && read_from_stdin) + fread (raw_image, 2, raw_height*raw_width, stdin); + else (*load_raw)(); + if (raw_image) { + crop_masked_pixels(); + free (raw_image); + } + if (zero_is_bad) remove_zeroes(); + bad_pixels (bpfile); + if (dark_frame) subtract (dark_frame); + quality = 2 + !fuji_width; + if (user_qual >= 0) quality = user_qual; + i = cblack[3]; + FORC3 if (i > cblack[c]) i = cblack[c]; + FORC4 cblack[c] -= i; + black += i; + if (user_black >= 0) black = user_black; + FORC4 cblack[c] += black; + if (user_sat > 0) maximum = user_sat; +#ifdef COLORCHECK + colorcheck(); +#endif + if (is_foveon) { + if (document_mode || model[0] == 'D') { + for (i=0; i < height*width*4; i++) + if ((short) image[0][i] < 0) image[0][i] = 0; + } else foveon_interpolate(); + } else if (document_mode < 2) + scale_colors(); + pre_interpolate(); + if (filters && !document_mode) { + if (quality == 0) + lin_interpolate(); + else if (quality == 1 || colors > 3 || filters < 1000) + vng_interpolate(); + else if (quality == 2) + ppg_interpolate(); + else ahd_interpolate(); + } + if (mix_green) + for (colors=3, i=0; i < height*width; i++) + image[i][1] = (image[i][1] + image[i][3]) >> 1; + if (!is_foveon && colors == 3) median_filter(); + if (!is_foveon && highlight == 2) blend_highlights(); + if (!is_foveon && highlight > 2) recover_highlights(); + if (use_fuji_rotate) fuji_rotate(); +#ifndef NO_LCMS + if (cam_profile) apply_profile (cam_profile, out_profile); +#endif + convert_to_rgb(); + if (use_fuji_rotate) stretch(); +thumbnail: + if (write_fun == &CLASS jpeg_thumb) + write_ext = ".jpg"; + else if (output_tiff && write_fun == &CLASS write_ppm_tiff) + write_ext = ".tiff"; + else + write_ext = ".pgm\0.ppm\0.ppm\0.pam" + colors*5-5; + ofname = (char *) malloc (strlen(ifname) + 64); + merror (ofname, "main()"); + if (write_to_stdout) + strcpy (ofname,_("standard output")); + else { + strcpy (ofname, ifname); + if ((cp = strrchr (ofname, '.'))) *cp = 0; + if (multi_out) + sprintf (ofname+strlen(ofname), "_%0*d", + snprintf(0,0,"%d",is_raw-1), shot_select); + if (thumbnail_only) + strcat (ofname, ".thumb"); + strcat (ofname, write_ext); + ofp = fopen (ofname, "wb"); + if (!ofp) { + status = 1; + perror (ofname); + goto cleanup; + } + } + if (verbose) + fprintf (stderr,_("Writing data to %s ...\n"), ofname); + (*write_fun)(); + fclose(ifp); + if (ofp != stdout) fclose(ofp); +cleanup: + if (meta_data) free (meta_data); + if (ofname) free (ofname); + if (oprof) free (oprof); + if (image) free (image); + if (multi_out) { + if (++shot_select < is_raw) arg--; + else shot_select = 0; + } + } + return status; +} diff --git a/Source/LibRawLite/internal/dcb_demosaicing.c b/Source/LibRawLite/internal/dcb_demosaicing.c index ed3631c..4839004 100644 --- a/Source/LibRawLite/internal/dcb_demosaicing.c +++ b/Source/LibRawLite/internal/dcb_demosaicing.c @@ -1,710 +1,710 @@ -/* - * Copyright (C) 2010, Jacek Gozdz (cuniek@kft.umcs.lublin.pl) - * - * This code is licensed under a (3-clause) BSD license as follows : - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following - * conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of the author nor the names of its - * contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - */ - -// DCB demosaicing by Jacek Gozdz (cuniek@kft.umcs.lublin.pl) - -// FBDD denoising by Jacek Gozdz (cuniek@kft.umcs.lublin.pl) and -// Luis Sanz Rodríguez (luis.sanz.rodriguez@gmail.com) - -// last modification: 11.07.2010 - - -// interpolates green vertically and saves it to image3 -void CLASS dcb_ver(float (*image3)[3]) -{ - int row, col, u=width, v=2*u, indx; - - for (row=2; row < height-2; row++) - for (col=2+(FC(row,2)&1),indx=row*width+col; col < u-2; col+=2,indx+=2) { - - image3[indx][1] = CLIP((image[indx+u][1] + image[indx-u][1])/2.0); - - } -} - - -// interpolates green horizontally and saves it to image2 -void CLASS dcb_hor(float (*image2)[3]) -{ - int row, col, u=width, v=2*u, indx; - - for (row=2; row < height-2; row++) - for (col=2+(FC(row,2)&1),indx=row*width+col; col < u-2; col+=2,indx+=2) { - - image2[indx][1] = CLIP((image[indx+1][1] + image[indx-1][1])/2.0); - - } -} - - - -// missing colors are interpolated -void CLASS dcb_color() -{ - int row, col, c, d, u=width, indx; - - - for (row=1; row < height-1; row++) - for (col=1+(FC(row,1) & 1), indx=row*width+col, c=2-FC(row,col); col < u-1; col+=2, indx+=2) { - - - image[indx][c] = CLIP(( - 4*image[indx][1] - - image[indx+u+1][1] - image[indx+u-1][1] - image[indx-u+1][1] - image[indx-u-1][1] - + image[indx+u+1][c] + image[indx+u-1][c] + image[indx-u+1][c] + image[indx-u-1][c] )/4.0); - } - - for (row=1; row ( image[indx-1][1] + image[indx+1][1] + image[indx-u][1] + image[indx+u][1])/4.0) - image[indx][3] = ((MIN( image[indx-1][1], image[indx+1][1]) + image[indx-1][1] + image[indx+1][1]) < - (MIN( image[indx-u][1], image[indx+u][1]) + image[indx-u][1] + image[indx+u][1])); - else - image[indx][3] = ((MAX( image[indx-1][1], image[indx+1][1]) + image[indx-1][1] + image[indx+1][1]) > - (MAX( image[indx-u][1], image[indx+u][1]) + image[indx-u][1] + image[indx+u][1])); - } - } -} - - -// interpolated green pixels are corrected using the map -void CLASS dcb_correction() -{ - int current, row, col, u=width, v=2*u, indx; - - for (row=2; row < height-2; row++) - for (col=2+(FC(row,2)&1),indx=row*width+col; col < u-2; col+=2,indx+=2) { - - current = 4*image[indx][3] + - 2*(image[indx+u][3] + image[indx-u][3] + image[indx+1][3] + image[indx-1][3]) + - image[indx+v][3] + image[indx-v][3] + image[indx+2][3] + image[indx-2][3]; - - image[indx][1] = ((16-current)*(image[indx-1][1] + image[indx+1][1])/2.0 + current*(image[indx-u][1] + image[indx+u][1])/2.0)/16.0; - - } - -} - - -// interpolated green pixels are corrected using the map -// with contrast correction -void CLASS dcb_correction2() -{ - int current, row, col, c, u=width, v=2*u, indx; - ushort (*pix)[4]; - - for (row=4; row < height-4; row++) - for (col=4+(FC(row,2)&1),indx=row*width+col, c=FC(row,col); col < u-4; col+=2,indx+=2) { - - current = 4*image[indx][3] + - 2*(image[indx+u][3] + image[indx-u][3] + image[indx+1][3] + image[indx-1][3]) + - image[indx+v][3] + image[indx-v][3] + image[indx+2][3] + image[indx-2][3]; - - image[indx][1] = CLIP(((16-current)*((image[indx-1][1] + image[indx+1][1])/2.0 + image[indx][c] - (image[indx+2][c] + image[indx-2][c])/2.0) + current*((image[indx-u][1] + image[indx+u][1])/2.0 + image[indx][c] - (image[indx+v][c] + image[indx-v][c])/2.0))/16.0); - - } - -} - - -void CLASS dcb_refinement() -{ - int row, col, c, u=width, v=2*u, w=3*u, indx, current; - float f[5], g1, g2, tmp, tmp2=0, tmp3=0; - - for (row=4; row < height-4; row++) - for (col=4+(FC(row,2)&1),indx=row*width+col, c=FC(row,col); col < u-4; col+=2,indx+=2) { - - current = 4*image[indx][3] + - 2*(image[indx+u][3] + image[indx-u][3] + image[indx+1][3] + image[indx-1][3]) - +image[indx+v][3] + image[indx-v][3] + image[indx-2][3] + image[indx+2][3]; - -if (image[indx][c] > 1) -{ - -f[0] = (float)(image[indx-u][1] + image[indx+u][1])/(2*image[indx][c]); - - -if (image[indx-v][c] > 0) -f[1] = 2*(float)image[indx-u][1]/(image[indx-v][c] + image[indx][c]); -else -f[1] = f[0]; - -if (image[indx-v][c] > 0) -f[2] = (float)(image[indx-u][1] + image[indx-w][1])/(2*image[indx-v][c]); -else -f[2] = f[0]; - -if (image[indx+v][c] > 0) -f[3] = 2*(float)image[indx+u][1]/(image[indx+v][c] + image[indx][c]); -else -f[3] = f[0]; - -if (image[indx+v][c] > 0) -f[4] = (float)(image[indx+u][1] + image[indx+w][1])/(2*image[indx+v][c]); -else -f[4] = f[0]; - -g1 = (5*f[0] + 3*f[1] + f[2] + 3*f[3] + f[4])/13.0; - - - -f[0] = (float)(image[indx-1][1] + image[indx+1][1])/(2*image[indx][c]); - -if (image[indx-2][c] > 0) -f[1] = 2*(float)image[indx-1][1]/(image[indx-2][c] + image[indx][c]); -else -f[1] = f[0]; - -if (image[indx-2][c] > 0) -f[2] = (float)(image[indx-1][1] + image[indx-3][1])/(2*image[indx-2][c]); -else -f[2] = f[0]; - -if (image[indx+2][c] > 0) -f[3] = 2*(float)image[indx+1][1]/(image[indx+2][c] + image[indx][c]); -else -f[3] = f[0]; - -if (image[indx+2][c] > 0) -f[4] = (float)(image[indx+1][1] + image[indx+3][1])/(2*image[indx+2][c]); -else -f[4] = f[0]; - -g2 = (5*f[0] + 3*f[1] + f[2] + 3*f[3] + f[4])/13.0; - - -image[indx][1] = CLIP((image[indx][c])*(current*g1 + (16-current)*g2)/16.0); -} -else -image[indx][1] = image[indx][c]; - - // get rid of overshooted pixels - - g1 = MIN(image[indx+1+u][1], MIN(image[indx+1-u][1], MIN(image[indx-1+u][1], MIN(image[indx-1-u][1], MIN(image[indx-1][1], MIN(image[indx+1][1], MIN(image[indx-u][1], image[indx+u][1]))))))); - - g2 = MAX(image[indx+1+u][1], MAX(image[indx+1-u][1], MAX(image[indx-1+u][1], MAX(image[indx-1-u][1], MAX(image[indx-1][1], MAX(image[indx+1][1], MAX(image[indx-u][1], image[indx+u][1]))))))); - - image[indx][1] = ULIM(image[indx][1], g2, g1); - - } - - - -} - -// converts RGB to LCH colorspace and saves it to image3 -void CLASS rgb_to_lch(double (*image2)[3]) -{ - int indx; - for (indx=0; indx < height*width; indx++) { - - image2[indx][0] = image[indx][0] + image[indx][1] + image[indx][2]; // L - image2[indx][1] = 1.732050808 *(image[indx][0] - image[indx][1]); // C - image2[indx][2] = 2.0*image[indx][2] - image[indx][0] - image[indx][1]; // H - } -} - -// converts LCH to RGB colorspace and saves it back to image -void CLASS lch_to_rgb(double (*image2)[3]) -{ - int indx; - for (indx=0; indx < height*width; indx++) { - - image[indx][0] = CLIP(image2[indx][0] / 3.0 - image2[indx][2] / 6.0 + image2[indx][1] / 3.464101615); - image[indx][1] = CLIP(image2[indx][0] / 3.0 - image2[indx][2] / 6.0 - image2[indx][1] / 3.464101615); - image[indx][2] = CLIP(image2[indx][0] / 3.0 + image2[indx][2] / 3.0); - } -} - - - - -// denoising using interpolated neighbours -void CLASS fbdd_correction() -{ - int row, col, c, u=width, indx; - ushort (*pix)[4]; - - for (row=2; row < height-2; row++) { - for (col=2, indx=row*width+col; col < width-2; col++, indx++) { - - c = fc(row,col); - - image[indx][c] = ULIM(image[indx][c], - MAX(image[indx-1][c], MAX(image[indx+1][c], MAX(image[indx-u][c], image[indx+u][c]))), - MIN(image[indx-1][c], MIN(image[indx+1][c], MIN(image[indx-u][c], image[indx+u][c])))); - - } - } -} - - -// corrects chroma noise -void CLASS fbdd_correction2(double (*image2)[3]) -{ - int indx, u=width, v=2*width; - int col, row; - double Co, Ho, ratio; - - for (row=6; row < height-6; row++) - { - for (col=6; col < width-6; col++) - { - indx = row*width+col; - - if ( image2[indx][1]*image2[indx][2] != 0 ) - { - Co = (image2[indx+v][1] + image2[indx-v][1] + image2[indx-2][1] + image2[indx+2][1] - - MAX(image2[indx-2][1], MAX(image2[indx+2][1], MAX(image2[indx-v][1], image2[indx+v][1]))) - - MIN(image2[indx-2][1], MIN(image2[indx+2][1], MIN(image2[indx-v][1], image2[indx+v][1]))))/2.0; - Ho = (image2[indx+v][2] + image2[indx-v][2] + image2[indx-2][2] + image2[indx+2][2] - - MAX(image2[indx-2][2], MAX(image2[indx+2][2], MAX(image2[indx-v][2], image2[indx+v][2]))) - - MIN(image2[indx-2][2], MIN(image2[indx+2][2], MIN(image2[indx-v][2], image2[indx+v][2]))))/2.0; - ratio = sqrt ((Co*Co+Ho*Ho) / (image2[indx][1]*image2[indx][1] + image2[indx][2]*image2[indx][2])); - - if (ratio < 0.85) - { - image2[indx][0] = -(image2[indx][1] + image2[indx][2] - Co - Ho) + image2[indx][0]; - image2[indx][1] = Co; - image2[indx][2] = Ho; - } - } - } - } -} - - -// Cubic Spline Interpolation by Li and Randhawa, modified by Jacek Gozdz and Luis Sanz Rodríguez -void CLASS fbdd_green() -{ - int row, col, c, u=width, v=2*u, w=3*u, x=4*u, y=5*u, indx, min, max, current; - float f[4], g[4]; - - for (row=5; row < height-5; row++) - for (col=5+(FC(row,1)&1),indx=row*width+col,c=FC(row,col); col < u-5; col+=2,indx+=2) { - - -f[0]=1.0/(1.0+abs(image[indx-u][1]-image[indx-w][1])+abs(image[indx-w][1]-image[indx+y][1])); -f[1]=1.0/(1.0+abs(image[indx+1][1]-image[indx+3][1])+abs(image[indx+3][1]-image[indx-5][1])); -f[2]=1.0/(1.0+abs(image[indx-1][1]-image[indx-3][1])+abs(image[indx-3][1]-image[indx+5][1])); -f[3]=1.0/(1.0+abs(image[indx+u][1]-image[indx+w][1])+abs(image[indx+w][1]-image[indx-y][1])); - -g[0]=CLIP((23*image[indx-u][1]+23*image[indx-w][1]+2*image[indx-y][1]+8*(image[indx-v][c]-image[indx-x][c])+40*(image[indx][c]-image[indx-v][c]))/48.0); -g[1]=CLIP((23*image[indx+1][1]+23*image[indx+3][1]+2*image[indx+5][1]+8*(image[indx+2][c]-image[indx+4][c])+40*(image[indx][c]-image[indx+2][c]))/48.0); -g[2]=CLIP((23*image[indx-1][1]+23*image[indx-3][1]+2*image[indx-5][1]+8*(image[indx-2][c]-image[indx-4][c])+40*(image[indx][c]-image[indx-2][c]))/48.0); -g[3]=CLIP((23*image[indx+u][1]+23*image[indx+w][1]+2*image[indx+y][1]+8*(image[indx+v][c]-image[indx+x][c])+40*(image[indx][c]-image[indx+v][c]))/48.0); - - image[indx][1]=CLIP((f[0]*g[0]+f[1]*g[1]+f[2]*g[2]+f[3]*g[3])/(f[0]+f[1]+f[2]+f[3])); - - min = MIN(image[indx+1+u][1], MIN(image[indx+1-u][1], MIN(image[indx-1+u][1], MIN(image[indx-1-u][1], MIN(image[indx-1][1], MIN(image[indx+1][1], MIN(image[indx-u][1], image[indx+u][1]))))))); - - max = MAX(image[indx+1+u][1], MAX(image[indx+1-u][1], MAX(image[indx-1+u][1], MAX(image[indx-1-u][1], MAX(image[indx-1][1], MAX(image[indx+1][1], MAX(image[indx-u][1], image[indx+u][1]))))))); - - image[indx][1] = ULIM(image[indx][1], max, min); - } -} - - - - -// FBDD (Fake Before Demosaicing Denoising) -void CLASS fbdd(int noiserd) -{ - double (*image2)[3]; - // safety net: disable for 4-color bayer or full-color images - if(colors!=3 || !filters) - return; - image2 = (double (*)[3]) calloc(width*height, sizeof *image2); - - border_interpolate(4); - -if (noiserd>1) -{ -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("FBDD full noise reduction...\n")); -#endif - fbdd_green(); - //dcb_color_full(image2); - dcb_color_full(); - fbdd_correction(); - - - dcb_color(); - rgb_to_lch(image2); - fbdd_correction2(image2); - fbdd_correction2(image2); - lch_to_rgb(image2); - -} -else -{ -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("FBDD noise reduction...\n")); -#endif - - fbdd_green(); - //dcb_color_full(image2); - dcb_color_full(); - fbdd_correction(); -} - -free(image2); - -} - - - - -// DCB demosaicing main routine -void CLASS dcb(int iterations, int dcb_enhance) -{ - - - int i=1; - - float (*image2)[3]; - image2 = (float (*)[3]) calloc(width*height, sizeof *image2); - - float (*image3)[3]; - image3 = (float (*)[3]) calloc(width*height, sizeof *image3); - -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("DCB demosaicing...\n")); -#endif - - border_interpolate(6); - - dcb_hor(image2); - dcb_color2(image2); - - dcb_ver(image3); - dcb_color3(image3); - - dcb_decide(image2, image3); - - free(image3); - - dcb_copy_to_buffer(image2); - - while (i<=iterations) - { -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("DCB correction pass %d...\n"), i); -#endif - dcb_nyquist(); - dcb_nyquist(); - dcb_nyquist(); - dcb_map(); - dcb_correction(); - i++; - } - - dcb_color(); - dcb_pp(); - -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("finishing DCB...\n")); -#endif - dcb_map(); - dcb_correction2(); - - dcb_map(); - dcb_correction(); - - dcb_map(); - dcb_correction(); - - dcb_map(); - dcb_correction(); - - dcb_map(); - dcb_restore_from_buffer(image2); - dcb_color(); - - if (dcb_enhance) - { -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("optional DCB refinement...\n")); -#endif - dcb_refinement(); - //dcb_color_full(image2); - dcb_color_full(); - } - - - free(image2); - -} - +/* + * Copyright (C) 2010, Jacek Gozdz (cuniek@kft.umcs.lublin.pl) + * + * This code is licensed under a (3-clause) BSD license as follows : + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following + * conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of the author nor the names of its + * contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + */ + +// DCB demosaicing by Jacek Gozdz (cuniek@kft.umcs.lublin.pl) + +// FBDD denoising by Jacek Gozdz (cuniek@kft.umcs.lublin.pl) and +// Luis Sanz Rodríguez (luis.sanz.rodriguez@gmail.com) + +// last modification: 11.07.2010 + + +// interpolates green vertically and saves it to image3 +void CLASS dcb_ver(float (*image3)[3]) +{ + int row, col, u=width, v=2*u, indx; + + for (row=2; row < height-2; row++) + for (col=2+(FC(row,2)&1),indx=row*width+col; col < u-2; col+=2,indx+=2) { + + image3[indx][1] = CLIP((image[indx+u][1] + image[indx-u][1])/2.0); + + } +} + + +// interpolates green horizontally and saves it to image2 +void CLASS dcb_hor(float (*image2)[3]) +{ + int row, col, u=width, v=2*u, indx; + + for (row=2; row < height-2; row++) + for (col=2+(FC(row,2)&1),indx=row*width+col; col < u-2; col+=2,indx+=2) { + + image2[indx][1] = CLIP((image[indx+1][1] + image[indx-1][1])/2.0); + + } +} + + + +// missing colors are interpolated +void CLASS dcb_color() +{ + int row, col, c, d, u=width, indx; + + + for (row=1; row < height-1; row++) + for (col=1+(FC(row,1) & 1), indx=row*width+col, c=2-FC(row,col); col < u-1; col+=2, indx+=2) { + + + image[indx][c] = CLIP(( + 4*image[indx][1] + - image[indx+u+1][1] - image[indx+u-1][1] - image[indx-u+1][1] - image[indx-u-1][1] + + image[indx+u+1][c] + image[indx+u-1][c] + image[indx-u+1][c] + image[indx-u-1][c] )/4.0); + } + + for (row=1; row ( image[indx-1][1] + image[indx+1][1] + image[indx-u][1] + image[indx+u][1])/4.0) + image[indx][3] = ((MIN( image[indx-1][1], image[indx+1][1]) + image[indx-1][1] + image[indx+1][1]) < + (MIN( image[indx-u][1], image[indx+u][1]) + image[indx-u][1] + image[indx+u][1])); + else + image[indx][3] = ((MAX( image[indx-1][1], image[indx+1][1]) + image[indx-1][1] + image[indx+1][1]) > + (MAX( image[indx-u][1], image[indx+u][1]) + image[indx-u][1] + image[indx+u][1])); + } + } +} + + +// interpolated green pixels are corrected using the map +void CLASS dcb_correction() +{ + int current, row, col, u=width, v=2*u, indx; + + for (row=2; row < height-2; row++) + for (col=2+(FC(row,2)&1),indx=row*width+col; col < u-2; col+=2,indx+=2) { + + current = 4*image[indx][3] + + 2*(image[indx+u][3] + image[indx-u][3] + image[indx+1][3] + image[indx-1][3]) + + image[indx+v][3] + image[indx-v][3] + image[indx+2][3] + image[indx-2][3]; + + image[indx][1] = ((16-current)*(image[indx-1][1] + image[indx+1][1])/2.0 + current*(image[indx-u][1] + image[indx+u][1])/2.0)/16.0; + + } + +} + + +// interpolated green pixels are corrected using the map +// with contrast correction +void CLASS dcb_correction2() +{ + int current, row, col, c, u=width, v=2*u, indx; + ushort (*pix)[4]; + + for (row=4; row < height-4; row++) + for (col=4+(FC(row,2)&1),indx=row*width+col, c=FC(row,col); col < u-4; col+=2,indx+=2) { + + current = 4*image[indx][3] + + 2*(image[indx+u][3] + image[indx-u][3] + image[indx+1][3] + image[indx-1][3]) + + image[indx+v][3] + image[indx-v][3] + image[indx+2][3] + image[indx-2][3]; + + image[indx][1] = CLIP(((16-current)*((image[indx-1][1] + image[indx+1][1])/2.0 + image[indx][c] - (image[indx+2][c] + image[indx-2][c])/2.0) + current*((image[indx-u][1] + image[indx+u][1])/2.0 + image[indx][c] - (image[indx+v][c] + image[indx-v][c])/2.0))/16.0); + + } + +} + + +void CLASS dcb_refinement() +{ + int row, col, c, u=width, v=2*u, w=3*u, indx, current; + float f[5], g1, g2, tmp, tmp2=0, tmp3=0; + + for (row=4; row < height-4; row++) + for (col=4+(FC(row,2)&1),indx=row*width+col, c=FC(row,col); col < u-4; col+=2,indx+=2) { + + current = 4*image[indx][3] + + 2*(image[indx+u][3] + image[indx-u][3] + image[indx+1][3] + image[indx-1][3]) + +image[indx+v][3] + image[indx-v][3] + image[indx-2][3] + image[indx+2][3]; + +if (image[indx][c] > 1) +{ + +f[0] = (float)(image[indx-u][1] + image[indx+u][1])/(2*image[indx][c]); + + +if (image[indx-v][c] > 0) +f[1] = 2*(float)image[indx-u][1]/(image[indx-v][c] + image[indx][c]); +else +f[1] = f[0]; + +if (image[indx-v][c] > 0) +f[2] = (float)(image[indx-u][1] + image[indx-w][1])/(2*image[indx-v][c]); +else +f[2] = f[0]; + +if (image[indx+v][c] > 0) +f[3] = 2*(float)image[indx+u][1]/(image[indx+v][c] + image[indx][c]); +else +f[3] = f[0]; + +if (image[indx+v][c] > 0) +f[4] = (float)(image[indx+u][1] + image[indx+w][1])/(2*image[indx+v][c]); +else +f[4] = f[0]; + +g1 = (5*f[0] + 3*f[1] + f[2] + 3*f[3] + f[4])/13.0; + + + +f[0] = (float)(image[indx-1][1] + image[indx+1][1])/(2*image[indx][c]); + +if (image[indx-2][c] > 0) +f[1] = 2*(float)image[indx-1][1]/(image[indx-2][c] + image[indx][c]); +else +f[1] = f[0]; + +if (image[indx-2][c] > 0) +f[2] = (float)(image[indx-1][1] + image[indx-3][1])/(2*image[indx-2][c]); +else +f[2] = f[0]; + +if (image[indx+2][c] > 0) +f[3] = 2*(float)image[indx+1][1]/(image[indx+2][c] + image[indx][c]); +else +f[3] = f[0]; + +if (image[indx+2][c] > 0) +f[4] = (float)(image[indx+1][1] + image[indx+3][1])/(2*image[indx+2][c]); +else +f[4] = f[0]; + +g2 = (5*f[0] + 3*f[1] + f[2] + 3*f[3] + f[4])/13.0; + + +image[indx][1] = CLIP((image[indx][c])*(current*g1 + (16-current)*g2)/16.0); +} +else +image[indx][1] = image[indx][c]; + + // get rid of overshooted pixels + + g1 = MIN(image[indx+1+u][1], MIN(image[indx+1-u][1], MIN(image[indx-1+u][1], MIN(image[indx-1-u][1], MIN(image[indx-1][1], MIN(image[indx+1][1], MIN(image[indx-u][1], image[indx+u][1]))))))); + + g2 = MAX(image[indx+1+u][1], MAX(image[indx+1-u][1], MAX(image[indx-1+u][1], MAX(image[indx-1-u][1], MAX(image[indx-1][1], MAX(image[indx+1][1], MAX(image[indx-u][1], image[indx+u][1]))))))); + + image[indx][1] = ULIM(image[indx][1], g2, g1); + + } + + + +} + +// converts RGB to LCH colorspace and saves it to image3 +void CLASS rgb_to_lch(double (*image2)[3]) +{ + int indx; + for (indx=0; indx < height*width; indx++) { + + image2[indx][0] = image[indx][0] + image[indx][1] + image[indx][2]; // L + image2[indx][1] = 1.732050808 *(image[indx][0] - image[indx][1]); // C + image2[indx][2] = 2.0*image[indx][2] - image[indx][0] - image[indx][1]; // H + } +} + +// converts LCH to RGB colorspace and saves it back to image +void CLASS lch_to_rgb(double (*image2)[3]) +{ + int indx; + for (indx=0; indx < height*width; indx++) { + + image[indx][0] = CLIP(image2[indx][0] / 3.0 - image2[indx][2] / 6.0 + image2[indx][1] / 3.464101615); + image[indx][1] = CLIP(image2[indx][0] / 3.0 - image2[indx][2] / 6.0 - image2[indx][1] / 3.464101615); + image[indx][2] = CLIP(image2[indx][0] / 3.0 + image2[indx][2] / 3.0); + } +} + + + + +// denoising using interpolated neighbours +void CLASS fbdd_correction() +{ + int row, col, c, u=width, indx; + ushort (*pix)[4]; + + for (row=2; row < height-2; row++) { + for (col=2, indx=row*width+col; col < width-2; col++, indx++) { + + c = fc(row,col); + + image[indx][c] = ULIM(image[indx][c], + MAX(image[indx-1][c], MAX(image[indx+1][c], MAX(image[indx-u][c], image[indx+u][c]))), + MIN(image[indx-1][c], MIN(image[indx+1][c], MIN(image[indx-u][c], image[indx+u][c])))); + + } + } +} + + +// corrects chroma noise +void CLASS fbdd_correction2(double (*image2)[3]) +{ + int indx, u=width, v=2*width; + int col, row; + double Co, Ho, ratio; + + for (row=6; row < height-6; row++) + { + for (col=6; col < width-6; col++) + { + indx = row*width+col; + + if ( image2[indx][1]*image2[indx][2] != 0 ) + { + Co = (image2[indx+v][1] + image2[indx-v][1] + image2[indx-2][1] + image2[indx+2][1] - + MAX(image2[indx-2][1], MAX(image2[indx+2][1], MAX(image2[indx-v][1], image2[indx+v][1]))) - + MIN(image2[indx-2][1], MIN(image2[indx+2][1], MIN(image2[indx-v][1], image2[indx+v][1]))))/2.0; + Ho = (image2[indx+v][2] + image2[indx-v][2] + image2[indx-2][2] + image2[indx+2][2] - + MAX(image2[indx-2][2], MAX(image2[indx+2][2], MAX(image2[indx-v][2], image2[indx+v][2]))) - + MIN(image2[indx-2][2], MIN(image2[indx+2][2], MIN(image2[indx-v][2], image2[indx+v][2]))))/2.0; + ratio = sqrt ((Co*Co+Ho*Ho) / (image2[indx][1]*image2[indx][1] + image2[indx][2]*image2[indx][2])); + + if (ratio < 0.85) + { + image2[indx][0] = -(image2[indx][1] + image2[indx][2] - Co - Ho) + image2[indx][0]; + image2[indx][1] = Co; + image2[indx][2] = Ho; + } + } + } + } +} + + +// Cubic Spline Interpolation by Li and Randhawa, modified by Jacek Gozdz and Luis Sanz Rodríguez +void CLASS fbdd_green() +{ + int row, col, c, u=width, v=2*u, w=3*u, x=4*u, y=5*u, indx, min, max, current; + float f[4], g[4]; + + for (row=5; row < height-5; row++) + for (col=5+(FC(row,1)&1),indx=row*width+col,c=FC(row,col); col < u-5; col+=2,indx+=2) { + + +f[0]=1.0/(1.0+abs(image[indx-u][1]-image[indx-w][1])+abs(image[indx-w][1]-image[indx+y][1])); +f[1]=1.0/(1.0+abs(image[indx+1][1]-image[indx+3][1])+abs(image[indx+3][1]-image[indx-5][1])); +f[2]=1.0/(1.0+abs(image[indx-1][1]-image[indx-3][1])+abs(image[indx-3][1]-image[indx+5][1])); +f[3]=1.0/(1.0+abs(image[indx+u][1]-image[indx+w][1])+abs(image[indx+w][1]-image[indx-y][1])); + +g[0]=CLIP((23*image[indx-u][1]+23*image[indx-w][1]+2*image[indx-y][1]+8*(image[indx-v][c]-image[indx-x][c])+40*(image[indx][c]-image[indx-v][c]))/48.0); +g[1]=CLIP((23*image[indx+1][1]+23*image[indx+3][1]+2*image[indx+5][1]+8*(image[indx+2][c]-image[indx+4][c])+40*(image[indx][c]-image[indx+2][c]))/48.0); +g[2]=CLIP((23*image[indx-1][1]+23*image[indx-3][1]+2*image[indx-5][1]+8*(image[indx-2][c]-image[indx-4][c])+40*(image[indx][c]-image[indx-2][c]))/48.0); +g[3]=CLIP((23*image[indx+u][1]+23*image[indx+w][1]+2*image[indx+y][1]+8*(image[indx+v][c]-image[indx+x][c])+40*(image[indx][c]-image[indx+v][c]))/48.0); + + image[indx][1]=CLIP((f[0]*g[0]+f[1]*g[1]+f[2]*g[2]+f[3]*g[3])/(f[0]+f[1]+f[2]+f[3])); + + min = MIN(image[indx+1+u][1], MIN(image[indx+1-u][1], MIN(image[indx-1+u][1], MIN(image[indx-1-u][1], MIN(image[indx-1][1], MIN(image[indx+1][1], MIN(image[indx-u][1], image[indx+u][1]))))))); + + max = MAX(image[indx+1+u][1], MAX(image[indx+1-u][1], MAX(image[indx-1+u][1], MAX(image[indx-1-u][1], MAX(image[indx-1][1], MAX(image[indx+1][1], MAX(image[indx-u][1], image[indx+u][1]))))))); + + image[indx][1] = ULIM(image[indx][1], max, min); + } +} + + + + +// FBDD (Fake Before Demosaicing Denoising) +void CLASS fbdd(int noiserd) +{ + double (*image2)[3]; + // safety net: disable for 4-color bayer or full-color images + if(colors!=3 || !filters) + return; + image2 = (double (*)[3]) calloc(width*height, sizeof *image2); + + border_interpolate(4); + +if (noiserd>1) +{ +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("FBDD full noise reduction...\n")); +#endif + fbdd_green(); + //dcb_color_full(image2); + dcb_color_full(); + fbdd_correction(); + + + dcb_color(); + rgb_to_lch(image2); + fbdd_correction2(image2); + fbdd_correction2(image2); + lch_to_rgb(image2); + +} +else +{ +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("FBDD noise reduction...\n")); +#endif + + fbdd_green(); + //dcb_color_full(image2); + dcb_color_full(); + fbdd_correction(); +} + +free(image2); + +} + + + + +// DCB demosaicing main routine +void CLASS dcb(int iterations, int dcb_enhance) +{ + + + int i=1; + + float (*image2)[3]; + image2 = (float (*)[3]) calloc(width*height, sizeof *image2); + + float (*image3)[3]; + image3 = (float (*)[3]) calloc(width*height, sizeof *image3); + +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("DCB demosaicing...\n")); +#endif + + border_interpolate(6); + + dcb_hor(image2); + dcb_color2(image2); + + dcb_ver(image3); + dcb_color3(image3); + + dcb_decide(image2, image3); + + free(image3); + + dcb_copy_to_buffer(image2); + + while (i<=iterations) + { +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("DCB correction pass %d...\n"), i); +#endif + dcb_nyquist(); + dcb_nyquist(); + dcb_nyquist(); + dcb_map(); + dcb_correction(); + i++; + } + + dcb_color(); + dcb_pp(); + +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("finishing DCB...\n")); +#endif + dcb_map(); + dcb_correction2(); + + dcb_map(); + dcb_correction(); + + dcb_map(); + dcb_correction(); + + dcb_map(); + dcb_correction(); + + dcb_map(); + dcb_restore_from_buffer(image2); + dcb_color(); + + if (dcb_enhance) + { +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("optional DCB refinement...\n")); +#endif + dcb_refinement(); + //dcb_color_full(image2); + dcb_color_full(); + } + + + free(image2); + +} + diff --git a/Source/LibRawLite/internal/dcraw_common.cpp b/Source/LibRawLite/internal/dcraw_common.cpp index 04d77a1..20ed524 100644 --- a/Source/LibRawLite/internal/dcraw_common.cpp +++ b/Source/LibRawLite/internal/dcraw_common.cpp @@ -1,9445 +1,9445 @@ -/* - Copyright 2008-2010 LibRaw LLC (info@libraw.org) - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - - This file is generated from Dave Coffin's dcraw.c - dcraw.c -- Dave Coffin's raw photo decoder - Copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net - - Look into dcraw homepage (probably http://cybercom.net/~dcoffin/dcraw/) - for more information -*/ - -#include -#define CLASS LibRaw:: -#include "libraw/libraw_types.h" -#define LIBRAW_LIBRARY_BUILD -#define LIBRAW_IO_REDEFINED -#include "libraw/libraw.h" -#include "internal/defines.h" -#include "internal/var_defines.h" -#include "internal/libraw_bytebuffer.h" - -#ifndef __GLIBC__ -char *my_memmem (char *haystack, size_t haystacklen, - char *needle, size_t needlelen) -{ - char *c; - for (c = haystack; c <= haystack + haystacklen - needlelen; c++) - if (!memcmp (c, needle, needlelen)) - return c; - return 0; -} -#define memmem my_memmem -#endif - - -ushort CLASS sget2 (uchar *s) -{ - if (order == 0x4949) /* "II" means little-endian */ - return s[0] | s[1] << 8; - else /* "MM" means big-endian */ - return s[0] << 8 | s[1]; -} - -ushort CLASS get2() -{ - uchar str[2] = { 0xff,0xff }; - fread (str, 1, 2, ifp); - return sget2(str); -} - -unsigned CLASS sget4 (uchar *s) -{ - if (order == 0x4949) - return s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24; - else - return s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]; -} -#define sget4(s) sget4((uchar *)s) - -unsigned CLASS get4() -{ - uchar str[4] = { 0xff,0xff,0xff,0xff }; - fread (str, 1, 4, ifp); - return sget4(str); -} - -unsigned CLASS getint (int type) -{ - return type == 3 ? get2() : get4(); -} - -float CLASS int_to_float (int i) -{ - union { int i; float f; } u; - u.i = i; - return u.f; -} - -double CLASS getreal (int type) -{ - union { char c[8]; double d; } u; - int i, rev; - - switch (type) { - case 3: return (unsigned short) get2(); - case 4: return (unsigned int) get4(); - case 5: u.d = (unsigned int) get4(); - return u.d / (unsigned int) get4(); - case 8: return (signed short) get2(); - case 9: return (signed int) get4(); - case 10: u.d = (signed int) get4(); - return u.d / (signed int) get4(); - case 11: return int_to_float (get4()); - case 12: - rev = 7 * ((order == 0x4949) == (ntohs(0x1234) == 0x1234)); - for (i=0; i < 8; i++) - u.c[i ^ rev] = fgetc(ifp); - return u.d; - default: return fgetc(ifp); - } -} - -void CLASS read_shorts (ushort *pixel, int count) -{ - if (fread (pixel, 2, count, ifp) < count) derror(); - if ((order == 0x4949) == (ntohs(0x1234) == 0x1234)) - swab ((char*)pixel, (char*)pixel, count*2); -} - -#ifdef LIBRAW_LIBRARY_BUILD -#define RBAYER(x,y) raw_image[(x)*raw_width+(y)] -#define RRBAYER(x,y) raw_image[((x)+top_margin)*raw_width+(y)+left_margin] -#define CBAYER(x,y) color_image[((x)+top_margin)*raw_width+(y)+left_margin][FC((x),(y))] -#else -#define CBAYER(x,y) BAYER((x),(y)) -#define RBAYER(x,y) BAYER((x),(y)) -#define RRBAYER(x,y) BAYER((x),(y)) -#endif - -void CLASS canon_600_fixed_wb (int temp) -{ - static const short mul[4][5] = { - { 667, 358,397,565,452 }, - { 731, 390,367,499,517 }, - { 1119, 396,348,448,537 }, - { 1399, 485,431,508,688 } }; - int lo, hi, i; - float frac=0; - - for (lo=4; --lo; ) - if (*mul[lo] <= temp) break; - for (hi=0; hi < 3; hi++) - if (*mul[hi] >= temp) break; - if (lo != hi) - frac = (float) (temp - *mul[lo]) / (*mul[hi] - *mul[lo]); - for (i=1; i < 5; i++) - pre_mul[i-1] = 1 / (frac * mul[hi][i] + (1-frac) * mul[lo][i]); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.pre_mul_state = LIBRAW_COLORSTATE_CONST; -#endif -} - -/* Return values: 0 = white 1 = near white 2 = not white */ -int CLASS canon_600_color (int ratio[2], int mar) -{ - int clipped=0, target, miss; - - if (flash_used) { - if (ratio[1] < -104) - { ratio[1] = -104; clipped = 1; } - if (ratio[1] > 12) - { ratio[1] = 12; clipped = 1; } - } else { - if (ratio[1] < -264 || ratio[1] > 461) return 2; - if (ratio[1] < -50) - { ratio[1] = -50; clipped = 1; } - if (ratio[1] > 307) - { ratio[1] = 307; clipped = 1; } - } - target = flash_used || ratio[1] < 197 - ? -38 - (398 * ratio[1] >> 10) - : -123 + (48 * ratio[1] >> 10); - if (target - mar <= ratio[0] && - target + 20 >= ratio[0] && !clipped) return 0; - miss = target - ratio[0]; - if (abs(miss) >= mar*4) return 2; - if (miss < -20) miss = -20; - if (miss > mar) miss = mar; - ratio[0] = target - miss; - return 1; -} - -void CLASS canon_600_auto_wb() -{ - int mar, row, col, i, j, st, count[] = { 0,0 }; - int test[8], total[2][8], ratio[2][2], stat[2]; - - memset (&total, 0, sizeof total); - i = canon_ev + 0.5; - if (i < 10) mar = 150; - else if (i > 12) mar = 20; - else mar = 280 - 20 * i; - if (flash_used) mar = 80; - for (row=14; row < height-14; row+=4) - for (col=10; col < width; col+=2) { - for (i=0; i < 8; i++) - test[(i & 4) + FC(row+(i >> 1),col+(i & 1))] = - BAYER(row+(i >> 1),col+(i & 1)); - for (i=0; i < 8; i++) - if (test[i] < 150 || test[i] > 1500) goto next; - for (i=0; i < 4; i++) - if (abs(test[i] - test[i+4]) > 50) goto next; - for (i=0; i < 2; i++) { - for (j=0; j < 4; j+=2) - ratio[i][j >> 1] = ((test[i*4+j+1]-test[i*4+j]) << 10) / test[i*4+j]; - stat[i] = canon_600_color (ratio[i], mar); - } - if ((st = stat[0] | stat[1]) > 1) goto next; - for (i=0; i < 2; i++) - if (stat[i]) - for (j=0; j < 2; j++) - test[i*4+j*2+1] = test[i*4+j*2] * (0x400 + ratio[i][j]) >> 10; - for (i=0; i < 8; i++) - total[st][i] += test[i]; - count[st]++; -next: ; - } - if (count[0] | count[1]) { - st = count[0]*200 < count[1]; - for (i=0; i < 4; i++) - pre_mul[i] = 1.0 / (total[st][i] + total[st][i+4]); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.pre_mul_state = LIBRAW_COLORSTATE_CALCULATED; -#endif - } -} - -void CLASS canon_600_coeff() -{ - static const short table[6][12] = { - { -190,702,-1878,2390, 1861,-1349,905,-393, -432,944,2617,-2105 }, - { -1203,1715,-1136,1648, 1388,-876,267,245, -1641,2153,3921,-3409 }, - { -615,1127,-1563,2075, 1437,-925,509,3, -756,1268,2519,-2007 }, - { -190,702,-1886,2398, 2153,-1641,763,-251, -452,964,3040,-2528 }, - { -190,702,-1878,2390, 1861,-1349,905,-393, -432,944,2617,-2105 }, - { -807,1319,-1785,2297, 1388,-876,769,-257, -230,742,2067,-1555 } }; - int t=0, i, c; - float mc, yc; - - mc = pre_mul[1] / pre_mul[2]; - yc = pre_mul[3] / pre_mul[2]; - if (mc > 1 && mc <= 1.28 && yc < 0.8789) t=1; - if (mc > 1.28 && mc <= 2) { - if (yc < 0.8789) t=3; - else if (yc <= 2) t=4; - } - if (flash_used) t=5; - for (raw_color = i=0; i < 3; i++) - FORCC rgb_cam[i][c] = table[t][i*4 + c] / 1024.0; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.rgb_cam_state = LIBRAW_COLORSTATE_CALCULATED; -#endif -} - -void CLASS canon_600_load_raw() -{ - uchar data[1120], *dp; - ushort pixel[896], *pix; - int irow, row, col, val; - static const short mul[4][2] = - { { 1141,1145 }, { 1128,1109 }, { 1178,1149 }, { 1128,1109 } }; - - for (irow=row=0; irow < height; irow++) { - if (fread (data, 1, raw_width*5/4, ifp) < raw_width*5/4) derror(); - for (dp=data, pix=pixel; dp < data+1120; dp+=10, pix+=8) { - pix[0] = (dp[0] << 2) + (dp[1] >> 6 ); - pix[1] = (dp[2] << 2) + (dp[1] >> 4 & 3); - pix[2] = (dp[3] << 2) + (dp[1] >> 2 & 3); - pix[3] = (dp[4] << 2) + (dp[1] & 3); - pix[4] = (dp[5] << 2) + (dp[9] & 3); - pix[5] = (dp[6] << 2) + (dp[9] >> 2 & 3); - pix[6] = (dp[7] << 2) + (dp[9] >> 4 & 3); - pix[7] = (dp[8] << 2) + (dp[9] >> 6 ); - } -#ifndef LIBRAW_LIBRARY_BUILD - for (col=0; col < width; col++) - { - BAYER(row,col) = pixel[col]; - } -#else - for (col=0; col < raw_width; col++) - RBAYER(row,col) = pixel[col]; -#endif - - for (col=width; col < raw_width; col++) - { - black += pixel[col]; - } - if ((row+=2) > height) row = 1; - } - if (raw_width > width) - black = black / ((raw_width - width) * height) - 4; -#ifndef LIBRAW_LIBRARY_BUILD - for (row=0; row < height; row++) - for (col=0; col < width; col++) { - if ((val = BAYER(row,col) - black) < 0) val = 0; - val = val * mul[row & 3][col & 1] >> 9; - BAYER(row,col) = val; - } -#else - for (row=0; row < height; row++) - for (col=0; col < raw_width; col++) { - if ((val = RBAYER(row,col) - black) < 0) val = 0; - val = val * mul[row & 3][col & 1] >> 9; - RBAYER(row,col) = val; - } - -#endif - canon_600_fixed_wb(1311); - canon_600_auto_wb(); - canon_600_coeff(); - maximum = (0x3ff - black) * 1109 >> 9; - black = 0; -} - -void CLASS remove_zeroes() -{ - unsigned row, col, tot, n, r, c; - -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_REMOVE_ZEROES,0,2); -#endif - for (row=0; row < height; row++) - for (col=0; col < width; col++) - if (BAYER(row,col) == 0) { - tot = n = 0; - for (r = row-2; r <= row+2; r++) - for (c = col-2; c <= col+2; c++) - if (r < height && c < width && - FC(r,c) == FC(row,col) && BAYER(r,c)) - tot += (n++,BAYER(r,c)); - if (n) BAYER(row,col) = tot/n; - } -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_REMOVE_ZEROES,1,2); -#endif -} - -int CLASS canon_s2is() -{ - unsigned row; - - for (row=0; row < 100; row++) { - fseek (ifp, row*3340 + 3284, SEEK_SET); - if (getc(ifp) > 15) return 1; - } - return 0; -} - -/* - getbits(-1) initializes the buffer - getbits(n) where 0 <= n <= 25 returns an n-bit integer - */ - -unsigned CLASS getbithuff (int nbits, ushort *huff) -{ -#ifdef LIBRAW_NOTHREADS - static unsigned bitbuf=0; - static int vbits=0, reset=0; -#else -#define bitbuf tls->getbits.bitbuf -#define vbits tls->getbits.vbits -#define reset tls->getbits.reset -#endif - unsigned c; - - if (nbits == -1) - return bitbuf = vbits = reset = 0; - if (nbits == 0 || vbits < 0) return 0; - while (!reset && vbits < nbits && (c = fgetc(ifp)) != EOF && - !(reset = zero_after_ff && c == 0xff && fgetc(ifp))) { - bitbuf = (bitbuf << 8) + (uchar) c; - vbits += 8; - } - c = bitbuf << (32-vbits) >> (32-nbits); - if (huff) { - vbits -= huff[c] >> 8; - c = (uchar) huff[c]; - } else - vbits -= nbits; - if (vbits < 0) derror(); - return c; -#ifndef LIBRAW_NOTHREADS -#undef bitbuf -#undef vbits -#undef reset -#endif -} - -#define getbits(n) getbithuff(n,0) -#define gethuff(h) getbithuff(*h,h+1) - -/* - Construct a decode tree according to the specification in *source. - The first 16 bytes specify how many codes should be 1-bit, 2-bit - 3-bit, etc. Bytes after that are the leaf values. - - For example, if the source is - - { 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0, - 0x04,0x03,0x05,0x06,0x02,0x07,0x01,0x08,0x09,0x00,0x0a,0x0b,0xff }, - - then the code is - - 00 0x04 - 010 0x03 - 011 0x05 - 100 0x06 - 101 0x02 - 1100 0x07 - 1101 0x01 - 11100 0x08 - 11101 0x09 - 11110 0x00 - 111110 0x0a - 1111110 0x0b - 1111111 0xff - */ -ushort * CLASS make_decoder_ref (const uchar **source) -{ - int max, len, h, i, j; - const uchar *count; - ushort *huff; - - count = (*source += 16) - 17; - for (max=16; max && !count[max]; max--); - huff = (ushort *) calloc (1 + (1 << max), sizeof *huff); - merror (huff, "make_decoder()"); - huff[0] = max; - for (h=len=1; len <= max; len++) - for (i=0; i < count[len]; i++, ++*source) - for (j=0; j < 1 << (max-len); j++) - if (h <= 1 << max) - huff[h++] = len << 8 | **source; - return huff; -} - -ushort * CLASS make_decoder (const uchar *source) -{ - return make_decoder_ref (&source); -} - -void CLASS crw_init_tables (unsigned table, ushort *huff[2]) -{ - static const uchar first_tree[3][29] = { - { 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0, - 0x04,0x03,0x05,0x06,0x02,0x07,0x01,0x08,0x09,0x00,0x0a,0x0b,0xff }, - { 0,2,2,3,1,1,1,1,2,0,0,0,0,0,0,0, - 0x03,0x02,0x04,0x01,0x05,0x00,0x06,0x07,0x09,0x08,0x0a,0x0b,0xff }, - { 0,0,6,3,1,1,2,0,0,0,0,0,0,0,0,0, - - 0x06,0x05,0x07,0x04,0x08,0x03,0x09,0x02,0x00,0x0a,0x01,0x0b,0xff }, - }; - static const uchar second_tree[3][180] = { - { 0,2,2,2,1,4,2,1,2,5,1,1,0,0,0,139, - 0x03,0x04,0x02,0x05,0x01,0x06,0x07,0x08, - 0x12,0x13,0x11,0x14,0x09,0x15,0x22,0x00,0x21,0x16,0x0a,0xf0, - 0x23,0x17,0x24,0x31,0x32,0x18,0x19,0x33,0x25,0x41,0x34,0x42, - 0x35,0x51,0x36,0x37,0x38,0x29,0x79,0x26,0x1a,0x39,0x56,0x57, - 0x28,0x27,0x52,0x55,0x58,0x43,0x76,0x59,0x77,0x54,0x61,0xf9, - 0x71,0x78,0x75,0x96,0x97,0x49,0xb7,0x53,0xd7,0x74,0xb6,0x98, - 0x47,0x48,0x95,0x69,0x99,0x91,0xfa,0xb8,0x68,0xb5,0xb9,0xd6, - 0xf7,0xd8,0x67,0x46,0x45,0x94,0x89,0xf8,0x81,0xd5,0xf6,0xb4, - 0x88,0xb1,0x2a,0x44,0x72,0xd9,0x87,0x66,0xd4,0xf5,0x3a,0xa7, - 0x73,0xa9,0xa8,0x86,0x62,0xc7,0x65,0xc8,0xc9,0xa1,0xf4,0xd1, - 0xe9,0x5a,0x92,0x85,0xa6,0xe7,0x93,0xe8,0xc1,0xc6,0x7a,0x64, - 0xe1,0x4a,0x6a,0xe6,0xb3,0xf1,0xd3,0xa5,0x8a,0xb2,0x9a,0xba, - 0x84,0xa4,0x63,0xe5,0xc5,0xf3,0xd2,0xc4,0x82,0xaa,0xda,0xe4, - 0xf2,0xca,0x83,0xa3,0xa2,0xc3,0xea,0xc2,0xe2,0xe3,0xff,0xff }, - { 0,2,2,1,4,1,4,1,3,3,1,0,0,0,0,140, - 0x02,0x03,0x01,0x04,0x05,0x12,0x11,0x06, - 0x13,0x07,0x08,0x14,0x22,0x09,0x21,0x00,0x23,0x15,0x31,0x32, - 0x0a,0x16,0xf0,0x24,0x33,0x41,0x42,0x19,0x17,0x25,0x18,0x51, - 0x34,0x43,0x52,0x29,0x35,0x61,0x39,0x71,0x62,0x36,0x53,0x26, - 0x38,0x1a,0x37,0x81,0x27,0x91,0x79,0x55,0x45,0x28,0x72,0x59, - 0xa1,0xb1,0x44,0x69,0x54,0x58,0xd1,0xfa,0x57,0xe1,0xf1,0xb9, - 0x49,0x47,0x63,0x6a,0xf9,0x56,0x46,0xa8,0x2a,0x4a,0x78,0x99, - 0x3a,0x75,0x74,0x86,0x65,0xc1,0x76,0xb6,0x96,0xd6,0x89,0x85, - 0xc9,0xf5,0x95,0xb4,0xc7,0xf7,0x8a,0x97,0xb8,0x73,0xb7,0xd8, - 0xd9,0x87,0xa7,0x7a,0x48,0x82,0x84,0xea,0xf4,0xa6,0xc5,0x5a, - 0x94,0xa4,0xc6,0x92,0xc3,0x68,0xb5,0xc8,0xe4,0xe5,0xe6,0xe9, - 0xa2,0xa3,0xe3,0xc2,0x66,0x67,0x93,0xaa,0xd4,0xd5,0xe7,0xf8, - 0x88,0x9a,0xd7,0x77,0xc4,0x64,0xe2,0x98,0xa5,0xca,0xda,0xe8, - 0xf3,0xf6,0xa9,0xb2,0xb3,0xf2,0xd2,0x83,0xba,0xd3,0xff,0xff }, - { 0,0,6,2,1,3,3,2,5,1,2,2,8,10,0,117, - 0x04,0x05,0x03,0x06,0x02,0x07,0x01,0x08, - 0x09,0x12,0x13,0x14,0x11,0x15,0x0a,0x16,0x17,0xf0,0x00,0x22, - 0x21,0x18,0x23,0x19,0x24,0x32,0x31,0x25,0x33,0x38,0x37,0x34, - 0x35,0x36,0x39,0x79,0x57,0x58,0x59,0x28,0x56,0x78,0x27,0x41, - 0x29,0x77,0x26,0x42,0x76,0x99,0x1a,0x55,0x98,0x97,0xf9,0x48, - 0x54,0x96,0x89,0x47,0xb7,0x49,0xfa,0x75,0x68,0xb6,0x67,0x69, - 0xb9,0xb8,0xd8,0x52,0xd7,0x88,0xb5,0x74,0x51,0x46,0xd9,0xf8, - 0x3a,0xd6,0x87,0x45,0x7a,0x95,0xd5,0xf6,0x86,0xb4,0xa9,0x94, - 0x53,0x2a,0xa8,0x43,0xf5,0xf7,0xd4,0x66,0xa7,0x5a,0x44,0x8a, - 0xc9,0xe8,0xc8,0xe7,0x9a,0x6a,0x73,0x4a,0x61,0xc7,0xf4,0xc6, - 0x65,0xe9,0x72,0xe6,0x71,0x91,0x93,0xa6,0xda,0x92,0x85,0x62, - 0xf3,0xc5,0xb2,0xa4,0x84,0xba,0x64,0xa5,0xb3,0xd2,0x81,0xe5, - 0xd3,0xaa,0xc4,0xca,0xf2,0xb1,0xe4,0xd1,0x83,0x63,0xea,0xc3, - 0xe2,0x82,0xf1,0xa3,0xc2,0xa1,0xc1,0xe3,0xa2,0xe1,0xff,0xff } - }; - if (table > 2) table = 2; - huff[0] = make_decoder ( first_tree[table]); - huff[1] = make_decoder (second_tree[table]); -} - -/* - Return 0 if the image starts with compressed data, - 1 if it starts with uncompressed low-order bits. - - In Canon compressed data, 0xff is always followed by 0x00. - */ -int CLASS canon_has_lowbits() -{ - uchar test[0x4000]; - int ret=1; - unsigned i; - - fseek (ifp, 0, SEEK_SET); - fread (test, 1, sizeof test, ifp); - for (i=540; i < sizeof test - 1; i++) - if (test[i] == 0xff) { - if (test[i+1]) return 1; - ret=0; - } - return ret; -} - -void CLASS canon_compressed_load_raw() -{ - ushort *pixel, *prow, *huff[2]; - int nblocks, lowbits, i, c, row, r, col, save, val; - unsigned irow, icol; - int block, diffbuf[64], leaf, len, diff, carry=0, pnum=0, base[2]; - - crw_init_tables (tiff_compress, huff); - pixel = (ushort *) calloc (raw_width*8, sizeof *pixel); - merror (pixel, "canon_compressed_load_raw()"); - lowbits = canon_has_lowbits(); - if (!lowbits) maximum = 0x3ff; - fseek (ifp, 540 + lowbits*raw_height*raw_width/4, SEEK_SET); - zero_after_ff = 1; - getbits(-1); - for (row=0; row < raw_height; row+=8) { - nblocks = MIN (8, raw_height-row) * raw_width >> 6; - for (block=0; block < nblocks; block++) { - memset (diffbuf, 0, sizeof diffbuf); - for (i=0; i < 64; i++ ) { - leaf = gethuff(huff[i > 0]); - if (leaf == 0 && i) break; - if (leaf == 0xff) continue; - i += leaf >> 4; - len = leaf & 15; - if (len == 0) continue; - diff = getbits(len); - if ((diff & (1 << (len-1))) == 0) - diff -= (1 << len) - 1; - if (i < 64) diffbuf[i] = diff; - } - diffbuf[0] += carry; - carry = diffbuf[0]; - for (i=0; i < 64; i++ ) { - if (pnum++ % raw_width == 0) - base[0] = base[1] = 512; - if ((pixel[(block << 6) + i] = base[i & 1] += diffbuf[i]) >> 10) - derror(); - } - } - if (lowbits) { - save = ftell(ifp); - fseek (ifp, 26 + row*raw_width/4, SEEK_SET); - for (prow=pixel, i=0; i < raw_width*2; i++) { - c = fgetc(ifp); - for (r=0; r < 8; r+=2, prow++) { - val = (*prow << 2) + ((c >> r) & 3); - if (raw_width == 2672 && val < 512) val += 2; - *prow = val; - } - } - fseek (ifp, save, SEEK_SET); - } - -#ifdef LIBRAW_LIBRARY_BUILD - for (r=0; r < 8; r++) { - if(row+r>=raw_height) break; // Not sure that raw_height is always N*8 - // MOVE entire row into place - memmove(&raw_image[(row+r)*raw_width],&pixel[r*raw_width],raw_width*sizeof(pixel[0])); - - irow = row - top_margin + r; - if (irow >= height) continue; // if row above image area than irow is VERY positive :) - - // only margins! - for (col=0; col < left_margin; col++) - { - icol = col - left_margin; - c = FC(irow,icol); - if (icol >= width && col > 1 && (unsigned) (col-left_margin+2) > width+3) - cblack[c] += (cblack[4+c]++,pixel[r*raw_width+col]); - } - for (col=width+left_margin; col < raw_width; col++) - { - icol = col - left_margin; - c = FC(irow,icol); - if (icol >= width && col > 1 && (unsigned) (col-left_margin+2) > width+3) - cblack[c] += (cblack[4+c]++,pixel[r*raw_width+col]); - } - - } -#else - // dcraw original code - for (r=0; r < 8; r++) { - irow = row - top_margin + r; - if (irow >= height) continue; - for (col=0; col < raw_width; col++) { - icol = col - left_margin; - c = FC(irow,icol); - if (icol < width) - BAYER(irow,icol) = pixel[r*raw_width+col]; - else if (col > 1 && (unsigned) (col-left_margin+2) > width+3) - cblack[c] += (cblack[4+c]++,pixel[r*raw_width+col]); - } - } -#endif - } - free (pixel); - FORC(2) free (huff[c]); - FORC4 if (cblack[4+c]) cblack[c] /= cblack[4+c]; -} - -int CLASS ljpeg_start (struct jhead *jh, int info_only) -{ - int c, tag, len; - uchar data[0x10000]; - const uchar *dp; - - memset (jh, 0, sizeof *jh); - jh->restart = INT_MAX; - fread (data, 2, 1, ifp); - if (data[1] != 0xd8) return 0; - do { - fread (data, 2, 2, ifp); - tag = data[0] << 8 | data[1]; - len = (data[2] << 8 | data[3]) - 2; - if (tag <= 0xff00) return 0; - fread (data, 1, len, ifp); - switch (tag) { - case 0xffc3: - jh->sraw = ((data[7] >> 4) * (data[7] & 15) - 1) & 3; - case 0xffc0: - jh->bits = data[0]; - jh->high = data[1] << 8 | data[2]; - jh->wide = data[3] << 8 | data[4]; - jh->clrs = data[5] + jh->sraw; - if (len == 9 && !dng_version) getc(ifp); - break; - case 0xffc4: - if (info_only) break; - for (dp = data; dp < data+len && (c = *dp++) < 4; ) - jh->free[c] = jh->huff[c] = make_decoder_ref (&dp); - break; - case 0xffda: - jh->psv = data[1+data[0]*2]; - jh->bits -= data[3+data[0]*2] & 15; - break; - case 0xffdd: - jh->restart = data[0] << 8 | data[1]; - } - } while (tag != 0xffda); - if (info_only) return 1; - FORC(5) if (!jh->huff[c+1]) jh->huff[c+1] = jh->huff[c]; - if (jh->sraw) { - FORC(4) jh->huff[2+c] = jh->huff[1]; - FORC(jh->sraw) jh->huff[1+c] = jh->huff[0]; - } - jh->row = (ushort *) calloc (jh->wide*jh->clrs, 4); - merror (jh->row, "ljpeg_start()"); - return zero_after_ff = 1; -} - -void CLASS ljpeg_end (struct jhead *jh) -{ - int c; - FORC4 if (jh->free[c]) free (jh->free[c]); - free (jh->row); -} - -// used for kodak-262 decoder -int CLASS ljpeg_diff (ushort *huff) -{ - int len, diff; - - len = gethuff(huff); - if (len == 16 && (!dng_version || dng_version >= 0x1010000)) - return -32768; - diff = getbits(len); - if ((diff & (1 << (len-1))) == 0) - diff -= (1 << len) - 1; - return diff; -} - -#ifdef LIBRAW_LIBRARY_BUILD -int CLASS ljpeg_diff_new (LibRaw_bit_buffer& bits, LibRaw_byte_buffer* buf,ushort *huff) -{ - int len, diff; - - len = bits._gethuff_lj(buf,*huff,huff+1); - if (len == 16 && (!dng_version || dng_version >= 0x1010000)) - return -32768; - diff = bits._getbits_lj(buf,len); - if ((diff & (1 << (len-1))) == 0) - diff -= (1 << len) - 1; - return diff; -} - -int CLASS ljpeg_diff_pef (LibRaw_bit_buffer& bits, LibRaw_byte_buffer* buf,ushort *huff) -{ - int len, diff; - - len = bits._gethuff(buf,*huff,huff+1,zero_after_ff); - if (len == 16 && (!dng_version || dng_version >= 0x1010000)) - return -32768; - diff = bits._getbits(buf,len,zero_after_ff); - if ((diff & (1 << (len-1))) == 0) - diff -= (1 << len) - 1; - return diff; -} - - -#endif - - -ushort * CLASS ljpeg_row (int jrow, struct jhead *jh) -{ - int col, c, diff, pred, spred=0; - ushort mark=0, *row[3]; - - if (jrow * jh->wide % jh->restart == 0) { - FORC(6) jh->vpred[c] = 1 << (jh->bits-1); - if (jrow) { - fseek (ifp, -2, SEEK_CUR); - do mark = (mark << 8) + (c = fgetc(ifp)); - while (c != EOF && mark >> 4 != 0xffd); - } - getbits(-1); - } - FORC3 row[c] = jh->row + jh->wide*jh->clrs*((jrow+c) & 1); - for (col=0; col < jh->wide; col++) - FORC(jh->clrs) { - diff = ljpeg_diff (jh->huff[c]); - if (jh->sraw && c <= jh->sraw && (col | c)) - pred = spred; - else if (col) pred = row[0][-jh->clrs]; - else pred = (jh->vpred[c] += diff) - diff; - if (jrow && col) switch (jh->psv) { - case 1: break; - case 2: pred = row[1][0]; break; - case 3: pred = row[1][-jh->clrs]; break; - case 4: pred = pred + row[1][0] - row[1][-jh->clrs]; break; - case 5: pred = pred + ((row[1][0] - row[1][-jh->clrs]) >> 1); break; - case 6: pred = row[1][0] + ((pred - row[1][-jh->clrs]) >> 1); break; - case 7: pred = (pred + row[1][0]) >> 1; break; - default: pred = 0; - } - if ((**row = pred + diff) >> jh->bits) derror(); - if (c <= jh->sraw) spred = **row; - row[0]++; row[1]++; - } - return row[2]; -} - -#ifdef LIBRAW_LIBRARY_BUILD -ushort * CLASS ljpeg_row_new (int jrow, struct jhead *jh, LibRaw_bit_buffer& bits,LibRaw_byte_buffer* bytes) -{ - int col, c, diff, pred, spred=0; - ushort mark=0, *row[3]; - - if (jrow * jh->wide % jh->restart == 0) { - FORC(6) jh->vpred[c] = 1 << (jh->bits-1); - if (jrow) { - bytes->unseek2(); - do mark = (mark << 8) + (c = bytes->get_byte()); - while (c != EOF && mark >> 4 != 0xffd); - } - bits.reset(); - } - FORC3 row[c] = jh->row + jh->wide*jh->clrs*((jrow+c) & 1); - for (col=0; col < jh->wide; col++) - FORC(jh->clrs) { - diff = ljpeg_diff_new (bits,bytes,jh->huff[c]); - if (jh->sraw && c <= jh->sraw && (col | c)) - pred = spred; - else if (col) pred = row[0][-jh->clrs]; - else pred = (jh->vpred[c] += diff) - diff; - if (jrow && col) switch (jh->psv) { - case 1: break; - case 2: pred = row[1][0]; break; - case 3: pred = row[1][-jh->clrs]; break; - case 4: pred = pred + row[1][0] - row[1][-jh->clrs]; break; - case 5: pred = pred + ((row[1][0] - row[1][-jh->clrs]) >> 1); break; - case 6: pred = row[1][0] + ((pred - row[1][-jh->clrs]) >> 1); break; - case 7: pred = (pred + row[1][0]) >> 1; break; - default: pred = 0; - } - if ((**row = pred + diff) >> jh->bits) derror(); - if (c <= jh->sraw) spred = **row; - row[0]++; row[1]++; - } - return row[2]; -} - -#endif - -void CLASS lossless_jpeg_load_raw() -{ - int jwide, jrow, jcol, val, c, i, row=0, col=0; -#ifndef LIBRAW_LIBRARY_BUILD - int jidx,j; -#endif - struct jhead jh; - int min=INT_MAX; - ushort *rp; -#ifdef LIBRAW_LIBRARY_BUILD - int save_min = 0; - unsigned slicesW[16],slicesWcnt=0,slices; - unsigned *offset; - unsigned t_y=0,t_x=0,t_s=0,slice=0,pixelsInSlice,pixno; - if (!strcasecmp(make,"KODAK")) - save_min = 1; -#endif - -#ifdef LIBRAW_LIBRARY_BUILD - if (cr2_slice[0]>15) - throw LIBRAW_EXCEPTION_IO_EOF; // change many slices -#else - if (cr2_slice[0]>15) - { - fprintf(stderr,"Too many CR2 slices: %d\n",cr2_slice[0]+1); - return; - } -#endif - - - if (!ljpeg_start (&jh, 0)) return; - jwide = jh.wide * jh.clrs; - -#ifdef LIBRAW_LIBRARY_BUILD - if(cr2_slice[0]) - { - for(i=0;i= raw_width * raw_height) - throw LIBRAW_EXCEPTION_IO_BADFILE; - t_y++; - if(t_y == jh.high) - { - t_y = 0; - t_x += slicesW[t_s++]; - } - } - offset[slices] = offset[slices-1]; - slice = 1; // next slice - pixno = offset[0]; - pixelsInSlice = slicesW[0]; -#endif - -#ifdef LIBRAW_LIBRARY_BUILD - LibRaw_byte_buffer *buf=NULL; - if(data_size) - buf = ifp->make_byte_buffer(data_size); - LibRaw_bit_buffer bits; -#endif - for (jrow=0; jrow < jh.high; jrow++) { -#ifdef LIBRAW_LIBRARY_BUILD - if (buf) - rp = ljpeg_row_new (jrow, &jh,bits,buf); - else -#endif - rp = ljpeg_row (jrow, &jh); - - if (load_flags & 1) - row = jrow & 1 ? height-1-jrow/2 : jrow/2; - for (jcol=0; jcol < jwide; jcol++) { - val = *rp++; - if (jh.bits <= 12) - val = curve[val & 0xfff]; -#ifndef LIBRAW_LIBRARY_BUILD - // slow dcraw way to calculate row/col - if (cr2_slice[0]) { - jidx = jrow*jwide + jcol; - i = jidx / (cr2_slice[1]*jh.high); - if ((j = i >= cr2_slice[0])) - i = cr2_slice[0]; - jidx -= i * (cr2_slice[1]*jh.high); - row = jidx / cr2_slice[1+j]; - col = jidx % cr2_slice[1+j] + i*cr2_slice[1]; - } -#else - // new fast one, but for data_size defined only (i.e. new CR2 format, not 1D/1Ds) - if(buf) - { - if(!(load_flags & 1)) - row = pixno/raw_width; - col = pixno % raw_width; - pixno++; - if (0 == --pixelsInSlice) - { - unsigned o = offset[slice++]; - pixno = o & 0x0fffffff; - pixelsInSlice = slicesW[o>>28]; - } - } -#endif -#ifndef LIBRAW_LIBRARY_BUILD - - if (raw_width == 3984 && (col -= 2) < 0) - col += (row--,raw_width); - - if ((unsigned) (row-top_margin) < height) { - c = FC(row-top_margin,col-left_margin); - if ((unsigned) (col-left_margin) < width) { - BAYER(row-top_margin,col-left_margin) = val; - if (min > val) min = val; - } else if (col > 1 && (unsigned) (col-left_margin+2) > width+3) - cblack[c] += (cblack[4+c]++,val); - } -#else - if (raw_width == 3984) - { - if ( (col -= 2) < 0) - col += (row--,raw_width); - if(row >= 0 && row < raw_height && col >= 0 && col < raw_width) - RBAYER(row,col) = val; - } - else - RBAYER(row,col) = val; - - if ((unsigned) (row-top_margin) < height) - { - // within image height - if ((unsigned) (col-left_margin) < width) - { - // within image area, save min - if(save_min) - if (min > val) min = val; - } - else if (col > 1 && (unsigned) (col-left_margin+2) > width+3) - { - c = FC(row-top_margin,col-left_margin); - cblack[c] += (cblack[4+c]++,val); - } - } -#endif - -#ifndef LIBRAW_LIBRARY_BUILD - if (++col >= raw_width) - col = (row++,0); -#else - if(!buf) // 1D or 1Ds case - if (++col >= raw_width) - col = (row++,0); -#endif - } - } - ljpeg_end (&jh); - FORC4 if (cblack[4+c]) cblack[c] /= cblack[4+c]; - if (!strcasecmp(make,"KODAK")) - black = min; -#ifdef LIBRAW_LIBRARY_BUILD - if(buf) - delete buf; - free(offset); -#endif -} - -void CLASS canon_sraw_load_raw() -{ - struct jhead jh; - short *rp=0, (*ip)[4]; - int jwide, slice, scol, ecol, row, col, jrow=0, jcol=0, pix[3], c; - int v[3]={0,0,0}, ver, hue; - char *cp; - - if (!ljpeg_start (&jh, 0)) return; - jwide = (jh.wide >>= 1) * jh.clrs; - -#ifdef LIBRAW_LIBRARY_BUILD - if(!data_size) - throw LIBRAW_EXCEPTION_IO_BADFILE; - LibRaw_byte_buffer *buf = ifp->make_byte_buffer(data_size); - LibRaw_bit_buffer bits; -#endif - - - for (ecol=slice=0; slice <= cr2_slice[0]; slice++) { - scol = ecol; - ecol += cr2_slice[1] * 2 / jh.clrs; - if (!cr2_slice[0] || ecol > raw_width-1) ecol = raw_width & -2; - for (row=0; row < height; row += (jh.clrs >> 1) - 1) { - ip = (short (*)[4]) image + row*width; - for (col=scol; col < ecol; col+=2, jcol+=jh.clrs) { - if ((jcol %= jwide) == 0) -#ifdef LIBRAW_LIBRARY_BUILD - rp = (short*) ljpeg_row_new (jrow++, &jh,bits,buf); -#else - rp = (short *) ljpeg_row (jrow++, &jh); -#endif - if (col >= width) continue; - FORC (jh.clrs-2) - ip[col + (c >> 1)*width + (c & 1)][0] = rp[jcol+c]; - ip[col][1] = rp[jcol+jh.clrs-2] - 16384; - ip[col][2] = rp[jcol+jh.clrs-1] - 16384; - } - } - } - for (cp=model2; *cp && !isdigit(*cp); cp++); - sscanf (cp, "%d.%d.%d", v, v+1, v+2); - ver = (v[0]*1000 + v[1])*1000 + v[2]; - hue = (jh.sraw+1) << 2; - if (unique_id >= 0x80000281 || (unique_id == 0x80000218 && ver > 1000006)) - hue = jh.sraw << 1; - ip = (short (*)[4]) image; - rp = ip[0]; - for (row=0; row < height; row++, ip+=width) { - if (row & (jh.sraw >> 1)) - for (col=0; col < width; col+=2) - for (c=1; c < 3; c++) - if (row == height-1) - ip[col][c] = ip[col-width][c]; - else ip[col][c] = (ip[col-width][c] + ip[col+width][c] + 1) >> 1; - for (col=1; col < width; col+=2) - for (c=1; c < 3; c++) - if (col == width-1) - ip[col][c] = ip[col-1][c]; - else ip[col][c] = (ip[col-1][c] + ip[col+1][c] + 1) >> 1; - } - for ( ; rp < ip[0]; rp+=4) { -#if 1 - if (unique_id < 0x80000218) { - rp[0] -= 512; - goto next; - } else if (unique_id == 0x80000285) { -next: pix[0] = rp[0] + rp[2]; - pix[2] = rp[0] + rp[1]; - pix[1] = rp[0] + ((-778*rp[1] - (rp[2] << 11)) >> 12); - } else { - rp[1] = (rp[1] << 2) + hue; - rp[2] = (rp[2] << 2) + hue; - pix[0] = rp[0] + (( 50*rp[1] + 22929*rp[2]) >> 14); - pix[1] = rp[0] + ((-5640*rp[1] - 11751*rp[2]) >> 14); - pix[2] = rp[0] + ((29040*rp[1] - 101*rp[2]) >> 14); - } -#else - if (unique_id < 0x80000218) { - pix[0] = rp[0] + rp[2] - 512; - pix[2] = rp[0] + rp[1] - 512; - pix[1] = rp[0] + ((-778*rp[1] - (rp[2] << 11)) >> 12) - 512; - } else { - rp[1] = (rp[1] << 2) + hue; - rp[2] = (rp[2] << 2) + hue; - pix[0] = rp[0] + (( 50*rp[1] + 22929*rp[2]) >> 14); - pix[1] = rp[0] + ((-5640*rp[1] - 11751*rp[2]) >> 14); - pix[2] = rp[0] + ((29040*rp[1] - 101*rp[2]) >> 14); - } -#endif - FORC3 - rp[c] = CLIP(pix[c] * sraw_mul[c] >> 10); - } -#ifdef LIBRAW_LIBRARY_BUILD - delete buf; -#endif - ljpeg_end (&jh); - maximum = 0x3fff; -} - -void CLASS adobe_copy_pixel (int row, int col, ushort **rp) -{ - unsigned r, c; - -#ifndef LIBRAW_LIBRARY_BUILD - r = row -= top_margin; - c = col -= left_margin; - if (is_raw == 2 && shot_select) (*rp)++; - if (filters) { - if (fuji_width) { - r = row + fuji_width - 1 - (col >> 1); - c = row + ((col+1) >> 1); - } - if (r < height && c < width) - BAYER(r,c) = **rp < 0x1000 ? curve[**rp] : **rp; - *rp += is_raw; - } else { - if (r < height && c < width) - FORC(tiff_samples) - image[row*width+col][c] = (*rp)[c] < 0x1000 ? curve[(*rp)[c]]:(*rp)[c]; - *rp += tiff_samples; - } -#else - if (is_raw == 2 && shot_select) (*rp)++; - if (filters) { - if(row < raw_height && col < raw_width) - RBAYER(row,col) = **rp < 0x1000 ? curve[**rp] : **rp; - *rp += is_raw; - } else { - if (row < raw_height && col < raw_width) - FORC(tiff_samples) - color_image[row*raw_width+col][c] = (*rp)[c]<0x1000 ? curve[(*rp)[c]]:(*rp)[c]; - *rp += tiff_samples; - } - -#endif - if (is_raw == 2 && shot_select) (*rp)--; - -} - -void CLASS adobe_dng_load_raw_lj() -{ - unsigned save, trow=0, tcol=0, jwide, jrow, jcol, row, col; - struct jhead jh; - ushort *rp; - while (trow < raw_height) { - save = ftell(ifp); - if (tile_length < INT_MAX) - fseek (ifp, get4(), SEEK_SET); - if (!ljpeg_start (&jh, 0)) break; - jwide = jh.wide; - if (filters) jwide *= jh.clrs; - jwide /= is_raw; -#ifdef LIBRAW_LIBRARY_BUILD - if(!data_size) - throw LIBRAW_EXCEPTION_IO_BADFILE; - LibRaw_byte_buffer *buf = ifp->make_byte_buffer(data_size); - LibRaw_bit_buffer bits; -#endif - for (row=col=jrow=0; jrow < jh.high; jrow++) { -#ifdef LIBRAW_LIBRARY_BUILD - rp = ljpeg_row_new (jrow, &jh,bits,buf); -#else - rp = ljpeg_row (jrow, &jh); -#endif - for (jcol=0; jcol < jwide; jcol++) { - adobe_copy_pixel (trow+row, tcol+col, &rp); - if (++col >= tile_width || col >= raw_width) - row += 1 + (col = 0); - } - } - fseek (ifp, save+4, SEEK_SET); - if ((tcol += tile_width) >= raw_width) - trow += tile_length + (tcol = 0); - ljpeg_end (&jh); -#ifdef LIBRAW_LIBRARY_BUILD - delete buf; -#endif - } -} - -void CLASS adobe_dng_load_raw_nc() -{ - ushort *pixel, *rp; - int row, col; - - pixel = (ushort *) calloc (raw_width * tiff_samples, sizeof *pixel); - merror (pixel, "adobe_dng_load_raw_nc()"); - - -#ifdef LIBRAW_LIBRARY_BUILD - int dsz= raw_height*raw_width * tiff_samples * tiff_bps/8; - LibRaw_byte_buffer *buf = NULL; - if (tiff_bps != 16) - { - buf = ifp->make_byte_buffer(dsz); - } - LibRaw_bit_buffer bits; -#endif - - for (row=0; row < raw_height; row++) { - if (tiff_bps == 16) - read_shorts (pixel, raw_width * tiff_samples); - else { -#ifdef LIBRAW_LIBRARY_BUILD - bits.reset(); - for (col=0; col < raw_width * tiff_samples; col++) - pixel[col] = bits._getbits(buf,tiff_bps,zero_after_ff); - -#else - getbits(-1); - for (col=0; col < raw_width * tiff_samples; col++) - pixel[col] = getbits(tiff_bps); -#endif - } - for (rp=pixel, col=0; col < raw_width; col++) - adobe_copy_pixel (row, col, &rp); - } - free (pixel); -#ifdef LIBRAW_LIBRARY_BUILD - if(buf) - delete buf; -#endif -} - -void CLASS pentax_load_raw() -{ - ushort bit[2][15], huff[4097]; - int dep, row, col, diff, c, i; - ushort vpred[2][2] = {{0,0},{0,0}}, hpred[2]; - - fseek (ifp, meta_offset, SEEK_SET); - dep = (get2() + 12) & 15; - fseek (ifp, 12, SEEK_CUR); - FORC(dep) bit[0][c] = get2(); - FORC(dep) bit[1][c] = fgetc(ifp); - FORC(dep) - for (i=bit[0][c]; i <= ((bit[0][c]+(4096 >> bit[1][c])-1) & 4095); ) - huff[++i] = bit[1][c] << 8 | c; - huff[0] = 12; - fseek (ifp, data_offset, SEEK_SET); -#ifdef LIBRAW_LIBRARY_BUILD - if(!data_size) - throw LIBRAW_EXCEPTION_IO_BADFILE; - LibRaw_byte_buffer *buf = ifp->make_byte_buffer(data_size); - LibRaw_bit_buffer bits; - bits.reset(); -#else - getbits(-1); -#endif - for (row=0; row < raw_height; row++) - { - for (col=0; col < raw_width; col++) { -#ifdef LIBRAW_LIBRARY_BUILD - diff = ljpeg_diff_pef(bits,buf,huff); -#else - diff = ljpeg_diff (huff); -#endif - if (col < 2) hpred[col] = vpred[row & 1][col] += diff; - else hpred[col & 1] += diff; - - unsigned val = hpred[col & 1]; - -#ifndef LIBRAW_LIBRARY_BUILD - if ((unsigned) (row-top_margin) < height && - (unsigned)(col-left_margin) < width) - BAYER(row-top_margin,col-left_margin) = val; -#else - RBAYER(row,col) = val; -#endif - if (val >> tiff_bps) derror(); - } - } -#ifdef LIBRAW_LIBRARY_BUILD - delete buf; -#endif -} - -void CLASS nikon_compressed_load_raw() -{ - static const uchar nikon_tree[][32] = { - { 0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0, /* 12-bit lossy */ - 5,4,3,6,2,7,1,0,8,9,11,10,12 }, - { 0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0, /* 12-bit lossy after split */ - 0x39,0x5a,0x38,0x27,0x16,5,4,3,2,1,0,11,12,12 }, - { 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0, /* 12-bit lossless */ - 5,4,6,3,7,2,8,1,9,0,10,11,12 }, - { 0,1,4,3,1,1,1,1,1,2,0,0,0,0,0,0, /* 14-bit lossy */ - 5,6,4,7,8,3,9,2,1,0,10,11,12,13,14 }, - { 0,1,5,1,1,1,1,1,1,1,2,0,0,0,0,0, /* 14-bit lossy after split */ - 8,0x5c,0x4b,0x3a,0x29,7,6,5,4,3,2,1,0,13,14 }, - { 0,1,4,2,2,3,1,2,0,0,0,0,0,0,0,0, /* 14-bit lossless */ - 7,6,8,5,9,4,10,3,11,12,2,0,1,13,14 } }; - ushort *huff, ver0, ver1, vpred[2][2], hpred[2], csize; - int i, min, max, step=0, tree=0, split=0, row, col, len, shl, diff; - - fseek (ifp, meta_offset, SEEK_SET); - ver0 = fgetc(ifp); - ver1 = fgetc(ifp); - if (ver0 == 0x49 || ver1 == 0x58) - fseek (ifp, 2110, SEEK_CUR); - if (ver0 == 0x46) tree = 2; - if (tiff_bps == 14) tree += 3; - read_shorts (vpred[0], 4); - max = 1 << tiff_bps & 0x7fff; - if ((csize = get2()) > 1) - step = max / (csize-1); - if (ver0 == 0x44 && ver1 == 0x20 && step > 0) { - for (i=0; i < csize; i++) - curve[i*step] = get2(); - for (i=0; i < max; i++) - curve[i] = ( curve[i-i%step]*(step-i%step) + - curve[i-i%step+step]*(i%step) ) / step; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.curve_state = LIBRAW_COLORSTATE_LOADED; -#endif - fseek (ifp, meta_offset+562, SEEK_SET); - split = get2(); - } else if (ver0 != 0x46 && csize <= 0x4001) - { - read_shorts (curve, max=csize); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.curve_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - while (curve[max-2] == curve[max-1]) max--; - huff = make_decoder (nikon_tree[tree]); - fseek (ifp, data_offset, SEEK_SET); -#ifdef LIBRAW_LIBRARY_BUILD - if(!data_size) - throw LIBRAW_EXCEPTION_IO_BADFILE; - LibRaw_byte_buffer *buf = ifp->make_byte_buffer(data_size); - LibRaw_bit_buffer bits; - bits.reset(); -#else - getbits(-1); -#endif - for (min=row=0; row < height; row++) { - if (split && row == split) { - free (huff); - huff = make_decoder (nikon_tree[tree+1]); - max += (min = 16) << 1; - } - for (col=0; col < raw_width; col++) { -#ifdef LIBRAW_LIBRARY_BUILD - i = bits._gethuff(buf,*huff,huff+1,zero_after_ff); -#else - i = gethuff(huff); -#endif - len = i & 15; - shl = i >> 4; -#ifdef LIBRAW_LIBRARY_BUILD - diff = ((bits._getbits(buf,len-shl,zero_after_ff) << 1) + 1) << shl >> 1; -#else - diff = ((getbits(len-shl) << 1) + 1) << shl >> 1; -#endif - if ((diff & (1 << (len-1))) == 0) - diff -= (1 << len) - !shl; - if (col < 2) hpred[col] = vpred[row & 1][col] += diff; - else hpred[col & 1] += diff; - if ((ushort)(hpred[col & 1] + min) >= max) derror(); -#ifndef LIBRAW_LIBRARY_BUILD - if ((unsigned) (col-left_margin) < width) - BAYER(row,col-left_margin) = curve[LIM((short)hpred[col & 1],0,0x3fff)]; -#else - ushort xval = hpred[col & 1]; - xval = curve[LIM((short)xval,0,0x3fff)]; - RBAYER(row,col) = xval; -#endif - - } - } -#ifdef LIBRAW_LIBRARY_BUILD - delete buf; -#endif - free (huff); -} - -/* - Figure out if a NEF file is compressed. These fancy heuristics - are only needed for the D100, thanks to a bug in some cameras - that tags all images as "compressed". - */ -int CLASS nikon_is_compressed() -{ - uchar test[256]; - int i; - - fseek (ifp, data_offset, SEEK_SET); - fread (test, 1, 256, ifp); - for (i=15; i < 256; i+=16) - if (test[i]) return 1; - return 0; -} - -/* - Returns 1 for a Coolpix 995, 0 for anything else. - */ -int CLASS nikon_e995() -{ - int i, histo[256]; - const uchar often[] = { 0x00, 0x55, 0xaa, 0xff }; - - memset (histo, 0, sizeof histo); - fseek (ifp, -2000, SEEK_END); - for (i=0; i < 2000; i++) - histo[fgetc(ifp)]++; - for (i=0; i < 4; i++) - if (histo[often[i]] < 200) - return 0; - return 1; -} - -/* - Returns 1 for a Coolpix 2100, 0 for anything else. - */ -int CLASS nikon_e2100() -{ - uchar t[12]; - int i; - - fseek (ifp, 0, SEEK_SET); - for (i=0; i < 1024; i++) { - fread (t, 1, 12, ifp); - if (((t[2] & t[4] & t[7] & t[9]) >> 4 - & t[1] & t[6] & t[8] & t[11] & 3) != 3) - return 0; - } - return 1; -} - -void CLASS nikon_3700() -{ - int bits, i; - uchar dp[24]; - static const struct { - int bits; - char t_make[12], t_model[15]; - } table[] = { - { 0x00, "PENTAX", "Optio 33WR" }, - { 0x03, "NIKON", "E3200" }, - { 0x32, "NIKON", "E3700" }, - { 0x33, "OLYMPUS", "C740UZ" } }; - - fseek (ifp, 3072, SEEK_SET); - fread (dp, 1, 24, ifp); - bits = (dp[8] & 3) << 4 | (dp[20] & 3); - for (i=0; i < sizeof table / sizeof *table; i++) - if (bits == table[i].bits) { - strcpy (make, table[i].t_make ); - strcpy (model, table[i].t_model); - } -} - -/* - Separates a Minolta DiMAGE Z2 from a Nikon E4300. - */ -int CLASS minolta_z2() -{ - int i, nz; - char tail[424]; - - fseek (ifp, -sizeof tail, SEEK_END); - fread (tail, 1, sizeof tail, ifp); - for (nz=i=0; i < sizeof tail; i++) - if (tail[i]) nz++; - return nz > 20; -} - -/* - The Fuji Super CCD is just a Bayer grid rotated 45 degrees. - */ -void CLASS fuji_load_raw() -{ -#ifndef LIBRAW_LIBRARY_BUILD - ushort *pixel; - int wide, row, col, r, c; - - fseek (ifp, (top_margin*raw_width + left_margin) * 2, SEEK_CUR); - wide = fuji_width << !fuji_layout; - pixel = (ushort *) calloc (wide, sizeof *pixel); - merror (pixel, "fuji_load_raw()"); - for (row=0; row < raw_height; row++) { - read_shorts (pixel, wide); - fseek (ifp, 2*(raw_width - wide), SEEK_CUR); - for (col=0; col < wide; col++) { - if (fuji_layout) { - r = fuji_width - 1 - col + (row >> 1); - c = col + ((row+1) >> 1); - } else { - r = fuji_width - 1 + row - (col >> 1); - c = row + ((col+1) >> 1); - } - BAYER(r,c) = pixel[col]; - } - } - free (pixel); -#else - read_shorts(raw_image,raw_width*raw_height); -#endif -} -void CLASS ppm_thumb() -{ - char *thumb; - thumb_length = thumb_width*thumb_height*3; - thumb = (char *) malloc (thumb_length); - merror (thumb, "ppm_thumb()"); - fprintf (ofp, "P6\n%d %d\n255\n", thumb_width, thumb_height); - fread (thumb, 1, thumb_length, ifp); - fwrite (thumb, 1, thumb_length, ofp); - free (thumb); -} - -void CLASS layer_thumb() -{ - int i, c; - char *thumb, map[][4] = { "012","102" }; - - colors = thumb_misc >> 5 & 7; - thumb_length = thumb_width*thumb_height; - thumb = (char *) calloc (colors, thumb_length); - merror (thumb, "layer_thumb()"); - fprintf (ofp, "P%d\n%d %d\n255\n", - 5 + (colors >> 1), thumb_width, thumb_height); - fread (thumb, thumb_length, colors, ifp); - for (i=0; i < thumb_length; i++) - FORCC putc (thumb[i+thumb_length*(map[thumb_misc >> 8][c]-'0')], ofp); - free (thumb); -} - -void CLASS rollei_thumb() -{ - unsigned i; - ushort *thumb; - - thumb_length = thumb_width * thumb_height; - thumb = (ushort *) calloc (thumb_length, 2); - merror (thumb, "rollei_thumb()"); - fprintf (ofp, "P6\n%d %d\n255\n", thumb_width, thumb_height); - read_shorts (thumb, thumb_length); - for (i=0; i < thumb_length; i++) { - putc (thumb[i] << 3, ofp); - putc (thumb[i] >> 5 << 2, ofp); - putc (thumb[i] >> 11 << 3, ofp); - } - free (thumb); -} - -void CLASS rollei_load_raw() -{ - uchar pixel[10]; - unsigned iten=0, isix, i, buffer=0, row, col, todo[16]; - - isix = raw_width * raw_height * 5 / 8; - while (fread (pixel, 1, 10, ifp) == 10) { - for (i=0; i < 10; i+=2) { - todo[i] = iten++; - todo[i+1] = pixel[i] << 8 | pixel[i+1]; - buffer = pixel[i] >> 2 | buffer << 6; - } - for ( ; i < 16; i+=2) { - todo[i] = isix++; - todo[i+1] = buffer >> (14-i)*5; - } - for (i=0; i < 16; i+=2) { -#ifndef LIBRAW_LIBRARY_BUILD - row = todo[i] / raw_width - top_margin; - col = todo[i] % raw_width - left_margin; - if (row < height && col < width) - BAYER(row,col) = (todo[i+1] & 0x3ff); -#else - RBAYER(todo[i] / raw_width,todo[i] % raw_width) = (todo[i+1] & 0x3ff); -#endif - } - } - maximum = 0x3ff; -} - -int CLASS bayer (unsigned row, unsigned col) -{ - return (row < height && col < width) ? BAYER(row,col) : 0; -} - -void CLASS phase_one_flat_field (int is_float, int nc) -{ - ushort head[8]; - unsigned wide, y, x, c, rend, cend, row, col; - float *mrow, num, mult[4]; - - read_shorts (head, 8); - wide = head[2] / head[4]; - mrow = (float *) calloc (nc*wide, sizeof *mrow); - merror (mrow, "phase_one_flat_field()"); - for (y=0; y < head[3] / head[5]; y++) { - for (x=0; x < wide; x++) - for (c=0; c < nc; c+=2) { - num = is_float ? getreal(11) : get2()/32768.0; - if (y==0) mrow[c*wide+x] = num; - else mrow[(c+1)*wide+x] = (num - mrow[c*wide+x]) / head[5]; - } - if (y==0) continue; - rend = head[1]-top_margin + y*head[5]; - for (row = rend-head[5]; row < height && row < rend; row++) { - for (x=1; x < wide; x++) { - for (c=0; c < nc; c+=2) { - mult[c] = mrow[c*wide+x-1]; - mult[c+1] = (mrow[c*wide+x] - mult[c]) / head[4]; - } - cend = head[0]-left_margin + x*head[4]; - for (col = cend-head[4]; col < width && col < cend; col++) { - c = nc > 2 ? FC(row,col) : 0; - if (!(c & 1)) { - c = BAYER(row,col) * mult[c]; - BAYER(row,col) = LIM(c,0,65535); - } - for (c=0; c < nc; c+=2) - mult[c] += mult[c+1]; - } - } - for (x=0; x < wide; x++) - for (c=0; c < nc; c+=2) - mrow[c*wide+x] += mrow[(c+1)*wide+x]; - } - } - free (mrow); -} - -void CLASS phase_one_correct() -{ - unsigned entries, tag, data, save, col, row, type; - int len, i, j, k, cip, val[4], dev[4], sum, max; - int head[9], diff, mindiff=INT_MAX, off_412=0; - static const signed char dir[12][2] = - { {-1,-1}, {-1,1}, {1,-1}, {1,1}, {-2,0}, {0,-2}, {0,2}, {2,0}, - {-2,-2}, {-2,2}, {2,-2}, {2,2} }; - float poly[8], num, cfrac, frac, mult[2], *yval[2]; - ushort *xval[2]; - - if (half_size || !meta_length) return; -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("Phase One correction...\n")); -#endif - fseek (ifp, meta_offset, SEEK_SET); - order = get2(); - fseek (ifp, 6, SEEK_CUR); - fseek (ifp, meta_offset+get4(), SEEK_SET); - entries = get4(); get4(); - while (entries--) { - tag = get4(); - len = get4(); - data = get4(); - save = ftell(ifp); - fseek (ifp, meta_offset+data, SEEK_SET); - if (tag == 0x419) { /* Polynomial curve */ - for (get4(), i=0; i < 8; i++) - poly[i] = getreal(11); - poly[3] += (ph1.tag_210 - poly[7]) * poly[6] + 1; - for (i=0; i < 0x10000; i++) { - num = (poly[5]*i + poly[3])*i + poly[1]; - curve[i] = LIM(num,0,65535); - } goto apply; /* apply to right half */ - } else if (tag == 0x41a) { /* Polynomial curve */ - for (i=0; i < 4; i++) - poly[i] = getreal(11); - for (i=0; i < 0x10000; i++) { - for (num=0, j=4; j--; ) - num = num * i + poly[j]; - curve[i] = LIM(num+i,0,65535); - } apply: /* apply to whole image */ - for (row=0; row < height; row++) - for (col = (tag & 1)*ph1.split_col; col < width; col++) - BAYER(row,col) = curve[BAYER(row,col)]; - } else if (tag == 0x400) { /* Sensor defects */ - while ((len -= 8) >= 0) { - col = get2() - left_margin; - row = get2() - top_margin; - type = get2(); get2(); - if (col >= width) continue; - if (type == 131) /* Bad column */ - for (row=0; row < height; row++) - if (FC(row,col) == 1) { - for (sum=i=0; i < 4; i++) - sum += val[i] = bayer (row+dir[i][0], col+dir[i][1]); - for (max=i=0; i < 4; i++) { - dev[i] = abs((val[i] << 2) - sum); - if (dev[max] < dev[i]) max = i; - } - BAYER(row,col) = (sum - val[max])/3.0 + 0.5; - } else { - for (sum=0, i=8; i < 12; i++) - sum += bayer (row+dir[i][0], col+dir[i][1]); - BAYER(row,col) = 0.5 + sum * 0.0732233 + - (bayer(row,col-2) + bayer(row,col+2)) * 0.3535534; - } - else if (type == 129) { /* Bad pixel */ - if (row >= height) continue; - j = (FC(row,col) != 1) * 4; - for (sum=0, i=j; i < j+8; i++) - sum += bayer (row+dir[i][0], col+dir[i][1]); - BAYER(row,col) = (sum + 4) >> 3; - } - } - } else if (tag == 0x401) { /* All-color flat fields */ - phase_one_flat_field (1, 2); - } else if (tag == 0x416 || tag == 0x410) { - phase_one_flat_field (0, 2); - } else if (tag == 0x40b) { /* Red+blue flat field */ - phase_one_flat_field (0, 4); - } else if (tag == 0x412) { - fseek (ifp, 36, SEEK_CUR); - diff = abs (get2() - ph1.tag_21a); - if (mindiff > diff) { - mindiff = diff; - off_412 = ftell(ifp) - 38; - } - } - fseek (ifp, save, SEEK_SET); - } - if (off_412) { - fseek (ifp, off_412, SEEK_SET); - for (i=0; i < 9; i++) head[i] = get4() & 0x7fff; - yval[0] = (float *) calloc (head[1]*head[3] + head[2]*head[4], 6); - merror (yval[0], "phase_one_correct()"); - yval[1] = (float *) (yval[0] + head[1]*head[3]); - xval[0] = (ushort *) (yval[1] + head[2]*head[4]); - xval[1] = (ushort *) (xval[0] + head[1]*head[3]); - get2(); - for (i=0; i < 2; i++) - for (j=0; j < head[i+1]*head[i+3]; j++) - yval[i][j] = getreal(11); - for (i=0; i < 2; i++) - for (j=0; j < head[i+1]*head[i+3]; j++) - xval[i][j] = get2(); - for (row=0; row < height; row++) - for (col=0; col < width; col++) { - cfrac = (float) col * head[3] / raw_width; - cfrac -= cip = cfrac; - num = BAYER(row,col) * 0.5; - for (i=cip; i < cip+2; i++) { - for (k=j=0; j < head[1]; j++) - if (num < xval[0][k = head[1]*i+j]) break; - frac = (j == 0 || j == head[1]) ? 0 : - (xval[0][k] - num) / (xval[0][k] - xval[0][k-1]); - mult[i-cip] = yval[0][k-1] * frac + yval[0][k] * (1-frac); - } - i = ((mult[0] * (1-cfrac) + mult[1] * cfrac) - * (row + top_margin) + num) * 2; - BAYER(row,col) = LIM(i,0,65535); - } - free (yval[0]); - } -} - -void CLASS phase_one_load_raw() -{ - int row, col, a, b; - ushort *pixel, akey, bkey, mask; - - fseek (ifp, ph1.key_off, SEEK_SET); - akey = get2(); - bkey = get2(); - mask = ph1.format == 1 ? 0x5555:0x1354; -#ifndef LIBRAW_LIBRARY_BUILD - fseek (ifp, data_offset + top_margin*raw_width*2, SEEK_SET); - pixel = (ushort *) calloc (raw_width, sizeof *pixel); - merror (pixel, "phase_one_load_raw()"); - for (row=0; row < height; row++) { - read_shorts (pixel, raw_width); - if (ph1.format) - for (col=0; col < raw_width; col+=2) { - a = pixel[col+0] ^ akey; - b = pixel[col+1] ^ bkey; - pixel[col+0] = (a & mask) | (b & ~mask); - pixel[col+1] = (b & mask) | (a & ~mask); - } - for (col=0; col < width; col++) - BAYER(row,col) = pixel[col+left_margin]; - } - free (pixel); - phase_one_correct(); -#else - fseek (ifp, data_offset, SEEK_SET); - pixel = (ushort *) calloc (raw_width, sizeof *pixel); - merror (pixel, "phase_one_load_raw()"); - for (row=0; row < raw_height; row++) { - read_shorts (pixel, raw_width); - if (ph1.format) - for (col=0; col < raw_width; col+=2) { - a = pixel[col+0] ^ akey; - b = pixel[col+1] ^ bkey; - pixel[col+0] = (a & mask) | (b & ~mask); - pixel[col+1] = (b & mask) | (a & ~mask); - } - memmove(&raw_image[row*raw_width],pixel,raw_width*sizeof(pixel[0])); - } - free (pixel); - // use correct on postprocessing! - imgdata.rawdata.use_ph1_correct=1; -#endif -} - -unsigned CLASS ph1_bithuff (int nbits, ushort *huff) -{ -#ifndef LIBRAW_NOTHREADS -#define bitbuf tls->ph1_bits.bitbuf -#define vbits tls->ph1_bits.vbits -#else - static UINT64 bitbuf=0; - static int vbits=0; -#endif - unsigned c; - - if (nbits == -1) - return bitbuf = vbits = 0; - if (nbits == 0) return 0; - if (vbits < nbits) { - bitbuf = bitbuf << 32 | get4(); - vbits += 32; - } - c = bitbuf << (64-vbits) >> (64-nbits); - if (huff) { - vbits -= huff[c] >> 8; - return (uchar) huff[c]; - } - vbits -= nbits; - return c; -#ifndef LIBRAW_NOTHREADS -#undef bitbuf -#undef vbits -#endif -} -#define ph1_bits(n) ph1_bithuff(n,0) -#define ph1_huff(h) ph1_bithuff(*h,h+1) - -void CLASS phase_one_load_raw_c() -{ - static const int length[] = { 8,7,6,9,11,10,5,12,14,13 }; - int *offset, len[2], pred[2], row, col, i, j; - ushort *pixel; - short (*t_black)[2]; - - pixel = (ushort *) calloc (raw_width + raw_height*4, 2); - merror (pixel, "phase_one_load_raw_c()"); - offset = (int *) (pixel + raw_width); - fseek (ifp, strip_offset, SEEK_SET); - for (row=0; row < raw_height; row++) - offset[row] = get4(); - t_black = (short (*)[2]) offset + raw_height; - fseek (ifp, ph1.black_off, SEEK_SET); - if (ph1.black_off) - { - read_shorts ((ushort *) t_black[0], raw_height*2); -#ifdef LIBRAW_LIBRARY_BUILD - imgdata.rawdata.ph1_black = (short (*)[2])calloc(raw_height*2,sizeof(short)); - merror (imgdata.rawdata.ph1_black, "phase_one_load_raw_c()"); - memmove(imgdata.rawdata.ph1_black,(short *) t_black[0],raw_height*2*sizeof(short)); -#endif - } - for (i=0; i < 256; i++) - curve[i] = i*i / 3.969 + 0.5; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.curve_state = LIBRAW_COLORSTATE_CALCULATED; -#endif - for (row=0; row < raw_height; row++) { - fseek (ifp, data_offset + offset[row], SEEK_SET); - ph1_bits(-1); - pred[0] = pred[1] = 0; - for (col=0; col < raw_width; col++) { - if (col >= (raw_width & -8)) - len[0] = len[1] = 14; - else if ((col & 7) == 0) - for (i=0; i < 2; i++) { - for (j=0; j < 5 && !ph1_bits(1); j++); - if (j--) len[i] = length[j*2 + ph1_bits(1)]; - } - if ((i = len[col & 1]) == 14) - pixel[col] = pred[col & 1] = ph1_bits(16); - else - pixel[col] = pred[col & 1] += ph1_bits(i) + 1 - (1 << (i - 1)); - if (pred[col & 1] >> 16) derror(); - if (ph1.format == 5 && pixel[col] < 256) - pixel[col] = curve[pixel[col]]; - } -#ifndef LIBRAW_LIBRARY_BUILD - if ((unsigned) (row-top_margin) < height) - for (col=0; col < width; col++) { - i = (pixel[col+left_margin] << 2) - - ph1.t_black + t_black[row][col >= ph1.split_col]; - if (i > 0) BAYER(row-top_margin,col) = i; - } -#else - for (col=0; col < raw_width; col++) - { - i = (pixel[col] << 2); - RBAYER(row,col) = i; - } -#endif - } - free (pixel); -#ifndef LIBRAW_LIBRARY_BUILD - phase_one_correct(); - maximum = 0xfffc - ph1.t_black; -#else - maximum = 0xfffc; - black = ph1.t_black; -#endif -} - -void CLASS hasselblad_load_raw() -{ - struct jhead jh; - int row, col, pred[2], len[2], diff, c; - - if (!ljpeg_start (&jh, 0)) return; - order = 0x4949; - ph1_bits(-1); -#ifndef LIBRAW_LIBRARY_BUILD - for (row=-top_margin; row < height; row++) { - pred[0] = pred[1] = 0x8000 + load_flags; - for (col=-left_margin; col < raw_width-left_margin; col+=2) { - FORC(2) len[c] = ph1_huff(jh.huff[0]); - FORC(2) { - diff = ph1_bits(len[c]); - if ((diff & (1 << (len[c]-1))) == 0) - diff -= (1 << len[c]) - 1; - if (diff == 65535) diff = -32768; - pred[c] += diff; - if (row >= 0 && (unsigned)(col+c) < width) - BAYER(row,col+c) = pred[c]; - } - } - } -#else - for (row=0; row < raw_height; row++) { - pred[0] = pred[1] = 0x8000 + load_flags; - for (col=0; col < raw_width; col+=2) { - FORC(2) len[c] = ph1_huff(jh.huff[0]); - FORC(2) { - diff = ph1_bits(len[c]); - if ((diff & (1 << (len[c]-1))) == 0) - diff -= (1 << len[c]) - 1; - if (diff == 65535) diff = -32768; - pred[c] += diff; - RBAYER(row,col+c) = pred[c]; - } - } - } - -#endif - ljpeg_end (&jh); - maximum = 0xffff; -} - -void CLASS leaf_hdr_load_raw() -{ - ushort *pixel; - unsigned tile=0, r, c, row, col; - - pixel = (ushort *) calloc (raw_width, sizeof *pixel); - merror (pixel, "leaf_hdr_load_raw()"); - FORC(tiff_samples) - for (r=0; r < raw_height; r++) { - if (r % tile_length == 0) { - fseek (ifp, data_offset + 4*tile++, SEEK_SET); - fseek (ifp, get4() + 2*left_margin, SEEK_SET); - } - if (filters && c != shot_select) continue; - read_shorts (pixel, raw_width); -#ifndef LIBRAW_LIBRARY_BUILD - if ((row = r - top_margin) >= height) continue; - for (col=0; col < width; col++) - if (filters) BAYER(row,col) = pixel[col]; - else image[row*width+col][c] = pixel[col]; -#else - if(filters) - memmove(&raw_image[r*raw_width],pixel,raw_width*sizeof(pixel[0])); - else - for (col=0; col < raw_width; col++) - color_image[r*raw_width+col][c] = pixel[col]; -#endif - } - free (pixel); - if (!filters) { - maximum = 0xffff; - raw_color = 1; - } -} - -void CLASS sinar_4shot_load_raw() -{ - ushort *pixel; - unsigned shot, row, col, r, c; - - if ((shot = shot_select) || half_size) { - if (shot) shot--; - if (shot > 3) shot = 3; - fseek (ifp, data_offset + shot*4, SEEK_SET); - fseek (ifp, get4(), SEEK_SET); - unpacked_load_raw(); - return; - } - free (image); - image = (ushort (*)[4]) - calloc ((iheight=height)*(iwidth=width), sizeof *image); - merror (image, "sinar_4shot_load_raw()"); - pixel = (ushort *) calloc (raw_width, sizeof *pixel); - merror (pixel, "sinar_4shot_load_raw()"); - for (shot=0; shot < 4; shot++) { - fseek (ifp, data_offset + shot*4, SEEK_SET); - fseek (ifp, get4(), SEEK_SET); -#ifndef LIBRAW_LIBRARY_BUILD - for (row=0; row < raw_height; row++) { - read_shorts (pixel, raw_width); - if ((r = row-top_margin - (shot >> 1 & 1)) >= height) continue; - for (col=0; col < raw_width; col++) { - if ((c = col-left_margin - (shot & 1)) >= width) continue; - image[r*width+c][FC(row,col)] = pixel[col]; - } - } -#else - for (row=0; row < raw_height; row++) { - read_shorts (pixel, raw_width); - if ((r = row - (shot >> 1 & 1)) >= raw_height) continue; - for (col=0; col < raw_width; col++) { - if ((c = col- (shot & 1)) >= raw_width) continue; - color_image[r*width+c][FC(row,col)] = pixel[col]; - } - } -#endif - } - free (pixel); - shrink = filters = 0; -} - -void CLASS imacon_full_load_raw() -{ - int row, col; - -#ifndef LIBRAW_LIBRARY_BUILD - for (row=0; row < height; row++) - for (col=0; col < width; col++) - { - read_shorts (image[row*width+col], 3); - } -#else - for (row=0; row < height; row++) - for (col=0; col < width; col++) - { - read_shorts (color_image[(row+top_margin)*raw_width+col+left_margin], 3); - } -#endif -} - -void CLASS packed_load_raw() -{ - int vbits=0, bwide, pwide, rbits, bite, half, irow, row, col, val, i; - int zero=0; - UINT64 bitbuf=0; - - if (raw_width * 8 >= width * tiff_bps) /* Is raw_width in bytes? */ - pwide = (bwide = raw_width) * 8 / tiff_bps; - else bwide = (pwide = raw_width) * tiff_bps / 8; - rbits = bwide * 8 - pwide * tiff_bps; - if (load_flags & 1) bwide = bwide * 16 / 15; - fseek (ifp, top_margin*bwide, SEEK_CUR); - bite = 8 + (load_flags & 24); - half = (height+1) >> 1; - for (irow=0; irow < height; irow++) - { - row = irow; - if (load_flags & 2 && - (row = irow % half * 2 + irow / half) == 1 && - load_flags & 4) { - if (vbits=0, tiff_compress) - fseek (ifp, data_offset - (-half*bwide & -2048), SEEK_SET); - else { - fseek (ifp, 0, SEEK_END); - fseek (ifp, ftell(ifp) >> 3 << 2, SEEK_SET); - } - } - for (col=0; col < pwide; col++) { - for (vbits -= tiff_bps; vbits < 0; vbits += bite) { - bitbuf <<= bite; - for (i=0; i < bite; i+=8) - bitbuf |= (unsigned) (fgetc(ifp) << i); - } - val = bitbuf << (64-tiff_bps-vbits) >> (64-tiff_bps); - i = (col ^ (load_flags >> 6)) - left_margin; -#ifdef LIBRAW_LIBRARY_BUILD - RBAYER(row+top_margin,i+left_margin) = val; - if (((unsigned)i>=width) && (load_flags & 32) ) { - black += val; - zero += !val; - } -#else - if ((unsigned) i < width) - BAYER(row,i+left_margin) = val; - else if (load_flags & 32) { - black += val; - zero += !val; - } -#endif - if (load_flags & 1 && (col % 10) == 9 && - fgetc(ifp) && col < width+left_margin) derror(); - } - vbits -= rbits; - } - if (load_flags & 32 && pwide > width) - black /= (pwide - width) * height; - if (zero*4 > (pwide - width) * height) - black = 0; -} - -void CLASS unpacked_load_raw() -{ - ushort *pixel; - int row, col, bits=0; - - while (1 << ++bits < maximum); -#ifndef LIBRAW_LIBRARY_BUILD - fseek (ifp, (top_margin*raw_width + left_margin) * 2, SEEK_CUR); - pixel = (ushort *) calloc (width, sizeof *pixel); - merror (pixel, "unpacked_load_raw()"); - for (row=0; row < height; row++) { - read_shorts (pixel, width); - fseek (ifp, 2*(raw_width - width), SEEK_CUR); - for (col=0; col < width; col++) - if ((BAYER2(row,col) = pixel[col] >> load_flags) >> bits) derror(); - } - free (pixel); -#else - // fseek (ifp, (top_margin*raw_width + left_margin) * 2, SEEK_CUR); - pixel = (ushort *) calloc (raw_width, sizeof *pixel); - merror (pixel, "unpacked_load_raw()"); - for (row=0; row < raw_height; row++) { - read_shorts (pixel, raw_width); - for (col=0; col < raw_width; col++) - { - RBAYER(row,col) = pixel[col]>>load_flags; - if( ((unsigned)(row-top_margin) < height) - && ((unsigned)(col-left_margin)>bits) - derror(); - } - } - free (pixel); -#endif -} - -void CLASS nokia_load_raw() -{ - uchar *data, *dp; - ushort *pixel, *pix; - int rev, dwide, row, c; - - rev = 3 * (order == 0x4949); - dwide = raw_width * 5 / 4; - data = (uchar *) malloc (dwide + raw_width*2); - merror (data, "nokia_load_raw()"); - pixel = (ushort *) (data + dwide); - for (row=0; row < raw_height; row++) { - if (fread (data+dwide, 1, dwide, ifp) < dwide) derror(); - FORC(dwide) data[c] = data[dwide+(c ^ rev)]; - for (dp=data, pix=pixel; pix < pixel+raw_width; dp+=5, pix+=4) - FORC4 pix[c] = (dp[c] << 2) | (dp[4] >> (c << 1) & 3); - if (row < top_margin) - FORC(width) black += pixel[c]; -#ifndef LIBRAW_LIBRARY_BUILD - else - FORC(width) BAYER(row-top_margin,c) = pixel[c]; -#else - memmove(&raw_image[row*raw_width],pixel,width*sizeof(pixel[0])); -#endif - } - free (data); - if (top_margin) black /= top_margin * width; - maximum = 0x3ff; -} - -unsigned CLASS pana_bits (int nbits) -{ -#ifndef LIBRAW_NOTHREADS -#define buf tls->pana_bits.buf -#define vbits tls->pana_bits.vbits -#else - static uchar buf[0x4000]; - static int vbits; -#endif - int byte; - - if (!nbits) return vbits=0; - if (!vbits) { - fread (buf+load_flags, 1, 0x4000-load_flags, ifp); - fread (buf, 1, load_flags, ifp); - } - vbits = (vbits - nbits) & 0x1ffff; - byte = vbits >> 3 ^ 0x3ff0; - return (buf[byte] | buf[byte+1] << 8) >> (vbits & 7) & ~(-1 << nbits); -#ifndef LIBRAW_NOTHREADS -#undef buf -#undef vbits -#endif -} - -void CLASS panasonic_load_raw() -{ - int row, col, i, j, sh=0, pred[2], nonz[2]; - - pana_bits(0); - for (row=0; row < height; row++) - for (col=0; col < raw_width; col++) { - if ((i = col % 14) == 0) - pred[0] = pred[1] = nonz[0] = nonz[1] = 0; - if (i % 3 == 2) sh = 4 >> (3 - pana_bits(2)); - if (nonz[i & 1]) { - if ((j = pana_bits(8))) { - if ((pred[i & 1] -= 0x80 << sh) < 0 || sh == 4) - pred[i & 1] &= ~(-1 << sh); - pred[i & 1] += j << sh; - } - } else if ((nonz[i & 1] = pana_bits(8)) || i > 11) - pred[i & 1] = nonz[i & 1] << 4 | pana_bits(4); -#ifndef LIBRAW_LIBRARY_BUILD - if (col < width) - if ((BAYER(row,col) = pred[col & 1]) > 4098) derror(); -#else - RBAYER(row,col) = pred[col & 1]; - if (col < width) - if (RBAYER(row,col) > 4098) derror(); -#endif - } -} - - -void CLASS olympus_load_raw() -{ - ushort huff[4096]; - int row, col, nbits, sign, low, high, i, c, w, n, nw; - int acarry[2][3], *carry, pred, diff; - - huff[n=0] = 0xc0c; - for (i=12; i--; ) - FORC(2048 >> i) huff[++n] = (i+1) << 8 | i; - fseek (ifp, 7, SEEK_CUR); -#ifdef LIBRAW_LIBRARY_BUILD - if(!data_size) - throw LIBRAW_EXCEPTION_IO_BADFILE; - LibRaw_byte_buffer *buf = ifp->make_byte_buffer(data_size); - LibRaw_bit_buffer bits; - bits.reset(); -#else - getbits(-1); -#endif - for (row=0; row < height; row++) { - memset (acarry, 0, sizeof acarry); - for (col=0; col < raw_width; col++) { - carry = acarry[col & 1]; - i = 2 * (carry[2] < 3); - for (nbits=2+i; (ushort) carry[0] >> (nbits+i); nbits++); -#ifdef LIBRAW_LIBRARY_BUILD - low = (sign = bits._getbits(buf,3,zero_after_ff)) & 3; - sign = sign << 29 >> 31; - if ((high = bits._gethuff(buf,12,huff,zero_after_ff)) == 12) - high = bits._getbits(buf,16-nbits,zero_after_ff) >> 1; - carry[0] = (high << nbits) | bits._getbits(buf,nbits,zero_after_ff); -#else - low = (sign = getbits(3)) & 3; - sign = sign << 29 >> 31; - if ((high = getbithuff(12,huff)) == 12) - high = getbits(16-nbits) >> 1; - carry[0] = (high << nbits) | getbits(nbits); -#endif - diff = (carry[0] ^ sign) + carry[1]; - carry[1] = (diff*3 + carry[1]) >> 5; - carry[2] = carry[0] > 16 ? 0 : carry[2]+1; - if (col >= width) continue; - if (row < 2 && col < 2) pred = 0; - else if (row < 2) pred = RBAYER(row,col-2); - else if (col < 2) pred = RBAYER(row-2,col); - else { - w = RBAYER(row,col-2); - n = RBAYER(row-2,col); - nw = RBAYER(row-2,col-2); - if ((w < nw && nw < n) || (n < nw && nw < w)) { - if (ABS(w-nw) > 32 || ABS(n-nw) > 32) - pred = w + n - nw; - else pred = (w + n) >> 1; - } else pred = ABS(w-nw) > ABS(n-nw) ? w : n; - } - if ((RBAYER(row,col) = pred + ((diff << 2) | low)) >> 12) derror(); - } - } -#ifdef LIBRAW_LIBRARY_BUILD - delete buf; -#endif -} - - -void CLASS minolta_rd175_load_raw() -{ - uchar pixel[768]; - unsigned irow, box, row, col; - - for (irow=0; irow < 1481; irow++) { - if (fread (pixel, 1, 768, ifp) < 768) derror(); - box = irow / 82; - row = irow % 82 * 12 + ((box < 12) ? box | 1 : (box-12)*2); - switch (irow) { - case 1477: case 1479: continue; - case 1476: row = 984; break; - case 1480: row = 985; break; - case 1478: row = 985; box = 1; - } - if ((box < 12) && (box & 1)) { - for (col=0; col < 1533; col++, row ^= 1) - if (col != 1) RRBAYER(row,col) = (col+1) & 2 ? - pixel[col/2-1] + pixel[col/2+1] : pixel[col/2] << 1; - RRBAYER(row,1) = pixel[1] << 1; - RRBAYER(row,1533) = pixel[765] << 1; - } else - for (col=row & 1; col < 1534; col+=2) - RRBAYER(row,col) = pixel[col/2] << 1; - } - maximum = 0xff << 1; -} - -void CLASS quicktake_100_load_raw() -{ - uchar pixel[484][644]; - static const short gstep[16] = - { -89,-60,-44,-32,-22,-15,-8,-2,2,8,15,22,32,44,60,89 }; - static const short rstep[6][4] = - { { -3,-1,1,3 }, { -5,-1,1,5 }, { -8,-2,2,8 }, - { -13,-3,3,13 }, { -19,-4,4,19 }, { -28,-6,6,28 } }; - static const short t_curve[256] = - { 0,1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27, - 28,29,30,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,53, - 54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,74,75,76,77,78, - 79,80,81,82,83,84,86,88,90,92,94,97,99,101,103,105,107,110,112,114,116, - 118,120,123,125,127,129,131,134,136,138,140,142,144,147,149,151,153,155, - 158,160,162,164,166,168,171,173,175,177,179,181,184,186,188,190,192,195, - 197,199,201,203,205,208,210,212,214,216,218,221,223,226,230,235,239,244, - 248,252,257,261,265,270,274,278,283,287,291,296,300,305,309,313,318,322, - 326,331,335,339,344,348,352,357,361,365,370,374,379,383,387,392,396,400, - 405,409,413,418,422,426,431,435,440,444,448,453,457,461,466,470,474,479, - 483,487,492,496,500,508,519,531,542,553,564,575,587,598,609,620,631,643, - 654,665,676,687,698,710,721,732,743,754,766,777,788,799,810,822,833,844, - 855,866,878,889,900,911,922,933,945,956,967,978,989,1001,1012,1023 }; - int rb, row, col, sharp, val=0; - - getbits(-1); - memset (pixel, 0x80, sizeof pixel); - for (row=2; row < height+2; row++) { - for (col=2+(row & 1); col < width+2; col+=2) { - val = ((pixel[row-1][col-1] + 2*pixel[row-1][col+1] + - pixel[row][col-2]) >> 2) + gstep[getbits(4)]; - pixel[row][col] = val = LIM(val,0,255); - if (col < 4) - pixel[row][col-2] = pixel[row+1][~row & 1] = val; - if (row == 2) - pixel[row-1][col+1] = pixel[row-1][col+3] = val; - } - pixel[row][col] = val; - } - for (rb=0; rb < 2; rb++) - for (row=2+rb; row < height+2; row+=2) - for (col=3-(row & 1); col < width+2; col+=2) { - if (row < 4 || col < 4) sharp = 2; - else { - val = ABS(pixel[row-2][col] - pixel[row][col-2]) - + ABS(pixel[row-2][col] - pixel[row-2][col-2]) - + ABS(pixel[row][col-2] - pixel[row-2][col-2]); - sharp = val < 4 ? 0 : val < 8 ? 1 : val < 16 ? 2 : - val < 32 ? 3 : val < 48 ? 4 : 5; - } - val = ((pixel[row-2][col] + pixel[row][col-2]) >> 1) - + rstep[sharp][getbits(2)]; - pixel[row][col] = val = LIM(val,0,255); - if (row < 4) pixel[row-2][col+2] = val; - if (col < 4) pixel[row+2][col-2] = val; - } - for (row=2; row < height+2; row++) - for (col=3-(row & 1); col < width+2; col+=2) { - val = ((pixel[row][col-1] + (pixel[row][col] << 2) + - pixel[row][col+1]) >> 1) - 0x100; - pixel[row][col] = LIM(val,0,255); - } - for (row=0; row < height; row++) - for (col=0; col < width; col++) - RBAYER(row,col) = t_curve[pixel[row+2][col+2]]; - maximum = 0x3ff; -} - -#define radc_token(tree) ((signed char) getbithuff(8,huff[tree])) - -#define FORYX for (y=1; y < 3; y++) for (x=col+1; x >= col; x--) - -#define PREDICTOR (c ? (buf[c][y-1][x] + buf[c][y][x+1]) / 2 \ -: (buf[c][y-1][x+1] + 2*buf[c][y-1][x] + buf[c][y][x+1]) / 4) - -void CLASS kodak_radc_load_raw() -{ - static const char src[] = { - 1,1, 2,3, 3,4, 4,2, 5,7, 6,5, 7,6, 7,8, - 1,0, 2,1, 3,3, 4,4, 5,2, 6,7, 7,6, 8,5, 8,8, - 2,1, 2,3, 3,0, 3,2, 3,4, 4,6, 5,5, 6,7, 6,8, - 2,0, 2,1, 2,3, 3,2, 4,4, 5,6, 6,7, 7,5, 7,8, - 2,1, 2,4, 3,0, 3,2, 3,3, 4,7, 5,5, 6,6, 6,8, - 2,3, 3,1, 3,2, 3,4, 3,5, 3,6, 4,7, 5,0, 5,8, - 2,3, 2,6, 3,0, 3,1, 4,4, 4,5, 4,7, 5,2, 5,8, - 2,4, 2,7, 3,3, 3,6, 4,1, 4,2, 4,5, 5,0, 5,8, - 2,6, 3,1, 3,3, 3,5, 3,7, 3,8, 4,0, 5,2, 5,4, - 2,0, 2,1, 3,2, 3,3, 4,4, 4,5, 5,6, 5,7, 4,8, - 1,0, 2,2, 2,-2, - 1,-3, 1,3, - 2,-17, 2,-5, 2,5, 2,17, - 2,-7, 2,2, 2,9, 2,18, - 2,-18, 2,-9, 2,-2, 2,7, - 2,-28, 2,28, 3,-49, 3,-9, 3,9, 4,49, 5,-79, 5,79, - 2,-1, 2,13, 2,26, 3,39, 4,-16, 5,55, 6,-37, 6,76, - 2,-26, 2,-13, 2,1, 3,-39, 4,16, 5,-55, 6,-76, 6,37 - }; - ushort huff[19][256]; - int row, col, tree, nreps, rep, step, i, c, s, r, x, y, val; - short last[3] = { 16,16,16 }, mul[3], buf[3][3][386]; - static const ushort pt[] = - { 0,0, 1280,1344, 2320,3616, 3328,8000, 4095,16383, 65535,16383 }; - - for (i=2; i < 12; i+=2) - for (c=pt[i-2]; c <= pt[i]; c++) - curve[c] = (float) - (c-pt[i-2]) / (pt[i]-pt[i-2]) * (pt[i+1]-pt[i-1]) + pt[i-1] + 0.5; - for (s=i=0; i < sizeof src; i+=2) - FORC(256 >> src[i]) - huff[0][s++] = src[i] << 8 | (uchar) src[i+1]; - s = kodak_cbpp == 243 ? 2 : 3; - FORC(256) huff[18][c] = (8-s) << 8 | c >> s << s | 1 << (s-1); - getbits(-1); - for (i=0; i < sizeof(buf)/sizeof(short); i++) - buf[0][0][i] = 2048; - for (row=0; row < height; row+=4) { - FORC3 mul[c] = getbits(6); - FORC3 { - val = ((0x1000000/last[c] + 0x7ff) >> 12) * mul[c]; - s = val > 65564 ? 10:12; - x = ~(-1 << (s-1)); - val <<= 12-s; - for (i=0; i < sizeof(buf[0])/sizeof(short); i++) - buf[c][0][i] = (buf[c][0][i] * val + x) >> s; - last[c] = mul[c]; - for (r=0; r <= !c; r++) { - buf[c][1][width/2] = buf[c][2][width/2] = mul[c] << 7; - for (tree=1, col=width/2; col > 0; ) { - if ((tree = radc_token(tree))) { - col -= 2; - if (tree == 8) - FORYX buf[c][y][x] = (uchar) radc_token(18) * mul[c]; - else - FORYX buf[c][y][x] = radc_token(tree+10) * 16 + PREDICTOR; - } else - do { - nreps = (col > 2) ? radc_token(9) + 1 : 1; - for (rep=0; rep < 8 && rep < nreps && col > 0; rep++) { - col -= 2; - FORYX buf[c][y][x] = PREDICTOR; - if (rep & 1) { - step = radc_token(10) << 4; - FORYX buf[c][y][x] += step; - } - } - } while (nreps == 9); - } - for (y=0; y < 2; y++) - for (x=0; x < width/2; x++) { - val = (buf[c][y+1][x] << 4) / mul[c]; - if (val < 0) val = 0; - if (c) CBAYER(row+y*2+c-1,x*2+2-c) = val; - else CBAYER(row+r*2+y,x*2+y) = val; - } - memcpy (buf[c][0]+!c, buf[c][2], sizeof buf[c][0]-2*!c); - } - } - for (y=row; y < row+4; y++) - for (x=0; x < width; x++) - if ((x+y) & 1) { - r = x ? x-1 : x+1; - s = x+1 < width ? x+1 : x-1; - val = (CBAYER(y,x)-2048)*2 + (CBAYER(y,r)+CBAYER(y,s))/2; - if (val < 0) val = 0; - CBAYER(y,x) = val; - } - } -#ifndef LIBRAW_LIBRARY_BUILD - for (i=0; i < iheight*iwidth*4; i++) - image[0][i] = curve[image[0][i]]; -#else - for (i=0; i < height*width*4; i++) - color_image[0][i] = curve[color_image[0][i]]; -#endif - maximum = 0x3fff; -} - -#undef FORYX -#undef PREDICTOR - -#ifdef NO_JPEG -void CLASS kodak_jpeg_load_raw() {} -#else - -METHODDEF(boolean) -fill_input_buffer (j_decompress_ptr cinfo) -{ -#ifndef LIBRAW_NOTHREADS -#define jpeg_buffer tls->jpeg_buffer -#else - static uchar jpeg_buffer[4096]; -#endif - size_t nbytes; - - nbytes = fread (jpeg_buffer, 1, 4096, ifp); - swab (jpeg_buffer, jpeg_buffer, nbytes); - cinfo->src->next_input_byte = jpeg_buffer; - cinfo->src->bytes_in_buffer = nbytes; - return TRUE; -#ifndef LIBRAW_NOTHREADS -#undef jpeg_buffer -#endif -} - -void CLASS kodak_jpeg_load_raw() -{ - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - JSAMPARRAY buf; - JSAMPLE (*pixel)[3]; - int row, col; - - cinfo.err = jpeg_std_error (&jerr); - jpeg_create_decompress (&cinfo); - jpeg_stdio_src (&cinfo, ifp); - cinfo.src->fill_input_buffer = fill_input_buffer; - jpeg_read_header (&cinfo, TRUE); - jpeg_start_decompress (&cinfo); - if ((cinfo.output_width != width ) || - (cinfo.output_height*2 != height ) || - (cinfo.output_components != 3 )) { -#ifdef DCRAW_VERBOSE - fprintf (stderr,_("%s: incorrect JPEG dimensions\n"), ifname); -#endif - jpeg_destroy_decompress (&cinfo); -#ifdef LIBRAW_LIBRARY_BUILD - throw LIBRAW_EXCEPTION_DECODE_JPEG; -#else - longjmp (failure, 3); -#endif - } - buf = (*cinfo.mem->alloc_sarray) - ((j_common_ptr) &cinfo, JPOOL_IMAGE, width*3, 1); - - while (cinfo.output_scanline < cinfo.output_height) { - row = cinfo.output_scanline * 2; - jpeg_read_scanlines (&cinfo, buf, 1); - pixel = (JSAMPLE (*)[3]) buf[0]; - for (col=0; col < width; col+=2) { - RBAYER(row+0,col+0) = pixel[col+0][1] << 1; - RBAYER(row+1,col+1) = pixel[col+1][1] << 1; - RBAYER(row+0,col+1) = pixel[col][0] + pixel[col+1][0]; - RBAYER(row+1,col+0) = pixel[col][2] + pixel[col+1][2]; - } - } - jpeg_finish_decompress (&cinfo); - jpeg_destroy_decompress (&cinfo); - maximum = 0xff << 1; -} -#endif - -void CLASS kodak_dc120_load_raw() -{ - static const int mul[4] = { 162, 192, 187, 92 }; - static const int add[4] = { 0, 636, 424, 212 }; - uchar pixel[848]; - int row, shift, col; - - for (row=0; row < height; row++) { - if (fread (pixel, 1, 848, ifp) < 848) derror(); - shift = row * mul[row & 3] + add[row & 3]; - for (col=0; col < width; col++) - RBAYER(row,col) = (ushort) pixel[(col + shift) % 848]; - } - maximum = 0xff; -} - -void CLASS eight_bit_load_raw() -{ - uchar *pixel; - unsigned row, col, val, lblack=0; - - pixel = (uchar *) calloc (raw_width, sizeof *pixel); - merror (pixel, "eight_bit_load_raw()"); -#ifndef LIBRAW_LIBRARY_BUILD - fseek (ifp, top_margin*raw_width, SEEK_CUR); - for (row=0; row < height; row++) { - if (fread (pixel, 1, raw_width, ifp) < raw_width) derror(); - for (col=0; col < raw_width; col++) { - val = curve[pixel[col]]; - if ((unsigned) (col-left_margin) < width) - BAYER(row,col-left_margin) = val; - else lblack += val; - } - } -#else - for (row=0; row < raw_height; row++) { - if (fread (pixel, 1, raw_width, ifp) < raw_width) derror(); - for (col=0; col < raw_width; col++) { - val = curve[pixel[col]]; - RBAYER(row,col) = val; - if((unsigned) (row-top_margin)< height) - if ((unsigned) (col-left_margin) >= width) - lblack+=val; - } - } -#endif - - free (pixel); - if (raw_width > width+1) - black = lblack / ((raw_width - width) * height); - if (!strncmp(model,"DC2",3)) - black = 0; - maximum = curve[0xff]; -} - -void CLASS kodak_yrgb_load_raw() -{ - uchar *pixel; - int row, col, y, cb, cr, rgb[3], c; - - pixel = (uchar *) calloc (raw_width, 3*sizeof *pixel); - merror (pixel, "kodak_yrgb_load_raw()"); - for (row=0; row < height; row++) { - if (~row & 1) - if (fread (pixel, raw_width, 3, ifp) < 3) derror(); - for (col=0; col < raw_width; col++) { - y = pixel[width*2*(row & 1) + col]; - cb = pixel[width + (col & -2)] - 128; - cr = pixel[width + (col & -2)+1] - 128; - rgb[1] = y-((cb + cr + 2) >> 2); - rgb[2] = rgb[1] + cb; - rgb[0] = rgb[1] + cr; - FORC3{ -#ifndef LIBRAW_LIBRARY_BUILD - image[row*width+col][c] = curve[LIM(rgb[c],0,255)]; -#else - color_image[(row+top_margin)*raw_width+col+left_margin][c] = curve[LIM(rgb[c],0,255)]; -#endif - } - } - } - free (pixel); - maximum = curve[0xff]; -} - -void CLASS kodak_262_load_raw() -{ - static const uchar kodak_tree[2][26] = - { { 0,1,5,1,1,2,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9 }, - { 0,3,1,1,1,1,1,2,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9 } }; - ushort *huff[2]; - uchar *pixel; - int *strip, ns, c, row, col, chess, pi=0, pi1, pi2, pred, val; - - FORC(2) huff[c] = make_decoder (kodak_tree[c]); - ns = (raw_height+63) >> 5; - pixel = (uchar *) malloc (raw_width*32 + ns*4); - merror (pixel, "kodak_262_load_raw()"); - strip = (int *) (pixel + raw_width*32); - order = 0x4d4d; - FORC(ns) strip[c] = get4(); - for (row=0; row < raw_height; row++) { - if ((row & 31) == 0) { - fseek (ifp, strip[row >> 5], SEEK_SET); - getbits(-1); - pi = 0; - } - for (col=0; col < raw_width; col++) { - chess = (row + col) & 1; - pi1 = chess ? pi-2 : pi-raw_width-1; - pi2 = chess ? pi-2*raw_width : pi-raw_width+1; - if (col <= chess) pi1 = -1; - if (pi1 < 0) pi1 = pi2; - if (pi2 < 0) pi2 = pi1; - if (pi1 < 0 && col > 1) pi1 = pi2 = pi-2; - pred = (pi1 < 0) ? 0 : (pixel[pi1] + pixel[pi2]) >> 1; - pixel[pi] = val = pred + ljpeg_diff (huff[chess]); - if (val >> 8) derror(); - - val = curve[pixel[pi++]]; - -#ifdef LIBRAW_LIBRARY_BUILD - RBAYER(row,col) = val; - if ((unsigned) (col-left_margin) >= width) - black+=val; -#else - if ((unsigned) (col-left_margin) < width) - BAYER(row,col-left_margin) = val; - else black += val; -#endif - } - } - free (pixel); - FORC(2) free (huff[c]); - if (raw_width > width) - black /= (raw_width - width) * height; -} - -int CLASS kodak_65000_decode (short *out, int bsize) -{ - uchar c, blen[768]; - ushort raw[6]; - INT64 bitbuf=0; - int save, bits=0, i, j, len, diff; - - save = ftell(ifp); - bsize = (bsize + 3) & -4; - for (i=0; i < bsize; i+=2) { - c = fgetc(ifp); - if ((blen[i ] = c & 15) > 12 || - (blen[i+1] = c >> 4) > 12 ) { - fseek (ifp, save, SEEK_SET); - for (i=0; i < bsize; i+=8) { - read_shorts (raw, 6); - out[i ] = raw[0] >> 12 << 8 | raw[2] >> 12 << 4 | raw[4] >> 12; - out[i+1] = raw[1] >> 12 << 8 | raw[3] >> 12 << 4 | raw[5] >> 12; - for (j=0; j < 6; j++) - out[i+2+j] = raw[j] & 0xfff; - } - return 1; - } - } - if ((bsize & 7) == 4) { - bitbuf = fgetc(ifp) << 8; - bitbuf += fgetc(ifp); - bits = 16; - } - for (i=0; i < bsize; i++) { - len = blen[i]; - if (bits < len) { - for (j=0; j < 32; j+=8) - bitbuf += (INT64) fgetc(ifp) << (bits+(j^8)); - bits += 32; - } - diff = bitbuf & (0xffff >> (16-len)); - bitbuf >>= len; - bits -= len; - if ((diff & (1 << (len-1))) == 0) - diff -= (1 << len) - 1; - out[i] = diff; - } - return 0; -} - -void CLASS kodak_65000_load_raw() -{ - short buf[256]; - int row, col, len, pred[2], ret, i; - - for (row=0; row < height; row++) - for (col=0; col < width; col+=256) { - pred[0] = pred[1] = 0; - len = MIN (256, width-col); - ret = kodak_65000_decode (buf, len); - for (i=0; i < len; i++) -#ifndef LIBRAW_LIBRARY_BUILD - if ((BAYER(row,col+i) = curve[ret ? buf[i] : - (pred[i & 1] += buf[i])]) >> 12) derror(); -#else - { - ushort val = ret ? buf[i] : (pred[i & 1] += buf[i]); - val = curve[val]; - RBAYER(row,col+i) = val; - if(curve[val]>>12) derror(); - } -#endif - } -} - -void CLASS kodak_ycbcr_load_raw() -{ - short buf[384], *bp; - int row, col, len, c, i, j, k, y[2][2], cb, cr, rgb[3]; - ushort *ip; - - for (row=0; row < height; row+=2) - for (col=0; col < width; col+=128) { - len = MIN (128, width-col); - kodak_65000_decode (buf, len*3); - y[0][1] = y[1][1] = cb = cr = 0; - for (bp=buf, i=0; i < len; i+=2, bp+=2) { - cb += bp[4]; - cr += bp[5]; - rgb[1] = -((cb + cr + 2) >> 2); - rgb[2] = rgb[1] + cb; - rgb[0] = rgb[1] + cr; - for (j=0; j < 2; j++) - for (k=0; k < 2; k++) { - if ((y[j][k] = y[j][k^1] + *bp++) >> 10) derror(); -#ifndef LIBRAW_LIBRARY_BUILD - ip = image[(row+j)*width + col+i+k]; - FORC3 ip[c] = curve[LIM(y[j][k]+rgb[c], 0, 0xfff)]; -#else - ip = color_image[(row+top_margin+j)*raw_width + col+i+k+left_margin]; - FORC3 ip[c] = curve[LIM(y[j][k]+rgb[c], 0, 0xfff)]; -#endif - } - } - } -} - -void CLASS kodak_rgb_load_raw() -{ - short buf[768], *bp; - int row, col, len, c, i, rgb[3]; -#ifndef LIBRAW_LIBRARY_BUILD - ushort *ip=image[0]; -#else - ushort *ip; -#endif - - for (row=0; row < height; row++) - for (col=0; col < width; col+=256) { - len = MIN (256, width-col); - kodak_65000_decode (buf, len*3); - memset (rgb, 0, sizeof rgb); -#ifdef LIBRAW_LIBRARY_BUILD - ip = &color_image[(row+top_margin)*raw_width+left_margin][0]; -#endif - for (bp=buf, i=0; i < len; i++, ip+=4) - FORC3{ - if ((ip[c] = rgb[c] += *bp++) >> 12) derror(); - } - } -} - -void CLASS kodak_ycbcr_load_thumb() -{ - short buf[384], *bp; - int row, col, len, c, i, j, k, y[2][2], cb, cr, rgb[3]; - ushort *ip; - - for (row=0; row < height; row+=2) - for (col=0; col < width; col+=128) { - len = MIN (128, width-col); - kodak_65000_decode (buf, len*3); - y[0][1] = y[1][1] = cb = cr = 0; - for (bp=buf, i=0; i < len; i+=2, bp+=2) { - cb += bp[4]; - cr += bp[5]; - rgb[1] = -((cb + cr + 2) >> 2); - rgb[2] = rgb[1] + cb; - rgb[0] = rgb[1] + cr; - for (j=0; j < 2; j++) - for (k=0; k < 2; k++) { - if ((y[j][k] = y[j][k^1] + *bp++) >> 10) derror(); - ip = image[(row+j)*width + col+i+k]; - FORC3 ip[c] = curve[LIM(y[j][k]+rgb[c], 0, 0xfff)]; - } - } - } -} - -void CLASS kodak_rgb_load_thumb() -{ - short buf[768], *bp; - int row, col, len, c, i, rgb[3]; - ushort *ip=image[0]; - - for (row=0; row < height; row++) - for (col=0; col < width; col+=256) { - len = MIN (256, width-col); - kodak_65000_decode (buf, len*3); - memset (rgb, 0, sizeof rgb); - for (bp=buf, i=0; i < len; i++, ip+=4) - FORC3 if ((ip[c] = rgb[c] += *bp++) >> 12) derror(); - } -} - -void CLASS kodak_thumb_load_raw() -{ - int row, col; - colors = thumb_misc >> 5; - for (row=0; row < height; row++) - for (col=0; col < width; col++) - read_shorts (image[row*width+col], colors); - maximum = (1 << (thumb_misc & 31)) - 1; -} - -void CLASS sony_decrypt (unsigned *data, int len, int start, int key) -{ -#ifndef LIBRAW_NOTHREADS -#define pad tls->sony_decrypt.pad -#define p tls->sony_decrypt.p -#else - static unsigned pad[128], p; -#endif - - if (start) { - for (p=0; p < 4; p++) - pad[p] = key = key * 48828125 + 1; - pad[3] = pad[3] << 1 | (pad[0]^pad[2]) >> 31; - for (p=4; p < 127; p++) - pad[p] = (pad[p-4]^pad[p-2]) << 1 | (pad[p-3]^pad[p-1]) >> 31; - for (p=0; p < 127; p++) - pad[p] = htonl(pad[p]); - } - while (len--) - *data++ ^= pad[p++ & 127] = pad[(p+1) & 127] ^ pad[(p+65) & 127]; -#ifndef LIBRAW_NOTHREADS -#undef pad -#undef p -#endif -} - -void CLASS sony_load_raw() -{ - uchar head[40]; - ushort *pixel; - unsigned i, key, row, col; - - fseek (ifp, 200896, SEEK_SET); - fseek (ifp, (unsigned) fgetc(ifp)*4 - 1, SEEK_CUR); - order = 0x4d4d; - key = get4(); - fseek (ifp, 164600, SEEK_SET); - fread (head, 1, 40, ifp); - sony_decrypt ((unsigned int *) head, 10, 1, key); - for (i=26; i-- > 22; ) - key = key << 8 | head[i]; - fseek (ifp, data_offset, SEEK_SET); - pixel = (ushort *) calloc (raw_width, sizeof *pixel); - merror (pixel, "sony_load_raw()"); - for (row=0; row < height; row++) { - if (fread (pixel, 2, raw_width, ifp) < raw_width) derror(); - sony_decrypt ((unsigned int *) pixel, raw_width/2, !row, key); - for (col=9; col < left_margin; col++) - black += ntohs(pixel[col]); -#ifndef LIBRAW_LIBRARY_BUILD - for (col=0; col < width; col++) - if ((BAYER(row,col) = ntohs(pixel[col+left_margin])) >> 14) - derror(); -#else - for (col=0; col < raw_width; col++) - { - RBAYER(row,col) = ntohs(pixel[col]); - if(col >= left_margin && col < width+left_margin - && (RBAYER(row,col)>>14)) - derror(); - } -#endif - } - free (pixel); - if (left_margin > 9) - black /= (left_margin-9) * height; - maximum = 0x3ff0; -} - -void CLASS sony_arw_load_raw() -{ - ushort huff[32768]; - static const ushort tab[18] = - { 0xf11,0xf10,0xe0f,0xd0e,0xc0d,0xb0c,0xa0b,0x90a,0x809, - 0x708,0x607,0x506,0x405,0x304,0x303,0x300,0x202,0x201 }; - int i, c, n, col, row, len, diff, sum=0; - - for (n=i=0; i < 18; i++) - FORC(32768 >> (tab[i] >> 8)) huff[n++] = tab[i]; -#ifdef LIBRAW_LIBRARY_BUILD - LibRaw_byte_buffer *buf=NULL; - if(data_size) - buf = ifp->make_byte_buffer(data_size); - else - getbits(-1); - - LibRaw_bit_buffer bits; - bits.reset(); -#else - getbits(-1); -#endif - for (col = raw_width; col--; ) - for (row=0; row < raw_height+1; row+=2) { - if (row == raw_height) row = 1; -#ifdef LIBRAW_LIBRARY_BUILD - if(data_size) - { - len = bits._gethuff(buf,15,huff,zero_after_ff); - diff = bits._getbits(buf,len,zero_after_ff); - } - else - { - len = getbithuff(15,huff); - diff = getbits(len); - } -#else - len = getbithuff(15,huff); - diff = getbits(len); -#endif - if ((diff & (1 << (len-1))) == 0) - diff -= (1 << len) - 1; - if ((sum += diff) >> 12) derror(); -#ifndef LIBRAW_LIBRARY_BUILD - if (row < height) - { - BAYER(row,col) = sum; - } -#else - RBAYER(row,col) = sum; -#endif - } -#ifdef LIBRAW_LIBRARY_BUILD - if(buf) delete buf; -#endif -} - -void CLASS sony_arw2_load_raw() -{ - uchar *data, *dp; - ushort pix[16]; - int row, col, val, max, min, imax, imin, sh, bit, i; - - data = (uchar *) malloc (raw_width+4); - merror (data, "sony_arw2_load_raw()"); - for (row=0; row < height; row++) { - fread (data, 1, raw_width, ifp); - for (dp=data, col=0; col < raw_width-30; dp+=16) { - max = 0x7ff & (val = sget4(dp)); - min = 0x7ff & val >> 11; - imax = 0x0f & val >> 22; - imin = 0x0f & val >> 26; - for (sh=0; sh < 4 && 0x80 << sh <= max-min; sh++); - for (bit=30, i=0; i < 16; i++) - if (i == imax) pix[i] = max; - else if (i == imin) pix[i] = min; - else { - pix[i] = ((sget2(dp+(bit >> 3)) >> (bit & 7) & 0x7f) << sh) + min; - if (pix[i] > 0x7ff) pix[i] = 0x7ff; - bit += 7; - } - for (i=0; i < 16; i++, col+=2) -#ifdef LIBRAW_LIBRARY_BUILD - RBAYER(row,col) = curve[pix[i] << 1] >> 2; -#else - if (col < width) BAYER(row,col) = curve[pix[i] << 1] >> 2; -#endif - col -= col & 1 ? 1:31; - } - } - free (data); -} - -#define HOLE(row) ((holes >> (((row) - raw_height) & 7)) & 1) - -/* Kudos to Rich Taylor for figuring out SMaL's compression algorithm. */ -void CLASS smal_decode_segment (unsigned seg[2][2], int holes) -{ - uchar hist[3][13] = { - { 7, 7, 0, 0, 63, 55, 47, 39, 31, 23, 15, 7, 0 }, - { 7, 7, 0, 0, 63, 55, 47, 39, 31, 23, 15, 7, 0 }, - { 3, 3, 0, 0, 63, 47, 31, 15, 0 } }; - int low, high=0xff, carry=0, nbits=8; - int s, count, bin, next, i, sym[3]; - uchar diff, pred[]={0,0}; - ushort data=0, range=0; - unsigned pix, row, col; - - fseek (ifp, seg[0][1]+1, SEEK_SET); - getbits(-1); - for (pix=seg[0][0]; pix < seg[1][0]; pix++) { - for (s=0; s < 3; s++) { - data = data << nbits | getbits(nbits); - if (carry < 0) - carry = (nbits += carry+1) < 1 ? nbits-1 : 0; - while (--nbits >= 0) - if ((data >> nbits & 0xff) == 0xff) break; - if (nbits > 0) - data = ((data & ((1 << (nbits-1)) - 1)) << 1) | - ((data + (((data & (1 << (nbits-1)))) << 1)) & (-1 << nbits)); - if (nbits >= 0) { - data += getbits(1); - carry = nbits - 8; - } - count = ((((data-range+1) & 0xffff) << 2) - 1) / (high >> 4); - for (bin=0; hist[s][bin+5] > count; bin++); - low = hist[s][bin+5] * (high >> 4) >> 2; - if (bin) high = hist[s][bin+4] * (high >> 4) >> 2; - high -= low; - for (nbits=0; high << nbits < 128; nbits++); - range = (range+low) << nbits; - high <<= nbits; - next = hist[s][1]; - if (++hist[s][2] > hist[s][3]) { - next = (next+1) & hist[s][0]; - hist[s][3] = (hist[s][next+4] - hist[s][next+5]) >> 2; - hist[s][2] = 1; - } - if (hist[s][hist[s][1]+4] - hist[s][hist[s][1]+5] > 1) { - if (bin < hist[s][1]) - for (i=bin; i < hist[s][1]; i++) hist[s][i+5]--; - else if (next <= bin) - for (i=hist[s][1]; i < bin; i++) hist[s][i+5]++; - } - hist[s][1] = next; - sym[s] = bin; - } - diff = sym[2] << 5 | sym[1] << 2 | (sym[0] & 3); - if (sym[0] & 4) - diff = diff ? -diff : 0x80; - if (ftell(ifp) + 12 >= seg[1][1]) - diff = 0; - pred[pix & 1] += diff; -#ifndef LIBRAW_LIBRARY_BUILD - row = pix / raw_width - top_margin; - col = pix % raw_width - left_margin; - if (row < height && col < width) - BAYER(row,col) = pred[pix & 1]; -#else - row = pix / raw_width - top_margin; - RBAYER(pix / raw_width, pix % raw_width) = pred[pix & 1]; -#endif - if (!(pix & 1) && HOLE(row)) pix += 2; - } - maximum = 0xff; -} - -void CLASS smal_v6_load_raw() -{ - unsigned seg[2][2]; - - fseek (ifp, 16, SEEK_SET); - seg[0][0] = 0; - seg[0][1] = get2(); - seg[1][0] = raw_width * raw_height; - seg[1][1] = INT_MAX; - smal_decode_segment (seg, 0); -} - -int CLASS median4 (int *p) -{ - int min, max, sum, i; - - min = max = sum = p[0]; - for (i=1; i < 4; i++) { - sum += p[i]; - if (min > p[i]) min = p[i]; - if (max < p[i]) max = p[i]; - } - return (sum - min - max) >> 1; -} - -void CLASS fill_holes (int holes) -{ - int row, col, val[4]; - - for (row=2; row < height-2; row++) { - if (!HOLE(row)) continue; - for (col=1; col < width-1; col+=4) { - val[0] = BAYER(row-1,col-1); - val[1] = BAYER(row-1,col+1); - val[2] = BAYER(row+1,col-1); - val[3] = BAYER(row+1,col+1); - BAYER(row,col) = median4(val); - } - for (col=2; col < width-2; col+=4) - if (HOLE(row-2) || HOLE(row+2)) - BAYER(row,col) = (BAYER(row,col-2) + BAYER(row,col+2)) >> 1; - else { - val[0] = BAYER(row,col-2); - val[1] = BAYER(row,col+2); - val[2] = BAYER(row-2,col); - val[3] = BAYER(row+2,col); - BAYER(row,col) = median4(val); - } - } -} - -void CLASS smal_v9_load_raw() -{ - unsigned seg[256][2], offset, nseg, holes, i; - - fseek (ifp, 67, SEEK_SET); - offset = get4(); - nseg = fgetc(ifp); - fseek (ifp, offset, SEEK_SET); - for (i=0; i < nseg*2; i++) - seg[0][i] = get4() + data_offset*(i & 1); - fseek (ifp, 78, SEEK_SET); - holes = fgetc(ifp); - fseek (ifp, 88, SEEK_SET); - seg[nseg][0] = raw_height * raw_width; - seg[nseg][1] = get4() + data_offset; - for (i=0; i < nseg; i++) - smal_decode_segment (seg+i, holes); - if (holes) fill_holes (holes); -} - -void CLASS redcine_load_raw() -{ -#ifndef NO_JASPER - int c, row, col; - jas_stream_t *in; - jas_image_t *jimg; - jas_matrix_t *jmat; - jas_seqent_t *data; - ushort *img, *pix; - - jas_init(); -#ifndef LIBRAW_LIBRARY_BUILD - in = jas_stream_fopen (ifname, "rb"); -#else - in = (jas_stream_t*)ifp->make_jas_stream(); - if(!in) - throw LIBRAW_EXCEPTION_DECODE_JPEG2000; -#endif - jas_stream_seek (in, data_offset+20, SEEK_SET); - jimg = jas_image_decode (in, -1, 0); -#ifndef LIBRAW_LIBRARY_BUILD - if (!jimg) longjmp (failure, 3); -#else - if(!jimg) - { - jas_stream_close (in); - throw LIBRAW_EXCEPTION_DECODE_JPEG2000; - } -#endif - jmat = jas_matrix_create (height/2, width/2); - merror (jmat, "redcine_load_raw()"); - img = (ushort *) calloc ((height+2)*(width+2), 2); - merror (img, "redcine_load_raw()"); - FORC4 { - jas_image_readcmpt (jimg, c, 0, 0, width/2, height/2, jmat); - data = jas_matrix_getref (jmat, 0, 0); - for (row = c >> 1; row < height; row+=2) - for (col = c & 1; col < width; col+=2) - img[(row+1)*(width+2)+col+1] = data[(row/2)*(width/2)+col/2]; - } - for (col=1; col <= width; col++) { - img[col] = img[2*(width+2)+col]; - img[(height+1)*(width+2)+col] = img[(height-1)*(width+2)+col]; - } - for (row=0; row < height+2; row++) { - img[row*(width+2)] = img[row*(width+2)+2]; - img[(row+1)*(width+2)-1] = img[(row+1)*(width+2)-3]; - } - for (row=1; row <= height; row++) { - pix = img + row*(width+2) + (col = 1 + (FC(row,1) & 1)); - for ( ; col <= width; col+=2, pix+=2) { - c = (((pix[0] - 0x800) << 3) + - pix[-(width+2)] + pix[width+2] + pix[-1] + pix[1]) >> 2; - pix[0] = LIM(c,0,4095); - } - } - for (row=0; row < height; row++) - for (col=0; col < width; col++) - RBAYER(row,col) = curve[img[(row+1)*(width+2)+col+1]]; - free (img); - jas_matrix_destroy (jmat); - jas_image_destroy (jimg); - jas_stream_close (in); -#endif -} - - -void CLASS gamma_curve (double pwr, double ts, int mode, int imax) -{ - int i; - double g[6], bnd[2]={0,0}, r; - - g[0] = pwr; - g[1] = ts; - g[2] = g[3] = g[4] = 0; - bnd[g[1] >= 1] = 1; - if (g[1] && (g[1]-1)*(g[0]-1) <= 0) { - for (i=0; i < 48; i++) { - g[2] = (bnd[0] + bnd[1])/2; - if (g[0]) bnd[(pow(g[2]/g[1],-g[0]) - 1)/g[0] - 1/g[2] > -1] = g[2]; - else bnd[g[2]/exp(1-1/g[2]) < g[1]] = g[2]; - } - g[3] = g[2] / g[1]; - if (g[0]) g[4] = g[2] * (1/g[0] - 1); - } - if (g[0]) g[5] = 1 / (g[1]*SQR(g[3])/2 - g[4]*(1 - g[3]) + - (1 - pow(g[3],1+g[0]))*(1 + g[4])/(1 + g[0])) - 1; - else g[5] = 1 / (g[1]*SQR(g[3])/2 + 1 - - g[2] - g[3] - g[2]*g[3]*(log(g[3]) - 1)) - 1; - if (!mode--) { - memcpy (gamm, g, sizeof gamm); - return; - } - for (i=0; i < 0x10000; i++) { - curve[i] = 0xffff; - if ((r = (double) i / imax) < 1) - curve[i] = 0x10000 * ( mode - ? (r < g[3] ? r*g[1] : (g[0] ? pow( r,g[0])*(1+g[4])-g[4] : log(r)*g[2]+1)) - : (r < g[2] ? r/g[1] : (g[0] ? pow((r+g[4])/(1+g[4]),1/g[0]) : exp((r-1)/g[2])))); - } -} - -void CLASS pseudoinverse (double (*in)[3], double (*out)[3], int size) -{ - double work[3][6], num; - int i, j, k; - - for (i=0; i < 3; i++) { - for (j=0; j < 6; j++) - work[i][j] = j == i+3; - for (j=0; j < 3; j++) - for (k=0; k < size; k++) - work[i][j] += in[k][i] * in[k][j]; - } - for (i=0; i < 3; i++) { - num = work[i][i]; - for (j=0; j < 6; j++) - work[i][j] /= num; - for (k=0; k < 3; k++) { - if (k==i) continue; - num = work[k][i]; - for (j=0; j < 6; j++) - work[k][j] -= work[i][j] * num; - } - } - for (i=0; i < size; i++) - for (j=0; j < 3; j++) - for (out[i][j]=k=0; k < 3; k++) - out[i][j] += work[j][k+3] * in[i][k]; -} - -void CLASS cam_xyz_coeff (double cam_xyz[4][3]) -{ - double cam_rgb[4][3], inverse[4][3], num; - int i, j, k; - - for (i=0; i < colors; i++) /* Multiply out XYZ colorspace */ - for (j=0; j < 3; j++) - for (cam_rgb[i][j] = k=0; k < 3; k++) - cam_rgb[i][j] += cam_xyz[i][k] * xyz_rgb[k][j]; - - for (i=0; i < colors; i++) { /* Normalize cam_rgb so that */ - for (num=j=0; j < 3; j++) /* cam_rgb * (1,1,1) is (1,1,1,1) */ - num += cam_rgb[i][j]; - for (j=0; j < 3; j++) - cam_rgb[i][j] /= num; - pre_mul[i] = 1 / num; - } - pseudoinverse (cam_rgb, inverse, colors); - for (raw_color = i=0; i < 3; i++) - for (j=0; j < colors; j++) - rgb_cam[i][j] = inverse[j][i]; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.pre_mul_state = LIBRAW_COLORSTATE_CONST; - color_flags.rgb_cam_state = LIBRAW_COLORSTATE_CONST; -#endif -} - -#ifdef COLORCHECK -void CLASS colorcheck() -{ -#define NSQ 24 -// Coordinates of the GretagMacbeth ColorChecker squares -// width, height, 1st_column, 1st_row - int cut[NSQ][4]; // you must set these -// ColorChecker Chart under 6500-kelvin illumination - static const double gmb_xyY[NSQ][3] = { - { 0.400, 0.350, 10.1 }, // Dark Skin - { 0.377, 0.345, 35.8 }, // Light Skin - { 0.247, 0.251, 19.3 }, // Blue Sky - { 0.337, 0.422, 13.3 }, // Foliage - { 0.265, 0.240, 24.3 }, // Blue Flower - { 0.261, 0.343, 43.1 }, // Bluish Green - { 0.506, 0.407, 30.1 }, // Orange - { 0.211, 0.175, 12.0 }, // Purplish Blue - { 0.453, 0.306, 19.8 }, // Moderate Red - { 0.285, 0.202, 6.6 }, // Purple - { 0.380, 0.489, 44.3 }, // Yellow Green - { 0.473, 0.438, 43.1 }, // Orange Yellow - { 0.187, 0.129, 6.1 }, // Blue - { 0.305, 0.478, 23.4 }, // Green - { 0.539, 0.313, 12.0 }, // Red - { 0.448, 0.470, 59.1 }, // Yellow - { 0.364, 0.233, 19.8 }, // Magenta - { 0.196, 0.252, 19.8 }, // Cyan - { 0.310, 0.316, 90.0 }, // White - { 0.310, 0.316, 59.1 }, // Neutral 8 - { 0.310, 0.316, 36.2 }, // Neutral 6.5 - { 0.310, 0.316, 19.8 }, // Neutral 5 - { 0.310, 0.316, 9.0 }, // Neutral 3.5 - { 0.310, 0.316, 3.1 } }; // Black - double gmb_cam[NSQ][4], gmb_xyz[NSQ][3]; - double inverse[NSQ][3], cam_xyz[4][3], num; - int c, i, j, k, sq, row, col, count[4]; - - memset (gmb_cam, 0, sizeof gmb_cam); - for (sq=0; sq < NSQ; sq++) { - FORCC count[c] = 0; - for (row=cut[sq][3]; row < cut[sq][3]+cut[sq][1]; row++) - for (col=cut[sq][2]; col < cut[sq][2]+cut[sq][0]; col++) { - c = FC(row,col); - if (c >= colors) c -= 2; - gmb_cam[sq][c] += BAYER(row,col); - count[c]++; - } - FORCC gmb_cam[sq][c] = gmb_cam[sq][c]/count[c] - black; - gmb_xyz[sq][0] = gmb_xyY[sq][2] * gmb_xyY[sq][0] / gmb_xyY[sq][1]; - gmb_xyz[sq][1] = gmb_xyY[sq][2]; - gmb_xyz[sq][2] = gmb_xyY[sq][2] * - (1 - gmb_xyY[sq][0] - gmb_xyY[sq][1]) / gmb_xyY[sq][1]; - } - pseudoinverse (gmb_xyz, inverse, NSQ); - for (i=0; i < colors; i++) - for (j=0; j < 3; j++) - for (cam_xyz[i][j] = k=0; k < NSQ; k++) - cam_xyz[i][j] += gmb_cam[k][i] * inverse[k][j]; - cam_xyz_coeff (cam_xyz); -#ifdef DCRAW_VERBOSE - if (verbose) { - printf (" { \"%s %s\", %d,\n\t{", make, model, black); - num = 10000 / (cam_xyz[1][0] + cam_xyz[1][1] + cam_xyz[1][2]); - FORCC for (j=0; j < 3; j++) - printf ("%c%d", (c | j) ? ',':' ', (int) (cam_xyz[c][j] * num + 0.5)); - puts (" } },"); - } -#endif -#undef NSQ -} -#endif - -void CLASS hat_transform (float *temp, float *base, int st, int size, int sc) -{ - int i; - for (i=0; i < sc; i++) - temp[i] = 2*base[st*i] + base[st*(sc-i)] + base[st*(i+sc)]; - for (; i+sc < size; i++) - temp[i] = 2*base[st*i] + base[st*(i-sc)] + base[st*(i+sc)]; - for (; i < size; i++) - temp[i] = 2*base[st*i] + base[st*(i-sc)] + base[st*(2*size-2-(i+sc))]; -} - -#if !defined(LIBRAW_USE_OPENMP) -void CLASS wavelet_denoise() -{ - float *fimg=0, *temp, thold, mul[2], avg, diff; - int scale=1, size, lev, hpass, lpass, row, col, nc, c, i, wlast, blk[2]; - ushort *window[4]; - static const float noise[] = - { 0.8002,0.2735,0.1202,0.0585,0.0291,0.0152,0.0080,0.0044 }; - -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("Wavelet denoising...\n")); -#endif - - while (maximum << scale < 0x10000) scale++; - maximum <<= --scale; - black <<= scale; - FORC4 cblack[c] <<= scale; - if ((size = iheight*iwidth) < 0x15550000) - fimg = (float *) malloc ((size*3 + iheight + iwidth) * sizeof *fimg); - merror (fimg, "wavelet_denoise()"); - temp = fimg + size*3; - if ((nc = colors) == 3 && filters) nc++; - FORC(nc) { /* denoise R,G1,B,G3 individually */ - for (i=0; i < size; i++) - fimg[i] = 256 * sqrt((double)(image[i][c] << scale)); - for (hpass=lev=0; lev < 5; lev++) { - lpass = size*((lev & 1)+1); - for (row=0; row < iheight; row++) { - hat_transform (temp, fimg+hpass+row*iwidth, 1, iwidth, 1 << lev); - for (col=0; col < iwidth; col++) - fimg[lpass + row*iwidth + col] = temp[col] * 0.25; - } - for (col=0; col < iwidth; col++) { - hat_transform (temp, fimg+lpass+col, iwidth, iheight, 1 << lev); - for (row=0; row < iheight; row++) - fimg[lpass + row*iwidth + col] = temp[row] * 0.25; - } - thold = threshold * noise[lev]; - for (i=0; i < size; i++) { - fimg[hpass+i] -= fimg[lpass+i]; - if (fimg[hpass+i] < -thold) fimg[hpass+i] += thold; - else if (fimg[hpass+i] > thold) fimg[hpass+i] -= thold; - else fimg[hpass+i] = 0; - if (hpass) fimg[i] += fimg[hpass+i]; - } - hpass = lpass; - } - for (i=0; i < size; i++) - image[i][c] = CLIP(SQR(fimg[i]+fimg[lpass+i])/0x10000); - } - if (filters && colors == 3) { /* pull G1 and G3 closer together */ - for (row=0; row < 2; row++) { - mul[row] = 0.125 * pre_mul[FC(row+1,0) | 1] / pre_mul[FC(row,0) | 1]; - blk[row] = cblack[FC(row,0) | 1]; - } - for (i=0; i < 4; i++) - window[i] = (ushort *) fimg + width*i; - for (wlast=-1, row=1; row < height-1; row++) { - while (wlast < row+1) { - for (wlast++, i=0; i < 4; i++) - window[(i+3) & 3] = window[i]; - for (col = FC(wlast,1) & 1; col < width; col+=2) - window[2][col] = BAYER(wlast,col); - } - thold = threshold/512; - for (col = (FC(row,0) & 1)+1; col < width-1; col+=2) { - avg = ( window[0][col-1] + window[0][col+1] + - window[2][col-1] + window[2][col+1] - blk[~row & 1]*4 ) - * mul[row & 1] + (window[1][col] + blk[row & 1]) * 0.5; - avg = avg < 0 ? 0 : sqrt(avg); - diff = sqrt((double)(BAYER(row,col))) - avg; - if (diff < -thold) diff += thold; - else if (diff > thold) diff -= thold; - else diff = 0; - BAYER(row,col) = CLIP(SQR(avg+diff) + 0.5); - } - } - } - free (fimg); -} -#else /* LIBRAW_USE_OPENMP */ -void CLASS wavelet_denoise() -{ - float *fimg=0, *temp, thold, mul[2], avg, diff; - int scale=1, size, lev, hpass, lpass, row, col, nc, c, i, wlast, blk[2]; - ushort *window[4]; - static const float noise[] = - { 0.8002,0.2735,0.1202,0.0585,0.0291,0.0152,0.0080,0.0044 }; - -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("Wavelet denoising...\n")); -#endif - - while (maximum << scale < 0x10000) scale++; - maximum <<= --scale; - black <<= scale; - FORC4 cblack[c] <<= scale; - if ((size = iheight*iwidth) < 0x15550000) - fimg = (float *) malloc ((size*3 + iheight + iwidth) * sizeof *fimg); - merror (fimg, "wavelet_denoise()"); - temp = fimg + size*3; - if ((nc = colors) == 3 && filters) nc++; -#ifdef LIBRAW_LIBRARY_BUILD -#pragma omp parallel default(shared) private(i,col,row,thold,lev,lpass,hpass,temp,c) firstprivate(scale,size) -#endif - { - temp = (float*)malloc( (iheight + iwidth) * sizeof *fimg); - FORC(nc) { /* denoise R,G1,B,G3 individually */ -#ifdef LIBRAW_LIBRARY_BUILD -#pragma omp for -#endif - for (i=0; i < size; i++) - fimg[i] = 256 * sqrt((double)(image[i][c] << scale)); - for (hpass=lev=0; lev < 5; lev++) { - lpass = size*((lev & 1)+1); -#ifdef LIBRAW_LIBRARY_BUILD -#pragma omp for -#endif - for (row=0; row < iheight; row++) { - hat_transform (temp, fimg+hpass+row*iwidth, 1, iwidth, 1 << lev); - for (col=0; col < iwidth; col++) - fimg[lpass + row*iwidth + col] = temp[col] * 0.25; - } -#ifdef LIBRAW_LIBRARY_BUILD -#pragma omp for -#endif - for (col=0; col < iwidth; col++) { - hat_transform (temp, fimg+lpass+col, iwidth, iheight, 1 << lev); - for (row=0; row < iheight; row++) - fimg[lpass + row*iwidth + col] = temp[row] * 0.25; - } - thold = threshold * noise[lev]; -#ifdef LIBRAW_LIBRARY_BUILD -#pragma omp for -#endif - for (i=0; i < size; i++) { - fimg[hpass+i] -= fimg[lpass+i]; - if (fimg[hpass+i] < -thold) fimg[hpass+i] += thold; - else if (fimg[hpass+i] > thold) fimg[hpass+i] -= thold; - else fimg[hpass+i] = 0; - if (hpass) fimg[i] += fimg[hpass+i]; - } - hpass = lpass; - } -#ifdef LIBRAW_LIBRARY_BUILD -#pragma omp for -#endif - for (i=0; i < size; i++) - image[i][c] = CLIP(SQR(fimg[i]+fimg[lpass+i])/0x10000); - } - free(temp); - } /* end omp parallel */ -/* the following loops are hard to parallize, no idea yes, - * problem is wlast which is carrying dependency - * second part should be easyer, but did not yet get it right. - */ - if (filters && colors == 3) { /* pull G1 and G3 closer together */ - for (row=0; row < 2; row++){ - mul[row] = 0.125 * pre_mul[FC(row+1,0) | 1] / pre_mul[FC(row,0) | 1]; - blk[row] = cblack[FC(row,0) | 1]; - } - for (i=0; i < 4; i++) - window[i] = (ushort *) fimg + width*i; - for (wlast=-1, row=1; row < height-1; row++) { - while (wlast < row+1) { - for (wlast++, i=0; i < 4; i++) - window[(i+3) & 3] = window[i]; - for (col = FC(wlast,1) & 1; col < width; col+=2) - window[2][col] = BAYER(wlast,col); - } - thold = threshold/512; - for (col = (FC(row,0) & 1)+1; col < width-1; col+=2) { - avg = ( window[0][col-1] + window[0][col+1] + - window[2][col-1] + window[2][col+1] - blk[~row & 1]*4 ) - * mul[row & 1] + (window[1][col] + blk[row & 1]) * 0.5; - avg = avg < 0 ? 0 : sqrt(avg); - diff = sqrt((double)BAYER(row,col)) - avg; - if (diff < -thold) diff += thold; - else if (diff > thold) diff -= thold; - else diff = 0; - BAYER(row,col) = CLIP(SQR(avg+diff) + 0.5); - } - } - } - free (fimg); -} - -#endif - - - -// green equilibration -void CLASS green_matching() -{ - int i,j; - double m1,m2,c1,c2; - int o1_1,o1_2,o1_3,o1_4; - int o2_1,o2_2,o2_3,o2_4; - ushort (*img)[4]; - const int margin = 3; - int oj = 2, oi = 2; - float f; - const float thr = 0.01f; - if(half_size || shrink) return; - if(FC(oj, oi) != 3) oj++; - if(FC(oj, oi) != 3) oi++; - if(FC(oj, oi) != 3) oj--; - - img = (ushort (*)[4]) calloc (height*width, sizeof *image); - merror (img, "green_matching()"); - memcpy(img,image,height*width*sizeof *image); - - for(j=oj;j0xffff?0xffff:f; - } - } - free(img); -} - - -void CLASS scale_colors() -{ - unsigned bottom, right, size, row, col, ur, uc, x, y, c, sum[8]; - int val, dark, sat,i; - double dsum[8], dmin, dmax; - float scale_mul[4], fr, fc; - ushort *img=0, *pix; - -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_SCALE_COLORS,0,2); -#endif - - FORC4 cblack[c] += black; - if (user_mul[0]) - memcpy (pre_mul, user_mul, sizeof pre_mul); - if (use_auto_wb || (use_camera_wb && cam_mul[0] == -1)) { - memset (dsum, 0, sizeof dsum); - bottom = MIN (greybox[1]+greybox[3], height); - right = MIN (greybox[0]+greybox[2], width); - for (row=greybox[1]; row < bottom; row += 8) - for (col=greybox[0]; col < right; col += 8) { - memset (sum, 0, sizeof sum); - for (y=row; y < row+8 && y < bottom; y++) - for (x=col; x < col+8 && x < right; x++) - FORC4 { - if (filters) { - c = FC(y,x); - val = BAYER(y,x); - } else - val = image[y*width+x][c]; - if (val > maximum-25) goto skip_block; - if ((val -= cblack[c]) < 0) val = 0; - sum[c] += val; - sum[c+4]++; - if (filters) break; - } - FORC(8) dsum[c] += sum[c]; -skip_block: ; - } - FORC4 if (dsum[c]) pre_mul[c] = dsum[c+4] / dsum[c]; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.pre_mul_state = LIBRAW_COLORSTATE_CALCULATED; -#endif - } - if (use_camera_wb && cam_mul[0] != -1) { - memset (sum, 0, sizeof sum); - for (row=0; row < 8; row++) - for (col=0; col < 8; col++) { - c = FC(row,col); - if ((val = white[row][col] - cblack[c]) > 0) - sum[c] += val; - sum[c+4]++; - } - if (sum[0] && sum[1] && sum[2] && sum[3]) - { - FORC4 pre_mul[c] = (float) sum[c+4] / sum[c]; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.pre_mul_state = LIBRAW_COLORSTATE_CALCULATED; -#endif - } - else if (cam_mul[0] && cam_mul[2]) - { - memcpy (pre_mul, cam_mul, sizeof pre_mul); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.pre_mul_state =color_flags.pre_mul_state; -#endif - } - else - { -#ifdef LIBRAW_LIBRARY_BUILD - imgdata.process_warnings |= LIBRAW_WARN_BAD_CAMERA_WB; -#endif -#ifdef DCRAW_VERBOSE - fprintf (stderr,_("%s: Cannot use camera white balance.\n"), ifname); -#endif - } - } - if (pre_mul[3] == 0) pre_mul[3] = colors < 4 ? pre_mul[1] : 1; - dark = black; - sat = maximum; - if (threshold) wavelet_denoise(); - maximum -= black; - for (dmin=DBL_MAX, dmax=c=0; c < 4; c++) { - if (dmin > pre_mul[c]) - dmin = pre_mul[c]; - if (dmax < pre_mul[c]) - dmax = pre_mul[c]; - } - if (!highlight) dmax = dmin; - FORC4 scale_mul[c] = (pre_mul[c] /= dmax) * 65535.0 / maximum; -#ifdef DCRAW_VERBOSE - if (verbose) { - fprintf (stderr, - _("Scaling with darkness %d, saturation %d, and\nmultipliers"), dark, sat); - FORC4 fprintf (stderr, " %f", pre_mul[c]); - fputc ('\n', stderr); - } -#endif - - size = iheight*iwidth; -#if defined(LIBRAW_USE_OPENMP) -#pragma omp parallel for private(val) default(shared) -#endif - for (i=0; i < size*4; i++) { - val = image[0][i]; - if (!val) continue; - val -= cblack[i & 3]; - val *= scale_mul[i & 3]; - image[0][i] = CLIP(val); - } - if ((aber[0] != 1 || aber[2] != 1) && colors == 3) { -#ifdef DCRAW_VERBOSE - if (verbose) - fprintf (stderr,_("Correcting chromatic aberration...\n")); -#endif - for (c=0; c < 4; c+=2) { - if (aber[c] == 1) continue; - img = (ushort *) malloc (size * sizeof *img); - merror (img, "scale_colors()"); - for (i=0; i < size; i++) - img[i] = image[i][c]; - for (row=0; row < iheight; row++) { - ur = fr = (row - iheight*0.5) * aber[c] + iheight*0.5; - if (ur > iheight-2) continue; - fr -= ur; - for (col=0; col < iwidth; col++) { - uc = fc = (col - iwidth*0.5) * aber[c] + iwidth*0.5; - if (uc > iwidth-2) continue; - fc -= uc; - pix = img + ur*iwidth + uc; - image[row*iwidth+col][c] = - (pix[ 0]*(1-fc) + pix[ 1]*fc) * (1-fr) + - (pix[iwidth]*(1-fc) + pix[iwidth+1]*fc) * fr; - } - } - free(img); - } - } -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_SCALE_COLORS,1,2); -#endif -} - -void CLASS pre_interpolate() -{ - ushort (*img)[4]; - int row, col, c; - -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_PRE_INTERPOLATE,0,2); -#endif - if (shrink) { - if (half_size) { - height = iheight; - width = iwidth; - } else { - img = (ushort (*)[4]) calloc (height*width, sizeof *img); - merror (img, "pre_interpolate()"); - for (row=0; row < height; row++) - for (col=0; col < width; col++) { - c = fc(row,col); - img[row*width+col][c] = image[(row >> 1)*iwidth+(col >> 1)][c]; - } - free (image); - image = img; - shrink = 0; - } - } - if (filters && colors == 3) { - if (four_color_rgb && colors++) - mix_green = !half_size; - else { - for (row = FC(1,0) >> 1; row < height; row+=2) - for (col = FC(row,1) & 1; col < width; col+=2) - image[row*width+col][1] = image[row*width+col][3]; - filters &= ~((filters & 0x55555555) << 1); - } - } - if (half_size) filters = 0; -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_PRE_INTERPOLATE,1,2); -#endif -} - -void CLASS border_interpolate (int border) -{ - unsigned row, col, y, x, f, c, sum[8]; - - for (row=0; row < height; row++) - for (col=0; col < width; col++) { - if (col==border && row >= border && row < height-border) - col = width-border; - memset (sum, 0, sizeof sum); - for (y=row-1; y != row+2; y++) - for (x=col-1; x != col+2; x++) - if (y < height && x < width) { - f = fc(y,x); - sum[f] += image[y*width+x][f]; - sum[f+4]++; - } - f = fc(row,col); - FORCC if (c != f && sum[c+4]) - image[row*width+col][c] = sum[c] / sum[c+4]; - } -} - -void CLASS lin_interpolate() -{ - int code[16][16][32], *ip, sum[4]; - int c, i, x, y, row, col, shift, color; - ushort *pix; - -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("Bilinear interpolation...\n")); -#endif - -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_INTERPOLATE,0,3); -#endif - border_interpolate(1); - for (row=0; row < 16; row++) - for (col=0; col < 16; col++) { - ip = code[row][col]; - memset (sum, 0, sizeof sum); - for (y=-1; y <= 1; y++) - for (x=-1; x <= 1; x++) { - shift = (y==0) + (x==0); - if (shift == 2) continue; - color = fc(row+y,col+x); - *ip++ = (width*y + x)*4 + color; - *ip++ = shift; - *ip++ = color; - sum[color] += 1 << shift; - } - FORCC - if (c != fc(row,col)) { - *ip++ = c; - *ip++ = 256 / sum[c]; - } - } -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_INTERPOLATE,1,3); -#endif - for (row=1; row < height-1; row++) - for (col=1; col < width-1; col++) { - pix = image[row*width+col]; - ip = code[row & 15][col & 15]; - memset (sum, 0, sizeof sum); - for (i=8; i--; ip+=3) - sum[ip[2]] += pix[ip[0]] << ip[1]; - for (i=colors; --i; ip+=2) - pix[ip[0]] = sum[ip[0]] * ip[1] >> 8; - } -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_INTERPOLATE,2,3); -#endif -} - -/* - This algorithm is officially called: - - "Interpolation using a Threshold-based variable number of gradients" - - described in http://scien.stanford.edu/pages/labsite/1999/psych221/projects/99/tingchen/algodep/vargra.html - - I've extended the basic idea to work with non-Bayer filter arrays. - Gradients are numbered clockwise from NW=0 to W=7. - */ -void CLASS vng_interpolate() -{ - static const signed char *cp, terms[] = { - -2,-2,+0,-1,0,0x01, -2,-2,+0,+0,1,0x01, -2,-1,-1,+0,0,0x01, - -2,-1,+0,-1,0,0x02, -2,-1,+0,+0,0,0x03, -2,-1,+0,+1,1,0x01, - -2,+0,+0,-1,0,0x06, -2,+0,+0,+0,1,0x02, -2,+0,+0,+1,0,0x03, - -2,+1,-1,+0,0,0x04, -2,+1,+0,-1,1,0x04, -2,+1,+0,+0,0,0x06, - -2,+1,+0,+1,0,0x02, -2,+2,+0,+0,1,0x04, -2,+2,+0,+1,0,0x04, - -1,-2,-1,+0,0,0x80, -1,-2,+0,-1,0,0x01, -1,-2,+1,-1,0,0x01, - -1,-2,+1,+0,1,0x01, -1,-1,-1,+1,0,0x88, -1,-1,+1,-2,0,0x40, - -1,-1,+1,-1,0,0x22, -1,-1,+1,+0,0,0x33, -1,-1,+1,+1,1,0x11, - -1,+0,-1,+2,0,0x08, -1,+0,+0,-1,0,0x44, -1,+0,+0,+1,0,0x11, - -1,+0,+1,-2,1,0x40, -1,+0,+1,-1,0,0x66, -1,+0,+1,+0,1,0x22, - -1,+0,+1,+1,0,0x33, -1,+0,+1,+2,1,0x10, -1,+1,+1,-1,1,0x44, - -1,+1,+1,+0,0,0x66, -1,+1,+1,+1,0,0x22, -1,+1,+1,+2,0,0x10, - -1,+2,+0,+1,0,0x04, -1,+2,+1,+0,1,0x04, -1,+2,+1,+1,0,0x04, - +0,-2,+0,+0,1,0x80, +0,-1,+0,+1,1,0x88, +0,-1,+1,-2,0,0x40, - +0,-1,+1,+0,0,0x11, +0,-1,+2,-2,0,0x40, +0,-1,+2,-1,0,0x20, - +0,-1,+2,+0,0,0x30, +0,-1,+2,+1,1,0x10, +0,+0,+0,+2,1,0x08, - +0,+0,+2,-2,1,0x40, +0,+0,+2,-1,0,0x60, +0,+0,+2,+0,1,0x20, - +0,+0,+2,+1,0,0x30, +0,+0,+2,+2,1,0x10, +0,+1,+1,+0,0,0x44, - +0,+1,+1,+2,0,0x10, +0,+1,+2,-1,1,0x40, +0,+1,+2,+0,0,0x60, - +0,+1,+2,+1,0,0x20, +0,+1,+2,+2,0,0x10, +1,-2,+1,+0,0,0x80, - +1,-1,+1,+1,0,0x88, +1,+0,+1,+2,0,0x08, +1,+0,+2,-1,0,0x40, - +1,+0,+2,+1,0,0x10 - }, chood[] = { -1,-1, -1,0, -1,+1, 0,+1, +1,+1, +1,0, +1,-1, 0,-1 }; - ushort (*brow[5])[4], *pix; - int prow=7, pcol=1, *ip, *code[16][16], gval[8], gmin, gmax, sum[4]; - int row, col, x, y, x1, x2, y1, y2, t, weight, grads, color, diag; - int g, diff, thold, num, c; - lin_interpolate(); -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("VNG interpolation...\n")); -#endif - - if (filters == 1) prow = pcol = 15; - ip = (int *) calloc ((prow+1)*(pcol+1), 1280); - merror (ip, "vng_interpolate()"); - for (row=0; row <= prow; row++) /* Precalculate for VNG */ - for (col=0; col <= pcol; col++) { - code[row][col] = ip; - for (cp=terms, t=0; t < 64; t++) { - y1 = *cp++; x1 = *cp++; - y2 = *cp++; x2 = *cp++; - weight = *cp++; - grads = *cp++; - color = fc(row+y1,col+x1); - if (fc(row+y2,col+x2) != color) continue; - diag = (fc(row,col+1) == color && fc(row+1,col) == color) ? 2:1; - if (abs(y1-y2) == diag && abs(x1-x2) == diag) continue; - *ip++ = (y1*width + x1)*4 + color; - *ip++ = (y2*width + x2)*4 + color; - *ip++ = weight; - for (g=0; g < 8; g++) - if (grads & 1< gval[g]) gmin = gval[g]; - if (gmax < gval[g]) gmax = gval[g]; - } - if (gmax == 0) { - memcpy (brow[2][col], pix, sizeof *image); - continue; - } - thold = gmin + (gmax >> 1); - memset (sum, 0, sizeof sum); - color = fc(row,col); - for (num=g=0; g < 8; g++,ip+=2) { /* Average the neighbors */ - if (gval[g] <= thold) { - FORCC - if (c == color && ip[1]) - sum[c] += (pix[c] + pix[ip[1]]) >> 1; - else - sum[c] += pix[ip[0] + c]; - num++; - } - } - FORCC { /* Save to buffer */ - t = pix[color]; - if (c != color) - t += (sum[c] - sum[color]) / num; - brow[2][col][c] = CLIP(t); - } - } - if (row > 3) /* Write buffer to image */ - memcpy (image[(row-2)*width+2], brow[0]+2, (width-4)*sizeof *image); - for (g=0; g < 4; g++) - brow[(g-1) & 3] = brow[g]; - } - memcpy (image[(row-2)*width+2], brow[0]+2, (width-4)*sizeof *image); - memcpy (image[(row-1)*width+2], brow[1]+2, (width-4)*sizeof *image); - free (brow[4]); - free (code[0][0]); -} - -/* - Patterned Pixel Grouping Interpolation by Alain Desbiolles -*/ -void CLASS ppg_interpolate() -{ - int dir[5] = { 1, width, -1, -width, 1 }; - int row, col, diff[2], guess[2], c, d, i; - ushort (*pix)[4]; - - border_interpolate(3); -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("PPG interpolation...\n")); -#endif - -/* Fill in the green layer with gradients and pattern recognition: */ -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_INTERPOLATE,0,3); -#ifdef LIBRAW_USE_OPENMP -#pragma omp parallel for default(shared) private(guess, diff, row, col, d, c, i, pix) schedule(static) -#endif -#endif - for (row=3; row < height-3; row++) - for (col=3+(FC(row,3) & 1), c=FC(row,col); col < width-3; col+=2) { - pix = image + row*width+col; - for (i=0; (d=dir[i]) > 0; i++) { - guess[i] = (pix[-d][1] + pix[0][c] + pix[d][1]) * 2 - - pix[-2*d][c] - pix[2*d][c]; - diff[i] = ( ABS(pix[-2*d][c] - pix[ 0][c]) + - ABS(pix[ 2*d][c] - pix[ 0][c]) + - ABS(pix[ -d][1] - pix[ d][1]) ) * 3 + - ( ABS(pix[ 3*d][1] - pix[ d][1]) + - ABS(pix[-3*d][1] - pix[-d][1]) ) * 2; - } - d = dir[i = diff[0] > diff[1]]; - pix[0][1] = ULIM(guess[i] >> 2, pix[d][1], pix[-d][1]); - } -/* Calculate red and blue for each green pixel: */ -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_INTERPOLATE,1,3); -#ifdef LIBRAW_USE_OPENMP -#pragma omp parallel for default(shared) private(guess, diff, row, col, d, c, i, pix) schedule(static) -#endif -#endif - for (row=1; row < height-1; row++) - for (col=1+(FC(row,2) & 1), c=FC(row,col+1); col < width-1; col+=2) { - pix = image + row*width+col; - for (i=0; (d=dir[i]) > 0; c=2-c, i++) - pix[0][c] = CLIP((pix[-d][c] + pix[d][c] + 2*pix[0][1] - - pix[-d][1] - pix[d][1]) >> 1); - } -/* Calculate blue for red pixels and vice versa: */ -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_INTERPOLATE,2,3); -#ifdef LIBRAW_USE_OPENMP -#pragma omp parallel for default(shared) private(guess, diff, row, col, d, c, i, pix) schedule(static) -#endif -#endif - for (row=1; row < height-1; row++) - for (col=1+(FC(row,1) & 1), c=2-FC(row,col); col < width-1; col+=2) { - pix = image + row*width+col; - for (i=0; (d=dir[i]+dir[i+1]) > 0; i++) { - diff[i] = ABS(pix[-d][c] - pix[d][c]) + - ABS(pix[-d][1] - pix[0][1]) + - ABS(pix[ d][1] - pix[0][1]); - guess[i] = pix[-d][c] + pix[d][c] + 2*pix[0][1] - - pix[-d][1] - pix[d][1]; - } - if (diff[0] != diff[1]) - pix[0][c] = CLIP(guess[diff[0] > diff[1]] >> 1); - else - pix[0][c] = CLIP((guess[0]+guess[1]) >> 2); - } -} - -/* - Adaptive Homogeneity-Directed interpolation is based on - the work of Keigo Hirakawa, Thomas Parks, and Paul Lee. - */ -#define TS 256 /* Tile Size */ -static float dcraw_cbrt[0x10000] = {-1.0f}; - -static inline float calc_64cbrt(float f) -{ - unsigned u; - static float lower = dcraw_cbrt[0]; - static float upper = dcraw_cbrt[0xffff]; - - if (f <= 0) { - return lower; - } - - u = (unsigned) f; - if (u >= 0xffff) { - return upper; - } - return dcraw_cbrt[u]; -} -void CLASS ahd_interpolate_green_h_and_v(int top, int left, ushort (*out_rgb)[TS][TS][3]) -{ - int row, col; - int c, val; - ushort (*pix)[4]; - const int rowlimit = MIN(top+TS, height-2); - const int collimit = MIN(left+TS, width-2); - - for (row = top; row < rowlimit; row++) { - col = left + (FC(row,left) & 1); - for (c = FC(row,col); col < collimit; col+=2) { - pix = image + row*width+col; - val = ((pix[-1][1] + pix[0][c] + pix[1][1]) * 2 - - pix[-2][c] - pix[2][c]) >> 2; - out_rgb[0][row-top][col-left][1] = ULIM(val,pix[-1][1],pix[1][1]); - val = ((pix[-width][1] + pix[0][c] + pix[width][1]) * 2 - - pix[-2*width][c] - pix[2*width][c]) >> 2; - out_rgb[1][row-top][col-left][1] = ULIM(val,pix[-width][1],pix[width][1]); - } - } -} -void CLASS ahd_interpolate_r_and_b_in_rgb_and_convert_to_cielab(int top, int left, ushort (*inout_rgb)[TS][3], short (*out_lab)[TS][3], const float (&xyz_cam)[3][4]) -{ - unsigned row, col; - int c, val; - ushort (*pix)[4]; - ushort (*rix)[3]; - short (*lix)[3]; - float xyz[3]; - const unsigned num_pix_per_row = 4*width; - const unsigned rowlimit = MIN(top+TS-1, height-3); - const unsigned collimit = MIN(left+TS-1, width-3); - ushort *pix_above; - ushort *pix_below; - int t1, t2; - - for (row = top+1; row < rowlimit; row++) { - pix = image + row*width + left; - rix = &inout_rgb[row-top][0]; - lix = &out_lab[row-top][0]; - - for (col = left+1; col < collimit; col++) { - pix++; - pix_above = &pix[0][0] - num_pix_per_row; - pix_below = &pix[0][0] + num_pix_per_row; - rix++; - lix++; - - c = 2 - FC(row, col); - - if (c == 1) { - c = FC(row+1,col); - t1 = 2-c; - val = pix[0][1] + (( pix[-1][t1] + pix[1][t1] - - rix[-1][1] - rix[1][1] ) >> 1); - rix[0][t1] = CLIP(val); - val = pix[0][1] + (( pix_above[c] + pix_below[c] - - rix[-TS][1] - rix[TS][1] ) >> 1); - } else { - t1 = -4+c; /* -4+c: pixel of color c to the left */ - t2 = 4+c; /* 4+c: pixel of color c to the right */ - val = rix[0][1] + (( pix_above[t1] + pix_above[t2] - + pix_below[t1] + pix_below[t2] - - rix[-TS-1][1] - rix[-TS+1][1] - - rix[+TS-1][1] - rix[+TS+1][1] + 1) >> 2); - } - rix[0][c] = CLIP(val); - c = FC(row,col); - rix[0][c] = pix[0][c]; - xyz[0] = xyz[1] = xyz[2] = 0.5; - FORC3 { - /* - * Technically this ought to be FORCC, but the rest of - * ahd_interpolate() assumes 3 colors so let's help the compiler. - */ - xyz[0] += xyz_cam[0][c] * rix[0][c]; - xyz[1] += xyz_cam[1][c] * rix[0][c]; - xyz[2] += xyz_cam[2][c] * rix[0][c]; - } - FORC3 { - xyz[c] = calc_64cbrt(xyz[c]); - } - lix[0][0] = (116 * xyz[1] - 16); - lix[0][1] = 500 * (xyz[0] - xyz[1]); - lix[0][2] = 200 * (xyz[1] - xyz[2]); - } - } -} -void CLASS ahd_interpolate_r_and_b_and_convert_to_cielab(int top, int left, ushort (*inout_rgb)[TS][TS][3], short (*out_lab)[TS][TS][3], const float (&xyz_cam)[3][4]) -{ - int direction; - for (direction = 0; direction < 2; direction++) { - ahd_interpolate_r_and_b_in_rgb_and_convert_to_cielab(top, left, inout_rgb[direction], out_lab[direction], xyz_cam); - } -} -void CLASS ahd_interpolate_build_homogeneity_map(int top, int left, short (*lab)[TS][TS][3], char (*out_homogeneity_map)[TS][2]) -{ - int row, col; - int tr, tc; - int direction; - int i; - short (*lix)[3]; - short (*lixs[2])[3]; - short *adjacent_lix; - unsigned ldiff[2][4], abdiff[2][4], leps, abeps; - static const int dir[4] = { -1, 1, -TS, TS }; - const int rowlimit = MIN(top+TS-2, height-4); - const int collimit = MIN(left+TS-2, width-4); - int homogeneity; - char (*homogeneity_map_p)[2]; - - memset (out_homogeneity_map, 0, 2*TS*TS); - - for (row=top+2; row < rowlimit; row++) { - tr = row-top; - homogeneity_map_p = &out_homogeneity_map[tr][1]; - for (direction=0; direction < 2; direction++) { - lixs[direction] = &lab[direction][tr][1]; - } - - for (col=left+2; col < collimit; col++) { - tc = col-left; - homogeneity_map_p++; - - for (direction=0; direction < 2; direction++) { - lix = ++lixs[direction]; - for (i=0; i < 4; i++) { - adjacent_lix = lix[dir[i]]; - ldiff[direction][i] = ABS(lix[0][0]-adjacent_lix[0]); - abdiff[direction][i] = SQR(lix[0][1]-adjacent_lix[1]) - + SQR(lix[0][2]-adjacent_lix[2]); - } - } - leps = MIN(MAX(ldiff[0][0],ldiff[0][1]), - MAX(ldiff[1][2],ldiff[1][3])); - abeps = MIN(MAX(abdiff[0][0],abdiff[0][1]), - MAX(abdiff[1][2],abdiff[1][3])); - for (direction=0; direction < 2; direction++) { - homogeneity = 0; - for (i=0; i < 4; i++) { - if (ldiff[direction][i] <= leps && abdiff[direction][i] <= abeps) { - homogeneity++; - } - } - homogeneity_map_p[0][direction] = homogeneity; - } - } - } -} -void CLASS ahd_interpolate_combine_homogeneous_pixels(int top, int left, ushort (*rgb)[TS][TS][3], char (*homogeneity_map)[TS][2]) -{ - int row, col; - int tr, tc; - int i, j; - int direction; - int hm[2]; - int c; - const int rowlimit = MIN(top+TS-3, height-5); - const int collimit = MIN(left+TS-3, width-5); - - ushort (*pix)[4]; - ushort (*rix[2])[3]; - - for (row=top+3; row < rowlimit; row++) { - tr = row-top; - pix = &image[row*width+left+2]; - for (direction = 0; direction < 2; direction++) { - rix[direction] = &rgb[direction][tr][2]; - } - - for (col=left+3; col < collimit; col++) { - tc = col-left; - pix++; - for (direction = 0; direction < 2; direction++) { - rix[direction]++; - } - - for (direction=0; direction < 2; direction++) { - hm[direction] = 0; - for (i=tr-1; i <= tr+1; i++) { - for (j=tc-1; j <= tc+1; j++) { - hm[direction] += homogeneity_map[i][j][direction]; - } - } - } - if (hm[0] != hm[1]) { - memcpy(pix[0], rix[hm[1] > hm[0]][0], 3 * sizeof(ushort)); - } else { - FORC3 { - pix[0][c] = (rix[0][0][c] + rix[1][0][c]) >> 1; - } - } - } - } -} -void CLASS ahd_interpolate() -{ - int i, j, k, top, left; - float xyz_cam[3][4],r; - char *buffer; - ushort (*rgb)[TS][TS][3]; - short (*lab)[TS][TS][3]; - char (*homo)[TS][2]; - int terminate_flag = 0; - - if(dcraw_cbrt[0]<-0.1){ - for (i=0x10000-1; i >=0; i--) { - r = i / 65535.0; - dcraw_cbrt[i] = 64.0*(r > 0.008856 ? pow((double)r,1/3.0) : 7.787*r + 16/116.0); - } - } - -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("AHD interpolation...\n")); -#endif - - for (i=0; i < 3; i++) { - for (j=0; j < colors; j++) { - xyz_cam[i][j] = 0; - for (k=0; k < 3; k++) { - xyz_cam[i][j] += xyz_rgb[i][k] * rgb_cam[k][j] / d65_white[i]; - } - } - } - - border_interpolate(5); - -#ifdef LIBRAW_LIBRARY_BUILD -#ifdef LIBRAW_USE_OPENMP -#pragma omp parallel private(buffer,rgb,lab,homo,top,left,i,j,k) shared(xyz_cam,terminate_flag) -#endif -#endif - { - buffer = (char *) malloc (26*TS*TS); /* 1664 kB */ - merror (buffer, "ahd_interpolate()"); - rgb = (ushort(*)[TS][TS][3]) buffer; - lab = (short (*)[TS][TS][3])(buffer + 12*TS*TS); - homo = (char (*)[TS][2]) (buffer + 24*TS*TS); - -#ifdef LIBRAW_LIBRARY_BUILD -#ifdef LIBRAW_USE_OPENMP -#pragma omp for schedule(dynamic) -#endif -#endif - for (top=2; top < height-5; top += TS-6){ -#ifdef LIBRAW_LIBRARY_BUILD -#ifdef LIBRAW_USE_OPENMP - if(0== omp_get_thread_num()) -#endif - if(callbacks.progress_cb) { - int rr = (*callbacks.progress_cb)(callbacks.progresscb_data,LIBRAW_PROGRESS_INTERPOLATE,top-2,height-7); - if(rr) - terminate_flag = 1; - } -#endif - for (left=2; !terminate_flag && (left < width-5); left += TS-6) { - ahd_interpolate_green_h_and_v(top, left, rgb); - ahd_interpolate_r_and_b_and_convert_to_cielab(top, left, rgb, lab, xyz_cam); - ahd_interpolate_build_homogeneity_map(top, left, lab, homo); - ahd_interpolate_combine_homogeneous_pixels(top, left, rgb, homo); - } - } - free (buffer); - } -#ifdef LIBRAW_LIBRARY_BUILD - if(terminate_flag) - throw LIBRAW_EXCEPTION_CANCELLED_BY_CALLBACK; -#endif -} - - - -#undef TS - -void CLASS median_filter() -{ - ushort (*pix)[4]; - int pass, c, i, j, k, med[9]; - static const uchar opt[] = /* Optimal 9-element median search */ - { 1,2, 4,5, 7,8, 0,1, 3,4, 6,7, 1,2, 4,5, 7,8, - 0,3, 5,8, 4,7, 3,6, 1,4, 2,5, 4,7, 4,2, 6,4, 4,2 }; - - for (pass=1; pass <= med_passes; pass++) { -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_MEDIAN_FILTER,pass-1,med_passes); -#endif -#ifdef DCRAW_VERBOSE - if (verbose) - fprintf (stderr,_("Median filter pass %d...\n"), pass); -#endif - for (c=0; c < 3; c+=2) { - for (pix = image; pix < image+width*height; pix++) - pix[0][3] = pix[0][c]; - for (pix = image+width; pix < image+width*(height-1); pix++) { - if ((pix-image+1) % width < 2) continue; - for (k=0, i = -width; i <= width; i += width) - for (j = i-1; j <= i+1; j++) - med[k++] = pix[j][3] - pix[j][1]; - for (i=0; i < sizeof opt; i+=2) - if (med[opt[i]] > med[opt[i+1]]) - SWAP (med[opt[i]] , med[opt[i+1]]); - pix[0][c] = CLIP(med[4] + pix[0][1]); - } - } - } -} - -void CLASS blend_highlights() -{ - int clip=INT_MAX, row, col, c, i, j; - static const float trans[2][4][4] = - { { { 1,1,1 }, { 1.7320508,-1.7320508,0 }, { -1,-1,2 } }, - { { 1,1,1,1 }, { 1,-1,1,-1 }, { 1,1,-1,-1 }, { 1,-1,-1,1 } } }; - static const float itrans[2][4][4] = - { { { 1,0.8660254,-0.5 }, { 1,-0.8660254,-0.5 }, { 1,0,1 } }, - { { 1,1,1,1 }, { 1,-1,1,-1 }, { 1,1,-1,-1 }, { 1,-1,-1,1 } } }; - float cam[2][4], lab[2][4], sum[2], chratio; - - if ((unsigned) (colors-3) > 1) return; -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("Blending highlights...\n")); -#endif - FORCC if (clip > (i = 65535*pre_mul[c])) clip = i; -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_HIGHLIGHTS,0,2); -#endif - for (row=0; row < height; row++) - for (col=0; col < width; col++) { - FORCC if (image[row*width+col][c] > clip) break; - if (c == colors) continue; - FORCC { - cam[0][c] = image[row*width+col][c]; - cam[1][c] = MIN(cam[0][c],clip); - } - for (i=0; i < 2; i++) { - FORCC for (lab[i][c]=j=0; j < colors; j++) - lab[i][c] += trans[colors-3][c][j] * cam[i][j]; - for (sum[i]=0,c=1; c < colors; c++) - sum[i] += SQR(lab[i][c]); - } - chratio = sqrt(sum[1]/sum[0]); - for (c=1; c < colors; c++) - lab[0][c] *= chratio; - FORCC for (cam[0][c]=j=0; j < colors; j++) - cam[0][c] += itrans[colors-3][c][j] * lab[0][j]; - FORCC image[row*width+col][c] = cam[0][c] / colors; - } -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_HIGHLIGHTS,1,2); -#endif -} - -#define SCALE (4 >> shrink) -void CLASS recover_highlights() -{ - float *map, sum, wgt, grow; - int hsat[4], count, spread, change, val, i; - unsigned high, wide, mrow, mcol, row, col, kc, c, d, y, x; - ushort *pixel; - static const signed char dir[8][2] = - { {-1,-1}, {-1,0}, {-1,1}, {0,1}, {1,1}, {1,0}, {1,-1}, {0,-1} }; - -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("Rebuilding highlights...\n")); -#endif - - grow = pow (2.0, 4.0-highlight); - FORCC hsat[c] = 32000 * pre_mul[c]; - for (kc=0, c=1; c < colors; c++) - if (pre_mul[kc] < pre_mul[c]) kc = c; - high = height / SCALE; - wide = width / SCALE; - map = (float *) calloc (high*wide, sizeof *map); - merror (map, "recover_highlights()"); - FORCC if (c != kc) { -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_HIGHLIGHTS,c-1,colors-1); -#endif - memset (map, 0, high*wide*sizeof *map); - for (mrow=0; mrow < high; mrow++) - for (mcol=0; mcol < wide; mcol++) { - sum = wgt = count = 0; - for (row = mrow*SCALE; row < (mrow+1)*SCALE; row++) - for (col = mcol*SCALE; col < (mcol+1)*SCALE; col++) { - pixel = image[row*width+col]; - if (pixel[c] / hsat[c] == 1 && pixel[kc] > 24000) { - sum += pixel[c]; - wgt += pixel[kc]; - count++; - } - } - if (count == SCALE*SCALE) - map[mrow*wide+mcol] = sum / wgt; - } - for (spread = 32/grow; spread--; ) { - for (mrow=0; mrow < high; mrow++) - for (mcol=0; mcol < wide; mcol++) { - if (map[mrow*wide+mcol]) continue; - sum = count = 0; - for (d=0; d < 8; d++) { - y = mrow + dir[d][0]; - x = mcol + dir[d][1]; - if (y < high && x < wide && map[y*wide+x] > 0) { - sum += (1 + (d & 1)) * map[y*wide+x]; - count += 1 + (d & 1); - } - } - if (count > 3) - map[mrow*wide+mcol] = - (sum+grow) / (count+grow); - } - for (change=i=0; i < high*wide; i++) - if (map[i] < 0) { - map[i] = -map[i]; - change = 1; - } - if (!change) break; - } - for (i=0; i < high*wide; i++) - if (map[i] == 0) map[i] = 1; - for (mrow=0; mrow < high; mrow++) - for (mcol=0; mcol < wide; mcol++) { - for (row = mrow*SCALE; row < (mrow+1)*SCALE; row++) - for (col = mcol*SCALE; col < (mcol+1)*SCALE; col++) { - pixel = image[row*width+col]; - if (pixel[c] / hsat[c] > 1) { - val = pixel[kc] * map[mrow*wide+mcol]; - if (pixel[c] < val) pixel[c] = CLIP(val); - } - } - } - } - free (map); -} -#undef SCALE - -void CLASS tiff_get (unsigned base, - unsigned *tag, unsigned *type, unsigned *len, unsigned *save) -{ - *tag = get2(); - *type = get2(); - *len = get4(); - *save = ftell(ifp) + 4; - if (*len * ("11124811248488"[*type < 14 ? *type:0]-'0') > 4) - fseek (ifp, get4()+base, SEEK_SET); -} - -void CLASS parse_thumb_note (int base, unsigned toff, unsigned tlen) -{ - unsigned entries, tag, type, len, save; - - entries = get2(); - while (entries--) { - tiff_get (base, &tag, &type, &len, &save); - if (tag == toff) thumb_offset = get4()+base; - if (tag == tlen) thumb_length = get4(); - fseek (ifp, save, SEEK_SET); - } -} - -void CLASS parse_makernote (int base, int uptag) -{ - static const uchar xlat[2][256] = { - { 0xc1,0xbf,0x6d,0x0d,0x59,0xc5,0x13,0x9d,0x83,0x61,0x6b,0x4f,0xc7,0x7f,0x3d,0x3d, - 0x53,0x59,0xe3,0xc7,0xe9,0x2f,0x95,0xa7,0x95,0x1f,0xdf,0x7f,0x2b,0x29,0xc7,0x0d, - 0xdf,0x07,0xef,0x71,0x89,0x3d,0x13,0x3d,0x3b,0x13,0xfb,0x0d,0x89,0xc1,0x65,0x1f, - 0xb3,0x0d,0x6b,0x29,0xe3,0xfb,0xef,0xa3,0x6b,0x47,0x7f,0x95,0x35,0xa7,0x47,0x4f, - 0xc7,0xf1,0x59,0x95,0x35,0x11,0x29,0x61,0xf1,0x3d,0xb3,0x2b,0x0d,0x43,0x89,0xc1, - 0x9d,0x9d,0x89,0x65,0xf1,0xe9,0xdf,0xbf,0x3d,0x7f,0x53,0x97,0xe5,0xe9,0x95,0x17, - 0x1d,0x3d,0x8b,0xfb,0xc7,0xe3,0x67,0xa7,0x07,0xf1,0x71,0xa7,0x53,0xb5,0x29,0x89, - 0xe5,0x2b,0xa7,0x17,0x29,0xe9,0x4f,0xc5,0x65,0x6d,0x6b,0xef,0x0d,0x89,0x49,0x2f, - 0xb3,0x43,0x53,0x65,0x1d,0x49,0xa3,0x13,0x89,0x59,0xef,0x6b,0xef,0x65,0x1d,0x0b, - 0x59,0x13,0xe3,0x4f,0x9d,0xb3,0x29,0x43,0x2b,0x07,0x1d,0x95,0x59,0x59,0x47,0xfb, - 0xe5,0xe9,0x61,0x47,0x2f,0x35,0x7f,0x17,0x7f,0xef,0x7f,0x95,0x95,0x71,0xd3,0xa3, - 0x0b,0x71,0xa3,0xad,0x0b,0x3b,0xb5,0xfb,0xa3,0xbf,0x4f,0x83,0x1d,0xad,0xe9,0x2f, - 0x71,0x65,0xa3,0xe5,0x07,0x35,0x3d,0x0d,0xb5,0xe9,0xe5,0x47,0x3b,0x9d,0xef,0x35, - 0xa3,0xbf,0xb3,0xdf,0x53,0xd3,0x97,0x53,0x49,0x71,0x07,0x35,0x61,0x71,0x2f,0x43, - 0x2f,0x11,0xdf,0x17,0x97,0xfb,0x95,0x3b,0x7f,0x6b,0xd3,0x25,0xbf,0xad,0xc7,0xc5, - 0xc5,0xb5,0x8b,0xef,0x2f,0xd3,0x07,0x6b,0x25,0x49,0x95,0x25,0x49,0x6d,0x71,0xc7 }, - { 0xa7,0xbc,0xc9,0xad,0x91,0xdf,0x85,0xe5,0xd4,0x78,0xd5,0x17,0x46,0x7c,0x29,0x4c, - 0x4d,0x03,0xe9,0x25,0x68,0x11,0x86,0xb3,0xbd,0xf7,0x6f,0x61,0x22,0xa2,0x26,0x34, - 0x2a,0xbe,0x1e,0x46,0x14,0x68,0x9d,0x44,0x18,0xc2,0x40,0xf4,0x7e,0x5f,0x1b,0xad, - 0x0b,0x94,0xb6,0x67,0xb4,0x0b,0xe1,0xea,0x95,0x9c,0x66,0xdc,0xe7,0x5d,0x6c,0x05, - 0xda,0xd5,0xdf,0x7a,0xef,0xf6,0xdb,0x1f,0x82,0x4c,0xc0,0x68,0x47,0xa1,0xbd,0xee, - 0x39,0x50,0x56,0x4a,0xdd,0xdf,0xa5,0xf8,0xc6,0xda,0xca,0x90,0xca,0x01,0x42,0x9d, - 0x8b,0x0c,0x73,0x43,0x75,0x05,0x94,0xde,0x24,0xb3,0x80,0x34,0xe5,0x2c,0xdc,0x9b, - 0x3f,0xca,0x33,0x45,0xd0,0xdb,0x5f,0xf5,0x52,0xc3,0x21,0xda,0xe2,0x22,0x72,0x6b, - 0x3e,0xd0,0x5b,0xa8,0x87,0x8c,0x06,0x5d,0x0f,0xdd,0x09,0x19,0x93,0xd0,0xb9,0xfc, - 0x8b,0x0f,0x84,0x60,0x33,0x1c,0x9b,0x45,0xf1,0xf0,0xa3,0x94,0x3a,0x12,0x77,0x33, - 0x4d,0x44,0x78,0x28,0x3c,0x9e,0xfd,0x65,0x57,0x16,0x94,0x6b,0xfb,0x59,0xd0,0xc8, - 0x22,0x36,0xdb,0xd2,0x63,0x98,0x43,0xa1,0x04,0x87,0x86,0xf7,0xa6,0x26,0xbb,0xd6, - 0x59,0x4d,0xbf,0x6a,0x2e,0xaa,0x2b,0xef,0xe6,0x78,0xb6,0x4e,0xe0,0x2f,0xdc,0x7c, - 0xbe,0x57,0x19,0x32,0x7e,0x2a,0xd0,0xb8,0xba,0x29,0x00,0x3c,0x52,0x7d,0xa8,0x49, - 0x3b,0x2d,0xeb,0x25,0x49,0xfa,0xa3,0xaa,0x39,0xa7,0xc5,0xa7,0x50,0x11,0x36,0xfb, - 0xc6,0x67,0x4a,0xf5,0xa5,0x12,0x65,0x7e,0xb0,0xdf,0xaf,0x4e,0xb3,0x61,0x7f,0x2f } }; - unsigned offset=0, entries, tag, type, len, save, c; - unsigned ver97=0, serial=0, i, wbi=0, wb[4]={0,0,0,0}; - uchar buf97[324], ci, cj, ck; - short morder, sorder=order; - char buf[10]; -/* - The MakerNote might have its own TIFF header (possibly with - its own byte-order!), or it might just be a table. - */ - if (!strcmp(make,"Nokia")) return; - fread (buf, 1, 10, ifp); - if (!strncmp (buf,"KDK" ,3) || /* these aren't TIFF tables */ - !strncmp (buf,"VER" ,3) || - !strncmp (buf,"IIII",4) || - !strncmp (buf,"MMMM",4)) return; - if (!strncmp (buf,"KC" ,2) || /* Konica KD-400Z, KD-510Z */ - !strncmp (buf,"MLY" ,3)) { /* Minolta DiMAGE G series */ - order = 0x4d4d; - while ((i=ftell(ifp)) < data_offset && i < 16384) { - wb[0] = wb[2]; wb[2] = wb[1]; wb[1] = wb[3]; - wb[3] = get2(); - if (wb[1] == 256 && wb[3] == 256 && - wb[0] > 256 && wb[0] < 640 && wb[2] > 256 && wb[2] < 640) - FORC4 cam_mul[c] = wb[c]; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - goto quit; - } - if (!strcmp (buf,"Nikon")) { - base = ftell(ifp); - order = get2(); - if (get2() != 42) goto quit; - offset = get4(); - fseek (ifp, offset-8, SEEK_CUR); - } else if (!strcmp (buf,"OLYMPUS")) { - base = ftell(ifp)-10; - fseek (ifp, -2, SEEK_CUR); - order = get2(); get2(); - } else if (!strncmp (buf,"SONY",4) || - !strcmp (buf,"Panasonic")) { - goto nf; - } else if (!strncmp (buf,"FUJIFILM",8)) { - base = ftell(ifp)-10; -nf: order = 0x4949; - fseek (ifp, 2, SEEK_CUR); - } else if (!strcmp (buf,"OLYMP") || - !strcmp (buf,"LEICA") || - !strcmp (buf,"Ricoh") || - !strcmp (buf,"EPSON")) - fseek (ifp, -2, SEEK_CUR); - else if (!strcmp (buf,"AOC") || - !strcmp (buf,"QVC")) - fseek (ifp, -4, SEEK_CUR); - else { - fseek (ifp, -10, SEEK_CUR); - if (!strncmp(make,"SAMSUNG",7)) - base = ftell(ifp); - } - entries = get2(); - if (entries > 1000) return; - morder = order; - while (entries--) { - order = morder; - tiff_get (base, &tag, &type, &len, &save); - tag |= uptag << 16; - if (tag == 2 && strstr(make,"NIKON") && !iso_speed) - iso_speed = (get2(),get2()); - if (tag == 4 && len > 26 && len < 35) { - if ((i=(get4(),get2())) != 0x7fff && !iso_speed) - iso_speed = 50 * pow (2.0, i/32.0 - 4); - if ((i=(get2(),get2())) != 0x7fff && !aperture) - aperture = pow (2.0, i/64.0); - if ((i=get2()) != 0xffff && !shutter) - shutter = pow (2.0, (short) i/-32.0); - wbi = (get2(),get2()); - shot_order = (get2(),get2()); - } - if ((tag == 4 || tag == 0x114) && !strncmp(make,"KONICA",6)) { - fseek (ifp, tag == 4 ? 140:160, SEEK_CUR); - switch (get2()) { - case 72: flip = 0; break; - case 76: flip = 6; break; - case 82: flip = 5; break; - } - } - if (tag == 7 && type == 2 && len > 20) - fgets (model2, 64, ifp); - if (tag == 8 && type == 4) - shot_order = get4(); - if (tag == 9 && !strcmp(make,"Canon")) - fread (artist, 64, 1, ifp); - if (tag == 0xc && len == 4) { - cam_mul[0] = getreal(type); - cam_mul[2] = getreal(type); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - if (tag == 0xd && type == 7 && get2() == 0xaaaa) { - for (c=i=2; (ushort) c != 0xbbbb && i < len; i++) - c = c << 8 | fgetc(ifp); - while ((i+=4) < len-5) - if (get4() == 257 && (i=len) && (c = (get4(),fgetc(ifp))) < 3) - flip = "065"[c]-'0'; - } - if (tag == 0x10 && type == 4) - unique_id = get4(); - if (tag == 0x11 && is_raw && !strncmp(make,"NIKON",5)) { - fseek (ifp, get4()+base, SEEK_SET); - parse_tiff_ifd (base); - } - if (tag == 0x14 && type == 7) { - if (len == 2560) { - fseek (ifp, 1248, SEEK_CUR); - goto get2_256; - } - fread (buf, 1, 10, ifp); - if (!strncmp(buf,"NRW ",4)) { - fseek (ifp, strcmp(buf+4,"0100") ? 46:1546, SEEK_CUR); - cam_mul[0] = get4() << 2; - cam_mul[1] = get4() + get4(); - cam_mul[2] = get4() << 2; - } - } - if (tag == 0x15 && type == 2 && is_raw) - fread (model, 64, 1, ifp); - if (strstr(make,"PENTAX")) { - if (tag == 0x1b) tag = 0x1018; - if (tag == 0x1c) tag = 0x1017; - } - if (tag == 0x1d) - while ((c = fgetc(ifp)) && c != EOF) - serial = serial*10 + (isdigit(c) ? c - '0' : c % 10); - if (tag == 0x81 && type == 4) { - data_offset = get4(); - fseek (ifp, data_offset + 41, SEEK_SET); - raw_height = get2() * 2; - raw_width = get2(); - filters = 0x61616161; - } - if (tag == 0x29 && type == 1) { - c = wbi < 18 ? "012347800000005896"[wbi]-'0' : 0; - fseek (ifp, 8 + c*32, SEEK_CUR); - FORC4 cam_mul[c ^ (c >> 1) ^ 1] = get4(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - if ((tag == 0x81 && type == 7) || - (tag == 0x100 && type == 7) || - (tag == 0x280 && type == 1)) { - thumb_offset = ftell(ifp); - thumb_length = len; - } - if (tag == 0x88 && type == 4 && (thumb_offset = get4())) - thumb_offset += base; - if (tag == 0x89 && type == 4) - thumb_length = get4(); - if (tag == 0x8c || tag == 0x96) - meta_offset = ftell(ifp); - if (tag == 0x97) { - for (i=0; i < 4; i++) - ver97 = ver97 * 10 + fgetc(ifp)-'0'; - switch (ver97) { - case 100: - fseek (ifp, 68, SEEK_CUR); - FORC4 cam_mul[(c >> 1) | ((c & 1) << 1)] = get2(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - break; - case 102: - fseek (ifp, 6, SEEK_CUR); - goto get2_rggb; - case 103: - fseek (ifp, 16, SEEK_CUR); - FORC4 cam_mul[c] = get2(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - if (ver97 >= 200) { - if (ver97 != 205) fseek (ifp, 280, SEEK_CUR); - fread (buf97, 324, 1, ifp); - } - } - if (tag == 0xa1 && type == 7) { - order = 0x4949; - fseek (ifp, 140, SEEK_CUR); - FORC3 cam_mul[c] = get4(); - } - if (tag == 0xa4 && type == 3) { - fseek (ifp, wbi*48, SEEK_CUR); - FORC3 cam_mul[c] = get2(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - if (tag == 0xa7 && (unsigned) (ver97-200) < 17) { - ci = xlat[0][serial & 0xff]; - cj = xlat[1][fgetc(ifp)^fgetc(ifp)^fgetc(ifp)^fgetc(ifp)]; - ck = 0x60; - for (i=0; i < 324; i++) - buf97[i] ^= (cj += ci * ck++); - i = "66666>666;6A;:;55"[ver97-200] - '0'; - FORC4 cam_mul[c ^ (c >> 1) ^ (i & 1)] = - sget2 (buf97 + (i & -2) + c*2); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - if (tag == 0x200 && len == 3) - shot_order = (get4(),get4()); - if (tag == 0x200 && len == 4) - FORC4 cblack[c ^ c >> 1] = get2(); - if (tag == 0x201 && len == 4) - goto get2_rggb; - if (tag == 0x220 && type == 7) - meta_offset = ftell(ifp); - if (tag == 0x401 && type == 4 && len == 4) - FORC4 cblack[c ^ c >> 1] = get4(); - if (tag == 0xe01) { /* Nikon Capture Note */ - order = 0x4949; - fseek (ifp, 22, SEEK_CUR); - for (offset=22; offset+22 < len; offset += 22+i) { - tag = get4(); - fseek (ifp, 14, SEEK_CUR); - i = get4()-4; - if (tag == 0x76a43207) flip = get2(); - else fseek (ifp, i, SEEK_CUR); - } - } - if (tag == 0xe80 && len == 256 && type == 7) { - fseek (ifp, 48, SEEK_CUR); - cam_mul[0] = get2() * 508 * 1.078 / 0x10000; - cam_mul[2] = get2() * 382 * 1.173 / 0x10000; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - if (tag == 0xf00 && type == 7) { - if (len == 614) - fseek (ifp, 176, SEEK_CUR); - else if (len == 734 || len == 1502) - fseek (ifp, 148, SEEK_CUR); - else goto next; - goto get2_256; - } - if ((tag == 0x1011 && len == 9) || tag == 0x20400200) - { - for (i=0; i < 3; i++) - FORC3 cmatrix[i][c] = ((short) get2()) / 256.0; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cmatrix_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - if ((tag == 0x1012 || tag == 0x20400600) && len == 4) - FORC4 cblack[c ^ c >> 1] = get2(); - if (tag == 0x1017 || tag == 0x20400100) - { - cam_mul[0] = get2() / 256.0; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - if (tag == 0x1018 || tag == 0x20400100) - { - cam_mul[2] = get2() / 256.0; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - if (tag == 0x2011 && len == 2) { -get2_256: - order = 0x4d4d; - cam_mul[0] = get2() / 256.0; - cam_mul[2] = get2() / 256.0; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - if ((tag | 0x70) == 0x2070 && type == 4) - fseek (ifp, get4()+base, SEEK_SET); - if (tag == 0x2010 && type != 7) - load_raw = &CLASS olympus_load_raw; - if (tag == 0x2020) - parse_thumb_note (base, 257, 258); - if (tag == 0x2040) - parse_makernote (base, 0x2040); - if (tag == 0xb028) { - fseek (ifp, get4()+base, SEEK_SET); - parse_thumb_note (base, 136, 137); - } - if (tag == 0x4001 && len > 500) { - i = len == 582 ? 50 : len == 653 ? 68 : len == 5120 ? 142 : 126; - fseek (ifp, i, SEEK_CUR); -get2_rggb: - FORC4 cam_mul[c ^ (c >> 1)] = get2(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif -#if 1 - i = len == 1312 ? 112:22; - fseek (ifp, i, SEEK_CUR); -#else - fseek (ifp, 22, SEEK_CUR); -#endif - FORC4 sraw_mul[c ^ (c >> 1)] = get2(); - } - if (tag == 0xa021) - FORC4 cam_mul[c ^ (c >> 1)] = get4(); - if (tag == 0xa028) - FORC4 cam_mul[c ^ (c >> 1)] -= get4(); -next: - fseek (ifp, save, SEEK_SET); - } -quit: - order = sorder; -} - -/* - Since the TIFF DateTime string has no timezone information, - assume that the camera's clock was set to Universal Time. - */ -void CLASS get_timestamp (int reversed) -{ - struct tm t; - char str[20]; - int i; - - str[19] = 0; - if (reversed) - for (i=19; i--; ) str[i] = fgetc(ifp); - else - fread (str, 19, 1, ifp); - memset (&t, 0, sizeof t); - if (sscanf (str, "%d:%d:%d %d:%d:%d", &t.tm_year, &t.tm_mon, - &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec) != 6) - return; - t.tm_year -= 1900; - t.tm_mon -= 1; - t.tm_isdst = -1; - if (mktime(&t) > 0) - timestamp = mktime(&t); -} - -void CLASS parse_exif (int base) -{ - unsigned kodak, entries, tag, type, len, save, c; - double expo; - - kodak = !strncmp(make,"EASTMAN",7) && tiff_nifds < 3; - entries = get2(); - while (entries--) { - tiff_get (base, &tag, &type, &len, &save); - switch (tag) { - case 33434: shutter = getreal(type); break; - case 33437: aperture = getreal(type); break; - case 34855: iso_speed = get2(); break; - case 36867: - case 36868: get_timestamp(0); break; - case 37377: if ((expo = -getreal(type)) < 128) - shutter = pow (2.0, expo); break; - case 37378: aperture = pow (2.0, getreal(type)/2); break; - case 37386: focal_len = getreal(type); break; - case 37500: parse_makernote (base, 0); break; - case 40962: if (kodak) raw_width = get4(); break; - case 40963: if (kodak) raw_height = get4(); break; - case 41730: - if (get4() == 0x20002) - for (exif_cfa=c=0; c < 8; c+=2) - exif_cfa |= fgetc(ifp) * 0x01010101 << c; - } - fseek (ifp, save, SEEK_SET); - } -} - -void CLASS parse_gps (int base) -{ - unsigned entries, tag, type, len, save, c; - - entries = get2(); - while (entries--) { - tiff_get (base, &tag, &type, &len, &save); - switch (tag) { - case 1: case 3: case 5: - gpsdata[29+tag/2] = getc(ifp); break; - case 2: case 4: case 7: - FORC(6) gpsdata[tag/3*6+c] = get4(); break; - case 6: - FORC(2) gpsdata[18+c] = get4(); break; - case 18: case 29: - fgets ((char *) (gpsdata+14+tag/3), MIN(len,12), ifp); - } - fseek (ifp, save, SEEK_SET); - } -} - -void CLASS romm_coeff (float romm_cam[3][3]) -{ - static const float rgb_romm[3][3] = /* ROMM == Kodak ProPhoto */ - { { 2.034193, -0.727420, -0.306766 }, - { -0.228811, 1.231729, -0.002922 }, - { -0.008565, -0.153273, 1.161839 } }; - int i, j, k; - - for (i=0; i < 3; i++) - for (j=0; j < 3; j++) - for (cmatrix[i][j] = k=0; k < 3; k++) - cmatrix[i][j] += rgb_romm[i][k] * romm_cam[k][j]; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cmatrix_state = LIBRAW_COLORSTATE_CALCULATED; -#endif -} - -void CLASS parse_mos (int offset) -{ - char data[40]; - int skip, from, i, c, neut[4], planes=0, frot=0; - static const char *mod[] = - { "","DCB2","Volare","Cantare","CMost","Valeo 6","Valeo 11","Valeo 22", - "Valeo 11p","Valeo 17","","Aptus 17","Aptus 22","Aptus 75","Aptus 65", - "Aptus 54S","Aptus 65S","Aptus 75S","AFi 5","AFi 6","AFi 7", - "AFi-II 7","","","AFi-II 6","","","AFi-II 10","AFi-II 5" - "","","","","","AFi-II 10R","AFi-II 8","","AFi-II 12"}; - - float romm_cam[3][3]; - - fseek (ifp, offset, SEEK_SET); - while (1) { - if (get4() != 0x504b5453) break; - get4(); - fread (data, 1, 40, ifp); - skip = get4(); - from = ftell(ifp); - if (!strcmp(data,"JPEG_preview_data")) { - thumb_offset = from; - thumb_length = skip; - } - if (!strcmp(data,"icc_camera_profile")) { - profile_offset = from; - profile_length = skip; - } - if (!strcmp(data,"ShootObj_back_type")) { - fscanf (ifp, "%d", &i); - if ((unsigned) i < sizeof mod / sizeof (*mod)) - strcpy (model, mod[i]); - } - if (!strcmp(data,"icc_camera_to_tone_matrix")) { - for (i=0; i < 9; i++) - romm_cam[0][i] = int_to_float(get4()); - romm_coeff (romm_cam); - } - if (!strcmp(data,"CaptProf_color_matrix")) { - for (i=0; i < 9; i++) - fscanf (ifp, "%f", &romm_cam[0][i]); - romm_coeff (romm_cam); - } - if (!strcmp(data,"CaptProf_number_of_planes")) - fscanf (ifp, "%d", &planes); - if (!strcmp(data,"CaptProf_raw_data_rotation")) - fscanf (ifp, "%d", &flip); - if (!strcmp(data,"CaptProf_mosaic_pattern")) - FORC4 { - fscanf (ifp, "%d", &i); - if (i == 1) frot = c ^ (c >> 1); - } - if (!strcmp(data,"ImgProf_rotation_angle")) { - fscanf (ifp, "%d", &i); - flip = i - flip; - } - if (!strcmp(data,"NeutObj_neutrals") && !cam_mul[0]) { - FORC4 fscanf (ifp, "%d", neut+c); - FORC3 cam_mul[c] = (float) neut[0] / neut[c+1]; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - if (!strcmp(data,"Rows_data")) - load_flags = get4(); - parse_mos (from); - fseek (ifp, skip+from, SEEK_SET); - } - if (planes) - filters = (planes == 1) * 0x01010101 * - (uchar) "\x94\x61\x16\x49"[(flip/90 + frot) & 3]; -} - -void CLASS linear_table (unsigned len) -{ - int i; - if (len > 0x1000) len = 0x1000; - read_shorts (curve, len); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.curve_state = LIBRAW_COLORSTATE_LOADED; -#endif - for (i=len; i < 0x1000; i++) - curve[i] = curve[i-1]; - maximum = curve[0xfff]; -} - -void CLASS parse_kodak_ifd (int base) -{ - unsigned entries, tag, type, len, save; - int i, c, wbi=-2, wbtemp=6500; - float mul[3]={1,1,1}, num; - static const int wbtag[] = { 64037,64040,64039,64041,-1,-1,64042 }; - - entries = get2(); - if (entries > 1024) return; - while (entries--) { - tiff_get (base, &tag, &type, &len, &save); - if (tag == 1020) wbi = getint(type); - if (tag == 1021 && len == 72) { /* WB set in software */ - fseek (ifp, 40, SEEK_CUR); - FORC3 cam_mul[c] = 2048.0 / get2(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - wbi = -2; - } - if (tag == 2118) wbtemp = getint(type); - if (tag == 2130 + wbi) - FORC3 mul[c] = getreal(type); - if (tag == 2140 + wbi && wbi >= 0) - { - FORC3 { - for (num=i=0; i < 4; i++) - num += getreal(type) * pow (wbtemp/100.0, i); - cam_mul[c] = 2048 / (num * mul[c]); - } -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - if (tag == 2317) linear_table (len); - if (tag == 6020) iso_speed = getint(type); - if (tag == 64013) wbi = fgetc(ifp); - if ((unsigned) wbi < 7 && tag == wbtag[wbi]) - FORC3 cam_mul[c] = get4(); - if (tag == 64019) width = getint(type); - if (tag == 64020) height = (getint(type)+1) & -2; - fseek (ifp, save, SEEK_SET); - } -} - -int CLASS parse_tiff_ifd (int base) -{ - unsigned entries, tag, type, len, plen=16, save; - int ifd, use_cm=0, cfa, i, j, c, ima_len=0; - int blrr=1, blrc=1, dblack[] = { 0,0,0,0 }; - char software[64], *cbuf, *cp; - uchar cfa_pat[16], cfa_pc[] = { 0,1,2,3 }, tab[256]; - double cc[4][4], cm[4][3], cam_xyz[4][3], num; - double ab[]={ 1,1,1,1 }, asn[] = { 0,0,0,0 }, xyz[] = { 1,1,1 }; - unsigned sony_curve[] = { 0,0,0,0,0,4095 }; - unsigned *buf, sony_offset=0, sony_length=0, sony_key=0; - struct jhead jh; -#ifndef LIBRAW_LIBRARY_BUILD - FILE *sfp; -#endif - - if (tiff_nifds >= sizeof tiff_ifd / sizeof tiff_ifd[0]) - return 1; - ifd = tiff_nifds++; - for (j=0; j < 4; j++) - for (i=0; i < 4; i++) - cc[j][i] = i == j; - entries = get2(); - if (entries > 512) return 1; - while (entries--) { - tiff_get (base, &tag, &type, &len, &save); - switch (tag) { - case 5: width = get2(); break; - case 6: height = get2(); break; - case 7: width += get2(); break; - case 9: filters = get2(); break; - case 17: case 18: - if (type == 3 && len == 1) - { - cam_mul[(tag-17)*2] = get2() / 256.0; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - break; - case 23: - if (type == 3) iso_speed = get2(); - break; - case 36: case 37: case 38: - cam_mul[tag-0x24] = get2(); - break; - case 39: - if (len < 50 || cam_mul[0]) break; - fseek (ifp, 12, SEEK_CUR); - FORC3 cam_mul[c] = get2(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - break; - case 46: - if (type != 7 || fgetc(ifp) != 0xff || fgetc(ifp) != 0xd8) break; - thumb_offset = ftell(ifp) - 2; - thumb_length = len; - break; - case 61440: /* Fuji HS10 table */ - parse_tiff_ifd (base); - break; - case 2: case 256: case 61441: /* ImageWidth */ - tiff_ifd[ifd].t_width = getint(type); - break; - case 3: case 257: case 61442: /* ImageHeight */ - tiff_ifd[ifd].t_height = getint(type); - break; - case 258: /* BitsPerSample */ - case 61443: - tiff_ifd[ifd].samples = len & 7; - tiff_ifd[ifd].bps = getint(type); - break; - case 61446: - raw_height = 0; - load_raw = &CLASS packed_load_raw; - load_flags = get4() && (filters=0x16161616) ? 24:80; - break; - case 259: /* Compression */ - tiff_ifd[ifd].comp = getint(type); - break; - case 262: /* PhotometricInterpretation */ - tiff_ifd[ifd].phint = get2(); - break; - case 270: /* ImageDescription */ - fread (desc, 512, 1, ifp); - break; - case 271: /* Make */ - fgets (make, 64, ifp); - break; - case 272: /* Model */ - fgets (model, 64, ifp); - break; - case 280: /* Panasonic RW2 offset */ - if (type != 4) break; - load_raw = &CLASS panasonic_load_raw; - load_flags = 0x2008; - case 273: /* StripOffset */ - case 513: /* JpegIFOffset */ - case 61447: - tiff_ifd[ifd].offset = get4()+base; - if (!tiff_ifd[ifd].bps && tiff_ifd[ifd].offset > 0) { - fseek (ifp, tiff_ifd[ifd].offset, SEEK_SET); - if (ljpeg_start (&jh, 1)) { - tiff_ifd[ifd].comp = 6; - tiff_ifd[ifd].t_width = jh.wide; - tiff_ifd[ifd].t_height = jh.high; - tiff_ifd[ifd].bps = jh.bits; - tiff_ifd[ifd].samples = jh.clrs; - if (!(jh.sraw || (jh.clrs & 1))) - tiff_ifd[ifd].t_width *= jh.clrs; - i = order; - parse_tiff (tiff_ifd[ifd].offset + 12); - order = i; - } - } - break; - case 274: /* Orientation */ - tiff_ifd[ifd].t_flip = "50132467"[get2() & 7]-'0'; - break; - case 277: /* SamplesPerPixel */ - tiff_ifd[ifd].samples = getint(type) & 7; - break; - case 279: /* StripByteCounts */ - case 514: - case 61448: - tiff_ifd[ifd].bytes = get4(); - break; - case 61454: - FORC3 cam_mul[(4-c) % 3] = getint(type); - break; - case 305: case 11: /* Software */ - fgets (software, 64, ifp); - if (!strncmp(software,"Adobe",5) || - !strncmp(software,"dcraw",5) || - !strncmp(software,"UFRaw",5) || - !strncmp(software,"Bibble",6) || - !strncmp(software,"Nikon Scan",10) || - !strcmp (software,"Digital Photo Professional")) - is_raw = 0; - break; - case 306: /* DateTime */ - get_timestamp(0); - break; - case 315: /* Artist */ - fread (artist, 64, 1, ifp); - break; - case 322: /* TileWidth */ - tile_width = getint(type); - break; - case 323: /* TileLength */ - tile_length = getint(type); - break; - case 324: /* TileOffsets */ - tiff_ifd[ifd].offset = len > 1 ? ftell(ifp) : get4(); - if (len == 4) { - load_raw = &CLASS sinar_4shot_load_raw; - is_raw = 5; - } - break; -#ifdef LIBRAW_LIBRARY_BUILD - case 325: /* TileByteCount */ - tiff_ifd[ifd].tile_maxbytes = 0; - for(int jj=0;jj tiff_ifd[ifd].tile_maxbytes) tiff_ifd[ifd].tile_maxbytes=s; - } - break; -#endif - case 330: /* SubIFDs */ - if (!strcmp(model,"DSLR-A100") && tiff_ifd[ifd].t_width == 3872) { - load_raw = &CLASS sony_arw_load_raw; - data_offset = get4()+base; - ifd++; break; - } - while (len--) { - i = ftell(ifp); - fseek (ifp, get4()+base, SEEK_SET); - if (parse_tiff_ifd (base)) break; - fseek (ifp, i+4, SEEK_SET); - } - break; - case 400: - strcpy (make, "Sarnoff"); - maximum = 0xfff; - break; - case 28688: - FORC4 sony_curve[c+1] = get2() >> 2 & 0xfff; - for (i=0; i < 5; i++) - for (j = sony_curve[i]+1; j <= sony_curve[i+1]; j++) - curve[j] = curve[j-1] + (1 << i); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.curve_state = LIBRAW_COLORSTATE_LOADED; -#endif - break; - case 29184: sony_offset = get4(); break; - case 29185: sony_length = get4(); break; - case 29217: sony_key = get4(); break; - case 29264: - parse_minolta (ftell(ifp)); - raw_width = 0; - break; - case 29443: - FORC4 cam_mul[c ^ (c < 2)] = get2(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - break; - case 29459: - FORC4 cam_mul[c] = get2(); - i = (cam_mul[1] == 1024 && cam_mul[2] == 1024) << 1; - SWAP (cam_mul[i],cam_mul[i+1]) -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - break; - case 33405: /* Model2 */ - fgets (model2, 64, ifp); - break; - case 33422: /* CFAPattern */ - case 64777: /* Kodak P-series */ - if ((plen=len) > 16) plen = 16; - fread (cfa_pat, 1, plen, ifp); - for (colors=cfa=i=0; i < plen; i++) { - colors += !(cfa & (1 << cfa_pat[i])); - cfa |= 1 << cfa_pat[i]; - } - if (cfa == 070) memcpy (cfa_pc,"\003\004\005",3); /* CMY */ - if (cfa == 072) memcpy (cfa_pc,"\005\003\004\001",4); /* GMCY */ - goto guess_cfa_pc; - case 33424: - case 65024: - fseek (ifp, get4()+base, SEEK_SET); - parse_kodak_ifd (base); - break; - case 33434: /* ExposureTime */ - shutter = getreal(type); - break; - case 33437: /* FNumber */ - aperture = getreal(type); - break; - case 34306: /* Leaf white balance */ - FORC4 cam_mul[c ^ 1] = 4096.0 / get2(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - break; - case 34307: /* Leaf CatchLight color matrix */ - fread (software, 1, 7, ifp); - if (strncmp(software,"MATRIX",6)) break; - colors = 4; - for (raw_color = i=0; i < 3; i++) { - FORC4 fscanf (ifp, "%f", &rgb_cam[i][c^1]); - if (!use_camera_wb) continue; - num = 0; - FORC4 num += rgb_cam[i][c]; - FORC4 rgb_cam[i][c] /= num; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.rgb_cam_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - break; - case 34310: /* Leaf metadata */ - parse_mos (ftell(ifp)); - case 34303: - strcpy (make, "Leaf"); - break; - case 34665: /* EXIF tag */ - fseek (ifp, get4()+base, SEEK_SET); - parse_exif (base); - break; - case 34853: /* GPSInfo tag */ - fseek (ifp, get4()+base, SEEK_SET); - parse_gps (base); - break; - case 34675: /* InterColorProfile */ - case 50831: /* AsShotICCProfile */ - profile_offset = ftell(ifp); - profile_length = len; - break; - case 37122: /* CompressedBitsPerPixel */ - kodak_cbpp = get4(); - break; - case 37386: /* FocalLength */ - focal_len = getreal(type); - break; - case 37393: /* ImageNumber */ - shot_order = getint(type); - break; - case 37400: /* old Kodak KDC tag */ - for (raw_color = i=0; i < 3; i++) { - getreal(type); - FORC3 rgb_cam[i][c] = getreal(type); - } -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.rgb_cam_state = LIBRAW_COLORSTATE_LOADED; -#endif - break; - case 46275: /* Imacon tags */ - strcpy (make, "Imacon"); - data_offset = ftell(ifp); - ima_len = len; - break; - case 46279: - if (!ima_len) break; - fseek (ifp, 38, SEEK_CUR); - case 46274: - fseek (ifp, 40, SEEK_CUR); - raw_width = get4(); - raw_height = get4(); - left_margin = get4() & 7; - width = raw_width - left_margin - (get4() & 7); - top_margin = get4() & 7; - height = raw_height - top_margin - (get4() & 7); - if (raw_width == 7262) { - height = 5444; - width = 7244; - left_margin = 7; - } - fseek (ifp, 52, SEEK_CUR); - FORC3 cam_mul[c] = getreal(11); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - fseek (ifp, 114, SEEK_CUR); - flip = (get2() >> 7) * 90; - if (width * height * 6 == ima_len) { -#if 1 - if (flip % 180 == 90) SWAP(width,height); - filters = flip = 0; -#else - if (flip % 180 == 90) SWAP(width,height); - raw_width = width; - raw_height = height; - left_margin = top_margin = filters = flip = 0; -#endif - } - sprintf (model, "Ixpress %d-Mp", height*width/1000000); - load_raw = &CLASS imacon_full_load_raw; - if (filters) { - if (left_margin & 1) filters = 0x61616161; - load_raw = &CLASS unpacked_load_raw; - } - maximum = 0xffff; - break; - case 50454: /* Sinar tag */ - case 50455: - if (!(cbuf = (char *) malloc(len))) break; - fread (cbuf, 1, len, ifp); - for (cp = cbuf-1; cp && cp < cbuf+len; cp = strchr(cp,'\n')) - if (!strncmp (++cp,"Neutral ",8)) - { - sscanf (cp+8, "%f %f %f", cam_mul, cam_mul+1, cam_mul+2); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - free (cbuf); - break; - case 50458: - if (!make[0]) strcpy (make, "Hasselblad"); - break; - case 50459: /* Hasselblad tag */ - i = order; - j = ftell(ifp); - c = tiff_nifds; - order = get2(); - fseek (ifp, j+(get2(),get4()), SEEK_SET); - parse_tiff_ifd (j); - maximum = 0xffff; - tiff_nifds = c; - order = i; - break; - case 50706: /* DNGVersion */ - FORC4 dng_version = (dng_version << 8) + fgetc(ifp); - if (!make[0]) strcpy (make, "DNG"); - is_raw = 1; - break; - case 50710: /* CFAPlaneColor */ - if (len > 4) len = 4; - colors = len; - fread (cfa_pc, 1, colors, ifp); -guess_cfa_pc: - FORCC tab[cfa_pc[c]] = c; - cdesc[c] = 0; - for (i=16; i--; ) - filters = filters << 2 | tab[cfa_pat[i % plen]]; - break; - case 50711: /* CFALayout */ - if (get2() == 2) { - fuji_width = 1; - filters = 0x49494949; - } - break; - case 291: - case 50712: /* LinearizationTable */ - linear_table (len); - break; - case 50713: /* BlackLevelRepeatDim */ - blrr = get2(); - blrc = get2(); - break; - case 61450: - blrr = blrc = 2; - case 50714: /* BlackLevel */ - black = getreal(type); - if (!filters || !~filters) break; - dblack[0] = black; - dblack[1] = (blrc == 2) ? getreal(type):dblack[0]; - dblack[2] = (blrr == 2) ? getreal(type):dblack[0]; - dblack[3] = (blrc == 2 && blrr == 2) ? getreal(type):dblack[1]; - if (colors == 3) - filters |= ((filters >> 2 & 0x22222222) | - (filters << 2 & 0x88888888)) & filters << 1; - FORC4 cblack[filters >> (c << 1) & 3] = dblack[c]; - black = 0; - break; - case 50715: /* BlackLevelDeltaH */ - case 50716: /* BlackLevelDeltaV */ - for (num=i=0; i < len; i++) - num += getreal(type); - black += num/len + 0.5; - break; - case 50717: /* WhiteLevel */ - maximum = getint(type); - break; - case 50718: /* DefaultScale */ - pixel_aspect = getreal(type); - pixel_aspect /= getreal(type); - break; - case 50721: /* ColorMatrix1 */ - case 50722: /* ColorMatrix2 */ - FORCC for (j=0; j < 3; j++) - cm[c][j] = getreal(type); - use_cm = 1; - break; - case 50723: /* CameraCalibration1 */ - case 50724: /* CameraCalibration2 */ - for (i=0; i < colors; i++) - FORCC cc[i][c] = getreal(type); - break; - case 50727: /* AnalogBalance */ - FORCC ab[c] = getreal(type); - break; - case 50728: /* AsShotNeutral */ - FORCC asn[c] = getreal(type); - break; - case 50729: /* AsShotWhiteXY */ - xyz[0] = getreal(type); - xyz[1] = getreal(type); - xyz[2] = 1 - xyz[0] - xyz[1]; - FORC3 xyz[c] /= d65_white[c]; - break; - case 50740: /* DNGPrivateData */ - if (dng_version) break; - parse_minolta (j = get4()+base); - fseek (ifp, j, SEEK_SET); - parse_tiff_ifd (base); - break; - case 50752: - read_shorts (cr2_slice, 3); - break; - case 50829: /* ActiveArea */ - top_margin = getint(type); - left_margin = getint(type); - height = getint(type) - top_margin; - width = getint(type) - left_margin; - break; -#if 0 - case 51009: /* OpcodeList2 */ - meta_offset = ftell(ifp); - break; -#endif - case 64772: /* Kodak P-series */ - if (len < 13) break; - fseek (ifp, 16, SEEK_CUR); - data_offset = get4(); - fseek (ifp, 28, SEEK_CUR); - data_offset += get4(); - load_raw = &CLASS packed_load_raw; - break; - case 65026: - if (type == 2) fgets (model2, 64, ifp); - } - fseek (ifp, save, SEEK_SET); - } - if (sony_length && (buf = (unsigned *) malloc(sony_length))) { - fseek (ifp, sony_offset, SEEK_SET); - fread (buf, sony_length, 1, ifp); - sony_decrypt (buf, sony_length/4, 1, sony_key); -#ifndef LIBRAW_LIBRARY_BUILD - sfp = ifp; - if ((ifp = tmpfile())) { - fwrite (buf, sony_length, 1, ifp); - fseek (ifp, 0, SEEK_SET); - parse_tiff_ifd (-sony_offset); - fclose (ifp); - } - ifp = sfp; -#else - if( !ifp->tempbuffer_open(buf,sony_length)) - { - parse_tiff_ifd(-sony_offset); - ifp->tempbuffer_close(); - } -#endif - free (buf); - } - for (i=0; i < colors; i++) - FORCC cc[i][c] *= ab[i]; - if (use_cm) { - FORCC for (i=0; i < 3; i++) - for (cam_xyz[c][i]=j=0; j < colors; j++) - cam_xyz[c][i] += cc[c][j] * cm[j][i] * xyz[i]; - cam_xyz_coeff (cam_xyz); - } - if (asn[0]) { - cam_mul[3] = 0; - FORCC cam_mul[c] = 1 / asn[c]; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - if (!use_cm) - { - FORCC pre_mul[c] /= cc[c][c]; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.pre_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - - return 0; -} - -int CLASS parse_tiff (int base) -{ - int doff; - - fseek (ifp, base, SEEK_SET); - order = get2(); - if (order != 0x4949 && order != 0x4d4d) return 0; - get2(); - while ((doff = get4())) { - fseek (ifp, doff+base, SEEK_SET); - if (parse_tiff_ifd (base)) break; - } - return 1; -} - -void CLASS apply_tiff() -{ - int max_samp=0, raw=-1, thm=-1, i,max_bps=0; - struct jhead jh; - - thumb_misc = 16; - if (thumb_offset) { - fseek (ifp, thumb_offset, SEEK_SET); - if (ljpeg_start (&jh, 1)) { - thumb_misc = jh.bits; - thumb_width = jh.wide; - thumb_height = jh.high; - } - } - for (i=0; i < tiff_nifds; i++) { - if (max_samp < tiff_ifd[i].samples) - max_samp = tiff_ifd[i].samples; - if (max_samp > 3) max_samp = 3; - if (max_bps < tiff_ifd[i].bps) - max_bps = tiff_ifd[i].bps; - if ((tiff_ifd[i].comp != 6 || tiff_ifd[i].samples != 3) && - (tiff_ifd[i].t_width | tiff_ifd[i].t_height) < 0x10000 && - tiff_ifd[i].t_width*tiff_ifd[i].t_height > raw_width*raw_height) { - raw_width = tiff_ifd[i].t_width; - raw_height = tiff_ifd[i].t_height; - tiff_bps = tiff_ifd[i].bps; - tiff_compress = tiff_ifd[i].comp; - data_offset = tiff_ifd[i].offset; - tiff_flip = tiff_ifd[i].t_flip; - tiff_samples = tiff_ifd[i].samples; -#ifdef LIBRAW_LIBRARY_BUILD - data_size = tile_length < INT_MAX ? tiff_ifd[i].tile_maxbytes: tiff_ifd[i].bytes; -#endif - raw = i; - } - } -#if 0 - if (!tile_width ) tile_width = INT_MAX; - if (!tile_length) tile_length = INT_MAX; -#endif - for (i=tiff_nifds; i--; ) - if (tiff_ifd[i].t_flip) tiff_flip = tiff_ifd[i].t_flip; - if (raw >= 0 && !load_raw) - switch (tiff_compress) { -#if 1 - case 32767: - if (tiff_ifd[raw].bytes == raw_width*raw_height) { - tiff_bps = 12; - load_raw = &CLASS sony_arw2_load_raw; break; - } - if (tiff_ifd[raw].bytes*8 != raw_width*raw_height*tiff_bps) { - raw_height += 8; - load_raw = &CLASS sony_arw_load_raw; break; - } - load_flags = 79; - case 32769: - load_flags++; - case 32770: - case 32773: goto slr; - case 0: case 1: - if (tiff_ifd[raw].bytes*5 == raw_width*raw_height*8) { - load_flags = 81; - tiff_bps = 12; - } slr: - switch (tiff_bps) { - case 8: load_raw = &CLASS eight_bit_load_raw; break; - case 12: if (tiff_ifd[raw].phint == 2) - load_flags = 6; - load_raw = &CLASS packed_load_raw; break; - case 14: load_flags = 0; - case 16: load_raw = &CLASS unpacked_load_raw; break; - } - break; - case 6: case 7: case 99: - load_raw = &CLASS lossless_jpeg_load_raw; break; - case 262: - load_raw = &CLASS kodak_262_load_raw; break; - case 34713: - load_raw = &CLASS nikon_compressed_load_raw; break; -/* - case 34892: - load_raw = &CLASS lossy_dng_load_raw; break; -*/ - case 65535: - load_raw = &CLASS pentax_load_raw; break; - case 65000: - switch (tiff_ifd[raw].phint) { - case 2: load_raw = &CLASS kodak_rgb_load_raw; filters = 0; break; - case 6: load_raw = &CLASS kodak_ycbcr_load_raw; filters = 0; break; - case 32803: load_raw = &CLASS kodak_65000_load_raw; - } - case 32867: break; - default: is_raw = 0; -#else - case 0: case 1: - switch (tiff_bps) { - case 8: load_raw = &CLASS eight_bit_load_raw; break; - case 12: load_raw = &CLASS packed_load_raw; - if (tiff_ifd[raw].phint == 2) - load_flags = 6; - if (strncmp(make,"PENTAX",6)) break; - case 14: - case 16: load_raw = &CLASS unpacked_load_raw; break; - } - if (tiff_ifd[raw].bytes*5 == raw_width*raw_height*8) { - tiff_bps = 12; - load_raw = &CLASS packed_load_raw; - load_flags = 81; - } - break; - case 6: case 7: case 99: - load_raw = &CLASS lossless_jpeg_load_raw; break; - case 262: - load_raw = &CLASS kodak_262_load_raw; break; - case 32767: - if (tiff_ifd[raw].bytes == raw_width*raw_height) { - tiff_bps = 12; - load_raw = &CLASS sony_arw2_load_raw; break; - } - if (tiff_ifd[raw].bytes*8 != raw_width*raw_height*tiff_bps) { - raw_height += 8; - load_raw = &CLASS sony_arw_load_raw; break; - } - load_flags = 79; - case 32769: - load_flags++; - case 32770: - case 32773: - load_raw = &CLASS packed_load_raw; break; - case 34713: - load_raw = &CLASS nikon_compressed_load_raw; break; - case 65535: - load_raw = &CLASS pentax_load_raw; break; - case 65000: - switch (tiff_ifd[raw].phint) { - case 2: load_raw = &CLASS kodak_rgb_load_raw; filters = 0; break; - case 6: load_raw = &CLASS kodak_ycbcr_load_raw; filters = 0; break; - case 32803: load_raw = &CLASS kodak_65000_load_raw; - } - case 32867: break; - default: is_raw = 0; -#endif - } - if (!dng_version) - if ( (tiff_samples == 3 && tiff_ifd[raw].bytes && - tiff_bps != 14 && tiff_bps != 2048 && tiff_compress != 32770) - || (tiff_bps == 8 && !strstr(make,"KODAK") && !strstr(make,"Kodak") && - !strstr(model2,"DEBUG RAW"))) - is_raw = 0; - if(dng_version && max_bps > 16) - is_raw = 0; - for (i=0; i < tiff_nifds; i++) - if (i != raw && tiff_ifd[i].samples == max_samp && tiff_ifd[i].offset && tiff_ifd[i].bytes && - tiff_ifd[i].t_width * tiff_ifd[i].t_height / SQR(tiff_ifd[i].bps+1) > - thumb_width * thumb_height / SQR(thumb_misc+1) - && tiff_ifd[i].comp != 34892) { - thumb_width = tiff_ifd[i].t_width; - thumb_height = tiff_ifd[i].t_height; - thumb_offset = tiff_ifd[i].offset; - thumb_length = tiff_ifd[i].bytes; - thumb_misc = tiff_ifd[i].bps; - thm = i; - } - if (thm >= 0) { - thumb_misc |= tiff_ifd[thm].samples << 5; - switch (tiff_ifd[thm].comp) { - case 0: - write_thumb = &CLASS layer_thumb; - break; - case 1: - if (tiff_ifd[thm].bps <= 8) - write_thumb = &CLASS ppm_thumb; - else if (!strcmp(make,"Imacon")) - write_thumb = NULL; /* &CLASS ppm16_thumb; */ - else - thumb_load_raw = &CLASS kodak_thumb_load_raw; - break; - case 65000: - thumb_load_raw = tiff_ifd[thm].phint == 6 ? - &CLASS kodak_ycbcr_load_thumb : &CLASS kodak_rgb_load_thumb; - } - } -} - -void CLASS parse_minolta (int base) -{ - int save, tag, len, offset, high=0, wide=0, i, c; - short sorder=order; - - fseek (ifp, base, SEEK_SET); - if (fgetc(ifp) || fgetc(ifp)-'M' || fgetc(ifp)-'R') return; - order = fgetc(ifp) * 0x101; - offset = base + get4() + 8; - while ((save=ftell(ifp)) < offset) { - for (tag=i=0; i < 4; i++) - tag = tag << 8 | fgetc(ifp); - len = get4(); - switch (tag) { - case 0x505244: /* PRD */ - fseek (ifp, 8, SEEK_CUR); - high = get2(); - wide = get2(); - break; - case 0x574247: /* WBG */ - get4(); - i = strcmp(model,"DiMAGE A200") ? 0:3; - FORC4 cam_mul[c ^ (c >> 1) ^ i] = get2(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - break; - case 0x545457: /* TTW */ - parse_tiff (ftell(ifp)); - data_offset = offset; - } - fseek (ifp, save+len+8, SEEK_SET); - } - raw_height = high; - raw_width = wide; - order = sorder; -} - -/* - Many cameras have a "debug mode" that writes JPEG and raw - at the same time. The raw file has no header, so try to - to open the matching JPEG file and read its metadata. - */ -void CLASS parse_external_jpeg() -{ - const char *file, *ext; - char *jname, *jfile, *jext; -#ifndef LIBRAW_LIBRARY_BUILD - FILE *save=ifp; -#else - if(!ifp->fname()) - { - imgdata.process_warnings |= LIBRAW_WARN_NO_METADATA ; - return; - } -#endif - - ext = strrchr (ifname, '.'); - file = strrchr (ifname, '/'); - if (!file) file = strrchr (ifname, '\\'); -#ifndef LIBRAW_LIBRARY_BUILD - if (!file) file = ifname-1; -#else - if (!file) file = (char*)ifname-1; -#endif - file++; - if (!ext || strlen(ext) != 4 || ext-file != 8) return; - jname = (char *) malloc (strlen(ifname) + 1); - merror (jname, "parse_external_jpeg()"); - strcpy (jname, ifname); - jfile = file - ifname + jname; - jext = ext - ifname + jname; - if (strcasecmp (ext, ".jpg")) { - strcpy (jext, isupper(ext[1]) ? ".JPG":".jpg"); - if (isdigit(*file)) { - memcpy (jfile, file+4, 4); - memcpy (jfile+4, file, 4); - } - } else - while (isdigit(*--jext)) { - if (*jext != '9') { - (*jext)++; - break; - } - *jext = '0'; - } -#ifndef LIBRAW_LIBRARY_BUILD - if (strcmp (jname, ifname)) { - if ((ifp = fopen (jname, "rb"))) { -#ifdef DCRAW_VERBOSE - if (verbose) - fprintf (stderr,_("Reading metadata from %s ...\n"), jname); -#endif - parse_tiff (12); - thumb_offset = 0; - is_raw = 1; - fclose (ifp); - } - } -#else - if (strcmp (jname, ifname)) - { - if(!ifp->subfile_open(jname)) - { - parse_tiff (12); - thumb_offset = 0; - is_raw = 1; - ifp->subfile_close(); - } - else - imgdata.process_warnings |= LIBRAW_WARN_NO_METADATA ; - } -#endif - if (!timestamp) - { -#ifdef LIBRAW_LIBRARY_BUILD - imgdata.process_warnings |= LIBRAW_WARN_NO_METADATA ; -#endif -#ifdef DCRAW_VERBOSE - fprintf (stderr,_("Failed to read metadata from %s\n"), jname); -#endif - } - free (jname); -#ifndef LIBRAW_LIBRARY_BUILD - ifp = save; -#endif -} - -/* - CIFF block 0x1030 contains an 8x8 white sample. - Load this into white[][] for use in scale_colors(). - */ -void CLASS ciff_block_1030() -{ - static const ushort key[] = { 0x410, 0x45f3 }; - int i, bpp, row, col, vbits=0; - unsigned long bitbuf=0; - - if ((get2(),get4()) != 0x80008 || !get4()) return; - bpp = get2(); - if (bpp != 10 && bpp != 12) return; - for (i=row=0; row < 8; row++) - for (col=0; col < 8; col++) { - if (vbits < bpp) { - bitbuf = bitbuf << 16 | (get2() ^ key[i++ & 1]); - vbits += 16; - } - white[row][col] = - bitbuf << (LONG_BIT - vbits) >> (LONG_BIT - bpp); - vbits -= bpp; - } -} - -/* - Parse a CIFF file, better known as Canon CRW format. - */ -void CLASS parse_ciff (int offset, int length) -{ - int tboff, nrecs, c, type, len, save, wbi=-1; - ushort key[] = { 0x410, 0x45f3 }; - - fseek (ifp, offset+length-4, SEEK_SET); - tboff = get4() + offset; - fseek (ifp, tboff, SEEK_SET); - nrecs = get2(); - if (nrecs > 100) return; - while (nrecs--) { - type = get2(); - len = get4(); - save = ftell(ifp) + 4; - fseek (ifp, offset+get4(), SEEK_SET); - if ((((type >> 8) + 8) | 8) == 0x38) - parse_ciff (ftell(ifp), len); /* Parse a sub-table */ - - if (type == 0x0810) - fread (artist, 64, 1, ifp); - if (type == 0x080a) { - fread (make, 64, 1, ifp); - fseek (ifp, ((INT64)strlen(make)) - 63, SEEK_CUR); - fread (model, 64, 1, ifp); - } - if (type == 0x1810) { - fseek (ifp, 12, SEEK_CUR); - flip = get4(); - } - if (type == 0x1835) /* Get the decoder table */ - tiff_compress = get4(); - if (type == 0x2007) { - thumb_offset = ftell(ifp); - thumb_length = len; - } - if (type == 0x1818) { - shutter = pow (2.0f, -int_to_float((get4(),get4()))); - aperture = pow (2.0f, int_to_float(get4())/2); - } - if (type == 0x102a) { - iso_speed = pow (2.0, (get4(),get2())/32.0 - 4) * 50; - aperture = pow (2.0, (get2(),(short)get2())/64.0); - shutter = pow (2.0,-((short)get2())/32.0); - wbi = (get2(),get2()); - if (wbi > 17) wbi = 0; - fseek (ifp, 32, SEEK_CUR); - if (shutter > 1e6) shutter = get2()/10.0; - } - if (type == 0x102c) { - if (get2() > 512) { /* Pro90, G1 */ - fseek (ifp, 118, SEEK_CUR); - FORC4 cam_mul[c ^ 2] = get2(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } else { /* G2, S30, S40 */ - fseek (ifp, 98, SEEK_CUR); - FORC4 cam_mul[c ^ (c >> 1) ^ 1] = get2(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - } - if (type == 0x0032) { - if (len == 768) { /* EOS D30 */ - fseek (ifp, 72, SEEK_CUR); - FORC4 cam_mul[c ^ (c >> 1)] = 1024.0 / get2(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - if (!wbi) cam_mul[0] = -1; /* use my auto white balance */ - } else if (!cam_mul[0]) { - if (get2() == key[0]) /* Pro1, G6, S60, S70 */ - c = (strstr(model,"Pro1") ? - "012346000000000000":"01345:000000006008")[wbi]-'0'+ 2; - else { /* G3, G5, S45, S50 */ - c = "023457000000006000"[wbi]-'0'; - key[0] = key[1] = 0; - } - fseek (ifp, 78 + c*8, SEEK_CUR); - FORC4 cam_mul[c ^ (c >> 1) ^ 1] = get2() ^ key[c & 1]; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - if (!wbi) cam_mul[0] = -1; - } - } - if (type == 0x10a9) { /* D60, 10D, 300D, and clones */ - if (len > 66) wbi = "0134567028"[wbi]-'0'; - fseek (ifp, 2 + wbi*8, SEEK_CUR); - FORC4 cam_mul[c ^ (c >> 1)] = get2(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } - if (type == 0x1030 && (0x18040 >> wbi & 1)) - ciff_block_1030(); /* all that don't have 0x10a9 */ - if (type == 0x1031) { - raw_width = (get2(),get2()); - raw_height = get2(); - } - if (type == 0x5029) { - focal_len = len >> 16; - if ((len & 0xffff) == 2) focal_len /= 32; - } - if (type == 0x5813) flash_used = int_to_float(len); - if (type == 0x5814) canon_ev = int_to_float(len); - if (type == 0x5817) shot_order = len; - if (type == 0x5834) unique_id = len; - if (type == 0x580e) timestamp = len; - if (type == 0x180e) timestamp = get4(); -#ifdef LOCALTIME - if ((type | 0x4000) == 0x580e) - timestamp = mktime (gmtime (×tamp)); -#endif - fseek (ifp, save, SEEK_SET); - } -} - -void CLASS parse_rollei() -{ - char line[128], *val; - struct tm t; - - fseek (ifp, 0, SEEK_SET); - memset (&t, 0, sizeof t); - do { - fgets (line, 128, ifp); - if ((val = strchr(line,'='))) - *val++ = 0; - else - val = line + strlen(line); - if (!strcmp(line,"DAT")) - sscanf (val, "%d.%d.%d", &t.tm_mday, &t.tm_mon, &t.tm_year); - if (!strcmp(line,"TIM")) - sscanf (val, "%d:%d:%d", &t.tm_hour, &t.tm_min, &t.tm_sec); - if (!strcmp(line,"HDR")) - thumb_offset = atoi(val); - if (!strcmp(line,"X ")) - raw_width = atoi(val); - if (!strcmp(line,"Y ")) - raw_height = atoi(val); - if (!strcmp(line,"TX ")) - thumb_width = atoi(val); - if (!strcmp(line,"TY ")) - thumb_height = atoi(val); - } while (strncmp(line,"EOHD",4)); - data_offset = thumb_offset + thumb_width * thumb_height * 2; - t.tm_year -= 1900; - t.tm_mon -= 1; - if (mktime(&t) > 0) - timestamp = mktime(&t); - strcpy (make, "Rollei"); - strcpy (model,"d530flex"); - write_thumb = &CLASS rollei_thumb; -} - -void CLASS parse_sinar_ia() -{ - int entries, off; - char str[8], *cp; - - order = 0x4949; - fseek (ifp, 4, SEEK_SET); - entries = get4(); - fseek (ifp, get4(), SEEK_SET); - while (entries--) { - off = get4(); get4(); - fread (str, 8, 1, ifp); - if (!strcmp(str,"META")) meta_offset = off; - if (!strcmp(str,"THUMB")) thumb_offset = off; - if (!strcmp(str,"RAW0")) data_offset = off; - } - fseek (ifp, meta_offset+20, SEEK_SET); - fread (make, 64, 1, ifp); - make[63] = 0; - if ((cp = strchr(make,' '))) { - strcpy (model, cp+1); - *cp = 0; - } - raw_width = get2(); - raw_height = get2(); - load_raw = &CLASS unpacked_load_raw; - thumb_width = (get4(),get2()); - thumb_height = get2(); - write_thumb = &CLASS ppm_thumb; - maximum = 0x3fff; -} - -void CLASS parse_phase_one (int base) -{ - unsigned entries, tag, type, len, data, save, i, c; - float romm_cam[3][3]; - char *cp; - - memset (&ph1, 0, sizeof ph1); - fseek (ifp, base, SEEK_SET); - order = get4() & 0xffff; - if (get4() >> 8 != 0x526177) return; /* "Raw" */ - fseek (ifp, get4()+base, SEEK_SET); - entries = get4(); - get4(); - while (entries--) { - tag = get4(); - type = get4(); - len = get4(); - data = get4(); - save = ftell(ifp); - fseek (ifp, base+data, SEEK_SET); - switch (tag) { - case 0x100: flip = "0653"[data & 3]-'0'; break; - case 0x106: - for (i=0; i < 9; i++) - romm_cam[0][i] = getreal(11); - romm_coeff (romm_cam); - break; - case 0x107: - FORC3 cam_mul[c] = getreal(11); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - break; - case 0x108: raw_width = data; break; - case 0x109: raw_height = data; break; - case 0x10a: left_margin = data; break; - case 0x10b: top_margin = data; break; - case 0x10c: width = data; break; - case 0x10d: height = data; break; - case 0x10e: ph1.format = data; break; - case 0x10f: data_offset = data+base; break; - case 0x110: meta_offset = data+base; - meta_length = len; break; - case 0x112: ph1.key_off = save - 4; break; - case 0x210: ph1.tag_210 = int_to_float(data); break; - case 0x21a: ph1.tag_21a = data; break; - case 0x21c: strip_offset = data+base; break; - case 0x21d: ph1.t_black = data; break; - case 0x222: ph1.split_col = data - left_margin; break; - case 0x223: ph1.black_off = data+base; break; - case 0x301: - model[63] = 0; - fread (model, 1, 63, ifp); - if ((cp = strstr(model," camera"))) *cp = 0; - } - fseek (ifp, save, SEEK_SET); - } - load_raw = ph1.format < 3 ? - &CLASS phase_one_load_raw : &CLASS phase_one_load_raw_c; - maximum = 0xffff; - strcpy (make, "Phase One"); - if (model[0]) return; - switch (raw_height) { - case 2060: strcpy (model,"LightPhase"); break; - case 2682: strcpy (model,"H 10"); break; - case 4128: strcpy (model,"H 20"); break; - case 5488: strcpy (model,"H 25"); break; - } -} - -void CLASS parse_fuji (int offset) -{ - unsigned entries, tag, len, save, c; - - fseek (ifp, offset, SEEK_SET); - entries = get4(); - if (entries > 255) return; - while (entries--) { - tag = get2(); - len = get2(); - save = ftell(ifp); - if (tag == 0x100) { - raw_height = get2(); - raw_width = get2(); - } else if (tag == 0x121) { - height = get2(); - if ((width = get2()) == 4284) width += 3; - } else if (tag == 0x130) { - fuji_layout = fgetc(ifp) >> 7; - load_raw = fgetc(ifp) & 8 ? - &CLASS unpacked_load_raw : &CLASS fuji_load_raw; - } else if (tag == 0x2ff0) { - FORC4 cam_mul[c ^ 1] = get2(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } else if (tag == 0xc000) { - c = order; - order = 0x4949; - width = get4(); - height = get4(); - order = c; - } - fseek (ifp, save+len, SEEK_SET); - } - height <<= fuji_layout; - width >>= fuji_layout; -} - -int CLASS parse_jpeg (int offset) -{ - int len, save, hlen, mark; - - fseek (ifp, offset, SEEK_SET); - if (fgetc(ifp) != 0xff || fgetc(ifp) != 0xd8) return 0; - - while (fgetc(ifp) == 0xff && (mark = fgetc(ifp)) != 0xda) { - order = 0x4d4d; - len = get2() - 2; - save = ftell(ifp); - if (mark == 0xc0 || mark == 0xc3) { - fgetc(ifp); - raw_height = get2(); - raw_width = get2(); - } - order = get2(); - hlen = get4(); - if (get4() == 0x48454150) /* "HEAP" */ - parse_ciff (save+hlen, len-hlen); - if (parse_tiff (save+6)) apply_tiff(); - fseek (ifp, save+len, SEEK_SET); - } - return 1; -} - -void CLASS parse_riff() -{ - unsigned i, size, end; - char tag[4], date[64], month[64]; - static const char mon[12][4] = - { "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" }; - struct tm t; - - order = 0x4949; - fread (tag, 4, 1, ifp); - size = get4(); - end = ftell(ifp) + size; - if (!memcmp(tag,"RIFF",4) || !memcmp(tag,"LIST",4)) { - int cnt=0; - get4(); - while (ftell(ifp)+7 < end) - { - parse_riff(); - if(cnt++>10000) break; // no more than 10k times - } - } else if (!memcmp(tag,"nctg",4)) { - while (ftell(ifp)+7 < end) { - i = get2(); - size = get2(); - if ((i+1) >> 1 == 10 && size == 20) - get_timestamp(0); - else fseek (ifp, size, SEEK_CUR); - } - } else if (!memcmp(tag,"IDIT",4) && size < 64) { - fread (date, 64, 1, ifp); - date[size] = 0; - memset (&t, 0, sizeof t); - if (sscanf (date, "%*s %s %d %d:%d:%d %d", month, &t.tm_mday, - &t.tm_hour, &t.tm_min, &t.tm_sec, &t.tm_year) == 6) { - for (i=0; i < 12 && strcasecmp(mon[i],month); i++); - t.tm_mon = i; - t.tm_year -= 1900; - if (mktime(&t) > 0) - timestamp = mktime(&t); - } - } else - fseek (ifp, size, SEEK_CUR); -} - -void CLASS parse_smal (int offset, int fsize) -{ - int ver; - - fseek (ifp, offset+2, SEEK_SET); - order = 0x4949; - ver = fgetc(ifp); - if (ver == 6) - fseek (ifp, 5, SEEK_CUR); - if (get4() != fsize) return; - if (ver > 6) data_offset = get4(); - raw_height = height = get2(); - raw_width = width = get2(); - strcpy (make, "SMaL"); - sprintf (model, "v%d %dx%d", ver, width, height); - if (ver == 6) load_raw = &CLASS smal_v6_load_raw; - if (ver == 9) load_raw = &CLASS smal_v9_load_raw; -} - -void CLASS parse_cine() -{ - unsigned off_head, off_setup, off_image, i; - - order = 0x4949; - fseek (ifp, 4, SEEK_SET); - is_raw = get2() == 2; - fseek (ifp, 14, SEEK_CUR); - is_raw *= get4(); - off_head = get4(); - off_setup = get4(); - off_image = get4(); - timestamp = get4(); - if ((i = get4())) timestamp = i; - fseek (ifp, off_head+4, SEEK_SET); - raw_width = get4(); - raw_height = get4(); - switch (get2(),get2()) { - case 8: load_raw = &CLASS eight_bit_load_raw; break; - case 16: load_raw = &CLASS unpacked_load_raw; - } - fseek (ifp, off_setup+792, SEEK_SET); - strcpy (make, "CINE"); - sprintf (model, "%d", get4()); - fseek (ifp, 12, SEEK_CUR); - switch ((i=get4()) & 0xffffff) { - case 3: filters = 0x94949494; break; - case 4: filters = 0x49494949; break; - default: is_raw = 0; - } - fseek (ifp, 72, SEEK_CUR); - switch ((get4()+3600) % 360) { - case 270: flip = 4; break; - case 180: flip = 1; break; - case 90: flip = 7; break; - case 0: flip = 2; - } - cam_mul[0] = getreal(11); - cam_mul[2] = getreal(11); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - maximum = ~(-1 << get4()); - fseek (ifp, 668, SEEK_CUR); - shutter = get4()/1000000000.0; - fseek (ifp, off_image, SEEK_SET); - if (shot_select < is_raw) - fseek (ifp, shot_select*8, SEEK_CUR); - data_offset = (INT64) get4() + 8; - data_offset += (INT64) get4() << 32; -} - -void CLASS parse_redcine() -{ - unsigned i, len, rdvo; - - order = 0x4d4d; - is_raw = 0; - fseek (ifp, 52, SEEK_SET); - width = get4(); - height = get4(); - fseek (ifp, 0, SEEK_END); - fseek (ifp, -(i = ftello(ifp) & 511), SEEK_CUR); - if (get4() != i || get4() != 0x52454f42) { -#ifdef DCRAW_VERBOSE - fprintf (stderr,_("%s: Tail is missing, parsing from head...\n"), ifname); -#endif - fseek (ifp, 0, SEEK_SET); - while ((len = get4()) != EOF) { - if (get4() == 0x52454456) - if (is_raw++ == shot_select) - data_offset = ftello(ifp) - 8; - fseek (ifp, len-8, SEEK_CUR); - } - } else { - rdvo = get4(); - fseek (ifp, 12, SEEK_CUR); - is_raw = get4(); - fseeko (ifp, rdvo+8 + shot_select*4, SEEK_SET); - data_offset = get4(); - } -} -void CLASS adobe_coeff (const char *p_make, const char *p_model) -{ - static const struct { - const char *prefix; - short t_black, t_maximum, trans[12]; - } table[] = { - { "AGFAPHOTO DC-833m", 0, 0, /* DJC */ - { 11438,-3762,-1115,-2409,9914,2497,-1227,2295,5300 } }, - { "Apple QuickTake", 0, 0, /* DJC */ - { 21392,-5653,-3353,2406,8010,-415,7166,1427,2078 } }, - { "Canon EOS D2000", 0, 0, - { 24542,-10860,-3401,-1490,11370,-297,2858,-605,3225 } }, - { "Canon EOS D6000", 0, 0, - { 20482,-7172,-3125,-1033,10410,-285,2542,226,3136 } }, - { "Canon EOS D30", 0, 0, - { 9805,-2689,-1312,-5803,13064,3068,-2438,3075,8775 } }, - { "Canon EOS D60", 0, 0xfa0, - { 6188,-1341,-890,-7168,14489,2937,-2640,3228,8483 } }, - { "Canon EOS 5D Mark III", 0, 0x3c80, - { 6722,-635,-963,-4287,12460,2028,-908,2162,5668 } }, - { "Canon EOS 5D Mark II", 0, 0x3cf0, - { 4716,603,-830,-7798,15474,2480,-1496,1937,6651 } }, - { "Canon EOS 5D", 0, 0xe6c, - { 6347,-479,-972,-8297,15954,2480,-1968,2131,7649 } }, - { "Canon EOS 7D", 0, 0x3510, - { 6844,-996,-856,-3876,11761,2396,-593,1772,6198 } }, - { "Canon EOS 10D", 0, 0xfa0, - { 8197,-2000,-1118,-6714,14335,2592,-2536,3178,8266 } }, - { "Canon EOS 20Da", 0, 0, - { 14155,-5065,-1382,-6550,14633,2039,-1623,1824,6561 } }, - { "Canon EOS 20D", 0, 0xfff, - { 6599,-537,-891,-8071,15783,2424,-1983,2234,7462 } }, - { "Canon EOS 30D", 0, 0, - { 6257,-303,-1000,-7880,15621,2396,-1714,1904,7046 } }, - { "Canon EOS 40D", 0, 0x3f60, - { 6071,-747,-856,-7653,15365,2441,-2025,2553,7315 } }, - { "Canon EOS 50D", 0, 0x3d93, - { 4920,616,-593,-6493,13964,2784,-1774,3178,7005 } }, - { "Canon EOS 60D", 0, 0x2ff7, - { 6719,-994,-925,-4408,12426,2211,-887,2129,6051 } }, - { "Canon EOS 300D", 0, 0xfa0, - { 8197,-2000,-1118,-6714,14335,2592,-2536,3178,8266 } }, - { "Canon EOS 350D", 0, 0xfff, - { 6018,-617,-965,-8645,15881,2975,-1530,1719,7642 } }, - { "Canon EOS 400D", 0, 0xe8e, - { 7054,-1501,-990,-8156,15544,2812,-1278,1414,7796 } }, - { "Canon EOS 450D", 0, 0x390d, - { 5784,-262,-821,-7539,15064,2672,-1982,2681,7427 } }, - { "Canon EOS 500D", 0, 0x3479, - { 4763,712,-646,-6821,14399,2640,-1921,3276,6561 } }, - { "Canon EOS 550D", 0, 0x3dd7, - { 6941,-1164,-857,-3825,11597,2534,-416,1540,6039 } }, - { "Canon EOS 600D", 0, 0x3510, - { 6461,-907,-882,-4300,12184,2378,-819,1944,5931 } }, - { "Canon EOS 1000D", 0, 0xe43, - { 6771,-1139,-977,-7818,15123,2928,-1244,1437,7533 } }, - { "Canon EOS 1100D", 0, 0x3510, - { 6444,-904,-893,-4563,12308,2535,-903,2016,6728 } }, - { "Canon EOS-1Ds Mark III", 0, 0x3bb0, - { 5859,-211,-930,-8255,16017,2353,-1732,1887,7448 } }, - { "Canon EOS-1Ds Mark II", 0, 0xe80, - { 6517,-602,-867,-8180,15926,2378,-1618,1771,7633 } }, - { "Canon EOS-1D Mark IV", 0, 0x3bb0, - { 6014,-220,-795,-4109,12014,2361,-561,1824,5787 } }, - { "Canon EOS-1D Mark III", 0, 0x3bb0, - { 6291,-540,-976,-8350,16145,2311,-1714,1858,7326 } }, - { "Canon EOS-1D Mark II N", 0, 0xe80, - { 6240,-466,-822,-8180,15825,2500,-1801,1938,8042 } }, - { "Canon EOS-1D Mark II", 0, 0xe80, - { 6264,-582,-724,-8312,15948,2504,-1744,1919,8664 } }, - { "Canon EOS-1DS", 0, 0xe20, - { 4374,3631,-1743,-7520,15212,2472,-2892,3632,8161 } }, - { "Canon EOS-1D X", 0, 0, - { 6847,-614,-1014,-4669,12737,2139,-1197,2488,6846 } }, - { "Canon EOS-1D", 0, 0xe20, - { 6806,-179,-1020,-8097,16415,1687,-3267,4236,7690 } }, - { "Canon EOS", 0, 0, - { 8197,-2000,-1118,-6714,14335,2592,-2536,3178,8266 } }, - { "Canon PowerShot A530", 0, 0, - { 0 } }, /* don't want the A5 matrix */ - { "Canon PowerShot A50", 0, 0, - { -5300,9846,1776,3436,684,3939,-5540,9879,6200,-1404,11175,217 } }, - { "Canon PowerShot A5", 0, 0, - { -4801,9475,1952,2926,1611,4094,-5259,10164,5947,-1554,10883,547 } }, - { "Canon PowerShot G10", 0, 0, - { 11093,-3906,-1028,-5047,12492,2879,-1003,1750,5561 } }, - { "Canon PowerShot G11", 0, 0, - { 12177,-4817,-1069,-1612,9864,2049,-98,850,4471 } }, - { "Canon PowerShot G12", 0, 0, - { 13244,-5501,-1248,-1508,9858,1935,-270,1083,4366 } }, - { "Canon PowerShot G1 X", 0, 0, - { 7378,-1255,-1043,-4088,12251,2048,-876,1946,5805 } }, - { "Canon PowerShot G1", 0, 0, - { -4778,9467,2172,4743,-1141,4344,-5146,9908,6077,-1566,11051,557 } }, - { "Canon PowerShot G2", 0, 0, - { 9087,-2693,-1049,-6715,14382,2537,-2291,2819,7790 } }, - { "Canon PowerShot G3", 0, 0, - { 9212,-2781,-1073,-6573,14189,2605,-2300,2844,7664 } }, - { "Canon PowerShot G5", 0, 0, - { 9757,-2872,-933,-5972,13861,2301,-1622,2328,7212 } }, - { "Canon PowerShot G6", 0, 0, - { 9877,-3775,-871,-7613,14807,3072,-1448,1305,7485 } }, - { "Canon PowerShot G9", 0, 0, - { 7368,-2141,-598,-5621,13254,2625,-1418,1696,5743 } }, - { "Canon PowerShot Pro1", 0, 0, - { 10062,-3522,-999,-7643,15117,2730,-765,817,7323 } }, - { "Canon PowerShot Pro70", 34, 0, - { -4155,9818,1529,3939,-25,4522,-5521,9870,6610,-2238,10873,1342 } }, - { "Canon PowerShot Pro90", 0, 0, - { -4963,9896,2235,4642,-987,4294,-5162,10011,5859,-1770,11230,577 } }, - { "Canon PowerShot S30", 0, 0, - { 10566,-3652,-1129,-6552,14662,2006,-2197,2581,7670 } }, - { "Canon PowerShot S40", 0, 0, - { 8510,-2487,-940,-6869,14231,2900,-2318,2829,9013 } }, - { "Canon PowerShot S45", 0, 0, - { 8163,-2333,-955,-6682,14174,2751,-2077,2597,8041 } }, - { "Canon PowerShot S50", 0, 0, - { 8882,-2571,-863,-6348,14234,2288,-1516,2172,6569 } }, - { "Canon PowerShot S60", 0, 0, - { 8795,-2482,-797,-7804,15403,2573,-1422,1996,7082 } }, - { "Canon PowerShot S70", 0, 0, - { 9976,-3810,-832,-7115,14463,2906,-901,989,7889 } }, - { "Canon PowerShot S90", 0, 0, - { 12374,-5016,-1049,-1677,9902,2078,-83,852,4683 } }, - { "Canon PowerShot S95", 0, 0, - { 13440,-5896,-1279,-1236,9598,1931,-180,1001,4651 } }, - { "Canon PowerShot S100", 0, 0, - { 7968,-2565,-636,-2873,10697,2513,180,667,4211 } }, - { "Canon PowerShot A470", 0, 0, /* DJC */ - { 12513,-4407,-1242,-2680,10276,2405,-878,2215,4734 } }, - { "Canon PowerShot A610", 0, 0, /* DJC */ - { 15591,-6402,-1592,-5365,13198,2168,-1300,1824,5075 } }, - { "Canon PowerShot A620", 0, 0, /* DJC */ - { 15265,-6193,-1558,-4125,12116,2010,-888,1639,5220 } }, - { "Canon PowerShot A630", 0, 0, /* DJC */ - { 14201,-5308,-1757,-6087,14472,1617,-2191,3105,5348 } }, - { "Canon PowerShot A640", 0, 0, /* DJC */ - { 13124,-5329,-1390,-3602,11658,1944,-1612,2863,4885 } }, - { "Canon PowerShot A650", 0, 0, /* DJC */ - { 9427,-3036,-959,-2581,10671,1911,-1039,1982,4430 } }, - { "Canon PowerShot A720", 0, 0, /* DJC */ - { 14573,-5482,-1546,-1266,9799,1468,-1040,1912,3810 } }, - { "Canon PowerShot S2 IS", 0, 0, /* jlb */ - { 14062,-5199,-1446,-4712,12470,2243,-1286,2028,4836 } }, /* jlb - copied from Powershot S3 IS */ - { "Canon PowerShot S3 IS", 0, 0, /* DJC */ - { 14062,-5199,-1446,-4712,12470,2243,-1286,2028,4836 } }, - { "Canon PowerShot SX1 IS", 0, 0, - { 6578,-259,-502,-5974,13030,3309,-308,1058,4970 } }, - { "Canon PowerShot SX110 IS", 0, 0, /* DJC */ - { 14134,-5576,-1527,-1991,10719,1273,-1158,1929,3581 } }, - { "CASIO EX-S20", 0, 0, /* DJC */ - { 11634,-3924,-1128,-4968,12954,2015,-1588,2648,7206 } }, - { "CASIO EX-Z750", 0, 0, /* DJC */ - { 10819,-3873,-1099,-4903,13730,1175,-1755,3751,4632 } }, - { "CASIO EX-Z10", 128, 0xfff, /* DJC */ - { 9790,-3338,-603,-2321,10222,2099,-344,1273,4799 } }, - { "CINE 650", 0, 0, - { 3390,480,-500,-800,3610,340,-550,2336,1192 } }, - { "CINE 660", 0, 0, - { 3390,480,-500,-800,3610,340,-550,2336,1192 } }, - { "CINE", 0, 0, - { 20183,-4295,-423,-3940,15330,3985,-280,4870,9800 } }, - { "Contax N Digital", 0, 0xf1e, - { 7777,1285,-1053,-9280,16543,2916,-3677,5679,7060 } }, - { "EPSON R-D1", 0, 0, - { 6827,-1878,-732,-8429,16012,2564,-704,592,7145 } }, - { "FUJIFILM E550", 0, 0, - { 11044,-3888,-1120,-7248,15168,2208,-1531,2277,8069 } }, - { "FUJIFILM E900", 0, 0, - { 9183,-2526,-1078,-7461,15071,2574,-2022,2440,8639 } }, - { "FUJIFILM F5", 0, 0, - { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, - { "FUJIFILM F6", 0, 0, - { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, - { "FUJIFILM F77", 0, 0, - { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, - { "FUJIFILM F7", 0, 0, - { 10004,-3219,-1201,-7036,15047,2107,-1863,2565,7736 } }, - { "FUJIFILM F8", 0, 0, - { 11044,-3888,-1120,-7248,15168,2208,-1531,2277,8069 } }, - { "FUJIFILM S100FS", 514, 0, - { 11521,-4355,-1065,-6524,13767,3058,-1466,1984,6045 } }, - { "FUJIFILM S200EXR", 512, 0x3fff, - { 11401,-4498,-1312,-5088,12751,2613,-838,1568,5941 } }, - { "FUJIFILM S20Pro", 0, 0, - { 10004,-3219,-1201,-7036,15047,2107,-1863,2565,7736 } }, - { "FUJIFILM S2Pro", 128, 0, - { 12492,-4690,-1402,-7033,15423,1647,-1507,2111,7697 } }, - { "FUJIFILM S3Pro", 0, 0, - { 11807,-4612,-1294,-8927,16968,1988,-2120,2741,8006 } }, - { "FUJIFILM S5Pro", 0, 0, - { 12300,-5110,-1304,-9117,17143,1998,-1947,2448,8100 } }, - { "FUJIFILM S5000", 0, 0, - { 8754,-2732,-1019,-7204,15069,2276,-1702,2334,6982 } }, - { "FUJIFILM S5100", 0, 0, - { 11940,-4431,-1255,-6766,14428,2542,-993,1165,7421 } }, - { "FUJIFILM S5500", 0, 0, - { 11940,-4431,-1255,-6766,14428,2542,-993,1165,7421 } }, - { "FUJIFILM S5200", 0, 0, - { 9636,-2804,-988,-7442,15040,2589,-1803,2311,8621 } }, - { "FUJIFILM S5600", 0, 0, - { 9636,-2804,-988,-7442,15040,2589,-1803,2311,8621 } }, - { "FUJIFILM S6", 0, 0, - { 12628,-4887,-1401,-6861,14996,1962,-2198,2782,7091 } }, - { "FUJIFILM S7000", 0, 0, - { 10190,-3506,-1312,-7153,15051,2238,-2003,2399,7505 } }, - { "FUJIFILM S9000", 0, 0, - { 10491,-3423,-1145,-7385,15027,2538,-1809,2275,8692 } }, - { "FUJIFILM S9500", 0, 0, - { 10491,-3423,-1145,-7385,15027,2538,-1809,2275,8692 } }, - { "FUJIFILM S9100", 0, 0, - { 12343,-4515,-1285,-7165,14899,2435,-1895,2496,8800 } }, - { "FUJIFILM S9600", 0, 0, - { 12343,-4515,-1285,-7165,14899,2435,-1895,2496,8800 } }, - { "FUJIFILM IS-1", 0, 0, - { 21461,-10807,-1441,-2332,10599,1999,289,875,7703 } }, - { "FUJIFILM IS Pro", 0, 0, - { 12300,-5110,-1304,-9117,17143,1998,-1947,2448,8100 } }, - { "FUJIFILM HS10 HS11", 0, 0xf68, - { 12440,-3954,-1183,-1123,9674,1708,-83,1614,4086 } }, - { "FUJIFILM HS20EXR", 0, 0, - { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, - { "FUJIFILM HS3", 0, 0, - { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, - { "FUJIFILM X100", 0, 0, - { 12161,-4457,-1069,-5034,12874,2400,-795,1724,6904 } }, - { "FUJIFILM X10", 0, 0, - { 13509,-6199,-1254,-4430,12733,1865,-331,1441,5022 } }, - { "FUJIFILM X-Pro1", 0, 0, - { 10413,-3996,-993,-3721,11640,2361,-733,1540,6011 } }, - { "FUJIFILM X-S1", 0, 0, - { 13509,-6199,-1254,-4430,12733,1865,-331,1441,5022 } }, - { "Imacon Ixpress", 0, 0, /* DJC */ - { 7025,-1415,-704,-5188,13765,1424,-1248,2742,6038 } }, - { "KODAK NC2000", 0, 0, - { 13891,-6055,-803,-465,9919,642,2121,82,1291 } }, - { "Kodak DCS315C", 8, 0, - { 17523,-4827,-2510,756,8546,-137,6113,1649,2250 } }, - { "Kodak DCS330C", 8, 0, - { 20620,-7572,-2801,-103,10073,-396,3551,-233,2220 } }, - { "KODAK DCS420", 0, 0, - { 10868,-1852,-644,-1537,11083,484,2343,628,2216 } }, - { "KODAK DCS460", 0, 0, - { 10592,-2206,-967,-1944,11685,230,2206,670,1273 } }, - { "KODAK EOSDCS1", 0, 0, - { 10592,-2206,-967,-1944,11685,230,2206,670,1273 } }, - { "KODAK EOSDCS3B", 0, 0, - { 9898,-2700,-940,-2478,12219,206,1985,634,1031 } }, - { "Kodak DCS520C", 180, 0, - { 24542,-10860,-3401,-1490,11370,-297,2858,-605,3225 } }, - { "Kodak DCS560C", 188, 0, - { 20482,-7172,-3125,-1033,10410,-285,2542,226,3136 } }, - { "Kodak DCS620C", 180, 0, - { 23617,-10175,-3149,-2054,11749,-272,2586,-489,3453 } }, - { "Kodak DCS620X", 185, 0, - { 13095,-6231,154,12221,-21,-2137,895,4602,2258 } }, - { "Kodak DCS660C", 214, 0, - { 18244,-6351,-2739,-791,11193,-521,3711,-129,2802 } }, - { "Kodak DCS720X", 0, 0, - { 11775,-5884,950,9556,1846,-1286,-1019,6221,2728 } }, - { "Kodak DCS760C", 0, 0, - { 16623,-6309,-1411,-4344,13923,323,2285,274,2926 } }, - { "Kodak DCS Pro SLR", 0, 0, - { 5494,2393,-232,-6427,13850,2846,-1876,3997,5445 } }, - { "Kodak DCS Pro 14nx", 0, 0, - { 5494,2393,-232,-6427,13850,2846,-1876,3997,5445 } }, - { "Kodak DCS Pro 14", 0, 0, - { 7791,3128,-776,-8588,16458,2039,-2455,4006,6198 } }, - { "Kodak ProBack645", 0, 0, - { 16414,-6060,-1470,-3555,13037,473,2545,122,4948 } }, - { "Kodak ProBack", 0, 0, - { 21179,-8316,-2918,-915,11019,-165,3477,-180,4210 } }, - { "KODAK P712", 0, 0, - { 9658,-3314,-823,-5163,12695,2768,-1342,1843,6044 } }, - { "KODAK P850", 0, 0xf7c, - { 10511,-3836,-1102,-6946,14587,2558,-1481,1792,6246 } }, - { "KODAK P880", 0, 0xfff, - { 12805,-4662,-1376,-7480,15267,2360,-1626,2194,7904 } }, - { "KODAK EasyShare Z980", 0, 0, - { 11313,-3559,-1101,-3893,11891,2257,-1214,2398,4908 } }, - { "KODAK EasyShare Z981", 0, 0, - { 12729,-4717,-1188,-1367,9187,2582,274,860,4411 } }, - { "KODAK EasyShare Z990", 0, 0xfed, - { 11749,-4048,-1309,-1867,10572,1489,-138,1449,4522 } }, - { "KODAK EASYSHARE Z1015", 0, 0xef1, - { 11265,-4286,-992,-4694,12343,2647,-1090,1523,5447 } }, - { "Leaf CMost", 0, 0, - { 3952,2189,449,-6701,14585,2275,-4536,7349,6536 } }, - { "Leaf Valeo 6", 0, 0, - { 3952,2189,449,-6701,14585,2275,-4536,7349,6536 } }, - { "Leaf Aptus 54S", 0, 0, - { 8236,1746,-1314,-8251,15953,2428,-3673,5786,5771 } }, - { "Leaf Aptus 65", 0, 0, - { 7914,1414,-1190,-8777,16582,2280,-2811,4605,5562 } }, - { "Leaf Aptus 75", 0, 0, - { 7914,1414,-1190,-8777,16582,2280,-2811,4605,5562 } }, - { "Leaf Aptus 22", 0, 0, - { 8236, 1746, -1314, -8251, 15953, 2428, -3673, 5786, 5770, } }, - { "Leaf Aptus-II 5", 0, 0, // Mamiya 645 AFD - { 8236, 1746, -1314, -8251, 15953, 2428, -3673, 5786, 5770, } }, - { "Leaf Aptus-II 6", 0, 0, - { 7914, 1414, -1190, -8777, 16582, 2280, -2811, 4605, 5562, } }, - { "Leaf Aptus-II 7", 0, 0, - { 7914, 1414, -1190, -8777, 16582, 2280, -2811, 4605, 5562, } }, - { "Leaf Aptus-II 8", 0, 0, // Hasselblad 500 Series - { 8236, 1746, -1314, -8251, 15953, 2428, -3673, 5786, 5770, } }, - { "Leaf Aptus-II 10", 0, 0, - { 8236, 1746, -1314, -8251, 15953, 2428, -3673, 5786, 5770, } }, - { "Leaf Aptus-II 10R", 0, 0, - { 8236, 1746, -1314, -8251, 15953, 2428, -3673, 5786, 5770, } }, - { "Leaf Aptus-II 12", 0, 0, - { 8236, 1746, -1314, -8251, 15953, 2428, -3673, 5786, 5770, } }, - { "Leaf", 0, 0, - { 8236,1746,-1314,-8251,15953,2428,-3673,5786,5771 } }, - { "Mamiya ZD", 0, 0, - { 7645,2579,-1363,-8689,16717,2015,-3712,5941,5961 } }, - { "Micron 2010", 110, 0, /* DJC */ - { 16695,-3761,-2151,155,9682,163,3433,951,4904 } }, - { "Minolta DiMAGE 5", 0, 0xf7d, - { 8983,-2942,-963,-6556,14476,2237,-2426,2887,8014 } }, - { "Minolta DiMAGE 7Hi", 0, 0xf7d, - { 11368,-3894,-1242,-6521,14358,2339,-2475,3056,7285 } }, - { "Minolta DiMAGE 7", 0, 0xf7d, - { 9144,-2777,-998,-6676,14556,2281,-2470,3019,7744 } }, - { "Minolta DiMAGE A1", 0, 0xf8b, - { 9274,-2547,-1167,-8220,16323,1943,-2273,2720,8340 } }, - { "MINOLTA DiMAGE A200", 0, 0, - { 8560,-2487,-986,-8112,15535,2771,-1209,1324,7743 } }, - { "Minolta DiMAGE A2", 0, 0xf8f, - { 9097,-2726,-1053,-8073,15506,2762,-966,981,7763 } }, - { "Minolta DiMAGE Z2", 0, 0, /* DJC */ - { 11280,-3564,-1370,-4655,12374,2282,-1423,2168,5396 } }, - { "MINOLTA DYNAX 5", 0, 0xffb, - { 10284,-3283,-1086,-7957,15762,2316,-829,882,6644 } }, - { "MINOLTA DYNAX 7", 0, 0xffb, - { 10239,-3104,-1099,-8037,15727,2451,-927,925,6871 } }, - { "MOTOROLA PIXL", 0, 0, /* DJC */ - { 8898,-989,-1033,-3292,11619,1674,-661,3178,5216 } }, - { "NIKON D100", 0, 0, - { 5902,-933,-782,-8983,16719,2354,-1402,1455,6464 } }, - { "NIKON D1H", 0, 0, - { 7577,-2166,-926,-7454,15592,1934,-2377,2808,8606 } }, - { "NIKON D1X", 0, 0, - { 7702,-2245,-975,-9114,17242,1875,-2679,3055,8521 } }, - { "NIKON D1", 0, 0, /* multiplied by 2.218750, 1.0, 1.148438 */ - { 16772,-4726,-2141,-7611,15713,1972,-2846,3494,9521 } }, - { "NIKON D200", 0, 0xfbc, - { 8367,-2248,-763,-8758,16447,2422,-1527,1550,8053 } }, - { "NIKON D2H", 0, 0, - { 5710,-901,-615,-8594,16617,2024,-2975,4120,6830 } }, - { "NIKON D2X", 0, 0, - { 10231,-2769,-1255,-8301,15900,2552,-797,680,7148 } }, - { "NIKON D3000", 0, 0, - { 8736,-2458,-935,-9075,16894,2251,-1354,1242,8263 } }, - { "NIKON D3100", 0, 0, - { 7911,-2167,-813,-5327,13150,2408,-1288,2483,7968 } }, - { "NIKON D3200", 0, 0, - { 7013,-1408,-635,-5268,12902,2640,-1470,2801,7379 } }, - { "NIKON D300", 0, 0, - { 9030,-1992,-715,-8465,16302,2255,-2689,3217,8069 } }, - { "NIKON D3X", 0, 0, - { 7171,-1986,-648,-8085,15555,2718,-2170,2512,7457 } }, - { "NIKON D3S", 0, 0, - { 8828,-2406,-694,-4874,12603,2541,-660,1509,7587 } }, - { "NIKON D3", 0, 0, - { 8139,-2171,-663,-8747,16541,2295,-1925,2008,8093 } }, - { "NIKON D40X", 0, 0, - { 8819,-2543,-911,-9025,16928,2151,-1329,1213,8449 } }, - { "NIKON D40", 0, 0, - { 6992,-1668,-806,-8138,15748,2543,-874,850,7897 } }, - { "NIKON D4", 0, 0, - { 8598,-2848,-857,-5618,13606,2195,-1002,1773,7137 } }, - { "NIKON D5000", 0, 0xf00, - { 7309,-1403,-519,-8474,16008,2622,-2433,2826,8064 } }, - { "NIKON D5100", 0, 0x3de6, - { 8198,-2239,-724,-4871,12389,2798,-1043,2050,7181 } }, - { "NIKON D50", 0, 0, - { 7732,-2422,-789,-8238,15884,2498,-859,783,7330 } }, - { "NIKON D60", 0, 0, - { 8736,-2458,-935,-9075,16894,2251,-1354,1242,8263 } }, - { "NIKON D7000", 0, 0, - { 8198,-2239,-724,-4871,12389,2798,-1043,2050,7181 } }, - { "NIKON D700", 0, 0, - { 8139,-2171,-663,-8747,16541,2295,-1925,2008,8093 } }, - { "NIKON D70", 0, 0, - { 7732,-2422,-789,-8238,15884,2498,-859,783,7330 } }, - { "NIKON D800", 0, 0, - { 7866,-2108,-555,-4869,12483,2681,-1176,2069,7501 } }, - { "NIKON D80", 0, 0, - { 8629,-2410,-883,-9055,16940,2171,-1490,1363,8520 } }, - { "NIKON D90", 0, 0xf00, - { 7309,-1403,-519,-8474,16008,2622,-2434,2826,8064 } }, - { "NIKON E950", 0, 0x3dd, /* DJC */ - { -3746,10611,1665,9621,-1734,2114,-2389,7082,3064,3406,6116,-244 } }, - { "NIKON E995", 0, 0, /* copied from E5000 */ - { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, - { "NIKON E2100", 0, 0, /* copied from Z2, new white balance */ - { 13142,-4152,-1596,-4655,12374,2282,-1769,2696,6711} }, - { "NIKON E2500", 0, 0, - { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, - { "NIKON E3200", 0, 0, /* DJC */ - { 9846,-2085,-1019,-3278,11109,2170,-774,2134,5745 } }, - { "NIKON E4300", 0, 0, /* copied from Minolta DiMAGE Z2 */ - { 11280,-3564,-1370,-4655,12374,2282,-1423,2168,5396 } }, - { "NIKON E4500", 0, 0, - { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, - { "NIKON E5000", 0, 0, - { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, - { "NIKON E5400", 0, 0, - { 9349,-2987,-1001,-7919,15766,2266,-2098,2680,6839 } }, - { "NIKON E5700", 0, 0, - { -5368,11478,2368,5537,-113,3148,-4969,10021,5782,778,9028,211 } }, - { "NIKON E8400", 0, 0, - { 7842,-2320,-992,-8154,15718,2599,-1098,1342,7560 } }, - { "NIKON E8700", 0, 0, - { 8489,-2583,-1036,-8051,15583,2643,-1307,1407,7354 } }, - { "NIKON E8800", 0, 0, - { 7971,-2314,-913,-8451,15762,2894,-1442,1520,7610 } }, - { "NIKON COOLPIX P6000", 0, 0, - { 9698,-3367,-914,-4706,12584,2368,-837,968,5801 } }, - { "NIKON COOLPIX P7000", 0, 0, - { 11432,-3679,-1111,-3169,11239,2202,-791,1380,4455 } }, - { "NIKON COOLPIX P7100", 0, 0, - { 11053,-4269,-1024,-1976,10182,2088,-526,1263,4469 } }, - { "NIKON 1 ", 0, 0, - { 8994,-2667,-865,-4594,12324,2552,-699,1786,6260 } }, - { "OLYMPUS C5050", 0, 0, - { 10508,-3124,-1273,-6079,14294,1901,-1653,2306,6237 } }, - { "OLYMPUS C5060", 0, 0, - { 10445,-3362,-1307,-7662,15690,2058,-1135,1176,7602 } }, - { "OLYMPUS C7070", 0, 0, - { 10252,-3531,-1095,-7114,14850,2436,-1451,1723,6365 } }, - { "OLYMPUS C70", 0, 0, - { 10793,-3791,-1146,-7498,15177,2488,-1390,1577,7321 } }, - { "OLYMPUS C80", 0, 0, - { 8606,-2509,-1014,-8238,15714,2703,-942,979,7760 } }, - { "OLYMPUS E-10", 0, 0xffc, - { 12745,-4500,-1416,-6062,14542,1580,-1934,2256,6603 } }, - { "OLYMPUS E-1", 0, 0, - { 11846,-4767,-945,-7027,15878,1089,-2699,4122,8311 } }, - { "OLYMPUS E-20", 0, 0xffc, - { 13173,-4732,-1499,-5807,14036,1895,-2045,2452,7142 } }, - { "OLYMPUS E-300", 0, 0, - { 7828,-1761,-348,-5788,14071,1830,-2853,4518,6557 } }, - { "OLYMPUS E-330", 0, 0, - { 8961,-2473,-1084,-7979,15990,2067,-2319,3035,8249 } }, - { "OLYMPUS E-30", 0, 0xfbc, - { 8144,-1861,-1111,-7763,15894,1929,-1865,2542,7607 } }, - { "OLYMPUS E-3", 0, 0xf99, - { 9487,-2875,-1115,-7533,15606,2010,-1618,2100,7389 } }, - { "OLYMPUS E-400", 0, 0, - { 6169,-1483,-21,-7107,14761,2536,-2904,3580,8568 } }, - { "OLYMPUS E-410", 0, 0xf6a, - { 8856,-2582,-1026,-7761,15766,2082,-2009,2575,7469 } }, - { "OLYMPUS E-420", 0, 0xfd7, - { 8746,-2425,-1095,-7594,15612,2073,-1780,2309,7416 } }, - { "OLYMPUS E-450", 0, 0xfd2, - { 8745,-2425,-1095,-7594,15613,2073,-1780,2309,7416 } }, - { "OLYMPUS E-500", 0, 0, - { 8136,-1968,-299,-5481,13742,1871,-2556,4205,6630 } }, - { "OLYMPUS E-510", 0, 0xf6a, - { 8785,-2529,-1033,-7639,15624,2112,-1783,2300,7817 } }, - { "OLYMPUS E-520", 0, 0xfd2, - { 8344,-2322,-1020,-7596,15635,2048,-1748,2269,7287 } }, - { "OLYMPUS E-5", 0, 0, - { 11200,-3783,-1325,-4576,12593,2206,-695,1742,7504 } }, - { "OLYMPUS E-600", 0, 0xfaf, - { 8453,-2198,-1092,-7609,15681,2008,-1725,2337,7824 } }, - { "OLYMPUS E-620", 0, 0xfaf, - { 8453,-2198,-1092,-7609,15681,2008,-1725,2337,7824 } }, - { "OLYMPUS E-P1", 0, 0xffd, - { 8343,-2050,-1021,-7715,15705,2103,-1831,2380,8235 } }, - { "OLYMPUS E-P2", 0, 0xffd, - { 8343,-2050,-1021,-7715,15705,2103,-1831,2380,8235 } }, - { "OLYMPUS E-P3", 0, 0, - { 7575,-2159,-571,-3722,11341,2725,-1434,2819,6271 } }, - { "OLYMPUS E-PL1s", 0, 0, - { 11409,-3872,-1393,-4572,12757,2003,-709,1810,7415 } }, - { "OLYMPUS E-PL1", 0, 0, - { 11408,-4289,-1215,-4286,12385,2118,-387,1467,7787 } }, - { "OLYMPUS E-PL2", 0, 0, - { 15030,-5552,-1806,-3987,12387,1767,-592,1670,7023 } }, - { "OLYMPUS E-PL3", 0, 0, - { 7575,-2159,-571,-3722,11341,2725,-1434,2819,6271 } }, - { "OLYMPUS E-PM1", 0, 0, - { 7575,-2159,-571,-3722,11341,2725,-1434,2819,6271 } }, - { "OLYMPUS E-M5", 0, 0, - { 8380,-2630,-639,-2887,10725,2496,-627,1427,5438 } }, - { "OLYMPUS SP350", 0, 0, - { 12078,-4836,-1069,-6671,14306,2578,-786,939,7418 } }, - { "OLYMPUS SP3", 0, 0, - { 11766,-4445,-1067,-6901,14421,2707,-1029,1217,7572 } }, - { "OLYMPUS SP500UZ", 0, 0xfff, - { 9493,-3415,-666,-5211,12334,3260,-1548,2262,6482 } }, - { "OLYMPUS SP510UZ", 0, 0xffe, - { 10593,-3607,-1010,-5881,13127,3084,-1200,1805,6721 } }, - { "OLYMPUS SP550UZ", 0, 0xffe, - { 11597,-4006,-1049,-5432,12799,2957,-1029,1750,6516 } }, - { "OLYMPUS SP560UZ", 0, 0xff9, - { 10915,-3677,-982,-5587,12986,2911,-1168,1968,6223 } }, - { "OLYMPUS SP570UZ", 0, 0, - { 11522,-4044,-1146,-4736,12172,2904,-988,1829,6039 } }, - { "OLYMPUS XZ-1", 0, 0, - { 10901,-4095,-1074,-1141,9208,2293,-62,1417,5158 } }, - { "PENTAX *ist DL2", 0, 0, - { 10504,-2438,-1189,-8603,16207,2531,-1022,863,12242 } }, - { "PENTAX *ist DL", 0, 0, - { 10829,-2838,-1115,-8339,15817,2696,-837,680,11939 } }, - { "PENTAX *ist DS2", 0, 0, - { 10504,-2438,-1189,-8603,16207,2531,-1022,863,12242 } }, - { "PENTAX *ist DS", 0, 0, - { 10371,-2333,-1206,-8688,16231,2602,-1230,1116,11282 } }, - { "PENTAX *ist D", 0, 0, - { 9651,-2059,-1189,-8881,16512,2487,-1460,1345,10687 } }, - { "PENTAX K10D", 0, 0, - { 9566,-2863,-803,-7170,15172,2112,-818,803,9705 } }, - { "PENTAX K1", 0, 0, - { 11095,-3157,-1324,-8377,15834,2720,-1108,947,11688 } }, - { "PENTAX K20D", 0, 0, - { 9427,-2714,-868,-7493,16092,1373,-2199,3264,7180 } }, - { "PENTAX K200D", 0, 0, - { 9186,-2678,-907,-8693,16517,2260,-1129,1094,8524 } }, - { "PENTAX K2000", 0, 0, - { 11057,-3604,-1155,-5152,13046,2329,-282,375,8104 } }, - { "PENTAX K-m", 0, 0, - { 11057,-3604,-1155,-5152,13046,2329,-282,375,8104 } }, - { "PENTAX K-x", 0, 0, - { 8843,-2837,-625,-5025,12644,2668,-411,1234,7410 } }, - { "PENTAX K-r", 0, 0, - { 9895,-3077,-850,-5304,13035,2521,-883,1768,6936 } }, - { "PENTAX K-5", 0, 0, - { 8713,-2833,-743,-4342,11900,2772,-722,1543,6247 } }, - { "PENTAX K-7", 0, 0, - { 9142,-2947,-678,-8648,16967,1663,-2224,2898,8615 } }, - { "PENTAX 645D", 0, 0x3e00, - { 10646,-3593,-1158,-3329,11699,1831,-667,2874,6287 } }, - { "Panasonic DMC-FZ8", 0, 0xf7f, - { 8986,-2755,-802,-6341,13575,3077,-1476,2144,6379 } }, - { "Panasonic DMC-FZ18", 0, 0, - { 9932,-3060,-935,-5809,13331,2753,-1267,2155,5575 } }, - { "Panasonic DMC-FZ28", 15, 0xf96, - { 10109,-3488,-993,-5412,12812,2916,-1305,2140,5543 } }, - { "Panasonic DMC-FZ30", 0, 0xf94, - { 10976,-4029,-1141,-7918,15491,2600,-1670,2071,8246 } }, - { "Panasonic DMC-FZ3", 143, 0, - { 9938,-2780,-890,-4604,12393,2480,-1117,2304,4620 } }, - { "Panasonic DMC-FZ4", 143, 0, - { 13639,-5535,-1371,-1698,9633,2430,316,1152,4108 } }, - { "Panasonic DMC-FZ50", 0, 0, - { 7906,-2709,-594,-6231,13351,3220,-1922,2631,6537 } }, - { "LEICA V-LUX1", 0, 0, - { 7906,-2709,-594,-6231,13351,3220,-1922,2631,6537 } }, - { "Panasonic DMC-L10", 15, 0xf96, - { 8025,-1942,-1050,-7920,15904,2100,-2456,3005,7039 } }, - { "Panasonic DMC-L1", 0, 0xf7f, - { 8054,-1885,-1025,-8349,16367,2040,-2805,3542,7629 } }, - { "LEICA DIGILUX 3", 0, 0xf7f, - { 8054,-1885,-1025,-8349,16367,2040,-2805,3542,7629 } }, - { "Panasonic DMC-LC1", 0, 0, - { 11340,-4069,-1275,-7555,15266,2448,-2960,3426,7685 } }, - { "LEICA DIGILUX 2", 0, 0, - { 11340,-4069,-1275,-7555,15266,2448,-2960,3426,7685 } }, - { "Panasonic DMC-LX1", 0, 0xf7f, - { 10704,-4187,-1230,-8314,15952,2501,-920,945,8927 } }, - { "LEICA D-LUX2", 0, 0xf7f, - { 10704,-4187,-1230,-8314,15952,2501,-920,945,8927 } }, - { "Panasonic DMC-LX2", 0, 0, - { 8048,-2810,-623,-6450,13519,3272,-1700,2146,7049 } }, - { "LEICA D-LUX3", 0, 0, - { 8048,-2810,-623,-6450,13519,3272,-1700,2146,7049 } }, - { "Panasonic DMC-LX3", 15, 0, - { 8128,-2668,-655,-6134,13307,3161,-1782,2568,6083 } }, - { "LEICA D-LUX 4", 15, 0, - { 8128,-2668,-655,-6134,13307,3161,-1782,2568,6083 } }, - { "Panasonic DMC-LX5", 143, 0, - { 10909,-4295,-948,-1333,9306,2399,22,1738,4582 } }, - { "LEICA D-LUX 5", 143, 0, - { 10909,-4295,-948,-1333,9306,2399,22,1738,4582 } }, - { "Panasonic DMC-FZ100", 143, 0xfff, - { 16197,-6146,-1761,-2393,10765,1869,366,2238,5248 } }, - { "LEICA V-LUX 2", 143, 0xfff, - { 16197,-6146,-1761,-2393,10765,1869,366,2238,5248 } }, - { "Panasonic DMC-FZ150", 143, 0xfff, - { 11904,-4541,-1189,-2355,10899,1662,-296,1586,4289 } }, - { "LEICA V-LUX 3", 143, 0xfff, - { 11904,-4541,-1189,-2355,10899,1662,-296,1586,4289 } }, - { "Panasonic DMC-FX150", 15, 0xfff, - { 9082,-2907,-925,-6119,13377,3058,-1797,2641,5609 } }, - { "Panasonic DMC-G10", 0, 0, - { 10113,-3400,-1114,-4765,12683,2317,-377,1437,6710 } }, - { "Panasonic DMC-G1", 15, 0xf94, - { 8199,-2065,-1056,-8124,16156,2033,-2458,3022,7220 } }, - { "Panasonic DMC-G2", 15, 0xf3c, - { 10113,-3400,-1114,-4765,12683,2317,-377,1437,6710 } }, - { "Panasonic DMC-G3", 143, 0xfff, - { 6763,-1919,-863,-3868,11515,2684,-1216,2387,5879 } }, - { "Panasonic DMC-GF1", 15, 0xf92, - { 7888,-1902,-1011,-8106,16085,2099,-2353,2866,7330 } }, - { "Panasonic DMC-GF2", 143, 0xfff, - { 7888,-1902,-1011,-8106,16085,2099,-2353,2866,7330 } }, - { "Panasonic DMC-GF3", 143, 0xfff, - { 9051,-2468,-1204,-5212,13276,2121,-1197,2510,6890 } }, - { "Panasonic DMC-GF5", 143, 0xfff, - { 8228,-2945,-660,-3938,11792,2430,-1094,2278,5793 } }, - { "Panasonic DMC-GH1", 15, 0xf92, - { 6299,-1466,-532,-6535,13852,2969,-2331,3112,5984 } }, - { "Panasonic DMC-GH2", 15, 0xf95, - { 7780,-2410,-806,-3913,11724,2484,-1018,2390,5298 } }, - { "Panasonic DMC-GX1", 143, 0, - { 6763,-1919,-863,-3868,11515,2684,-1216,2387,5879 } }, - { "Phase One H 20", 0, 0, /* DJC */ - { 1313,1855,-109,-6715,15908,808,-327,1840,6020 } }, - { "Phase One H 25", 0, 0, - { 2905,732,-237,-8134,16626,1476,-3038,4253,7517 } }, - { "Phase One P 2", 0, 0, - { 2905,732,-237,-8134,16626,1476,-3038,4253,7517 } }, - { "Phase One P 30", 0, 0, - { 4516,-245,-37,-7020,14976,2173,-3206,4671,7087 } }, - { "Phase One P 45", 0, 0, - { 5053,-24,-117,-5684,14076,1702,-2619,4492,5849 } }, - { "Phase One P40", 0, 0, - { 8035,435,-962,-6001,13872,2320,-1159,3065,5434 } }, - { "Phase One P65", 0, 0, - { 8035,435,-962,-6001,13872,2320,-1159,3065,5434 } }, - { "RED ONE", 704, 0xffff, /* DJC */ - { 21014,-7891,-2613,-3056,12201,856,-2203,5125,8042 } }, - { "SAMSUNG EX1", 0, 0x3e00, - { 8898,-2498,-994,-3144,11328,2066,-760,1381,4576 } }, - { "SAMSUNG NX2", 0, 0xfff, /* NX20, NX200, NX210 */ - { 6933,-2268,-753,-4921,13387,1647,-803,1641,6096 } }, - { "SAMSUNG NX", 0, 0, /* NX5, NX10, NX11, NX100 */ - { 10332,-3234,-1168,-6111,14639,1520,-1352,2647,8331 } }, - { "SAMSUNG WB2000", 0, 0xfff, - { 12093,-3557,-1155,-1000,9534,1733,-22,1787,4576 } }, - { "SAMSUNG GX-1", 0, 0, - { 10504,-2438,-1189,-8603,16207,2531,-1022,863,12242 } }, - { "SAMSUNG S85", 0, 0xffff, /* DJC */ - { 11885,-3968,-1473,-4214,12299,1916,-835,1655,5549 } }, - { "Sinar", 0, 0, /* DJC */ - { 16442,-2956,-2422,-2877,12128,750,-1136,6066,4559 } }, - { "SONY DSC-F828", 491, 0, - { 7924,-1910,-777,-8226,15459,2998,-1517,2199,6818,-7242,11401,3481 } }, - { "SONY DSC-R1", 512, 0, - { 8512,-2641,-694,-8042,15670,2526,-1821,2117,7414 } }, - { "SONY DSC-V3", 0, 0, - { 7511,-2571,-692,-7894,15088,3060,-948,1111,8128 } }, - { "SONY DSLR-A100", 0, 0xfeb, - { 9437,-2811,-774,-8405,16215,2290,-710,596,7181 } }, - { "SONY DSLR-A290", 0, 0, - { 6038,-1484,-579,-9145,16746,2512,-875,746,7218 } }, - { "SONY DSLR-A2", 0, 0, - { 9847,-3091,-928,-8485,16345,2225,-715,595,7103 } }, - { "SONY DSLR-A300", 0, 0, - { 9847,-3091,-928,-8485,16345,2225,-715,595,7103 } }, - { "SONY DSLR-A330", 0, 0, - { 9847,-3091,-929,-8485,16346,2225,-714,595,7103 } }, - { "SONY DSLR-A350", 0, 0xffc, - { 6038,-1484,-578,-9146,16746,2513,-875,746,7217 } }, - { "SONY DSLR-A380", 0, 0, - { 6038,-1484,-579,-9145,16746,2512,-875,746,7218 } }, - { "SONY DSLR-A390", 0, 0, - { 6038,-1484,-579,-9145,16746,2512,-875,746,7218 } }, - { "SONY DSLR-A450", 128, 0xfeb, - { 4950,-580,-103,-5228,12542,3029,-709,1435,7371 } }, - { "SONY DSLR-A580", 128, 0xfeb, - { 5932,-1492,-411,-4813,12285,2856,-741,1524,6739 } }, - { "SONY DSLR-A5", 128, 0xfeb, - { 4950,-580,-103,-5228,12542,3029,-709,1435,7371 } }, - { "SONY DSLR-A700", 126, 0, - { 5775,-805,-359,-8574,16295,2391,-1943,2341,7249 } }, - { "SONY DSLR-A850", 128, 0, - { 5413,-1162,-365,-5665,13098,2866,-608,1179,8440 } }, - { "SONY DSLR-A900", 128, 0, - { 5209,-1072,-397,-8845,16120,2919,-1618,1803,8654 } }, - { "SONY NEX-5N", 128, 0, - { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, - { "SONY NEX-3", 138, 0, /* DJC */ - { 6907,-1256,-645,-4940,12621,2320,-1710,2581,6230 } }, - { "SONY NEX-5", 116, 0, /* DJC */ - { 6807,-1350,-342,-4216,11649,2567,-1089,2001,6420 } }, - { "SONY NEX-3", 128, 0, /* Adobe */ - { 6549,-1550,-436,-4880,12435,2753,-854,1868,6976 } }, - { "SONY NEX-5", 128, 0, /* Adobe */ - { 6549,-1550,-436,-4880,12435,2753,-854,1868,6976 } }, - { "SONY NEX-7", 128, 0, - { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } }, - { "SONY NEX", 128, 0, /* NEX-C3, NEX-F3 */ - { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, - { "SONY SLT-A33", 128, 0, - { 6069,-1221,-366,-5221,12779,2734,-1024,2066,6834 } }, - { "SONY SLT-A35", 128, 0, - { 5986,-1618,-415,-4557,11820,3120,-681,1404,6971 } }, - { "SONY SLT-A37", 128, 0, - { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, - { "SONY SLT-A55", 128, 0, - { 5932,-1492,-411,-4813,12285,2856,-741,1524,6739 } }, - { "SONY SLT-A57", 128, 0, - { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, - { "SONY SLT-A65", 128, 0, - { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } }, - { "SONY SLT-A77", 128, 0, - { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } } - }; - double cam_xyz[4][3]; - char name[130]; - int i, j; - - sprintf (name, "%s %s", p_make, p_model); - for (i=0; i < sizeof table / sizeof *table; i++) - if (!strncmp (name, table[i].prefix, strlen(table[i].prefix))) { - if (table[i].t_black) black = (ushort) table[i].t_black; - if (table[i].t_maximum) maximum = (ushort) table[i].t_maximum; - if (table[i].trans[0]) { - for (j=0; j < 12; j++) -#ifdef LIBRAW_LIBRARY_BUILD - imgdata.color.cam_xyz[0][j] = -#endif - cam_xyz[0][j] = table[i].trans[j] / 10000.0; - cam_xyz_coeff (cam_xyz); - } - break; - } -} - -void CLASS simple_coeff (int index) -{ - static const float table[][12] = { - /* index 0 -- all Foveon cameras */ - { 1.4032,-0.2231,-0.1016,-0.5263,1.4816,0.017,-0.0112,0.0183,0.9113 }, - /* index 1 -- Kodak DC20 and DC25 */ - { 2.25,0.75,-1.75,-0.25,-0.25,0.75,0.75,-0.25,-0.25,-1.75,0.75,2.25 }, - /* index 2 -- Logitech Fotoman Pixtura */ - { 1.893,-0.418,-0.476,-0.495,1.773,-0.278,-1.017,-0.655,2.672 }, - /* index 3 -- Nikon E880, E900, and E990 */ - { -1.936280, 1.800443, -1.448486, 2.584324, - 1.405365, -0.524955, -0.289090, 0.408680, - -1.204965, 1.082304, 2.941367, -1.818705 } - }; - int i, c; - - for (raw_color = i=0; i < 3; i++) - FORCC rgb_cam[i][c] = table[index][i*colors+c]; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.rgb_cam_state = LIBRAW_COLORSTATE_CALCULATED; -#endif -} - -short CLASS guess_byte_order (int words) -{ - uchar test[4][2]; - int t=2, msb; - double diff, sum[2] = {0,0}; - - fread (test[0], 2, 2, ifp); - for (words-=2; words--; ) { - fread (test[t], 2, 1, ifp); - for (msb=0; msb < 2; msb++) { - diff = (test[t^2][msb] << 8 | test[t^2][!msb]) - - (test[t ][msb] << 8 | test[t ][!msb]); - sum[msb] += diff*diff; - } - t = (t+1) & 3; - } - return sum[0] < sum[1] ? 0x4d4d : 0x4949; -} - - -float CLASS find_green (int bps, int bite, int off0, int off1) -{ - UINT64 bitbuf=0; - int vbits, col, i, c; - ushort img[2][2064]; - double sum[]={0,0}; - - FORC(2) { - fseek (ifp, c ? off1:off0, SEEK_SET); - for (vbits=col=0; col < width; col++) { - for (vbits -= bps; vbits < 0; vbits += bite) { - bitbuf <<= bite; - for (i=0; i < bite; i+=8) - bitbuf |= (unsigned) (fgetc(ifp) << i); - } - img[c][col] = bitbuf << (64-bps-vbits) >> (64-bps); - } - } - FORC(width-1) { - sum[ c & 1] += ABS(img[0][c]-img[1][c+1]); - sum[~c & 1] += ABS(img[1][c]-img[0][c+1]); - } - return 100 * log(sum[0]/sum[1]); -} - -/* - Identify which camera created this file, and set global variables - accordingly. - */ -void CLASS identify() -{ - char head[32], *cp; - int hlen, flen, fsize, zero_fsize=1, i, c, is_canon; - struct jhead jh; - short pana[][6] = { - { 3130, 1743, 4, 0, -6, 0 }, - { 3130, 2055, 4, 0, -6, 0 }, - { 3130, 2319, 4, 0, -6, 0 }, - { 3170, 2103, 18, 0,-42, 20 }, - { 3170, 2367, 18, 13,-42,-21 }, - { 3177, 2367, 0, 0, -1, 0 }, - { 3304, 2458, 0, 0, -1, 0 }, - { 3330, 2463, 9, 0, -5, 0 }, - { 3330, 2479, 9, 0,-17, 4 }, - { 3370, 1899, 15, 0,-44, 20 }, - { 3370, 2235, 15, 0,-44, 20 }, - { 3370, 2511, 15, 10,-44,-21 }, - { 3690, 2751, 3, 0, -8, -3 }, - { 3710, 2751, 0, 0, -3, 0 }, - { 3724, 2450, 0, 0, 0, -2 }, - { 3770, 2487, 17, 0,-44, 19 }, - { 3770, 2799, 17, 15,-44,-19 }, - { 3880, 2170, 6, 0, -6, 0 }, - { 4060, 3018, 0, 0, 0, -2 }, - { 4290, 2391, 3, 0, -8, -1 }, - { 4330, 2439, 17, 15,-44,-19 }, - { 4508, 2962, 0, 0, -3, -4 }, - { 4508, 3330, 0, 0, -3, -6 } }; - static const struct { - int fsize; - char t_make[12], t_model[19], withjpeg; - } table[] = { - { 62464, "Kodak", "DC20" ,0 }, - { 124928, "Kodak", "DC20" ,0 }, - { 1652736, "Kodak", "DCS200" ,0 }, - { 4159302, "Kodak", "C330" ,0 }, - { 4162462, "Kodak", "C330" ,0 }, - { 460800, "Kodak", "C603v" ,0 }, - { 614400, "Kodak", "C603v" ,0 }, - { 6163328, "Kodak", "C603" ,0 }, - { 6166488, "Kodak", "C603" ,0 }, - { 9116448, "Kodak", "C603y" ,0 }, - { 311696, "ST Micro", "STV680 VGA" ,0 }, /* SPYz */ - { 787456, "Creative", "PC-CAM 600" ,0 }, - { 1138688, "Minolta", "RD175" ,0 }, - { 3840000, "Foculus", "531C" ,0 }, - { 307200, "Generic", "640x480" ,0 }, - { 786432, "AVT", "F-080C" ,0 }, - { 1447680, "AVT", "F-145C" ,0 }, - { 1920000, "AVT", "F-201C" ,0 }, - { 5067304, "AVT", "F-510C" ,0 }, - { 5067316, "AVT", "F-510C" ,0 }, - { 10134608, "AVT", "F-510C" ,0 }, - { 10134620, "AVT", "F-510C" ,0 }, - { 16157136, "AVT", "F-810C" ,0 }, - { 1409024, "Sony", "XCD-SX910CR" ,0 }, - { 2818048, "Sony", "XCD-SX910CR" ,0 }, - { 3884928, "Micron", "2010" ,0 }, - { 6624000, "Pixelink", "A782" ,0 }, - { 13248000, "Pixelink", "A782" ,0 }, - { 6291456, "RoverShot","3320AF" ,0 }, - { 6553440, "Canon", "PowerShot A460" ,0 }, - { 6653280, "Canon", "PowerShot A530" ,0 }, - { 6573120, "Canon", "PowerShot A610" ,0 }, - { 9219600, "Canon", "PowerShot A620" ,0 }, - { 9243240, "Canon", "PowerShot A470" ,0 }, - { 10341600, "Canon", "PowerShot A720 IS",0 }, - { 10383120, "Canon", "PowerShot A630" ,0 }, - { 12945240, "Canon", "PowerShot A640" ,0 }, - { 15636240, "Canon", "PowerShot A650" ,0 }, - { 5298000, "Canon", "PowerShot SD300" ,0 }, - { 7710960, "Canon", "PowerShot S3 IS" ,0 }, - { 15467760, "Canon", "PowerShot SX110 IS",0 }, - { 15534576, "Canon", "PowerShot SX120 IS",0 }, - { 18653760, "Canon", "PowerShot SX20 IS",0 }, - { 19131120, "Canon", "PowerShot SX220 HS",0 }, - { 21936096, "Canon", "PowerShot SX30 IS",0 }, - { 5939200, "OLYMPUS", "C770UZ" ,0 }, - { 1581060, "NIKON", "E900" ,1 }, /* or E900s,E910 */ - { 2465792, "NIKON", "E950" ,1 }, /* or E800,E700 */ - { 2940928, "NIKON", "E2100" ,1 }, /* or E2500 */ - { 4771840, "NIKON", "E990" ,1 }, /* or E995, Oly C3030Z */ - { 4775936, "NIKON", "E3700" ,1 }, /* or Optio 33WR */ - { 5869568, "NIKON", "E4300" ,1 }, /* or DiMAGE Z2 */ - { 5865472, "NIKON", "E4500" ,1 }, - { 7438336, "NIKON", "E5000" ,1 }, /* or E5700 */ - { 8998912, "NIKON", "COOLPIX S6" ,1 }, - { 1976352, "CASIO", "QV-2000UX" ,1 }, - { 3217760, "CASIO", "QV-3*00EX" ,1 }, - { 6218368, "CASIO", "QV-5700" ,1 }, - { 6054400, "CASIO", "QV-R41" ,1 }, - { 7530816, "CASIO", "QV-R51" ,1 }, - { 7684000, "CASIO", "QV-4000" ,1 }, - { 2937856, "CASIO", "EX-S20" ,1 }, - { 4948608, "CASIO", "EX-S100" ,1 }, - { 7542528, "CASIO", "EX-Z50" ,1 }, - { 7562048, "CASIO", "EX-Z500" ,1 }, - { 7753344, "CASIO", "EX-Z55" ,1 }, - { 7816704, "CASIO", "EX-Z60" ,1 }, - { 10843712, "CASIO", "EX-Z75" ,1 }, - { 10834368, "CASIO", "EX-Z750" ,1 }, - { 12310144, "CASIO", "EX-Z850" ,1 }, - { 12489984, "CASIO", "EX-Z8" ,1 }, - { 15499264, "CASIO", "EX-Z1050" ,1 }, - { 7426656, "CASIO", "EX-P505" ,1 }, - { 9313536, "CASIO", "EX-P600" ,1 }, - { 10979200, "CASIO", "EX-P700" ,1 }, - { 3178560, "PENTAX", "Optio S" ,1 }, - { 4841984, "PENTAX", "Optio S" ,1 }, - { 6114240, "PENTAX", "Optio S4" ,1 }, /* or S4i, CASIO EX-Z4 */ - { 10702848, "PENTAX", "Optio 750Z" ,1 }, - { 15980544, "AGFAPHOTO","DC-833m" ,1 }, - { 16098048, "SAMSUNG", "S85" ,1 }, - { 16215552, "SAMSUNG", "S85" ,1 }, - { 20487168, "SAMSUNG", "WB550" ,1 }, - { 24000000, "SAMSUNG", "WB550" ,1 }, - { 9994240, "ptGrey", "GRAS-50S5C" ,0 }, // KC: SUPPORT GRASSHOPPER - { 10075968, "JaiPulnix","BB-500CL" ,0 }, // KC: SUPPORT BB-500CL - { 10108896, "JaiPulnix","BB-500GE" ,0 }, // KC: SUPPORT BB-500GE - { 10036800, "SVS", "SVS625CL" ,0 }, // KC: SUPPORT SVS625 cameralink - { 12582980, "Sinar", "" ,0 }, - { 33292868, "Sinar", "" ,0 }, - { 44390468, "Sinar", "" ,0 } }; - static const char *corp[] = - { "Canon", "NIKON", "EPSON", "KODAK", "Kodak", "OLYMPUS", "PENTAX", - "MINOLTA", "Minolta", "Konica", "CASIO", "Sinar", "Phase One", - "SAMSUNG", "Mamiya", "MOTOROLA", "LEICA" }; - -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_IDENTIFY,0,2); -#endif - - tiff_flip = flip = filters = -1; /* 0 is valid, so -1 is unknown */ - raw_height = raw_width = fuji_width = fuji_layout = cr2_slice[0] = 0; - maximum = height = width = top_margin = left_margin = 0; - cdesc[0] = desc[0] = artist[0] = make[0] = model[0] = model2[0] = 0; - iso_speed = shutter = aperture = focal_len = unique_id = 0; - tiff_nifds = 0; - memset (tiff_ifd, 0, sizeof tiff_ifd); - memset (gpsdata, 0, sizeof gpsdata); - memset (cblack, 0, sizeof cblack); - memset (white, 0, sizeof white); - thumb_offset = thumb_length = thumb_width = thumb_height = 0; - load_raw = thumb_load_raw = 0; - write_thumb = &CLASS jpeg_thumb; - data_offset = meta_length = tiff_bps = tiff_compress = 0; - kodak_cbpp = zero_after_ff = dng_version = load_flags = 0; - timestamp = shot_order = tiff_samples = black = is_foveon = 0; - mix_green = profile_length = data_error = zero_is_bad = 0; - pixel_aspect = is_raw = raw_color = 1; - tile_width = tile_length = INT_MAX; - for (i=0; i < 4; i++) { - cam_mul[i] = i == 1; - pre_mul[i] = i < 3; - FORC3 cmatrix[c][i] = 0; - FORC3 rgb_cam[c][i] = c == i; - } -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cmatrix_state = LIBRAW_COLORSTATE_INIT; - color_flags.rgb_cam_state = LIBRAW_COLORSTATE_INIT; - color_flags.pre_mul_state = LIBRAW_COLORSTATE_INIT; - color_flags.cam_mul_state = LIBRAW_COLORSTATE_INIT; -#endif - colors = 3; - for (i=0; i < 0x4000; i++) curve[i] = i; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.curve_state = LIBRAW_COLORSTATE_INIT; -#endif - - order = get2(); - hlen = get4(); - fseek (ifp, 0, SEEK_SET); - fread (head, 1, 32, ifp); - fseek (ifp, 0, SEEK_END); - flen = fsize = ftell(ifp); - if ((cp = (char *) memmem (head, 32, (char*)"MMMM", 4)) || - (cp = (char *) memmem (head, 32, (char*)"IIII", 4))) { - parse_phase_one (cp-head); - if (cp-head && parse_tiff(0)) apply_tiff(); - } else if (order == 0x4949 || order == 0x4d4d) { - if (!memcmp (head+6,"HEAPCCDR",8)) { - data_offset = hlen; - parse_ciff (hlen, flen - hlen); - } else if (parse_tiff(0)) apply_tiff(); - } else if (!memcmp (head,"\xff\xd8\xff\xe1",4) && - !memcmp (head+6,"Exif",4)) { - fseek (ifp, 4, SEEK_SET); - data_offset = 4 + get2(); - fseek (ifp, data_offset, SEEK_SET); - if (fgetc(ifp) != 0xff) - parse_tiff(12); - thumb_offset = 0; - } else if (!memcmp (head+25,"ARECOYK",7)) { - strcpy (make, "Contax"); - strcpy (model,"N Digital"); - fseek (ifp, 33, SEEK_SET); - get_timestamp(1); - fseek (ifp, 60, SEEK_SET); - FORC4 cam_mul[c ^ (c >> 1)] = get4(); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; -#endif - } else if (!strcmp (head, "PXN")) { - strcpy (make, "Logitech"); - strcpy (model,"Fotoman Pixtura"); - } else if (!strcmp (head, "qktk")) { - strcpy (make, "Apple"); - strcpy (model,"QuickTake 100"); - load_raw = &CLASS quicktake_100_load_raw; - } else if (!strcmp (head, "qktn")) { - strcpy (make, "Apple"); - strcpy (model,"QuickTake 150"); - load_raw = &CLASS kodak_radc_load_raw; - } else if (!memcmp (head,"FUJIFILM",8)) { - fseek (ifp, 84, SEEK_SET); - thumb_offset = get4(); - thumb_length = get4(); - fseek (ifp, 92, SEEK_SET); - parse_fuji (get4()); - if (thumb_offset > 120) { - fseek (ifp, 120, SEEK_SET); - is_raw += (i = get4()) && 1; - if (is_raw == 2 && shot_select) - parse_fuji (i); - } -// load_raw = &CLASS unpacked_load_raw; - fseek (ifp, 100+28*(shot_select > 0), SEEK_SET); - parse_tiff (data_offset = get4()); - parse_tiff (thumb_offset+12); - apply_tiff(); - } else if (!memcmp (head,"RIFF",4)) { - fseek (ifp, 0, SEEK_SET); - parse_riff(); - } else if (!memcmp (head,"\0\001\0\001\0@",6)) { - fseek (ifp, 6, SEEK_SET); - fread (make, 1, 8, ifp); - fread (model, 1, 8, ifp); - fread (model2, 1, 16, ifp); - data_offset = get2(); - get2(); - raw_width = get2(); - raw_height = get2(); - load_raw = &CLASS nokia_load_raw; - filters = 0x61616161; - } else if (!memcmp (head,"NOKIARAW",8)) { - strcpy (make, "NOKIA"); - strcpy (model, "X2"); - order = 0x4949; - fseek (ifp, 300, SEEK_SET); - data_offset = get4(); - i = get4(); - width = get2(); - height = get2(); - data_offset += i - width * 5 / 4 * height; - load_raw = &CLASS nokia_load_raw; - filters = 0x61616161; - } else if (!memcmp (head,"ARRI",4)) { - order = 0x4949; - fseek (ifp, 20, SEEK_SET); - width = get4(); - height = get4(); - strcpy (make, "ARRI"); - fseek (ifp, 668, SEEK_SET); - fread (model, 1, 64, ifp); - data_offset = 4096; - load_raw = &CLASS packed_load_raw; - load_flags = 88; - filters = 0x61616161; - } else if (!memcmp (head+4,"RED1",4)) { - strcpy (make, "RED"); - strcpy (model,"ONE"); - parse_redcine(); - load_raw = &CLASS redcine_load_raw; - gamma_curve (1/2.4, 12.92, 1, 4095); - filters = 0x49494949; - } else if (!memcmp (head,"DSC-Image",9)) - parse_rollei(); - else if (!memcmp (head,"PWAD",4)) - parse_sinar_ia(); - else if (!memcmp (head,"\0MRM",4)) - parse_minolta(0); - else if (!memcmp (head,"FOVb",4)) - { - parse_foveon(); - if(!strcasecmp(make,"SIGMA") && !strncasecmp(model,"SIGMA DP",8)) - { - make[0] = model[0] = 0; - is_foveon = 0; - } - } - else if (!memcmp (head,"CI",2)) - parse_cine(); - else - for (zero_fsize=i=0; i < sizeof table / sizeof *table; i++) - if (fsize == table[i].fsize) { - strcpy (make, table[i].t_make ); - strcpy (model, table[i].t_model); - if (table[i].withjpeg) - parse_external_jpeg(); - } - if (zero_fsize) fsize = 0; - if (make[0] == 0) parse_smal (0, flen); - if (make[0] == 0) parse_jpeg (is_raw = 0); - - for (i=0; i < sizeof corp / sizeof *corp; i++) - if (strstr (make, corp[i])) /* Simplify company names */ - strcpy (make, corp[i]); - if (!strncmp (make,"KODAK",5) && - ((cp = strstr(model," DIGITAL CAMERA")) || - (cp = strstr(model," Digital Camera")) || - (cp = strstr(model,"FILE VERSION")))) - *cp = 0; - cp = make + strlen(make); /* Remove trailing spaces */ - while (*--cp == ' ') *cp = 0; - cp = model + strlen(model); - while (*--cp == ' ') *cp = 0; - i = strlen(make); /* Remove make from model */ - if (!strncasecmp (model, make, i) && model[i++] == ' ') - memmove (model, model+i, 64-i); - if (!strncmp (model,"FinePix ",8)) - strcpy (model, model+8); - if (!strncmp (model,"Digital Camera ",15)) - strcpy (model, model+15); - desc[511] = artist[63] = make[63] = model[63] = model2[63] = 0; - if (!is_raw) goto notraw; - - if (!height) height = raw_height; - if (!width) width = raw_width; - if (fuji_width) { - fuji_width = (raw_width+1)/2; - width = height + fuji_width; - height = width - 1; - pixel_aspect = 1; - } - if (height == 2624 && width == 3936) /* Pentax K10D and Samsung GX10 */ - { height = 2616; width = 3896; } - if (height == 3136 && width == 4864) /* Pentax K20D and Samsung GX20 */ - { height = 3124; width = 4688; filters = 0x16161616; } - if (width == 4352 && (!strcmp(model,"K-r") || !strcmp(model,"K-x"))) - { width = 4309; filters = 0x16161616; } - if (width >= 4960 && !strcmp(model,"K-5")) - { left_margin = 10; width = 4950; filters = 0x16161616; } - if (width == 4736 && !strcmp(model,"K-7")) - { height = 3122; width = 4684; filters = 0x16161616; top_margin = 2; } - if (width == 7424 && !strcmp(model,"645D")) - { height = 5502; width = 7328; filters = 0x61616161; top_margin = 29; - left_margin = 48; } - if (height == 3014 && width == 4096) /* Ricoh GX200 */ - width = 4014; - if (dng_version) { - if (filters == UINT_MAX) filters = 0; - if (filters) is_raw = tiff_samples; - else colors = tiff_samples; - if (tiff_compress == 1) - load_raw = &CLASS adobe_dng_load_raw_nc; - if (tiff_compress == 7) - load_raw = &CLASS adobe_dng_load_raw_lj; - goto dng_skip; - } - if ((is_canon = !strcmp(make,"Canon"))) - load_raw = memcmp (head+6,"HEAPCCDR",8) ? - &CLASS lossless_jpeg_load_raw : &CLASS canon_compressed_load_raw; - if (!strcmp(make,"NIKON")) { - if (!load_raw) - load_raw = &CLASS packed_load_raw; - if (model[0] == 'E') - load_flags |= !data_offset << 2 | 2; - } - if (!strcmp(make,"CASIO")) { - load_raw = &CLASS packed_load_raw; - maximum = 0xf7f; - } - -/* Set parameters based on camera name (for non-DNG files). */ - if (is_foveon) { - if (height*2 < width) pixel_aspect = 0.5; - if (height > width) pixel_aspect = 2; - filters = 0; - load_raw = &CLASS foveon_load_raw; - simple_coeff(0); - } else if (is_canon && tiff_bps == 15) { - switch (width) { - case 3344: width -= 66; - case 3872: width -= 6; - } - filters = 0; - load_raw = &CLASS canon_sraw_load_raw; - } else if (!strcmp(model,"PowerShot 600")) { - height = 613; - width = 854; - raw_width = 896; - pixel_aspect = 607/628.0; - colors = 4; - filters = 0xe1e4e1e4; - load_raw = &CLASS canon_600_load_raw; - } else if (!strcmp(model,"PowerShot A5") || - !strcmp(model,"PowerShot A5 Zoom")) { - height = 773; - width = 960; - raw_width = 992; - pixel_aspect = 256/235.0; - colors = 4; - filters = 0x1e4e1e4e; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A50")) { - height = 968; - width = 1290; - raw_width = 1320; - colors = 4; - filters = 0x1b4e4b1e; - goto canon_a5; - } else if (!strcmp(model,"PowerShot Pro70")) { - height = 1024; - width = 1552; - colors = 4; - filters = 0x1e4b4e1b; - goto canon_a5; - } else if (!strcmp(model,"PowerShot SD300")) { - height = 1752; - width = 2344; - raw_height = 1766; - raw_width = 2400; - top_margin = 12; - left_margin = 12; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A460")) { - height = 1960; - width = 2616; - raw_height = 1968; - raw_width = 2664; - top_margin = 4; - left_margin = 4; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A530")) { - height = 1984; - width = 2620; - raw_height = 1992; - raw_width = 2672; - top_margin = 6; - left_margin = 10; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A610")) { - if (canon_s2is()) strcpy (model+10, "S2 IS"); - height = 1960; - width = 2616; - raw_height = 1968; - raw_width = 2672; - top_margin = 8; - left_margin = 12; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A620")) { - height = 2328; - width = 3112; - raw_height = 2340; - raw_width = 3152; - top_margin = 12; - left_margin = 36; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A470")) { - height = 2328; - width = 3096; - raw_height = 2346; - raw_width = 3152; - top_margin = 6; - left_margin = 12; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A720 IS")) { - height = 2472; - width = 3298; - raw_height = 2480; - raw_width = 3336; - top_margin = 5; - left_margin = 6; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A630")) { - height = 2472; - width = 3288; - raw_height = 2484; - raw_width = 3344; - top_margin = 6; - left_margin = 12; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A640")) { - height = 2760; - width = 3672; - raw_height = 2772; - raw_width = 3736; - top_margin = 6; - left_margin = 12; - goto canon_a5; - } else if (!strcmp(model,"PowerShot A650")) { - height = 3024; - width = 4032; - raw_height = 3048; - raw_width = 4104; - top_margin = 12; - left_margin = 48; - goto canon_a5; - } else if (!strcmp(model,"PowerShot S3 IS")) { - height = 2128; - width = 2840; - raw_height = 2136; - raw_width = 2888; - top_margin = 8; - left_margin = 44; -canon_a5: - tiff_bps = 10; - load_raw = &CLASS packed_load_raw; - load_flags = 40; - if (raw_width > 1600) zero_is_bad = 1; - } else if (!strcmp(model,"PowerShot SX110 IS")) { - height = 2760; - width = 3684; - raw_height = 2772; - raw_width = 3720; - top_margin = 12; - left_margin = 6; - load_raw = &CLASS packed_load_raw; - load_flags = 40; - zero_is_bad = 1; - } else if (!strcmp(model,"PowerShot SX120 IS")) { - height = 2742; - width = 3664; - raw_height = 2778; - raw_width = 3728; - top_margin = 18; - left_margin = 16; - filters = 0x49494949; - load_raw = &CLASS packed_load_raw; - load_flags = 40; - zero_is_bad = 1; - } else if (!strcmp(model,"PowerShot SX20 IS")) { - height = 3024; - width = 4032; - raw_height = 3048; - raw_width = 4080; - top_margin = 12; - left_margin = 24; - load_raw = &CLASS packed_load_raw; - load_flags = 40; - zero_is_bad = 1; - } else if (!strcmp(model,"PowerShot SX220 HS")) { - height = 3043; - width = 4072; - raw_height = 3060; - raw_width = 4168; -/* - mask[0][0] = top_margin = 16; - mask[0][2] = top_margin + height; - mask[0][3] = left_margin = 92; -*/ - load_raw = &CLASS packed_load_raw; - load_flags = 8; - zero_is_bad = 1; - } else if (!strcmp(model,"PowerShot SX30 IS")) { - height = 3254; - width = 4366; - raw_height = 3276; - raw_width = 4464; - top_margin = 10; - left_margin = 25; - filters = 0x16161616; - load_raw = &CLASS packed_load_raw; - load_flags = 40; - zero_is_bad = 1; - } else if (!strcmp(model,"PowerShot Pro90 IS")) { - width = 1896; - colors = 4; - filters = 0xb4b4b4b4; - } else if (is_canon && raw_width == 2144) { - height = 1550; - width = 2088; - top_margin = 8; - left_margin = 4; - if (!strcmp(model,"PowerShot G1")) { - colors = 4; - filters = 0xb4b4b4b4; - } - } else if (is_canon && raw_width == 2224) { - height = 1448; - width = 2176; - top_margin = 6; - left_margin = 48; - } else if (is_canon && raw_width == 2376) { - height = 1720; - width = 2312; - top_margin = 6; - left_margin = 12; - } else if (is_canon && raw_width == 2672) { - height = 1960; - width = 2616; - top_margin = 6; - left_margin = 12; - } else if (is_canon && raw_width == 3152) { - height = 2056; - width = 3088; - top_margin = 12; - left_margin = 64; - if (unique_id == 0x80000170) - adobe_coeff ("Canon","EOS 300D"); - } else if (is_canon && raw_width == 3160) { - height = 2328; - width = 3112; - top_margin = 12; - left_margin = 44; - } else if (is_canon && raw_width == 3344) { - height = 2472; - width = 3288; - top_margin = 6; - left_margin = 4; - } else if (!strcmp(model,"EOS D2000C")) { - filters = 0x61616161; - black = curve[200]; - } else if (is_canon && raw_width == 3516) { - top_margin = 14; - left_margin = 42; - if (unique_id == 0x80000189) - adobe_coeff ("Canon","EOS 350D"); - goto canon_cr2; - } else if (is_canon && raw_width == 3596) { - top_margin = 12; - left_margin = 74; - goto canon_cr2; - } else if (is_canon && raw_width == 3744) { - height = 2760; - width = 3684; - top_margin = 16; - left_margin = 8; - if (unique_id > 0x2720000) { - top_margin = 12; - left_margin = 52; - } - } else if (is_canon && raw_width == 3944) { - height = 2602; - width = 3908; - top_margin = 18; - left_margin = 30; - } else if (is_canon && raw_width == 3948) { - top_margin = 18; - left_margin = 42; - height -= 2; - if (unique_id == 0x80000236) - adobe_coeff ("Canon","EOS 400D"); - if (unique_id == 0x80000254) - adobe_coeff ("Canon","EOS 1000D"); - goto canon_cr2; - } else if (is_canon && raw_width == 3984) { - top_margin = 20; - left_margin = 76; - height -= 2; - goto canon_cr2; - } else if (is_canon && raw_width == 4104) { - height = 3024; - width = 4032; - top_margin = 12; - left_margin = 48; - } else if (is_canon && raw_width == 4152) { - top_margin = 12; - left_margin = 192; - goto canon_cr2; - } else if (is_canon && raw_width == 4160) { - height = 3048; - width = 4048; - top_margin = 11; - left_margin = 104; - } else if (is_canon && raw_width == 4312) { - top_margin = 18; - left_margin = 22; - height -= 2; - if (unique_id == 0x80000176) - adobe_coeff ("Canon","EOS 450D"); - goto canon_cr2; - } else if (is_canon && raw_width == 4352) { - top_margin = 18; - left_margin = 62; - if (unique_id == 0x80000288) - adobe_coeff ("Canon","EOS 1100D"); - goto canon_cr2; - } else if (is_canon && raw_width == 4476) { - top_margin = 34; - left_margin = 90; - goto canon_cr2; - } else if (is_canon && raw_width == 4480) { - height = 3326; - width = 4432; - top_margin = 10; - left_margin = 12; - filters = 0x49494949; - } else if (is_canon && raw_width == 4496) { - height = 3316; - width = 4404; - top_margin = 50; - left_margin = 80; - } else if (is_canon && raw_width == 4832) { - top_margin = unique_id == 0x80000261 ? 51:26; - left_margin = 62; - if (unique_id == 0x80000252) - adobe_coeff ("Canon","EOS 500D"); - goto canon_cr2; - } else if (is_canon && raw_width == 5108) { - top_margin = 13; - left_margin = 98; - goto canon_cr2; - } else if (is_canon && raw_width == 5120) { - height -= top_margin = 45; - left_margin = 142; - width = 4916; - } else if (is_canon && raw_width == 5344) { - top_margin = 51; - left_margin = 142; - if (unique_id == 0x80000269) { - top_margin = 100; - left_margin = 126; - height -= 2; - adobe_coeff ("Canon","EOS-1D X"); - } - if (unique_id == 0x80000270) - adobe_coeff ("Canon","EOS 550D"); - if (unique_id == 0x80000286) - adobe_coeff ("Canon","EOS 600D"); - goto canon_cr2; - } else if (is_canon && raw_width == 5360) { - top_margin = 51; - left_margin = 158; - goto canon_cr2; - } else if (is_canon && raw_width == 5712) { - height = 3752; - width = 5640; - top_margin = 20; - left_margin = 62; - } else if (is_canon && raw_width == 5792) { - top_margin = 51; - left_margin = 158; -canon_cr2: - height -= top_margin; - width -= left_margin; - } else if (is_canon && raw_width == 5920) { - height = 3870; - width = 5796; - top_margin = 80; - left_margin = 122; - } else if (!strcmp(model,"D1")) { - cam_mul[0] *= 256/527.0; - cam_mul[2] *= 256/317.0; - } else if (!strcmp(model,"D1X")) { - width -= 4; - pixel_aspect = 0.5; - } else if (!strcmp(model,"D40X") || - !strcmp(model,"D60") || - !strcmp(model,"D80") || - !strcmp(model,"D3000")) { - height -= 3; - width -= 4; - } else if (!strcmp(model,"D3") || - !strcmp(model,"D3S") || - !strcmp(model,"D700")) { - width -= 4; - left_margin = 2; - } else if (!strcmp(model,"D3100")) { - width -= 28; - left_margin = 6; - } else if (!strcmp(model,"D5000") || - !strcmp(model,"D90")) { - width -= 42; - } else if (!strcmp(model,"D5100") || - !strcmp(model,"D7000")) { - width -= 44; - } else if (!strcmp(model,"D3200") || - !strcmp(model,"D800")) { - width -= 46; - } else if (!strcmp(model,"D4")) { - width -= 52; - left_margin = 2; - } else if (!strncmp(model,"D40",3) || - !strncmp(model,"D50",3) || - !strncmp(model,"D70",3)) { - width--; - } else if (!strcmp(model,"D100")) { - if (tiff_compress == 34713 && !nikon_is_compressed()) { - load_raw = &CLASS packed_load_raw; - load_flags |= 1; - raw_width = (width += 3) + 3; - } - } else if (!strcmp(model,"D200")) { - left_margin = 1; - width -= 4; - filters = 0x94949494; - } else if (!strncmp(model,"D2H",3)) { - left_margin = 6; - width -= 14; - } else if (!strncmp(model,"D2X",3)) { - if (width == 3264) width -= 32; - else width -= 8; - } else if (!strncmp(model,"D300",4)) { - width -= 32; - } else if (!strncmp(model,"COOLPIX P",9)) { - load_flags = 24; - filters = 0x94949494; - if (model[9] == '7' && iso_speed >= 400) - black = 255; - } else if (!strncmp(model,"1 ",2)) { - height -= 2; - } else if (fsize == 1581060) { - height = 963; - width = 1287; - raw_width = 1632; - maximum = 0x3f4; - colors = 4; - filters = 0x1e1e1e1e; - simple_coeff(3); - pre_mul[0] = 1.2085; - pre_mul[1] = 1.0943; - pre_mul[3] = 1.1103; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.pre_mul_state = LIBRAW_COLORSTATE_CONST; -#endif - goto e900; - } else if (fsize == 2465792) { - height = 1203; - width = 1616; - raw_width = 2048; - colors = 4; - filters = 0x4b4b4b4b; - adobe_coeff ("NIKON","E950"); -e900: - tiff_bps = 10; - load_raw = &CLASS packed_load_raw; - load_flags = 6; - } else if (fsize == 4771840) { - height = 1540; - width = 2064; - colors = 4; - filters = 0xe1e1e1e1; - load_raw = &CLASS packed_load_raw; - load_flags = 6; - if (!timestamp && nikon_e995()) - strcpy (model, "E995"); - if (strcmp(model,"E995")) { - filters = 0xb4b4b4b4; - simple_coeff(3); - pre_mul[0] = 1.196; - pre_mul[1] = 1.246; - pre_mul[2] = 1.018; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.pre_mul_state = LIBRAW_COLORSTATE_CONST; -#endif - } - } else if (!strcmp(model,"E2100")) { - if (!timestamp && !nikon_e2100()) goto cp_e2500; - height = 1206; - width = 1616; - load_flags = 30; - } else if (!strcmp(model,"E2500")) { -cp_e2500: - strcpy (model, "E2500"); - height = 1204; - width = 1616; - colors = 4; - filters = 0x4b4b4b4b; - } else if (fsize == 4775936) { - height = 1542; - width = 2064; - load_raw = &CLASS packed_load_raw; - load_flags = 30; - if (!timestamp) nikon_3700(); - if (model[0] == 'E' && atoi(model+1) < 3700) - filters = 0x49494949; - if (!strcmp(model,"Optio 33WR")) { - flip = 1; - filters = 0x16161616; - } - if (make[0] == 'O') { - i = find_green (12, 32, 1188864, 3576832); - c = find_green (12, 32, 2383920, 2387016); - if (abs(i) < abs(c)) { - SWAP(i,c); - load_flags = 24; - } - if (i < 0) filters = 0x61616161; - } - } else if (fsize == 5869568) { - height = 1710; - width = 2288; - filters = 0x16161616; - if (!timestamp && minolta_z2()) { - strcpy (make, "Minolta"); - strcpy (model,"DiMAGE Z2"); - } - load_raw = &CLASS packed_load_raw; - load_flags = 6 + 24*(make[0] == 'M'); - } else if (!strcmp(model,"E4500")) { - height = 1708; - width = 2288; - colors = 4; - filters = 0xb4b4b4b4; - } else if (fsize == 7438336) { - height = 1924; - width = 2576; - colors = 4; - filters = 0xb4b4b4b4; - } else if (fsize == 8998912) { - height = 2118; - width = 2832; - maximum = 0xf83; - load_raw = &CLASS packed_load_raw; - load_flags = 30; - } else if (!strcmp(make,"FUJIFILM")) { - if (!strcmp(model+7,"S2Pro")) { - strcpy (model,"S2Pro"); - height = 2144; - width = 2880; - flip = 6; - } else if (load_raw != &CLASS packed_load_raw) - maximum = (is_raw == 2 && shot_select) ? 0x2f00 : 0x3e00; - top_margin = (raw_height - height) >> 2 << 1; - left_margin = (raw_width - width ) >> 2 << 1; - if (width == 3328) { - width = 3262; - left_margin = 34; - } - if (!strcmp(model,"X10") || !strcmp(model,"X-S1")) - filters = 0x16161616; - if (fuji_layout) raw_width *= is_raw; - if (load_raw == &CLASS fuji_load_raw) { - fuji_width = width >> !fuji_layout; - width = (height >> fuji_layout) + fuji_width; - raw_height = height; - height = width - 1; - if (~fuji_width & 1) filters = 0x49494949; - } - if (!strcmp(model,"X-Pro1")) { - left_margin = 0; - filters = 2; - is_raw = 0; /* Not supported! */ - } - } else if (!strcmp(model,"RD175")) { - height = 986; - width = 1534; - data_offset = 513; - filters = 0x61616161; - load_raw = &CLASS minolta_rd175_load_raw; - } else if (!strcmp(model,"KD-400Z")) { - height = 1712; - width = 2312; - raw_width = 2336; - goto konica_400z; - } else if (!strcmp(model,"KD-510Z")) { - goto konica_510z; - } else if (!strcasecmp(make,"MINOLTA")) { - load_raw = &CLASS unpacked_load_raw; - maximum = 0xfff; - if (!strncmp(model,"DiMAGE A",8)) { - if (!strcmp(model,"DiMAGE A200")) - filters = 0x49494949; - tiff_bps = 12; - load_raw = &CLASS packed_load_raw; - } else if (!strncmp(model,"ALPHA",5) || - !strncmp(model,"DYNAX",5) || - !strncmp(model,"MAXXUM",6)) { - sprintf (model+20, "DYNAX %-10s", model+6+(model[0]=='M')); - adobe_coeff (make, model+20); - load_raw = &CLASS packed_load_raw; - } else if (!strncmp(model,"DiMAGE G",8)) { - if (model[8] == '4') { - height = 1716; - width = 2304; - } else if (model[8] == '5') { -konica_510z: - height = 1956; - width = 2607; - raw_width = 2624; - } else if (model[8] == '6') { - height = 2136; - width = 2848; - } - data_offset += 14; - filters = 0x61616161; -konica_400z: - load_raw = &CLASS unpacked_load_raw; - maximum = 0x3df; - order = 0x4d4d; - } - } else if (!strcmp(model,"*ist D")) { - load_raw = &CLASS unpacked_load_raw; - data_error = -1; - } else if (!strcmp(model,"*ist DS")) { - height -= 2; - } else if (!strcmp(model,"Optio S")) { - if (fsize == 3178560) { - height = 1540; - width = 2064; - load_raw = &CLASS eight_bit_load_raw; - cam_mul[0] *= 4; - cam_mul[2] *= 4; - } else { - height = 1544; - width = 2068; - raw_width = 3136; - load_raw = &CLASS packed_load_raw; - maximum = 0xf7c; - } - } else if (fsize == 6114240) { - height = 1737; - width = 2324; - raw_width = 3520; - load_raw = &CLASS packed_load_raw; - maximum = 0xf7a; - } else if (!strcmp(model,"Optio 750Z")) { - height = 2302; - width = 3072; - load_raw = &CLASS packed_load_raw; - load_flags = 30; - } else if (!strcmp(model,"DC-833m")) { - height = 2448; - width = 3264; - order = 0x4949; - filters = 0x61616161; - load_raw = &CLASS unpacked_load_raw; - maximum = 0xfc00; - } else if (!strncmp(model,"S85",3)) { - height = 2448; - width = 3264; - raw_width = fsize/height/2; - order = 0x4d4d; - load_raw = &CLASS unpacked_load_raw; - } else if (!strncmp(model,"NX1",3)) { - height -= top_margin = 8; - width -= 2 * (left_margin = 8); - load_flags = 32; - } else if (!strcmp(model,"NX200")) { - order = 0x4949; - height = 3694; - top_margin = 2; - width = 5574 - (left_margin = 32 + tiff_bps); - if (tiff_bps == 12) load_flags = 80; - } else if (!strcmp(model,"EX1")) { - order = 0x4949; - height -= 20; - top_margin = 2; - if ((width -= 6) > 3682) { - height -= 10; - width -= 46; - top_margin = 8; - } - } else if (!strcmp(model,"WB2000")) { - order = 0x4949; - height -= 3; - top_margin = 2; - if ((width -= 10) > 3718) { - height -= 28; - width -= 56; - top_margin = 8; - } - } else if (fsize == 20487168) { - height = 2808; - width = 3648; - goto wb550; - } else if (fsize == 24000000) { - height = 3000; - width = 4000; -wb550: - strcpy (model, "WB550"); - order = 0x4d4d; - load_raw = &CLASS unpacked_load_raw; - load_flags = 6; - maximum = 0x3df; - } else if (!strcmp(model,"STV680 VGA")) { - height = 484; - width = 644; - load_raw = &CLASS eight_bit_load_raw; - flip = 2; - filters = 0x16161616; - black = 16; - } else if (!strcmp(model,"N95")) { - height = raw_height - (top_margin = 2); - } else if (!strcmp(model,"531C")) { - height = 1200; - width = 1600; - load_raw = &CLASS unpacked_load_raw; - filters = 0x49494949; - } else if (!strcmp(model,"640x480")) { - height = 480; - width = 640; - load_raw = &CLASS eight_bit_load_raw; - gamma_curve (0.45, 4.5, 1, 255); - } else if (!strcmp(model,"F-080C")) { - height = 768; - width = 1024; - load_raw = &CLASS eight_bit_load_raw; - } else if (!strcmp(model,"F-145C")) { - height = 1040; - width = 1392; - load_raw = &CLASS eight_bit_load_raw; - } else if (!strcmp(model,"F-201C")) { - height = 1200; - width = 1600; - load_raw = &CLASS eight_bit_load_raw; - } else if (!strcmp(model,"F-510C")) { - height = 1958; - width = 2588; - load_raw = fsize < 7500000 ? - &CLASS eight_bit_load_raw : &CLASS unpacked_load_raw; - data_offset = fsize - width*height*(fsize >> 22); - maximum = 0xfff0; - } else if (!strcmp(model,"F-810C")) { - height = 2469; - width = 3272; - load_raw = &CLASS unpacked_load_raw; - maximum = 0xfff0; - } else if (!strcmp(model,"XCD-SX910CR")) { - height = 1024; - width = 1375; - raw_width = 1376; - filters = 0x49494949; - maximum = 0x3ff; - load_raw = fsize < 2000000 ? - &CLASS eight_bit_load_raw : &CLASS unpacked_load_raw; - } else if (!strcmp(model,"2010")) { - height = 1207; - width = 1608; - order = 0x4949; - filters = 0x16161616; - data_offset = 3212; - maximum = 0x3ff; - load_raw = &CLASS unpacked_load_raw; - } else if (!strcmp(model,"A782")) { - height = 3000; - width = 2208; - filters = 0x61616161; - load_raw = fsize < 10000000 ? - &CLASS eight_bit_load_raw : &CLASS unpacked_load_raw; - maximum = 0xffc0; - } else if (!strcmp(model,"3320AF")) { - height = 1536; - raw_width = width = 2048; - filters = 0x61616161; - load_raw = &CLASS unpacked_load_raw; - maximum = 0x3ff; - fseek (ifp, 0x300000, SEEK_SET); - if ((order = guess_byte_order(0x10000)) == 0x4d4d) { - height -= (top_margin = 16); - width -= (left_margin = 28); - maximum = 0xf5c0; - strcpy (make, "ISG"); - model[0] = 0; - } - } else if (!strcmp(make,"Hasselblad")) { - if (load_raw == &CLASS lossless_jpeg_load_raw) - load_raw = &CLASS hasselblad_load_raw; - if (raw_width == 7262) { - height = 5444; - width = 7248; - top_margin = 4; - left_margin = 7; - filters = 0x61616161; - } else if (raw_width == 7410) { - height = 5502; - width = 7328; - top_margin = 4; - left_margin = 41; - filters = 0x61616161; - } else if (raw_width == 9044) { - height = 6716; - width = 8964; - top_margin = 8; - left_margin = 40; - black += load_flags = 256; - maximum = 0x8101; - } else if (raw_width == 4090) { - strcpy (model, "V96C"); - height -= (top_margin = 6); - width -= (left_margin = 3) + 7; - filters = 0x61616161; - } - } else if (!strcmp(make,"Sinar")) { - if (!memcmp(head,"8BPS",4)) { - fseek (ifp, 14, SEEK_SET); - height = get4(); - width = get4(); - filters = 0x61616161; - data_offset = 68; - } - if (!load_raw) load_raw = &CLASS unpacked_load_raw; - maximum = 0x3fff; - } else if (!strcmp(make,"Leaf")) { - maximum = 0x3fff; - fseek (ifp, data_offset, SEEK_SET); - if (ljpeg_start (&jh, 1) && jh.bits == 15) - maximum = 0x1fff; - if (tiff_samples > 1) filters = 0; - if (tiff_samples > 1 || tile_length < raw_height) { - load_raw = &CLASS leaf_hdr_load_raw; - raw_width = tile_width; - } - if ((width | height) == 2048) { - if (tiff_samples == 1) { - filters = 1; - strcpy (cdesc, "RBTG"); - strcpy (model, "CatchLight"); - top_margin = 8; left_margin = 18; height = 2032; width = 2016; - } else { - strcpy (model, "DCB2"); - top_margin = 10; left_margin = 16; height = 2028; width = 2022; - } - } else if (width+height == 3144+2060) { - if (!model[0]) strcpy (model, "Cantare"); - if (width > height) { - top_margin = 6; left_margin = 32; height = 2048; width = 3072; - filters = 0x61616161; - } else { - left_margin = 6; top_margin = 32; width = 2048; height = 3072; - filters = 0x16161616; - } - if (!cam_mul[0] || model[0] == 'V') filters = 0; - else is_raw = tiff_samples; - } else if (width == 2116) { - strcpy (model, "Valeo 6"); - height -= 2 * (top_margin = 30); - width -= 2 * (left_margin = 55); - filters = 0x49494949; - } else if (width == 3171) { - strcpy (model, "Valeo 6"); - height -= 2 * (top_margin = 24); - width -= 2 * (left_margin = 24); - filters = 0x16161616; - } - } else if (!strcmp(make,"LEICA") || !strcmp(make,"Panasonic")) { - if(raw_width < 1) { is_raw = 0; goto notraw; } - if ((flen - data_offset) / (raw_width*8/7) == raw_height) - load_raw = &CLASS panasonic_load_raw; - if (!load_raw) { - load_raw = &CLASS unpacked_load_raw; - load_flags = 4; - } - zero_is_bad = 1; - if ((height += 12) > raw_height) height = raw_height; - for (i=0; i < sizeof pana / sizeof *pana; i++) - if (raw_width == pana[i][0] && raw_height == pana[i][1]) { - left_margin = pana[i][2]; - top_margin = pana[i][3]; - width += pana[i][4]; - height += pana[i][5]; - } - filters = 0x01010101 * (uchar) "\x94\x61\x49\x16" - [((filters-1) ^ (left_margin & 1) ^ (top_margin << 1)) & 3]; - } else if (!strcmp(model,"C770UZ")) { - height = 1718; - width = 2304; - filters = 0x16161616; - load_raw = &CLASS packed_load_raw; - load_flags = 30; - } else if (!strcmp(make,"OLYMPUS")) { - height += height & 1; - filters = exif_cfa; - if (width == 4100) width -= 4; - if (width == 4080) width -= 24; - if (load_raw == &CLASS unpacked_load_raw) - load_flags = 4; - tiff_bps = 12; - if (!strcmp(model,"E-300") || - !strcmp(model,"E-500")) { - width -= 20; - if (load_raw == &CLASS unpacked_load_raw) { - maximum = 0xfc3; - memset (cblack, 0, sizeof cblack); - } - } else if (!strcmp(model,"E-330")) { - width -= 30; - if (load_raw == &CLASS unpacked_load_raw) - maximum = 0xf79; - } else if (!strcmp(model,"SP550UZ")) { - thumb_length = flen - (thumb_offset = 0xa39800); - thumb_height = 480; - thumb_width = 640; - } - } - else - identify2(fsize,flen,head); /* Avoid MS VS 2008 bug */ - - - if (!model[0]) - sprintf (model, "%dx%d", width, height); - if (filters == UINT_MAX) filters = 0x94949494; - if (raw_color) adobe_coeff (make, model); - if (load_raw == &CLASS kodak_radc_load_raw) - if (raw_color) adobe_coeff ("Apple","Quicktake"); - if (thumb_offset && !thumb_height) { - fseek (ifp, thumb_offset, SEEK_SET); - if (ljpeg_start (&jh, 1)) { - thumb_width = jh.wide; - thumb_height = jh.high; - } - } -dng_skip: - if (fuji_width) { -/* - fuji_width = width >> !fuji_layout; - if (~fuji_width & 1) filters = 0x49494949; - width = (height >> fuji_layout) + fuji_width; - height = width - 1; - pixel_aspect = 1; -*/ - } else { - if (raw_height < height) raw_height = height; - if (raw_width < width ) raw_width = width; - } - if (!tiff_bps) tiff_bps = 12; - if (!maximum) maximum = (1 << tiff_bps) - 1; - if (!load_raw || height < 22) is_raw = 0; -#ifdef NO_JASPER - if (load_raw == &CLASS redcine_load_raw) { -#ifdef DCRAW_VERBOSE - fprintf (stderr,_("%s: You must link dcraw with %s!!\n"), - ifname, "libjasper"); -#endif - is_raw = 0; -#ifdef LIBRAW_LIBRARY_BUILD - imgdata.process_warnings |= LIBRAW_WARN_NO_JASPER; -#endif - } -#endif -#ifdef NO_JPEG - if (load_raw == &CLASS kodak_jpeg_load_raw) { -#ifdef DCRAW_VERBOSE - fprintf (stderr,_("%s: You must link dcraw with %s!!\n"), - ifname, "libjpeg"); -#endif - is_raw = 0; -#ifdef LIBRAW_LIBRARY_BUILD - imgdata.process_warnings |= LIBRAW_WARN_NO_JPEGLIB; -#endif - } -#endif - if (!cdesc[0]) - strcpy (cdesc, colors == 3 ? "RGBG":"GMCY"); - if (!raw_height) raw_height = height; - if (!raw_width ) raw_width = width; - if (filters && colors == 3) - filters |= ((filters >> 2 & 0x22222222) | - (filters << 2 & 0x88888888)) & filters << 1; -notraw: - if (flip == -1) flip = tiff_flip; - if (flip == -1) flip = 0; - -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_IDENTIFY,1,2); -#endif -} - -void CLASS identify2(unsigned fsize, unsigned flen, char *head) -{ - if (!strcmp(model,"N Digital")) { - height = 2047; - width = 3072; - filters = 0x61616161; - data_offset = 0x1a00; - load_raw = &CLASS packed_load_raw; - } else if (!strcmp(model,"DSC-F828")) { - width = 3288; - left_margin = 5; - data_offset = 862144; - load_raw = &CLASS sony_load_raw; - filters = 0x9c9c9c9c; - colors = 4; - strcpy (cdesc, "RGBE"); - } else if (!strcmp(model,"DSC-V3")) { - width = 3109; - left_margin = 59; - data_offset = 787392; - load_raw = &CLASS sony_load_raw; - } else if (!strcmp(make,"SONY") && raw_width == 3984) { - adobe_coeff ("SONY","DSC-R1"); - width = 3925; - order = 0x4d4d; - } else if (!strcmp(make,"SONY") && raw_width == 6048) { - width -= 24; - } else if (!strcmp(model,"DSLR-A100")) { - if (width == 3880) { - height--; - width = ++raw_width; - } else { - order = 0x4d4d; - load_flags = 2; - } - filters = 0x61616161; - } else if (!strcmp(model,"DSLR-A350")) { - height -= 4; - } - else if (!strcmp(model,"PIXL")) { - height -= top_margin = 4; - width -= left_margin = 32; - gamma_curve (0, 7, 1, 255); - } else if (!strcmp(model,"C603v")) { - height = 480; - width = 640; - if (fsize < 614400 || find_green (16, 16, 3840, 5120) < 25) goto c603v; - strcpy (model,"KAI-0340"); - height -= 3; - data_offset = 3840; - order = 0x4949; - load_raw = &CLASS unpacked_load_raw; - } else if (!strcmp(model,"C603y")) { - height = 2134; - width = 2848; -c603v: - filters = 0; - load_raw = &CLASS kodak_yrgb_load_raw; - gamma_curve (0, 3.875, 1, 255); - } else if (!strcmp(model,"C603")) { - raw_height = height = 2152; - raw_width = width = 2864; - goto c603; - } else if (!strcmp(model,"C330")) { - height = 1744; - width = 2336; - raw_height = 1779; - raw_width = 2338; - top_margin = 33; - left_margin = 1; -c603: - order = 0x4949; - if ((data_offset = fsize - raw_height*raw_width)) { - fseek (ifp, 168, SEEK_SET); - read_shorts (curve, 256); -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.curve_state = LIBRAW_COLORSTATE_LOADED; -#endif - } else gamma_curve (0, 3.875, 1, 255); - load_raw = &CLASS eight_bit_load_raw; - } - else if (!strncasecmp(model,"EasyShare",9)) { - data_offset = data_offset < 0x15000 ? 0x15000 : 0x17000; - load_raw = &CLASS packed_load_raw; - } else if (!strcasecmp(make,"KODAK")) { - if (filters == UINT_MAX) filters = 0x61616161; - if (!strncmp(model,"NC2000",6)) { - width -= 4; - left_margin = 2; - } else if (!strcmp(model,"EOSDCS3B")) { - width -= 4; - left_margin = 2; - } else if (!strcmp(model,"EOSDCS1")) { - width -= 4; - left_margin = 2; - } else if (!strcmp(model,"DCS420")) { - width -= 4; - left_margin = 2; - } else if (!strncmp(model,"DCS460 ",7)) { - model[6] = 0; - width -= 4; - left_margin = 2; - } else if (!strcmp(model,"DCS460A")) { - width -= 4; - left_margin = 2; - colors = 1; - filters = 0; - } else if (!strcmp(model,"DCS660M")) { - black = 214; - colors = 1; - filters = 0; - } else if (!strcmp(model,"DCS760M")) { - colors = 1; - filters = 0; - } - if (!strcmp(model+4,"20X")) - strcpy (cdesc, "MYCY"); - if (strstr(model,"DC25")) { - strcpy (model, "DC25"); - data_offset = 15424; - } - if (!strncmp(model,"DC2",3)) { - raw_height = height = 242; - if (flen < 100000) { - raw_width = 256; width = 249; - pixel_aspect = (4.0*height) / (3.0*width); - } else { - raw_width = 512; width = 501; - pixel_aspect = (493.0*height) / (373.0*width); - } - data_offset += raw_width + 1; - colors = 4; - filters = 0x8d8d8d8d; - simple_coeff(1); - pre_mul[1] = 1.179; - pre_mul[2] = 1.209; - pre_mul[3] = 1.036; -#ifdef LIBRAW_LIBRARY_BUILD - color_flags.pre_mul_state = LIBRAW_COLORSTATE_CONST; -#endif - load_raw = &CLASS eight_bit_load_raw; - } else if (!strcmp(model,"40")) { - strcpy (model, "DC40"); - height = 512; - width = 768; - data_offset = 1152; - load_raw = &CLASS kodak_radc_load_raw; - } else if (strstr(model,"DC50")) { - strcpy (model, "DC50"); - height = 512; - width = 768; - data_offset = 19712; - load_raw = &CLASS kodak_radc_load_raw; - } else if (strstr(model,"DC120")) { - strcpy (model, "DC120"); - height = 976; - width = 848; - pixel_aspect = height/0.75/width; - load_raw = tiff_compress == 7 ? - &CLASS kodak_jpeg_load_raw : &CLASS kodak_dc120_load_raw; - } else if (!strcmp(model,"DCS200")) { - thumb_height = 128; - thumb_width = 192; - thumb_offset = 6144; - thumb_misc = 360; - write_thumb = &CLASS layer_thumb; - height = 1024; - width = 1536; - data_offset = 79872; - load_raw = &CLASS eight_bit_load_raw; - black = 17; - } -} else if (!strcmp(model,"Fotoman Pixtura")) { - height = 512; - width = 768; - data_offset = 3632; - load_raw = &CLASS kodak_radc_load_raw; - filters = 0x61616161; - simple_coeff(2); - } else if (!strncmp(model,"QuickTake",9)) { - if (head[5]) strcpy (model+10, "200"); - fseek (ifp, 544, SEEK_SET); - height = get2(); - width = get2(); - data_offset = (get4(),get2()) == 30 ? 738:736; - if (height > width) { - SWAP(height,width); - fseek (ifp, data_offset-6, SEEK_SET); - flip = ~get2() & 3 ? 5:6; - } - filters = 0x61616161; - } else if (!strcmp(make,"Rollei") && !load_raw) { - switch (raw_width) { - case 1316: - height = 1030; - width = 1300; - top_margin = 1; - left_margin = 6; - break; - case 2568: - height = 1960; - width = 2560; - top_margin = 2; - left_margin = 8; - } - filters = 0x16161616; - load_raw = &CLASS rollei_load_raw; - } else if (!strcmp(model,"PC-CAM 600")) { - height = 768; - data_offset = width = 1024; - filters = 0x49494949; - load_raw = &CLASS eight_bit_load_raw; - } -else if (!strcmp(model,"QV-2000UX")) { - height = 1208; - width = 1632; - data_offset = width * 2; - load_raw = &CLASS eight_bit_load_raw; - } else if (fsize == 3217760) { - height = 1546; - width = 2070; - raw_width = 2080; - load_raw = &CLASS eight_bit_load_raw; - } else if (!strcmp(model,"QV-4000")) { - height = 1700; - width = 2260; - load_raw = &CLASS unpacked_load_raw; - maximum = 0xffff; - } else if (!strcmp(model,"QV-5700")) { - height = 1924; - width = 2576; - raw_width = 3232; - tiff_bps = 10; - } else if (!strcmp(model,"QV-R41")) { - height = 1720; - width = 2312; - raw_width = 3520; - left_margin = 2; - } else if (!strcmp(model,"QV-R51")) { - height = 1926; - width = 2580; - raw_width = 3904; - } else if (!strcmp(model,"EX-S20")) { - height = 1208; - width = 1620; - raw_width = 2432; - flip = 3; - } else if (!strcmp(model,"EX-S100")) { - height = 1544; - width = 2058; - raw_width = 3136; - } else if (!strcmp(model,"EX-Z50")) { - height = 1931; - width = 2570; - raw_width = 3904; - } else if (!strcmp(model,"EX-Z500")) { - height = 1937; - width = 2577; - raw_width = 3904; - filters = 0x16161616; - } else if (!strcmp(model,"EX-Z55")) { - height = 1960; - width = 2570; - raw_width = 3904; - } else if (!strcmp(model,"EX-Z60")) { - height = 2145; - width = 2833; - raw_width = 3584; - filters = 0x16161616; - tiff_bps = 10; - } else if (!strcmp(model,"EX-Z75")) { - height = 2321; - width = 3089; - raw_width = 4672; - } else if (!strcmp(model,"EX-Z750")) { - height = 2319; - width = 3087; - raw_width = 4672; - maximum = 0xfff; - } else if (!strcmp(model,"EX-Z850")) { - height = 2468; - width = 3279; - raw_width = 4928; - maximum = 0xfff; - } else if (!strcmp(model,"EX-Z8")) { - height = 2467; - width = 3281; - raw_height = 2502; - raw_width = 4992; - maximum = 0xfff; - } else if (fsize == 15499264) { /* EX-Z1050 or EX-Z1080 */ - height = 2752; - width = 3672; - raw_width = 5632; - } else if (!strcmp(model,"EX-P505")) { - height = 1928; - width = 2568; - raw_width = 3852; - maximum = 0xfff; - } else if (fsize == 9313536) { /* EX-P600 or QV-R61 */ - height = 2142; - width = 2844; - raw_width = 4288; - } else if (!strcmp(model,"EX-P700")) { - height = 2318; - width = 3082; - raw_width = 4672; - } - else if (!strcmp(model,"GRAS-50S5C")) { - height = 2048; - width = 2440; - load_raw = &CLASS unpacked_load_raw; - data_offset = 0; - filters = 0x49494949; - order = 0x4949; - maximum = 0xfffC; - } else if (!strcmp(model,"BB-500CL")) { - height = 2058; - width = 2448; - load_raw = &CLASS unpacked_load_raw; - data_offset = 0; - filters = 0x94949494; - order = 0x4949; - maximum = 0x3fff; - } else if (!strcmp(model,"BB-500GE")) { - height = 2058; - width = 2456; - load_raw = &CLASS unpacked_load_raw; - data_offset = 0; - filters = 0x94949494; - order = 0x4949; - maximum = 0x3fff; - } else if (!strcmp(model,"SVS625CL")) { - height = 2050; - width = 2448; - load_raw = &CLASS unpacked_load_raw; - data_offset = 0; - filters = 0x94949494; - order = 0x4949; - maximum = 0x0fff; - } -} - -void CLASS convert_to_rgb() -{ - int row, col, c, i, j, k; - ushort *img; - float out[3], out_cam[3][4]; - double num, inverse[3][3]; - static const double xyzd50_srgb[3][3] = - { { 0.436083, 0.385083, 0.143055 }, - { 0.222507, 0.716888, 0.060608 }, - { 0.013930, 0.097097, 0.714022 } }; - static const double rgb_rgb[3][3] = - { { 1,0,0 }, { 0,1,0 }, { 0,0,1 } }; - static const double adobe_rgb[3][3] = - { { 0.715146, 0.284856, 0.000000 }, - { 0.000000, 1.000000, 0.000000 }, - { 0.000000, 0.041166, 0.958839 } }; - static const double wide_rgb[3][3] = - { { 0.593087, 0.404710, 0.002206 }, - { 0.095413, 0.843149, 0.061439 }, - { 0.011621, 0.069091, 0.919288 } }; - static const double prophoto_rgb[3][3] = - { { 0.529317, 0.330092, 0.140588 }, - { 0.098368, 0.873465, 0.028169 }, - { 0.016879, 0.117663, 0.865457 } }; - static const double (*out_rgb[])[3] = - { rgb_rgb, adobe_rgb, wide_rgb, prophoto_rgb, xyz_rgb }; - static const char *name[] = - { "sRGB", "Adobe RGB (1998)", "WideGamut D65", "ProPhoto D65", "XYZ" }; - static const unsigned phead[] = - { 1024, 0, 0x2100000, 0x6d6e7472, 0x52474220, 0x58595a20, 0, 0, 0, - 0x61637370, 0, 0, 0x6e6f6e65, 0, 0, 0, 0, 0xf6d6, 0x10000, 0xd32d }; - unsigned pbody[] = - { 10, 0x63707274, 0, 36, /* cprt */ - 0x64657363, 0, 40, /* desc */ - 0x77747074, 0, 20, /* wtpt */ - 0x626b7074, 0, 20, /* bkpt */ - 0x72545243, 0, 14, /* rTRC */ - 0x67545243, 0, 14, /* gTRC */ - 0x62545243, 0, 14, /* bTRC */ - 0x7258595a, 0, 20, /* rXYZ */ - 0x6758595a, 0, 20, /* gXYZ */ - 0x6258595a, 0, 20 }; /* bXYZ */ - static const unsigned pwhite[] = { 0xf351, 0x10000, 0x116cc }; - unsigned pcurve[] = { 0x63757276, 0, 1, 0x1000000 }; - -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_CONVERT_RGB,0,2); -#endif - gamma_curve (gamm[0], gamm[1], 0, 0); - memcpy (out_cam, rgb_cam, sizeof out_cam); - raw_color |= colors == 1 || document_mode || - output_color < 1 || output_color > 5; - if (!raw_color) { - oprof = (unsigned *) calloc (phead[0], 1); - merror (oprof, "convert_to_rgb()"); - memcpy (oprof, phead, sizeof phead); - if (output_color == 5) oprof[4] = oprof[5]; - oprof[0] = 132 + 12*pbody[0]; - for (i=0; i < pbody[0]; i++) { - oprof[oprof[0]/4] = i ? (i > 1 ? 0x58595a20 : 0x64657363) : 0x74657874; - pbody[i*3+2] = oprof[0]; - oprof[0] += (pbody[i*3+3] + 3) & -4; - } - memcpy (oprof+32, pbody, sizeof pbody); - oprof[pbody[5]/4+2] = strlen(name[output_color-1]) + 1; - memcpy ((char *)oprof+pbody[8]+8, pwhite, sizeof pwhite); - pcurve[3] = (short)(256/gamm[5]+0.5) << 16; - for (i=4; i < 7; i++) - memcpy ((char *)oprof+pbody[i*3+2], pcurve, sizeof pcurve); - pseudoinverse ((double (*)[3]) out_rgb[output_color-1], inverse, 3); - for (i=0; i < 3; i++) - for (j=0; j < 3; j++) { - for (num = k=0; k < 3; k++) - num += xyzd50_srgb[i][k] * inverse[j][k]; - oprof[pbody[j*3+23]/4+i+2] = num * 0x10000 + 0.5; - } - for (i=0; i < phead[0]/4; i++) - oprof[i] = htonl(oprof[i]); - strcpy ((char *)oprof+pbody[2]+8, "auto-generated by dcraw"); - strcpy ((char *)oprof+pbody[5]+12, name[output_color-1]); - for (i=0; i < 3; i++) - for (j=0; j < colors; j++) - for (out_cam[i][j] = k=0; k < 3; k++) - out_cam[i][j] += out_rgb[output_color-1][i][k] * rgb_cam[k][j]; - } -#ifdef DCRAW_VERBOSE - if (verbose) - fprintf (stderr, raw_color ? _("Building histograms...\n") : - _("Converting to %s colorspace...\n"), name[output_color-1]); - -#endif -#ifdef LIBRAW_LIBRARY_BUILD - memset(histogram,0,sizeof(int)*LIBRAW_HISTOGRAM_SIZE*4); -#else - memset (histogram, 0, sizeof histogram); -#endif - for (img=image[0], row=0; row < height; row++) - for (col=0; col < width; col++, img+=4) { - if (!raw_color) { - out[0] = out[1] = out[2] = 0; - FORCC { - out[0] += out_cam[0][c] * img[c]; - out[1] += out_cam[1][c] * img[c]; - out[2] += out_cam[2][c] * img[c]; - } - FORC3 img[c] = CLIP((int) out[c]); - } - else if (document_mode) - img[0] = img[FC(row,col)]; - FORCC histogram[c][img[c] >> 3]++; - } - if (colors == 4 && output_color) colors = 3; - if (document_mode && filters) colors = 1; -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_CONVERT_RGB,1,2); -#endif -} - -void CLASS fuji_rotate() -{ - int i, row, col; - double step; - float r, c, fr, fc; - unsigned ur, uc; - ushort wide, high, (*img)[4], (*pix)[4]; - - if (!fuji_width) return; -#ifdef DCRAW_VERBOSE - if (verbose) - fprintf (stderr,_("Rotating image 45 degrees...\n")); -#endif - fuji_width = (fuji_width - 1 + shrink) >> shrink; - step = sqrt(0.5); - wide = fuji_width / step; - high = (height - fuji_width) / step; - img = (ushort (*)[4]) calloc (wide*high, sizeof *img); - merror (img, "fuji_rotate()"); - -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_FUJI_ROTATE,0,2); -#endif - - for (row=0; row < high; row++) - for (col=0; col < wide; col++) { - ur = r = fuji_width + (row-col)*step; - uc = c = (row+col)*step; - if (ur > height-2 || uc > width-2) continue; - fr = r - ur; - fc = c - uc; - pix = image + ur*width + uc; - for (i=0; i < colors; i++) - img[row*wide+col][i] = - (pix[ 0][i]*(1-fc) + pix[ 1][i]*fc) * (1-fr) + - (pix[width][i]*(1-fc) + pix[width+1][i]*fc) * fr; - } - free (image); - width = wide; - height = high; - image = img; - fuji_width = 0; -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_FUJI_ROTATE,1,2); -#endif -} - -void CLASS stretch() -{ - ushort newdim, (*img)[4], *pix0, *pix1; - int row, col, c; - double rc, frac; - - if (pixel_aspect == 1) return; -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_STRETCH,0,2); -#endif -#ifdef DCRAW_VERBOSE - if (verbose) fprintf (stderr,_("Stretching the image...\n")); -#endif - if (pixel_aspect < 1) { - newdim = height / pixel_aspect + 0.5; - img = (ushort (*)[4]) calloc (width*newdim, sizeof *img); - merror (img, "stretch()"); - for (rc=row=0; row < newdim; row++, rc+=pixel_aspect) { - frac = rc - (c = rc); - pix0 = pix1 = image[c*width]; - if (c+1 < height) pix1 += width*4; - for (col=0; col < width; col++, pix0+=4, pix1+=4) - FORCC img[row*width+col][c] = pix0[c]*(1-frac) + pix1[c]*frac + 0.5; - } - height = newdim; - } else { - newdim = width * pixel_aspect + 0.5; - img = (ushort (*)[4]) calloc (height*newdim, sizeof *img); - merror (img, "stretch()"); - for (rc=col=0; col < newdim; col++, rc+=1/pixel_aspect) { - frac = rc - (c = rc); - pix0 = pix1 = image[c]; - if (c+1 < width) pix1 += 4; - for (row=0; row < height; row++, pix0+=width*4, pix1+=width*4) - FORCC img[row*newdim+col][c] = pix0[c]*(1-frac) + pix1[c]*frac + 0.5; - } - width = newdim; - } - free (image); - image = img; -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_STRETCH,1,2); -#endif -} - -int CLASS flip_index (int row, int col) -{ - if (flip & 4) SWAP(row,col); - if (flip & 2) row = iheight - 1 - row; - if (flip & 1) col = iwidth - 1 - col; - return row * iwidth + col; -} - -void CLASS tiff_set (ushort *ntag, - ushort tag, ushort type, int count, int val) -{ - struct tiff_tag *tt; - int c; - - tt = (struct tiff_tag *)(ntag+1) + (*ntag)++; - tt->tag = tag; - tt->type = type; - tt->count = count; - if (type < 3 && count <= 4) - FORC(4) tt->val.c[c] = val >> (c << 3); - else if (type == 3 && count <= 2) - FORC(2) tt->val.s[c] = val >> (c << 4); - else tt->val.i = val; -} - -#define TOFF(ptr) ((char *)(&(ptr)) - (char *)th) - -void CLASS tiff_head (struct tiff_hdr *th, int full) -{ - int c, psize=0; - struct tm *t; - - memset (th, 0, sizeof *th); - th->t_order = htonl(0x4d4d4949) >> 16; - th->magic = 42; - th->ifd = 10; - if (full) { - tiff_set (&th->ntag, 254, 4, 1, 0); - tiff_set (&th->ntag, 256, 4, 1, width); - tiff_set (&th->ntag, 257, 4, 1, height); - tiff_set (&th->ntag, 258, 3, colors, output_bps); - if (colors > 2) - th->tag[th->ntag-1].val.i = TOFF(th->bps); - FORC4 th->bps[c] = output_bps; - tiff_set (&th->ntag, 259, 3, 1, 1); - tiff_set (&th->ntag, 262, 3, 1, 1 + (colors > 1)); - } - tiff_set (&th->ntag, 270, 2, 512, TOFF(th->t_desc)); - tiff_set (&th->ntag, 271, 2, 64, TOFF(th->t_make)); - tiff_set (&th->ntag, 272, 2, 64, TOFF(th->t_model)); - if (full) { - if (oprof) psize = ntohl(oprof[0]); - tiff_set (&th->ntag, 273, 4, 1, sizeof *th + psize); - tiff_set (&th->ntag, 277, 3, 1, colors); - tiff_set (&th->ntag, 278, 4, 1, height); - tiff_set (&th->ntag, 279, 4, 1, height*width*colors*output_bps/8); - } else - tiff_set (&th->ntag, 274, 3, 1, "12435867"[flip]-'0'); - tiff_set (&th->ntag, 282, 5, 1, TOFF(th->rat[0])); - tiff_set (&th->ntag, 283, 5, 1, TOFF(th->rat[2])); - tiff_set (&th->ntag, 284, 3, 1, 1); - tiff_set (&th->ntag, 296, 3, 1, 2); - tiff_set (&th->ntag, 305, 2, 32, TOFF(th->soft)); - tiff_set (&th->ntag, 306, 2, 20, TOFF(th->date)); - tiff_set (&th->ntag, 315, 2, 64, TOFF(th->t_artist)); - tiff_set (&th->ntag, 34665, 4, 1, TOFF(th->nexif)); - if (psize) tiff_set (&th->ntag, 34675, 7, psize, sizeof *th); - tiff_set (&th->nexif, 33434, 5, 1, TOFF(th->rat[4])); - tiff_set (&th->nexif, 33437, 5, 1, TOFF(th->rat[6])); - tiff_set (&th->nexif, 34855, 3, 1, iso_speed); - tiff_set (&th->nexif, 37386, 5, 1, TOFF(th->rat[8])); - if (gpsdata[1]) { - tiff_set (&th->ntag, 34853, 4, 1, TOFF(th->ngps)); - tiff_set (&th->ngps, 0, 1, 4, 0x202); - tiff_set (&th->ngps, 1, 2, 2, gpsdata[29]); - tiff_set (&th->ngps, 2, 5, 3, TOFF(th->gps[0])); - tiff_set (&th->ngps, 3, 2, 2, gpsdata[30]); - tiff_set (&th->ngps, 4, 5, 3, TOFF(th->gps[6])); - tiff_set (&th->ngps, 5, 1, 1, gpsdata[31]); - tiff_set (&th->ngps, 6, 5, 1, TOFF(th->gps[18])); - tiff_set (&th->ngps, 7, 5, 3, TOFF(th->gps[12])); - tiff_set (&th->ngps, 18, 2, 12, TOFF(th->gps[20])); - tiff_set (&th->ngps, 29, 2, 12, TOFF(th->gps[23])); - memcpy (th->gps, gpsdata, sizeof th->gps); - } - th->rat[0] = th->rat[2] = 300; - th->rat[1] = th->rat[3] = 1; - FORC(6) th->rat[4+c] = 1000000; - th->rat[4] *= shutter; - th->rat[6] *= aperture; - th->rat[8] *= focal_len; - strncpy (th->t_desc, desc, 512); - strncpy (th->t_make, make, 64); - strncpy (th->t_model, model, 64); - strcpy (th->soft, "dcraw v"DCRAW_VERSION); - t = localtime (×tamp); - sprintf (th->date, "%04d:%02d:%02d %02d:%02d:%02d", - t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); - strncpy (th->t_artist, artist, 64); -} - -void CLASS jpeg_thumb_writer (FILE *tfp,char *t_humb,int t_humb_length) -{ - ushort exif[5]; - struct tiff_hdr th; - fputc (0xff, tfp); - fputc (0xd8, tfp); - if (strcmp (t_humb+6, "Exif")) { - memcpy (exif, "\xff\xe1 Exif\0\0", 10); - exif[1] = htons (8 + sizeof th); - fwrite (exif, 1, sizeof exif, tfp); - tiff_head (&th, 0); - fwrite (&th, 1, sizeof th, tfp); - } - fwrite (t_humb+2, 1, t_humb_length-2, tfp); -} - - -void CLASS jpeg_thumb() -{ - char *thumb; - - thumb = (char *) malloc (thumb_length); - merror (thumb, "jpeg_thumb()"); - fread (thumb, 1, thumb_length, ifp); - jpeg_thumb_writer(ofp,thumb,thumb_length); - free (thumb); -} - -void CLASS write_ppm_tiff() -{ - struct tiff_hdr th; - uchar *ppm; - ushort *ppm2; - int c, row, col, soff, rstep, cstep; - int perc, val, total, t_white=0x2000; - - perc = width * height * 0.01; /* 99th percentile white level */ - if (fuji_width) perc /= 2; - if (!((highlight & ~2) || no_auto_bright)) - for (t_white=c=0; c < colors; c++) { - for (val=0x2000, total=0; --val > 32; ) - if ((total += histogram[c][val]) > perc) break; - if (t_white < val) t_white = val; - } - gamma_curve (gamm[0], gamm[1], 2, (t_white << 3)/bright); - iheight = height; - iwidth = width; - if (flip & 4) SWAP(height,width); - ppm = (uchar *) calloc (width, colors*output_bps/8); - ppm2 = (ushort *) ppm; - merror (ppm, "write_ppm_tiff()"); - if (output_tiff) { - tiff_head (&th, 1); - fwrite (&th, sizeof th, 1, ofp); - if (oprof) - fwrite (oprof, ntohl(oprof[0]), 1, ofp); - } else if (colors > 3) - fprintf (ofp, - "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLTYPE %s\nENDHDR\n", - width, height, colors, (1 << output_bps)-1, cdesc); - else - fprintf (ofp, "P%d\n%d %d\n%d\n", - colors/2+5, width, height, (1 << output_bps)-1); - - soff = flip_index (0, 0); - cstep = flip_index (0, 1) - soff; - rstep = flip_index (1, 0) - flip_index (0, width); - for (row=0; row < height; row++, soff += rstep) { - for (col=0; col < width; col++, soff += cstep) - if (output_bps == 8) - FORCC ppm [col*colors+c] = curve[image[soff][c]] >> 8; - else FORCC ppm2[col*colors+c] = curve[image[soff][c]]; - if (output_bps == 16 && !output_tiff && htons(0x55aa) != 0x55aa) - swab ((char*)ppm2, (char*)ppm2, width*colors*2); - fwrite (ppm, colors*output_bps/8, width, ofp); - } - free (ppm); -} - +/* + Copyright 2008-2010 LibRaw LLC (info@libraw.org) + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + + This file is generated from Dave Coffin's dcraw.c + dcraw.c -- Dave Coffin's raw photo decoder + Copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net + + Look into dcraw homepage (probably http://cybercom.net/~dcoffin/dcraw/) + for more information +*/ + +#include +#define CLASS LibRaw:: +#include "libraw/libraw_types.h" +#define LIBRAW_LIBRARY_BUILD +#define LIBRAW_IO_REDEFINED +#include "libraw/libraw.h" +#include "internal/defines.h" +#include "internal/var_defines.h" +#include "internal/libraw_bytebuffer.h" + +#ifndef __GLIBC__ +char *my_memmem (char *haystack, size_t haystacklen, + char *needle, size_t needlelen) +{ + char *c; + for (c = haystack; c <= haystack + haystacklen - needlelen; c++) + if (!memcmp (c, needle, needlelen)) + return c; + return 0; +} +#define memmem my_memmem +#endif + + +ushort CLASS sget2 (uchar *s) +{ + if (order == 0x4949) /* "II" means little-endian */ + return s[0] | s[1] << 8; + else /* "MM" means big-endian */ + return s[0] << 8 | s[1]; +} + +ushort CLASS get2() +{ + uchar str[2] = { 0xff,0xff }; + fread (str, 1, 2, ifp); + return sget2(str); +} + +unsigned CLASS sget4 (uchar *s) +{ + if (order == 0x4949) + return s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24; + else + return s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]; +} +#define sget4(s) sget4((uchar *)s) + +unsigned CLASS get4() +{ + uchar str[4] = { 0xff,0xff,0xff,0xff }; + fread (str, 1, 4, ifp); + return sget4(str); +} + +unsigned CLASS getint (int type) +{ + return type == 3 ? get2() : get4(); +} + +float CLASS int_to_float (int i) +{ + union { int i; float f; } u; + u.i = i; + return u.f; +} + +double CLASS getreal (int type) +{ + union { char c[8]; double d; } u; + int i, rev; + + switch (type) { + case 3: return (unsigned short) get2(); + case 4: return (unsigned int) get4(); + case 5: u.d = (unsigned int) get4(); + return u.d / (unsigned int) get4(); + case 8: return (signed short) get2(); + case 9: return (signed int) get4(); + case 10: u.d = (signed int) get4(); + return u.d / (signed int) get4(); + case 11: return int_to_float (get4()); + case 12: + rev = 7 * ((order == 0x4949) == (ntohs(0x1234) == 0x1234)); + for (i=0; i < 8; i++) + u.c[i ^ rev] = fgetc(ifp); + return u.d; + default: return fgetc(ifp); + } +} + +void CLASS read_shorts (ushort *pixel, int count) +{ + if (fread (pixel, 2, count, ifp) < count) derror(); + if ((order == 0x4949) == (ntohs(0x1234) == 0x1234)) + swab ((char*)pixel, (char*)pixel, count*2); +} + +#ifdef LIBRAW_LIBRARY_BUILD +#define RBAYER(x,y) raw_image[(x)*raw_width+(y)] +#define RRBAYER(x,y) raw_image[((x)+top_margin)*raw_width+(y)+left_margin] +#define CBAYER(x,y) color_image[((x)+top_margin)*raw_width+(y)+left_margin][FC((x),(y))] +#else +#define CBAYER(x,y) BAYER((x),(y)) +#define RBAYER(x,y) BAYER((x),(y)) +#define RRBAYER(x,y) BAYER((x),(y)) +#endif + +void CLASS canon_600_fixed_wb (int temp) +{ + static const short mul[4][5] = { + { 667, 358,397,565,452 }, + { 731, 390,367,499,517 }, + { 1119, 396,348,448,537 }, + { 1399, 485,431,508,688 } }; + int lo, hi, i; + float frac=0; + + for (lo=4; --lo; ) + if (*mul[lo] <= temp) break; + for (hi=0; hi < 3; hi++) + if (*mul[hi] >= temp) break; + if (lo != hi) + frac = (float) (temp - *mul[lo]) / (*mul[hi] - *mul[lo]); + for (i=1; i < 5; i++) + pre_mul[i-1] = 1 / (frac * mul[hi][i] + (1-frac) * mul[lo][i]); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.pre_mul_state = LIBRAW_COLORSTATE_CONST; +#endif +} + +/* Return values: 0 = white 1 = near white 2 = not white */ +int CLASS canon_600_color (int ratio[2], int mar) +{ + int clipped=0, target, miss; + + if (flash_used) { + if (ratio[1] < -104) + { ratio[1] = -104; clipped = 1; } + if (ratio[1] > 12) + { ratio[1] = 12; clipped = 1; } + } else { + if (ratio[1] < -264 || ratio[1] > 461) return 2; + if (ratio[1] < -50) + { ratio[1] = -50; clipped = 1; } + if (ratio[1] > 307) + { ratio[1] = 307; clipped = 1; } + } + target = flash_used || ratio[1] < 197 + ? -38 - (398 * ratio[1] >> 10) + : -123 + (48 * ratio[1] >> 10); + if (target - mar <= ratio[0] && + target + 20 >= ratio[0] && !clipped) return 0; + miss = target - ratio[0]; + if (abs(miss) >= mar*4) return 2; + if (miss < -20) miss = -20; + if (miss > mar) miss = mar; + ratio[0] = target - miss; + return 1; +} + +void CLASS canon_600_auto_wb() +{ + int mar, row, col, i, j, st, count[] = { 0,0 }; + int test[8], total[2][8], ratio[2][2], stat[2]; + + memset (&total, 0, sizeof total); + i = canon_ev + 0.5; + if (i < 10) mar = 150; + else if (i > 12) mar = 20; + else mar = 280 - 20 * i; + if (flash_used) mar = 80; + for (row=14; row < height-14; row+=4) + for (col=10; col < width; col+=2) { + for (i=0; i < 8; i++) + test[(i & 4) + FC(row+(i >> 1),col+(i & 1))] = + BAYER(row+(i >> 1),col+(i & 1)); + for (i=0; i < 8; i++) + if (test[i] < 150 || test[i] > 1500) goto next; + for (i=0; i < 4; i++) + if (abs(test[i] - test[i+4]) > 50) goto next; + for (i=0; i < 2; i++) { + for (j=0; j < 4; j+=2) + ratio[i][j >> 1] = ((test[i*4+j+1]-test[i*4+j]) << 10) / test[i*4+j]; + stat[i] = canon_600_color (ratio[i], mar); + } + if ((st = stat[0] | stat[1]) > 1) goto next; + for (i=0; i < 2; i++) + if (stat[i]) + for (j=0; j < 2; j++) + test[i*4+j*2+1] = test[i*4+j*2] * (0x400 + ratio[i][j]) >> 10; + for (i=0; i < 8; i++) + total[st][i] += test[i]; + count[st]++; +next: ; + } + if (count[0] | count[1]) { + st = count[0]*200 < count[1]; + for (i=0; i < 4; i++) + pre_mul[i] = 1.0 / (total[st][i] + total[st][i+4]); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.pre_mul_state = LIBRAW_COLORSTATE_CALCULATED; +#endif + } +} + +void CLASS canon_600_coeff() +{ + static const short table[6][12] = { + { -190,702,-1878,2390, 1861,-1349,905,-393, -432,944,2617,-2105 }, + { -1203,1715,-1136,1648, 1388,-876,267,245, -1641,2153,3921,-3409 }, + { -615,1127,-1563,2075, 1437,-925,509,3, -756,1268,2519,-2007 }, + { -190,702,-1886,2398, 2153,-1641,763,-251, -452,964,3040,-2528 }, + { -190,702,-1878,2390, 1861,-1349,905,-393, -432,944,2617,-2105 }, + { -807,1319,-1785,2297, 1388,-876,769,-257, -230,742,2067,-1555 } }; + int t=0, i, c; + float mc, yc; + + mc = pre_mul[1] / pre_mul[2]; + yc = pre_mul[3] / pre_mul[2]; + if (mc > 1 && mc <= 1.28 && yc < 0.8789) t=1; + if (mc > 1.28 && mc <= 2) { + if (yc < 0.8789) t=3; + else if (yc <= 2) t=4; + } + if (flash_used) t=5; + for (raw_color = i=0; i < 3; i++) + FORCC rgb_cam[i][c] = table[t][i*4 + c] / 1024.0; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.rgb_cam_state = LIBRAW_COLORSTATE_CALCULATED; +#endif +} + +void CLASS canon_600_load_raw() +{ + uchar data[1120], *dp; + ushort pixel[896], *pix; + int irow, row, col, val; + static const short mul[4][2] = + { { 1141,1145 }, { 1128,1109 }, { 1178,1149 }, { 1128,1109 } }; + + for (irow=row=0; irow < height; irow++) { + if (fread (data, 1, raw_width*5/4, ifp) < raw_width*5/4) derror(); + for (dp=data, pix=pixel; dp < data+1120; dp+=10, pix+=8) { + pix[0] = (dp[0] << 2) + (dp[1] >> 6 ); + pix[1] = (dp[2] << 2) + (dp[1] >> 4 & 3); + pix[2] = (dp[3] << 2) + (dp[1] >> 2 & 3); + pix[3] = (dp[4] << 2) + (dp[1] & 3); + pix[4] = (dp[5] << 2) + (dp[9] & 3); + pix[5] = (dp[6] << 2) + (dp[9] >> 2 & 3); + pix[6] = (dp[7] << 2) + (dp[9] >> 4 & 3); + pix[7] = (dp[8] << 2) + (dp[9] >> 6 ); + } +#ifndef LIBRAW_LIBRARY_BUILD + for (col=0; col < width; col++) + { + BAYER(row,col) = pixel[col]; + } +#else + for (col=0; col < raw_width; col++) + RBAYER(row,col) = pixel[col]; +#endif + + for (col=width; col < raw_width; col++) + { + black += pixel[col]; + } + if ((row+=2) > height) row = 1; + } + if (raw_width > width) + black = black / ((raw_width - width) * height) - 4; +#ifndef LIBRAW_LIBRARY_BUILD + for (row=0; row < height; row++) + for (col=0; col < width; col++) { + if ((val = BAYER(row,col) - black) < 0) val = 0; + val = val * mul[row & 3][col & 1] >> 9; + BAYER(row,col) = val; + } +#else + for (row=0; row < height; row++) + for (col=0; col < raw_width; col++) { + if ((val = RBAYER(row,col) - black) < 0) val = 0; + val = val * mul[row & 3][col & 1] >> 9; + RBAYER(row,col) = val; + } + +#endif + canon_600_fixed_wb(1311); + canon_600_auto_wb(); + canon_600_coeff(); + maximum = (0x3ff - black) * 1109 >> 9; + black = 0; +} + +void CLASS remove_zeroes() +{ + unsigned row, col, tot, n, r, c; + +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_REMOVE_ZEROES,0,2); +#endif + for (row=0; row < height; row++) + for (col=0; col < width; col++) + if (BAYER(row,col) == 0) { + tot = n = 0; + for (r = row-2; r <= row+2; r++) + for (c = col-2; c <= col+2; c++) + if (r < height && c < width && + FC(r,c) == FC(row,col) && BAYER(r,c)) + tot += (n++,BAYER(r,c)); + if (n) BAYER(row,col) = tot/n; + } +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_REMOVE_ZEROES,1,2); +#endif +} + +int CLASS canon_s2is() +{ + unsigned row; + + for (row=0; row < 100; row++) { + fseek (ifp, row*3340 + 3284, SEEK_SET); + if (getc(ifp) > 15) return 1; + } + return 0; +} + +/* + getbits(-1) initializes the buffer + getbits(n) where 0 <= n <= 25 returns an n-bit integer + */ + +unsigned CLASS getbithuff (int nbits, ushort *huff) +{ +#ifdef LIBRAW_NOTHREADS + static unsigned bitbuf=0; + static int vbits=0, reset=0; +#else +#define bitbuf tls->getbits.bitbuf +#define vbits tls->getbits.vbits +#define reset tls->getbits.reset +#endif + unsigned c; + + if (nbits == -1) + return bitbuf = vbits = reset = 0; + if (nbits == 0 || vbits < 0) return 0; + while (!reset && vbits < nbits && (c = fgetc(ifp)) != EOF && + !(reset = zero_after_ff && c == 0xff && fgetc(ifp))) { + bitbuf = (bitbuf << 8) + (uchar) c; + vbits += 8; + } + c = bitbuf << (32-vbits) >> (32-nbits); + if (huff) { + vbits -= huff[c] >> 8; + c = (uchar) huff[c]; + } else + vbits -= nbits; + if (vbits < 0) derror(); + return c; +#ifndef LIBRAW_NOTHREADS +#undef bitbuf +#undef vbits +#undef reset +#endif +} + +#define getbits(n) getbithuff(n,0) +#define gethuff(h) getbithuff(*h,h+1) + +/* + Construct a decode tree according to the specification in *source. + The first 16 bytes specify how many codes should be 1-bit, 2-bit + 3-bit, etc. Bytes after that are the leaf values. + + For example, if the source is + + { 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0, + 0x04,0x03,0x05,0x06,0x02,0x07,0x01,0x08,0x09,0x00,0x0a,0x0b,0xff }, + + then the code is + + 00 0x04 + 010 0x03 + 011 0x05 + 100 0x06 + 101 0x02 + 1100 0x07 + 1101 0x01 + 11100 0x08 + 11101 0x09 + 11110 0x00 + 111110 0x0a + 1111110 0x0b + 1111111 0xff + */ +ushort * CLASS make_decoder_ref (const uchar **source) +{ + int max, len, h, i, j; + const uchar *count; + ushort *huff; + + count = (*source += 16) - 17; + for (max=16; max && !count[max]; max--); + huff = (ushort *) calloc (1 + (1 << max), sizeof *huff); + merror (huff, "make_decoder()"); + huff[0] = max; + for (h=len=1; len <= max; len++) + for (i=0; i < count[len]; i++, ++*source) + for (j=0; j < 1 << (max-len); j++) + if (h <= 1 << max) + huff[h++] = len << 8 | **source; + return huff; +} + +ushort * CLASS make_decoder (const uchar *source) +{ + return make_decoder_ref (&source); +} + +void CLASS crw_init_tables (unsigned table, ushort *huff[2]) +{ + static const uchar first_tree[3][29] = { + { 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0, + 0x04,0x03,0x05,0x06,0x02,0x07,0x01,0x08,0x09,0x00,0x0a,0x0b,0xff }, + { 0,2,2,3,1,1,1,1,2,0,0,0,0,0,0,0, + 0x03,0x02,0x04,0x01,0x05,0x00,0x06,0x07,0x09,0x08,0x0a,0x0b,0xff }, + { 0,0,6,3,1,1,2,0,0,0,0,0,0,0,0,0, + + 0x06,0x05,0x07,0x04,0x08,0x03,0x09,0x02,0x00,0x0a,0x01,0x0b,0xff }, + }; + static const uchar second_tree[3][180] = { + { 0,2,2,2,1,4,2,1,2,5,1,1,0,0,0,139, + 0x03,0x04,0x02,0x05,0x01,0x06,0x07,0x08, + 0x12,0x13,0x11,0x14,0x09,0x15,0x22,0x00,0x21,0x16,0x0a,0xf0, + 0x23,0x17,0x24,0x31,0x32,0x18,0x19,0x33,0x25,0x41,0x34,0x42, + 0x35,0x51,0x36,0x37,0x38,0x29,0x79,0x26,0x1a,0x39,0x56,0x57, + 0x28,0x27,0x52,0x55,0x58,0x43,0x76,0x59,0x77,0x54,0x61,0xf9, + 0x71,0x78,0x75,0x96,0x97,0x49,0xb7,0x53,0xd7,0x74,0xb6,0x98, + 0x47,0x48,0x95,0x69,0x99,0x91,0xfa,0xb8,0x68,0xb5,0xb9,0xd6, + 0xf7,0xd8,0x67,0x46,0x45,0x94,0x89,0xf8,0x81,0xd5,0xf6,0xb4, + 0x88,0xb1,0x2a,0x44,0x72,0xd9,0x87,0x66,0xd4,0xf5,0x3a,0xa7, + 0x73,0xa9,0xa8,0x86,0x62,0xc7,0x65,0xc8,0xc9,0xa1,0xf4,0xd1, + 0xe9,0x5a,0x92,0x85,0xa6,0xe7,0x93,0xe8,0xc1,0xc6,0x7a,0x64, + 0xe1,0x4a,0x6a,0xe6,0xb3,0xf1,0xd3,0xa5,0x8a,0xb2,0x9a,0xba, + 0x84,0xa4,0x63,0xe5,0xc5,0xf3,0xd2,0xc4,0x82,0xaa,0xda,0xe4, + 0xf2,0xca,0x83,0xa3,0xa2,0xc3,0xea,0xc2,0xe2,0xe3,0xff,0xff }, + { 0,2,2,1,4,1,4,1,3,3,1,0,0,0,0,140, + 0x02,0x03,0x01,0x04,0x05,0x12,0x11,0x06, + 0x13,0x07,0x08,0x14,0x22,0x09,0x21,0x00,0x23,0x15,0x31,0x32, + 0x0a,0x16,0xf0,0x24,0x33,0x41,0x42,0x19,0x17,0x25,0x18,0x51, + 0x34,0x43,0x52,0x29,0x35,0x61,0x39,0x71,0x62,0x36,0x53,0x26, + 0x38,0x1a,0x37,0x81,0x27,0x91,0x79,0x55,0x45,0x28,0x72,0x59, + 0xa1,0xb1,0x44,0x69,0x54,0x58,0xd1,0xfa,0x57,0xe1,0xf1,0xb9, + 0x49,0x47,0x63,0x6a,0xf9,0x56,0x46,0xa8,0x2a,0x4a,0x78,0x99, + 0x3a,0x75,0x74,0x86,0x65,0xc1,0x76,0xb6,0x96,0xd6,0x89,0x85, + 0xc9,0xf5,0x95,0xb4,0xc7,0xf7,0x8a,0x97,0xb8,0x73,0xb7,0xd8, + 0xd9,0x87,0xa7,0x7a,0x48,0x82,0x84,0xea,0xf4,0xa6,0xc5,0x5a, + 0x94,0xa4,0xc6,0x92,0xc3,0x68,0xb5,0xc8,0xe4,0xe5,0xe6,0xe9, + 0xa2,0xa3,0xe3,0xc2,0x66,0x67,0x93,0xaa,0xd4,0xd5,0xe7,0xf8, + 0x88,0x9a,0xd7,0x77,0xc4,0x64,0xe2,0x98,0xa5,0xca,0xda,0xe8, + 0xf3,0xf6,0xa9,0xb2,0xb3,0xf2,0xd2,0x83,0xba,0xd3,0xff,0xff }, + { 0,0,6,2,1,3,3,2,5,1,2,2,8,10,0,117, + 0x04,0x05,0x03,0x06,0x02,0x07,0x01,0x08, + 0x09,0x12,0x13,0x14,0x11,0x15,0x0a,0x16,0x17,0xf0,0x00,0x22, + 0x21,0x18,0x23,0x19,0x24,0x32,0x31,0x25,0x33,0x38,0x37,0x34, + 0x35,0x36,0x39,0x79,0x57,0x58,0x59,0x28,0x56,0x78,0x27,0x41, + 0x29,0x77,0x26,0x42,0x76,0x99,0x1a,0x55,0x98,0x97,0xf9,0x48, + 0x54,0x96,0x89,0x47,0xb7,0x49,0xfa,0x75,0x68,0xb6,0x67,0x69, + 0xb9,0xb8,0xd8,0x52,0xd7,0x88,0xb5,0x74,0x51,0x46,0xd9,0xf8, + 0x3a,0xd6,0x87,0x45,0x7a,0x95,0xd5,0xf6,0x86,0xb4,0xa9,0x94, + 0x53,0x2a,0xa8,0x43,0xf5,0xf7,0xd4,0x66,0xa7,0x5a,0x44,0x8a, + 0xc9,0xe8,0xc8,0xe7,0x9a,0x6a,0x73,0x4a,0x61,0xc7,0xf4,0xc6, + 0x65,0xe9,0x72,0xe6,0x71,0x91,0x93,0xa6,0xda,0x92,0x85,0x62, + 0xf3,0xc5,0xb2,0xa4,0x84,0xba,0x64,0xa5,0xb3,0xd2,0x81,0xe5, + 0xd3,0xaa,0xc4,0xca,0xf2,0xb1,0xe4,0xd1,0x83,0x63,0xea,0xc3, + 0xe2,0x82,0xf1,0xa3,0xc2,0xa1,0xc1,0xe3,0xa2,0xe1,0xff,0xff } + }; + if (table > 2) table = 2; + huff[0] = make_decoder ( first_tree[table]); + huff[1] = make_decoder (second_tree[table]); +} + +/* + Return 0 if the image starts with compressed data, + 1 if it starts with uncompressed low-order bits. + + In Canon compressed data, 0xff is always followed by 0x00. + */ +int CLASS canon_has_lowbits() +{ + uchar test[0x4000]; + int ret=1; + unsigned i; + + fseek (ifp, 0, SEEK_SET); + fread (test, 1, sizeof test, ifp); + for (i=540; i < sizeof test - 1; i++) + if (test[i] == 0xff) { + if (test[i+1]) return 1; + ret=0; + } + return ret; +} + +void CLASS canon_compressed_load_raw() +{ + ushort *pixel, *prow, *huff[2]; + int nblocks, lowbits, i, c, row, r, col, save, val; + unsigned irow, icol; + int block, diffbuf[64], leaf, len, diff, carry=0, pnum=0, base[2]; + + crw_init_tables (tiff_compress, huff); + pixel = (ushort *) calloc (raw_width*8, sizeof *pixel); + merror (pixel, "canon_compressed_load_raw()"); + lowbits = canon_has_lowbits(); + if (!lowbits) maximum = 0x3ff; + fseek (ifp, 540 + lowbits*raw_height*raw_width/4, SEEK_SET); + zero_after_ff = 1; + getbits(-1); + for (row=0; row < raw_height; row+=8) { + nblocks = MIN (8, raw_height-row) * raw_width >> 6; + for (block=0; block < nblocks; block++) { + memset (diffbuf, 0, sizeof diffbuf); + for (i=0; i < 64; i++ ) { + leaf = gethuff(huff[i > 0]); + if (leaf == 0 && i) break; + if (leaf == 0xff) continue; + i += leaf >> 4; + len = leaf & 15; + if (len == 0) continue; + diff = getbits(len); + if ((diff & (1 << (len-1))) == 0) + diff -= (1 << len) - 1; + if (i < 64) diffbuf[i] = diff; + } + diffbuf[0] += carry; + carry = diffbuf[0]; + for (i=0; i < 64; i++ ) { + if (pnum++ % raw_width == 0) + base[0] = base[1] = 512; + if ((pixel[(block << 6) + i] = base[i & 1] += diffbuf[i]) >> 10) + derror(); + } + } + if (lowbits) { + save = ftell(ifp); + fseek (ifp, 26 + row*raw_width/4, SEEK_SET); + for (prow=pixel, i=0; i < raw_width*2; i++) { + c = fgetc(ifp); + for (r=0; r < 8; r+=2, prow++) { + val = (*prow << 2) + ((c >> r) & 3); + if (raw_width == 2672 && val < 512) val += 2; + *prow = val; + } + } + fseek (ifp, save, SEEK_SET); + } + +#ifdef LIBRAW_LIBRARY_BUILD + for (r=0; r < 8; r++) { + if(row+r>=raw_height) break; // Not sure that raw_height is always N*8 + // MOVE entire row into place + memmove(&raw_image[(row+r)*raw_width],&pixel[r*raw_width],raw_width*sizeof(pixel[0])); + + irow = row - top_margin + r; + if (irow >= height) continue; // if row above image area than irow is VERY positive :) + + // only margins! + for (col=0; col < left_margin; col++) + { + icol = col - left_margin; + c = FC(irow,icol); + if (icol >= width && col > 1 && (unsigned) (col-left_margin+2) > width+3) + cblack[c] += (cblack[4+c]++,pixel[r*raw_width+col]); + } + for (col=width+left_margin; col < raw_width; col++) + { + icol = col - left_margin; + c = FC(irow,icol); + if (icol >= width && col > 1 && (unsigned) (col-left_margin+2) > width+3) + cblack[c] += (cblack[4+c]++,pixel[r*raw_width+col]); + } + + } +#else + // dcraw original code + for (r=0; r < 8; r++) { + irow = row - top_margin + r; + if (irow >= height) continue; + for (col=0; col < raw_width; col++) { + icol = col - left_margin; + c = FC(irow,icol); + if (icol < width) + BAYER(irow,icol) = pixel[r*raw_width+col]; + else if (col > 1 && (unsigned) (col-left_margin+2) > width+3) + cblack[c] += (cblack[4+c]++,pixel[r*raw_width+col]); + } + } +#endif + } + free (pixel); + FORC(2) free (huff[c]); + FORC4 if (cblack[4+c]) cblack[c] /= cblack[4+c]; +} + +int CLASS ljpeg_start (struct jhead *jh, int info_only) +{ + int c, tag, len; + uchar data[0x10000]; + const uchar *dp; + + memset (jh, 0, sizeof *jh); + jh->restart = INT_MAX; + fread (data, 2, 1, ifp); + if (data[1] != 0xd8) return 0; + do { + fread (data, 2, 2, ifp); + tag = data[0] << 8 | data[1]; + len = (data[2] << 8 | data[3]) - 2; + if (tag <= 0xff00) return 0; + fread (data, 1, len, ifp); + switch (tag) { + case 0xffc3: + jh->sraw = ((data[7] >> 4) * (data[7] & 15) - 1) & 3; + case 0xffc0: + jh->bits = data[0]; + jh->high = data[1] << 8 | data[2]; + jh->wide = data[3] << 8 | data[4]; + jh->clrs = data[5] + jh->sraw; + if (len == 9 && !dng_version) getc(ifp); + break; + case 0xffc4: + if (info_only) break; + for (dp = data; dp < data+len && (c = *dp++) < 4; ) + jh->free[c] = jh->huff[c] = make_decoder_ref (&dp); + break; + case 0xffda: + jh->psv = data[1+data[0]*2]; + jh->bits -= data[3+data[0]*2] & 15; + break; + case 0xffdd: + jh->restart = data[0] << 8 | data[1]; + } + } while (tag != 0xffda); + if (info_only) return 1; + FORC(5) if (!jh->huff[c+1]) jh->huff[c+1] = jh->huff[c]; + if (jh->sraw) { + FORC(4) jh->huff[2+c] = jh->huff[1]; + FORC(jh->sraw) jh->huff[1+c] = jh->huff[0]; + } + jh->row = (ushort *) calloc (jh->wide*jh->clrs, 4); + merror (jh->row, "ljpeg_start()"); + return zero_after_ff = 1; +} + +void CLASS ljpeg_end (struct jhead *jh) +{ + int c; + FORC4 if (jh->free[c]) free (jh->free[c]); + free (jh->row); +} + +// used for kodak-262 decoder +int CLASS ljpeg_diff (ushort *huff) +{ + int len, diff; + + len = gethuff(huff); + if (len == 16 && (!dng_version || dng_version >= 0x1010000)) + return -32768; + diff = getbits(len); + if ((diff & (1 << (len-1))) == 0) + diff -= (1 << len) - 1; + return diff; +} + +#ifdef LIBRAW_LIBRARY_BUILD +int CLASS ljpeg_diff_new (LibRaw_bit_buffer& bits, LibRaw_byte_buffer* buf,ushort *huff) +{ + int len, diff; + + len = bits._gethuff_lj(buf,*huff,huff+1); + if (len == 16 && (!dng_version || dng_version >= 0x1010000)) + return -32768; + diff = bits._getbits_lj(buf,len); + if ((diff & (1 << (len-1))) == 0) + diff -= (1 << len) - 1; + return diff; +} + +int CLASS ljpeg_diff_pef (LibRaw_bit_buffer& bits, LibRaw_byte_buffer* buf,ushort *huff) +{ + int len, diff; + + len = bits._gethuff(buf,*huff,huff+1,zero_after_ff); + if (len == 16 && (!dng_version || dng_version >= 0x1010000)) + return -32768; + diff = bits._getbits(buf,len,zero_after_ff); + if ((diff & (1 << (len-1))) == 0) + diff -= (1 << len) - 1; + return diff; +} + + +#endif + + +ushort * CLASS ljpeg_row (int jrow, struct jhead *jh) +{ + int col, c, diff, pred, spred=0; + ushort mark=0, *row[3]; + + if (jrow * jh->wide % jh->restart == 0) { + FORC(6) jh->vpred[c] = 1 << (jh->bits-1); + if (jrow) { + fseek (ifp, -2, SEEK_CUR); + do mark = (mark << 8) + (c = fgetc(ifp)); + while (c != EOF && mark >> 4 != 0xffd); + } + getbits(-1); + } + FORC3 row[c] = jh->row + jh->wide*jh->clrs*((jrow+c) & 1); + for (col=0; col < jh->wide; col++) + FORC(jh->clrs) { + diff = ljpeg_diff (jh->huff[c]); + if (jh->sraw && c <= jh->sraw && (col | c)) + pred = spred; + else if (col) pred = row[0][-jh->clrs]; + else pred = (jh->vpred[c] += diff) - diff; + if (jrow && col) switch (jh->psv) { + case 1: break; + case 2: pred = row[1][0]; break; + case 3: pred = row[1][-jh->clrs]; break; + case 4: pred = pred + row[1][0] - row[1][-jh->clrs]; break; + case 5: pred = pred + ((row[1][0] - row[1][-jh->clrs]) >> 1); break; + case 6: pred = row[1][0] + ((pred - row[1][-jh->clrs]) >> 1); break; + case 7: pred = (pred + row[1][0]) >> 1; break; + default: pred = 0; + } + if ((**row = pred + diff) >> jh->bits) derror(); + if (c <= jh->sraw) spred = **row; + row[0]++; row[1]++; + } + return row[2]; +} + +#ifdef LIBRAW_LIBRARY_BUILD +ushort * CLASS ljpeg_row_new (int jrow, struct jhead *jh, LibRaw_bit_buffer& bits,LibRaw_byte_buffer* bytes) +{ + int col, c, diff, pred, spred=0; + ushort mark=0, *row[3]; + + if (jrow * jh->wide % jh->restart == 0) { + FORC(6) jh->vpred[c] = 1 << (jh->bits-1); + if (jrow) { + bytes->unseek2(); + do mark = (mark << 8) + (c = bytes->get_byte()); + while (c != EOF && mark >> 4 != 0xffd); + } + bits.reset(); + } + FORC3 row[c] = jh->row + jh->wide*jh->clrs*((jrow+c) & 1); + for (col=0; col < jh->wide; col++) + FORC(jh->clrs) { + diff = ljpeg_diff_new (bits,bytes,jh->huff[c]); + if (jh->sraw && c <= jh->sraw && (col | c)) + pred = spred; + else if (col) pred = row[0][-jh->clrs]; + else pred = (jh->vpred[c] += diff) - diff; + if (jrow && col) switch (jh->psv) { + case 1: break; + case 2: pred = row[1][0]; break; + case 3: pred = row[1][-jh->clrs]; break; + case 4: pred = pred + row[1][0] - row[1][-jh->clrs]; break; + case 5: pred = pred + ((row[1][0] - row[1][-jh->clrs]) >> 1); break; + case 6: pred = row[1][0] + ((pred - row[1][-jh->clrs]) >> 1); break; + case 7: pred = (pred + row[1][0]) >> 1; break; + default: pred = 0; + } + if ((**row = pred + diff) >> jh->bits) derror(); + if (c <= jh->sraw) spred = **row; + row[0]++; row[1]++; + } + return row[2]; +} + +#endif + +void CLASS lossless_jpeg_load_raw() +{ + int jwide, jrow, jcol, val, c, i, row=0, col=0; +#ifndef LIBRAW_LIBRARY_BUILD + int jidx,j; +#endif + struct jhead jh; + int min=INT_MAX; + ushort *rp; +#ifdef LIBRAW_LIBRARY_BUILD + int save_min = 0; + unsigned slicesW[16],slicesWcnt=0,slices; + unsigned *offset; + unsigned t_y=0,t_x=0,t_s=0,slice=0,pixelsInSlice,pixno; + if (!strcasecmp(make,"KODAK")) + save_min = 1; +#endif + +#ifdef LIBRAW_LIBRARY_BUILD + if (cr2_slice[0]>15) + throw LIBRAW_EXCEPTION_IO_EOF; // change many slices +#else + if (cr2_slice[0]>15) + { + fprintf(stderr,"Too many CR2 slices: %d\n",cr2_slice[0]+1); + return; + } +#endif + + + if (!ljpeg_start (&jh, 0)) return; + jwide = jh.wide * jh.clrs; + +#ifdef LIBRAW_LIBRARY_BUILD + if(cr2_slice[0]) + { + for(i=0;i= raw_width * raw_height) + throw LIBRAW_EXCEPTION_IO_BADFILE; + t_y++; + if(t_y == jh.high) + { + t_y = 0; + t_x += slicesW[t_s++]; + } + } + offset[slices] = offset[slices-1]; + slice = 1; // next slice + pixno = offset[0]; + pixelsInSlice = slicesW[0]; +#endif + +#ifdef LIBRAW_LIBRARY_BUILD + LibRaw_byte_buffer *buf=NULL; + if(data_size) + buf = ifp->make_byte_buffer(data_size); + LibRaw_bit_buffer bits; +#endif + for (jrow=0; jrow < jh.high; jrow++) { +#ifdef LIBRAW_LIBRARY_BUILD + if (buf) + rp = ljpeg_row_new (jrow, &jh,bits,buf); + else +#endif + rp = ljpeg_row (jrow, &jh); + + if (load_flags & 1) + row = jrow & 1 ? height-1-jrow/2 : jrow/2; + for (jcol=0; jcol < jwide; jcol++) { + val = *rp++; + if (jh.bits <= 12) + val = curve[val & 0xfff]; +#ifndef LIBRAW_LIBRARY_BUILD + // slow dcraw way to calculate row/col + if (cr2_slice[0]) { + jidx = jrow*jwide + jcol; + i = jidx / (cr2_slice[1]*jh.high); + if ((j = i >= cr2_slice[0])) + i = cr2_slice[0]; + jidx -= i * (cr2_slice[1]*jh.high); + row = jidx / cr2_slice[1+j]; + col = jidx % cr2_slice[1+j] + i*cr2_slice[1]; + } +#else + // new fast one, but for data_size defined only (i.e. new CR2 format, not 1D/1Ds) + if(buf) + { + if(!(load_flags & 1)) + row = pixno/raw_width; + col = pixno % raw_width; + pixno++; + if (0 == --pixelsInSlice) + { + unsigned o = offset[slice++]; + pixno = o & 0x0fffffff; + pixelsInSlice = slicesW[o>>28]; + } + } +#endif +#ifndef LIBRAW_LIBRARY_BUILD + + if (raw_width == 3984 && (col -= 2) < 0) + col += (row--,raw_width); + + if ((unsigned) (row-top_margin) < height) { + c = FC(row-top_margin,col-left_margin); + if ((unsigned) (col-left_margin) < width) { + BAYER(row-top_margin,col-left_margin) = val; + if (min > val) min = val; + } else if (col > 1 && (unsigned) (col-left_margin+2) > width+3) + cblack[c] += (cblack[4+c]++,val); + } +#else + if (raw_width == 3984) + { + if ( (col -= 2) < 0) + col += (row--,raw_width); + if(row >= 0 && row < raw_height && col >= 0 && col < raw_width) + RBAYER(row,col) = val; + } + else + RBAYER(row,col) = val; + + if ((unsigned) (row-top_margin) < height) + { + // within image height + if ((unsigned) (col-left_margin) < width) + { + // within image area, save min + if(save_min) + if (min > val) min = val; + } + else if (col > 1 && (unsigned) (col-left_margin+2) > width+3) + { + c = FC(row-top_margin,col-left_margin); + cblack[c] += (cblack[4+c]++,val); + } + } +#endif + +#ifndef LIBRAW_LIBRARY_BUILD + if (++col >= raw_width) + col = (row++,0); +#else + if(!buf) // 1D or 1Ds case + if (++col >= raw_width) + col = (row++,0); +#endif + } + } + ljpeg_end (&jh); + FORC4 if (cblack[4+c]) cblack[c] /= cblack[4+c]; + if (!strcasecmp(make,"KODAK")) + black = min; +#ifdef LIBRAW_LIBRARY_BUILD + if(buf) + delete buf; + free(offset); +#endif +} + +void CLASS canon_sraw_load_raw() +{ + struct jhead jh; + short *rp=0, (*ip)[4]; + int jwide, slice, scol, ecol, row, col, jrow=0, jcol=0, pix[3], c; + int v[3]={0,0,0}, ver, hue; + char *cp; + + if (!ljpeg_start (&jh, 0)) return; + jwide = (jh.wide >>= 1) * jh.clrs; + +#ifdef LIBRAW_LIBRARY_BUILD + if(!data_size) + throw LIBRAW_EXCEPTION_IO_BADFILE; + LibRaw_byte_buffer *buf = ifp->make_byte_buffer(data_size); + LibRaw_bit_buffer bits; +#endif + + + for (ecol=slice=0; slice <= cr2_slice[0]; slice++) { + scol = ecol; + ecol += cr2_slice[1] * 2 / jh.clrs; + if (!cr2_slice[0] || ecol > raw_width-1) ecol = raw_width & -2; + for (row=0; row < height; row += (jh.clrs >> 1) - 1) { + ip = (short (*)[4]) image + row*width; + for (col=scol; col < ecol; col+=2, jcol+=jh.clrs) { + if ((jcol %= jwide) == 0) +#ifdef LIBRAW_LIBRARY_BUILD + rp = (short*) ljpeg_row_new (jrow++, &jh,bits,buf); +#else + rp = (short *) ljpeg_row (jrow++, &jh); +#endif + if (col >= width) continue; + FORC (jh.clrs-2) + ip[col + (c >> 1)*width + (c & 1)][0] = rp[jcol+c]; + ip[col][1] = rp[jcol+jh.clrs-2] - 16384; + ip[col][2] = rp[jcol+jh.clrs-1] - 16384; + } + } + } + for (cp=model2; *cp && !isdigit(*cp); cp++); + sscanf (cp, "%d.%d.%d", v, v+1, v+2); + ver = (v[0]*1000 + v[1])*1000 + v[2]; + hue = (jh.sraw+1) << 2; + if (unique_id >= 0x80000281 || (unique_id == 0x80000218 && ver > 1000006)) + hue = jh.sraw << 1; + ip = (short (*)[4]) image; + rp = ip[0]; + for (row=0; row < height; row++, ip+=width) { + if (row & (jh.sraw >> 1)) + for (col=0; col < width; col+=2) + for (c=1; c < 3; c++) + if (row == height-1) + ip[col][c] = ip[col-width][c]; + else ip[col][c] = (ip[col-width][c] + ip[col+width][c] + 1) >> 1; + for (col=1; col < width; col+=2) + for (c=1; c < 3; c++) + if (col == width-1) + ip[col][c] = ip[col-1][c]; + else ip[col][c] = (ip[col-1][c] + ip[col+1][c] + 1) >> 1; + } + for ( ; rp < ip[0]; rp+=4) { +#if 1 + if (unique_id < 0x80000218) { + rp[0] -= 512; + goto next; + } else if (unique_id == 0x80000285) { +next: pix[0] = rp[0] + rp[2]; + pix[2] = rp[0] + rp[1]; + pix[1] = rp[0] + ((-778*rp[1] - (rp[2] << 11)) >> 12); + } else { + rp[1] = (rp[1] << 2) + hue; + rp[2] = (rp[2] << 2) + hue; + pix[0] = rp[0] + (( 50*rp[1] + 22929*rp[2]) >> 14); + pix[1] = rp[0] + ((-5640*rp[1] - 11751*rp[2]) >> 14); + pix[2] = rp[0] + ((29040*rp[1] - 101*rp[2]) >> 14); + } +#else + if (unique_id < 0x80000218) { + pix[0] = rp[0] + rp[2] - 512; + pix[2] = rp[0] + rp[1] - 512; + pix[1] = rp[0] + ((-778*rp[1] - (rp[2] << 11)) >> 12) - 512; + } else { + rp[1] = (rp[1] << 2) + hue; + rp[2] = (rp[2] << 2) + hue; + pix[0] = rp[0] + (( 50*rp[1] + 22929*rp[2]) >> 14); + pix[1] = rp[0] + ((-5640*rp[1] - 11751*rp[2]) >> 14); + pix[2] = rp[0] + ((29040*rp[1] - 101*rp[2]) >> 14); + } +#endif + FORC3 + rp[c] = CLIP(pix[c] * sraw_mul[c] >> 10); + } +#ifdef LIBRAW_LIBRARY_BUILD + delete buf; +#endif + ljpeg_end (&jh); + maximum = 0x3fff; +} + +void CLASS adobe_copy_pixel (int row, int col, ushort **rp) +{ + unsigned r, c; + +#ifndef LIBRAW_LIBRARY_BUILD + r = row -= top_margin; + c = col -= left_margin; + if (is_raw == 2 && shot_select) (*rp)++; + if (filters) { + if (fuji_width) { + r = row + fuji_width - 1 - (col >> 1); + c = row + ((col+1) >> 1); + } + if (r < height && c < width) + BAYER(r,c) = **rp < 0x1000 ? curve[**rp] : **rp; + *rp += is_raw; + } else { + if (r < height && c < width) + FORC(tiff_samples) + image[row*width+col][c] = (*rp)[c] < 0x1000 ? curve[(*rp)[c]]:(*rp)[c]; + *rp += tiff_samples; + } +#else + if (is_raw == 2 && shot_select) (*rp)++; + if (filters) { + if(row < raw_height && col < raw_width) + RBAYER(row,col) = **rp < 0x1000 ? curve[**rp] : **rp; + *rp += is_raw; + } else { + if (row < raw_height && col < raw_width) + FORC(tiff_samples) + color_image[row*raw_width+col][c] = (*rp)[c]<0x1000 ? curve[(*rp)[c]]:(*rp)[c]; + *rp += tiff_samples; + } + +#endif + if (is_raw == 2 && shot_select) (*rp)--; + +} + +void CLASS adobe_dng_load_raw_lj() +{ + unsigned save, trow=0, tcol=0, jwide, jrow, jcol, row, col; + struct jhead jh; + ushort *rp; + while (trow < raw_height) { + save = ftell(ifp); + if (tile_length < INT_MAX) + fseek (ifp, get4(), SEEK_SET); + if (!ljpeg_start (&jh, 0)) break; + jwide = jh.wide; + if (filters) jwide *= jh.clrs; + jwide /= is_raw; +#ifdef LIBRAW_LIBRARY_BUILD + if(!data_size) + throw LIBRAW_EXCEPTION_IO_BADFILE; + LibRaw_byte_buffer *buf = ifp->make_byte_buffer(data_size); + LibRaw_bit_buffer bits; +#endif + for (row=col=jrow=0; jrow < jh.high; jrow++) { +#ifdef LIBRAW_LIBRARY_BUILD + rp = ljpeg_row_new (jrow, &jh,bits,buf); +#else + rp = ljpeg_row (jrow, &jh); +#endif + for (jcol=0; jcol < jwide; jcol++) { + adobe_copy_pixel (trow+row, tcol+col, &rp); + if (++col >= tile_width || col >= raw_width) + row += 1 + (col = 0); + } + } + fseek (ifp, save+4, SEEK_SET); + if ((tcol += tile_width) >= raw_width) + trow += tile_length + (tcol = 0); + ljpeg_end (&jh); +#ifdef LIBRAW_LIBRARY_BUILD + delete buf; +#endif + } +} + +void CLASS adobe_dng_load_raw_nc() +{ + ushort *pixel, *rp; + int row, col; + + pixel = (ushort *) calloc (raw_width * tiff_samples, sizeof *pixel); + merror (pixel, "adobe_dng_load_raw_nc()"); + + +#ifdef LIBRAW_LIBRARY_BUILD + int dsz= raw_height*raw_width * tiff_samples * tiff_bps/8; + LibRaw_byte_buffer *buf = NULL; + if (tiff_bps != 16) + { + buf = ifp->make_byte_buffer(dsz); + } + LibRaw_bit_buffer bits; +#endif + + for (row=0; row < raw_height; row++) { + if (tiff_bps == 16) + read_shorts (pixel, raw_width * tiff_samples); + else { +#ifdef LIBRAW_LIBRARY_BUILD + bits.reset(); + for (col=0; col < raw_width * tiff_samples; col++) + pixel[col] = bits._getbits(buf,tiff_bps,zero_after_ff); + +#else + getbits(-1); + for (col=0; col < raw_width * tiff_samples; col++) + pixel[col] = getbits(tiff_bps); +#endif + } + for (rp=pixel, col=0; col < raw_width; col++) + adobe_copy_pixel (row, col, &rp); + } + free (pixel); +#ifdef LIBRAW_LIBRARY_BUILD + if(buf) + delete buf; +#endif +} + +void CLASS pentax_load_raw() +{ + ushort bit[2][15], huff[4097]; + int dep, row, col, diff, c, i; + ushort vpred[2][2] = {{0,0},{0,0}}, hpred[2]; + + fseek (ifp, meta_offset, SEEK_SET); + dep = (get2() + 12) & 15; + fseek (ifp, 12, SEEK_CUR); + FORC(dep) bit[0][c] = get2(); + FORC(dep) bit[1][c] = fgetc(ifp); + FORC(dep) + for (i=bit[0][c]; i <= ((bit[0][c]+(4096 >> bit[1][c])-1) & 4095); ) + huff[++i] = bit[1][c] << 8 | c; + huff[0] = 12; + fseek (ifp, data_offset, SEEK_SET); +#ifdef LIBRAW_LIBRARY_BUILD + if(!data_size) + throw LIBRAW_EXCEPTION_IO_BADFILE; + LibRaw_byte_buffer *buf = ifp->make_byte_buffer(data_size); + LibRaw_bit_buffer bits; + bits.reset(); +#else + getbits(-1); +#endif + for (row=0; row < raw_height; row++) + { + for (col=0; col < raw_width; col++) { +#ifdef LIBRAW_LIBRARY_BUILD + diff = ljpeg_diff_pef(bits,buf,huff); +#else + diff = ljpeg_diff (huff); +#endif + if (col < 2) hpred[col] = vpred[row & 1][col] += diff; + else hpred[col & 1] += diff; + + unsigned val = hpred[col & 1]; + +#ifndef LIBRAW_LIBRARY_BUILD + if ((unsigned) (row-top_margin) < height && + (unsigned)(col-left_margin) < width) + BAYER(row-top_margin,col-left_margin) = val; +#else + RBAYER(row,col) = val; +#endif + if (val >> tiff_bps) derror(); + } + } +#ifdef LIBRAW_LIBRARY_BUILD + delete buf; +#endif +} + +void CLASS nikon_compressed_load_raw() +{ + static const uchar nikon_tree[][32] = { + { 0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0, /* 12-bit lossy */ + 5,4,3,6,2,7,1,0,8,9,11,10,12 }, + { 0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0, /* 12-bit lossy after split */ + 0x39,0x5a,0x38,0x27,0x16,5,4,3,2,1,0,11,12,12 }, + { 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0, /* 12-bit lossless */ + 5,4,6,3,7,2,8,1,9,0,10,11,12 }, + { 0,1,4,3,1,1,1,1,1,2,0,0,0,0,0,0, /* 14-bit lossy */ + 5,6,4,7,8,3,9,2,1,0,10,11,12,13,14 }, + { 0,1,5,1,1,1,1,1,1,1,2,0,0,0,0,0, /* 14-bit lossy after split */ + 8,0x5c,0x4b,0x3a,0x29,7,6,5,4,3,2,1,0,13,14 }, + { 0,1,4,2,2,3,1,2,0,0,0,0,0,0,0,0, /* 14-bit lossless */ + 7,6,8,5,9,4,10,3,11,12,2,0,1,13,14 } }; + ushort *huff, ver0, ver1, vpred[2][2], hpred[2], csize; + int i, min, max, step=0, tree=0, split=0, row, col, len, shl, diff; + + fseek (ifp, meta_offset, SEEK_SET); + ver0 = fgetc(ifp); + ver1 = fgetc(ifp); + if (ver0 == 0x49 || ver1 == 0x58) + fseek (ifp, 2110, SEEK_CUR); + if (ver0 == 0x46) tree = 2; + if (tiff_bps == 14) tree += 3; + read_shorts (vpred[0], 4); + max = 1 << tiff_bps & 0x7fff; + if ((csize = get2()) > 1) + step = max / (csize-1); + if (ver0 == 0x44 && ver1 == 0x20 && step > 0) { + for (i=0; i < csize; i++) + curve[i*step] = get2(); + for (i=0; i < max; i++) + curve[i] = ( curve[i-i%step]*(step-i%step) + + curve[i-i%step+step]*(i%step) ) / step; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.curve_state = LIBRAW_COLORSTATE_LOADED; +#endif + fseek (ifp, meta_offset+562, SEEK_SET); + split = get2(); + } else if (ver0 != 0x46 && csize <= 0x4001) + { + read_shorts (curve, max=csize); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.curve_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + while (curve[max-2] == curve[max-1]) max--; + huff = make_decoder (nikon_tree[tree]); + fseek (ifp, data_offset, SEEK_SET); +#ifdef LIBRAW_LIBRARY_BUILD + if(!data_size) + throw LIBRAW_EXCEPTION_IO_BADFILE; + LibRaw_byte_buffer *buf = ifp->make_byte_buffer(data_size); + LibRaw_bit_buffer bits; + bits.reset(); +#else + getbits(-1); +#endif + for (min=row=0; row < height; row++) { + if (split && row == split) { + free (huff); + huff = make_decoder (nikon_tree[tree+1]); + max += (min = 16) << 1; + } + for (col=0; col < raw_width; col++) { +#ifdef LIBRAW_LIBRARY_BUILD + i = bits._gethuff(buf,*huff,huff+1,zero_after_ff); +#else + i = gethuff(huff); +#endif + len = i & 15; + shl = i >> 4; +#ifdef LIBRAW_LIBRARY_BUILD + diff = ((bits._getbits(buf,len-shl,zero_after_ff) << 1) + 1) << shl >> 1; +#else + diff = ((getbits(len-shl) << 1) + 1) << shl >> 1; +#endif + if ((diff & (1 << (len-1))) == 0) + diff -= (1 << len) - !shl; + if (col < 2) hpred[col] = vpred[row & 1][col] += diff; + else hpred[col & 1] += diff; + if ((ushort)(hpred[col & 1] + min) >= max) derror(); +#ifndef LIBRAW_LIBRARY_BUILD + if ((unsigned) (col-left_margin) < width) + BAYER(row,col-left_margin) = curve[LIM((short)hpred[col & 1],0,0x3fff)]; +#else + ushort xval = hpred[col & 1]; + xval = curve[LIM((short)xval,0,0x3fff)]; + RBAYER(row,col) = xval; +#endif + + } + } +#ifdef LIBRAW_LIBRARY_BUILD + delete buf; +#endif + free (huff); +} + +/* + Figure out if a NEF file is compressed. These fancy heuristics + are only needed for the D100, thanks to a bug in some cameras + that tags all images as "compressed". + */ +int CLASS nikon_is_compressed() +{ + uchar test[256]; + int i; + + fseek (ifp, data_offset, SEEK_SET); + fread (test, 1, 256, ifp); + for (i=15; i < 256; i+=16) + if (test[i]) return 1; + return 0; +} + +/* + Returns 1 for a Coolpix 995, 0 for anything else. + */ +int CLASS nikon_e995() +{ + int i, histo[256]; + const uchar often[] = { 0x00, 0x55, 0xaa, 0xff }; + + memset (histo, 0, sizeof histo); + fseek (ifp, -2000, SEEK_END); + for (i=0; i < 2000; i++) + histo[fgetc(ifp)]++; + for (i=0; i < 4; i++) + if (histo[often[i]] < 200) + return 0; + return 1; +} + +/* + Returns 1 for a Coolpix 2100, 0 for anything else. + */ +int CLASS nikon_e2100() +{ + uchar t[12]; + int i; + + fseek (ifp, 0, SEEK_SET); + for (i=0; i < 1024; i++) { + fread (t, 1, 12, ifp); + if (((t[2] & t[4] & t[7] & t[9]) >> 4 + & t[1] & t[6] & t[8] & t[11] & 3) != 3) + return 0; + } + return 1; +} + +void CLASS nikon_3700() +{ + int bits, i; + uchar dp[24]; + static const struct { + int bits; + char t_make[12], t_model[15]; + } table[] = { + { 0x00, "PENTAX", "Optio 33WR" }, + { 0x03, "NIKON", "E3200" }, + { 0x32, "NIKON", "E3700" }, + { 0x33, "OLYMPUS", "C740UZ" } }; + + fseek (ifp, 3072, SEEK_SET); + fread (dp, 1, 24, ifp); + bits = (dp[8] & 3) << 4 | (dp[20] & 3); + for (i=0; i < sizeof table / sizeof *table; i++) + if (bits == table[i].bits) { + strcpy (make, table[i].t_make ); + strcpy (model, table[i].t_model); + } +} + +/* + Separates a Minolta DiMAGE Z2 from a Nikon E4300. + */ +int CLASS minolta_z2() +{ + int i, nz; + char tail[424]; + + fseek (ifp, -sizeof tail, SEEK_END); + fread (tail, 1, sizeof tail, ifp); + for (nz=i=0; i < sizeof tail; i++) + if (tail[i]) nz++; + return nz > 20; +} + +/* + The Fuji Super CCD is just a Bayer grid rotated 45 degrees. + */ +void CLASS fuji_load_raw() +{ +#ifndef LIBRAW_LIBRARY_BUILD + ushort *pixel; + int wide, row, col, r, c; + + fseek (ifp, (top_margin*raw_width + left_margin) * 2, SEEK_CUR); + wide = fuji_width << !fuji_layout; + pixel = (ushort *) calloc (wide, sizeof *pixel); + merror (pixel, "fuji_load_raw()"); + for (row=0; row < raw_height; row++) { + read_shorts (pixel, wide); + fseek (ifp, 2*(raw_width - wide), SEEK_CUR); + for (col=0; col < wide; col++) { + if (fuji_layout) { + r = fuji_width - 1 - col + (row >> 1); + c = col + ((row+1) >> 1); + } else { + r = fuji_width - 1 + row - (col >> 1); + c = row + ((col+1) >> 1); + } + BAYER(r,c) = pixel[col]; + } + } + free (pixel); +#else + read_shorts(raw_image,raw_width*raw_height); +#endif +} +void CLASS ppm_thumb() +{ + char *thumb; + thumb_length = thumb_width*thumb_height*3; + thumb = (char *) malloc (thumb_length); + merror (thumb, "ppm_thumb()"); + fprintf (ofp, "P6\n%d %d\n255\n", thumb_width, thumb_height); + fread (thumb, 1, thumb_length, ifp); + fwrite (thumb, 1, thumb_length, ofp); + free (thumb); +} + +void CLASS layer_thumb() +{ + int i, c; + char *thumb, map[][4] = { "012","102" }; + + colors = thumb_misc >> 5 & 7; + thumb_length = thumb_width*thumb_height; + thumb = (char *) calloc (colors, thumb_length); + merror (thumb, "layer_thumb()"); + fprintf (ofp, "P%d\n%d %d\n255\n", + 5 + (colors >> 1), thumb_width, thumb_height); + fread (thumb, thumb_length, colors, ifp); + for (i=0; i < thumb_length; i++) + FORCC putc (thumb[i+thumb_length*(map[thumb_misc >> 8][c]-'0')], ofp); + free (thumb); +} + +void CLASS rollei_thumb() +{ + unsigned i; + ushort *thumb; + + thumb_length = thumb_width * thumb_height; + thumb = (ushort *) calloc (thumb_length, 2); + merror (thumb, "rollei_thumb()"); + fprintf (ofp, "P6\n%d %d\n255\n", thumb_width, thumb_height); + read_shorts (thumb, thumb_length); + for (i=0; i < thumb_length; i++) { + putc (thumb[i] << 3, ofp); + putc (thumb[i] >> 5 << 2, ofp); + putc (thumb[i] >> 11 << 3, ofp); + } + free (thumb); +} + +void CLASS rollei_load_raw() +{ + uchar pixel[10]; + unsigned iten=0, isix, i, buffer=0, row, col, todo[16]; + + isix = raw_width * raw_height * 5 / 8; + while (fread (pixel, 1, 10, ifp) == 10) { + for (i=0; i < 10; i+=2) { + todo[i] = iten++; + todo[i+1] = pixel[i] << 8 | pixel[i+1]; + buffer = pixel[i] >> 2 | buffer << 6; + } + for ( ; i < 16; i+=2) { + todo[i] = isix++; + todo[i+1] = buffer >> (14-i)*5; + } + for (i=0; i < 16; i+=2) { +#ifndef LIBRAW_LIBRARY_BUILD + row = todo[i] / raw_width - top_margin; + col = todo[i] % raw_width - left_margin; + if (row < height && col < width) + BAYER(row,col) = (todo[i+1] & 0x3ff); +#else + RBAYER(todo[i] / raw_width,todo[i] % raw_width) = (todo[i+1] & 0x3ff); +#endif + } + } + maximum = 0x3ff; +} + +int CLASS bayer (unsigned row, unsigned col) +{ + return (row < height && col < width) ? BAYER(row,col) : 0; +} + +void CLASS phase_one_flat_field (int is_float, int nc) +{ + ushort head[8]; + unsigned wide, y, x, c, rend, cend, row, col; + float *mrow, num, mult[4]; + + read_shorts (head, 8); + wide = head[2] / head[4]; + mrow = (float *) calloc (nc*wide, sizeof *mrow); + merror (mrow, "phase_one_flat_field()"); + for (y=0; y < head[3] / head[5]; y++) { + for (x=0; x < wide; x++) + for (c=0; c < nc; c+=2) { + num = is_float ? getreal(11) : get2()/32768.0; + if (y==0) mrow[c*wide+x] = num; + else mrow[(c+1)*wide+x] = (num - mrow[c*wide+x]) / head[5]; + } + if (y==0) continue; + rend = head[1]-top_margin + y*head[5]; + for (row = rend-head[5]; row < height && row < rend; row++) { + for (x=1; x < wide; x++) { + for (c=0; c < nc; c+=2) { + mult[c] = mrow[c*wide+x-1]; + mult[c+1] = (mrow[c*wide+x] - mult[c]) / head[4]; + } + cend = head[0]-left_margin + x*head[4]; + for (col = cend-head[4]; col < width && col < cend; col++) { + c = nc > 2 ? FC(row,col) : 0; + if (!(c & 1)) { + c = BAYER(row,col) * mult[c]; + BAYER(row,col) = LIM(c,0,65535); + } + for (c=0; c < nc; c+=2) + mult[c] += mult[c+1]; + } + } + for (x=0; x < wide; x++) + for (c=0; c < nc; c+=2) + mrow[c*wide+x] += mrow[(c+1)*wide+x]; + } + } + free (mrow); +} + +void CLASS phase_one_correct() +{ + unsigned entries, tag, data, save, col, row, type; + int len, i, j, k, cip, val[4], dev[4], sum, max; + int head[9], diff, mindiff=INT_MAX, off_412=0; + static const signed char dir[12][2] = + { {-1,-1}, {-1,1}, {1,-1}, {1,1}, {-2,0}, {0,-2}, {0,2}, {2,0}, + {-2,-2}, {-2,2}, {2,-2}, {2,2} }; + float poly[8], num, cfrac, frac, mult[2], *yval[2]; + ushort *xval[2]; + + if (half_size || !meta_length) return; +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("Phase One correction...\n")); +#endif + fseek (ifp, meta_offset, SEEK_SET); + order = get2(); + fseek (ifp, 6, SEEK_CUR); + fseek (ifp, meta_offset+get4(), SEEK_SET); + entries = get4(); get4(); + while (entries--) { + tag = get4(); + len = get4(); + data = get4(); + save = ftell(ifp); + fseek (ifp, meta_offset+data, SEEK_SET); + if (tag == 0x419) { /* Polynomial curve */ + for (get4(), i=0; i < 8; i++) + poly[i] = getreal(11); + poly[3] += (ph1.tag_210 - poly[7]) * poly[6] + 1; + for (i=0; i < 0x10000; i++) { + num = (poly[5]*i + poly[3])*i + poly[1]; + curve[i] = LIM(num,0,65535); + } goto apply; /* apply to right half */ + } else if (tag == 0x41a) { /* Polynomial curve */ + for (i=0; i < 4; i++) + poly[i] = getreal(11); + for (i=0; i < 0x10000; i++) { + for (num=0, j=4; j--; ) + num = num * i + poly[j]; + curve[i] = LIM(num+i,0,65535); + } apply: /* apply to whole image */ + for (row=0; row < height; row++) + for (col = (tag & 1)*ph1.split_col; col < width; col++) + BAYER(row,col) = curve[BAYER(row,col)]; + } else if (tag == 0x400) { /* Sensor defects */ + while ((len -= 8) >= 0) { + col = get2() - left_margin; + row = get2() - top_margin; + type = get2(); get2(); + if (col >= width) continue; + if (type == 131) /* Bad column */ + for (row=0; row < height; row++) + if (FC(row,col) == 1) { + for (sum=i=0; i < 4; i++) + sum += val[i] = bayer (row+dir[i][0], col+dir[i][1]); + for (max=i=0; i < 4; i++) { + dev[i] = abs((val[i] << 2) - sum); + if (dev[max] < dev[i]) max = i; + } + BAYER(row,col) = (sum - val[max])/3.0 + 0.5; + } else { + for (sum=0, i=8; i < 12; i++) + sum += bayer (row+dir[i][0], col+dir[i][1]); + BAYER(row,col) = 0.5 + sum * 0.0732233 + + (bayer(row,col-2) + bayer(row,col+2)) * 0.3535534; + } + else if (type == 129) { /* Bad pixel */ + if (row >= height) continue; + j = (FC(row,col) != 1) * 4; + for (sum=0, i=j; i < j+8; i++) + sum += bayer (row+dir[i][0], col+dir[i][1]); + BAYER(row,col) = (sum + 4) >> 3; + } + } + } else if (tag == 0x401) { /* All-color flat fields */ + phase_one_flat_field (1, 2); + } else if (tag == 0x416 || tag == 0x410) { + phase_one_flat_field (0, 2); + } else if (tag == 0x40b) { /* Red+blue flat field */ + phase_one_flat_field (0, 4); + } else if (tag == 0x412) { + fseek (ifp, 36, SEEK_CUR); + diff = abs (get2() - ph1.tag_21a); + if (mindiff > diff) { + mindiff = diff; + off_412 = ftell(ifp) - 38; + } + } + fseek (ifp, save, SEEK_SET); + } + if (off_412) { + fseek (ifp, off_412, SEEK_SET); + for (i=0; i < 9; i++) head[i] = get4() & 0x7fff; + yval[0] = (float *) calloc (head[1]*head[3] + head[2]*head[4], 6); + merror (yval[0], "phase_one_correct()"); + yval[1] = (float *) (yval[0] + head[1]*head[3]); + xval[0] = (ushort *) (yval[1] + head[2]*head[4]); + xval[1] = (ushort *) (xval[0] + head[1]*head[3]); + get2(); + for (i=0; i < 2; i++) + for (j=0; j < head[i+1]*head[i+3]; j++) + yval[i][j] = getreal(11); + for (i=0; i < 2; i++) + for (j=0; j < head[i+1]*head[i+3]; j++) + xval[i][j] = get2(); + for (row=0; row < height; row++) + for (col=0; col < width; col++) { + cfrac = (float) col * head[3] / raw_width; + cfrac -= cip = cfrac; + num = BAYER(row,col) * 0.5; + for (i=cip; i < cip+2; i++) { + for (k=j=0; j < head[1]; j++) + if (num < xval[0][k = head[1]*i+j]) break; + frac = (j == 0 || j == head[1]) ? 0 : + (xval[0][k] - num) / (xval[0][k] - xval[0][k-1]); + mult[i-cip] = yval[0][k-1] * frac + yval[0][k] * (1-frac); + } + i = ((mult[0] * (1-cfrac) + mult[1] * cfrac) + * (row + top_margin) + num) * 2; + BAYER(row,col) = LIM(i,0,65535); + } + free (yval[0]); + } +} + +void CLASS phase_one_load_raw() +{ + int row, col, a, b; + ushort *pixel, akey, bkey, mask; + + fseek (ifp, ph1.key_off, SEEK_SET); + akey = get2(); + bkey = get2(); + mask = ph1.format == 1 ? 0x5555:0x1354; +#ifndef LIBRAW_LIBRARY_BUILD + fseek (ifp, data_offset + top_margin*raw_width*2, SEEK_SET); + pixel = (ushort *) calloc (raw_width, sizeof *pixel); + merror (pixel, "phase_one_load_raw()"); + for (row=0; row < height; row++) { + read_shorts (pixel, raw_width); + if (ph1.format) + for (col=0; col < raw_width; col+=2) { + a = pixel[col+0] ^ akey; + b = pixel[col+1] ^ bkey; + pixel[col+0] = (a & mask) | (b & ~mask); + pixel[col+1] = (b & mask) | (a & ~mask); + } + for (col=0; col < width; col++) + BAYER(row,col) = pixel[col+left_margin]; + } + free (pixel); + phase_one_correct(); +#else + fseek (ifp, data_offset, SEEK_SET); + pixel = (ushort *) calloc (raw_width, sizeof *pixel); + merror (pixel, "phase_one_load_raw()"); + for (row=0; row < raw_height; row++) { + read_shorts (pixel, raw_width); + if (ph1.format) + for (col=0; col < raw_width; col+=2) { + a = pixel[col+0] ^ akey; + b = pixel[col+1] ^ bkey; + pixel[col+0] = (a & mask) | (b & ~mask); + pixel[col+1] = (b & mask) | (a & ~mask); + } + memmove(&raw_image[row*raw_width],pixel,raw_width*sizeof(pixel[0])); + } + free (pixel); + // use correct on postprocessing! + imgdata.rawdata.use_ph1_correct=1; +#endif +} + +unsigned CLASS ph1_bithuff (int nbits, ushort *huff) +{ +#ifndef LIBRAW_NOTHREADS +#define bitbuf tls->ph1_bits.bitbuf +#define vbits tls->ph1_bits.vbits +#else + static UINT64 bitbuf=0; + static int vbits=0; +#endif + unsigned c; + + if (nbits == -1) + return bitbuf = vbits = 0; + if (nbits == 0) return 0; + if (vbits < nbits) { + bitbuf = bitbuf << 32 | get4(); + vbits += 32; + } + c = bitbuf << (64-vbits) >> (64-nbits); + if (huff) { + vbits -= huff[c] >> 8; + return (uchar) huff[c]; + } + vbits -= nbits; + return c; +#ifndef LIBRAW_NOTHREADS +#undef bitbuf +#undef vbits +#endif +} +#define ph1_bits(n) ph1_bithuff(n,0) +#define ph1_huff(h) ph1_bithuff(*h,h+1) + +void CLASS phase_one_load_raw_c() +{ + static const int length[] = { 8,7,6,9,11,10,5,12,14,13 }; + int *offset, len[2], pred[2], row, col, i, j; + ushort *pixel; + short (*t_black)[2]; + + pixel = (ushort *) calloc (raw_width + raw_height*4, 2); + merror (pixel, "phase_one_load_raw_c()"); + offset = (int *) (pixel + raw_width); + fseek (ifp, strip_offset, SEEK_SET); + for (row=0; row < raw_height; row++) + offset[row] = get4(); + t_black = (short (*)[2]) offset + raw_height; + fseek (ifp, ph1.black_off, SEEK_SET); + if (ph1.black_off) + { + read_shorts ((ushort *) t_black[0], raw_height*2); +#ifdef LIBRAW_LIBRARY_BUILD + imgdata.rawdata.ph1_black = (short (*)[2])calloc(raw_height*2,sizeof(short)); + merror (imgdata.rawdata.ph1_black, "phase_one_load_raw_c()"); + memmove(imgdata.rawdata.ph1_black,(short *) t_black[0],raw_height*2*sizeof(short)); +#endif + } + for (i=0; i < 256; i++) + curve[i] = i*i / 3.969 + 0.5; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.curve_state = LIBRAW_COLORSTATE_CALCULATED; +#endif + for (row=0; row < raw_height; row++) { + fseek (ifp, data_offset + offset[row], SEEK_SET); + ph1_bits(-1); + pred[0] = pred[1] = 0; + for (col=0; col < raw_width; col++) { + if (col >= (raw_width & -8)) + len[0] = len[1] = 14; + else if ((col & 7) == 0) + for (i=0; i < 2; i++) { + for (j=0; j < 5 && !ph1_bits(1); j++); + if (j--) len[i] = length[j*2 + ph1_bits(1)]; + } + if ((i = len[col & 1]) == 14) + pixel[col] = pred[col & 1] = ph1_bits(16); + else + pixel[col] = pred[col & 1] += ph1_bits(i) + 1 - (1 << (i - 1)); + if (pred[col & 1] >> 16) derror(); + if (ph1.format == 5 && pixel[col] < 256) + pixel[col] = curve[pixel[col]]; + } +#ifndef LIBRAW_LIBRARY_BUILD + if ((unsigned) (row-top_margin) < height) + for (col=0; col < width; col++) { + i = (pixel[col+left_margin] << 2) + - ph1.t_black + t_black[row][col >= ph1.split_col]; + if (i > 0) BAYER(row-top_margin,col) = i; + } +#else + for (col=0; col < raw_width; col++) + { + i = (pixel[col] << 2); + RBAYER(row,col) = i; + } +#endif + } + free (pixel); +#ifndef LIBRAW_LIBRARY_BUILD + phase_one_correct(); + maximum = 0xfffc - ph1.t_black; +#else + maximum = 0xfffc; + black = ph1.t_black; +#endif +} + +void CLASS hasselblad_load_raw() +{ + struct jhead jh; + int row, col, pred[2], len[2], diff, c; + + if (!ljpeg_start (&jh, 0)) return; + order = 0x4949; + ph1_bits(-1); +#ifndef LIBRAW_LIBRARY_BUILD + for (row=-top_margin; row < height; row++) { + pred[0] = pred[1] = 0x8000 + load_flags; + for (col=-left_margin; col < raw_width-left_margin; col+=2) { + FORC(2) len[c] = ph1_huff(jh.huff[0]); + FORC(2) { + diff = ph1_bits(len[c]); + if ((diff & (1 << (len[c]-1))) == 0) + diff -= (1 << len[c]) - 1; + if (diff == 65535) diff = -32768; + pred[c] += diff; + if (row >= 0 && (unsigned)(col+c) < width) + BAYER(row,col+c) = pred[c]; + } + } + } +#else + for (row=0; row < raw_height; row++) { + pred[0] = pred[1] = 0x8000 + load_flags; + for (col=0; col < raw_width; col+=2) { + FORC(2) len[c] = ph1_huff(jh.huff[0]); + FORC(2) { + diff = ph1_bits(len[c]); + if ((diff & (1 << (len[c]-1))) == 0) + diff -= (1 << len[c]) - 1; + if (diff == 65535) diff = -32768; + pred[c] += diff; + RBAYER(row,col+c) = pred[c]; + } + } + } + +#endif + ljpeg_end (&jh); + maximum = 0xffff; +} + +void CLASS leaf_hdr_load_raw() +{ + ushort *pixel; + unsigned tile=0, r, c, row, col; + + pixel = (ushort *) calloc (raw_width, sizeof *pixel); + merror (pixel, "leaf_hdr_load_raw()"); + FORC(tiff_samples) + for (r=0; r < raw_height; r++) { + if (r % tile_length == 0) { + fseek (ifp, data_offset + 4*tile++, SEEK_SET); + fseek (ifp, get4() + 2*left_margin, SEEK_SET); + } + if (filters && c != shot_select) continue; + read_shorts (pixel, raw_width); +#ifndef LIBRAW_LIBRARY_BUILD + if ((row = r - top_margin) >= height) continue; + for (col=0; col < width; col++) + if (filters) BAYER(row,col) = pixel[col]; + else image[row*width+col][c] = pixel[col]; +#else + if(filters) + memmove(&raw_image[r*raw_width],pixel,raw_width*sizeof(pixel[0])); + else + for (col=0; col < raw_width; col++) + color_image[r*raw_width+col][c] = pixel[col]; +#endif + } + free (pixel); + if (!filters) { + maximum = 0xffff; + raw_color = 1; + } +} + +void CLASS sinar_4shot_load_raw() +{ + ushort *pixel; + unsigned shot, row, col, r, c; + + if ((shot = shot_select) || half_size) { + if (shot) shot--; + if (shot > 3) shot = 3; + fseek (ifp, data_offset + shot*4, SEEK_SET); + fseek (ifp, get4(), SEEK_SET); + unpacked_load_raw(); + return; + } + free (image); + image = (ushort (*)[4]) + calloc ((iheight=height)*(iwidth=width), sizeof *image); + merror (image, "sinar_4shot_load_raw()"); + pixel = (ushort *) calloc (raw_width, sizeof *pixel); + merror (pixel, "sinar_4shot_load_raw()"); + for (shot=0; shot < 4; shot++) { + fseek (ifp, data_offset + shot*4, SEEK_SET); + fseek (ifp, get4(), SEEK_SET); +#ifndef LIBRAW_LIBRARY_BUILD + for (row=0; row < raw_height; row++) { + read_shorts (pixel, raw_width); + if ((r = row-top_margin - (shot >> 1 & 1)) >= height) continue; + for (col=0; col < raw_width; col++) { + if ((c = col-left_margin - (shot & 1)) >= width) continue; + image[r*width+c][FC(row,col)] = pixel[col]; + } + } +#else + for (row=0; row < raw_height; row++) { + read_shorts (pixel, raw_width); + if ((r = row - (shot >> 1 & 1)) >= raw_height) continue; + for (col=0; col < raw_width; col++) { + if ((c = col- (shot & 1)) >= raw_width) continue; + color_image[r*width+c][FC(row,col)] = pixel[col]; + } + } +#endif + } + free (pixel); + shrink = filters = 0; +} + +void CLASS imacon_full_load_raw() +{ + int row, col; + +#ifndef LIBRAW_LIBRARY_BUILD + for (row=0; row < height; row++) + for (col=0; col < width; col++) + { + read_shorts (image[row*width+col], 3); + } +#else + for (row=0; row < height; row++) + for (col=0; col < width; col++) + { + read_shorts (color_image[(row+top_margin)*raw_width+col+left_margin], 3); + } +#endif +} + +void CLASS packed_load_raw() +{ + int vbits=0, bwide, pwide, rbits, bite, half, irow, row, col, val, i; + int zero=0; + UINT64 bitbuf=0; + + if (raw_width * 8 >= width * tiff_bps) /* Is raw_width in bytes? */ + pwide = (bwide = raw_width) * 8 / tiff_bps; + else bwide = (pwide = raw_width) * tiff_bps / 8; + rbits = bwide * 8 - pwide * tiff_bps; + if (load_flags & 1) bwide = bwide * 16 / 15; + fseek (ifp, top_margin*bwide, SEEK_CUR); + bite = 8 + (load_flags & 24); + half = (height+1) >> 1; + for (irow=0; irow < height; irow++) + { + row = irow; + if (load_flags & 2 && + (row = irow % half * 2 + irow / half) == 1 && + load_flags & 4) { + if (vbits=0, tiff_compress) + fseek (ifp, data_offset - (-half*bwide & -2048), SEEK_SET); + else { + fseek (ifp, 0, SEEK_END); + fseek (ifp, ftell(ifp) >> 3 << 2, SEEK_SET); + } + } + for (col=0; col < pwide; col++) { + for (vbits -= tiff_bps; vbits < 0; vbits += bite) { + bitbuf <<= bite; + for (i=0; i < bite; i+=8) + bitbuf |= (unsigned) (fgetc(ifp) << i); + } + val = bitbuf << (64-tiff_bps-vbits) >> (64-tiff_bps); + i = (col ^ (load_flags >> 6)) - left_margin; +#ifdef LIBRAW_LIBRARY_BUILD + RBAYER(row+top_margin,i+left_margin) = val; + if (((unsigned)i>=width) && (load_flags & 32) ) { + black += val; + zero += !val; + } +#else + if ((unsigned) i < width) + BAYER(row,i+left_margin) = val; + else if (load_flags & 32) { + black += val; + zero += !val; + } +#endif + if (load_flags & 1 && (col % 10) == 9 && + fgetc(ifp) && col < width+left_margin) derror(); + } + vbits -= rbits; + } + if (load_flags & 32 && pwide > width) + black /= (pwide - width) * height; + if (zero*4 > (pwide - width) * height) + black = 0; +} + +void CLASS unpacked_load_raw() +{ + ushort *pixel; + int row, col, bits=0; + + while (1 << ++bits < maximum); +#ifndef LIBRAW_LIBRARY_BUILD + fseek (ifp, (top_margin*raw_width + left_margin) * 2, SEEK_CUR); + pixel = (ushort *) calloc (width, sizeof *pixel); + merror (pixel, "unpacked_load_raw()"); + for (row=0; row < height; row++) { + read_shorts (pixel, width); + fseek (ifp, 2*(raw_width - width), SEEK_CUR); + for (col=0; col < width; col++) + if ((BAYER2(row,col) = pixel[col] >> load_flags) >> bits) derror(); + } + free (pixel); +#else + // fseek (ifp, (top_margin*raw_width + left_margin) * 2, SEEK_CUR); + pixel = (ushort *) calloc (raw_width, sizeof *pixel); + merror (pixel, "unpacked_load_raw()"); + for (row=0; row < raw_height; row++) { + read_shorts (pixel, raw_width); + for (col=0; col < raw_width; col++) + { + RBAYER(row,col) = pixel[col]>>load_flags; + if( ((unsigned)(row-top_margin) < height) + && ((unsigned)(col-left_margin)>bits) + derror(); + } + } + free (pixel); +#endif +} + +void CLASS nokia_load_raw() +{ + uchar *data, *dp; + ushort *pixel, *pix; + int rev, dwide, row, c; + + rev = 3 * (order == 0x4949); + dwide = raw_width * 5 / 4; + data = (uchar *) malloc (dwide + raw_width*2); + merror (data, "nokia_load_raw()"); + pixel = (ushort *) (data + dwide); + for (row=0; row < raw_height; row++) { + if (fread (data+dwide, 1, dwide, ifp) < dwide) derror(); + FORC(dwide) data[c] = data[dwide+(c ^ rev)]; + for (dp=data, pix=pixel; pix < pixel+raw_width; dp+=5, pix+=4) + FORC4 pix[c] = (dp[c] << 2) | (dp[4] >> (c << 1) & 3); + if (row < top_margin) + FORC(width) black += pixel[c]; +#ifndef LIBRAW_LIBRARY_BUILD + else + FORC(width) BAYER(row-top_margin,c) = pixel[c]; +#else + memmove(&raw_image[row*raw_width],pixel,width*sizeof(pixel[0])); +#endif + } + free (data); + if (top_margin) black /= top_margin * width; + maximum = 0x3ff; +} + +unsigned CLASS pana_bits (int nbits) +{ +#ifndef LIBRAW_NOTHREADS +#define buf tls->pana_bits.buf +#define vbits tls->pana_bits.vbits +#else + static uchar buf[0x4000]; + static int vbits; +#endif + int byte; + + if (!nbits) return vbits=0; + if (!vbits) { + fread (buf+load_flags, 1, 0x4000-load_flags, ifp); + fread (buf, 1, load_flags, ifp); + } + vbits = (vbits - nbits) & 0x1ffff; + byte = vbits >> 3 ^ 0x3ff0; + return (buf[byte] | buf[byte+1] << 8) >> (vbits & 7) & ~(-1 << nbits); +#ifndef LIBRAW_NOTHREADS +#undef buf +#undef vbits +#endif +} + +void CLASS panasonic_load_raw() +{ + int row, col, i, j, sh=0, pred[2], nonz[2]; + + pana_bits(0); + for (row=0; row < height; row++) + for (col=0; col < raw_width; col++) { + if ((i = col % 14) == 0) + pred[0] = pred[1] = nonz[0] = nonz[1] = 0; + if (i % 3 == 2) sh = 4 >> (3 - pana_bits(2)); + if (nonz[i & 1]) { + if ((j = pana_bits(8))) { + if ((pred[i & 1] -= 0x80 << sh) < 0 || sh == 4) + pred[i & 1] &= ~(-1 << sh); + pred[i & 1] += j << sh; + } + } else if ((nonz[i & 1] = pana_bits(8)) || i > 11) + pred[i & 1] = nonz[i & 1] << 4 | pana_bits(4); +#ifndef LIBRAW_LIBRARY_BUILD + if (col < width) + if ((BAYER(row,col) = pred[col & 1]) > 4098) derror(); +#else + RBAYER(row,col) = pred[col & 1]; + if (col < width) + if (RBAYER(row,col) > 4098) derror(); +#endif + } +} + + +void CLASS olympus_load_raw() +{ + ushort huff[4096]; + int row, col, nbits, sign, low, high, i, c, w, n, nw; + int acarry[2][3], *carry, pred, diff; + + huff[n=0] = 0xc0c; + for (i=12; i--; ) + FORC(2048 >> i) huff[++n] = (i+1) << 8 | i; + fseek (ifp, 7, SEEK_CUR); +#ifdef LIBRAW_LIBRARY_BUILD + if(!data_size) + throw LIBRAW_EXCEPTION_IO_BADFILE; + LibRaw_byte_buffer *buf = ifp->make_byte_buffer(data_size); + LibRaw_bit_buffer bits; + bits.reset(); +#else + getbits(-1); +#endif + for (row=0; row < height; row++) { + memset (acarry, 0, sizeof acarry); + for (col=0; col < raw_width; col++) { + carry = acarry[col & 1]; + i = 2 * (carry[2] < 3); + for (nbits=2+i; (ushort) carry[0] >> (nbits+i); nbits++); +#ifdef LIBRAW_LIBRARY_BUILD + low = (sign = bits._getbits(buf,3,zero_after_ff)) & 3; + sign = sign << 29 >> 31; + if ((high = bits._gethuff(buf,12,huff,zero_after_ff)) == 12) + high = bits._getbits(buf,16-nbits,zero_after_ff) >> 1; + carry[0] = (high << nbits) | bits._getbits(buf,nbits,zero_after_ff); +#else + low = (sign = getbits(3)) & 3; + sign = sign << 29 >> 31; + if ((high = getbithuff(12,huff)) == 12) + high = getbits(16-nbits) >> 1; + carry[0] = (high << nbits) | getbits(nbits); +#endif + diff = (carry[0] ^ sign) + carry[1]; + carry[1] = (diff*3 + carry[1]) >> 5; + carry[2] = carry[0] > 16 ? 0 : carry[2]+1; + if (col >= width) continue; + if (row < 2 && col < 2) pred = 0; + else if (row < 2) pred = RBAYER(row,col-2); + else if (col < 2) pred = RBAYER(row-2,col); + else { + w = RBAYER(row,col-2); + n = RBAYER(row-2,col); + nw = RBAYER(row-2,col-2); + if ((w < nw && nw < n) || (n < nw && nw < w)) { + if (ABS(w-nw) > 32 || ABS(n-nw) > 32) + pred = w + n - nw; + else pred = (w + n) >> 1; + } else pred = ABS(w-nw) > ABS(n-nw) ? w : n; + } + if ((RBAYER(row,col) = pred + ((diff << 2) | low)) >> 12) derror(); + } + } +#ifdef LIBRAW_LIBRARY_BUILD + delete buf; +#endif +} + + +void CLASS minolta_rd175_load_raw() +{ + uchar pixel[768]; + unsigned irow, box, row, col; + + for (irow=0; irow < 1481; irow++) { + if (fread (pixel, 1, 768, ifp) < 768) derror(); + box = irow / 82; + row = irow % 82 * 12 + ((box < 12) ? box | 1 : (box-12)*2); + switch (irow) { + case 1477: case 1479: continue; + case 1476: row = 984; break; + case 1480: row = 985; break; + case 1478: row = 985; box = 1; + } + if ((box < 12) && (box & 1)) { + for (col=0; col < 1533; col++, row ^= 1) + if (col != 1) RRBAYER(row,col) = (col+1) & 2 ? + pixel[col/2-1] + pixel[col/2+1] : pixel[col/2] << 1; + RRBAYER(row,1) = pixel[1] << 1; + RRBAYER(row,1533) = pixel[765] << 1; + } else + for (col=row & 1; col < 1534; col+=2) + RRBAYER(row,col) = pixel[col/2] << 1; + } + maximum = 0xff << 1; +} + +void CLASS quicktake_100_load_raw() +{ + uchar pixel[484][644]; + static const short gstep[16] = + { -89,-60,-44,-32,-22,-15,-8,-2,2,8,15,22,32,44,60,89 }; + static const short rstep[6][4] = + { { -3,-1,1,3 }, { -5,-1,1,5 }, { -8,-2,2,8 }, + { -13,-3,3,13 }, { -19,-4,4,19 }, { -28,-6,6,28 } }; + static const short t_curve[256] = + { 0,1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27, + 28,29,30,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,53, + 54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,74,75,76,77,78, + 79,80,81,82,83,84,86,88,90,92,94,97,99,101,103,105,107,110,112,114,116, + 118,120,123,125,127,129,131,134,136,138,140,142,144,147,149,151,153,155, + 158,160,162,164,166,168,171,173,175,177,179,181,184,186,188,190,192,195, + 197,199,201,203,205,208,210,212,214,216,218,221,223,226,230,235,239,244, + 248,252,257,261,265,270,274,278,283,287,291,296,300,305,309,313,318,322, + 326,331,335,339,344,348,352,357,361,365,370,374,379,383,387,392,396,400, + 405,409,413,418,422,426,431,435,440,444,448,453,457,461,466,470,474,479, + 483,487,492,496,500,508,519,531,542,553,564,575,587,598,609,620,631,643, + 654,665,676,687,698,710,721,732,743,754,766,777,788,799,810,822,833,844, + 855,866,878,889,900,911,922,933,945,956,967,978,989,1001,1012,1023 }; + int rb, row, col, sharp, val=0; + + getbits(-1); + memset (pixel, 0x80, sizeof pixel); + for (row=2; row < height+2; row++) { + for (col=2+(row & 1); col < width+2; col+=2) { + val = ((pixel[row-1][col-1] + 2*pixel[row-1][col+1] + + pixel[row][col-2]) >> 2) + gstep[getbits(4)]; + pixel[row][col] = val = LIM(val,0,255); + if (col < 4) + pixel[row][col-2] = pixel[row+1][~row & 1] = val; + if (row == 2) + pixel[row-1][col+1] = pixel[row-1][col+3] = val; + } + pixel[row][col] = val; + } + for (rb=0; rb < 2; rb++) + for (row=2+rb; row < height+2; row+=2) + for (col=3-(row & 1); col < width+2; col+=2) { + if (row < 4 || col < 4) sharp = 2; + else { + val = ABS(pixel[row-2][col] - pixel[row][col-2]) + + ABS(pixel[row-2][col] - pixel[row-2][col-2]) + + ABS(pixel[row][col-2] - pixel[row-2][col-2]); + sharp = val < 4 ? 0 : val < 8 ? 1 : val < 16 ? 2 : + val < 32 ? 3 : val < 48 ? 4 : 5; + } + val = ((pixel[row-2][col] + pixel[row][col-2]) >> 1) + + rstep[sharp][getbits(2)]; + pixel[row][col] = val = LIM(val,0,255); + if (row < 4) pixel[row-2][col+2] = val; + if (col < 4) pixel[row+2][col-2] = val; + } + for (row=2; row < height+2; row++) + for (col=3-(row & 1); col < width+2; col+=2) { + val = ((pixel[row][col-1] + (pixel[row][col] << 2) + + pixel[row][col+1]) >> 1) - 0x100; + pixel[row][col] = LIM(val,0,255); + } + for (row=0; row < height; row++) + for (col=0; col < width; col++) + RBAYER(row,col) = t_curve[pixel[row+2][col+2]]; + maximum = 0x3ff; +} + +#define radc_token(tree) ((signed char) getbithuff(8,huff[tree])) + +#define FORYX for (y=1; y < 3; y++) for (x=col+1; x >= col; x--) + +#define PREDICTOR (c ? (buf[c][y-1][x] + buf[c][y][x+1]) / 2 \ +: (buf[c][y-1][x+1] + 2*buf[c][y-1][x] + buf[c][y][x+1]) / 4) + +void CLASS kodak_radc_load_raw() +{ + static const char src[] = { + 1,1, 2,3, 3,4, 4,2, 5,7, 6,5, 7,6, 7,8, + 1,0, 2,1, 3,3, 4,4, 5,2, 6,7, 7,6, 8,5, 8,8, + 2,1, 2,3, 3,0, 3,2, 3,4, 4,6, 5,5, 6,7, 6,8, + 2,0, 2,1, 2,3, 3,2, 4,4, 5,6, 6,7, 7,5, 7,8, + 2,1, 2,4, 3,0, 3,2, 3,3, 4,7, 5,5, 6,6, 6,8, + 2,3, 3,1, 3,2, 3,4, 3,5, 3,6, 4,7, 5,0, 5,8, + 2,3, 2,6, 3,0, 3,1, 4,4, 4,5, 4,7, 5,2, 5,8, + 2,4, 2,7, 3,3, 3,6, 4,1, 4,2, 4,5, 5,0, 5,8, + 2,6, 3,1, 3,3, 3,5, 3,7, 3,8, 4,0, 5,2, 5,4, + 2,0, 2,1, 3,2, 3,3, 4,4, 4,5, 5,6, 5,7, 4,8, + 1,0, 2,2, 2,-2, + 1,-3, 1,3, + 2,-17, 2,-5, 2,5, 2,17, + 2,-7, 2,2, 2,9, 2,18, + 2,-18, 2,-9, 2,-2, 2,7, + 2,-28, 2,28, 3,-49, 3,-9, 3,9, 4,49, 5,-79, 5,79, + 2,-1, 2,13, 2,26, 3,39, 4,-16, 5,55, 6,-37, 6,76, + 2,-26, 2,-13, 2,1, 3,-39, 4,16, 5,-55, 6,-76, 6,37 + }; + ushort huff[19][256]; + int row, col, tree, nreps, rep, step, i, c, s, r, x, y, val; + short last[3] = { 16,16,16 }, mul[3], buf[3][3][386]; + static const ushort pt[] = + { 0,0, 1280,1344, 2320,3616, 3328,8000, 4095,16383, 65535,16383 }; + + for (i=2; i < 12; i+=2) + for (c=pt[i-2]; c <= pt[i]; c++) + curve[c] = (float) + (c-pt[i-2]) / (pt[i]-pt[i-2]) * (pt[i+1]-pt[i-1]) + pt[i-1] + 0.5; + for (s=i=0; i < sizeof src; i+=2) + FORC(256 >> src[i]) + huff[0][s++] = src[i] << 8 | (uchar) src[i+1]; + s = kodak_cbpp == 243 ? 2 : 3; + FORC(256) huff[18][c] = (8-s) << 8 | c >> s << s | 1 << (s-1); + getbits(-1); + for (i=0; i < sizeof(buf)/sizeof(short); i++) + buf[0][0][i] = 2048; + for (row=0; row < height; row+=4) { + FORC3 mul[c] = getbits(6); + FORC3 { + val = ((0x1000000/last[c] + 0x7ff) >> 12) * mul[c]; + s = val > 65564 ? 10:12; + x = ~(-1 << (s-1)); + val <<= 12-s; + for (i=0; i < sizeof(buf[0])/sizeof(short); i++) + buf[c][0][i] = (buf[c][0][i] * val + x) >> s; + last[c] = mul[c]; + for (r=0; r <= !c; r++) { + buf[c][1][width/2] = buf[c][2][width/2] = mul[c] << 7; + for (tree=1, col=width/2; col > 0; ) { + if ((tree = radc_token(tree))) { + col -= 2; + if (tree == 8) + FORYX buf[c][y][x] = (uchar) radc_token(18) * mul[c]; + else + FORYX buf[c][y][x] = radc_token(tree+10) * 16 + PREDICTOR; + } else + do { + nreps = (col > 2) ? radc_token(9) + 1 : 1; + for (rep=0; rep < 8 && rep < nreps && col > 0; rep++) { + col -= 2; + FORYX buf[c][y][x] = PREDICTOR; + if (rep & 1) { + step = radc_token(10) << 4; + FORYX buf[c][y][x] += step; + } + } + } while (nreps == 9); + } + for (y=0; y < 2; y++) + for (x=0; x < width/2; x++) { + val = (buf[c][y+1][x] << 4) / mul[c]; + if (val < 0) val = 0; + if (c) CBAYER(row+y*2+c-1,x*2+2-c) = val; + else CBAYER(row+r*2+y,x*2+y) = val; + } + memcpy (buf[c][0]+!c, buf[c][2], sizeof buf[c][0]-2*!c); + } + } + for (y=row; y < row+4; y++) + for (x=0; x < width; x++) + if ((x+y) & 1) { + r = x ? x-1 : x+1; + s = x+1 < width ? x+1 : x-1; + val = (CBAYER(y,x)-2048)*2 + (CBAYER(y,r)+CBAYER(y,s))/2; + if (val < 0) val = 0; + CBAYER(y,x) = val; + } + } +#ifndef LIBRAW_LIBRARY_BUILD + for (i=0; i < iheight*iwidth*4; i++) + image[0][i] = curve[image[0][i]]; +#else + for (i=0; i < height*width*4; i++) + color_image[0][i] = curve[color_image[0][i]]; +#endif + maximum = 0x3fff; +} + +#undef FORYX +#undef PREDICTOR + +#ifdef NO_JPEG +void CLASS kodak_jpeg_load_raw() {} +#else + +METHODDEF(boolean) +fill_input_buffer (j_decompress_ptr cinfo) +{ +#ifndef LIBRAW_NOTHREADS +#define jpeg_buffer tls->jpeg_buffer +#else + static uchar jpeg_buffer[4096]; +#endif + size_t nbytes; + + nbytes = fread (jpeg_buffer, 1, 4096, ifp); + swab (jpeg_buffer, jpeg_buffer, nbytes); + cinfo->src->next_input_byte = jpeg_buffer; + cinfo->src->bytes_in_buffer = nbytes; + return TRUE; +#ifndef LIBRAW_NOTHREADS +#undef jpeg_buffer +#endif +} + +void CLASS kodak_jpeg_load_raw() +{ + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + JSAMPARRAY buf; + JSAMPLE (*pixel)[3]; + int row, col; + + cinfo.err = jpeg_std_error (&jerr); + jpeg_create_decompress (&cinfo); + jpeg_stdio_src (&cinfo, ifp); + cinfo.src->fill_input_buffer = fill_input_buffer; + jpeg_read_header (&cinfo, TRUE); + jpeg_start_decompress (&cinfo); + if ((cinfo.output_width != width ) || + (cinfo.output_height*2 != height ) || + (cinfo.output_components != 3 )) { +#ifdef DCRAW_VERBOSE + fprintf (stderr,_("%s: incorrect JPEG dimensions\n"), ifname); +#endif + jpeg_destroy_decompress (&cinfo); +#ifdef LIBRAW_LIBRARY_BUILD + throw LIBRAW_EXCEPTION_DECODE_JPEG; +#else + longjmp (failure, 3); +#endif + } + buf = (*cinfo.mem->alloc_sarray) + ((j_common_ptr) &cinfo, JPOOL_IMAGE, width*3, 1); + + while (cinfo.output_scanline < cinfo.output_height) { + row = cinfo.output_scanline * 2; + jpeg_read_scanlines (&cinfo, buf, 1); + pixel = (JSAMPLE (*)[3]) buf[0]; + for (col=0; col < width; col+=2) { + RBAYER(row+0,col+0) = pixel[col+0][1] << 1; + RBAYER(row+1,col+1) = pixel[col+1][1] << 1; + RBAYER(row+0,col+1) = pixel[col][0] + pixel[col+1][0]; + RBAYER(row+1,col+0) = pixel[col][2] + pixel[col+1][2]; + } + } + jpeg_finish_decompress (&cinfo); + jpeg_destroy_decompress (&cinfo); + maximum = 0xff << 1; +} +#endif + +void CLASS kodak_dc120_load_raw() +{ + static const int mul[4] = { 162, 192, 187, 92 }; + static const int add[4] = { 0, 636, 424, 212 }; + uchar pixel[848]; + int row, shift, col; + + for (row=0; row < height; row++) { + if (fread (pixel, 1, 848, ifp) < 848) derror(); + shift = row * mul[row & 3] + add[row & 3]; + for (col=0; col < width; col++) + RBAYER(row,col) = (ushort) pixel[(col + shift) % 848]; + } + maximum = 0xff; +} + +void CLASS eight_bit_load_raw() +{ + uchar *pixel; + unsigned row, col, val, lblack=0; + + pixel = (uchar *) calloc (raw_width, sizeof *pixel); + merror (pixel, "eight_bit_load_raw()"); +#ifndef LIBRAW_LIBRARY_BUILD + fseek (ifp, top_margin*raw_width, SEEK_CUR); + for (row=0; row < height; row++) { + if (fread (pixel, 1, raw_width, ifp) < raw_width) derror(); + for (col=0; col < raw_width; col++) { + val = curve[pixel[col]]; + if ((unsigned) (col-left_margin) < width) + BAYER(row,col-left_margin) = val; + else lblack += val; + } + } +#else + for (row=0; row < raw_height; row++) { + if (fread (pixel, 1, raw_width, ifp) < raw_width) derror(); + for (col=0; col < raw_width; col++) { + val = curve[pixel[col]]; + RBAYER(row,col) = val; + if((unsigned) (row-top_margin)< height) + if ((unsigned) (col-left_margin) >= width) + lblack+=val; + } + } +#endif + + free (pixel); + if (raw_width > width+1) + black = lblack / ((raw_width - width) * height); + if (!strncmp(model,"DC2",3)) + black = 0; + maximum = curve[0xff]; +} + +void CLASS kodak_yrgb_load_raw() +{ + uchar *pixel; + int row, col, y, cb, cr, rgb[3], c; + + pixel = (uchar *) calloc (raw_width, 3*sizeof *pixel); + merror (pixel, "kodak_yrgb_load_raw()"); + for (row=0; row < height; row++) { + if (~row & 1) + if (fread (pixel, raw_width, 3, ifp) < 3) derror(); + for (col=0; col < raw_width; col++) { + y = pixel[width*2*(row & 1) + col]; + cb = pixel[width + (col & -2)] - 128; + cr = pixel[width + (col & -2)+1] - 128; + rgb[1] = y-((cb + cr + 2) >> 2); + rgb[2] = rgb[1] + cb; + rgb[0] = rgb[1] + cr; + FORC3{ +#ifndef LIBRAW_LIBRARY_BUILD + image[row*width+col][c] = curve[LIM(rgb[c],0,255)]; +#else + color_image[(row+top_margin)*raw_width+col+left_margin][c] = curve[LIM(rgb[c],0,255)]; +#endif + } + } + } + free (pixel); + maximum = curve[0xff]; +} + +void CLASS kodak_262_load_raw() +{ + static const uchar kodak_tree[2][26] = + { { 0,1,5,1,1,2,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9 }, + { 0,3,1,1,1,1,1,2,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9 } }; + ushort *huff[2]; + uchar *pixel; + int *strip, ns, c, row, col, chess, pi=0, pi1, pi2, pred, val; + + FORC(2) huff[c] = make_decoder (kodak_tree[c]); + ns = (raw_height+63) >> 5; + pixel = (uchar *) malloc (raw_width*32 + ns*4); + merror (pixel, "kodak_262_load_raw()"); + strip = (int *) (pixel + raw_width*32); + order = 0x4d4d; + FORC(ns) strip[c] = get4(); + for (row=0; row < raw_height; row++) { + if ((row & 31) == 0) { + fseek (ifp, strip[row >> 5], SEEK_SET); + getbits(-1); + pi = 0; + } + for (col=0; col < raw_width; col++) { + chess = (row + col) & 1; + pi1 = chess ? pi-2 : pi-raw_width-1; + pi2 = chess ? pi-2*raw_width : pi-raw_width+1; + if (col <= chess) pi1 = -1; + if (pi1 < 0) pi1 = pi2; + if (pi2 < 0) pi2 = pi1; + if (pi1 < 0 && col > 1) pi1 = pi2 = pi-2; + pred = (pi1 < 0) ? 0 : (pixel[pi1] + pixel[pi2]) >> 1; + pixel[pi] = val = pred + ljpeg_diff (huff[chess]); + if (val >> 8) derror(); + + val = curve[pixel[pi++]]; + +#ifdef LIBRAW_LIBRARY_BUILD + RBAYER(row,col) = val; + if ((unsigned) (col-left_margin) >= width) + black+=val; +#else + if ((unsigned) (col-left_margin) < width) + BAYER(row,col-left_margin) = val; + else black += val; +#endif + } + } + free (pixel); + FORC(2) free (huff[c]); + if (raw_width > width) + black /= (raw_width - width) * height; +} + +int CLASS kodak_65000_decode (short *out, int bsize) +{ + uchar c, blen[768]; + ushort raw[6]; + INT64 bitbuf=0; + int save, bits=0, i, j, len, diff; + + save = ftell(ifp); + bsize = (bsize + 3) & -4; + for (i=0; i < bsize; i+=2) { + c = fgetc(ifp); + if ((blen[i ] = c & 15) > 12 || + (blen[i+1] = c >> 4) > 12 ) { + fseek (ifp, save, SEEK_SET); + for (i=0; i < bsize; i+=8) { + read_shorts (raw, 6); + out[i ] = raw[0] >> 12 << 8 | raw[2] >> 12 << 4 | raw[4] >> 12; + out[i+1] = raw[1] >> 12 << 8 | raw[3] >> 12 << 4 | raw[5] >> 12; + for (j=0; j < 6; j++) + out[i+2+j] = raw[j] & 0xfff; + } + return 1; + } + } + if ((bsize & 7) == 4) { + bitbuf = fgetc(ifp) << 8; + bitbuf += fgetc(ifp); + bits = 16; + } + for (i=0; i < bsize; i++) { + len = blen[i]; + if (bits < len) { + for (j=0; j < 32; j+=8) + bitbuf += (INT64) fgetc(ifp) << (bits+(j^8)); + bits += 32; + } + diff = bitbuf & (0xffff >> (16-len)); + bitbuf >>= len; + bits -= len; + if ((diff & (1 << (len-1))) == 0) + diff -= (1 << len) - 1; + out[i] = diff; + } + return 0; +} + +void CLASS kodak_65000_load_raw() +{ + short buf[256]; + int row, col, len, pred[2], ret, i; + + for (row=0; row < height; row++) + for (col=0; col < width; col+=256) { + pred[0] = pred[1] = 0; + len = MIN (256, width-col); + ret = kodak_65000_decode (buf, len); + for (i=0; i < len; i++) +#ifndef LIBRAW_LIBRARY_BUILD + if ((BAYER(row,col+i) = curve[ret ? buf[i] : + (pred[i & 1] += buf[i])]) >> 12) derror(); +#else + { + ushort val = ret ? buf[i] : (pred[i & 1] += buf[i]); + val = curve[val]; + RBAYER(row,col+i) = val; + if(curve[val]>>12) derror(); + } +#endif + } +} + +void CLASS kodak_ycbcr_load_raw() +{ + short buf[384], *bp; + int row, col, len, c, i, j, k, y[2][2], cb, cr, rgb[3]; + ushort *ip; + + for (row=0; row < height; row+=2) + for (col=0; col < width; col+=128) { + len = MIN (128, width-col); + kodak_65000_decode (buf, len*3); + y[0][1] = y[1][1] = cb = cr = 0; + for (bp=buf, i=0; i < len; i+=2, bp+=2) { + cb += bp[4]; + cr += bp[5]; + rgb[1] = -((cb + cr + 2) >> 2); + rgb[2] = rgb[1] + cb; + rgb[0] = rgb[1] + cr; + for (j=0; j < 2; j++) + for (k=0; k < 2; k++) { + if ((y[j][k] = y[j][k^1] + *bp++) >> 10) derror(); +#ifndef LIBRAW_LIBRARY_BUILD + ip = image[(row+j)*width + col+i+k]; + FORC3 ip[c] = curve[LIM(y[j][k]+rgb[c], 0, 0xfff)]; +#else + ip = color_image[(row+top_margin+j)*raw_width + col+i+k+left_margin]; + FORC3 ip[c] = curve[LIM(y[j][k]+rgb[c], 0, 0xfff)]; +#endif + } + } + } +} + +void CLASS kodak_rgb_load_raw() +{ + short buf[768], *bp; + int row, col, len, c, i, rgb[3]; +#ifndef LIBRAW_LIBRARY_BUILD + ushort *ip=image[0]; +#else + ushort *ip; +#endif + + for (row=0; row < height; row++) + for (col=0; col < width; col+=256) { + len = MIN (256, width-col); + kodak_65000_decode (buf, len*3); + memset (rgb, 0, sizeof rgb); +#ifdef LIBRAW_LIBRARY_BUILD + ip = &color_image[(row+top_margin)*raw_width+left_margin][0]; +#endif + for (bp=buf, i=0; i < len; i++, ip+=4) + FORC3{ + if ((ip[c] = rgb[c] += *bp++) >> 12) derror(); + } + } +} + +void CLASS kodak_ycbcr_load_thumb() +{ + short buf[384], *bp; + int row, col, len, c, i, j, k, y[2][2], cb, cr, rgb[3]; + ushort *ip; + + for (row=0; row < height; row+=2) + for (col=0; col < width; col+=128) { + len = MIN (128, width-col); + kodak_65000_decode (buf, len*3); + y[0][1] = y[1][1] = cb = cr = 0; + for (bp=buf, i=0; i < len; i+=2, bp+=2) { + cb += bp[4]; + cr += bp[5]; + rgb[1] = -((cb + cr + 2) >> 2); + rgb[2] = rgb[1] + cb; + rgb[0] = rgb[1] + cr; + for (j=0; j < 2; j++) + for (k=0; k < 2; k++) { + if ((y[j][k] = y[j][k^1] + *bp++) >> 10) derror(); + ip = image[(row+j)*width + col+i+k]; + FORC3 ip[c] = curve[LIM(y[j][k]+rgb[c], 0, 0xfff)]; + } + } + } +} + +void CLASS kodak_rgb_load_thumb() +{ + short buf[768], *bp; + int row, col, len, c, i, rgb[3]; + ushort *ip=image[0]; + + for (row=0; row < height; row++) + for (col=0; col < width; col+=256) { + len = MIN (256, width-col); + kodak_65000_decode (buf, len*3); + memset (rgb, 0, sizeof rgb); + for (bp=buf, i=0; i < len; i++, ip+=4) + FORC3 if ((ip[c] = rgb[c] += *bp++) >> 12) derror(); + } +} + +void CLASS kodak_thumb_load_raw() +{ + int row, col; + colors = thumb_misc >> 5; + for (row=0; row < height; row++) + for (col=0; col < width; col++) + read_shorts (image[row*width+col], colors); + maximum = (1 << (thumb_misc & 31)) - 1; +} + +void CLASS sony_decrypt (unsigned *data, int len, int start, int key) +{ +#ifndef LIBRAW_NOTHREADS +#define pad tls->sony_decrypt.pad +#define p tls->sony_decrypt.p +#else + static unsigned pad[128], p; +#endif + + if (start) { + for (p=0; p < 4; p++) + pad[p] = key = key * 48828125 + 1; + pad[3] = pad[3] << 1 | (pad[0]^pad[2]) >> 31; + for (p=4; p < 127; p++) + pad[p] = (pad[p-4]^pad[p-2]) << 1 | (pad[p-3]^pad[p-1]) >> 31; + for (p=0; p < 127; p++) + pad[p] = htonl(pad[p]); + } + while (len--) + *data++ ^= pad[p++ & 127] = pad[(p+1) & 127] ^ pad[(p+65) & 127]; +#ifndef LIBRAW_NOTHREADS +#undef pad +#undef p +#endif +} + +void CLASS sony_load_raw() +{ + uchar head[40]; + ushort *pixel; + unsigned i, key, row, col; + + fseek (ifp, 200896, SEEK_SET); + fseek (ifp, (unsigned) fgetc(ifp)*4 - 1, SEEK_CUR); + order = 0x4d4d; + key = get4(); + fseek (ifp, 164600, SEEK_SET); + fread (head, 1, 40, ifp); + sony_decrypt ((unsigned int *) head, 10, 1, key); + for (i=26; i-- > 22; ) + key = key << 8 | head[i]; + fseek (ifp, data_offset, SEEK_SET); + pixel = (ushort *) calloc (raw_width, sizeof *pixel); + merror (pixel, "sony_load_raw()"); + for (row=0; row < height; row++) { + if (fread (pixel, 2, raw_width, ifp) < raw_width) derror(); + sony_decrypt ((unsigned int *) pixel, raw_width/2, !row, key); + for (col=9; col < left_margin; col++) + black += ntohs(pixel[col]); +#ifndef LIBRAW_LIBRARY_BUILD + for (col=0; col < width; col++) + if ((BAYER(row,col) = ntohs(pixel[col+left_margin])) >> 14) + derror(); +#else + for (col=0; col < raw_width; col++) + { + RBAYER(row,col) = ntohs(pixel[col]); + if(col >= left_margin && col < width+left_margin + && (RBAYER(row,col)>>14)) + derror(); + } +#endif + } + free (pixel); + if (left_margin > 9) + black /= (left_margin-9) * height; + maximum = 0x3ff0; +} + +void CLASS sony_arw_load_raw() +{ + ushort huff[32768]; + static const ushort tab[18] = + { 0xf11,0xf10,0xe0f,0xd0e,0xc0d,0xb0c,0xa0b,0x90a,0x809, + 0x708,0x607,0x506,0x405,0x304,0x303,0x300,0x202,0x201 }; + int i, c, n, col, row, len, diff, sum=0; + + for (n=i=0; i < 18; i++) + FORC(32768 >> (tab[i] >> 8)) huff[n++] = tab[i]; +#ifdef LIBRAW_LIBRARY_BUILD + LibRaw_byte_buffer *buf=NULL; + if(data_size) + buf = ifp->make_byte_buffer(data_size); + else + getbits(-1); + + LibRaw_bit_buffer bits; + bits.reset(); +#else + getbits(-1); +#endif + for (col = raw_width; col--; ) + for (row=0; row < raw_height+1; row+=2) { + if (row == raw_height) row = 1; +#ifdef LIBRAW_LIBRARY_BUILD + if(data_size) + { + len = bits._gethuff(buf,15,huff,zero_after_ff); + diff = bits._getbits(buf,len,zero_after_ff); + } + else + { + len = getbithuff(15,huff); + diff = getbits(len); + } +#else + len = getbithuff(15,huff); + diff = getbits(len); +#endif + if ((diff & (1 << (len-1))) == 0) + diff -= (1 << len) - 1; + if ((sum += diff) >> 12) derror(); +#ifndef LIBRAW_LIBRARY_BUILD + if (row < height) + { + BAYER(row,col) = sum; + } +#else + RBAYER(row,col) = sum; +#endif + } +#ifdef LIBRAW_LIBRARY_BUILD + if(buf) delete buf; +#endif +} + +void CLASS sony_arw2_load_raw() +{ + uchar *data, *dp; + ushort pix[16]; + int row, col, val, max, min, imax, imin, sh, bit, i; + + data = (uchar *) malloc (raw_width+4); + merror (data, "sony_arw2_load_raw()"); + for (row=0; row < height; row++) { + fread (data, 1, raw_width, ifp); + for (dp=data, col=0; col < raw_width-30; dp+=16) { + max = 0x7ff & (val = sget4(dp)); + min = 0x7ff & val >> 11; + imax = 0x0f & val >> 22; + imin = 0x0f & val >> 26; + for (sh=0; sh < 4 && 0x80 << sh <= max-min; sh++); + for (bit=30, i=0; i < 16; i++) + if (i == imax) pix[i] = max; + else if (i == imin) pix[i] = min; + else { + pix[i] = ((sget2(dp+(bit >> 3)) >> (bit & 7) & 0x7f) << sh) + min; + if (pix[i] > 0x7ff) pix[i] = 0x7ff; + bit += 7; + } + for (i=0; i < 16; i++, col+=2) +#ifdef LIBRAW_LIBRARY_BUILD + RBAYER(row,col) = curve[pix[i] << 1] >> 2; +#else + if (col < width) BAYER(row,col) = curve[pix[i] << 1] >> 2; +#endif + col -= col & 1 ? 1:31; + } + } + free (data); +} + +#define HOLE(row) ((holes >> (((row) - raw_height) & 7)) & 1) + +/* Kudos to Rich Taylor for figuring out SMaL's compression algorithm. */ +void CLASS smal_decode_segment (unsigned seg[2][2], int holes) +{ + uchar hist[3][13] = { + { 7, 7, 0, 0, 63, 55, 47, 39, 31, 23, 15, 7, 0 }, + { 7, 7, 0, 0, 63, 55, 47, 39, 31, 23, 15, 7, 0 }, + { 3, 3, 0, 0, 63, 47, 31, 15, 0 } }; + int low, high=0xff, carry=0, nbits=8; + int s, count, bin, next, i, sym[3]; + uchar diff, pred[]={0,0}; + ushort data=0, range=0; + unsigned pix, row, col; + + fseek (ifp, seg[0][1]+1, SEEK_SET); + getbits(-1); + for (pix=seg[0][0]; pix < seg[1][0]; pix++) { + for (s=0; s < 3; s++) { + data = data << nbits | getbits(nbits); + if (carry < 0) + carry = (nbits += carry+1) < 1 ? nbits-1 : 0; + while (--nbits >= 0) + if ((data >> nbits & 0xff) == 0xff) break; + if (nbits > 0) + data = ((data & ((1 << (nbits-1)) - 1)) << 1) | + ((data + (((data & (1 << (nbits-1)))) << 1)) & (-1 << nbits)); + if (nbits >= 0) { + data += getbits(1); + carry = nbits - 8; + } + count = ((((data-range+1) & 0xffff) << 2) - 1) / (high >> 4); + for (bin=0; hist[s][bin+5] > count; bin++); + low = hist[s][bin+5] * (high >> 4) >> 2; + if (bin) high = hist[s][bin+4] * (high >> 4) >> 2; + high -= low; + for (nbits=0; high << nbits < 128; nbits++); + range = (range+low) << nbits; + high <<= nbits; + next = hist[s][1]; + if (++hist[s][2] > hist[s][3]) { + next = (next+1) & hist[s][0]; + hist[s][3] = (hist[s][next+4] - hist[s][next+5]) >> 2; + hist[s][2] = 1; + } + if (hist[s][hist[s][1]+4] - hist[s][hist[s][1]+5] > 1) { + if (bin < hist[s][1]) + for (i=bin; i < hist[s][1]; i++) hist[s][i+5]--; + else if (next <= bin) + for (i=hist[s][1]; i < bin; i++) hist[s][i+5]++; + } + hist[s][1] = next; + sym[s] = bin; + } + diff = sym[2] << 5 | sym[1] << 2 | (sym[0] & 3); + if (sym[0] & 4) + diff = diff ? -diff : 0x80; + if (ftell(ifp) + 12 >= seg[1][1]) + diff = 0; + pred[pix & 1] += diff; +#ifndef LIBRAW_LIBRARY_BUILD + row = pix / raw_width - top_margin; + col = pix % raw_width - left_margin; + if (row < height && col < width) + BAYER(row,col) = pred[pix & 1]; +#else + row = pix / raw_width - top_margin; + RBAYER(pix / raw_width, pix % raw_width) = pred[pix & 1]; +#endif + if (!(pix & 1) && HOLE(row)) pix += 2; + } + maximum = 0xff; +} + +void CLASS smal_v6_load_raw() +{ + unsigned seg[2][2]; + + fseek (ifp, 16, SEEK_SET); + seg[0][0] = 0; + seg[0][1] = get2(); + seg[1][0] = raw_width * raw_height; + seg[1][1] = INT_MAX; + smal_decode_segment (seg, 0); +} + +int CLASS median4 (int *p) +{ + int min, max, sum, i; + + min = max = sum = p[0]; + for (i=1; i < 4; i++) { + sum += p[i]; + if (min > p[i]) min = p[i]; + if (max < p[i]) max = p[i]; + } + return (sum - min - max) >> 1; +} + +void CLASS fill_holes (int holes) +{ + int row, col, val[4]; + + for (row=2; row < height-2; row++) { + if (!HOLE(row)) continue; + for (col=1; col < width-1; col+=4) { + val[0] = BAYER(row-1,col-1); + val[1] = BAYER(row-1,col+1); + val[2] = BAYER(row+1,col-1); + val[3] = BAYER(row+1,col+1); + BAYER(row,col) = median4(val); + } + for (col=2; col < width-2; col+=4) + if (HOLE(row-2) || HOLE(row+2)) + BAYER(row,col) = (BAYER(row,col-2) + BAYER(row,col+2)) >> 1; + else { + val[0] = BAYER(row,col-2); + val[1] = BAYER(row,col+2); + val[2] = BAYER(row-2,col); + val[3] = BAYER(row+2,col); + BAYER(row,col) = median4(val); + } + } +} + +void CLASS smal_v9_load_raw() +{ + unsigned seg[256][2], offset, nseg, holes, i; + + fseek (ifp, 67, SEEK_SET); + offset = get4(); + nseg = fgetc(ifp); + fseek (ifp, offset, SEEK_SET); + for (i=0; i < nseg*2; i++) + seg[0][i] = get4() + data_offset*(i & 1); + fseek (ifp, 78, SEEK_SET); + holes = fgetc(ifp); + fseek (ifp, 88, SEEK_SET); + seg[nseg][0] = raw_height * raw_width; + seg[nseg][1] = get4() + data_offset; + for (i=0; i < nseg; i++) + smal_decode_segment (seg+i, holes); + if (holes) fill_holes (holes); +} + +void CLASS redcine_load_raw() +{ +#ifndef NO_JASPER + int c, row, col; + jas_stream_t *in; + jas_image_t *jimg; + jas_matrix_t *jmat; + jas_seqent_t *data; + ushort *img, *pix; + + jas_init(); +#ifndef LIBRAW_LIBRARY_BUILD + in = jas_stream_fopen (ifname, "rb"); +#else + in = (jas_stream_t*)ifp->make_jas_stream(); + if(!in) + throw LIBRAW_EXCEPTION_DECODE_JPEG2000; +#endif + jas_stream_seek (in, data_offset+20, SEEK_SET); + jimg = jas_image_decode (in, -1, 0); +#ifndef LIBRAW_LIBRARY_BUILD + if (!jimg) longjmp (failure, 3); +#else + if(!jimg) + { + jas_stream_close (in); + throw LIBRAW_EXCEPTION_DECODE_JPEG2000; + } +#endif + jmat = jas_matrix_create (height/2, width/2); + merror (jmat, "redcine_load_raw()"); + img = (ushort *) calloc ((height+2)*(width+2), 2); + merror (img, "redcine_load_raw()"); + FORC4 { + jas_image_readcmpt (jimg, c, 0, 0, width/2, height/2, jmat); + data = jas_matrix_getref (jmat, 0, 0); + for (row = c >> 1; row < height; row+=2) + for (col = c & 1; col < width; col+=2) + img[(row+1)*(width+2)+col+1] = data[(row/2)*(width/2)+col/2]; + } + for (col=1; col <= width; col++) { + img[col] = img[2*(width+2)+col]; + img[(height+1)*(width+2)+col] = img[(height-1)*(width+2)+col]; + } + for (row=0; row < height+2; row++) { + img[row*(width+2)] = img[row*(width+2)+2]; + img[(row+1)*(width+2)-1] = img[(row+1)*(width+2)-3]; + } + for (row=1; row <= height; row++) { + pix = img + row*(width+2) + (col = 1 + (FC(row,1) & 1)); + for ( ; col <= width; col+=2, pix+=2) { + c = (((pix[0] - 0x800) << 3) + + pix[-(width+2)] + pix[width+2] + pix[-1] + pix[1]) >> 2; + pix[0] = LIM(c,0,4095); + } + } + for (row=0; row < height; row++) + for (col=0; col < width; col++) + RBAYER(row,col) = curve[img[(row+1)*(width+2)+col+1]]; + free (img); + jas_matrix_destroy (jmat); + jas_image_destroy (jimg); + jas_stream_close (in); +#endif +} + + +void CLASS gamma_curve (double pwr, double ts, int mode, int imax) +{ + int i; + double g[6], bnd[2]={0,0}, r; + + g[0] = pwr; + g[1] = ts; + g[2] = g[3] = g[4] = 0; + bnd[g[1] >= 1] = 1; + if (g[1] && (g[1]-1)*(g[0]-1) <= 0) { + for (i=0; i < 48; i++) { + g[2] = (bnd[0] + bnd[1])/2; + if (g[0]) bnd[(pow(g[2]/g[1],-g[0]) - 1)/g[0] - 1/g[2] > -1] = g[2]; + else bnd[g[2]/exp(1-1/g[2]) < g[1]] = g[2]; + } + g[3] = g[2] / g[1]; + if (g[0]) g[4] = g[2] * (1/g[0] - 1); + } + if (g[0]) g[5] = 1 / (g[1]*SQR(g[3])/2 - g[4]*(1 - g[3]) + + (1 - pow(g[3],1+g[0]))*(1 + g[4])/(1 + g[0])) - 1; + else g[5] = 1 / (g[1]*SQR(g[3])/2 + 1 + - g[2] - g[3] - g[2]*g[3]*(log(g[3]) - 1)) - 1; + if (!mode--) { + memcpy (gamm, g, sizeof gamm); + return; + } + for (i=0; i < 0x10000; i++) { + curve[i] = 0xffff; + if ((r = (double) i / imax) < 1) + curve[i] = 0x10000 * ( mode + ? (r < g[3] ? r*g[1] : (g[0] ? pow( r,g[0])*(1+g[4])-g[4] : log(r)*g[2]+1)) + : (r < g[2] ? r/g[1] : (g[0] ? pow((r+g[4])/(1+g[4]),1/g[0]) : exp((r-1)/g[2])))); + } +} + +void CLASS pseudoinverse (double (*in)[3], double (*out)[3], int size) +{ + double work[3][6], num; + int i, j, k; + + for (i=0; i < 3; i++) { + for (j=0; j < 6; j++) + work[i][j] = j == i+3; + for (j=0; j < 3; j++) + for (k=0; k < size; k++) + work[i][j] += in[k][i] * in[k][j]; + } + for (i=0; i < 3; i++) { + num = work[i][i]; + for (j=0; j < 6; j++) + work[i][j] /= num; + for (k=0; k < 3; k++) { + if (k==i) continue; + num = work[k][i]; + for (j=0; j < 6; j++) + work[k][j] -= work[i][j] * num; + } + } + for (i=0; i < size; i++) + for (j=0; j < 3; j++) + for (out[i][j]=k=0; k < 3; k++) + out[i][j] += work[j][k+3] * in[i][k]; +} + +void CLASS cam_xyz_coeff (double cam_xyz[4][3]) +{ + double cam_rgb[4][3], inverse[4][3], num; + int i, j, k; + + for (i=0; i < colors; i++) /* Multiply out XYZ colorspace */ + for (j=0; j < 3; j++) + for (cam_rgb[i][j] = k=0; k < 3; k++) + cam_rgb[i][j] += cam_xyz[i][k] * xyz_rgb[k][j]; + + for (i=0; i < colors; i++) { /* Normalize cam_rgb so that */ + for (num=j=0; j < 3; j++) /* cam_rgb * (1,1,1) is (1,1,1,1) */ + num += cam_rgb[i][j]; + for (j=0; j < 3; j++) + cam_rgb[i][j] /= num; + pre_mul[i] = 1 / num; + } + pseudoinverse (cam_rgb, inverse, colors); + for (raw_color = i=0; i < 3; i++) + for (j=0; j < colors; j++) + rgb_cam[i][j] = inverse[j][i]; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.pre_mul_state = LIBRAW_COLORSTATE_CONST; + color_flags.rgb_cam_state = LIBRAW_COLORSTATE_CONST; +#endif +} + +#ifdef COLORCHECK +void CLASS colorcheck() +{ +#define NSQ 24 +// Coordinates of the GretagMacbeth ColorChecker squares +// width, height, 1st_column, 1st_row + int cut[NSQ][4]; // you must set these +// ColorChecker Chart under 6500-kelvin illumination + static const double gmb_xyY[NSQ][3] = { + { 0.400, 0.350, 10.1 }, // Dark Skin + { 0.377, 0.345, 35.8 }, // Light Skin + { 0.247, 0.251, 19.3 }, // Blue Sky + { 0.337, 0.422, 13.3 }, // Foliage + { 0.265, 0.240, 24.3 }, // Blue Flower + { 0.261, 0.343, 43.1 }, // Bluish Green + { 0.506, 0.407, 30.1 }, // Orange + { 0.211, 0.175, 12.0 }, // Purplish Blue + { 0.453, 0.306, 19.8 }, // Moderate Red + { 0.285, 0.202, 6.6 }, // Purple + { 0.380, 0.489, 44.3 }, // Yellow Green + { 0.473, 0.438, 43.1 }, // Orange Yellow + { 0.187, 0.129, 6.1 }, // Blue + { 0.305, 0.478, 23.4 }, // Green + { 0.539, 0.313, 12.0 }, // Red + { 0.448, 0.470, 59.1 }, // Yellow + { 0.364, 0.233, 19.8 }, // Magenta + { 0.196, 0.252, 19.8 }, // Cyan + { 0.310, 0.316, 90.0 }, // White + { 0.310, 0.316, 59.1 }, // Neutral 8 + { 0.310, 0.316, 36.2 }, // Neutral 6.5 + { 0.310, 0.316, 19.8 }, // Neutral 5 + { 0.310, 0.316, 9.0 }, // Neutral 3.5 + { 0.310, 0.316, 3.1 } }; // Black + double gmb_cam[NSQ][4], gmb_xyz[NSQ][3]; + double inverse[NSQ][3], cam_xyz[4][3], num; + int c, i, j, k, sq, row, col, count[4]; + + memset (gmb_cam, 0, sizeof gmb_cam); + for (sq=0; sq < NSQ; sq++) { + FORCC count[c] = 0; + for (row=cut[sq][3]; row < cut[sq][3]+cut[sq][1]; row++) + for (col=cut[sq][2]; col < cut[sq][2]+cut[sq][0]; col++) { + c = FC(row,col); + if (c >= colors) c -= 2; + gmb_cam[sq][c] += BAYER(row,col); + count[c]++; + } + FORCC gmb_cam[sq][c] = gmb_cam[sq][c]/count[c] - black; + gmb_xyz[sq][0] = gmb_xyY[sq][2] * gmb_xyY[sq][0] / gmb_xyY[sq][1]; + gmb_xyz[sq][1] = gmb_xyY[sq][2]; + gmb_xyz[sq][2] = gmb_xyY[sq][2] * + (1 - gmb_xyY[sq][0] - gmb_xyY[sq][1]) / gmb_xyY[sq][1]; + } + pseudoinverse (gmb_xyz, inverse, NSQ); + for (i=0; i < colors; i++) + for (j=0; j < 3; j++) + for (cam_xyz[i][j] = k=0; k < NSQ; k++) + cam_xyz[i][j] += gmb_cam[k][i] * inverse[k][j]; + cam_xyz_coeff (cam_xyz); +#ifdef DCRAW_VERBOSE + if (verbose) { + printf (" { \"%s %s\", %d,\n\t{", make, model, black); + num = 10000 / (cam_xyz[1][0] + cam_xyz[1][1] + cam_xyz[1][2]); + FORCC for (j=0; j < 3; j++) + printf ("%c%d", (c | j) ? ',':' ', (int) (cam_xyz[c][j] * num + 0.5)); + puts (" } },"); + } +#endif +#undef NSQ +} +#endif + +void CLASS hat_transform (float *temp, float *base, int st, int size, int sc) +{ + int i; + for (i=0; i < sc; i++) + temp[i] = 2*base[st*i] + base[st*(sc-i)] + base[st*(i+sc)]; + for (; i+sc < size; i++) + temp[i] = 2*base[st*i] + base[st*(i-sc)] + base[st*(i+sc)]; + for (; i < size; i++) + temp[i] = 2*base[st*i] + base[st*(i-sc)] + base[st*(2*size-2-(i+sc))]; +} + +#if !defined(LIBRAW_USE_OPENMP) +void CLASS wavelet_denoise() +{ + float *fimg=0, *temp, thold, mul[2], avg, diff; + int scale=1, size, lev, hpass, lpass, row, col, nc, c, i, wlast, blk[2]; + ushort *window[4]; + static const float noise[] = + { 0.8002,0.2735,0.1202,0.0585,0.0291,0.0152,0.0080,0.0044 }; + +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("Wavelet denoising...\n")); +#endif + + while (maximum << scale < 0x10000) scale++; + maximum <<= --scale; + black <<= scale; + FORC4 cblack[c] <<= scale; + if ((size = iheight*iwidth) < 0x15550000) + fimg = (float *) malloc ((size*3 + iheight + iwidth) * sizeof *fimg); + merror (fimg, "wavelet_denoise()"); + temp = fimg + size*3; + if ((nc = colors) == 3 && filters) nc++; + FORC(nc) { /* denoise R,G1,B,G3 individually */ + for (i=0; i < size; i++) + fimg[i] = 256 * sqrt((double)(image[i][c] << scale)); + for (hpass=lev=0; lev < 5; lev++) { + lpass = size*((lev & 1)+1); + for (row=0; row < iheight; row++) { + hat_transform (temp, fimg+hpass+row*iwidth, 1, iwidth, 1 << lev); + for (col=0; col < iwidth; col++) + fimg[lpass + row*iwidth + col] = temp[col] * 0.25; + } + for (col=0; col < iwidth; col++) { + hat_transform (temp, fimg+lpass+col, iwidth, iheight, 1 << lev); + for (row=0; row < iheight; row++) + fimg[lpass + row*iwidth + col] = temp[row] * 0.25; + } + thold = threshold * noise[lev]; + for (i=0; i < size; i++) { + fimg[hpass+i] -= fimg[lpass+i]; + if (fimg[hpass+i] < -thold) fimg[hpass+i] += thold; + else if (fimg[hpass+i] > thold) fimg[hpass+i] -= thold; + else fimg[hpass+i] = 0; + if (hpass) fimg[i] += fimg[hpass+i]; + } + hpass = lpass; + } + for (i=0; i < size; i++) + image[i][c] = CLIP(SQR(fimg[i]+fimg[lpass+i])/0x10000); + } + if (filters && colors == 3) { /* pull G1 and G3 closer together */ + for (row=0; row < 2; row++) { + mul[row] = 0.125 * pre_mul[FC(row+1,0) | 1] / pre_mul[FC(row,0) | 1]; + blk[row] = cblack[FC(row,0) | 1]; + } + for (i=0; i < 4; i++) + window[i] = (ushort *) fimg + width*i; + for (wlast=-1, row=1; row < height-1; row++) { + while (wlast < row+1) { + for (wlast++, i=0; i < 4; i++) + window[(i+3) & 3] = window[i]; + for (col = FC(wlast,1) & 1; col < width; col+=2) + window[2][col] = BAYER(wlast,col); + } + thold = threshold/512; + for (col = (FC(row,0) & 1)+1; col < width-1; col+=2) { + avg = ( window[0][col-1] + window[0][col+1] + + window[2][col-1] + window[2][col+1] - blk[~row & 1]*4 ) + * mul[row & 1] + (window[1][col] + blk[row & 1]) * 0.5; + avg = avg < 0 ? 0 : sqrt(avg); + diff = sqrt((double)(BAYER(row,col))) - avg; + if (diff < -thold) diff += thold; + else if (diff > thold) diff -= thold; + else diff = 0; + BAYER(row,col) = CLIP(SQR(avg+diff) + 0.5); + } + } + } + free (fimg); +} +#else /* LIBRAW_USE_OPENMP */ +void CLASS wavelet_denoise() +{ + float *fimg=0, *temp, thold, mul[2], avg, diff; + int scale=1, size, lev, hpass, lpass, row, col, nc, c, i, wlast, blk[2]; + ushort *window[4]; + static const float noise[] = + { 0.8002,0.2735,0.1202,0.0585,0.0291,0.0152,0.0080,0.0044 }; + +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("Wavelet denoising...\n")); +#endif + + while (maximum << scale < 0x10000) scale++; + maximum <<= --scale; + black <<= scale; + FORC4 cblack[c] <<= scale; + if ((size = iheight*iwidth) < 0x15550000) + fimg = (float *) malloc ((size*3 + iheight + iwidth) * sizeof *fimg); + merror (fimg, "wavelet_denoise()"); + temp = fimg + size*3; + if ((nc = colors) == 3 && filters) nc++; +#ifdef LIBRAW_LIBRARY_BUILD +#pragma omp parallel default(shared) private(i,col,row,thold,lev,lpass,hpass,temp,c) firstprivate(scale,size) +#endif + { + temp = (float*)malloc( (iheight + iwidth) * sizeof *fimg); + FORC(nc) { /* denoise R,G1,B,G3 individually */ +#ifdef LIBRAW_LIBRARY_BUILD +#pragma omp for +#endif + for (i=0; i < size; i++) + fimg[i] = 256 * sqrt((double)(image[i][c] << scale)); + for (hpass=lev=0; lev < 5; lev++) { + lpass = size*((lev & 1)+1); +#ifdef LIBRAW_LIBRARY_BUILD +#pragma omp for +#endif + for (row=0; row < iheight; row++) { + hat_transform (temp, fimg+hpass+row*iwidth, 1, iwidth, 1 << lev); + for (col=0; col < iwidth; col++) + fimg[lpass + row*iwidth + col] = temp[col] * 0.25; + } +#ifdef LIBRAW_LIBRARY_BUILD +#pragma omp for +#endif + for (col=0; col < iwidth; col++) { + hat_transform (temp, fimg+lpass+col, iwidth, iheight, 1 << lev); + for (row=0; row < iheight; row++) + fimg[lpass + row*iwidth + col] = temp[row] * 0.25; + } + thold = threshold * noise[lev]; +#ifdef LIBRAW_LIBRARY_BUILD +#pragma omp for +#endif + for (i=0; i < size; i++) { + fimg[hpass+i] -= fimg[lpass+i]; + if (fimg[hpass+i] < -thold) fimg[hpass+i] += thold; + else if (fimg[hpass+i] > thold) fimg[hpass+i] -= thold; + else fimg[hpass+i] = 0; + if (hpass) fimg[i] += fimg[hpass+i]; + } + hpass = lpass; + } +#ifdef LIBRAW_LIBRARY_BUILD +#pragma omp for +#endif + for (i=0; i < size; i++) + image[i][c] = CLIP(SQR(fimg[i]+fimg[lpass+i])/0x10000); + } + free(temp); + } /* end omp parallel */ +/* the following loops are hard to parallize, no idea yes, + * problem is wlast which is carrying dependency + * second part should be easyer, but did not yet get it right. + */ + if (filters && colors == 3) { /* pull G1 and G3 closer together */ + for (row=0; row < 2; row++){ + mul[row] = 0.125 * pre_mul[FC(row+1,0) | 1] / pre_mul[FC(row,0) | 1]; + blk[row] = cblack[FC(row,0) | 1]; + } + for (i=0; i < 4; i++) + window[i] = (ushort *) fimg + width*i; + for (wlast=-1, row=1; row < height-1; row++) { + while (wlast < row+1) { + for (wlast++, i=0; i < 4; i++) + window[(i+3) & 3] = window[i]; + for (col = FC(wlast,1) & 1; col < width; col+=2) + window[2][col] = BAYER(wlast,col); + } + thold = threshold/512; + for (col = (FC(row,0) & 1)+1; col < width-1; col+=2) { + avg = ( window[0][col-1] + window[0][col+1] + + window[2][col-1] + window[2][col+1] - blk[~row & 1]*4 ) + * mul[row & 1] + (window[1][col] + blk[row & 1]) * 0.5; + avg = avg < 0 ? 0 : sqrt(avg); + diff = sqrt((double)BAYER(row,col)) - avg; + if (diff < -thold) diff += thold; + else if (diff > thold) diff -= thold; + else diff = 0; + BAYER(row,col) = CLIP(SQR(avg+diff) + 0.5); + } + } + } + free (fimg); +} + +#endif + + + +// green equilibration +void CLASS green_matching() +{ + int i,j; + double m1,m2,c1,c2; + int o1_1,o1_2,o1_3,o1_4; + int o2_1,o2_2,o2_3,o2_4; + ushort (*img)[4]; + const int margin = 3; + int oj = 2, oi = 2; + float f; + const float thr = 0.01f; + if(half_size || shrink) return; + if(FC(oj, oi) != 3) oj++; + if(FC(oj, oi) != 3) oi++; + if(FC(oj, oi) != 3) oj--; + + img = (ushort (*)[4]) calloc (height*width, sizeof *image); + merror (img, "green_matching()"); + memcpy(img,image,height*width*sizeof *image); + + for(j=oj;j0xffff?0xffff:f; + } + } + free(img); +} + + +void CLASS scale_colors() +{ + unsigned bottom, right, size, row, col, ur, uc, x, y, c, sum[8]; + int val, dark, sat,i; + double dsum[8], dmin, dmax; + float scale_mul[4], fr, fc; + ushort *img=0, *pix; + +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_SCALE_COLORS,0,2); +#endif + + FORC4 cblack[c] += black; + if (user_mul[0]) + memcpy (pre_mul, user_mul, sizeof pre_mul); + if (use_auto_wb || (use_camera_wb && cam_mul[0] == -1)) { + memset (dsum, 0, sizeof dsum); + bottom = MIN (greybox[1]+greybox[3], height); + right = MIN (greybox[0]+greybox[2], width); + for (row=greybox[1]; row < bottom; row += 8) + for (col=greybox[0]; col < right; col += 8) { + memset (sum, 0, sizeof sum); + for (y=row; y < row+8 && y < bottom; y++) + for (x=col; x < col+8 && x < right; x++) + FORC4 { + if (filters) { + c = FC(y,x); + val = BAYER(y,x); + } else + val = image[y*width+x][c]; + if (val > maximum-25) goto skip_block; + if ((val -= cblack[c]) < 0) val = 0; + sum[c] += val; + sum[c+4]++; + if (filters) break; + } + FORC(8) dsum[c] += sum[c]; +skip_block: ; + } + FORC4 if (dsum[c]) pre_mul[c] = dsum[c+4] / dsum[c]; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.pre_mul_state = LIBRAW_COLORSTATE_CALCULATED; +#endif + } + if (use_camera_wb && cam_mul[0] != -1) { + memset (sum, 0, sizeof sum); + for (row=0; row < 8; row++) + for (col=0; col < 8; col++) { + c = FC(row,col); + if ((val = white[row][col] - cblack[c]) > 0) + sum[c] += val; + sum[c+4]++; + } + if (sum[0] && sum[1] && sum[2] && sum[3]) + { + FORC4 pre_mul[c] = (float) sum[c+4] / sum[c]; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.pre_mul_state = LIBRAW_COLORSTATE_CALCULATED; +#endif + } + else if (cam_mul[0] && cam_mul[2]) + { + memcpy (pre_mul, cam_mul, sizeof pre_mul); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.pre_mul_state =color_flags.pre_mul_state; +#endif + } + else + { +#ifdef LIBRAW_LIBRARY_BUILD + imgdata.process_warnings |= LIBRAW_WARN_BAD_CAMERA_WB; +#endif +#ifdef DCRAW_VERBOSE + fprintf (stderr,_("%s: Cannot use camera white balance.\n"), ifname); +#endif + } + } + if (pre_mul[3] == 0) pre_mul[3] = colors < 4 ? pre_mul[1] : 1; + dark = black; + sat = maximum; + if (threshold) wavelet_denoise(); + maximum -= black; + for (dmin=DBL_MAX, dmax=c=0; c < 4; c++) { + if (dmin > pre_mul[c]) + dmin = pre_mul[c]; + if (dmax < pre_mul[c]) + dmax = pre_mul[c]; + } + if (!highlight) dmax = dmin; + FORC4 scale_mul[c] = (pre_mul[c] /= dmax) * 65535.0 / maximum; +#ifdef DCRAW_VERBOSE + if (verbose) { + fprintf (stderr, + _("Scaling with darkness %d, saturation %d, and\nmultipliers"), dark, sat); + FORC4 fprintf (stderr, " %f", pre_mul[c]); + fputc ('\n', stderr); + } +#endif + + size = iheight*iwidth; +#if defined(LIBRAW_USE_OPENMP) +#pragma omp parallel for private(val) default(shared) +#endif + for (i=0; i < size*4; i++) { + val = image[0][i]; + if (!val) continue; + val -= cblack[i & 3]; + val *= scale_mul[i & 3]; + image[0][i] = CLIP(val); + } + if ((aber[0] != 1 || aber[2] != 1) && colors == 3) { +#ifdef DCRAW_VERBOSE + if (verbose) + fprintf (stderr,_("Correcting chromatic aberration...\n")); +#endif + for (c=0; c < 4; c+=2) { + if (aber[c] == 1) continue; + img = (ushort *) malloc (size * sizeof *img); + merror (img, "scale_colors()"); + for (i=0; i < size; i++) + img[i] = image[i][c]; + for (row=0; row < iheight; row++) { + ur = fr = (row - iheight*0.5) * aber[c] + iheight*0.5; + if (ur > iheight-2) continue; + fr -= ur; + for (col=0; col < iwidth; col++) { + uc = fc = (col - iwidth*0.5) * aber[c] + iwidth*0.5; + if (uc > iwidth-2) continue; + fc -= uc; + pix = img + ur*iwidth + uc; + image[row*iwidth+col][c] = + (pix[ 0]*(1-fc) + pix[ 1]*fc) * (1-fr) + + (pix[iwidth]*(1-fc) + pix[iwidth+1]*fc) * fr; + } + } + free(img); + } + } +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_SCALE_COLORS,1,2); +#endif +} + +void CLASS pre_interpolate() +{ + ushort (*img)[4]; + int row, col, c; + +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_PRE_INTERPOLATE,0,2); +#endif + if (shrink) { + if (half_size) { + height = iheight; + width = iwidth; + } else { + img = (ushort (*)[4]) calloc (height*width, sizeof *img); + merror (img, "pre_interpolate()"); + for (row=0; row < height; row++) + for (col=0; col < width; col++) { + c = fc(row,col); + img[row*width+col][c] = image[(row >> 1)*iwidth+(col >> 1)][c]; + } + free (image); + image = img; + shrink = 0; + } + } + if (filters && colors == 3) { + if (four_color_rgb && colors++) + mix_green = !half_size; + else { + for (row = FC(1,0) >> 1; row < height; row+=2) + for (col = FC(row,1) & 1; col < width; col+=2) + image[row*width+col][1] = image[row*width+col][3]; + filters &= ~((filters & 0x55555555) << 1); + } + } + if (half_size) filters = 0; +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_PRE_INTERPOLATE,1,2); +#endif +} + +void CLASS border_interpolate (int border) +{ + unsigned row, col, y, x, f, c, sum[8]; + + for (row=0; row < height; row++) + for (col=0; col < width; col++) { + if (col==border && row >= border && row < height-border) + col = width-border; + memset (sum, 0, sizeof sum); + for (y=row-1; y != row+2; y++) + for (x=col-1; x != col+2; x++) + if (y < height && x < width) { + f = fc(y,x); + sum[f] += image[y*width+x][f]; + sum[f+4]++; + } + f = fc(row,col); + FORCC if (c != f && sum[c+4]) + image[row*width+col][c] = sum[c] / sum[c+4]; + } +} + +void CLASS lin_interpolate() +{ + int code[16][16][32], *ip, sum[4]; + int c, i, x, y, row, col, shift, color; + ushort *pix; + +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("Bilinear interpolation...\n")); +#endif + +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_INTERPOLATE,0,3); +#endif + border_interpolate(1); + for (row=0; row < 16; row++) + for (col=0; col < 16; col++) { + ip = code[row][col]; + memset (sum, 0, sizeof sum); + for (y=-1; y <= 1; y++) + for (x=-1; x <= 1; x++) { + shift = (y==0) + (x==0); + if (shift == 2) continue; + color = fc(row+y,col+x); + *ip++ = (width*y + x)*4 + color; + *ip++ = shift; + *ip++ = color; + sum[color] += 1 << shift; + } + FORCC + if (c != fc(row,col)) { + *ip++ = c; + *ip++ = 256 / sum[c]; + } + } +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_INTERPOLATE,1,3); +#endif + for (row=1; row < height-1; row++) + for (col=1; col < width-1; col++) { + pix = image[row*width+col]; + ip = code[row & 15][col & 15]; + memset (sum, 0, sizeof sum); + for (i=8; i--; ip+=3) + sum[ip[2]] += pix[ip[0]] << ip[1]; + for (i=colors; --i; ip+=2) + pix[ip[0]] = sum[ip[0]] * ip[1] >> 8; + } +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_INTERPOLATE,2,3); +#endif +} + +/* + This algorithm is officially called: + + "Interpolation using a Threshold-based variable number of gradients" + + described in http://scien.stanford.edu/pages/labsite/1999/psych221/projects/99/tingchen/algodep/vargra.html + + I've extended the basic idea to work with non-Bayer filter arrays. + Gradients are numbered clockwise from NW=0 to W=7. + */ +void CLASS vng_interpolate() +{ + static const signed char *cp, terms[] = { + -2,-2,+0,-1,0,0x01, -2,-2,+0,+0,1,0x01, -2,-1,-1,+0,0,0x01, + -2,-1,+0,-1,0,0x02, -2,-1,+0,+0,0,0x03, -2,-1,+0,+1,1,0x01, + -2,+0,+0,-1,0,0x06, -2,+0,+0,+0,1,0x02, -2,+0,+0,+1,0,0x03, + -2,+1,-1,+0,0,0x04, -2,+1,+0,-1,1,0x04, -2,+1,+0,+0,0,0x06, + -2,+1,+0,+1,0,0x02, -2,+2,+0,+0,1,0x04, -2,+2,+0,+1,0,0x04, + -1,-2,-1,+0,0,0x80, -1,-2,+0,-1,0,0x01, -1,-2,+1,-1,0,0x01, + -1,-2,+1,+0,1,0x01, -1,-1,-1,+1,0,0x88, -1,-1,+1,-2,0,0x40, + -1,-1,+1,-1,0,0x22, -1,-1,+1,+0,0,0x33, -1,-1,+1,+1,1,0x11, + -1,+0,-1,+2,0,0x08, -1,+0,+0,-1,0,0x44, -1,+0,+0,+1,0,0x11, + -1,+0,+1,-2,1,0x40, -1,+0,+1,-1,0,0x66, -1,+0,+1,+0,1,0x22, + -1,+0,+1,+1,0,0x33, -1,+0,+1,+2,1,0x10, -1,+1,+1,-1,1,0x44, + -1,+1,+1,+0,0,0x66, -1,+1,+1,+1,0,0x22, -1,+1,+1,+2,0,0x10, + -1,+2,+0,+1,0,0x04, -1,+2,+1,+0,1,0x04, -1,+2,+1,+1,0,0x04, + +0,-2,+0,+0,1,0x80, +0,-1,+0,+1,1,0x88, +0,-1,+1,-2,0,0x40, + +0,-1,+1,+0,0,0x11, +0,-1,+2,-2,0,0x40, +0,-1,+2,-1,0,0x20, + +0,-1,+2,+0,0,0x30, +0,-1,+2,+1,1,0x10, +0,+0,+0,+2,1,0x08, + +0,+0,+2,-2,1,0x40, +0,+0,+2,-1,0,0x60, +0,+0,+2,+0,1,0x20, + +0,+0,+2,+1,0,0x30, +0,+0,+2,+2,1,0x10, +0,+1,+1,+0,0,0x44, + +0,+1,+1,+2,0,0x10, +0,+1,+2,-1,1,0x40, +0,+1,+2,+0,0,0x60, + +0,+1,+2,+1,0,0x20, +0,+1,+2,+2,0,0x10, +1,-2,+1,+0,0,0x80, + +1,-1,+1,+1,0,0x88, +1,+0,+1,+2,0,0x08, +1,+0,+2,-1,0,0x40, + +1,+0,+2,+1,0,0x10 + }, chood[] = { -1,-1, -1,0, -1,+1, 0,+1, +1,+1, +1,0, +1,-1, 0,-1 }; + ushort (*brow[5])[4], *pix; + int prow=7, pcol=1, *ip, *code[16][16], gval[8], gmin, gmax, sum[4]; + int row, col, x, y, x1, x2, y1, y2, t, weight, grads, color, diag; + int g, diff, thold, num, c; + lin_interpolate(); +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("VNG interpolation...\n")); +#endif + + if (filters == 1) prow = pcol = 15; + ip = (int *) calloc ((prow+1)*(pcol+1), 1280); + merror (ip, "vng_interpolate()"); + for (row=0; row <= prow; row++) /* Precalculate for VNG */ + for (col=0; col <= pcol; col++) { + code[row][col] = ip; + for (cp=terms, t=0; t < 64; t++) { + y1 = *cp++; x1 = *cp++; + y2 = *cp++; x2 = *cp++; + weight = *cp++; + grads = *cp++; + color = fc(row+y1,col+x1); + if (fc(row+y2,col+x2) != color) continue; + diag = (fc(row,col+1) == color && fc(row+1,col) == color) ? 2:1; + if (abs(y1-y2) == diag && abs(x1-x2) == diag) continue; + *ip++ = (y1*width + x1)*4 + color; + *ip++ = (y2*width + x2)*4 + color; + *ip++ = weight; + for (g=0; g < 8; g++) + if (grads & 1< gval[g]) gmin = gval[g]; + if (gmax < gval[g]) gmax = gval[g]; + } + if (gmax == 0) { + memcpy (brow[2][col], pix, sizeof *image); + continue; + } + thold = gmin + (gmax >> 1); + memset (sum, 0, sizeof sum); + color = fc(row,col); + for (num=g=0; g < 8; g++,ip+=2) { /* Average the neighbors */ + if (gval[g] <= thold) { + FORCC + if (c == color && ip[1]) + sum[c] += (pix[c] + pix[ip[1]]) >> 1; + else + sum[c] += pix[ip[0] + c]; + num++; + } + } + FORCC { /* Save to buffer */ + t = pix[color]; + if (c != color) + t += (sum[c] - sum[color]) / num; + brow[2][col][c] = CLIP(t); + } + } + if (row > 3) /* Write buffer to image */ + memcpy (image[(row-2)*width+2], brow[0]+2, (width-4)*sizeof *image); + for (g=0; g < 4; g++) + brow[(g-1) & 3] = brow[g]; + } + memcpy (image[(row-2)*width+2], brow[0]+2, (width-4)*sizeof *image); + memcpy (image[(row-1)*width+2], brow[1]+2, (width-4)*sizeof *image); + free (brow[4]); + free (code[0][0]); +} + +/* + Patterned Pixel Grouping Interpolation by Alain Desbiolles +*/ +void CLASS ppg_interpolate() +{ + int dir[5] = { 1, width, -1, -width, 1 }; + int row, col, diff[2], guess[2], c, d, i; + ushort (*pix)[4]; + + border_interpolate(3); +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("PPG interpolation...\n")); +#endif + +/* Fill in the green layer with gradients and pattern recognition: */ +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_INTERPOLATE,0,3); +#ifdef LIBRAW_USE_OPENMP +#pragma omp parallel for default(shared) private(guess, diff, row, col, d, c, i, pix) schedule(static) +#endif +#endif + for (row=3; row < height-3; row++) + for (col=3+(FC(row,3) & 1), c=FC(row,col); col < width-3; col+=2) { + pix = image + row*width+col; + for (i=0; (d=dir[i]) > 0; i++) { + guess[i] = (pix[-d][1] + pix[0][c] + pix[d][1]) * 2 + - pix[-2*d][c] - pix[2*d][c]; + diff[i] = ( ABS(pix[-2*d][c] - pix[ 0][c]) + + ABS(pix[ 2*d][c] - pix[ 0][c]) + + ABS(pix[ -d][1] - pix[ d][1]) ) * 3 + + ( ABS(pix[ 3*d][1] - pix[ d][1]) + + ABS(pix[-3*d][1] - pix[-d][1]) ) * 2; + } + d = dir[i = diff[0] > diff[1]]; + pix[0][1] = ULIM(guess[i] >> 2, pix[d][1], pix[-d][1]); + } +/* Calculate red and blue for each green pixel: */ +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_INTERPOLATE,1,3); +#ifdef LIBRAW_USE_OPENMP +#pragma omp parallel for default(shared) private(guess, diff, row, col, d, c, i, pix) schedule(static) +#endif +#endif + for (row=1; row < height-1; row++) + for (col=1+(FC(row,2) & 1), c=FC(row,col+1); col < width-1; col+=2) { + pix = image + row*width+col; + for (i=0; (d=dir[i]) > 0; c=2-c, i++) + pix[0][c] = CLIP((pix[-d][c] + pix[d][c] + 2*pix[0][1] + - pix[-d][1] - pix[d][1]) >> 1); + } +/* Calculate blue for red pixels and vice versa: */ +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_INTERPOLATE,2,3); +#ifdef LIBRAW_USE_OPENMP +#pragma omp parallel for default(shared) private(guess, diff, row, col, d, c, i, pix) schedule(static) +#endif +#endif + for (row=1; row < height-1; row++) + for (col=1+(FC(row,1) & 1), c=2-FC(row,col); col < width-1; col+=2) { + pix = image + row*width+col; + for (i=0; (d=dir[i]+dir[i+1]) > 0; i++) { + diff[i] = ABS(pix[-d][c] - pix[d][c]) + + ABS(pix[-d][1] - pix[0][1]) + + ABS(pix[ d][1] - pix[0][1]); + guess[i] = pix[-d][c] + pix[d][c] + 2*pix[0][1] + - pix[-d][1] - pix[d][1]; + } + if (diff[0] != diff[1]) + pix[0][c] = CLIP(guess[diff[0] > diff[1]] >> 1); + else + pix[0][c] = CLIP((guess[0]+guess[1]) >> 2); + } +} + +/* + Adaptive Homogeneity-Directed interpolation is based on + the work of Keigo Hirakawa, Thomas Parks, and Paul Lee. + */ +#define TS 256 /* Tile Size */ +static float dcraw_cbrt[0x10000] = {-1.0f}; + +static inline float calc_64cbrt(float f) +{ + unsigned u; + static float lower = dcraw_cbrt[0]; + static float upper = dcraw_cbrt[0xffff]; + + if (f <= 0) { + return lower; + } + + u = (unsigned) f; + if (u >= 0xffff) { + return upper; + } + return dcraw_cbrt[u]; +} +void CLASS ahd_interpolate_green_h_and_v(int top, int left, ushort (*out_rgb)[TS][TS][3]) +{ + int row, col; + int c, val; + ushort (*pix)[4]; + const int rowlimit = MIN(top+TS, height-2); + const int collimit = MIN(left+TS, width-2); + + for (row = top; row < rowlimit; row++) { + col = left + (FC(row,left) & 1); + for (c = FC(row,col); col < collimit; col+=2) { + pix = image + row*width+col; + val = ((pix[-1][1] + pix[0][c] + pix[1][1]) * 2 + - pix[-2][c] - pix[2][c]) >> 2; + out_rgb[0][row-top][col-left][1] = ULIM(val,pix[-1][1],pix[1][1]); + val = ((pix[-width][1] + pix[0][c] + pix[width][1]) * 2 + - pix[-2*width][c] - pix[2*width][c]) >> 2; + out_rgb[1][row-top][col-left][1] = ULIM(val,pix[-width][1],pix[width][1]); + } + } +} +void CLASS ahd_interpolate_r_and_b_in_rgb_and_convert_to_cielab(int top, int left, ushort (*inout_rgb)[TS][3], short (*out_lab)[TS][3], const float (&xyz_cam)[3][4]) +{ + unsigned row, col; + int c, val; + ushort (*pix)[4]; + ushort (*rix)[3]; + short (*lix)[3]; + float xyz[3]; + const unsigned num_pix_per_row = 4*width; + const unsigned rowlimit = MIN(top+TS-1, height-3); + const unsigned collimit = MIN(left+TS-1, width-3); + ushort *pix_above; + ushort *pix_below; + int t1, t2; + + for (row = top+1; row < rowlimit; row++) { + pix = image + row*width + left; + rix = &inout_rgb[row-top][0]; + lix = &out_lab[row-top][0]; + + for (col = left+1; col < collimit; col++) { + pix++; + pix_above = &pix[0][0] - num_pix_per_row; + pix_below = &pix[0][0] + num_pix_per_row; + rix++; + lix++; + + c = 2 - FC(row, col); + + if (c == 1) { + c = FC(row+1,col); + t1 = 2-c; + val = pix[0][1] + (( pix[-1][t1] + pix[1][t1] + - rix[-1][1] - rix[1][1] ) >> 1); + rix[0][t1] = CLIP(val); + val = pix[0][1] + (( pix_above[c] + pix_below[c] + - rix[-TS][1] - rix[TS][1] ) >> 1); + } else { + t1 = -4+c; /* -4+c: pixel of color c to the left */ + t2 = 4+c; /* 4+c: pixel of color c to the right */ + val = rix[0][1] + (( pix_above[t1] + pix_above[t2] + + pix_below[t1] + pix_below[t2] + - rix[-TS-1][1] - rix[-TS+1][1] + - rix[+TS-1][1] - rix[+TS+1][1] + 1) >> 2); + } + rix[0][c] = CLIP(val); + c = FC(row,col); + rix[0][c] = pix[0][c]; + xyz[0] = xyz[1] = xyz[2] = 0.5; + FORC3 { + /* + * Technically this ought to be FORCC, but the rest of + * ahd_interpolate() assumes 3 colors so let's help the compiler. + */ + xyz[0] += xyz_cam[0][c] * rix[0][c]; + xyz[1] += xyz_cam[1][c] * rix[0][c]; + xyz[2] += xyz_cam[2][c] * rix[0][c]; + } + FORC3 { + xyz[c] = calc_64cbrt(xyz[c]); + } + lix[0][0] = (116 * xyz[1] - 16); + lix[0][1] = 500 * (xyz[0] - xyz[1]); + lix[0][2] = 200 * (xyz[1] - xyz[2]); + } + } +} +void CLASS ahd_interpolate_r_and_b_and_convert_to_cielab(int top, int left, ushort (*inout_rgb)[TS][TS][3], short (*out_lab)[TS][TS][3], const float (&xyz_cam)[3][4]) +{ + int direction; + for (direction = 0; direction < 2; direction++) { + ahd_interpolate_r_and_b_in_rgb_and_convert_to_cielab(top, left, inout_rgb[direction], out_lab[direction], xyz_cam); + } +} +void CLASS ahd_interpolate_build_homogeneity_map(int top, int left, short (*lab)[TS][TS][3], char (*out_homogeneity_map)[TS][2]) +{ + int row, col; + int tr, tc; + int direction; + int i; + short (*lix)[3]; + short (*lixs[2])[3]; + short *adjacent_lix; + unsigned ldiff[2][4], abdiff[2][4], leps, abeps; + static const int dir[4] = { -1, 1, -TS, TS }; + const int rowlimit = MIN(top+TS-2, height-4); + const int collimit = MIN(left+TS-2, width-4); + int homogeneity; + char (*homogeneity_map_p)[2]; + + memset (out_homogeneity_map, 0, 2*TS*TS); + + for (row=top+2; row < rowlimit; row++) { + tr = row-top; + homogeneity_map_p = &out_homogeneity_map[tr][1]; + for (direction=0; direction < 2; direction++) { + lixs[direction] = &lab[direction][tr][1]; + } + + for (col=left+2; col < collimit; col++) { + tc = col-left; + homogeneity_map_p++; + + for (direction=0; direction < 2; direction++) { + lix = ++lixs[direction]; + for (i=0; i < 4; i++) { + adjacent_lix = lix[dir[i]]; + ldiff[direction][i] = ABS(lix[0][0]-adjacent_lix[0]); + abdiff[direction][i] = SQR(lix[0][1]-adjacent_lix[1]) + + SQR(lix[0][2]-adjacent_lix[2]); + } + } + leps = MIN(MAX(ldiff[0][0],ldiff[0][1]), + MAX(ldiff[1][2],ldiff[1][3])); + abeps = MIN(MAX(abdiff[0][0],abdiff[0][1]), + MAX(abdiff[1][2],abdiff[1][3])); + for (direction=0; direction < 2; direction++) { + homogeneity = 0; + for (i=0; i < 4; i++) { + if (ldiff[direction][i] <= leps && abdiff[direction][i] <= abeps) { + homogeneity++; + } + } + homogeneity_map_p[0][direction] = homogeneity; + } + } + } +} +void CLASS ahd_interpolate_combine_homogeneous_pixels(int top, int left, ushort (*rgb)[TS][TS][3], char (*homogeneity_map)[TS][2]) +{ + int row, col; + int tr, tc; + int i, j; + int direction; + int hm[2]; + int c; + const int rowlimit = MIN(top+TS-3, height-5); + const int collimit = MIN(left+TS-3, width-5); + + ushort (*pix)[4]; + ushort (*rix[2])[3]; + + for (row=top+3; row < rowlimit; row++) { + tr = row-top; + pix = &image[row*width+left+2]; + for (direction = 0; direction < 2; direction++) { + rix[direction] = &rgb[direction][tr][2]; + } + + for (col=left+3; col < collimit; col++) { + tc = col-left; + pix++; + for (direction = 0; direction < 2; direction++) { + rix[direction]++; + } + + for (direction=0; direction < 2; direction++) { + hm[direction] = 0; + for (i=tr-1; i <= tr+1; i++) { + for (j=tc-1; j <= tc+1; j++) { + hm[direction] += homogeneity_map[i][j][direction]; + } + } + } + if (hm[0] != hm[1]) { + memcpy(pix[0], rix[hm[1] > hm[0]][0], 3 * sizeof(ushort)); + } else { + FORC3 { + pix[0][c] = (rix[0][0][c] + rix[1][0][c]) >> 1; + } + } + } + } +} +void CLASS ahd_interpolate() +{ + int i, j, k, top, left; + float xyz_cam[3][4],r; + char *buffer; + ushort (*rgb)[TS][TS][3]; + short (*lab)[TS][TS][3]; + char (*homo)[TS][2]; + int terminate_flag = 0; + + if(dcraw_cbrt[0]<-0.1){ + for (i=0x10000-1; i >=0; i--) { + r = i / 65535.0; + dcraw_cbrt[i] = 64.0*(r > 0.008856 ? pow((double)r,1/3.0) : 7.787*r + 16/116.0); + } + } + +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("AHD interpolation...\n")); +#endif + + for (i=0; i < 3; i++) { + for (j=0; j < colors; j++) { + xyz_cam[i][j] = 0; + for (k=0; k < 3; k++) { + xyz_cam[i][j] += xyz_rgb[i][k] * rgb_cam[k][j] / d65_white[i]; + } + } + } + + border_interpolate(5); + +#ifdef LIBRAW_LIBRARY_BUILD +#ifdef LIBRAW_USE_OPENMP +#pragma omp parallel private(buffer,rgb,lab,homo,top,left,i,j,k) shared(xyz_cam,terminate_flag) +#endif +#endif + { + buffer = (char *) malloc (26*TS*TS); /* 1664 kB */ + merror (buffer, "ahd_interpolate()"); + rgb = (ushort(*)[TS][TS][3]) buffer; + lab = (short (*)[TS][TS][3])(buffer + 12*TS*TS); + homo = (char (*)[TS][2]) (buffer + 24*TS*TS); + +#ifdef LIBRAW_LIBRARY_BUILD +#ifdef LIBRAW_USE_OPENMP +#pragma omp for schedule(dynamic) +#endif +#endif + for (top=2; top < height-5; top += TS-6){ +#ifdef LIBRAW_LIBRARY_BUILD +#ifdef LIBRAW_USE_OPENMP + if(0== omp_get_thread_num()) +#endif + if(callbacks.progress_cb) { + int rr = (*callbacks.progress_cb)(callbacks.progresscb_data,LIBRAW_PROGRESS_INTERPOLATE,top-2,height-7); + if(rr) + terminate_flag = 1; + } +#endif + for (left=2; !terminate_flag && (left < width-5); left += TS-6) { + ahd_interpolate_green_h_and_v(top, left, rgb); + ahd_interpolate_r_and_b_and_convert_to_cielab(top, left, rgb, lab, xyz_cam); + ahd_interpolate_build_homogeneity_map(top, left, lab, homo); + ahd_interpolate_combine_homogeneous_pixels(top, left, rgb, homo); + } + } + free (buffer); + } +#ifdef LIBRAW_LIBRARY_BUILD + if(terminate_flag) + throw LIBRAW_EXCEPTION_CANCELLED_BY_CALLBACK; +#endif +} + + + +#undef TS + +void CLASS median_filter() +{ + ushort (*pix)[4]; + int pass, c, i, j, k, med[9]; + static const uchar opt[] = /* Optimal 9-element median search */ + { 1,2, 4,5, 7,8, 0,1, 3,4, 6,7, 1,2, 4,5, 7,8, + 0,3, 5,8, 4,7, 3,6, 1,4, 2,5, 4,7, 4,2, 6,4, 4,2 }; + + for (pass=1; pass <= med_passes; pass++) { +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_MEDIAN_FILTER,pass-1,med_passes); +#endif +#ifdef DCRAW_VERBOSE + if (verbose) + fprintf (stderr,_("Median filter pass %d...\n"), pass); +#endif + for (c=0; c < 3; c+=2) { + for (pix = image; pix < image+width*height; pix++) + pix[0][3] = pix[0][c]; + for (pix = image+width; pix < image+width*(height-1); pix++) { + if ((pix-image+1) % width < 2) continue; + for (k=0, i = -width; i <= width; i += width) + for (j = i-1; j <= i+1; j++) + med[k++] = pix[j][3] - pix[j][1]; + for (i=0; i < sizeof opt; i+=2) + if (med[opt[i]] > med[opt[i+1]]) + SWAP (med[opt[i]] , med[opt[i+1]]); + pix[0][c] = CLIP(med[4] + pix[0][1]); + } + } + } +} + +void CLASS blend_highlights() +{ + int clip=INT_MAX, row, col, c, i, j; + static const float trans[2][4][4] = + { { { 1,1,1 }, { 1.7320508,-1.7320508,0 }, { -1,-1,2 } }, + { { 1,1,1,1 }, { 1,-1,1,-1 }, { 1,1,-1,-1 }, { 1,-1,-1,1 } } }; + static const float itrans[2][4][4] = + { { { 1,0.8660254,-0.5 }, { 1,-0.8660254,-0.5 }, { 1,0,1 } }, + { { 1,1,1,1 }, { 1,-1,1,-1 }, { 1,1,-1,-1 }, { 1,-1,-1,1 } } }; + float cam[2][4], lab[2][4], sum[2], chratio; + + if ((unsigned) (colors-3) > 1) return; +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("Blending highlights...\n")); +#endif + FORCC if (clip > (i = 65535*pre_mul[c])) clip = i; +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_HIGHLIGHTS,0,2); +#endif + for (row=0; row < height; row++) + for (col=0; col < width; col++) { + FORCC if (image[row*width+col][c] > clip) break; + if (c == colors) continue; + FORCC { + cam[0][c] = image[row*width+col][c]; + cam[1][c] = MIN(cam[0][c],clip); + } + for (i=0; i < 2; i++) { + FORCC for (lab[i][c]=j=0; j < colors; j++) + lab[i][c] += trans[colors-3][c][j] * cam[i][j]; + for (sum[i]=0,c=1; c < colors; c++) + sum[i] += SQR(lab[i][c]); + } + chratio = sqrt(sum[1]/sum[0]); + for (c=1; c < colors; c++) + lab[0][c] *= chratio; + FORCC for (cam[0][c]=j=0; j < colors; j++) + cam[0][c] += itrans[colors-3][c][j] * lab[0][j]; + FORCC image[row*width+col][c] = cam[0][c] / colors; + } +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_HIGHLIGHTS,1,2); +#endif +} + +#define SCALE (4 >> shrink) +void CLASS recover_highlights() +{ + float *map, sum, wgt, grow; + int hsat[4], count, spread, change, val, i; + unsigned high, wide, mrow, mcol, row, col, kc, c, d, y, x; + ushort *pixel; + static const signed char dir[8][2] = + { {-1,-1}, {-1,0}, {-1,1}, {0,1}, {1,1}, {1,0}, {1,-1}, {0,-1} }; + +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("Rebuilding highlights...\n")); +#endif + + grow = pow (2.0, 4.0-highlight); + FORCC hsat[c] = 32000 * pre_mul[c]; + for (kc=0, c=1; c < colors; c++) + if (pre_mul[kc] < pre_mul[c]) kc = c; + high = height / SCALE; + wide = width / SCALE; + map = (float *) calloc (high*wide, sizeof *map); + merror (map, "recover_highlights()"); + FORCC if (c != kc) { +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_HIGHLIGHTS,c-1,colors-1); +#endif + memset (map, 0, high*wide*sizeof *map); + for (mrow=0; mrow < high; mrow++) + for (mcol=0; mcol < wide; mcol++) { + sum = wgt = count = 0; + for (row = mrow*SCALE; row < (mrow+1)*SCALE; row++) + for (col = mcol*SCALE; col < (mcol+1)*SCALE; col++) { + pixel = image[row*width+col]; + if (pixel[c] / hsat[c] == 1 && pixel[kc] > 24000) { + sum += pixel[c]; + wgt += pixel[kc]; + count++; + } + } + if (count == SCALE*SCALE) + map[mrow*wide+mcol] = sum / wgt; + } + for (spread = 32/grow; spread--; ) { + for (mrow=0; mrow < high; mrow++) + for (mcol=0; mcol < wide; mcol++) { + if (map[mrow*wide+mcol]) continue; + sum = count = 0; + for (d=0; d < 8; d++) { + y = mrow + dir[d][0]; + x = mcol + dir[d][1]; + if (y < high && x < wide && map[y*wide+x] > 0) { + sum += (1 + (d & 1)) * map[y*wide+x]; + count += 1 + (d & 1); + } + } + if (count > 3) + map[mrow*wide+mcol] = - (sum+grow) / (count+grow); + } + for (change=i=0; i < high*wide; i++) + if (map[i] < 0) { + map[i] = -map[i]; + change = 1; + } + if (!change) break; + } + for (i=0; i < high*wide; i++) + if (map[i] == 0) map[i] = 1; + for (mrow=0; mrow < high; mrow++) + for (mcol=0; mcol < wide; mcol++) { + for (row = mrow*SCALE; row < (mrow+1)*SCALE; row++) + for (col = mcol*SCALE; col < (mcol+1)*SCALE; col++) { + pixel = image[row*width+col]; + if (pixel[c] / hsat[c] > 1) { + val = pixel[kc] * map[mrow*wide+mcol]; + if (pixel[c] < val) pixel[c] = CLIP(val); + } + } + } + } + free (map); +} +#undef SCALE + +void CLASS tiff_get (unsigned base, + unsigned *tag, unsigned *type, unsigned *len, unsigned *save) +{ + *tag = get2(); + *type = get2(); + *len = get4(); + *save = ftell(ifp) + 4; + if (*len * ("11124811248488"[*type < 14 ? *type:0]-'0') > 4) + fseek (ifp, get4()+base, SEEK_SET); +} + +void CLASS parse_thumb_note (int base, unsigned toff, unsigned tlen) +{ + unsigned entries, tag, type, len, save; + + entries = get2(); + while (entries--) { + tiff_get (base, &tag, &type, &len, &save); + if (tag == toff) thumb_offset = get4()+base; + if (tag == tlen) thumb_length = get4(); + fseek (ifp, save, SEEK_SET); + } +} + +void CLASS parse_makernote (int base, int uptag) +{ + static const uchar xlat[2][256] = { + { 0xc1,0xbf,0x6d,0x0d,0x59,0xc5,0x13,0x9d,0x83,0x61,0x6b,0x4f,0xc7,0x7f,0x3d,0x3d, + 0x53,0x59,0xe3,0xc7,0xe9,0x2f,0x95,0xa7,0x95,0x1f,0xdf,0x7f,0x2b,0x29,0xc7,0x0d, + 0xdf,0x07,0xef,0x71,0x89,0x3d,0x13,0x3d,0x3b,0x13,0xfb,0x0d,0x89,0xc1,0x65,0x1f, + 0xb3,0x0d,0x6b,0x29,0xe3,0xfb,0xef,0xa3,0x6b,0x47,0x7f,0x95,0x35,0xa7,0x47,0x4f, + 0xc7,0xf1,0x59,0x95,0x35,0x11,0x29,0x61,0xf1,0x3d,0xb3,0x2b,0x0d,0x43,0x89,0xc1, + 0x9d,0x9d,0x89,0x65,0xf1,0xe9,0xdf,0xbf,0x3d,0x7f,0x53,0x97,0xe5,0xe9,0x95,0x17, + 0x1d,0x3d,0x8b,0xfb,0xc7,0xe3,0x67,0xa7,0x07,0xf1,0x71,0xa7,0x53,0xb5,0x29,0x89, + 0xe5,0x2b,0xa7,0x17,0x29,0xe9,0x4f,0xc5,0x65,0x6d,0x6b,0xef,0x0d,0x89,0x49,0x2f, + 0xb3,0x43,0x53,0x65,0x1d,0x49,0xa3,0x13,0x89,0x59,0xef,0x6b,0xef,0x65,0x1d,0x0b, + 0x59,0x13,0xe3,0x4f,0x9d,0xb3,0x29,0x43,0x2b,0x07,0x1d,0x95,0x59,0x59,0x47,0xfb, + 0xe5,0xe9,0x61,0x47,0x2f,0x35,0x7f,0x17,0x7f,0xef,0x7f,0x95,0x95,0x71,0xd3,0xa3, + 0x0b,0x71,0xa3,0xad,0x0b,0x3b,0xb5,0xfb,0xa3,0xbf,0x4f,0x83,0x1d,0xad,0xe9,0x2f, + 0x71,0x65,0xa3,0xe5,0x07,0x35,0x3d,0x0d,0xb5,0xe9,0xe5,0x47,0x3b,0x9d,0xef,0x35, + 0xa3,0xbf,0xb3,0xdf,0x53,0xd3,0x97,0x53,0x49,0x71,0x07,0x35,0x61,0x71,0x2f,0x43, + 0x2f,0x11,0xdf,0x17,0x97,0xfb,0x95,0x3b,0x7f,0x6b,0xd3,0x25,0xbf,0xad,0xc7,0xc5, + 0xc5,0xb5,0x8b,0xef,0x2f,0xd3,0x07,0x6b,0x25,0x49,0x95,0x25,0x49,0x6d,0x71,0xc7 }, + { 0xa7,0xbc,0xc9,0xad,0x91,0xdf,0x85,0xe5,0xd4,0x78,0xd5,0x17,0x46,0x7c,0x29,0x4c, + 0x4d,0x03,0xe9,0x25,0x68,0x11,0x86,0xb3,0xbd,0xf7,0x6f,0x61,0x22,0xa2,0x26,0x34, + 0x2a,0xbe,0x1e,0x46,0x14,0x68,0x9d,0x44,0x18,0xc2,0x40,0xf4,0x7e,0x5f,0x1b,0xad, + 0x0b,0x94,0xb6,0x67,0xb4,0x0b,0xe1,0xea,0x95,0x9c,0x66,0xdc,0xe7,0x5d,0x6c,0x05, + 0xda,0xd5,0xdf,0x7a,0xef,0xf6,0xdb,0x1f,0x82,0x4c,0xc0,0x68,0x47,0xa1,0xbd,0xee, + 0x39,0x50,0x56,0x4a,0xdd,0xdf,0xa5,0xf8,0xc6,0xda,0xca,0x90,0xca,0x01,0x42,0x9d, + 0x8b,0x0c,0x73,0x43,0x75,0x05,0x94,0xde,0x24,0xb3,0x80,0x34,0xe5,0x2c,0xdc,0x9b, + 0x3f,0xca,0x33,0x45,0xd0,0xdb,0x5f,0xf5,0x52,0xc3,0x21,0xda,0xe2,0x22,0x72,0x6b, + 0x3e,0xd0,0x5b,0xa8,0x87,0x8c,0x06,0x5d,0x0f,0xdd,0x09,0x19,0x93,0xd0,0xb9,0xfc, + 0x8b,0x0f,0x84,0x60,0x33,0x1c,0x9b,0x45,0xf1,0xf0,0xa3,0x94,0x3a,0x12,0x77,0x33, + 0x4d,0x44,0x78,0x28,0x3c,0x9e,0xfd,0x65,0x57,0x16,0x94,0x6b,0xfb,0x59,0xd0,0xc8, + 0x22,0x36,0xdb,0xd2,0x63,0x98,0x43,0xa1,0x04,0x87,0x86,0xf7,0xa6,0x26,0xbb,0xd6, + 0x59,0x4d,0xbf,0x6a,0x2e,0xaa,0x2b,0xef,0xe6,0x78,0xb6,0x4e,0xe0,0x2f,0xdc,0x7c, + 0xbe,0x57,0x19,0x32,0x7e,0x2a,0xd0,0xb8,0xba,0x29,0x00,0x3c,0x52,0x7d,0xa8,0x49, + 0x3b,0x2d,0xeb,0x25,0x49,0xfa,0xa3,0xaa,0x39,0xa7,0xc5,0xa7,0x50,0x11,0x36,0xfb, + 0xc6,0x67,0x4a,0xf5,0xa5,0x12,0x65,0x7e,0xb0,0xdf,0xaf,0x4e,0xb3,0x61,0x7f,0x2f } }; + unsigned offset=0, entries, tag, type, len, save, c; + unsigned ver97=0, serial=0, i, wbi=0, wb[4]={0,0,0,0}; + uchar buf97[324], ci, cj, ck; + short morder, sorder=order; + char buf[10]; +/* + The MakerNote might have its own TIFF header (possibly with + its own byte-order!), or it might just be a table. + */ + if (!strcmp(make,"Nokia")) return; + fread (buf, 1, 10, ifp); + if (!strncmp (buf,"KDK" ,3) || /* these aren't TIFF tables */ + !strncmp (buf,"VER" ,3) || + !strncmp (buf,"IIII",4) || + !strncmp (buf,"MMMM",4)) return; + if (!strncmp (buf,"KC" ,2) || /* Konica KD-400Z, KD-510Z */ + !strncmp (buf,"MLY" ,3)) { /* Minolta DiMAGE G series */ + order = 0x4d4d; + while ((i=ftell(ifp)) < data_offset && i < 16384) { + wb[0] = wb[2]; wb[2] = wb[1]; wb[1] = wb[3]; + wb[3] = get2(); + if (wb[1] == 256 && wb[3] == 256 && + wb[0] > 256 && wb[0] < 640 && wb[2] > 256 && wb[2] < 640) + FORC4 cam_mul[c] = wb[c]; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + goto quit; + } + if (!strcmp (buf,"Nikon")) { + base = ftell(ifp); + order = get2(); + if (get2() != 42) goto quit; + offset = get4(); + fseek (ifp, offset-8, SEEK_CUR); + } else if (!strcmp (buf,"OLYMPUS")) { + base = ftell(ifp)-10; + fseek (ifp, -2, SEEK_CUR); + order = get2(); get2(); + } else if (!strncmp (buf,"SONY",4) || + !strcmp (buf,"Panasonic")) { + goto nf; + } else if (!strncmp (buf,"FUJIFILM",8)) { + base = ftell(ifp)-10; +nf: order = 0x4949; + fseek (ifp, 2, SEEK_CUR); + } else if (!strcmp (buf,"OLYMP") || + !strcmp (buf,"LEICA") || + !strcmp (buf,"Ricoh") || + !strcmp (buf,"EPSON")) + fseek (ifp, -2, SEEK_CUR); + else if (!strcmp (buf,"AOC") || + !strcmp (buf,"QVC")) + fseek (ifp, -4, SEEK_CUR); + else { + fseek (ifp, -10, SEEK_CUR); + if (!strncmp(make,"SAMSUNG",7)) + base = ftell(ifp); + } + entries = get2(); + if (entries > 1000) return; + morder = order; + while (entries--) { + order = morder; + tiff_get (base, &tag, &type, &len, &save); + tag |= uptag << 16; + if (tag == 2 && strstr(make,"NIKON") && !iso_speed) + iso_speed = (get2(),get2()); + if (tag == 4 && len > 26 && len < 35) { + if ((i=(get4(),get2())) != 0x7fff && !iso_speed) + iso_speed = 50 * pow (2.0, i/32.0 - 4); + if ((i=(get2(),get2())) != 0x7fff && !aperture) + aperture = pow (2.0, i/64.0); + if ((i=get2()) != 0xffff && !shutter) + shutter = pow (2.0, (short) i/-32.0); + wbi = (get2(),get2()); + shot_order = (get2(),get2()); + } + if ((tag == 4 || tag == 0x114) && !strncmp(make,"KONICA",6)) { + fseek (ifp, tag == 4 ? 140:160, SEEK_CUR); + switch (get2()) { + case 72: flip = 0; break; + case 76: flip = 6; break; + case 82: flip = 5; break; + } + } + if (tag == 7 && type == 2 && len > 20) + fgets (model2, 64, ifp); + if (tag == 8 && type == 4) + shot_order = get4(); + if (tag == 9 && !strcmp(make,"Canon")) + fread (artist, 64, 1, ifp); + if (tag == 0xc && len == 4) { + cam_mul[0] = getreal(type); + cam_mul[2] = getreal(type); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + if (tag == 0xd && type == 7 && get2() == 0xaaaa) { + for (c=i=2; (ushort) c != 0xbbbb && i < len; i++) + c = c << 8 | fgetc(ifp); + while ((i+=4) < len-5) + if (get4() == 257 && (i=len) && (c = (get4(),fgetc(ifp))) < 3) + flip = "065"[c]-'0'; + } + if (tag == 0x10 && type == 4) + unique_id = get4(); + if (tag == 0x11 && is_raw && !strncmp(make,"NIKON",5)) { + fseek (ifp, get4()+base, SEEK_SET); + parse_tiff_ifd (base); + } + if (tag == 0x14 && type == 7) { + if (len == 2560) { + fseek (ifp, 1248, SEEK_CUR); + goto get2_256; + } + fread (buf, 1, 10, ifp); + if (!strncmp(buf,"NRW ",4)) { + fseek (ifp, strcmp(buf+4,"0100") ? 46:1546, SEEK_CUR); + cam_mul[0] = get4() << 2; + cam_mul[1] = get4() + get4(); + cam_mul[2] = get4() << 2; + } + } + if (tag == 0x15 && type == 2 && is_raw) + fread (model, 64, 1, ifp); + if (strstr(make,"PENTAX")) { + if (tag == 0x1b) tag = 0x1018; + if (tag == 0x1c) tag = 0x1017; + } + if (tag == 0x1d) + while ((c = fgetc(ifp)) && c != EOF) + serial = serial*10 + (isdigit(c) ? c - '0' : c % 10); + if (tag == 0x81 && type == 4) { + data_offset = get4(); + fseek (ifp, data_offset + 41, SEEK_SET); + raw_height = get2() * 2; + raw_width = get2(); + filters = 0x61616161; + } + if (tag == 0x29 && type == 1) { + c = wbi < 18 ? "012347800000005896"[wbi]-'0' : 0; + fseek (ifp, 8 + c*32, SEEK_CUR); + FORC4 cam_mul[c ^ (c >> 1) ^ 1] = get4(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + if ((tag == 0x81 && type == 7) || + (tag == 0x100 && type == 7) || + (tag == 0x280 && type == 1)) { + thumb_offset = ftell(ifp); + thumb_length = len; + } + if (tag == 0x88 && type == 4 && (thumb_offset = get4())) + thumb_offset += base; + if (tag == 0x89 && type == 4) + thumb_length = get4(); + if (tag == 0x8c || tag == 0x96) + meta_offset = ftell(ifp); + if (tag == 0x97) { + for (i=0; i < 4; i++) + ver97 = ver97 * 10 + fgetc(ifp)-'0'; + switch (ver97) { + case 100: + fseek (ifp, 68, SEEK_CUR); + FORC4 cam_mul[(c >> 1) | ((c & 1) << 1)] = get2(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + break; + case 102: + fseek (ifp, 6, SEEK_CUR); + goto get2_rggb; + case 103: + fseek (ifp, 16, SEEK_CUR); + FORC4 cam_mul[c] = get2(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + if (ver97 >= 200) { + if (ver97 != 205) fseek (ifp, 280, SEEK_CUR); + fread (buf97, 324, 1, ifp); + } + } + if (tag == 0xa1 && type == 7) { + order = 0x4949; + fseek (ifp, 140, SEEK_CUR); + FORC3 cam_mul[c] = get4(); + } + if (tag == 0xa4 && type == 3) { + fseek (ifp, wbi*48, SEEK_CUR); + FORC3 cam_mul[c] = get2(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + if (tag == 0xa7 && (unsigned) (ver97-200) < 17) { + ci = xlat[0][serial & 0xff]; + cj = xlat[1][fgetc(ifp)^fgetc(ifp)^fgetc(ifp)^fgetc(ifp)]; + ck = 0x60; + for (i=0; i < 324; i++) + buf97[i] ^= (cj += ci * ck++); + i = "66666>666;6A;:;55"[ver97-200] - '0'; + FORC4 cam_mul[c ^ (c >> 1) ^ (i & 1)] = + sget2 (buf97 + (i & -2) + c*2); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + if (tag == 0x200 && len == 3) + shot_order = (get4(),get4()); + if (tag == 0x200 && len == 4) + FORC4 cblack[c ^ c >> 1] = get2(); + if (tag == 0x201 && len == 4) + goto get2_rggb; + if (tag == 0x220 && type == 7) + meta_offset = ftell(ifp); + if (tag == 0x401 && type == 4 && len == 4) + FORC4 cblack[c ^ c >> 1] = get4(); + if (tag == 0xe01) { /* Nikon Capture Note */ + order = 0x4949; + fseek (ifp, 22, SEEK_CUR); + for (offset=22; offset+22 < len; offset += 22+i) { + tag = get4(); + fseek (ifp, 14, SEEK_CUR); + i = get4()-4; + if (tag == 0x76a43207) flip = get2(); + else fseek (ifp, i, SEEK_CUR); + } + } + if (tag == 0xe80 && len == 256 && type == 7) { + fseek (ifp, 48, SEEK_CUR); + cam_mul[0] = get2() * 508 * 1.078 / 0x10000; + cam_mul[2] = get2() * 382 * 1.173 / 0x10000; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + if (tag == 0xf00 && type == 7) { + if (len == 614) + fseek (ifp, 176, SEEK_CUR); + else if (len == 734 || len == 1502) + fseek (ifp, 148, SEEK_CUR); + else goto next; + goto get2_256; + } + if ((tag == 0x1011 && len == 9) || tag == 0x20400200) + { + for (i=0; i < 3; i++) + FORC3 cmatrix[i][c] = ((short) get2()) / 256.0; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cmatrix_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + if ((tag == 0x1012 || tag == 0x20400600) && len == 4) + FORC4 cblack[c ^ c >> 1] = get2(); + if (tag == 0x1017 || tag == 0x20400100) + { + cam_mul[0] = get2() / 256.0; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + if (tag == 0x1018 || tag == 0x20400100) + { + cam_mul[2] = get2() / 256.0; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + if (tag == 0x2011 && len == 2) { +get2_256: + order = 0x4d4d; + cam_mul[0] = get2() / 256.0; + cam_mul[2] = get2() / 256.0; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + if ((tag | 0x70) == 0x2070 && type == 4) + fseek (ifp, get4()+base, SEEK_SET); + if (tag == 0x2010 && type != 7) + load_raw = &CLASS olympus_load_raw; + if (tag == 0x2020) + parse_thumb_note (base, 257, 258); + if (tag == 0x2040) + parse_makernote (base, 0x2040); + if (tag == 0xb028) { + fseek (ifp, get4()+base, SEEK_SET); + parse_thumb_note (base, 136, 137); + } + if (tag == 0x4001 && len > 500) { + i = len == 582 ? 50 : len == 653 ? 68 : len == 5120 ? 142 : 126; + fseek (ifp, i, SEEK_CUR); +get2_rggb: + FORC4 cam_mul[c ^ (c >> 1)] = get2(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif +#if 1 + i = len == 1312 ? 112:22; + fseek (ifp, i, SEEK_CUR); +#else + fseek (ifp, 22, SEEK_CUR); +#endif + FORC4 sraw_mul[c ^ (c >> 1)] = get2(); + } + if (tag == 0xa021) + FORC4 cam_mul[c ^ (c >> 1)] = get4(); + if (tag == 0xa028) + FORC4 cam_mul[c ^ (c >> 1)] -= get4(); +next: + fseek (ifp, save, SEEK_SET); + } +quit: + order = sorder; +} + +/* + Since the TIFF DateTime string has no timezone information, + assume that the camera's clock was set to Universal Time. + */ +void CLASS get_timestamp (int reversed) +{ + struct tm t; + char str[20]; + int i; + + str[19] = 0; + if (reversed) + for (i=19; i--; ) str[i] = fgetc(ifp); + else + fread (str, 19, 1, ifp); + memset (&t, 0, sizeof t); + if (sscanf (str, "%d:%d:%d %d:%d:%d", &t.tm_year, &t.tm_mon, + &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec) != 6) + return; + t.tm_year -= 1900; + t.tm_mon -= 1; + t.tm_isdst = -1; + if (mktime(&t) > 0) + timestamp = mktime(&t); +} + +void CLASS parse_exif (int base) +{ + unsigned kodak, entries, tag, type, len, save, c; + double expo; + + kodak = !strncmp(make,"EASTMAN",7) && tiff_nifds < 3; + entries = get2(); + while (entries--) { + tiff_get (base, &tag, &type, &len, &save); + switch (tag) { + case 33434: shutter = getreal(type); break; + case 33437: aperture = getreal(type); break; + case 34855: iso_speed = get2(); break; + case 36867: + case 36868: get_timestamp(0); break; + case 37377: if ((expo = -getreal(type)) < 128) + shutter = pow (2.0, expo); break; + case 37378: aperture = pow (2.0, getreal(type)/2); break; + case 37386: focal_len = getreal(type); break; + case 37500: parse_makernote (base, 0); break; + case 40962: if (kodak) raw_width = get4(); break; + case 40963: if (kodak) raw_height = get4(); break; + case 41730: + if (get4() == 0x20002) + for (exif_cfa=c=0; c < 8; c+=2) + exif_cfa |= fgetc(ifp) * 0x01010101 << c; + } + fseek (ifp, save, SEEK_SET); + } +} + +void CLASS parse_gps (int base) +{ + unsigned entries, tag, type, len, save, c; + + entries = get2(); + while (entries--) { + tiff_get (base, &tag, &type, &len, &save); + switch (tag) { + case 1: case 3: case 5: + gpsdata[29+tag/2] = getc(ifp); break; + case 2: case 4: case 7: + FORC(6) gpsdata[tag/3*6+c] = get4(); break; + case 6: + FORC(2) gpsdata[18+c] = get4(); break; + case 18: case 29: + fgets ((char *) (gpsdata+14+tag/3), MIN(len,12), ifp); + } + fseek (ifp, save, SEEK_SET); + } +} + +void CLASS romm_coeff (float romm_cam[3][3]) +{ + static const float rgb_romm[3][3] = /* ROMM == Kodak ProPhoto */ + { { 2.034193, -0.727420, -0.306766 }, + { -0.228811, 1.231729, -0.002922 }, + { -0.008565, -0.153273, 1.161839 } }; + int i, j, k; + + for (i=0; i < 3; i++) + for (j=0; j < 3; j++) + for (cmatrix[i][j] = k=0; k < 3; k++) + cmatrix[i][j] += rgb_romm[i][k] * romm_cam[k][j]; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cmatrix_state = LIBRAW_COLORSTATE_CALCULATED; +#endif +} + +void CLASS parse_mos (int offset) +{ + char data[40]; + int skip, from, i, c, neut[4], planes=0, frot=0; + static const char *mod[] = + { "","DCB2","Volare","Cantare","CMost","Valeo 6","Valeo 11","Valeo 22", + "Valeo 11p","Valeo 17","","Aptus 17","Aptus 22","Aptus 75","Aptus 65", + "Aptus 54S","Aptus 65S","Aptus 75S","AFi 5","AFi 6","AFi 7", + "AFi-II 7","","","AFi-II 6","","","AFi-II 10","AFi-II 5" + "","","","","","AFi-II 10R","AFi-II 8","","AFi-II 12"}; + + float romm_cam[3][3]; + + fseek (ifp, offset, SEEK_SET); + while (1) { + if (get4() != 0x504b5453) break; + get4(); + fread (data, 1, 40, ifp); + skip = get4(); + from = ftell(ifp); + if (!strcmp(data,"JPEG_preview_data")) { + thumb_offset = from; + thumb_length = skip; + } + if (!strcmp(data,"icc_camera_profile")) { + profile_offset = from; + profile_length = skip; + } + if (!strcmp(data,"ShootObj_back_type")) { + fscanf (ifp, "%d", &i); + if ((unsigned) i < sizeof mod / sizeof (*mod)) + strcpy (model, mod[i]); + } + if (!strcmp(data,"icc_camera_to_tone_matrix")) { + for (i=0; i < 9; i++) + romm_cam[0][i] = int_to_float(get4()); + romm_coeff (romm_cam); + } + if (!strcmp(data,"CaptProf_color_matrix")) { + for (i=0; i < 9; i++) + fscanf (ifp, "%f", &romm_cam[0][i]); + romm_coeff (romm_cam); + } + if (!strcmp(data,"CaptProf_number_of_planes")) + fscanf (ifp, "%d", &planes); + if (!strcmp(data,"CaptProf_raw_data_rotation")) + fscanf (ifp, "%d", &flip); + if (!strcmp(data,"CaptProf_mosaic_pattern")) + FORC4 { + fscanf (ifp, "%d", &i); + if (i == 1) frot = c ^ (c >> 1); + } + if (!strcmp(data,"ImgProf_rotation_angle")) { + fscanf (ifp, "%d", &i); + flip = i - flip; + } + if (!strcmp(data,"NeutObj_neutrals") && !cam_mul[0]) { + FORC4 fscanf (ifp, "%d", neut+c); + FORC3 cam_mul[c] = (float) neut[0] / neut[c+1]; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + if (!strcmp(data,"Rows_data")) + load_flags = get4(); + parse_mos (from); + fseek (ifp, skip+from, SEEK_SET); + } + if (planes) + filters = (planes == 1) * 0x01010101 * + (uchar) "\x94\x61\x16\x49"[(flip/90 + frot) & 3]; +} + +void CLASS linear_table (unsigned len) +{ + int i; + if (len > 0x1000) len = 0x1000; + read_shorts (curve, len); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.curve_state = LIBRAW_COLORSTATE_LOADED; +#endif + for (i=len; i < 0x1000; i++) + curve[i] = curve[i-1]; + maximum = curve[0xfff]; +} + +void CLASS parse_kodak_ifd (int base) +{ + unsigned entries, tag, type, len, save; + int i, c, wbi=-2, wbtemp=6500; + float mul[3]={1,1,1}, num; + static const int wbtag[] = { 64037,64040,64039,64041,-1,-1,64042 }; + + entries = get2(); + if (entries > 1024) return; + while (entries--) { + tiff_get (base, &tag, &type, &len, &save); + if (tag == 1020) wbi = getint(type); + if (tag == 1021 && len == 72) { /* WB set in software */ + fseek (ifp, 40, SEEK_CUR); + FORC3 cam_mul[c] = 2048.0 / get2(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + wbi = -2; + } + if (tag == 2118) wbtemp = getint(type); + if (tag == 2130 + wbi) + FORC3 mul[c] = getreal(type); + if (tag == 2140 + wbi && wbi >= 0) + { + FORC3 { + for (num=i=0; i < 4; i++) + num += getreal(type) * pow (wbtemp/100.0, i); + cam_mul[c] = 2048 / (num * mul[c]); + } +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + if (tag == 2317) linear_table (len); + if (tag == 6020) iso_speed = getint(type); + if (tag == 64013) wbi = fgetc(ifp); + if ((unsigned) wbi < 7 && tag == wbtag[wbi]) + FORC3 cam_mul[c] = get4(); + if (tag == 64019) width = getint(type); + if (tag == 64020) height = (getint(type)+1) & -2; + fseek (ifp, save, SEEK_SET); + } +} + +int CLASS parse_tiff_ifd (int base) +{ + unsigned entries, tag, type, len, plen=16, save; + int ifd, use_cm=0, cfa, i, j, c, ima_len=0; + int blrr=1, blrc=1, dblack[] = { 0,0,0,0 }; + char software[64], *cbuf, *cp; + uchar cfa_pat[16], cfa_pc[] = { 0,1,2,3 }, tab[256]; + double cc[4][4], cm[4][3], cam_xyz[4][3], num; + double ab[]={ 1,1,1,1 }, asn[] = { 0,0,0,0 }, xyz[] = { 1,1,1 }; + unsigned sony_curve[] = { 0,0,0,0,0,4095 }; + unsigned *buf, sony_offset=0, sony_length=0, sony_key=0; + struct jhead jh; +#ifndef LIBRAW_LIBRARY_BUILD + FILE *sfp; +#endif + + if (tiff_nifds >= sizeof tiff_ifd / sizeof tiff_ifd[0]) + return 1; + ifd = tiff_nifds++; + for (j=0; j < 4; j++) + for (i=0; i < 4; i++) + cc[j][i] = i == j; + entries = get2(); + if (entries > 512) return 1; + while (entries--) { + tiff_get (base, &tag, &type, &len, &save); + switch (tag) { + case 5: width = get2(); break; + case 6: height = get2(); break; + case 7: width += get2(); break; + case 9: filters = get2(); break; + case 17: case 18: + if (type == 3 && len == 1) + { + cam_mul[(tag-17)*2] = get2() / 256.0; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + break; + case 23: + if (type == 3) iso_speed = get2(); + break; + case 36: case 37: case 38: + cam_mul[tag-0x24] = get2(); + break; + case 39: + if (len < 50 || cam_mul[0]) break; + fseek (ifp, 12, SEEK_CUR); + FORC3 cam_mul[c] = get2(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + break; + case 46: + if (type != 7 || fgetc(ifp) != 0xff || fgetc(ifp) != 0xd8) break; + thumb_offset = ftell(ifp) - 2; + thumb_length = len; + break; + case 61440: /* Fuji HS10 table */ + parse_tiff_ifd (base); + break; + case 2: case 256: case 61441: /* ImageWidth */ + tiff_ifd[ifd].t_width = getint(type); + break; + case 3: case 257: case 61442: /* ImageHeight */ + tiff_ifd[ifd].t_height = getint(type); + break; + case 258: /* BitsPerSample */ + case 61443: + tiff_ifd[ifd].samples = len & 7; + tiff_ifd[ifd].bps = getint(type); + break; + case 61446: + raw_height = 0; + load_raw = &CLASS packed_load_raw; + load_flags = get4() && (filters=0x16161616) ? 24:80; + break; + case 259: /* Compression */ + tiff_ifd[ifd].comp = getint(type); + break; + case 262: /* PhotometricInterpretation */ + tiff_ifd[ifd].phint = get2(); + break; + case 270: /* ImageDescription */ + fread (desc, 512, 1, ifp); + break; + case 271: /* Make */ + fgets (make, 64, ifp); + break; + case 272: /* Model */ + fgets (model, 64, ifp); + break; + case 280: /* Panasonic RW2 offset */ + if (type != 4) break; + load_raw = &CLASS panasonic_load_raw; + load_flags = 0x2008; + case 273: /* StripOffset */ + case 513: /* JpegIFOffset */ + case 61447: + tiff_ifd[ifd].offset = get4()+base; + if (!tiff_ifd[ifd].bps && tiff_ifd[ifd].offset > 0) { + fseek (ifp, tiff_ifd[ifd].offset, SEEK_SET); + if (ljpeg_start (&jh, 1)) { + tiff_ifd[ifd].comp = 6; + tiff_ifd[ifd].t_width = jh.wide; + tiff_ifd[ifd].t_height = jh.high; + tiff_ifd[ifd].bps = jh.bits; + tiff_ifd[ifd].samples = jh.clrs; + if (!(jh.sraw || (jh.clrs & 1))) + tiff_ifd[ifd].t_width *= jh.clrs; + i = order; + parse_tiff (tiff_ifd[ifd].offset + 12); + order = i; + } + } + break; + case 274: /* Orientation */ + tiff_ifd[ifd].t_flip = "50132467"[get2() & 7]-'0'; + break; + case 277: /* SamplesPerPixel */ + tiff_ifd[ifd].samples = getint(type) & 7; + break; + case 279: /* StripByteCounts */ + case 514: + case 61448: + tiff_ifd[ifd].bytes = get4(); + break; + case 61454: + FORC3 cam_mul[(4-c) % 3] = getint(type); + break; + case 305: case 11: /* Software */ + fgets (software, 64, ifp); + if (!strncmp(software,"Adobe",5) || + !strncmp(software,"dcraw",5) || + !strncmp(software,"UFRaw",5) || + !strncmp(software,"Bibble",6) || + !strncmp(software,"Nikon Scan",10) || + !strcmp (software,"Digital Photo Professional")) + is_raw = 0; + break; + case 306: /* DateTime */ + get_timestamp(0); + break; + case 315: /* Artist */ + fread (artist, 64, 1, ifp); + break; + case 322: /* TileWidth */ + tile_width = getint(type); + break; + case 323: /* TileLength */ + tile_length = getint(type); + break; + case 324: /* TileOffsets */ + tiff_ifd[ifd].offset = len > 1 ? ftell(ifp) : get4(); + if (len == 4) { + load_raw = &CLASS sinar_4shot_load_raw; + is_raw = 5; + } + break; +#ifdef LIBRAW_LIBRARY_BUILD + case 325: /* TileByteCount */ + tiff_ifd[ifd].tile_maxbytes = 0; + for(int jj=0;jj tiff_ifd[ifd].tile_maxbytes) tiff_ifd[ifd].tile_maxbytes=s; + } + break; +#endif + case 330: /* SubIFDs */ + if (!strcmp(model,"DSLR-A100") && tiff_ifd[ifd].t_width == 3872) { + load_raw = &CLASS sony_arw_load_raw; + data_offset = get4()+base; + ifd++; break; + } + while (len--) { + i = ftell(ifp); + fseek (ifp, get4()+base, SEEK_SET); + if (parse_tiff_ifd (base)) break; + fseek (ifp, i+4, SEEK_SET); + } + break; + case 400: + strcpy (make, "Sarnoff"); + maximum = 0xfff; + break; + case 28688: + FORC4 sony_curve[c+1] = get2() >> 2 & 0xfff; + for (i=0; i < 5; i++) + for (j = sony_curve[i]+1; j <= sony_curve[i+1]; j++) + curve[j] = curve[j-1] + (1 << i); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.curve_state = LIBRAW_COLORSTATE_LOADED; +#endif + break; + case 29184: sony_offset = get4(); break; + case 29185: sony_length = get4(); break; + case 29217: sony_key = get4(); break; + case 29264: + parse_minolta (ftell(ifp)); + raw_width = 0; + break; + case 29443: + FORC4 cam_mul[c ^ (c < 2)] = get2(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + break; + case 29459: + FORC4 cam_mul[c] = get2(); + i = (cam_mul[1] == 1024 && cam_mul[2] == 1024) << 1; + SWAP (cam_mul[i],cam_mul[i+1]) +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + break; + case 33405: /* Model2 */ + fgets (model2, 64, ifp); + break; + case 33422: /* CFAPattern */ + case 64777: /* Kodak P-series */ + if ((plen=len) > 16) plen = 16; + fread (cfa_pat, 1, plen, ifp); + for (colors=cfa=i=0; i < plen; i++) { + colors += !(cfa & (1 << cfa_pat[i])); + cfa |= 1 << cfa_pat[i]; + } + if (cfa == 070) memcpy (cfa_pc,"\003\004\005",3); /* CMY */ + if (cfa == 072) memcpy (cfa_pc,"\005\003\004\001",4); /* GMCY */ + goto guess_cfa_pc; + case 33424: + case 65024: + fseek (ifp, get4()+base, SEEK_SET); + parse_kodak_ifd (base); + break; + case 33434: /* ExposureTime */ + shutter = getreal(type); + break; + case 33437: /* FNumber */ + aperture = getreal(type); + break; + case 34306: /* Leaf white balance */ + FORC4 cam_mul[c ^ 1] = 4096.0 / get2(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + break; + case 34307: /* Leaf CatchLight color matrix */ + fread (software, 1, 7, ifp); + if (strncmp(software,"MATRIX",6)) break; + colors = 4; + for (raw_color = i=0; i < 3; i++) { + FORC4 fscanf (ifp, "%f", &rgb_cam[i][c^1]); + if (!use_camera_wb) continue; + num = 0; + FORC4 num += rgb_cam[i][c]; + FORC4 rgb_cam[i][c] /= num; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.rgb_cam_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + break; + case 34310: /* Leaf metadata */ + parse_mos (ftell(ifp)); + case 34303: + strcpy (make, "Leaf"); + break; + case 34665: /* EXIF tag */ + fseek (ifp, get4()+base, SEEK_SET); + parse_exif (base); + break; + case 34853: /* GPSInfo tag */ + fseek (ifp, get4()+base, SEEK_SET); + parse_gps (base); + break; + case 34675: /* InterColorProfile */ + case 50831: /* AsShotICCProfile */ + profile_offset = ftell(ifp); + profile_length = len; + break; + case 37122: /* CompressedBitsPerPixel */ + kodak_cbpp = get4(); + break; + case 37386: /* FocalLength */ + focal_len = getreal(type); + break; + case 37393: /* ImageNumber */ + shot_order = getint(type); + break; + case 37400: /* old Kodak KDC tag */ + for (raw_color = i=0; i < 3; i++) { + getreal(type); + FORC3 rgb_cam[i][c] = getreal(type); + } +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.rgb_cam_state = LIBRAW_COLORSTATE_LOADED; +#endif + break; + case 46275: /* Imacon tags */ + strcpy (make, "Imacon"); + data_offset = ftell(ifp); + ima_len = len; + break; + case 46279: + if (!ima_len) break; + fseek (ifp, 38, SEEK_CUR); + case 46274: + fseek (ifp, 40, SEEK_CUR); + raw_width = get4(); + raw_height = get4(); + left_margin = get4() & 7; + width = raw_width - left_margin - (get4() & 7); + top_margin = get4() & 7; + height = raw_height - top_margin - (get4() & 7); + if (raw_width == 7262) { + height = 5444; + width = 7244; + left_margin = 7; + } + fseek (ifp, 52, SEEK_CUR); + FORC3 cam_mul[c] = getreal(11); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + fseek (ifp, 114, SEEK_CUR); + flip = (get2() >> 7) * 90; + if (width * height * 6 == ima_len) { +#if 1 + if (flip % 180 == 90) SWAP(width,height); + filters = flip = 0; +#else + if (flip % 180 == 90) SWAP(width,height); + raw_width = width; + raw_height = height; + left_margin = top_margin = filters = flip = 0; +#endif + } + sprintf (model, "Ixpress %d-Mp", height*width/1000000); + load_raw = &CLASS imacon_full_load_raw; + if (filters) { + if (left_margin & 1) filters = 0x61616161; + load_raw = &CLASS unpacked_load_raw; + } + maximum = 0xffff; + break; + case 50454: /* Sinar tag */ + case 50455: + if (!(cbuf = (char *) malloc(len))) break; + fread (cbuf, 1, len, ifp); + for (cp = cbuf-1; cp && cp < cbuf+len; cp = strchr(cp,'\n')) + if (!strncmp (++cp,"Neutral ",8)) + { + sscanf (cp+8, "%f %f %f", cam_mul, cam_mul+1, cam_mul+2); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + free (cbuf); + break; + case 50458: + if (!make[0]) strcpy (make, "Hasselblad"); + break; + case 50459: /* Hasselblad tag */ + i = order; + j = ftell(ifp); + c = tiff_nifds; + order = get2(); + fseek (ifp, j+(get2(),get4()), SEEK_SET); + parse_tiff_ifd (j); + maximum = 0xffff; + tiff_nifds = c; + order = i; + break; + case 50706: /* DNGVersion */ + FORC4 dng_version = (dng_version << 8) + fgetc(ifp); + if (!make[0]) strcpy (make, "DNG"); + is_raw = 1; + break; + case 50710: /* CFAPlaneColor */ + if (len > 4) len = 4; + colors = len; + fread (cfa_pc, 1, colors, ifp); +guess_cfa_pc: + FORCC tab[cfa_pc[c]] = c; + cdesc[c] = 0; + for (i=16; i--; ) + filters = filters << 2 | tab[cfa_pat[i % plen]]; + break; + case 50711: /* CFALayout */ + if (get2() == 2) { + fuji_width = 1; + filters = 0x49494949; + } + break; + case 291: + case 50712: /* LinearizationTable */ + linear_table (len); + break; + case 50713: /* BlackLevelRepeatDim */ + blrr = get2(); + blrc = get2(); + break; + case 61450: + blrr = blrc = 2; + case 50714: /* BlackLevel */ + black = getreal(type); + if (!filters || !~filters) break; + dblack[0] = black; + dblack[1] = (blrc == 2) ? getreal(type):dblack[0]; + dblack[2] = (blrr == 2) ? getreal(type):dblack[0]; + dblack[3] = (blrc == 2 && blrr == 2) ? getreal(type):dblack[1]; + if (colors == 3) + filters |= ((filters >> 2 & 0x22222222) | + (filters << 2 & 0x88888888)) & filters << 1; + FORC4 cblack[filters >> (c << 1) & 3] = dblack[c]; + black = 0; + break; + case 50715: /* BlackLevelDeltaH */ + case 50716: /* BlackLevelDeltaV */ + for (num=i=0; i < len; i++) + num += getreal(type); + black += num/len + 0.5; + break; + case 50717: /* WhiteLevel */ + maximum = getint(type); + break; + case 50718: /* DefaultScale */ + pixel_aspect = getreal(type); + pixel_aspect /= getreal(type); + break; + case 50721: /* ColorMatrix1 */ + case 50722: /* ColorMatrix2 */ + FORCC for (j=0; j < 3; j++) + cm[c][j] = getreal(type); + use_cm = 1; + break; + case 50723: /* CameraCalibration1 */ + case 50724: /* CameraCalibration2 */ + for (i=0; i < colors; i++) + FORCC cc[i][c] = getreal(type); + break; + case 50727: /* AnalogBalance */ + FORCC ab[c] = getreal(type); + break; + case 50728: /* AsShotNeutral */ + FORCC asn[c] = getreal(type); + break; + case 50729: /* AsShotWhiteXY */ + xyz[0] = getreal(type); + xyz[1] = getreal(type); + xyz[2] = 1 - xyz[0] - xyz[1]; + FORC3 xyz[c] /= d65_white[c]; + break; + case 50740: /* DNGPrivateData */ + if (dng_version) break; + parse_minolta (j = get4()+base); + fseek (ifp, j, SEEK_SET); + parse_tiff_ifd (base); + break; + case 50752: + read_shorts (cr2_slice, 3); + break; + case 50829: /* ActiveArea */ + top_margin = getint(type); + left_margin = getint(type); + height = getint(type) - top_margin; + width = getint(type) - left_margin; + break; +#if 0 + case 51009: /* OpcodeList2 */ + meta_offset = ftell(ifp); + break; +#endif + case 64772: /* Kodak P-series */ + if (len < 13) break; + fseek (ifp, 16, SEEK_CUR); + data_offset = get4(); + fseek (ifp, 28, SEEK_CUR); + data_offset += get4(); + load_raw = &CLASS packed_load_raw; + break; + case 65026: + if (type == 2) fgets (model2, 64, ifp); + } + fseek (ifp, save, SEEK_SET); + } + if (sony_length && (buf = (unsigned *) malloc(sony_length))) { + fseek (ifp, sony_offset, SEEK_SET); + fread (buf, sony_length, 1, ifp); + sony_decrypt (buf, sony_length/4, 1, sony_key); +#ifndef LIBRAW_LIBRARY_BUILD + sfp = ifp; + if ((ifp = tmpfile())) { + fwrite (buf, sony_length, 1, ifp); + fseek (ifp, 0, SEEK_SET); + parse_tiff_ifd (-sony_offset); + fclose (ifp); + } + ifp = sfp; +#else + if( !ifp->tempbuffer_open(buf,sony_length)) + { + parse_tiff_ifd(-sony_offset); + ifp->tempbuffer_close(); + } +#endif + free (buf); + } + for (i=0; i < colors; i++) + FORCC cc[i][c] *= ab[i]; + if (use_cm) { + FORCC for (i=0; i < 3; i++) + for (cam_xyz[c][i]=j=0; j < colors; j++) + cam_xyz[c][i] += cc[c][j] * cm[j][i] * xyz[i]; + cam_xyz_coeff (cam_xyz); + } + if (asn[0]) { + cam_mul[3] = 0; + FORCC cam_mul[c] = 1 / asn[c]; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + if (!use_cm) + { + FORCC pre_mul[c] /= cc[c][c]; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.pre_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + + return 0; +} + +int CLASS parse_tiff (int base) +{ + int doff; + + fseek (ifp, base, SEEK_SET); + order = get2(); + if (order != 0x4949 && order != 0x4d4d) return 0; + get2(); + while ((doff = get4())) { + fseek (ifp, doff+base, SEEK_SET); + if (parse_tiff_ifd (base)) break; + } + return 1; +} + +void CLASS apply_tiff() +{ + int max_samp=0, raw=-1, thm=-1, i,max_bps=0; + struct jhead jh; + + thumb_misc = 16; + if (thumb_offset) { + fseek (ifp, thumb_offset, SEEK_SET); + if (ljpeg_start (&jh, 1)) { + thumb_misc = jh.bits; + thumb_width = jh.wide; + thumb_height = jh.high; + } + } + for (i=0; i < tiff_nifds; i++) { + if (max_samp < tiff_ifd[i].samples) + max_samp = tiff_ifd[i].samples; + if (max_samp > 3) max_samp = 3; + if (max_bps < tiff_ifd[i].bps) + max_bps = tiff_ifd[i].bps; + if ((tiff_ifd[i].comp != 6 || tiff_ifd[i].samples != 3) && + (tiff_ifd[i].t_width | tiff_ifd[i].t_height) < 0x10000 && + tiff_ifd[i].t_width*tiff_ifd[i].t_height > raw_width*raw_height) { + raw_width = tiff_ifd[i].t_width; + raw_height = tiff_ifd[i].t_height; + tiff_bps = tiff_ifd[i].bps; + tiff_compress = tiff_ifd[i].comp; + data_offset = tiff_ifd[i].offset; + tiff_flip = tiff_ifd[i].t_flip; + tiff_samples = tiff_ifd[i].samples; +#ifdef LIBRAW_LIBRARY_BUILD + data_size = tile_length < INT_MAX ? tiff_ifd[i].tile_maxbytes: tiff_ifd[i].bytes; +#endif + raw = i; + } + } +#if 0 + if (!tile_width ) tile_width = INT_MAX; + if (!tile_length) tile_length = INT_MAX; +#endif + for (i=tiff_nifds; i--; ) + if (tiff_ifd[i].t_flip) tiff_flip = tiff_ifd[i].t_flip; + if (raw >= 0 && !load_raw) + switch (tiff_compress) { +#if 1 + case 32767: + if (tiff_ifd[raw].bytes == raw_width*raw_height) { + tiff_bps = 12; + load_raw = &CLASS sony_arw2_load_raw; break; + } + if (tiff_ifd[raw].bytes*8 != raw_width*raw_height*tiff_bps) { + raw_height += 8; + load_raw = &CLASS sony_arw_load_raw; break; + } + load_flags = 79; + case 32769: + load_flags++; + case 32770: + case 32773: goto slr; + case 0: case 1: + if (tiff_ifd[raw].bytes*5 == raw_width*raw_height*8) { + load_flags = 81; + tiff_bps = 12; + } slr: + switch (tiff_bps) { + case 8: load_raw = &CLASS eight_bit_load_raw; break; + case 12: if (tiff_ifd[raw].phint == 2) + load_flags = 6; + load_raw = &CLASS packed_load_raw; break; + case 14: load_flags = 0; + case 16: load_raw = &CLASS unpacked_load_raw; break; + } + break; + case 6: case 7: case 99: + load_raw = &CLASS lossless_jpeg_load_raw; break; + case 262: + load_raw = &CLASS kodak_262_load_raw; break; + case 34713: + load_raw = &CLASS nikon_compressed_load_raw; break; +/* + case 34892: + load_raw = &CLASS lossy_dng_load_raw; break; +*/ + case 65535: + load_raw = &CLASS pentax_load_raw; break; + case 65000: + switch (tiff_ifd[raw].phint) { + case 2: load_raw = &CLASS kodak_rgb_load_raw; filters = 0; break; + case 6: load_raw = &CLASS kodak_ycbcr_load_raw; filters = 0; break; + case 32803: load_raw = &CLASS kodak_65000_load_raw; + } + case 32867: break; + default: is_raw = 0; +#else + case 0: case 1: + switch (tiff_bps) { + case 8: load_raw = &CLASS eight_bit_load_raw; break; + case 12: load_raw = &CLASS packed_load_raw; + if (tiff_ifd[raw].phint == 2) + load_flags = 6; + if (strncmp(make,"PENTAX",6)) break; + case 14: + case 16: load_raw = &CLASS unpacked_load_raw; break; + } + if (tiff_ifd[raw].bytes*5 == raw_width*raw_height*8) { + tiff_bps = 12; + load_raw = &CLASS packed_load_raw; + load_flags = 81; + } + break; + case 6: case 7: case 99: + load_raw = &CLASS lossless_jpeg_load_raw; break; + case 262: + load_raw = &CLASS kodak_262_load_raw; break; + case 32767: + if (tiff_ifd[raw].bytes == raw_width*raw_height) { + tiff_bps = 12; + load_raw = &CLASS sony_arw2_load_raw; break; + } + if (tiff_ifd[raw].bytes*8 != raw_width*raw_height*tiff_bps) { + raw_height += 8; + load_raw = &CLASS sony_arw_load_raw; break; + } + load_flags = 79; + case 32769: + load_flags++; + case 32770: + case 32773: + load_raw = &CLASS packed_load_raw; break; + case 34713: + load_raw = &CLASS nikon_compressed_load_raw; break; + case 65535: + load_raw = &CLASS pentax_load_raw; break; + case 65000: + switch (tiff_ifd[raw].phint) { + case 2: load_raw = &CLASS kodak_rgb_load_raw; filters = 0; break; + case 6: load_raw = &CLASS kodak_ycbcr_load_raw; filters = 0; break; + case 32803: load_raw = &CLASS kodak_65000_load_raw; + } + case 32867: break; + default: is_raw = 0; +#endif + } + if (!dng_version) + if ( (tiff_samples == 3 && tiff_ifd[raw].bytes && + tiff_bps != 14 && tiff_bps != 2048 && tiff_compress != 32770) + || (tiff_bps == 8 && !strstr(make,"KODAK") && !strstr(make,"Kodak") && + !strstr(model2,"DEBUG RAW"))) + is_raw = 0; + if(dng_version && max_bps > 16) + is_raw = 0; + for (i=0; i < tiff_nifds; i++) + if (i != raw && tiff_ifd[i].samples == max_samp && tiff_ifd[i].offset && tiff_ifd[i].bytes && + tiff_ifd[i].t_width * tiff_ifd[i].t_height / SQR(tiff_ifd[i].bps+1) > + thumb_width * thumb_height / SQR(thumb_misc+1) + && tiff_ifd[i].comp != 34892) { + thumb_width = tiff_ifd[i].t_width; + thumb_height = tiff_ifd[i].t_height; + thumb_offset = tiff_ifd[i].offset; + thumb_length = tiff_ifd[i].bytes; + thumb_misc = tiff_ifd[i].bps; + thm = i; + } + if (thm >= 0) { + thumb_misc |= tiff_ifd[thm].samples << 5; + switch (tiff_ifd[thm].comp) { + case 0: + write_thumb = &CLASS layer_thumb; + break; + case 1: + if (tiff_ifd[thm].bps <= 8) + write_thumb = &CLASS ppm_thumb; + else if (!strcmp(make,"Imacon")) + write_thumb = NULL; /* &CLASS ppm16_thumb; */ + else + thumb_load_raw = &CLASS kodak_thumb_load_raw; + break; + case 65000: + thumb_load_raw = tiff_ifd[thm].phint == 6 ? + &CLASS kodak_ycbcr_load_thumb : &CLASS kodak_rgb_load_thumb; + } + } +} + +void CLASS parse_minolta (int base) +{ + int save, tag, len, offset, high=0, wide=0, i, c; + short sorder=order; + + fseek (ifp, base, SEEK_SET); + if (fgetc(ifp) || fgetc(ifp)-'M' || fgetc(ifp)-'R') return; + order = fgetc(ifp) * 0x101; + offset = base + get4() + 8; + while ((save=ftell(ifp)) < offset) { + for (tag=i=0; i < 4; i++) + tag = tag << 8 | fgetc(ifp); + len = get4(); + switch (tag) { + case 0x505244: /* PRD */ + fseek (ifp, 8, SEEK_CUR); + high = get2(); + wide = get2(); + break; + case 0x574247: /* WBG */ + get4(); + i = strcmp(model,"DiMAGE A200") ? 0:3; + FORC4 cam_mul[c ^ (c >> 1) ^ i] = get2(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + break; + case 0x545457: /* TTW */ + parse_tiff (ftell(ifp)); + data_offset = offset; + } + fseek (ifp, save+len+8, SEEK_SET); + } + raw_height = high; + raw_width = wide; + order = sorder; +} + +/* + Many cameras have a "debug mode" that writes JPEG and raw + at the same time. The raw file has no header, so try to + to open the matching JPEG file and read its metadata. + */ +void CLASS parse_external_jpeg() +{ + const char *file, *ext; + char *jname, *jfile, *jext; +#ifndef LIBRAW_LIBRARY_BUILD + FILE *save=ifp; +#else + if(!ifp->fname()) + { + imgdata.process_warnings |= LIBRAW_WARN_NO_METADATA ; + return; + } +#endif + + ext = strrchr (ifname, '.'); + file = strrchr (ifname, '/'); + if (!file) file = strrchr (ifname, '\\'); +#ifndef LIBRAW_LIBRARY_BUILD + if (!file) file = ifname-1; +#else + if (!file) file = (char*)ifname-1; +#endif + file++; + if (!ext || strlen(ext) != 4 || ext-file != 8) return; + jname = (char *) malloc (strlen(ifname) + 1); + merror (jname, "parse_external_jpeg()"); + strcpy (jname, ifname); + jfile = file - ifname + jname; + jext = ext - ifname + jname; + if (strcasecmp (ext, ".jpg")) { + strcpy (jext, isupper(ext[1]) ? ".JPG":".jpg"); + if (isdigit(*file)) { + memcpy (jfile, file+4, 4); + memcpy (jfile+4, file, 4); + } + } else + while (isdigit(*--jext)) { + if (*jext != '9') { + (*jext)++; + break; + } + *jext = '0'; + } +#ifndef LIBRAW_LIBRARY_BUILD + if (strcmp (jname, ifname)) { + if ((ifp = fopen (jname, "rb"))) { +#ifdef DCRAW_VERBOSE + if (verbose) + fprintf (stderr,_("Reading metadata from %s ...\n"), jname); +#endif + parse_tiff (12); + thumb_offset = 0; + is_raw = 1; + fclose (ifp); + } + } +#else + if (strcmp (jname, ifname)) + { + if(!ifp->subfile_open(jname)) + { + parse_tiff (12); + thumb_offset = 0; + is_raw = 1; + ifp->subfile_close(); + } + else + imgdata.process_warnings |= LIBRAW_WARN_NO_METADATA ; + } +#endif + if (!timestamp) + { +#ifdef LIBRAW_LIBRARY_BUILD + imgdata.process_warnings |= LIBRAW_WARN_NO_METADATA ; +#endif +#ifdef DCRAW_VERBOSE + fprintf (stderr,_("Failed to read metadata from %s\n"), jname); +#endif + } + free (jname); +#ifndef LIBRAW_LIBRARY_BUILD + ifp = save; +#endif +} + +/* + CIFF block 0x1030 contains an 8x8 white sample. + Load this into white[][] for use in scale_colors(). + */ +void CLASS ciff_block_1030() +{ + static const ushort key[] = { 0x410, 0x45f3 }; + int i, bpp, row, col, vbits=0; + unsigned long bitbuf=0; + + if ((get2(),get4()) != 0x80008 || !get4()) return; + bpp = get2(); + if (bpp != 10 && bpp != 12) return; + for (i=row=0; row < 8; row++) + for (col=0; col < 8; col++) { + if (vbits < bpp) { + bitbuf = bitbuf << 16 | (get2() ^ key[i++ & 1]); + vbits += 16; + } + white[row][col] = + bitbuf << (LONG_BIT - vbits) >> (LONG_BIT - bpp); + vbits -= bpp; + } +} + +/* + Parse a CIFF file, better known as Canon CRW format. + */ +void CLASS parse_ciff (int offset, int length) +{ + int tboff, nrecs, c, type, len, save, wbi=-1; + ushort key[] = { 0x410, 0x45f3 }; + + fseek (ifp, offset+length-4, SEEK_SET); + tboff = get4() + offset; + fseek (ifp, tboff, SEEK_SET); + nrecs = get2(); + if (nrecs > 100) return; + while (nrecs--) { + type = get2(); + len = get4(); + save = ftell(ifp) + 4; + fseek (ifp, offset+get4(), SEEK_SET); + if ((((type >> 8) + 8) | 8) == 0x38) + parse_ciff (ftell(ifp), len); /* Parse a sub-table */ + + if (type == 0x0810) + fread (artist, 64, 1, ifp); + if (type == 0x080a) { + fread (make, 64, 1, ifp); + fseek (ifp, ((INT64)strlen(make)) - 63, SEEK_CUR); + fread (model, 64, 1, ifp); + } + if (type == 0x1810) { + fseek (ifp, 12, SEEK_CUR); + flip = get4(); + } + if (type == 0x1835) /* Get the decoder table */ + tiff_compress = get4(); + if (type == 0x2007) { + thumb_offset = ftell(ifp); + thumb_length = len; + } + if (type == 0x1818) { + shutter = pow (2.0f, -int_to_float((get4(),get4()))); + aperture = pow (2.0f, int_to_float(get4())/2); + } + if (type == 0x102a) { + iso_speed = pow (2.0, (get4(),get2())/32.0 - 4) * 50; + aperture = pow (2.0, (get2(),(short)get2())/64.0); + shutter = pow (2.0,-((short)get2())/32.0); + wbi = (get2(),get2()); + if (wbi > 17) wbi = 0; + fseek (ifp, 32, SEEK_CUR); + if (shutter > 1e6) shutter = get2()/10.0; + } + if (type == 0x102c) { + if (get2() > 512) { /* Pro90, G1 */ + fseek (ifp, 118, SEEK_CUR); + FORC4 cam_mul[c ^ 2] = get2(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } else { /* G2, S30, S40 */ + fseek (ifp, 98, SEEK_CUR); + FORC4 cam_mul[c ^ (c >> 1) ^ 1] = get2(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + } + if (type == 0x0032) { + if (len == 768) { /* EOS D30 */ + fseek (ifp, 72, SEEK_CUR); + FORC4 cam_mul[c ^ (c >> 1)] = 1024.0 / get2(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + if (!wbi) cam_mul[0] = -1; /* use my auto white balance */ + } else if (!cam_mul[0]) { + if (get2() == key[0]) /* Pro1, G6, S60, S70 */ + c = (strstr(model,"Pro1") ? + "012346000000000000":"01345:000000006008")[wbi]-'0'+ 2; + else { /* G3, G5, S45, S50 */ + c = "023457000000006000"[wbi]-'0'; + key[0] = key[1] = 0; + } + fseek (ifp, 78 + c*8, SEEK_CUR); + FORC4 cam_mul[c ^ (c >> 1) ^ 1] = get2() ^ key[c & 1]; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + if (!wbi) cam_mul[0] = -1; + } + } + if (type == 0x10a9) { /* D60, 10D, 300D, and clones */ + if (len > 66) wbi = "0134567028"[wbi]-'0'; + fseek (ifp, 2 + wbi*8, SEEK_CUR); + FORC4 cam_mul[c ^ (c >> 1)] = get2(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } + if (type == 0x1030 && (0x18040 >> wbi & 1)) + ciff_block_1030(); /* all that don't have 0x10a9 */ + if (type == 0x1031) { + raw_width = (get2(),get2()); + raw_height = get2(); + } + if (type == 0x5029) { + focal_len = len >> 16; + if ((len & 0xffff) == 2) focal_len /= 32; + } + if (type == 0x5813) flash_used = int_to_float(len); + if (type == 0x5814) canon_ev = int_to_float(len); + if (type == 0x5817) shot_order = len; + if (type == 0x5834) unique_id = len; + if (type == 0x580e) timestamp = len; + if (type == 0x180e) timestamp = get4(); +#ifdef LOCALTIME + if ((type | 0x4000) == 0x580e) + timestamp = mktime (gmtime (×tamp)); +#endif + fseek (ifp, save, SEEK_SET); + } +} + +void CLASS parse_rollei() +{ + char line[128], *val; + struct tm t; + + fseek (ifp, 0, SEEK_SET); + memset (&t, 0, sizeof t); + do { + fgets (line, 128, ifp); + if ((val = strchr(line,'='))) + *val++ = 0; + else + val = line + strlen(line); + if (!strcmp(line,"DAT")) + sscanf (val, "%d.%d.%d", &t.tm_mday, &t.tm_mon, &t.tm_year); + if (!strcmp(line,"TIM")) + sscanf (val, "%d:%d:%d", &t.tm_hour, &t.tm_min, &t.tm_sec); + if (!strcmp(line,"HDR")) + thumb_offset = atoi(val); + if (!strcmp(line,"X ")) + raw_width = atoi(val); + if (!strcmp(line,"Y ")) + raw_height = atoi(val); + if (!strcmp(line,"TX ")) + thumb_width = atoi(val); + if (!strcmp(line,"TY ")) + thumb_height = atoi(val); + } while (strncmp(line,"EOHD",4)); + data_offset = thumb_offset + thumb_width * thumb_height * 2; + t.tm_year -= 1900; + t.tm_mon -= 1; + if (mktime(&t) > 0) + timestamp = mktime(&t); + strcpy (make, "Rollei"); + strcpy (model,"d530flex"); + write_thumb = &CLASS rollei_thumb; +} + +void CLASS parse_sinar_ia() +{ + int entries, off; + char str[8], *cp; + + order = 0x4949; + fseek (ifp, 4, SEEK_SET); + entries = get4(); + fseek (ifp, get4(), SEEK_SET); + while (entries--) { + off = get4(); get4(); + fread (str, 8, 1, ifp); + if (!strcmp(str,"META")) meta_offset = off; + if (!strcmp(str,"THUMB")) thumb_offset = off; + if (!strcmp(str,"RAW0")) data_offset = off; + } + fseek (ifp, meta_offset+20, SEEK_SET); + fread (make, 64, 1, ifp); + make[63] = 0; + if ((cp = strchr(make,' '))) { + strcpy (model, cp+1); + *cp = 0; + } + raw_width = get2(); + raw_height = get2(); + load_raw = &CLASS unpacked_load_raw; + thumb_width = (get4(),get2()); + thumb_height = get2(); + write_thumb = &CLASS ppm_thumb; + maximum = 0x3fff; +} + +void CLASS parse_phase_one (int base) +{ + unsigned entries, tag, type, len, data, save, i, c; + float romm_cam[3][3]; + char *cp; + + memset (&ph1, 0, sizeof ph1); + fseek (ifp, base, SEEK_SET); + order = get4() & 0xffff; + if (get4() >> 8 != 0x526177) return; /* "Raw" */ + fseek (ifp, get4()+base, SEEK_SET); + entries = get4(); + get4(); + while (entries--) { + tag = get4(); + type = get4(); + len = get4(); + data = get4(); + save = ftell(ifp); + fseek (ifp, base+data, SEEK_SET); + switch (tag) { + case 0x100: flip = "0653"[data & 3]-'0'; break; + case 0x106: + for (i=0; i < 9; i++) + romm_cam[0][i] = getreal(11); + romm_coeff (romm_cam); + break; + case 0x107: + FORC3 cam_mul[c] = getreal(11); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + break; + case 0x108: raw_width = data; break; + case 0x109: raw_height = data; break; + case 0x10a: left_margin = data; break; + case 0x10b: top_margin = data; break; + case 0x10c: width = data; break; + case 0x10d: height = data; break; + case 0x10e: ph1.format = data; break; + case 0x10f: data_offset = data+base; break; + case 0x110: meta_offset = data+base; + meta_length = len; break; + case 0x112: ph1.key_off = save - 4; break; + case 0x210: ph1.tag_210 = int_to_float(data); break; + case 0x21a: ph1.tag_21a = data; break; + case 0x21c: strip_offset = data+base; break; + case 0x21d: ph1.t_black = data; break; + case 0x222: ph1.split_col = data - left_margin; break; + case 0x223: ph1.black_off = data+base; break; + case 0x301: + model[63] = 0; + fread (model, 1, 63, ifp); + if ((cp = strstr(model," camera"))) *cp = 0; + } + fseek (ifp, save, SEEK_SET); + } + load_raw = ph1.format < 3 ? + &CLASS phase_one_load_raw : &CLASS phase_one_load_raw_c; + maximum = 0xffff; + strcpy (make, "Phase One"); + if (model[0]) return; + switch (raw_height) { + case 2060: strcpy (model,"LightPhase"); break; + case 2682: strcpy (model,"H 10"); break; + case 4128: strcpy (model,"H 20"); break; + case 5488: strcpy (model,"H 25"); break; + } +} + +void CLASS parse_fuji (int offset) +{ + unsigned entries, tag, len, save, c; + + fseek (ifp, offset, SEEK_SET); + entries = get4(); + if (entries > 255) return; + while (entries--) { + tag = get2(); + len = get2(); + save = ftell(ifp); + if (tag == 0x100) { + raw_height = get2(); + raw_width = get2(); + } else if (tag == 0x121) { + height = get2(); + if ((width = get2()) == 4284) width += 3; + } else if (tag == 0x130) { + fuji_layout = fgetc(ifp) >> 7; + load_raw = fgetc(ifp) & 8 ? + &CLASS unpacked_load_raw : &CLASS fuji_load_raw; + } else if (tag == 0x2ff0) { + FORC4 cam_mul[c ^ 1] = get2(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } else if (tag == 0xc000) { + c = order; + order = 0x4949; + width = get4(); + height = get4(); + order = c; + } + fseek (ifp, save+len, SEEK_SET); + } + height <<= fuji_layout; + width >>= fuji_layout; +} + +int CLASS parse_jpeg (int offset) +{ + int len, save, hlen, mark; + + fseek (ifp, offset, SEEK_SET); + if (fgetc(ifp) != 0xff || fgetc(ifp) != 0xd8) return 0; + + while (fgetc(ifp) == 0xff && (mark = fgetc(ifp)) != 0xda) { + order = 0x4d4d; + len = get2() - 2; + save = ftell(ifp); + if (mark == 0xc0 || mark == 0xc3) { + fgetc(ifp); + raw_height = get2(); + raw_width = get2(); + } + order = get2(); + hlen = get4(); + if (get4() == 0x48454150) /* "HEAP" */ + parse_ciff (save+hlen, len-hlen); + if (parse_tiff (save+6)) apply_tiff(); + fseek (ifp, save+len, SEEK_SET); + } + return 1; +} + +void CLASS parse_riff() +{ + unsigned i, size, end; + char tag[4], date[64], month[64]; + static const char mon[12][4] = + { "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" }; + struct tm t; + + order = 0x4949; + fread (tag, 4, 1, ifp); + size = get4(); + end = ftell(ifp) + size; + if (!memcmp(tag,"RIFF",4) || !memcmp(tag,"LIST",4)) { + int cnt=0; + get4(); + while (ftell(ifp)+7 < end) + { + parse_riff(); + if(cnt++>10000) break; // no more than 10k times + } + } else if (!memcmp(tag,"nctg",4)) { + while (ftell(ifp)+7 < end) { + i = get2(); + size = get2(); + if ((i+1) >> 1 == 10 && size == 20) + get_timestamp(0); + else fseek (ifp, size, SEEK_CUR); + } + } else if (!memcmp(tag,"IDIT",4) && size < 64) { + fread (date, 64, 1, ifp); + date[size] = 0; + memset (&t, 0, sizeof t); + if (sscanf (date, "%*s %s %d %d:%d:%d %d", month, &t.tm_mday, + &t.tm_hour, &t.tm_min, &t.tm_sec, &t.tm_year) == 6) { + for (i=0; i < 12 && strcasecmp(mon[i],month); i++); + t.tm_mon = i; + t.tm_year -= 1900; + if (mktime(&t) > 0) + timestamp = mktime(&t); + } + } else + fseek (ifp, size, SEEK_CUR); +} + +void CLASS parse_smal (int offset, int fsize) +{ + int ver; + + fseek (ifp, offset+2, SEEK_SET); + order = 0x4949; + ver = fgetc(ifp); + if (ver == 6) + fseek (ifp, 5, SEEK_CUR); + if (get4() != fsize) return; + if (ver > 6) data_offset = get4(); + raw_height = height = get2(); + raw_width = width = get2(); + strcpy (make, "SMaL"); + sprintf (model, "v%d %dx%d", ver, width, height); + if (ver == 6) load_raw = &CLASS smal_v6_load_raw; + if (ver == 9) load_raw = &CLASS smal_v9_load_raw; +} + +void CLASS parse_cine() +{ + unsigned off_head, off_setup, off_image, i; + + order = 0x4949; + fseek (ifp, 4, SEEK_SET); + is_raw = get2() == 2; + fseek (ifp, 14, SEEK_CUR); + is_raw *= get4(); + off_head = get4(); + off_setup = get4(); + off_image = get4(); + timestamp = get4(); + if ((i = get4())) timestamp = i; + fseek (ifp, off_head+4, SEEK_SET); + raw_width = get4(); + raw_height = get4(); + switch (get2(),get2()) { + case 8: load_raw = &CLASS eight_bit_load_raw; break; + case 16: load_raw = &CLASS unpacked_load_raw; + } + fseek (ifp, off_setup+792, SEEK_SET); + strcpy (make, "CINE"); + sprintf (model, "%d", get4()); + fseek (ifp, 12, SEEK_CUR); + switch ((i=get4()) & 0xffffff) { + case 3: filters = 0x94949494; break; + case 4: filters = 0x49494949; break; + default: is_raw = 0; + } + fseek (ifp, 72, SEEK_CUR); + switch ((get4()+3600) % 360) { + case 270: flip = 4; break; + case 180: flip = 1; break; + case 90: flip = 7; break; + case 0: flip = 2; + } + cam_mul[0] = getreal(11); + cam_mul[2] = getreal(11); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + maximum = ~(-1 << get4()); + fseek (ifp, 668, SEEK_CUR); + shutter = get4()/1000000000.0; + fseek (ifp, off_image, SEEK_SET); + if (shot_select < is_raw) + fseek (ifp, shot_select*8, SEEK_CUR); + data_offset = (INT64) get4() + 8; + data_offset += (INT64) get4() << 32; +} + +void CLASS parse_redcine() +{ + unsigned i, len, rdvo; + + order = 0x4d4d; + is_raw = 0; + fseek (ifp, 52, SEEK_SET); + width = get4(); + height = get4(); + fseek (ifp, 0, SEEK_END); + fseek (ifp, -(i = ftello(ifp) & 511), SEEK_CUR); + if (get4() != i || get4() != 0x52454f42) { +#ifdef DCRAW_VERBOSE + fprintf (stderr,_("%s: Tail is missing, parsing from head...\n"), ifname); +#endif + fseek (ifp, 0, SEEK_SET); + while ((len = get4()) != EOF) { + if (get4() == 0x52454456) + if (is_raw++ == shot_select) + data_offset = ftello(ifp) - 8; + fseek (ifp, len-8, SEEK_CUR); + } + } else { + rdvo = get4(); + fseek (ifp, 12, SEEK_CUR); + is_raw = get4(); + fseeko (ifp, rdvo+8 + shot_select*4, SEEK_SET); + data_offset = get4(); + } +} +void CLASS adobe_coeff (const char *p_make, const char *p_model) +{ + static const struct { + const char *prefix; + short t_black, t_maximum, trans[12]; + } table[] = { + { "AGFAPHOTO DC-833m", 0, 0, /* DJC */ + { 11438,-3762,-1115,-2409,9914,2497,-1227,2295,5300 } }, + { "Apple QuickTake", 0, 0, /* DJC */ + { 21392,-5653,-3353,2406,8010,-415,7166,1427,2078 } }, + { "Canon EOS D2000", 0, 0, + { 24542,-10860,-3401,-1490,11370,-297,2858,-605,3225 } }, + { "Canon EOS D6000", 0, 0, + { 20482,-7172,-3125,-1033,10410,-285,2542,226,3136 } }, + { "Canon EOS D30", 0, 0, + { 9805,-2689,-1312,-5803,13064,3068,-2438,3075,8775 } }, + { "Canon EOS D60", 0, 0xfa0, + { 6188,-1341,-890,-7168,14489,2937,-2640,3228,8483 } }, + { "Canon EOS 5D Mark III", 0, 0x3c80, + { 6722,-635,-963,-4287,12460,2028,-908,2162,5668 } }, + { "Canon EOS 5D Mark II", 0, 0x3cf0, + { 4716,603,-830,-7798,15474,2480,-1496,1937,6651 } }, + { "Canon EOS 5D", 0, 0xe6c, + { 6347,-479,-972,-8297,15954,2480,-1968,2131,7649 } }, + { "Canon EOS 7D", 0, 0x3510, + { 6844,-996,-856,-3876,11761,2396,-593,1772,6198 } }, + { "Canon EOS 10D", 0, 0xfa0, + { 8197,-2000,-1118,-6714,14335,2592,-2536,3178,8266 } }, + { "Canon EOS 20Da", 0, 0, + { 14155,-5065,-1382,-6550,14633,2039,-1623,1824,6561 } }, + { "Canon EOS 20D", 0, 0xfff, + { 6599,-537,-891,-8071,15783,2424,-1983,2234,7462 } }, + { "Canon EOS 30D", 0, 0, + { 6257,-303,-1000,-7880,15621,2396,-1714,1904,7046 } }, + { "Canon EOS 40D", 0, 0x3f60, + { 6071,-747,-856,-7653,15365,2441,-2025,2553,7315 } }, + { "Canon EOS 50D", 0, 0x3d93, + { 4920,616,-593,-6493,13964,2784,-1774,3178,7005 } }, + { "Canon EOS 60D", 0, 0x2ff7, + { 6719,-994,-925,-4408,12426,2211,-887,2129,6051 } }, + { "Canon EOS 300D", 0, 0xfa0, + { 8197,-2000,-1118,-6714,14335,2592,-2536,3178,8266 } }, + { "Canon EOS 350D", 0, 0xfff, + { 6018,-617,-965,-8645,15881,2975,-1530,1719,7642 } }, + { "Canon EOS 400D", 0, 0xe8e, + { 7054,-1501,-990,-8156,15544,2812,-1278,1414,7796 } }, + { "Canon EOS 450D", 0, 0x390d, + { 5784,-262,-821,-7539,15064,2672,-1982,2681,7427 } }, + { "Canon EOS 500D", 0, 0x3479, + { 4763,712,-646,-6821,14399,2640,-1921,3276,6561 } }, + { "Canon EOS 550D", 0, 0x3dd7, + { 6941,-1164,-857,-3825,11597,2534,-416,1540,6039 } }, + { "Canon EOS 600D", 0, 0x3510, + { 6461,-907,-882,-4300,12184,2378,-819,1944,5931 } }, + { "Canon EOS 1000D", 0, 0xe43, + { 6771,-1139,-977,-7818,15123,2928,-1244,1437,7533 } }, + { "Canon EOS 1100D", 0, 0x3510, + { 6444,-904,-893,-4563,12308,2535,-903,2016,6728 } }, + { "Canon EOS-1Ds Mark III", 0, 0x3bb0, + { 5859,-211,-930,-8255,16017,2353,-1732,1887,7448 } }, + { "Canon EOS-1Ds Mark II", 0, 0xe80, + { 6517,-602,-867,-8180,15926,2378,-1618,1771,7633 } }, + { "Canon EOS-1D Mark IV", 0, 0x3bb0, + { 6014,-220,-795,-4109,12014,2361,-561,1824,5787 } }, + { "Canon EOS-1D Mark III", 0, 0x3bb0, + { 6291,-540,-976,-8350,16145,2311,-1714,1858,7326 } }, + { "Canon EOS-1D Mark II N", 0, 0xe80, + { 6240,-466,-822,-8180,15825,2500,-1801,1938,8042 } }, + { "Canon EOS-1D Mark II", 0, 0xe80, + { 6264,-582,-724,-8312,15948,2504,-1744,1919,8664 } }, + { "Canon EOS-1DS", 0, 0xe20, + { 4374,3631,-1743,-7520,15212,2472,-2892,3632,8161 } }, + { "Canon EOS-1D X", 0, 0, + { 6847,-614,-1014,-4669,12737,2139,-1197,2488,6846 } }, + { "Canon EOS-1D", 0, 0xe20, + { 6806,-179,-1020,-8097,16415,1687,-3267,4236,7690 } }, + { "Canon EOS", 0, 0, + { 8197,-2000,-1118,-6714,14335,2592,-2536,3178,8266 } }, + { "Canon PowerShot A530", 0, 0, + { 0 } }, /* don't want the A5 matrix */ + { "Canon PowerShot A50", 0, 0, + { -5300,9846,1776,3436,684,3939,-5540,9879,6200,-1404,11175,217 } }, + { "Canon PowerShot A5", 0, 0, + { -4801,9475,1952,2926,1611,4094,-5259,10164,5947,-1554,10883,547 } }, + { "Canon PowerShot G10", 0, 0, + { 11093,-3906,-1028,-5047,12492,2879,-1003,1750,5561 } }, + { "Canon PowerShot G11", 0, 0, + { 12177,-4817,-1069,-1612,9864,2049,-98,850,4471 } }, + { "Canon PowerShot G12", 0, 0, + { 13244,-5501,-1248,-1508,9858,1935,-270,1083,4366 } }, + { "Canon PowerShot G1 X", 0, 0, + { 7378,-1255,-1043,-4088,12251,2048,-876,1946,5805 } }, + { "Canon PowerShot G1", 0, 0, + { -4778,9467,2172,4743,-1141,4344,-5146,9908,6077,-1566,11051,557 } }, + { "Canon PowerShot G2", 0, 0, + { 9087,-2693,-1049,-6715,14382,2537,-2291,2819,7790 } }, + { "Canon PowerShot G3", 0, 0, + { 9212,-2781,-1073,-6573,14189,2605,-2300,2844,7664 } }, + { "Canon PowerShot G5", 0, 0, + { 9757,-2872,-933,-5972,13861,2301,-1622,2328,7212 } }, + { "Canon PowerShot G6", 0, 0, + { 9877,-3775,-871,-7613,14807,3072,-1448,1305,7485 } }, + { "Canon PowerShot G9", 0, 0, + { 7368,-2141,-598,-5621,13254,2625,-1418,1696,5743 } }, + { "Canon PowerShot Pro1", 0, 0, + { 10062,-3522,-999,-7643,15117,2730,-765,817,7323 } }, + { "Canon PowerShot Pro70", 34, 0, + { -4155,9818,1529,3939,-25,4522,-5521,9870,6610,-2238,10873,1342 } }, + { "Canon PowerShot Pro90", 0, 0, + { -4963,9896,2235,4642,-987,4294,-5162,10011,5859,-1770,11230,577 } }, + { "Canon PowerShot S30", 0, 0, + { 10566,-3652,-1129,-6552,14662,2006,-2197,2581,7670 } }, + { "Canon PowerShot S40", 0, 0, + { 8510,-2487,-940,-6869,14231,2900,-2318,2829,9013 } }, + { "Canon PowerShot S45", 0, 0, + { 8163,-2333,-955,-6682,14174,2751,-2077,2597,8041 } }, + { "Canon PowerShot S50", 0, 0, + { 8882,-2571,-863,-6348,14234,2288,-1516,2172,6569 } }, + { "Canon PowerShot S60", 0, 0, + { 8795,-2482,-797,-7804,15403,2573,-1422,1996,7082 } }, + { "Canon PowerShot S70", 0, 0, + { 9976,-3810,-832,-7115,14463,2906,-901,989,7889 } }, + { "Canon PowerShot S90", 0, 0, + { 12374,-5016,-1049,-1677,9902,2078,-83,852,4683 } }, + { "Canon PowerShot S95", 0, 0, + { 13440,-5896,-1279,-1236,9598,1931,-180,1001,4651 } }, + { "Canon PowerShot S100", 0, 0, + { 7968,-2565,-636,-2873,10697,2513,180,667,4211 } }, + { "Canon PowerShot A470", 0, 0, /* DJC */ + { 12513,-4407,-1242,-2680,10276,2405,-878,2215,4734 } }, + { "Canon PowerShot A610", 0, 0, /* DJC */ + { 15591,-6402,-1592,-5365,13198,2168,-1300,1824,5075 } }, + { "Canon PowerShot A620", 0, 0, /* DJC */ + { 15265,-6193,-1558,-4125,12116,2010,-888,1639,5220 } }, + { "Canon PowerShot A630", 0, 0, /* DJC */ + { 14201,-5308,-1757,-6087,14472,1617,-2191,3105,5348 } }, + { "Canon PowerShot A640", 0, 0, /* DJC */ + { 13124,-5329,-1390,-3602,11658,1944,-1612,2863,4885 } }, + { "Canon PowerShot A650", 0, 0, /* DJC */ + { 9427,-3036,-959,-2581,10671,1911,-1039,1982,4430 } }, + { "Canon PowerShot A720", 0, 0, /* DJC */ + { 14573,-5482,-1546,-1266,9799,1468,-1040,1912,3810 } }, + { "Canon PowerShot S2 IS", 0, 0, /* jlb */ + { 14062,-5199,-1446,-4712,12470,2243,-1286,2028,4836 } }, /* jlb - copied from Powershot S3 IS */ + { "Canon PowerShot S3 IS", 0, 0, /* DJC */ + { 14062,-5199,-1446,-4712,12470,2243,-1286,2028,4836 } }, + { "Canon PowerShot SX1 IS", 0, 0, + { 6578,-259,-502,-5974,13030,3309,-308,1058,4970 } }, + { "Canon PowerShot SX110 IS", 0, 0, /* DJC */ + { 14134,-5576,-1527,-1991,10719,1273,-1158,1929,3581 } }, + { "CASIO EX-S20", 0, 0, /* DJC */ + { 11634,-3924,-1128,-4968,12954,2015,-1588,2648,7206 } }, + { "CASIO EX-Z750", 0, 0, /* DJC */ + { 10819,-3873,-1099,-4903,13730,1175,-1755,3751,4632 } }, + { "CASIO EX-Z10", 128, 0xfff, /* DJC */ + { 9790,-3338,-603,-2321,10222,2099,-344,1273,4799 } }, + { "CINE 650", 0, 0, + { 3390,480,-500,-800,3610,340,-550,2336,1192 } }, + { "CINE 660", 0, 0, + { 3390,480,-500,-800,3610,340,-550,2336,1192 } }, + { "CINE", 0, 0, + { 20183,-4295,-423,-3940,15330,3985,-280,4870,9800 } }, + { "Contax N Digital", 0, 0xf1e, + { 7777,1285,-1053,-9280,16543,2916,-3677,5679,7060 } }, + { "EPSON R-D1", 0, 0, + { 6827,-1878,-732,-8429,16012,2564,-704,592,7145 } }, + { "FUJIFILM E550", 0, 0, + { 11044,-3888,-1120,-7248,15168,2208,-1531,2277,8069 } }, + { "FUJIFILM E900", 0, 0, + { 9183,-2526,-1078,-7461,15071,2574,-2022,2440,8639 } }, + { "FUJIFILM F5", 0, 0, + { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, + { "FUJIFILM F6", 0, 0, + { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, + { "FUJIFILM F77", 0, 0, + { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, + { "FUJIFILM F7", 0, 0, + { 10004,-3219,-1201,-7036,15047,2107,-1863,2565,7736 } }, + { "FUJIFILM F8", 0, 0, + { 11044,-3888,-1120,-7248,15168,2208,-1531,2277,8069 } }, + { "FUJIFILM S100FS", 514, 0, + { 11521,-4355,-1065,-6524,13767,3058,-1466,1984,6045 } }, + { "FUJIFILM S200EXR", 512, 0x3fff, + { 11401,-4498,-1312,-5088,12751,2613,-838,1568,5941 } }, + { "FUJIFILM S20Pro", 0, 0, + { 10004,-3219,-1201,-7036,15047,2107,-1863,2565,7736 } }, + { "FUJIFILM S2Pro", 128, 0, + { 12492,-4690,-1402,-7033,15423,1647,-1507,2111,7697 } }, + { "FUJIFILM S3Pro", 0, 0, + { 11807,-4612,-1294,-8927,16968,1988,-2120,2741,8006 } }, + { "FUJIFILM S5Pro", 0, 0, + { 12300,-5110,-1304,-9117,17143,1998,-1947,2448,8100 } }, + { "FUJIFILM S5000", 0, 0, + { 8754,-2732,-1019,-7204,15069,2276,-1702,2334,6982 } }, + { "FUJIFILM S5100", 0, 0, + { 11940,-4431,-1255,-6766,14428,2542,-993,1165,7421 } }, + { "FUJIFILM S5500", 0, 0, + { 11940,-4431,-1255,-6766,14428,2542,-993,1165,7421 } }, + { "FUJIFILM S5200", 0, 0, + { 9636,-2804,-988,-7442,15040,2589,-1803,2311,8621 } }, + { "FUJIFILM S5600", 0, 0, + { 9636,-2804,-988,-7442,15040,2589,-1803,2311,8621 } }, + { "FUJIFILM S6", 0, 0, + { 12628,-4887,-1401,-6861,14996,1962,-2198,2782,7091 } }, + { "FUJIFILM S7000", 0, 0, + { 10190,-3506,-1312,-7153,15051,2238,-2003,2399,7505 } }, + { "FUJIFILM S9000", 0, 0, + { 10491,-3423,-1145,-7385,15027,2538,-1809,2275,8692 } }, + { "FUJIFILM S9500", 0, 0, + { 10491,-3423,-1145,-7385,15027,2538,-1809,2275,8692 } }, + { "FUJIFILM S9100", 0, 0, + { 12343,-4515,-1285,-7165,14899,2435,-1895,2496,8800 } }, + { "FUJIFILM S9600", 0, 0, + { 12343,-4515,-1285,-7165,14899,2435,-1895,2496,8800 } }, + { "FUJIFILM IS-1", 0, 0, + { 21461,-10807,-1441,-2332,10599,1999,289,875,7703 } }, + { "FUJIFILM IS Pro", 0, 0, + { 12300,-5110,-1304,-9117,17143,1998,-1947,2448,8100 } }, + { "FUJIFILM HS10 HS11", 0, 0xf68, + { 12440,-3954,-1183,-1123,9674,1708,-83,1614,4086 } }, + { "FUJIFILM HS20EXR", 0, 0, + { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, + { "FUJIFILM HS3", 0, 0, + { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, + { "FUJIFILM X100", 0, 0, + { 12161,-4457,-1069,-5034,12874,2400,-795,1724,6904 } }, + { "FUJIFILM X10", 0, 0, + { 13509,-6199,-1254,-4430,12733,1865,-331,1441,5022 } }, + { "FUJIFILM X-Pro1", 0, 0, + { 10413,-3996,-993,-3721,11640,2361,-733,1540,6011 } }, + { "FUJIFILM X-S1", 0, 0, + { 13509,-6199,-1254,-4430,12733,1865,-331,1441,5022 } }, + { "Imacon Ixpress", 0, 0, /* DJC */ + { 7025,-1415,-704,-5188,13765,1424,-1248,2742,6038 } }, + { "KODAK NC2000", 0, 0, + { 13891,-6055,-803,-465,9919,642,2121,82,1291 } }, + { "Kodak DCS315C", 8, 0, + { 17523,-4827,-2510,756,8546,-137,6113,1649,2250 } }, + { "Kodak DCS330C", 8, 0, + { 20620,-7572,-2801,-103,10073,-396,3551,-233,2220 } }, + { "KODAK DCS420", 0, 0, + { 10868,-1852,-644,-1537,11083,484,2343,628,2216 } }, + { "KODAK DCS460", 0, 0, + { 10592,-2206,-967,-1944,11685,230,2206,670,1273 } }, + { "KODAK EOSDCS1", 0, 0, + { 10592,-2206,-967,-1944,11685,230,2206,670,1273 } }, + { "KODAK EOSDCS3B", 0, 0, + { 9898,-2700,-940,-2478,12219,206,1985,634,1031 } }, + { "Kodak DCS520C", 180, 0, + { 24542,-10860,-3401,-1490,11370,-297,2858,-605,3225 } }, + { "Kodak DCS560C", 188, 0, + { 20482,-7172,-3125,-1033,10410,-285,2542,226,3136 } }, + { "Kodak DCS620C", 180, 0, + { 23617,-10175,-3149,-2054,11749,-272,2586,-489,3453 } }, + { "Kodak DCS620X", 185, 0, + { 13095,-6231,154,12221,-21,-2137,895,4602,2258 } }, + { "Kodak DCS660C", 214, 0, + { 18244,-6351,-2739,-791,11193,-521,3711,-129,2802 } }, + { "Kodak DCS720X", 0, 0, + { 11775,-5884,950,9556,1846,-1286,-1019,6221,2728 } }, + { "Kodak DCS760C", 0, 0, + { 16623,-6309,-1411,-4344,13923,323,2285,274,2926 } }, + { "Kodak DCS Pro SLR", 0, 0, + { 5494,2393,-232,-6427,13850,2846,-1876,3997,5445 } }, + { "Kodak DCS Pro 14nx", 0, 0, + { 5494,2393,-232,-6427,13850,2846,-1876,3997,5445 } }, + { "Kodak DCS Pro 14", 0, 0, + { 7791,3128,-776,-8588,16458,2039,-2455,4006,6198 } }, + { "Kodak ProBack645", 0, 0, + { 16414,-6060,-1470,-3555,13037,473,2545,122,4948 } }, + { "Kodak ProBack", 0, 0, + { 21179,-8316,-2918,-915,11019,-165,3477,-180,4210 } }, + { "KODAK P712", 0, 0, + { 9658,-3314,-823,-5163,12695,2768,-1342,1843,6044 } }, + { "KODAK P850", 0, 0xf7c, + { 10511,-3836,-1102,-6946,14587,2558,-1481,1792,6246 } }, + { "KODAK P880", 0, 0xfff, + { 12805,-4662,-1376,-7480,15267,2360,-1626,2194,7904 } }, + { "KODAK EasyShare Z980", 0, 0, + { 11313,-3559,-1101,-3893,11891,2257,-1214,2398,4908 } }, + { "KODAK EasyShare Z981", 0, 0, + { 12729,-4717,-1188,-1367,9187,2582,274,860,4411 } }, + { "KODAK EasyShare Z990", 0, 0xfed, + { 11749,-4048,-1309,-1867,10572,1489,-138,1449,4522 } }, + { "KODAK EASYSHARE Z1015", 0, 0xef1, + { 11265,-4286,-992,-4694,12343,2647,-1090,1523,5447 } }, + { "Leaf CMost", 0, 0, + { 3952,2189,449,-6701,14585,2275,-4536,7349,6536 } }, + { "Leaf Valeo 6", 0, 0, + { 3952,2189,449,-6701,14585,2275,-4536,7349,6536 } }, + { "Leaf Aptus 54S", 0, 0, + { 8236,1746,-1314,-8251,15953,2428,-3673,5786,5771 } }, + { "Leaf Aptus 65", 0, 0, + { 7914,1414,-1190,-8777,16582,2280,-2811,4605,5562 } }, + { "Leaf Aptus 75", 0, 0, + { 7914,1414,-1190,-8777,16582,2280,-2811,4605,5562 } }, + { "Leaf Aptus 22", 0, 0, + { 8236, 1746, -1314, -8251, 15953, 2428, -3673, 5786, 5770, } }, + { "Leaf Aptus-II 5", 0, 0, // Mamiya 645 AFD + { 8236, 1746, -1314, -8251, 15953, 2428, -3673, 5786, 5770, } }, + { "Leaf Aptus-II 6", 0, 0, + { 7914, 1414, -1190, -8777, 16582, 2280, -2811, 4605, 5562, } }, + { "Leaf Aptus-II 7", 0, 0, + { 7914, 1414, -1190, -8777, 16582, 2280, -2811, 4605, 5562, } }, + { "Leaf Aptus-II 8", 0, 0, // Hasselblad 500 Series + { 8236, 1746, -1314, -8251, 15953, 2428, -3673, 5786, 5770, } }, + { "Leaf Aptus-II 10", 0, 0, + { 8236, 1746, -1314, -8251, 15953, 2428, -3673, 5786, 5770, } }, + { "Leaf Aptus-II 10R", 0, 0, + { 8236, 1746, -1314, -8251, 15953, 2428, -3673, 5786, 5770, } }, + { "Leaf Aptus-II 12", 0, 0, + { 8236, 1746, -1314, -8251, 15953, 2428, -3673, 5786, 5770, } }, + { "Leaf", 0, 0, + { 8236,1746,-1314,-8251,15953,2428,-3673,5786,5771 } }, + { "Mamiya ZD", 0, 0, + { 7645,2579,-1363,-8689,16717,2015,-3712,5941,5961 } }, + { "Micron 2010", 110, 0, /* DJC */ + { 16695,-3761,-2151,155,9682,163,3433,951,4904 } }, + { "Minolta DiMAGE 5", 0, 0xf7d, + { 8983,-2942,-963,-6556,14476,2237,-2426,2887,8014 } }, + { "Minolta DiMAGE 7Hi", 0, 0xf7d, + { 11368,-3894,-1242,-6521,14358,2339,-2475,3056,7285 } }, + { "Minolta DiMAGE 7", 0, 0xf7d, + { 9144,-2777,-998,-6676,14556,2281,-2470,3019,7744 } }, + { "Minolta DiMAGE A1", 0, 0xf8b, + { 9274,-2547,-1167,-8220,16323,1943,-2273,2720,8340 } }, + { "MINOLTA DiMAGE A200", 0, 0, + { 8560,-2487,-986,-8112,15535,2771,-1209,1324,7743 } }, + { "Minolta DiMAGE A2", 0, 0xf8f, + { 9097,-2726,-1053,-8073,15506,2762,-966,981,7763 } }, + { "Minolta DiMAGE Z2", 0, 0, /* DJC */ + { 11280,-3564,-1370,-4655,12374,2282,-1423,2168,5396 } }, + { "MINOLTA DYNAX 5", 0, 0xffb, + { 10284,-3283,-1086,-7957,15762,2316,-829,882,6644 } }, + { "MINOLTA DYNAX 7", 0, 0xffb, + { 10239,-3104,-1099,-8037,15727,2451,-927,925,6871 } }, + { "MOTOROLA PIXL", 0, 0, /* DJC */ + { 8898,-989,-1033,-3292,11619,1674,-661,3178,5216 } }, + { "NIKON D100", 0, 0, + { 5902,-933,-782,-8983,16719,2354,-1402,1455,6464 } }, + { "NIKON D1H", 0, 0, + { 7577,-2166,-926,-7454,15592,1934,-2377,2808,8606 } }, + { "NIKON D1X", 0, 0, + { 7702,-2245,-975,-9114,17242,1875,-2679,3055,8521 } }, + { "NIKON D1", 0, 0, /* multiplied by 2.218750, 1.0, 1.148438 */ + { 16772,-4726,-2141,-7611,15713,1972,-2846,3494,9521 } }, + { "NIKON D200", 0, 0xfbc, + { 8367,-2248,-763,-8758,16447,2422,-1527,1550,8053 } }, + { "NIKON D2H", 0, 0, + { 5710,-901,-615,-8594,16617,2024,-2975,4120,6830 } }, + { "NIKON D2X", 0, 0, + { 10231,-2769,-1255,-8301,15900,2552,-797,680,7148 } }, + { "NIKON D3000", 0, 0, + { 8736,-2458,-935,-9075,16894,2251,-1354,1242,8263 } }, + { "NIKON D3100", 0, 0, + { 7911,-2167,-813,-5327,13150,2408,-1288,2483,7968 } }, + { "NIKON D3200", 0, 0, + { 7013,-1408,-635,-5268,12902,2640,-1470,2801,7379 } }, + { "NIKON D300", 0, 0, + { 9030,-1992,-715,-8465,16302,2255,-2689,3217,8069 } }, + { "NIKON D3X", 0, 0, + { 7171,-1986,-648,-8085,15555,2718,-2170,2512,7457 } }, + { "NIKON D3S", 0, 0, + { 8828,-2406,-694,-4874,12603,2541,-660,1509,7587 } }, + { "NIKON D3", 0, 0, + { 8139,-2171,-663,-8747,16541,2295,-1925,2008,8093 } }, + { "NIKON D40X", 0, 0, + { 8819,-2543,-911,-9025,16928,2151,-1329,1213,8449 } }, + { "NIKON D40", 0, 0, + { 6992,-1668,-806,-8138,15748,2543,-874,850,7897 } }, + { "NIKON D4", 0, 0, + { 8598,-2848,-857,-5618,13606,2195,-1002,1773,7137 } }, + { "NIKON D5000", 0, 0xf00, + { 7309,-1403,-519,-8474,16008,2622,-2433,2826,8064 } }, + { "NIKON D5100", 0, 0x3de6, + { 8198,-2239,-724,-4871,12389,2798,-1043,2050,7181 } }, + { "NIKON D50", 0, 0, + { 7732,-2422,-789,-8238,15884,2498,-859,783,7330 } }, + { "NIKON D60", 0, 0, + { 8736,-2458,-935,-9075,16894,2251,-1354,1242,8263 } }, + { "NIKON D7000", 0, 0, + { 8198,-2239,-724,-4871,12389,2798,-1043,2050,7181 } }, + { "NIKON D700", 0, 0, + { 8139,-2171,-663,-8747,16541,2295,-1925,2008,8093 } }, + { "NIKON D70", 0, 0, + { 7732,-2422,-789,-8238,15884,2498,-859,783,7330 } }, + { "NIKON D800", 0, 0, + { 7866,-2108,-555,-4869,12483,2681,-1176,2069,7501 } }, + { "NIKON D80", 0, 0, + { 8629,-2410,-883,-9055,16940,2171,-1490,1363,8520 } }, + { "NIKON D90", 0, 0xf00, + { 7309,-1403,-519,-8474,16008,2622,-2434,2826,8064 } }, + { "NIKON E950", 0, 0x3dd, /* DJC */ + { -3746,10611,1665,9621,-1734,2114,-2389,7082,3064,3406,6116,-244 } }, + { "NIKON E995", 0, 0, /* copied from E5000 */ + { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, + { "NIKON E2100", 0, 0, /* copied from Z2, new white balance */ + { 13142,-4152,-1596,-4655,12374,2282,-1769,2696,6711} }, + { "NIKON E2500", 0, 0, + { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, + { "NIKON E3200", 0, 0, /* DJC */ + { 9846,-2085,-1019,-3278,11109,2170,-774,2134,5745 } }, + { "NIKON E4300", 0, 0, /* copied from Minolta DiMAGE Z2 */ + { 11280,-3564,-1370,-4655,12374,2282,-1423,2168,5396 } }, + { "NIKON E4500", 0, 0, + { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, + { "NIKON E5000", 0, 0, + { -5547,11762,2189,5814,-558,3342,-4924,9840,5949,688,9083,96 } }, + { "NIKON E5400", 0, 0, + { 9349,-2987,-1001,-7919,15766,2266,-2098,2680,6839 } }, + { "NIKON E5700", 0, 0, + { -5368,11478,2368,5537,-113,3148,-4969,10021,5782,778,9028,211 } }, + { "NIKON E8400", 0, 0, + { 7842,-2320,-992,-8154,15718,2599,-1098,1342,7560 } }, + { "NIKON E8700", 0, 0, + { 8489,-2583,-1036,-8051,15583,2643,-1307,1407,7354 } }, + { "NIKON E8800", 0, 0, + { 7971,-2314,-913,-8451,15762,2894,-1442,1520,7610 } }, + { "NIKON COOLPIX P6000", 0, 0, + { 9698,-3367,-914,-4706,12584,2368,-837,968,5801 } }, + { "NIKON COOLPIX P7000", 0, 0, + { 11432,-3679,-1111,-3169,11239,2202,-791,1380,4455 } }, + { "NIKON COOLPIX P7100", 0, 0, + { 11053,-4269,-1024,-1976,10182,2088,-526,1263,4469 } }, + { "NIKON 1 ", 0, 0, + { 8994,-2667,-865,-4594,12324,2552,-699,1786,6260 } }, + { "OLYMPUS C5050", 0, 0, + { 10508,-3124,-1273,-6079,14294,1901,-1653,2306,6237 } }, + { "OLYMPUS C5060", 0, 0, + { 10445,-3362,-1307,-7662,15690,2058,-1135,1176,7602 } }, + { "OLYMPUS C7070", 0, 0, + { 10252,-3531,-1095,-7114,14850,2436,-1451,1723,6365 } }, + { "OLYMPUS C70", 0, 0, + { 10793,-3791,-1146,-7498,15177,2488,-1390,1577,7321 } }, + { "OLYMPUS C80", 0, 0, + { 8606,-2509,-1014,-8238,15714,2703,-942,979,7760 } }, + { "OLYMPUS E-10", 0, 0xffc, + { 12745,-4500,-1416,-6062,14542,1580,-1934,2256,6603 } }, + { "OLYMPUS E-1", 0, 0, + { 11846,-4767,-945,-7027,15878,1089,-2699,4122,8311 } }, + { "OLYMPUS E-20", 0, 0xffc, + { 13173,-4732,-1499,-5807,14036,1895,-2045,2452,7142 } }, + { "OLYMPUS E-300", 0, 0, + { 7828,-1761,-348,-5788,14071,1830,-2853,4518,6557 } }, + { "OLYMPUS E-330", 0, 0, + { 8961,-2473,-1084,-7979,15990,2067,-2319,3035,8249 } }, + { "OLYMPUS E-30", 0, 0xfbc, + { 8144,-1861,-1111,-7763,15894,1929,-1865,2542,7607 } }, + { "OLYMPUS E-3", 0, 0xf99, + { 9487,-2875,-1115,-7533,15606,2010,-1618,2100,7389 } }, + { "OLYMPUS E-400", 0, 0, + { 6169,-1483,-21,-7107,14761,2536,-2904,3580,8568 } }, + { "OLYMPUS E-410", 0, 0xf6a, + { 8856,-2582,-1026,-7761,15766,2082,-2009,2575,7469 } }, + { "OLYMPUS E-420", 0, 0xfd7, + { 8746,-2425,-1095,-7594,15612,2073,-1780,2309,7416 } }, + { "OLYMPUS E-450", 0, 0xfd2, + { 8745,-2425,-1095,-7594,15613,2073,-1780,2309,7416 } }, + { "OLYMPUS E-500", 0, 0, + { 8136,-1968,-299,-5481,13742,1871,-2556,4205,6630 } }, + { "OLYMPUS E-510", 0, 0xf6a, + { 8785,-2529,-1033,-7639,15624,2112,-1783,2300,7817 } }, + { "OLYMPUS E-520", 0, 0xfd2, + { 8344,-2322,-1020,-7596,15635,2048,-1748,2269,7287 } }, + { "OLYMPUS E-5", 0, 0, + { 11200,-3783,-1325,-4576,12593,2206,-695,1742,7504 } }, + { "OLYMPUS E-600", 0, 0xfaf, + { 8453,-2198,-1092,-7609,15681,2008,-1725,2337,7824 } }, + { "OLYMPUS E-620", 0, 0xfaf, + { 8453,-2198,-1092,-7609,15681,2008,-1725,2337,7824 } }, + { "OLYMPUS E-P1", 0, 0xffd, + { 8343,-2050,-1021,-7715,15705,2103,-1831,2380,8235 } }, + { "OLYMPUS E-P2", 0, 0xffd, + { 8343,-2050,-1021,-7715,15705,2103,-1831,2380,8235 } }, + { "OLYMPUS E-P3", 0, 0, + { 7575,-2159,-571,-3722,11341,2725,-1434,2819,6271 } }, + { "OLYMPUS E-PL1s", 0, 0, + { 11409,-3872,-1393,-4572,12757,2003,-709,1810,7415 } }, + { "OLYMPUS E-PL1", 0, 0, + { 11408,-4289,-1215,-4286,12385,2118,-387,1467,7787 } }, + { "OLYMPUS E-PL2", 0, 0, + { 15030,-5552,-1806,-3987,12387,1767,-592,1670,7023 } }, + { "OLYMPUS E-PL3", 0, 0, + { 7575,-2159,-571,-3722,11341,2725,-1434,2819,6271 } }, + { "OLYMPUS E-PM1", 0, 0, + { 7575,-2159,-571,-3722,11341,2725,-1434,2819,6271 } }, + { "OLYMPUS E-M5", 0, 0, + { 8380,-2630,-639,-2887,10725,2496,-627,1427,5438 } }, + { "OLYMPUS SP350", 0, 0, + { 12078,-4836,-1069,-6671,14306,2578,-786,939,7418 } }, + { "OLYMPUS SP3", 0, 0, + { 11766,-4445,-1067,-6901,14421,2707,-1029,1217,7572 } }, + { "OLYMPUS SP500UZ", 0, 0xfff, + { 9493,-3415,-666,-5211,12334,3260,-1548,2262,6482 } }, + { "OLYMPUS SP510UZ", 0, 0xffe, + { 10593,-3607,-1010,-5881,13127,3084,-1200,1805,6721 } }, + { "OLYMPUS SP550UZ", 0, 0xffe, + { 11597,-4006,-1049,-5432,12799,2957,-1029,1750,6516 } }, + { "OLYMPUS SP560UZ", 0, 0xff9, + { 10915,-3677,-982,-5587,12986,2911,-1168,1968,6223 } }, + { "OLYMPUS SP570UZ", 0, 0, + { 11522,-4044,-1146,-4736,12172,2904,-988,1829,6039 } }, + { "OLYMPUS XZ-1", 0, 0, + { 10901,-4095,-1074,-1141,9208,2293,-62,1417,5158 } }, + { "PENTAX *ist DL2", 0, 0, + { 10504,-2438,-1189,-8603,16207,2531,-1022,863,12242 } }, + { "PENTAX *ist DL", 0, 0, + { 10829,-2838,-1115,-8339,15817,2696,-837,680,11939 } }, + { "PENTAX *ist DS2", 0, 0, + { 10504,-2438,-1189,-8603,16207,2531,-1022,863,12242 } }, + { "PENTAX *ist DS", 0, 0, + { 10371,-2333,-1206,-8688,16231,2602,-1230,1116,11282 } }, + { "PENTAX *ist D", 0, 0, + { 9651,-2059,-1189,-8881,16512,2487,-1460,1345,10687 } }, + { "PENTAX K10D", 0, 0, + { 9566,-2863,-803,-7170,15172,2112,-818,803,9705 } }, + { "PENTAX K1", 0, 0, + { 11095,-3157,-1324,-8377,15834,2720,-1108,947,11688 } }, + { "PENTAX K20D", 0, 0, + { 9427,-2714,-868,-7493,16092,1373,-2199,3264,7180 } }, + { "PENTAX K200D", 0, 0, + { 9186,-2678,-907,-8693,16517,2260,-1129,1094,8524 } }, + { "PENTAX K2000", 0, 0, + { 11057,-3604,-1155,-5152,13046,2329,-282,375,8104 } }, + { "PENTAX K-m", 0, 0, + { 11057,-3604,-1155,-5152,13046,2329,-282,375,8104 } }, + { "PENTAX K-x", 0, 0, + { 8843,-2837,-625,-5025,12644,2668,-411,1234,7410 } }, + { "PENTAX K-r", 0, 0, + { 9895,-3077,-850,-5304,13035,2521,-883,1768,6936 } }, + { "PENTAX K-5", 0, 0, + { 8713,-2833,-743,-4342,11900,2772,-722,1543,6247 } }, + { "PENTAX K-7", 0, 0, + { 9142,-2947,-678,-8648,16967,1663,-2224,2898,8615 } }, + { "PENTAX 645D", 0, 0x3e00, + { 10646,-3593,-1158,-3329,11699,1831,-667,2874,6287 } }, + { "Panasonic DMC-FZ8", 0, 0xf7f, + { 8986,-2755,-802,-6341,13575,3077,-1476,2144,6379 } }, + { "Panasonic DMC-FZ18", 0, 0, + { 9932,-3060,-935,-5809,13331,2753,-1267,2155,5575 } }, + { "Panasonic DMC-FZ28", 15, 0xf96, + { 10109,-3488,-993,-5412,12812,2916,-1305,2140,5543 } }, + { "Panasonic DMC-FZ30", 0, 0xf94, + { 10976,-4029,-1141,-7918,15491,2600,-1670,2071,8246 } }, + { "Panasonic DMC-FZ3", 143, 0, + { 9938,-2780,-890,-4604,12393,2480,-1117,2304,4620 } }, + { "Panasonic DMC-FZ4", 143, 0, + { 13639,-5535,-1371,-1698,9633,2430,316,1152,4108 } }, + { "Panasonic DMC-FZ50", 0, 0, + { 7906,-2709,-594,-6231,13351,3220,-1922,2631,6537 } }, + { "LEICA V-LUX1", 0, 0, + { 7906,-2709,-594,-6231,13351,3220,-1922,2631,6537 } }, + { "Panasonic DMC-L10", 15, 0xf96, + { 8025,-1942,-1050,-7920,15904,2100,-2456,3005,7039 } }, + { "Panasonic DMC-L1", 0, 0xf7f, + { 8054,-1885,-1025,-8349,16367,2040,-2805,3542,7629 } }, + { "LEICA DIGILUX 3", 0, 0xf7f, + { 8054,-1885,-1025,-8349,16367,2040,-2805,3542,7629 } }, + { "Panasonic DMC-LC1", 0, 0, + { 11340,-4069,-1275,-7555,15266,2448,-2960,3426,7685 } }, + { "LEICA DIGILUX 2", 0, 0, + { 11340,-4069,-1275,-7555,15266,2448,-2960,3426,7685 } }, + { "Panasonic DMC-LX1", 0, 0xf7f, + { 10704,-4187,-1230,-8314,15952,2501,-920,945,8927 } }, + { "LEICA D-LUX2", 0, 0xf7f, + { 10704,-4187,-1230,-8314,15952,2501,-920,945,8927 } }, + { "Panasonic DMC-LX2", 0, 0, + { 8048,-2810,-623,-6450,13519,3272,-1700,2146,7049 } }, + { "LEICA D-LUX3", 0, 0, + { 8048,-2810,-623,-6450,13519,3272,-1700,2146,7049 } }, + { "Panasonic DMC-LX3", 15, 0, + { 8128,-2668,-655,-6134,13307,3161,-1782,2568,6083 } }, + { "LEICA D-LUX 4", 15, 0, + { 8128,-2668,-655,-6134,13307,3161,-1782,2568,6083 } }, + { "Panasonic DMC-LX5", 143, 0, + { 10909,-4295,-948,-1333,9306,2399,22,1738,4582 } }, + { "LEICA D-LUX 5", 143, 0, + { 10909,-4295,-948,-1333,9306,2399,22,1738,4582 } }, + { "Panasonic DMC-FZ100", 143, 0xfff, + { 16197,-6146,-1761,-2393,10765,1869,366,2238,5248 } }, + { "LEICA V-LUX 2", 143, 0xfff, + { 16197,-6146,-1761,-2393,10765,1869,366,2238,5248 } }, + { "Panasonic DMC-FZ150", 143, 0xfff, + { 11904,-4541,-1189,-2355,10899,1662,-296,1586,4289 } }, + { "LEICA V-LUX 3", 143, 0xfff, + { 11904,-4541,-1189,-2355,10899,1662,-296,1586,4289 } }, + { "Panasonic DMC-FX150", 15, 0xfff, + { 9082,-2907,-925,-6119,13377,3058,-1797,2641,5609 } }, + { "Panasonic DMC-G10", 0, 0, + { 10113,-3400,-1114,-4765,12683,2317,-377,1437,6710 } }, + { "Panasonic DMC-G1", 15, 0xf94, + { 8199,-2065,-1056,-8124,16156,2033,-2458,3022,7220 } }, + { "Panasonic DMC-G2", 15, 0xf3c, + { 10113,-3400,-1114,-4765,12683,2317,-377,1437,6710 } }, + { "Panasonic DMC-G3", 143, 0xfff, + { 6763,-1919,-863,-3868,11515,2684,-1216,2387,5879 } }, + { "Panasonic DMC-GF1", 15, 0xf92, + { 7888,-1902,-1011,-8106,16085,2099,-2353,2866,7330 } }, + { "Panasonic DMC-GF2", 143, 0xfff, + { 7888,-1902,-1011,-8106,16085,2099,-2353,2866,7330 } }, + { "Panasonic DMC-GF3", 143, 0xfff, + { 9051,-2468,-1204,-5212,13276,2121,-1197,2510,6890 } }, + { "Panasonic DMC-GF5", 143, 0xfff, + { 8228,-2945,-660,-3938,11792,2430,-1094,2278,5793 } }, + { "Panasonic DMC-GH1", 15, 0xf92, + { 6299,-1466,-532,-6535,13852,2969,-2331,3112,5984 } }, + { "Panasonic DMC-GH2", 15, 0xf95, + { 7780,-2410,-806,-3913,11724,2484,-1018,2390,5298 } }, + { "Panasonic DMC-GX1", 143, 0, + { 6763,-1919,-863,-3868,11515,2684,-1216,2387,5879 } }, + { "Phase One H 20", 0, 0, /* DJC */ + { 1313,1855,-109,-6715,15908,808,-327,1840,6020 } }, + { "Phase One H 25", 0, 0, + { 2905,732,-237,-8134,16626,1476,-3038,4253,7517 } }, + { "Phase One P 2", 0, 0, + { 2905,732,-237,-8134,16626,1476,-3038,4253,7517 } }, + { "Phase One P 30", 0, 0, + { 4516,-245,-37,-7020,14976,2173,-3206,4671,7087 } }, + { "Phase One P 45", 0, 0, + { 5053,-24,-117,-5684,14076,1702,-2619,4492,5849 } }, + { "Phase One P40", 0, 0, + { 8035,435,-962,-6001,13872,2320,-1159,3065,5434 } }, + { "Phase One P65", 0, 0, + { 8035,435,-962,-6001,13872,2320,-1159,3065,5434 } }, + { "RED ONE", 704, 0xffff, /* DJC */ + { 21014,-7891,-2613,-3056,12201,856,-2203,5125,8042 } }, + { "SAMSUNG EX1", 0, 0x3e00, + { 8898,-2498,-994,-3144,11328,2066,-760,1381,4576 } }, + { "SAMSUNG NX2", 0, 0xfff, /* NX20, NX200, NX210 */ + { 6933,-2268,-753,-4921,13387,1647,-803,1641,6096 } }, + { "SAMSUNG NX", 0, 0, /* NX5, NX10, NX11, NX100 */ + { 10332,-3234,-1168,-6111,14639,1520,-1352,2647,8331 } }, + { "SAMSUNG WB2000", 0, 0xfff, + { 12093,-3557,-1155,-1000,9534,1733,-22,1787,4576 } }, + { "SAMSUNG GX-1", 0, 0, + { 10504,-2438,-1189,-8603,16207,2531,-1022,863,12242 } }, + { "SAMSUNG S85", 0, 0xffff, /* DJC */ + { 11885,-3968,-1473,-4214,12299,1916,-835,1655,5549 } }, + { "Sinar", 0, 0, /* DJC */ + { 16442,-2956,-2422,-2877,12128,750,-1136,6066,4559 } }, + { "SONY DSC-F828", 491, 0, + { 7924,-1910,-777,-8226,15459,2998,-1517,2199,6818,-7242,11401,3481 } }, + { "SONY DSC-R1", 512, 0, + { 8512,-2641,-694,-8042,15670,2526,-1821,2117,7414 } }, + { "SONY DSC-V3", 0, 0, + { 7511,-2571,-692,-7894,15088,3060,-948,1111,8128 } }, + { "SONY DSLR-A100", 0, 0xfeb, + { 9437,-2811,-774,-8405,16215,2290,-710,596,7181 } }, + { "SONY DSLR-A290", 0, 0, + { 6038,-1484,-579,-9145,16746,2512,-875,746,7218 } }, + { "SONY DSLR-A2", 0, 0, + { 9847,-3091,-928,-8485,16345,2225,-715,595,7103 } }, + { "SONY DSLR-A300", 0, 0, + { 9847,-3091,-928,-8485,16345,2225,-715,595,7103 } }, + { "SONY DSLR-A330", 0, 0, + { 9847,-3091,-929,-8485,16346,2225,-714,595,7103 } }, + { "SONY DSLR-A350", 0, 0xffc, + { 6038,-1484,-578,-9146,16746,2513,-875,746,7217 } }, + { "SONY DSLR-A380", 0, 0, + { 6038,-1484,-579,-9145,16746,2512,-875,746,7218 } }, + { "SONY DSLR-A390", 0, 0, + { 6038,-1484,-579,-9145,16746,2512,-875,746,7218 } }, + { "SONY DSLR-A450", 128, 0xfeb, + { 4950,-580,-103,-5228,12542,3029,-709,1435,7371 } }, + { "SONY DSLR-A580", 128, 0xfeb, + { 5932,-1492,-411,-4813,12285,2856,-741,1524,6739 } }, + { "SONY DSLR-A5", 128, 0xfeb, + { 4950,-580,-103,-5228,12542,3029,-709,1435,7371 } }, + { "SONY DSLR-A700", 126, 0, + { 5775,-805,-359,-8574,16295,2391,-1943,2341,7249 } }, + { "SONY DSLR-A850", 128, 0, + { 5413,-1162,-365,-5665,13098,2866,-608,1179,8440 } }, + { "SONY DSLR-A900", 128, 0, + { 5209,-1072,-397,-8845,16120,2919,-1618,1803,8654 } }, + { "SONY NEX-5N", 128, 0, + { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, + { "SONY NEX-3", 138, 0, /* DJC */ + { 6907,-1256,-645,-4940,12621,2320,-1710,2581,6230 } }, + { "SONY NEX-5", 116, 0, /* DJC */ + { 6807,-1350,-342,-4216,11649,2567,-1089,2001,6420 } }, + { "SONY NEX-3", 128, 0, /* Adobe */ + { 6549,-1550,-436,-4880,12435,2753,-854,1868,6976 } }, + { "SONY NEX-5", 128, 0, /* Adobe */ + { 6549,-1550,-436,-4880,12435,2753,-854,1868,6976 } }, + { "SONY NEX-7", 128, 0, + { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } }, + { "SONY NEX", 128, 0, /* NEX-C3, NEX-F3 */ + { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, + { "SONY SLT-A33", 128, 0, + { 6069,-1221,-366,-5221,12779,2734,-1024,2066,6834 } }, + { "SONY SLT-A35", 128, 0, + { 5986,-1618,-415,-4557,11820,3120,-681,1404,6971 } }, + { "SONY SLT-A37", 128, 0, + { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, + { "SONY SLT-A55", 128, 0, + { 5932,-1492,-411,-4813,12285,2856,-741,1524,6739 } }, + { "SONY SLT-A57", 128, 0, + { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } }, + { "SONY SLT-A65", 128, 0, + { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } }, + { "SONY SLT-A77", 128, 0, + { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } } + }; + double cam_xyz[4][3]; + char name[130]; + int i, j; + + sprintf (name, "%s %s", p_make, p_model); + for (i=0; i < sizeof table / sizeof *table; i++) + if (!strncmp (name, table[i].prefix, strlen(table[i].prefix))) { + if (table[i].t_black) black = (ushort) table[i].t_black; + if (table[i].t_maximum) maximum = (ushort) table[i].t_maximum; + if (table[i].trans[0]) { + for (j=0; j < 12; j++) +#ifdef LIBRAW_LIBRARY_BUILD + imgdata.color.cam_xyz[0][j] = +#endif + cam_xyz[0][j] = table[i].trans[j] / 10000.0; + cam_xyz_coeff (cam_xyz); + } + break; + } +} + +void CLASS simple_coeff (int index) +{ + static const float table[][12] = { + /* index 0 -- all Foveon cameras */ + { 1.4032,-0.2231,-0.1016,-0.5263,1.4816,0.017,-0.0112,0.0183,0.9113 }, + /* index 1 -- Kodak DC20 and DC25 */ + { 2.25,0.75,-1.75,-0.25,-0.25,0.75,0.75,-0.25,-0.25,-1.75,0.75,2.25 }, + /* index 2 -- Logitech Fotoman Pixtura */ + { 1.893,-0.418,-0.476,-0.495,1.773,-0.278,-1.017,-0.655,2.672 }, + /* index 3 -- Nikon E880, E900, and E990 */ + { -1.936280, 1.800443, -1.448486, 2.584324, + 1.405365, -0.524955, -0.289090, 0.408680, + -1.204965, 1.082304, 2.941367, -1.818705 } + }; + int i, c; + + for (raw_color = i=0; i < 3; i++) + FORCC rgb_cam[i][c] = table[index][i*colors+c]; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.rgb_cam_state = LIBRAW_COLORSTATE_CALCULATED; +#endif +} + +short CLASS guess_byte_order (int words) +{ + uchar test[4][2]; + int t=2, msb; + double diff, sum[2] = {0,0}; + + fread (test[0], 2, 2, ifp); + for (words-=2; words--; ) { + fread (test[t], 2, 1, ifp); + for (msb=0; msb < 2; msb++) { + diff = (test[t^2][msb] << 8 | test[t^2][!msb]) + - (test[t ][msb] << 8 | test[t ][!msb]); + sum[msb] += diff*diff; + } + t = (t+1) & 3; + } + return sum[0] < sum[1] ? 0x4d4d : 0x4949; +} + + +float CLASS find_green (int bps, int bite, int off0, int off1) +{ + UINT64 bitbuf=0; + int vbits, col, i, c; + ushort img[2][2064]; + double sum[]={0,0}; + + FORC(2) { + fseek (ifp, c ? off1:off0, SEEK_SET); + for (vbits=col=0; col < width; col++) { + for (vbits -= bps; vbits < 0; vbits += bite) { + bitbuf <<= bite; + for (i=0; i < bite; i+=8) + bitbuf |= (unsigned) (fgetc(ifp) << i); + } + img[c][col] = bitbuf << (64-bps-vbits) >> (64-bps); + } + } + FORC(width-1) { + sum[ c & 1] += ABS(img[0][c]-img[1][c+1]); + sum[~c & 1] += ABS(img[1][c]-img[0][c+1]); + } + return 100 * log(sum[0]/sum[1]); +} + +/* + Identify which camera created this file, and set global variables + accordingly. + */ +void CLASS identify() +{ + char head[32], *cp; + int hlen, flen, fsize, zero_fsize=1, i, c, is_canon; + struct jhead jh; + short pana[][6] = { + { 3130, 1743, 4, 0, -6, 0 }, + { 3130, 2055, 4, 0, -6, 0 }, + { 3130, 2319, 4, 0, -6, 0 }, + { 3170, 2103, 18, 0,-42, 20 }, + { 3170, 2367, 18, 13,-42,-21 }, + { 3177, 2367, 0, 0, -1, 0 }, + { 3304, 2458, 0, 0, -1, 0 }, + { 3330, 2463, 9, 0, -5, 0 }, + { 3330, 2479, 9, 0,-17, 4 }, + { 3370, 1899, 15, 0,-44, 20 }, + { 3370, 2235, 15, 0,-44, 20 }, + { 3370, 2511, 15, 10,-44,-21 }, + { 3690, 2751, 3, 0, -8, -3 }, + { 3710, 2751, 0, 0, -3, 0 }, + { 3724, 2450, 0, 0, 0, -2 }, + { 3770, 2487, 17, 0,-44, 19 }, + { 3770, 2799, 17, 15,-44,-19 }, + { 3880, 2170, 6, 0, -6, 0 }, + { 4060, 3018, 0, 0, 0, -2 }, + { 4290, 2391, 3, 0, -8, -1 }, + { 4330, 2439, 17, 15,-44,-19 }, + { 4508, 2962, 0, 0, -3, -4 }, + { 4508, 3330, 0, 0, -3, -6 } }; + static const struct { + int fsize; + char t_make[12], t_model[19], withjpeg; + } table[] = { + { 62464, "Kodak", "DC20" ,0 }, + { 124928, "Kodak", "DC20" ,0 }, + { 1652736, "Kodak", "DCS200" ,0 }, + { 4159302, "Kodak", "C330" ,0 }, + { 4162462, "Kodak", "C330" ,0 }, + { 460800, "Kodak", "C603v" ,0 }, + { 614400, "Kodak", "C603v" ,0 }, + { 6163328, "Kodak", "C603" ,0 }, + { 6166488, "Kodak", "C603" ,0 }, + { 9116448, "Kodak", "C603y" ,0 }, + { 311696, "ST Micro", "STV680 VGA" ,0 }, /* SPYz */ + { 787456, "Creative", "PC-CAM 600" ,0 }, + { 1138688, "Minolta", "RD175" ,0 }, + { 3840000, "Foculus", "531C" ,0 }, + { 307200, "Generic", "640x480" ,0 }, + { 786432, "AVT", "F-080C" ,0 }, + { 1447680, "AVT", "F-145C" ,0 }, + { 1920000, "AVT", "F-201C" ,0 }, + { 5067304, "AVT", "F-510C" ,0 }, + { 5067316, "AVT", "F-510C" ,0 }, + { 10134608, "AVT", "F-510C" ,0 }, + { 10134620, "AVT", "F-510C" ,0 }, + { 16157136, "AVT", "F-810C" ,0 }, + { 1409024, "Sony", "XCD-SX910CR" ,0 }, + { 2818048, "Sony", "XCD-SX910CR" ,0 }, + { 3884928, "Micron", "2010" ,0 }, + { 6624000, "Pixelink", "A782" ,0 }, + { 13248000, "Pixelink", "A782" ,0 }, + { 6291456, "RoverShot","3320AF" ,0 }, + { 6553440, "Canon", "PowerShot A460" ,0 }, + { 6653280, "Canon", "PowerShot A530" ,0 }, + { 6573120, "Canon", "PowerShot A610" ,0 }, + { 9219600, "Canon", "PowerShot A620" ,0 }, + { 9243240, "Canon", "PowerShot A470" ,0 }, + { 10341600, "Canon", "PowerShot A720 IS",0 }, + { 10383120, "Canon", "PowerShot A630" ,0 }, + { 12945240, "Canon", "PowerShot A640" ,0 }, + { 15636240, "Canon", "PowerShot A650" ,0 }, + { 5298000, "Canon", "PowerShot SD300" ,0 }, + { 7710960, "Canon", "PowerShot S3 IS" ,0 }, + { 15467760, "Canon", "PowerShot SX110 IS",0 }, + { 15534576, "Canon", "PowerShot SX120 IS",0 }, + { 18653760, "Canon", "PowerShot SX20 IS",0 }, + { 19131120, "Canon", "PowerShot SX220 HS",0 }, + { 21936096, "Canon", "PowerShot SX30 IS",0 }, + { 5939200, "OLYMPUS", "C770UZ" ,0 }, + { 1581060, "NIKON", "E900" ,1 }, /* or E900s,E910 */ + { 2465792, "NIKON", "E950" ,1 }, /* or E800,E700 */ + { 2940928, "NIKON", "E2100" ,1 }, /* or E2500 */ + { 4771840, "NIKON", "E990" ,1 }, /* or E995, Oly C3030Z */ + { 4775936, "NIKON", "E3700" ,1 }, /* or Optio 33WR */ + { 5869568, "NIKON", "E4300" ,1 }, /* or DiMAGE Z2 */ + { 5865472, "NIKON", "E4500" ,1 }, + { 7438336, "NIKON", "E5000" ,1 }, /* or E5700 */ + { 8998912, "NIKON", "COOLPIX S6" ,1 }, + { 1976352, "CASIO", "QV-2000UX" ,1 }, + { 3217760, "CASIO", "QV-3*00EX" ,1 }, + { 6218368, "CASIO", "QV-5700" ,1 }, + { 6054400, "CASIO", "QV-R41" ,1 }, + { 7530816, "CASIO", "QV-R51" ,1 }, + { 7684000, "CASIO", "QV-4000" ,1 }, + { 2937856, "CASIO", "EX-S20" ,1 }, + { 4948608, "CASIO", "EX-S100" ,1 }, + { 7542528, "CASIO", "EX-Z50" ,1 }, + { 7562048, "CASIO", "EX-Z500" ,1 }, + { 7753344, "CASIO", "EX-Z55" ,1 }, + { 7816704, "CASIO", "EX-Z60" ,1 }, + { 10843712, "CASIO", "EX-Z75" ,1 }, + { 10834368, "CASIO", "EX-Z750" ,1 }, + { 12310144, "CASIO", "EX-Z850" ,1 }, + { 12489984, "CASIO", "EX-Z8" ,1 }, + { 15499264, "CASIO", "EX-Z1050" ,1 }, + { 7426656, "CASIO", "EX-P505" ,1 }, + { 9313536, "CASIO", "EX-P600" ,1 }, + { 10979200, "CASIO", "EX-P700" ,1 }, + { 3178560, "PENTAX", "Optio S" ,1 }, + { 4841984, "PENTAX", "Optio S" ,1 }, + { 6114240, "PENTAX", "Optio S4" ,1 }, /* or S4i, CASIO EX-Z4 */ + { 10702848, "PENTAX", "Optio 750Z" ,1 }, + { 15980544, "AGFAPHOTO","DC-833m" ,1 }, + { 16098048, "SAMSUNG", "S85" ,1 }, + { 16215552, "SAMSUNG", "S85" ,1 }, + { 20487168, "SAMSUNG", "WB550" ,1 }, + { 24000000, "SAMSUNG", "WB550" ,1 }, + { 9994240, "ptGrey", "GRAS-50S5C" ,0 }, // KC: SUPPORT GRASSHOPPER + { 10075968, "JaiPulnix","BB-500CL" ,0 }, // KC: SUPPORT BB-500CL + { 10108896, "JaiPulnix","BB-500GE" ,0 }, // KC: SUPPORT BB-500GE + { 10036800, "SVS", "SVS625CL" ,0 }, // KC: SUPPORT SVS625 cameralink + { 12582980, "Sinar", "" ,0 }, + { 33292868, "Sinar", "" ,0 }, + { 44390468, "Sinar", "" ,0 } }; + static const char *corp[] = + { "Canon", "NIKON", "EPSON", "KODAK", "Kodak", "OLYMPUS", "PENTAX", + "MINOLTA", "Minolta", "Konica", "CASIO", "Sinar", "Phase One", + "SAMSUNG", "Mamiya", "MOTOROLA", "LEICA" }; + +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_IDENTIFY,0,2); +#endif + + tiff_flip = flip = filters = -1; /* 0 is valid, so -1 is unknown */ + raw_height = raw_width = fuji_width = fuji_layout = cr2_slice[0] = 0; + maximum = height = width = top_margin = left_margin = 0; + cdesc[0] = desc[0] = artist[0] = make[0] = model[0] = model2[0] = 0; + iso_speed = shutter = aperture = focal_len = unique_id = 0; + tiff_nifds = 0; + memset (tiff_ifd, 0, sizeof tiff_ifd); + memset (gpsdata, 0, sizeof gpsdata); + memset (cblack, 0, sizeof cblack); + memset (white, 0, sizeof white); + thumb_offset = thumb_length = thumb_width = thumb_height = 0; + load_raw = thumb_load_raw = 0; + write_thumb = &CLASS jpeg_thumb; + data_offset = meta_length = tiff_bps = tiff_compress = 0; + kodak_cbpp = zero_after_ff = dng_version = load_flags = 0; + timestamp = shot_order = tiff_samples = black = is_foveon = 0; + mix_green = profile_length = data_error = zero_is_bad = 0; + pixel_aspect = is_raw = raw_color = 1; + tile_width = tile_length = INT_MAX; + for (i=0; i < 4; i++) { + cam_mul[i] = i == 1; + pre_mul[i] = i < 3; + FORC3 cmatrix[c][i] = 0; + FORC3 rgb_cam[c][i] = c == i; + } +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cmatrix_state = LIBRAW_COLORSTATE_INIT; + color_flags.rgb_cam_state = LIBRAW_COLORSTATE_INIT; + color_flags.pre_mul_state = LIBRAW_COLORSTATE_INIT; + color_flags.cam_mul_state = LIBRAW_COLORSTATE_INIT; +#endif + colors = 3; + for (i=0; i < 0x4000; i++) curve[i] = i; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.curve_state = LIBRAW_COLORSTATE_INIT; +#endif + + order = get2(); + hlen = get4(); + fseek (ifp, 0, SEEK_SET); + fread (head, 1, 32, ifp); + fseek (ifp, 0, SEEK_END); + flen = fsize = ftell(ifp); + if ((cp = (char *) memmem (head, 32, (char*)"MMMM", 4)) || + (cp = (char *) memmem (head, 32, (char*)"IIII", 4))) { + parse_phase_one (cp-head); + if (cp-head && parse_tiff(0)) apply_tiff(); + } else if (order == 0x4949 || order == 0x4d4d) { + if (!memcmp (head+6,"HEAPCCDR",8)) { + data_offset = hlen; + parse_ciff (hlen, flen - hlen); + } else if (parse_tiff(0)) apply_tiff(); + } else if (!memcmp (head,"\xff\xd8\xff\xe1",4) && + !memcmp (head+6,"Exif",4)) { + fseek (ifp, 4, SEEK_SET); + data_offset = 4 + get2(); + fseek (ifp, data_offset, SEEK_SET); + if (fgetc(ifp) != 0xff) + parse_tiff(12); + thumb_offset = 0; + } else if (!memcmp (head+25,"ARECOYK",7)) { + strcpy (make, "Contax"); + strcpy (model,"N Digital"); + fseek (ifp, 33, SEEK_SET); + get_timestamp(1); + fseek (ifp, 60, SEEK_SET); + FORC4 cam_mul[c ^ (c >> 1)] = get4(); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.cam_mul_state = LIBRAW_COLORSTATE_LOADED; +#endif + } else if (!strcmp (head, "PXN")) { + strcpy (make, "Logitech"); + strcpy (model,"Fotoman Pixtura"); + } else if (!strcmp (head, "qktk")) { + strcpy (make, "Apple"); + strcpy (model,"QuickTake 100"); + load_raw = &CLASS quicktake_100_load_raw; + } else if (!strcmp (head, "qktn")) { + strcpy (make, "Apple"); + strcpy (model,"QuickTake 150"); + load_raw = &CLASS kodak_radc_load_raw; + } else if (!memcmp (head,"FUJIFILM",8)) { + fseek (ifp, 84, SEEK_SET); + thumb_offset = get4(); + thumb_length = get4(); + fseek (ifp, 92, SEEK_SET); + parse_fuji (get4()); + if (thumb_offset > 120) { + fseek (ifp, 120, SEEK_SET); + is_raw += (i = get4()) && 1; + if (is_raw == 2 && shot_select) + parse_fuji (i); + } +// load_raw = &CLASS unpacked_load_raw; + fseek (ifp, 100+28*(shot_select > 0), SEEK_SET); + parse_tiff (data_offset = get4()); + parse_tiff (thumb_offset+12); + apply_tiff(); + } else if (!memcmp (head,"RIFF",4)) { + fseek (ifp, 0, SEEK_SET); + parse_riff(); + } else if (!memcmp (head,"\0\001\0\001\0@",6)) { + fseek (ifp, 6, SEEK_SET); + fread (make, 1, 8, ifp); + fread (model, 1, 8, ifp); + fread (model2, 1, 16, ifp); + data_offset = get2(); + get2(); + raw_width = get2(); + raw_height = get2(); + load_raw = &CLASS nokia_load_raw; + filters = 0x61616161; + } else if (!memcmp (head,"NOKIARAW",8)) { + strcpy (make, "NOKIA"); + strcpy (model, "X2"); + order = 0x4949; + fseek (ifp, 300, SEEK_SET); + data_offset = get4(); + i = get4(); + width = get2(); + height = get2(); + data_offset += i - width * 5 / 4 * height; + load_raw = &CLASS nokia_load_raw; + filters = 0x61616161; + } else if (!memcmp (head,"ARRI",4)) { + order = 0x4949; + fseek (ifp, 20, SEEK_SET); + width = get4(); + height = get4(); + strcpy (make, "ARRI"); + fseek (ifp, 668, SEEK_SET); + fread (model, 1, 64, ifp); + data_offset = 4096; + load_raw = &CLASS packed_load_raw; + load_flags = 88; + filters = 0x61616161; + } else if (!memcmp (head+4,"RED1",4)) { + strcpy (make, "RED"); + strcpy (model,"ONE"); + parse_redcine(); + load_raw = &CLASS redcine_load_raw; + gamma_curve (1/2.4, 12.92, 1, 4095); + filters = 0x49494949; + } else if (!memcmp (head,"DSC-Image",9)) + parse_rollei(); + else if (!memcmp (head,"PWAD",4)) + parse_sinar_ia(); + else if (!memcmp (head,"\0MRM",4)) + parse_minolta(0); + else if (!memcmp (head,"FOVb",4)) + { + parse_foveon(); + if(!strcasecmp(make,"SIGMA") && !strncasecmp(model,"SIGMA DP",8)) + { + make[0] = model[0] = 0; + is_foveon = 0; + } + } + else if (!memcmp (head,"CI",2)) + parse_cine(); + else + for (zero_fsize=i=0; i < sizeof table / sizeof *table; i++) + if (fsize == table[i].fsize) { + strcpy (make, table[i].t_make ); + strcpy (model, table[i].t_model); + if (table[i].withjpeg) + parse_external_jpeg(); + } + if (zero_fsize) fsize = 0; + if (make[0] == 0) parse_smal (0, flen); + if (make[0] == 0) parse_jpeg (is_raw = 0); + + for (i=0; i < sizeof corp / sizeof *corp; i++) + if (strstr (make, corp[i])) /* Simplify company names */ + strcpy (make, corp[i]); + if (!strncmp (make,"KODAK",5) && + ((cp = strstr(model," DIGITAL CAMERA")) || + (cp = strstr(model," Digital Camera")) || + (cp = strstr(model,"FILE VERSION")))) + *cp = 0; + cp = make + strlen(make); /* Remove trailing spaces */ + while (*--cp == ' ') *cp = 0; + cp = model + strlen(model); + while (*--cp == ' ') *cp = 0; + i = strlen(make); /* Remove make from model */ + if (!strncasecmp (model, make, i) && model[i++] == ' ') + memmove (model, model+i, 64-i); + if (!strncmp (model,"FinePix ",8)) + strcpy (model, model+8); + if (!strncmp (model,"Digital Camera ",15)) + strcpy (model, model+15); + desc[511] = artist[63] = make[63] = model[63] = model2[63] = 0; + if (!is_raw) goto notraw; + + if (!height) height = raw_height; + if (!width) width = raw_width; + if (fuji_width) { + fuji_width = (raw_width+1)/2; + width = height + fuji_width; + height = width - 1; + pixel_aspect = 1; + } + if (height == 2624 && width == 3936) /* Pentax K10D and Samsung GX10 */ + { height = 2616; width = 3896; } + if (height == 3136 && width == 4864) /* Pentax K20D and Samsung GX20 */ + { height = 3124; width = 4688; filters = 0x16161616; } + if (width == 4352 && (!strcmp(model,"K-r") || !strcmp(model,"K-x"))) + { width = 4309; filters = 0x16161616; } + if (width >= 4960 && !strcmp(model,"K-5")) + { left_margin = 10; width = 4950; filters = 0x16161616; } + if (width == 4736 && !strcmp(model,"K-7")) + { height = 3122; width = 4684; filters = 0x16161616; top_margin = 2; } + if (width == 7424 && !strcmp(model,"645D")) + { height = 5502; width = 7328; filters = 0x61616161; top_margin = 29; + left_margin = 48; } + if (height == 3014 && width == 4096) /* Ricoh GX200 */ + width = 4014; + if (dng_version) { + if (filters == UINT_MAX) filters = 0; + if (filters) is_raw = tiff_samples; + else colors = tiff_samples; + if (tiff_compress == 1) + load_raw = &CLASS adobe_dng_load_raw_nc; + if (tiff_compress == 7) + load_raw = &CLASS adobe_dng_load_raw_lj; + goto dng_skip; + } + if ((is_canon = !strcmp(make,"Canon"))) + load_raw = memcmp (head+6,"HEAPCCDR",8) ? + &CLASS lossless_jpeg_load_raw : &CLASS canon_compressed_load_raw; + if (!strcmp(make,"NIKON")) { + if (!load_raw) + load_raw = &CLASS packed_load_raw; + if (model[0] == 'E') + load_flags |= !data_offset << 2 | 2; + } + if (!strcmp(make,"CASIO")) { + load_raw = &CLASS packed_load_raw; + maximum = 0xf7f; + } + +/* Set parameters based on camera name (for non-DNG files). */ + if (is_foveon) { + if (height*2 < width) pixel_aspect = 0.5; + if (height > width) pixel_aspect = 2; + filters = 0; + load_raw = &CLASS foveon_load_raw; + simple_coeff(0); + } else if (is_canon && tiff_bps == 15) { + switch (width) { + case 3344: width -= 66; + case 3872: width -= 6; + } + filters = 0; + load_raw = &CLASS canon_sraw_load_raw; + } else if (!strcmp(model,"PowerShot 600")) { + height = 613; + width = 854; + raw_width = 896; + pixel_aspect = 607/628.0; + colors = 4; + filters = 0xe1e4e1e4; + load_raw = &CLASS canon_600_load_raw; + } else if (!strcmp(model,"PowerShot A5") || + !strcmp(model,"PowerShot A5 Zoom")) { + height = 773; + width = 960; + raw_width = 992; + pixel_aspect = 256/235.0; + colors = 4; + filters = 0x1e4e1e4e; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A50")) { + height = 968; + width = 1290; + raw_width = 1320; + colors = 4; + filters = 0x1b4e4b1e; + goto canon_a5; + } else if (!strcmp(model,"PowerShot Pro70")) { + height = 1024; + width = 1552; + colors = 4; + filters = 0x1e4b4e1b; + goto canon_a5; + } else if (!strcmp(model,"PowerShot SD300")) { + height = 1752; + width = 2344; + raw_height = 1766; + raw_width = 2400; + top_margin = 12; + left_margin = 12; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A460")) { + height = 1960; + width = 2616; + raw_height = 1968; + raw_width = 2664; + top_margin = 4; + left_margin = 4; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A530")) { + height = 1984; + width = 2620; + raw_height = 1992; + raw_width = 2672; + top_margin = 6; + left_margin = 10; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A610")) { + if (canon_s2is()) strcpy (model+10, "S2 IS"); + height = 1960; + width = 2616; + raw_height = 1968; + raw_width = 2672; + top_margin = 8; + left_margin = 12; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A620")) { + height = 2328; + width = 3112; + raw_height = 2340; + raw_width = 3152; + top_margin = 12; + left_margin = 36; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A470")) { + height = 2328; + width = 3096; + raw_height = 2346; + raw_width = 3152; + top_margin = 6; + left_margin = 12; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A720 IS")) { + height = 2472; + width = 3298; + raw_height = 2480; + raw_width = 3336; + top_margin = 5; + left_margin = 6; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A630")) { + height = 2472; + width = 3288; + raw_height = 2484; + raw_width = 3344; + top_margin = 6; + left_margin = 12; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A640")) { + height = 2760; + width = 3672; + raw_height = 2772; + raw_width = 3736; + top_margin = 6; + left_margin = 12; + goto canon_a5; + } else if (!strcmp(model,"PowerShot A650")) { + height = 3024; + width = 4032; + raw_height = 3048; + raw_width = 4104; + top_margin = 12; + left_margin = 48; + goto canon_a5; + } else if (!strcmp(model,"PowerShot S3 IS")) { + height = 2128; + width = 2840; + raw_height = 2136; + raw_width = 2888; + top_margin = 8; + left_margin = 44; +canon_a5: + tiff_bps = 10; + load_raw = &CLASS packed_load_raw; + load_flags = 40; + if (raw_width > 1600) zero_is_bad = 1; + } else if (!strcmp(model,"PowerShot SX110 IS")) { + height = 2760; + width = 3684; + raw_height = 2772; + raw_width = 3720; + top_margin = 12; + left_margin = 6; + load_raw = &CLASS packed_load_raw; + load_flags = 40; + zero_is_bad = 1; + } else if (!strcmp(model,"PowerShot SX120 IS")) { + height = 2742; + width = 3664; + raw_height = 2778; + raw_width = 3728; + top_margin = 18; + left_margin = 16; + filters = 0x49494949; + load_raw = &CLASS packed_load_raw; + load_flags = 40; + zero_is_bad = 1; + } else if (!strcmp(model,"PowerShot SX20 IS")) { + height = 3024; + width = 4032; + raw_height = 3048; + raw_width = 4080; + top_margin = 12; + left_margin = 24; + load_raw = &CLASS packed_load_raw; + load_flags = 40; + zero_is_bad = 1; + } else if (!strcmp(model,"PowerShot SX220 HS")) { + height = 3043; + width = 4072; + raw_height = 3060; + raw_width = 4168; +/* + mask[0][0] = top_margin = 16; + mask[0][2] = top_margin + height; + mask[0][3] = left_margin = 92; +*/ + load_raw = &CLASS packed_load_raw; + load_flags = 8; + zero_is_bad = 1; + } else if (!strcmp(model,"PowerShot SX30 IS")) { + height = 3254; + width = 4366; + raw_height = 3276; + raw_width = 4464; + top_margin = 10; + left_margin = 25; + filters = 0x16161616; + load_raw = &CLASS packed_load_raw; + load_flags = 40; + zero_is_bad = 1; + } else if (!strcmp(model,"PowerShot Pro90 IS")) { + width = 1896; + colors = 4; + filters = 0xb4b4b4b4; + } else if (is_canon && raw_width == 2144) { + height = 1550; + width = 2088; + top_margin = 8; + left_margin = 4; + if (!strcmp(model,"PowerShot G1")) { + colors = 4; + filters = 0xb4b4b4b4; + } + } else if (is_canon && raw_width == 2224) { + height = 1448; + width = 2176; + top_margin = 6; + left_margin = 48; + } else if (is_canon && raw_width == 2376) { + height = 1720; + width = 2312; + top_margin = 6; + left_margin = 12; + } else if (is_canon && raw_width == 2672) { + height = 1960; + width = 2616; + top_margin = 6; + left_margin = 12; + } else if (is_canon && raw_width == 3152) { + height = 2056; + width = 3088; + top_margin = 12; + left_margin = 64; + if (unique_id == 0x80000170) + adobe_coeff ("Canon","EOS 300D"); + } else if (is_canon && raw_width == 3160) { + height = 2328; + width = 3112; + top_margin = 12; + left_margin = 44; + } else if (is_canon && raw_width == 3344) { + height = 2472; + width = 3288; + top_margin = 6; + left_margin = 4; + } else if (!strcmp(model,"EOS D2000C")) { + filters = 0x61616161; + black = curve[200]; + } else if (is_canon && raw_width == 3516) { + top_margin = 14; + left_margin = 42; + if (unique_id == 0x80000189) + adobe_coeff ("Canon","EOS 350D"); + goto canon_cr2; + } else if (is_canon && raw_width == 3596) { + top_margin = 12; + left_margin = 74; + goto canon_cr2; + } else if (is_canon && raw_width == 3744) { + height = 2760; + width = 3684; + top_margin = 16; + left_margin = 8; + if (unique_id > 0x2720000) { + top_margin = 12; + left_margin = 52; + } + } else if (is_canon && raw_width == 3944) { + height = 2602; + width = 3908; + top_margin = 18; + left_margin = 30; + } else if (is_canon && raw_width == 3948) { + top_margin = 18; + left_margin = 42; + height -= 2; + if (unique_id == 0x80000236) + adobe_coeff ("Canon","EOS 400D"); + if (unique_id == 0x80000254) + adobe_coeff ("Canon","EOS 1000D"); + goto canon_cr2; + } else if (is_canon && raw_width == 3984) { + top_margin = 20; + left_margin = 76; + height -= 2; + goto canon_cr2; + } else if (is_canon && raw_width == 4104) { + height = 3024; + width = 4032; + top_margin = 12; + left_margin = 48; + } else if (is_canon && raw_width == 4152) { + top_margin = 12; + left_margin = 192; + goto canon_cr2; + } else if (is_canon && raw_width == 4160) { + height = 3048; + width = 4048; + top_margin = 11; + left_margin = 104; + } else if (is_canon && raw_width == 4312) { + top_margin = 18; + left_margin = 22; + height -= 2; + if (unique_id == 0x80000176) + adobe_coeff ("Canon","EOS 450D"); + goto canon_cr2; + } else if (is_canon && raw_width == 4352) { + top_margin = 18; + left_margin = 62; + if (unique_id == 0x80000288) + adobe_coeff ("Canon","EOS 1100D"); + goto canon_cr2; + } else if (is_canon && raw_width == 4476) { + top_margin = 34; + left_margin = 90; + goto canon_cr2; + } else if (is_canon && raw_width == 4480) { + height = 3326; + width = 4432; + top_margin = 10; + left_margin = 12; + filters = 0x49494949; + } else if (is_canon && raw_width == 4496) { + height = 3316; + width = 4404; + top_margin = 50; + left_margin = 80; + } else if (is_canon && raw_width == 4832) { + top_margin = unique_id == 0x80000261 ? 51:26; + left_margin = 62; + if (unique_id == 0x80000252) + adobe_coeff ("Canon","EOS 500D"); + goto canon_cr2; + } else if (is_canon && raw_width == 5108) { + top_margin = 13; + left_margin = 98; + goto canon_cr2; + } else if (is_canon && raw_width == 5120) { + height -= top_margin = 45; + left_margin = 142; + width = 4916; + } else if (is_canon && raw_width == 5344) { + top_margin = 51; + left_margin = 142; + if (unique_id == 0x80000269) { + top_margin = 100; + left_margin = 126; + height -= 2; + adobe_coeff ("Canon","EOS-1D X"); + } + if (unique_id == 0x80000270) + adobe_coeff ("Canon","EOS 550D"); + if (unique_id == 0x80000286) + adobe_coeff ("Canon","EOS 600D"); + goto canon_cr2; + } else if (is_canon && raw_width == 5360) { + top_margin = 51; + left_margin = 158; + goto canon_cr2; + } else if (is_canon && raw_width == 5712) { + height = 3752; + width = 5640; + top_margin = 20; + left_margin = 62; + } else if (is_canon && raw_width == 5792) { + top_margin = 51; + left_margin = 158; +canon_cr2: + height -= top_margin; + width -= left_margin; + } else if (is_canon && raw_width == 5920) { + height = 3870; + width = 5796; + top_margin = 80; + left_margin = 122; + } else if (!strcmp(model,"D1")) { + cam_mul[0] *= 256/527.0; + cam_mul[2] *= 256/317.0; + } else if (!strcmp(model,"D1X")) { + width -= 4; + pixel_aspect = 0.5; + } else if (!strcmp(model,"D40X") || + !strcmp(model,"D60") || + !strcmp(model,"D80") || + !strcmp(model,"D3000")) { + height -= 3; + width -= 4; + } else if (!strcmp(model,"D3") || + !strcmp(model,"D3S") || + !strcmp(model,"D700")) { + width -= 4; + left_margin = 2; + } else if (!strcmp(model,"D3100")) { + width -= 28; + left_margin = 6; + } else if (!strcmp(model,"D5000") || + !strcmp(model,"D90")) { + width -= 42; + } else if (!strcmp(model,"D5100") || + !strcmp(model,"D7000")) { + width -= 44; + } else if (!strcmp(model,"D3200") || + !strcmp(model,"D800")) { + width -= 46; + } else if (!strcmp(model,"D4")) { + width -= 52; + left_margin = 2; + } else if (!strncmp(model,"D40",3) || + !strncmp(model,"D50",3) || + !strncmp(model,"D70",3)) { + width--; + } else if (!strcmp(model,"D100")) { + if (tiff_compress == 34713 && !nikon_is_compressed()) { + load_raw = &CLASS packed_load_raw; + load_flags |= 1; + raw_width = (width += 3) + 3; + } + } else if (!strcmp(model,"D200")) { + left_margin = 1; + width -= 4; + filters = 0x94949494; + } else if (!strncmp(model,"D2H",3)) { + left_margin = 6; + width -= 14; + } else if (!strncmp(model,"D2X",3)) { + if (width == 3264) width -= 32; + else width -= 8; + } else if (!strncmp(model,"D300",4)) { + width -= 32; + } else if (!strncmp(model,"COOLPIX P",9)) { + load_flags = 24; + filters = 0x94949494; + if (model[9] == '7' && iso_speed >= 400) + black = 255; + } else if (!strncmp(model,"1 ",2)) { + height -= 2; + } else if (fsize == 1581060) { + height = 963; + width = 1287; + raw_width = 1632; + maximum = 0x3f4; + colors = 4; + filters = 0x1e1e1e1e; + simple_coeff(3); + pre_mul[0] = 1.2085; + pre_mul[1] = 1.0943; + pre_mul[3] = 1.1103; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.pre_mul_state = LIBRAW_COLORSTATE_CONST; +#endif + goto e900; + } else if (fsize == 2465792) { + height = 1203; + width = 1616; + raw_width = 2048; + colors = 4; + filters = 0x4b4b4b4b; + adobe_coeff ("NIKON","E950"); +e900: + tiff_bps = 10; + load_raw = &CLASS packed_load_raw; + load_flags = 6; + } else if (fsize == 4771840) { + height = 1540; + width = 2064; + colors = 4; + filters = 0xe1e1e1e1; + load_raw = &CLASS packed_load_raw; + load_flags = 6; + if (!timestamp && nikon_e995()) + strcpy (model, "E995"); + if (strcmp(model,"E995")) { + filters = 0xb4b4b4b4; + simple_coeff(3); + pre_mul[0] = 1.196; + pre_mul[1] = 1.246; + pre_mul[2] = 1.018; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.pre_mul_state = LIBRAW_COLORSTATE_CONST; +#endif + } + } else if (!strcmp(model,"E2100")) { + if (!timestamp && !nikon_e2100()) goto cp_e2500; + height = 1206; + width = 1616; + load_flags = 30; + } else if (!strcmp(model,"E2500")) { +cp_e2500: + strcpy (model, "E2500"); + height = 1204; + width = 1616; + colors = 4; + filters = 0x4b4b4b4b; + } else if (fsize == 4775936) { + height = 1542; + width = 2064; + load_raw = &CLASS packed_load_raw; + load_flags = 30; + if (!timestamp) nikon_3700(); + if (model[0] == 'E' && atoi(model+1) < 3700) + filters = 0x49494949; + if (!strcmp(model,"Optio 33WR")) { + flip = 1; + filters = 0x16161616; + } + if (make[0] == 'O') { + i = find_green (12, 32, 1188864, 3576832); + c = find_green (12, 32, 2383920, 2387016); + if (abs(i) < abs(c)) { + SWAP(i,c); + load_flags = 24; + } + if (i < 0) filters = 0x61616161; + } + } else if (fsize == 5869568) { + height = 1710; + width = 2288; + filters = 0x16161616; + if (!timestamp && minolta_z2()) { + strcpy (make, "Minolta"); + strcpy (model,"DiMAGE Z2"); + } + load_raw = &CLASS packed_load_raw; + load_flags = 6 + 24*(make[0] == 'M'); + } else if (!strcmp(model,"E4500")) { + height = 1708; + width = 2288; + colors = 4; + filters = 0xb4b4b4b4; + } else if (fsize == 7438336) { + height = 1924; + width = 2576; + colors = 4; + filters = 0xb4b4b4b4; + } else if (fsize == 8998912) { + height = 2118; + width = 2832; + maximum = 0xf83; + load_raw = &CLASS packed_load_raw; + load_flags = 30; + } else if (!strcmp(make,"FUJIFILM")) { + if (!strcmp(model+7,"S2Pro")) { + strcpy (model,"S2Pro"); + height = 2144; + width = 2880; + flip = 6; + } else if (load_raw != &CLASS packed_load_raw) + maximum = (is_raw == 2 && shot_select) ? 0x2f00 : 0x3e00; + top_margin = (raw_height - height) >> 2 << 1; + left_margin = (raw_width - width ) >> 2 << 1; + if (width == 3328) { + width = 3262; + left_margin = 34; + } + if (!strcmp(model,"X10") || !strcmp(model,"X-S1")) + filters = 0x16161616; + if (fuji_layout) raw_width *= is_raw; + if (load_raw == &CLASS fuji_load_raw) { + fuji_width = width >> !fuji_layout; + width = (height >> fuji_layout) + fuji_width; + raw_height = height; + height = width - 1; + if (~fuji_width & 1) filters = 0x49494949; + } + if (!strcmp(model,"X-Pro1")) { + left_margin = 0; + filters = 2; + is_raw = 0; /* Not supported! */ + } + } else if (!strcmp(model,"RD175")) { + height = 986; + width = 1534; + data_offset = 513; + filters = 0x61616161; + load_raw = &CLASS minolta_rd175_load_raw; + } else if (!strcmp(model,"KD-400Z")) { + height = 1712; + width = 2312; + raw_width = 2336; + goto konica_400z; + } else if (!strcmp(model,"KD-510Z")) { + goto konica_510z; + } else if (!strcasecmp(make,"MINOLTA")) { + load_raw = &CLASS unpacked_load_raw; + maximum = 0xfff; + if (!strncmp(model,"DiMAGE A",8)) { + if (!strcmp(model,"DiMAGE A200")) + filters = 0x49494949; + tiff_bps = 12; + load_raw = &CLASS packed_load_raw; + } else if (!strncmp(model,"ALPHA",5) || + !strncmp(model,"DYNAX",5) || + !strncmp(model,"MAXXUM",6)) { + sprintf (model+20, "DYNAX %-10s", model+6+(model[0]=='M')); + adobe_coeff (make, model+20); + load_raw = &CLASS packed_load_raw; + } else if (!strncmp(model,"DiMAGE G",8)) { + if (model[8] == '4') { + height = 1716; + width = 2304; + } else if (model[8] == '5') { +konica_510z: + height = 1956; + width = 2607; + raw_width = 2624; + } else if (model[8] == '6') { + height = 2136; + width = 2848; + } + data_offset += 14; + filters = 0x61616161; +konica_400z: + load_raw = &CLASS unpacked_load_raw; + maximum = 0x3df; + order = 0x4d4d; + } + } else if (!strcmp(model,"*ist D")) { + load_raw = &CLASS unpacked_load_raw; + data_error = -1; + } else if (!strcmp(model,"*ist DS")) { + height -= 2; + } else if (!strcmp(model,"Optio S")) { + if (fsize == 3178560) { + height = 1540; + width = 2064; + load_raw = &CLASS eight_bit_load_raw; + cam_mul[0] *= 4; + cam_mul[2] *= 4; + } else { + height = 1544; + width = 2068; + raw_width = 3136; + load_raw = &CLASS packed_load_raw; + maximum = 0xf7c; + } + } else if (fsize == 6114240) { + height = 1737; + width = 2324; + raw_width = 3520; + load_raw = &CLASS packed_load_raw; + maximum = 0xf7a; + } else if (!strcmp(model,"Optio 750Z")) { + height = 2302; + width = 3072; + load_raw = &CLASS packed_load_raw; + load_flags = 30; + } else if (!strcmp(model,"DC-833m")) { + height = 2448; + width = 3264; + order = 0x4949; + filters = 0x61616161; + load_raw = &CLASS unpacked_load_raw; + maximum = 0xfc00; + } else if (!strncmp(model,"S85",3)) { + height = 2448; + width = 3264; + raw_width = fsize/height/2; + order = 0x4d4d; + load_raw = &CLASS unpacked_load_raw; + } else if (!strncmp(model,"NX1",3)) { + height -= top_margin = 8; + width -= 2 * (left_margin = 8); + load_flags = 32; + } else if (!strcmp(model,"NX200")) { + order = 0x4949; + height = 3694; + top_margin = 2; + width = 5574 - (left_margin = 32 + tiff_bps); + if (tiff_bps == 12) load_flags = 80; + } else if (!strcmp(model,"EX1")) { + order = 0x4949; + height -= 20; + top_margin = 2; + if ((width -= 6) > 3682) { + height -= 10; + width -= 46; + top_margin = 8; + } + } else if (!strcmp(model,"WB2000")) { + order = 0x4949; + height -= 3; + top_margin = 2; + if ((width -= 10) > 3718) { + height -= 28; + width -= 56; + top_margin = 8; + } + } else if (fsize == 20487168) { + height = 2808; + width = 3648; + goto wb550; + } else if (fsize == 24000000) { + height = 3000; + width = 4000; +wb550: + strcpy (model, "WB550"); + order = 0x4d4d; + load_raw = &CLASS unpacked_load_raw; + load_flags = 6; + maximum = 0x3df; + } else if (!strcmp(model,"STV680 VGA")) { + height = 484; + width = 644; + load_raw = &CLASS eight_bit_load_raw; + flip = 2; + filters = 0x16161616; + black = 16; + } else if (!strcmp(model,"N95")) { + height = raw_height - (top_margin = 2); + } else if (!strcmp(model,"531C")) { + height = 1200; + width = 1600; + load_raw = &CLASS unpacked_load_raw; + filters = 0x49494949; + } else if (!strcmp(model,"640x480")) { + height = 480; + width = 640; + load_raw = &CLASS eight_bit_load_raw; + gamma_curve (0.45, 4.5, 1, 255); + } else if (!strcmp(model,"F-080C")) { + height = 768; + width = 1024; + load_raw = &CLASS eight_bit_load_raw; + } else if (!strcmp(model,"F-145C")) { + height = 1040; + width = 1392; + load_raw = &CLASS eight_bit_load_raw; + } else if (!strcmp(model,"F-201C")) { + height = 1200; + width = 1600; + load_raw = &CLASS eight_bit_load_raw; + } else if (!strcmp(model,"F-510C")) { + height = 1958; + width = 2588; + load_raw = fsize < 7500000 ? + &CLASS eight_bit_load_raw : &CLASS unpacked_load_raw; + data_offset = fsize - width*height*(fsize >> 22); + maximum = 0xfff0; + } else if (!strcmp(model,"F-810C")) { + height = 2469; + width = 3272; + load_raw = &CLASS unpacked_load_raw; + maximum = 0xfff0; + } else if (!strcmp(model,"XCD-SX910CR")) { + height = 1024; + width = 1375; + raw_width = 1376; + filters = 0x49494949; + maximum = 0x3ff; + load_raw = fsize < 2000000 ? + &CLASS eight_bit_load_raw : &CLASS unpacked_load_raw; + } else if (!strcmp(model,"2010")) { + height = 1207; + width = 1608; + order = 0x4949; + filters = 0x16161616; + data_offset = 3212; + maximum = 0x3ff; + load_raw = &CLASS unpacked_load_raw; + } else if (!strcmp(model,"A782")) { + height = 3000; + width = 2208; + filters = 0x61616161; + load_raw = fsize < 10000000 ? + &CLASS eight_bit_load_raw : &CLASS unpacked_load_raw; + maximum = 0xffc0; + } else if (!strcmp(model,"3320AF")) { + height = 1536; + raw_width = width = 2048; + filters = 0x61616161; + load_raw = &CLASS unpacked_load_raw; + maximum = 0x3ff; + fseek (ifp, 0x300000, SEEK_SET); + if ((order = guess_byte_order(0x10000)) == 0x4d4d) { + height -= (top_margin = 16); + width -= (left_margin = 28); + maximum = 0xf5c0; + strcpy (make, "ISG"); + model[0] = 0; + } + } else if (!strcmp(make,"Hasselblad")) { + if (load_raw == &CLASS lossless_jpeg_load_raw) + load_raw = &CLASS hasselblad_load_raw; + if (raw_width == 7262) { + height = 5444; + width = 7248; + top_margin = 4; + left_margin = 7; + filters = 0x61616161; + } else if (raw_width == 7410) { + height = 5502; + width = 7328; + top_margin = 4; + left_margin = 41; + filters = 0x61616161; + } else if (raw_width == 9044) { + height = 6716; + width = 8964; + top_margin = 8; + left_margin = 40; + black += load_flags = 256; + maximum = 0x8101; + } else if (raw_width == 4090) { + strcpy (model, "V96C"); + height -= (top_margin = 6); + width -= (left_margin = 3) + 7; + filters = 0x61616161; + } + } else if (!strcmp(make,"Sinar")) { + if (!memcmp(head,"8BPS",4)) { + fseek (ifp, 14, SEEK_SET); + height = get4(); + width = get4(); + filters = 0x61616161; + data_offset = 68; + } + if (!load_raw) load_raw = &CLASS unpacked_load_raw; + maximum = 0x3fff; + } else if (!strcmp(make,"Leaf")) { + maximum = 0x3fff; + fseek (ifp, data_offset, SEEK_SET); + if (ljpeg_start (&jh, 1) && jh.bits == 15) + maximum = 0x1fff; + if (tiff_samples > 1) filters = 0; + if (tiff_samples > 1 || tile_length < raw_height) { + load_raw = &CLASS leaf_hdr_load_raw; + raw_width = tile_width; + } + if ((width | height) == 2048) { + if (tiff_samples == 1) { + filters = 1; + strcpy (cdesc, "RBTG"); + strcpy (model, "CatchLight"); + top_margin = 8; left_margin = 18; height = 2032; width = 2016; + } else { + strcpy (model, "DCB2"); + top_margin = 10; left_margin = 16; height = 2028; width = 2022; + } + } else if (width+height == 3144+2060) { + if (!model[0]) strcpy (model, "Cantare"); + if (width > height) { + top_margin = 6; left_margin = 32; height = 2048; width = 3072; + filters = 0x61616161; + } else { + left_margin = 6; top_margin = 32; width = 2048; height = 3072; + filters = 0x16161616; + } + if (!cam_mul[0] || model[0] == 'V') filters = 0; + else is_raw = tiff_samples; + } else if (width == 2116) { + strcpy (model, "Valeo 6"); + height -= 2 * (top_margin = 30); + width -= 2 * (left_margin = 55); + filters = 0x49494949; + } else if (width == 3171) { + strcpy (model, "Valeo 6"); + height -= 2 * (top_margin = 24); + width -= 2 * (left_margin = 24); + filters = 0x16161616; + } + } else if (!strcmp(make,"LEICA") || !strcmp(make,"Panasonic")) { + if(raw_width < 1) { is_raw = 0; goto notraw; } + if ((flen - data_offset) / (raw_width*8/7) == raw_height) + load_raw = &CLASS panasonic_load_raw; + if (!load_raw) { + load_raw = &CLASS unpacked_load_raw; + load_flags = 4; + } + zero_is_bad = 1; + if ((height += 12) > raw_height) height = raw_height; + for (i=0; i < sizeof pana / sizeof *pana; i++) + if (raw_width == pana[i][0] && raw_height == pana[i][1]) { + left_margin = pana[i][2]; + top_margin = pana[i][3]; + width += pana[i][4]; + height += pana[i][5]; + } + filters = 0x01010101 * (uchar) "\x94\x61\x49\x16" + [((filters-1) ^ (left_margin & 1) ^ (top_margin << 1)) & 3]; + } else if (!strcmp(model,"C770UZ")) { + height = 1718; + width = 2304; + filters = 0x16161616; + load_raw = &CLASS packed_load_raw; + load_flags = 30; + } else if (!strcmp(make,"OLYMPUS")) { + height += height & 1; + filters = exif_cfa; + if (width == 4100) width -= 4; + if (width == 4080) width -= 24; + if (load_raw == &CLASS unpacked_load_raw) + load_flags = 4; + tiff_bps = 12; + if (!strcmp(model,"E-300") || + !strcmp(model,"E-500")) { + width -= 20; + if (load_raw == &CLASS unpacked_load_raw) { + maximum = 0xfc3; + memset (cblack, 0, sizeof cblack); + } + } else if (!strcmp(model,"E-330")) { + width -= 30; + if (load_raw == &CLASS unpacked_load_raw) + maximum = 0xf79; + } else if (!strcmp(model,"SP550UZ")) { + thumb_length = flen - (thumb_offset = 0xa39800); + thumb_height = 480; + thumb_width = 640; + } + } + else + identify2(fsize,flen,head); /* Avoid MS VS 2008 bug */ + + + if (!model[0]) + sprintf (model, "%dx%d", width, height); + if (filters == UINT_MAX) filters = 0x94949494; + if (raw_color) adobe_coeff (make, model); + if (load_raw == &CLASS kodak_radc_load_raw) + if (raw_color) adobe_coeff ("Apple","Quicktake"); + if (thumb_offset && !thumb_height) { + fseek (ifp, thumb_offset, SEEK_SET); + if (ljpeg_start (&jh, 1)) { + thumb_width = jh.wide; + thumb_height = jh.high; + } + } +dng_skip: + if (fuji_width) { +/* + fuji_width = width >> !fuji_layout; + if (~fuji_width & 1) filters = 0x49494949; + width = (height >> fuji_layout) + fuji_width; + height = width - 1; + pixel_aspect = 1; +*/ + } else { + if (raw_height < height) raw_height = height; + if (raw_width < width ) raw_width = width; + } + if (!tiff_bps) tiff_bps = 12; + if (!maximum) maximum = (1 << tiff_bps) - 1; + if (!load_raw || height < 22) is_raw = 0; +#ifdef NO_JASPER + if (load_raw == &CLASS redcine_load_raw) { +#ifdef DCRAW_VERBOSE + fprintf (stderr,_("%s: You must link dcraw with %s!!\n"), + ifname, "libjasper"); +#endif + is_raw = 0; +#ifdef LIBRAW_LIBRARY_BUILD + imgdata.process_warnings |= LIBRAW_WARN_NO_JASPER; +#endif + } +#endif +#ifdef NO_JPEG + if (load_raw == &CLASS kodak_jpeg_load_raw) { +#ifdef DCRAW_VERBOSE + fprintf (stderr,_("%s: You must link dcraw with %s!!\n"), + ifname, "libjpeg"); +#endif + is_raw = 0; +#ifdef LIBRAW_LIBRARY_BUILD + imgdata.process_warnings |= LIBRAW_WARN_NO_JPEGLIB; +#endif + } +#endif + if (!cdesc[0]) + strcpy (cdesc, colors == 3 ? "RGBG":"GMCY"); + if (!raw_height) raw_height = height; + if (!raw_width ) raw_width = width; + if (filters && colors == 3) + filters |= ((filters >> 2 & 0x22222222) | + (filters << 2 & 0x88888888)) & filters << 1; +notraw: + if (flip == -1) flip = tiff_flip; + if (flip == -1) flip = 0; + +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_IDENTIFY,1,2); +#endif +} + +void CLASS identify2(unsigned fsize, unsigned flen, char *head) +{ + if (!strcmp(model,"N Digital")) { + height = 2047; + width = 3072; + filters = 0x61616161; + data_offset = 0x1a00; + load_raw = &CLASS packed_load_raw; + } else if (!strcmp(model,"DSC-F828")) { + width = 3288; + left_margin = 5; + data_offset = 862144; + load_raw = &CLASS sony_load_raw; + filters = 0x9c9c9c9c; + colors = 4; + strcpy (cdesc, "RGBE"); + } else if (!strcmp(model,"DSC-V3")) { + width = 3109; + left_margin = 59; + data_offset = 787392; + load_raw = &CLASS sony_load_raw; + } else if (!strcmp(make,"SONY") && raw_width == 3984) { + adobe_coeff ("SONY","DSC-R1"); + width = 3925; + order = 0x4d4d; + } else if (!strcmp(make,"SONY") && raw_width == 6048) { + width -= 24; + } else if (!strcmp(model,"DSLR-A100")) { + if (width == 3880) { + height--; + width = ++raw_width; + } else { + order = 0x4d4d; + load_flags = 2; + } + filters = 0x61616161; + } else if (!strcmp(model,"DSLR-A350")) { + height -= 4; + } + else if (!strcmp(model,"PIXL")) { + height -= top_margin = 4; + width -= left_margin = 32; + gamma_curve (0, 7, 1, 255); + } else if (!strcmp(model,"C603v")) { + height = 480; + width = 640; + if (fsize < 614400 || find_green (16, 16, 3840, 5120) < 25) goto c603v; + strcpy (model,"KAI-0340"); + height -= 3; + data_offset = 3840; + order = 0x4949; + load_raw = &CLASS unpacked_load_raw; + } else if (!strcmp(model,"C603y")) { + height = 2134; + width = 2848; +c603v: + filters = 0; + load_raw = &CLASS kodak_yrgb_load_raw; + gamma_curve (0, 3.875, 1, 255); + } else if (!strcmp(model,"C603")) { + raw_height = height = 2152; + raw_width = width = 2864; + goto c603; + } else if (!strcmp(model,"C330")) { + height = 1744; + width = 2336; + raw_height = 1779; + raw_width = 2338; + top_margin = 33; + left_margin = 1; +c603: + order = 0x4949; + if ((data_offset = fsize - raw_height*raw_width)) { + fseek (ifp, 168, SEEK_SET); + read_shorts (curve, 256); +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.curve_state = LIBRAW_COLORSTATE_LOADED; +#endif + } else gamma_curve (0, 3.875, 1, 255); + load_raw = &CLASS eight_bit_load_raw; + } + else if (!strncasecmp(model,"EasyShare",9)) { + data_offset = data_offset < 0x15000 ? 0x15000 : 0x17000; + load_raw = &CLASS packed_load_raw; + } else if (!strcasecmp(make,"KODAK")) { + if (filters == UINT_MAX) filters = 0x61616161; + if (!strncmp(model,"NC2000",6)) { + width -= 4; + left_margin = 2; + } else if (!strcmp(model,"EOSDCS3B")) { + width -= 4; + left_margin = 2; + } else if (!strcmp(model,"EOSDCS1")) { + width -= 4; + left_margin = 2; + } else if (!strcmp(model,"DCS420")) { + width -= 4; + left_margin = 2; + } else if (!strncmp(model,"DCS460 ",7)) { + model[6] = 0; + width -= 4; + left_margin = 2; + } else if (!strcmp(model,"DCS460A")) { + width -= 4; + left_margin = 2; + colors = 1; + filters = 0; + } else if (!strcmp(model,"DCS660M")) { + black = 214; + colors = 1; + filters = 0; + } else if (!strcmp(model,"DCS760M")) { + colors = 1; + filters = 0; + } + if (!strcmp(model+4,"20X")) + strcpy (cdesc, "MYCY"); + if (strstr(model,"DC25")) { + strcpy (model, "DC25"); + data_offset = 15424; + } + if (!strncmp(model,"DC2",3)) { + raw_height = height = 242; + if (flen < 100000) { + raw_width = 256; width = 249; + pixel_aspect = (4.0*height) / (3.0*width); + } else { + raw_width = 512; width = 501; + pixel_aspect = (493.0*height) / (373.0*width); + } + data_offset += raw_width + 1; + colors = 4; + filters = 0x8d8d8d8d; + simple_coeff(1); + pre_mul[1] = 1.179; + pre_mul[2] = 1.209; + pre_mul[3] = 1.036; +#ifdef LIBRAW_LIBRARY_BUILD + color_flags.pre_mul_state = LIBRAW_COLORSTATE_CONST; +#endif + load_raw = &CLASS eight_bit_load_raw; + } else if (!strcmp(model,"40")) { + strcpy (model, "DC40"); + height = 512; + width = 768; + data_offset = 1152; + load_raw = &CLASS kodak_radc_load_raw; + } else if (strstr(model,"DC50")) { + strcpy (model, "DC50"); + height = 512; + width = 768; + data_offset = 19712; + load_raw = &CLASS kodak_radc_load_raw; + } else if (strstr(model,"DC120")) { + strcpy (model, "DC120"); + height = 976; + width = 848; + pixel_aspect = height/0.75/width; + load_raw = tiff_compress == 7 ? + &CLASS kodak_jpeg_load_raw : &CLASS kodak_dc120_load_raw; + } else if (!strcmp(model,"DCS200")) { + thumb_height = 128; + thumb_width = 192; + thumb_offset = 6144; + thumb_misc = 360; + write_thumb = &CLASS layer_thumb; + height = 1024; + width = 1536; + data_offset = 79872; + load_raw = &CLASS eight_bit_load_raw; + black = 17; + } +} else if (!strcmp(model,"Fotoman Pixtura")) { + height = 512; + width = 768; + data_offset = 3632; + load_raw = &CLASS kodak_radc_load_raw; + filters = 0x61616161; + simple_coeff(2); + } else if (!strncmp(model,"QuickTake",9)) { + if (head[5]) strcpy (model+10, "200"); + fseek (ifp, 544, SEEK_SET); + height = get2(); + width = get2(); + data_offset = (get4(),get2()) == 30 ? 738:736; + if (height > width) { + SWAP(height,width); + fseek (ifp, data_offset-6, SEEK_SET); + flip = ~get2() & 3 ? 5:6; + } + filters = 0x61616161; + } else if (!strcmp(make,"Rollei") && !load_raw) { + switch (raw_width) { + case 1316: + height = 1030; + width = 1300; + top_margin = 1; + left_margin = 6; + break; + case 2568: + height = 1960; + width = 2560; + top_margin = 2; + left_margin = 8; + } + filters = 0x16161616; + load_raw = &CLASS rollei_load_raw; + } else if (!strcmp(model,"PC-CAM 600")) { + height = 768; + data_offset = width = 1024; + filters = 0x49494949; + load_raw = &CLASS eight_bit_load_raw; + } +else if (!strcmp(model,"QV-2000UX")) { + height = 1208; + width = 1632; + data_offset = width * 2; + load_raw = &CLASS eight_bit_load_raw; + } else if (fsize == 3217760) { + height = 1546; + width = 2070; + raw_width = 2080; + load_raw = &CLASS eight_bit_load_raw; + } else if (!strcmp(model,"QV-4000")) { + height = 1700; + width = 2260; + load_raw = &CLASS unpacked_load_raw; + maximum = 0xffff; + } else if (!strcmp(model,"QV-5700")) { + height = 1924; + width = 2576; + raw_width = 3232; + tiff_bps = 10; + } else if (!strcmp(model,"QV-R41")) { + height = 1720; + width = 2312; + raw_width = 3520; + left_margin = 2; + } else if (!strcmp(model,"QV-R51")) { + height = 1926; + width = 2580; + raw_width = 3904; + } else if (!strcmp(model,"EX-S20")) { + height = 1208; + width = 1620; + raw_width = 2432; + flip = 3; + } else if (!strcmp(model,"EX-S100")) { + height = 1544; + width = 2058; + raw_width = 3136; + } else if (!strcmp(model,"EX-Z50")) { + height = 1931; + width = 2570; + raw_width = 3904; + } else if (!strcmp(model,"EX-Z500")) { + height = 1937; + width = 2577; + raw_width = 3904; + filters = 0x16161616; + } else if (!strcmp(model,"EX-Z55")) { + height = 1960; + width = 2570; + raw_width = 3904; + } else if (!strcmp(model,"EX-Z60")) { + height = 2145; + width = 2833; + raw_width = 3584; + filters = 0x16161616; + tiff_bps = 10; + } else if (!strcmp(model,"EX-Z75")) { + height = 2321; + width = 3089; + raw_width = 4672; + } else if (!strcmp(model,"EX-Z750")) { + height = 2319; + width = 3087; + raw_width = 4672; + maximum = 0xfff; + } else if (!strcmp(model,"EX-Z850")) { + height = 2468; + width = 3279; + raw_width = 4928; + maximum = 0xfff; + } else if (!strcmp(model,"EX-Z8")) { + height = 2467; + width = 3281; + raw_height = 2502; + raw_width = 4992; + maximum = 0xfff; + } else if (fsize == 15499264) { /* EX-Z1050 or EX-Z1080 */ + height = 2752; + width = 3672; + raw_width = 5632; + } else if (!strcmp(model,"EX-P505")) { + height = 1928; + width = 2568; + raw_width = 3852; + maximum = 0xfff; + } else if (fsize == 9313536) { /* EX-P600 or QV-R61 */ + height = 2142; + width = 2844; + raw_width = 4288; + } else if (!strcmp(model,"EX-P700")) { + height = 2318; + width = 3082; + raw_width = 4672; + } + else if (!strcmp(model,"GRAS-50S5C")) { + height = 2048; + width = 2440; + load_raw = &CLASS unpacked_load_raw; + data_offset = 0; + filters = 0x49494949; + order = 0x4949; + maximum = 0xfffC; + } else if (!strcmp(model,"BB-500CL")) { + height = 2058; + width = 2448; + load_raw = &CLASS unpacked_load_raw; + data_offset = 0; + filters = 0x94949494; + order = 0x4949; + maximum = 0x3fff; + } else if (!strcmp(model,"BB-500GE")) { + height = 2058; + width = 2456; + load_raw = &CLASS unpacked_load_raw; + data_offset = 0; + filters = 0x94949494; + order = 0x4949; + maximum = 0x3fff; + } else if (!strcmp(model,"SVS625CL")) { + height = 2050; + width = 2448; + load_raw = &CLASS unpacked_load_raw; + data_offset = 0; + filters = 0x94949494; + order = 0x4949; + maximum = 0x0fff; + } +} + +void CLASS convert_to_rgb() +{ + int row, col, c, i, j, k; + ushort *img; + float out[3], out_cam[3][4]; + double num, inverse[3][3]; + static const double xyzd50_srgb[3][3] = + { { 0.436083, 0.385083, 0.143055 }, + { 0.222507, 0.716888, 0.060608 }, + { 0.013930, 0.097097, 0.714022 } }; + static const double rgb_rgb[3][3] = + { { 1,0,0 }, { 0,1,0 }, { 0,0,1 } }; + static const double adobe_rgb[3][3] = + { { 0.715146, 0.284856, 0.000000 }, + { 0.000000, 1.000000, 0.000000 }, + { 0.000000, 0.041166, 0.958839 } }; + static const double wide_rgb[3][3] = + { { 0.593087, 0.404710, 0.002206 }, + { 0.095413, 0.843149, 0.061439 }, + { 0.011621, 0.069091, 0.919288 } }; + static const double prophoto_rgb[3][3] = + { { 0.529317, 0.330092, 0.140588 }, + { 0.098368, 0.873465, 0.028169 }, + { 0.016879, 0.117663, 0.865457 } }; + static const double (*out_rgb[])[3] = + { rgb_rgb, adobe_rgb, wide_rgb, prophoto_rgb, xyz_rgb }; + static const char *name[] = + { "sRGB", "Adobe RGB (1998)", "WideGamut D65", "ProPhoto D65", "XYZ" }; + static const unsigned phead[] = + { 1024, 0, 0x2100000, 0x6d6e7472, 0x52474220, 0x58595a20, 0, 0, 0, + 0x61637370, 0, 0, 0x6e6f6e65, 0, 0, 0, 0, 0xf6d6, 0x10000, 0xd32d }; + unsigned pbody[] = + { 10, 0x63707274, 0, 36, /* cprt */ + 0x64657363, 0, 40, /* desc */ + 0x77747074, 0, 20, /* wtpt */ + 0x626b7074, 0, 20, /* bkpt */ + 0x72545243, 0, 14, /* rTRC */ + 0x67545243, 0, 14, /* gTRC */ + 0x62545243, 0, 14, /* bTRC */ + 0x7258595a, 0, 20, /* rXYZ */ + 0x6758595a, 0, 20, /* gXYZ */ + 0x6258595a, 0, 20 }; /* bXYZ */ + static const unsigned pwhite[] = { 0xf351, 0x10000, 0x116cc }; + unsigned pcurve[] = { 0x63757276, 0, 1, 0x1000000 }; + +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_CONVERT_RGB,0,2); +#endif + gamma_curve (gamm[0], gamm[1], 0, 0); + memcpy (out_cam, rgb_cam, sizeof out_cam); + raw_color |= colors == 1 || document_mode || + output_color < 1 || output_color > 5; + if (!raw_color) { + oprof = (unsigned *) calloc (phead[0], 1); + merror (oprof, "convert_to_rgb()"); + memcpy (oprof, phead, sizeof phead); + if (output_color == 5) oprof[4] = oprof[5]; + oprof[0] = 132 + 12*pbody[0]; + for (i=0; i < pbody[0]; i++) { + oprof[oprof[0]/4] = i ? (i > 1 ? 0x58595a20 : 0x64657363) : 0x74657874; + pbody[i*3+2] = oprof[0]; + oprof[0] += (pbody[i*3+3] + 3) & -4; + } + memcpy (oprof+32, pbody, sizeof pbody); + oprof[pbody[5]/4+2] = strlen(name[output_color-1]) + 1; + memcpy ((char *)oprof+pbody[8]+8, pwhite, sizeof pwhite); + pcurve[3] = (short)(256/gamm[5]+0.5) << 16; + for (i=4; i < 7; i++) + memcpy ((char *)oprof+pbody[i*3+2], pcurve, sizeof pcurve); + pseudoinverse ((double (*)[3]) out_rgb[output_color-1], inverse, 3); + for (i=0; i < 3; i++) + for (j=0; j < 3; j++) { + for (num = k=0; k < 3; k++) + num += xyzd50_srgb[i][k] * inverse[j][k]; + oprof[pbody[j*3+23]/4+i+2] = num * 0x10000 + 0.5; + } + for (i=0; i < phead[0]/4; i++) + oprof[i] = htonl(oprof[i]); + strcpy ((char *)oprof+pbody[2]+8, "auto-generated by dcraw"); + strcpy ((char *)oprof+pbody[5]+12, name[output_color-1]); + for (i=0; i < 3; i++) + for (j=0; j < colors; j++) + for (out_cam[i][j] = k=0; k < 3; k++) + out_cam[i][j] += out_rgb[output_color-1][i][k] * rgb_cam[k][j]; + } +#ifdef DCRAW_VERBOSE + if (verbose) + fprintf (stderr, raw_color ? _("Building histograms...\n") : + _("Converting to %s colorspace...\n"), name[output_color-1]); + +#endif +#ifdef LIBRAW_LIBRARY_BUILD + memset(histogram,0,sizeof(int)*LIBRAW_HISTOGRAM_SIZE*4); +#else + memset (histogram, 0, sizeof histogram); +#endif + for (img=image[0], row=0; row < height; row++) + for (col=0; col < width; col++, img+=4) { + if (!raw_color) { + out[0] = out[1] = out[2] = 0; + FORCC { + out[0] += out_cam[0][c] * img[c]; + out[1] += out_cam[1][c] * img[c]; + out[2] += out_cam[2][c] * img[c]; + } + FORC3 img[c] = CLIP((int) out[c]); + } + else if (document_mode) + img[0] = img[FC(row,col)]; + FORCC histogram[c][img[c] >> 3]++; + } + if (colors == 4 && output_color) colors = 3; + if (document_mode && filters) colors = 1; +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_CONVERT_RGB,1,2); +#endif +} + +void CLASS fuji_rotate() +{ + int i, row, col; + double step; + float r, c, fr, fc; + unsigned ur, uc; + ushort wide, high, (*img)[4], (*pix)[4]; + + if (!fuji_width) return; +#ifdef DCRAW_VERBOSE + if (verbose) + fprintf (stderr,_("Rotating image 45 degrees...\n")); +#endif + fuji_width = (fuji_width - 1 + shrink) >> shrink; + step = sqrt(0.5); + wide = fuji_width / step; + high = (height - fuji_width) / step; + img = (ushort (*)[4]) calloc (wide*high, sizeof *img); + merror (img, "fuji_rotate()"); + +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_FUJI_ROTATE,0,2); +#endif + + for (row=0; row < high; row++) + for (col=0; col < wide; col++) { + ur = r = fuji_width + (row-col)*step; + uc = c = (row+col)*step; + if (ur > height-2 || uc > width-2) continue; + fr = r - ur; + fc = c - uc; + pix = image + ur*width + uc; + for (i=0; i < colors; i++) + img[row*wide+col][i] = + (pix[ 0][i]*(1-fc) + pix[ 1][i]*fc) * (1-fr) + + (pix[width][i]*(1-fc) + pix[width+1][i]*fc) * fr; + } + free (image); + width = wide; + height = high; + image = img; + fuji_width = 0; +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_FUJI_ROTATE,1,2); +#endif +} + +void CLASS stretch() +{ + ushort newdim, (*img)[4], *pix0, *pix1; + int row, col, c; + double rc, frac; + + if (pixel_aspect == 1) return; +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_STRETCH,0,2); +#endif +#ifdef DCRAW_VERBOSE + if (verbose) fprintf (stderr,_("Stretching the image...\n")); +#endif + if (pixel_aspect < 1) { + newdim = height / pixel_aspect + 0.5; + img = (ushort (*)[4]) calloc (width*newdim, sizeof *img); + merror (img, "stretch()"); + for (rc=row=0; row < newdim; row++, rc+=pixel_aspect) { + frac = rc - (c = rc); + pix0 = pix1 = image[c*width]; + if (c+1 < height) pix1 += width*4; + for (col=0; col < width; col++, pix0+=4, pix1+=4) + FORCC img[row*width+col][c] = pix0[c]*(1-frac) + pix1[c]*frac + 0.5; + } + height = newdim; + } else { + newdim = width * pixel_aspect + 0.5; + img = (ushort (*)[4]) calloc (height*newdim, sizeof *img); + merror (img, "stretch()"); + for (rc=col=0; col < newdim; col++, rc+=1/pixel_aspect) { + frac = rc - (c = rc); + pix0 = pix1 = image[c]; + if (c+1 < width) pix1 += 4; + for (row=0; row < height; row++, pix0+=width*4, pix1+=width*4) + FORCC img[row*newdim+col][c] = pix0[c]*(1-frac) + pix1[c]*frac + 0.5; + } + width = newdim; + } + free (image); + image = img; +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_STRETCH,1,2); +#endif +} + +int CLASS flip_index (int row, int col) +{ + if (flip & 4) SWAP(row,col); + if (flip & 2) row = iheight - 1 - row; + if (flip & 1) col = iwidth - 1 - col; + return row * iwidth + col; +} + +void CLASS tiff_set (ushort *ntag, + ushort tag, ushort type, int count, int val) +{ + struct tiff_tag *tt; + int c; + + tt = (struct tiff_tag *)(ntag+1) + (*ntag)++; + tt->tag = tag; + tt->type = type; + tt->count = count; + if (type < 3 && count <= 4) + FORC(4) tt->val.c[c] = val >> (c << 3); + else if (type == 3 && count <= 2) + FORC(2) tt->val.s[c] = val >> (c << 4); + else tt->val.i = val; +} + +#define TOFF(ptr) ((char *)(&(ptr)) - (char *)th) + +void CLASS tiff_head (struct tiff_hdr *th, int full) +{ + int c, psize=0; + struct tm *t; + + memset (th, 0, sizeof *th); + th->t_order = htonl(0x4d4d4949) >> 16; + th->magic = 42; + th->ifd = 10; + if (full) { + tiff_set (&th->ntag, 254, 4, 1, 0); + tiff_set (&th->ntag, 256, 4, 1, width); + tiff_set (&th->ntag, 257, 4, 1, height); + tiff_set (&th->ntag, 258, 3, colors, output_bps); + if (colors > 2) + th->tag[th->ntag-1].val.i = TOFF(th->bps); + FORC4 th->bps[c] = output_bps; + tiff_set (&th->ntag, 259, 3, 1, 1); + tiff_set (&th->ntag, 262, 3, 1, 1 + (colors > 1)); + } + tiff_set (&th->ntag, 270, 2, 512, TOFF(th->t_desc)); + tiff_set (&th->ntag, 271, 2, 64, TOFF(th->t_make)); + tiff_set (&th->ntag, 272, 2, 64, TOFF(th->t_model)); + if (full) { + if (oprof) psize = ntohl(oprof[0]); + tiff_set (&th->ntag, 273, 4, 1, sizeof *th + psize); + tiff_set (&th->ntag, 277, 3, 1, colors); + tiff_set (&th->ntag, 278, 4, 1, height); + tiff_set (&th->ntag, 279, 4, 1, height*width*colors*output_bps/8); + } else + tiff_set (&th->ntag, 274, 3, 1, "12435867"[flip]-'0'); + tiff_set (&th->ntag, 282, 5, 1, TOFF(th->rat[0])); + tiff_set (&th->ntag, 283, 5, 1, TOFF(th->rat[2])); + tiff_set (&th->ntag, 284, 3, 1, 1); + tiff_set (&th->ntag, 296, 3, 1, 2); + tiff_set (&th->ntag, 305, 2, 32, TOFF(th->soft)); + tiff_set (&th->ntag, 306, 2, 20, TOFF(th->date)); + tiff_set (&th->ntag, 315, 2, 64, TOFF(th->t_artist)); + tiff_set (&th->ntag, 34665, 4, 1, TOFF(th->nexif)); + if (psize) tiff_set (&th->ntag, 34675, 7, psize, sizeof *th); + tiff_set (&th->nexif, 33434, 5, 1, TOFF(th->rat[4])); + tiff_set (&th->nexif, 33437, 5, 1, TOFF(th->rat[6])); + tiff_set (&th->nexif, 34855, 3, 1, iso_speed); + tiff_set (&th->nexif, 37386, 5, 1, TOFF(th->rat[8])); + if (gpsdata[1]) { + tiff_set (&th->ntag, 34853, 4, 1, TOFF(th->ngps)); + tiff_set (&th->ngps, 0, 1, 4, 0x202); + tiff_set (&th->ngps, 1, 2, 2, gpsdata[29]); + tiff_set (&th->ngps, 2, 5, 3, TOFF(th->gps[0])); + tiff_set (&th->ngps, 3, 2, 2, gpsdata[30]); + tiff_set (&th->ngps, 4, 5, 3, TOFF(th->gps[6])); + tiff_set (&th->ngps, 5, 1, 1, gpsdata[31]); + tiff_set (&th->ngps, 6, 5, 1, TOFF(th->gps[18])); + tiff_set (&th->ngps, 7, 5, 3, TOFF(th->gps[12])); + tiff_set (&th->ngps, 18, 2, 12, TOFF(th->gps[20])); + tiff_set (&th->ngps, 29, 2, 12, TOFF(th->gps[23])); + memcpy (th->gps, gpsdata, sizeof th->gps); + } + th->rat[0] = th->rat[2] = 300; + th->rat[1] = th->rat[3] = 1; + FORC(6) th->rat[4+c] = 1000000; + th->rat[4] *= shutter; + th->rat[6] *= aperture; + th->rat[8] *= focal_len; + strncpy (th->t_desc, desc, 512); + strncpy (th->t_make, make, 64); + strncpy (th->t_model, model, 64); + strcpy (th->soft, "dcraw v"DCRAW_VERSION); + t = localtime (×tamp); + sprintf (th->date, "%04d:%02d:%02d %02d:%02d:%02d", + t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); + strncpy (th->t_artist, artist, 64); +} + +void CLASS jpeg_thumb_writer (FILE *tfp,char *t_humb,int t_humb_length) +{ + ushort exif[5]; + struct tiff_hdr th; + fputc (0xff, tfp); + fputc (0xd8, tfp); + if (strcmp (t_humb+6, "Exif")) { + memcpy (exif, "\xff\xe1 Exif\0\0", 10); + exif[1] = htons (8 + sizeof th); + fwrite (exif, 1, sizeof exif, tfp); + tiff_head (&th, 0); + fwrite (&th, 1, sizeof th, tfp); + } + fwrite (t_humb+2, 1, t_humb_length-2, tfp); +} + + +void CLASS jpeg_thumb() +{ + char *thumb; + + thumb = (char *) malloc (thumb_length); + merror (thumb, "jpeg_thumb()"); + fread (thumb, 1, thumb_length, ifp); + jpeg_thumb_writer(ofp,thumb,thumb_length); + free (thumb); +} + +void CLASS write_ppm_tiff() +{ + struct tiff_hdr th; + uchar *ppm; + ushort *ppm2; + int c, row, col, soff, rstep, cstep; + int perc, val, total, t_white=0x2000; + + perc = width * height * 0.01; /* 99th percentile white level */ + if (fuji_width) perc /= 2; + if (!((highlight & ~2) || no_auto_bright)) + for (t_white=c=0; c < colors; c++) { + for (val=0x2000, total=0; --val > 32; ) + if ((total += histogram[c][val]) > perc) break; + if (t_white < val) t_white = val; + } + gamma_curve (gamm[0], gamm[1], 2, (t_white << 3)/bright); + iheight = height; + iwidth = width; + if (flip & 4) SWAP(height,width); + ppm = (uchar *) calloc (width, colors*output_bps/8); + ppm2 = (ushort *) ppm; + merror (ppm, "write_ppm_tiff()"); + if (output_tiff) { + tiff_head (&th, 1); + fwrite (&th, sizeof th, 1, ofp); + if (oprof) + fwrite (oprof, ntohl(oprof[0]), 1, ofp); + } else if (colors > 3) + fprintf (ofp, + "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLTYPE %s\nENDHDR\n", + width, height, colors, (1 << output_bps)-1, cdesc); + else + fprintf (ofp, "P%d\n%d %d\n%d\n", + colors/2+5, width, height, (1 << output_bps)-1); + + soff = flip_index (0, 0); + cstep = flip_index (0, 1) - soff; + rstep = flip_index (1, 0) - flip_index (0, width); + for (row=0; row < height; row++, soff += rstep) { + for (col=0; col < width; col++, soff += cstep) + if (output_bps == 8) + FORCC ppm [col*colors+c] = curve[image[soff][c]] >> 8; + else FORCC ppm2[col*colors+c] = curve[image[soff][c]]; + if (output_bps == 16 && !output_tiff && htons(0x55aa) != 0x55aa) + swab ((char*)ppm2, (char*)ppm2, width*colors*2); + fwrite (ppm, colors*output_bps/8, width, ofp); + } + free (ppm); +} + diff --git a/Source/LibRawLite/internal/dcraw_fileio.cpp b/Source/LibRawLite/internal/dcraw_fileio.cpp index ec796ce..70c695c 100644 --- a/Source/LibRawLite/internal/dcraw_fileio.cpp +++ b/Source/LibRawLite/internal/dcraw_fileio.cpp @@ -1,240 +1,240 @@ -/* - Copyright 2008-2010 LibRaw LLC (info@libraw.org) - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - - This file is generated from Dave Coffin's dcraw.c - dcraw.c -- Dave Coffin's raw photo decoder - Copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net - - Look into dcraw homepage (probably http://cybercom.net/~dcoffin/dcraw/) - for more information -*/ - -#include -#define CLASS LibRaw:: -#include "libraw/libraw_types.h" -#define LIBRAW_LIBRARY_BUILD -#include "libraw/libraw.h" -#include "internal/defines.h" -#include "internal/var_defines.h" - -/* - Seach from the current directory up to the root looking for - a ".badpixels" file, and fix those pixels now. - */ -void CLASS bad_pixels (const char *cfname) -{ - FILE *fp=0; -#ifndef LIBRAW_LIBRARY_BUILD - char *fname, *cp, line[128]; - int len, time, row, col, r, c, rad, tot, n, fixed=0; -#else - char *cp, line[128]; - int time, row, col, r, c, rad, tot, n; -#ifdef DCRAW_VERBOSE - int fixed = 0; -#endif -#endif - - if (!filters) return; -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_BAD_PIXELS,0,2); -#endif - if (cfname) - fp = fopen (cfname, "r"); - if (!fp) - { -#ifdef LIBRAW_LIBRARY_BUILD - imgdata.process_warnings |= LIBRAW_WARN_NO_BADPIXELMAP; -#endif - return; - } - while (fgets (line, 128, fp)) { - cp = strchr (line, '#'); - if (cp) *cp = 0; - if (sscanf (line, "%d %d %d", &col, &row, &time) != 3) continue; - if ((unsigned) col >= width || (unsigned) row >= height) continue; - if (time > timestamp) continue; - for (tot=n=0, rad=1; rad < 3 && n==0; rad++) - for (r = row-rad; r <= row+rad; r++) - for (c = col-rad; c <= col+rad; c++) - if ((unsigned) r < height && (unsigned) c < width && - (r != row || c != col) && fc(r,c) == fc(row,col)) { - tot += BAYER2(r,c); - n++; - } - BAYER2(row,col) = tot/n; -#ifdef DCRAW_VERBOSE - if (verbose) { - if (!fixed++) - fprintf (stderr,_("Fixed dead pixels at:")); - fprintf (stderr, " %d,%d", col, row); - } -#endif - } -#ifdef DCRAW_VERBOSE - if (fixed) fputc ('\n', stderr); -#endif - fclose (fp); -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_BAD_PIXELS,1,2); -#endif -} - -void CLASS subtract (const char *fname) -{ - FILE *fp; - int dim[3]={0,0,0}, comment=0, number=0, error=0, nd=0, c, row, col; - ushort *pixel; -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_DARK_FRAME,0,2); -#endif - - if (!(fp = fopen (fname, "rb"))) { -#ifdef DCRAW_VERBOSE - perror (fname); -#endif -#ifdef LIBRAW_LIBRARY_BUILD - imgdata.process_warnings |= LIBRAW_WARN_BAD_DARKFRAME_FILE; -#endif - return; - } - if (fgetc(fp) != 'P' || fgetc(fp) != '5') error = 1; - while (!error && nd < 3 && (c = fgetc(fp)) != EOF) { - if (c == '#') comment = 1; - if (c == '\n') comment = 0; - if (comment) continue; - if (isdigit(c)) number = 1; - if (number) { - if (isdigit(c)) dim[nd] = dim[nd]*10 + c -'0'; - else if (isspace(c)) { - number = 0; nd++; - } else error = 1; - } - } - if (error || nd < 3) { - fprintf (stderr,_("%s is not a valid PGM file!\n"), fname); - fclose (fp); return; - } else if (dim[0] != width || dim[1] != height || dim[2] != 65535) { -#ifdef DCRAW_VERBOSE - fprintf (stderr,_("%s has the wrong dimensions!\n"), fname); -#endif -#ifdef LIBRAW_LIBRARY_BUILD - imgdata.process_warnings |= LIBRAW_WARN_BAD_DARKFRAME_DIM; -#endif - fclose (fp); return; - } - pixel = (ushort *) calloc (width, sizeof *pixel); - merror (pixel, "subtract()"); - for (row=0; row < height; row++) { - fread (pixel, 2, width, fp); - for (col=0; col < width; col++) - BAYER(row,col) = MAX (BAYER(row,col) - ntohs(pixel[col]), 0); - } - free (pixel); - fclose (fp); - memset (cblack, 0, sizeof cblack); - black = 0; -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_DARK_FRAME,1,2); -#endif -} - -#ifndef NO_LCMS -void CLASS apply_profile (const char *input, const char *output) -{ - char *prof; - cmsHPROFILE hInProfile=0, hOutProfile=0; - cmsHTRANSFORM hTransform; - FILE *fp; - unsigned size; - -#ifndef USE_LCMS2 - cmsErrorAction (LCMS_ERROR_SHOW); -#endif - if (strcmp (input, "embed")) - hInProfile = cmsOpenProfileFromFile (input, "r"); - else if (profile_length) { -#ifndef LIBRAW_LIBRARY_BUILD - prof = (char *) malloc (profile_length); - merror (prof, "apply_profile()"); - fseek (ifp, profile_offset, SEEK_SET); - fread (prof, 1, profile_length, ifp); - hInProfile = cmsOpenProfileFromMem (prof, profile_length); - free (prof); -#else - hInProfile = cmsOpenProfileFromMem (imgdata.color.profile, profile_length); -#endif - } else - { -#ifdef LIBRAW_LIBRARY_BUILD - imgdata.process_warnings |= LIBRAW_WARN_NO_EMBEDDED_PROFILE; -#endif -#ifdef DCRAW_VERBOSE - fprintf (stderr,_("%s has no embedded profile.\n"), ifname); -#endif - } - if (!hInProfile) - { -#ifdef LIBRAW_LIBRARY_BUILD - imgdata.process_warnings |= LIBRAW_WARN_NO_INPUT_PROFILE; -#endif - return; - } - if (!output) - hOutProfile = cmsCreate_sRGBProfile(); - else if ((fp = fopen (output, "rb"))) { - fread (&size, 4, 1, fp); - fseek (fp, 0, SEEK_SET); - oprof = (unsigned *) malloc (size = ntohl(size)); - merror (oprof, "apply_profile()"); - fread (oprof, 1, size, fp); - fclose (fp); - if (!(hOutProfile = cmsOpenProfileFromMem (oprof, size))) { - free (oprof); - oprof = 0; - } -#ifdef DCRAW_VERBOSE - } else - fprintf (stderr,_("Cannot open file %s!\n"), output); -#else -} -#endif - if (!hOutProfile) - { -#ifdef LIBRAW_LIBRARY_BUILD - imgdata.process_warnings |= LIBRAW_WARN_BAD_OUTPUT_PROFILE; -#endif - goto quit; - } -#ifdef DCRAW_VERBOSE - if (verbose) - fprintf (stderr,_("Applying color profile...\n")); -#endif -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_APPLY_PROFILE,0,2); -#endif - hTransform = cmsCreateTransform (hInProfile, TYPE_RGBA_16, - hOutProfile, TYPE_RGBA_16, INTENT_PERCEPTUAL, 0); - cmsDoTransform (hTransform, image, image, width*height); - raw_color = 1; /* Don't use rgb_cam with a profile */ - cmsDeleteTransform (hTransform); - cmsCloseProfile (hOutProfile); -quit: - cmsCloseProfile (hInProfile); -#ifdef LIBRAW_LIBRARY_BUILD - RUN_CALLBACK(LIBRAW_PROGRESS_APPLY_PROFILE,1,2); -#endif -} -#endif +/* + Copyright 2008-2010 LibRaw LLC (info@libraw.org) + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + + This file is generated from Dave Coffin's dcraw.c + dcraw.c -- Dave Coffin's raw photo decoder + Copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net + + Look into dcraw homepage (probably http://cybercom.net/~dcoffin/dcraw/) + for more information +*/ + +#include +#define CLASS LibRaw:: +#include "libraw/libraw_types.h" +#define LIBRAW_LIBRARY_BUILD +#include "libraw/libraw.h" +#include "internal/defines.h" +#include "internal/var_defines.h" + +/* + Seach from the current directory up to the root looking for + a ".badpixels" file, and fix those pixels now. + */ +void CLASS bad_pixels (const char *cfname) +{ + FILE *fp=0; +#ifndef LIBRAW_LIBRARY_BUILD + char *fname, *cp, line[128]; + int len, time, row, col, r, c, rad, tot, n, fixed=0; +#else + char *cp, line[128]; + int time, row, col, r, c, rad, tot, n; +#ifdef DCRAW_VERBOSE + int fixed = 0; +#endif +#endif + + if (!filters) return; +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_BAD_PIXELS,0,2); +#endif + if (cfname) + fp = fopen (cfname, "r"); + if (!fp) + { +#ifdef LIBRAW_LIBRARY_BUILD + imgdata.process_warnings |= LIBRAW_WARN_NO_BADPIXELMAP; +#endif + return; + } + while (fgets (line, 128, fp)) { + cp = strchr (line, '#'); + if (cp) *cp = 0; + if (sscanf (line, "%d %d %d", &col, &row, &time) != 3) continue; + if ((unsigned) col >= width || (unsigned) row >= height) continue; + if (time > timestamp) continue; + for (tot=n=0, rad=1; rad < 3 && n==0; rad++) + for (r = row-rad; r <= row+rad; r++) + for (c = col-rad; c <= col+rad; c++) + if ((unsigned) r < height && (unsigned) c < width && + (r != row || c != col) && fc(r,c) == fc(row,col)) { + tot += BAYER2(r,c); + n++; + } + BAYER2(row,col) = tot/n; +#ifdef DCRAW_VERBOSE + if (verbose) { + if (!fixed++) + fprintf (stderr,_("Fixed dead pixels at:")); + fprintf (stderr, " %d,%d", col, row); + } +#endif + } +#ifdef DCRAW_VERBOSE + if (fixed) fputc ('\n', stderr); +#endif + fclose (fp); +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_BAD_PIXELS,1,2); +#endif +} + +void CLASS subtract (const char *fname) +{ + FILE *fp; + int dim[3]={0,0,0}, comment=0, number=0, error=0, nd=0, c, row, col; + ushort *pixel; +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_DARK_FRAME,0,2); +#endif + + if (!(fp = fopen (fname, "rb"))) { +#ifdef DCRAW_VERBOSE + perror (fname); +#endif +#ifdef LIBRAW_LIBRARY_BUILD + imgdata.process_warnings |= LIBRAW_WARN_BAD_DARKFRAME_FILE; +#endif + return; + } + if (fgetc(fp) != 'P' || fgetc(fp) != '5') error = 1; + while (!error && nd < 3 && (c = fgetc(fp)) != EOF) { + if (c == '#') comment = 1; + if (c == '\n') comment = 0; + if (comment) continue; + if (isdigit(c)) number = 1; + if (number) { + if (isdigit(c)) dim[nd] = dim[nd]*10 + c -'0'; + else if (isspace(c)) { + number = 0; nd++; + } else error = 1; + } + } + if (error || nd < 3) { + fprintf (stderr,_("%s is not a valid PGM file!\n"), fname); + fclose (fp); return; + } else if (dim[0] != width || dim[1] != height || dim[2] != 65535) { +#ifdef DCRAW_VERBOSE + fprintf (stderr,_("%s has the wrong dimensions!\n"), fname); +#endif +#ifdef LIBRAW_LIBRARY_BUILD + imgdata.process_warnings |= LIBRAW_WARN_BAD_DARKFRAME_DIM; +#endif + fclose (fp); return; + } + pixel = (ushort *) calloc (width, sizeof *pixel); + merror (pixel, "subtract()"); + for (row=0; row < height; row++) { + fread (pixel, 2, width, fp); + for (col=0; col < width; col++) + BAYER(row,col) = MAX (BAYER(row,col) - ntohs(pixel[col]), 0); + } + free (pixel); + fclose (fp); + memset (cblack, 0, sizeof cblack); + black = 0; +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_DARK_FRAME,1,2); +#endif +} + +#ifndef NO_LCMS +void CLASS apply_profile (const char *input, const char *output) +{ + char *prof; + cmsHPROFILE hInProfile=0, hOutProfile=0; + cmsHTRANSFORM hTransform; + FILE *fp; + unsigned size; + +#ifndef USE_LCMS2 + cmsErrorAction (LCMS_ERROR_SHOW); +#endif + if (strcmp (input, "embed")) + hInProfile = cmsOpenProfileFromFile (input, "r"); + else if (profile_length) { +#ifndef LIBRAW_LIBRARY_BUILD + prof = (char *) malloc (profile_length); + merror (prof, "apply_profile()"); + fseek (ifp, profile_offset, SEEK_SET); + fread (prof, 1, profile_length, ifp); + hInProfile = cmsOpenProfileFromMem (prof, profile_length); + free (prof); +#else + hInProfile = cmsOpenProfileFromMem (imgdata.color.profile, profile_length); +#endif + } else + { +#ifdef LIBRAW_LIBRARY_BUILD + imgdata.process_warnings |= LIBRAW_WARN_NO_EMBEDDED_PROFILE; +#endif +#ifdef DCRAW_VERBOSE + fprintf (stderr,_("%s has no embedded profile.\n"), ifname); +#endif + } + if (!hInProfile) + { +#ifdef LIBRAW_LIBRARY_BUILD + imgdata.process_warnings |= LIBRAW_WARN_NO_INPUT_PROFILE; +#endif + return; + } + if (!output) + hOutProfile = cmsCreate_sRGBProfile(); + else if ((fp = fopen (output, "rb"))) { + fread (&size, 4, 1, fp); + fseek (fp, 0, SEEK_SET); + oprof = (unsigned *) malloc (size = ntohl(size)); + merror (oprof, "apply_profile()"); + fread (oprof, 1, size, fp); + fclose (fp); + if (!(hOutProfile = cmsOpenProfileFromMem (oprof, size))) { + free (oprof); + oprof = 0; + } +#ifdef DCRAW_VERBOSE + } else + fprintf (stderr,_("Cannot open file %s!\n"), output); +#else +} +#endif + if (!hOutProfile) + { +#ifdef LIBRAW_LIBRARY_BUILD + imgdata.process_warnings |= LIBRAW_WARN_BAD_OUTPUT_PROFILE; +#endif + goto quit; + } +#ifdef DCRAW_VERBOSE + if (verbose) + fprintf (stderr,_("Applying color profile...\n")); +#endif +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_APPLY_PROFILE,0,2); +#endif + hTransform = cmsCreateTransform (hInProfile, TYPE_RGBA_16, + hOutProfile, TYPE_RGBA_16, INTENT_PERCEPTUAL, 0); + cmsDoTransform (hTransform, image, image, width*height); + raw_color = 1; /* Don't use rgb_cam with a profile */ + cmsDeleteTransform (hTransform); + cmsCloseProfile (hOutProfile); +quit: + cmsCloseProfile (hInProfile); +#ifdef LIBRAW_LIBRARY_BUILD + RUN_CALLBACK(LIBRAW_PROGRESS_APPLY_PROFILE,1,2); +#endif +} +#endif diff --git a/Source/LibRawLite/internal/defines.h b/Source/LibRawLite/internal/defines.h index 2fb5bb8..71e0c9d 100644 --- a/Source/LibRawLite/internal/defines.h +++ b/Source/LibRawLite/internal/defines.h @@ -1,153 +1,153 @@ -/* - Copyright 2008-2010 LibRaw LLC (info@libraw.org) - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - - This file is generated from Dave Coffin's dcraw.c - dcraw.c -- Dave Coffin's raw photo decoder - Copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net - - Look into dcraw homepage (probably http://cybercom.net/~dcoffin/dcraw/) - for more information -*/ - -#define NO_JPEG -#ifndef USE_JASPER -#define NO_JASPER -#endif -#define DCRAW_VERSION "9.12" - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif -#define _USE_MATH_DEFINES -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - NO_JPEG disables decoding of compressed Kodak DC120 files. - NO_LCMS disables the "-p" option. - */ -#ifdef NODEPS -#define NO_JASPER -#define NO_JPEG -#define NO_LCMS -#endif -#ifndef NO_JASPER -#undef PACKAGE_BUGREPORT -#undef PACKAGE_NAME -#undef PACKAGE_STRING -#undef PACKAGE_TARNAME -#undef PACKAGE_VERSION -#include /* Decode RED camera movies */ -#endif -#ifndef NO_JPEG -#include /* Decode compressed Kodak DC120 photos */ -#endif -#ifdef LOCALEDIR -#include -#define _(String) gettext(String) -#else -#define _(String) (String) -#endif -#ifdef __CYGWIN__ -#include -#endif -#ifdef WIN32 -#include -#include -#pragma comment(lib, "ws2_32.lib") -#define snprintf _snprintf -#define strcasecmp _stricmp -#define strncasecmp strnicmp -#else -#include -#include -#include -#endif - -#ifdef LJPEG_DECODE -#error Please compile dcraw.c by itself. -#error Do not link it with ljpeg_decode. -#endif - -#ifndef LONG_BIT -#define LONG_BIT (8 * sizeof (long)) -#endif -#define FORC(cnt) for (c=0; c < cnt; c++) -#define FORC3 FORC(3) -#define FORC4 FORC(4) -#define FORCC FORC(colors) - -#define SQR(x) ((x)*(x)) -#define ABS(x) (((int)(x) ^ ((int)(x) >> 31)) - ((int)(x) >> 31)) -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) > (b) ? (a) : (b)) -#define LIM(x,min,max) MAX(min,MIN(x,max)) -#define ULIM(x,y,z) ((y) < (z) ? LIM(x,y,z) : LIM(x,z,y)) -#define CLIP(x) LIM(x,0,65535) -#define SWAP(a,b) { a=a+b; b=a-b; a=a-b; } - -/* - In order to inline this calculation, I make the risky - assumption that all filter patterns can be described - by a repeating pattern of eight rows and two columns - - Do not use the FC or BAYER macros with the Leaf CatchLight, - because its pattern is 16x16, not 2x8. - - Return values are either 0/1/2/3 = G/M/C/Y or 0/1/2/3 = R/G1/B/G2 - - PowerShot 600 PowerShot A50 PowerShot Pro70 Pro90 & G1 - 0xe1e4e1e4: 0x1b4e4b1e: 0x1e4b4e1b: 0xb4b4b4b4: - - 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 - 0 G M G M G M 0 C Y C Y C Y 0 Y C Y C Y C 0 G M G M G M - 1 C Y C Y C Y 1 M G M G M G 1 M G M G M G 1 Y C Y C Y C - 2 M G M G M G 2 Y C Y C Y C 2 C Y C Y C Y - 3 C Y C Y C Y 3 G M G M G M 3 G M G M G M - 4 C Y C Y C Y 4 Y C Y C Y C - PowerShot A5 5 G M G M G M 5 G M G M G M - 0x1e4e1e4e: 6 Y C Y C Y C 6 C Y C Y C Y - 7 M G M G M G 7 M G M G M G - 0 1 2 3 4 5 - 0 C Y C Y C Y - 1 G M G M G M - 2 C Y C Y C Y - 3 M G M G M G - - All RGB cameras use one of these Bayer grids: - - 0x16161616: 0x61616161: 0x49494949: 0x94949494: - - 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 - 0 B G B G B G 0 G R G R G R 0 G B G B G B 0 R G R G R G - 1 G R G R G R 1 B G B G B G 1 R G R G R G 1 G B G B G B - 2 B G B G B G 2 G R G R G R 2 G B G B G B 2 R G R G R G - 3 G R G R G R 3 B G B G B G 3 R G R G R G 3 G B G B G B - */ - -#define BAYER(row,col) \ - image[((row) >> shrink)*iwidth + ((col) >> shrink)][FC(row,col)] -#define BAYER2(row,col) \ - image[((row) >> shrink)*iwidth + ((col) >> shrink)][fc(row,col)] +/* + Copyright 2008-2010 LibRaw LLC (info@libraw.org) + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + + This file is generated from Dave Coffin's dcraw.c + dcraw.c -- Dave Coffin's raw photo decoder + Copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net + + Look into dcraw homepage (probably http://cybercom.net/~dcoffin/dcraw/) + for more information +*/ + +#define NO_JPEG +#ifndef USE_JASPER +#define NO_JASPER +#endif +#define DCRAW_VERSION "9.12" + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#define _USE_MATH_DEFINES +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + NO_JPEG disables decoding of compressed Kodak DC120 files. + NO_LCMS disables the "-p" option. + */ +#ifdef NODEPS +#define NO_JASPER +#define NO_JPEG +#define NO_LCMS +#endif +#ifndef NO_JASPER +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_VERSION +#include /* Decode RED camera movies */ +#endif +#ifndef NO_JPEG +#include /* Decode compressed Kodak DC120 photos */ +#endif +#ifdef LOCALEDIR +#include +#define _(String) gettext(String) +#else +#define _(String) (String) +#endif +#ifdef __CYGWIN__ +#include +#endif +#ifdef WIN32 +#include +#include +#pragma comment(lib, "ws2_32.lib") +#define snprintf _snprintf +#define strcasecmp _stricmp +#define strncasecmp strnicmp +#else +#include +#include +#include +#endif + +#ifdef LJPEG_DECODE +#error Please compile dcraw.c by itself. +#error Do not link it with ljpeg_decode. +#endif + +#ifndef LONG_BIT +#define LONG_BIT (8 * sizeof (long)) +#endif +#define FORC(cnt) for (c=0; c < cnt; c++) +#define FORC3 FORC(3) +#define FORC4 FORC(4) +#define FORCC FORC(colors) + +#define SQR(x) ((x)*(x)) +#define ABS(x) (((int)(x) ^ ((int)(x) >> 31)) - ((int)(x) >> 31)) +#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#define MAX(a,b) ((a) > (b) ? (a) : (b)) +#define LIM(x,min,max) MAX(min,MIN(x,max)) +#define ULIM(x,y,z) ((y) < (z) ? LIM(x,y,z) : LIM(x,z,y)) +#define CLIP(x) LIM(x,0,65535) +#define SWAP(a,b) { a=a+b; b=a-b; a=a-b; } + +/* + In order to inline this calculation, I make the risky + assumption that all filter patterns can be described + by a repeating pattern of eight rows and two columns + + Do not use the FC or BAYER macros with the Leaf CatchLight, + because its pattern is 16x16, not 2x8. + + Return values are either 0/1/2/3 = G/M/C/Y or 0/1/2/3 = R/G1/B/G2 + + PowerShot 600 PowerShot A50 PowerShot Pro70 Pro90 & G1 + 0xe1e4e1e4: 0x1b4e4b1e: 0x1e4b4e1b: 0xb4b4b4b4: + + 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 + 0 G M G M G M 0 C Y C Y C Y 0 Y C Y C Y C 0 G M G M G M + 1 C Y C Y C Y 1 M G M G M G 1 M G M G M G 1 Y C Y C Y C + 2 M G M G M G 2 Y C Y C Y C 2 C Y C Y C Y + 3 C Y C Y C Y 3 G M G M G M 3 G M G M G M + 4 C Y C Y C Y 4 Y C Y C Y C + PowerShot A5 5 G M G M G M 5 G M G M G M + 0x1e4e1e4e: 6 Y C Y C Y C 6 C Y C Y C Y + 7 M G M G M G 7 M G M G M G + 0 1 2 3 4 5 + 0 C Y C Y C Y + 1 G M G M G M + 2 C Y C Y C Y + 3 M G M G M G + + All RGB cameras use one of these Bayer grids: + + 0x16161616: 0x61616161: 0x49494949: 0x94949494: + + 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 + 0 B G B G B G 0 G R G R G R 0 G B G B G B 0 R G R G R G + 1 G R G R G R 1 B G B G B G 1 R G R G R G 1 G B G B G B + 2 B G B G B G 2 G R G R G R 2 G B G B G B 2 R G R G R G + 3 G R G R G R 3 B G B G B G 3 R G R G R G 3 G B G B G B + */ + +#define BAYER(row,col) \ + image[((row) >> shrink)*iwidth + ((col) >> shrink)][FC(row,col)] +#define BAYER2(row,col) \ + image[((row) >> shrink)*iwidth + ((col) >> shrink)][fc(row,col)] diff --git a/Source/LibRawLite/internal/demosaic_packs.cpp b/Source/LibRawLite/internal/demosaic_packs.cpp index 874fc10..dccdf78 100644 --- a/Source/LibRawLite/internal/demosaic_packs.cpp +++ b/Source/LibRawLite/internal/demosaic_packs.cpp @@ -1,97 +1,97 @@ -/* - Copyright 2008-2010 LibRaw LLC (info@libraw.org) - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - - This file is generated from Dave Coffin's dcraw.c - dcraw.c -- Dave Coffin's raw photo decoder - Copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net - - Look into dcraw homepage (probably http://cybercom.net/~dcoffin/dcraw/) - for more information -*/ - -#include - -#define CLASS LibRaw:: - -#include "libraw/libraw_types.h" -#define LIBRAW_LIBRARY_BUILD -#define LIBRAW_IO_REDEFINED -#include "libraw/libraw.h" -#include "internal/defines.h" -#define SRC_USES_SHRINK -#define SRC_USES_BLACK -#define SRC_USES_CURVE - -#include "internal/var_defines.h" - - -#ifdef LIBRAW_DEMOSAIC_PACK_GPL2 -/*AHD-Mod*/ -#include -/*LMMSE*/ -#include -/*AFD*/ -#include -#include -/* VCD*/ -#include -#include -#include -#include -#else -// fake implementations of all GPL2 demosaics - -void CLASS ahd_interpolate_mod() {ahd_interpolate();} -void CLASS afd_interpolate_pl(int, int) {ahd_interpolate();} -void CLASS vcd_interpolate(int) {ahd_interpolate();} -void CLASS lmmse_interpolate(int) {ahd_interpolate();} -void CLASS es_median_filter() {} -void CLASS median_filter_new() {} -void CLASS refinement() {} - -#endif - -/* DCB is BSD licensed, so include it */ -#include "./dcb_demosaicing.c" - -#ifdef LIBRAW_DEMOSAIC_PACK_GPL3 -/*AMaZE*/ -#include -#include -#include -#include -#include -#else -// fallback to AHD and no correction -void CLASS CA_correct_RT(float,float){} -void CLASS amaze_demosaic_RT() { ahd_interpolate();} -void CLASS green_equilibrate(float thresh) {} -void CLASS cfa_linedn(float linenoise){} -void CLASS cfa_impulse_gauss(float lclean, float cclean){} -#endif - -#define sget4(s) sget4((uchar *)s) -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif -#ifdef LIBRAW_DEMOSAIC_PACK_GPL2 -#include -#else -void CLASS foveon_interpolate(){} -void CLASS foveon_load_raw(){} -void CLASS parse_foveon(){} -void CLASS foveon_thumb_loader(){} -void CLASS foveon_thumb(){} -#endif +/* + Copyright 2008-2010 LibRaw LLC (info@libraw.org) + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + + This file is generated from Dave Coffin's dcraw.c + dcraw.c -- Dave Coffin's raw photo decoder + Copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net + + Look into dcraw homepage (probably http://cybercom.net/~dcoffin/dcraw/) + for more information +*/ + +#include + +#define CLASS LibRaw:: + +#include "libraw/libraw_types.h" +#define LIBRAW_LIBRARY_BUILD +#define LIBRAW_IO_REDEFINED +#include "libraw/libraw.h" +#include "internal/defines.h" +#define SRC_USES_SHRINK +#define SRC_USES_BLACK +#define SRC_USES_CURVE + +#include "internal/var_defines.h" + + +#ifdef LIBRAW_DEMOSAIC_PACK_GPL2 +/*AHD-Mod*/ +#include +/*LMMSE*/ +#include +/*AFD*/ +#include +#include +/* VCD*/ +#include +#include +#include +#include +#else +// fake implementations of all GPL2 demosaics + +void CLASS ahd_interpolate_mod() {ahd_interpolate();} +void CLASS afd_interpolate_pl(int, int) {ahd_interpolate();} +void CLASS vcd_interpolate(int) {ahd_interpolate();} +void CLASS lmmse_interpolate(int) {ahd_interpolate();} +void CLASS es_median_filter() {} +void CLASS median_filter_new() {} +void CLASS refinement() {} + +#endif + +/* DCB is BSD licensed, so include it */ +#include "./dcb_demosaicing.c" + +#ifdef LIBRAW_DEMOSAIC_PACK_GPL3 +/*AMaZE*/ +#include +#include +#include +#include +#include +#else +// fallback to AHD and no correction +void CLASS CA_correct_RT(float,float){} +void CLASS amaze_demosaic_RT() { ahd_interpolate();} +void CLASS green_equilibrate(float thresh) {} +void CLASS cfa_linedn(float linenoise){} +void CLASS cfa_impulse_gauss(float lclean, float cclean){} +#endif + +#define sget4(s) sget4((uchar *)s) +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif +#ifdef LIBRAW_DEMOSAIC_PACK_GPL2 +#include +#else +void CLASS foveon_interpolate(){} +void CLASS foveon_load_raw(){} +void CLASS parse_foveon(){} +void CLASS foveon_thumb_loader(){} +void CLASS foveon_thumb(){} +#endif diff --git a/Source/LibRawLite/internal/libraw_bytebuffer.h b/Source/LibRawLite/internal/libraw_bytebuffer.h index ba180c3..487173a 100644 --- a/Source/LibRawLite/internal/libraw_bytebuffer.h +++ b/Source/LibRawLite/internal/libraw_bytebuffer.h @@ -1,140 +1,140 @@ -/* -*- C -*- - * File: libraw_bytebuffer.h - * - * Created: Fri Aug 12 14:41:45 2011 - - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - - */ -class LibRaw_byte_buffer -{ - public: - LibRaw_byte_buffer(unsigned sz=0); - void set_buffer(void *bb, unsigned int sz); - virtual ~LibRaw_byte_buffer(); - // fast inlines - int get_byte() { if(offt>=size) return EOF; return buf[offt++];} - void unseek2() { if(offt>=2) offt-=2;} - void *get_buffer() { return buf; } - int get_ljpeg_byte() { - if(offt>=size) return 0; - unsigned char val = buf[offt++]; - if(val!=0xFF || offt >=size || buf[offt++]==0) - return val; - offt -=2; - return 0; - } - - private: - unsigned char *buf; - unsigned int size,offt, do_free; -}; - -class LibRaw_bit_buffer -{ - unsigned bitbuf; - int vbits, rst; - public: - LibRaw_bit_buffer() : bitbuf(0),vbits(0),rst(0) {} - - void reset() { bitbuf=vbits=rst=0;} -#ifndef LIBRAW_LIBRARY_BUILD - void fill_lj(LibRaw_byte_buffer* buf,int nbits); - unsigned _getbits_lj(LibRaw_byte_buffer* buf, int nbits); - unsigned _gethuff_lj(LibRaw_byte_buffer* buf, int nbits, unsigned short* huff); - void fill(LibRaw_byte_buffer* buf,int nbits,int zer0_ff); - unsigned _getbits(LibRaw_byte_buffer* buf, int nbits,int zer0_ff); - unsigned _gethuff(LibRaw_byte_buffer* buf, int nbits, unsigned short* huff, int zer0_ff); -#else - void fill_lj(LibRaw_byte_buffer* buf,int nbits) - { - unsigned c1,c2,c3; - if(rst || nbits < vbits) return; - int m = vbits >> 3; - switch(m) - { - case 2: - c1 = buf->get_ljpeg_byte(); - bitbuf = (bitbuf <<8) | (c1); - vbits+=8; - break; - case 1: - c1 = buf->get_ljpeg_byte(); - c2 = buf->get_ljpeg_byte(); - bitbuf = (bitbuf <<16) | (c1<<8) | c2; - vbits+=16; - break; - case 0: - c1 = buf->get_ljpeg_byte(); - c2 = buf->get_ljpeg_byte(); - c3 = buf->get_ljpeg_byte(); - bitbuf = (bitbuf <<24) | (c1<<16) | (c2<<8)|c3; - vbits+=24; - break; - } - } - - unsigned _getbits_lj(LibRaw_byte_buffer* buf, int nbits) - { - unsigned c; - if(nbits==0 || vbits < 0) return 0; - fill_lj(buf,nbits); - c = bitbuf << (32-vbits) >> (32-nbits); - vbits-=nbits; - if(vbits<0)throw LIBRAW_EXCEPTION_IO_EOF; - return c; - } - unsigned _gethuff_lj(LibRaw_byte_buffer* buf, int nbits, unsigned short* huff) - { - unsigned c; - if(nbits==0 || vbits < 0) return 0; - fill_lj(buf,nbits); - c = bitbuf << (32-vbits) >> (32-nbits); - vbits -= huff[c] >> 8; - c = (uchar) huff[c]; - if(vbits<0)throw LIBRAW_EXCEPTION_IO_EOF; - return c; - } - void fill(LibRaw_byte_buffer* buf,int nbits,int zer0_ff) - { - unsigned c; - while (!rst && vbits < nbits && (c = buf->get_byte()) != EOF && - !(rst = zer0_ff && c == 0xff && buf->get_byte())) { - bitbuf = (bitbuf << 8) + (uchar) c; - vbits += 8; - } - } - unsigned _getbits(LibRaw_byte_buffer* buf, int nbits,int zer0_ff) - { - unsigned c; - if(nbits==0 || vbits < 0) return 0; - fill(buf,nbits,zer0_ff); - c = bitbuf << (32-vbits) >> (32-nbits); - vbits-=nbits; - if(vbits<0)throw LIBRAW_EXCEPTION_IO_EOF; - return c; - } - unsigned _gethuff(LibRaw_byte_buffer* buf, int nbits, unsigned short* huff, int zer0_ff) - { - unsigned c; - if(nbits==0 || vbits < 0) return 0; - fill(buf,nbits,zer0_ff); - c = bitbuf << (32-vbits) >> (32-nbits); - vbits -= huff[c] >> 8; - c = (uchar) huff[c]; - if(vbits<0)throw LIBRAW_EXCEPTION_IO_EOF; - return c; - } -#endif -}; +/* -*- C -*- + * File: libraw_bytebuffer.h + * + * Created: Fri Aug 12 14:41:45 2011 + + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + + */ +class LibRaw_byte_buffer +{ + public: + LibRaw_byte_buffer(unsigned sz=0); + void set_buffer(void *bb, unsigned int sz); + virtual ~LibRaw_byte_buffer(); + // fast inlines + int get_byte() { if(offt>=size) return EOF; return buf[offt++];} + void unseek2() { if(offt>=2) offt-=2;} + void *get_buffer() { return buf; } + int get_ljpeg_byte() { + if(offt>=size) return 0; + unsigned char val = buf[offt++]; + if(val!=0xFF || offt >=size || buf[offt++]==0) + return val; + offt -=2; + return 0; + } + + private: + unsigned char *buf; + unsigned int size,offt, do_free; +}; + +class LibRaw_bit_buffer +{ + unsigned bitbuf; + int vbits, rst; + public: + LibRaw_bit_buffer() : bitbuf(0),vbits(0),rst(0) {} + + void reset() { bitbuf=vbits=rst=0;} +#ifndef LIBRAW_LIBRARY_BUILD + void fill_lj(LibRaw_byte_buffer* buf,int nbits); + unsigned _getbits_lj(LibRaw_byte_buffer* buf, int nbits); + unsigned _gethuff_lj(LibRaw_byte_buffer* buf, int nbits, unsigned short* huff); + void fill(LibRaw_byte_buffer* buf,int nbits,int zer0_ff); + unsigned _getbits(LibRaw_byte_buffer* buf, int nbits,int zer0_ff); + unsigned _gethuff(LibRaw_byte_buffer* buf, int nbits, unsigned short* huff, int zer0_ff); +#else + void fill_lj(LibRaw_byte_buffer* buf,int nbits) + { + unsigned c1,c2,c3; + if(rst || nbits < vbits) return; + int m = vbits >> 3; + switch(m) + { + case 2: + c1 = buf->get_ljpeg_byte(); + bitbuf = (bitbuf <<8) | (c1); + vbits+=8; + break; + case 1: + c1 = buf->get_ljpeg_byte(); + c2 = buf->get_ljpeg_byte(); + bitbuf = (bitbuf <<16) | (c1<<8) | c2; + vbits+=16; + break; + case 0: + c1 = buf->get_ljpeg_byte(); + c2 = buf->get_ljpeg_byte(); + c3 = buf->get_ljpeg_byte(); + bitbuf = (bitbuf <<24) | (c1<<16) | (c2<<8)|c3; + vbits+=24; + break; + } + } + + unsigned _getbits_lj(LibRaw_byte_buffer* buf, int nbits) + { + unsigned c; + if(nbits==0 || vbits < 0) return 0; + fill_lj(buf,nbits); + c = bitbuf << (32-vbits) >> (32-nbits); + vbits-=nbits; + if(vbits<0)throw LIBRAW_EXCEPTION_IO_EOF; + return c; + } + unsigned _gethuff_lj(LibRaw_byte_buffer* buf, int nbits, unsigned short* huff) + { + unsigned c; + if(nbits==0 || vbits < 0) return 0; + fill_lj(buf,nbits); + c = bitbuf << (32-vbits) >> (32-nbits); + vbits -= huff[c] >> 8; + c = (uchar) huff[c]; + if(vbits<0)throw LIBRAW_EXCEPTION_IO_EOF; + return c; + } + void fill(LibRaw_byte_buffer* buf,int nbits,int zer0_ff) + { + unsigned c; + while (!rst && vbits < nbits && (c = buf->get_byte()) != EOF && + !(rst = zer0_ff && c == 0xff && buf->get_byte())) { + bitbuf = (bitbuf << 8) + (uchar) c; + vbits += 8; + } + } + unsigned _getbits(LibRaw_byte_buffer* buf, int nbits,int zer0_ff) + { + unsigned c; + if(nbits==0 || vbits < 0) return 0; + fill(buf,nbits,zer0_ff); + c = bitbuf << (32-vbits) >> (32-nbits); + vbits-=nbits; + if(vbits<0)throw LIBRAW_EXCEPTION_IO_EOF; + return c; + } + unsigned _gethuff(LibRaw_byte_buffer* buf, int nbits, unsigned short* huff, int zer0_ff) + { + unsigned c; + if(nbits==0 || vbits < 0) return 0; + fill(buf,nbits,zer0_ff); + c = bitbuf << (32-vbits) >> (32-nbits); + vbits -= huff[c] >> 8; + c = (uchar) huff[c]; + if(vbits<0)throw LIBRAW_EXCEPTION_IO_EOF; + return c; + } +#endif +}; diff --git a/Source/LibRawLite/internal/libraw_internal_funcs.h b/Source/LibRawLite/internal/libraw_internal_funcs.h index e8847af..88ce5da 100644 --- a/Source/LibRawLite/internal/libraw_internal_funcs.h +++ b/Source/LibRawLite/internal/libraw_internal_funcs.h @@ -1,241 +1,241 @@ -/* -*- C++ -*- - * File: libraw_internal_funcs.h - * Copyright 2008-2009 LibRaw LLC (info@libraw.org) - * Created: Sat Mar 14, 2008 - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - - */ - -#ifndef _LIBRAW_INTERNAL_FUNCS_H -#define _LIBRAW_INTERNAL_FUNCS_H - -#ifndef LIBRAW_LIBRARY_BUILD -#error "This file should be used only for libraw library build" -#else -// inline functions - ushort sget2 (uchar *s); - ushort get2(); - unsigned sget4 (uchar *s); - unsigned getint (int type); - float int_to_float (int i); - double getreal (int type); - void read_shorts (ushort *pixel, int count); - -// Canon P&S cameras - void canon_600_fixed_wb (int temp); - int canon_600_color (int ratio[2], int mar); - void canon_600_auto_wb(); - void canon_600_coeff(); - void canon_600_load_raw(); - int canon_s2is(); - void parse_ciff (int offset, int length); - void ciff_block_1030(); - -// LJPEG decoder - unsigned getbithuff (int nbits, ushort *huff); - ushort* make_decoder_ref (const uchar **source); - ushort* make_decoder (const uchar *source); - int ljpeg_start (struct jhead *jh, int info_only); - void ljpeg_end(struct jhead *jh); - int ljpeg_diff (ushort *huff); - int ljpeg_diff_new (LibRaw_bit_buffer& bits, LibRaw_byte_buffer* buf,ushort *huff); - int ljpeg_diff_pef (LibRaw_bit_buffer& bits, LibRaw_byte_buffer* buf,ushort *huff); - ushort * ljpeg_row (int jrow, struct jhead *jh); - ushort * ljpeg_row_new (int jrow, struct jhead *jh, LibRaw_bit_buffer& bits,LibRaw_byte_buffer* bytes); - - unsigned ph1_bithuff (int nbits, ushort *huff); - -// Canon DSLRs -void crw_init_tables (unsigned table, ushort *huff[2]); - int canon_has_lowbits(); - void canon_compressed_load_raw(); - void lossless_jpeg_load_raw(); - void canon_sraw_load_raw(); -// Adobe DNG - void adobe_copy_pixel (int row, int col, ushort **rp); - void adobe_dng_load_raw_lj(); - void adobe_dng_load_raw_nc(); - -// Pentax - void pentax_load_raw(); - void pentax_tree(); - -// Nikon (and Minolta Z2) - void nikon_compressed_load_raw(); - void nikon_load_raw(); - int nikon_is_compressed(); - int nikon_e995(); - int nikon_e2100(); - void nikon_3700(); - int minolta_z2(); - void nikon_e2100_load_raw(); - -// Fuji - void fuji_load_raw(); - void parse_fuji (int offset); - -// RedCine - void parse_redcine(); - void redcine_load_raw(); - -// Rollei - void rollei_load_raw(); - void parse_rollei(); - -// MF backs - int bayer (unsigned row, unsigned col); - void phase_one_flat_field (int is_float, int nc); - void phase_one_correct(); - void phase_one_load_raw(); - unsigned ph1_bits (int nbits); - void phase_one_load_raw_c(); - void hasselblad_load_raw(); - void leaf_hdr_load_raw(); - void sinar_4shot_load_raw(); - void imacon_full_load_raw(); - void packed_load_raw(); - float find_green(int,int,int,int); - void unpacked_load_raw(); - void parse_sinar_ia(); - void parse_phase_one (int base); - -// Misc P&S cameras - void nokia_load_raw(); - unsigned pana_bits (int nbits); - void panasonic_load_raw(); - void olympus_load_raw(); - void olympus_cseries_load_raw(); - void minolta_rd175_load_raw(); - void quicktake_100_load_raw(); - const int* make_decoder_int (const int *source, int level); - int radc_token (int tree); - void kodak_radc_load_raw(); - void kodak_jpeg_load_raw(); - void kodak_dc120_load_raw(); - void eight_bit_load_raw(); - void smal_decode_segment (unsigned seg[2][2], int holes); - void smal_v6_load_raw(); - int median4 (int *p); - void fill_holes (int holes); - void smal_v9_load_raw(); - void parse_riff(); - void parse_cine(); - void parse_smal (int offset, int fsize); - int parse_jpeg (int offset); - -// Kodak - void kodak_262_load_raw(); - int kodak_65000_decode (short *out, int bsize); - void kodak_65000_load_raw(); - void kodak_rgb_load_raw(); - void kodak_yrgb_load_raw(); - void kodak_ycbcr_load_raw(); - void kodak_rgb_load_thumb(); - void kodak_ycbcr_load_thumb(); - -// It's a Sony (and K&M) - void sony_decrypt (unsigned *data, int len, int start, int key); - void sony_load_raw(); - void sony_arw_load_raw(); - void sony_arw2_load_raw(); - void parse_minolta (int base); - -// Foveon/Sigma - void foveon_load_camf(); - void foveon_load_raw(); - const char* foveon_camf_param (const char *block, const char *param); - void * foveon_camf_matrix (unsigned dim[3], const char *name); - int foveon_fixed (void *ptr, int size, const char *name); - float foveon_avg (short *pix, int range[2], float cfilt); - short * foveon_make_curve (double max, double mul, double filt); - void foveon_make_curves(short **curvep, float dq[3], float div[3], float filt); - int foveon_apply_curve (short *curve, int i); - void foveon_interpolate(); - char * foveon_gets (int offset, char *str, int len); - void parse_foveon(); - -// CAM/RGB - void pseudoinverse (double (*in)[3], double (*out)[3], int size); - void cam_xyz_coeff (double cam_xyz[4][3]); - void adobe_coeff (const char *, const char *); - void simple_coeff (int index); - - -// Tiff/Exif parsers - void tiff_get (unsigned base,unsigned *tag, unsigned *type, unsigned *len, unsigned *save); - void parse_thumb_note (int base, unsigned toff, unsigned tlen); - void parse_makernote (int base, int uptag); - void parse_exif (int base); - void linear_table (unsigned len); - void parse_kodak_ifd (int base); - int parse_tiff_ifd (int base); - int parse_tiff (int base); - void apply_tiff(void); - void parse_gps (int base); - void romm_coeff (float romm_cam[3][3]); - void parse_mos (int offset); - void get_timestamp (int reversed); - -// External JPEGs, what cameras uses it ? - void parse_external_jpeg(); - -// The identify - short guess_byte_order (int words); - -// Tiff writer - void tiff_set (ushort *ntag, ushort tag, ushort type, int count, int val); - void tiff_head (struct tiff_hdr *th, int full); - -// splitted AHD code -#define TS 256 - void ahd_interpolate_green_h_and_v(int top, int left, ushort (*out_rgb)[TS][TS][3]); - void ahd_interpolate_r_and_b_in_rgb_and_convert_to_cielab(int top, int left, ushort (*inout_rgb)[TS][3], short (*out_lab)[TS][3], const float (&xyz_cam)[3][4]); - void ahd_interpolate_r_and_b_and_convert_to_cielab(int top, int left, ushort (*inout_rgb)[TS][TS][3], short (*out_lab)[TS][TS][3], const float (&xyz_cam)[3][4]); - void ahd_interpolate_build_homogeneity_map(int top, int left, short (*lab)[TS][TS][3], char (*out_homogeneity_map)[TS][2]); - void ahd_interpolate_combine_homogeneous_pixels(int top, int left, ushort (*rgb)[TS][TS][3], char (*homogeneity_map)[TS][2]); - -#undef TS - -// LibRaw demosaic packs functions -// AMaZe - int LinEqSolve(int, float*, float*, float*); -// DCB - void dcb_pp(); - void dcb_copy_to_buffer(float (*image2)[3]); - void dcb_restore_from_buffer(float (*image2)[3]); - void dcb_color(); - void dcb_color_full(); - void dcb_map(); - void dcb_correction(); - void dcb_correction2(); - void dcb_refinement(); - void rgb_to_lch(double (*image3)[3]); - void lch_to_rgb(double (*image3)[3]); - void fbdd_correction(); - void fbdd_correction2(double (*image3)[3]); - void fbdd_green(); - void dcb_ver(float (*image3)[3]); - void dcb_hor(float (*image2)[3]); - void dcb_color2(float (*image2)[3]); - void dcb_color3(float (*image3)[3]); - void dcb_decide(float (*image2)[3], float (*image3)[3]); - void dcb_nyquist(); -// VCD/modified dcraw - void refinement(); - void ahd_partial_interpolate(int threshold_value); - void es_median_filter(); - void median_filter_new(); -#endif - -#endif +/* -*- C++ -*- + * File: libraw_internal_funcs.h + * Copyright 2008-2009 LibRaw LLC (info@libraw.org) + * Created: Sat Mar 14, 2008 + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + + */ + +#ifndef _LIBRAW_INTERNAL_FUNCS_H +#define _LIBRAW_INTERNAL_FUNCS_H + +#ifndef LIBRAW_LIBRARY_BUILD +#error "This file should be used only for libraw library build" +#else +// inline functions + ushort sget2 (uchar *s); + ushort get2(); + unsigned sget4 (uchar *s); + unsigned getint (int type); + float int_to_float (int i); + double getreal (int type); + void read_shorts (ushort *pixel, int count); + +// Canon P&S cameras + void canon_600_fixed_wb (int temp); + int canon_600_color (int ratio[2], int mar); + void canon_600_auto_wb(); + void canon_600_coeff(); + void canon_600_load_raw(); + int canon_s2is(); + void parse_ciff (int offset, int length); + void ciff_block_1030(); + +// LJPEG decoder + unsigned getbithuff (int nbits, ushort *huff); + ushort* make_decoder_ref (const uchar **source); + ushort* make_decoder (const uchar *source); + int ljpeg_start (struct jhead *jh, int info_only); + void ljpeg_end(struct jhead *jh); + int ljpeg_diff (ushort *huff); + int ljpeg_diff_new (LibRaw_bit_buffer& bits, LibRaw_byte_buffer* buf,ushort *huff); + int ljpeg_diff_pef (LibRaw_bit_buffer& bits, LibRaw_byte_buffer* buf,ushort *huff); + ushort * ljpeg_row (int jrow, struct jhead *jh); + ushort * ljpeg_row_new (int jrow, struct jhead *jh, LibRaw_bit_buffer& bits,LibRaw_byte_buffer* bytes); + + unsigned ph1_bithuff (int nbits, ushort *huff); + +// Canon DSLRs +void crw_init_tables (unsigned table, ushort *huff[2]); + int canon_has_lowbits(); + void canon_compressed_load_raw(); + void lossless_jpeg_load_raw(); + void canon_sraw_load_raw(); +// Adobe DNG + void adobe_copy_pixel (int row, int col, ushort **rp); + void adobe_dng_load_raw_lj(); + void adobe_dng_load_raw_nc(); + +// Pentax + void pentax_load_raw(); + void pentax_tree(); + +// Nikon (and Minolta Z2) + void nikon_compressed_load_raw(); + void nikon_load_raw(); + int nikon_is_compressed(); + int nikon_e995(); + int nikon_e2100(); + void nikon_3700(); + int minolta_z2(); + void nikon_e2100_load_raw(); + +// Fuji + void fuji_load_raw(); + void parse_fuji (int offset); + +// RedCine + void parse_redcine(); + void redcine_load_raw(); + +// Rollei + void rollei_load_raw(); + void parse_rollei(); + +// MF backs + int bayer (unsigned row, unsigned col); + void phase_one_flat_field (int is_float, int nc); + void phase_one_correct(); + void phase_one_load_raw(); + unsigned ph1_bits (int nbits); + void phase_one_load_raw_c(); + void hasselblad_load_raw(); + void leaf_hdr_load_raw(); + void sinar_4shot_load_raw(); + void imacon_full_load_raw(); + void packed_load_raw(); + float find_green(int,int,int,int); + void unpacked_load_raw(); + void parse_sinar_ia(); + void parse_phase_one (int base); + +// Misc P&S cameras + void nokia_load_raw(); + unsigned pana_bits (int nbits); + void panasonic_load_raw(); + void olympus_load_raw(); + void olympus_cseries_load_raw(); + void minolta_rd175_load_raw(); + void quicktake_100_load_raw(); + const int* make_decoder_int (const int *source, int level); + int radc_token (int tree); + void kodak_radc_load_raw(); + void kodak_jpeg_load_raw(); + void kodak_dc120_load_raw(); + void eight_bit_load_raw(); + void smal_decode_segment (unsigned seg[2][2], int holes); + void smal_v6_load_raw(); + int median4 (int *p); + void fill_holes (int holes); + void smal_v9_load_raw(); + void parse_riff(); + void parse_cine(); + void parse_smal (int offset, int fsize); + int parse_jpeg (int offset); + +// Kodak + void kodak_262_load_raw(); + int kodak_65000_decode (short *out, int bsize); + void kodak_65000_load_raw(); + void kodak_rgb_load_raw(); + void kodak_yrgb_load_raw(); + void kodak_ycbcr_load_raw(); + void kodak_rgb_load_thumb(); + void kodak_ycbcr_load_thumb(); + +// It's a Sony (and K&M) + void sony_decrypt (unsigned *data, int len, int start, int key); + void sony_load_raw(); + void sony_arw_load_raw(); + void sony_arw2_load_raw(); + void parse_minolta (int base); + +// Foveon/Sigma + void foveon_load_camf(); + void foveon_load_raw(); + const char* foveon_camf_param (const char *block, const char *param); + void * foveon_camf_matrix (unsigned dim[3], const char *name); + int foveon_fixed (void *ptr, int size, const char *name); + float foveon_avg (short *pix, int range[2], float cfilt); + short * foveon_make_curve (double max, double mul, double filt); + void foveon_make_curves(short **curvep, float dq[3], float div[3], float filt); + int foveon_apply_curve (short *curve, int i); + void foveon_interpolate(); + char * foveon_gets (int offset, char *str, int len); + void parse_foveon(); + +// CAM/RGB + void pseudoinverse (double (*in)[3], double (*out)[3], int size); + void cam_xyz_coeff (double cam_xyz[4][3]); + void adobe_coeff (const char *, const char *); + void simple_coeff (int index); + + +// Tiff/Exif parsers + void tiff_get (unsigned base,unsigned *tag, unsigned *type, unsigned *len, unsigned *save); + void parse_thumb_note (int base, unsigned toff, unsigned tlen); + void parse_makernote (int base, int uptag); + void parse_exif (int base); + void linear_table (unsigned len); + void parse_kodak_ifd (int base); + int parse_tiff_ifd (int base); + int parse_tiff (int base); + void apply_tiff(void); + void parse_gps (int base); + void romm_coeff (float romm_cam[3][3]); + void parse_mos (int offset); + void get_timestamp (int reversed); + +// External JPEGs, what cameras uses it ? + void parse_external_jpeg(); + +// The identify + short guess_byte_order (int words); + +// Tiff writer + void tiff_set (ushort *ntag, ushort tag, ushort type, int count, int val); + void tiff_head (struct tiff_hdr *th, int full); + +// splitted AHD code +#define TS 256 + void ahd_interpolate_green_h_and_v(int top, int left, ushort (*out_rgb)[TS][TS][3]); + void ahd_interpolate_r_and_b_in_rgb_and_convert_to_cielab(int top, int left, ushort (*inout_rgb)[TS][3], short (*out_lab)[TS][3], const float (&xyz_cam)[3][4]); + void ahd_interpolate_r_and_b_and_convert_to_cielab(int top, int left, ushort (*inout_rgb)[TS][TS][3], short (*out_lab)[TS][TS][3], const float (&xyz_cam)[3][4]); + void ahd_interpolate_build_homogeneity_map(int top, int left, short (*lab)[TS][TS][3], char (*out_homogeneity_map)[TS][2]); + void ahd_interpolate_combine_homogeneous_pixels(int top, int left, ushort (*rgb)[TS][TS][3], char (*homogeneity_map)[TS][2]); + +#undef TS + +// LibRaw demosaic packs functions +// AMaZe + int LinEqSolve(int, float*, float*, float*); +// DCB + void dcb_pp(); + void dcb_copy_to_buffer(float (*image2)[3]); + void dcb_restore_from_buffer(float (*image2)[3]); + void dcb_color(); + void dcb_color_full(); + void dcb_map(); + void dcb_correction(); + void dcb_correction2(); + void dcb_refinement(); + void rgb_to_lch(double (*image3)[3]); + void lch_to_rgb(double (*image3)[3]); + void fbdd_correction(); + void fbdd_correction2(double (*image3)[3]); + void fbdd_green(); + void dcb_ver(float (*image3)[3]); + void dcb_hor(float (*image2)[3]); + void dcb_color2(float (*image2)[3]); + void dcb_color3(float (*image3)[3]); + void dcb_decide(float (*image2)[3], float (*image3)[3]); + void dcb_nyquist(); +// VCD/modified dcraw + void refinement(); + void ahd_partial_interpolate(int threshold_value); + void es_median_filter(); + void median_filter_new(); +#endif + +#endif diff --git a/Source/LibRawLite/internal/var_defines.h b/Source/LibRawLite/internal/var_defines.h index 6c91654..ba60b2f 100644 --- a/Source/LibRawLite/internal/var_defines.h +++ b/Source/LibRawLite/internal/var_defines.h @@ -1,206 +1,206 @@ -/* -*- C++ -*- - * File: var_defines.h - * Copyright 2008-2009 LibRaw LLC (info@libraw.org) - * Created: Sat Mar 8, 2008 - * - * LibRaw redefinitions of dcraw internal variables - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - */ - -#ifndef VAR_DEFINES_H -#define VAR_DEFINES_H - -// imgdata.idata -#define make (imgdata.idata.make) -#define model (imgdata.idata.model) -#define is_raw (imgdata.idata.raw_count) -#define dng_version (imgdata.idata.dng_version) -#define is_foveon (imgdata.idata.is_foveon) -#define colors (imgdata.idata.colors) -#define cdesc (imgdata.idata.cdesc) -#define filters (imgdata.idata.filters) - -//imgdata image -#define image (imgdata.image) -#define raw_image (imgdata.rawdata.raw_image) -#define color_image (imgdata.rawdata.color_image) - -// imgdata.sizes -#define raw_height (imgdata.sizes.raw_height) -#define raw_width (imgdata.sizes.raw_width) -#define height (imgdata.sizes.height) -#define width (imgdata.sizes.width) -#define top_margin (imgdata.sizes.top_margin) -#define left_margin (imgdata.sizes.left_margin) -#define bottom_margin (imgdata.sizes.bottom_margin) -#define right_margin (imgdata.sizes.right_margin) -#define iheight (imgdata.sizes.iheight) -#define iwidth (imgdata.sizes.iwidth) -#define pixel_aspect (imgdata.sizes.pixel_aspect) -#define flip (imgdata.sizes.flip) - -//imgdata.color -#define white (imgdata.color.white) -#define cam_mul (imgdata.color.cam_mul) -#define pre_mul (imgdata.color.pre_mul) -#define cmatrix (imgdata.color.cmatrix) -#define rgb_cam (imgdata.color.rgb_cam) -#ifndef SRC_USES_CURVE -#define curve (imgdata.color.curve) -#endif -#ifndef SRC_USES_BLACK -#define black (imgdata.color.black) -#define cblack (imgdata.color.cblack) -#endif -#define maximum (imgdata.color.maximum) -#define channel_maximum (imgdata.color.channel_maximum) -#define profile_length (imgdata.color.profile_length) -#define color_flags (imgdata.color.color_flags) -#define ph1 (imgdata.color.phase_one_data) -#define flash_used (imgdata.color.flash_used) -#define canon_ev (imgdata.color.canon_ev) -#define model2 (imgdata.color.model2) - -//imgdata.thumbnail - -#define thumb_width (imgdata.thumbnail.twidth) -#define thumb_height (imgdata.thumbnail.theight) -#define thumb_length (imgdata.thumbnail.tlength) - - -//imgdata.others -#define iso_speed (imgdata.other.iso_speed) -#define shutter (imgdata.other.shutter) -#define aperture (imgdata.other.aperture) -#define focal_len (imgdata.other.focal_len) -#define timestamp (imgdata.other.timestamp) -#define shot_order (imgdata.other.shot_order) -#define gpsdata (imgdata.other.gpsdata) -#define desc (imgdata.other.desc) -#define artist (imgdata.other.artist) - -//imgdata.output -#define greybox (imgdata.params.greybox) -#define cropbox (imgdata.params.cropbox) -#define aber (imgdata.params.aber) -#define gamm (imgdata.params.gamm) -#define user_mul (imgdata.params.user_mul) -#define shot_select (imgdata.params.shot_select) -#define bright (imgdata.params.bright) -#define threshold (imgdata.params.threshold) -#define half_size (imgdata.params.half_size) -#define four_color_rgb (imgdata.params.four_color_rgb) -#define document_mode (imgdata.params.document_mode) -#define highlight (imgdata.params.highlight) -//#define verbose (imgdata.params.verbose) -#define use_auto_wb (imgdata.params.use_auto_wb) -#define use_camera_wb (imgdata.params.use_camera_wb) -#define use_camera_matrix (imgdata.params.use_camera_matrix) -#define output_color (imgdata.params.output_color) -#define output_bps (imgdata.params.output_bps) -#define gamma_16bit (imgdata.params.gamma_16bit) -#define output_tiff (imgdata.params.output_tiff) -#define med_passes (imgdata.params.med_passes) -#define no_auto_bright (imgdata.params.no_auto_bright) -#define use_fuji_rotate (imgdata.params.use_fuji_rotate) -#define filtering_mode (imgdata.params.filtering_mode) - -// Demosaic packs -//AFD -//#define afd_noise_att (imgdata.params.afd_noise_att) -//#define afd_noise_thres (imgdata.params.afd_noise_thres) -//#define afd_luminance_passes (imgdata.params.afd_luminance_passes) -//#define afd_chrominance_method (imgdata.params.afd_chrominance_method) -//#define afd_luminance_only (imgdata.params.afd_luminance_only) -// DCB -#define dcb_iterations (imgdata.params.iterations) -#define dcb_enhance_fl (imgdata.params.dcb_enhance) -#define fbdd_noiserd (imgdata.params.fbdd_noiserd) -// VCD -#define eeci_refine (imgdata.params.eeci_refine) -#define es_med_passes (imgdata.params.es_med_passes) - - - -//rgb_constants -#define xyz_rgb (rgb_constants.xyz_rgb) -#define d65_white (rgb_constants.d65_white) - -//libraw_internal_data.internal_data -#define meta_data (libraw_internal_data.internal_data.meta_data) -#define ifp libraw_internal_data.internal_data.input -#define ifname ((char*)libraw_internal_data.internal_data.input->fname()) -#define ofp libraw_internal_data.internal_data.output -#define profile_offset (libraw_internal_data.internal_data.profile_offset) -#define thumb_offset (libraw_internal_data.internal_data.toffset) - -//libraw_internal_data.internal_output_params -#define mix_green (libraw_internal_data.internal_output_params.mix_green) -#define raw_color (libraw_internal_data.internal_output_params.raw_color) -#define use_gamma (libraw_internal_data.internal_output_params.use_gamma) -#define zero_is_bad (libraw_internal_data.internal_output_params.zero_is_bad) -#ifndef SRC_USES_SHRINK -#define shrink (libraw_internal_data.internal_output_params.shrink) -#endif -#define fuji_width (libraw_internal_data.internal_output_params.fuji_width) - - -//libraw_internal_data.output_data -#define histogram (libraw_internal_data.output_data.histogram) -#define oprof (libraw_internal_data.output_data.oprof) - -//libraw_internal_data.identify_data -#define exif_cfa (libraw_internal_data.identify_data.olympus_exif_cfa) -#define unique_id (libraw_internal_data.identify_data.unique_id) -#define tiff_nifds (libraw_internal_data.identify_data.tiff_nifds) -#define tiff_flip (libraw_internal_data.identify_data.tiff_flip) - -//libraw_internal_data.unpacker_data -#define order (libraw_internal_data.unpacker_data.order) -#define data_error (libraw_internal_data.unpacker_data.data_error) -#define cr2_slice (libraw_internal_data.unpacker_data.cr2_slice) -#define sraw_mul (libraw_internal_data.unpacker_data.sraw_mul) -#define kodak_cbpp (libraw_internal_data.unpacker_data.kodak_cbpp) -#define strip_offset (libraw_internal_data.unpacker_data.strip_offset) -#define data_offset (libraw_internal_data.unpacker_data.data_offset) -#define data_size (libraw_internal_data.unpacker_data.data_size) -#define meta_offset (libraw_internal_data.unpacker_data.meta_offset) -#define meta_length (libraw_internal_data.unpacker_data.meta_length) -#define thumb_misc (libraw_internal_data.unpacker_data.thumb_misc) -#define fuji_layout (libraw_internal_data.unpacker_data.fuji_layout) -#define tiff_samples (libraw_internal_data.unpacker_data.tiff_samples) -#define tiff_bps (libraw_internal_data.unpacker_data.tiff_bps) -#define tiff_compress (libraw_internal_data.unpacker_data.tiff_compress) -#define zero_after_ff (libraw_internal_data.unpacker_data.zero_after_ff) -#define tile_width (libraw_internal_data.unpacker_data.tile_width) -#define tile_length (libraw_internal_data.unpacker_data.tile_length) -#define load_flags (libraw_internal_data.unpacker_data.load_flags) - -#ifdef LIBRAW_IO_REDEFINED -#define fread(ptr,size,n,stream) stream->read(ptr,size,n) -#define fseek(stream,o,w) stream->seek(o,w) -#define fseeko(stream,o,w) stream->seek(o,w) -#define ftell(stream) stream->tell() -#define ftello(stream) stream->tell() -#ifdef getc -#undef getc -#endif -#define getc(stream) stream->get_char() -#define fgetc(stream) stream->get_char() -#define fgetcb(stream) stream->get_char_buf() -#define fgets(str,n,stream) stream->gets(str,n) -#define fscanf(stream,fmt,ptr) stream->scanf_one(fmt,ptr) -#endif - -#endif +/* -*- C++ -*- + * File: var_defines.h + * Copyright 2008-2009 LibRaw LLC (info@libraw.org) + * Created: Sat Mar 8, 2008 + * + * LibRaw redefinitions of dcraw internal variables + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + */ + +#ifndef VAR_DEFINES_H +#define VAR_DEFINES_H + +// imgdata.idata +#define make (imgdata.idata.make) +#define model (imgdata.idata.model) +#define is_raw (imgdata.idata.raw_count) +#define dng_version (imgdata.idata.dng_version) +#define is_foveon (imgdata.idata.is_foveon) +#define colors (imgdata.idata.colors) +#define cdesc (imgdata.idata.cdesc) +#define filters (imgdata.idata.filters) + +//imgdata image +#define image (imgdata.image) +#define raw_image (imgdata.rawdata.raw_image) +#define color_image (imgdata.rawdata.color_image) + +// imgdata.sizes +#define raw_height (imgdata.sizes.raw_height) +#define raw_width (imgdata.sizes.raw_width) +#define height (imgdata.sizes.height) +#define width (imgdata.sizes.width) +#define top_margin (imgdata.sizes.top_margin) +#define left_margin (imgdata.sizes.left_margin) +#define bottom_margin (imgdata.sizes.bottom_margin) +#define right_margin (imgdata.sizes.right_margin) +#define iheight (imgdata.sizes.iheight) +#define iwidth (imgdata.sizes.iwidth) +#define pixel_aspect (imgdata.sizes.pixel_aspect) +#define flip (imgdata.sizes.flip) + +//imgdata.color +#define white (imgdata.color.white) +#define cam_mul (imgdata.color.cam_mul) +#define pre_mul (imgdata.color.pre_mul) +#define cmatrix (imgdata.color.cmatrix) +#define rgb_cam (imgdata.color.rgb_cam) +#ifndef SRC_USES_CURVE +#define curve (imgdata.color.curve) +#endif +#ifndef SRC_USES_BLACK +#define black (imgdata.color.black) +#define cblack (imgdata.color.cblack) +#endif +#define maximum (imgdata.color.maximum) +#define channel_maximum (imgdata.color.channel_maximum) +#define profile_length (imgdata.color.profile_length) +#define color_flags (imgdata.color.color_flags) +#define ph1 (imgdata.color.phase_one_data) +#define flash_used (imgdata.color.flash_used) +#define canon_ev (imgdata.color.canon_ev) +#define model2 (imgdata.color.model2) + +//imgdata.thumbnail + +#define thumb_width (imgdata.thumbnail.twidth) +#define thumb_height (imgdata.thumbnail.theight) +#define thumb_length (imgdata.thumbnail.tlength) + + +//imgdata.others +#define iso_speed (imgdata.other.iso_speed) +#define shutter (imgdata.other.shutter) +#define aperture (imgdata.other.aperture) +#define focal_len (imgdata.other.focal_len) +#define timestamp (imgdata.other.timestamp) +#define shot_order (imgdata.other.shot_order) +#define gpsdata (imgdata.other.gpsdata) +#define desc (imgdata.other.desc) +#define artist (imgdata.other.artist) + +//imgdata.output +#define greybox (imgdata.params.greybox) +#define cropbox (imgdata.params.cropbox) +#define aber (imgdata.params.aber) +#define gamm (imgdata.params.gamm) +#define user_mul (imgdata.params.user_mul) +#define shot_select (imgdata.params.shot_select) +#define bright (imgdata.params.bright) +#define threshold (imgdata.params.threshold) +#define half_size (imgdata.params.half_size) +#define four_color_rgb (imgdata.params.four_color_rgb) +#define document_mode (imgdata.params.document_mode) +#define highlight (imgdata.params.highlight) +//#define verbose (imgdata.params.verbose) +#define use_auto_wb (imgdata.params.use_auto_wb) +#define use_camera_wb (imgdata.params.use_camera_wb) +#define use_camera_matrix (imgdata.params.use_camera_matrix) +#define output_color (imgdata.params.output_color) +#define output_bps (imgdata.params.output_bps) +#define gamma_16bit (imgdata.params.gamma_16bit) +#define output_tiff (imgdata.params.output_tiff) +#define med_passes (imgdata.params.med_passes) +#define no_auto_bright (imgdata.params.no_auto_bright) +#define use_fuji_rotate (imgdata.params.use_fuji_rotate) +#define filtering_mode (imgdata.params.filtering_mode) + +// Demosaic packs +//AFD +//#define afd_noise_att (imgdata.params.afd_noise_att) +//#define afd_noise_thres (imgdata.params.afd_noise_thres) +//#define afd_luminance_passes (imgdata.params.afd_luminance_passes) +//#define afd_chrominance_method (imgdata.params.afd_chrominance_method) +//#define afd_luminance_only (imgdata.params.afd_luminance_only) +// DCB +#define dcb_iterations (imgdata.params.iterations) +#define dcb_enhance_fl (imgdata.params.dcb_enhance) +#define fbdd_noiserd (imgdata.params.fbdd_noiserd) +// VCD +#define eeci_refine (imgdata.params.eeci_refine) +#define es_med_passes (imgdata.params.es_med_passes) + + + +//rgb_constants +#define xyz_rgb (rgb_constants.xyz_rgb) +#define d65_white (rgb_constants.d65_white) + +//libraw_internal_data.internal_data +#define meta_data (libraw_internal_data.internal_data.meta_data) +#define ifp libraw_internal_data.internal_data.input +#define ifname ((char*)libraw_internal_data.internal_data.input->fname()) +#define ofp libraw_internal_data.internal_data.output +#define profile_offset (libraw_internal_data.internal_data.profile_offset) +#define thumb_offset (libraw_internal_data.internal_data.toffset) + +//libraw_internal_data.internal_output_params +#define mix_green (libraw_internal_data.internal_output_params.mix_green) +#define raw_color (libraw_internal_data.internal_output_params.raw_color) +#define use_gamma (libraw_internal_data.internal_output_params.use_gamma) +#define zero_is_bad (libraw_internal_data.internal_output_params.zero_is_bad) +#ifndef SRC_USES_SHRINK +#define shrink (libraw_internal_data.internal_output_params.shrink) +#endif +#define fuji_width (libraw_internal_data.internal_output_params.fuji_width) + + +//libraw_internal_data.output_data +#define histogram (libraw_internal_data.output_data.histogram) +#define oprof (libraw_internal_data.output_data.oprof) + +//libraw_internal_data.identify_data +#define exif_cfa (libraw_internal_data.identify_data.olympus_exif_cfa) +#define unique_id (libraw_internal_data.identify_data.unique_id) +#define tiff_nifds (libraw_internal_data.identify_data.tiff_nifds) +#define tiff_flip (libraw_internal_data.identify_data.tiff_flip) + +//libraw_internal_data.unpacker_data +#define order (libraw_internal_data.unpacker_data.order) +#define data_error (libraw_internal_data.unpacker_data.data_error) +#define cr2_slice (libraw_internal_data.unpacker_data.cr2_slice) +#define sraw_mul (libraw_internal_data.unpacker_data.sraw_mul) +#define kodak_cbpp (libraw_internal_data.unpacker_data.kodak_cbpp) +#define strip_offset (libraw_internal_data.unpacker_data.strip_offset) +#define data_offset (libraw_internal_data.unpacker_data.data_offset) +#define data_size (libraw_internal_data.unpacker_data.data_size) +#define meta_offset (libraw_internal_data.unpacker_data.meta_offset) +#define meta_length (libraw_internal_data.unpacker_data.meta_length) +#define thumb_misc (libraw_internal_data.unpacker_data.thumb_misc) +#define fuji_layout (libraw_internal_data.unpacker_data.fuji_layout) +#define tiff_samples (libraw_internal_data.unpacker_data.tiff_samples) +#define tiff_bps (libraw_internal_data.unpacker_data.tiff_bps) +#define tiff_compress (libraw_internal_data.unpacker_data.tiff_compress) +#define zero_after_ff (libraw_internal_data.unpacker_data.zero_after_ff) +#define tile_width (libraw_internal_data.unpacker_data.tile_width) +#define tile_length (libraw_internal_data.unpacker_data.tile_length) +#define load_flags (libraw_internal_data.unpacker_data.load_flags) + +#ifdef LIBRAW_IO_REDEFINED +#define fread(ptr,size,n,stream) stream->read(ptr,size,n) +#define fseek(stream,o,w) stream->seek(o,w) +#define fseeko(stream,o,w) stream->seek(o,w) +#define ftell(stream) stream->tell() +#define ftello(stream) stream->tell() +#ifdef getc +#undef getc +#endif +#define getc(stream) stream->get_char() +#define fgetc(stream) stream->get_char() +#define fgetcb(stream) stream->get_char_buf() +#define fgets(str,n,stream) stream->gets(str,n) +#define fscanf(stream,fmt,ptr) stream->scanf_one(fmt,ptr) +#endif + +#endif diff --git a/Source/LibRawLite/libraw/libraw.h b/Source/LibRawLite/libraw/libraw.h index 8091c21..bf9df7e 100644 --- a/Source/LibRawLite/libraw/libraw.h +++ b/Source/LibRawLite/libraw/libraw.h @@ -1,269 +1,269 @@ -/* -*- C++ -*- - * File: libraw.h - * Copyright 2008-2010 LibRaw LLC (info@libraw.org) - * Created: Sat Mar 8, 2008 - * - * LibRaw C++ interface - * - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - -*/ - -#ifndef _LIBRAW_CLASS_H -#define _LIBRAW_CLASS_H - -#ifdef __linux__ -#define _FILE_OFFSET_BITS 64 -#endif - -/* maximum file size to use LibRaw_file_datastream (fully buffered) I/O */ -#define LIBRAW_USE_STREAMS_DATASTREAM_MAXSIZE (250*1024L*1024L) - - -#include -#include -#include -#include - - -#include "libraw_datastream.h" -#include "libraw_types.h" -#include "libraw_const.h" -#include "libraw_internal.h" -#include "libraw_alloc.h" - -#ifdef __cplusplus -extern "C" -{ -#endif -DllDef const char *libraw_strerror(int errorcode); -DllDef const char *libraw_strprogress(enum LibRaw_progress); - /* LibRaw C API */ -DllDef libraw_data_t *libraw_init(unsigned int flags); -DllDef int libraw_open_file(libraw_data_t*, const char *); -DllDef int libraw_open_file_ex(libraw_data_t*, const char *, INT64 max_buff_sz); -DllDef int libraw_open_buffer(libraw_data_t*, void * buffer, size_t size); -DllDef int libraw_unpack(libraw_data_t*); -DllDef int libraw_unpack_thumb(libraw_data_t*); -DllDef void libraw_recycle(libraw_data_t*); -DllDef void libraw_close(libraw_data_t*); -DllDef void libraw_subtract_black(libraw_data_t*); -DllDef int libraw_raw2image(libraw_data_t*); -DllDef void libraw_free_image(libraw_data_t*); - /* version helpers */ -DllDef const char* libraw_version(); -DllDef int libraw_versionNumber(); - /* Camera list */ -DllDef const char** libraw_cameraList(); -DllDef int libraw_cameraCount(); - -DllDef void libraw_set_memerror_handler(libraw_data_t*, memory_callback cb, void *datap); -DllDef void libraw_set_dataerror_handler(libraw_data_t*,data_callback func,void *datap); -DllDef void libraw_set_progress_handler(libraw_data_t*,progress_callback cb,void *datap); -DllDef const char * libraw_unpack_function_name(libraw_data_t* lr); -DllDef int libraw_get_decoder_info(libraw_data_t* lr,libraw_decoder_info_t* d); - - /* DCRAW compatibility */ -DllDef int libraw_adjust_sizes_info_only(libraw_data_t*); -DllDef int libraw_dcraw_document_mode_processing(libraw_data_t*); -DllDef int libraw_dcraw_ppm_tiff_writer(libraw_data_t* lr,const char *filename); -DllDef int libraw_dcraw_thumb_writer(libraw_data_t* lr,const char *fname); -DllDef int libraw_dcraw_process(libraw_data_t* lr); -DllDef libraw_processed_image_t* libraw_dcraw_make_mem_image(libraw_data_t* lr, int *errc); -DllDef libraw_processed_image_t* libraw_dcraw_make_mem_thumb(libraw_data_t* lr, int *errc); -DllDef void libraw_dcraw_clear_mem(libraw_processed_image_t*); -#ifdef __cplusplus -} -#endif - - -#ifdef __cplusplus - -class DllDef LibRaw -{ - public: - libraw_data_t imgdata; - int verbose; - - LibRaw(unsigned int flags = LIBRAW_OPTIONS_NONE); - - libraw_output_params_t* output_params_ptr() { return &imgdata.params;} - int open_file(const char *fname, INT64 max_buffered_sz=LIBRAW_USE_STREAMS_DATASTREAM_MAXSIZE); - int open_buffer(void *buffer, size_t size); - int open_datastream(LibRaw_abstract_datastream *); - int unpack(void); - int unpack_thumb(void); - - int adjust_sizes_info_only(void); - void subtract_black(); - int raw2image(); - int raw2image_ex(); - void raw2image_start(); - void free_image(); - int adjust_maximum(); - void set_memerror_handler( memory_callback cb,void *data) {callbacks.memcb_data = data; callbacks.mem_cb = cb; } - void set_dataerror_handler(data_callback func, void *data) { callbacks.datacb_data = data; callbacks.data_cb = func;} - void set_progress_handler(progress_callback pcb, void *data) { callbacks.progresscb_data = data; callbacks.progress_cb = pcb;} - - /* helpers */ - static const char* version(); - static int versionNumber(); - static const char** cameraList(); - static int cameraCount(); - static const char* strprogress(enum LibRaw_progress); - static const char* strerror(int p); - /* dcraw emulation */ - int dcraw_document_mode_processing(); - int dcraw_ppm_tiff_writer(const char *filename); - int dcraw_thumb_writer(const char *fname); - int dcraw_process(void); - /* memory writers */ - libraw_processed_image_t* dcraw_make_mem_image(int *errcode=NULL); - libraw_processed_image_t* dcraw_make_mem_thumb(int *errcode=NULL); - static void dcraw_clear_mem(libraw_processed_image_t*); - - /* Additional calls for make_mem_image */ - void get_mem_image_format(int* width, int* height, int* colors, int* bps) const; - int copy_mem_image(void* scan0, int stride, int bgr); - - /* free all internal data structures */ - void recycle(); - ~LibRaw(void) { recycle(); delete tls; } - - int COLOR(int row, int col) { return libraw_internal_data.internal_output_params.fuji_width? FCF(row,col):FC(row,col);} - - int FC(int row,int col) { return (imgdata.idata.filters >> (((row << 1 & 14) | (col & 1)) << 1) & 3);} - int fc (int row, int col); - - const char *unpack_function_name(); - int get_decoder_info(libraw_decoder_info_t* d_info); - libraw_internal_data_t * get_internal_data_pointer(){ return &libraw_internal_data; } - - private: - - int FCF(int row,int col) { - int rr,cc; - if (libraw_internal_data.unpacker_data.fuji_layout) { - rr = libraw_internal_data.internal_output_params.fuji_width - 1 - col + (row >> 1); - cc = col + ((row+1) >> 1); - } else { - rr = libraw_internal_data.internal_output_params.fuji_width - 1 + row - (col >> 1); - cc = row + ((col+1) >> 1); - } - return FC(rr,cc); - } - - void* malloc(size_t t); - void* calloc(size_t n,size_t t); - void* realloc(void *p, size_t s); - void free(void *p); - void merror (void *ptr, const char *where); - void derror(); - - LibRaw_TLS *tls; - libraw_internal_data_t libraw_internal_data; - decode first_decode[2048], *second_decode, *free_decode; - tiff_ifd_t tiff_ifd[10]; - libraw_memmgr memmgr; - libraw_callbacks_t callbacks; - - LibRaw_constants rgb_constants; - void (LibRaw:: *write_thumb)(); - void (LibRaw:: *write_fun)(); - void (LibRaw:: *load_raw)(); - void (LibRaw:: *thumb_load_raw)(); - - void kodak_thumb_loader(); - void write_thumb_ppm_tiff(FILE *); - void foveon_thumb_loader (void); - - int own_filtering_supported(){ return 0;} - void identify(); - void identify2(unsigned, unsigned, char*); - void write_ppm_tiff (); - void convert_to_rgb(); - void remove_zeroes(); -#ifndef NO_LCMS - void apply_profile(const char*,const char*); -#endif - void pre_interpolate(); - void border_interpolate (int border); - void lin_interpolate(); - void vng_interpolate(); - void ppg_interpolate(); - void ahd_interpolate(); - - /* from demosaic pack */ - void ahd_interpolate_mod(); - void afd_interpolate_pl(int afd_passes, int clip_on); - void afd_noise_filter_pl(); - void lmmse_interpolate(int gamma_apply); - void dcb(int iterations, int dcb_enhance); - void fbdd(int noiserd); - void vcd_interpolate(int ahd_cutoff); - void amaze_demosaic_RT(); - void exp_bef(float expos, float preser); - void CA_correct_RT(float cared, float cablue); - void cfa_linedn(float linenoise); - void cfa_impulse_gauss(float lclean, float cclean); - void green_equilibrate(float thresh); - - /* demosaic pack end */ - - void bad_pixels(const char*); - void subtract(const char*); - void hat_transform (float *temp, float *base, int st, int size, int sc); - void wavelet_denoise(); - void scale_colors(); - void median_filter (); - void blend_highlights(); - void recover_highlights(); - void green_matching(); - - void fuji_rotate(); - void stretch(); - - void foveon_thumb (); - void jpeg_thumb_writer (FILE *tfp,char *thumb,int thumb_length); - void jpeg_thumb (); - void ppm_thumb (); - void layer_thumb (); - void rollei_thumb (); - void kodak_thumb_load_raw(); - - void foveon_decoder (unsigned size, unsigned code); - unsigned get4(); - - int flip_index (int row, int col); - void gamma_curve (double pwr, double ts, int mode, int imax); - - -#ifdef LIBRAW_LIBRARY_BUILD -#include "internal/libraw_internal_funcs.h" -#endif - -}; - -#ifdef LIBRAW_LIBRARY_BUILD -#define RUN_CALLBACK(stage,iter,expect) if(callbacks.progress_cb) { \ - int rr = (*callbacks.progress_cb)(callbacks.progresscb_data,stage,iter,expect); \ - if(rr!=0) throw LIBRAW_EXCEPTION_CANCELLED_BY_CALLBACK; \ - } -#endif - - -#endif /* __cplusplus */ - - -#endif /* _LIBRAW_CLASS_H */ +/* -*- C++ -*- + * File: libraw.h + * Copyright 2008-2010 LibRaw LLC (info@libraw.org) + * Created: Sat Mar 8, 2008 + * + * LibRaw C++ interface + * + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + +*/ + +#ifndef _LIBRAW_CLASS_H +#define _LIBRAW_CLASS_H + +#ifdef __linux__ +#define _FILE_OFFSET_BITS 64 +#endif + +/* maximum file size to use LibRaw_file_datastream (fully buffered) I/O */ +#define LIBRAW_USE_STREAMS_DATASTREAM_MAXSIZE (250*1024L*1024L) + + +#include +#include +#include +#include + + +#include "libraw_datastream.h" +#include "libraw_types.h" +#include "libraw_const.h" +#include "libraw_internal.h" +#include "libraw_alloc.h" + +#ifdef __cplusplus +extern "C" +{ +#endif +DllDef const char *libraw_strerror(int errorcode); +DllDef const char *libraw_strprogress(enum LibRaw_progress); + /* LibRaw C API */ +DllDef libraw_data_t *libraw_init(unsigned int flags); +DllDef int libraw_open_file(libraw_data_t*, const char *); +DllDef int libraw_open_file_ex(libraw_data_t*, const char *, INT64 max_buff_sz); +DllDef int libraw_open_buffer(libraw_data_t*, void * buffer, size_t size); +DllDef int libraw_unpack(libraw_data_t*); +DllDef int libraw_unpack_thumb(libraw_data_t*); +DllDef void libraw_recycle(libraw_data_t*); +DllDef void libraw_close(libraw_data_t*); +DllDef void libraw_subtract_black(libraw_data_t*); +DllDef int libraw_raw2image(libraw_data_t*); +DllDef void libraw_free_image(libraw_data_t*); + /* version helpers */ +DllDef const char* libraw_version(); +DllDef int libraw_versionNumber(); + /* Camera list */ +DllDef const char** libraw_cameraList(); +DllDef int libraw_cameraCount(); + +DllDef void libraw_set_memerror_handler(libraw_data_t*, memory_callback cb, void *datap); +DllDef void libraw_set_dataerror_handler(libraw_data_t*,data_callback func,void *datap); +DllDef void libraw_set_progress_handler(libraw_data_t*,progress_callback cb,void *datap); +DllDef const char * libraw_unpack_function_name(libraw_data_t* lr); +DllDef int libraw_get_decoder_info(libraw_data_t* lr,libraw_decoder_info_t* d); + + /* DCRAW compatibility */ +DllDef int libraw_adjust_sizes_info_only(libraw_data_t*); +DllDef int libraw_dcraw_document_mode_processing(libraw_data_t*); +DllDef int libraw_dcraw_ppm_tiff_writer(libraw_data_t* lr,const char *filename); +DllDef int libraw_dcraw_thumb_writer(libraw_data_t* lr,const char *fname); +DllDef int libraw_dcraw_process(libraw_data_t* lr); +DllDef libraw_processed_image_t* libraw_dcraw_make_mem_image(libraw_data_t* lr, int *errc); +DllDef libraw_processed_image_t* libraw_dcraw_make_mem_thumb(libraw_data_t* lr, int *errc); +DllDef void libraw_dcraw_clear_mem(libraw_processed_image_t*); +#ifdef __cplusplus +} +#endif + + +#ifdef __cplusplus + +class DllDef LibRaw +{ + public: + libraw_data_t imgdata; + int verbose; + + LibRaw(unsigned int flags = LIBRAW_OPTIONS_NONE); + + libraw_output_params_t* output_params_ptr() { return &imgdata.params;} + int open_file(const char *fname, INT64 max_buffered_sz=LIBRAW_USE_STREAMS_DATASTREAM_MAXSIZE); + int open_buffer(void *buffer, size_t size); + int open_datastream(LibRaw_abstract_datastream *); + int unpack(void); + int unpack_thumb(void); + + int adjust_sizes_info_only(void); + void subtract_black(); + int raw2image(); + int raw2image_ex(); + void raw2image_start(); + void free_image(); + int adjust_maximum(); + void set_memerror_handler( memory_callback cb,void *data) {callbacks.memcb_data = data; callbacks.mem_cb = cb; } + void set_dataerror_handler(data_callback func, void *data) { callbacks.datacb_data = data; callbacks.data_cb = func;} + void set_progress_handler(progress_callback pcb, void *data) { callbacks.progresscb_data = data; callbacks.progress_cb = pcb;} + + /* helpers */ + static const char* version(); + static int versionNumber(); + static const char** cameraList(); + static int cameraCount(); + static const char* strprogress(enum LibRaw_progress); + static const char* strerror(int p); + /* dcraw emulation */ + int dcraw_document_mode_processing(); + int dcraw_ppm_tiff_writer(const char *filename); + int dcraw_thumb_writer(const char *fname); + int dcraw_process(void); + /* memory writers */ + libraw_processed_image_t* dcraw_make_mem_image(int *errcode=NULL); + libraw_processed_image_t* dcraw_make_mem_thumb(int *errcode=NULL); + static void dcraw_clear_mem(libraw_processed_image_t*); + + /* Additional calls for make_mem_image */ + void get_mem_image_format(int* width, int* height, int* colors, int* bps) const; + int copy_mem_image(void* scan0, int stride, int bgr); + + /* free all internal data structures */ + void recycle(); + ~LibRaw(void) { recycle(); delete tls; } + + int COLOR(int row, int col) { return libraw_internal_data.internal_output_params.fuji_width? FCF(row,col):FC(row,col);} + + int FC(int row,int col) { return (imgdata.idata.filters >> (((row << 1 & 14) | (col & 1)) << 1) & 3);} + int fc (int row, int col); + + const char *unpack_function_name(); + int get_decoder_info(libraw_decoder_info_t* d_info); + libraw_internal_data_t * get_internal_data_pointer(){ return &libraw_internal_data; } + + private: + + int FCF(int row,int col) { + int rr,cc; + if (libraw_internal_data.unpacker_data.fuji_layout) { + rr = libraw_internal_data.internal_output_params.fuji_width - 1 - col + (row >> 1); + cc = col + ((row+1) >> 1); + } else { + rr = libraw_internal_data.internal_output_params.fuji_width - 1 + row - (col >> 1); + cc = row + ((col+1) >> 1); + } + return FC(rr,cc); + } + + void* malloc(size_t t); + void* calloc(size_t n,size_t t); + void* realloc(void *p, size_t s); + void free(void *p); + void merror (void *ptr, const char *where); + void derror(); + + LibRaw_TLS *tls; + libraw_internal_data_t libraw_internal_data; + decode first_decode[2048], *second_decode, *free_decode; + tiff_ifd_t tiff_ifd[10]; + libraw_memmgr memmgr; + libraw_callbacks_t callbacks; + + LibRaw_constants rgb_constants; + void (LibRaw:: *write_thumb)(); + void (LibRaw:: *write_fun)(); + void (LibRaw:: *load_raw)(); + void (LibRaw:: *thumb_load_raw)(); + + void kodak_thumb_loader(); + void write_thumb_ppm_tiff(FILE *); + void foveon_thumb_loader (void); + + int own_filtering_supported(){ return 0;} + void identify(); + void identify2(unsigned, unsigned, char*); + void write_ppm_tiff (); + void convert_to_rgb(); + void remove_zeroes(); +#ifndef NO_LCMS + void apply_profile(const char*,const char*); +#endif + void pre_interpolate(); + void border_interpolate (int border); + void lin_interpolate(); + void vng_interpolate(); + void ppg_interpolate(); + void ahd_interpolate(); + + /* from demosaic pack */ + void ahd_interpolate_mod(); + void afd_interpolate_pl(int afd_passes, int clip_on); + void afd_noise_filter_pl(); + void lmmse_interpolate(int gamma_apply); + void dcb(int iterations, int dcb_enhance); + void fbdd(int noiserd); + void vcd_interpolate(int ahd_cutoff); + void amaze_demosaic_RT(); + void exp_bef(float expos, float preser); + void CA_correct_RT(float cared, float cablue); + void cfa_linedn(float linenoise); + void cfa_impulse_gauss(float lclean, float cclean); + void green_equilibrate(float thresh); + + /* demosaic pack end */ + + void bad_pixels(const char*); + void subtract(const char*); + void hat_transform (float *temp, float *base, int st, int size, int sc); + void wavelet_denoise(); + void scale_colors(); + void median_filter (); + void blend_highlights(); + void recover_highlights(); + void green_matching(); + + void fuji_rotate(); + void stretch(); + + void foveon_thumb (); + void jpeg_thumb_writer (FILE *tfp,char *thumb,int thumb_length); + void jpeg_thumb (); + void ppm_thumb (); + void layer_thumb (); + void rollei_thumb (); + void kodak_thumb_load_raw(); + + void foveon_decoder (unsigned size, unsigned code); + unsigned get4(); + + int flip_index (int row, int col); + void gamma_curve (double pwr, double ts, int mode, int imax); + + +#ifdef LIBRAW_LIBRARY_BUILD +#include "internal/libraw_internal_funcs.h" +#endif + +}; + +#ifdef LIBRAW_LIBRARY_BUILD +#define RUN_CALLBACK(stage,iter,expect) if(callbacks.progress_cb) { \ + int rr = (*callbacks.progress_cb)(callbacks.progresscb_data,stage,iter,expect); \ + if(rr!=0) throw LIBRAW_EXCEPTION_CANCELLED_BY_CALLBACK; \ + } +#endif + + +#endif /* __cplusplus */ + + +#endif /* _LIBRAW_CLASS_H */ diff --git a/Source/LibRawLite/libraw/libraw_alloc.h b/Source/LibRawLite/libraw/libraw_alloc.h index ec6d4e6..1407d47 100644 --- a/Source/LibRawLite/libraw/libraw_alloc.h +++ b/Source/LibRawLite/libraw/libraw_alloc.h @@ -1,99 +1,99 @@ -/* -*- C++ -*- - * File: libraw_alloc.h - * Copyright 2008-2010 LibRaw LLC (info@libraw.org) - * Created: Sat Mar 22, 2008 - * - * LibRaw C++ interface - * -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - - */ - -#ifndef __LIBRAW_ALLOC_H -#define __LIBRAW_ALLOC_H - -#include -#include - -#ifdef __cplusplus - -#define MSIZE 32 - -class DllDef libraw_memmgr -{ - public: - libraw_memmgr() - { - memset(mems,0,sizeof(mems)); - calloc_cnt=0; - } - void *malloc(size_t sz) - { - void *ptr = ::malloc(sz); - mem_ptr(ptr); - return ptr; - } - void *calloc(size_t n, size_t sz) - { - void *ptr = ::calloc(n,sz); - mem_ptr(ptr); - return ptr; - } - void *realloc(void *ptr,size_t newsz) - { - void *ret = ::realloc(ptr,newsz); - forget_ptr(ptr); - mem_ptr(ret); - return ret; - } - void free(void *ptr) - { - forget_ptr(ptr); - ::free(ptr); - } - void cleanup(void) - { - for(int i = 0; i< MSIZE; i++) - if(mems[i]) - { - free(mems[i]); - mems[i] = NULL; - } - } - - private: - void *mems[MSIZE]; - int calloc_cnt; - void mem_ptr(void *ptr) - { - if(ptr) - for(int i=0;i < MSIZE; i++) - if(!mems[i]) - { - mems[i] = ptr; - break; - } - } - void forget_ptr(void *ptr) - { - if(ptr) - for(int i=0;i < MSIZE; i++) - if(mems[i] == ptr) - mems[i] = NULL; - } - -}; - -#endif /* C++ */ - -#endif +/* -*- C++ -*- + * File: libraw_alloc.h + * Copyright 2008-2010 LibRaw LLC (info@libraw.org) + * Created: Sat Mar 22, 2008 + * + * LibRaw C++ interface + * +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + + */ + +#ifndef __LIBRAW_ALLOC_H +#define __LIBRAW_ALLOC_H + +#include +#include + +#ifdef __cplusplus + +#define MSIZE 32 + +class DllDef libraw_memmgr +{ + public: + libraw_memmgr() + { + memset(mems,0,sizeof(mems)); + calloc_cnt=0; + } + void *malloc(size_t sz) + { + void *ptr = ::malloc(sz); + mem_ptr(ptr); + return ptr; + } + void *calloc(size_t n, size_t sz) + { + void *ptr = ::calloc(n,sz); + mem_ptr(ptr); + return ptr; + } + void *realloc(void *ptr,size_t newsz) + { + void *ret = ::realloc(ptr,newsz); + forget_ptr(ptr); + mem_ptr(ret); + return ret; + } + void free(void *ptr) + { + forget_ptr(ptr); + ::free(ptr); + } + void cleanup(void) + { + for(int i = 0; i< MSIZE; i++) + if(mems[i]) + { + free(mems[i]); + mems[i] = NULL; + } + } + + private: + void *mems[MSIZE]; + int calloc_cnt; + void mem_ptr(void *ptr) + { + if(ptr) + for(int i=0;i < MSIZE; i++) + if(!mems[i]) + { + mems[i] = ptr; + break; + } + } + void forget_ptr(void *ptr) + { + if(ptr) + for(int i=0;i < MSIZE; i++) + if(mems[i] == ptr) + mems[i] = NULL; + } + +}; + +#endif /* C++ */ + +#endif diff --git a/Source/LibRawLite/libraw/libraw_const.h b/Source/LibRawLite/libraw/libraw_const.h index 0fe03cf..fb26cf9 100644 --- a/Source/LibRawLite/libraw/libraw_const.h +++ b/Source/LibRawLite/libraw/libraw_const.h @@ -1,162 +1,162 @@ -/* -*- C++ -*- - * File: libraw_const.h - * Copyright 2008-2010 LibRaw LLC (info@libraw.org) - * Created: Sat Mar 8 , 2008 - * - * LibRaw error codes -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - - */ - -#ifndef _LIBRAW_ERRORS_H -#define _LIBRAW_ERRORS_H - -#define LIBRAW_DEFAULT_ADJUST_MAXIMUM_THRESHOLD 0.75 -#define LIBRAW_DEFAULT_AUTO_BRIGHTNESS_THRESHOLD 0.01 - -enum LibRaw_decoder_flags -{ - LIBRAW_DECODER_LEGACY = 1, - LIBRAW_DECODER_FLATFIELD = 1<<1, - LIBRAW_DECODER_4COMPONENT = 1<<2, - LIBRAW_DECODER_USEBAYER2 = 1<<3, - LIBRAW_DECODER_HASCURVE = 1<<4, - LIBRAW_DECODER_NOTSET = 1<<15 -}; - - -enum LibRaw_constructor_flags -{ - LIBRAW_OPTIONS_NONE =0, - LIBRAW_OPIONS_NO_MEMERR_CALLBACK=1, - LIBRAW_OPIONS_NO_DATAERR_CALLBACK=1<<1 -}; - -enum LibRaw_warnings -{ - LIBRAW_WARN_NONE =0, - LIBRAW_WARN_FOVEON_NOMATRIX =1, - LIBRAW_WARN_FOVEON_INVALIDWB =1<<1, - LIBRAW_WARN_BAD_CAMERA_WB =1<<2, - LIBRAW_WARN_NO_METADATA =1<<3, - LIBRAW_WARN_NO_JPEGLIB = 1<<4, - LIBRAW_WARN_NO_EMBEDDED_PROFILE = 1<<5, - LIBRAW_WARN_NO_INPUT_PROFILE = 1<<6, - LIBRAW_WARN_BAD_OUTPUT_PROFILE= 1<<7, - LIBRAW_WARN_NO_BADPIXELMAP=1<<8, - LIBRAW_WARN_BAD_DARKFRAME_FILE=1<<9, - LIBRAW_WARN_BAD_DARKFRAME_DIM=1<<10, - LIBRAW_WARN_NO_JASPER = 1<<11 -}; - -enum LibRaw_exceptions -{ - LIBRAW_EXCEPTION_NONE =0, - LIBRAW_EXCEPTION_ALLOC =1, - LIBRAW_EXCEPTION_DECODE_RAW =2, - LIBRAW_EXCEPTION_DECODE_JPEG=3, - LIBRAW_EXCEPTION_IO_EOF =4, - LIBRAW_EXCEPTION_IO_CORRUPT =5, - LIBRAW_EXCEPTION_CANCELLED_BY_CALLBACK=6, - LIBRAW_EXCEPTION_BAD_CROP =7, - LIBRAW_EXCEPTION_IO_BADFILE =8, - LIBRAW_EXCEPTION_DECODE_JPEG2000=9 -}; - - -enum LibRaw_colorstate -{ - LIBRAW_COLORSTATE_UNKNOWN =0, - LIBRAW_COLORSTATE_INIT =1, - LIBRAW_COLORSTATE_CONST =2, - LIBRAW_COLORSTATE_LOADED =3, - LIBRAW_COLORSTATE_CALCULATED=4, - LIBRAW_COLORSTATE_RESERVED1 =5, - LIBRAW_COLORSTATE_RESERVED2 =6, - LIBRAW_COLORSTATE_RESERVED3 =7 -}; - -enum LibRaw_progress -{ - LIBRAW_PROGRESS_START = 0, - LIBRAW_PROGRESS_OPEN = 1, - LIBRAW_PROGRESS_IDENTIFY = 1<<1, - LIBRAW_PROGRESS_SIZE_ADJUST = 1<<2, - LIBRAW_PROGRESS_LOAD_RAW = 1<<3, - LIBRAW_PROGRESS_REMOVE_ZEROES = 1<<4, - LIBRAW_PROGRESS_BAD_PIXELS = 1<<5, - LIBRAW_PROGRESS_DARK_FRAME = 1<<6, - LIBRAW_PROGRESS_FOVEON_INTERPOLATE = 1<<7, - LIBRAW_PROGRESS_SCALE_COLORS = 1<<8, - LIBRAW_PROGRESS_PRE_INTERPOLATE = 1<<9, - LIBRAW_PROGRESS_INTERPOLATE = 1<<10, - LIBRAW_PROGRESS_MIX_GREEN = 1<<11, - LIBRAW_PROGRESS_MEDIAN_FILTER = 1<<12, - LIBRAW_PROGRESS_HIGHLIGHTS = 1<<13, - LIBRAW_PROGRESS_FUJI_ROTATE = 1<<14, - LIBRAW_PROGRESS_FLIP = 1<<15, - LIBRAW_PROGRESS_APPLY_PROFILE = 1<<16, - LIBRAW_PROGRESS_CONVERT_RGB = 1<<17, - LIBRAW_PROGRESS_STRETCH = 1<<18, -/* reserved */ - LIBRAW_PROGRESS_STAGE19 = 1<<19, - LIBRAW_PROGRESS_STAGE20 = 1<<20, - LIBRAW_PROGRESS_STAGE21 = 1<<21, - LIBRAW_PROGRESS_STAGE22 = 1<<22, - LIBRAW_PROGRESS_STAGE23 = 1<<23, - LIBRAW_PROGRESS_STAGE24 = 1<<24, - LIBRAW_PROGRESS_STAGE25 = 1<<25, - LIBRAW_PROGRESS_STAGE26 = 1<<26, - LIBRAW_PROGRESS_STAGE27 = 1<<27, - - LIBRAW_PROGRESS_THUMB_LOAD = 1<<28, - LIBRAW_PROGRESS_TRESERVED1 = 1<<29, - LIBRAW_PROGRESS_TRESERVED2 = 1<<30, - LIBRAW_PROGRESS_TRESERVED3 = 1<<31 -}; -#define LIBRAW_PROGRESS_THUMB_MASK 0x0fffffff - -enum LibRaw_errors -{ - LIBRAW_SUCCESS = 0, - LIBRAW_UNSPECIFIED_ERROR=-1, - LIBRAW_FILE_UNSUPPORTED = -2, - LIBRAW_REQUEST_FOR_NONEXISTENT_IMAGE=-3, - LIBRAW_OUT_OF_ORDER_CALL=-4, - LIBRAW_NO_THUMBNAIL=-5, - LIBRAW_UNSUPPORTED_THUMBNAIL=-6, - LIBRAW_UNSUFFICIENT_MEMORY=-100007, - LIBRAW_DATA_ERROR=-100008, - LIBRAW_IO_ERROR=-100009, - LIBRAW_CANCELLED_BY_CALLBACK=-100010, - LIBRAW_BAD_CROP=-100011 -}; - -#define LIBRAW_FATAL_ERROR(ec) ((ec)<-100000) - -enum LibRaw_thumbnail_formats -{ - LIBRAW_THUMBNAIL_UNKNOWN=0, - LIBRAW_THUMBNAIL_JPEG=1, - LIBRAW_THUMBNAIL_BITMAP=2, - LIBRAW_THUMBNAIL_LAYER=4, - LIBRAW_THUMBNAIL_ROLLEI=5 -}; - -enum LibRaw_image_formats -{ - LIBRAW_IMAGE_JPEG=1, - LIBRAW_IMAGE_BITMAP=2 -}; - -#endif +/* -*- C++ -*- + * File: libraw_const.h + * Copyright 2008-2010 LibRaw LLC (info@libraw.org) + * Created: Sat Mar 8 , 2008 + * + * LibRaw error codes +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + + */ + +#ifndef _LIBRAW_ERRORS_H +#define _LIBRAW_ERRORS_H + +#define LIBRAW_DEFAULT_ADJUST_MAXIMUM_THRESHOLD 0.75 +#define LIBRAW_DEFAULT_AUTO_BRIGHTNESS_THRESHOLD 0.01 + +enum LibRaw_decoder_flags +{ + LIBRAW_DECODER_LEGACY = 1, + LIBRAW_DECODER_FLATFIELD = 1<<1, + LIBRAW_DECODER_4COMPONENT = 1<<2, + LIBRAW_DECODER_USEBAYER2 = 1<<3, + LIBRAW_DECODER_HASCURVE = 1<<4, + LIBRAW_DECODER_NOTSET = 1<<15 +}; + + +enum LibRaw_constructor_flags +{ + LIBRAW_OPTIONS_NONE =0, + LIBRAW_OPIONS_NO_MEMERR_CALLBACK=1, + LIBRAW_OPIONS_NO_DATAERR_CALLBACK=1<<1 +}; + +enum LibRaw_warnings +{ + LIBRAW_WARN_NONE =0, + LIBRAW_WARN_FOVEON_NOMATRIX =1, + LIBRAW_WARN_FOVEON_INVALIDWB =1<<1, + LIBRAW_WARN_BAD_CAMERA_WB =1<<2, + LIBRAW_WARN_NO_METADATA =1<<3, + LIBRAW_WARN_NO_JPEGLIB = 1<<4, + LIBRAW_WARN_NO_EMBEDDED_PROFILE = 1<<5, + LIBRAW_WARN_NO_INPUT_PROFILE = 1<<6, + LIBRAW_WARN_BAD_OUTPUT_PROFILE= 1<<7, + LIBRAW_WARN_NO_BADPIXELMAP=1<<8, + LIBRAW_WARN_BAD_DARKFRAME_FILE=1<<9, + LIBRAW_WARN_BAD_DARKFRAME_DIM=1<<10, + LIBRAW_WARN_NO_JASPER = 1<<11 +}; + +enum LibRaw_exceptions +{ + LIBRAW_EXCEPTION_NONE =0, + LIBRAW_EXCEPTION_ALLOC =1, + LIBRAW_EXCEPTION_DECODE_RAW =2, + LIBRAW_EXCEPTION_DECODE_JPEG=3, + LIBRAW_EXCEPTION_IO_EOF =4, + LIBRAW_EXCEPTION_IO_CORRUPT =5, + LIBRAW_EXCEPTION_CANCELLED_BY_CALLBACK=6, + LIBRAW_EXCEPTION_BAD_CROP =7, + LIBRAW_EXCEPTION_IO_BADFILE =8, + LIBRAW_EXCEPTION_DECODE_JPEG2000=9 +}; + + +enum LibRaw_colorstate +{ + LIBRAW_COLORSTATE_UNKNOWN =0, + LIBRAW_COLORSTATE_INIT =1, + LIBRAW_COLORSTATE_CONST =2, + LIBRAW_COLORSTATE_LOADED =3, + LIBRAW_COLORSTATE_CALCULATED=4, + LIBRAW_COLORSTATE_RESERVED1 =5, + LIBRAW_COLORSTATE_RESERVED2 =6, + LIBRAW_COLORSTATE_RESERVED3 =7 +}; + +enum LibRaw_progress +{ + LIBRAW_PROGRESS_START = 0, + LIBRAW_PROGRESS_OPEN = 1, + LIBRAW_PROGRESS_IDENTIFY = 1<<1, + LIBRAW_PROGRESS_SIZE_ADJUST = 1<<2, + LIBRAW_PROGRESS_LOAD_RAW = 1<<3, + LIBRAW_PROGRESS_REMOVE_ZEROES = 1<<4, + LIBRAW_PROGRESS_BAD_PIXELS = 1<<5, + LIBRAW_PROGRESS_DARK_FRAME = 1<<6, + LIBRAW_PROGRESS_FOVEON_INTERPOLATE = 1<<7, + LIBRAW_PROGRESS_SCALE_COLORS = 1<<8, + LIBRAW_PROGRESS_PRE_INTERPOLATE = 1<<9, + LIBRAW_PROGRESS_INTERPOLATE = 1<<10, + LIBRAW_PROGRESS_MIX_GREEN = 1<<11, + LIBRAW_PROGRESS_MEDIAN_FILTER = 1<<12, + LIBRAW_PROGRESS_HIGHLIGHTS = 1<<13, + LIBRAW_PROGRESS_FUJI_ROTATE = 1<<14, + LIBRAW_PROGRESS_FLIP = 1<<15, + LIBRAW_PROGRESS_APPLY_PROFILE = 1<<16, + LIBRAW_PROGRESS_CONVERT_RGB = 1<<17, + LIBRAW_PROGRESS_STRETCH = 1<<18, +/* reserved */ + LIBRAW_PROGRESS_STAGE19 = 1<<19, + LIBRAW_PROGRESS_STAGE20 = 1<<20, + LIBRAW_PROGRESS_STAGE21 = 1<<21, + LIBRAW_PROGRESS_STAGE22 = 1<<22, + LIBRAW_PROGRESS_STAGE23 = 1<<23, + LIBRAW_PROGRESS_STAGE24 = 1<<24, + LIBRAW_PROGRESS_STAGE25 = 1<<25, + LIBRAW_PROGRESS_STAGE26 = 1<<26, + LIBRAW_PROGRESS_STAGE27 = 1<<27, + + LIBRAW_PROGRESS_THUMB_LOAD = 1<<28, + LIBRAW_PROGRESS_TRESERVED1 = 1<<29, + LIBRAW_PROGRESS_TRESERVED2 = 1<<30, + LIBRAW_PROGRESS_TRESERVED3 = 1<<31 +}; +#define LIBRAW_PROGRESS_THUMB_MASK 0x0fffffff + +enum LibRaw_errors +{ + LIBRAW_SUCCESS = 0, + LIBRAW_UNSPECIFIED_ERROR=-1, + LIBRAW_FILE_UNSUPPORTED = -2, + LIBRAW_REQUEST_FOR_NONEXISTENT_IMAGE=-3, + LIBRAW_OUT_OF_ORDER_CALL=-4, + LIBRAW_NO_THUMBNAIL=-5, + LIBRAW_UNSUPPORTED_THUMBNAIL=-6, + LIBRAW_UNSUFFICIENT_MEMORY=-100007, + LIBRAW_DATA_ERROR=-100008, + LIBRAW_IO_ERROR=-100009, + LIBRAW_CANCELLED_BY_CALLBACK=-100010, + LIBRAW_BAD_CROP=-100011 +}; + +#define LIBRAW_FATAL_ERROR(ec) ((ec)<-100000) + +enum LibRaw_thumbnail_formats +{ + LIBRAW_THUMBNAIL_UNKNOWN=0, + LIBRAW_THUMBNAIL_JPEG=1, + LIBRAW_THUMBNAIL_BITMAP=2, + LIBRAW_THUMBNAIL_LAYER=4, + LIBRAW_THUMBNAIL_ROLLEI=5 +}; + +enum LibRaw_image_formats +{ + LIBRAW_IMAGE_JPEG=1, + LIBRAW_IMAGE_BITMAP=2 +}; + +#endif diff --git a/Source/LibRawLite/libraw/libraw_datastream.h b/Source/LibRawLite/libraw/libraw_datastream.h index 5096047..cab6cd7 100644 --- a/Source/LibRawLite/libraw/libraw_datastream.h +++ b/Source/LibRawLite/libraw/libraw_datastream.h @@ -1,205 +1,205 @@ -/* -*- C -*- - * File: libraw_datastream.h - * Copyright 2008-2010 LibRaw LLC (info@libraw.org) - * Created: Sun Jan 18 13:07:35 2009 - * - * LibRaw Data stream interface - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - - */ - -#ifndef __LIBRAW_DATASTREAM_H -#define __LIBRAW_DATASTREAM_H - -#include -#include -#include -#include - -#ifndef __cplusplus - - -#else /* __cplusplus */ - -#include "libraw_const.h" -#include "libraw_types.h" -#include -#include - -#if defined (WIN32) -#include - -/* MSVS 2008 and above... */ -#if _MSC_VER >= 1500 -#define WIN32SECURECALLS -#endif -#endif - -#define IOERROR() do { throw LIBRAW_EXCEPTION_IO_EOF; } while(0) - -class LibRaw_buffer_datastream; -class LibRaw_byte_buffer; -class LibRaw_bit_buffer; - -class DllDef LibRaw_abstract_datastream -{ - public: - LibRaw_abstract_datastream(){ substream=0;}; - virtual ~LibRaw_abstract_datastream(void){if(substream) delete substream;} - virtual int valid() = 0; - virtual int read(void *,size_t, size_t ) = 0; - virtual int seek(INT64 , int ) = 0; - virtual INT64 tell() = 0; - virtual int get_char() = 0; - virtual char* gets(char *, int) = 0; - virtual int scanf_one(const char *, void *) = 0; - virtual int eof() = 0; - virtual void * make_jas_stream() = 0; - /* Make buffer from current offset */ - virtual LibRaw_byte_buffer *make_byte_buffer(unsigned int sz); - - /* subfile parsing not implemented in base class */ - virtual const char* fname(){ return NULL;}; - virtual int subfile_open(const char*) { return -1;} - virtual void subfile_close() { } - - - virtual int tempbuffer_open(void*, size_t); - virtual void tempbuffer_close(); - - protected: - LibRaw_abstract_datastream *substream; -}; - -#ifdef WIN32 -template class DllDef std::auto_ptr; -#endif - -class DllDef LibRaw_file_datastream: public LibRaw_abstract_datastream -{ - protected: - std::auto_ptr f; /* will close() automatically through dtor */ - std::auto_ptr saved_f; /* when *f is a subfile, *saved_f is the master file */ - const char *filename; - - public: - virtual ~LibRaw_file_datastream(){} - LibRaw_file_datastream(const char *fname); - virtual void *make_jas_stream(); - virtual int valid(); - virtual int read(void * ptr,size_t size, size_t nmemb); - virtual int eof(); - virtual int seek(INT64 o, int whence); - virtual INT64 tell(); - virtual int get_char() - { - if(substream) return substream->get_char(); - return f->sbumpc(); - } - virtual char* gets(char *str, int sz); - virtual int scanf_one(const char *fmt, void*val); - virtual const char* fname(); - virtual int subfile_open(const char *fn); - virtual void subfile_close(); -}; - -class DllDef LibRaw_buffer_datastream : public LibRaw_abstract_datastream -{ - public: - LibRaw_buffer_datastream(void *buffer, size_t bsize); - virtual ~LibRaw_buffer_datastream(); - virtual int valid(); - virtual void *make_jas_stream(); - virtual LibRaw_byte_buffer *make_byte_buffer(unsigned int sz); - virtual int read(void * ptr,size_t sz, size_t nmemb); - virtual int eof(); - virtual int seek(INT64 o, int whence); - virtual INT64 tell(); - virtual char* gets(char *s, int sz); - virtual int scanf_one(const char *fmt, void* val); - virtual int get_char() - { - if(substream) return substream->get_char(); - if(streampos>=streamsize) - return -1; - return buf[streampos++]; - } - - private: - unsigned char *buf; - size_t streampos,streamsize; -}; - -class DllDef LibRaw_bigfile_datastream : public LibRaw_abstract_datastream -{ - public: - LibRaw_bigfile_datastream(const char *fname); - virtual ~LibRaw_bigfile_datastream(); - virtual int valid(); - virtual void *make_jas_stream(); - - virtual int read(void * ptr,size_t size, size_t nmemb); - virtual int eof(); - virtual int seek(INT64 o, int whence); - virtual INT64 tell(); - virtual char* gets(char *str, int sz); - virtual int scanf_one(const char *fmt, void*val); - virtual const char *fname(); - virtual int subfile_open(const char *fn); - virtual void subfile_close(); - virtual int get_char() - { -#ifndef WIN32 - return substream?substream->get_char():getc_unlocked(f); -#else - return substream?substream->get_char():fgetc(f); -#endif - } - - private: - FILE *f,*sav; - const char *filename; -}; - -#ifdef WIN32 -class DllDef LibRaw_windows_datastream : public LibRaw_buffer_datastream -{ -public: - /* ctor: high level constructor opens a file by name */ - LibRaw_windows_datastream(const TCHAR* sFile); - /* ctor: construct with a file handle - caller is responsible for closing the file handle */ - LibRaw_windows_datastream(HANDLE hFile); - /* dtor: unmap and close the mapping handle */ - virtual ~LibRaw_windows_datastream(); - -protected: - void Open(HANDLE hFile); - inline void reconstruct_base() - { - /* this subterfuge is to overcome the private-ness of LibRaw_buffer_datastream */ - (LibRaw_buffer_datastream&)*this = LibRaw_buffer_datastream(pView_, (size_t)cbView_); - } - - HANDLE hMap_; /* handle of the file mapping */ - void* pView_; /* pointer to the mapped memory */ - __int64 cbView_; /* size of the mapping in bytes */ -}; - -#endif - - -#endif /* cplusplus */ - -#endif - +/* -*- C -*- + * File: libraw_datastream.h + * Copyright 2008-2010 LibRaw LLC (info@libraw.org) + * Created: Sun Jan 18 13:07:35 2009 + * + * LibRaw Data stream interface + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + + */ + +#ifndef __LIBRAW_DATASTREAM_H +#define __LIBRAW_DATASTREAM_H + +#include +#include +#include +#include + +#ifndef __cplusplus + + +#else /* __cplusplus */ + +#include "libraw_const.h" +#include "libraw_types.h" +#include +#include + +#if defined (WIN32) +#include + +/* MSVS 2008 and above... */ +#if _MSC_VER >= 1500 +#define WIN32SECURECALLS +#endif +#endif + +#define IOERROR() do { throw LIBRAW_EXCEPTION_IO_EOF; } while(0) + +class LibRaw_buffer_datastream; +class LibRaw_byte_buffer; +class LibRaw_bit_buffer; + +class DllDef LibRaw_abstract_datastream +{ + public: + LibRaw_abstract_datastream(){ substream=0;}; + virtual ~LibRaw_abstract_datastream(void){if(substream) delete substream;} + virtual int valid() = 0; + virtual int read(void *,size_t, size_t ) = 0; + virtual int seek(INT64 , int ) = 0; + virtual INT64 tell() = 0; + virtual int get_char() = 0; + virtual char* gets(char *, int) = 0; + virtual int scanf_one(const char *, void *) = 0; + virtual int eof() = 0; + virtual void * make_jas_stream() = 0; + /* Make buffer from current offset */ + virtual LibRaw_byte_buffer *make_byte_buffer(unsigned int sz); + + /* subfile parsing not implemented in base class */ + virtual const char* fname(){ return NULL;}; + virtual int subfile_open(const char*) { return -1;} + virtual void subfile_close() { } + + + virtual int tempbuffer_open(void*, size_t); + virtual void tempbuffer_close(); + + protected: + LibRaw_abstract_datastream *substream; +}; + +#ifdef WIN32 +template class DllDef std::auto_ptr; +#endif + +class DllDef LibRaw_file_datastream: public LibRaw_abstract_datastream +{ + protected: + std::auto_ptr f; /* will close() automatically through dtor */ + std::auto_ptr saved_f; /* when *f is a subfile, *saved_f is the master file */ + const char *filename; + + public: + virtual ~LibRaw_file_datastream(){} + LibRaw_file_datastream(const char *fname); + virtual void *make_jas_stream(); + virtual int valid(); + virtual int read(void * ptr,size_t size, size_t nmemb); + virtual int eof(); + virtual int seek(INT64 o, int whence); + virtual INT64 tell(); + virtual int get_char() + { + if(substream) return substream->get_char(); + return f->sbumpc(); + } + virtual char* gets(char *str, int sz); + virtual int scanf_one(const char *fmt, void*val); + virtual const char* fname(); + virtual int subfile_open(const char *fn); + virtual void subfile_close(); +}; + +class DllDef LibRaw_buffer_datastream : public LibRaw_abstract_datastream +{ + public: + LibRaw_buffer_datastream(void *buffer, size_t bsize); + virtual ~LibRaw_buffer_datastream(); + virtual int valid(); + virtual void *make_jas_stream(); + virtual LibRaw_byte_buffer *make_byte_buffer(unsigned int sz); + virtual int read(void * ptr,size_t sz, size_t nmemb); + virtual int eof(); + virtual int seek(INT64 o, int whence); + virtual INT64 tell(); + virtual char* gets(char *s, int sz); + virtual int scanf_one(const char *fmt, void* val); + virtual int get_char() + { + if(substream) return substream->get_char(); + if(streampos>=streamsize) + return -1; + return buf[streampos++]; + } + + private: + unsigned char *buf; + size_t streampos,streamsize; +}; + +class DllDef LibRaw_bigfile_datastream : public LibRaw_abstract_datastream +{ + public: + LibRaw_bigfile_datastream(const char *fname); + virtual ~LibRaw_bigfile_datastream(); + virtual int valid(); + virtual void *make_jas_stream(); + + virtual int read(void * ptr,size_t size, size_t nmemb); + virtual int eof(); + virtual int seek(INT64 o, int whence); + virtual INT64 tell(); + virtual char* gets(char *str, int sz); + virtual int scanf_one(const char *fmt, void*val); + virtual const char *fname(); + virtual int subfile_open(const char *fn); + virtual void subfile_close(); + virtual int get_char() + { +#ifndef WIN32 + return substream?substream->get_char():getc_unlocked(f); +#else + return substream?substream->get_char():fgetc(f); +#endif + } + + private: + FILE *f,*sav; + const char *filename; +}; + +#ifdef WIN32 +class DllDef LibRaw_windows_datastream : public LibRaw_buffer_datastream +{ +public: + /* ctor: high level constructor opens a file by name */ + LibRaw_windows_datastream(const TCHAR* sFile); + /* ctor: construct with a file handle - caller is responsible for closing the file handle */ + LibRaw_windows_datastream(HANDLE hFile); + /* dtor: unmap and close the mapping handle */ + virtual ~LibRaw_windows_datastream(); + +protected: + void Open(HANDLE hFile); + inline void reconstruct_base() + { + /* this subterfuge is to overcome the private-ness of LibRaw_buffer_datastream */ + (LibRaw_buffer_datastream&)*this = LibRaw_buffer_datastream(pView_, (size_t)cbView_); + } + + HANDLE hMap_; /* handle of the file mapping */ + void* pView_; /* pointer to the mapped memory */ + __int64 cbView_; /* size of the mapping in bytes */ +}; + +#endif + + +#endif /* cplusplus */ + +#endif + diff --git a/Source/LibRawLite/libraw/libraw_internal.h b/Source/LibRawLite/libraw/libraw_internal.h index 286286f..920f4c8 100644 --- a/Source/LibRawLite/libraw/libraw_internal.h +++ b/Source/LibRawLite/libraw/libraw_internal.h @@ -1,218 +1,218 @@ -/* -*- C++ -*- - * File: libraw_internal.h - * Copyright 2008-2010 LibRaw LLC (info@libraw.org) - * Created: Sat Mar 8 , 2008 - * - * LibRaw internal data structures (not visible outside) - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - - */ - -#ifndef _LIBRAW_INTERNAL_TYPES_H -#define _LIBRAW_INTERNAL_TYPES_H - -#include -#ifdef __cplusplus - -#ifdef LIBRAW_LIBRARY_BUILD -#ifndef CLASS -#define CLASS LibRaw:: -#endif -#endif - -#else -#ifndef CLASS -#define CLASS -#endif -#endif - - -#ifdef __cplusplus - -#include "libraw_datastream.h" -#include "libraw_types.h" - -class LibRaw_TLS -{ -public: - struct - { - unsigned bitbuf; - int vbits, reset; - }getbits; - struct - { - UINT64 bitbuf; - int vbits; - - }ph1_bits; - struct - { - unsigned pad[128], p; - }sony_decrypt; - uchar jpeg_buffer[4096]; - struct - { - uchar buf[0x4000]; - int vbits, padding; - }pana_bits; - - void init() - { - getbits.bitbuf = 0; getbits.vbits = getbits.reset = 0; - ph1_bits.bitbuf = 0; ph1_bits.vbits = 0; - pana_bits.vbits = 0; - } -}; - - -class LibRaw_constants -{ - public: - static const float d65_white[3]; - static const double xyz_rgb[3][3]; -}; -#endif /* __cplusplus */ - - -typedef struct -{ -#ifndef __cplusplus - struct -#endif - LibRaw_abstract_datastream *input; - FILE *output; - int input_internal; - char *meta_data; - INT64 profile_offset; - INT64 toffset; - -} internal_data_t; - - -#define LIBRAW_HISTOGRAM_SIZE 0x2000 -typedef struct -{ - int (*histogram)[LIBRAW_HISTOGRAM_SIZE]; - unsigned *oprof; -} output_data_t; - -typedef struct -{ - unsigned olympus_exif_cfa; - unsigned unique_id; - unsigned tiff_nifds; - int tiff_flip; -}identify_data_t; - -typedef struct -{ - short order; - ushort sraw_mul[4],cr2_slice[3]; - unsigned kodak_cbpp; - INT64 strip_offset, data_offset; - INT64 meta_offset; - unsigned data_size; - unsigned meta_length; - unsigned thumb_misc; - unsigned fuji_layout; - unsigned tiff_samples; - unsigned tiff_bps; - unsigned tiff_compress; - unsigned zero_after_ff; - unsigned tile_width, tile_length,load_flags; - unsigned data_error; -}unpacker_data_t; - - - -typedef struct -{ - internal_data_t internal_data; - libraw_internal_output_params_t internal_output_params; - output_data_t output_data; - identify_data_t identify_data; - unpacker_data_t unpacker_data; -} libraw_internal_data_t; - - -struct decode -{ - struct decode *branch[2]; - int leaf; -}; - -struct tiff_ifd_t -{ - int t_width, t_height, bps, comp, phint, offset, t_flip, samples, bytes,tile_maxbytes; -}; - - -struct jhead { - int bits, high, wide, clrs, sraw, psv, restart, vpred[6]; - ushort *huff[6], *free[4], *row; -}; -struct tiff_tag { - ushort tag, type; - int count; - union { char c[4]; short s[2]; int i; } val; -}; - -struct tiff_hdr { - ushort t_order, magic; - int ifd; - ushort pad, ntag; - struct tiff_tag tag[23]; - int nextifd; - ushort pad2, nexif; - struct tiff_tag exif[4]; - ushort pad3, ngps; - struct tiff_tag gpst[10]; - short bps[4]; - int rat[10]; - unsigned gps[26]; - char t_desc[512], t_make[64], t_model[64], soft[32], date[20], t_artist[64]; -}; - - - -#ifdef DEBUG_STAGE_CHECKS -#define CHECK_ORDER_HIGH(expected_stage) \ - do { if((imgdata.progress_flags & LIBRAW_PROGRESS_THUMB_MASK) >= expected_stage) {fprintf(stderr,"CHECK_HIGH: check %d >= %d\n",imgdata.progress_flags & LIBRAW_PROGRESS_THUMB_MASK,expected_stage);return LIBRAW_OUT_OF_ORDER_CALL;} } while(0) - -#define CHECK_ORDER_LOW(expected_stage) \ - do { printf("Checking LOW %d/%d : %d\n",imgdata.progress_flags,expected_stage,imgdata.progress_flags= expected_stage) \ - {return LIBRAW_OUT_OF_ORDER_CALL;} } while(0) - -#define CHECK_ORDER_LOW(expected_stage) \ - do { if((imgdata.progress_flags&LIBRAW_PROGRESS_THUMB_MASK) < expected_stage) \ - return LIBRAW_OUT_OF_ORDER_CALL; } while(0) - -#define CHECK_ORDER_BIT(expected_stage) \ - do { if(imgdata.progress_flags & expected_stage) return LIBRAW_OUT_OF_ORDER_CALL; } while(0) - -#define SET_PROC_FLAG(stage) do {imgdata.progress_flags |= stage;} while (0) - -#endif - -#endif +/* -*- C++ -*- + * File: libraw_internal.h + * Copyright 2008-2010 LibRaw LLC (info@libraw.org) + * Created: Sat Mar 8 , 2008 + * + * LibRaw internal data structures (not visible outside) + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + + */ + +#ifndef _LIBRAW_INTERNAL_TYPES_H +#define _LIBRAW_INTERNAL_TYPES_H + +#include +#ifdef __cplusplus + +#ifdef LIBRAW_LIBRARY_BUILD +#ifndef CLASS +#define CLASS LibRaw:: +#endif +#endif + +#else +#ifndef CLASS +#define CLASS +#endif +#endif + + +#ifdef __cplusplus + +#include "libraw_datastream.h" +#include "libraw_types.h" + +class LibRaw_TLS +{ +public: + struct + { + unsigned bitbuf; + int vbits, reset; + }getbits; + struct + { + UINT64 bitbuf; + int vbits; + + }ph1_bits; + struct + { + unsigned pad[128], p; + }sony_decrypt; + uchar jpeg_buffer[4096]; + struct + { + uchar buf[0x4000]; + int vbits, padding; + }pana_bits; + + void init() + { + getbits.bitbuf = 0; getbits.vbits = getbits.reset = 0; + ph1_bits.bitbuf = 0; ph1_bits.vbits = 0; + pana_bits.vbits = 0; + } +}; + + +class LibRaw_constants +{ + public: + static const float d65_white[3]; + static const double xyz_rgb[3][3]; +}; +#endif /* __cplusplus */ + + +typedef struct +{ +#ifndef __cplusplus + struct +#endif + LibRaw_abstract_datastream *input; + FILE *output; + int input_internal; + char *meta_data; + INT64 profile_offset; + INT64 toffset; + +} internal_data_t; + + +#define LIBRAW_HISTOGRAM_SIZE 0x2000 +typedef struct +{ + int (*histogram)[LIBRAW_HISTOGRAM_SIZE]; + unsigned *oprof; +} output_data_t; + +typedef struct +{ + unsigned olympus_exif_cfa; + unsigned unique_id; + unsigned tiff_nifds; + int tiff_flip; +}identify_data_t; + +typedef struct +{ + short order; + ushort sraw_mul[4],cr2_slice[3]; + unsigned kodak_cbpp; + INT64 strip_offset, data_offset; + INT64 meta_offset; + unsigned data_size; + unsigned meta_length; + unsigned thumb_misc; + unsigned fuji_layout; + unsigned tiff_samples; + unsigned tiff_bps; + unsigned tiff_compress; + unsigned zero_after_ff; + unsigned tile_width, tile_length,load_flags; + unsigned data_error; +}unpacker_data_t; + + + +typedef struct +{ + internal_data_t internal_data; + libraw_internal_output_params_t internal_output_params; + output_data_t output_data; + identify_data_t identify_data; + unpacker_data_t unpacker_data; +} libraw_internal_data_t; + + +struct decode +{ + struct decode *branch[2]; + int leaf; +}; + +struct tiff_ifd_t +{ + int t_width, t_height, bps, comp, phint, offset, t_flip, samples, bytes,tile_maxbytes; +}; + + +struct jhead { + int bits, high, wide, clrs, sraw, psv, restart, vpred[6]; + ushort *huff[6], *free[4], *row; +}; +struct tiff_tag { + ushort tag, type; + int count; + union { char c[4]; short s[2]; int i; } val; +}; + +struct tiff_hdr { + ushort t_order, magic; + int ifd; + ushort pad, ntag; + struct tiff_tag tag[23]; + int nextifd; + ushort pad2, nexif; + struct tiff_tag exif[4]; + ushort pad3, ngps; + struct tiff_tag gpst[10]; + short bps[4]; + int rat[10]; + unsigned gps[26]; + char t_desc[512], t_make[64], t_model[64], soft[32], date[20], t_artist[64]; +}; + + + +#ifdef DEBUG_STAGE_CHECKS +#define CHECK_ORDER_HIGH(expected_stage) \ + do { if((imgdata.progress_flags & LIBRAW_PROGRESS_THUMB_MASK) >= expected_stage) {fprintf(stderr,"CHECK_HIGH: check %d >= %d\n",imgdata.progress_flags & LIBRAW_PROGRESS_THUMB_MASK,expected_stage);return LIBRAW_OUT_OF_ORDER_CALL;} } while(0) + +#define CHECK_ORDER_LOW(expected_stage) \ + do { printf("Checking LOW %d/%d : %d\n",imgdata.progress_flags,expected_stage,imgdata.progress_flags= expected_stage) \ + {return LIBRAW_OUT_OF_ORDER_CALL;} } while(0) + +#define CHECK_ORDER_LOW(expected_stage) \ + do { if((imgdata.progress_flags&LIBRAW_PROGRESS_THUMB_MASK) < expected_stage) \ + return LIBRAW_OUT_OF_ORDER_CALL; } while(0) + +#define CHECK_ORDER_BIT(expected_stage) \ + do { if(imgdata.progress_flags & expected_stage) return LIBRAW_OUT_OF_ORDER_CALL; } while(0) + +#define SET_PROC_FLAG(stage) do {imgdata.progress_flags |= stage;} while (0) + +#endif + +#endif diff --git a/Source/LibRawLite/libraw/libraw_types.h b/Source/LibRawLite/libraw/libraw_types.h index b2b484c..4185934 100644 --- a/Source/LibRawLite/libraw/libraw_types.h +++ b/Source/LibRawLite/libraw/libraw_types.h @@ -1,352 +1,352 @@ -/* -*- C++ -*- - * File: libraw_types.h - * Copyright 2008-2010 LibRaw LLC (info@libraw.org) - * Created: Sat Mar 8 , 2008 - * - * LibRaw C data structures - * - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - - */ - -#ifndef _LIBRAW_TYPES_H -#define _LIBRAW_TYPES_H - -#include -#ifndef WIN32 -#include -#endif -#include - -#if defined (_OPENMP) - -#if defined(WIN32) -# if defined (_MSC_VER) && (_MSC_VER >= 1600 || (_MSC_VER == 1500 && _MSC_FULL_VER >= 150030729) ) -/* VS2010+ : OpenMP works OK, VS2008: have tested by cgilles */ -# define LIBRAW_USE_OPENMP -#elif defined (__INTEL_COMPILER) && (__INTEL_COMPILER >=910) -/* Have not tested on 9.x and 10.x, but Intel documentation claims OpenMP 2.5 support in 9.1 */ -# define LIBRAW_USE_OPENMP -#else -# undef LIBRAW_USE_OPENMP -#endif -/* Not Win32 */ -# elif (defined(__APPLE__) || defined(__MACOSX__)) && defined(_REENTRANT) -# undef LIBRAW_USE_OPENMP -# else -# define LIBRAW_USE_OPENMP -# endif -#endif - -#ifdef LIBRAW_USE_OPENMP -#include -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(USE_LCMS) -#include -#elif defined(USE_LCMS2) -#include -#else -#define NO_LCMS -#endif - -#include "libraw_const.h" -#include "libraw_version.h" - -#ifndef _MSC_VER -// define portable types for 32-bit / 64-bit OS -#include -typedef int64_t INT64; -typedef uint64_t UINT64; -#else -// MS is not C99 ISO compliant -typedef signed __int64 INT64; -typedef unsigned __int64 UINT64; -#endif // _MSC_VER - -typedef unsigned char uchar; -typedef unsigned short ushort; - -#ifdef WIN32 -#ifdef LIBRAW_NODLL -# define DllDef -#else -# ifdef LIBRAW_BUILDLIB -# define DllDef __declspec( dllexport ) -# else -# define DllDef __declspec( dllimport ) -# endif -#endif -#else -# define DllDef -#endif - -typedef struct -{ - const char *decoder_name; - unsigned decoder_flags; -}libraw_decoder_info_t; - -typedef struct -{ - unsigned mix_green; - unsigned raw_color; - unsigned zero_is_bad; - ushort shrink; - ushort fuji_width; - ushort fwidth,fheight; -} libraw_internal_output_params_t; - - -typedef void (* memory_callback)(void * data, const char *file, const char *where); - -DllDef void default_memory_callback(void *data,const char *file, const char *where); - -typedef void (*data_callback)(void *data,const char *file, const int offset); - -DllDef void default_data_callback(void *data,const char *file, const int offset); - -typedef int (* progress_callback) (void *data,enum LibRaw_progress stage, int iteration,int expected); - -typedef struct -{ - memory_callback mem_cb; - void* memcb_data; - - data_callback data_cb; - void* datacb_data; - - progress_callback progress_cb; - void *progresscb_data; -} libraw_callbacks_t; - - -typedef struct -{ - enum LibRaw_image_formats type; - ushort height, - width, - colors, - bits; - unsigned int data_size; - unsigned char data[1]; -}libraw_processed_image_t; - - -typedef struct -{ - char make[64]; - char model[64]; - - unsigned raw_count; - unsigned dng_version; - unsigned is_foveon; - int colors; - - unsigned filters; - char cdesc[5]; - -}libraw_iparams_t; - -typedef struct -{ - ushort raw_height, - raw_width, - height, - width, - top_margin, - left_margin; - ushort iheight, - iwidth; - double pixel_aspect; - int flip; - -} libraw_image_sizes_t; - -struct ph1_t -{ - int format, key_off, t_black, black_off, split_col, tag_21a; - float tag_210; -}; - - -typedef struct -{ - unsigned curve_state : 3; - unsigned rgb_cam_state : 3; - unsigned cmatrix_state : 3; - unsigned pre_mul_state : 3; - unsigned cam_mul_state : 3; - unsigned filler : 17; -} color_data_state_t; - -typedef struct -{ - color_data_state_t color_flags; - ushort white[8][8]; - float cam_mul[4]; - float pre_mul[4]; - float cmatrix[3][4]; - float rgb_cam[3][4]; - float cam_xyz[4][3]; - ushort curve[0x10000]; - unsigned black; - unsigned cblack[8]; - unsigned maximum; - unsigned channel_maximum[4]; - struct ph1_t phase_one_data; - float flash_used; - float canon_ev; - char model2[64]; - void *profile; - unsigned profile_length; - short (*ph1_black)[2]; -}libraw_colordata_t; - -typedef struct -{ - enum LibRaw_thumbnail_formats tformat; - ushort twidth, - theight; - unsigned tlength; - int tcolors; - - char *thumb; -}libraw_thumbnail_t; - -typedef struct -{ - float iso_speed; - float shutter; - float aperture; - float focal_len; - time_t timestamp; - unsigned shot_order; - unsigned gpsdata[32]; - char desc[512], - artist[64]; -} libraw_imgother_t; - -typedef struct -{ - unsigned greybox[4]; /* -A x1 y1 x2 y2 */ - unsigned cropbox[4]; /* -B x1 y1 x2 y2 */ - double aber[4]; /* -C */ - double gamm[6]; /* -g */ - float user_mul[4]; /* -r mul0 mul1 mul2 mul3 */ - unsigned shot_select; /* -s */ - float bright; /* -b */ - float threshold; /* -n */ - int half_size; /* -h */ - int four_color_rgb; /* -f */ - int document_mode; /* -d/-D */ - int highlight; /* -H */ - int use_auto_wb; /* -a */ - int use_camera_wb; /* -w */ - int use_camera_matrix; /* +M/-M */ - int output_color; /* -o */ - char *output_profile; /* -o */ - char *camera_profile; /* -p */ - char *bad_pixels; /* -P */ - char *dark_frame; /* -K */ - int output_bps; /* -4 */ - int output_tiff; /* -T */ - int user_flip; /* -t */ - int user_qual; /* -q */ - int user_black; /* -k */ - int user_sat; /* -S */ - - int med_passes; /* -m */ - float auto_bright_thr; - float adjust_maximum_thr; - int no_auto_bright; /* -W */ - int use_fuji_rotate;/* -j */ - int green_matching; -#if 0 - /* AFD noise suppression parameters, disabled for now */ - int afd_noise_att; - int afd_noise_thres; - int afd_luminance_passes; - int afd_chrominance_method; - int afd_luminance_only; -#endif - /* DCB parameters */ - int dcb_iterations; - int dcb_enhance_fl; - int fbdd_noiserd; - /* VCD parameters */ - int eeci_refine; - int es_med_passes; - /* AMaZE*/ - int ca_correc; - float cared; - float cablue; - int cfaline; - float linenoise; - int cfa_clean; - float lclean; - float cclean; - int cfa_green; - float green_thresh; - int exp_correc; - float exp_shift; - float exp_preser; -}libraw_output_params_t; - -typedef struct -{ - /* really allocated bitmap */ - void *raw_alloc; - /* alias to single_channel variant */ - ushort *raw_image; - /* alias to 4-channel variant */ - ushort (*color_image)[4] ; - - /* Phase One black level data; */ - short (*ph1_black)[2]; - int use_ph1_correct; - /* save color and sizes here, too.... */ - libraw_iparams_t iparams; - libraw_image_sizes_t sizes; - libraw_internal_output_params_t ioparams; - libraw_colordata_t color; -} libraw_rawdata_t; - - -typedef struct -{ - unsigned int progress_flags; - unsigned int process_warnings; - libraw_iparams_t idata; - libraw_image_sizes_t sizes; - libraw_colordata_t color; - libraw_imgother_t other; - libraw_thumbnail_t thumbnail; - libraw_rawdata_t rawdata; - ushort (*image)[4] ; - libraw_output_params_t params; - void *parent_class; -} libraw_data_t; - - -#ifdef __cplusplus -} -#endif - -#endif +/* -*- C++ -*- + * File: libraw_types.h + * Copyright 2008-2010 LibRaw LLC (info@libraw.org) + * Created: Sat Mar 8 , 2008 + * + * LibRaw C data structures + * + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + + */ + +#ifndef _LIBRAW_TYPES_H +#define _LIBRAW_TYPES_H + +#include +#ifndef WIN32 +#include +#endif +#include + +#if defined (_OPENMP) + +#if defined(WIN32) +# if defined (_MSC_VER) && (_MSC_VER >= 1600 || (_MSC_VER == 1500 && _MSC_FULL_VER >= 150030729) ) +/* VS2010+ : OpenMP works OK, VS2008: have tested by cgilles */ +# define LIBRAW_USE_OPENMP +#elif defined (__INTEL_COMPILER) && (__INTEL_COMPILER >=910) +/* Have not tested on 9.x and 10.x, but Intel documentation claims OpenMP 2.5 support in 9.1 */ +# define LIBRAW_USE_OPENMP +#else +# undef LIBRAW_USE_OPENMP +#endif +/* Not Win32 */ +# elif (defined(__APPLE__) || defined(__MACOSX__)) && defined(_REENTRANT) +# undef LIBRAW_USE_OPENMP +# else +# define LIBRAW_USE_OPENMP +# endif +#endif + +#ifdef LIBRAW_USE_OPENMP +#include +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(USE_LCMS) +#include +#elif defined(USE_LCMS2) +#include +#else +#define NO_LCMS +#endif + +#include "libraw_const.h" +#include "libraw_version.h" + +#ifndef _MSC_VER +// define portable types for 32-bit / 64-bit OS +#include +typedef int64_t INT64; +typedef uint64_t UINT64; +#else +// MS is not C99 ISO compliant +typedef signed __int64 INT64; +typedef unsigned __int64 UINT64; +#endif // _MSC_VER + +typedef unsigned char uchar; +typedef unsigned short ushort; + +#ifdef WIN32 +#ifdef LIBRAW_NODLL +# define DllDef +#else +# ifdef LIBRAW_BUILDLIB +# define DllDef __declspec( dllexport ) +# else +# define DllDef __declspec( dllimport ) +# endif +#endif +#else +# define DllDef +#endif + +typedef struct +{ + const char *decoder_name; + unsigned decoder_flags; +}libraw_decoder_info_t; + +typedef struct +{ + unsigned mix_green; + unsigned raw_color; + unsigned zero_is_bad; + ushort shrink; + ushort fuji_width; + ushort fwidth,fheight; +} libraw_internal_output_params_t; + + +typedef void (* memory_callback)(void * data, const char *file, const char *where); + +DllDef void default_memory_callback(void *data,const char *file, const char *where); + +typedef void (*data_callback)(void *data,const char *file, const int offset); + +DllDef void default_data_callback(void *data,const char *file, const int offset); + +typedef int (* progress_callback) (void *data,enum LibRaw_progress stage, int iteration,int expected); + +typedef struct +{ + memory_callback mem_cb; + void* memcb_data; + + data_callback data_cb; + void* datacb_data; + + progress_callback progress_cb; + void *progresscb_data; +} libraw_callbacks_t; + + +typedef struct +{ + enum LibRaw_image_formats type; + ushort height, + width, + colors, + bits; + unsigned int data_size; + unsigned char data[1]; +}libraw_processed_image_t; + + +typedef struct +{ + char make[64]; + char model[64]; + + unsigned raw_count; + unsigned dng_version; + unsigned is_foveon; + int colors; + + unsigned filters; + char cdesc[5]; + +}libraw_iparams_t; + +typedef struct +{ + ushort raw_height, + raw_width, + height, + width, + top_margin, + left_margin; + ushort iheight, + iwidth; + double pixel_aspect; + int flip; + +} libraw_image_sizes_t; + +struct ph1_t +{ + int format, key_off, t_black, black_off, split_col, tag_21a; + float tag_210; +}; + + +typedef struct +{ + unsigned curve_state : 3; + unsigned rgb_cam_state : 3; + unsigned cmatrix_state : 3; + unsigned pre_mul_state : 3; + unsigned cam_mul_state : 3; + unsigned filler : 17; +} color_data_state_t; + +typedef struct +{ + color_data_state_t color_flags; + ushort white[8][8]; + float cam_mul[4]; + float pre_mul[4]; + float cmatrix[3][4]; + float rgb_cam[3][4]; + float cam_xyz[4][3]; + ushort curve[0x10000]; + unsigned black; + unsigned cblack[8]; + unsigned maximum; + unsigned channel_maximum[4]; + struct ph1_t phase_one_data; + float flash_used; + float canon_ev; + char model2[64]; + void *profile; + unsigned profile_length; + short (*ph1_black)[2]; +}libraw_colordata_t; + +typedef struct +{ + enum LibRaw_thumbnail_formats tformat; + ushort twidth, + theight; + unsigned tlength; + int tcolors; + + char *thumb; +}libraw_thumbnail_t; + +typedef struct +{ + float iso_speed; + float shutter; + float aperture; + float focal_len; + time_t timestamp; + unsigned shot_order; + unsigned gpsdata[32]; + char desc[512], + artist[64]; +} libraw_imgother_t; + +typedef struct +{ + unsigned greybox[4]; /* -A x1 y1 x2 y2 */ + unsigned cropbox[4]; /* -B x1 y1 x2 y2 */ + double aber[4]; /* -C */ + double gamm[6]; /* -g */ + float user_mul[4]; /* -r mul0 mul1 mul2 mul3 */ + unsigned shot_select; /* -s */ + float bright; /* -b */ + float threshold; /* -n */ + int half_size; /* -h */ + int four_color_rgb; /* -f */ + int document_mode; /* -d/-D */ + int highlight; /* -H */ + int use_auto_wb; /* -a */ + int use_camera_wb; /* -w */ + int use_camera_matrix; /* +M/-M */ + int output_color; /* -o */ + char *output_profile; /* -o */ + char *camera_profile; /* -p */ + char *bad_pixels; /* -P */ + char *dark_frame; /* -K */ + int output_bps; /* -4 */ + int output_tiff; /* -T */ + int user_flip; /* -t */ + int user_qual; /* -q */ + int user_black; /* -k */ + int user_sat; /* -S */ + + int med_passes; /* -m */ + float auto_bright_thr; + float adjust_maximum_thr; + int no_auto_bright; /* -W */ + int use_fuji_rotate;/* -j */ + int green_matching; +#if 0 + /* AFD noise suppression parameters, disabled for now */ + int afd_noise_att; + int afd_noise_thres; + int afd_luminance_passes; + int afd_chrominance_method; + int afd_luminance_only; +#endif + /* DCB parameters */ + int dcb_iterations; + int dcb_enhance_fl; + int fbdd_noiserd; + /* VCD parameters */ + int eeci_refine; + int es_med_passes; + /* AMaZE*/ + int ca_correc; + float cared; + float cablue; + int cfaline; + float linenoise; + int cfa_clean; + float lclean; + float cclean; + int cfa_green; + float green_thresh; + int exp_correc; + float exp_shift; + float exp_preser; +}libraw_output_params_t; + +typedef struct +{ + /* really allocated bitmap */ + void *raw_alloc; + /* alias to single_channel variant */ + ushort *raw_image; + /* alias to 4-channel variant */ + ushort (*color_image)[4] ; + + /* Phase One black level data; */ + short (*ph1_black)[2]; + int use_ph1_correct; + /* save color and sizes here, too.... */ + libraw_iparams_t iparams; + libraw_image_sizes_t sizes; + libraw_internal_output_params_t ioparams; + libraw_colordata_t color; +} libraw_rawdata_t; + + +typedef struct +{ + unsigned int progress_flags; + unsigned int process_warnings; + libraw_iparams_t idata; + libraw_image_sizes_t sizes; + libraw_colordata_t color; + libraw_imgother_t other; + libraw_thumbnail_t thumbnail; + libraw_rawdata_t rawdata; + ushort (*image)[4] ; + libraw_output_params_t params; + void *parent_class; +} libraw_data_t; + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Source/LibRawLite/libraw/libraw_version.h b/Source/LibRawLite/libraw/libraw_version.h index e78a13b..f3656a7 100644 --- a/Source/LibRawLite/libraw/libraw_version.h +++ b/Source/LibRawLite/libraw/libraw_version.h @@ -1,62 +1,62 @@ -/* -*- C++ -*- - * File: libraw_version.h - * Copyright 2008-2010 LibRaw LLC (info@libraw.org) - * Created: Mon Sept 8, 2008 - * - * LibRaw C++ interface - * - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 -(See the file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 -(See the file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See the file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - - */ - -#ifndef __VERSION_H -#define __VERSION_H - -#define LIBRAW_MAJOR_VERSION 0 -#define LIBRAW_MINOR_VERSION 14 -#define LIBRAW_PATCH_VERSION 7 -#define LIBRAW_VERSION_TAIL Release - -#define LIBRAW_SHLIB_CURRENT 5 -#define LIBRAW_SHLIB_REVISION 0 -#define LIBRAW_SHLIB_AGE 0 - -#define _LIBRAW_VERSION_MAKE(a,b,c,d) #a"."#b"."#c"-"#d -#define LIBRAW_VERSION_MAKE(a,b,c,d) _LIBRAW_VERSION_MAKE(a,b,c,d) - -#define LIBRAW_VERSION_STR LIBRAW_VERSION_MAKE(LIBRAW_MAJOR_VERSION,LIBRAW_MINOR_VERSION,LIBRAW_PATCH_VERSION,LIBRAW_VERSION_TAIL) - -#define LIBRAW_MAKE_VERSION(major,minor,patch) \ - (((major) << 16) | ((minor) << 8) | (patch)) - -#define LIBRAW_VERSION \ - LIBRAW_MAKE_VERSION(LIBRAW_MAJOR_VERSION,LIBRAW_MINOR_VERSION,LIBRAW_PATCH_VERSION) - -#define LIBRAW_CHECK_VERSION(major,minor,patch) \ - ( LibRaw::versionNumber() >= LIBRAW_MAKE_VERSION(major,minor,patch) ) - -#define LIBRAW_RUNTIME_CHECK_VERSION_EXACT() \ - ( (LibRaw::versionNumber() & 0xffff00) == LIBRAW_MAKE_VERSION(LIBRAW_MAJOR_VERSION,LIBRAW_MINOR_VERSION,0) ) - -#define LIBRAW_RUNTIME_CHECK_VERSION_NOTLESS() \ - ( (LibRaw::versionNumber() & 0xffff00) >= LIBRAW_MAKE_VERSION(LIBRAW_MAJOR_VERSION,LIBRAW_MINOR_VERSION,0) ) - -#define LIBRAW_COMPILE_CHECK_VERSION(major,minor) \ - (LIBRAW_MAKE_VERSION(major,minor,0) == (LIBRAW_VERSION & 0xffff00)) - -#define LIBRAW_COMPILE_CHECK_VERSION_NOTLESS(major,minor) \ - (LIBRAW_MAKE_VERSION(major,minor,0) <= (LIBRAW_VERSION & 0xffff00)) - - -#endif +/* -*- C++ -*- + * File: libraw_version.h + * Copyright 2008-2010 LibRaw LLC (info@libraw.org) + * Created: Mon Sept 8, 2008 + * + * LibRaw C++ interface + * + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 +(See the file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 +(See the file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See the file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + + */ + +#ifndef __VERSION_H +#define __VERSION_H + +#define LIBRAW_MAJOR_VERSION 0 +#define LIBRAW_MINOR_VERSION 14 +#define LIBRAW_PATCH_VERSION 7 +#define LIBRAW_VERSION_TAIL Release + +#define LIBRAW_SHLIB_CURRENT 5 +#define LIBRAW_SHLIB_REVISION 0 +#define LIBRAW_SHLIB_AGE 0 + +#define _LIBRAW_VERSION_MAKE(a,b,c,d) #a"."#b"."#c"-"#d +#define LIBRAW_VERSION_MAKE(a,b,c,d) _LIBRAW_VERSION_MAKE(a,b,c,d) + +#define LIBRAW_VERSION_STR LIBRAW_VERSION_MAKE(LIBRAW_MAJOR_VERSION,LIBRAW_MINOR_VERSION,LIBRAW_PATCH_VERSION,LIBRAW_VERSION_TAIL) + +#define LIBRAW_MAKE_VERSION(major,minor,patch) \ + (((major) << 16) | ((minor) << 8) | (patch)) + +#define LIBRAW_VERSION \ + LIBRAW_MAKE_VERSION(LIBRAW_MAJOR_VERSION,LIBRAW_MINOR_VERSION,LIBRAW_PATCH_VERSION) + +#define LIBRAW_CHECK_VERSION(major,minor,patch) \ + ( LibRaw::versionNumber() >= LIBRAW_MAKE_VERSION(major,minor,patch) ) + +#define LIBRAW_RUNTIME_CHECK_VERSION_EXACT() \ + ( (LibRaw::versionNumber() & 0xffff00) == LIBRAW_MAKE_VERSION(LIBRAW_MAJOR_VERSION,LIBRAW_MINOR_VERSION,0) ) + +#define LIBRAW_RUNTIME_CHECK_VERSION_NOTLESS() \ + ( (LibRaw::versionNumber() & 0xffff00) >= LIBRAW_MAKE_VERSION(LIBRAW_MAJOR_VERSION,LIBRAW_MINOR_VERSION,0) ) + +#define LIBRAW_COMPILE_CHECK_VERSION(major,minor) \ + (LIBRAW_MAKE_VERSION(major,minor,0) == (LIBRAW_VERSION & 0xffff00)) + +#define LIBRAW_COMPILE_CHECK_VERSION_NOTLESS(major,minor) \ + (LIBRAW_MAKE_VERSION(major,minor,0) <= (LIBRAW_VERSION & 0xffff00)) + + +#endif diff --git a/Source/LibRawLite/src/libraw_c_api.cpp b/Source/LibRawLite/src/libraw_c_api.cpp index aeb921d..c795307 100644 --- a/Source/LibRawLite/src/libraw_c_api.cpp +++ b/Source/LibRawLite/src/libraw_c_api.cpp @@ -1,201 +1,201 @@ -/* -*- C++ -*- - * File: libraw_c_api.cpp - * Copyright 2008-2010 LibRaw LLC (info@libraw.org) - * Created: Sat Mar 8 , 2008 - * - * LibRaw C interface - - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - */ - -#include -#include -#include "libraw/libraw.h" - -#ifdef __cplusplus -#include -extern "C" -{ -#endif - - libraw_data_t *libraw_init(unsigned int flags) - { - LibRaw *ret; - try { - ret = new LibRaw(flags); - } - catch (std::bad_alloc) - { - return NULL; - } - return &(ret->imgdata); - } - - const char* libraw_version() { return LibRaw::version();} - const char* libraw_strprogress(enum LibRaw_progress p) { return LibRaw::strprogress(p);} - int libraw_versionNumber() { return LibRaw::versionNumber();} - const char** libraw_cameraList() { return LibRaw::cameraList();} - int libraw_cameraCount() { return LibRaw::cameraCount(); } - const char* libraw_unpack_function_name(libraw_data_t* lr) - { - if(!lr) return "NULL parameter passed"; - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->unpack_function_name(); - } - - void libraw_subtract_black(libraw_data_t* lr) - { - if(!lr) return; - LibRaw *ip = (LibRaw*) lr->parent_class; - ip->subtract_black(); - } - - - int libraw_open_file(libraw_data_t* lr, const char *file) - { - if(!lr) return EINVAL; - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->open_file(file); - } - int libraw_open_file_ex(libraw_data_t* lr, const char *file,INT64 sz) - { - if(!lr) return EINVAL; - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->open_file(file,sz); - } - int libraw_open_buffer(libraw_data_t* lr, void *buffer, size_t size) - { - if(!lr) return EINVAL; - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->open_buffer(buffer,size); - } - int libraw_unpack(libraw_data_t* lr) - { - if(!lr) return EINVAL; - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->unpack(); - } - int libraw_unpack_thumb(libraw_data_t* lr) - { - if(!lr) return EINVAL; - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->unpack_thumb(); - } - void libraw_recycle(libraw_data_t* lr) - { - if(!lr) return; - LibRaw *ip = (LibRaw*) lr->parent_class; - ip->recycle(); - } - void libraw_close(libraw_data_t* lr) - { - if(!lr) return; - LibRaw *ip = (LibRaw*) lr->parent_class; - delete ip; - } - - void libraw_set_memerror_handler(libraw_data_t* lr, memory_callback cb,void *data) - { - if(!lr) return; - LibRaw *ip = (LibRaw*) lr->parent_class; - ip->set_memerror_handler(cb,data); - - } - void libraw_set_dataerror_handler(libraw_data_t* lr,data_callback func,void *data) - { - if(!lr) return; - LibRaw *ip = (LibRaw*) lr->parent_class; - ip->set_dataerror_handler(func,data); - - } - void libraw_set_progress_handler(libraw_data_t* lr, progress_callback cb,void *data) - { - if(!lr) return; - LibRaw *ip = (LibRaw*) lr->parent_class; - ip->set_progress_handler(cb,data); - - } - - // DCRAW - int libraw_adjust_sizes_info_only(libraw_data_t* lr) - { - if(!lr) return EINVAL; - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->adjust_sizes_info_only(); - } - int libraw_dcraw_document_mode_processing(libraw_data_t* lr) - { - if(!lr) return EINVAL; - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->dcraw_document_mode_processing(); - - } - int libraw_dcraw_ppm_tiff_writer(libraw_data_t* lr,const char *filename) - { - if(!lr) return EINVAL; - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->dcraw_ppm_tiff_writer(filename); - } - int libraw_dcraw_thumb_writer(libraw_data_t* lr,const char *fname) - { - if(!lr) return EINVAL; - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->dcraw_thumb_writer(fname); - - } - int libraw_dcraw_process(libraw_data_t* lr) - { - if(!lr) return EINVAL; - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->dcraw_process(); - } - libraw_processed_image_t *libraw_dcraw_make_mem_image(libraw_data_t* lr,int *errc) - { - if(!lr) { if(errc) *errc=EINVAL; return NULL;} - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->dcraw_make_mem_image(errc); - } - libraw_processed_image_t *libraw_dcraw_make_mem_thumb(libraw_data_t* lr,int *errc) - { - if(!lr) { if(errc) *errc=EINVAL; return NULL;} - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->dcraw_make_mem_thumb(errc); - } - - void libraw_dcraw_clear_mem(libraw_processed_image_t* p) - { - LibRaw::dcraw_clear_mem(p); - } - - int libraw_raw2image(libraw_data_t* lr) - { - if(!lr) return EINVAL; - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->raw2image(); - } - void libraw_free_image(libraw_data_t* lr) - { - if(!lr) return; - LibRaw *ip = (LibRaw*) lr->parent_class; - ip->free_image(); - } - int libraw_get_decoder_info(libraw_data_t* lr,libraw_decoder_info_t *d) - { - if(!lr || !d) return EINVAL; - LibRaw *ip = (LibRaw*) lr->parent_class; - return ip->get_decoder_info(d); - } -#ifdef __cplusplus -} -#endif +/* -*- C++ -*- + * File: libraw_c_api.cpp + * Copyright 2008-2010 LibRaw LLC (info@libraw.org) + * Created: Sat Mar 8 , 2008 + * + * LibRaw C interface + + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + */ + +#include +#include +#include "libraw/libraw.h" + +#ifdef __cplusplus +#include +extern "C" +{ +#endif + + libraw_data_t *libraw_init(unsigned int flags) + { + LibRaw *ret; + try { + ret = new LibRaw(flags); + } + catch (std::bad_alloc) + { + return NULL; + } + return &(ret->imgdata); + } + + const char* libraw_version() { return LibRaw::version();} + const char* libraw_strprogress(enum LibRaw_progress p) { return LibRaw::strprogress(p);} + int libraw_versionNumber() { return LibRaw::versionNumber();} + const char** libraw_cameraList() { return LibRaw::cameraList();} + int libraw_cameraCount() { return LibRaw::cameraCount(); } + const char* libraw_unpack_function_name(libraw_data_t* lr) + { + if(!lr) return "NULL parameter passed"; + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->unpack_function_name(); + } + + void libraw_subtract_black(libraw_data_t* lr) + { + if(!lr) return; + LibRaw *ip = (LibRaw*) lr->parent_class; + ip->subtract_black(); + } + + + int libraw_open_file(libraw_data_t* lr, const char *file) + { + if(!lr) return EINVAL; + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->open_file(file); + } + int libraw_open_file_ex(libraw_data_t* lr, const char *file,INT64 sz) + { + if(!lr) return EINVAL; + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->open_file(file,sz); + } + int libraw_open_buffer(libraw_data_t* lr, void *buffer, size_t size) + { + if(!lr) return EINVAL; + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->open_buffer(buffer,size); + } + int libraw_unpack(libraw_data_t* lr) + { + if(!lr) return EINVAL; + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->unpack(); + } + int libraw_unpack_thumb(libraw_data_t* lr) + { + if(!lr) return EINVAL; + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->unpack_thumb(); + } + void libraw_recycle(libraw_data_t* lr) + { + if(!lr) return; + LibRaw *ip = (LibRaw*) lr->parent_class; + ip->recycle(); + } + void libraw_close(libraw_data_t* lr) + { + if(!lr) return; + LibRaw *ip = (LibRaw*) lr->parent_class; + delete ip; + } + + void libraw_set_memerror_handler(libraw_data_t* lr, memory_callback cb,void *data) + { + if(!lr) return; + LibRaw *ip = (LibRaw*) lr->parent_class; + ip->set_memerror_handler(cb,data); + + } + void libraw_set_dataerror_handler(libraw_data_t* lr,data_callback func,void *data) + { + if(!lr) return; + LibRaw *ip = (LibRaw*) lr->parent_class; + ip->set_dataerror_handler(func,data); + + } + void libraw_set_progress_handler(libraw_data_t* lr, progress_callback cb,void *data) + { + if(!lr) return; + LibRaw *ip = (LibRaw*) lr->parent_class; + ip->set_progress_handler(cb,data); + + } + + // DCRAW + int libraw_adjust_sizes_info_only(libraw_data_t* lr) + { + if(!lr) return EINVAL; + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->adjust_sizes_info_only(); + } + int libraw_dcraw_document_mode_processing(libraw_data_t* lr) + { + if(!lr) return EINVAL; + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->dcraw_document_mode_processing(); + + } + int libraw_dcraw_ppm_tiff_writer(libraw_data_t* lr,const char *filename) + { + if(!lr) return EINVAL; + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->dcraw_ppm_tiff_writer(filename); + } + int libraw_dcraw_thumb_writer(libraw_data_t* lr,const char *fname) + { + if(!lr) return EINVAL; + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->dcraw_thumb_writer(fname); + + } + int libraw_dcraw_process(libraw_data_t* lr) + { + if(!lr) return EINVAL; + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->dcraw_process(); + } + libraw_processed_image_t *libraw_dcraw_make_mem_image(libraw_data_t* lr,int *errc) + { + if(!lr) { if(errc) *errc=EINVAL; return NULL;} + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->dcraw_make_mem_image(errc); + } + libraw_processed_image_t *libraw_dcraw_make_mem_thumb(libraw_data_t* lr,int *errc) + { + if(!lr) { if(errc) *errc=EINVAL; return NULL;} + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->dcraw_make_mem_thumb(errc); + } + + void libraw_dcraw_clear_mem(libraw_processed_image_t* p) + { + LibRaw::dcraw_clear_mem(p); + } + + int libraw_raw2image(libraw_data_t* lr) + { + if(!lr) return EINVAL; + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->raw2image(); + } + void libraw_free_image(libraw_data_t* lr) + { + if(!lr) return; + LibRaw *ip = (LibRaw*) lr->parent_class; + ip->free_image(); + } + int libraw_get_decoder_info(libraw_data_t* lr,libraw_decoder_info_t *d) + { + if(!lr || !d) return EINVAL; + LibRaw *ip = (LibRaw*) lr->parent_class; + return ip->get_decoder_info(d); + } +#ifdef __cplusplus +} +#endif diff --git a/Source/LibRawLite/src/libraw_cxx.cpp b/Source/LibRawLite/src/libraw_cxx.cpp index 89d5f04..218460c 100644 --- a/Source/LibRawLite/src/libraw_cxx.cpp +++ b/Source/LibRawLite/src/libraw_cxx.cpp @@ -1,2814 +1,2814 @@ -/* -*- C++ -*- - * File: libraw_cxx.cpp - * Copyright 2008-2010 LibRaw LLC (info@libraw.org) - * Created: Sat Mar 8 , 2008 - * - * LibRaw C++ interface (implementation) - -LibRaw is free software; you can redistribute it and/or modify -it under the terms of the one of three licenses as you choose: - -1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - (See file LICENSE.LGPL provided in LibRaw distribution archive for details). - -2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - (See file LICENSE.CDDL provided in LibRaw distribution archive for details). - -3. LibRaw Software License 27032010 - (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). - - */ - -#include -#include -#include -#include -#include -#include -#include -#ifndef WIN32 -#include -#else -#include -#endif -#define LIBRAW_LIBRARY_BUILD -#include "libraw/libraw.h" -#include "internal/defines.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - void default_memory_callback(void *,const char *file,const char *where) - { - fprintf (stderr,"%s: Out of memory in %s\n", file?file:"unknown file", where); - } - - void default_data_callback(void*,const char *file, const int offset) - { - if(offset < 0) - fprintf (stderr,"%s: Unexpected end of file\n", file?file:"unknown file"); - else - fprintf (stderr,"%s: data corrupted at %d\n",file?file:"unknown file",offset); - } - const char *libraw_strerror(int e) - { - enum LibRaw_errors errorcode = (LibRaw_errors)e; - switch(errorcode) - { - case LIBRAW_SUCCESS: - return "No error"; - case LIBRAW_UNSPECIFIED_ERROR: - return "Unspecified error"; - case LIBRAW_FILE_UNSUPPORTED: - return "Unsupported file format or not RAW file"; - case LIBRAW_REQUEST_FOR_NONEXISTENT_IMAGE: - return "Request for nonexisting image number"; - case LIBRAW_OUT_OF_ORDER_CALL: - return "Out of order call of libraw function"; - case LIBRAW_NO_THUMBNAIL: - return "No thumbnail in file"; - case LIBRAW_UNSUPPORTED_THUMBNAIL: - return "Unsupported thumbnail format"; - case LIBRAW_UNSUFFICIENT_MEMORY: - return "Unsufficient memory"; - case LIBRAW_DATA_ERROR: - return "Corrupted data or unexpected EOF"; - case LIBRAW_IO_ERROR: - return "Input/output error"; - case LIBRAW_CANCELLED_BY_CALLBACK: - return "Cancelled by user callback"; - case LIBRAW_BAD_CROP: - return "Bad crop box"; - default: - return "Unknown error code"; - } - } - -#ifdef __cplusplus -} -#endif - - -const double LibRaw_constants::xyz_rgb[3][3] = -{ - { 0.412453, 0.357580, 0.180423 }, - { 0.212671, 0.715160, 0.072169 }, - { 0.019334, 0.119193, 0.950227 } -}; - -const float LibRaw_constants::d65_white[3] = { 0.950456f, 1.0f, 1.088754f }; - -#define P1 imgdata.idata -#define S imgdata.sizes -#define O imgdata.params -#define C imgdata.color -#define T imgdata.thumbnail -#define IO libraw_internal_data.internal_output_params -#define ID libraw_internal_data.internal_data - -#define EXCEPTION_HANDLER(e) do{ \ - /* fprintf(stderr,"Exception %d caught\n",e);*/ \ - switch(e) \ - { \ - case LIBRAW_EXCEPTION_ALLOC: \ - recycle(); \ - return LIBRAW_UNSUFFICIENT_MEMORY; \ - case LIBRAW_EXCEPTION_DECODE_RAW: \ - case LIBRAW_EXCEPTION_DECODE_JPEG: \ - recycle(); \ - return LIBRAW_DATA_ERROR; \ - case LIBRAW_EXCEPTION_DECODE_JPEG2000: \ - recycle(); \ - return LIBRAW_DATA_ERROR; \ - case LIBRAW_EXCEPTION_IO_EOF: \ - case LIBRAW_EXCEPTION_IO_CORRUPT: \ - recycle(); \ - return LIBRAW_IO_ERROR; \ - case LIBRAW_EXCEPTION_CANCELLED_BY_CALLBACK:\ - recycle(); \ - return LIBRAW_CANCELLED_BY_CALLBACK; \ - case LIBRAW_EXCEPTION_BAD_CROP: \ - recycle(); \ - return LIBRAW_BAD_CROP; \ - default: \ - return LIBRAW_UNSPECIFIED_ERROR; \ - } \ - }while(0) - -const char* LibRaw::version() { return LIBRAW_VERSION_STR;} -int LibRaw::versionNumber() { return LIBRAW_VERSION; } -const char* LibRaw::strerror(int p) { return libraw_strerror(p);} - - -void LibRaw::derror() -{ - if (!libraw_internal_data.unpacker_data.data_error && libraw_internal_data.internal_data.input) - { - if (libraw_internal_data.internal_data.input->eof()) - { - if(callbacks.data_cb)(*callbacks.data_cb)(callbacks.datacb_data, - libraw_internal_data.internal_data.input->fname(),-1); - throw LIBRAW_EXCEPTION_IO_EOF; - } - else - { - if(callbacks.data_cb)(*callbacks.data_cb)(callbacks.datacb_data, - libraw_internal_data.internal_data.input->fname(), - libraw_internal_data.internal_data.input->tell()); - throw LIBRAW_EXCEPTION_IO_CORRUPT; - } - } - libraw_internal_data.unpacker_data.data_error++; -} - -void LibRaw::dcraw_clear_mem(libraw_processed_image_t* p) -{ - if(p) ::free(p); -} - -#define ZERO(a) memset(&a,0,sizeof(a)) - - -LibRaw:: LibRaw(unsigned int flags) -{ - double aber[4] = {1,1,1,1}; - double gamm[6] = { 0.45,4.5,0,0,0,0 }; - unsigned greybox[4] = { 0, 0, UINT_MAX, UINT_MAX }; - unsigned cropbox[4] = { 0, 0, UINT_MAX, UINT_MAX }; -#ifdef DCRAW_VERBOSE - verbose = 1; -#else - verbose = 0; -#endif - ZERO(imgdata); - ZERO(libraw_internal_data); - ZERO(callbacks); - callbacks.mem_cb = (flags & LIBRAW_OPIONS_NO_MEMERR_CALLBACK) ? NULL: &default_memory_callback; - callbacks.data_cb = (flags & LIBRAW_OPIONS_NO_DATAERR_CALLBACK)? NULL : &default_data_callback; - memmove(&imgdata.params.aber,&aber,sizeof(aber)); - memmove(&imgdata.params.gamm,&gamm,sizeof(gamm)); - memmove(&imgdata.params.greybox,&greybox,sizeof(greybox)); - memmove(&imgdata.params.cropbox,&cropbox,sizeof(cropbox)); - - imgdata.params.bright=1; - imgdata.params.use_camera_matrix=-1; - imgdata.params.user_flip=-1; - imgdata.params.user_black=-1; - imgdata.params.user_sat=-1; - imgdata.params.user_qual=-1; - imgdata.params.output_color=1; - imgdata.params.output_bps=8; - imgdata.params.use_fuji_rotate=1; - imgdata.params.exp_shift = 1.0; - imgdata.params.auto_bright_thr = LIBRAW_DEFAULT_AUTO_BRIGHTNESS_THRESHOLD; - imgdata.params.adjust_maximum_thr= LIBRAW_DEFAULT_ADJUST_MAXIMUM_THRESHOLD; - imgdata.params.green_matching = 0; - imgdata.parent_class = this; - imgdata.progress_flags = 0; - tls = new LibRaw_TLS; - tls->init(); -} - - -void* LibRaw:: malloc(size_t t) -{ - void *p = memmgr.malloc(t); - return p; -} -void* LibRaw:: realloc(void *q,size_t t) -{ - void *p = memmgr.realloc(q,t); - return p; -} - - -void* LibRaw:: calloc(size_t n,size_t t) -{ - void *p = memmgr.calloc(n,t); - return p; -} -void LibRaw:: free(void *p) -{ - memmgr.free(p); -} - - -int LibRaw:: fc (int row, int col) -{ - static const char filter[16][16] = - { { 2,1,1,3,2,3,2,0,3,2,3,0,1,2,1,0 }, - { 0,3,0,2,0,1,3,1,0,1,1,2,0,3,3,2 }, - { 2,3,3,2,3,1,1,3,3,1,2,1,2,0,0,3 }, - { 0,1,0,1,0,2,0,2,2,0,3,0,1,3,2,1 }, - { 3,1,1,2,0,1,0,2,1,3,1,3,0,1,3,0 }, - { 2,0,0,3,3,2,3,1,2,0,2,0,3,2,2,1 }, - { 2,3,3,1,2,1,2,1,2,1,1,2,3,0,0,1 }, - { 1,0,0,2,3,0,0,3,0,3,0,3,2,1,2,3 }, - { 2,3,3,1,1,2,1,0,3,2,3,0,2,3,1,3 }, - { 1,0,2,0,3,0,3,2,0,1,1,2,0,1,0,2 }, - { 0,1,1,3,3,2,2,1,1,3,3,0,2,1,3,2 }, - { 2,3,2,0,0,1,3,0,2,0,1,2,3,0,1,0 }, - { 1,3,1,2,3,2,3,2,0,2,0,1,1,0,3,0 }, - { 0,2,0,3,1,0,0,1,1,3,3,2,3,2,2,1 }, - { 2,1,3,2,3,1,2,1,0,3,0,2,0,2,0,2 }, - { 0,3,1,0,0,2,0,3,2,1,3,1,1,3,1,3 } }; - - if (imgdata.idata.filters != 1) return FC(row,col); - return filter[(row+imgdata.sizes.top_margin) & 15][(col+imgdata.sizes.left_margin) & 15]; -} - -void LibRaw:: recycle() -{ - if(libraw_internal_data.internal_data.input && libraw_internal_data.internal_data.input_internal) - { - delete libraw_internal_data.internal_data.input; - libraw_internal_data.internal_data.input = NULL; - } - libraw_internal_data.internal_data.input_internal = 0; -#define FREE(a) do { if(a) { free(a); a = NULL;} }while(0) - - FREE(imgdata.image); - FREE(imgdata.thumbnail.thumb); - FREE(libraw_internal_data.internal_data.meta_data); - FREE(libraw_internal_data.output_data.histogram); - FREE(libraw_internal_data.output_data.oprof); - FREE(imgdata.color.profile); - FREE(imgdata.rawdata.ph1_black); - FREE(imgdata.rawdata.raw_alloc); -#undef FREE - ZERO(imgdata.rawdata); - ZERO(imgdata.sizes); - ZERO(imgdata.color); - ZERO(libraw_internal_data); - memmgr.cleanup(); - imgdata.thumbnail.tformat = LIBRAW_THUMBNAIL_UNKNOWN; - imgdata.progress_flags = 0; - - tls->init(); -} - -const char * LibRaw::unpack_function_name() -{ - libraw_decoder_info_t decoder_info; - get_decoder_info(&decoder_info); - return decoder_info.decoder_name; -} - -int LibRaw::get_decoder_info(libraw_decoder_info_t* d_info) -{ - if(!d_info) return LIBRAW_UNSPECIFIED_ERROR; - if(!load_raw) return LIBRAW_OUT_OF_ORDER_CALL; - - d_info->decoder_flags = LIBRAW_DECODER_NOTSET; - - // sorted names order - if (load_raw == &LibRaw::adobe_dng_load_raw_lj) - { - // Check rbayer - d_info->decoder_name = "adobe_dng_load_raw_lj()"; - d_info->decoder_flags = imgdata.idata.filters ? LIBRAW_DECODER_FLATFIELD : LIBRAW_DECODER_4COMPONENT ; - d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; - } - else if (load_raw == &LibRaw::adobe_dng_load_raw_nc) - { - // Check rbayer - d_info->decoder_name = "adobe_dng_load_raw_nc()"; - d_info->decoder_flags = imgdata.idata.filters ? LIBRAW_DECODER_FLATFIELD : LIBRAW_DECODER_4COMPONENT; - d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; - } - else if (load_raw == &LibRaw::canon_600_load_raw) - { - d_info->decoder_name = "canon_600_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; // WB set within decoder, no need to load raw - } - else if (load_raw == &LibRaw::canon_compressed_load_raw) - { - d_info->decoder_name = "canon_compressed_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::canon_sraw_load_raw) - { - d_info->decoder_name = "canon_sraw_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_LEGACY; - } - else if (load_raw == &LibRaw::eight_bit_load_raw ) - { - d_info->decoder_name = "eight_bit_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; - } - else if (load_raw == &LibRaw::foveon_load_raw ) - { - d_info->decoder_name = "foveon_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_LEGACY; - } - else if (load_raw == &LibRaw::fuji_load_raw ) - { - d_info->decoder_name = "fuji_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::hasselblad_load_raw ) - { - d_info->decoder_name = "hasselblad_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::imacon_full_load_raw ) - { - d_info->decoder_name = "imacon_full_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT; - } - else if (load_raw == &LibRaw::kodak_262_load_raw ) - { - d_info->decoder_name = "kodak_262_load_raw()"; // UNTESTED! - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; - } - else if (load_raw == &LibRaw::kodak_65000_load_raw ) - { - d_info->decoder_name = "kodak_65000_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; - } - else if (load_raw == &LibRaw::kodak_dc120_load_raw ) - { - d_info->decoder_name = "kodak_dc120_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::kodak_jpeg_load_raw ) - { - // UNTESTED + RBAYER - d_info->decoder_name = "kodak_jpeg_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::kodak_radc_load_raw ) - { - d_info->decoder_name = "kodak_radc_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT; - } - else if (load_raw == &LibRaw::kodak_rgb_load_raw ) - { - // UNTESTED - d_info->decoder_name = "kodak_rgb_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT; - } - else if (load_raw == &LibRaw::kodak_yrgb_load_raw ) - { - d_info->decoder_name = "kodak_yrgb_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT; - d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; - } - else if (load_raw == &LibRaw::kodak_ycbcr_load_raw ) - { - // UNTESTED - d_info->decoder_name = "kodak_ycbcr_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT; - d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; - } - else if (load_raw == &LibRaw::leaf_hdr_load_raw ) - { - d_info->decoder_name = "leaf_hdr_load_raw()"; - d_info->decoder_flags = imgdata.idata.filters ? LIBRAW_DECODER_FLATFIELD : LIBRAW_DECODER_4COMPONENT; - } - else if (load_raw == &LibRaw::lossless_jpeg_load_raw) - { - // Check rbayer - d_info->decoder_name = "lossless_jpeg_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD | LIBRAW_DECODER_HASCURVE; - } - else if (load_raw == &LibRaw::minolta_rd175_load_raw ) - { - // UNTESTED - d_info->decoder_name = "minolta_rd175_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::nikon_compressed_load_raw) - { - // Check rbayer - d_info->decoder_name = "nikon_compressed_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::nokia_load_raw ) - { - // UNTESTED - d_info->decoder_name = "nokia_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::olympus_load_raw ) - { - d_info->decoder_name = "olympus_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::packed_load_raw ) - { - d_info->decoder_name = "packed_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::panasonic_load_raw ) - { - d_info->decoder_name = "panasonic_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::pentax_load_raw ) - { - d_info->decoder_name = "pentax_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::phase_one_load_raw ) - { - d_info->decoder_name = "phase_one_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::phase_one_load_raw_c ) - { - d_info->decoder_name = "phase_one_load_raw_c()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::quicktake_100_load_raw ) - { - // UNTESTED - d_info->decoder_name = "quicktake_100_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::rollei_load_raw ) - { - // UNTESTED - d_info->decoder_name = "rollei_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::sinar_4shot_load_raw ) - { - // UNTESTED - d_info->decoder_name = "sinar_4shot_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT; - } - else if (load_raw == &LibRaw::smal_v6_load_raw ) - { - // UNTESTED - d_info->decoder_name = "smal_v6_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::smal_v9_load_raw ) - { - // UNTESTED - d_info->decoder_name = "smal_v9_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::sony_load_raw ) - { - d_info->decoder_name = "sony_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::sony_arw_load_raw ) - { - d_info->decoder_name = "sony_arw_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - } - else if (load_raw == &LibRaw::sony_arw2_load_raw ) - { - d_info->decoder_name = "sony_arw2_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; - } - else if (load_raw == &LibRaw::unpacked_load_raw ) - { - d_info->decoder_name = "unpacked_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD | LIBRAW_DECODER_USEBAYER2; - } - else if (load_raw == &LibRaw::redcine_load_raw) - { - d_info->decoder_name = "redcine_load_raw()"; - d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; - d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; - } - else - { - d_info->decoder_name = "Unknown unpack function"; - d_info->decoder_flags = LIBRAW_DECODER_NOTSET; - } - return LIBRAW_SUCCESS; -} - -int LibRaw::adjust_maximum() -{ - int i; - ushort real_max; - float auto_threshold; - - if(O.adjust_maximum_thr < 0.00001) - return LIBRAW_SUCCESS; - else if (O.adjust_maximum_thr > 0.99999) - auto_threshold = LIBRAW_DEFAULT_ADJUST_MAXIMUM_THRESHOLD; - else - auto_threshold = O.adjust_maximum_thr; - - - real_max = C.channel_maximum[0]; - for(i = 1; i< 4; i++) - if(real_max < C.channel_maximum[i]) - real_max = C.channel_maximum[i]; - - if (real_max > 0 && real_max < C.maximum && real_max > C.maximum* auto_threshold) - { - C.maximum = real_max; - } - return LIBRAW_SUCCESS; -} - - -void LibRaw:: merror (void *ptr, const char *where) -{ - if (ptr) return; - if(callbacks.mem_cb)(*callbacks.mem_cb)(callbacks.memcb_data, - libraw_internal_data.internal_data.input - ?libraw_internal_data.internal_data.input->fname() - :NULL, - where); - throw LIBRAW_EXCEPTION_ALLOC; -} - - - -int LibRaw::open_file(const char *fname, INT64 max_buf_size) -{ -#ifndef WIN32 - struct stat st; - if(stat(fname,&st)) - return LIBRAW_IO_ERROR; - int big = (st.st_size > max_buf_size)?1:0; -#else - struct _stati64 st; - if(_stati64(fname,&st)) - return LIBRAW_IO_ERROR; - int big = (st.st_size > max_buf_size)?1:0; -#endif - - LibRaw_abstract_datastream *stream; - try { - if(big) - stream = new LibRaw_bigfile_datastream(fname); - else - stream = new LibRaw_file_datastream(fname); - } - - catch (std::bad_alloc) - { - recycle(); - return LIBRAW_UNSUFFICIENT_MEMORY; - } - if(!stream->valid()) - { - delete stream; - return LIBRAW_IO_ERROR; - } - ID.input_internal = 0; // preserve from deletion on error - int ret = open_datastream(stream); - if (ret == LIBRAW_SUCCESS) - { - ID.input_internal =1 ; // flag to delete datastream on recycle - } - else - { - delete stream; - ID.input_internal = 0; - } - return ret; -} - -int LibRaw::open_buffer(void *buffer, size_t size) -{ - // this stream will close on recycle() - if(!buffer || buffer==(void*)-1) - return LIBRAW_IO_ERROR; - - LibRaw_buffer_datastream *stream; - try { - stream = new LibRaw_buffer_datastream(buffer,size); - } - catch (std::bad_alloc) - { - recycle(); - return LIBRAW_UNSUFFICIENT_MEMORY; - } - if(!stream->valid()) - { - delete stream; - return LIBRAW_IO_ERROR; - } - ID.input_internal = 0; // preserve from deletion on error - int ret = open_datastream(stream); - if (ret == LIBRAW_SUCCESS) - { - ID.input_internal =1 ; // flag to delete datastream on recycle - } - else - { - delete stream; - ID.input_internal = 0; - } - return ret; -} - - -int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) -{ - - if(!stream) - return ENOENT; - if(!stream->valid()) - return LIBRAW_IO_ERROR; - recycle(); - - try { - ID.input = stream; - SET_PROC_FLAG(LIBRAW_PROGRESS_OPEN); - - if (O.use_camera_matrix < 0) - O.use_camera_matrix = O.use_camera_wb; - - identify(); - - if(IO.fuji_width) - { - IO.fwidth = S.width; - IO.fheight = S.height; - S.iwidth = S.width = IO.fuji_width << (int)(!libraw_internal_data.unpacker_data.fuji_layout); - S.iheight = S.height = S.raw_height; - S.raw_height += 2*S.top_margin; - } - - if(C.profile_length) - { - if(C.profile) free(C.profile); - C.profile = malloc(C.profile_length); - merror(C.profile,"LibRaw::open_file()"); - ID.input->seek(ID.profile_offset,SEEK_SET); - ID.input->read(C.profile,C.profile_length,1); - } - - SET_PROC_FLAG(LIBRAW_PROGRESS_IDENTIFY); - } - catch ( LibRaw_exceptions err) { - EXCEPTION_HANDLER(err); - } - catch (std::exception ee) { - EXCEPTION_HANDLER(LIBRAW_EXCEPTION_IO_CORRUPT); - } - - if(P1.raw_count < 1) - return LIBRAW_FILE_UNSUPPORTED; - - - write_fun = &LibRaw::write_ppm_tiff; - - if (load_raw == &LibRaw::kodak_ycbcr_load_raw) - { - S.height += S.height & 1; - S.width += S.width & 1; - } - - IO.shrink = P1.filters && (O.half_size || - ((O.threshold || O.aber[0] != 1 || O.aber[2] != 1) )); - - S.iheight = (S.height + IO.shrink) >> IO.shrink; - S.iwidth = (S.width + IO.shrink) >> IO.shrink; - - // Save color,sizes and internal data into raw_image fields - memmove(&imgdata.rawdata.color,&imgdata.color,sizeof(imgdata.color)); - memmove(&imgdata.rawdata.sizes,&imgdata.sizes,sizeof(imgdata.sizes)); - memmove(&imgdata.rawdata.iparams,&imgdata.idata,sizeof(imgdata.idata)); - memmove(&imgdata.rawdata.ioparams,&libraw_internal_data.internal_output_params,sizeof(libraw_internal_data.internal_output_params)); - - SET_PROC_FLAG(LIBRAW_PROGRESS_SIZE_ADJUST); - - - return LIBRAW_SUCCESS; -} - -int LibRaw::unpack(void) -{ - CHECK_ORDER_HIGH(LIBRAW_PROGRESS_LOAD_RAW); - CHECK_ORDER_LOW(LIBRAW_PROGRESS_IDENTIFY); - try { - - RUN_CALLBACK(LIBRAW_PROGRESS_LOAD_RAW,0,2); - if (O.shot_select >= P1.raw_count) - return LIBRAW_REQUEST_FOR_NONEXISTENT_IMAGE; - - if(!load_raw) - return LIBRAW_UNSPECIFIED_ERROR; - - if (O.use_camera_matrix && C.cmatrix[0][0] > 0.25) - { - memcpy (C.rgb_cam, C.cmatrix, sizeof (C.cmatrix)); - IO.raw_color = 0; - } - // already allocated ? - if(imgdata.image) - { - free(imgdata.image); - imgdata.image = 0; - } - - if (libraw_internal_data.unpacker_data.meta_length) - { - libraw_internal_data.internal_data.meta_data = - (char *) malloc (libraw_internal_data.unpacker_data.meta_length); - merror (libraw_internal_data.internal_data.meta_data, "LibRaw::unpack()"); - } - ID.input->seek(libraw_internal_data.unpacker_data.data_offset, SEEK_SET); - int save_document_mode = O.document_mode; - O.document_mode = 0; - - libraw_decoder_info_t decoder_info; - get_decoder_info(&decoder_info); - - int save_iwidth = S.iwidth, save_iheight = S.iheight, save_shrink = IO.shrink; - - int rwidth = S.raw_width, rheight = S.raw_height; - if( !IO.fuji_width) - { - // adjust non-Fuji allocation - if(rwidth < S.width + S.left_margin) - rwidth = S.width + S.left_margin; - if(rheight < S.height + S.top_margin) - rheight = S.height + S.top_margin; - } - - if(decoder_info.decoder_flags & LIBRAW_DECODER_FLATFIELD) - { - imgdata.rawdata.raw_alloc = malloc(rwidth*rheight*sizeof(imgdata.rawdata.raw_image[0])); - imgdata.rawdata.raw_image = (ushort*) imgdata.rawdata.raw_alloc; - } - else if (decoder_info.decoder_flags & LIBRAW_DECODER_4COMPONENT) - { - S.iwidth = S.width; - S.iheight= S.height; - IO.shrink = 0; - imgdata.rawdata.raw_alloc = calloc(rwidth*rheight,sizeof(*imgdata.rawdata.color_image)); - imgdata.rawdata.color_image = (ushort(*)[4]) imgdata.rawdata.raw_alloc; - } - else if (decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY) - { - // sRAW and Foveon only, so extra buffer size is just 1/4 - // Legacy converters does not supports half mode! - S.iwidth = S.width; - S.iheight= S.height; - IO.shrink = 0; - // allocate image as temporary buffer, size - imgdata.rawdata.raw_alloc = calloc(S.iwidth*S.iheight,sizeof(*imgdata.image)); - imgdata.image = (ushort (*)[4]) imgdata.rawdata.raw_alloc; - } - - - (this->*load_raw)(); - - - // recover saved - if( decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY) - { - imgdata.image = 0; - imgdata.rawdata.color_image = (ushort (*)[4]) imgdata.rawdata.raw_alloc; - } - - // calculate channel maximum - { - for(int c=0;c<4;c++) C.channel_maximum[c] = 0; - if(decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY) - { - for(int rc = 0; rc < S.iwidth*S.iheight; rc++) - { - if(C.channel_maximum[0] C.cblack[c]) i = C.cblack[c]; - for (c=0;c<4;c++) - C.cblack[c] -= i; - C.black += i; - - - // Save color,sizes and internal data into raw_image fields - memmove(&imgdata.rawdata.color,&imgdata.color,sizeof(imgdata.color)); - memmove(&imgdata.rawdata.sizes,&imgdata.sizes,sizeof(imgdata.sizes)); - memmove(&imgdata.rawdata.iparams,&imgdata.idata,sizeof(imgdata.idata)); - memmove(&imgdata.rawdata.ioparams,&libraw_internal_data.internal_output_params,sizeof(libraw_internal_data.internal_output_params)); - - SET_PROC_FLAG(LIBRAW_PROGRESS_LOAD_RAW); - RUN_CALLBACK(LIBRAW_PROGRESS_LOAD_RAW,1,2); - - return 0; - } - catch ( LibRaw_exceptions err) { - EXCEPTION_HANDLER(err); - } - catch (std::exception ee) { - EXCEPTION_HANDLER(LIBRAW_EXCEPTION_IO_CORRUPT); - } -} - -void LibRaw::free_image(void) -{ - if(imgdata.image) - { - free(imgdata.image); - imgdata.image = 0; - imgdata.progress_flags - = LIBRAW_PROGRESS_START|LIBRAW_PROGRESS_OPEN - |LIBRAW_PROGRESS_IDENTIFY|LIBRAW_PROGRESS_SIZE_ADJUST|LIBRAW_PROGRESS_LOAD_RAW; - } -} - - -void LibRaw::raw2image_start() -{ - // restore color,sizes and internal data into raw_image fields - memmove(&imgdata.color,&imgdata.rawdata.color,sizeof(imgdata.color)); - memmove(&imgdata.sizes,&imgdata.rawdata.sizes,sizeof(imgdata.sizes)); - memmove(&imgdata.idata,&imgdata.rawdata.iparams,sizeof(imgdata.idata)); - memmove(&libraw_internal_data.internal_output_params,&imgdata.rawdata.ioparams,sizeof(libraw_internal_data.internal_output_params)); - - if (O.user_flip >= 0) - S.flip = O.user_flip; - - switch ((S.flip+3600) % 360) - { - case 270: S.flip = 5; break; - case 180: S.flip = 3; break; - case 90: S.flip = 6; break; - } - - // adjust for half mode! - IO.shrink = P1.filters && (O.half_size || - ((O.threshold || O.aber[0] != 1 || O.aber[2] != 1) )); - - S.iheight = (S.height + IO.shrink) >> IO.shrink; - S.iwidth = (S.width + IO.shrink) >> IO.shrink; - - if (O.user_black >= 0) - C.black = O.user_black; -} - -// Same as raw2image, but -// 1) Do raw2image and rotate_fuji_raw in one pass -// 2) Do raw2image and cropping in one pass -#ifndef MIN -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#endif -int LibRaw::raw2image_ex(void) -{ - CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW); - - raw2image_start(); - - // process cropping - int do_crop = 0; - unsigned save_filters = imgdata.idata.filters; - unsigned save_width = S.width; - if (~O.cropbox[2] && ~O.cropbox[3]) - { - int crop[4],c,filt; - for(int c=0;c<4;c++) - { - crop[c] = O.cropbox[c]; - if(crop[c]<0) - crop[c]=0; - } - if(IO.fwidth) - { - crop[0] = (crop[0]/4)*4; - crop[1] = (crop[1]/4)*4; - } - do_crop = 1; - crop[2] = MIN (crop[2], (signed) S.width-crop[0]); - crop[3] = MIN (crop[3], (signed) S.height-crop[1]); - if (crop[2] <= 0 || crop[3] <= 0) - throw LIBRAW_EXCEPTION_BAD_CROP; - - // adjust sizes! - S.left_margin+=crop[0]; - S.top_margin+=crop[1]; - S.width=crop[2]; - S.height=crop[3]; - - S.iheight = (S.height + IO.shrink) >> IO.shrink; - S.iwidth = (S.width + IO.shrink) >> IO.shrink; - if(!IO.fwidth && imgdata.idata.filters) - { - for (filt=c=0; c < 16; c++) - filt |= FC((c >> 1)+(crop[1]), - (c & 1)+(crop[0])) << c*2; - imgdata.idata.filters = filt; - } - } - - if(IO.fwidth) - { - ushort fiwidth,fiheight; - if(do_crop) - { - IO.fuji_width = S.width >> !libraw_internal_data.unpacker_data.fuji_layout; - IO.fwidth = (S.height >> libraw_internal_data.unpacker_data.fuji_layout) + IO.fuji_width; - IO.fheight = IO.fwidth - 1; - } - - fiheight = (IO.fheight + IO.shrink) >> IO.shrink; - fiwidth = (IO.fwidth + IO.shrink) >> IO.shrink; - if(imgdata.image) - { - imgdata.image = (ushort (*)[4])realloc(imgdata.image,fiheight*fiwidth*sizeof (*imgdata.image)); - memset(imgdata.image,0,fiheight*fiwidth *sizeof (*imgdata.image)); - } - else - imgdata.image = (ushort (*)[4]) calloc (fiheight*fiwidth, sizeof (*imgdata.image)); - merror (imgdata.image, "raw2image_ex()"); - - int cblk[4],i; - for(i=0;i<4;i++) - cblk[i] = C.cblack[i]+C.black; - ZERO(C.channel_maximum); - - int row,col; - for(row=0;row> 1); - c = col + ((row+1) >> 1); - } else { - r = IO.fuji_width - 1 + row - (col >> 1); - c = row + ((col+1) >> 1); - } - - int val = imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width - +(col+S.left_margin)]; - int cc = FCF(row,col); - if(val > cblk[cc]) - val -= cblk[cc]; - else - val = 0; - imgdata.image[((r) >> IO.shrink)*fiwidth + ((c) >> IO.shrink)][cc] = val; - if(C.channel_maximum[cc] < val) C.channel_maximum[cc] = val; - } - } - C.maximum -= C.black; - ZERO(C.cblack); - C.black = 0; - - // restore fuji sizes! - S.height = IO.fheight; - S.width = IO.fwidth; - S.iheight = (S.height + IO.shrink) >> IO.shrink; - S.iwidth = (S.width + IO.shrink) >> IO.shrink; - S.raw_height -= 2*S.top_margin; - } - else - { - - if(imgdata.image) - { - imgdata.image = (ushort (*)[4]) realloc (imgdata.image,S.iheight*S.iwidth - *sizeof (*imgdata.image)); - memset(imgdata.image,0,S.iheight*S.iwidth *sizeof (*imgdata.image)); - } - else - imgdata.image = (ushort (*)[4]) calloc (S.iheight*S.iwidth, sizeof (*imgdata.image)); - - merror (imgdata.image, "raw2image_ex()"); - - libraw_decoder_info_t decoder_info; - get_decoder_info(&decoder_info); - - - if(decoder_info.decoder_flags & LIBRAW_DECODER_FLATFIELD) - { - if(decoder_info.decoder_flags & LIBRAW_DECODER_USEBAYER2) -#if defined(LIBRAW_USE_OPENMP) -#pragma omp parallel for default(shared) -#endif - for(int row = 0; row < S.height; row++) - for(int col = 0; col < S.width; col++) - imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][fc(row,col)] - = imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width - +(col+S.left_margin)]; - else -#if defined(LIBRAW_USE_OPENMP) -#pragma omp parallel for default(shared) -#endif - for(int row = 0; row < S.height; row++) - { - int colors[2]; - for (int xx=0;xx<2;xx++) - colors[xx] = COLOR(row,xx); - for(int col = 0; col < S.width; col++) - { - int cc = colors[col&1]; - imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][cc] = - imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width - +(col+S.left_margin)]; - } - } - } - else if (decoder_info.decoder_flags & LIBRAW_DECODER_4COMPONENT) - { -#define FC0(row,col) (save_filters >> ((((row) << 1 & 14) + ((col) & 1)) << 1) & 3) - if(IO.shrink) -#if defined(LIBRAW_USE_OPENMP) -#pragma omp parallel for default(shared) -#endif - for(int row = 0; row < S.height; row++) - for(int col = 0; col < S.width; col++) - imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][FC(row,col)] - = imgdata.rawdata.color_image[(row+S.top_margin)*S.raw_width - +S.left_margin+col] - [FC0(row+S.top_margin,col+S.left_margin)]; -#undef FC0 - else -#if defined(LIBRAW_USE_OPENMP) -#pragma omp parallel for default(shared) -#endif - for(int row = 0; row < S.height; row++) - memmove(&imgdata.image[row*S.width], - &imgdata.rawdata.color_image[(row+S.top_margin)*S.raw_width+S.left_margin], - S.width*sizeof(*imgdata.image)); - } - else if(decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY) - { - if(do_crop) -#if defined(LIBRAW_USE_OPENMP) -#pragma omp parallel for default(shared) -#endif - for(int row = 0; row < S.height; row++) - memmove(&imgdata.image[row*S.width], - &imgdata.rawdata.color_image[(row+S.top_margin)*save_width+S.left_margin], - S.width*sizeof(*imgdata.image)); - - else - memmove(imgdata.image,imgdata.rawdata.color_image, - S.width*S.height*sizeof(*imgdata.image)); - } - - if(imgdata.rawdata.use_ph1_correct) // Phase one unpacked! - phase_one_correct(); - } - return LIBRAW_SUCCESS; -} - -#undef MIN - - - - -int LibRaw::raw2image(void) -{ - - CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW); - - try { - raw2image_start(); - - // free and re-allocate image bitmap - if(imgdata.image) - { - imgdata.image = (ushort (*)[4]) realloc (imgdata.image,S.iheight*S.iwidth *sizeof (*imgdata.image)); - memset(imgdata.image,0,S.iheight*S.iwidth *sizeof (*imgdata.image)); - } - else - imgdata.image = (ushort (*)[4]) calloc (S.iheight*S.iwidth, sizeof (*imgdata.image)); - - merror (imgdata.image, "raw2image()"); - - libraw_decoder_info_t decoder_info; - get_decoder_info(&decoder_info); - - // Move saved bitmap to imgdata.image - if(decoder_info.decoder_flags & LIBRAW_DECODER_FLATFIELD) - { - if(decoder_info.decoder_flags & LIBRAW_DECODER_USEBAYER2) - { - for(int row = 0; row < S.height; row++) - for(int col = 0; col < S.width; col++) - imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][fc(row,col)] - = imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width - +(col+S.left_margin)]; - } - else - { - for(int row = 0; row < S.height; row++) - { - int colors[4]; - for (int xx=0;xx<4;xx++) - colors[xx] = COLOR(row,xx); - for(int col = 0; col < S.width; col++) - { - int cc = colors[col&3]; - imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][cc] = - imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width+(col - +S.left_margin)]; - } - } - } - } - else if (decoder_info.decoder_flags & LIBRAW_DECODER_4COMPONENT) - { - if(IO.shrink) - { - for(int row = 0; row < S.height; row++) - for(int col = 0; col < S.width; col++) - { - int cc = FC(row,col); - imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][cc] - = imgdata.rawdata.color_image[(row+S.top_margin)*S.raw_width - +S.left_margin+col][cc]; - } - } - else - for(int row = 0; row < S.height; row++) - memmove(&imgdata.image[row*S.width], - &imgdata.rawdata.color_image[(row+S.top_margin)*S.raw_width+S.left_margin], - S.width*sizeof(*imgdata.image)); - } - else if(decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY) - { - // legacy is always 4channel and not shrinked! - memmove(imgdata.image,imgdata.rawdata.color_image,S.width*S.height*sizeof(*imgdata.image)); - } - - if(imgdata.rawdata.use_ph1_correct) // Phase one unpacked! - phase_one_correct(); - - // hack - clear later flags! - imgdata.progress_flags - = LIBRAW_PROGRESS_START|LIBRAW_PROGRESS_OPEN - |LIBRAW_PROGRESS_IDENTIFY|LIBRAW_PROGRESS_SIZE_ADJUST|LIBRAW_PROGRESS_LOAD_RAW; - return 0; - } - catch ( LibRaw_exceptions err) { - EXCEPTION_HANDLER(err); - } -} - - -int LibRaw::dcraw_document_mode_processing(void) -{ -// CHECK_ORDER_HIGH(LIBRAW_PROGRESS_PRE_INTERPOLATE); - CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW); - - try { - - int no_crop = 1; - - if (~O.cropbox[2] && ~O.cropbox[3]) - no_crop=0; - - raw2image_ex(); // raw2image+crop+rotate_fuji_raw - - if (IO.zero_is_bad) - { - remove_zeroes(); - SET_PROC_FLAG(LIBRAW_PROGRESS_REMOVE_ZEROES); - } - - if(!IO.fuji_width) - subtract_black(); - - O.document_mode = 2; - - if(P1.is_foveon) - { - // filter image data for foveon document mode - short *iptr = (short *)imgdata.image; - for (int i=0; i < S.height*S.width*4; i++) - { - if ((short) iptr[i] < 0) - iptr[i] = 0; - } - SET_PROC_FLAG(LIBRAW_PROGRESS_FOVEON_INTERPOLATE); - } - - O.use_fuji_rotate = 0; - - if(O.bad_pixels && no_crop) - { - bad_pixels(O.bad_pixels); - SET_PROC_FLAG(LIBRAW_PROGRESS_BAD_PIXELS); - } - if (O.dark_frame && no_crop) - { - subtract (O.dark_frame); - SET_PROC_FLAG(LIBRAW_PROGRESS_DARK_FRAME); - } - - - adjust_maximum(); - - if (O.user_sat > 0) - C.maximum = O.user_sat; - - pre_interpolate(); - SET_PROC_FLAG(LIBRAW_PROGRESS_PRE_INTERPOLATE); - - if (libraw_internal_data.internal_output_params.mix_green) - { - int i; - for (P1.colors=3, i=0; i < S.height*S.width; i++) - imgdata.image[i][1] = (imgdata.image[i][1] + imgdata.image[i][3]) >> 1; - } - SET_PROC_FLAG(LIBRAW_PROGRESS_MIX_GREEN); - - if (!P1.is_foveon && P1.colors == 3) - median_filter(); - SET_PROC_FLAG(LIBRAW_PROGRESS_MEDIAN_FILTER); - - if (!P1.is_foveon && O.highlight == 2) - blend_highlights(); - - if (!P1.is_foveon && O.highlight > 2) - recover_highlights(); - SET_PROC_FLAG(LIBRAW_PROGRESS_HIGHLIGHTS); - - if (O.use_fuji_rotate) - fuji_rotate(); - SET_PROC_FLAG(LIBRAW_PROGRESS_FUJI_ROTATE); -#ifndef NO_LCMS - if(O.camera_profile) - { - apply_profile(O.camera_profile,O.output_profile); - SET_PROC_FLAG(LIBRAW_PROGRESS_APPLY_PROFILE); - } -#endif - if(!libraw_internal_data.output_data.histogram) - { - libraw_internal_data.output_data.histogram = (int (*)[LIBRAW_HISTOGRAM_SIZE]) malloc(sizeof(*libraw_internal_data.output_data.histogram)*4); - merror(libraw_internal_data.output_data.histogram,"LibRaw::dcraw_document_mode_processing()"); - } - convert_to_rgb(); - SET_PROC_FLAG(LIBRAW_PROGRESS_CONVERT_RGB); - - if (O.use_fuji_rotate) - stretch(); - SET_PROC_FLAG(LIBRAW_PROGRESS_STRETCH); - - return 0; - } - catch ( LibRaw_exceptions err) { - EXCEPTION_HANDLER(err); - } - -} - -#if 1 - -libraw_processed_image_t * LibRaw::dcraw_make_mem_thumb(int *errcode) -{ - if(!T.thumb) - { - if ( !ID.toffset) - { - if(errcode) *errcode= LIBRAW_NO_THUMBNAIL; - } - else - { - if(errcode) *errcode= LIBRAW_OUT_OF_ORDER_CALL; - } - return NULL; - } - - if (T.tformat == LIBRAW_THUMBNAIL_BITMAP) - { - libraw_processed_image_t * ret = - (libraw_processed_image_t *)::malloc(sizeof(libraw_processed_image_t)+T.tlength); - - if(!ret) - { - if(errcode) *errcode= ENOMEM; - return NULL; - } - - memset(ret,0,sizeof(libraw_processed_image_t)); - ret->type = LIBRAW_IMAGE_BITMAP; - ret->height = T.theight; - ret->width = T.twidth; - ret->colors = 3; - ret->bits = 8; - ret->data_size = T.tlength; - memmove(ret->data,T.thumb,T.tlength); - if(errcode) *errcode= 0; - return ret; - } - else if (T.tformat == LIBRAW_THUMBNAIL_JPEG) - { - ushort exif[5]; - int mk_exif = 0; - if(strcmp(T.thumb+6,"Exif")) mk_exif = 1; - - int dsize = T.tlength + mk_exif * (sizeof(exif)+sizeof(tiff_hdr)); - - libraw_processed_image_t * ret = - (libraw_processed_image_t *)::malloc(sizeof(libraw_processed_image_t)+dsize); - - if(!ret) - { - if(errcode) *errcode= ENOMEM; - return NULL; - } - - memset(ret,0,sizeof(libraw_processed_image_t)); - - ret->type = LIBRAW_IMAGE_JPEG; - ret->data_size = dsize; - - ret->data[0] = 0xff; - ret->data[1] = 0xd8; - if(mk_exif) - { - struct tiff_hdr th; - memcpy (exif, "\xff\xe1 Exif\0\0", 10); - exif[1] = htons (8 + sizeof th); - memmove(ret->data+2,exif,sizeof(exif)); - tiff_head (&th, 0); - memmove(ret->data+(2+sizeof(exif)),&th,sizeof(th)); - memmove(ret->data+(2+sizeof(exif)+sizeof(th)),T.thumb+2,T.tlength-2); - } - else - { - memmove(ret->data+2,T.thumb+2,T.tlength-2); - } - if(errcode) *errcode= 0; - return ret; - - } - else - { - if(errcode) *errcode= LIBRAW_UNSUPPORTED_THUMBNAIL; - return NULL; - - } -} - - - -// jlb -// macros for copying pixels to either BGR or RGB formats -#define FORBGR for(c=P1.colors-1; c >=0 ; c--) -#define FORRGB for(c=0; c < P1.colors ; c++) - -void LibRaw::get_mem_image_format(int* width, int* height, int* colors, int* bps) const - -{ - if (S.flip & 4) { - *width = S.height; - *height = S.width; - } - else { - *width = S.width; - *height = S.height; - } - *colors = P1.colors; - *bps = O.output_bps; -} - -int LibRaw::copy_mem_image(void* scan0, int stride, int bgr) - -{ - // the image memory pointed to by scan0 is assumed to be in the format returned by get_mem_image_format - if((imgdata.progress_flags & LIBRAW_PROGRESS_THUMB_MASK) < LIBRAW_PROGRESS_PRE_INTERPOLATE) - return LIBRAW_OUT_OF_ORDER_CALL; - - if(libraw_internal_data.output_data.histogram) - { - int perc, val, total, t_white=0x2000,c; - perc = S.width * S.height * 0.01; /* 99th percentile white level */ - if (IO.fuji_width) perc /= 2; - if (!((O.highlight & ~2) || O.no_auto_bright)) - for (t_white=c=0; c < P1.colors; c++) { - for (val=0x2000, total=0; --val > 32; ) - if ((total += libraw_internal_data.output_data.histogram[c][val]) > perc) break; - if (t_white < val) t_white = val; - } - gamma_curve (O.gamm[0], O.gamm[1], 2, (t_white << 3)/O.bright); - } - - int s_iheight = S.iheight; - int s_iwidth = S.iwidth; - int s_width = S.width; - int s_hwight = S.height; - - S.iheight = S.height; - S.iwidth = S.width; - - if (S.flip & 4) SWAP(S.height,S.width); - uchar *ppm; - ushort *ppm2; - int c, row, col, soff, rstep, cstep; - - soff = flip_index (0, 0); - cstep = flip_index (0, 1) - soff; - rstep = flip_index (1, 0) - flip_index (0, S.width); - - for (row=0; row < S.height; row++, soff += rstep) - { - uchar *bufp = ((uchar*)scan0)+row*stride; - ppm2 = (ushort*) (ppm = bufp); - // keep trivial decisions in the outer loop for speed - if (bgr) { - if (O.output_bps == 8) { - for (col=0; col < S.width; col++, soff += cstep) - FORBGR *ppm++ = imgdata.color.curve[imgdata.image[soff][c]]>>8; - } - else { - for (col=0; col < S.width; col++, soff += cstep) - FORBGR *ppm2++ = imgdata.color.curve[imgdata.image[soff][c]]; - } - } - else { - if (O.output_bps == 8) { - for (col=0; col < S.width; col++, soff += cstep) - FORRGB *ppm++ = imgdata.color.curve[imgdata.image[soff][c]]>>8; - } - else { - for (col=0; col < S.width; col++, soff += cstep) - FORRGB *ppm2++ = imgdata.color.curve[imgdata.image[soff][c]]; - } - } - -// bufp += stride; // go to the next line - } - - S.iheight = s_iheight; - S.iwidth = s_iwidth; - S.width = s_width; - S.height = s_hwight; - - return 0; - - -} -#undef FORBGR -#undef FORRGB - - - -libraw_processed_image_t *LibRaw::dcraw_make_mem_image(int *errcode) - -{ - int width, height, colors, bps; - get_mem_image_format(&width, &height, &colors, &bps); - int stride = width * (bps/8) * colors; - unsigned ds = height * stride; - libraw_processed_image_t *ret = (libraw_processed_image_t*)::malloc(sizeof(libraw_processed_image_t)+ds); - if(!ret) - { - if(errcode) *errcode= ENOMEM; - return NULL; - } - memset(ret,0,sizeof(libraw_processed_image_t)); - - // metadata init - ret->type = LIBRAW_IMAGE_BITMAP; - ret->height = height; - ret->width = width; - ret->colors = colors; - ret->bits = bps; - ret->data_size = ds; - copy_mem_image(ret->data, stride, 0); - - return ret; -} - -#undef FORC -#undef FORCC -#undef SWAP -#endif - - -int LibRaw::dcraw_ppm_tiff_writer(const char *filename) -{ - CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW); - - if(!imgdata.image) - return LIBRAW_OUT_OF_ORDER_CALL; - - if(!filename) - return ENOENT; - FILE *f = fopen(filename,"wb"); - - if(!f) - return errno; - - try { - if(!libraw_internal_data.output_data.histogram) - { - libraw_internal_data.output_data.histogram = - (int (*)[LIBRAW_HISTOGRAM_SIZE]) malloc(sizeof(*libraw_internal_data.output_data.histogram)*4); - merror(libraw_internal_data.output_data.histogram,"LibRaw::dcraw_ppm_tiff_writer()"); - } - libraw_internal_data.internal_data.output = f; - write_ppm_tiff(); - SET_PROC_FLAG(LIBRAW_PROGRESS_FLIP); - libraw_internal_data.internal_data.output = NULL; - fclose(f); - return 0; - } - catch ( LibRaw_exceptions err) { - fclose(f); - EXCEPTION_HANDLER(err); - } -} - -void LibRaw::kodak_thumb_loader() -{ - // some kodak cameras - ushort s_height = S.height, s_width = S.width,s_iwidth = S.iwidth,s_iheight=S.iheight; - int s_colors = P1.colors; - unsigned s_filters = P1.filters; - ushort (*s_image)[4] = imgdata.image; - - - S.height = T.theight; - S.width = T.twidth; - P1.filters = 0; - - if (thumb_load_raw == &CLASS kodak_ycbcr_load_thumb) - { - S.height += S.height & 1; - S.width += S.width & 1; - } - - imgdata.image = (ushort (*)[4]) calloc (S.iheight*S.iwidth, sizeof (*imgdata.image)); - merror (imgdata.image, "LibRaw::kodak_thumb_loader()"); - - ID.input->seek(ID.toffset, SEEK_SET); - // read kodak thumbnail into T.image[] - (this->*thumb_load_raw)(); - - // copy-n-paste from image pipe -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) > (b) ? (a) : (b)) -#define LIM(x,min,max) MAX(min,MIN(x,max)) -#define CLIP(x) LIM(x,0,65535) -#define SWAP(a,b) { a ^= b; a ^= (b ^= a); } - - // from scale_colors - { - double dmax; - float scale_mul[4]; - int c,val; - for (dmax=DBL_MAX, c=0; c < 3; c++) - if (dmax > C.pre_mul[c]) - dmax = C.pre_mul[c]; - - for( c=0; c< 3; c++) - scale_mul[c] = (C.pre_mul[c] / dmax) * 65535.0 / C.maximum; - scale_mul[3] = scale_mul[1]; - - size_t size = S.height * S.width; - for (unsigned i=0; i < size*4 ; i++) - { - val = imgdata.image[0][i]; - if(!val) continue; - val *= scale_mul[i & 3]; - imgdata.image[0][i] = CLIP(val); - } - } - - // from convert_to_rgb - ushort *img; - int row,col; - - int (*t_hist)[LIBRAW_HISTOGRAM_SIZE] = (int (*)[LIBRAW_HISTOGRAM_SIZE]) calloc(sizeof(*t_hist),4); - merror (t_hist, "LibRaw::kodak_thumb_loader()"); - - float out[3], - out_cam[3][4] = - { - {2.81761312, -1.98369181, 0.166078627, 0}, - {-0.111855984, 1.73688626, -0.625030339, 0}, - {-0.0379119813, -0.891268849, 1.92918086, 0} - }; - - for (img=imgdata.image[0], row=0; row < S.height; row++) - for (col=0; col < S.width; col++, img+=4) - { - out[0] = out[1] = out[2] = 0; - int c; - for(c=0;c<3;c++) - { - out[0] += out_cam[0][c] * img[c]; - out[1] += out_cam[1][c] * img[c]; - out[2] += out_cam[2][c] * img[c]; - } - for(c=0; c<3; c++) - img[c] = CLIP((int) out[c]); - for(c=0; c> 3]++; - - } - - // from gamma_lut - int (*save_hist)[LIBRAW_HISTOGRAM_SIZE] = libraw_internal_data.output_data.histogram; - libraw_internal_data.output_data.histogram = t_hist; - - // make curve output curve! - ushort (*t_curve) = (ushort*) calloc(sizeof(C.curve),1); - merror (t_curve, "LibRaw::kodak_thumb_loader()"); - memmove(t_curve,C.curve,sizeof(C.curve)); - memset(C.curve,0,sizeof(C.curve)); - { - int perc, val, total, t_white=0x2000,c; - - perc = S.width * S.height * 0.01; /* 99th percentile white level */ - if (IO.fuji_width) perc /= 2; - if (!((O.highlight & ~2) || O.no_auto_bright)) - for (t_white=c=0; c < P1.colors; c++) { - for (val=0x2000, total=0; --val > 32; ) - if ((total += libraw_internal_data.output_data.histogram[c][val]) > perc) break; - if (t_white < val) t_white = val; - } - gamma_curve (O.gamm[0], O.gamm[1], 2, (t_white << 3)/O.bright); - } - - libraw_internal_data.output_data.histogram = save_hist; - free(t_hist); - - // from write_ppm_tiff - copy pixels into bitmap - - S.iheight = S.height; - S.iwidth = S.width; - if (S.flip & 4) SWAP(S.height,S.width); - - if(T.thumb) free(T.thumb); - T.thumb = (char*) calloc (S.width * S.height, P1.colors); - merror (T.thumb, "LibRaw::kodak_thumb_loader()"); - T.tlength = S.width * S.height * P1.colors; - - // from write_tiff_ppm - { - int soff = flip_index (0, 0); - int cstep = flip_index (0, 1) - soff; - int rstep = flip_index (1, 0) - flip_index (0, S.width); - - for (int row=0; row < S.height; row++, soff += rstep) - { - char *ppm = T.thumb + row*S.width*P1.colors; - for (int col=0; col < S.width; col++, soff += cstep) - for(int c = 0; c < P1.colors; c++) - ppm [col*P1.colors+c] = imgdata.color.curve[imgdata.image[soff][c]]>>8; - } - } - - memmove(C.curve,t_curve,sizeof(C.curve)); - free(t_curve); - - // restore variables - free(imgdata.image); - imgdata.image = s_image; - - T.twidth = S.width; - S.width = s_width; - - S.iwidth = s_iwidth; - S.iheight = s_iheight; - - T.theight = S.height; - S.height = s_height; - - T.tcolors = P1.colors; - P1.colors = s_colors; - - P1.filters = s_filters; -} -#undef MIN -#undef MAX -#undef LIM -#undef CLIP -#undef SWAP - - - - -// Äîñòàåò thumbnail èç ôàéëà, ñòàâèò thumb_format â ñîîòâåòñòâèè ñ ôîðìàòîì -int LibRaw::unpack_thumb(void) -{ - CHECK_ORDER_LOW(LIBRAW_PROGRESS_IDENTIFY); - CHECK_ORDER_BIT(LIBRAW_PROGRESS_THUMB_LOAD); - - try { - if ( !ID.toffset) - { - return LIBRAW_NO_THUMBNAIL; - } - else if (thumb_load_raw) - { - kodak_thumb_loader(); - T.tformat = LIBRAW_THUMBNAIL_BITMAP; - SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD); - return 0; - } - else - { - ID.input->seek(ID.toffset, SEEK_SET); - if ( write_thumb == &LibRaw::jpeg_thumb) - { - if(T.thumb) free(T.thumb); - T.thumb = (char *) malloc (T.tlength); - merror (T.thumb, "jpeg_thumb()"); - ID.input->read (T.thumb, 1, T.tlength); - T.tcolors = 3; - T.tformat = LIBRAW_THUMBNAIL_JPEG; - SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD); - return 0; - } - else if (write_thumb == &LibRaw::ppm_thumb) - { - T.tlength = T.twidth * T.theight*3; - if(T.thumb) free(T.thumb); - - T.thumb = (char *) malloc (T.tlength); - merror (T.thumb, "ppm_thumb()"); - - ID.input->read(T.thumb, 1, T.tlength); - - T.tformat = LIBRAW_THUMBNAIL_BITMAP; - SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD); - return 0; - - } - else if (write_thumb == &LibRaw::foveon_thumb) - { - foveon_thumb_loader(); - // may return with error, so format is set in - // foveon thumb loader itself - SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD); - return 0; - } - // else if -- all other write_thumb cases! - else - { - return LIBRAW_UNSUPPORTED_THUMBNAIL; - } - } - // last resort - return LIBRAW_UNSUPPORTED_THUMBNAIL; - } - catch ( LibRaw_exceptions err) { - EXCEPTION_HANDLER(err); - } - -} - -int LibRaw::dcraw_thumb_writer(const char *fname) -{ -// CHECK_ORDER_LOW(LIBRAW_PROGRESS_THUMB_LOAD); - - if(!fname) - return ENOENT; - - FILE *tfp = fopen(fname,"wb"); - - if(!tfp) - return errno; - - if(!T.thumb) - { - fclose(tfp); - return LIBRAW_OUT_OF_ORDER_CALL; - } - - try { - switch (T.tformat) - { - case LIBRAW_THUMBNAIL_JPEG: - jpeg_thumb_writer (tfp,T.thumb,T.tlength); - break; - case LIBRAW_THUMBNAIL_BITMAP: - fprintf (tfp, "P6\n%d %d\n255\n", T.twidth, T.theight); - fwrite (T.thumb, 1, T.tlength, tfp); - break; - default: - fclose(tfp); - return LIBRAW_UNSUPPORTED_THUMBNAIL; - } - fclose(tfp); - return 0; - } - catch ( LibRaw_exceptions err) { - fclose(tfp); - EXCEPTION_HANDLER(err); - } -} - -int LibRaw::adjust_sizes_info_only(void) -{ - CHECK_ORDER_LOW(LIBRAW_PROGRESS_IDENTIFY); - - raw2image_start(); - if (O.use_fuji_rotate) - { - if (IO.fuji_width) - { - // restore saved values - if(IO.fheight) - { - S.height = IO.fheight; - S.width = IO.fwidth; - S.iheight = (S.height + IO.shrink) >> IO.shrink; - S.iwidth = (S.width + IO.shrink) >> IO.shrink; - S.raw_height -= 2*S.top_margin; - IO.fheight = IO.fwidth = 0; // prevent repeated calls - } - // dcraw code - IO.fuji_width = (IO.fuji_width - 1 + IO.shrink) >> IO.shrink; - S.iwidth = (ushort)(IO.fuji_width / sqrt(0.5)); - S.iheight = (ushort)( (S.iheight - IO.fuji_width) / sqrt(0.5)); - } - else - { - if (S.pixel_aspect < 1) S.iheight = (ushort)( S.iheight / S.pixel_aspect + 0.5); - if (S.pixel_aspect > 1) S.iwidth = (ushort) (S.iwidth * S.pixel_aspect + 0.5); - } - } - SET_PROC_FLAG(LIBRAW_PROGRESS_FUJI_ROTATE); - if ( S.flip & 4) - { - unsigned short t = S.iheight; - S.iheight=S.iwidth; - S.iwidth = t; - SET_PROC_FLAG(LIBRAW_PROGRESS_FLIP); - } - return 0; -} - - -void LibRaw::subtract_black() -{ - -#define BAYERC(row,col,c) imgdata.image[((row) >> IO.shrink)*S.iwidth + ((col) >> IO.shrink)][c] - - if(C.ph1_black) - { - // Phase One compressed format - int row,col,val,cc; - for(row=0;row=C.phase_one_data.split_col]; - if(val<0) val = 0; - BAYERC(row,col,cc) = val; - } - C.maximum -= C.black; - phase_one_correct(); - // recalculate channel maximum - ZERO(C.channel_maximum); - for(row=0;row val) C.channel_maximum[cc] = val; - } - // clear P1 black level data - imgdata.color.phase_one_data.t_black = 0; - C.ph1_black = 0; - ZERO(C.cblack); - C.black = 0; - } - else if((C.black || C.cblack[0] || C.cblack[1] || C.cblack[2] || C.cblack[3])) - { - int cblk[4],i,row,col,val,cc; - for(i=0;i<4;i++) - cblk[i] = C.cblack[i]+C.black; - ZERO(C.channel_maximum); - - for(row=0;row cblk[cc]) - val -= cblk[cc]; - else - val = 0; - if(C.channel_maximum[cc] < val) C.channel_maximum[cc] = val; - BAYERC(row,col,cc) = val; - } - C.maximum -= C.black; - ZERO(C.cblack); - C.black = 0; - } - else - { - // only calculate channel maximum; - int row,col,cc,val; - ZERO(C.channel_maximum); - for(row=0;row8) shift = 8; - if(shift<0.25) shift = 0.25; - if(smooth < 0.0) smooth = 0.0; - if(smooth > 1.0) smooth = 1.0; - - unsigned short *lut = (ushort*)malloc((TBLN+1)*sizeof(unsigned short)); - - if(shift <=1.0) - { - for(int i=0;i<=TBLN;i++) - lut[i] = (unsigned short)((float)i*shift); - } - else - { - float x1,x2,y1,y2; - - float cstops = log(shift)/log(2.0f); - float room = cstops*2; - float roomlin = powf(2.0f,room); - x2 = (float)TBLN; - x1 = (x2+1)/roomlin-1; - y1 = x1*shift; - y2 = x2*(1+(1-smooth)*(shift-1)); - float sq3x=powf(x1*x1*x2,1.0f/3.0f); - float B = (y2-y1+shift*(3*x1-3.0f*sq3x)) / (x2+2.0f*x1-3.0f*sq3x); - float A = (shift - B)*3.0f*powf(x1*x1,1.0f/3.0f); - float CC = y2 - A*powf(x2,1.0f/3.0f)-B*x2; - for(int i=0;i<=TBLN;i++) - { - float X = (float)i; - float Y = A*powf(X,1.0f/3.0f)+B*X+CC; - if(iTBLN?TBLN:(unsigned short)(Y)); - } - } - for(int i=0; i< S.height*S.width; i++) - { - imgdata.image[i][0] = lut[imgdata.image[i][0]]; - imgdata.image[i][1] = lut[imgdata.image[i][1]]; - imgdata.image[i][2] = lut[imgdata.image[i][2]]; - imgdata.image[i][3] = lut[imgdata.image[i][3]]; - } - for(int i=0;i<4;i++) - C.channel_maximum[i] = lut[C.channel_maximum[i]]; - C.maximum = lut[C.maximum]; - // no need to adjust the minumum, black is already subtracted - free(lut); -} -int LibRaw::dcraw_process(void) -{ - int quality,i; - - int iterations=-1, dcb_enhance=1, noiserd=0; - int eeci_refine_fl=0, es_med_passes_fl=0; - float cared=0,cablue=0; - float linenoise=0; - float lclean=0,cclean=0; - float thresh=0; - float preser=0; - float expos=1.0; - - - CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW); -// CHECK_ORDER_HIGH(LIBRAW_PROGRESS_PRE_INTERPOLATE); - - try { - - int no_crop = 1; - - if (~O.cropbox[2] && ~O.cropbox[3]) - no_crop=0; - - raw2image_ex(); // raw2image+crop+rotate_fuji_raw + subtract_black for fuji - - int save_4color = O.four_color_rgb; - - if (IO.zero_is_bad) - { - remove_zeroes(); - SET_PROC_FLAG(LIBRAW_PROGRESS_REMOVE_ZEROES); - } - - if(!IO.fuji_width) // PhaseOne only, all other cases handled at raw2image_ex() - subtract_black(); - - if(O.half_size) - O.four_color_rgb = 1; - - if(O.bad_pixels && no_crop) - { - bad_pixels(O.bad_pixels); - SET_PROC_FLAG(LIBRAW_PROGRESS_BAD_PIXELS); - } - - if (O.dark_frame && no_crop) - { - subtract (O.dark_frame); - SET_PROC_FLAG(LIBRAW_PROGRESS_DARK_FRAME); - } - - - quality = 2 + !IO.fuji_width; - - if (O.user_qual >= 0) quality = O.user_qual; - - adjust_maximum(); - - if (O.user_sat > 0) C.maximum = O.user_sat; - - if (P1.is_foveon && !O.document_mode) - { - foveon_interpolate(); - SET_PROC_FLAG(LIBRAW_PROGRESS_FOVEON_INTERPOLATE); - } - - if (O.green_matching && !O.half_size) - { - green_matching(); - } - - if (!P1.is_foveon && O.document_mode < 2) - { - scale_colors(); - SET_PROC_FLAG(LIBRAW_PROGRESS_SCALE_COLORS); - } - - pre_interpolate(); - - SET_PROC_FLAG(LIBRAW_PROGRESS_PRE_INTERPOLATE); - - if (O.dcb_iterations >= 0) iterations = O.dcb_iterations; - if (O.dcb_enhance_fl >=0 ) dcb_enhance = O.dcb_enhance_fl; - if (O.fbdd_noiserd >=0 ) noiserd = O.fbdd_noiserd; - if (O.eeci_refine >=0 ) eeci_refine_fl = O.eeci_refine; - if (O.es_med_passes >0 ) es_med_passes_fl = O.es_med_passes; - -// LIBRAW_DEMOSAIC_PACK_GPL3 - - if (!O.half_size && O.cfa_green >0) {thresh=O.green_thresh ;green_equilibrate(thresh);} - if (O.exp_correc >0) {expos=O.exp_shift ; preser=O.exp_preser; exp_bef(expos,preser);} - if (O.ca_correc >0 ) {cablue=O.cablue; cared=O.cared; CA_correct_RT(cablue, cared);} - if (O.cfaline >0 ) {linenoise=O.linenoise; cfa_linedn(linenoise);} - if (O.cfa_clean >0 ) {lclean=O.lclean; cclean=O.cclean; cfa_impulse_gauss(lclean,cclean);} - - if (P1.filters && !O.document_mode) - { - if (noiserd>0 && P1.colors==3 && P1.filters) fbdd(noiserd); - - if (quality == 0) - lin_interpolate(); - else if (quality == 1 || P1.colors > 3) - vng_interpolate(); - else if (quality == 2) - ppg_interpolate(); - - else if (quality == 3) - ahd_interpolate(); // really don't need it here due to fallback op - - else if (quality == 4) - dcb(iterations, dcb_enhance); - -// LIBRAW_DEMOSAIC_PACK_GPL2 - else if (quality == 5) - ahd_interpolate_mod(); - else if (quality == 6) - afd_interpolate_pl(2,1); - else if (quality == 7) - vcd_interpolate(0); - else if (quality == 8) - vcd_interpolate(12); - else if (quality == 9) - lmmse_interpolate(1); - -// LIBRAW_DEMOSAIC_PACK_GPL3 - else if (quality == 10) - amaze_demosaic_RT(); - // fallback to AHD - else - ahd_interpolate(); - - SET_PROC_FLAG(LIBRAW_PROGRESS_INTERPOLATE); - } - if (IO.mix_green) - { - for (P1.colors=3, i=0; i < S.height * S.width; i++) - imgdata.image[i][1] = (imgdata.image[i][1] + imgdata.image[i][3]) >> 1; - SET_PROC_FLAG(LIBRAW_PROGRESS_MIX_GREEN); - } - - if(!P1.is_foveon) - { - if (P1.colors == 3) - { - - if (quality == 8) - { - if (eeci_refine_fl == 1) refinement(); - if (O.med_passes > 0) median_filter_new(); - if (es_med_passes_fl > 0) es_median_filter(); - } - else { - median_filter(); - } - SET_PROC_FLAG(LIBRAW_PROGRESS_MEDIAN_FILTER); - } - } - - if (O.highlight == 2) - { - blend_highlights(); - SET_PROC_FLAG(LIBRAW_PROGRESS_HIGHLIGHTS); - } - - if (O.highlight > 2) - { - recover_highlights(); - SET_PROC_FLAG(LIBRAW_PROGRESS_HIGHLIGHTS); - } - - if (O.use_fuji_rotate) - { - fuji_rotate(); - SET_PROC_FLAG(LIBRAW_PROGRESS_FUJI_ROTATE); - } - - if(!libraw_internal_data.output_data.histogram) - { - libraw_internal_data.output_data.histogram = (int (*)[LIBRAW_HISTOGRAM_SIZE]) malloc(sizeof(*libraw_internal_data.output_data.histogram)*4); - merror(libraw_internal_data.output_data.histogram,"LibRaw::dcraw_process()"); - } -#ifndef NO_LCMS - if(O.camera_profile) - { - apply_profile(O.camera_profile,O.output_profile); - SET_PROC_FLAG(LIBRAW_PROGRESS_APPLY_PROFILE); - } -#endif - - convert_to_rgb(); - SET_PROC_FLAG(LIBRAW_PROGRESS_CONVERT_RGB); - - if (O.use_fuji_rotate) - { - stretch(); - SET_PROC_FLAG(LIBRAW_PROGRESS_STRETCH); - } - O.four_color_rgb = save_4color; // also, restore - - return 0; - } - catch ( LibRaw_exceptions err) { - EXCEPTION_HANDLER(err); - } -} - -// Supported cameras: -static const char *static_camera_list[] = -{ -"Adobe Digital Negative (DNG)", -"AgfaPhoto DC-833m", -"Apple QuickTake 100", -"Apple QuickTake 150", -"Apple QuickTake 200", -"ARRIRAW format", -"AVT F-080C", -"AVT F-145C", -"AVT F-201C", -"AVT F-510C", -"AVT F-810C", -"Canon PowerShot 600", -"Canon PowerShot A5", -"Canon PowerShot A5 Zoom", -"Canon PowerShot A50", -"Canon PowerShot A460 (CHDK hack)", -"Canon PowerShot A470 (CHDK hack)", -"Canon PowerShot A530 (CHDK hack)", -"Canon PowerShot A570 (CHDK hack)", -"Canon PowerShot A590 (CHDK hack)", -"Canon PowerShot A610 (CHDK hack)", -"Canon PowerShot A620 (CHDK hack)", -"Canon PowerShot A630 (CHDK hack)", -"Canon PowerShot A640 (CHDK hack)", -"Canon PowerShot A650 (CHDK hack)", -"Canon PowerShot A710 IS (CHDK hack)", -"Canon PowerShot A720 IS (CHDK hack)", -"Canon PowerShot Pro70", -"Canon PowerShot Pro90 IS", -"Canon PowerShot Pro1", -"Canon PowerShot G1", -"Canon PowerShot G1 X", -"Canon PowerShot G2", -"Canon PowerShot G3", -"Canon PowerShot G5", -"Canon PowerShot G6", -"Canon PowerShot G7 (CHDK hack)", -"Canon PowerShot G9", -"Canon PowerShot G10", -"Canon PowerShot G11", -"Canon PowerShot G12", -"Canon PowerShot S2 IS (CHDK hack)", -"Canon PowerShot S3 IS (CHDK hack)", -"Canon PowerShot S5 IS (CHDK hack)", -"Canon PowerShot SD300 (CHDK hack)", -"Canon PowerShot S30", -"Canon PowerShot S40", -"Canon PowerShot S45", -"Canon PowerShot S50", -"Canon PowerShot S60", -"Canon PowerShot S70", -"Canon PowerShot S90", -"Canon PowerShot S95", -"Canon PowerShot S100", -"Canon PowerShot SX1 IS", -"Canon PowerShot SX110 IS (CHDK hack)", -"Canon PowerShot SX120 IS (CHDK hack)", -"Canon PowerShot SX20 IS (CHDK hack)", -"Canon PowerShot SX220 HS (CHDK hack)", -"Canon PowerShot SX30 IS (CHDK hack)", -"Canon EOS D30", -"Canon EOS D60", -"Canon EOS 5D", -"Canon EOS 5D Mark II", -"Canon EOS 5D Mark III", -"Canon EOS 7D", -"Canon EOS 10D", -"Canon EOS 20D", -"Canon EOS 30D", -"Canon EOS 40D", -"Canon EOS 50D", -"Canon EOS 60D", -"Canon EOS 300D / Digital Rebel / Kiss Digital", -"Canon EOS 350D / Digital Rebel XT / Kiss Digital N", -"Canon EOS 400D / Digital Rebel XTi / Kiss Digital X", -"Canon EOS 450D / Digital Rebel XSi / Kiss Digital X2", -"Canon EOS 500D / Digital Rebel T1i / Kiss Digital X3", -"Canon EOS 550D / Digital Rebel T2i / Kiss Digital X4", -"Canon EOS 600D / Digital Rebel T3i / Kiss Digital X5", -"Canon EOS 1000D / Digital Rebel XS / Kiss Digital F", -"Canon EOS 1100D / Digital Rebel T3 / Kiss Digital X50", -"Canon EOS D2000C", -"Canon EOS-1D", -"Canon EOS-1DS", -"Canon EOS-1D X", -"Canon EOS-1D Mark II", -"Canon EOS-1D Mark II N", -"Canon EOS-1D Mark III", -"Canon EOS-1D Mark IV", -"Canon EOS-1Ds Mark II", -"Canon EOS-1Ds Mark III", -"Casio QV-2000UX", -"Casio QV-3000EX", -"Casio QV-3500EX", -"Casio QV-4000", -"Casio QV-5700", -"Casio QV-R41", -"Casio QV-R51", -"Casio QV-R61", -"Casio EX-S20", -"Casio EX-S100", -"Casio EX-Z4", -"Casio EX-Z50", -"Casio EX-Z500", -"Casio EX-Z55", -"Casio EX-Z60", -"Casio EX-Z75", -"Casio EX-Z750", -"Casio EX-Z8", -"Casio EX-Z850", -"Casio EX-Z1050", -"Casio EX-Z1080", -"Casio Exlim Pro 505", -"Casio Exlim Pro 600", -"Casio Exlim Pro 700", -"Contax N Digital", -"Creative PC-CAM 600", -"Epson R-D1", -"Foculus 531C", -"Fuji FinePix E550", -"Fuji FinePix E900", -"Fuji FinePix F700", -"Fuji FinePix F710", -"Fuji FinePix F800", -"Fuji FinePix F810", -"Fuji FinePix S2Pro", -"Fuji FinePix S3Pro", -"Fuji FinePix S5Pro", -"Fuji FinePix S20Pro", -"Fuji FinePix S100FS", -"Fuji FinePix S5000", -"Fuji FinePix S5100/S5500", -"Fuji FinePix S5200/S5600", -"Fuji FinePix S6000fd", -"Fuji FinePix S7000", -"Fuji FinePix S9000/S9500", -"Fuji FinePix S9100/S9600", -"Fuji FinePix S200EXR", -"Fuji FinePix HS10/HS11", -"Fuji FinePix HS20EXR", -"Fuji FinePix HS30EXR", -"Fuji FinePix F550EXR", -"Fuji FinePix F600EXR", -"Fuji FinePix X-S1", -"Fuji FinePix X100", -"Fuji FinePix X10", -"Fuji IS-1", -"Hasselblad CFV", -"Hasselblad H3D", -"Hasselblad H4D", -"Hasselblad V96C", -"Imacon Ixpress 16-megapixel", -"Imacon Ixpress 22-megapixel", -"Imacon Ixpress 39-megapixel", -"ISG 2020x1520", -"Kodak DC20", -"Kodak DC25", -"Kodak DC40", -"Kodak DC50", -"Kodak DC120 (also try kdc2tiff)", -"Kodak DCS200", -"Kodak DCS315C", -"Kodak DCS330C", -"Kodak DCS420", -"Kodak DCS460", -"Kodak DCS460A", -"Kodak DCS520C", -"Kodak DCS560C", -"Kodak DCS620C", -"Kodak DCS620X", -"Kodak DCS660C", -"Kodak DCS660M", -"Kodak DCS720X", -"Kodak DCS760C", -"Kodak DCS760M", -"Kodak EOSDCS1", -"Kodak EOSDCS3B", -"Kodak NC2000F", -"Kodak ProBack", -"Kodak PB645C", -"Kodak PB645H", -"Kodak PB645M", -"Kodak DCS Pro 14n", -"Kodak DCS Pro 14nx", -"Kodak DCS Pro SLR/c", -"Kodak DCS Pro SLR/n", -"Kodak C330", -"Kodak C603", -"Kodak P850", -"Kodak P880", -"Kodak Z980", -"Kodak Z981", -"Kodak Z990", -"Kodak Z1015", -"Kodak KAI-0340", -"Konica KD-400Z", -"Konica KD-510Z", -"Leaf AFi 7", -"Leaf AFi-II 5", -"Leaf AFi-II 6", -"Leaf AFi-II 7", -"Leaf AFi-II 8", -"Leaf AFi-II 10", -"Leaf AFi-II 10R", -"Leaf AFi-II 12", -"Leaf AFi-II 12R", -"Leaf Aptus 17", -"Leaf Aptus 22", -"Leaf Aptus 54S", -"Leaf Aptus 65", -"Leaf Aptus 75", -"Leaf Aptus 75S", -"Leaf Cantare", -"Leaf CatchLight", -"Leaf CMost", -"Leaf DCB2", -"Leaf Valeo 6", -"Leaf Valeo 11", -"Leaf Valeo 17", -"Leaf Valeo 22", -"Leaf Volare", -"Leica Digilux 2", -"Leica Digilux 3", -"Leica D-LUX2", -"Leica D-LUX3", -"Leica D-LUX4", -"Leica D-LUX5", -"Leica V-LUX1", -"Leica V-LUX2", -"Logitech Fotoman Pixtura", -"Mamiya ZD", -"Micron 2010", -"Minolta RD175", -"Minolta DiMAGE 5", -"Minolta DiMAGE 7", -"Minolta DiMAGE 7i", -"Minolta DiMAGE 7Hi", -"Minolta DiMAGE A1", -"Minolta DiMAGE A2", -"Minolta DiMAGE A200", -"Minolta DiMAGE G400", -"Minolta DiMAGE G500", -"Minolta DiMAGE G530", -"Minolta DiMAGE G600", -"Minolta DiMAGE Z2", -"Minolta Alpha/Dynax/Maxxum 5D", -"Minolta Alpha/Dynax/Maxxum 7D", -"Motorola PIXL", -"Nikon D1", -"Nikon D1H", -"Nikon D1X", -"Nikon D2H", -"Nikon D2Hs", -"Nikon D2X", -"Nikon D2Xs", -"Nikon D3", -"Nikon D3s", -"Nikon D3X", -"Nikon D4", -"Nikon D40", -"Nikon D40X", -"Nikon D50", -"Nikon D60", -"Nikon D70", -"Nikon D70s", -"Nikon D80", -"Nikon D90", -"Nikon D100", -"Nikon D200", -"Nikon D300", -"Nikon D300s", -"Nikon D700", -"Nikon D3000", -"Nikon D3100", -"Nikon D3200", -"Nikon D5000", -"Nikon D5100", -"Nikon D7000", -"Nikon D800", -"Nikon 1 J1", -"Nikon 1 V1", -"Nikon E700 (\"DIAG RAW\" hack)", -"Nikon E800 (\"DIAG RAW\" hack)", -"Nikon E880 (\"DIAG RAW\" hack)", -"Nikon E900 (\"DIAG RAW\" hack)", -"Nikon E950 (\"DIAG RAW\" hack)", -"Nikon E990 (\"DIAG RAW\" hack)", -"Nikon E995 (\"DIAG RAW\" hack)", -"Nikon E2100 (\"DIAG RAW\" hack)", -"Nikon E2500 (\"DIAG RAW\" hack)", -"Nikon E3200 (\"DIAG RAW\" hack)", -"Nikon E3700 (\"DIAG RAW\" hack)", -"Nikon E4300 (\"DIAG RAW\" hack)", -"Nikon E4500 (\"DIAG RAW\" hack)", -"Nikon E5000", -"Nikon E5400", -"Nikon E5700", -"Nikon E8400", -"Nikon E8700", -"Nikon E8800", -"Nikon Coolpix P6000", -"Nikon Coolpix P7000", -"Nikon Coolpix P7100", -"Nikon Coolpix S6 (\"DIAG RAW\" hack)", -"Nokia N95", -"Nokia X2", -"Olympus C3030Z", -"Olympus C5050Z", -"Olympus C5060WZ", -"Olympus C7070WZ", -"Olympus C70Z,C7000Z", -"Olympus C740UZ", -"Olympus C770UZ", -"Olympus C8080WZ", -"Olympus X200,D560Z,C350Z", -"Olympus E-1", -"Olympus E-3", -"Olympus E-5", -"Olympus E-10", -"Olympus E-20", -"Olympus E-30", -"Olympus E-300", -"Olympus E-330", -"Olympus E-400", -"Olympus E-410", -"Olympus E-420", -"Olympus E-500", -"Olympus E-510", -"Olympus E-520", -"Olympus E-620", -"Olympus E-P1", -"Olympus E-P2", -"Olympus E-P3", -"Olympus E-PL1", -"Olympus E-PL1s", -"Olympus E-PL2", -"Olympus E-PL3", -"Olympus E-PM1", -"Olympus E-M5", -"Olympus SP310", -"Olympus SP320", -"Olympus SP350", -"Olympus SP500UZ", -"Olympus SP510UZ", -"Olympus SP550UZ", -"Olympus SP560UZ", -"Olympus SP570UZ", -"Olympus XZ-1", -"Panasonic DMC-FZ8", -"Panasonic DMC-FZ18", -"Panasonic DMC-FZ28", -"Panasonic DMC-FZ30", -"Panasonic DMC-FZ35/FZ38", -"Panasonic DMC-FZ40", -"Panasonic DMC-FZ50", -"Panasonic DMC-FZ100", -"Panasonic DMC-FZ150", -"Panasonic DMC-FX150", -"Panasonic DMC-G1", -"Panasonic DMC-G10", -"Panasonic DMC-G2", -"Panasonic DMC-G3", -"Panasonic DMC-GF1", -"Panasonic DMC-GF2", -"Panasonic DMC-GF3", -"Panasonic DMC-GF5", -"Panasonic DMC-GH1", -"Panasonic DMC-GH2", -"Panasonic DMC-GX1", -"Panasonic DMC-L1", -"Panasonic DMC-L10", -"Panasonic DMC-LC1", -"Panasonic DMC-LX1", -"Panasonic DMC-LX2", -"Panasonic DMC-LX3", -"Panasonic DMC-LX5", -"Pentax *ist D", -"Pentax *ist DL", -"Pentax *ist DL2", -"Pentax *ist DS", -"Pentax *ist DS2", -"Pentax K10D", -"Pentax K20D", -"Pentax K100D", -"Pentax K100D Super", -"Pentax K200D", -"Pentax K2000/K-m", -"Pentax K-x", -"Pentax K-r", -"Pentax K-5", -"Pentax K-7", -"Pentax Optio S", -"Pentax Optio S4", -"Pentax Optio 33WR", -"Pentax Optio 750Z", -"Pentax 645D", -"Phase One LightPhase", -"Phase One H 10", -"Phase One H 20", -"Phase One H 25", -"Phase One P 20", -"Phase One P 25", -"Phase One P 30", -"Phase One P 45", -"Phase One P 45+", -"Phase One P 65", -"Pixelink A782", -#ifdef LIBRAW_DEMOSAIC_PACK_GPL2 -"Polaroid x530", -#endif -#ifndef NO_JASPER -"Redcode R3D format", -#endif -"Rollei d530flex", -"RoverShot 3320af", -"Samsung EX1", -"Samsung GX-1S", -"Samsung GX10", -"Samsung GX20", -"Samsung NX10", -"Samsung NX11", -"Samsung NX100", -"Samsung NX20", -"Samsung NX200", -"Samsung NX210", -"Samsung WB550", -"Samsung WB2000", -"Samsung S85 (hacked)", -"Samsung S850 (hacked)", -"Sarnoff 4096x5440", -#ifdef LIBRAW_DEMOSAIC_PACK_GPL2 -"Sigma SD9", -"Sigma SD10", -"Sigma SD14", -#endif -"Sinar 3072x2048", -"Sinar 4080x4080", -"Sinar 4080x5440", -"Sinar STI format", -"SMaL Ultra-Pocket 3", -"SMaL Ultra-Pocket 4", -"SMaL Ultra-Pocket 5", -"Sony DSC-F828", -"Sony DSC-R1", -"Sony DSC-V3", -"Sony DSLR-A100", -"Sony DSLR-A200", -"Sony DSLR-A230", -"Sony DSLR-A290", -"Sony DSLR-A300", -"Sony DSLR-A330", -"Sony DSLR-A350", -"Sony DSLR-A380", -"Sony DSLR-A390", -"Sony DSLR-A450", -"Sony DSLR-A500", -"Sony DSLR-A550", -"Sony DSLR-A580", -"Sony DSLR-A700", -"Sony DSLR-A850", -"Sony DSLR-A900", -"Sony NEX-3", -"Sony NEX-5", -"Sony NEX-5N", -"Sony NEX-7", -"Sony NEX-C3", -"Sony NEX-F3", -"Sony SLT-A33", -"Sony SLT-A35", -"Sony SLT-A37", -"Sony SLT-A55V", -"Sony SLT-A57", -"Sony SLT-A65V", -"Sony SLT-A77V", -"Sony XCD-SX910CR", -"STV680 VGA", - NULL -}; - -const char** LibRaw::cameraList() { return static_camera_list;} -int LibRaw::cameraCount() { return (sizeof(static_camera_list)/sizeof(static_camera_list[0]))-1; } - - -const char * LibRaw::strprogress(enum LibRaw_progress p) -{ - switch(p) - { - case LIBRAW_PROGRESS_START: - return "Starting"; - case LIBRAW_PROGRESS_OPEN : - return "Opening file"; - case LIBRAW_PROGRESS_IDENTIFY : - return "Reading metadata"; - case LIBRAW_PROGRESS_SIZE_ADJUST: - return "Adjusting size"; - case LIBRAW_PROGRESS_LOAD_RAW: - return "Reading RAW data"; - case LIBRAW_PROGRESS_REMOVE_ZEROES: - return "Clearing zero values"; - case LIBRAW_PROGRESS_BAD_PIXELS : - return "Removing dead pixels"; - case LIBRAW_PROGRESS_DARK_FRAME: - return "Subtracting dark frame data"; - case LIBRAW_PROGRESS_FOVEON_INTERPOLATE: - return "Interpolating Foveon sensor data"; - case LIBRAW_PROGRESS_SCALE_COLORS: - return "Scaling colors"; - case LIBRAW_PROGRESS_PRE_INTERPOLATE: - return "Pre-interpolating"; - case LIBRAW_PROGRESS_INTERPOLATE: - return "Interpolating"; - case LIBRAW_PROGRESS_MIX_GREEN : - return "Mixing green channels"; - case LIBRAW_PROGRESS_MEDIAN_FILTER : - return "Median filter"; - case LIBRAW_PROGRESS_HIGHLIGHTS: - return "Highlight recovery"; - case LIBRAW_PROGRESS_FUJI_ROTATE : - return "Rotating Fuji diagonal data"; - case LIBRAW_PROGRESS_FLIP : - return "Flipping image"; - case LIBRAW_PROGRESS_APPLY_PROFILE: - return "ICC conversion"; - case LIBRAW_PROGRESS_CONVERT_RGB: - return "Converting to RGB"; - case LIBRAW_PROGRESS_STRETCH: - return "Stretching image"; - case LIBRAW_PROGRESS_THUMB_LOAD: - return "Loading thumbnail"; - default: - return "Some strange things"; - } -} +/* -*- C++ -*- + * File: libraw_cxx.cpp + * Copyright 2008-2010 LibRaw LLC (info@libraw.org) + * Created: Sat Mar 8 , 2008 + * + * LibRaw C++ interface (implementation) + +LibRaw is free software; you can redistribute it and/or modify +it under the terms of the one of three licenses as you choose: + +1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + (See file LICENSE.LGPL provided in LibRaw distribution archive for details). + +2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + (See file LICENSE.CDDL provided in LibRaw distribution archive for details). + +3. LibRaw Software License 27032010 + (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). + + */ + +#include +#include +#include +#include +#include +#include +#include +#ifndef WIN32 +#include +#else +#include +#endif +#define LIBRAW_LIBRARY_BUILD +#include "libraw/libraw.h" +#include "internal/defines.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + void default_memory_callback(void *,const char *file,const char *where) + { + fprintf (stderr,"%s: Out of memory in %s\n", file?file:"unknown file", where); + } + + void default_data_callback(void*,const char *file, const int offset) + { + if(offset < 0) + fprintf (stderr,"%s: Unexpected end of file\n", file?file:"unknown file"); + else + fprintf (stderr,"%s: data corrupted at %d\n",file?file:"unknown file",offset); + } + const char *libraw_strerror(int e) + { + enum LibRaw_errors errorcode = (LibRaw_errors)e; + switch(errorcode) + { + case LIBRAW_SUCCESS: + return "No error"; + case LIBRAW_UNSPECIFIED_ERROR: + return "Unspecified error"; + case LIBRAW_FILE_UNSUPPORTED: + return "Unsupported file format or not RAW file"; + case LIBRAW_REQUEST_FOR_NONEXISTENT_IMAGE: + return "Request for nonexisting image number"; + case LIBRAW_OUT_OF_ORDER_CALL: + return "Out of order call of libraw function"; + case LIBRAW_NO_THUMBNAIL: + return "No thumbnail in file"; + case LIBRAW_UNSUPPORTED_THUMBNAIL: + return "Unsupported thumbnail format"; + case LIBRAW_UNSUFFICIENT_MEMORY: + return "Unsufficient memory"; + case LIBRAW_DATA_ERROR: + return "Corrupted data or unexpected EOF"; + case LIBRAW_IO_ERROR: + return "Input/output error"; + case LIBRAW_CANCELLED_BY_CALLBACK: + return "Cancelled by user callback"; + case LIBRAW_BAD_CROP: + return "Bad crop box"; + default: + return "Unknown error code"; + } + } + +#ifdef __cplusplus +} +#endif + + +const double LibRaw_constants::xyz_rgb[3][3] = +{ + { 0.412453, 0.357580, 0.180423 }, + { 0.212671, 0.715160, 0.072169 }, + { 0.019334, 0.119193, 0.950227 } +}; + +const float LibRaw_constants::d65_white[3] = { 0.950456f, 1.0f, 1.088754f }; + +#define P1 imgdata.idata +#define S imgdata.sizes +#define O imgdata.params +#define C imgdata.color +#define T imgdata.thumbnail +#define IO libraw_internal_data.internal_output_params +#define ID libraw_internal_data.internal_data + +#define EXCEPTION_HANDLER(e) do{ \ + /* fprintf(stderr,"Exception %d caught\n",e);*/ \ + switch(e) \ + { \ + case LIBRAW_EXCEPTION_ALLOC: \ + recycle(); \ + return LIBRAW_UNSUFFICIENT_MEMORY; \ + case LIBRAW_EXCEPTION_DECODE_RAW: \ + case LIBRAW_EXCEPTION_DECODE_JPEG: \ + recycle(); \ + return LIBRAW_DATA_ERROR; \ + case LIBRAW_EXCEPTION_DECODE_JPEG2000: \ + recycle(); \ + return LIBRAW_DATA_ERROR; \ + case LIBRAW_EXCEPTION_IO_EOF: \ + case LIBRAW_EXCEPTION_IO_CORRUPT: \ + recycle(); \ + return LIBRAW_IO_ERROR; \ + case LIBRAW_EXCEPTION_CANCELLED_BY_CALLBACK:\ + recycle(); \ + return LIBRAW_CANCELLED_BY_CALLBACK; \ + case LIBRAW_EXCEPTION_BAD_CROP: \ + recycle(); \ + return LIBRAW_BAD_CROP; \ + default: \ + return LIBRAW_UNSPECIFIED_ERROR; \ + } \ + }while(0) + +const char* LibRaw::version() { return LIBRAW_VERSION_STR;} +int LibRaw::versionNumber() { return LIBRAW_VERSION; } +const char* LibRaw::strerror(int p) { return libraw_strerror(p);} + + +void LibRaw::derror() +{ + if (!libraw_internal_data.unpacker_data.data_error && libraw_internal_data.internal_data.input) + { + if (libraw_internal_data.internal_data.input->eof()) + { + if(callbacks.data_cb)(*callbacks.data_cb)(callbacks.datacb_data, + libraw_internal_data.internal_data.input->fname(),-1); + throw LIBRAW_EXCEPTION_IO_EOF; + } + else + { + if(callbacks.data_cb)(*callbacks.data_cb)(callbacks.datacb_data, + libraw_internal_data.internal_data.input->fname(), + libraw_internal_data.internal_data.input->tell()); + throw LIBRAW_EXCEPTION_IO_CORRUPT; + } + } + libraw_internal_data.unpacker_data.data_error++; +} + +void LibRaw::dcraw_clear_mem(libraw_processed_image_t* p) +{ + if(p) ::free(p); +} + +#define ZERO(a) memset(&a,0,sizeof(a)) + + +LibRaw:: LibRaw(unsigned int flags) +{ + double aber[4] = {1,1,1,1}; + double gamm[6] = { 0.45,4.5,0,0,0,0 }; + unsigned greybox[4] = { 0, 0, UINT_MAX, UINT_MAX }; + unsigned cropbox[4] = { 0, 0, UINT_MAX, UINT_MAX }; +#ifdef DCRAW_VERBOSE + verbose = 1; +#else + verbose = 0; +#endif + ZERO(imgdata); + ZERO(libraw_internal_data); + ZERO(callbacks); + callbacks.mem_cb = (flags & LIBRAW_OPIONS_NO_MEMERR_CALLBACK) ? NULL: &default_memory_callback; + callbacks.data_cb = (flags & LIBRAW_OPIONS_NO_DATAERR_CALLBACK)? NULL : &default_data_callback; + memmove(&imgdata.params.aber,&aber,sizeof(aber)); + memmove(&imgdata.params.gamm,&gamm,sizeof(gamm)); + memmove(&imgdata.params.greybox,&greybox,sizeof(greybox)); + memmove(&imgdata.params.cropbox,&cropbox,sizeof(cropbox)); + + imgdata.params.bright=1; + imgdata.params.use_camera_matrix=-1; + imgdata.params.user_flip=-1; + imgdata.params.user_black=-1; + imgdata.params.user_sat=-1; + imgdata.params.user_qual=-1; + imgdata.params.output_color=1; + imgdata.params.output_bps=8; + imgdata.params.use_fuji_rotate=1; + imgdata.params.exp_shift = 1.0; + imgdata.params.auto_bright_thr = LIBRAW_DEFAULT_AUTO_BRIGHTNESS_THRESHOLD; + imgdata.params.adjust_maximum_thr= LIBRAW_DEFAULT_ADJUST_MAXIMUM_THRESHOLD; + imgdata.params.green_matching = 0; + imgdata.parent_class = this; + imgdata.progress_flags = 0; + tls = new LibRaw_TLS; + tls->init(); +} + + +void* LibRaw:: malloc(size_t t) +{ + void *p = memmgr.malloc(t); + return p; +} +void* LibRaw:: realloc(void *q,size_t t) +{ + void *p = memmgr.realloc(q,t); + return p; +} + + +void* LibRaw:: calloc(size_t n,size_t t) +{ + void *p = memmgr.calloc(n,t); + return p; +} +void LibRaw:: free(void *p) +{ + memmgr.free(p); +} + + +int LibRaw:: fc (int row, int col) +{ + static const char filter[16][16] = + { { 2,1,1,3,2,3,2,0,3,2,3,0,1,2,1,0 }, + { 0,3,0,2,0,1,3,1,0,1,1,2,0,3,3,2 }, + { 2,3,3,2,3,1,1,3,3,1,2,1,2,0,0,3 }, + { 0,1,0,1,0,2,0,2,2,0,3,0,1,3,2,1 }, + { 3,1,1,2,0,1,0,2,1,3,1,3,0,1,3,0 }, + { 2,0,0,3,3,2,3,1,2,0,2,0,3,2,2,1 }, + { 2,3,3,1,2,1,2,1,2,1,1,2,3,0,0,1 }, + { 1,0,0,2,3,0,0,3,0,3,0,3,2,1,2,3 }, + { 2,3,3,1,1,2,1,0,3,2,3,0,2,3,1,3 }, + { 1,0,2,0,3,0,3,2,0,1,1,2,0,1,0,2 }, + { 0,1,1,3,3,2,2,1,1,3,3,0,2,1,3,2 }, + { 2,3,2,0,0,1,3,0,2,0,1,2,3,0,1,0 }, + { 1,3,1,2,3,2,3,2,0,2,0,1,1,0,3,0 }, + { 0,2,0,3,1,0,0,1,1,3,3,2,3,2,2,1 }, + { 2,1,3,2,3,1,2,1,0,3,0,2,0,2,0,2 }, + { 0,3,1,0,0,2,0,3,2,1,3,1,1,3,1,3 } }; + + if (imgdata.idata.filters != 1) return FC(row,col); + return filter[(row+imgdata.sizes.top_margin) & 15][(col+imgdata.sizes.left_margin) & 15]; +} + +void LibRaw:: recycle() +{ + if(libraw_internal_data.internal_data.input && libraw_internal_data.internal_data.input_internal) + { + delete libraw_internal_data.internal_data.input; + libraw_internal_data.internal_data.input = NULL; + } + libraw_internal_data.internal_data.input_internal = 0; +#define FREE(a) do { if(a) { free(a); a = NULL;} }while(0) + + FREE(imgdata.image); + FREE(imgdata.thumbnail.thumb); + FREE(libraw_internal_data.internal_data.meta_data); + FREE(libraw_internal_data.output_data.histogram); + FREE(libraw_internal_data.output_data.oprof); + FREE(imgdata.color.profile); + FREE(imgdata.rawdata.ph1_black); + FREE(imgdata.rawdata.raw_alloc); +#undef FREE + ZERO(imgdata.rawdata); + ZERO(imgdata.sizes); + ZERO(imgdata.color); + ZERO(libraw_internal_data); + memmgr.cleanup(); + imgdata.thumbnail.tformat = LIBRAW_THUMBNAIL_UNKNOWN; + imgdata.progress_flags = 0; + + tls->init(); +} + +const char * LibRaw::unpack_function_name() +{ + libraw_decoder_info_t decoder_info; + get_decoder_info(&decoder_info); + return decoder_info.decoder_name; +} + +int LibRaw::get_decoder_info(libraw_decoder_info_t* d_info) +{ + if(!d_info) return LIBRAW_UNSPECIFIED_ERROR; + if(!load_raw) return LIBRAW_OUT_OF_ORDER_CALL; + + d_info->decoder_flags = LIBRAW_DECODER_NOTSET; + + // sorted names order + if (load_raw == &LibRaw::adobe_dng_load_raw_lj) + { + // Check rbayer + d_info->decoder_name = "adobe_dng_load_raw_lj()"; + d_info->decoder_flags = imgdata.idata.filters ? LIBRAW_DECODER_FLATFIELD : LIBRAW_DECODER_4COMPONENT ; + d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; + } + else if (load_raw == &LibRaw::adobe_dng_load_raw_nc) + { + // Check rbayer + d_info->decoder_name = "adobe_dng_load_raw_nc()"; + d_info->decoder_flags = imgdata.idata.filters ? LIBRAW_DECODER_FLATFIELD : LIBRAW_DECODER_4COMPONENT; + d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; + } + else if (load_raw == &LibRaw::canon_600_load_raw) + { + d_info->decoder_name = "canon_600_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; // WB set within decoder, no need to load raw + } + else if (load_raw == &LibRaw::canon_compressed_load_raw) + { + d_info->decoder_name = "canon_compressed_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::canon_sraw_load_raw) + { + d_info->decoder_name = "canon_sraw_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_LEGACY; + } + else if (load_raw == &LibRaw::eight_bit_load_raw ) + { + d_info->decoder_name = "eight_bit_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; + } + else if (load_raw == &LibRaw::foveon_load_raw ) + { + d_info->decoder_name = "foveon_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_LEGACY; + } + else if (load_raw == &LibRaw::fuji_load_raw ) + { + d_info->decoder_name = "fuji_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::hasselblad_load_raw ) + { + d_info->decoder_name = "hasselblad_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::imacon_full_load_raw ) + { + d_info->decoder_name = "imacon_full_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT; + } + else if (load_raw == &LibRaw::kodak_262_load_raw ) + { + d_info->decoder_name = "kodak_262_load_raw()"; // UNTESTED! + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; + } + else if (load_raw == &LibRaw::kodak_65000_load_raw ) + { + d_info->decoder_name = "kodak_65000_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; + } + else if (load_raw == &LibRaw::kodak_dc120_load_raw ) + { + d_info->decoder_name = "kodak_dc120_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::kodak_jpeg_load_raw ) + { + // UNTESTED + RBAYER + d_info->decoder_name = "kodak_jpeg_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::kodak_radc_load_raw ) + { + d_info->decoder_name = "kodak_radc_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT; + } + else if (load_raw == &LibRaw::kodak_rgb_load_raw ) + { + // UNTESTED + d_info->decoder_name = "kodak_rgb_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT; + } + else if (load_raw == &LibRaw::kodak_yrgb_load_raw ) + { + d_info->decoder_name = "kodak_yrgb_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT; + d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; + } + else if (load_raw == &LibRaw::kodak_ycbcr_load_raw ) + { + // UNTESTED + d_info->decoder_name = "kodak_ycbcr_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT; + d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; + } + else if (load_raw == &LibRaw::leaf_hdr_load_raw ) + { + d_info->decoder_name = "leaf_hdr_load_raw()"; + d_info->decoder_flags = imgdata.idata.filters ? LIBRAW_DECODER_FLATFIELD : LIBRAW_DECODER_4COMPONENT; + } + else if (load_raw == &LibRaw::lossless_jpeg_load_raw) + { + // Check rbayer + d_info->decoder_name = "lossless_jpeg_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD | LIBRAW_DECODER_HASCURVE; + } + else if (load_raw == &LibRaw::minolta_rd175_load_raw ) + { + // UNTESTED + d_info->decoder_name = "minolta_rd175_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::nikon_compressed_load_raw) + { + // Check rbayer + d_info->decoder_name = "nikon_compressed_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::nokia_load_raw ) + { + // UNTESTED + d_info->decoder_name = "nokia_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::olympus_load_raw ) + { + d_info->decoder_name = "olympus_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::packed_load_raw ) + { + d_info->decoder_name = "packed_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::panasonic_load_raw ) + { + d_info->decoder_name = "panasonic_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::pentax_load_raw ) + { + d_info->decoder_name = "pentax_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::phase_one_load_raw ) + { + d_info->decoder_name = "phase_one_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::phase_one_load_raw_c ) + { + d_info->decoder_name = "phase_one_load_raw_c()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::quicktake_100_load_raw ) + { + // UNTESTED + d_info->decoder_name = "quicktake_100_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::rollei_load_raw ) + { + // UNTESTED + d_info->decoder_name = "rollei_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::sinar_4shot_load_raw ) + { + // UNTESTED + d_info->decoder_name = "sinar_4shot_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_4COMPONENT; + } + else if (load_raw == &LibRaw::smal_v6_load_raw ) + { + // UNTESTED + d_info->decoder_name = "smal_v6_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::smal_v9_load_raw ) + { + // UNTESTED + d_info->decoder_name = "smal_v9_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::sony_load_raw ) + { + d_info->decoder_name = "sony_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::sony_arw_load_raw ) + { + d_info->decoder_name = "sony_arw_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + } + else if (load_raw == &LibRaw::sony_arw2_load_raw ) + { + d_info->decoder_name = "sony_arw2_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; + } + else if (load_raw == &LibRaw::unpacked_load_raw ) + { + d_info->decoder_name = "unpacked_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD | LIBRAW_DECODER_USEBAYER2; + } + else if (load_raw == &LibRaw::redcine_load_raw) + { + d_info->decoder_name = "redcine_load_raw()"; + d_info->decoder_flags = LIBRAW_DECODER_FLATFIELD; + d_info->decoder_flags |= LIBRAW_DECODER_HASCURVE; + } + else + { + d_info->decoder_name = "Unknown unpack function"; + d_info->decoder_flags = LIBRAW_DECODER_NOTSET; + } + return LIBRAW_SUCCESS; +} + +int LibRaw::adjust_maximum() +{ + int i; + ushort real_max; + float auto_threshold; + + if(O.adjust_maximum_thr < 0.00001) + return LIBRAW_SUCCESS; + else if (O.adjust_maximum_thr > 0.99999) + auto_threshold = LIBRAW_DEFAULT_ADJUST_MAXIMUM_THRESHOLD; + else + auto_threshold = O.adjust_maximum_thr; + + + real_max = C.channel_maximum[0]; + for(i = 1; i< 4; i++) + if(real_max < C.channel_maximum[i]) + real_max = C.channel_maximum[i]; + + if (real_max > 0 && real_max < C.maximum && real_max > C.maximum* auto_threshold) + { + C.maximum = real_max; + } + return LIBRAW_SUCCESS; +} + + +void LibRaw:: merror (void *ptr, const char *where) +{ + if (ptr) return; + if(callbacks.mem_cb)(*callbacks.mem_cb)(callbacks.memcb_data, + libraw_internal_data.internal_data.input + ?libraw_internal_data.internal_data.input->fname() + :NULL, + where); + throw LIBRAW_EXCEPTION_ALLOC; +} + + + +int LibRaw::open_file(const char *fname, INT64 max_buf_size) +{ +#ifndef WIN32 + struct stat st; + if(stat(fname,&st)) + return LIBRAW_IO_ERROR; + int big = (st.st_size > max_buf_size)?1:0; +#else + struct _stati64 st; + if(_stati64(fname,&st)) + return LIBRAW_IO_ERROR; + int big = (st.st_size > max_buf_size)?1:0; +#endif + + LibRaw_abstract_datastream *stream; + try { + if(big) + stream = new LibRaw_bigfile_datastream(fname); + else + stream = new LibRaw_file_datastream(fname); + } + + catch (std::bad_alloc) + { + recycle(); + return LIBRAW_UNSUFFICIENT_MEMORY; + } + if(!stream->valid()) + { + delete stream; + return LIBRAW_IO_ERROR; + } + ID.input_internal = 0; // preserve from deletion on error + int ret = open_datastream(stream); + if (ret == LIBRAW_SUCCESS) + { + ID.input_internal =1 ; // flag to delete datastream on recycle + } + else + { + delete stream; + ID.input_internal = 0; + } + return ret; +} + +int LibRaw::open_buffer(void *buffer, size_t size) +{ + // this stream will close on recycle() + if(!buffer || buffer==(void*)-1) + return LIBRAW_IO_ERROR; + + LibRaw_buffer_datastream *stream; + try { + stream = new LibRaw_buffer_datastream(buffer,size); + } + catch (std::bad_alloc) + { + recycle(); + return LIBRAW_UNSUFFICIENT_MEMORY; + } + if(!stream->valid()) + { + delete stream; + return LIBRAW_IO_ERROR; + } + ID.input_internal = 0; // preserve from deletion on error + int ret = open_datastream(stream); + if (ret == LIBRAW_SUCCESS) + { + ID.input_internal =1 ; // flag to delete datastream on recycle + } + else + { + delete stream; + ID.input_internal = 0; + } + return ret; +} + + +int LibRaw::open_datastream(LibRaw_abstract_datastream *stream) +{ + + if(!stream) + return ENOENT; + if(!stream->valid()) + return LIBRAW_IO_ERROR; + recycle(); + + try { + ID.input = stream; + SET_PROC_FLAG(LIBRAW_PROGRESS_OPEN); + + if (O.use_camera_matrix < 0) + O.use_camera_matrix = O.use_camera_wb; + + identify(); + + if(IO.fuji_width) + { + IO.fwidth = S.width; + IO.fheight = S.height; + S.iwidth = S.width = IO.fuji_width << (int)(!libraw_internal_data.unpacker_data.fuji_layout); + S.iheight = S.height = S.raw_height; + S.raw_height += 2*S.top_margin; + } + + if(C.profile_length) + { + if(C.profile) free(C.profile); + C.profile = malloc(C.profile_length); + merror(C.profile,"LibRaw::open_file()"); + ID.input->seek(ID.profile_offset,SEEK_SET); + ID.input->read(C.profile,C.profile_length,1); + } + + SET_PROC_FLAG(LIBRAW_PROGRESS_IDENTIFY); + } + catch ( LibRaw_exceptions err) { + EXCEPTION_HANDLER(err); + } + catch (std::exception ee) { + EXCEPTION_HANDLER(LIBRAW_EXCEPTION_IO_CORRUPT); + } + + if(P1.raw_count < 1) + return LIBRAW_FILE_UNSUPPORTED; + + + write_fun = &LibRaw::write_ppm_tiff; + + if (load_raw == &LibRaw::kodak_ycbcr_load_raw) + { + S.height += S.height & 1; + S.width += S.width & 1; + } + + IO.shrink = P1.filters && (O.half_size || + ((O.threshold || O.aber[0] != 1 || O.aber[2] != 1) )); + + S.iheight = (S.height + IO.shrink) >> IO.shrink; + S.iwidth = (S.width + IO.shrink) >> IO.shrink; + + // Save color,sizes and internal data into raw_image fields + memmove(&imgdata.rawdata.color,&imgdata.color,sizeof(imgdata.color)); + memmove(&imgdata.rawdata.sizes,&imgdata.sizes,sizeof(imgdata.sizes)); + memmove(&imgdata.rawdata.iparams,&imgdata.idata,sizeof(imgdata.idata)); + memmove(&imgdata.rawdata.ioparams,&libraw_internal_data.internal_output_params,sizeof(libraw_internal_data.internal_output_params)); + + SET_PROC_FLAG(LIBRAW_PROGRESS_SIZE_ADJUST); + + + return LIBRAW_SUCCESS; +} + +int LibRaw::unpack(void) +{ + CHECK_ORDER_HIGH(LIBRAW_PROGRESS_LOAD_RAW); + CHECK_ORDER_LOW(LIBRAW_PROGRESS_IDENTIFY); + try { + + RUN_CALLBACK(LIBRAW_PROGRESS_LOAD_RAW,0,2); + if (O.shot_select >= P1.raw_count) + return LIBRAW_REQUEST_FOR_NONEXISTENT_IMAGE; + + if(!load_raw) + return LIBRAW_UNSPECIFIED_ERROR; + + if (O.use_camera_matrix && C.cmatrix[0][0] > 0.25) + { + memcpy (C.rgb_cam, C.cmatrix, sizeof (C.cmatrix)); + IO.raw_color = 0; + } + // already allocated ? + if(imgdata.image) + { + free(imgdata.image); + imgdata.image = 0; + } + + if (libraw_internal_data.unpacker_data.meta_length) + { + libraw_internal_data.internal_data.meta_data = + (char *) malloc (libraw_internal_data.unpacker_data.meta_length); + merror (libraw_internal_data.internal_data.meta_data, "LibRaw::unpack()"); + } + ID.input->seek(libraw_internal_data.unpacker_data.data_offset, SEEK_SET); + int save_document_mode = O.document_mode; + O.document_mode = 0; + + libraw_decoder_info_t decoder_info; + get_decoder_info(&decoder_info); + + int save_iwidth = S.iwidth, save_iheight = S.iheight, save_shrink = IO.shrink; + + int rwidth = S.raw_width, rheight = S.raw_height; + if( !IO.fuji_width) + { + // adjust non-Fuji allocation + if(rwidth < S.width + S.left_margin) + rwidth = S.width + S.left_margin; + if(rheight < S.height + S.top_margin) + rheight = S.height + S.top_margin; + } + + if(decoder_info.decoder_flags & LIBRAW_DECODER_FLATFIELD) + { + imgdata.rawdata.raw_alloc = malloc(rwidth*rheight*sizeof(imgdata.rawdata.raw_image[0])); + imgdata.rawdata.raw_image = (ushort*) imgdata.rawdata.raw_alloc; + } + else if (decoder_info.decoder_flags & LIBRAW_DECODER_4COMPONENT) + { + S.iwidth = S.width; + S.iheight= S.height; + IO.shrink = 0; + imgdata.rawdata.raw_alloc = calloc(rwidth*rheight,sizeof(*imgdata.rawdata.color_image)); + imgdata.rawdata.color_image = (ushort(*)[4]) imgdata.rawdata.raw_alloc; + } + else if (decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY) + { + // sRAW and Foveon only, so extra buffer size is just 1/4 + // Legacy converters does not supports half mode! + S.iwidth = S.width; + S.iheight= S.height; + IO.shrink = 0; + // allocate image as temporary buffer, size + imgdata.rawdata.raw_alloc = calloc(S.iwidth*S.iheight,sizeof(*imgdata.image)); + imgdata.image = (ushort (*)[4]) imgdata.rawdata.raw_alloc; + } + + + (this->*load_raw)(); + + + // recover saved + if( decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY) + { + imgdata.image = 0; + imgdata.rawdata.color_image = (ushort (*)[4]) imgdata.rawdata.raw_alloc; + } + + // calculate channel maximum + { + for(int c=0;c<4;c++) C.channel_maximum[c] = 0; + if(decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY) + { + for(int rc = 0; rc < S.iwidth*S.iheight; rc++) + { + if(C.channel_maximum[0] C.cblack[c]) i = C.cblack[c]; + for (c=0;c<4;c++) + C.cblack[c] -= i; + C.black += i; + + + // Save color,sizes and internal data into raw_image fields + memmove(&imgdata.rawdata.color,&imgdata.color,sizeof(imgdata.color)); + memmove(&imgdata.rawdata.sizes,&imgdata.sizes,sizeof(imgdata.sizes)); + memmove(&imgdata.rawdata.iparams,&imgdata.idata,sizeof(imgdata.idata)); + memmove(&imgdata.rawdata.ioparams,&libraw_internal_data.internal_output_params,sizeof(libraw_internal_data.internal_output_params)); + + SET_PROC_FLAG(LIBRAW_PROGRESS_LOAD_RAW); + RUN_CALLBACK(LIBRAW_PROGRESS_LOAD_RAW,1,2); + + return 0; + } + catch ( LibRaw_exceptions err) { + EXCEPTION_HANDLER(err); + } + catch (std::exception ee) { + EXCEPTION_HANDLER(LIBRAW_EXCEPTION_IO_CORRUPT); + } +} + +void LibRaw::free_image(void) +{ + if(imgdata.image) + { + free(imgdata.image); + imgdata.image = 0; + imgdata.progress_flags + = LIBRAW_PROGRESS_START|LIBRAW_PROGRESS_OPEN + |LIBRAW_PROGRESS_IDENTIFY|LIBRAW_PROGRESS_SIZE_ADJUST|LIBRAW_PROGRESS_LOAD_RAW; + } +} + + +void LibRaw::raw2image_start() +{ + // restore color,sizes and internal data into raw_image fields + memmove(&imgdata.color,&imgdata.rawdata.color,sizeof(imgdata.color)); + memmove(&imgdata.sizes,&imgdata.rawdata.sizes,sizeof(imgdata.sizes)); + memmove(&imgdata.idata,&imgdata.rawdata.iparams,sizeof(imgdata.idata)); + memmove(&libraw_internal_data.internal_output_params,&imgdata.rawdata.ioparams,sizeof(libraw_internal_data.internal_output_params)); + + if (O.user_flip >= 0) + S.flip = O.user_flip; + + switch ((S.flip+3600) % 360) + { + case 270: S.flip = 5; break; + case 180: S.flip = 3; break; + case 90: S.flip = 6; break; + } + + // adjust for half mode! + IO.shrink = P1.filters && (O.half_size || + ((O.threshold || O.aber[0] != 1 || O.aber[2] != 1) )); + + S.iheight = (S.height + IO.shrink) >> IO.shrink; + S.iwidth = (S.width + IO.shrink) >> IO.shrink; + + if (O.user_black >= 0) + C.black = O.user_black; +} + +// Same as raw2image, but +// 1) Do raw2image and rotate_fuji_raw in one pass +// 2) Do raw2image and cropping in one pass +#ifndef MIN +#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif +int LibRaw::raw2image_ex(void) +{ + CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW); + + raw2image_start(); + + // process cropping + int do_crop = 0; + unsigned save_filters = imgdata.idata.filters; + unsigned save_width = S.width; + if (~O.cropbox[2] && ~O.cropbox[3]) + { + int crop[4],c,filt; + for(int c=0;c<4;c++) + { + crop[c] = O.cropbox[c]; + if(crop[c]<0) + crop[c]=0; + } + if(IO.fwidth) + { + crop[0] = (crop[0]/4)*4; + crop[1] = (crop[1]/4)*4; + } + do_crop = 1; + crop[2] = MIN (crop[2], (signed) S.width-crop[0]); + crop[3] = MIN (crop[3], (signed) S.height-crop[1]); + if (crop[2] <= 0 || crop[3] <= 0) + throw LIBRAW_EXCEPTION_BAD_CROP; + + // adjust sizes! + S.left_margin+=crop[0]; + S.top_margin+=crop[1]; + S.width=crop[2]; + S.height=crop[3]; + + S.iheight = (S.height + IO.shrink) >> IO.shrink; + S.iwidth = (S.width + IO.shrink) >> IO.shrink; + if(!IO.fwidth && imgdata.idata.filters) + { + for (filt=c=0; c < 16; c++) + filt |= FC((c >> 1)+(crop[1]), + (c & 1)+(crop[0])) << c*2; + imgdata.idata.filters = filt; + } + } + + if(IO.fwidth) + { + ushort fiwidth,fiheight; + if(do_crop) + { + IO.fuji_width = S.width >> !libraw_internal_data.unpacker_data.fuji_layout; + IO.fwidth = (S.height >> libraw_internal_data.unpacker_data.fuji_layout) + IO.fuji_width; + IO.fheight = IO.fwidth - 1; + } + + fiheight = (IO.fheight + IO.shrink) >> IO.shrink; + fiwidth = (IO.fwidth + IO.shrink) >> IO.shrink; + if(imgdata.image) + { + imgdata.image = (ushort (*)[4])realloc(imgdata.image,fiheight*fiwidth*sizeof (*imgdata.image)); + memset(imgdata.image,0,fiheight*fiwidth *sizeof (*imgdata.image)); + } + else + imgdata.image = (ushort (*)[4]) calloc (fiheight*fiwidth, sizeof (*imgdata.image)); + merror (imgdata.image, "raw2image_ex()"); + + int cblk[4],i; + for(i=0;i<4;i++) + cblk[i] = C.cblack[i]+C.black; + ZERO(C.channel_maximum); + + int row,col; + for(row=0;row> 1); + c = col + ((row+1) >> 1); + } else { + r = IO.fuji_width - 1 + row - (col >> 1); + c = row + ((col+1) >> 1); + } + + int val = imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width + +(col+S.left_margin)]; + int cc = FCF(row,col); + if(val > cblk[cc]) + val -= cblk[cc]; + else + val = 0; + imgdata.image[((r) >> IO.shrink)*fiwidth + ((c) >> IO.shrink)][cc] = val; + if(C.channel_maximum[cc] < val) C.channel_maximum[cc] = val; + } + } + C.maximum -= C.black; + ZERO(C.cblack); + C.black = 0; + + // restore fuji sizes! + S.height = IO.fheight; + S.width = IO.fwidth; + S.iheight = (S.height + IO.shrink) >> IO.shrink; + S.iwidth = (S.width + IO.shrink) >> IO.shrink; + S.raw_height -= 2*S.top_margin; + } + else + { + + if(imgdata.image) + { + imgdata.image = (ushort (*)[4]) realloc (imgdata.image,S.iheight*S.iwidth + *sizeof (*imgdata.image)); + memset(imgdata.image,0,S.iheight*S.iwidth *sizeof (*imgdata.image)); + } + else + imgdata.image = (ushort (*)[4]) calloc (S.iheight*S.iwidth, sizeof (*imgdata.image)); + + merror (imgdata.image, "raw2image_ex()"); + + libraw_decoder_info_t decoder_info; + get_decoder_info(&decoder_info); + + + if(decoder_info.decoder_flags & LIBRAW_DECODER_FLATFIELD) + { + if(decoder_info.decoder_flags & LIBRAW_DECODER_USEBAYER2) +#if defined(LIBRAW_USE_OPENMP) +#pragma omp parallel for default(shared) +#endif + for(int row = 0; row < S.height; row++) + for(int col = 0; col < S.width; col++) + imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][fc(row,col)] + = imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width + +(col+S.left_margin)]; + else +#if defined(LIBRAW_USE_OPENMP) +#pragma omp parallel for default(shared) +#endif + for(int row = 0; row < S.height; row++) + { + int colors[2]; + for (int xx=0;xx<2;xx++) + colors[xx] = COLOR(row,xx); + for(int col = 0; col < S.width; col++) + { + int cc = colors[col&1]; + imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][cc] = + imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width + +(col+S.left_margin)]; + } + } + } + else if (decoder_info.decoder_flags & LIBRAW_DECODER_4COMPONENT) + { +#define FC0(row,col) (save_filters >> ((((row) << 1 & 14) + ((col) & 1)) << 1) & 3) + if(IO.shrink) +#if defined(LIBRAW_USE_OPENMP) +#pragma omp parallel for default(shared) +#endif + for(int row = 0; row < S.height; row++) + for(int col = 0; col < S.width; col++) + imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][FC(row,col)] + = imgdata.rawdata.color_image[(row+S.top_margin)*S.raw_width + +S.left_margin+col] + [FC0(row+S.top_margin,col+S.left_margin)]; +#undef FC0 + else +#if defined(LIBRAW_USE_OPENMP) +#pragma omp parallel for default(shared) +#endif + for(int row = 0; row < S.height; row++) + memmove(&imgdata.image[row*S.width], + &imgdata.rawdata.color_image[(row+S.top_margin)*S.raw_width+S.left_margin], + S.width*sizeof(*imgdata.image)); + } + else if(decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY) + { + if(do_crop) +#if defined(LIBRAW_USE_OPENMP) +#pragma omp parallel for default(shared) +#endif + for(int row = 0; row < S.height; row++) + memmove(&imgdata.image[row*S.width], + &imgdata.rawdata.color_image[(row+S.top_margin)*save_width+S.left_margin], + S.width*sizeof(*imgdata.image)); + + else + memmove(imgdata.image,imgdata.rawdata.color_image, + S.width*S.height*sizeof(*imgdata.image)); + } + + if(imgdata.rawdata.use_ph1_correct) // Phase one unpacked! + phase_one_correct(); + } + return LIBRAW_SUCCESS; +} + +#undef MIN + + + + +int LibRaw::raw2image(void) +{ + + CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW); + + try { + raw2image_start(); + + // free and re-allocate image bitmap + if(imgdata.image) + { + imgdata.image = (ushort (*)[4]) realloc (imgdata.image,S.iheight*S.iwidth *sizeof (*imgdata.image)); + memset(imgdata.image,0,S.iheight*S.iwidth *sizeof (*imgdata.image)); + } + else + imgdata.image = (ushort (*)[4]) calloc (S.iheight*S.iwidth, sizeof (*imgdata.image)); + + merror (imgdata.image, "raw2image()"); + + libraw_decoder_info_t decoder_info; + get_decoder_info(&decoder_info); + + // Move saved bitmap to imgdata.image + if(decoder_info.decoder_flags & LIBRAW_DECODER_FLATFIELD) + { + if(decoder_info.decoder_flags & LIBRAW_DECODER_USEBAYER2) + { + for(int row = 0; row < S.height; row++) + for(int col = 0; col < S.width; col++) + imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][fc(row,col)] + = imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width + +(col+S.left_margin)]; + } + else + { + for(int row = 0; row < S.height; row++) + { + int colors[4]; + for (int xx=0;xx<4;xx++) + colors[xx] = COLOR(row,xx); + for(int col = 0; col < S.width; col++) + { + int cc = colors[col&3]; + imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][cc] = + imgdata.rawdata.raw_image[(row+S.top_margin)*S.raw_width+(col + +S.left_margin)]; + } + } + } + } + else if (decoder_info.decoder_flags & LIBRAW_DECODER_4COMPONENT) + { + if(IO.shrink) + { + for(int row = 0; row < S.height; row++) + for(int col = 0; col < S.width; col++) + { + int cc = FC(row,col); + imgdata.image[(row >> IO.shrink)*S.iwidth + (col>>IO.shrink)][cc] + = imgdata.rawdata.color_image[(row+S.top_margin)*S.raw_width + +S.left_margin+col][cc]; + } + } + else + for(int row = 0; row < S.height; row++) + memmove(&imgdata.image[row*S.width], + &imgdata.rawdata.color_image[(row+S.top_margin)*S.raw_width+S.left_margin], + S.width*sizeof(*imgdata.image)); + } + else if(decoder_info.decoder_flags & LIBRAW_DECODER_LEGACY) + { + // legacy is always 4channel and not shrinked! + memmove(imgdata.image,imgdata.rawdata.color_image,S.width*S.height*sizeof(*imgdata.image)); + } + + if(imgdata.rawdata.use_ph1_correct) // Phase one unpacked! + phase_one_correct(); + + // hack - clear later flags! + imgdata.progress_flags + = LIBRAW_PROGRESS_START|LIBRAW_PROGRESS_OPEN + |LIBRAW_PROGRESS_IDENTIFY|LIBRAW_PROGRESS_SIZE_ADJUST|LIBRAW_PROGRESS_LOAD_RAW; + return 0; + } + catch ( LibRaw_exceptions err) { + EXCEPTION_HANDLER(err); + } +} + + +int LibRaw::dcraw_document_mode_processing(void) +{ +// CHECK_ORDER_HIGH(LIBRAW_PROGRESS_PRE_INTERPOLATE); + CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW); + + try { + + int no_crop = 1; + + if (~O.cropbox[2] && ~O.cropbox[3]) + no_crop=0; + + raw2image_ex(); // raw2image+crop+rotate_fuji_raw + + if (IO.zero_is_bad) + { + remove_zeroes(); + SET_PROC_FLAG(LIBRAW_PROGRESS_REMOVE_ZEROES); + } + + if(!IO.fuji_width) + subtract_black(); + + O.document_mode = 2; + + if(P1.is_foveon) + { + // filter image data for foveon document mode + short *iptr = (short *)imgdata.image; + for (int i=0; i < S.height*S.width*4; i++) + { + if ((short) iptr[i] < 0) + iptr[i] = 0; + } + SET_PROC_FLAG(LIBRAW_PROGRESS_FOVEON_INTERPOLATE); + } + + O.use_fuji_rotate = 0; + + if(O.bad_pixels && no_crop) + { + bad_pixels(O.bad_pixels); + SET_PROC_FLAG(LIBRAW_PROGRESS_BAD_PIXELS); + } + if (O.dark_frame && no_crop) + { + subtract (O.dark_frame); + SET_PROC_FLAG(LIBRAW_PROGRESS_DARK_FRAME); + } + + + adjust_maximum(); + + if (O.user_sat > 0) + C.maximum = O.user_sat; + + pre_interpolate(); + SET_PROC_FLAG(LIBRAW_PROGRESS_PRE_INTERPOLATE); + + if (libraw_internal_data.internal_output_params.mix_green) + { + int i; + for (P1.colors=3, i=0; i < S.height*S.width; i++) + imgdata.image[i][1] = (imgdata.image[i][1] + imgdata.image[i][3]) >> 1; + } + SET_PROC_FLAG(LIBRAW_PROGRESS_MIX_GREEN); + + if (!P1.is_foveon && P1.colors == 3) + median_filter(); + SET_PROC_FLAG(LIBRAW_PROGRESS_MEDIAN_FILTER); + + if (!P1.is_foveon && O.highlight == 2) + blend_highlights(); + + if (!P1.is_foveon && O.highlight > 2) + recover_highlights(); + SET_PROC_FLAG(LIBRAW_PROGRESS_HIGHLIGHTS); + + if (O.use_fuji_rotate) + fuji_rotate(); + SET_PROC_FLAG(LIBRAW_PROGRESS_FUJI_ROTATE); +#ifndef NO_LCMS + if(O.camera_profile) + { + apply_profile(O.camera_profile,O.output_profile); + SET_PROC_FLAG(LIBRAW_PROGRESS_APPLY_PROFILE); + } +#endif + if(!libraw_internal_data.output_data.histogram) + { + libraw_internal_data.output_data.histogram = (int (*)[LIBRAW_HISTOGRAM_SIZE]) malloc(sizeof(*libraw_internal_data.output_data.histogram)*4); + merror(libraw_internal_data.output_data.histogram,"LibRaw::dcraw_document_mode_processing()"); + } + convert_to_rgb(); + SET_PROC_FLAG(LIBRAW_PROGRESS_CONVERT_RGB); + + if (O.use_fuji_rotate) + stretch(); + SET_PROC_FLAG(LIBRAW_PROGRESS_STRETCH); + + return 0; + } + catch ( LibRaw_exceptions err) { + EXCEPTION_HANDLER(err); + } + +} + +#if 1 + +libraw_processed_image_t * LibRaw::dcraw_make_mem_thumb(int *errcode) +{ + if(!T.thumb) + { + if ( !ID.toffset) + { + if(errcode) *errcode= LIBRAW_NO_THUMBNAIL; + } + else + { + if(errcode) *errcode= LIBRAW_OUT_OF_ORDER_CALL; + } + return NULL; + } + + if (T.tformat == LIBRAW_THUMBNAIL_BITMAP) + { + libraw_processed_image_t * ret = + (libraw_processed_image_t *)::malloc(sizeof(libraw_processed_image_t)+T.tlength); + + if(!ret) + { + if(errcode) *errcode= ENOMEM; + return NULL; + } + + memset(ret,0,sizeof(libraw_processed_image_t)); + ret->type = LIBRAW_IMAGE_BITMAP; + ret->height = T.theight; + ret->width = T.twidth; + ret->colors = 3; + ret->bits = 8; + ret->data_size = T.tlength; + memmove(ret->data,T.thumb,T.tlength); + if(errcode) *errcode= 0; + return ret; + } + else if (T.tformat == LIBRAW_THUMBNAIL_JPEG) + { + ushort exif[5]; + int mk_exif = 0; + if(strcmp(T.thumb+6,"Exif")) mk_exif = 1; + + int dsize = T.tlength + mk_exif * (sizeof(exif)+sizeof(tiff_hdr)); + + libraw_processed_image_t * ret = + (libraw_processed_image_t *)::malloc(sizeof(libraw_processed_image_t)+dsize); + + if(!ret) + { + if(errcode) *errcode= ENOMEM; + return NULL; + } + + memset(ret,0,sizeof(libraw_processed_image_t)); + + ret->type = LIBRAW_IMAGE_JPEG; + ret->data_size = dsize; + + ret->data[0] = 0xff; + ret->data[1] = 0xd8; + if(mk_exif) + { + struct tiff_hdr th; + memcpy (exif, "\xff\xe1 Exif\0\0", 10); + exif[1] = htons (8 + sizeof th); + memmove(ret->data+2,exif,sizeof(exif)); + tiff_head (&th, 0); + memmove(ret->data+(2+sizeof(exif)),&th,sizeof(th)); + memmove(ret->data+(2+sizeof(exif)+sizeof(th)),T.thumb+2,T.tlength-2); + } + else + { + memmove(ret->data+2,T.thumb+2,T.tlength-2); + } + if(errcode) *errcode= 0; + return ret; + + } + else + { + if(errcode) *errcode= LIBRAW_UNSUPPORTED_THUMBNAIL; + return NULL; + + } +} + + + +// jlb +// macros for copying pixels to either BGR or RGB formats +#define FORBGR for(c=P1.colors-1; c >=0 ; c--) +#define FORRGB for(c=0; c < P1.colors ; c++) + +void LibRaw::get_mem_image_format(int* width, int* height, int* colors, int* bps) const + +{ + if (S.flip & 4) { + *width = S.height; + *height = S.width; + } + else { + *width = S.width; + *height = S.height; + } + *colors = P1.colors; + *bps = O.output_bps; +} + +int LibRaw::copy_mem_image(void* scan0, int stride, int bgr) + +{ + // the image memory pointed to by scan0 is assumed to be in the format returned by get_mem_image_format + if((imgdata.progress_flags & LIBRAW_PROGRESS_THUMB_MASK) < LIBRAW_PROGRESS_PRE_INTERPOLATE) + return LIBRAW_OUT_OF_ORDER_CALL; + + if(libraw_internal_data.output_data.histogram) + { + int perc, val, total, t_white=0x2000,c; + perc = S.width * S.height * 0.01; /* 99th percentile white level */ + if (IO.fuji_width) perc /= 2; + if (!((O.highlight & ~2) || O.no_auto_bright)) + for (t_white=c=0; c < P1.colors; c++) { + for (val=0x2000, total=0; --val > 32; ) + if ((total += libraw_internal_data.output_data.histogram[c][val]) > perc) break; + if (t_white < val) t_white = val; + } + gamma_curve (O.gamm[0], O.gamm[1], 2, (t_white << 3)/O.bright); + } + + int s_iheight = S.iheight; + int s_iwidth = S.iwidth; + int s_width = S.width; + int s_hwight = S.height; + + S.iheight = S.height; + S.iwidth = S.width; + + if (S.flip & 4) SWAP(S.height,S.width); + uchar *ppm; + ushort *ppm2; + int c, row, col, soff, rstep, cstep; + + soff = flip_index (0, 0); + cstep = flip_index (0, 1) - soff; + rstep = flip_index (1, 0) - flip_index (0, S.width); + + for (row=0; row < S.height; row++, soff += rstep) + { + uchar *bufp = ((uchar*)scan0)+row*stride; + ppm2 = (ushort*) (ppm = bufp); + // keep trivial decisions in the outer loop for speed + if (bgr) { + if (O.output_bps == 8) { + for (col=0; col < S.width; col++, soff += cstep) + FORBGR *ppm++ = imgdata.color.curve[imgdata.image[soff][c]]>>8; + } + else { + for (col=0; col < S.width; col++, soff += cstep) + FORBGR *ppm2++ = imgdata.color.curve[imgdata.image[soff][c]]; + } + } + else { + if (O.output_bps == 8) { + for (col=0; col < S.width; col++, soff += cstep) + FORRGB *ppm++ = imgdata.color.curve[imgdata.image[soff][c]]>>8; + } + else { + for (col=0; col < S.width; col++, soff += cstep) + FORRGB *ppm2++ = imgdata.color.curve[imgdata.image[soff][c]]; + } + } + +// bufp += stride; // go to the next line + } + + S.iheight = s_iheight; + S.iwidth = s_iwidth; + S.width = s_width; + S.height = s_hwight; + + return 0; + + +} +#undef FORBGR +#undef FORRGB + + + +libraw_processed_image_t *LibRaw::dcraw_make_mem_image(int *errcode) + +{ + int width, height, colors, bps; + get_mem_image_format(&width, &height, &colors, &bps); + int stride = width * (bps/8) * colors; + unsigned ds = height * stride; + libraw_processed_image_t *ret = (libraw_processed_image_t*)::malloc(sizeof(libraw_processed_image_t)+ds); + if(!ret) + { + if(errcode) *errcode= ENOMEM; + return NULL; + } + memset(ret,0,sizeof(libraw_processed_image_t)); + + // metadata init + ret->type = LIBRAW_IMAGE_BITMAP; + ret->height = height; + ret->width = width; + ret->colors = colors; + ret->bits = bps; + ret->data_size = ds; + copy_mem_image(ret->data, stride, 0); + + return ret; +} + +#undef FORC +#undef FORCC +#undef SWAP +#endif + + +int LibRaw::dcraw_ppm_tiff_writer(const char *filename) +{ + CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW); + + if(!imgdata.image) + return LIBRAW_OUT_OF_ORDER_CALL; + + if(!filename) + return ENOENT; + FILE *f = fopen(filename,"wb"); + + if(!f) + return errno; + + try { + if(!libraw_internal_data.output_data.histogram) + { + libraw_internal_data.output_data.histogram = + (int (*)[LIBRAW_HISTOGRAM_SIZE]) malloc(sizeof(*libraw_internal_data.output_data.histogram)*4); + merror(libraw_internal_data.output_data.histogram,"LibRaw::dcraw_ppm_tiff_writer()"); + } + libraw_internal_data.internal_data.output = f; + write_ppm_tiff(); + SET_PROC_FLAG(LIBRAW_PROGRESS_FLIP); + libraw_internal_data.internal_data.output = NULL; + fclose(f); + return 0; + } + catch ( LibRaw_exceptions err) { + fclose(f); + EXCEPTION_HANDLER(err); + } +} + +void LibRaw::kodak_thumb_loader() +{ + // some kodak cameras + ushort s_height = S.height, s_width = S.width,s_iwidth = S.iwidth,s_iheight=S.iheight; + int s_colors = P1.colors; + unsigned s_filters = P1.filters; + ushort (*s_image)[4] = imgdata.image; + + + S.height = T.theight; + S.width = T.twidth; + P1.filters = 0; + + if (thumb_load_raw == &CLASS kodak_ycbcr_load_thumb) + { + S.height += S.height & 1; + S.width += S.width & 1; + } + + imgdata.image = (ushort (*)[4]) calloc (S.iheight*S.iwidth, sizeof (*imgdata.image)); + merror (imgdata.image, "LibRaw::kodak_thumb_loader()"); + + ID.input->seek(ID.toffset, SEEK_SET); + // read kodak thumbnail into T.image[] + (this->*thumb_load_raw)(); + + // copy-n-paste from image pipe +#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#define MAX(a,b) ((a) > (b) ? (a) : (b)) +#define LIM(x,min,max) MAX(min,MIN(x,max)) +#define CLIP(x) LIM(x,0,65535) +#define SWAP(a,b) { a ^= b; a ^= (b ^= a); } + + // from scale_colors + { + double dmax; + float scale_mul[4]; + int c,val; + for (dmax=DBL_MAX, c=0; c < 3; c++) + if (dmax > C.pre_mul[c]) + dmax = C.pre_mul[c]; + + for( c=0; c< 3; c++) + scale_mul[c] = (C.pre_mul[c] / dmax) * 65535.0 / C.maximum; + scale_mul[3] = scale_mul[1]; + + size_t size = S.height * S.width; + for (unsigned i=0; i < size*4 ; i++) + { + val = imgdata.image[0][i]; + if(!val) continue; + val *= scale_mul[i & 3]; + imgdata.image[0][i] = CLIP(val); + } + } + + // from convert_to_rgb + ushort *img; + int row,col; + + int (*t_hist)[LIBRAW_HISTOGRAM_SIZE] = (int (*)[LIBRAW_HISTOGRAM_SIZE]) calloc(sizeof(*t_hist),4); + merror (t_hist, "LibRaw::kodak_thumb_loader()"); + + float out[3], + out_cam[3][4] = + { + {2.81761312, -1.98369181, 0.166078627, 0}, + {-0.111855984, 1.73688626, -0.625030339, 0}, + {-0.0379119813, -0.891268849, 1.92918086, 0} + }; + + for (img=imgdata.image[0], row=0; row < S.height; row++) + for (col=0; col < S.width; col++, img+=4) + { + out[0] = out[1] = out[2] = 0; + int c; + for(c=0;c<3;c++) + { + out[0] += out_cam[0][c] * img[c]; + out[1] += out_cam[1][c] * img[c]; + out[2] += out_cam[2][c] * img[c]; + } + for(c=0; c<3; c++) + img[c] = CLIP((int) out[c]); + for(c=0; c> 3]++; + + } + + // from gamma_lut + int (*save_hist)[LIBRAW_HISTOGRAM_SIZE] = libraw_internal_data.output_data.histogram; + libraw_internal_data.output_data.histogram = t_hist; + + // make curve output curve! + ushort (*t_curve) = (ushort*) calloc(sizeof(C.curve),1); + merror (t_curve, "LibRaw::kodak_thumb_loader()"); + memmove(t_curve,C.curve,sizeof(C.curve)); + memset(C.curve,0,sizeof(C.curve)); + { + int perc, val, total, t_white=0x2000,c; + + perc = S.width * S.height * 0.01; /* 99th percentile white level */ + if (IO.fuji_width) perc /= 2; + if (!((O.highlight & ~2) || O.no_auto_bright)) + for (t_white=c=0; c < P1.colors; c++) { + for (val=0x2000, total=0; --val > 32; ) + if ((total += libraw_internal_data.output_data.histogram[c][val]) > perc) break; + if (t_white < val) t_white = val; + } + gamma_curve (O.gamm[0], O.gamm[1], 2, (t_white << 3)/O.bright); + } + + libraw_internal_data.output_data.histogram = save_hist; + free(t_hist); + + // from write_ppm_tiff - copy pixels into bitmap + + S.iheight = S.height; + S.iwidth = S.width; + if (S.flip & 4) SWAP(S.height,S.width); + + if(T.thumb) free(T.thumb); + T.thumb = (char*) calloc (S.width * S.height, P1.colors); + merror (T.thumb, "LibRaw::kodak_thumb_loader()"); + T.tlength = S.width * S.height * P1.colors; + + // from write_tiff_ppm + { + int soff = flip_index (0, 0); + int cstep = flip_index (0, 1) - soff; + int rstep = flip_index (1, 0) - flip_index (0, S.width); + + for (int row=0; row < S.height; row++, soff += rstep) + { + char *ppm = T.thumb + row*S.width*P1.colors; + for (int col=0; col < S.width; col++, soff += cstep) + for(int c = 0; c < P1.colors; c++) + ppm [col*P1.colors+c] = imgdata.color.curve[imgdata.image[soff][c]]>>8; + } + } + + memmove(C.curve,t_curve,sizeof(C.curve)); + free(t_curve); + + // restore variables + free(imgdata.image); + imgdata.image = s_image; + + T.twidth = S.width; + S.width = s_width; + + S.iwidth = s_iwidth; + S.iheight = s_iheight; + + T.theight = S.height; + S.height = s_height; + + T.tcolors = P1.colors; + P1.colors = s_colors; + + P1.filters = s_filters; +} +#undef MIN +#undef MAX +#undef LIM +#undef CLIP +#undef SWAP + + + + +// Äîñòàåò thumbnail èç ôàéëà, ñòàâèò thumb_format â ñîîòâåòñòâèè ñ ôîðìàòîì +int LibRaw::unpack_thumb(void) +{ + CHECK_ORDER_LOW(LIBRAW_PROGRESS_IDENTIFY); + CHECK_ORDER_BIT(LIBRAW_PROGRESS_THUMB_LOAD); + + try { + if ( !ID.toffset) + { + return LIBRAW_NO_THUMBNAIL; + } + else if (thumb_load_raw) + { + kodak_thumb_loader(); + T.tformat = LIBRAW_THUMBNAIL_BITMAP; + SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD); + return 0; + } + else + { + ID.input->seek(ID.toffset, SEEK_SET); + if ( write_thumb == &LibRaw::jpeg_thumb) + { + if(T.thumb) free(T.thumb); + T.thumb = (char *) malloc (T.tlength); + merror (T.thumb, "jpeg_thumb()"); + ID.input->read (T.thumb, 1, T.tlength); + T.tcolors = 3; + T.tformat = LIBRAW_THUMBNAIL_JPEG; + SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD); + return 0; + } + else if (write_thumb == &LibRaw::ppm_thumb) + { + T.tlength = T.twidth * T.theight*3; + if(T.thumb) free(T.thumb); + + T.thumb = (char *) malloc (T.tlength); + merror (T.thumb, "ppm_thumb()"); + + ID.input->read(T.thumb, 1, T.tlength); + + T.tformat = LIBRAW_THUMBNAIL_BITMAP; + SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD); + return 0; + + } + else if (write_thumb == &LibRaw::foveon_thumb) + { + foveon_thumb_loader(); + // may return with error, so format is set in + // foveon thumb loader itself + SET_PROC_FLAG(LIBRAW_PROGRESS_THUMB_LOAD); + return 0; + } + // else if -- all other write_thumb cases! + else + { + return LIBRAW_UNSUPPORTED_THUMBNAIL; + } + } + // last resort + return LIBRAW_UNSUPPORTED_THUMBNAIL; + } + catch ( LibRaw_exceptions err) { + EXCEPTION_HANDLER(err); + } + +} + +int LibRaw::dcraw_thumb_writer(const char *fname) +{ +// CHECK_ORDER_LOW(LIBRAW_PROGRESS_THUMB_LOAD); + + if(!fname) + return ENOENT; + + FILE *tfp = fopen(fname,"wb"); + + if(!tfp) + return errno; + + if(!T.thumb) + { + fclose(tfp); + return LIBRAW_OUT_OF_ORDER_CALL; + } + + try { + switch (T.tformat) + { + case LIBRAW_THUMBNAIL_JPEG: + jpeg_thumb_writer (tfp,T.thumb,T.tlength); + break; + case LIBRAW_THUMBNAIL_BITMAP: + fprintf (tfp, "P6\n%d %d\n255\n", T.twidth, T.theight); + fwrite (T.thumb, 1, T.tlength, tfp); + break; + default: + fclose(tfp); + return LIBRAW_UNSUPPORTED_THUMBNAIL; + } + fclose(tfp); + return 0; + } + catch ( LibRaw_exceptions err) { + fclose(tfp); + EXCEPTION_HANDLER(err); + } +} + +int LibRaw::adjust_sizes_info_only(void) +{ + CHECK_ORDER_LOW(LIBRAW_PROGRESS_IDENTIFY); + + raw2image_start(); + if (O.use_fuji_rotate) + { + if (IO.fuji_width) + { + // restore saved values + if(IO.fheight) + { + S.height = IO.fheight; + S.width = IO.fwidth; + S.iheight = (S.height + IO.shrink) >> IO.shrink; + S.iwidth = (S.width + IO.shrink) >> IO.shrink; + S.raw_height -= 2*S.top_margin; + IO.fheight = IO.fwidth = 0; // prevent repeated calls + } + // dcraw code + IO.fuji_width = (IO.fuji_width - 1 + IO.shrink) >> IO.shrink; + S.iwidth = (ushort)(IO.fuji_width / sqrt(0.5)); + S.iheight = (ushort)( (S.iheight - IO.fuji_width) / sqrt(0.5)); + } + else + { + if (S.pixel_aspect < 1) S.iheight = (ushort)( S.iheight / S.pixel_aspect + 0.5); + if (S.pixel_aspect > 1) S.iwidth = (ushort) (S.iwidth * S.pixel_aspect + 0.5); + } + } + SET_PROC_FLAG(LIBRAW_PROGRESS_FUJI_ROTATE); + if ( S.flip & 4) + { + unsigned short t = S.iheight; + S.iheight=S.iwidth; + S.iwidth = t; + SET_PROC_FLAG(LIBRAW_PROGRESS_FLIP); + } + return 0; +} + + +void LibRaw::subtract_black() +{ + +#define BAYERC(row,col,c) imgdata.image[((row) >> IO.shrink)*S.iwidth + ((col) >> IO.shrink)][c] + + if(C.ph1_black) + { + // Phase One compressed format + int row,col,val,cc; + for(row=0;row=C.phase_one_data.split_col]; + if(val<0) val = 0; + BAYERC(row,col,cc) = val; + } + C.maximum -= C.black; + phase_one_correct(); + // recalculate channel maximum + ZERO(C.channel_maximum); + for(row=0;row val) C.channel_maximum[cc] = val; + } + // clear P1 black level data + imgdata.color.phase_one_data.t_black = 0; + C.ph1_black = 0; + ZERO(C.cblack); + C.black = 0; + } + else if((C.black || C.cblack[0] || C.cblack[1] || C.cblack[2] || C.cblack[3])) + { + int cblk[4],i,row,col,val,cc; + for(i=0;i<4;i++) + cblk[i] = C.cblack[i]+C.black; + ZERO(C.channel_maximum); + + for(row=0;row cblk[cc]) + val -= cblk[cc]; + else + val = 0; + if(C.channel_maximum[cc] < val) C.channel_maximum[cc] = val; + BAYERC(row,col,cc) = val; + } + C.maximum -= C.black; + ZERO(C.cblack); + C.black = 0; + } + else + { + // only calculate channel maximum; + int row,col,cc,val; + ZERO(C.channel_maximum); + for(row=0;row8) shift = 8; + if(shift<0.25) shift = 0.25; + if(smooth < 0.0) smooth = 0.0; + if(smooth > 1.0) smooth = 1.0; + + unsigned short *lut = (ushort*)malloc((TBLN+1)*sizeof(unsigned short)); + + if(shift <=1.0) + { + for(int i=0;i<=TBLN;i++) + lut[i] = (unsigned short)((float)i*shift); + } + else + { + float x1,x2,y1,y2; + + float cstops = log(shift)/log(2.0f); + float room = cstops*2; + float roomlin = powf(2.0f,room); + x2 = (float)TBLN; + x1 = (x2+1)/roomlin-1; + y1 = x1*shift; + y2 = x2*(1+(1-smooth)*(shift-1)); + float sq3x=powf(x1*x1*x2,1.0f/3.0f); + float B = (y2-y1+shift*(3*x1-3.0f*sq3x)) / (x2+2.0f*x1-3.0f*sq3x); + float A = (shift - B)*3.0f*powf(x1*x1,1.0f/3.0f); + float CC = y2 - A*powf(x2,1.0f/3.0f)-B*x2; + for(int i=0;i<=TBLN;i++) + { + float X = (float)i; + float Y = A*powf(X,1.0f/3.0f)+B*X+CC; + if(iTBLN?TBLN:(unsigned short)(Y)); + } + } + for(int i=0; i< S.height*S.width; i++) + { + imgdata.image[i][0] = lut[imgdata.image[i][0]]; + imgdata.image[i][1] = lut[imgdata.image[i][1]]; + imgdata.image[i][2] = lut[imgdata.image[i][2]]; + imgdata.image[i][3] = lut[imgdata.image[i][3]]; + } + for(int i=0;i<4;i++) + C.channel_maximum[i] = lut[C.channel_maximum[i]]; + C.maximum = lut[C.maximum]; + // no need to adjust the minumum, black is already subtracted + free(lut); +} +int LibRaw::dcraw_process(void) +{ + int quality,i; + + int iterations=-1, dcb_enhance=1, noiserd=0; + int eeci_refine_fl=0, es_med_passes_fl=0; + float cared=0,cablue=0; + float linenoise=0; + float lclean=0,cclean=0; + float thresh=0; + float preser=0; + float expos=1.0; + + + CHECK_ORDER_LOW(LIBRAW_PROGRESS_LOAD_RAW); +// CHECK_ORDER_HIGH(LIBRAW_PROGRESS_PRE_INTERPOLATE); + + try { + + int no_crop = 1; + + if (~O.cropbox[2] && ~O.cropbox[3]) + no_crop=0; + + raw2image_ex(); // raw2image+crop+rotate_fuji_raw + subtract_black for fuji + + int save_4color = O.four_color_rgb; + + if (IO.zero_is_bad) + { + remove_zeroes(); + SET_PROC_FLAG(LIBRAW_PROGRESS_REMOVE_ZEROES); + } + + if(!IO.fuji_width) // PhaseOne only, all other cases handled at raw2image_ex() + subtract_black(); + + if(O.half_size) + O.four_color_rgb = 1; + + if(O.bad_pixels && no_crop) + { + bad_pixels(O.bad_pixels); + SET_PROC_FLAG(LIBRAW_PROGRESS_BAD_PIXELS); + } + + if (O.dark_frame && no_crop) + { + subtract (O.dark_frame); + SET_PROC_FLAG(LIBRAW_PROGRESS_DARK_FRAME); + } + + + quality = 2 + !IO.fuji_width; + + if (O.user_qual >= 0) quality = O.user_qual; + + adjust_maximum(); + + if (O.user_sat > 0) C.maximum = O.user_sat; + + if (P1.is_foveon && !O.document_mode) + { + foveon_interpolate(); + SET_PROC_FLAG(LIBRAW_PROGRESS_FOVEON_INTERPOLATE); + } + + if (O.green_matching && !O.half_size) + { + green_matching(); + } + + if (!P1.is_foveon && O.document_mode < 2) + { + scale_colors(); + SET_PROC_FLAG(LIBRAW_PROGRESS_SCALE_COLORS); + } + + pre_interpolate(); + + SET_PROC_FLAG(LIBRAW_PROGRESS_PRE_INTERPOLATE); + + if (O.dcb_iterations >= 0) iterations = O.dcb_iterations; + if (O.dcb_enhance_fl >=0 ) dcb_enhance = O.dcb_enhance_fl; + if (O.fbdd_noiserd >=0 ) noiserd = O.fbdd_noiserd; + if (O.eeci_refine >=0 ) eeci_refine_fl = O.eeci_refine; + if (O.es_med_passes >0 ) es_med_passes_fl = O.es_med_passes; + +// LIBRAW_DEMOSAIC_PACK_GPL3 + + if (!O.half_size && O.cfa_green >0) {thresh=O.green_thresh ;green_equilibrate(thresh);} + if (O.exp_correc >0) {expos=O.exp_shift ; preser=O.exp_preser; exp_bef(expos,preser);} + if (O.ca_correc >0 ) {cablue=O.cablue; cared=O.cared; CA_correct_RT(cablue, cared);} + if (O.cfaline >0 ) {linenoise=O.linenoise; cfa_linedn(linenoise);} + if (O.cfa_clean >0 ) {lclean=O.lclean; cclean=O.cclean; cfa_impulse_gauss(lclean,cclean);} + + if (P1.filters && !O.document_mode) + { + if (noiserd>0 && P1.colors==3 && P1.filters) fbdd(noiserd); + + if (quality == 0) + lin_interpolate(); + else if (quality == 1 || P1.colors > 3) + vng_interpolate(); + else if (quality == 2) + ppg_interpolate(); + + else if (quality == 3) + ahd_interpolate(); // really don't need it here due to fallback op + + else if (quality == 4) + dcb(iterations, dcb_enhance); + +// LIBRAW_DEMOSAIC_PACK_GPL2 + else if (quality == 5) + ahd_interpolate_mod(); + else if (quality == 6) + afd_interpolate_pl(2,1); + else if (quality == 7) + vcd_interpolate(0); + else if (quality == 8) + vcd_interpolate(12); + else if (quality == 9) + lmmse_interpolate(1); + +// LIBRAW_DEMOSAIC_PACK_GPL3 + else if (quality == 10) + amaze_demosaic_RT(); + // fallback to AHD + else + ahd_interpolate(); + + SET_PROC_FLAG(LIBRAW_PROGRESS_INTERPOLATE); + } + if (IO.mix_green) + { + for (P1.colors=3, i=0; i < S.height * S.width; i++) + imgdata.image[i][1] = (imgdata.image[i][1] + imgdata.image[i][3]) >> 1; + SET_PROC_FLAG(LIBRAW_PROGRESS_MIX_GREEN); + } + + if(!P1.is_foveon) + { + if (P1.colors == 3) + { + + if (quality == 8) + { + if (eeci_refine_fl == 1) refinement(); + if (O.med_passes > 0) median_filter_new(); + if (es_med_passes_fl > 0) es_median_filter(); + } + else { + median_filter(); + } + SET_PROC_FLAG(LIBRAW_PROGRESS_MEDIAN_FILTER); + } + } + + if (O.highlight == 2) + { + blend_highlights(); + SET_PROC_FLAG(LIBRAW_PROGRESS_HIGHLIGHTS); + } + + if (O.highlight > 2) + { + recover_highlights(); + SET_PROC_FLAG(LIBRAW_PROGRESS_HIGHLIGHTS); + } + + if (O.use_fuji_rotate) + { + fuji_rotate(); + SET_PROC_FLAG(LIBRAW_PROGRESS_FUJI_ROTATE); + } + + if(!libraw_internal_data.output_data.histogram) + { + libraw_internal_data.output_data.histogram = (int (*)[LIBRAW_HISTOGRAM_SIZE]) malloc(sizeof(*libraw_internal_data.output_data.histogram)*4); + merror(libraw_internal_data.output_data.histogram,"LibRaw::dcraw_process()"); + } +#ifndef NO_LCMS + if(O.camera_profile) + { + apply_profile(O.camera_profile,O.output_profile); + SET_PROC_FLAG(LIBRAW_PROGRESS_APPLY_PROFILE); + } +#endif + + convert_to_rgb(); + SET_PROC_FLAG(LIBRAW_PROGRESS_CONVERT_RGB); + + if (O.use_fuji_rotate) + { + stretch(); + SET_PROC_FLAG(LIBRAW_PROGRESS_STRETCH); + } + O.four_color_rgb = save_4color; // also, restore + + return 0; + } + catch ( LibRaw_exceptions err) { + EXCEPTION_HANDLER(err); + } +} + +// Supported cameras: +static const char *static_camera_list[] = +{ +"Adobe Digital Negative (DNG)", +"AgfaPhoto DC-833m", +"Apple QuickTake 100", +"Apple QuickTake 150", +"Apple QuickTake 200", +"ARRIRAW format", +"AVT F-080C", +"AVT F-145C", +"AVT F-201C", +"AVT F-510C", +"AVT F-810C", +"Canon PowerShot 600", +"Canon PowerShot A5", +"Canon PowerShot A5 Zoom", +"Canon PowerShot A50", +"Canon PowerShot A460 (CHDK hack)", +"Canon PowerShot A470 (CHDK hack)", +"Canon PowerShot A530 (CHDK hack)", +"Canon PowerShot A570 (CHDK hack)", +"Canon PowerShot A590 (CHDK hack)", +"Canon PowerShot A610 (CHDK hack)", +"Canon PowerShot A620 (CHDK hack)", +"Canon PowerShot A630 (CHDK hack)", +"Canon PowerShot A640 (CHDK hack)", +"Canon PowerShot A650 (CHDK hack)", +"Canon PowerShot A710 IS (CHDK hack)", +"Canon PowerShot A720 IS (CHDK hack)", +"Canon PowerShot Pro70", +"Canon PowerShot Pro90 IS", +"Canon PowerShot Pro1", +"Canon PowerShot G1", +"Canon PowerShot G1 X", +"Canon PowerShot G2", +"Canon PowerShot G3", +"Canon PowerShot G5", +"Canon PowerShot G6", +"Canon PowerShot G7 (CHDK hack)", +"Canon PowerShot G9", +"Canon PowerShot G10", +"Canon PowerShot G11", +"Canon PowerShot G12", +"Canon PowerShot S2 IS (CHDK hack)", +"Canon PowerShot S3 IS (CHDK hack)", +"Canon PowerShot S5 IS (CHDK hack)", +"Canon PowerShot SD300 (CHDK hack)", +"Canon PowerShot S30", +"Canon PowerShot S40", +"Canon PowerShot S45", +"Canon PowerShot S50", +"Canon PowerShot S60", +"Canon PowerShot S70", +"Canon PowerShot S90", +"Canon PowerShot S95", +"Canon PowerShot S100", +"Canon PowerShot SX1 IS", +"Canon PowerShot SX110 IS (CHDK hack)", +"Canon PowerShot SX120 IS (CHDK hack)", +"Canon PowerShot SX20 IS (CHDK hack)", +"Canon PowerShot SX220 HS (CHDK hack)", +"Canon PowerShot SX30 IS (CHDK hack)", +"Canon EOS D30", +"Canon EOS D60", +"Canon EOS 5D", +"Canon EOS 5D Mark II", +"Canon EOS 5D Mark III", +"Canon EOS 7D", +"Canon EOS 10D", +"Canon EOS 20D", +"Canon EOS 30D", +"Canon EOS 40D", +"Canon EOS 50D", +"Canon EOS 60D", +"Canon EOS 300D / Digital Rebel / Kiss Digital", +"Canon EOS 350D / Digital Rebel XT / Kiss Digital N", +"Canon EOS 400D / Digital Rebel XTi / Kiss Digital X", +"Canon EOS 450D / Digital Rebel XSi / Kiss Digital X2", +"Canon EOS 500D / Digital Rebel T1i / Kiss Digital X3", +"Canon EOS 550D / Digital Rebel T2i / Kiss Digital X4", +"Canon EOS 600D / Digital Rebel T3i / Kiss Digital X5", +"Canon EOS 1000D / Digital Rebel XS / Kiss Digital F", +"Canon EOS 1100D / Digital Rebel T3 / Kiss Digital X50", +"Canon EOS D2000C", +"Canon EOS-1D", +"Canon EOS-1DS", +"Canon EOS-1D X", +"Canon EOS-1D Mark II", +"Canon EOS-1D Mark II N", +"Canon EOS-1D Mark III", +"Canon EOS-1D Mark IV", +"Canon EOS-1Ds Mark II", +"Canon EOS-1Ds Mark III", +"Casio QV-2000UX", +"Casio QV-3000EX", +"Casio QV-3500EX", +"Casio QV-4000", +"Casio QV-5700", +"Casio QV-R41", +"Casio QV-R51", +"Casio QV-R61", +"Casio EX-S20", +"Casio EX-S100", +"Casio EX-Z4", +"Casio EX-Z50", +"Casio EX-Z500", +"Casio EX-Z55", +"Casio EX-Z60", +"Casio EX-Z75", +"Casio EX-Z750", +"Casio EX-Z8", +"Casio EX-Z850", +"Casio EX-Z1050", +"Casio EX-Z1080", +"Casio Exlim Pro 505", +"Casio Exlim Pro 600", +"Casio Exlim Pro 700", +"Contax N Digital", +"Creative PC-CAM 600", +"Epson R-D1", +"Foculus 531C", +"Fuji FinePix E550", +"Fuji FinePix E900", +"Fuji FinePix F700", +"Fuji FinePix F710", +"Fuji FinePix F800", +"Fuji FinePix F810", +"Fuji FinePix S2Pro", +"Fuji FinePix S3Pro", +"Fuji FinePix S5Pro", +"Fuji FinePix S20Pro", +"Fuji FinePix S100FS", +"Fuji FinePix S5000", +"Fuji FinePix S5100/S5500", +"Fuji FinePix S5200/S5600", +"Fuji FinePix S6000fd", +"Fuji FinePix S7000", +"Fuji FinePix S9000/S9500", +"Fuji FinePix S9100/S9600", +"Fuji FinePix S200EXR", +"Fuji FinePix HS10/HS11", +"Fuji FinePix HS20EXR", +"Fuji FinePix HS30EXR", +"Fuji FinePix F550EXR", +"Fuji FinePix F600EXR", +"Fuji FinePix X-S1", +"Fuji FinePix X100", +"Fuji FinePix X10", +"Fuji IS-1", +"Hasselblad CFV", +"Hasselblad H3D", +"Hasselblad H4D", +"Hasselblad V96C", +"Imacon Ixpress 16-megapixel", +"Imacon Ixpress 22-megapixel", +"Imacon Ixpress 39-megapixel", +"ISG 2020x1520", +"Kodak DC20", +"Kodak DC25", +"Kodak DC40", +"Kodak DC50", +"Kodak DC120 (also try kdc2tiff)", +"Kodak DCS200", +"Kodak DCS315C", +"Kodak DCS330C", +"Kodak DCS420", +"Kodak DCS460", +"Kodak DCS460A", +"Kodak DCS520C", +"Kodak DCS560C", +"Kodak DCS620C", +"Kodak DCS620X", +"Kodak DCS660C", +"Kodak DCS660M", +"Kodak DCS720X", +"Kodak DCS760C", +"Kodak DCS760M", +"Kodak EOSDCS1", +"Kodak EOSDCS3B", +"Kodak NC2000F", +"Kodak ProBack", +"Kodak PB645C", +"Kodak PB645H", +"Kodak PB645M", +"Kodak DCS Pro 14n", +"Kodak DCS Pro 14nx", +"Kodak DCS Pro SLR/c", +"Kodak DCS Pro SLR/n", +"Kodak C330", +"Kodak C603", +"Kodak P850", +"Kodak P880", +"Kodak Z980", +"Kodak Z981", +"Kodak Z990", +"Kodak Z1015", +"Kodak KAI-0340", +"Konica KD-400Z", +"Konica KD-510Z", +"Leaf AFi 7", +"Leaf AFi-II 5", +"Leaf AFi-II 6", +"Leaf AFi-II 7", +"Leaf AFi-II 8", +"Leaf AFi-II 10", +"Leaf AFi-II 10R", +"Leaf AFi-II 12", +"Leaf AFi-II 12R", +"Leaf Aptus 17", +"Leaf Aptus 22", +"Leaf Aptus 54S", +"Leaf Aptus 65", +"Leaf Aptus 75", +"Leaf Aptus 75S", +"Leaf Cantare", +"Leaf CatchLight", +"Leaf CMost", +"Leaf DCB2", +"Leaf Valeo 6", +"Leaf Valeo 11", +"Leaf Valeo 17", +"Leaf Valeo 22", +"Leaf Volare", +"Leica Digilux 2", +"Leica Digilux 3", +"Leica D-LUX2", +"Leica D-LUX3", +"Leica D-LUX4", +"Leica D-LUX5", +"Leica V-LUX1", +"Leica V-LUX2", +"Logitech Fotoman Pixtura", +"Mamiya ZD", +"Micron 2010", +"Minolta RD175", +"Minolta DiMAGE 5", +"Minolta DiMAGE 7", +"Minolta DiMAGE 7i", +"Minolta DiMAGE 7Hi", +"Minolta DiMAGE A1", +"Minolta DiMAGE A2", +"Minolta DiMAGE A200", +"Minolta DiMAGE G400", +"Minolta DiMAGE G500", +"Minolta DiMAGE G530", +"Minolta DiMAGE G600", +"Minolta DiMAGE Z2", +"Minolta Alpha/Dynax/Maxxum 5D", +"Minolta Alpha/Dynax/Maxxum 7D", +"Motorola PIXL", +"Nikon D1", +"Nikon D1H", +"Nikon D1X", +"Nikon D2H", +"Nikon D2Hs", +"Nikon D2X", +"Nikon D2Xs", +"Nikon D3", +"Nikon D3s", +"Nikon D3X", +"Nikon D4", +"Nikon D40", +"Nikon D40X", +"Nikon D50", +"Nikon D60", +"Nikon D70", +"Nikon D70s", +"Nikon D80", +"Nikon D90", +"Nikon D100", +"Nikon D200", +"Nikon D300", +"Nikon D300s", +"Nikon D700", +"Nikon D3000", +"Nikon D3100", +"Nikon D3200", +"Nikon D5000", +"Nikon D5100", +"Nikon D7000", +"Nikon D800", +"Nikon 1 J1", +"Nikon 1 V1", +"Nikon E700 (\"DIAG RAW\" hack)", +"Nikon E800 (\"DIAG RAW\" hack)", +"Nikon E880 (\"DIAG RAW\" hack)", +"Nikon E900 (\"DIAG RAW\" hack)", +"Nikon E950 (\"DIAG RAW\" hack)", +"Nikon E990 (\"DIAG RAW\" hack)", +"Nikon E995 (\"DIAG RAW\" hack)", +"Nikon E2100 (\"DIAG RAW\" hack)", +"Nikon E2500 (\"DIAG RAW\" hack)", +"Nikon E3200 (\"DIAG RAW\" hack)", +"Nikon E3700 (\"DIAG RAW\" hack)", +"Nikon E4300 (\"DIAG RAW\" hack)", +"Nikon E4500 (\"DIAG RAW\" hack)", +"Nikon E5000", +"Nikon E5400", +"Nikon E5700", +"Nikon E8400", +"Nikon E8700", +"Nikon E8800", +"Nikon Coolpix P6000", +"Nikon Coolpix P7000", +"Nikon Coolpix P7100", +"Nikon Coolpix S6 (\"DIAG RAW\" hack)", +"Nokia N95", +"Nokia X2", +"Olympus C3030Z", +"Olympus C5050Z", +"Olympus C5060WZ", +"Olympus C7070WZ", +"Olympus C70Z,C7000Z", +"Olympus C740UZ", +"Olympus C770UZ", +"Olympus C8080WZ", +"Olympus X200,D560Z,C350Z", +"Olympus E-1", +"Olympus E-3", +"Olympus E-5", +"Olympus E-10", +"Olympus E-20", +"Olympus E-30", +"Olympus E-300", +"Olympus E-330", +"Olympus E-400", +"Olympus E-410", +"Olympus E-420", +"Olympus E-500", +"Olympus E-510", +"Olympus E-520", +"Olympus E-620", +"Olympus E-P1", +"Olympus E-P2", +"Olympus E-P3", +"Olympus E-PL1", +"Olympus E-PL1s", +"Olympus E-PL2", +"Olympus E-PL3", +"Olympus E-PM1", +"Olympus E-M5", +"Olympus SP310", +"Olympus SP320", +"Olympus SP350", +"Olympus SP500UZ", +"Olympus SP510UZ", +"Olympus SP550UZ", +"Olympus SP560UZ", +"Olympus SP570UZ", +"Olympus XZ-1", +"Panasonic DMC-FZ8", +"Panasonic DMC-FZ18", +"Panasonic DMC-FZ28", +"Panasonic DMC-FZ30", +"Panasonic DMC-FZ35/FZ38", +"Panasonic DMC-FZ40", +"Panasonic DMC-FZ50", +"Panasonic DMC-FZ100", +"Panasonic DMC-FZ150", +"Panasonic DMC-FX150", +"Panasonic DMC-G1", +"Panasonic DMC-G10", +"Panasonic DMC-G2", +"Panasonic DMC-G3", +"Panasonic DMC-GF1", +"Panasonic DMC-GF2", +"Panasonic DMC-GF3", +"Panasonic DMC-GF5", +"Panasonic DMC-GH1", +"Panasonic DMC-GH2", +"Panasonic DMC-GX1", +"Panasonic DMC-L1", +"Panasonic DMC-L10", +"Panasonic DMC-LC1", +"Panasonic DMC-LX1", +"Panasonic DMC-LX2", +"Panasonic DMC-LX3", +"Panasonic DMC-LX5", +"Pentax *ist D", +"Pentax *ist DL", +"Pentax *ist DL2", +"Pentax *ist DS", +"Pentax *ist DS2", +"Pentax K10D", +"Pentax K20D", +"Pentax K100D", +"Pentax K100D Super", +"Pentax K200D", +"Pentax K2000/K-m", +"Pentax K-x", +"Pentax K-r", +"Pentax K-5", +"Pentax K-7", +"Pentax Optio S", +"Pentax Optio S4", +"Pentax Optio 33WR", +"Pentax Optio 750Z", +"Pentax 645D", +"Phase One LightPhase", +"Phase One H 10", +"Phase One H 20", +"Phase One H 25", +"Phase One P 20", +"Phase One P 25", +"Phase One P 30", +"Phase One P 45", +"Phase One P 45+", +"Phase One P 65", +"Pixelink A782", +#ifdef LIBRAW_DEMOSAIC_PACK_GPL2 +"Polaroid x530", +#endif +#ifndef NO_JASPER +"Redcode R3D format", +#endif +"Rollei d530flex", +"RoverShot 3320af", +"Samsung EX1", +"Samsung GX-1S", +"Samsung GX10", +"Samsung GX20", +"Samsung NX10", +"Samsung NX11", +"Samsung NX100", +"Samsung NX20", +"Samsung NX200", +"Samsung NX210", +"Samsung WB550", +"Samsung WB2000", +"Samsung S85 (hacked)", +"Samsung S850 (hacked)", +"Sarnoff 4096x5440", +#ifdef LIBRAW_DEMOSAIC_PACK_GPL2 +"Sigma SD9", +"Sigma SD10", +"Sigma SD14", +#endif +"Sinar 3072x2048", +"Sinar 4080x4080", +"Sinar 4080x5440", +"Sinar STI format", +"SMaL Ultra-Pocket 3", +"SMaL Ultra-Pocket 4", +"SMaL Ultra-Pocket 5", +"Sony DSC-F828", +"Sony DSC-R1", +"Sony DSC-V3", +"Sony DSLR-A100", +"Sony DSLR-A200", +"Sony DSLR-A230", +"Sony DSLR-A290", +"Sony DSLR-A300", +"Sony DSLR-A330", +"Sony DSLR-A350", +"Sony DSLR-A380", +"Sony DSLR-A390", +"Sony DSLR-A450", +"Sony DSLR-A500", +"Sony DSLR-A550", +"Sony DSLR-A580", +"Sony DSLR-A700", +"Sony DSLR-A850", +"Sony DSLR-A900", +"Sony NEX-3", +"Sony NEX-5", +"Sony NEX-5N", +"Sony NEX-7", +"Sony NEX-C3", +"Sony NEX-F3", +"Sony SLT-A33", +"Sony SLT-A35", +"Sony SLT-A37", +"Sony SLT-A55V", +"Sony SLT-A57", +"Sony SLT-A65V", +"Sony SLT-A77V", +"Sony XCD-SX910CR", +"STV680 VGA", + NULL +}; + +const char** LibRaw::cameraList() { return static_camera_list;} +int LibRaw::cameraCount() { return (sizeof(static_camera_list)/sizeof(static_camera_list[0]))-1; } + + +const char * LibRaw::strprogress(enum LibRaw_progress p) +{ + switch(p) + { + case LIBRAW_PROGRESS_START: + return "Starting"; + case LIBRAW_PROGRESS_OPEN : + return "Opening file"; + case LIBRAW_PROGRESS_IDENTIFY : + return "Reading metadata"; + case LIBRAW_PROGRESS_SIZE_ADJUST: + return "Adjusting size"; + case LIBRAW_PROGRESS_LOAD_RAW: + return "Reading RAW data"; + case LIBRAW_PROGRESS_REMOVE_ZEROES: + return "Clearing zero values"; + case LIBRAW_PROGRESS_BAD_PIXELS : + return "Removing dead pixels"; + case LIBRAW_PROGRESS_DARK_FRAME: + return "Subtracting dark frame data"; + case LIBRAW_PROGRESS_FOVEON_INTERPOLATE: + return "Interpolating Foveon sensor data"; + case LIBRAW_PROGRESS_SCALE_COLORS: + return "Scaling colors"; + case LIBRAW_PROGRESS_PRE_INTERPOLATE: + return "Pre-interpolating"; + case LIBRAW_PROGRESS_INTERPOLATE: + return "Interpolating"; + case LIBRAW_PROGRESS_MIX_GREEN : + return "Mixing green channels"; + case LIBRAW_PROGRESS_MEDIAN_FILTER : + return "Median filter"; + case LIBRAW_PROGRESS_HIGHLIGHTS: + return "Highlight recovery"; + case LIBRAW_PROGRESS_FUJI_ROTATE : + return "Rotating Fuji diagonal data"; + case LIBRAW_PROGRESS_FLIP : + return "Flipping image"; + case LIBRAW_PROGRESS_APPLY_PROFILE: + return "ICC conversion"; + case LIBRAW_PROGRESS_CONVERT_RGB: + return "Converting to RGB"; + case LIBRAW_PROGRESS_STRETCH: + return "Stretching image"; + case LIBRAW_PROGRESS_THUMB_LOAD: + return "Loading thumbnail"; + default: + return "Some strange things"; + } +} diff --git a/Source/LibRawLite/src/libraw_datastream.cpp b/Source/LibRawLite/src/libraw_datastream.cpp index be05e05..b42d18e 100644 --- a/Source/LibRawLite/src/libraw_datastream.cpp +++ b/Source/LibRawLite/src/libraw_datastream.cpp @@ -1,526 +1,526 @@ -#ifdef WIN32 -#ifdef __MINGW32__ - #define _WIN32_WINNT 0x0500 - #include -#endif -#endif - -#define LIBRAW_LIBRARY_BUILD -#include "libraw/libraw_types.h" -#include "libraw/libraw.h" -#include "libraw/libraw_datastream.h" -#include "internal/libraw_bytebuffer.h" -#ifdef USE_JASPER -#include /* Decode RED camera movies */ -#else -#define NO_JASPER -#endif - - -LibRaw_byte_buffer::LibRaw_byte_buffer(unsigned sz) -{ - buf=0; size=sz; offt=0; do_free=0; - if(size) - { - buf = (unsigned char*)malloc(size); do_free=1; - } -} - -void LibRaw_byte_buffer::set_buffer(void *bb, unsigned int sz) -{ - buf = (unsigned char*)bb; size = sz; offt=0; do_free=0; -} - -LibRaw_byte_buffer::~LibRaw_byte_buffer() -{ - if(do_free) free(buf); -} - -LibRaw_byte_buffer *LibRaw_abstract_datastream::make_byte_buffer(unsigned int sz) -{ - LibRaw_byte_buffer *ret = new LibRaw_byte_buffer(sz); - read(ret->get_buffer(),sz,1); - return ret; -} - -int LibRaw_abstract_datastream::tempbuffer_open(void *buf, size_t size) -{ - if(substream) return EBUSY; - substream = new LibRaw_buffer_datastream(buf,size); - return substream?0:EINVAL; -} - - -void LibRaw_abstract_datastream::tempbuffer_close() -{ - if(substream) delete substream; - substream = NULL; -} - -// == LibRaw_file_datastream == - -LibRaw_file_datastream::LibRaw_file_datastream(const char *fname) - :filename(fname) -{ - if (filename) { - std::auto_ptr buf(new std::filebuf()); - buf->open(filename, std::ios_base::in | std::ios_base::binary); - if (buf->is_open()) { - f = buf; - } - } -} - int LibRaw_file_datastream::valid() -{ - return f.get() ? 1 : 0; -} - -#define LR_STREAM_CHK() do {if(!f.get()) throw LIBRAW_EXCEPTION_IO_EOF;}while(0) - -int LibRaw_file_datastream::read(void * ptr,size_t size, size_t nmemb) -{ - if(substream) return substream->read(ptr,size,nmemb); - -/* Visual Studio 2008 marks sgetn as insecure, but VS2010 does not. */ -#if defined(WIN32SECURECALLS) && (_MSC_VER < 1600) - LR_STREAM_CHK(); return int(f->_Sgetn_s(static_cast(ptr), nmemb * size,nmemb * size) / size); -#else - LR_STREAM_CHK(); return int(f->sgetn(static_cast(ptr), std::streamsize(nmemb * size)) / size); -#endif -} - -int LibRaw_file_datastream::eof() -{ - if(substream) return substream->eof(); - LR_STREAM_CHK(); return f->sgetc() == EOF; -} - -int LibRaw_file_datastream::seek(INT64 o, int whence) -{ - if(substream) return substream->seek(o,whence); - LR_STREAM_CHK(); - std::ios_base::seekdir dir; - switch (whence) - { - case SEEK_SET: dir = std::ios_base::beg; break; - case SEEK_CUR: dir = std::ios_base::cur; break; - case SEEK_END: dir = std::ios_base::end; break; - default: dir = std::ios_base::beg; - } - return (int)f->pubseekoff((long)o, dir); -} - -INT64 LibRaw_file_datastream::tell() -{ - if(substream) return substream->tell(); - LR_STREAM_CHK(); return f->pubseekoff(0, std::ios_base::cur); -} - -char* LibRaw_file_datastream::gets(char *str, int sz) -{ - if(substream) return substream->gets(str,sz); - LR_STREAM_CHK(); - std::istream is(f.get()); - is.getline(str, sz); - if (is.fail()) return 0; - return str; -} - -int LibRaw_file_datastream::scanf_one(const char *fmt, void*val) -{ - if(substream) return substream->scanf_one(fmt,val); - LR_STREAM_CHK(); - - std::istream is(f.get()); - - /* HUGE ASSUMPTION: *fmt is either "%d" or "%f" */ - if (strcmp(fmt, "%d") == 0) { - int d; - is >> d; - if (is.fail()) return EOF; - *(static_cast(val)) = d; - } else { - float f; - is >> f; - if (is.fail()) return EOF; - *(static_cast(val)) = f; - } - - return 1; -} - -const char* LibRaw_file_datastream::fname() -{ - return filename; -} - -/* You can't have a "subfile" and a "tempfile" at the same time. */ -int LibRaw_file_datastream::subfile_open(const char *fn) -{ - LR_STREAM_CHK(); - if (saved_f.get()) return EBUSY; - saved_f = f; - std::auto_ptr buf(new std::filebuf()); - - buf->open(fn, std::ios_base::in | std::ios_base::binary); - if (!buf->is_open()) { - f = saved_f; - return ENOENT; - } else { - f = buf; - } - - return 0; -} - - -void LibRaw_file_datastream::subfile_close() -{ - if (!saved_f.get()) return; - f = saved_f; -} - -#undef LR_STREAM_CHK - -void * LibRaw_file_datastream::make_jas_stream() -{ -#ifdef NO_JASPER - return NULL; -#else - return jas_stream_fopen(fname(),"rb"); -#endif -} - -// == LibRaw_buffer_datastream -LibRaw_buffer_datastream::LibRaw_buffer_datastream(void *buffer, size_t bsize) -{ - buf = (unsigned char*)buffer; streampos = 0; streamsize = bsize; -} - -LibRaw_buffer_datastream::~LibRaw_buffer_datastream(){} - -int LibRaw_buffer_datastream::read(void * ptr,size_t sz, size_t nmemb) -{ - if(substream) return substream->read(ptr,sz,nmemb); - size_t to_read = sz*nmemb; - if(to_read > streamsize - streampos) - to_read = streamsize-streampos; - if(to_read<1) - return 0; - memmove(ptr,buf+streampos,to_read); - streampos+=to_read; - return int((to_read+sz-1)/sz); -} - -int LibRaw_buffer_datastream::seek(INT64 o, int whence) -{ - if(substream) return substream->seek(o,whence); - switch(whence) - { - case SEEK_SET: - if(o<0) - streampos = 0; - else if (size_t(o) > streamsize) - streampos = streamsize; - else - streampos = size_t(o); - return 0; - case SEEK_CUR: - if(o<0) - { - if(size_t(-o) >= streampos) - streampos = 0; - else - streampos += (size_t)o; - } - else if (o>0) - { - if(o+streampos> streamsize) - streampos = streamsize; - else - streampos += (size_t)o; - } - return 0; - case SEEK_END: - if(o>0) - streampos = streamsize; - else if ( size_t(-o) > streamsize) - streampos = 0; - else - streampos = streamsize+(size_t)o; - return 0; - default: - return 0; - } -} - -INT64 LibRaw_buffer_datastream::tell() -{ - if(substream) return substream->tell(); - return INT64(streampos); -} - -char* LibRaw_buffer_datastream::gets(char *s, int sz) -{ - if (substream) return substream->gets(s,sz); - unsigned char *psrc,*pdest,*str; - str = (unsigned char *)s; - psrc = buf+streampos; - pdest = str; - while ( (size_t(psrc - buf) < streamsize) - && - ((pdest-str)scanf_one(fmt,val); - int scanf_res; - if(streampos>streamsize) return 0; -#ifndef WIN32SECURECALLS - scanf_res = sscanf((char*)(buf+streampos),fmt,val); -#else - scanf_res = sscanf_s((char*)(buf+streampos),fmt,val); -#endif - if(scanf_res>0) - { - int xcnt=0; - while(streampos24) - break; - } - } - return scanf_res; -} - -LibRaw_byte_buffer *LibRaw_buffer_datastream::make_byte_buffer(unsigned int sz) -{ - LibRaw_byte_buffer *ret = new LibRaw_byte_buffer(0); - if(streampos + sz > streamsize) - sz = streamsize - streampos; - ret->set_buffer(buf+streampos,sz); - return ret; -} - -int LibRaw_buffer_datastream::eof() -{ - if(substream) return substream->eof(); - return streampos >= streamsize; -} - int LibRaw_buffer_datastream::valid() -{ - return buf?1:0; -} - - -void * LibRaw_buffer_datastream::make_jas_stream() -{ -#ifdef NO_JASPER - return NULL; -#else - return jas_stream_memopen((char*)buf,streamsize); -#endif -} - -// == LibRaw_bigfile_datastream -LibRaw_bigfile_datastream::LibRaw_bigfile_datastream(const char *fname) -{ - if(fname) - { - filename = fname; -#ifndef WIN32SECURECALLS - f = fopen(fname,"rb"); -#else - if(fopen_s(&f,fname,"rb")) - f = 0; -#endif - } - else - {filename=0;f=0;} - sav=0; -} - -LibRaw_bigfile_datastream::~LibRaw_bigfile_datastream() {if(f)fclose(f); if(sav)fclose(sav);} -int LibRaw_bigfile_datastream::valid() { return f?1:0;} - -#define LR_BF_CHK() do {if(!f) throw LIBRAW_EXCEPTION_IO_EOF;}while(0) - -int LibRaw_bigfile_datastream::read(void * ptr,size_t size, size_t nmemb) -{ - LR_BF_CHK(); - return substream?substream->read(ptr,size,nmemb):int(fread(ptr,size,nmemb,f)); -} - -int LibRaw_bigfile_datastream::eof() -{ - LR_BF_CHK(); - return substream?substream->eof():feof(f); -} - -int LibRaw_bigfile_datastream:: seek(INT64 o, int whence) -{ - LR_BF_CHK(); -#if defined (WIN32) -#ifdef WIN32SECURECALLS - return substream?substream->seek(o,whence):_fseeki64(f,o,whence); -#else - return substream?substream->seek(o,whence):fseek(f,(long)o,whence); -#endif -#else - return substream?substream->seek(o,whence):fseeko(f,o,whence); -#endif -} - -INT64 LibRaw_bigfile_datastream::tell() -{ - LR_BF_CHK(); -#if defined (WIN32) -#ifdef WIN32SECURECALLS - return substream?substream->tell():_ftelli64(f); -#else - return substream?substream->tell():ftell(f); -#endif -#else - return substream?substream->tell():ftello(f); -#endif -} - -char* LibRaw_bigfile_datastream::gets(char *str, int sz) -{ - LR_BF_CHK(); - return substream?substream->gets(str,sz):fgets(str,sz,f); -} - -int LibRaw_bigfile_datastream::scanf_one(const char *fmt, void*val) -{ - LR_BF_CHK(); - return substream?substream->scanf_one(fmt,val): -#ifndef WIN32SECURECALLS - fscanf(f,fmt,val) -#else - fscanf_s(f,fmt,val) -#endif - ; -} - -const char *LibRaw_bigfile_datastream::fname() -{ - return filename; -} - -int LibRaw_bigfile_datastream::subfile_open(const char *fn) -{ - if(sav) return EBUSY; - sav = f; -#ifndef WIN32SECURECALLS - f = fopen(fn,"rb"); -#else - fopen_s(&f,fn,"rb"); -#endif - if(!f) - { - f = sav; - sav = NULL; - return ENOENT; - } - else - return 0; -} - -void LibRaw_bigfile_datastream::subfile_close() -{ - if(!sav) return; - fclose(f); - f = sav; - sav = 0; -} - - -void *LibRaw_bigfile_datastream::make_jas_stream() -{ -#ifdef NO_JASPER - return NULL; -#else - return jas_stream_freopen(fname(),"rb",f); -#endif -} - -// == LibRaw_windows_datastream -#ifdef WIN32 - -LibRaw_windows_datastream::LibRaw_windows_datastream(const TCHAR* sFile) - : LibRaw_buffer_datastream(NULL, 0) - , hMap_(0) - , pView_(NULL) -{ - HANDLE hFile = CreateFile(sFile, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - if (hFile == INVALID_HANDLE_VALUE) - throw std::runtime_error("failed to open the file"); - - try { Open(hFile); } catch(...) { CloseHandle(hFile); throw; } - - CloseHandle(hFile); // windows will defer the actual closing of this handle until the hMap_ is closed - reconstruct_base(); -} - - // ctor: construct with a file handle - caller is responsible for closing the file handle -LibRaw_windows_datastream::LibRaw_windows_datastream(HANDLE hFile) - : LibRaw_buffer_datastream(NULL, 0) - , hMap_(0) - , pView_(NULL) -{ - Open(hFile); - reconstruct_base(); -} - -// dtor: unmap and close the mapping handle -LibRaw_windows_datastream::~LibRaw_windows_datastream() -{ - if (pView_ != NULL) - ::UnmapViewOfFile(pView_); - - if (hMap_ != 0) - ::CloseHandle(hMap_); -} - -void LibRaw_windows_datastream::Open(HANDLE hFile) -{ - // create a file mapping handle on the file handle - hMap_ = ::CreateFileMapping(hFile, 0, PAGE_READONLY, 0, 0, 0); - if (hMap_ == NULL) throw std::runtime_error("failed to create file mapping"); - - // now map the whole file base view - if (!::GetFileSizeEx(hFile, (PLARGE_INTEGER)&cbView_)) - throw std::runtime_error("failed to get the file size"); - - pView_ = ::MapViewOfFile(hMap_, FILE_MAP_READ, 0, 0, (size_t)cbView_); - if (pView_ == NULL) - throw std::runtime_error("failed to map the file"); -} - - -#endif - - - +#ifdef WIN32 +#ifdef __MINGW32__ + #define _WIN32_WINNT 0x0500 + #include +#endif +#endif + +#define LIBRAW_LIBRARY_BUILD +#include "libraw/libraw_types.h" +#include "libraw/libraw.h" +#include "libraw/libraw_datastream.h" +#include "internal/libraw_bytebuffer.h" +#ifdef USE_JASPER +#include /* Decode RED camera movies */ +#else +#define NO_JASPER +#endif + + +LibRaw_byte_buffer::LibRaw_byte_buffer(unsigned sz) +{ + buf=0; size=sz; offt=0; do_free=0; + if(size) + { + buf = (unsigned char*)malloc(size); do_free=1; + } +} + +void LibRaw_byte_buffer::set_buffer(void *bb, unsigned int sz) +{ + buf = (unsigned char*)bb; size = sz; offt=0; do_free=0; +} + +LibRaw_byte_buffer::~LibRaw_byte_buffer() +{ + if(do_free) free(buf); +} + +LibRaw_byte_buffer *LibRaw_abstract_datastream::make_byte_buffer(unsigned int sz) +{ + LibRaw_byte_buffer *ret = new LibRaw_byte_buffer(sz); + read(ret->get_buffer(),sz,1); + return ret; +} + +int LibRaw_abstract_datastream::tempbuffer_open(void *buf, size_t size) +{ + if(substream) return EBUSY; + substream = new LibRaw_buffer_datastream(buf,size); + return substream?0:EINVAL; +} + + +void LibRaw_abstract_datastream::tempbuffer_close() +{ + if(substream) delete substream; + substream = NULL; +} + +// == LibRaw_file_datastream == + +LibRaw_file_datastream::LibRaw_file_datastream(const char *fname) + :filename(fname) +{ + if (filename) { + std::auto_ptr buf(new std::filebuf()); + buf->open(filename, std::ios_base::in | std::ios_base::binary); + if (buf->is_open()) { + f = buf; + } + } +} + int LibRaw_file_datastream::valid() +{ + return f.get() ? 1 : 0; +} + +#define LR_STREAM_CHK() do {if(!f.get()) throw LIBRAW_EXCEPTION_IO_EOF;}while(0) + +int LibRaw_file_datastream::read(void * ptr,size_t size, size_t nmemb) +{ + if(substream) return substream->read(ptr,size,nmemb); + +/* Visual Studio 2008 marks sgetn as insecure, but VS2010 does not. */ +#if defined(WIN32SECURECALLS) && (_MSC_VER < 1600) + LR_STREAM_CHK(); return int(f->_Sgetn_s(static_cast(ptr), nmemb * size,nmemb * size) / size); +#else + LR_STREAM_CHK(); return int(f->sgetn(static_cast(ptr), std::streamsize(nmemb * size)) / size); +#endif +} + +int LibRaw_file_datastream::eof() +{ + if(substream) return substream->eof(); + LR_STREAM_CHK(); return f->sgetc() == EOF; +} + +int LibRaw_file_datastream::seek(INT64 o, int whence) +{ + if(substream) return substream->seek(o,whence); + LR_STREAM_CHK(); + std::ios_base::seekdir dir; + switch (whence) + { + case SEEK_SET: dir = std::ios_base::beg; break; + case SEEK_CUR: dir = std::ios_base::cur; break; + case SEEK_END: dir = std::ios_base::end; break; + default: dir = std::ios_base::beg; + } + return (int)f->pubseekoff((long)o, dir); +} + +INT64 LibRaw_file_datastream::tell() +{ + if(substream) return substream->tell(); + LR_STREAM_CHK(); return f->pubseekoff(0, std::ios_base::cur); +} + +char* LibRaw_file_datastream::gets(char *str, int sz) +{ + if(substream) return substream->gets(str,sz); + LR_STREAM_CHK(); + std::istream is(f.get()); + is.getline(str, sz); + if (is.fail()) return 0; + return str; +} + +int LibRaw_file_datastream::scanf_one(const char *fmt, void*val) +{ + if(substream) return substream->scanf_one(fmt,val); + LR_STREAM_CHK(); + + std::istream is(f.get()); + + /* HUGE ASSUMPTION: *fmt is either "%d" or "%f" */ + if (strcmp(fmt, "%d") == 0) { + int d; + is >> d; + if (is.fail()) return EOF; + *(static_cast(val)) = d; + } else { + float f; + is >> f; + if (is.fail()) return EOF; + *(static_cast(val)) = f; + } + + return 1; +} + +const char* LibRaw_file_datastream::fname() +{ + return filename; +} + +/* You can't have a "subfile" and a "tempfile" at the same time. */ +int LibRaw_file_datastream::subfile_open(const char *fn) +{ + LR_STREAM_CHK(); + if (saved_f.get()) return EBUSY; + saved_f = f; + std::auto_ptr buf(new std::filebuf()); + + buf->open(fn, std::ios_base::in | std::ios_base::binary); + if (!buf->is_open()) { + f = saved_f; + return ENOENT; + } else { + f = buf; + } + + return 0; +} + + +void LibRaw_file_datastream::subfile_close() +{ + if (!saved_f.get()) return; + f = saved_f; +} + +#undef LR_STREAM_CHK + +void * LibRaw_file_datastream::make_jas_stream() +{ +#ifdef NO_JASPER + return NULL; +#else + return jas_stream_fopen(fname(),"rb"); +#endif +} + +// == LibRaw_buffer_datastream +LibRaw_buffer_datastream::LibRaw_buffer_datastream(void *buffer, size_t bsize) +{ + buf = (unsigned char*)buffer; streampos = 0; streamsize = bsize; +} + +LibRaw_buffer_datastream::~LibRaw_buffer_datastream(){} + +int LibRaw_buffer_datastream::read(void * ptr,size_t sz, size_t nmemb) +{ + if(substream) return substream->read(ptr,sz,nmemb); + size_t to_read = sz*nmemb; + if(to_read > streamsize - streampos) + to_read = streamsize-streampos; + if(to_read<1) + return 0; + memmove(ptr,buf+streampos,to_read); + streampos+=to_read; + return int((to_read+sz-1)/sz); +} + +int LibRaw_buffer_datastream::seek(INT64 o, int whence) +{ + if(substream) return substream->seek(o,whence); + switch(whence) + { + case SEEK_SET: + if(o<0) + streampos = 0; + else if (size_t(o) > streamsize) + streampos = streamsize; + else + streampos = size_t(o); + return 0; + case SEEK_CUR: + if(o<0) + { + if(size_t(-o) >= streampos) + streampos = 0; + else + streampos += (size_t)o; + } + else if (o>0) + { + if(o+streampos> streamsize) + streampos = streamsize; + else + streampos += (size_t)o; + } + return 0; + case SEEK_END: + if(o>0) + streampos = streamsize; + else if ( size_t(-o) > streamsize) + streampos = 0; + else + streampos = streamsize+(size_t)o; + return 0; + default: + return 0; + } +} + +INT64 LibRaw_buffer_datastream::tell() +{ + if(substream) return substream->tell(); + return INT64(streampos); +} + +char* LibRaw_buffer_datastream::gets(char *s, int sz) +{ + if (substream) return substream->gets(s,sz); + unsigned char *psrc,*pdest,*str; + str = (unsigned char *)s; + psrc = buf+streampos; + pdest = str; + while ( (size_t(psrc - buf) < streamsize) + && + ((pdest-str)scanf_one(fmt,val); + int scanf_res; + if(streampos>streamsize) return 0; +#ifndef WIN32SECURECALLS + scanf_res = sscanf((char*)(buf+streampos),fmt,val); +#else + scanf_res = sscanf_s((char*)(buf+streampos),fmt,val); +#endif + if(scanf_res>0) + { + int xcnt=0; + while(streampos24) + break; + } + } + return scanf_res; +} + +LibRaw_byte_buffer *LibRaw_buffer_datastream::make_byte_buffer(unsigned int sz) +{ + LibRaw_byte_buffer *ret = new LibRaw_byte_buffer(0); + if(streampos + sz > streamsize) + sz = streamsize - streampos; + ret->set_buffer(buf+streampos,sz); + return ret; +} + +int LibRaw_buffer_datastream::eof() +{ + if(substream) return substream->eof(); + return streampos >= streamsize; +} + int LibRaw_buffer_datastream::valid() +{ + return buf?1:0; +} + + +void * LibRaw_buffer_datastream::make_jas_stream() +{ +#ifdef NO_JASPER + return NULL; +#else + return jas_stream_memopen((char*)buf,streamsize); +#endif +} + +// == LibRaw_bigfile_datastream +LibRaw_bigfile_datastream::LibRaw_bigfile_datastream(const char *fname) +{ + if(fname) + { + filename = fname; +#ifndef WIN32SECURECALLS + f = fopen(fname,"rb"); +#else + if(fopen_s(&f,fname,"rb")) + f = 0; +#endif + } + else + {filename=0;f=0;} + sav=0; +} + +LibRaw_bigfile_datastream::~LibRaw_bigfile_datastream() {if(f)fclose(f); if(sav)fclose(sav);} +int LibRaw_bigfile_datastream::valid() { return f?1:0;} + +#define LR_BF_CHK() do {if(!f) throw LIBRAW_EXCEPTION_IO_EOF;}while(0) + +int LibRaw_bigfile_datastream::read(void * ptr,size_t size, size_t nmemb) +{ + LR_BF_CHK(); + return substream?substream->read(ptr,size,nmemb):int(fread(ptr,size,nmemb,f)); +} + +int LibRaw_bigfile_datastream::eof() +{ + LR_BF_CHK(); + return substream?substream->eof():feof(f); +} + +int LibRaw_bigfile_datastream:: seek(INT64 o, int whence) +{ + LR_BF_CHK(); +#if defined (WIN32) +#ifdef WIN32SECURECALLS + return substream?substream->seek(o,whence):_fseeki64(f,o,whence); +#else + return substream?substream->seek(o,whence):fseek(f,(long)o,whence); +#endif +#else + return substream?substream->seek(o,whence):fseeko(f,o,whence); +#endif +} + +INT64 LibRaw_bigfile_datastream::tell() +{ + LR_BF_CHK(); +#if defined (WIN32) +#ifdef WIN32SECURECALLS + return substream?substream->tell():_ftelli64(f); +#else + return substream?substream->tell():ftell(f); +#endif +#else + return substream?substream->tell():ftello(f); +#endif +} + +char* LibRaw_bigfile_datastream::gets(char *str, int sz) +{ + LR_BF_CHK(); + return substream?substream->gets(str,sz):fgets(str,sz,f); +} + +int LibRaw_bigfile_datastream::scanf_one(const char *fmt, void*val) +{ + LR_BF_CHK(); + return substream?substream->scanf_one(fmt,val): +#ifndef WIN32SECURECALLS + fscanf(f,fmt,val) +#else + fscanf_s(f,fmt,val) +#endif + ; +} + +const char *LibRaw_bigfile_datastream::fname() +{ + return filename; +} + +int LibRaw_bigfile_datastream::subfile_open(const char *fn) +{ + if(sav) return EBUSY; + sav = f; +#ifndef WIN32SECURECALLS + f = fopen(fn,"rb"); +#else + fopen_s(&f,fn,"rb"); +#endif + if(!f) + { + f = sav; + sav = NULL; + return ENOENT; + } + else + return 0; +} + +void LibRaw_bigfile_datastream::subfile_close() +{ + if(!sav) return; + fclose(f); + f = sav; + sav = 0; +} + + +void *LibRaw_bigfile_datastream::make_jas_stream() +{ +#ifdef NO_JASPER + return NULL; +#else + return jas_stream_freopen(fname(),"rb",f); +#endif +} + +// == LibRaw_windows_datastream +#ifdef WIN32 + +LibRaw_windows_datastream::LibRaw_windows_datastream(const TCHAR* sFile) + : LibRaw_buffer_datastream(NULL, 0) + , hMap_(0) + , pView_(NULL) +{ + HANDLE hFile = CreateFile(sFile, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + if (hFile == INVALID_HANDLE_VALUE) + throw std::runtime_error("failed to open the file"); + + try { Open(hFile); } catch(...) { CloseHandle(hFile); throw; } + + CloseHandle(hFile); // windows will defer the actual closing of this handle until the hMap_ is closed + reconstruct_base(); +} + + // ctor: construct with a file handle - caller is responsible for closing the file handle +LibRaw_windows_datastream::LibRaw_windows_datastream(HANDLE hFile) + : LibRaw_buffer_datastream(NULL, 0) + , hMap_(0) + , pView_(NULL) +{ + Open(hFile); + reconstruct_base(); +} + +// dtor: unmap and close the mapping handle +LibRaw_windows_datastream::~LibRaw_windows_datastream() +{ + if (pView_ != NULL) + ::UnmapViewOfFile(pView_); + + if (hMap_ != 0) + ::CloseHandle(hMap_); +} + +void LibRaw_windows_datastream::Open(HANDLE hFile) +{ + // create a file mapping handle on the file handle + hMap_ = ::CreateFileMapping(hFile, 0, PAGE_READONLY, 0, 0, 0); + if (hMap_ == NULL) throw std::runtime_error("failed to create file mapping"); + + // now map the whole file base view + if (!::GetFileSizeEx(hFile, (PLARGE_INTEGER)&cbView_)) + throw std::runtime_error("failed to get the file size"); + + pView_ = ::MapViewOfFile(hMap_, FILE_MAP_READ, 0, 0, (size_t)cbView_); + if (pView_ == NULL) + throw std::runtime_error("failed to map the file"); +} + + +#endif + + + diff --git a/Source/LibTIFF/ChangeLog b/Source/LibTIFF/ChangeLog index f3dfe26..f7c2631 100644 --- a/Source/LibTIFF/ChangeLog +++ b/Source/LibTIFF/ChangeLog @@ -1,4849 +1,4849 @@ -2011-04-09 Bob Friesenhahn - - * libtiff 3.9.5 released. - -2011-04-09 Bob Friesenhahn - - * configure.ac: Should use AC_CANONICAL_HOST since host specifies - the run-time target whereas target is used to specify the final - output target if the package is a build tool (like a compiler), - which libtiff is not. Resolves libtiff bug 2307 "Use - AC_CANONICAL_HOST macro". - -2011-04-02 Bob Friesenhahn - - * tools/fax2ps.c (main): Use tmpfile() rather than mkstemp() since - it is much more portable. Tmpfile is included in ISO/IEC - 9899:1990 and the WIN32 CRT. - -2011-03-21 Frank Warmerdam - - * libtiff/tiffiop.h: avoid declaring int64/uint64 on AIX with XLC - where they are already available. (#2301) - - * libtiff/tif_thunder.c: Correct potential buffer overflow with - thunder encoded files with wrong bitspersample set. The libtiff - development team would like to thank Marin Barbella and TippingPoint's - Zero Day Initiative for reporting this vulnerability (ZDI-CAN-1004, - CVE-2011-1167). - http://bugzilla.maptools.org/show_bug.cgi?id=2300 - -2011-03-10 Frank Warmerdam - - * libtiff/tif_fax3.h: Fix to last change allowing zero length - runs at the start of a scanline - needed for legal cases. - -2011-03-02 Frank Warmerdam - - * libtiff/tif_fax3.h: Protect against a fax VL(n) codeword commanding - a move left. Without this, a malicious input file can generate an - indefinitely large series of runs without a0 ever reaching the right - margin, thus overrunning our buffer of run lengths. Per CVE-2011-0192. - This is a modified version of a patch proposed by Drew Yao of Apple - Product Security. It adds an unexpected() report, and disallows the - equality case, since emitting a run without increasing a0 still allows - buffer overrun. - -2011-02-25 Andrey Kiselev - - * libtiff/tif_dirwrite.c: Avoid undefined behaviour when casting from - float to unsigned integer in TIFFWriteRationalArray() as reported by - Kareem Shehata. - -2011-01-03 Lee Howard - - * libtiff/tif_jpeg.c: Fix regressions with 2 and 3 band images - caused by commit on 2010-12-14. Submitted by e-mail from - Even Rouault - -2010-12-31 Olivier Paquet - - * libtiff/tif_dirread.c: Allow reading directories where - TIFFTAG_SMINSAMPLEVALUE and TIFFTAG_SMAXSAMPLEVALUE values differ for each - channel. The min/max of all channels is used as appropriate. - -2010-12-14 Lee Howard - - * libtiff/tif_dirread.c: tolerate some cases where - FIELD_COLORMAP is missing - http://bugzilla.maptools.org/show_bug.cgi?id=2189 - -2010-12-14 Lee Howard - - * libtiff/tif_strip.c: use TIFFGetFieldDefaulted instead - of TIFFGetField when we assume that it will succeed - http://bugzilla.maptools.org/show_bug.cgi?id=2215 - -2010-12-14 Lee Howard - - * tools/gif2tiff.c: fix buffer overrun - http://bugzilla.maptools.org/show_bug.cgi?id=2270 - -2010-12-14 Lee Howard - - * libtiff/tif_jpeg.c: reduce usage of JCS_UNKNOWN in order - to improve compatibility with various viewers - submitted by e-mail from Dwight Kelly - -2010-12-13 Lee Howard - - * tools/fax2ps.c: be consistent with page-numbering - http://bugzilla.maptools.org/show_bug.cgi?id=2225 - -2010-12-13 Lee Howard - - * libtiff/tif_dirread.c: fix needless tag ordering warning - http://bugzilla.maptools.org/show_bug.cgi?id=2210 - -2010-12-13 Lee Howard - - * libtiff/tif_color.c: prevent crash in handling bad TIFFs - resolves CVE-2010-2595 - http://bugzilla.maptools.org/show_bug.cgi?id=2208 - -2010-12-13 Lee Howard - - * tools/tiffcrop.c: new release by Richard Nolde - http://bugzilla.maptools.org/show_bug.cgi?id=2004 - -2010-12-12 Lee Howard - - * tools/tiff2pdf.c: fix colors for images with RGBA - interleaved data - http://bugzilla.maptools.org/show_bug.cgi?id=2250 - -2010-12-11 Lee Howard - - * tools/tiff2pdf.c: remove invalid duplication for Lab - http://bugzilla.maptools.org/show_bug.cgi?id=2162 - -2010-12-11 Lee Howard - - * libtiff/tif_jpeg.c: fix use of clumplines calculation - http://bugzilla.maptools.org/show_bug.cgi?id=2149 - -2010-12-11 Lee Howard - - * tools/fax2ps.c: replace unsafe tmpfile() with mkstemp() - http://bugzilla.maptools.org/show_bug.cgi?id=2118 - -2010-12-11 Lee Howard - - * tools/tiff2pdf.c: add fill-page option - http://bugzilla.maptools.org/show_bug.cgi?id=2051 - -2010-12-11 Lee Howard - - * libtiff/tif_dirread.c: modify warnings - http://bugzilla.maptools.org/show_bug.cgi?id=2016 - -2010-12-11 Lee Howard - - * libtiff/tif_ojpeg.c: fix buffer overflow on problem data - http://bugzilla.maptools.org/show_bug.cgi?id=1999 - -2010-12-11 Lee Howard - - * libtiff/tif_ojpeg.c: fix crash when reading a TIFF with a zero - or missing byte-count tag - * tools/tiffsplit.c: abort when reading a TIFF without a byte-count - per http://bugzilla.maptools.org/show_bug.cgi?id=1996 - -2010-12-08 Lee Howard - - * libtiff/tif_dirread.c: fix crash when reading a badly-constructed - TIFF per http://bugzilla.maptools.org/show_bug.cgi?id=1994 - -2010-12-07 Lee Howard - - * libtiff/tif_jpeg.c, libtiff/tif_strip.c: apply patch for - CVE-2010-3087 per bug - http://bugzilla.maptools.org/show_bug.cgi?id=2140 - -2010-12-06 Lee Howard - - * libtiff/tif_open.c: Fix mode check before opening a file. - http://bugzilla.maptools.org/show_bug.cgi?id=1906 - -2010-09-25 Lee Howard - - * tools/tiff2ps.c: improvements and enhancements from Richard Nolde - with additional command line options for Document Title, - Document Creator, and Page Orientation - -2010-07-13 Bob Friesenhahn - - * tools/tiffcrop.c: Patch from Richard Nolde to avoid a - potentially unterminated buffer due to using an exceptionally long - file name. - -2010-07-08 Andrey Kiselev - - * tools/tiff2pdf.c: Fixed ID buffer filling in - t2p_write_pdf_trailer(), thanks to Dmitry V. Levin. - -2010-07-07 Andrey Kiselev - - * libtiff/tif_dirread.c: Really reset the tag count in CheckDirCount() - to expected value as the warning message suggests. As per bug - http://bugzilla.maptools.org/show_bug.cgi?id=1963 - - * tools/tiffdump.c: Avoid integer overflows computing the buffer size - for large directories. As per bug - http://bugzilla.maptools.org/show_bug.cgi?id=2218 - -2010-07-06 Andrey Kiselev - - * tools/tiffset.c: Properly handle TIFFTAG_PAGENUMBER, - TIFFTAG_HALFTONEHINTS, TIFFTAG_YCBCRSUBSAMPLING, TIFFTAG_DOTRANGE - which should be set by value. - - * libtiff/tif_dirinfo.c: Don't use assertions in _TIFFFieldWithTag() - and _TIFFFieldWithName() if the tag is not found in the tag table. - This should be normal situation and returned NULL value should be - properly handled by the caller. - - * libtiff/{tif_dirwrite.c, tif_print.c}: Properly handle "DotRange" - tag as it can be either byte or short size and should be set and read - by value, not as an array. As per bug - http://bugzilla.maptools.org/show_bug.cgi?id=2116 - -2010-07-02 Andrey Kiselev - - * libtiff/tif_getimage.c: Avoid wrong math du to the signed/unsigned - integer type conversions. As per bug - http://bugzilla.maptools.org/show_bug.cgi?id=2207 - - * tools/{tiff2bw.c, thumbnail.c, pal2rgb.c}: Fix the count for - WhitePoint tag as per bug - http://bugzilla.maptools.org/show_bug.cgi?id=2042 - - * tools/tiffdump.c: Use PrintData() function instead of - PrintByte/Short/Long(). Should fix an issue reported at - http://bugzilla.maptools.org/show_bug.cgi?id=2116 - - * libtiff/tif_getimage.c: Check the number of samples per pixel when - working with YCbCr image in PickContigCase(). As per bug - http://bugzilla.maptools.org/show_bug.cgi?id=2216 - - * libtiff/tif_dir.c: Set the bogus post-decoding hook when processing - TIFFTAG_BITSPERSAMPLE in _TIFFVSetField() for the case of 8 bit when - we don't need any post-processing. That helps to reset the hook if we - previously set this field to some other value and the hook was - initialized accordingly. As per bug - http://bugzilla.maptools.org/show_bug.cgi?id=2035 - -2010-06-30 Andrey Kiselev - - * tools/tiff2pdf.c: Better generation of ID field in - t2p_write_pdf_trailer(). Get rid of GCC aliasing warnings. - - * tools/tiff2pdf.c: Fixed computation of the tile buffer size when - converting JPEG encoded tiles. - - * tools/tiff2pdf.c: Better handling of string fields, use static - string buffers instead of dynamically allocated, use strncpy() instead - of strcpy(), control the string lengths. - -2010-06-25 Andrey Kiselev - - * tools/tiffcp.c: Initialize buffer arrays with zero to avoid - referencing to uninitialized memory in some cases (e.g. when tile size - set bigger than the image size). - -2010-06-15 Bob Friesenhahn - - * tools/tiffcrop.c: Patch from Richard Nolde. Reject YCbCr - subsampled data since tiffcrop currently doesn't support it. Fix - JPEG support. - -2010-06-15 Bob Friesenhahn - - * libtiff 3.9.4 released. - -2010-06-13 Frank Warmerdam - - * libtiff/tif_jpeg.c: avoid re-preparing jpeg tables unnecessarily - (gdal #3633, libtiff #2135). - - * libtiff/tif_dirread.c: Fixed bad handling of out of order tags - definated late by a codec (#2210) - - * libtiff/tif_dirread.c: Fixed inadequate validation of the - SubjectDistance field (#2212). - - * tiff2pdf.c: Fix assorted bugs in tiff2pdf: missing "return" - in t2p_read_tiff_size() causes t2p->tiff_datasize to be set entirely - wrong for COMPRESSION_JPEG case, resulting in memory stomp if actual - size is larger. Also, there are a bunch of places that try to - memset() a malloc'd buffer before checking for malloc failure, which - would result in core dump if there actually were a failure. (#2211) - -2010-06-11 Bob Friesenhahn - - * tools/tiff2rgba.c: Applied portion of patch (from Tom Lane) - which was left out in order to fully resolve "CVE-2009-2347 - libtiff: integer overflows in various inter-color space conversion - tools". http://bugzilla.maptools.org/show_bug.cgi?id=2079 - - * libtiff/tiffiop.h (TIFFSafeMultiply): Need more castings to - avoid compiler warnings if parameter types are not sign - consistent. - - * tools/tiffcrop.c: Applied patch from Richard Nolde: Corrected - European page size dimensions. Added an option to allow the user - to specify a custom page size on the command line. Fix the case - where a page size specified with a fractional part was being - coerced to an integer by retyping the variables that define the - paper size. - - * libtiff 3.9.3 released. - - * tools/tiffcp.c (tiffcp): Applied Tom Lane's patch to reject - YCbCr subsampled data since tiffcp currently doesn't support it. - http://bugzilla.maptools.org/show_bug.cgi?id=2097 - - * Update libtool to version 2.2.10. - -2010-06-10 Bob Friesenhahn - - * libtiff/tiffiop.h (TIFFSafeMultiply): Work properly if - multiplier is zero. - -2010-06-09 Bob Friesenhahn - - * libtiff/tif_dir.h: Restore ReferenceBlackWhite as a non-custom - field. This avoids a multi-thread reentrancy problem as well as - fixing output of wrong tag value due to redundant definitions for - the same tag in the tiffFieldInfo[] array. Resolves - http://bugzilla.maptools.org/show_bug.cgi?id=2185 - - * libtiff/tif_fax3.c (Fax3SetupState): Yesterday's fix for - CVE-2010-1411 was not complete. - - * libtiff/tiffiop.h (TIFFSafeMultiply): New macro to safely - multiply two integers. Returns zero if there is an integer - overflow. - - * tools/tiffcp.c (main): Fix more TIFF handle leaks. - - * libtiff/tif_read.c (TIFFReadBufferSetup): Skip allocating - tif_rawdata if tif_rawdatasize becomes zero. - -2010-06-08 Bob Friesenhahn - - * tools/tiffcrop.c: Removed duplicated macros such as - TIFFhowmany(). - - * Update libtool to version 2.2.8. - - * libtiff/tif_fax3.c (Fax3SetupState): Avoid under-allocation of - buffer due to integer overflow in TIFFroundup() and several other - potential overflows. In conjunction with the fix to TIFFhowmany(), - fixes CVE-2010-1411. - - * libtiff/tiffiop.h (TIFFhowmany): Return zero if parameters would - result in an integer overflow. This causes TIFFroundup() to also - return zero if there would be an integer overflow. - - * libtiff/tif_read.c (TIFFReadBufferSetup): Return an error if - tif_rawdatasize becomes zero due to an initial raw size of zero or - an overflow reported by TIFFroundup(). - - * libtiff/tif_ojpeg.c (OJPEGReadBufferFill): Report an error and - avoid a crash if the input file is so broken that the strip - offsets are not defined. - - * tools/tiffcp.c (main): tiffcp should not leak memory if an error - is reported when reading the input file. - - * libtiff/tif_aux.c (_TIFFCheckRealloc): Produce a fully detailed - error message string. - - * Add an emacs formatting mode footer to all source files so that - emacs can be effectively used. - -2010-06-03 Oliver Chen Feng - - * libtiff/tools/tiffcp.c: add a new option -x to force merged tiff - file PAGENUMBER value in sequence for users who care the page - sequence, this will also prevent tiff2pdf from creating pdf file from - the merged tiff file with wrong page sequence. - -2010-05-07 Frank Warmerdam - - * libtiff/tif_jpeg.c: Ensure that quality is always set in - JPEGPreEncode(), not just when we want to output local tables. - Otherwise the quality used during compression may not be right and - might not match the tables in the tables tag. This bug only occurs - when seeking between directories in the midst of writing blocks. - http://trac.osgeo.org/gdal/ticket/3539 - -2010-05-05 Olivier Paquet - - * libtiff/tif_print.c: Have TIFFTAG_REFERENCEBLACKWHITE always print 6 - floats instead of 2*SamplesPerPixel. - http://bugzilla.maptools.org/show_bug.cgi?id=2186 - * man/TIFFGetField.3tiff, man/TIFFSetField.3tiff: Fixed doc to reflect the - fact that libtiff considers TIFFTAG_REFERENCEBLACKWHITE to be 6 floats. - -2010-04-10 Bob Friesenhahn - - * tools/ppm2tiff.c (main): While case for parsing comment line - requires extra parenthesis to work as expected. Reported by - Thomas Sinclair. - -2010-02-22 Lee Howard - - * libtiff/tif_jpeg.c: Do not generate a JPEGTables tag when creating - the JPEG TIFF as is is not required in order to prevent it from - being unused and filled with invalid data. (Leave it to be - generated by later activity.) - http://bugzilla.maptools.org/show_bug.cgi?id=2135 - * tools/tiff2pdf.c: Write the JPEG SOI headers into the TIFF strip - data rather than skipping them. This fixes the ability to view in - Acrobat Reader, Evince, and Ghostscript. - http://bugzilla.maptools.org/show_bug.cgi?id=2135 - * libtiff/tif_fax3.c: Don't return error on badly-terminated MMR - strips. - http://bugzilla.maptools.org/show_bug.cgi?id=2029 - -2010-01-06 Frank Warmerdam - - * libtiff/tif_dir.c: Ensure tile and scanline sizes are reset - when moving to new directories. - http://bugzilla.maptools.org/show_bug.cgi?id=1936 - -2009-12-03 Frank Warmerdam - - * libtiff/tif_jpeg.c: Fix a couple of issues that trigger failures in - some cases when using TIFFReadScanline() with JPEG compressed - subsampled ycbcr images. - http://bugzilla.maptools.org/show_bug.cgi?id=1936 - -2009-11-04 Bob Friesenhahn - - * libtiff 3.9.2 released. - -2009-11-03 Bob Friesenhahn - - * tools/tiffcrop.c: Updated tiffcrop from Richard Nolde. This - version has undergone substantial testing with arbitrary sample - bit depths. Also eliminates GCC compilation warnings. - -2009-11-02 Bob Friesenhahn - - * port/libport.h: Added header file for porting prototypes and - extern declarations. - -2009-10-31 Bob Friesenhahn - - * libtiff/tif_dirwrite.c (TIFFWriteAnyArray): Add missing break - statement so writing an array of TIFF_DOUBLE works. - -2009-10-29 Bob Friesenhahn - - * libtiff/tif_dirread.c: Eliminate GCC "dereferencing type-punned - pointer" warnings. - -2009-10-28 Bob Friesenhahn - - * html/tools.html: Add manual page links, and a summary - description of tiffcrop. - -2009-10-07 Bob Friesenhahn - - * configure.ac: x86_64 should use the same fill order as i386. - -2009-09-24 Bob Friesenhahn - - * tools/tiffcrop.c, man/tiffcrop.1: New tiffcrop from Richard - Nolde. Major updates to add significant functionality for reading - and writing tile based images with bit depths not a multiple of 8 - which cannot be handled by tiffcp. - -2009-09-03 Bob Friesenhahn - - * libtiff/tif_ojpeg.c (OJPEGWriteHeaderInfo): IJG JPEG 7 needs - do_fancy_upsampling=FALSE in order to read raw data. Resolves - "Bug 2090 - OJPEG crash with libjpeg v7". - http://bugzilla.maptools.org/show_bug.cgi?id=2090 - -2009-08-30 Bob Friesenhahn - - * contrib/iptcutil/iptcutil.c, - libtiff/tif_getimage.c,libtiff/tif_jpeg.c,libtiff/tif_ojpeg.c,tools/tiffcrop.c,tools/tiffgt.c: - Applied patch from Oden Eriksson to allow building with GCC using - the "-Wformat -Werror=format-security" flags. - -2009-08-28 Bob Friesenhahn - - * libtiff 3.9.1 released. - -2009-08-28 Frank Warmerdam - - * libtiff/tif_dirwrite.c: Back out changes from 2007-11-22 that - resulted in the final strip not being written in some circumstances. - http://bugzilla.maptools.org/show_bug.cgi?id=2088 - -2009-08-27 Bob Friesenhahn - - * libtiff/tif_write.c (TIFFAppendToStrip): Remove cast which - caused libtiff to output a wrong last strip with byte-count and - strip-offset of zero. This cast was added on the day of the 3.9.0 - release. - - * libtiff/tif_config.vc.h: tiffiop.h needs the TIFF_INT64_T and - TIFF_UINT64_T defines in order to compile. Copy existing - definitions from tiffconf.vc.h. - -2009-08-21 Bob Friesenhahn - - * test/Makefile.am (AUTOMAKE_OPTIONS): Colorized tests was not - actually activated since it needed to be enabled in this - Makefile.am. Also activated parallel-tests mode since it offers - useful features such as per-test .log files and a summary test - report .log file. - -2009-08-20 Bob Friesenhahn - - * libtiff 3.9.0 released. - - * libtiff/tif_print.c (TIFFPrintDirectory): Applied patch for "tag - error may cause segfault in tif_print.c." - http://bugzilla.maptools.org/show_bug.cgi?id=1896 - - * tools/{rgb2ycbcr.c, tiff2rgba.c}: Applied patch for - CVE-2009-2347 libtiff: integer overflows in various inter-color - space conversion tools. - http://bugzilla.maptools.org/show_bug.cgi?id=2079 - - * configure.ac: Updated autotools. Autoconf 2.64, Automake 1.11, - libtool 2.2.6. Enabled support for silent build rules - (--enable-silent-rules or 'make V=0') and colorized tests. - -2009-06-30 Frank Warmerdam - - * libtiff/tif_luv.c: correct return codes from encoderow to be - 1 on success instead of zero. - http://bugzilla.maptools.org/show_bug.cgi?id=2069 - -2009-06-22 Frank Warmerdam - - * libtiff/tif_lzw.c: Fix buffer underflow bug. - http://bugzilla.maptools.org/show_bug.cgi?id=2065 - -2009-06-03 Frank Warmerdam - - * libtiff/tif_write.c: do not override the planar configuration to be - contig for one sample files if planar configuration is already set. - http://bugzilla.maptools.org/show_bug.cgi?id=2057 - -2009-02-12 Frank Warmerdam - - * libtiff/tif_luv.c: Fix handling of tiled logluv images. - http://bugzilla.maptools.org/show_bug.cgi?id=2005 - -2009-01-23 Frank Warmerdam - - * libtiff/tif_predict.c: Add support for 32bit integer horz. predictors. - http://bugzilla.maptools.org/show_bug.cgi?id=1911 - -2009-01-20 Frank Warmerdam - - * tools/tiffsplit.c: fix sampleformat to be shortv instead of longv. - -2009-01-12 Bob Friesenhahn - - * tools/tiff2ps.c: Remove spurious message printed to stderr. - -2009-01-11 Bob Friesenhahn - - * tools/tiff2ps.c: Incorporated significant functionality update - from Richard Nolde. In particular, support for rotating the image - by 90, 180, 270, and 'auto' has been added. - - * tools/tiffcrop.c: Incorporated significant functionality update - from Richard Nolde. - -2009-01-06 Bob Friesenhahn - - * libtiff/tiffiop.h: Add private type declarations for int64, and - uint64 so that bundled utilities (like tiffcrop) can use it when - necessary. - -2009-01-01 Bob Friesenhahn - - * configure.ac: Updated to test for 64-bit types. This version of - the library does not require a 64-bit type, but tiffcrop needs it. - -2008-12-31 Bob Friesenhahn - - * Update to use current FSF autotools versions. - * libtiff/tiffio.h: GCC will now validate format specifications - for TIFFError(), TIFFErrorExt(), TIFFWarning(), and - TIFFWarningExt() in order to reveal bugs. Cleaned up resulting - warnings throughout for 32 bit build only. - -2008-12-31 Frank Warmerdam - - * tools/tiffcrop.c, man/tiffcrop.1: A major update from Richard - Nolde. - -2008-12-21 Frank Warmerdam - - * libtiff/tif_jpeg.c: Avoid errors if the application writes a full - strip for the last partial strip in a jpeg compressed file. - http://bugzilla.maptools.org/show_bug.cgi?id=1981 - -2008-12-21 Frank Warmerdam - - * libtiff/tif_getimage.c, tiffio.h: More ABI corrections. - Removed SubsamplingHor/Ver from TIFFRGBAImage structure. - http://bugzilla.maptools.org/show_bug.cgi?id=1980 - -2008-12-18 Frank Warmerdam - - * libtiff/tif_getimage.c,tiffio.h: removed all use of UaToAa and - Bitmap16to8 arrays in TIFFRGBAImage structure to restore ABI - compatability. These were just an attempt to speed up processing - with precalculated tables. - http://bugzilla.maptools.org/show_bug.cgi?id=1979 - - * libtiff/tif_codec.c: Avoid printing c->name if it does not exist. - -2008-10-21 Andrey Kiselev - - * libtiff/tif_jbig.c: Support the JBIG-KIT 2.0 (compatibility with - the older versions retained). - -2008-09-05 Andrey Kiselev - - * tools/tiffsplit.c: Use dynamically allocated array instead of static - when constructing output file names. - -2008-09-03 Andrey Kiselev - - * tools/tiffsplit.c: Get rid of unsafe strcpy()/strcat() calls when - doing the filename/path construction. - - * tools/tiff2pdf.c: More appropriate format string in - t2p_write_pdf_string(); avoid signed/unsigned mismatch. - - * libtiff/tif_lzw.c: Properly zero out the codetable. As per bug - - http://bugzilla.maptools.org/show_bug.cgi?id=1929 - - * libtiff/tif_lzw.c: Properly zero out the string table. Fixes - CVE-2008-2327 security issue. - -2008-05-24 Frank Warmerdam - - * tif_codec.c: Avoid NULL pointer dereferencing for exotic - compression codec codes. - - * tif_dirread.c: zero tif->tif_dir after freeing the directory - in TIFFReadCustomDirectory(). I don't exactly remember why this - was important. - - * tif_dirwrite.c: Fix potential memory leak writing large double - tags. - - * tif_dirread.c: Fix unchecked malloc result. - -2008-01-30 Andrey Kiselev - - * tif_fax3.c: Make find0span() and find1span() non-inline to - make MSVC 6.0 compiler happy. - -2007-11-26 Frank Warmerdam - - * tif_fax3.c: fix leak of FAXCS state (per bug 1603). - -2007-11-23 Andrey Kiselev - - * configure.com, libtiff/tif_vms.c: Better OpenVMS support. Patches - from Alexey Chupahin. - -2007-11-22 Frank Warmerdam - - * tif_write.c: Rip out the fancy logic in TIFFAppendToStrip() for - establishing if an existing tile can be rewritten to the same location - by comparing the current size to all the other blocks in the same - directory. This is dangerous in many situations and can easily - corrupt a file. (observed in esoteric GDAL situation that's hard to - document). This change involves leaving the stripbytecount[] values - unaltered till TIFFAppendToStrip(). Now we only write a block back - to the same location it used to be at if the new data is the same - size or smaller - otherwise we move it to the end of file. - - * tif_dirwrite.c: Try to avoid writing out a full readbuffer of tile - data when writing the directory just because we have BEENWRITING at - some point in the past. This was causing odd junk to be written out - in a tile of data when a single tile had an interleaving of reading - and writing with reading last. (highlighted by gdal - autotest/gcore/tif_write.py test 7. - - * tif_predict.c: use working buffer in PredictorEncodeTile to avoid - modifying callers buffer. - http://trac.osgeo.org/gdal/ticket/1965 - - * tif_predict.c/h, tif_lzw.c, tif_zip.c: Improvements so that - predictor based encoding and decoding works in read-write update - mode properly. - http://trac.osgeo.org/gdal/ticket/1948 - -2007-10-05 Frank Warmerdam - - * tools/tiff2pdf.c: Fixed setting of alpha value per report on list. - -2007-09-13 Frank Warmerdam - - * tif_dirinfo.c: _TIFFMergeFields() now only merges in field - definitions that are missing. Existing definitions are silently - ignored. (Bug #1585) - -2007-07-18 Andrey Kiselev - - * libtiff/{Makefile.am, Makefile.v}: Do not distribute tiffconf.h, - remove tif_config.h/tiffconf.h during cleaning. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1573 - -2007-07-13 Andrey Kiselev - - * libtiff 3.9.0beta released. - -2007-07-12 Andrey Kiselev - - * tools/tiff2pdf.c: Added missed extern optind as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1567 - -2007-07-03 Andrey Kiselev - - * tools/tiff2ps.c: Added support 16-bit images as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1566 - - Patch from William Bader. - - * tools/tiff2pdf.c: Fix for TIFFTAG_JPEGTABLES tag fetching and - significant upgrade of the whole utility as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1560 - - Now we don't need tiffiop.h in tiff2pdf anymore and will open output - PDF file using TIFFClientOpen() machinery as it is implemented - by Leon Bottou. - -2007-06-29 Bob Friesenhahn - - * libtiff/tif_dirinfo.c (_TIFFFindFieldInfo): Don't attempt to - bsearch() on a NULL fieldinfo list. - (_TIFFFindFieldInfoByName): Don't attempt to - lfind() on a NULL fieldinfo list. - -2007-05-01 Andrey Kiselev - - * libtiff/tif_dirwrite.c: Fixed problem introduced with a fix for a - byte swapping issue - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1363 - - As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1550 - -2007-04-27 Andrey Kiselev - - * tools/tiff2pdf.c: Check the tmpfile() return status as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=154 - -2007-04-07 Andrey Kiselev - - * libtiff/{tif_dir.h, tif_dirread.c, tif_dirinfo.c, tif_jpeg.c, - tif_fax3.c, tif_jbig.c, tif_luv.c, tif_ojpeg.c, tif_pixarlog.c, - tif_predict.c, tif_zip.c}: Finally fix bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1274 - - by introducing _TIFFMergeFieldInfo() returning integer error status - instead of void in case of problems with field merging (e.g., if the - field with such a tag already registered). TIFFMergeFieldInfo() in - public API remains void. Use _TIFFMergeFieldInfo() everywhere and - check returned value. - -2007-04-07 Frank Warmerdam - - * contrib/addtiffo/tif_overview.c: Fix problems with odd sized output - blocks in TIFF_DownSample_Subsampled() (bug 1542). - -2007-04-06 Frank Warmerdam - - * libtiff/tif_jpeg.c: Changed JPEGInitializeLibJPEG() so that it - will convert from decompressor to compressor or compress to decompress - if required by the force arguments. This works around a problem in - where the JPEGFixupTestSubsampling() may cause a decompressor to - be setup on a directory when later a compressor is required with the - force flag set. Occurs with the addtiffo program for instance. - -2007-04-06 Andrey Kiselev - - * libtiff/tif_dirwrite.c: Fixed swapping of byte arrays stored - in-place in tag offsets as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1363 - - * tools/tiffcrop.c, man/tiffcrop.1: Significant update in - functionality from Richard Nolde. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1525 - -2007-03-28 Frank Warmerdam - - * libtiff/tif_fax3.c: "inline static" -> "static inline" for IRIC CC. - -2007-03-07 Joris Van Damme - - * libtiff/tif_getimage.c: workaround for 'Fractional scanline' error reading - OJPEG images with rowsperstrip that is not a multiple of vertical subsampling - factor. This bug is mentioned in: - http://bugzilla.remotesensing.org/show_bug.cgi?id=1390 - http://www.asmail.be/msg0054766825.html - -2007-03-07 Joris Van Damme - - * libtiff/tif_win32.c: made inclusion of windows.h unconditional - - * libtiff/tif_win32.c: replaced preprocessor indication for consiously - unused arguments by standard C indication for the same - -2007-02-27 Andrey Kiselev - - * libtiff/tif_dirread.c: Use uint32 type instead of tsize_t in byte - counters in TIFFFetchData(). Should finally fix the issue - - http://bugzilla.remotesensing.org/show_bug.cgi?id=890 - -2007-02-24 Andrey Kiselev - - * tools/tiffset.c: Properly handle tags with TIFF_VARIABLE writecount. - As per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1350 - - * libtiff/tif_dirread.c: Added special function to handle - SubjectDistance EXIF tag as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1362 - - * tools/tiff2pdf.c: Do not assume inches when the resolution units - do not specified. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1366 - - * tools/{tiffcp.c, tiffcrop.c}: Do not change RowsPerStrip value if - it was set as infinite. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1368 - - * tools/tiffcrop.c, man/tiffcrop.1: New tiffcrop utility contributed - by Richard Nolde. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1383 - -2007-02-22 Andrey Kiselev - - * libtiff/tif_dir.c: Workaround for incorrect TIFFs with - ExtraSamples == 999 produced by Corel Draw. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1490 - - * libtiff/{tif_dirread.c, tif_read.c}: Type of the byte counters - changed from tsize_t to uint32 to be able to work with data arrays - larger than 2GB. Fixes bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=890 - - Idea submitted by Matt Hancher. - -2007-01-31 Andrey Kiselev - - * tools/tif2rgba.c: This utility does not work properly on big-endian - architectures. It was fixed including the bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1149 - -2007-01-15 Mateusz Loskot - - * Submitted libtiff port for Windows CE platform - * libtiff/tif_config.wince.h: Added configuration header for WinCE. - * libtiff/tiffconf.wince.h: Ported old configuration header for WinCE. - * libtiff/tif_wince.c: Added WinCE-specific implementation of some - functons from tif_win32.c. - * libtiff/tif_win32.c: Disabled some functions already reimplemented in tif_wince.c. - * libtiff/tiffiop.h, port/lfind.c: Added conditional include of some - standard header files for Windows CE build. - * tools/tiffinfoce.c: Ported tiffinfo utility for Windows CE. - -2006-11-19 Frank Warmerdam - - * libtiff/tif_write.c: TIFFAppendToStrip() - clear sorted flag if - we move a strip. - http://bugzilla.remotesensing.org/show_bug.cgi?id=1359 - -2006-10-13 Andrey Kiselev - - * libtiff/tif_dir.c: More fixes for vulnerabilities, reported - in Gentoo bug (): - - http://bugs.gentoo.org/show_bug.cgi?id=142383 - - * libtiff/contrib/dbs/xtiff/xtiff.c: Make xtiff utility compilable. - Though it is still far from the state of being working and useful. - -2006-10-12 Andrey Kiselev - - * libtiff/tif_fax3.c: Save the state of printdir codec dependent - method. - - * libtiff/tif_jpeg.c: Save the state of printdir codec dependent method - as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1273 - - * libtiff/tif_win32.c: Fixed problem with offset value manipulation - as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1322 - - * libtiff/{tif_read.c, tif_jpeg.c, tif_dir.c}: More fixes for - vulnerabilities, reported in Gentoo bug (): - - http://bugs.gentoo.org/show_bug.cgi?id=142383 - -2006-09-28 Andrey Kiselev - - * libtiff/{tif_fax3.c, tif_next.c, tif_pixarlog.c}: Fixed multiple - vulnerabilities, as per Gentoo bug (): - - http://bugs.gentoo.org/show_bug.cgi?id=142383 - -2006-09-27 Frank Warmerdam - - * libtiff/tif_lzw.c, libtiff/tif_zip.c: Fixed problems with mixing - encoding and decoding on the same read-write TIFF handle. The LZW - code can now maintain encode and decode state at the same time. The - ZIP code will switch back and forth as needed. - http://bugzilla.remotesensing.org/show_bug.cgi?id=757 - -2006-09-20 Frank Warmerdam - - * libtiff: Rename config.h.vc and tif_config.h.vc to config.vc.h and - tif_config.vc.h for easier identification by folks using an IDE. - -2006-07-25 Frank Warmerdam - - * tif_msdos.c: Avoid handle leak for failed opens. c/o Thierry Pierron - -2006-07-19 Frank Warmerdam - - * tif_dirwrite.c: take care not to flush out buffer of strip/tile - data in _TIFFWriteDirectory if TIFF_BEENWRITING not set. Relates - to bug report by Peng Gao with black strip at bottom of images. - -2006-07-12 Frank Warmerdam - - * tif_dirwrite.c: make sure to use uint32 for wordcount in - TIFFWriteNormanTag if writecount is VARIABLE2 for ASCII fields. - It already seems to have been done for other field types. Needed - for "tiffset" on files with geotiff ascii text. - -2006-07-04 Bob Friesenhahn - - * {configure.ac, libtiff/tif_config.h.vc, libtiff/tif_jbig.c} - (JBIGDecode): jbg_newlen is not available in older JBIG-KIT and - its use does not appear to be required, so use it only when it is - available. - -2006-06-24 Andrey Kiselev - - * libtiff/tif_dirinfo.c: Added missed EXIF tag ColorSpace (40961). - - * libtiff/tif_dirread.c: Move IFD fetching code in the separate - function TIFFFetchDirectory() avoiding code duplication in - TIFFReadDirectory() and TIFFReadCustomDirectory(). - -2006-06-19 Frank Warmerdam - - * tools/tiff2pdf.c: Fix handling of -q values. - http://bugzilla.remotesensing.org/show_bug.cgi?id=587 - -2006-06-17 Frank Warmerdam - - * tif_readdir.c: Added case in EstimateStripByteCounts() for tiled - files. Modified TIFFReadDirectory() to not invoke - EstimateStripByteCounts() for case where entry 0 and 1 are unequal - but one of them is zero. - http://bugzilla.remotesensing.org/show_bug.cgi?id=1204 - -2006-06-08 Andrey Kiselev - - * libtiff/{tif_open.c, tif_dirread.c, tiffiop.h}: Move IFD looping - checking code in the separate function TIFFCheckDirOffset(). - - * libtiff/tif_aux.c: Added _TIFFCheckRealloc() function. - - * tools/tiffcmp.c: Fixed floating point comparison logic as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1191 - - * libtiff/tif_fax3.c: Fixed problems in fax decoder as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1194 - - * tools/tiff2pdf.c: Fixed buffer overflow condition in - t2p_write_pdf_string() as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1196 - -2006-06-07 Andrey Kiselev - - * {configure, configure.ac, libtiff/tif_jbig.c, tools/tiffcp.c}: Added - support for JBIG compression scheme (34661 code) contributed by Lee - Howard. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=896 - - * configure, configure.ac: OJPEG support enabled by default. - - * contrib/ojpeg/: Removed. New OJPEG support does not need this patch. - -2006-06-03 Bob Friesenhahn - - * libtiff/{tif_dirinfo.c, tif_print.c} : Fix crash in - TIFFPrintDirectory(). Joris Van Damme authored the fix. - -2006-04-21 Andrey Kiselev - - * tools/tiff2pdf.c: Unified line ending characters (always use '\n') - as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1163 - - * README.vms, Makefile.am, configure.com, libtiff/{Makefile.am, - tif_config.h-vms, tif_stream.cxx, tif_vms.c, tiffconf.h-vms}: - Added support for OpenVMS by Alexey Chupahin, elvis_75@mail.ru. - -2006-04-20 Andrey Kiselev - - * tools/{fax2ps.c, fax2tiff.c, ppm2tiff.c, ras2tiff.c, tiff2pdf.c}: - Properly set the binary mode for stdin stream as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1141 - - * man/{bmp2tiff.1, fax2ps.1, fax2tiff.1, gif2tiff.1, ras2tiff.1, - raw2tiff.1, rgb2ycbcr.1, sgi2tiff.1, tiff2bw.1, tiff2pdf.1, tiff2ps.1, - tiff2rgba.1, tiffcmp.1, tiffcp.1, tiffdither.1, tiffdump.1, tiffgt.1, - tiffset.1}: Improvements in page formatting as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1140 - - * html/tools.html, html/man/Makefile.am, tools/tiff2pdf.c: Fixed - typos as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1139 - -2006-04-18 Frank Warmerdam - - * nmake.opt: use /EHsc for VS2005 compatibility. Also define - _CRT_SECURE_NO_DEPRECATE to avoid noise on VS2005. - -2006-04-12 Joris Van Damme - - * libtiff/tif_getimage.c: Added support for planarconfig separate - non-subsampled YCbCr (i.e. separate YCbCr with subsampling [1,1]) - -2006-04-11 Joris Van Damme - - * libtiff/tif_getimage.c: Revision of all RGB(A) put routines - - Conversion of unassociated alpha to associated alpha now done with - more performant LUT, and calculation more correct - - Conversion of 16bit data to 8bit data now done with - more performant LUT, and calculation more correct - - Bugfix of handling of 16bit RGB with unassociated alpha - -2006-04-11 Joris Van Damme - - * libtiff/tif_getimage.c: - - When there is no alpha, gtTileSeparate and gtStripSeparate allocated - buffer for alpha strile and filled it, only to never read it back. - Removed allocation and fill. - - Minor rename of vars in gtTileSeparate and gtStripSeparate - anticipating planned functionality extension - -2006-04-08 Joris Van Damme - - * libtiff/tif_getimage.c: renamed pickTileContigCase to PickContigCase - and pickTileSeparateCase to PickSeparateCase as both work on strips as - well - - * libtiff/tif_getimage.c: moved img->get selection from - TIFFRGBAImageBegin into PickContigCase and PickSeparateCase to create - logical hook for planned functionality extension - -2006-04-08 Joris Van Damme - - * libtiff/tif_ojpeg.c: resolved memory leak that was a consequence - of inappropriate use of jpeg_abort instead of jpeg_destroy - -2006-04-07 Joris Van Damme - - * libtiff/tif_getimage.c: replaced usage of TIFFScanlineSize in - gtStripContig with TIFFNewScanlineSize so as to fix buggy behaviour - on subsampled images - this ought to get sorted when we feel brave - enough to replace TIFFScanlineSize alltogether - - * libtiff/tif_ojpeg.c: fixed bug in OJPEGReadSkip - -2006-04-04 Joris Van Damme - - * libtiff/tiffio.h: added new type tstrile_t - - * libtiff/tif_dir.h: changed types of td_stripsperimage and td_nstrips - to new tstrile_t, types of td_stripoffset and td_stripbytecount to - toff_t* - - * libtiff/tif_ojpeg.c: totally new implementation - - * libtiff/tif_dirread.c: added several hacks to suit new support of - OJPEG - - * libtiff/tif_getimage.c: removed TIFFTAG_JPEGCOLORMODE handling - of OJPEG images in favor of tif_getimage.c native handling of - YCbCr and desubsampling - -2006-03-29 Frank Warmerdam - - * libtiff/tif_jpeg.c: JPEGVSetField() so that altering the photometric - interpretation causes the "upsampled" flag to be recomputed. Fixes - peculiar bug where photometric flag had to be set before jpegcolormode - flag. - -2006-03-25 Joris Van Damme - - * libtiff/tif_jpeg.c: strip size related bugfix in encode raw - - * libtiff/tif_strip.c: temporarilly added two new versions of - TIFFScanlineSize - - TIFFNewScanlineSize: proposed new version, after all related - issues and side-effects are sorted out - - TIFFOldScanlineSize: old version, from prior to 2006-03-21 change - This needs further sorting out. - -2006-03-25 Joris Van Damme - - * contrib/addtiffo/tif_ovrcache.c: bugfix to correctly pass size - of last truncated strip data to TIFFWriteEncodedStrip - -2006-03-25 Joris Van Damme - - * libtiff/{tif_jpeg.c, tif_strip.c}: bugfix of tif_jpeg decode raw - -2006-03-25 Joris Van Damme - - * libtiff/tif_getimage.c: bugfix/rewrite of putcontig8bitYCbCr22tile - - * libtiff/tif_getimage.c: added putcontig8bitYCbCr12tile - - * libtiff/tif_read.c: added support for new TIFF_NOREADRAW flag to - prepare the path for new tif_ojpeg.c - -2006-03-23 Andrey Kiselev - - * libtiff 3.8.2 released. - - * tools/Makefile.am: Use runtime paths linker flags when rpath - option enabled. - -2006-03-21 Andrey Kiselev - - * libtiff/libtiff.def: Added missed exports as per bug - http://bugzilla.remotesensing.org/attachment.cgi?id=337 - - * contrib/addtiffo/Makefile.vc, libtiff/Makefile.vc, port/Makefile.vc, - tools/Makefile.vc: Makefiles improvements as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1128 - - * nmake.opt libtiff/{tif_config.h.vc, tif_unix.c, tiffio.h}, - tools/{fax2ps.c, fax2tiff.c, tiff2pdf.c}: Fixed win32 I/O functions - usage as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1127 - - * libtiff/tif_strip.c: Take subsampling in account when calculating - TIFFScanlineSize(). - - * tools/tiffcp.c: Do not set RowsPerStrip bigger than image length. - -2006-03-17 Andrey Kiselev - - * tools/fax2tiff.c: Fixed wrong TIFFerror() invocations as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1125 - - * tools/fax2ps.c: Fixed reading the input stream from stdin as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1124 - -2006-03-16 Andrey Kiselev - - * libtiff/tiffiop.h: Added decalration for - _TIFFSetDefaultCompressionState(). - - * libtiff/{tif_jpeg.c, tif_fax3.c, tif_zip.c, tif_pixarlog.c, - tif_lzw.c, tif_luv.c}: Use _TIFFSetDefaultCompressionState() in all - codec cleanup methods. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1120 - -2006-03-15 Andrey Kiselev - - * libtiff/tif_jpeg.c: Do not cleanup codec state in TIFFInitJPEG(). As - per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1119 - - * tools/raw2tiff.c: Do not set RowsPerStrip larger than ImageLength. - As per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1110 - - * libtiff/tiffiop.h: dblparam_t typedef removed; GLOBALDATA macro - removed; move here the STRIP_SIZE_DEFAULT macro definition. - - * libtiff/{tif_dirread.c, tif_strip.c}: Removed STRIP_SIZE_DEFAULT - macro definition. - - * libtiff/tif_dir.c: Use double type instead of dblparam_t. - -2006-03-14 Andrey Kiselev - - * libtiff/tif_dirread.c: Do not check the PlanarConfig tag presence - in TIFFReadDirectory, because it is always set at the start of - function and we allow TIFFs without that tag set. - -2005-03-13 Andrey Kiselev - - * libtiff 3.8.1 released. - -2006-03-07 Andrey Kiselev - - * libtiff/tif_dirread.c: Fixed error reporting in TIFFFetchAnyArray() - function as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 - - * libtiff/tif_dirread.c: More wise check for integer overflow - condition as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 - - * libtiff/{tif_jpeg.c, tif_pixarlog.c, tif_fax3.c, tif_zip.c}: - Properly restore setfield/getfield methods in cleanup functions. As - per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 - -2006-03-03 Andrey Kiselev - - * libtiff/{tif_predict.c, tif_predict.h}: Added new function - TIFFPredictorCleanup() to restore parent decode/encode/field methods. - - * libtiff/{tif_lzw.c, tif_pixarlog.c, tif_zip.c}: Use - TIFFPredictorCleanup() in codec cleanup methods. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 - - * libtiff/tif_dirread.c: Fixed integer overflow condition in - TIFFFetchData() function. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 - -2006-03-01 Andrey Kiselev - - * libtiff/tif_ojpeg.c: Set the ReferenceBlackWhite with the - TIFFSetField() method, not directly. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1043 - - * tools/ppm2tiff.c: Added support for PBM files as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1044 - -2006-02-27 Andrey Kiselev - - * libtiff/tif_write.c: Small code rearrangement in TIFFWriteScanline() - to avoid crash as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1081. - -2006-02-26 Andrey Kiselev - - * tools/tiff2pdf.c: Functions t2p_sample_rgbaa_to_rgb() and - t2p_sample_rgba_to_rgb() was used in place of each other, that was - resulted in problems with RGBA images with associated alpha. - As per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1097 - -2006-02-23 Andrey Kiselev - - * libtiff/tif_dirwrite.c: Properly write TIFFTAG_DOTRANGE tag as per - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1088. - - * libtiff/tif_print.c: Properly read TIFFTAG_PAGENUMBER, - TIFFTAG_HALFTONEHINTS, TIFFTAG_YCBCRSUBSAMPLING and TIFFTAG_DOTRANGE - tags as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1088. - - * tools/tiff2ps.c: Properly scale all the pages when converting - multipage TIFF with /width/height/center options set. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1080 - -2006-02-15 Andrey Kiselev - - * tools/tiff2pdf.c: Do not create output file until all option checks - will be done. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1072 - - * tools/bmp2tiff.c: Added ability to create multipage TIFFs from the - list of input files as per bug: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1077 - -2006-02-09 Andrey Kiselev - - * libtiff/tif_tile.c: Fix error reporting in TIFFCheckTile() as per - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1063. - - * tools/tiffgt.c: Avoid crashing in case of image unsupported by - TIFFRGBAImage interface. - - * libtiff/tif_color.c: Avoid overflow in case of wrong input as per - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1065. - -2006-02-07 Frank Warmerdam - - * tools/tiff2pdf.c: Fixed support for non-YCbCr encoded JPEG - compressed TIFF files, per submission from Dan Cobra. - -2006-02-07 Andrey Kiselev - - * libtiff/{tif_dirread.c, tif_packbits.c, tif_win32.c}: Properly - cast values to avoid warnings. As per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1033. - - * libtiff/tif_dirinfo.c: Use TIFF_NOTYPE instead of 0 when - appropriate. As per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1033. - - * libtiff/tif_aux.c: Fixed type of temporary variable in - _TIFFCheckMalloc() as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1033. - -2006-02-06 Andrey Kiselev - - * libtiff/tif_aux.c: Return static array when fetching default - YCbCrCoefficients (another problem, reported a the - http://bugzilla.remotesensing.org/show_bug.cgi?id=1029 entry). - -2006-02-03 Andrey Kiselev - - * libtiff/tif_dir.c: Special handling for PageNumber, HalftoneHints, - YCbCrSubsampling and DotRange tags as per bugs - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1029 - http://bugzilla.remotesensing.org/show_bug.cgi?id=1034 - - * libtiff/tif_dirread.c: Use _TIFFGetExifFieldInfo() instead of - _TIFFGetFieldInfo() in TIFFReadEXIFDirectory() call as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1026. - -2006-01-23 Andrey Kiselev - - * libtool related stuff updated from the 2.1a branch. - -2006-01-11 Frank Warmerdam - - * tools/bmp2tiff,pal2rgb,ppm2tiff,ras2tiff,raw2tiff,sgi2tiff, - tiff2bw,tiffcp: Fixed jpeg option processing so -c jpeg:r:50 works - properly as per bug: - http://bugzilla.remotesensing.org/show_bug.cgi?id=1025 - -2006-01-09 Bob Friesenhahn - - * configure.ac: Fix with_default_strip_size comparison as reported - by Norihiko Murase. - -2006-01-08 Bob Friesenhahn - - * test/Makefile.am (LIBTIFF): Due to linking against libtiff - incorrectly, tests were not actually testing the uninstalled - libtiff. Now they are. - -2006-01-04 Andrey Kiselev - - * libtiff/tif_dirinfo.c: Change definitions for TIFFTAG_ICCPROFILE, - TIFFTAG_PHOTOSHOP, TIFFTAG_RICHTIFFIPTC, TIFFTAG_XMLPACKET: readcount - should be uint32 value. - -2006-01-02 Bob Friesenhahn - - * html/man/Makefile.am (htmldoc): Fix htmldoc rule so that it can - be used if build directory is not the same as source directory. - * man/{TIFFGetField.3tiff, TIFFSetField.3tiff}: Documented - TIFFTAG_PHOTOSHOP, TIFFTAG_RICHTIFFIPTC, and TIFFTAG_XMLPACKET, - and re-sorted tag names in alphabetical order. - -2005-12-29 Andrey Kiselev - - * libtiff 3.8.0 released. - -2005-12-28 Bob Friesenhahn - - * tools/bmp2tiff.c (main): Fixed warning regarding returning - inconsistent types from a condition. - * tools/tiffcmp.c (CheckLongTag): Eliminate warning due to printf - format. - * tools/bmp2tiff.c: Reduce compilation warnings on big-endian CPUs. - -2005-12-28 Joris Van Damme - - * html/{index.html, support.hml, libtiff.html}: Cleaned up HTML - -2005-12-27 Andrey Kiselev - - * libtiff/tiffio.h: Added VC_EXTRALEAN definition before including - windows.h, to reduce the compile time. - -2005-12-26 Bob Friesenhahn - - * libtiff/tif_jpeg.c: Improve compilation under MinGW. - -2005-12-26 Andrey Kiselev - - * libtiff/{tif_dir.c, tif_dir.h, tif_dirread.c, tif_dirinfo.c}: - tiffFieldInfo and exifFieldInfo arrays definitions moved back to - tif_dirinfo.c; added _TIFFGetFieldInfo() and _TIFFGetExifFieldInfo() - private functions to retrieve FieldInfo arrays. - -2005-12-24 Bob Friesenhahn - - * html/build.html: Added some additional instructions for when - building using MSVC under Windows. Also fixed two HTML syntax - errors and used HTML Tidy to tidy up the HTML syntax and - formatting. - -2005-12-24 Andrey Kiselev - - * libtiff/{tif_aux.c, tif_dir.c, tif_dir.h, tif_dirwrite.c, - tif_print.c, tif_getimage.c}: Make InkSet, NumberOfInks, DotRange and - StoNits tags custom. - -2005-12-23 Andrey Kiselev - - * libtiff/{tif_aux.c, tif_dir.c, tif_dir.h, tif_print.c}: Make - WhitePoint tag custom. - - * libtiff/{tif_dir.h, tiff.h}: More EXIF tags added. - -2005-12-23 Joris Van Damme - - * libtiff/tiffio.h: fixed typo that potentially resulted in - redefininition of USE_WIN32_FILEIO - - * libtiff/*: Added more 'dual-mode' error handling: Done TIFFWarning - calls in core LibTiff. - -2005-12-21 Andrey Kiselev - - * libtiff/{tif_dir.c, tif_dir.h, tif_print.c}: Make RichTIFFIPTC, - Photoshop and ICCProfile tags custom. - -2005-12-21 Joris Van Damme - - * libtiff/*, contrib/*: Added 'dual-mode' error handling, enabling - newer code to get context indicator in error handler and still - remain compatible with older code: Done TIFFError calls everywhere - except in tools - -2005-12-20 Andrey Kiselev - - * tools/tiffcp.c: Added many error reporting messages; fixed integer - overflow as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=789 - -2005-12-16 Frank Warmerdam - - * contrib/addtiffo/*: Major upgrade by Joris to support subsampled - YCbCr images in jpeg compressed TIFF files. - -2005-12-14 Andrey Kiselev - - * tools/tiffcp.c: Return non-zero status when reading fails (again). - -2005-12-13 Andrey Kiselev - - * tools/tiffcp.c: Return non-zero status when reading fails. - -2005-12-12 Andrey Kiselev - - * libtiff/{tif_dir.h, tiff.h}: Added more EXIF tags. - -2005-12-09 Andrey Kiselev - - * libtiff/{tif_dir.c, tif_dir.h, tif_print.c}: Make XMLPacket tag - custom. - - * tools/tiffinfo.c: Print EXIF directory contents if exist. - - * libtiff/tiff.h: Few EXIF tag numbers added. - - * libtiff/{tif_dirinfo.c, tif_dirread.c, tif_dir.h, tif_dir.c, - tiffio.h}: Preliminary support to read custom directories. New - functions: TIFFReadCustomDirectory() and TIFFReadEXIFDirectory(). - -2005-12-07 Andrey Kiselev - - * libtiff/{tif_dirinfo.c, tif_dirread.c, tif_dir.h, tif_dir.c}: - More work to implement custom directory read support. - - * libtiff/{tif_aux.c, tif_dirinfo.c, tif_dirread.c, tif_dir.h, - tif_dir.c, tif_print.c}: Make YCbCrCoefficients and ReferenceBlackWhite - tags custom. - -2005-12-05 Andrey Kiselev - - * libtiff/tif_dirread.c: One more workaround for broken - StripByteCounts tag. Handle the case when StripByteCounts array filled - with completely wrong values. - -2005-11-30 Andrey Kiselev - - * libtiff/tif_dirinfo.c: Release file descriptor in case of failure - in the TIFFOpenW() function as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1003 - - * libtiff/tif_dirinfo.c: Correctly yse bsearch() and lfind() - functions as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1008 - -2005-11-20 Frank Warmerdam - - * tif_open.c, tiff.h, tiffdump.c: Incorporate preliminary support - for MS MDI format. - http://bugzilla.remotesensing.org/show_bug.cgi?id=1002 - - * .cvsignore: many files added, and a few update according - to suggestion of Brad HArds on tiff mailing list. - -2005-11-03 Frank Warmerdam - - * libtiff/libtiff.def, tiffiop.h, tiffio.h: Made TIFFFreeDirectory - public. - -2005-10-31 Andrey Kiselev - - * tools/fax2tiff.c: Properly calculate sizes of temporary arrays - as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=943 - - * tools/fax2tiff.c: Added option '-r' to set RowsPerStrip parameter - as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=944 - - * tools/tiffdump.c: Fixed typeshift and typemask arrays initialization - problem as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=946 - - * tools/bmp2tiff.c: Fixed possible integer overflow error as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=965 - - * libtiff/tif_dirinfo.c: Make XResolution, YResolution and - ResolutionUnit tags modifiable during write process. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=977 - - * tools/tiffsplit.c: Copy fax related fields over splitted parts - as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=983 - -2005-10-21 Frank Warmerdam - - * tif_dirread.c: Don't try and split single strips into "0" strips - in ChopUpSingleUncompressedStrip. This happens in some degenerate - cases (like 1x1 files with stripbytecounts==0 (gtsmall.jp2 embed tiff) - -2005-10-20 Joris Van Damme - - * tif_fax3.c: changed 'at scanline ...' style warning/errors - with incorrect use of tif_row, to 'at line ... of - strip/tile ...' style - -2005-10-15 Frank Warmerdam - - * tif_write.c: fixed setting of planarconfig as per bug report - on the mailing list from Joris. - -2005-10-07 Andrey Kiselev - - * configure.ac, configure, nmake.opt, libtiff/{tif_config.h, - tif_dirread.c}: Make the default strip size configurable via the - --with-default-strip-size and STRIP_SIZE_DEFAULT options. - -2005-09-30 Bob Friesenhahn - - * html/support.html: Fixed link to documentation on Greg Ward's - LogLuv TIFF format. - -2005-09-28 Andrey Kiselev - - * tools/tiffdump.c: Fixed crash when reading malformed tags. - -2005-09-20 Andrey Kiselev - - * tools/tiff2pdf.c: Added missed 'break' statement as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=932 - -2005-09-12 Andrey Kiselev - - * libtiff 3.7.4 released. - - * {configure, configure.ac, Makefile.am, autogen.sh}: Applied patch - from Patrick Welche (all scripts moved in the 'config' and 'm4' - directories). - -2005-09-12 Frank Warmerdam - - * libtiff/tif_open.c: reintroduce seek to avoid problem on solaris. - -2005-09-05 Frank Warmerdam - - * libtiff/tif_dir.c: When prefreeing tv->value in TIFFSetFieldV - also set it to NULL to avoid double free when re-setting custom - string fields as per: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=922 - -2005-08-12 Frank Warmerdam - - * libtiff/tif_print.c: avoid signed/unsigned warning. - - * libtiff/tif_dirread.c: removed unused variable. - -2005-07-30 Frank Warmerdam - - * libtiff/tif_dir.c: Fixed up support for swapping "double complex" - values (128 bits as 2 64 bits doubles). GDAL gcore tests now - pass on bigendian (macosx) system. - -2005-07-28 Andrey Kiselev - - * libtiff/{tif_aux.c, tif_dirread.c, tif_fax3.c, tiffiop.h}: Rename - CheckMalloc() function to _TIFFCheckMalloc() and make it available - globally as an internal helper routine. - -2005-07-27 Andrey Kiselev - - * libtiff/tif_dir.c: More improvements in the "pass by value" part of - the custom tags handling code. - -2005-07-26 Andrey Kiselev - - * libtiff/{tif_dirread.c, tif_dirinfo.c}: Do not upcast BYTEs to - SHORTs in the TIFFFetchByteArray(). Remove TIFFFetchExtraSamples() - function, use TIFFFetchNormalTag() instead as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=831 - - Remove TIFFFetchExtraSamples() function, use TIFFFetchNormalTag() - instead. - - * libtiff/tiffconf.h.in: One more attempt to fix the AIX bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=39 - -2005-07-25 Andrey Kiselev - - * libtiff/tif_print.c: Fixed printing of the BYTE and SBYTE arrays. - - * tools/tiffdump.c: Added support for TIFF_IFD datatype. - -2005-07-21 Andrey Kiselev - - * libtiff/tif_write.c: Do not check the PlanarConfiguration field in - the TIFFWriteCheck() function in case of single band images (as per - TIFF spec). - -2005-07-12 Andrey Kiselev - - * SConstruct, libtiff/SConstruct: Added the first very preliminary - support for SCons software building tool (http://www.scons.org/). - This is experimental infrastructure and it will exist along with the - autotools mechanics. - -2005-07-07 Andrey Kiselev - - * port/{getopt.c, strcasecmp.c, strtoul.c}: Update modules from - the NetBSD source tree (the old 4-clause BSD license changed to - the new 3-clause one). - - * configure.ac, port/lfind.c, libtiff/tiffiop.h: Added lfind() - replacement module. - - * port/dummy.c: Make the dummy function static. - -2005-07-06 Andrey Kiselev - - * tools/tiffcp.c: Fixed WhitePoint tag copying. - - * libtiff/{tif_dir.c, tif_dir.h, tif_dirinfo.c, tif_print.c}: - Make FieldOfViewCotangent, MatrixWorldToScreen, MatrixWorldToCamera, - ImageFullWidth, ImageFullLength and PrimaryChromaticities tags custom. - -2005-07-04 Andrey Kiselev - - * libtiff 3.7.3 released. - - * configure, configure.ac: Do not use empty -R option when linking - with --enable-rpath. - -2005-07-01 Andrey Kiselev - - * libtiff/{tiffiop.h, tif_open.c}: Added open option 'h' to avoid - reading the first IFD when needed. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=875 - - * libtiff/tif_color.c: Better use of TIFFmin() macro to avoid side - effects. - -2005-06-23 Andrey Kiselev - - * tools/tiff2pdf.c: Print two characters per loop in the - t2p_write_pdf_trailer(). As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=594 - - * tools/tiffgt.c: Use MacOS X OpenGL framework when appropriate. As - per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=844 - - * acinclude.m4: Updated to latest OpenGL test macros versions. - - * libtiff/tiff.h: Use correct int size on Sparc 64bit/Sun compiler - platform. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=855 - -2005-06-14 Andrey Kiselev - - * libtiff/tif_dirinfo.c: Added support for ClipPath, XClipPathUnits - and YClipPathUnits tags. - -2005-06-07 Andrey Kiselev - - * contrib/addtiffo/tif_ovrcache.c: Properly extract tile/strip size; - use pixel sized shift in contigous case. - -2005-06-06 Andrey Kiselev - - * contrib/addtiffo/{tif_overview.c, tif_ovrcache.c, tif_ovrcache.h}: - Make overviews working for contiguos images. - -2005-06-03 Andrey Kiselev - - * libtiff/tif_open.c: Replace runtime endianess check with the compile - time one. - - * libtiff/tif_predict.c: Floating point predictor now works on - big-endian hosts. - -2005-06-01 Andrey Kiselev - - * libtiff/tif_dir.c: Use _TIFFsetString() function when read custom - ASCII values. - - * libtiff/{tif_dirinfo.c, tif_dir.h, tif_dir.c, tif_print.c}: Make - DocumentName, Artist, HostComputer, ImageDescription, Make, Model, - Copyright, DateTime, PageName, TextureFormat, TextureWrapModes and - TargetPrinter tags custom. - - * libtiff/tif_jpeg.c: Cleanup the codec state depending on - TIFF_CODERSETUP flag (to fix memry leaks). - - * libtiff/tif_jpeg.c: Initialize JPEGTables array with zero after - allocating. - -2005-05-26 Andrey Kiselev - - * configure.ac, libtiff/Makefile.am: Added workaround for - OpenBSD/MirOS soname problem as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=838 - - * libtiff/tif_dirwrite.c: Use tdir_count when calling - TIFFCvtNativeToIEEEDouble() in the TIFFWriteDoubleArray() function as - per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=845 - -2005-05-25 Andrey Kiselev - - * tools/ppm2tiff.c: Fixed format string when read PPM file header with - the fscanf() function. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=861 - - * libtiff/{tif_dirinfo.c, tif_print.c}: TIFFFetchByteArray() returns - uint16 array when fetching the BYTE and SBYTE filds, so we should - consider result as pointer to uint16 array and not as array of chars. - As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=831 - - * libtiff/tif_dir.c: More efficient custom tags retrieval as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=830 - - * libtiff/tif_win32.c: Use FILE_SHARE_READ | FILE_SHARE_WRITE share - mode in CreateFile() call as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=829 - - * libtiff/Makefile.am: Fixed parallel compilation of the libtiff and - libtiffxx libraries as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=826 - - * contrib/addtiffo/{tif_overview.c, tif_ovrcache.h}: Sinchronized with - GDAL. - -2005-05-23 Frank Warmerdam - - * libtiff/tif_jpeg.c: Substantial fix for addtiffo problems with - JPEG encoded TIFF files. Pre-allocate lots of space for jpegtables - in directory. - -2005-05-22 Frank Warmerdam - - * libtiff/tif_dirread.c: Changed the code that computes - stripbytecount[0] if it appears bogus to ignore if stripoffset[0] is - zero. This is a common case with GDAL indicating a "null" tile/strip. - -2005-05-17 Andrey Kiselev - - * tools/tiffsplit.c: Check for JPEGTables tag presence before copying. - -2005-05-06 Frank Warmerdam - - * libtiff/tif_dirread.c: Applied similar change to - TIFFFetchPerSampleLongs and TIFFFetchPerSampleAnys. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=843 - - * libtiff/tif_jpeg.c: added LIB_JPEG_MK1 support in JPEGDecodeRaw(). - -2005-05-06 Andrey Kiselev - * tools/tiff2pdfr.c, man/tiff2pdf.1: Calculate the tile width properly; - added new option '-b' to use interpolation in output PDF files (Bruno - Ledoux). - -2005-05-05 Frank Warmerdam - - * libtiff/tif_dirread.c: Ensure that broken files with too many - values in PerSampleShorts work ok instead of crashing. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=843 - -2005-04-27 Andrey Kiselev - - * tools/tiffdither.c: Copy the PhotometricInterpretation tag from the - input file. - -2005-04-15 Andrey Kiselev - - * libtiff/tif_predict.c: Added ability to encode floating point - predictor, as per TIFF Technical Note 3. - -2005-04-14 Andrey Kiselev - - * libtiff/{tif_predict.h, tif_predict.c}: Added ability to decode - floating point predictor, as per TIFF Technical Note 3. - -2005-04-13 Andrey Kiselev - - * libtiff/{tiffio.h, tiffiop.h, tif_dir.c, tif_read.c, tif_swab.c}: - Added _TIFFSwab24BitData() and TIFFSwabArrayOfLong() functions used to - swap 24-bit floating point values. - - * libtiff/tiff.h: Added predictor constants. - -2005-04-08 Andrey Kiselev - - * libtiff/{tiffiop.h, tif_dir.c}: Use uint32 type for appropriate - values in _TIFFVSetField() function. Inspired by the bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=816 - - * man/TIFFSetField.3tiff: Fixed definition of the TIFFTAG_INKNAMES tag - as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=816 - -2005-03-30 Andrey Kiselev - - * libtiff/tif_open.c: Do not read header in case the output file - should be truncated (Ron). - - * libtiff/{tif_dirinfo.c, tif_config.h.vc}: Use lfind() instead - of bsearch() in _TIFFFindFieldInfoByName() function (Ron). - - * libtiff/{tiff.h, tif_dirinfo.c}: Fixes in EXIF tag ordering (Ron). - -2005-03-22 Andrey Kiselev - - * configure.ac, libtiff/Makefile.am: Use libtool machinery to pass - rpath option. - -2005-03-21 Andrey Kiselev - - * libtiff/{tif_dir.c, tif_print.c}: Handle all data types in custom - tags. - -2005-03-18 Andrey Kiselev - - * libtiff/dirinfo.c: Added DNG tags. - - * libtiff/{tif_dir.c, tif_print.c}: More improvements in custom tag - handling code. - - * libtiff/tiff.h: More comments; added missed DNG tag (LensInfo); - added DNG 1.1.0.0 tags. - - * tools/tif2pdf.c: Fixed problem with alpha channel handling as per - bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=794 - - * man/TIFFGetField.3tiff: Add a note about autoregistered tags. - -2005-03-17 Andrey Kiselev - - * nmake.opt: Build with Win32 CRT library by default. - - * tools/tiff2ps.c: Fixed typo in page size handling code. - - * libtiff/{tif_dir.c, tif_print.c}: Support for custom tags, passed - by value. - - * libtiff/{tiff.h, tif_dirinfo.c, tiffiop.h}: Added EXIF related tags. - -2005-03-15 Andrey Kiselev - - * libtiff 3.7.2 released. - -2005-03-09 Andrey Kiselev - - * tools/tiffcmp.c: Added ability to compare the 32-bit integer and - floating point data; complain on unsupported bit depths. - -2005-03-05 Andrey Kiselev - - * tif_stream.cxx: Use ios namespace instead of ios_base to support - GCC 2.95. - - * libtiff/{tiff.h, tif_fax3.tif, tif_jpeg.c}: Applied correct patch from - Lee Howard for HylaFax DCS tag - (see http://bugzilla.remotesensing.org/show_bug.cgi?id=771) - -2005-03-04 Andrey Kiselev - - * configure, configure.ac: Use -rpath option instead of -R as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=732 - - * libtiff/{tiff.h, tif_fax3.tif, tif_jpeg.c}: Applied patch from Lee - Howard to support a new tag TIFFTAG_FAXDCS (34911) used in HylaFax - software. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=771 - - * nmake.opt, html/build.html: Add more comments, change the config - file organization a bit as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=764 - - * tools/tiffcmp.c: Use properly sized buffer in short arrays comparison - as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=785 - -2005-03-03 Andrey Kiselev - - * libtiff/tif_dirread.c: More logic to guess missed strip size as per - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=705 - - * tools/fax2ps.c: Replace insecure mktemp() function with the - tmpfile() as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=786 - -2005-02-04 Andrey Kiselev - - * libtiff/tiff.h: Changed the int8 definition to be always signed char - as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=727 - - * libtiff/tiffio.h: Move TIFFOpenW() function into the extern "C"{} - block as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=763 - -2005-02-03 Bob Friesenhahn - - * tools/tiffgt.c: Fix problem on big-endian CPUs so that images - display more correctly. Images display brighter than they should - on a Sun workstation. - -2005-02-03 Andrey Kiselev - - * libtiff/tif_dirread.c: Estimate strip size in case of wrong or - suspicious values in the tags. As per bugs - - http://bugzilla.remotesensing.org/show_bug.cgi?id=705 - - and - - http://bugzilla.remotesensing.org/show_bug.cgi?id=320 - - * tools/tiff2ps.c: Fixed problem with page sizes as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=742 - -2005-01-31 Bob Friesenhahn - - * libtiff/tiff.h (TIFFTAG_TILEWIDTH): Corrected description. - (TIFFTAG_TILELENGTH): Corrected description. - -2005-01-30 Andrey Kiselev - - * configure.ac: Fixes for --with-docdir option as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=759 - - * libtiff/tif_open.c: Remove unnesessary TIFFSeekFile() call as per - bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=756 - - * libtiff/tif_stream.cxx: Fixes for C++ stream interface from - Michael Rinne and Edward Lam. - -2005-01-15 Andrey Kiselev - - * configure.ac: Make the documentation directory location configurable - via the --with-docdir option (as suggested by Jeremy C. Reed). - - * libtiff/tif_color.c: Use double as the second argument of pow() - function in TIFFCIELabToRGBInit(). As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=741 - - * libtiff/tif_pixarlog.c: Avoid warnings when converting float to - integer as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=740 - - * libtiff/tif_getimage.c: Always fill the error message buffer in - TIFFRGBAImageBegin() as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=739 - -2005-01-12 Andrey Kiselev - - * libtiff/tif_jpeg.c: Added ability to read/write the fax specific - TIFFTAG_FAXRECVPARAMS, TIFFTAG_FAXSUBADDRESS and TIFFTAG_FAXRECVTIME - tags as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=736 - - * libtiff/tif_win32.c: Fixed message formatting in functions - Win32WarningHandler() and Win32ErrorHandler() as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=735 - - * tools/tiff2ps.c: Interpret the -w and -h options independently. As - per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=689 - -2005-01-11 Andrey Kiselev - - * libtiff/tiffio.h: Move the color conversion routines in the 'extern - "C"' section as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=727 - - * libtiff/tiff.h: Restore back the workaround for AIX Visual Age C - compiler to avoid double definition of BSD types as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=39 - - * libtiff/Makefile.am: Place the C++ stream API in the separate - library called libtiffxx to avoid unneeded dependencies. Probably - there will be more C++ API in the future. As per bugs - - http://bugzilla.remotesensing.org/show_bug.cgi?id=733 - - and - - http://bugzilla.remotesensing.org/show_bug.cgi?id=730 - -2005-01-05 Andrey Kiselev - - * tools/tiffdump.c: Fixed problem when read broken TIFFs with the - wrong tag counts (Dmitry V. Levin, Martin Pitt). - - * configure.ac: Replace --disable-c++ with the --disable-cxx option as - per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=730 - -2004-12-25 Andrey Kiselev - - * libtiff/tif_getimage.c: More fixes for multiple-alpha-channelled - RGB-images as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=713 - - - * tools/tiffset.c: Convert character option to integer value as per - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=725 - -2004-12-20 Andrey Kiselev - - * libtiff 3.7.1 released. - - * html/tiffset.1.html: Add missed manual page as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=678 - - * libtiff/tiff.h: Revert back libtiff data type definitions as per - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=687 - -2004-12-19 Andrey Kiselev - - * libtiff/tif_dirread.c: Do not forget about TIFF_VARIABLE2 when - checking for tag count in TIFFReadDirectory() function. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=713 - - * libtiff/{tif_dirread.c, tif_fax3.c}: More argument checking in - CheckMallock() function. - - * libtiff/tif_getimage.c: Support for multiple-alpha-channelled - RGB-images as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=718 - -2004-12-15 Frank Warmerdam - - * libtiff/tif_getimage.c: #define A1 bracketing for clean build on - SunPro compiler. - -2004-12-11 Bob Friesenhahn - - * autogen.sh: aclocal and autoheader should be executed after - libtoolize. Also add '-I .' to aclocal invocation to check - current directory for macros. - -2004-12-10 Andrey Kiselev - - * libtiff/tif_dirwrite.c: Always write TIFFTAG_SUBIFD using LONG type - as per bugs - - http://bugzilla.remotesensing.org/show_bug.cgi?id=703 - - and - - http://bugzilla.remotesensing.org/show_bug.cgi?id=704 - -2004-12-04 Andrey Kiselev - - * nmake.opt: Link with the user32.lib in windowed mode. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=697 - - * libtiff/tif_win32.c: Use char* strings instead of TCHAR in windowed - mode as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=697 - - * libtiff/tif_config.in.vc: Removed unneded definitions for - read/open/close/lseek functions to fix the - - http://bugzilla.remotesensing.org/show_bug.cgi?id=680 - -2004-12-03 Andrey Kiselev - - * libtiff/{tif_dir.c, tif_dirread.c}: Remove TIFFReassignTagToIgnore() - call from the TIFFReadDirectory() function. TIFFReassignTagToIgnore - must be removed in the future, as it was never used properly. As per - bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=692 - -2004-11-30 Bob Friesenhahn - - * libtiff/tif_jpeg.c: Added a work-around in order to allow - compilation with the heavily modified version of libjpeg delivered - with Cygwin. - -2004-11-29 Andrey Kiselev - - * libtiff/tif_dir.c: Properly handle tags, which have the uint32 - counts. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=693 - - * tools/fax2ps.c: Be able to extract the first page (#0). As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=690 - -2004-11-28 Andrey Kiselev - - * libtiff/tif_unix.c: Make UNIX module compilable (and usable) - on Windows. - - * nmake.opt: Add missed DLLNAME variable. - -2004-11-26 Frank Warmerdam - - * libtiff/makefile.vc: make it easier to rename the libtiff DLL. - -2004-11-24 Andrey Kiselev - - * man/libtiff.3tiff: Improvements in the "LIST OF ROUTINES" table as - per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=545 - - * man/tiffset.1: Added manual page for tiffset tool written by Jay - Berkenbilt. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=678 - -2004-11-23 Frank Warmerdam - - * libtiff/tif_error.c: fixed TIFFerror call to be TIFFError. - -2004-11-21 Frank Warmerdam - - * html/document.html: Updated Adobe web links as per email from Joris. - -2004-11-21 Andrey Kiselev - - * libtiff/{tiffio.hxx, tiffio.h}: C++ stream interface moved to new - file tiffio.hxx. We don't have any C++ in tiffio.h, those who want to - use C++ streams should #include . - -2004-11-13 Andrey Kiselev - - * libtiff/tiff.h: Added Adobe DNG tags. - - * libtiff/tif_win32.c: Typo fixed. - - * libtiff/{tif_stream.cxx, tiffio.h}: C++ stream interface updated to - be compliant with the latest standard. Appropriate additions in - makefiles now completed. - -2004-11-11 Andrey Kiselev - - * tools/tiffset.c, libtiff/tif_dirinfo.c: Properly handle the - different tag types. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=600 - -2004-11-10 Andrey Kiselev - - * libtiff/tif_aux.c: Set the appropriate ReferenceBlackWhite array for - YCbCr image which lacks that tag (noted by Hans Petter Selasky). - -2004-11-09 Andrey Kiselev - - * libtiff/tif_color.c: Division by zero fixed (Hans Petter Selasky). - -2004-11-07 Andrey Kiselev - - * libtiff/{tif_stream.cxx, tiffio.h}: Added C++ stream interface - contributed by Edward Lam (see - http://bugzilla.remotesensing.org/show_bug.cgi?id=654 for details). - Though no changes in any makefiles yet. - -2004-11-05 Frank Warmerdam - - * libtiff/tif_open.c: Removed close() in TIFFClientOpen() if file - is bad. This is the callers responsibility. - http://bugzilla.remotesensing.org/show_bug.cgi?id=651 - -2004-11-05 Andrey Kiselev - - * libtiff/{tiffio.h, tif_win32.c, libtiff.def}: Added TIFFOpenW() - function to work with the double byte strings (used to represent - filenames in some locales). As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=625 - - * libtiff/tif_dirread.c: Fixed problem when fetching BitsPerSample and - Compression tags of type LONG from broken TIFFS as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=662 - - * libtiff/tif_dirinfo.c: Fixed definition for TIFFTAG_RICHTIFFIPTC, - the writecount should have uint32 type. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=662 - - * libtiff/tif_write.c: Fixed wrong if() statement in - TIFFAppendToStrip() function as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=660 - -2004-11-04 Andrey Kiselev - - * libtiff/tif_dirinfo.c: Change definition for TIFFTAG_EXTRASAMPLES - field. The caller should supply a count when setting this field. As - per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=648 - - * libtiff/{tif_jpeg.c, tif_ojpeg.c}: TIFFTAG_JPEGTABLES should have - uint32 count. Use this type everywhere. - -2004-11-03 Frank Warmerdam - - * libtiff/tif_next.c: avoid use of u_long and u_char types. Bug 653. - -2004-11-02 Frank Warmerdam - - * tools/tiff2rgba.c: removed extra newlines in usage message. - -2004-10-30 Andrey Kiselev - - * libtiff/tif_dirwrite.c: Improvements in tag writing code. - - * tools/tiff2ps.c: Fixed wrong variable data type when read Position - tags (Tristan Hill). - -2004-10-30 Frank Warmerdam - - * libtiff/tiffiop.h: added fallback definition of assert() if we - don't have assert.h. - -2004-10-29 Andrey Kiselev - - * libtiff/tif_fax3.c: Fixed case with the wrong decode routines - choosing when the incorrect Group4Options tag set. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=323 - - * libtiff/tif_dirwrite.c: Fixed problem with passing count variable of - wrong type when writing the TIFF_BYTE/TIFF_SBYTE tags in - TIFFWriteNormalTag(). - -2004-10-28 Andrey Kiselev - - * tools/tiff2ps.c: Fixed wrong variable data type when read Resolution - tags (Peter Fales). - - * tools/{bmp2tiff.c, raw2tiff.c}: Get rid of stream I/O functions. - -2004-10-28 Frank Warmerdam - - * tools/tiff2pdf.c: added casts to avoid warnings. - - * libtiff/libtiff.def: Added several more entry points required - to link fax2tiff.c against the DLL on windows. - -2004-10-27 Andrey Kiselev - - * configure, configure.ac: Added --enable-rpath option to embed linker - paths into library binary. - -2004-10-26 Andrey Kiselev - - * tools/tiffset.c: Check the malloc return value (Dmitry V. Levin). - - * libtiff/{tif_strip.c, tif_tile.c}: Zero division problem fixed - (Vladimir Nadvornik, Dmitry V. Levin). - -2004-10-16 Andrey Kiselev - - * libtiff 3.7.0 released. - -2004-10-15 Bob Friesenhahn - - * libtiff/tif_jpeg.c: There seems to be no need to include stdio.h - in this file so its inclusion is removed. Including stdio.h - sometimes incurs an INT32 typedef conflict between MinGW's - basetsd.h and libjpeg's jmorecfg.h. - -2004-10-15 Andrey Kiselev - - * man/bmp2tiff.1: Added manual page for bmp2tiff utility. - -2004-10-13 Bob Friesenhahn - - * tools/tiffcmp.c (leof): Renamed from 'eof' in order to avoid - conflict noticed under MinGW. - * ltmain.sh: Fix for MinGW compilation. - -2004-10-13 Frank Warmerdam - - * man/tiffsplit.1: Fixed to indicate using aaa-zzz, not aa-zz. - http://bugzilla.remotesensing.org/show_bug.cgi?id=635 - -2004-10-12 Andrey Kiselev - - * libtiff/{tif_dirread.c, tif_jpeg.c, tif_luv.c, tif_ojpeg.c, - tif_pixarlog.c, tif_write.c}: Handle the zero strip/tile sizes - properly (Dmitry V. Levin, Marcus Meissner). - -2004-10-11 Andrey Kiselev - - * libtiff/tif_dirinfo.c: Type of the TIFFTAG_SUBIFD field changed - to TIFF_IFD. - -2004-10-10 Andrey Kiselev - - * tools/bmp2tif.c: Check the space allocation results. - -2004-10-09 Andrey Kiselev - - * libtiff/tif_dir.c: Initialize td_tilewidth and td_tilelength fields - of the TIFFDirectory structure with the 0 instead of -1 to avoid - confusing integer overflows in TIFFTileRowSize() for striped images. - - * tools/tiff2pdf.c: Fixed TransferFunction tag handling reported - by Ross A. Finlayson. - - * libtiff/tif_dir.c: Fixed custom tags handling as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=629 - -2004-10-08 Frank Warmerdam - - * libtiff/tif_dirinfo.c: Fix bug with tif_foundfield and reallocation - of tif_fieldinfo. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=630 - -2004-10-04 Bob Friesenhahn - - * contrib/iptcutil/README: Added the missing README which goes - along with iptcutil. - -2004-10-03 Andrey Kiselev - - * libtiff/tif_compress.c: Improved error reporting in - TIFFGetConfiguredCODECs() (Dmitry V. Levin). - -2004-10-02 Andrey Kiselev - - * libtiff 3.7.0beta2 released. - - * libtiff/{tif_aux.c, tif_compress.c, tif_dirinfo.c, tif_dirwrite.c, - tif_extension.c, tif_fax3.c, tif_luv.c, tif_packbits.c, - tif_pixarlog.c, tif_write.c}: Added checks for failed memory - allocations and integer overflows (Dmitry V. Levin). - - * libtiff/tiff.h: Missed TIFF_BIGTIFF_VERSION constant added. - -2004-10-01 Frank Warmerdam - - * libtiff/tif_open.c: added a more informative message if a BigTIFF - file is opened. - -2004-09-30 Frank Warmerdam - - * libtiff/tif_dirinfo.c: changed type of XMLPacket (tag 700) to - TIFFTAG_BYTE instead of TIFFTAG_UNDEFINED to comply with the info - in the Adobe XMP Specification. - -2004-09-29 Andrey Kiselev - - * libtiff/{tif_jpeg.c, tif_pixarlog.c}: Use _TIFFmemset() instead of - memset(). - - * libtiff/{tif_dirread.c, tif_strip.c, tif_tile.c}: Applied patches - from Dmitry V. Levin to fix possible integer overflow problems. - -2004-09-28 Andrey Kiselev - - * libtiff/tif_getimage.c: Check for allocated buffers before clearing - (Dmitry V. Levin). - -2004-09-26 Andrey Kiselev - - * libtiff/{tif_dir.h, tif_dir.c, tif_dirread.c, tif_write.c}: - Optimize checking for the strip bounds. - - * libtiff/{tif_dirread.c, tif_strip.c}: TIFFScanlineSize() and - TIFFRasterScanlineSize() functions report zero in the case of integer - overflow now. Properly handle this case in TIFFReadDirectory() - (patches from Dmitry V. Levin). - -2004-09-25 Andrey Kiselev - - * libtiff/{tif_dirinfo.c, tif_strip.c, tif_tile.c}: Use TIFFhowmany8() - macro where appropriate. - - * tools/tiff2bw.c: Write ImageWidth/Height tags to output file, as - noted by Gennady Khokhorin. - - * libtiff/tif_dirread.c: Always check the return values, returned - by the _TIFFmalloc() (Dmitry V. Levin). - - * libtiff/tif_dir.c: Fixed possible integer overflow _TIFFset*Array() - functions (Dmitry V. Levin). - - * libtiff/{tif_dirread.c, tif_dir.c, tif_write.c}: - Potential memory leak fixed in TIFFReadDirectory(), _TIFFVSetField(), - TIFFGrowStrips() (found by Dmitry V. Levin). - -2004-09-24 Andrey Kiselev - - * libtiff/{tiffio.h, tif_compress.c}: Added TIFFGetConfiguredCODECs() - to get the list of configured codecs. - - * libtiff/{tiffiop.h, tif_dirread.c}: More overflow fixes from - Dmitry V. Levin. - -2004-09-23 Andrey Kiselev - - * libtiff/tif_dirread.c: Applied patch from Dmitry V. Levin to fix - possible integer overflow in CheckMalloc() function. - -2004-09-22 Andrey Kiselev - - * libtiff/{tiffiop.h, tif_strip.c}: Use TIFFhowmany8() macro instead - of plain TIFFhowmany() where appropriate. - -2004-09-21 Andrey Kiselev - - * libtiff/tif_getimage.c: Initialize arrays after space allocation. - -2004-09-19 Andrey Kiselev - - * libtiff 3.7.0beta released. - - * libtiff/{tif_luv.c, tif_next.c, tif_thunder.c}: Several buffer - overruns fixed, as noted by Chris Evans. - -2004-09-14 Bob Friesenhahn - - * commit: Added a script to make it more convenient to commit - updates. The CVS commit message is extracted from this ChangeLog - file. - -2004-09-14 Andrey Kiselev - - * configure.ac, configure, aclocal.m4, libtiff/{mkspans.c, tif_fax3.c, - tif_getimage.c, tif_luv.c, tif_lzw.c, tif_ojpeg.c, tif_packbits.c, - tif_predict.c, tif_read.c, tif_swab.c, tif_thunder.c, tif_write.c, - tif_dir.c, tif_dirread.c, tif_dirwrite.c, tif_jpeg.c, tif_dirinfo.c, - tif_vms.c, tif_print.c, tif_strip.c, tif_tile.c, tif_dir.h, - tif_config.h.in, tiffiop.h}: - Get rid of BSD data types (u_char, u_short, u_int, u_long). - -2004-09-13 Bob Friesenhahn - - * libtiff/tiff.h: Fix column tagging. Reference current Adobe XMP - specification. Reference libtiff bug tracking system to submit - private tag additions. - -2004-09-12 Bob Friesenhahn - - * tools/tiffgt.c: Include "tif_config.h". - - * configure.ac: Use AM_PROG_CC_C_O since it is now needed to build - tiffgt. This results in the 'compile' script being added to the - project. - - * tools/Makefile.am (tiffgt_CFLAGS): Add extra build options - required to find OpenGL headers necessary to build tiffgt. Also - ensure that the libtiff that we built is used rather than some other - libtiff installed on the system. - -2004-09-12 Andrey Kiselev - - * configure.ac, acinclude.m4, aclocal.m4: New macros to detect GLUT - libraries. - -2004-09-11 Bob Friesenhahn - - * configure.ac: Pass library configuration defines via - tif_config.h rather than extending CPPFLAGS. Configure a - libtiff/tiffconf.h in order to satisfy application requirements - (not used by library build). Do not define _POSIX_C_SOURCE=2 since - this causes failure to build on systems which properly respect - this request. - - * libtiff/tiffconf.h.in: New file to act as the template for the - configured tiffconf.h - - * libtiff/files.lst (HDRS): Install the configured tiffconf.h. - -2004-09-10 Frank Warmerdam - - * html/internals.html: Split off a discussion of adding new tags - into addingtags.html. - -2004-09-10 Andrey Kiselev - - * test/{ascii_tag.c, long_tag.c}: Preliminary test suite added. - - * tools/tiff2pdf.c: Fixed reading TransferFunction tag as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=590 - - * libtiff/tif_print.c: Fixes in InkNames and NumberOfInks reporting. - - * libtiff/tif_dirread.c: Don't reject to read tags of the - SamplesPerPixel size when the tag count is greater than number of - samples as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=576 - - * libtiff/tiff.h: Use _TIFF_DATA_TYPEDEFS_ guardian to switch off - defining int8/uint8/... etc. types. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=607 - -2004-09-09 Frank Warmerdam - - * tools/tiff2ps.c, tools/tiffmedian.c: fiddle with include files - to avoid compile warnings about getopt() and a few other things. - -2004-09-02 Andrey Kiselev - - * libtiff/tif_dirread.c: Use memcpy() function instead of pointer - assigning magic in TIFFFetchFloat(). - -2004-09-01 Andrey Kiselev - - * libtiff/{tiffio.h, tif_open.c}: Applied patches from Joris Van Damme - to avoid requirement for tiffiop.h inclusion in some applications. See - here - - http://www.asmail.be/msg0054799560.html - - for details. - - * tools/fax2tiff.c: Use the new functions in the code. - -2004-08-25 Andrey Kiselev - - * tools/tiff2pdf.c: Initialize arrays properly. - - * tools/tiff2ps.c: Avoid zero division in setupPageState() function; - properly initialize array in PSDataBW(). - -2004-08-24 Andrey Kiselev - - * tools/tiff2pdf.c: More fixes for bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=590 - - from Ross Finlayson. - -2004-08-23 Andrey Kiselev - - * tools/tiff2ps.c: Fixed problem with uninitialized values. - - * libtiff/tif_dir.c: Initialize tif_foundfield data member in the - TIFFDefaultDirectory() (in addition to 2004-08-19 fix). - - * tools/tiff2pdf.c: Fixed a bunch of problems as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=590 - -2004-08-20 Andrey Kiselev - - * tools/tiff2pdf.c: Applied patch from Ross Finlayson that checks - that the input file has compression, photometric interpretation, - etcetra, tags or if not than a more descriptive error is returned. - - * libtiff/tif_dirread.c: Fixed problem in TIFFReadDirectory() in the - code, responsible for tag data type checking. - -2004-08-19 Andrey Kiselev - - * libtiff/{tiffiop.h, tif_dirinfo.c}: Fixed problem with the static - variable as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=593 - -2004-08-16 Andrey Kiselev - - * tools/ras2tiff.c: Fixed issue with missed big-endian checks as per - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=586 - -2004-08-01 Andrey Kiselev - - * libtiff/{tif_config.h.in, tif_config.h.vc}: config.h.in and - config.h.vc files renamed in the tif_config.h.in and tif_config.h.vc. - -2004-07-24 Andrey Kiselev - - * libtiff/tif_lzw.c: LZW compression code is merged back from the - separate package. All libtiff tools are updated to not advertise an - abcence of LZW support. - -2004-07-12 Andrey Kiselev - - * libtiff/tiffio.h: Revert thandle_t back to void* type. - -2004-07-11 Andrey Kiselev - - * libtiff/{tif_read.c, tif_tile.c, tif_strip.c}: Fixes in error - messages, as suggested by Bernd Herd. - -2004-07-03 Andrey Kiselev - - * libtiff/tif_dir.c: Call TIFFError() instead of producing warnings - when setting custom tags by value. Reported by Eric Fieleke. - -2004-06-14 Andrey Kiselev - - * tools/bmp2tiff.c: Add missed RawsPerStrip setting. - -2004-06-08 Andrey Kiselev - - * tools/bmp2tiff.c: Added new utility to convert Windows BMP files - into TIFFs. - -2004-06-07 Andrey Kiselev - - * libtiff 3.7.0alpha released. - -2004-06-06 Andrey Kiselev - - * libtiff/{tiff.h, tif_dirwrite.c, tif_fax3.c, tif_packbits.c,}: Get rid - of ugly 64-bit hacks, replace them with the clever (autoconf based ) - ones :-). - - * libtiff/tiffio.h: Define thandle_t as int, not void* (may cause - problems in 64-bit environment). - -2004-06-05 Andrey Kiselev - - * tools/tiffset.c: tiffset now can set any libtiff supported tags. - Tags can be supplied by the mnemonic name or number. - - * libtiff/{tiffio.h, tif_dir.h, tif_dirinfo.c,}: Added two new - functions TIFFFindFieldInfoByName() and TIFFFieldWithName(). - -2004-05-27 Andrey Kiselev - - * libtiff/tif_ojpeg.c: Fixed problem with duplicated SOI and SOF - markers as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=581 - -2004-05-24 Andrey Kiselev - - * tools/tiffsplit.c: Don't forget to copy Photometric - Interpretation tag. - -2004-05-20 Andrey Kiselev - - * libtiff/{tif_open.c, tiffio.h}: New function added: - TIFFIsBigEndian(). Function returns nonzero if given was file written - in big-endian order. - - * tools/tiffsplit.c: Fixed problem with unproperly written multibyte - files. Now output files will be written using the same byte order - flag as in the input image. See - - http://bugzilla.remotesensing.org/show_bug.cgi?id=574 - - for details. - -2004-05-19 Frank Warmerdam - - * libtiff/tif_print.c: added (untested) support for printing - SSHORT, SLONG and SRATIONAL fields. - - * tools/tiffcp.c: close output file on normal exit. - -2004-05-17 Andrey Kiselev - - * libtiff/tif_fax3.c: Avoid reading CCITT compression options - if compression type mismatches. See - - http://bugzilla.remotesensing.org/show_bug.cgi?id=565 - -2004-04-30 Andrey Kiselev - - * libtiff/tif_strip.c: Never return 0 from the - TIFFNumberOfStrips(). - -2004-04-29 Andrey Kiselev - - * libtiff/tif_dirread.c: Workaround for broken TIFF writers which - store single SampleFormat value for multisampled images. See - - http://bugzilla.remotesensing.org/show_bug.cgi?id=562 - -2004-04-25 Andrey Kiselev - - * configure.ac, libtiff/{tiff.h, config.h.in}: Added tests for int8, - int16 and int32 types to avoid complains on some compilers. Details at - - http://bugzilla.remotesensing.org/show_bug.cgi?id=39 - -2004-04-20 Andrey Kiselev - - * tools/tiff2pdf.c: Fixed problem with unaligned access as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=555 - -2004-04-14 Andrey Kiselev - - * libtiff/tif_write.c: Allow in-place updating of the compressed - images (don't work properly with all codecs). For details see GDAL bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=534 - -2004-04-06 Andrey Kiselev - - * libtiff/tif_jpeg.c: Workaround for wrong sampling factors used - in the Intergarph JPEG compressed TIFF images as per bug: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=532 - -2004-04-04 Frank Warmerdam - - * libtiff/tif_open.c: close clientdata if TIFFClientOpen() fails - via bad2. - -2004-03-26 Andrey Kiselev - - * tools/tiffcp.c: Properly set Photometric Interpretation in case of - JPEG compression of grayscale images. - - * tools/tiffcp.c: Don't emit warnings when Orientation tag does not - present in the input image. - -2004-03-19 Andrey Kiselev - - * {many}: The first attempt to switch to autotools. - -2004-03-03 Andrey Kiselev - - * libtiff/tif_open.c: Use dummy mmap/munmap functions in - TIFFClientOpen() when the appropriate client functions was not - supplied by user. - -2004-03-02 Frank Warmerdam - - * tools/ycbcr.c: fixed main() declaration as per: - http://bugzilla.remotesensing.org/show_bug.cgi?id=513 - -2004-02-26 Andrey Kiselev - - * tools/tiffsplit.c: Copy JPEGTables tag contents for JPEG compressed - images. Reported by Artem Mirolubov. - - * libtiff/tif_dirread.c: Fixed problem with handling TIFF_UNDEFINED - tag type in TIFFFetchNormalTag() as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=508 - -2004-02-17 Frank Warmerdam - - * libtiff/tif_codec.c: Fixed typo in TIFFInitPackBits name as per: - http://bugzilla.remotesensing.org/show_bug.cgi?id=494 - -2004-02-05 Andrey Kiselev - - * libtiff/tif_fax3.c: Fixed problem with CCITT encoding modes as per - bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=483 - - But we need more work on fax codec to support update mode. - -2004-01-30 Frank Warmerdam - - * libtiff/libtiff.def: Added TIFFCurrentDirOffset, TIFFWriteCheck, - TIFFRGBAImageOK, and TIFFNumberOfDirectories as suggested by - Scott Reynolds. - -2004-01-29 Andrey Kiselev - - * libtiff/tiff.h: Fixed tag definitions for TIFFTAG_YCLIPPATHUNITS - and TIFFTAG_INDEXED as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=475 - - * libtiff/{tif_win32.c, tif_unix.c}: Check whether the pointer is - NULL before proceeding further as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=474 - - Check results, returned by the TIFFFdOpen() before returning and close - file if TIFFFdOpen() failed as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=468 - - * libtiff/tif_open.c: More fixes for - - http://bugzilla.remotesensing.org/show_bug.cgi?id=468 - -2004-01-28 Andrey Kiselev - - * libtiff/{libtiff.def, tif_close.c, tiffio.h, tif_open.c}: Separate - TIFFCleanup() from the TIFFClose() in order to fix the bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=468 - - * tools/tiffcp.c: Fixed problem with wrong interpretation of the - InkNames tag as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=466 - - Memory leak fixed. - -2004-01-21 Frank Warmerdam - - * libtiff/tif_dirwrite.c: Fixed handling of writable ASCII tags that - are field_passcount=TRUE properly. Arguably anonymous custom tags - should be declared as passcount=FALSE, but I don't want to change - that without a careful review. - -2004-01-20 Andrey Kiselev - - * libtiff/tif_write.c: Fixed reporting size of the buffer in case of - stripped image in TIFFWriteBufferSetup(). As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=460 - -2004-01-11 Andrey Kiselev - - * libtiff/tif_dir.c: Incomplete cleanup in TIFFFreeDirectory(), - patch from Gerben Koopmans. - - * libtiff/tif_dirread.c: Check field_passcount value before setting - the value of undefined type, patch from Gerben Koopmans. - -2004-01-02 Andrey Kiselev - - * tools/tiffcp.c: Fixed problem with wrong Photometric setting for - non-RGB images. - -2003-12-31 Andrey Kiselev - - * libtiff/tif_win32.c: Fixed problem with _TIFFrealloc() when the NULL - pointer passed. Patch supplied by Larry Grill. - - * libtiff/{tiff.h, tif_fax3.c}:Fixes for AMD 64 platform as - suggested by Jeremy C. Reed. - -2003-12-26 Andrey Kiselev - - * libtiff 3.6.1 released. - -2003-12-24 Andrey Kiselev - - * config.guess, config.sub: Updated from the recent upstream. - -2003-12-22 Andrey Kiselev - - * libtiff/{tif_color, tif_getimage.c, tiffio.h}, man/TIFFcolor.3t: - More cleanups in color conversion interface, added appropriate manual - page. - -2003-12-19 Andrey Kiselev - - * libtiff/{tif_extension.c, tif_dirinfo.c, tiff.h}: Warnings fixed as - per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=357 - - * tools/tiff2ps.c: Added support for alpha channel. Fixes - - http://bugzilla.remotesensing.org/show_bug.cgi?id=428 - - * libtiff/{libtiff.def, tif_color.c, tif_getimage.c, tiffio.h}: - Interface for Lab->RGB color conversion is finally cleaned up. - Added support for ReferenceBlackWhite tag handling when converted from - YCbCr color space. The latter closes - - http://bugzilla.remotesensing.org/show_bug.cgi?id=120 - -2003-12-07 Andrey Kiselev - - * libtiff/{tif_getimage.c, tiffio.h}: Avoid warnings. - - * libtiff/makefile.vc, tools/makefile.vc: Support for IJG JPEG - library. - -2003-12-06 Andrey Kiselev - - * libtiff/{tif_getimage.c, tif_aux.c}: Read WhitePoint tag from the - file and properly use it for CIE Lab->RGB transform. - -2003-12-04 Andrey Kiselev - - * libtiff/{tif_getimage.c, tif_color.c, tiffio.h}: YCbCr->RGB - conversion routines now in the tif_color.c module. New function - TIFFYCbCrtoRGB() available in TIFF API. - - * libtiff/tif_dirwrite.c: Handle TIFF_IFD tag type correctly. - -2003-12-03 Andrey Kiselev - - * libtiff/{tif_getimage.c, tif_color.c, tiffio.h}: Improvements in - CIE Lab conversion code. Start moving YCbCr stuff to the tif_color.c - module. - - * libtiff/{tif_getimage.c, tiffio.h}, man{TIFFReadRGBAImage.3t, - TIFFReadRGBAStrip.3t, TIFFReadRGBATile.3t, TIFFRGBAImage.3t}: - Finally resolved problems with orientation handling. TIFFRGBAImage - interface now properly supports all possible orientations, i.e. images - will be flipped both in horizontal and vertical directions if - required. 'Known bugs' section now removed from the appropriate manual - pages. Closed bug entry: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=322 - -2003-12-02 Andrey Kiselev - - * libtiff/tif_dir.c: Fixed order of the parameters in TIFFError() - function calls as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=440 - -2003-11-28 Ross Finlayson - - * tools/tiff2pdf.c: Some bugs fixed. - -2003-11-27 Andrey Kiselev - - * libtiff/tif_luv.c: Fixed bug in 48-bit to 24-bit conversion routine, - reported by Antonio Scuri. - - * man/tiff2pdf.1: Few improvements in page layout. - - * Makefile.in, /man/Makefile.in, /html/man/tiff2pdf.1.html: - Added support fpr tiff2pdf manual page. - -2003-11-26 Ross Finlayson - - * /man/tiff2pdf.1: File added to repository. - -2003-11-26 Andrey Kiselev - - * Makefile.in, /tools/{Makefile.in, makefile.vc}: - Added support fpr tiff2pdf utility. - -2003-11-25 Ross Finlayson - - * /tools/tiff2pdf.c: File added to repository. - -2003-11-22 Andrey Kiselev - - * /tools/raw2tiff.c: sqrtf() replaced with sqrt(). - -2003-11-21 Andrey Kiselev - - * /tools/raw2tiff.c: #include removed. - - * tools/{Makefile.in, tiffgt.c}: Unmaintained and platform dependent - sgigt utility removed and replaced with the completely rewritten - portable tiffgt tool (depend on OpenGL and GLUT). Initial revision, - there is a lot of things to improve. - - * libtiff/tif_ojpeg.c: TIFFVGetField() function now can properly - extract the fields from the OJPEG files. Patch supplied by Ross - Finlayson. - - * libtiff/{tiffio.h, tif_codec.c}, man/{libtiff.3t, TIFFcodec.3t}: - Added new function TIFFIsCODECConfigured(), suggested by Ross - Finlayson. - -2003-11-18 Andrey Kiselev - - * libtiff/tif_dirinfo.c: Implemented binary search in - _TIFFMergeFieldInfo(). Patch supplied by Ross Finlayson. - - * libtiff/tif_dir.h: _TIFFFindOrRegisterdInfo declaration replaced - with _TIFFFindOrRegisterFieldInfo as reported by Ross Finlayson. - -2003-11-17 Frank Warmerdam - - * tif_dirread.c: do not mark all anonymously defined tags to be - IGNOREd. - -2003-11-17 Andrey Kiselev - - * contrib/pds/{tif_pdsdirread.c, tif_pdsdirwrite.c}: Use - TIFFDataWidth() function insted of tiffDataWidth array. - -2003-11-16 Andrey Kiselev - - * libtiff/{tiff.h, tif_dirinfo.c}: Added support for IFD (13) - datatype, intruduced in "Adobe PageMaker TIFF Tech. Notes". - -2003-11-15 Frank Warmerdam - - * Makefile.in: fixed missing backslash for tif_color.c in list. - -2003-11-13 Andrey Kiselev - - * libtiff/{tif_color.c, tif_getimage.c, tiffio.h, Makefile.in}: - New color space conversion code: CIE L*a*b* 1976 images now supported - by the TIFFRGBAImage interface. All introduced routines go to new - module tif_color.c. Eventually all color conversion functions should - be moved there. - -2003-11-12 Andrey Kiselev - - * tools/{ras2tiff.c, rasterfile.h}: Properly determine SUN Rasterfiles - with the reverse byte order (it is reported by the magic header - field). Problem reported by Andreas Wiesmann. - - * tools/raw2tiff.c, man/raw2tiff.1: Few improvements in correlation - calculation function. Guessing mechanics now documented in manual page. - -2003-11-11 Andrey Kiselev - - * tools/raw2tiff.c: Implemented image size guessing using - correlation coefficient calculation between two neighbour lines. - -2003-11-09 Frank Warmerdam - - * libtiff/tif_tile.c: remove spurious use of "s" (sample) in the - planarconfig_contig case in TIFFComputeTile(). - - http://bugzilla.remotesensing.org/show_bug.cgi?id=387 - -2003-11-09 Andrey Kiselev - - * libtiff/tiffiop.h: New macros: TIFFmax, TIFFmin and TIFFrint. - -2003-11-07 Andrey Kiselev - - * libtiff/{tiffio.h, tif_strip.c}, man/{TIFFstrip.3t, libtiff.3t}: - Added TIFFRawStripSize() function as suggested by Chris Hanson. - -2003-11-03 Andrey Kiselev - - * libtiff/{tif_lzw.c, tif_fax3.c}: Proper support for update mode as - per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=424 - -2003-10-29 Andrey Kiselev - - * libtiff/libtiff.def: Added TIFFReadRGBAImageOriented. - - * html/build.html: Added note about GNU make requirement. - -2003-10-25 Andrey Kiselev - - * Makefile.in: Fixes in using MAKEFLAGS as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=418 - - * port/install.sh.in: Option -p added to the mkdir command to create - all directory tree structure before installing. - -2003-10-18 Andrey Kiselev - - * /tools/tiff2ps.c: #include replaced with the - #include . - -2003-10-16 Andrey Kiselev - - * Makefile.in: Add an absolute path to the test_pics.sh call. - -2003-10-12 Andrey Kiselev - - * libtiff/tiffcomp.h: #define _BSDTYPES_DEFINED when defining BSD - typedefs. - -2003-10-09 Andrey Kiselev - - * configure, libtiff/{Makefile.in, mkversion.c}: - Relative buildings fixed. - - * tools/Makefile.in: Added "-I../libtiff" to the tiffset building - rule. - -2003-10-07 Andrey Kiselev - - * Makefile.in: Added missed v3.6.0.html. - - * libtiff/tiffio.h: Typo fixed: ORIENTATION_BOTTOMLEFT replaced with - ORIENTATION_BOTLEFT. - -2003-10-04 Andrey Kiselev - - * 3.6.0 final release. - -2003-10-03 Andrey Kiselev - - * libtiff/{tif_getimage.c, tiffio.h}, man/TIFFReadRGBAImage.3t: New - function TIFFReadRGBAImageOriented() implemented to retrieve raster - array with user-specified origin position as suggested by Jason Frank. - See - - http://bugzilla.remotesensing.org/show_bug.cgi?id=322 - - for details. - - * tools/tiff2rgba.c: Switched to use TIFFReadRGBAImageOriented() - instead of TIFFReadRGBAImage(). - - * tools/tiff2ps.c: Fixed possible endless loop as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=404 - -2003-09-30 Andrey Kiselev - - * libtiff/tif_dirread.c: Check field counter against number of fields - in order to fix - - http://bugzilla.remotesensing.org/show_bug.cgi?id=366 - - * libtiff/tif_fax3.c: Fix wrong line numbering as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=342 - -2003-09-25 Andrey Kiselev - - * libtiff/{tiffiop.h, tif_dirread.c, tif_dir.c, tif_open.c, - tif_close.c}: Store a list of opened IFD to prevent looping as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=383 - -2003-09-23 Andrey Kiselev - - * libtiff/tif_dirread.c: More fixes for EstimateStripByteCounts(). See - - http://bugzilla.remotesensing.org/show_bug.cgi?id=358 - -2003-08-21 Andrey Kiselev - - * tools/tiffmedian.c: int declaration replaced with the uint32 to - support large images as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=382 - -2003-08-12 Andrey Kiselev - - * libtiff/Makefile.in: Fixed problem with building in different - directory. - - * tools/tiff2ps.c: Added missing #include . - - * libtiff/tif_dirwrite.c: More fixes for custom tags code - from Ashley Dreier. - -2003-08-07 Andrey Kiselev - - * tools/tiff2ps.c: Added page size setting when creating PS Level 2. - Patch submitted by Balatoni Denes (with corrections from Tom - Kacvinsky). - - * tools/tiff2ps.c: Fixed PS comment emitted when FlateDecode is - being used. Reported by Tom Kacvinsky. - - * libtiff/tif_dirwrite.c: Fixed problem with custom tags writing, - reported by Ashley Dreier. - - * libtiff/tif_print.c: Fixed problem with float tags reading, support - for printing RATIONAL and BYTE tags added. - -2003-08-05 Andrey Kiselev - - * libtiff/tif_lzw.c: Move LZW codec state block allocation back to - TIFFInitLZW(), because its initialization in LZWSetupDecode() cause - problems with predictor initialization. Remove O_RDONLY check during - state block allocation to be able open LZW compressed files in update - mode. - - Problem exist for libtiff version of the tif_lzw.c module. One from - lzw-compression-kit hasn't such troubles. - -2003-08-04 Frank Warmerdam - - * libtiff/tif_write.c: modified tif_write.c so that the various - encoded write functions use tif_postdecode() to apply byte order - swapping (swab) to the application passed data buffer if the same - would be done when reading. This allows us to write pixel data with - more than 8 bits per sample to existing files of a non-native byte - order. One side effect of this change is the applications buffer - itself is altered in this case by the act of writing. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=171 - -2003-07-25 Frank Warmerdam - - * libtiff/tif_open.c: avoid signed/unsigned casting warning - initializing typemask as per patch from J.A. Strother. - - * tools/tiffcp.c: fixed signed/unsigned casting warning. - - * libtiff/tif_print.c: dos2unix conversion. - - * tools/tiffsplit.c: increased the maximum number of pages that - can be split. Patch provided by Andrew J. Montalenti. - -2003-07-11 Andrey Kiselev - - * tools/raw2tiff.c: Added option `-p' to explicitly select color - space of input image data. Closes - - http://bugzilla.remotesensing.org/show_bug.cgi?id=364 - -2003-07-08 Frank Warmerdam - - * tif_aux.c, tif_codec.c, tif_dir.c, tif_dirread.c, tif_extension.c, - tif_fax3.c, tif_getimage.c, tif_luv.c, tif_lzw.c, tif_next.c, - tif_packbits.c, tif_predict.c, tif_print.c, tif_swab.c, tif_thunder.c: - avoid casting warning at /W4. - -2003-07-03 Andrey Kiselev - - * tools/thumbnail.c: Memory leak fixed as reported by Robert S. Kissel. - -2003-06-30 Andrey Kiselev - - * libtiff/tif_pixarlog.c: Unused variables removed. - - * libtiff/{tif_dirread.c, tif_dir.c}: Fixed problem with - EstimateStripByteCounts() as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=358 - - * libtiff/{tif_dirwrite.c, tif_packbits.c}: Fixed compilation on - 64-bit architectures as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=357 - - * libtiff/tif_dirinfo.c: TIFFDataWidth() returns 0 in case of - unknown data type. - -2003-06-19 Frank Warmerdam - - * libtiff/tif_print.c: fixed some serious bugs when printing - custom tags ... almost certain to crash. - - * libtiff/tif_dirread.c: Don't ignore custom fields that are - autodefined. Not sure how this got to be like this. - -2003-06-18 Andrey Kiselev - - * 3.6.0 Beta2 released. - - * tools/tiffcmp.c, man/tiffcmp.1: Fixed problem with unused data - comparing as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=349 - - `-z' option now can be used to set the number of reported different - bytes. - -2003-06-09 Andrey Kiselev - - * tools/tiffcp.c, man/tiffcp.1: Added possibility to specify value -1 - to -r option to get the entire image as one strip. See - - http://bugzilla.remotesensing.org/show_bug.cgi?id=343 - - for details. - -2003-06-04 Andrey Kiselev - - * tools/tiffcp.c: Set the correct RowsPerStrip and PageNumber - values as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=343 - -2003-05-27 Frank Warmerdam - - * libtiff/tif_jpeg.c: modified segment_height calculation to always - be a full height tile for tiled images. Also changed error to just - be a warning. - -2003-05-25 Andrey Kiselev - - * tools/fax2tiff.c: Page numbering fixed, as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=341 - -2003-05-20 Andrey Kiselev - - * contrib/ojpeg/{Makefile.in, jdhuff.h, jinclude.h, ojpeg.c, README}, - configure, Makefile.in: Switched back to the old behaviour. Likely - better solution should be found for OJPEG support. - -2003-05-11 Andrey Kiselev - - * libtiff/mkversion.c: Fixed problem with wrong string size when - reading RELEASE-DATE file. - -2003-05-07 Andrey Kiselev - - * tools/tiff2ps.c: Fixed bug in Ascii85EncodeBlock() function: array - index was out of range. - -2003-05-06 Andrey Kiselev - - * contrib/ojpeg/{Makefile.in, jdhuff.h, jinclude.h, ojpeg.c, README}, - configure, Makefile.in: Improved libtiff compilation with OJPEG - support. Now no need for patching IJG JPEG library, hack requred by - libtiff will be compiled and used in-place. Implemented with - suggestion and help from Bill Allombert, Debian's libjpeg maintainer. - - * libtiff/tif_aux.c: Properly handle TIFFTAG_PREDICTOR in - TIFFVGetFieldDefaulted() function. - -2003-05-05 Andrey Kiselev - - * tools/ppm2tiff.c: PPM header parser improved: now able to skip - comments. - - * tools/tiffdither.c: Fixed problem with bit fill order tag setting: - was not copied from source image. - - * libtiff/getimage.c: Workaround for some images without correct - info about alpha channel as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=331 - -2003-04-29 Andrey Kiselev - - * tools/tiff2ps.c, man/tiff2ps.1: Add ability to generate PS Level 3. - It basically allows one to use the /flateDecode filter for ZIP - compressed TIFF images. Patch supplied by Tom Kacvinsky. Fixes - - http://bugzilla.remotesensing.org/show_bug.cgi?id=328 - - * tools/tiff2ps.c: Force deadzone printing when EPS output specified - as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=325 - -2003-04-17 Andrey Kiselev - - * libtiff/tif_dirread.c: Removed additional check for StripByteCounts - due to problems with multidirectory images. Quality of error messages - improved. - -2003-04-16 Andrey Kiselev - - * tools/tiffcp.c: Fixed problem with colorspace conversion for JPEG - encoded images. See bug entries - - http://bugzilla.remotesensing.org/show_bug.cgi?id=275 - - and - - http://bugzilla.remotesensing.org/show_bug.cgi?id=23 - - * libtiff/tif_dirread.c: Additional check for StripByteCounts - correctness. Fixes - - http://bugzilla.remotesensing.org/show_bug.cgi?id=320 - -2003-03-12 Andrey Kiselev - - * tools/{fax2ps.c, fax2tiff.c, gif2tiff.c, pal2rgb.c, ppm2tiff.c, - ras2tiff.c, raw2tiff.c, rgb2ycbcr.c, thumbnail.c, tiff2bw.c, - tiff2ps.c, tiff2rgba.c, tiffcp.c, tiffdither.c, tiffinfo.c, - tiffmedian.c}: Added library version reporting facility to all tools. - -2003-03-06 Frank Warmerdam - - * port/install.sh.in: Fixed problems with install producing paths - like ///usr/local/lib on cygwin. - -2003-02-27 Andrey Kiselev - - * tools/fax2tiff.c, man/fax2tiff.1: New switch (-X) to set width of - raw input page. Patch supplied by Julien Gaulmin. See - - http://bugzilla.remotesensing.org/show_bug.cgi?id=293 - - for details. - -2003-02-26 Frank Warmerdam - - * libtiff/tif_dir.c: fixed up the tif_postdecode settings - responsible for byte swapping complex image data. - - * libtiff/tif_lzw.c: fixed so that decoder state isn't allocated till - LZWSetupDecode(). Needed to read LZW files in "r+" mode. - -2003-02-07 Andrey Kiselev - - * tools/ppm2tiff.c: Fixed problem with too many arguments. - -2003-02-04 Andrey Kiselev - - * tools/raw2tiff.c: Memory leak fixed. - -2003-02-03 Andrey Kiselev - - * tools/fax2tiff.c, man/fax2tiff.1: Applied patch from Julien Gaulmin - (thanks, Julien!). More switches for fax2tiff tool for better control - of input and output. Details at - - http://bugzilla.remotesensing.org/show_bug.cgi?id=272 - -2003-02-03 Frank Warmerdam - - * libtiff/tif_jpeg.c: Modified to defer initialization of jpeg - library so that we can check if there is already any tile/strip data - before deciding between creating a compressor or a decompressor. - -2003-01-31 Frank Warmerdam - - * libtiff/tif_write.c: TIFFWriteCheck() now fails if the image is - a pre-existing compressed image. That is, image writing to - pre-existing compressed images is not allowed. - - * libtiff/tif_open.c: Removed error if opening a compressed file - in update mode. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=198 - -2003-01-31 Andrey Kiselev - - * config.guess, config.sub: Updated to recent upstream versions. - -2003-01-15 Frank Warmerdam - - * cut 3.6.0 Beta release. - -2002-12-20 Andrey Kiselev - - * tools/fax2ps.c, man/fax2ps.1: Page size was determined - in wrong way as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=239 - -2002-12-17 Frank Warmerdam - - * libtiff/tif_dirread.c: Allow wrong sized arrays in - TIFFFetchStripThing(). - - http://bugzilla.remotesensing.org/show_bug.cgi?id=49 - -2002-12-02 Frank Warmerdam - - * libtiff/tif_dir.c: fix problem with test on td_customValueCount. - Was using realloc even first time. Fix by Igor Venevtsev. - -2002-11-30 Frank Warmerdam - - * libtiff/tif_dir.c: fixed bug with resetting an existing custom - field value. - - * libtiff/tif_dir.c: Fixed potential problem with ascii "custom" - tags in TIFFVGetField() ... added missing break. - -2002-10-14 Frank Warmerdam - - * tools/tiff2ps.c: fixes a problem where "tiff2ps -1e" did not make - the scanline buffer long enough when writing rgb triplets. - The scanline needs to be 3 X the number of dots or else it will - contain an incomplete triplet and programs that try to separate - the eps by redefining the colorimage operator will get messed up. - Patch supplied by William Bader. - - * Makefile.in: added tif_extension.c to file list as per - http://bugzilla.remotesensing.org/show_bug.cgi?id=218. - -2002-10-11 Andrey Kiselev - - * configure, config.site, libtiff/{tif_unix.c, Makefile.in}: Fix for - large files (>2GiB) supporting. New option in the config.site: - LARGEFILE="yes". Should be enough for I/O of the large files. - -2002-10-10 Frank Warmerdam - - * libtiff/html/v3.6.0.html: new release notes. - - * libtiff/index.html: removed faq, cvs snapshot cruft. Added email - link for Andrey. Pointer to v3.6.0.html. - - * libtiff/Makefile.in: added direct rule for tiffvers.h for release. - -2002-10-07 Andrey Kiselev - * tools/tiff2ps.c, man/tiff2ps.1: Applied patch form Sebastian Eken - (thanks, Sebastian!). New switches: - -b # for a bottom margin of # inches - -c center image - -l # for a left margin of # inches - -r rotate the image by 180 degrees - New features merged with code for shrinking/overlapping. - Previously added -c and -n switches (for overriding PS units) renamed - in -x and -y respectively. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=200 - - * html/man/*.html: Updated from actual manual pages. - -2002-10-06 Frank Warmerdam - - * libtiff/tif_jpeg.c: fixed problem with boolean defined with wrong - size on windows. Use #define boolean hack. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=188 - - * libtiff/tiff.h: Don't do special type handling in tiff.h unless - USING_VISUALAGE is defined. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=39 - -2002-10-03 Frank Warmerdam - - * libtiff/tiff.h: added COMPRESSION_JP2000. - -2002-10-02 Andrey Kiselev - - * libtiff/tif_dirread.c: Another fix for the fetching SBYTE arrays - by the TIFFFetchByteArray() function. Should finally resolve - - http://bugzilla.remotesensing.org/show_bug.cgi?id=52 - - * configure: Set -DPIXARLOG_SUPPORT option along with -DZIP_SUPPORT - - * html/Makefile.in: New targets added: html and groffhtml for - producing HTML representations of the manual pages automatically. - html target uses man2html tool, groffhtml uses groff tool. - -2002-09-29 Frank Warmerdam - - * configure, libtiff/Makefile.in: Added SCO OpenServer 5.0.6 support - from John H. DuBois III. - -2002-09-15 Andrey Kiselev - - * Makefile.in, /man/{raw2tiff.1, Makefile.in, libtiff.3}: Added - manual page for raw2tiff(1) tool. - -2002-09-12 Andrey Kiselev - - * /libtiff/{tiffio.h, tif_dir.h}: TIFFDataWidth() declaration moved to - the tiffio.h header file. - - * Makefile.in, /man/{TIFFDataWidth.3t, Makefile.in, libtiff.3}: Added - manual page for TIFFDataWidth() function - -2002-09-08 Frank Warmerdam - - * libtiff/tif_dirread.c: Expand v[2] to v[4] in TIFFFetchShortPair() - as per http://bugzilla.remotesensing.org/show_bug.cgi?id=196. - - * tools/tiff2ps.c: Don't emit BeginData/EndData DSC comments - since we are unable to properly include the amount to skip. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=80 - -2002-09-02 Andrey Kiselev - - * /libtiff/tif_dirread.c: Fixed problem with SBYTE type data fetching - in TIFFFetchByteArray(). Problem described at - http://bugzilla.remotesensing.org/show_bug.cgi?id=52 - -2002-08-22 Andrey Kiselev - - * /libtiff/tif_dirinfo.c: Further additions to free custom fields - in _TIFFSetupFieldInfo() function. - See http://bugzilla.remotesensing.org/show_bug.cgi?id=169 for details. - - * /libtiff/tif_lzw.c: Additional consistency checking added in - LZWDecode() and LZWDecodeCompat(). - Fixes http://bugzilla.remotesensing.org/show_bug.cgi?id=190 - and http://bugzilla.remotesensing.org/show_bug.cgi?id=100 - - * /libtiff/tif_lzw.c: - Added check for valid code lengths in LZWDecode() and - LZWDecodeCompat(). Fixes - http://bugzilla.remotesensing.org/show_bug.cgi?id=115 - -2002-08-16 Andrey Kiselev - - * /libtiff/{Makefile.vc, libtiff.def}: - Missed declarations added. - -2002-08-15 Frank Warmerdam - - * tif_getimage.c: Ensure that TIFFRGBAImageBegin() returns the - return code from the underlying pick function. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=177 - - * tif_dir.h: changed FIELD_CODEC to 66 from 64 to avoid overlap - with FIELD_CUSTOM as mentioned in bug 169. - - * tif_close.c: added logic to free dynamically created anonymous - field definitions to correct a small memory leak. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=169 - -2002-08-10 Andrey Kiselev - - * /tools/{raw2tiff.c, Makefile.in, Makefile.lcc, Makefile.vc}: - New tool: raw2tiff --- raw images to TIFF converter. No manual page yet. - -2002-07-31 Frank Warmerdam - - * libtiff/tif_jpeg.c: Fixed problem with setting of nrows in - JPEGDecode() as per bugzilla bug (issue 1): - - http://bugzilla.remotesensing.org/show_bug.cgi?id=129 - - * libtiff/{tif_jpeg.c,tif_strip.c,tif_print.c}: Hacked tif_jpeg.c to - fetch TIFFTAG_YCBCRSUBSAMPLING from the jpeg data stream if it isn't - present in the tiff tags. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=168 - - * libtiff/tif_read.c, libtiff/tif_write.c: TIFFReadScanline() and - TIFFWriteScanline() now set tif_row explicitly in case the codec has - fooled with the value. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=129 - -2002-06-22 Andrey Kiselev - - * /tools/tiff2ps.c: Added workaround for some software that may crash - when last strip of image contains fewer number of scanlines than - specified by the `/Height' variable. See - http://bugzilla.remotesensing.org/show_bug.cgi?id=164 - for explanation. - -2002-06-21 Andrey Kiselev - - * tools/tiff2ps, man/tiff2ps.1: New functionality for tiff2ps utility: - splitting long images in several pages. See - http://bugzilla.remotesensing.org/show_bug.cgi?id=142 for explanation. - Patch granted by John Williams . - -2002-06-11 Frank Warmerdam - - * libtiff/contrib/win95: renamed to contrib/win_dib. Added new - Tiffile.cpp example of converting TIFF files into a DIB on Win32. - This one is described in: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=143 - - * libtiff/tif_ojpeg.c: Major upgrade from Scott. See details at: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=156 - -2002-05-10 Andrey Kiselev - - * tools/tiff2ps: New commandline switches to override resolution - units obtained from the input file. Closes - http://bugzilla.remotesensing.org/show_bug.cgi?id=131 - -2002-04-26 Andrey Kiselev - - * libtiff/libtiff.def: Added missed declaration. - -2002-04-22 Andrey Kiselev - - * tools/fax2tiff.c: Updated to reflect latest changes in libtiff. - Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=125 - -2002-04-20 Andrey Kiselev - - * libtiff/tif_open.c: Pointers to custom procedures - in TIFFClientOpen() are checked to be not NULL-pointers. - -2002-04-18 Andrey Kiselev - - * libtiff/libtiff.def: Added missed declarations. - - * libtiff/tif_pixarlog.c: Updated for using tif_tagmethods structure. - -2002-04-16 Andrey Kiselev - - * libtiff/tif_lzw.c: Additional checks for data integrity introduced. - Should finally close - http://bugzilla.remotesensing.org/show_bug.cgi?id=100 - -2002-04-10 Andrey Kiselev - - * tools/tiff2ps: Division by zero fixed. - Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=88 - -2002-04-09 Andrey Kiselev - - * libtiff/: tif_dirwrite.c, tif_write.c, tiffio.h: - TIFFCheckpointDirectory() routine added. - Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=124 - - * man/: TIFFWriteDirectory.3t, Makefile.in: Added description - for the new function. - -2002-04-08 Andrey Kiselev - - * libtiff/: tif_codec.c, tif_compress.c, tiffiop.h: Introduced - additional members tif->tif_decodestatus and tif->tif_encodestatus - for correct handling of unconfigured codecs (we should not try to read - data or to define data size without correct codecs). - - * libtiff/tif_getimage.c: The way of codecs checking in TIFFRGBAImageOK - changed. Now it has used tif->tif_decodestatus and - tif->tif_encodestatus. - Should fix http://bugzilla.remotesensing.org/show_bug.cgi?id=119 (in - case of __cvs_8.tif test image). - - * libtiff/: tif_dirinfo.c, tif_dirread.c: Somebody makes a bug in - tif_dirread.c when TIFFCreateAnonFieldInfo was introduced. - Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=119 in case - of _cvs_00000-00.tif, _cvs_00000-01.tif and _cvs_00000-02.tif. - -2002-04-04 Andrey Kiselev - - * libtiff/: tif_lzw.c: Assertions in LZWDecode and LZWDecodeCompat - replaced by warnings. Now libtiff should read corrupted LZW-compressed - files by skipping bad strips. - Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=100 - -2002-04-03 Frank Warmerdam - - * libtiff/tif_dirwrite.c: Removed some dead code. - - * libtiff/*: Cleanup some warnings. - - * libtiff/tif_dir.c: Fixed bug with count returned by TIFFGetField() - for variable length FIELD_CUSTOM values. Was int * but should be - u_short *. - -2002-04-01 Andrey Kiselev - - * tools/: tifcp.c: Added support for 'Orientation' tag in tiffcp - utility (at cpStripToTile routine). - -2002-03-27 Frank Warmerdam - - * tif_dirread.c: avoid div-by-zero if rowbytes is zero in chop func. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=111 - - * tif_print.c: Fixed so that ASCII FIELD_CUSTOM values with - passcount set FALSE can be printed (such as TIFFTAG_SOFTWARE). - - * libtiff/tif_dir.c,tif_dirinfo.c,tif_dir.h,tif_ojpeg.c: modified so - that TIFFTAG_SOFTWARE uses FIELD_CUSTOM as an example. - -2002-03-26 Dwight Kelly - - * libtiff/: tiff.h, tif_dir.c, tif_dir.h, tif_dirinfo.c, tif_dirread.c, - tif_dirwrite.c: Added get/put code for new tag XMLPACKET as defined - in Adobe XMP Technote. Added missing INKSET tag value from TIFF 6.0 spec - INKSET_MULTIINK (=2). Added missing tags from Adobe TIFF technotes: - CLIPPATH, XCLIPPATHUNITS, YCLIPPATHUNITS, OPIIMAGEID, OPIPROXY and - INDEXED. Added PHOTOMETRIC tag value from TIFF technote 4 ICCLAB (=9). - -2002-03-26 Andrey Kiselev - - * libtiff/: tif_getimage.c: TIFFReadRGBAStrip and TIFFReadRGBATile - now also uses TIFFRGBAImageOK before reading. This is additional fix - for http://bugzilla.remotesensing.org/show_bug.cgi?id=110 - -2002-03-25 Andrey Kiselev - - * libtiff/: tif_getimage.c: Additional check for supported - codecs added in TIFFRGBAImageOK and TIFFReadRGBAImage now uses - TIFFRGBAImageOK before reading. - Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=110 - -2002-03-15 Andrey Kiselev - - * libtiff/: tif_dir.c, tif_dir.h, tif_dirinfo.c, tif_dirread.c, - tif_dirwrite.c: Added routine TIFFDataWidth for detrmining - TIFFDataType sizes instead of working with tiffDataWidth array - directly. Should prevent out-of-borders bugs in case of unknown or - broken data types. EstimateStripByteCounts routine modified, so it - won't work when tags with uknown sizes founded. - Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=109 - -2002-03-13 Andrey Kiselev - - * libtiff/tif_getimage.c: Added support for correct handling - `Orientation' tag in gtTileContig. Should be added in other gt* - functions as well, but I have not images for testing yet. Partially - resolves http://bugzilla.remotesensing.org/show_bug.cgi?id=23 - -2002-03-10 Andrey Kiselev - - * libtiff/: tif_dirinfo.c, tif_dirwrite.c: Added possibility to - read broken TIFFs with LONG type used for TIFFTAG_COMPRESSION, - TIFFTAG_BITSPERSAMPLE, TIFFTAG_PHOTOMETRIC. Closes - http://bugzilla.remotesensing.org/show_bug.cgi?id=99 - -2002-03-08 Andrey Kiselev - - * libtiff/Makefile.in, tools/Makefile.in: Shared library will not - be stripped when installing, utility binaries will do. Closes - http://bugzilla.remotesensing.org/show_bug.cgi?id=93 - -2002-02-28 Frank Warmerdam - - * man/TIFFGetField: fixed type of TIFFTAG_COPYRIGHT. - - * man/libtiff.3t: added copyright tag info. - -2002-02-11 Frank Warmerdam - - * libtiff/{tiff.h,tif_fax3.c}: Add support for __arch64__. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=94 - - * man/Makefile.in: Patch DESTDIR handling - - http://bugzilla.remotesensing.org/show_bug.cgi?id=95 - - * configure: OpenBSD changes for Sparc64 and DSO version. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=96 - -2002-02-05 Frank Warmerdam - - * config.site/configure: added support for OJPEG=yes option to enable - OJPEG support from config.site. - -2002-01-27 Frank Warmerdam - - * html/document.html: fixed links for TIFf 6 docs. - -2002-01-18 Frank Warmerdam - - * config.guess, config.sub: Updated from ftp.gnu.org/pub/config. - - * libtiff/tif_read.c: Fixed TIFFReadEncodedStrip() to fail if the - decodestrip function returns anything not greater than zero as per - http://bugzilla.remotesensing.org/show_bug.cgi?id=97 - - * configure: Modify CheckForBigEndian so it can work in a cross - compiled situation. - -2002-01-16 Frank Warmerdam - - * tools/tiffdump.c: include TIFFTAG_JPEGTABLES in tag list. - - * tools/tiffset.c: fix bug in error reporting. - - * tools/tiffcp.c: fix several warnings that show up with -Wall. - -2002-01-04 Frank Warmerdam - - * libtiff/tif_jpeg.c: fixed computation of segment_width for - tiles files to avoid error about it not matching the - cinfo.d.image_width values ("JPEGPreDecode: Improper JPEG strip/tile - size.") for ITIFF files. Apparently the problem was incorporated since - 3.5.5, presumably during the OJPEG/JPEG work recently. - -2001-12-15 Frank Warmerdam - - * configure, libtiff/Makefile.in: Changes for building on MacOS 10.1. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=94 - - * libtiff/tif_getimage.c: If DEFAULT_EXTRASAMPLE_AS_ALPHA is 1 - (defined in tiffconf.h - 1 by default) then the RGBA interface - will assume that a fourth extra sample is ASSOCALPHA if the - EXTRASAMPLE value isn't set for it. This changes the behaviour of - the library, but makes it work better with RGBA files produced by - lots of applications that don't mark the alpha values properly. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=93 - http://bugzilla.remotesensing.org/show_bug.cgi?id=65 - -2001-12-12 Frank Warmerdam - - * libtiff/tif_jpeg.c: allow jpeg data stream sampling values to - override those from tiff directory. This makes this work with - ImageGear generated files. - -2001-12-07 Frank Warmerdam - - * html/Makefile.in: added missing images per bug 92. - - * port/Makefile.in: fixed clean target per bug 92. - -2001-11-28 Frank Warmerdam - - * Reissue 3.5.7 release. - - * libtiff/mkversion.c: Fix output of TIFF_VERSION to be - YYYYMMDD so that it is increasing over time. - - * Makefile.in: Ensure that tiffvers.h is regenerated in the - make release target. - - * Makefile.in: added libtiff/tiffvers.h to the release file list. - -2001-11-23 Frank Warmerdam - - * added html/v3.5.7.html, updated html/index.html. - - * Makefile.in: added contrib/addtiffo/tif_ovrcache.{c,h}. - -2001-11-15 Frank Warmerdam - - * configure: fixed test for -lm. - -2001-11-02 Frank Warmerdam - - * Added PHOTOMETRIC_ITULAB as per bug 90. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=90 - -2001-10-10 Frank Warmerdam - - * libtiff/tiff.h: I have created COMPRESSION_CCITT_T4, - COMPRESSION_CCITT_T6, TIFFTAG_T4OPTIONS and TIFFTAG_T6OPTIONS aliases - in keeping with TIFF 6.0 standard in tiff.h - - http://bugzilla.remotesensing.org/show_bug.cgi?id=83 - -2001-09-26 Frank Warmerdam - - * libtiff/tif_dirwrite.c: added TIFFRewriteDirectory() function. - Updated TIFFWriteDirectory man page to include TIFFRewriteDirectory. - -2001-09-24 Frank Warmerdam - - * libtiff/tif_lzw.c: Avoid MS VC++ 5.0 optimization bug. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=78 - - * libtiff/tif_lzw.c: added dummy LZWSetupEncode() to report an - error about LZW not being available. - - * libtiff/tif_dir.c: propagate failure to initialize compression - back from TIFFSetField() as an error status, so applications can - detect failure. - - * libtiff/tif_dir.c: removed the auto replacement of - COMPRESSION_LZW with COMPRESSION_NONE in _TIFFVSetField(). - - * Removed Makefile, tools/Makefile, port/install.sh, man/Makefile - from CVS as they are all supposed to be auto-generated by configure. - -2001-09-22 Frank Warmerdam - - * libtiff/tif_ojpeg.c: new update from Scott. - -2001-09-09 Frank Warmerdam - - * libtif/tif_fax3.c: Removed #ifdef PURIFY logic, and modified to - always use the "safe" version, even if there is a very slight - cost in performance. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=54 - - * libtiff/Makefile.in: Fixed @DSOSUB_VERSION to be @DSOSUF_VERSION@ - in two places. - - * libtiff/tif_getimage.c: Fixed problem with reading strips or - tiles that don't start on a tile boundary. Fix contributed by - Josep Vallverdu (from HP), and further described in bug 47. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=47 - - * tools/tiff2ps.c: added OJPEG YCbCr to RGB support. - - * libtiff/tif_ojpeg.c: Applied substantial patch from Scott. - -2001-09-06 Frank Warmerdam - - * libtiff/tif_packbits.c: fixed memory overrun error. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=77 - -2001-08-31 Frank Warmerdam - - * libtiff/tif_getimage.c: relax handling of contig case where - there are extra samples that are supposed to be ignored. This - should now work for 8bit greyscale or palletted images. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=75 - -2001-08-28 Frank Warmerdam - - * libtiff/tif_getimage.c: Don't complain for CMYK (separated) - images with more than four samples per pixel. See: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=73 - -2001-08-10 Frank Warmerdam - - * libtiff/tif_getimage.c: Use memmove() instead of TIFFmemcpy() - in TIFFReadRGBATile() to avoid issues in cases of overlapping - buffers. See Bug 69 in Bugzilla. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=69 - - * tools/tiff2rgba.c: fixed getopt() call so that -b works again. - -2001-08-09 Frank Warmerdam - - * libtiff/tiff.h, libtiff/tif_fax3.c: added check for __LP64__ - when checking for 64 bit architectures as per bugzilla bug 67. - -2001-07-27 Frank Warmerdam - - * man/Makefile.in: add TIFFClientOpen link as per debian submitted - bug 66. - -2001-07-20 Frank Warmerdam - - * libtiff/tif_jpeg.c: Define HAVE_BOOLEAN on windows if RPCNDR.H - has been included. - -2001-07-19 Frank Warmerdam - - * libtiff/tif_open.c: Seek back to zero after failed read, - before writing header. - -2001-07-18 Frank Warmerdam - - * libtiff/tif_ojpeg.c: updates from Scott. Handles colors - much better. Now depends on having patched libjpeg as per - patch in contrib/ojpeg/*. - -2001-07-17 Frank Warmerdam - - * */Makefile.in: added DESTDIR support. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=60 - -2001-07-16 Frank Warmerdam - - * configure, libtiff/Makefile.in: applied OpenBSD patches - as per: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=61 - -2001-06-28 Frank Warmerdam - - * libtiff/tif_getimage.c: Fixed so that failure is properly - reported by gtTileContig, gtStripContig, gtTileSeparate and - gtStripSeparate. - - See http://bugzilla.remotesensing.org/show_bug.cgi?id=51 - - * tiffcmp.c: Fixed multi samples per pixel support for ContigCompare. - Updated bug section of tiffcmp.1 to note tiled file issues. - - See http://bugzilla.remotesensing.org/show_bug.cgi?id=53 - -2001-06-22 Frank Warmerdam - - * configure: Changes for DSO generation on AIX provided by - John Marquart . - - * configure, libtiff/Makeifle.in: Modified to build DSOs properly - on Darwin thanks to Robert Krajewski (rpk@alum.mit.edu) and - Keisuke Fujii (fujiik@jlcuxf.kek.jp). - -2001-06-13 Frank Warmerdam - - * tools/tiff2rgba.c: added -n flag to avoid emitting alpha component. - - * man/tiff2rgba.1: new - -2001-05-22 Frank Warmerdam - - * Added tiffset and tif_ojpeg to the dist lists in Makefile.in. - -2001-05-13 Frank Warmerdam - - * libtiff/tools/thumbnail.c: changed default output compression - to packbits from LZW since LZW isn't generally available. - -2001-05-12 Frank Warmerdam - - * libtiff/tif_ojpeg.c: New. - libtiff/tif_jpeg.c, tiffconf.h, tif_getimage.c: changes related - to OJPEG support. - - Scott Marovich supplied OJPEG support. - -2001-05-11 Frank Warmerdam - - * tiff.h: removed, it duplicates libtiff/tiff.h. - -2001-05-08 Frank Warmerdam - - * libtiff/tif_dirinfo.c: moved pixar and copyright flags to - ensure everything is in order. - - * libtiff/libtiff.def: added TIFFCreateDirectory and - TIFFDefaultStripSize as per: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=46 - -2001-05-02 Frank Warmerdam - - * libtiff/tif_dirinfo.c: Modified the TIFF_BYTE definition for - TIFFTAG_PHOTOSHOP to use a writecount of TIFF_VARIABLE2 (-3) to - force use of uint32 counts instead of short counts. - - * libtiff/tif_dirwrite.c: Added support for TIFF_VARIABLE2 in the - case of writing TIFF_BYTE/TIFF_SBYTE fields. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=43 - -2001-05-01 Frank Warmerdam - - * libtiff/tif_dirinfo.c: removed duplicate TIFFTAG_PHOTOSHOP as per - bug report http://bugzilla.remotesensing.org/show_bug.cgi?id=44 - -2001-04-05 Frank Warmerdam - - * tiffio.h: removed C++ style comment. - - * configure: fixed up SCRIPT_SH/SHELL handling. - - * Makefile.in: Fixed SCRIPT_SH/SHELL handling. - - * config.guess: documented more variables as per bug 40. - -2001-04-03 Frank Warmerdam - - * configure, *Makefile.in: Various changes to improve configuration - for HP/UX specifically, and also in general. They include: - - Try to handle /usr/bin/sh instead of /bin/sh where necessary. - - Upgrade to HP/UX 10.x+ compiler, linker and dso options. - - Fixed mmap() test to avoid MMAP_FIXED ... it isn't available on HP - - Use -${MAKEFLAGS} in sub makes from makefiles. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=40 - -2001-04-02 Frank Warmerdam - - * libtiff/tiff.h: Applied hac to try and resolve the problem - with the inttypes.h include file on AIX. - - See http://bugzilla.remotesensing.org/show_bug.cgi?id=39 - - * VERSION: update to 3.5.7 beta in preparation for release. - - * configure/config.site: modified to check if -lm is needed for - MACHDEPLIBS if not supplied by config.site. Needed for Darwin. - - * config.guess: updated wholesale to an FSF version apparently - from 1998 (as opposed to 1994). This is mainly inspired by - providing for MacOS X support. - -2001-03-29 Frank Warmerdam - - * configure, Makefile.in, etc: added support for OPTIMIZER being - set from config.site. - -2001-03-28 Frank Warmerdam - - * fax2ps.c: Helge (libtiff at oldach.net) submitted fix: - - Here's a fix for fax2ps that corrects behaviour for non-Letter paper - sizes. It fixes two problems: - - Without scaling (-S) the fax is now centered on the page size specified - with -H and/or -W. Before, fax2ps was using an obscure and practially - useless algorithm to allocate the image relative to Letter sized paper - which sometime sled to useless whitespace on the paper, while at the - same time cutting of the faxes printable area at the opposite border. - - Second, scaling now preserves aspect ratio, which makes unusual faxes - (in particular short ones) print properly. - - See http://bugzilla.remotesensing.org/show_bug.cgi?id=35 - - * tiff2ps.c/tiff2ps.1: Substantial changes to tiff2ps by - Bruce A. Mallett. See check message for detailed information - on all the changes, including a faster encoder, fixes for level - 2 PostScript, and support for the imagemask operator. - -2001-03-27 Frank Warmerdam - - * libtiff/tiffio.h: Changed "#if LOGLUV_PUBLIC" to - "#ifdef LOGLUV_PUBLIC" so it will work with VisualAge on AIX. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=39 - -2001-03-16 Frank Warmerdam - - * tif_dirinfo.c: moved definition of copyright tag in field list. - Apparently they have to be in sorted order by tag id. - -2001-03-13 Frank Warmerdam - - * tif_getimage.c: Added support for 16bit minisblack/miniswhite - images in RGBA interface. - -2001-03-02 Frank Warmerdam - - * Added TIFFTAG_COPYRIGHT support. - -2001-02-19 Frank Warmerdam - - * Brent Roman contributed updated tiffcp utility (and tiffcp.1) - with support for extracting subimages with the ,n syntax, and also - adding the -b bias removal flag. - -2001-02-16 Frank Warmerdam - - * libtiff/libtiff.def: Brent Roman submitted new version adding - serveral missing entry points. - - * libtiff/tif_dirinfo.c: don't declare tiffFieldInfo static on VMS. - Some sort of weird VMS thing. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=31 - - * tif_luv.c/tiff.h/tiffio.h: - New version of TIFF LogLuv (SGILOG) modules contributed by Greg Ward - (greg@shutterfly.com). He writes: - - 1) I improved the gamut-mapping function in tif_luv.c for imaginary - colors, because some images were being super-saturated on the input - side and this resulted in some strange color shifts in the output. - - 2) I added a psuedotag in tiff.h to control random dithering during - LogLuv encoding. This is turned off by default for 32-bit LogLuv and - on for 24-bit LogLuv output. Dithering improves the average color - accuracy over the image. - - 3) I added a #define for LOG_LUV_PUBLIC, which is enabled by default in - tiffio.h, to expose internal routines for converting between LogLuv and - XYZ coordinates. This is helpful for writing more efficient, - specialized conversion routines, especially for reading LogLuv files. - - Changes applied with minor edits. - -2001-01-23 Frank Warmerdam - - * tif_fax3.c: keep rw_mode flag internal to fax3 state to remember - whether we are encoding or decoding. This is to ensure graceful - recovery if TIFFClientOpen() discovers an attempt to open a compressed - file for "r+" access, and subsequently close it, as it resets the - tif_mode flag to O_RDONLY in this case to avoid writes, confusing the - compressor's concept of whether it is in encode or decode mode. - -2001-01-08 Mike Welles - - * Makefile.in: Now cleaning up after itself after creating the .tar.gz and .zip - -2001-01-07 Frank Warmerdam - - * html/libtiff.html: Fixed arguments in example for TIFFRGBAImageGet() - as per bug report by Patrick Connor. - -2000-12-28 Frank Warmerdam - - * Added RELEASE-DATE file to release file list. - - * Fixed libtiff/makefile.vc to make tiffvers.h not version.h. - -2000-12-22 Mike Welles - * added link to CVS mirror from index.html - - * updated html/internals.html to note that LZW compression is - not supported by default. - -2000-12-22 Frank Warmerdam - - * updated html/libtiff.html to not point at Niles' old JPL web site - for the man pages, point at www.libtiff.org. - -2000-12-21 Frank Warmerdam - - * libtiff/tif_apple.c: Applied "Carbon" support patches supplied by - Leonard Rosenthol . May interfere - with correct building on older systems. If so, please let me know. - -2000-12-19 Mike Welles - - * Took out LZW Encoding from tif_lzw.c - - * Created HOWTO-RELEASE - - * Created html/v3.5.6.html - - * updated index.html - -2000-12-01 Frank Warmerdam - - * Added patches for EOFB support in tif_fax3.c and tif_fax3.h. - Patches supplied by Frank Cringle - Example file at: ftp://ftp.remotesensing.org/pub/libtiff/eofb_396.tif - -2000-11-24 Frank Warmerdam - - * libtiff/Makefile.in: Added an installPrivateHdrs and install-private - target so that the private headers required by libgeotiff can be - installed with the others. They are not installed by default. - - * libtiff/Makefile.in: Added @MACHLIBDEPS@ to LINUXdso and GNULDdso - targets so libtiff.so will be built with an explicit dependency - on libm.so. - - * libtiff/Makefile.in: Use softlinks to link libtiff.so.3 to - libtiff.so.3.5.5. - - * libtiff/Makefile.in & configure: Remove all references to the ALPHA - file, or ALPHA version logic. Added stuff about DIST_POINT in - place of DIST_TYPE and the alpha release number stuff. - -2000-11-22 Frank Warmerdam - - * I have applied a patch from Steffen Moeller to - the configure script so that it now accepts the --prefix, and - --exec-prefix directives. - -2000-11-13 Frank Warmerdam - - * I have made a variety of modifications in an effort to ensure the - TIFFLIB_VERSION macro is automatically generated from the RELEASE-DATE - file which seems to be updated regularly. - - o mkversion.c now reads RELEASE-DATE and emits TIFFLIB_VERSION in - version include file. - o renamed version.h to tiffvers.h because we now have to install it - with the public libtiff include files. - o include tiffvers.h in tiffio.h. - o updated tif_version.c to use tiffvers.h. - o Updated Makefile.in accordingly. - - * As per http://bugzilla.remotesensing.org/show_bug.cgi?id=25 - I have updated the win32 detection rules in tiffcomp.h. - -2000-10-20 Frank Warmerdam - - * tif_getimage.c: Fixed RGBA translation for YCbCr images for which - the strip/tile width and height aren't multiples of the sampling size. - See http://bugzilla.remotesensing.org/show_bug.cgi?id=20 - Some patches from Rick LaMont of Dot C Software. - - * Modified tif_packbits.c encoder to avoid compressing more - data than provided if rowsize doesn't factor into provided data - (such as occurs for YCbCr). - -2000-10-19 Frank Warmerdam - - * tools/rgb2ycbcr.c: fixed output strip size to account for vertical - roundup if rows_per_strip not a multiple of vertical sample size. - -2000-10-16 Frank Warmerdam - - * tif_dir.c: Clear TIFF_ISTILED flag in TIFFDefaultDirectory - as per http://bugzilla.remotesensing.org/show_bug.cgi?id=18 - from vandrove@vc.cvut.cz. - - * Modified tif_packbits.c decoding to avoid overrunning the - output buffer, and to issue a warning if data needs to be - discarded. See http://bugzilla.remotesensing.org/show_bug.cgi?id=18 - -2000-10-12 Frank Warmerdam - - * Modified tiff2bw to ensure portions add to 100%, and that - white is properly recovered. - - See bug http://bugzilla.remotesensing.org/show_bug.cgi?id=15 - Patch c/o Stanislav Brabec - -2000-09-30 Frank Warmerdam - - * Modified TIFFClientOpen() to emit an error on an attempt to - open a comperessed file for update (O_RDWR/r+) access. This is - because the compressor/decompressor code gets very confused when - the mode is O_RDWR, assuming this means writing only. See - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=13 - -2000-09-27 Frank Warmerdam - - * Added GNULDdso target an`d switched linux and freebsd to use it. - -2000-09-26 Frank Warmerdam - - * Applied patch for 0x0000 sequences in tif_fax3.h's definition - of EXPAND1D() as per bug 11 (from Roman). - -2000-09-25 Frank Warmerdam - * Fixed tiffcomp.h to avoid win32 stuff if unix #defined, to improve - cygwin compatibility. - - * Applied patch from Roman Shpount to tif_fax3.c. This seems to - be a proper fix to the buffer sizing problem. See - http://bugzilla.remotesensing.org/show_bug.cgi?id=11 - - * Fixed tif_getimage.c to fix overrun bug with YCbCr images without - downsampling. http://bugzilla.remotesensing.org/show_bug.cgi?id=10 - Thanks to Nick Lamb for reporting the - bug and proving the patch. - -2000-09-18 Frank Warmerdam - - * Fixed tif_jpeg.c so avoid destroying the decompressor before - we are done access data thanks to bug report from: - Michael Eckstein . - - * Reverted tif_flush change. - -2000-09-14 Frank Warmerdam - - * tif_flush.c: Changed so that TIFFFlushData() doesn't return an - error when TIFF_BEENWRITING is not set. This ensures that the - directory contents can still be flushed by TIFFFlush(). - -2000-08-14 Frank Warmerdam - - * tif_open.c: Don't set MMAP for O_RDWR files. - - * tif_open.c: Set STRIPCHOP_DEFAULT for O_RDWR as well as O_RDONLY - so that files opened for update can be strip chopped too. - - * tif_read.c: fixed up bug with files missing rowsperstrip and - the strips per separation fix done a few weeks ago. - -2000-07-17 Frank Warmerdam - - * Tentatively added support for SAMPLEFORMAT_COMPLEXIEEEFP, and - SAMPLEFORMAT_COMPLEXINT. - -2000-07-13 Mike Welles - - * index.html, bugs.html: added bugzilla info. - -2000-07-12 Frank Warmerdam - - * tif_read.c: fix subtle bug with determining the number of - rows for strips that are the last strip in a separation but - not the last strip of all in TIFFReadEncodedStrip(). - - * Applied 16/32 bit fix to tif_fax3.c. Fix supplied by - Peter Skarpetis - -2000-06-15 Frank Warmerdam - - * Modified tiffio.h logic with regard to including windows.h. It - won't include it when building with __CYGWIN__. - -2000-05-11 Frank Warmerdam - - * README: update to mention www.libtiff.org, don't list Sam's old - email address. - - * configure: Fixed DSO test for Linux as per patch from - Jan Van Buggenhout . - -2000-04-21 Frank Warmerdam - - * libtiff/tif_dirread.c: Don't use estimate strip byte count for - one tile/strip images with an offset, and byte count of zero. These - could be "unpopulated" images. - -2000-04-18 Frank Warmerdam - - * contrib/addtiffo: Added "averaging" resampling option. - - * tools/tiffsplit.c: Copy TIFFTAG_SAMPLEFORMAT. - -Tue Apr 18 16:18:08 2000 Frank Warmerdam - - * tools/Makefile.in: Modified to install properly on SGI. - -2000-04-12 Mike Welles - * configure: Fixed stupid mistake in libc6 test on Linux - -2000-04-04 Mike Welles - * tif_win32.c: Applied patch to fix overreads and ovverwrites - caught by BoundsChecker. From Arvan Pritchard - (untested). - - * tif_getimage.c: Applied patch to silence VC6 warnings. From - Arvan Pritchard - - * tif_lzw.c: Applied patch to silence VC6 warnings. From - Arvan Pritchard - -2000-03-28 Frank Warmerdam - - * Added contrib/stream (stream io) code submitted by Avi Bleiweiss. - -2000-03-28 Frank Warmerdam *** 3.5.5 release *** - - * fax2ps: Fixed mixup of width and height in bounding box statement - as per submission by Nalin Dahyabhai . - -2000-03-27 Mike Welles - - * fax2ps: Modified printruns to take uint32 instead of uint16. - Patch courtesy of Bernt Herd - -2000-03-20 Mike Welles - - * configure: added test for libc6 for linux targets. Bug reported by - Stanislav Brabec - - * Added 3.5 docs to html/Makefile.in. - Thanks to Stanislav Brabec - - * configure: fixed bugs in sed scripts - (applied sed script s:/@:s;@:;s:/s;;:;: to configure). - fix submitted to Stanislav Brabec - - * tools/iptcutil was not in files list, and wasn't being - added to tar archive. Updated Makefile.in. - -2000-03-17 Frank Warmerdam - - * tif_fax3.c: Fixed serious bug introduced during the uint16->uint32 - conversion for the run arrays. - -2000-03-03 Frank Warmerdam - - * Set td_sampleformat default to SAMPLEFORMAT_UINT instead of - SAMPLEFORMAT_VOID in TIFFDefaultDirectory() in tif_dir.c. - -2000-03-02 Frank Warmerdam - - * Added "GetDefaulted" support for TIFFTAG_SAMPLEFORMAT in tif_aux.c. - - * Patched tif_fax3.c so that dsp->runs is allocated a bit bigger - to avoid overruns encountered with frle_bug.tif. - -Tue Feb 15 22:01:05 2000 Frank Warmerdam - - * Fixed tools/tiffcmp so that stopondiff testing works. - Patch care of Joseph Orost . - -2000-01-28 - - * Modified tif_unix.c to support 2-4GB seeks if USE_64BIT_API is - set to 1, and added default (off) setting in tiffconf.h. This - should eventually be set by the configure script somehow. - - The original work on all these 2-4GB changes was done by - Peter Smith (psmith@creo.com). - - * Modified tif_win32.c to support 2-4GB seeks. - - * tentatively changed toff_t to be unsigned instead of signed to - facilitate support for 2-4GB files. - - * Updated a variety of files to use toff_t. Fixed some mixups - between toff_t and tsize_t. - -Fri Jan 28 10:13:49 2000 Frank Warmerdam - - * Largely reimplemented contrib/addtiffo to avoid temp files, - updating the TIFF file in place. Fixed a few other bugs to. - - * Set tif_rawdatasize to zero when freeing raw data buffer in - TIFFWriteDirectory(). - - * Enabled "REWRITE_HACK" in tif_write.c by default. - - * Fix bug in tif_write.c when switching between reading one directory - and writing to another. - - * Made TIFFWriteCheck() public, and added TIFFCreateDirectory() - -Wed Jan 5 12:37:48 2000 Frank Warmerdam - - * Added TIFFmemory(3t) functions to libtiff.def. - -Tue Jan 4 13:39:00 2000 Frank Warmerdam - - * Added libtiff/libtiff.def to TIFFILES distribution list. - -Mon Dec 27 12:13:39 EST 1999 Mike Welles - - * Created lzw compression kit, as a new module (libtiff-lzw-compression-kit). - - * Altered descriptions in tools to reflect "by default" lzw not supported - - * Updated index.html to note lzw compression kit. - -Tue Dec 21 14:01:51 1999 Frank Warmerdam - - * Added fax3sm_winnt.c to distribution list in Makefile.in. - -Tue Dec 21 11:04:45 EST 1999 Mike Welles *** 3.5.4 release *** - - * Aadded Pixar tag support. Contributed by Phil Beffery - - * Made one more change to tif_dir.c for removal of LZW compression. Also added notice - when LZW compression invoked. - - * Changed default compression in tools to TIFF_PACKBITS, and changed usage descriptions - in tools to reflect removal of LZW compression - -Mon Dec 20 18:39:02 EST 1999 Mike Welles - - * Fixed bug that caused LZW (non) compression to segfault. Added - warning about LZW compression removed being removed, and why. - - * Added nostrip to install in tools/Makefile.in so that debugging - symbols are kept. - -Tue Dec 7 12:04:47 EST 1999 Mike Welles - - * Added patch from Ivo Penzar , - supporting Adobe ZIP deflate. Untested. - -Sat Dec 4 15:47:11 1999 Frank Warmerdam - - * Made Packbits the default compression in tools/tiff2rgba.c instead - of LZW. - -Tue Nov 30 14:41:43 1999 Frank Warmerdam *** 3.5.3. release *** - - * Added tif_luv to contrib/djgpp/Makefile.lib. - -Tue Nov 30 14:15:32 EST 1999 Mike Welles - - * Added zip creation to relase makefile target - - * Added html for TIFFWriteTile.3t man page. - -Tue Nov 30 09:20:16 1999 Frank Warmerdam - - * Added some changes to tif_write.c to support rewriting existing - fixed sized tiles and strips. Code mods disabled by default, only - enabled if REWRITE_HACK is defined for now. - -Mon Nov 29 11:43:42 1999 Frank Warmerdam - - * Added TIFFWriteTile.3t man page. - -Sun Nov 28 20:36:18 1999 Frank Warmerdam - - * Added notes on use of makefile.vc in build.html, and fixed - email subscription address. - -199-11-28 Mike Welles - - * Fixed apocalypse-inducing y2k bug in contrib/ras/ras2tiff.c - - * Did some casts cleaning up to reduce compiler warnings in tif_fax3.c, - from Bruce Carmeron -- modifications of - changes made by Frank (sun cc still complained on cast). - - * Added tiffconf.h to install target per request from Bill - Radcliffe : "We need a way for ImageMagick to - know features have been compiled into the TIFF library in order to - handle things properly". - -Sat Nov 27 16:49:21 1999 Frank Warmerdam - - * fixed various VC++ warnings as suggested by Gilles Vollant - . - -Wed Nov 24 12:08:16 1999 Frank Warmerdam - - * Modified TIFFquery.3t man pages info on TIFFIsByteSwapped() to - not imply applications are responsible for image data swapping. - -1999-11-22 Mike Welles - * HTML-ized the man pages, added to html/man - - * Removed LZW Compression to comply with Unisys patent extortion. - -1999-09-29 Mike Welles - * Corrected one remaining 16 -> 32 bit value in tif_fax3.c, - From Ivo Penzar - -1999-09-26 Mike Welles *** 3.5.2 release *** - * Corrected alpha versioning. - - * Removed distinction between alpha and release targets in Makefile.in. - - * added release.stamp target, which tags cvs tree, and updates - "RELEASE-DATE" - - * added releasediff target, which diffs tree with source as of - date in "RELEASE-DATE" - - * Ticked up version to 3.5.2 (alpha 01 -- but I think we'll moving - away from alpha/non-alpha distinctions). - - * updated html to reflect release - -1999-09-23 - - * Set O_BINARY for tif_unix.c open() ... used on cygwin for instance. - - * Added CYGWIN case in configure. - -Fri Sep 17 00:13:51 CEST 1999 Mike Welles - - * Applied Francois Dagand's patch to handle fax decompression bug. - (sizes >= 65536 were failing) - -Tue Sep 14 21:31:43 1999 Frank Warmerdam - - * Applied "a" mode fix to tif_win32.c/TIFFOpen() as suggested - by Christopher Lawton - -Wed Sep 8 08:19:18 1999 Frank Warmerdam - - * Added IRIX/gcc, and OSF/1 4.x support on behalf of - Albert Chin-A-Young - - * Added TIFFReassignTagToIgnore() API on behalf of - Bruce Cameron . Man page still pending. - -Wed Aug 25 11:39:07 1999 Frank Warmerdam - - * Added test target in Makefile, test_pics.sh script and pics/*.rpt - files to provide for a rudimentary testsuite. - - * Added contrib/tags back from old distribution ... fixed up a bit. - -1999-08-16 - - * Added simple makefile.vc makefiles for building with MS VC++ - on Windows NT/98/95 in console mode. Stuff in contrib/win* make give - better solutions for some users. - -Mon Aug 16 21:52:11 1999 Frank Warmerdam - - * Added addtiffo (add overviews to a TIFF file) in contrib. Didn't - put it in tools since part of it is in C++. - -1999-08-16 Michael L. Welles - - * Updated html/index.html with anon CVS instructions. - -Mon Aug 16 13:18:41 1999 Frank Warmerdam - - * pre-remove so link before softlink in LINUXdso action in - libtiff/Makefile.in to avoid failure on LINUXdso builds other than - the first. - - * Fixed problem with cvtcmap() in tif_getimage.c modifying the - colormaps owned by the TIFF handle itself when trying to fixup wrong - (eight bit) colormaps. Corrected by maintaining a private copy of - the colormap. - - * Added TIFFReadRGBATile()/TIFFReadRGBAStrip() support in - tif_getimage.c. - - * CVS Repository placed at remotesensing.org. ChangeLog added. +2011-04-09 Bob Friesenhahn + + * libtiff 3.9.5 released. + +2011-04-09 Bob Friesenhahn + + * configure.ac: Should use AC_CANONICAL_HOST since host specifies + the run-time target whereas target is used to specify the final + output target if the package is a build tool (like a compiler), + which libtiff is not. Resolves libtiff bug 2307 "Use + AC_CANONICAL_HOST macro". + +2011-04-02 Bob Friesenhahn + + * tools/fax2ps.c (main): Use tmpfile() rather than mkstemp() since + it is much more portable. Tmpfile is included in ISO/IEC + 9899:1990 and the WIN32 CRT. + +2011-03-21 Frank Warmerdam + + * libtiff/tiffiop.h: avoid declaring int64/uint64 on AIX with XLC + where they are already available. (#2301) + + * libtiff/tif_thunder.c: Correct potential buffer overflow with + thunder encoded files with wrong bitspersample set. The libtiff + development team would like to thank Marin Barbella and TippingPoint's + Zero Day Initiative for reporting this vulnerability (ZDI-CAN-1004, + CVE-2011-1167). + http://bugzilla.maptools.org/show_bug.cgi?id=2300 + +2011-03-10 Frank Warmerdam + + * libtiff/tif_fax3.h: Fix to last change allowing zero length + runs at the start of a scanline - needed for legal cases. + +2011-03-02 Frank Warmerdam + + * libtiff/tif_fax3.h: Protect against a fax VL(n) codeword commanding + a move left. Without this, a malicious input file can generate an + indefinitely large series of runs without a0 ever reaching the right + margin, thus overrunning our buffer of run lengths. Per CVE-2011-0192. + This is a modified version of a patch proposed by Drew Yao of Apple + Product Security. It adds an unexpected() report, and disallows the + equality case, since emitting a run without increasing a0 still allows + buffer overrun. + +2011-02-25 Andrey Kiselev + + * libtiff/tif_dirwrite.c: Avoid undefined behaviour when casting from + float to unsigned integer in TIFFWriteRationalArray() as reported by + Kareem Shehata. + +2011-01-03 Lee Howard + + * libtiff/tif_jpeg.c: Fix regressions with 2 and 3 band images + caused by commit on 2010-12-14. Submitted by e-mail from + Even Rouault + +2010-12-31 Olivier Paquet + + * libtiff/tif_dirread.c: Allow reading directories where + TIFFTAG_SMINSAMPLEVALUE and TIFFTAG_SMAXSAMPLEVALUE values differ for each + channel. The min/max of all channels is used as appropriate. + +2010-12-14 Lee Howard + + * libtiff/tif_dirread.c: tolerate some cases where + FIELD_COLORMAP is missing + http://bugzilla.maptools.org/show_bug.cgi?id=2189 + +2010-12-14 Lee Howard + + * libtiff/tif_strip.c: use TIFFGetFieldDefaulted instead + of TIFFGetField when we assume that it will succeed + http://bugzilla.maptools.org/show_bug.cgi?id=2215 + +2010-12-14 Lee Howard + + * tools/gif2tiff.c: fix buffer overrun + http://bugzilla.maptools.org/show_bug.cgi?id=2270 + +2010-12-14 Lee Howard + + * libtiff/tif_jpeg.c: reduce usage of JCS_UNKNOWN in order + to improve compatibility with various viewers + submitted by e-mail from Dwight Kelly + +2010-12-13 Lee Howard + + * tools/fax2ps.c: be consistent with page-numbering + http://bugzilla.maptools.org/show_bug.cgi?id=2225 + +2010-12-13 Lee Howard + + * libtiff/tif_dirread.c: fix needless tag ordering warning + http://bugzilla.maptools.org/show_bug.cgi?id=2210 + +2010-12-13 Lee Howard + + * libtiff/tif_color.c: prevent crash in handling bad TIFFs + resolves CVE-2010-2595 + http://bugzilla.maptools.org/show_bug.cgi?id=2208 + +2010-12-13 Lee Howard + + * tools/tiffcrop.c: new release by Richard Nolde + http://bugzilla.maptools.org/show_bug.cgi?id=2004 + +2010-12-12 Lee Howard + + * tools/tiff2pdf.c: fix colors for images with RGBA + interleaved data + http://bugzilla.maptools.org/show_bug.cgi?id=2250 + +2010-12-11 Lee Howard + + * tools/tiff2pdf.c: remove invalid duplication for Lab + http://bugzilla.maptools.org/show_bug.cgi?id=2162 + +2010-12-11 Lee Howard + + * libtiff/tif_jpeg.c: fix use of clumplines calculation + http://bugzilla.maptools.org/show_bug.cgi?id=2149 + +2010-12-11 Lee Howard + + * tools/fax2ps.c: replace unsafe tmpfile() with mkstemp() + http://bugzilla.maptools.org/show_bug.cgi?id=2118 + +2010-12-11 Lee Howard + + * tools/tiff2pdf.c: add fill-page option + http://bugzilla.maptools.org/show_bug.cgi?id=2051 + +2010-12-11 Lee Howard + + * libtiff/tif_dirread.c: modify warnings + http://bugzilla.maptools.org/show_bug.cgi?id=2016 + +2010-12-11 Lee Howard + + * libtiff/tif_ojpeg.c: fix buffer overflow on problem data + http://bugzilla.maptools.org/show_bug.cgi?id=1999 + +2010-12-11 Lee Howard + + * libtiff/tif_ojpeg.c: fix crash when reading a TIFF with a zero + or missing byte-count tag + * tools/tiffsplit.c: abort when reading a TIFF without a byte-count + per http://bugzilla.maptools.org/show_bug.cgi?id=1996 + +2010-12-08 Lee Howard + + * libtiff/tif_dirread.c: fix crash when reading a badly-constructed + TIFF per http://bugzilla.maptools.org/show_bug.cgi?id=1994 + +2010-12-07 Lee Howard + + * libtiff/tif_jpeg.c, libtiff/tif_strip.c: apply patch for + CVE-2010-3087 per bug + http://bugzilla.maptools.org/show_bug.cgi?id=2140 + +2010-12-06 Lee Howard + + * libtiff/tif_open.c: Fix mode check before opening a file. + http://bugzilla.maptools.org/show_bug.cgi?id=1906 + +2010-09-25 Lee Howard + + * tools/tiff2ps.c: improvements and enhancements from Richard Nolde + with additional command line options for Document Title, + Document Creator, and Page Orientation + +2010-07-13 Bob Friesenhahn + + * tools/tiffcrop.c: Patch from Richard Nolde to avoid a + potentially unterminated buffer due to using an exceptionally long + file name. + +2010-07-08 Andrey Kiselev + + * tools/tiff2pdf.c: Fixed ID buffer filling in + t2p_write_pdf_trailer(), thanks to Dmitry V. Levin. + +2010-07-07 Andrey Kiselev + + * libtiff/tif_dirread.c: Really reset the tag count in CheckDirCount() + to expected value as the warning message suggests. As per bug + http://bugzilla.maptools.org/show_bug.cgi?id=1963 + + * tools/tiffdump.c: Avoid integer overflows computing the buffer size + for large directories. As per bug + http://bugzilla.maptools.org/show_bug.cgi?id=2218 + +2010-07-06 Andrey Kiselev + + * tools/tiffset.c: Properly handle TIFFTAG_PAGENUMBER, + TIFFTAG_HALFTONEHINTS, TIFFTAG_YCBCRSUBSAMPLING, TIFFTAG_DOTRANGE + which should be set by value. + + * libtiff/tif_dirinfo.c: Don't use assertions in _TIFFFieldWithTag() + and _TIFFFieldWithName() if the tag is not found in the tag table. + This should be normal situation and returned NULL value should be + properly handled by the caller. + + * libtiff/{tif_dirwrite.c, tif_print.c}: Properly handle "DotRange" + tag as it can be either byte or short size and should be set and read + by value, not as an array. As per bug + http://bugzilla.maptools.org/show_bug.cgi?id=2116 + +2010-07-02 Andrey Kiselev + + * libtiff/tif_getimage.c: Avoid wrong math du to the signed/unsigned + integer type conversions. As per bug + http://bugzilla.maptools.org/show_bug.cgi?id=2207 + + * tools/{tiff2bw.c, thumbnail.c, pal2rgb.c}: Fix the count for + WhitePoint tag as per bug + http://bugzilla.maptools.org/show_bug.cgi?id=2042 + + * tools/tiffdump.c: Use PrintData() function instead of + PrintByte/Short/Long(). Should fix an issue reported at + http://bugzilla.maptools.org/show_bug.cgi?id=2116 + + * libtiff/tif_getimage.c: Check the number of samples per pixel when + working with YCbCr image in PickContigCase(). As per bug + http://bugzilla.maptools.org/show_bug.cgi?id=2216 + + * libtiff/tif_dir.c: Set the bogus post-decoding hook when processing + TIFFTAG_BITSPERSAMPLE in _TIFFVSetField() for the case of 8 bit when + we don't need any post-processing. That helps to reset the hook if we + previously set this field to some other value and the hook was + initialized accordingly. As per bug + http://bugzilla.maptools.org/show_bug.cgi?id=2035 + +2010-06-30 Andrey Kiselev + + * tools/tiff2pdf.c: Better generation of ID field in + t2p_write_pdf_trailer(). Get rid of GCC aliasing warnings. + + * tools/tiff2pdf.c: Fixed computation of the tile buffer size when + converting JPEG encoded tiles. + + * tools/tiff2pdf.c: Better handling of string fields, use static + string buffers instead of dynamically allocated, use strncpy() instead + of strcpy(), control the string lengths. + +2010-06-25 Andrey Kiselev + + * tools/tiffcp.c: Initialize buffer arrays with zero to avoid + referencing to uninitialized memory in some cases (e.g. when tile size + set bigger than the image size). + +2010-06-15 Bob Friesenhahn + + * tools/tiffcrop.c: Patch from Richard Nolde. Reject YCbCr + subsampled data since tiffcrop currently doesn't support it. Fix + JPEG support. + +2010-06-15 Bob Friesenhahn + + * libtiff 3.9.4 released. + +2010-06-13 Frank Warmerdam + + * libtiff/tif_jpeg.c: avoid re-preparing jpeg tables unnecessarily + (gdal #3633, libtiff #2135). + + * libtiff/tif_dirread.c: Fixed bad handling of out of order tags + definated late by a codec (#2210) + + * libtiff/tif_dirread.c: Fixed inadequate validation of the + SubjectDistance field (#2212). + + * tiff2pdf.c: Fix assorted bugs in tiff2pdf: missing "return" + in t2p_read_tiff_size() causes t2p->tiff_datasize to be set entirely + wrong for COMPRESSION_JPEG case, resulting in memory stomp if actual + size is larger. Also, there are a bunch of places that try to + memset() a malloc'd buffer before checking for malloc failure, which + would result in core dump if there actually were a failure. (#2211) + +2010-06-11 Bob Friesenhahn + + * tools/tiff2rgba.c: Applied portion of patch (from Tom Lane) + which was left out in order to fully resolve "CVE-2009-2347 + libtiff: integer overflows in various inter-color space conversion + tools". http://bugzilla.maptools.org/show_bug.cgi?id=2079 + + * libtiff/tiffiop.h (TIFFSafeMultiply): Need more castings to + avoid compiler warnings if parameter types are not sign + consistent. + + * tools/tiffcrop.c: Applied patch from Richard Nolde: Corrected + European page size dimensions. Added an option to allow the user + to specify a custom page size on the command line. Fix the case + where a page size specified with a fractional part was being + coerced to an integer by retyping the variables that define the + paper size. + + * libtiff 3.9.3 released. + + * tools/tiffcp.c (tiffcp): Applied Tom Lane's patch to reject + YCbCr subsampled data since tiffcp currently doesn't support it. + http://bugzilla.maptools.org/show_bug.cgi?id=2097 + + * Update libtool to version 2.2.10. + +2010-06-10 Bob Friesenhahn + + * libtiff/tiffiop.h (TIFFSafeMultiply): Work properly if + multiplier is zero. + +2010-06-09 Bob Friesenhahn + + * libtiff/tif_dir.h: Restore ReferenceBlackWhite as a non-custom + field. This avoids a multi-thread reentrancy problem as well as + fixing output of wrong tag value due to redundant definitions for + the same tag in the tiffFieldInfo[] array. Resolves + http://bugzilla.maptools.org/show_bug.cgi?id=2185 + + * libtiff/tif_fax3.c (Fax3SetupState): Yesterday's fix for + CVE-2010-1411 was not complete. + + * libtiff/tiffiop.h (TIFFSafeMultiply): New macro to safely + multiply two integers. Returns zero if there is an integer + overflow. + + * tools/tiffcp.c (main): Fix more TIFF handle leaks. + + * libtiff/tif_read.c (TIFFReadBufferSetup): Skip allocating + tif_rawdata if tif_rawdatasize becomes zero. + +2010-06-08 Bob Friesenhahn + + * tools/tiffcrop.c: Removed duplicated macros such as + TIFFhowmany(). + + * Update libtool to version 2.2.8. + + * libtiff/tif_fax3.c (Fax3SetupState): Avoid under-allocation of + buffer due to integer overflow in TIFFroundup() and several other + potential overflows. In conjunction with the fix to TIFFhowmany(), + fixes CVE-2010-1411. + + * libtiff/tiffiop.h (TIFFhowmany): Return zero if parameters would + result in an integer overflow. This causes TIFFroundup() to also + return zero if there would be an integer overflow. + + * libtiff/tif_read.c (TIFFReadBufferSetup): Return an error if + tif_rawdatasize becomes zero due to an initial raw size of zero or + an overflow reported by TIFFroundup(). + + * libtiff/tif_ojpeg.c (OJPEGReadBufferFill): Report an error and + avoid a crash if the input file is so broken that the strip + offsets are not defined. + + * tools/tiffcp.c (main): tiffcp should not leak memory if an error + is reported when reading the input file. + + * libtiff/tif_aux.c (_TIFFCheckRealloc): Produce a fully detailed + error message string. + + * Add an emacs formatting mode footer to all source files so that + emacs can be effectively used. + +2010-06-03 Oliver Chen Feng + + * libtiff/tools/tiffcp.c: add a new option -x to force merged tiff + file PAGENUMBER value in sequence for users who care the page + sequence, this will also prevent tiff2pdf from creating pdf file from + the merged tiff file with wrong page sequence. + +2010-05-07 Frank Warmerdam + + * libtiff/tif_jpeg.c: Ensure that quality is always set in + JPEGPreEncode(), not just when we want to output local tables. + Otherwise the quality used during compression may not be right and + might not match the tables in the tables tag. This bug only occurs + when seeking between directories in the midst of writing blocks. + http://trac.osgeo.org/gdal/ticket/3539 + +2010-05-05 Olivier Paquet + + * libtiff/tif_print.c: Have TIFFTAG_REFERENCEBLACKWHITE always print 6 + floats instead of 2*SamplesPerPixel. + http://bugzilla.maptools.org/show_bug.cgi?id=2186 + * man/TIFFGetField.3tiff, man/TIFFSetField.3tiff: Fixed doc to reflect the + fact that libtiff considers TIFFTAG_REFERENCEBLACKWHITE to be 6 floats. + +2010-04-10 Bob Friesenhahn + + * tools/ppm2tiff.c (main): While case for parsing comment line + requires extra parenthesis to work as expected. Reported by + Thomas Sinclair. + +2010-02-22 Lee Howard + + * libtiff/tif_jpeg.c: Do not generate a JPEGTables tag when creating + the JPEG TIFF as is is not required in order to prevent it from + being unused and filled with invalid data. (Leave it to be + generated by later activity.) + http://bugzilla.maptools.org/show_bug.cgi?id=2135 + * tools/tiff2pdf.c: Write the JPEG SOI headers into the TIFF strip + data rather than skipping them. This fixes the ability to view in + Acrobat Reader, Evince, and Ghostscript. + http://bugzilla.maptools.org/show_bug.cgi?id=2135 + * libtiff/tif_fax3.c: Don't return error on badly-terminated MMR + strips. + http://bugzilla.maptools.org/show_bug.cgi?id=2029 + +2010-01-06 Frank Warmerdam + + * libtiff/tif_dir.c: Ensure tile and scanline sizes are reset + when moving to new directories. + http://bugzilla.maptools.org/show_bug.cgi?id=1936 + +2009-12-03 Frank Warmerdam + + * libtiff/tif_jpeg.c: Fix a couple of issues that trigger failures in + some cases when using TIFFReadScanline() with JPEG compressed + subsampled ycbcr images. + http://bugzilla.maptools.org/show_bug.cgi?id=1936 + +2009-11-04 Bob Friesenhahn + + * libtiff 3.9.2 released. + +2009-11-03 Bob Friesenhahn + + * tools/tiffcrop.c: Updated tiffcrop from Richard Nolde. This + version has undergone substantial testing with arbitrary sample + bit depths. Also eliminates GCC compilation warnings. + +2009-11-02 Bob Friesenhahn + + * port/libport.h: Added header file for porting prototypes and + extern declarations. + +2009-10-31 Bob Friesenhahn + + * libtiff/tif_dirwrite.c (TIFFWriteAnyArray): Add missing break + statement so writing an array of TIFF_DOUBLE works. + +2009-10-29 Bob Friesenhahn + + * libtiff/tif_dirread.c: Eliminate GCC "dereferencing type-punned + pointer" warnings. + +2009-10-28 Bob Friesenhahn + + * html/tools.html: Add manual page links, and a summary + description of tiffcrop. + +2009-10-07 Bob Friesenhahn + + * configure.ac: x86_64 should use the same fill order as i386. + +2009-09-24 Bob Friesenhahn + + * tools/tiffcrop.c, man/tiffcrop.1: New tiffcrop from Richard + Nolde. Major updates to add significant functionality for reading + and writing tile based images with bit depths not a multiple of 8 + which cannot be handled by tiffcp. + +2009-09-03 Bob Friesenhahn + + * libtiff/tif_ojpeg.c (OJPEGWriteHeaderInfo): IJG JPEG 7 needs + do_fancy_upsampling=FALSE in order to read raw data. Resolves + "Bug 2090 - OJPEG crash with libjpeg v7". + http://bugzilla.maptools.org/show_bug.cgi?id=2090 + +2009-08-30 Bob Friesenhahn + + * contrib/iptcutil/iptcutil.c, + libtiff/tif_getimage.c,libtiff/tif_jpeg.c,libtiff/tif_ojpeg.c,tools/tiffcrop.c,tools/tiffgt.c: + Applied patch from Oden Eriksson to allow building with GCC using + the "-Wformat -Werror=format-security" flags. + +2009-08-28 Bob Friesenhahn + + * libtiff 3.9.1 released. + +2009-08-28 Frank Warmerdam + + * libtiff/tif_dirwrite.c: Back out changes from 2007-11-22 that + resulted in the final strip not being written in some circumstances. + http://bugzilla.maptools.org/show_bug.cgi?id=2088 + +2009-08-27 Bob Friesenhahn + + * libtiff/tif_write.c (TIFFAppendToStrip): Remove cast which + caused libtiff to output a wrong last strip with byte-count and + strip-offset of zero. This cast was added on the day of the 3.9.0 + release. + + * libtiff/tif_config.vc.h: tiffiop.h needs the TIFF_INT64_T and + TIFF_UINT64_T defines in order to compile. Copy existing + definitions from tiffconf.vc.h. + +2009-08-21 Bob Friesenhahn + + * test/Makefile.am (AUTOMAKE_OPTIONS): Colorized tests was not + actually activated since it needed to be enabled in this + Makefile.am. Also activated parallel-tests mode since it offers + useful features such as per-test .log files and a summary test + report .log file. + +2009-08-20 Bob Friesenhahn + + * libtiff 3.9.0 released. + + * libtiff/tif_print.c (TIFFPrintDirectory): Applied patch for "tag + error may cause segfault in tif_print.c." + http://bugzilla.maptools.org/show_bug.cgi?id=1896 + + * tools/{rgb2ycbcr.c, tiff2rgba.c}: Applied patch for + CVE-2009-2347 libtiff: integer overflows in various inter-color + space conversion tools. + http://bugzilla.maptools.org/show_bug.cgi?id=2079 + + * configure.ac: Updated autotools. Autoconf 2.64, Automake 1.11, + libtool 2.2.6. Enabled support for silent build rules + (--enable-silent-rules or 'make V=0') and colorized tests. + +2009-06-30 Frank Warmerdam + + * libtiff/tif_luv.c: correct return codes from encoderow to be + 1 on success instead of zero. + http://bugzilla.maptools.org/show_bug.cgi?id=2069 + +2009-06-22 Frank Warmerdam + + * libtiff/tif_lzw.c: Fix buffer underflow bug. + http://bugzilla.maptools.org/show_bug.cgi?id=2065 + +2009-06-03 Frank Warmerdam + + * libtiff/tif_write.c: do not override the planar configuration to be + contig for one sample files if planar configuration is already set. + http://bugzilla.maptools.org/show_bug.cgi?id=2057 + +2009-02-12 Frank Warmerdam + + * libtiff/tif_luv.c: Fix handling of tiled logluv images. + http://bugzilla.maptools.org/show_bug.cgi?id=2005 + +2009-01-23 Frank Warmerdam + + * libtiff/tif_predict.c: Add support for 32bit integer horz. predictors. + http://bugzilla.maptools.org/show_bug.cgi?id=1911 + +2009-01-20 Frank Warmerdam + + * tools/tiffsplit.c: fix sampleformat to be shortv instead of longv. + +2009-01-12 Bob Friesenhahn + + * tools/tiff2ps.c: Remove spurious message printed to stderr. + +2009-01-11 Bob Friesenhahn + + * tools/tiff2ps.c: Incorporated significant functionality update + from Richard Nolde. In particular, support for rotating the image + by 90, 180, 270, and 'auto' has been added. + + * tools/tiffcrop.c: Incorporated significant functionality update + from Richard Nolde. + +2009-01-06 Bob Friesenhahn + + * libtiff/tiffiop.h: Add private type declarations for int64, and + uint64 so that bundled utilities (like tiffcrop) can use it when + necessary. + +2009-01-01 Bob Friesenhahn + + * configure.ac: Updated to test for 64-bit types. This version of + the library does not require a 64-bit type, but tiffcrop needs it. + +2008-12-31 Bob Friesenhahn + + * Update to use current FSF autotools versions. + * libtiff/tiffio.h: GCC will now validate format specifications + for TIFFError(), TIFFErrorExt(), TIFFWarning(), and + TIFFWarningExt() in order to reveal bugs. Cleaned up resulting + warnings throughout for 32 bit build only. + +2008-12-31 Frank Warmerdam + + * tools/tiffcrop.c, man/tiffcrop.1: A major update from Richard + Nolde. + +2008-12-21 Frank Warmerdam + + * libtiff/tif_jpeg.c: Avoid errors if the application writes a full + strip for the last partial strip in a jpeg compressed file. + http://bugzilla.maptools.org/show_bug.cgi?id=1981 + +2008-12-21 Frank Warmerdam + + * libtiff/tif_getimage.c, tiffio.h: More ABI corrections. + Removed SubsamplingHor/Ver from TIFFRGBAImage structure. + http://bugzilla.maptools.org/show_bug.cgi?id=1980 + +2008-12-18 Frank Warmerdam + + * libtiff/tif_getimage.c,tiffio.h: removed all use of UaToAa and + Bitmap16to8 arrays in TIFFRGBAImage structure to restore ABI + compatability. These were just an attempt to speed up processing + with precalculated tables. + http://bugzilla.maptools.org/show_bug.cgi?id=1979 + + * libtiff/tif_codec.c: Avoid printing c->name if it does not exist. + +2008-10-21 Andrey Kiselev + + * libtiff/tif_jbig.c: Support the JBIG-KIT 2.0 (compatibility with + the older versions retained). + +2008-09-05 Andrey Kiselev + + * tools/tiffsplit.c: Use dynamically allocated array instead of static + when constructing output file names. + +2008-09-03 Andrey Kiselev + + * tools/tiffsplit.c: Get rid of unsafe strcpy()/strcat() calls when + doing the filename/path construction. + + * tools/tiff2pdf.c: More appropriate format string in + t2p_write_pdf_string(); avoid signed/unsigned mismatch. + + * libtiff/tif_lzw.c: Properly zero out the codetable. As per bug + + http://bugzilla.maptools.org/show_bug.cgi?id=1929 + + * libtiff/tif_lzw.c: Properly zero out the string table. Fixes + CVE-2008-2327 security issue. + +2008-05-24 Frank Warmerdam + + * tif_codec.c: Avoid NULL pointer dereferencing for exotic + compression codec codes. + + * tif_dirread.c: zero tif->tif_dir after freeing the directory + in TIFFReadCustomDirectory(). I don't exactly remember why this + was important. + + * tif_dirwrite.c: Fix potential memory leak writing large double + tags. + + * tif_dirread.c: Fix unchecked malloc result. + +2008-01-30 Andrey Kiselev + + * tif_fax3.c: Make find0span() and find1span() non-inline to + make MSVC 6.0 compiler happy. + +2007-11-26 Frank Warmerdam + + * tif_fax3.c: fix leak of FAXCS state (per bug 1603). + +2007-11-23 Andrey Kiselev + + * configure.com, libtiff/tif_vms.c: Better OpenVMS support. Patches + from Alexey Chupahin. + +2007-11-22 Frank Warmerdam + + * tif_write.c: Rip out the fancy logic in TIFFAppendToStrip() for + establishing if an existing tile can be rewritten to the same location + by comparing the current size to all the other blocks in the same + directory. This is dangerous in many situations and can easily + corrupt a file. (observed in esoteric GDAL situation that's hard to + document). This change involves leaving the stripbytecount[] values + unaltered till TIFFAppendToStrip(). Now we only write a block back + to the same location it used to be at if the new data is the same + size or smaller - otherwise we move it to the end of file. + + * tif_dirwrite.c: Try to avoid writing out a full readbuffer of tile + data when writing the directory just because we have BEENWRITING at + some point in the past. This was causing odd junk to be written out + in a tile of data when a single tile had an interleaving of reading + and writing with reading last. (highlighted by gdal + autotest/gcore/tif_write.py test 7. + + * tif_predict.c: use working buffer in PredictorEncodeTile to avoid + modifying callers buffer. + http://trac.osgeo.org/gdal/ticket/1965 + + * tif_predict.c/h, tif_lzw.c, tif_zip.c: Improvements so that + predictor based encoding and decoding works in read-write update + mode properly. + http://trac.osgeo.org/gdal/ticket/1948 + +2007-10-05 Frank Warmerdam + + * tools/tiff2pdf.c: Fixed setting of alpha value per report on list. + +2007-09-13 Frank Warmerdam + + * tif_dirinfo.c: _TIFFMergeFields() now only merges in field + definitions that are missing. Existing definitions are silently + ignored. (Bug #1585) + +2007-07-18 Andrey Kiselev + + * libtiff/{Makefile.am, Makefile.v}: Do not distribute tiffconf.h, + remove tif_config.h/tiffconf.h during cleaning. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1573 + +2007-07-13 Andrey Kiselev + + * libtiff 3.9.0beta released. + +2007-07-12 Andrey Kiselev + + * tools/tiff2pdf.c: Added missed extern optind as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1567 + +2007-07-03 Andrey Kiselev + + * tools/tiff2ps.c: Added support 16-bit images as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1566 + + Patch from William Bader. + + * tools/tiff2pdf.c: Fix for TIFFTAG_JPEGTABLES tag fetching and + significant upgrade of the whole utility as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1560 + + Now we don't need tiffiop.h in tiff2pdf anymore and will open output + PDF file using TIFFClientOpen() machinery as it is implemented + by Leon Bottou. + +2007-06-29 Bob Friesenhahn + + * libtiff/tif_dirinfo.c (_TIFFFindFieldInfo): Don't attempt to + bsearch() on a NULL fieldinfo list. + (_TIFFFindFieldInfoByName): Don't attempt to + lfind() on a NULL fieldinfo list. + +2007-05-01 Andrey Kiselev + + * libtiff/tif_dirwrite.c: Fixed problem introduced with a fix for a + byte swapping issue + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1363 + + As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1550 + +2007-04-27 Andrey Kiselev + + * tools/tiff2pdf.c: Check the tmpfile() return status as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=154 + +2007-04-07 Andrey Kiselev + + * libtiff/{tif_dir.h, tif_dirread.c, tif_dirinfo.c, tif_jpeg.c, + tif_fax3.c, tif_jbig.c, tif_luv.c, tif_ojpeg.c, tif_pixarlog.c, + tif_predict.c, tif_zip.c}: Finally fix bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1274 + + by introducing _TIFFMergeFieldInfo() returning integer error status + instead of void in case of problems with field merging (e.g., if the + field with such a tag already registered). TIFFMergeFieldInfo() in + public API remains void. Use _TIFFMergeFieldInfo() everywhere and + check returned value. + +2007-04-07 Frank Warmerdam + + * contrib/addtiffo/tif_overview.c: Fix problems with odd sized output + blocks in TIFF_DownSample_Subsampled() (bug 1542). + +2007-04-06 Frank Warmerdam + + * libtiff/tif_jpeg.c: Changed JPEGInitializeLibJPEG() so that it + will convert from decompressor to compressor or compress to decompress + if required by the force arguments. This works around a problem in + where the JPEGFixupTestSubsampling() may cause a decompressor to + be setup on a directory when later a compressor is required with the + force flag set. Occurs with the addtiffo program for instance. + +2007-04-06 Andrey Kiselev + + * libtiff/tif_dirwrite.c: Fixed swapping of byte arrays stored + in-place in tag offsets as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1363 + + * tools/tiffcrop.c, man/tiffcrop.1: Significant update in + functionality from Richard Nolde. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1525 + +2007-03-28 Frank Warmerdam + + * libtiff/tif_fax3.c: "inline static" -> "static inline" for IRIC CC. + +2007-03-07 Joris Van Damme + + * libtiff/tif_getimage.c: workaround for 'Fractional scanline' error reading + OJPEG images with rowsperstrip that is not a multiple of vertical subsampling + factor. This bug is mentioned in: + http://bugzilla.remotesensing.org/show_bug.cgi?id=1390 + http://www.asmail.be/msg0054766825.html + +2007-03-07 Joris Van Damme + + * libtiff/tif_win32.c: made inclusion of windows.h unconditional + + * libtiff/tif_win32.c: replaced preprocessor indication for consiously + unused arguments by standard C indication for the same + +2007-02-27 Andrey Kiselev + + * libtiff/tif_dirread.c: Use uint32 type instead of tsize_t in byte + counters in TIFFFetchData(). Should finally fix the issue + + http://bugzilla.remotesensing.org/show_bug.cgi?id=890 + +2007-02-24 Andrey Kiselev + + * tools/tiffset.c: Properly handle tags with TIFF_VARIABLE writecount. + As per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1350 + + * libtiff/tif_dirread.c: Added special function to handle + SubjectDistance EXIF tag as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1362 + + * tools/tiff2pdf.c: Do not assume inches when the resolution units + do not specified. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1366 + + * tools/{tiffcp.c, tiffcrop.c}: Do not change RowsPerStrip value if + it was set as infinite. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1368 + + * tools/tiffcrop.c, man/tiffcrop.1: New tiffcrop utility contributed + by Richard Nolde. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1383 + +2007-02-22 Andrey Kiselev + + * libtiff/tif_dir.c: Workaround for incorrect TIFFs with + ExtraSamples == 999 produced by Corel Draw. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1490 + + * libtiff/{tif_dirread.c, tif_read.c}: Type of the byte counters + changed from tsize_t to uint32 to be able to work with data arrays + larger than 2GB. Fixes bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=890 + + Idea submitted by Matt Hancher. + +2007-01-31 Andrey Kiselev + + * tools/tif2rgba.c: This utility does not work properly on big-endian + architectures. It was fixed including the bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1149 + +2007-01-15 Mateusz Loskot + + * Submitted libtiff port for Windows CE platform + * libtiff/tif_config.wince.h: Added configuration header for WinCE. + * libtiff/tiffconf.wince.h: Ported old configuration header for WinCE. + * libtiff/tif_wince.c: Added WinCE-specific implementation of some + functons from tif_win32.c. + * libtiff/tif_win32.c: Disabled some functions already reimplemented in tif_wince.c. + * libtiff/tiffiop.h, port/lfind.c: Added conditional include of some + standard header files for Windows CE build. + * tools/tiffinfoce.c: Ported tiffinfo utility for Windows CE. + +2006-11-19 Frank Warmerdam + + * libtiff/tif_write.c: TIFFAppendToStrip() - clear sorted flag if + we move a strip. + http://bugzilla.remotesensing.org/show_bug.cgi?id=1359 + +2006-10-13 Andrey Kiselev + + * libtiff/tif_dir.c: More fixes for vulnerabilities, reported + in Gentoo bug (): + + http://bugs.gentoo.org/show_bug.cgi?id=142383 + + * libtiff/contrib/dbs/xtiff/xtiff.c: Make xtiff utility compilable. + Though it is still far from the state of being working and useful. + +2006-10-12 Andrey Kiselev + + * libtiff/tif_fax3.c: Save the state of printdir codec dependent + method. + + * libtiff/tif_jpeg.c: Save the state of printdir codec dependent method + as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1273 + + * libtiff/tif_win32.c: Fixed problem with offset value manipulation + as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1322 + + * libtiff/{tif_read.c, tif_jpeg.c, tif_dir.c}: More fixes for + vulnerabilities, reported in Gentoo bug (): + + http://bugs.gentoo.org/show_bug.cgi?id=142383 + +2006-09-28 Andrey Kiselev + + * libtiff/{tif_fax3.c, tif_next.c, tif_pixarlog.c}: Fixed multiple + vulnerabilities, as per Gentoo bug (): + + http://bugs.gentoo.org/show_bug.cgi?id=142383 + +2006-09-27 Frank Warmerdam + + * libtiff/tif_lzw.c, libtiff/tif_zip.c: Fixed problems with mixing + encoding and decoding on the same read-write TIFF handle. The LZW + code can now maintain encode and decode state at the same time. The + ZIP code will switch back and forth as needed. + http://bugzilla.remotesensing.org/show_bug.cgi?id=757 + +2006-09-20 Frank Warmerdam + + * libtiff: Rename config.h.vc and tif_config.h.vc to config.vc.h and + tif_config.vc.h for easier identification by folks using an IDE. + +2006-07-25 Frank Warmerdam + + * tif_msdos.c: Avoid handle leak for failed opens. c/o Thierry Pierron + +2006-07-19 Frank Warmerdam + + * tif_dirwrite.c: take care not to flush out buffer of strip/tile + data in _TIFFWriteDirectory if TIFF_BEENWRITING not set. Relates + to bug report by Peng Gao with black strip at bottom of images. + +2006-07-12 Frank Warmerdam + + * tif_dirwrite.c: make sure to use uint32 for wordcount in + TIFFWriteNormanTag if writecount is VARIABLE2 for ASCII fields. + It already seems to have been done for other field types. Needed + for "tiffset" on files with geotiff ascii text. + +2006-07-04 Bob Friesenhahn + + * {configure.ac, libtiff/tif_config.h.vc, libtiff/tif_jbig.c} + (JBIGDecode): jbg_newlen is not available in older JBIG-KIT and + its use does not appear to be required, so use it only when it is + available. + +2006-06-24 Andrey Kiselev + + * libtiff/tif_dirinfo.c: Added missed EXIF tag ColorSpace (40961). + + * libtiff/tif_dirread.c: Move IFD fetching code in the separate + function TIFFFetchDirectory() avoiding code duplication in + TIFFReadDirectory() and TIFFReadCustomDirectory(). + +2006-06-19 Frank Warmerdam + + * tools/tiff2pdf.c: Fix handling of -q values. + http://bugzilla.remotesensing.org/show_bug.cgi?id=587 + +2006-06-17 Frank Warmerdam + + * tif_readdir.c: Added case in EstimateStripByteCounts() for tiled + files. Modified TIFFReadDirectory() to not invoke + EstimateStripByteCounts() for case where entry 0 and 1 are unequal + but one of them is zero. + http://bugzilla.remotesensing.org/show_bug.cgi?id=1204 + +2006-06-08 Andrey Kiselev + + * libtiff/{tif_open.c, tif_dirread.c, tiffiop.h}: Move IFD looping + checking code in the separate function TIFFCheckDirOffset(). + + * libtiff/tif_aux.c: Added _TIFFCheckRealloc() function. + + * tools/tiffcmp.c: Fixed floating point comparison logic as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1191 + + * libtiff/tif_fax3.c: Fixed problems in fax decoder as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1194 + + * tools/tiff2pdf.c: Fixed buffer overflow condition in + t2p_write_pdf_string() as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1196 + +2006-06-07 Andrey Kiselev + + * {configure, configure.ac, libtiff/tif_jbig.c, tools/tiffcp.c}: Added + support for JBIG compression scheme (34661 code) contributed by Lee + Howard. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=896 + + * configure, configure.ac: OJPEG support enabled by default. + + * contrib/ojpeg/: Removed. New OJPEG support does not need this patch. + +2006-06-03 Bob Friesenhahn + + * libtiff/{tif_dirinfo.c, tif_print.c} : Fix crash in + TIFFPrintDirectory(). Joris Van Damme authored the fix. + +2006-04-21 Andrey Kiselev + + * tools/tiff2pdf.c: Unified line ending characters (always use '\n') + as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1163 + + * README.vms, Makefile.am, configure.com, libtiff/{Makefile.am, + tif_config.h-vms, tif_stream.cxx, tif_vms.c, tiffconf.h-vms}: + Added support for OpenVMS by Alexey Chupahin, elvis_75@mail.ru. + +2006-04-20 Andrey Kiselev + + * tools/{fax2ps.c, fax2tiff.c, ppm2tiff.c, ras2tiff.c, tiff2pdf.c}: + Properly set the binary mode for stdin stream as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1141 + + * man/{bmp2tiff.1, fax2ps.1, fax2tiff.1, gif2tiff.1, ras2tiff.1, + raw2tiff.1, rgb2ycbcr.1, sgi2tiff.1, tiff2bw.1, tiff2pdf.1, tiff2ps.1, + tiff2rgba.1, tiffcmp.1, tiffcp.1, tiffdither.1, tiffdump.1, tiffgt.1, + tiffset.1}: Improvements in page formatting as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1140 + + * html/tools.html, html/man/Makefile.am, tools/tiff2pdf.c: Fixed + typos as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1139 + +2006-04-18 Frank Warmerdam + + * nmake.opt: use /EHsc for VS2005 compatibility. Also define + _CRT_SECURE_NO_DEPRECATE to avoid noise on VS2005. + +2006-04-12 Joris Van Damme + + * libtiff/tif_getimage.c: Added support for planarconfig separate + non-subsampled YCbCr (i.e. separate YCbCr with subsampling [1,1]) + +2006-04-11 Joris Van Damme + + * libtiff/tif_getimage.c: Revision of all RGB(A) put routines + - Conversion of unassociated alpha to associated alpha now done with + more performant LUT, and calculation more correct + - Conversion of 16bit data to 8bit data now done with + more performant LUT, and calculation more correct + - Bugfix of handling of 16bit RGB with unassociated alpha + +2006-04-11 Joris Van Damme + + * libtiff/tif_getimage.c: + - When there is no alpha, gtTileSeparate and gtStripSeparate allocated + buffer for alpha strile and filled it, only to never read it back. + Removed allocation and fill. + - Minor rename of vars in gtTileSeparate and gtStripSeparate + anticipating planned functionality extension + +2006-04-08 Joris Van Damme + + * libtiff/tif_getimage.c: renamed pickTileContigCase to PickContigCase + and pickTileSeparateCase to PickSeparateCase as both work on strips as + well + + * libtiff/tif_getimage.c: moved img->get selection from + TIFFRGBAImageBegin into PickContigCase and PickSeparateCase to create + logical hook for planned functionality extension + +2006-04-08 Joris Van Damme + + * libtiff/tif_ojpeg.c: resolved memory leak that was a consequence + of inappropriate use of jpeg_abort instead of jpeg_destroy + +2006-04-07 Joris Van Damme + + * libtiff/tif_getimage.c: replaced usage of TIFFScanlineSize in + gtStripContig with TIFFNewScanlineSize so as to fix buggy behaviour + on subsampled images - this ought to get sorted when we feel brave + enough to replace TIFFScanlineSize alltogether + + * libtiff/tif_ojpeg.c: fixed bug in OJPEGReadSkip + +2006-04-04 Joris Van Damme + + * libtiff/tiffio.h: added new type tstrile_t + + * libtiff/tif_dir.h: changed types of td_stripsperimage and td_nstrips + to new tstrile_t, types of td_stripoffset and td_stripbytecount to + toff_t* + + * libtiff/tif_ojpeg.c: totally new implementation + + * libtiff/tif_dirread.c: added several hacks to suit new support of + OJPEG + + * libtiff/tif_getimage.c: removed TIFFTAG_JPEGCOLORMODE handling + of OJPEG images in favor of tif_getimage.c native handling of + YCbCr and desubsampling + +2006-03-29 Frank Warmerdam + + * libtiff/tif_jpeg.c: JPEGVSetField() so that altering the photometric + interpretation causes the "upsampled" flag to be recomputed. Fixes + peculiar bug where photometric flag had to be set before jpegcolormode + flag. + +2006-03-25 Joris Van Damme + + * libtiff/tif_jpeg.c: strip size related bugfix in encode raw + + * libtiff/tif_strip.c: temporarilly added two new versions of + TIFFScanlineSize + - TIFFNewScanlineSize: proposed new version, after all related + issues and side-effects are sorted out + - TIFFOldScanlineSize: old version, from prior to 2006-03-21 change + This needs further sorting out. + +2006-03-25 Joris Van Damme + + * contrib/addtiffo/tif_ovrcache.c: bugfix to correctly pass size + of last truncated strip data to TIFFWriteEncodedStrip + +2006-03-25 Joris Van Damme + + * libtiff/{tif_jpeg.c, tif_strip.c}: bugfix of tif_jpeg decode raw + +2006-03-25 Joris Van Damme + + * libtiff/tif_getimage.c: bugfix/rewrite of putcontig8bitYCbCr22tile + + * libtiff/tif_getimage.c: added putcontig8bitYCbCr12tile + + * libtiff/tif_read.c: added support for new TIFF_NOREADRAW flag to + prepare the path for new tif_ojpeg.c + +2006-03-23 Andrey Kiselev + + * libtiff 3.8.2 released. + + * tools/Makefile.am: Use runtime paths linker flags when rpath + option enabled. + +2006-03-21 Andrey Kiselev + + * libtiff/libtiff.def: Added missed exports as per bug + http://bugzilla.remotesensing.org/attachment.cgi?id=337 + + * contrib/addtiffo/Makefile.vc, libtiff/Makefile.vc, port/Makefile.vc, + tools/Makefile.vc: Makefiles improvements as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1128 + + * nmake.opt libtiff/{tif_config.h.vc, tif_unix.c, tiffio.h}, + tools/{fax2ps.c, fax2tiff.c, tiff2pdf.c}: Fixed win32 I/O functions + usage as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1127 + + * libtiff/tif_strip.c: Take subsampling in account when calculating + TIFFScanlineSize(). + + * tools/tiffcp.c: Do not set RowsPerStrip bigger than image length. + +2006-03-17 Andrey Kiselev + + * tools/fax2tiff.c: Fixed wrong TIFFerror() invocations as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1125 + + * tools/fax2ps.c: Fixed reading the input stream from stdin as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1124 + +2006-03-16 Andrey Kiselev + + * libtiff/tiffiop.h: Added decalration for + _TIFFSetDefaultCompressionState(). + + * libtiff/{tif_jpeg.c, tif_fax3.c, tif_zip.c, tif_pixarlog.c, + tif_lzw.c, tif_luv.c}: Use _TIFFSetDefaultCompressionState() in all + codec cleanup methods. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1120 + +2006-03-15 Andrey Kiselev + + * libtiff/tif_jpeg.c: Do not cleanup codec state in TIFFInitJPEG(). As + per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1119 + + * tools/raw2tiff.c: Do not set RowsPerStrip larger than ImageLength. + As per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1110 + + * libtiff/tiffiop.h: dblparam_t typedef removed; GLOBALDATA macro + removed; move here the STRIP_SIZE_DEFAULT macro definition. + + * libtiff/{tif_dirread.c, tif_strip.c}: Removed STRIP_SIZE_DEFAULT + macro definition. + + * libtiff/tif_dir.c: Use double type instead of dblparam_t. + +2006-03-14 Andrey Kiselev + + * libtiff/tif_dirread.c: Do not check the PlanarConfig tag presence + in TIFFReadDirectory, because it is always set at the start of + function and we allow TIFFs without that tag set. + +2005-03-13 Andrey Kiselev + + * libtiff 3.8.1 released. + +2006-03-07 Andrey Kiselev + + * libtiff/tif_dirread.c: Fixed error reporting in TIFFFetchAnyArray() + function as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 + + * libtiff/tif_dirread.c: More wise check for integer overflow + condition as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 + + * libtiff/{tif_jpeg.c, tif_pixarlog.c, tif_fax3.c, tif_zip.c}: + Properly restore setfield/getfield methods in cleanup functions. As + per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 + +2006-03-03 Andrey Kiselev + + * libtiff/{tif_predict.c, tif_predict.h}: Added new function + TIFFPredictorCleanup() to restore parent decode/encode/field methods. + + * libtiff/{tif_lzw.c, tif_pixarlog.c, tif_zip.c}: Use + TIFFPredictorCleanup() in codec cleanup methods. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 + + * libtiff/tif_dirread.c: Fixed integer overflow condition in + TIFFFetchData() function. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 + +2006-03-01 Andrey Kiselev + + * libtiff/tif_ojpeg.c: Set the ReferenceBlackWhite with the + TIFFSetField() method, not directly. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1043 + + * tools/ppm2tiff.c: Added support for PBM files as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1044 + +2006-02-27 Andrey Kiselev + + * libtiff/tif_write.c: Small code rearrangement in TIFFWriteScanline() + to avoid crash as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1081. + +2006-02-26 Andrey Kiselev + + * tools/tiff2pdf.c: Functions t2p_sample_rgbaa_to_rgb() and + t2p_sample_rgba_to_rgb() was used in place of each other, that was + resulted in problems with RGBA images with associated alpha. + As per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1097 + +2006-02-23 Andrey Kiselev + + * libtiff/tif_dirwrite.c: Properly write TIFFTAG_DOTRANGE tag as per + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1088. + + * libtiff/tif_print.c: Properly read TIFFTAG_PAGENUMBER, + TIFFTAG_HALFTONEHINTS, TIFFTAG_YCBCRSUBSAMPLING and TIFFTAG_DOTRANGE + tags as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1088. + + * tools/tiff2ps.c: Properly scale all the pages when converting + multipage TIFF with /width/height/center options set. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1080 + +2006-02-15 Andrey Kiselev + + * tools/tiff2pdf.c: Do not create output file until all option checks + will be done. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1072 + + * tools/bmp2tiff.c: Added ability to create multipage TIFFs from the + list of input files as per bug: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1077 + +2006-02-09 Andrey Kiselev + + * libtiff/tif_tile.c: Fix error reporting in TIFFCheckTile() as per + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1063. + + * tools/tiffgt.c: Avoid crashing in case of image unsupported by + TIFFRGBAImage interface. + + * libtiff/tif_color.c: Avoid overflow in case of wrong input as per + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1065. + +2006-02-07 Frank Warmerdam + + * tools/tiff2pdf.c: Fixed support for non-YCbCr encoded JPEG + compressed TIFF files, per submission from Dan Cobra. + +2006-02-07 Andrey Kiselev + + * libtiff/{tif_dirread.c, tif_packbits.c, tif_win32.c}: Properly + cast values to avoid warnings. As per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1033. + + * libtiff/tif_dirinfo.c: Use TIFF_NOTYPE instead of 0 when + appropriate. As per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1033. + + * libtiff/tif_aux.c: Fixed type of temporary variable in + _TIFFCheckMalloc() as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1033. + +2006-02-06 Andrey Kiselev + + * libtiff/tif_aux.c: Return static array when fetching default + YCbCrCoefficients (another problem, reported a the + http://bugzilla.remotesensing.org/show_bug.cgi?id=1029 entry). + +2006-02-03 Andrey Kiselev + + * libtiff/tif_dir.c: Special handling for PageNumber, HalftoneHints, + YCbCrSubsampling and DotRange tags as per bugs + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1029 + http://bugzilla.remotesensing.org/show_bug.cgi?id=1034 + + * libtiff/tif_dirread.c: Use _TIFFGetExifFieldInfo() instead of + _TIFFGetFieldInfo() in TIFFReadEXIFDirectory() call as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1026. + +2006-01-23 Andrey Kiselev + + * libtool related stuff updated from the 2.1a branch. + +2006-01-11 Frank Warmerdam + + * tools/bmp2tiff,pal2rgb,ppm2tiff,ras2tiff,raw2tiff,sgi2tiff, + tiff2bw,tiffcp: Fixed jpeg option processing so -c jpeg:r:50 works + properly as per bug: + http://bugzilla.remotesensing.org/show_bug.cgi?id=1025 + +2006-01-09 Bob Friesenhahn + + * configure.ac: Fix with_default_strip_size comparison as reported + by Norihiko Murase. + +2006-01-08 Bob Friesenhahn + + * test/Makefile.am (LIBTIFF): Due to linking against libtiff + incorrectly, tests were not actually testing the uninstalled + libtiff. Now they are. + +2006-01-04 Andrey Kiselev + + * libtiff/tif_dirinfo.c: Change definitions for TIFFTAG_ICCPROFILE, + TIFFTAG_PHOTOSHOP, TIFFTAG_RICHTIFFIPTC, TIFFTAG_XMLPACKET: readcount + should be uint32 value. + +2006-01-02 Bob Friesenhahn + + * html/man/Makefile.am (htmldoc): Fix htmldoc rule so that it can + be used if build directory is not the same as source directory. + * man/{TIFFGetField.3tiff, TIFFSetField.3tiff}: Documented + TIFFTAG_PHOTOSHOP, TIFFTAG_RICHTIFFIPTC, and TIFFTAG_XMLPACKET, + and re-sorted tag names in alphabetical order. + +2005-12-29 Andrey Kiselev + + * libtiff 3.8.0 released. + +2005-12-28 Bob Friesenhahn + + * tools/bmp2tiff.c (main): Fixed warning regarding returning + inconsistent types from a condition. + * tools/tiffcmp.c (CheckLongTag): Eliminate warning due to printf + format. + * tools/bmp2tiff.c: Reduce compilation warnings on big-endian CPUs. + +2005-12-28 Joris Van Damme + + * html/{index.html, support.hml, libtiff.html}: Cleaned up HTML + +2005-12-27 Andrey Kiselev + + * libtiff/tiffio.h: Added VC_EXTRALEAN definition before including + windows.h, to reduce the compile time. + +2005-12-26 Bob Friesenhahn + + * libtiff/tif_jpeg.c: Improve compilation under MinGW. + +2005-12-26 Andrey Kiselev + + * libtiff/{tif_dir.c, tif_dir.h, tif_dirread.c, tif_dirinfo.c}: + tiffFieldInfo and exifFieldInfo arrays definitions moved back to + tif_dirinfo.c; added _TIFFGetFieldInfo() and _TIFFGetExifFieldInfo() + private functions to retrieve FieldInfo arrays. + +2005-12-24 Bob Friesenhahn + + * html/build.html: Added some additional instructions for when + building using MSVC under Windows. Also fixed two HTML syntax + errors and used HTML Tidy to tidy up the HTML syntax and + formatting. + +2005-12-24 Andrey Kiselev + + * libtiff/{tif_aux.c, tif_dir.c, tif_dir.h, tif_dirwrite.c, + tif_print.c, tif_getimage.c}: Make InkSet, NumberOfInks, DotRange and + StoNits tags custom. + +2005-12-23 Andrey Kiselev + + * libtiff/{tif_aux.c, tif_dir.c, tif_dir.h, tif_print.c}: Make + WhitePoint tag custom. + + * libtiff/{tif_dir.h, tiff.h}: More EXIF tags added. + +2005-12-23 Joris Van Damme + + * libtiff/tiffio.h: fixed typo that potentially resulted in + redefininition of USE_WIN32_FILEIO + + * libtiff/*: Added more 'dual-mode' error handling: Done TIFFWarning + calls in core LibTiff. + +2005-12-21 Andrey Kiselev + + * libtiff/{tif_dir.c, tif_dir.h, tif_print.c}: Make RichTIFFIPTC, + Photoshop and ICCProfile tags custom. + +2005-12-21 Joris Van Damme + + * libtiff/*, contrib/*: Added 'dual-mode' error handling, enabling + newer code to get context indicator in error handler and still + remain compatible with older code: Done TIFFError calls everywhere + except in tools + +2005-12-20 Andrey Kiselev + + * tools/tiffcp.c: Added many error reporting messages; fixed integer + overflow as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=789 + +2005-12-16 Frank Warmerdam + + * contrib/addtiffo/*: Major upgrade by Joris to support subsampled + YCbCr images in jpeg compressed TIFF files. + +2005-12-14 Andrey Kiselev + + * tools/tiffcp.c: Return non-zero status when reading fails (again). + +2005-12-13 Andrey Kiselev + + * tools/tiffcp.c: Return non-zero status when reading fails. + +2005-12-12 Andrey Kiselev + + * libtiff/{tif_dir.h, tiff.h}: Added more EXIF tags. + +2005-12-09 Andrey Kiselev + + * libtiff/{tif_dir.c, tif_dir.h, tif_print.c}: Make XMLPacket tag + custom. + + * tools/tiffinfo.c: Print EXIF directory contents if exist. + + * libtiff/tiff.h: Few EXIF tag numbers added. + + * libtiff/{tif_dirinfo.c, tif_dirread.c, tif_dir.h, tif_dir.c, + tiffio.h}: Preliminary support to read custom directories. New + functions: TIFFReadCustomDirectory() and TIFFReadEXIFDirectory(). + +2005-12-07 Andrey Kiselev + + * libtiff/{tif_dirinfo.c, tif_dirread.c, tif_dir.h, tif_dir.c}: + More work to implement custom directory read support. + + * libtiff/{tif_aux.c, tif_dirinfo.c, tif_dirread.c, tif_dir.h, + tif_dir.c, tif_print.c}: Make YCbCrCoefficients and ReferenceBlackWhite + tags custom. + +2005-12-05 Andrey Kiselev + + * libtiff/tif_dirread.c: One more workaround for broken + StripByteCounts tag. Handle the case when StripByteCounts array filled + with completely wrong values. + +2005-11-30 Andrey Kiselev + + * libtiff/tif_dirinfo.c: Release file descriptor in case of failure + in the TIFFOpenW() function as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1003 + + * libtiff/tif_dirinfo.c: Correctly yse bsearch() and lfind() + functions as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1008 + +2005-11-20 Frank Warmerdam + + * tif_open.c, tiff.h, tiffdump.c: Incorporate preliminary support + for MS MDI format. + http://bugzilla.remotesensing.org/show_bug.cgi?id=1002 + + * .cvsignore: many files added, and a few update according + to suggestion of Brad HArds on tiff mailing list. + +2005-11-03 Frank Warmerdam + + * libtiff/libtiff.def, tiffiop.h, tiffio.h: Made TIFFFreeDirectory + public. + +2005-10-31 Andrey Kiselev + + * tools/fax2tiff.c: Properly calculate sizes of temporary arrays + as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=943 + + * tools/fax2tiff.c: Added option '-r' to set RowsPerStrip parameter + as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=944 + + * tools/tiffdump.c: Fixed typeshift and typemask arrays initialization + problem as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=946 + + * tools/bmp2tiff.c: Fixed possible integer overflow error as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=965 + + * libtiff/tif_dirinfo.c: Make XResolution, YResolution and + ResolutionUnit tags modifiable during write process. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=977 + + * tools/tiffsplit.c: Copy fax related fields over splitted parts + as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=983 + +2005-10-21 Frank Warmerdam + + * tif_dirread.c: Don't try and split single strips into "0" strips + in ChopUpSingleUncompressedStrip. This happens in some degenerate + cases (like 1x1 files with stripbytecounts==0 (gtsmall.jp2 embed tiff) + +2005-10-20 Joris Van Damme + + * tif_fax3.c: changed 'at scanline ...' style warning/errors + with incorrect use of tif_row, to 'at line ... of + strip/tile ...' style + +2005-10-15 Frank Warmerdam + + * tif_write.c: fixed setting of planarconfig as per bug report + on the mailing list from Joris. + +2005-10-07 Andrey Kiselev + + * configure.ac, configure, nmake.opt, libtiff/{tif_config.h, + tif_dirread.c}: Make the default strip size configurable via the + --with-default-strip-size and STRIP_SIZE_DEFAULT options. + +2005-09-30 Bob Friesenhahn + + * html/support.html: Fixed link to documentation on Greg Ward's + LogLuv TIFF format. + +2005-09-28 Andrey Kiselev + + * tools/tiffdump.c: Fixed crash when reading malformed tags. + +2005-09-20 Andrey Kiselev + + * tools/tiff2pdf.c: Added missed 'break' statement as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=932 + +2005-09-12 Andrey Kiselev + + * libtiff 3.7.4 released. + + * {configure, configure.ac, Makefile.am, autogen.sh}: Applied patch + from Patrick Welche (all scripts moved in the 'config' and 'm4' + directories). + +2005-09-12 Frank Warmerdam + + * libtiff/tif_open.c: reintroduce seek to avoid problem on solaris. + +2005-09-05 Frank Warmerdam + + * libtiff/tif_dir.c: When prefreeing tv->value in TIFFSetFieldV + also set it to NULL to avoid double free when re-setting custom + string fields as per: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=922 + +2005-08-12 Frank Warmerdam + + * libtiff/tif_print.c: avoid signed/unsigned warning. + + * libtiff/tif_dirread.c: removed unused variable. + +2005-07-30 Frank Warmerdam + + * libtiff/tif_dir.c: Fixed up support for swapping "double complex" + values (128 bits as 2 64 bits doubles). GDAL gcore tests now + pass on bigendian (macosx) system. + +2005-07-28 Andrey Kiselev + + * libtiff/{tif_aux.c, tif_dirread.c, tif_fax3.c, tiffiop.h}: Rename + CheckMalloc() function to _TIFFCheckMalloc() and make it available + globally as an internal helper routine. + +2005-07-27 Andrey Kiselev + + * libtiff/tif_dir.c: More improvements in the "pass by value" part of + the custom tags handling code. + +2005-07-26 Andrey Kiselev + + * libtiff/{tif_dirread.c, tif_dirinfo.c}: Do not upcast BYTEs to + SHORTs in the TIFFFetchByteArray(). Remove TIFFFetchExtraSamples() + function, use TIFFFetchNormalTag() instead as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=831 + + Remove TIFFFetchExtraSamples() function, use TIFFFetchNormalTag() + instead. + + * libtiff/tiffconf.h.in: One more attempt to fix the AIX bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=39 + +2005-07-25 Andrey Kiselev + + * libtiff/tif_print.c: Fixed printing of the BYTE and SBYTE arrays. + + * tools/tiffdump.c: Added support for TIFF_IFD datatype. + +2005-07-21 Andrey Kiselev + + * libtiff/tif_write.c: Do not check the PlanarConfiguration field in + the TIFFWriteCheck() function in case of single band images (as per + TIFF spec). + +2005-07-12 Andrey Kiselev + + * SConstruct, libtiff/SConstruct: Added the first very preliminary + support for SCons software building tool (http://www.scons.org/). + This is experimental infrastructure and it will exist along with the + autotools mechanics. + +2005-07-07 Andrey Kiselev + + * port/{getopt.c, strcasecmp.c, strtoul.c}: Update modules from + the NetBSD source tree (the old 4-clause BSD license changed to + the new 3-clause one). + + * configure.ac, port/lfind.c, libtiff/tiffiop.h: Added lfind() + replacement module. + + * port/dummy.c: Make the dummy function static. + +2005-07-06 Andrey Kiselev + + * tools/tiffcp.c: Fixed WhitePoint tag copying. + + * libtiff/{tif_dir.c, tif_dir.h, tif_dirinfo.c, tif_print.c}: + Make FieldOfViewCotangent, MatrixWorldToScreen, MatrixWorldToCamera, + ImageFullWidth, ImageFullLength and PrimaryChromaticities tags custom. + +2005-07-04 Andrey Kiselev + + * libtiff 3.7.3 released. + + * configure, configure.ac: Do not use empty -R option when linking + with --enable-rpath. + +2005-07-01 Andrey Kiselev + + * libtiff/{tiffiop.h, tif_open.c}: Added open option 'h' to avoid + reading the first IFD when needed. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=875 + + * libtiff/tif_color.c: Better use of TIFFmin() macro to avoid side + effects. + +2005-06-23 Andrey Kiselev + + * tools/tiff2pdf.c: Print two characters per loop in the + t2p_write_pdf_trailer(). As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=594 + + * tools/tiffgt.c: Use MacOS X OpenGL framework when appropriate. As + per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=844 + + * acinclude.m4: Updated to latest OpenGL test macros versions. + + * libtiff/tiff.h: Use correct int size on Sparc 64bit/Sun compiler + platform. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=855 + +2005-06-14 Andrey Kiselev + + * libtiff/tif_dirinfo.c: Added support for ClipPath, XClipPathUnits + and YClipPathUnits tags. + +2005-06-07 Andrey Kiselev + + * contrib/addtiffo/tif_ovrcache.c: Properly extract tile/strip size; + use pixel sized shift in contigous case. + +2005-06-06 Andrey Kiselev + + * contrib/addtiffo/{tif_overview.c, tif_ovrcache.c, tif_ovrcache.h}: + Make overviews working for contiguos images. + +2005-06-03 Andrey Kiselev + + * libtiff/tif_open.c: Replace runtime endianess check with the compile + time one. + + * libtiff/tif_predict.c: Floating point predictor now works on + big-endian hosts. + +2005-06-01 Andrey Kiselev + + * libtiff/tif_dir.c: Use _TIFFsetString() function when read custom + ASCII values. + + * libtiff/{tif_dirinfo.c, tif_dir.h, tif_dir.c, tif_print.c}: Make + DocumentName, Artist, HostComputer, ImageDescription, Make, Model, + Copyright, DateTime, PageName, TextureFormat, TextureWrapModes and + TargetPrinter tags custom. + + * libtiff/tif_jpeg.c: Cleanup the codec state depending on + TIFF_CODERSETUP flag (to fix memry leaks). + + * libtiff/tif_jpeg.c: Initialize JPEGTables array with zero after + allocating. + +2005-05-26 Andrey Kiselev + + * configure.ac, libtiff/Makefile.am: Added workaround for + OpenBSD/MirOS soname problem as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=838 + + * libtiff/tif_dirwrite.c: Use tdir_count when calling + TIFFCvtNativeToIEEEDouble() in the TIFFWriteDoubleArray() function as + per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=845 + +2005-05-25 Andrey Kiselev + + * tools/ppm2tiff.c: Fixed format string when read PPM file header with + the fscanf() function. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=861 + + * libtiff/{tif_dirinfo.c, tif_print.c}: TIFFFetchByteArray() returns + uint16 array when fetching the BYTE and SBYTE filds, so we should + consider result as pointer to uint16 array and not as array of chars. + As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=831 + + * libtiff/tif_dir.c: More efficient custom tags retrieval as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=830 + + * libtiff/tif_win32.c: Use FILE_SHARE_READ | FILE_SHARE_WRITE share + mode in CreateFile() call as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=829 + + * libtiff/Makefile.am: Fixed parallel compilation of the libtiff and + libtiffxx libraries as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=826 + + * contrib/addtiffo/{tif_overview.c, tif_ovrcache.h}: Sinchronized with + GDAL. + +2005-05-23 Frank Warmerdam + + * libtiff/tif_jpeg.c: Substantial fix for addtiffo problems with + JPEG encoded TIFF files. Pre-allocate lots of space for jpegtables + in directory. + +2005-05-22 Frank Warmerdam + + * libtiff/tif_dirread.c: Changed the code that computes + stripbytecount[0] if it appears bogus to ignore if stripoffset[0] is + zero. This is a common case with GDAL indicating a "null" tile/strip. + +2005-05-17 Andrey Kiselev + + * tools/tiffsplit.c: Check for JPEGTables tag presence before copying. + +2005-05-06 Frank Warmerdam + + * libtiff/tif_dirread.c: Applied similar change to + TIFFFetchPerSampleLongs and TIFFFetchPerSampleAnys. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=843 + + * libtiff/tif_jpeg.c: added LIB_JPEG_MK1 support in JPEGDecodeRaw(). + +2005-05-06 Andrey Kiselev + * tools/tiff2pdfr.c, man/tiff2pdf.1: Calculate the tile width properly; + added new option '-b' to use interpolation in output PDF files (Bruno + Ledoux). + +2005-05-05 Frank Warmerdam + + * libtiff/tif_dirread.c: Ensure that broken files with too many + values in PerSampleShorts work ok instead of crashing. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=843 + +2005-04-27 Andrey Kiselev + + * tools/tiffdither.c: Copy the PhotometricInterpretation tag from the + input file. + +2005-04-15 Andrey Kiselev + + * libtiff/tif_predict.c: Added ability to encode floating point + predictor, as per TIFF Technical Note 3. + +2005-04-14 Andrey Kiselev + + * libtiff/{tif_predict.h, tif_predict.c}: Added ability to decode + floating point predictor, as per TIFF Technical Note 3. + +2005-04-13 Andrey Kiselev + + * libtiff/{tiffio.h, tiffiop.h, tif_dir.c, tif_read.c, tif_swab.c}: + Added _TIFFSwab24BitData() and TIFFSwabArrayOfLong() functions used to + swap 24-bit floating point values. + + * libtiff/tiff.h: Added predictor constants. + +2005-04-08 Andrey Kiselev + + * libtiff/{tiffiop.h, tif_dir.c}: Use uint32 type for appropriate + values in _TIFFVSetField() function. Inspired by the bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=816 + + * man/TIFFSetField.3tiff: Fixed definition of the TIFFTAG_INKNAMES tag + as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=816 + +2005-03-30 Andrey Kiselev + + * libtiff/tif_open.c: Do not read header in case the output file + should be truncated (Ron). + + * libtiff/{tif_dirinfo.c, tif_config.h.vc}: Use lfind() instead + of bsearch() in _TIFFFindFieldInfoByName() function (Ron). + + * libtiff/{tiff.h, tif_dirinfo.c}: Fixes in EXIF tag ordering (Ron). + +2005-03-22 Andrey Kiselev + + * configure.ac, libtiff/Makefile.am: Use libtool machinery to pass + rpath option. + +2005-03-21 Andrey Kiselev + + * libtiff/{tif_dir.c, tif_print.c}: Handle all data types in custom + tags. + +2005-03-18 Andrey Kiselev + + * libtiff/dirinfo.c: Added DNG tags. + + * libtiff/{tif_dir.c, tif_print.c}: More improvements in custom tag + handling code. + + * libtiff/tiff.h: More comments; added missed DNG tag (LensInfo); + added DNG 1.1.0.0 tags. + + * tools/tif2pdf.c: Fixed problem with alpha channel handling as per + bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=794 + + * man/TIFFGetField.3tiff: Add a note about autoregistered tags. + +2005-03-17 Andrey Kiselev + + * nmake.opt: Build with Win32 CRT library by default. + + * tools/tiff2ps.c: Fixed typo in page size handling code. + + * libtiff/{tif_dir.c, tif_print.c}: Support for custom tags, passed + by value. + + * libtiff/{tiff.h, tif_dirinfo.c, tiffiop.h}: Added EXIF related tags. + +2005-03-15 Andrey Kiselev + + * libtiff 3.7.2 released. + +2005-03-09 Andrey Kiselev + + * tools/tiffcmp.c: Added ability to compare the 32-bit integer and + floating point data; complain on unsupported bit depths. + +2005-03-05 Andrey Kiselev + + * tif_stream.cxx: Use ios namespace instead of ios_base to support + GCC 2.95. + + * libtiff/{tiff.h, tif_fax3.tif, tif_jpeg.c}: Applied correct patch from + Lee Howard for HylaFax DCS tag + (see http://bugzilla.remotesensing.org/show_bug.cgi?id=771) + +2005-03-04 Andrey Kiselev + + * configure, configure.ac: Use -rpath option instead of -R as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=732 + + * libtiff/{tiff.h, tif_fax3.tif, tif_jpeg.c}: Applied patch from Lee + Howard to support a new tag TIFFTAG_FAXDCS (34911) used in HylaFax + software. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=771 + + * nmake.opt, html/build.html: Add more comments, change the config + file organization a bit as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=764 + + * tools/tiffcmp.c: Use properly sized buffer in short arrays comparison + as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=785 + +2005-03-03 Andrey Kiselev + + * libtiff/tif_dirread.c: More logic to guess missed strip size as per + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=705 + + * tools/fax2ps.c: Replace insecure mktemp() function with the + tmpfile() as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=786 + +2005-02-04 Andrey Kiselev + + * libtiff/tiff.h: Changed the int8 definition to be always signed char + as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=727 + + * libtiff/tiffio.h: Move TIFFOpenW() function into the extern "C"{} + block as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=763 + +2005-02-03 Bob Friesenhahn + + * tools/tiffgt.c: Fix problem on big-endian CPUs so that images + display more correctly. Images display brighter than they should + on a Sun workstation. + +2005-02-03 Andrey Kiselev + + * libtiff/tif_dirread.c: Estimate strip size in case of wrong or + suspicious values in the tags. As per bugs + + http://bugzilla.remotesensing.org/show_bug.cgi?id=705 + + and + + http://bugzilla.remotesensing.org/show_bug.cgi?id=320 + + * tools/tiff2ps.c: Fixed problem with page sizes as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=742 + +2005-01-31 Bob Friesenhahn + + * libtiff/tiff.h (TIFFTAG_TILEWIDTH): Corrected description. + (TIFFTAG_TILELENGTH): Corrected description. + +2005-01-30 Andrey Kiselev + + * configure.ac: Fixes for --with-docdir option as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=759 + + * libtiff/tif_open.c: Remove unnesessary TIFFSeekFile() call as per + bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=756 + + * libtiff/tif_stream.cxx: Fixes for C++ stream interface from + Michael Rinne and Edward Lam. + +2005-01-15 Andrey Kiselev + + * configure.ac: Make the documentation directory location configurable + via the --with-docdir option (as suggested by Jeremy C. Reed). + + * libtiff/tif_color.c: Use double as the second argument of pow() + function in TIFFCIELabToRGBInit(). As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=741 + + * libtiff/tif_pixarlog.c: Avoid warnings when converting float to + integer as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=740 + + * libtiff/tif_getimage.c: Always fill the error message buffer in + TIFFRGBAImageBegin() as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=739 + +2005-01-12 Andrey Kiselev + + * libtiff/tif_jpeg.c: Added ability to read/write the fax specific + TIFFTAG_FAXRECVPARAMS, TIFFTAG_FAXSUBADDRESS and TIFFTAG_FAXRECVTIME + tags as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=736 + + * libtiff/tif_win32.c: Fixed message formatting in functions + Win32WarningHandler() and Win32ErrorHandler() as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=735 + + * tools/tiff2ps.c: Interpret the -w and -h options independently. As + per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=689 + +2005-01-11 Andrey Kiselev + + * libtiff/tiffio.h: Move the color conversion routines in the 'extern + "C"' section as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=727 + + * libtiff/tiff.h: Restore back the workaround for AIX Visual Age C + compiler to avoid double definition of BSD types as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=39 + + * libtiff/Makefile.am: Place the C++ stream API in the separate + library called libtiffxx to avoid unneeded dependencies. Probably + there will be more C++ API in the future. As per bugs + + http://bugzilla.remotesensing.org/show_bug.cgi?id=733 + + and + + http://bugzilla.remotesensing.org/show_bug.cgi?id=730 + +2005-01-05 Andrey Kiselev + + * tools/tiffdump.c: Fixed problem when read broken TIFFs with the + wrong tag counts (Dmitry V. Levin, Martin Pitt). + + * configure.ac: Replace --disable-c++ with the --disable-cxx option as + per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=730 + +2004-12-25 Andrey Kiselev + + * libtiff/tif_getimage.c: More fixes for multiple-alpha-channelled + RGB-images as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=713 + + + * tools/tiffset.c: Convert character option to integer value as per + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=725 + +2004-12-20 Andrey Kiselev + + * libtiff 3.7.1 released. + + * html/tiffset.1.html: Add missed manual page as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=678 + + * libtiff/tiff.h: Revert back libtiff data type definitions as per + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=687 + +2004-12-19 Andrey Kiselev + + * libtiff/tif_dirread.c: Do not forget about TIFF_VARIABLE2 when + checking for tag count in TIFFReadDirectory() function. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=713 + + * libtiff/{tif_dirread.c, tif_fax3.c}: More argument checking in + CheckMallock() function. + + * libtiff/tif_getimage.c: Support for multiple-alpha-channelled + RGB-images as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=718 + +2004-12-15 Frank Warmerdam + + * libtiff/tif_getimage.c: #define A1 bracketing for clean build on + SunPro compiler. + +2004-12-11 Bob Friesenhahn + + * autogen.sh: aclocal and autoheader should be executed after + libtoolize. Also add '-I .' to aclocal invocation to check + current directory for macros. + +2004-12-10 Andrey Kiselev + + * libtiff/tif_dirwrite.c: Always write TIFFTAG_SUBIFD using LONG type + as per bugs + + http://bugzilla.remotesensing.org/show_bug.cgi?id=703 + + and + + http://bugzilla.remotesensing.org/show_bug.cgi?id=704 + +2004-12-04 Andrey Kiselev + + * nmake.opt: Link with the user32.lib in windowed mode. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=697 + + * libtiff/tif_win32.c: Use char* strings instead of TCHAR in windowed + mode as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=697 + + * libtiff/tif_config.in.vc: Removed unneded definitions for + read/open/close/lseek functions to fix the + + http://bugzilla.remotesensing.org/show_bug.cgi?id=680 + +2004-12-03 Andrey Kiselev + + * libtiff/{tif_dir.c, tif_dirread.c}: Remove TIFFReassignTagToIgnore() + call from the TIFFReadDirectory() function. TIFFReassignTagToIgnore + must be removed in the future, as it was never used properly. As per + bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=692 + +2004-11-30 Bob Friesenhahn + + * libtiff/tif_jpeg.c: Added a work-around in order to allow + compilation with the heavily modified version of libjpeg delivered + with Cygwin. + +2004-11-29 Andrey Kiselev + + * libtiff/tif_dir.c: Properly handle tags, which have the uint32 + counts. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=693 + + * tools/fax2ps.c: Be able to extract the first page (#0). As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=690 + +2004-11-28 Andrey Kiselev + + * libtiff/tif_unix.c: Make UNIX module compilable (and usable) + on Windows. + + * nmake.opt: Add missed DLLNAME variable. + +2004-11-26 Frank Warmerdam + + * libtiff/makefile.vc: make it easier to rename the libtiff DLL. + +2004-11-24 Andrey Kiselev + + * man/libtiff.3tiff: Improvements in the "LIST OF ROUTINES" table as + per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=545 + + * man/tiffset.1: Added manual page for tiffset tool written by Jay + Berkenbilt. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=678 + +2004-11-23 Frank Warmerdam + + * libtiff/tif_error.c: fixed TIFFerror call to be TIFFError. + +2004-11-21 Frank Warmerdam + + * html/document.html: Updated Adobe web links as per email from Joris. + +2004-11-21 Andrey Kiselev + + * libtiff/{tiffio.hxx, tiffio.h}: C++ stream interface moved to new + file tiffio.hxx. We don't have any C++ in tiffio.h, those who want to + use C++ streams should #include . + +2004-11-13 Andrey Kiselev + + * libtiff/tiff.h: Added Adobe DNG tags. + + * libtiff/tif_win32.c: Typo fixed. + + * libtiff/{tif_stream.cxx, tiffio.h}: C++ stream interface updated to + be compliant with the latest standard. Appropriate additions in + makefiles now completed. + +2004-11-11 Andrey Kiselev + + * tools/tiffset.c, libtiff/tif_dirinfo.c: Properly handle the + different tag types. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=600 + +2004-11-10 Andrey Kiselev + + * libtiff/tif_aux.c: Set the appropriate ReferenceBlackWhite array for + YCbCr image which lacks that tag (noted by Hans Petter Selasky). + +2004-11-09 Andrey Kiselev + + * libtiff/tif_color.c: Division by zero fixed (Hans Petter Selasky). + +2004-11-07 Andrey Kiselev + + * libtiff/{tif_stream.cxx, tiffio.h}: Added C++ stream interface + contributed by Edward Lam (see + http://bugzilla.remotesensing.org/show_bug.cgi?id=654 for details). + Though no changes in any makefiles yet. + +2004-11-05 Frank Warmerdam + + * libtiff/tif_open.c: Removed close() in TIFFClientOpen() if file + is bad. This is the callers responsibility. + http://bugzilla.remotesensing.org/show_bug.cgi?id=651 + +2004-11-05 Andrey Kiselev + + * libtiff/{tiffio.h, tif_win32.c, libtiff.def}: Added TIFFOpenW() + function to work with the double byte strings (used to represent + filenames in some locales). As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=625 + + * libtiff/tif_dirread.c: Fixed problem when fetching BitsPerSample and + Compression tags of type LONG from broken TIFFS as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=662 + + * libtiff/tif_dirinfo.c: Fixed definition for TIFFTAG_RICHTIFFIPTC, + the writecount should have uint32 type. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=662 + + * libtiff/tif_write.c: Fixed wrong if() statement in + TIFFAppendToStrip() function as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=660 + +2004-11-04 Andrey Kiselev + + * libtiff/tif_dirinfo.c: Change definition for TIFFTAG_EXTRASAMPLES + field. The caller should supply a count when setting this field. As + per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=648 + + * libtiff/{tif_jpeg.c, tif_ojpeg.c}: TIFFTAG_JPEGTABLES should have + uint32 count. Use this type everywhere. + +2004-11-03 Frank Warmerdam + + * libtiff/tif_next.c: avoid use of u_long and u_char types. Bug 653. + +2004-11-02 Frank Warmerdam + + * tools/tiff2rgba.c: removed extra newlines in usage message. + +2004-10-30 Andrey Kiselev + + * libtiff/tif_dirwrite.c: Improvements in tag writing code. + + * tools/tiff2ps.c: Fixed wrong variable data type when read Position + tags (Tristan Hill). + +2004-10-30 Frank Warmerdam + + * libtiff/tiffiop.h: added fallback definition of assert() if we + don't have assert.h. + +2004-10-29 Andrey Kiselev + + * libtiff/tif_fax3.c: Fixed case with the wrong decode routines + choosing when the incorrect Group4Options tag set. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=323 + + * libtiff/tif_dirwrite.c: Fixed problem with passing count variable of + wrong type when writing the TIFF_BYTE/TIFF_SBYTE tags in + TIFFWriteNormalTag(). + +2004-10-28 Andrey Kiselev + + * tools/tiff2ps.c: Fixed wrong variable data type when read Resolution + tags (Peter Fales). + + * tools/{bmp2tiff.c, raw2tiff.c}: Get rid of stream I/O functions. + +2004-10-28 Frank Warmerdam + + * tools/tiff2pdf.c: added casts to avoid warnings. + + * libtiff/libtiff.def: Added several more entry points required + to link fax2tiff.c against the DLL on windows. + +2004-10-27 Andrey Kiselev + + * configure, configure.ac: Added --enable-rpath option to embed linker + paths into library binary. + +2004-10-26 Andrey Kiselev + + * tools/tiffset.c: Check the malloc return value (Dmitry V. Levin). + + * libtiff/{tif_strip.c, tif_tile.c}: Zero division problem fixed + (Vladimir Nadvornik, Dmitry V. Levin). + +2004-10-16 Andrey Kiselev + + * libtiff 3.7.0 released. + +2004-10-15 Bob Friesenhahn + + * libtiff/tif_jpeg.c: There seems to be no need to include stdio.h + in this file so its inclusion is removed. Including stdio.h + sometimes incurs an INT32 typedef conflict between MinGW's + basetsd.h and libjpeg's jmorecfg.h. + +2004-10-15 Andrey Kiselev + + * man/bmp2tiff.1: Added manual page for bmp2tiff utility. + +2004-10-13 Bob Friesenhahn + + * tools/tiffcmp.c (leof): Renamed from 'eof' in order to avoid + conflict noticed under MinGW. + * ltmain.sh: Fix for MinGW compilation. + +2004-10-13 Frank Warmerdam + + * man/tiffsplit.1: Fixed to indicate using aaa-zzz, not aa-zz. + http://bugzilla.remotesensing.org/show_bug.cgi?id=635 + +2004-10-12 Andrey Kiselev + + * libtiff/{tif_dirread.c, tif_jpeg.c, tif_luv.c, tif_ojpeg.c, + tif_pixarlog.c, tif_write.c}: Handle the zero strip/tile sizes + properly (Dmitry V. Levin, Marcus Meissner). + +2004-10-11 Andrey Kiselev + + * libtiff/tif_dirinfo.c: Type of the TIFFTAG_SUBIFD field changed + to TIFF_IFD. + +2004-10-10 Andrey Kiselev + + * tools/bmp2tif.c: Check the space allocation results. + +2004-10-09 Andrey Kiselev + + * libtiff/tif_dir.c: Initialize td_tilewidth and td_tilelength fields + of the TIFFDirectory structure with the 0 instead of -1 to avoid + confusing integer overflows in TIFFTileRowSize() for striped images. + + * tools/tiff2pdf.c: Fixed TransferFunction tag handling reported + by Ross A. Finlayson. + + * libtiff/tif_dir.c: Fixed custom tags handling as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=629 + +2004-10-08 Frank Warmerdam + + * libtiff/tif_dirinfo.c: Fix bug with tif_foundfield and reallocation + of tif_fieldinfo. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=630 + +2004-10-04 Bob Friesenhahn + + * contrib/iptcutil/README: Added the missing README which goes + along with iptcutil. + +2004-10-03 Andrey Kiselev + + * libtiff/tif_compress.c: Improved error reporting in + TIFFGetConfiguredCODECs() (Dmitry V. Levin). + +2004-10-02 Andrey Kiselev + + * libtiff 3.7.0beta2 released. + + * libtiff/{tif_aux.c, tif_compress.c, tif_dirinfo.c, tif_dirwrite.c, + tif_extension.c, tif_fax3.c, tif_luv.c, tif_packbits.c, + tif_pixarlog.c, tif_write.c}: Added checks for failed memory + allocations and integer overflows (Dmitry V. Levin). + + * libtiff/tiff.h: Missed TIFF_BIGTIFF_VERSION constant added. + +2004-10-01 Frank Warmerdam + + * libtiff/tif_open.c: added a more informative message if a BigTIFF + file is opened. + +2004-09-30 Frank Warmerdam + + * libtiff/tif_dirinfo.c: changed type of XMLPacket (tag 700) to + TIFFTAG_BYTE instead of TIFFTAG_UNDEFINED to comply with the info + in the Adobe XMP Specification. + +2004-09-29 Andrey Kiselev + + * libtiff/{tif_jpeg.c, tif_pixarlog.c}: Use _TIFFmemset() instead of + memset(). + + * libtiff/{tif_dirread.c, tif_strip.c, tif_tile.c}: Applied patches + from Dmitry V. Levin to fix possible integer overflow problems. + +2004-09-28 Andrey Kiselev + + * libtiff/tif_getimage.c: Check for allocated buffers before clearing + (Dmitry V. Levin). + +2004-09-26 Andrey Kiselev + + * libtiff/{tif_dir.h, tif_dir.c, tif_dirread.c, tif_write.c}: + Optimize checking for the strip bounds. + + * libtiff/{tif_dirread.c, tif_strip.c}: TIFFScanlineSize() and + TIFFRasterScanlineSize() functions report zero in the case of integer + overflow now. Properly handle this case in TIFFReadDirectory() + (patches from Dmitry V. Levin). + +2004-09-25 Andrey Kiselev + + * libtiff/{tif_dirinfo.c, tif_strip.c, tif_tile.c}: Use TIFFhowmany8() + macro where appropriate. + + * tools/tiff2bw.c: Write ImageWidth/Height tags to output file, as + noted by Gennady Khokhorin. + + * libtiff/tif_dirread.c: Always check the return values, returned + by the _TIFFmalloc() (Dmitry V. Levin). + + * libtiff/tif_dir.c: Fixed possible integer overflow _TIFFset*Array() + functions (Dmitry V. Levin). + + * libtiff/{tif_dirread.c, tif_dir.c, tif_write.c}: + Potential memory leak fixed in TIFFReadDirectory(), _TIFFVSetField(), + TIFFGrowStrips() (found by Dmitry V. Levin). + +2004-09-24 Andrey Kiselev + + * libtiff/{tiffio.h, tif_compress.c}: Added TIFFGetConfiguredCODECs() + to get the list of configured codecs. + + * libtiff/{tiffiop.h, tif_dirread.c}: More overflow fixes from + Dmitry V. Levin. + +2004-09-23 Andrey Kiselev + + * libtiff/tif_dirread.c: Applied patch from Dmitry V. Levin to fix + possible integer overflow in CheckMalloc() function. + +2004-09-22 Andrey Kiselev + + * libtiff/{tiffiop.h, tif_strip.c}: Use TIFFhowmany8() macro instead + of plain TIFFhowmany() where appropriate. + +2004-09-21 Andrey Kiselev + + * libtiff/tif_getimage.c: Initialize arrays after space allocation. + +2004-09-19 Andrey Kiselev + + * libtiff 3.7.0beta released. + + * libtiff/{tif_luv.c, tif_next.c, tif_thunder.c}: Several buffer + overruns fixed, as noted by Chris Evans. + +2004-09-14 Bob Friesenhahn + + * commit: Added a script to make it more convenient to commit + updates. The CVS commit message is extracted from this ChangeLog + file. + +2004-09-14 Andrey Kiselev + + * configure.ac, configure, aclocal.m4, libtiff/{mkspans.c, tif_fax3.c, + tif_getimage.c, tif_luv.c, tif_lzw.c, tif_ojpeg.c, tif_packbits.c, + tif_predict.c, tif_read.c, tif_swab.c, tif_thunder.c, tif_write.c, + tif_dir.c, tif_dirread.c, tif_dirwrite.c, tif_jpeg.c, tif_dirinfo.c, + tif_vms.c, tif_print.c, tif_strip.c, tif_tile.c, tif_dir.h, + tif_config.h.in, tiffiop.h}: + Get rid of BSD data types (u_char, u_short, u_int, u_long). + +2004-09-13 Bob Friesenhahn + + * libtiff/tiff.h: Fix column tagging. Reference current Adobe XMP + specification. Reference libtiff bug tracking system to submit + private tag additions. + +2004-09-12 Bob Friesenhahn + + * tools/tiffgt.c: Include "tif_config.h". + + * configure.ac: Use AM_PROG_CC_C_O since it is now needed to build + tiffgt. This results in the 'compile' script being added to the + project. + + * tools/Makefile.am (tiffgt_CFLAGS): Add extra build options + required to find OpenGL headers necessary to build tiffgt. Also + ensure that the libtiff that we built is used rather than some other + libtiff installed on the system. + +2004-09-12 Andrey Kiselev + + * configure.ac, acinclude.m4, aclocal.m4: New macros to detect GLUT + libraries. + +2004-09-11 Bob Friesenhahn + + * configure.ac: Pass library configuration defines via + tif_config.h rather than extending CPPFLAGS. Configure a + libtiff/tiffconf.h in order to satisfy application requirements + (not used by library build). Do not define _POSIX_C_SOURCE=2 since + this causes failure to build on systems which properly respect + this request. + + * libtiff/tiffconf.h.in: New file to act as the template for the + configured tiffconf.h + + * libtiff/files.lst (HDRS): Install the configured tiffconf.h. + +2004-09-10 Frank Warmerdam + + * html/internals.html: Split off a discussion of adding new tags + into addingtags.html. + +2004-09-10 Andrey Kiselev + + * test/{ascii_tag.c, long_tag.c}: Preliminary test suite added. + + * tools/tiff2pdf.c: Fixed reading TransferFunction tag as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=590 + + * libtiff/tif_print.c: Fixes in InkNames and NumberOfInks reporting. + + * libtiff/tif_dirread.c: Don't reject to read tags of the + SamplesPerPixel size when the tag count is greater than number of + samples as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=576 + + * libtiff/tiff.h: Use _TIFF_DATA_TYPEDEFS_ guardian to switch off + defining int8/uint8/... etc. types. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=607 + +2004-09-09 Frank Warmerdam + + * tools/tiff2ps.c, tools/tiffmedian.c: fiddle with include files + to avoid compile warnings about getopt() and a few other things. + +2004-09-02 Andrey Kiselev + + * libtiff/tif_dirread.c: Use memcpy() function instead of pointer + assigning magic in TIFFFetchFloat(). + +2004-09-01 Andrey Kiselev + + * libtiff/{tiffio.h, tif_open.c}: Applied patches from Joris Van Damme + to avoid requirement for tiffiop.h inclusion in some applications. See + here + + http://www.asmail.be/msg0054799560.html + + for details. + + * tools/fax2tiff.c: Use the new functions in the code. + +2004-08-25 Andrey Kiselev + + * tools/tiff2pdf.c: Initialize arrays properly. + + * tools/tiff2ps.c: Avoid zero division in setupPageState() function; + properly initialize array in PSDataBW(). + +2004-08-24 Andrey Kiselev + + * tools/tiff2pdf.c: More fixes for bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=590 + + from Ross Finlayson. + +2004-08-23 Andrey Kiselev + + * tools/tiff2ps.c: Fixed problem with uninitialized values. + + * libtiff/tif_dir.c: Initialize tif_foundfield data member in the + TIFFDefaultDirectory() (in addition to 2004-08-19 fix). + + * tools/tiff2pdf.c: Fixed a bunch of problems as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=590 + +2004-08-20 Andrey Kiselev + + * tools/tiff2pdf.c: Applied patch from Ross Finlayson that checks + that the input file has compression, photometric interpretation, + etcetra, tags or if not than a more descriptive error is returned. + + * libtiff/tif_dirread.c: Fixed problem in TIFFReadDirectory() in the + code, responsible for tag data type checking. + +2004-08-19 Andrey Kiselev + + * libtiff/{tiffiop.h, tif_dirinfo.c}: Fixed problem with the static + variable as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=593 + +2004-08-16 Andrey Kiselev + + * tools/ras2tiff.c: Fixed issue with missed big-endian checks as per + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=586 + +2004-08-01 Andrey Kiselev + + * libtiff/{tif_config.h.in, tif_config.h.vc}: config.h.in and + config.h.vc files renamed in the tif_config.h.in and tif_config.h.vc. + +2004-07-24 Andrey Kiselev + + * libtiff/tif_lzw.c: LZW compression code is merged back from the + separate package. All libtiff tools are updated to not advertise an + abcence of LZW support. + +2004-07-12 Andrey Kiselev + + * libtiff/tiffio.h: Revert thandle_t back to void* type. + +2004-07-11 Andrey Kiselev + + * libtiff/{tif_read.c, tif_tile.c, tif_strip.c}: Fixes in error + messages, as suggested by Bernd Herd. + +2004-07-03 Andrey Kiselev + + * libtiff/tif_dir.c: Call TIFFError() instead of producing warnings + when setting custom tags by value. Reported by Eric Fieleke. + +2004-06-14 Andrey Kiselev + + * tools/bmp2tiff.c: Add missed RawsPerStrip setting. + +2004-06-08 Andrey Kiselev + + * tools/bmp2tiff.c: Added new utility to convert Windows BMP files + into TIFFs. + +2004-06-07 Andrey Kiselev + + * libtiff 3.7.0alpha released. + +2004-06-06 Andrey Kiselev + + * libtiff/{tiff.h, tif_dirwrite.c, tif_fax3.c, tif_packbits.c,}: Get rid + of ugly 64-bit hacks, replace them with the clever (autoconf based ) + ones :-). + + * libtiff/tiffio.h: Define thandle_t as int, not void* (may cause + problems in 64-bit environment). + +2004-06-05 Andrey Kiselev + + * tools/tiffset.c: tiffset now can set any libtiff supported tags. + Tags can be supplied by the mnemonic name or number. + + * libtiff/{tiffio.h, tif_dir.h, tif_dirinfo.c,}: Added two new + functions TIFFFindFieldInfoByName() and TIFFFieldWithName(). + +2004-05-27 Andrey Kiselev + + * libtiff/tif_ojpeg.c: Fixed problem with duplicated SOI and SOF + markers as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=581 + +2004-05-24 Andrey Kiselev + + * tools/tiffsplit.c: Don't forget to copy Photometric + Interpretation tag. + +2004-05-20 Andrey Kiselev + + * libtiff/{tif_open.c, tiffio.h}: New function added: + TIFFIsBigEndian(). Function returns nonzero if given was file written + in big-endian order. + + * tools/tiffsplit.c: Fixed problem with unproperly written multibyte + files. Now output files will be written using the same byte order + flag as in the input image. See + + http://bugzilla.remotesensing.org/show_bug.cgi?id=574 + + for details. + +2004-05-19 Frank Warmerdam + + * libtiff/tif_print.c: added (untested) support for printing + SSHORT, SLONG and SRATIONAL fields. + + * tools/tiffcp.c: close output file on normal exit. + +2004-05-17 Andrey Kiselev + + * libtiff/tif_fax3.c: Avoid reading CCITT compression options + if compression type mismatches. See + + http://bugzilla.remotesensing.org/show_bug.cgi?id=565 + +2004-04-30 Andrey Kiselev + + * libtiff/tif_strip.c: Never return 0 from the + TIFFNumberOfStrips(). + +2004-04-29 Andrey Kiselev + + * libtiff/tif_dirread.c: Workaround for broken TIFF writers which + store single SampleFormat value for multisampled images. See + + http://bugzilla.remotesensing.org/show_bug.cgi?id=562 + +2004-04-25 Andrey Kiselev + + * configure.ac, libtiff/{tiff.h, config.h.in}: Added tests for int8, + int16 and int32 types to avoid complains on some compilers. Details at + + http://bugzilla.remotesensing.org/show_bug.cgi?id=39 + +2004-04-20 Andrey Kiselev + + * tools/tiff2pdf.c: Fixed problem with unaligned access as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=555 + +2004-04-14 Andrey Kiselev + + * libtiff/tif_write.c: Allow in-place updating of the compressed + images (don't work properly with all codecs). For details see GDAL bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=534 + +2004-04-06 Andrey Kiselev + + * libtiff/tif_jpeg.c: Workaround for wrong sampling factors used + in the Intergarph JPEG compressed TIFF images as per bug: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=532 + +2004-04-04 Frank Warmerdam + + * libtiff/tif_open.c: close clientdata if TIFFClientOpen() fails + via bad2. + +2004-03-26 Andrey Kiselev + + * tools/tiffcp.c: Properly set Photometric Interpretation in case of + JPEG compression of grayscale images. + + * tools/tiffcp.c: Don't emit warnings when Orientation tag does not + present in the input image. + +2004-03-19 Andrey Kiselev + + * {many}: The first attempt to switch to autotools. + +2004-03-03 Andrey Kiselev + + * libtiff/tif_open.c: Use dummy mmap/munmap functions in + TIFFClientOpen() when the appropriate client functions was not + supplied by user. + +2004-03-02 Frank Warmerdam + + * tools/ycbcr.c: fixed main() declaration as per: + http://bugzilla.remotesensing.org/show_bug.cgi?id=513 + +2004-02-26 Andrey Kiselev + + * tools/tiffsplit.c: Copy JPEGTables tag contents for JPEG compressed + images. Reported by Artem Mirolubov. + + * libtiff/tif_dirread.c: Fixed problem with handling TIFF_UNDEFINED + tag type in TIFFFetchNormalTag() as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=508 + +2004-02-17 Frank Warmerdam + + * libtiff/tif_codec.c: Fixed typo in TIFFInitPackBits name as per: + http://bugzilla.remotesensing.org/show_bug.cgi?id=494 + +2004-02-05 Andrey Kiselev + + * libtiff/tif_fax3.c: Fixed problem with CCITT encoding modes as per + bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=483 + + But we need more work on fax codec to support update mode. + +2004-01-30 Frank Warmerdam + + * libtiff/libtiff.def: Added TIFFCurrentDirOffset, TIFFWriteCheck, + TIFFRGBAImageOK, and TIFFNumberOfDirectories as suggested by + Scott Reynolds. + +2004-01-29 Andrey Kiselev + + * libtiff/tiff.h: Fixed tag definitions for TIFFTAG_YCLIPPATHUNITS + and TIFFTAG_INDEXED as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=475 + + * libtiff/{tif_win32.c, tif_unix.c}: Check whether the pointer is + NULL before proceeding further as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=474 + + Check results, returned by the TIFFFdOpen() before returning and close + file if TIFFFdOpen() failed as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=468 + + * libtiff/tif_open.c: More fixes for + + http://bugzilla.remotesensing.org/show_bug.cgi?id=468 + +2004-01-28 Andrey Kiselev + + * libtiff/{libtiff.def, tif_close.c, tiffio.h, tif_open.c}: Separate + TIFFCleanup() from the TIFFClose() in order to fix the bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=468 + + * tools/tiffcp.c: Fixed problem with wrong interpretation of the + InkNames tag as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=466 + + Memory leak fixed. + +2004-01-21 Frank Warmerdam + + * libtiff/tif_dirwrite.c: Fixed handling of writable ASCII tags that + are field_passcount=TRUE properly. Arguably anonymous custom tags + should be declared as passcount=FALSE, but I don't want to change + that without a careful review. + +2004-01-20 Andrey Kiselev + + * libtiff/tif_write.c: Fixed reporting size of the buffer in case of + stripped image in TIFFWriteBufferSetup(). As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=460 + +2004-01-11 Andrey Kiselev + + * libtiff/tif_dir.c: Incomplete cleanup in TIFFFreeDirectory(), + patch from Gerben Koopmans. + + * libtiff/tif_dirread.c: Check field_passcount value before setting + the value of undefined type, patch from Gerben Koopmans. + +2004-01-02 Andrey Kiselev + + * tools/tiffcp.c: Fixed problem with wrong Photometric setting for + non-RGB images. + +2003-12-31 Andrey Kiselev + + * libtiff/tif_win32.c: Fixed problem with _TIFFrealloc() when the NULL + pointer passed. Patch supplied by Larry Grill. + + * libtiff/{tiff.h, tif_fax3.c}:Fixes for AMD 64 platform as + suggested by Jeremy C. Reed. + +2003-12-26 Andrey Kiselev + + * libtiff 3.6.1 released. + +2003-12-24 Andrey Kiselev + + * config.guess, config.sub: Updated from the recent upstream. + +2003-12-22 Andrey Kiselev + + * libtiff/{tif_color, tif_getimage.c, tiffio.h}, man/TIFFcolor.3t: + More cleanups in color conversion interface, added appropriate manual + page. + +2003-12-19 Andrey Kiselev + + * libtiff/{tif_extension.c, tif_dirinfo.c, tiff.h}: Warnings fixed as + per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=357 + + * tools/tiff2ps.c: Added support for alpha channel. Fixes + + http://bugzilla.remotesensing.org/show_bug.cgi?id=428 + + * libtiff/{libtiff.def, tif_color.c, tif_getimage.c, tiffio.h}: + Interface for Lab->RGB color conversion is finally cleaned up. + Added support for ReferenceBlackWhite tag handling when converted from + YCbCr color space. The latter closes + + http://bugzilla.remotesensing.org/show_bug.cgi?id=120 + +2003-12-07 Andrey Kiselev + + * libtiff/{tif_getimage.c, tiffio.h}: Avoid warnings. + + * libtiff/makefile.vc, tools/makefile.vc: Support for IJG JPEG + library. + +2003-12-06 Andrey Kiselev + + * libtiff/{tif_getimage.c, tif_aux.c}: Read WhitePoint tag from the + file and properly use it for CIE Lab->RGB transform. + +2003-12-04 Andrey Kiselev + + * libtiff/{tif_getimage.c, tif_color.c, tiffio.h}: YCbCr->RGB + conversion routines now in the tif_color.c module. New function + TIFFYCbCrtoRGB() available in TIFF API. + + * libtiff/tif_dirwrite.c: Handle TIFF_IFD tag type correctly. + +2003-12-03 Andrey Kiselev + + * libtiff/{tif_getimage.c, tif_color.c, tiffio.h}: Improvements in + CIE Lab conversion code. Start moving YCbCr stuff to the tif_color.c + module. + + * libtiff/{tif_getimage.c, tiffio.h}, man{TIFFReadRGBAImage.3t, + TIFFReadRGBAStrip.3t, TIFFReadRGBATile.3t, TIFFRGBAImage.3t}: + Finally resolved problems with orientation handling. TIFFRGBAImage + interface now properly supports all possible orientations, i.e. images + will be flipped both in horizontal and vertical directions if + required. 'Known bugs' section now removed from the appropriate manual + pages. Closed bug entry: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=322 + +2003-12-02 Andrey Kiselev + + * libtiff/tif_dir.c: Fixed order of the parameters in TIFFError() + function calls as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=440 + +2003-11-28 Ross Finlayson + + * tools/tiff2pdf.c: Some bugs fixed. + +2003-11-27 Andrey Kiselev + + * libtiff/tif_luv.c: Fixed bug in 48-bit to 24-bit conversion routine, + reported by Antonio Scuri. + + * man/tiff2pdf.1: Few improvements in page layout. + + * Makefile.in, /man/Makefile.in, /html/man/tiff2pdf.1.html: + Added support fpr tiff2pdf manual page. + +2003-11-26 Ross Finlayson + + * /man/tiff2pdf.1: File added to repository. + +2003-11-26 Andrey Kiselev + + * Makefile.in, /tools/{Makefile.in, makefile.vc}: + Added support fpr tiff2pdf utility. + +2003-11-25 Ross Finlayson + + * /tools/tiff2pdf.c: File added to repository. + +2003-11-22 Andrey Kiselev + + * /tools/raw2tiff.c: sqrtf() replaced with sqrt(). + +2003-11-21 Andrey Kiselev + + * /tools/raw2tiff.c: #include removed. + + * tools/{Makefile.in, tiffgt.c}: Unmaintained and platform dependent + sgigt utility removed and replaced with the completely rewritten + portable tiffgt tool (depend on OpenGL and GLUT). Initial revision, + there is a lot of things to improve. + + * libtiff/tif_ojpeg.c: TIFFVGetField() function now can properly + extract the fields from the OJPEG files. Patch supplied by Ross + Finlayson. + + * libtiff/{tiffio.h, tif_codec.c}, man/{libtiff.3t, TIFFcodec.3t}: + Added new function TIFFIsCODECConfigured(), suggested by Ross + Finlayson. + +2003-11-18 Andrey Kiselev + + * libtiff/tif_dirinfo.c: Implemented binary search in + _TIFFMergeFieldInfo(). Patch supplied by Ross Finlayson. + + * libtiff/tif_dir.h: _TIFFFindOrRegisterdInfo declaration replaced + with _TIFFFindOrRegisterFieldInfo as reported by Ross Finlayson. + +2003-11-17 Frank Warmerdam + + * tif_dirread.c: do not mark all anonymously defined tags to be + IGNOREd. + +2003-11-17 Andrey Kiselev + + * contrib/pds/{tif_pdsdirread.c, tif_pdsdirwrite.c}: Use + TIFFDataWidth() function insted of tiffDataWidth array. + +2003-11-16 Andrey Kiselev + + * libtiff/{tiff.h, tif_dirinfo.c}: Added support for IFD (13) + datatype, intruduced in "Adobe PageMaker TIFF Tech. Notes". + +2003-11-15 Frank Warmerdam + + * Makefile.in: fixed missing backslash for tif_color.c in list. + +2003-11-13 Andrey Kiselev + + * libtiff/{tif_color.c, tif_getimage.c, tiffio.h, Makefile.in}: + New color space conversion code: CIE L*a*b* 1976 images now supported + by the TIFFRGBAImage interface. All introduced routines go to new + module tif_color.c. Eventually all color conversion functions should + be moved there. + +2003-11-12 Andrey Kiselev + + * tools/{ras2tiff.c, rasterfile.h}: Properly determine SUN Rasterfiles + with the reverse byte order (it is reported by the magic header + field). Problem reported by Andreas Wiesmann. + + * tools/raw2tiff.c, man/raw2tiff.1: Few improvements in correlation + calculation function. Guessing mechanics now documented in manual page. + +2003-11-11 Andrey Kiselev + + * tools/raw2tiff.c: Implemented image size guessing using + correlation coefficient calculation between two neighbour lines. + +2003-11-09 Frank Warmerdam + + * libtiff/tif_tile.c: remove spurious use of "s" (sample) in the + planarconfig_contig case in TIFFComputeTile(). + + http://bugzilla.remotesensing.org/show_bug.cgi?id=387 + +2003-11-09 Andrey Kiselev + + * libtiff/tiffiop.h: New macros: TIFFmax, TIFFmin and TIFFrint. + +2003-11-07 Andrey Kiselev + + * libtiff/{tiffio.h, tif_strip.c}, man/{TIFFstrip.3t, libtiff.3t}: + Added TIFFRawStripSize() function as suggested by Chris Hanson. + +2003-11-03 Andrey Kiselev + + * libtiff/{tif_lzw.c, tif_fax3.c}: Proper support for update mode as + per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=424 + +2003-10-29 Andrey Kiselev + + * libtiff/libtiff.def: Added TIFFReadRGBAImageOriented. + + * html/build.html: Added note about GNU make requirement. + +2003-10-25 Andrey Kiselev + + * Makefile.in: Fixes in using MAKEFLAGS as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=418 + + * port/install.sh.in: Option -p added to the mkdir command to create + all directory tree structure before installing. + +2003-10-18 Andrey Kiselev + + * /tools/tiff2ps.c: #include replaced with the + #include . + +2003-10-16 Andrey Kiselev + + * Makefile.in: Add an absolute path to the test_pics.sh call. + +2003-10-12 Andrey Kiselev + + * libtiff/tiffcomp.h: #define _BSDTYPES_DEFINED when defining BSD + typedefs. + +2003-10-09 Andrey Kiselev + + * configure, libtiff/{Makefile.in, mkversion.c}: + Relative buildings fixed. + + * tools/Makefile.in: Added "-I../libtiff" to the tiffset building + rule. + +2003-10-07 Andrey Kiselev + + * Makefile.in: Added missed v3.6.0.html. + + * libtiff/tiffio.h: Typo fixed: ORIENTATION_BOTTOMLEFT replaced with + ORIENTATION_BOTLEFT. + +2003-10-04 Andrey Kiselev + + * 3.6.0 final release. + +2003-10-03 Andrey Kiselev + + * libtiff/{tif_getimage.c, tiffio.h}, man/TIFFReadRGBAImage.3t: New + function TIFFReadRGBAImageOriented() implemented to retrieve raster + array with user-specified origin position as suggested by Jason Frank. + See + + http://bugzilla.remotesensing.org/show_bug.cgi?id=322 + + for details. + + * tools/tiff2rgba.c: Switched to use TIFFReadRGBAImageOriented() + instead of TIFFReadRGBAImage(). + + * tools/tiff2ps.c: Fixed possible endless loop as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=404 + +2003-09-30 Andrey Kiselev + + * libtiff/tif_dirread.c: Check field counter against number of fields + in order to fix + + http://bugzilla.remotesensing.org/show_bug.cgi?id=366 + + * libtiff/tif_fax3.c: Fix wrong line numbering as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=342 + +2003-09-25 Andrey Kiselev + + * libtiff/{tiffiop.h, tif_dirread.c, tif_dir.c, tif_open.c, + tif_close.c}: Store a list of opened IFD to prevent looping as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=383 + +2003-09-23 Andrey Kiselev + + * libtiff/tif_dirread.c: More fixes for EstimateStripByteCounts(). See + + http://bugzilla.remotesensing.org/show_bug.cgi?id=358 + +2003-08-21 Andrey Kiselev + + * tools/tiffmedian.c: int declaration replaced with the uint32 to + support large images as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=382 + +2003-08-12 Andrey Kiselev + + * libtiff/Makefile.in: Fixed problem with building in different + directory. + + * tools/tiff2ps.c: Added missing #include . + + * libtiff/tif_dirwrite.c: More fixes for custom tags code + from Ashley Dreier. + +2003-08-07 Andrey Kiselev + + * tools/tiff2ps.c: Added page size setting when creating PS Level 2. + Patch submitted by Balatoni Denes (with corrections from Tom + Kacvinsky). + + * tools/tiff2ps.c: Fixed PS comment emitted when FlateDecode is + being used. Reported by Tom Kacvinsky. + + * libtiff/tif_dirwrite.c: Fixed problem with custom tags writing, + reported by Ashley Dreier. + + * libtiff/tif_print.c: Fixed problem with float tags reading, support + for printing RATIONAL and BYTE tags added. + +2003-08-05 Andrey Kiselev + + * libtiff/tif_lzw.c: Move LZW codec state block allocation back to + TIFFInitLZW(), because its initialization in LZWSetupDecode() cause + problems with predictor initialization. Remove O_RDONLY check during + state block allocation to be able open LZW compressed files in update + mode. + + Problem exist for libtiff version of the tif_lzw.c module. One from + lzw-compression-kit hasn't such troubles. + +2003-08-04 Frank Warmerdam + + * libtiff/tif_write.c: modified tif_write.c so that the various + encoded write functions use tif_postdecode() to apply byte order + swapping (swab) to the application passed data buffer if the same + would be done when reading. This allows us to write pixel data with + more than 8 bits per sample to existing files of a non-native byte + order. One side effect of this change is the applications buffer + itself is altered in this case by the act of writing. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=171 + +2003-07-25 Frank Warmerdam + + * libtiff/tif_open.c: avoid signed/unsigned casting warning + initializing typemask as per patch from J.A. Strother. + + * tools/tiffcp.c: fixed signed/unsigned casting warning. + + * libtiff/tif_print.c: dos2unix conversion. + + * tools/tiffsplit.c: increased the maximum number of pages that + can be split. Patch provided by Andrew J. Montalenti. + +2003-07-11 Andrey Kiselev + + * tools/raw2tiff.c: Added option `-p' to explicitly select color + space of input image data. Closes + + http://bugzilla.remotesensing.org/show_bug.cgi?id=364 + +2003-07-08 Frank Warmerdam + + * tif_aux.c, tif_codec.c, tif_dir.c, tif_dirread.c, tif_extension.c, + tif_fax3.c, tif_getimage.c, tif_luv.c, tif_lzw.c, tif_next.c, + tif_packbits.c, tif_predict.c, tif_print.c, tif_swab.c, tif_thunder.c: + avoid casting warning at /W4. + +2003-07-03 Andrey Kiselev + + * tools/thumbnail.c: Memory leak fixed as reported by Robert S. Kissel. + +2003-06-30 Andrey Kiselev + + * libtiff/tif_pixarlog.c: Unused variables removed. + + * libtiff/{tif_dirread.c, tif_dir.c}: Fixed problem with + EstimateStripByteCounts() as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=358 + + * libtiff/{tif_dirwrite.c, tif_packbits.c}: Fixed compilation on + 64-bit architectures as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=357 + + * libtiff/tif_dirinfo.c: TIFFDataWidth() returns 0 in case of + unknown data type. + +2003-06-19 Frank Warmerdam + + * libtiff/tif_print.c: fixed some serious bugs when printing + custom tags ... almost certain to crash. + + * libtiff/tif_dirread.c: Don't ignore custom fields that are + autodefined. Not sure how this got to be like this. + +2003-06-18 Andrey Kiselev + + * 3.6.0 Beta2 released. + + * tools/tiffcmp.c, man/tiffcmp.1: Fixed problem with unused data + comparing as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=349 + + `-z' option now can be used to set the number of reported different + bytes. + +2003-06-09 Andrey Kiselev + + * tools/tiffcp.c, man/tiffcp.1: Added possibility to specify value -1 + to -r option to get the entire image as one strip. See + + http://bugzilla.remotesensing.org/show_bug.cgi?id=343 + + for details. + +2003-06-04 Andrey Kiselev + + * tools/tiffcp.c: Set the correct RowsPerStrip and PageNumber + values as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=343 + +2003-05-27 Frank Warmerdam + + * libtiff/tif_jpeg.c: modified segment_height calculation to always + be a full height tile for tiled images. Also changed error to just + be a warning. + +2003-05-25 Andrey Kiselev + + * tools/fax2tiff.c: Page numbering fixed, as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=341 + +2003-05-20 Andrey Kiselev + + * contrib/ojpeg/{Makefile.in, jdhuff.h, jinclude.h, ojpeg.c, README}, + configure, Makefile.in: Switched back to the old behaviour. Likely + better solution should be found for OJPEG support. + +2003-05-11 Andrey Kiselev + + * libtiff/mkversion.c: Fixed problem with wrong string size when + reading RELEASE-DATE file. + +2003-05-07 Andrey Kiselev + + * tools/tiff2ps.c: Fixed bug in Ascii85EncodeBlock() function: array + index was out of range. + +2003-05-06 Andrey Kiselev + + * contrib/ojpeg/{Makefile.in, jdhuff.h, jinclude.h, ojpeg.c, README}, + configure, Makefile.in: Improved libtiff compilation with OJPEG + support. Now no need for patching IJG JPEG library, hack requred by + libtiff will be compiled and used in-place. Implemented with + suggestion and help from Bill Allombert, Debian's libjpeg maintainer. + + * libtiff/tif_aux.c: Properly handle TIFFTAG_PREDICTOR in + TIFFVGetFieldDefaulted() function. + +2003-05-05 Andrey Kiselev + + * tools/ppm2tiff.c: PPM header parser improved: now able to skip + comments. + + * tools/tiffdither.c: Fixed problem with bit fill order tag setting: + was not copied from source image. + + * libtiff/getimage.c: Workaround for some images without correct + info about alpha channel as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=331 + +2003-04-29 Andrey Kiselev + + * tools/tiff2ps.c, man/tiff2ps.1: Add ability to generate PS Level 3. + It basically allows one to use the /flateDecode filter for ZIP + compressed TIFF images. Patch supplied by Tom Kacvinsky. Fixes + + http://bugzilla.remotesensing.org/show_bug.cgi?id=328 + + * tools/tiff2ps.c: Force deadzone printing when EPS output specified + as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=325 + +2003-04-17 Andrey Kiselev + + * libtiff/tif_dirread.c: Removed additional check for StripByteCounts + due to problems with multidirectory images. Quality of error messages + improved. + +2003-04-16 Andrey Kiselev + + * tools/tiffcp.c: Fixed problem with colorspace conversion for JPEG + encoded images. See bug entries + + http://bugzilla.remotesensing.org/show_bug.cgi?id=275 + + and + + http://bugzilla.remotesensing.org/show_bug.cgi?id=23 + + * libtiff/tif_dirread.c: Additional check for StripByteCounts + correctness. Fixes + + http://bugzilla.remotesensing.org/show_bug.cgi?id=320 + +2003-03-12 Andrey Kiselev + + * tools/{fax2ps.c, fax2tiff.c, gif2tiff.c, pal2rgb.c, ppm2tiff.c, + ras2tiff.c, raw2tiff.c, rgb2ycbcr.c, thumbnail.c, tiff2bw.c, + tiff2ps.c, tiff2rgba.c, tiffcp.c, tiffdither.c, tiffinfo.c, + tiffmedian.c}: Added library version reporting facility to all tools. + +2003-03-06 Frank Warmerdam + + * port/install.sh.in: Fixed problems with install producing paths + like ///usr/local/lib on cygwin. + +2003-02-27 Andrey Kiselev + + * tools/fax2tiff.c, man/fax2tiff.1: New switch (-X) to set width of + raw input page. Patch supplied by Julien Gaulmin. See + + http://bugzilla.remotesensing.org/show_bug.cgi?id=293 + + for details. + +2003-02-26 Frank Warmerdam + + * libtiff/tif_dir.c: fixed up the tif_postdecode settings + responsible for byte swapping complex image data. + + * libtiff/tif_lzw.c: fixed so that decoder state isn't allocated till + LZWSetupDecode(). Needed to read LZW files in "r+" mode. + +2003-02-07 Andrey Kiselev + + * tools/ppm2tiff.c: Fixed problem with too many arguments. + +2003-02-04 Andrey Kiselev + + * tools/raw2tiff.c: Memory leak fixed. + +2003-02-03 Andrey Kiselev + + * tools/fax2tiff.c, man/fax2tiff.1: Applied patch from Julien Gaulmin + (thanks, Julien!). More switches for fax2tiff tool for better control + of input and output. Details at + + http://bugzilla.remotesensing.org/show_bug.cgi?id=272 + +2003-02-03 Frank Warmerdam + + * libtiff/tif_jpeg.c: Modified to defer initialization of jpeg + library so that we can check if there is already any tile/strip data + before deciding between creating a compressor or a decompressor. + +2003-01-31 Frank Warmerdam + + * libtiff/tif_write.c: TIFFWriteCheck() now fails if the image is + a pre-existing compressed image. That is, image writing to + pre-existing compressed images is not allowed. + + * libtiff/tif_open.c: Removed error if opening a compressed file + in update mode. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=198 + +2003-01-31 Andrey Kiselev + + * config.guess, config.sub: Updated to recent upstream versions. + +2003-01-15 Frank Warmerdam + + * cut 3.6.0 Beta release. + +2002-12-20 Andrey Kiselev + + * tools/fax2ps.c, man/fax2ps.1: Page size was determined + in wrong way as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=239 + +2002-12-17 Frank Warmerdam + + * libtiff/tif_dirread.c: Allow wrong sized arrays in + TIFFFetchStripThing(). + + http://bugzilla.remotesensing.org/show_bug.cgi?id=49 + +2002-12-02 Frank Warmerdam + + * libtiff/tif_dir.c: fix problem with test on td_customValueCount. + Was using realloc even first time. Fix by Igor Venevtsev. + +2002-11-30 Frank Warmerdam + + * libtiff/tif_dir.c: fixed bug with resetting an existing custom + field value. + + * libtiff/tif_dir.c: Fixed potential problem with ascii "custom" + tags in TIFFVGetField() ... added missing break. + +2002-10-14 Frank Warmerdam + + * tools/tiff2ps.c: fixes a problem where "tiff2ps -1e" did not make + the scanline buffer long enough when writing rgb triplets. + The scanline needs to be 3 X the number of dots or else it will + contain an incomplete triplet and programs that try to separate + the eps by redefining the colorimage operator will get messed up. + Patch supplied by William Bader. + + * Makefile.in: added tif_extension.c to file list as per + http://bugzilla.remotesensing.org/show_bug.cgi?id=218. + +2002-10-11 Andrey Kiselev + + * configure, config.site, libtiff/{tif_unix.c, Makefile.in}: Fix for + large files (>2GiB) supporting. New option in the config.site: + LARGEFILE="yes". Should be enough for I/O of the large files. + +2002-10-10 Frank Warmerdam + + * libtiff/html/v3.6.0.html: new release notes. + + * libtiff/index.html: removed faq, cvs snapshot cruft. Added email + link for Andrey. Pointer to v3.6.0.html. + + * libtiff/Makefile.in: added direct rule for tiffvers.h for release. + +2002-10-07 Andrey Kiselev + * tools/tiff2ps.c, man/tiff2ps.1: Applied patch form Sebastian Eken + (thanks, Sebastian!). New switches: + -b # for a bottom margin of # inches + -c center image + -l # for a left margin of # inches + -r rotate the image by 180 degrees + New features merged with code for shrinking/overlapping. + Previously added -c and -n switches (for overriding PS units) renamed + in -x and -y respectively. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=200 + + * html/man/*.html: Updated from actual manual pages. + +2002-10-06 Frank Warmerdam + + * libtiff/tif_jpeg.c: fixed problem with boolean defined with wrong + size on windows. Use #define boolean hack. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=188 + + * libtiff/tiff.h: Don't do special type handling in tiff.h unless + USING_VISUALAGE is defined. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=39 + +2002-10-03 Frank Warmerdam + + * libtiff/tiff.h: added COMPRESSION_JP2000. + +2002-10-02 Andrey Kiselev + + * libtiff/tif_dirread.c: Another fix for the fetching SBYTE arrays + by the TIFFFetchByteArray() function. Should finally resolve + + http://bugzilla.remotesensing.org/show_bug.cgi?id=52 + + * configure: Set -DPIXARLOG_SUPPORT option along with -DZIP_SUPPORT + + * html/Makefile.in: New targets added: html and groffhtml for + producing HTML representations of the manual pages automatically. + html target uses man2html tool, groffhtml uses groff tool. + +2002-09-29 Frank Warmerdam + + * configure, libtiff/Makefile.in: Added SCO OpenServer 5.0.6 support + from John H. DuBois III. + +2002-09-15 Andrey Kiselev + + * Makefile.in, /man/{raw2tiff.1, Makefile.in, libtiff.3}: Added + manual page for raw2tiff(1) tool. + +2002-09-12 Andrey Kiselev + + * /libtiff/{tiffio.h, tif_dir.h}: TIFFDataWidth() declaration moved to + the tiffio.h header file. + + * Makefile.in, /man/{TIFFDataWidth.3t, Makefile.in, libtiff.3}: Added + manual page for TIFFDataWidth() function + +2002-09-08 Frank Warmerdam + + * libtiff/tif_dirread.c: Expand v[2] to v[4] in TIFFFetchShortPair() + as per http://bugzilla.remotesensing.org/show_bug.cgi?id=196. + + * tools/tiff2ps.c: Don't emit BeginData/EndData DSC comments + since we are unable to properly include the amount to skip. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=80 + +2002-09-02 Andrey Kiselev + + * /libtiff/tif_dirread.c: Fixed problem with SBYTE type data fetching + in TIFFFetchByteArray(). Problem described at + http://bugzilla.remotesensing.org/show_bug.cgi?id=52 + +2002-08-22 Andrey Kiselev + + * /libtiff/tif_dirinfo.c: Further additions to free custom fields + in _TIFFSetupFieldInfo() function. + See http://bugzilla.remotesensing.org/show_bug.cgi?id=169 for details. + + * /libtiff/tif_lzw.c: Additional consistency checking added in + LZWDecode() and LZWDecodeCompat(). + Fixes http://bugzilla.remotesensing.org/show_bug.cgi?id=190 + and http://bugzilla.remotesensing.org/show_bug.cgi?id=100 + + * /libtiff/tif_lzw.c: + Added check for valid code lengths in LZWDecode() and + LZWDecodeCompat(). Fixes + http://bugzilla.remotesensing.org/show_bug.cgi?id=115 + +2002-08-16 Andrey Kiselev + + * /libtiff/{Makefile.vc, libtiff.def}: + Missed declarations added. + +2002-08-15 Frank Warmerdam + + * tif_getimage.c: Ensure that TIFFRGBAImageBegin() returns the + return code from the underlying pick function. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=177 + + * tif_dir.h: changed FIELD_CODEC to 66 from 64 to avoid overlap + with FIELD_CUSTOM as mentioned in bug 169. + + * tif_close.c: added logic to free dynamically created anonymous + field definitions to correct a small memory leak. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=169 + +2002-08-10 Andrey Kiselev + + * /tools/{raw2tiff.c, Makefile.in, Makefile.lcc, Makefile.vc}: + New tool: raw2tiff --- raw images to TIFF converter. No manual page yet. + +2002-07-31 Frank Warmerdam + + * libtiff/tif_jpeg.c: Fixed problem with setting of nrows in + JPEGDecode() as per bugzilla bug (issue 1): + + http://bugzilla.remotesensing.org/show_bug.cgi?id=129 + + * libtiff/{tif_jpeg.c,tif_strip.c,tif_print.c}: Hacked tif_jpeg.c to + fetch TIFFTAG_YCBCRSUBSAMPLING from the jpeg data stream if it isn't + present in the tiff tags. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=168 + + * libtiff/tif_read.c, libtiff/tif_write.c: TIFFReadScanline() and + TIFFWriteScanline() now set tif_row explicitly in case the codec has + fooled with the value. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=129 + +2002-06-22 Andrey Kiselev + + * /tools/tiff2ps.c: Added workaround for some software that may crash + when last strip of image contains fewer number of scanlines than + specified by the `/Height' variable. See + http://bugzilla.remotesensing.org/show_bug.cgi?id=164 + for explanation. + +2002-06-21 Andrey Kiselev + + * tools/tiff2ps, man/tiff2ps.1: New functionality for tiff2ps utility: + splitting long images in several pages. See + http://bugzilla.remotesensing.org/show_bug.cgi?id=142 for explanation. + Patch granted by John Williams . + +2002-06-11 Frank Warmerdam + + * libtiff/contrib/win95: renamed to contrib/win_dib. Added new + Tiffile.cpp example of converting TIFF files into a DIB on Win32. + This one is described in: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=143 + + * libtiff/tif_ojpeg.c: Major upgrade from Scott. See details at: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=156 + +2002-05-10 Andrey Kiselev + + * tools/tiff2ps: New commandline switches to override resolution + units obtained from the input file. Closes + http://bugzilla.remotesensing.org/show_bug.cgi?id=131 + +2002-04-26 Andrey Kiselev + + * libtiff/libtiff.def: Added missed declaration. + +2002-04-22 Andrey Kiselev + + * tools/fax2tiff.c: Updated to reflect latest changes in libtiff. + Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=125 + +2002-04-20 Andrey Kiselev + + * libtiff/tif_open.c: Pointers to custom procedures + in TIFFClientOpen() are checked to be not NULL-pointers. + +2002-04-18 Andrey Kiselev + + * libtiff/libtiff.def: Added missed declarations. + + * libtiff/tif_pixarlog.c: Updated for using tif_tagmethods structure. + +2002-04-16 Andrey Kiselev + + * libtiff/tif_lzw.c: Additional checks for data integrity introduced. + Should finally close + http://bugzilla.remotesensing.org/show_bug.cgi?id=100 + +2002-04-10 Andrey Kiselev + + * tools/tiff2ps: Division by zero fixed. + Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=88 + +2002-04-09 Andrey Kiselev + + * libtiff/: tif_dirwrite.c, tif_write.c, tiffio.h: + TIFFCheckpointDirectory() routine added. + Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=124 + + * man/: TIFFWriteDirectory.3t, Makefile.in: Added description + for the new function. + +2002-04-08 Andrey Kiselev + + * libtiff/: tif_codec.c, tif_compress.c, tiffiop.h: Introduced + additional members tif->tif_decodestatus and tif->tif_encodestatus + for correct handling of unconfigured codecs (we should not try to read + data or to define data size without correct codecs). + + * libtiff/tif_getimage.c: The way of codecs checking in TIFFRGBAImageOK + changed. Now it has used tif->tif_decodestatus and + tif->tif_encodestatus. + Should fix http://bugzilla.remotesensing.org/show_bug.cgi?id=119 (in + case of __cvs_8.tif test image). + + * libtiff/: tif_dirinfo.c, tif_dirread.c: Somebody makes a bug in + tif_dirread.c when TIFFCreateAnonFieldInfo was introduced. + Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=119 in case + of _cvs_00000-00.tif, _cvs_00000-01.tif and _cvs_00000-02.tif. + +2002-04-04 Andrey Kiselev + + * libtiff/: tif_lzw.c: Assertions in LZWDecode and LZWDecodeCompat + replaced by warnings. Now libtiff should read corrupted LZW-compressed + files by skipping bad strips. + Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=100 + +2002-04-03 Frank Warmerdam + + * libtiff/tif_dirwrite.c: Removed some dead code. + + * libtiff/*: Cleanup some warnings. + + * libtiff/tif_dir.c: Fixed bug with count returned by TIFFGetField() + for variable length FIELD_CUSTOM values. Was int * but should be + u_short *. + +2002-04-01 Andrey Kiselev + + * tools/: tifcp.c: Added support for 'Orientation' tag in tiffcp + utility (at cpStripToTile routine). + +2002-03-27 Frank Warmerdam + + * tif_dirread.c: avoid div-by-zero if rowbytes is zero in chop func. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=111 + + * tif_print.c: Fixed so that ASCII FIELD_CUSTOM values with + passcount set FALSE can be printed (such as TIFFTAG_SOFTWARE). + + * libtiff/tif_dir.c,tif_dirinfo.c,tif_dir.h,tif_ojpeg.c: modified so + that TIFFTAG_SOFTWARE uses FIELD_CUSTOM as an example. + +2002-03-26 Dwight Kelly + + * libtiff/: tiff.h, tif_dir.c, tif_dir.h, tif_dirinfo.c, tif_dirread.c, + tif_dirwrite.c: Added get/put code for new tag XMLPACKET as defined + in Adobe XMP Technote. Added missing INKSET tag value from TIFF 6.0 spec + INKSET_MULTIINK (=2). Added missing tags from Adobe TIFF technotes: + CLIPPATH, XCLIPPATHUNITS, YCLIPPATHUNITS, OPIIMAGEID, OPIPROXY and + INDEXED. Added PHOTOMETRIC tag value from TIFF technote 4 ICCLAB (=9). + +2002-03-26 Andrey Kiselev + + * libtiff/: tif_getimage.c: TIFFReadRGBAStrip and TIFFReadRGBATile + now also uses TIFFRGBAImageOK before reading. This is additional fix + for http://bugzilla.remotesensing.org/show_bug.cgi?id=110 + +2002-03-25 Andrey Kiselev + + * libtiff/: tif_getimage.c: Additional check for supported + codecs added in TIFFRGBAImageOK and TIFFReadRGBAImage now uses + TIFFRGBAImageOK before reading. + Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=110 + +2002-03-15 Andrey Kiselev + + * libtiff/: tif_dir.c, tif_dir.h, tif_dirinfo.c, tif_dirread.c, + tif_dirwrite.c: Added routine TIFFDataWidth for detrmining + TIFFDataType sizes instead of working with tiffDataWidth array + directly. Should prevent out-of-borders bugs in case of unknown or + broken data types. EstimateStripByteCounts routine modified, so it + won't work when tags with uknown sizes founded. + Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=109 + +2002-03-13 Andrey Kiselev + + * libtiff/tif_getimage.c: Added support for correct handling + `Orientation' tag in gtTileContig. Should be added in other gt* + functions as well, but I have not images for testing yet. Partially + resolves http://bugzilla.remotesensing.org/show_bug.cgi?id=23 + +2002-03-10 Andrey Kiselev + + * libtiff/: tif_dirinfo.c, tif_dirwrite.c: Added possibility to + read broken TIFFs with LONG type used for TIFFTAG_COMPRESSION, + TIFFTAG_BITSPERSAMPLE, TIFFTAG_PHOTOMETRIC. Closes + http://bugzilla.remotesensing.org/show_bug.cgi?id=99 + +2002-03-08 Andrey Kiselev + + * libtiff/Makefile.in, tools/Makefile.in: Shared library will not + be stripped when installing, utility binaries will do. Closes + http://bugzilla.remotesensing.org/show_bug.cgi?id=93 + +2002-02-28 Frank Warmerdam + + * man/TIFFGetField: fixed type of TIFFTAG_COPYRIGHT. + + * man/libtiff.3t: added copyright tag info. + +2002-02-11 Frank Warmerdam + + * libtiff/{tiff.h,tif_fax3.c}: Add support for __arch64__. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=94 + + * man/Makefile.in: Patch DESTDIR handling + + http://bugzilla.remotesensing.org/show_bug.cgi?id=95 + + * configure: OpenBSD changes for Sparc64 and DSO version. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=96 + +2002-02-05 Frank Warmerdam + + * config.site/configure: added support for OJPEG=yes option to enable + OJPEG support from config.site. + +2002-01-27 Frank Warmerdam + + * html/document.html: fixed links for TIFf 6 docs. + +2002-01-18 Frank Warmerdam + + * config.guess, config.sub: Updated from ftp.gnu.org/pub/config. + + * libtiff/tif_read.c: Fixed TIFFReadEncodedStrip() to fail if the + decodestrip function returns anything not greater than zero as per + http://bugzilla.remotesensing.org/show_bug.cgi?id=97 + + * configure: Modify CheckForBigEndian so it can work in a cross + compiled situation. + +2002-01-16 Frank Warmerdam + + * tools/tiffdump.c: include TIFFTAG_JPEGTABLES in tag list. + + * tools/tiffset.c: fix bug in error reporting. + + * tools/tiffcp.c: fix several warnings that show up with -Wall. + +2002-01-04 Frank Warmerdam + + * libtiff/tif_jpeg.c: fixed computation of segment_width for + tiles files to avoid error about it not matching the + cinfo.d.image_width values ("JPEGPreDecode: Improper JPEG strip/tile + size.") for ITIFF files. Apparently the problem was incorporated since + 3.5.5, presumably during the OJPEG/JPEG work recently. + +2001-12-15 Frank Warmerdam + + * configure, libtiff/Makefile.in: Changes for building on MacOS 10.1. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=94 + + * libtiff/tif_getimage.c: If DEFAULT_EXTRASAMPLE_AS_ALPHA is 1 + (defined in tiffconf.h - 1 by default) then the RGBA interface + will assume that a fourth extra sample is ASSOCALPHA if the + EXTRASAMPLE value isn't set for it. This changes the behaviour of + the library, but makes it work better with RGBA files produced by + lots of applications that don't mark the alpha values properly. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=93 + http://bugzilla.remotesensing.org/show_bug.cgi?id=65 + +2001-12-12 Frank Warmerdam + + * libtiff/tif_jpeg.c: allow jpeg data stream sampling values to + override those from tiff directory. This makes this work with + ImageGear generated files. + +2001-12-07 Frank Warmerdam + + * html/Makefile.in: added missing images per bug 92. + + * port/Makefile.in: fixed clean target per bug 92. + +2001-11-28 Frank Warmerdam + + * Reissue 3.5.7 release. + + * libtiff/mkversion.c: Fix output of TIFF_VERSION to be + YYYYMMDD so that it is increasing over time. + + * Makefile.in: Ensure that tiffvers.h is regenerated in the + make release target. + + * Makefile.in: added libtiff/tiffvers.h to the release file list. + +2001-11-23 Frank Warmerdam + + * added html/v3.5.7.html, updated html/index.html. + + * Makefile.in: added contrib/addtiffo/tif_ovrcache.{c,h}. + +2001-11-15 Frank Warmerdam + + * configure: fixed test for -lm. + +2001-11-02 Frank Warmerdam + + * Added PHOTOMETRIC_ITULAB as per bug 90. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=90 + +2001-10-10 Frank Warmerdam + + * libtiff/tiff.h: I have created COMPRESSION_CCITT_T4, + COMPRESSION_CCITT_T6, TIFFTAG_T4OPTIONS and TIFFTAG_T6OPTIONS aliases + in keeping with TIFF 6.0 standard in tiff.h + + http://bugzilla.remotesensing.org/show_bug.cgi?id=83 + +2001-09-26 Frank Warmerdam + + * libtiff/tif_dirwrite.c: added TIFFRewriteDirectory() function. + Updated TIFFWriteDirectory man page to include TIFFRewriteDirectory. + +2001-09-24 Frank Warmerdam + + * libtiff/tif_lzw.c: Avoid MS VC++ 5.0 optimization bug. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=78 + + * libtiff/tif_lzw.c: added dummy LZWSetupEncode() to report an + error about LZW not being available. + + * libtiff/tif_dir.c: propagate failure to initialize compression + back from TIFFSetField() as an error status, so applications can + detect failure. + + * libtiff/tif_dir.c: removed the auto replacement of + COMPRESSION_LZW with COMPRESSION_NONE in _TIFFVSetField(). + + * Removed Makefile, tools/Makefile, port/install.sh, man/Makefile + from CVS as they are all supposed to be auto-generated by configure. + +2001-09-22 Frank Warmerdam + + * libtiff/tif_ojpeg.c: new update from Scott. + +2001-09-09 Frank Warmerdam + + * libtif/tif_fax3.c: Removed #ifdef PURIFY logic, and modified to + always use the "safe" version, even if there is a very slight + cost in performance. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=54 + + * libtiff/Makefile.in: Fixed @DSOSUB_VERSION to be @DSOSUF_VERSION@ + in two places. + + * libtiff/tif_getimage.c: Fixed problem with reading strips or + tiles that don't start on a tile boundary. Fix contributed by + Josep Vallverdu (from HP), and further described in bug 47. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=47 + + * tools/tiff2ps.c: added OJPEG YCbCr to RGB support. + + * libtiff/tif_ojpeg.c: Applied substantial patch from Scott. + +2001-09-06 Frank Warmerdam + + * libtiff/tif_packbits.c: fixed memory overrun error. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=77 + +2001-08-31 Frank Warmerdam + + * libtiff/tif_getimage.c: relax handling of contig case where + there are extra samples that are supposed to be ignored. This + should now work for 8bit greyscale or palletted images. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=75 + +2001-08-28 Frank Warmerdam + + * libtiff/tif_getimage.c: Don't complain for CMYK (separated) + images with more than four samples per pixel. See: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=73 + +2001-08-10 Frank Warmerdam + + * libtiff/tif_getimage.c: Use memmove() instead of TIFFmemcpy() + in TIFFReadRGBATile() to avoid issues in cases of overlapping + buffers. See Bug 69 in Bugzilla. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=69 + + * tools/tiff2rgba.c: fixed getopt() call so that -b works again. + +2001-08-09 Frank Warmerdam + + * libtiff/tiff.h, libtiff/tif_fax3.c: added check for __LP64__ + when checking for 64 bit architectures as per bugzilla bug 67. + +2001-07-27 Frank Warmerdam + + * man/Makefile.in: add TIFFClientOpen link as per debian submitted + bug 66. + +2001-07-20 Frank Warmerdam + + * libtiff/tif_jpeg.c: Define HAVE_BOOLEAN on windows if RPCNDR.H + has been included. + +2001-07-19 Frank Warmerdam + + * libtiff/tif_open.c: Seek back to zero after failed read, + before writing header. + +2001-07-18 Frank Warmerdam + + * libtiff/tif_ojpeg.c: updates from Scott. Handles colors + much better. Now depends on having patched libjpeg as per + patch in contrib/ojpeg/*. + +2001-07-17 Frank Warmerdam + + * */Makefile.in: added DESTDIR support. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=60 + +2001-07-16 Frank Warmerdam + + * configure, libtiff/Makefile.in: applied OpenBSD patches + as per: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=61 + +2001-06-28 Frank Warmerdam + + * libtiff/tif_getimage.c: Fixed so that failure is properly + reported by gtTileContig, gtStripContig, gtTileSeparate and + gtStripSeparate. + + See http://bugzilla.remotesensing.org/show_bug.cgi?id=51 + + * tiffcmp.c: Fixed multi samples per pixel support for ContigCompare. + Updated bug section of tiffcmp.1 to note tiled file issues. + + See http://bugzilla.remotesensing.org/show_bug.cgi?id=53 + +2001-06-22 Frank Warmerdam + + * configure: Changes for DSO generation on AIX provided by + John Marquart . + + * configure, libtiff/Makeifle.in: Modified to build DSOs properly + on Darwin thanks to Robert Krajewski (rpk@alum.mit.edu) and + Keisuke Fujii (fujiik@jlcuxf.kek.jp). + +2001-06-13 Frank Warmerdam + + * tools/tiff2rgba.c: added -n flag to avoid emitting alpha component. + + * man/tiff2rgba.1: new + +2001-05-22 Frank Warmerdam + + * Added tiffset and tif_ojpeg to the dist lists in Makefile.in. + +2001-05-13 Frank Warmerdam + + * libtiff/tools/thumbnail.c: changed default output compression + to packbits from LZW since LZW isn't generally available. + +2001-05-12 Frank Warmerdam + + * libtiff/tif_ojpeg.c: New. + libtiff/tif_jpeg.c, tiffconf.h, tif_getimage.c: changes related + to OJPEG support. + + Scott Marovich supplied OJPEG support. + +2001-05-11 Frank Warmerdam + + * tiff.h: removed, it duplicates libtiff/tiff.h. + +2001-05-08 Frank Warmerdam + + * libtiff/tif_dirinfo.c: moved pixar and copyright flags to + ensure everything is in order. + + * libtiff/libtiff.def: added TIFFCreateDirectory and + TIFFDefaultStripSize as per: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=46 + +2001-05-02 Frank Warmerdam + + * libtiff/tif_dirinfo.c: Modified the TIFF_BYTE definition for + TIFFTAG_PHOTOSHOP to use a writecount of TIFF_VARIABLE2 (-3) to + force use of uint32 counts instead of short counts. + + * libtiff/tif_dirwrite.c: Added support for TIFF_VARIABLE2 in the + case of writing TIFF_BYTE/TIFF_SBYTE fields. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=43 + +2001-05-01 Frank Warmerdam + + * libtiff/tif_dirinfo.c: removed duplicate TIFFTAG_PHOTOSHOP as per + bug report http://bugzilla.remotesensing.org/show_bug.cgi?id=44 + +2001-04-05 Frank Warmerdam + + * tiffio.h: removed C++ style comment. + + * configure: fixed up SCRIPT_SH/SHELL handling. + + * Makefile.in: Fixed SCRIPT_SH/SHELL handling. + + * config.guess: documented more variables as per bug 40. + +2001-04-03 Frank Warmerdam + + * configure, *Makefile.in: Various changes to improve configuration + for HP/UX specifically, and also in general. They include: + - Try to handle /usr/bin/sh instead of /bin/sh where necessary. + - Upgrade to HP/UX 10.x+ compiler, linker and dso options. + - Fixed mmap() test to avoid MMAP_FIXED ... it isn't available on HP + - Use -${MAKEFLAGS} in sub makes from makefiles. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=40 + +2001-04-02 Frank Warmerdam + + * libtiff/tiff.h: Applied hac to try and resolve the problem + with the inttypes.h include file on AIX. + + See http://bugzilla.remotesensing.org/show_bug.cgi?id=39 + + * VERSION: update to 3.5.7 beta in preparation for release. + + * configure/config.site: modified to check if -lm is needed for + MACHDEPLIBS if not supplied by config.site. Needed for Darwin. + + * config.guess: updated wholesale to an FSF version apparently + from 1998 (as opposed to 1994). This is mainly inspired by + providing for MacOS X support. + +2001-03-29 Frank Warmerdam + + * configure, Makefile.in, etc: added support for OPTIMIZER being + set from config.site. + +2001-03-28 Frank Warmerdam + + * fax2ps.c: Helge (libtiff at oldach.net) submitted fix: + + Here's a fix for fax2ps that corrects behaviour for non-Letter paper + sizes. It fixes two problems: + + Without scaling (-S) the fax is now centered on the page size specified + with -H and/or -W. Before, fax2ps was using an obscure and practially + useless algorithm to allocate the image relative to Letter sized paper + which sometime sled to useless whitespace on the paper, while at the + same time cutting of the faxes printable area at the opposite border. + + Second, scaling now preserves aspect ratio, which makes unusual faxes + (in particular short ones) print properly. + + See http://bugzilla.remotesensing.org/show_bug.cgi?id=35 + + * tiff2ps.c/tiff2ps.1: Substantial changes to tiff2ps by + Bruce A. Mallett. See check message for detailed information + on all the changes, including a faster encoder, fixes for level + 2 PostScript, and support for the imagemask operator. + +2001-03-27 Frank Warmerdam + + * libtiff/tiffio.h: Changed "#if LOGLUV_PUBLIC" to + "#ifdef LOGLUV_PUBLIC" so it will work with VisualAge on AIX. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=39 + +2001-03-16 Frank Warmerdam + + * tif_dirinfo.c: moved definition of copyright tag in field list. + Apparently they have to be in sorted order by tag id. + +2001-03-13 Frank Warmerdam + + * tif_getimage.c: Added support for 16bit minisblack/miniswhite + images in RGBA interface. + +2001-03-02 Frank Warmerdam + + * Added TIFFTAG_COPYRIGHT support. + +2001-02-19 Frank Warmerdam + + * Brent Roman contributed updated tiffcp utility (and tiffcp.1) + with support for extracting subimages with the ,n syntax, and also + adding the -b bias removal flag. + +2001-02-16 Frank Warmerdam + + * libtiff/libtiff.def: Brent Roman submitted new version adding + serveral missing entry points. + + * libtiff/tif_dirinfo.c: don't declare tiffFieldInfo static on VMS. + Some sort of weird VMS thing. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=31 + + * tif_luv.c/tiff.h/tiffio.h: + New version of TIFF LogLuv (SGILOG) modules contributed by Greg Ward + (greg@shutterfly.com). He writes: + + 1) I improved the gamut-mapping function in tif_luv.c for imaginary + colors, because some images were being super-saturated on the input + side and this resulted in some strange color shifts in the output. + + 2) I added a psuedotag in tiff.h to control random dithering during + LogLuv encoding. This is turned off by default for 32-bit LogLuv and + on for 24-bit LogLuv output. Dithering improves the average color + accuracy over the image. + + 3) I added a #define for LOG_LUV_PUBLIC, which is enabled by default in + tiffio.h, to expose internal routines for converting between LogLuv and + XYZ coordinates. This is helpful for writing more efficient, + specialized conversion routines, especially for reading LogLuv files. + + Changes applied with minor edits. + +2001-01-23 Frank Warmerdam + + * tif_fax3.c: keep rw_mode flag internal to fax3 state to remember + whether we are encoding or decoding. This is to ensure graceful + recovery if TIFFClientOpen() discovers an attempt to open a compressed + file for "r+" access, and subsequently close it, as it resets the + tif_mode flag to O_RDONLY in this case to avoid writes, confusing the + compressor's concept of whether it is in encode or decode mode. + +2001-01-08 Mike Welles + + * Makefile.in: Now cleaning up after itself after creating the .tar.gz and .zip + +2001-01-07 Frank Warmerdam + + * html/libtiff.html: Fixed arguments in example for TIFFRGBAImageGet() + as per bug report by Patrick Connor. + +2000-12-28 Frank Warmerdam + + * Added RELEASE-DATE file to release file list. + + * Fixed libtiff/makefile.vc to make tiffvers.h not version.h. + +2000-12-22 Mike Welles + * added link to CVS mirror from index.html + + * updated html/internals.html to note that LZW compression is + not supported by default. + +2000-12-22 Frank Warmerdam + + * updated html/libtiff.html to not point at Niles' old JPL web site + for the man pages, point at www.libtiff.org. + +2000-12-21 Frank Warmerdam + + * libtiff/tif_apple.c: Applied "Carbon" support patches supplied by + Leonard Rosenthol . May interfere + with correct building on older systems. If so, please let me know. + +2000-12-19 Mike Welles + + * Took out LZW Encoding from tif_lzw.c + + * Created HOWTO-RELEASE + + * Created html/v3.5.6.html + + * updated index.html + +2000-12-01 Frank Warmerdam + + * Added patches for EOFB support in tif_fax3.c and tif_fax3.h. + Patches supplied by Frank Cringle + Example file at: ftp://ftp.remotesensing.org/pub/libtiff/eofb_396.tif + +2000-11-24 Frank Warmerdam + + * libtiff/Makefile.in: Added an installPrivateHdrs and install-private + target so that the private headers required by libgeotiff can be + installed with the others. They are not installed by default. + + * libtiff/Makefile.in: Added @MACHLIBDEPS@ to LINUXdso and GNULDdso + targets so libtiff.so will be built with an explicit dependency + on libm.so. + + * libtiff/Makefile.in: Use softlinks to link libtiff.so.3 to + libtiff.so.3.5.5. + + * libtiff/Makefile.in & configure: Remove all references to the ALPHA + file, or ALPHA version logic. Added stuff about DIST_POINT in + place of DIST_TYPE and the alpha release number stuff. + +2000-11-22 Frank Warmerdam + + * I have applied a patch from Steffen Moeller to + the configure script so that it now accepts the --prefix, and + --exec-prefix directives. + +2000-11-13 Frank Warmerdam + + * I have made a variety of modifications in an effort to ensure the + TIFFLIB_VERSION macro is automatically generated from the RELEASE-DATE + file which seems to be updated regularly. + + o mkversion.c now reads RELEASE-DATE and emits TIFFLIB_VERSION in + version include file. + o renamed version.h to tiffvers.h because we now have to install it + with the public libtiff include files. + o include tiffvers.h in tiffio.h. + o updated tif_version.c to use tiffvers.h. + o Updated Makefile.in accordingly. + + * As per http://bugzilla.remotesensing.org/show_bug.cgi?id=25 + I have updated the win32 detection rules in tiffcomp.h. + +2000-10-20 Frank Warmerdam + + * tif_getimage.c: Fixed RGBA translation for YCbCr images for which + the strip/tile width and height aren't multiples of the sampling size. + See http://bugzilla.remotesensing.org/show_bug.cgi?id=20 + Some patches from Rick LaMont of Dot C Software. + + * Modified tif_packbits.c encoder to avoid compressing more + data than provided if rowsize doesn't factor into provided data + (such as occurs for YCbCr). + +2000-10-19 Frank Warmerdam + + * tools/rgb2ycbcr.c: fixed output strip size to account for vertical + roundup if rows_per_strip not a multiple of vertical sample size. + +2000-10-16 Frank Warmerdam + + * tif_dir.c: Clear TIFF_ISTILED flag in TIFFDefaultDirectory + as per http://bugzilla.remotesensing.org/show_bug.cgi?id=18 + from vandrove@vc.cvut.cz. + + * Modified tif_packbits.c decoding to avoid overrunning the + output buffer, and to issue a warning if data needs to be + discarded. See http://bugzilla.remotesensing.org/show_bug.cgi?id=18 + +2000-10-12 Frank Warmerdam + + * Modified tiff2bw to ensure portions add to 100%, and that + white is properly recovered. + + See bug http://bugzilla.remotesensing.org/show_bug.cgi?id=15 + Patch c/o Stanislav Brabec + +2000-09-30 Frank Warmerdam + + * Modified TIFFClientOpen() to emit an error on an attempt to + open a comperessed file for update (O_RDWR/r+) access. This is + because the compressor/decompressor code gets very confused when + the mode is O_RDWR, assuming this means writing only. See + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=13 + +2000-09-27 Frank Warmerdam + + * Added GNULDdso target an`d switched linux and freebsd to use it. + +2000-09-26 Frank Warmerdam + + * Applied patch for 0x0000 sequences in tif_fax3.h's definition + of EXPAND1D() as per bug 11 (from Roman). + +2000-09-25 Frank Warmerdam + * Fixed tiffcomp.h to avoid win32 stuff if unix #defined, to improve + cygwin compatibility. + + * Applied patch from Roman Shpount to tif_fax3.c. This seems to + be a proper fix to the buffer sizing problem. See + http://bugzilla.remotesensing.org/show_bug.cgi?id=11 + + * Fixed tif_getimage.c to fix overrun bug with YCbCr images without + downsampling. http://bugzilla.remotesensing.org/show_bug.cgi?id=10 + Thanks to Nick Lamb for reporting the + bug and proving the patch. + +2000-09-18 Frank Warmerdam + + * Fixed tif_jpeg.c so avoid destroying the decompressor before + we are done access data thanks to bug report from: + Michael Eckstein . + + * Reverted tif_flush change. + +2000-09-14 Frank Warmerdam + + * tif_flush.c: Changed so that TIFFFlushData() doesn't return an + error when TIFF_BEENWRITING is not set. This ensures that the + directory contents can still be flushed by TIFFFlush(). + +2000-08-14 Frank Warmerdam + + * tif_open.c: Don't set MMAP for O_RDWR files. + + * tif_open.c: Set STRIPCHOP_DEFAULT for O_RDWR as well as O_RDONLY + so that files opened for update can be strip chopped too. + + * tif_read.c: fixed up bug with files missing rowsperstrip and + the strips per separation fix done a few weeks ago. + +2000-07-17 Frank Warmerdam + + * Tentatively added support for SAMPLEFORMAT_COMPLEXIEEEFP, and + SAMPLEFORMAT_COMPLEXINT. + +2000-07-13 Mike Welles + + * index.html, bugs.html: added bugzilla info. + +2000-07-12 Frank Warmerdam + + * tif_read.c: fix subtle bug with determining the number of + rows for strips that are the last strip in a separation but + not the last strip of all in TIFFReadEncodedStrip(). + + * Applied 16/32 bit fix to tif_fax3.c. Fix supplied by + Peter Skarpetis + +2000-06-15 Frank Warmerdam + + * Modified tiffio.h logic with regard to including windows.h. It + won't include it when building with __CYGWIN__. + +2000-05-11 Frank Warmerdam + + * README: update to mention www.libtiff.org, don't list Sam's old + email address. + + * configure: Fixed DSO test for Linux as per patch from + Jan Van Buggenhout . + +2000-04-21 Frank Warmerdam + + * libtiff/tif_dirread.c: Don't use estimate strip byte count for + one tile/strip images with an offset, and byte count of zero. These + could be "unpopulated" images. + +2000-04-18 Frank Warmerdam + + * contrib/addtiffo: Added "averaging" resampling option. + + * tools/tiffsplit.c: Copy TIFFTAG_SAMPLEFORMAT. + +Tue Apr 18 16:18:08 2000 Frank Warmerdam + + * tools/Makefile.in: Modified to install properly on SGI. + +2000-04-12 Mike Welles + * configure: Fixed stupid mistake in libc6 test on Linux + +2000-04-04 Mike Welles + * tif_win32.c: Applied patch to fix overreads and ovverwrites + caught by BoundsChecker. From Arvan Pritchard + (untested). + + * tif_getimage.c: Applied patch to silence VC6 warnings. From + Arvan Pritchard + + * tif_lzw.c: Applied patch to silence VC6 warnings. From + Arvan Pritchard + +2000-03-28 Frank Warmerdam + + * Added contrib/stream (stream io) code submitted by Avi Bleiweiss. + +2000-03-28 Frank Warmerdam *** 3.5.5 release *** + + * fax2ps: Fixed mixup of width and height in bounding box statement + as per submission by Nalin Dahyabhai . + +2000-03-27 Mike Welles + + * fax2ps: Modified printruns to take uint32 instead of uint16. + Patch courtesy of Bernt Herd + +2000-03-20 Mike Welles + + * configure: added test for libc6 for linux targets. Bug reported by + Stanislav Brabec + + * Added 3.5 docs to html/Makefile.in. + Thanks to Stanislav Brabec + + * configure: fixed bugs in sed scripts + (applied sed script s:/@:s;@:;s:/s;;:;: to configure). + fix submitted to Stanislav Brabec + + * tools/iptcutil was not in files list, and wasn't being + added to tar archive. Updated Makefile.in. + +2000-03-17 Frank Warmerdam + + * tif_fax3.c: Fixed serious bug introduced during the uint16->uint32 + conversion for the run arrays. + +2000-03-03 Frank Warmerdam + + * Set td_sampleformat default to SAMPLEFORMAT_UINT instead of + SAMPLEFORMAT_VOID in TIFFDefaultDirectory() in tif_dir.c. + +2000-03-02 Frank Warmerdam + + * Added "GetDefaulted" support for TIFFTAG_SAMPLEFORMAT in tif_aux.c. + + * Patched tif_fax3.c so that dsp->runs is allocated a bit bigger + to avoid overruns encountered with frle_bug.tif. + +Tue Feb 15 22:01:05 2000 Frank Warmerdam + + * Fixed tools/tiffcmp so that stopondiff testing works. + Patch care of Joseph Orost . + +2000-01-28 + + * Modified tif_unix.c to support 2-4GB seeks if USE_64BIT_API is + set to 1, and added default (off) setting in tiffconf.h. This + should eventually be set by the configure script somehow. + + The original work on all these 2-4GB changes was done by + Peter Smith (psmith@creo.com). + + * Modified tif_win32.c to support 2-4GB seeks. + + * tentatively changed toff_t to be unsigned instead of signed to + facilitate support for 2-4GB files. + + * Updated a variety of files to use toff_t. Fixed some mixups + between toff_t and tsize_t. + +Fri Jan 28 10:13:49 2000 Frank Warmerdam + + * Largely reimplemented contrib/addtiffo to avoid temp files, + updating the TIFF file in place. Fixed a few other bugs to. + + * Set tif_rawdatasize to zero when freeing raw data buffer in + TIFFWriteDirectory(). + + * Enabled "REWRITE_HACK" in tif_write.c by default. + + * Fix bug in tif_write.c when switching between reading one directory + and writing to another. + + * Made TIFFWriteCheck() public, and added TIFFCreateDirectory() + +Wed Jan 5 12:37:48 2000 Frank Warmerdam + + * Added TIFFmemory(3t) functions to libtiff.def. + +Tue Jan 4 13:39:00 2000 Frank Warmerdam + + * Added libtiff/libtiff.def to TIFFILES distribution list. + +Mon Dec 27 12:13:39 EST 1999 Mike Welles + + * Created lzw compression kit, as a new module (libtiff-lzw-compression-kit). + + * Altered descriptions in tools to reflect "by default" lzw not supported + + * Updated index.html to note lzw compression kit. + +Tue Dec 21 14:01:51 1999 Frank Warmerdam + + * Added fax3sm_winnt.c to distribution list in Makefile.in. + +Tue Dec 21 11:04:45 EST 1999 Mike Welles *** 3.5.4 release *** + + * Aadded Pixar tag support. Contributed by Phil Beffery + + * Made one more change to tif_dir.c for removal of LZW compression. Also added notice + when LZW compression invoked. + + * Changed default compression in tools to TIFF_PACKBITS, and changed usage descriptions + in tools to reflect removal of LZW compression + +Mon Dec 20 18:39:02 EST 1999 Mike Welles + + * Fixed bug that caused LZW (non) compression to segfault. Added + warning about LZW compression removed being removed, and why. + + * Added nostrip to install in tools/Makefile.in so that debugging + symbols are kept. + +Tue Dec 7 12:04:47 EST 1999 Mike Welles + + * Added patch from Ivo Penzar , + supporting Adobe ZIP deflate. Untested. + +Sat Dec 4 15:47:11 1999 Frank Warmerdam + + * Made Packbits the default compression in tools/tiff2rgba.c instead + of LZW. + +Tue Nov 30 14:41:43 1999 Frank Warmerdam *** 3.5.3. release *** + + * Added tif_luv to contrib/djgpp/Makefile.lib. + +Tue Nov 30 14:15:32 EST 1999 Mike Welles + + * Added zip creation to relase makefile target + + * Added html for TIFFWriteTile.3t man page. + +Tue Nov 30 09:20:16 1999 Frank Warmerdam + + * Added some changes to tif_write.c to support rewriting existing + fixed sized tiles and strips. Code mods disabled by default, only + enabled if REWRITE_HACK is defined for now. + +Mon Nov 29 11:43:42 1999 Frank Warmerdam + + * Added TIFFWriteTile.3t man page. + +Sun Nov 28 20:36:18 1999 Frank Warmerdam + + * Added notes on use of makefile.vc in build.html, and fixed + email subscription address. + +199-11-28 Mike Welles + + * Fixed apocalypse-inducing y2k bug in contrib/ras/ras2tiff.c + + * Did some casts cleaning up to reduce compiler warnings in tif_fax3.c, + from Bruce Carmeron -- modifications of + changes made by Frank (sun cc still complained on cast). + + * Added tiffconf.h to install target per request from Bill + Radcliffe : "We need a way for ImageMagick to + know features have been compiled into the TIFF library in order to + handle things properly". + +Sat Nov 27 16:49:21 1999 Frank Warmerdam + + * fixed various VC++ warnings as suggested by Gilles Vollant + . + +Wed Nov 24 12:08:16 1999 Frank Warmerdam + + * Modified TIFFquery.3t man pages info on TIFFIsByteSwapped() to + not imply applications are responsible for image data swapping. + +1999-11-22 Mike Welles + * HTML-ized the man pages, added to html/man + + * Removed LZW Compression to comply with Unisys patent extortion. + +1999-09-29 Mike Welles + * Corrected one remaining 16 -> 32 bit value in tif_fax3.c, + From Ivo Penzar + +1999-09-26 Mike Welles *** 3.5.2 release *** + * Corrected alpha versioning. + + * Removed distinction between alpha and release targets in Makefile.in. + + * added release.stamp target, which tags cvs tree, and updates + "RELEASE-DATE" + + * added releasediff target, which diffs tree with source as of + date in "RELEASE-DATE" + + * Ticked up version to 3.5.2 (alpha 01 -- but I think we'll moving + away from alpha/non-alpha distinctions). + + * updated html to reflect release + +1999-09-23 + + * Set O_BINARY for tif_unix.c open() ... used on cygwin for instance. + + * Added CYGWIN case in configure. + +Fri Sep 17 00:13:51 CEST 1999 Mike Welles + + * Applied Francois Dagand's patch to handle fax decompression bug. + (sizes >= 65536 were failing) + +Tue Sep 14 21:31:43 1999 Frank Warmerdam + + * Applied "a" mode fix to tif_win32.c/TIFFOpen() as suggested + by Christopher Lawton + +Wed Sep 8 08:19:18 1999 Frank Warmerdam + + * Added IRIX/gcc, and OSF/1 4.x support on behalf of + Albert Chin-A-Young + + * Added TIFFReassignTagToIgnore() API on behalf of + Bruce Cameron . Man page still pending. + +Wed Aug 25 11:39:07 1999 Frank Warmerdam + + * Added test target in Makefile, test_pics.sh script and pics/*.rpt + files to provide for a rudimentary testsuite. + + * Added contrib/tags back from old distribution ... fixed up a bit. + +1999-08-16 + + * Added simple makefile.vc makefiles for building with MS VC++ + on Windows NT/98/95 in console mode. Stuff in contrib/win* make give + better solutions for some users. + +Mon Aug 16 21:52:11 1999 Frank Warmerdam + + * Added addtiffo (add overviews to a TIFF file) in contrib. Didn't + put it in tools since part of it is in C++. + +1999-08-16 Michael L. Welles + + * Updated html/index.html with anon CVS instructions. + +Mon Aug 16 13:18:41 1999 Frank Warmerdam + + * pre-remove so link before softlink in LINUXdso action in + libtiff/Makefile.in to avoid failure on LINUXdso builds other than + the first. + + * Fixed problem with cvtcmap() in tif_getimage.c modifying the + colormaps owned by the TIFF handle itself when trying to fixup wrong + (eight bit) colormaps. Corrected by maintaining a private copy of + the colormap. + + * Added TIFFReadRGBATile()/TIFFReadRGBAStrip() support in + tif_getimage.c. + + * CVS Repository placed at remotesensing.org. ChangeLog added. diff --git a/Source/LibTIFF/Makefile.am b/Source/LibTIFF/Makefile.am index 0aaac39..b918bb9 100644 --- a/Source/LibTIFF/Makefile.am +++ b/Source/LibTIFF/Makefile.am @@ -1,143 +1,143 @@ -# Tag Image File Format (TIFF) Software -# -# Copyright (C) 2004, Andrey Kiselev -# -# Permission to use, copy, modify, distribute, and sell this software and -# its documentation for any purpose is hereby granted without fee, provided -# that (i) the above copyright notices and this permission notice appear in -# all copies of the software and related documentation, and (ii) the names of -# Sam Leffler and Silicon Graphics may not be used in any advertising or -# publicity relating to the software without the specific, prior written -# permission of Sam Leffler and Silicon Graphics. -# -# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -# -# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR -# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, -# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF -# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -# OF THIS SOFTWARE. - -# Process this file with automake to produce Makefile.in. - -LIBPORT = $(top_builddir)/port/libport.la -LIBTIFF = $(top_builddir)/libtiff/libtiff.la -libtiffincludedir = $(includedir) - -EXTRA_DIST = Makefile.vc \ - SConstruct \ - tif_config.h-vms \ - tif_config.vc.h \ - tif_config.wince.h \ - tiffconf.vc.h \ - tiffconf.wince.h \ - libtiff.def \ - $(EXTRA_SRCS) - -libtiffinclude_HEADERS = \ - tiff.h \ - tiffio.h \ - tiffvers.h - -if HAVE_CXX -libtiffinclude_HEADERS += tiffio.hxx -endif - -noinst_HEADERS = \ - t4.h \ - tif_dir.h \ - tif_predict.h \ - tiffiop.h \ - uvcode.h - -nodist_libtiffinclude_HEADERS = \ - tiffconf.h - -libtiff_la_SOURCES = \ - tif_aux.c \ - tif_close.c \ - tif_codec.c \ - tif_color.c \ - tif_compress.c \ - tif_dir.c \ - tif_dirinfo.c \ - tif_dirread.c \ - tif_dirwrite.c \ - tif_dumpmode.c \ - tif_error.c \ - tif_extension.c \ - tif_fax3.c \ - tif_fax3sm.c \ - tif_flush.c \ - tif_getimage.c \ - tif_jbig.c \ - tif_jpeg.c \ - tif_luv.c \ - tif_lzw.c \ - tif_next.c \ - tif_ojpeg.c \ - tif_open.c \ - tif_packbits.c \ - tif_pixarlog.c \ - tif_predict.c \ - tif_print.c \ - tif_read.c \ - tif_strip.c \ - tif_swab.c \ - tif_thunder.c \ - tif_tile.c \ - tif_unix.c \ - tif_version.c \ - tif_warning.c \ - tif_write.c \ - tif_zip.c - -libtiffxx_la_SOURCES = \ - tif_stream.cxx - -EXTRA_SRCS = \ - tif_acorn.c \ - tif_apple.c \ - tif_atari.c \ - tif_msdos.c \ - tif_next.c \ - tif_win3.c \ - tif_win32.c - -lib_LTLIBRARIES = libtiff.la -if HAVE_CXX -lib_LTLIBRARIES += libtiffxx.la -endif - -libtiff_la_LDFLAGS = \ - -no-undefined \ - -version-number $(LIBTIFF_VERSION_INFO) -if HAVE_RPATH -libtiff_la_LDFLAGS += $(LIBDIR) -endif -libtiff_la_LIBADD = $(LIBPORT) - -libtiffxx_la_LDFLAGS = \ - -no-undefined \ - -version-number $(LIBTIFF_VERSION_INFO) -if HAVE_RPATH -libtiffxx_la_LDFLAGS += $(LIBDIR) -endif -libtiffxx_la_LIBADD = $(LIBTIFF) $(LIBPORT) -libtiffxx_la_DEPENDENCIES = libtiff.la - -# -# The finite state machine tables used by the G3/G4 decoders -# are generated by the mkg3states program. On systems without -# make these rules have to be manually carried out. -# -noinst_PROGRAMS = mkg3states -mkg3states_SOURCES = mkg3states.c tif_fax3.h -mkg3states_LDADD = $(LIBPORT) - -faxtable: mkg3states - (rm -f tif_fax3sm.c && ./mkg3states -b -c const tif_fax3sm.c) - +# Tag Image File Format (TIFF) Software +# +# Copyright (C) 2004, Andrey Kiselev +# +# Permission to use, copy, modify, distribute, and sell this software and +# its documentation for any purpose is hereby granted without fee, provided +# that (i) the above copyright notices and this permission notice appear in +# all copies of the software and related documentation, and (ii) the names of +# Sam Leffler and Silicon Graphics may not be used in any advertising or +# publicity relating to the software without the specific, prior written +# permission of Sam Leffler and Silicon Graphics. +# +# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, +# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY +# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. +# +# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR +# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, +# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF +# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. + +# Process this file with automake to produce Makefile.in. + +LIBPORT = $(top_builddir)/port/libport.la +LIBTIFF = $(top_builddir)/libtiff/libtiff.la +libtiffincludedir = $(includedir) + +EXTRA_DIST = Makefile.vc \ + SConstruct \ + tif_config.h-vms \ + tif_config.vc.h \ + tif_config.wince.h \ + tiffconf.vc.h \ + tiffconf.wince.h \ + libtiff.def \ + $(EXTRA_SRCS) + +libtiffinclude_HEADERS = \ + tiff.h \ + tiffio.h \ + tiffvers.h + +if HAVE_CXX +libtiffinclude_HEADERS += tiffio.hxx +endif + +noinst_HEADERS = \ + t4.h \ + tif_dir.h \ + tif_predict.h \ + tiffiop.h \ + uvcode.h + +nodist_libtiffinclude_HEADERS = \ + tiffconf.h + +libtiff_la_SOURCES = \ + tif_aux.c \ + tif_close.c \ + tif_codec.c \ + tif_color.c \ + tif_compress.c \ + tif_dir.c \ + tif_dirinfo.c \ + tif_dirread.c \ + tif_dirwrite.c \ + tif_dumpmode.c \ + tif_error.c \ + tif_extension.c \ + tif_fax3.c \ + tif_fax3sm.c \ + tif_flush.c \ + tif_getimage.c \ + tif_jbig.c \ + tif_jpeg.c \ + tif_luv.c \ + tif_lzw.c \ + tif_next.c \ + tif_ojpeg.c \ + tif_open.c \ + tif_packbits.c \ + tif_pixarlog.c \ + tif_predict.c \ + tif_print.c \ + tif_read.c \ + tif_strip.c \ + tif_swab.c \ + tif_thunder.c \ + tif_tile.c \ + tif_unix.c \ + tif_version.c \ + tif_warning.c \ + tif_write.c \ + tif_zip.c + +libtiffxx_la_SOURCES = \ + tif_stream.cxx + +EXTRA_SRCS = \ + tif_acorn.c \ + tif_apple.c \ + tif_atari.c \ + tif_msdos.c \ + tif_next.c \ + tif_win3.c \ + tif_win32.c + +lib_LTLIBRARIES = libtiff.la +if HAVE_CXX +lib_LTLIBRARIES += libtiffxx.la +endif + +libtiff_la_LDFLAGS = \ + -no-undefined \ + -version-number $(LIBTIFF_VERSION_INFO) +if HAVE_RPATH +libtiff_la_LDFLAGS += $(LIBDIR) +endif +libtiff_la_LIBADD = $(LIBPORT) + +libtiffxx_la_LDFLAGS = \ + -no-undefined \ + -version-number $(LIBTIFF_VERSION_INFO) +if HAVE_RPATH +libtiffxx_la_LDFLAGS += $(LIBDIR) +endif +libtiffxx_la_LIBADD = $(LIBTIFF) $(LIBPORT) +libtiffxx_la_DEPENDENCIES = libtiff.la + +# +# The finite state machine tables used by the G3/G4 decoders +# are generated by the mkg3states program. On systems without +# make these rules have to be manually carried out. +# +noinst_PROGRAMS = mkg3states +mkg3states_SOURCES = mkg3states.c tif_fax3.h +mkg3states_LDADD = $(LIBPORT) + +faxtable: mkg3states + (rm -f tif_fax3sm.c && ./mkg3states -b -c const tif_fax3sm.c) + diff --git a/Source/LibTIFF/Makefile.in b/Source/LibTIFF/Makefile.in index 10dbddf..2932630 100644 --- a/Source/LibTIFF/Makefile.in +++ b/Source/LibTIFF/Makefile.in @@ -1,884 +1,884 @@ -# Makefile.in generated by automake 1.11.1 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, -# Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ - -# Tag Image File Format (TIFF) Software -# -# Copyright (C) 2004, Andrey Kiselev -# -# Permission to use, copy, modify, distribute, and sell this software and -# its documentation for any purpose is hereby granted without fee, provided -# that (i) the above copyright notices and this permission notice appear in -# all copies of the software and related documentation, and (ii) the names of -# Sam Leffler and Silicon Graphics may not be used in any advertising or -# publicity relating to the software without the specific, prior written -# permission of Sam Leffler and Silicon Graphics. -# -# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -# -# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR -# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, -# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF -# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -# OF THIS SOFTWARE. - -# Process this file with automake to produce Makefile.in. - - - -VPATH = @srcdir@ -pkgdatadir = $(datadir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkglibexecdir = $(libexecdir)/@PACKAGE@ -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -build_triplet = @build@ -host_triplet = @host@ -@HAVE_CXX_TRUE@am__append_1 = tiffio.hxx -@HAVE_CXX_TRUE@am__append_2 = libtiffxx.la -@HAVE_RPATH_TRUE@am__append_3 = $(LIBDIR) -@HAVE_RPATH_TRUE@am__append_4 = $(LIBDIR) -noinst_PROGRAMS = mkg3states$(EXEEXT) -subdir = libtiff -DIST_COMMON = $(am__libtiffinclude_HEADERS_DIST) $(noinst_HEADERS) \ - $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ - $(srcdir)/tif_config.h.in $(srcdir)/tiffconf.h.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/acinclude.m4 \ - $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ - $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ - $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs -CONFIG_HEADER = tif_config.h tiffconf.h -CONFIG_CLEAN_FILES = -CONFIG_CLEAN_VPATH_FILES = -am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; -am__vpath_adj = case $$p in \ - $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ - *) f=$$p;; \ - esac; -am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; -am__install_max = 40 -am__nobase_strip_setup = \ - srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` -am__nobase_strip = \ - for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" -am__nobase_list = $(am__nobase_strip_setup); \ - for p in $$list; do echo "$$p $$p"; done | \ - sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ - $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ - if (++n[$$2] == $(am__install_max)) \ - { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ - END { for (dir in files) print dir, files[dir] }' -am__base_list = \ - sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ - sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' -am__installdirs = "$(DESTDIR)$(libdir)" \ - "$(DESTDIR)$(libtiffincludedir)" \ - "$(DESTDIR)$(libtiffincludedir)" -LTLIBRARIES = $(lib_LTLIBRARIES) -libtiff_la_DEPENDENCIES = $(LIBPORT) -am_libtiff_la_OBJECTS = tif_aux.lo tif_close.lo tif_codec.lo \ - tif_color.lo tif_compress.lo tif_dir.lo tif_dirinfo.lo \ - tif_dirread.lo tif_dirwrite.lo tif_dumpmode.lo tif_error.lo \ - tif_extension.lo tif_fax3.lo tif_fax3sm.lo tif_flush.lo \ - tif_getimage.lo tif_jbig.lo tif_jpeg.lo tif_luv.lo tif_lzw.lo \ - tif_next.lo tif_ojpeg.lo tif_open.lo tif_packbits.lo \ - tif_pixarlog.lo tif_predict.lo tif_print.lo tif_read.lo \ - tif_strip.lo tif_swab.lo tif_thunder.lo tif_tile.lo \ - tif_unix.lo tif_version.lo tif_warning.lo tif_write.lo \ - tif_zip.lo -libtiff_la_OBJECTS = $(am_libtiff_la_OBJECTS) -AM_V_lt = $(am__v_lt_$(V)) -am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) -am__v_lt_0 = --silent -libtiff_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(libtiff_la_LDFLAGS) $(LDFLAGS) -o $@ -am_libtiffxx_la_OBJECTS = tif_stream.lo -libtiffxx_la_OBJECTS = $(am_libtiffxx_la_OBJECTS) -libtiffxx_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(libtiffxx_la_LDFLAGS) $(LDFLAGS) -o $@ -@HAVE_CXX_TRUE@am_libtiffxx_la_rpath = -rpath $(libdir) -PROGRAMS = $(noinst_PROGRAMS) -am_mkg3states_OBJECTS = mkg3states.$(OBJEXT) -mkg3states_OBJECTS = $(am_mkg3states_OBJECTS) -mkg3states_DEPENDENCIES = $(LIBPORT) -DEFAULT_INCLUDES = -I.@am__isrc@ -depcomp = $(SHELL) $(top_srcdir)/config/depcomp -am__depfiles_maybe = depfiles -am__mv = mv -f -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ - $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ - $(AM_CFLAGS) $(CFLAGS) -AM_V_CC = $(am__v_CC_$(V)) -am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) -am__v_CC_0 = @echo " CC " $@; -AM_V_at = $(am__v_at_$(V)) -am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) -am__v_at_0 = @ -CCLD = $(CC) -LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(AM_LDFLAGS) $(LDFLAGS) -o $@ -AM_V_CCLD = $(am__v_CCLD_$(V)) -am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) -am__v_CCLD_0 = @echo " CCLD " $@; -CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \ - $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ - $(AM_CXXFLAGS) $(CXXFLAGS) -AM_V_CXX = $(am__v_CXX_$(V)) -am__v_CXX_ = $(am__v_CXX_$(AM_DEFAULT_VERBOSITY)) -am__v_CXX_0 = @echo " CXX " $@; -CXXLD = $(CXX) -CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ -AM_V_CXXLD = $(am__v_CXXLD_$(V)) -am__v_CXXLD_ = $(am__v_CXXLD_$(AM_DEFAULT_VERBOSITY)) -am__v_CXXLD_0 = @echo " CXXLD " $@; -AM_V_GEN = $(am__v_GEN_$(V)) -am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) -am__v_GEN_0 = @echo " GEN " $@; -SOURCES = $(libtiff_la_SOURCES) $(libtiffxx_la_SOURCES) \ - $(mkg3states_SOURCES) -DIST_SOURCES = $(libtiff_la_SOURCES) $(libtiffxx_la_SOURCES) \ - $(mkg3states_SOURCES) -am__libtiffinclude_HEADERS_DIST = tiff.h tiffio.h tiffvers.h \ - tiffio.hxx -HEADERS = $(libtiffinclude_HEADERS) $(nodist_libtiffinclude_HEADERS) \ - $(noinst_HEADERS) -ETAGS = etags -CTAGS = ctags -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = @ACLOCAL@ -AMTAR = @AMTAR@ -AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ -AR = @AR@ -AS = @AS@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -DLLTOOL = @DLLTOOL@ -DSYMUTIL = @DSYMUTIL@ -DUMPBIN = @DUMPBIN@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -FGREP = @FGREP@ -GLUT_CFLAGS = @GLUT_CFLAGS@ -GLUT_LIBS = @GLUT_LIBS@ -GLU_CFLAGS = @GLU_CFLAGS@ -GLU_LIBS = @GLU_LIBS@ -GL_CFLAGS = @GL_CFLAGS@ -GL_LIBS = @GL_LIBS@ -GREP = @GREP@ -INSTALL = @INSTALL@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -LD = @LD@ -LDFLAGS = @LDFLAGS@ -LIBDIR = @LIBDIR@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LIBTIFF_ALPHA_VERSION = @LIBTIFF_ALPHA_VERSION@ -LIBTIFF_DOCDIR = @LIBTIFF_DOCDIR@ -LIBTIFF_MAJOR_VERSION = @LIBTIFF_MAJOR_VERSION@ -LIBTIFF_MICRO_VERSION = @LIBTIFF_MICRO_VERSION@ -LIBTIFF_MINOR_VERSION = @LIBTIFF_MINOR_VERSION@ -LIBTIFF_RELEASE_DATE = @LIBTIFF_RELEASE_DATE@ -LIBTIFF_VERSION = @LIBTIFF_VERSION@ -LIBTIFF_VERSION_INFO = @LIBTIFF_VERSION_INFO@ -LIBTOOL = @LIBTOOL@ -LIPO = @LIPO@ -LN_S = @LN_S@ -LTLIBOBJS = @LTLIBOBJS@ -MAINT = @MAINT@ -MAKEINFO = @MAKEINFO@ -MANIFEST_TOOL = @MANIFEST_TOOL@ -MKDIR_P = @MKDIR_P@ -NM = @NM@ -NMEDIT = @NMEDIT@ -OBJDUMP = @OBJDUMP@ -OBJEXT = @OBJEXT@ -OTOOL = @OTOOL@ -OTOOL64 = @OTOOL64@ -PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_URL = @PACKAGE_URL@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_SEPARATOR = @PATH_SEPARATOR@ -PTHREAD_CC = @PTHREAD_CC@ -PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ -PTHREAD_LIBS = @PTHREAD_LIBS@ -RANLIB = @RANLIB@ -SED = @SED@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -STRIP = @STRIP@ -VERSION = @VERSION@ -XMKMF = @XMKMF@ -X_CFLAGS = @X_CFLAGS@ -X_EXTRA_LIBS = @X_EXTRA_LIBS@ -X_LIBS = @X_LIBS@ -X_PRE_LIBS = @X_PRE_LIBS@ -abs_builddir = @abs_builddir@ -abs_srcdir = @abs_srcdir@ -abs_top_builddir = @abs_top_builddir@ -abs_top_srcdir = @abs_top_srcdir@ -ac_ct_AR = @ac_ct_AR@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ -acx_pthread_config = @acx_pthread_config@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -am__tar = @am__tar@ -am__untar = @am__untar@ -bindir = @bindir@ -build = @build@ -build_alias = @build_alias@ -build_cpu = @build_cpu@ -build_os = @build_os@ -build_vendor = @build_vendor@ -builddir = @builddir@ -datadir = @datadir@ -datarootdir = @datarootdir@ -docdir = @docdir@ -dvidir = @dvidir@ -exec_prefix = @exec_prefix@ -host = @host@ -host_alias = @host_alias@ -host_cpu = @host_cpu@ -host_os = @host_os@ -host_vendor = @host_vendor@ -htmldir = @htmldir@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localedir = @localedir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -oldincludedir = @oldincludedir@ -pdfdir = @pdfdir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -psdir = @psdir@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -srcdir = @srcdir@ -sysconfdir = @sysconfdir@ -target_alias = @target_alias@ -top_build_prefix = @top_build_prefix@ -top_builddir = @top_builddir@ -top_srcdir = @top_srcdir@ -LIBPORT = $(top_builddir)/port/libport.la -LIBTIFF = $(top_builddir)/libtiff/libtiff.la -libtiffincludedir = $(includedir) -EXTRA_DIST = Makefile.vc \ - SConstruct \ - tif_config.h-vms \ - tif_config.vc.h \ - tif_config.wince.h \ - tiffconf.vc.h \ - tiffconf.wince.h \ - libtiff.def \ - $(EXTRA_SRCS) - -libtiffinclude_HEADERS = tiff.h tiffio.h tiffvers.h $(am__append_1) -noinst_HEADERS = \ - t4.h \ - tif_dir.h \ - tif_predict.h \ - tiffiop.h \ - uvcode.h - -nodist_libtiffinclude_HEADERS = \ - tiffconf.h - -libtiff_la_SOURCES = \ - tif_aux.c \ - tif_close.c \ - tif_codec.c \ - tif_color.c \ - tif_compress.c \ - tif_dir.c \ - tif_dirinfo.c \ - tif_dirread.c \ - tif_dirwrite.c \ - tif_dumpmode.c \ - tif_error.c \ - tif_extension.c \ - tif_fax3.c \ - tif_fax3sm.c \ - tif_flush.c \ - tif_getimage.c \ - tif_jbig.c \ - tif_jpeg.c \ - tif_luv.c \ - tif_lzw.c \ - tif_next.c \ - tif_ojpeg.c \ - tif_open.c \ - tif_packbits.c \ - tif_pixarlog.c \ - tif_predict.c \ - tif_print.c \ - tif_read.c \ - tif_strip.c \ - tif_swab.c \ - tif_thunder.c \ - tif_tile.c \ - tif_unix.c \ - tif_version.c \ - tif_warning.c \ - tif_write.c \ - tif_zip.c - -libtiffxx_la_SOURCES = \ - tif_stream.cxx - -EXTRA_SRCS = \ - tif_acorn.c \ - tif_apple.c \ - tif_atari.c \ - tif_msdos.c \ - tif_next.c \ - tif_win3.c \ - tif_win32.c - -lib_LTLIBRARIES = libtiff.la $(am__append_2) -libtiff_la_LDFLAGS = -no-undefined -version-number \ - $(LIBTIFF_VERSION_INFO) $(am__append_3) -libtiff_la_LIBADD = $(LIBPORT) -libtiffxx_la_LDFLAGS = -no-undefined -version-number \ - $(LIBTIFF_VERSION_INFO) $(am__append_4) -libtiffxx_la_LIBADD = $(LIBTIFF) $(LIBPORT) -libtiffxx_la_DEPENDENCIES = libtiff.la -mkg3states_SOURCES = mkg3states.c tif_fax3.h -mkg3states_LDADD = $(LIBPORT) -all: tif_config.h tiffconf.h - $(MAKE) $(AM_MAKEFLAGS) all-am - -.SUFFIXES: -.SUFFIXES: .c .cxx .lo .o .obj -$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ - && { if test -f $@; then exit 0; else break; fi; }; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libtiff/Makefile'; \ - $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --foreign libtiff/Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(am__aclocal_m4_deps): - -tif_config.h: stamp-h1 - @if test ! -f $@; then \ - rm -f stamp-h1; \ - $(MAKE) $(AM_MAKEFLAGS) stamp-h1; \ - else :; fi - -stamp-h1: $(srcdir)/tif_config.h.in $(top_builddir)/config.status - @rm -f stamp-h1 - cd $(top_builddir) && $(SHELL) ./config.status libtiff/tif_config.h -$(srcdir)/tif_config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) - ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) - rm -f stamp-h1 - touch $@ - -tiffconf.h: stamp-h2 - @if test ! -f $@; then \ - rm -f stamp-h2; \ - $(MAKE) $(AM_MAKEFLAGS) stamp-h2; \ - else :; fi - -stamp-h2: $(srcdir)/tiffconf.h.in $(top_builddir)/config.status - @rm -f stamp-h2 - cd $(top_builddir) && $(SHELL) ./config.status libtiff/tiffconf.h - -distclean-hdr: - -rm -f tif_config.h stamp-h1 tiffconf.h stamp-h2 -install-libLTLIBRARIES: $(lib_LTLIBRARIES) - @$(NORMAL_INSTALL) - test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" - @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ - list2=; for p in $$list; do \ - if test -f $$p; then \ - list2="$$list2 $$p"; \ - else :; fi; \ - done; \ - test -z "$$list2" || { \ - echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ - $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ - } - -uninstall-libLTLIBRARIES: - @$(NORMAL_UNINSTALL) - @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ - for p in $$list; do \ - $(am__strip_dir) \ - echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ - $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ - done - -clean-libLTLIBRARIES: - -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) - @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ - dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ - test "$$dir" != "$$p" || dir=.; \ - echo "rm -f \"$${dir}/so_locations\""; \ - rm -f "$${dir}/so_locations"; \ - done -libtiff.la: $(libtiff_la_OBJECTS) $(libtiff_la_DEPENDENCIES) - $(AM_V_CCLD)$(libtiff_la_LINK) -rpath $(libdir) $(libtiff_la_OBJECTS) $(libtiff_la_LIBADD) $(LIBS) -libtiffxx.la: $(libtiffxx_la_OBJECTS) $(libtiffxx_la_DEPENDENCIES) - $(AM_V_CXXLD)$(libtiffxx_la_LINK) $(am_libtiffxx_la_rpath) $(libtiffxx_la_OBJECTS) $(libtiffxx_la_LIBADD) $(LIBS) - -clean-noinstPROGRAMS: - @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \ - echo " rm -f" $$list; \ - rm -f $$list || exit $$?; \ - test -n "$(EXEEXT)" || exit 0; \ - list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ - echo " rm -f" $$list; \ - rm -f $$list -mkg3states$(EXEEXT): $(mkg3states_OBJECTS) $(mkg3states_DEPENDENCIES) - @rm -f mkg3states$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(mkg3states_OBJECTS) $(mkg3states_LDADD) $(LIBS) - -mostlyclean-compile: - -rm -f *.$(OBJEXT) - -distclean-compile: - -rm -f *.tab.c - -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mkg3states.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_aux.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_close.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_codec.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_color.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_compress.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_dir.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_dirinfo.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_dirread.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_dirwrite.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_dumpmode.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_error.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_extension.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_fax3.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_fax3sm.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_flush.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_getimage.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_jbig.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_jpeg.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_luv.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_lzw.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_next.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_ojpeg.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_open.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_packbits.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_pixarlog.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_predict.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_print.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_read.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_stream.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_strip.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_swab.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_thunder.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_tile.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_unix.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_version.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_warning.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_write.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_zip.Plo@am__quote@ - -.c.o: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(COMPILE) -c $< - -.c.obj: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` - -.c.lo: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo -@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< - -.cxx.o: -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< - -.cxx.obj: -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` - -.cxx.lo: -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< - -mostlyclean-libtool: - -rm -f *.lo - -clean-libtool: - -rm -rf .libs _libs -install-libtiffincludeHEADERS: $(libtiffinclude_HEADERS) - @$(NORMAL_INSTALL) - test -z "$(libtiffincludedir)" || $(MKDIR_P) "$(DESTDIR)$(libtiffincludedir)" - @list='$(libtiffinclude_HEADERS)'; test -n "$(libtiffincludedir)" || list=; \ - for p in $$list; do \ - if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ - echo "$$d$$p"; \ - done | $(am__base_list) | \ - while read files; do \ - echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libtiffincludedir)'"; \ - $(INSTALL_HEADER) $$files "$(DESTDIR)$(libtiffincludedir)" || exit $$?; \ - done - -uninstall-libtiffincludeHEADERS: - @$(NORMAL_UNINSTALL) - @list='$(libtiffinclude_HEADERS)'; test -n "$(libtiffincludedir)" || list=; \ - files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ - test -n "$$files" || exit 0; \ - echo " ( cd '$(DESTDIR)$(libtiffincludedir)' && rm -f" $$files ")"; \ - cd "$(DESTDIR)$(libtiffincludedir)" && rm -f $$files -install-nodist_libtiffincludeHEADERS: $(nodist_libtiffinclude_HEADERS) - @$(NORMAL_INSTALL) - test -z "$(libtiffincludedir)" || $(MKDIR_P) "$(DESTDIR)$(libtiffincludedir)" - @list='$(nodist_libtiffinclude_HEADERS)'; test -n "$(libtiffincludedir)" || list=; \ - for p in $$list; do \ - if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ - echo "$$d$$p"; \ - done | $(am__base_list) | \ - while read files; do \ - echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libtiffincludedir)'"; \ - $(INSTALL_HEADER) $$files "$(DESTDIR)$(libtiffincludedir)" || exit $$?; \ - done - -uninstall-nodist_libtiffincludeHEADERS: - @$(NORMAL_UNINSTALL) - @list='$(nodist_libtiffinclude_HEADERS)'; test -n "$(libtiffincludedir)" || list=; \ - files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ - test -n "$$files" || exit 0; \ - echo " ( cd '$(DESTDIR)$(libtiffincludedir)' && rm -f" $$files ")"; \ - cd "$(DESTDIR)$(libtiffincludedir)" && rm -f $$files - -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - mkid -fID $$unique -tags: TAGS - -TAGS: $(HEADERS) $(SOURCES) tif_config.h.in tiffconf.h.in $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - set x; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) tif_config.h.in tiffconf.h.in $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - shift; \ - if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ - test -n "$$unique" || unique=$$empty_fix; \ - if test $$# -gt 0; then \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - "$$@" $$unique; \ - else \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$unique; \ - fi; \ - fi -ctags: CTAGS -CTAGS: $(HEADERS) $(SOURCES) tif_config.h.in tiffconf.h.in $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - list='$(SOURCES) $(HEADERS) tif_config.h.in tiffconf.h.in $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - test -z "$(CTAGS_ARGS)$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && $(am__cd) $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) "$$here" - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - list='$(DISTFILES)'; \ - dist_files=`for file in $$list; do echo $$file; done | \ - sed -e "s|^$$srcdirstrip/||;t" \ - -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ - case $$dist_files in \ - */*) $(MKDIR_P) `echo "$$dist_files" | \ - sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ - sort -u` ;; \ - esac; \ - for file in $$dist_files; do \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - if test -d $$d/$$file; then \ - dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test -d "$(distdir)/$$file"; then \ - find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ - fi; \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ - find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ - fi; \ - cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ - else \ - test -f "$(distdir)/$$file" \ - || cp -p $$d/$$file "$(distdir)/$$file" \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: check-am -all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS) tif_config.h \ - tiffconf.h -installdirs: - for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(libtiffincludedir)" "$(DESTDIR)$(libtiffincludedir)"; do \ - test -z "$$dir" || $(MKDIR_P) "$$dir"; \ - done -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -clean: clean-am - -clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ - clean-noinstPROGRAMS mostlyclean-am - -distclean: distclean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-generic \ - distclean-hdr distclean-tags - -dvi: dvi-am - -dvi-am: - -html: html-am - -html-am: - -info: info-am - -info-am: - -install-data-am: install-libtiffincludeHEADERS \ - install-nodist_libtiffincludeHEADERS - -install-dvi: install-dvi-am - -install-dvi-am: - -install-exec-am: install-libLTLIBRARIES - -install-html: install-html-am - -install-html-am: - -install-info: install-info-am - -install-info-am: - -install-man: - -install-pdf: install-pdf-am - -install-pdf-am: - -install-ps: install-ps-am - -install-ps-am: - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-compile mostlyclean-generic \ - mostlyclean-libtool - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: uninstall-libLTLIBRARIES uninstall-libtiffincludeHEADERS \ - uninstall-nodist_libtiffincludeHEADERS - -.MAKE: all install-am install-strip - -.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ - clean-libLTLIBRARIES clean-libtool clean-noinstPROGRAMS ctags \ - distclean distclean-compile distclean-generic distclean-hdr \ - distclean-libtool distclean-tags distdir dvi dvi-am html \ - html-am info info-am install install-am install-data \ - install-data-am install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-libLTLIBRARIES \ - install-libtiffincludeHEADERS install-man \ - install-nodist_libtiffincludeHEADERS install-pdf \ - install-pdf-am install-ps install-ps-am install-strip \ - installcheck installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - tags uninstall uninstall-am uninstall-libLTLIBRARIES \ - uninstall-libtiffincludeHEADERS \ - uninstall-nodist_libtiffincludeHEADERS - - -faxtable: mkg3states - (rm -f tif_fax3sm.c && ./mkg3states -b -c const tif_fax3sm.c) - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +# Tag Image File Format (TIFF) Software +# +# Copyright (C) 2004, Andrey Kiselev +# +# Permission to use, copy, modify, distribute, and sell this software and +# its documentation for any purpose is hereby granted without fee, provided +# that (i) the above copyright notices and this permission notice appear in +# all copies of the software and related documentation, and (ii) the names of +# Sam Leffler and Silicon Graphics may not be used in any advertising or +# publicity relating to the software without the specific, prior written +# permission of Sam Leffler and Silicon Graphics. +# +# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, +# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY +# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. +# +# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR +# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, +# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF +# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. + +# Process this file with automake to produce Makefile.in. + + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +@HAVE_CXX_TRUE@am__append_1 = tiffio.hxx +@HAVE_CXX_TRUE@am__append_2 = libtiffxx.la +@HAVE_RPATH_TRUE@am__append_3 = $(LIBDIR) +@HAVE_RPATH_TRUE@am__append_4 = $(LIBDIR) +noinst_PROGRAMS = mkg3states$(EXEEXT) +subdir = libtiff +DIST_COMMON = $(am__libtiffinclude_HEADERS_DIST) $(noinst_HEADERS) \ + $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ + $(srcdir)/tif_config.h.in $(srcdir)/tiffconf.h.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs +CONFIG_HEADER = tif_config.h tiffconf.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(libdir)" \ + "$(DESTDIR)$(libtiffincludedir)" \ + "$(DESTDIR)$(libtiffincludedir)" +LTLIBRARIES = $(lib_LTLIBRARIES) +libtiff_la_DEPENDENCIES = $(LIBPORT) +am_libtiff_la_OBJECTS = tif_aux.lo tif_close.lo tif_codec.lo \ + tif_color.lo tif_compress.lo tif_dir.lo tif_dirinfo.lo \ + tif_dirread.lo tif_dirwrite.lo tif_dumpmode.lo tif_error.lo \ + tif_extension.lo tif_fax3.lo tif_fax3sm.lo tif_flush.lo \ + tif_getimage.lo tif_jbig.lo tif_jpeg.lo tif_luv.lo tif_lzw.lo \ + tif_next.lo tif_ojpeg.lo tif_open.lo tif_packbits.lo \ + tif_pixarlog.lo tif_predict.lo tif_print.lo tif_read.lo \ + tif_strip.lo tif_swab.lo tif_thunder.lo tif_tile.lo \ + tif_unix.lo tif_version.lo tif_warning.lo tif_write.lo \ + tif_zip.lo +libtiff_la_OBJECTS = $(am_libtiff_la_OBJECTS) +AM_V_lt = $(am__v_lt_$(V)) +am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) +am__v_lt_0 = --silent +libtiff_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libtiff_la_LDFLAGS) $(LDFLAGS) -o $@ +am_libtiffxx_la_OBJECTS = tif_stream.lo +libtiffxx_la_OBJECTS = $(am_libtiffxx_la_OBJECTS) +libtiffxx_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ + $(CXXFLAGS) $(libtiffxx_la_LDFLAGS) $(LDFLAGS) -o $@ +@HAVE_CXX_TRUE@am_libtiffxx_la_rpath = -rpath $(libdir) +PROGRAMS = $(noinst_PROGRAMS) +am_mkg3states_OBJECTS = mkg3states.$(OBJEXT) +mkg3states_OBJECTS = $(am_mkg3states_OBJECTS) +mkg3states_DEPENDENCIES = $(LIBPORT) +DEFAULT_INCLUDES = -I.@am__isrc@ +depcomp = $(SHELL) $(top_srcdir)/config/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +AM_V_CXX = $(am__v_CXX_$(V)) +am__v_CXX_ = $(am__v_CXX_$(AM_DEFAULT_VERBOSITY)) +am__v_CXX_0 = @echo " CXX " $@; +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ + $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CXXLD = $(am__v_CXXLD_$(V)) +am__v_CXXLD_ = $(am__v_CXXLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CXXLD_0 = @echo " CXXLD " $@; +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +SOURCES = $(libtiff_la_SOURCES) $(libtiffxx_la_SOURCES) \ + $(mkg3states_SOURCES) +DIST_SOURCES = $(libtiff_la_SOURCES) $(libtiffxx_la_SOURCES) \ + $(mkg3states_SOURCES) +am__libtiffinclude_HEADERS_DIST = tiff.h tiffio.h tiffvers.h \ + tiffio.hxx +HEADERS = $(libtiffinclude_HEADERS) $(nodist_libtiffinclude_HEADERS) \ + $(noinst_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AS = @AS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GLUT_CFLAGS = @GLUT_CFLAGS@ +GLUT_LIBS = @GLUT_LIBS@ +GLU_CFLAGS = @GLU_CFLAGS@ +GLU_LIBS = @GLU_LIBS@ +GL_CFLAGS = @GL_CFLAGS@ +GL_LIBS = @GL_LIBS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDIR = @LIBDIR@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTIFF_ALPHA_VERSION = @LIBTIFF_ALPHA_VERSION@ +LIBTIFF_DOCDIR = @LIBTIFF_DOCDIR@ +LIBTIFF_MAJOR_VERSION = @LIBTIFF_MAJOR_VERSION@ +LIBTIFF_MICRO_VERSION = @LIBTIFF_MICRO_VERSION@ +LIBTIFF_MINOR_VERSION = @LIBTIFF_MINOR_VERSION@ +LIBTIFF_RELEASE_DATE = @LIBTIFF_RELEASE_DATE@ +LIBTIFF_VERSION = @LIBTIFF_VERSION@ +LIBTIFF_VERSION_INFO = @LIBTIFF_VERSION_INFO@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PTHREAD_CC = @PTHREAD_CC@ +PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ +PTHREAD_LIBS = @PTHREAD_LIBS@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +XMKMF = @XMKMF@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +acx_pthread_config = @acx_pthread_config@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +LIBPORT = $(top_builddir)/port/libport.la +LIBTIFF = $(top_builddir)/libtiff/libtiff.la +libtiffincludedir = $(includedir) +EXTRA_DIST = Makefile.vc \ + SConstruct \ + tif_config.h-vms \ + tif_config.vc.h \ + tif_config.wince.h \ + tiffconf.vc.h \ + tiffconf.wince.h \ + libtiff.def \ + $(EXTRA_SRCS) + +libtiffinclude_HEADERS = tiff.h tiffio.h tiffvers.h $(am__append_1) +noinst_HEADERS = \ + t4.h \ + tif_dir.h \ + tif_predict.h \ + tiffiop.h \ + uvcode.h + +nodist_libtiffinclude_HEADERS = \ + tiffconf.h + +libtiff_la_SOURCES = \ + tif_aux.c \ + tif_close.c \ + tif_codec.c \ + tif_color.c \ + tif_compress.c \ + tif_dir.c \ + tif_dirinfo.c \ + tif_dirread.c \ + tif_dirwrite.c \ + tif_dumpmode.c \ + tif_error.c \ + tif_extension.c \ + tif_fax3.c \ + tif_fax3sm.c \ + tif_flush.c \ + tif_getimage.c \ + tif_jbig.c \ + tif_jpeg.c \ + tif_luv.c \ + tif_lzw.c \ + tif_next.c \ + tif_ojpeg.c \ + tif_open.c \ + tif_packbits.c \ + tif_pixarlog.c \ + tif_predict.c \ + tif_print.c \ + tif_read.c \ + tif_strip.c \ + tif_swab.c \ + tif_thunder.c \ + tif_tile.c \ + tif_unix.c \ + tif_version.c \ + tif_warning.c \ + tif_write.c \ + tif_zip.c + +libtiffxx_la_SOURCES = \ + tif_stream.cxx + +EXTRA_SRCS = \ + tif_acorn.c \ + tif_apple.c \ + tif_atari.c \ + tif_msdos.c \ + tif_next.c \ + tif_win3.c \ + tif_win32.c + +lib_LTLIBRARIES = libtiff.la $(am__append_2) +libtiff_la_LDFLAGS = -no-undefined -version-number \ + $(LIBTIFF_VERSION_INFO) $(am__append_3) +libtiff_la_LIBADD = $(LIBPORT) +libtiffxx_la_LDFLAGS = -no-undefined -version-number \ + $(LIBTIFF_VERSION_INFO) $(am__append_4) +libtiffxx_la_LIBADD = $(LIBTIFF) $(LIBPORT) +libtiffxx_la_DEPENDENCIES = libtiff.la +mkg3states_SOURCES = mkg3states.c tif_fax3.h +mkg3states_LDADD = $(LIBPORT) +all: tif_config.h tiffconf.h + $(MAKE) $(AM_MAKEFLAGS) all-am + +.SUFFIXES: +.SUFFIXES: .c .cxx .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libtiff/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign libtiff/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +tif_config.h: stamp-h1 + @if test ! -f $@; then \ + rm -f stamp-h1; \ + $(MAKE) $(AM_MAKEFLAGS) stamp-h1; \ + else :; fi + +stamp-h1: $(srcdir)/tif_config.h.in $(top_builddir)/config.status + @rm -f stamp-h1 + cd $(top_builddir) && $(SHELL) ./config.status libtiff/tif_config.h +$(srcdir)/tif_config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) + rm -f stamp-h1 + touch $@ + +tiffconf.h: stamp-h2 + @if test ! -f $@; then \ + rm -f stamp-h2; \ + $(MAKE) $(AM_MAKEFLAGS) stamp-h2; \ + else :; fi + +stamp-h2: $(srcdir)/tiffconf.h.in $(top_builddir)/config.status + @rm -f stamp-h2 + cd $(top_builddir) && $(SHELL) ./config.status libtiff/tiffconf.h + +distclean-hdr: + -rm -f tif_config.h stamp-h1 tiffconf.h stamp-h2 +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ + } + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libtiff.la: $(libtiff_la_OBJECTS) $(libtiff_la_DEPENDENCIES) + $(AM_V_CCLD)$(libtiff_la_LINK) -rpath $(libdir) $(libtiff_la_OBJECTS) $(libtiff_la_LIBADD) $(LIBS) +libtiffxx.la: $(libtiffxx_la_OBJECTS) $(libtiffxx_la_DEPENDENCIES) + $(AM_V_CXXLD)$(libtiffxx_la_LINK) $(am_libtiffxx_la_rpath) $(libtiffxx_la_OBJECTS) $(libtiffxx_la_LIBADD) $(LIBS) + +clean-noinstPROGRAMS: + @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +mkg3states$(EXEEXT): $(mkg3states_OBJECTS) $(mkg3states_DEPENDENCIES) + @rm -f mkg3states$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(mkg3states_OBJECTS) $(mkg3states_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mkg3states.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_aux.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_close.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_codec.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_color.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_compress.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_dir.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_dirinfo.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_dirread.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_dirwrite.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_dumpmode.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_error.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_extension.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_fax3.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_fax3sm.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_flush.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_getimage.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_jbig.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_jpeg.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_luv.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_lzw.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_next.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_ojpeg.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_open.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_packbits.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_pixarlog.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_predict.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_print.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_read.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_stream.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_strip.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_swab.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_thunder.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_tile.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_unix.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_version.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_warning.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_write.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_zip.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +.cxx.o: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< + +.cxx.obj: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cxx.lo: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-libtiffincludeHEADERS: $(libtiffinclude_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(libtiffincludedir)" || $(MKDIR_P) "$(DESTDIR)$(libtiffincludedir)" + @list='$(libtiffinclude_HEADERS)'; test -n "$(libtiffincludedir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libtiffincludedir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(libtiffincludedir)" || exit $$?; \ + done + +uninstall-libtiffincludeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(libtiffinclude_HEADERS)'; test -n "$(libtiffincludedir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '$(DESTDIR)$(libtiffincludedir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(libtiffincludedir)" && rm -f $$files +install-nodist_libtiffincludeHEADERS: $(nodist_libtiffinclude_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(libtiffincludedir)" || $(MKDIR_P) "$(DESTDIR)$(libtiffincludedir)" + @list='$(nodist_libtiffinclude_HEADERS)'; test -n "$(libtiffincludedir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libtiffincludedir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(libtiffincludedir)" || exit $$?; \ + done + +uninstall-nodist_libtiffincludeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(nodist_libtiffinclude_HEADERS)'; test -n "$(libtiffincludedir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '$(DESTDIR)$(libtiffincludedir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(libtiffincludedir)" && rm -f $$files + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) tif_config.h.in tiffconf.h.in $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) tif_config.h.in tiffconf.h.in $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) tif_config.h.in tiffconf.h.in $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) tif_config.h.in tiffconf.h.in $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS) tif_config.h \ + tiffconf.h +installdirs: + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(libtiffincludedir)" "$(DESTDIR)$(libtiffincludedir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ + clean-noinstPROGRAMS mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-hdr distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-libtiffincludeHEADERS \ + install-nodist_libtiffincludeHEADERS + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-libLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-libLTLIBRARIES uninstall-libtiffincludeHEADERS \ + uninstall-nodist_libtiffincludeHEADERS + +.MAKE: all install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool clean-noinstPROGRAMS ctags \ + distclean distclean-compile distclean-generic distclean-hdr \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-libLTLIBRARIES \ + install-libtiffincludeHEADERS install-man \ + install-nodist_libtiffincludeHEADERS install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-libLTLIBRARIES \ + uninstall-libtiffincludeHEADERS \ + uninstall-nodist_libtiffincludeHEADERS + + +faxtable: mkg3states + (rm -f tif_fax3sm.c && ./mkg3states -b -c const tif_fax3sm.c) + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/Source/LibTIFF/SConstruct b/Source/LibTIFF/SConstruct index d1a2620..50e0abc 100644 --- a/Source/LibTIFF/SConstruct +++ b/Source/LibTIFF/SConstruct @@ -1,73 +1,73 @@ -# $Id: SConstruct,v 1.29 2011/04/10 17:14:09 drolon Exp $ - -# Tag Image File Format (TIFF) Software -# -# Copyright (C) 2005, Andrey Kiselev -# -# Permission to use, copy, modify, distribute, and sell this software and -# its documentation for any purpose is hereby granted without fee, provided -# that (i) the above copyright notices and this permission notice appear in -# all copies of the software and related documentation, and (ii) the names of -# Sam Leffler and Silicon Graphics may not be used in any advertising or -# publicity relating to the software without the specific, prior written -# permission of Sam Leffler and Silicon Graphics. -# -# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -# -# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR -# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, -# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF -# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -# OF THIS SOFTWARE. - -# This file contains rules to build software with the SCons tool -# (see the http://www.scons.org/ for details on SCons). - -# Import globally defined options -Import([ 'env', 'idir_lib' ]) - -SRCS = [ \ - 'tif_aux.c', \ - 'tif_close.c', \ - 'tif_codec.c', \ - 'tif_color.c', \ - 'tif_compress.c', \ - 'tif_dir.c', \ - 'tif_dirinfo.c', \ - 'tif_dirread.c', \ - 'tif_dirwrite.c', \ - 'tif_dumpmode.c', \ - 'tif_error.c', \ - 'tif_extension.c', \ - 'tif_fax3.c', \ - 'tif_fax3sm.c', \ - 'tif_flush.c', \ - 'tif_getimage.c', \ - 'tif_jbig.c', \ - 'tif_jpeg.c', \ - 'tif_luv.c', \ - 'tif_lzw.c', \ - 'tif_next.c', \ - 'tif_ojpeg.c', \ - 'tif_open.c', \ - 'tif_packbits.c', \ - 'tif_pixarlog.c', \ - 'tif_predict.c', \ - 'tif_print.c', \ - 'tif_read.c', \ - 'tif_strip.c', \ - 'tif_swab.c', \ - 'tif_thunder.c', \ - 'tif_tile.c', \ - 'tif_unix.c', \ - 'tif_version.c', \ - 'tif_warning.c', \ - 'tif_write.c', \ - 'tif_zip.c' ] - -StaticLibrary('tiff', SRCS) -SharedLibrary('tiff', SRCS) - +# $Id: SConstruct,v 1.29 2011/04/10 17:14:09 drolon Exp $ + +# Tag Image File Format (TIFF) Software +# +# Copyright (C) 2005, Andrey Kiselev +# +# Permission to use, copy, modify, distribute, and sell this software and +# its documentation for any purpose is hereby granted without fee, provided +# that (i) the above copyright notices and this permission notice appear in +# all copies of the software and related documentation, and (ii) the names of +# Sam Leffler and Silicon Graphics may not be used in any advertising or +# publicity relating to the software without the specific, prior written +# permission of Sam Leffler and Silicon Graphics. +# +# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, +# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY +# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. +# +# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR +# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, +# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF +# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. + +# This file contains rules to build software with the SCons tool +# (see the http://www.scons.org/ for details on SCons). + +# Import globally defined options +Import([ 'env', 'idir_lib' ]) + +SRCS = [ \ + 'tif_aux.c', \ + 'tif_close.c', \ + 'tif_codec.c', \ + 'tif_color.c', \ + 'tif_compress.c', \ + 'tif_dir.c', \ + 'tif_dirinfo.c', \ + 'tif_dirread.c', \ + 'tif_dirwrite.c', \ + 'tif_dumpmode.c', \ + 'tif_error.c', \ + 'tif_extension.c', \ + 'tif_fax3.c', \ + 'tif_fax3sm.c', \ + 'tif_flush.c', \ + 'tif_getimage.c', \ + 'tif_jbig.c', \ + 'tif_jpeg.c', \ + 'tif_luv.c', \ + 'tif_lzw.c', \ + 'tif_next.c', \ + 'tif_ojpeg.c', \ + 'tif_open.c', \ + 'tif_packbits.c', \ + 'tif_pixarlog.c', \ + 'tif_predict.c', \ + 'tif_print.c', \ + 'tif_read.c', \ + 'tif_strip.c', \ + 'tif_swab.c', \ + 'tif_thunder.c', \ + 'tif_tile.c', \ + 'tif_unix.c', \ + 'tif_version.c', \ + 'tif_warning.c', \ + 'tif_write.c', \ + 'tif_zip.c' ] + +StaticLibrary('tiff', SRCS) +SharedLibrary('tiff', SRCS) + diff --git a/Source/LibTIFF/_FI_3151_PluginG3.cpp b/Source/LibTIFF/_FI_3151_PluginG3.cpp index 477e91e..a20df3c 100644 --- a/Source/LibTIFF/_FI_3151_PluginG3.cpp +++ b/Source/LibTIFF/_FI_3151_PluginG3.cpp @@ -1,433 +1,433 @@ -// ========================================================== -// G3 Fax Loader -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// - Petr Pytelka (pyta@lightcomp.com) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "../LibTIFF/tiffiop.h" - -#include "FreeImage.h" -#include "Utilities.h" - -// ========================================================== -// Plugin Interface -// ========================================================== - -static int s_format_id; - -// ========================================================== -// Constant/Macro declarations -// ========================================================== - -#define G3_DEFAULT_WIDTH 1728 - -#define TIFFhowmany8(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3) - -// ========================================================== -// libtiff interface -// ========================================================== - -static tsize_t -_g3ReadProc(thandle_t fd, tdata_t buf, tsize_t size) { - // returns an error when reading the TIFF header - return 0; -} - -static tsize_t -_g3WriteProc(thandle_t fd, tdata_t buf, tsize_t size) { - // returns ok when writing the TIFF header - return size; -} - -static toff_t -_g3SeekProc(thandle_t fd, toff_t off, int whence) { - return 0; -} - -static int -_g3CloseProc(thandle_t fd) { - return 0; -} - -static toff_t -_g3SizeProc(thandle_t fd) { - return 0; -} - -static int -_g3MapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) { - return 0; -} - -static void -_g3UnmapProc(thandle_t fd, tdata_t base, toff_t size) { -} - -// -------------------------------------------------------------- - -static toff_t -G3GetFileSize(FreeImageIO *io, fi_handle handle) { - long currentPos = io->tell_proc(handle); - io->seek_proc(handle, 0, SEEK_END); - long fileSize = io->tell_proc(handle); - io->seek_proc(handle, currentPos, SEEK_SET); - return fileSize; -} - -static BOOL -G3ReadFile(FreeImageIO *io, fi_handle handle, tidata_t tif_rawdata, tsize_t tif_rawdatasize) { - return ((tsize_t)(io->read_proc(tif_rawdata, tif_rawdatasize, 1, handle) * tif_rawdatasize) == tif_rawdatasize); -} - -// ========================================================== -// Internal functions -// ========================================================== - -static int -copyFaxFile(FreeImageIO *io, fi_handle handle, TIFF* tifin, uint32 xsize, int stretch, FIMEMORY *memory) { - BYTE *rowbuf = NULL; - BYTE *refbuf = NULL; - uint32 row; - uint16 badrun; - uint16 badfaxrun; - uint32 badfaxlines; - int ok; - - try { - - uint32 linesize = TIFFhowmany8(xsize); - rowbuf = (BYTE*) _TIFFmalloc(linesize); - refbuf = (BYTE*) _TIFFmalloc(linesize); - if (rowbuf == NULL || refbuf == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - tifin->tif_rawdatasize = G3GetFileSize(io, handle); - tifin->tif_rawdata = (tidata_t) _TIFFmalloc(tifin->tif_rawdatasize); - if (tifin->tif_rawdata == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - if(!G3ReadFile(io, handle, tifin->tif_rawdata, tifin->tif_rawdatasize)) { - throw "Read error at scanline 0"; - } - tifin->tif_rawcp = tifin->tif_rawdata; - tifin->tif_rawcc = tifin->tif_rawdatasize; - - (*tifin->tif_setupdecode)(tifin); - (*tifin->tif_predecode)(tifin, (tsample_t) 0); - tifin->tif_row = 0; - badfaxlines = 0; - badfaxrun = 0; - - _TIFFmemset(refbuf, 0, linesize); - row = 0; - badrun = 0; // current run of bad lines - while (tifin->tif_rawcc > 0) { - ok = (*tifin->tif_decoderow)(tifin, rowbuf, linesize, 0); - if (!ok) { - badfaxlines++; - badrun++; - // regenerate line from previous good line - _TIFFmemcpy(rowbuf, refbuf, linesize); - } else { - if (badrun > badfaxrun) - badfaxrun = badrun; - badrun = 0; - _TIFFmemcpy(refbuf, rowbuf, linesize); - } - tifin->tif_row++; - - FreeImage_WriteMemory(rowbuf, linesize, 1, memory); - row++; - if (stretch) { - FreeImage_WriteMemory(rowbuf, linesize, 1, memory); - row++; - } - } - if (badrun > badfaxrun) - badfaxrun = badrun; - - _TIFFfree(tifin->tif_rawdata); - tifin->tif_rawdata = NULL; - - _TIFFfree(rowbuf); - _TIFFfree(refbuf); - - /* - if (verbose) { - fprintf(stderr, "%d rows in input\n", rows); - fprintf(stderr, "%ld total bad rows\n", (long) badfaxlines); - fprintf(stderr, "%d max consecutive bad rows\n", badfaxrun); - } - */ - - } catch(const char *message) { - if(rowbuf) _TIFFfree(rowbuf); - if(refbuf) _TIFFfree(refbuf); - if(tifin->tif_rawdata) { - _TIFFfree(tifin->tif_rawdata); - tifin->tif_rawdata = NULL; - } - FreeImage_OutputMessageProc(s_format_id, message); - - return -1; - } - - return (row); -} - - -// ========================================================== -// Plugin Implementation -// ========================================================== - -static const char * DLL_CALLCONV -Format() { - return "G3"; -} - -static const char * DLL_CALLCONV -Description() { - return "Raw fax format CCITT G.3"; -} - -static const char * DLL_CALLCONV -Extension() { - return "g3"; -} - -static const char * DLL_CALLCONV -RegExpr() { - return NULL; // there is now reasonable regexp for raw G3 -} - -static const char * DLL_CALLCONV -MimeType() { - return "image/fax-g3"; -} - -static BOOL DLL_CALLCONV -SupportsExportDepth(int depth) { - return FALSE; -} - -// ---------------------------------------------------------- - -static FIBITMAP * DLL_CALLCONV -Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { - TIFF *faxTIFF = NULL; - FIBITMAP *dib = NULL; - FIMEMORY *memory = NULL; - - //int verbose = 0; - int stretch = 0; - int rows; - float resX = 204.0; - float resY = 196.0; - - uint32 xsize = G3_DEFAULT_WIDTH; - int compression_in = COMPRESSION_CCITTFAX3; - int fillorder_in = FILLORDER_LSB2MSB; - uint32 group3options_in = 0; // 1d-encoded - uint32 group4options_in = 0; // compressed - int photometric_in = PHOTOMETRIC_MINISWHITE; - - if(handle==NULL) return NULL; - - try { - // set default load options - - compression_in = COMPRESSION_CCITTFAX3; // input is g3-encoded - group3options_in &= ~GROUP3OPT_2DENCODING; // input is 1d-encoded (g3 only) - fillorder_in = FILLORDER_MSB2LSB; // input has msb-to-lsb fillorder - - /* - Original input-related fax2tiff options - - while ((c = getopt(argc, argv, "R:X:o:1234ABLMPUW5678abcflmprsuvwz?")) != -1) { - switch (c) { - // input-related options - case '3': // input is g3-encoded - compression_in = COMPRESSION_CCITTFAX3; - break; - case '4': // input is g4-encoded - compression_in = COMPRESSION_CCITTFAX4; - break; - case 'U': // input is uncompressed (g3 and g4) - group3options_in |= GROUP3OPT_UNCOMPRESSED; - group4options_in |= GROUP4OPT_UNCOMPRESSED; - break; - case '1': // input is 1d-encoded (g3 only) - group3options_in &= ~GROUP3OPT_2DENCODING; - break; - case '2': // input is 2d-encoded (g3 only) - group3options_in |= GROUP3OPT_2DENCODING; - break; - case 'P': // input has not-aligned EOL (g3 only) - group3options_in &= ~GROUP3OPT_FILLBITS; - break; - case 'A': // input has aligned EOL (g3 only) - group3options_in |= GROUP3OPT_FILLBITS; - break; - case 'W': // input has 0 mean white - photometric_in = PHOTOMETRIC_MINISWHITE; - break; - case 'B': // input has 0 mean black - photometric_in = PHOTOMETRIC_MINISBLACK; - break; - case 'L': // input has lsb-to-msb fillorder - fillorder_in = FILLORDER_LSB2MSB; - break; - case 'M': // input has msb-to-lsb fillorder - fillorder_in = FILLORDER_MSB2LSB; - break; - case 'R': // input resolution - resY = (float) atof(optarg); - break; - case 'X': // input width - xsize = (uint32) atoi(optarg); - break; - - // output-related options - case 's': // stretch image by dup'ng scanlines - stretch = 1; - break; - case 'v': // -v for info - verbose++; - break; - } - } - - */ - - // open a temporary memory buffer to save decoded scanlines - memory = FreeImage_OpenMemory(); - if(!memory) throw FI_MSG_ERROR_MEMORY; - - // wrap the raw fax file - faxTIFF = TIFFClientOpen("(FakeInput)", "w", - // TIFFClientOpen() fails if we don't set existing value here - NULL, - _g3ReadProc, _g3WriteProc, - _g3SeekProc, _g3CloseProc, - _g3SizeProc, _g3MapProc, - _g3UnmapProc); - - if (faxTIFF == NULL) { - throw "Can not create fake input file"; - } - TIFFSetMode(faxTIFF, O_RDONLY); - TIFFSetField(faxTIFF, TIFFTAG_IMAGEWIDTH, xsize); - TIFFSetField(faxTIFF, TIFFTAG_SAMPLESPERPIXEL, 1); - TIFFSetField(faxTIFF, TIFFTAG_BITSPERSAMPLE, 1); - TIFFSetField(faxTIFF, TIFFTAG_FILLORDER, fillorder_in); - TIFFSetField(faxTIFF, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); - TIFFSetField(faxTIFF, TIFFTAG_PHOTOMETRIC, photometric_in); - TIFFSetField(faxTIFF, TIFFTAG_YRESOLUTION, resY); - TIFFSetField(faxTIFF, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); - - // NB: this must be done after directory info is setup - TIFFSetField(faxTIFF, TIFFTAG_COMPRESSION, compression_in); - if (compression_in == COMPRESSION_CCITTFAX3) - TIFFSetField(faxTIFF, TIFFTAG_GROUP3OPTIONS, group3options_in); - else if (compression_in == COMPRESSION_CCITTFAX4) - TIFFSetField(faxTIFF, TIFFTAG_GROUP4OPTIONS, group4options_in); - - resX = 204; - if (!stretch) { - TIFFGetField(faxTIFF, TIFFTAG_YRESOLUTION, &resY); - } else { - resY = 196; - } - - // decode the raw fax data - rows = copyFaxFile(io, handle, faxTIFF, xsize, stretch, memory); - if(rows <= 0) throw "Error when decoding raw fax file : check the decoder options"; - - - // allocate the output dib - dib = FreeImage_Allocate(xsize, rows, 1); - unsigned pitch = FreeImage_GetPitch(dib); - uint32 linesize = TIFFhowmany8(xsize); - - // fill the bitmap structure ... - // ... palette - RGBQUAD *pal = FreeImage_GetPalette(dib); - if(photometric_in == PHOTOMETRIC_MINISWHITE) { - pal[0].rgbRed = pal[0].rgbGreen = pal[0].rgbBlue = 255; - pal[1].rgbRed = pal[1].rgbGreen = pal[1].rgbBlue = 0; - } else { - pal[0].rgbRed = pal[0].rgbGreen = pal[0].rgbBlue = 0; - pal[1].rgbRed = pal[1].rgbGreen = pal[1].rgbBlue = 255; - } - // ... resolution - FreeImage_SetDotsPerMeterX(dib, (unsigned)(resX/0.0254000 + 0.5)); - FreeImage_SetDotsPerMeterY(dib, (unsigned)(resY/0.0254000 + 0.5)); - - // read the decoded scanline and fill the bitmap data - FreeImage_SeekMemory(memory, 0, SEEK_SET); - BYTE *bits = FreeImage_GetScanLine(dib, rows - 1); - for(int k = 0; k < rows; k++) { - FreeImage_ReadMemory(bits, linesize, 1, memory); - bits -= pitch; - } - - // free the TIFF wrapper - TIFFClose(faxTIFF); - - // free the memory buffer - FreeImage_CloseMemory(memory); - - } catch(const char *message) { - if(memory) FreeImage_CloseMemory(memory); - if(faxTIFF) TIFFClose(faxTIFF); - if(dib) FreeImage_Unload(dib); - FreeImage_OutputMessageProc(s_format_id, message); - return NULL; - } - - return dib; - -} - -// ========================================================== -// Init -// ========================================================== - -void DLL_CALLCONV -InitG3(Plugin *plugin, int format_id) { - s_format_id = format_id; - - plugin->format_proc = Format; - plugin->description_proc = Description; - plugin->extension_proc = Extension; - plugin->regexpr_proc = RegExpr; - plugin->open_proc = NULL; - plugin->close_proc = NULL; - plugin->pagecount_proc = NULL; - plugin->pagecapability_proc = NULL; - plugin->load_proc = Load; - plugin->save_proc = NULL; - plugin->validate_proc = NULL; - plugin->mime_proc = MimeType; - plugin->supports_export_bpp_proc = SupportsExportDepth; - plugin->supports_export_type_proc = NULL; - plugin->supports_icc_profiles_proc = NULL; -} +// ========================================================== +// G3 Fax Loader +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// - Petr Pytelka (pyta@lightcomp.com) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "../LibTIFF/tiffiop.h" + +#include "FreeImage.h" +#include "Utilities.h" + +// ========================================================== +// Plugin Interface +// ========================================================== + +static int s_format_id; + +// ========================================================== +// Constant/Macro declarations +// ========================================================== + +#define G3_DEFAULT_WIDTH 1728 + +#define TIFFhowmany8(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3) + +// ========================================================== +// libtiff interface +// ========================================================== + +static tsize_t +_g3ReadProc(thandle_t fd, tdata_t buf, tsize_t size) { + // returns an error when reading the TIFF header + return 0; +} + +static tsize_t +_g3WriteProc(thandle_t fd, tdata_t buf, tsize_t size) { + // returns ok when writing the TIFF header + return size; +} + +static toff_t +_g3SeekProc(thandle_t fd, toff_t off, int whence) { + return 0; +} + +static int +_g3CloseProc(thandle_t fd) { + return 0; +} + +static toff_t +_g3SizeProc(thandle_t fd) { + return 0; +} + +static int +_g3MapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) { + return 0; +} + +static void +_g3UnmapProc(thandle_t fd, tdata_t base, toff_t size) { +} + +// -------------------------------------------------------------- + +static toff_t +G3GetFileSize(FreeImageIO *io, fi_handle handle) { + long currentPos = io->tell_proc(handle); + io->seek_proc(handle, 0, SEEK_END); + long fileSize = io->tell_proc(handle); + io->seek_proc(handle, currentPos, SEEK_SET); + return fileSize; +} + +static BOOL +G3ReadFile(FreeImageIO *io, fi_handle handle, tidata_t tif_rawdata, tsize_t tif_rawdatasize) { + return ((tsize_t)(io->read_proc(tif_rawdata, tif_rawdatasize, 1, handle) * tif_rawdatasize) == tif_rawdatasize); +} + +// ========================================================== +// Internal functions +// ========================================================== + +static int +copyFaxFile(FreeImageIO *io, fi_handle handle, TIFF* tifin, uint32 xsize, int stretch, FIMEMORY *memory) { + BYTE *rowbuf = NULL; + BYTE *refbuf = NULL; + uint32 row; + uint16 badrun; + uint16 badfaxrun; + uint32 badfaxlines; + int ok; + + try { + + uint32 linesize = TIFFhowmany8(xsize); + rowbuf = (BYTE*) _TIFFmalloc(linesize); + refbuf = (BYTE*) _TIFFmalloc(linesize); + if (rowbuf == NULL || refbuf == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + tifin->tif_rawdatasize = G3GetFileSize(io, handle); + tifin->tif_rawdata = (tidata_t) _TIFFmalloc(tifin->tif_rawdatasize); + if (tifin->tif_rawdata == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + if(!G3ReadFile(io, handle, tifin->tif_rawdata, tifin->tif_rawdatasize)) { + throw "Read error at scanline 0"; + } + tifin->tif_rawcp = tifin->tif_rawdata; + tifin->tif_rawcc = tifin->tif_rawdatasize; + + (*tifin->tif_setupdecode)(tifin); + (*tifin->tif_predecode)(tifin, (tsample_t) 0); + tifin->tif_row = 0; + badfaxlines = 0; + badfaxrun = 0; + + _TIFFmemset(refbuf, 0, linesize); + row = 0; + badrun = 0; // current run of bad lines + while (tifin->tif_rawcc > 0) { + ok = (*tifin->tif_decoderow)(tifin, rowbuf, linesize, 0); + if (!ok) { + badfaxlines++; + badrun++; + // regenerate line from previous good line + _TIFFmemcpy(rowbuf, refbuf, linesize); + } else { + if (badrun > badfaxrun) + badfaxrun = badrun; + badrun = 0; + _TIFFmemcpy(refbuf, rowbuf, linesize); + } + tifin->tif_row++; + + FreeImage_WriteMemory(rowbuf, linesize, 1, memory); + row++; + if (stretch) { + FreeImage_WriteMemory(rowbuf, linesize, 1, memory); + row++; + } + } + if (badrun > badfaxrun) + badfaxrun = badrun; + + _TIFFfree(tifin->tif_rawdata); + tifin->tif_rawdata = NULL; + + _TIFFfree(rowbuf); + _TIFFfree(refbuf); + + /* + if (verbose) { + fprintf(stderr, "%d rows in input\n", rows); + fprintf(stderr, "%ld total bad rows\n", (long) badfaxlines); + fprintf(stderr, "%d max consecutive bad rows\n", badfaxrun); + } + */ + + } catch(const char *message) { + if(rowbuf) _TIFFfree(rowbuf); + if(refbuf) _TIFFfree(refbuf); + if(tifin->tif_rawdata) { + _TIFFfree(tifin->tif_rawdata); + tifin->tif_rawdata = NULL; + } + FreeImage_OutputMessageProc(s_format_id, message); + + return -1; + } + + return (row); +} + + +// ========================================================== +// Plugin Implementation +// ========================================================== + +static const char * DLL_CALLCONV +Format() { + return "G3"; +} + +static const char * DLL_CALLCONV +Description() { + return "Raw fax format CCITT G.3"; +} + +static const char * DLL_CALLCONV +Extension() { + return "g3"; +} + +static const char * DLL_CALLCONV +RegExpr() { + return NULL; // there is now reasonable regexp for raw G3 +} + +static const char * DLL_CALLCONV +MimeType() { + return "image/fax-g3"; +} + +static BOOL DLL_CALLCONV +SupportsExportDepth(int depth) { + return FALSE; +} + +// ---------------------------------------------------------- + +static FIBITMAP * DLL_CALLCONV +Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { + TIFF *faxTIFF = NULL; + FIBITMAP *dib = NULL; + FIMEMORY *memory = NULL; + + //int verbose = 0; + int stretch = 0; + int rows; + float resX = 204.0; + float resY = 196.0; + + uint32 xsize = G3_DEFAULT_WIDTH; + int compression_in = COMPRESSION_CCITTFAX3; + int fillorder_in = FILLORDER_LSB2MSB; + uint32 group3options_in = 0; // 1d-encoded + uint32 group4options_in = 0; // compressed + int photometric_in = PHOTOMETRIC_MINISWHITE; + + if(handle==NULL) return NULL; + + try { + // set default load options + + compression_in = COMPRESSION_CCITTFAX3; // input is g3-encoded + group3options_in &= ~GROUP3OPT_2DENCODING; // input is 1d-encoded (g3 only) + fillorder_in = FILLORDER_MSB2LSB; // input has msb-to-lsb fillorder + + /* + Original input-related fax2tiff options + + while ((c = getopt(argc, argv, "R:X:o:1234ABLMPUW5678abcflmprsuvwz?")) != -1) { + switch (c) { + // input-related options + case '3': // input is g3-encoded + compression_in = COMPRESSION_CCITTFAX3; + break; + case '4': // input is g4-encoded + compression_in = COMPRESSION_CCITTFAX4; + break; + case 'U': // input is uncompressed (g3 and g4) + group3options_in |= GROUP3OPT_UNCOMPRESSED; + group4options_in |= GROUP4OPT_UNCOMPRESSED; + break; + case '1': // input is 1d-encoded (g3 only) + group3options_in &= ~GROUP3OPT_2DENCODING; + break; + case '2': // input is 2d-encoded (g3 only) + group3options_in |= GROUP3OPT_2DENCODING; + break; + case 'P': // input has not-aligned EOL (g3 only) + group3options_in &= ~GROUP3OPT_FILLBITS; + break; + case 'A': // input has aligned EOL (g3 only) + group3options_in |= GROUP3OPT_FILLBITS; + break; + case 'W': // input has 0 mean white + photometric_in = PHOTOMETRIC_MINISWHITE; + break; + case 'B': // input has 0 mean black + photometric_in = PHOTOMETRIC_MINISBLACK; + break; + case 'L': // input has lsb-to-msb fillorder + fillorder_in = FILLORDER_LSB2MSB; + break; + case 'M': // input has msb-to-lsb fillorder + fillorder_in = FILLORDER_MSB2LSB; + break; + case 'R': // input resolution + resY = (float) atof(optarg); + break; + case 'X': // input width + xsize = (uint32) atoi(optarg); + break; + + // output-related options + case 's': // stretch image by dup'ng scanlines + stretch = 1; + break; + case 'v': // -v for info + verbose++; + break; + } + } + + */ + + // open a temporary memory buffer to save decoded scanlines + memory = FreeImage_OpenMemory(); + if(!memory) throw FI_MSG_ERROR_MEMORY; + + // wrap the raw fax file + faxTIFF = TIFFClientOpen("(FakeInput)", "w", + // TIFFClientOpen() fails if we don't set existing value here + NULL, + _g3ReadProc, _g3WriteProc, + _g3SeekProc, _g3CloseProc, + _g3SizeProc, _g3MapProc, + _g3UnmapProc); + + if (faxTIFF == NULL) { + throw "Can not create fake input file"; + } + TIFFSetMode(faxTIFF, O_RDONLY); + TIFFSetField(faxTIFF, TIFFTAG_IMAGEWIDTH, xsize); + TIFFSetField(faxTIFF, TIFFTAG_SAMPLESPERPIXEL, 1); + TIFFSetField(faxTIFF, TIFFTAG_BITSPERSAMPLE, 1); + TIFFSetField(faxTIFF, TIFFTAG_FILLORDER, fillorder_in); + TIFFSetField(faxTIFF, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); + TIFFSetField(faxTIFF, TIFFTAG_PHOTOMETRIC, photometric_in); + TIFFSetField(faxTIFF, TIFFTAG_YRESOLUTION, resY); + TIFFSetField(faxTIFF, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); + + // NB: this must be done after directory info is setup + TIFFSetField(faxTIFF, TIFFTAG_COMPRESSION, compression_in); + if (compression_in == COMPRESSION_CCITTFAX3) + TIFFSetField(faxTIFF, TIFFTAG_GROUP3OPTIONS, group3options_in); + else if (compression_in == COMPRESSION_CCITTFAX4) + TIFFSetField(faxTIFF, TIFFTAG_GROUP4OPTIONS, group4options_in); + + resX = 204; + if (!stretch) { + TIFFGetField(faxTIFF, TIFFTAG_YRESOLUTION, &resY); + } else { + resY = 196; + } + + // decode the raw fax data + rows = copyFaxFile(io, handle, faxTIFF, xsize, stretch, memory); + if(rows <= 0) throw "Error when decoding raw fax file : check the decoder options"; + + + // allocate the output dib + dib = FreeImage_Allocate(xsize, rows, 1); + unsigned pitch = FreeImage_GetPitch(dib); + uint32 linesize = TIFFhowmany8(xsize); + + // fill the bitmap structure ... + // ... palette + RGBQUAD *pal = FreeImage_GetPalette(dib); + if(photometric_in == PHOTOMETRIC_MINISWHITE) { + pal[0].rgbRed = pal[0].rgbGreen = pal[0].rgbBlue = 255; + pal[1].rgbRed = pal[1].rgbGreen = pal[1].rgbBlue = 0; + } else { + pal[0].rgbRed = pal[0].rgbGreen = pal[0].rgbBlue = 0; + pal[1].rgbRed = pal[1].rgbGreen = pal[1].rgbBlue = 255; + } + // ... resolution + FreeImage_SetDotsPerMeterX(dib, (unsigned)(resX/0.0254000 + 0.5)); + FreeImage_SetDotsPerMeterY(dib, (unsigned)(resY/0.0254000 + 0.5)); + + // read the decoded scanline and fill the bitmap data + FreeImage_SeekMemory(memory, 0, SEEK_SET); + BYTE *bits = FreeImage_GetScanLine(dib, rows - 1); + for(int k = 0; k < rows; k++) { + FreeImage_ReadMemory(bits, linesize, 1, memory); + bits -= pitch; + } + + // free the TIFF wrapper + TIFFClose(faxTIFF); + + // free the memory buffer + FreeImage_CloseMemory(memory); + + } catch(const char *message) { + if(memory) FreeImage_CloseMemory(memory); + if(faxTIFF) TIFFClose(faxTIFF); + if(dib) FreeImage_Unload(dib); + FreeImage_OutputMessageProc(s_format_id, message); + return NULL; + } + + return dib; + +} + +// ========================================================== +// Init +// ========================================================== + +void DLL_CALLCONV +InitG3(Plugin *plugin, int format_id) { + s_format_id = format_id; + + plugin->format_proc = Format; + plugin->description_proc = Description; + plugin->extension_proc = Extension; + plugin->regexpr_proc = RegExpr; + plugin->open_proc = NULL; + plugin->close_proc = NULL; + plugin->pagecount_proc = NULL; + plugin->pagecapability_proc = NULL; + plugin->load_proc = Load; + plugin->save_proc = NULL; + plugin->validate_proc = NULL; + plugin->mime_proc = MimeType; + plugin->supports_export_bpp_proc = SupportsExportDepth; + plugin->supports_export_type_proc = NULL; + plugin->supports_icc_profiles_proc = NULL; +} diff --git a/Source/LibTIFF/_FI_3151_PluginTIFF.cpp b/Source/LibTIFF/_FI_3151_PluginTIFF.cpp index deca588..2a577e3 100644 --- a/Source/LibTIFF/_FI_3151_PluginTIFF.cpp +++ b/Source/LibTIFF/_FI_3151_PluginTIFF.cpp @@ -1,2628 +1,2628 @@ -// ========================================================== -// TIFF Loader and Writer -// -// Design and implementation by -// - Floris van den Berg (flvdberg@wxs.nl) -// - Hervé Drolon (drolon@infonie.fr) -// - Markus Loibl (markus.loibl@epost.de) -// - Luca Piergentili (l.pierge@terra.es) -// - Detlev Vendt (detlev.vendt@brillit.de) -// - Mihail Naydenov (mnaydenov@users.sourceforge.net) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#ifdef _MSC_VER -#pragma warning (disable : 4786) // identifier was truncated to 'number' characters -#endif - -#ifdef unix -#undef unix -#endif -#ifdef __unix -#undef __unix -#endif - -#include "FreeImage.h" -#include "Utilities.h" -#include "../LibTIFF/tiffiop.h" -#include "../Metadata/FreeImageTag.h" -#include "../OpenEXR/Half/half.h" - -#include "FreeImageIO.h" -#include "PSDParser.h" - -// ---------------------------------------------------------- -// geotiff interface (see XTIFF.cpp) -// ---------------------------------------------------------- - -// Extended TIFF Directory GEO Tag Support -void XTIFFInitialize(); - -// GeoTIFF profile -void tiff_read_geotiff_profile(TIFF *tif, FIBITMAP *dib); -void tiff_write_geotiff_profile(TIFF *tif, FIBITMAP *dib); - -// ---------------------------------------------------------- -// exif interface (see XTIFF.cpp) -// ---------------------------------------------------------- - -// TIFF Exif profile -BOOL tiff_read_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib); -BOOL tiff_write_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib); - -// ---------------------------------------------------------- -// LogLuv conversion functions interface (see TIFFLogLuv.cpp) -// ---------------------------------------------------------- - -void tiff_ConvertLineXYZToRGB(BYTE *target, BYTE *source, double stonits, int width_in_pixels); -void tiff_ConvertLineRGBToXYZ(BYTE *target, BYTE *source, int width_in_pixels); - -// ---------------------------------------------------------- - -/** Supported loading methods */ -typedef enum { - LoadAsRBGA = 0, - LoadAsCMYK = 1, - LoadAs8BitTrns = 2, - LoadAsGenericStrip = 3, - LoadAsTiled = 4, - LoadAsLogLuv = 5, - LoadAsHalfFloat = 6 -} TIFFLoadMethod; - -// ---------------------------------------------------------- -// local prototypes -// ---------------------------------------------------------- - -static tsize_t _tiffReadProc(thandle_t handle, tdata_t buf, tsize_t size); -static tsize_t _tiffWriteProc(thandle_t handle, tdata_t buf, tsize_t size); -static toff_t _tiffSeekProc(thandle_t handle, toff_t off, int whence); -static int _tiffCloseProc(thandle_t fd); -static int _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize); -static void _tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size); - -static uint16 CheckColormap(int n, uint16* r, uint16* g, uint16* b); -static uint16 GetPhotometric(FIBITMAP *dib); - -static void ReadResolution(TIFF *tiff, FIBITMAP *dib); -static void WriteResolution(TIFF *tiff, FIBITMAP *dib); - -static void ReadPalette(TIFF *tiff, uint16 photometric, uint16 bitspersample, FIBITMAP *dib); - -static FIBITMAP* CreateImageType(BOOL header_only, FREE_IMAGE_TYPE fit, int width, int height, uint16 bitspersample, uint16 samplesperpixel); -static FREE_IMAGE_TYPE ReadImageType(TIFF *tiff, uint16 bitspersample, uint16 samplesperpixel); -static void WriteImageType(TIFF *tiff, FREE_IMAGE_TYPE fit); - -static void WriteCompression(TIFF *tiff, uint16 bitspersample, uint16 samplesperpixel, uint16 photometric, int flags); - -static BOOL tiff_read_iptc_profile(TIFF *tiff, FIBITMAP *dib); -static BOOL tiff_read_xmp_profile(TIFF *tiff, FIBITMAP *dib); -static BOOL tiff_read_exif_profile(TIFF *tiff, FIBITMAP *dib); -static void ReadMetadata(TIFF *tiff, FIBITMAP *dib); - -static BOOL tiff_write_iptc_profile(TIFF *tiff, FIBITMAP *dib); -static BOOL tiff_write_xmp_profile(TIFF *tiff, FIBITMAP *dib); -static void WriteMetadata(TIFF *tiff, FIBITMAP *dib); - -static TIFFLoadMethod FindLoadMethod(TIFF *tif, uint16 photometric, uint16 bitspersample, uint16 samplesperpixel, FREE_IMAGE_TYPE image_type, int flags); - -static void ReadThumbnail(FreeImageIO *io, fi_handle handle, void *data, TIFF *tiff, FIBITMAP *dib); - - -// ========================================================== -// Plugin Interface -// ========================================================== - -static int s_format_id; - -typedef struct { - FreeImageIO *io; - fi_handle handle; - TIFF *tif; -} fi_TIFFIO; - -// ---------------------------------------------------------- -// libtiff interface -// ---------------------------------------------------------- - -static tsize_t -_tiffReadProc(thandle_t handle, tdata_t buf, tsize_t size) { - fi_TIFFIO *fio = (fi_TIFFIO*)handle; - return fio->io->read_proc(buf, size, 1, fio->handle) * size; -} - -static tsize_t -_tiffWriteProc(thandle_t handle, tdata_t buf, tsize_t size) { - fi_TIFFIO *fio = (fi_TIFFIO*)handle; - return fio->io->write_proc(buf, size, 1, fio->handle) * size; -} - -static toff_t -_tiffSeekProc(thandle_t handle, toff_t off, int whence) { - fi_TIFFIO *fio = (fi_TIFFIO*)handle; - fio->io->seek_proc(fio->handle, off, whence); - return fio->io->tell_proc(fio->handle); -} - -static int -_tiffCloseProc(thandle_t fd) { - return 0; -} - -#include - -static toff_t -_tiffSizeProc(thandle_t handle) { - fi_TIFFIO *fio = (fi_TIFFIO*)handle; - long currPos = fio->io->tell_proc(fio->handle); - fio->io->seek_proc(fio->handle, 0, SEEK_END); - long fileSize = fio->io->tell_proc(fio->handle); - fio->io->seek_proc(fio->handle, currPos, SEEK_SET); - return fileSize; -} - -static int -_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) { - return 0; -} - -static void -_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) { -} - -/** -Open a TIFF file descriptor for reading or writing -@param handle File handle -@param name Name of the file handle -@param mode Specifies if the file is to be opened for reading ("r") or writing ("w") -*/ -TIFF * -TIFFFdOpen(thandle_t handle, const char *name, const char *mode) { - TIFF *tif; - - // Set up the callback for extended TIFF directory tag support - // (see XTIFF.cpp) - XTIFFInitialize(); - - // Open the file; the callback will set everything up - tif = TIFFClientOpen(name, mode, handle, - _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, - _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); - - // Warning: tif_fd is declared as 'int' currently (see libTIFF), - // may result in incorrect file pointers inside libTIFF on - // 64bit machines (sizeof(int) != sizeof(long)). - // Needs to be fixed within libTIFF. - if (tif) { - tif->tif_fd = (long)handle; - } - - return tif; -} - -/** -Open a TIFF file for reading or writing -@param name -@param mode -*/ -TIFF* -TIFFOpen(const char* name, const char* mode) { - return 0; -} - -// ---------------------------------------------------------- -// TIFF library FreeImage-specific routines. -// ---------------------------------------------------------- - -tdata_t -_TIFFmalloc(tsize_t s) { - return malloc(s); -} - -void -_TIFFfree(tdata_t p) { - free(p); -} - -tdata_t -_TIFFrealloc(tdata_t p, tsize_t s) { - return realloc(p, s); -} - -void -_TIFFmemset(tdata_t p, int v, tsize_t c) { - memset(p, v, (size_t) c); -} - -void -_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) { - memcpy(d, s, (size_t) c); -} - -int -_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) { - return (memcmp(p1, p2, (size_t) c)); -} - -// ---------------------------------------------------------- -// in FreeImage warnings and errors are disabled -// ---------------------------------------------------------- - -static void -msdosWarningHandler(const char* module, const char* fmt, va_list ap) { -} - -TIFFErrorHandler _TIFFwarningHandler = msdosWarningHandler; - -static void -msdosErrorHandler(const char* module, const char* fmt, va_list ap) { - - // use this for diagnostic only (do not use otherwise, even in DEBUG mode) - /* - if (module != NULL) { - char msg[1024]; - vsprintf(msg, fmt, ap); - FreeImage_OutputMessageProc(s_format_id, "%s: %s", module, msg); - } - */ -} - -TIFFErrorHandler _TIFFerrorHandler = msdosErrorHandler; - -// ---------------------------------------------------------- - -#define CVT(x) (((x) * 255L) / ((1L<<16)-1)) -#define SCALE(x) (((x)*((1L<<16)-1))/255) - -// ========================================================== -// Internal functions -// ========================================================== - -static uint16 -CheckColormap(int n, uint16* r, uint16* g, uint16* b) { - while (n-- > 0) { - if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256) { - return 16; - } - } - - return 8; -} - -/** -Get the TIFFTAG_PHOTOMETRIC value from the dib -*/ -static uint16 -GetPhotometric(FIBITMAP *dib) { - FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib); - switch(color_type) { - case FIC_MINISWHITE: // min value is white - return PHOTOMETRIC_MINISWHITE; - case FIC_MINISBLACK: // min value is black - return PHOTOMETRIC_MINISBLACK; - case FIC_PALETTE: // color map indexed - return PHOTOMETRIC_PALETTE; - case FIC_RGB: // RGB color model - case FIC_RGBALPHA: // RGB color model with alpha channel - return PHOTOMETRIC_RGB; - case FIC_CMYK: // CMYK color model - return PHOTOMETRIC_RGB; // default to RGB unless the save flag is set to TIFF_CMYK - default: - return PHOTOMETRIC_MINISBLACK; - } -} - -/** -Get the resolution from the TIFF and fill the dib with universal units -*/ -static void -ReadResolution(TIFF *tiff, FIBITMAP *dib) { - float fResX = 300.0; - float fResY = 300.0; - uint16 resUnit = RESUNIT_INCH; - - TIFFGetField(tiff, TIFFTAG_RESOLUTIONUNIT, &resUnit); - TIFFGetField(tiff, TIFFTAG_XRESOLUTION, &fResX); - TIFFGetField(tiff, TIFFTAG_YRESOLUTION, &fResY); - - // If we don't have a valid resolution unit and valid resolution is specified then assume inch - if (resUnit == RESUNIT_NONE && fResX > 0.0 && fResY > 0.0) { - resUnit = RESUNIT_INCH; - } - if (resUnit == RESUNIT_INCH) { - FreeImage_SetDotsPerMeterX(dib, (unsigned) (fResX/0.0254000 + 0.5)); - FreeImage_SetDotsPerMeterY(dib, (unsigned) (fResY/0.0254000 + 0.5)); - } else if(resUnit == RESUNIT_CENTIMETER) { - FreeImage_SetDotsPerMeterX(dib, (unsigned) (fResX*100.0 + 0.5)); - FreeImage_SetDotsPerMeterY(dib, (unsigned) (fResY*100.0 + 0.5)); - } -} - -/** -Set the resolution to the TIFF using english units -*/ -static void -WriteResolution(TIFF *tiff, FIBITMAP *dib) { - double res; - - TIFFSetField(tiff, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); - - res = (unsigned long) (0.5 + 0.0254 * FreeImage_GetDotsPerMeterX(dib)); - TIFFSetField(tiff, TIFFTAG_XRESOLUTION, res); - - res = (unsigned long) (0.5 + 0.0254 * FreeImage_GetDotsPerMeterY(dib)); - TIFFSetField(tiff, TIFFTAG_YRESOLUTION, res); -} - -/** -Fill the dib palette according to the TIFF photometric -*/ -static void -ReadPalette(TIFF *tiff, uint16 photometric, uint16 bitspersample, FIBITMAP *dib) { - RGBQUAD *pal = FreeImage_GetPalette(dib); - - switch(photometric) { - case PHOTOMETRIC_MINISBLACK: // bitmap and greyscale image types - case PHOTOMETRIC_MINISWHITE: - // Monochrome image - - if (bitspersample == 1) { - if (photometric == PHOTOMETRIC_MINISWHITE) { - pal[0].rgbRed = pal[0].rgbGreen = pal[0].rgbBlue = 255; - pal[1].rgbRed = pal[1].rgbGreen = pal[1].rgbBlue = 0; - } else { - pal[0].rgbRed = pal[0].rgbGreen = pal[0].rgbBlue = 0; - pal[1].rgbRed = pal[1].rgbGreen = pal[1].rgbBlue = 255; - } - - } else if ((bitspersample == 4) ||(bitspersample == 8)) { - // need to build the scale for greyscale images - int ncolors = FreeImage_GetColorsUsed(dib); - - if (photometric == PHOTOMETRIC_MINISBLACK) { - for (int i = 0; i < ncolors; i++) { - pal[i].rgbRed = - pal[i].rgbGreen = - pal[i].rgbBlue = (BYTE)(i*(255/(ncolors-1))); - } - } else { - for (int i = 0; i < ncolors; i++) { - pal[i].rgbRed = - pal[i].rgbGreen = - pal[i].rgbBlue = (BYTE)(255-i*(255/(ncolors-1))); - } - } - } - - break; - - case PHOTOMETRIC_PALETTE: // color map indexed - uint16 *red; - uint16 *green; - uint16 *blue; - - TIFFGetField(tiff, TIFFTAG_COLORMAP, &red, &green, &blue); - - // load the palette in the DIB - - if (CheckColormap(1<= 0; i--) { - pal[i].rgbRed =(BYTE) CVT(red[i]); - pal[i].rgbGreen = (BYTE) CVT(green[i]); - pal[i].rgbBlue = (BYTE) CVT(blue[i]); - } - } else { - for (int i = (1 << bitspersample) - 1; i >= 0; i--) { - pal[i].rgbRed = (BYTE) red[i]; - pal[i].rgbGreen = (BYTE) green[i]; - pal[i].rgbBlue = (BYTE) blue[i]; - } - } - - break; - } -} - -/** -Allocate a FIBITMAP -@param header_only If TRUE, allocate a 'header only' FIBITMAP, otherwise allocate a full FIBITMAP -@param fit Image type -@param width Image width in pixels -@param height Image height in pixels -@param bitspersample # bits per sample -@param samplesperpixel # samples per pixel -@return Returns the allocated image if successful, returns NULL otherwise -*/ -static FIBITMAP* -CreateImageType(BOOL header_only, FREE_IMAGE_TYPE fit, int width, int height, uint16 bitspersample, uint16 samplesperpixel) { - FIBITMAP *dib = NULL; - - if((width < 0) || (height < 0)) { - // check for malicious images - return NULL; - } - - int bpp = bitspersample * samplesperpixel; - - if(fit == FIT_BITMAP) { - // standard bitmap type - - if(bpp == 16) { - - if((samplesperpixel == 2) && (bitspersample == 8)) { - // 8-bit indexed + 8-bit alpha channel -> convert to 8-bit transparent - dib = FreeImage_AllocateHeader(header_only, width, height, 8); - } else { - // 16-bit RGB -> expect it to be 565 - dib = FreeImage_AllocateHeader(header_only, width, height, bpp, FI16_565_RED_MASK, FI16_565_GREEN_MASK, FI16_565_BLUE_MASK); - } - - } - else { - - dib = FreeImage_AllocateHeader(header_only, width, height, MIN(bpp, 32), FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - } - - - } else { - // other bitmap types - - dib = FreeImage_AllocateHeaderT(header_only, fit, width, height, bpp); - } - - return dib; -} - -/** -Read the TIFFTAG_SAMPLEFORMAT tag and convert to FREE_IMAGE_TYPE -@param tiff LibTIFF TIFF Handle -@param bitspersample # bit per sample -@param samplesperpixel # samples per pixel -@return Returns the image type as a FREE_IMAGE_TYPE value -*/ -static FREE_IMAGE_TYPE -ReadImageType(TIFF *tiff, uint16 bitspersample, uint16 samplesperpixel) { - uint16 sampleformat = 0; - FREE_IMAGE_TYPE fit = FIT_BITMAP ; - - uint16 bpp = bitspersample * samplesperpixel; - - // try the sampleformat tag - if(TIFFGetField(tiff, TIFFTAG_SAMPLEFORMAT, &sampleformat)) { - - switch (sampleformat) { - case SAMPLEFORMAT_UINT: - switch (bpp) { - case 1: - case 4: - case 8: - case 24: - fit = FIT_BITMAP; - break; - case 16: - // 8-bit + alpha or 16-bit greyscale - if(samplesperpixel == 2) { - fit = FIT_BITMAP; - } else { - fit = FIT_UINT16; - } - break; - case 32: - if(samplesperpixel == 4) { - fit = FIT_BITMAP; - } else { - fit = FIT_UINT32; - } - break; - case 48: - if(samplesperpixel == 3) { - fit = FIT_RGB16; - } - break; - case 64: - if(samplesperpixel == 4) { - fit = FIT_RGBA16; - } - break; - } - break; - - case SAMPLEFORMAT_INT: - switch (bpp) { - case 16: - if(samplesperpixel == 3) { - fit = FIT_BITMAP; - } else { - fit = FIT_INT16; - } - break; - case 32: - fit = FIT_INT32; - break; - } - break; - - case SAMPLEFORMAT_IEEEFP: - switch (bpp) { - case 32: - fit = FIT_FLOAT; - break; - case 48: - // 3 x half float => convert to RGBF - if((samplesperpixel == 3) && (bitspersample == 16)) { - fit = FIT_RGBF; - } - break; - case 64: - if(samplesperpixel == 2) { - fit = FIT_FLOAT; - } else { - fit = FIT_DOUBLE; - } - break; - case 96: - fit = FIT_RGBF; - break; - default: - if(bpp >= 128) { - fit = FIT_RGBAF; - } - break; - } - break; - case SAMPLEFORMAT_COMPLEXIEEEFP: - switch (bpp) { - case 64: - break; - case 128: - fit = FIT_COMPLEX; - break; - } - break; - - } - } - // no sampleformat tag : assume SAMPLEFORMAT_UINT - else { - if(samplesperpixel == 1) { - switch (bpp) { - case 16: - fit = FIT_UINT16; - break; - - case 32: - fit = FIT_UINT32; - break; - } - } - else if(samplesperpixel == 3) { - if(bpp == 48) fit = FIT_RGB16; - } - else if(samplesperpixel >= 4) { - if(bitspersample == 16) { - fit = FIT_RGBA16; - } - } - - } - - return fit; -} - -/** -Convert FREE_IMAGE_TYPE and write TIFFTAG_SAMPLEFORMAT -@param tiff LibTIFF TIFF Handle -@param fit Image type as a FREE_IMAGE_TYPE value -*/ -static void -WriteImageType(TIFF *tiff, FREE_IMAGE_TYPE fit) { - switch(fit) { - case FIT_BITMAP: // standard image: 1-, 4-, 8-, 16-, 24-, 32-bit - case FIT_UINT16: // array of unsigned short : unsigned 16-bit - case FIT_UINT32: // array of unsigned long : unsigned 32-bit - case FIT_RGB16: // 48-bit RGB image : 3 x 16-bit - case FIT_RGBA16: // 64-bit RGBA image : 4 x 16-bit - TIFFSetField(tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT); - break; - - case FIT_INT16: // array of short : signed 16-bit - case FIT_INT32: // array of long : signed 32-bit - TIFFSetField(tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_INT); - break; - - case FIT_FLOAT: // array of float : 32-bit - case FIT_DOUBLE: // array of double : 64-bit - case FIT_RGBF: // 96-bit RGB float image : 3 x 32-bit IEEE floating point - case FIT_RGBAF: // 128-bit RGBA float image : 4 x 32-bit IEEE floating point - TIFFSetField(tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP); - break; - - case FIT_COMPLEX: // array of COMPLEX : 2 x 64-bit - TIFFSetField(tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_COMPLEXIEEEFP); - break; - } -} - -/** -Select the compression algorithm -@param tiff LibTIFF TIFF Handle -@param -*/ -static void -WriteCompression(TIFF *tiff, uint16 bitspersample, uint16 samplesperpixel, uint16 photometric, int flags) { - uint16 compression; - uint16 bitsperpixel = bitspersample * samplesperpixel; - - if(photometric == PHOTOMETRIC_LOGLUV) { - compression = COMPRESSION_SGILOG; - } else if ((flags & TIFF_PACKBITS) == TIFF_PACKBITS) { - compression = COMPRESSION_PACKBITS; - } else if ((flags & TIFF_DEFLATE) == TIFF_DEFLATE) { - compression = COMPRESSION_DEFLATE; - } else if ((flags & TIFF_ADOBE_DEFLATE) == TIFF_ADOBE_DEFLATE) { - compression = COMPRESSION_ADOBE_DEFLATE; - } else if ((flags & TIFF_NONE) == TIFF_NONE) { - compression = COMPRESSION_NONE; - } else if ((bitsperpixel == 1) && ((flags & TIFF_CCITTFAX3) == TIFF_CCITTFAX3)) { - compression = COMPRESSION_CCITTFAX3; - } else if ((bitsperpixel == 1) && ((flags & TIFF_CCITTFAX4) == TIFF_CCITTFAX4)) { - compression = COMPRESSION_CCITTFAX4; - } else if ((flags & TIFF_LZW) == TIFF_LZW) { - compression = COMPRESSION_LZW; - } else if ((flags & TIFF_JPEG) == TIFF_JPEG) { - if(((bitsperpixel == 8) && (photometric != PHOTOMETRIC_PALETTE)) || (bitsperpixel == 24)) { - compression = COMPRESSION_JPEG; - // RowsPerStrip must be multiple of 8 for JPEG - uint32 rowsperstrip = (uint32) -1; - rowsperstrip = TIFFDefaultStripSize(tiff, rowsperstrip); - rowsperstrip = rowsperstrip + (8 - (rowsperstrip % 8)); - // overwrite previous RowsPerStrip - TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, rowsperstrip); - } else { - // default to LZW - compression = COMPRESSION_LZW; - } - } - else { - // default compression scheme - - switch(bitsperpixel) { - case 1: - compression = COMPRESSION_CCITTFAX4; - break; - - case 4: - case 8: - case 16: - case 24: - case 32: - compression = COMPRESSION_LZW; - break; - case 48: - case 64: - case 96: - case 128: - compression = COMPRESSION_LZW; - break; - - default : - compression = COMPRESSION_NONE; - break; - } - } - - TIFFSetField(tiff, TIFFTAG_COMPRESSION, compression); - - if(compression == COMPRESSION_LZW) { - // This option is only meaningful with LZW compression: a predictor value of 2 - // causes each scanline of the output image to undergo horizontal differencing - // before it is encoded; a value of 1 forces each scanline to be encoded without differencing. - - // Found on LibTIFF mailing list : - // LZW without differencing works well for 1-bit images, 4-bit grayscale images, - // and many palette-color images. But natural 24-bit color images and some 8-bit - // grayscale images do much better with differencing. - - if((bitspersample == 8) || (bitspersample == 16)) { - if ((bitsperpixel >= 8) && (photometric != PHOTOMETRIC_PALETTE)) { - TIFFSetField(tiff, TIFFTAG_PREDICTOR, 2); - } else { - TIFFSetField(tiff, TIFFTAG_PREDICTOR, 1); - } - } else { - TIFFSetField(tiff, TIFFTAG_PREDICTOR, 1); - } - } - else if(compression == COMPRESSION_CCITTFAX3) { - // try to be compliant with the TIFF Class F specification - // that documents the TIFF tags specific to FAX applications - // see http://palimpsest.stanford.edu/bytopic/imaging/std/tiff-f.html - uint32 group3options = GROUP3OPT_2DENCODING | GROUP3OPT_FILLBITS; - TIFFSetField(tiff, TIFFTAG_GROUP3OPTIONS, group3options); // 2d-encoded, has aligned EOL - TIFFSetField(tiff, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB); // lsb-to-msb fillorder - } -} - -// ========================================================== -// TIFF metadata routines -// ========================================================== - -/** - Read the TIFFTAG_RICHTIFFIPTC tag (IPTC/NAA or Adobe Photoshop profile) -*/ -static BOOL -tiff_read_iptc_profile(TIFF *tiff, FIBITMAP *dib) { - BYTE *profile = NULL; - uint32 profile_size = 0; - - if(TIFFGetField(tiff,TIFFTAG_RICHTIFFIPTC, &profile_size, &profile) == 1) { - if (TIFFIsByteSwapped(tiff) != 0) { - TIFFSwabArrayOfLong((uint32 *) profile, (unsigned long)profile_size); - } - - return read_iptc_profile(dib, profile, 4 * profile_size); - } - - return FALSE; -} - -/** - Read the TIFFTAG_XMLPACKET tag (XMP profile) - @param dib Input FIBITMAP - @param tiff LibTIFF TIFF handle - @return Returns TRUE if successful, FALSE otherwise -*/ -static BOOL -tiff_read_xmp_profile(TIFF *tiff, FIBITMAP *dib) { - BYTE *profile = NULL; - uint32 profile_size = 0; - - if (TIFFGetField(tiff, TIFFTAG_XMLPACKET, &profile_size, &profile) == 1) { - // create a tag - FITAG *tag = FreeImage_CreateTag(); - if(!tag) return FALSE; - - FreeImage_SetTagID(tag, TIFFTAG_XMLPACKET); // 700 - FreeImage_SetTagKey(tag, g_TagLib_XMPFieldName); - FreeImage_SetTagLength(tag, profile_size); - FreeImage_SetTagCount(tag, profile_size); - FreeImage_SetTagType(tag, FIDT_ASCII); - FreeImage_SetTagValue(tag, profile); - - // store the tag - FreeImage_SetMetadata(FIMD_XMP, dib, FreeImage_GetTagKey(tag), tag); - - // destroy the tag - FreeImage_DeleteTag(tag); - - return TRUE; - } - - return FALSE; -} - -/** - Read the Exif profile embedded in a TIFF - @param dib Input FIBITMAP - @param tiff LibTIFF TIFF handle - @return Returns TRUE if successful, FALSE otherwise -*/ -static BOOL -tiff_read_exif_profile(TIFF *tiff, FIBITMAP *dib) { - BOOL bResult = FALSE; - uint32 exif_offset = 0; - - // read EXIF-TIFF tags - bResult = tiff_read_exif_tags(tiff, TagLib::EXIF_MAIN, dib); - - // get the IFD offset - if(TIFFGetField(tiff, TIFFTAG_EXIFIFD, &exif_offset)) { - - // read EXIF tags - if(!TIFFReadEXIFDirectory(tiff, exif_offset)) { - return FALSE; - } - - // read all known exif tags - bResult = tiff_read_exif_tags(tiff, TagLib::EXIF_EXIF, dib); - } - - return bResult; -} - -/** -Read TIFF special profiles -*/ -static void -ReadMetadata(TIFF *tiff, FIBITMAP *dib) { - - // IPTC/NAA - tiff_read_iptc_profile(tiff, dib); - - // Adobe XMP - tiff_read_xmp_profile(tiff, dib); - - // GeoTIFF - tiff_read_geotiff_profile(tiff, dib); - - // Exif-TIFF - tiff_read_exif_profile(tiff, dib); -} - -// ---------------------------------------------------------- - -/** - Write the TIFFTAG_RICHTIFFIPTC tag (IPTC/NAA or Adobe Photoshop profile) -*/ -static BOOL -tiff_write_iptc_profile(TIFF *tiff, FIBITMAP *dib) { - if(FreeImage_GetMetadataCount(FIMD_IPTC, dib)) { - BYTE *profile = NULL; - uint32 profile_size = 0; - // create a binary profile - if(write_iptc_profile(dib, &profile, &profile_size)) { - uint32 iptc_size = profile_size; - iptc_size += (4-(iptc_size & 0x03)); // Round up for long word alignment - BYTE *iptc_profile = (BYTE*)malloc(iptc_size); - if(!iptc_profile) { - free(profile); - return FALSE; - } - memset(iptc_profile, 0, iptc_size); - memcpy(iptc_profile, profile, profile_size); - if (TIFFIsByteSwapped(tiff)) { - TIFFSwabArrayOfLong((uint32 *) iptc_profile, (unsigned long)iptc_size/4); - } - // Tag is type TIFF_LONG so byte length is divided by four - TIFFSetField(tiff, TIFFTAG_RICHTIFFIPTC, iptc_size/4, iptc_profile); - // release the profile data - free(iptc_profile); - free(profile); - - return TRUE; - } - } - - return FALSE; -} - -/** - Write the TIFFTAG_XMLPACKET tag (XMP profile) - @param dib Input FIBITMAP - @param tiff LibTIFF TIFF handle - @return Returns TRUE if successful, FALSE otherwise -*/ -static BOOL -tiff_write_xmp_profile(TIFF *tiff, FIBITMAP *dib) { - FITAG *tag_xmp = NULL; - FreeImage_GetMetadata(FIMD_XMP, dib, g_TagLib_XMPFieldName, &tag_xmp); - - if(tag_xmp && (NULL != FreeImage_GetTagValue(tag_xmp))) { - - TIFFSetField(tiff, TIFFTAG_XMLPACKET, (uint32)FreeImage_GetTagLength(tag_xmp), (BYTE*)FreeImage_GetTagValue(tag_xmp)); - - return TRUE; - } - - return FALSE; -} - -/** - Write the Exif profile to TIFF - @param dib Input FIBITMAP - @param tiff LibTIFF TIFF handle - @return Returns TRUE if successful, FALSE otherwise -*/ -static BOOL -tiff_write_exif_profile(TIFF *tiff, FIBITMAP *dib) { - BOOL bResult = FALSE; - uint32 exif_offset = 0; - - // write EXIF_MAIN tags, EXIF_EXIF not supported yet - bResult = tiff_write_exif_tags(tiff, TagLib::EXIF_MAIN, dib); - - return bResult; -} - -/** -Write TIFF special profiles -*/ -static void -WriteMetadata(TIFF *tiff, FIBITMAP *dib) { - // IPTC - tiff_write_iptc_profile(tiff, dib); - - // Adobe XMP - tiff_write_xmp_profile(tiff, dib); - - // EXIF_MAIN tags - tiff_write_exif_profile(tiff, dib); - - // GeoTIFF tags - tiff_write_geotiff_profile(tiff, dib); -} - -// ========================================================== -// Plugin Implementation -// ========================================================== - -static const char * DLL_CALLCONV -Format() { - return "TIFF"; -} - -static const char * DLL_CALLCONV -Description() { - return "Tagged Image File Format"; -} - -static const char * DLL_CALLCONV -Extension() { - return "tif,tiff"; -} - -static const char * DLL_CALLCONV -RegExpr() { - return "^[MI][MI][\\x01*][\\x01*]"; -} - -static const char * DLL_CALLCONV -MimeType() { - return "image/tiff"; -} - -static BOOL DLL_CALLCONV -Validate(FreeImageIO *io, fi_handle handle) { - BYTE tiff_id1[] = { 0x49, 0x49, 0x2A, 0x00 }; - BYTE tiff_id2[] = { 0x4D, 0x4D, 0x00, 0x2A }; - BYTE signature[4] = { 0, 0, 0, 0 }; - - io->read_proc(signature, 1, 4, handle); - - if(memcmp(tiff_id1, signature, 4) == 0) - return TRUE; - - if(memcmp(tiff_id2, signature, 4) == 0) - return TRUE; - - return FALSE; -} - -static BOOL DLL_CALLCONV -SupportsExportDepth(int depth) { - return ( - (depth == 1) || - (depth == 4) || - (depth == 8) || - (depth == 24) || - (depth == 32) - ); -} - -static BOOL DLL_CALLCONV -SupportsExportType(FREE_IMAGE_TYPE type) { - return ( - (type == FIT_BITMAP) || - (type == FIT_UINT16) || - (type == FIT_INT16) || - (type == FIT_UINT32) || - (type == FIT_INT32) || - (type == FIT_FLOAT) || - (type == FIT_DOUBLE) || - (type == FIT_COMPLEX) || - (type == FIT_RGB16) || - (type == FIT_RGBA16) || - (type == FIT_RGBF) || - (type == FIT_RGBAF) - ); -} - -static BOOL DLL_CALLCONV -SupportsICCProfiles() { - return TRUE; -} - -static BOOL DLL_CALLCONV -SupportsNoPixels() { - return TRUE; -} - -// ---------------------------------------------------------- - -static void * DLL_CALLCONV -Open(FreeImageIO *io, fi_handle handle, BOOL read) { - // wrapper for TIFF I/O - fi_TIFFIO *fio = (fi_TIFFIO*)malloc(sizeof(fi_TIFFIO)); - if(!fio) return NULL; - fio->io = io; - fio->handle = handle; - - if (read) { - fio->tif = TIFFFdOpen((thandle_t)fio, "", "r"); - } else { - fio->tif = TIFFFdOpen((thandle_t)fio, "", "w"); - } - if(fio->tif == NULL) { - free(fio); - FreeImage_OutputMessageProc(s_format_id, "Error while opening TIFF: data is invalid"); - return NULL; - } - return fio; -} - -static void DLL_CALLCONV -Close(FreeImageIO *io, fi_handle handle, void *data) { - if(data) { - fi_TIFFIO *fio = (fi_TIFFIO*)data; - TIFFClose(fio->tif); - free(fio); - } -} - -// ---------------------------------------------------------- - -static int DLL_CALLCONV -PageCount(FreeImageIO *io, fi_handle handle, void *data) { - if(data) { - fi_TIFFIO *fio = (fi_TIFFIO*)data; - TIFF *tif = (TIFF *)fio->tif; - int nr_ifd = 0; - - do { - nr_ifd++; - } while (TIFFReadDirectory(tif)); - - return nr_ifd; - } - - return 0; -} - -// ---------------------------------------------------------- - -/** -check for uncommon bitspersample values (e.g. 10, 12, ...) -@param photometric TIFFTAG_PHOTOMETRIC tiff tag -@param bitspersample TIFFTAG_BITSPERSAMPLE tiff tag -@param samplesperpixel TIFFTAG_SAMPLESPERPIXEL tiff tag -@return Returns FALSE if a uncommon bit-depth is encountered, returns TRUE otherwise -*/ -static BOOL -IsValidBitsPerSample(uint16 photometric, uint16 bitspersample, uint16 samplesperpixel) { - - switch(bitspersample) { - case 1: - case 4: - if((photometric == PHOTOMETRIC_MINISWHITE) || (photometric == PHOTOMETRIC_MINISBLACK) || (photometric == PHOTOMETRIC_PALETTE)) { - return TRUE; - } else { - return FALSE; - } - break; - case 8: - return TRUE; - case 16: - if(photometric != PHOTOMETRIC_PALETTE) { - return TRUE; - } else { - return FALSE; - } - break; - case 32: - return TRUE; - case 64: - case 128: - if(photometric == PHOTOMETRIC_MINISBLACK) { - return TRUE; - } else { - return FALSE; - } - break; - default: - return FALSE; - } -} - -static TIFFLoadMethod -FindLoadMethod(TIFF *tif, FREE_IMAGE_TYPE image_type, int flags) { - uint16 bitspersample = (uint16)-1; - uint16 samplesperpixel = (uint16)-1; - uint16 photometric = (uint16)-1; - uint16 planar_config = (uint16)-1; - - TIFFLoadMethod loadMethod = LoadAsGenericStrip; - - TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric); - TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); - TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample); - TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planar_config); - - BOOL bIsTiled = (TIFFIsTiled(tif) == 0) ? FALSE:TRUE; - - switch(photometric) { - // convert to 24 or 32 bits RGB if the image is full color - case PHOTOMETRIC_RGB: - if((image_type == FIT_RGB16) || (image_type == FIT_RGBA16)) { - // load 48-bit RGB and 64-bit RGBA without conversion - loadMethod = LoadAsGenericStrip; - } - else if(image_type == FIT_RGBF) { - if((samplesperpixel == 3) && (bitspersample == 16)) { - // load 3 x 16-bit half as RGBF - loadMethod = LoadAsHalfFloat; - } - } - break; - case PHOTOMETRIC_YCBCR: - case PHOTOMETRIC_CIELAB: - case PHOTOMETRIC_ICCLAB: - case PHOTOMETRIC_ITULAB: - loadMethod = LoadAsRBGA; - break; - case PHOTOMETRIC_LOGLUV: - loadMethod = LoadAsLogLuv; - break; - case PHOTOMETRIC_SEPARATED: - // if image is PHOTOMETRIC_SEPARATED _and_ comes with an ICC profile, - // then the image should preserve its original (CMYK) colour model and - // should be read as CMYK (to keep the match of pixel and profile and - // to avoid multiple conversions. Conversion can be done by changing - // the profile from it's original CMYK to an RGB profile with an - // apropriate color management system. Works with non-tiled TIFFs. - if(!bIsTiled) { - loadMethod = LoadAsCMYK; - } - break; - case PHOTOMETRIC_MINISWHITE: - case PHOTOMETRIC_MINISBLACK: - case PHOTOMETRIC_PALETTE: - // When samplesperpixel = 2 and bitspersample = 8, set the image as a - // 8-bit indexed image + 8-bit alpha layer image - // and convert to a 8-bit image with a transparency table - if((samplesperpixel > 1) && (bitspersample == 8)) { - loadMethod = LoadAs8BitTrns; - } else { - loadMethod = LoadAsGenericStrip; - } - break; - default: - loadMethod = LoadAsGenericStrip; - break; - } - - if((loadMethod == LoadAsGenericStrip) && bIsTiled) { - loadMethod = LoadAsTiled; - } - - return loadMethod; -} - -// ========================================================== -// TIFF thumbnail routines -// ========================================================== - -static FIBITMAP * DLL_CALLCONV -Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data); - -/** -Read embedded thumbnail -*/ -static void -ReadThumbnail(FreeImageIO *io, fi_handle handle, void *data, TIFF *tiff, FIBITMAP *dib) { - FIBITMAP* thumbnail = NULL; - - // read exif thumbnail (IFD 1) ... - - uint32 exif_offset = 0; - if(TIFFGetField(tiff, TIFFTAG_EXIFIFD, &exif_offset)) { - - if(TIFFLastDirectory(tiff) != 0) { - // save current position - long tell_pos = io->tell_proc(handle); - tdir_t cur_dir = TIFFCurrentDirectory(tiff); - - // load the thumbnail - int page = 1; - int flags = TIFF_DEFAULT; - thumbnail = Load(io, handle, page, flags, data); - // store the thumbnail (remember to release it later ...) - FreeImage_SetThumbnail(dib, thumbnail); - - // restore current position - io->seek_proc(handle, tell_pos, SEEK_SET); - TIFFSetDirectory(tiff, cur_dir); - } - } - - // ... or read the first subIFD - - if(!thumbnail) { - uint16 subIFD_count = 0; - uint32* subIFD_offsets = NULL; - // ### Theoretically this should also read the first subIFD from a Photoshop-created file with "pyramid". - // It does not however - the tag is there (using Tag Viewer app) but libtiff refuses to read it - if(TIFFGetField(tiff, TIFFTAG_SUBIFD, &subIFD_count, &subIFD_offsets)) { - if(subIFD_count > 0) { - // save current position - long tell_pos = io->tell_proc(handle); - tdir_t cur_dir = TIFFCurrentDirectory(tiff); - if(TIFFSetSubDirectory(tiff, subIFD_offsets[0])) { - // load the thumbnail - int page = -1; - int flags = TIFF_DEFAULT; - thumbnail = Load(io, handle, page, flags, data); - // store the thumbnail (remember to release it later ...) - FreeImage_SetThumbnail(dib, thumbnail); - } - // restore current position - io->seek_proc(handle, tell_pos, SEEK_SET); - TIFFSetDirectory(tiff, cur_dir); - } - } - } - - // ... or read Photoshop thumbnail - - if(!thumbnail) { - uint32 ps_size = 0; - void *ps_data = NULL; - - if(TIFFGetField(tiff, TIFFTAG_PHOTOSHOP, &ps_size, &ps_data)) { - FIMEMORY *handle = FreeImage_OpenMemory((BYTE*)ps_data, ps_size); - - FreeImageIO io; - SetMemoryIO(&io); - - psdParser parser; - parser.ReadImageResources(&io, handle, ps_size); - - FreeImage_SetThumbnail(dib, parser.GetThumbnail()); - - FreeImage_CloseMemory(handle); - } - - } - - // release thumbnail - FreeImage_Unload(thumbnail); -} - -// -------------------------------------------------------------------------- - -static FIBITMAP * DLL_CALLCONV -Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { - if (!handle || !data ) { - return NULL; - } - - TIFF *tif = NULL; - uint32 height = 0; - uint32 width = 0; - uint16 bitspersample = 1; - uint16 samplesperpixel = 1; - uint32 rowsperstrip = (uint32)-1; - uint16 photometric = PHOTOMETRIC_MINISWHITE; - uint16 compression = (uint16)-1; - uint16 planar_config; - - FIBITMAP *dib = NULL; - uint32 iccSize = 0; // ICC profile length - void *iccBuf = NULL; // ICC profile data - - const BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS; - - try { - fi_TIFFIO *fio = (fi_TIFFIO*)data; - tif = fio->tif; - - if (page != -1) { - if (!tif || !TIFFSetDirectory(tif, (tdir_t)page)) { - throw "Error encountered while opening TIFF file"; - } - } - - const BOOL asCMYK = (flags & TIFF_CMYK) == TIFF_CMYK; - - // first, get the photometric, the compression and basic metadata - // --------------------------------------------------------------------------------- - - TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric); - TIFFGetField(tif, TIFFTAG_COMPRESSION, &compression); - - // check for HDR formats - // --------------------------------------------------------------------------------- - - if(photometric == PHOTOMETRIC_LOGLUV) { - // check the compression - if(compression != COMPRESSION_SGILOG && compression != COMPRESSION_SGILOG24) { - throw "Only support SGILOG compressed LogLuv data"; - } - // set decoder to output in IEEE 32-bit float XYZ values - TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_FLOAT); - } - - // --------------------------------------------------------------------------------- - - TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width); - TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height); - TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); - TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample); - TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); - TIFFGetField(tif, TIFFTAG_ICCPROFILE, &iccSize, &iccBuf); - TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planar_config); - - // check for unsupported formats - // --------------------------------------------------------------------------------- - - if(IsValidBitsPerSample(photometric, bitspersample, samplesperpixel) == FALSE) { - FreeImage_OutputMessageProc(s_format_id, - "Unable to handle this format: bitspersample = %d, samplesperpixel = %d, photometric = %d", - (int)bitspersample, (int)samplesperpixel, (int)photometric); - throw (char*)NULL; - } - - // --------------------------------------------------------------------------------- - - // get image data type - - FREE_IMAGE_TYPE image_type = ReadImageType(tif, bitspersample, samplesperpixel); - - // get the most appropriate loading method - - TIFFLoadMethod loadMethod = FindLoadMethod(tif, image_type, flags); - - // --------------------------------------------------------------------------------- - - if(loadMethod == LoadAsRBGA) { - // --------------------------------------------------------------------------------- - // RGB[A] loading using the TIFFReadRGBAImage() API - // --------------------------------------------------------------------------------- - - BOOL has_alpha = FALSE; - - // Read the whole image into one big RGBA buffer and then - // convert it to a DIB. This is using the traditional - // TIFFReadRGBAImage() API that we trust. - - uint32 *raster = NULL; - - if(!header_only) { - - raster = (uint32*)_TIFFmalloc(width * height * sizeof(uint32)); - if (raster == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - // read the image in one chunk into an RGBA array - - if (!TIFFReadRGBAImage(tif, width, height, raster, 1)) { - _TIFFfree(raster); - throw FI_MSG_ERROR_UNSUPPORTED_FORMAT; - } - } - // TIFFReadRGBAImage always deliveres 3 or 4 samples per pixel images - // (RGB or RGBA, see below). Cut-off possibly present channels (additional - // alpha channels) from e.g. Photoshop. Any CMYK(A..) is now treated as RGB, - // any additional alpha channel on RGB(AA..) is lost on conversion to RGB(A) - - if(samplesperpixel > 4) { // TODO Write to Extra Channels - FreeImage_OutputMessageProc(s_format_id, "Warning: %d additional alpha channel(s) ignored", samplesperpixel-4); - samplesperpixel = 4; - } - - // create a new DIB (take care of different samples-per-pixel in case - // of converted CMYK image (RGB conversion is on sample per pixel less) - - if (photometric == PHOTOMETRIC_SEPARATED && samplesperpixel == 4) { - samplesperpixel = 3; - } - - dib = CreateImageType(header_only, image_type, width, height, bitspersample, samplesperpixel); - if (dib == NULL) { - // free the raster pointer and output an error if allocation failed - if(raster) { - _TIFFfree(raster); - } - throw FI_MSG_ERROR_DIB_MEMORY; - } - - // fill in the resolution (english or universal) - - ReadResolution(tif, dib); - - if(!header_only) { - - // read the raster lines and save them in the DIB - // with RGB mode, we have to change the order of the 3 samples RGB - // We use macros for extracting components from the packed ABGR - // form returned by TIFFReadRGBAImage. - - uint32 *row = &raster[0]; - - if (samplesperpixel == 4) { - // 32-bit RGBA - for (uint32 y = 0; y < height; y++) { - BYTE *bits = FreeImage_GetScanLine(dib, y); - for (uint32 x = 0; x < width; x++) { - bits[FI_RGBA_BLUE] = (BYTE)TIFFGetB(row[x]); - bits[FI_RGBA_GREEN] = (BYTE)TIFFGetG(row[x]); - bits[FI_RGBA_RED] = (BYTE)TIFFGetR(row[x]); - bits[FI_RGBA_ALPHA] = (BYTE)TIFFGetA(row[x]); - - if (bits[FI_RGBA_ALPHA] != 0) { - has_alpha = TRUE; - } - - bits += 4; - } - row += width; - } - } else { - // 24-bit RGB - for (uint32 y = 0; y < height; y++) { - BYTE *bits = FreeImage_GetScanLine(dib, y); - for (uint32 x = 0; x < width; x++) { - bits[FI_RGBA_BLUE] = (BYTE)TIFFGetB(row[x]); - bits[FI_RGBA_GREEN] = (BYTE)TIFFGetG(row[x]); - bits[FI_RGBA_RED] = (BYTE)TIFFGetR(row[x]); - - bits += 3; - } - row += width; - } - } - - _TIFFfree(raster); - } - - // ### Not correct when header only - FreeImage_SetTransparent(dib, has_alpha); - - } else if(loadMethod == LoadAs8BitTrns) { - // --------------------------------------------------------------------------------- - // 8-bit + 8-bit alpha layer loading - // --------------------------------------------------------------------------------- - - // create a new 8-bit DIB - dib = CreateImageType(header_only, image_type, width, height, bitspersample, MIN(2, samplesperpixel)); - if (dib == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - // fill in the resolution (english or universal) - - ReadResolution(tif, dib); - - // set up the colormap based on photometric - - ReadPalette(tif, photometric, bitspersample, dib); - - // calculate the line + pitch (separate for scr & dest) - - const tsize_t src_line = TIFFScanlineSize(tif); - // here, the pitch is 2x less than the original as we only keep the first layer - int dst_pitch = FreeImage_GetPitch(dib); - - // transparency table for 8-bit + 8-bit alpha images - - BYTE trns[256]; - // clear the transparency table - memset(trns, 0xFF, 256 * sizeof(BYTE)); - - // In the tiff file the lines are saved from up to down - // In a DIB the lines must be saved from down to up - - BYTE *bits = FreeImage_GetScanLine(dib, height - 1); - - // read the tiff lines and save them in the DIB - - if(planar_config == PLANARCONFIG_CONTIG && !header_only) { - - BYTE *buf = (BYTE*)malloc(TIFFStripSize(tif) * sizeof(BYTE)); - if(buf == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - for (uint32 y = 0; y < height; y += rowsperstrip) { - int32 nrow = (y + rowsperstrip > height ? height - y : rowsperstrip); - - if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, 0), buf, nrow * src_line) == -1) { - free(buf); - throw FI_MSG_ERROR_PARSING; - } - for (int l = 0; l < nrow; l++) { - BYTE *p = bits; - BYTE *b = buf + l * src_line; - - for(uint32 x = 0; x < (uint32)(src_line / samplesperpixel); x++) { - // copy the 8-bit layer - *p = b[0]; - // convert the 8-bit alpha layer to a trns table - trns[ b[0] ] = b[1]; - - p++; - b += samplesperpixel; - } - bits -= dst_pitch; - } - } - - free(buf); - } - else if(planar_config == PLANARCONFIG_SEPARATE && !header_only) { - tsize_t stripsize = TIFFStripSize(tif) * sizeof(BYTE); - BYTE *buf = (BYTE*)malloc(2 * stripsize); - if(buf == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - BYTE *grey = buf; - BYTE *alpha = buf + stripsize; - - for (uint32 y = 0; y < height; y += rowsperstrip) { - int32 nrow = (y + rowsperstrip > height ? height - y : rowsperstrip); - - if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, 0), grey, nrow * src_line) == -1) { - free(buf); - throw FI_MSG_ERROR_PARSING; - } - if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, 1), alpha, nrow * src_line) == -1) { - free(buf); - throw FI_MSG_ERROR_PARSING; - } - - for (int l = 0; l < nrow; l++) { - BYTE *p = bits; - BYTE *g = grey + l * src_line; - BYTE *a = alpha + l * src_line; - - for(uint32 x = 0; x < (uint32)(src_line); x++) { - // copy the 8-bit layer - *p = g[0]; - // convert the 8-bit alpha layer to a trns table - trns[ g[0] ] = a[0]; - - p++; - g++; - a++; - } - bits -= dst_pitch; - } - } - - free(buf); - - } - - FreeImage_SetTransparencyTable(dib, &trns[0], 256); - FreeImage_SetTransparent(dib, TRUE); - - } else if(loadMethod == LoadAsCMYK) { - // --------------------------------------------------------------------------------- - // CMYK loading - // --------------------------------------------------------------------------------- - - // At this place, samplesperpixel could be > 4, esp. when a CMYK(A) format - // is recognized. Where all other formats are handled straight-forward, this - // format has to be handled special - - BOOL isCMYKA = (photometric == PHOTOMETRIC_SEPARATED) && (samplesperpixel > 4); - - // We use a temp dib to store the alpha for the CMYKA to RGBA conversion - // NOTE this is until we have Extra channels implementation. - // Also then it will be possible to merge LoadAsCMYK with LoadAsGenericStrip - - FIBITMAP *alpha = NULL; - unsigned alpha_pitch = 0; - BYTE *alpha_bits = NULL; - unsigned alpha_Bpp = 0; - - if(isCMYKA && !asCMYK && !header_only) { - if(bitspersample == 16) { - alpha = FreeImage_AllocateT(FIT_UINT16, width, height); - } else if (bitspersample == 8) { - alpha = FreeImage_Allocate(width, height, 8); - } - - if(!alpha) { - FreeImage_OutputMessageProc(s_format_id, "Failed to allocate temporary alpha channel"); - } else { - alpha_bits = FreeImage_GetScanLine(alpha, height - 1); - alpha_pitch = FreeImage_GetPitch(alpha); - alpha_Bpp = FreeImage_GetBPP(alpha) / 8; - } - - } - - // create a new DIB - const uint16 chCount = MIN(samplesperpixel, 4); - dib = CreateImageType(header_only, image_type, width, height, bitspersample, chCount); - if (dib == NULL) { - FreeImage_Unload(alpha); - throw FI_MSG_ERROR_MEMORY; - } - - // fill in the resolution (english or universal) - - ReadResolution(tif, dib); - - if(!header_only) { - - // calculate the line + pitch (separate for scr & dest) - - const tsize_t src_line = TIFFScanlineSize(tif); - const tsize_t dst_line = FreeImage_GetLine(dib); - const unsigned dib_pitch = FreeImage_GetPitch(dib); - const unsigned dibBpp = FreeImage_GetBPP(dib) / 8; - const unsigned Bpc = dibBpp / chCount; - const unsigned srcBpp = bitspersample * samplesperpixel / 8; - - assert(Bpc <= 2); //< CMYK is only BYTE or SHORT - - // In the tiff file the lines are save from up to down - // In a DIB the lines must be saved from down to up - - BYTE *bits = FreeImage_GetScanLine(dib, height - 1); - - // read the tiff lines and save them in the DIB - - BYTE *buf = (BYTE*)malloc(TIFFStripSize(tif) * sizeof(BYTE)); - if(buf == NULL) { - FreeImage_Unload(alpha); - throw FI_MSG_ERROR_MEMORY; - } - - if(planar_config == PLANARCONFIG_CONTIG) { - - // - loop for strip blocks - - - for (uint32 y = 0; y < height; y += rowsperstrip) { - const int32 strips = (y + rowsperstrip > height ? height - y : rowsperstrip); - - if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, 0), buf, strips * src_line) == -1) { - free(buf); - FreeImage_Unload(alpha); - throw FI_MSG_ERROR_PARSING; - } - - // - loop for strips - - - if(src_line != dst_line) { - // CMYKA+ - if(alpha) { - for (int l = 0; l < strips; l++) { - for(BYTE *pixel = bits, *al_pixel = alpha_bits, *src_pixel = buf + l * src_line; pixel < bits + dib_pitch; pixel += dibBpp, al_pixel += alpha_Bpp, src_pixel += srcBpp) { - // copy pixel byte by byte - BYTE b = 0; - for( ; b < dibBpp; ++b) { - pixel[b] = src_pixel[b]; - } - // TODO write the remaining bytes to extra channel(s) - - // HACK write the first alpha to a separate dib (assume BYTE or WORD) - al_pixel[0] = src_pixel[b]; - if(Bpc > 1) { - al_pixel[1] = src_pixel[b + 1]; - } - - } - bits -= dib_pitch; - alpha_bits -= alpha_pitch; - } - } - else { - // alpha/extra channels alloc failed - for (int l = 0; l < strips; l++) { - for(BYTE* pixel = bits, * src_pixel = buf + l * src_line; pixel < bits + dst_line; pixel += dibBpp, src_pixel += srcBpp) { - AssignPixel(pixel, src_pixel, dibBpp); - } - bits -= dib_pitch; - } - } - } - else { - // CMYK to CMYK - for (int l = 0; l < strips; l++) { - BYTE *b = buf + l * src_line; - memcpy(bits, b, src_line); - bits -= dib_pitch; - } - } - - } // height - - } - else if(planar_config == PLANARCONFIG_SEPARATE) { - - BYTE *dib_strip = bits; - BYTE *al_strip = alpha_bits; - - // - loop for strip blocks - - - for (uint32 y = 0; y < height; y += rowsperstrip) { - const int32 strips = (y + rowsperstrip > height ? height - y : rowsperstrip); - - // - loop for channels (planes) - - - for(uint16 sample = 0; sample < samplesperpixel; sample++) { - - if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, sample), buf, strips * src_line) == -1) { - free(buf); - FreeImage_Unload(alpha); - throw FI_MSG_ERROR_PARSING; - } - - BYTE *dst_strip = dib_strip; - unsigned dst_pitch = dib_pitch; - uint16 ch = sample; - unsigned Bpp = dibBpp; - - if(sample >= chCount) { - // TODO Write to Extra Channel - - // HACK redirect write to temp alpha - if(alpha && sample == chCount) { - - dst_strip = al_strip; - dst_pitch = alpha_pitch; - - ch = 0; - Bpp = alpha_Bpp; - } - else { - break; - } - } - - const unsigned channelOffset = ch * Bpc; - - // - loop for strips in block - - - BYTE *src_line_begin = buf; - BYTE *dst_line_begin = dst_strip; - for (int l = 0; l < strips; l++, src_line_begin += src_line, dst_line_begin -= dst_pitch ) { - // - loop for pixels in strip - - - const BYTE* const src_line_end = src_line_begin + src_line; - for (BYTE *src_bits = src_line_begin, * dst_bits = dst_line_begin; src_bits < src_line_end; src_bits += Bpc, dst_bits += Bpp) { - AssignPixel(dst_bits + channelOffset, src_bits, Bpc); - } // line - - } // strips - - } // channels - - // done with a strip block, incr to the next - dib_strip -= strips * dib_pitch; - al_strip -= strips * alpha_pitch; - - } //< height - - } - - free(buf); - - if(!asCMYK) { - ConvertCMYKtoRGBA(dib); - - // The ICC Profile is invalid, clear it - iccSize = 0; - iccBuf = NULL; - - if(isCMYKA) { - // HACK until we have Extra channels. (ConvertCMYKtoRGBA will then do the work) - - FreeImage_SetChannel(dib, alpha, FICC_ALPHA); - FreeImage_Unload(alpha); - alpha = NULL; - } - else { - FIBITMAP *t = RemoveAlphaChannel(dib); - if(t) { - FreeImage_Unload(dib); - dib = t; - } - else { - FreeImage_OutputMessageProc(s_format_id, "Cannot allocate memory for buffer. CMYK image converted to RGB + pending Alpha"); - } - } - } - - } // !header_only - - } else if(loadMethod == LoadAsGenericStrip) { - // --------------------------------------------------------------------------------- - // Generic loading - // --------------------------------------------------------------------------------- - - // create a new DIB - const uint16 chCount = MIN(samplesperpixel, 4); - dib = CreateImageType(header_only, image_type, width, height, bitspersample, chCount); - if (dib == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - // fill in the resolution (english or universal) - - ReadResolution(tif, dib); - - // set up the colormap based on photometric - - ReadPalette(tif, photometric, bitspersample, dib); - - if(!header_only) { - // calculate the line + pitch (separate for scr & dest) - - const tsize_t src_line = TIFFScanlineSize(tif); - const tsize_t dst_line = FreeImage_GetLine(dib); - const unsigned dst_pitch = FreeImage_GetPitch(dib); - const unsigned Bpp = FreeImage_GetBPP(dib) / 8; - const unsigned srcBpp = bitspersample * samplesperpixel / 8; - - // In the tiff file the lines are save from up to down - // In a DIB the lines must be saved from down to up - - BYTE *bits = FreeImage_GetScanLine(dib, height - 1); - - // read the tiff lines and save them in the DIB - - BYTE *buf = (BYTE*)malloc(TIFFStripSize(tif) * sizeof(BYTE)); - if(buf == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - BOOL bThrowMessage = FALSE; - - if(planar_config == PLANARCONFIG_CONTIG) { - - for (uint32 y = 0; y < height; y += rowsperstrip) { - int32 strips = (y + rowsperstrip > height ? height - y : rowsperstrip); - - if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, 0), buf, strips * src_line) == -1) { - // ignore errors as they can be frequent and not really valid errors, especially with fax images - bThrowMessage = TRUE; - /* - free(buf); - throw FI_MSG_ERROR_PARSING; - */ - } - if(src_line == dst_line) { - // channel count match - for (int l = 0; l < strips; l++) { - memcpy(bits, buf + l * src_line, src_line); - bits -= dst_pitch; - } - } - else { - for (int l = 0; l < strips; l++) { - for(BYTE *pixel = bits, *src_pixel = buf + l * src_line; pixel < bits + dst_pitch; pixel += Bpp, src_pixel += srcBpp) { - AssignPixel(pixel, src_pixel, Bpp); - } - bits -= dst_pitch; - } - } - } - } - else if(planar_config == PLANARCONFIG_SEPARATE) { - - const unsigned Bpc = bitspersample / 8; - BYTE* dib_strip = bits; - // - loop for strip blocks - - - for (uint32 y = 0; y < height; y += rowsperstrip) { - const int32 strips = (y + rowsperstrip > height ? height - y : rowsperstrip); - - // - loop for channels (planes) - - - for(uint16 sample = 0; sample < samplesperpixel; sample++) { - - if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, sample), buf, strips * src_line) == -1) { - // ignore errors as they can be frequent and not really valid errors, especially with fax images - bThrowMessage = TRUE; - } - - if(sample >= chCount) { - // TODO Write to Extra Channel - break; - } - - const unsigned channelOffset = sample * Bpc; - - // - loop for strips in block - - - BYTE* src_line_begin = buf; - BYTE* dst_line_begin = dib_strip; - for (int l = 0; l < strips; l++, src_line_begin += src_line, dst_line_begin -= dst_pitch ) { - - // - loop for pixels in strip - - - const BYTE* const src_line_end = src_line_begin + src_line; - - for (BYTE* src_bits = src_line_begin, * dst_bits = dst_line_begin; src_bits < src_line_end; src_bits += Bpc, dst_bits += Bpp) { - // actually assigns channel - AssignPixel(dst_bits + channelOffset, src_bits, Bpc); - } // line - - } // strips - - } // channels - - // done with a strip block, incr to the next - dib_strip -= strips * dst_pitch; - - } // height - - } - free(buf); - - if(bThrowMessage) { - FreeImage_OutputMessageProc(s_format_id, "Warning: parsing error. Image may be incomplete or contain invalid data !"); - } - -#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR - SwapRedBlue32(dib); -#endif - - } // !header only - - } else if(loadMethod == LoadAsTiled) { - // --------------------------------------------------------------------------------- - // Tiled image loading - // --------------------------------------------------------------------------------- - - uint32 tileWidth, tileHeight; - uint32 src_line = 0; - - // create a new DIB - dib = CreateImageType( header_only, image_type, width, height, bitspersample, samplesperpixel); - if (dib == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - // fill in the resolution (english or universal) - - ReadResolution(tif, dib); - - // set up the colormap based on photometric - - ReadPalette(tif, photometric, bitspersample, dib); - - // get the tile geometry - if(!TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tileWidth) || !TIFFGetField(tif, TIFFTAG_TILELENGTH, &tileHeight)) { - throw "Invalid tiled TIFF image"; - } - - // read the tiff lines and save them in the DIB - - if(planar_config == PLANARCONFIG_CONTIG && !header_only) { - - // get the maximum number of bytes required to contain a tile - tsize_t tileSize = TIFFTileSize(tif); - - // allocate tile buffer - BYTE *tileBuffer = (BYTE*)malloc(tileSize * sizeof(BYTE)); - if(tileBuffer == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - // calculate src line and dst pitch - int dst_pitch = FreeImage_GetPitch(dib); - int tileRowSize = TIFFTileRowSize(tif); - int imageRowSize = TIFFScanlineSize(tif); - - - // In the tiff file the lines are saved from up to down - // In a DIB the lines must be saved from down to up - - BYTE *bits = FreeImage_GetScanLine(dib, height - 1); - - uint32 x, y, rowSize; - for (y = 0; y < height; y += tileHeight) { - int32 nrows = (y + tileHeight > height ? height - y : tileHeight); - - for (x = 0, rowSize = 0; x < width; x += tileWidth, rowSize += tileRowSize) { - memset(tileBuffer, 0, tileSize); - - // read one tile - if (TIFFReadTile(tif, tileBuffer, x, y, 0, 0) < 0) { - free(tileBuffer); - throw "Corrupted tiled TIFF file"; - } - // convert to strip - if(x + tileWidth > width) { - src_line = imageRowSize - rowSize; - } else { - src_line = tileRowSize; - } - BYTE *src_bits = tileBuffer; - BYTE *dst_bits = bits + rowSize; - for(int k = 0; k < nrows; k++) { - memcpy(dst_bits, src_bits, src_line); - src_bits += tileRowSize; - dst_bits -= dst_pitch; - } - } - - bits -= nrows * dst_pitch; - } - -#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR - SwapRedBlue32(dib); -#endif - free(tileBuffer); - } - else if(planar_config == PLANARCONFIG_SEPARATE) { - throw "Separated tiled TIFF images are not supported"; - } - - - } else if(loadMethod == LoadAsLogLuv) { - // --------------------------------------------------------------------------------- - // RGBF LogLuv compressed loading - // --------------------------------------------------------------------------------- - - double stonits; // input conversion to nits - if (!TIFFGetField(tif, TIFFTAG_STONITS, &stonits)) { - stonits = 1; - } - - // create a new DIB - dib = CreateImageType(header_only, image_type, width, height, bitspersample, samplesperpixel); - if (dib == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - // fill in the resolution (english or universal) - - ReadResolution(tif, dib); - - if(planar_config == PLANARCONFIG_CONTIG && !header_only) { - // calculate the line + pitch (separate for scr & dest) - - tsize_t src_line = TIFFScanlineSize(tif); - int dst_pitch = FreeImage_GetPitch(dib); - - // In the tiff file the lines are save from up to down - // In a DIB the lines must be saved from down to up - - BYTE *bits = FreeImage_GetScanLine(dib, height - 1); - - // read the tiff lines and save them in the DIB - - BYTE *buf = (BYTE*)malloc(TIFFStripSize(tif) * sizeof(BYTE)); - if(buf == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - for (uint32 y = 0; y < height; y += rowsperstrip) { - int32 nrow = (y + rowsperstrip > height ? height - y : rowsperstrip); - - if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, 0), buf, nrow * src_line) == -1) { - free(buf); - throw FI_MSG_ERROR_PARSING; - } - // convert from XYZ to RGB - for (int l = 0; l < nrow; l++) { - tiff_ConvertLineXYZToRGB(bits, buf + l * src_line, stonits, width); - bits -= dst_pitch; - } - } - - free(buf); - } - else if(planar_config == PLANARCONFIG_SEPARATE) { - // this cannot happen according to the LogLuv specification - throw "Unable to handle PLANARCONFIG_SEPARATE LogLuv images"; - } - - } else if(loadMethod == LoadAsHalfFloat) { - // --------------------------------------------------------------------------------- - // RGBF loading from a half format - // --------------------------------------------------------------------------------- - - // create a new DIB - dib = CreateImageType(header_only, image_type, width, height, bitspersample, samplesperpixel); - if (dib == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - // fill in the resolution (english or universal) - - ReadResolution(tif, dib); - - if(!header_only) { - - // calculate the line + pitch (separate for scr & dest) - - tsize_t src_line = TIFFScanlineSize(tif); - unsigned dst_pitch = FreeImage_GetPitch(dib); - - // In the tiff file the lines are save from up to down - // In a DIB the lines must be saved from down to up - - BYTE *bits = FreeImage_GetScanLine(dib, height - 1); - - // read the tiff lines and save them in the DIB - - if(planar_config == PLANARCONFIG_CONTIG) { - - BYTE *buf = (BYTE*)malloc(TIFFStripSize(tif) * sizeof(BYTE)); - if(buf == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - for (uint32 y = 0; y < height; y += rowsperstrip) { - uint32 nrow = (y + rowsperstrip > height ? height - y : rowsperstrip); - - if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, 0), buf, nrow * src_line) == -1) { - free(buf); - throw FI_MSG_ERROR_PARSING; - } - - // convert from half (16-bit) to float (32-bit) - // !!! use OpenEXR half helper class - - half half_value; - - for (uint32 l = 0; l < nrow; l++) { - WORD *src_pixel = (WORD*)(buf + l * src_line); - float *dst_pixel = (float*)bits; - - for(tsize_t x = 0; x < (tsize_t)(src_line / sizeof(WORD)); x++) { - half_value.setBits(src_pixel[x]); - dst_pixel[x] = half_value; - } - - bits -= dst_pitch; - } - } - - free(buf); - } - else if(planar_config == PLANARCONFIG_SEPARATE) { - // this use case was never encountered yet - throw "Unable to handle PLANARCONFIG_SEPARATE RGB half float images"; - } - - } // !header only - - } else { - // --------------------------------------------------------------------------------- - // Unknown or unsupported format - // --------------------------------------------------------------------------------- - - throw FI_MSG_ERROR_UNSUPPORTED_FORMAT; - } - - // copy ICC profile data (must be done after FreeImage_Allocate) - - FreeImage_CreateICCProfile(dib, iccBuf, iccSize); - if (photometric == PHOTOMETRIC_SEPARATED && asCMYK) { - FreeImage_GetICCProfile(dib)->flags |= FIICC_COLOR_IS_CMYK; - } - - // copy TIFF metadata (must be done after FreeImage_Allocate) - - ReadMetadata(tif, dib); - - // copy TIFF thumbnail (must be done after FreeImage_Allocate) - - ReadThumbnail(io, handle, data, tif, dib); - - return (FIBITMAP *)dib; - - } catch (const char *message) { - if(dib) { - FreeImage_Unload(dib); - } - if(message) { - FreeImage_OutputMessageProc(s_format_id, message); - } - return NULL; - } - -} - -// -------------------------------------------------------------------------- - -static BOOL -SaveOneTIFF(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data, unsigned ifd, unsigned ifdCount) { - if (!dib || !handle || !data) { - return FALSE; - } - - try { - fi_TIFFIO *fio = (fi_TIFFIO*)data; - TIFF *out = fio->tif; - - const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); - - const uint32 width = FreeImage_GetWidth(dib); - const uint32 height = FreeImage_GetHeight(dib); - const uint16 bitsperpixel = (uint16)FreeImage_GetBPP(dib); - - const FIICCPROFILE* iccProfile = FreeImage_GetICCProfile(dib); - - // setup out-variables based on dib and flag options - - uint16 bitspersample; - uint16 samplesperpixel; - uint16 photometric; - - if(image_type == FIT_BITMAP) { - // standard image: 1-, 4-, 8-, 16-, 24-, 32-bit - - samplesperpixel = ((bitsperpixel == 24) ? 3 : ((bitsperpixel == 32) ? 4 : 1)); - bitspersample = bitsperpixel / samplesperpixel; - photometric = GetPhotometric(dib); - - if((bitsperpixel == 8) && FreeImage_IsTransparent(dib)) { - // 8-bit transparent picture : convert later to 8-bit + 8-bit alpha - samplesperpixel = 2; - bitspersample = 8; - } - else if(bitsperpixel == 32) { - // 32-bit images : check for CMYK or alpha transparency - - if((((iccProfile->flags & FIICC_COLOR_IS_CMYK) == FIICC_COLOR_IS_CMYK) || ((flags & TIFF_CMYK) == TIFF_CMYK))) { - // CMYK support - photometric = PHOTOMETRIC_SEPARATED; - TIFFSetField(out, TIFFTAG_INKSET, INKSET_CMYK); - TIFFSetField(out, TIFFTAG_NUMBEROFINKS, 4); - } - else if(photometric == PHOTOMETRIC_RGB) { - // transparency mask support - uint16 sampleinfo[1]; - // unassociated alpha data is transparency information - sampleinfo[0] = EXTRASAMPLE_UNASSALPHA; - TIFFSetField(out, TIFFTAG_EXTRASAMPLES, 1, sampleinfo); - } - } - } else if(image_type == FIT_RGB16) { - // 48-bit RGB - - samplesperpixel = 3; - bitspersample = bitsperpixel / samplesperpixel; - photometric = PHOTOMETRIC_RGB; - } else if(image_type == FIT_RGBA16) { - // 64-bit RGBA - - samplesperpixel = 4; - bitspersample = bitsperpixel / samplesperpixel; - if((((iccProfile->flags & FIICC_COLOR_IS_CMYK) == FIICC_COLOR_IS_CMYK) || ((flags & TIFF_CMYK) == TIFF_CMYK))) { - // CMYK support - photometric = PHOTOMETRIC_SEPARATED; - TIFFSetField(out, TIFFTAG_INKSET, INKSET_CMYK); - TIFFSetField(out, TIFFTAG_NUMBEROFINKS, 4); - } - else { - photometric = PHOTOMETRIC_RGB; - // transparency mask support - uint16 sampleinfo[1]; - // unassociated alpha data is transparency information - sampleinfo[0] = EXTRASAMPLE_UNASSALPHA; - TIFFSetField(out, TIFFTAG_EXTRASAMPLES, 1, sampleinfo); - } - } else if(image_type == FIT_RGBF) { - // 96-bit RGBF => store with a LogLuv encoding ? - - samplesperpixel = 3; - bitspersample = bitsperpixel / samplesperpixel; - // the library converts to and from floating-point XYZ CIE values - if((flags & TIFF_LOGLUV) == TIFF_LOGLUV) { - photometric = PHOTOMETRIC_LOGLUV; - TIFFSetField(out, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_FLOAT); - // TIFFSetField(out, TIFFTAG_STONITS, 1.0); // assume unknown - } - else { - // store with default compression (LZW) or with input compression flag - photometric = PHOTOMETRIC_RGB; - } - - } else if (image_type == FIT_RGBAF) { - // 128-bit RGBAF => store with default compression (LZW) or with input compression flag - - samplesperpixel = 4; - bitspersample = bitsperpixel / samplesperpixel; - photometric = PHOTOMETRIC_RGB; - } else { - // special image type (int, long, double, ...) - - samplesperpixel = 1; - bitspersample = bitsperpixel; - photometric = PHOTOMETRIC_MINISBLACK; - } - - // set image data type - - WriteImageType(out, image_type); - - // write possible ICC profile - - if (iccProfile->size && iccProfile->data) { - TIFFSetField(out, TIFFTAG_ICCPROFILE, iccProfile->size, iccProfile->data); - } - - // handle standard width/height/bpp stuff - - TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width); - TIFFSetField(out, TIFFTAG_IMAGELENGTH, height); - TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel); - TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, bitspersample); - TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric); - TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); // single image plane - TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); - TIFFSetField(out, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB); - TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, (uint32) -1)); - - // handle metrics - - WriteResolution(out, dib); - - // multi-paging - - if (page >= 0) { - char page_number[20]; - sprintf(page_number, "Page %d", page); - - TIFFSetField(out, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE); - TIFFSetField(out, TIFFTAG_PAGENUMBER, (uint16)page, (uint16)0); - TIFFSetField(out, TIFFTAG_PAGENAME, page_number); - - } else { - // is it a thumbnail ? - TIFFSetField(out, TIFFTAG_SUBFILETYPE, (ifd == 0) ? 0 : FILETYPE_REDUCEDIMAGE); - } - - // palettes (image colormaps are automatically scaled to 16-bits) - - if (photometric == PHOTOMETRIC_PALETTE) { - uint16 *r, *g, *b; - uint16 nColors = (uint16)FreeImage_GetColorsUsed(dib); - RGBQUAD *pal = FreeImage_GetPalette(dib); - - r = (uint16 *) _TIFFmalloc(sizeof(uint16) * 3 * nColors); - if(r == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - g = r + nColors; - b = g + nColors; - - for (int i = nColors - 1; i >= 0; i--) { - r[i] = SCALE((uint16)pal[i].rgbRed); - g[i] = SCALE((uint16)pal[i].rgbGreen); - b[i] = SCALE((uint16)pal[i].rgbBlue); - } - - TIFFSetField(out, TIFFTAG_COLORMAP, r, g, b); - - _TIFFfree(r); - } - - // compression tag - - WriteCompression(out, bitspersample, samplesperpixel, photometric, flags); - - // metadata - - WriteMetadata(out, dib); - - // thumbnail tag - - if((ifd == 0) && (ifdCount > 1)) { - uint32 diroff[1]; - diroff[0] = 0; - TIFFSetField(out, TIFFTAG_SUBIFD, 1, diroff); - } - - // read the DIB lines from bottom to top - // and save them in the TIF - // ------------------------------------- - - const uint32 pitch = FreeImage_GetPitch(dib); - - if(image_type == FIT_BITMAP) { - // standard bitmap type - - switch(bitsperpixel) { - case 1 : - case 4 : - case 8 : - { - if((bitsperpixel == 8) && FreeImage_IsTransparent(dib)) { - // 8-bit transparent picture : convert to 8-bit + 8-bit alpha - - // get the transparency table - BYTE *trns = FreeImage_GetTransparencyTable(dib); - - BYTE *buffer = (BYTE *)malloc(2 * width * sizeof(BYTE)); - if(buffer == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - for (int y = height - 1; y >= 0; y--) { - BYTE *bits = FreeImage_GetScanLine(dib, y); - - BYTE *p = bits, *b = buffer; - - for(uint32 x = 0; x < width; x++) { - // copy the 8-bit layer - b[0] = *p; - // convert the trns table to a 8-bit alpha layer - b[1] = trns[ b[0] ]; - - p++; - b += samplesperpixel; - } - - // write the scanline to disc - - TIFFWriteScanline(out, buffer, height - y - 1, 0); - } - - free(buffer); - } - else { - // other cases - BYTE *buffer = (BYTE *)malloc(pitch * sizeof(BYTE)); - if(buffer == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - for (uint32 y = 0; y < height; y++) { - // get a copy of the scanline - memcpy(buffer, FreeImage_GetScanLine(dib, height - y - 1), pitch); - // write the scanline to disc - TIFFWriteScanline(out, buffer, y, 0); - } - free(buffer); - } - - break; - } - - case 24: - case 32: - { - BYTE *buffer = (BYTE *)malloc(pitch * sizeof(BYTE)); - if(buffer == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - for (uint32 y = 0; y < height; y++) { - // get a copy of the scanline - - memcpy(buffer, FreeImage_GetScanLine(dib, height - y - 1), pitch); - -#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR - if (photometric != PHOTOMETRIC_SEPARATED) { - // TIFFs store color data RGB(A) instead of BGR(A) - - BYTE *pBuf = buffer; - - for (uint32 x = 0; x < width; x++) { - INPLACESWAP(pBuf[0], pBuf[2]); - pBuf += samplesperpixel; - } - } -#endif - // write the scanline to disc - - TIFFWriteScanline(out, buffer, y, 0); - } - - free(buffer); - - break; - } - }//< switch (bitsperpixel) - - } else if(image_type == FIT_RGBF && (flags & TIFF_LOGLUV) == TIFF_LOGLUV) { - // RGBF image => store as XYZ using a LogLuv encoding - - BYTE *buffer = (BYTE *)malloc(pitch * sizeof(BYTE)); - if(buffer == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - for (uint32 y = 0; y < height; y++) { - // get a copy of the scanline and convert from RGB to XYZ - tiff_ConvertLineRGBToXYZ(buffer, FreeImage_GetScanLine(dib, height - y - 1), width); - // write the scanline to disc - TIFFWriteScanline(out, buffer, y, 0); - } - free(buffer); - } else { - // just dump the dib (tiff supports all dib types) - - BYTE *buffer = (BYTE *)malloc(pitch * sizeof(BYTE)); - if(buffer == NULL) { - throw FI_MSG_ERROR_MEMORY; - } - - for (uint32 y = 0; y < height; y++) { - // get a copy of the scanline - memcpy(buffer, FreeImage_GetScanLine(dib, height - y - 1), pitch); - // write the scanline to disc - TIFFWriteScanline(out, buffer, y, 0); - } - free(buffer); - } - - // write out the directory tag if we wrote a page other than -1 or if we have a thumbnail to write later - - if( (page >= 0) || ((ifd == 0) && (ifdCount > 1)) ) { - TIFFWriteDirectory(out); - // else: TIFFClose will WriteDirectory - } - - return TRUE; - - } catch(const char *text) { - FreeImage_OutputMessageProc(s_format_id, text); - return FALSE; - } -} - -static BOOL DLL_CALLCONV -Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) { - BOOL bResult = FALSE; - - // handle thumbnail as SubIFD - const BOOL bHasThumbnail = (FreeImage_GetThumbnail(dib) != NULL); - const unsigned ifdCount = bHasThumbnail ? 2 : 1; - - FIBITMAP *bitmap = dib; - - for(unsigned ifd = 0; ifd < ifdCount; ifd++) { - // redirect dib to thumbnail for the second pass - if(ifd == 1) { - bitmap = FreeImage_GetThumbnail(dib); - } - - bResult = SaveOneTIFF(io, bitmap, handle, page, flags, data, ifd, ifdCount); - if(!bResult) { - return FALSE; - } - } - - return bResult; -} - -// ========================================================== -// Init -// ========================================================== - -void DLL_CALLCONV -InitTIFF(Plugin *plugin, int format_id) { - s_format_id = format_id; - - plugin->format_proc = Format; - plugin->description_proc = Description; - plugin->extension_proc = Extension; - plugin->regexpr_proc = RegExpr; - plugin->open_proc = Open; - plugin->close_proc = Close; - plugin->pagecount_proc = PageCount; - plugin->pagecapability_proc = NULL; - plugin->load_proc = Load; - plugin->save_proc = Save; - plugin->validate_proc = Validate; - plugin->mime_proc = MimeType; - plugin->supports_export_bpp_proc = SupportsExportDepth; - plugin->supports_export_type_proc = SupportsExportType; - plugin->supports_icc_profiles_proc = SupportsICCProfiles; - plugin->supports_no_pixels_proc = SupportsNoPixels; -} +// ========================================================== +// TIFF Loader and Writer +// +// Design and implementation by +// - Floris van den Berg (flvdberg@wxs.nl) +// - Hervé Drolon (drolon@infonie.fr) +// - Markus Loibl (markus.loibl@epost.de) +// - Luca Piergentili (l.pierge@terra.es) +// - Detlev Vendt (detlev.vendt@brillit.de) +// - Mihail Naydenov (mnaydenov@users.sourceforge.net) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#ifdef _MSC_VER +#pragma warning (disable : 4786) // identifier was truncated to 'number' characters +#endif + +#ifdef unix +#undef unix +#endif +#ifdef __unix +#undef __unix +#endif + +#include "FreeImage.h" +#include "Utilities.h" +#include "../LibTIFF/tiffiop.h" +#include "../Metadata/FreeImageTag.h" +#include "../OpenEXR/Half/half.h" + +#include "FreeImageIO.h" +#include "PSDParser.h" + +// ---------------------------------------------------------- +// geotiff interface (see XTIFF.cpp) +// ---------------------------------------------------------- + +// Extended TIFF Directory GEO Tag Support +void XTIFFInitialize(); + +// GeoTIFF profile +void tiff_read_geotiff_profile(TIFF *tif, FIBITMAP *dib); +void tiff_write_geotiff_profile(TIFF *tif, FIBITMAP *dib); + +// ---------------------------------------------------------- +// exif interface (see XTIFF.cpp) +// ---------------------------------------------------------- + +// TIFF Exif profile +BOOL tiff_read_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib); +BOOL tiff_write_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib); + +// ---------------------------------------------------------- +// LogLuv conversion functions interface (see TIFFLogLuv.cpp) +// ---------------------------------------------------------- + +void tiff_ConvertLineXYZToRGB(BYTE *target, BYTE *source, double stonits, int width_in_pixels); +void tiff_ConvertLineRGBToXYZ(BYTE *target, BYTE *source, int width_in_pixels); + +// ---------------------------------------------------------- + +/** Supported loading methods */ +typedef enum { + LoadAsRBGA = 0, + LoadAsCMYK = 1, + LoadAs8BitTrns = 2, + LoadAsGenericStrip = 3, + LoadAsTiled = 4, + LoadAsLogLuv = 5, + LoadAsHalfFloat = 6 +} TIFFLoadMethod; + +// ---------------------------------------------------------- +// local prototypes +// ---------------------------------------------------------- + +static tsize_t _tiffReadProc(thandle_t handle, tdata_t buf, tsize_t size); +static tsize_t _tiffWriteProc(thandle_t handle, tdata_t buf, tsize_t size); +static toff_t _tiffSeekProc(thandle_t handle, toff_t off, int whence); +static int _tiffCloseProc(thandle_t fd); +static int _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize); +static void _tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size); + +static uint16 CheckColormap(int n, uint16* r, uint16* g, uint16* b); +static uint16 GetPhotometric(FIBITMAP *dib); + +static void ReadResolution(TIFF *tiff, FIBITMAP *dib); +static void WriteResolution(TIFF *tiff, FIBITMAP *dib); + +static void ReadPalette(TIFF *tiff, uint16 photometric, uint16 bitspersample, FIBITMAP *dib); + +static FIBITMAP* CreateImageType(BOOL header_only, FREE_IMAGE_TYPE fit, int width, int height, uint16 bitspersample, uint16 samplesperpixel); +static FREE_IMAGE_TYPE ReadImageType(TIFF *tiff, uint16 bitspersample, uint16 samplesperpixel); +static void WriteImageType(TIFF *tiff, FREE_IMAGE_TYPE fit); + +static void WriteCompression(TIFF *tiff, uint16 bitspersample, uint16 samplesperpixel, uint16 photometric, int flags); + +static BOOL tiff_read_iptc_profile(TIFF *tiff, FIBITMAP *dib); +static BOOL tiff_read_xmp_profile(TIFF *tiff, FIBITMAP *dib); +static BOOL tiff_read_exif_profile(TIFF *tiff, FIBITMAP *dib); +static void ReadMetadata(TIFF *tiff, FIBITMAP *dib); + +static BOOL tiff_write_iptc_profile(TIFF *tiff, FIBITMAP *dib); +static BOOL tiff_write_xmp_profile(TIFF *tiff, FIBITMAP *dib); +static void WriteMetadata(TIFF *tiff, FIBITMAP *dib); + +static TIFFLoadMethod FindLoadMethod(TIFF *tif, uint16 photometric, uint16 bitspersample, uint16 samplesperpixel, FREE_IMAGE_TYPE image_type, int flags); + +static void ReadThumbnail(FreeImageIO *io, fi_handle handle, void *data, TIFF *tiff, FIBITMAP *dib); + + +// ========================================================== +// Plugin Interface +// ========================================================== + +static int s_format_id; + +typedef struct { + FreeImageIO *io; + fi_handle handle; + TIFF *tif; +} fi_TIFFIO; + +// ---------------------------------------------------------- +// libtiff interface +// ---------------------------------------------------------- + +static tsize_t +_tiffReadProc(thandle_t handle, tdata_t buf, tsize_t size) { + fi_TIFFIO *fio = (fi_TIFFIO*)handle; + return fio->io->read_proc(buf, size, 1, fio->handle) * size; +} + +static tsize_t +_tiffWriteProc(thandle_t handle, tdata_t buf, tsize_t size) { + fi_TIFFIO *fio = (fi_TIFFIO*)handle; + return fio->io->write_proc(buf, size, 1, fio->handle) * size; +} + +static toff_t +_tiffSeekProc(thandle_t handle, toff_t off, int whence) { + fi_TIFFIO *fio = (fi_TIFFIO*)handle; + fio->io->seek_proc(fio->handle, off, whence); + return fio->io->tell_proc(fio->handle); +} + +static int +_tiffCloseProc(thandle_t fd) { + return 0; +} + +#include + +static toff_t +_tiffSizeProc(thandle_t handle) { + fi_TIFFIO *fio = (fi_TIFFIO*)handle; + long currPos = fio->io->tell_proc(fio->handle); + fio->io->seek_proc(fio->handle, 0, SEEK_END); + long fileSize = fio->io->tell_proc(fio->handle); + fio->io->seek_proc(fio->handle, currPos, SEEK_SET); + return fileSize; +} + +static int +_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) { + return 0; +} + +static void +_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) { +} + +/** +Open a TIFF file descriptor for reading or writing +@param handle File handle +@param name Name of the file handle +@param mode Specifies if the file is to be opened for reading ("r") or writing ("w") +*/ +TIFF * +TIFFFdOpen(thandle_t handle, const char *name, const char *mode) { + TIFF *tif; + + // Set up the callback for extended TIFF directory tag support + // (see XTIFF.cpp) + XTIFFInitialize(); + + // Open the file; the callback will set everything up + tif = TIFFClientOpen(name, mode, handle, + _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, + _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); + + // Warning: tif_fd is declared as 'int' currently (see libTIFF), + // may result in incorrect file pointers inside libTIFF on + // 64bit machines (sizeof(int) != sizeof(long)). + // Needs to be fixed within libTIFF. + if (tif) { + tif->tif_fd = (long)handle; + } + + return tif; +} + +/** +Open a TIFF file for reading or writing +@param name +@param mode +*/ +TIFF* +TIFFOpen(const char* name, const char* mode) { + return 0; +} + +// ---------------------------------------------------------- +// TIFF library FreeImage-specific routines. +// ---------------------------------------------------------- + +tdata_t +_TIFFmalloc(tsize_t s) { + return malloc(s); +} + +void +_TIFFfree(tdata_t p) { + free(p); +} + +tdata_t +_TIFFrealloc(tdata_t p, tsize_t s) { + return realloc(p, s); +} + +void +_TIFFmemset(tdata_t p, int v, tsize_t c) { + memset(p, v, (size_t) c); +} + +void +_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) { + memcpy(d, s, (size_t) c); +} + +int +_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) { + return (memcmp(p1, p2, (size_t) c)); +} + +// ---------------------------------------------------------- +// in FreeImage warnings and errors are disabled +// ---------------------------------------------------------- + +static void +msdosWarningHandler(const char* module, const char* fmt, va_list ap) { +} + +TIFFErrorHandler _TIFFwarningHandler = msdosWarningHandler; + +static void +msdosErrorHandler(const char* module, const char* fmt, va_list ap) { + + // use this for diagnostic only (do not use otherwise, even in DEBUG mode) + /* + if (module != NULL) { + char msg[1024]; + vsprintf(msg, fmt, ap); + FreeImage_OutputMessageProc(s_format_id, "%s: %s", module, msg); + } + */ +} + +TIFFErrorHandler _TIFFerrorHandler = msdosErrorHandler; + +// ---------------------------------------------------------- + +#define CVT(x) (((x) * 255L) / ((1L<<16)-1)) +#define SCALE(x) (((x)*((1L<<16)-1))/255) + +// ========================================================== +// Internal functions +// ========================================================== + +static uint16 +CheckColormap(int n, uint16* r, uint16* g, uint16* b) { + while (n-- > 0) { + if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256) { + return 16; + } + } + + return 8; +} + +/** +Get the TIFFTAG_PHOTOMETRIC value from the dib +*/ +static uint16 +GetPhotometric(FIBITMAP *dib) { + FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib); + switch(color_type) { + case FIC_MINISWHITE: // min value is white + return PHOTOMETRIC_MINISWHITE; + case FIC_MINISBLACK: // min value is black + return PHOTOMETRIC_MINISBLACK; + case FIC_PALETTE: // color map indexed + return PHOTOMETRIC_PALETTE; + case FIC_RGB: // RGB color model + case FIC_RGBALPHA: // RGB color model with alpha channel + return PHOTOMETRIC_RGB; + case FIC_CMYK: // CMYK color model + return PHOTOMETRIC_RGB; // default to RGB unless the save flag is set to TIFF_CMYK + default: + return PHOTOMETRIC_MINISBLACK; + } +} + +/** +Get the resolution from the TIFF and fill the dib with universal units +*/ +static void +ReadResolution(TIFF *tiff, FIBITMAP *dib) { + float fResX = 300.0; + float fResY = 300.0; + uint16 resUnit = RESUNIT_INCH; + + TIFFGetField(tiff, TIFFTAG_RESOLUTIONUNIT, &resUnit); + TIFFGetField(tiff, TIFFTAG_XRESOLUTION, &fResX); + TIFFGetField(tiff, TIFFTAG_YRESOLUTION, &fResY); + + // If we don't have a valid resolution unit and valid resolution is specified then assume inch + if (resUnit == RESUNIT_NONE && fResX > 0.0 && fResY > 0.0) { + resUnit = RESUNIT_INCH; + } + if (resUnit == RESUNIT_INCH) { + FreeImage_SetDotsPerMeterX(dib, (unsigned) (fResX/0.0254000 + 0.5)); + FreeImage_SetDotsPerMeterY(dib, (unsigned) (fResY/0.0254000 + 0.5)); + } else if(resUnit == RESUNIT_CENTIMETER) { + FreeImage_SetDotsPerMeterX(dib, (unsigned) (fResX*100.0 + 0.5)); + FreeImage_SetDotsPerMeterY(dib, (unsigned) (fResY*100.0 + 0.5)); + } +} + +/** +Set the resolution to the TIFF using english units +*/ +static void +WriteResolution(TIFF *tiff, FIBITMAP *dib) { + double res; + + TIFFSetField(tiff, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); + + res = (unsigned long) (0.5 + 0.0254 * FreeImage_GetDotsPerMeterX(dib)); + TIFFSetField(tiff, TIFFTAG_XRESOLUTION, res); + + res = (unsigned long) (0.5 + 0.0254 * FreeImage_GetDotsPerMeterY(dib)); + TIFFSetField(tiff, TIFFTAG_YRESOLUTION, res); +} + +/** +Fill the dib palette according to the TIFF photometric +*/ +static void +ReadPalette(TIFF *tiff, uint16 photometric, uint16 bitspersample, FIBITMAP *dib) { + RGBQUAD *pal = FreeImage_GetPalette(dib); + + switch(photometric) { + case PHOTOMETRIC_MINISBLACK: // bitmap and greyscale image types + case PHOTOMETRIC_MINISWHITE: + // Monochrome image + + if (bitspersample == 1) { + if (photometric == PHOTOMETRIC_MINISWHITE) { + pal[0].rgbRed = pal[0].rgbGreen = pal[0].rgbBlue = 255; + pal[1].rgbRed = pal[1].rgbGreen = pal[1].rgbBlue = 0; + } else { + pal[0].rgbRed = pal[0].rgbGreen = pal[0].rgbBlue = 0; + pal[1].rgbRed = pal[1].rgbGreen = pal[1].rgbBlue = 255; + } + + } else if ((bitspersample == 4) ||(bitspersample == 8)) { + // need to build the scale for greyscale images + int ncolors = FreeImage_GetColorsUsed(dib); + + if (photometric == PHOTOMETRIC_MINISBLACK) { + for (int i = 0; i < ncolors; i++) { + pal[i].rgbRed = + pal[i].rgbGreen = + pal[i].rgbBlue = (BYTE)(i*(255/(ncolors-1))); + } + } else { + for (int i = 0; i < ncolors; i++) { + pal[i].rgbRed = + pal[i].rgbGreen = + pal[i].rgbBlue = (BYTE)(255-i*(255/(ncolors-1))); + } + } + } + + break; + + case PHOTOMETRIC_PALETTE: // color map indexed + uint16 *red; + uint16 *green; + uint16 *blue; + + TIFFGetField(tiff, TIFFTAG_COLORMAP, &red, &green, &blue); + + // load the palette in the DIB + + if (CheckColormap(1<= 0; i--) { + pal[i].rgbRed =(BYTE) CVT(red[i]); + pal[i].rgbGreen = (BYTE) CVT(green[i]); + pal[i].rgbBlue = (BYTE) CVT(blue[i]); + } + } else { + for (int i = (1 << bitspersample) - 1; i >= 0; i--) { + pal[i].rgbRed = (BYTE) red[i]; + pal[i].rgbGreen = (BYTE) green[i]; + pal[i].rgbBlue = (BYTE) blue[i]; + } + } + + break; + } +} + +/** +Allocate a FIBITMAP +@param header_only If TRUE, allocate a 'header only' FIBITMAP, otherwise allocate a full FIBITMAP +@param fit Image type +@param width Image width in pixels +@param height Image height in pixels +@param bitspersample # bits per sample +@param samplesperpixel # samples per pixel +@return Returns the allocated image if successful, returns NULL otherwise +*/ +static FIBITMAP* +CreateImageType(BOOL header_only, FREE_IMAGE_TYPE fit, int width, int height, uint16 bitspersample, uint16 samplesperpixel) { + FIBITMAP *dib = NULL; + + if((width < 0) || (height < 0)) { + // check for malicious images + return NULL; + } + + int bpp = bitspersample * samplesperpixel; + + if(fit == FIT_BITMAP) { + // standard bitmap type + + if(bpp == 16) { + + if((samplesperpixel == 2) && (bitspersample == 8)) { + // 8-bit indexed + 8-bit alpha channel -> convert to 8-bit transparent + dib = FreeImage_AllocateHeader(header_only, width, height, 8); + } else { + // 16-bit RGB -> expect it to be 565 + dib = FreeImage_AllocateHeader(header_only, width, height, bpp, FI16_565_RED_MASK, FI16_565_GREEN_MASK, FI16_565_BLUE_MASK); + } + + } + else { + + dib = FreeImage_AllocateHeader(header_only, width, height, MIN(bpp, 32), FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + } + + + } else { + // other bitmap types + + dib = FreeImage_AllocateHeaderT(header_only, fit, width, height, bpp); + } + + return dib; +} + +/** +Read the TIFFTAG_SAMPLEFORMAT tag and convert to FREE_IMAGE_TYPE +@param tiff LibTIFF TIFF Handle +@param bitspersample # bit per sample +@param samplesperpixel # samples per pixel +@return Returns the image type as a FREE_IMAGE_TYPE value +*/ +static FREE_IMAGE_TYPE +ReadImageType(TIFF *tiff, uint16 bitspersample, uint16 samplesperpixel) { + uint16 sampleformat = 0; + FREE_IMAGE_TYPE fit = FIT_BITMAP ; + + uint16 bpp = bitspersample * samplesperpixel; + + // try the sampleformat tag + if(TIFFGetField(tiff, TIFFTAG_SAMPLEFORMAT, &sampleformat)) { + + switch (sampleformat) { + case SAMPLEFORMAT_UINT: + switch (bpp) { + case 1: + case 4: + case 8: + case 24: + fit = FIT_BITMAP; + break; + case 16: + // 8-bit + alpha or 16-bit greyscale + if(samplesperpixel == 2) { + fit = FIT_BITMAP; + } else { + fit = FIT_UINT16; + } + break; + case 32: + if(samplesperpixel == 4) { + fit = FIT_BITMAP; + } else { + fit = FIT_UINT32; + } + break; + case 48: + if(samplesperpixel == 3) { + fit = FIT_RGB16; + } + break; + case 64: + if(samplesperpixel == 4) { + fit = FIT_RGBA16; + } + break; + } + break; + + case SAMPLEFORMAT_INT: + switch (bpp) { + case 16: + if(samplesperpixel == 3) { + fit = FIT_BITMAP; + } else { + fit = FIT_INT16; + } + break; + case 32: + fit = FIT_INT32; + break; + } + break; + + case SAMPLEFORMAT_IEEEFP: + switch (bpp) { + case 32: + fit = FIT_FLOAT; + break; + case 48: + // 3 x half float => convert to RGBF + if((samplesperpixel == 3) && (bitspersample == 16)) { + fit = FIT_RGBF; + } + break; + case 64: + if(samplesperpixel == 2) { + fit = FIT_FLOAT; + } else { + fit = FIT_DOUBLE; + } + break; + case 96: + fit = FIT_RGBF; + break; + default: + if(bpp >= 128) { + fit = FIT_RGBAF; + } + break; + } + break; + case SAMPLEFORMAT_COMPLEXIEEEFP: + switch (bpp) { + case 64: + break; + case 128: + fit = FIT_COMPLEX; + break; + } + break; + + } + } + // no sampleformat tag : assume SAMPLEFORMAT_UINT + else { + if(samplesperpixel == 1) { + switch (bpp) { + case 16: + fit = FIT_UINT16; + break; + + case 32: + fit = FIT_UINT32; + break; + } + } + else if(samplesperpixel == 3) { + if(bpp == 48) fit = FIT_RGB16; + } + else if(samplesperpixel >= 4) { + if(bitspersample == 16) { + fit = FIT_RGBA16; + } + } + + } + + return fit; +} + +/** +Convert FREE_IMAGE_TYPE and write TIFFTAG_SAMPLEFORMAT +@param tiff LibTIFF TIFF Handle +@param fit Image type as a FREE_IMAGE_TYPE value +*/ +static void +WriteImageType(TIFF *tiff, FREE_IMAGE_TYPE fit) { + switch(fit) { + case FIT_BITMAP: // standard image: 1-, 4-, 8-, 16-, 24-, 32-bit + case FIT_UINT16: // array of unsigned short : unsigned 16-bit + case FIT_UINT32: // array of unsigned long : unsigned 32-bit + case FIT_RGB16: // 48-bit RGB image : 3 x 16-bit + case FIT_RGBA16: // 64-bit RGBA image : 4 x 16-bit + TIFFSetField(tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT); + break; + + case FIT_INT16: // array of short : signed 16-bit + case FIT_INT32: // array of long : signed 32-bit + TIFFSetField(tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_INT); + break; + + case FIT_FLOAT: // array of float : 32-bit + case FIT_DOUBLE: // array of double : 64-bit + case FIT_RGBF: // 96-bit RGB float image : 3 x 32-bit IEEE floating point + case FIT_RGBAF: // 128-bit RGBA float image : 4 x 32-bit IEEE floating point + TIFFSetField(tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP); + break; + + case FIT_COMPLEX: // array of COMPLEX : 2 x 64-bit + TIFFSetField(tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_COMPLEXIEEEFP); + break; + } +} + +/** +Select the compression algorithm +@param tiff LibTIFF TIFF Handle +@param +*/ +static void +WriteCompression(TIFF *tiff, uint16 bitspersample, uint16 samplesperpixel, uint16 photometric, int flags) { + uint16 compression; + uint16 bitsperpixel = bitspersample * samplesperpixel; + + if(photometric == PHOTOMETRIC_LOGLUV) { + compression = COMPRESSION_SGILOG; + } else if ((flags & TIFF_PACKBITS) == TIFF_PACKBITS) { + compression = COMPRESSION_PACKBITS; + } else if ((flags & TIFF_DEFLATE) == TIFF_DEFLATE) { + compression = COMPRESSION_DEFLATE; + } else if ((flags & TIFF_ADOBE_DEFLATE) == TIFF_ADOBE_DEFLATE) { + compression = COMPRESSION_ADOBE_DEFLATE; + } else if ((flags & TIFF_NONE) == TIFF_NONE) { + compression = COMPRESSION_NONE; + } else if ((bitsperpixel == 1) && ((flags & TIFF_CCITTFAX3) == TIFF_CCITTFAX3)) { + compression = COMPRESSION_CCITTFAX3; + } else if ((bitsperpixel == 1) && ((flags & TIFF_CCITTFAX4) == TIFF_CCITTFAX4)) { + compression = COMPRESSION_CCITTFAX4; + } else if ((flags & TIFF_LZW) == TIFF_LZW) { + compression = COMPRESSION_LZW; + } else if ((flags & TIFF_JPEG) == TIFF_JPEG) { + if(((bitsperpixel == 8) && (photometric != PHOTOMETRIC_PALETTE)) || (bitsperpixel == 24)) { + compression = COMPRESSION_JPEG; + // RowsPerStrip must be multiple of 8 for JPEG + uint32 rowsperstrip = (uint32) -1; + rowsperstrip = TIFFDefaultStripSize(tiff, rowsperstrip); + rowsperstrip = rowsperstrip + (8 - (rowsperstrip % 8)); + // overwrite previous RowsPerStrip + TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, rowsperstrip); + } else { + // default to LZW + compression = COMPRESSION_LZW; + } + } + else { + // default compression scheme + + switch(bitsperpixel) { + case 1: + compression = COMPRESSION_CCITTFAX4; + break; + + case 4: + case 8: + case 16: + case 24: + case 32: + compression = COMPRESSION_LZW; + break; + case 48: + case 64: + case 96: + case 128: + compression = COMPRESSION_LZW; + break; + + default : + compression = COMPRESSION_NONE; + break; + } + } + + TIFFSetField(tiff, TIFFTAG_COMPRESSION, compression); + + if(compression == COMPRESSION_LZW) { + // This option is only meaningful with LZW compression: a predictor value of 2 + // causes each scanline of the output image to undergo horizontal differencing + // before it is encoded; a value of 1 forces each scanline to be encoded without differencing. + + // Found on LibTIFF mailing list : + // LZW without differencing works well for 1-bit images, 4-bit grayscale images, + // and many palette-color images. But natural 24-bit color images and some 8-bit + // grayscale images do much better with differencing. + + if((bitspersample == 8) || (bitspersample == 16)) { + if ((bitsperpixel >= 8) && (photometric != PHOTOMETRIC_PALETTE)) { + TIFFSetField(tiff, TIFFTAG_PREDICTOR, 2); + } else { + TIFFSetField(tiff, TIFFTAG_PREDICTOR, 1); + } + } else { + TIFFSetField(tiff, TIFFTAG_PREDICTOR, 1); + } + } + else if(compression == COMPRESSION_CCITTFAX3) { + // try to be compliant with the TIFF Class F specification + // that documents the TIFF tags specific to FAX applications + // see http://palimpsest.stanford.edu/bytopic/imaging/std/tiff-f.html + uint32 group3options = GROUP3OPT_2DENCODING | GROUP3OPT_FILLBITS; + TIFFSetField(tiff, TIFFTAG_GROUP3OPTIONS, group3options); // 2d-encoded, has aligned EOL + TIFFSetField(tiff, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB); // lsb-to-msb fillorder + } +} + +// ========================================================== +// TIFF metadata routines +// ========================================================== + +/** + Read the TIFFTAG_RICHTIFFIPTC tag (IPTC/NAA or Adobe Photoshop profile) +*/ +static BOOL +tiff_read_iptc_profile(TIFF *tiff, FIBITMAP *dib) { + BYTE *profile = NULL; + uint32 profile_size = 0; + + if(TIFFGetField(tiff,TIFFTAG_RICHTIFFIPTC, &profile_size, &profile) == 1) { + if (TIFFIsByteSwapped(tiff) != 0) { + TIFFSwabArrayOfLong((uint32 *) profile, (unsigned long)profile_size); + } + + return read_iptc_profile(dib, profile, 4 * profile_size); + } + + return FALSE; +} + +/** + Read the TIFFTAG_XMLPACKET tag (XMP profile) + @param dib Input FIBITMAP + @param tiff LibTIFF TIFF handle + @return Returns TRUE if successful, FALSE otherwise +*/ +static BOOL +tiff_read_xmp_profile(TIFF *tiff, FIBITMAP *dib) { + BYTE *profile = NULL; + uint32 profile_size = 0; + + if (TIFFGetField(tiff, TIFFTAG_XMLPACKET, &profile_size, &profile) == 1) { + // create a tag + FITAG *tag = FreeImage_CreateTag(); + if(!tag) return FALSE; + + FreeImage_SetTagID(tag, TIFFTAG_XMLPACKET); // 700 + FreeImage_SetTagKey(tag, g_TagLib_XMPFieldName); + FreeImage_SetTagLength(tag, profile_size); + FreeImage_SetTagCount(tag, profile_size); + FreeImage_SetTagType(tag, FIDT_ASCII); + FreeImage_SetTagValue(tag, profile); + + // store the tag + FreeImage_SetMetadata(FIMD_XMP, dib, FreeImage_GetTagKey(tag), tag); + + // destroy the tag + FreeImage_DeleteTag(tag); + + return TRUE; + } + + return FALSE; +} + +/** + Read the Exif profile embedded in a TIFF + @param dib Input FIBITMAP + @param tiff LibTIFF TIFF handle + @return Returns TRUE if successful, FALSE otherwise +*/ +static BOOL +tiff_read_exif_profile(TIFF *tiff, FIBITMAP *dib) { + BOOL bResult = FALSE; + uint32 exif_offset = 0; + + // read EXIF-TIFF tags + bResult = tiff_read_exif_tags(tiff, TagLib::EXIF_MAIN, dib); + + // get the IFD offset + if(TIFFGetField(tiff, TIFFTAG_EXIFIFD, &exif_offset)) { + + // read EXIF tags + if(!TIFFReadEXIFDirectory(tiff, exif_offset)) { + return FALSE; + } + + // read all known exif tags + bResult = tiff_read_exif_tags(tiff, TagLib::EXIF_EXIF, dib); + } + + return bResult; +} + +/** +Read TIFF special profiles +*/ +static void +ReadMetadata(TIFF *tiff, FIBITMAP *dib) { + + // IPTC/NAA + tiff_read_iptc_profile(tiff, dib); + + // Adobe XMP + tiff_read_xmp_profile(tiff, dib); + + // GeoTIFF + tiff_read_geotiff_profile(tiff, dib); + + // Exif-TIFF + tiff_read_exif_profile(tiff, dib); +} + +// ---------------------------------------------------------- + +/** + Write the TIFFTAG_RICHTIFFIPTC tag (IPTC/NAA or Adobe Photoshop profile) +*/ +static BOOL +tiff_write_iptc_profile(TIFF *tiff, FIBITMAP *dib) { + if(FreeImage_GetMetadataCount(FIMD_IPTC, dib)) { + BYTE *profile = NULL; + uint32 profile_size = 0; + // create a binary profile + if(write_iptc_profile(dib, &profile, &profile_size)) { + uint32 iptc_size = profile_size; + iptc_size += (4-(iptc_size & 0x03)); // Round up for long word alignment + BYTE *iptc_profile = (BYTE*)malloc(iptc_size); + if(!iptc_profile) { + free(profile); + return FALSE; + } + memset(iptc_profile, 0, iptc_size); + memcpy(iptc_profile, profile, profile_size); + if (TIFFIsByteSwapped(tiff)) { + TIFFSwabArrayOfLong((uint32 *) iptc_profile, (unsigned long)iptc_size/4); + } + // Tag is type TIFF_LONG so byte length is divided by four + TIFFSetField(tiff, TIFFTAG_RICHTIFFIPTC, iptc_size/4, iptc_profile); + // release the profile data + free(iptc_profile); + free(profile); + + return TRUE; + } + } + + return FALSE; +} + +/** + Write the TIFFTAG_XMLPACKET tag (XMP profile) + @param dib Input FIBITMAP + @param tiff LibTIFF TIFF handle + @return Returns TRUE if successful, FALSE otherwise +*/ +static BOOL +tiff_write_xmp_profile(TIFF *tiff, FIBITMAP *dib) { + FITAG *tag_xmp = NULL; + FreeImage_GetMetadata(FIMD_XMP, dib, g_TagLib_XMPFieldName, &tag_xmp); + + if(tag_xmp && (NULL != FreeImage_GetTagValue(tag_xmp))) { + + TIFFSetField(tiff, TIFFTAG_XMLPACKET, (uint32)FreeImage_GetTagLength(tag_xmp), (BYTE*)FreeImage_GetTagValue(tag_xmp)); + + return TRUE; + } + + return FALSE; +} + +/** + Write the Exif profile to TIFF + @param dib Input FIBITMAP + @param tiff LibTIFF TIFF handle + @return Returns TRUE if successful, FALSE otherwise +*/ +static BOOL +tiff_write_exif_profile(TIFF *tiff, FIBITMAP *dib) { + BOOL bResult = FALSE; + uint32 exif_offset = 0; + + // write EXIF_MAIN tags, EXIF_EXIF not supported yet + bResult = tiff_write_exif_tags(tiff, TagLib::EXIF_MAIN, dib); + + return bResult; +} + +/** +Write TIFF special profiles +*/ +static void +WriteMetadata(TIFF *tiff, FIBITMAP *dib) { + // IPTC + tiff_write_iptc_profile(tiff, dib); + + // Adobe XMP + tiff_write_xmp_profile(tiff, dib); + + // EXIF_MAIN tags + tiff_write_exif_profile(tiff, dib); + + // GeoTIFF tags + tiff_write_geotiff_profile(tiff, dib); +} + +// ========================================================== +// Plugin Implementation +// ========================================================== + +static const char * DLL_CALLCONV +Format() { + return "TIFF"; +} + +static const char * DLL_CALLCONV +Description() { + return "Tagged Image File Format"; +} + +static const char * DLL_CALLCONV +Extension() { + return "tif,tiff"; +} + +static const char * DLL_CALLCONV +RegExpr() { + return "^[MI][MI][\\x01*][\\x01*]"; +} + +static const char * DLL_CALLCONV +MimeType() { + return "image/tiff"; +} + +static BOOL DLL_CALLCONV +Validate(FreeImageIO *io, fi_handle handle) { + BYTE tiff_id1[] = { 0x49, 0x49, 0x2A, 0x00 }; + BYTE tiff_id2[] = { 0x4D, 0x4D, 0x00, 0x2A }; + BYTE signature[4] = { 0, 0, 0, 0 }; + + io->read_proc(signature, 1, 4, handle); + + if(memcmp(tiff_id1, signature, 4) == 0) + return TRUE; + + if(memcmp(tiff_id2, signature, 4) == 0) + return TRUE; + + return FALSE; +} + +static BOOL DLL_CALLCONV +SupportsExportDepth(int depth) { + return ( + (depth == 1) || + (depth == 4) || + (depth == 8) || + (depth == 24) || + (depth == 32) + ); +} + +static BOOL DLL_CALLCONV +SupportsExportType(FREE_IMAGE_TYPE type) { + return ( + (type == FIT_BITMAP) || + (type == FIT_UINT16) || + (type == FIT_INT16) || + (type == FIT_UINT32) || + (type == FIT_INT32) || + (type == FIT_FLOAT) || + (type == FIT_DOUBLE) || + (type == FIT_COMPLEX) || + (type == FIT_RGB16) || + (type == FIT_RGBA16) || + (type == FIT_RGBF) || + (type == FIT_RGBAF) + ); +} + +static BOOL DLL_CALLCONV +SupportsICCProfiles() { + return TRUE; +} + +static BOOL DLL_CALLCONV +SupportsNoPixels() { + return TRUE; +} + +// ---------------------------------------------------------- + +static void * DLL_CALLCONV +Open(FreeImageIO *io, fi_handle handle, BOOL read) { + // wrapper for TIFF I/O + fi_TIFFIO *fio = (fi_TIFFIO*)malloc(sizeof(fi_TIFFIO)); + if(!fio) return NULL; + fio->io = io; + fio->handle = handle; + + if (read) { + fio->tif = TIFFFdOpen((thandle_t)fio, "", "r"); + } else { + fio->tif = TIFFFdOpen((thandle_t)fio, "", "w"); + } + if(fio->tif == NULL) { + free(fio); + FreeImage_OutputMessageProc(s_format_id, "Error while opening TIFF: data is invalid"); + return NULL; + } + return fio; +} + +static void DLL_CALLCONV +Close(FreeImageIO *io, fi_handle handle, void *data) { + if(data) { + fi_TIFFIO *fio = (fi_TIFFIO*)data; + TIFFClose(fio->tif); + free(fio); + } +} + +// ---------------------------------------------------------- + +static int DLL_CALLCONV +PageCount(FreeImageIO *io, fi_handle handle, void *data) { + if(data) { + fi_TIFFIO *fio = (fi_TIFFIO*)data; + TIFF *tif = (TIFF *)fio->tif; + int nr_ifd = 0; + + do { + nr_ifd++; + } while (TIFFReadDirectory(tif)); + + return nr_ifd; + } + + return 0; +} + +// ---------------------------------------------------------- + +/** +check for uncommon bitspersample values (e.g. 10, 12, ...) +@param photometric TIFFTAG_PHOTOMETRIC tiff tag +@param bitspersample TIFFTAG_BITSPERSAMPLE tiff tag +@param samplesperpixel TIFFTAG_SAMPLESPERPIXEL tiff tag +@return Returns FALSE if a uncommon bit-depth is encountered, returns TRUE otherwise +*/ +static BOOL +IsValidBitsPerSample(uint16 photometric, uint16 bitspersample, uint16 samplesperpixel) { + + switch(bitspersample) { + case 1: + case 4: + if((photometric == PHOTOMETRIC_MINISWHITE) || (photometric == PHOTOMETRIC_MINISBLACK) || (photometric == PHOTOMETRIC_PALETTE)) { + return TRUE; + } else { + return FALSE; + } + break; + case 8: + return TRUE; + case 16: + if(photometric != PHOTOMETRIC_PALETTE) { + return TRUE; + } else { + return FALSE; + } + break; + case 32: + return TRUE; + case 64: + case 128: + if(photometric == PHOTOMETRIC_MINISBLACK) { + return TRUE; + } else { + return FALSE; + } + break; + default: + return FALSE; + } +} + +static TIFFLoadMethod +FindLoadMethod(TIFF *tif, FREE_IMAGE_TYPE image_type, int flags) { + uint16 bitspersample = (uint16)-1; + uint16 samplesperpixel = (uint16)-1; + uint16 photometric = (uint16)-1; + uint16 planar_config = (uint16)-1; + + TIFFLoadMethod loadMethod = LoadAsGenericStrip; + + TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric); + TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); + TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample); + TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planar_config); + + BOOL bIsTiled = (TIFFIsTiled(tif) == 0) ? FALSE:TRUE; + + switch(photometric) { + // convert to 24 or 32 bits RGB if the image is full color + case PHOTOMETRIC_RGB: + if((image_type == FIT_RGB16) || (image_type == FIT_RGBA16)) { + // load 48-bit RGB and 64-bit RGBA without conversion + loadMethod = LoadAsGenericStrip; + } + else if(image_type == FIT_RGBF) { + if((samplesperpixel == 3) && (bitspersample == 16)) { + // load 3 x 16-bit half as RGBF + loadMethod = LoadAsHalfFloat; + } + } + break; + case PHOTOMETRIC_YCBCR: + case PHOTOMETRIC_CIELAB: + case PHOTOMETRIC_ICCLAB: + case PHOTOMETRIC_ITULAB: + loadMethod = LoadAsRBGA; + break; + case PHOTOMETRIC_LOGLUV: + loadMethod = LoadAsLogLuv; + break; + case PHOTOMETRIC_SEPARATED: + // if image is PHOTOMETRIC_SEPARATED _and_ comes with an ICC profile, + // then the image should preserve its original (CMYK) colour model and + // should be read as CMYK (to keep the match of pixel and profile and + // to avoid multiple conversions. Conversion can be done by changing + // the profile from it's original CMYK to an RGB profile with an + // apropriate color management system. Works with non-tiled TIFFs. + if(!bIsTiled) { + loadMethod = LoadAsCMYK; + } + break; + case PHOTOMETRIC_MINISWHITE: + case PHOTOMETRIC_MINISBLACK: + case PHOTOMETRIC_PALETTE: + // When samplesperpixel = 2 and bitspersample = 8, set the image as a + // 8-bit indexed image + 8-bit alpha layer image + // and convert to a 8-bit image with a transparency table + if((samplesperpixel > 1) && (bitspersample == 8)) { + loadMethod = LoadAs8BitTrns; + } else { + loadMethod = LoadAsGenericStrip; + } + break; + default: + loadMethod = LoadAsGenericStrip; + break; + } + + if((loadMethod == LoadAsGenericStrip) && bIsTiled) { + loadMethod = LoadAsTiled; + } + + return loadMethod; +} + +// ========================================================== +// TIFF thumbnail routines +// ========================================================== + +static FIBITMAP * DLL_CALLCONV +Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data); + +/** +Read embedded thumbnail +*/ +static void +ReadThumbnail(FreeImageIO *io, fi_handle handle, void *data, TIFF *tiff, FIBITMAP *dib) { + FIBITMAP* thumbnail = NULL; + + // read exif thumbnail (IFD 1) ... + + uint32 exif_offset = 0; + if(TIFFGetField(tiff, TIFFTAG_EXIFIFD, &exif_offset)) { + + if(TIFFLastDirectory(tiff) != 0) { + // save current position + long tell_pos = io->tell_proc(handle); + tdir_t cur_dir = TIFFCurrentDirectory(tiff); + + // load the thumbnail + int page = 1; + int flags = TIFF_DEFAULT; + thumbnail = Load(io, handle, page, flags, data); + // store the thumbnail (remember to release it later ...) + FreeImage_SetThumbnail(dib, thumbnail); + + // restore current position + io->seek_proc(handle, tell_pos, SEEK_SET); + TIFFSetDirectory(tiff, cur_dir); + } + } + + // ... or read the first subIFD + + if(!thumbnail) { + uint16 subIFD_count = 0; + uint32* subIFD_offsets = NULL; + // ### Theoretically this should also read the first subIFD from a Photoshop-created file with "pyramid". + // It does not however - the tag is there (using Tag Viewer app) but libtiff refuses to read it + if(TIFFGetField(tiff, TIFFTAG_SUBIFD, &subIFD_count, &subIFD_offsets)) { + if(subIFD_count > 0) { + // save current position + long tell_pos = io->tell_proc(handle); + tdir_t cur_dir = TIFFCurrentDirectory(tiff); + if(TIFFSetSubDirectory(tiff, subIFD_offsets[0])) { + // load the thumbnail + int page = -1; + int flags = TIFF_DEFAULT; + thumbnail = Load(io, handle, page, flags, data); + // store the thumbnail (remember to release it later ...) + FreeImage_SetThumbnail(dib, thumbnail); + } + // restore current position + io->seek_proc(handle, tell_pos, SEEK_SET); + TIFFSetDirectory(tiff, cur_dir); + } + } + } + + // ... or read Photoshop thumbnail + + if(!thumbnail) { + uint32 ps_size = 0; + void *ps_data = NULL; + + if(TIFFGetField(tiff, TIFFTAG_PHOTOSHOP, &ps_size, &ps_data)) { + FIMEMORY *handle = FreeImage_OpenMemory((BYTE*)ps_data, ps_size); + + FreeImageIO io; + SetMemoryIO(&io); + + psdParser parser; + parser.ReadImageResources(&io, handle, ps_size); + + FreeImage_SetThumbnail(dib, parser.GetThumbnail()); + + FreeImage_CloseMemory(handle); + } + + } + + // release thumbnail + FreeImage_Unload(thumbnail); +} + +// -------------------------------------------------------------------------- + +static FIBITMAP * DLL_CALLCONV +Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { + if (!handle || !data ) { + return NULL; + } + + TIFF *tif = NULL; + uint32 height = 0; + uint32 width = 0; + uint16 bitspersample = 1; + uint16 samplesperpixel = 1; + uint32 rowsperstrip = (uint32)-1; + uint16 photometric = PHOTOMETRIC_MINISWHITE; + uint16 compression = (uint16)-1; + uint16 planar_config; + + FIBITMAP *dib = NULL; + uint32 iccSize = 0; // ICC profile length + void *iccBuf = NULL; // ICC profile data + + const BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS; + + try { + fi_TIFFIO *fio = (fi_TIFFIO*)data; + tif = fio->tif; + + if (page != -1) { + if (!tif || !TIFFSetDirectory(tif, (tdir_t)page)) { + throw "Error encountered while opening TIFF file"; + } + } + + const BOOL asCMYK = (flags & TIFF_CMYK) == TIFF_CMYK; + + // first, get the photometric, the compression and basic metadata + // --------------------------------------------------------------------------------- + + TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric); + TIFFGetField(tif, TIFFTAG_COMPRESSION, &compression); + + // check for HDR formats + // --------------------------------------------------------------------------------- + + if(photometric == PHOTOMETRIC_LOGLUV) { + // check the compression + if(compression != COMPRESSION_SGILOG && compression != COMPRESSION_SGILOG24) { + throw "Only support SGILOG compressed LogLuv data"; + } + // set decoder to output in IEEE 32-bit float XYZ values + TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_FLOAT); + } + + // --------------------------------------------------------------------------------- + + TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width); + TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height); + TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); + TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample); + TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); + TIFFGetField(tif, TIFFTAG_ICCPROFILE, &iccSize, &iccBuf); + TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planar_config); + + // check for unsupported formats + // --------------------------------------------------------------------------------- + + if(IsValidBitsPerSample(photometric, bitspersample, samplesperpixel) == FALSE) { + FreeImage_OutputMessageProc(s_format_id, + "Unable to handle this format: bitspersample = %d, samplesperpixel = %d, photometric = %d", + (int)bitspersample, (int)samplesperpixel, (int)photometric); + throw (char*)NULL; + } + + // --------------------------------------------------------------------------------- + + // get image data type + + FREE_IMAGE_TYPE image_type = ReadImageType(tif, bitspersample, samplesperpixel); + + // get the most appropriate loading method + + TIFFLoadMethod loadMethod = FindLoadMethod(tif, image_type, flags); + + // --------------------------------------------------------------------------------- + + if(loadMethod == LoadAsRBGA) { + // --------------------------------------------------------------------------------- + // RGB[A] loading using the TIFFReadRGBAImage() API + // --------------------------------------------------------------------------------- + + BOOL has_alpha = FALSE; + + // Read the whole image into one big RGBA buffer and then + // convert it to a DIB. This is using the traditional + // TIFFReadRGBAImage() API that we trust. + + uint32 *raster = NULL; + + if(!header_only) { + + raster = (uint32*)_TIFFmalloc(width * height * sizeof(uint32)); + if (raster == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + // read the image in one chunk into an RGBA array + + if (!TIFFReadRGBAImage(tif, width, height, raster, 1)) { + _TIFFfree(raster); + throw FI_MSG_ERROR_UNSUPPORTED_FORMAT; + } + } + // TIFFReadRGBAImage always deliveres 3 or 4 samples per pixel images + // (RGB or RGBA, see below). Cut-off possibly present channels (additional + // alpha channels) from e.g. Photoshop. Any CMYK(A..) is now treated as RGB, + // any additional alpha channel on RGB(AA..) is lost on conversion to RGB(A) + + if(samplesperpixel > 4) { // TODO Write to Extra Channels + FreeImage_OutputMessageProc(s_format_id, "Warning: %d additional alpha channel(s) ignored", samplesperpixel-4); + samplesperpixel = 4; + } + + // create a new DIB (take care of different samples-per-pixel in case + // of converted CMYK image (RGB conversion is on sample per pixel less) + + if (photometric == PHOTOMETRIC_SEPARATED && samplesperpixel == 4) { + samplesperpixel = 3; + } + + dib = CreateImageType(header_only, image_type, width, height, bitspersample, samplesperpixel); + if (dib == NULL) { + // free the raster pointer and output an error if allocation failed + if(raster) { + _TIFFfree(raster); + } + throw FI_MSG_ERROR_DIB_MEMORY; + } + + // fill in the resolution (english or universal) + + ReadResolution(tif, dib); + + if(!header_only) { + + // read the raster lines and save them in the DIB + // with RGB mode, we have to change the order of the 3 samples RGB + // We use macros for extracting components from the packed ABGR + // form returned by TIFFReadRGBAImage. + + uint32 *row = &raster[0]; + + if (samplesperpixel == 4) { + // 32-bit RGBA + for (uint32 y = 0; y < height; y++) { + BYTE *bits = FreeImage_GetScanLine(dib, y); + for (uint32 x = 0; x < width; x++) { + bits[FI_RGBA_BLUE] = (BYTE)TIFFGetB(row[x]); + bits[FI_RGBA_GREEN] = (BYTE)TIFFGetG(row[x]); + bits[FI_RGBA_RED] = (BYTE)TIFFGetR(row[x]); + bits[FI_RGBA_ALPHA] = (BYTE)TIFFGetA(row[x]); + + if (bits[FI_RGBA_ALPHA] != 0) { + has_alpha = TRUE; + } + + bits += 4; + } + row += width; + } + } else { + // 24-bit RGB + for (uint32 y = 0; y < height; y++) { + BYTE *bits = FreeImage_GetScanLine(dib, y); + for (uint32 x = 0; x < width; x++) { + bits[FI_RGBA_BLUE] = (BYTE)TIFFGetB(row[x]); + bits[FI_RGBA_GREEN] = (BYTE)TIFFGetG(row[x]); + bits[FI_RGBA_RED] = (BYTE)TIFFGetR(row[x]); + + bits += 3; + } + row += width; + } + } + + _TIFFfree(raster); + } + + // ### Not correct when header only + FreeImage_SetTransparent(dib, has_alpha); + + } else if(loadMethod == LoadAs8BitTrns) { + // --------------------------------------------------------------------------------- + // 8-bit + 8-bit alpha layer loading + // --------------------------------------------------------------------------------- + + // create a new 8-bit DIB + dib = CreateImageType(header_only, image_type, width, height, bitspersample, MIN(2, samplesperpixel)); + if (dib == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + // fill in the resolution (english or universal) + + ReadResolution(tif, dib); + + // set up the colormap based on photometric + + ReadPalette(tif, photometric, bitspersample, dib); + + // calculate the line + pitch (separate for scr & dest) + + const tsize_t src_line = TIFFScanlineSize(tif); + // here, the pitch is 2x less than the original as we only keep the first layer + int dst_pitch = FreeImage_GetPitch(dib); + + // transparency table for 8-bit + 8-bit alpha images + + BYTE trns[256]; + // clear the transparency table + memset(trns, 0xFF, 256 * sizeof(BYTE)); + + // In the tiff file the lines are saved from up to down + // In a DIB the lines must be saved from down to up + + BYTE *bits = FreeImage_GetScanLine(dib, height - 1); + + // read the tiff lines and save them in the DIB + + if(planar_config == PLANARCONFIG_CONTIG && !header_only) { + + BYTE *buf = (BYTE*)malloc(TIFFStripSize(tif) * sizeof(BYTE)); + if(buf == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + for (uint32 y = 0; y < height; y += rowsperstrip) { + int32 nrow = (y + rowsperstrip > height ? height - y : rowsperstrip); + + if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, 0), buf, nrow * src_line) == -1) { + free(buf); + throw FI_MSG_ERROR_PARSING; + } + for (int l = 0; l < nrow; l++) { + BYTE *p = bits; + BYTE *b = buf + l * src_line; + + for(uint32 x = 0; x < (uint32)(src_line / samplesperpixel); x++) { + // copy the 8-bit layer + *p = b[0]; + // convert the 8-bit alpha layer to a trns table + trns[ b[0] ] = b[1]; + + p++; + b += samplesperpixel; + } + bits -= dst_pitch; + } + } + + free(buf); + } + else if(planar_config == PLANARCONFIG_SEPARATE && !header_only) { + tsize_t stripsize = TIFFStripSize(tif) * sizeof(BYTE); + BYTE *buf = (BYTE*)malloc(2 * stripsize); + if(buf == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + BYTE *grey = buf; + BYTE *alpha = buf + stripsize; + + for (uint32 y = 0; y < height; y += rowsperstrip) { + int32 nrow = (y + rowsperstrip > height ? height - y : rowsperstrip); + + if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, 0), grey, nrow * src_line) == -1) { + free(buf); + throw FI_MSG_ERROR_PARSING; + } + if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, 1), alpha, nrow * src_line) == -1) { + free(buf); + throw FI_MSG_ERROR_PARSING; + } + + for (int l = 0; l < nrow; l++) { + BYTE *p = bits; + BYTE *g = grey + l * src_line; + BYTE *a = alpha + l * src_line; + + for(uint32 x = 0; x < (uint32)(src_line); x++) { + // copy the 8-bit layer + *p = g[0]; + // convert the 8-bit alpha layer to a trns table + trns[ g[0] ] = a[0]; + + p++; + g++; + a++; + } + bits -= dst_pitch; + } + } + + free(buf); + + } + + FreeImage_SetTransparencyTable(dib, &trns[0], 256); + FreeImage_SetTransparent(dib, TRUE); + + } else if(loadMethod == LoadAsCMYK) { + // --------------------------------------------------------------------------------- + // CMYK loading + // --------------------------------------------------------------------------------- + + // At this place, samplesperpixel could be > 4, esp. when a CMYK(A) format + // is recognized. Where all other formats are handled straight-forward, this + // format has to be handled special + + BOOL isCMYKA = (photometric == PHOTOMETRIC_SEPARATED) && (samplesperpixel > 4); + + // We use a temp dib to store the alpha for the CMYKA to RGBA conversion + // NOTE this is until we have Extra channels implementation. + // Also then it will be possible to merge LoadAsCMYK with LoadAsGenericStrip + + FIBITMAP *alpha = NULL; + unsigned alpha_pitch = 0; + BYTE *alpha_bits = NULL; + unsigned alpha_Bpp = 0; + + if(isCMYKA && !asCMYK && !header_only) { + if(bitspersample == 16) { + alpha = FreeImage_AllocateT(FIT_UINT16, width, height); + } else if (bitspersample == 8) { + alpha = FreeImage_Allocate(width, height, 8); + } + + if(!alpha) { + FreeImage_OutputMessageProc(s_format_id, "Failed to allocate temporary alpha channel"); + } else { + alpha_bits = FreeImage_GetScanLine(alpha, height - 1); + alpha_pitch = FreeImage_GetPitch(alpha); + alpha_Bpp = FreeImage_GetBPP(alpha) / 8; + } + + } + + // create a new DIB + const uint16 chCount = MIN(samplesperpixel, 4); + dib = CreateImageType(header_only, image_type, width, height, bitspersample, chCount); + if (dib == NULL) { + FreeImage_Unload(alpha); + throw FI_MSG_ERROR_MEMORY; + } + + // fill in the resolution (english or universal) + + ReadResolution(tif, dib); + + if(!header_only) { + + // calculate the line + pitch (separate for scr & dest) + + const tsize_t src_line = TIFFScanlineSize(tif); + const tsize_t dst_line = FreeImage_GetLine(dib); + const unsigned dib_pitch = FreeImage_GetPitch(dib); + const unsigned dibBpp = FreeImage_GetBPP(dib) / 8; + const unsigned Bpc = dibBpp / chCount; + const unsigned srcBpp = bitspersample * samplesperpixel / 8; + + assert(Bpc <= 2); //< CMYK is only BYTE or SHORT + + // In the tiff file the lines are save from up to down + // In a DIB the lines must be saved from down to up + + BYTE *bits = FreeImage_GetScanLine(dib, height - 1); + + // read the tiff lines and save them in the DIB + + BYTE *buf = (BYTE*)malloc(TIFFStripSize(tif) * sizeof(BYTE)); + if(buf == NULL) { + FreeImage_Unload(alpha); + throw FI_MSG_ERROR_MEMORY; + } + + if(planar_config == PLANARCONFIG_CONTIG) { + + // - loop for strip blocks - + + for (uint32 y = 0; y < height; y += rowsperstrip) { + const int32 strips = (y + rowsperstrip > height ? height - y : rowsperstrip); + + if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, 0), buf, strips * src_line) == -1) { + free(buf); + FreeImage_Unload(alpha); + throw FI_MSG_ERROR_PARSING; + } + + // - loop for strips - + + if(src_line != dst_line) { + // CMYKA+ + if(alpha) { + for (int l = 0; l < strips; l++) { + for(BYTE *pixel = bits, *al_pixel = alpha_bits, *src_pixel = buf + l * src_line; pixel < bits + dib_pitch; pixel += dibBpp, al_pixel += alpha_Bpp, src_pixel += srcBpp) { + // copy pixel byte by byte + BYTE b = 0; + for( ; b < dibBpp; ++b) { + pixel[b] = src_pixel[b]; + } + // TODO write the remaining bytes to extra channel(s) + + // HACK write the first alpha to a separate dib (assume BYTE or WORD) + al_pixel[0] = src_pixel[b]; + if(Bpc > 1) { + al_pixel[1] = src_pixel[b + 1]; + } + + } + bits -= dib_pitch; + alpha_bits -= alpha_pitch; + } + } + else { + // alpha/extra channels alloc failed + for (int l = 0; l < strips; l++) { + for(BYTE* pixel = bits, * src_pixel = buf + l * src_line; pixel < bits + dst_line; pixel += dibBpp, src_pixel += srcBpp) { + AssignPixel(pixel, src_pixel, dibBpp); + } + bits -= dib_pitch; + } + } + } + else { + // CMYK to CMYK + for (int l = 0; l < strips; l++) { + BYTE *b = buf + l * src_line; + memcpy(bits, b, src_line); + bits -= dib_pitch; + } + } + + } // height + + } + else if(planar_config == PLANARCONFIG_SEPARATE) { + + BYTE *dib_strip = bits; + BYTE *al_strip = alpha_bits; + + // - loop for strip blocks - + + for (uint32 y = 0; y < height; y += rowsperstrip) { + const int32 strips = (y + rowsperstrip > height ? height - y : rowsperstrip); + + // - loop for channels (planes) - + + for(uint16 sample = 0; sample < samplesperpixel; sample++) { + + if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, sample), buf, strips * src_line) == -1) { + free(buf); + FreeImage_Unload(alpha); + throw FI_MSG_ERROR_PARSING; + } + + BYTE *dst_strip = dib_strip; + unsigned dst_pitch = dib_pitch; + uint16 ch = sample; + unsigned Bpp = dibBpp; + + if(sample >= chCount) { + // TODO Write to Extra Channel + + // HACK redirect write to temp alpha + if(alpha && sample == chCount) { + + dst_strip = al_strip; + dst_pitch = alpha_pitch; + + ch = 0; + Bpp = alpha_Bpp; + } + else { + break; + } + } + + const unsigned channelOffset = ch * Bpc; + + // - loop for strips in block - + + BYTE *src_line_begin = buf; + BYTE *dst_line_begin = dst_strip; + for (int l = 0; l < strips; l++, src_line_begin += src_line, dst_line_begin -= dst_pitch ) { + // - loop for pixels in strip - + + const BYTE* const src_line_end = src_line_begin + src_line; + for (BYTE *src_bits = src_line_begin, * dst_bits = dst_line_begin; src_bits < src_line_end; src_bits += Bpc, dst_bits += Bpp) { + AssignPixel(dst_bits + channelOffset, src_bits, Bpc); + } // line + + } // strips + + } // channels + + // done with a strip block, incr to the next + dib_strip -= strips * dib_pitch; + al_strip -= strips * alpha_pitch; + + } //< height + + } + + free(buf); + + if(!asCMYK) { + ConvertCMYKtoRGBA(dib); + + // The ICC Profile is invalid, clear it + iccSize = 0; + iccBuf = NULL; + + if(isCMYKA) { + // HACK until we have Extra channels. (ConvertCMYKtoRGBA will then do the work) + + FreeImage_SetChannel(dib, alpha, FICC_ALPHA); + FreeImage_Unload(alpha); + alpha = NULL; + } + else { + FIBITMAP *t = RemoveAlphaChannel(dib); + if(t) { + FreeImage_Unload(dib); + dib = t; + } + else { + FreeImage_OutputMessageProc(s_format_id, "Cannot allocate memory for buffer. CMYK image converted to RGB + pending Alpha"); + } + } + } + + } // !header_only + + } else if(loadMethod == LoadAsGenericStrip) { + // --------------------------------------------------------------------------------- + // Generic loading + // --------------------------------------------------------------------------------- + + // create a new DIB + const uint16 chCount = MIN(samplesperpixel, 4); + dib = CreateImageType(header_only, image_type, width, height, bitspersample, chCount); + if (dib == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + // fill in the resolution (english or universal) + + ReadResolution(tif, dib); + + // set up the colormap based on photometric + + ReadPalette(tif, photometric, bitspersample, dib); + + if(!header_only) { + // calculate the line + pitch (separate for scr & dest) + + const tsize_t src_line = TIFFScanlineSize(tif); + const tsize_t dst_line = FreeImage_GetLine(dib); + const unsigned dst_pitch = FreeImage_GetPitch(dib); + const unsigned Bpp = FreeImage_GetBPP(dib) / 8; + const unsigned srcBpp = bitspersample * samplesperpixel / 8; + + // In the tiff file the lines are save from up to down + // In a DIB the lines must be saved from down to up + + BYTE *bits = FreeImage_GetScanLine(dib, height - 1); + + // read the tiff lines and save them in the DIB + + BYTE *buf = (BYTE*)malloc(TIFFStripSize(tif) * sizeof(BYTE)); + if(buf == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + BOOL bThrowMessage = FALSE; + + if(planar_config == PLANARCONFIG_CONTIG) { + + for (uint32 y = 0; y < height; y += rowsperstrip) { + int32 strips = (y + rowsperstrip > height ? height - y : rowsperstrip); + + if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, 0), buf, strips * src_line) == -1) { + // ignore errors as they can be frequent and not really valid errors, especially with fax images + bThrowMessage = TRUE; + /* + free(buf); + throw FI_MSG_ERROR_PARSING; + */ + } + if(src_line == dst_line) { + // channel count match + for (int l = 0; l < strips; l++) { + memcpy(bits, buf + l * src_line, src_line); + bits -= dst_pitch; + } + } + else { + for (int l = 0; l < strips; l++) { + for(BYTE *pixel = bits, *src_pixel = buf + l * src_line; pixel < bits + dst_pitch; pixel += Bpp, src_pixel += srcBpp) { + AssignPixel(pixel, src_pixel, Bpp); + } + bits -= dst_pitch; + } + } + } + } + else if(planar_config == PLANARCONFIG_SEPARATE) { + + const unsigned Bpc = bitspersample / 8; + BYTE* dib_strip = bits; + // - loop for strip blocks - + + for (uint32 y = 0; y < height; y += rowsperstrip) { + const int32 strips = (y + rowsperstrip > height ? height - y : rowsperstrip); + + // - loop for channels (planes) - + + for(uint16 sample = 0; sample < samplesperpixel; sample++) { + + if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, sample), buf, strips * src_line) == -1) { + // ignore errors as they can be frequent and not really valid errors, especially with fax images + bThrowMessage = TRUE; + } + + if(sample >= chCount) { + // TODO Write to Extra Channel + break; + } + + const unsigned channelOffset = sample * Bpc; + + // - loop for strips in block - + + BYTE* src_line_begin = buf; + BYTE* dst_line_begin = dib_strip; + for (int l = 0; l < strips; l++, src_line_begin += src_line, dst_line_begin -= dst_pitch ) { + + // - loop for pixels in strip - + + const BYTE* const src_line_end = src_line_begin + src_line; + + for (BYTE* src_bits = src_line_begin, * dst_bits = dst_line_begin; src_bits < src_line_end; src_bits += Bpc, dst_bits += Bpp) { + // actually assigns channel + AssignPixel(dst_bits + channelOffset, src_bits, Bpc); + } // line + + } // strips + + } // channels + + // done with a strip block, incr to the next + dib_strip -= strips * dst_pitch; + + } // height + + } + free(buf); + + if(bThrowMessage) { + FreeImage_OutputMessageProc(s_format_id, "Warning: parsing error. Image may be incomplete or contain invalid data !"); + } + +#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR + SwapRedBlue32(dib); +#endif + + } // !header only + + } else if(loadMethod == LoadAsTiled) { + // --------------------------------------------------------------------------------- + // Tiled image loading + // --------------------------------------------------------------------------------- + + uint32 tileWidth, tileHeight; + uint32 src_line = 0; + + // create a new DIB + dib = CreateImageType( header_only, image_type, width, height, bitspersample, samplesperpixel); + if (dib == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + // fill in the resolution (english or universal) + + ReadResolution(tif, dib); + + // set up the colormap based on photometric + + ReadPalette(tif, photometric, bitspersample, dib); + + // get the tile geometry + if(!TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tileWidth) || !TIFFGetField(tif, TIFFTAG_TILELENGTH, &tileHeight)) { + throw "Invalid tiled TIFF image"; + } + + // read the tiff lines and save them in the DIB + + if(planar_config == PLANARCONFIG_CONTIG && !header_only) { + + // get the maximum number of bytes required to contain a tile + tsize_t tileSize = TIFFTileSize(tif); + + // allocate tile buffer + BYTE *tileBuffer = (BYTE*)malloc(tileSize * sizeof(BYTE)); + if(tileBuffer == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + // calculate src line and dst pitch + int dst_pitch = FreeImage_GetPitch(dib); + int tileRowSize = TIFFTileRowSize(tif); + int imageRowSize = TIFFScanlineSize(tif); + + + // In the tiff file the lines are saved from up to down + // In a DIB the lines must be saved from down to up + + BYTE *bits = FreeImage_GetScanLine(dib, height - 1); + + uint32 x, y, rowSize; + for (y = 0; y < height; y += tileHeight) { + int32 nrows = (y + tileHeight > height ? height - y : tileHeight); + + for (x = 0, rowSize = 0; x < width; x += tileWidth, rowSize += tileRowSize) { + memset(tileBuffer, 0, tileSize); + + // read one tile + if (TIFFReadTile(tif, tileBuffer, x, y, 0, 0) < 0) { + free(tileBuffer); + throw "Corrupted tiled TIFF file"; + } + // convert to strip + if(x + tileWidth > width) { + src_line = imageRowSize - rowSize; + } else { + src_line = tileRowSize; + } + BYTE *src_bits = tileBuffer; + BYTE *dst_bits = bits + rowSize; + for(int k = 0; k < nrows; k++) { + memcpy(dst_bits, src_bits, src_line); + src_bits += tileRowSize; + dst_bits -= dst_pitch; + } + } + + bits -= nrows * dst_pitch; + } + +#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR + SwapRedBlue32(dib); +#endif + free(tileBuffer); + } + else if(planar_config == PLANARCONFIG_SEPARATE) { + throw "Separated tiled TIFF images are not supported"; + } + + + } else if(loadMethod == LoadAsLogLuv) { + // --------------------------------------------------------------------------------- + // RGBF LogLuv compressed loading + // --------------------------------------------------------------------------------- + + double stonits; // input conversion to nits + if (!TIFFGetField(tif, TIFFTAG_STONITS, &stonits)) { + stonits = 1; + } + + // create a new DIB + dib = CreateImageType(header_only, image_type, width, height, bitspersample, samplesperpixel); + if (dib == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + // fill in the resolution (english or universal) + + ReadResolution(tif, dib); + + if(planar_config == PLANARCONFIG_CONTIG && !header_only) { + // calculate the line + pitch (separate for scr & dest) + + tsize_t src_line = TIFFScanlineSize(tif); + int dst_pitch = FreeImage_GetPitch(dib); + + // In the tiff file the lines are save from up to down + // In a DIB the lines must be saved from down to up + + BYTE *bits = FreeImage_GetScanLine(dib, height - 1); + + // read the tiff lines and save them in the DIB + + BYTE *buf = (BYTE*)malloc(TIFFStripSize(tif) * sizeof(BYTE)); + if(buf == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + for (uint32 y = 0; y < height; y += rowsperstrip) { + int32 nrow = (y + rowsperstrip > height ? height - y : rowsperstrip); + + if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, 0), buf, nrow * src_line) == -1) { + free(buf); + throw FI_MSG_ERROR_PARSING; + } + // convert from XYZ to RGB + for (int l = 0; l < nrow; l++) { + tiff_ConvertLineXYZToRGB(bits, buf + l * src_line, stonits, width); + bits -= dst_pitch; + } + } + + free(buf); + } + else if(planar_config == PLANARCONFIG_SEPARATE) { + // this cannot happen according to the LogLuv specification + throw "Unable to handle PLANARCONFIG_SEPARATE LogLuv images"; + } + + } else if(loadMethod == LoadAsHalfFloat) { + // --------------------------------------------------------------------------------- + // RGBF loading from a half format + // --------------------------------------------------------------------------------- + + // create a new DIB + dib = CreateImageType(header_only, image_type, width, height, bitspersample, samplesperpixel); + if (dib == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + // fill in the resolution (english or universal) + + ReadResolution(tif, dib); + + if(!header_only) { + + // calculate the line + pitch (separate for scr & dest) + + tsize_t src_line = TIFFScanlineSize(tif); + unsigned dst_pitch = FreeImage_GetPitch(dib); + + // In the tiff file the lines are save from up to down + // In a DIB the lines must be saved from down to up + + BYTE *bits = FreeImage_GetScanLine(dib, height - 1); + + // read the tiff lines and save them in the DIB + + if(planar_config == PLANARCONFIG_CONTIG) { + + BYTE *buf = (BYTE*)malloc(TIFFStripSize(tif) * sizeof(BYTE)); + if(buf == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + for (uint32 y = 0; y < height; y += rowsperstrip) { + uint32 nrow = (y + rowsperstrip > height ? height - y : rowsperstrip); + + if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, y, 0), buf, nrow * src_line) == -1) { + free(buf); + throw FI_MSG_ERROR_PARSING; + } + + // convert from half (16-bit) to float (32-bit) + // !!! use OpenEXR half helper class + + half half_value; + + for (uint32 l = 0; l < nrow; l++) { + WORD *src_pixel = (WORD*)(buf + l * src_line); + float *dst_pixel = (float*)bits; + + for(tsize_t x = 0; x < (tsize_t)(src_line / sizeof(WORD)); x++) { + half_value.setBits(src_pixel[x]); + dst_pixel[x] = half_value; + } + + bits -= dst_pitch; + } + } + + free(buf); + } + else if(planar_config == PLANARCONFIG_SEPARATE) { + // this use case was never encountered yet + throw "Unable to handle PLANARCONFIG_SEPARATE RGB half float images"; + } + + } // !header only + + } else { + // --------------------------------------------------------------------------------- + // Unknown or unsupported format + // --------------------------------------------------------------------------------- + + throw FI_MSG_ERROR_UNSUPPORTED_FORMAT; + } + + // copy ICC profile data (must be done after FreeImage_Allocate) + + FreeImage_CreateICCProfile(dib, iccBuf, iccSize); + if (photometric == PHOTOMETRIC_SEPARATED && asCMYK) { + FreeImage_GetICCProfile(dib)->flags |= FIICC_COLOR_IS_CMYK; + } + + // copy TIFF metadata (must be done after FreeImage_Allocate) + + ReadMetadata(tif, dib); + + // copy TIFF thumbnail (must be done after FreeImage_Allocate) + + ReadThumbnail(io, handle, data, tif, dib); + + return (FIBITMAP *)dib; + + } catch (const char *message) { + if(dib) { + FreeImage_Unload(dib); + } + if(message) { + FreeImage_OutputMessageProc(s_format_id, message); + } + return NULL; + } + +} + +// -------------------------------------------------------------------------- + +static BOOL +SaveOneTIFF(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data, unsigned ifd, unsigned ifdCount) { + if (!dib || !handle || !data) { + return FALSE; + } + + try { + fi_TIFFIO *fio = (fi_TIFFIO*)data; + TIFF *out = fio->tif; + + const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); + + const uint32 width = FreeImage_GetWidth(dib); + const uint32 height = FreeImage_GetHeight(dib); + const uint16 bitsperpixel = (uint16)FreeImage_GetBPP(dib); + + const FIICCPROFILE* iccProfile = FreeImage_GetICCProfile(dib); + + // setup out-variables based on dib and flag options + + uint16 bitspersample; + uint16 samplesperpixel; + uint16 photometric; + + if(image_type == FIT_BITMAP) { + // standard image: 1-, 4-, 8-, 16-, 24-, 32-bit + + samplesperpixel = ((bitsperpixel == 24) ? 3 : ((bitsperpixel == 32) ? 4 : 1)); + bitspersample = bitsperpixel / samplesperpixel; + photometric = GetPhotometric(dib); + + if((bitsperpixel == 8) && FreeImage_IsTransparent(dib)) { + // 8-bit transparent picture : convert later to 8-bit + 8-bit alpha + samplesperpixel = 2; + bitspersample = 8; + } + else if(bitsperpixel == 32) { + // 32-bit images : check for CMYK or alpha transparency + + if((((iccProfile->flags & FIICC_COLOR_IS_CMYK) == FIICC_COLOR_IS_CMYK) || ((flags & TIFF_CMYK) == TIFF_CMYK))) { + // CMYK support + photometric = PHOTOMETRIC_SEPARATED; + TIFFSetField(out, TIFFTAG_INKSET, INKSET_CMYK); + TIFFSetField(out, TIFFTAG_NUMBEROFINKS, 4); + } + else if(photometric == PHOTOMETRIC_RGB) { + // transparency mask support + uint16 sampleinfo[1]; + // unassociated alpha data is transparency information + sampleinfo[0] = EXTRASAMPLE_UNASSALPHA; + TIFFSetField(out, TIFFTAG_EXTRASAMPLES, 1, sampleinfo); + } + } + } else if(image_type == FIT_RGB16) { + // 48-bit RGB + + samplesperpixel = 3; + bitspersample = bitsperpixel / samplesperpixel; + photometric = PHOTOMETRIC_RGB; + } else if(image_type == FIT_RGBA16) { + // 64-bit RGBA + + samplesperpixel = 4; + bitspersample = bitsperpixel / samplesperpixel; + if((((iccProfile->flags & FIICC_COLOR_IS_CMYK) == FIICC_COLOR_IS_CMYK) || ((flags & TIFF_CMYK) == TIFF_CMYK))) { + // CMYK support + photometric = PHOTOMETRIC_SEPARATED; + TIFFSetField(out, TIFFTAG_INKSET, INKSET_CMYK); + TIFFSetField(out, TIFFTAG_NUMBEROFINKS, 4); + } + else { + photometric = PHOTOMETRIC_RGB; + // transparency mask support + uint16 sampleinfo[1]; + // unassociated alpha data is transparency information + sampleinfo[0] = EXTRASAMPLE_UNASSALPHA; + TIFFSetField(out, TIFFTAG_EXTRASAMPLES, 1, sampleinfo); + } + } else if(image_type == FIT_RGBF) { + // 96-bit RGBF => store with a LogLuv encoding ? + + samplesperpixel = 3; + bitspersample = bitsperpixel / samplesperpixel; + // the library converts to and from floating-point XYZ CIE values + if((flags & TIFF_LOGLUV) == TIFF_LOGLUV) { + photometric = PHOTOMETRIC_LOGLUV; + TIFFSetField(out, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_FLOAT); + // TIFFSetField(out, TIFFTAG_STONITS, 1.0); // assume unknown + } + else { + // store with default compression (LZW) or with input compression flag + photometric = PHOTOMETRIC_RGB; + } + + } else if (image_type == FIT_RGBAF) { + // 128-bit RGBAF => store with default compression (LZW) or with input compression flag + + samplesperpixel = 4; + bitspersample = bitsperpixel / samplesperpixel; + photometric = PHOTOMETRIC_RGB; + } else { + // special image type (int, long, double, ...) + + samplesperpixel = 1; + bitspersample = bitsperpixel; + photometric = PHOTOMETRIC_MINISBLACK; + } + + // set image data type + + WriteImageType(out, image_type); + + // write possible ICC profile + + if (iccProfile->size && iccProfile->data) { + TIFFSetField(out, TIFFTAG_ICCPROFILE, iccProfile->size, iccProfile->data); + } + + // handle standard width/height/bpp stuff + + TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width); + TIFFSetField(out, TIFFTAG_IMAGELENGTH, height); + TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel); + TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, bitspersample); + TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric); + TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); // single image plane + TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); + TIFFSetField(out, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB); + TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, (uint32) -1)); + + // handle metrics + + WriteResolution(out, dib); + + // multi-paging + + if (page >= 0) { + char page_number[20]; + sprintf(page_number, "Page %d", page); + + TIFFSetField(out, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE); + TIFFSetField(out, TIFFTAG_PAGENUMBER, (uint16)page, (uint16)0); + TIFFSetField(out, TIFFTAG_PAGENAME, page_number); + + } else { + // is it a thumbnail ? + TIFFSetField(out, TIFFTAG_SUBFILETYPE, (ifd == 0) ? 0 : FILETYPE_REDUCEDIMAGE); + } + + // palettes (image colormaps are automatically scaled to 16-bits) + + if (photometric == PHOTOMETRIC_PALETTE) { + uint16 *r, *g, *b; + uint16 nColors = (uint16)FreeImage_GetColorsUsed(dib); + RGBQUAD *pal = FreeImage_GetPalette(dib); + + r = (uint16 *) _TIFFmalloc(sizeof(uint16) * 3 * nColors); + if(r == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + g = r + nColors; + b = g + nColors; + + for (int i = nColors - 1; i >= 0; i--) { + r[i] = SCALE((uint16)pal[i].rgbRed); + g[i] = SCALE((uint16)pal[i].rgbGreen); + b[i] = SCALE((uint16)pal[i].rgbBlue); + } + + TIFFSetField(out, TIFFTAG_COLORMAP, r, g, b); + + _TIFFfree(r); + } + + // compression tag + + WriteCompression(out, bitspersample, samplesperpixel, photometric, flags); + + // metadata + + WriteMetadata(out, dib); + + // thumbnail tag + + if((ifd == 0) && (ifdCount > 1)) { + uint32 diroff[1]; + diroff[0] = 0; + TIFFSetField(out, TIFFTAG_SUBIFD, 1, diroff); + } + + // read the DIB lines from bottom to top + // and save them in the TIF + // ------------------------------------- + + const uint32 pitch = FreeImage_GetPitch(dib); + + if(image_type == FIT_BITMAP) { + // standard bitmap type + + switch(bitsperpixel) { + case 1 : + case 4 : + case 8 : + { + if((bitsperpixel == 8) && FreeImage_IsTransparent(dib)) { + // 8-bit transparent picture : convert to 8-bit + 8-bit alpha + + // get the transparency table + BYTE *trns = FreeImage_GetTransparencyTable(dib); + + BYTE *buffer = (BYTE *)malloc(2 * width * sizeof(BYTE)); + if(buffer == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + for (int y = height - 1; y >= 0; y--) { + BYTE *bits = FreeImage_GetScanLine(dib, y); + + BYTE *p = bits, *b = buffer; + + for(uint32 x = 0; x < width; x++) { + // copy the 8-bit layer + b[0] = *p; + // convert the trns table to a 8-bit alpha layer + b[1] = trns[ b[0] ]; + + p++; + b += samplesperpixel; + } + + // write the scanline to disc + + TIFFWriteScanline(out, buffer, height - y - 1, 0); + } + + free(buffer); + } + else { + // other cases + BYTE *buffer = (BYTE *)malloc(pitch * sizeof(BYTE)); + if(buffer == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + for (uint32 y = 0; y < height; y++) { + // get a copy of the scanline + memcpy(buffer, FreeImage_GetScanLine(dib, height - y - 1), pitch); + // write the scanline to disc + TIFFWriteScanline(out, buffer, y, 0); + } + free(buffer); + } + + break; + } + + case 24: + case 32: + { + BYTE *buffer = (BYTE *)malloc(pitch * sizeof(BYTE)); + if(buffer == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + for (uint32 y = 0; y < height; y++) { + // get a copy of the scanline + + memcpy(buffer, FreeImage_GetScanLine(dib, height - y - 1), pitch); + +#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR + if (photometric != PHOTOMETRIC_SEPARATED) { + // TIFFs store color data RGB(A) instead of BGR(A) + + BYTE *pBuf = buffer; + + for (uint32 x = 0; x < width; x++) { + INPLACESWAP(pBuf[0], pBuf[2]); + pBuf += samplesperpixel; + } + } +#endif + // write the scanline to disc + + TIFFWriteScanline(out, buffer, y, 0); + } + + free(buffer); + + break; + } + }//< switch (bitsperpixel) + + } else if(image_type == FIT_RGBF && (flags & TIFF_LOGLUV) == TIFF_LOGLUV) { + // RGBF image => store as XYZ using a LogLuv encoding + + BYTE *buffer = (BYTE *)malloc(pitch * sizeof(BYTE)); + if(buffer == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + for (uint32 y = 0; y < height; y++) { + // get a copy of the scanline and convert from RGB to XYZ + tiff_ConvertLineRGBToXYZ(buffer, FreeImage_GetScanLine(dib, height - y - 1), width); + // write the scanline to disc + TIFFWriteScanline(out, buffer, y, 0); + } + free(buffer); + } else { + // just dump the dib (tiff supports all dib types) + + BYTE *buffer = (BYTE *)malloc(pitch * sizeof(BYTE)); + if(buffer == NULL) { + throw FI_MSG_ERROR_MEMORY; + } + + for (uint32 y = 0; y < height; y++) { + // get a copy of the scanline + memcpy(buffer, FreeImage_GetScanLine(dib, height - y - 1), pitch); + // write the scanline to disc + TIFFWriteScanline(out, buffer, y, 0); + } + free(buffer); + } + + // write out the directory tag if we wrote a page other than -1 or if we have a thumbnail to write later + + if( (page >= 0) || ((ifd == 0) && (ifdCount > 1)) ) { + TIFFWriteDirectory(out); + // else: TIFFClose will WriteDirectory + } + + return TRUE; + + } catch(const char *text) { + FreeImage_OutputMessageProc(s_format_id, text); + return FALSE; + } +} + +static BOOL DLL_CALLCONV +Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) { + BOOL bResult = FALSE; + + // handle thumbnail as SubIFD + const BOOL bHasThumbnail = (FreeImage_GetThumbnail(dib) != NULL); + const unsigned ifdCount = bHasThumbnail ? 2 : 1; + + FIBITMAP *bitmap = dib; + + for(unsigned ifd = 0; ifd < ifdCount; ifd++) { + // redirect dib to thumbnail for the second pass + if(ifd == 1) { + bitmap = FreeImage_GetThumbnail(dib); + } + + bResult = SaveOneTIFF(io, bitmap, handle, page, flags, data, ifd, ifdCount); + if(!bResult) { + return FALSE; + } + } + + return bResult; +} + +// ========================================================== +// Init +// ========================================================== + +void DLL_CALLCONV +InitTIFF(Plugin *plugin, int format_id) { + s_format_id = format_id; + + plugin->format_proc = Format; + plugin->description_proc = Description; + plugin->extension_proc = Extension; + plugin->regexpr_proc = RegExpr; + plugin->open_proc = Open; + plugin->close_proc = Close; + plugin->pagecount_proc = PageCount; + plugin->pagecapability_proc = NULL; + plugin->load_proc = Load; + plugin->save_proc = Save; + plugin->validate_proc = Validate; + plugin->mime_proc = MimeType; + plugin->supports_export_bpp_proc = SupportsExportDepth; + plugin->supports_export_type_proc = SupportsExportType; + plugin->supports_icc_profiles_proc = SupportsICCProfiles; + plugin->supports_no_pixels_proc = SupportsNoPixels; +} diff --git a/Source/LibTIFF/_FI_3151_XTIFF.cpp b/Source/LibTIFF/_FI_3151_XTIFF.cpp index c9bb19d..f7d3890 100644 --- a/Source/LibTIFF/_FI_3151_XTIFF.cpp +++ b/Source/LibTIFF/_FI_3151_XTIFF.cpp @@ -1,664 +1,664 @@ -// ========================================================== -// Metadata functions implementation -// Extended TIFF Directory GEO Tag Support -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// - Thorsten Radde (support@IdealSoftware.com) -// - Berend Engelbrecht (softwarecave@users.sourceforge.net) -// - Mihail Naydenov (mnaydenov@users.sourceforge.net) -// -// Based on the LibTIFF xtiffio sample and on LibGeoTIFF -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#ifdef _MSC_VER -#pragma warning (disable : 4786) // identifier was truncated to 'number' characters -#endif - -#include "../LibTIFF/tiffiop.h" - -#include "FreeImage.h" -#include "Utilities.h" -#include "FreeImageTag.h" -#include "FIRational.h" - -// ---------------------------------------------------------- -// Extended TIFF Directory GEO Tag Support -// ---------------------------------------------------------- - -/** - Tiff info structure. - Entry format: - { TAGNUMBER, ReadCount, WriteCount, DataType, FIELDNUM, OkToChange, PassDirCountOnSet, AsciiName } - - For ReadCount, WriteCount, -1 = unknown. -*/ -static const TIFFFieldInfo xtiffFieldInfo[] = { - { TIFFTAG_GEOPIXELSCALE, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoPixelScale" }, - { TIFFTAG_INTERGRAPH_MATRIX, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "Intergraph TransformationMatrix" }, - { TIFFTAG_GEOTRANSMATRIX, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoTransformationMatrix" }, - { TIFFTAG_GEOTIEPOINTS, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoTiePoints" }, - { TIFFTAG_GEOKEYDIRECTORY,-1,-1, TIFF_SHORT, FIELD_CUSTOM, TRUE, TRUE, "GeoKeyDirectory" }, - { TIFFTAG_GEODOUBLEPARAMS, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoDoubleParams" }, - { TIFFTAG_GEOASCIIPARAMS, -1, -1, TIFF_ASCII, FIELD_CUSTOM, TRUE, FALSE, "GeoASCIIParams" }, - { TIFFTAG_JPL_CARTO_IFD, 1, 1, TIFF_LONG, FIELD_CUSTOM, TRUE, TRUE, "JPL Carto IFD offset" } /** Don't use this! **/ -}; - -static void -_XTIFFLocalDefaultDirectory(TIFF *tif) { - int tag_size = sizeof(xtiffFieldInfo) / sizeof(xtiffFieldInfo[0]); - // Install the extended Tag field info - TIFFMergeFieldInfo(tif, xtiffFieldInfo, tag_size); -} - -static TIFFExtendProc _ParentExtender; - -/** -This is the callback procedure, and is -called by the DefaultDirectory method -every time a new TIFF directory is opened. -*/ -static void -_XTIFFDefaultDirectory(TIFF *tif) { - // set up our own defaults - _XTIFFLocalDefaultDirectory(tif); - - /* - Since an XTIFF client module may have overridden - the default directory method, we call it now to - allow it to set up the rest of its own methods. - */ - if (_ParentExtender) - (*_ParentExtender)(tif); -} - -/** -XTIFF Initializer -- sets up the callback procedure for the TIFF module -*/ -void -XTIFFInitialize(void) { - static int first_time = 1; - - if (! first_time) - return; /* Been there. Done that. */ - first_time = 0; - - // Grab the inherited method and install - _ParentExtender = TIFFSetTagExtender(_XTIFFDefaultDirectory); -} - -// ---------------------------------------------------------- -// GeoTIFF tag reading / writing -// ---------------------------------------------------------- - -void -tiff_read_geotiff_profile(TIFF *tif, FIBITMAP *dib) { - char defaultKey[16]; - - size_t tag_size = sizeof(xtiffFieldInfo) / sizeof(xtiffFieldInfo[0]); - - TagLib& tag_lib = TagLib::instance(); - - for(unsigned i = 0; i < tag_size; i++) { - - const TIFFFieldInfo *fieldInfo = &xtiffFieldInfo[i]; - - if(fieldInfo->field_type == TIFF_ASCII) { - char *params = NULL; - - if(TIFFGetField(tif, fieldInfo->field_tag, ¶ms)) { - // create a tag - FITAG *tag = FreeImage_CreateTag(); - if(!tag) - return; - - WORD tag_id = (WORD)fieldInfo->field_tag; - - FreeImage_SetTagType(tag, (FREE_IMAGE_MDTYPE)fieldInfo->field_type); - FreeImage_SetTagID(tag, tag_id); - FreeImage_SetTagKey(tag, tag_lib.getTagFieldName(TagLib::GEOTIFF, tag_id, defaultKey)); - FreeImage_SetTagDescription(tag, tag_lib.getTagDescription(TagLib::GEOTIFF, tag_id)); - FreeImage_SetTagLength(tag, (DWORD)strlen(params) + 1); - FreeImage_SetTagCount(tag, FreeImage_GetTagLength(tag)); - FreeImage_SetTagValue(tag, params); - FreeImage_SetMetadata(FIMD_GEOTIFF, dib, FreeImage_GetTagKey(tag), tag); - - // delete the tag - FreeImage_DeleteTag(tag); - } - } else { - short tag_count = 0; - void* data = NULL; - - if(TIFFGetField(tif, fieldInfo->field_tag, &tag_count, &data)) { - // create a tag - FITAG *tag = FreeImage_CreateTag(); - if(!tag) - return; - - WORD tag_id = (WORD)fieldInfo->field_tag; - FREE_IMAGE_MDTYPE tag_type = (FREE_IMAGE_MDTYPE)fieldInfo->field_type; - - FreeImage_SetTagType(tag, tag_type); - FreeImage_SetTagID(tag, tag_id); - FreeImage_SetTagKey(tag, tag_lib.getTagFieldName(TagLib::GEOTIFF, tag_id, defaultKey)); - FreeImage_SetTagDescription(tag, tag_lib.getTagDescription(TagLib::GEOTIFF, tag_id)); - FreeImage_SetTagLength(tag, FreeImage_TagDataWidth(tag_type) * tag_count); - FreeImage_SetTagCount(tag, tag_count); - FreeImage_SetTagValue(tag, data); - FreeImage_SetMetadata(FIMD_GEOTIFF, dib, FreeImage_GetTagKey(tag), tag); - - // delete the tag - FreeImage_DeleteTag(tag); - } - } - } // for(tag_size) -} - -void -tiff_write_geotiff_profile(TIFF *tif, FIBITMAP *dib) { - char defaultKey[16]; - - if(FreeImage_GetMetadataCount(FIMD_GEOTIFF, dib) == 0) { - return; - } - - size_t tag_size = sizeof(xtiffFieldInfo) / sizeof(xtiffFieldInfo[0]); - - TagLib& tag_lib = TagLib::instance(); - - for(unsigned i = 0; i < tag_size; i++) { - const TIFFFieldInfo *fieldInfo = &xtiffFieldInfo[i]; - - FITAG *tag = NULL; - const char *key = tag_lib.getTagFieldName(TagLib::GEOTIFF, (WORD)fieldInfo->field_tag, defaultKey); - - if(FreeImage_GetMetadata(FIMD_GEOTIFF, dib, key, &tag)) { - if(FreeImage_GetTagType(tag) == FIDT_ASCII) { - TIFFSetField(tif, fieldInfo->field_tag, FreeImage_GetTagValue(tag)); - } else { - TIFFSetField(tif, fieldInfo->field_tag, FreeImage_GetTagCount(tag), FreeImage_GetTagValue(tag)); - } - } - } -} - -// ---------------------------------------------------------- -// EXIF tag reading & writing -// ---------------------------------------------------------- - -/** -Read a single exif tag -*/ -static BOOL -tiff_read_exif_tag(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib, TagLib& tagLib, TIFFDirectory *td, ttag_t tag) { - const TIFFFieldInfo *fip; - uint32 value_count; - int mem_alloc = 0; - void *raw_data = NULL; - - if(tag == TIFFTAG_EXIFIFD) { - return TRUE; - } - - // get the tag key - use NULL to avoid reading GeoTIFF tags - const char *key = tagLib.getTagFieldName(md_model, (WORD)tag, NULL); - if(key == NULL) { - return TRUE; - } - - fip = TIFFFieldWithTag(tif, tag); - if(fip == NULL) { - return TRUE; - } - - // ### for some reason TIFFFieldWithTag returns wrong version (TIFF_LONG vs TIFF_SHORT) for some params, correct this - if(fip->field_tag == TIFFTAG_IMAGEWIDTH && fip->field_type == TIFF_SHORT) { - fip = TIFFFindFieldInfo(tif, tag, TIFF_LONG); - } else if(fip->field_tag == TIFFTAG_IMAGELENGTH && fip->field_type == TIFF_SHORT) { - fip = TIFFFindFieldInfo(tif, tag, TIFF_LONG); - } else if(fip->field_tag == TIFFTAG_BITSPERSAMPLE && fip->field_type == TIFF_LONG) { - fip = TIFFFindFieldInfo(tif, tag, TIFF_SHORT); - } else if(fip->field_tag == TIFFTAG_COMPRESSION && fip->field_type == TIFF_LONG) { - fip = TIFFFindFieldInfo(tif, tag, TIFF_SHORT); - } else if(fip->field_tag == TIFFTAG_PHOTOMETRIC && fip->field_type == TIFF_LONG) { - fip = TIFFFindFieldInfo(tif, tag, TIFF_SHORT); - } else if(fip->field_tag == TIFFTAG_ROWSPERSTRIP && fip->field_type == TIFF_SHORT) { - fip = TIFFFindFieldInfo(tif, tag, TIFF_LONG); - } else if(fip->field_tag == TIFFTAG_STRIPOFFSETS && fip->field_type == TIFF_SHORT) { - fip = TIFFFindFieldInfo(tif, tag, TIFF_LONG); - } else if(fip->field_tag == TIFFTAG_STRIPBYTECOUNTS && fip->field_type == TIFF_SHORT) { - fip = TIFFFindFieldInfo(tif, tag, TIFF_LONG); - } - // ### the tags left unchecked are SGI, Pixar and DNG tags filtered by tagLib.getTagFieldName - - - if(fip->field_passcount) { //<- "passcount" means "returns count" - if (fip->field_readcount != TIFF_VARIABLE2) { //<- TIFF_VARIABLE2 means "uses LONG count" - - // assume TIFF_VARIABLE (uses SHORT count) - uint16 value_count16; - if(TIFFGetField(tif, tag, &value_count16, &raw_data) != 1) { - return TRUE; - } - value_count = value_count16; - } else { - if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1) { - return TRUE; - } - } - } else { - - // determine count - - if (fip->field_readcount == TIFF_VARIABLE || fip->field_readcount == TIFF_VARIABLE2) { - value_count = 1; - } else if (fip->field_readcount == TIFF_SPP) { - value_count = td->td_samplesperpixel; - } else { - value_count = fip->field_readcount; - } - - // access fields as pointers to data - // (### determining this is NOT robust... and hardly can be. It is implemented looking the _TIFFVGetField code) - - if(fip->field_tag == TIFFTAG_TRANSFERFUNCTION) { - // reading this tag cause a bug probably located somewhere inside libtiff - return TRUE; - } - - if ((fip->field_type == TIFF_ASCII - || fip->field_readcount == TIFF_VARIABLE - || fip->field_readcount == TIFF_VARIABLE2 - || fip->field_readcount == TIFF_SPP - || value_count > 1) - - && fip->field_tag != TIFFTAG_PAGENUMBER - && fip->field_tag != TIFFTAG_HALFTONEHINTS - && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING - && fip->field_tag != TIFFTAG_DOTRANGE - - && fip->field_tag != TIFFTAG_BITSPERSAMPLE //<- these two are tricky - - && fip->field_tag != TIFFTAG_COMPRESSION //<- they are defined as TIFF_VARIABLE but in reality return a single value - ) { - if(TIFFGetField(tif, tag, &raw_data) != 1) { - return TRUE; - } - } else { - - // access fields as values - - const int value_size = _TIFFDataSize(fip->field_type); - raw_data = _TIFFmalloc(value_size * value_count); - mem_alloc = 1; - int ok = FALSE; - - // ### if value_count > 1, tag is PAGENUMBER or HALFTONEHINTS or YCBCRSUBSAMPLING or DOTRANGE, - // all off which are value_count == 2 (see tif_dirinfo.c) - switch(value_count) - { - case 1: - ok = TIFFGetField(tif, tag, raw_data); - break; - case 2: - ok = TIFFGetField(tif, tag, raw_data, (BYTE*)(raw_data) + value_size*1); - break; -/* # we might need more in the future: - case 3: - ok = TIFFGetField(tif, tag, raw_data, (BYTE*)(raw_data) + value_size*1, (BYTE*)(raw_data) + value_size*2); - break; -*/ - default: - FreeImage_OutputMessageProc(FIF_TIFF, "Unimplemented variable number of parameters for Tiff Tag %s", fip->field_name); - break; - } - if(ok != 1) { - _TIFFfree(raw_data); - return TRUE; - } - } - } - - // build FreeImage tag from Tiff Tag data we collected - - FITAG *fitag = FreeImage_CreateTag(); - if(!fitag) { - if(mem_alloc) { - _TIFFfree(raw_data); - } - return FALSE; - } - - FreeImage_SetTagID(fitag, (WORD)tag); - FreeImage_SetTagKey(fitag, key); - - switch(fip->field_type) { - case TIFF_BYTE: - FreeImage_SetTagType(fitag, FIDT_BYTE); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_UNDEFINED: - FreeImage_SetTagType(fitag, FIDT_UNDEFINED); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_SBYTE: - FreeImage_SetTagType(fitag, FIDT_SBYTE); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_SHORT: - FreeImage_SetTagType(fitag, FIDT_SHORT); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_SSHORT: - FreeImage_SetTagType(fitag, FIDT_SSHORT); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_LONG: - FreeImage_SetTagType(fitag, FIDT_LONG); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_IFD: - FreeImage_SetTagType(fitag, FIDT_IFD); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_SLONG: - FreeImage_SetTagType(fitag, FIDT_SLONG); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_RATIONAL: { - // LibTIFF converts rational to floats : reconvert floats to rationals - DWORD *rvalue = (DWORD*)malloc(2 * value_count * sizeof(DWORD)); - for(uint32 i = 0; i < value_count; i++) { - float *fv = (float*)raw_data; - FIRational rational(fv[i]); - rvalue[2*i] = rational.getNumerator(); - rvalue[2*i+1] = rational.getDenominator(); - } - FreeImage_SetTagType(fitag, FIDT_RATIONAL); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, rvalue); - free(rvalue); - } - break; - - case TIFF_SRATIONAL: { - // LibTIFF converts rational to floats : reconvert floats to rationals - LONG *rvalue = (LONG*)malloc(2 * value_count * sizeof(LONG)); - for(uint32 i = 0; i < value_count; i++) { - float *fv = (float*)raw_data; - FIRational rational(fv[i]); - rvalue[2*i] = rational.getNumerator(); - rvalue[2*i+1] = rational.getDenominator(); - } - FreeImage_SetTagType(fitag, FIDT_RATIONAL); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, rvalue); - free(rvalue); - } - break; - - case TIFF_FLOAT: - FreeImage_SetTagType(fitag, FIDT_FLOAT); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_DOUBLE: - FreeImage_SetTagType(fitag, FIDT_DOUBLE); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - default: { - size_t length = strlen((char*)raw_data) + 1; - FreeImage_SetTagType(fitag, FIDT_ASCII); - FreeImage_SetTagLength(fitag, (DWORD)length); - FreeImage_SetTagCount(fitag, (DWORD)length); - FreeImage_SetTagValue(fitag, raw_data); - } - break; - } - - const char *description = tagLib.getTagDescription(md_model, (WORD)tag); - if(description) { - FreeImage_SetTagDescription(fitag, description); - } - // store the tag - FreeImage_SetMetadata(tagLib.getFreeImageModel(md_model), dib, FreeImage_GetTagKey(fitag), fitag); - - // destroy the tag - FreeImage_DeleteTag(fitag); - - if(mem_alloc) { - _TIFFfree(raw_data); - } - return TRUE; -} - -/** -Read all known exif tags -*/ -BOOL -tiff_read_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib) { - int i; - short count; - - TagLib& tagLib = TagLib::instance(); - - TIFFDirectory *td = &tif->tif_dir; - - count = (short) TIFFGetTagListCount(tif); - for(i = 0; i < count; i++) { - ttag_t tag = TIFFGetTagListEntry(tif, i); - // read the tag - if (!tiff_read_exif_tag(tif, md_model, dib, tagLib, td, tag)) - return FALSE; - } - - // we want to know values of standard tags too!! - - // loop over all Core Directory Tags - // ### uses private data, but there is no other way - if(md_model == TagLib::EXIF_MAIN) { - - ttag_t lastTag = 0; //<- used to prevent reading some tags twice (as stored in tif_fieldinfo) - - for (int fi = 0, nfi = (int)tif->tif_nfields; nfi > 0; nfi--, fi++) { - const TIFFFieldInfo* fip = tif->tif_fieldinfo[fi]; - - if(fip->field_tag == lastTag) - continue; - - // test if tag value is set - // (lifted directly form LibTiff _TIFFWriteDirectory) - - if( fip->field_bit == FIELD_CUSTOM ) { - int ci, is_set = FALSE; - - for( ci = 0; ci < td->td_customValueCount; ci++ ) { - is_set |= (td->td_customValues[ci].info == fip); - } - - if( !is_set ) { - continue; - } - - } else if(!TIFFFieldSet(tif, fip->field_bit)) { - continue; - } - - // process *all* other tags (some will be ignored) - - tiff_read_exif_tag(tif, md_model, dib, tagLib, td, fip->field_tag); - - - lastTag = fip->field_tag; - } - - } - - return TRUE; - -} - - -/** -Skip tags that are already handled by the LibTIFF writing process -*/ -static BOOL -skip_write_field(TIFF* tif, ttag_t tag) { - switch (tag) { - case TIFFTAG_SAMPLEFORMAT: - case TIFFTAG_IMAGEWIDTH: - case TIFFTAG_IMAGELENGTH: - case TIFFTAG_SAMPLESPERPIXEL: - case TIFFTAG_BITSPERSAMPLE: - case TIFFTAG_PHOTOMETRIC: - case TIFFTAG_PLANARCONFIG: - case TIFFTAG_ROWSPERSTRIP: - case TIFFTAG_RESOLUTIONUNIT: - case TIFFTAG_XRESOLUTION: - case TIFFTAG_YRESOLUTION: - case TIFFTAG_SUBFILETYPE: - case TIFFTAG_PAGENUMBER: - case TIFFTAG_COLORMAP: - case TIFFTAG_ORIENTATION: - case TIFFTAG_COMPRESSION: - case TIFFTAG_PREDICTOR: - case TIFFTAG_GROUP3OPTIONS: - case TIFFTAG_FILLORDER: - // skip always, values have been set in SaveOneTIFF() - return TRUE; - break; - - case TIFFTAG_RICHTIFFIPTC: - // skip always, IPTC metadata model is set in tiff_write_iptc_profile() - return TRUE; - break; - - case TIFFTAG_YCBCRCOEFFICIENTS: - case TIFFTAG_REFERENCEBLACKWHITE: - case TIFFTAG_YCBCRSUBSAMPLING: - // skip as they cannot be filled yet - return TRUE; - break; - - case TIFFTAG_PAGENAME: - { - char *value = NULL; - TIFFGetField(tif, TIFFTAG_PAGENAME, &value); - // only skip if no value has been set - if(value == NULL) { - return FALSE; - } else { - return TRUE; - } - } - default: - return FALSE; - break; - } -} - -/** -Write all known exif tags -*/ -BOOL -tiff_write_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib) { - char defaultKey[16]; - size_t tag_size = 0; - const TIFFFieldInfo *tiffFieldInfos; - - // only EXIF_MAIN so far - if(md_model != TagLib::EXIF_MAIN) { - return FALSE; - } - - if(FreeImage_GetMetadataCount(FIMD_EXIF_MAIN, dib) == 0) { - return FALSE; - } - - TagLib& tag_lib = TagLib::instance(); - tiffFieldInfos = _TIFFGetFieldInfo(&tag_size); - - for(size_t i = 0; i < tag_size; i++) { - const TIFFFieldInfo *fieldInfo = &tiffFieldInfos[i]; - - if(skip_write_field(tif, fieldInfo->field_tag)) { - // skip tags that are already handled by the LibTIFF writing process - continue; - } - - FITAG *tag = NULL; - // get the tag key - const char *key = tag_lib.getTagFieldName(TagLib::EXIF_MAIN, (WORD)fieldInfo->field_tag, defaultKey); - - if(FreeImage_GetMetadata(FIMD_EXIF_MAIN, dib, key, &tag)) { - FREE_IMAGE_MDTYPE tag_type = FreeImage_GetTagType(tag); - TIFFDataType tif_tag_type = fieldInfo->field_type; - - // check for identical formats - - // (enum value are the sames between FREE_IMAGE_MDTYPE and TIFFDataType types) - if((int)tif_tag_type != (int)tag_type) { - // skip tag or _TIFFmemcpy will fail - continue; - } - // type of storage may differ (e.g. rationnal array vs float array type) - if(_TIFFDataSize(tif_tag_type) != FreeImage_TagDataWidth(tag_type)) { - // skip tag or _TIFFmemcpy will fail - continue; - } - - if(tag_type == FIDT_ASCII) { - TIFFSetField(tif, fieldInfo->field_tag, FreeImage_GetTagValue(tag)); - } else { - TIFFSetField(tif, fieldInfo->field_tag, FreeImage_GetTagCount(tag), FreeImage_GetTagValue(tag)); - } - } - } - - return TRUE; -} +// ========================================================== +// Metadata functions implementation +// Extended TIFF Directory GEO Tag Support +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// - Thorsten Radde (support@IdealSoftware.com) +// - Berend Engelbrecht (softwarecave@users.sourceforge.net) +// - Mihail Naydenov (mnaydenov@users.sourceforge.net) +// +// Based on the LibTIFF xtiffio sample and on LibGeoTIFF +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#ifdef _MSC_VER +#pragma warning (disable : 4786) // identifier was truncated to 'number' characters +#endif + +#include "../LibTIFF/tiffiop.h" + +#include "FreeImage.h" +#include "Utilities.h" +#include "FreeImageTag.h" +#include "FIRational.h" + +// ---------------------------------------------------------- +// Extended TIFF Directory GEO Tag Support +// ---------------------------------------------------------- + +/** + Tiff info structure. + Entry format: + { TAGNUMBER, ReadCount, WriteCount, DataType, FIELDNUM, OkToChange, PassDirCountOnSet, AsciiName } + + For ReadCount, WriteCount, -1 = unknown. +*/ +static const TIFFFieldInfo xtiffFieldInfo[] = { + { TIFFTAG_GEOPIXELSCALE, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoPixelScale" }, + { TIFFTAG_INTERGRAPH_MATRIX, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "Intergraph TransformationMatrix" }, + { TIFFTAG_GEOTRANSMATRIX, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoTransformationMatrix" }, + { TIFFTAG_GEOTIEPOINTS, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoTiePoints" }, + { TIFFTAG_GEOKEYDIRECTORY,-1,-1, TIFF_SHORT, FIELD_CUSTOM, TRUE, TRUE, "GeoKeyDirectory" }, + { TIFFTAG_GEODOUBLEPARAMS, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoDoubleParams" }, + { TIFFTAG_GEOASCIIPARAMS, -1, -1, TIFF_ASCII, FIELD_CUSTOM, TRUE, FALSE, "GeoASCIIParams" }, + { TIFFTAG_JPL_CARTO_IFD, 1, 1, TIFF_LONG, FIELD_CUSTOM, TRUE, TRUE, "JPL Carto IFD offset" } /** Don't use this! **/ +}; + +static void +_XTIFFLocalDefaultDirectory(TIFF *tif) { + int tag_size = sizeof(xtiffFieldInfo) / sizeof(xtiffFieldInfo[0]); + // Install the extended Tag field info + TIFFMergeFieldInfo(tif, xtiffFieldInfo, tag_size); +} + +static TIFFExtendProc _ParentExtender; + +/** +This is the callback procedure, and is +called by the DefaultDirectory method +every time a new TIFF directory is opened. +*/ +static void +_XTIFFDefaultDirectory(TIFF *tif) { + // set up our own defaults + _XTIFFLocalDefaultDirectory(tif); + + /* + Since an XTIFF client module may have overridden + the default directory method, we call it now to + allow it to set up the rest of its own methods. + */ + if (_ParentExtender) + (*_ParentExtender)(tif); +} + +/** +XTIFF Initializer -- sets up the callback procedure for the TIFF module +*/ +void +XTIFFInitialize(void) { + static int first_time = 1; + + if (! first_time) + return; /* Been there. Done that. */ + first_time = 0; + + // Grab the inherited method and install + _ParentExtender = TIFFSetTagExtender(_XTIFFDefaultDirectory); +} + +// ---------------------------------------------------------- +// GeoTIFF tag reading / writing +// ---------------------------------------------------------- + +void +tiff_read_geotiff_profile(TIFF *tif, FIBITMAP *dib) { + char defaultKey[16]; + + size_t tag_size = sizeof(xtiffFieldInfo) / sizeof(xtiffFieldInfo[0]); + + TagLib& tag_lib = TagLib::instance(); + + for(unsigned i = 0; i < tag_size; i++) { + + const TIFFFieldInfo *fieldInfo = &xtiffFieldInfo[i]; + + if(fieldInfo->field_type == TIFF_ASCII) { + char *params = NULL; + + if(TIFFGetField(tif, fieldInfo->field_tag, ¶ms)) { + // create a tag + FITAG *tag = FreeImage_CreateTag(); + if(!tag) + return; + + WORD tag_id = (WORD)fieldInfo->field_tag; + + FreeImage_SetTagType(tag, (FREE_IMAGE_MDTYPE)fieldInfo->field_type); + FreeImage_SetTagID(tag, tag_id); + FreeImage_SetTagKey(tag, tag_lib.getTagFieldName(TagLib::GEOTIFF, tag_id, defaultKey)); + FreeImage_SetTagDescription(tag, tag_lib.getTagDescription(TagLib::GEOTIFF, tag_id)); + FreeImage_SetTagLength(tag, (DWORD)strlen(params) + 1); + FreeImage_SetTagCount(tag, FreeImage_GetTagLength(tag)); + FreeImage_SetTagValue(tag, params); + FreeImage_SetMetadata(FIMD_GEOTIFF, dib, FreeImage_GetTagKey(tag), tag); + + // delete the tag + FreeImage_DeleteTag(tag); + } + } else { + short tag_count = 0; + void* data = NULL; + + if(TIFFGetField(tif, fieldInfo->field_tag, &tag_count, &data)) { + // create a tag + FITAG *tag = FreeImage_CreateTag(); + if(!tag) + return; + + WORD tag_id = (WORD)fieldInfo->field_tag; + FREE_IMAGE_MDTYPE tag_type = (FREE_IMAGE_MDTYPE)fieldInfo->field_type; + + FreeImage_SetTagType(tag, tag_type); + FreeImage_SetTagID(tag, tag_id); + FreeImage_SetTagKey(tag, tag_lib.getTagFieldName(TagLib::GEOTIFF, tag_id, defaultKey)); + FreeImage_SetTagDescription(tag, tag_lib.getTagDescription(TagLib::GEOTIFF, tag_id)); + FreeImage_SetTagLength(tag, FreeImage_TagDataWidth(tag_type) * tag_count); + FreeImage_SetTagCount(tag, tag_count); + FreeImage_SetTagValue(tag, data); + FreeImage_SetMetadata(FIMD_GEOTIFF, dib, FreeImage_GetTagKey(tag), tag); + + // delete the tag + FreeImage_DeleteTag(tag); + } + } + } // for(tag_size) +} + +void +tiff_write_geotiff_profile(TIFF *tif, FIBITMAP *dib) { + char defaultKey[16]; + + if(FreeImage_GetMetadataCount(FIMD_GEOTIFF, dib) == 0) { + return; + } + + size_t tag_size = sizeof(xtiffFieldInfo) / sizeof(xtiffFieldInfo[0]); + + TagLib& tag_lib = TagLib::instance(); + + for(unsigned i = 0; i < tag_size; i++) { + const TIFFFieldInfo *fieldInfo = &xtiffFieldInfo[i]; + + FITAG *tag = NULL; + const char *key = tag_lib.getTagFieldName(TagLib::GEOTIFF, (WORD)fieldInfo->field_tag, defaultKey); + + if(FreeImage_GetMetadata(FIMD_GEOTIFF, dib, key, &tag)) { + if(FreeImage_GetTagType(tag) == FIDT_ASCII) { + TIFFSetField(tif, fieldInfo->field_tag, FreeImage_GetTagValue(tag)); + } else { + TIFFSetField(tif, fieldInfo->field_tag, FreeImage_GetTagCount(tag), FreeImage_GetTagValue(tag)); + } + } + } +} + +// ---------------------------------------------------------- +// EXIF tag reading & writing +// ---------------------------------------------------------- + +/** +Read a single exif tag +*/ +static BOOL +tiff_read_exif_tag(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib, TagLib& tagLib, TIFFDirectory *td, ttag_t tag) { + const TIFFFieldInfo *fip; + uint32 value_count; + int mem_alloc = 0; + void *raw_data = NULL; + + if(tag == TIFFTAG_EXIFIFD) { + return TRUE; + } + + // get the tag key - use NULL to avoid reading GeoTIFF tags + const char *key = tagLib.getTagFieldName(md_model, (WORD)tag, NULL); + if(key == NULL) { + return TRUE; + } + + fip = TIFFFieldWithTag(tif, tag); + if(fip == NULL) { + return TRUE; + } + + // ### for some reason TIFFFieldWithTag returns wrong version (TIFF_LONG vs TIFF_SHORT) for some params, correct this + if(fip->field_tag == TIFFTAG_IMAGEWIDTH && fip->field_type == TIFF_SHORT) { + fip = TIFFFindFieldInfo(tif, tag, TIFF_LONG); + } else if(fip->field_tag == TIFFTAG_IMAGELENGTH && fip->field_type == TIFF_SHORT) { + fip = TIFFFindFieldInfo(tif, tag, TIFF_LONG); + } else if(fip->field_tag == TIFFTAG_BITSPERSAMPLE && fip->field_type == TIFF_LONG) { + fip = TIFFFindFieldInfo(tif, tag, TIFF_SHORT); + } else if(fip->field_tag == TIFFTAG_COMPRESSION && fip->field_type == TIFF_LONG) { + fip = TIFFFindFieldInfo(tif, tag, TIFF_SHORT); + } else if(fip->field_tag == TIFFTAG_PHOTOMETRIC && fip->field_type == TIFF_LONG) { + fip = TIFFFindFieldInfo(tif, tag, TIFF_SHORT); + } else if(fip->field_tag == TIFFTAG_ROWSPERSTRIP && fip->field_type == TIFF_SHORT) { + fip = TIFFFindFieldInfo(tif, tag, TIFF_LONG); + } else if(fip->field_tag == TIFFTAG_STRIPOFFSETS && fip->field_type == TIFF_SHORT) { + fip = TIFFFindFieldInfo(tif, tag, TIFF_LONG); + } else if(fip->field_tag == TIFFTAG_STRIPBYTECOUNTS && fip->field_type == TIFF_SHORT) { + fip = TIFFFindFieldInfo(tif, tag, TIFF_LONG); + } + // ### the tags left unchecked are SGI, Pixar and DNG tags filtered by tagLib.getTagFieldName + + + if(fip->field_passcount) { //<- "passcount" means "returns count" + if (fip->field_readcount != TIFF_VARIABLE2) { //<- TIFF_VARIABLE2 means "uses LONG count" + + // assume TIFF_VARIABLE (uses SHORT count) + uint16 value_count16; + if(TIFFGetField(tif, tag, &value_count16, &raw_data) != 1) { + return TRUE; + } + value_count = value_count16; + } else { + if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1) { + return TRUE; + } + } + } else { + + // determine count + + if (fip->field_readcount == TIFF_VARIABLE || fip->field_readcount == TIFF_VARIABLE2) { + value_count = 1; + } else if (fip->field_readcount == TIFF_SPP) { + value_count = td->td_samplesperpixel; + } else { + value_count = fip->field_readcount; + } + + // access fields as pointers to data + // (### determining this is NOT robust... and hardly can be. It is implemented looking the _TIFFVGetField code) + + if(fip->field_tag == TIFFTAG_TRANSFERFUNCTION) { + // reading this tag cause a bug probably located somewhere inside libtiff + return TRUE; + } + + if ((fip->field_type == TIFF_ASCII + || fip->field_readcount == TIFF_VARIABLE + || fip->field_readcount == TIFF_VARIABLE2 + || fip->field_readcount == TIFF_SPP + || value_count > 1) + + && fip->field_tag != TIFFTAG_PAGENUMBER + && fip->field_tag != TIFFTAG_HALFTONEHINTS + && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING + && fip->field_tag != TIFFTAG_DOTRANGE + + && fip->field_tag != TIFFTAG_BITSPERSAMPLE //<- these two are tricky - + && fip->field_tag != TIFFTAG_COMPRESSION //<- they are defined as TIFF_VARIABLE but in reality return a single value + ) { + if(TIFFGetField(tif, tag, &raw_data) != 1) { + return TRUE; + } + } else { + + // access fields as values + + const int value_size = _TIFFDataSize(fip->field_type); + raw_data = _TIFFmalloc(value_size * value_count); + mem_alloc = 1; + int ok = FALSE; + + // ### if value_count > 1, tag is PAGENUMBER or HALFTONEHINTS or YCBCRSUBSAMPLING or DOTRANGE, + // all off which are value_count == 2 (see tif_dirinfo.c) + switch(value_count) + { + case 1: + ok = TIFFGetField(tif, tag, raw_data); + break; + case 2: + ok = TIFFGetField(tif, tag, raw_data, (BYTE*)(raw_data) + value_size*1); + break; +/* # we might need more in the future: + case 3: + ok = TIFFGetField(tif, tag, raw_data, (BYTE*)(raw_data) + value_size*1, (BYTE*)(raw_data) + value_size*2); + break; +*/ + default: + FreeImage_OutputMessageProc(FIF_TIFF, "Unimplemented variable number of parameters for Tiff Tag %s", fip->field_name); + break; + } + if(ok != 1) { + _TIFFfree(raw_data); + return TRUE; + } + } + } + + // build FreeImage tag from Tiff Tag data we collected + + FITAG *fitag = FreeImage_CreateTag(); + if(!fitag) { + if(mem_alloc) { + _TIFFfree(raw_data); + } + return FALSE; + } + + FreeImage_SetTagID(fitag, (WORD)tag); + FreeImage_SetTagKey(fitag, key); + + switch(fip->field_type) { + case TIFF_BYTE: + FreeImage_SetTagType(fitag, FIDT_BYTE); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_UNDEFINED: + FreeImage_SetTagType(fitag, FIDT_UNDEFINED); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_SBYTE: + FreeImage_SetTagType(fitag, FIDT_SBYTE); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_SHORT: + FreeImage_SetTagType(fitag, FIDT_SHORT); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_SSHORT: + FreeImage_SetTagType(fitag, FIDT_SSHORT); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_LONG: + FreeImage_SetTagType(fitag, FIDT_LONG); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_IFD: + FreeImage_SetTagType(fitag, FIDT_IFD); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_SLONG: + FreeImage_SetTagType(fitag, FIDT_SLONG); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_RATIONAL: { + // LibTIFF converts rational to floats : reconvert floats to rationals + DWORD *rvalue = (DWORD*)malloc(2 * value_count * sizeof(DWORD)); + for(uint32 i = 0; i < value_count; i++) { + float *fv = (float*)raw_data; + FIRational rational(fv[i]); + rvalue[2*i] = rational.getNumerator(); + rvalue[2*i+1] = rational.getDenominator(); + } + FreeImage_SetTagType(fitag, FIDT_RATIONAL); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, rvalue); + free(rvalue); + } + break; + + case TIFF_SRATIONAL: { + // LibTIFF converts rational to floats : reconvert floats to rationals + LONG *rvalue = (LONG*)malloc(2 * value_count * sizeof(LONG)); + for(uint32 i = 0; i < value_count; i++) { + float *fv = (float*)raw_data; + FIRational rational(fv[i]); + rvalue[2*i] = rational.getNumerator(); + rvalue[2*i+1] = rational.getDenominator(); + } + FreeImage_SetTagType(fitag, FIDT_RATIONAL); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, rvalue); + free(rvalue); + } + break; + + case TIFF_FLOAT: + FreeImage_SetTagType(fitag, FIDT_FLOAT); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_DOUBLE: + FreeImage_SetTagType(fitag, FIDT_DOUBLE); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + default: { + size_t length = strlen((char*)raw_data) + 1; + FreeImage_SetTagType(fitag, FIDT_ASCII); + FreeImage_SetTagLength(fitag, (DWORD)length); + FreeImage_SetTagCount(fitag, (DWORD)length); + FreeImage_SetTagValue(fitag, raw_data); + } + break; + } + + const char *description = tagLib.getTagDescription(md_model, (WORD)tag); + if(description) { + FreeImage_SetTagDescription(fitag, description); + } + // store the tag + FreeImage_SetMetadata(tagLib.getFreeImageModel(md_model), dib, FreeImage_GetTagKey(fitag), fitag); + + // destroy the tag + FreeImage_DeleteTag(fitag); + + if(mem_alloc) { + _TIFFfree(raw_data); + } + return TRUE; +} + +/** +Read all known exif tags +*/ +BOOL +tiff_read_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib) { + int i; + short count; + + TagLib& tagLib = TagLib::instance(); + + TIFFDirectory *td = &tif->tif_dir; + + count = (short) TIFFGetTagListCount(tif); + for(i = 0; i < count; i++) { + ttag_t tag = TIFFGetTagListEntry(tif, i); + // read the tag + if (!tiff_read_exif_tag(tif, md_model, dib, tagLib, td, tag)) + return FALSE; + } + + // we want to know values of standard tags too!! + + // loop over all Core Directory Tags + // ### uses private data, but there is no other way + if(md_model == TagLib::EXIF_MAIN) { + + ttag_t lastTag = 0; //<- used to prevent reading some tags twice (as stored in tif_fieldinfo) + + for (int fi = 0, nfi = (int)tif->tif_nfields; nfi > 0; nfi--, fi++) { + const TIFFFieldInfo* fip = tif->tif_fieldinfo[fi]; + + if(fip->field_tag == lastTag) + continue; + + // test if tag value is set + // (lifted directly form LibTiff _TIFFWriteDirectory) + + if( fip->field_bit == FIELD_CUSTOM ) { + int ci, is_set = FALSE; + + for( ci = 0; ci < td->td_customValueCount; ci++ ) { + is_set |= (td->td_customValues[ci].info == fip); + } + + if( !is_set ) { + continue; + } + + } else if(!TIFFFieldSet(tif, fip->field_bit)) { + continue; + } + + // process *all* other tags (some will be ignored) + + tiff_read_exif_tag(tif, md_model, dib, tagLib, td, fip->field_tag); + + + lastTag = fip->field_tag; + } + + } + + return TRUE; + +} + + +/** +Skip tags that are already handled by the LibTIFF writing process +*/ +static BOOL +skip_write_field(TIFF* tif, ttag_t tag) { + switch (tag) { + case TIFFTAG_SAMPLEFORMAT: + case TIFFTAG_IMAGEWIDTH: + case TIFFTAG_IMAGELENGTH: + case TIFFTAG_SAMPLESPERPIXEL: + case TIFFTAG_BITSPERSAMPLE: + case TIFFTAG_PHOTOMETRIC: + case TIFFTAG_PLANARCONFIG: + case TIFFTAG_ROWSPERSTRIP: + case TIFFTAG_RESOLUTIONUNIT: + case TIFFTAG_XRESOLUTION: + case TIFFTAG_YRESOLUTION: + case TIFFTAG_SUBFILETYPE: + case TIFFTAG_PAGENUMBER: + case TIFFTAG_COLORMAP: + case TIFFTAG_ORIENTATION: + case TIFFTAG_COMPRESSION: + case TIFFTAG_PREDICTOR: + case TIFFTAG_GROUP3OPTIONS: + case TIFFTAG_FILLORDER: + // skip always, values have been set in SaveOneTIFF() + return TRUE; + break; + + case TIFFTAG_RICHTIFFIPTC: + // skip always, IPTC metadata model is set in tiff_write_iptc_profile() + return TRUE; + break; + + case TIFFTAG_YCBCRCOEFFICIENTS: + case TIFFTAG_REFERENCEBLACKWHITE: + case TIFFTAG_YCBCRSUBSAMPLING: + // skip as they cannot be filled yet + return TRUE; + break; + + case TIFFTAG_PAGENAME: + { + char *value = NULL; + TIFFGetField(tif, TIFFTAG_PAGENAME, &value); + // only skip if no value has been set + if(value == NULL) { + return FALSE; + } else { + return TRUE; + } + } + default: + return FALSE; + break; + } +} + +/** +Write all known exif tags +*/ +BOOL +tiff_write_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib) { + char defaultKey[16]; + size_t tag_size = 0; + const TIFFFieldInfo *tiffFieldInfos; + + // only EXIF_MAIN so far + if(md_model != TagLib::EXIF_MAIN) { + return FALSE; + } + + if(FreeImage_GetMetadataCount(FIMD_EXIF_MAIN, dib) == 0) { + return FALSE; + } + + TagLib& tag_lib = TagLib::instance(); + tiffFieldInfos = _TIFFGetFieldInfo(&tag_size); + + for(size_t i = 0; i < tag_size; i++) { + const TIFFFieldInfo *fieldInfo = &tiffFieldInfos[i]; + + if(skip_write_field(tif, fieldInfo->field_tag)) { + // skip tags that are already handled by the LibTIFF writing process + continue; + } + + FITAG *tag = NULL; + // get the tag key + const char *key = tag_lib.getTagFieldName(TagLib::EXIF_MAIN, (WORD)fieldInfo->field_tag, defaultKey); + + if(FreeImage_GetMetadata(FIMD_EXIF_MAIN, dib, key, &tag)) { + FREE_IMAGE_MDTYPE tag_type = FreeImage_GetTagType(tag); + TIFFDataType tif_tag_type = fieldInfo->field_type; + + // check for identical formats + + // (enum value are the sames between FREE_IMAGE_MDTYPE and TIFFDataType types) + if((int)tif_tag_type != (int)tag_type) { + // skip tag or _TIFFmemcpy will fail + continue; + } + // type of storage may differ (e.g. rationnal array vs float array type) + if(_TIFFDataSize(tif_tag_type) != FreeImage_TagDataWidth(tag_type)) { + // skip tag or _TIFFmemcpy will fail + continue; + } + + if(tag_type == FIDT_ASCII) { + TIFFSetField(tif, fieldInfo->field_tag, FreeImage_GetTagValue(tag)); + } else { + TIFFSetField(tif, fieldInfo->field_tag, FreeImage_GetTagCount(tag), FreeImage_GetTagValue(tag)); + } + } + } + + return TRUE; +} diff --git a/Source/LibTIFF/makefile.vc b/Source/LibTIFF/makefile.vc index 2544541..e7c002f 100644 --- a/Source/LibTIFF/makefile.vc +++ b/Source/LibTIFF/makefile.vc @@ -1,102 +1,102 @@ -# $Id: makefile.vc,v 1.37 2011/04/10 17:14:09 drolon Exp $ -# -# Copyright (C) 2004, Andrey Kiselev -# -# Permission to use, copy, modify, distribute, and sell this software and -# its documentation for any purpose is hereby granted without fee, provided -# that (i) the above copyright notices and this permission notice appear in -# all copies of the software and related documentation, and (ii) the names of -# Sam Leffler and Silicon Graphics may not be used in any advertising or -# publicity relating to the software without the specific, prior written -# permission of Sam Leffler and Silicon Graphics. -# -# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. -# -# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR -# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, -# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF -# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -# OF THIS SOFTWARE. -# -# Makefile for MS Visual C and Watcom C compilers. -# -# To build: -# C:\libtiff\libtiff> nmake /f makefile.vc all -# - -!INCLUDE ..\nmake.opt - -INCL = -I. $(JPEG_INCLUDE) $(ZLIB_INCLUDE) $(JBIG_INCLUDE) - -!IFDEF USE_WIN_CRT_LIB -OBJ_SYSDEP_MODULE = tif_unix.obj -!ELSE -OBJ_SYSDEP_MODULE = tif_win32.obj -!ENDIF - -OBJ = \ - tif_aux.obj \ - tif_close.obj \ - tif_codec.obj \ - tif_color.obj \ - tif_compress.obj \ - tif_dir.obj \ - tif_dirinfo.obj \ - tif_dirread.obj \ - tif_dirwrite.obj \ - tif_dumpmode.obj \ - tif_error.obj \ - tif_extension.obj \ - tif_fax3.obj \ - tif_fax3sm.obj \ - tif_getimage.obj \ - tif_jbig.obj \ - tif_jpeg.obj \ - tif_ojpeg.obj \ - tif_flush.obj \ - tif_luv.obj \ - tif_lzw.obj \ - tif_next.obj \ - tif_open.obj \ - tif_packbits.obj \ - tif_pixarlog.obj \ - tif_predict.obj \ - tif_print.obj \ - tif_read.obj \ - tif_stream.obj \ - tif_swab.obj \ - tif_strip.obj \ - tif_thunder.obj \ - tif_tile.obj \ - tif_version.obj \ - tif_warning.obj \ - tif_write.obj \ - tif_zip.obj \ - tif_jbig.obj \ - $(OBJ_SYSDEP_MODULE) - -all: libtiff.lib $(DLLNAME) - -tif_config.h: tif_config.vc.h - copy tif_config.vc.h tif_config.h - -tiffconf.h: tiffconf.vc.h - copy tiffconf.vc.h tiffconf.h - -libtiff.lib: tif_config.h tiffconf.h $(OBJ) - $(AR) /out:libtiff.lib $(OBJ) $(LIBS) - -$(DLLNAME): tif_config.h tiffconf.h libtiff.def $(OBJ) - $(LD) /debug /dll /def:libtiff.def /out:$(DLLNAME) \ - /implib:libtiff_i.lib $(OBJ) $(LIBS) - -clean: - -del tif_config.h tiffconf.h - -del *.obj - -del *.lib - -del *.dll - -del *.exe - -del *.pdb +# $Id: makefile.vc,v 1.37 2011/04/10 17:14:09 drolon Exp $ +# +# Copyright (C) 2004, Andrey Kiselev +# +# Permission to use, copy, modify, distribute, and sell this software and +# its documentation for any purpose is hereby granted without fee, provided +# that (i) the above copyright notices and this permission notice appear in +# all copies of the software and related documentation, and (ii) the names of +# Sam Leffler and Silicon Graphics may not be used in any advertising or +# publicity relating to the software without the specific, prior written +# permission of Sam Leffler and Silicon Graphics. +# +# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, +# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY +# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. +# +# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR +# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, +# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF +# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. +# +# Makefile for MS Visual C and Watcom C compilers. +# +# To build: +# C:\libtiff\libtiff> nmake /f makefile.vc all +# + +!INCLUDE ..\nmake.opt + +INCL = -I. $(JPEG_INCLUDE) $(ZLIB_INCLUDE) $(JBIG_INCLUDE) + +!IFDEF USE_WIN_CRT_LIB +OBJ_SYSDEP_MODULE = tif_unix.obj +!ELSE +OBJ_SYSDEP_MODULE = tif_win32.obj +!ENDIF + +OBJ = \ + tif_aux.obj \ + tif_close.obj \ + tif_codec.obj \ + tif_color.obj \ + tif_compress.obj \ + tif_dir.obj \ + tif_dirinfo.obj \ + tif_dirread.obj \ + tif_dirwrite.obj \ + tif_dumpmode.obj \ + tif_error.obj \ + tif_extension.obj \ + tif_fax3.obj \ + tif_fax3sm.obj \ + tif_getimage.obj \ + tif_jbig.obj \ + tif_jpeg.obj \ + tif_ojpeg.obj \ + tif_flush.obj \ + tif_luv.obj \ + tif_lzw.obj \ + tif_next.obj \ + tif_open.obj \ + tif_packbits.obj \ + tif_pixarlog.obj \ + tif_predict.obj \ + tif_print.obj \ + tif_read.obj \ + tif_stream.obj \ + tif_swab.obj \ + tif_strip.obj \ + tif_thunder.obj \ + tif_tile.obj \ + tif_version.obj \ + tif_warning.obj \ + tif_write.obj \ + tif_zip.obj \ + tif_jbig.obj \ + $(OBJ_SYSDEP_MODULE) + +all: libtiff.lib $(DLLNAME) + +tif_config.h: tif_config.vc.h + copy tif_config.vc.h tif_config.h + +tiffconf.h: tiffconf.vc.h + copy tiffconf.vc.h tiffconf.h + +libtiff.lib: tif_config.h tiffconf.h $(OBJ) + $(AR) /out:libtiff.lib $(OBJ) $(LIBS) + +$(DLLNAME): tif_config.h tiffconf.h libtiff.def $(OBJ) + $(LD) /debug /dll /def:libtiff.def /out:$(DLLNAME) \ + /implib:libtiff_i.lib $(OBJ) $(LIBS) + +clean: + -del tif_config.h tiffconf.h + -del *.obj + -del *.lib + -del *.dll + -del *.exe + -del *.pdb diff --git a/Source/LibTIFF/mkg3states.c b/Source/LibTIFF/mkg3states.c index 46fac37..24b1066 100644 --- a/Source/LibTIFF/mkg3states.c +++ b/Source/LibTIFF/mkg3states.c @@ -1,451 +1,451 @@ -/* "$Id: mkg3states.c,v 1.37 2011/04/10 17:14:09 drolon Exp $ */ - -/* - * Copyright (c) 1991-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* Initialise fax decoder tables - * Decoder support is derived, with permission, from the code - * in Frank Cringle's viewfax program; - * Copyright (C) 1990, 1995 Frank D. Cringle. - */ -#include "tif_config.h" - -#include -#include -#include - -#ifdef HAVE_UNISTD_H -# include -#endif - -#include "tif_fax3.h" - -#ifndef HAVE_GETOPT -extern int getopt(int, char**, char*); -#endif - -#define streq(a,b) (strcmp(a,b) == 0) - -/* NB: can't use names in tif_fax3.h 'cuz they are declared const */ -TIFFFaxTabEnt MainTable[128]; -TIFFFaxTabEnt WhiteTable[4096]; -TIFFFaxTabEnt BlackTable[8192]; - -struct proto { - uint16 code; /* right justified, lsb-first, zero filled */ - uint16 val; /* (pixel count)<<4 + code width */ -}; - -static struct proto Pass[] = { -{ 0x0008, 4 }, -{ 0, 0 } -}; - -static struct proto Horiz[] = { -{ 0x0004, 3 }, -{ 0, 0 } -}; - -static struct proto V0[] = { -{ 0x0001, 1 }, -{ 0, 0 } -}; - -static struct proto VR[] = { -{ 0x0006, (1<<4)+3 }, -{ 0x0030, (2<<4)+6 }, -{ 0x0060, (3<<4)+7 }, -{ 0, 0 } -}; - -static struct proto VL[] = { -{ 0x0002, (1<<4)+3 }, -{ 0x0010, (2<<4)+6 }, -{ 0x0020, (3<<4)+7 }, -{ 0, 0 } -}; - -static struct proto Ext[] = { -{ 0x0040, 7 }, -{ 0, 0 } -}; - -static struct proto EOLV[] = { -{ 0x0000, 7 }, -{ 0, 0 } -}; - -static struct proto MakeUpW[] = { -{ 0x001b, 1029 }, -{ 0x0009, 2053 }, -{ 0x003a, 3078 }, -{ 0x0076, 4103 }, -{ 0x006c, 5128 }, -{ 0x00ec, 6152 }, -{ 0x0026, 7176 }, -{ 0x00a6, 8200 }, -{ 0x0016, 9224 }, -{ 0x00e6, 10248 }, -{ 0x0066, 11273 }, -{ 0x0166, 12297 }, -{ 0x0096, 13321 }, -{ 0x0196, 14345 }, -{ 0x0056, 15369 }, -{ 0x0156, 16393 }, -{ 0x00d6, 17417 }, -{ 0x01d6, 18441 }, -{ 0x0036, 19465 }, -{ 0x0136, 20489 }, -{ 0x00b6, 21513 }, -{ 0x01b6, 22537 }, -{ 0x0032, 23561 }, -{ 0x0132, 24585 }, -{ 0x00b2, 25609 }, -{ 0x0006, 26630 }, -{ 0x01b2, 27657 }, -{ 0, 0 } -}; - -static struct proto MakeUpB[] = { -{ 0x03c0, 1034 }, -{ 0x0130, 2060 }, -{ 0x0930, 3084 }, -{ 0x0da0, 4108 }, -{ 0x0cc0, 5132 }, -{ 0x02c0, 6156 }, -{ 0x0ac0, 7180 }, -{ 0x06c0, 8205 }, -{ 0x16c0, 9229 }, -{ 0x0a40, 10253 }, -{ 0x1a40, 11277 }, -{ 0x0640, 12301 }, -{ 0x1640, 13325 }, -{ 0x09c0, 14349 }, -{ 0x19c0, 15373 }, -{ 0x05c0, 16397 }, -{ 0x15c0, 17421 }, -{ 0x0dc0, 18445 }, -{ 0x1dc0, 19469 }, -{ 0x0940, 20493 }, -{ 0x1940, 21517 }, -{ 0x0540, 22541 }, -{ 0x1540, 23565 }, -{ 0x0b40, 24589 }, -{ 0x1b40, 25613 }, -{ 0x04c0, 26637 }, -{ 0x14c0, 27661 }, -{ 0, 0 } -}; - -static struct proto MakeUp[] = { -{ 0x0080, 28683 }, -{ 0x0180, 29707 }, -{ 0x0580, 30731 }, -{ 0x0480, 31756 }, -{ 0x0c80, 32780 }, -{ 0x0280, 33804 }, -{ 0x0a80, 34828 }, -{ 0x0680, 35852 }, -{ 0x0e80, 36876 }, -{ 0x0380, 37900 }, -{ 0x0b80, 38924 }, -{ 0x0780, 39948 }, -{ 0x0f80, 40972 }, -{ 0, 0 } -}; - -static struct proto TermW[] = { -{ 0x00ac, 8 }, -{ 0x0038, 22 }, -{ 0x000e, 36 }, -{ 0x0001, 52 }, -{ 0x000d, 68 }, -{ 0x0003, 84 }, -{ 0x0007, 100 }, -{ 0x000f, 116 }, -{ 0x0019, 133 }, -{ 0x0005, 149 }, -{ 0x001c, 165 }, -{ 0x0002, 181 }, -{ 0x0004, 198 }, -{ 0x0030, 214 }, -{ 0x000b, 230 }, -{ 0x002b, 246 }, -{ 0x0015, 262 }, -{ 0x0035, 278 }, -{ 0x0072, 295 }, -{ 0x0018, 311 }, -{ 0x0008, 327 }, -{ 0x0074, 343 }, -{ 0x0060, 359 }, -{ 0x0010, 375 }, -{ 0x000a, 391 }, -{ 0x006a, 407 }, -{ 0x0064, 423 }, -{ 0x0012, 439 }, -{ 0x000c, 455 }, -{ 0x0040, 472 }, -{ 0x00c0, 488 }, -{ 0x0058, 504 }, -{ 0x00d8, 520 }, -{ 0x0048, 536 }, -{ 0x00c8, 552 }, -{ 0x0028, 568 }, -{ 0x00a8, 584 }, -{ 0x0068, 600 }, -{ 0x00e8, 616 }, -{ 0x0014, 632 }, -{ 0x0094, 648 }, -{ 0x0054, 664 }, -{ 0x00d4, 680 }, -{ 0x0034, 696 }, -{ 0x00b4, 712 }, -{ 0x0020, 728 }, -{ 0x00a0, 744 }, -{ 0x0050, 760 }, -{ 0x00d0, 776 }, -{ 0x004a, 792 }, -{ 0x00ca, 808 }, -{ 0x002a, 824 }, -{ 0x00aa, 840 }, -{ 0x0024, 856 }, -{ 0x00a4, 872 }, -{ 0x001a, 888 }, -{ 0x009a, 904 }, -{ 0x005a, 920 }, -{ 0x00da, 936 }, -{ 0x0052, 952 }, -{ 0x00d2, 968 }, -{ 0x004c, 984 }, -{ 0x00cc, 1000 }, -{ 0x002c, 1016 }, -{ 0, 0 } -}; - -static struct proto TermB[] = { -{ 0x03b0, 10 }, -{ 0x0002, 19 }, -{ 0x0003, 34 }, -{ 0x0001, 50 }, -{ 0x0006, 67 }, -{ 0x000c, 84 }, -{ 0x0004, 100 }, -{ 0x0018, 117 }, -{ 0x0028, 134 }, -{ 0x0008, 150 }, -{ 0x0010, 167 }, -{ 0x0050, 183 }, -{ 0x0070, 199 }, -{ 0x0020, 216 }, -{ 0x00e0, 232 }, -{ 0x0030, 249 }, -{ 0x03a0, 266 }, -{ 0x0060, 282 }, -{ 0x0040, 298 }, -{ 0x0730, 315 }, -{ 0x00b0, 331 }, -{ 0x01b0, 347 }, -{ 0x0760, 363 }, -{ 0x00a0, 379 }, -{ 0x0740, 395 }, -{ 0x00c0, 411 }, -{ 0x0530, 428 }, -{ 0x0d30, 444 }, -{ 0x0330, 460 }, -{ 0x0b30, 476 }, -{ 0x0160, 492 }, -{ 0x0960, 508 }, -{ 0x0560, 524 }, -{ 0x0d60, 540 }, -{ 0x04b0, 556 }, -{ 0x0cb0, 572 }, -{ 0x02b0, 588 }, -{ 0x0ab0, 604 }, -{ 0x06b0, 620 }, -{ 0x0eb0, 636 }, -{ 0x0360, 652 }, -{ 0x0b60, 668 }, -{ 0x05b0, 684 }, -{ 0x0db0, 700 }, -{ 0x02a0, 716 }, -{ 0x0aa0, 732 }, -{ 0x06a0, 748 }, -{ 0x0ea0, 764 }, -{ 0x0260, 780 }, -{ 0x0a60, 796 }, -{ 0x04a0, 812 }, -{ 0x0ca0, 828 }, -{ 0x0240, 844 }, -{ 0x0ec0, 860 }, -{ 0x01c0, 876 }, -{ 0x0e40, 892 }, -{ 0x0140, 908 }, -{ 0x01a0, 924 }, -{ 0x09a0, 940 }, -{ 0x0d40, 956 }, -{ 0x0340, 972 }, -{ 0x05a0, 988 }, -{ 0x0660, 1004 }, -{ 0x0e60, 1020 }, -{ 0, 0 } -}; - -static struct proto EOLH[] = { -{ 0x0000, 11 }, -{ 0, 0 } -}; - -static void -FillTable(TIFFFaxTabEnt *T, int Size, struct proto *P, int State) -{ - int limit = 1 << Size; - - while (P->val) { - int width = P->val & 15; - int param = P->val >> 4; - int incr = 1 << width; - int code; - for (code = P->code; code < limit; code += incr) { - TIFFFaxTabEnt *E = T+code; - E->State = State; - E->Width = width; - E->Param = param; - } - P++; - } -} - -static char* storage_class = ""; -static char* const_class = ""; -static int packoutput = 1; -static char* prebrace = ""; -static char* postbrace = ""; - -void -WriteTable(FILE* fd, const TIFFFaxTabEnt* T, int Size, const char* name) -{ - int i; - char* sep; - - fprintf(fd, "%s %s TIFFFaxTabEnt %s[%d] = {", - storage_class, const_class, name, Size); - if (packoutput) { - sep = "\n"; - for (i = 0; i < Size; i++) { - fprintf(fd, "%s%s%d,%d,%d%s", - sep, prebrace, T->State, T->Width, (int) T->Param, postbrace); - if (((i+1) % 10) == 0) - sep = ",\n"; - else - sep = ","; - T++; - } - } else { - sep = "\n "; - for (i = 0; i < Size; i++) { - fprintf(fd, "%s%s%3d,%3d,%4d%s", - sep, prebrace, T->State, T->Width, (int) T->Param, postbrace); - if (((i+1) % 6) == 0) - sep = ",\n "; - else - sep = ","; - T++; - } - } - fprintf(fd, "\n};\n"); -} - -/* initialise the huffman code tables */ -int -main(int argc, char* argv[]) -{ - FILE* fd; - char* outputfile; - int c; - extern int optind; - extern char* optarg; - - while ((c = getopt(argc, argv, "c:s:bp")) != -1) - switch (c) { - case 'c': - const_class = optarg; - break; - case 's': - storage_class = optarg; - break; - case 'p': - packoutput = 0; - break; - case 'b': - prebrace = "{"; - postbrace = "}"; - break; - case '?': - fprintf(stderr, - "usage: %s [-c const] [-s storage] [-p] [-b] file\n", - argv[0]); - return (-1); - } - outputfile = optind < argc ? argv[optind] : "g3states.h"; - fd = fopen(outputfile, "w"); - if (fd == NULL) { - fprintf(stderr, "%s: %s: Cannot create output file.\n", - argv[0], outputfile); - return (-2); - } - FillTable(MainTable, 7, Pass, S_Pass); - FillTable(MainTable, 7, Horiz, S_Horiz); - FillTable(MainTable, 7, V0, S_V0); - FillTable(MainTable, 7, VR, S_VR); - FillTable(MainTable, 7, VL, S_VL); - FillTable(MainTable, 7, Ext, S_Ext); - FillTable(MainTable, 7, EOLV, S_EOL); - FillTable(WhiteTable, 12, MakeUpW, S_MakeUpW); - FillTable(WhiteTable, 12, MakeUp, S_MakeUp); - FillTable(WhiteTable, 12, TermW, S_TermW); - FillTable(WhiteTable, 12, EOLH, S_EOL); - FillTable(BlackTable, 13, MakeUpB, S_MakeUpB); - FillTable(BlackTable, 13, MakeUp, S_MakeUp); - FillTable(BlackTable, 13, TermB, S_TermB); - FillTable(BlackTable, 13, EOLH, S_EOL); - - fprintf(fd, "/* WARNING, this file was automatically generated by the\n"); - fprintf(fd, " mkg3states program */\n"); - fprintf(fd, "#include \"tiff.h\"\n"); - fprintf(fd, "#include \"tif_fax3.h\"\n"); - WriteTable(fd, MainTable, 128, "TIFFFaxMainTable"); - WriteTable(fd, WhiteTable, 4096, "TIFFFaxWhiteTable"); - WriteTable(fd, BlackTable, 8192, "TIFFFaxBlackTable"); - fclose(fd); - return (0); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* "$Id: mkg3states.c,v 1.37 2011/04/10 17:14:09 drolon Exp $ */ + +/* + * Copyright (c) 1991-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* Initialise fax decoder tables + * Decoder support is derived, with permission, from the code + * in Frank Cringle's viewfax program; + * Copyright (C) 1990, 1995 Frank D. Cringle. + */ +#include "tif_config.h" + +#include +#include +#include + +#ifdef HAVE_UNISTD_H +# include +#endif + +#include "tif_fax3.h" + +#ifndef HAVE_GETOPT +extern int getopt(int, char**, char*); +#endif + +#define streq(a,b) (strcmp(a,b) == 0) + +/* NB: can't use names in tif_fax3.h 'cuz they are declared const */ +TIFFFaxTabEnt MainTable[128]; +TIFFFaxTabEnt WhiteTable[4096]; +TIFFFaxTabEnt BlackTable[8192]; + +struct proto { + uint16 code; /* right justified, lsb-first, zero filled */ + uint16 val; /* (pixel count)<<4 + code width */ +}; + +static struct proto Pass[] = { +{ 0x0008, 4 }, +{ 0, 0 } +}; + +static struct proto Horiz[] = { +{ 0x0004, 3 }, +{ 0, 0 } +}; + +static struct proto V0[] = { +{ 0x0001, 1 }, +{ 0, 0 } +}; + +static struct proto VR[] = { +{ 0x0006, (1<<4)+3 }, +{ 0x0030, (2<<4)+6 }, +{ 0x0060, (3<<4)+7 }, +{ 0, 0 } +}; + +static struct proto VL[] = { +{ 0x0002, (1<<4)+3 }, +{ 0x0010, (2<<4)+6 }, +{ 0x0020, (3<<4)+7 }, +{ 0, 0 } +}; + +static struct proto Ext[] = { +{ 0x0040, 7 }, +{ 0, 0 } +}; + +static struct proto EOLV[] = { +{ 0x0000, 7 }, +{ 0, 0 } +}; + +static struct proto MakeUpW[] = { +{ 0x001b, 1029 }, +{ 0x0009, 2053 }, +{ 0x003a, 3078 }, +{ 0x0076, 4103 }, +{ 0x006c, 5128 }, +{ 0x00ec, 6152 }, +{ 0x0026, 7176 }, +{ 0x00a6, 8200 }, +{ 0x0016, 9224 }, +{ 0x00e6, 10248 }, +{ 0x0066, 11273 }, +{ 0x0166, 12297 }, +{ 0x0096, 13321 }, +{ 0x0196, 14345 }, +{ 0x0056, 15369 }, +{ 0x0156, 16393 }, +{ 0x00d6, 17417 }, +{ 0x01d6, 18441 }, +{ 0x0036, 19465 }, +{ 0x0136, 20489 }, +{ 0x00b6, 21513 }, +{ 0x01b6, 22537 }, +{ 0x0032, 23561 }, +{ 0x0132, 24585 }, +{ 0x00b2, 25609 }, +{ 0x0006, 26630 }, +{ 0x01b2, 27657 }, +{ 0, 0 } +}; + +static struct proto MakeUpB[] = { +{ 0x03c0, 1034 }, +{ 0x0130, 2060 }, +{ 0x0930, 3084 }, +{ 0x0da0, 4108 }, +{ 0x0cc0, 5132 }, +{ 0x02c0, 6156 }, +{ 0x0ac0, 7180 }, +{ 0x06c0, 8205 }, +{ 0x16c0, 9229 }, +{ 0x0a40, 10253 }, +{ 0x1a40, 11277 }, +{ 0x0640, 12301 }, +{ 0x1640, 13325 }, +{ 0x09c0, 14349 }, +{ 0x19c0, 15373 }, +{ 0x05c0, 16397 }, +{ 0x15c0, 17421 }, +{ 0x0dc0, 18445 }, +{ 0x1dc0, 19469 }, +{ 0x0940, 20493 }, +{ 0x1940, 21517 }, +{ 0x0540, 22541 }, +{ 0x1540, 23565 }, +{ 0x0b40, 24589 }, +{ 0x1b40, 25613 }, +{ 0x04c0, 26637 }, +{ 0x14c0, 27661 }, +{ 0, 0 } +}; + +static struct proto MakeUp[] = { +{ 0x0080, 28683 }, +{ 0x0180, 29707 }, +{ 0x0580, 30731 }, +{ 0x0480, 31756 }, +{ 0x0c80, 32780 }, +{ 0x0280, 33804 }, +{ 0x0a80, 34828 }, +{ 0x0680, 35852 }, +{ 0x0e80, 36876 }, +{ 0x0380, 37900 }, +{ 0x0b80, 38924 }, +{ 0x0780, 39948 }, +{ 0x0f80, 40972 }, +{ 0, 0 } +}; + +static struct proto TermW[] = { +{ 0x00ac, 8 }, +{ 0x0038, 22 }, +{ 0x000e, 36 }, +{ 0x0001, 52 }, +{ 0x000d, 68 }, +{ 0x0003, 84 }, +{ 0x0007, 100 }, +{ 0x000f, 116 }, +{ 0x0019, 133 }, +{ 0x0005, 149 }, +{ 0x001c, 165 }, +{ 0x0002, 181 }, +{ 0x0004, 198 }, +{ 0x0030, 214 }, +{ 0x000b, 230 }, +{ 0x002b, 246 }, +{ 0x0015, 262 }, +{ 0x0035, 278 }, +{ 0x0072, 295 }, +{ 0x0018, 311 }, +{ 0x0008, 327 }, +{ 0x0074, 343 }, +{ 0x0060, 359 }, +{ 0x0010, 375 }, +{ 0x000a, 391 }, +{ 0x006a, 407 }, +{ 0x0064, 423 }, +{ 0x0012, 439 }, +{ 0x000c, 455 }, +{ 0x0040, 472 }, +{ 0x00c0, 488 }, +{ 0x0058, 504 }, +{ 0x00d8, 520 }, +{ 0x0048, 536 }, +{ 0x00c8, 552 }, +{ 0x0028, 568 }, +{ 0x00a8, 584 }, +{ 0x0068, 600 }, +{ 0x00e8, 616 }, +{ 0x0014, 632 }, +{ 0x0094, 648 }, +{ 0x0054, 664 }, +{ 0x00d4, 680 }, +{ 0x0034, 696 }, +{ 0x00b4, 712 }, +{ 0x0020, 728 }, +{ 0x00a0, 744 }, +{ 0x0050, 760 }, +{ 0x00d0, 776 }, +{ 0x004a, 792 }, +{ 0x00ca, 808 }, +{ 0x002a, 824 }, +{ 0x00aa, 840 }, +{ 0x0024, 856 }, +{ 0x00a4, 872 }, +{ 0x001a, 888 }, +{ 0x009a, 904 }, +{ 0x005a, 920 }, +{ 0x00da, 936 }, +{ 0x0052, 952 }, +{ 0x00d2, 968 }, +{ 0x004c, 984 }, +{ 0x00cc, 1000 }, +{ 0x002c, 1016 }, +{ 0, 0 } +}; + +static struct proto TermB[] = { +{ 0x03b0, 10 }, +{ 0x0002, 19 }, +{ 0x0003, 34 }, +{ 0x0001, 50 }, +{ 0x0006, 67 }, +{ 0x000c, 84 }, +{ 0x0004, 100 }, +{ 0x0018, 117 }, +{ 0x0028, 134 }, +{ 0x0008, 150 }, +{ 0x0010, 167 }, +{ 0x0050, 183 }, +{ 0x0070, 199 }, +{ 0x0020, 216 }, +{ 0x00e0, 232 }, +{ 0x0030, 249 }, +{ 0x03a0, 266 }, +{ 0x0060, 282 }, +{ 0x0040, 298 }, +{ 0x0730, 315 }, +{ 0x00b0, 331 }, +{ 0x01b0, 347 }, +{ 0x0760, 363 }, +{ 0x00a0, 379 }, +{ 0x0740, 395 }, +{ 0x00c0, 411 }, +{ 0x0530, 428 }, +{ 0x0d30, 444 }, +{ 0x0330, 460 }, +{ 0x0b30, 476 }, +{ 0x0160, 492 }, +{ 0x0960, 508 }, +{ 0x0560, 524 }, +{ 0x0d60, 540 }, +{ 0x04b0, 556 }, +{ 0x0cb0, 572 }, +{ 0x02b0, 588 }, +{ 0x0ab0, 604 }, +{ 0x06b0, 620 }, +{ 0x0eb0, 636 }, +{ 0x0360, 652 }, +{ 0x0b60, 668 }, +{ 0x05b0, 684 }, +{ 0x0db0, 700 }, +{ 0x02a0, 716 }, +{ 0x0aa0, 732 }, +{ 0x06a0, 748 }, +{ 0x0ea0, 764 }, +{ 0x0260, 780 }, +{ 0x0a60, 796 }, +{ 0x04a0, 812 }, +{ 0x0ca0, 828 }, +{ 0x0240, 844 }, +{ 0x0ec0, 860 }, +{ 0x01c0, 876 }, +{ 0x0e40, 892 }, +{ 0x0140, 908 }, +{ 0x01a0, 924 }, +{ 0x09a0, 940 }, +{ 0x0d40, 956 }, +{ 0x0340, 972 }, +{ 0x05a0, 988 }, +{ 0x0660, 1004 }, +{ 0x0e60, 1020 }, +{ 0, 0 } +}; + +static struct proto EOLH[] = { +{ 0x0000, 11 }, +{ 0, 0 } +}; + +static void +FillTable(TIFFFaxTabEnt *T, int Size, struct proto *P, int State) +{ + int limit = 1 << Size; + + while (P->val) { + int width = P->val & 15; + int param = P->val >> 4; + int incr = 1 << width; + int code; + for (code = P->code; code < limit; code += incr) { + TIFFFaxTabEnt *E = T+code; + E->State = State; + E->Width = width; + E->Param = param; + } + P++; + } +} + +static char* storage_class = ""; +static char* const_class = ""; +static int packoutput = 1; +static char* prebrace = ""; +static char* postbrace = ""; + +void +WriteTable(FILE* fd, const TIFFFaxTabEnt* T, int Size, const char* name) +{ + int i; + char* sep; + + fprintf(fd, "%s %s TIFFFaxTabEnt %s[%d] = {", + storage_class, const_class, name, Size); + if (packoutput) { + sep = "\n"; + for (i = 0; i < Size; i++) { + fprintf(fd, "%s%s%d,%d,%d%s", + sep, prebrace, T->State, T->Width, (int) T->Param, postbrace); + if (((i+1) % 10) == 0) + sep = ",\n"; + else + sep = ","; + T++; + } + } else { + sep = "\n "; + for (i = 0; i < Size; i++) { + fprintf(fd, "%s%s%3d,%3d,%4d%s", + sep, prebrace, T->State, T->Width, (int) T->Param, postbrace); + if (((i+1) % 6) == 0) + sep = ",\n "; + else + sep = ","; + T++; + } + } + fprintf(fd, "\n};\n"); +} + +/* initialise the huffman code tables */ +int +main(int argc, char* argv[]) +{ + FILE* fd; + char* outputfile; + int c; + extern int optind; + extern char* optarg; + + while ((c = getopt(argc, argv, "c:s:bp")) != -1) + switch (c) { + case 'c': + const_class = optarg; + break; + case 's': + storage_class = optarg; + break; + case 'p': + packoutput = 0; + break; + case 'b': + prebrace = "{"; + postbrace = "}"; + break; + case '?': + fprintf(stderr, + "usage: %s [-c const] [-s storage] [-p] [-b] file\n", + argv[0]); + return (-1); + } + outputfile = optind < argc ? argv[optind] : "g3states.h"; + fd = fopen(outputfile, "w"); + if (fd == NULL) { + fprintf(stderr, "%s: %s: Cannot create output file.\n", + argv[0], outputfile); + return (-2); + } + FillTable(MainTable, 7, Pass, S_Pass); + FillTable(MainTable, 7, Horiz, S_Horiz); + FillTable(MainTable, 7, V0, S_V0); + FillTable(MainTable, 7, VR, S_VR); + FillTable(MainTable, 7, VL, S_VL); + FillTable(MainTable, 7, Ext, S_Ext); + FillTable(MainTable, 7, EOLV, S_EOL); + FillTable(WhiteTable, 12, MakeUpW, S_MakeUpW); + FillTable(WhiteTable, 12, MakeUp, S_MakeUp); + FillTable(WhiteTable, 12, TermW, S_TermW); + FillTable(WhiteTable, 12, EOLH, S_EOL); + FillTable(BlackTable, 13, MakeUpB, S_MakeUpB); + FillTable(BlackTable, 13, MakeUp, S_MakeUp); + FillTable(BlackTable, 13, TermB, S_TermB); + FillTable(BlackTable, 13, EOLH, S_EOL); + + fprintf(fd, "/* WARNING, this file was automatically generated by the\n"); + fprintf(fd, " mkg3states program */\n"); + fprintf(fd, "#include \"tiff.h\"\n"); + fprintf(fd, "#include \"tif_fax3.h\"\n"); + WriteTable(fd, MainTable, 128, "TIFFFaxMainTable"); + WriteTable(fd, WhiteTable, 4096, "TIFFFaxWhiteTable"); + WriteTable(fd, BlackTable, 8192, "TIFFFaxBlackTable"); + fclose(fd); + return (0); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF/mkspans.c b/Source/LibTIFF/mkspans.c index 61be306..21af952 100644 --- a/Source/LibTIFF/mkspans.c +++ b/Source/LibTIFF/mkspans.c @@ -1,82 +1,82 @@ -/* $Id: mkspans.c,v 1.22 2011/04/10 17:14:09 drolon Exp $ */ - -/* - * Copyright (c) 1991-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include -#include - -/* - * Hack program to construct tables used to find - * runs of zeros and ones in Group 3 Fax encoding. - */ - -dumparray(name, runs) - char *name; - unsigned char runs[256]; -{ - int i; - char *sep; - printf("static unsigned char %s[256] = {\n", name); - sep = " "; - for (i = 0; i < 256; i++) { - printf("%s%d", sep, runs[i]); - if (((i + 1) % 16) == 0) { - printf(", /* 0x%02x - 0x%02x */\n", i-15, i); - sep = " "; - } else - sep = ", "; - } - printf("\n};\n"); -} - -main() -{ - unsigned char runs[2][256]; - - memset(runs[0], 0, 256*sizeof (char)); - memset(runs[1], 0, 256*sizeof (char)); - { register int run, runlen, i; - runlen = 1; - for (run = 0x80; run != 0xff; run = (run>>1)|0x80) { - for (i = run-1; i >= 0; i--) { - runs[1][run|i] = runlen; - runs[0][(~(run|i)) & 0xff] = runlen; - } - runlen++; - } - runs[1][0xff] = runs[0][0] = 8; - } - dumparray("bruns", runs[0]); - dumparray("wruns", runs[1]); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: mkspans.c,v 1.22 2011/04/10 17:14:09 drolon Exp $ */ + +/* + * Copyright (c) 1991-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include + +/* + * Hack program to construct tables used to find + * runs of zeros and ones in Group 3 Fax encoding. + */ + +dumparray(name, runs) + char *name; + unsigned char runs[256]; +{ + int i; + char *sep; + printf("static unsigned char %s[256] = {\n", name); + sep = " "; + for (i = 0; i < 256; i++) { + printf("%s%d", sep, runs[i]); + if (((i + 1) % 16) == 0) { + printf(", /* 0x%02x - 0x%02x */\n", i-15, i); + sep = " "; + } else + sep = ", "; + } + printf("\n};\n"); +} + +main() +{ + unsigned char runs[2][256]; + + memset(runs[0], 0, 256*sizeof (char)); + memset(runs[1], 0, 256*sizeof (char)); + { register int run, runlen, i; + runlen = 1; + for (run = 0x80; run != 0xff; run = (run>>1)|0x80) { + for (i = run-1; i >= 0; i--) { + runs[1][run|i] = runlen; + runs[0][(~(run|i)) & 0xff] = runlen; + } + runlen++; + } + runs[1][0xff] = runs[0][0] = 8; + } + dumparray("bruns", runs[0]); + dumparray("wruns", runs[1]); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF/tif_acorn.c b/Source/LibTIFF/tif_acorn.c index d2de42d..66e197e 100644 --- a/Source/LibTIFF/tif_acorn.c +++ b/Source/LibTIFF/tif_acorn.c @@ -1,526 +1,526 @@ -/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF/tif_acorn.c,v 1.37 2011/04/10 17:14:09 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library RISC OS specific Routines. - * Developed out of the Unix version. - * Peter Greenham, May 1995 - */ -#include "tiffiop.h" -#include -#include - -/* -Low-level file handling -~~~~~~~~~~~~~~~~~~~~~~~ -The functions in osfcn.h are unavailable when compiling under C, as it's a -C++ header. Therefore they have been implemented here. - -Now, why have I done it this way? - -The definitive API library for RISC OS is Jonathan Coxhead's OSLib, which -uses heavily optimised ARM assembler or even plain inline SWI calls for -maximum performance and minimum runtime size. However, I don't want to make -LIBTIFF need that to survive. Therefore I have also emulated the functions -using macros to _swi() and _swix() defined in the swis.h header, and -borrowing types from kernel.h, which is less efficient but doesn't need any -third-party libraries. - */ - -#ifdef INCLUDE_OSLIB - -#include "osfile.h" -#include "osgbpb.h" -#include "osargs.h" -#include "osfind.h" - -#else - -/* OSLIB EMULATION STARTS */ - -#include "kernel.h" -#include "swis.h" - -/* From oslib:types.h */ -typedef unsigned int bits; -typedef unsigned char byte; -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef NULL -#define NULL 0 -#endif -#ifndef SKIP -#define SKIP 0 -#endif - -/* From oslib:os.h */ -typedef _kernel_oserror os_error; -typedef byte os_f; - -/* From oslib:osfile.h */ -#undef OS_File -#define OS_File 0x8 - -/* From oslib:osgbpb.h */ -#undef OS_GBPB -#define OS_GBPB 0xC -#undef OSGBPB_Write -#define OSGBPB_Write 0x2 -#undef OSGBPB_Read -#define OSGBPB_Read 0x4 - -extern os_error *xosgbpb_write (os_f file, - byte *data, - int size, - int *unwritten); -extern int osgbpb_write (os_f file, - byte *data, - int size); - -#define xosgbpb_write(file, data, size, unwritten) \ - (os_error*) _swix(OS_GBPB, _IN(0)|_IN(1)|_IN(2)|_IN(3)|_IN(4)|_OUT(3), \ - OSGBPB_WriteAt, \ - file, \ - data, \ - size, \ - unwritten) - -#define osgbpb_write(file, data, size) \ - _swi(OS_GBPB, _IN(0)|_IN(1)|_IN(2)|_IN(3)|_RETURN(3), \ - OSGBPB_Write, \ - file, \ - data, \ - size) - -extern os_error *xosgbpb_read (os_f file, - byte *buffer, - int size, - int *unread); -extern int osgbpb_read (os_f file, - byte *buffer, - int size); - -#define xosgbpb_read(file, buffer, size, unread) \ - (os_error*) _swix(OS_GBPB, _IN(0)|_IN(1)|_IN(2)|_IN(3)|_OUT(3), \ - OSGBPB_Read, \ - file, \ - buffer, \ - size, \ - unread) - -#define osgbpb_read(file, buffer, size) \ - _swi(OS_GBPB, _IN(0)|_IN(1)|_IN(2)|_IN(3)|_RETURN(3), \ - OSGBPB_Read, \ - file, \ - buffer, \ - size) - -/* From oslib:osfind.h */ -#undef OS_Find -#define OS_Find 0xD -#undef OSFind_Openin -#define OSFind_Openin 0x40 -#undef OSFind_Openout -#define OSFind_Openout 0x80 -#undef OSFind_Openup -#define OSFind_Openup 0xC0 -#undef OSFind_Close -#define OSFind_Close 0x0 - -#define xosfind_open(reason, file_name, path, file) \ - (os_error*) _swix(OS_Find, _IN(0)|_IN(1)|_IN(2)|_OUT(0), \ - reason, file_name, path, file) - -#define osfind_open(reason, file_name, path) \ - (os_f) _swi(OS_Find, _IN(0)|_IN(1)|_IN(2)|_RETURN(0), \ - reason, file_name, path) - -extern os_error *xosfind_openin (bits flags, - char *file_name, - char *path, - os_f *file); -extern os_f osfind_openin (bits flags, - char *file_name, - char *path); - -#define xosfind_openin(flags, file_name, path, file) \ - xosfind_open(flags | OSFind_Openin, file_name, path, file) - -#define osfind_openin(flags, file_name, path) \ - osfind_open(flags | OSFind_Openin, file_name, path) - -extern os_error *xosfind_openout (bits flags, - char *file_name, - char *path, - os_f *file); -extern os_f osfind_openout (bits flags, - char *file_name, - char *path); - -#define xosfind_openout(flags, file_name, path, file) \ - xosfind_open(flags | OSFind_Openout, file_name, path, file) - -#define osfind_openout(flags, file_name, path) \ - osfind_open(flags | OSFind_Openout, file_name, path) - -extern os_error *xosfind_openup (bits flags, - char *file_name, - char *path, - os_f *file); -extern os_f osfind_openup (bits flags, - char *file_name, - char *path); - -#define xosfind_openup(flags, file_name, path, file) \ - xosfind_open(flags | OSFind_Openup, file_name, path, file) - -#define osfind_openup(flags, file_name, path) \ - osfind_open(flags | OSFind_Openup, file_name, path) - -extern os_error *xosfind_close (os_f file); -extern void osfind_close (os_f file); - -#define xosfind_close(file) \ - (os_error*) _swix(OS_Find, _IN(0)|_IN(1), \ - OSFind_Close, \ - file) - -#define osfind_close(file) \ - (void) _swi(OS_Find, _IN(0)|_IN(1), \ - OSFind_Close, \ - file) - -/* From oslib:osargs.h */ -#undef OS_Args -#define OS_Args 0x9 -#undef OSArgs_ReadPtr -#define OSArgs_ReadPtr 0x0 -#undef OSArgs_SetPtr -#define OSArgs_SetPtr 0x1 -#undef OSArgs_ReadExt -#define OSArgs_ReadExt 0x2 - -extern os_error *xosargs_read_ptr (os_f file, - int *ptr); -extern int osargs_read_ptr (os_f file); - -#define xosargs_read_ptr(file, ptr) \ - (os_error*) _swix(OS_Args, _IN(0)|_IN(1)|_OUT(2), \ - OSArgs_ReadPtr, \ - file, \ - ptr) - -#define osargs_read_ptr(file) \ - _swi(OS_Args, _IN(0)|_IN(1)|_RETURN(2), \ - OSArgs_ReadPtr, \ - file) - -extern os_error *xosargs_set_ptr (os_f file, - int ptr); -extern void osargs_set_ptr (os_f file, - int ptr); - -#define xosargs_set_ptr(file, ptr) \ - (os_error*) _swix(OS_Args, _IN(0)|_IN(1)|_IN(2), \ - OSArgs_SetPtr, \ - file, \ - ptr) - -#define osargs_set_ptr(file, ptr) \ - (void) _swi(OS_Args, _IN(0)|_IN(1)|_IN(2), \ - OSArgs_SetPtr, \ - file, \ - ptr) - -extern os_error *xosargs_read_ext (os_f file, - int *ext); -extern int osargs_read_ext (os_f file); - -#define xosargs_read_ext(file, ext) \ - (os_error*) _swix(OS_Args, _IN(0)|_IN(1)|_OUT(2), \ - OSArgs_ReadExt, \ - file, \ - ext) - -#define osargs_read_ext(file) \ - _swi(OS_Args, _IN(0)|_IN(1)|_RETURN(2), \ - OSArgs_ReadExt, \ - file) - -/* OSLIB EMULATION ENDS */ - -#endif - -#ifndef __osfcn_h -/* Will be set or not during tiffcomp.h */ -/* You get this to compile under C++? Please say how! */ - -extern int open(const char* name, int flags, int mode) -{ - /* From what I can tell, should return <0 for failure */ - os_error* e = (os_error*) 1; /* Cheeky way to use a pointer eh? :-) */ - os_f file = (os_f) -1; - - flags = flags; - - switch(mode) - { - case O_RDONLY: - { - e = xosfind_openin(SKIP, name, SKIP, &file); - break; - } - case O_WRONLY: - case O_RDWR|O_CREAT: - case O_RDWR|O_CREAT|O_TRUNC: - { - e = xosfind_openout(SKIP, name, SKIP, &file); - break; - } - case O_RDWR: - { - e = xosfind_openup(SKIP, name, SKIP, &file); - break; - } - } - if (e) - { - file = (os_f) -1; - } - return (file); -} - -extern int close(int fd) -{ - return ((int) xosfind_close((os_f) fd)); -} - -extern int write(int fd, const char *buf, int nbytes) -{ - /* Returns number of bytes written */ - return (nbytes - osgbpb_write((os_f) fd, (const byte*) buf, nbytes)); -} - -extern int read(int fd, char *buf, int nbytes) -{ - /* Returns number of bytes read */ - return (nbytes - osgbpb_read((os_f) fd, (byte*) buf, nbytes)); -} - -extern off_t lseek(int fd, off_t offset, int whence) -{ - int absolute = 0; - - switch (whence) - { - case SEEK_SET: - { - absolute = (int) offset; - break; - } - case SEEK_CUR: - { - absolute = osargs_read_ptr((os_f) fd) + (int) offset; - break; - } - case SEEK_END: - { - absolute = osargs_read_ext((os_f) fd) + (int) offset; - break; - } - } - - osargs_set_ptr((os_f) fd, absolute); - - return ((off_t) osargs_read_ptr((os_f) fd)); -} -#endif - -static tsize_t -_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - return ((tsize_t) read((int) fd, buf, (size_t) size)); -} - -static tsize_t -_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - return ((tsize_t) write((int) fd, buf, (size_t) size)); -} - -static toff_t -_tiffSeekProc(thandle_t fd, toff_t off, int whence) -{ - return ((toff_t) lseek((int) fd, (off_t) off, whence)); -} - -static int -_tiffCloseProc(thandle_t fd) -{ - return (close((int) fd)); -} - -static toff_t -_tiffSizeProc(thandle_t fd) -{ - return (lseek((int) fd, SEEK_END, SEEK_SET)); -} - -#ifdef HAVE_MMAP -#error "I didn't know Acorn had that!" -#endif - -/* !HAVE_MMAP */ -static int -_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) -{ - (void) fd; (void) pbase; (void) psize; - return (0); -} - -static void -_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) -{ - (void) fd; (void) base; (void) size; -} - -/* - * Open a TIFF file descriptor for read/writing. - */ -TIFF* -TIFFFdOpen(int fd, const char* name, const char* mode) -{ - TIFF* tif; - - tif = TIFFClientOpen(name, mode, - (thandle_t) fd, - _tiffReadProc, _tiffWriteProc, - _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, - _tiffMapProc, _tiffUnmapProc); - if (tif) - { - tif->tif_fd = fd; - } - return (tif); -} - -/* - * Open a TIFF file for read/writing. - */ -TIFF* -TIFFOpen(const char* name, const char* mode) -{ - static const char module[] = "TIFFOpen"; - int m, fd; - - m = _TIFFgetMode(mode, module); - - if (m == -1) - { - return ((TIFF*) 0); - } - - fd = open(name, 0, m); - - if (fd < 0) - { - TIFFErrorExt(0, module, "%s: Cannot open", name); - return ((TIFF *)0); - } - return (TIFFFdOpen(fd, name, mode)); -} - -void* -_TIFFmalloc(tsize_t s) -{ - return (malloc((size_t) s)); -} - -void -_TIFFfree(tdata_t p) -{ - free(p); -} - -void* -_TIFFrealloc(tdata_t p, tsize_t s) -{ - return (realloc(p, (size_t) s)); -} - -void -_TIFFmemset(tdata_t p, int v, tsize_t c) -{ - memset(p, v, (size_t) c); -} - -void -_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) -{ - memcpy(d, s, (size_t) c); -} - -int -_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) -{ - return (memcmp(p1, p2, (size_t) c)); -} - -static void -acornWarningHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - { - fprintf(stderr, "%s: ", module); - } - fprintf(stderr, "Warning, "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} -TIFFErrorHandler _TIFFwarningHandler = acornWarningHandler; - -static void -acornErrorHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - { - fprintf(stderr, "%s: ", module); - } - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} -TIFFErrorHandler _TIFFerrorHandler = acornErrorHandler; -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF/tif_acorn.c,v 1.37 2011/04/10 17:14:09 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library RISC OS specific Routines. + * Developed out of the Unix version. + * Peter Greenham, May 1995 + */ +#include "tiffiop.h" +#include +#include + +/* +Low-level file handling +~~~~~~~~~~~~~~~~~~~~~~~ +The functions in osfcn.h are unavailable when compiling under C, as it's a +C++ header. Therefore they have been implemented here. + +Now, why have I done it this way? + +The definitive API library for RISC OS is Jonathan Coxhead's OSLib, which +uses heavily optimised ARM assembler or even plain inline SWI calls for +maximum performance and minimum runtime size. However, I don't want to make +LIBTIFF need that to survive. Therefore I have also emulated the functions +using macros to _swi() and _swix() defined in the swis.h header, and +borrowing types from kernel.h, which is less efficient but doesn't need any +third-party libraries. + */ + +#ifdef INCLUDE_OSLIB + +#include "osfile.h" +#include "osgbpb.h" +#include "osargs.h" +#include "osfind.h" + +#else + +/* OSLIB EMULATION STARTS */ + +#include "kernel.h" +#include "swis.h" + +/* From oslib:types.h */ +typedef unsigned int bits; +typedef unsigned char byte; +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef NULL +#define NULL 0 +#endif +#ifndef SKIP +#define SKIP 0 +#endif + +/* From oslib:os.h */ +typedef _kernel_oserror os_error; +typedef byte os_f; + +/* From oslib:osfile.h */ +#undef OS_File +#define OS_File 0x8 + +/* From oslib:osgbpb.h */ +#undef OS_GBPB +#define OS_GBPB 0xC +#undef OSGBPB_Write +#define OSGBPB_Write 0x2 +#undef OSGBPB_Read +#define OSGBPB_Read 0x4 + +extern os_error *xosgbpb_write (os_f file, + byte *data, + int size, + int *unwritten); +extern int osgbpb_write (os_f file, + byte *data, + int size); + +#define xosgbpb_write(file, data, size, unwritten) \ + (os_error*) _swix(OS_GBPB, _IN(0)|_IN(1)|_IN(2)|_IN(3)|_IN(4)|_OUT(3), \ + OSGBPB_WriteAt, \ + file, \ + data, \ + size, \ + unwritten) + +#define osgbpb_write(file, data, size) \ + _swi(OS_GBPB, _IN(0)|_IN(1)|_IN(2)|_IN(3)|_RETURN(3), \ + OSGBPB_Write, \ + file, \ + data, \ + size) + +extern os_error *xosgbpb_read (os_f file, + byte *buffer, + int size, + int *unread); +extern int osgbpb_read (os_f file, + byte *buffer, + int size); + +#define xosgbpb_read(file, buffer, size, unread) \ + (os_error*) _swix(OS_GBPB, _IN(0)|_IN(1)|_IN(2)|_IN(3)|_OUT(3), \ + OSGBPB_Read, \ + file, \ + buffer, \ + size, \ + unread) + +#define osgbpb_read(file, buffer, size) \ + _swi(OS_GBPB, _IN(0)|_IN(1)|_IN(2)|_IN(3)|_RETURN(3), \ + OSGBPB_Read, \ + file, \ + buffer, \ + size) + +/* From oslib:osfind.h */ +#undef OS_Find +#define OS_Find 0xD +#undef OSFind_Openin +#define OSFind_Openin 0x40 +#undef OSFind_Openout +#define OSFind_Openout 0x80 +#undef OSFind_Openup +#define OSFind_Openup 0xC0 +#undef OSFind_Close +#define OSFind_Close 0x0 + +#define xosfind_open(reason, file_name, path, file) \ + (os_error*) _swix(OS_Find, _IN(0)|_IN(1)|_IN(2)|_OUT(0), \ + reason, file_name, path, file) + +#define osfind_open(reason, file_name, path) \ + (os_f) _swi(OS_Find, _IN(0)|_IN(1)|_IN(2)|_RETURN(0), \ + reason, file_name, path) + +extern os_error *xosfind_openin (bits flags, + char *file_name, + char *path, + os_f *file); +extern os_f osfind_openin (bits flags, + char *file_name, + char *path); + +#define xosfind_openin(flags, file_name, path, file) \ + xosfind_open(flags | OSFind_Openin, file_name, path, file) + +#define osfind_openin(flags, file_name, path) \ + osfind_open(flags | OSFind_Openin, file_name, path) + +extern os_error *xosfind_openout (bits flags, + char *file_name, + char *path, + os_f *file); +extern os_f osfind_openout (bits flags, + char *file_name, + char *path); + +#define xosfind_openout(flags, file_name, path, file) \ + xosfind_open(flags | OSFind_Openout, file_name, path, file) + +#define osfind_openout(flags, file_name, path) \ + osfind_open(flags | OSFind_Openout, file_name, path) + +extern os_error *xosfind_openup (bits flags, + char *file_name, + char *path, + os_f *file); +extern os_f osfind_openup (bits flags, + char *file_name, + char *path); + +#define xosfind_openup(flags, file_name, path, file) \ + xosfind_open(flags | OSFind_Openup, file_name, path, file) + +#define osfind_openup(flags, file_name, path) \ + osfind_open(flags | OSFind_Openup, file_name, path) + +extern os_error *xosfind_close (os_f file); +extern void osfind_close (os_f file); + +#define xosfind_close(file) \ + (os_error*) _swix(OS_Find, _IN(0)|_IN(1), \ + OSFind_Close, \ + file) + +#define osfind_close(file) \ + (void) _swi(OS_Find, _IN(0)|_IN(1), \ + OSFind_Close, \ + file) + +/* From oslib:osargs.h */ +#undef OS_Args +#define OS_Args 0x9 +#undef OSArgs_ReadPtr +#define OSArgs_ReadPtr 0x0 +#undef OSArgs_SetPtr +#define OSArgs_SetPtr 0x1 +#undef OSArgs_ReadExt +#define OSArgs_ReadExt 0x2 + +extern os_error *xosargs_read_ptr (os_f file, + int *ptr); +extern int osargs_read_ptr (os_f file); + +#define xosargs_read_ptr(file, ptr) \ + (os_error*) _swix(OS_Args, _IN(0)|_IN(1)|_OUT(2), \ + OSArgs_ReadPtr, \ + file, \ + ptr) + +#define osargs_read_ptr(file) \ + _swi(OS_Args, _IN(0)|_IN(1)|_RETURN(2), \ + OSArgs_ReadPtr, \ + file) + +extern os_error *xosargs_set_ptr (os_f file, + int ptr); +extern void osargs_set_ptr (os_f file, + int ptr); + +#define xosargs_set_ptr(file, ptr) \ + (os_error*) _swix(OS_Args, _IN(0)|_IN(1)|_IN(2), \ + OSArgs_SetPtr, \ + file, \ + ptr) + +#define osargs_set_ptr(file, ptr) \ + (void) _swi(OS_Args, _IN(0)|_IN(1)|_IN(2), \ + OSArgs_SetPtr, \ + file, \ + ptr) + +extern os_error *xosargs_read_ext (os_f file, + int *ext); +extern int osargs_read_ext (os_f file); + +#define xosargs_read_ext(file, ext) \ + (os_error*) _swix(OS_Args, _IN(0)|_IN(1)|_OUT(2), \ + OSArgs_ReadExt, \ + file, \ + ext) + +#define osargs_read_ext(file) \ + _swi(OS_Args, _IN(0)|_IN(1)|_RETURN(2), \ + OSArgs_ReadExt, \ + file) + +/* OSLIB EMULATION ENDS */ + +#endif + +#ifndef __osfcn_h +/* Will be set or not during tiffcomp.h */ +/* You get this to compile under C++? Please say how! */ + +extern int open(const char* name, int flags, int mode) +{ + /* From what I can tell, should return <0 for failure */ + os_error* e = (os_error*) 1; /* Cheeky way to use a pointer eh? :-) */ + os_f file = (os_f) -1; + + flags = flags; + + switch(mode) + { + case O_RDONLY: + { + e = xosfind_openin(SKIP, name, SKIP, &file); + break; + } + case O_WRONLY: + case O_RDWR|O_CREAT: + case O_RDWR|O_CREAT|O_TRUNC: + { + e = xosfind_openout(SKIP, name, SKIP, &file); + break; + } + case O_RDWR: + { + e = xosfind_openup(SKIP, name, SKIP, &file); + break; + } + } + if (e) + { + file = (os_f) -1; + } + return (file); +} + +extern int close(int fd) +{ + return ((int) xosfind_close((os_f) fd)); +} + +extern int write(int fd, const char *buf, int nbytes) +{ + /* Returns number of bytes written */ + return (nbytes - osgbpb_write((os_f) fd, (const byte*) buf, nbytes)); +} + +extern int read(int fd, char *buf, int nbytes) +{ + /* Returns number of bytes read */ + return (nbytes - osgbpb_read((os_f) fd, (byte*) buf, nbytes)); +} + +extern off_t lseek(int fd, off_t offset, int whence) +{ + int absolute = 0; + + switch (whence) + { + case SEEK_SET: + { + absolute = (int) offset; + break; + } + case SEEK_CUR: + { + absolute = osargs_read_ptr((os_f) fd) + (int) offset; + break; + } + case SEEK_END: + { + absolute = osargs_read_ext((os_f) fd) + (int) offset; + break; + } + } + + osargs_set_ptr((os_f) fd, absolute); + + return ((off_t) osargs_read_ptr((os_f) fd)); +} +#endif + +static tsize_t +_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + return ((tsize_t) read((int) fd, buf, (size_t) size)); +} + +static tsize_t +_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + return ((tsize_t) write((int) fd, buf, (size_t) size)); +} + +static toff_t +_tiffSeekProc(thandle_t fd, toff_t off, int whence) +{ + return ((toff_t) lseek((int) fd, (off_t) off, whence)); +} + +static int +_tiffCloseProc(thandle_t fd) +{ + return (close((int) fd)); +} + +static toff_t +_tiffSizeProc(thandle_t fd) +{ + return (lseek((int) fd, SEEK_END, SEEK_SET)); +} + +#ifdef HAVE_MMAP +#error "I didn't know Acorn had that!" +#endif + +/* !HAVE_MMAP */ +static int +_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) +{ + (void) fd; (void) pbase; (void) psize; + return (0); +} + +static void +_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) +{ + (void) fd; (void) base; (void) size; +} + +/* + * Open a TIFF file descriptor for read/writing. + */ +TIFF* +TIFFFdOpen(int fd, const char* name, const char* mode) +{ + TIFF* tif; + + tif = TIFFClientOpen(name, mode, + (thandle_t) fd, + _tiffReadProc, _tiffWriteProc, + _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, + _tiffMapProc, _tiffUnmapProc); + if (tif) + { + tif->tif_fd = fd; + } + return (tif); +} + +/* + * Open a TIFF file for read/writing. + */ +TIFF* +TIFFOpen(const char* name, const char* mode) +{ + static const char module[] = "TIFFOpen"; + int m, fd; + + m = _TIFFgetMode(mode, module); + + if (m == -1) + { + return ((TIFF*) 0); + } + + fd = open(name, 0, m); + + if (fd < 0) + { + TIFFErrorExt(0, module, "%s: Cannot open", name); + return ((TIFF *)0); + } + return (TIFFFdOpen(fd, name, mode)); +} + +void* +_TIFFmalloc(tsize_t s) +{ + return (malloc((size_t) s)); +} + +void +_TIFFfree(tdata_t p) +{ + free(p); +} + +void* +_TIFFrealloc(tdata_t p, tsize_t s) +{ + return (realloc(p, (size_t) s)); +} + +void +_TIFFmemset(tdata_t p, int v, tsize_t c) +{ + memset(p, v, (size_t) c); +} + +void +_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) +{ + memcpy(d, s, (size_t) c); +} + +int +_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) +{ + return (memcmp(p1, p2, (size_t) c)); +} + +static void +acornWarningHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + { + fprintf(stderr, "%s: ", module); + } + fprintf(stderr, "Warning, "); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} +TIFFErrorHandler _TIFFwarningHandler = acornWarningHandler; + +static void +acornErrorHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + { + fprintf(stderr, "%s: ", module); + } + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} +TIFFErrorHandler _TIFFerrorHandler = acornErrorHandler; +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF/tif_apple.c b/Source/LibTIFF/tif_apple.c index 0cd2948..b24fd1b 100644 --- a/Source/LibTIFF/tif_apple.c +++ b/Source/LibTIFF/tif_apple.c @@ -1,281 +1,281 @@ -/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF/tif_apple.c,v 1.37 2011/04/10 17:14:09 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library Macintosh-specific routines. - * - * These routines use only Toolbox and high-level File Manager traps. - * They make no calls to the THINK C "unix" compatibility library. Also, - * malloc is not used directly but it is still referenced internally by - * the ANSI library in rare cases. Heap fragmentation by the malloc ring - * buffer is therefore minimized. - * - * O_RDONLY and O_RDWR are treated identically here. The tif_mode flag is - * checked in TIFFWriteCheck(). - * - * Create below fills in a blank creator signature and sets the file type - * to 'TIFF'. It is much better for the application to do this by Create'ing - * the file first and TIFFOpen'ing it later. - * --------- - * This code has been "Carbonized", and may not work with older MacOS versions. - * If so, grab the tif_apple.c out of an older libtiff distribution, like - * 3.5.5 from www.libtiff.org. - */ - -#include "tiffiop.h" -#include -#include -#include -#include - -#if defined(__PPCC__) || defined(__SC__) || defined(__MRC__) || defined(applec) -#define CtoPstr c2pstr -#endif - -static tsize_t -_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - return (FSRead((short) fd, (long*) &size, (char*) buf) == noErr ? - size : (tsize_t) -1); -} - -static tsize_t -_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - return (FSWrite((short) fd, (long*) &size, (char*) buf) == noErr ? - size : (tsize_t) -1); -} - -static toff_t -_tiffSeekProc(thandle_t fd, toff_t off, int whence) -{ - long fpos, size; - - if (GetEOF((short) fd, &size) != noErr) - return EOF; - (void) GetFPos((short) fd, &fpos); - - switch (whence) { - case SEEK_CUR: - if (off + fpos > size) - SetEOF((short) fd, off + fpos); - if (SetFPos((short) fd, fsFromMark, off) != noErr) - return EOF; - break; - case SEEK_END: - if (off > 0) - SetEOF((short) fd, off + size); - if (SetFPos((short) fd, fsFromStart, off + size) != noErr) - return EOF; - break; - case SEEK_SET: - if (off > size) - SetEOF((short) fd, off); - if (SetFPos((short) fd, fsFromStart, off) != noErr) - return EOF; - break; - } - - return (toff_t)(GetFPos((short) fd, &fpos) == noErr ? fpos : EOF); -} - -static int -_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) -{ - return (0); -} - -static void -_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) -{ -} - -static int -_tiffCloseProc(thandle_t fd) -{ - return (FSClose((short) fd)); -} - -static toff_t -_tiffSizeProc(thandle_t fd) -{ - long size; - - if (GetEOF((short) fd, &size) != noErr) { - TIFFErrorExt(fd, "_tiffSizeProc", "%s: Cannot get file size"); - return (-1L); - } - return ((toff_t) size); -} - -/* - * Open a TIFF file descriptor for read/writing. - */ -TIFF* -TIFFFdOpen(int fd, const char* name, const char* mode) -{ - TIFF* tif; - - tif = TIFFClientOpen(name, mode, (thandle_t) fd, - _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, - _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); - if (tif) - tif->tif_fd = fd; - return (tif); -} - -static void ourc2pstr( char* inString ) -{ - int sLen = strlen( inString ); - BlockMoveData( inString, &inString[1], sLen ); - inString[0] = sLen; -} - -/* - * Open a TIFF file for read/writing. - */ -TIFF* -TIFFOpen(const char* name, const char* mode) -{ - static const char module[] = "TIFFOpen"; - Str255 pname; - FInfo finfo; - short fref; - OSErr err; - FSSpec fSpec; - - strcpy((char*) pname, name); - ourc2pstr((char*) pname); - - err = FSMakeFSSpec( 0, 0, pname, &fSpec ); - - switch (_TIFFgetMode(mode, module)) { - default: - return ((TIFF*) 0); - case O_RDWR | O_CREAT | O_TRUNC: - if (FSpGetFInfo(&fSpec, &finfo) == noErr) - FSpDelete(&fSpec); - /* fall through */ - case O_RDWR | O_CREAT: - if ((err = FSpGetFInfo(&fSpec, &finfo)) == fnfErr) { - if (FSpCreate(&fSpec, ' ', 'TIFF', smSystemScript) != noErr) - goto badCreate; - if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr) - goto badOpen; - } else if (err == noErr) { - if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr) - goto badOpen; - } else - goto badOpen; - break; - case O_RDONLY: - if (FSpOpenDF(&fSpec, fsRdPerm, &fref) != noErr) - goto badOpen; - break; - case O_RDWR: - if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr) - goto badOpen; - break; - } - return (TIFFFdOpen((int) fref, name, mode)); -badCreate: - TIFFErrorExt(0, module, "%s: Cannot create", name); - return ((TIFF*) 0); -badOpen: - TIFFErrorExt(0, module, "%s: Cannot open", name); - return ((TIFF*) 0); -} - -void -_TIFFmemset(tdata_t p, int v, tsize_t c) -{ - memset(p, v, (size_t) c); -} - -void -_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) -{ - memcpy(d, s, (size_t) c); -} - -int -_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) -{ - return (memcmp(p1, p2, (size_t) c)); -} - -tdata_t -_TIFFmalloc(tsize_t s) -{ - return (NewPtr((size_t) s)); -} - -void -_TIFFfree(tdata_t p) -{ - DisposePtr(p); -} - -tdata_t -_TIFFrealloc(tdata_t p, tsize_t s) -{ - Ptr n = p; - - SetPtrSize(p, (size_t) s); - if (MemError() && (n = NewPtr((size_t) s)) != NULL) { - BlockMove(p, n, GetPtrSize(p)); - DisposePtr(p); - } - return ((tdata_t) n); -} - -static void -appleWarningHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - fprintf(stderr, "%s: ", module); - fprintf(stderr, "Warning, "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} -TIFFErrorHandler _TIFFwarningHandler = appleWarningHandler; - -static void -appleErrorHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - fprintf(stderr, "%s: ", module); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} -TIFFErrorHandler _TIFFerrorHandler = appleErrorHandler; -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF/tif_apple.c,v 1.37 2011/04/10 17:14:09 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library Macintosh-specific routines. + * + * These routines use only Toolbox and high-level File Manager traps. + * They make no calls to the THINK C "unix" compatibility library. Also, + * malloc is not used directly but it is still referenced internally by + * the ANSI library in rare cases. Heap fragmentation by the malloc ring + * buffer is therefore minimized. + * + * O_RDONLY and O_RDWR are treated identically here. The tif_mode flag is + * checked in TIFFWriteCheck(). + * + * Create below fills in a blank creator signature and sets the file type + * to 'TIFF'. It is much better for the application to do this by Create'ing + * the file first and TIFFOpen'ing it later. + * --------- + * This code has been "Carbonized", and may not work with older MacOS versions. + * If so, grab the tif_apple.c out of an older libtiff distribution, like + * 3.5.5 from www.libtiff.org. + */ + +#include "tiffiop.h" +#include +#include +#include +#include + +#if defined(__PPCC__) || defined(__SC__) || defined(__MRC__) || defined(applec) +#define CtoPstr c2pstr +#endif + +static tsize_t +_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + return (FSRead((short) fd, (long*) &size, (char*) buf) == noErr ? + size : (tsize_t) -1); +} + +static tsize_t +_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + return (FSWrite((short) fd, (long*) &size, (char*) buf) == noErr ? + size : (tsize_t) -1); +} + +static toff_t +_tiffSeekProc(thandle_t fd, toff_t off, int whence) +{ + long fpos, size; + + if (GetEOF((short) fd, &size) != noErr) + return EOF; + (void) GetFPos((short) fd, &fpos); + + switch (whence) { + case SEEK_CUR: + if (off + fpos > size) + SetEOF((short) fd, off + fpos); + if (SetFPos((short) fd, fsFromMark, off) != noErr) + return EOF; + break; + case SEEK_END: + if (off > 0) + SetEOF((short) fd, off + size); + if (SetFPos((short) fd, fsFromStart, off + size) != noErr) + return EOF; + break; + case SEEK_SET: + if (off > size) + SetEOF((short) fd, off); + if (SetFPos((short) fd, fsFromStart, off) != noErr) + return EOF; + break; + } + + return (toff_t)(GetFPos((short) fd, &fpos) == noErr ? fpos : EOF); +} + +static int +_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) +{ + return (0); +} + +static void +_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) +{ +} + +static int +_tiffCloseProc(thandle_t fd) +{ + return (FSClose((short) fd)); +} + +static toff_t +_tiffSizeProc(thandle_t fd) +{ + long size; + + if (GetEOF((short) fd, &size) != noErr) { + TIFFErrorExt(fd, "_tiffSizeProc", "%s: Cannot get file size"); + return (-1L); + } + return ((toff_t) size); +} + +/* + * Open a TIFF file descriptor for read/writing. + */ +TIFF* +TIFFFdOpen(int fd, const char* name, const char* mode) +{ + TIFF* tif; + + tif = TIFFClientOpen(name, mode, (thandle_t) fd, + _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, + _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); + if (tif) + tif->tif_fd = fd; + return (tif); +} + +static void ourc2pstr( char* inString ) +{ + int sLen = strlen( inString ); + BlockMoveData( inString, &inString[1], sLen ); + inString[0] = sLen; +} + +/* + * Open a TIFF file for read/writing. + */ +TIFF* +TIFFOpen(const char* name, const char* mode) +{ + static const char module[] = "TIFFOpen"; + Str255 pname; + FInfo finfo; + short fref; + OSErr err; + FSSpec fSpec; + + strcpy((char*) pname, name); + ourc2pstr((char*) pname); + + err = FSMakeFSSpec( 0, 0, pname, &fSpec ); + + switch (_TIFFgetMode(mode, module)) { + default: + return ((TIFF*) 0); + case O_RDWR | O_CREAT | O_TRUNC: + if (FSpGetFInfo(&fSpec, &finfo) == noErr) + FSpDelete(&fSpec); + /* fall through */ + case O_RDWR | O_CREAT: + if ((err = FSpGetFInfo(&fSpec, &finfo)) == fnfErr) { + if (FSpCreate(&fSpec, ' ', 'TIFF', smSystemScript) != noErr) + goto badCreate; + if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr) + goto badOpen; + } else if (err == noErr) { + if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr) + goto badOpen; + } else + goto badOpen; + break; + case O_RDONLY: + if (FSpOpenDF(&fSpec, fsRdPerm, &fref) != noErr) + goto badOpen; + break; + case O_RDWR: + if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr) + goto badOpen; + break; + } + return (TIFFFdOpen((int) fref, name, mode)); +badCreate: + TIFFErrorExt(0, module, "%s: Cannot create", name); + return ((TIFF*) 0); +badOpen: + TIFFErrorExt(0, module, "%s: Cannot open", name); + return ((TIFF*) 0); +} + +void +_TIFFmemset(tdata_t p, int v, tsize_t c) +{ + memset(p, v, (size_t) c); +} + +void +_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) +{ + memcpy(d, s, (size_t) c); +} + +int +_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) +{ + return (memcmp(p1, p2, (size_t) c)); +} + +tdata_t +_TIFFmalloc(tsize_t s) +{ + return (NewPtr((size_t) s)); +} + +void +_TIFFfree(tdata_t p) +{ + DisposePtr(p); +} + +tdata_t +_TIFFrealloc(tdata_t p, tsize_t s) +{ + Ptr n = p; + + SetPtrSize(p, (size_t) s); + if (MemError() && (n = NewPtr((size_t) s)) != NULL) { + BlockMove(p, n, GetPtrSize(p)); + DisposePtr(p); + } + return ((tdata_t) n); +} + +static void +appleWarningHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + fprintf(stderr, "%s: ", module); + fprintf(stderr, "Warning, "); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} +TIFFErrorHandler _TIFFwarningHandler = appleWarningHandler; + +static void +appleErrorHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + fprintf(stderr, "%s: ", module); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} +TIFFErrorHandler _TIFFerrorHandler = appleErrorHandler; +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF/tif_atari.c b/Source/LibTIFF/tif_atari.c index 62453a1..0aa4322 100644 --- a/Source/LibTIFF/tif_atari.c +++ b/Source/LibTIFF/tif_atari.c @@ -1,250 +1,250 @@ -/* "$Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF/tif_atari.c,v 1.37 2011/04/10 17:14:09 drolon Exp $" */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library ATARI-specific Routines. - */ -#include "tiffiop.h" -#if defined(__TURBOC__) -#include -#include -#else -#include -#include -#endif - -#ifndef O_ACCMODE -#define O_ACCMODE 3 -#endif - -#include - -#define AEFILNF -33 - -static tsize_t -_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - long r; - - r = Fread((int) fd, size, buf); - if (r < 0) { - errno = (int)-r; - r = -1; - } - return r; -} - -static tsize_t -_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - long r; - - r = Fwrite((int) fd, size, buf); - if (r < 0) { - errno = (int)-r; - r = -1; - } - return r; -} - -static toff_t -_tiffSeekProc(thandle_t fd, off_t off, int whence) -{ - char buf[256]; - long current_off, expected_off, new_off; - - if (whence == SEEK_END || off <= 0) - return Fseek(off, (int) fd, whence); - current_off = Fseek(0, (int) fd, SEEK_CUR); /* find out where we are */ - if (whence == SEEK_SET) - expected_off = off; - else - expected_off = off + current_off; - new_off = Fseek(off, (int) fd, whence); - if (new_off == expected_off) - return new_off; - /* otherwise extend file -- zero filling the hole */ - if (new_off < 0) /* error? */ - new_off = Fseek(0, (int) fd, SEEK_END); /* go to eof */ - _TIFFmemset(buf, 0, sizeof(buf)); - while (expected_off > new_off) { - off = expected_off - new_off; - if (off > sizeof(buf)) - off = sizeof(buf); - if ((current_off = Fwrite((int) fd, off, buf)) != off) - return (current_off > 0) ? - new_off + current_off : new_off; - new_off += off; - } - return new_off; -} - -static int -_tiffCloseProc(thandle_t fd) -{ - long r; - - r = Fclose((int) fd); - if (r < 0) { - errno = (int)-r; - r = -1; - } - return (int)r; -} - -static toff_t -_tiffSizeProc(thandle_t fd) -{ - long pos, eof; - - pos = Fseek(0, (int) fd, SEEK_CUR); - eof = Fseek(0, (int) fd, SEEK_END); - Fseek(pos, (int) fd, SEEK_SET); - return eof; -} - -static int -_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) -{ - return (0); -} - -static void -_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) -{ -} - -/* -* Open a TIFF file descriptor for read/writing. -*/ -TIFF* -TIFFFdOpen(int fd, const char* name, const char* mode) -{ - TIFF* tif; - - tif = TIFFClientOpen(name, mode, - (thandle_t) fd, - _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, - _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); - if (tif) - tif->tif_fd = fd; - return (tif); -} - -/* -* Open a TIFF file for read/writing. -*/ -TIFF* -TIFFOpen(const char* name, const char* mode) -{ - static const char module[] = "TIFFOpen"; - int m; - long fd; - - m = _TIFFgetMode(mode, module); - if (m == -1) - return ((TIFF*)0); - if (m & O_TRUNC) { - fd = Fcreate(name, 0); - } else { - fd = Fopen(name, m & O_ACCMODE); - if (fd == AEFILNF && m & O_CREAT) - fd = Fcreate(name, 0); - } - if (fd < 0) - errno = (int)fd; - if (fd < 0) { - TIFFErrorExt(0, module, "%s: Cannot open", name); - return ((TIFF*)0); - } - return (TIFFFdOpen(fd, name, mode)); -} - -#include - -tdata_t -_TIFFmalloc(tsize_t s) -{ - return (malloc((size_t) s)); -} - -void -_TIFFfree(tdata_t p) -{ - free(p); -} - -tdata_t -_TIFFrealloc(tdata_t p, tsize_t s) -{ - return (realloc(p, (size_t) s)); -} - -void -_TIFFmemset(tdata_t p, int v, size_t c) -{ - memset(p, v, (size_t) c); -} - -void -_TIFFmemcpy(tdata_t d, const tdata_t s, size_t c) -{ - memcpy(d, s, (size_t) c); -} - -int -_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) -{ - return (memcmp(p1, p2, (size_t) c)); -} - -static void -atariWarningHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - fprintf(stderr, "%s: ", module); - fprintf(stderr, "Warning, "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} -TIFFErrorHandler _TIFFwarningHandler = atariWarningHandler; - -static void -atariErrorHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - fprintf(stderr, "%s: ", module); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} -TIFFErrorHandler _TIFFerrorHandler = atariErrorHandler; -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* "$Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF/tif_atari.c,v 1.37 2011/04/10 17:14:09 drolon Exp $" */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library ATARI-specific Routines. + */ +#include "tiffiop.h" +#if defined(__TURBOC__) +#include +#include +#else +#include +#include +#endif + +#ifndef O_ACCMODE +#define O_ACCMODE 3 +#endif + +#include + +#define AEFILNF -33 + +static tsize_t +_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + long r; + + r = Fread((int) fd, size, buf); + if (r < 0) { + errno = (int)-r; + r = -1; + } + return r; +} + +static tsize_t +_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + long r; + + r = Fwrite((int) fd, size, buf); + if (r < 0) { + errno = (int)-r; + r = -1; + } + return r; +} + +static toff_t +_tiffSeekProc(thandle_t fd, off_t off, int whence) +{ + char buf[256]; + long current_off, expected_off, new_off; + + if (whence == SEEK_END || off <= 0) + return Fseek(off, (int) fd, whence); + current_off = Fseek(0, (int) fd, SEEK_CUR); /* find out where we are */ + if (whence == SEEK_SET) + expected_off = off; + else + expected_off = off + current_off; + new_off = Fseek(off, (int) fd, whence); + if (new_off == expected_off) + return new_off; + /* otherwise extend file -- zero filling the hole */ + if (new_off < 0) /* error? */ + new_off = Fseek(0, (int) fd, SEEK_END); /* go to eof */ + _TIFFmemset(buf, 0, sizeof(buf)); + while (expected_off > new_off) { + off = expected_off - new_off; + if (off > sizeof(buf)) + off = sizeof(buf); + if ((current_off = Fwrite((int) fd, off, buf)) != off) + return (current_off > 0) ? + new_off + current_off : new_off; + new_off += off; + } + return new_off; +} + +static int +_tiffCloseProc(thandle_t fd) +{ + long r; + + r = Fclose((int) fd); + if (r < 0) { + errno = (int)-r; + r = -1; + } + return (int)r; +} + +static toff_t +_tiffSizeProc(thandle_t fd) +{ + long pos, eof; + + pos = Fseek(0, (int) fd, SEEK_CUR); + eof = Fseek(0, (int) fd, SEEK_END); + Fseek(pos, (int) fd, SEEK_SET); + return eof; +} + +static int +_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) +{ + return (0); +} + +static void +_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) +{ +} + +/* +* Open a TIFF file descriptor for read/writing. +*/ +TIFF* +TIFFFdOpen(int fd, const char* name, const char* mode) +{ + TIFF* tif; + + tif = TIFFClientOpen(name, mode, + (thandle_t) fd, + _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, + _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); + if (tif) + tif->tif_fd = fd; + return (tif); +} + +/* +* Open a TIFF file for read/writing. +*/ +TIFF* +TIFFOpen(const char* name, const char* mode) +{ + static const char module[] = "TIFFOpen"; + int m; + long fd; + + m = _TIFFgetMode(mode, module); + if (m == -1) + return ((TIFF*)0); + if (m & O_TRUNC) { + fd = Fcreate(name, 0); + } else { + fd = Fopen(name, m & O_ACCMODE); + if (fd == AEFILNF && m & O_CREAT) + fd = Fcreate(name, 0); + } + if (fd < 0) + errno = (int)fd; + if (fd < 0) { + TIFFErrorExt(0, module, "%s: Cannot open", name); + return ((TIFF*)0); + } + return (TIFFFdOpen(fd, name, mode)); +} + +#include + +tdata_t +_TIFFmalloc(tsize_t s) +{ + return (malloc((size_t) s)); +} + +void +_TIFFfree(tdata_t p) +{ + free(p); +} + +tdata_t +_TIFFrealloc(tdata_t p, tsize_t s) +{ + return (realloc(p, (size_t) s)); +} + +void +_TIFFmemset(tdata_t p, int v, size_t c) +{ + memset(p, v, (size_t) c); +} + +void +_TIFFmemcpy(tdata_t d, const tdata_t s, size_t c) +{ + memcpy(d, s, (size_t) c); +} + +int +_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) +{ + return (memcmp(p1, p2, (size_t) c)); +} + +static void +atariWarningHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + fprintf(stderr, "%s: ", module); + fprintf(stderr, "Warning, "); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} +TIFFErrorHandler _TIFFwarningHandler = atariWarningHandler; + +static void +atariErrorHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + fprintf(stderr, "%s: ", module); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} +TIFFErrorHandler _TIFFerrorHandler = atariErrorHandler; +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF/tif_config.h-vms b/Source/LibTIFF/tif_config.h-vms index c2cae57..d653bd8 100644 --- a/Source/LibTIFF/tif_config.h-vms +++ b/Source/LibTIFF/tif_config.h-vms @@ -1,46 +1,46 @@ -/* Define to 1 if you have the header file. */ -#define HAVE_ASSERT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#define HAVE_IEEEFP 1 - -#define HAVE_UNISTD_H 1 - -#define HAVE_STRING_H 1 -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -//#define HAVE_IO_H 1 - -/* Define to 1 if you have the header file. */ -//#define HAVE_SEARCH_H 1 - -/* The size of a `int', as computed by sizeof. */ -#define SIZEOF_INT 4 - -/* The size of a `long', as computed by sizeof. */ -#define SIZEOF_LONG 4 - -/* Set the native cpu bit order */ -#define HOST_FILLORDER FILLORDER_LSB2MSB - -/* Define to 1 if your processor stores words with the most significant byte - first (like Motorola and SPARC, unlike Intel and VAX). */ -/* #undef WORDS_BIGENDIAN */ - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -/* -#ifndef __cplusplus -# ifndef inline -# define inline __inline -# endif -#endif -*/ - -// #define lfind _lfind +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#define HAVE_IEEEFP 1 + +#define HAVE_UNISTD_H 1 + +#define HAVE_STRING_H 1 +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +//#define HAVE_IO_H 1 + +/* Define to 1 if you have the header file. */ +//#define HAVE_SEARCH_H 1 + +/* The size of a `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of a `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* Set the native cpu bit order */ +#define HOST_FILLORDER FILLORDER_LSB2MSB + +/* Define to 1 if your processor stores words with the most significant byte + first (like Motorola and SPARC, unlike Intel and VAX). */ +/* #undef WORDS_BIGENDIAN */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +/* +#ifndef __cplusplus +# ifndef inline +# define inline __inline +# endif +#endif +*/ + +// #define lfind _lfind diff --git a/Source/LibTIFF/tif_config.h.in b/Source/LibTIFF/tif_config.h.in index 86c07e6..01e54de 100644 --- a/Source/LibTIFF/tif_config.h.in +++ b/Source/LibTIFF/tif_config.h.in @@ -1,309 +1,309 @@ -/* libtiff/tif_config.h.in. Generated from configure.ac by autoheader. */ - -/* Define if building universal (internal helper macro) */ -#undef AC_APPLE_UNIVERSAL_BUILD - -/* Support CCITT Group 3 & 4 algorithms */ -#undef CCITT_SUPPORT - -/* Pick up YCbCr subsampling info from the JPEG data stream to support files - lacking the tag (default enabled). */ -#undef CHECK_JPEG_YCBCR_SUBSAMPLING - -/* Support C++ stream API (requires C++ compiler) */ -#undef CXX_SUPPORT - -/* Treat extra sample as alpha (default enabled). The RGBA interface will - treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many - packages produce RGBA files but don't mark the alpha properly. */ -#undef DEFAULT_EXTRASAMPLE_AS_ALPHA - -/* Use the Apple OpenGL framework. */ -#undef HAVE_APPLE_OPENGL_FRAMEWORK - -/* Define to 1 if you have the header file. */ -#undef HAVE_ASSERT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_DLFCN_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_FCNTL_H - -/* Define to 1 if you have the `floor' function. */ -#undef HAVE_FLOOR - -/* Define to 1 if you have the `getopt' function. */ -#undef HAVE_GETOPT - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#undef HAVE_IEEEFP - -/* Define to 1 if the system has the type `int16'. */ -#undef HAVE_INT16 - -/* Define to 1 if the system has the type `int32'. */ -#undef HAVE_INT32 - -/* Define to 1 if the system has the type `int8'. */ -#undef HAVE_INT8 - -/* Define to 1 if you have the header file. */ -#undef HAVE_INTTYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_IO_H - -/* Define to 1 if you have the `isascii' function. */ -#undef HAVE_ISASCII - -/* Define to 1 if you have the `jbg_newlen' function. */ -#undef HAVE_JBG_NEWLEN - -/* Define to 1 if you have the `lfind' function. */ -#undef HAVE_LFIND - -/* Define to 1 if you have the `c' library (-lc). */ -#undef HAVE_LIBC - -/* Define to 1 if you have the `m' library (-lm). */ -#undef HAVE_LIBM - -/* Define to 1 if you have the header file. */ -#undef HAVE_LIMITS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_MALLOC_H - -/* Define to 1 if you have the `memmove' function. */ -#undef HAVE_MEMMOVE - -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - -/* Define to 1 if you have the `memset' function. */ -#undef HAVE_MEMSET - -/* Define to 1 if you have the `mmap' function. */ -#undef HAVE_MMAP - -/* Define to 1 if you have the `pow' function. */ -#undef HAVE_POW - -/* Define if you have POSIX threads libraries and header files. */ -#undef HAVE_PTHREAD - -/* Define to 1 if you have the header file. */ -#undef HAVE_SEARCH_H - -/* Define to 1 if you have the `setmode' function. */ -#undef HAVE_SETMODE - -/* Define to 1 if you have the `sqrt' function. */ -#undef HAVE_SQRT - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDINT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDLIB_H - -/* Define to 1 if you have the `strcasecmp' function. */ -#undef HAVE_STRCASECMP - -/* Define to 1 if you have the `strchr' function. */ -#undef HAVE_STRCHR - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRING_H - -/* Define to 1 if you have the `strrchr' function. */ -#undef HAVE_STRRCHR - -/* Define to 1 if you have the `strstr' function. */ -#undef HAVE_STRSTR - -/* Define to 1 if you have the `strtol' function. */ -#undef HAVE_STRTOL - -/* Define to 1 if you have the `strtoul' function. */ -#undef HAVE_STRTOUL - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_STAT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TIME_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_UNISTD_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_WINDOWS_H - -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian - (Intel) */ -#undef HOST_BIGENDIAN - -/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ -#undef HOST_FILLORDER - -/* Support ISO JBIG compression (requires JBIG-KIT library) */ -#undef JBIG_SUPPORT - -/* Support JPEG compression (requires IJG JPEG library) */ -#undef JPEG_SUPPORT - -/* Support LogLuv high dynamic range encoding */ -#undef LOGLUV_SUPPORT - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#undef LT_OBJDIR - -/* Support LZW algorithm */ -#undef LZW_SUPPORT - -/* Support Microsoft Document Imaging format */ -#undef MDI_SUPPORT - -/* Support NeXT 2-bit RLE algorithm */ -#undef NEXT_SUPPORT - -/* Define to 1 if your C compiler doesn't accept -c and -o together. */ -#undef NO_MINUS_C_MINUS_O - -/* Support Old JPEG compresson (read-only) */ -#undef OJPEG_SUPPORT - -/* Name of package */ -#undef PACKAGE - -/* Define to the address where bug reports for this package should be sent. */ -#undef PACKAGE_BUGREPORT - -/* Define to the full name of this package. */ -#undef PACKAGE_NAME - -/* Define to the full name and version of this package. */ -#undef PACKAGE_STRING - -/* Define to the one symbol short name of this package. */ -#undef PACKAGE_TARNAME - -/* Define to the home page for this package. */ -#undef PACKAGE_URL - -/* Define to the version of this package. */ -#undef PACKAGE_VERSION - -/* Support Macintosh PackBits algorithm */ -#undef PACKBITS_SUPPORT - -/* Support Pixar log-format algorithm (requires Zlib) */ -#undef PIXARLOG_SUPPORT - -/* Define to necessary symbol if this constant uses a non-standard name on - your system. */ -#undef PTHREAD_CREATE_JOINABLE - -/* The size of `int', as computed by sizeof. */ -#undef SIZEOF_INT - -/* The size of `long', as computed by sizeof. */ -#undef SIZEOF_LONG - -/* The size of `signed long', as computed by sizeof. */ -#undef SIZEOF_SIGNED_LONG - -/* The size of `signed long long', as computed by sizeof. */ -#undef SIZEOF_SIGNED_LONG_LONG - -/* The size of `unsigned long', as computed by sizeof. */ -#undef SIZEOF_UNSIGNED_LONG - -/* The size of `unsigned long long', as computed by sizeof. */ -#undef SIZEOF_UNSIGNED_LONG_LONG - -/* Define to 1 if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Support strip chopping (whether or not to convert single-strip uncompressed - images to mutiple strips of specified size to reduce memory usage) */ -#undef STRIPCHOP_DEFAULT - -/* Default size of the strip in bytes (when strip chopping enabled) */ -#undef STRIP_SIZE_DEFAULT - -/* Enable SubIFD tag (330) support */ -#undef SUBIFD_SUPPORT - -/* Support ThunderScan 4-bit RLE algorithm */ -#undef THUNDER_SUPPORT - -/* Signed 64-bit type formatter */ -#undef TIFF_INT64_FORMAT - -/* Signed 64-bit type */ -#undef TIFF_INT64_T - -/* Unsigned 64-bit type formatter */ -#undef TIFF_UINT64_FORMAT - -/* Unsigned 64-bit type */ -#undef TIFF_UINT64_T - -/* Define to 1 if you can safely include both and . */ -#undef TIME_WITH_SYS_TIME - -/* Define to 1 if your declares `struct tm'. */ -#undef TM_IN_SYS_TIME - -/* Version number of package */ -#undef VERSION - -/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most - significant byte first (like Motorola and SPARC, unlike Intel). */ -#if defined AC_APPLE_UNIVERSAL_BUILD -# if defined __BIG_ENDIAN__ -# define WORDS_BIGENDIAN 1 -# endif -#else -# ifndef WORDS_BIGENDIAN -# undef WORDS_BIGENDIAN -# endif -#endif - -/* Define to 1 if the X Window System is missing or not being used. */ -#undef X_DISPLAY_MISSING - -/* Support Deflate compression */ -#undef ZIP_SUPPORT - -/* Number of bits in a file offset, on hosts where this is settable. */ -#undef _FILE_OFFSET_BITS - -/* Define for large files, on AIX-style hosts. */ -#undef _LARGE_FILES - -/* Define to empty if `const' does not conform to ANSI C. */ -#undef const - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -#undef inline -#endif - -/* Define to `long int' if does not define. */ -#undef off_t - -/* Define to `unsigned int' if does not define. */ -#undef size_t +/* libtiff/tif_config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +#undef AC_APPLE_UNIVERSAL_BUILD + +/* Support CCITT Group 3 & 4 algorithms */ +#undef CCITT_SUPPORT + +/* Pick up YCbCr subsampling info from the JPEG data stream to support files + lacking the tag (default enabled). */ +#undef CHECK_JPEG_YCBCR_SUBSAMPLING + +/* Support C++ stream API (requires C++ compiler) */ +#undef CXX_SUPPORT + +/* Treat extra sample as alpha (default enabled). The RGBA interface will + treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many + packages produce RGBA files but don't mark the alpha properly. */ +#undef DEFAULT_EXTRASAMPLE_AS_ALPHA + +/* Use the Apple OpenGL framework. */ +#undef HAVE_APPLE_OPENGL_FRAMEWORK + +/* Define to 1 if you have the header file. */ +#undef HAVE_ASSERT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_FCNTL_H + +/* Define to 1 if you have the `floor' function. */ +#undef HAVE_FLOOR + +/* Define to 1 if you have the `getopt' function. */ +#undef HAVE_GETOPT + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#undef HAVE_IEEEFP + +/* Define to 1 if the system has the type `int16'. */ +#undef HAVE_INT16 + +/* Define to 1 if the system has the type `int32'. */ +#undef HAVE_INT32 + +/* Define to 1 if the system has the type `int8'. */ +#undef HAVE_INT8 + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_IO_H + +/* Define to 1 if you have the `isascii' function. */ +#undef HAVE_ISASCII + +/* Define to 1 if you have the `jbg_newlen' function. */ +#undef HAVE_JBG_NEWLEN + +/* Define to 1 if you have the `lfind' function. */ +#undef HAVE_LFIND + +/* Define to 1 if you have the `c' library (-lc). */ +#undef HAVE_LIBC + +/* Define to 1 if you have the `m' library (-lm). */ +#undef HAVE_LIBM + +/* Define to 1 if you have the header file. */ +#undef HAVE_LIMITS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_MALLOC_H + +/* Define to 1 if you have the `memmove' function. */ +#undef HAVE_MEMMOVE + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the `memset' function. */ +#undef HAVE_MEMSET + +/* Define to 1 if you have the `mmap' function. */ +#undef HAVE_MMAP + +/* Define to 1 if you have the `pow' function. */ +#undef HAVE_POW + +/* Define if you have POSIX threads libraries and header files. */ +#undef HAVE_PTHREAD + +/* Define to 1 if you have the header file. */ +#undef HAVE_SEARCH_H + +/* Define to 1 if you have the `setmode' function. */ +#undef HAVE_SETMODE + +/* Define to 1 if you have the `sqrt' function. */ +#undef HAVE_SQRT + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the `strcasecmp' function. */ +#undef HAVE_STRCASECMP + +/* Define to 1 if you have the `strchr' function. */ +#undef HAVE_STRCHR + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `strrchr' function. */ +#undef HAVE_STRRCHR + +/* Define to 1 if you have the `strstr' function. */ +#undef HAVE_STRSTR + +/* Define to 1 if you have the `strtol' function. */ +#undef HAVE_STRTOL + +/* Define to 1 if you have the `strtoul' function. */ +#undef HAVE_STRTOUL + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TIME_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_WINDOWS_H + +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian + (Intel) */ +#undef HOST_BIGENDIAN + +/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ +#undef HOST_FILLORDER + +/* Support ISO JBIG compression (requires JBIG-KIT library) */ +#undef JBIG_SUPPORT + +/* Support JPEG compression (requires IJG JPEG library) */ +#undef JPEG_SUPPORT + +/* Support LogLuv high dynamic range encoding */ +#undef LOGLUV_SUPPORT + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#undef LT_OBJDIR + +/* Support LZW algorithm */ +#undef LZW_SUPPORT + +/* Support Microsoft Document Imaging format */ +#undef MDI_SUPPORT + +/* Support NeXT 2-bit RLE algorithm */ +#undef NEXT_SUPPORT + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +#undef NO_MINUS_C_MINUS_O + +/* Support Old JPEG compresson (read-only) */ +#undef OJPEG_SUPPORT + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Support Macintosh PackBits algorithm */ +#undef PACKBITS_SUPPORT + +/* Support Pixar log-format algorithm (requires Zlib) */ +#undef PIXARLOG_SUPPORT + +/* Define to necessary symbol if this constant uses a non-standard name on + your system. */ +#undef PTHREAD_CREATE_JOINABLE + +/* The size of `int', as computed by sizeof. */ +#undef SIZEOF_INT + +/* The size of `long', as computed by sizeof. */ +#undef SIZEOF_LONG + +/* The size of `signed long', as computed by sizeof. */ +#undef SIZEOF_SIGNED_LONG + +/* The size of `signed long long', as computed by sizeof. */ +#undef SIZEOF_SIGNED_LONG_LONG + +/* The size of `unsigned long', as computed by sizeof. */ +#undef SIZEOF_UNSIGNED_LONG + +/* The size of `unsigned long long', as computed by sizeof. */ +#undef SIZEOF_UNSIGNED_LONG_LONG + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Support strip chopping (whether or not to convert single-strip uncompressed + images to mutiple strips of specified size to reduce memory usage) */ +#undef STRIPCHOP_DEFAULT + +/* Default size of the strip in bytes (when strip chopping enabled) */ +#undef STRIP_SIZE_DEFAULT + +/* Enable SubIFD tag (330) support */ +#undef SUBIFD_SUPPORT + +/* Support ThunderScan 4-bit RLE algorithm */ +#undef THUNDER_SUPPORT + +/* Signed 64-bit type formatter */ +#undef TIFF_INT64_FORMAT + +/* Signed 64-bit type */ +#undef TIFF_INT64_T + +/* Unsigned 64-bit type formatter */ +#undef TIFF_UINT64_FORMAT + +/* Unsigned 64-bit type */ +#undef TIFF_UINT64_T + +/* Define to 1 if you can safely include both and . */ +#undef TIME_WITH_SYS_TIME + +/* Define to 1 if your declares `struct tm'. */ +#undef TM_IN_SYS_TIME + +/* Version number of package */ +#undef VERSION + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +# undef WORDS_BIGENDIAN +# endif +#endif + +/* Define to 1 if the X Window System is missing or not being used. */ +#undef X_DISPLAY_MISSING + +/* Support Deflate compression */ +#undef ZIP_SUPPORT + +/* Number of bits in a file offset, on hosts where this is settable. */ +#undef _FILE_OFFSET_BITS + +/* Define for large files, on AIX-style hosts. */ +#undef _LARGE_FILES + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif + +/* Define to `long int' if does not define. */ +#undef off_t + +/* Define to `unsigned int' if does not define. */ +#undef size_t diff --git a/Source/LibTIFF/tif_jbig.c b/Source/LibTIFF/tif_jbig.c index c779c9b..baed257 100644 --- a/Source/LibTIFF/tif_jbig.c +++ b/Source/LibTIFF/tif_jbig.c @@ -1,385 +1,385 @@ -/* $Id: tif_jbig.c,v 1.23 2011/04/10 17:14:09 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * - * JBIG Compression Algorithm Support. - * Contributed by Lee Howard - * - */ - -#include "tiffiop.h" - -#ifdef JBIG_SUPPORT -#include "jbig.h" - -typedef struct -{ - uint32 recvparams; /* encoded Class 2 session params */ - char* subaddress; /* subaddress string */ - uint32 recvtime; /* time spend receiving in seconds */ - char* faxdcs; /* encoded fax parameters (DCS, Table 2/T.30) */ - - TIFFVGetMethod vgetparent; - TIFFVSetMethod vsetparent; -} JBIGState; - -#define GetJBIGState(tif) ((JBIGState*)(tif)->tif_data) - -#define FIELD_RECVPARAMS (FIELD_CODEC+0) -#define FIELD_SUBADDRESS (FIELD_CODEC+1) -#define FIELD_RECVTIME (FIELD_CODEC+2) -#define FIELD_FAXDCS (FIELD_CODEC+3) - -static const TIFFFieldInfo jbigFieldInfo[] = -{ - {TIFFTAG_FAXRECVPARAMS, 1, 1, TIFF_LONG, FIELD_RECVPARAMS, TRUE, FALSE, "FaxRecvParams"}, - {TIFFTAG_FAXSUBADDRESS, -1, -1, TIFF_ASCII, FIELD_SUBADDRESS, TRUE, FALSE, "FaxSubAddress"}, - {TIFFTAG_FAXRECVTIME, 1, 1, TIFF_LONG, FIELD_RECVTIME, TRUE, FALSE, "FaxRecvTime"}, - {TIFFTAG_FAXDCS, -1, -1, TIFF_ASCII, FIELD_FAXDCS, TRUE, FALSE, "FaxDcs"}, -}; - -static int JBIGSetupDecode(TIFF* tif) -{ - if (TIFFNumberOfStrips(tif) != 1) - { - TIFFError("JBIG", "Multistrip images not supported in decoder"); - return 0; - } - - return 1; -} - -static int JBIGDecode(TIFF* tif, tidata_t buffer, tsize_t size, tsample_t s) -{ - struct jbg_dec_state decoder; - int decodeStatus = 0; - unsigned char* pImage = NULL; - (void) size, (void) s; - - if (isFillOrder(tif, tif->tif_dir.td_fillorder)) - { - TIFFReverseBits(tif->tif_rawdata, tif->tif_rawdatasize); - } - - jbg_dec_init(&decoder); - -#if defined(HAVE_JBG_NEWLEN) - jbg_newlen(tif->tif_rawdata, tif->tif_rawdatasize); - /* - * I do not check the return status of jbg_newlen because even if this - * function fails it does not necessarily mean that decoding the image - * will fail. It is generally only needed for received fax images - * that do not contain the actual length of the image in the BIE - * header. I do not log when an error occurs because that will cause - * problems when converting JBIG encoded TIFF's to - * PostScript. As long as the actual image length is contained in the - * BIE header jbg_dec_in should succeed. - */ -#endif /* HAVE_JBG_NEWLEN */ - - decodeStatus = jbg_dec_in(&decoder, tif->tif_rawdata, - tif->tif_rawdatasize, NULL); - if (JBG_EOK != decodeStatus) - { - /* - * XXX: JBG_EN constant was defined in pre-2.0 releases of the - * JBIG-KIT. Since the 2.0 the error reporting functions were - * changed. We will handle both cases here. - */ - TIFFError("JBIG", "Error (%d) decoding: %s", decodeStatus, -#if defined(JBG_EN) - jbg_strerror(decodeStatus, JBG_EN) -#else - jbg_strerror(decodeStatus) -#endif - ); - return 0; - } - - pImage = jbg_dec_getimage(&decoder, 0); - _TIFFmemcpy(buffer, pImage, jbg_dec_getsize(&decoder)); - jbg_dec_free(&decoder); - return 1; -} - -static int JBIGSetupEncode(TIFF* tif) -{ - if (TIFFNumberOfStrips(tif) != 1) - { - TIFFError("JBIG", "Multistrip images not supported in encoder"); - return 0; - } - - return 1; -} - -static int JBIGCopyEncodedData(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s) -{ - (void) s; - while (cc > 0) - { - tsize_t n = cc; - - if (tif->tif_rawcc + n > tif->tif_rawdatasize) - { - n = tif->tif_rawdatasize - tif->tif_rawcc; - } - - assert(n > 0); - _TIFFmemcpy(tif->tif_rawcp, pp, n); - tif->tif_rawcp += n; - tif->tif_rawcc += n; - pp += n; - cc -= n; - if (tif->tif_rawcc >= tif->tif_rawdatasize && - !TIFFFlushData1(tif)) - { - return (-1); - } - } - - return (1); -} - -static void JBIGOutputBie(unsigned char* buffer, size_t len, void *userData) -{ - TIFF* tif = (TIFF*)userData; - - if (isFillOrder(tif, tif->tif_dir.td_fillorder)) - { - TIFFReverseBits(buffer, len); - } - - JBIGCopyEncodedData(tif, buffer, len, 0); -} - -static int JBIGEncode(TIFF* tif, tidata_t buffer, tsize_t size, tsample_t s) -{ - TIFFDirectory* dir = &tif->tif_dir; - struct jbg_enc_state encoder; - - (void) size, (void) s; - - jbg_enc_init(&encoder, - dir->td_imagewidth, - dir->td_imagelength, - 1, - &buffer, - JBIGOutputBie, - tif); - /* - * jbg_enc_out does the "real" encoding. As data is encoded, - * JBIGOutputBie is called, which writes the data to the directory. - */ - jbg_enc_out(&encoder); - jbg_enc_free(&encoder); - - return 1; -} - -static void JBIGCleanup(TIFF* tif) -{ - JBIGState *sp = GetJBIGState(tif); - - assert(sp != 0); - - tif->tif_tagmethods.vgetfield = sp->vgetparent; - tif->tif_tagmethods.vsetfield = sp->vsetparent; - - _TIFFfree(tif->tif_data); - tif->tif_data = NULL; - - _TIFFSetDefaultCompressionState(tif); -} - -static void JBIGPrintDir(TIFF* tif, FILE* fd, long flags) -{ - JBIGState* codec = GetJBIGState(tif); - (void)flags; - - if (TIFFFieldSet(tif, FIELD_RECVPARAMS)) - { - fprintf(fd, - " Fax Receive Parameters: %08lx\n", - (unsigned long)codec->recvparams); - } - - if (TIFFFieldSet(tif, FIELD_SUBADDRESS)) - { - fprintf(fd, - " Fax SubAddress: %s\n", - codec->subaddress); - } - - if (TIFFFieldSet(tif, FIELD_RECVTIME)) - { - fprintf(fd, - " Fax Receive Time: %lu secs\n", - (unsigned long)codec->recvtime); - } - - if (TIFFFieldSet(tif, FIELD_FAXDCS)) - { - fprintf(fd, - " Fax DCS: %s\n", - codec->faxdcs); - } -} - -static int JBIGVGetField(TIFF* tif, ttag_t tag, va_list ap) -{ - JBIGState* codec = GetJBIGState(tif); - - switch (tag) - { - case TIFFTAG_FAXRECVPARAMS: - *va_arg(ap, uint32*) = codec->recvparams; - break; - - case TIFFTAG_FAXSUBADDRESS: - *va_arg(ap, char**) = codec->subaddress; - break; - - case TIFFTAG_FAXRECVTIME: - *va_arg(ap, uint32*) = codec->recvtime; - break; - - case TIFFTAG_FAXDCS: - *va_arg(ap, char**) = codec->faxdcs; - break; - - default: - return (*codec->vgetparent)(tif, tag, ap); - } - - return 1; -} - -static int JBIGVSetField(TIFF* tif, ttag_t tag, va_list ap) -{ - JBIGState* codec = GetJBIGState(tif); - - switch (tag) - { - case TIFFTAG_FAXRECVPARAMS: - codec->recvparams = va_arg(ap, uint32); - break; - - case TIFFTAG_FAXSUBADDRESS: - _TIFFsetString(&codec->subaddress, va_arg(ap, char*)); - break; - - case TIFFTAG_FAXRECVTIME: - codec->recvtime = va_arg(ap, uint32); - break; - - case TIFFTAG_FAXDCS: - _TIFFsetString(&codec->faxdcs, va_arg(ap, char*)); - break; - - default: - return (*codec->vsetparent)(tif, tag, ap); - } - - TIFFSetFieldBit(tif, _TIFFFieldWithTag(tif, tag)->field_bit); - tif->tif_flags |= TIFF_DIRTYDIRECT; - return 1; -} - -int TIFFInitJBIG(TIFF* tif, int scheme) -{ - JBIGState* codec = NULL; - - assert(scheme == COMPRESSION_JBIG); - - /* - * Merge codec-specific tag information. - */ - if (!_TIFFMergeFieldInfo(tif, jbigFieldInfo, - TIFFArrayCount(jbigFieldInfo))) { - TIFFErrorExt(tif->tif_clientdata, "TIFFInitJBIG", - "Merging JBIG codec-specific tags failed"); - return 0; - } - - /* Allocate memory for the JBIGState structure.*/ - tif->tif_data = (tdata_t)_TIFFmalloc(sizeof(JBIGState)); - if (tif->tif_data == NULL) - { - TIFFError("TIFFInitJBIG", "Not enough memory for JBIGState"); - return 0; - } - _TIFFmemset(tif->tif_data, 0, sizeof(JBIGState)); - codec = GetJBIGState(tif); - - /* Initialize codec private fields */ - codec->recvparams = 0; - codec->subaddress = NULL; - codec->faxdcs = NULL; - codec->recvtime = 0; - - /* - * Override parent get/set field methods. - */ - codec->vgetparent = tif->tif_tagmethods.vgetfield; - codec->vsetparent = tif->tif_tagmethods.vsetfield; - tif->tif_tagmethods.vgetfield = JBIGVGetField; - tif->tif_tagmethods.vsetfield = JBIGVSetField; - tif->tif_tagmethods.printdir = JBIGPrintDir; - - /* - * These flags are set so the JBIG Codec can control when to reverse - * bits and when not to and to allow the jbig decoder and bit reverser - * to write to memory when necessary. - */ - tif->tif_flags |= TIFF_NOBITREV; - tif->tif_flags &= ~TIFF_MAPPED; - - /* Setup the function pointers for encode, decode, and cleanup. */ - tif->tif_setupdecode = JBIGSetupDecode; - tif->tif_decodestrip = JBIGDecode; - - tif->tif_setupencode = JBIGSetupEncode; - tif->tif_encodestrip = JBIGEncode; - - tif->tif_cleanup = JBIGCleanup; - - return 1; -} - -#endif /* JBIG_SUPPORT */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ - -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_jbig.c,v 1.23 2011/04/10 17:14:09 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * + * JBIG Compression Algorithm Support. + * Contributed by Lee Howard + * + */ + +#include "tiffiop.h" + +#ifdef JBIG_SUPPORT +#include "jbig.h" + +typedef struct +{ + uint32 recvparams; /* encoded Class 2 session params */ + char* subaddress; /* subaddress string */ + uint32 recvtime; /* time spend receiving in seconds */ + char* faxdcs; /* encoded fax parameters (DCS, Table 2/T.30) */ + + TIFFVGetMethod vgetparent; + TIFFVSetMethod vsetparent; +} JBIGState; + +#define GetJBIGState(tif) ((JBIGState*)(tif)->tif_data) + +#define FIELD_RECVPARAMS (FIELD_CODEC+0) +#define FIELD_SUBADDRESS (FIELD_CODEC+1) +#define FIELD_RECVTIME (FIELD_CODEC+2) +#define FIELD_FAXDCS (FIELD_CODEC+3) + +static const TIFFFieldInfo jbigFieldInfo[] = +{ + {TIFFTAG_FAXRECVPARAMS, 1, 1, TIFF_LONG, FIELD_RECVPARAMS, TRUE, FALSE, "FaxRecvParams"}, + {TIFFTAG_FAXSUBADDRESS, -1, -1, TIFF_ASCII, FIELD_SUBADDRESS, TRUE, FALSE, "FaxSubAddress"}, + {TIFFTAG_FAXRECVTIME, 1, 1, TIFF_LONG, FIELD_RECVTIME, TRUE, FALSE, "FaxRecvTime"}, + {TIFFTAG_FAXDCS, -1, -1, TIFF_ASCII, FIELD_FAXDCS, TRUE, FALSE, "FaxDcs"}, +}; + +static int JBIGSetupDecode(TIFF* tif) +{ + if (TIFFNumberOfStrips(tif) != 1) + { + TIFFError("JBIG", "Multistrip images not supported in decoder"); + return 0; + } + + return 1; +} + +static int JBIGDecode(TIFF* tif, tidata_t buffer, tsize_t size, tsample_t s) +{ + struct jbg_dec_state decoder; + int decodeStatus = 0; + unsigned char* pImage = NULL; + (void) size, (void) s; + + if (isFillOrder(tif, tif->tif_dir.td_fillorder)) + { + TIFFReverseBits(tif->tif_rawdata, tif->tif_rawdatasize); + } + + jbg_dec_init(&decoder); + +#if defined(HAVE_JBG_NEWLEN) + jbg_newlen(tif->tif_rawdata, tif->tif_rawdatasize); + /* + * I do not check the return status of jbg_newlen because even if this + * function fails it does not necessarily mean that decoding the image + * will fail. It is generally only needed for received fax images + * that do not contain the actual length of the image in the BIE + * header. I do not log when an error occurs because that will cause + * problems when converting JBIG encoded TIFF's to + * PostScript. As long as the actual image length is contained in the + * BIE header jbg_dec_in should succeed. + */ +#endif /* HAVE_JBG_NEWLEN */ + + decodeStatus = jbg_dec_in(&decoder, tif->tif_rawdata, + tif->tif_rawdatasize, NULL); + if (JBG_EOK != decodeStatus) + { + /* + * XXX: JBG_EN constant was defined in pre-2.0 releases of the + * JBIG-KIT. Since the 2.0 the error reporting functions were + * changed. We will handle both cases here. + */ + TIFFError("JBIG", "Error (%d) decoding: %s", decodeStatus, +#if defined(JBG_EN) + jbg_strerror(decodeStatus, JBG_EN) +#else + jbg_strerror(decodeStatus) +#endif + ); + return 0; + } + + pImage = jbg_dec_getimage(&decoder, 0); + _TIFFmemcpy(buffer, pImage, jbg_dec_getsize(&decoder)); + jbg_dec_free(&decoder); + return 1; +} + +static int JBIGSetupEncode(TIFF* tif) +{ + if (TIFFNumberOfStrips(tif) != 1) + { + TIFFError("JBIG", "Multistrip images not supported in encoder"); + return 0; + } + + return 1; +} + +static int JBIGCopyEncodedData(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s) +{ + (void) s; + while (cc > 0) + { + tsize_t n = cc; + + if (tif->tif_rawcc + n > tif->tif_rawdatasize) + { + n = tif->tif_rawdatasize - tif->tif_rawcc; + } + + assert(n > 0); + _TIFFmemcpy(tif->tif_rawcp, pp, n); + tif->tif_rawcp += n; + tif->tif_rawcc += n; + pp += n; + cc -= n; + if (tif->tif_rawcc >= tif->tif_rawdatasize && + !TIFFFlushData1(tif)) + { + return (-1); + } + } + + return (1); +} + +static void JBIGOutputBie(unsigned char* buffer, size_t len, void *userData) +{ + TIFF* tif = (TIFF*)userData; + + if (isFillOrder(tif, tif->tif_dir.td_fillorder)) + { + TIFFReverseBits(buffer, len); + } + + JBIGCopyEncodedData(tif, buffer, len, 0); +} + +static int JBIGEncode(TIFF* tif, tidata_t buffer, tsize_t size, tsample_t s) +{ + TIFFDirectory* dir = &tif->tif_dir; + struct jbg_enc_state encoder; + + (void) size, (void) s; + + jbg_enc_init(&encoder, + dir->td_imagewidth, + dir->td_imagelength, + 1, + &buffer, + JBIGOutputBie, + tif); + /* + * jbg_enc_out does the "real" encoding. As data is encoded, + * JBIGOutputBie is called, which writes the data to the directory. + */ + jbg_enc_out(&encoder); + jbg_enc_free(&encoder); + + return 1; +} + +static void JBIGCleanup(TIFF* tif) +{ + JBIGState *sp = GetJBIGState(tif); + + assert(sp != 0); + + tif->tif_tagmethods.vgetfield = sp->vgetparent; + tif->tif_tagmethods.vsetfield = sp->vsetparent; + + _TIFFfree(tif->tif_data); + tif->tif_data = NULL; + + _TIFFSetDefaultCompressionState(tif); +} + +static void JBIGPrintDir(TIFF* tif, FILE* fd, long flags) +{ + JBIGState* codec = GetJBIGState(tif); + (void)flags; + + if (TIFFFieldSet(tif, FIELD_RECVPARAMS)) + { + fprintf(fd, + " Fax Receive Parameters: %08lx\n", + (unsigned long)codec->recvparams); + } + + if (TIFFFieldSet(tif, FIELD_SUBADDRESS)) + { + fprintf(fd, + " Fax SubAddress: %s\n", + codec->subaddress); + } + + if (TIFFFieldSet(tif, FIELD_RECVTIME)) + { + fprintf(fd, + " Fax Receive Time: %lu secs\n", + (unsigned long)codec->recvtime); + } + + if (TIFFFieldSet(tif, FIELD_FAXDCS)) + { + fprintf(fd, + " Fax DCS: %s\n", + codec->faxdcs); + } +} + +static int JBIGVGetField(TIFF* tif, ttag_t tag, va_list ap) +{ + JBIGState* codec = GetJBIGState(tif); + + switch (tag) + { + case TIFFTAG_FAXRECVPARAMS: + *va_arg(ap, uint32*) = codec->recvparams; + break; + + case TIFFTAG_FAXSUBADDRESS: + *va_arg(ap, char**) = codec->subaddress; + break; + + case TIFFTAG_FAXRECVTIME: + *va_arg(ap, uint32*) = codec->recvtime; + break; + + case TIFFTAG_FAXDCS: + *va_arg(ap, char**) = codec->faxdcs; + break; + + default: + return (*codec->vgetparent)(tif, tag, ap); + } + + return 1; +} + +static int JBIGVSetField(TIFF* tif, ttag_t tag, va_list ap) +{ + JBIGState* codec = GetJBIGState(tif); + + switch (tag) + { + case TIFFTAG_FAXRECVPARAMS: + codec->recvparams = va_arg(ap, uint32); + break; + + case TIFFTAG_FAXSUBADDRESS: + _TIFFsetString(&codec->subaddress, va_arg(ap, char*)); + break; + + case TIFFTAG_FAXRECVTIME: + codec->recvtime = va_arg(ap, uint32); + break; + + case TIFFTAG_FAXDCS: + _TIFFsetString(&codec->faxdcs, va_arg(ap, char*)); + break; + + default: + return (*codec->vsetparent)(tif, tag, ap); + } + + TIFFSetFieldBit(tif, _TIFFFieldWithTag(tif, tag)->field_bit); + tif->tif_flags |= TIFF_DIRTYDIRECT; + return 1; +} + +int TIFFInitJBIG(TIFF* tif, int scheme) +{ + JBIGState* codec = NULL; + + assert(scheme == COMPRESSION_JBIG); + + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFieldInfo(tif, jbigFieldInfo, + TIFFArrayCount(jbigFieldInfo))) { + TIFFErrorExt(tif->tif_clientdata, "TIFFInitJBIG", + "Merging JBIG codec-specific tags failed"); + return 0; + } + + /* Allocate memory for the JBIGState structure.*/ + tif->tif_data = (tdata_t)_TIFFmalloc(sizeof(JBIGState)); + if (tif->tif_data == NULL) + { + TIFFError("TIFFInitJBIG", "Not enough memory for JBIGState"); + return 0; + } + _TIFFmemset(tif->tif_data, 0, sizeof(JBIGState)); + codec = GetJBIGState(tif); + + /* Initialize codec private fields */ + codec->recvparams = 0; + codec->subaddress = NULL; + codec->faxdcs = NULL; + codec->recvtime = 0; + + /* + * Override parent get/set field methods. + */ + codec->vgetparent = tif->tif_tagmethods.vgetfield; + codec->vsetparent = tif->tif_tagmethods.vsetfield; + tif->tif_tagmethods.vgetfield = JBIGVGetField; + tif->tif_tagmethods.vsetfield = JBIGVSetField; + tif->tif_tagmethods.printdir = JBIGPrintDir; + + /* + * These flags are set so the JBIG Codec can control when to reverse + * bits and when not to and to allow the jbig decoder and bit reverser + * to write to memory when necessary. + */ + tif->tif_flags |= TIFF_NOBITREV; + tif->tif_flags &= ~TIFF_MAPPED; + + /* Setup the function pointers for encode, decode, and cleanup. */ + tif->tif_setupdecode = JBIGSetupDecode; + tif->tif_decodestrip = JBIGDecode; + + tif->tif_setupencode = JBIGSetupEncode; + tif->tif_encodestrip = JBIGEncode; + + tif->tif_cleanup = JBIGCleanup; + + return 1; +} + +#endif /* JBIG_SUPPORT */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ + +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF/tif_msdos.c b/Source/LibTIFF/tif_msdos.c index 884981f..a71ef43 100644 --- a/Source/LibTIFF/tif_msdos.c +++ b/Source/LibTIFF/tif_msdos.c @@ -1,193 +1,193 @@ -/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF/tif_msdos.c,v 1.35 2011/04/10 17:14:09 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library MSDOS-specific Routines. - */ -#if defined(__WATCOMC__) || defined(__BORLANDC__) || defined(_MSC_VER) -#include /* for open, close, etc. function prototypes */ -#include -#endif -#include "tiffiop.h" - -static tsize_t -_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - return (read((int) fd, buf, size)); -} - -static tsize_t -_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - return (write((int) fd, buf, size)); -} - -static toff_t -_tiffSeekProc(thandle_t fd, toff_t off, int whence) -{ - return (lseek((int) fd, (off_t) off, whence)); -} - -static int -_tiffCloseProc(thandle_t fd) -{ - return (close((int) fd)); -} - -#include - -static toff_t -_tiffSizeProc(thandle_t fd) -{ - struct stat sb; - return (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size); -} - -static int -_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) -{ - return (0); -} - -static void -_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) -{ -} - -/* - * Open a TIFF file descriptor for read/writing. - */ -TIFF* -TIFFFdOpen(int fd, const char* name, const char* mode) -{ - TIFF* tif; - - tif = TIFFClientOpen(name, mode, - (void*) fd, - _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, - _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); - if (tif) - tif->tif_fd = fd; - return (tif); -} - -/* - * Open a TIFF file for read/writing. - */ -TIFF* -TIFFOpen(const char* name, const char* mode) -{ - static const char module[] = "TIFFOpen"; - int m, fd; - TIFF *ret; - - m = _TIFFgetMode(mode, module); - if (m == -1) - return ((TIFF*)0); - fd = open(name, m|O_BINARY, 0666); - if (fd < 0) { - TIFFErrorExt(0, module, "%s: Cannot open", name); - return ((TIFF*)0); - } - return (TIFFFdOpen(fd, name, mode)); - - ret = TIFFFdOpen(fd, name, mode); - - if (ret == NULL) close(fd); - - return ret; -} - -#ifdef __GNUC__ -extern char* malloc(); -extern char* realloc(); -#else -#include -#endif - -tdata_t -_TIFFmalloc(tsize_t s) -{ - return (malloc((size_t) s)); -} - -void -_TIFFfree(tdata_t p) -{ - free(p); -} - -tdata_t -_TIFFrealloc(tdata_t p, tsize_t s) -{ - return (realloc(p, (size_t) s)); -} - -void -_TIFFmemset(tdata_t p, int v, tsize_t c) -{ - memset(p, v, (size_t) c); -} - -void -_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) -{ - memcpy(d, s, (size_t) c); -} - -int -_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) -{ - return (memcmp(p1, p2, (size_t) c)); -} - -static void -msdosWarningHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - fprintf(stderr, "%s: ", module); - fprintf(stderr, "Warning, "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} -TIFFErrorHandler _TIFFwarningHandler = msdosWarningHandler; - -static void -msdosErrorHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - fprintf(stderr, "%s: ", module); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} -TIFFErrorHandler _TIFFerrorHandler = msdosErrorHandler; -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF/tif_msdos.c,v 1.35 2011/04/10 17:14:09 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library MSDOS-specific Routines. + */ +#if defined(__WATCOMC__) || defined(__BORLANDC__) || defined(_MSC_VER) +#include /* for open, close, etc. function prototypes */ +#include +#endif +#include "tiffiop.h" + +static tsize_t +_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + return (read((int) fd, buf, size)); +} + +static tsize_t +_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + return (write((int) fd, buf, size)); +} + +static toff_t +_tiffSeekProc(thandle_t fd, toff_t off, int whence) +{ + return (lseek((int) fd, (off_t) off, whence)); +} + +static int +_tiffCloseProc(thandle_t fd) +{ + return (close((int) fd)); +} + +#include + +static toff_t +_tiffSizeProc(thandle_t fd) +{ + struct stat sb; + return (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size); +} + +static int +_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) +{ + return (0); +} + +static void +_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) +{ +} + +/* + * Open a TIFF file descriptor for read/writing. + */ +TIFF* +TIFFFdOpen(int fd, const char* name, const char* mode) +{ + TIFF* tif; + + tif = TIFFClientOpen(name, mode, + (void*) fd, + _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, + _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); + if (tif) + tif->tif_fd = fd; + return (tif); +} + +/* + * Open a TIFF file for read/writing. + */ +TIFF* +TIFFOpen(const char* name, const char* mode) +{ + static const char module[] = "TIFFOpen"; + int m, fd; + TIFF *ret; + + m = _TIFFgetMode(mode, module); + if (m == -1) + return ((TIFF*)0); + fd = open(name, m|O_BINARY, 0666); + if (fd < 0) { + TIFFErrorExt(0, module, "%s: Cannot open", name); + return ((TIFF*)0); + } + return (TIFFFdOpen(fd, name, mode)); + + ret = TIFFFdOpen(fd, name, mode); + + if (ret == NULL) close(fd); + + return ret; +} + +#ifdef __GNUC__ +extern char* malloc(); +extern char* realloc(); +#else +#include +#endif + +tdata_t +_TIFFmalloc(tsize_t s) +{ + return (malloc((size_t) s)); +} + +void +_TIFFfree(tdata_t p) +{ + free(p); +} + +tdata_t +_TIFFrealloc(tdata_t p, tsize_t s) +{ + return (realloc(p, (size_t) s)); +} + +void +_TIFFmemset(tdata_t p, int v, tsize_t c) +{ + memset(p, v, (size_t) c); +} + +void +_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) +{ + memcpy(d, s, (size_t) c); +} + +int +_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) +{ + return (memcmp(p1, p2, (size_t) c)); +} + +static void +msdosWarningHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + fprintf(stderr, "%s: ", module); + fprintf(stderr, "Warning, "); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} +TIFFErrorHandler _TIFFwarningHandler = msdosWarningHandler; + +static void +msdosErrorHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + fprintf(stderr, "%s: ", module); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} +TIFFErrorHandler _TIFFerrorHandler = msdosErrorHandler; +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF/tif_stream.cxx b/Source/LibTIFF/tif_stream.cxx index a3aaea1..1ac3c07 100644 --- a/Source/LibTIFF/tif_stream.cxx +++ b/Source/LibTIFF/tif_stream.cxx @@ -1,295 +1,295 @@ -/* $Id: tif_stream.cxx,v 1.32 2011/04/10 17:14:09 drolon Exp $ */ - -/* - * Copyright (c) 1988-1996 Sam Leffler - * Copyright (c) 1991-1996 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library UNIX-specific Routines. - */ -#include "tiffiop.h" -#include - -#ifndef __VMS -using namespace std; -#endif - -class tiffis_data -{ - public: - - istream *myIS; - long myStreamStartPos; -}; - -class tiffos_data -{ - public: - - ostream *myOS; - long myStreamStartPos; -}; - -static tsize_t -_tiffosReadProc(thandle_t, tdata_t, tsize_t) -{ - return 0; -} - -static tsize_t -_tiffisReadProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - tiffis_data *data = (tiffis_data *)fd; - - data->myIS->read((char *)buf, (int)size); - - return data->myIS->gcount(); -} - -static tsize_t -_tiffosWriteProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - tiffos_data *data = (tiffos_data *)fd; - ostream *os = data->myOS; - int pos = os->tellp(); - - os->write((const char *)buf, size); - - return ((int)os->tellp()) - pos; -} - -static tsize_t -_tiffisWriteProc(thandle_t, tdata_t, tsize_t) -{ - return 0; -} - -static toff_t -_tiffosSeekProc(thandle_t fd, toff_t off, int whence) -{ - tiffos_data *data = (tiffos_data *)fd; - ostream *os = data->myOS; - - // if the stream has already failed, don't do anything - if( os->fail() ) - return os->tellp(); - - switch(whence) { - case SEEK_SET: - os->seekp(data->myStreamStartPos + off, ios::beg); - break; - case SEEK_CUR: - os->seekp(off, ios::cur); - break; - case SEEK_END: - os->seekp(off, ios::end); - break; - } - - // Attempt to workaround problems with seeking past the end of the - // stream. ofstream doesn't have a problem with this but - // ostrstream/ostringstream does. In that situation, add intermediate - // '\0' characters. - if( os->fail() ) { -#ifdef __VMS - int old_state; -#else - ios::iostate old_state; -#endif - toff_t origin=0; - - old_state = os->rdstate(); - // reset the fail bit or else tellp() won't work below - os->clear(os->rdstate() & ~ios::failbit); - switch( whence ) { - case SEEK_SET: - origin = data->myStreamStartPos; - break; - case SEEK_CUR: - origin = os->tellp(); - break; - case SEEK_END: - os->seekp(0, ios::end); - origin = os->tellp(); - break; - } - // restore original stream state - os->clear(old_state); - - // only do something if desired seek position is valid - if( origin + off > data->myStreamStartPos ) { - toff_t num_fill; - - // clear the fail bit - os->clear(os->rdstate() & ~ios::failbit); - - // extend the stream to the expected size - os->seekp(0, ios::end); - num_fill = origin + off - (toff_t)os->tellp(); - for( toff_t i = 0; i < num_fill; i++ ) - os->put('\0'); - - // retry the seek - os->seekp(origin + off, ios::beg); - } - } - - return os->tellp(); -} - -static toff_t -_tiffisSeekProc(thandle_t fd, toff_t off, int whence) -{ - tiffis_data *data = (tiffis_data *)fd; - - switch(whence) { - case SEEK_SET: - data->myIS->seekg(data->myStreamStartPos + off, ios::beg); - break; - case SEEK_CUR: - data->myIS->seekg(off, ios::cur); - break; - case SEEK_END: - data->myIS->seekg(off, ios::end); - break; - } - - return ((long)data->myIS->tellg()) - data->myStreamStartPos; -} - -static toff_t -_tiffosSizeProc(thandle_t fd) -{ - tiffos_data *data = (tiffos_data *)fd; - ostream *os = data->myOS; - toff_t pos = os->tellp(); - toff_t len; - - os->seekp(0, ios::end); - len = os->tellp(); - os->seekp(pos); - - return len; -} - -static toff_t -_tiffisSizeProc(thandle_t fd) -{ - tiffis_data *data = (tiffis_data *)fd; - int pos = data->myIS->tellg(); - int len; - - data->myIS->seekg(0, ios::end); - len = data->myIS->tellg(); - data->myIS->seekg(pos); - - return len; -} - -static int -_tiffosCloseProc(thandle_t fd) -{ - // Our stream was not allocated by us, so it shouldn't be closed by us. - delete (tiffos_data *)fd; - return 0; -} - -static int -_tiffisCloseProc(thandle_t fd) -{ - // Our stream was not allocated by us, so it shouldn't be closed by us. - delete (tiffis_data *)fd; - return 0; -} - -static int -_tiffDummyMapProc(thandle_t , tdata_t* , toff_t* ) -{ - return (0); -} - -static void -_tiffDummyUnmapProc(thandle_t , tdata_t , toff_t ) -{ -} - -/* - * Open a TIFF file descriptor for read/writing. - */ -static TIFF* -_tiffStreamOpen(const char* name, const char* mode, void *fd) -{ - TIFF* tif; - - if( strchr(mode, 'w') ) { - tiffos_data *data = new tiffos_data; - data->myOS = (ostream *)fd; - data->myStreamStartPos = data->myOS->tellp(); - - // Open for writing. - tif = TIFFClientOpen(name, mode, - (thandle_t) data, - _tiffosReadProc, _tiffosWriteProc, - _tiffosSeekProc, _tiffosCloseProc, - _tiffosSizeProc, - _tiffDummyMapProc, _tiffDummyUnmapProc); - } else { - tiffis_data *data = new tiffis_data; - data->myIS = (istream *)fd; - data->myStreamStartPos = data->myIS->tellg(); - // Open for reading. - tif = TIFFClientOpen(name, mode, - (thandle_t) data, - _tiffisReadProc, _tiffisWriteProc, - _tiffisSeekProc, _tiffisCloseProc, - _tiffisSizeProc, - _tiffDummyMapProc, _tiffDummyUnmapProc); - } - - return (tif); -} - -TIFF* -TIFFStreamOpen(const char* name, ostream *os) -{ - // If os is either a ostrstream or ostringstream, and has no data - // written to it yet, then tellp() will return -1 which will break us. - // We workaround this by writing out a dummy character and - // then seek back to the beginning. - if( !os->fail() && (int)os->tellp() < 0 ) { - *os << '\0'; - os->seekp(0); - } - - // NB: We don't support mapped files with streams so add 'm' - return _tiffStreamOpen(name, "wm", os); -} - -TIFF* -TIFFStreamOpen(const char* name, istream *is) -{ - // NB: We don't support mapped files with streams so add 'm' - return _tiffStreamOpen(name, "rm", is); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ +/* $Id: tif_stream.cxx,v 1.32 2011/04/10 17:14:09 drolon Exp $ */ + +/* + * Copyright (c) 1988-1996 Sam Leffler + * Copyright (c) 1991-1996 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library UNIX-specific Routines. + */ +#include "tiffiop.h" +#include + +#ifndef __VMS +using namespace std; +#endif + +class tiffis_data +{ + public: + + istream *myIS; + long myStreamStartPos; +}; + +class tiffos_data +{ + public: + + ostream *myOS; + long myStreamStartPos; +}; + +static tsize_t +_tiffosReadProc(thandle_t, tdata_t, tsize_t) +{ + return 0; +} + +static tsize_t +_tiffisReadProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + tiffis_data *data = (tiffis_data *)fd; + + data->myIS->read((char *)buf, (int)size); + + return data->myIS->gcount(); +} + +static tsize_t +_tiffosWriteProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + tiffos_data *data = (tiffos_data *)fd; + ostream *os = data->myOS; + int pos = os->tellp(); + + os->write((const char *)buf, size); + + return ((int)os->tellp()) - pos; +} + +static tsize_t +_tiffisWriteProc(thandle_t, tdata_t, tsize_t) +{ + return 0; +} + +static toff_t +_tiffosSeekProc(thandle_t fd, toff_t off, int whence) +{ + tiffos_data *data = (tiffos_data *)fd; + ostream *os = data->myOS; + + // if the stream has already failed, don't do anything + if( os->fail() ) + return os->tellp(); + + switch(whence) { + case SEEK_SET: + os->seekp(data->myStreamStartPos + off, ios::beg); + break; + case SEEK_CUR: + os->seekp(off, ios::cur); + break; + case SEEK_END: + os->seekp(off, ios::end); + break; + } + + // Attempt to workaround problems with seeking past the end of the + // stream. ofstream doesn't have a problem with this but + // ostrstream/ostringstream does. In that situation, add intermediate + // '\0' characters. + if( os->fail() ) { +#ifdef __VMS + int old_state; +#else + ios::iostate old_state; +#endif + toff_t origin=0; + + old_state = os->rdstate(); + // reset the fail bit or else tellp() won't work below + os->clear(os->rdstate() & ~ios::failbit); + switch( whence ) { + case SEEK_SET: + origin = data->myStreamStartPos; + break; + case SEEK_CUR: + origin = os->tellp(); + break; + case SEEK_END: + os->seekp(0, ios::end); + origin = os->tellp(); + break; + } + // restore original stream state + os->clear(old_state); + + // only do something if desired seek position is valid + if( origin + off > data->myStreamStartPos ) { + toff_t num_fill; + + // clear the fail bit + os->clear(os->rdstate() & ~ios::failbit); + + // extend the stream to the expected size + os->seekp(0, ios::end); + num_fill = origin + off - (toff_t)os->tellp(); + for( toff_t i = 0; i < num_fill; i++ ) + os->put('\0'); + + // retry the seek + os->seekp(origin + off, ios::beg); + } + } + + return os->tellp(); +} + +static toff_t +_tiffisSeekProc(thandle_t fd, toff_t off, int whence) +{ + tiffis_data *data = (tiffis_data *)fd; + + switch(whence) { + case SEEK_SET: + data->myIS->seekg(data->myStreamStartPos + off, ios::beg); + break; + case SEEK_CUR: + data->myIS->seekg(off, ios::cur); + break; + case SEEK_END: + data->myIS->seekg(off, ios::end); + break; + } + + return ((long)data->myIS->tellg()) - data->myStreamStartPos; +} + +static toff_t +_tiffosSizeProc(thandle_t fd) +{ + tiffos_data *data = (tiffos_data *)fd; + ostream *os = data->myOS; + toff_t pos = os->tellp(); + toff_t len; + + os->seekp(0, ios::end); + len = os->tellp(); + os->seekp(pos); + + return len; +} + +static toff_t +_tiffisSizeProc(thandle_t fd) +{ + tiffis_data *data = (tiffis_data *)fd; + int pos = data->myIS->tellg(); + int len; + + data->myIS->seekg(0, ios::end); + len = data->myIS->tellg(); + data->myIS->seekg(pos); + + return len; +} + +static int +_tiffosCloseProc(thandle_t fd) +{ + // Our stream was not allocated by us, so it shouldn't be closed by us. + delete (tiffos_data *)fd; + return 0; +} + +static int +_tiffisCloseProc(thandle_t fd) +{ + // Our stream was not allocated by us, so it shouldn't be closed by us. + delete (tiffis_data *)fd; + return 0; +} + +static int +_tiffDummyMapProc(thandle_t , tdata_t* , toff_t* ) +{ + return (0); +} + +static void +_tiffDummyUnmapProc(thandle_t , tdata_t , toff_t ) +{ +} + +/* + * Open a TIFF file descriptor for read/writing. + */ +static TIFF* +_tiffStreamOpen(const char* name, const char* mode, void *fd) +{ + TIFF* tif; + + if( strchr(mode, 'w') ) { + tiffos_data *data = new tiffos_data; + data->myOS = (ostream *)fd; + data->myStreamStartPos = data->myOS->tellp(); + + // Open for writing. + tif = TIFFClientOpen(name, mode, + (thandle_t) data, + _tiffosReadProc, _tiffosWriteProc, + _tiffosSeekProc, _tiffosCloseProc, + _tiffosSizeProc, + _tiffDummyMapProc, _tiffDummyUnmapProc); + } else { + tiffis_data *data = new tiffis_data; + data->myIS = (istream *)fd; + data->myStreamStartPos = data->myIS->tellg(); + // Open for reading. + tif = TIFFClientOpen(name, mode, + (thandle_t) data, + _tiffisReadProc, _tiffisWriteProc, + _tiffisSeekProc, _tiffisCloseProc, + _tiffisSizeProc, + _tiffDummyMapProc, _tiffDummyUnmapProc); + } + + return (tif); +} + +TIFF* +TIFFStreamOpen(const char* name, ostream *os) +{ + // If os is either a ostrstream or ostringstream, and has no data + // written to it yet, then tellp() will return -1 which will break us. + // We workaround this by writing out a dummy character and + // then seek back to the beginning. + if( !os->fail() && (int)os->tellp() < 0 ) { + *os << '\0'; + os->seekp(0); + } + + // NB: We don't support mapped files with streams so add 'm' + return _tiffStreamOpen(name, "wm", os); +} + +TIFF* +TIFFStreamOpen(const char* name, istream *is) +{ + // NB: We don't support mapped files with streams so add 'm' + return _tiffStreamOpen(name, "rm", is); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ diff --git a/Source/LibTIFF/tif_unix.c b/Source/LibTIFF/tif_unix.c index f693df7..ecfaedd 100644 --- a/Source/LibTIFF/tif_unix.c +++ b/Source/LibTIFF/tif_unix.c @@ -1,300 +1,300 @@ -/* $Id: tif_unix.c,v 1.35 2011/04/10 17:14:09 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library UNIX-specific Routines. These are should also work with the - * Windows Common RunTime Library. - */ -#include "tif_config.h" - -#ifdef HAVE_SYS_TYPES_H -# include -#endif - -#include -#include -#include - -#ifdef HAVE_UNISTD_H -# include -#endif - -#ifdef HAVE_FCNTL_H -# include -#endif - -#ifdef HAVE_IO_H -# include -#endif - -#include "tiffiop.h" - -static tsize_t -_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - return ((tsize_t) read((int) fd, buf, (size_t) size)); -} - -static tsize_t -_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - return ((tsize_t) write((int) fd, buf, (size_t) size)); -} - -static toff_t -_tiffSeekProc(thandle_t fd, toff_t off, int whence) -{ - return ((toff_t) lseek((int) fd, (off_t) off, whence)); -} - -static int -_tiffCloseProc(thandle_t fd) -{ - return (close((int) fd)); -} - - -static toff_t -_tiffSizeProc(thandle_t fd) -{ -#ifdef _AM29K - long fsize; - return ((fsize = lseek((int) fd, 0, SEEK_END)) < 0 ? 0 : fsize); -#else - struct stat sb; - return (toff_t) (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size); -#endif -} - -#ifdef HAVE_MMAP -#include - -static int -_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) -{ - toff_t size = _tiffSizeProc(fd); - if (size != (toff_t) -1) { - *pbase = (tdata_t) - mmap(0, size, PROT_READ, MAP_SHARED, (int) fd, 0); - if (*pbase != (tdata_t) -1) { - *psize = size; - return (1); - } - } - return (0); -} - -static void -_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) -{ - (void) fd; - (void) munmap(base, (off_t) size); -} -#else /* !HAVE_MMAP */ -static int -_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) -{ - (void) fd; (void) pbase; (void) psize; - return (0); -} - -static void -_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) -{ - (void) fd; (void) base; (void) size; -} -#endif /* !HAVE_MMAP */ - -/* - * Open a TIFF file descriptor for read/writing. - */ -TIFF* -TIFFFdOpen(int fd, const char* name, const char* mode) -{ - TIFF* tif; - - tif = TIFFClientOpen(name, mode, - (thandle_t) fd, - _tiffReadProc, _tiffWriteProc, - _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, - _tiffMapProc, _tiffUnmapProc); - if (tif) - tif->tif_fd = fd; - return (tif); -} - -/* - * Open a TIFF file for read/writing. - */ -TIFF* -TIFFOpen(const char* name, const char* mode) -{ - static const char module[] = "TIFFOpen"; - int m, fd; - TIFF* tif; - - m = _TIFFgetMode(mode, module); - if (m == -1) - return ((TIFF*)0); - -/* for cygwin and mingw */ -#ifdef O_BINARY - m |= O_BINARY; -#endif - -#ifdef _AM29K - fd = open(name, m); -#else - fd = open(name, m, 0666); -#endif - if (fd < 0) { - TIFFErrorExt(0, module, "%s: Cannot open", name); - return ((TIFF *)0); - } - - tif = TIFFFdOpen((int)fd, name, mode); - if(!tif) - close(fd); - return tif; -} - -#ifdef __WIN32__ -#include -/* - * Open a TIFF file with a Unicode filename, for read/writing. - */ -TIFF* -TIFFOpenW(const wchar_t* name, const char* mode) -{ - static const char module[] = "TIFFOpenW"; - int m, fd; - int mbsize; - char *mbname; - TIFF* tif; - - m = _TIFFgetMode(mode, module); - if (m == -1) - return ((TIFF*)0); - -/* for cygwin and mingw */ -#ifdef O_BINARY - m |= O_BINARY; -#endif - - fd = _wopen(name, m, 0666); - if (fd < 0) { - TIFFErrorExt(0, module, "%s: Cannot open", name); - return ((TIFF *)0); - } - - mbname = NULL; - mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL); - if (mbsize > 0) { - mbname = _TIFFmalloc(mbsize); - if (!mbname) { - TIFFErrorExt(0, module, - "Can't allocate space for filename conversion buffer"); - return ((TIFF*)0); - } - - WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, - NULL, NULL); - } - - tif = TIFFFdOpen((int)fd, (mbname != NULL) ? mbname : "", - mode); - - _TIFFfree(mbname); - - if(!tif) - close(fd); - return tif; -} -#endif - -void* -_TIFFmalloc(tsize_t s) -{ - return (malloc((size_t) s)); -} - -void -_TIFFfree(tdata_t p) -{ - free(p); -} - -void* -_TIFFrealloc(tdata_t p, tsize_t s) -{ - return (realloc(p, (size_t) s)); -} - -void -_TIFFmemset(tdata_t p, int v, tsize_t c) -{ - memset(p, v, (size_t) c); -} - -void -_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) -{ - memcpy(d, s, (size_t) c); -} - -int -_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) -{ - return (memcmp(p1, p2, (size_t) c)); -} - -static void -unixWarningHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - fprintf(stderr, "%s: ", module); - fprintf(stderr, "Warning, "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} -TIFFErrorHandler _TIFFwarningHandler = unixWarningHandler; - -static void -unixErrorHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - fprintf(stderr, "%s: ", module); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} -TIFFErrorHandler _TIFFerrorHandler = unixErrorHandler; -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_unix.c,v 1.35 2011/04/10 17:14:09 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library UNIX-specific Routines. These are should also work with the + * Windows Common RunTime Library. + */ +#include "tif_config.h" + +#ifdef HAVE_SYS_TYPES_H +# include +#endif + +#include +#include +#include + +#ifdef HAVE_UNISTD_H +# include +#endif + +#ifdef HAVE_FCNTL_H +# include +#endif + +#ifdef HAVE_IO_H +# include +#endif + +#include "tiffiop.h" + +static tsize_t +_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + return ((tsize_t) read((int) fd, buf, (size_t) size)); +} + +static tsize_t +_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + return ((tsize_t) write((int) fd, buf, (size_t) size)); +} + +static toff_t +_tiffSeekProc(thandle_t fd, toff_t off, int whence) +{ + return ((toff_t) lseek((int) fd, (off_t) off, whence)); +} + +static int +_tiffCloseProc(thandle_t fd) +{ + return (close((int) fd)); +} + + +static toff_t +_tiffSizeProc(thandle_t fd) +{ +#ifdef _AM29K + long fsize; + return ((fsize = lseek((int) fd, 0, SEEK_END)) < 0 ? 0 : fsize); +#else + struct stat sb; + return (toff_t) (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size); +#endif +} + +#ifdef HAVE_MMAP +#include + +static int +_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) +{ + toff_t size = _tiffSizeProc(fd); + if (size != (toff_t) -1) { + *pbase = (tdata_t) + mmap(0, size, PROT_READ, MAP_SHARED, (int) fd, 0); + if (*pbase != (tdata_t) -1) { + *psize = size; + return (1); + } + } + return (0); +} + +static void +_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) +{ + (void) fd; + (void) munmap(base, (off_t) size); +} +#else /* !HAVE_MMAP */ +static int +_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) +{ + (void) fd; (void) pbase; (void) psize; + return (0); +} + +static void +_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) +{ + (void) fd; (void) base; (void) size; +} +#endif /* !HAVE_MMAP */ + +/* + * Open a TIFF file descriptor for read/writing. + */ +TIFF* +TIFFFdOpen(int fd, const char* name, const char* mode) +{ + TIFF* tif; + + tif = TIFFClientOpen(name, mode, + (thandle_t) fd, + _tiffReadProc, _tiffWriteProc, + _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, + _tiffMapProc, _tiffUnmapProc); + if (tif) + tif->tif_fd = fd; + return (tif); +} + +/* + * Open a TIFF file for read/writing. + */ +TIFF* +TIFFOpen(const char* name, const char* mode) +{ + static const char module[] = "TIFFOpen"; + int m, fd; + TIFF* tif; + + m = _TIFFgetMode(mode, module); + if (m == -1) + return ((TIFF*)0); + +/* for cygwin and mingw */ +#ifdef O_BINARY + m |= O_BINARY; +#endif + +#ifdef _AM29K + fd = open(name, m); +#else + fd = open(name, m, 0666); +#endif + if (fd < 0) { + TIFFErrorExt(0, module, "%s: Cannot open", name); + return ((TIFF *)0); + } + + tif = TIFFFdOpen((int)fd, name, mode); + if(!tif) + close(fd); + return tif; +} + +#ifdef __WIN32__ +#include +/* + * Open a TIFF file with a Unicode filename, for read/writing. + */ +TIFF* +TIFFOpenW(const wchar_t* name, const char* mode) +{ + static const char module[] = "TIFFOpenW"; + int m, fd; + int mbsize; + char *mbname; + TIFF* tif; + + m = _TIFFgetMode(mode, module); + if (m == -1) + return ((TIFF*)0); + +/* for cygwin and mingw */ +#ifdef O_BINARY + m |= O_BINARY; +#endif + + fd = _wopen(name, m, 0666); + if (fd < 0) { + TIFFErrorExt(0, module, "%s: Cannot open", name); + return ((TIFF *)0); + } + + mbname = NULL; + mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL); + if (mbsize > 0) { + mbname = _TIFFmalloc(mbsize); + if (!mbname) { + TIFFErrorExt(0, module, + "Can't allocate space for filename conversion buffer"); + return ((TIFF*)0); + } + + WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, + NULL, NULL); + } + + tif = TIFFFdOpen((int)fd, (mbname != NULL) ? mbname : "", + mode); + + _TIFFfree(mbname); + + if(!tif) + close(fd); + return tif; +} +#endif + +void* +_TIFFmalloc(tsize_t s) +{ + return (malloc((size_t) s)); +} + +void +_TIFFfree(tdata_t p) +{ + free(p); +} + +void* +_TIFFrealloc(tdata_t p, tsize_t s) +{ + return (realloc(p, (size_t) s)); +} + +void +_TIFFmemset(tdata_t p, int v, tsize_t c) +{ + memset(p, v, (size_t) c); +} + +void +_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) +{ + memcpy(d, s, (size_t) c); +} + +int +_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) +{ + return (memcmp(p1, p2, (size_t) c)); +} + +static void +unixWarningHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + fprintf(stderr, "%s: ", module); + fprintf(stderr, "Warning, "); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} +TIFFErrorHandler _TIFFwarningHandler = unixWarningHandler; + +static void +unixErrorHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + fprintf(stderr, "%s: ", module); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} +TIFFErrorHandler _TIFFerrorHandler = unixErrorHandler; +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF/tif_vms.c b/Source/LibTIFF/tif_vms.c index 553f507..ab99503 100644 --- a/Source/LibTIFF/tif_vms.c +++ b/Source/LibTIFF/tif_vms.c @@ -1,595 +1,595 @@ -/* $Id: tif_vms.c,v 1.21 2011/04/10 17:14:09 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library VMS-specific Routines. - */ - -#include -#include -#include "tiffiop.h" -#if !HAVE_IEEEFP -#include -#endif - -#ifdef VAXC -#define NOSHARE noshare -#else -#define NOSHARE -#endif - -#ifdef __alpha -/* Dummy entry point for backwards compatibility */ -void TIFFModeCCITTFax3(void){} -#endif - -static tsize_t -_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - return (read((int) fd, buf, size)); -} - -static tsize_t -_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - return (write((int) fd, buf, size)); -} - -static toff_t -_tiffSeekProc(thandle_t fd, toff_t off, int whence) -{ - return ((toff_t) lseek((int) fd, (off_t) off, whence)); -} - -static int -_tiffCloseProc(thandle_t fd) -{ - return (close((int) fd)); -} - -#include - -static toff_t -_tiffSizeProc(thandle_t fd) -{ - struct stat sb; - return (toff_t) (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size); -} - -#ifdef HAVE_MMAP -#include -#include -#include - -/* - * Table for storing information on current open sections. - * (Should really be a linked list) - */ -#define MAX_MAPPED 100 -static int no_mapped = 0; -static struct { - char *base; - char *top; - unsigned short channel; -} map_table[MAX_MAPPED]; - -/* - * This routine maps a file into a private section. Note that this - * method of accessing a file is by far the fastest under VMS. - * The routine may fail (i.e. return 0) for several reasons, for - * example: - * - There is no more room for storing the info on sections. - * - The process is out of open file quota, channels, ... - * - fd does not describe an opened file. - * - The file is already opened for write access by this process - * or another process - * - There is no free "hole" in virtual memory that fits the - * size of the file - */ -static int -_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) -{ - char name[256]; - struct FAB fab; - unsigned short channel; - char *inadr[2], *retadr[2]; - unsigned long status; - long size; - - if (no_mapped >= MAX_MAPPED) - return(0); - /* - * We cannot use a file descriptor, we - * must open the file once more. - */ - if (getname((int)fd, name, 1) == NULL) - return(0); - /* prepare the FAB for a user file open */ - fab = cc$rms_fab; - fab.fab$l_fop |= FAB$V_UFO; - fab.fab$b_fac = FAB$M_GET; - fab.fab$b_shr = FAB$M_SHRGET; - fab.fab$l_fna = name; - fab.fab$b_fns = strlen(name); - status = sys$open(&fab); /* open file & get channel number */ - if ((status&1) == 0) - return(0); - channel = (unsigned short)fab.fab$l_stv; - inadr[0] = inadr[1] = (char *)0; /* just an address in P0 space */ - /* - * Map the blocks of the file up to - * the EOF block into virtual memory. - */ - size = _tiffSizeProc(fd); - status = sys$crmpsc(inadr, retadr, 0, SEC$M_EXPREG, 0,0,0, channel, - TIFFhowmany(size,512), 0,0,0); - if ((status&1) == 0){ - sys$dassgn(channel); - return(0); - } - *pbase = (tdata_t) retadr[0]; /* starting virtual address */ - /* - * Use the size of the file up to the - * EOF mark for UNIX compatibility. - */ - *psize = (toff_t) size; - /* Record the section in the table */ - map_table[no_mapped].base = retadr[0]; - map_table[no_mapped].top = retadr[1]; - map_table[no_mapped].channel = channel; - no_mapped++; - - return(1); -} - -/* - * This routine unmaps a section from the virtual address space of - * the process, but only if the base was the one returned from a - * call to TIFFMapFileContents. - */ -static void -_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) -{ - char *inadr[2]; - int i, j; - - /* Find the section in the table */ - for (i = 0;i < no_mapped; i++) { - if (map_table[i].base == (char *) base) { - /* Unmap the section */ - inadr[0] = (char *) base; - inadr[1] = map_table[i].top; - sys$deltva(inadr, 0, 0); - sys$dassgn(map_table[i].channel); - /* Remove this section from the list */ - for (j = i+1; j < no_mapped; j++) - map_table[j-1] = map_table[j]; - no_mapped--; - return; - } - } -} -#else /* !HAVE_MMAP */ -static int -_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) -{ - return (0); -} - -static void -_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) -{ -} -#endif /* !HAVE_MMAP */ - -/* - * Open a TIFF file descriptor for read/writing. - */ -TIFF* -TIFFFdOpen(int fd, const char* name, const char* mode) -{ - TIFF* tif; - - tif = TIFFClientOpen(name, mode, - (thandle_t) fd, - _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, - _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); - if (tif) - tif->tif_fd = fd; - return (tif); -} - -/* - * Open a TIFF file for read/writing. - */ -TIFF* -TIFFOpen(const char* name, const char* mode) -{ - static const char module[] = "TIFFOpen"; - int m, fd; - - m = _TIFFgetMode(mode, module); - if (m == -1) - return ((TIFF*)0); - if (m&O_TRUNC){ - /* - * There is a bug in open in VAXC. If you use - * open w/ m=O_RDWR|O_CREAT|O_TRUNC the - * wrong thing happens. On the other hand - * creat does the right thing. - */ - fd = creat((char *) /* bug in stdio.h */ name, 0666, - "alq = 128", "deq = 64", "mbc = 32", - "fop = tef"); - } else if (m&O_RDWR) { - fd = open(name, m, 0666, - "deq = 64", "mbc = 32", "fop = tef", "ctx = stm"); - } else - fd = open(name, m, 0666, "mbc = 32", "ctx = stm"); - if (fd < 0) { - TIFFErrorExt(0, module, "%s: Cannot open", name); - return ((TIFF*)0); - } - return (TIFFFdOpen(fd, name, mode)); -} - -tdata_t -_TIFFmalloc(tsize_t s) -{ - return (malloc((size_t) s)); -} - -void -_TIFFfree(tdata_t p) -{ - free(p); -} - -tdata_t -_TIFFrealloc(tdata_t p, tsize_t s) -{ - return (realloc(p, (size_t) s)); -} - -void -_TIFFmemset(tdata_t p, int v, tsize_t c) -{ - memset(p, v, (size_t) c); -} - -void -_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) -{ - memcpy(d, s, (size_t) c); -} - -int -_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) -{ - return (memcmp(p1, p2, (size_t) c)); -} - -/* - * On the VAX, we need to make those global, writable pointers - * non-shareable, otherwise they would be made shareable by default. - * On the AXP, this brain damage has been corrected. - * - * I (Karsten Spang, krs@kampsax.dk) have dug around in the GCC - * manual and the GAS code and have come up with the following - * construct, but I don't have GCC on my VAX, so it is untested. - * Please tell me if it does not work. - */ - -static void -vmsWarningHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - fprintf(stderr, "%s: ", module); - fprintf(stderr, "Warning, "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} - -NOSHARE TIFFErrorHandler _TIFFwarningHandler = vmsWarningHandler -#if defined(VAX) && defined(__GNUC__) -asm("_$$PsectAttributes_NOSHR$$_TIFFwarningHandler") -#endif -; - -static void -vmsErrorHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - fprintf(stderr, "%s: ", module); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} - -NOSHARE TIFFErrorHandler _TIFFerrorHandler = vmsErrorHandler -#if defined(VAX) && defined(__GNUC__) -asm("_$$PsectAttributes_NOSHR$$_TIFFerrorHandler") -#endif -; - - -#if !HAVE_IEEEFP -/* IEEE floting point handling */ - -typedef struct ieeedouble { - unsigned long mant2; /* fix NDR: full 8-byte swap */ - unsigned long mant : 20, - exp : 11, - sign : 1; -} ieeedouble; -typedef struct ieeefloat { - unsigned long mant : 23, - exp : 8, - sign : 1; -} ieeefloat; - -/* - * NB: These are D_FLOAT's, not G_FLOAT's. A G_FLOAT is - * simply a reverse-IEEE float/double. - */ - -typedef struct { - unsigned long mant1 : 7, - exp : 8, - sign : 1, - mant2 : 16, - mant3 : 16, - mant4 : 16; -} nativedouble; -typedef struct { - unsigned long mant1 : 7, - exp : 8, - sign : 1, - mant2 : 16; -} nativefloat; - -typedef union { - ieeedouble ieee; - nativedouble native; - char b[8]; - uint32 l[2]; - double d; -} double_t; - -typedef union { - ieeefloat ieee; - nativefloat native; - char b[4]; - uint32 l; - float f; -} float_t; - -#if defined(VAXC) || defined(DECC) -#pragma inline(ieeetod,dtoieee) -#endif - -/* - * Convert an IEEE double precision number to native double precision. - * The source is contained in two longwords, the second holding the sign, - * exponent and the higher order bits of the mantissa, and the first - * holding the rest of the mantissa as follows: - * (Note: It is assumed that the number has been eight-byte swapped to - * LSB first.) - * - * First longword: - * 32 least significant bits of mantissa - * Second longword: - * 0-19: 20 most significant bits of mantissa - * 20-30: exponent - * 31: sign - * The exponent is stored as excess 1023. - * The most significant bit of the mantissa is implied 1, and not stored. - * If the exponent and mantissa are zero, the number is zero. - * If the exponent is 0 (i.e. -1023) and the mantissa is non-zero, it is an - * unnormalized number with the most significant bit NOT implied. - * If the exponent is 2047, the number is invalid, in case the mantissa is zero, - * this means overflow (+/- depending of the sign bit), otherwise - * it simply means invalid number. - * - * If the number is too large for the machine or was specified as overflow, - * +/-HUGE_VAL is returned. - */ -INLINE static void -ieeetod(double *dp) -{ - double_t source; - long sign,exp,mant; - double dmant; - - source.ieee = ((double_t*)dp)->ieee; - sign = source.ieee.sign; - exp = source.ieee.exp; - mant = source.ieee.mant; - - if (exp == 2047) { - if (mant) /* Not a Number (NAN) */ - *dp = HUGE_VAL; - else /* +/- infinity */ - *dp = (sign ? -HUGE_VAL : HUGE_VAL); - return; - } - if (!exp) { - if (!(mant || source.ieee.mant2)) { /* zero */ - *dp=0; - return; - } else { /* Unnormalized number */ - /* NB: not -1023, the 1 bit is not implied */ - exp= -1022; - } - } else { - mant |= 1<<20; - exp -= 1023; - } - dmant = (((double) mant) + - ((double) source.ieee.mant2) / (((double) (1<<16)) * - ((double) (1<<16)))) / (double) (1<<20); - dmant = ldexp(dmant, exp); - if (sign) - dmant= -dmant; - *dp = dmant; -} - -INLINE static void -dtoieee(double *dp) -{ - double_t num; - double x; - int exp; - - num.d = *dp; - if (!num.d) { /* Zero is just binary all zeros */ - num.l[0] = num.l[1] = 0; - return; - } - - if (num.d < 0) { /* Sign is encoded separately */ - num.d = -num.d; - num.ieee.sign = 1; - } else { - num.ieee.sign = 0; - } - - /* Now separate the absolute value into mantissa and exponent */ - x = frexp(num.d, &exp); - - /* - * Handle cases where the value is outside the - * range for IEEE floating point numbers. - * (Overflow cannot happen on a VAX, but underflow - * can happen for G float.) - */ - if (exp < -1022) { /* Unnormalized number */ - x = ldexp(x, -1023-exp); - exp = 0; - } else if (exp > 1023) { /* +/- infinity */ - x = 0; - exp = 2047; - } else { /* Get rid of most significant bit */ - x *= 2; - x -= 1; - exp += 1022; /* fix NDR: 1.0 -> x=0.5, exp=1 -> ieee.exp = 1023 */ - } - num.ieee.exp = exp; - - x *= (double) (1<<20); - num.ieee.mant = (long) x; - x -= (double) num.ieee.mant; - num.ieee.mant2 = (long) (x*((double) (1<<16)*(double) (1<<16))); - - if (!(num.ieee.mant || num.ieee.exp || num.ieee.mant2)) { - /* Avoid negative zero */ - num.ieee.sign = 0; - } - ((double_t*)dp)->ieee = num.ieee; -} - -/* - * Beware, these do not handle over/under-flow - * during conversion from ieee to native format. - */ -#define NATIVE2IEEEFLOAT(fp) { \ - float_t t; \ - if (t.ieee.exp = (fp)->native.exp) \ - t.ieee.exp += -129 + 127; \ - t.ieee.sign = (fp)->native.sign; \ - t.ieee.mant = ((fp)->native.mant1<<16)|(fp)->native.mant2; \ - *(fp) = t; \ -} -#define IEEEFLOAT2NATIVE(fp) { \ - float_t t; int v = (fp)->ieee.exp; \ - if (v) v += -127 + 129; /* alter bias of exponent */\ - t.native.exp = v; /* implicit truncation of exponent */\ - t.native.sign = (fp)->ieee.sign; \ - v = (fp)->ieee.mant; \ - t.native.mant1 = v >> 16; \ - t.native.mant2 = v;\ - *(fp) = t; \ -} - -#define IEEEDOUBLE2NATIVE(dp) ieeetod(dp) - -#define NATIVE2IEEEDOUBLE(dp) dtoieee(dp) - - -/* - * These unions are used during floating point - * conversions. The above macros define the - * conversion operations. - */ -void -TIFFCvtIEEEFloatToNative(TIFF* tif, u_int n, float* f) -{ - float_t* fp = (float_t*) f; - - while (n-- > 0) { - IEEEFLOAT2NATIVE(fp); - fp++; - } -} - -void -TIFFCvtNativeToIEEEFloat(TIFF* tif, u_int n, float* f) -{ - float_t* fp = (float_t*) f; - - while (n-- > 0) { - NATIVE2IEEEFLOAT(fp); - fp++; - } -} -void -TIFFCvtIEEEDoubleToNative(TIFF* tif, u_int n, double* f) -{ - double_t* fp = (double_t*) f; - - while (n-- > 0) { - IEEEDOUBLE2NATIVE(fp); - fp++; - } -} - -void -TIFFCvtNativeToIEEEDouble(TIFF* tif, u_int n, double* f) -{ - double_t* fp = (double_t*) f; - - while (n-- > 0) { - NATIVE2IEEEDOUBLE(fp); - fp++; - } -} -#endif -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_vms.c,v 1.21 2011/04/10 17:14:09 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library VMS-specific Routines. + */ + +#include +#include +#include "tiffiop.h" +#if !HAVE_IEEEFP +#include +#endif + +#ifdef VAXC +#define NOSHARE noshare +#else +#define NOSHARE +#endif + +#ifdef __alpha +/* Dummy entry point for backwards compatibility */ +void TIFFModeCCITTFax3(void){} +#endif + +static tsize_t +_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + return (read((int) fd, buf, size)); +} + +static tsize_t +_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + return (write((int) fd, buf, size)); +} + +static toff_t +_tiffSeekProc(thandle_t fd, toff_t off, int whence) +{ + return ((toff_t) lseek((int) fd, (off_t) off, whence)); +} + +static int +_tiffCloseProc(thandle_t fd) +{ + return (close((int) fd)); +} + +#include + +static toff_t +_tiffSizeProc(thandle_t fd) +{ + struct stat sb; + return (toff_t) (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size); +} + +#ifdef HAVE_MMAP +#include +#include +#include + +/* + * Table for storing information on current open sections. + * (Should really be a linked list) + */ +#define MAX_MAPPED 100 +static int no_mapped = 0; +static struct { + char *base; + char *top; + unsigned short channel; +} map_table[MAX_MAPPED]; + +/* + * This routine maps a file into a private section. Note that this + * method of accessing a file is by far the fastest under VMS. + * The routine may fail (i.e. return 0) for several reasons, for + * example: + * - There is no more room for storing the info on sections. + * - The process is out of open file quota, channels, ... + * - fd does not describe an opened file. + * - The file is already opened for write access by this process + * or another process + * - There is no free "hole" in virtual memory that fits the + * size of the file + */ +static int +_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) +{ + char name[256]; + struct FAB fab; + unsigned short channel; + char *inadr[2], *retadr[2]; + unsigned long status; + long size; + + if (no_mapped >= MAX_MAPPED) + return(0); + /* + * We cannot use a file descriptor, we + * must open the file once more. + */ + if (getname((int)fd, name, 1) == NULL) + return(0); + /* prepare the FAB for a user file open */ + fab = cc$rms_fab; + fab.fab$l_fop |= FAB$V_UFO; + fab.fab$b_fac = FAB$M_GET; + fab.fab$b_shr = FAB$M_SHRGET; + fab.fab$l_fna = name; + fab.fab$b_fns = strlen(name); + status = sys$open(&fab); /* open file & get channel number */ + if ((status&1) == 0) + return(0); + channel = (unsigned short)fab.fab$l_stv; + inadr[0] = inadr[1] = (char *)0; /* just an address in P0 space */ + /* + * Map the blocks of the file up to + * the EOF block into virtual memory. + */ + size = _tiffSizeProc(fd); + status = sys$crmpsc(inadr, retadr, 0, SEC$M_EXPREG, 0,0,0, channel, + TIFFhowmany(size,512), 0,0,0); + if ((status&1) == 0){ + sys$dassgn(channel); + return(0); + } + *pbase = (tdata_t) retadr[0]; /* starting virtual address */ + /* + * Use the size of the file up to the + * EOF mark for UNIX compatibility. + */ + *psize = (toff_t) size; + /* Record the section in the table */ + map_table[no_mapped].base = retadr[0]; + map_table[no_mapped].top = retadr[1]; + map_table[no_mapped].channel = channel; + no_mapped++; + + return(1); +} + +/* + * This routine unmaps a section from the virtual address space of + * the process, but only if the base was the one returned from a + * call to TIFFMapFileContents. + */ +static void +_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) +{ + char *inadr[2]; + int i, j; + + /* Find the section in the table */ + for (i = 0;i < no_mapped; i++) { + if (map_table[i].base == (char *) base) { + /* Unmap the section */ + inadr[0] = (char *) base; + inadr[1] = map_table[i].top; + sys$deltva(inadr, 0, 0); + sys$dassgn(map_table[i].channel); + /* Remove this section from the list */ + for (j = i+1; j < no_mapped; j++) + map_table[j-1] = map_table[j]; + no_mapped--; + return; + } + } +} +#else /* !HAVE_MMAP */ +static int +_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) +{ + return (0); +} + +static void +_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) +{ +} +#endif /* !HAVE_MMAP */ + +/* + * Open a TIFF file descriptor for read/writing. + */ +TIFF* +TIFFFdOpen(int fd, const char* name, const char* mode) +{ + TIFF* tif; + + tif = TIFFClientOpen(name, mode, + (thandle_t) fd, + _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, + _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); + if (tif) + tif->tif_fd = fd; + return (tif); +} + +/* + * Open a TIFF file for read/writing. + */ +TIFF* +TIFFOpen(const char* name, const char* mode) +{ + static const char module[] = "TIFFOpen"; + int m, fd; + + m = _TIFFgetMode(mode, module); + if (m == -1) + return ((TIFF*)0); + if (m&O_TRUNC){ + /* + * There is a bug in open in VAXC. If you use + * open w/ m=O_RDWR|O_CREAT|O_TRUNC the + * wrong thing happens. On the other hand + * creat does the right thing. + */ + fd = creat((char *) /* bug in stdio.h */ name, 0666, + "alq = 128", "deq = 64", "mbc = 32", + "fop = tef"); + } else if (m&O_RDWR) { + fd = open(name, m, 0666, + "deq = 64", "mbc = 32", "fop = tef", "ctx = stm"); + } else + fd = open(name, m, 0666, "mbc = 32", "ctx = stm"); + if (fd < 0) { + TIFFErrorExt(0, module, "%s: Cannot open", name); + return ((TIFF*)0); + } + return (TIFFFdOpen(fd, name, mode)); +} + +tdata_t +_TIFFmalloc(tsize_t s) +{ + return (malloc((size_t) s)); +} + +void +_TIFFfree(tdata_t p) +{ + free(p); +} + +tdata_t +_TIFFrealloc(tdata_t p, tsize_t s) +{ + return (realloc(p, (size_t) s)); +} + +void +_TIFFmemset(tdata_t p, int v, tsize_t c) +{ + memset(p, v, (size_t) c); +} + +void +_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) +{ + memcpy(d, s, (size_t) c); +} + +int +_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) +{ + return (memcmp(p1, p2, (size_t) c)); +} + +/* + * On the VAX, we need to make those global, writable pointers + * non-shareable, otherwise they would be made shareable by default. + * On the AXP, this brain damage has been corrected. + * + * I (Karsten Spang, krs@kampsax.dk) have dug around in the GCC + * manual and the GAS code and have come up with the following + * construct, but I don't have GCC on my VAX, so it is untested. + * Please tell me if it does not work. + */ + +static void +vmsWarningHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + fprintf(stderr, "%s: ", module); + fprintf(stderr, "Warning, "); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} + +NOSHARE TIFFErrorHandler _TIFFwarningHandler = vmsWarningHandler +#if defined(VAX) && defined(__GNUC__) +asm("_$$PsectAttributes_NOSHR$$_TIFFwarningHandler") +#endif +; + +static void +vmsErrorHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + fprintf(stderr, "%s: ", module); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} + +NOSHARE TIFFErrorHandler _TIFFerrorHandler = vmsErrorHandler +#if defined(VAX) && defined(__GNUC__) +asm("_$$PsectAttributes_NOSHR$$_TIFFerrorHandler") +#endif +; + + +#if !HAVE_IEEEFP +/* IEEE floting point handling */ + +typedef struct ieeedouble { + unsigned long mant2; /* fix NDR: full 8-byte swap */ + unsigned long mant : 20, + exp : 11, + sign : 1; +} ieeedouble; +typedef struct ieeefloat { + unsigned long mant : 23, + exp : 8, + sign : 1; +} ieeefloat; + +/* + * NB: These are D_FLOAT's, not G_FLOAT's. A G_FLOAT is + * simply a reverse-IEEE float/double. + */ + +typedef struct { + unsigned long mant1 : 7, + exp : 8, + sign : 1, + mant2 : 16, + mant3 : 16, + mant4 : 16; +} nativedouble; +typedef struct { + unsigned long mant1 : 7, + exp : 8, + sign : 1, + mant2 : 16; +} nativefloat; + +typedef union { + ieeedouble ieee; + nativedouble native; + char b[8]; + uint32 l[2]; + double d; +} double_t; + +typedef union { + ieeefloat ieee; + nativefloat native; + char b[4]; + uint32 l; + float f; +} float_t; + +#if defined(VAXC) || defined(DECC) +#pragma inline(ieeetod,dtoieee) +#endif + +/* + * Convert an IEEE double precision number to native double precision. + * The source is contained in two longwords, the second holding the sign, + * exponent and the higher order bits of the mantissa, and the first + * holding the rest of the mantissa as follows: + * (Note: It is assumed that the number has been eight-byte swapped to + * LSB first.) + * + * First longword: + * 32 least significant bits of mantissa + * Second longword: + * 0-19: 20 most significant bits of mantissa + * 20-30: exponent + * 31: sign + * The exponent is stored as excess 1023. + * The most significant bit of the mantissa is implied 1, and not stored. + * If the exponent and mantissa are zero, the number is zero. + * If the exponent is 0 (i.e. -1023) and the mantissa is non-zero, it is an + * unnormalized number with the most significant bit NOT implied. + * If the exponent is 2047, the number is invalid, in case the mantissa is zero, + * this means overflow (+/- depending of the sign bit), otherwise + * it simply means invalid number. + * + * If the number is too large for the machine or was specified as overflow, + * +/-HUGE_VAL is returned. + */ +INLINE static void +ieeetod(double *dp) +{ + double_t source; + long sign,exp,mant; + double dmant; + + source.ieee = ((double_t*)dp)->ieee; + sign = source.ieee.sign; + exp = source.ieee.exp; + mant = source.ieee.mant; + + if (exp == 2047) { + if (mant) /* Not a Number (NAN) */ + *dp = HUGE_VAL; + else /* +/- infinity */ + *dp = (sign ? -HUGE_VAL : HUGE_VAL); + return; + } + if (!exp) { + if (!(mant || source.ieee.mant2)) { /* zero */ + *dp=0; + return; + } else { /* Unnormalized number */ + /* NB: not -1023, the 1 bit is not implied */ + exp= -1022; + } + } else { + mant |= 1<<20; + exp -= 1023; + } + dmant = (((double) mant) + + ((double) source.ieee.mant2) / (((double) (1<<16)) * + ((double) (1<<16)))) / (double) (1<<20); + dmant = ldexp(dmant, exp); + if (sign) + dmant= -dmant; + *dp = dmant; +} + +INLINE static void +dtoieee(double *dp) +{ + double_t num; + double x; + int exp; + + num.d = *dp; + if (!num.d) { /* Zero is just binary all zeros */ + num.l[0] = num.l[1] = 0; + return; + } + + if (num.d < 0) { /* Sign is encoded separately */ + num.d = -num.d; + num.ieee.sign = 1; + } else { + num.ieee.sign = 0; + } + + /* Now separate the absolute value into mantissa and exponent */ + x = frexp(num.d, &exp); + + /* + * Handle cases where the value is outside the + * range for IEEE floating point numbers. + * (Overflow cannot happen on a VAX, but underflow + * can happen for G float.) + */ + if (exp < -1022) { /* Unnormalized number */ + x = ldexp(x, -1023-exp); + exp = 0; + } else if (exp > 1023) { /* +/- infinity */ + x = 0; + exp = 2047; + } else { /* Get rid of most significant bit */ + x *= 2; + x -= 1; + exp += 1022; /* fix NDR: 1.0 -> x=0.5, exp=1 -> ieee.exp = 1023 */ + } + num.ieee.exp = exp; + + x *= (double) (1<<20); + num.ieee.mant = (long) x; + x -= (double) num.ieee.mant; + num.ieee.mant2 = (long) (x*((double) (1<<16)*(double) (1<<16))); + + if (!(num.ieee.mant || num.ieee.exp || num.ieee.mant2)) { + /* Avoid negative zero */ + num.ieee.sign = 0; + } + ((double_t*)dp)->ieee = num.ieee; +} + +/* + * Beware, these do not handle over/under-flow + * during conversion from ieee to native format. + */ +#define NATIVE2IEEEFLOAT(fp) { \ + float_t t; \ + if (t.ieee.exp = (fp)->native.exp) \ + t.ieee.exp += -129 + 127; \ + t.ieee.sign = (fp)->native.sign; \ + t.ieee.mant = ((fp)->native.mant1<<16)|(fp)->native.mant2; \ + *(fp) = t; \ +} +#define IEEEFLOAT2NATIVE(fp) { \ + float_t t; int v = (fp)->ieee.exp; \ + if (v) v += -127 + 129; /* alter bias of exponent */\ + t.native.exp = v; /* implicit truncation of exponent */\ + t.native.sign = (fp)->ieee.sign; \ + v = (fp)->ieee.mant; \ + t.native.mant1 = v >> 16; \ + t.native.mant2 = v;\ + *(fp) = t; \ +} + +#define IEEEDOUBLE2NATIVE(dp) ieeetod(dp) + +#define NATIVE2IEEEDOUBLE(dp) dtoieee(dp) + + +/* + * These unions are used during floating point + * conversions. The above macros define the + * conversion operations. + */ +void +TIFFCvtIEEEFloatToNative(TIFF* tif, u_int n, float* f) +{ + float_t* fp = (float_t*) f; + + while (n-- > 0) { + IEEEFLOAT2NATIVE(fp); + fp++; + } +} + +void +TIFFCvtNativeToIEEEFloat(TIFF* tif, u_int n, float* f) +{ + float_t* fp = (float_t*) f; + + while (n-- > 0) { + NATIVE2IEEEFLOAT(fp); + fp++; + } +} +void +TIFFCvtIEEEDoubleToNative(TIFF* tif, u_int n, double* f) +{ + double_t* fp = (double_t*) f; + + while (n-- > 0) { + IEEEDOUBLE2NATIVE(fp); + fp++; + } +} + +void +TIFFCvtNativeToIEEEDouble(TIFF* tif, u_int n, double* f) +{ + double_t* fp = (double_t*) f; + + while (n-- > 0) { + NATIVE2IEEEDOUBLE(fp); + fp++; + } +} +#endif +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF/tif_win3.c b/Source/LibTIFF/tif_win3.c index aa21e3a..56d7896 100644 --- a/Source/LibTIFF/tif_win3.c +++ b/Source/LibTIFF/tif_win3.c @@ -1,232 +1,232 @@ -/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF/tif_win3.c,v 1.35 2011/04/10 17:14:09 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library Windows 3.x-specific Routines. - */ -#include "tiffiop.h" -#if defined(__WATCOMC__) || defined(__BORLANDC__) || defined(_MSC_VER) -#include /* for open, close, etc. function prototypes */ -#endif - -#include -#include -#include - -static tsize_t -_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - return (_hread(fd, buf, size)); -} - -static tsize_t -_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - return (_hwrite(fd, buf, size)); -} - -static toff_t -_tiffSeekProc(thandle_t fd, toff_t off, int whence) -{ - return (_llseek(fd, (off_t) off, whence)); -} - -static int -_tiffCloseProc(thandle_t fd) -{ - return (_lclose(fd)); -} - -#include - -static toff_t -_tiffSizeProc(thandle_t fd) -{ - struct stat sb; - return (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size); -} - -static int -_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) -{ - return (0); -} - -static void -_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) -{ -} - -/* - * Open a TIFF file descriptor for read/writing. - */ -TIFF* -TIFFFdOpen(int fd, const char* name, const char* mode) -{ - TIFF* tif; - - tif = TIFFClientOpen(name, mode, - (thandle_t) fd, - _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, - _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); - if (tif) - tif->tif_fd = fd; - return (tif); -} - -/* - * Open a TIFF file for read/writing. - */ -TIFF* -TIFFOpen(const char* name, const char* mode) -{ - static const char module[] = "TIFFOpen"; - int m, fd; - OFSTRUCT of; - int mm = 0; - - m = _TIFFgetMode(mode, module); - if (m == -1) - return ((TIFF*)0); - if (m & O_CREAT) { - if ((m & O_TRUNC) || OpenFile(name, &of, OF_EXIST) != HFILE_ERROR) - mm |= OF_CREATE; - } - if (m & O_WRONLY) - mm |= OF_WRITE; - if (m & O_RDWR) - mm |= OF_READWRITE; - fd = OpenFile(name, &of, mm); - if (fd < 0) { - TIFFErrorExt(0, module, "%s: Cannot open", name); - return ((TIFF*)0); - } - return (TIFFFdOpen(fd, name, mode)); -} - -tdata_t -_TIFFmalloc(tsize_t s) -{ - return (tdata_t) GlobalAllocPtr(GHND, (DWORD) s); -} - -void -_TIFFfree(tdata_t p) -{ - GlobalFreePtr(p); -} - -tdata_t -_TIFFrealloc(tdata_t p, tsize_t s) -{ - return (tdata_t) GlobalReAllocPtr(p, (DWORD) s, GHND); -} - -void -_TIFFmemset(tdata_t p, int v, tsize_t c) -{ - char* pp = (char*) p; - - while (c > 0) { - tsize_t chunk = 0x10000 - ((uint32) pp & 0xffff);/* What's left in segment */ - if (chunk > 0xff00) /* No more than 0xff00 */ - chunk = 0xff00; - if (chunk > c) /* No more than needed */ - chunk = c; - memset(pp, v, chunk); - pp = (char*) (chunk + (char huge*) pp); - c -= chunk; - } -} - -void -_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) -{ - if (c > 0xFFFF) - hmemcpy((void _huge*) d, (void _huge*) s, c); - else - (void) memcpy(d, s, (size_t) c); -} - -int -_TIFFmemcmp(const tdata_t d, const tdata_t s, tsize_t c) -{ - char* dd = (char*) d; - char* ss = (char*) s; - tsize_t chunks, chunkd, chunk; - int result; - - while (c > 0) { - chunks = 0x10000 - ((uint32) ss & 0xffff); /* What's left in segment */ - chunkd = 0x10000 - ((uint32) dd & 0xffff); /* What's left in segment */ - chunk = c; /* Get the largest of */ - if (chunk > chunks) /* c, chunks, chunkd, */ - chunk = chunks; /* 0xff00 */ - if (chunk > chunkd) - chunk = chunkd; - if (chunk > 0xff00) - chunk = 0xff00; - result = memcmp(dd, ss, chunk); - if (result != 0) - return (result); - dd = (char*) (chunk + (char huge*) dd); - ss = (char*) (chunk + (char huge*) ss); - c -= chunk; - } - return (0); -} - -static void -win3WarningHandler(const char* module, const char* fmt, va_list ap) -{ - char e[512] = { '\0' }; - if (module != NULL) - strcat(strcpy(e, module), ":"); - vsprintf(e+strlen(e), fmt, ap); - strcat(e, "."); - MessageBox(GetActiveWindow(), e, "LibTIFF Warning", - MB_OK|MB_ICONEXCLAMATION); -} -TIFFErrorHandler _TIFFwarningHandler = win3WarningHandler; - -static void -win3ErrorHandler(const char* module, const char* fmt, va_list ap) -{ - char e[512] = { '\0' }; - if (module != NULL) - strcat(strcpy(e, module), ":"); - vsprintf(e+strlen(e), fmt, ap); - strcat(e, "."); - MessageBox(GetActiveWindow(), e, "LibTIFF Error", MB_OK|MB_ICONSTOP); -} -TIFFErrorHandler _TIFFerrorHandler = win3ErrorHandler; -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF/tif_win3.c,v 1.35 2011/04/10 17:14:09 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library Windows 3.x-specific Routines. + */ +#include "tiffiop.h" +#if defined(__WATCOMC__) || defined(__BORLANDC__) || defined(_MSC_VER) +#include /* for open, close, etc. function prototypes */ +#endif + +#include +#include +#include + +static tsize_t +_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + return (_hread(fd, buf, size)); +} + +static tsize_t +_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + return (_hwrite(fd, buf, size)); +} + +static toff_t +_tiffSeekProc(thandle_t fd, toff_t off, int whence) +{ + return (_llseek(fd, (off_t) off, whence)); +} + +static int +_tiffCloseProc(thandle_t fd) +{ + return (_lclose(fd)); +} + +#include + +static toff_t +_tiffSizeProc(thandle_t fd) +{ + struct stat sb; + return (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size); +} + +static int +_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) +{ + return (0); +} + +static void +_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) +{ +} + +/* + * Open a TIFF file descriptor for read/writing. + */ +TIFF* +TIFFFdOpen(int fd, const char* name, const char* mode) +{ + TIFF* tif; + + tif = TIFFClientOpen(name, mode, + (thandle_t) fd, + _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, + _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); + if (tif) + tif->tif_fd = fd; + return (tif); +} + +/* + * Open a TIFF file for read/writing. + */ +TIFF* +TIFFOpen(const char* name, const char* mode) +{ + static const char module[] = "TIFFOpen"; + int m, fd; + OFSTRUCT of; + int mm = 0; + + m = _TIFFgetMode(mode, module); + if (m == -1) + return ((TIFF*)0); + if (m & O_CREAT) { + if ((m & O_TRUNC) || OpenFile(name, &of, OF_EXIST) != HFILE_ERROR) + mm |= OF_CREATE; + } + if (m & O_WRONLY) + mm |= OF_WRITE; + if (m & O_RDWR) + mm |= OF_READWRITE; + fd = OpenFile(name, &of, mm); + if (fd < 0) { + TIFFErrorExt(0, module, "%s: Cannot open", name); + return ((TIFF*)0); + } + return (TIFFFdOpen(fd, name, mode)); +} + +tdata_t +_TIFFmalloc(tsize_t s) +{ + return (tdata_t) GlobalAllocPtr(GHND, (DWORD) s); +} + +void +_TIFFfree(tdata_t p) +{ + GlobalFreePtr(p); +} + +tdata_t +_TIFFrealloc(tdata_t p, tsize_t s) +{ + return (tdata_t) GlobalReAllocPtr(p, (DWORD) s, GHND); +} + +void +_TIFFmemset(tdata_t p, int v, tsize_t c) +{ + char* pp = (char*) p; + + while (c > 0) { + tsize_t chunk = 0x10000 - ((uint32) pp & 0xffff);/* What's left in segment */ + if (chunk > 0xff00) /* No more than 0xff00 */ + chunk = 0xff00; + if (chunk > c) /* No more than needed */ + chunk = c; + memset(pp, v, chunk); + pp = (char*) (chunk + (char huge*) pp); + c -= chunk; + } +} + +void +_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) +{ + if (c > 0xFFFF) + hmemcpy((void _huge*) d, (void _huge*) s, c); + else + (void) memcpy(d, s, (size_t) c); +} + +int +_TIFFmemcmp(const tdata_t d, const tdata_t s, tsize_t c) +{ + char* dd = (char*) d; + char* ss = (char*) s; + tsize_t chunks, chunkd, chunk; + int result; + + while (c > 0) { + chunks = 0x10000 - ((uint32) ss & 0xffff); /* What's left in segment */ + chunkd = 0x10000 - ((uint32) dd & 0xffff); /* What's left in segment */ + chunk = c; /* Get the largest of */ + if (chunk > chunks) /* c, chunks, chunkd, */ + chunk = chunks; /* 0xff00 */ + if (chunk > chunkd) + chunk = chunkd; + if (chunk > 0xff00) + chunk = 0xff00; + result = memcmp(dd, ss, chunk); + if (result != 0) + return (result); + dd = (char*) (chunk + (char huge*) dd); + ss = (char*) (chunk + (char huge*) ss); + c -= chunk; + } + return (0); +} + +static void +win3WarningHandler(const char* module, const char* fmt, va_list ap) +{ + char e[512] = { '\0' }; + if (module != NULL) + strcat(strcpy(e, module), ":"); + vsprintf(e+strlen(e), fmt, ap); + strcat(e, "."); + MessageBox(GetActiveWindow(), e, "LibTIFF Warning", + MB_OK|MB_ICONEXCLAMATION); +} +TIFFErrorHandler _TIFFwarningHandler = win3WarningHandler; + +static void +win3ErrorHandler(const char* module, const char* fmt, va_list ap) +{ + char e[512] = { '\0' }; + if (module != NULL) + strcat(strcpy(e, module), ":"); + vsprintf(e+strlen(e), fmt, ap); + strcat(e, "."); + MessageBox(GetActiveWindow(), e, "LibTIFF Error", MB_OK|MB_ICONSTOP); +} +TIFFErrorHandler _TIFFerrorHandler = win3ErrorHandler; +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF/tif_win32.c b/Source/LibTIFF/tif_win32.c index ddfd778..0dd564e 100644 --- a/Source/LibTIFF/tif_win32.c +++ b/Source/LibTIFF/tif_win32.c @@ -1,408 +1,408 @@ -/* $Id: tif_win32.c,v 1.35 2011/04/10 17:14:09 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library Win32-specific Routines. Adapted from tif_unix.c 4/5/95 by - * Scott Wagner (wagner@itek.com), Itek Graphix, Rochester, NY USA - */ -#include "tiffiop.h" - -#include - -static tsize_t -_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - DWORD dwSizeRead; - if (!ReadFile(fd, buf, size, &dwSizeRead, NULL)) - return(0); - return ((tsize_t) dwSizeRead); -} - -static tsize_t -_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - DWORD dwSizeWritten; - if (!WriteFile(fd, buf, size, &dwSizeWritten, NULL)) - return(0); - return ((tsize_t) dwSizeWritten); -} - -static toff_t -_tiffSeekProc(thandle_t fd, toff_t off, int whence) -{ - ULARGE_INTEGER li; - DWORD dwMoveMethod; - - li.QuadPart = off; - - switch(whence) - { - case SEEK_SET: - dwMoveMethod = FILE_BEGIN; - break; - case SEEK_CUR: - dwMoveMethod = FILE_CURRENT; - break; - case SEEK_END: - dwMoveMethod = FILE_END; - break; - default: - dwMoveMethod = FILE_BEGIN; - break; - } - return ((toff_t)SetFilePointer(fd, (LONG) li.LowPart, - (PLONG)&li.HighPart, dwMoveMethod)); -} - -static int -_tiffCloseProc(thandle_t fd) -{ - return (CloseHandle(fd) ? 0 : -1); -} - -static toff_t -_tiffSizeProc(thandle_t fd) -{ - return ((toff_t)GetFileSize(fd, NULL)); -} - -static int -_tiffDummyMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) -{ - (void) fd; - (void) pbase; - (void) psize; - return (0); -} - -/* - * From "Hermann Josef Hill" : - * - * Windows uses both a handle and a pointer for file mapping, - * but according to the SDK documentation and Richter's book - * "Advanced Windows Programming" it is safe to free the handle - * after obtaining the file mapping pointer - * - * This removes a nasty OS dependency and cures a problem - * with Visual C++ 5.0 - */ -static int -_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) -{ - toff_t size; - HANDLE hMapFile; - - if ((size = _tiffSizeProc(fd)) == 0xFFFFFFFF) - return (0); - hMapFile = CreateFileMapping(fd, NULL, PAGE_READONLY, 0, size, NULL); - if (hMapFile == NULL) - return (0); - *pbase = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0); - CloseHandle(hMapFile); - if (*pbase == NULL) - return (0); - *psize = size; - return(1); -} - -static void -_tiffDummyUnmapProc(thandle_t fd, tdata_t base, toff_t size) -{ - (void) fd; - (void) base; - (void) size; -} - -static void -_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) -{ - UnmapViewOfFile(base); -} - -/* - * Open a TIFF file descriptor for read/writing. - * Note that TIFFFdOpen and TIFFOpen recognise the character 'u' in the mode - * string, which forces the file to be opened unmapped. - */ -TIFF* -TIFFFdOpen(int ifd, const char* name, const char* mode) -{ - TIFF* tif; - BOOL fSuppressMap = (mode[1] == 'u' || (mode[1]!=0 && mode[2] == 'u')); - - tif = TIFFClientOpen(name, mode, (thandle_t)ifd, - _tiffReadProc, _tiffWriteProc, - _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, - fSuppressMap ? _tiffDummyMapProc : _tiffMapProc, - fSuppressMap ? _tiffDummyUnmapProc : _tiffUnmapProc); - if (tif) - tif->tif_fd = ifd; - return (tif); -} - -#ifndef _WIN32_WCE - -/* - * Open a TIFF file for read/writing. - */ -TIFF* -TIFFOpen(const char* name, const char* mode) -{ - static const char module[] = "TIFFOpen"; - thandle_t fd; - int m; - DWORD dwMode; - TIFF* tif; - - m = _TIFFgetMode(mode, module); - - switch(m) - { - case O_RDONLY: - dwMode = OPEN_EXISTING; - break; - case O_RDWR: - dwMode = OPEN_ALWAYS; - break; - case O_RDWR|O_CREAT: - dwMode = OPEN_ALWAYS; - break; - case O_RDWR|O_TRUNC: - dwMode = CREATE_ALWAYS; - break; - case O_RDWR|O_CREAT|O_TRUNC: - dwMode = CREATE_ALWAYS; - break; - default: - return ((TIFF*)0); - } - fd = (thandle_t)CreateFileA(name, - (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ | GENERIC_WRITE), - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, - (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, - NULL); - if (fd == INVALID_HANDLE_VALUE) { - TIFFErrorExt(0, module, "%s: Cannot open", name); - return ((TIFF *)0); - } - - tif = TIFFFdOpen((int)fd, name, mode); - if(!tif) - CloseHandle(fd); - return tif; -} - -/* - * Open a TIFF file with a Unicode filename, for read/writing. - */ -TIFF* -TIFFOpenW(const wchar_t* name, const char* mode) -{ - static const char module[] = "TIFFOpenW"; - thandle_t fd; - int m; - DWORD dwMode; - int mbsize; - char *mbname; - TIFF *tif; - - m = _TIFFgetMode(mode, module); - - switch(m) { - case O_RDONLY: dwMode = OPEN_EXISTING; break; - case O_RDWR: dwMode = OPEN_ALWAYS; break; - case O_RDWR|O_CREAT: dwMode = OPEN_ALWAYS; break; - case O_RDWR|O_TRUNC: dwMode = CREATE_ALWAYS; break; - case O_RDWR|O_CREAT|O_TRUNC: dwMode = CREATE_ALWAYS; break; - default: return ((TIFF*)0); - } - - fd = (thandle_t)CreateFileW(name, - (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ|GENERIC_WRITE), - FILE_SHARE_READ, NULL, dwMode, - (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, - NULL); - if (fd == INVALID_HANDLE_VALUE) { - TIFFErrorExt(0, module, "%S: Cannot open", name); - return ((TIFF *)0); - } - - mbname = NULL; - mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL); - if (mbsize > 0) { - mbname = (char *)_TIFFmalloc(mbsize); - if (!mbname) { - TIFFErrorExt(0, module, - "Can't allocate space for filename conversion buffer"); - return ((TIFF*)0); - } - - WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, - NULL, NULL); - } - - tif = TIFFFdOpen((int)fd, - (mbname != NULL) ? mbname : "", mode); - if(!tif) - CloseHandle(fd); - - _TIFFfree(mbname); - - return tif; -} - -#endif /* ndef _WIN32_WCE */ - - -tdata_t -_TIFFmalloc(tsize_t s) -{ - return ((tdata_t)GlobalAlloc(GMEM_FIXED, s)); -} - -void -_TIFFfree(tdata_t p) -{ - GlobalFree(p); - return; -} - -tdata_t -_TIFFrealloc(tdata_t p, tsize_t s) -{ - void* pvTmp; - tsize_t old; - - if(p == NULL) - return ((tdata_t)GlobalAlloc(GMEM_FIXED, s)); - - old = GlobalSize(p); - - if (old>=s) { - if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) { - CopyMemory(pvTmp, p, s); - GlobalFree(p); - } - } else { - if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) { - CopyMemory(pvTmp, p, old); - GlobalFree(p); - } - } - return ((tdata_t)pvTmp); -} - -void -_TIFFmemset(void* p, int v, tsize_t c) -{ - FillMemory(p, c, (BYTE)v); -} - -void -_TIFFmemcpy(void* d, const tdata_t s, tsize_t c) -{ - CopyMemory(d, s, c); -} - -int -_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) -{ - register const BYTE *pb1 = (const BYTE *) p1; - register const BYTE *pb2 = (const BYTE *) p2; - register DWORD dwTmp = c; - register int iTmp; - for (iTmp = 0; dwTmp-- && !iTmp; iTmp = (int)*pb1++ - (int)*pb2++) - ; - return (iTmp); -} - -#ifndef _WIN32_WCE - -static void -Win32WarningHandler(const char* module, const char* fmt, va_list ap) -{ -#ifndef TIF_PLATFORM_CONSOLE - LPTSTR szTitle; - LPTSTR szTmp; - LPCTSTR szTitleText = "%s Warning"; - LPCTSTR szDefaultModule = "LIBTIFF"; - LPCTSTR szTmpModule = (module == NULL) ? szDefaultModule : module; - if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, (strlen(szTmpModule) + - strlen(szTitleText) + strlen(fmt) + 128)*sizeof(char))) == NULL) - return; - sprintf(szTitle, szTitleText, szTmpModule); - szTmp = szTitle + (strlen(szTitle)+2)*sizeof(char); - vsprintf(szTmp, fmt, ap); - MessageBoxA(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONINFORMATION); - LocalFree(szTitle); - return; -#else - if (module != NULL) - fprintf(stderr, "%s: ", module); - fprintf(stderr, "Warning, "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -#endif -} -TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler; - -static void -Win32ErrorHandler(const char* module, const char* fmt, va_list ap) -{ -#ifndef TIF_PLATFORM_CONSOLE - LPTSTR szTitle; - LPTSTR szTmp; - LPCTSTR szTitleText = "%s Error"; - LPCTSTR szDefaultModule = "LIBTIFF"; - LPCTSTR szTmpModule = (module == NULL) ? szDefaultModule : module; - if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, (strlen(szTmpModule) + - strlen(szTitleText) + strlen(fmt) + 128)*sizeof(char))) == NULL) - return; - sprintf(szTitle, szTitleText, szTmpModule); - szTmp = szTitle + (strlen(szTitle)+2)*sizeof(char); - vsprintf(szTmp, fmt, ap); - MessageBoxA(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONEXCLAMATION); - LocalFree(szTitle); - return; -#else - if (module != NULL) - fprintf(stderr, "%s: ", module); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -#endif -} -TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler; - -#endif /* ndef _WIN32_WCE */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_win32.c,v 1.35 2011/04/10 17:14:09 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library Win32-specific Routines. Adapted from tif_unix.c 4/5/95 by + * Scott Wagner (wagner@itek.com), Itek Graphix, Rochester, NY USA + */ +#include "tiffiop.h" + +#include + +static tsize_t +_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + DWORD dwSizeRead; + if (!ReadFile(fd, buf, size, &dwSizeRead, NULL)) + return(0); + return ((tsize_t) dwSizeRead); +} + +static tsize_t +_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + DWORD dwSizeWritten; + if (!WriteFile(fd, buf, size, &dwSizeWritten, NULL)) + return(0); + return ((tsize_t) dwSizeWritten); +} + +static toff_t +_tiffSeekProc(thandle_t fd, toff_t off, int whence) +{ + ULARGE_INTEGER li; + DWORD dwMoveMethod; + + li.QuadPart = off; + + switch(whence) + { + case SEEK_SET: + dwMoveMethod = FILE_BEGIN; + break; + case SEEK_CUR: + dwMoveMethod = FILE_CURRENT; + break; + case SEEK_END: + dwMoveMethod = FILE_END; + break; + default: + dwMoveMethod = FILE_BEGIN; + break; + } + return ((toff_t)SetFilePointer(fd, (LONG) li.LowPart, + (PLONG)&li.HighPart, dwMoveMethod)); +} + +static int +_tiffCloseProc(thandle_t fd) +{ + return (CloseHandle(fd) ? 0 : -1); +} + +static toff_t +_tiffSizeProc(thandle_t fd) +{ + return ((toff_t)GetFileSize(fd, NULL)); +} + +static int +_tiffDummyMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) +{ + (void) fd; + (void) pbase; + (void) psize; + return (0); +} + +/* + * From "Hermann Josef Hill" : + * + * Windows uses both a handle and a pointer for file mapping, + * but according to the SDK documentation and Richter's book + * "Advanced Windows Programming" it is safe to free the handle + * after obtaining the file mapping pointer + * + * This removes a nasty OS dependency and cures a problem + * with Visual C++ 5.0 + */ +static int +_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) +{ + toff_t size; + HANDLE hMapFile; + + if ((size = _tiffSizeProc(fd)) == 0xFFFFFFFF) + return (0); + hMapFile = CreateFileMapping(fd, NULL, PAGE_READONLY, 0, size, NULL); + if (hMapFile == NULL) + return (0); + *pbase = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0); + CloseHandle(hMapFile); + if (*pbase == NULL) + return (0); + *psize = size; + return(1); +} + +static void +_tiffDummyUnmapProc(thandle_t fd, tdata_t base, toff_t size) +{ + (void) fd; + (void) base; + (void) size; +} + +static void +_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) +{ + UnmapViewOfFile(base); +} + +/* + * Open a TIFF file descriptor for read/writing. + * Note that TIFFFdOpen and TIFFOpen recognise the character 'u' in the mode + * string, which forces the file to be opened unmapped. + */ +TIFF* +TIFFFdOpen(int ifd, const char* name, const char* mode) +{ + TIFF* tif; + BOOL fSuppressMap = (mode[1] == 'u' || (mode[1]!=0 && mode[2] == 'u')); + + tif = TIFFClientOpen(name, mode, (thandle_t)ifd, + _tiffReadProc, _tiffWriteProc, + _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, + fSuppressMap ? _tiffDummyMapProc : _tiffMapProc, + fSuppressMap ? _tiffDummyUnmapProc : _tiffUnmapProc); + if (tif) + tif->tif_fd = ifd; + return (tif); +} + +#ifndef _WIN32_WCE + +/* + * Open a TIFF file for read/writing. + */ +TIFF* +TIFFOpen(const char* name, const char* mode) +{ + static const char module[] = "TIFFOpen"; + thandle_t fd; + int m; + DWORD dwMode; + TIFF* tif; + + m = _TIFFgetMode(mode, module); + + switch(m) + { + case O_RDONLY: + dwMode = OPEN_EXISTING; + break; + case O_RDWR: + dwMode = OPEN_ALWAYS; + break; + case O_RDWR|O_CREAT: + dwMode = OPEN_ALWAYS; + break; + case O_RDWR|O_TRUNC: + dwMode = CREATE_ALWAYS; + break; + case O_RDWR|O_CREAT|O_TRUNC: + dwMode = CREATE_ALWAYS; + break; + default: + return ((TIFF*)0); + } + fd = (thandle_t)CreateFileA(name, + (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ | GENERIC_WRITE), + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, + (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, + NULL); + if (fd == INVALID_HANDLE_VALUE) { + TIFFErrorExt(0, module, "%s: Cannot open", name); + return ((TIFF *)0); + } + + tif = TIFFFdOpen((int)fd, name, mode); + if(!tif) + CloseHandle(fd); + return tif; +} + +/* + * Open a TIFF file with a Unicode filename, for read/writing. + */ +TIFF* +TIFFOpenW(const wchar_t* name, const char* mode) +{ + static const char module[] = "TIFFOpenW"; + thandle_t fd; + int m; + DWORD dwMode; + int mbsize; + char *mbname; + TIFF *tif; + + m = _TIFFgetMode(mode, module); + + switch(m) { + case O_RDONLY: dwMode = OPEN_EXISTING; break; + case O_RDWR: dwMode = OPEN_ALWAYS; break; + case O_RDWR|O_CREAT: dwMode = OPEN_ALWAYS; break; + case O_RDWR|O_TRUNC: dwMode = CREATE_ALWAYS; break; + case O_RDWR|O_CREAT|O_TRUNC: dwMode = CREATE_ALWAYS; break; + default: return ((TIFF*)0); + } + + fd = (thandle_t)CreateFileW(name, + (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ|GENERIC_WRITE), + FILE_SHARE_READ, NULL, dwMode, + (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, + NULL); + if (fd == INVALID_HANDLE_VALUE) { + TIFFErrorExt(0, module, "%S: Cannot open", name); + return ((TIFF *)0); + } + + mbname = NULL; + mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL); + if (mbsize > 0) { + mbname = (char *)_TIFFmalloc(mbsize); + if (!mbname) { + TIFFErrorExt(0, module, + "Can't allocate space for filename conversion buffer"); + return ((TIFF*)0); + } + + WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, + NULL, NULL); + } + + tif = TIFFFdOpen((int)fd, + (mbname != NULL) ? mbname : "", mode); + if(!tif) + CloseHandle(fd); + + _TIFFfree(mbname); + + return tif; +} + +#endif /* ndef _WIN32_WCE */ + + +tdata_t +_TIFFmalloc(tsize_t s) +{ + return ((tdata_t)GlobalAlloc(GMEM_FIXED, s)); +} + +void +_TIFFfree(tdata_t p) +{ + GlobalFree(p); + return; +} + +tdata_t +_TIFFrealloc(tdata_t p, tsize_t s) +{ + void* pvTmp; + tsize_t old; + + if(p == NULL) + return ((tdata_t)GlobalAlloc(GMEM_FIXED, s)); + + old = GlobalSize(p); + + if (old>=s) { + if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) { + CopyMemory(pvTmp, p, s); + GlobalFree(p); + } + } else { + if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) { + CopyMemory(pvTmp, p, old); + GlobalFree(p); + } + } + return ((tdata_t)pvTmp); +} + +void +_TIFFmemset(void* p, int v, tsize_t c) +{ + FillMemory(p, c, (BYTE)v); +} + +void +_TIFFmemcpy(void* d, const tdata_t s, tsize_t c) +{ + CopyMemory(d, s, c); +} + +int +_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) +{ + register const BYTE *pb1 = (const BYTE *) p1; + register const BYTE *pb2 = (const BYTE *) p2; + register DWORD dwTmp = c; + register int iTmp; + for (iTmp = 0; dwTmp-- && !iTmp; iTmp = (int)*pb1++ - (int)*pb2++) + ; + return (iTmp); +} + +#ifndef _WIN32_WCE + +static void +Win32WarningHandler(const char* module, const char* fmt, va_list ap) +{ +#ifndef TIF_PLATFORM_CONSOLE + LPTSTR szTitle; + LPTSTR szTmp; + LPCTSTR szTitleText = "%s Warning"; + LPCTSTR szDefaultModule = "LIBTIFF"; + LPCTSTR szTmpModule = (module == NULL) ? szDefaultModule : module; + if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, (strlen(szTmpModule) + + strlen(szTitleText) + strlen(fmt) + 128)*sizeof(char))) == NULL) + return; + sprintf(szTitle, szTitleText, szTmpModule); + szTmp = szTitle + (strlen(szTitle)+2)*sizeof(char); + vsprintf(szTmp, fmt, ap); + MessageBoxA(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONINFORMATION); + LocalFree(szTitle); + return; +#else + if (module != NULL) + fprintf(stderr, "%s: ", module); + fprintf(stderr, "Warning, "); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +#endif +} +TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler; + +static void +Win32ErrorHandler(const char* module, const char* fmt, va_list ap) +{ +#ifndef TIF_PLATFORM_CONSOLE + LPTSTR szTitle; + LPTSTR szTmp; + LPCTSTR szTitleText = "%s Error"; + LPCTSTR szDefaultModule = "LIBTIFF"; + LPCTSTR szTmpModule = (module == NULL) ? szDefaultModule : module; + if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, (strlen(szTmpModule) + + strlen(szTitleText) + strlen(fmt) + 128)*sizeof(char))) == NULL) + return; + sprintf(szTitle, szTitleText, szTmpModule); + szTmp = szTitle + (strlen(szTitle)+2)*sizeof(char); + vsprintf(szTmp, fmt, ap); + MessageBoxA(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONEXCLAMATION); + LocalFree(szTitle); + return; +#else + if (module != NULL) + fprintf(stderr, "%s: ", module); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +#endif +} +TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler; + +#endif /* ndef _WIN32_WCE */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF/tif_wince.c b/Source/LibTIFF/tif_wince.c index ecd362a..c5025b3 100644 --- a/Source/LibTIFF/tif_wince.c +++ b/Source/LibTIFF/tif_wince.c @@ -1,288 +1,288 @@ -/* $Id: tif_wince.c,v 1.18 2011/04/10 17:14:09 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * Windows CE-specific routines for TIFF Library. - * Adapted from tif_win32.c 01/10/2006 by Mateusz Loskot (mateusz@loskot.net) - */ - -#ifndef _WIN32_WCE -# error "Only Windows CE target is supported!" -#endif - -#include "tiffiop.h" -#include - -/* Turn off console support on Windows CE. */ -#undef TIF_PLATFORM_CONSOLE - - -/* - * Open a TIFF file for read/writing. - */ -TIFF* -TIFFOpen(const char* name, const char* mode) -{ - static const char module[] = "TIFFOpen"; - thandle_t fd; - int m; - DWORD dwMode; - TIFF* tif; - size_t nLen; - size_t nWideLen; - wchar_t* wchName; - - m = _TIFFgetMode(mode, module); - - switch(m) - { - case O_RDONLY: - dwMode = OPEN_EXISTING; - break; - case O_RDWR: - dwMode = OPEN_ALWAYS; - break; - case O_RDWR|O_CREAT: - dwMode = OPEN_ALWAYS; - break; - case O_RDWR|O_TRUNC: - dwMode = CREATE_ALWAYS; - break; - case O_RDWR|O_CREAT|O_TRUNC: - dwMode = CREATE_ALWAYS; - break; - default: - return ((TIFF*)0); - } - - /* On Windows CE, CreateFile is mapped to CreateFileW, - * but file path is passed as char-based string, - * so the path has to be converted to wchar_t. - */ - - nWideLen = 0; - wchName = NULL; - nLen = strlen(name) + 1; - - nWideLen = MultiByteToWideChar(CP_ACP, 0, name, nLen, NULL, 0); - wchName = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); - if (NULL == wchName) - { - TIFFErrorExt(0, module, "Memory allocation error!"); - return ((TIFF *)0); - } - memset(wchName, 0, sizeof(wchar_t) * nWideLen); - MultiByteToWideChar(CP_ACP, 0, name, nLen, wchName, nWideLen); - - fd = (thandle_t)CreateFile(wchName, - (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ | GENERIC_WRITE), - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, - (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, - NULL); - - free(wchName); - - if (fd == INVALID_HANDLE_VALUE) { - TIFFErrorExt(0, module, "%s: Cannot open", name); - return ((TIFF *)0); - } - - /* TODO - mloskot: change to TIFFdOpenW and pass wchar path */ - - tif = TIFFFdOpen((int)fd, name, mode); - if(!tif) - CloseHandle(fd); - return tif; -} - -/* - * Open a TIFF file with a Unicode filename, for read/writing. - */ -TIFF* -TIFFOpenW(const wchar_t* name, const char* mode) -{ - static const char module[] = "TIFFOpenW"; - thandle_t fd; - int m; - DWORD dwMode; - int mbsize; - char *mbname; - TIFF *tif; - - m = _TIFFgetMode(mode, module); - - switch(m) { - case O_RDONLY: dwMode = OPEN_EXISTING; break; - case O_RDWR: dwMode = OPEN_ALWAYS; break; - case O_RDWR|O_CREAT: dwMode = OPEN_ALWAYS; break; - case O_RDWR|O_TRUNC: dwMode = CREATE_ALWAYS; break; - case O_RDWR|O_CREAT|O_TRUNC: dwMode = CREATE_ALWAYS; break; - default: return ((TIFF*)0); - } - - /* On Windows CE, CreateFile is mapped to CreateFileW, - * so no conversion of wchar_t to char is required. - */ - - fd = (thandle_t)CreateFile(name, - (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ|GENERIC_WRITE), - FILE_SHARE_READ, NULL, dwMode, - (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, - NULL); - if (fd == INVALID_HANDLE_VALUE) { - TIFFErrorExt(0, module, "%S: Cannot open", name); - return ((TIFF *)0); - } - - mbname = NULL; - mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL); - if (mbsize > 0) { - mbname = (char *)_TIFFmalloc(mbsize); - if (!mbname) { - TIFFErrorExt(0, module, - "Can't allocate space for filename conversion buffer"); - return ((TIFF*)0); - } - - WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, - NULL, NULL); - } - - tif = TIFFFdOpen((int)fd, - (mbname != NULL) ? mbname : "", mode); - if(!tif) - CloseHandle(fd); - - _TIFFfree(mbname); - - return tif; -} - -static void -Win32WarningHandler(const char* module, const char* fmt, va_list ap) -{ - /* On Windows CE, MessageBox is mapped to wide-char based MessageBoxW. */ - - size_t nWideLen = 0; - LPTSTR szWideTitle = NULL; - LPTSTR szWideMsg = NULL; - - LPSTR szTitle; - LPSTR szTmp; - LPCSTR szTitleText = "%s Warning"; - LPCSTR szDefaultModule = "LIBTIFF"; - LPCSTR szTmpModule; - - szTmpModule = (module == NULL) ? szDefaultModule : module; - if ((szTitle = (LPSTR)LocalAlloc(LMEM_FIXED, - (strlen(szTmpModule) + strlen(szTitleText) - + strlen(fmt) + 128) * sizeof(char))) == NULL) - return; - - sprintf(szTitle, szTitleText, szTmpModule); - szTmp = szTitle + (strlen(szTitle) + 2) * sizeof(char); - vsprintf(szTmp, fmt, ap); - - /* Convert error message to Unicode. */ - - nWideLen = MultiByteToWideChar(CP_ACP, 0, szTitle, -1, NULL, 0); - szWideTitle = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); - MultiByteToWideChar(CP_ACP, 0, szTitle, -1, szWideTitle, nWideLen); - - nWideLen = MultiByteToWideChar(CP_ACP, 0, szTmp, -1, NULL, 0); - szWideMsg = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); - MultiByteToWideChar(CP_ACP, 0, szTmp, -1, szWideMsg, nWideLen); - - /* Display message */ - - MessageBox(GetFocus(), szWideMsg, szWideTitle, MB_OK | MB_ICONEXCLAMATION); - - /* Free resources */ - - LocalFree(szTitle); - free(szWideMsg); - free(szWideTitle); -} - -TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler; - -static void -Win32ErrorHandler(const char* module, const char* fmt, va_list ap) -{ - /* On Windows CE, MessageBox is mapped to wide-char based MessageBoxW. */ - - size_t nWideLen = 0; - LPTSTR szWideTitle = NULL; - LPTSTR szWideMsg = NULL; - - LPSTR szTitle; - LPSTR szTmp; - LPCSTR szTitleText = "%s Error"; - LPCSTR szDefaultModule = "LIBTIFF"; - LPCSTR szTmpModule; - - szTmpModule = (module == NULL) ? szDefaultModule : module; - if ((szTitle = (LPSTR)LocalAlloc(LMEM_FIXED, - (strlen(szTmpModule) + strlen(szTitleText) - + strlen(fmt) + 128) * sizeof(char))) == NULL) - return; - - sprintf(szTitle, szTitleText, szTmpModule); - szTmp = szTitle + (strlen(szTitle) + 2) * sizeof(char); - vsprintf(szTmp, fmt, ap); - - /* Convert error message to Unicode. */ - - nWideLen = MultiByteToWideChar(CP_ACP, 0, szTitle, -1, NULL, 0); - szWideTitle = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); - MultiByteToWideChar(CP_ACP, 0, szTitle, -1, szWideTitle, nWideLen); - - nWideLen = MultiByteToWideChar(CP_ACP, 0, szTmp, -1, NULL, 0); - szWideMsg = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); - MultiByteToWideChar(CP_ACP, 0, szTmp, -1, szWideMsg, nWideLen); - - /* Display message */ - - MessageBox(GetFocus(), szWideMsg, szWideTitle, MB_OK | MB_ICONEXCLAMATION); - - /* Free resources */ - - LocalFree(szTitle); - free(szWideMsg); - free(szWideTitle); -} - -TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler; - - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_wince.c,v 1.18 2011/04/10 17:14:09 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * Windows CE-specific routines for TIFF Library. + * Adapted from tif_win32.c 01/10/2006 by Mateusz Loskot (mateusz@loskot.net) + */ + +#ifndef _WIN32_WCE +# error "Only Windows CE target is supported!" +#endif + +#include "tiffiop.h" +#include + +/* Turn off console support on Windows CE. */ +#undef TIF_PLATFORM_CONSOLE + + +/* + * Open a TIFF file for read/writing. + */ +TIFF* +TIFFOpen(const char* name, const char* mode) +{ + static const char module[] = "TIFFOpen"; + thandle_t fd; + int m; + DWORD dwMode; + TIFF* tif; + size_t nLen; + size_t nWideLen; + wchar_t* wchName; + + m = _TIFFgetMode(mode, module); + + switch(m) + { + case O_RDONLY: + dwMode = OPEN_EXISTING; + break; + case O_RDWR: + dwMode = OPEN_ALWAYS; + break; + case O_RDWR|O_CREAT: + dwMode = OPEN_ALWAYS; + break; + case O_RDWR|O_TRUNC: + dwMode = CREATE_ALWAYS; + break; + case O_RDWR|O_CREAT|O_TRUNC: + dwMode = CREATE_ALWAYS; + break; + default: + return ((TIFF*)0); + } + + /* On Windows CE, CreateFile is mapped to CreateFileW, + * but file path is passed as char-based string, + * so the path has to be converted to wchar_t. + */ + + nWideLen = 0; + wchName = NULL; + nLen = strlen(name) + 1; + + nWideLen = MultiByteToWideChar(CP_ACP, 0, name, nLen, NULL, 0); + wchName = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); + if (NULL == wchName) + { + TIFFErrorExt(0, module, "Memory allocation error!"); + return ((TIFF *)0); + } + memset(wchName, 0, sizeof(wchar_t) * nWideLen); + MultiByteToWideChar(CP_ACP, 0, name, nLen, wchName, nWideLen); + + fd = (thandle_t)CreateFile(wchName, + (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ | GENERIC_WRITE), + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, + (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, + NULL); + + free(wchName); + + if (fd == INVALID_HANDLE_VALUE) { + TIFFErrorExt(0, module, "%s: Cannot open", name); + return ((TIFF *)0); + } + + /* TODO - mloskot: change to TIFFdOpenW and pass wchar path */ + + tif = TIFFFdOpen((int)fd, name, mode); + if(!tif) + CloseHandle(fd); + return tif; +} + +/* + * Open a TIFF file with a Unicode filename, for read/writing. + */ +TIFF* +TIFFOpenW(const wchar_t* name, const char* mode) +{ + static const char module[] = "TIFFOpenW"; + thandle_t fd; + int m; + DWORD dwMode; + int mbsize; + char *mbname; + TIFF *tif; + + m = _TIFFgetMode(mode, module); + + switch(m) { + case O_RDONLY: dwMode = OPEN_EXISTING; break; + case O_RDWR: dwMode = OPEN_ALWAYS; break; + case O_RDWR|O_CREAT: dwMode = OPEN_ALWAYS; break; + case O_RDWR|O_TRUNC: dwMode = CREATE_ALWAYS; break; + case O_RDWR|O_CREAT|O_TRUNC: dwMode = CREATE_ALWAYS; break; + default: return ((TIFF*)0); + } + + /* On Windows CE, CreateFile is mapped to CreateFileW, + * so no conversion of wchar_t to char is required. + */ + + fd = (thandle_t)CreateFile(name, + (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ|GENERIC_WRITE), + FILE_SHARE_READ, NULL, dwMode, + (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, + NULL); + if (fd == INVALID_HANDLE_VALUE) { + TIFFErrorExt(0, module, "%S: Cannot open", name); + return ((TIFF *)0); + } + + mbname = NULL; + mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL); + if (mbsize > 0) { + mbname = (char *)_TIFFmalloc(mbsize); + if (!mbname) { + TIFFErrorExt(0, module, + "Can't allocate space for filename conversion buffer"); + return ((TIFF*)0); + } + + WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, + NULL, NULL); + } + + tif = TIFFFdOpen((int)fd, + (mbname != NULL) ? mbname : "", mode); + if(!tif) + CloseHandle(fd); + + _TIFFfree(mbname); + + return tif; +} + +static void +Win32WarningHandler(const char* module, const char* fmt, va_list ap) +{ + /* On Windows CE, MessageBox is mapped to wide-char based MessageBoxW. */ + + size_t nWideLen = 0; + LPTSTR szWideTitle = NULL; + LPTSTR szWideMsg = NULL; + + LPSTR szTitle; + LPSTR szTmp; + LPCSTR szTitleText = "%s Warning"; + LPCSTR szDefaultModule = "LIBTIFF"; + LPCSTR szTmpModule; + + szTmpModule = (module == NULL) ? szDefaultModule : module; + if ((szTitle = (LPSTR)LocalAlloc(LMEM_FIXED, + (strlen(szTmpModule) + strlen(szTitleText) + + strlen(fmt) + 128) * sizeof(char))) == NULL) + return; + + sprintf(szTitle, szTitleText, szTmpModule); + szTmp = szTitle + (strlen(szTitle) + 2) * sizeof(char); + vsprintf(szTmp, fmt, ap); + + /* Convert error message to Unicode. */ + + nWideLen = MultiByteToWideChar(CP_ACP, 0, szTitle, -1, NULL, 0); + szWideTitle = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); + MultiByteToWideChar(CP_ACP, 0, szTitle, -1, szWideTitle, nWideLen); + + nWideLen = MultiByteToWideChar(CP_ACP, 0, szTmp, -1, NULL, 0); + szWideMsg = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); + MultiByteToWideChar(CP_ACP, 0, szTmp, -1, szWideMsg, nWideLen); + + /* Display message */ + + MessageBox(GetFocus(), szWideMsg, szWideTitle, MB_OK | MB_ICONEXCLAMATION); + + /* Free resources */ + + LocalFree(szTitle); + free(szWideMsg); + free(szWideTitle); +} + +TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler; + +static void +Win32ErrorHandler(const char* module, const char* fmt, va_list ap) +{ + /* On Windows CE, MessageBox is mapped to wide-char based MessageBoxW. */ + + size_t nWideLen = 0; + LPTSTR szWideTitle = NULL; + LPTSTR szWideMsg = NULL; + + LPSTR szTitle; + LPSTR szTmp; + LPCSTR szTitleText = "%s Error"; + LPCSTR szDefaultModule = "LIBTIFF"; + LPCSTR szTmpModule; + + szTmpModule = (module == NULL) ? szDefaultModule : module; + if ((szTitle = (LPSTR)LocalAlloc(LMEM_FIXED, + (strlen(szTmpModule) + strlen(szTitleText) + + strlen(fmt) + 128) * sizeof(char))) == NULL) + return; + + sprintf(szTitle, szTitleText, szTmpModule); + szTmp = szTitle + (strlen(szTitle) + 2) * sizeof(char); + vsprintf(szTmp, fmt, ap); + + /* Convert error message to Unicode. */ + + nWideLen = MultiByteToWideChar(CP_ACP, 0, szTitle, -1, NULL, 0); + szWideTitle = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); + MultiByteToWideChar(CP_ACP, 0, szTitle, -1, szWideTitle, nWideLen); + + nWideLen = MultiByteToWideChar(CP_ACP, 0, szTmp, -1, NULL, 0); + szWideMsg = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); + MultiByteToWideChar(CP_ACP, 0, szTmp, -1, szWideMsg, nWideLen); + + /* Display message */ + + MessageBox(GetFocus(), szWideMsg, szWideTitle, MB_OK | MB_ICONEXCLAMATION); + + /* Free resources */ + + LocalFree(szTitle); + free(szWideMsg); + free(szWideTitle); +} + +TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler; + + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF/tiffconf.h-vms b/Source/LibTIFF/tiffconf.h-vms index de717ec..8d52893 100644 --- a/Source/LibTIFF/tiffconf.h-vms +++ b/Source/LibTIFF/tiffconf.h-vms @@ -1,99 +1,99 @@ -/* - Configuration defines for installed libtiff. - This file maintained for backward compatibility. Do not use definitions - from this file in your programs. -*/ - -#ifndef _TIFFCONF_ -#define _TIFFCONF_ - -/* Define to 1 if the system has the type `int16'. */ -//#define HAVE_INT16 - -/* Define to 1 if the system has the type `int32'. */ -//#define HAVE_INT32 - -/* Define to 1 if the system has the type `int8'. */ -//#define HAVE_INT8 - -/* The size of a `int', as computed by sizeof. */ -#define SIZEOF_INT 4 - -/* The size of a `long', as computed by sizeof. */ -#define SIZEOF_LONG 4 - -/* Compatibility stuff. */ - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#define HAVE_IEEEFP 1 - -#define HAVE_GETOPT 1 - -/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ -#define HOST_FILLORDER FILLORDER_LSB2MSB - -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian - (Intel) */ -#define HOST_BIGENDIAN 0 - -/* Support CCITT Group 3 & 4 algorithms */ -#define CCITT_SUPPORT 1 - -/* Support JPEG compression (requires IJG JPEG library) */ -#define JPEG_SUPPORT - -/* Support LogLuv high dynamic range encoding */ -#define LOGLUV_SUPPORT 1 - -/* Support LZW algorithm */ -#define LZW_SUPPORT 1 - -/* Support NeXT 2-bit RLE algorithm */ -#define NEXT_SUPPORT 1 - -/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation - fails with unpatched IJG JPEG library) */ -/* #undef OJPEG_SUPPORT */ - -/* Support Macintosh PackBits algorithm */ -#define PACKBITS_SUPPORT 1 - -/* Support Pixar log-format algorithm (requires Zlib) */ -/* #undef PIXARLOG_SUPPORT */ - -/* Support ThunderScan 4-bit RLE algorithm */ -#define THUNDER_SUPPORT 1 - -/* Support Deflate compression */ -/* #undef ZIP_SUPPORT */ - -/* Support strip chopping (whether or not to convert single-strip uncompressed - images to mutiple strips of ~8Kb to reduce memory usage) */ -#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP - -/* Enable SubIFD tag (330) support */ -#define SUBIFD_SUPPORT 1 - -/* Treat extra sample as alpha (default enabled). The RGBA interface will - treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many - packages produce RGBA files but don't mark the alpha properly. */ -#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1 - -/* Pick up YCbCr subsampling info from the JPEG data stream to support files - lacking the tag (default enabled). */ -#define CHECK_JPEG_YCBCR_SUBSAMPLING 1 - -/* - * Feature support definitions. - * XXX: These macros are obsoleted. Don't use them in your apps! - * Macros stays here for backward compatibility and should be always defined. - */ -#define COLORIMETRY_SUPPORT -#define YCBCR_SUPPORT -#define CMYK_SUPPORT -#define ICC_SUPPORT -#define PHOTOSHOP_SUPPORT -#define IPTC_SUPPORT - -#endif /* _TIFFCONF_ */ +/* + Configuration defines for installed libtiff. + This file maintained for backward compatibility. Do not use definitions + from this file in your programs. +*/ + +#ifndef _TIFFCONF_ +#define _TIFFCONF_ + +/* Define to 1 if the system has the type `int16'. */ +//#define HAVE_INT16 + +/* Define to 1 if the system has the type `int32'. */ +//#define HAVE_INT32 + +/* Define to 1 if the system has the type `int8'. */ +//#define HAVE_INT8 + +/* The size of a `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of a `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* Compatibility stuff. */ + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#define HAVE_IEEEFP 1 + +#define HAVE_GETOPT 1 + +/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ +#define HOST_FILLORDER FILLORDER_LSB2MSB + +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian + (Intel) */ +#define HOST_BIGENDIAN 0 + +/* Support CCITT Group 3 & 4 algorithms */ +#define CCITT_SUPPORT 1 + +/* Support JPEG compression (requires IJG JPEG library) */ +#define JPEG_SUPPORT + +/* Support LogLuv high dynamic range encoding */ +#define LOGLUV_SUPPORT 1 + +/* Support LZW algorithm */ +#define LZW_SUPPORT 1 + +/* Support NeXT 2-bit RLE algorithm */ +#define NEXT_SUPPORT 1 + +/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation + fails with unpatched IJG JPEG library) */ +/* #undef OJPEG_SUPPORT */ + +/* Support Macintosh PackBits algorithm */ +#define PACKBITS_SUPPORT 1 + +/* Support Pixar log-format algorithm (requires Zlib) */ +/* #undef PIXARLOG_SUPPORT */ + +/* Support ThunderScan 4-bit RLE algorithm */ +#define THUNDER_SUPPORT 1 + +/* Support Deflate compression */ +/* #undef ZIP_SUPPORT */ + +/* Support strip chopping (whether or not to convert single-strip uncompressed + images to mutiple strips of ~8Kb to reduce memory usage) */ +#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP + +/* Enable SubIFD tag (330) support */ +#define SUBIFD_SUPPORT 1 + +/* Treat extra sample as alpha (default enabled). The RGBA interface will + treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many + packages produce RGBA files but don't mark the alpha properly. */ +#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1 + +/* Pick up YCbCr subsampling info from the JPEG data stream to support files + lacking the tag (default enabled). */ +#define CHECK_JPEG_YCBCR_SUBSAMPLING 1 + +/* + * Feature support definitions. + * XXX: These macros are obsoleted. Don't use them in your apps! + * Macros stays here for backward compatibility and should be always defined. + */ +#define COLORIMETRY_SUPPORT +#define YCBCR_SUPPORT +#define CMYK_SUPPORT +#define ICC_SUPPORT +#define PHOTOSHOP_SUPPORT +#define IPTC_SUPPORT + +#endif /* _TIFFCONF_ */ diff --git a/Source/LibTIFF/tiffconf.h.in b/Source/LibTIFF/tiffconf.h.in index 88544d5..1a52b37 100644 --- a/Source/LibTIFF/tiffconf.h.in +++ b/Source/LibTIFF/tiffconf.h.in @@ -1,103 +1,103 @@ -/* - Configuration defines for installed libtiff. - This file maintained for backward compatibility. Do not use definitions - from this file in your programs. -*/ - -#ifndef _TIFFCONF_ -#define _TIFFCONF_ - -/* Define to 1 if the system has the type `int16'. */ -#undef HAVE_INT16 - -/* Define to 1 if the system has the type `int32'. */ -#undef HAVE_INT32 - -/* Define to 1 if the system has the type `int8'. */ -#undef HAVE_INT8 - -/* The size of a `int', as computed by sizeof. */ -#undef SIZEOF_INT - -/* The size of a `long', as computed by sizeof. */ -#undef SIZEOF_LONG - -/* Compatibility stuff. */ - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#undef HAVE_IEEEFP - -/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ -#undef HOST_FILLORDER - -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian - (Intel) */ -#undef HOST_BIGENDIAN - -/* Support CCITT Group 3 & 4 algorithms */ -#undef CCITT_SUPPORT - -/* Support JPEG compression (requires IJG JPEG library) */ -#undef JPEG_SUPPORT - -/* Support JBIG compression (requires JBIG-KIT library) */ -#undef JBIG_SUPPORT - -/* Support LogLuv high dynamic range encoding */ -#undef LOGLUV_SUPPORT - -/* Support LZW algorithm */ -#undef LZW_SUPPORT - -/* Support NeXT 2-bit RLE algorithm */ -#undef NEXT_SUPPORT - -/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation - fails with unpatched IJG JPEG library) */ -#undef OJPEG_SUPPORT - -/* Support Macintosh PackBits algorithm */ -#undef PACKBITS_SUPPORT - -/* Support Pixar log-format algorithm (requires Zlib) */ -#undef PIXARLOG_SUPPORT - -/* Support ThunderScan 4-bit RLE algorithm */ -#undef THUNDER_SUPPORT - -/* Support Deflate compression */ -#undef ZIP_SUPPORT - -/* Support strip chopping (whether or not to convert single-strip uncompressed - images to mutiple strips of ~8Kb to reduce memory usage) */ -#undef STRIPCHOP_DEFAULT - -/* Enable SubIFD tag (330) support */ -#undef SUBIFD_SUPPORT - -/* Treat extra sample as alpha (default enabled). The RGBA interface will - treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many - packages produce RGBA files but don't mark the alpha properly. */ -#undef DEFAULT_EXTRASAMPLE_AS_ALPHA - -/* Pick up YCbCr subsampling info from the JPEG data stream to support files - lacking the tag (default enabled). */ -#undef CHECK_JPEG_YCBCR_SUBSAMPLING - -/* Support MS MDI magic number files as TIFF */ -#undef MDI_SUPPORT - -/* - * Feature support definitions. - * XXX: These macros are obsoleted. Don't use them in your apps! - * Macros stays here for backward compatibility and should be always defined. - */ -#define COLORIMETRY_SUPPORT -#define YCBCR_SUPPORT -#define CMYK_SUPPORT -#define ICC_SUPPORT -#define PHOTOSHOP_SUPPORT -#define IPTC_SUPPORT - -#endif /* _TIFFCONF_ */ +/* + Configuration defines for installed libtiff. + This file maintained for backward compatibility. Do not use definitions + from this file in your programs. +*/ + +#ifndef _TIFFCONF_ +#define _TIFFCONF_ + +/* Define to 1 if the system has the type `int16'. */ +#undef HAVE_INT16 + +/* Define to 1 if the system has the type `int32'. */ +#undef HAVE_INT32 + +/* Define to 1 if the system has the type `int8'. */ +#undef HAVE_INT8 + +/* The size of a `int', as computed by sizeof. */ +#undef SIZEOF_INT + +/* The size of a `long', as computed by sizeof. */ +#undef SIZEOF_LONG + +/* Compatibility stuff. */ + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#undef HAVE_IEEEFP + +/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ +#undef HOST_FILLORDER + +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian + (Intel) */ +#undef HOST_BIGENDIAN + +/* Support CCITT Group 3 & 4 algorithms */ +#undef CCITT_SUPPORT + +/* Support JPEG compression (requires IJG JPEG library) */ +#undef JPEG_SUPPORT + +/* Support JBIG compression (requires JBIG-KIT library) */ +#undef JBIG_SUPPORT + +/* Support LogLuv high dynamic range encoding */ +#undef LOGLUV_SUPPORT + +/* Support LZW algorithm */ +#undef LZW_SUPPORT + +/* Support NeXT 2-bit RLE algorithm */ +#undef NEXT_SUPPORT + +/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation + fails with unpatched IJG JPEG library) */ +#undef OJPEG_SUPPORT + +/* Support Macintosh PackBits algorithm */ +#undef PACKBITS_SUPPORT + +/* Support Pixar log-format algorithm (requires Zlib) */ +#undef PIXARLOG_SUPPORT + +/* Support ThunderScan 4-bit RLE algorithm */ +#undef THUNDER_SUPPORT + +/* Support Deflate compression */ +#undef ZIP_SUPPORT + +/* Support strip chopping (whether or not to convert single-strip uncompressed + images to mutiple strips of ~8Kb to reduce memory usage) */ +#undef STRIPCHOP_DEFAULT + +/* Enable SubIFD tag (330) support */ +#undef SUBIFD_SUPPORT + +/* Treat extra sample as alpha (default enabled). The RGBA interface will + treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many + packages produce RGBA files but don't mark the alpha properly. */ +#undef DEFAULT_EXTRASAMPLE_AS_ALPHA + +/* Pick up YCbCr subsampling info from the JPEG data stream to support files + lacking the tag (default enabled). */ +#undef CHECK_JPEG_YCBCR_SUBSAMPLING + +/* Support MS MDI magic number files as TIFF */ +#undef MDI_SUPPORT + +/* + * Feature support definitions. + * XXX: These macros are obsoleted. Don't use them in your apps! + * Macros stays here for backward compatibility and should be always defined. + */ +#define COLORIMETRY_SUPPORT +#define YCBCR_SUPPORT +#define CMYK_SUPPORT +#define ICC_SUPPORT +#define PHOTOSHOP_SUPPORT +#define IPTC_SUPPORT + +#endif /* _TIFFCONF_ */ diff --git a/Source/LibTIFF/tiffio.hxx b/Source/LibTIFF/tiffio.hxx index fc20d72..32f1f11 100644 --- a/Source/LibTIFF/tiffio.hxx +++ b/Source/LibTIFF/tiffio.hxx @@ -1,49 +1,49 @@ -/* $Id: tiffio.hxx,v 1.32 2011/04/10 17:14:09 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifndef _TIFFIO_HXX_ -#define _TIFFIO_HXX_ - -/* - * TIFF I/O library definitions which provide C++ streams API. - */ - -#include -#include "tiff.h" - -extern TIFF* TIFFStreamOpen(const char*, std::ostream *); -extern TIFF* TIFFStreamOpen(const char*, std::istream *); - -#endif /* _TIFFIO_HXX_ */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c++ - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tiffio.hxx,v 1.32 2011/04/10 17:14:09 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef _TIFFIO_HXX_ +#define _TIFFIO_HXX_ + +/* + * TIFF I/O library definitions which provide C++ streams API. + */ + +#include +#include "tiff.h" + +extern TIFF* TIFFStreamOpen(const char*, std::ostream *); +extern TIFF* TIFFStreamOpen(const char*, std::istream *); + +#endif /* _TIFFIO_HXX_ */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c++ + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF/tiffvers.h.in b/Source/LibTIFF/tiffvers.h.in index c855630..48ec0eb 100644 --- a/Source/LibTIFF/tiffvers.h.in +++ b/Source/LibTIFF/tiffvers.h.in @@ -1,9 +1,9 @@ -#define TIFFLIB_VERSION_STR "LIBTIFF, Version LIBTIFF_VERSION\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." -/* - * This define can be used in code that requires - * compilation-related definitions specific to a - * version or versions of the library. Runtime - * version checking should be done based on the - * string returned by TIFFGetVersion. - */ -#define TIFFLIB_VERSION LIBTIFF_RELEASE_DATE +#define TIFFLIB_VERSION_STR "LIBTIFF, Version LIBTIFF_VERSION\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." +/* + * This define can be used in code that requires + * compilation-related definitions specific to a + * version or versions of the library. Runtime + * version checking should be done based on the + * string returned by TIFFGetVersion. + */ +#define TIFFLIB_VERSION LIBTIFF_RELEASE_DATE diff --git a/Source/LibTIFF4/ChangeLog b/Source/LibTIFF4/ChangeLog index aa4d760..a537f71 100644 --- a/Source/LibTIFF4/ChangeLog +++ b/Source/LibTIFF4/ChangeLog @@ -1,5835 +1,5835 @@ -2012-09-22 Bob Friesenhahn - - * libtiff 4.0.3 released. - -2012-09-20 Bob Friesenhahn - - * Makefile.am: Update to Automake 1.12.4 - -2012-08-19 Bob Friesenhahn - - * Makefile.in: Update to Automake 1.12.3 - - * libtiff{tiff.h, tif_print.c, tif_dirinfo.c, tif_dirread.c}: Add - some TIFF/FX support in libtiff. Add the tag definitions to - tiff.h. Add the related TIFF field definitions to tif_dirinfo.c, - and also fixes an error in a comment. Adds the photometric values - to tif_print.c, and fixes a bug. These changes are by Steve - Underwood. - -2012-08-13 Frank Warmerdam - - * libtiff/tif_write.c: Fix bug rewriting image tiles in a - compressed file: http://trac.osgeo.org/gdal/ticket/4771 - -2012-08-02 Frank Warmerdam - - * libtiff/tif_dirread.c: report error in case of mismatch value - counts for tags (ie. DotRange). - -2012-07-26 Tom Lane - - * libtiff/{tiffio.h, tif_dirinfo.c, libtiff.def}: Add six new - functions TIFFFieldTag(), TIFFFieldName(), TIFFFieldDataType(), - TIFFFieldPassCount(), TIFFFieldReadCount(), TIFFFieldWriteCount() - as external accessors for the opaque type TIFFField. - - * tools/tiffset.c: Make tiffset use the above functions instead of - relying on library private headers. - -2012-07-19 Tom Lane - - * tools/tiff2pdf.c: Fix two places where t2p_error didn't get set - after a malloc failure. No crash risk AFAICS, but the program - might not report exit code 1 as desired. h/t mancha@mac.hush.com - -2012-07-18 Tom Lane - - * tools/tiff2pdf.c: Fail when TIFFSetDirectory() fails. This - prevents core dumps or perhaps even arbitrary code execution when - processing a corrupt input file (CVE-2012-3401). - -2012-07-06 Bob Friesenhahn - - * test/raw_decode.c (main): Test fixes to work with IJG JPEG 7+. - IJG JPEG 7+ uses a different upsampling algorithm which produces - different numeric results. - - * libtiff/tif_jpeg.c (JPEGPreDecode): Patch from Even Rouault to - work with IJG JPEG 7+. - -2012-07-04 Bob Friesenhahn - - * test/raw_decode.c: Add changes so that test can run with build - directory outside of source directory. - -2012-07-02 Frank Warmerdam - - * libtiff/tif_jpeg.c: Fix handling when writing RGBA jpeg compressed - imagery (http://trac.osgeo.org/gdal/ticket/4732) - -2012-06-20 Frank Warmerdam - - * libtiff/tif_fax3.c: fix memory initialization of runs, only - partly done. - - * libtiff/tif_pixarlog.c: Make sure tbuf is large enough for one - full "stride" past the end. - -2012-06-19 Frank Warmerdam - - * libtiff/tif_packbits.c: fix read past end of data buffer. - -2012-06-15 Frank Warmerdam - - * libtiff 4.0.2 released. - - * tools/tif2pdf.c, tools/tifdump.c: avoid unitialized variable - warnings with clang. - -2012-06-15 Tom Lane - - * tools/tiff2pdf.c: Defend against integer overflows while - calculating required buffer sizes (CVE-2012-2113). - -2012-06-12 Frank Warmerdam - - * libtiff/tif_print.c: Be careful about printing corrupt inknames. - - * libtiff/tif_fax3.c: Ensure runs array is initialized to zeros. - -2012-06-07 Frank Warmerdam - - * libtiff/tif_print.c: avoid pretty printing other fields when - we don't have the proper amount and type of data or if the field - is actually autodefined. - -2012-06-05 Frank Warmerdam - - * libtiff/tif_tile.c, libtiff/tif_strip.c: Ensure that illegal - ycbcrsubsampling values result in a runtime error, not just an - assertion. - - * tests/custom_dir.c: Add testing of EXIF and custom directory - reading and writing. - - * libtiff/tif_dir.c, libtiff/tiffio.h: Add TIFFCreateCustomDirectory() - and TIFFCreateEXIFDirectory() functions. - - * libtiff/tif_dir.c, tif_print.c : Remove FIELD_CUSTOM handling for - PAGENUMBER, HALFTONEHINTS, and YCBCRSUBSAMPLING. Implement DOTRANGE - differently. This is to avoid using special TIFFGetField/TIFFSetField - rules for these fields in non-image directories (like EXIF). - -2012-06-04 Frank Warmerdam - - * libtiff/tif_jpeg.c: Remove code for fixing up h_sampling and v_sampling - in JPEGPreDecode(). If a fixup will be done it needs to be done sooner - in JPEGFixupTagsSubsampling() or else buffer sized may be wrong. - -2012-06-01 Frank Warmerdam - - * tools/tiffinfo.c: Do not try to read image data in EXIF directories. - - * libtiff/tif_getimage.c: added support for _SEPARATED CMYK images. - http://bugzilla.maptools.org/show_bug.cgi?id=2379 - - * libtiff/tif_unix.c: use strerror() to return a more specific error message - on failed open. - http://bugzilla.maptools.org/show_bug.cgi?id=2341 - - * libtiff/tif_jpeg.c: Fix JPEGDecodeRaw() bugs. - http://bugzilla.maptools.org/show_bug.cgi?id=2386 - - * tests/decode_raw.c, tests/images/quad-tile.jpg.tiff: add limited support - for testing jpeg in tiff image decoding including the "raw" decode interface. - -2012-05-31 Frank Warmerdam - - * libtiff/tif_jpeg.c: avoid overrunning the end of the output buffer in - JPEGDecodeRaw() - mostly likely to occur when there is confusion about - sampling values. - - * libtiff/tif_read.c: Make sure tif_rawdatasize is cleared when tif_rawdata is freed. - - * libtiff/tif_getimage.c: Add support for greyscale+alpha c/o Jérémie Laval. - http://bugzilla.maptools.org/show_bug.cgi?id=2398 - -2012-05-29 Frank Warmerdam - - * libtiff/tif_dir.c: avoid using specific set/get logic to process fields in custom directories, - like EXIF directories. This fixes problems like a tag "320" existing in a custom directory getting - processed as if it were a colormap when it isn't really. Damn the wide variety of argument formulations - to get/set functions for different tags! - - * libtiff/tif_dir.c: Ensure that we keep track of when tif_rawdata - is a pointer into an mmap()ed file via TIFF_BUFFERMMAP flag. - -2012-05-24 Frank Warmerdam - - * libtiff/tif_pixarlog.c: Allocate working buffer one word larger since we "forward - accumulate" and overwrite the end by one word in at least some cases. - -2012-05-23 Frank Warmerdam - - * libtiff/tif_pixarlog.c: avoid accessing out of the lookup arrays for out of range inputs. - - * tools/tiffinfo.c: initialize h=0 to avoid undefined variable for degenerate files. - - * libtiff/tif_ojpeg.c: if OJPEGWriteHeader() fails once do not bother trying again on - the same image. - - * libtiff/tif_ojpeg.c: make things more resilient in the face of files without - stripbytecounts or stripoffsets or where loading these fails. - - * libtiff/tif_print.c: be careful about whether min/max values are singular - or one per sample. - - * libtiff/tif_print.c: Avoid confusion about count size when printing custom fields. - May affect things like ISOSpeedRatings. - - * libtiff/tif_dir.c: avoid one byte past end of ink names reading - in some cases. - -2012-05-19 Bob Friesenhahn - - * man/TIFFGetField.3tiff: Correct the 'count' field type in the - example for how to retreive the value of unsupported tags. - -2012-03-30 Frank Warmerdam - - * tif_getimage.c: Fix size overflow (zdi-can-1221,CVE-2012-1173) - care of Tom Lane @ Red Hat. - -2012-02-18 Bob Friesenhahn - - * libtiff 4.0.1 released. - - * Update automake used to 1.11.3. - - * libtiff/tiffio.h: Use double-underbar syntax in GCC printf - attribute specification to lessen the risk of accidental macro - substitution. Patch from Vincent Torri. - -2012-01-31 Frank Warmerdam - - * libtiff/tif_dir.c, libtiff/tif_dirread.c: Extra caution around - assumption tag fetching is always successful. - - * libtiff/tif_jpeg.c: Extra caution for case where sp is NULL. - -2012-01-22 Bob Friesenhahn - - * configure.ac: Add support for using library symbol versioning on - ELF systems with the GNU linker. Support is enabled via - --enable-ld-version-script. Disabled by default for now until - there is a decision for how to deploy a libtiff with versioned - symbols after libtiff 4.0.0 was already released. - -2011-12-22 Bob Friesenhahn - - * libtiff/tif_win32.c: Eliminate some minor 64-bit warnings in - - tif_win32.c. Patch by Edward Lam. - - * configure.ac: Add libtiff private dependency on -llzma for - pkg-config. Patch by Mark Brand. - Updated Automake to 1.11.2. - -2011-12-21 Bob Friesenhahn - - * libtiff 4.0.0 released. - -2011-12-08 Frank Warmerdam - - * libtiff/tif_dirread.c, libtiff/tif_read.c: more cautious checking - of _TIFFFillStriles() results (#gdal 4372) - -2011-12-07 Frank Warmerdam - - * libtiff/tif_dirread.c: fixes to deal with invalid files where - _TIFFFillStriles() fails, and we try to chop up strips (gdal #4372) - - * libtiff/tif_dirread.c: fix error reporting when there is no - tag information struct and name (gdal #4373) - -2011-10-22 Bob Friesenhahn - - * Update GNU libtool to 2.4.2. - - * tools/tiffsplit.c (tiffcp): TIFFGetField count field should be - uint32 type for TIFFTAG_JPEGTABLES. Patch by Christophe - Deroulers. - -2011-06-21 Frank Warmerdam - - * libtiff/libtiff.def: Restore TIFFMergeFieldInfo. - -2011-05-31 Jim Meyering - - * libtiff/tif_dirread.c (TIFFFetchStripThing): Free "data" also - upon failure to allocate "resizeddata". - * tools/tiff2ps.c (PSDataBW): Zero buffer *after* checking for - allocation failure, not before. - * libtiff/tif_ojpeg.c: plug leaks on OJPEG read failure path - * tools/rgb2ycbcr.c (cvtRaster): unchecked malloc - * libtiff/tif_jpeg.c, tools/tiff2pdf.c, tools/tiff2ps.c: mark - NULL-deref and possible overflow - * tools/tiff2pdf.c: remove decl+set of set-but-not-used local, "written" - * libtiff/tif_jpeg.c (JPEGInitializeLibJPEG): Remove declaration - and set of otherwise unused local, data_is_empty. - * libtiff/tif_jpeg.c (JPEGDecodeRaw) [JPEG_LIB_MK1_OR_12BIT]: - Diagnose out-of-memory failure and return 0 rather than - dereferencing NULL. - -2011-05-24 Frank Warmerdam - - * libtiff/tif_dirread.c: produce special error message for zero tag - directories instead of error out on the malloc(0) failure. - -2011-05-16 Frank Warmerdam - - * libtiff/tif_dirinfo.c: Restore TIFFMergeFieldInfo() and - related declarations as they are in active use by libraries - such as libgeotiff, and work just fine. (#2315) - -2011-04-20 Frank Warmerdam - - * libtiff/tif_dirinfo.c,tiffio.h: Remove the obsolete - TIFFMergeFieldInfo/TIFFFindFieldInfo/TIFFFindFieldInfoByName API. - http://bugzilla.maptools.org/show_bug.cgi?id=2315 - - * libtiff/libtiff.def: add some missing (64bit) APIs. - http://bugzilla.maptools.org/show_bug.cgi?id=2316 - -2011-04-09 Bob Friesenhahn - - * libtiff 4.0.0beta7 released. - -2011-04-09 Bob Friesenhahn - - * configure.ac: Should use AC_CANONICAL_HOST since host specifies - the run-time target whereas target is used to specify the final - output target if the package is a build tool (like a compiler), - which libtiff is not. Resolves libtiff bug 2307 "Use - AC_CANONICAL_HOST macro". - -2011-04-02 Bob Friesenhahn - - * configure.ac: Support configuring TIFF_INT64_FORMAT and - TIFF_UINT64_FORMAT appropriately for MinGW32. - - * tools/tiffdump.c (ReadDirectory): MinGW32 needs to use WIN32 - printf conventions for 64-bit types because it uses the WIN32 CRT. - - * libtiff/{tif_dumpmode.c,tif_luv.c,tif_lzw.c,tif_print.c, - tif_read.c,tif_strip.c,tif_thunder.c}: MinGW32 needs to use WIN32 - printf conventions for 64-bit types because it uses the WIN32 CRT. - - * tools/tiff2pdf.c (t2p_write_pdf_string): Fix printf syntax not - understood by WIN32 CRT. - - * libtiff/tif_ojpeg.c: Fixes to compile with MinGW32 GCC. - - * tools/fax2ps.c (main): Use tmpfile() rather than mkstemp() since - it is much more portable. Tmpfile is included in ISO/IEC - 9899:1990 and the WIN32 CRT. - -2011-03-26 Frank Warmerdam - - * tools/tiffset.c: add -d and -sd switches to allow operation on - a particular directory, not just the first (jef). - -2011-03-21 Frank Warmerdam - - * libtiff/tif_thunder.c: Correct potential buffer overflow with - thunder encoded files with wrong bitspersample set. The libtiff - development team would like to thank Marin Barbella and TippingPoint's - Zero Day Initiative for reporting this vulnerability (ZDI-CAN-1004, - CVE-2011-1167). - http://bugzilla.maptools.org/show_bug.cgi?id=2300 - -2011-03-10 Frank Warmerdam - - * libtiff/tif_fax3.h: Fix to last change allowing zero length - runs at the start of a scanline - needed for legal cases. - -2011-03-02 Frank Warmerdam - - * libtiff/tif_fax3.h: Protect against a fax VL(n) codeword commanding - a move left. Without this, a malicious input file can generate an - indefinitely large series of runs without a0 ever reaching the right - margin, thus overrunning our buffer of run lengths. Per CVE-2011-0192. - This is a modified version of a patch proposed by Drew Yao of Apple - Product Security. It adds an unexpected() report, and disallows the - equality case, since emitting a run without increasing a0 still allows - buffer overrun. - -2011-02-23 Frank Warmerdam - - * libtiff/tif_jpeg.c: avoid divide by zero in degenerate case (#2296) - - * tools/tiff2rgba.c: close source file on error to make leak - detection easier. - - * libtiff/tif_getimage.c: avoid leaks if TIFFRGBAImageBegin() fails. - - http://bugzilla.maptools.org/show_bug.cgi?id=2295 - -2011-02-22 Frank Warmerdam - - * libtiff/tif_lzma.c: Maintain tif_rawcc/tif_rawcp (CHUNKY_STRING_READ - _SUPPORT) - -2011-02-18 Frank Warmerdam - - * configure.ac, configure: Added support for --enable-chunky-strip-read - configure option to enable the experimental feature from a couple - months ago for reading big strips in chunks. - - * configure.ac, tif_read.c, tif_readdir.c, tif_dir.h, tiffiop.h, - tif_write.c, tif_print.c, tif_jpeg.c, tif_dirwrite.c, tif_write.c: - Implement optional support for deferring the load of strip/tile - offset and size tags for optimized scanning of directories. Enabled - with the --enable-defer-strile-load configure option (DEFER_STRILE_LOAD - #define in tif_config.h). - -2011-02-11 Frank Warmerdam - - * libtiff/tif_print.c: remove unused variable. - -2011-02-09 Frank Warmerdam - - * libtiff/tif_win32.c: avoid error/warning buffer overrun problem - with non-console (popup message) builds on win32. - - http://bugzilla.maptools.org/show_bug.cgi?id=2293 - -2011-01-24 Olivier Paquet - - * libtiff/{tif_dir.{h,c}, tif_dirinfo.c, tif_dirread.c, tif_dirwrite.c, - tif_print.c, tiff.h, tiffiop.h} : Added support for - TIFFTAG_SMINSAMPLEVALUE and TIFFTAG_SMAXSAMPLEVALUE to have different - values for each sample. Presents the min/max of all samples by default for - compatibility. TIFFSetField/TIFFGetField can be made to handle those tags - as arrays by changing the new TIFFTAG_PERSAMPLE pseudo tag. - http://www.asmail.be/msg0055458208.html - -2011-01-06 Frank Warmerdam - - * libtiff/tif_pixarlog.c: Note that tif_rawcc/tif_rawcp are not - maintained. - - * libtiff/tif_zip.c: Maintain tif_rawcc/tif_rawcp when decoding - for CHUNKY_STRIP_READ_SUPPORT. - - * libtiff/tif_jpeg.c: ensure that rawcc and rawcp are maintained - during JPEGPreDecode and JPEGDecode calls. - * libtiff/tif_read.c: larger read ahead for CHUNKY_STRIP_READ_SUPPORT, - as compression formats like JPEG keep 16 lines interleaved in a sense - and might need to touch quite a bit of data. - - http://trac.osgeo.org/gdal/ticket/3894 - -2011-01-03 Lee Howard - - * libtiff/tif_jpeg.c: Fix regressions with 2 and 3 band images - caused by commit on 2010-12-14. Submitted by e-mail from - Even Rouault - -2010-12-31 Olivier Paquet - - * libtiff/tif_dirwrite.c: Fixed writing of TIFFTAG_REFERENCEBLACKWHITE. - http://bugzilla.maptools.org/show_bug.cgi?id=2266 - -2010-12-23 Andrey Kiselev - - * tools/tiffcp.c, man/tiffcp.1: Added support for specifying the - compression level parameter (preset) for Deflate and LZMA encoders, - e.g "-c lzma:p1" or "-c zip:p9". - - * libtiff/tif_lzma.c: Properly set the LZMA2 compression level - (preset) in LZMAVSetField(). - -2010-12-18 Bob Friesenhahn - - * libtiff/Makefile.am (libtiff_la_SOURCES): Added tif_lzma.c to - Makefile. - -2010-12-14 Andrey Kiselev - - * configure.ac, libtiff/{tif_codec.c, tif_config.h.in, tiff.h, - tiffiop.h, tif_lzma.c}, tools/tiffcp.c, man/tiffcp.1: Implement a new - TIFF compression scheme LZMA reserving a new value 34925 for - Compression tag. As per - bug http://bugzilla.maptools.org/show_bug.cgi?id=2221 - -2010-12-14 Lee Howard - - * libtiff/tif_dirread.c: tolerate some cases where - FIELD_COLORMAP is missing - http://bugzilla.maptools.org/show_bug.cgi?id=2189 - -2010-12-14 Lee Howard - - * libtiff/tif_read.c: change read_ahead to tmsize_t - http://bugzilla.maptools.org/show_bug.cgi?id=2222 - -2010-12-14 Lee Howard - - * configure.ac, libtiff/Makefile.am: Build tif_win32.c on - Windows except on Cygwin - http://bugzilla.maptools.org/show_bug.cgi?id=2224 - -2010-12-14 Lee Howard - - * tools/gif2tiff.c: fix buffer overrun - http://bugzilla.maptools.org/show_bug.cgi?id=2270 - -2010-12-14 Lee Howard - - * libtiff/tif_jpeg.c: reduce usage of JCS_UNKNOWN in order - to improve compatibility with various viewers - submitted by e-mail from Dwight Kelly - -2010-12-13 Lee Howard - - * tools/fax2ps.c: be consistent with page-numbering - http://bugzilla.maptools.org/show_bug.cgi?id=2225 - -2010-12-13 Lee Howard - - * libtiff/tif_color.c: prevent crash in handling bad TIFFs - resolves CVE-2010-2595 - http://bugzilla.maptools.org/show_bug.cgi?id=2208 - -2010-12-13 Lee Howard - - * tools/tiffcrop.c: new release by Richard Nolde - http://bugzilla.maptools.org/show_bug.cgi?id=2004 - -2010-12-12 Lee Howard - - * tools/tiff2pdf.c: fix colors for images with RGBA - interleaved data - http://bugzilla.maptools.org/show_bug.cgi?id=2250 - -2010-12-12 Lee Howard - - * libtiff/tif_dirread.c: fix for Zeiss LSM and Canon CR2 files - http://bugzilla.maptools.org/show_bug.cgi?id=2164 - -2010-12-11 Lee Howard - - * tools/tiff2pdf.c: remove invalid duplication for Lab - http://bugzilla.maptools.org/show_bug.cgi?id=2162 - -2010-12-11 Lee Howard - - * libtiff/tif_jpeg.c: fix use of clumplines calculation - http://bugzilla.maptools.org/show_bug.cgi?id=2149 - -2010-12-11 Lee Howard - - * tools/fax2ps.c: replace unsafe tmpfile() with mkstemp() - http://bugzilla.maptools.org/show_bug.cgi?id=2118 - -2010-12-11 Lee Howard - - * libtiff/tif_ojpeg.c, libtiff/tif_pixarlog.c, - libtiff/tif_zip.c: fix build errors for VC6 - http://bugzilla.maptools.org/show_bug.cgi?id=2105 - -2010-12-11 Lee Howard - - * libtiff/tif_stream.cxx: warnings cleanup - http://bugzilla.maptools.org/show_bug.cgi?id=2091 - * libtiff/tif_dirread.c: warnings cleanup - http://bugzilla.maptools.org/show_bug.cgi?id=2092 - -2010-12-11 Lee Howard - - * tools/tiff2pdf.c: add fill-page option - http://bugzilla.maptools.org/show_bug.cgi?id=2051 - -2010-12-11 Lee Howard - - * libtiff/tif_dirread.c: modify warnings - http://bugzilla.maptools.org/show_bug.cgi?id=2016 - -2010-12-11 Lee Howard - - * libtiff/tif_ojpeg.c: fix buffer overflow on problem data - http://bugzilla.maptools.org/show_bug.cgi?id=1999 - -2010-12-11 Lee Howard - - * tools/tiffinfoce.c: strip byte counts are uint64* now - -2010-12-11 Lee Howard - - * libtiff/tif_ojpeg.c: fix crash when reading a TIFF with a zero - or missing byte-count tag - * tools/tiffsplit.c: abort when reading a TIFF without a byte-count - per http://bugzilla.maptools.org/show_bug.cgi?id=1996 - -2010-12-08 Lee Howard - - * libtiff/tif_dirread.c: fix crash when reading a badly-constructed - TIFF per http://bugzilla.maptools.org/show_bug.cgi?id=1994 - -2010-12-06 Lee Howard - - * libtiff/tif_open.c: Fix mode check before opening a file. - http://bugzilla.maptools.org/show_bug.cgi?id=1906 - -2010-11-27 Bob Friesenhahn - - * libtiff-4.pc.in: Added libtiff pkg-config .pc file support. - Patch by Vincent Torri. - -2010-10-21 Frank Warmerdam - - * tools/tiffinfo.c: avoid direct reference to _TIFFerrorHandler. - - * libtiff/tif_config.vc.h: define snprintf to _snprintf for tiff2pdf. - - * libtiff/libtiff.def: export _TIFFCheckMalloc for tools. - -2010-09-25 Lee Howard - - * tools/tiff2ps.c: improvements and enhancements from Richard Nolde - with additional command line options for Document Title, - Document Creator, and Page Orientation - -2010-07-13 Bob Friesenhahn - - * tools/tiffcrop.c: Patch from Richard Nolde to avoid a - potentially unterminated buffer due to using an exceptionally long - file name. - -2010-07-08 Andrey Kiselev - - * tools/tiff2pdf.c: Fixed ID buffer filling in - t2p_write_pdf_trailer(), thanks to Dmitry V. Levin. - -2010-07-07 Andrey Kiselev - - * libtiff/tif_dirread.c: Really reset the tag count in CheckDirCount() - to expected value as the warning message suggests. As per bug - http://bugzilla.maptools.org/show_bug.cgi?id=1963 - -2010-07-06 Andrey Kiselev - - * tools/tiffset.c: Properly handle TIFFTAG_PAGENUMBER, - TIFFTAG_HALFTONEHINTS, TIFFTAG_YCBCRSUBSAMPLING, TIFFTAG_DOTRANGE - which should be set by value. - - * libtiff/tif_dirinfo.c: Don't use assertions in _TIFFFieldWithTag() - and _TIFFFieldWithName() if the tag is not found in the tag table. - This should be normal situation and returned NULL value should be - properly handled by the caller. - -2010-07-02 Andrey Kiselev - - * libtiff/tif_getimage.c: Avoid wrong math du to the signed/unsigned - integer type conversions. As per bug - http://bugzilla.maptools.org/show_bug.cgi?id=2207 - - * tools/{tiff2bw.c, thumbnail.c, pal2rgb.c}: Fix the count for - WhitePoint tag as per bug - http://bugzilla.maptools.org/show_bug.cgi?id=2042 - - * libtiff/tif_getimage.c: Check the number of samples per pixel when - working with YCbCr image in PickContigCase(). As per bug - http://bugzilla.maptools.org/show_bug.cgi?id=2216 - - * libtiff/tif_dir.c: Set the bogus post-decoding hook when processing - TIFFTAG_BITSPERSAMPLE in _TIFFVSetField() for the case of 8 bit when - we don't need any post-processing. That helps to reset the hook if we - previously set this field to some other value and the hook was - initialized accordingly. As per bug - http://bugzilla.maptools.org/show_bug.cgi?id=2035 - -2010-07-01 Andrey Kiselev - - * tools/tiffgt.c: Properly check the raster buffer allocations for - integer overflows. As per bug - http://bugzilla.maptools.org/show_bug.cgi?id=2108 - - * m4/acinclude.m4: Update GL/GLU/GLUt/Pthread macros from the - upstream. - - * libtiff/{tif_aux.c, tif_strip.c, tif_tile.c, tiffiop.h}: Move - multiply_32() and multiply_64() functions into tif_aux.c file and - rename them into _TIFFMultiply32() and _TIFFMultiply64() respectively. - -2010-06-30 Andrey Kiselev - - * tools/tiff2pdf.c: Better generation of ID field in - t2p_write_pdf_trailer(). Get rid of GCC aliasing warnings. - - * tools/tiff2pdf.c: Fixed computation of the tile buffer size when - converting JPEG encoded tiles. - - * tools/tiff2pdf.c: Better handling of string fields, use static - string buffers instead of dynamically allocated, use strncpy() instead - of strcpy(), control the string lengths. - -2010-06-25 Andrey Kiselev - - * tools/tiffcp.c: Initialize buffer arrays with zero to avoid - referencing to uninitialized memory in some cases (e.g. when tile size - set bigger than the image size). - -2010-06-15 Bob Friesenhahn - - * tools/tiffcrop.c: Patch from Richard Nolde. Reject YCbCr - subsampled data since tiffcrop currently doesn't support it. Fix - JPEG support. - -2010-06-13 Frank Warmerdam - - * libtiff/tif_dirinfo.c: Fix invocation of tag compare function (#2201) - - * tools/tiff2pdf.c: Fix assorted bugs in tiff2pdf: missing "return" - in t2p_read_tiff_size() causes t2p->tiff_datasize to be set entirely - wrong for COMPRESSION_JPEG case, resulting in memory stomp if actual - size is larger. Also, there are a bunch of places that try to - memset() a malloc'd buffer before checking for malloc failure, which - would result in core dump if there actually were a failure. (#2211) - -2010-06-11 Bob Friesenhahn - - * libtiff/tiffiop.h (TIFFSafeMultiply): Need more castings to - avoid compiler warnings if parameter types are not sign - consistent. - - * libtiff 4.0.0alpha6 released. - - * tools/tiffcrop.c: Applied patch from Richard Nolde: Corrected - European page size dimensions. Added an option to allow the user - to specify a custom page size on the command line. Fix the case - where a page size specified with a fractional part was being - coerced to an integer by retyping the variables that define the - paper size. - - * html/index.html: Update for the 3.9.3 release. - - * tools/tiffcp.c (tiffcp): Applied Tom Lane's patch to reject - YCbCr subsampled data since tiffcp currently doesn't support it. - http://bugzilla.maptools.org/show_bug.cgi?id=2097 - - * Update libtool to version 2.2.10. - -2010-06-10 Bob Friesenhahn - - * libtiff/tiffiop.h (TIFFSafeMultiply): Work properly if - multiplier is zero. - -2010-06-09 Bob Friesenhahn - - * libtiff/tif_fax3.c (Fax3SetupState): Yesterday's fix for - CVE-2010-1411 was not complete. - - * libtiff/tiffiop.h (TIFFSafeMultiply): New macro to safely - multiply two integers. Returns zero if there is an integer - overflow. - - * tools/tiffcp.c (main): tiffcp should not leak memory if an error - is reported when reading the input file. - -2010-06-08 Bob Friesenhahn - - * Update libtool to version 2.2.8. - - * libtiff/tif_fax3.c (Fax3SetupState): Avoid under-allocation of - buffer due to integer overflow in TIFFroundup() and several other - potential overflows. In conjunction with the fix to TIFFhowmany(), - fixes CVE-2010-1411. - - * libtiff/tiffiop.h (TIFFhowmany): Return zero if parameters would - result in an integer overflow. This causes TIFFroundup() to also - return zero if there would be an integer overflow. - - * contrib: Add an emacs formatting mode footer to all source files - so that emacs can be effectively used. - -2010-06-03 Oliver Chen Feng - - * libtiff/tools/tiffcp.c: add a new option -x to force merged tiff - file PAGENUMBER value in sequence for users who care the page - sequence, this will also prevent tiff2pdf from creating pdf file from - the merged tiff file with wrong page sequence. - -2010-05-08 Olivier Paquet - - * libtiff/tif_dirread.c: Restored TIFFReadDirEntryFloat function in order - to add missing TIFF_SETGET_FLOAT case to TIFFFetchNormalTag. - * libtiff/tif_dirinfo.c: Use correct set_field_type for - TIFFTAG_PIXAR_FOVCOT so it is readable again (regression from 3.9.2). - http://bugzilla.maptools.org/show_bug.cgi?id=2192 - -2010-05-07 Frank Warmerdam - - * libtiff/tif_jpeg.c: Ensure that quality is always set in - JPEGPreEncode(), not just when we want to output local tables. - Otherwise the quality used during compression may not be right and - might not match the tables in the tables tag. This bug only occurs - when seeking between directories in the midst of writing blocks. - http://trac.osgeo.org/gdal/ticket/3539 - -2010-05-06 Andrey Kiselev - - * html/man/TIFFGetField.3tiff.html, html/man/TIFFSetField.3tiff.html: - Regenerated from the source. - -2010-05-05 Olivier Paquet - - * libtiff/tif_print.c: Fixed printing of TIFFTAG_REFERENCEBLACKWHITE which - had stopped working. Also made it always print 6 floats instead of - 2*SamplesPerPixel. - http://bugzilla.maptools.org/show_bug.cgi?id=2191 - http://bugzilla.maptools.org/show_bug.cgi?id=2186 - * man/TIFFGetField.3tiff, man/TIFFSetField.3tiff: Fixed doc to reflect the - fact that libtiff considers TIFFTAG_REFERENCEBLACKWHITE to be 6 floats. - -2010-05-05 Frank Warmerdam - - * libtiff/tif_jpeg.c: Fix to use memcmp(), not memcpy() when checking - if the jpeg table was written. This is a fix for the last fix on 04-21. - -2010-04-21 Frank Warmerdam - - * libtiff/tif_jpeg.c: avoid preparing jpeg tables everytime - JPEGSetupEncode() is called if the tables already seem to be - established. This prevents spurious updates and rewriting of - directories with jpegtables when doing updates to existing images. - http://trac.osgeo.org/gdal/ticket/3539 - -2010-04-20 Olivier Paquet - - * libtiff/tif_dirinfo.c: Use correct set_field_type for - TIFFTAG_PIXAR_IMAGEFULLWIDTH, TIFFTAG_PIXAR_IMAGEFULLLENGTH, - TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN and TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA. - They were unreadable with TIFF_SETGET_UNDEFINED, a regression from 3.9.2. - http://bugzilla.maptools.org/show_bug.cgi?id=2139 - -2010-04-10 Bob Friesenhahn - - * libtiff/tif_dir.c (_TIFFVSetField): Add a special error case for - when the tag count value is zero. Error handling is still a - regression since in 3.9.2, empty tags are skipped (with a warning) - rather than returning a hard error and refusing to read the file. - - * tools/ppm2tiff.c (main): While case for parsing comment line - requires extra parenthesis to work as expected. Reported by - Thomas Sinclair. - -2010-04-02 Frank Warmerdam - - * libtiff/tif_read.c (primarily): Add support for - CHUNKY_STRIP_READ_SUPPORT where large strips are - read in chunks for applications using TIFFReadScanline(). - This is intended to make it more practical work with very - large compressed one-strip files. Feature is off by default. - Enable by defining CHUNK_STRIP_READ_SUPPORT as a macro. - http://trac.osgeo.org/gdal/ticket/3514 - -2010-03-31 Frank Warmerdam - - * libtiff/tif_flush.c: Use TIFFRewriteDirectory() when flushing - directories so previously placed directories will be migrated to - the end of file if needed. - -2010-03-30 Frank Warmerdam - - * libtiff/tif_lzw.c: change type of dec_bitsleft field to uint64 - to support operating on strips/tiles of more than 256MB. - http://trac.osgeo.org/gdal/ticket/3512 - -2010-03-10 Bob Friesenhahn - - * libtiff/tif_aux.c (_TIFFCheckRealloc): Improve error message so - that it is clearly a memory allocation error message, and also - includes the size of the allocation request. - -2010-02-22 Lee Howard - - * libtiff/tif_jpeg.c: Do not generate a JPEGTables tag when creating - the JPEG TIFF as is is not required in order to prevent it from - being unused and filled with invalid data. (Leave it to be - generated by later activity.) - http://bugzilla.maptools.org/show_bug.cgi?id=2135 - * tools/tiff2pdf.c: Write the JPEG SOI headers into the TIFF strip - data rather than skipping them. This fixes the ability to view in - Acrobat Reader, Evince, and Ghostscript. - http://bugzilla.maptools.org/show_bug.cgi?id=2135 - * libtiff/tif_fax3.c: Don't return error on badly-terminated MMR - strips. - http://bugzilla.maptools.org/show_bug.cgi?id=2029 - -2009-12-03 Frank Warmerdam - - * libtiff/tif_jpeg.c: Made JPEGDecodeRaw() check for buffer overruns. - Made so that when working with downsampled images a stub function - reporting an error is used for tif_decoderow. We cannot meaningfully - support reading scanlines in this situation. (#1936) - - * libtiff/tif_jpeg.c: Ensure that tif_scanlinesize is computed after - resetting of the upsampling values (gdal:#3259). - http://bugzilla.maptools.org/show_bug.cgi?id=1936 - -2009-11-30 Frank Warmerdam - - * contrib/dbs/tiff-grayscale.c, contrib/tif-palette.c, - tools/ras2tiff.c: Fix resource leaks on error. - http://bugzilla.maptools.org/show_bug.cgi?id=2121 - - * libtiff/tif_{aux.c,dir.c,dir.h,dirinfo.c}: Return to handling - TIFFTAG_REFERENCEBLACKWHITE as a field in the TIFF directory instead - of as a custom(generic) field to avoid a potential reentrancy problem. - http://bugzilla.maptools.org/show_bug.cgi?id=2125 - - * libtiff/tif_color.c, libtiff/tif_getimage.c, libtiff/tiffio.h, - man/TIFFcolor.3tiff: Make TIFFDisplay argument in TIFFCIELabToRGBInit - const, and display_sRGB static and const. - http://bugzilla.maptools.org/show_bug.cgi?id=2124 - -2009-11-04 Bob Friesenhahn - - * libtiff 4.0.0alpha5 released. - -2009-11-03 Bob Friesenhahn - - * tools/tiffcrop.c: Updated tiffcrop from Richard Nolde. This - version has undergone substantial testing with arbitrary sample - bit depths. Also eliminates GCC compilation warnings. - -2009-11-02 Bob Friesenhahn - - * port/libport.h: Add extern declarations for getopt standard - globals. - -2009-10-31 Bob Friesenhahn - - * libtiff/tif_lzw.c (LZWDecode, LZWDecodeCompat): Fix warnings - noticed in 64-bit build of libtiff with Visual Studio 2005. - Resolves "Bug 2067 - Visual Studio 2005 64-bit warnings in - tif_lzw.c", http://bugzilla.maptools.org/show_bug.cgi?id=2067 - - * libtiff/tif_pixarlog.c (PixarLogEncode): Fix non-important - warning noticed in Visual Studio 2005 build. Resolves "Bug 2068 - - Visual Studio 2005 64-bit warning in tif_pixarlog.c", - http://bugzilla.maptools.org/show_bug.cgi?id=2068 - -2009-10-29 Bob Friesenhahn - - * libtiff/tif_dirread.c: Eliminate GCC "dereferencing type-punned - pointer" warnings. - -2009-10-28 Bob Friesenhahn - - * html/tools.html: Add manual page links, and a summary - description of tiffcrop. - -2009-10-07 Bob Friesenhahn - - * configure.ac: x86_64 should use the same fill order as i386. - -2009-09-24 Bob Friesenhahn - - * tools/tiffcrop.c, man/tiffcrop.1: New tiffcrop from Richard - Nolde. Major updates to add significant functionality for reading - and writing tile based images with bit depths not a multiple of 8 - which cannot be handled by tiffcp. - -2009-09-03 Bob Friesenhahn - - * libtiff/tif_ojpeg.c (OJPEGWriteHeaderInfo): IJG JPEG 7 needs - do_fancy_upsampling=FALSE in order to read raw data. Resolves - "Bug 2090 - OJPEG crash with libjpeg v7". - http://bugzilla.maptools.org/show_bug.cgi?id=2090 - -2009-09-03 Frank Warmerdam - - * libtiff/tif_getimage.c: Fixed error recognition handling in RGBA - interface when stoponerror is set. - http://bugzilla.maptools.org/show_bug.cgi?id=2071 - -2009-08-30 Bob Friesenhahn - - * tools/{tiffcrop.c,tiffgt.c}: Applied patch from Oden Eriksson to - fix build with gcc when using the "-Wformat - -Werror=format-security" flags. - -2009-08-29 Bob Friesenhahn - - * test/{bmp2tiff_palette.sh, bmp2tiff_rgb.sh, gif2tiff.sh, - ppm2tiff_pbm.sh, ppm2tiff_pgm.sh, ppm2tiff_ppm.sh}: Additional - utilities tests. - -2009-08-28 Bob Friesenhahn - - * tools/tiffinfo.c: tiffinfo should return error status to the - caller. Register a private error callback to accomplish that. - - * test/Makefile.am (TIFFIMAGES): Add test images in BMP, GIF, and - PNM formats so that we will be able to test more of the tools. - While adding these test images I notice that bmp2tiff and gif2tiff - only support ancient versions of their respective formats. - -2009-08-27 Bob Friesenhahn - - * libtiff 4.0.0alpha4 released. - - * HOWTO-RELEASE: Improved release instructions. - -2009-08-24 Bob Friesenhahn - - * man/{TIFFClose.3tiff,raw2tiff.1,tiffcmp.1,tiffsplit.1}: Applied - fixes for "Bug 2023 - nroff errors in manual pages". - http://bugzilla.maptools.org/show_bug.cgi?id=2023 - - * tools/{rgb2ycbcr.c, tiff2rgba.c}: Applied fixes for "Bug 2079 - - CVE-2009-2347 libtiff: integer overflows in various inter-color - space conversion tools". - http://bugzilla.maptools.org/show_bug.cgi?id=2079 - - * libtiff/tif_print.c (TIFFPrintDirectory): Apply fix from Jay - Berkenbilt for "Bug 2024 - possible null pointer dereference with - one-line fix". - http://bugzilla.maptools.org/show_bug.cgi?id=2024 - - * libtiff/tif_dirread.c (TIFFReadCustomDirectory): Apply patch - from Jay Berkenbilt for "Bug 1895 - logic error in tif_dirread.c: - segfault after setting tdir_tag = IGNORE". - http://bugzilla.maptools.org/show_bug.cgi?id=1895 - -2009-08-23 Bob Friesenhahn - - * test/Makefile.am, test/tiffcrop*.sh: Split previously existing - tiffcrop.sh into a collection of many specific tests. Re-wrote - all of the existing tests to be based on some simple shell - functions. Make distcheck works again. - - Export certain variables (MAKE, MAKEFLAGS, MEMCHECK) to tests and - added 'memcheck' and 'ptrcheck' targets to make it easy to run the - tests under valgrind. - -2009-08-21 Bob Friesenhahn - - * test/tiffcp-logluv.sh: Fix test so that it works with a VPATH - build. - - * test/Makefile.am (AUTOMAKE_OPTIONS): Colorized tests was not - actually activated since it needed to be enabled in this - Makefile.am. Also activated parallel-tests mode since it offers - useful features such as per-test .log files and a summary test - report .log file. - -2009-08-20 Bob Friesenhahn - - * configure.ac: Updated autotools. Autoconf 2.64, Automake 1.11, - libtool 2.2.6. Enabled support for silent build rules - (--enable-silent-rules or 'make V=0') and colorized tests. - - * html/{index.html, v3.9.0.html}: Update for 3.9.0 release. - -2009-06-30 Frank Warmerdam - - * tests/tiffcp-logluv.sh: minimal testing of sgilog compression. - - * tools/tiffcp.c: add -c sgilog support. - - * libtiff/tif_luv.c: correct return codes from encoderow to be - 1 on success instead of zero. - http://bugzilla.maptools.org/show_bug.cgi?id=2069 - - * libtiff/tif_lzw.c: back out patch from #2065 and apply patch from - #1085 for a better underflow fix that errors properly. - http://bugzilla.maptools.org/show_bug.cgi?id=2065 - http://bugzilla.maptools.org/show_bug.cgi?id=1985 - -2009-06-26 Frank Warmerdam - - * libtiff/tif_strip.c: Remove an inappropriate assertion that often - fails on oddly sized 12bit jpeg compressed ycbcr images. - -2009-06-22 Frank Warmerdam - - * libtiff/tif_lzw.c: Fix buffer underflow bug. - http://bugzilla.maptools.org/show_bug.cgi?id=2065 - -2009-06-21 Frank Warmerdam - - * configure.ac, libtiff/tif_jpeg.c, libtiff/tif_jpeg_12.c: add support - for dual mode 8/12 bit jpeg support. - -2009-06-03 Frank Warmerdam - - * libtiff/tif_write.c: do not override the planar configuration to be - contig for one sample files if planar configuration is already set. - http://bugzilla.maptools.org/show_bug.cgi?id=2057 - -2009-06-02 Frank Warmerdam - - * libtiff/libtiff.def: Add TIFFUnsetField. - -2009-05-03 Frank Warmerdam - - * libtiff/{tif_jpeg.c,tif_ojpeg.c,tif_getimage.c}: Fixed various - error reports to use "%s" as format string. - http://trac.osgeo.org/gdal/ticket/2976 - -2009-03-12 Frank Warmerdam - - * libtiff/{tif_fax3.c,tif_jpeg.c,tif_ojpeg.c}: Fix printdir chaining - for some codecs (#2020). - -2009-02-12 Frank Warmerdam - - * libtiff/tif_luv.c: Fix handling of tiled logluv images. - http://bugzilla.maptools.org/show_bug.cgi?id=2005 - -2009-02-09 Frank Warmerdam - - * libtiff/tif_dirread.c: Improve allocation safety when allocated - buffer for large tags. (#1998) Related to (#1993) - -2009-02-06 Frank Warmerdam - - * tools/tiffcrop.c: Don't default image->res_unit to INCH. Now the - test suite should pass. - -2009-02-05 Frank Warmerdam - - * libtiff/tif_dirread.c: Re-incorporated a sanity check on tag size, - but at the 2GB boundary to avoid overflow on 32bit systems. - http://bugzilla.maptools.org/show_bug.cgi?id=1993 - - * libtiff/tif_dirread.c: Remove some assertions that blow due to - corrupt files rather than in response to library internal - inconsistencies. - http://bugzilla.maptools.org/show_bug.cgi?id=1995 - http://bugzilla.maptools.org/show_bug.cgi?id=1991 - - * libtiff/tif_dirread.c: Fixed testing for failed result from - TIFFReadDirectoryFindFieldInfo(). - http://bugzilla.maptools.org/show_bug.cgi?id=1992 - -2009-01-23 Frank Warmerdam - - * libtiff/tif_predict.c: Add support for 32bit integer horz. predictors. - http://bugzilla.maptools.org/show_bug.cgi?id=1911 - - * libtiff/tif_dirwrite.c: Fix byte swapping of next directory offset. - - http://bugzilla.maptools.org/show_bug.cgi?id=1924 - - * tools/tiffcrop.c: initialize xres/yres values. - - * test/*.sh - default ${srcdir} to local directory. - - * test/common.sh - start verbose mode after common settings. - - * libtiff/tif_dirinfo.c: Replace lfind() with local equivelent to - avoid type mismatches on different platforms. - http://bugzilla.maptools.org/show_bug.cgi?id=1889 - -2009-01-22 Frank Warmerdam - - * tools/{fax2tiff.c,thumbnail.c,tiff2pdf.c,tiff2ps.c,tiffdump.c, - tiffsplit.c}: avoid warnings, mostly 32bit/64bit casting issues. - - * port,tools: Introduce libport.h, and include in tools if NEED_LIBPORT - defined, primarily to reduce prototype warnings on windows. - - * libtiff/tif_dirinfo.c,tif_dirread.c: Avoid warnings - about unused parameters, and uninitialized variables. - -2009-01-21 Bob Friesenhahn - - * test/common.sh: Execute tests like 'make VERBOSE=TRUE check' in - order to trace full execution detail while executing the test suite. - -2009-01-20 Frank Warmerdam - - * tools/tiffsplit.c: fix sampleformat to be shortv instead of longv. - -2009-01-20 Bob Friesenhahn - - * test/Makefile.am (CLEANFILES): Make sure that test output files - are removed by 'make clean' - - * Update autotools for 4.0.0 beta3 - - * 4.0.0 beta3 produced. - -2009-01-12 Bob Friesenhahn - - * test/tiffcrop.sh: New test script for tiffcrop from Richard - Nolde. - - * tools/tiff2ps.c: Remove spurious message to stderr. - -2009-01-11 Bob Friesenhahn - - * tools/tiff2ps.c: Incorporated significant functionality update - from Richard Nolde. In particular, support for rotating the image - by 90, 180, 270, and 'auto' has been added. - - * man/tiffcrop.1: Incorporated documentation updates from Richard - Nolde. - - * tools/tiffcrop.c: Incorporated significant functionality update - from Richard Nolde. - -2008-12-31 Bob Friesenhahn - - * libtiff/tiffio.h: GCC will now validate format specifications - for TIFFError(), TIFFErrorExt(), TIFFWarning(), and - TIFFWarningExt() in order to reveal bugs. - - * Many fixes throughout to work better as a 64-bit build. - -2008-12-30 Bob Friesenhahn - - * tools/{tiff2pdf.c, tiff2ps.c, tiffinfo.c}: Offset and length - tags now require 64-bit parameter rather than 32-bit. - - * libtiff/tif_dirread.c: Fixed issues with unaligned access to - 64-bit values. - - * tools/thumbnail.c: Eliminate crash noticed while running test - suite. - -2008-12-29 Bob Friesenhahn - - * libtiff/tif_ojpeg.c (OJPEGLibjpegJpegSourceMgrFillInputBuffer): - Initialize stack variables to avoid compiler warning. - - * tools/tiffinfoce.c (main): Use toff_t for offset type when - retrieving offset of EXIF IFD. - - * libtiff/tiffio.h: Undeprecate toff_t and restore its use in the - TIFFClientOpen() callback and other external function definitions. - - * tools/tiffinfo.c (main): Offset to EXIF IFD requires a 64-bit - type now. Fixes crash when dumping files containing an EXIF IFD. - - * m4/libtool.m4: Update to libtool 2.2.6. - -2008-12-21 Frank Warmerdam - - * libtiff/tif_dir.c, tiffio.h: Introduce TIFFUnsetField() function. - - * libtiff/tif_jpeg.c: Avoid errors if the application writes a full - strip for the last partial strip in a jpeg compressed file. - http://bugzilla.maptools.org/show_bug.cgi?id=1981 - -2008-10-29 Frank Warmerdam - - * libtiff/tif_flush.c: Make sure that BEENWRITING is cleared when - we take the shortcut to only update the strip/tile offsets in place. - http://trac.osgeo.org/gdal/ticket/2621 - -2008-10-21 Andrey Kiselev - - * libtiff/tif_jbig.c: Support the JBIG-KIT 2.0 (compatibility with - the older versions retained). - -2008-10-09 Frank Warmerdam - - * libtiff/tif_jpeg.c: Add #ifdefs for changes needed if using - IPP enabled version of libjpeg from Intel. - http://bugzilla.maptools.org/show_bug.cgi?id=1951 - -2008-09-05 Andrey Kiselev - - * tools/tiffsplit.c: Use byte counts of proper size (uint64). - Required for libtiff 4.0. - - * tools/tiffsplit.c: Use dynamically allocated array instead of static - when constructing output file names. - -2008-09-03 Andrey Kiselev - - * tools/tiffsplit.c: Get rid of unsafe strcpy()/strcat() calls when - doing the filename/path construction. - - * tools/tiff2pdf.c: More appropriate format string in - t2p_write_pdf_string(); avoid signed/unsigned mismatch. - - * libtiff/tif_lzw.c: Properly zero out the codetable. As per bug - - http://bugzilla.maptools.org/show_bug.cgi?id=1929 - - * libtiff/tif_lzw.c: Properly zero out the string table. Fixes - CVE-2008-2327 security issue. - -2008-09-01 Frank Warmerdam - - * libtiff/tif_dirread.c: Avoid unused TIFFReadDirEntryFloat() function. - - * libtiff/tif_dirwrite.c: modified to write IFDs as either IFD8 or IFD - depending on whether the file is bigtiff or classic tiff. - http://bugzilla.maptools.org/show_bug.cgi?id=1917 - -2008-08-12 Edward Lam - - * tools/tiffdump.c: When compiling for Microsoft Windows, apply - consistent (__int64) casting when testing if _lseeki64 has - successfully seeked as requested. This is necessary for large - file support to work since off_t is only 32-bit. - -2008-07-29 Frank Warmerdam - - * tif_strip.c: Replace assertions related to samplesperpixel != 3 or - the subsampling values not being 1, 2 or 4 (for jpeg compressed images) - with control logic to return runtime errors (c/o Even Rouault) (#1927). - -2008-06-17 Frank Warmerdam - - * tools/tiffcrop.c: Fix some portability problems. - - * libtiff/tif_ojpeg.c: Use same jpeg/win32 boolean/FAR hacks as are - used in tif_jpeg.c. - - * libtiff/tif_win32.c: Ensure TIFFOpenW() uses same FILE_SHARE flags - as TIFFOpen(). - -2008-06-01 Frank Warmerdam - - * libtiff/tif_dirwrite.c: Fix alignment problems affecting architectures - like Sparc/Solaris. - http://bugzilla.maptools.org/show_bug.cgi?id=1892 - -2008-05-27 Frank Warmerdam - - * libtiff.def: Add TIFFFindField - http://bugzilla.maptools.org/show_bug.cgi?id=1891 - -2008-05-26 Frank Warmerdam - - * tif_config.*.h, tiffconf.*.h: Remove SIZEOF_LONG definition, unused. - - * li2008-04-15 Andrey Kiselev - -btiff/tif_win32.c: Replace custom Win32 memory api with generic - POSIX one. No apparent value to use of GlobalAlloc() in the modern - age. http://bugzilla.maptools.org/show_bug.cgi?id=1885 - - * libtiff/tiffconf.vc.h: Added JBIG_SUPPORT and MDI_SUPPORT items - in windows version (care of Edward Lam). - -2008-05-24 Frank Warmerdam - - * tif_codec.c: Avoid NULL pointer dereferencing for exotic - compression codec codes. - - * tif_dirwrite.c: fix potential memory leak. - - * tif_dirread.c: Fix unchecked malloc result. - -2008-05-24 Bob Friesenhahn - - * test {tiff2pdf.sh tiff2ps-EPS1.sh tiff2ps-PS1.sh tiff2ps-PS2.sh - tiff2ps-PS3.sh tiffcp-g3-1d-fill.sh tiffcp-g3-1d.sh - tiffcp-g3-2d-fill.sh tiffcp-g3-2d.sh tiffcp-g3.sh tiffcp-g4.sh - tiffcp-split-join.sh tiffcp-split.sh tiffcp-thumbnail.sh - tiffdump.sh tiffinfo.sh}: Added more test scripts based on - suggestions from Lee Howard posted to the tiff list on 13 Sep - 2007. - -2008-05-23 Frank Warmerdam - - * libtiff/tif_fax3.c: Add an assert in an effort to detect a - possible runtime problem reported by coverity. - - * contrib/iptcutil/iptcutil.c: Fixed memory leak of str. - - * tools/tiffcrop.c, man/tiffcrop.1: Major update from Richard Nolde. - http://bugzilla.maptools.org/show_bug.cgi?id=1888 - - * tools/tiffdither.c: remove dead onestrip code. avoid memory leak. - - * tools/rgb2ycbcr.c: fix memory leak of raster buffer. - - * tools/tiffcp.c: Simplify inknames code to avoid pointless test. - Cleanup scanline allocation to avoid coverity warning. - - * tools/thumbnail.c: Check for TIFFOpen() failure. - -2008-05-18 Frank Warmerdam - - * libtiff/tif_dirinfo.c: Use TIFF_SETGET_ASCII for PIXAR_TEXTUREFORMAT - and PIXAR_WRAPMODES instead of TIFF_SETGET_UNDEFINED. Not exactly clear - why this is needed. - -2008-05-09 Bob Friesenhahn - - * Makefile.am (ACLOCAL_AMFLAGS): Libtool 2.2.4 does not like - "ACLOCAL_AMFLAGS=-I ./m4". It wants "ACLOCAL_AMFLAGS=-I m4". - -2008-04-15 Andrey Kiselev - - * test/: Test suite updated. Everything is passed now. - - * libtiff/tif_dirinfo.c: Fixed description of the - TIFFTAG_NUMBEROFINKS tag. - -2008-04-14 Andrey Kiselev - - * libtiff/{tif_dirread.c, tif_dirwrite.c, tiffiop.h}: - Get rid of some of "dereferencing type-punned" warnings by converting - tdir_offset field of TIFFDirEntry structure into union. - -2008-04-10 Andrey Kiselev - - * libtiff/{tif_flush.c, tif_dirwrite.c, tiffio.h, tiffiop.h}: - TIFFRewriteField() renamed into _TIFFRewriteField() and moved out - from the public interface. Type of its 'count' parameter changed - from uint32 to tmsize_t. - - * /libtiff/tiffiop.h: Make tif_nfields and tif_nfieldscompat fields - of the tiff structure have the size_t type instead of uint32. - -2008-04-09 Andrey Kiselev - - * tools/tiffdump.c: Added support for MSVS 6.0. - - * libtiff/tif_dirread.c: Use custom functions _TIFFUInt64ToFloat() - and _TIFFUInt64ToDouble() to convert 64-bit integers into floating - point values on MSVS 6.0 platform. - -2008-03-14 Frank Warmerdam - - * tif_dirread.c: Removed sanity checks on tags larger than 4MB in - TIFFReadDirEntryArray() since they are interfering with seemingly - legitimate files. http://trac.osgeo.org/gdal/ticket/2005 - -2008-02-09 Joris Van Damme - - * tif_dirread.c: Added handling for the case of number of values for - PageNumber tag different from 2 (previously resulted in an assert - indicating lack of handling and was forgotten about) - -2008-02-01 Frank Warmerdam - - * libtiff/tif_jpeg.c: Do not try to fixup subsampling tags based on - the actual jpeg data stream if the first strip/tile has zero size. - This is the case when GDAL creates a new file with zero sizes, closes - and reopens it. - -2008-01-07 Frank Warmerdam - - * tools/tiff2ps.c: fix up 64bit issues (from Edward Lam). - -2008-01-01 Frank Warmerdam - - * libtiff/tif_dirwrite.c: #ifdef out lots of unused functions. - - * Makefile.vc, libtiff/Makefile.vc, tools/Makefile.vc: Improve clean - targets. - - * tools/tiffinfo.c, tools/tiffcmp.c, tools/gif2tiff.c, tools/bmp2tiff.c - tools/tiff2pdf.c: Fix 64-bit warnings when compiling under MSVC 2005 - (x64). - - * tools/tiffset.c: Changes to reflect the fact that TIFFFieldWithTag() - and TIFFFieldWithName() now return TIFFField pointers instead of - TIFFFieldInfo pointers. - - * tools/tiffdump.c: Added ssize_t typedef on Windows since it doesn't - exist. This makes it compile again on Windows - - * tif_aux.c, tif_getimage.c, tif_next.c, tif_predict.c, tif_win32.c, - tiffconf.vc.h: Various 64bit fixes from Edward Lam identified on win64. - - * test/rewrite_tag.c: New test for TIFFRewriteField(). - -2007-12-31 Frank Warmerdam - - * tif_dirwrite.c: Added TIFFRewriteField(). This new function - rewrites one field "on disk" updating an existing directory - entry. Lots of limitations still... - - * tiffiop.h, tif_write.c, tif_dirread.c, tif_flush.c: Keep track of - TIFF_DIRTYSTRIP separately from TIFF_DIRTYDIRECT to indicate that - the strip offset/size values are dirty but nothing else about the - directory is dirty. In flush handle "just stripmaps dirty" as a - special case that just rewrites these values without otherwise - modifying the directory on disk using TIFFRewriteField(). - - We also modify logic so that in update mode the directory is not - marked dirty on read, but only when something is changed. This - means we need to keep track of updates to the stripmap stuff in - TIFFAppendToStrip(). - -2007-12-10 Frank Warmerdam - - * tif_jpeg.c: Improve ability to switch between encoding and decoding - in the jpeg code (gdal bug #2033). - -2007-11-23 Frank Warmerdam - - * tif_dir.c, tif_dirread.c, tif_dirwrite.c, tif_read.c, tif_write.c, - tiffiop.h: Added TIFF_BUF4WRITE flag to indicate if contents of the - rawcp/rawcc buffer are for writing and thus may require flushing. - Necessary to distinguish whether they need to be written to disk when - in mixed read/write mode and doing a mixture of writing followed by - reading. http://trac.osgeo.org/gdal/ticket/1758 - -2007-11-23 Andrey Kiselev - - * configure.com, libtiff/tif_vms.c: Better OpenVMS support. Patches - from Alexey Chupahin. - -2007-11-02 Frank Warmerdam - - * tif_write.c: Rip out the fancy logic in TIFFAppendToStrip() for - establishing if an existing tile can be rewritten to the same location - by comparing the current size to all the other blocks in the same - directory. This is dangerous in many situations and can easily - corrupt a file. (observed in esoteric GDAL situation that's hard to - document). This change involves leaving the stripbytecount[] values - unaltered till TIFFAppendToStrip(). Now we only write a block back - to the same location it used to be at if the new data is the same - size or smaller - otherwise we move it to the end of file. - - * tif_dirwrite.c: Try to avoid writing out a full readbuffer of tile - data when writing the directory just because we have BEENWRITING at - some point in the past. This was causing odd junk to be written out - in a tile of data when a single tile had an interleaving of reading - and writing with reading last. (highlighted by gdal - autotest/gcore/tif_write.py test 7. - - * tif_predict.c: use working buffer in PredictorEncodeTile to avoid - modifying callers buffer. - http://trac.osgeo.org/gdal/ticket/1965 - - * tif_predict.c/h: more fixes related to last item, keeping a - distinct pfunc for encode and decode cases as these were getting - mixed up sometimes. - http://trac.osgeo.org/gdal/ticket/1948 - -2007-11-01 Frank Warmerdam - - * tif_predict.c/h, tif_lzw.c, tif_zip.c: Improvements so that - predictor based encoding and decoding works in read-write update - mode properly. - http://trac.osgeo.org/gdal/ticket/1948 - -2007-10-24 Joris Van Damme - - * tif_dirread.c: Fixed problem with bogus file triggering - assert(td->td_planarconfig == PLANARCONFIG_CONTIG) in - ChopUpSingleUncompressedStrip - -2007-10-22 Joris Van Damme - - * tif_jpeg.c: Resolved buffer incrementation bug that lead to faulty images - at best, access violation at worst, when subsampled JPEG compressed imagery - is decoded without the JPEG_COLORMODE feature - -2007-10-11 Frank Warmerdam - - * html/index.html: Update "people responsible" section. - -2007-10-05 Frank Warmerdam - - * tools/tiff2pdf.c: Fix problem with alpha setting in some cases - as reported on the mailing list. - -2007-10-01 Joris Van Damme - - * changed some more incorrect %lud printf flags to %lu - -2007-09-29 Joris Van Damme - - * tif_dirread.c: Strip chopping interfered badly with uncompressed - subsampled images because it tried to divide subsampled rowblocks, - leading to all sorts of errors throughout the library for these - images. Fixed by making strip chopping divide in row counts that - are a multiple of vertical subsampling value. - -2007-09-28 Joris Van Damme - - * tif_dirread.c: Logical cast working around compiler warning - - * tif_read.c: Correction of some error flags and parameter lists - -2007-09-27 Joris Van Damme - - * tif_dirread.c: Made calculation of td_maxsamplevalue more robust - when dealing with large bitspersample values, shutting up purification - tools that warn about truncation, though it remains incorrect and - indicates a conceptual problem there. - - * tif_open.c: Moved early exit in case of 'h' flag (to disable reading - of first IFD) to proper place because it badly interfered with memory - mapping, resulting in mapping flag even with dummy mapping functions - that returned 0 whilst at the same time the mapping tif_size wasn't - set, thus resulting in continuous incorrect beyond-eof errors. - -2007-09-24 Joris Van Damme - - * tif_dirinfo.c: Fixed (MSVC) compiler reports about - inconsistent use of const in tiffFields and exifFields definition - -2007-09-20 Frank Warmerdam - - * tif_dirwrite.c: Always write tile/strip offsets and sizes - using LONG8 type when output format is BigTIFF. The - TIFFWriteDirectoryTagLongLong8Array() function was restructured - accordingly. - - * tif_dirread.c: Improvements to error reporting text in - TIFFFetchDirectory(). - -2007-09-19 Bob Friesenhahn - - * test/images: Added a small collection of test images for use by - test programs and scripts. - * test/tiffinfo.sh: A trivial example test script. - * test/common.sh: Added small script for setting the environment - used by script-based tests. - -2007-08-24 Frank Warmerdam - - * tif_dirwrite.c: Write the tif_nextdiroff value instead of a fixed - zero when writing directory contents to preserve the ability to - rewrite directories in place, even in the middle of a directory - chain. - - * tif_dirinfo.c: _TIFFMergeFields() now only merges in field - definitions that are missing. Existing definitions are silently - ignored. - - * tif_dirread.c: Add runtime error for fields for which no definition - is found (in addition to an assert for developers) in - TIFFFetchNormalTag(). Not sure if this is needed, but it seems - prudent. - -2007-08-10 Joris Van Damme - - * libtiff/tif_getimage.c: removed SubsamplingHor and SubsamplingVer - from _TIFFRGBAImage structure to revert unwanted ABI change. - -2007-08-10 Joris Van Damme - - * libtiff/tif_win32.c: use SetFilePointer instead of - SetFilePointerEx, as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1580 - -2007-07-19 Andrey Kiselev - - * libtiff/tif_stream.cxx: Put all callback functions declarations - inside extern "C" block. - - * libtiff/{tif_lzw.c, tif_luv.c, tif_dumpmode.c, tif_print.c, - tif_read.c, tif_strip.c, tif_thunder.c}: Use "%I64d" printf() - formatter instead of "%lld" with MSVC compiler. - - * libtiff/{tiffiop.h, tif_aux.c}: Added _TIFFUInt64ToFloat() and - _TIFFUInt64ToDouble() functions. - -2007-07-18 Andrey Kiselev - - * libtiff/tif_dirread.c: Handle the case of MSVC 6 when using 64-bit - integer constants. - - * libtiff/{Makefile.am, Makefile.v}: Do not distribute tiffconf.h, - remove tif_config.h/tiffconf.h during cleaning. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1573 - - * libtiff/tif_unix.c: Do not use O_LARGEFILE. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1577 - -2007-07-13 Andrey Kiselev - - * libtiff 4.0.0alpha released. - -2007-07-12 Andrey Kiselev - - * tools/tiff2pdf.c: Added missed extern optind as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1567 - - * libtiff/{tif_close.c, tif_dirinfo.c, tiffiop.c, tif_dirread.c, - tif_dir.h, tif_dir.c, tiffio.h}: Transition to the new-style tag - extending scheme completed. - -2007-07-11 Bob Friesenhahn - - * libtiff/tif_stream.cxx: Adapt to use toff_t again. Update to - use standard C++ library size types and attempt to detect overflow - cases. - -2007-07-08 Andrey Kiselev - - * libtiff/{tif_jpeg.c, tif_dir.h, tif_dir.c, tif_dirinfo.c, tiffio.h, - tif_ojpeg.c, tif_print.c, tif_fax3.c, tif_dirread.c}: More work on new - tag extending scheme. Use the new scheme everywhere. - - * libtiff/{tif_zip.c, tif_predict.c, tif_pixarlog.c, tif_luv.c, - tif_fax3.c, tif_dirread.c, tif_dirwrite.c, tif_close.c, tif_ojpeg.c, - tif_jpeg.c, tif_dirinfo.c, tif_dir.h, tiffio.h, tiffiop.h}: - TIFFFIeldInfo structure replaced with TIFFField structure. - TIFFFieldInfo retained for the backward compatibility. - -2007-07-05 Bob Friesenhahn - - * tools/tiff2pdf.c: Fix a compile problem when JPEG_SUPPORT is not - defined. - -2007-07-04 Andrey Kiselev - - * libtiff/{tif_dir.c, tiff.h, tiffio.h, libtiff.def}: Unused - TIFFReassignTagToIgnore() function and TIFFIgnoreSense enumeration - removed. - - * libtiff/{tif_dirinfo.c, tif_fax3.c, tif_jbig.c, tif_jpeg.c}: Move - tags TIFFTAG_FAXRECVPARAMS, TIFFTAG_FAXSUBADDRESS, - TIFFTAG_FAXRECVTIME and TIFFTAG_FAXDCS to the common tag directory. - These tags are not codec-specific and relate to image content, so - process them as other normal tags. - - * libtiff/{tiffio.h, tif_dir.h}: TIFFTagValue structure moved from the - public tiffio.h to private tif_dir.h. - - * contrib/{acorn, mac-cw, mac-mpw}: Removed as unmaintained and - outdated. - -2007-07-03 Andrey Kiselev - - * libtiff{tif_acorn.c, tif_apple.c, tif_atari.c, tif_msdos.c, - tif_win3.c}: Obsoleted portability stuff removed. - - * tools/tiff2ps.c: Added support 16-bit images as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1566 - - Patch from William Bader. - - * tools/tiff2pdf.c: Fix for TIFFTAG_JPEGTABLES tag fetching and - significant upgrade of the whole utility as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1560 - - Now we don't need tiffiop.h in tiff2pdf anymore and will open output - PDF file using TIFFClientOpen() machinery as it is implemented - by Leon Bottou. - -2007-06-26 Bob Friesenhahn - - * configure.ac: Fix typo when substituting value for unsigned 8 bit type. - Added support for a TIFF_PTRDIFF_T type to use when doing pointer arithmetic. - Added support for a TIFF_SSIZE_T in order to return memory sizes but still - allow returning -1 for errors. - * libtiff/tiffconf.vc.h: Add porting type defintions for WIN32. - -2007-06-25 Bob Friesenhahn - - * port/strtoull.c: New porting function in case strtoull() is not - available on the target system. - * configure.ac: Add configure support for determining sized types - in a portable way and performing necessary substitutions in - tif_config.h and tiffconf.h. Updated tiff.h to use the new - definitions. - -2007-04-27 Andrey Kiselev - - * tools/tiff2pdf.c: Check the tmpfile() return status as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=154 - -2007-04-07 Andrey Kiselev - - * libtiff/{tif_dir.h, tif_dirread.c, tif_dirinfo.c, tif_jpeg.c, - tif_fax3.c, tif_jbig.c, tif_luv.c, tif_ojpeg.c, tif_pixarlog.c, - tif_predict.c, tif_zip.c}: Finally fix bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1274 - - by introducing _TIFFMergeFieldInfo() returning integer error status - instead of void in case of problems with field merging (e.g., if the - field with such a tag already registered). TIFFMergeFieldInfo() in - public API remains void. Use _TIFFMergeFieldInfo() everywhere and - check returned value. - -2007-04-07 Frank Warmerdam - - * contrib/addtiffo/tif_overview.c: Fix problems with odd sized output - blocks in TIFF_DownSample_Subsampled() (bug 1542). - -2007-04-06 Frank Warmerdam - - * libtiff/tif_jpeg.c: Changed JPEGInitializeLibJPEG() so that it - will convert from decompressor to compressor or compress to decompress - if required by the force arguments. This works around a problem in - where the JPEGFixupTestSubsampling() may cause a decompressor to - be setup on a directory when later a compressor is required with the - force flag set. Occurs with the addtiffo program for instance. - -2007-04-06 Andrey Kiselev - - * tools/tiffcrop.c, man/tiffcrop.1: Significant update in - functionality from Richard Nolde. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1525 - -2007-03-28 Frank Warmerdam - - * libtiff/tif_fax3.c: "inline static" -> "static inline" for IRIC CC. - -2007-03-17 Joris Van Damme - - * start of BigTIFF upgrade - CVS HEAD unstable until further notice - -2007-03-07 Joris Van Damme - - * libtiff/tif_getimage.c: workaround for 'Fractional scanline' error reading - OJPEG images with rowsperstrip that is not a multiple of vertical subsampling - factor. This bug is mentioned in: - http://bugzilla.remotesensing.org/show_bug.cgi?id=1390 - http://www.asmail.be/msg0054766825.html - -2007-03-07 Joris Van Damme - - * libtiff/tif_win32.c: made inclusion of windows.h unconditional - - * libtiff/tif_win32.c: replaced preprocessor indication for consiously - unused arguments by standard C indication for the same - -2007-02-27 Andrey Kiselev - - * libtiff/tif_dirread.c: Use uint32 type instead of tsize_t in byte - counters in TIFFFetchData(). Should finally fix the issue - - http://bugzilla.remotesensing.org/show_bug.cgi?id=890 - -2007-02-24 Andrey Kiselev - - * tools/tiffset.c: Properly handle tags with TIFF_VARIABLE writecount. - As per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1350 - - * libtiff/tif_dirread.c: Added special function to handle - SubjectDistance EXIF tag as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1362 - - * tools/tiff2pdf.c: Do not assume inches when the resolution units - do not specified. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1366 - - * tools/{tiffcp.c, tiffcrop.c}: Do not change RowsPerStrip value if - it was set as infinite. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1368 - - * tools/tiffcrop.c, man/tiffcrop.1: New tiffcrop utility contributed - by Richard Nolde. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1383 - -2007-02-22 Andrey Kiselev - - * libtiff/tif_dir.c: Workaround for incorrect TIFFs with - ExtraSamples == 999 produced by Corel Draw. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1490 - - * libtiff/{tif_dirread.c, tif_read.c}: Type of the byte counters - changed from tsize_t to uint32 to be able to work with data arrays - larger than 2GB. Fixes bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=890 - - Idea submitted by Matt Hancher. - -2007-01-31 Andrey Kiselev - - * tools/tif2rgba.c: This utility does not work properly on big-endian - architectures. It was fixed including the bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1149 - -2007-01-15 Mateusz Loskot - - * Submitted libtiff port for Windows CE platform - * libtiff/tif_config.wince.h: Added configuration header for WinCE. - * libtiff/tiffconf.wince.h: Ported old configuration header for WinCE. - * libtiff/tif_wince.c: Added WinCE-specific implementation of some - functons from tif_win32.c. - * libtiff/tif_win32.c: Disabled some functions already reimplemented in tif_wince.c. - * libtiff/tiffiop.h, port/lfind.c: Added conditional include of some - standard header files for Windows CE build. - * tools/tiffinfoce.c: Ported tiffinfo utility for Windows CE. - -2006-11-19 Frank Warmerdam - - * libtiff/tif_write.c: TIFFAppendToStrip() - clear sorted flag if - we move a strip. - http://bugzilla.remotesensing.org/show_bug.cgi?id=1359 - -2006-10-13 Andrey Kiselev - - * libtiff/tif_dir.c: More fixes for vulnerabilities, reported - in Gentoo bug (): - - http://bugs.gentoo.org/show_bug.cgi?id=142383 - - * libtiff/contrib/dbs/xtiff/xtiff.c: Make xtiff utility compilable. - Though it is still far from the state of being working and useful. - -2006-10-12 Andrey Kiselev - - * libtiff/tif_fax3.c: Save the state of printdir codec dependent - method. - - * libtiff/tif_jpeg.c: Save the state of printdir codec dependent method - as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1273 - - * libtiff/tif_win32.c: Fixed problem with offset value manipulation - as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1322 - - * libtiff/{tif_read.c, tif_jpeg.c, tif_dir.c}: More fixes for - vulnerabilities, reported in Gentoo bug (): - - http://bugs.gentoo.org/show_bug.cgi?id=142383 - -2006-09-28 Andrey Kiselev - - * libtiff/{tif_fax3.c, tif_next.c, tif_pixarlog.c}: Fixed multiple - vulnerabilities, as per Gentoo bug (): - - http://bugs.gentoo.org/show_bug.cgi?id=142383 - -2006-09-27 Frank Warmerdam - - * libtiff/tif_lzw.c, libtiff/tif_zip.c: Fixed problems with mixing - encoding and decoding on the same read-write TIFF handle. The LZW - code can now maintain encode and decode state at the same time. The - ZIP code will switch back and forth as needed. - http://bugzilla.remotesensing.org/show_bug.cgi?id=757 - -2006-09-20 Frank Warmerdam - - * libtiff: Rename config.h.vc and tif_config.h.vc to config.vc.h and - tif_config.vc.h for easier identification by folks using an IDE. - -2006-07-25 Frank Warmerdam - - * tif_msdos.c: Avoid handle leak for failed opens. c/o Thierry Pierron - -2006-07-19 Frank Warmerdam - - * tif_dirwrite.c: take care not to flush out buffer of strip/tile - data in _TIFFWriteDirectory if TIFF_BEENWRITING not set. Relates - to bug report by Peng Gao with black strip at bottom of images. - -2006-07-12 Frank Warmerdam - - * tif_dirwrite.c: make sure to use uint32 for wordcount in - TIFFWriteNormanTag if writecount is VARIABLE2 for ASCII fields. - It already seems to have been done for other field types. Needed - for "tiffset" on files with geotiff ascii text. - -2006-07-04 Bob Friesenhahn - - * {configure.ac, libtiff/tif_config.h.vc, libtiff/tif_jbig.c} - (JBIGDecode): jbg_newlen is not available in older JBIG-KIT and - its use does not appear to be required, so use it only when it is - available. - -2006-06-24 Andrey Kiselev - - * libtiff/tif_dirinfo.c: Added missed EXIF tag ColorSpace (40961). - - * libtiff/tif_dirread.c: Move IFD fetching code in the separate - function TIFFFetchDirectory() avoiding code duplication in - TIFFReadDirectory() and TIFFReadCustomDirectory(). - -2006-06-19 Frank Warmerdam - - * tools/tiff2pdf.c: Fix handling of -q values. - http://bugzilla.remotesensing.org/show_bug.cgi?id=587 - -2006-06-17 Frank Warmerdam - - * tif_readdir.c: Added case in EstimateStripByteCounts() for tiled - files. Modified TIFFReadDirectory() to not invoke - EstimateStripByteCounts() for case where entry 0 and 1 are unequal - but one of them is zero. - http://bugzilla.remotesensing.org/show_bug.cgi?id=1204 - -2006-06-08 Andrey Kiselev - - * libtiff/{tif_open.c, tif_dirread.c, tiffiop.h}: Move IFD looping - checking code in the separate function TIFFCheckDirOffset(). - - * libtiff/tif_aux.c: Added _TIFFCheckRealloc() function. - - * tools/tiffcmp.c: Fixed floating point comparison logic as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1191 - - * libtiff/tif_fax3.c: Fixed problems in fax decoder as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1194 - - * tools/tiff2pdf.c: Fixed buffer overflow condition in - t2p_write_pdf_string() as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1196 - -2006-06-07 Andrey Kiselev - - * {configure, configure.ac, libtiff/tif_jbig.c, tools/tiffcp.c}: Added - support for JBIG compression scheme (34661 code) contributed by Lee - Howard. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=896 - - * configure, configure.ac: OJPEG support enabled by default. - - * contrib/ojpeg/: Removed. New OJPEG support does not need this patch. - -2006-06-03 Bob Friesenhahn - - * libtiff/{tif_dirinfo.c, tif_print.c} : Fix crash in - TIFFPrintDirectory(). Joris Van Damme authored the fix. - -2006-04-21 Andrey Kiselev - - * tools/tiff2pdf.c: Unified line ending characters (always use '\n') - as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1163 - - * README.vms, Makefile.am, configure.com, libtiff/{Makefile.am, - tif_config.h-vms, tif_stream.cxx, tif_vms.c, tiffconf.h-vms}: - Added support for OpenVMS by Alexey Chupahin, elvis_75@mail.ru. - -2006-04-20 Andrey Kiselev - - * tools/{fax2ps.c, fax2tiff.c, ppm2tiff.c, ras2tiff.c, tiff2pdf.c}: - Properly set the binary mode for stdin stream as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1141 - - * man/{bmp2tiff.1, fax2ps.1, fax2tiff.1, gif2tiff.1, ras2tiff.1, - raw2tiff.1, rgb2ycbcr.1, sgi2tiff.1, tiff2bw.1, tiff2pdf.1, tiff2ps.1, - tiff2rgba.1, tiffcmp.1, tiffcp.1, tiffdither.1, tiffdump.1, tiffgt.1, - tiffset.1}: Improvements in page formatting as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1140 - - * html/tools.html, html/man/Makefile.am, tools/tiff2pdf.c: Fixed - typos as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1139 - -2006-04-18 Frank Warmerdam - - * nmake.opt: use /EHsc for VS2005 compatibility. Also define - _CRT_SECURE_NO_DEPRECATE to avoid noise on VS2005. - -2006-04-12 Joris Van Damme - - * libtiff/tif_getimage.c: Added support for planarconfig separate - non-subsampled YCbCr (i.e. separate YCbCr with subsampling [1,1]) - -2006-04-11 Joris Van Damme - - * libtiff/tif_getimage.c: Revision of all RGB(A) put routines - - Conversion of unassociated alpha to associated alpha now done with - more performant LUT, and calculation more correct - - Conversion of 16bit data to 8bit data now done with - more performant LUT, and calculation more correct - - Bugfix of handling of 16bit RGB with unassociated alpha - -2006-04-11 Joris Van Damme - - * libtiff/tif_getimage.c: - - When there is no alpha, gtTileSeparate and gtStripSeparate allocated - buffer for alpha strile and filled it, only to never read it back. - Removed allocation and fill. - - Minor rename of vars in gtTileSeparate and gtStripSeparate - anticipating planned functionality extension - -2006-04-08 Joris Van Damme - - * libtiff/tif_getimage.c: renamed pickTileContigCase to PickContigCase - and pickTileSeparateCase to PickSeparateCase as both work on strips as - well - - * libtiff/tif_getimage.c: moved img->get selection from - TIFFRGBAImageBegin into PickContigCase and PickSeparateCase to create - logical hook for planned functionality extension - -2006-04-08 Joris Van Damme - - * libtiff/tif_ojpeg.c: resolved memory leak that was a consequence - of inappropriate use of jpeg_abort instead of jpeg_destroy - -2006-04-07 Joris Van Damme - - * libtiff/tif_getimage.c: replaced usage of TIFFScanlineSize in - gtStripContig with TIFFNewScanlineSize so as to fix buggy behaviour - on subsampled images - this ought to get sorted when we feel brave - enough to replace TIFFScanlineSize alltogether - - * libtiff/tif_ojpeg.c: fixed bug in OJPEGReadSkip - -2006-04-04 Joris Van Damme - - * libtiff/tiffio.h: added new type tstrile_t - - * libtiff/tif_dir.h: changed types of td_stripsperimage and td_nstrips - to new tstrile_t, types of td_stripoffset and td_stripbytecount to - toff_t* - - * libtiff/tif_ojpeg.c: totally new implementation - - * libtiff/tif_dirread.c: added several hacks to suit new support of - OJPEG - - * libtiff/tif_getimage.c: removed TIFFTAG_JPEGCOLORMODE handling - of OJPEG images in favor of tif_getimage.c native handling of - YCbCr and desubsampling - -2006-03-29 Frank Warmerdam - - * libtiff/tif_jpeg.c: JPEGVSetField() so that altering the photometric - interpretation causes the "upsampled" flag to be recomputed. Fixes - peculiar bug where photometric flag had to be set before jpegcolormode - flag. - -2006-03-25 Joris Van Damme - - * libtiff/tif_jpeg.c: strip size related bugfix in encode raw - - * libtiff/tif_strip.c: temporarilly added two new versions of - TIFFScanlineSize - - TIFFNewScanlineSize: proposed new version, after all related - issues and side-effects are sorted out - - TIFFOldScanlineSize: old version, from prior to 2006-03-21 change - This needs further sorting out. - -2006-03-25 Joris Van Damme - - * contrib/addtiffo/tif_ovrcache.c: bugfix to correctly pass size - of last truncated strip data to TIFFWriteEncodedStrip - -2006-03-25 Joris Van Damme - - * libtiff/{tif_jpeg.c, tif_strip.c}: bugfix of tif_jpeg decode raw - -2006-03-25 Joris Van Damme - - * libtiff/tif_getimage.c: bugfix/rewrite of putcontig8bitYCbCr22tile - - * libtiff/tif_getimage.c: added putcontig8bitYCbCr12tile - - * libtiff/tif_read.c: added support for new TIFF_NOREADRAW flag to - prepare the path for new tif_ojpeg.c - -2006-03-23 Andrey Kiselev - - * libtiff 3.8.2 released. - - * tools/Makefile.am: Use runtime paths linker flags when rpath - option enabled. - -2006-03-21 Andrey Kiselev - - * libtiff/libtiff.def: Added missed exports as per bug - http://bugzilla.remotesensing.org/attachment.cgi?id=337 - - * contrib/addtiffo/Makefile.vc, libtiff/Makefile.vc, port/Makefile.vc, - tools/Makefile.vc: Makefiles improvements as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1128 - - * nmake.opt libtiff/{tif_config.h.vc, tif_unix.c, tiffio.h}, - tools/{fax2ps.c, fax2tiff.c, tiff2pdf.c}: Fixed win32 I/O functions - usage as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1127 - - * libtiff/tif_strip.c: Take subsampling in account when calculating - TIFFScanlineSize(). - - * tools/tiffcp.c: Do not set RowsPerStrip bigger than image length. - -2006-03-17 Andrey Kiselev - - * tools/fax2tiff.c: Fixed wrong TIFFerror() invocations as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1125 - - * tools/fax2ps.c: Fixed reading the input stream from stdin as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1124 - -2006-03-16 Andrey Kiselev - - * libtiff/tiffiop.h: Added decalration for - _TIFFSetDefaultCompressionState(). - - * libtiff/{tif_jpeg.c, tif_fax3.c, tif_zip.c, tif_pixarlog.c, - tif_lzw.c, tif_luv.c}: Use _TIFFSetDefaultCompressionState() in all - codec cleanup methods. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1120 - -2006-03-15 Andrey Kiselev - - * libtiff/tif_jpeg.c: Do not cleanup codec state in TIFFInitJPEG(). As - per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1119 - - * tools/raw2tiff.c: Do not set RowsPerStrip larger than ImageLength. - As per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1110 - - * libtiff/tiffiop.h: dblparam_t typedef removed; GLOBALDATA macro - removed; move here the STRIP_SIZE_DEFAULT macro definition. - - * libtiff/{tif_dirread.c, tif_strip.c}: Removed STRIP_SIZE_DEFAULT - macro definition. - - * libtiff/tif_dir.c: Use double type instead of dblparam_t. - -2006-03-14 Andrey Kiselev - - * libtiff/tif_dirread.c: Do not check the PlanarConfig tag presence - in TIFFReadDirectory, because it is always set at the start of - function and we allow TIFFs without that tag set. - -2005-03-13 Andrey Kiselev - - * libtiff 3.8.1 released. - -2006-03-07 Andrey Kiselev - - * libtiff/tif_dirread.c: Fixed error reporting in TIFFFetchAnyArray() - function as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 - - * libtiff/tif_dirread.c: More wise check for integer overflow - condition as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 - - * libtiff/{tif_jpeg.c, tif_pixarlog.c, tif_fax3.c, tif_zip.c}: - Properly restore setfield/getfield methods in cleanup functions. As - per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 - -2006-03-03 Andrey Kiselev - - * libtiff/{tif_predict.c, tif_predict.h}: Added new function - TIFFPredictorCleanup() to restore parent decode/encode/field methods. - - * libtiff/{tif_lzw.c, tif_pixarlog.c, tif_zip.c}: Use - TIFFPredictorCleanup() in codec cleanup methods. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 - - * libtiff/tif_dirread.c: Fixed integer overflow condition in - TIFFFetchData() function. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 - -2006-03-01 Andrey Kiselev - - * libtiff/tif_ojpeg.c: Set the ReferenceBlackWhite with the - TIFFSetField() method, not directly. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1043 - - * tools/ppm2tiff.c: Added support for PBM files as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1044 - -2006-02-27 Andrey Kiselev - - * libtiff/tif_write.c: Small code rearrangement in TIFFWriteScanline() - to avoid crash as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1081. - -2006-02-26 Andrey Kiselev - - * tools/tiff2pdf.c: Functions t2p_sample_rgbaa_to_rgb() and - t2p_sample_rgba_to_rgb() was used in place of each other, that was - resulted in problems with RGBA images with associated alpha. - As per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1097 - -2006-02-23 Andrey Kiselev - - * libtiff/tif_dirwrite.c: Properly write TIFFTAG_DOTRANGE tag as per - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1088. - - * libtiff/tif_print.c: Properly read TIFFTAG_PAGENUMBER, - TIFFTAG_HALFTONEHINTS, TIFFTAG_YCBCRSUBSAMPLING and TIFFTAG_DOTRANGE - tags as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1088. - - * tools/tiff2ps.c: Properly scale all the pages when converting - multipage TIFF with /width/height/center options set. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1080 - -2006-02-15 Andrey Kiselev - - * tools/tiff2pdf.c: Do not create output file until all option checks - will be done. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1072 - - * tools/bmp2tiff.c: Added ability to create multipage TIFFs from the - list of input files as per bug: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1077 - -2006-02-09 Andrey Kiselev - - * libtiff/tif_tile.c: Fix error reporting in TIFFCheckTile() as per - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1063. - - * tools/tiffgt.c: Avoid crashing in case of image unsupported by - TIFFRGBAImage interface. - - * libtiff/tif_color.c: Avoid overflow in case of wrong input as per - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1065. - -2006-02-07 Frank Warmerdam - - * tools/tiff2pdf.c: Fixed support for non-YCbCr encoded JPEG - compressed TIFF files, per submission from Dan Cobra. - -2006-02-07 Andrey Kiselev - - * libtiff/{tif_dirread.c, tif_packbits.c, tif_win32.c}: Properly - cast values to avoid warnings. As per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1033. - - * libtiff/tif_dirinfo.c: Use TIFF_NOTYPE instead of 0 when - appropriate. As per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1033. - - * libtiff/tif_aux.c: Fixed type of temporary variable in - _TIFFCheckMalloc() as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=1033. - -2006-02-06 Andrey Kiselev - - * libtiff/tif_aux.c: Return static array when fetching default - YCbCrCoefficients (another problem, reported a the - http://bugzilla.remotesensing.org/show_bug.cgi?id=1029 entry). - -2006-02-03 Andrey Kiselev - - * libtiff/tif_dir.c: Special handling for PageNumber, HalftoneHints, - YCbCrSubsampling and DotRange tags as per bugs - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1029 - http://bugzilla.remotesensing.org/show_bug.cgi?id=1034 - - * libtiff/tif_dirread.c: Use _TIFFGetExifFieldInfo() instead of - _TIFFGetFieldInfo() in TIFFReadEXIFDirectory() call as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1026. - -2006-01-23 Andrey Kiselev - - * libtool related stuff updated from the 2.1a branch. - -2006-01-11 Frank Warmerdam - - * tools/bmp2tiff,pal2rgb,ppm2tiff,ras2tiff,raw2tiff,sgi2tiff, - tiff2bw,tiffcp: Fixed jpeg option processing so -c jpeg:r:50 works - properly as per bug: - http://bugzilla.remotesensing.org/show_bug.cgi?id=1025 - -2006-01-09 Bob Friesenhahn - - * configure.ac: Fix with_default_strip_size comparison as reported - by Norihiko Murase. - -2006-01-08 Bob Friesenhahn - - * test/Makefile.am (LIBTIFF): Due to linking against libtiff - incorrectly, tests were not actually testing the uninstalled - libtiff. Now they are. - -2006-01-04 Andrey Kiselev - - * libtiff/tif_dirinfo.c: Change definitions for TIFFTAG_ICCPROFILE, - TIFFTAG_PHOTOSHOP, TIFFTAG_RICHTIFFIPTC, TIFFTAG_XMLPACKET: readcount - should be uint32 value. - -2006-01-02 Bob Friesenhahn - - * html/man/Makefile.am (htmldoc): Fix htmldoc rule so that it can - be used if build directory is not the same as source directory. - * man/{TIFFGetField.3tiff, TIFFSetField.3tiff}: Documented - TIFFTAG_PHOTOSHOP, TIFFTAG_RICHTIFFIPTC, and TIFFTAG_XMLPACKET, - and re-sorted tag names in alphabetical order. - -2005-12-29 Andrey Kiselev - - * libtiff 3.8.0 released. - -2005-12-28 Bob Friesenhahn - - * tools/bmp2tiff.c (main): Fixed warning regarding returning - inconsistent types from a condition. - * tools/tiffcmp.c (CheckLongTag): Eliminate warning due to printf - format. - * tools/bmp2tiff.c: Reduce compilation warnings on big-endian CPUs. - -2005-12-28 Joris Van Damme - - * html/{index.html, support.hml, libtiff.html}: Cleaned up HTML - -2005-12-27 Andrey Kiselev - - * libtiff/tiffio.h: Added VC_EXTRALEAN definition before including - windows.h, to reduce the compile time. - -2005-12-26 Bob Friesenhahn - - * libtiff/tif_jpeg.c: Improve compilation under MinGW. - -2005-12-26 Andrey Kiselev - - * libtiff/{tif_dir.c, tif_dir.h, tif_dirread.c, tif_dirinfo.c}: - tiffFieldInfo and exifFieldInfo arrays definitions moved back to - tif_dirinfo.c; added _TIFFGetFieldInfo() and _TIFFGetExifFieldInfo() - private functions to retrieve FieldInfo arrays. - -2005-12-24 Bob Friesenhahn - - * html/build.html: Added some additional instructions for when - building using MSVC under Windows. Also fixed two HTML syntax - errors and used HTML Tidy to tidy up the HTML syntax and - formatting. - -2005-12-24 Andrey Kiselev - - * libtiff/{tif_aux.c, tif_dir.c, tif_dir.h, tif_dirwrite.c, - tif_print.c, tif_getimage.c}: Make InkSet, NumberOfInks, DotRange and - StoNits tags custom. - -2005-12-23 Andrey Kiselev - - * libtiff/{tif_aux.c, tif_dir.c, tif_dir.h, tif_print.c}: Make - WhitePoint tag custom. - - * libtiff/{tif_dir.h, tiff.h}: More EXIF tags added. - -2005-12-23 Joris Van Damme - - * libtiff/tiffio.h: fixed typo that potentially resulted in - redefininition of USE_WIN32_FILEIO - - * libtiff/*: Added more 'dual-mode' error handling: Done TIFFWarning - calls in core LibTiff. - -2005-12-21 Andrey Kiselev - - * libtiff/{tif_dir.c, tif_dir.h, tif_print.c}: Make RichTIFFIPTC, - Photoshop and ICCProfile tags custom. - -2005-12-21 Joris Van Damme - - * libtiff/*, contrib/*: Added 'dual-mode' error handling, enabling - newer code to get context indicator in error handler and still - remain compatible with older code: Done TIFFError calls everywhere - except in tools - -2005-12-20 Andrey Kiselev - - * tools/tiffcp.c: Added many error reporting messages; fixed integer - overflow as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=789 - -2005-12-16 Frank Warmerdam - - * contrib/addtiffo/*: Major upgrade by Joris to support subsampled - YCbCr images in jpeg compressed TIFF files. - -2005-12-14 Andrey Kiselev - - * tools/tiffcp.c: Return non-zero status when reading fails (again). - -2005-12-13 Andrey Kiselev - - * tools/tiffcp.c: Return non-zero status when reading fails. - -2005-12-12 Andrey Kiselev - - * libtiff/{tif_dir.h, tiff.h}: Added more EXIF tags. - -2005-12-09 Andrey Kiselev - - * libtiff/{tif_dir.c, tif_dir.h, tif_print.c}: Make XMLPacket tag - custom. - - * tools/tiffinfo.c: Print EXIF directory contents if exist. - - * libtiff/tiff.h: Few EXIF tag numbers added. - - * libtiff/{tif_dirinfo.c, tif_dirread.c, tif_dir.h, tif_dir.c, - tiffio.h}: Preliminary support to read custom directories. New - functions: TIFFReadCustomDirectory() and TIFFReadEXIFDirectory(). - -2005-12-07 Andrey Kiselev - - * libtiff/{tif_dirinfo.c, tif_dirread.c, tif_dir.h, tif_dir.c}: - More work to implement custom directory read support. - - * libtiff/{tif_aux.c, tif_dirinfo.c, tif_dirread.c, tif_dir.h, - tif_dir.c, tif_print.c}: Make YCbCrCoefficients and ReferenceBlackWhite - tags custom. - -2005-12-05 Andrey Kiselev - - * libtiff/tif_dirread.c: One more workaround for broken - StripByteCounts tag. Handle the case when StripByteCounts array filled - with completely wrong values. - -2005-11-30 Andrey Kiselev - - * libtiff/tif_dirinfo.c: Release file descriptor in case of failure - in the TIFFOpenW() function as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1003 - - * libtiff/tif_dirinfo.c: Correctly yse bsearch() and lfind() - functions as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=1008 - -2005-11-20 Frank Warmerdam - - * tif_open.c, tiff.h, tiffdump.c: Incorporate preliminary support - for MS MDI format. - http://bugzilla.remotesensing.org/show_bug.cgi?id=1002 - - * .cvsignore: many files added, and a few update according - to suggestion of Brad HArds on tiff mailing list. - -2005-11-03 Frank Warmerdam - - * libtiff/libtiff.def, tiffiop.h, tiffio.h: Made TIFFFreeDirectory - public. - -2005-10-31 Andrey Kiselev - - * tools/fax2tiff.c: Properly calculate sizes of temporary arrays - as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=943 - - * tools/fax2tiff.c: Added option '-r' to set RowsPerStrip parameter - as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=944 - - * tools/tiffdump.c: Fixed typeshift and typemask arrays initialization - problem as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=946 - - * tools/bmp2tiff.c: Fixed possible integer overflow error as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=965 - - * libtiff/tif_dirinfo.c: Make XResolution, YResolution and - ResolutionUnit tags modifiable during write process. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=977 - - * tools/tiffsplit.c: Copy fax related fields over splitted parts - as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=983 - -2005-10-21 Frank Warmerdam - - * tif_dirread.c: Don't try and split single strips into "0" strips - in ChopUpSingleUncompressedStrip. This happens in some degenerate - cases (like 1x1 files with stripbytecounts==0 (gtsmall.jp2 embed tiff) - -2005-10-20 Joris Van Damme - - * tif_fax3.c: changed 'at scanline ...' style warning/errors - with incorrect use of tif_row, to 'at line ... of - strip/tile ...' style - -2005-10-15 Frank Warmerdam - - * tif_write.c: fixed setting of planarconfig as per bug report - on the mailing list from Joris. - -2005-10-07 Andrey Kiselev - - * configure.ac, configure, nmake.opt, libtiff/{tif_config.h, - tif_dirread.c}: Make the default strip size configurable via the - --with-default-strip-size and STRIP_SIZE_DEFAULT options. - -2005-09-30 Bob Friesenhahn - - * html/support.html: Fixed link to documentation on Greg Ward's - LogLuv TIFF format. - -2005-09-28 Andrey Kiselev - - * tools/tiffdump.c: Fixed crash when reading malformed tags. - -2005-09-20 Andrey Kiselev - - * tools/tiff2pdf.c: Added missed 'break' statement as per bug - http://bugzilla.remotesensing.org/show_bug.cgi?id=932 - -2005-09-12 Andrey Kiselev - - * libtiff 3.7.4 released. - - * {configure, configure.ac, Makefile.am, autogen.sh}: Applied patch - from Patrick Welche (all scripts moved in the 'config' and 'm4' - directories). - -2005-09-12 Frank Warmerdam - - * libtiff/tif_open.c: reintroduce seek to avoid problem on solaris. - -2005-09-05 Frank Warmerdam - - * libtiff/tif_dir.c: When prefreeing tv->value in TIFFSetFieldV - also set it to NULL to avoid double free when re-setting custom - string fields as per: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=922 - -2005-08-12 Frank Warmerdam - - * libtiff/tif_print.c: avoid signed/unsigned warning. - - * libtiff/tif_dirread.c: removed unused variable. - -2005-07-30 Frank Warmerdam - - * libtiff/tif_dir.c: Fixed up support for swapping "double complex" - values (128 bits as 2 64 bits doubles). GDAL gcore tests now - pass on bigendian (macosx) system. - -2005-07-28 Andrey Kiselev - - * libtiff/{tif_aux.c, tif_dirread.c, tif_fax3.c, tiffiop.h}: Rename - CheckMalloc() function to _TIFFCheckMalloc() and make it available - globally as an internal helper routine. - -2005-07-27 Andrey Kiselev - - * libtiff/tif_dir.c: More improvements in the "pass by value" part of - the custom tags handling code. - -2005-07-26 Andrey Kiselev - - * libtiff/{tif_dirread.c, tif_dirinfo.c}: Do not upcast BYTEs to - SHORTs in the TIFFFetchByteArray(). Remove TIFFFetchExtraSamples() - function, use TIFFFetchNormalTag() instead as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=831 - - Remove TIFFFetchExtraSamples() function, use TIFFFetchNormalTag() - instead. - - * libtiff/tiffconf.h.in: One more attempt to fix the AIX bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=39 - -2005-07-25 Andrey Kiselev - - * libtiff/tif_print.c: Fixed printing of the BYTE and SBYTE arrays. - - * tools/tiffdump.c: Added support for TIFF_IFD datatype. - -2005-07-21 Andrey Kiselev - - * libtiff/tif_write.c: Do not check the PlanarConfiguration field in - the TIFFWriteCheck() function in case of single band images (as per - TIFF spec). - -2005-07-12 Andrey Kiselev - - * SConstruct, libtiff/SConstruct: Added the first very preliminary - support for SCons software building tool (http://www.scons.org/). - This is experimental infrastructure and it will exist along with the - autotools mechanics. - -2005-07-07 Andrey Kiselev - - * port/{getopt.c, strcasecmp.c, strtoul.c}: Update modules from - the NetBSD source tree (the old 4-clause BSD license changed to - the new 3-clause one). - - * configure.ac, port/lfind.c, libtiff/tiffiop.h: Added lfind() - replacement module. - - * port/dummy.c: Make the dummy function static. - -2005-07-06 Andrey Kiselev - - * tools/tiffcp.c: Fixed WhitePoint tag copying. - - * libtiff/{tif_dir.c, tif_dir.h, tif_dirinfo.c, tif_print.c}: - Make FieldOfViewCotangent, MatrixWorldToScreen, MatrixWorldToCamera, - ImageFullWidth, ImageFullLength and PrimaryChromaticities tags custom. - -2005-07-04 Andrey Kiselev - - * libtiff 3.7.3 released. - - * configure, configure.ac: Do not use empty -R option when linking - with --enable-rpath. - -2005-07-01 Andrey Kiselev - - * libtiff/{tiffiop.h, tif_open.c}: Added open option 'h' to avoid - reading the first IFD when needed. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=875 - - * libtiff/tif_color.c: Better use of TIFFmin() macro to avoid side - effects. - -2005-06-23 Andrey Kiselev - - * tools/tiff2pdf.c: Print two characters per loop in the - t2p_write_pdf_trailer(). As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=594 - - * tools/tiffgt.c: Use MacOS X OpenGL framework when appropriate. As - per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=844 - - * acinclude.m4: Updated to latest OpenGL test macros versions. - - * libtiff/tiff.h: Use correct int size on Sparc 64bit/Sun compiler - platform. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=855 - -2005-06-14 Andrey Kiselev - - * libtiff/tif_dirinfo.c: Added support for ClipPath, XClipPathUnits - and YClipPathUnits tags. - -2005-06-07 Andrey Kiselev - - * contrib/addtiffo/tif_ovrcache.c: Properly extract tile/strip size; - use pixel sized shift in contigous case. - -2005-06-06 Andrey Kiselev - - * contrib/addtiffo/{tif_overview.c, tif_ovrcache.c, tif_ovrcache.h}: - Make overviews working for contiguos images. - -2005-06-03 Andrey Kiselev - - * libtiff/tif_open.c: Replace runtime endianess check with the compile - time one. - - * libtiff/tif_predict.c: Floating point predictor now works on - big-endian hosts. - -2005-06-01 Andrey Kiselev - - * libtiff/tif_dir.c: Use _TIFFsetString() function when read custom - ASCII values. - - * libtiff/{tif_dirinfo.c, tif_dir.h, tif_dir.c, tif_print.c}: Make - DocumentName, Artist, HostComputer, ImageDescription, Make, Model, - Copyright, DateTime, PageName, TextureFormat, TextureWrapModes and - TargetPrinter tags custom. - - * libtiff/tif_jpeg.c: Cleanup the codec state depending on - TIFF_CODERSETUP flag (to fix memry leaks). - - * libtiff/tif_jpeg.c: Initialize JPEGTables array with zero after - allocating. - -2005-05-26 Andrey Kiselev - - * configure.ac, libtiff/Makefile.am: Added workaround for - OpenBSD/MirOS soname problem as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=838 - - * libtiff/tif_dirwrite.c: Use tdir_count when calling - TIFFCvtNativeToIEEEDouble() in the TIFFWriteDoubleArray() function as - per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=845 - -2005-05-25 Andrey Kiselev - - * tools/ppm2tiff.c: Fixed format string when read PPM file header with - the fscanf() function. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=861 - - * libtiff/{tif_dirinfo.c, tif_print.c}: TIFFFetchByteArray() returns - uint16 array when fetching the BYTE and SBYTE filds, so we should - consider result as pointer to uint16 array and not as array of chars. - As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=831 - - * libtiff/tif_dir.c: More efficient custom tags retrieval as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=830 - - * libtiff/tif_win32.c: Use FILE_SHARE_READ | FILE_SHARE_WRITE share - mode in CreateFile() call as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=829 - - * libtiff/Makefile.am: Fixed parallel compilation of the libtiff and - libtiffxx libraries as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=826 - - * contrib/addtiffo/{tif_overview.c, tif_ovrcache.h}: Sinchronized with - GDAL. - -2005-05-23 Frank Warmerdam - - * libtiff/tif_jpeg.c: Substantial fix for addtiffo problems with - JPEG encoded TIFF files. Pre-allocate lots of space for jpegtables - in directory. - -2005-05-22 Frank Warmerdam - - * libtiff/tif_dirread.c: Changed the code that computes - stripbytecount[0] if it appears bogus to ignore if stripoffset[0] is - zero. This is a common case with GDAL indicating a "null" tile/strip. - -2005-05-17 Andrey Kiselev - - * tools/tiffsplit.c: Check for JPEGTables tag presence before copying. - -2005-05-06 Frank Warmerdam - - * libtiff/tif_dirread.c: Applied similar change to - TIFFFetchPerSampleLongs and TIFFFetchPerSampleAnys. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=843 - - * libtiff/tif_jpeg.c: added LIB_JPEG_MK1 support in JPEGDecodeRaw(). - -2005-05-06 Andrey Kiselev - * tools/tiff2pdfr.c, man/tiff2pdf.1: Calculate the tile width properly; - added new option '-b' to use interpolation in output PDF files (Bruno - Ledoux). - -2005-05-05 Frank Warmerdam - - * libtiff/tif_dirread.c: Ensure that broken files with too many - values in PerSampleShorts work ok instead of crashing. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=843 - -2005-04-27 Andrey Kiselev - - * tools/tiffdither.c: Copy the PhotometricInterpretation tag from the - input file. - -2005-04-15 Andrey Kiselev - - * libtiff/tif_predict.c: Added ability to encode floating point - predictor, as per TIFF Technical Note 3. - -2005-04-14 Andrey Kiselev - - * libtiff/{tif_predict.h, tif_predict.c}: Added ability to decode - floating point predictor, as per TIFF Technical Note 3. - -2005-04-13 Andrey Kiselev - - * libtiff/{tiffio.h, tiffiop.h, tif_dir.c, tif_read.c, tif_swab.c}: - Added _TIFFSwab24BitData() and TIFFSwabArrayOfLong() functions used to - swap 24-bit floating point values. - - * libtiff/tiff.h: Added predictor constants. - -2005-04-08 Andrey Kiselev - - * libtiff/{tiffiop.h, tif_dir.c}: Use uint32 type for appropriate - values in _TIFFVSetField() function. Inspired by the bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=816 - - * man/TIFFSetField.3tiff: Fixed definition of the TIFFTAG_INKNAMES tag - as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=816 - -2005-03-30 Andrey Kiselev - - * libtiff/tif_open.c: Do not read header in case the output file - should be truncated (Ron). - - * libtiff/{tif_dirinfo.c, tif_config.h.vc}: Use lfind() instead - of bsearch() in _TIFFFindFieldInfoByName() function (Ron). - - * libtiff/{tiff.h, tif_dirinfo.c}: Fixes in EXIF tag ordering (Ron). - -2005-03-22 Andrey Kiselev - - * configure.ac, libtiff/Makefile.am: Use libtool machinery to pass - rpath option. - -2005-03-21 Andrey Kiselev - - * libtiff/{tif_dir.c, tif_print.c}: Handle all data types in custom - tags. - -2005-03-18 Andrey Kiselev - - * libtiff/dirinfo.c: Added DNG tags. - - * libtiff/{tif_dir.c, tif_print.c}: More improvements in custom tag - handling code. - - * libtiff/tiff.h: More comments; added missed DNG tag (LensInfo); - added DNG 1.1.0.0 tags. - - * tools/tif2pdf.c: Fixed problem with alpha channel handling as per - bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=794 - - * man/TIFFGetField.3tiff: Add a note about autoregistered tags. - -2005-03-17 Andrey Kiselev - - * nmake.opt: Build with Win32 CRT library by default. - - * tools/tiff2ps.c: Fixed typo in page size handling code. - - * libtiff/{tif_dir.c, tif_print.c}: Support for custom tags, passed - by value. - - * libtiff/{tiff.h, tif_dirinfo.c, tiffiop.h}: Added EXIF related tags. - -2005-03-15 Andrey Kiselev - - * libtiff 3.7.2 released. - -2005-03-09 Andrey Kiselev - - * tools/tiffcmp.c: Added ability to compare the 32-bit integer and - floating point data; complain on unsupported bit depths. - -2005-03-05 Andrey Kiselev - - * tif_stream.cxx: Use ios namespace instead of ios_base to support - GCC 2.95. - - * libtiff/{tiff.h, tif_fax3.tif, tif_jpeg.c}: Applied correct patch from - Lee Howard for HylaFax DCS tag - (see http://bugzilla.remotesensing.org/show_bug.cgi?id=771) - -2005-03-04 Andrey Kiselev - - * configure, configure.ac: Use -rpath option instead of -R as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=732 - - * libtiff/{tiff.h, tif_fax3.tif, tif_jpeg.c}: Applied patch from Lee - Howard to support a new tag TIFFTAG_FAXDCS (34911) used in HylaFax - software. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=771 - - * nmake.opt, html/build.html: Add more comments, change the config - file organization a bit as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=764 - - * tools/tiffcmp.c: Use properly sized buffer in short arrays comparison - as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=785 - -2005-03-03 Andrey Kiselev - - * libtiff/tif_dirread.c: More logic to guess missed strip size as per - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=705 - - * tools/fax2ps.c: Replace insecure mktemp() function with the - tmpfile() as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=786 - -2005-02-04 Andrey Kiselev - - * libtiff/tiff.h: Changed the int8 definition to be always signed char - as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=727 - - * libtiff/tiffio.h: Move TIFFOpenW() function into the extern "C"{} - block as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=763 - -2005-02-03 Bob Friesenhahn - - * tools/tiffgt.c: Fix problem on big-endian CPUs so that images - display more correctly. Images display brighter than they should - on a Sun workstation. - -2005-02-03 Andrey Kiselev - - * libtiff/tif_dirread.c: Estimate strip size in case of wrong or - suspicious values in the tags. As per bugs - - http://bugzilla.remotesensing.org/show_bug.cgi?id=705 - - and - - http://bugzilla.remotesensing.org/show_bug.cgi?id=320 - - * tools/tiff2ps.c: Fixed problem with page sizes as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=742 - -2005-01-31 Bob Friesenhahn - - * libtiff/tiff.h (TIFFTAG_TILEWIDTH): Corrected description. - (TIFFTAG_TILELENGTH): Corrected description. - -2005-01-30 Andrey Kiselev - - * configure.ac: Fixes for --with-docdir option as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=759 - - * libtiff/tif_open.c: Remove unnesessary TIFFSeekFile() call as per - bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=756 - - * libtiff/tif_stream.cxx: Fixes for C++ stream interface from - Michael Rinne and Edward Lam. - -2005-01-15 Andrey Kiselev - - * configure.ac: Make the documentation directory location configurable - via the --with-docdir option (as suggested by Jeremy C. Reed). - - * libtiff/tif_color.c: Use double as the second argument of pow() - function in TIFFCIELabToRGBInit(). As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=741 - - * libtiff/tif_pixarlog.c: Avoid warnings when converting float to - integer as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=740 - - * libtiff/tif_getimage.c: Always fill the error message buffer in - TIFFRGBAImageBegin() as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=739 - -2005-01-12 Andrey Kiselev - - * libtiff/tif_jpeg.c: Added ability to read/write the fax specific - TIFFTAG_FAXRECVPARAMS, TIFFTAG_FAXSUBADDRESS and TIFFTAG_FAXRECVTIME - tags as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=736 - - * libtiff/tif_win32.c: Fixed message formatting in functions - Win32WarningHandler() and Win32ErrorHandler() as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=735 - - * tools/tiff2ps.c: Interpret the -w and -h options independently. As - per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=689 - -2005-01-11 Andrey Kiselev - - * libtiff/tiffio.h: Move the color conversion routines in the 'extern - "C"' section as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=727 - - * libtiff/tiff.h: Restore back the workaround for AIX Visual Age C - compiler to avoid double definition of BSD types as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=39 - - * libtiff/Makefile.am: Place the C++ stream API in the separate - library called libtiffxx to avoid unneeded dependencies. Probably - there will be more C++ API in the future. As per bugs - - http://bugzilla.remotesensing.org/show_bug.cgi?id=733 - - and - - http://bugzilla.remotesensing.org/show_bug.cgi?id=730 - -2005-01-05 Andrey Kiselev - - * tools/tiffdump.c: Fixed problem when read broken TIFFs with the - wrong tag counts (Dmitry V. Levin, Martin Pitt). - - * configure.ac: Replace --disable-c++ with the --disable-cxx option as - per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=730 - -2004-12-25 Andrey Kiselev - - * libtiff/tif_getimage.c: More fixes for multiple-alpha-channelled - RGB-images as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=713 - - - * tools/tiffset.c: Convert character option to integer value as per - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=725 - -2004-12-20 Andrey Kiselev - - * libtiff 3.7.1 released. - - * html/tiffset.1.html: Add missed manual page as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=678 - - * libtiff/tiff.h: Revert back libtiff data type definitions as per - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=687 - -2004-12-19 Andrey Kiselev - - * libtiff/tif_dirread.c: Do not forget about TIFF_VARIABLE2 when - checking for tag count in TIFFReadDirectory() function. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=713 - - * libtiff/{tif_dirread.c, tif_fax3.c}: More argument checking in - CheckMallock() function. - - * libtiff/tif_getimage.c: Support for multiple-alpha-channelled - RGB-images as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=718 - -2004-12-15 Frank Warmerdam - - * libtiff/tif_getimage.c: #define A1 bracketing for clean build on - SunPro compiler. - -2004-12-11 Bob Friesenhahn - - * autogen.sh: aclocal and autoheader should be executed after - libtoolize. Also add '-I .' to aclocal invocation to check - current directory for macros. - -2004-12-10 Andrey Kiselev - - * libtiff/tif_dirwrite.c: Always write TIFFTAG_SUBIFD using LONG type - as per bugs - - http://bugzilla.remotesensing.org/show_bug.cgi?id=703 - - and - - http://bugzilla.remotesensing.org/show_bug.cgi?id=704 - -2004-12-04 Andrey Kiselev - - * nmake.opt: Link with the user32.lib in windowed mode. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=697 - - * libtiff/tif_win32.c: Use char* strings instead of TCHAR in windowed - mode as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=697 - - * libtiff/tif_config.in.vc: Removed unneded definitions for - read/open/close/lseek functions to fix the - - http://bugzilla.remotesensing.org/show_bug.cgi?id=680 - -2004-12-03 Andrey Kiselev - - * libtiff/{tif_dir.c, tif_dirread.c}: Remove TIFFReassignTagToIgnore() - call from the TIFFReadDirectory() function. TIFFReassignTagToIgnore - must be removed in the future, as it was never used properly. As per - bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=692 - -2004-11-30 Bob Friesenhahn - - * libtiff/tif_jpeg.c: Added a work-around in order to allow - compilation with the heavily modified version of libjpeg delivered - with Cygwin. - -2004-11-29 Andrey Kiselev - - * libtiff/tif_dir.c: Properly handle tags, which have the uint32 - counts. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=693 - - * tools/fax2ps.c: Be able to extract the first page (#0). As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=690 - -2004-11-28 Andrey Kiselev - - * libtiff/tif_unix.c: Make UNIX module compilable (and usable) - on Windows. - - * nmake.opt: Add missed DLLNAME variable. - -2004-11-26 Frank Warmerdam - - * libtiff/makefile.vc: make it easier to rename the libtiff DLL. - -2004-11-24 Andrey Kiselev - - * man/libtiff.3tiff: Improvements in the "LIST OF ROUTINES" table as - per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=545 - - * man/tiffset.1: Added manual page for tiffset tool written by Jay - Berkenbilt. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=678 - -2004-11-23 Frank Warmerdam - - * libtiff/tif_error.c: fixed TIFFerror call to be TIFFError. - -2004-11-21 Frank Warmerdam - - * html/document.html: Updated Adobe web links as per email from Joris. - -2004-11-21 Andrey Kiselev - - * libtiff/{tiffio.hxx, tiffio.h}: C++ stream interface moved to new - file tiffio.hxx. We don't have any C++ in tiffio.h, those who want to - use C++ streams should #include . - -2004-11-13 Andrey Kiselev - - * libtiff/tiff.h: Added Adobe DNG tags. - - * libtiff/tif_win32.c: Typo fixed. - - * libtiff/{tif_stream.cxx, tiffio.h}: C++ stream interface updated to - be compliant with the latest standard. Appropriate additions in - makefiles now completed. - -2004-11-11 Andrey Kiselev - - * tools/tiffset.c, libtiff/tif_dirinfo.c: Properly handle the - different tag types. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=600 - -2004-11-10 Andrey Kiselev - - * libtiff/tif_aux.c: Set the appropriate ReferenceBlackWhite array for - YCbCr image which lacks that tag (noted by Hans Petter Selasky). - -2004-11-09 Andrey Kiselev - - * libtiff/tif_color.c: Division by zero fixed (Hans Petter Selasky). - -2004-11-07 Andrey Kiselev - - * libtiff/{tif_stream.cxx, tiffio.h}: Added C++ stream interface - contributed by Edward Lam (see - http://bugzilla.remotesensing.org/show_bug.cgi?id=654 for details). - Though no changes in any makefiles yet. - -2004-11-05 Frank Warmerdam - - * libtiff/tif_open.c: Removed close() in TIFFClientOpen() if file - is bad. This is the callers responsibility. - http://bugzilla.remotesensing.org/show_bug.cgi?id=651 - -2004-11-05 Andrey Kiselev - - * libtiff/{tiffio.h, tif_win32.c, libtiff.def}: Added TIFFOpenW() - function to work with the double byte strings (used to represent - filenames in some locales). As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=625 - - * libtiff/tif_dirread.c: Fixed problem when fetching BitsPerSample and - Compression tags of type LONG from broken TIFFS as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=662 - - * libtiff/tif_dirinfo.c: Fixed definition for TIFFTAG_RICHTIFFIPTC, - the writecount should have uint32 type. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=662 - - * libtiff/tif_write.c: Fixed wrong if() statement in - TIFFAppendToStrip() function as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=660 - -2004-11-04 Andrey Kiselev - - * libtiff/tif_dirinfo.c: Change definition for TIFFTAG_EXTRASAMPLES - field. The caller should supply a count when setting this field. As - per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=648 - - * libtiff/{tif_jpeg.c, tif_ojpeg.c}: TIFFTAG_JPEGTABLES should have - uint32 count. Use this type everywhere. - -2004-11-03 Frank Warmerdam - - * libtiff/tif_next.c: avoid use of u_long and u_char types. Bug 653. - -2004-11-02 Frank Warmerdam - - * tools/tiff2rgba.c: removed extra newlines in usage message. - -2004-10-30 Andrey Kiselev - - * libtiff/tif_dirwrite.c: Improvements in tag writing code. - - * tools/tiff2ps.c: Fixed wrong variable data type when read Position - tags (Tristan Hill). - -2004-10-30 Frank Warmerdam - - * libtiff/tiffiop.h: added fallback definition of assert() if we - don't have assert.h. - -2004-10-29 Andrey Kiselev - - * libtiff/tif_fax3.c: Fixed case with the wrong decode routines - choosing when the incorrect Group4Options tag set. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=323 - - * libtiff/tif_dirwrite.c: Fixed problem with passing count variable of - wrong type when writing the TIFF_BYTE/TIFF_SBYTE tags in - TIFFWriteNormalTag(). - -2004-10-28 Andrey Kiselev - - * tools/tiff2ps.c: Fixed wrong variable data type when read Resolution - tags (Peter Fales). - - * tools/{bmp2tiff.c, raw2tiff.c}: Get rid of stream I/O functions. - -2004-10-28 Frank Warmerdam - - * tools/tiff2pdf.c: added casts to avoid warnings. - - * libtiff/libtiff.def: Added several more entry points required - to link fax2tiff.c against the DLL on windows. - -2004-10-27 Andrey Kiselev - - * configure, configure.ac: Added --enable-rpath option to embed linker - paths into library binary. - -2004-10-26 Andrey Kiselev - - * tools/tiffset.c: Check the malloc return value (Dmitry V. Levin). - - * libtiff/{tif_strip.c, tif_tile.c}: Zero division problem fixed - (Vladimir Nadvornik, Dmitry V. Levin). - -2004-10-16 Andrey Kiselev - - * libtiff 3.7.0 released. - -2004-10-15 Bob Friesenhahn - - * libtiff/tif_jpeg.c: There seems to be no need to include stdio.h - in this file so its inclusion is removed. Including stdio.h - sometimes incurs an INT32 typedef conflict between MinGW's - basetsd.h and libjpeg's jmorecfg.h. - -2004-10-15 Andrey Kiselev - - * man/bmp2tiff.1: Added manual page for bmp2tiff utility. - -2004-10-13 Bob Friesenhahn - - * tools/tiffcmp.c (leof): Renamed from 'eof' in order to avoid - conflict noticed under MinGW. - * ltmain.sh: Fix for MinGW compilation. - -2004-10-13 Frank Warmerdam - - * man/tiffsplit.1: Fixed to indicate using aaa-zzz, not aa-zz. - http://bugzilla.remotesensing.org/show_bug.cgi?id=635 - -2004-10-12 Andrey Kiselev - - * libtiff/{tif_dirread.c, tif_jpeg.c, tif_luv.c, tif_ojpeg.c, - tif_pixarlog.c, tif_write.c}: Handle the zero strip/tile sizes - properly (Dmitry V. Levin, Marcus Meissner). - -2004-10-11 Andrey Kiselev - - * libtiff/tif_dirinfo.c: Type of the TIFFTAG_SUBIFD field changed - to TIFF_IFD. - -2004-10-10 Andrey Kiselev - - * tools/bmp2tif.c: Check the space allocation results. - -2004-10-09 Andrey Kiselev - - * libtiff/tif_dir.c: Initialize td_tilewidth and td_tilelength fields - of the TIFFDirectory structure with the 0 instead of -1 to avoid - confusing integer overflows in TIFFTileRowSize() for striped images. - - * tools/tiff2pdf.c: Fixed TransferFunction tag handling reported - by Ross A. Finlayson. - - * libtiff/tif_dir.c: Fixed custom tags handling as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=629 - -2004-10-08 Frank Warmerdam - - * libtiff/tif_dirinfo.c: Fix bug with tif_foundfield and reallocation - of tif_fieldinfo. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=630 - -2004-10-04 Bob Friesenhahn - - * contrib/iptcutil/README: Added the missing README which goes - along with iptcutil. - -2004-10-03 Andrey Kiselev - - * libtiff/tif_compress.c: Improved error reporting in - TIFFGetConfiguredCODECs() (Dmitry V. Levin). - -2004-10-02 Andrey Kiselev - - * libtiff 3.7.0beta2 released. - - * libtiff/{tif_aux.c, tif_compress.c, tif_dirinfo.c, tif_dirwrite.c, - tif_extension.c, tif_fax3.c, tif_luv.c, tif_packbits.c, - tif_pixarlog.c, tif_write.c}: Added checks for failed memory - allocations and integer overflows (Dmitry V. Levin). - - * libtiff/tiff.h: Missed TIFF_BIGTIFF_VERSION constant added. - -2004-10-01 Frank Warmerdam - - * libtiff/tif_open.c: added a more informative message if a BigTIFF - file is opened. - -2004-09-30 Frank Warmerdam - - * libtiff/tif_dirinfo.c: changed type of XMLPacket (tag 700) to - TIFFTAG_BYTE instead of TIFFTAG_UNDEFINED to comply with the info - in the Adobe XMP Specification. - -2004-09-29 Andrey Kiselev - - * libtiff/{tif_jpeg.c, tif_pixarlog.c}: Use _TIFFmemset() instead of - memset(). - - * libtiff/{tif_dirread.c, tif_strip.c, tif_tile.c}: Applied patches - from Dmitry V. Levin to fix possible integer overflow problems. - -2004-09-28 Andrey Kiselev - - * libtiff/tif_getimage.c: Check for allocated buffers before clearing - (Dmitry V. Levin). - -2004-09-26 Andrey Kiselev - - * libtiff/{tif_dir.h, tif_dir.c, tif_dirread.c, tif_write.c}: - Optimize checking for the strip bounds. - - * libtiff/{tif_dirread.c, tif_strip.c}: TIFFScanlineSize() and - TIFFRasterScanlineSize() functions report zero in the case of integer - overflow now. Properly handle this case in TIFFReadDirectory() - (patches from Dmitry V. Levin). - -2004-09-25 Andrey Kiselev - - * libtiff/{tif_dirinfo.c, tif_strip.c, tif_tile.c}: Use TIFFhowmany8() - macro where appropriate. - - * tools/tiff2bw.c: Write ImageWidth/Height tags to output file, as - noted by Gennady Khokhorin. - - * libtiff/tif_dirread.c: Always check the return values, returned - by the _TIFFmalloc() (Dmitry V. Levin). - - * libtiff/tif_dir.c: Fixed possible integer overflow _TIFFset*Array() - functions (Dmitry V. Levin). - - * libtiff/{tif_dirread.c, tif_dir.c, tif_write.c}: - Potential memory leak fixed in TIFFReadDirectory(), _TIFFVSetField(), - TIFFGrowStrips() (found by Dmitry V. Levin). - -2004-09-24 Andrey Kiselev - - * libtiff/{tiffio.h, tif_compress.c}: Added TIFFGetConfiguredCODECs() - to get the list of configured codecs. - - * libtiff/{tiffiop.h, tif_dirread.c}: More overflow fixes from - Dmitry V. Levin. - -2004-09-23 Andrey Kiselev - - * libtiff/tif_dirread.c: Applied patch from Dmitry V. Levin to fix - possible integer overflow in CheckMalloc() function. - -2004-09-22 Andrey Kiselev - - * libtiff/{tiffiop.h, tif_strip.c}: Use TIFFhowmany8() macro instead - of plain TIFFhowmany() where appropriate. - -2004-09-21 Andrey Kiselev - - * libtiff/tif_getimage.c: Initialize arrays after space allocation. - -2004-09-19 Andrey Kiselev - - * libtiff 3.7.0beta released. - - * libtiff/{tif_luv.c, tif_next.c, tif_thunder.c}: Several buffer - overruns fixed, as noted by Chris Evans. - -2004-09-14 Bob Friesenhahn - - * commit: Added a script to make it more convenient to commit - updates. The CVS commit message is extracted from this ChangeLog - file. - -2004-09-14 Andrey Kiselev - - * configure.ac, configure, aclocal.m4, libtiff/{mkspans.c, tif_fax3.c, - tif_getimage.c, tif_luv.c, tif_lzw.c, tif_ojpeg.c, tif_packbits.c, - tif_predict.c, tif_read.c, tif_swab.c, tif_thunder.c, tif_write.c, - tif_dir.c, tif_dirread.c, tif_dirwrite.c, tif_jpeg.c, tif_dirinfo.c, - tif_vms.c, tif_print.c, tif_strip.c, tif_tile.c, tif_dir.h, - tif_config.h.in, tiffiop.h}: - Get rid of BSD data types (u_char, u_short, u_int, u_long). - -2004-09-13 Bob Friesenhahn - - * libtiff/tiff.h: Fix column tagging. Reference current Adobe XMP - specification. Reference libtiff bug tracking system to submit - private tag additions. - -2004-09-12 Bob Friesenhahn - - * tools/tiffgt.c: Include "tif_config.h". - - * configure.ac: Use AM_PROG_CC_C_O since it is now needed to build - tiffgt. This results in the 'compile' script being added to the - project. - - * tools/Makefile.am (tiffgt_CFLAGS): Add extra build options - required to find OpenGL headers necessary to build tiffgt. Also - ensure that the libtiff that we built is used rather than some other - libtiff installed on the system. - -2004-09-12 Andrey Kiselev - - * configure.ac, acinclude.m4, aclocal.m4: New macros to detect GLUT - libraries. - -2004-09-11 Bob Friesenhahn - - * configure.ac: Pass library configuration defines via - tif_config.h rather than extending CPPFLAGS. Configure a - libtiff/tiffconf.h in order to satisfy application requirements - (not used by library build). Do not define _POSIX_C_SOURCE=2 since - this causes failure to build on systems which properly respect - this request. - - * libtiff/tiffconf.h.in: New file to act as the template for the - configured tiffconf.h - - * libtiff/files.lst (HDRS): Install the configured tiffconf.h. - -2004-09-10 Frank Warmerdam - - * html/internals.html: Split off a discussion of adding new tags - into addingtags.html. - -2004-09-10 Andrey Kiselev - - * test/{ascii_tag.c, long_tag.c}: Preliminary test suite added. - - * tools/tiff2pdf.c: Fixed reading TransferFunction tag as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=590 - - * libtiff/tif_print.c: Fixes in InkNames and NumberOfInks reporting. - - * libtiff/tif_dirread.c: Don't reject to read tags of the - SamplesPerPixel size when the tag count is greater than number of - samples as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=576 - - * libtiff/tiff.h: Use _TIFF_DATA_TYPEDEFS_ guardian to switch off - defining int8/uint8/... etc. types. As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=607 - -2004-09-09 Frank Warmerdam - - * tools/tiff2ps.c, tools/tiffmedian.c: fiddle with include files - to avoid compile warnings about getopt() and a few other things. - -2004-09-02 Andrey Kiselev - - * libtiff/tif_dirread.c: Use memcpy() function instead of pointer - assigning magic in TIFFFetchFloat(). - -2004-09-01 Andrey Kiselev - - * libtiff/{tiffio.h, tif_open.c}: Applied patches from Joris Van Damme - to avoid requirement for tiffiop.h inclusion in some applications. See - here - - http://www.asmail.be/msg0054799560.html - - for details. - - * tools/fax2tiff.c: Use the new functions in the code. - -2004-08-25 Andrey Kiselev - - * tools/tiff2pdf.c: Initialize arrays properly. - - * tools/tiff2ps.c: Avoid zero division in setupPageState() function; - properly initialize array in PSDataBW(). - -2004-08-24 Andrey Kiselev - - * tools/tiff2pdf.c: More fixes for bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=590 - - from Ross Finlayson. - -2004-08-23 Andrey Kiselev - - * tools/tiff2ps.c: Fixed problem with uninitialized values. - - * libtiff/tif_dir.c: Initialize tif_foundfield data member in the - TIFFDefaultDirectory() (in addition to 2004-08-19 fix). - - * tools/tiff2pdf.c: Fixed a bunch of problems as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=590 - -2004-08-20 Andrey Kiselev - - * tools/tiff2pdf.c: Applied patch from Ross Finlayson that checks - that the input file has compression, photometric interpretation, - etcetra, tags or if not than a more descriptive error is returned. - - * libtiff/tif_dirread.c: Fixed problem in TIFFReadDirectory() in the - code, responsible for tag data type checking. - -2004-08-19 Andrey Kiselev - - * libtiff/{tiffiop.h, tif_dirinfo.c}: Fixed problem with the static - variable as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=593 - -2004-08-16 Andrey Kiselev - - * tools/ras2tiff.c: Fixed issue with missed big-endian checks as per - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=586 - -2004-08-01 Andrey Kiselev - - * libtiff/{tif_config.h.in, tif_config.h.vc}: config.h.in and - config.h.vc files renamed in the tif_config.h.in and tif_config.h.vc. - -2004-07-24 Andrey Kiselev - - * libtiff/tif_lzw.c: LZW compression code is merged back from the - separate package. All libtiff tools are updated to not advertise an - abcence of LZW support. - -2004-07-12 Andrey Kiselev - - * libtiff/tiffio.h: Revert thandle_t back to void* type. - -2004-07-11 Andrey Kiselev - - * libtiff/{tif_read.c, tif_tile.c, tif_strip.c}: Fixes in error - messages, as suggested by Bernd Herd. - -2004-07-03 Andrey Kiselev - - * libtiff/tif_dir.c: Call TIFFError() instead of producing warnings - when setting custom tags by value. Reported by Eric Fieleke. - -2004-06-14 Andrey Kiselev - - * tools/bmp2tiff.c: Add missed RawsPerStrip setting. - -2004-06-08 Andrey Kiselev - - * tools/bmp2tiff.c: Added new utility to convert Windows BMP files - into TIFFs. - -2004-06-07 Andrey Kiselev - - * libtiff 3.7.0alpha released. - -2004-06-06 Andrey Kiselev - - * libtiff/{tiff.h, tif_dirwrite.c, tif_fax3.c, tif_packbits.c,}: Get rid - of ugly 64-bit hacks, replace them with the clever (autoconf based ) - ones :-). - - * libtiff/tiffio.h: Define thandle_t as int, not void* (may cause - problems in 64-bit environment). - -2004-06-05 Andrey Kiselev - - * tools/tiffset.c: tiffset now can set any libtiff supported tags. - Tags can be supplied by the mnemonic name or number. - - * libtiff/{tiffio.h, tif_dir.h, tif_dirinfo.c,}: Added two new - functions TIFFFindFieldInfoByName() and TIFFFieldWithName(). - -2004-05-27 Andrey Kiselev - - * libtiff/tif_ojpeg.c: Fixed problem with duplicated SOI and SOF - markers as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=581 - -2004-05-24 Andrey Kiselev - - * tools/tiffsplit.c: Don't forget to copy Photometric - Interpretation tag. - -2004-05-20 Andrey Kiselev - - * libtiff/{tif_open.c, tiffio.h}: New function added: - TIFFIsBigEndian(). Function returns nonzero if given was file written - in big-endian order. - - * tools/tiffsplit.c: Fixed problem with unproperly written multibyte - files. Now output files will be written using the same byte order - flag as in the input image. See - - http://bugzilla.remotesensing.org/show_bug.cgi?id=574 - - for details. - -2004-05-19 Frank Warmerdam - - * libtiff/tif_print.c: added (untested) support for printing - SSHORT, SLONG and SRATIONAL fields. - - * tools/tiffcp.c: close output file on normal exit. - -2004-05-17 Andrey Kiselev - - * libtiff/tif_fax3.c: Avoid reading CCITT compression options - if compression type mismatches. See - - http://bugzilla.remotesensing.org/show_bug.cgi?id=565 - -2004-04-30 Andrey Kiselev - - * libtiff/tif_strip.c: Never return 0 from the - TIFFNumberOfStrips(). - -2004-04-29 Andrey Kiselev - - * libtiff/tif_dirread.c: Workaround for broken TIFF writers which - store single SampleFormat value for multisampled images. See - - http://bugzilla.remotesensing.org/show_bug.cgi?id=562 - -2004-04-25 Andrey Kiselev - - * configure.ac, libtiff/{tiff.h, config.h.in}: Added tests for int8, - int16 and int32 types to avoid complains on some compilers. Details at - - http://bugzilla.remotesensing.org/show_bug.cgi?id=39 - -2004-04-20 Andrey Kiselev - - * tools/tiff2pdf.c: Fixed problem with unaligned access as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=555 - -2004-04-14 Andrey Kiselev - - * libtiff/tif_write.c: Allow in-place updating of the compressed - images (don't work properly with all codecs). For details see GDAL bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=534 - -2004-04-06 Andrey Kiselev - - * libtiff/tif_jpeg.c: Workaround for wrong sampling factors used - in the Intergarph JPEG compressed TIFF images as per bug: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=532 - -2004-04-04 Frank Warmerdam - - * libtiff/tif_open.c: close clientdata if TIFFClientOpen() fails - via bad2. - -2004-03-26 Andrey Kiselev - - * tools/tiffcp.c: Properly set Photometric Interpretation in case of - JPEG compression of grayscale images. - - * tools/tiffcp.c: Don't emit warnings when Orientation tag does not - present in the input image. - -2004-03-19 Andrey Kiselev - - * {many}: The first attempt to switch to autotools. - -2004-03-03 Andrey Kiselev - - * libtiff/tif_open.c: Use dummy mmap/munmap functions in - TIFFClientOpen() when the appropriate client functions was not - supplied by user. - -2004-03-02 Frank Warmerdam - - * tools/ycbcr.c: fixed main() declaration as per: - http://bugzilla.remotesensing.org/show_bug.cgi?id=513 - -2004-02-26 Andrey Kiselev - - * tools/tiffsplit.c: Copy JPEGTables tag contents for JPEG compressed - images. Reported by Artem Mirolubov. - - * libtiff/tif_dirread.c: Fixed problem with handling TIFF_UNDEFINED - tag type in TIFFFetchNormalTag() as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=508 - -2004-02-17 Frank Warmerdam - - * libtiff/tif_codec.c: Fixed typo in TIFFInitPackBits name as per: - http://bugzilla.remotesensing.org/show_bug.cgi?id=494 - -2004-02-05 Andrey Kiselev - - * libtiff/tif_fax3.c: Fixed problem with CCITT encoding modes as per - bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=483 - - But we need more work on fax codec to support update mode. - -2004-01-30 Frank Warmerdam - - * libtiff/libtiff.def: Added TIFFCurrentDirOffset, TIFFWriteCheck, - TIFFRGBAImageOK, and TIFFNumberOfDirectories as suggested by - Scott Reynolds. - -2004-01-29 Andrey Kiselev - - * libtiff/tiff.h: Fixed tag definitions for TIFFTAG_YCLIPPATHUNITS - and TIFFTAG_INDEXED as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=475 - - * libtiff/{tif_win32.c, tif_unix.c}: Check whether the pointer is - NULL before proceeding further as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=474 - - Check results, returned by the TIFFFdOpen() before returning and close - file if TIFFFdOpen() failed as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=468 - - * libtiff/tif_open.c: More fixes for - - http://bugzilla.remotesensing.org/show_bug.cgi?id=468 - -2004-01-28 Andrey Kiselev - - * libtiff/{libtiff.def, tif_close.c, tiffio.h, tif_open.c}: Separate - TIFFCleanup() from the TIFFClose() in order to fix the bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=468 - - * tools/tiffcp.c: Fixed problem with wrong interpretation of the - InkNames tag as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=466 - - Memory leak fixed. - -2004-01-21 Frank Warmerdam - - * libtiff/tif_dirwrite.c: Fixed handling of writable ASCII tags that - are field_passcount=TRUE properly. Arguably anonymous custom tags - should be declared as passcount=FALSE, but I don't want to change - that without a careful review. - -2004-01-20 Andrey Kiselev - - * libtiff/tif_write.c: Fixed reporting size of the buffer in case of - stripped image in TIFFWriteBufferSetup(). As per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=460 - -2004-01-11 Andrey Kiselev - - * libtiff/tif_dir.c: Incomplete cleanup in TIFFFreeDirectory(), - patch from Gerben Koopmans. - - * libtiff/tif_dirread.c: Check field_passcount value before setting - the value of undefined type, patch from Gerben Koopmans. - -2004-01-02 Andrey Kiselev - - * tools/tiffcp.c: Fixed problem with wrong Photometric setting for - non-RGB images. - -2003-12-31 Andrey Kiselev - - * libtiff/tif_win32.c: Fixed problem with _TIFFrealloc() when the NULL - pointer passed. Patch supplied by Larry Grill. - - * libtiff/{tiff.h, tif_fax3.c}:Fixes for AMD 64 platform as - suggested by Jeremy C. Reed. - -2003-12-26 Andrey Kiselev - - * libtiff 3.6.1 released. - -2003-12-24 Andrey Kiselev - - * config.guess, config.sub: Updated from the recent upstream. - -2003-12-22 Andrey Kiselev - - * libtiff/{tif_color, tif_getimage.c, tiffio.h}, man/TIFFcolor.3t: - More cleanups in color conversion interface, added appropriate manual - page. - -2003-12-19 Andrey Kiselev - - * libtiff/{tif_extension.c, tif_dirinfo.c, tiff.h}: Warnings fixed as - per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=357 - - * tools/tiff2ps.c: Added support for alpha channel. Fixes - - http://bugzilla.remotesensing.org/show_bug.cgi?id=428 - - * libtiff/{libtiff.def, tif_color.c, tif_getimage.c, tiffio.h}: - Interface for Lab->RGB color conversion is finally cleaned up. - Added support for ReferenceBlackWhite tag handling when converted from - YCbCr color space. The latter closes - - http://bugzilla.remotesensing.org/show_bug.cgi?id=120 - -2003-12-07 Andrey Kiselev - - * libtiff/{tif_getimage.c, tiffio.h}: Avoid warnings. - - * libtiff/makefile.vc, tools/makefile.vc: Support for IJG JPEG - library. - -2003-12-06 Andrey Kiselev - - * libtiff/{tif_getimage.c, tif_aux.c}: Read WhitePoint tag from the - file and properly use it for CIE Lab->RGB transform. - -2003-12-04 Andrey Kiselev - - * libtiff/{tif_getimage.c, tif_color.c, tiffio.h}: YCbCr->RGB - conversion routines now in the tif_color.c module. New function - TIFFYCbCrtoRGB() available in TIFF API. - - * libtiff/tif_dirwrite.c: Handle TIFF_IFD tag type correctly. - -2003-12-03 Andrey Kiselev - - * libtiff/{tif_getimage.c, tif_color.c, tiffio.h}: Improvements in - CIE Lab conversion code. Start moving YCbCr stuff to the tif_color.c - module. - - * libtiff/{tif_getimage.c, tiffio.h}, man{TIFFReadRGBAImage.3t, - TIFFReadRGBAStrip.3t, TIFFReadRGBATile.3t, TIFFRGBAImage.3t}: - Finally resolved problems with orientation handling. TIFFRGBAImage - interface now properly supports all possible orientations, i.e. images - will be flipped both in horizontal and vertical directions if - required. 'Known bugs' section now removed from the appropriate manual - pages. Closed bug entry: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=322 - -2003-12-02 Andrey Kiselev - - * libtiff/tif_dir.c: Fixed order of the parameters in TIFFError() - function calls as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=440 - -2003-11-28 Ross Finlayson - - * tools/tiff2pdf.c: Some bugs fixed. - -2003-11-27 Andrey Kiselev - - * libtiff/tif_luv.c: Fixed bug in 48-bit to 24-bit conversion routine, - reported by Antonio Scuri. - - * man/tiff2pdf.1: Few improvements in page layout. - - * Makefile.in, /man/Makefile.in, /html/man/tiff2pdf.1.html: - Added support fpr tiff2pdf manual page. - -2003-11-26 Ross Finlayson - - * /man/tiff2pdf.1: File added to repository. - -2003-11-26 Andrey Kiselev - - * Makefile.in, /tools/{Makefile.in, makefile.vc}: - Added support fpr tiff2pdf utility. - -2003-11-25 Ross Finlayson - - * /tools/tiff2pdf.c: File added to repository. - -2003-11-22 Andrey Kiselev - - * /tools/raw2tiff.c: sqrtf() replaced with sqrt(). - -2003-11-21 Andrey Kiselev - - * /tools/raw2tiff.c: #include removed. - - * tools/{Makefile.in, tiffgt.c}: Unmaintained and platform dependent - sgigt utility removed and replaced with the completely rewritten - portable tiffgt tool (depend on OpenGL and GLUT). Initial revision, - there is a lot of things to improve. - - * libtiff/tif_ojpeg.c: TIFFVGetField() function now can properly - extract the fields from the OJPEG files. Patch supplied by Ross - Finlayson. - - * libtiff/{tiffio.h, tif_codec.c}, man/{libtiff.3t, TIFFcodec.3t}: - Added new function TIFFIsCODECConfigured(), suggested by Ross - Finlayson. - -2003-11-18 Andrey Kiselev - - * libtiff/tif_dirinfo.c: Implemented binary search in - _TIFFMergeFieldInfo(). Patch supplied by Ross Finlayson. - - * libtiff/tif_dir.h: _TIFFFindOrRegisterdInfo declaration replaced - with _TIFFFindOrRegisterFieldInfo as reported by Ross Finlayson. - -2003-11-17 Frank Warmerdam - - * tif_dirread.c: do not mark all anonymously defined tags to be - IGNOREd. - -2003-11-17 Andrey Kiselev - - * contrib/pds/{tif_pdsdirread.c, tif_pdsdirwrite.c}: Use - TIFFDataWidth() function insted of tiffDataWidth array. - -2003-11-16 Andrey Kiselev - - * libtiff/{tiff.h, tif_dirinfo.c}: Added support for IFD (13) - datatype, intruduced in "Adobe PageMaker TIFF Tech. Notes". - -2003-11-15 Frank Warmerdam - - * Makefile.in: fixed missing backslash for tif_color.c in list. - -2003-11-13 Andrey Kiselev - - * libtiff/{tif_color.c, tif_getimage.c, tiffio.h, Makefile.in}: - New color space conversion code: CIE L*a*b* 1976 images now supported - by the TIFFRGBAImage interface. All introduced routines go to new - module tif_color.c. Eventually all color conversion functions should - be moved there. - -2003-11-12 Andrey Kiselev - - * tools/{ras2tiff.c, rasterfile.h}: Properly determine SUN Rasterfiles - with the reverse byte order (it is reported by the magic header - field). Problem reported by Andreas Wiesmann. - - * tools/raw2tiff.c, man/raw2tiff.1: Few improvements in correlation - calculation function. Guessing mechanics now documented in manual page. - -2003-11-11 Andrey Kiselev - - * tools/raw2tiff.c: Implemented image size guessing using - correlation coefficient calculation between two neighbour lines. - -2003-11-09 Frank Warmerdam - - * libtiff/tif_tile.c: remove spurious use of "s" (sample) in the - planarconfig_contig case in TIFFComputeTile(). - - http://bugzilla.remotesensing.org/show_bug.cgi?id=387 - -2003-11-09 Andrey Kiselev - - * libtiff/tiffiop.h: New macros: TIFFmax, TIFFmin and TIFFrint. - -2003-11-07 Andrey Kiselev - - * libtiff/{tiffio.h, tif_strip.c}, man/{TIFFstrip.3t, libtiff.3t}: - Added TIFFRawStripSize() function as suggested by Chris Hanson. - -2003-11-03 Andrey Kiselev - - * libtiff/{tif_lzw.c, tif_fax3.c}: Proper support for update mode as - per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=424 - -2003-10-29 Andrey Kiselev - - * libtiff/libtiff.def: Added TIFFReadRGBAImageOriented. - - * html/build.html: Added note about GNU make requirement. - -2003-10-25 Andrey Kiselev - - * Makefile.in: Fixes in using MAKEFLAGS as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=418 - - * port/install.sh.in: Option -p added to the mkdir command to create - all directory tree structure before installing. - -2003-10-18 Andrey Kiselev - - * /tools/tiff2ps.c: #include replaced with the - #include . - -2003-10-16 Andrey Kiselev - - * Makefile.in: Add an absolute path to the test_pics.sh call. - -2003-10-12 Andrey Kiselev - - * libtiff/tiffcomp.h: #define _BSDTYPES_DEFINED when defining BSD - typedefs. - -2003-10-09 Andrey Kiselev - - * configure, libtiff/{Makefile.in, mkversion.c}: - Relative buildings fixed. - - * tools/Makefile.in: Added "-I../libtiff" to the tiffset building - rule. - -2003-10-07 Andrey Kiselev - - * Makefile.in: Added missed v3.6.0.html. - - * libtiff/tiffio.h: Typo fixed: ORIENTATION_BOTTOMLEFT replaced with - ORIENTATION_BOTLEFT. - -2003-10-04 Andrey Kiselev - - * 3.6.0 final release. - -2003-10-03 Andrey Kiselev - - * libtiff/{tif_getimage.c, tiffio.h}, man/TIFFReadRGBAImage.3t: New - function TIFFReadRGBAImageOriented() implemented to retrieve raster - array with user-specified origin position as suggested by Jason Frank. - See - - http://bugzilla.remotesensing.org/show_bug.cgi?id=322 - - for details. - - * tools/tiff2rgba.c: Switched to use TIFFReadRGBAImageOriented() - instead of TIFFReadRGBAImage(). - - * tools/tiff2ps.c: Fixed possible endless loop as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=404 - -2003-09-30 Andrey Kiselev - - * libtiff/tif_dirread.c: Check field counter against number of fields - in order to fix - - http://bugzilla.remotesensing.org/show_bug.cgi?id=366 - - * libtiff/tif_fax3.c: Fix wrong line numbering as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=342 - -2003-09-25 Andrey Kiselev - - * libtiff/{tiffiop.h, tif_dirread.c, tif_dir.c, tif_open.c, - tif_close.c}: Store a list of opened IFD to prevent looping as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=383 - -2003-09-23 Andrey Kiselev - - * libtiff/tif_dirread.c: More fixes for EstimateStripByteCounts(). See - - http://bugzilla.remotesensing.org/show_bug.cgi?id=358 - -2003-08-21 Andrey Kiselev - - * tools/tiffmedian.c: int declaration replaced with the uint32 to - support large images as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=382 - -2003-08-12 Andrey Kiselev - - * libtiff/Makefile.in: Fixed problem with building in different - directory. - - * tools/tiff2ps.c: Added missing #include . - - * libtiff/tif_dirwrite.c: More fixes for custom tags code - from Ashley Dreier. - -2003-08-07 Andrey Kiselev - - * tools/tiff2ps.c: Added page size setting when creating PS Level 2. - Patch submitted by Balatoni Denes (with corrections from Tom - Kacvinsky). - - * tools/tiff2ps.c: Fixed PS comment emitted when FlateDecode is - being used. Reported by Tom Kacvinsky. - - * libtiff/tif_dirwrite.c: Fixed problem with custom tags writing, - reported by Ashley Dreier. - - * libtiff/tif_print.c: Fixed problem with float tags reading, support - for printing RATIONAL and BYTE tags added. - -2003-08-05 Andrey Kiselev - - * libtiff/tif_lzw.c: Move LZW codec state block allocation back to - TIFFInitLZW(), because its initialization in LZWSetupDecode() cause - problems with predictor initialization. Remove O_RDONLY check during - state block allocation to be able open LZW compressed files in update - mode. - - Problem exist for libtiff version of the tif_lzw.c module. One from - lzw-compression-kit hasn't such troubles. - -2003-08-04 Frank Warmerdam - - * libtiff/tif_write.c: modified tif_write.c so that the various - encoded write functions use tif_postdecode() to apply byte order - swapping (swab) to the application passed data buffer if the same - would be done when reading. This allows us to write pixel data with - more than 8 bits per sample to existing files of a non-native byte - order. One side effect of this change is the applications buffer - itself is altered in this case by the act of writing. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=171 - -2003-07-25 Frank Warmerdam - - * libtiff/tif_open.c: avoid signed/unsigned casting warning - initializing typemask as per patch from J.A. Strother. - - * tools/tiffcp.c: fixed signed/unsigned casting warning. - - * libtiff/tif_print.c: dos2unix conversion. - - * tools/tiffsplit.c: increased the maximum number of pages that - can be split. Patch provided by Andrew J. Montalenti. - -2003-07-11 Andrey Kiselev - - * tools/raw2tiff.c: Added option `-p' to explicitly select color - space of input image data. Closes - - http://bugzilla.remotesensing.org/show_bug.cgi?id=364 - -2003-07-08 Frank Warmerdam - - * tif_aux.c, tif_codec.c, tif_dir.c, tif_dirread.c, tif_extension.c, - tif_fax3.c, tif_getimage.c, tif_luv.c, tif_lzw.c, tif_next.c, - tif_packbits.c, tif_predict.c, tif_print.c, tif_swab.c, tif_thunder.c: - avoid casting warning at /W4. - -2003-07-03 Andrey Kiselev - - * tools/thumbnail.c: Memory leak fixed as reported by Robert S. Kissel. - -2003-06-30 Andrey Kiselev - - * libtiff/tif_pixarlog.c: Unused variables removed. - - * libtiff/{tif_dirread.c, tif_dir.c}: Fixed problem with - EstimateStripByteCounts() as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=358 - - * libtiff/{tif_dirwrite.c, tif_packbits.c}: Fixed compilation on - 64-bit architectures as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=357 - - * libtiff/tif_dirinfo.c: TIFFDataWidth() returns 0 in case of - unknown data type. - -2003-06-19 Frank Warmerdam - - * libtiff/tif_print.c: fixed some serious bugs when printing - custom tags ... almost certain to crash. - - * libtiff/tif_dirread.c: Don't ignore custom fields that are - autodefined. Not sure how this got to be like this. - -2003-06-18 Andrey Kiselev - - * 3.6.0 Beta2 released. - - * tools/tiffcmp.c, man/tiffcmp.1: Fixed problem with unused data - comparing as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=349 - - `-z' option now can be used to set the number of reported different - bytes. - -2003-06-09 Andrey Kiselev - - * tools/tiffcp.c, man/tiffcp.1: Added possibility to specify value -1 - to -r option to get the entire image as one strip. See - - http://bugzilla.remotesensing.org/show_bug.cgi?id=343 - - for details. - -2003-06-04 Andrey Kiselev - - * tools/tiffcp.c: Set the correct RowsPerStrip and PageNumber - values as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=343 - -2003-05-27 Frank Warmerdam - - * libtiff/tif_jpeg.c: modified segment_height calculation to always - be a full height tile for tiled images. Also changed error to just - be a warning. - -2003-05-25 Andrey Kiselev - - * tools/fax2tiff.c: Page numbering fixed, as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=341 - -2003-05-20 Andrey Kiselev - - * contrib/ojpeg/{Makefile.in, jdhuff.h, jinclude.h, ojpeg.c, README}, - configure, Makefile.in: Switched back to the old behaviour. Likely - better solution should be found for OJPEG support. - -2003-05-11 Andrey Kiselev - - * libtiff/mkversion.c: Fixed problem with wrong string size when - reading RELEASE-DATE file. - -2003-05-07 Andrey Kiselev - - * tools/tiff2ps.c: Fixed bug in Ascii85EncodeBlock() function: array - index was out of range. - -2003-05-06 Andrey Kiselev - - * contrib/ojpeg/{Makefile.in, jdhuff.h, jinclude.h, ojpeg.c, README}, - configure, Makefile.in: Improved libtiff compilation with OJPEG - support. Now no need for patching IJG JPEG library, hack requred by - libtiff will be compiled and used in-place. Implemented with - suggestion and help from Bill Allombert, Debian's libjpeg maintainer. - - * libtiff/tif_aux.c: Properly handle TIFFTAG_PREDICTOR in - TIFFVGetFieldDefaulted() function. - -2003-05-05 Andrey Kiselev - - * tools/ppm2tiff.c: PPM header parser improved: now able to skip - comments. - - * tools/tiffdither.c: Fixed problem with bit fill order tag setting: - was not copied from source image. - - * libtiff/getimage.c: Workaround for some images without correct - info about alpha channel as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=331 - -2003-04-29 Andrey Kiselev - - * tools/tiff2ps.c, man/tiff2ps.1: Add ability to generate PS Level 3. - It basically allows one to use the /flateDecode filter for ZIP - compressed TIFF images. Patch supplied by Tom Kacvinsky. Fixes - - http://bugzilla.remotesensing.org/show_bug.cgi?id=328 - - * tools/tiff2ps.c: Force deadzone printing when EPS output specified - as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=325 - -2003-04-17 Andrey Kiselev - - * libtiff/tif_dirread.c: Removed additional check for StripByteCounts - due to problems with multidirectory images. Quality of error messages - improved. - -2003-04-16 Andrey Kiselev - - * tools/tiffcp.c: Fixed problem with colorspace conversion for JPEG - encoded images. See bug entries - - http://bugzilla.remotesensing.org/show_bug.cgi?id=275 - - and - - http://bugzilla.remotesensing.org/show_bug.cgi?id=23 - - * libtiff/tif_dirread.c: Additional check for StripByteCounts - correctness. Fixes - - http://bugzilla.remotesensing.org/show_bug.cgi?id=320 - -2003-03-12 Andrey Kiselev - - * tools/{fax2ps.c, fax2tiff.c, gif2tiff.c, pal2rgb.c, ppm2tiff.c, - ras2tiff.c, raw2tiff.c, rgb2ycbcr.c, thumbnail.c, tiff2bw.c, - tiff2ps.c, tiff2rgba.c, tiffcp.c, tiffdither.c, tiffinfo.c, - tiffmedian.c}: Added library version reporting facility to all tools. - -2003-03-06 Frank Warmerdam - - * port/install.sh.in: Fixed problems with install producing paths - like ///usr/local/lib on cygwin. - -2003-02-27 Andrey Kiselev - - * tools/fax2tiff.c, man/fax2tiff.1: New switch (-X) to set width of - raw input page. Patch supplied by Julien Gaulmin. See - - http://bugzilla.remotesensing.org/show_bug.cgi?id=293 - - for details. - -2003-02-26 Frank Warmerdam - - * libtiff/tif_dir.c: fixed up the tif_postdecode settings - responsible for byte swapping complex image data. - - * libtiff/tif_lzw.c: fixed so that decoder state isn't allocated till - LZWSetupDecode(). Needed to read LZW files in "r+" mode. - -2003-02-07 Andrey Kiselev - - * tools/ppm2tiff.c: Fixed problem with too many arguments. - -2003-02-04 Andrey Kiselev - - * tools/raw2tiff.c: Memory leak fixed. - -2003-02-03 Andrey Kiselev - - * tools/fax2tiff.c, man/fax2tiff.1: Applied patch from Julien Gaulmin - (thanks, Julien!). More switches for fax2tiff tool for better control - of input and output. Details at - - http://bugzilla.remotesensing.org/show_bug.cgi?id=272 - -2003-02-03 Frank Warmerdam - - * libtiff/tif_jpeg.c: Modified to defer initialization of jpeg - library so that we can check if there is already any tile/strip data - before deciding between creating a compressor or a decompressor. - -2003-01-31 Frank Warmerdam - - * libtiff/tif_write.c: TIFFWriteCheck() now fails if the image is - a pre-existing compressed image. That is, image writing to - pre-existing compressed images is not allowed. - - * libtiff/tif_open.c: Removed error if opening a compressed file - in update mode. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=198 - -2003-01-31 Andrey Kiselev - - * config.guess, config.sub: Updated to recent upstream versions. - -2003-01-15 Frank Warmerdam - - * cut 3.6.0 Beta release. - -2002-12-20 Andrey Kiselev - - * tools/fax2ps.c, man/fax2ps.1: Page size was determined - in wrong way as per bug - - http://bugzilla.remotesensing.org/show_bug.cgi?id=239 - -2002-12-17 Frank Warmerdam - - * libtiff/tif_dirread.c: Allow wrong sized arrays in - TIFFFetchStripThing(). - - http://bugzilla.remotesensing.org/show_bug.cgi?id=49 - -2002-12-02 Frank Warmerdam - - * libtiff/tif_dir.c: fix problem with test on td_customValueCount. - Was using realloc even first time. Fix by Igor Venevtsev. - -2002-11-30 Frank Warmerdam - - * libtiff/tif_dir.c: fixed bug with resetting an existing custom - field value. - - * libtiff/tif_dir.c: Fixed potential problem with ascii "custom" - tags in TIFFVGetField() ... added missing break. - -2002-10-14 Frank Warmerdam - - * tools/tiff2ps.c: fixes a problem where "tiff2ps -1e" did not make - the scanline buffer long enough when writing rgb triplets. - The scanline needs to be 3 X the number of dots or else it will - contain an incomplete triplet and programs that try to separate - the eps by redefining the colorimage operator will get messed up. - Patch supplied by William Bader. - - * Makefile.in: added tif_extension.c to file list as per - http://bugzilla.remotesensing.org/show_bug.cgi?id=218. - -2002-10-11 Andrey Kiselev - - * configure, config.site, libtiff/{tif_unix.c, Makefile.in}: Fix for - large files (>2GiB) supporting. New option in the config.site: - LARGEFILE="yes". Should be enough for I/O of the large files. - -2002-10-10 Frank Warmerdam - - * libtiff/html/v3.6.0.html: new release notes. - - * libtiff/index.html: removed faq, cvs snapshot cruft. Added email - link for Andrey. Pointer to v3.6.0.html. - - * libtiff/Makefile.in: added direct rule for tiffvers.h for release. - -2002-10-07 Andrey Kiselev - * tools/tiff2ps.c, man/tiff2ps.1: Applied patch form Sebastian Eken - (thanks, Sebastian!). New switches: - -b # for a bottom margin of # inches - -c center image - -l # for a left margin of # inches - -r rotate the image by 180 degrees - New features merged with code for shrinking/overlapping. - Previously added -c and -n switches (for overriding PS units) renamed - in -x and -y respectively. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=200 - - * html/man/*.html: Updated from actual manual pages. - -2002-10-06 Frank Warmerdam - - * libtiff/tif_jpeg.c: fixed problem with boolean defined with wrong - size on windows. Use #define boolean hack. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=188 - - * libtiff/tiff.h: Don't do special type handling in tiff.h unless - USING_VISUALAGE is defined. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=39 - -2002-10-03 Frank Warmerdam - - * libtiff/tiff.h: added COMPRESSION_JP2000. - -2002-10-02 Andrey Kiselev - - * libtiff/tif_dirread.c: Another fix for the fetching SBYTE arrays - by the TIFFFetchByteArray() function. Should finally resolve - - http://bugzilla.remotesensing.org/show_bug.cgi?id=52 - - * configure: Set -DPIXARLOG_SUPPORT option along with -DZIP_SUPPORT - - * html/Makefile.in: New targets added: html and groffhtml for - producing HTML representations of the manual pages automatically. - html target uses man2html tool, groffhtml uses groff tool. - -2002-09-29 Frank Warmerdam - - * configure, libtiff/Makefile.in: Added SCO OpenServer 5.0.6 support - from John H. DuBois III. - -2002-09-15 Andrey Kiselev - - * Makefile.in, /man/{raw2tiff.1, Makefile.in, libtiff.3}: Added - manual page for raw2tiff(1) tool. - -2002-09-12 Andrey Kiselev - - * /libtiff/{tiffio.h, tif_dir.h}: TIFFDataWidth() declaration moved to - the tiffio.h header file. - - * Makefile.in, /man/{TIFFDataWidth.3t, Makefile.in, libtiff.3}: Added - manual page for TIFFDataWidth() function - -2002-09-08 Frank Warmerdam - - * libtiff/tif_dirread.c: Expand v[2] to v[4] in TIFFFetchShortPair() - as per http://bugzilla.remotesensing.org/show_bug.cgi?id=196. - - * tools/tiff2ps.c: Don't emit BeginData/EndData DSC comments - since we are unable to properly include the amount to skip. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=80 - -2002-09-02 Andrey Kiselev - - * /libtiff/tif_dirread.c: Fixed problem with SBYTE type data fetching - in TIFFFetchByteArray(). Problem described at - http://bugzilla.remotesensing.org/show_bug.cgi?id=52 - -2002-08-22 Andrey Kiselev - - * /libtiff/tif_dirinfo.c: Further additions to free custom fields - in _TIFFSetupFieldInfo() function. - See http://bugzilla.remotesensing.org/show_bug.cgi?id=169 for details. - - * /libtiff/tif_lzw.c: Additional consistency checking added in - LZWDecode() and LZWDecodeCompat(). - Fixes http://bugzilla.remotesensing.org/show_bug.cgi?id=190 - and http://bugzilla.remotesensing.org/show_bug.cgi?id=100 - - * /libtiff/tif_lzw.c: - Added check for valid code lengths in LZWDecode() and - LZWDecodeCompat(). Fixes - http://bugzilla.remotesensing.org/show_bug.cgi?id=115 - -2002-08-16 Andrey Kiselev - - * /libtiff/{Makefile.vc, libtiff.def}: - Missed declarations added. - -2002-08-15 Frank Warmerdam - - * tif_getimage.c: Ensure that TIFFRGBAImageBegin() returns the - return code from the underlying pick function. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=177 - - * tif_dir.h: changed FIELD_CODEC to 66 from 64 to avoid overlap - with FIELD_CUSTOM as mentioned in bug 169. - - * tif_close.c: added logic to free dynamically created anonymous - field definitions to correct a small memory leak. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=169 - -2002-08-10 Andrey Kiselev - - * /tools/{raw2tiff.c, Makefile.in, Makefile.lcc, Makefile.vc}: - New tool: raw2tiff --- raw images to TIFF converter. No manual page yet. - -2002-07-31 Frank Warmerdam - - * libtiff/tif_jpeg.c: Fixed problem with setting of nrows in - JPEGDecode() as per bugzilla bug (issue 1): - - http://bugzilla.remotesensing.org/show_bug.cgi?id=129 - - * libtiff/{tif_jpeg.c,tif_strip.c,tif_print.c}: Hacked tif_jpeg.c to - fetch TIFFTAG_YCBCRSUBSAMPLING from the jpeg data stream if it isn't - present in the tiff tags. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=168 - - * libtiff/tif_read.c, libtiff/tif_write.c: TIFFReadScanline() and - TIFFWriteScanline() now set tif_row explicitly in case the codec has - fooled with the value. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=129 - -2002-06-22 Andrey Kiselev - - * /tools/tiff2ps.c: Added workaround for some software that may crash - when last strip of image contains fewer number of scanlines than - specified by the `/Height' variable. See - http://bugzilla.remotesensing.org/show_bug.cgi?id=164 - for explanation. - -2002-06-21 Andrey Kiselev - - * tools/tiff2ps, man/tiff2ps.1: New functionality for tiff2ps utility: - splitting long images in several pages. See - http://bugzilla.remotesensing.org/show_bug.cgi?id=142 for explanation. - Patch granted by John Williams . - -2002-06-11 Frank Warmerdam - - * libtiff/contrib/win95: renamed to contrib/win_dib. Added new - Tiffile.cpp example of converting TIFF files into a DIB on Win32. - This one is described in: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=143 - - * libtiff/tif_ojpeg.c: Major upgrade from Scott. See details at: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=156 - -2002-05-10 Andrey Kiselev - - * tools/tiff2ps: New commandline switches to override resolution - units obtained from the input file. Closes - http://bugzilla.remotesensing.org/show_bug.cgi?id=131 - -2002-04-26 Andrey Kiselev - - * libtiff/libtiff.def: Added missed declaration. - -2002-04-22 Andrey Kiselev - - * tools/fax2tiff.c: Updated to reflect latest changes in libtiff. - Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=125 - -2002-04-20 Andrey Kiselev - - * libtiff/tif_open.c: Pointers to custom procedures - in TIFFClientOpen() are checked to be not NULL-pointers. - -2002-04-18 Andrey Kiselev - - * libtiff/libtiff.def: Added missed declarations. - - * libtiff/tif_pixarlog.c: Updated for using tif_tagmethods structure. - -2002-04-16 Andrey Kiselev - - * libtiff/tif_lzw.c: Additional checks for data integrity introduced. - Should finally close - http://bugzilla.remotesensing.org/show_bug.cgi?id=100 - -2002-04-10 Andrey Kiselev - - * tools/tiff2ps: Division by zero fixed. - Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=88 - -2002-04-09 Andrey Kiselev - - * libtiff/: tif_dirwrite.c, tif_write.c, tiffio.h: - TIFFCheckpointDirectory() routine added. - Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=124 - - * man/: TIFFWriteDirectory.3t, Makefile.in: Added description - for the new function. - -2002-04-08 Andrey Kiselev - - * libtiff/: tif_codec.c, tif_compress.c, tiffiop.h: Introduced - additional members tif->tif_decodestatus and tif->tif_encodestatus - for correct handling of unconfigured codecs (we should not try to read - data or to define data size without correct codecs). - - * libtiff/tif_getimage.c: The way of codecs checking in TIFFRGBAImageOK - changed. Now it has used tif->tif_decodestatus and - tif->tif_encodestatus. - Should fix http://bugzilla.remotesensing.org/show_bug.cgi?id=119 (in - case of __cvs_8.tif test image). - - * libtiff/: tif_dirinfo.c, tif_dirread.c: Somebody makes a bug in - tif_dirread.c when TIFFCreateAnonFieldInfo was introduced. - Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=119 in case - of _cvs_00000-00.tif, _cvs_00000-01.tif and _cvs_00000-02.tif. - -2002-04-04 Andrey Kiselev - - * libtiff/: tif_lzw.c: Assertions in LZWDecode and LZWDecodeCompat - replaced by warnings. Now libtiff should read corrupted LZW-compressed - files by skipping bad strips. - Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=100 - -2002-04-03 Frank Warmerdam - - * libtiff/tif_dirwrite.c: Removed some dead code. - - * libtiff/*: Cleanup some warnings. - - * libtiff/tif_dir.c: Fixed bug with count returned by TIFFGetField() - for variable length FIELD_CUSTOM values. Was int * but should be - u_short *. - -2002-04-01 Andrey Kiselev - - * tools/: tifcp.c: Added support for 'Orientation' tag in tiffcp - utility (at cpStripToTile routine). - -2002-03-27 Frank Warmerdam - - * tif_dirread.c: avoid div-by-zero if rowbytes is zero in chop func. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=111 - - * tif_print.c: Fixed so that ASCII FIELD_CUSTOM values with - passcount set FALSE can be printed (such as TIFFTAG_SOFTWARE). - - * libtiff/tif_dir.c,tif_dirinfo.c,tif_dir.h,tif_ojpeg.c: modified so - that TIFFTAG_SOFTWARE uses FIELD_CUSTOM as an example. - -2002-03-26 Dwight Kelly - - * libtiff/: tiff.h, tif_dir.c, tif_dir.h, tif_dirinfo.c, tif_dirread.c, - tif_dirwrite.c: Added get/put code for new tag XMLPACKET as defined - in Adobe XMP Technote. Added missing INKSET tag value from TIFF 6.0 spec - INKSET_MULTIINK (=2). Added missing tags from Adobe TIFF technotes: - CLIPPATH, XCLIPPATHUNITS, YCLIPPATHUNITS, OPIIMAGEID, OPIPROXY and - INDEXED. Added PHOTOMETRIC tag value from TIFF technote 4 ICCLAB (=9). - -2002-03-26 Andrey Kiselev - - * libtiff/: tif_getimage.c: TIFFReadRGBAStrip and TIFFReadRGBATile - now also uses TIFFRGBAImageOK before reading. This is additional fix - for http://bugzilla.remotesensing.org/show_bug.cgi?id=110 - -2002-03-25 Andrey Kiselev - - * libtiff/: tif_getimage.c: Additional check for supported - codecs added in TIFFRGBAImageOK and TIFFReadRGBAImage now uses - TIFFRGBAImageOK before reading. - Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=110 - -2002-03-15 Andrey Kiselev - - * libtiff/: tif_dir.c, tif_dir.h, tif_dirinfo.c, tif_dirread.c, - tif_dirwrite.c: Added routine TIFFDataWidth for detrmining - TIFFDataType sizes instead of working with tiffDataWidth array - directly. Should prevent out-of-borders bugs in case of unknown or - broken data types. EstimateStripByteCounts routine modified, so it - won't work when tags with uknown sizes founded. - Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=109 - -2002-03-13 Andrey Kiselev - - * libtiff/tif_getimage.c: Added support for correct handling - `Orientation' tag in gtTileContig. Should be added in other gt* - functions as well, but I have not images for testing yet. Partially - resolves http://bugzilla.remotesensing.org/show_bug.cgi?id=23 - -2002-03-10 Andrey Kiselev - - * libtiff/: tif_dirinfo.c, tif_dirwrite.c: Added possibility to - read broken TIFFs with LONG type used for TIFFTAG_COMPRESSION, - TIFFTAG_BITSPERSAMPLE, TIFFTAG_PHOTOMETRIC. Closes - http://bugzilla.remotesensing.org/show_bug.cgi?id=99 - -2002-03-08 Andrey Kiselev - - * libtiff/Makefile.in, tools/Makefile.in: Shared library will not - be stripped when installing, utility binaries will do. Closes - http://bugzilla.remotesensing.org/show_bug.cgi?id=93 - -2002-02-28 Frank Warmerdam - - * man/TIFFGetField: fixed type of TIFFTAG_COPYRIGHT. - - * man/libtiff.3t: added copyright tag info. - -2002-02-11 Frank Warmerdam - - * libtiff/{tiff.h,tif_fax3.c}: Add support for __arch64__. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=94 - - * man/Makefile.in: Patch DESTDIR handling - - http://bugzilla.remotesensing.org/show_bug.cgi?id=95 - - * configure: OpenBSD changes for Sparc64 and DSO version. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=96 - -2002-02-05 Frank Warmerdam - - * config.site/configure: added support for OJPEG=yes option to enable - OJPEG support from config.site. - -2002-01-27 Frank Warmerdam - - * html/document.html: fixed links for TIFf 6 docs. - -2002-01-18 Frank Warmerdam - - * config.guess, config.sub: Updated from ftp.gnu.org/pub/config. - - * libtiff/tif_read.c: Fixed TIFFReadEncodedStrip() to fail if the - decodestrip function returns anything not greater than zero as per - http://bugzilla.remotesensing.org/show_bug.cgi?id=97 - - * configure: Modify CheckForBigEndian so it can work in a cross - compiled situation. - -2002-01-16 Frank Warmerdam - - * tools/tiffdump.c: include TIFFTAG_JPEGTABLES in tag list. - - * tools/tiffset.c: fix bug in error reporting. - - * tools/tiffcp.c: fix several warnings that show up with -Wall. - -2002-01-04 Frank Warmerdam - - * libtiff/tif_jpeg.c: fixed computation of segment_width for - tiles files to avoid error about it not matching the - cinfo.d.image_width values ("JPEGPreDecode: Improper JPEG strip/tile - size.") for ITIFF files. Apparently the problem was incorporated since - 3.5.5, presumably during the OJPEG/JPEG work recently. - -2001-12-15 Frank Warmerdam - - * configure, libtiff/Makefile.in: Changes for building on MacOS 10.1. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=94 - - * libtiff/tif_getimage.c: If DEFAULT_EXTRASAMPLE_AS_ALPHA is 1 - (defined in tiffconf.h - 1 by default) then the RGBA interface - will assume that a fourth extra sample is ASSOCALPHA if the - EXTRASAMPLE value isn't set for it. This changes the behaviour of - the library, but makes it work better with RGBA files produced by - lots of applications that don't mark the alpha values properly. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=93 - http://bugzilla.remotesensing.org/show_bug.cgi?id=65 - -2001-12-12 Frank Warmerdam - - * libtiff/tif_jpeg.c: allow jpeg data stream sampling values to - override those from tiff directory. This makes this work with - ImageGear generated files. - -2001-12-07 Frank Warmerdam - - * html/Makefile.in: added missing images per bug 92. - - * port/Makefile.in: fixed clean target per bug 92. - -2001-11-28 Frank Warmerdam - - * Reissue 3.5.7 release. - - * libtiff/mkversion.c: Fix output of TIFF_VERSION to be - YYYYMMDD so that it is increasing over time. - - * Makefile.in: Ensure that tiffvers.h is regenerated in the - make release target. - - * Makefile.in: added libtiff/tiffvers.h to the release file list. - -2001-11-23 Frank Warmerdam - - * added html/v3.5.7.html, updated html/index.html. - - * Makefile.in: added contrib/addtiffo/tif_ovrcache.{c,h}. - -2001-11-15 Frank Warmerdam - - * configure: fixed test for -lm. - -2001-11-02 Frank Warmerdam - - * Added PHOTOMETRIC_ITULAB as per bug 90. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=90 - -2001-10-10 Frank Warmerdam - - * libtiff/tiff.h: I have created COMPRESSION_CCITT_T4, - COMPRESSION_CCITT_T6, TIFFTAG_T4OPTIONS and TIFFTAG_T6OPTIONS aliases - in keeping with TIFF 6.0 standard in tiff.h - - http://bugzilla.remotesensing.org/show_bug.cgi?id=83 - -2001-09-26 Frank Warmerdam - - * libtiff/tif_dirwrite.c: added TIFFRewriteDirectory() function. - Updated TIFFWriteDirectory man page to include TIFFRewriteDirectory. - -2001-09-24 Frank Warmerdam - - * libtiff/tif_lzw.c: Avoid MS VC++ 5.0 optimization bug. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=78 - - * libtiff/tif_lzw.c: added dummy LZWSetupEncode() to report an - error about LZW not being available. - - * libtiff/tif_dir.c: propagate failure to initialize compression - back from TIFFSetField() as an error status, so applications can - detect failure. - - * libtiff/tif_dir.c: removed the auto replacement of - COMPRESSION_LZW with COMPRESSION_NONE in _TIFFVSetField(). - - * Removed Makefile, tools/Makefile, port/install.sh, man/Makefile - from CVS as they are all supposed to be auto-generated by configure. - -2001-09-22 Frank Warmerdam - - * libtiff/tif_ojpeg.c: new update from Scott. - -2001-09-09 Frank Warmerdam - - * libtif/tif_fax3.c: Removed #ifdef PURIFY logic, and modified to - always use the "safe" version, even if there is a very slight - cost in performance. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=54 - - * libtiff/Makefile.in: Fixed @DSOSUB_VERSION to be @DSOSUF_VERSION@ - in two places. - - * libtiff/tif_getimage.c: Fixed problem with reading strips or - tiles that don't start on a tile boundary. Fix contributed by - Josep Vallverdu (from HP), and further described in bug 47. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=47 - - * tools/tiff2ps.c: added OJPEG YCbCr to RGB support. - - * libtiff/tif_ojpeg.c: Applied substantial patch from Scott. - -2001-09-06 Frank Warmerdam - - * libtiff/tif_packbits.c: fixed memory overrun error. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=77 - -2001-08-31 Frank Warmerdam - - * libtiff/tif_getimage.c: relax handling of contig case where - there are extra samples that are supposed to be ignored. This - should now work for 8bit greyscale or palletted images. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=75 - -2001-08-28 Frank Warmerdam - - * libtiff/tif_getimage.c: Don't complain for CMYK (separated) - images with more than four samples per pixel. See: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=73 - -2001-08-10 Frank Warmerdam - - * libtiff/tif_getimage.c: Use memmove() instead of TIFFmemcpy() - in TIFFReadRGBATile() to avoid issues in cases of overlapping - buffers. See Bug 69 in Bugzilla. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=69 - - * tools/tiff2rgba.c: fixed getopt() call so that -b works again. - -2001-08-09 Frank Warmerdam - - * libtiff/tiff.h, libtiff/tif_fax3.c: added check for __LP64__ - when checking for 64 bit architectures as per bugzilla bug 67. - -2001-07-27 Frank Warmerdam - - * man/Makefile.in: add TIFFClientOpen link as per debian submitted - bug 66. - -2001-07-20 Frank Warmerdam - - * libtiff/tif_jpeg.c: Define HAVE_BOOLEAN on windows if RPCNDR.H - has been included. - -2001-07-19 Frank Warmerdam - - * libtiff/tif_open.c: Seek back to zero after failed read, - before writing header. - -2001-07-18 Frank Warmerdam - - * libtiff/tif_ojpeg.c: updates from Scott. Handles colors - much better. Now depends on having patched libjpeg as per - patch in contrib/ojpeg/*. - -2001-07-17 Frank Warmerdam - - * */Makefile.in: added DESTDIR support. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=60 - -2001-07-16 Frank Warmerdam - - * configure, libtiff/Makefile.in: applied OpenBSD patches - as per: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=61 - -2001-06-28 Frank Warmerdam - - * libtiff/tif_getimage.c: Fixed so that failure is properly - reported by gtTileContig, gtStripContig, gtTileSeparate and - gtStripSeparate. - - See http://bugzilla.remotesensing.org/show_bug.cgi?id=51 - - * tiffcmp.c: Fixed multi samples per pixel support for ContigCompare. - Updated bug section of tiffcmp.1 to note tiled file issues. - - See http://bugzilla.remotesensing.org/show_bug.cgi?id=53 - -2001-06-22 Frank Warmerdam - - * configure: Changes for DSO generation on AIX provided by - John Marquart . - - * configure, libtiff/Makeifle.in: Modified to build DSOs properly - on Darwin thanks to Robert Krajewski (rpk@alum.mit.edu) and - Keisuke Fujii (fujiik@jlcuxf.kek.jp). - -2001-06-13 Frank Warmerdam - - * tools/tiff2rgba.c: added -n flag to avoid emitting alpha component. - - * man/tiff2rgba.1: new - -2001-05-22 Frank Warmerdam - - * Added tiffset and tif_ojpeg to the dist lists in Makefile.in. - -2001-05-13 Frank Warmerdam - - * libtiff/tools/thumbnail.c: changed default output compression - to packbits from LZW since LZW isn't generally available. - -2001-05-12 Frank Warmerdam - - * libtiff/tif_ojpeg.c: New. - libtiff/tif_jpeg.c, tiffconf.h, tif_getimage.c: changes related - to OJPEG support. - - Scott Marovich supplied OJPEG support. - -2001-05-11 Frank Warmerdam - - * tiff.h: removed, it duplicates libtiff/tiff.h. - -2001-05-08 Frank Warmerdam - - * libtiff/tif_dirinfo.c: moved pixar and copyright flags to - ensure everything is in order. - - * libtiff/libtiff.def: added TIFFCreateDirectory and - TIFFDefaultStripSize as per: - - http://bugzilla.remotesensing.org/show_bug.cgi?id=46 - -2001-05-02 Frank Warmerdam - - * libtiff/tif_dirinfo.c: Modified the TIFF_BYTE definition for - TIFFTAG_PHOTOSHOP to use a writecount of TIFF_VARIABLE2 (-3) to - force use of uint32 counts instead of short counts. - - * libtiff/tif_dirwrite.c: Added support for TIFF_VARIABLE2 in the - case of writing TIFF_BYTE/TIFF_SBYTE fields. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=43 - -2001-05-01 Frank Warmerdam - - * libtiff/tif_dirinfo.c: removed duplicate TIFFTAG_PHOTOSHOP as per - bug report http://bugzilla.remotesensing.org/show_bug.cgi?id=44 - -2001-04-05 Frank Warmerdam - - * tiffio.h: removed C++ style comment. - - * configure: fixed up SCRIPT_SH/SHELL handling. - - * Makefile.in: Fixed SCRIPT_SH/SHELL handling. - - * config.guess: documented more variables as per bug 40. - -2001-04-03 Frank Warmerdam - - * configure, *Makefile.in: Various changes to improve configuration - for HP/UX specifically, and also in general. They include: - - Try to handle /usr/bin/sh instead of /bin/sh where necessary. - - Upgrade to HP/UX 10.x+ compiler, linker and dso options. - - Fixed mmap() test to avoid MMAP_FIXED ... it isn't available on HP - - Use -${MAKEFLAGS} in sub makes from makefiles. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=40 - -2001-04-02 Frank Warmerdam - - * libtiff/tiff.h: Applied hac to try and resolve the problem - with the inttypes.h include file on AIX. - - See http://bugzilla.remotesensing.org/show_bug.cgi?id=39 - - * VERSION: update to 3.5.7 beta in preparation for release. - - * configure/config.site: modified to check if -lm is needed for - MACHDEPLIBS if not supplied by config.site. Needed for Darwin. - - * config.guess: updated wholesale to an FSF version apparently - from 1998 (as opposed to 1994). This is mainly inspired by - providing for MacOS X support. - -2001-03-29 Frank Warmerdam - - * configure, Makefile.in, etc: added support for OPTIMIZER being - set from config.site. - -2001-03-28 Frank Warmerdam - - * fax2ps.c: Helge (libtiff at oldach.net) submitted fix: - - Here's a fix for fax2ps that corrects behaviour for non-Letter paper - sizes. It fixes two problems: - - Without scaling (-S) the fax is now centered on the page size specified - with -H and/or -W. Before, fax2ps was using an obscure and practially - useless algorithm to allocate the image relative to Letter sized paper - which sometime sled to useless whitespace on the paper, while at the - same time cutting of the faxes printable area at the opposite border. - - Second, scaling now preserves aspect ratio, which makes unusual faxes - (in particular short ones) print properly. - - See http://bugzilla.remotesensing.org/show_bug.cgi?id=35 - - * tiff2ps.c/tiff2ps.1: Substantial changes to tiff2ps by - Bruce A. Mallett. See check message for detailed information - on all the changes, including a faster encoder, fixes for level - 2 PostScript, and support for the imagemask operator. - -2001-03-27 Frank Warmerdam - - * libtiff/tiffio.h: Changed "#if LOGLUV_PUBLIC" to - "#ifdef LOGLUV_PUBLIC" so it will work with VisualAge on AIX. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=39 - -2001-03-16 Frank Warmerdam - - * tif_dirinfo.c: moved definition of copyright tag in field list. - Apparently they have to be in sorted order by tag id. - -2001-03-13 Frank Warmerdam - - * tif_getimage.c: Added support for 16bit minisblack/miniswhite - images in RGBA interface. - -2001-03-02 Frank Warmerdam - - * Added TIFFTAG_COPYRIGHT support. - -2001-02-19 Frank Warmerdam - - * Brent Roman contributed updated tiffcp utility (and tiffcp.1) - with support for extracting subimages with the ,n syntax, and also - adding the -b bias removal flag. - -2001-02-16 Frank Warmerdam - - * libtiff/libtiff.def: Brent Roman submitted new version adding - serveral missing entry points. - - * libtiff/tif_dirinfo.c: don't declare tiffFieldInfo static on VMS. - Some sort of weird VMS thing. - - http://bugzilla.remotesensing.org/show_bug.cgi?id=31 - - * tif_luv.c/tiff.h/tiffio.h: - New version of TIFF LogLuv (SGILOG) modules contributed by Greg Ward - (greg@shutterfly.com). He writes: - - 1) I improved the gamut-mapping function in tif_luv.c for imaginary - colors, because some images were being super-saturated on the input - side and this resulted in some strange color shifts in the output. - - 2) I added a psuedotag in tiff.h to control random dithering during - LogLuv encoding. This is turned off by default for 32-bit LogLuv and - on for 24-bit LogLuv output. Dithering improves the average color - accuracy over the image. - - 3) I added a #define for LOG_LUV_PUBLIC, which is enabled by default in - tiffio.h, to expose internal routines for converting between LogLuv and - XYZ coordinates. This is helpful for writing more efficient, - specialized conversion routines, especially for reading LogLuv files. - - Changes applied with minor edits. - -2001-01-23 Frank Warmerdam - - * tif_fax3.c: keep rw_mode flag internal to fax3 state to remember - whether we are encoding or decoding. This is to ensure graceful - recovery if TIFFClientOpen() discovers an attempt to open a compressed - file for "r+" access, and subsequently close it, as it resets the - tif_mode flag to O_RDONLY in this case to avoid writes, confusing the - compressor's concept of whether it is in encode or decode mode. - -2001-01-08 Mike Welles - - * Makefile.in: Now cleaning up after itself after creating the .tar.gz and .zip - -2001-01-07 Frank Warmerdam - - * html/libtiff.html: Fixed arguments in example for TIFFRGBAImageGet() - as per bug report by Patrick Connor. - -2000-12-28 Frank Warmerdam - - * Added RELEASE-DATE file to release file list. - - * Fixed libtiff/makefile.vc to make tiffvers.h not version.h. - -2000-12-22 Mike Welles - * added link to CVS mirror from index.html - - * updated html/internals.html to note that LZW compression is - not supported by default. - -2000-12-22 Frank Warmerdam - - * updated html/libtiff.html to not point at Niles' old JPL web site - for the man pages, point at www.libtiff.org. - -2000-12-21 Frank Warmerdam - - * libtiff/tif_apple.c: Applied "Carbon" support patches supplied by - Leonard Rosenthol . May interfere - with correct building on older systems. If so, please let me know. - -2000-12-19 Mike Welles - - * Took out LZW Encoding from tif_lzw.c - - * Created HOWTO-RELEASE - - * Created html/v3.5.6.html - - * updated index.html - -2000-12-01 Frank Warmerdam - - * Added patches for EOFB support in tif_fax3.c and tif_fax3.h. - Patches supplied by Frank Cringle - Example file at: ftp://ftp.remotesensing.org/pub/libtiff/eofb_396.tif - -2000-11-24 Frank Warmerdam - - * libtiff/Makefile.in: Added an installPrivateHdrs and install-private - target so that the private headers required by libgeotiff can be - installed with the others. They are not installed by default. - - * libtiff/Makefile.in: Added @MACHLIBDEPS@ to LINUXdso and GNULDdso - targets so libtiff.so will be built with an explicit dependency - on libm.so. - - * libtiff/Makefile.in: Use softlinks to link libtiff.so.3 to - libtiff.so.3.5.5. - - * libtiff/Makefile.in & configure: Remove all references to the ALPHA - file, or ALPHA version logic. Added stuff about DIST_POINT in - place of DIST_TYPE and the alpha release number stuff. - -2000-11-22 Frank Warmerdam - - * I have applied a patch from Steffen Moeller to - the configure script so that it now accepts the --prefix, and - --exec-prefix directives. - -2000-11-13 Frank Warmerdam - - * I have made a variety of modifications in an effort to ensure the - TIFFLIB_VERSION macro is automatically generated from the RELEASE-DATE - file which seems to be updated regularly. - - o mkversion.c now reads RELEASE-DATE and emits TIFFLIB_VERSION in - version include file. - o renamed version.h to tiffvers.h because we now have to install it - with the public libtiff include files. - o include tiffvers.h in tiffio.h. - o updated tif_version.c to use tiffvers.h. - o Updated Makefile.in accordingly. - - * As per http://bugzilla.remotesensing.org/show_bug.cgi?id=25 - I have updated the win32 detection rules in tiffcomp.h. - -2000-10-20 Frank Warmerdam - - * tif_getimage.c: Fixed RGBA translation for YCbCr images for which - the strip/tile width and height aren't multiples of the sampling size. - See http://bugzilla.remotesensing.org/show_bug.cgi?id=20 - Some patches from Rick LaMont of Dot C Software. - - * Modified tif_packbits.c encoder to avoid compressing more - data than provided if rowsize doesn't factor into provided data - (such as occurs for YCbCr). - -2000-10-19 Frank Warmerdam - - * tools/rgb2ycbcr.c: fixed output strip size to account for vertical - roundup if rows_per_strip not a multiple of vertical sample size. - -2000-10-16 Frank Warmerdam - - * tif_dir.c: Clear TIFF_ISTILED flag in TIFFDefaultDirectory - as per http://bugzilla.remotesensing.org/show_bug.cgi?id=18 - from vandrove@vc.cvut.cz. - - * Modified tif_packbits.c decoding to avoid overrunning the - output buffer, and to issue a warning if data needs to be - discarded. See http://bugzilla.remotesensing.org/show_bug.cgi?id=18 - -2000-10-12 Frank Warmerdam - - * Modified tiff2bw to ensure portions add to 100%, and that - white is properly recovered. - - See bug http://bugzilla.remotesensing.org/show_bug.cgi?id=15 - Patch c/o Stanislav Brabec - -2000-09-30 Frank Warmerdam - - * Modified TIFFClientOpen() to emit an error on an attempt to - open a comperessed file for update (O_RDWR/r+) access. This is - because the compressor/decompressor code gets very confused when - the mode is O_RDWR, assuming this means writing only. See - bug http://bugzilla.remotesensing.org/show_bug.cgi?id=13 - -2000-09-27 Frank Warmerdam - - * Added GNULDdso target an`d switched linux and freebsd to use it. - -2000-09-26 Frank Warmerdam - - * Applied patch for 0x0000 sequences in tif_fax3.h's definition - of EXPAND1D() as per bug 11 (from Roman). - -2000-09-25 Frank Warmerdam - * Fixed tiffcomp.h to avoid win32 stuff if unix #defined, to improve - cygwin compatibility. - - * Applied patch from Roman Shpount to tif_fax3.c. This seems to - be a proper fix to the buffer sizing problem. See - http://bugzilla.remotesensing.org/show_bug.cgi?id=11 - - * Fixed tif_getimage.c to fix overrun bug with YCbCr images without - downsampling. http://bugzilla.remotesensing.org/show_bug.cgi?id=10 - Thanks to Nick Lamb for reporting the - bug and proving the patch. - -2000-09-18 Frank Warmerdam - - * Fixed tif_jpeg.c so avoid destroying the decompressor before - we are done access data thanks to bug report from: - Michael Eckstein . - - * Reverted tif_flush change. - -2000-09-14 Frank Warmerdam - - * tif_flush.c: Changed so that TIFFFlushData() doesn't return an - error when TIFF_BEENWRITING is not set. This ensures that the - directory contents can still be flushed by TIFFFlush(). - -2000-08-14 Frank Warmerdam - - * tif_open.c: Don't set MMAP for O_RDWR files. - - * tif_open.c: Set STRIPCHOP_DEFAULT for O_RDWR as well as O_RDONLY - so that files opened for update can be strip chopped too. - - * tif_read.c: fixed up bug with files missing rowsperstrip and - the strips per separation fix done a few weeks ago. - -2000-07-17 Frank Warmerdam - - * Tentatively added support for SAMPLEFORMAT_COMPLEXIEEEFP, and - SAMPLEFORMAT_COMPLEXINT. - -2000-07-13 Mike Welles - - * index.html, bugs.html: added bugzilla info. - -2000-07-12 Frank Warmerdam - - * tif_read.c: fix subtle bug with determining the number of - rows for strips that are the last strip in a separation but - not the last strip of all in TIFFReadEncodedStrip(). - - * Applied 16/32 bit fix to tif_fax3.c. Fix supplied by - Peter Skarpetis - -2000-06-15 Frank Warmerdam - - * Modified tiffio.h logic with regard to including windows.h. It - won't include it when building with __CYGWIN__. - -2000-05-11 Frank Warmerdam - - * README: update to mention www.libtiff.org, don't list Sam's old - email address. - - * configure: Fixed DSO test for Linux as per patch from - Jan Van Buggenhout . - -2000-04-21 Frank Warmerdam - - * libtiff/tif_dirread.c: Don't use estimate strip byte count for - one tile/strip images with an offset, and byte count of zero. These - could be "unpopulated" images. - -2000-04-18 Frank Warmerdam - - * contrib/addtiffo: Added "averaging" resampling option. - - * tools/tiffsplit.c: Copy TIFFTAG_SAMPLEFORMAT. - -Tue Apr 18 16:18:08 2000 Frank Warmerdam - - * tools/Makefile.in: Modified to install properly on SGI. - -2000-04-12 Mike Welles - * configure: Fixed stupid mistake in libc6 test on Linux - -2000-04-04 Mike Welles - * tif_win32.c: Applied patch to fix overreads and ovverwrites - caught by BoundsChecker. From Arvan Pritchard - (untested). - - * tif_getimage.c: Applied patch to silence VC6 warnings. From - Arvan Pritchard - - * tif_lzw.c: Applied patch to silence VC6 warnings. From - Arvan Pritchard - -2000-03-28 Frank Warmerdam - - * Added contrib/stream (stream io) code submitted by Avi Bleiweiss. - -2000-03-28 Frank Warmerdam *** 3.5.5 release *** - - * fax2ps: Fixed mixup of width and height in bounding box statement - as per submission by Nalin Dahyabhai . - -2000-03-27 Mike Welles - - * fax2ps: Modified printruns to take uint32 instead of uint16. - Patch courtesy of Bernt Herd - -2000-03-20 Mike Welles - - * configure: added test for libc6 for linux targets. Bug reported by - Stanislav Brabec - - * Added 3.5 docs to html/Makefile.in. - Thanks to Stanislav Brabec - - * configure: fixed bugs in sed scripts - (applied sed script s:/@:s;@:;s:/s;;:;: to configure). - fix submitted to Stanislav Brabec - - * tools/iptcutil was not in files list, and wasn't being - added to tar archive. Updated Makefile.in. - -2000-03-17 Frank Warmerdam - - * tif_fax3.c: Fixed serious bug introduced during the uint16->uint32 - conversion for the run arrays. - -2000-03-03 Frank Warmerdam - - * Set td_sampleformat default to SAMPLEFORMAT_UINT instead of - SAMPLEFORMAT_VOID in TIFFDefaultDirectory() in tif_dir.c. - -2000-03-02 Frank Warmerdam - - * Added "GetDefaulted" support for TIFFTAG_SAMPLEFORMAT in tif_aux.c. - - * Patched tif_fax3.c so that dsp->runs is allocated a bit bigger - to avoid overruns encountered with frle_bug.tif. - -Tue Feb 15 22:01:05 2000 Frank Warmerdam - - * Fixed tools/tiffcmp so that stopondiff testing works. - Patch care of Joseph Orost . - -2000-01-28 - - * Modified tif_unix.c to support 2-4GB seeks if USE_64BIT_API is - set to 1, and added default (off) setting in tiffconf.h. This - should eventually be set by the configure script somehow. - - The original work on all these 2-4GB changes was done by - Peter Smith (psmith@creo.com). - - * Modified tif_win32.c to support 2-4GB seeks. - - * tentatively changed toff_t to be unsigned instead of signed to - facilitate support for 2-4GB files. - - * Updated a variety of files to use toff_t. Fixed some mixups - between toff_t and tsize_t. - -Fri Jan 28 10:13:49 2000 Frank Warmerdam - - * Largely reimplemented contrib/addtiffo to avoid temp files, - updating the TIFF file in place. Fixed a few other bugs to. - - * Set tif_rawdatasize to zero when freeing raw data buffer in - TIFFWriteDirectory(). - - * Enabled "REWRITE_HACK" in tif_write.c by default. - - * Fix bug in tif_write.c when switching between reading one directory - and writing to another. - - * Made TIFFWriteCheck() public, and added TIFFCreateDirectory() - -Wed Jan 5 12:37:48 2000 Frank Warmerdam - - * Added TIFFmemory(3t) functions to libtiff.def. - -Tue Jan 4 13:39:00 2000 Frank Warmerdam - - * Added libtiff/libtiff.def to TIFFILES distribution list. - -Mon Dec 27 12:13:39 EST 1999 Mike Welles - - * Created lzw compression kit, as a new module (libtiff-lzw-compression-kit). - - * Altered descriptions in tools to reflect "by default" lzw not supported - - * Updated index.html to note lzw compression kit. - -Tue Dec 21 14:01:51 1999 Frank Warmerdam - - * Added fax3sm_winnt.c to distribution list in Makefile.in. - -Tue Dec 21 11:04:45 EST 1999 Mike Welles *** 3.5.4 release *** - - * Aadded Pixar tag support. Contributed by Phil Beffery - - * Made one more change to tif_dir.c for removal of LZW compression. Also added notice - when LZW compression invoked. - - * Changed default compression in tools to TIFF_PACKBITS, and changed usage descriptions - in tools to reflect removal of LZW compression - -Mon Dec 20 18:39:02 EST 1999 Mike Welles - - * Fixed bug that caused LZW (non) compression to segfault. Added - warning about LZW compression removed being removed, and why. - - * Added nostrip to install in tools/Makefile.in so that debugging - symbols are kept. - -Tue Dec 7 12:04:47 EST 1999 Mike Welles - - * Added patch from Ivo Penzar , - supporting Adobe ZIP deflate. Untested. - -Sat Dec 4 15:47:11 1999 Frank Warmerdam - - * Made Packbits the default compression in tools/tiff2rgba.c instead - of LZW. - -Tue Nov 30 14:41:43 1999 Frank Warmerdam *** 3.5.3. release *** - - * Added tif_luv to contrib/djgpp/Makefile.lib. - -Tue Nov 30 14:15:32 EST 1999 Mike Welles - - * Added zip creation to relase makefile target - - * Added html for TIFFWriteTile.3t man page. - -Tue Nov 30 09:20:16 1999 Frank Warmerdam - - * Added some changes to tif_write.c to support rewriting existing - fixed sized tiles and strips. Code mods disabled by default, only - enabled if REWRITE_HACK is defined for now. - -Mon Nov 29 11:43:42 1999 Frank Warmerdam - - * Added TIFFWriteTile.3t man page. - -Sun Nov 28 20:36:18 1999 Frank Warmerdam - - * Added notes on use of makefile.vc in build.html, and fixed - email subscription address. - -199-11-28 Mike Welles - - * Fixed apocalypse-inducing y2k bug in contrib/ras/ras2tiff.c - - * Did some casts cleaning up to reduce compiler warnings in tif_fax3.c, - from Bruce Carmeron -- modifications of - changes made by Frank (sun cc still complained on cast). - - * Added tiffconf.h to install target per request from Bill - Radcliffe : "We need a way for ImageMagick to - know features have been compiled into the TIFF library in order to - handle things properly". - -Sat Nov 27 16:49:21 1999 Frank Warmerdam - - * fixed various VC++ warnings as suggested by Gilles Vollant - . - -Wed Nov 24 12:08:16 1999 Frank Warmerdam - - * Modified TIFFquery.3t man pages info on TIFFIsByteSwapped() to - not imply applications are responsible for image data swapping. - -1999-11-22 Mike Welles - * HTML-ized the man pages, added to html/man - - * Removed LZW Compression to comply with Unisys patent extortion. - -1999-09-29 Mike Welles - * Corrected one remaining 16 -> 32 bit value in tif_fax3.c, - From Ivo Penzar - -1999-09-26 Mike Welles *** 3.5.2 release *** - * Corrected alpha versioning. - - * Removed distinction between alpha and release targets in Makefile.in. - - * added release.stamp target, which tags cvs tree, and updates - "RELEASE-DATE" - - * added releasediff target, which diffs tree with source as of - date in "RELEASE-DATE" - - * Ticked up version to 3.5.2 (alpha 01 -- but I think we'll moving - away from alpha/non-alpha distinctions). - - * updated html to reflect release - -1999-09-23 - - * Set O_BINARY for tif_unix.c open() ... used on cygwin for instance. - - * Added CYGWIN case in configure. - -Fri Sep 17 00:13:51 CEST 1999 Mike Welles - - * Applied Francois Dagand's patch to handle fax decompression bug. - (sizes >= 65536 were failing) - -Tue Sep 14 21:31:43 1999 Frank Warmerdam - - * Applied "a" mode fix to tif_win32.c/TIFFOpen() as suggested - by Christopher Lawton - -Wed Sep 8 08:19:18 1999 Frank Warmerdam - - * Added IRIX/gcc, and OSF/1 4.x support on behalf of - Albert Chin-A-Young - - * Added TIFFReassignTagToIgnore() API on behalf of - Bruce Cameron . Man page still pending. - -Wed Aug 25 11:39:07 1999 Frank Warmerdam - - * Added test target in Makefile, test_pics.sh script and pics/*.rpt - files to provide for a rudimentary testsuite. - - * Added contrib/tags back from old distribution ... fixed up a bit. - -1999-08-16 - - * Added simple makefile.vc makefiles for building with MS VC++ - on Windows NT/98/95 in console mode. Stuff in contrib/win* make give - better solutions for some users. - -Mon Aug 16 21:52:11 1999 Frank Warmerdam - - * Added addtiffo (add overviews to a TIFF file) in contrib. Didn't - put it in tools since part of it is in C++. - -1999-08-16 Michael L. Welles - - * Updated html/index.html with anon CVS instructions. - -Mon Aug 16 13:18:41 1999 Frank Warmerdam - - * pre-remove so link before softlink in LINUXdso action in - libtiff/Makefile.in to avoid failure on LINUXdso builds other than - the first. - - * Fixed problem with cvtcmap() in tif_getimage.c modifying the - colormaps owned by the TIFF handle itself when trying to fixup wrong - (eight bit) colormaps. Corrected by maintaining a private copy of - the colormap. - - * Added TIFFReadRGBATile()/TIFFReadRGBAStrip() support in - tif_getimage.c. - - * CVS Repository placed at remotesensing.org. ChangeLog added. +2012-09-22 Bob Friesenhahn + + * libtiff 4.0.3 released. + +2012-09-20 Bob Friesenhahn + + * Makefile.am: Update to Automake 1.12.4 + +2012-08-19 Bob Friesenhahn + + * Makefile.in: Update to Automake 1.12.3 + + * libtiff{tiff.h, tif_print.c, tif_dirinfo.c, tif_dirread.c}: Add + some TIFF/FX support in libtiff. Add the tag definitions to + tiff.h. Add the related TIFF field definitions to tif_dirinfo.c, + and also fixes an error in a comment. Adds the photometric values + to tif_print.c, and fixes a bug. These changes are by Steve + Underwood. + +2012-08-13 Frank Warmerdam + + * libtiff/tif_write.c: Fix bug rewriting image tiles in a + compressed file: http://trac.osgeo.org/gdal/ticket/4771 + +2012-08-02 Frank Warmerdam + + * libtiff/tif_dirread.c: report error in case of mismatch value + counts for tags (ie. DotRange). + +2012-07-26 Tom Lane + + * libtiff/{tiffio.h, tif_dirinfo.c, libtiff.def}: Add six new + functions TIFFFieldTag(), TIFFFieldName(), TIFFFieldDataType(), + TIFFFieldPassCount(), TIFFFieldReadCount(), TIFFFieldWriteCount() + as external accessors for the opaque type TIFFField. + + * tools/tiffset.c: Make tiffset use the above functions instead of + relying on library private headers. + +2012-07-19 Tom Lane + + * tools/tiff2pdf.c: Fix two places where t2p_error didn't get set + after a malloc failure. No crash risk AFAICS, but the program + might not report exit code 1 as desired. h/t mancha@mac.hush.com + +2012-07-18 Tom Lane + + * tools/tiff2pdf.c: Fail when TIFFSetDirectory() fails. This + prevents core dumps or perhaps even arbitrary code execution when + processing a corrupt input file (CVE-2012-3401). + +2012-07-06 Bob Friesenhahn + + * test/raw_decode.c (main): Test fixes to work with IJG JPEG 7+. + IJG JPEG 7+ uses a different upsampling algorithm which produces + different numeric results. + + * libtiff/tif_jpeg.c (JPEGPreDecode): Patch from Even Rouault to + work with IJG JPEG 7+. + +2012-07-04 Bob Friesenhahn + + * test/raw_decode.c: Add changes so that test can run with build + directory outside of source directory. + +2012-07-02 Frank Warmerdam + + * libtiff/tif_jpeg.c: Fix handling when writing RGBA jpeg compressed + imagery (http://trac.osgeo.org/gdal/ticket/4732) + +2012-06-20 Frank Warmerdam + + * libtiff/tif_fax3.c: fix memory initialization of runs, only + partly done. + + * libtiff/tif_pixarlog.c: Make sure tbuf is large enough for one + full "stride" past the end. + +2012-06-19 Frank Warmerdam + + * libtiff/tif_packbits.c: fix read past end of data buffer. + +2012-06-15 Frank Warmerdam + + * libtiff 4.0.2 released. + + * tools/tif2pdf.c, tools/tifdump.c: avoid unitialized variable + warnings with clang. + +2012-06-15 Tom Lane + + * tools/tiff2pdf.c: Defend against integer overflows while + calculating required buffer sizes (CVE-2012-2113). + +2012-06-12 Frank Warmerdam + + * libtiff/tif_print.c: Be careful about printing corrupt inknames. + + * libtiff/tif_fax3.c: Ensure runs array is initialized to zeros. + +2012-06-07 Frank Warmerdam + + * libtiff/tif_print.c: avoid pretty printing other fields when + we don't have the proper amount and type of data or if the field + is actually autodefined. + +2012-06-05 Frank Warmerdam + + * libtiff/tif_tile.c, libtiff/tif_strip.c: Ensure that illegal + ycbcrsubsampling values result in a runtime error, not just an + assertion. + + * tests/custom_dir.c: Add testing of EXIF and custom directory + reading and writing. + + * libtiff/tif_dir.c, libtiff/tiffio.h: Add TIFFCreateCustomDirectory() + and TIFFCreateEXIFDirectory() functions. + + * libtiff/tif_dir.c, tif_print.c : Remove FIELD_CUSTOM handling for + PAGENUMBER, HALFTONEHINTS, and YCBCRSUBSAMPLING. Implement DOTRANGE + differently. This is to avoid using special TIFFGetField/TIFFSetField + rules for these fields in non-image directories (like EXIF). + +2012-06-04 Frank Warmerdam + + * libtiff/tif_jpeg.c: Remove code for fixing up h_sampling and v_sampling + in JPEGPreDecode(). If a fixup will be done it needs to be done sooner + in JPEGFixupTagsSubsampling() or else buffer sized may be wrong. + +2012-06-01 Frank Warmerdam + + * tools/tiffinfo.c: Do not try to read image data in EXIF directories. + + * libtiff/tif_getimage.c: added support for _SEPARATED CMYK images. + http://bugzilla.maptools.org/show_bug.cgi?id=2379 + + * libtiff/tif_unix.c: use strerror() to return a more specific error message + on failed open. + http://bugzilla.maptools.org/show_bug.cgi?id=2341 + + * libtiff/tif_jpeg.c: Fix JPEGDecodeRaw() bugs. + http://bugzilla.maptools.org/show_bug.cgi?id=2386 + + * tests/decode_raw.c, tests/images/quad-tile.jpg.tiff: add limited support + for testing jpeg in tiff image decoding including the "raw" decode interface. + +2012-05-31 Frank Warmerdam + + * libtiff/tif_jpeg.c: avoid overrunning the end of the output buffer in + JPEGDecodeRaw() - mostly likely to occur when there is confusion about + sampling values. + + * libtiff/tif_read.c: Make sure tif_rawdatasize is cleared when tif_rawdata is freed. + + * libtiff/tif_getimage.c: Add support for greyscale+alpha c/o Jérémie Laval. + http://bugzilla.maptools.org/show_bug.cgi?id=2398 + +2012-05-29 Frank Warmerdam + + * libtiff/tif_dir.c: avoid using specific set/get logic to process fields in custom directories, + like EXIF directories. This fixes problems like a tag "320" existing in a custom directory getting + processed as if it were a colormap when it isn't really. Damn the wide variety of argument formulations + to get/set functions for different tags! + + * libtiff/tif_dir.c: Ensure that we keep track of when tif_rawdata + is a pointer into an mmap()ed file via TIFF_BUFFERMMAP flag. + +2012-05-24 Frank Warmerdam + + * libtiff/tif_pixarlog.c: Allocate working buffer one word larger since we "forward + accumulate" and overwrite the end by one word in at least some cases. + +2012-05-23 Frank Warmerdam + + * libtiff/tif_pixarlog.c: avoid accessing out of the lookup arrays for out of range inputs. + + * tools/tiffinfo.c: initialize h=0 to avoid undefined variable for degenerate files. + + * libtiff/tif_ojpeg.c: if OJPEGWriteHeader() fails once do not bother trying again on + the same image. + + * libtiff/tif_ojpeg.c: make things more resilient in the face of files without + stripbytecounts or stripoffsets or where loading these fails. + + * libtiff/tif_print.c: be careful about whether min/max values are singular + or one per sample. + + * libtiff/tif_print.c: Avoid confusion about count size when printing custom fields. + May affect things like ISOSpeedRatings. + + * libtiff/tif_dir.c: avoid one byte past end of ink names reading + in some cases. + +2012-05-19 Bob Friesenhahn + + * man/TIFFGetField.3tiff: Correct the 'count' field type in the + example for how to retreive the value of unsupported tags. + +2012-03-30 Frank Warmerdam + + * tif_getimage.c: Fix size overflow (zdi-can-1221,CVE-2012-1173) + care of Tom Lane @ Red Hat. + +2012-02-18 Bob Friesenhahn + + * libtiff 4.0.1 released. + + * Update automake used to 1.11.3. + + * libtiff/tiffio.h: Use double-underbar syntax in GCC printf + attribute specification to lessen the risk of accidental macro + substitution. Patch from Vincent Torri. + +2012-01-31 Frank Warmerdam + + * libtiff/tif_dir.c, libtiff/tif_dirread.c: Extra caution around + assumption tag fetching is always successful. + + * libtiff/tif_jpeg.c: Extra caution for case where sp is NULL. + +2012-01-22 Bob Friesenhahn + + * configure.ac: Add support for using library symbol versioning on + ELF systems with the GNU linker. Support is enabled via + --enable-ld-version-script. Disabled by default for now until + there is a decision for how to deploy a libtiff with versioned + symbols after libtiff 4.0.0 was already released. + +2011-12-22 Bob Friesenhahn + + * libtiff/tif_win32.c: Eliminate some minor 64-bit warnings in + + tif_win32.c. Patch by Edward Lam. + + * configure.ac: Add libtiff private dependency on -llzma for + pkg-config. Patch by Mark Brand. + Updated Automake to 1.11.2. + +2011-12-21 Bob Friesenhahn + + * libtiff 4.0.0 released. + +2011-12-08 Frank Warmerdam + + * libtiff/tif_dirread.c, libtiff/tif_read.c: more cautious checking + of _TIFFFillStriles() results (#gdal 4372) + +2011-12-07 Frank Warmerdam + + * libtiff/tif_dirread.c: fixes to deal with invalid files where + _TIFFFillStriles() fails, and we try to chop up strips (gdal #4372) + + * libtiff/tif_dirread.c: fix error reporting when there is no + tag information struct and name (gdal #4373) + +2011-10-22 Bob Friesenhahn + + * Update GNU libtool to 2.4.2. + + * tools/tiffsplit.c (tiffcp): TIFFGetField count field should be + uint32 type for TIFFTAG_JPEGTABLES. Patch by Christophe + Deroulers. + +2011-06-21 Frank Warmerdam + + * libtiff/libtiff.def: Restore TIFFMergeFieldInfo. + +2011-05-31 Jim Meyering + + * libtiff/tif_dirread.c (TIFFFetchStripThing): Free "data" also + upon failure to allocate "resizeddata". + * tools/tiff2ps.c (PSDataBW): Zero buffer *after* checking for + allocation failure, not before. + * libtiff/tif_ojpeg.c: plug leaks on OJPEG read failure path + * tools/rgb2ycbcr.c (cvtRaster): unchecked malloc + * libtiff/tif_jpeg.c, tools/tiff2pdf.c, tools/tiff2ps.c: mark + NULL-deref and possible overflow + * tools/tiff2pdf.c: remove decl+set of set-but-not-used local, "written" + * libtiff/tif_jpeg.c (JPEGInitializeLibJPEG): Remove declaration + and set of otherwise unused local, data_is_empty. + * libtiff/tif_jpeg.c (JPEGDecodeRaw) [JPEG_LIB_MK1_OR_12BIT]: + Diagnose out-of-memory failure and return 0 rather than + dereferencing NULL. + +2011-05-24 Frank Warmerdam + + * libtiff/tif_dirread.c: produce special error message for zero tag + directories instead of error out on the malloc(0) failure. + +2011-05-16 Frank Warmerdam + + * libtiff/tif_dirinfo.c: Restore TIFFMergeFieldInfo() and + related declarations as they are in active use by libraries + such as libgeotiff, and work just fine. (#2315) + +2011-04-20 Frank Warmerdam + + * libtiff/tif_dirinfo.c,tiffio.h: Remove the obsolete + TIFFMergeFieldInfo/TIFFFindFieldInfo/TIFFFindFieldInfoByName API. + http://bugzilla.maptools.org/show_bug.cgi?id=2315 + + * libtiff/libtiff.def: add some missing (64bit) APIs. + http://bugzilla.maptools.org/show_bug.cgi?id=2316 + +2011-04-09 Bob Friesenhahn + + * libtiff 4.0.0beta7 released. + +2011-04-09 Bob Friesenhahn + + * configure.ac: Should use AC_CANONICAL_HOST since host specifies + the run-time target whereas target is used to specify the final + output target if the package is a build tool (like a compiler), + which libtiff is not. Resolves libtiff bug 2307 "Use + AC_CANONICAL_HOST macro". + +2011-04-02 Bob Friesenhahn + + * configure.ac: Support configuring TIFF_INT64_FORMAT and + TIFF_UINT64_FORMAT appropriately for MinGW32. + + * tools/tiffdump.c (ReadDirectory): MinGW32 needs to use WIN32 + printf conventions for 64-bit types because it uses the WIN32 CRT. + + * libtiff/{tif_dumpmode.c,tif_luv.c,tif_lzw.c,tif_print.c, + tif_read.c,tif_strip.c,tif_thunder.c}: MinGW32 needs to use WIN32 + printf conventions for 64-bit types because it uses the WIN32 CRT. + + * tools/tiff2pdf.c (t2p_write_pdf_string): Fix printf syntax not + understood by WIN32 CRT. + + * libtiff/tif_ojpeg.c: Fixes to compile with MinGW32 GCC. + + * tools/fax2ps.c (main): Use tmpfile() rather than mkstemp() since + it is much more portable. Tmpfile is included in ISO/IEC + 9899:1990 and the WIN32 CRT. + +2011-03-26 Frank Warmerdam + + * tools/tiffset.c: add -d and -sd switches to allow operation on + a particular directory, not just the first (jef). + +2011-03-21 Frank Warmerdam + + * libtiff/tif_thunder.c: Correct potential buffer overflow with + thunder encoded files with wrong bitspersample set. The libtiff + development team would like to thank Marin Barbella and TippingPoint's + Zero Day Initiative for reporting this vulnerability (ZDI-CAN-1004, + CVE-2011-1167). + http://bugzilla.maptools.org/show_bug.cgi?id=2300 + +2011-03-10 Frank Warmerdam + + * libtiff/tif_fax3.h: Fix to last change allowing zero length + runs at the start of a scanline - needed for legal cases. + +2011-03-02 Frank Warmerdam + + * libtiff/tif_fax3.h: Protect against a fax VL(n) codeword commanding + a move left. Without this, a malicious input file can generate an + indefinitely large series of runs without a0 ever reaching the right + margin, thus overrunning our buffer of run lengths. Per CVE-2011-0192. + This is a modified version of a patch proposed by Drew Yao of Apple + Product Security. It adds an unexpected() report, and disallows the + equality case, since emitting a run without increasing a0 still allows + buffer overrun. + +2011-02-23 Frank Warmerdam + + * libtiff/tif_jpeg.c: avoid divide by zero in degenerate case (#2296) + + * tools/tiff2rgba.c: close source file on error to make leak + detection easier. + + * libtiff/tif_getimage.c: avoid leaks if TIFFRGBAImageBegin() fails. + + http://bugzilla.maptools.org/show_bug.cgi?id=2295 + +2011-02-22 Frank Warmerdam + + * libtiff/tif_lzma.c: Maintain tif_rawcc/tif_rawcp (CHUNKY_STRING_READ + _SUPPORT) + +2011-02-18 Frank Warmerdam + + * configure.ac, configure: Added support for --enable-chunky-strip-read + configure option to enable the experimental feature from a couple + months ago for reading big strips in chunks. + + * configure.ac, tif_read.c, tif_readdir.c, tif_dir.h, tiffiop.h, + tif_write.c, tif_print.c, tif_jpeg.c, tif_dirwrite.c, tif_write.c: + Implement optional support for deferring the load of strip/tile + offset and size tags for optimized scanning of directories. Enabled + with the --enable-defer-strile-load configure option (DEFER_STRILE_LOAD + #define in tif_config.h). + +2011-02-11 Frank Warmerdam + + * libtiff/tif_print.c: remove unused variable. + +2011-02-09 Frank Warmerdam + + * libtiff/tif_win32.c: avoid error/warning buffer overrun problem + with non-console (popup message) builds on win32. + + http://bugzilla.maptools.org/show_bug.cgi?id=2293 + +2011-01-24 Olivier Paquet + + * libtiff/{tif_dir.{h,c}, tif_dirinfo.c, tif_dirread.c, tif_dirwrite.c, + tif_print.c, tiff.h, tiffiop.h} : Added support for + TIFFTAG_SMINSAMPLEVALUE and TIFFTAG_SMAXSAMPLEVALUE to have different + values for each sample. Presents the min/max of all samples by default for + compatibility. TIFFSetField/TIFFGetField can be made to handle those tags + as arrays by changing the new TIFFTAG_PERSAMPLE pseudo tag. + http://www.asmail.be/msg0055458208.html + +2011-01-06 Frank Warmerdam + + * libtiff/tif_pixarlog.c: Note that tif_rawcc/tif_rawcp are not + maintained. + + * libtiff/tif_zip.c: Maintain tif_rawcc/tif_rawcp when decoding + for CHUNKY_STRIP_READ_SUPPORT. + + * libtiff/tif_jpeg.c: ensure that rawcc and rawcp are maintained + during JPEGPreDecode and JPEGDecode calls. + * libtiff/tif_read.c: larger read ahead for CHUNKY_STRIP_READ_SUPPORT, + as compression formats like JPEG keep 16 lines interleaved in a sense + and might need to touch quite a bit of data. + + http://trac.osgeo.org/gdal/ticket/3894 + +2011-01-03 Lee Howard + + * libtiff/tif_jpeg.c: Fix regressions with 2 and 3 band images + caused by commit on 2010-12-14. Submitted by e-mail from + Even Rouault + +2010-12-31 Olivier Paquet + + * libtiff/tif_dirwrite.c: Fixed writing of TIFFTAG_REFERENCEBLACKWHITE. + http://bugzilla.maptools.org/show_bug.cgi?id=2266 + +2010-12-23 Andrey Kiselev + + * tools/tiffcp.c, man/tiffcp.1: Added support for specifying the + compression level parameter (preset) for Deflate and LZMA encoders, + e.g "-c lzma:p1" or "-c zip:p9". + + * libtiff/tif_lzma.c: Properly set the LZMA2 compression level + (preset) in LZMAVSetField(). + +2010-12-18 Bob Friesenhahn + + * libtiff/Makefile.am (libtiff_la_SOURCES): Added tif_lzma.c to + Makefile. + +2010-12-14 Andrey Kiselev + + * configure.ac, libtiff/{tif_codec.c, tif_config.h.in, tiff.h, + tiffiop.h, tif_lzma.c}, tools/tiffcp.c, man/tiffcp.1: Implement a new + TIFF compression scheme LZMA reserving a new value 34925 for + Compression tag. As per + bug http://bugzilla.maptools.org/show_bug.cgi?id=2221 + +2010-12-14 Lee Howard + + * libtiff/tif_dirread.c: tolerate some cases where + FIELD_COLORMAP is missing + http://bugzilla.maptools.org/show_bug.cgi?id=2189 + +2010-12-14 Lee Howard + + * libtiff/tif_read.c: change read_ahead to tmsize_t + http://bugzilla.maptools.org/show_bug.cgi?id=2222 + +2010-12-14 Lee Howard + + * configure.ac, libtiff/Makefile.am: Build tif_win32.c on + Windows except on Cygwin + http://bugzilla.maptools.org/show_bug.cgi?id=2224 + +2010-12-14 Lee Howard + + * tools/gif2tiff.c: fix buffer overrun + http://bugzilla.maptools.org/show_bug.cgi?id=2270 + +2010-12-14 Lee Howard + + * libtiff/tif_jpeg.c: reduce usage of JCS_UNKNOWN in order + to improve compatibility with various viewers + submitted by e-mail from Dwight Kelly + +2010-12-13 Lee Howard + + * tools/fax2ps.c: be consistent with page-numbering + http://bugzilla.maptools.org/show_bug.cgi?id=2225 + +2010-12-13 Lee Howard + + * libtiff/tif_color.c: prevent crash in handling bad TIFFs + resolves CVE-2010-2595 + http://bugzilla.maptools.org/show_bug.cgi?id=2208 + +2010-12-13 Lee Howard + + * tools/tiffcrop.c: new release by Richard Nolde + http://bugzilla.maptools.org/show_bug.cgi?id=2004 + +2010-12-12 Lee Howard + + * tools/tiff2pdf.c: fix colors for images with RGBA + interleaved data + http://bugzilla.maptools.org/show_bug.cgi?id=2250 + +2010-12-12 Lee Howard + + * libtiff/tif_dirread.c: fix for Zeiss LSM and Canon CR2 files + http://bugzilla.maptools.org/show_bug.cgi?id=2164 + +2010-12-11 Lee Howard + + * tools/tiff2pdf.c: remove invalid duplication for Lab + http://bugzilla.maptools.org/show_bug.cgi?id=2162 + +2010-12-11 Lee Howard + + * libtiff/tif_jpeg.c: fix use of clumplines calculation + http://bugzilla.maptools.org/show_bug.cgi?id=2149 + +2010-12-11 Lee Howard + + * tools/fax2ps.c: replace unsafe tmpfile() with mkstemp() + http://bugzilla.maptools.org/show_bug.cgi?id=2118 + +2010-12-11 Lee Howard + + * libtiff/tif_ojpeg.c, libtiff/tif_pixarlog.c, + libtiff/tif_zip.c: fix build errors for VC6 + http://bugzilla.maptools.org/show_bug.cgi?id=2105 + +2010-12-11 Lee Howard + + * libtiff/tif_stream.cxx: warnings cleanup + http://bugzilla.maptools.org/show_bug.cgi?id=2091 + * libtiff/tif_dirread.c: warnings cleanup + http://bugzilla.maptools.org/show_bug.cgi?id=2092 + +2010-12-11 Lee Howard + + * tools/tiff2pdf.c: add fill-page option + http://bugzilla.maptools.org/show_bug.cgi?id=2051 + +2010-12-11 Lee Howard + + * libtiff/tif_dirread.c: modify warnings + http://bugzilla.maptools.org/show_bug.cgi?id=2016 + +2010-12-11 Lee Howard + + * libtiff/tif_ojpeg.c: fix buffer overflow on problem data + http://bugzilla.maptools.org/show_bug.cgi?id=1999 + +2010-12-11 Lee Howard + + * tools/tiffinfoce.c: strip byte counts are uint64* now + +2010-12-11 Lee Howard + + * libtiff/tif_ojpeg.c: fix crash when reading a TIFF with a zero + or missing byte-count tag + * tools/tiffsplit.c: abort when reading a TIFF without a byte-count + per http://bugzilla.maptools.org/show_bug.cgi?id=1996 + +2010-12-08 Lee Howard + + * libtiff/tif_dirread.c: fix crash when reading a badly-constructed + TIFF per http://bugzilla.maptools.org/show_bug.cgi?id=1994 + +2010-12-06 Lee Howard + + * libtiff/tif_open.c: Fix mode check before opening a file. + http://bugzilla.maptools.org/show_bug.cgi?id=1906 + +2010-11-27 Bob Friesenhahn + + * libtiff-4.pc.in: Added libtiff pkg-config .pc file support. + Patch by Vincent Torri. + +2010-10-21 Frank Warmerdam + + * tools/tiffinfo.c: avoid direct reference to _TIFFerrorHandler. + + * libtiff/tif_config.vc.h: define snprintf to _snprintf for tiff2pdf. + + * libtiff/libtiff.def: export _TIFFCheckMalloc for tools. + +2010-09-25 Lee Howard + + * tools/tiff2ps.c: improvements and enhancements from Richard Nolde + with additional command line options for Document Title, + Document Creator, and Page Orientation + +2010-07-13 Bob Friesenhahn + + * tools/tiffcrop.c: Patch from Richard Nolde to avoid a + potentially unterminated buffer due to using an exceptionally long + file name. + +2010-07-08 Andrey Kiselev + + * tools/tiff2pdf.c: Fixed ID buffer filling in + t2p_write_pdf_trailer(), thanks to Dmitry V. Levin. + +2010-07-07 Andrey Kiselev + + * libtiff/tif_dirread.c: Really reset the tag count in CheckDirCount() + to expected value as the warning message suggests. As per bug + http://bugzilla.maptools.org/show_bug.cgi?id=1963 + +2010-07-06 Andrey Kiselev + + * tools/tiffset.c: Properly handle TIFFTAG_PAGENUMBER, + TIFFTAG_HALFTONEHINTS, TIFFTAG_YCBCRSUBSAMPLING, TIFFTAG_DOTRANGE + which should be set by value. + + * libtiff/tif_dirinfo.c: Don't use assertions in _TIFFFieldWithTag() + and _TIFFFieldWithName() if the tag is not found in the tag table. + This should be normal situation and returned NULL value should be + properly handled by the caller. + +2010-07-02 Andrey Kiselev + + * libtiff/tif_getimage.c: Avoid wrong math du to the signed/unsigned + integer type conversions. As per bug + http://bugzilla.maptools.org/show_bug.cgi?id=2207 + + * tools/{tiff2bw.c, thumbnail.c, pal2rgb.c}: Fix the count for + WhitePoint tag as per bug + http://bugzilla.maptools.org/show_bug.cgi?id=2042 + + * libtiff/tif_getimage.c: Check the number of samples per pixel when + working with YCbCr image in PickContigCase(). As per bug + http://bugzilla.maptools.org/show_bug.cgi?id=2216 + + * libtiff/tif_dir.c: Set the bogus post-decoding hook when processing + TIFFTAG_BITSPERSAMPLE in _TIFFVSetField() for the case of 8 bit when + we don't need any post-processing. That helps to reset the hook if we + previously set this field to some other value and the hook was + initialized accordingly. As per bug + http://bugzilla.maptools.org/show_bug.cgi?id=2035 + +2010-07-01 Andrey Kiselev + + * tools/tiffgt.c: Properly check the raster buffer allocations for + integer overflows. As per bug + http://bugzilla.maptools.org/show_bug.cgi?id=2108 + + * m4/acinclude.m4: Update GL/GLU/GLUt/Pthread macros from the + upstream. + + * libtiff/{tif_aux.c, tif_strip.c, tif_tile.c, tiffiop.h}: Move + multiply_32() and multiply_64() functions into tif_aux.c file and + rename them into _TIFFMultiply32() and _TIFFMultiply64() respectively. + +2010-06-30 Andrey Kiselev + + * tools/tiff2pdf.c: Better generation of ID field in + t2p_write_pdf_trailer(). Get rid of GCC aliasing warnings. + + * tools/tiff2pdf.c: Fixed computation of the tile buffer size when + converting JPEG encoded tiles. + + * tools/tiff2pdf.c: Better handling of string fields, use static + string buffers instead of dynamically allocated, use strncpy() instead + of strcpy(), control the string lengths. + +2010-06-25 Andrey Kiselev + + * tools/tiffcp.c: Initialize buffer arrays with zero to avoid + referencing to uninitialized memory in some cases (e.g. when tile size + set bigger than the image size). + +2010-06-15 Bob Friesenhahn + + * tools/tiffcrop.c: Patch from Richard Nolde. Reject YCbCr + subsampled data since tiffcrop currently doesn't support it. Fix + JPEG support. + +2010-06-13 Frank Warmerdam + + * libtiff/tif_dirinfo.c: Fix invocation of tag compare function (#2201) + + * tools/tiff2pdf.c: Fix assorted bugs in tiff2pdf: missing "return" + in t2p_read_tiff_size() causes t2p->tiff_datasize to be set entirely + wrong for COMPRESSION_JPEG case, resulting in memory stomp if actual + size is larger. Also, there are a bunch of places that try to + memset() a malloc'd buffer before checking for malloc failure, which + would result in core dump if there actually were a failure. (#2211) + +2010-06-11 Bob Friesenhahn + + * libtiff/tiffiop.h (TIFFSafeMultiply): Need more castings to + avoid compiler warnings if parameter types are not sign + consistent. + + * libtiff 4.0.0alpha6 released. + + * tools/tiffcrop.c: Applied patch from Richard Nolde: Corrected + European page size dimensions. Added an option to allow the user + to specify a custom page size on the command line. Fix the case + where a page size specified with a fractional part was being + coerced to an integer by retyping the variables that define the + paper size. + + * html/index.html: Update for the 3.9.3 release. + + * tools/tiffcp.c (tiffcp): Applied Tom Lane's patch to reject + YCbCr subsampled data since tiffcp currently doesn't support it. + http://bugzilla.maptools.org/show_bug.cgi?id=2097 + + * Update libtool to version 2.2.10. + +2010-06-10 Bob Friesenhahn + + * libtiff/tiffiop.h (TIFFSafeMultiply): Work properly if + multiplier is zero. + +2010-06-09 Bob Friesenhahn + + * libtiff/tif_fax3.c (Fax3SetupState): Yesterday's fix for + CVE-2010-1411 was not complete. + + * libtiff/tiffiop.h (TIFFSafeMultiply): New macro to safely + multiply two integers. Returns zero if there is an integer + overflow. + + * tools/tiffcp.c (main): tiffcp should not leak memory if an error + is reported when reading the input file. + +2010-06-08 Bob Friesenhahn + + * Update libtool to version 2.2.8. + + * libtiff/tif_fax3.c (Fax3SetupState): Avoid under-allocation of + buffer due to integer overflow in TIFFroundup() and several other + potential overflows. In conjunction with the fix to TIFFhowmany(), + fixes CVE-2010-1411. + + * libtiff/tiffiop.h (TIFFhowmany): Return zero if parameters would + result in an integer overflow. This causes TIFFroundup() to also + return zero if there would be an integer overflow. + + * contrib: Add an emacs formatting mode footer to all source files + so that emacs can be effectively used. + +2010-06-03 Oliver Chen Feng + + * libtiff/tools/tiffcp.c: add a new option -x to force merged tiff + file PAGENUMBER value in sequence for users who care the page + sequence, this will also prevent tiff2pdf from creating pdf file from + the merged tiff file with wrong page sequence. + +2010-05-08 Olivier Paquet + + * libtiff/tif_dirread.c: Restored TIFFReadDirEntryFloat function in order + to add missing TIFF_SETGET_FLOAT case to TIFFFetchNormalTag. + * libtiff/tif_dirinfo.c: Use correct set_field_type for + TIFFTAG_PIXAR_FOVCOT so it is readable again (regression from 3.9.2). + http://bugzilla.maptools.org/show_bug.cgi?id=2192 + +2010-05-07 Frank Warmerdam + + * libtiff/tif_jpeg.c: Ensure that quality is always set in + JPEGPreEncode(), not just when we want to output local tables. + Otherwise the quality used during compression may not be right and + might not match the tables in the tables tag. This bug only occurs + when seeking between directories in the midst of writing blocks. + http://trac.osgeo.org/gdal/ticket/3539 + +2010-05-06 Andrey Kiselev + + * html/man/TIFFGetField.3tiff.html, html/man/TIFFSetField.3tiff.html: + Regenerated from the source. + +2010-05-05 Olivier Paquet + + * libtiff/tif_print.c: Fixed printing of TIFFTAG_REFERENCEBLACKWHITE which + had stopped working. Also made it always print 6 floats instead of + 2*SamplesPerPixel. + http://bugzilla.maptools.org/show_bug.cgi?id=2191 + http://bugzilla.maptools.org/show_bug.cgi?id=2186 + * man/TIFFGetField.3tiff, man/TIFFSetField.3tiff: Fixed doc to reflect the + fact that libtiff considers TIFFTAG_REFERENCEBLACKWHITE to be 6 floats. + +2010-05-05 Frank Warmerdam + + * libtiff/tif_jpeg.c: Fix to use memcmp(), not memcpy() when checking + if the jpeg table was written. This is a fix for the last fix on 04-21. + +2010-04-21 Frank Warmerdam + + * libtiff/tif_jpeg.c: avoid preparing jpeg tables everytime + JPEGSetupEncode() is called if the tables already seem to be + established. This prevents spurious updates and rewriting of + directories with jpegtables when doing updates to existing images. + http://trac.osgeo.org/gdal/ticket/3539 + +2010-04-20 Olivier Paquet + + * libtiff/tif_dirinfo.c: Use correct set_field_type for + TIFFTAG_PIXAR_IMAGEFULLWIDTH, TIFFTAG_PIXAR_IMAGEFULLLENGTH, + TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN and TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA. + They were unreadable with TIFF_SETGET_UNDEFINED, a regression from 3.9.2. + http://bugzilla.maptools.org/show_bug.cgi?id=2139 + +2010-04-10 Bob Friesenhahn + + * libtiff/tif_dir.c (_TIFFVSetField): Add a special error case for + when the tag count value is zero. Error handling is still a + regression since in 3.9.2, empty tags are skipped (with a warning) + rather than returning a hard error and refusing to read the file. + + * tools/ppm2tiff.c (main): While case for parsing comment line + requires extra parenthesis to work as expected. Reported by + Thomas Sinclair. + +2010-04-02 Frank Warmerdam + + * libtiff/tif_read.c (primarily): Add support for + CHUNKY_STRIP_READ_SUPPORT where large strips are + read in chunks for applications using TIFFReadScanline(). + This is intended to make it more practical work with very + large compressed one-strip files. Feature is off by default. + Enable by defining CHUNK_STRIP_READ_SUPPORT as a macro. + http://trac.osgeo.org/gdal/ticket/3514 + +2010-03-31 Frank Warmerdam + + * libtiff/tif_flush.c: Use TIFFRewriteDirectory() when flushing + directories so previously placed directories will be migrated to + the end of file if needed. + +2010-03-30 Frank Warmerdam + + * libtiff/tif_lzw.c: change type of dec_bitsleft field to uint64 + to support operating on strips/tiles of more than 256MB. + http://trac.osgeo.org/gdal/ticket/3512 + +2010-03-10 Bob Friesenhahn + + * libtiff/tif_aux.c (_TIFFCheckRealloc): Improve error message so + that it is clearly a memory allocation error message, and also + includes the size of the allocation request. + +2010-02-22 Lee Howard + + * libtiff/tif_jpeg.c: Do not generate a JPEGTables tag when creating + the JPEG TIFF as is is not required in order to prevent it from + being unused and filled with invalid data. (Leave it to be + generated by later activity.) + http://bugzilla.maptools.org/show_bug.cgi?id=2135 + * tools/tiff2pdf.c: Write the JPEG SOI headers into the TIFF strip + data rather than skipping them. This fixes the ability to view in + Acrobat Reader, Evince, and Ghostscript. + http://bugzilla.maptools.org/show_bug.cgi?id=2135 + * libtiff/tif_fax3.c: Don't return error on badly-terminated MMR + strips. + http://bugzilla.maptools.org/show_bug.cgi?id=2029 + +2009-12-03 Frank Warmerdam + + * libtiff/tif_jpeg.c: Made JPEGDecodeRaw() check for buffer overruns. + Made so that when working with downsampled images a stub function + reporting an error is used for tif_decoderow. We cannot meaningfully + support reading scanlines in this situation. (#1936) + + * libtiff/tif_jpeg.c: Ensure that tif_scanlinesize is computed after + resetting of the upsampling values (gdal:#3259). + http://bugzilla.maptools.org/show_bug.cgi?id=1936 + +2009-11-30 Frank Warmerdam + + * contrib/dbs/tiff-grayscale.c, contrib/tif-palette.c, + tools/ras2tiff.c: Fix resource leaks on error. + http://bugzilla.maptools.org/show_bug.cgi?id=2121 + + * libtiff/tif_{aux.c,dir.c,dir.h,dirinfo.c}: Return to handling + TIFFTAG_REFERENCEBLACKWHITE as a field in the TIFF directory instead + of as a custom(generic) field to avoid a potential reentrancy problem. + http://bugzilla.maptools.org/show_bug.cgi?id=2125 + + * libtiff/tif_color.c, libtiff/tif_getimage.c, libtiff/tiffio.h, + man/TIFFcolor.3tiff: Make TIFFDisplay argument in TIFFCIELabToRGBInit + const, and display_sRGB static and const. + http://bugzilla.maptools.org/show_bug.cgi?id=2124 + +2009-11-04 Bob Friesenhahn + + * libtiff 4.0.0alpha5 released. + +2009-11-03 Bob Friesenhahn + + * tools/tiffcrop.c: Updated tiffcrop from Richard Nolde. This + version has undergone substantial testing with arbitrary sample + bit depths. Also eliminates GCC compilation warnings. + +2009-11-02 Bob Friesenhahn + + * port/libport.h: Add extern declarations for getopt standard + globals. + +2009-10-31 Bob Friesenhahn + + * libtiff/tif_lzw.c (LZWDecode, LZWDecodeCompat): Fix warnings + noticed in 64-bit build of libtiff with Visual Studio 2005. + Resolves "Bug 2067 - Visual Studio 2005 64-bit warnings in + tif_lzw.c", http://bugzilla.maptools.org/show_bug.cgi?id=2067 + + * libtiff/tif_pixarlog.c (PixarLogEncode): Fix non-important + warning noticed in Visual Studio 2005 build. Resolves "Bug 2068 - + Visual Studio 2005 64-bit warning in tif_pixarlog.c", + http://bugzilla.maptools.org/show_bug.cgi?id=2068 + +2009-10-29 Bob Friesenhahn + + * libtiff/tif_dirread.c: Eliminate GCC "dereferencing type-punned + pointer" warnings. + +2009-10-28 Bob Friesenhahn + + * html/tools.html: Add manual page links, and a summary + description of tiffcrop. + +2009-10-07 Bob Friesenhahn + + * configure.ac: x86_64 should use the same fill order as i386. + +2009-09-24 Bob Friesenhahn + + * tools/tiffcrop.c, man/tiffcrop.1: New tiffcrop from Richard + Nolde. Major updates to add significant functionality for reading + and writing tile based images with bit depths not a multiple of 8 + which cannot be handled by tiffcp. + +2009-09-03 Bob Friesenhahn + + * libtiff/tif_ojpeg.c (OJPEGWriteHeaderInfo): IJG JPEG 7 needs + do_fancy_upsampling=FALSE in order to read raw data. Resolves + "Bug 2090 - OJPEG crash with libjpeg v7". + http://bugzilla.maptools.org/show_bug.cgi?id=2090 + +2009-09-03 Frank Warmerdam + + * libtiff/tif_getimage.c: Fixed error recognition handling in RGBA + interface when stoponerror is set. + http://bugzilla.maptools.org/show_bug.cgi?id=2071 + +2009-08-30 Bob Friesenhahn + + * tools/{tiffcrop.c,tiffgt.c}: Applied patch from Oden Eriksson to + fix build with gcc when using the "-Wformat + -Werror=format-security" flags. + +2009-08-29 Bob Friesenhahn + + * test/{bmp2tiff_palette.sh, bmp2tiff_rgb.sh, gif2tiff.sh, + ppm2tiff_pbm.sh, ppm2tiff_pgm.sh, ppm2tiff_ppm.sh}: Additional + utilities tests. + +2009-08-28 Bob Friesenhahn + + * tools/tiffinfo.c: tiffinfo should return error status to the + caller. Register a private error callback to accomplish that. + + * test/Makefile.am (TIFFIMAGES): Add test images in BMP, GIF, and + PNM formats so that we will be able to test more of the tools. + While adding these test images I notice that bmp2tiff and gif2tiff + only support ancient versions of their respective formats. + +2009-08-27 Bob Friesenhahn + + * libtiff 4.0.0alpha4 released. + + * HOWTO-RELEASE: Improved release instructions. + +2009-08-24 Bob Friesenhahn + + * man/{TIFFClose.3tiff,raw2tiff.1,tiffcmp.1,tiffsplit.1}: Applied + fixes for "Bug 2023 - nroff errors in manual pages". + http://bugzilla.maptools.org/show_bug.cgi?id=2023 + + * tools/{rgb2ycbcr.c, tiff2rgba.c}: Applied fixes for "Bug 2079 - + CVE-2009-2347 libtiff: integer overflows in various inter-color + space conversion tools". + http://bugzilla.maptools.org/show_bug.cgi?id=2079 + + * libtiff/tif_print.c (TIFFPrintDirectory): Apply fix from Jay + Berkenbilt for "Bug 2024 - possible null pointer dereference with + one-line fix". + http://bugzilla.maptools.org/show_bug.cgi?id=2024 + + * libtiff/tif_dirread.c (TIFFReadCustomDirectory): Apply patch + from Jay Berkenbilt for "Bug 1895 - logic error in tif_dirread.c: + segfault after setting tdir_tag = IGNORE". + http://bugzilla.maptools.org/show_bug.cgi?id=1895 + +2009-08-23 Bob Friesenhahn + + * test/Makefile.am, test/tiffcrop*.sh: Split previously existing + tiffcrop.sh into a collection of many specific tests. Re-wrote + all of the existing tests to be based on some simple shell + functions. Make distcheck works again. + + Export certain variables (MAKE, MAKEFLAGS, MEMCHECK) to tests and + added 'memcheck' and 'ptrcheck' targets to make it easy to run the + tests under valgrind. + +2009-08-21 Bob Friesenhahn + + * test/tiffcp-logluv.sh: Fix test so that it works with a VPATH + build. + + * test/Makefile.am (AUTOMAKE_OPTIONS): Colorized tests was not + actually activated since it needed to be enabled in this + Makefile.am. Also activated parallel-tests mode since it offers + useful features such as per-test .log files and a summary test + report .log file. + +2009-08-20 Bob Friesenhahn + + * configure.ac: Updated autotools. Autoconf 2.64, Automake 1.11, + libtool 2.2.6. Enabled support for silent build rules + (--enable-silent-rules or 'make V=0') and colorized tests. + + * html/{index.html, v3.9.0.html}: Update for 3.9.0 release. + +2009-06-30 Frank Warmerdam + + * tests/tiffcp-logluv.sh: minimal testing of sgilog compression. + + * tools/tiffcp.c: add -c sgilog support. + + * libtiff/tif_luv.c: correct return codes from encoderow to be + 1 on success instead of zero. + http://bugzilla.maptools.org/show_bug.cgi?id=2069 + + * libtiff/tif_lzw.c: back out patch from #2065 and apply patch from + #1085 for a better underflow fix that errors properly. + http://bugzilla.maptools.org/show_bug.cgi?id=2065 + http://bugzilla.maptools.org/show_bug.cgi?id=1985 + +2009-06-26 Frank Warmerdam + + * libtiff/tif_strip.c: Remove an inappropriate assertion that often + fails on oddly sized 12bit jpeg compressed ycbcr images. + +2009-06-22 Frank Warmerdam + + * libtiff/tif_lzw.c: Fix buffer underflow bug. + http://bugzilla.maptools.org/show_bug.cgi?id=2065 + +2009-06-21 Frank Warmerdam + + * configure.ac, libtiff/tif_jpeg.c, libtiff/tif_jpeg_12.c: add support + for dual mode 8/12 bit jpeg support. + +2009-06-03 Frank Warmerdam + + * libtiff/tif_write.c: do not override the planar configuration to be + contig for one sample files if planar configuration is already set. + http://bugzilla.maptools.org/show_bug.cgi?id=2057 + +2009-06-02 Frank Warmerdam + + * libtiff/libtiff.def: Add TIFFUnsetField. + +2009-05-03 Frank Warmerdam + + * libtiff/{tif_jpeg.c,tif_ojpeg.c,tif_getimage.c}: Fixed various + error reports to use "%s" as format string. + http://trac.osgeo.org/gdal/ticket/2976 + +2009-03-12 Frank Warmerdam + + * libtiff/{tif_fax3.c,tif_jpeg.c,tif_ojpeg.c}: Fix printdir chaining + for some codecs (#2020). + +2009-02-12 Frank Warmerdam + + * libtiff/tif_luv.c: Fix handling of tiled logluv images. + http://bugzilla.maptools.org/show_bug.cgi?id=2005 + +2009-02-09 Frank Warmerdam + + * libtiff/tif_dirread.c: Improve allocation safety when allocated + buffer for large tags. (#1998) Related to (#1993) + +2009-02-06 Frank Warmerdam + + * tools/tiffcrop.c: Don't default image->res_unit to INCH. Now the + test suite should pass. + +2009-02-05 Frank Warmerdam + + * libtiff/tif_dirread.c: Re-incorporated a sanity check on tag size, + but at the 2GB boundary to avoid overflow on 32bit systems. + http://bugzilla.maptools.org/show_bug.cgi?id=1993 + + * libtiff/tif_dirread.c: Remove some assertions that blow due to + corrupt files rather than in response to library internal + inconsistencies. + http://bugzilla.maptools.org/show_bug.cgi?id=1995 + http://bugzilla.maptools.org/show_bug.cgi?id=1991 + + * libtiff/tif_dirread.c: Fixed testing for failed result from + TIFFReadDirectoryFindFieldInfo(). + http://bugzilla.maptools.org/show_bug.cgi?id=1992 + +2009-01-23 Frank Warmerdam + + * libtiff/tif_predict.c: Add support for 32bit integer horz. predictors. + http://bugzilla.maptools.org/show_bug.cgi?id=1911 + + * libtiff/tif_dirwrite.c: Fix byte swapping of next directory offset. + + http://bugzilla.maptools.org/show_bug.cgi?id=1924 + + * tools/tiffcrop.c: initialize xres/yres values. + + * test/*.sh - default ${srcdir} to local directory. + + * test/common.sh - start verbose mode after common settings. + + * libtiff/tif_dirinfo.c: Replace lfind() with local equivelent to + avoid type mismatches on different platforms. + http://bugzilla.maptools.org/show_bug.cgi?id=1889 + +2009-01-22 Frank Warmerdam + + * tools/{fax2tiff.c,thumbnail.c,tiff2pdf.c,tiff2ps.c,tiffdump.c, + tiffsplit.c}: avoid warnings, mostly 32bit/64bit casting issues. + + * port,tools: Introduce libport.h, and include in tools if NEED_LIBPORT + defined, primarily to reduce prototype warnings on windows. + + * libtiff/tif_dirinfo.c,tif_dirread.c: Avoid warnings + about unused parameters, and uninitialized variables. + +2009-01-21 Bob Friesenhahn + + * test/common.sh: Execute tests like 'make VERBOSE=TRUE check' in + order to trace full execution detail while executing the test suite. + +2009-01-20 Frank Warmerdam + + * tools/tiffsplit.c: fix sampleformat to be shortv instead of longv. + +2009-01-20 Bob Friesenhahn + + * test/Makefile.am (CLEANFILES): Make sure that test output files + are removed by 'make clean' + + * Update autotools for 4.0.0 beta3 + + * 4.0.0 beta3 produced. + +2009-01-12 Bob Friesenhahn + + * test/tiffcrop.sh: New test script for tiffcrop from Richard + Nolde. + + * tools/tiff2ps.c: Remove spurious message to stderr. + +2009-01-11 Bob Friesenhahn + + * tools/tiff2ps.c: Incorporated significant functionality update + from Richard Nolde. In particular, support for rotating the image + by 90, 180, 270, and 'auto' has been added. + + * man/tiffcrop.1: Incorporated documentation updates from Richard + Nolde. + + * tools/tiffcrop.c: Incorporated significant functionality update + from Richard Nolde. + +2008-12-31 Bob Friesenhahn + + * libtiff/tiffio.h: GCC will now validate format specifications + for TIFFError(), TIFFErrorExt(), TIFFWarning(), and + TIFFWarningExt() in order to reveal bugs. + + * Many fixes throughout to work better as a 64-bit build. + +2008-12-30 Bob Friesenhahn + + * tools/{tiff2pdf.c, tiff2ps.c, tiffinfo.c}: Offset and length + tags now require 64-bit parameter rather than 32-bit. + + * libtiff/tif_dirread.c: Fixed issues with unaligned access to + 64-bit values. + + * tools/thumbnail.c: Eliminate crash noticed while running test + suite. + +2008-12-29 Bob Friesenhahn + + * libtiff/tif_ojpeg.c (OJPEGLibjpegJpegSourceMgrFillInputBuffer): + Initialize stack variables to avoid compiler warning. + + * tools/tiffinfoce.c (main): Use toff_t for offset type when + retrieving offset of EXIF IFD. + + * libtiff/tiffio.h: Undeprecate toff_t and restore its use in the + TIFFClientOpen() callback and other external function definitions. + + * tools/tiffinfo.c (main): Offset to EXIF IFD requires a 64-bit + type now. Fixes crash when dumping files containing an EXIF IFD. + + * m4/libtool.m4: Update to libtool 2.2.6. + +2008-12-21 Frank Warmerdam + + * libtiff/tif_dir.c, tiffio.h: Introduce TIFFUnsetField() function. + + * libtiff/tif_jpeg.c: Avoid errors if the application writes a full + strip for the last partial strip in a jpeg compressed file. + http://bugzilla.maptools.org/show_bug.cgi?id=1981 + +2008-10-29 Frank Warmerdam + + * libtiff/tif_flush.c: Make sure that BEENWRITING is cleared when + we take the shortcut to only update the strip/tile offsets in place. + http://trac.osgeo.org/gdal/ticket/2621 + +2008-10-21 Andrey Kiselev + + * libtiff/tif_jbig.c: Support the JBIG-KIT 2.0 (compatibility with + the older versions retained). + +2008-10-09 Frank Warmerdam + + * libtiff/tif_jpeg.c: Add #ifdefs for changes needed if using + IPP enabled version of libjpeg from Intel. + http://bugzilla.maptools.org/show_bug.cgi?id=1951 + +2008-09-05 Andrey Kiselev + + * tools/tiffsplit.c: Use byte counts of proper size (uint64). + Required for libtiff 4.0. + + * tools/tiffsplit.c: Use dynamically allocated array instead of static + when constructing output file names. + +2008-09-03 Andrey Kiselev + + * tools/tiffsplit.c: Get rid of unsafe strcpy()/strcat() calls when + doing the filename/path construction. + + * tools/tiff2pdf.c: More appropriate format string in + t2p_write_pdf_string(); avoid signed/unsigned mismatch. + + * libtiff/tif_lzw.c: Properly zero out the codetable. As per bug + + http://bugzilla.maptools.org/show_bug.cgi?id=1929 + + * libtiff/tif_lzw.c: Properly zero out the string table. Fixes + CVE-2008-2327 security issue. + +2008-09-01 Frank Warmerdam + + * libtiff/tif_dirread.c: Avoid unused TIFFReadDirEntryFloat() function. + + * libtiff/tif_dirwrite.c: modified to write IFDs as either IFD8 or IFD + depending on whether the file is bigtiff or classic tiff. + http://bugzilla.maptools.org/show_bug.cgi?id=1917 + +2008-08-12 Edward Lam + + * tools/tiffdump.c: When compiling for Microsoft Windows, apply + consistent (__int64) casting when testing if _lseeki64 has + successfully seeked as requested. This is necessary for large + file support to work since off_t is only 32-bit. + +2008-07-29 Frank Warmerdam + + * tif_strip.c: Replace assertions related to samplesperpixel != 3 or + the subsampling values not being 1, 2 or 4 (for jpeg compressed images) + with control logic to return runtime errors (c/o Even Rouault) (#1927). + +2008-06-17 Frank Warmerdam + + * tools/tiffcrop.c: Fix some portability problems. + + * libtiff/tif_ojpeg.c: Use same jpeg/win32 boolean/FAR hacks as are + used in tif_jpeg.c. + + * libtiff/tif_win32.c: Ensure TIFFOpenW() uses same FILE_SHARE flags + as TIFFOpen(). + +2008-06-01 Frank Warmerdam + + * libtiff/tif_dirwrite.c: Fix alignment problems affecting architectures + like Sparc/Solaris. + http://bugzilla.maptools.org/show_bug.cgi?id=1892 + +2008-05-27 Frank Warmerdam + + * libtiff.def: Add TIFFFindField + http://bugzilla.maptools.org/show_bug.cgi?id=1891 + +2008-05-26 Frank Warmerdam + + * tif_config.*.h, tiffconf.*.h: Remove SIZEOF_LONG definition, unused. + + * li2008-04-15 Andrey Kiselev + +btiff/tif_win32.c: Replace custom Win32 memory api with generic + POSIX one. No apparent value to use of GlobalAlloc() in the modern + age. http://bugzilla.maptools.org/show_bug.cgi?id=1885 + + * libtiff/tiffconf.vc.h: Added JBIG_SUPPORT and MDI_SUPPORT items + in windows version (care of Edward Lam). + +2008-05-24 Frank Warmerdam + + * tif_codec.c: Avoid NULL pointer dereferencing for exotic + compression codec codes. + + * tif_dirwrite.c: fix potential memory leak. + + * tif_dirread.c: Fix unchecked malloc result. + +2008-05-24 Bob Friesenhahn + + * test {tiff2pdf.sh tiff2ps-EPS1.sh tiff2ps-PS1.sh tiff2ps-PS2.sh + tiff2ps-PS3.sh tiffcp-g3-1d-fill.sh tiffcp-g3-1d.sh + tiffcp-g3-2d-fill.sh tiffcp-g3-2d.sh tiffcp-g3.sh tiffcp-g4.sh + tiffcp-split-join.sh tiffcp-split.sh tiffcp-thumbnail.sh + tiffdump.sh tiffinfo.sh}: Added more test scripts based on + suggestions from Lee Howard posted to the tiff list on 13 Sep + 2007. + +2008-05-23 Frank Warmerdam + + * libtiff/tif_fax3.c: Add an assert in an effort to detect a + possible runtime problem reported by coverity. + + * contrib/iptcutil/iptcutil.c: Fixed memory leak of str. + + * tools/tiffcrop.c, man/tiffcrop.1: Major update from Richard Nolde. + http://bugzilla.maptools.org/show_bug.cgi?id=1888 + + * tools/tiffdither.c: remove dead onestrip code. avoid memory leak. + + * tools/rgb2ycbcr.c: fix memory leak of raster buffer. + + * tools/tiffcp.c: Simplify inknames code to avoid pointless test. + Cleanup scanline allocation to avoid coverity warning. + + * tools/thumbnail.c: Check for TIFFOpen() failure. + +2008-05-18 Frank Warmerdam + + * libtiff/tif_dirinfo.c: Use TIFF_SETGET_ASCII for PIXAR_TEXTUREFORMAT + and PIXAR_WRAPMODES instead of TIFF_SETGET_UNDEFINED. Not exactly clear + why this is needed. + +2008-05-09 Bob Friesenhahn + + * Makefile.am (ACLOCAL_AMFLAGS): Libtool 2.2.4 does not like + "ACLOCAL_AMFLAGS=-I ./m4". It wants "ACLOCAL_AMFLAGS=-I m4". + +2008-04-15 Andrey Kiselev + + * test/: Test suite updated. Everything is passed now. + + * libtiff/tif_dirinfo.c: Fixed description of the + TIFFTAG_NUMBEROFINKS tag. + +2008-04-14 Andrey Kiselev + + * libtiff/{tif_dirread.c, tif_dirwrite.c, tiffiop.h}: + Get rid of some of "dereferencing type-punned" warnings by converting + tdir_offset field of TIFFDirEntry structure into union. + +2008-04-10 Andrey Kiselev + + * libtiff/{tif_flush.c, tif_dirwrite.c, tiffio.h, tiffiop.h}: + TIFFRewriteField() renamed into _TIFFRewriteField() and moved out + from the public interface. Type of its 'count' parameter changed + from uint32 to tmsize_t. + + * /libtiff/tiffiop.h: Make tif_nfields and tif_nfieldscompat fields + of the tiff structure have the size_t type instead of uint32. + +2008-04-09 Andrey Kiselev + + * tools/tiffdump.c: Added support for MSVS 6.0. + + * libtiff/tif_dirread.c: Use custom functions _TIFFUInt64ToFloat() + and _TIFFUInt64ToDouble() to convert 64-bit integers into floating + point values on MSVS 6.0 platform. + +2008-03-14 Frank Warmerdam + + * tif_dirread.c: Removed sanity checks on tags larger than 4MB in + TIFFReadDirEntryArray() since they are interfering with seemingly + legitimate files. http://trac.osgeo.org/gdal/ticket/2005 + +2008-02-09 Joris Van Damme + + * tif_dirread.c: Added handling for the case of number of values for + PageNumber tag different from 2 (previously resulted in an assert + indicating lack of handling and was forgotten about) + +2008-02-01 Frank Warmerdam + + * libtiff/tif_jpeg.c: Do not try to fixup subsampling tags based on + the actual jpeg data stream if the first strip/tile has zero size. + This is the case when GDAL creates a new file with zero sizes, closes + and reopens it. + +2008-01-07 Frank Warmerdam + + * tools/tiff2ps.c: fix up 64bit issues (from Edward Lam). + +2008-01-01 Frank Warmerdam + + * libtiff/tif_dirwrite.c: #ifdef out lots of unused functions. + + * Makefile.vc, libtiff/Makefile.vc, tools/Makefile.vc: Improve clean + targets. + + * tools/tiffinfo.c, tools/tiffcmp.c, tools/gif2tiff.c, tools/bmp2tiff.c + tools/tiff2pdf.c: Fix 64-bit warnings when compiling under MSVC 2005 + (x64). + + * tools/tiffset.c: Changes to reflect the fact that TIFFFieldWithTag() + and TIFFFieldWithName() now return TIFFField pointers instead of + TIFFFieldInfo pointers. + + * tools/tiffdump.c: Added ssize_t typedef on Windows since it doesn't + exist. This makes it compile again on Windows + + * tif_aux.c, tif_getimage.c, tif_next.c, tif_predict.c, tif_win32.c, + tiffconf.vc.h: Various 64bit fixes from Edward Lam identified on win64. + + * test/rewrite_tag.c: New test for TIFFRewriteField(). + +2007-12-31 Frank Warmerdam + + * tif_dirwrite.c: Added TIFFRewriteField(). This new function + rewrites one field "on disk" updating an existing directory + entry. Lots of limitations still... + + * tiffiop.h, tif_write.c, tif_dirread.c, tif_flush.c: Keep track of + TIFF_DIRTYSTRIP separately from TIFF_DIRTYDIRECT to indicate that + the strip offset/size values are dirty but nothing else about the + directory is dirty. In flush handle "just stripmaps dirty" as a + special case that just rewrites these values without otherwise + modifying the directory on disk using TIFFRewriteField(). + + We also modify logic so that in update mode the directory is not + marked dirty on read, but only when something is changed. This + means we need to keep track of updates to the stripmap stuff in + TIFFAppendToStrip(). + +2007-12-10 Frank Warmerdam + + * tif_jpeg.c: Improve ability to switch between encoding and decoding + in the jpeg code (gdal bug #2033). + +2007-11-23 Frank Warmerdam + + * tif_dir.c, tif_dirread.c, tif_dirwrite.c, tif_read.c, tif_write.c, + tiffiop.h: Added TIFF_BUF4WRITE flag to indicate if contents of the + rawcp/rawcc buffer are for writing and thus may require flushing. + Necessary to distinguish whether they need to be written to disk when + in mixed read/write mode and doing a mixture of writing followed by + reading. http://trac.osgeo.org/gdal/ticket/1758 + +2007-11-23 Andrey Kiselev + + * configure.com, libtiff/tif_vms.c: Better OpenVMS support. Patches + from Alexey Chupahin. + +2007-11-02 Frank Warmerdam + + * tif_write.c: Rip out the fancy logic in TIFFAppendToStrip() for + establishing if an existing tile can be rewritten to the same location + by comparing the current size to all the other blocks in the same + directory. This is dangerous in many situations and can easily + corrupt a file. (observed in esoteric GDAL situation that's hard to + document). This change involves leaving the stripbytecount[] values + unaltered till TIFFAppendToStrip(). Now we only write a block back + to the same location it used to be at if the new data is the same + size or smaller - otherwise we move it to the end of file. + + * tif_dirwrite.c: Try to avoid writing out a full readbuffer of tile + data when writing the directory just because we have BEENWRITING at + some point in the past. This was causing odd junk to be written out + in a tile of data when a single tile had an interleaving of reading + and writing with reading last. (highlighted by gdal + autotest/gcore/tif_write.py test 7. + + * tif_predict.c: use working buffer in PredictorEncodeTile to avoid + modifying callers buffer. + http://trac.osgeo.org/gdal/ticket/1965 + + * tif_predict.c/h: more fixes related to last item, keeping a + distinct pfunc for encode and decode cases as these were getting + mixed up sometimes. + http://trac.osgeo.org/gdal/ticket/1948 + +2007-11-01 Frank Warmerdam + + * tif_predict.c/h, tif_lzw.c, tif_zip.c: Improvements so that + predictor based encoding and decoding works in read-write update + mode properly. + http://trac.osgeo.org/gdal/ticket/1948 + +2007-10-24 Joris Van Damme + + * tif_dirread.c: Fixed problem with bogus file triggering + assert(td->td_planarconfig == PLANARCONFIG_CONTIG) in + ChopUpSingleUncompressedStrip + +2007-10-22 Joris Van Damme + + * tif_jpeg.c: Resolved buffer incrementation bug that lead to faulty images + at best, access violation at worst, when subsampled JPEG compressed imagery + is decoded without the JPEG_COLORMODE feature + +2007-10-11 Frank Warmerdam + + * html/index.html: Update "people responsible" section. + +2007-10-05 Frank Warmerdam + + * tools/tiff2pdf.c: Fix problem with alpha setting in some cases + as reported on the mailing list. + +2007-10-01 Joris Van Damme + + * changed some more incorrect %lud printf flags to %lu + +2007-09-29 Joris Van Damme + + * tif_dirread.c: Strip chopping interfered badly with uncompressed + subsampled images because it tried to divide subsampled rowblocks, + leading to all sorts of errors throughout the library for these + images. Fixed by making strip chopping divide in row counts that + are a multiple of vertical subsampling value. + +2007-09-28 Joris Van Damme + + * tif_dirread.c: Logical cast working around compiler warning + + * tif_read.c: Correction of some error flags and parameter lists + +2007-09-27 Joris Van Damme + + * tif_dirread.c: Made calculation of td_maxsamplevalue more robust + when dealing with large bitspersample values, shutting up purification + tools that warn about truncation, though it remains incorrect and + indicates a conceptual problem there. + + * tif_open.c: Moved early exit in case of 'h' flag (to disable reading + of first IFD) to proper place because it badly interfered with memory + mapping, resulting in mapping flag even with dummy mapping functions + that returned 0 whilst at the same time the mapping tif_size wasn't + set, thus resulting in continuous incorrect beyond-eof errors. + +2007-09-24 Joris Van Damme + + * tif_dirinfo.c: Fixed (MSVC) compiler reports about + inconsistent use of const in tiffFields and exifFields definition + +2007-09-20 Frank Warmerdam + + * tif_dirwrite.c: Always write tile/strip offsets and sizes + using LONG8 type when output format is BigTIFF. The + TIFFWriteDirectoryTagLongLong8Array() function was restructured + accordingly. + + * tif_dirread.c: Improvements to error reporting text in + TIFFFetchDirectory(). + +2007-09-19 Bob Friesenhahn + + * test/images: Added a small collection of test images for use by + test programs and scripts. + * test/tiffinfo.sh: A trivial example test script. + * test/common.sh: Added small script for setting the environment + used by script-based tests. + +2007-08-24 Frank Warmerdam + + * tif_dirwrite.c: Write the tif_nextdiroff value instead of a fixed + zero when writing directory contents to preserve the ability to + rewrite directories in place, even in the middle of a directory + chain. + + * tif_dirinfo.c: _TIFFMergeFields() now only merges in field + definitions that are missing. Existing definitions are silently + ignored. + + * tif_dirread.c: Add runtime error for fields for which no definition + is found (in addition to an assert for developers) in + TIFFFetchNormalTag(). Not sure if this is needed, but it seems + prudent. + +2007-08-10 Joris Van Damme + + * libtiff/tif_getimage.c: removed SubsamplingHor and SubsamplingVer + from _TIFFRGBAImage structure to revert unwanted ABI change. + +2007-08-10 Joris Van Damme + + * libtiff/tif_win32.c: use SetFilePointer instead of + SetFilePointerEx, as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1580 + +2007-07-19 Andrey Kiselev + + * libtiff/tif_stream.cxx: Put all callback functions declarations + inside extern "C" block. + + * libtiff/{tif_lzw.c, tif_luv.c, tif_dumpmode.c, tif_print.c, + tif_read.c, tif_strip.c, tif_thunder.c}: Use "%I64d" printf() + formatter instead of "%lld" with MSVC compiler. + + * libtiff/{tiffiop.h, tif_aux.c}: Added _TIFFUInt64ToFloat() and + _TIFFUInt64ToDouble() functions. + +2007-07-18 Andrey Kiselev + + * libtiff/tif_dirread.c: Handle the case of MSVC 6 when using 64-bit + integer constants. + + * libtiff/{Makefile.am, Makefile.v}: Do not distribute tiffconf.h, + remove tif_config.h/tiffconf.h during cleaning. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1573 + + * libtiff/tif_unix.c: Do not use O_LARGEFILE. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1577 + +2007-07-13 Andrey Kiselev + + * libtiff 4.0.0alpha released. + +2007-07-12 Andrey Kiselev + + * tools/tiff2pdf.c: Added missed extern optind as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1567 + + * libtiff/{tif_close.c, tif_dirinfo.c, tiffiop.c, tif_dirread.c, + tif_dir.h, tif_dir.c, tiffio.h}: Transition to the new-style tag + extending scheme completed. + +2007-07-11 Bob Friesenhahn + + * libtiff/tif_stream.cxx: Adapt to use toff_t again. Update to + use standard C++ library size types and attempt to detect overflow + cases. + +2007-07-08 Andrey Kiselev + + * libtiff/{tif_jpeg.c, tif_dir.h, tif_dir.c, tif_dirinfo.c, tiffio.h, + tif_ojpeg.c, tif_print.c, tif_fax3.c, tif_dirread.c}: More work on new + tag extending scheme. Use the new scheme everywhere. + + * libtiff/{tif_zip.c, tif_predict.c, tif_pixarlog.c, tif_luv.c, + tif_fax3.c, tif_dirread.c, tif_dirwrite.c, tif_close.c, tif_ojpeg.c, + tif_jpeg.c, tif_dirinfo.c, tif_dir.h, tiffio.h, tiffiop.h}: + TIFFFIeldInfo structure replaced with TIFFField structure. + TIFFFieldInfo retained for the backward compatibility. + +2007-07-05 Bob Friesenhahn + + * tools/tiff2pdf.c: Fix a compile problem when JPEG_SUPPORT is not + defined. + +2007-07-04 Andrey Kiselev + + * libtiff/{tif_dir.c, tiff.h, tiffio.h, libtiff.def}: Unused + TIFFReassignTagToIgnore() function and TIFFIgnoreSense enumeration + removed. + + * libtiff/{tif_dirinfo.c, tif_fax3.c, tif_jbig.c, tif_jpeg.c}: Move + tags TIFFTAG_FAXRECVPARAMS, TIFFTAG_FAXSUBADDRESS, + TIFFTAG_FAXRECVTIME and TIFFTAG_FAXDCS to the common tag directory. + These tags are not codec-specific and relate to image content, so + process them as other normal tags. + + * libtiff/{tiffio.h, tif_dir.h}: TIFFTagValue structure moved from the + public tiffio.h to private tif_dir.h. + + * contrib/{acorn, mac-cw, mac-mpw}: Removed as unmaintained and + outdated. + +2007-07-03 Andrey Kiselev + + * libtiff{tif_acorn.c, tif_apple.c, tif_atari.c, tif_msdos.c, + tif_win3.c}: Obsoleted portability stuff removed. + + * tools/tiff2ps.c: Added support 16-bit images as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1566 + + Patch from William Bader. + + * tools/tiff2pdf.c: Fix for TIFFTAG_JPEGTABLES tag fetching and + significant upgrade of the whole utility as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1560 + + Now we don't need tiffiop.h in tiff2pdf anymore and will open output + PDF file using TIFFClientOpen() machinery as it is implemented + by Leon Bottou. + +2007-06-26 Bob Friesenhahn + + * configure.ac: Fix typo when substituting value for unsigned 8 bit type. + Added support for a TIFF_PTRDIFF_T type to use when doing pointer arithmetic. + Added support for a TIFF_SSIZE_T in order to return memory sizes but still + allow returning -1 for errors. + * libtiff/tiffconf.vc.h: Add porting type defintions for WIN32. + +2007-06-25 Bob Friesenhahn + + * port/strtoull.c: New porting function in case strtoull() is not + available on the target system. + * configure.ac: Add configure support for determining sized types + in a portable way and performing necessary substitutions in + tif_config.h and tiffconf.h. Updated tiff.h to use the new + definitions. + +2007-04-27 Andrey Kiselev + + * tools/tiff2pdf.c: Check the tmpfile() return status as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=154 + +2007-04-07 Andrey Kiselev + + * libtiff/{tif_dir.h, tif_dirread.c, tif_dirinfo.c, tif_jpeg.c, + tif_fax3.c, tif_jbig.c, tif_luv.c, tif_ojpeg.c, tif_pixarlog.c, + tif_predict.c, tif_zip.c}: Finally fix bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1274 + + by introducing _TIFFMergeFieldInfo() returning integer error status + instead of void in case of problems with field merging (e.g., if the + field with such a tag already registered). TIFFMergeFieldInfo() in + public API remains void. Use _TIFFMergeFieldInfo() everywhere and + check returned value. + +2007-04-07 Frank Warmerdam + + * contrib/addtiffo/tif_overview.c: Fix problems with odd sized output + blocks in TIFF_DownSample_Subsampled() (bug 1542). + +2007-04-06 Frank Warmerdam + + * libtiff/tif_jpeg.c: Changed JPEGInitializeLibJPEG() so that it + will convert from decompressor to compressor or compress to decompress + if required by the force arguments. This works around a problem in + where the JPEGFixupTestSubsampling() may cause a decompressor to + be setup on a directory when later a compressor is required with the + force flag set. Occurs with the addtiffo program for instance. + +2007-04-06 Andrey Kiselev + + * tools/tiffcrop.c, man/tiffcrop.1: Significant update in + functionality from Richard Nolde. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1525 + +2007-03-28 Frank Warmerdam + + * libtiff/tif_fax3.c: "inline static" -> "static inline" for IRIC CC. + +2007-03-17 Joris Van Damme + + * start of BigTIFF upgrade - CVS HEAD unstable until further notice + +2007-03-07 Joris Van Damme + + * libtiff/tif_getimage.c: workaround for 'Fractional scanline' error reading + OJPEG images with rowsperstrip that is not a multiple of vertical subsampling + factor. This bug is mentioned in: + http://bugzilla.remotesensing.org/show_bug.cgi?id=1390 + http://www.asmail.be/msg0054766825.html + +2007-03-07 Joris Van Damme + + * libtiff/tif_win32.c: made inclusion of windows.h unconditional + + * libtiff/tif_win32.c: replaced preprocessor indication for consiously + unused arguments by standard C indication for the same + +2007-02-27 Andrey Kiselev + + * libtiff/tif_dirread.c: Use uint32 type instead of tsize_t in byte + counters in TIFFFetchData(). Should finally fix the issue + + http://bugzilla.remotesensing.org/show_bug.cgi?id=890 + +2007-02-24 Andrey Kiselev + + * tools/tiffset.c: Properly handle tags with TIFF_VARIABLE writecount. + As per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1350 + + * libtiff/tif_dirread.c: Added special function to handle + SubjectDistance EXIF tag as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1362 + + * tools/tiff2pdf.c: Do not assume inches when the resolution units + do not specified. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1366 + + * tools/{tiffcp.c, tiffcrop.c}: Do not change RowsPerStrip value if + it was set as infinite. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1368 + + * tools/tiffcrop.c, man/tiffcrop.1: New tiffcrop utility contributed + by Richard Nolde. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1383 + +2007-02-22 Andrey Kiselev + + * libtiff/tif_dir.c: Workaround for incorrect TIFFs with + ExtraSamples == 999 produced by Corel Draw. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1490 + + * libtiff/{tif_dirread.c, tif_read.c}: Type of the byte counters + changed from tsize_t to uint32 to be able to work with data arrays + larger than 2GB. Fixes bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=890 + + Idea submitted by Matt Hancher. + +2007-01-31 Andrey Kiselev + + * tools/tif2rgba.c: This utility does not work properly on big-endian + architectures. It was fixed including the bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1149 + +2007-01-15 Mateusz Loskot + + * Submitted libtiff port for Windows CE platform + * libtiff/tif_config.wince.h: Added configuration header for WinCE. + * libtiff/tiffconf.wince.h: Ported old configuration header for WinCE. + * libtiff/tif_wince.c: Added WinCE-specific implementation of some + functons from tif_win32.c. + * libtiff/tif_win32.c: Disabled some functions already reimplemented in tif_wince.c. + * libtiff/tiffiop.h, port/lfind.c: Added conditional include of some + standard header files for Windows CE build. + * tools/tiffinfoce.c: Ported tiffinfo utility for Windows CE. + +2006-11-19 Frank Warmerdam + + * libtiff/tif_write.c: TIFFAppendToStrip() - clear sorted flag if + we move a strip. + http://bugzilla.remotesensing.org/show_bug.cgi?id=1359 + +2006-10-13 Andrey Kiselev + + * libtiff/tif_dir.c: More fixes for vulnerabilities, reported + in Gentoo bug (): + + http://bugs.gentoo.org/show_bug.cgi?id=142383 + + * libtiff/contrib/dbs/xtiff/xtiff.c: Make xtiff utility compilable. + Though it is still far from the state of being working and useful. + +2006-10-12 Andrey Kiselev + + * libtiff/tif_fax3.c: Save the state of printdir codec dependent + method. + + * libtiff/tif_jpeg.c: Save the state of printdir codec dependent method + as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1273 + + * libtiff/tif_win32.c: Fixed problem with offset value manipulation + as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1322 + + * libtiff/{tif_read.c, tif_jpeg.c, tif_dir.c}: More fixes for + vulnerabilities, reported in Gentoo bug (): + + http://bugs.gentoo.org/show_bug.cgi?id=142383 + +2006-09-28 Andrey Kiselev + + * libtiff/{tif_fax3.c, tif_next.c, tif_pixarlog.c}: Fixed multiple + vulnerabilities, as per Gentoo bug (): + + http://bugs.gentoo.org/show_bug.cgi?id=142383 + +2006-09-27 Frank Warmerdam + + * libtiff/tif_lzw.c, libtiff/tif_zip.c: Fixed problems with mixing + encoding and decoding on the same read-write TIFF handle. The LZW + code can now maintain encode and decode state at the same time. The + ZIP code will switch back and forth as needed. + http://bugzilla.remotesensing.org/show_bug.cgi?id=757 + +2006-09-20 Frank Warmerdam + + * libtiff: Rename config.h.vc and tif_config.h.vc to config.vc.h and + tif_config.vc.h for easier identification by folks using an IDE. + +2006-07-25 Frank Warmerdam + + * tif_msdos.c: Avoid handle leak for failed opens. c/o Thierry Pierron + +2006-07-19 Frank Warmerdam + + * tif_dirwrite.c: take care not to flush out buffer of strip/tile + data in _TIFFWriteDirectory if TIFF_BEENWRITING not set. Relates + to bug report by Peng Gao with black strip at bottom of images. + +2006-07-12 Frank Warmerdam + + * tif_dirwrite.c: make sure to use uint32 for wordcount in + TIFFWriteNormanTag if writecount is VARIABLE2 for ASCII fields. + It already seems to have been done for other field types. Needed + for "tiffset" on files with geotiff ascii text. + +2006-07-04 Bob Friesenhahn + + * {configure.ac, libtiff/tif_config.h.vc, libtiff/tif_jbig.c} + (JBIGDecode): jbg_newlen is not available in older JBIG-KIT and + its use does not appear to be required, so use it only when it is + available. + +2006-06-24 Andrey Kiselev + + * libtiff/tif_dirinfo.c: Added missed EXIF tag ColorSpace (40961). + + * libtiff/tif_dirread.c: Move IFD fetching code in the separate + function TIFFFetchDirectory() avoiding code duplication in + TIFFReadDirectory() and TIFFReadCustomDirectory(). + +2006-06-19 Frank Warmerdam + + * tools/tiff2pdf.c: Fix handling of -q values. + http://bugzilla.remotesensing.org/show_bug.cgi?id=587 + +2006-06-17 Frank Warmerdam + + * tif_readdir.c: Added case in EstimateStripByteCounts() for tiled + files. Modified TIFFReadDirectory() to not invoke + EstimateStripByteCounts() for case where entry 0 and 1 are unequal + but one of them is zero. + http://bugzilla.remotesensing.org/show_bug.cgi?id=1204 + +2006-06-08 Andrey Kiselev + + * libtiff/{tif_open.c, tif_dirread.c, tiffiop.h}: Move IFD looping + checking code in the separate function TIFFCheckDirOffset(). + + * libtiff/tif_aux.c: Added _TIFFCheckRealloc() function. + + * tools/tiffcmp.c: Fixed floating point comparison logic as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1191 + + * libtiff/tif_fax3.c: Fixed problems in fax decoder as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1194 + + * tools/tiff2pdf.c: Fixed buffer overflow condition in + t2p_write_pdf_string() as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1196 + +2006-06-07 Andrey Kiselev + + * {configure, configure.ac, libtiff/tif_jbig.c, tools/tiffcp.c}: Added + support for JBIG compression scheme (34661 code) contributed by Lee + Howard. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=896 + + * configure, configure.ac: OJPEG support enabled by default. + + * contrib/ojpeg/: Removed. New OJPEG support does not need this patch. + +2006-06-03 Bob Friesenhahn + + * libtiff/{tif_dirinfo.c, tif_print.c} : Fix crash in + TIFFPrintDirectory(). Joris Van Damme authored the fix. + +2006-04-21 Andrey Kiselev + + * tools/tiff2pdf.c: Unified line ending characters (always use '\n') + as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1163 + + * README.vms, Makefile.am, configure.com, libtiff/{Makefile.am, + tif_config.h-vms, tif_stream.cxx, tif_vms.c, tiffconf.h-vms}: + Added support for OpenVMS by Alexey Chupahin, elvis_75@mail.ru. + +2006-04-20 Andrey Kiselev + + * tools/{fax2ps.c, fax2tiff.c, ppm2tiff.c, ras2tiff.c, tiff2pdf.c}: + Properly set the binary mode for stdin stream as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1141 + + * man/{bmp2tiff.1, fax2ps.1, fax2tiff.1, gif2tiff.1, ras2tiff.1, + raw2tiff.1, rgb2ycbcr.1, sgi2tiff.1, tiff2bw.1, tiff2pdf.1, tiff2ps.1, + tiff2rgba.1, tiffcmp.1, tiffcp.1, tiffdither.1, tiffdump.1, tiffgt.1, + tiffset.1}: Improvements in page formatting as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1140 + + * html/tools.html, html/man/Makefile.am, tools/tiff2pdf.c: Fixed + typos as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1139 + +2006-04-18 Frank Warmerdam + + * nmake.opt: use /EHsc for VS2005 compatibility. Also define + _CRT_SECURE_NO_DEPRECATE to avoid noise on VS2005. + +2006-04-12 Joris Van Damme + + * libtiff/tif_getimage.c: Added support for planarconfig separate + non-subsampled YCbCr (i.e. separate YCbCr with subsampling [1,1]) + +2006-04-11 Joris Van Damme + + * libtiff/tif_getimage.c: Revision of all RGB(A) put routines + - Conversion of unassociated alpha to associated alpha now done with + more performant LUT, and calculation more correct + - Conversion of 16bit data to 8bit data now done with + more performant LUT, and calculation more correct + - Bugfix of handling of 16bit RGB with unassociated alpha + +2006-04-11 Joris Van Damme + + * libtiff/tif_getimage.c: + - When there is no alpha, gtTileSeparate and gtStripSeparate allocated + buffer for alpha strile and filled it, only to never read it back. + Removed allocation and fill. + - Minor rename of vars in gtTileSeparate and gtStripSeparate + anticipating planned functionality extension + +2006-04-08 Joris Van Damme + + * libtiff/tif_getimage.c: renamed pickTileContigCase to PickContigCase + and pickTileSeparateCase to PickSeparateCase as both work on strips as + well + + * libtiff/tif_getimage.c: moved img->get selection from + TIFFRGBAImageBegin into PickContigCase and PickSeparateCase to create + logical hook for planned functionality extension + +2006-04-08 Joris Van Damme + + * libtiff/tif_ojpeg.c: resolved memory leak that was a consequence + of inappropriate use of jpeg_abort instead of jpeg_destroy + +2006-04-07 Joris Van Damme + + * libtiff/tif_getimage.c: replaced usage of TIFFScanlineSize in + gtStripContig with TIFFNewScanlineSize so as to fix buggy behaviour + on subsampled images - this ought to get sorted when we feel brave + enough to replace TIFFScanlineSize alltogether + + * libtiff/tif_ojpeg.c: fixed bug in OJPEGReadSkip + +2006-04-04 Joris Van Damme + + * libtiff/tiffio.h: added new type tstrile_t + + * libtiff/tif_dir.h: changed types of td_stripsperimage and td_nstrips + to new tstrile_t, types of td_stripoffset and td_stripbytecount to + toff_t* + + * libtiff/tif_ojpeg.c: totally new implementation + + * libtiff/tif_dirread.c: added several hacks to suit new support of + OJPEG + + * libtiff/tif_getimage.c: removed TIFFTAG_JPEGCOLORMODE handling + of OJPEG images in favor of tif_getimage.c native handling of + YCbCr and desubsampling + +2006-03-29 Frank Warmerdam + + * libtiff/tif_jpeg.c: JPEGVSetField() so that altering the photometric + interpretation causes the "upsampled" flag to be recomputed. Fixes + peculiar bug where photometric flag had to be set before jpegcolormode + flag. + +2006-03-25 Joris Van Damme + + * libtiff/tif_jpeg.c: strip size related bugfix in encode raw + + * libtiff/tif_strip.c: temporarilly added two new versions of + TIFFScanlineSize + - TIFFNewScanlineSize: proposed new version, after all related + issues and side-effects are sorted out + - TIFFOldScanlineSize: old version, from prior to 2006-03-21 change + This needs further sorting out. + +2006-03-25 Joris Van Damme + + * contrib/addtiffo/tif_ovrcache.c: bugfix to correctly pass size + of last truncated strip data to TIFFWriteEncodedStrip + +2006-03-25 Joris Van Damme + + * libtiff/{tif_jpeg.c, tif_strip.c}: bugfix of tif_jpeg decode raw + +2006-03-25 Joris Van Damme + + * libtiff/tif_getimage.c: bugfix/rewrite of putcontig8bitYCbCr22tile + + * libtiff/tif_getimage.c: added putcontig8bitYCbCr12tile + + * libtiff/tif_read.c: added support for new TIFF_NOREADRAW flag to + prepare the path for new tif_ojpeg.c + +2006-03-23 Andrey Kiselev + + * libtiff 3.8.2 released. + + * tools/Makefile.am: Use runtime paths linker flags when rpath + option enabled. + +2006-03-21 Andrey Kiselev + + * libtiff/libtiff.def: Added missed exports as per bug + http://bugzilla.remotesensing.org/attachment.cgi?id=337 + + * contrib/addtiffo/Makefile.vc, libtiff/Makefile.vc, port/Makefile.vc, + tools/Makefile.vc: Makefiles improvements as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1128 + + * nmake.opt libtiff/{tif_config.h.vc, tif_unix.c, tiffio.h}, + tools/{fax2ps.c, fax2tiff.c, tiff2pdf.c}: Fixed win32 I/O functions + usage as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1127 + + * libtiff/tif_strip.c: Take subsampling in account when calculating + TIFFScanlineSize(). + + * tools/tiffcp.c: Do not set RowsPerStrip bigger than image length. + +2006-03-17 Andrey Kiselev + + * tools/fax2tiff.c: Fixed wrong TIFFerror() invocations as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1125 + + * tools/fax2ps.c: Fixed reading the input stream from stdin as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1124 + +2006-03-16 Andrey Kiselev + + * libtiff/tiffiop.h: Added decalration for + _TIFFSetDefaultCompressionState(). + + * libtiff/{tif_jpeg.c, tif_fax3.c, tif_zip.c, tif_pixarlog.c, + tif_lzw.c, tif_luv.c}: Use _TIFFSetDefaultCompressionState() in all + codec cleanup methods. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1120 + +2006-03-15 Andrey Kiselev + + * libtiff/tif_jpeg.c: Do not cleanup codec state in TIFFInitJPEG(). As + per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1119 + + * tools/raw2tiff.c: Do not set RowsPerStrip larger than ImageLength. + As per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1110 + + * libtiff/tiffiop.h: dblparam_t typedef removed; GLOBALDATA macro + removed; move here the STRIP_SIZE_DEFAULT macro definition. + + * libtiff/{tif_dirread.c, tif_strip.c}: Removed STRIP_SIZE_DEFAULT + macro definition. + + * libtiff/tif_dir.c: Use double type instead of dblparam_t. + +2006-03-14 Andrey Kiselev + + * libtiff/tif_dirread.c: Do not check the PlanarConfig tag presence + in TIFFReadDirectory, because it is always set at the start of + function and we allow TIFFs without that tag set. + +2005-03-13 Andrey Kiselev + + * libtiff 3.8.1 released. + +2006-03-07 Andrey Kiselev + + * libtiff/tif_dirread.c: Fixed error reporting in TIFFFetchAnyArray() + function as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 + + * libtiff/tif_dirread.c: More wise check for integer overflow + condition as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 + + * libtiff/{tif_jpeg.c, tif_pixarlog.c, tif_fax3.c, tif_zip.c}: + Properly restore setfield/getfield methods in cleanup functions. As + per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 + +2006-03-03 Andrey Kiselev + + * libtiff/{tif_predict.c, tif_predict.h}: Added new function + TIFFPredictorCleanup() to restore parent decode/encode/field methods. + + * libtiff/{tif_lzw.c, tif_pixarlog.c, tif_zip.c}: Use + TIFFPredictorCleanup() in codec cleanup methods. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 + + * libtiff/tif_dirread.c: Fixed integer overflow condition in + TIFFFetchData() function. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1102 + +2006-03-01 Andrey Kiselev + + * libtiff/tif_ojpeg.c: Set the ReferenceBlackWhite with the + TIFFSetField() method, not directly. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1043 + + * tools/ppm2tiff.c: Added support for PBM files as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1044 + +2006-02-27 Andrey Kiselev + + * libtiff/tif_write.c: Small code rearrangement in TIFFWriteScanline() + to avoid crash as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1081. + +2006-02-26 Andrey Kiselev + + * tools/tiff2pdf.c: Functions t2p_sample_rgbaa_to_rgb() and + t2p_sample_rgba_to_rgb() was used in place of each other, that was + resulted in problems with RGBA images with associated alpha. + As per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1097 + +2006-02-23 Andrey Kiselev + + * libtiff/tif_dirwrite.c: Properly write TIFFTAG_DOTRANGE tag as per + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1088. + + * libtiff/tif_print.c: Properly read TIFFTAG_PAGENUMBER, + TIFFTAG_HALFTONEHINTS, TIFFTAG_YCBCRSUBSAMPLING and TIFFTAG_DOTRANGE + tags as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1088. + + * tools/tiff2ps.c: Properly scale all the pages when converting + multipage TIFF with /width/height/center options set. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1080 + +2006-02-15 Andrey Kiselev + + * tools/tiff2pdf.c: Do not create output file until all option checks + will be done. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1072 + + * tools/bmp2tiff.c: Added ability to create multipage TIFFs from the + list of input files as per bug: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1077 + +2006-02-09 Andrey Kiselev + + * libtiff/tif_tile.c: Fix error reporting in TIFFCheckTile() as per + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1063. + + * tools/tiffgt.c: Avoid crashing in case of image unsupported by + TIFFRGBAImage interface. + + * libtiff/tif_color.c: Avoid overflow in case of wrong input as per + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1065. + +2006-02-07 Frank Warmerdam + + * tools/tiff2pdf.c: Fixed support for non-YCbCr encoded JPEG + compressed TIFF files, per submission from Dan Cobra. + +2006-02-07 Andrey Kiselev + + * libtiff/{tif_dirread.c, tif_packbits.c, tif_win32.c}: Properly + cast values to avoid warnings. As per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1033. + + * libtiff/tif_dirinfo.c: Use TIFF_NOTYPE instead of 0 when + appropriate. As per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1033. + + * libtiff/tif_aux.c: Fixed type of temporary variable in + _TIFFCheckMalloc() as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=1033. + +2006-02-06 Andrey Kiselev + + * libtiff/tif_aux.c: Return static array when fetching default + YCbCrCoefficients (another problem, reported a the + http://bugzilla.remotesensing.org/show_bug.cgi?id=1029 entry). + +2006-02-03 Andrey Kiselev + + * libtiff/tif_dir.c: Special handling for PageNumber, HalftoneHints, + YCbCrSubsampling and DotRange tags as per bugs + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1029 + http://bugzilla.remotesensing.org/show_bug.cgi?id=1034 + + * libtiff/tif_dirread.c: Use _TIFFGetExifFieldInfo() instead of + _TIFFGetFieldInfo() in TIFFReadEXIFDirectory() call as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1026. + +2006-01-23 Andrey Kiselev + + * libtool related stuff updated from the 2.1a branch. + +2006-01-11 Frank Warmerdam + + * tools/bmp2tiff,pal2rgb,ppm2tiff,ras2tiff,raw2tiff,sgi2tiff, + tiff2bw,tiffcp: Fixed jpeg option processing so -c jpeg:r:50 works + properly as per bug: + http://bugzilla.remotesensing.org/show_bug.cgi?id=1025 + +2006-01-09 Bob Friesenhahn + + * configure.ac: Fix with_default_strip_size comparison as reported + by Norihiko Murase. + +2006-01-08 Bob Friesenhahn + + * test/Makefile.am (LIBTIFF): Due to linking against libtiff + incorrectly, tests were not actually testing the uninstalled + libtiff. Now they are. + +2006-01-04 Andrey Kiselev + + * libtiff/tif_dirinfo.c: Change definitions for TIFFTAG_ICCPROFILE, + TIFFTAG_PHOTOSHOP, TIFFTAG_RICHTIFFIPTC, TIFFTAG_XMLPACKET: readcount + should be uint32 value. + +2006-01-02 Bob Friesenhahn + + * html/man/Makefile.am (htmldoc): Fix htmldoc rule so that it can + be used if build directory is not the same as source directory. + * man/{TIFFGetField.3tiff, TIFFSetField.3tiff}: Documented + TIFFTAG_PHOTOSHOP, TIFFTAG_RICHTIFFIPTC, and TIFFTAG_XMLPACKET, + and re-sorted tag names in alphabetical order. + +2005-12-29 Andrey Kiselev + + * libtiff 3.8.0 released. + +2005-12-28 Bob Friesenhahn + + * tools/bmp2tiff.c (main): Fixed warning regarding returning + inconsistent types from a condition. + * tools/tiffcmp.c (CheckLongTag): Eliminate warning due to printf + format. + * tools/bmp2tiff.c: Reduce compilation warnings on big-endian CPUs. + +2005-12-28 Joris Van Damme + + * html/{index.html, support.hml, libtiff.html}: Cleaned up HTML + +2005-12-27 Andrey Kiselev + + * libtiff/tiffio.h: Added VC_EXTRALEAN definition before including + windows.h, to reduce the compile time. + +2005-12-26 Bob Friesenhahn + + * libtiff/tif_jpeg.c: Improve compilation under MinGW. + +2005-12-26 Andrey Kiselev + + * libtiff/{tif_dir.c, tif_dir.h, tif_dirread.c, tif_dirinfo.c}: + tiffFieldInfo and exifFieldInfo arrays definitions moved back to + tif_dirinfo.c; added _TIFFGetFieldInfo() and _TIFFGetExifFieldInfo() + private functions to retrieve FieldInfo arrays. + +2005-12-24 Bob Friesenhahn + + * html/build.html: Added some additional instructions for when + building using MSVC under Windows. Also fixed two HTML syntax + errors and used HTML Tidy to tidy up the HTML syntax and + formatting. + +2005-12-24 Andrey Kiselev + + * libtiff/{tif_aux.c, tif_dir.c, tif_dir.h, tif_dirwrite.c, + tif_print.c, tif_getimage.c}: Make InkSet, NumberOfInks, DotRange and + StoNits tags custom. + +2005-12-23 Andrey Kiselev + + * libtiff/{tif_aux.c, tif_dir.c, tif_dir.h, tif_print.c}: Make + WhitePoint tag custom. + + * libtiff/{tif_dir.h, tiff.h}: More EXIF tags added. + +2005-12-23 Joris Van Damme + + * libtiff/tiffio.h: fixed typo that potentially resulted in + redefininition of USE_WIN32_FILEIO + + * libtiff/*: Added more 'dual-mode' error handling: Done TIFFWarning + calls in core LibTiff. + +2005-12-21 Andrey Kiselev + + * libtiff/{tif_dir.c, tif_dir.h, tif_print.c}: Make RichTIFFIPTC, + Photoshop and ICCProfile tags custom. + +2005-12-21 Joris Van Damme + + * libtiff/*, contrib/*: Added 'dual-mode' error handling, enabling + newer code to get context indicator in error handler and still + remain compatible with older code: Done TIFFError calls everywhere + except in tools + +2005-12-20 Andrey Kiselev + + * tools/tiffcp.c: Added many error reporting messages; fixed integer + overflow as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=789 + +2005-12-16 Frank Warmerdam + + * contrib/addtiffo/*: Major upgrade by Joris to support subsampled + YCbCr images in jpeg compressed TIFF files. + +2005-12-14 Andrey Kiselev + + * tools/tiffcp.c: Return non-zero status when reading fails (again). + +2005-12-13 Andrey Kiselev + + * tools/tiffcp.c: Return non-zero status when reading fails. + +2005-12-12 Andrey Kiselev + + * libtiff/{tif_dir.h, tiff.h}: Added more EXIF tags. + +2005-12-09 Andrey Kiselev + + * libtiff/{tif_dir.c, tif_dir.h, tif_print.c}: Make XMLPacket tag + custom. + + * tools/tiffinfo.c: Print EXIF directory contents if exist. + + * libtiff/tiff.h: Few EXIF tag numbers added. + + * libtiff/{tif_dirinfo.c, tif_dirread.c, tif_dir.h, tif_dir.c, + tiffio.h}: Preliminary support to read custom directories. New + functions: TIFFReadCustomDirectory() and TIFFReadEXIFDirectory(). + +2005-12-07 Andrey Kiselev + + * libtiff/{tif_dirinfo.c, tif_dirread.c, tif_dir.h, tif_dir.c}: + More work to implement custom directory read support. + + * libtiff/{tif_aux.c, tif_dirinfo.c, tif_dirread.c, tif_dir.h, + tif_dir.c, tif_print.c}: Make YCbCrCoefficients and ReferenceBlackWhite + tags custom. + +2005-12-05 Andrey Kiselev + + * libtiff/tif_dirread.c: One more workaround for broken + StripByteCounts tag. Handle the case when StripByteCounts array filled + with completely wrong values. + +2005-11-30 Andrey Kiselev + + * libtiff/tif_dirinfo.c: Release file descriptor in case of failure + in the TIFFOpenW() function as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1003 + + * libtiff/tif_dirinfo.c: Correctly yse bsearch() and lfind() + functions as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=1008 + +2005-11-20 Frank Warmerdam + + * tif_open.c, tiff.h, tiffdump.c: Incorporate preliminary support + for MS MDI format. + http://bugzilla.remotesensing.org/show_bug.cgi?id=1002 + + * .cvsignore: many files added, and a few update according + to suggestion of Brad HArds on tiff mailing list. + +2005-11-03 Frank Warmerdam + + * libtiff/libtiff.def, tiffiop.h, tiffio.h: Made TIFFFreeDirectory + public. + +2005-10-31 Andrey Kiselev + + * tools/fax2tiff.c: Properly calculate sizes of temporary arrays + as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=943 + + * tools/fax2tiff.c: Added option '-r' to set RowsPerStrip parameter + as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=944 + + * tools/tiffdump.c: Fixed typeshift and typemask arrays initialization + problem as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=946 + + * tools/bmp2tiff.c: Fixed possible integer overflow error as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=965 + + * libtiff/tif_dirinfo.c: Make XResolution, YResolution and + ResolutionUnit tags modifiable during write process. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=977 + + * tools/tiffsplit.c: Copy fax related fields over splitted parts + as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=983 + +2005-10-21 Frank Warmerdam + + * tif_dirread.c: Don't try and split single strips into "0" strips + in ChopUpSingleUncompressedStrip. This happens in some degenerate + cases (like 1x1 files with stripbytecounts==0 (gtsmall.jp2 embed tiff) + +2005-10-20 Joris Van Damme + + * tif_fax3.c: changed 'at scanline ...' style warning/errors + with incorrect use of tif_row, to 'at line ... of + strip/tile ...' style + +2005-10-15 Frank Warmerdam + + * tif_write.c: fixed setting of planarconfig as per bug report + on the mailing list from Joris. + +2005-10-07 Andrey Kiselev + + * configure.ac, configure, nmake.opt, libtiff/{tif_config.h, + tif_dirread.c}: Make the default strip size configurable via the + --with-default-strip-size and STRIP_SIZE_DEFAULT options. + +2005-09-30 Bob Friesenhahn + + * html/support.html: Fixed link to documentation on Greg Ward's + LogLuv TIFF format. + +2005-09-28 Andrey Kiselev + + * tools/tiffdump.c: Fixed crash when reading malformed tags. + +2005-09-20 Andrey Kiselev + + * tools/tiff2pdf.c: Added missed 'break' statement as per bug + http://bugzilla.remotesensing.org/show_bug.cgi?id=932 + +2005-09-12 Andrey Kiselev + + * libtiff 3.7.4 released. + + * {configure, configure.ac, Makefile.am, autogen.sh}: Applied patch + from Patrick Welche (all scripts moved in the 'config' and 'm4' + directories). + +2005-09-12 Frank Warmerdam + + * libtiff/tif_open.c: reintroduce seek to avoid problem on solaris. + +2005-09-05 Frank Warmerdam + + * libtiff/tif_dir.c: When prefreeing tv->value in TIFFSetFieldV + also set it to NULL to avoid double free when re-setting custom + string fields as per: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=922 + +2005-08-12 Frank Warmerdam + + * libtiff/tif_print.c: avoid signed/unsigned warning. + + * libtiff/tif_dirread.c: removed unused variable. + +2005-07-30 Frank Warmerdam + + * libtiff/tif_dir.c: Fixed up support for swapping "double complex" + values (128 bits as 2 64 bits doubles). GDAL gcore tests now + pass on bigendian (macosx) system. + +2005-07-28 Andrey Kiselev + + * libtiff/{tif_aux.c, tif_dirread.c, tif_fax3.c, tiffiop.h}: Rename + CheckMalloc() function to _TIFFCheckMalloc() and make it available + globally as an internal helper routine. + +2005-07-27 Andrey Kiselev + + * libtiff/tif_dir.c: More improvements in the "pass by value" part of + the custom tags handling code. + +2005-07-26 Andrey Kiselev + + * libtiff/{tif_dirread.c, tif_dirinfo.c}: Do not upcast BYTEs to + SHORTs in the TIFFFetchByteArray(). Remove TIFFFetchExtraSamples() + function, use TIFFFetchNormalTag() instead as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=831 + + Remove TIFFFetchExtraSamples() function, use TIFFFetchNormalTag() + instead. + + * libtiff/tiffconf.h.in: One more attempt to fix the AIX bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=39 + +2005-07-25 Andrey Kiselev + + * libtiff/tif_print.c: Fixed printing of the BYTE and SBYTE arrays. + + * tools/tiffdump.c: Added support for TIFF_IFD datatype. + +2005-07-21 Andrey Kiselev + + * libtiff/tif_write.c: Do not check the PlanarConfiguration field in + the TIFFWriteCheck() function in case of single band images (as per + TIFF spec). + +2005-07-12 Andrey Kiselev + + * SConstruct, libtiff/SConstruct: Added the first very preliminary + support for SCons software building tool (http://www.scons.org/). + This is experimental infrastructure and it will exist along with the + autotools mechanics. + +2005-07-07 Andrey Kiselev + + * port/{getopt.c, strcasecmp.c, strtoul.c}: Update modules from + the NetBSD source tree (the old 4-clause BSD license changed to + the new 3-clause one). + + * configure.ac, port/lfind.c, libtiff/tiffiop.h: Added lfind() + replacement module. + + * port/dummy.c: Make the dummy function static. + +2005-07-06 Andrey Kiselev + + * tools/tiffcp.c: Fixed WhitePoint tag copying. + + * libtiff/{tif_dir.c, tif_dir.h, tif_dirinfo.c, tif_print.c}: + Make FieldOfViewCotangent, MatrixWorldToScreen, MatrixWorldToCamera, + ImageFullWidth, ImageFullLength and PrimaryChromaticities tags custom. + +2005-07-04 Andrey Kiselev + + * libtiff 3.7.3 released. + + * configure, configure.ac: Do not use empty -R option when linking + with --enable-rpath. + +2005-07-01 Andrey Kiselev + + * libtiff/{tiffiop.h, tif_open.c}: Added open option 'h' to avoid + reading the first IFD when needed. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=875 + + * libtiff/tif_color.c: Better use of TIFFmin() macro to avoid side + effects. + +2005-06-23 Andrey Kiselev + + * tools/tiff2pdf.c: Print two characters per loop in the + t2p_write_pdf_trailer(). As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=594 + + * tools/tiffgt.c: Use MacOS X OpenGL framework when appropriate. As + per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=844 + + * acinclude.m4: Updated to latest OpenGL test macros versions. + + * libtiff/tiff.h: Use correct int size on Sparc 64bit/Sun compiler + platform. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=855 + +2005-06-14 Andrey Kiselev + + * libtiff/tif_dirinfo.c: Added support for ClipPath, XClipPathUnits + and YClipPathUnits tags. + +2005-06-07 Andrey Kiselev + + * contrib/addtiffo/tif_ovrcache.c: Properly extract tile/strip size; + use pixel sized shift in contigous case. + +2005-06-06 Andrey Kiselev + + * contrib/addtiffo/{tif_overview.c, tif_ovrcache.c, tif_ovrcache.h}: + Make overviews working for contiguos images. + +2005-06-03 Andrey Kiselev + + * libtiff/tif_open.c: Replace runtime endianess check with the compile + time one. + + * libtiff/tif_predict.c: Floating point predictor now works on + big-endian hosts. + +2005-06-01 Andrey Kiselev + + * libtiff/tif_dir.c: Use _TIFFsetString() function when read custom + ASCII values. + + * libtiff/{tif_dirinfo.c, tif_dir.h, tif_dir.c, tif_print.c}: Make + DocumentName, Artist, HostComputer, ImageDescription, Make, Model, + Copyright, DateTime, PageName, TextureFormat, TextureWrapModes and + TargetPrinter tags custom. + + * libtiff/tif_jpeg.c: Cleanup the codec state depending on + TIFF_CODERSETUP flag (to fix memry leaks). + + * libtiff/tif_jpeg.c: Initialize JPEGTables array with zero after + allocating. + +2005-05-26 Andrey Kiselev + + * configure.ac, libtiff/Makefile.am: Added workaround for + OpenBSD/MirOS soname problem as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=838 + + * libtiff/tif_dirwrite.c: Use tdir_count when calling + TIFFCvtNativeToIEEEDouble() in the TIFFWriteDoubleArray() function as + per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=845 + +2005-05-25 Andrey Kiselev + + * tools/ppm2tiff.c: Fixed format string when read PPM file header with + the fscanf() function. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=861 + + * libtiff/{tif_dirinfo.c, tif_print.c}: TIFFFetchByteArray() returns + uint16 array when fetching the BYTE and SBYTE filds, so we should + consider result as pointer to uint16 array and not as array of chars. + As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=831 + + * libtiff/tif_dir.c: More efficient custom tags retrieval as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=830 + + * libtiff/tif_win32.c: Use FILE_SHARE_READ | FILE_SHARE_WRITE share + mode in CreateFile() call as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=829 + + * libtiff/Makefile.am: Fixed parallel compilation of the libtiff and + libtiffxx libraries as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=826 + + * contrib/addtiffo/{tif_overview.c, tif_ovrcache.h}: Sinchronized with + GDAL. + +2005-05-23 Frank Warmerdam + + * libtiff/tif_jpeg.c: Substantial fix for addtiffo problems with + JPEG encoded TIFF files. Pre-allocate lots of space for jpegtables + in directory. + +2005-05-22 Frank Warmerdam + + * libtiff/tif_dirread.c: Changed the code that computes + stripbytecount[0] if it appears bogus to ignore if stripoffset[0] is + zero. This is a common case with GDAL indicating a "null" tile/strip. + +2005-05-17 Andrey Kiselev + + * tools/tiffsplit.c: Check for JPEGTables tag presence before copying. + +2005-05-06 Frank Warmerdam + + * libtiff/tif_dirread.c: Applied similar change to + TIFFFetchPerSampleLongs and TIFFFetchPerSampleAnys. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=843 + + * libtiff/tif_jpeg.c: added LIB_JPEG_MK1 support in JPEGDecodeRaw(). + +2005-05-06 Andrey Kiselev + * tools/tiff2pdfr.c, man/tiff2pdf.1: Calculate the tile width properly; + added new option '-b' to use interpolation in output PDF files (Bruno + Ledoux). + +2005-05-05 Frank Warmerdam + + * libtiff/tif_dirread.c: Ensure that broken files with too many + values in PerSampleShorts work ok instead of crashing. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=843 + +2005-04-27 Andrey Kiselev + + * tools/tiffdither.c: Copy the PhotometricInterpretation tag from the + input file. + +2005-04-15 Andrey Kiselev + + * libtiff/tif_predict.c: Added ability to encode floating point + predictor, as per TIFF Technical Note 3. + +2005-04-14 Andrey Kiselev + + * libtiff/{tif_predict.h, tif_predict.c}: Added ability to decode + floating point predictor, as per TIFF Technical Note 3. + +2005-04-13 Andrey Kiselev + + * libtiff/{tiffio.h, tiffiop.h, tif_dir.c, tif_read.c, tif_swab.c}: + Added _TIFFSwab24BitData() and TIFFSwabArrayOfLong() functions used to + swap 24-bit floating point values. + + * libtiff/tiff.h: Added predictor constants. + +2005-04-08 Andrey Kiselev + + * libtiff/{tiffiop.h, tif_dir.c}: Use uint32 type for appropriate + values in _TIFFVSetField() function. Inspired by the bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=816 + + * man/TIFFSetField.3tiff: Fixed definition of the TIFFTAG_INKNAMES tag + as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=816 + +2005-03-30 Andrey Kiselev + + * libtiff/tif_open.c: Do not read header in case the output file + should be truncated (Ron). + + * libtiff/{tif_dirinfo.c, tif_config.h.vc}: Use lfind() instead + of bsearch() in _TIFFFindFieldInfoByName() function (Ron). + + * libtiff/{tiff.h, tif_dirinfo.c}: Fixes in EXIF tag ordering (Ron). + +2005-03-22 Andrey Kiselev + + * configure.ac, libtiff/Makefile.am: Use libtool machinery to pass + rpath option. + +2005-03-21 Andrey Kiselev + + * libtiff/{tif_dir.c, tif_print.c}: Handle all data types in custom + tags. + +2005-03-18 Andrey Kiselev + + * libtiff/dirinfo.c: Added DNG tags. + + * libtiff/{tif_dir.c, tif_print.c}: More improvements in custom tag + handling code. + + * libtiff/tiff.h: More comments; added missed DNG tag (LensInfo); + added DNG 1.1.0.0 tags. + + * tools/tif2pdf.c: Fixed problem with alpha channel handling as per + bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=794 + + * man/TIFFGetField.3tiff: Add a note about autoregistered tags. + +2005-03-17 Andrey Kiselev + + * nmake.opt: Build with Win32 CRT library by default. + + * tools/tiff2ps.c: Fixed typo in page size handling code. + + * libtiff/{tif_dir.c, tif_print.c}: Support for custom tags, passed + by value. + + * libtiff/{tiff.h, tif_dirinfo.c, tiffiop.h}: Added EXIF related tags. + +2005-03-15 Andrey Kiselev + + * libtiff 3.7.2 released. + +2005-03-09 Andrey Kiselev + + * tools/tiffcmp.c: Added ability to compare the 32-bit integer and + floating point data; complain on unsupported bit depths. + +2005-03-05 Andrey Kiselev + + * tif_stream.cxx: Use ios namespace instead of ios_base to support + GCC 2.95. + + * libtiff/{tiff.h, tif_fax3.tif, tif_jpeg.c}: Applied correct patch from + Lee Howard for HylaFax DCS tag + (see http://bugzilla.remotesensing.org/show_bug.cgi?id=771) + +2005-03-04 Andrey Kiselev + + * configure, configure.ac: Use -rpath option instead of -R as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=732 + + * libtiff/{tiff.h, tif_fax3.tif, tif_jpeg.c}: Applied patch from Lee + Howard to support a new tag TIFFTAG_FAXDCS (34911) used in HylaFax + software. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=771 + + * nmake.opt, html/build.html: Add more comments, change the config + file organization a bit as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=764 + + * tools/tiffcmp.c: Use properly sized buffer in short arrays comparison + as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=785 + +2005-03-03 Andrey Kiselev + + * libtiff/tif_dirread.c: More logic to guess missed strip size as per + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=705 + + * tools/fax2ps.c: Replace insecure mktemp() function with the + tmpfile() as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=786 + +2005-02-04 Andrey Kiselev + + * libtiff/tiff.h: Changed the int8 definition to be always signed char + as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=727 + + * libtiff/tiffio.h: Move TIFFOpenW() function into the extern "C"{} + block as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=763 + +2005-02-03 Bob Friesenhahn + + * tools/tiffgt.c: Fix problem on big-endian CPUs so that images + display more correctly. Images display brighter than they should + on a Sun workstation. + +2005-02-03 Andrey Kiselev + + * libtiff/tif_dirread.c: Estimate strip size in case of wrong or + suspicious values in the tags. As per bugs + + http://bugzilla.remotesensing.org/show_bug.cgi?id=705 + + and + + http://bugzilla.remotesensing.org/show_bug.cgi?id=320 + + * tools/tiff2ps.c: Fixed problem with page sizes as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=742 + +2005-01-31 Bob Friesenhahn + + * libtiff/tiff.h (TIFFTAG_TILEWIDTH): Corrected description. + (TIFFTAG_TILELENGTH): Corrected description. + +2005-01-30 Andrey Kiselev + + * configure.ac: Fixes for --with-docdir option as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=759 + + * libtiff/tif_open.c: Remove unnesessary TIFFSeekFile() call as per + bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=756 + + * libtiff/tif_stream.cxx: Fixes for C++ stream interface from + Michael Rinne and Edward Lam. + +2005-01-15 Andrey Kiselev + + * configure.ac: Make the documentation directory location configurable + via the --with-docdir option (as suggested by Jeremy C. Reed). + + * libtiff/tif_color.c: Use double as the second argument of pow() + function in TIFFCIELabToRGBInit(). As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=741 + + * libtiff/tif_pixarlog.c: Avoid warnings when converting float to + integer as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=740 + + * libtiff/tif_getimage.c: Always fill the error message buffer in + TIFFRGBAImageBegin() as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=739 + +2005-01-12 Andrey Kiselev + + * libtiff/tif_jpeg.c: Added ability to read/write the fax specific + TIFFTAG_FAXRECVPARAMS, TIFFTAG_FAXSUBADDRESS and TIFFTAG_FAXRECVTIME + tags as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=736 + + * libtiff/tif_win32.c: Fixed message formatting in functions + Win32WarningHandler() and Win32ErrorHandler() as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=735 + + * tools/tiff2ps.c: Interpret the -w and -h options independently. As + per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=689 + +2005-01-11 Andrey Kiselev + + * libtiff/tiffio.h: Move the color conversion routines in the 'extern + "C"' section as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=727 + + * libtiff/tiff.h: Restore back the workaround for AIX Visual Age C + compiler to avoid double definition of BSD types as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=39 + + * libtiff/Makefile.am: Place the C++ stream API in the separate + library called libtiffxx to avoid unneeded dependencies. Probably + there will be more C++ API in the future. As per bugs + + http://bugzilla.remotesensing.org/show_bug.cgi?id=733 + + and + + http://bugzilla.remotesensing.org/show_bug.cgi?id=730 + +2005-01-05 Andrey Kiselev + + * tools/tiffdump.c: Fixed problem when read broken TIFFs with the + wrong tag counts (Dmitry V. Levin, Martin Pitt). + + * configure.ac: Replace --disable-c++ with the --disable-cxx option as + per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=730 + +2004-12-25 Andrey Kiselev + + * libtiff/tif_getimage.c: More fixes for multiple-alpha-channelled + RGB-images as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=713 + + + * tools/tiffset.c: Convert character option to integer value as per + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=725 + +2004-12-20 Andrey Kiselev + + * libtiff 3.7.1 released. + + * html/tiffset.1.html: Add missed manual page as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=678 + + * libtiff/tiff.h: Revert back libtiff data type definitions as per + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=687 + +2004-12-19 Andrey Kiselev + + * libtiff/tif_dirread.c: Do not forget about TIFF_VARIABLE2 when + checking for tag count in TIFFReadDirectory() function. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=713 + + * libtiff/{tif_dirread.c, tif_fax3.c}: More argument checking in + CheckMallock() function. + + * libtiff/tif_getimage.c: Support for multiple-alpha-channelled + RGB-images as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=718 + +2004-12-15 Frank Warmerdam + + * libtiff/tif_getimage.c: #define A1 bracketing for clean build on + SunPro compiler. + +2004-12-11 Bob Friesenhahn + + * autogen.sh: aclocal and autoheader should be executed after + libtoolize. Also add '-I .' to aclocal invocation to check + current directory for macros. + +2004-12-10 Andrey Kiselev + + * libtiff/tif_dirwrite.c: Always write TIFFTAG_SUBIFD using LONG type + as per bugs + + http://bugzilla.remotesensing.org/show_bug.cgi?id=703 + + and + + http://bugzilla.remotesensing.org/show_bug.cgi?id=704 + +2004-12-04 Andrey Kiselev + + * nmake.opt: Link with the user32.lib in windowed mode. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=697 + + * libtiff/tif_win32.c: Use char* strings instead of TCHAR in windowed + mode as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=697 + + * libtiff/tif_config.in.vc: Removed unneded definitions for + read/open/close/lseek functions to fix the + + http://bugzilla.remotesensing.org/show_bug.cgi?id=680 + +2004-12-03 Andrey Kiselev + + * libtiff/{tif_dir.c, tif_dirread.c}: Remove TIFFReassignTagToIgnore() + call from the TIFFReadDirectory() function. TIFFReassignTagToIgnore + must be removed in the future, as it was never used properly. As per + bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=692 + +2004-11-30 Bob Friesenhahn + + * libtiff/tif_jpeg.c: Added a work-around in order to allow + compilation with the heavily modified version of libjpeg delivered + with Cygwin. + +2004-11-29 Andrey Kiselev + + * libtiff/tif_dir.c: Properly handle tags, which have the uint32 + counts. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=693 + + * tools/fax2ps.c: Be able to extract the first page (#0). As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=690 + +2004-11-28 Andrey Kiselev + + * libtiff/tif_unix.c: Make UNIX module compilable (and usable) + on Windows. + + * nmake.opt: Add missed DLLNAME variable. + +2004-11-26 Frank Warmerdam + + * libtiff/makefile.vc: make it easier to rename the libtiff DLL. + +2004-11-24 Andrey Kiselev + + * man/libtiff.3tiff: Improvements in the "LIST OF ROUTINES" table as + per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=545 + + * man/tiffset.1: Added manual page for tiffset tool written by Jay + Berkenbilt. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=678 + +2004-11-23 Frank Warmerdam + + * libtiff/tif_error.c: fixed TIFFerror call to be TIFFError. + +2004-11-21 Frank Warmerdam + + * html/document.html: Updated Adobe web links as per email from Joris. + +2004-11-21 Andrey Kiselev + + * libtiff/{tiffio.hxx, tiffio.h}: C++ stream interface moved to new + file tiffio.hxx. We don't have any C++ in tiffio.h, those who want to + use C++ streams should #include . + +2004-11-13 Andrey Kiselev + + * libtiff/tiff.h: Added Adobe DNG tags. + + * libtiff/tif_win32.c: Typo fixed. + + * libtiff/{tif_stream.cxx, tiffio.h}: C++ stream interface updated to + be compliant with the latest standard. Appropriate additions in + makefiles now completed. + +2004-11-11 Andrey Kiselev + + * tools/tiffset.c, libtiff/tif_dirinfo.c: Properly handle the + different tag types. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=600 + +2004-11-10 Andrey Kiselev + + * libtiff/tif_aux.c: Set the appropriate ReferenceBlackWhite array for + YCbCr image which lacks that tag (noted by Hans Petter Selasky). + +2004-11-09 Andrey Kiselev + + * libtiff/tif_color.c: Division by zero fixed (Hans Petter Selasky). + +2004-11-07 Andrey Kiselev + + * libtiff/{tif_stream.cxx, tiffio.h}: Added C++ stream interface + contributed by Edward Lam (see + http://bugzilla.remotesensing.org/show_bug.cgi?id=654 for details). + Though no changes in any makefiles yet. + +2004-11-05 Frank Warmerdam + + * libtiff/tif_open.c: Removed close() in TIFFClientOpen() if file + is bad. This is the callers responsibility. + http://bugzilla.remotesensing.org/show_bug.cgi?id=651 + +2004-11-05 Andrey Kiselev + + * libtiff/{tiffio.h, tif_win32.c, libtiff.def}: Added TIFFOpenW() + function to work with the double byte strings (used to represent + filenames in some locales). As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=625 + + * libtiff/tif_dirread.c: Fixed problem when fetching BitsPerSample and + Compression tags of type LONG from broken TIFFS as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=662 + + * libtiff/tif_dirinfo.c: Fixed definition for TIFFTAG_RICHTIFFIPTC, + the writecount should have uint32 type. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=662 + + * libtiff/tif_write.c: Fixed wrong if() statement in + TIFFAppendToStrip() function as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=660 + +2004-11-04 Andrey Kiselev + + * libtiff/tif_dirinfo.c: Change definition for TIFFTAG_EXTRASAMPLES + field. The caller should supply a count when setting this field. As + per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=648 + + * libtiff/{tif_jpeg.c, tif_ojpeg.c}: TIFFTAG_JPEGTABLES should have + uint32 count. Use this type everywhere. + +2004-11-03 Frank Warmerdam + + * libtiff/tif_next.c: avoid use of u_long and u_char types. Bug 653. + +2004-11-02 Frank Warmerdam + + * tools/tiff2rgba.c: removed extra newlines in usage message. + +2004-10-30 Andrey Kiselev + + * libtiff/tif_dirwrite.c: Improvements in tag writing code. + + * tools/tiff2ps.c: Fixed wrong variable data type when read Position + tags (Tristan Hill). + +2004-10-30 Frank Warmerdam + + * libtiff/tiffiop.h: added fallback definition of assert() if we + don't have assert.h. + +2004-10-29 Andrey Kiselev + + * libtiff/tif_fax3.c: Fixed case with the wrong decode routines + choosing when the incorrect Group4Options tag set. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=323 + + * libtiff/tif_dirwrite.c: Fixed problem with passing count variable of + wrong type when writing the TIFF_BYTE/TIFF_SBYTE tags in + TIFFWriteNormalTag(). + +2004-10-28 Andrey Kiselev + + * tools/tiff2ps.c: Fixed wrong variable data type when read Resolution + tags (Peter Fales). + + * tools/{bmp2tiff.c, raw2tiff.c}: Get rid of stream I/O functions. + +2004-10-28 Frank Warmerdam + + * tools/tiff2pdf.c: added casts to avoid warnings. + + * libtiff/libtiff.def: Added several more entry points required + to link fax2tiff.c against the DLL on windows. + +2004-10-27 Andrey Kiselev + + * configure, configure.ac: Added --enable-rpath option to embed linker + paths into library binary. + +2004-10-26 Andrey Kiselev + + * tools/tiffset.c: Check the malloc return value (Dmitry V. Levin). + + * libtiff/{tif_strip.c, tif_tile.c}: Zero division problem fixed + (Vladimir Nadvornik, Dmitry V. Levin). + +2004-10-16 Andrey Kiselev + + * libtiff 3.7.0 released. + +2004-10-15 Bob Friesenhahn + + * libtiff/tif_jpeg.c: There seems to be no need to include stdio.h + in this file so its inclusion is removed. Including stdio.h + sometimes incurs an INT32 typedef conflict between MinGW's + basetsd.h and libjpeg's jmorecfg.h. + +2004-10-15 Andrey Kiselev + + * man/bmp2tiff.1: Added manual page for bmp2tiff utility. + +2004-10-13 Bob Friesenhahn + + * tools/tiffcmp.c (leof): Renamed from 'eof' in order to avoid + conflict noticed under MinGW. + * ltmain.sh: Fix for MinGW compilation. + +2004-10-13 Frank Warmerdam + + * man/tiffsplit.1: Fixed to indicate using aaa-zzz, not aa-zz. + http://bugzilla.remotesensing.org/show_bug.cgi?id=635 + +2004-10-12 Andrey Kiselev + + * libtiff/{tif_dirread.c, tif_jpeg.c, tif_luv.c, tif_ojpeg.c, + tif_pixarlog.c, tif_write.c}: Handle the zero strip/tile sizes + properly (Dmitry V. Levin, Marcus Meissner). + +2004-10-11 Andrey Kiselev + + * libtiff/tif_dirinfo.c: Type of the TIFFTAG_SUBIFD field changed + to TIFF_IFD. + +2004-10-10 Andrey Kiselev + + * tools/bmp2tif.c: Check the space allocation results. + +2004-10-09 Andrey Kiselev + + * libtiff/tif_dir.c: Initialize td_tilewidth and td_tilelength fields + of the TIFFDirectory structure with the 0 instead of -1 to avoid + confusing integer overflows in TIFFTileRowSize() for striped images. + + * tools/tiff2pdf.c: Fixed TransferFunction tag handling reported + by Ross A. Finlayson. + + * libtiff/tif_dir.c: Fixed custom tags handling as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=629 + +2004-10-08 Frank Warmerdam + + * libtiff/tif_dirinfo.c: Fix bug with tif_foundfield and reallocation + of tif_fieldinfo. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=630 + +2004-10-04 Bob Friesenhahn + + * contrib/iptcutil/README: Added the missing README which goes + along with iptcutil. + +2004-10-03 Andrey Kiselev + + * libtiff/tif_compress.c: Improved error reporting in + TIFFGetConfiguredCODECs() (Dmitry V. Levin). + +2004-10-02 Andrey Kiselev + + * libtiff 3.7.0beta2 released. + + * libtiff/{tif_aux.c, tif_compress.c, tif_dirinfo.c, tif_dirwrite.c, + tif_extension.c, tif_fax3.c, tif_luv.c, tif_packbits.c, + tif_pixarlog.c, tif_write.c}: Added checks for failed memory + allocations and integer overflows (Dmitry V. Levin). + + * libtiff/tiff.h: Missed TIFF_BIGTIFF_VERSION constant added. + +2004-10-01 Frank Warmerdam + + * libtiff/tif_open.c: added a more informative message if a BigTIFF + file is opened. + +2004-09-30 Frank Warmerdam + + * libtiff/tif_dirinfo.c: changed type of XMLPacket (tag 700) to + TIFFTAG_BYTE instead of TIFFTAG_UNDEFINED to comply with the info + in the Adobe XMP Specification. + +2004-09-29 Andrey Kiselev + + * libtiff/{tif_jpeg.c, tif_pixarlog.c}: Use _TIFFmemset() instead of + memset(). + + * libtiff/{tif_dirread.c, tif_strip.c, tif_tile.c}: Applied patches + from Dmitry V. Levin to fix possible integer overflow problems. + +2004-09-28 Andrey Kiselev + + * libtiff/tif_getimage.c: Check for allocated buffers before clearing + (Dmitry V. Levin). + +2004-09-26 Andrey Kiselev + + * libtiff/{tif_dir.h, tif_dir.c, tif_dirread.c, tif_write.c}: + Optimize checking for the strip bounds. + + * libtiff/{tif_dirread.c, tif_strip.c}: TIFFScanlineSize() and + TIFFRasterScanlineSize() functions report zero in the case of integer + overflow now. Properly handle this case in TIFFReadDirectory() + (patches from Dmitry V. Levin). + +2004-09-25 Andrey Kiselev + + * libtiff/{tif_dirinfo.c, tif_strip.c, tif_tile.c}: Use TIFFhowmany8() + macro where appropriate. + + * tools/tiff2bw.c: Write ImageWidth/Height tags to output file, as + noted by Gennady Khokhorin. + + * libtiff/tif_dirread.c: Always check the return values, returned + by the _TIFFmalloc() (Dmitry V. Levin). + + * libtiff/tif_dir.c: Fixed possible integer overflow _TIFFset*Array() + functions (Dmitry V. Levin). + + * libtiff/{tif_dirread.c, tif_dir.c, tif_write.c}: + Potential memory leak fixed in TIFFReadDirectory(), _TIFFVSetField(), + TIFFGrowStrips() (found by Dmitry V. Levin). + +2004-09-24 Andrey Kiselev + + * libtiff/{tiffio.h, tif_compress.c}: Added TIFFGetConfiguredCODECs() + to get the list of configured codecs. + + * libtiff/{tiffiop.h, tif_dirread.c}: More overflow fixes from + Dmitry V. Levin. + +2004-09-23 Andrey Kiselev + + * libtiff/tif_dirread.c: Applied patch from Dmitry V. Levin to fix + possible integer overflow in CheckMalloc() function. + +2004-09-22 Andrey Kiselev + + * libtiff/{tiffiop.h, tif_strip.c}: Use TIFFhowmany8() macro instead + of plain TIFFhowmany() where appropriate. + +2004-09-21 Andrey Kiselev + + * libtiff/tif_getimage.c: Initialize arrays after space allocation. + +2004-09-19 Andrey Kiselev + + * libtiff 3.7.0beta released. + + * libtiff/{tif_luv.c, tif_next.c, tif_thunder.c}: Several buffer + overruns fixed, as noted by Chris Evans. + +2004-09-14 Bob Friesenhahn + + * commit: Added a script to make it more convenient to commit + updates. The CVS commit message is extracted from this ChangeLog + file. + +2004-09-14 Andrey Kiselev + + * configure.ac, configure, aclocal.m4, libtiff/{mkspans.c, tif_fax3.c, + tif_getimage.c, tif_luv.c, tif_lzw.c, tif_ojpeg.c, tif_packbits.c, + tif_predict.c, tif_read.c, tif_swab.c, tif_thunder.c, tif_write.c, + tif_dir.c, tif_dirread.c, tif_dirwrite.c, tif_jpeg.c, tif_dirinfo.c, + tif_vms.c, tif_print.c, tif_strip.c, tif_tile.c, tif_dir.h, + tif_config.h.in, tiffiop.h}: + Get rid of BSD data types (u_char, u_short, u_int, u_long). + +2004-09-13 Bob Friesenhahn + + * libtiff/tiff.h: Fix column tagging. Reference current Adobe XMP + specification. Reference libtiff bug tracking system to submit + private tag additions. + +2004-09-12 Bob Friesenhahn + + * tools/tiffgt.c: Include "tif_config.h". + + * configure.ac: Use AM_PROG_CC_C_O since it is now needed to build + tiffgt. This results in the 'compile' script being added to the + project. + + * tools/Makefile.am (tiffgt_CFLAGS): Add extra build options + required to find OpenGL headers necessary to build tiffgt. Also + ensure that the libtiff that we built is used rather than some other + libtiff installed on the system. + +2004-09-12 Andrey Kiselev + + * configure.ac, acinclude.m4, aclocal.m4: New macros to detect GLUT + libraries. + +2004-09-11 Bob Friesenhahn + + * configure.ac: Pass library configuration defines via + tif_config.h rather than extending CPPFLAGS. Configure a + libtiff/tiffconf.h in order to satisfy application requirements + (not used by library build). Do not define _POSIX_C_SOURCE=2 since + this causes failure to build on systems which properly respect + this request. + + * libtiff/tiffconf.h.in: New file to act as the template for the + configured tiffconf.h + + * libtiff/files.lst (HDRS): Install the configured tiffconf.h. + +2004-09-10 Frank Warmerdam + + * html/internals.html: Split off a discussion of adding new tags + into addingtags.html. + +2004-09-10 Andrey Kiselev + + * test/{ascii_tag.c, long_tag.c}: Preliminary test suite added. + + * tools/tiff2pdf.c: Fixed reading TransferFunction tag as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=590 + + * libtiff/tif_print.c: Fixes in InkNames and NumberOfInks reporting. + + * libtiff/tif_dirread.c: Don't reject to read tags of the + SamplesPerPixel size when the tag count is greater than number of + samples as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=576 + + * libtiff/tiff.h: Use _TIFF_DATA_TYPEDEFS_ guardian to switch off + defining int8/uint8/... etc. types. As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=607 + +2004-09-09 Frank Warmerdam + + * tools/tiff2ps.c, tools/tiffmedian.c: fiddle with include files + to avoid compile warnings about getopt() and a few other things. + +2004-09-02 Andrey Kiselev + + * libtiff/tif_dirread.c: Use memcpy() function instead of pointer + assigning magic in TIFFFetchFloat(). + +2004-09-01 Andrey Kiselev + + * libtiff/{tiffio.h, tif_open.c}: Applied patches from Joris Van Damme + to avoid requirement for tiffiop.h inclusion in some applications. See + here + + http://www.asmail.be/msg0054799560.html + + for details. + + * tools/fax2tiff.c: Use the new functions in the code. + +2004-08-25 Andrey Kiselev + + * tools/tiff2pdf.c: Initialize arrays properly. + + * tools/tiff2ps.c: Avoid zero division in setupPageState() function; + properly initialize array in PSDataBW(). + +2004-08-24 Andrey Kiselev + + * tools/tiff2pdf.c: More fixes for bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=590 + + from Ross Finlayson. + +2004-08-23 Andrey Kiselev + + * tools/tiff2ps.c: Fixed problem with uninitialized values. + + * libtiff/tif_dir.c: Initialize tif_foundfield data member in the + TIFFDefaultDirectory() (in addition to 2004-08-19 fix). + + * tools/tiff2pdf.c: Fixed a bunch of problems as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=590 + +2004-08-20 Andrey Kiselev + + * tools/tiff2pdf.c: Applied patch from Ross Finlayson that checks + that the input file has compression, photometric interpretation, + etcetra, tags or if not than a more descriptive error is returned. + + * libtiff/tif_dirread.c: Fixed problem in TIFFReadDirectory() in the + code, responsible for tag data type checking. + +2004-08-19 Andrey Kiselev + + * libtiff/{tiffiop.h, tif_dirinfo.c}: Fixed problem with the static + variable as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=593 + +2004-08-16 Andrey Kiselev + + * tools/ras2tiff.c: Fixed issue with missed big-endian checks as per + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=586 + +2004-08-01 Andrey Kiselev + + * libtiff/{tif_config.h.in, tif_config.h.vc}: config.h.in and + config.h.vc files renamed in the tif_config.h.in and tif_config.h.vc. + +2004-07-24 Andrey Kiselev + + * libtiff/tif_lzw.c: LZW compression code is merged back from the + separate package. All libtiff tools are updated to not advertise an + abcence of LZW support. + +2004-07-12 Andrey Kiselev + + * libtiff/tiffio.h: Revert thandle_t back to void* type. + +2004-07-11 Andrey Kiselev + + * libtiff/{tif_read.c, tif_tile.c, tif_strip.c}: Fixes in error + messages, as suggested by Bernd Herd. + +2004-07-03 Andrey Kiselev + + * libtiff/tif_dir.c: Call TIFFError() instead of producing warnings + when setting custom tags by value. Reported by Eric Fieleke. + +2004-06-14 Andrey Kiselev + + * tools/bmp2tiff.c: Add missed RawsPerStrip setting. + +2004-06-08 Andrey Kiselev + + * tools/bmp2tiff.c: Added new utility to convert Windows BMP files + into TIFFs. + +2004-06-07 Andrey Kiselev + + * libtiff 3.7.0alpha released. + +2004-06-06 Andrey Kiselev + + * libtiff/{tiff.h, tif_dirwrite.c, tif_fax3.c, tif_packbits.c,}: Get rid + of ugly 64-bit hacks, replace them with the clever (autoconf based ) + ones :-). + + * libtiff/tiffio.h: Define thandle_t as int, not void* (may cause + problems in 64-bit environment). + +2004-06-05 Andrey Kiselev + + * tools/tiffset.c: tiffset now can set any libtiff supported tags. + Tags can be supplied by the mnemonic name or number. + + * libtiff/{tiffio.h, tif_dir.h, tif_dirinfo.c,}: Added two new + functions TIFFFindFieldInfoByName() and TIFFFieldWithName(). + +2004-05-27 Andrey Kiselev + + * libtiff/tif_ojpeg.c: Fixed problem with duplicated SOI and SOF + markers as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=581 + +2004-05-24 Andrey Kiselev + + * tools/tiffsplit.c: Don't forget to copy Photometric + Interpretation tag. + +2004-05-20 Andrey Kiselev + + * libtiff/{tif_open.c, tiffio.h}: New function added: + TIFFIsBigEndian(). Function returns nonzero if given was file written + in big-endian order. + + * tools/tiffsplit.c: Fixed problem with unproperly written multibyte + files. Now output files will be written using the same byte order + flag as in the input image. See + + http://bugzilla.remotesensing.org/show_bug.cgi?id=574 + + for details. + +2004-05-19 Frank Warmerdam + + * libtiff/tif_print.c: added (untested) support for printing + SSHORT, SLONG and SRATIONAL fields. + + * tools/tiffcp.c: close output file on normal exit. + +2004-05-17 Andrey Kiselev + + * libtiff/tif_fax3.c: Avoid reading CCITT compression options + if compression type mismatches. See + + http://bugzilla.remotesensing.org/show_bug.cgi?id=565 + +2004-04-30 Andrey Kiselev + + * libtiff/tif_strip.c: Never return 0 from the + TIFFNumberOfStrips(). + +2004-04-29 Andrey Kiselev + + * libtiff/tif_dirread.c: Workaround for broken TIFF writers which + store single SampleFormat value for multisampled images. See + + http://bugzilla.remotesensing.org/show_bug.cgi?id=562 + +2004-04-25 Andrey Kiselev + + * configure.ac, libtiff/{tiff.h, config.h.in}: Added tests for int8, + int16 and int32 types to avoid complains on some compilers. Details at + + http://bugzilla.remotesensing.org/show_bug.cgi?id=39 + +2004-04-20 Andrey Kiselev + + * tools/tiff2pdf.c: Fixed problem with unaligned access as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=555 + +2004-04-14 Andrey Kiselev + + * libtiff/tif_write.c: Allow in-place updating of the compressed + images (don't work properly with all codecs). For details see GDAL bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=534 + +2004-04-06 Andrey Kiselev + + * libtiff/tif_jpeg.c: Workaround for wrong sampling factors used + in the Intergarph JPEG compressed TIFF images as per bug: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=532 + +2004-04-04 Frank Warmerdam + + * libtiff/tif_open.c: close clientdata if TIFFClientOpen() fails + via bad2. + +2004-03-26 Andrey Kiselev + + * tools/tiffcp.c: Properly set Photometric Interpretation in case of + JPEG compression of grayscale images. + + * tools/tiffcp.c: Don't emit warnings when Orientation tag does not + present in the input image. + +2004-03-19 Andrey Kiselev + + * {many}: The first attempt to switch to autotools. + +2004-03-03 Andrey Kiselev + + * libtiff/tif_open.c: Use dummy mmap/munmap functions in + TIFFClientOpen() when the appropriate client functions was not + supplied by user. + +2004-03-02 Frank Warmerdam + + * tools/ycbcr.c: fixed main() declaration as per: + http://bugzilla.remotesensing.org/show_bug.cgi?id=513 + +2004-02-26 Andrey Kiselev + + * tools/tiffsplit.c: Copy JPEGTables tag contents for JPEG compressed + images. Reported by Artem Mirolubov. + + * libtiff/tif_dirread.c: Fixed problem with handling TIFF_UNDEFINED + tag type in TIFFFetchNormalTag() as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=508 + +2004-02-17 Frank Warmerdam + + * libtiff/tif_codec.c: Fixed typo in TIFFInitPackBits name as per: + http://bugzilla.remotesensing.org/show_bug.cgi?id=494 + +2004-02-05 Andrey Kiselev + + * libtiff/tif_fax3.c: Fixed problem with CCITT encoding modes as per + bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=483 + + But we need more work on fax codec to support update mode. + +2004-01-30 Frank Warmerdam + + * libtiff/libtiff.def: Added TIFFCurrentDirOffset, TIFFWriteCheck, + TIFFRGBAImageOK, and TIFFNumberOfDirectories as suggested by + Scott Reynolds. + +2004-01-29 Andrey Kiselev + + * libtiff/tiff.h: Fixed tag definitions for TIFFTAG_YCLIPPATHUNITS + and TIFFTAG_INDEXED as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=475 + + * libtiff/{tif_win32.c, tif_unix.c}: Check whether the pointer is + NULL before proceeding further as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=474 + + Check results, returned by the TIFFFdOpen() before returning and close + file if TIFFFdOpen() failed as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=468 + + * libtiff/tif_open.c: More fixes for + + http://bugzilla.remotesensing.org/show_bug.cgi?id=468 + +2004-01-28 Andrey Kiselev + + * libtiff/{libtiff.def, tif_close.c, tiffio.h, tif_open.c}: Separate + TIFFCleanup() from the TIFFClose() in order to fix the bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=468 + + * tools/tiffcp.c: Fixed problem with wrong interpretation of the + InkNames tag as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=466 + + Memory leak fixed. + +2004-01-21 Frank Warmerdam + + * libtiff/tif_dirwrite.c: Fixed handling of writable ASCII tags that + are field_passcount=TRUE properly. Arguably anonymous custom tags + should be declared as passcount=FALSE, but I don't want to change + that without a careful review. + +2004-01-20 Andrey Kiselev + + * libtiff/tif_write.c: Fixed reporting size of the buffer in case of + stripped image in TIFFWriteBufferSetup(). As per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=460 + +2004-01-11 Andrey Kiselev + + * libtiff/tif_dir.c: Incomplete cleanup in TIFFFreeDirectory(), + patch from Gerben Koopmans. + + * libtiff/tif_dirread.c: Check field_passcount value before setting + the value of undefined type, patch from Gerben Koopmans. + +2004-01-02 Andrey Kiselev + + * tools/tiffcp.c: Fixed problem with wrong Photometric setting for + non-RGB images. + +2003-12-31 Andrey Kiselev + + * libtiff/tif_win32.c: Fixed problem with _TIFFrealloc() when the NULL + pointer passed. Patch supplied by Larry Grill. + + * libtiff/{tiff.h, tif_fax3.c}:Fixes for AMD 64 platform as + suggested by Jeremy C. Reed. + +2003-12-26 Andrey Kiselev + + * libtiff 3.6.1 released. + +2003-12-24 Andrey Kiselev + + * config.guess, config.sub: Updated from the recent upstream. + +2003-12-22 Andrey Kiselev + + * libtiff/{tif_color, tif_getimage.c, tiffio.h}, man/TIFFcolor.3t: + More cleanups in color conversion interface, added appropriate manual + page. + +2003-12-19 Andrey Kiselev + + * libtiff/{tif_extension.c, tif_dirinfo.c, tiff.h}: Warnings fixed as + per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=357 + + * tools/tiff2ps.c: Added support for alpha channel. Fixes + + http://bugzilla.remotesensing.org/show_bug.cgi?id=428 + + * libtiff/{libtiff.def, tif_color.c, tif_getimage.c, tiffio.h}: + Interface for Lab->RGB color conversion is finally cleaned up. + Added support for ReferenceBlackWhite tag handling when converted from + YCbCr color space. The latter closes + + http://bugzilla.remotesensing.org/show_bug.cgi?id=120 + +2003-12-07 Andrey Kiselev + + * libtiff/{tif_getimage.c, tiffio.h}: Avoid warnings. + + * libtiff/makefile.vc, tools/makefile.vc: Support for IJG JPEG + library. + +2003-12-06 Andrey Kiselev + + * libtiff/{tif_getimage.c, tif_aux.c}: Read WhitePoint tag from the + file and properly use it for CIE Lab->RGB transform. + +2003-12-04 Andrey Kiselev + + * libtiff/{tif_getimage.c, tif_color.c, tiffio.h}: YCbCr->RGB + conversion routines now in the tif_color.c module. New function + TIFFYCbCrtoRGB() available in TIFF API. + + * libtiff/tif_dirwrite.c: Handle TIFF_IFD tag type correctly. + +2003-12-03 Andrey Kiselev + + * libtiff/{tif_getimage.c, tif_color.c, tiffio.h}: Improvements in + CIE Lab conversion code. Start moving YCbCr stuff to the tif_color.c + module. + + * libtiff/{tif_getimage.c, tiffio.h}, man{TIFFReadRGBAImage.3t, + TIFFReadRGBAStrip.3t, TIFFReadRGBATile.3t, TIFFRGBAImage.3t}: + Finally resolved problems with orientation handling. TIFFRGBAImage + interface now properly supports all possible orientations, i.e. images + will be flipped both in horizontal and vertical directions if + required. 'Known bugs' section now removed from the appropriate manual + pages. Closed bug entry: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=322 + +2003-12-02 Andrey Kiselev + + * libtiff/tif_dir.c: Fixed order of the parameters in TIFFError() + function calls as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=440 + +2003-11-28 Ross Finlayson + + * tools/tiff2pdf.c: Some bugs fixed. + +2003-11-27 Andrey Kiselev + + * libtiff/tif_luv.c: Fixed bug in 48-bit to 24-bit conversion routine, + reported by Antonio Scuri. + + * man/tiff2pdf.1: Few improvements in page layout. + + * Makefile.in, /man/Makefile.in, /html/man/tiff2pdf.1.html: + Added support fpr tiff2pdf manual page. + +2003-11-26 Ross Finlayson + + * /man/tiff2pdf.1: File added to repository. + +2003-11-26 Andrey Kiselev + + * Makefile.in, /tools/{Makefile.in, makefile.vc}: + Added support fpr tiff2pdf utility. + +2003-11-25 Ross Finlayson + + * /tools/tiff2pdf.c: File added to repository. + +2003-11-22 Andrey Kiselev + + * /tools/raw2tiff.c: sqrtf() replaced with sqrt(). + +2003-11-21 Andrey Kiselev + + * /tools/raw2tiff.c: #include removed. + + * tools/{Makefile.in, tiffgt.c}: Unmaintained and platform dependent + sgigt utility removed and replaced with the completely rewritten + portable tiffgt tool (depend on OpenGL and GLUT). Initial revision, + there is a lot of things to improve. + + * libtiff/tif_ojpeg.c: TIFFVGetField() function now can properly + extract the fields from the OJPEG files. Patch supplied by Ross + Finlayson. + + * libtiff/{tiffio.h, tif_codec.c}, man/{libtiff.3t, TIFFcodec.3t}: + Added new function TIFFIsCODECConfigured(), suggested by Ross + Finlayson. + +2003-11-18 Andrey Kiselev + + * libtiff/tif_dirinfo.c: Implemented binary search in + _TIFFMergeFieldInfo(). Patch supplied by Ross Finlayson. + + * libtiff/tif_dir.h: _TIFFFindOrRegisterdInfo declaration replaced + with _TIFFFindOrRegisterFieldInfo as reported by Ross Finlayson. + +2003-11-17 Frank Warmerdam + + * tif_dirread.c: do not mark all anonymously defined tags to be + IGNOREd. + +2003-11-17 Andrey Kiselev + + * contrib/pds/{tif_pdsdirread.c, tif_pdsdirwrite.c}: Use + TIFFDataWidth() function insted of tiffDataWidth array. + +2003-11-16 Andrey Kiselev + + * libtiff/{tiff.h, tif_dirinfo.c}: Added support for IFD (13) + datatype, intruduced in "Adobe PageMaker TIFF Tech. Notes". + +2003-11-15 Frank Warmerdam + + * Makefile.in: fixed missing backslash for tif_color.c in list. + +2003-11-13 Andrey Kiselev + + * libtiff/{tif_color.c, tif_getimage.c, tiffio.h, Makefile.in}: + New color space conversion code: CIE L*a*b* 1976 images now supported + by the TIFFRGBAImage interface. All introduced routines go to new + module tif_color.c. Eventually all color conversion functions should + be moved there. + +2003-11-12 Andrey Kiselev + + * tools/{ras2tiff.c, rasterfile.h}: Properly determine SUN Rasterfiles + with the reverse byte order (it is reported by the magic header + field). Problem reported by Andreas Wiesmann. + + * tools/raw2tiff.c, man/raw2tiff.1: Few improvements in correlation + calculation function. Guessing mechanics now documented in manual page. + +2003-11-11 Andrey Kiselev + + * tools/raw2tiff.c: Implemented image size guessing using + correlation coefficient calculation between two neighbour lines. + +2003-11-09 Frank Warmerdam + + * libtiff/tif_tile.c: remove spurious use of "s" (sample) in the + planarconfig_contig case in TIFFComputeTile(). + + http://bugzilla.remotesensing.org/show_bug.cgi?id=387 + +2003-11-09 Andrey Kiselev + + * libtiff/tiffiop.h: New macros: TIFFmax, TIFFmin and TIFFrint. + +2003-11-07 Andrey Kiselev + + * libtiff/{tiffio.h, tif_strip.c}, man/{TIFFstrip.3t, libtiff.3t}: + Added TIFFRawStripSize() function as suggested by Chris Hanson. + +2003-11-03 Andrey Kiselev + + * libtiff/{tif_lzw.c, tif_fax3.c}: Proper support for update mode as + per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=424 + +2003-10-29 Andrey Kiselev + + * libtiff/libtiff.def: Added TIFFReadRGBAImageOriented. + + * html/build.html: Added note about GNU make requirement. + +2003-10-25 Andrey Kiselev + + * Makefile.in: Fixes in using MAKEFLAGS as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=418 + + * port/install.sh.in: Option -p added to the mkdir command to create + all directory tree structure before installing. + +2003-10-18 Andrey Kiselev + + * /tools/tiff2ps.c: #include replaced with the + #include . + +2003-10-16 Andrey Kiselev + + * Makefile.in: Add an absolute path to the test_pics.sh call. + +2003-10-12 Andrey Kiselev + + * libtiff/tiffcomp.h: #define _BSDTYPES_DEFINED when defining BSD + typedefs. + +2003-10-09 Andrey Kiselev + + * configure, libtiff/{Makefile.in, mkversion.c}: + Relative buildings fixed. + + * tools/Makefile.in: Added "-I../libtiff" to the tiffset building + rule. + +2003-10-07 Andrey Kiselev + + * Makefile.in: Added missed v3.6.0.html. + + * libtiff/tiffio.h: Typo fixed: ORIENTATION_BOTTOMLEFT replaced with + ORIENTATION_BOTLEFT. + +2003-10-04 Andrey Kiselev + + * 3.6.0 final release. + +2003-10-03 Andrey Kiselev + + * libtiff/{tif_getimage.c, tiffio.h}, man/TIFFReadRGBAImage.3t: New + function TIFFReadRGBAImageOriented() implemented to retrieve raster + array with user-specified origin position as suggested by Jason Frank. + See + + http://bugzilla.remotesensing.org/show_bug.cgi?id=322 + + for details. + + * tools/tiff2rgba.c: Switched to use TIFFReadRGBAImageOriented() + instead of TIFFReadRGBAImage(). + + * tools/tiff2ps.c: Fixed possible endless loop as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=404 + +2003-09-30 Andrey Kiselev + + * libtiff/tif_dirread.c: Check field counter against number of fields + in order to fix + + http://bugzilla.remotesensing.org/show_bug.cgi?id=366 + + * libtiff/tif_fax3.c: Fix wrong line numbering as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=342 + +2003-09-25 Andrey Kiselev + + * libtiff/{tiffiop.h, tif_dirread.c, tif_dir.c, tif_open.c, + tif_close.c}: Store a list of opened IFD to prevent looping as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=383 + +2003-09-23 Andrey Kiselev + + * libtiff/tif_dirread.c: More fixes for EstimateStripByteCounts(). See + + http://bugzilla.remotesensing.org/show_bug.cgi?id=358 + +2003-08-21 Andrey Kiselev + + * tools/tiffmedian.c: int declaration replaced with the uint32 to + support large images as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=382 + +2003-08-12 Andrey Kiselev + + * libtiff/Makefile.in: Fixed problem with building in different + directory. + + * tools/tiff2ps.c: Added missing #include . + + * libtiff/tif_dirwrite.c: More fixes for custom tags code + from Ashley Dreier. + +2003-08-07 Andrey Kiselev + + * tools/tiff2ps.c: Added page size setting when creating PS Level 2. + Patch submitted by Balatoni Denes (with corrections from Tom + Kacvinsky). + + * tools/tiff2ps.c: Fixed PS comment emitted when FlateDecode is + being used. Reported by Tom Kacvinsky. + + * libtiff/tif_dirwrite.c: Fixed problem with custom tags writing, + reported by Ashley Dreier. + + * libtiff/tif_print.c: Fixed problem with float tags reading, support + for printing RATIONAL and BYTE tags added. + +2003-08-05 Andrey Kiselev + + * libtiff/tif_lzw.c: Move LZW codec state block allocation back to + TIFFInitLZW(), because its initialization in LZWSetupDecode() cause + problems with predictor initialization. Remove O_RDONLY check during + state block allocation to be able open LZW compressed files in update + mode. + + Problem exist for libtiff version of the tif_lzw.c module. One from + lzw-compression-kit hasn't such troubles. + +2003-08-04 Frank Warmerdam + + * libtiff/tif_write.c: modified tif_write.c so that the various + encoded write functions use tif_postdecode() to apply byte order + swapping (swab) to the application passed data buffer if the same + would be done when reading. This allows us to write pixel data with + more than 8 bits per sample to existing files of a non-native byte + order. One side effect of this change is the applications buffer + itself is altered in this case by the act of writing. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=171 + +2003-07-25 Frank Warmerdam + + * libtiff/tif_open.c: avoid signed/unsigned casting warning + initializing typemask as per patch from J.A. Strother. + + * tools/tiffcp.c: fixed signed/unsigned casting warning. + + * libtiff/tif_print.c: dos2unix conversion. + + * tools/tiffsplit.c: increased the maximum number of pages that + can be split. Patch provided by Andrew J. Montalenti. + +2003-07-11 Andrey Kiselev + + * tools/raw2tiff.c: Added option `-p' to explicitly select color + space of input image data. Closes + + http://bugzilla.remotesensing.org/show_bug.cgi?id=364 + +2003-07-08 Frank Warmerdam + + * tif_aux.c, tif_codec.c, tif_dir.c, tif_dirread.c, tif_extension.c, + tif_fax3.c, tif_getimage.c, tif_luv.c, tif_lzw.c, tif_next.c, + tif_packbits.c, tif_predict.c, tif_print.c, tif_swab.c, tif_thunder.c: + avoid casting warning at /W4. + +2003-07-03 Andrey Kiselev + + * tools/thumbnail.c: Memory leak fixed as reported by Robert S. Kissel. + +2003-06-30 Andrey Kiselev + + * libtiff/tif_pixarlog.c: Unused variables removed. + + * libtiff/{tif_dirread.c, tif_dir.c}: Fixed problem with + EstimateStripByteCounts() as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=358 + + * libtiff/{tif_dirwrite.c, tif_packbits.c}: Fixed compilation on + 64-bit architectures as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=357 + + * libtiff/tif_dirinfo.c: TIFFDataWidth() returns 0 in case of + unknown data type. + +2003-06-19 Frank Warmerdam + + * libtiff/tif_print.c: fixed some serious bugs when printing + custom tags ... almost certain to crash. + + * libtiff/tif_dirread.c: Don't ignore custom fields that are + autodefined. Not sure how this got to be like this. + +2003-06-18 Andrey Kiselev + + * 3.6.0 Beta2 released. + + * tools/tiffcmp.c, man/tiffcmp.1: Fixed problem with unused data + comparing as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=349 + + `-z' option now can be used to set the number of reported different + bytes. + +2003-06-09 Andrey Kiselev + + * tools/tiffcp.c, man/tiffcp.1: Added possibility to specify value -1 + to -r option to get the entire image as one strip. See + + http://bugzilla.remotesensing.org/show_bug.cgi?id=343 + + for details. + +2003-06-04 Andrey Kiselev + + * tools/tiffcp.c: Set the correct RowsPerStrip and PageNumber + values as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=343 + +2003-05-27 Frank Warmerdam + + * libtiff/tif_jpeg.c: modified segment_height calculation to always + be a full height tile for tiled images. Also changed error to just + be a warning. + +2003-05-25 Andrey Kiselev + + * tools/fax2tiff.c: Page numbering fixed, as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=341 + +2003-05-20 Andrey Kiselev + + * contrib/ojpeg/{Makefile.in, jdhuff.h, jinclude.h, ojpeg.c, README}, + configure, Makefile.in: Switched back to the old behaviour. Likely + better solution should be found for OJPEG support. + +2003-05-11 Andrey Kiselev + + * libtiff/mkversion.c: Fixed problem with wrong string size when + reading RELEASE-DATE file. + +2003-05-07 Andrey Kiselev + + * tools/tiff2ps.c: Fixed bug in Ascii85EncodeBlock() function: array + index was out of range. + +2003-05-06 Andrey Kiselev + + * contrib/ojpeg/{Makefile.in, jdhuff.h, jinclude.h, ojpeg.c, README}, + configure, Makefile.in: Improved libtiff compilation with OJPEG + support. Now no need for patching IJG JPEG library, hack requred by + libtiff will be compiled and used in-place. Implemented with + suggestion and help from Bill Allombert, Debian's libjpeg maintainer. + + * libtiff/tif_aux.c: Properly handle TIFFTAG_PREDICTOR in + TIFFVGetFieldDefaulted() function. + +2003-05-05 Andrey Kiselev + + * tools/ppm2tiff.c: PPM header parser improved: now able to skip + comments. + + * tools/tiffdither.c: Fixed problem with bit fill order tag setting: + was not copied from source image. + + * libtiff/getimage.c: Workaround for some images without correct + info about alpha channel as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=331 + +2003-04-29 Andrey Kiselev + + * tools/tiff2ps.c, man/tiff2ps.1: Add ability to generate PS Level 3. + It basically allows one to use the /flateDecode filter for ZIP + compressed TIFF images. Patch supplied by Tom Kacvinsky. Fixes + + http://bugzilla.remotesensing.org/show_bug.cgi?id=328 + + * tools/tiff2ps.c: Force deadzone printing when EPS output specified + as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=325 + +2003-04-17 Andrey Kiselev + + * libtiff/tif_dirread.c: Removed additional check for StripByteCounts + due to problems with multidirectory images. Quality of error messages + improved. + +2003-04-16 Andrey Kiselev + + * tools/tiffcp.c: Fixed problem with colorspace conversion for JPEG + encoded images. See bug entries + + http://bugzilla.remotesensing.org/show_bug.cgi?id=275 + + and + + http://bugzilla.remotesensing.org/show_bug.cgi?id=23 + + * libtiff/tif_dirread.c: Additional check for StripByteCounts + correctness. Fixes + + http://bugzilla.remotesensing.org/show_bug.cgi?id=320 + +2003-03-12 Andrey Kiselev + + * tools/{fax2ps.c, fax2tiff.c, gif2tiff.c, pal2rgb.c, ppm2tiff.c, + ras2tiff.c, raw2tiff.c, rgb2ycbcr.c, thumbnail.c, tiff2bw.c, + tiff2ps.c, tiff2rgba.c, tiffcp.c, tiffdither.c, tiffinfo.c, + tiffmedian.c}: Added library version reporting facility to all tools. + +2003-03-06 Frank Warmerdam + + * port/install.sh.in: Fixed problems with install producing paths + like ///usr/local/lib on cygwin. + +2003-02-27 Andrey Kiselev + + * tools/fax2tiff.c, man/fax2tiff.1: New switch (-X) to set width of + raw input page. Patch supplied by Julien Gaulmin. See + + http://bugzilla.remotesensing.org/show_bug.cgi?id=293 + + for details. + +2003-02-26 Frank Warmerdam + + * libtiff/tif_dir.c: fixed up the tif_postdecode settings + responsible for byte swapping complex image data. + + * libtiff/tif_lzw.c: fixed so that decoder state isn't allocated till + LZWSetupDecode(). Needed to read LZW files in "r+" mode. + +2003-02-07 Andrey Kiselev + + * tools/ppm2tiff.c: Fixed problem with too many arguments. + +2003-02-04 Andrey Kiselev + + * tools/raw2tiff.c: Memory leak fixed. + +2003-02-03 Andrey Kiselev + + * tools/fax2tiff.c, man/fax2tiff.1: Applied patch from Julien Gaulmin + (thanks, Julien!). More switches for fax2tiff tool for better control + of input and output. Details at + + http://bugzilla.remotesensing.org/show_bug.cgi?id=272 + +2003-02-03 Frank Warmerdam + + * libtiff/tif_jpeg.c: Modified to defer initialization of jpeg + library so that we can check if there is already any tile/strip data + before deciding between creating a compressor or a decompressor. + +2003-01-31 Frank Warmerdam + + * libtiff/tif_write.c: TIFFWriteCheck() now fails if the image is + a pre-existing compressed image. That is, image writing to + pre-existing compressed images is not allowed. + + * libtiff/tif_open.c: Removed error if opening a compressed file + in update mode. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=198 + +2003-01-31 Andrey Kiselev + + * config.guess, config.sub: Updated to recent upstream versions. + +2003-01-15 Frank Warmerdam + + * cut 3.6.0 Beta release. + +2002-12-20 Andrey Kiselev + + * tools/fax2ps.c, man/fax2ps.1: Page size was determined + in wrong way as per bug + + http://bugzilla.remotesensing.org/show_bug.cgi?id=239 + +2002-12-17 Frank Warmerdam + + * libtiff/tif_dirread.c: Allow wrong sized arrays in + TIFFFetchStripThing(). + + http://bugzilla.remotesensing.org/show_bug.cgi?id=49 + +2002-12-02 Frank Warmerdam + + * libtiff/tif_dir.c: fix problem with test on td_customValueCount. + Was using realloc even first time. Fix by Igor Venevtsev. + +2002-11-30 Frank Warmerdam + + * libtiff/tif_dir.c: fixed bug with resetting an existing custom + field value. + + * libtiff/tif_dir.c: Fixed potential problem with ascii "custom" + tags in TIFFVGetField() ... added missing break. + +2002-10-14 Frank Warmerdam + + * tools/tiff2ps.c: fixes a problem where "tiff2ps -1e" did not make + the scanline buffer long enough when writing rgb triplets. + The scanline needs to be 3 X the number of dots or else it will + contain an incomplete triplet and programs that try to separate + the eps by redefining the colorimage operator will get messed up. + Patch supplied by William Bader. + + * Makefile.in: added tif_extension.c to file list as per + http://bugzilla.remotesensing.org/show_bug.cgi?id=218. + +2002-10-11 Andrey Kiselev + + * configure, config.site, libtiff/{tif_unix.c, Makefile.in}: Fix for + large files (>2GiB) supporting. New option in the config.site: + LARGEFILE="yes". Should be enough for I/O of the large files. + +2002-10-10 Frank Warmerdam + + * libtiff/html/v3.6.0.html: new release notes. + + * libtiff/index.html: removed faq, cvs snapshot cruft. Added email + link for Andrey. Pointer to v3.6.0.html. + + * libtiff/Makefile.in: added direct rule for tiffvers.h for release. + +2002-10-07 Andrey Kiselev + * tools/tiff2ps.c, man/tiff2ps.1: Applied patch form Sebastian Eken + (thanks, Sebastian!). New switches: + -b # for a bottom margin of # inches + -c center image + -l # for a left margin of # inches + -r rotate the image by 180 degrees + New features merged with code for shrinking/overlapping. + Previously added -c and -n switches (for overriding PS units) renamed + in -x and -y respectively. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=200 + + * html/man/*.html: Updated from actual manual pages. + +2002-10-06 Frank Warmerdam + + * libtiff/tif_jpeg.c: fixed problem with boolean defined with wrong + size on windows. Use #define boolean hack. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=188 + + * libtiff/tiff.h: Don't do special type handling in tiff.h unless + USING_VISUALAGE is defined. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=39 + +2002-10-03 Frank Warmerdam + + * libtiff/tiff.h: added COMPRESSION_JP2000. + +2002-10-02 Andrey Kiselev + + * libtiff/tif_dirread.c: Another fix for the fetching SBYTE arrays + by the TIFFFetchByteArray() function. Should finally resolve + + http://bugzilla.remotesensing.org/show_bug.cgi?id=52 + + * configure: Set -DPIXARLOG_SUPPORT option along with -DZIP_SUPPORT + + * html/Makefile.in: New targets added: html and groffhtml for + producing HTML representations of the manual pages automatically. + html target uses man2html tool, groffhtml uses groff tool. + +2002-09-29 Frank Warmerdam + + * configure, libtiff/Makefile.in: Added SCO OpenServer 5.0.6 support + from John H. DuBois III. + +2002-09-15 Andrey Kiselev + + * Makefile.in, /man/{raw2tiff.1, Makefile.in, libtiff.3}: Added + manual page for raw2tiff(1) tool. + +2002-09-12 Andrey Kiselev + + * /libtiff/{tiffio.h, tif_dir.h}: TIFFDataWidth() declaration moved to + the tiffio.h header file. + + * Makefile.in, /man/{TIFFDataWidth.3t, Makefile.in, libtiff.3}: Added + manual page for TIFFDataWidth() function + +2002-09-08 Frank Warmerdam + + * libtiff/tif_dirread.c: Expand v[2] to v[4] in TIFFFetchShortPair() + as per http://bugzilla.remotesensing.org/show_bug.cgi?id=196. + + * tools/tiff2ps.c: Don't emit BeginData/EndData DSC comments + since we are unable to properly include the amount to skip. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=80 + +2002-09-02 Andrey Kiselev + + * /libtiff/tif_dirread.c: Fixed problem with SBYTE type data fetching + in TIFFFetchByteArray(). Problem described at + http://bugzilla.remotesensing.org/show_bug.cgi?id=52 + +2002-08-22 Andrey Kiselev + + * /libtiff/tif_dirinfo.c: Further additions to free custom fields + in _TIFFSetupFieldInfo() function. + See http://bugzilla.remotesensing.org/show_bug.cgi?id=169 for details. + + * /libtiff/tif_lzw.c: Additional consistency checking added in + LZWDecode() and LZWDecodeCompat(). + Fixes http://bugzilla.remotesensing.org/show_bug.cgi?id=190 + and http://bugzilla.remotesensing.org/show_bug.cgi?id=100 + + * /libtiff/tif_lzw.c: + Added check for valid code lengths in LZWDecode() and + LZWDecodeCompat(). Fixes + http://bugzilla.remotesensing.org/show_bug.cgi?id=115 + +2002-08-16 Andrey Kiselev + + * /libtiff/{Makefile.vc, libtiff.def}: + Missed declarations added. + +2002-08-15 Frank Warmerdam + + * tif_getimage.c: Ensure that TIFFRGBAImageBegin() returns the + return code from the underlying pick function. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=177 + + * tif_dir.h: changed FIELD_CODEC to 66 from 64 to avoid overlap + with FIELD_CUSTOM as mentioned in bug 169. + + * tif_close.c: added logic to free dynamically created anonymous + field definitions to correct a small memory leak. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=169 + +2002-08-10 Andrey Kiselev + + * /tools/{raw2tiff.c, Makefile.in, Makefile.lcc, Makefile.vc}: + New tool: raw2tiff --- raw images to TIFF converter. No manual page yet. + +2002-07-31 Frank Warmerdam + + * libtiff/tif_jpeg.c: Fixed problem with setting of nrows in + JPEGDecode() as per bugzilla bug (issue 1): + + http://bugzilla.remotesensing.org/show_bug.cgi?id=129 + + * libtiff/{tif_jpeg.c,tif_strip.c,tif_print.c}: Hacked tif_jpeg.c to + fetch TIFFTAG_YCBCRSUBSAMPLING from the jpeg data stream if it isn't + present in the tiff tags. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=168 + + * libtiff/tif_read.c, libtiff/tif_write.c: TIFFReadScanline() and + TIFFWriteScanline() now set tif_row explicitly in case the codec has + fooled with the value. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=129 + +2002-06-22 Andrey Kiselev + + * /tools/tiff2ps.c: Added workaround for some software that may crash + when last strip of image contains fewer number of scanlines than + specified by the `/Height' variable. See + http://bugzilla.remotesensing.org/show_bug.cgi?id=164 + for explanation. + +2002-06-21 Andrey Kiselev + + * tools/tiff2ps, man/tiff2ps.1: New functionality for tiff2ps utility: + splitting long images in several pages. See + http://bugzilla.remotesensing.org/show_bug.cgi?id=142 for explanation. + Patch granted by John Williams . + +2002-06-11 Frank Warmerdam + + * libtiff/contrib/win95: renamed to contrib/win_dib. Added new + Tiffile.cpp example of converting TIFF files into a DIB on Win32. + This one is described in: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=143 + + * libtiff/tif_ojpeg.c: Major upgrade from Scott. See details at: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=156 + +2002-05-10 Andrey Kiselev + + * tools/tiff2ps: New commandline switches to override resolution + units obtained from the input file. Closes + http://bugzilla.remotesensing.org/show_bug.cgi?id=131 + +2002-04-26 Andrey Kiselev + + * libtiff/libtiff.def: Added missed declaration. + +2002-04-22 Andrey Kiselev + + * tools/fax2tiff.c: Updated to reflect latest changes in libtiff. + Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=125 + +2002-04-20 Andrey Kiselev + + * libtiff/tif_open.c: Pointers to custom procedures + in TIFFClientOpen() are checked to be not NULL-pointers. + +2002-04-18 Andrey Kiselev + + * libtiff/libtiff.def: Added missed declarations. + + * libtiff/tif_pixarlog.c: Updated for using tif_tagmethods structure. + +2002-04-16 Andrey Kiselev + + * libtiff/tif_lzw.c: Additional checks for data integrity introduced. + Should finally close + http://bugzilla.remotesensing.org/show_bug.cgi?id=100 + +2002-04-10 Andrey Kiselev + + * tools/tiff2ps: Division by zero fixed. + Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=88 + +2002-04-09 Andrey Kiselev + + * libtiff/: tif_dirwrite.c, tif_write.c, tiffio.h: + TIFFCheckpointDirectory() routine added. + Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=124 + + * man/: TIFFWriteDirectory.3t, Makefile.in: Added description + for the new function. + +2002-04-08 Andrey Kiselev + + * libtiff/: tif_codec.c, tif_compress.c, tiffiop.h: Introduced + additional members tif->tif_decodestatus and tif->tif_encodestatus + for correct handling of unconfigured codecs (we should not try to read + data or to define data size without correct codecs). + + * libtiff/tif_getimage.c: The way of codecs checking in TIFFRGBAImageOK + changed. Now it has used tif->tif_decodestatus and + tif->tif_encodestatus. + Should fix http://bugzilla.remotesensing.org/show_bug.cgi?id=119 (in + case of __cvs_8.tif test image). + + * libtiff/: tif_dirinfo.c, tif_dirread.c: Somebody makes a bug in + tif_dirread.c when TIFFCreateAnonFieldInfo was introduced. + Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=119 in case + of _cvs_00000-00.tif, _cvs_00000-01.tif and _cvs_00000-02.tif. + +2002-04-04 Andrey Kiselev + + * libtiff/: tif_lzw.c: Assertions in LZWDecode and LZWDecodeCompat + replaced by warnings. Now libtiff should read corrupted LZW-compressed + files by skipping bad strips. + Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=100 + +2002-04-03 Frank Warmerdam + + * libtiff/tif_dirwrite.c: Removed some dead code. + + * libtiff/*: Cleanup some warnings. + + * libtiff/tif_dir.c: Fixed bug with count returned by TIFFGetField() + for variable length FIELD_CUSTOM values. Was int * but should be + u_short *. + +2002-04-01 Andrey Kiselev + + * tools/: tifcp.c: Added support for 'Orientation' tag in tiffcp + utility (at cpStripToTile routine). + +2002-03-27 Frank Warmerdam + + * tif_dirread.c: avoid div-by-zero if rowbytes is zero in chop func. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=111 + + * tif_print.c: Fixed so that ASCII FIELD_CUSTOM values with + passcount set FALSE can be printed (such as TIFFTAG_SOFTWARE). + + * libtiff/tif_dir.c,tif_dirinfo.c,tif_dir.h,tif_ojpeg.c: modified so + that TIFFTAG_SOFTWARE uses FIELD_CUSTOM as an example. + +2002-03-26 Dwight Kelly + + * libtiff/: tiff.h, tif_dir.c, tif_dir.h, tif_dirinfo.c, tif_dirread.c, + tif_dirwrite.c: Added get/put code for new tag XMLPACKET as defined + in Adobe XMP Technote. Added missing INKSET tag value from TIFF 6.0 spec + INKSET_MULTIINK (=2). Added missing tags from Adobe TIFF technotes: + CLIPPATH, XCLIPPATHUNITS, YCLIPPATHUNITS, OPIIMAGEID, OPIPROXY and + INDEXED. Added PHOTOMETRIC tag value from TIFF technote 4 ICCLAB (=9). + +2002-03-26 Andrey Kiselev + + * libtiff/: tif_getimage.c: TIFFReadRGBAStrip and TIFFReadRGBATile + now also uses TIFFRGBAImageOK before reading. This is additional fix + for http://bugzilla.remotesensing.org/show_bug.cgi?id=110 + +2002-03-25 Andrey Kiselev + + * libtiff/: tif_getimage.c: Additional check for supported + codecs added in TIFFRGBAImageOK and TIFFReadRGBAImage now uses + TIFFRGBAImageOK before reading. + Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=110 + +2002-03-15 Andrey Kiselev + + * libtiff/: tif_dir.c, tif_dir.h, tif_dirinfo.c, tif_dirread.c, + tif_dirwrite.c: Added routine TIFFDataWidth for detrmining + TIFFDataType sizes instead of working with tiffDataWidth array + directly. Should prevent out-of-borders bugs in case of unknown or + broken data types. EstimateStripByteCounts routine modified, so it + won't work when tags with uknown sizes founded. + Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=109 + +2002-03-13 Andrey Kiselev + + * libtiff/tif_getimage.c: Added support for correct handling + `Orientation' tag in gtTileContig. Should be added in other gt* + functions as well, but I have not images for testing yet. Partially + resolves http://bugzilla.remotesensing.org/show_bug.cgi?id=23 + +2002-03-10 Andrey Kiselev + + * libtiff/: tif_dirinfo.c, tif_dirwrite.c: Added possibility to + read broken TIFFs with LONG type used for TIFFTAG_COMPRESSION, + TIFFTAG_BITSPERSAMPLE, TIFFTAG_PHOTOMETRIC. Closes + http://bugzilla.remotesensing.org/show_bug.cgi?id=99 + +2002-03-08 Andrey Kiselev + + * libtiff/Makefile.in, tools/Makefile.in: Shared library will not + be stripped when installing, utility binaries will do. Closes + http://bugzilla.remotesensing.org/show_bug.cgi?id=93 + +2002-02-28 Frank Warmerdam + + * man/TIFFGetField: fixed type of TIFFTAG_COPYRIGHT. + + * man/libtiff.3t: added copyright tag info. + +2002-02-11 Frank Warmerdam + + * libtiff/{tiff.h,tif_fax3.c}: Add support for __arch64__. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=94 + + * man/Makefile.in: Patch DESTDIR handling + + http://bugzilla.remotesensing.org/show_bug.cgi?id=95 + + * configure: OpenBSD changes for Sparc64 and DSO version. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=96 + +2002-02-05 Frank Warmerdam + + * config.site/configure: added support for OJPEG=yes option to enable + OJPEG support from config.site. + +2002-01-27 Frank Warmerdam + + * html/document.html: fixed links for TIFf 6 docs. + +2002-01-18 Frank Warmerdam + + * config.guess, config.sub: Updated from ftp.gnu.org/pub/config. + + * libtiff/tif_read.c: Fixed TIFFReadEncodedStrip() to fail if the + decodestrip function returns anything not greater than zero as per + http://bugzilla.remotesensing.org/show_bug.cgi?id=97 + + * configure: Modify CheckForBigEndian so it can work in a cross + compiled situation. + +2002-01-16 Frank Warmerdam + + * tools/tiffdump.c: include TIFFTAG_JPEGTABLES in tag list. + + * tools/tiffset.c: fix bug in error reporting. + + * tools/tiffcp.c: fix several warnings that show up with -Wall. + +2002-01-04 Frank Warmerdam + + * libtiff/tif_jpeg.c: fixed computation of segment_width for + tiles files to avoid error about it not matching the + cinfo.d.image_width values ("JPEGPreDecode: Improper JPEG strip/tile + size.") for ITIFF files. Apparently the problem was incorporated since + 3.5.5, presumably during the OJPEG/JPEG work recently. + +2001-12-15 Frank Warmerdam + + * configure, libtiff/Makefile.in: Changes for building on MacOS 10.1. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=94 + + * libtiff/tif_getimage.c: If DEFAULT_EXTRASAMPLE_AS_ALPHA is 1 + (defined in tiffconf.h - 1 by default) then the RGBA interface + will assume that a fourth extra sample is ASSOCALPHA if the + EXTRASAMPLE value isn't set for it. This changes the behaviour of + the library, but makes it work better with RGBA files produced by + lots of applications that don't mark the alpha values properly. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=93 + http://bugzilla.remotesensing.org/show_bug.cgi?id=65 + +2001-12-12 Frank Warmerdam + + * libtiff/tif_jpeg.c: allow jpeg data stream sampling values to + override those from tiff directory. This makes this work with + ImageGear generated files. + +2001-12-07 Frank Warmerdam + + * html/Makefile.in: added missing images per bug 92. + + * port/Makefile.in: fixed clean target per bug 92. + +2001-11-28 Frank Warmerdam + + * Reissue 3.5.7 release. + + * libtiff/mkversion.c: Fix output of TIFF_VERSION to be + YYYYMMDD so that it is increasing over time. + + * Makefile.in: Ensure that tiffvers.h is regenerated in the + make release target. + + * Makefile.in: added libtiff/tiffvers.h to the release file list. + +2001-11-23 Frank Warmerdam + + * added html/v3.5.7.html, updated html/index.html. + + * Makefile.in: added contrib/addtiffo/tif_ovrcache.{c,h}. + +2001-11-15 Frank Warmerdam + + * configure: fixed test for -lm. + +2001-11-02 Frank Warmerdam + + * Added PHOTOMETRIC_ITULAB as per bug 90. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=90 + +2001-10-10 Frank Warmerdam + + * libtiff/tiff.h: I have created COMPRESSION_CCITT_T4, + COMPRESSION_CCITT_T6, TIFFTAG_T4OPTIONS and TIFFTAG_T6OPTIONS aliases + in keeping with TIFF 6.0 standard in tiff.h + + http://bugzilla.remotesensing.org/show_bug.cgi?id=83 + +2001-09-26 Frank Warmerdam + + * libtiff/tif_dirwrite.c: added TIFFRewriteDirectory() function. + Updated TIFFWriteDirectory man page to include TIFFRewriteDirectory. + +2001-09-24 Frank Warmerdam + + * libtiff/tif_lzw.c: Avoid MS VC++ 5.0 optimization bug. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=78 + + * libtiff/tif_lzw.c: added dummy LZWSetupEncode() to report an + error about LZW not being available. + + * libtiff/tif_dir.c: propagate failure to initialize compression + back from TIFFSetField() as an error status, so applications can + detect failure. + + * libtiff/tif_dir.c: removed the auto replacement of + COMPRESSION_LZW with COMPRESSION_NONE in _TIFFVSetField(). + + * Removed Makefile, tools/Makefile, port/install.sh, man/Makefile + from CVS as they are all supposed to be auto-generated by configure. + +2001-09-22 Frank Warmerdam + + * libtiff/tif_ojpeg.c: new update from Scott. + +2001-09-09 Frank Warmerdam + + * libtif/tif_fax3.c: Removed #ifdef PURIFY logic, and modified to + always use the "safe" version, even if there is a very slight + cost in performance. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=54 + + * libtiff/Makefile.in: Fixed @DSOSUB_VERSION to be @DSOSUF_VERSION@ + in two places. + + * libtiff/tif_getimage.c: Fixed problem with reading strips or + tiles that don't start on a tile boundary. Fix contributed by + Josep Vallverdu (from HP), and further described in bug 47. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=47 + + * tools/tiff2ps.c: added OJPEG YCbCr to RGB support. + + * libtiff/tif_ojpeg.c: Applied substantial patch from Scott. + +2001-09-06 Frank Warmerdam + + * libtiff/tif_packbits.c: fixed memory overrun error. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=77 + +2001-08-31 Frank Warmerdam + + * libtiff/tif_getimage.c: relax handling of contig case where + there are extra samples that are supposed to be ignored. This + should now work for 8bit greyscale or palletted images. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=75 + +2001-08-28 Frank Warmerdam + + * libtiff/tif_getimage.c: Don't complain for CMYK (separated) + images with more than four samples per pixel. See: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=73 + +2001-08-10 Frank Warmerdam + + * libtiff/tif_getimage.c: Use memmove() instead of TIFFmemcpy() + in TIFFReadRGBATile() to avoid issues in cases of overlapping + buffers. See Bug 69 in Bugzilla. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=69 + + * tools/tiff2rgba.c: fixed getopt() call so that -b works again. + +2001-08-09 Frank Warmerdam + + * libtiff/tiff.h, libtiff/tif_fax3.c: added check for __LP64__ + when checking for 64 bit architectures as per bugzilla bug 67. + +2001-07-27 Frank Warmerdam + + * man/Makefile.in: add TIFFClientOpen link as per debian submitted + bug 66. + +2001-07-20 Frank Warmerdam + + * libtiff/tif_jpeg.c: Define HAVE_BOOLEAN on windows if RPCNDR.H + has been included. + +2001-07-19 Frank Warmerdam + + * libtiff/tif_open.c: Seek back to zero after failed read, + before writing header. + +2001-07-18 Frank Warmerdam + + * libtiff/tif_ojpeg.c: updates from Scott. Handles colors + much better. Now depends on having patched libjpeg as per + patch in contrib/ojpeg/*. + +2001-07-17 Frank Warmerdam + + * */Makefile.in: added DESTDIR support. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=60 + +2001-07-16 Frank Warmerdam + + * configure, libtiff/Makefile.in: applied OpenBSD patches + as per: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=61 + +2001-06-28 Frank Warmerdam + + * libtiff/tif_getimage.c: Fixed so that failure is properly + reported by gtTileContig, gtStripContig, gtTileSeparate and + gtStripSeparate. + + See http://bugzilla.remotesensing.org/show_bug.cgi?id=51 + + * tiffcmp.c: Fixed multi samples per pixel support for ContigCompare. + Updated bug section of tiffcmp.1 to note tiled file issues. + + See http://bugzilla.remotesensing.org/show_bug.cgi?id=53 + +2001-06-22 Frank Warmerdam + + * configure: Changes for DSO generation on AIX provided by + John Marquart . + + * configure, libtiff/Makeifle.in: Modified to build DSOs properly + on Darwin thanks to Robert Krajewski (rpk@alum.mit.edu) and + Keisuke Fujii (fujiik@jlcuxf.kek.jp). + +2001-06-13 Frank Warmerdam + + * tools/tiff2rgba.c: added -n flag to avoid emitting alpha component. + + * man/tiff2rgba.1: new + +2001-05-22 Frank Warmerdam + + * Added tiffset and tif_ojpeg to the dist lists in Makefile.in. + +2001-05-13 Frank Warmerdam + + * libtiff/tools/thumbnail.c: changed default output compression + to packbits from LZW since LZW isn't generally available. + +2001-05-12 Frank Warmerdam + + * libtiff/tif_ojpeg.c: New. + libtiff/tif_jpeg.c, tiffconf.h, tif_getimage.c: changes related + to OJPEG support. + + Scott Marovich supplied OJPEG support. + +2001-05-11 Frank Warmerdam + + * tiff.h: removed, it duplicates libtiff/tiff.h. + +2001-05-08 Frank Warmerdam + + * libtiff/tif_dirinfo.c: moved pixar and copyright flags to + ensure everything is in order. + + * libtiff/libtiff.def: added TIFFCreateDirectory and + TIFFDefaultStripSize as per: + + http://bugzilla.remotesensing.org/show_bug.cgi?id=46 + +2001-05-02 Frank Warmerdam + + * libtiff/tif_dirinfo.c: Modified the TIFF_BYTE definition for + TIFFTAG_PHOTOSHOP to use a writecount of TIFF_VARIABLE2 (-3) to + force use of uint32 counts instead of short counts. + + * libtiff/tif_dirwrite.c: Added support for TIFF_VARIABLE2 in the + case of writing TIFF_BYTE/TIFF_SBYTE fields. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=43 + +2001-05-01 Frank Warmerdam + + * libtiff/tif_dirinfo.c: removed duplicate TIFFTAG_PHOTOSHOP as per + bug report http://bugzilla.remotesensing.org/show_bug.cgi?id=44 + +2001-04-05 Frank Warmerdam + + * tiffio.h: removed C++ style comment. + + * configure: fixed up SCRIPT_SH/SHELL handling. + + * Makefile.in: Fixed SCRIPT_SH/SHELL handling. + + * config.guess: documented more variables as per bug 40. + +2001-04-03 Frank Warmerdam + + * configure, *Makefile.in: Various changes to improve configuration + for HP/UX specifically, and also in general. They include: + - Try to handle /usr/bin/sh instead of /bin/sh where necessary. + - Upgrade to HP/UX 10.x+ compiler, linker and dso options. + - Fixed mmap() test to avoid MMAP_FIXED ... it isn't available on HP + - Use -${MAKEFLAGS} in sub makes from makefiles. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=40 + +2001-04-02 Frank Warmerdam + + * libtiff/tiff.h: Applied hac to try and resolve the problem + with the inttypes.h include file on AIX. + + See http://bugzilla.remotesensing.org/show_bug.cgi?id=39 + + * VERSION: update to 3.5.7 beta in preparation for release. + + * configure/config.site: modified to check if -lm is needed for + MACHDEPLIBS if not supplied by config.site. Needed for Darwin. + + * config.guess: updated wholesale to an FSF version apparently + from 1998 (as opposed to 1994). This is mainly inspired by + providing for MacOS X support. + +2001-03-29 Frank Warmerdam + + * configure, Makefile.in, etc: added support for OPTIMIZER being + set from config.site. + +2001-03-28 Frank Warmerdam + + * fax2ps.c: Helge (libtiff at oldach.net) submitted fix: + + Here's a fix for fax2ps that corrects behaviour for non-Letter paper + sizes. It fixes two problems: + + Without scaling (-S) the fax is now centered on the page size specified + with -H and/or -W. Before, fax2ps was using an obscure and practially + useless algorithm to allocate the image relative to Letter sized paper + which sometime sled to useless whitespace on the paper, while at the + same time cutting of the faxes printable area at the opposite border. + + Second, scaling now preserves aspect ratio, which makes unusual faxes + (in particular short ones) print properly. + + See http://bugzilla.remotesensing.org/show_bug.cgi?id=35 + + * tiff2ps.c/tiff2ps.1: Substantial changes to tiff2ps by + Bruce A. Mallett. See check message for detailed information + on all the changes, including a faster encoder, fixes for level + 2 PostScript, and support for the imagemask operator. + +2001-03-27 Frank Warmerdam + + * libtiff/tiffio.h: Changed "#if LOGLUV_PUBLIC" to + "#ifdef LOGLUV_PUBLIC" so it will work with VisualAge on AIX. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=39 + +2001-03-16 Frank Warmerdam + + * tif_dirinfo.c: moved definition of copyright tag in field list. + Apparently they have to be in sorted order by tag id. + +2001-03-13 Frank Warmerdam + + * tif_getimage.c: Added support for 16bit minisblack/miniswhite + images in RGBA interface. + +2001-03-02 Frank Warmerdam + + * Added TIFFTAG_COPYRIGHT support. + +2001-02-19 Frank Warmerdam + + * Brent Roman contributed updated tiffcp utility (and tiffcp.1) + with support for extracting subimages with the ,n syntax, and also + adding the -b bias removal flag. + +2001-02-16 Frank Warmerdam + + * libtiff/libtiff.def: Brent Roman submitted new version adding + serveral missing entry points. + + * libtiff/tif_dirinfo.c: don't declare tiffFieldInfo static on VMS. + Some sort of weird VMS thing. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=31 + + * tif_luv.c/tiff.h/tiffio.h: + New version of TIFF LogLuv (SGILOG) modules contributed by Greg Ward + (greg@shutterfly.com). He writes: + + 1) I improved the gamut-mapping function in tif_luv.c for imaginary + colors, because some images were being super-saturated on the input + side and this resulted in some strange color shifts in the output. + + 2) I added a psuedotag in tiff.h to control random dithering during + LogLuv encoding. This is turned off by default for 32-bit LogLuv and + on for 24-bit LogLuv output. Dithering improves the average color + accuracy over the image. + + 3) I added a #define for LOG_LUV_PUBLIC, which is enabled by default in + tiffio.h, to expose internal routines for converting between LogLuv and + XYZ coordinates. This is helpful for writing more efficient, + specialized conversion routines, especially for reading LogLuv files. + + Changes applied with minor edits. + +2001-01-23 Frank Warmerdam + + * tif_fax3.c: keep rw_mode flag internal to fax3 state to remember + whether we are encoding or decoding. This is to ensure graceful + recovery if TIFFClientOpen() discovers an attempt to open a compressed + file for "r+" access, and subsequently close it, as it resets the + tif_mode flag to O_RDONLY in this case to avoid writes, confusing the + compressor's concept of whether it is in encode or decode mode. + +2001-01-08 Mike Welles + + * Makefile.in: Now cleaning up after itself after creating the .tar.gz and .zip + +2001-01-07 Frank Warmerdam + + * html/libtiff.html: Fixed arguments in example for TIFFRGBAImageGet() + as per bug report by Patrick Connor. + +2000-12-28 Frank Warmerdam + + * Added RELEASE-DATE file to release file list. + + * Fixed libtiff/makefile.vc to make tiffvers.h not version.h. + +2000-12-22 Mike Welles + * added link to CVS mirror from index.html + + * updated html/internals.html to note that LZW compression is + not supported by default. + +2000-12-22 Frank Warmerdam + + * updated html/libtiff.html to not point at Niles' old JPL web site + for the man pages, point at www.libtiff.org. + +2000-12-21 Frank Warmerdam + + * libtiff/tif_apple.c: Applied "Carbon" support patches supplied by + Leonard Rosenthol . May interfere + with correct building on older systems. If so, please let me know. + +2000-12-19 Mike Welles + + * Took out LZW Encoding from tif_lzw.c + + * Created HOWTO-RELEASE + + * Created html/v3.5.6.html + + * updated index.html + +2000-12-01 Frank Warmerdam + + * Added patches for EOFB support in tif_fax3.c and tif_fax3.h. + Patches supplied by Frank Cringle + Example file at: ftp://ftp.remotesensing.org/pub/libtiff/eofb_396.tif + +2000-11-24 Frank Warmerdam + + * libtiff/Makefile.in: Added an installPrivateHdrs and install-private + target so that the private headers required by libgeotiff can be + installed with the others. They are not installed by default. + + * libtiff/Makefile.in: Added @MACHLIBDEPS@ to LINUXdso and GNULDdso + targets so libtiff.so will be built with an explicit dependency + on libm.so. + + * libtiff/Makefile.in: Use softlinks to link libtiff.so.3 to + libtiff.so.3.5.5. + + * libtiff/Makefile.in & configure: Remove all references to the ALPHA + file, or ALPHA version logic. Added stuff about DIST_POINT in + place of DIST_TYPE and the alpha release number stuff. + +2000-11-22 Frank Warmerdam + + * I have applied a patch from Steffen Moeller to + the configure script so that it now accepts the --prefix, and + --exec-prefix directives. + +2000-11-13 Frank Warmerdam + + * I have made a variety of modifications in an effort to ensure the + TIFFLIB_VERSION macro is automatically generated from the RELEASE-DATE + file which seems to be updated regularly. + + o mkversion.c now reads RELEASE-DATE and emits TIFFLIB_VERSION in + version include file. + o renamed version.h to tiffvers.h because we now have to install it + with the public libtiff include files. + o include tiffvers.h in tiffio.h. + o updated tif_version.c to use tiffvers.h. + o Updated Makefile.in accordingly. + + * As per http://bugzilla.remotesensing.org/show_bug.cgi?id=25 + I have updated the win32 detection rules in tiffcomp.h. + +2000-10-20 Frank Warmerdam + + * tif_getimage.c: Fixed RGBA translation for YCbCr images for which + the strip/tile width and height aren't multiples of the sampling size. + See http://bugzilla.remotesensing.org/show_bug.cgi?id=20 + Some patches from Rick LaMont of Dot C Software. + + * Modified tif_packbits.c encoder to avoid compressing more + data than provided if rowsize doesn't factor into provided data + (such as occurs for YCbCr). + +2000-10-19 Frank Warmerdam + + * tools/rgb2ycbcr.c: fixed output strip size to account for vertical + roundup if rows_per_strip not a multiple of vertical sample size. + +2000-10-16 Frank Warmerdam + + * tif_dir.c: Clear TIFF_ISTILED flag in TIFFDefaultDirectory + as per http://bugzilla.remotesensing.org/show_bug.cgi?id=18 + from vandrove@vc.cvut.cz. + + * Modified tif_packbits.c decoding to avoid overrunning the + output buffer, and to issue a warning if data needs to be + discarded. See http://bugzilla.remotesensing.org/show_bug.cgi?id=18 + +2000-10-12 Frank Warmerdam + + * Modified tiff2bw to ensure portions add to 100%, and that + white is properly recovered. + + See bug http://bugzilla.remotesensing.org/show_bug.cgi?id=15 + Patch c/o Stanislav Brabec + +2000-09-30 Frank Warmerdam + + * Modified TIFFClientOpen() to emit an error on an attempt to + open a comperessed file for update (O_RDWR/r+) access. This is + because the compressor/decompressor code gets very confused when + the mode is O_RDWR, assuming this means writing only. See + bug http://bugzilla.remotesensing.org/show_bug.cgi?id=13 + +2000-09-27 Frank Warmerdam + + * Added GNULDdso target an`d switched linux and freebsd to use it. + +2000-09-26 Frank Warmerdam + + * Applied patch for 0x0000 sequences in tif_fax3.h's definition + of EXPAND1D() as per bug 11 (from Roman). + +2000-09-25 Frank Warmerdam + * Fixed tiffcomp.h to avoid win32 stuff if unix #defined, to improve + cygwin compatibility. + + * Applied patch from Roman Shpount to tif_fax3.c. This seems to + be a proper fix to the buffer sizing problem. See + http://bugzilla.remotesensing.org/show_bug.cgi?id=11 + + * Fixed tif_getimage.c to fix overrun bug with YCbCr images without + downsampling. http://bugzilla.remotesensing.org/show_bug.cgi?id=10 + Thanks to Nick Lamb for reporting the + bug and proving the patch. + +2000-09-18 Frank Warmerdam + + * Fixed tif_jpeg.c so avoid destroying the decompressor before + we are done access data thanks to bug report from: + Michael Eckstein . + + * Reverted tif_flush change. + +2000-09-14 Frank Warmerdam + + * tif_flush.c: Changed so that TIFFFlushData() doesn't return an + error when TIFF_BEENWRITING is not set. This ensures that the + directory contents can still be flushed by TIFFFlush(). + +2000-08-14 Frank Warmerdam + + * tif_open.c: Don't set MMAP for O_RDWR files. + + * tif_open.c: Set STRIPCHOP_DEFAULT for O_RDWR as well as O_RDONLY + so that files opened for update can be strip chopped too. + + * tif_read.c: fixed up bug with files missing rowsperstrip and + the strips per separation fix done a few weeks ago. + +2000-07-17 Frank Warmerdam + + * Tentatively added support for SAMPLEFORMAT_COMPLEXIEEEFP, and + SAMPLEFORMAT_COMPLEXINT. + +2000-07-13 Mike Welles + + * index.html, bugs.html: added bugzilla info. + +2000-07-12 Frank Warmerdam + + * tif_read.c: fix subtle bug with determining the number of + rows for strips that are the last strip in a separation but + not the last strip of all in TIFFReadEncodedStrip(). + + * Applied 16/32 bit fix to tif_fax3.c. Fix supplied by + Peter Skarpetis + +2000-06-15 Frank Warmerdam + + * Modified tiffio.h logic with regard to including windows.h. It + won't include it when building with __CYGWIN__. + +2000-05-11 Frank Warmerdam + + * README: update to mention www.libtiff.org, don't list Sam's old + email address. + + * configure: Fixed DSO test for Linux as per patch from + Jan Van Buggenhout . + +2000-04-21 Frank Warmerdam + + * libtiff/tif_dirread.c: Don't use estimate strip byte count for + one tile/strip images with an offset, and byte count of zero. These + could be "unpopulated" images. + +2000-04-18 Frank Warmerdam + + * contrib/addtiffo: Added "averaging" resampling option. + + * tools/tiffsplit.c: Copy TIFFTAG_SAMPLEFORMAT. + +Tue Apr 18 16:18:08 2000 Frank Warmerdam + + * tools/Makefile.in: Modified to install properly on SGI. + +2000-04-12 Mike Welles + * configure: Fixed stupid mistake in libc6 test on Linux + +2000-04-04 Mike Welles + * tif_win32.c: Applied patch to fix overreads and ovverwrites + caught by BoundsChecker. From Arvan Pritchard + (untested). + + * tif_getimage.c: Applied patch to silence VC6 warnings. From + Arvan Pritchard + + * tif_lzw.c: Applied patch to silence VC6 warnings. From + Arvan Pritchard + +2000-03-28 Frank Warmerdam + + * Added contrib/stream (stream io) code submitted by Avi Bleiweiss. + +2000-03-28 Frank Warmerdam *** 3.5.5 release *** + + * fax2ps: Fixed mixup of width and height in bounding box statement + as per submission by Nalin Dahyabhai . + +2000-03-27 Mike Welles + + * fax2ps: Modified printruns to take uint32 instead of uint16. + Patch courtesy of Bernt Herd + +2000-03-20 Mike Welles + + * configure: added test for libc6 for linux targets. Bug reported by + Stanislav Brabec + + * Added 3.5 docs to html/Makefile.in. + Thanks to Stanislav Brabec + + * configure: fixed bugs in sed scripts + (applied sed script s:/@:s;@:;s:/s;;:;: to configure). + fix submitted to Stanislav Brabec + + * tools/iptcutil was not in files list, and wasn't being + added to tar archive. Updated Makefile.in. + +2000-03-17 Frank Warmerdam + + * tif_fax3.c: Fixed serious bug introduced during the uint16->uint32 + conversion for the run arrays. + +2000-03-03 Frank Warmerdam + + * Set td_sampleformat default to SAMPLEFORMAT_UINT instead of + SAMPLEFORMAT_VOID in TIFFDefaultDirectory() in tif_dir.c. + +2000-03-02 Frank Warmerdam + + * Added "GetDefaulted" support for TIFFTAG_SAMPLEFORMAT in tif_aux.c. + + * Patched tif_fax3.c so that dsp->runs is allocated a bit bigger + to avoid overruns encountered with frle_bug.tif. + +Tue Feb 15 22:01:05 2000 Frank Warmerdam + + * Fixed tools/tiffcmp so that stopondiff testing works. + Patch care of Joseph Orost . + +2000-01-28 + + * Modified tif_unix.c to support 2-4GB seeks if USE_64BIT_API is + set to 1, and added default (off) setting in tiffconf.h. This + should eventually be set by the configure script somehow. + + The original work on all these 2-4GB changes was done by + Peter Smith (psmith@creo.com). + + * Modified tif_win32.c to support 2-4GB seeks. + + * tentatively changed toff_t to be unsigned instead of signed to + facilitate support for 2-4GB files. + + * Updated a variety of files to use toff_t. Fixed some mixups + between toff_t and tsize_t. + +Fri Jan 28 10:13:49 2000 Frank Warmerdam + + * Largely reimplemented contrib/addtiffo to avoid temp files, + updating the TIFF file in place. Fixed a few other bugs to. + + * Set tif_rawdatasize to zero when freeing raw data buffer in + TIFFWriteDirectory(). + + * Enabled "REWRITE_HACK" in tif_write.c by default. + + * Fix bug in tif_write.c when switching between reading one directory + and writing to another. + + * Made TIFFWriteCheck() public, and added TIFFCreateDirectory() + +Wed Jan 5 12:37:48 2000 Frank Warmerdam + + * Added TIFFmemory(3t) functions to libtiff.def. + +Tue Jan 4 13:39:00 2000 Frank Warmerdam + + * Added libtiff/libtiff.def to TIFFILES distribution list. + +Mon Dec 27 12:13:39 EST 1999 Mike Welles + + * Created lzw compression kit, as a new module (libtiff-lzw-compression-kit). + + * Altered descriptions in tools to reflect "by default" lzw not supported + + * Updated index.html to note lzw compression kit. + +Tue Dec 21 14:01:51 1999 Frank Warmerdam + + * Added fax3sm_winnt.c to distribution list in Makefile.in. + +Tue Dec 21 11:04:45 EST 1999 Mike Welles *** 3.5.4 release *** + + * Aadded Pixar tag support. Contributed by Phil Beffery + + * Made one more change to tif_dir.c for removal of LZW compression. Also added notice + when LZW compression invoked. + + * Changed default compression in tools to TIFF_PACKBITS, and changed usage descriptions + in tools to reflect removal of LZW compression + +Mon Dec 20 18:39:02 EST 1999 Mike Welles + + * Fixed bug that caused LZW (non) compression to segfault. Added + warning about LZW compression removed being removed, and why. + + * Added nostrip to install in tools/Makefile.in so that debugging + symbols are kept. + +Tue Dec 7 12:04:47 EST 1999 Mike Welles + + * Added patch from Ivo Penzar , + supporting Adobe ZIP deflate. Untested. + +Sat Dec 4 15:47:11 1999 Frank Warmerdam + + * Made Packbits the default compression in tools/tiff2rgba.c instead + of LZW. + +Tue Nov 30 14:41:43 1999 Frank Warmerdam *** 3.5.3. release *** + + * Added tif_luv to contrib/djgpp/Makefile.lib. + +Tue Nov 30 14:15:32 EST 1999 Mike Welles + + * Added zip creation to relase makefile target + + * Added html for TIFFWriteTile.3t man page. + +Tue Nov 30 09:20:16 1999 Frank Warmerdam + + * Added some changes to tif_write.c to support rewriting existing + fixed sized tiles and strips. Code mods disabled by default, only + enabled if REWRITE_HACK is defined for now. + +Mon Nov 29 11:43:42 1999 Frank Warmerdam + + * Added TIFFWriteTile.3t man page. + +Sun Nov 28 20:36:18 1999 Frank Warmerdam + + * Added notes on use of makefile.vc in build.html, and fixed + email subscription address. + +199-11-28 Mike Welles + + * Fixed apocalypse-inducing y2k bug in contrib/ras/ras2tiff.c + + * Did some casts cleaning up to reduce compiler warnings in tif_fax3.c, + from Bruce Carmeron -- modifications of + changes made by Frank (sun cc still complained on cast). + + * Added tiffconf.h to install target per request from Bill + Radcliffe : "We need a way for ImageMagick to + know features have been compiled into the TIFF library in order to + handle things properly". + +Sat Nov 27 16:49:21 1999 Frank Warmerdam + + * fixed various VC++ warnings as suggested by Gilles Vollant + . + +Wed Nov 24 12:08:16 1999 Frank Warmerdam + + * Modified TIFFquery.3t man pages info on TIFFIsByteSwapped() to + not imply applications are responsible for image data swapping. + +1999-11-22 Mike Welles + * HTML-ized the man pages, added to html/man + + * Removed LZW Compression to comply with Unisys patent extortion. + +1999-09-29 Mike Welles + * Corrected one remaining 16 -> 32 bit value in tif_fax3.c, + From Ivo Penzar + +1999-09-26 Mike Welles *** 3.5.2 release *** + * Corrected alpha versioning. + + * Removed distinction between alpha and release targets in Makefile.in. + + * added release.stamp target, which tags cvs tree, and updates + "RELEASE-DATE" + + * added releasediff target, which diffs tree with source as of + date in "RELEASE-DATE" + + * Ticked up version to 3.5.2 (alpha 01 -- but I think we'll moving + away from alpha/non-alpha distinctions). + + * updated html to reflect release + +1999-09-23 + + * Set O_BINARY for tif_unix.c open() ... used on cygwin for instance. + + * Added CYGWIN case in configure. + +Fri Sep 17 00:13:51 CEST 1999 Mike Welles + + * Applied Francois Dagand's patch to handle fax decompression bug. + (sizes >= 65536 were failing) + +Tue Sep 14 21:31:43 1999 Frank Warmerdam + + * Applied "a" mode fix to tif_win32.c/TIFFOpen() as suggested + by Christopher Lawton + +Wed Sep 8 08:19:18 1999 Frank Warmerdam + + * Added IRIX/gcc, and OSF/1 4.x support on behalf of + Albert Chin-A-Young + + * Added TIFFReassignTagToIgnore() API on behalf of + Bruce Cameron . Man page still pending. + +Wed Aug 25 11:39:07 1999 Frank Warmerdam + + * Added test target in Makefile, test_pics.sh script and pics/*.rpt + files to provide for a rudimentary testsuite. + + * Added contrib/tags back from old distribution ... fixed up a bit. + +1999-08-16 + + * Added simple makefile.vc makefiles for building with MS VC++ + on Windows NT/98/95 in console mode. Stuff in contrib/win* make give + better solutions for some users. + +Mon Aug 16 21:52:11 1999 Frank Warmerdam + + * Added addtiffo (add overviews to a TIFF file) in contrib. Didn't + put it in tools since part of it is in C++. + +1999-08-16 Michael L. Welles + + * Updated html/index.html with anon CVS instructions. + +Mon Aug 16 13:18:41 1999 Frank Warmerdam + + * pre-remove so link before softlink in LINUXdso action in + libtiff/Makefile.in to avoid failure on LINUXdso builds other than + the first. + + * Fixed problem with cvtcmap() in tif_getimage.c modifying the + colormaps owned by the TIFF handle itself when trying to fixup wrong + (eight bit) colormaps. Corrected by maintaining a private copy of + the colormap. + + * Added TIFFReadRGBATile()/TIFFReadRGBAStrip() support in + tif_getimage.c. + + * CVS Repository placed at remotesensing.org. ChangeLog added. diff --git a/Source/LibTIFF4/mkg3states.c b/Source/LibTIFF4/mkg3states.c index 7b718fa..22cc2e9 100644 --- a/Source/LibTIFF4/mkg3states.c +++ b/Source/LibTIFF4/mkg3states.c @@ -1,451 +1,451 @@ -/* "$Id: mkg3states.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1991-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* Initialise fax decoder tables - * Decoder support is derived, with permission, from the code - * in Frank Cringle's viewfax program; - * Copyright (C) 1990, 1995 Frank D. Cringle. - */ -#include "tif_config.h" - -#include -#include -#include - -#ifdef HAVE_UNISTD_H -# include -#endif - -#include "tif_fax3.h" - -#ifndef HAVE_GETOPT -extern int getopt(int, char**, char*); -#endif - -#define streq(a,b) (strcmp(a,b) == 0) - -/* NB: can't use names in tif_fax3.h 'cuz they are declared const */ -TIFFFaxTabEnt MainTable[128]; -TIFFFaxTabEnt WhiteTable[4096]; -TIFFFaxTabEnt BlackTable[8192]; - -struct proto { - uint16 code; /* right justified, lsb-first, zero filled */ - uint16 val; /* (pixel count)<<4 + code width */ -}; - -static struct proto Pass[] = { -{ 0x0008, 4 }, -{ 0, 0 } -}; - -static struct proto Horiz[] = { -{ 0x0004, 3 }, -{ 0, 0 } -}; - -static struct proto V0[] = { -{ 0x0001, 1 }, -{ 0, 0 } -}; - -static struct proto VR[] = { -{ 0x0006, (1<<4)+3 }, -{ 0x0030, (2<<4)+6 }, -{ 0x0060, (3<<4)+7 }, -{ 0, 0 } -}; - -static struct proto VL[] = { -{ 0x0002, (1<<4)+3 }, -{ 0x0010, (2<<4)+6 }, -{ 0x0020, (3<<4)+7 }, -{ 0, 0 } -}; - -static struct proto Ext[] = { -{ 0x0040, 7 }, -{ 0, 0 } -}; - -static struct proto EOLV[] = { -{ 0x0000, 7 }, -{ 0, 0 } -}; - -static struct proto MakeUpW[] = { -{ 0x001b, 1029 }, -{ 0x0009, 2053 }, -{ 0x003a, 3078 }, -{ 0x0076, 4103 }, -{ 0x006c, 5128 }, -{ 0x00ec, 6152 }, -{ 0x0026, 7176 }, -{ 0x00a6, 8200 }, -{ 0x0016, 9224 }, -{ 0x00e6, 10248 }, -{ 0x0066, 11273 }, -{ 0x0166, 12297 }, -{ 0x0096, 13321 }, -{ 0x0196, 14345 }, -{ 0x0056, 15369 }, -{ 0x0156, 16393 }, -{ 0x00d6, 17417 }, -{ 0x01d6, 18441 }, -{ 0x0036, 19465 }, -{ 0x0136, 20489 }, -{ 0x00b6, 21513 }, -{ 0x01b6, 22537 }, -{ 0x0032, 23561 }, -{ 0x0132, 24585 }, -{ 0x00b2, 25609 }, -{ 0x0006, 26630 }, -{ 0x01b2, 27657 }, -{ 0, 0 } -}; - -static struct proto MakeUpB[] = { -{ 0x03c0, 1034 }, -{ 0x0130, 2060 }, -{ 0x0930, 3084 }, -{ 0x0da0, 4108 }, -{ 0x0cc0, 5132 }, -{ 0x02c0, 6156 }, -{ 0x0ac0, 7180 }, -{ 0x06c0, 8205 }, -{ 0x16c0, 9229 }, -{ 0x0a40, 10253 }, -{ 0x1a40, 11277 }, -{ 0x0640, 12301 }, -{ 0x1640, 13325 }, -{ 0x09c0, 14349 }, -{ 0x19c0, 15373 }, -{ 0x05c0, 16397 }, -{ 0x15c0, 17421 }, -{ 0x0dc0, 18445 }, -{ 0x1dc0, 19469 }, -{ 0x0940, 20493 }, -{ 0x1940, 21517 }, -{ 0x0540, 22541 }, -{ 0x1540, 23565 }, -{ 0x0b40, 24589 }, -{ 0x1b40, 25613 }, -{ 0x04c0, 26637 }, -{ 0x14c0, 27661 }, -{ 0, 0 } -}; - -static struct proto MakeUp[] = { -{ 0x0080, 28683 }, -{ 0x0180, 29707 }, -{ 0x0580, 30731 }, -{ 0x0480, 31756 }, -{ 0x0c80, 32780 }, -{ 0x0280, 33804 }, -{ 0x0a80, 34828 }, -{ 0x0680, 35852 }, -{ 0x0e80, 36876 }, -{ 0x0380, 37900 }, -{ 0x0b80, 38924 }, -{ 0x0780, 39948 }, -{ 0x0f80, 40972 }, -{ 0, 0 } -}; - -static struct proto TermW[] = { -{ 0x00ac, 8 }, -{ 0x0038, 22 }, -{ 0x000e, 36 }, -{ 0x0001, 52 }, -{ 0x000d, 68 }, -{ 0x0003, 84 }, -{ 0x0007, 100 }, -{ 0x000f, 116 }, -{ 0x0019, 133 }, -{ 0x0005, 149 }, -{ 0x001c, 165 }, -{ 0x0002, 181 }, -{ 0x0004, 198 }, -{ 0x0030, 214 }, -{ 0x000b, 230 }, -{ 0x002b, 246 }, -{ 0x0015, 262 }, -{ 0x0035, 278 }, -{ 0x0072, 295 }, -{ 0x0018, 311 }, -{ 0x0008, 327 }, -{ 0x0074, 343 }, -{ 0x0060, 359 }, -{ 0x0010, 375 }, -{ 0x000a, 391 }, -{ 0x006a, 407 }, -{ 0x0064, 423 }, -{ 0x0012, 439 }, -{ 0x000c, 455 }, -{ 0x0040, 472 }, -{ 0x00c0, 488 }, -{ 0x0058, 504 }, -{ 0x00d8, 520 }, -{ 0x0048, 536 }, -{ 0x00c8, 552 }, -{ 0x0028, 568 }, -{ 0x00a8, 584 }, -{ 0x0068, 600 }, -{ 0x00e8, 616 }, -{ 0x0014, 632 }, -{ 0x0094, 648 }, -{ 0x0054, 664 }, -{ 0x00d4, 680 }, -{ 0x0034, 696 }, -{ 0x00b4, 712 }, -{ 0x0020, 728 }, -{ 0x00a0, 744 }, -{ 0x0050, 760 }, -{ 0x00d0, 776 }, -{ 0x004a, 792 }, -{ 0x00ca, 808 }, -{ 0x002a, 824 }, -{ 0x00aa, 840 }, -{ 0x0024, 856 }, -{ 0x00a4, 872 }, -{ 0x001a, 888 }, -{ 0x009a, 904 }, -{ 0x005a, 920 }, -{ 0x00da, 936 }, -{ 0x0052, 952 }, -{ 0x00d2, 968 }, -{ 0x004c, 984 }, -{ 0x00cc, 1000 }, -{ 0x002c, 1016 }, -{ 0, 0 } -}; - -static struct proto TermB[] = { -{ 0x03b0, 10 }, -{ 0x0002, 19 }, -{ 0x0003, 34 }, -{ 0x0001, 50 }, -{ 0x0006, 67 }, -{ 0x000c, 84 }, -{ 0x0004, 100 }, -{ 0x0018, 117 }, -{ 0x0028, 134 }, -{ 0x0008, 150 }, -{ 0x0010, 167 }, -{ 0x0050, 183 }, -{ 0x0070, 199 }, -{ 0x0020, 216 }, -{ 0x00e0, 232 }, -{ 0x0030, 249 }, -{ 0x03a0, 266 }, -{ 0x0060, 282 }, -{ 0x0040, 298 }, -{ 0x0730, 315 }, -{ 0x00b0, 331 }, -{ 0x01b0, 347 }, -{ 0x0760, 363 }, -{ 0x00a0, 379 }, -{ 0x0740, 395 }, -{ 0x00c0, 411 }, -{ 0x0530, 428 }, -{ 0x0d30, 444 }, -{ 0x0330, 460 }, -{ 0x0b30, 476 }, -{ 0x0160, 492 }, -{ 0x0960, 508 }, -{ 0x0560, 524 }, -{ 0x0d60, 540 }, -{ 0x04b0, 556 }, -{ 0x0cb0, 572 }, -{ 0x02b0, 588 }, -{ 0x0ab0, 604 }, -{ 0x06b0, 620 }, -{ 0x0eb0, 636 }, -{ 0x0360, 652 }, -{ 0x0b60, 668 }, -{ 0x05b0, 684 }, -{ 0x0db0, 700 }, -{ 0x02a0, 716 }, -{ 0x0aa0, 732 }, -{ 0x06a0, 748 }, -{ 0x0ea0, 764 }, -{ 0x0260, 780 }, -{ 0x0a60, 796 }, -{ 0x04a0, 812 }, -{ 0x0ca0, 828 }, -{ 0x0240, 844 }, -{ 0x0ec0, 860 }, -{ 0x01c0, 876 }, -{ 0x0e40, 892 }, -{ 0x0140, 908 }, -{ 0x01a0, 924 }, -{ 0x09a0, 940 }, -{ 0x0d40, 956 }, -{ 0x0340, 972 }, -{ 0x05a0, 988 }, -{ 0x0660, 1004 }, -{ 0x0e60, 1020 }, -{ 0, 0 } -}; - -static struct proto EOLH[] = { -{ 0x0000, 11 }, -{ 0, 0 } -}; - -static void -FillTable(TIFFFaxTabEnt *T, int Size, struct proto *P, int State) -{ - int limit = 1 << Size; - - while (P->val) { - int width = P->val & 15; - int param = P->val >> 4; - int incr = 1 << width; - int code; - for (code = P->code; code < limit; code += incr) { - TIFFFaxTabEnt *E = T+code; - E->State = State; - E->Width = width; - E->Param = param; - } - P++; - } -} - -static char* storage_class = ""; -static char* const_class = ""; -static int packoutput = 1; -static char* prebrace = ""; -static char* postbrace = ""; - -void -WriteTable(FILE* fd, const TIFFFaxTabEnt* T, int Size, const char* name) -{ - int i; - char* sep; - - fprintf(fd, "%s %s TIFFFaxTabEnt %s[%d] = {", - storage_class, const_class, name, Size); - if (packoutput) { - sep = "\n"; - for (i = 0; i < Size; i++) { - fprintf(fd, "%s%s%d,%d,%d%s", - sep, prebrace, T->State, T->Width, (int) T->Param, postbrace); - if (((i+1) % 10) == 0) - sep = ",\n"; - else - sep = ","; - T++; - } - } else { - sep = "\n "; - for (i = 0; i < Size; i++) { - fprintf(fd, "%s%s%3d,%3d,%4d%s", - sep, prebrace, T->State, T->Width, (int) T->Param, postbrace); - if (((i+1) % 6) == 0) - sep = ",\n "; - else - sep = ","; - T++; - } - } - fprintf(fd, "\n};\n"); -} - -/* initialise the huffman code tables */ -int -main(int argc, char* argv[]) -{ - FILE* fd; - char* outputfile; - int c; - extern int optind; - extern char* optarg; - - while ((c = getopt(argc, argv, "c:s:bp")) != -1) - switch (c) { - case 'c': - const_class = optarg; - break; - case 's': - storage_class = optarg; - break; - case 'p': - packoutput = 0; - break; - case 'b': - prebrace = "{"; - postbrace = "}"; - break; - case '?': - fprintf(stderr, - "usage: %s [-c const] [-s storage] [-p] [-b] file\n", - argv[0]); - return (-1); - } - outputfile = optind < argc ? argv[optind] : "g3states.h"; - fd = fopen(outputfile, "w"); - if (fd == NULL) { - fprintf(stderr, "%s: %s: Cannot create output file.\n", - argv[0], outputfile); - return (-2); - } - FillTable(MainTable, 7, Pass, S_Pass); - FillTable(MainTable, 7, Horiz, S_Horiz); - FillTable(MainTable, 7, V0, S_V0); - FillTable(MainTable, 7, VR, S_VR); - FillTable(MainTable, 7, VL, S_VL); - FillTable(MainTable, 7, Ext, S_Ext); - FillTable(MainTable, 7, EOLV, S_EOL); - FillTable(WhiteTable, 12, MakeUpW, S_MakeUpW); - FillTable(WhiteTable, 12, MakeUp, S_MakeUp); - FillTable(WhiteTable, 12, TermW, S_TermW); - FillTable(WhiteTable, 12, EOLH, S_EOL); - FillTable(BlackTable, 13, MakeUpB, S_MakeUpB); - FillTable(BlackTable, 13, MakeUp, S_MakeUp); - FillTable(BlackTable, 13, TermB, S_TermB); - FillTable(BlackTable, 13, EOLH, S_EOL); - - fprintf(fd, "/* WARNING, this file was automatically generated by the\n"); - fprintf(fd, " mkg3states program */\n"); - fprintf(fd, "#include \"tiff.h\"\n"); - fprintf(fd, "#include \"tif_fax3.h\"\n"); - WriteTable(fd, MainTable, 128, "TIFFFaxMainTable"); - WriteTable(fd, WhiteTable, 4096, "TIFFFaxWhiteTable"); - WriteTable(fd, BlackTable, 8192, "TIFFFaxBlackTable"); - fclose(fd); - return (0); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* "$Id: mkg3states.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1991-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* Initialise fax decoder tables + * Decoder support is derived, with permission, from the code + * in Frank Cringle's viewfax program; + * Copyright (C) 1990, 1995 Frank D. Cringle. + */ +#include "tif_config.h" + +#include +#include +#include + +#ifdef HAVE_UNISTD_H +# include +#endif + +#include "tif_fax3.h" + +#ifndef HAVE_GETOPT +extern int getopt(int, char**, char*); +#endif + +#define streq(a,b) (strcmp(a,b) == 0) + +/* NB: can't use names in tif_fax3.h 'cuz they are declared const */ +TIFFFaxTabEnt MainTable[128]; +TIFFFaxTabEnt WhiteTable[4096]; +TIFFFaxTabEnt BlackTable[8192]; + +struct proto { + uint16 code; /* right justified, lsb-first, zero filled */ + uint16 val; /* (pixel count)<<4 + code width */ +}; + +static struct proto Pass[] = { +{ 0x0008, 4 }, +{ 0, 0 } +}; + +static struct proto Horiz[] = { +{ 0x0004, 3 }, +{ 0, 0 } +}; + +static struct proto V0[] = { +{ 0x0001, 1 }, +{ 0, 0 } +}; + +static struct proto VR[] = { +{ 0x0006, (1<<4)+3 }, +{ 0x0030, (2<<4)+6 }, +{ 0x0060, (3<<4)+7 }, +{ 0, 0 } +}; + +static struct proto VL[] = { +{ 0x0002, (1<<4)+3 }, +{ 0x0010, (2<<4)+6 }, +{ 0x0020, (3<<4)+7 }, +{ 0, 0 } +}; + +static struct proto Ext[] = { +{ 0x0040, 7 }, +{ 0, 0 } +}; + +static struct proto EOLV[] = { +{ 0x0000, 7 }, +{ 0, 0 } +}; + +static struct proto MakeUpW[] = { +{ 0x001b, 1029 }, +{ 0x0009, 2053 }, +{ 0x003a, 3078 }, +{ 0x0076, 4103 }, +{ 0x006c, 5128 }, +{ 0x00ec, 6152 }, +{ 0x0026, 7176 }, +{ 0x00a6, 8200 }, +{ 0x0016, 9224 }, +{ 0x00e6, 10248 }, +{ 0x0066, 11273 }, +{ 0x0166, 12297 }, +{ 0x0096, 13321 }, +{ 0x0196, 14345 }, +{ 0x0056, 15369 }, +{ 0x0156, 16393 }, +{ 0x00d6, 17417 }, +{ 0x01d6, 18441 }, +{ 0x0036, 19465 }, +{ 0x0136, 20489 }, +{ 0x00b6, 21513 }, +{ 0x01b6, 22537 }, +{ 0x0032, 23561 }, +{ 0x0132, 24585 }, +{ 0x00b2, 25609 }, +{ 0x0006, 26630 }, +{ 0x01b2, 27657 }, +{ 0, 0 } +}; + +static struct proto MakeUpB[] = { +{ 0x03c0, 1034 }, +{ 0x0130, 2060 }, +{ 0x0930, 3084 }, +{ 0x0da0, 4108 }, +{ 0x0cc0, 5132 }, +{ 0x02c0, 6156 }, +{ 0x0ac0, 7180 }, +{ 0x06c0, 8205 }, +{ 0x16c0, 9229 }, +{ 0x0a40, 10253 }, +{ 0x1a40, 11277 }, +{ 0x0640, 12301 }, +{ 0x1640, 13325 }, +{ 0x09c0, 14349 }, +{ 0x19c0, 15373 }, +{ 0x05c0, 16397 }, +{ 0x15c0, 17421 }, +{ 0x0dc0, 18445 }, +{ 0x1dc0, 19469 }, +{ 0x0940, 20493 }, +{ 0x1940, 21517 }, +{ 0x0540, 22541 }, +{ 0x1540, 23565 }, +{ 0x0b40, 24589 }, +{ 0x1b40, 25613 }, +{ 0x04c0, 26637 }, +{ 0x14c0, 27661 }, +{ 0, 0 } +}; + +static struct proto MakeUp[] = { +{ 0x0080, 28683 }, +{ 0x0180, 29707 }, +{ 0x0580, 30731 }, +{ 0x0480, 31756 }, +{ 0x0c80, 32780 }, +{ 0x0280, 33804 }, +{ 0x0a80, 34828 }, +{ 0x0680, 35852 }, +{ 0x0e80, 36876 }, +{ 0x0380, 37900 }, +{ 0x0b80, 38924 }, +{ 0x0780, 39948 }, +{ 0x0f80, 40972 }, +{ 0, 0 } +}; + +static struct proto TermW[] = { +{ 0x00ac, 8 }, +{ 0x0038, 22 }, +{ 0x000e, 36 }, +{ 0x0001, 52 }, +{ 0x000d, 68 }, +{ 0x0003, 84 }, +{ 0x0007, 100 }, +{ 0x000f, 116 }, +{ 0x0019, 133 }, +{ 0x0005, 149 }, +{ 0x001c, 165 }, +{ 0x0002, 181 }, +{ 0x0004, 198 }, +{ 0x0030, 214 }, +{ 0x000b, 230 }, +{ 0x002b, 246 }, +{ 0x0015, 262 }, +{ 0x0035, 278 }, +{ 0x0072, 295 }, +{ 0x0018, 311 }, +{ 0x0008, 327 }, +{ 0x0074, 343 }, +{ 0x0060, 359 }, +{ 0x0010, 375 }, +{ 0x000a, 391 }, +{ 0x006a, 407 }, +{ 0x0064, 423 }, +{ 0x0012, 439 }, +{ 0x000c, 455 }, +{ 0x0040, 472 }, +{ 0x00c0, 488 }, +{ 0x0058, 504 }, +{ 0x00d8, 520 }, +{ 0x0048, 536 }, +{ 0x00c8, 552 }, +{ 0x0028, 568 }, +{ 0x00a8, 584 }, +{ 0x0068, 600 }, +{ 0x00e8, 616 }, +{ 0x0014, 632 }, +{ 0x0094, 648 }, +{ 0x0054, 664 }, +{ 0x00d4, 680 }, +{ 0x0034, 696 }, +{ 0x00b4, 712 }, +{ 0x0020, 728 }, +{ 0x00a0, 744 }, +{ 0x0050, 760 }, +{ 0x00d0, 776 }, +{ 0x004a, 792 }, +{ 0x00ca, 808 }, +{ 0x002a, 824 }, +{ 0x00aa, 840 }, +{ 0x0024, 856 }, +{ 0x00a4, 872 }, +{ 0x001a, 888 }, +{ 0x009a, 904 }, +{ 0x005a, 920 }, +{ 0x00da, 936 }, +{ 0x0052, 952 }, +{ 0x00d2, 968 }, +{ 0x004c, 984 }, +{ 0x00cc, 1000 }, +{ 0x002c, 1016 }, +{ 0, 0 } +}; + +static struct proto TermB[] = { +{ 0x03b0, 10 }, +{ 0x0002, 19 }, +{ 0x0003, 34 }, +{ 0x0001, 50 }, +{ 0x0006, 67 }, +{ 0x000c, 84 }, +{ 0x0004, 100 }, +{ 0x0018, 117 }, +{ 0x0028, 134 }, +{ 0x0008, 150 }, +{ 0x0010, 167 }, +{ 0x0050, 183 }, +{ 0x0070, 199 }, +{ 0x0020, 216 }, +{ 0x00e0, 232 }, +{ 0x0030, 249 }, +{ 0x03a0, 266 }, +{ 0x0060, 282 }, +{ 0x0040, 298 }, +{ 0x0730, 315 }, +{ 0x00b0, 331 }, +{ 0x01b0, 347 }, +{ 0x0760, 363 }, +{ 0x00a0, 379 }, +{ 0x0740, 395 }, +{ 0x00c0, 411 }, +{ 0x0530, 428 }, +{ 0x0d30, 444 }, +{ 0x0330, 460 }, +{ 0x0b30, 476 }, +{ 0x0160, 492 }, +{ 0x0960, 508 }, +{ 0x0560, 524 }, +{ 0x0d60, 540 }, +{ 0x04b0, 556 }, +{ 0x0cb0, 572 }, +{ 0x02b0, 588 }, +{ 0x0ab0, 604 }, +{ 0x06b0, 620 }, +{ 0x0eb0, 636 }, +{ 0x0360, 652 }, +{ 0x0b60, 668 }, +{ 0x05b0, 684 }, +{ 0x0db0, 700 }, +{ 0x02a0, 716 }, +{ 0x0aa0, 732 }, +{ 0x06a0, 748 }, +{ 0x0ea0, 764 }, +{ 0x0260, 780 }, +{ 0x0a60, 796 }, +{ 0x04a0, 812 }, +{ 0x0ca0, 828 }, +{ 0x0240, 844 }, +{ 0x0ec0, 860 }, +{ 0x01c0, 876 }, +{ 0x0e40, 892 }, +{ 0x0140, 908 }, +{ 0x01a0, 924 }, +{ 0x09a0, 940 }, +{ 0x0d40, 956 }, +{ 0x0340, 972 }, +{ 0x05a0, 988 }, +{ 0x0660, 1004 }, +{ 0x0e60, 1020 }, +{ 0, 0 } +}; + +static struct proto EOLH[] = { +{ 0x0000, 11 }, +{ 0, 0 } +}; + +static void +FillTable(TIFFFaxTabEnt *T, int Size, struct proto *P, int State) +{ + int limit = 1 << Size; + + while (P->val) { + int width = P->val & 15; + int param = P->val >> 4; + int incr = 1 << width; + int code; + for (code = P->code; code < limit; code += incr) { + TIFFFaxTabEnt *E = T+code; + E->State = State; + E->Width = width; + E->Param = param; + } + P++; + } +} + +static char* storage_class = ""; +static char* const_class = ""; +static int packoutput = 1; +static char* prebrace = ""; +static char* postbrace = ""; + +void +WriteTable(FILE* fd, const TIFFFaxTabEnt* T, int Size, const char* name) +{ + int i; + char* sep; + + fprintf(fd, "%s %s TIFFFaxTabEnt %s[%d] = {", + storage_class, const_class, name, Size); + if (packoutput) { + sep = "\n"; + for (i = 0; i < Size; i++) { + fprintf(fd, "%s%s%d,%d,%d%s", + sep, prebrace, T->State, T->Width, (int) T->Param, postbrace); + if (((i+1) % 10) == 0) + sep = ",\n"; + else + sep = ","; + T++; + } + } else { + sep = "\n "; + for (i = 0; i < Size; i++) { + fprintf(fd, "%s%s%3d,%3d,%4d%s", + sep, prebrace, T->State, T->Width, (int) T->Param, postbrace); + if (((i+1) % 6) == 0) + sep = ",\n "; + else + sep = ","; + T++; + } + } + fprintf(fd, "\n};\n"); +} + +/* initialise the huffman code tables */ +int +main(int argc, char* argv[]) +{ + FILE* fd; + char* outputfile; + int c; + extern int optind; + extern char* optarg; + + while ((c = getopt(argc, argv, "c:s:bp")) != -1) + switch (c) { + case 'c': + const_class = optarg; + break; + case 's': + storage_class = optarg; + break; + case 'p': + packoutput = 0; + break; + case 'b': + prebrace = "{"; + postbrace = "}"; + break; + case '?': + fprintf(stderr, + "usage: %s [-c const] [-s storage] [-p] [-b] file\n", + argv[0]); + return (-1); + } + outputfile = optind < argc ? argv[optind] : "g3states.h"; + fd = fopen(outputfile, "w"); + if (fd == NULL) { + fprintf(stderr, "%s: %s: Cannot create output file.\n", + argv[0], outputfile); + return (-2); + } + FillTable(MainTable, 7, Pass, S_Pass); + FillTable(MainTable, 7, Horiz, S_Horiz); + FillTable(MainTable, 7, V0, S_V0); + FillTable(MainTable, 7, VR, S_VR); + FillTable(MainTable, 7, VL, S_VL); + FillTable(MainTable, 7, Ext, S_Ext); + FillTable(MainTable, 7, EOLV, S_EOL); + FillTable(WhiteTable, 12, MakeUpW, S_MakeUpW); + FillTable(WhiteTable, 12, MakeUp, S_MakeUp); + FillTable(WhiteTable, 12, TermW, S_TermW); + FillTable(WhiteTable, 12, EOLH, S_EOL); + FillTable(BlackTable, 13, MakeUpB, S_MakeUpB); + FillTable(BlackTable, 13, MakeUp, S_MakeUp); + FillTable(BlackTable, 13, TermB, S_TermB); + FillTable(BlackTable, 13, EOLH, S_EOL); + + fprintf(fd, "/* WARNING, this file was automatically generated by the\n"); + fprintf(fd, " mkg3states program */\n"); + fprintf(fd, "#include \"tiff.h\"\n"); + fprintf(fd, "#include \"tif_fax3.h\"\n"); + WriteTable(fd, MainTable, 128, "TIFFFaxMainTable"); + WriteTable(fd, WhiteTable, 4096, "TIFFFaxWhiteTable"); + WriteTable(fd, BlackTable, 8192, "TIFFFaxBlackTable"); + fclose(fd); + return (0); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/mkspans.c b/Source/LibTIFF4/mkspans.c index 1806313..5789b19 100644 --- a/Source/LibTIFF4/mkspans.c +++ b/Source/LibTIFF4/mkspans.c @@ -1,82 +1,82 @@ -/* $Id: mkspans.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1991-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include -#include - -/* - * Hack program to construct tables used to find - * runs of zeros and ones in Group 3 Fax encoding. - */ - -dumparray(name, runs) - char *name; - unsigned char runs[256]; -{ - int i; - char *sep; - printf("static unsigned char %s[256] = {\n", name); - sep = " "; - for (i = 0; i < 256; i++) { - printf("%s%d", sep, runs[i]); - if (((i + 1) % 16) == 0) { - printf(", /* 0x%02x - 0x%02x */\n", i-15, i); - sep = " "; - } else - sep = ", "; - } - printf("\n};\n"); -} - -main() -{ - unsigned char runs[2][256]; - - memset(runs[0], 0, 256*sizeof (char)); - memset(runs[1], 0, 256*sizeof (char)); - { register int run, runlen, i; - runlen = 1; - for (run = 0x80; run != 0xff; run = (run>>1)|0x80) { - for (i = run-1; i >= 0; i--) { - runs[1][run|i] = runlen; - runs[0][(~(run|i)) & 0xff] = runlen; - } - runlen++; - } - runs[1][0xff] = runs[0][0] = 8; - } - dumparray("bruns", runs[0]); - dumparray("wruns", runs[1]); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: mkspans.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1991-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include + +/* + * Hack program to construct tables used to find + * runs of zeros and ones in Group 3 Fax encoding. + */ + +dumparray(name, runs) + char *name; + unsigned char runs[256]; +{ + int i; + char *sep; + printf("static unsigned char %s[256] = {\n", name); + sep = " "; + for (i = 0; i < 256; i++) { + printf("%s%d", sep, runs[i]); + if (((i + 1) % 16) == 0) { + printf(", /* 0x%02x - 0x%02x */\n", i-15, i); + sep = " "; + } else + sep = ", "; + } + printf("\n};\n"); +} + +main() +{ + unsigned char runs[2][256]; + + memset(runs[0], 0, 256*sizeof (char)); + memset(runs[1], 0, 256*sizeof (char)); + { register int run, runlen, i; + runlen = 1; + for (run = 0x80; run != 0xff; run = (run>>1)|0x80) { + for (i = run-1; i >= 0; i--) { + runs[1][run|i] = runlen; + runs[0][(~(run|i)) & 0xff] = runlen; + } + runlen++; + } + runs[1][0xff] = runs[0][0] = 8; + } + dumparray("bruns", runs[0]); + dumparray("wruns", runs[1]); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/t4.h b/Source/LibTIFF4/t4.h index 32023b0..dbad244 100644 --- a/Source/LibTIFF4/t4.h +++ b/Source/LibTIFF4/t4.h @@ -1,292 +1,292 @@ -/* $Id: t4.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifndef _T4_ -#define _T4_ -/* - * CCITT T.4 1D Huffman runlength codes and - * related definitions. Given the small sizes - * of these tables it does not seem - * worthwhile to make code & length 8 bits. - */ -typedef struct tableentry { - unsigned short length; /* bit length of g3 code */ - unsigned short code; /* g3 code */ - short runlen; /* run length in bits */ -} tableentry; - -#define EOL 0x001 /* EOL code value - 0000 0000 0000 1 */ - -/* status values returned instead of a run length */ -#define G3CODE_EOL -1 /* NB: ACT_EOL - ACT_WRUNT */ -#define G3CODE_INVALID -2 /* NB: ACT_INVALID - ACT_WRUNT */ -#define G3CODE_EOF -3 /* end of input data */ -#define G3CODE_INCOMP -4 /* incomplete run code */ - -/* - * Note that these tables are ordered such that the - * index into the table is known to be either the - * run length, or (run length / 64) + a fixed offset. - * - * NB: The G3CODE_INVALID entries are only used - * during state generation (see mkg3states.c). - */ -#ifdef G3CODES -const tableentry TIFFFaxWhiteCodes[] = { - { 8, 0x35, 0 }, /* 0011 0101 */ - { 6, 0x7, 1 }, /* 0001 11 */ - { 4, 0x7, 2 }, /* 0111 */ - { 4, 0x8, 3 }, /* 1000 */ - { 4, 0xB, 4 }, /* 1011 */ - { 4, 0xC, 5 }, /* 1100 */ - { 4, 0xE, 6 }, /* 1110 */ - { 4, 0xF, 7 }, /* 1111 */ - { 5, 0x13, 8 }, /* 1001 1 */ - { 5, 0x14, 9 }, /* 1010 0 */ - { 5, 0x7, 10 }, /* 0011 1 */ - { 5, 0x8, 11 }, /* 0100 0 */ - { 6, 0x8, 12 }, /* 0010 00 */ - { 6, 0x3, 13 }, /* 0000 11 */ - { 6, 0x34, 14 }, /* 1101 00 */ - { 6, 0x35, 15 }, /* 1101 01 */ - { 6, 0x2A, 16 }, /* 1010 10 */ - { 6, 0x2B, 17 }, /* 1010 11 */ - { 7, 0x27, 18 }, /* 0100 111 */ - { 7, 0xC, 19 }, /* 0001 100 */ - { 7, 0x8, 20 }, /* 0001 000 */ - { 7, 0x17, 21 }, /* 0010 111 */ - { 7, 0x3, 22 }, /* 0000 011 */ - { 7, 0x4, 23 }, /* 0000 100 */ - { 7, 0x28, 24 }, /* 0101 000 */ - { 7, 0x2B, 25 }, /* 0101 011 */ - { 7, 0x13, 26 }, /* 0010 011 */ - { 7, 0x24, 27 }, /* 0100 100 */ - { 7, 0x18, 28 }, /* 0011 000 */ - { 8, 0x2, 29 }, /* 0000 0010 */ - { 8, 0x3, 30 }, /* 0000 0011 */ - { 8, 0x1A, 31 }, /* 0001 1010 */ - { 8, 0x1B, 32 }, /* 0001 1011 */ - { 8, 0x12, 33 }, /* 0001 0010 */ - { 8, 0x13, 34 }, /* 0001 0011 */ - { 8, 0x14, 35 }, /* 0001 0100 */ - { 8, 0x15, 36 }, /* 0001 0101 */ - { 8, 0x16, 37 }, /* 0001 0110 */ - { 8, 0x17, 38 }, /* 0001 0111 */ - { 8, 0x28, 39 }, /* 0010 1000 */ - { 8, 0x29, 40 }, /* 0010 1001 */ - { 8, 0x2A, 41 }, /* 0010 1010 */ - { 8, 0x2B, 42 }, /* 0010 1011 */ - { 8, 0x2C, 43 }, /* 0010 1100 */ - { 8, 0x2D, 44 }, /* 0010 1101 */ - { 8, 0x4, 45 }, /* 0000 0100 */ - { 8, 0x5, 46 }, /* 0000 0101 */ - { 8, 0xA, 47 }, /* 0000 1010 */ - { 8, 0xB, 48 }, /* 0000 1011 */ - { 8, 0x52, 49 }, /* 0101 0010 */ - { 8, 0x53, 50 }, /* 0101 0011 */ - { 8, 0x54, 51 }, /* 0101 0100 */ - { 8, 0x55, 52 }, /* 0101 0101 */ - { 8, 0x24, 53 }, /* 0010 0100 */ - { 8, 0x25, 54 }, /* 0010 0101 */ - { 8, 0x58, 55 }, /* 0101 1000 */ - { 8, 0x59, 56 }, /* 0101 1001 */ - { 8, 0x5A, 57 }, /* 0101 1010 */ - { 8, 0x5B, 58 }, /* 0101 1011 */ - { 8, 0x4A, 59 }, /* 0100 1010 */ - { 8, 0x4B, 60 }, /* 0100 1011 */ - { 8, 0x32, 61 }, /* 0011 0010 */ - { 8, 0x33, 62 }, /* 0011 0011 */ - { 8, 0x34, 63 }, /* 0011 0100 */ - { 5, 0x1B, 64 }, /* 1101 1 */ - { 5, 0x12, 128 }, /* 1001 0 */ - { 6, 0x17, 192 }, /* 0101 11 */ - { 7, 0x37, 256 }, /* 0110 111 */ - { 8, 0x36, 320 }, /* 0011 0110 */ - { 8, 0x37, 384 }, /* 0011 0111 */ - { 8, 0x64, 448 }, /* 0110 0100 */ - { 8, 0x65, 512 }, /* 0110 0101 */ - { 8, 0x68, 576 }, /* 0110 1000 */ - { 8, 0x67, 640 }, /* 0110 0111 */ - { 9, 0xCC, 704 }, /* 0110 0110 0 */ - { 9, 0xCD, 768 }, /* 0110 0110 1 */ - { 9, 0xD2, 832 }, /* 0110 1001 0 */ - { 9, 0xD3, 896 }, /* 0110 1001 1 */ - { 9, 0xD4, 960 }, /* 0110 1010 0 */ - { 9, 0xD5, 1024 }, /* 0110 1010 1 */ - { 9, 0xD6, 1088 }, /* 0110 1011 0 */ - { 9, 0xD7, 1152 }, /* 0110 1011 1 */ - { 9, 0xD8, 1216 }, /* 0110 1100 0 */ - { 9, 0xD9, 1280 }, /* 0110 1100 1 */ - { 9, 0xDA, 1344 }, /* 0110 1101 0 */ - { 9, 0xDB, 1408 }, /* 0110 1101 1 */ - { 9, 0x98, 1472 }, /* 0100 1100 0 */ - { 9, 0x99, 1536 }, /* 0100 1100 1 */ - { 9, 0x9A, 1600 }, /* 0100 1101 0 */ - { 6, 0x18, 1664 }, /* 0110 00 */ - { 9, 0x9B, 1728 }, /* 0100 1101 1 */ - { 11, 0x8, 1792 }, /* 0000 0001 000 */ - { 11, 0xC, 1856 }, /* 0000 0001 100 */ - { 11, 0xD, 1920 }, /* 0000 0001 101 */ - { 12, 0x12, 1984 }, /* 0000 0001 0010 */ - { 12, 0x13, 2048 }, /* 0000 0001 0011 */ - { 12, 0x14, 2112 }, /* 0000 0001 0100 */ - { 12, 0x15, 2176 }, /* 0000 0001 0101 */ - { 12, 0x16, 2240 }, /* 0000 0001 0110 */ - { 12, 0x17, 2304 }, /* 0000 0001 0111 */ - { 12, 0x1C, 2368 }, /* 0000 0001 1100 */ - { 12, 0x1D, 2432 }, /* 0000 0001 1101 */ - { 12, 0x1E, 2496 }, /* 0000 0001 1110 */ - { 12, 0x1F, 2560 }, /* 0000 0001 1111 */ - { 12, 0x1, G3CODE_EOL }, /* 0000 0000 0001 */ - { 9, 0x1, G3CODE_INVALID }, /* 0000 0000 1 */ - { 10, 0x1, G3CODE_INVALID }, /* 0000 0000 01 */ - { 11, 0x1, G3CODE_INVALID }, /* 0000 0000 001 */ - { 12, 0x0, G3CODE_INVALID }, /* 0000 0000 0000 */ -}; - -const tableentry TIFFFaxBlackCodes[] = { - { 10, 0x37, 0 }, /* 0000 1101 11 */ - { 3, 0x2, 1 }, /* 010 */ - { 2, 0x3, 2 }, /* 11 */ - { 2, 0x2, 3 }, /* 10 */ - { 3, 0x3, 4 }, /* 011 */ - { 4, 0x3, 5 }, /* 0011 */ - { 4, 0x2, 6 }, /* 0010 */ - { 5, 0x3, 7 }, /* 0001 1 */ - { 6, 0x5, 8 }, /* 0001 01 */ - { 6, 0x4, 9 }, /* 0001 00 */ - { 7, 0x4, 10 }, /* 0000 100 */ - { 7, 0x5, 11 }, /* 0000 101 */ - { 7, 0x7, 12 }, /* 0000 111 */ - { 8, 0x4, 13 }, /* 0000 0100 */ - { 8, 0x7, 14 }, /* 0000 0111 */ - { 9, 0x18, 15 }, /* 0000 1100 0 */ - { 10, 0x17, 16 }, /* 0000 0101 11 */ - { 10, 0x18, 17 }, /* 0000 0110 00 */ - { 10, 0x8, 18 }, /* 0000 0010 00 */ - { 11, 0x67, 19 }, /* 0000 1100 111 */ - { 11, 0x68, 20 }, /* 0000 1101 000 */ - { 11, 0x6C, 21 }, /* 0000 1101 100 */ - { 11, 0x37, 22 }, /* 0000 0110 111 */ - { 11, 0x28, 23 }, /* 0000 0101 000 */ - { 11, 0x17, 24 }, /* 0000 0010 111 */ - { 11, 0x18, 25 }, /* 0000 0011 000 */ - { 12, 0xCA, 26 }, /* 0000 1100 1010 */ - { 12, 0xCB, 27 }, /* 0000 1100 1011 */ - { 12, 0xCC, 28 }, /* 0000 1100 1100 */ - { 12, 0xCD, 29 }, /* 0000 1100 1101 */ - { 12, 0x68, 30 }, /* 0000 0110 1000 */ - { 12, 0x69, 31 }, /* 0000 0110 1001 */ - { 12, 0x6A, 32 }, /* 0000 0110 1010 */ - { 12, 0x6B, 33 }, /* 0000 0110 1011 */ - { 12, 0xD2, 34 }, /* 0000 1101 0010 */ - { 12, 0xD3, 35 }, /* 0000 1101 0011 */ - { 12, 0xD4, 36 }, /* 0000 1101 0100 */ - { 12, 0xD5, 37 }, /* 0000 1101 0101 */ - { 12, 0xD6, 38 }, /* 0000 1101 0110 */ - { 12, 0xD7, 39 }, /* 0000 1101 0111 */ - { 12, 0x6C, 40 }, /* 0000 0110 1100 */ - { 12, 0x6D, 41 }, /* 0000 0110 1101 */ - { 12, 0xDA, 42 }, /* 0000 1101 1010 */ - { 12, 0xDB, 43 }, /* 0000 1101 1011 */ - { 12, 0x54, 44 }, /* 0000 0101 0100 */ - { 12, 0x55, 45 }, /* 0000 0101 0101 */ - { 12, 0x56, 46 }, /* 0000 0101 0110 */ - { 12, 0x57, 47 }, /* 0000 0101 0111 */ - { 12, 0x64, 48 }, /* 0000 0110 0100 */ - { 12, 0x65, 49 }, /* 0000 0110 0101 */ - { 12, 0x52, 50 }, /* 0000 0101 0010 */ - { 12, 0x53, 51 }, /* 0000 0101 0011 */ - { 12, 0x24, 52 }, /* 0000 0010 0100 */ - { 12, 0x37, 53 }, /* 0000 0011 0111 */ - { 12, 0x38, 54 }, /* 0000 0011 1000 */ - { 12, 0x27, 55 }, /* 0000 0010 0111 */ - { 12, 0x28, 56 }, /* 0000 0010 1000 */ - { 12, 0x58, 57 }, /* 0000 0101 1000 */ - { 12, 0x59, 58 }, /* 0000 0101 1001 */ - { 12, 0x2B, 59 }, /* 0000 0010 1011 */ - { 12, 0x2C, 60 }, /* 0000 0010 1100 */ - { 12, 0x5A, 61 }, /* 0000 0101 1010 */ - { 12, 0x66, 62 }, /* 0000 0110 0110 */ - { 12, 0x67, 63 }, /* 0000 0110 0111 */ - { 10, 0xF, 64 }, /* 0000 0011 11 */ - { 12, 0xC8, 128 }, /* 0000 1100 1000 */ - { 12, 0xC9, 192 }, /* 0000 1100 1001 */ - { 12, 0x5B, 256 }, /* 0000 0101 1011 */ - { 12, 0x33, 320 }, /* 0000 0011 0011 */ - { 12, 0x34, 384 }, /* 0000 0011 0100 */ - { 12, 0x35, 448 }, /* 0000 0011 0101 */ - { 13, 0x6C, 512 }, /* 0000 0011 0110 0 */ - { 13, 0x6D, 576 }, /* 0000 0011 0110 1 */ - { 13, 0x4A, 640 }, /* 0000 0010 0101 0 */ - { 13, 0x4B, 704 }, /* 0000 0010 0101 1 */ - { 13, 0x4C, 768 }, /* 0000 0010 0110 0 */ - { 13, 0x4D, 832 }, /* 0000 0010 0110 1 */ - { 13, 0x72, 896 }, /* 0000 0011 1001 0 */ - { 13, 0x73, 960 }, /* 0000 0011 1001 1 */ - { 13, 0x74, 1024 }, /* 0000 0011 1010 0 */ - { 13, 0x75, 1088 }, /* 0000 0011 1010 1 */ - { 13, 0x76, 1152 }, /* 0000 0011 1011 0 */ - { 13, 0x77, 1216 }, /* 0000 0011 1011 1 */ - { 13, 0x52, 1280 }, /* 0000 0010 1001 0 */ - { 13, 0x53, 1344 }, /* 0000 0010 1001 1 */ - { 13, 0x54, 1408 }, /* 0000 0010 1010 0 */ - { 13, 0x55, 1472 }, /* 0000 0010 1010 1 */ - { 13, 0x5A, 1536 }, /* 0000 0010 1101 0 */ - { 13, 0x5B, 1600 }, /* 0000 0010 1101 1 */ - { 13, 0x64, 1664 }, /* 0000 0011 0010 0 */ - { 13, 0x65, 1728 }, /* 0000 0011 0010 1 */ - { 11, 0x8, 1792 }, /* 0000 0001 000 */ - { 11, 0xC, 1856 }, /* 0000 0001 100 */ - { 11, 0xD, 1920 }, /* 0000 0001 101 */ - { 12, 0x12, 1984 }, /* 0000 0001 0010 */ - { 12, 0x13, 2048 }, /* 0000 0001 0011 */ - { 12, 0x14, 2112 }, /* 0000 0001 0100 */ - { 12, 0x15, 2176 }, /* 0000 0001 0101 */ - { 12, 0x16, 2240 }, /* 0000 0001 0110 */ - { 12, 0x17, 2304 }, /* 0000 0001 0111 */ - { 12, 0x1C, 2368 }, /* 0000 0001 1100 */ - { 12, 0x1D, 2432 }, /* 0000 0001 1101 */ - { 12, 0x1E, 2496 }, /* 0000 0001 1110 */ - { 12, 0x1F, 2560 }, /* 0000 0001 1111 */ - { 12, 0x1, G3CODE_EOL }, /* 0000 0000 0001 */ - { 9, 0x1, G3CODE_INVALID }, /* 0000 0000 1 */ - { 10, 0x1, G3CODE_INVALID }, /* 0000 0000 01 */ - { 11, 0x1, G3CODE_INVALID }, /* 0000 0000 001 */ - { 12, 0x0, G3CODE_INVALID }, /* 0000 0000 0000 */ -}; -#else -extern const tableentry TIFFFaxWhiteCodes[]; -extern const tableentry TIFFFaxBlackCodes[]; -#endif -#endif /* _T4_ */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: t4.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef _T4_ +#define _T4_ +/* + * CCITT T.4 1D Huffman runlength codes and + * related definitions. Given the small sizes + * of these tables it does not seem + * worthwhile to make code & length 8 bits. + */ +typedef struct tableentry { + unsigned short length; /* bit length of g3 code */ + unsigned short code; /* g3 code */ + short runlen; /* run length in bits */ +} tableentry; + +#define EOL 0x001 /* EOL code value - 0000 0000 0000 1 */ + +/* status values returned instead of a run length */ +#define G3CODE_EOL -1 /* NB: ACT_EOL - ACT_WRUNT */ +#define G3CODE_INVALID -2 /* NB: ACT_INVALID - ACT_WRUNT */ +#define G3CODE_EOF -3 /* end of input data */ +#define G3CODE_INCOMP -4 /* incomplete run code */ + +/* + * Note that these tables are ordered such that the + * index into the table is known to be either the + * run length, or (run length / 64) + a fixed offset. + * + * NB: The G3CODE_INVALID entries are only used + * during state generation (see mkg3states.c). + */ +#ifdef G3CODES +const tableentry TIFFFaxWhiteCodes[] = { + { 8, 0x35, 0 }, /* 0011 0101 */ + { 6, 0x7, 1 }, /* 0001 11 */ + { 4, 0x7, 2 }, /* 0111 */ + { 4, 0x8, 3 }, /* 1000 */ + { 4, 0xB, 4 }, /* 1011 */ + { 4, 0xC, 5 }, /* 1100 */ + { 4, 0xE, 6 }, /* 1110 */ + { 4, 0xF, 7 }, /* 1111 */ + { 5, 0x13, 8 }, /* 1001 1 */ + { 5, 0x14, 9 }, /* 1010 0 */ + { 5, 0x7, 10 }, /* 0011 1 */ + { 5, 0x8, 11 }, /* 0100 0 */ + { 6, 0x8, 12 }, /* 0010 00 */ + { 6, 0x3, 13 }, /* 0000 11 */ + { 6, 0x34, 14 }, /* 1101 00 */ + { 6, 0x35, 15 }, /* 1101 01 */ + { 6, 0x2A, 16 }, /* 1010 10 */ + { 6, 0x2B, 17 }, /* 1010 11 */ + { 7, 0x27, 18 }, /* 0100 111 */ + { 7, 0xC, 19 }, /* 0001 100 */ + { 7, 0x8, 20 }, /* 0001 000 */ + { 7, 0x17, 21 }, /* 0010 111 */ + { 7, 0x3, 22 }, /* 0000 011 */ + { 7, 0x4, 23 }, /* 0000 100 */ + { 7, 0x28, 24 }, /* 0101 000 */ + { 7, 0x2B, 25 }, /* 0101 011 */ + { 7, 0x13, 26 }, /* 0010 011 */ + { 7, 0x24, 27 }, /* 0100 100 */ + { 7, 0x18, 28 }, /* 0011 000 */ + { 8, 0x2, 29 }, /* 0000 0010 */ + { 8, 0x3, 30 }, /* 0000 0011 */ + { 8, 0x1A, 31 }, /* 0001 1010 */ + { 8, 0x1B, 32 }, /* 0001 1011 */ + { 8, 0x12, 33 }, /* 0001 0010 */ + { 8, 0x13, 34 }, /* 0001 0011 */ + { 8, 0x14, 35 }, /* 0001 0100 */ + { 8, 0x15, 36 }, /* 0001 0101 */ + { 8, 0x16, 37 }, /* 0001 0110 */ + { 8, 0x17, 38 }, /* 0001 0111 */ + { 8, 0x28, 39 }, /* 0010 1000 */ + { 8, 0x29, 40 }, /* 0010 1001 */ + { 8, 0x2A, 41 }, /* 0010 1010 */ + { 8, 0x2B, 42 }, /* 0010 1011 */ + { 8, 0x2C, 43 }, /* 0010 1100 */ + { 8, 0x2D, 44 }, /* 0010 1101 */ + { 8, 0x4, 45 }, /* 0000 0100 */ + { 8, 0x5, 46 }, /* 0000 0101 */ + { 8, 0xA, 47 }, /* 0000 1010 */ + { 8, 0xB, 48 }, /* 0000 1011 */ + { 8, 0x52, 49 }, /* 0101 0010 */ + { 8, 0x53, 50 }, /* 0101 0011 */ + { 8, 0x54, 51 }, /* 0101 0100 */ + { 8, 0x55, 52 }, /* 0101 0101 */ + { 8, 0x24, 53 }, /* 0010 0100 */ + { 8, 0x25, 54 }, /* 0010 0101 */ + { 8, 0x58, 55 }, /* 0101 1000 */ + { 8, 0x59, 56 }, /* 0101 1001 */ + { 8, 0x5A, 57 }, /* 0101 1010 */ + { 8, 0x5B, 58 }, /* 0101 1011 */ + { 8, 0x4A, 59 }, /* 0100 1010 */ + { 8, 0x4B, 60 }, /* 0100 1011 */ + { 8, 0x32, 61 }, /* 0011 0010 */ + { 8, 0x33, 62 }, /* 0011 0011 */ + { 8, 0x34, 63 }, /* 0011 0100 */ + { 5, 0x1B, 64 }, /* 1101 1 */ + { 5, 0x12, 128 }, /* 1001 0 */ + { 6, 0x17, 192 }, /* 0101 11 */ + { 7, 0x37, 256 }, /* 0110 111 */ + { 8, 0x36, 320 }, /* 0011 0110 */ + { 8, 0x37, 384 }, /* 0011 0111 */ + { 8, 0x64, 448 }, /* 0110 0100 */ + { 8, 0x65, 512 }, /* 0110 0101 */ + { 8, 0x68, 576 }, /* 0110 1000 */ + { 8, 0x67, 640 }, /* 0110 0111 */ + { 9, 0xCC, 704 }, /* 0110 0110 0 */ + { 9, 0xCD, 768 }, /* 0110 0110 1 */ + { 9, 0xD2, 832 }, /* 0110 1001 0 */ + { 9, 0xD3, 896 }, /* 0110 1001 1 */ + { 9, 0xD4, 960 }, /* 0110 1010 0 */ + { 9, 0xD5, 1024 }, /* 0110 1010 1 */ + { 9, 0xD6, 1088 }, /* 0110 1011 0 */ + { 9, 0xD7, 1152 }, /* 0110 1011 1 */ + { 9, 0xD8, 1216 }, /* 0110 1100 0 */ + { 9, 0xD9, 1280 }, /* 0110 1100 1 */ + { 9, 0xDA, 1344 }, /* 0110 1101 0 */ + { 9, 0xDB, 1408 }, /* 0110 1101 1 */ + { 9, 0x98, 1472 }, /* 0100 1100 0 */ + { 9, 0x99, 1536 }, /* 0100 1100 1 */ + { 9, 0x9A, 1600 }, /* 0100 1101 0 */ + { 6, 0x18, 1664 }, /* 0110 00 */ + { 9, 0x9B, 1728 }, /* 0100 1101 1 */ + { 11, 0x8, 1792 }, /* 0000 0001 000 */ + { 11, 0xC, 1856 }, /* 0000 0001 100 */ + { 11, 0xD, 1920 }, /* 0000 0001 101 */ + { 12, 0x12, 1984 }, /* 0000 0001 0010 */ + { 12, 0x13, 2048 }, /* 0000 0001 0011 */ + { 12, 0x14, 2112 }, /* 0000 0001 0100 */ + { 12, 0x15, 2176 }, /* 0000 0001 0101 */ + { 12, 0x16, 2240 }, /* 0000 0001 0110 */ + { 12, 0x17, 2304 }, /* 0000 0001 0111 */ + { 12, 0x1C, 2368 }, /* 0000 0001 1100 */ + { 12, 0x1D, 2432 }, /* 0000 0001 1101 */ + { 12, 0x1E, 2496 }, /* 0000 0001 1110 */ + { 12, 0x1F, 2560 }, /* 0000 0001 1111 */ + { 12, 0x1, G3CODE_EOL }, /* 0000 0000 0001 */ + { 9, 0x1, G3CODE_INVALID }, /* 0000 0000 1 */ + { 10, 0x1, G3CODE_INVALID }, /* 0000 0000 01 */ + { 11, 0x1, G3CODE_INVALID }, /* 0000 0000 001 */ + { 12, 0x0, G3CODE_INVALID }, /* 0000 0000 0000 */ +}; + +const tableentry TIFFFaxBlackCodes[] = { + { 10, 0x37, 0 }, /* 0000 1101 11 */ + { 3, 0x2, 1 }, /* 010 */ + { 2, 0x3, 2 }, /* 11 */ + { 2, 0x2, 3 }, /* 10 */ + { 3, 0x3, 4 }, /* 011 */ + { 4, 0x3, 5 }, /* 0011 */ + { 4, 0x2, 6 }, /* 0010 */ + { 5, 0x3, 7 }, /* 0001 1 */ + { 6, 0x5, 8 }, /* 0001 01 */ + { 6, 0x4, 9 }, /* 0001 00 */ + { 7, 0x4, 10 }, /* 0000 100 */ + { 7, 0x5, 11 }, /* 0000 101 */ + { 7, 0x7, 12 }, /* 0000 111 */ + { 8, 0x4, 13 }, /* 0000 0100 */ + { 8, 0x7, 14 }, /* 0000 0111 */ + { 9, 0x18, 15 }, /* 0000 1100 0 */ + { 10, 0x17, 16 }, /* 0000 0101 11 */ + { 10, 0x18, 17 }, /* 0000 0110 00 */ + { 10, 0x8, 18 }, /* 0000 0010 00 */ + { 11, 0x67, 19 }, /* 0000 1100 111 */ + { 11, 0x68, 20 }, /* 0000 1101 000 */ + { 11, 0x6C, 21 }, /* 0000 1101 100 */ + { 11, 0x37, 22 }, /* 0000 0110 111 */ + { 11, 0x28, 23 }, /* 0000 0101 000 */ + { 11, 0x17, 24 }, /* 0000 0010 111 */ + { 11, 0x18, 25 }, /* 0000 0011 000 */ + { 12, 0xCA, 26 }, /* 0000 1100 1010 */ + { 12, 0xCB, 27 }, /* 0000 1100 1011 */ + { 12, 0xCC, 28 }, /* 0000 1100 1100 */ + { 12, 0xCD, 29 }, /* 0000 1100 1101 */ + { 12, 0x68, 30 }, /* 0000 0110 1000 */ + { 12, 0x69, 31 }, /* 0000 0110 1001 */ + { 12, 0x6A, 32 }, /* 0000 0110 1010 */ + { 12, 0x6B, 33 }, /* 0000 0110 1011 */ + { 12, 0xD2, 34 }, /* 0000 1101 0010 */ + { 12, 0xD3, 35 }, /* 0000 1101 0011 */ + { 12, 0xD4, 36 }, /* 0000 1101 0100 */ + { 12, 0xD5, 37 }, /* 0000 1101 0101 */ + { 12, 0xD6, 38 }, /* 0000 1101 0110 */ + { 12, 0xD7, 39 }, /* 0000 1101 0111 */ + { 12, 0x6C, 40 }, /* 0000 0110 1100 */ + { 12, 0x6D, 41 }, /* 0000 0110 1101 */ + { 12, 0xDA, 42 }, /* 0000 1101 1010 */ + { 12, 0xDB, 43 }, /* 0000 1101 1011 */ + { 12, 0x54, 44 }, /* 0000 0101 0100 */ + { 12, 0x55, 45 }, /* 0000 0101 0101 */ + { 12, 0x56, 46 }, /* 0000 0101 0110 */ + { 12, 0x57, 47 }, /* 0000 0101 0111 */ + { 12, 0x64, 48 }, /* 0000 0110 0100 */ + { 12, 0x65, 49 }, /* 0000 0110 0101 */ + { 12, 0x52, 50 }, /* 0000 0101 0010 */ + { 12, 0x53, 51 }, /* 0000 0101 0011 */ + { 12, 0x24, 52 }, /* 0000 0010 0100 */ + { 12, 0x37, 53 }, /* 0000 0011 0111 */ + { 12, 0x38, 54 }, /* 0000 0011 1000 */ + { 12, 0x27, 55 }, /* 0000 0010 0111 */ + { 12, 0x28, 56 }, /* 0000 0010 1000 */ + { 12, 0x58, 57 }, /* 0000 0101 1000 */ + { 12, 0x59, 58 }, /* 0000 0101 1001 */ + { 12, 0x2B, 59 }, /* 0000 0010 1011 */ + { 12, 0x2C, 60 }, /* 0000 0010 1100 */ + { 12, 0x5A, 61 }, /* 0000 0101 1010 */ + { 12, 0x66, 62 }, /* 0000 0110 0110 */ + { 12, 0x67, 63 }, /* 0000 0110 0111 */ + { 10, 0xF, 64 }, /* 0000 0011 11 */ + { 12, 0xC8, 128 }, /* 0000 1100 1000 */ + { 12, 0xC9, 192 }, /* 0000 1100 1001 */ + { 12, 0x5B, 256 }, /* 0000 0101 1011 */ + { 12, 0x33, 320 }, /* 0000 0011 0011 */ + { 12, 0x34, 384 }, /* 0000 0011 0100 */ + { 12, 0x35, 448 }, /* 0000 0011 0101 */ + { 13, 0x6C, 512 }, /* 0000 0011 0110 0 */ + { 13, 0x6D, 576 }, /* 0000 0011 0110 1 */ + { 13, 0x4A, 640 }, /* 0000 0010 0101 0 */ + { 13, 0x4B, 704 }, /* 0000 0010 0101 1 */ + { 13, 0x4C, 768 }, /* 0000 0010 0110 0 */ + { 13, 0x4D, 832 }, /* 0000 0010 0110 1 */ + { 13, 0x72, 896 }, /* 0000 0011 1001 0 */ + { 13, 0x73, 960 }, /* 0000 0011 1001 1 */ + { 13, 0x74, 1024 }, /* 0000 0011 1010 0 */ + { 13, 0x75, 1088 }, /* 0000 0011 1010 1 */ + { 13, 0x76, 1152 }, /* 0000 0011 1011 0 */ + { 13, 0x77, 1216 }, /* 0000 0011 1011 1 */ + { 13, 0x52, 1280 }, /* 0000 0010 1001 0 */ + { 13, 0x53, 1344 }, /* 0000 0010 1001 1 */ + { 13, 0x54, 1408 }, /* 0000 0010 1010 0 */ + { 13, 0x55, 1472 }, /* 0000 0010 1010 1 */ + { 13, 0x5A, 1536 }, /* 0000 0010 1101 0 */ + { 13, 0x5B, 1600 }, /* 0000 0010 1101 1 */ + { 13, 0x64, 1664 }, /* 0000 0011 0010 0 */ + { 13, 0x65, 1728 }, /* 0000 0011 0010 1 */ + { 11, 0x8, 1792 }, /* 0000 0001 000 */ + { 11, 0xC, 1856 }, /* 0000 0001 100 */ + { 11, 0xD, 1920 }, /* 0000 0001 101 */ + { 12, 0x12, 1984 }, /* 0000 0001 0010 */ + { 12, 0x13, 2048 }, /* 0000 0001 0011 */ + { 12, 0x14, 2112 }, /* 0000 0001 0100 */ + { 12, 0x15, 2176 }, /* 0000 0001 0101 */ + { 12, 0x16, 2240 }, /* 0000 0001 0110 */ + { 12, 0x17, 2304 }, /* 0000 0001 0111 */ + { 12, 0x1C, 2368 }, /* 0000 0001 1100 */ + { 12, 0x1D, 2432 }, /* 0000 0001 1101 */ + { 12, 0x1E, 2496 }, /* 0000 0001 1110 */ + { 12, 0x1F, 2560 }, /* 0000 0001 1111 */ + { 12, 0x1, G3CODE_EOL }, /* 0000 0000 0001 */ + { 9, 0x1, G3CODE_INVALID }, /* 0000 0000 1 */ + { 10, 0x1, G3CODE_INVALID }, /* 0000 0000 01 */ + { 11, 0x1, G3CODE_INVALID }, /* 0000 0000 001 */ + { 12, 0x0, G3CODE_INVALID }, /* 0000 0000 0000 */ +}; +#else +extern const tableentry TIFFFaxWhiteCodes[]; +extern const tableentry TIFFFaxBlackCodes[]; +#endif +#endif /* _T4_ */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_aux.c b/Source/LibTIFF4/tif_aux.c index c80efff..b169b60 100644 --- a/Source/LibTIFF4/tif_aux.c +++ b/Source/LibTIFF4/tif_aux.c @@ -1,358 +1,358 @@ -/* $Id: tif_aux.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1991-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * - * Auxiliary Support Routines. - */ -#include "tiffiop.h" -#include "tif_predict.h" -#include - -uint32 -_TIFFMultiply32(TIFF* tif, uint32 first, uint32 second, const char* where) -{ - uint32 bytes = first * second; - - if (second && bytes / second != first) { - TIFFErrorExt(tif->tif_clientdata, where, "Integer overflow in %s", where); - bytes = 0; - } - - return bytes; -} - -uint64 -_TIFFMultiply64(TIFF* tif, uint64 first, uint64 second, const char* where) -{ - uint64 bytes = first * second; - - if (second && bytes / second != first) { - TIFFErrorExt(tif->tif_clientdata, where, "Integer overflow in %s", where); - bytes = 0; - } - - return bytes; -} - -void* -_TIFFCheckRealloc(TIFF* tif, void* buffer, - tmsize_t nmemb, tmsize_t elem_size, const char* what) -{ - void* cp = NULL; - tmsize_t bytes = nmemb * elem_size; - - /* - * XXX: Check for integer overflow. - */ - if (nmemb && elem_size && bytes / elem_size == nmemb) - cp = _TIFFrealloc(buffer, bytes); - - if (cp == NULL) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "Failed to allocate memory for %s " - "(%ld elements of %ld bytes each)", - what,(long) nmemb, (long) elem_size); - } - - return cp; -} - -void* -_TIFFCheckMalloc(TIFF* tif, tmsize_t nmemb, tmsize_t elem_size, const char* what) -{ - return _TIFFCheckRealloc(tif, NULL, nmemb, elem_size, what); -} - -static int -TIFFDefaultTransferFunction(TIFFDirectory* td) -{ - uint16 **tf = td->td_transferfunction; - tmsize_t i, n, nbytes; - - tf[0] = tf[1] = tf[2] = 0; - if (td->td_bitspersample >= sizeof(tmsize_t) * 8 - 2) - return 0; - - n = ((tmsize_t)1)<td_bitspersample; - nbytes = n * sizeof (uint16); - if (!(tf[0] = (uint16 *)_TIFFmalloc(nbytes))) - return 0; - tf[0][0] = 0; - for (i = 1; i < n; i++) { - double t = (double)i/((double) n-1.); - tf[0][i] = (uint16)floor(65535.*pow(t, 2.2) + .5); - } - - if (td->td_samplesperpixel - td->td_extrasamples > 1) { - if (!(tf[1] = (uint16 *)_TIFFmalloc(nbytes))) - goto bad; - _TIFFmemcpy(tf[1], tf[0], nbytes); - if (!(tf[2] = (uint16 *)_TIFFmalloc(nbytes))) - goto bad; - _TIFFmemcpy(tf[2], tf[0], nbytes); - } - return 1; - -bad: - if (tf[0]) - _TIFFfree(tf[0]); - if (tf[1]) - _TIFFfree(tf[1]); - if (tf[2]) - _TIFFfree(tf[2]); - tf[0] = tf[1] = tf[2] = 0; - return 0; -} - -static int -TIFFDefaultRefBlackWhite(TIFFDirectory* td) -{ - int i; - - if (!(td->td_refblackwhite = (float *)_TIFFmalloc(6*sizeof (float)))) - return 0; - if (td->td_photometric == PHOTOMETRIC_YCBCR) { - /* - * YCbCr (Class Y) images must have the ReferenceBlackWhite - * tag set. Fix the broken images, which lacks that tag. - */ - td->td_refblackwhite[0] = 0.0F; - td->td_refblackwhite[1] = td->td_refblackwhite[3] = - td->td_refblackwhite[5] = 255.0F; - td->td_refblackwhite[2] = td->td_refblackwhite[4] = 128.0F; - } else { - /* - * Assume RGB (Class R) - */ - for (i = 0; i < 3; i++) { - td->td_refblackwhite[2*i+0] = 0; - td->td_refblackwhite[2*i+1] = - (float)((1L<td_bitspersample)-1L); - } - } - return 1; -} - -/* - * Like TIFFGetField, but return any default - * value if the tag is not present in the directory. - * - * NB: We use the value in the directory, rather than - * explcit values so that defaults exist only one - * place in the library -- in TIFFDefaultDirectory. - */ -int -TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap) -{ - TIFFDirectory *td = &tif->tif_dir; - - if (TIFFVGetField(tif, tag, ap)) - return (1); - switch (tag) { - case TIFFTAG_SUBFILETYPE: - *va_arg(ap, uint32 *) = td->td_subfiletype; - return (1); - case TIFFTAG_BITSPERSAMPLE: - *va_arg(ap, uint16 *) = td->td_bitspersample; - return (1); - case TIFFTAG_THRESHHOLDING: - *va_arg(ap, uint16 *) = td->td_threshholding; - return (1); - case TIFFTAG_FILLORDER: - *va_arg(ap, uint16 *) = td->td_fillorder; - return (1); - case TIFFTAG_ORIENTATION: - *va_arg(ap, uint16 *) = td->td_orientation; - return (1); - case TIFFTAG_SAMPLESPERPIXEL: - *va_arg(ap, uint16 *) = td->td_samplesperpixel; - return (1); - case TIFFTAG_ROWSPERSTRIP: - *va_arg(ap, uint32 *) = td->td_rowsperstrip; - return (1); - case TIFFTAG_MINSAMPLEVALUE: - *va_arg(ap, uint16 *) = td->td_minsamplevalue; - return (1); - case TIFFTAG_MAXSAMPLEVALUE: - *va_arg(ap, uint16 *) = td->td_maxsamplevalue; - return (1); - case TIFFTAG_PLANARCONFIG: - *va_arg(ap, uint16 *) = td->td_planarconfig; - return (1); - case TIFFTAG_RESOLUTIONUNIT: - *va_arg(ap, uint16 *) = td->td_resolutionunit; - return (1); - case TIFFTAG_PREDICTOR: - { - TIFFPredictorState* sp = (TIFFPredictorState*) tif->tif_data; - *va_arg(ap, uint16*) = (uint16) sp->predictor; - return 1; - } - case TIFFTAG_DOTRANGE: - *va_arg(ap, uint16 *) = 0; - *va_arg(ap, uint16 *) = (1<td_bitspersample)-1; - return (1); - case TIFFTAG_INKSET: - *va_arg(ap, uint16 *) = INKSET_CMYK; - return 1; - case TIFFTAG_NUMBEROFINKS: - *va_arg(ap, uint16 *) = 4; - return (1); - case TIFFTAG_EXTRASAMPLES: - *va_arg(ap, uint16 *) = td->td_extrasamples; - *va_arg(ap, uint16 **) = td->td_sampleinfo; - return (1); - case TIFFTAG_MATTEING: - *va_arg(ap, uint16 *) = - (td->td_extrasamples == 1 && - td->td_sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA); - return (1); - case TIFFTAG_TILEDEPTH: - *va_arg(ap, uint32 *) = td->td_tiledepth; - return (1); - case TIFFTAG_DATATYPE: - *va_arg(ap, uint16 *) = td->td_sampleformat-1; - return (1); - case TIFFTAG_SAMPLEFORMAT: - *va_arg(ap, uint16 *) = td->td_sampleformat; - return(1); - case TIFFTAG_IMAGEDEPTH: - *va_arg(ap, uint32 *) = td->td_imagedepth; - return (1); - case TIFFTAG_YCBCRCOEFFICIENTS: - { - /* defaults are from CCIR Recommendation 601-1 */ - static float ycbcrcoeffs[] = { 0.299f, 0.587f, 0.114f }; - *va_arg(ap, float **) = ycbcrcoeffs; - return 1; - } - case TIFFTAG_YCBCRSUBSAMPLING: - *va_arg(ap, uint16 *) = td->td_ycbcrsubsampling[0]; - *va_arg(ap, uint16 *) = td->td_ycbcrsubsampling[1]; - return (1); - case TIFFTAG_YCBCRPOSITIONING: - *va_arg(ap, uint16 *) = td->td_ycbcrpositioning; - return (1); - case TIFFTAG_WHITEPOINT: - { - static float whitepoint[2]; - - /* TIFF 6.0 specification tells that it is no default - value for the WhitePoint, but AdobePhotoshop TIFF - Technical Note tells that it should be CIE D50. */ - whitepoint[0] = D50_X0 / (D50_X0 + D50_Y0 + D50_Z0); - whitepoint[1] = D50_Y0 / (D50_X0 + D50_Y0 + D50_Z0); - *va_arg(ap, float **) = whitepoint; - return 1; - } - case TIFFTAG_TRANSFERFUNCTION: - if (!td->td_transferfunction[0] && - !TIFFDefaultTransferFunction(td)) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "No space for \"TransferFunction\" tag"); - return (0); - } - *va_arg(ap, uint16 **) = td->td_transferfunction[0]; - if (td->td_samplesperpixel - td->td_extrasamples > 1) { - *va_arg(ap, uint16 **) = td->td_transferfunction[1]; - *va_arg(ap, uint16 **) = td->td_transferfunction[2]; - } - return (1); - case TIFFTAG_REFERENCEBLACKWHITE: - if (!td->td_refblackwhite && !TIFFDefaultRefBlackWhite(td)) - return (0); - *va_arg(ap, float **) = td->td_refblackwhite; - return (1); - } - return 0; -} - -/* - * Like TIFFGetField, but return any default - * value if the tag is not present in the directory. - */ -int -TIFFGetFieldDefaulted(TIFF* tif, uint32 tag, ...) -{ - int ok; - va_list ap; - - va_start(ap, tag); - ok = TIFFVGetFieldDefaulted(tif, tag, ap); - va_end(ap); - return (ok); -} - -struct _Int64Parts { - int32 low, high; -}; - -typedef union { - struct _Int64Parts part; - int64 value; -} _Int64; - -float -_TIFFUInt64ToFloat(uint64 ui64) -{ - _Int64 i; - - i.value = ui64; - if (i.part.high >= 0) { - return (float)i.value; - } else { - long double df; - df = (long double)i.value; - df += 18446744073709551616.0; /* adding 2**64 */ - return (float)df; - } -} - -double -_TIFFUInt64ToDouble(uint64 ui64) -{ - _Int64 i; - - i.value = ui64; - if (i.part.high >= 0) { - return (double)i.value; - } else { - long double df; - df = (long double)i.value; - df += 18446744073709551616.0; /* adding 2**64 */ - return (double)df; - } -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_aux.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1991-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * + * Auxiliary Support Routines. + */ +#include "tiffiop.h" +#include "tif_predict.h" +#include + +uint32 +_TIFFMultiply32(TIFF* tif, uint32 first, uint32 second, const char* where) +{ + uint32 bytes = first * second; + + if (second && bytes / second != first) { + TIFFErrorExt(tif->tif_clientdata, where, "Integer overflow in %s", where); + bytes = 0; + } + + return bytes; +} + +uint64 +_TIFFMultiply64(TIFF* tif, uint64 first, uint64 second, const char* where) +{ + uint64 bytes = first * second; + + if (second && bytes / second != first) { + TIFFErrorExt(tif->tif_clientdata, where, "Integer overflow in %s", where); + bytes = 0; + } + + return bytes; +} + +void* +_TIFFCheckRealloc(TIFF* tif, void* buffer, + tmsize_t nmemb, tmsize_t elem_size, const char* what) +{ + void* cp = NULL; + tmsize_t bytes = nmemb * elem_size; + + /* + * XXX: Check for integer overflow. + */ + if (nmemb && elem_size && bytes / elem_size == nmemb) + cp = _TIFFrealloc(buffer, bytes); + + if (cp == NULL) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "Failed to allocate memory for %s " + "(%ld elements of %ld bytes each)", + what,(long) nmemb, (long) elem_size); + } + + return cp; +} + +void* +_TIFFCheckMalloc(TIFF* tif, tmsize_t nmemb, tmsize_t elem_size, const char* what) +{ + return _TIFFCheckRealloc(tif, NULL, nmemb, elem_size, what); +} + +static int +TIFFDefaultTransferFunction(TIFFDirectory* td) +{ + uint16 **tf = td->td_transferfunction; + tmsize_t i, n, nbytes; + + tf[0] = tf[1] = tf[2] = 0; + if (td->td_bitspersample >= sizeof(tmsize_t) * 8 - 2) + return 0; + + n = ((tmsize_t)1)<td_bitspersample; + nbytes = n * sizeof (uint16); + if (!(tf[0] = (uint16 *)_TIFFmalloc(nbytes))) + return 0; + tf[0][0] = 0; + for (i = 1; i < n; i++) { + double t = (double)i/((double) n-1.); + tf[0][i] = (uint16)floor(65535.*pow(t, 2.2) + .5); + } + + if (td->td_samplesperpixel - td->td_extrasamples > 1) { + if (!(tf[1] = (uint16 *)_TIFFmalloc(nbytes))) + goto bad; + _TIFFmemcpy(tf[1], tf[0], nbytes); + if (!(tf[2] = (uint16 *)_TIFFmalloc(nbytes))) + goto bad; + _TIFFmemcpy(tf[2], tf[0], nbytes); + } + return 1; + +bad: + if (tf[0]) + _TIFFfree(tf[0]); + if (tf[1]) + _TIFFfree(tf[1]); + if (tf[2]) + _TIFFfree(tf[2]); + tf[0] = tf[1] = tf[2] = 0; + return 0; +} + +static int +TIFFDefaultRefBlackWhite(TIFFDirectory* td) +{ + int i; + + if (!(td->td_refblackwhite = (float *)_TIFFmalloc(6*sizeof (float)))) + return 0; + if (td->td_photometric == PHOTOMETRIC_YCBCR) { + /* + * YCbCr (Class Y) images must have the ReferenceBlackWhite + * tag set. Fix the broken images, which lacks that tag. + */ + td->td_refblackwhite[0] = 0.0F; + td->td_refblackwhite[1] = td->td_refblackwhite[3] = + td->td_refblackwhite[5] = 255.0F; + td->td_refblackwhite[2] = td->td_refblackwhite[4] = 128.0F; + } else { + /* + * Assume RGB (Class R) + */ + for (i = 0; i < 3; i++) { + td->td_refblackwhite[2*i+0] = 0; + td->td_refblackwhite[2*i+1] = + (float)((1L<td_bitspersample)-1L); + } + } + return 1; +} + +/* + * Like TIFFGetField, but return any default + * value if the tag is not present in the directory. + * + * NB: We use the value in the directory, rather than + * explcit values so that defaults exist only one + * place in the library -- in TIFFDefaultDirectory. + */ +int +TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap) +{ + TIFFDirectory *td = &tif->tif_dir; + + if (TIFFVGetField(tif, tag, ap)) + return (1); + switch (tag) { + case TIFFTAG_SUBFILETYPE: + *va_arg(ap, uint32 *) = td->td_subfiletype; + return (1); + case TIFFTAG_BITSPERSAMPLE: + *va_arg(ap, uint16 *) = td->td_bitspersample; + return (1); + case TIFFTAG_THRESHHOLDING: + *va_arg(ap, uint16 *) = td->td_threshholding; + return (1); + case TIFFTAG_FILLORDER: + *va_arg(ap, uint16 *) = td->td_fillorder; + return (1); + case TIFFTAG_ORIENTATION: + *va_arg(ap, uint16 *) = td->td_orientation; + return (1); + case TIFFTAG_SAMPLESPERPIXEL: + *va_arg(ap, uint16 *) = td->td_samplesperpixel; + return (1); + case TIFFTAG_ROWSPERSTRIP: + *va_arg(ap, uint32 *) = td->td_rowsperstrip; + return (1); + case TIFFTAG_MINSAMPLEVALUE: + *va_arg(ap, uint16 *) = td->td_minsamplevalue; + return (1); + case TIFFTAG_MAXSAMPLEVALUE: + *va_arg(ap, uint16 *) = td->td_maxsamplevalue; + return (1); + case TIFFTAG_PLANARCONFIG: + *va_arg(ap, uint16 *) = td->td_planarconfig; + return (1); + case TIFFTAG_RESOLUTIONUNIT: + *va_arg(ap, uint16 *) = td->td_resolutionunit; + return (1); + case TIFFTAG_PREDICTOR: + { + TIFFPredictorState* sp = (TIFFPredictorState*) tif->tif_data; + *va_arg(ap, uint16*) = (uint16) sp->predictor; + return 1; + } + case TIFFTAG_DOTRANGE: + *va_arg(ap, uint16 *) = 0; + *va_arg(ap, uint16 *) = (1<td_bitspersample)-1; + return (1); + case TIFFTAG_INKSET: + *va_arg(ap, uint16 *) = INKSET_CMYK; + return 1; + case TIFFTAG_NUMBEROFINKS: + *va_arg(ap, uint16 *) = 4; + return (1); + case TIFFTAG_EXTRASAMPLES: + *va_arg(ap, uint16 *) = td->td_extrasamples; + *va_arg(ap, uint16 **) = td->td_sampleinfo; + return (1); + case TIFFTAG_MATTEING: + *va_arg(ap, uint16 *) = + (td->td_extrasamples == 1 && + td->td_sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA); + return (1); + case TIFFTAG_TILEDEPTH: + *va_arg(ap, uint32 *) = td->td_tiledepth; + return (1); + case TIFFTAG_DATATYPE: + *va_arg(ap, uint16 *) = td->td_sampleformat-1; + return (1); + case TIFFTAG_SAMPLEFORMAT: + *va_arg(ap, uint16 *) = td->td_sampleformat; + return(1); + case TIFFTAG_IMAGEDEPTH: + *va_arg(ap, uint32 *) = td->td_imagedepth; + return (1); + case TIFFTAG_YCBCRCOEFFICIENTS: + { + /* defaults are from CCIR Recommendation 601-1 */ + static float ycbcrcoeffs[] = { 0.299f, 0.587f, 0.114f }; + *va_arg(ap, float **) = ycbcrcoeffs; + return 1; + } + case TIFFTAG_YCBCRSUBSAMPLING: + *va_arg(ap, uint16 *) = td->td_ycbcrsubsampling[0]; + *va_arg(ap, uint16 *) = td->td_ycbcrsubsampling[1]; + return (1); + case TIFFTAG_YCBCRPOSITIONING: + *va_arg(ap, uint16 *) = td->td_ycbcrpositioning; + return (1); + case TIFFTAG_WHITEPOINT: + { + static float whitepoint[2]; + + /* TIFF 6.0 specification tells that it is no default + value for the WhitePoint, but AdobePhotoshop TIFF + Technical Note tells that it should be CIE D50. */ + whitepoint[0] = D50_X0 / (D50_X0 + D50_Y0 + D50_Z0); + whitepoint[1] = D50_Y0 / (D50_X0 + D50_Y0 + D50_Z0); + *va_arg(ap, float **) = whitepoint; + return 1; + } + case TIFFTAG_TRANSFERFUNCTION: + if (!td->td_transferfunction[0] && + !TIFFDefaultTransferFunction(td)) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "No space for \"TransferFunction\" tag"); + return (0); + } + *va_arg(ap, uint16 **) = td->td_transferfunction[0]; + if (td->td_samplesperpixel - td->td_extrasamples > 1) { + *va_arg(ap, uint16 **) = td->td_transferfunction[1]; + *va_arg(ap, uint16 **) = td->td_transferfunction[2]; + } + return (1); + case TIFFTAG_REFERENCEBLACKWHITE: + if (!td->td_refblackwhite && !TIFFDefaultRefBlackWhite(td)) + return (0); + *va_arg(ap, float **) = td->td_refblackwhite; + return (1); + } + return 0; +} + +/* + * Like TIFFGetField, but return any default + * value if the tag is not present in the directory. + */ +int +TIFFGetFieldDefaulted(TIFF* tif, uint32 tag, ...) +{ + int ok; + va_list ap; + + va_start(ap, tag); + ok = TIFFVGetFieldDefaulted(tif, tag, ap); + va_end(ap); + return (ok); +} + +struct _Int64Parts { + int32 low, high; +}; + +typedef union { + struct _Int64Parts part; + int64 value; +} _Int64; + +float +_TIFFUInt64ToFloat(uint64 ui64) +{ + _Int64 i; + + i.value = ui64; + if (i.part.high >= 0) { + return (float)i.value; + } else { + long double df; + df = (long double)i.value; + df += 18446744073709551616.0; /* adding 2**64 */ + return (float)df; + } +} + +double +_TIFFUInt64ToDouble(uint64 ui64) +{ + _Int64 i; + + i.value = ui64; + if (i.part.high >= 0) { + return (double)i.value; + } else { + long double df; + df = (long double)i.value; + df += 18446744073709551616.0; /* adding 2**64 */ + return (double)df; + } +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_close.c b/Source/LibTIFF4/tif_close.c index fb67a96..b1394b5 100644 --- a/Source/LibTIFF4/tif_close.c +++ b/Source/LibTIFF4/tif_close.c @@ -1,140 +1,140 @@ -/* $Id: tif_close.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - */ -#include "tiffiop.h" -#include - -/************************************************************************/ -/* TIFFCleanup() */ -/************************************************************************/ - -/** - * Auxiliary function to free the TIFF structure. Given structure will be - * completetly freed, so you should save opened file handle and pointer - * to the close procedure in external variables before calling - * _TIFFCleanup(), if you will need these ones to close the file. - * - * @param tif A TIFF pointer. - */ - -void -TIFFCleanup(TIFF* tif) -{ - /* - * Flush buffered data and directory (if dirty). - */ - if (tif->tif_mode != O_RDONLY) - TIFFFlush(tif); - (*tif->tif_cleanup)(tif); - TIFFFreeDirectory(tif); - - if (tif->tif_dirlist) - _TIFFfree(tif->tif_dirlist); - - /* - * Clean up client info links. - */ - while( tif->tif_clientinfo ) - { - TIFFClientInfoLink *link = tif->tif_clientinfo; - - tif->tif_clientinfo = link->next; - _TIFFfree( link->name ); - _TIFFfree( link ); - } - - if (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER)) - _TIFFfree(tif->tif_rawdata); - if (isMapped(tif)) - TIFFUnmapFileContents(tif, tif->tif_base, (toff_t)tif->tif_size); - - /* - * Clean up custom fields. - */ - if (tif->tif_fields && tif->tif_nfields > 0) { - uint32 i; - - for (i = 0; i < tif->tif_nfields; i++) { - TIFFField *fld = tif->tif_fields[i]; - if (fld->field_bit == FIELD_CUSTOM && - strncmp("Tag ", fld->field_name, 4) == 0) { - _TIFFfree(fld->field_name); - _TIFFfree(fld); - } - } - - _TIFFfree(tif->tif_fields); - } - - if (tif->tif_nfieldscompat > 0) { - uint32 i; - - for (i = 0; i < tif->tif_nfieldscompat; i++) { - if (tif->tif_fieldscompat[i].allocated_size) - _TIFFfree(tif->tif_fieldscompat[i].fields); - } - _TIFFfree(tif->tif_fieldscompat); - } - - _TIFFfree(tif); -} - -/************************************************************************/ -/* TIFFClose() */ -/************************************************************************/ - -/** - * Close a previously opened TIFF file. - * - * TIFFClose closes a file that was previously opened with TIFFOpen(). - * Any buffered data are flushed to the file, including the contents of - * the current directory (if modified); and all resources are reclaimed. - * - * @param tif A TIFF pointer. - */ - -void -TIFFClose(TIFF* tif) -{ - TIFFCloseProc closeproc = tif->tif_closeproc; - thandle_t fd = tif->tif_clientdata; - - TIFFCleanup(tif); - (void) (*closeproc)(fd); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ - -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_close.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + */ +#include "tiffiop.h" +#include + +/************************************************************************/ +/* TIFFCleanup() */ +/************************************************************************/ + +/** + * Auxiliary function to free the TIFF structure. Given structure will be + * completetly freed, so you should save opened file handle and pointer + * to the close procedure in external variables before calling + * _TIFFCleanup(), if you will need these ones to close the file. + * + * @param tif A TIFF pointer. + */ + +void +TIFFCleanup(TIFF* tif) +{ + /* + * Flush buffered data and directory (if dirty). + */ + if (tif->tif_mode != O_RDONLY) + TIFFFlush(tif); + (*tif->tif_cleanup)(tif); + TIFFFreeDirectory(tif); + + if (tif->tif_dirlist) + _TIFFfree(tif->tif_dirlist); + + /* + * Clean up client info links. + */ + while( tif->tif_clientinfo ) + { + TIFFClientInfoLink *link = tif->tif_clientinfo; + + tif->tif_clientinfo = link->next; + _TIFFfree( link->name ); + _TIFFfree( link ); + } + + if (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER)) + _TIFFfree(tif->tif_rawdata); + if (isMapped(tif)) + TIFFUnmapFileContents(tif, tif->tif_base, (toff_t)tif->tif_size); + + /* + * Clean up custom fields. + */ + if (tif->tif_fields && tif->tif_nfields > 0) { + uint32 i; + + for (i = 0; i < tif->tif_nfields; i++) { + TIFFField *fld = tif->tif_fields[i]; + if (fld->field_bit == FIELD_CUSTOM && + strncmp("Tag ", fld->field_name, 4) == 0) { + _TIFFfree(fld->field_name); + _TIFFfree(fld); + } + } + + _TIFFfree(tif->tif_fields); + } + + if (tif->tif_nfieldscompat > 0) { + uint32 i; + + for (i = 0; i < tif->tif_nfieldscompat; i++) { + if (tif->tif_fieldscompat[i].allocated_size) + _TIFFfree(tif->tif_fieldscompat[i].fields); + } + _TIFFfree(tif->tif_fieldscompat); + } + + _TIFFfree(tif); +} + +/************************************************************************/ +/* TIFFClose() */ +/************************************************************************/ + +/** + * Close a previously opened TIFF file. + * + * TIFFClose closes a file that was previously opened with TIFFOpen(). + * Any buffered data are flushed to the file, including the contents of + * the current directory (if modified); and all resources are reclaimed. + * + * @param tif A TIFF pointer. + */ + +void +TIFFClose(TIFF* tif) +{ + TIFFCloseProc closeproc = tif->tif_closeproc; + thandle_t fd = tif->tif_clientdata; + + TIFFCleanup(tif); + (void) (*closeproc)(fd); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ + +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_codec.c b/Source/LibTIFF4/tif_codec.c index ee360a8..285d6e3 100644 --- a/Source/LibTIFF4/tif_codec.c +++ b/Source/LibTIFF4/tif_codec.c @@ -1,165 +1,165 @@ -/* $Id: tif_codec.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library - * - * Builtin Compression Scheme Configuration Support. - */ -#include "tiffiop.h" - -static int NotConfigured(TIFF*, int); - -#ifndef LZW_SUPPORT -#define TIFFInitLZW NotConfigured -#endif -#ifndef PACKBITS_SUPPORT -#define TIFFInitPackBits NotConfigured -#endif -#ifndef THUNDER_SUPPORT -#define TIFFInitThunderScan NotConfigured -#endif -#ifndef NEXT_SUPPORT -#define TIFFInitNeXT NotConfigured -#endif -#ifndef JPEG_SUPPORT -#define TIFFInitJPEG NotConfigured -#endif -#ifndef OJPEG_SUPPORT -#define TIFFInitOJPEG NotConfigured -#endif -#ifndef CCITT_SUPPORT -#define TIFFInitCCITTRLE NotConfigured -#define TIFFInitCCITTRLEW NotConfigured -#define TIFFInitCCITTFax3 NotConfigured -#define TIFFInitCCITTFax4 NotConfigured -#endif -#ifndef JBIG_SUPPORT -#define TIFFInitJBIG NotConfigured -#endif -#ifndef ZIP_SUPPORT -#define TIFFInitZIP NotConfigured -#endif -#ifndef PIXARLOG_SUPPORT -#define TIFFInitPixarLog NotConfigured -#endif -#ifndef LOGLUV_SUPPORT -#define TIFFInitSGILog NotConfigured -#endif -#ifndef LZMA_SUPPORT -#define TIFFInitLZMA NotConfigured -#endif - -/* - * Compression schemes statically built into the library. - */ -#ifdef VMS -const TIFFCodec _TIFFBuiltinCODECS[] = { -#else -TIFFCodec _TIFFBuiltinCODECS[] = { -#endif - { "None", COMPRESSION_NONE, TIFFInitDumpMode }, - { "LZW", COMPRESSION_LZW, TIFFInitLZW }, - { "PackBits", COMPRESSION_PACKBITS, TIFFInitPackBits }, - { "ThunderScan", COMPRESSION_THUNDERSCAN,TIFFInitThunderScan }, - { "NeXT", COMPRESSION_NEXT, TIFFInitNeXT }, - { "JPEG", COMPRESSION_JPEG, TIFFInitJPEG }, - { "Old-style JPEG", COMPRESSION_OJPEG, TIFFInitOJPEG }, - { "CCITT RLE", COMPRESSION_CCITTRLE, TIFFInitCCITTRLE }, - { "CCITT RLE/W", COMPRESSION_CCITTRLEW, TIFFInitCCITTRLEW }, - { "CCITT Group 3", COMPRESSION_CCITTFAX3, TIFFInitCCITTFax3 }, - { "CCITT Group 4", COMPRESSION_CCITTFAX4, TIFFInitCCITTFax4 }, - { "ISO JBIG", COMPRESSION_JBIG, TIFFInitJBIG }, - { "Deflate", COMPRESSION_DEFLATE, TIFFInitZIP }, - { "AdobeDeflate", COMPRESSION_ADOBE_DEFLATE , TIFFInitZIP }, - { "PixarLog", COMPRESSION_PIXARLOG, TIFFInitPixarLog }, - { "SGILog", COMPRESSION_SGILOG, TIFFInitSGILog }, - { "SGILog24", COMPRESSION_SGILOG24, TIFFInitSGILog }, - { "LZMA", COMPRESSION_LZMA, TIFFInitLZMA }, - { NULL, 0, NULL } -}; - -static int -_notConfigured(TIFF* tif) -{ - const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression); - char compression_code[20]; - - sprintf( compression_code, "%d", tif->tif_dir.td_compression ); - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "%s compression support is not configured", - c ? c->name : compression_code ); - return (0); -} - -static int -NotConfigured(TIFF* tif, int scheme) -{ - (void) scheme; - - tif->tif_fixuptags = _notConfigured; - tif->tif_decodestatus = FALSE; - tif->tif_setupdecode = _notConfigured; - tif->tif_encodestatus = FALSE; - tif->tif_setupencode = _notConfigured; - return (1); -} - -/************************************************************************/ -/* TIFFIsCODECConfigured() */ -/************************************************************************/ - -/** - * Check whether we have working codec for the specific coding scheme. - * - * @return returns 1 if the codec is configured and working. Otherwise - * 0 will be returned. - */ - -int -TIFFIsCODECConfigured(uint16 scheme) -{ - const TIFFCodec* codec = TIFFFindCODEC(scheme); - - if(codec == NULL) { - return 0; - } - if(codec->init == NULL) { - return 0; - } - if(codec->init != NotConfigured){ - return 1; - } - return 0; -} - -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_codec.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library + * + * Builtin Compression Scheme Configuration Support. + */ +#include "tiffiop.h" + +static int NotConfigured(TIFF*, int); + +#ifndef LZW_SUPPORT +#define TIFFInitLZW NotConfigured +#endif +#ifndef PACKBITS_SUPPORT +#define TIFFInitPackBits NotConfigured +#endif +#ifndef THUNDER_SUPPORT +#define TIFFInitThunderScan NotConfigured +#endif +#ifndef NEXT_SUPPORT +#define TIFFInitNeXT NotConfigured +#endif +#ifndef JPEG_SUPPORT +#define TIFFInitJPEG NotConfigured +#endif +#ifndef OJPEG_SUPPORT +#define TIFFInitOJPEG NotConfigured +#endif +#ifndef CCITT_SUPPORT +#define TIFFInitCCITTRLE NotConfigured +#define TIFFInitCCITTRLEW NotConfigured +#define TIFFInitCCITTFax3 NotConfigured +#define TIFFInitCCITTFax4 NotConfigured +#endif +#ifndef JBIG_SUPPORT +#define TIFFInitJBIG NotConfigured +#endif +#ifndef ZIP_SUPPORT +#define TIFFInitZIP NotConfigured +#endif +#ifndef PIXARLOG_SUPPORT +#define TIFFInitPixarLog NotConfigured +#endif +#ifndef LOGLUV_SUPPORT +#define TIFFInitSGILog NotConfigured +#endif +#ifndef LZMA_SUPPORT +#define TIFFInitLZMA NotConfigured +#endif + +/* + * Compression schemes statically built into the library. + */ +#ifdef VMS +const TIFFCodec _TIFFBuiltinCODECS[] = { +#else +TIFFCodec _TIFFBuiltinCODECS[] = { +#endif + { "None", COMPRESSION_NONE, TIFFInitDumpMode }, + { "LZW", COMPRESSION_LZW, TIFFInitLZW }, + { "PackBits", COMPRESSION_PACKBITS, TIFFInitPackBits }, + { "ThunderScan", COMPRESSION_THUNDERSCAN,TIFFInitThunderScan }, + { "NeXT", COMPRESSION_NEXT, TIFFInitNeXT }, + { "JPEG", COMPRESSION_JPEG, TIFFInitJPEG }, + { "Old-style JPEG", COMPRESSION_OJPEG, TIFFInitOJPEG }, + { "CCITT RLE", COMPRESSION_CCITTRLE, TIFFInitCCITTRLE }, + { "CCITT RLE/W", COMPRESSION_CCITTRLEW, TIFFInitCCITTRLEW }, + { "CCITT Group 3", COMPRESSION_CCITTFAX3, TIFFInitCCITTFax3 }, + { "CCITT Group 4", COMPRESSION_CCITTFAX4, TIFFInitCCITTFax4 }, + { "ISO JBIG", COMPRESSION_JBIG, TIFFInitJBIG }, + { "Deflate", COMPRESSION_DEFLATE, TIFFInitZIP }, + { "AdobeDeflate", COMPRESSION_ADOBE_DEFLATE , TIFFInitZIP }, + { "PixarLog", COMPRESSION_PIXARLOG, TIFFInitPixarLog }, + { "SGILog", COMPRESSION_SGILOG, TIFFInitSGILog }, + { "SGILog24", COMPRESSION_SGILOG24, TIFFInitSGILog }, + { "LZMA", COMPRESSION_LZMA, TIFFInitLZMA }, + { NULL, 0, NULL } +}; + +static int +_notConfigured(TIFF* tif) +{ + const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression); + char compression_code[20]; + + sprintf( compression_code, "%d", tif->tif_dir.td_compression ); + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "%s compression support is not configured", + c ? c->name : compression_code ); + return (0); +} + +static int +NotConfigured(TIFF* tif, int scheme) +{ + (void) scheme; + + tif->tif_fixuptags = _notConfigured; + tif->tif_decodestatus = FALSE; + tif->tif_setupdecode = _notConfigured; + tif->tif_encodestatus = FALSE; + tif->tif_setupencode = _notConfigured; + return (1); +} + +/************************************************************************/ +/* TIFFIsCODECConfigured() */ +/************************************************************************/ + +/** + * Check whether we have working codec for the specific coding scheme. + * + * @return returns 1 if the codec is configured and working. Otherwise + * 0 will be returned. + */ + +int +TIFFIsCODECConfigured(uint16 scheme) +{ + const TIFFCodec* codec = TIFFFindCODEC(scheme); + + if(codec == NULL) { + return 0; + } + if(codec->init == NULL) { + return 0; + } + if(codec->init != NotConfigured){ + return 1; + } + return 0; +} + +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_color.c b/Source/LibTIFF4/tif_color.c index 93f6acd..c5f0ac1 100644 --- a/Source/LibTIFF4/tif_color.c +++ b/Source/LibTIFF4/tif_color.c @@ -1,287 +1,287 @@ -/* $Id: tif_color.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * CIE L*a*b* to CIE XYZ and CIE XYZ to RGB conversion routines are taken - * from the VIPS library (http://www.vips.ecs.soton.ac.uk) with - * the permission of John Cupitt, the VIPS author. - */ - -/* - * TIFF Library. - * - * Color space conversion routines. - */ - -#include "tiffiop.h" -#include - -/* - * Convert color value from the CIE L*a*b* 1976 space to CIE XYZ. - */ -void -TIFFCIELabToXYZ(TIFFCIELabToRGB *cielab, uint32 l, int32 a, int32 b, - float *X, float *Y, float *Z) -{ - float L = (float)l * 100.0F / 255.0F; - float cby, tmp; - - if( L < 8.856F ) { - *Y = (L * cielab->Y0) / 903.292F; - cby = 7.787F * (*Y / cielab->Y0) + 16.0F / 116.0F; - } else { - cby = (L + 16.0F) / 116.0F; - *Y = cielab->Y0 * cby * cby * cby; - } - - tmp = (float)a / 500.0F + cby; - if( tmp < 0.2069F ) - *X = cielab->X0 * (tmp - 0.13793F) / 7.787F; - else - *X = cielab->X0 * tmp * tmp * tmp; - - tmp = cby - (float)b / 200.0F; - if( tmp < 0.2069F ) - *Z = cielab->Z0 * (tmp - 0.13793F) / 7.787F; - else - *Z = cielab->Z0 * tmp * tmp * tmp; -} - -#define RINT(R) ((uint32)((R)>0?((R)+0.5):((R)-0.5))) -/* - * Convert color value from the XYZ space to RGB. - */ -void -TIFFXYZToRGB(TIFFCIELabToRGB *cielab, float X, float Y, float Z, - uint32 *r, uint32 *g, uint32 *b) -{ - int i; - float Yr, Yg, Yb; - float *matrix = &cielab->display.d_mat[0][0]; - - /* Multiply through the matrix to get luminosity values. */ - Yr = matrix[0] * X + matrix[1] * Y + matrix[2] * Z; - Yg = matrix[3] * X + matrix[4] * Y + matrix[5] * Z; - Yb = matrix[6] * X + matrix[7] * Y + matrix[8] * Z; - - /* Clip input */ - Yr = TIFFmax(Yr, cielab->display.d_Y0R); - Yg = TIFFmax(Yg, cielab->display.d_Y0G); - Yb = TIFFmax(Yb, cielab->display.d_Y0B); - - /* Avoid overflow in case of wrong input values */ - Yr = TIFFmin(Yr, cielab->display.d_YCR); - Yg = TIFFmin(Yg, cielab->display.d_YCG); - Yb = TIFFmin(Yb, cielab->display.d_YCB); - - /* Turn luminosity to colour value. */ - i = (int)((Yr - cielab->display.d_Y0R) / cielab->rstep); - i = TIFFmin(cielab->range, i); - *r = RINT(cielab->Yr2r[i]); - - i = (int)((Yg - cielab->display.d_Y0G) / cielab->gstep); - i = TIFFmin(cielab->range, i); - *g = RINT(cielab->Yg2g[i]); - - i = (int)((Yb - cielab->display.d_Y0B) / cielab->bstep); - i = TIFFmin(cielab->range, i); - *b = RINT(cielab->Yb2b[i]); - - /* Clip output. */ - *r = TIFFmin(*r, cielab->display.d_Vrwr); - *g = TIFFmin(*g, cielab->display.d_Vrwg); - *b = TIFFmin(*b, cielab->display.d_Vrwb); -} -#undef RINT - -/* - * Allocate conversion state structures and make look_up tables for - * the Yr,Yb,Yg <=> r,g,b conversions. - */ -int -TIFFCIELabToRGBInit(TIFFCIELabToRGB* cielab, - const TIFFDisplay *display, float *refWhite) -{ - int i; - double gamma; - - cielab->range = CIELABTORGB_TABLE_RANGE; - - _TIFFmemcpy(&cielab->display, display, sizeof(TIFFDisplay)); - - /* Red */ - gamma = 1.0 / cielab->display.d_gammaR ; - cielab->rstep = - (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range; - for(i = 0; i <= cielab->range; i++) { - cielab->Yr2r[i] = cielab->display.d_Vrwr - * ((float)pow((double)i / cielab->range, gamma)); - } - - /* Green */ - gamma = 1.0 / cielab->display.d_gammaG ; - cielab->gstep = - (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range; - for(i = 0; i <= cielab->range; i++) { - cielab->Yg2g[i] = cielab->display.d_Vrwg - * ((float)pow((double)i / cielab->range, gamma)); - } - - /* Blue */ - gamma = 1.0 / cielab->display.d_gammaB ; - cielab->bstep = - (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range; - for(i = 0; i <= cielab->range; i++) { - cielab->Yb2b[i] = cielab->display.d_Vrwb - * ((float)pow((double)i / cielab->range, gamma)); - } - - /* Init reference white point */ - cielab->X0 = refWhite[0]; - cielab->Y0 = refWhite[1]; - cielab->Z0 = refWhite[2]; - - return 0; -} - -/* - * Convert color value from the YCbCr space to CIE XYZ. - * The colorspace conversion algorithm comes from the IJG v5a code; - * see below for more information on how it works. - */ -#define SHIFT 16 -#define FIX(x) ((int32)((x) * (1L<(max)?(max):(f)) -#define HICLAMP(f,max) ((f)>(max)?(max):(f)) - -void -TIFFYCbCrtoRGB(TIFFYCbCrToRGB *ycbcr, uint32 Y, int32 Cb, int32 Cr, - uint32 *r, uint32 *g, uint32 *b) -{ - int32 i; - - /* XXX: Only 8-bit YCbCr input supported for now */ - Y = HICLAMP(Y, 255), Cb = CLAMP(Cb, 0, 255), Cr = CLAMP(Cr, 0, 255); - - i = ycbcr->Y_tab[Y] + ycbcr->Cr_r_tab[Cr]; - *r = CLAMP(i, 0, 255); - i = ycbcr->Y_tab[Y] - + (int)((ycbcr->Cb_g_tab[Cb] + ycbcr->Cr_g_tab[Cr]) >> SHIFT); - *g = CLAMP(i, 0, 255); - i = ycbcr->Y_tab[Y] + ycbcr->Cb_b_tab[Cb]; - *b = CLAMP(i, 0, 255); -} - -/* - * Initialize the YCbCr->RGB conversion tables. The conversion - * is done according to the 6.0 spec: - * - * R = Y + Cr*(2 - 2*LumaRed) - * B = Y + Cb*(2 - 2*LumaBlue) - * G = Y - * - LumaBlue*Cb*(2-2*LumaBlue)/LumaGreen - * - LumaRed*Cr*(2-2*LumaRed)/LumaGreen - * - * To avoid floating point arithmetic the fractional constants that - * come out of the equations are represented as fixed point values - * in the range 0...2^16. We also eliminate multiplications by - * pre-calculating possible values indexed by Cb and Cr (this code - * assumes conversion is being done for 8-bit samples). - */ -int -TIFFYCbCrToRGBInit(TIFFYCbCrToRGB* ycbcr, float *luma, float *refBlackWhite) -{ - TIFFRGBValue* clamptab; - int i; - -#define LumaRed luma[0] -#define LumaGreen luma[1] -#define LumaBlue luma[2] - - clamptab = (TIFFRGBValue*)( - (uint8*) ycbcr+TIFFroundup_32(sizeof (TIFFYCbCrToRGB), sizeof (long))); - _TIFFmemset(clamptab, 0, 256); /* v < 0 => 0 */ - ycbcr->clamptab = (clamptab += 256); - for (i = 0; i < 256; i++) - clamptab[i] = (TIFFRGBValue) i; - _TIFFmemset(clamptab+256, 255, 2*256); /* v > 255 => 255 */ - ycbcr->Cr_r_tab = (int*) (clamptab + 3*256); - ycbcr->Cb_b_tab = ycbcr->Cr_r_tab + 256; - ycbcr->Cr_g_tab = (int32*) (ycbcr->Cb_b_tab + 256); - ycbcr->Cb_g_tab = ycbcr->Cr_g_tab + 256; - ycbcr->Y_tab = ycbcr->Cb_g_tab + 256; - - { float f1 = 2-2*LumaRed; int32 D1 = FIX(f1); - float f2 = LumaRed*f1/LumaGreen; int32 D2 = -FIX(f2); - float f3 = 2-2*LumaBlue; int32 D3 = FIX(f3); - float f4 = LumaBlue*f3/LumaGreen; int32 D4 = -FIX(f4); - int x; - -#undef LumaBlue -#undef LumaGreen -#undef LumaRed - - /* - * i is the actual input pixel value in the range 0..255 - * Cb and Cr values are in the range -128..127 (actually - * they are in a range defined by the ReferenceBlackWhite - * tag) so there is some range shifting to do here when - * constructing tables indexed by the raw pixel data. - */ - for (i = 0, x = -128; i < 256; i++, x++) { - int32 Cr = (int32)Code2V(x, refBlackWhite[4] - 128.0F, - refBlackWhite[5] - 128.0F, 127); - int32 Cb = (int32)Code2V(x, refBlackWhite[2] - 128.0F, - refBlackWhite[3] - 128.0F, 127); - - ycbcr->Cr_r_tab[i] = (int32)((D1*Cr + ONE_HALF)>>SHIFT); - ycbcr->Cb_b_tab[i] = (int32)((D3*Cb + ONE_HALF)>>SHIFT); - ycbcr->Cr_g_tab[i] = D2*Cr; - ycbcr->Cb_g_tab[i] = D4*Cb + ONE_HALF; - ycbcr->Y_tab[i] = - (int32)Code2V(x + 128, refBlackWhite[0], refBlackWhite[1], 255); - } - } - - return 0; -} -#undef HICLAMP -#undef CLAMP -#undef Code2V -#undef SHIFT -#undef ONE_HALF -#undef FIX - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_color.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * CIE L*a*b* to CIE XYZ and CIE XYZ to RGB conversion routines are taken + * from the VIPS library (http://www.vips.ecs.soton.ac.uk) with + * the permission of John Cupitt, the VIPS author. + */ + +/* + * TIFF Library. + * + * Color space conversion routines. + */ + +#include "tiffiop.h" +#include + +/* + * Convert color value from the CIE L*a*b* 1976 space to CIE XYZ. + */ +void +TIFFCIELabToXYZ(TIFFCIELabToRGB *cielab, uint32 l, int32 a, int32 b, + float *X, float *Y, float *Z) +{ + float L = (float)l * 100.0F / 255.0F; + float cby, tmp; + + if( L < 8.856F ) { + *Y = (L * cielab->Y0) / 903.292F; + cby = 7.787F * (*Y / cielab->Y0) + 16.0F / 116.0F; + } else { + cby = (L + 16.0F) / 116.0F; + *Y = cielab->Y0 * cby * cby * cby; + } + + tmp = (float)a / 500.0F + cby; + if( tmp < 0.2069F ) + *X = cielab->X0 * (tmp - 0.13793F) / 7.787F; + else + *X = cielab->X0 * tmp * tmp * tmp; + + tmp = cby - (float)b / 200.0F; + if( tmp < 0.2069F ) + *Z = cielab->Z0 * (tmp - 0.13793F) / 7.787F; + else + *Z = cielab->Z0 * tmp * tmp * tmp; +} + +#define RINT(R) ((uint32)((R)>0?((R)+0.5):((R)-0.5))) +/* + * Convert color value from the XYZ space to RGB. + */ +void +TIFFXYZToRGB(TIFFCIELabToRGB *cielab, float X, float Y, float Z, + uint32 *r, uint32 *g, uint32 *b) +{ + int i; + float Yr, Yg, Yb; + float *matrix = &cielab->display.d_mat[0][0]; + + /* Multiply through the matrix to get luminosity values. */ + Yr = matrix[0] * X + matrix[1] * Y + matrix[2] * Z; + Yg = matrix[3] * X + matrix[4] * Y + matrix[5] * Z; + Yb = matrix[6] * X + matrix[7] * Y + matrix[8] * Z; + + /* Clip input */ + Yr = TIFFmax(Yr, cielab->display.d_Y0R); + Yg = TIFFmax(Yg, cielab->display.d_Y0G); + Yb = TIFFmax(Yb, cielab->display.d_Y0B); + + /* Avoid overflow in case of wrong input values */ + Yr = TIFFmin(Yr, cielab->display.d_YCR); + Yg = TIFFmin(Yg, cielab->display.d_YCG); + Yb = TIFFmin(Yb, cielab->display.d_YCB); + + /* Turn luminosity to colour value. */ + i = (int)((Yr - cielab->display.d_Y0R) / cielab->rstep); + i = TIFFmin(cielab->range, i); + *r = RINT(cielab->Yr2r[i]); + + i = (int)((Yg - cielab->display.d_Y0G) / cielab->gstep); + i = TIFFmin(cielab->range, i); + *g = RINT(cielab->Yg2g[i]); + + i = (int)((Yb - cielab->display.d_Y0B) / cielab->bstep); + i = TIFFmin(cielab->range, i); + *b = RINT(cielab->Yb2b[i]); + + /* Clip output. */ + *r = TIFFmin(*r, cielab->display.d_Vrwr); + *g = TIFFmin(*g, cielab->display.d_Vrwg); + *b = TIFFmin(*b, cielab->display.d_Vrwb); +} +#undef RINT + +/* + * Allocate conversion state structures and make look_up tables for + * the Yr,Yb,Yg <=> r,g,b conversions. + */ +int +TIFFCIELabToRGBInit(TIFFCIELabToRGB* cielab, + const TIFFDisplay *display, float *refWhite) +{ + int i; + double gamma; + + cielab->range = CIELABTORGB_TABLE_RANGE; + + _TIFFmemcpy(&cielab->display, display, sizeof(TIFFDisplay)); + + /* Red */ + gamma = 1.0 / cielab->display.d_gammaR ; + cielab->rstep = + (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range; + for(i = 0; i <= cielab->range; i++) { + cielab->Yr2r[i] = cielab->display.d_Vrwr + * ((float)pow((double)i / cielab->range, gamma)); + } + + /* Green */ + gamma = 1.0 / cielab->display.d_gammaG ; + cielab->gstep = + (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range; + for(i = 0; i <= cielab->range; i++) { + cielab->Yg2g[i] = cielab->display.d_Vrwg + * ((float)pow((double)i / cielab->range, gamma)); + } + + /* Blue */ + gamma = 1.0 / cielab->display.d_gammaB ; + cielab->bstep = + (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range; + for(i = 0; i <= cielab->range; i++) { + cielab->Yb2b[i] = cielab->display.d_Vrwb + * ((float)pow((double)i / cielab->range, gamma)); + } + + /* Init reference white point */ + cielab->X0 = refWhite[0]; + cielab->Y0 = refWhite[1]; + cielab->Z0 = refWhite[2]; + + return 0; +} + +/* + * Convert color value from the YCbCr space to CIE XYZ. + * The colorspace conversion algorithm comes from the IJG v5a code; + * see below for more information on how it works. + */ +#define SHIFT 16 +#define FIX(x) ((int32)((x) * (1L<(max)?(max):(f)) +#define HICLAMP(f,max) ((f)>(max)?(max):(f)) + +void +TIFFYCbCrtoRGB(TIFFYCbCrToRGB *ycbcr, uint32 Y, int32 Cb, int32 Cr, + uint32 *r, uint32 *g, uint32 *b) +{ + int32 i; + + /* XXX: Only 8-bit YCbCr input supported for now */ + Y = HICLAMP(Y, 255), Cb = CLAMP(Cb, 0, 255), Cr = CLAMP(Cr, 0, 255); + + i = ycbcr->Y_tab[Y] + ycbcr->Cr_r_tab[Cr]; + *r = CLAMP(i, 0, 255); + i = ycbcr->Y_tab[Y] + + (int)((ycbcr->Cb_g_tab[Cb] + ycbcr->Cr_g_tab[Cr]) >> SHIFT); + *g = CLAMP(i, 0, 255); + i = ycbcr->Y_tab[Y] + ycbcr->Cb_b_tab[Cb]; + *b = CLAMP(i, 0, 255); +} + +/* + * Initialize the YCbCr->RGB conversion tables. The conversion + * is done according to the 6.0 spec: + * + * R = Y + Cr*(2 - 2*LumaRed) + * B = Y + Cb*(2 - 2*LumaBlue) + * G = Y + * - LumaBlue*Cb*(2-2*LumaBlue)/LumaGreen + * - LumaRed*Cr*(2-2*LumaRed)/LumaGreen + * + * To avoid floating point arithmetic the fractional constants that + * come out of the equations are represented as fixed point values + * in the range 0...2^16. We also eliminate multiplications by + * pre-calculating possible values indexed by Cb and Cr (this code + * assumes conversion is being done for 8-bit samples). + */ +int +TIFFYCbCrToRGBInit(TIFFYCbCrToRGB* ycbcr, float *luma, float *refBlackWhite) +{ + TIFFRGBValue* clamptab; + int i; + +#define LumaRed luma[0] +#define LumaGreen luma[1] +#define LumaBlue luma[2] + + clamptab = (TIFFRGBValue*)( + (uint8*) ycbcr+TIFFroundup_32(sizeof (TIFFYCbCrToRGB), sizeof (long))); + _TIFFmemset(clamptab, 0, 256); /* v < 0 => 0 */ + ycbcr->clamptab = (clamptab += 256); + for (i = 0; i < 256; i++) + clamptab[i] = (TIFFRGBValue) i; + _TIFFmemset(clamptab+256, 255, 2*256); /* v > 255 => 255 */ + ycbcr->Cr_r_tab = (int*) (clamptab + 3*256); + ycbcr->Cb_b_tab = ycbcr->Cr_r_tab + 256; + ycbcr->Cr_g_tab = (int32*) (ycbcr->Cb_b_tab + 256); + ycbcr->Cb_g_tab = ycbcr->Cr_g_tab + 256; + ycbcr->Y_tab = ycbcr->Cb_g_tab + 256; + + { float f1 = 2-2*LumaRed; int32 D1 = FIX(f1); + float f2 = LumaRed*f1/LumaGreen; int32 D2 = -FIX(f2); + float f3 = 2-2*LumaBlue; int32 D3 = FIX(f3); + float f4 = LumaBlue*f3/LumaGreen; int32 D4 = -FIX(f4); + int x; + +#undef LumaBlue +#undef LumaGreen +#undef LumaRed + + /* + * i is the actual input pixel value in the range 0..255 + * Cb and Cr values are in the range -128..127 (actually + * they are in a range defined by the ReferenceBlackWhite + * tag) so there is some range shifting to do here when + * constructing tables indexed by the raw pixel data. + */ + for (i = 0, x = -128; i < 256; i++, x++) { + int32 Cr = (int32)Code2V(x, refBlackWhite[4] - 128.0F, + refBlackWhite[5] - 128.0F, 127); + int32 Cb = (int32)Code2V(x, refBlackWhite[2] - 128.0F, + refBlackWhite[3] - 128.0F, 127); + + ycbcr->Cr_r_tab[i] = (int32)((D1*Cr + ONE_HALF)>>SHIFT); + ycbcr->Cb_b_tab[i] = (int32)((D3*Cb + ONE_HALF)>>SHIFT); + ycbcr->Cr_g_tab[i] = D2*Cr; + ycbcr->Cb_g_tab[i] = D4*Cb + ONE_HALF; + ycbcr->Y_tab[i] = + (int32)Code2V(x + 128, refBlackWhite[0], refBlackWhite[1], 255); + } + } + + return 0; +} +#undef HICLAMP +#undef CLAMP +#undef Code2V +#undef SHIFT +#undef ONE_HALF +#undef FIX + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_compress.c b/Source/LibTIFF4/tif_compress.c index 29ae999..ddd7a62 100644 --- a/Source/LibTIFF4/tif_compress.c +++ b/Source/LibTIFF4/tif_compress.c @@ -1,304 +1,304 @@ -/* $Id: tif_compress.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library - * - * Compression Scheme Configuration Support. - */ -#include "tiffiop.h" - -static int -TIFFNoEncode(TIFF* tif, const char* method) -{ - const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression); - - if (c) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "%s %s encoding is not implemented", - c->name, method); - } else { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "Compression scheme %u %s encoding is not implemented", - tif->tif_dir.td_compression, method); - } - return (-1); -} - -int -_TIFFNoRowEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) -{ - (void) pp; (void) cc; (void) s; - return (TIFFNoEncode(tif, "scanline")); -} - -int -_TIFFNoStripEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) -{ - (void) pp; (void) cc; (void) s; - return (TIFFNoEncode(tif, "strip")); -} - -int -_TIFFNoTileEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) -{ - (void) pp; (void) cc; (void) s; - return (TIFFNoEncode(tif, "tile")); -} - -static int -TIFFNoDecode(TIFF* tif, const char* method) -{ - const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression); - - if (c) - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "%s %s decoding is not implemented", - c->name, method); - else - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "Compression scheme %u %s decoding is not implemented", - tif->tif_dir.td_compression, method); - return (-1); -} - -int -_TIFFNoFixupTags(TIFF* tif) -{ - (void) tif; - return (1); -} - -int -_TIFFNoRowDecode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) -{ - (void) pp; (void) cc; (void) s; - return (TIFFNoDecode(tif, "scanline")); -} - -int -_TIFFNoStripDecode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) -{ - (void) pp; (void) cc; (void) s; - return (TIFFNoDecode(tif, "strip")); -} - -int -_TIFFNoTileDecode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) -{ - (void) pp; (void) cc; (void) s; - return (TIFFNoDecode(tif, "tile")); -} - -int -_TIFFNoSeek(TIFF* tif, uint32 off) -{ - (void) off; - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "Compression algorithm does not support random access"); - return (0); -} - -int -_TIFFNoPreCode(TIFF* tif, uint16 s) -{ - (void) tif; (void) s; - return (1); -} - -static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); } -static void _TIFFvoid(TIFF* tif) { (void) tif; } - -void -_TIFFSetDefaultCompressionState(TIFF* tif) -{ - tif->tif_fixuptags = _TIFFNoFixupTags; - tif->tif_decodestatus = TRUE; - tif->tif_setupdecode = _TIFFtrue; - tif->tif_predecode = _TIFFNoPreCode; - tif->tif_decoderow = _TIFFNoRowDecode; - tif->tif_decodestrip = _TIFFNoStripDecode; - tif->tif_decodetile = _TIFFNoTileDecode; - tif->tif_encodestatus = TRUE; - tif->tif_setupencode = _TIFFtrue; - tif->tif_preencode = _TIFFNoPreCode; - tif->tif_postencode = _TIFFtrue; - tif->tif_encoderow = _TIFFNoRowEncode; - tif->tif_encodestrip = _TIFFNoStripEncode; - tif->tif_encodetile = _TIFFNoTileEncode; - tif->tif_close = _TIFFvoid; - tif->tif_seek = _TIFFNoSeek; - tif->tif_cleanup = _TIFFvoid; - tif->tif_defstripsize = _TIFFDefaultStripSize; - tif->tif_deftilesize = _TIFFDefaultTileSize; - tif->tif_flags &= ~(TIFF_NOBITREV|TIFF_NOREADRAW); -} - -int -TIFFSetCompressionScheme(TIFF* tif, int scheme) -{ - const TIFFCodec *c = TIFFFindCODEC((uint16) scheme); - - _TIFFSetDefaultCompressionState(tif); - /* - * Don't treat an unknown compression scheme as an error. - * This permits applications to open files with data that - * the library does not have builtin support for, but which - * may still be meaningful. - */ - return (c ? (*c->init)(tif, scheme) : 1); -} - -/* - * Other compression schemes may be registered. Registered - * schemes can also override the builtin versions provided - * by this library. - */ -typedef struct _codec { - struct _codec* next; - TIFFCodec* info; -} codec_t; -static codec_t* registeredCODECS = NULL; - -const TIFFCodec* -TIFFFindCODEC(uint16 scheme) -{ - const TIFFCodec* c; - codec_t* cd; - - for (cd = registeredCODECS; cd; cd = cd->next) - if (cd->info->scheme == scheme) - return ((const TIFFCodec*) cd->info); - for (c = _TIFFBuiltinCODECS; c->name; c++) - if (c->scheme == scheme) - return (c); - return ((const TIFFCodec*) 0); -} - -TIFFCodec* -TIFFRegisterCODEC(uint16 scheme, const char* name, TIFFInitMethod init) -{ - codec_t* cd = (codec_t*) - _TIFFmalloc((tmsize_t)(sizeof (codec_t) + sizeof (TIFFCodec) + strlen(name)+1)); - - if (cd != NULL) { - cd->info = (TIFFCodec*) ((uint8*) cd + sizeof (codec_t)); - cd->info->name = (char*) - ((uint8*) cd->info + sizeof (TIFFCodec)); - strcpy(cd->info->name, name); - cd->info->scheme = scheme; - cd->info->init = init; - cd->next = registeredCODECS; - registeredCODECS = cd; - } else { - TIFFErrorExt(0, "TIFFRegisterCODEC", - "No space to register compression scheme %s", name); - return NULL; - } - return (cd->info); -} - -void -TIFFUnRegisterCODEC(TIFFCodec* c) -{ - codec_t* cd; - codec_t** pcd; - - for (pcd = ®isteredCODECS; (cd = *pcd); pcd = &cd->next) - if (cd->info == c) { - *pcd = cd->next; - _TIFFfree(cd); - return; - } - TIFFErrorExt(0, "TIFFUnRegisterCODEC", - "Cannot remove compression scheme %s; not registered", c->name); -} - -/************************************************************************/ -/* TIFFGetConfisuredCODECs() */ -/************************************************************************/ - -/** - * Get list of configured codecs, both built-in and registered by user. - * Caller is responsible to free this structure. - * - * @return returns array of TIFFCodec records (the last record should be NULL) - * or NULL if function failed. - */ - -TIFFCodec* -TIFFGetConfiguredCODECs() -{ - int i = 1; - codec_t *cd; - const TIFFCodec* c; - TIFFCodec* codecs = NULL; - TIFFCodec* new_codecs; - - for (cd = registeredCODECS; cd; cd = cd->next) { - new_codecs = (TIFFCodec *) - _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); - if (!new_codecs) { - _TIFFfree (codecs); - return NULL; - } - codecs = new_codecs; - _TIFFmemcpy(codecs + i - 1, cd, sizeof(TIFFCodec)); - i++; - } - for (c = _TIFFBuiltinCODECS; c->name; c++) { - if (TIFFIsCODECConfigured(c->scheme)) { - new_codecs = (TIFFCodec *) - _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); - if (!new_codecs) { - _TIFFfree (codecs); - return NULL; - } - codecs = new_codecs; - _TIFFmemcpy(codecs + i - 1, (const void*)c, sizeof(TIFFCodec)); - i++; - } - } - - new_codecs = (TIFFCodec *) _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); - if (!new_codecs) { - _TIFFfree (codecs); - return NULL; - } - codecs = new_codecs; - _TIFFmemset(codecs + i - 1, 0, sizeof(TIFFCodec)); - - return codecs; -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_compress.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library + * + * Compression Scheme Configuration Support. + */ +#include "tiffiop.h" + +static int +TIFFNoEncode(TIFF* tif, const char* method) +{ + const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression); + + if (c) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "%s %s encoding is not implemented", + c->name, method); + } else { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "Compression scheme %u %s encoding is not implemented", + tif->tif_dir.td_compression, method); + } + return (-1); +} + +int +_TIFFNoRowEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) +{ + (void) pp; (void) cc; (void) s; + return (TIFFNoEncode(tif, "scanline")); +} + +int +_TIFFNoStripEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) +{ + (void) pp; (void) cc; (void) s; + return (TIFFNoEncode(tif, "strip")); +} + +int +_TIFFNoTileEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) +{ + (void) pp; (void) cc; (void) s; + return (TIFFNoEncode(tif, "tile")); +} + +static int +TIFFNoDecode(TIFF* tif, const char* method) +{ + const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression); + + if (c) + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "%s %s decoding is not implemented", + c->name, method); + else + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "Compression scheme %u %s decoding is not implemented", + tif->tif_dir.td_compression, method); + return (-1); +} + +int +_TIFFNoFixupTags(TIFF* tif) +{ + (void) tif; + return (1); +} + +int +_TIFFNoRowDecode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) +{ + (void) pp; (void) cc; (void) s; + return (TIFFNoDecode(tif, "scanline")); +} + +int +_TIFFNoStripDecode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) +{ + (void) pp; (void) cc; (void) s; + return (TIFFNoDecode(tif, "strip")); +} + +int +_TIFFNoTileDecode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) +{ + (void) pp; (void) cc; (void) s; + return (TIFFNoDecode(tif, "tile")); +} + +int +_TIFFNoSeek(TIFF* tif, uint32 off) +{ + (void) off; + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "Compression algorithm does not support random access"); + return (0); +} + +int +_TIFFNoPreCode(TIFF* tif, uint16 s) +{ + (void) tif; (void) s; + return (1); +} + +static int _TIFFtrue(TIFF* tif) { (void) tif; return (1); } +static void _TIFFvoid(TIFF* tif) { (void) tif; } + +void +_TIFFSetDefaultCompressionState(TIFF* tif) +{ + tif->tif_fixuptags = _TIFFNoFixupTags; + tif->tif_decodestatus = TRUE; + tif->tif_setupdecode = _TIFFtrue; + tif->tif_predecode = _TIFFNoPreCode; + tif->tif_decoderow = _TIFFNoRowDecode; + tif->tif_decodestrip = _TIFFNoStripDecode; + tif->tif_decodetile = _TIFFNoTileDecode; + tif->tif_encodestatus = TRUE; + tif->tif_setupencode = _TIFFtrue; + tif->tif_preencode = _TIFFNoPreCode; + tif->tif_postencode = _TIFFtrue; + tif->tif_encoderow = _TIFFNoRowEncode; + tif->tif_encodestrip = _TIFFNoStripEncode; + tif->tif_encodetile = _TIFFNoTileEncode; + tif->tif_close = _TIFFvoid; + tif->tif_seek = _TIFFNoSeek; + tif->tif_cleanup = _TIFFvoid; + tif->tif_defstripsize = _TIFFDefaultStripSize; + tif->tif_deftilesize = _TIFFDefaultTileSize; + tif->tif_flags &= ~(TIFF_NOBITREV|TIFF_NOREADRAW); +} + +int +TIFFSetCompressionScheme(TIFF* tif, int scheme) +{ + const TIFFCodec *c = TIFFFindCODEC((uint16) scheme); + + _TIFFSetDefaultCompressionState(tif); + /* + * Don't treat an unknown compression scheme as an error. + * This permits applications to open files with data that + * the library does not have builtin support for, but which + * may still be meaningful. + */ + return (c ? (*c->init)(tif, scheme) : 1); +} + +/* + * Other compression schemes may be registered. Registered + * schemes can also override the builtin versions provided + * by this library. + */ +typedef struct _codec { + struct _codec* next; + TIFFCodec* info; +} codec_t; +static codec_t* registeredCODECS = NULL; + +const TIFFCodec* +TIFFFindCODEC(uint16 scheme) +{ + const TIFFCodec* c; + codec_t* cd; + + for (cd = registeredCODECS; cd; cd = cd->next) + if (cd->info->scheme == scheme) + return ((const TIFFCodec*) cd->info); + for (c = _TIFFBuiltinCODECS; c->name; c++) + if (c->scheme == scheme) + return (c); + return ((const TIFFCodec*) 0); +} + +TIFFCodec* +TIFFRegisterCODEC(uint16 scheme, const char* name, TIFFInitMethod init) +{ + codec_t* cd = (codec_t*) + _TIFFmalloc((tmsize_t)(sizeof (codec_t) + sizeof (TIFFCodec) + strlen(name)+1)); + + if (cd != NULL) { + cd->info = (TIFFCodec*) ((uint8*) cd + sizeof (codec_t)); + cd->info->name = (char*) + ((uint8*) cd->info + sizeof (TIFFCodec)); + strcpy(cd->info->name, name); + cd->info->scheme = scheme; + cd->info->init = init; + cd->next = registeredCODECS; + registeredCODECS = cd; + } else { + TIFFErrorExt(0, "TIFFRegisterCODEC", + "No space to register compression scheme %s", name); + return NULL; + } + return (cd->info); +} + +void +TIFFUnRegisterCODEC(TIFFCodec* c) +{ + codec_t* cd; + codec_t** pcd; + + for (pcd = ®isteredCODECS; (cd = *pcd); pcd = &cd->next) + if (cd->info == c) { + *pcd = cd->next; + _TIFFfree(cd); + return; + } + TIFFErrorExt(0, "TIFFUnRegisterCODEC", + "Cannot remove compression scheme %s; not registered", c->name); +} + +/************************************************************************/ +/* TIFFGetConfisuredCODECs() */ +/************************************************************************/ + +/** + * Get list of configured codecs, both built-in and registered by user. + * Caller is responsible to free this structure. + * + * @return returns array of TIFFCodec records (the last record should be NULL) + * or NULL if function failed. + */ + +TIFFCodec* +TIFFGetConfiguredCODECs() +{ + int i = 1; + codec_t *cd; + const TIFFCodec* c; + TIFFCodec* codecs = NULL; + TIFFCodec* new_codecs; + + for (cd = registeredCODECS; cd; cd = cd->next) { + new_codecs = (TIFFCodec *) + _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); + if (!new_codecs) { + _TIFFfree (codecs); + return NULL; + } + codecs = new_codecs; + _TIFFmemcpy(codecs + i - 1, cd, sizeof(TIFFCodec)); + i++; + } + for (c = _TIFFBuiltinCODECS; c->name; c++) { + if (TIFFIsCODECConfigured(c->scheme)) { + new_codecs = (TIFFCodec *) + _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); + if (!new_codecs) { + _TIFFfree (codecs); + return NULL; + } + codecs = new_codecs; + _TIFFmemcpy(codecs + i - 1, (const void*)c, sizeof(TIFFCodec)); + i++; + } + } + + new_codecs = (TIFFCodec *) _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); + if (!new_codecs) { + _TIFFfree (codecs); + return NULL; + } + codecs = new_codecs; + _TIFFmemset(codecs + i - 1, 0, sizeof(TIFFCodec)); + + return codecs; +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_config.h b/Source/LibTIFF4/tif_config.h index 800fbce..64391b8 100644 --- a/Source/LibTIFF4/tif_config.h +++ b/Source/LibTIFF4/tif_config.h @@ -1,97 +1,97 @@ -#ifndef TIF_CONFIG_H -#define TIF_CONFIG_H - -/* Define to 1 if you have the header file. */ -#define HAVE_ASSERT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#define HAVE_IEEEFP 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_IO_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SEARCH_H 1 - -/* Define to 1 if you have the `setmode' function. */ -#define HAVE_SETMODE 1 - -/* Define to 1 if you have the `memmove' function. */ -#define HAVE_MEMMOVE 1 - -/* Define to 1 if you have the `memset' function. */ -#define HAVE_MEMSET 1 - -/* Signed 32-bit type formatter */ -#define TIFF_INT32_FORMAT "%d" - -/* Unsigned 32-bit type formatter */ -#define TIFF_UINT32_FORMAT "%u" - -/* Signed 64-bit type formatter */ -#define TIFF_INT64_FORMAT "%ld" - -/* Unsigned 64-bit type formatter */ -#define TIFF_UINT64_FORMAT "%lu" - -/* Pointer difference type formatter */ -#define TIFF_PTRDIFF_FORMAT "%ld" - -/* Signed size type formatter */ -#define TIFF_SSIZE_FORMAT "%ld" - -/* ------------------------------------------------------------------------ -Byte order ------------------------------------------------------------------------ -*/ - -/* -Define WORDS_BIGENDIAN to 1 if your processor stores words with the most -significant byte first (like Motorola and SPARC, unlike Intel). -Some versions of gcc may have BYTE_ORDER or __BYTE_ORDER defined -If your big endian system isn't being detected, add an OS specific check -*/ -#if (defined(BYTE_ORDER) && BYTE_ORDER==BIG_ENDIAN) || \ - (defined(__BYTE_ORDER) && __BYTE_ORDER==__BIG_ENDIAN) || \ - defined(__BIG_ENDIAN__) -/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ -#define HOST_FILLORDER FILLORDER_MSB2LSB -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ -#define WORDS_BIGENDIAN 1 -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ -#define HOST_BIGENDIAN 1 -#else -/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ -#define HOST_FILLORDER FILLORDER_LSB2MSB -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ -#undef WORDS_BIGENDIAN -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ -#undef HOST_BIGENDIAN -#endif // BYTE_ORDER - -#ifdef _WIN32 -#define snprintf _snprintf -#define lfind _lfind -#endif // _WIN32 - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -# ifndef inline -# define inline __inline -# endif -#endif - - -#endif // TIF_CONFIG_H +#ifndef TIF_CONFIG_H +#define TIF_CONFIG_H + +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#define HAVE_IEEEFP 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_IO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SEARCH_H 1 + +/* Define to 1 if you have the `setmode' function. */ +#define HAVE_SETMODE 1 + +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Define to 1 if you have the `memset' function. */ +#define HAVE_MEMSET 1 + +/* Signed 32-bit type formatter */ +#define TIFF_INT32_FORMAT "%d" + +/* Unsigned 32-bit type formatter */ +#define TIFF_UINT32_FORMAT "%u" + +/* Signed 64-bit type formatter */ +#define TIFF_INT64_FORMAT "%ld" + +/* Unsigned 64-bit type formatter */ +#define TIFF_UINT64_FORMAT "%lu" + +/* Pointer difference type formatter */ +#define TIFF_PTRDIFF_FORMAT "%ld" + +/* Signed size type formatter */ +#define TIFF_SSIZE_FORMAT "%ld" + +/* +----------------------------------------------------------------------- +Byte order +----------------------------------------------------------------------- +*/ + +/* +Define WORDS_BIGENDIAN to 1 if your processor stores words with the most +significant byte first (like Motorola and SPARC, unlike Intel). +Some versions of gcc may have BYTE_ORDER or __BYTE_ORDER defined +If your big endian system isn't being detected, add an OS specific check +*/ +#if (defined(BYTE_ORDER) && BYTE_ORDER==BIG_ENDIAN) || \ + (defined(__BYTE_ORDER) && __BYTE_ORDER==__BIG_ENDIAN) || \ + defined(__BIG_ENDIAN__) +/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ +#define HOST_FILLORDER FILLORDER_MSB2LSB +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ +#define WORDS_BIGENDIAN 1 +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ +#define HOST_BIGENDIAN 1 +#else +/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ +#define HOST_FILLORDER FILLORDER_LSB2MSB +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ +#undef WORDS_BIGENDIAN +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ +#undef HOST_BIGENDIAN +#endif // BYTE_ORDER + +#ifdef _WIN32 +#define snprintf _snprintf +#define lfind _lfind +#endif // _WIN32 + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +# ifndef inline +# define inline __inline +# endif +#endif + + +#endif // TIF_CONFIG_H diff --git a/Source/LibTIFF4/tif_config.h-vms b/Source/LibTIFF4/tif_config.h-vms index c2cae57..d653bd8 100644 --- a/Source/LibTIFF4/tif_config.h-vms +++ b/Source/LibTIFF4/tif_config.h-vms @@ -1,46 +1,46 @@ -/* Define to 1 if you have the header file. */ -#define HAVE_ASSERT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#define HAVE_IEEEFP 1 - -#define HAVE_UNISTD_H 1 - -#define HAVE_STRING_H 1 -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -//#define HAVE_IO_H 1 - -/* Define to 1 if you have the header file. */ -//#define HAVE_SEARCH_H 1 - -/* The size of a `int', as computed by sizeof. */ -#define SIZEOF_INT 4 - -/* The size of a `long', as computed by sizeof. */ -#define SIZEOF_LONG 4 - -/* Set the native cpu bit order */ -#define HOST_FILLORDER FILLORDER_LSB2MSB - -/* Define to 1 if your processor stores words with the most significant byte - first (like Motorola and SPARC, unlike Intel and VAX). */ -/* #undef WORDS_BIGENDIAN */ - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -/* -#ifndef __cplusplus -# ifndef inline -# define inline __inline -# endif -#endif -*/ - -// #define lfind _lfind +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#define HAVE_IEEEFP 1 + +#define HAVE_UNISTD_H 1 + +#define HAVE_STRING_H 1 +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +//#define HAVE_IO_H 1 + +/* Define to 1 if you have the header file. */ +//#define HAVE_SEARCH_H 1 + +/* The size of a `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of a `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* Set the native cpu bit order */ +#define HOST_FILLORDER FILLORDER_LSB2MSB + +/* Define to 1 if your processor stores words with the most significant byte + first (like Motorola and SPARC, unlike Intel and VAX). */ +/* #undef WORDS_BIGENDIAN */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +/* +#ifndef __cplusplus +# ifndef inline +# define inline __inline +# endif +#endif +*/ + +// #define lfind _lfind diff --git a/Source/LibTIFF4/tif_config.h.in b/Source/LibTIFF4/tif_config.h.in index ac564b9..b2cea35 100644 --- a/Source/LibTIFF4/tif_config.h.in +++ b/Source/LibTIFF4/tif_config.h.in @@ -1,395 +1,395 @@ -/* libtiff/tif_config.h.in. Generated from configure.ac by autoheader. */ - -/* Define if building universal (internal helper macro) */ -#undef AC_APPLE_UNIVERSAL_BUILD - -/* Support CCITT Group 3 & 4 algorithms */ -#undef CCITT_SUPPORT - -/* Pick up YCbCr subsampling info from the JPEG data stream to support files - lacking the tag (default enabled). */ -#undef CHECK_JPEG_YCBCR_SUBSAMPLING - -/* enable partial strip reading for large strips (experimental) */ -#undef CHUNKY_STRIP_READ_SUPPORT - -/* Support C++ stream API (requires C++ compiler) */ -#undef CXX_SUPPORT - -/* Treat extra sample as alpha (default enabled). The RGBA interface will - treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many - packages produce RGBA files but don't mark the alpha properly. */ -#undef DEFAULT_EXTRASAMPLE_AS_ALPHA - -/* enable deferred strip/tile offset/size loading (experimental) */ -#undef DEFER_STRILE_LOAD - -/* Define to 1 if you have the header file. */ -#undef HAVE_ASSERT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_DLFCN_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_FCNTL_H - -/* Define to 1 if you have the `floor' function. */ -#undef HAVE_FLOOR - -/* Define to 1 if you have the `getopt' function. */ -#undef HAVE_GETOPT - -/* Define to 1 if you have the header file. */ -#undef HAVE_GLUT_GLUT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_GL_GLUT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_GL_GLU_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_GL_GL_H - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#undef HAVE_IEEEFP - -/* Define to 1 if the system has the type `int16'. */ -#undef HAVE_INT16 - -/* Define to 1 if the system has the type `int32'. */ -#undef HAVE_INT32 - -/* Define to 1 if the system has the type `int8'. */ -#undef HAVE_INT8 - -/* Define to 1 if you have the header file. */ -#undef HAVE_INTTYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_IO_H - -/* Define to 1 if you have the `isascii' function. */ -#undef HAVE_ISASCII - -/* Define to 1 if you have the `jbg_newlen' function. */ -#undef HAVE_JBG_NEWLEN - -/* Define to 1 if you have the `lfind' function. */ -#undef HAVE_LFIND - -/* Define to 1 if you have the `m' library (-lm). */ -#undef HAVE_LIBM - -/* Define to 1 if you have the header file. */ -#undef HAVE_LIMITS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_MALLOC_H - -/* Define to 1 if you have the `memmove' function. */ -#undef HAVE_MEMMOVE - -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - -/* Define to 1 if you have the `memset' function. */ -#undef HAVE_MEMSET - -/* Define to 1 if you have the `mmap' function. */ -#undef HAVE_MMAP - -/* Define to 1 if you have the header file. */ -#undef HAVE_OPENGL_GLU_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_OPENGL_GL_H - -/* Define to 1 if you have the `pow' function. */ -#undef HAVE_POW - -/* Define if you have POSIX threads libraries and header files. */ -#undef HAVE_PTHREAD - -/* Define to 1 if you have the header file. */ -#undef HAVE_SEARCH_H - -/* Define to 1 if you have the `setmode' function. */ -#undef HAVE_SETMODE - -/* Define to 1 if you have the `sqrt' function. */ -#undef HAVE_SQRT - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDINT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDLIB_H - -/* Define to 1 if you have the `strcasecmp' function. */ -#undef HAVE_STRCASECMP - -/* Define to 1 if you have the `strchr' function. */ -#undef HAVE_STRCHR - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRING_H - -/* Define to 1 if you have the `strrchr' function. */ -#undef HAVE_STRRCHR - -/* Define to 1 if you have the `strstr' function. */ -#undef HAVE_STRSTR - -/* Define to 1 if you have the `strtol' function. */ -#undef HAVE_STRTOL - -/* Define to 1 if you have the `strtoul' function. */ -#undef HAVE_STRTOUL - -/* Define to 1 if you have the `strtoull' function. */ -#undef HAVE_STRTOULL - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_STAT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TIME_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_UNISTD_H - -/* Use nonstandard varargs form for the GLU tesselator callback */ -#undef HAVE_VARARGS_GLU_TESSCB - -/* Define to 1 if you have the header file. */ -#undef HAVE_WINDOWS_H - -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian - (Intel) */ -#undef HOST_BIGENDIAN - -/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ -#undef HOST_FILLORDER - -/* Support ISO JBIG compression (requires JBIG-KIT library) */ -#undef JBIG_SUPPORT - -/* 8/12 bit libjpeg dual mode enabled */ -#undef JPEG_DUAL_MODE_8_12 - -/* Support JPEG compression (requires IJG JPEG library) */ -#undef JPEG_SUPPORT - -/* 12bit libjpeg primary include file with path */ -#undef LIBJPEG_12_PATH - -/* Support LogLuv high dynamic range encoding */ -#undef LOGLUV_SUPPORT - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#undef LT_OBJDIR - -/* Support LZMA2 compression */ -#undef LZMA_SUPPORT - -/* Support LZW algorithm */ -#undef LZW_SUPPORT - -/* Support Microsoft Document Imaging format */ -#undef MDI_SUPPORT - -/* Support NeXT 2-bit RLE algorithm */ -#undef NEXT_SUPPORT - -/* Define to 1 if your C compiler doesn't accept -c and -o together. */ -#undef NO_MINUS_C_MINUS_O - -/* Support Old JPEG compresson (read-only) */ -#undef OJPEG_SUPPORT - -/* Name of package */ -#undef PACKAGE - -/* Define to the address where bug reports for this package should be sent. */ -#undef PACKAGE_BUGREPORT - -/* Define to the full name of this package. */ -#undef PACKAGE_NAME - -/* Define to the full name and version of this package. */ -#undef PACKAGE_STRING - -/* Define to the one symbol short name of this package. */ -#undef PACKAGE_TARNAME - -/* Define to the home page for this package. */ -#undef PACKAGE_URL - -/* Define to the version of this package. */ -#undef PACKAGE_VERSION - -/* Support Macintosh PackBits algorithm */ -#undef PACKBITS_SUPPORT - -/* Support Pixar log-format algorithm (requires Zlib) */ -#undef PIXARLOG_SUPPORT - -/* Define to necessary symbol if this constant uses a non-standard name on - your system. */ -#undef PTHREAD_CREATE_JOINABLE - -/* The size of `signed int', as computed by sizeof. */ -#undef SIZEOF_SIGNED_INT - -/* The size of `signed long', as computed by sizeof. */ -#undef SIZEOF_SIGNED_LONG - -/* The size of `signed long long', as computed by sizeof. */ -#undef SIZEOF_SIGNED_LONG_LONG - -/* The size of `signed short', as computed by sizeof. */ -#undef SIZEOF_SIGNED_SHORT - -/* The size of `unsigned char *', as computed by sizeof. */ -#undef SIZEOF_UNSIGNED_CHAR_P - -/* The size of `unsigned int', as computed by sizeof. */ -#undef SIZEOF_UNSIGNED_INT - -/* The size of `unsigned long', as computed by sizeof. */ -#undef SIZEOF_UNSIGNED_LONG - -/* The size of `unsigned long long', as computed by sizeof. */ -#undef SIZEOF_UNSIGNED_LONG_LONG - -/* The size of `unsigned short', as computed by sizeof. */ -#undef SIZEOF_UNSIGNED_SHORT - -/* Define to 1 if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Support strip chopping (whether or not to convert single-strip uncompressed - images to mutiple strips of specified size to reduce memory usage) */ -#undef STRIPCHOP_DEFAULT - -/* Default size of the strip in bytes (when strip chopping enabled) */ -#undef STRIP_SIZE_DEFAULT - -/* Enable SubIFD tag (330) support */ -#undef SUBIFD_SUPPORT - -/* Support ThunderScan 4-bit RLE algorithm */ -#undef THUNDER_SUPPORT - -/* Signed 16-bit type */ -#undef TIFF_INT16_T - -/* Signed 32-bit type formatter */ -#undef TIFF_INT32_FORMAT - -/* Signed 32-bit type */ -#undef TIFF_INT32_T - -/* Signed 64-bit type formatter */ -#undef TIFF_INT64_FORMAT - -/* Signed 64-bit type */ -#undef TIFF_INT64_T - -/* Signed 8-bit type */ -#undef TIFF_INT8_T - -/* Pointer difference type formatter */ -#undef TIFF_PTRDIFF_FORMAT - -/* Pointer difference type */ -#undef TIFF_PTRDIFF_T - -/* Signed size type formatter */ -#undef TIFF_SSIZE_FORMAT - -/* Signed size type */ -#undef TIFF_SSIZE_T - -/* Unsigned 16-bit type */ -#undef TIFF_UINT16_T - -/* Unsigned 32-bit type formatter */ -#undef TIFF_UINT32_FORMAT - -/* Unsigned 32-bit type */ -#undef TIFF_UINT32_T - -/* Unsigned 64-bit type formatter */ -#undef TIFF_UINT64_FORMAT - -/* Unsigned 64-bit type */ -#undef TIFF_UINT64_T - -/* Unsigned 8-bit type */ -#undef TIFF_UINT8_T - -/* Define to 1 if you can safely include both and . */ -#undef TIME_WITH_SYS_TIME - -/* Define to 1 if your declares `struct tm'. */ -#undef TM_IN_SYS_TIME - -/* define to use win32 IO system */ -#undef USE_WIN32_FILEIO - -/* Version number of package */ -#undef VERSION - -/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most - significant byte first (like Motorola and SPARC, unlike Intel). */ -#if defined AC_APPLE_UNIVERSAL_BUILD -# if defined __BIG_ENDIAN__ -# define WORDS_BIGENDIAN 1 -# endif -#else -# ifndef WORDS_BIGENDIAN -# undef WORDS_BIGENDIAN -# endif -#endif - -/* Define to 1 if the X Window System is missing or not being used. */ -#undef X_DISPLAY_MISSING - -/* Support Deflate compression */ -#undef ZIP_SUPPORT - -/* Enable large inode numbers on Mac OS X 10.5. */ -#ifndef _DARWIN_USE_64_BIT_INODE -# define _DARWIN_USE_64_BIT_INODE 1 -#endif - -/* Number of bits in a file offset, on hosts where this is settable. */ -#undef _FILE_OFFSET_BITS - -/* Define for large files, on AIX-style hosts. */ -#undef _LARGE_FILES - -/* Define to empty if `const' does not conform to ANSI C. */ -#undef const - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -#undef inline -#endif - -/* Define to `long int' if does not define. */ -#undef off_t - -/* Define to `unsigned int' if does not define. */ -#undef size_t +/* libtiff/tif_config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +#undef AC_APPLE_UNIVERSAL_BUILD + +/* Support CCITT Group 3 & 4 algorithms */ +#undef CCITT_SUPPORT + +/* Pick up YCbCr subsampling info from the JPEG data stream to support files + lacking the tag (default enabled). */ +#undef CHECK_JPEG_YCBCR_SUBSAMPLING + +/* enable partial strip reading for large strips (experimental) */ +#undef CHUNKY_STRIP_READ_SUPPORT + +/* Support C++ stream API (requires C++ compiler) */ +#undef CXX_SUPPORT + +/* Treat extra sample as alpha (default enabled). The RGBA interface will + treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many + packages produce RGBA files but don't mark the alpha properly. */ +#undef DEFAULT_EXTRASAMPLE_AS_ALPHA + +/* enable deferred strip/tile offset/size loading (experimental) */ +#undef DEFER_STRILE_LOAD + +/* Define to 1 if you have the header file. */ +#undef HAVE_ASSERT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_FCNTL_H + +/* Define to 1 if you have the `floor' function. */ +#undef HAVE_FLOOR + +/* Define to 1 if you have the `getopt' function. */ +#undef HAVE_GETOPT + +/* Define to 1 if you have the header file. */ +#undef HAVE_GLUT_GLUT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_GL_GLUT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_GL_GLU_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_GL_GL_H + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#undef HAVE_IEEEFP + +/* Define to 1 if the system has the type `int16'. */ +#undef HAVE_INT16 + +/* Define to 1 if the system has the type `int32'. */ +#undef HAVE_INT32 + +/* Define to 1 if the system has the type `int8'. */ +#undef HAVE_INT8 + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_IO_H + +/* Define to 1 if you have the `isascii' function. */ +#undef HAVE_ISASCII + +/* Define to 1 if you have the `jbg_newlen' function. */ +#undef HAVE_JBG_NEWLEN + +/* Define to 1 if you have the `lfind' function. */ +#undef HAVE_LFIND + +/* Define to 1 if you have the `m' library (-lm). */ +#undef HAVE_LIBM + +/* Define to 1 if you have the header file. */ +#undef HAVE_LIMITS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_MALLOC_H + +/* Define to 1 if you have the `memmove' function. */ +#undef HAVE_MEMMOVE + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the `memset' function. */ +#undef HAVE_MEMSET + +/* Define to 1 if you have the `mmap' function. */ +#undef HAVE_MMAP + +/* Define to 1 if you have the header file. */ +#undef HAVE_OPENGL_GLU_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_OPENGL_GL_H + +/* Define to 1 if you have the `pow' function. */ +#undef HAVE_POW + +/* Define if you have POSIX threads libraries and header files. */ +#undef HAVE_PTHREAD + +/* Define to 1 if you have the header file. */ +#undef HAVE_SEARCH_H + +/* Define to 1 if you have the `setmode' function. */ +#undef HAVE_SETMODE + +/* Define to 1 if you have the `sqrt' function. */ +#undef HAVE_SQRT + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the `strcasecmp' function. */ +#undef HAVE_STRCASECMP + +/* Define to 1 if you have the `strchr' function. */ +#undef HAVE_STRCHR + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `strrchr' function. */ +#undef HAVE_STRRCHR + +/* Define to 1 if you have the `strstr' function. */ +#undef HAVE_STRSTR + +/* Define to 1 if you have the `strtol' function. */ +#undef HAVE_STRTOL + +/* Define to 1 if you have the `strtoul' function. */ +#undef HAVE_STRTOUL + +/* Define to 1 if you have the `strtoull' function. */ +#undef HAVE_STRTOULL + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TIME_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Use nonstandard varargs form for the GLU tesselator callback */ +#undef HAVE_VARARGS_GLU_TESSCB + +/* Define to 1 if you have the header file. */ +#undef HAVE_WINDOWS_H + +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian + (Intel) */ +#undef HOST_BIGENDIAN + +/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ +#undef HOST_FILLORDER + +/* Support ISO JBIG compression (requires JBIG-KIT library) */ +#undef JBIG_SUPPORT + +/* 8/12 bit libjpeg dual mode enabled */ +#undef JPEG_DUAL_MODE_8_12 + +/* Support JPEG compression (requires IJG JPEG library) */ +#undef JPEG_SUPPORT + +/* 12bit libjpeg primary include file with path */ +#undef LIBJPEG_12_PATH + +/* Support LogLuv high dynamic range encoding */ +#undef LOGLUV_SUPPORT + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#undef LT_OBJDIR + +/* Support LZMA2 compression */ +#undef LZMA_SUPPORT + +/* Support LZW algorithm */ +#undef LZW_SUPPORT + +/* Support Microsoft Document Imaging format */ +#undef MDI_SUPPORT + +/* Support NeXT 2-bit RLE algorithm */ +#undef NEXT_SUPPORT + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +#undef NO_MINUS_C_MINUS_O + +/* Support Old JPEG compresson (read-only) */ +#undef OJPEG_SUPPORT + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Support Macintosh PackBits algorithm */ +#undef PACKBITS_SUPPORT + +/* Support Pixar log-format algorithm (requires Zlib) */ +#undef PIXARLOG_SUPPORT + +/* Define to necessary symbol if this constant uses a non-standard name on + your system. */ +#undef PTHREAD_CREATE_JOINABLE + +/* The size of `signed int', as computed by sizeof. */ +#undef SIZEOF_SIGNED_INT + +/* The size of `signed long', as computed by sizeof. */ +#undef SIZEOF_SIGNED_LONG + +/* The size of `signed long long', as computed by sizeof. */ +#undef SIZEOF_SIGNED_LONG_LONG + +/* The size of `signed short', as computed by sizeof. */ +#undef SIZEOF_SIGNED_SHORT + +/* The size of `unsigned char *', as computed by sizeof. */ +#undef SIZEOF_UNSIGNED_CHAR_P + +/* The size of `unsigned int', as computed by sizeof. */ +#undef SIZEOF_UNSIGNED_INT + +/* The size of `unsigned long', as computed by sizeof. */ +#undef SIZEOF_UNSIGNED_LONG + +/* The size of `unsigned long long', as computed by sizeof. */ +#undef SIZEOF_UNSIGNED_LONG_LONG + +/* The size of `unsigned short', as computed by sizeof. */ +#undef SIZEOF_UNSIGNED_SHORT + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Support strip chopping (whether or not to convert single-strip uncompressed + images to mutiple strips of specified size to reduce memory usage) */ +#undef STRIPCHOP_DEFAULT + +/* Default size of the strip in bytes (when strip chopping enabled) */ +#undef STRIP_SIZE_DEFAULT + +/* Enable SubIFD tag (330) support */ +#undef SUBIFD_SUPPORT + +/* Support ThunderScan 4-bit RLE algorithm */ +#undef THUNDER_SUPPORT + +/* Signed 16-bit type */ +#undef TIFF_INT16_T + +/* Signed 32-bit type formatter */ +#undef TIFF_INT32_FORMAT + +/* Signed 32-bit type */ +#undef TIFF_INT32_T + +/* Signed 64-bit type formatter */ +#undef TIFF_INT64_FORMAT + +/* Signed 64-bit type */ +#undef TIFF_INT64_T + +/* Signed 8-bit type */ +#undef TIFF_INT8_T + +/* Pointer difference type formatter */ +#undef TIFF_PTRDIFF_FORMAT + +/* Pointer difference type */ +#undef TIFF_PTRDIFF_T + +/* Signed size type formatter */ +#undef TIFF_SSIZE_FORMAT + +/* Signed size type */ +#undef TIFF_SSIZE_T + +/* Unsigned 16-bit type */ +#undef TIFF_UINT16_T + +/* Unsigned 32-bit type formatter */ +#undef TIFF_UINT32_FORMAT + +/* Unsigned 32-bit type */ +#undef TIFF_UINT32_T + +/* Unsigned 64-bit type formatter */ +#undef TIFF_UINT64_FORMAT + +/* Unsigned 64-bit type */ +#undef TIFF_UINT64_T + +/* Unsigned 8-bit type */ +#undef TIFF_UINT8_T + +/* Define to 1 if you can safely include both and . */ +#undef TIME_WITH_SYS_TIME + +/* Define to 1 if your declares `struct tm'. */ +#undef TM_IN_SYS_TIME + +/* define to use win32 IO system */ +#undef USE_WIN32_FILEIO + +/* Version number of package */ +#undef VERSION + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +# undef WORDS_BIGENDIAN +# endif +#endif + +/* Define to 1 if the X Window System is missing or not being used. */ +#undef X_DISPLAY_MISSING + +/* Support Deflate compression */ +#undef ZIP_SUPPORT + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +#undef _FILE_OFFSET_BITS + +/* Define for large files, on AIX-style hosts. */ +#undef _LARGE_FILES + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif + +/* Define to `long int' if does not define. */ +#undef off_t + +/* Define to `unsigned int' if does not define. */ +#undef size_t diff --git a/Source/LibTIFF4/tif_config.vc.h b/Source/LibTIFF4/tif_config.vc.h index ad5688a..c297cf3 100644 --- a/Source/LibTIFF4/tif_config.vc.h +++ b/Source/LibTIFF4/tif_config.vc.h @@ -1,71 +1,71 @@ -/* Define to 1 if you have the header file. */ -#define HAVE_ASSERT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#define HAVE_IEEEFP 1 - -/* Define to 1 if you have the `jbg_newlen' function. */ -#define HAVE_JBG_NEWLEN 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_IO_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SEARCH_H 1 - -/* Define to 1 if you have the `setmode' function. */ -#define HAVE_SETMODE 1 - -/* The size of a `int', as computed by sizeof. */ -#define SIZEOF_INT 4 - -/* The size of a `long', as computed by sizeof. */ -#define SIZEOF_LONG 4 - -/* Signed 64-bit type formatter */ -#define TIFF_INT64_FORMAT "%I64d" - -/* Signed 64-bit type */ -#define TIFF_INT64_T signed __int64 - -/* Unsigned 64-bit type formatter */ -#define TIFF_UINT64_FORMAT "%I64u" - -/* Unsigned 64-bit type */ -#define TIFF_UINT64_T unsigned __int64 - -/* Set the native cpu bit order */ -#define HOST_FILLORDER FILLORDER_LSB2MSB - -#define snprintf _snprintf - -/* Define to 1 if your processor stores words with the most significant byte - first (like Motorola and SPARC, unlike Intel and VAX). */ -/* #undef WORDS_BIGENDIAN */ - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -# ifndef inline -# define inline __inline -# endif -#endif - -#define lfind _lfind -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#define HAVE_IEEEFP 1 + +/* Define to 1 if you have the `jbg_newlen' function. */ +#define HAVE_JBG_NEWLEN 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_IO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SEARCH_H 1 + +/* Define to 1 if you have the `setmode' function. */ +#define HAVE_SETMODE 1 + +/* The size of a `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of a `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* Signed 64-bit type formatter */ +#define TIFF_INT64_FORMAT "%I64d" + +/* Signed 64-bit type */ +#define TIFF_INT64_T signed __int64 + +/* Unsigned 64-bit type formatter */ +#define TIFF_UINT64_FORMAT "%I64u" + +/* Unsigned 64-bit type */ +#define TIFF_UINT64_T unsigned __int64 + +/* Set the native cpu bit order */ +#define HOST_FILLORDER FILLORDER_LSB2MSB + +#define snprintf _snprintf + +/* Define to 1 if your processor stores words with the most significant byte + first (like Motorola and SPARC, unlike Intel and VAX). */ +/* #undef WORDS_BIGENDIAN */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +# ifndef inline +# define inline __inline +# endif +#endif + +#define lfind _lfind +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_config.wince.h b/Source/LibTIFF4/tif_config.wince.h index bc65cb5..c37ddd4 100644 --- a/Source/LibTIFF4/tif_config.wince.h +++ b/Source/LibTIFF4/tif_config.wince.h @@ -1,71 +1,71 @@ -/* $Id: tif_config.wince.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * TIFF library configuration header for Windows CE platform. - */ -#ifndef _WIN32_WCE -# error This version of tif_config.h header is dedicated for Windows CE platform! -#endif - -/* Define to 1 if you have the header file. */ -#define HAVE_ASSERT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#define HAVE_IEEEFP 1 - -/* Define to 1 if you have the `jbg_newlen' function. */ -#define HAVE_JBG_NEWLEN 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TYPES_H - -/* Define to 1 if you have the header file. */ -#define HAVE_IO_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SEARCH_H 1 - -/* Define to 1 if you have the `setmode' function. */ -#define HAVE_SETMODE 1 - -/* Define to 1 if you have the `bsearch' function. */ -#define HAVE_BSEARCH 1 -#define bsearch wceex_bsearch - -/* Define to 1 if you have the `lfind' function. */ -#define HAVE_LFIND 1 -#define lfind wceex_lfind - -/* The size of a `int', as computed by sizeof. */ -#define SIZEOF_INT 4 - -/* Set the native cpu bit order */ -#define HOST_FILLORDER FILLORDER_LSB2MSB - -/* Define to 1 if your processor stores words with the most significant byte - first (like Motorola and SPARC, unlike Intel and VAX). */ -/* #undef WORDS_BIGENDIAN */ - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -# ifndef inline -# define inline __inline -# endif -#endif - - -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_config.wince.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * TIFF library configuration header for Windows CE platform. + */ +#ifndef _WIN32_WCE +# error This version of tif_config.h header is dedicated for Windows CE platform! +#endif + +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#define HAVE_IEEEFP 1 + +/* Define to 1 if you have the `jbg_newlen' function. */ +#define HAVE_JBG_NEWLEN 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#define HAVE_IO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SEARCH_H 1 + +/* Define to 1 if you have the `setmode' function. */ +#define HAVE_SETMODE 1 + +/* Define to 1 if you have the `bsearch' function. */ +#define HAVE_BSEARCH 1 +#define bsearch wceex_bsearch + +/* Define to 1 if you have the `lfind' function. */ +#define HAVE_LFIND 1 +#define lfind wceex_lfind + +/* The size of a `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* Set the native cpu bit order */ +#define HOST_FILLORDER FILLORDER_LSB2MSB + +/* Define to 1 if your processor stores words with the most significant byte + first (like Motorola and SPARC, unlike Intel and VAX). */ +/* #undef WORDS_BIGENDIAN */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +# ifndef inline +# define inline __inline +# endif +#endif + + +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_dir.c b/Source/LibTIFF4/tif_dir.c index e0bdc24..a767f20 100644 --- a/Source/LibTIFF4/tif_dir.c +++ b/Source/LibTIFF4/tif_dir.c @@ -1,1659 +1,1659 @@ -/* $Id: tif_dir.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * - * Directory Tag Get & Set Routines. - * (and also some miscellaneous stuff) - */ -#include "tiffiop.h" - -/* - * These are used in the backwards compatibility code... - */ -#define DATATYPE_VOID 0 /* !untyped data */ -#define DATATYPE_INT 1 /* !signed integer data */ -#define DATATYPE_UINT 2 /* !unsigned integer data */ -#define DATATYPE_IEEEFP 3 /* !IEEE floating point data */ - -static void -setByteArray(void** vpp, void* vp, size_t nmemb, size_t elem_size) -{ - if (*vpp) - _TIFFfree(*vpp), *vpp = 0; - if (vp) { - tmsize_t bytes = (tmsize_t)(nmemb * elem_size); - if (elem_size && bytes / elem_size == nmemb) - *vpp = (void*) _TIFFmalloc(bytes); - if (*vpp) - _TIFFmemcpy(*vpp, vp, bytes); - } -} -void _TIFFsetByteArray(void** vpp, void* vp, uint32 n) - { setByteArray(vpp, vp, n, 1); } -void _TIFFsetString(char** cpp, char* cp) - { setByteArray((void**) cpp, (void*) cp, strlen(cp)+1, 1); } -void _TIFFsetNString(char** cpp, char* cp, uint32 n) - { setByteArray((void**) cpp, (void*) cp, n, 1); } -void _TIFFsetShortArray(uint16** wpp, uint16* wp, uint32 n) - { setByteArray((void**) wpp, (void*) wp, n, sizeof (uint16)); } -void _TIFFsetLongArray(uint32** lpp, uint32* lp, uint32 n) - { setByteArray((void**) lpp, (void*) lp, n, sizeof (uint32)); } -void _TIFFsetLong8Array(uint64** lpp, uint64* lp, uint32 n) - { setByteArray((void**) lpp, (void*) lp, n, sizeof (uint64)); } -void _TIFFsetFloatArray(float** fpp, float* fp, uint32 n) - { setByteArray((void**) fpp, (void*) fp, n, sizeof (float)); } -void _TIFFsetDoubleArray(double** dpp, double* dp, uint32 n) - { setByteArray((void**) dpp, (void*) dp, n, sizeof (double)); } - -static void -setDoubleArrayOneValue(double** vpp, double value, size_t nmemb) -{ - if (*vpp) - _TIFFfree(*vpp); - *vpp = _TIFFmalloc(nmemb*sizeof(double)); - if (*vpp) - { - while (nmemb--) - ((double*)*vpp)[nmemb] = value; - } -} - -/* - * Install extra samples information. - */ -static int -setExtraSamples(TIFFDirectory* td, va_list ap, uint32* v) -{ -/* XXX: Unassociated alpha data == 999 is a known Corel Draw bug, see below */ -#define EXTRASAMPLE_COREL_UNASSALPHA 999 - - uint16* va; - uint32 i; - - *v = (uint16) va_arg(ap, uint16_vap); - if ((uint16) *v > td->td_samplesperpixel) - return 0; - va = va_arg(ap, uint16*); - if (*v > 0 && va == NULL) /* typically missing param */ - return 0; - for (i = 0; i < *v; i++) { - if (va[i] > EXTRASAMPLE_UNASSALPHA) { - /* - * XXX: Corel Draw is known to produce incorrect - * ExtraSamples tags which must be patched here if we - * want to be able to open some of the damaged TIFF - * files: - */ - if (va[i] == EXTRASAMPLE_COREL_UNASSALPHA) - va[i] = EXTRASAMPLE_UNASSALPHA; - else - return 0; - } - } - td->td_extrasamples = (uint16) *v; - _TIFFsetShortArray(&td->td_sampleinfo, va, td->td_extrasamples); - return 1; - -#undef EXTRASAMPLE_COREL_UNASSALPHA -} - -/* - * Confirm we have "samplesperpixel" ink names separated by \0. Returns - * zero if the ink names are not as expected. - */ -static uint32 -checkInkNamesString(TIFF* tif, uint32 slen, const char* s) -{ - TIFFDirectory* td = &tif->tif_dir; - uint16 i = td->td_samplesperpixel; - - if (slen > 0) { - const char* ep = s+slen; - const char* cp = s; - for (; i > 0; i--) { - for (; cp < ep && *cp != '\0'; cp++) {} - if (cp >= ep) - goto bad; - cp++; /* skip \0 */ - } - return ((uint32)(cp-s)); - } -bad: - TIFFErrorExt(tif->tif_clientdata, "TIFFSetField", - "%s: Invalid InkNames value; expecting %d names, found %d", - tif->tif_name, - td->td_samplesperpixel, - td->td_samplesperpixel-i); - return (0); -} - -static int -_TIFFVSetField(TIFF* tif, uint32 tag, va_list ap) -{ - static const char module[] = "_TIFFVSetField"; - - TIFFDirectory* td = &tif->tif_dir; - int status = 1; - uint32 v32, i, v; - char* s; - const TIFFField *fip = TIFFFindField(tif, tag, TIFF_ANY); - uint32 standard_tag = tag; - - /* - * We want to force the custom code to be used for custom - * fields even if the tag happens to match a well known - * one - important for reinterpreted handling of standard - * tag values in custom directories (ie. EXIF) - */ - if (fip->field_bit == FIELD_CUSTOM) { - standard_tag = 0; - } - - switch (standard_tag) { - case TIFFTAG_SUBFILETYPE: - td->td_subfiletype = (uint32) va_arg(ap, uint32); - break; - case TIFFTAG_IMAGEWIDTH: - td->td_imagewidth = (uint32) va_arg(ap, uint32); - break; - case TIFFTAG_IMAGELENGTH: - td->td_imagelength = (uint32) va_arg(ap, uint32); - break; - case TIFFTAG_BITSPERSAMPLE: - td->td_bitspersample = (uint16) va_arg(ap, uint16_vap); - /* - * If the data require post-decoding processing to byte-swap - * samples, set it up here. Note that since tags are required - * to be ordered, compression code can override this behaviour - * in the setup method if it wants to roll the post decoding - * work in with its normal work. - */ - if (tif->tif_flags & TIFF_SWAB) { - if (td->td_bitspersample == 8) - tif->tif_postdecode = _TIFFNoPostDecode; - else if (td->td_bitspersample == 16) - tif->tif_postdecode = _TIFFSwab16BitData; - else if (td->td_bitspersample == 24) - tif->tif_postdecode = _TIFFSwab24BitData; - else if (td->td_bitspersample == 32) - tif->tif_postdecode = _TIFFSwab32BitData; - else if (td->td_bitspersample == 64) - tif->tif_postdecode = _TIFFSwab64BitData; - else if (td->td_bitspersample == 128) /* two 64's */ - tif->tif_postdecode = _TIFFSwab64BitData; - } - break; - case TIFFTAG_COMPRESSION: - v = (uint16) va_arg(ap, uint16_vap); - /* - * If we're changing the compression scheme, the notify the - * previous module so that it can cleanup any state it's - * setup. - */ - if (TIFFFieldSet(tif, FIELD_COMPRESSION)) { - if ((uint32)td->td_compression == v) - break; - (*tif->tif_cleanup)(tif); - tif->tif_flags &= ~TIFF_CODERSETUP; - } - /* - * Setup new compression routine state. - */ - if( (status = TIFFSetCompressionScheme(tif, v)) != 0 ) - td->td_compression = (uint16) v; - else - status = 0; - break; - case TIFFTAG_PHOTOMETRIC: - td->td_photometric = (uint16) va_arg(ap, uint16_vap); - break; - case TIFFTAG_THRESHHOLDING: - td->td_threshholding = (uint16) va_arg(ap, uint16_vap); - break; - case TIFFTAG_FILLORDER: - v = (uint16) va_arg(ap, uint16_vap); - if (v != FILLORDER_LSB2MSB && v != FILLORDER_MSB2LSB) - goto badvalue; - td->td_fillorder = (uint16) v; - break; - case TIFFTAG_ORIENTATION: - v = (uint16) va_arg(ap, uint16_vap); - if (v < ORIENTATION_TOPLEFT || ORIENTATION_LEFTBOT < v) - goto badvalue; - else - td->td_orientation = (uint16) v; - break; - case TIFFTAG_SAMPLESPERPIXEL: - v = (uint16) va_arg(ap, uint16_vap); - if (v == 0) - goto badvalue; - td->td_samplesperpixel = (uint16) v; - break; - case TIFFTAG_ROWSPERSTRIP: - v32 = (uint32) va_arg(ap, uint32); - if (v32 == 0) - goto badvalue32; - td->td_rowsperstrip = v32; - if (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) { - td->td_tilelength = v32; - td->td_tilewidth = td->td_imagewidth; - } - break; - case TIFFTAG_MINSAMPLEVALUE: - td->td_minsamplevalue = (uint16) va_arg(ap, uint16_vap); - break; - case TIFFTAG_MAXSAMPLEVALUE: - td->td_maxsamplevalue = (uint16) va_arg(ap, uint16_vap); - break; - case TIFFTAG_SMINSAMPLEVALUE: - if (tif->tif_flags & TIFF_PERSAMPLE) - _TIFFsetDoubleArray(&td->td_sminsamplevalue, va_arg(ap, double*), td->td_samplesperpixel); - else - setDoubleArrayOneValue(&td->td_sminsamplevalue, va_arg(ap, double), td->td_samplesperpixel); - break; - case TIFFTAG_SMAXSAMPLEVALUE: - if (tif->tif_flags & TIFF_PERSAMPLE) - _TIFFsetDoubleArray(&td->td_smaxsamplevalue, va_arg(ap, double*), td->td_samplesperpixel); - else - setDoubleArrayOneValue(&td->td_smaxsamplevalue, va_arg(ap, double), td->td_samplesperpixel); - break; - case TIFFTAG_XRESOLUTION: - td->td_xresolution = (float) va_arg(ap, double); - break; - case TIFFTAG_YRESOLUTION: - td->td_yresolution = (float) va_arg(ap, double); - break; - case TIFFTAG_PLANARCONFIG: - v = (uint16) va_arg(ap, uint16_vap); - if (v != PLANARCONFIG_CONTIG && v != PLANARCONFIG_SEPARATE) - goto badvalue; - td->td_planarconfig = (uint16) v; - break; - case TIFFTAG_XPOSITION: - td->td_xposition = (float) va_arg(ap, double); - break; - case TIFFTAG_YPOSITION: - td->td_yposition = (float) va_arg(ap, double); - break; - case TIFFTAG_RESOLUTIONUNIT: - v = (uint16) va_arg(ap, uint16_vap); - if (v < RESUNIT_NONE || RESUNIT_CENTIMETER < v) - goto badvalue; - td->td_resolutionunit = (uint16) v; - break; - case TIFFTAG_PAGENUMBER: - td->td_pagenumber[0] = (uint16) va_arg(ap, uint16_vap); - td->td_pagenumber[1] = (uint16) va_arg(ap, uint16_vap); - break; - case TIFFTAG_HALFTONEHINTS: - td->td_halftonehints[0] = (uint16) va_arg(ap, uint16_vap); - td->td_halftonehints[1] = (uint16) va_arg(ap, uint16_vap); - break; - case TIFFTAG_COLORMAP: - v32 = (uint32)(1L<td_bitspersample); - _TIFFsetShortArray(&td->td_colormap[0], va_arg(ap, uint16*), v32); - _TIFFsetShortArray(&td->td_colormap[1], va_arg(ap, uint16*), v32); - _TIFFsetShortArray(&td->td_colormap[2], va_arg(ap, uint16*), v32); - break; - case TIFFTAG_EXTRASAMPLES: - if (!setExtraSamples(td, ap, &v)) - goto badvalue; - break; - case TIFFTAG_MATTEING: - td->td_extrasamples = (((uint16) va_arg(ap, uint16_vap)) != 0); - if (td->td_extrasamples) { - uint16 sv = EXTRASAMPLE_ASSOCALPHA; - _TIFFsetShortArray(&td->td_sampleinfo, &sv, 1); - } - break; - case TIFFTAG_TILEWIDTH: - v32 = (uint32) va_arg(ap, uint32); - if (v32 % 16) { - if (tif->tif_mode != O_RDONLY) - goto badvalue32; - TIFFWarningExt(tif->tif_clientdata, tif->tif_name, - "Nonstandard tile width %d, convert file", v32); - } - td->td_tilewidth = v32; - tif->tif_flags |= TIFF_ISTILED; - break; - case TIFFTAG_TILELENGTH: - v32 = (uint32) va_arg(ap, uint32); - if (v32 % 16) { - if (tif->tif_mode != O_RDONLY) - goto badvalue32; - TIFFWarningExt(tif->tif_clientdata, tif->tif_name, - "Nonstandard tile length %d, convert file", v32); - } - td->td_tilelength = v32; - tif->tif_flags |= TIFF_ISTILED; - break; - case TIFFTAG_TILEDEPTH: - v32 = (uint32) va_arg(ap, uint32); - if (v32 == 0) - goto badvalue32; - td->td_tiledepth = v32; - break; - case TIFFTAG_DATATYPE: - v = (uint16) va_arg(ap, uint16_vap); - switch (v) { - case DATATYPE_VOID: v = SAMPLEFORMAT_VOID; break; - case DATATYPE_INT: v = SAMPLEFORMAT_INT; break; - case DATATYPE_UINT: v = SAMPLEFORMAT_UINT; break; - case DATATYPE_IEEEFP: v = SAMPLEFORMAT_IEEEFP;break; - default: goto badvalue; - } - td->td_sampleformat = (uint16) v; - break; - case TIFFTAG_SAMPLEFORMAT: - v = (uint16) va_arg(ap, uint16_vap); - if (v < SAMPLEFORMAT_UINT || SAMPLEFORMAT_COMPLEXIEEEFP < v) - goto badvalue; - td->td_sampleformat = (uint16) v; - - /* Try to fix up the SWAB function for complex data. */ - if( td->td_sampleformat == SAMPLEFORMAT_COMPLEXINT - && td->td_bitspersample == 32 - && tif->tif_postdecode == _TIFFSwab32BitData ) - tif->tif_postdecode = _TIFFSwab16BitData; - else if( (td->td_sampleformat == SAMPLEFORMAT_COMPLEXINT - || td->td_sampleformat == SAMPLEFORMAT_COMPLEXIEEEFP) - && td->td_bitspersample == 64 - && tif->tif_postdecode == _TIFFSwab64BitData ) - tif->tif_postdecode = _TIFFSwab32BitData; - break; - case TIFFTAG_IMAGEDEPTH: - td->td_imagedepth = (uint32) va_arg(ap, uint32); - break; - case TIFFTAG_SUBIFD: - if ((tif->tif_flags & TIFF_INSUBIFD) == 0) { - td->td_nsubifd = (uint16) va_arg(ap, uint16_vap); - _TIFFsetLong8Array(&td->td_subifd, (uint64*) va_arg(ap, uint64*), - (long) td->td_nsubifd); - } else { - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Sorry, cannot nest SubIFDs", - tif->tif_name); - status = 0; - } - break; - case TIFFTAG_YCBCRPOSITIONING: - td->td_ycbcrpositioning = (uint16) va_arg(ap, uint16_vap); - break; - case TIFFTAG_YCBCRSUBSAMPLING: - td->td_ycbcrsubsampling[0] = (uint16) va_arg(ap, uint16_vap); - td->td_ycbcrsubsampling[1] = (uint16) va_arg(ap, uint16_vap); - break; - case TIFFTAG_TRANSFERFUNCTION: - v = (td->td_samplesperpixel - td->td_extrasamples) > 1 ? 3 : 1; - for (i = 0; i < v; i++) - _TIFFsetShortArray(&td->td_transferfunction[i], - va_arg(ap, uint16*), 1L<td_bitspersample); - break; - case TIFFTAG_REFERENCEBLACKWHITE: - /* XXX should check for null range */ - _TIFFsetFloatArray(&td->td_refblackwhite, va_arg(ap, float*), 6); - break; - case TIFFTAG_INKNAMES: - v = (uint16) va_arg(ap, uint16_vap); - s = va_arg(ap, char*); - v = checkInkNamesString(tif, v, s); - status = v > 0; - if( v > 0 ) { - _TIFFsetNString(&td->td_inknames, s, v); - td->td_inknameslen = v; - } - break; - case TIFFTAG_PERSAMPLE: - v = (uint16) va_arg(ap, uint16_vap); - if( v == PERSAMPLE_MULTI ) - tif->tif_flags |= TIFF_PERSAMPLE; - else - tif->tif_flags &= ~TIFF_PERSAMPLE; - break; - default: { - TIFFTagValue *tv; - int tv_size, iCustom; - - /* - * This can happen if multiple images are open with different - * codecs which have private tags. The global tag information - * table may then have tags that are valid for one file but not - * the other. If the client tries to set a tag that is not valid - * for the image's codec then we'll arrive here. This - * happens, for example, when tiffcp is used to convert between - * compression schemes and codec-specific tags are blindly copied. - */ - if(fip == NULL || fip->field_bit != FIELD_CUSTOM) { - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Invalid %stag \"%s\" (not supported by codec)", - tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "", - fip ? fip->field_name : "Unknown"); - status = 0; - break; - } - - /* - * Find the existing entry for this custom value. - */ - tv = NULL; - for (iCustom = 0; iCustom < td->td_customValueCount; iCustom++) { - if (td->td_customValues[iCustom].info->field_tag == tag) { - tv = td->td_customValues + iCustom; - if (tv->value != NULL) { - _TIFFfree(tv->value); - tv->value = NULL; - } - break; - } - } - - /* - * Grow the custom list if the entry was not found. - */ - if(tv == NULL) { - TIFFTagValue *new_customValues; - - td->td_customValueCount++; - new_customValues = (TIFFTagValue *) - _TIFFrealloc(td->td_customValues, - sizeof(TIFFTagValue) * td->td_customValueCount); - if (!new_customValues) { - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Failed to allocate space for list of custom values", - tif->tif_name); - status = 0; - goto end; - } - - td->td_customValues = new_customValues; - - tv = td->td_customValues + (td->td_customValueCount - 1); - tv->info = fip; - tv->value = NULL; - tv->count = 0; - } - - /* - * Set custom value ... save a copy of the custom tag value. - */ - tv_size = _TIFFDataSize(fip->field_type); - if (tv_size == 0) { - status = 0; - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Bad field type %d for \"%s\"", - tif->tif_name, fip->field_type, - fip->field_name); - goto end; - } - - if (fip->field_type == TIFF_ASCII) - { - uint32 ma; - char* mb; - if (fip->field_passcount) - { - assert(fip->field_writecount==TIFF_VARIABLE2); - ma=(uint32)va_arg(ap,uint32); - mb=(char*)va_arg(ap,char*); - } - else - { - mb=(char*)va_arg(ap,char*); - ma=(uint32)(strlen(mb)+1); - } - tv->count=ma; - setByteArray(&tv->value,mb,ma,1); - } - else - { - if (fip->field_passcount) { - if (fip->field_writecount == TIFF_VARIABLE2) - tv->count = (uint32) va_arg(ap, uint32); - else - tv->count = (int) va_arg(ap, int); - } else if (fip->field_writecount == TIFF_VARIABLE - || fip->field_writecount == TIFF_VARIABLE2) - tv->count = 1; - else if (fip->field_writecount == TIFF_SPP) - tv->count = td->td_samplesperpixel; - else - tv->count = fip->field_writecount; - - if (tv->count == 0) { - status = 0; - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Null count for \"%s\" (type " - "%d, writecount %d, passcount %d)", - tif->tif_name, - fip->field_name, - fip->field_type, - fip->field_writecount, - fip->field_passcount); - goto end; - } - - tv->value = _TIFFCheckMalloc(tif, tv->count, tv_size, - "custom tag binary object"); - if (!tv->value) { - status = 0; - goto end; - } - - if (fip->field_tag == TIFFTAG_DOTRANGE - && strcmp(fip->field_name,"DotRange") == 0) { - /* TODO: This is an evil exception and should not have been - handled this way ... likely best if we move it into - the directory structure with an explicit field in - libtiff 4.1 and assign it a FIELD_ value */ - uint16 v[2]; - v[0] = (uint16)va_arg(ap, int); - v[1] = (uint16)va_arg(ap, int); - _TIFFmemcpy(tv->value, &v, 4); - } - - else if (fip->field_passcount - || fip->field_writecount == TIFF_VARIABLE - || fip->field_writecount == TIFF_VARIABLE2 - || fip->field_writecount == TIFF_SPP - || tv->count > 1) { - _TIFFmemcpy(tv->value, va_arg(ap, void *), - tv->count * tv_size); - } else { - char *val = (char *)tv->value; - assert( tv->count == 1 ); - - switch (fip->field_type) { - case TIFF_BYTE: - case TIFF_UNDEFINED: - { - uint8 v = (uint8)va_arg(ap, int); - _TIFFmemcpy(val, &v, tv_size); - } - break; - case TIFF_SBYTE: - { - int8 v = (int8)va_arg(ap, int); - _TIFFmemcpy(val, &v, tv_size); - } - break; - case TIFF_SHORT: - { - uint16 v = (uint16)va_arg(ap, int); - _TIFFmemcpy(val, &v, tv_size); - } - break; - case TIFF_SSHORT: - { - int16 v = (int16)va_arg(ap, int); - _TIFFmemcpy(val, &v, tv_size); - } - break; - case TIFF_LONG: - case TIFF_IFD: - { - uint32 v = va_arg(ap, uint32); - _TIFFmemcpy(val, &v, tv_size); - } - break; - case TIFF_SLONG: - { - int32 v = va_arg(ap, int32); - _TIFFmemcpy(val, &v, tv_size); - } - break; - case TIFF_LONG8: - case TIFF_IFD8: - { - uint64 v = va_arg(ap, uint64); - _TIFFmemcpy(val, &v, tv_size); - } - break; - case TIFF_SLONG8: - { - int64 v = va_arg(ap, int64); - _TIFFmemcpy(val, &v, tv_size); - } - break; - case TIFF_RATIONAL: - case TIFF_SRATIONAL: - case TIFF_FLOAT: - { - float v = (float)va_arg(ap, double); - _TIFFmemcpy(val, &v, tv_size); - } - break; - case TIFF_DOUBLE: - { - double v = va_arg(ap, double); - _TIFFmemcpy(val, &v, tv_size); - } - break; - default: - _TIFFmemset(val, 0, tv_size); - status = 0; - break; - } - } - } - } - } - if (status) { - const TIFFField* fip=TIFFFieldWithTag(tif,tag); - if (fip) - TIFFSetFieldBit(tif, fip->field_bit); - tif->tif_flags |= TIFF_DIRTYDIRECT; - } - -end: - va_end(ap); - return (status); -badvalue: - { - const TIFFField* fip=TIFFFieldWithTag(tif,tag); - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Bad value %u for \"%s\" tag", - tif->tif_name, v, - fip ? fip->field_name : "Unknown"); - va_end(ap); - } - return (0); -badvalue32: - { - const TIFFField* fip=TIFFFieldWithTag(tif,tag); - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Bad value %u for \"%s\" tag", - tif->tif_name, v32, - fip ? fip->field_name : "Unknown"); - va_end(ap); - } - return (0); -} - -/* - * Return 1/0 according to whether or not - * it is permissible to set the tag's value. - * Note that we allow ImageLength to be changed - * so that we can append and extend to images. - * Any other tag may not be altered once writing - * has commenced, unless its value has no effect - * on the format of the data that is written. - */ -static int -OkToChangeTag(TIFF* tif, uint32 tag) -{ - const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY); - if (!fip) { /* unknown tag */ - TIFFErrorExt(tif->tif_clientdata, "TIFFSetField", "%s: Unknown %stag %u", - tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "", tag); - return (0); - } - if (tag != TIFFTAG_IMAGELENGTH && (tif->tif_flags & TIFF_BEENWRITING) && - !fip->field_oktochange) { - /* - * Consult info table to see if tag can be changed - * after we've started writing. We only allow changes - * to those tags that don't/shouldn't affect the - * compression and/or format of the data. - */ - TIFFErrorExt(tif->tif_clientdata, "TIFFSetField", - "%s: Cannot modify tag \"%s\" while writing", - tif->tif_name, fip->field_name); - return (0); - } - return (1); -} - -/* - * Record the value of a field in the - * internal directory structure. The - * field will be written to the file - * when/if the directory structure is - * updated. - */ -int -TIFFSetField(TIFF* tif, uint32 tag, ...) -{ - va_list ap; - int status; - - va_start(ap, tag); - status = TIFFVSetField(tif, tag, ap); - va_end(ap); - return (status); -} - -/* - * Clear the contents of the field in the internal structure. - */ -int -TIFFUnsetField(TIFF* tif, uint32 tag) -{ - const TIFFField *fip = TIFFFieldWithTag(tif, tag); - TIFFDirectory* td = &tif->tif_dir; - - if( !fip ) - return 0; - - if( fip->field_bit != FIELD_CUSTOM ) - TIFFClrFieldBit(tif, fip->field_bit); - else - { - TIFFTagValue *tv = NULL; - int i; - - for (i = 0; i < td->td_customValueCount; i++) { - - tv = td->td_customValues + i; - if( tv->info->field_tag == tag ) - break; - } - - if( i < td->td_customValueCount ) - { - _TIFFfree(tv->value); - for( ; i < td->td_customValueCount-1; i++) { - td->td_customValues[i] = td->td_customValues[i+1]; - } - td->td_customValueCount--; - } - } - - tif->tif_flags |= TIFF_DIRTYDIRECT; - - return (1); -} - -/* - * Like TIFFSetField, but taking a varargs - * parameter list. This routine is useful - * for building higher-level interfaces on - * top of the library. - */ -int -TIFFVSetField(TIFF* tif, uint32 tag, va_list ap) -{ - return OkToChangeTag(tif, tag) ? - (*tif->tif_tagmethods.vsetfield)(tif, tag, ap) : 0; -} - -static int -_TIFFVGetField(TIFF* tif, uint32 tag, va_list ap) -{ - TIFFDirectory* td = &tif->tif_dir; - int ret_val = 1; - uint32 standard_tag = tag; - const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY); - - /* - * We want to force the custom code to be used for custom - * fields even if the tag happens to match a well known - * one - important for reinterpreted handling of standard - * tag values in custom directories (ie. EXIF) - */ - if (fip->field_bit == FIELD_CUSTOM) { - standard_tag = 0; - } - - switch (standard_tag) { - case TIFFTAG_SUBFILETYPE: - *va_arg(ap, uint32*) = td->td_subfiletype; - break; - case TIFFTAG_IMAGEWIDTH: - *va_arg(ap, uint32*) = td->td_imagewidth; - break; - case TIFFTAG_IMAGELENGTH: - *va_arg(ap, uint32*) = td->td_imagelength; - break; - case TIFFTAG_BITSPERSAMPLE: - *va_arg(ap, uint16*) = td->td_bitspersample; - break; - case TIFFTAG_COMPRESSION: - *va_arg(ap, uint16*) = td->td_compression; - break; - case TIFFTAG_PHOTOMETRIC: - *va_arg(ap, uint16*) = td->td_photometric; - break; - case TIFFTAG_THRESHHOLDING: - *va_arg(ap, uint16*) = td->td_threshholding; - break; - case TIFFTAG_FILLORDER: - *va_arg(ap, uint16*) = td->td_fillorder; - break; - case TIFFTAG_ORIENTATION: - *va_arg(ap, uint16*) = td->td_orientation; - break; - case TIFFTAG_SAMPLESPERPIXEL: - *va_arg(ap, uint16*) = td->td_samplesperpixel; - break; - case TIFFTAG_ROWSPERSTRIP: - *va_arg(ap, uint32*) = td->td_rowsperstrip; - break; - case TIFFTAG_MINSAMPLEVALUE: - *va_arg(ap, uint16*) = td->td_minsamplevalue; - break; - case TIFFTAG_MAXSAMPLEVALUE: - *va_arg(ap, uint16*) = td->td_maxsamplevalue; - break; - case TIFFTAG_SMINSAMPLEVALUE: - if (tif->tif_flags & TIFF_PERSAMPLE) - *va_arg(ap, double**) = td->td_sminsamplevalue; - else - { - /* libtiff historially treats this as a single value. */ - uint16 i; - double v = td->td_sminsamplevalue[0]; - for (i=1; i < td->td_samplesperpixel; ++i) - if( td->td_sminsamplevalue[i] < v ) - v = td->td_sminsamplevalue[i]; - *va_arg(ap, double*) = v; - } - break; - case TIFFTAG_SMAXSAMPLEVALUE: - if (tif->tif_flags & TIFF_PERSAMPLE) - *va_arg(ap, double**) = td->td_smaxsamplevalue; - else - { - /* libtiff historially treats this as a single value. */ - uint16 i; - double v = td->td_smaxsamplevalue[0]; - for (i=1; i < td->td_samplesperpixel; ++i) - if( td->td_smaxsamplevalue[i] > v ) - v = td->td_smaxsamplevalue[i]; - *va_arg(ap, double*) = v; - } - break; - case TIFFTAG_XRESOLUTION: - *va_arg(ap, float*) = td->td_xresolution; - break; - case TIFFTAG_YRESOLUTION: - *va_arg(ap, float*) = td->td_yresolution; - break; - case TIFFTAG_PLANARCONFIG: - *va_arg(ap, uint16*) = td->td_planarconfig; - break; - case TIFFTAG_XPOSITION: - *va_arg(ap, float*) = td->td_xposition; - break; - case TIFFTAG_YPOSITION: - *va_arg(ap, float*) = td->td_yposition; - break; - case TIFFTAG_RESOLUTIONUNIT: - *va_arg(ap, uint16*) = td->td_resolutionunit; - break; - case TIFFTAG_PAGENUMBER: - *va_arg(ap, uint16*) = td->td_pagenumber[0]; - *va_arg(ap, uint16*) = td->td_pagenumber[1]; - break; - case TIFFTAG_HALFTONEHINTS: - *va_arg(ap, uint16*) = td->td_halftonehints[0]; - *va_arg(ap, uint16*) = td->td_halftonehints[1]; - break; - case TIFFTAG_COLORMAP: - *va_arg(ap, uint16**) = td->td_colormap[0]; - *va_arg(ap, uint16**) = td->td_colormap[1]; - *va_arg(ap, uint16**) = td->td_colormap[2]; - break; - case TIFFTAG_STRIPOFFSETS: - case TIFFTAG_TILEOFFSETS: - _TIFFFillStriles( tif ); - *va_arg(ap, uint64**) = td->td_stripoffset; - break; - case TIFFTAG_STRIPBYTECOUNTS: - case TIFFTAG_TILEBYTECOUNTS: - _TIFFFillStriles( tif ); - *va_arg(ap, uint64**) = td->td_stripbytecount; - break; - case TIFFTAG_MATTEING: - *va_arg(ap, uint16*) = - (td->td_extrasamples == 1 && - td->td_sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA); - break; - case TIFFTAG_EXTRASAMPLES: - *va_arg(ap, uint16*) = td->td_extrasamples; - *va_arg(ap, uint16**) = td->td_sampleinfo; - break; - case TIFFTAG_TILEWIDTH: - *va_arg(ap, uint32*) = td->td_tilewidth; - break; - case TIFFTAG_TILELENGTH: - *va_arg(ap, uint32*) = td->td_tilelength; - break; - case TIFFTAG_TILEDEPTH: - *va_arg(ap, uint32*) = td->td_tiledepth; - break; - case TIFFTAG_DATATYPE: - switch (td->td_sampleformat) { - case SAMPLEFORMAT_UINT: - *va_arg(ap, uint16*) = DATATYPE_UINT; - break; - case SAMPLEFORMAT_INT: - *va_arg(ap, uint16*) = DATATYPE_INT; - break; - case SAMPLEFORMAT_IEEEFP: - *va_arg(ap, uint16*) = DATATYPE_IEEEFP; - break; - case SAMPLEFORMAT_VOID: - *va_arg(ap, uint16*) = DATATYPE_VOID; - break; - } - break; - case TIFFTAG_SAMPLEFORMAT: - *va_arg(ap, uint16*) = td->td_sampleformat; - break; - case TIFFTAG_IMAGEDEPTH: - *va_arg(ap, uint32*) = td->td_imagedepth; - break; - case TIFFTAG_SUBIFD: - *va_arg(ap, uint16*) = td->td_nsubifd; - *va_arg(ap, uint64**) = td->td_subifd; - break; - case TIFFTAG_YCBCRPOSITIONING: - *va_arg(ap, uint16*) = td->td_ycbcrpositioning; - break; - case TIFFTAG_YCBCRSUBSAMPLING: - *va_arg(ap, uint16*) = td->td_ycbcrsubsampling[0]; - *va_arg(ap, uint16*) = td->td_ycbcrsubsampling[1]; - break; - case TIFFTAG_TRANSFERFUNCTION: - *va_arg(ap, uint16**) = td->td_transferfunction[0]; - if (td->td_samplesperpixel - td->td_extrasamples > 1) { - *va_arg(ap, uint16**) = td->td_transferfunction[1]; - *va_arg(ap, uint16**) = td->td_transferfunction[2]; - } - break; - case TIFFTAG_REFERENCEBLACKWHITE: - *va_arg(ap, float**) = td->td_refblackwhite; - break; - case TIFFTAG_INKNAMES: - *va_arg(ap, char**) = td->td_inknames; - break; - default: - { - int i; - - /* - * This can happen if multiple images are open - * with different codecs which have private - * tags. The global tag information table may - * then have tags that are valid for one file - * but not the other. If the client tries to - * get a tag that is not valid for the image's - * codec then we'll arrive here. - */ - if( fip == NULL || fip->field_bit != FIELD_CUSTOM ) - { - TIFFErrorExt(tif->tif_clientdata, "_TIFFVGetField", - "%s: Invalid %stag \"%s\" " - "(not supported by codec)", - tif->tif_name, - isPseudoTag(tag) ? "pseudo-" : "", - fip ? fip->field_name : "Unknown"); - ret_val = 0; - break; - } - - /* - * Do we have a custom value? - */ - ret_val = 0; - for (i = 0; i < td->td_customValueCount; i++) { - TIFFTagValue *tv = td->td_customValues + i; - - if (tv->info->field_tag != tag) - continue; - - if (fip->field_passcount) { - if (fip->field_readcount == TIFF_VARIABLE2) - *va_arg(ap, uint32*) = (uint32)tv->count; - else /* Assume TIFF_VARIABLE */ - *va_arg(ap, uint16*) = (uint16)tv->count; - *va_arg(ap, void **) = tv->value; - ret_val = 1; - } else if (fip->field_tag == TIFFTAG_DOTRANGE - && strcmp(fip->field_name,"DotRange") == 0) { - /* TODO: This is an evil exception and should not have been - handled this way ... likely best if we move it into - the directory structure with an explicit field in - libtiff 4.1 and assign it a FIELD_ value */ - *va_arg(ap, uint16*) = ((uint16 *)tv->value)[0]; - *va_arg(ap, uint16*) = ((uint16 *)tv->value)[1]; - ret_val = 1; - } else { - if (fip->field_type == TIFF_ASCII - || fip->field_readcount == TIFF_VARIABLE - || fip->field_readcount == TIFF_VARIABLE2 - || fip->field_readcount == TIFF_SPP - || tv->count > 1) { - *va_arg(ap, void **) = tv->value; - ret_val = 1; - } else { - char *val = (char *)tv->value; - assert( tv->count == 1 ); - switch (fip->field_type) { - case TIFF_BYTE: - case TIFF_UNDEFINED: - *va_arg(ap, uint8*) = - *(uint8 *)val; - ret_val = 1; - break; - case TIFF_SBYTE: - *va_arg(ap, int8*) = - *(int8 *)val; - ret_val = 1; - break; - case TIFF_SHORT: - *va_arg(ap, uint16*) = - *(uint16 *)val; - ret_val = 1; - break; - case TIFF_SSHORT: - *va_arg(ap, int16*) = - *(int16 *)val; - ret_val = 1; - break; - case TIFF_LONG: - case TIFF_IFD: - *va_arg(ap, uint32*) = - *(uint32 *)val; - ret_val = 1; - break; - case TIFF_SLONG: - *va_arg(ap, int32*) = - *(int32 *)val; - ret_val = 1; - break; - case TIFF_LONG8: - case TIFF_IFD8: - *va_arg(ap, uint64*) = - *(uint64 *)val; - ret_val = 1; - break; - case TIFF_SLONG8: - *va_arg(ap, int64*) = - *(int64 *)val; - ret_val = 1; - break; - case TIFF_RATIONAL: - case TIFF_SRATIONAL: - case TIFF_FLOAT: - *va_arg(ap, float*) = - *(float *)val; - ret_val = 1; - break; - case TIFF_DOUBLE: - *va_arg(ap, double*) = - *(double *)val; - ret_val = 1; - break; - default: - ret_val = 0; - break; - } - } - } - break; - } - } - } - return(ret_val); -} - -/* - * Return the value of a field in the - * internal directory structure. - */ -int -TIFFGetField(TIFF* tif, uint32 tag, ...) -{ - int status; - va_list ap; - - va_start(ap, tag); - status = TIFFVGetField(tif, tag, ap); - va_end(ap); - return (status); -} - -/* - * Like TIFFGetField, but taking a varargs - * parameter list. This routine is useful - * for building higher-level interfaces on - * top of the library. - */ -int -TIFFVGetField(TIFF* tif, uint32 tag, va_list ap) -{ - const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY); - return (fip && (isPseudoTag(tag) || TIFFFieldSet(tif, fip->field_bit)) ? - (*tif->tif_tagmethods.vgetfield)(tif, tag, ap) : 0); -} - -#define CleanupField(member) { \ - if (td->member) { \ - _TIFFfree(td->member); \ - td->member = 0; \ - } \ -} - -/* - * Release storage associated with a directory. - */ -void -TIFFFreeDirectory(TIFF* tif) -{ - TIFFDirectory *td = &tif->tif_dir; - int i; - - _TIFFmemset(td->td_fieldsset, 0, FIELD_SETLONGS); - CleanupField(td_sminsamplevalue); - CleanupField(td_smaxsamplevalue); - CleanupField(td_colormap[0]); - CleanupField(td_colormap[1]); - CleanupField(td_colormap[2]); - CleanupField(td_sampleinfo); - CleanupField(td_subifd); - CleanupField(td_inknames); - CleanupField(td_refblackwhite); - CleanupField(td_transferfunction[0]); - CleanupField(td_transferfunction[1]); - CleanupField(td_transferfunction[2]); - CleanupField(td_stripoffset); - CleanupField(td_stripbytecount); - TIFFClrFieldBit(tif, FIELD_YCBCRSUBSAMPLING); - TIFFClrFieldBit(tif, FIELD_YCBCRPOSITIONING); - - /* Cleanup custom tag values */ - for( i = 0; i < td->td_customValueCount; i++ ) { - if (td->td_customValues[i].value) - _TIFFfree(td->td_customValues[i].value); - } - - td->td_customValueCount = 0; - CleanupField(td_customValues); - -#if defined(DEFER_STRILE_LOAD) - _TIFFmemset( &(td->td_stripoffset_entry), 0, sizeof(TIFFDirEntry)); - _TIFFmemset( &(td->td_stripbytecount_entry), 0, sizeof(TIFFDirEntry)); -#endif -} -#undef CleanupField - -/* - * Client Tag extension support (from Niles Ritter). - */ -static TIFFExtendProc _TIFFextender = (TIFFExtendProc) NULL; - -TIFFExtendProc -TIFFSetTagExtender(TIFFExtendProc extender) -{ - TIFFExtendProc prev = _TIFFextender; - _TIFFextender = extender; - return (prev); -} - -/* - * Setup for a new directory. Should we automatically call - * TIFFWriteDirectory() if the current one is dirty? - * - * The newly created directory will not exist on the file till - * TIFFWriteDirectory(), TIFFFlush() or TIFFClose() is called. - */ -int -TIFFCreateDirectory(TIFF* tif) -{ - TIFFDefaultDirectory(tif); - tif->tif_diroff = 0; - tif->tif_nextdiroff = 0; - tif->tif_curoff = 0; - tif->tif_row = (uint32) -1; - tif->tif_curstrip = (uint32) -1; - - return 0; -} - -int -TIFFCreateCustomDirectory(TIFF* tif, const TIFFFieldArray* infoarray) -{ - TIFFDefaultDirectory(tif); - - /* - * Reset the field definitions to match the application provided list. - * Hopefully TIFFDefaultDirectory() won't have done anything irreversable - * based on it's assumption this is an image directory. - */ - _TIFFSetupFields(tif, infoarray); - - tif->tif_diroff = 0; - tif->tif_nextdiroff = 0; - tif->tif_curoff = 0; - tif->tif_row = (uint32) -1; - tif->tif_curstrip = (uint32) -1; - - return 0; -} - -int -TIFFCreateEXIFDirectory(TIFF* tif) -{ - const TIFFFieldArray* exifFieldArray; - exifFieldArray = _TIFFGetExifFields(); - return TIFFCreateCustomDirectory(tif, exifFieldArray); -} - -/* - * Setup a default directory structure. - */ -int -TIFFDefaultDirectory(TIFF* tif) -{ - register TIFFDirectory* td = &tif->tif_dir; - const TIFFFieldArray* tiffFieldArray; - - tiffFieldArray = _TIFFGetFields(); - _TIFFSetupFields(tif, tiffFieldArray); - - _TIFFmemset(td, 0, sizeof (*td)); - td->td_fillorder = FILLORDER_MSB2LSB; - td->td_bitspersample = 1; - td->td_threshholding = THRESHHOLD_BILEVEL; - td->td_orientation = ORIENTATION_TOPLEFT; - td->td_samplesperpixel = 1; - td->td_rowsperstrip = (uint32) -1; - td->td_tilewidth = 0; - td->td_tilelength = 0; - td->td_tiledepth = 1; - td->td_stripbytecountsorted = 1; /* Our own arrays always sorted. */ - td->td_resolutionunit = RESUNIT_INCH; - td->td_sampleformat = SAMPLEFORMAT_UINT; - td->td_imagedepth = 1; - td->td_ycbcrsubsampling[0] = 2; - td->td_ycbcrsubsampling[1] = 2; - td->td_ycbcrpositioning = YCBCRPOSITION_CENTERED; - tif->tif_postdecode = _TIFFNoPostDecode; - tif->tif_foundfield = NULL; - tif->tif_tagmethods.vsetfield = _TIFFVSetField; - tif->tif_tagmethods.vgetfield = _TIFFVGetField; - tif->tif_tagmethods.printdir = NULL; - /* - * Give client code a chance to install their own - * tag extensions & methods, prior to compression overloads. - */ - if (_TIFFextender) - (*_TIFFextender)(tif); - (void) TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE); - /* - * NB: The directory is marked dirty as a result of setting - * up the default compression scheme. However, this really - * isn't correct -- we want TIFF_DIRTYDIRECT to be set only - * if the user does something. We could just do the setup - * by hand, but it seems better to use the normal mechanism - * (i.e. TIFFSetField). - */ - tif->tif_flags &= ~TIFF_DIRTYDIRECT; - - /* - * As per http://bugzilla.remotesensing.org/show_bug.cgi?id=19 - * we clear the ISTILED flag when setting up a new directory. - * Should we also be clearing stuff like INSUBIFD? - */ - tif->tif_flags &= ~TIFF_ISTILED; - - return (1); -} - -static int -TIFFAdvanceDirectory(TIFF* tif, uint64* nextdir, uint64* off) -{ - static const char module[] = "TIFFAdvanceDirectory"; - if (isMapped(tif)) - { - uint64 poff=*nextdir; - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - tmsize_t poffa,poffb,poffc,poffd; - uint16 dircount; - uint32 nextdir32; - poffa=(tmsize_t)poff; - poffb=poffa+sizeof(uint16); - if (((uint64)poffa!=poff)||(poffbtif->tif_size)) - { - TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory count"); - return(0); - } - _TIFFmemcpy(&dircount,tif->tif_base+poffa,sizeof(uint16)); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabShort(&dircount); - poffc=poffb+dircount*12; - poffd=poffc+sizeof(uint32); - if ((poffctif->tif_size)) - { - TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory link"); - return(0); - } - if (off!=NULL) - *off=(uint64)poffc; - _TIFFmemcpy(&nextdir32,tif->tif_base+poffc,sizeof(uint32)); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(&nextdir32); - *nextdir=nextdir32; - } - else - { - tmsize_t poffa,poffb,poffc,poffd; - uint64 dircount64; - uint16 dircount16; - poffa=(tmsize_t)poff; - poffb=poffa+sizeof(uint64); - if (((uint64)poffa!=poff)||(poffbtif->tif_size)) - { - TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory count"); - return(0); - } - _TIFFmemcpy(&dircount64,tif->tif_base+poffa,sizeof(uint64)); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8(&dircount64); - if (dircount64>0xFFFF) - { - TIFFErrorExt(tif->tif_clientdata,module,"Sanity check on directory count failed"); - return(0); - } - dircount16=(uint16)dircount64; - poffc=poffb+dircount16*20; - poffd=poffc+sizeof(uint64); - if ((poffctif->tif_size)) - { - TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory link"); - return(0); - } - if (off!=NULL) - *off=(uint64)poffc; - _TIFFmemcpy(nextdir,tif->tif_base+poffc,sizeof(uint64)); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8(nextdir); - } - return(1); - } - else - { - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - uint16 dircount; - uint32 nextdir32; - if (!SeekOK(tif, *nextdir) || - !ReadOK(tif, &dircount, sizeof (uint16))) { - TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory count", - tif->tif_name); - return (0); - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabShort(&dircount); - if (off != NULL) - *off = TIFFSeekFile(tif, - dircount*12, SEEK_CUR); - else - (void) TIFFSeekFile(tif, - dircount*12, SEEK_CUR); - if (!ReadOK(tif, &nextdir32, sizeof (uint32))) { - TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory link", - tif->tif_name); - return (0); - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong(&nextdir32); - *nextdir=nextdir32; - } - else - { - uint64 dircount64; - uint16 dircount16; - if (!SeekOK(tif, *nextdir) || - !ReadOK(tif, &dircount64, sizeof (uint64))) { - TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory count", - tif->tif_name); - return (0); - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong8(&dircount64); - if (dircount64>0xFFFF) - { - TIFFErrorExt(tif->tif_clientdata, module, "Error fetching directory count"); - return(0); - } - dircount16 = (uint16)dircount64; - if (off != NULL) - *off = TIFFSeekFile(tif, - dircount16*20, SEEK_CUR); - else - (void) TIFFSeekFile(tif, - dircount16*20, SEEK_CUR); - if (!ReadOK(tif, nextdir, sizeof (uint64))) { - TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory link", - tif->tif_name); - return (0); - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong8(nextdir); - } - return (1); - } -} - -/* - * Count the number of directories in a file. - */ -uint16 -TIFFNumberOfDirectories(TIFF* tif) -{ - uint64 nextdir; - uint16 n; - if (!(tif->tif_flags&TIFF_BIGTIFF)) - nextdir = tif->tif_header.classic.tiff_diroff; - else - nextdir = tif->tif_header.big.tiff_diroff; - n = 0; - while (nextdir != 0 && TIFFAdvanceDirectory(tif, &nextdir, NULL)) - n++; - return (n); -} - -/* - * Set the n-th directory as the current directory. - * NB: Directories are numbered starting at 0. - */ -int -TIFFSetDirectory(TIFF* tif, uint16 dirn) -{ - uint64 nextdir; - uint16 n; - - if (!(tif->tif_flags&TIFF_BIGTIFF)) - nextdir = tif->tif_header.classic.tiff_diroff; - else - nextdir = tif->tif_header.big.tiff_diroff; - for (n = dirn; n > 0 && nextdir != 0; n--) - if (!TIFFAdvanceDirectory(tif, &nextdir, NULL)) - return (0); - tif->tif_nextdiroff = nextdir; - /* - * Set curdir to the actual directory index. The - * -1 is because TIFFReadDirectory will increment - * tif_curdir after successfully reading the directory. - */ - tif->tif_curdir = (dirn - n) - 1; - /* - * Reset tif_dirnumber counter and start new list of seen directories. - * We need this to prevent IFD loops. - */ - tif->tif_dirnumber = 0; - return (TIFFReadDirectory(tif)); -} - -/* - * Set the current directory to be the directory - * located at the specified file offset. This interface - * is used mainly to access directories linked with - * the SubIFD tag (e.g. thumbnail images). - */ -int -TIFFSetSubDirectory(TIFF* tif, uint64 diroff) -{ - tif->tif_nextdiroff = diroff; - /* - * Reset tif_dirnumber counter and start new list of seen directories. - * We need this to prevent IFD loops. - */ - tif->tif_dirnumber = 0; - return (TIFFReadDirectory(tif)); -} - -/* - * Return file offset of the current directory. - */ -uint64 -TIFFCurrentDirOffset(TIFF* tif) -{ - return (tif->tif_diroff); -} - -/* - * Return an indication of whether or not we are - * at the last directory in the file. - */ -int -TIFFLastDirectory(TIFF* tif) -{ - return (tif->tif_nextdiroff == 0); -} - -/* - * Unlink the specified directory from the directory chain. - */ -int -TIFFUnlinkDirectory(TIFF* tif, uint16 dirn) -{ - static const char module[] = "TIFFUnlinkDirectory"; - uint64 nextdir; - uint64 off; - uint16 n; - - if (tif->tif_mode == O_RDONLY) { - TIFFErrorExt(tif->tif_clientdata, module, - "Can not unlink directory in read-only file"); - return (0); - } - /* - * Go to the directory before the one we want - * to unlink and nab the offset of the link - * field we'll need to patch. - */ - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - nextdir = tif->tif_header.classic.tiff_diroff; - off = 4; - } - else - { - nextdir = tif->tif_header.big.tiff_diroff; - off = 8; - } - for (n = dirn-1; n > 0; n--) { - if (nextdir == 0) { - TIFFErrorExt(tif->tif_clientdata, module, "Directory %d does not exist", dirn); - return (0); - } - if (!TIFFAdvanceDirectory(tif, &nextdir, &off)) - return (0); - } - /* - * Advance to the directory to be unlinked and fetch - * the offset of the directory that follows. - */ - if (!TIFFAdvanceDirectory(tif, &nextdir, NULL)) - return (0); - /* - * Go back and patch the link field of the preceding - * directory to point to the offset of the directory - * that follows. - */ - (void) TIFFSeekFile(tif, off, SEEK_SET); - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - uint32 nextdir32; - nextdir32=(uint32)nextdir; - assert((uint64)nextdir32==nextdir); - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong(&nextdir32); - if (!WriteOK(tif, &nextdir32, sizeof (uint32))) { - TIFFErrorExt(tif->tif_clientdata, module, "Error writing directory link"); - return (0); - } - } - else - { - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong8(&nextdir); - if (!WriteOK(tif, &nextdir, sizeof (uint64))) { - TIFFErrorExt(tif->tif_clientdata, module, "Error writing directory link"); - return (0); - } - } - /* - * Leave directory state setup safely. We don't have - * facilities for doing inserting and removing directories, - * so it's safest to just invalidate everything. This - * means that the caller can only append to the directory - * chain. - */ - (*tif->tif_cleanup)(tif); - if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) { - _TIFFfree(tif->tif_rawdata); - tif->tif_rawdata = NULL; - tif->tif_rawcc = 0; - tif->tif_rawdataoff = 0; - tif->tif_rawdataloaded = 0; - } - tif->tif_flags &= ~(TIFF_BEENWRITING|TIFF_BUFFERSETUP|TIFF_POSTENCODE|TIFF_BUF4WRITE); - TIFFFreeDirectory(tif); - TIFFDefaultDirectory(tif); - tif->tif_diroff = 0; /* force link on next write */ - tif->tif_nextdiroff = 0; /* next write must be at end */ - tif->tif_curoff = 0; - tif->tif_row = (uint32) -1; - tif->tif_curstrip = (uint32) -1; - return (1); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_dir.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * + * Directory Tag Get & Set Routines. + * (and also some miscellaneous stuff) + */ +#include "tiffiop.h" + +/* + * These are used in the backwards compatibility code... + */ +#define DATATYPE_VOID 0 /* !untyped data */ +#define DATATYPE_INT 1 /* !signed integer data */ +#define DATATYPE_UINT 2 /* !unsigned integer data */ +#define DATATYPE_IEEEFP 3 /* !IEEE floating point data */ + +static void +setByteArray(void** vpp, void* vp, size_t nmemb, size_t elem_size) +{ + if (*vpp) + _TIFFfree(*vpp), *vpp = 0; + if (vp) { + tmsize_t bytes = (tmsize_t)(nmemb * elem_size); + if (elem_size && bytes / elem_size == nmemb) + *vpp = (void*) _TIFFmalloc(bytes); + if (*vpp) + _TIFFmemcpy(*vpp, vp, bytes); + } +} +void _TIFFsetByteArray(void** vpp, void* vp, uint32 n) + { setByteArray(vpp, vp, n, 1); } +void _TIFFsetString(char** cpp, char* cp) + { setByteArray((void**) cpp, (void*) cp, strlen(cp)+1, 1); } +void _TIFFsetNString(char** cpp, char* cp, uint32 n) + { setByteArray((void**) cpp, (void*) cp, n, 1); } +void _TIFFsetShortArray(uint16** wpp, uint16* wp, uint32 n) + { setByteArray((void**) wpp, (void*) wp, n, sizeof (uint16)); } +void _TIFFsetLongArray(uint32** lpp, uint32* lp, uint32 n) + { setByteArray((void**) lpp, (void*) lp, n, sizeof (uint32)); } +void _TIFFsetLong8Array(uint64** lpp, uint64* lp, uint32 n) + { setByteArray((void**) lpp, (void*) lp, n, sizeof (uint64)); } +void _TIFFsetFloatArray(float** fpp, float* fp, uint32 n) + { setByteArray((void**) fpp, (void*) fp, n, sizeof (float)); } +void _TIFFsetDoubleArray(double** dpp, double* dp, uint32 n) + { setByteArray((void**) dpp, (void*) dp, n, sizeof (double)); } + +static void +setDoubleArrayOneValue(double** vpp, double value, size_t nmemb) +{ + if (*vpp) + _TIFFfree(*vpp); + *vpp = _TIFFmalloc(nmemb*sizeof(double)); + if (*vpp) + { + while (nmemb--) + ((double*)*vpp)[nmemb] = value; + } +} + +/* + * Install extra samples information. + */ +static int +setExtraSamples(TIFFDirectory* td, va_list ap, uint32* v) +{ +/* XXX: Unassociated alpha data == 999 is a known Corel Draw bug, see below */ +#define EXTRASAMPLE_COREL_UNASSALPHA 999 + + uint16* va; + uint32 i; + + *v = (uint16) va_arg(ap, uint16_vap); + if ((uint16) *v > td->td_samplesperpixel) + return 0; + va = va_arg(ap, uint16*); + if (*v > 0 && va == NULL) /* typically missing param */ + return 0; + for (i = 0; i < *v; i++) { + if (va[i] > EXTRASAMPLE_UNASSALPHA) { + /* + * XXX: Corel Draw is known to produce incorrect + * ExtraSamples tags which must be patched here if we + * want to be able to open some of the damaged TIFF + * files: + */ + if (va[i] == EXTRASAMPLE_COREL_UNASSALPHA) + va[i] = EXTRASAMPLE_UNASSALPHA; + else + return 0; + } + } + td->td_extrasamples = (uint16) *v; + _TIFFsetShortArray(&td->td_sampleinfo, va, td->td_extrasamples); + return 1; + +#undef EXTRASAMPLE_COREL_UNASSALPHA +} + +/* + * Confirm we have "samplesperpixel" ink names separated by \0. Returns + * zero if the ink names are not as expected. + */ +static uint32 +checkInkNamesString(TIFF* tif, uint32 slen, const char* s) +{ + TIFFDirectory* td = &tif->tif_dir; + uint16 i = td->td_samplesperpixel; + + if (slen > 0) { + const char* ep = s+slen; + const char* cp = s; + for (; i > 0; i--) { + for (; cp < ep && *cp != '\0'; cp++) {} + if (cp >= ep) + goto bad; + cp++; /* skip \0 */ + } + return ((uint32)(cp-s)); + } +bad: + TIFFErrorExt(tif->tif_clientdata, "TIFFSetField", + "%s: Invalid InkNames value; expecting %d names, found %d", + tif->tif_name, + td->td_samplesperpixel, + td->td_samplesperpixel-i); + return (0); +} + +static int +_TIFFVSetField(TIFF* tif, uint32 tag, va_list ap) +{ + static const char module[] = "_TIFFVSetField"; + + TIFFDirectory* td = &tif->tif_dir; + int status = 1; + uint32 v32, i, v; + char* s; + const TIFFField *fip = TIFFFindField(tif, tag, TIFF_ANY); + uint32 standard_tag = tag; + + /* + * We want to force the custom code to be used for custom + * fields even if the tag happens to match a well known + * one - important for reinterpreted handling of standard + * tag values in custom directories (ie. EXIF) + */ + if (fip->field_bit == FIELD_CUSTOM) { + standard_tag = 0; + } + + switch (standard_tag) { + case TIFFTAG_SUBFILETYPE: + td->td_subfiletype = (uint32) va_arg(ap, uint32); + break; + case TIFFTAG_IMAGEWIDTH: + td->td_imagewidth = (uint32) va_arg(ap, uint32); + break; + case TIFFTAG_IMAGELENGTH: + td->td_imagelength = (uint32) va_arg(ap, uint32); + break; + case TIFFTAG_BITSPERSAMPLE: + td->td_bitspersample = (uint16) va_arg(ap, uint16_vap); + /* + * If the data require post-decoding processing to byte-swap + * samples, set it up here. Note that since tags are required + * to be ordered, compression code can override this behaviour + * in the setup method if it wants to roll the post decoding + * work in with its normal work. + */ + if (tif->tif_flags & TIFF_SWAB) { + if (td->td_bitspersample == 8) + tif->tif_postdecode = _TIFFNoPostDecode; + else if (td->td_bitspersample == 16) + tif->tif_postdecode = _TIFFSwab16BitData; + else if (td->td_bitspersample == 24) + tif->tif_postdecode = _TIFFSwab24BitData; + else if (td->td_bitspersample == 32) + tif->tif_postdecode = _TIFFSwab32BitData; + else if (td->td_bitspersample == 64) + tif->tif_postdecode = _TIFFSwab64BitData; + else if (td->td_bitspersample == 128) /* two 64's */ + tif->tif_postdecode = _TIFFSwab64BitData; + } + break; + case TIFFTAG_COMPRESSION: + v = (uint16) va_arg(ap, uint16_vap); + /* + * If we're changing the compression scheme, the notify the + * previous module so that it can cleanup any state it's + * setup. + */ + if (TIFFFieldSet(tif, FIELD_COMPRESSION)) { + if ((uint32)td->td_compression == v) + break; + (*tif->tif_cleanup)(tif); + tif->tif_flags &= ~TIFF_CODERSETUP; + } + /* + * Setup new compression routine state. + */ + if( (status = TIFFSetCompressionScheme(tif, v)) != 0 ) + td->td_compression = (uint16) v; + else + status = 0; + break; + case TIFFTAG_PHOTOMETRIC: + td->td_photometric = (uint16) va_arg(ap, uint16_vap); + break; + case TIFFTAG_THRESHHOLDING: + td->td_threshholding = (uint16) va_arg(ap, uint16_vap); + break; + case TIFFTAG_FILLORDER: + v = (uint16) va_arg(ap, uint16_vap); + if (v != FILLORDER_LSB2MSB && v != FILLORDER_MSB2LSB) + goto badvalue; + td->td_fillorder = (uint16) v; + break; + case TIFFTAG_ORIENTATION: + v = (uint16) va_arg(ap, uint16_vap); + if (v < ORIENTATION_TOPLEFT || ORIENTATION_LEFTBOT < v) + goto badvalue; + else + td->td_orientation = (uint16) v; + break; + case TIFFTAG_SAMPLESPERPIXEL: + v = (uint16) va_arg(ap, uint16_vap); + if (v == 0) + goto badvalue; + td->td_samplesperpixel = (uint16) v; + break; + case TIFFTAG_ROWSPERSTRIP: + v32 = (uint32) va_arg(ap, uint32); + if (v32 == 0) + goto badvalue32; + td->td_rowsperstrip = v32; + if (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) { + td->td_tilelength = v32; + td->td_tilewidth = td->td_imagewidth; + } + break; + case TIFFTAG_MINSAMPLEVALUE: + td->td_minsamplevalue = (uint16) va_arg(ap, uint16_vap); + break; + case TIFFTAG_MAXSAMPLEVALUE: + td->td_maxsamplevalue = (uint16) va_arg(ap, uint16_vap); + break; + case TIFFTAG_SMINSAMPLEVALUE: + if (tif->tif_flags & TIFF_PERSAMPLE) + _TIFFsetDoubleArray(&td->td_sminsamplevalue, va_arg(ap, double*), td->td_samplesperpixel); + else + setDoubleArrayOneValue(&td->td_sminsamplevalue, va_arg(ap, double), td->td_samplesperpixel); + break; + case TIFFTAG_SMAXSAMPLEVALUE: + if (tif->tif_flags & TIFF_PERSAMPLE) + _TIFFsetDoubleArray(&td->td_smaxsamplevalue, va_arg(ap, double*), td->td_samplesperpixel); + else + setDoubleArrayOneValue(&td->td_smaxsamplevalue, va_arg(ap, double), td->td_samplesperpixel); + break; + case TIFFTAG_XRESOLUTION: + td->td_xresolution = (float) va_arg(ap, double); + break; + case TIFFTAG_YRESOLUTION: + td->td_yresolution = (float) va_arg(ap, double); + break; + case TIFFTAG_PLANARCONFIG: + v = (uint16) va_arg(ap, uint16_vap); + if (v != PLANARCONFIG_CONTIG && v != PLANARCONFIG_SEPARATE) + goto badvalue; + td->td_planarconfig = (uint16) v; + break; + case TIFFTAG_XPOSITION: + td->td_xposition = (float) va_arg(ap, double); + break; + case TIFFTAG_YPOSITION: + td->td_yposition = (float) va_arg(ap, double); + break; + case TIFFTAG_RESOLUTIONUNIT: + v = (uint16) va_arg(ap, uint16_vap); + if (v < RESUNIT_NONE || RESUNIT_CENTIMETER < v) + goto badvalue; + td->td_resolutionunit = (uint16) v; + break; + case TIFFTAG_PAGENUMBER: + td->td_pagenumber[0] = (uint16) va_arg(ap, uint16_vap); + td->td_pagenumber[1] = (uint16) va_arg(ap, uint16_vap); + break; + case TIFFTAG_HALFTONEHINTS: + td->td_halftonehints[0] = (uint16) va_arg(ap, uint16_vap); + td->td_halftonehints[1] = (uint16) va_arg(ap, uint16_vap); + break; + case TIFFTAG_COLORMAP: + v32 = (uint32)(1L<td_bitspersample); + _TIFFsetShortArray(&td->td_colormap[0], va_arg(ap, uint16*), v32); + _TIFFsetShortArray(&td->td_colormap[1], va_arg(ap, uint16*), v32); + _TIFFsetShortArray(&td->td_colormap[2], va_arg(ap, uint16*), v32); + break; + case TIFFTAG_EXTRASAMPLES: + if (!setExtraSamples(td, ap, &v)) + goto badvalue; + break; + case TIFFTAG_MATTEING: + td->td_extrasamples = (((uint16) va_arg(ap, uint16_vap)) != 0); + if (td->td_extrasamples) { + uint16 sv = EXTRASAMPLE_ASSOCALPHA; + _TIFFsetShortArray(&td->td_sampleinfo, &sv, 1); + } + break; + case TIFFTAG_TILEWIDTH: + v32 = (uint32) va_arg(ap, uint32); + if (v32 % 16) { + if (tif->tif_mode != O_RDONLY) + goto badvalue32; + TIFFWarningExt(tif->tif_clientdata, tif->tif_name, + "Nonstandard tile width %d, convert file", v32); + } + td->td_tilewidth = v32; + tif->tif_flags |= TIFF_ISTILED; + break; + case TIFFTAG_TILELENGTH: + v32 = (uint32) va_arg(ap, uint32); + if (v32 % 16) { + if (tif->tif_mode != O_RDONLY) + goto badvalue32; + TIFFWarningExt(tif->tif_clientdata, tif->tif_name, + "Nonstandard tile length %d, convert file", v32); + } + td->td_tilelength = v32; + tif->tif_flags |= TIFF_ISTILED; + break; + case TIFFTAG_TILEDEPTH: + v32 = (uint32) va_arg(ap, uint32); + if (v32 == 0) + goto badvalue32; + td->td_tiledepth = v32; + break; + case TIFFTAG_DATATYPE: + v = (uint16) va_arg(ap, uint16_vap); + switch (v) { + case DATATYPE_VOID: v = SAMPLEFORMAT_VOID; break; + case DATATYPE_INT: v = SAMPLEFORMAT_INT; break; + case DATATYPE_UINT: v = SAMPLEFORMAT_UINT; break; + case DATATYPE_IEEEFP: v = SAMPLEFORMAT_IEEEFP;break; + default: goto badvalue; + } + td->td_sampleformat = (uint16) v; + break; + case TIFFTAG_SAMPLEFORMAT: + v = (uint16) va_arg(ap, uint16_vap); + if (v < SAMPLEFORMAT_UINT || SAMPLEFORMAT_COMPLEXIEEEFP < v) + goto badvalue; + td->td_sampleformat = (uint16) v; + + /* Try to fix up the SWAB function for complex data. */ + if( td->td_sampleformat == SAMPLEFORMAT_COMPLEXINT + && td->td_bitspersample == 32 + && tif->tif_postdecode == _TIFFSwab32BitData ) + tif->tif_postdecode = _TIFFSwab16BitData; + else if( (td->td_sampleformat == SAMPLEFORMAT_COMPLEXINT + || td->td_sampleformat == SAMPLEFORMAT_COMPLEXIEEEFP) + && td->td_bitspersample == 64 + && tif->tif_postdecode == _TIFFSwab64BitData ) + tif->tif_postdecode = _TIFFSwab32BitData; + break; + case TIFFTAG_IMAGEDEPTH: + td->td_imagedepth = (uint32) va_arg(ap, uint32); + break; + case TIFFTAG_SUBIFD: + if ((tif->tif_flags & TIFF_INSUBIFD) == 0) { + td->td_nsubifd = (uint16) va_arg(ap, uint16_vap); + _TIFFsetLong8Array(&td->td_subifd, (uint64*) va_arg(ap, uint64*), + (long) td->td_nsubifd); + } else { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Sorry, cannot nest SubIFDs", + tif->tif_name); + status = 0; + } + break; + case TIFFTAG_YCBCRPOSITIONING: + td->td_ycbcrpositioning = (uint16) va_arg(ap, uint16_vap); + break; + case TIFFTAG_YCBCRSUBSAMPLING: + td->td_ycbcrsubsampling[0] = (uint16) va_arg(ap, uint16_vap); + td->td_ycbcrsubsampling[1] = (uint16) va_arg(ap, uint16_vap); + break; + case TIFFTAG_TRANSFERFUNCTION: + v = (td->td_samplesperpixel - td->td_extrasamples) > 1 ? 3 : 1; + for (i = 0; i < v; i++) + _TIFFsetShortArray(&td->td_transferfunction[i], + va_arg(ap, uint16*), 1L<td_bitspersample); + break; + case TIFFTAG_REFERENCEBLACKWHITE: + /* XXX should check for null range */ + _TIFFsetFloatArray(&td->td_refblackwhite, va_arg(ap, float*), 6); + break; + case TIFFTAG_INKNAMES: + v = (uint16) va_arg(ap, uint16_vap); + s = va_arg(ap, char*); + v = checkInkNamesString(tif, v, s); + status = v > 0; + if( v > 0 ) { + _TIFFsetNString(&td->td_inknames, s, v); + td->td_inknameslen = v; + } + break; + case TIFFTAG_PERSAMPLE: + v = (uint16) va_arg(ap, uint16_vap); + if( v == PERSAMPLE_MULTI ) + tif->tif_flags |= TIFF_PERSAMPLE; + else + tif->tif_flags &= ~TIFF_PERSAMPLE; + break; + default: { + TIFFTagValue *tv; + int tv_size, iCustom; + + /* + * This can happen if multiple images are open with different + * codecs which have private tags. The global tag information + * table may then have tags that are valid for one file but not + * the other. If the client tries to set a tag that is not valid + * for the image's codec then we'll arrive here. This + * happens, for example, when tiffcp is used to convert between + * compression schemes and codec-specific tags are blindly copied. + */ + if(fip == NULL || fip->field_bit != FIELD_CUSTOM) { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Invalid %stag \"%s\" (not supported by codec)", + tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "", + fip ? fip->field_name : "Unknown"); + status = 0; + break; + } + + /* + * Find the existing entry for this custom value. + */ + tv = NULL; + for (iCustom = 0; iCustom < td->td_customValueCount; iCustom++) { + if (td->td_customValues[iCustom].info->field_tag == tag) { + tv = td->td_customValues + iCustom; + if (tv->value != NULL) { + _TIFFfree(tv->value); + tv->value = NULL; + } + break; + } + } + + /* + * Grow the custom list if the entry was not found. + */ + if(tv == NULL) { + TIFFTagValue *new_customValues; + + td->td_customValueCount++; + new_customValues = (TIFFTagValue *) + _TIFFrealloc(td->td_customValues, + sizeof(TIFFTagValue) * td->td_customValueCount); + if (!new_customValues) { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Failed to allocate space for list of custom values", + tif->tif_name); + status = 0; + goto end; + } + + td->td_customValues = new_customValues; + + tv = td->td_customValues + (td->td_customValueCount - 1); + tv->info = fip; + tv->value = NULL; + tv->count = 0; + } + + /* + * Set custom value ... save a copy of the custom tag value. + */ + tv_size = _TIFFDataSize(fip->field_type); + if (tv_size == 0) { + status = 0; + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Bad field type %d for \"%s\"", + tif->tif_name, fip->field_type, + fip->field_name); + goto end; + } + + if (fip->field_type == TIFF_ASCII) + { + uint32 ma; + char* mb; + if (fip->field_passcount) + { + assert(fip->field_writecount==TIFF_VARIABLE2); + ma=(uint32)va_arg(ap,uint32); + mb=(char*)va_arg(ap,char*); + } + else + { + mb=(char*)va_arg(ap,char*); + ma=(uint32)(strlen(mb)+1); + } + tv->count=ma; + setByteArray(&tv->value,mb,ma,1); + } + else + { + if (fip->field_passcount) { + if (fip->field_writecount == TIFF_VARIABLE2) + tv->count = (uint32) va_arg(ap, uint32); + else + tv->count = (int) va_arg(ap, int); + } else if (fip->field_writecount == TIFF_VARIABLE + || fip->field_writecount == TIFF_VARIABLE2) + tv->count = 1; + else if (fip->field_writecount == TIFF_SPP) + tv->count = td->td_samplesperpixel; + else + tv->count = fip->field_writecount; + + if (tv->count == 0) { + status = 0; + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Null count for \"%s\" (type " + "%d, writecount %d, passcount %d)", + tif->tif_name, + fip->field_name, + fip->field_type, + fip->field_writecount, + fip->field_passcount); + goto end; + } + + tv->value = _TIFFCheckMalloc(tif, tv->count, tv_size, + "custom tag binary object"); + if (!tv->value) { + status = 0; + goto end; + } + + if (fip->field_tag == TIFFTAG_DOTRANGE + && strcmp(fip->field_name,"DotRange") == 0) { + /* TODO: This is an evil exception and should not have been + handled this way ... likely best if we move it into + the directory structure with an explicit field in + libtiff 4.1 and assign it a FIELD_ value */ + uint16 v[2]; + v[0] = (uint16)va_arg(ap, int); + v[1] = (uint16)va_arg(ap, int); + _TIFFmemcpy(tv->value, &v, 4); + } + + else if (fip->field_passcount + || fip->field_writecount == TIFF_VARIABLE + || fip->field_writecount == TIFF_VARIABLE2 + || fip->field_writecount == TIFF_SPP + || tv->count > 1) { + _TIFFmemcpy(tv->value, va_arg(ap, void *), + tv->count * tv_size); + } else { + char *val = (char *)tv->value; + assert( tv->count == 1 ); + + switch (fip->field_type) { + case TIFF_BYTE: + case TIFF_UNDEFINED: + { + uint8 v = (uint8)va_arg(ap, int); + _TIFFmemcpy(val, &v, tv_size); + } + break; + case TIFF_SBYTE: + { + int8 v = (int8)va_arg(ap, int); + _TIFFmemcpy(val, &v, tv_size); + } + break; + case TIFF_SHORT: + { + uint16 v = (uint16)va_arg(ap, int); + _TIFFmemcpy(val, &v, tv_size); + } + break; + case TIFF_SSHORT: + { + int16 v = (int16)va_arg(ap, int); + _TIFFmemcpy(val, &v, tv_size); + } + break; + case TIFF_LONG: + case TIFF_IFD: + { + uint32 v = va_arg(ap, uint32); + _TIFFmemcpy(val, &v, tv_size); + } + break; + case TIFF_SLONG: + { + int32 v = va_arg(ap, int32); + _TIFFmemcpy(val, &v, tv_size); + } + break; + case TIFF_LONG8: + case TIFF_IFD8: + { + uint64 v = va_arg(ap, uint64); + _TIFFmemcpy(val, &v, tv_size); + } + break; + case TIFF_SLONG8: + { + int64 v = va_arg(ap, int64); + _TIFFmemcpy(val, &v, tv_size); + } + break; + case TIFF_RATIONAL: + case TIFF_SRATIONAL: + case TIFF_FLOAT: + { + float v = (float)va_arg(ap, double); + _TIFFmemcpy(val, &v, tv_size); + } + break; + case TIFF_DOUBLE: + { + double v = va_arg(ap, double); + _TIFFmemcpy(val, &v, tv_size); + } + break; + default: + _TIFFmemset(val, 0, tv_size); + status = 0; + break; + } + } + } + } + } + if (status) { + const TIFFField* fip=TIFFFieldWithTag(tif,tag); + if (fip) + TIFFSetFieldBit(tif, fip->field_bit); + tif->tif_flags |= TIFF_DIRTYDIRECT; + } + +end: + va_end(ap); + return (status); +badvalue: + { + const TIFFField* fip=TIFFFieldWithTag(tif,tag); + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Bad value %u for \"%s\" tag", + tif->tif_name, v, + fip ? fip->field_name : "Unknown"); + va_end(ap); + } + return (0); +badvalue32: + { + const TIFFField* fip=TIFFFieldWithTag(tif,tag); + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Bad value %u for \"%s\" tag", + tif->tif_name, v32, + fip ? fip->field_name : "Unknown"); + va_end(ap); + } + return (0); +} + +/* + * Return 1/0 according to whether or not + * it is permissible to set the tag's value. + * Note that we allow ImageLength to be changed + * so that we can append and extend to images. + * Any other tag may not be altered once writing + * has commenced, unless its value has no effect + * on the format of the data that is written. + */ +static int +OkToChangeTag(TIFF* tif, uint32 tag) +{ + const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY); + if (!fip) { /* unknown tag */ + TIFFErrorExt(tif->tif_clientdata, "TIFFSetField", "%s: Unknown %stag %u", + tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "", tag); + return (0); + } + if (tag != TIFFTAG_IMAGELENGTH && (tif->tif_flags & TIFF_BEENWRITING) && + !fip->field_oktochange) { + /* + * Consult info table to see if tag can be changed + * after we've started writing. We only allow changes + * to those tags that don't/shouldn't affect the + * compression and/or format of the data. + */ + TIFFErrorExt(tif->tif_clientdata, "TIFFSetField", + "%s: Cannot modify tag \"%s\" while writing", + tif->tif_name, fip->field_name); + return (0); + } + return (1); +} + +/* + * Record the value of a field in the + * internal directory structure. The + * field will be written to the file + * when/if the directory structure is + * updated. + */ +int +TIFFSetField(TIFF* tif, uint32 tag, ...) +{ + va_list ap; + int status; + + va_start(ap, tag); + status = TIFFVSetField(tif, tag, ap); + va_end(ap); + return (status); +} + +/* + * Clear the contents of the field in the internal structure. + */ +int +TIFFUnsetField(TIFF* tif, uint32 tag) +{ + const TIFFField *fip = TIFFFieldWithTag(tif, tag); + TIFFDirectory* td = &tif->tif_dir; + + if( !fip ) + return 0; + + if( fip->field_bit != FIELD_CUSTOM ) + TIFFClrFieldBit(tif, fip->field_bit); + else + { + TIFFTagValue *tv = NULL; + int i; + + for (i = 0; i < td->td_customValueCount; i++) { + + tv = td->td_customValues + i; + if( tv->info->field_tag == tag ) + break; + } + + if( i < td->td_customValueCount ) + { + _TIFFfree(tv->value); + for( ; i < td->td_customValueCount-1; i++) { + td->td_customValues[i] = td->td_customValues[i+1]; + } + td->td_customValueCount--; + } + } + + tif->tif_flags |= TIFF_DIRTYDIRECT; + + return (1); +} + +/* + * Like TIFFSetField, but taking a varargs + * parameter list. This routine is useful + * for building higher-level interfaces on + * top of the library. + */ +int +TIFFVSetField(TIFF* tif, uint32 tag, va_list ap) +{ + return OkToChangeTag(tif, tag) ? + (*tif->tif_tagmethods.vsetfield)(tif, tag, ap) : 0; +} + +static int +_TIFFVGetField(TIFF* tif, uint32 tag, va_list ap) +{ + TIFFDirectory* td = &tif->tif_dir; + int ret_val = 1; + uint32 standard_tag = tag; + const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY); + + /* + * We want to force the custom code to be used for custom + * fields even if the tag happens to match a well known + * one - important for reinterpreted handling of standard + * tag values in custom directories (ie. EXIF) + */ + if (fip->field_bit == FIELD_CUSTOM) { + standard_tag = 0; + } + + switch (standard_tag) { + case TIFFTAG_SUBFILETYPE: + *va_arg(ap, uint32*) = td->td_subfiletype; + break; + case TIFFTAG_IMAGEWIDTH: + *va_arg(ap, uint32*) = td->td_imagewidth; + break; + case TIFFTAG_IMAGELENGTH: + *va_arg(ap, uint32*) = td->td_imagelength; + break; + case TIFFTAG_BITSPERSAMPLE: + *va_arg(ap, uint16*) = td->td_bitspersample; + break; + case TIFFTAG_COMPRESSION: + *va_arg(ap, uint16*) = td->td_compression; + break; + case TIFFTAG_PHOTOMETRIC: + *va_arg(ap, uint16*) = td->td_photometric; + break; + case TIFFTAG_THRESHHOLDING: + *va_arg(ap, uint16*) = td->td_threshholding; + break; + case TIFFTAG_FILLORDER: + *va_arg(ap, uint16*) = td->td_fillorder; + break; + case TIFFTAG_ORIENTATION: + *va_arg(ap, uint16*) = td->td_orientation; + break; + case TIFFTAG_SAMPLESPERPIXEL: + *va_arg(ap, uint16*) = td->td_samplesperpixel; + break; + case TIFFTAG_ROWSPERSTRIP: + *va_arg(ap, uint32*) = td->td_rowsperstrip; + break; + case TIFFTAG_MINSAMPLEVALUE: + *va_arg(ap, uint16*) = td->td_minsamplevalue; + break; + case TIFFTAG_MAXSAMPLEVALUE: + *va_arg(ap, uint16*) = td->td_maxsamplevalue; + break; + case TIFFTAG_SMINSAMPLEVALUE: + if (tif->tif_flags & TIFF_PERSAMPLE) + *va_arg(ap, double**) = td->td_sminsamplevalue; + else + { + /* libtiff historially treats this as a single value. */ + uint16 i; + double v = td->td_sminsamplevalue[0]; + for (i=1; i < td->td_samplesperpixel; ++i) + if( td->td_sminsamplevalue[i] < v ) + v = td->td_sminsamplevalue[i]; + *va_arg(ap, double*) = v; + } + break; + case TIFFTAG_SMAXSAMPLEVALUE: + if (tif->tif_flags & TIFF_PERSAMPLE) + *va_arg(ap, double**) = td->td_smaxsamplevalue; + else + { + /* libtiff historially treats this as a single value. */ + uint16 i; + double v = td->td_smaxsamplevalue[0]; + for (i=1; i < td->td_samplesperpixel; ++i) + if( td->td_smaxsamplevalue[i] > v ) + v = td->td_smaxsamplevalue[i]; + *va_arg(ap, double*) = v; + } + break; + case TIFFTAG_XRESOLUTION: + *va_arg(ap, float*) = td->td_xresolution; + break; + case TIFFTAG_YRESOLUTION: + *va_arg(ap, float*) = td->td_yresolution; + break; + case TIFFTAG_PLANARCONFIG: + *va_arg(ap, uint16*) = td->td_planarconfig; + break; + case TIFFTAG_XPOSITION: + *va_arg(ap, float*) = td->td_xposition; + break; + case TIFFTAG_YPOSITION: + *va_arg(ap, float*) = td->td_yposition; + break; + case TIFFTAG_RESOLUTIONUNIT: + *va_arg(ap, uint16*) = td->td_resolutionunit; + break; + case TIFFTAG_PAGENUMBER: + *va_arg(ap, uint16*) = td->td_pagenumber[0]; + *va_arg(ap, uint16*) = td->td_pagenumber[1]; + break; + case TIFFTAG_HALFTONEHINTS: + *va_arg(ap, uint16*) = td->td_halftonehints[0]; + *va_arg(ap, uint16*) = td->td_halftonehints[1]; + break; + case TIFFTAG_COLORMAP: + *va_arg(ap, uint16**) = td->td_colormap[0]; + *va_arg(ap, uint16**) = td->td_colormap[1]; + *va_arg(ap, uint16**) = td->td_colormap[2]; + break; + case TIFFTAG_STRIPOFFSETS: + case TIFFTAG_TILEOFFSETS: + _TIFFFillStriles( tif ); + *va_arg(ap, uint64**) = td->td_stripoffset; + break; + case TIFFTAG_STRIPBYTECOUNTS: + case TIFFTAG_TILEBYTECOUNTS: + _TIFFFillStriles( tif ); + *va_arg(ap, uint64**) = td->td_stripbytecount; + break; + case TIFFTAG_MATTEING: + *va_arg(ap, uint16*) = + (td->td_extrasamples == 1 && + td->td_sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA); + break; + case TIFFTAG_EXTRASAMPLES: + *va_arg(ap, uint16*) = td->td_extrasamples; + *va_arg(ap, uint16**) = td->td_sampleinfo; + break; + case TIFFTAG_TILEWIDTH: + *va_arg(ap, uint32*) = td->td_tilewidth; + break; + case TIFFTAG_TILELENGTH: + *va_arg(ap, uint32*) = td->td_tilelength; + break; + case TIFFTAG_TILEDEPTH: + *va_arg(ap, uint32*) = td->td_tiledepth; + break; + case TIFFTAG_DATATYPE: + switch (td->td_sampleformat) { + case SAMPLEFORMAT_UINT: + *va_arg(ap, uint16*) = DATATYPE_UINT; + break; + case SAMPLEFORMAT_INT: + *va_arg(ap, uint16*) = DATATYPE_INT; + break; + case SAMPLEFORMAT_IEEEFP: + *va_arg(ap, uint16*) = DATATYPE_IEEEFP; + break; + case SAMPLEFORMAT_VOID: + *va_arg(ap, uint16*) = DATATYPE_VOID; + break; + } + break; + case TIFFTAG_SAMPLEFORMAT: + *va_arg(ap, uint16*) = td->td_sampleformat; + break; + case TIFFTAG_IMAGEDEPTH: + *va_arg(ap, uint32*) = td->td_imagedepth; + break; + case TIFFTAG_SUBIFD: + *va_arg(ap, uint16*) = td->td_nsubifd; + *va_arg(ap, uint64**) = td->td_subifd; + break; + case TIFFTAG_YCBCRPOSITIONING: + *va_arg(ap, uint16*) = td->td_ycbcrpositioning; + break; + case TIFFTAG_YCBCRSUBSAMPLING: + *va_arg(ap, uint16*) = td->td_ycbcrsubsampling[0]; + *va_arg(ap, uint16*) = td->td_ycbcrsubsampling[1]; + break; + case TIFFTAG_TRANSFERFUNCTION: + *va_arg(ap, uint16**) = td->td_transferfunction[0]; + if (td->td_samplesperpixel - td->td_extrasamples > 1) { + *va_arg(ap, uint16**) = td->td_transferfunction[1]; + *va_arg(ap, uint16**) = td->td_transferfunction[2]; + } + break; + case TIFFTAG_REFERENCEBLACKWHITE: + *va_arg(ap, float**) = td->td_refblackwhite; + break; + case TIFFTAG_INKNAMES: + *va_arg(ap, char**) = td->td_inknames; + break; + default: + { + int i; + + /* + * This can happen if multiple images are open + * with different codecs which have private + * tags. The global tag information table may + * then have tags that are valid for one file + * but not the other. If the client tries to + * get a tag that is not valid for the image's + * codec then we'll arrive here. + */ + if( fip == NULL || fip->field_bit != FIELD_CUSTOM ) + { + TIFFErrorExt(tif->tif_clientdata, "_TIFFVGetField", + "%s: Invalid %stag \"%s\" " + "(not supported by codec)", + tif->tif_name, + isPseudoTag(tag) ? "pseudo-" : "", + fip ? fip->field_name : "Unknown"); + ret_val = 0; + break; + } + + /* + * Do we have a custom value? + */ + ret_val = 0; + for (i = 0; i < td->td_customValueCount; i++) { + TIFFTagValue *tv = td->td_customValues + i; + + if (tv->info->field_tag != tag) + continue; + + if (fip->field_passcount) { + if (fip->field_readcount == TIFF_VARIABLE2) + *va_arg(ap, uint32*) = (uint32)tv->count; + else /* Assume TIFF_VARIABLE */ + *va_arg(ap, uint16*) = (uint16)tv->count; + *va_arg(ap, void **) = tv->value; + ret_val = 1; + } else if (fip->field_tag == TIFFTAG_DOTRANGE + && strcmp(fip->field_name,"DotRange") == 0) { + /* TODO: This is an evil exception and should not have been + handled this way ... likely best if we move it into + the directory structure with an explicit field in + libtiff 4.1 and assign it a FIELD_ value */ + *va_arg(ap, uint16*) = ((uint16 *)tv->value)[0]; + *va_arg(ap, uint16*) = ((uint16 *)tv->value)[1]; + ret_val = 1; + } else { + if (fip->field_type == TIFF_ASCII + || fip->field_readcount == TIFF_VARIABLE + || fip->field_readcount == TIFF_VARIABLE2 + || fip->field_readcount == TIFF_SPP + || tv->count > 1) { + *va_arg(ap, void **) = tv->value; + ret_val = 1; + } else { + char *val = (char *)tv->value; + assert( tv->count == 1 ); + switch (fip->field_type) { + case TIFF_BYTE: + case TIFF_UNDEFINED: + *va_arg(ap, uint8*) = + *(uint8 *)val; + ret_val = 1; + break; + case TIFF_SBYTE: + *va_arg(ap, int8*) = + *(int8 *)val; + ret_val = 1; + break; + case TIFF_SHORT: + *va_arg(ap, uint16*) = + *(uint16 *)val; + ret_val = 1; + break; + case TIFF_SSHORT: + *va_arg(ap, int16*) = + *(int16 *)val; + ret_val = 1; + break; + case TIFF_LONG: + case TIFF_IFD: + *va_arg(ap, uint32*) = + *(uint32 *)val; + ret_val = 1; + break; + case TIFF_SLONG: + *va_arg(ap, int32*) = + *(int32 *)val; + ret_val = 1; + break; + case TIFF_LONG8: + case TIFF_IFD8: + *va_arg(ap, uint64*) = + *(uint64 *)val; + ret_val = 1; + break; + case TIFF_SLONG8: + *va_arg(ap, int64*) = + *(int64 *)val; + ret_val = 1; + break; + case TIFF_RATIONAL: + case TIFF_SRATIONAL: + case TIFF_FLOAT: + *va_arg(ap, float*) = + *(float *)val; + ret_val = 1; + break; + case TIFF_DOUBLE: + *va_arg(ap, double*) = + *(double *)val; + ret_val = 1; + break; + default: + ret_val = 0; + break; + } + } + } + break; + } + } + } + return(ret_val); +} + +/* + * Return the value of a field in the + * internal directory structure. + */ +int +TIFFGetField(TIFF* tif, uint32 tag, ...) +{ + int status; + va_list ap; + + va_start(ap, tag); + status = TIFFVGetField(tif, tag, ap); + va_end(ap); + return (status); +} + +/* + * Like TIFFGetField, but taking a varargs + * parameter list. This routine is useful + * for building higher-level interfaces on + * top of the library. + */ +int +TIFFVGetField(TIFF* tif, uint32 tag, va_list ap) +{ + const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY); + return (fip && (isPseudoTag(tag) || TIFFFieldSet(tif, fip->field_bit)) ? + (*tif->tif_tagmethods.vgetfield)(tif, tag, ap) : 0); +} + +#define CleanupField(member) { \ + if (td->member) { \ + _TIFFfree(td->member); \ + td->member = 0; \ + } \ +} + +/* + * Release storage associated with a directory. + */ +void +TIFFFreeDirectory(TIFF* tif) +{ + TIFFDirectory *td = &tif->tif_dir; + int i; + + _TIFFmemset(td->td_fieldsset, 0, FIELD_SETLONGS); + CleanupField(td_sminsamplevalue); + CleanupField(td_smaxsamplevalue); + CleanupField(td_colormap[0]); + CleanupField(td_colormap[1]); + CleanupField(td_colormap[2]); + CleanupField(td_sampleinfo); + CleanupField(td_subifd); + CleanupField(td_inknames); + CleanupField(td_refblackwhite); + CleanupField(td_transferfunction[0]); + CleanupField(td_transferfunction[1]); + CleanupField(td_transferfunction[2]); + CleanupField(td_stripoffset); + CleanupField(td_stripbytecount); + TIFFClrFieldBit(tif, FIELD_YCBCRSUBSAMPLING); + TIFFClrFieldBit(tif, FIELD_YCBCRPOSITIONING); + + /* Cleanup custom tag values */ + for( i = 0; i < td->td_customValueCount; i++ ) { + if (td->td_customValues[i].value) + _TIFFfree(td->td_customValues[i].value); + } + + td->td_customValueCount = 0; + CleanupField(td_customValues); + +#if defined(DEFER_STRILE_LOAD) + _TIFFmemset( &(td->td_stripoffset_entry), 0, sizeof(TIFFDirEntry)); + _TIFFmemset( &(td->td_stripbytecount_entry), 0, sizeof(TIFFDirEntry)); +#endif +} +#undef CleanupField + +/* + * Client Tag extension support (from Niles Ritter). + */ +static TIFFExtendProc _TIFFextender = (TIFFExtendProc) NULL; + +TIFFExtendProc +TIFFSetTagExtender(TIFFExtendProc extender) +{ + TIFFExtendProc prev = _TIFFextender; + _TIFFextender = extender; + return (prev); +} + +/* + * Setup for a new directory. Should we automatically call + * TIFFWriteDirectory() if the current one is dirty? + * + * The newly created directory will not exist on the file till + * TIFFWriteDirectory(), TIFFFlush() or TIFFClose() is called. + */ +int +TIFFCreateDirectory(TIFF* tif) +{ + TIFFDefaultDirectory(tif); + tif->tif_diroff = 0; + tif->tif_nextdiroff = 0; + tif->tif_curoff = 0; + tif->tif_row = (uint32) -1; + tif->tif_curstrip = (uint32) -1; + + return 0; +} + +int +TIFFCreateCustomDirectory(TIFF* tif, const TIFFFieldArray* infoarray) +{ + TIFFDefaultDirectory(tif); + + /* + * Reset the field definitions to match the application provided list. + * Hopefully TIFFDefaultDirectory() won't have done anything irreversable + * based on it's assumption this is an image directory. + */ + _TIFFSetupFields(tif, infoarray); + + tif->tif_diroff = 0; + tif->tif_nextdiroff = 0; + tif->tif_curoff = 0; + tif->tif_row = (uint32) -1; + tif->tif_curstrip = (uint32) -1; + + return 0; +} + +int +TIFFCreateEXIFDirectory(TIFF* tif) +{ + const TIFFFieldArray* exifFieldArray; + exifFieldArray = _TIFFGetExifFields(); + return TIFFCreateCustomDirectory(tif, exifFieldArray); +} + +/* + * Setup a default directory structure. + */ +int +TIFFDefaultDirectory(TIFF* tif) +{ + register TIFFDirectory* td = &tif->tif_dir; + const TIFFFieldArray* tiffFieldArray; + + tiffFieldArray = _TIFFGetFields(); + _TIFFSetupFields(tif, tiffFieldArray); + + _TIFFmemset(td, 0, sizeof (*td)); + td->td_fillorder = FILLORDER_MSB2LSB; + td->td_bitspersample = 1; + td->td_threshholding = THRESHHOLD_BILEVEL; + td->td_orientation = ORIENTATION_TOPLEFT; + td->td_samplesperpixel = 1; + td->td_rowsperstrip = (uint32) -1; + td->td_tilewidth = 0; + td->td_tilelength = 0; + td->td_tiledepth = 1; + td->td_stripbytecountsorted = 1; /* Our own arrays always sorted. */ + td->td_resolutionunit = RESUNIT_INCH; + td->td_sampleformat = SAMPLEFORMAT_UINT; + td->td_imagedepth = 1; + td->td_ycbcrsubsampling[0] = 2; + td->td_ycbcrsubsampling[1] = 2; + td->td_ycbcrpositioning = YCBCRPOSITION_CENTERED; + tif->tif_postdecode = _TIFFNoPostDecode; + tif->tif_foundfield = NULL; + tif->tif_tagmethods.vsetfield = _TIFFVSetField; + tif->tif_tagmethods.vgetfield = _TIFFVGetField; + tif->tif_tagmethods.printdir = NULL; + /* + * Give client code a chance to install their own + * tag extensions & methods, prior to compression overloads. + */ + if (_TIFFextender) + (*_TIFFextender)(tif); + (void) TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE); + /* + * NB: The directory is marked dirty as a result of setting + * up the default compression scheme. However, this really + * isn't correct -- we want TIFF_DIRTYDIRECT to be set only + * if the user does something. We could just do the setup + * by hand, but it seems better to use the normal mechanism + * (i.e. TIFFSetField). + */ + tif->tif_flags &= ~TIFF_DIRTYDIRECT; + + /* + * As per http://bugzilla.remotesensing.org/show_bug.cgi?id=19 + * we clear the ISTILED flag when setting up a new directory. + * Should we also be clearing stuff like INSUBIFD? + */ + tif->tif_flags &= ~TIFF_ISTILED; + + return (1); +} + +static int +TIFFAdvanceDirectory(TIFF* tif, uint64* nextdir, uint64* off) +{ + static const char module[] = "TIFFAdvanceDirectory"; + if (isMapped(tif)) + { + uint64 poff=*nextdir; + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + tmsize_t poffa,poffb,poffc,poffd; + uint16 dircount; + uint32 nextdir32; + poffa=(tmsize_t)poff; + poffb=poffa+sizeof(uint16); + if (((uint64)poffa!=poff)||(poffbtif->tif_size)) + { + TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory count"); + return(0); + } + _TIFFmemcpy(&dircount,tif->tif_base+poffa,sizeof(uint16)); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabShort(&dircount); + poffc=poffb+dircount*12; + poffd=poffc+sizeof(uint32); + if ((poffctif->tif_size)) + { + TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory link"); + return(0); + } + if (off!=NULL) + *off=(uint64)poffc; + _TIFFmemcpy(&nextdir32,tif->tif_base+poffc,sizeof(uint32)); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(&nextdir32); + *nextdir=nextdir32; + } + else + { + tmsize_t poffa,poffb,poffc,poffd; + uint64 dircount64; + uint16 dircount16; + poffa=(tmsize_t)poff; + poffb=poffa+sizeof(uint64); + if (((uint64)poffa!=poff)||(poffbtif->tif_size)) + { + TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory count"); + return(0); + } + _TIFFmemcpy(&dircount64,tif->tif_base+poffa,sizeof(uint64)); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8(&dircount64); + if (dircount64>0xFFFF) + { + TIFFErrorExt(tif->tif_clientdata,module,"Sanity check on directory count failed"); + return(0); + } + dircount16=(uint16)dircount64; + poffc=poffb+dircount16*20; + poffd=poffc+sizeof(uint64); + if ((poffctif->tif_size)) + { + TIFFErrorExt(tif->tif_clientdata,module,"Error fetching directory link"); + return(0); + } + if (off!=NULL) + *off=(uint64)poffc; + _TIFFmemcpy(nextdir,tif->tif_base+poffc,sizeof(uint64)); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8(nextdir); + } + return(1); + } + else + { + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + uint16 dircount; + uint32 nextdir32; + if (!SeekOK(tif, *nextdir) || + !ReadOK(tif, &dircount, sizeof (uint16))) { + TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory count", + tif->tif_name); + return (0); + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabShort(&dircount); + if (off != NULL) + *off = TIFFSeekFile(tif, + dircount*12, SEEK_CUR); + else + (void) TIFFSeekFile(tif, + dircount*12, SEEK_CUR); + if (!ReadOK(tif, &nextdir32, sizeof (uint32))) { + TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory link", + tif->tif_name); + return (0); + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong(&nextdir32); + *nextdir=nextdir32; + } + else + { + uint64 dircount64; + uint16 dircount16; + if (!SeekOK(tif, *nextdir) || + !ReadOK(tif, &dircount64, sizeof (uint64))) { + TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory count", + tif->tif_name); + return (0); + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong8(&dircount64); + if (dircount64>0xFFFF) + { + TIFFErrorExt(tif->tif_clientdata, module, "Error fetching directory count"); + return(0); + } + dircount16 = (uint16)dircount64; + if (off != NULL) + *off = TIFFSeekFile(tif, + dircount16*20, SEEK_CUR); + else + (void) TIFFSeekFile(tif, + dircount16*20, SEEK_CUR); + if (!ReadOK(tif, nextdir, sizeof (uint64))) { + TIFFErrorExt(tif->tif_clientdata, module, "%s: Error fetching directory link", + tif->tif_name); + return (0); + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong8(nextdir); + } + return (1); + } +} + +/* + * Count the number of directories in a file. + */ +uint16 +TIFFNumberOfDirectories(TIFF* tif) +{ + uint64 nextdir; + uint16 n; + if (!(tif->tif_flags&TIFF_BIGTIFF)) + nextdir = tif->tif_header.classic.tiff_diroff; + else + nextdir = tif->tif_header.big.tiff_diroff; + n = 0; + while (nextdir != 0 && TIFFAdvanceDirectory(tif, &nextdir, NULL)) + n++; + return (n); +} + +/* + * Set the n-th directory as the current directory. + * NB: Directories are numbered starting at 0. + */ +int +TIFFSetDirectory(TIFF* tif, uint16 dirn) +{ + uint64 nextdir; + uint16 n; + + if (!(tif->tif_flags&TIFF_BIGTIFF)) + nextdir = tif->tif_header.classic.tiff_diroff; + else + nextdir = tif->tif_header.big.tiff_diroff; + for (n = dirn; n > 0 && nextdir != 0; n--) + if (!TIFFAdvanceDirectory(tif, &nextdir, NULL)) + return (0); + tif->tif_nextdiroff = nextdir; + /* + * Set curdir to the actual directory index. The + * -1 is because TIFFReadDirectory will increment + * tif_curdir after successfully reading the directory. + */ + tif->tif_curdir = (dirn - n) - 1; + /* + * Reset tif_dirnumber counter and start new list of seen directories. + * We need this to prevent IFD loops. + */ + tif->tif_dirnumber = 0; + return (TIFFReadDirectory(tif)); +} + +/* + * Set the current directory to be the directory + * located at the specified file offset. This interface + * is used mainly to access directories linked with + * the SubIFD tag (e.g. thumbnail images). + */ +int +TIFFSetSubDirectory(TIFF* tif, uint64 diroff) +{ + tif->tif_nextdiroff = diroff; + /* + * Reset tif_dirnumber counter and start new list of seen directories. + * We need this to prevent IFD loops. + */ + tif->tif_dirnumber = 0; + return (TIFFReadDirectory(tif)); +} + +/* + * Return file offset of the current directory. + */ +uint64 +TIFFCurrentDirOffset(TIFF* tif) +{ + return (tif->tif_diroff); +} + +/* + * Return an indication of whether or not we are + * at the last directory in the file. + */ +int +TIFFLastDirectory(TIFF* tif) +{ + return (tif->tif_nextdiroff == 0); +} + +/* + * Unlink the specified directory from the directory chain. + */ +int +TIFFUnlinkDirectory(TIFF* tif, uint16 dirn) +{ + static const char module[] = "TIFFUnlinkDirectory"; + uint64 nextdir; + uint64 off; + uint16 n; + + if (tif->tif_mode == O_RDONLY) { + TIFFErrorExt(tif->tif_clientdata, module, + "Can not unlink directory in read-only file"); + return (0); + } + /* + * Go to the directory before the one we want + * to unlink and nab the offset of the link + * field we'll need to patch. + */ + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + nextdir = tif->tif_header.classic.tiff_diroff; + off = 4; + } + else + { + nextdir = tif->tif_header.big.tiff_diroff; + off = 8; + } + for (n = dirn-1; n > 0; n--) { + if (nextdir == 0) { + TIFFErrorExt(tif->tif_clientdata, module, "Directory %d does not exist", dirn); + return (0); + } + if (!TIFFAdvanceDirectory(tif, &nextdir, &off)) + return (0); + } + /* + * Advance to the directory to be unlinked and fetch + * the offset of the directory that follows. + */ + if (!TIFFAdvanceDirectory(tif, &nextdir, NULL)) + return (0); + /* + * Go back and patch the link field of the preceding + * directory to point to the offset of the directory + * that follows. + */ + (void) TIFFSeekFile(tif, off, SEEK_SET); + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + uint32 nextdir32; + nextdir32=(uint32)nextdir; + assert((uint64)nextdir32==nextdir); + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong(&nextdir32); + if (!WriteOK(tif, &nextdir32, sizeof (uint32))) { + TIFFErrorExt(tif->tif_clientdata, module, "Error writing directory link"); + return (0); + } + } + else + { + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong8(&nextdir); + if (!WriteOK(tif, &nextdir, sizeof (uint64))) { + TIFFErrorExt(tif->tif_clientdata, module, "Error writing directory link"); + return (0); + } + } + /* + * Leave directory state setup safely. We don't have + * facilities for doing inserting and removing directories, + * so it's safest to just invalidate everything. This + * means that the caller can only append to the directory + * chain. + */ + (*tif->tif_cleanup)(tif); + if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) { + _TIFFfree(tif->tif_rawdata); + tif->tif_rawdata = NULL; + tif->tif_rawcc = 0; + tif->tif_rawdataoff = 0; + tif->tif_rawdataloaded = 0; + } + tif->tif_flags &= ~(TIFF_BEENWRITING|TIFF_BUFFERSETUP|TIFF_POSTENCODE|TIFF_BUF4WRITE); + TIFFFreeDirectory(tif); + TIFFDefaultDirectory(tif); + tif->tif_diroff = 0; /* force link on next write */ + tif->tif_nextdiroff = 0; /* next write must be at end */ + tif->tif_curoff = 0; + tif->tif_row = (uint32) -1; + tif->tif_curstrip = (uint32) -1; + return (1); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_dir.h b/Source/LibTIFF4/tif_dir.h index 410dab2..1e5a925 100644 --- a/Source/LibTIFF4/tif_dir.h +++ b/Source/LibTIFF4/tif_dir.h @@ -1,308 +1,308 @@ -/* $Id: tif_dir.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifndef _TIFFDIR_ -#define _TIFFDIR_ -/* - * ``Library-private'' Directory-related Definitions. - */ - -typedef struct { - const TIFFField *info; - int count; - void *value; -} TIFFTagValue; - -/* - * TIFF Image File Directories are comprised of a table of field - * descriptors of the form shown below. The table is sorted in - * ascending order by tag. The values associated with each entry are - * disjoint and may appear anywhere in the file (so long as they are - * placed on a word boundary). - * - * If the value is 4 bytes or less, in ClassicTIFF, or 8 bytes or less in - * BigTIFF, then it is placed in the offset field to save space. If so, - * it is left-justified in the offset field. - */ -typedef struct { - uint16 tdir_tag; /* see below */ - uint16 tdir_type; /* data type; see below */ - uint64 tdir_count; /* number of items; length in spec */ - union { - uint16 toff_short; - uint32 toff_long; - uint64 toff_long8; - } tdir_offset; /* either offset or the data itself if fits */ -} TIFFDirEntry; - -/* - * Internal format of a TIFF directory entry. - */ -typedef struct { -#define FIELD_SETLONGS 4 - /* bit vector of fields that are set */ - unsigned long td_fieldsset[FIELD_SETLONGS]; - - uint32 td_imagewidth, td_imagelength, td_imagedepth; - uint32 td_tilewidth, td_tilelength, td_tiledepth; - uint32 td_subfiletype; - uint16 td_bitspersample; - uint16 td_sampleformat; - uint16 td_compression; - uint16 td_photometric; - uint16 td_threshholding; - uint16 td_fillorder; - uint16 td_orientation; - uint16 td_samplesperpixel; - uint32 td_rowsperstrip; - uint16 td_minsamplevalue, td_maxsamplevalue; - double* td_sminsamplevalue; - double* td_smaxsamplevalue; - float td_xresolution, td_yresolution; - uint16 td_resolutionunit; - uint16 td_planarconfig; - float td_xposition, td_yposition; - uint16 td_pagenumber[2]; - uint16* td_colormap[3]; - uint16 td_halftonehints[2]; - uint16 td_extrasamples; - uint16* td_sampleinfo; - /* even though the name is misleading, td_stripsperimage is the number - * of striles (=strips or tiles) per plane, and td_nstrips the total - * number of striles */ - uint32 td_stripsperimage; - uint32 td_nstrips; /* size of offset & bytecount arrays */ - uint64* td_stripoffset; - uint64* td_stripbytecount; - int td_stripbytecountsorted; /* is the bytecount array sorted ascending? */ -#if defined(DEFER_STRILE_LOAD) - TIFFDirEntry td_stripoffset_entry; /* for deferred loading */ - TIFFDirEntry td_stripbytecount_entry; /* for deferred loading */ -#endif - uint16 td_nsubifd; - uint64* td_subifd; - /* YCbCr parameters */ - uint16 td_ycbcrsubsampling[2]; - uint16 td_ycbcrpositioning; - /* Colorimetry parameters */ - uint16* td_transferfunction[3]; - float* td_refblackwhite; - /* CMYK parameters */ - int td_inknameslen; - char* td_inknames; - - int td_customValueCount; - TIFFTagValue *td_customValues; -} TIFFDirectory; - -/* - * Field flags used to indicate fields that have been set in a directory, and - * to reference fields when manipulating a directory. - */ - -/* - * FIELD_IGNORE is used to signify tags that are to be processed but otherwise - * ignored. This permits antiquated tags to be quietly read and discarded. - * Note that a bit *is* allocated for ignored tags; this is understood by the - * directory reading logic which uses this fact to avoid special-case handling - */ -#define FIELD_IGNORE 0 - -/* multi-item fields */ -#define FIELD_IMAGEDIMENSIONS 1 -#define FIELD_TILEDIMENSIONS 2 -#define FIELD_RESOLUTION 3 -#define FIELD_POSITION 4 - -/* single-item fields */ -#define FIELD_SUBFILETYPE 5 -#define FIELD_BITSPERSAMPLE 6 -#define FIELD_COMPRESSION 7 -#define FIELD_PHOTOMETRIC 8 -#define FIELD_THRESHHOLDING 9 -#define FIELD_FILLORDER 10 -#define FIELD_ORIENTATION 15 -#define FIELD_SAMPLESPERPIXEL 16 -#define FIELD_ROWSPERSTRIP 17 -#define FIELD_MINSAMPLEVALUE 18 -#define FIELD_MAXSAMPLEVALUE 19 -#define FIELD_PLANARCONFIG 20 -#define FIELD_RESOLUTIONUNIT 22 -#define FIELD_PAGENUMBER 23 -#define FIELD_STRIPBYTECOUNTS 24 -#define FIELD_STRIPOFFSETS 25 -#define FIELD_COLORMAP 26 -#define FIELD_EXTRASAMPLES 31 -#define FIELD_SAMPLEFORMAT 32 -#define FIELD_SMINSAMPLEVALUE 33 -#define FIELD_SMAXSAMPLEVALUE 34 -#define FIELD_IMAGEDEPTH 35 -#define FIELD_TILEDEPTH 36 -#define FIELD_HALFTONEHINTS 37 -#define FIELD_YCBCRSUBSAMPLING 39 -#define FIELD_YCBCRPOSITIONING 40 -#define FIELD_REFBLACKWHITE 41 -#define FIELD_TRANSFERFUNCTION 44 -#define FIELD_INKNAMES 46 -#define FIELD_SUBIFD 49 -/* FIELD_CUSTOM (see tiffio.h) 65 */ -/* end of support for well-known tags; codec-private tags follow */ -#define FIELD_CODEC 66 /* base of codec-private tags */ - - -/* - * Pseudo-tags don't normally need field bits since they are not written to an - * output file (by definition). The library also has express logic to always - * query a codec for a pseudo-tag so allocating a field bit for one is a - * waste. If codec wants to promote the notion of a pseudo-tag being ``set'' - * or ``unset'' then it can do using internal state flags without polluting - * the field bit space defined for real tags. - */ -#define FIELD_PSEUDO 0 - -#define FIELD_LAST (32*FIELD_SETLONGS-1) - -#define BITn(n) (((unsigned long)1L)<<((n)&0x1f)) -#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n)/32]) -#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field)) -#define TIFFSetFieldBit(tif, field) (BITFIELDn(tif, field) |= BITn(field)) -#define TIFFClrFieldBit(tif, field) (BITFIELDn(tif, field) &= ~BITn(field)) - -#define FieldSet(fields, f) (fields[(f)/32] & BITn(f)) -#define ResetFieldBit(fields, f) (fields[(f)/32] &= ~BITn(f)) - -typedef enum { - TIFF_SETGET_UNDEFINED = 0, - TIFF_SETGET_ASCII = 1, - TIFF_SETGET_UINT8 = 2, - TIFF_SETGET_SINT8 = 3, - TIFF_SETGET_UINT16 = 4, - TIFF_SETGET_SINT16 = 5, - TIFF_SETGET_UINT32 = 6, - TIFF_SETGET_SINT32 = 7, - TIFF_SETGET_UINT64 = 8, - TIFF_SETGET_SINT64 = 9, - TIFF_SETGET_FLOAT = 10, - TIFF_SETGET_DOUBLE = 11, - TIFF_SETGET_IFD8 = 12, - TIFF_SETGET_INT = 13, - TIFF_SETGET_UINT16_PAIR = 14, - TIFF_SETGET_C0_ASCII = 15, - TIFF_SETGET_C0_UINT8 = 16, - TIFF_SETGET_C0_SINT8 = 17, - TIFF_SETGET_C0_UINT16 = 18, - TIFF_SETGET_C0_SINT16 = 19, - TIFF_SETGET_C0_UINT32 = 20, - TIFF_SETGET_C0_SINT32 = 21, - TIFF_SETGET_C0_UINT64 = 22, - TIFF_SETGET_C0_SINT64 = 23, - TIFF_SETGET_C0_FLOAT = 24, - TIFF_SETGET_C0_DOUBLE = 25, - TIFF_SETGET_C0_IFD8 = 26, - TIFF_SETGET_C16_ASCII = 27, - TIFF_SETGET_C16_UINT8 = 28, - TIFF_SETGET_C16_SINT8 = 29, - TIFF_SETGET_C16_UINT16 = 30, - TIFF_SETGET_C16_SINT16 = 31, - TIFF_SETGET_C16_UINT32 = 32, - TIFF_SETGET_C16_SINT32 = 33, - TIFF_SETGET_C16_UINT64 = 34, - TIFF_SETGET_C16_SINT64 = 35, - TIFF_SETGET_C16_FLOAT = 36, - TIFF_SETGET_C16_DOUBLE = 37, - TIFF_SETGET_C16_IFD8 = 38, - TIFF_SETGET_C32_ASCII = 39, - TIFF_SETGET_C32_UINT8 = 40, - TIFF_SETGET_C32_SINT8 = 41, - TIFF_SETGET_C32_UINT16 = 42, - TIFF_SETGET_C32_SINT16 = 43, - TIFF_SETGET_C32_UINT32 = 44, - TIFF_SETGET_C32_SINT32 = 45, - TIFF_SETGET_C32_UINT64 = 46, - TIFF_SETGET_C32_SINT64 = 47, - TIFF_SETGET_C32_FLOAT = 48, - TIFF_SETGET_C32_DOUBLE = 49, - TIFF_SETGET_C32_IFD8 = 50, - TIFF_SETGET_OTHER = 51 -} TIFFSetGetFieldType; - -#if defined(__cplusplus) -extern "C" { -#endif - -extern const TIFFFieldArray* _TIFFGetFields(void); -extern const TIFFFieldArray* _TIFFGetExifFields(void); -extern void _TIFFSetupFields(TIFF* tif, const TIFFFieldArray* infoarray); -extern void _TIFFPrintFieldInfo(TIFF*, FILE*); - -extern int _TIFFFillStriles(TIFF*); - -typedef enum { - tfiatImage, - tfiatExif, - tfiatOther -} TIFFFieldArrayType; - -struct _TIFFFieldArray { - TIFFFieldArrayType type; /* array type, will be used to determine if IFD is image and such */ - uint32 allocated_size; /* 0 if array is constant, other if modified by future definition extension support */ - uint32 count; /* number of elements in fields array */ - TIFFField* fields; /* actual field info */ -}; - -struct _TIFFField { - uint32 field_tag; /* field's tag */ - short field_readcount; /* read count/TIFF_VARIABLE/TIFF_SPP */ - short field_writecount; /* write count/TIFF_VARIABLE */ - TIFFDataType field_type; /* type of associated data */ - uint32 reserved; /* reserved for future extension */ - TIFFSetGetFieldType set_field_type; /* type to be passed to TIFFSetField */ - TIFFSetGetFieldType get_field_type; /* type to be passed to TIFFGetField */ - unsigned short field_bit; /* bit in fieldsset bit vector */ - unsigned char field_oktochange; /* if true, can change while writing */ - unsigned char field_passcount; /* if true, pass dir count on set */ - char* field_name; /* ASCII name */ - TIFFFieldArray* field_subfields; /* if field points to child ifds, child ifd field definition array */ -}; - -extern int _TIFFMergeFields(TIFF*, const TIFFField[], uint32); -extern const TIFFField* _TIFFFindOrRegisterField(TIFF *, uint32, TIFFDataType); -extern TIFFField* _TIFFCreateAnonField(TIFF *, uint32, TIFFDataType); - -#if defined(__cplusplus) -} -#endif -#endif /* _TIFFDIR_ */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ - -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_dir.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef _TIFFDIR_ +#define _TIFFDIR_ +/* + * ``Library-private'' Directory-related Definitions. + */ + +typedef struct { + const TIFFField *info; + int count; + void *value; +} TIFFTagValue; + +/* + * TIFF Image File Directories are comprised of a table of field + * descriptors of the form shown below. The table is sorted in + * ascending order by tag. The values associated with each entry are + * disjoint and may appear anywhere in the file (so long as they are + * placed on a word boundary). + * + * If the value is 4 bytes or less, in ClassicTIFF, or 8 bytes or less in + * BigTIFF, then it is placed in the offset field to save space. If so, + * it is left-justified in the offset field. + */ +typedef struct { + uint16 tdir_tag; /* see below */ + uint16 tdir_type; /* data type; see below */ + uint64 tdir_count; /* number of items; length in spec */ + union { + uint16 toff_short; + uint32 toff_long; + uint64 toff_long8; + } tdir_offset; /* either offset or the data itself if fits */ +} TIFFDirEntry; + +/* + * Internal format of a TIFF directory entry. + */ +typedef struct { +#define FIELD_SETLONGS 4 + /* bit vector of fields that are set */ + unsigned long td_fieldsset[FIELD_SETLONGS]; + + uint32 td_imagewidth, td_imagelength, td_imagedepth; + uint32 td_tilewidth, td_tilelength, td_tiledepth; + uint32 td_subfiletype; + uint16 td_bitspersample; + uint16 td_sampleformat; + uint16 td_compression; + uint16 td_photometric; + uint16 td_threshholding; + uint16 td_fillorder; + uint16 td_orientation; + uint16 td_samplesperpixel; + uint32 td_rowsperstrip; + uint16 td_minsamplevalue, td_maxsamplevalue; + double* td_sminsamplevalue; + double* td_smaxsamplevalue; + float td_xresolution, td_yresolution; + uint16 td_resolutionunit; + uint16 td_planarconfig; + float td_xposition, td_yposition; + uint16 td_pagenumber[2]; + uint16* td_colormap[3]; + uint16 td_halftonehints[2]; + uint16 td_extrasamples; + uint16* td_sampleinfo; + /* even though the name is misleading, td_stripsperimage is the number + * of striles (=strips or tiles) per plane, and td_nstrips the total + * number of striles */ + uint32 td_stripsperimage; + uint32 td_nstrips; /* size of offset & bytecount arrays */ + uint64* td_stripoffset; + uint64* td_stripbytecount; + int td_stripbytecountsorted; /* is the bytecount array sorted ascending? */ +#if defined(DEFER_STRILE_LOAD) + TIFFDirEntry td_stripoffset_entry; /* for deferred loading */ + TIFFDirEntry td_stripbytecount_entry; /* for deferred loading */ +#endif + uint16 td_nsubifd; + uint64* td_subifd; + /* YCbCr parameters */ + uint16 td_ycbcrsubsampling[2]; + uint16 td_ycbcrpositioning; + /* Colorimetry parameters */ + uint16* td_transferfunction[3]; + float* td_refblackwhite; + /* CMYK parameters */ + int td_inknameslen; + char* td_inknames; + + int td_customValueCount; + TIFFTagValue *td_customValues; +} TIFFDirectory; + +/* + * Field flags used to indicate fields that have been set in a directory, and + * to reference fields when manipulating a directory. + */ + +/* + * FIELD_IGNORE is used to signify tags that are to be processed but otherwise + * ignored. This permits antiquated tags to be quietly read and discarded. + * Note that a bit *is* allocated for ignored tags; this is understood by the + * directory reading logic which uses this fact to avoid special-case handling + */ +#define FIELD_IGNORE 0 + +/* multi-item fields */ +#define FIELD_IMAGEDIMENSIONS 1 +#define FIELD_TILEDIMENSIONS 2 +#define FIELD_RESOLUTION 3 +#define FIELD_POSITION 4 + +/* single-item fields */ +#define FIELD_SUBFILETYPE 5 +#define FIELD_BITSPERSAMPLE 6 +#define FIELD_COMPRESSION 7 +#define FIELD_PHOTOMETRIC 8 +#define FIELD_THRESHHOLDING 9 +#define FIELD_FILLORDER 10 +#define FIELD_ORIENTATION 15 +#define FIELD_SAMPLESPERPIXEL 16 +#define FIELD_ROWSPERSTRIP 17 +#define FIELD_MINSAMPLEVALUE 18 +#define FIELD_MAXSAMPLEVALUE 19 +#define FIELD_PLANARCONFIG 20 +#define FIELD_RESOLUTIONUNIT 22 +#define FIELD_PAGENUMBER 23 +#define FIELD_STRIPBYTECOUNTS 24 +#define FIELD_STRIPOFFSETS 25 +#define FIELD_COLORMAP 26 +#define FIELD_EXTRASAMPLES 31 +#define FIELD_SAMPLEFORMAT 32 +#define FIELD_SMINSAMPLEVALUE 33 +#define FIELD_SMAXSAMPLEVALUE 34 +#define FIELD_IMAGEDEPTH 35 +#define FIELD_TILEDEPTH 36 +#define FIELD_HALFTONEHINTS 37 +#define FIELD_YCBCRSUBSAMPLING 39 +#define FIELD_YCBCRPOSITIONING 40 +#define FIELD_REFBLACKWHITE 41 +#define FIELD_TRANSFERFUNCTION 44 +#define FIELD_INKNAMES 46 +#define FIELD_SUBIFD 49 +/* FIELD_CUSTOM (see tiffio.h) 65 */ +/* end of support for well-known tags; codec-private tags follow */ +#define FIELD_CODEC 66 /* base of codec-private tags */ + + +/* + * Pseudo-tags don't normally need field bits since they are not written to an + * output file (by definition). The library also has express logic to always + * query a codec for a pseudo-tag so allocating a field bit for one is a + * waste. If codec wants to promote the notion of a pseudo-tag being ``set'' + * or ``unset'' then it can do using internal state flags without polluting + * the field bit space defined for real tags. + */ +#define FIELD_PSEUDO 0 + +#define FIELD_LAST (32*FIELD_SETLONGS-1) + +#define BITn(n) (((unsigned long)1L)<<((n)&0x1f)) +#define BITFIELDn(tif, n) ((tif)->tif_dir.td_fieldsset[(n)/32]) +#define TIFFFieldSet(tif, field) (BITFIELDn(tif, field) & BITn(field)) +#define TIFFSetFieldBit(tif, field) (BITFIELDn(tif, field) |= BITn(field)) +#define TIFFClrFieldBit(tif, field) (BITFIELDn(tif, field) &= ~BITn(field)) + +#define FieldSet(fields, f) (fields[(f)/32] & BITn(f)) +#define ResetFieldBit(fields, f) (fields[(f)/32] &= ~BITn(f)) + +typedef enum { + TIFF_SETGET_UNDEFINED = 0, + TIFF_SETGET_ASCII = 1, + TIFF_SETGET_UINT8 = 2, + TIFF_SETGET_SINT8 = 3, + TIFF_SETGET_UINT16 = 4, + TIFF_SETGET_SINT16 = 5, + TIFF_SETGET_UINT32 = 6, + TIFF_SETGET_SINT32 = 7, + TIFF_SETGET_UINT64 = 8, + TIFF_SETGET_SINT64 = 9, + TIFF_SETGET_FLOAT = 10, + TIFF_SETGET_DOUBLE = 11, + TIFF_SETGET_IFD8 = 12, + TIFF_SETGET_INT = 13, + TIFF_SETGET_UINT16_PAIR = 14, + TIFF_SETGET_C0_ASCII = 15, + TIFF_SETGET_C0_UINT8 = 16, + TIFF_SETGET_C0_SINT8 = 17, + TIFF_SETGET_C0_UINT16 = 18, + TIFF_SETGET_C0_SINT16 = 19, + TIFF_SETGET_C0_UINT32 = 20, + TIFF_SETGET_C0_SINT32 = 21, + TIFF_SETGET_C0_UINT64 = 22, + TIFF_SETGET_C0_SINT64 = 23, + TIFF_SETGET_C0_FLOAT = 24, + TIFF_SETGET_C0_DOUBLE = 25, + TIFF_SETGET_C0_IFD8 = 26, + TIFF_SETGET_C16_ASCII = 27, + TIFF_SETGET_C16_UINT8 = 28, + TIFF_SETGET_C16_SINT8 = 29, + TIFF_SETGET_C16_UINT16 = 30, + TIFF_SETGET_C16_SINT16 = 31, + TIFF_SETGET_C16_UINT32 = 32, + TIFF_SETGET_C16_SINT32 = 33, + TIFF_SETGET_C16_UINT64 = 34, + TIFF_SETGET_C16_SINT64 = 35, + TIFF_SETGET_C16_FLOAT = 36, + TIFF_SETGET_C16_DOUBLE = 37, + TIFF_SETGET_C16_IFD8 = 38, + TIFF_SETGET_C32_ASCII = 39, + TIFF_SETGET_C32_UINT8 = 40, + TIFF_SETGET_C32_SINT8 = 41, + TIFF_SETGET_C32_UINT16 = 42, + TIFF_SETGET_C32_SINT16 = 43, + TIFF_SETGET_C32_UINT32 = 44, + TIFF_SETGET_C32_SINT32 = 45, + TIFF_SETGET_C32_UINT64 = 46, + TIFF_SETGET_C32_SINT64 = 47, + TIFF_SETGET_C32_FLOAT = 48, + TIFF_SETGET_C32_DOUBLE = 49, + TIFF_SETGET_C32_IFD8 = 50, + TIFF_SETGET_OTHER = 51 +} TIFFSetGetFieldType; + +#if defined(__cplusplus) +extern "C" { +#endif + +extern const TIFFFieldArray* _TIFFGetFields(void); +extern const TIFFFieldArray* _TIFFGetExifFields(void); +extern void _TIFFSetupFields(TIFF* tif, const TIFFFieldArray* infoarray); +extern void _TIFFPrintFieldInfo(TIFF*, FILE*); + +extern int _TIFFFillStriles(TIFF*); + +typedef enum { + tfiatImage, + tfiatExif, + tfiatOther +} TIFFFieldArrayType; + +struct _TIFFFieldArray { + TIFFFieldArrayType type; /* array type, will be used to determine if IFD is image and such */ + uint32 allocated_size; /* 0 if array is constant, other if modified by future definition extension support */ + uint32 count; /* number of elements in fields array */ + TIFFField* fields; /* actual field info */ +}; + +struct _TIFFField { + uint32 field_tag; /* field's tag */ + short field_readcount; /* read count/TIFF_VARIABLE/TIFF_SPP */ + short field_writecount; /* write count/TIFF_VARIABLE */ + TIFFDataType field_type; /* type of associated data */ + uint32 reserved; /* reserved for future extension */ + TIFFSetGetFieldType set_field_type; /* type to be passed to TIFFSetField */ + TIFFSetGetFieldType get_field_type; /* type to be passed to TIFFGetField */ + unsigned short field_bit; /* bit in fieldsset bit vector */ + unsigned char field_oktochange; /* if true, can change while writing */ + unsigned char field_passcount; /* if true, pass dir count on set */ + char* field_name; /* ASCII name */ + TIFFFieldArray* field_subfields; /* if field points to child ifds, child ifd field definition array */ +}; + +extern int _TIFFMergeFields(TIFF*, const TIFFField[], uint32); +extern const TIFFField* _TIFFFindOrRegisterField(TIFF *, uint32, TIFFDataType); +extern TIFFField* _TIFFCreateAnonField(TIFF *, uint32, TIFFDataType); + +#if defined(__cplusplus) +} +#endif +#endif /* _TIFFDIR_ */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ + +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_dirinfo.c b/Source/LibTIFF4/tif_dirinfo.c index 9c8bd4c..4a7b8f8 100644 --- a/Source/LibTIFF4/tif_dirinfo.c +++ b/Source/LibTIFF4/tif_dirinfo.c @@ -1,957 +1,957 @@ -/* $Id: tif_dirinfo.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * - * Core Directory Tag Support. - */ -#include "tiffiop.h" -#include - -/* - * NOTE: THIS ARRAY IS ASSUMED TO BE SORTED BY TAG. - * - * NOTE: The second field (field_readcount) and third field (field_writecount) - * sometimes use the values TIFF_VARIABLE (-1), TIFF_VARIABLE2 (-3) - * and TIFF_SPP (-2). The macros should be used but would throw off - * the formatting of the code, so please interprete the -1, -2 and -3 - * values accordingly. - */ - -static TIFFFieldArray tiffFieldArray; -static TIFFFieldArray exifFieldArray; - -static TIFFField -tiffFields[] = { - { TIFFTAG_SUBFILETYPE, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_SUBFILETYPE, 1, 0, "SubfileType", NULL }, - { TIFFTAG_OSUBFILETYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_SUBFILETYPE, 1, 0, "OldSubfileType", NULL }, - { TIFFTAG_IMAGEWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_IMAGEDIMENSIONS, 0, 0, "ImageWidth", NULL }, - { TIFFTAG_IMAGELENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_IMAGEDIMENSIONS, 1, 0, "ImageLength", NULL }, - { TIFFTAG_BITSPERSAMPLE, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_BITSPERSAMPLE, 0, 0, "BitsPerSample", NULL }, - { TIFFTAG_COMPRESSION, -1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_COMPRESSION, 0, 0, "Compression", NULL }, - { TIFFTAG_PHOTOMETRIC, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_PHOTOMETRIC, 0, 0, "PhotometricInterpretation", NULL }, - { TIFFTAG_THRESHHOLDING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_THRESHHOLDING, 1, 0, "Threshholding", NULL }, - { TIFFTAG_CELLWIDTH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "CellWidth", NULL }, - { TIFFTAG_CELLLENGTH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "CellLength", NULL }, - { TIFFTAG_FILLORDER, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_FILLORDER, 0, 0, "FillOrder", NULL }, - { TIFFTAG_DOCUMENTNAME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DocumentName", NULL }, - { TIFFTAG_IMAGEDESCRIPTION, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageDescription", NULL }, - { TIFFTAG_MAKE, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Make", NULL }, - { TIFFTAG_MODEL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Model", NULL }, - { TIFFTAG_STRIPOFFSETS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPOFFSETS, 0, 0, "StripOffsets", NULL }, - { TIFFTAG_ORIENTATION, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_ORIENTATION, 0, 0, "Orientation", NULL }, - { TIFFTAG_SAMPLESPERPIXEL, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_SAMPLESPERPIXEL, 0, 0, "SamplesPerPixel", NULL }, - { TIFFTAG_ROWSPERSTRIP, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_ROWSPERSTRIP, 0, 0, "RowsPerStrip", NULL }, - { TIFFTAG_STRIPBYTECOUNTS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPBYTECOUNTS, 0, 0, "StripByteCounts", NULL }, - { TIFFTAG_MINSAMPLEVALUE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_MINSAMPLEVALUE, 1, 0, "MinSampleValue", NULL }, - { TIFFTAG_MAXSAMPLEVALUE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_MAXSAMPLEVALUE, 1, 0, "MaxSampleValue", NULL }, - { TIFFTAG_XRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTION, 1, 0, "XResolution", NULL }, - { TIFFTAG_YRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTION, 1, 0, "YResolution", NULL }, - { TIFFTAG_PLANARCONFIG, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_PLANARCONFIG, 0, 0, "PlanarConfiguration", NULL }, - { TIFFTAG_PAGENAME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PageName", NULL }, - { TIFFTAG_XPOSITION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_POSITION, 1, 0, "XPosition", NULL }, - { TIFFTAG_YPOSITION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_POSITION, 1, 0, "YPosition", NULL }, - { TIFFTAG_FREEOFFSETS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 0, 0, "FreeOffsets", NULL }, - { TIFFTAG_FREEBYTECOUNTS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 0, 0, "FreeByteCounts", NULL }, - { TIFFTAG_GRAYRESPONSEUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "GrayResponseUnit", NULL }, - { TIFFTAG_GRAYRESPONSECURVE, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "GrayResponseCurve", NULL }, - { TIFFTAG_RESOLUTIONUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTIONUNIT, 1, 0, "ResolutionUnit", NULL }, - { TIFFTAG_PAGENUMBER, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_PAGENUMBER, 1, 0, "PageNumber", NULL }, - { TIFFTAG_COLORRESPONSEUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "ColorResponseUnit", NULL }, - { TIFFTAG_TRANSFERFUNCTION, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_OTHER, TIFF_SETGET_UNDEFINED, FIELD_TRANSFERFUNCTION, 1, 0, "TransferFunction", NULL }, - { TIFFTAG_SOFTWARE, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Software", NULL }, - { TIFFTAG_DATETIME, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTime", NULL }, - { TIFFTAG_ARTIST, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Artist", NULL }, - { TIFFTAG_HOSTCOMPUTER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "HostComputer", NULL }, - { TIFFTAG_WHITEPOINT, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "WhitePoint", NULL }, - { TIFFTAG_PRIMARYCHROMATICITIES, 6, 6, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PrimaryChromaticities", NULL }, - { TIFFTAG_COLORMAP, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_OTHER, TIFF_SETGET_UNDEFINED, FIELD_COLORMAP, 1, 0, "ColorMap", NULL }, - { TIFFTAG_HALFTONEHINTS, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_HALFTONEHINTS, 1, 0, "HalftoneHints", NULL }, - { TIFFTAG_TILEWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_TILEDIMENSIONS, 0, 0, "TileWidth", NULL }, - { TIFFTAG_TILELENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_TILEDIMENSIONS, 0, 0, "TileLength", NULL }, - { TIFFTAG_TILEOFFSETS, -1, 1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPOFFSETS, 0, 0, "TileOffsets", NULL }, - { TIFFTAG_TILEBYTECOUNTS, -1, 1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPBYTECOUNTS, 0, 0, "TileByteCounts", NULL }, - { TIFFTAG_SUBIFD, -1, -1, TIFF_IFD8, 0, TIFF_SETGET_C16_IFD8, TIFF_SETGET_UNDEFINED, FIELD_SUBIFD, 1, 1, "SubIFD", &tiffFieldArray }, - { TIFFTAG_INKSET, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "InkSet", NULL }, - { TIFFTAG_INKNAMES, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_C16_ASCII, TIFF_SETGET_UNDEFINED, FIELD_INKNAMES, 1, 1, "InkNames", NULL }, - { TIFFTAG_NUMBEROFINKS, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "NumberOfInks", NULL }, - { TIFFTAG_DOTRANGE, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DotRange", NULL }, - { TIFFTAG_TARGETPRINTER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TargetPrinter", NULL }, - { TIFFTAG_EXTRASAMPLES, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_EXTRASAMPLES, 0, 1, "ExtraSamples", NULL }, - { TIFFTAG_SAMPLEFORMAT, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_SAMPLEFORMAT, 0, 0, "SampleFormat", NULL }, - { TIFFTAG_SMINSAMPLEVALUE, -2, -1, TIFF_ANY, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_SMINSAMPLEVALUE, 1, 0, "SMinSampleValue", NULL }, - { TIFFTAG_SMAXSAMPLEVALUE, -2, -1, TIFF_ANY, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_SMAXSAMPLEVALUE, 1, 0, "SMaxSampleValue", NULL }, - { TIFFTAG_CLIPPATH, -1, -3, TIFF_BYTE, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ClipPath", NULL }, - { TIFFTAG_XCLIPPATHUNITS, 1, 1, TIFF_SLONG, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "XClipPathUnits", NULL }, - { TIFFTAG_XCLIPPATHUNITS, 1, 1, TIFF_SBYTE, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "XClipPathUnits", NULL }, - { TIFFTAG_YCLIPPATHUNITS, 1, 1, TIFF_SLONG, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "YClipPathUnits", NULL }, - { TIFFTAG_YCBCRCOEFFICIENTS, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "YCbCrCoefficients", NULL }, - { TIFFTAG_YCBCRSUBSAMPLING, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_YCBCRSUBSAMPLING, 0, 0, "YCbCrSubsampling", NULL }, - { TIFFTAG_YCBCRPOSITIONING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_YCBCRPOSITIONING, 0, 0, "YCbCrPositioning", NULL }, - { TIFFTAG_REFERENCEBLACKWHITE, 6, 6, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_REFBLACKWHITE, 1, 0, "ReferenceBlackWhite", NULL }, - { TIFFTAG_XMLPACKET, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "XMLPacket", NULL }, - /* begin SGI tags */ - { TIFFTAG_MATTEING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_EXTRASAMPLES, 0, 0, "Matteing", NULL }, - { TIFFTAG_DATATYPE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_SAMPLEFORMAT, 0, 0, "DataType", NULL }, - { TIFFTAG_IMAGEDEPTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_IMAGEDEPTH, 0, 0, "ImageDepth", NULL }, - { TIFFTAG_TILEDEPTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_TILEDEPTH, 0, 0, "TileDepth", NULL }, - /* end SGI tags */ - /* begin Pixar tags */ - { TIFFTAG_PIXAR_IMAGEFULLWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageFullWidth", NULL }, - { TIFFTAG_PIXAR_IMAGEFULLLENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageFullLength", NULL }, - { TIFFTAG_PIXAR_TEXTUREFORMAT, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TextureFormat", NULL }, - { TIFFTAG_PIXAR_WRAPMODES, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TextureWrapModes", NULL }, - { TIFFTAG_PIXAR_FOVCOT, 1, 1, TIFF_FLOAT, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FieldOfViewCotangent", NULL }, - { TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN, 16, 16, TIFF_FLOAT, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MatrixWorldToScreen", NULL }, - { TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA, 16, 16, TIFF_FLOAT, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MatrixWorldToCamera", NULL }, - { TIFFTAG_COPYRIGHT, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Copyright", NULL }, - /* end Pixar tags */ - { TIFFTAG_RICHTIFFIPTC, -3, -3, TIFF_LONG, 0, TIFF_SETGET_C32_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "RichTIFFIPTC", NULL }, - { TIFFTAG_PHOTOSHOP, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Photoshop", NULL }, - { TIFFTAG_EXIFIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "EXIFIFDOffset", &exifFieldArray }, - { TIFFTAG_ICCPROFILE, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ICC Profile", NULL }, - { TIFFTAG_GPSIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "GPSIFDOffset", NULL }, - { TIFFTAG_FAXRECVPARAMS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvParams", NULL }, - { TIFFTAG_FAXSUBADDRESS, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_ASCII, FIELD_CUSTOM, TRUE, FALSE, "FaxSubAddress", NULL }, - { TIFFTAG_FAXRECVTIME, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvTime", NULL }, - { TIFFTAG_FAXDCS, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_ASCII, FIELD_CUSTOM, TRUE, FALSE, "FaxDcs", NULL }, - { TIFFTAG_STONITS, 1, 1, TIFF_DOUBLE, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "StoNits", NULL }, - { TIFFTAG_INTEROPERABILITYIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "InteroperabilityIFDOffset", NULL }, - /* begin DNG tags */ - { TIFFTAG_DNGVERSION, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DNGVersion", NULL }, - { TIFFTAG_DNGBACKWARDVERSION, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DNGBackwardVersion", NULL }, - { TIFFTAG_UNIQUECAMERAMODEL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "UniqueCameraModel", NULL }, - { TIFFTAG_LOCALIZEDCAMERAMODEL, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "LocalizedCameraModel", NULL }, - { TIFFTAG_CFAPLANECOLOR, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CFAPlaneColor", NULL }, - { TIFFTAG_CFALAYOUT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CFALayout", NULL }, - { TIFFTAG_LINEARIZATIONTABLE, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "LinearizationTable", NULL }, - { TIFFTAG_BLACKLEVELREPEATDIM, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BlackLevelRepeatDim", NULL }, - { TIFFTAG_BLACKLEVEL, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevel", NULL }, - { TIFFTAG_BLACKLEVELDELTAH, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevelDeltaH", NULL }, - { TIFFTAG_BLACKLEVELDELTAV, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevelDeltaV", NULL }, - { TIFFTAG_WHITELEVEL, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "WhiteLevel", NULL }, - { TIFFTAG_DEFAULTSCALE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultScale", NULL }, - { TIFFTAG_BESTQUALITYSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BestQualityScale", NULL }, - { TIFFTAG_DEFAULTCROPORIGIN, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultCropOrigin", NULL }, - { TIFFTAG_DEFAULTCROPSIZE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultCropSize", NULL }, - { TIFFTAG_COLORMATRIX1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ColorMatrix1", NULL }, - { TIFFTAG_COLORMATRIX2, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ColorMatrix2", NULL }, - { TIFFTAG_CAMERACALIBRATION1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CameraCalibration1", NULL }, - { TIFFTAG_CAMERACALIBRATION2, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CameraCalibration2", NULL }, - { TIFFTAG_REDUCTIONMATRIX1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ReductionMatrix1", NULL }, - { TIFFTAG_REDUCTIONMATRIX2, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ReductionMatrix2", NULL }, - { TIFFTAG_ANALOGBALANCE, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AnalogBalance", NULL }, - { TIFFTAG_ASSHOTNEUTRAL, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotNeutral", NULL }, - { TIFFTAG_ASSHOTWHITEXY, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "AsShotWhiteXY", NULL }, - { TIFFTAG_BASELINEEXPOSURE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineExposure", NULL }, - { TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineNoise", NULL }, - { TIFFTAG_BASELINESHARPNESS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineSharpness", NULL }, - { TIFFTAG_BAYERGREENSPLIT, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BayerGreenSplit", NULL }, - { TIFFTAG_LINEARRESPONSELIMIT, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "LinearResponseLimit", NULL }, - { TIFFTAG_CAMERASERIALNUMBER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CameraSerialNumber", NULL }, - { TIFFTAG_LENSINFO, 4, 4, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "LensInfo", NULL }, - { TIFFTAG_CHROMABLURRADIUS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ChromaBlurRadius", NULL }, - { TIFFTAG_ANTIALIASSTRENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "AntiAliasStrength", NULL }, - { TIFFTAG_SHADOWSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ShadowScale", NULL }, - { TIFFTAG_DNGPRIVATEDATA, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "DNGPrivateData", NULL }, - { TIFFTAG_MAKERNOTESAFETY, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "MakerNoteSafety", NULL }, - { TIFFTAG_CALIBRATIONILLUMINANT1, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CalibrationIlluminant1", NULL }, - { TIFFTAG_CALIBRATIONILLUMINANT2, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CalibrationIlluminant2", NULL }, - { TIFFTAG_RAWDATAUNIQUEID, 16, 16, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "RawDataUniqueID", NULL }, - { TIFFTAG_ORIGINALRAWFILENAME, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "OriginalRawFileName", NULL }, - { TIFFTAG_ORIGINALRAWFILEDATA, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "OriginalRawFileData", NULL }, - { TIFFTAG_ACTIVEAREA, 4, 4, TIFF_LONG, 0, TIFF_SETGET_C0_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ActiveArea", NULL }, - { TIFFTAG_MASKEDAREAS, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "MaskedAreas", NULL }, - { TIFFTAG_ASSHOTICCPROFILE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotICCProfile", NULL }, - { TIFFTAG_ASSHOTPREPROFILEMATRIX, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotPreProfileMatrix", NULL }, - { TIFFTAG_CURRENTICCPROFILE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CurrentICCProfile", NULL }, - { TIFFTAG_CURRENTPREPROFILEMATRIX, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CurrentPreProfileMatrix", NULL }, - { TIFFTAG_PERSAMPLE, 0, 0, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "PerSample", NULL}, - /* end DNG tags */ - /* begin TIFF/FX tags */ - { TIFFTAG_INDEXED, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Indexed" }, - { TIFFTAG_GLOBALPARAMETERSIFD, 1, 1, TIFF_IFD, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "GlobalParametersIFD", NULL }, - { TIFFTAG_PROFILETYPE, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ProfileType", NULL }, - { TIFFTAG_FAXPROFILE, 1, 1, TIFF_BYTE, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "FaxProfile", NULL }, - { TIFFTAG_CODINGMETHODS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CodingMethods", NULL }, - { TIFFTAG_VERSIONYEAR, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "VersionYear", NULL }, - { TIFFTAG_MODENUMBER, 1, 1, TIFF_BYTE, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ModeNumber", NULL }, - { TIFFTAG_DECODE, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Decode", NULL }, - { TIFFTAG_IMAGEBASECOLOR, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ImageBaseColor", NULL }, - { TIFFTAG_T82OPTIONS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "T82Options", NULL }, - { TIFFTAG_STRIPROWCOUNTS, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "StripRowCounts", NULL }, - { TIFFTAG_IMAGELAYER, 2, 2, TIFF_LONG, 0, TIFF_SETGET_C0_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ImageLayer", NULL }, - /* end DNG tags */ - /* begin pseudo tags */ -}; - -static TIFFField -exifFields[] = { - { EXIFTAG_EXPOSURETIME, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureTime", NULL }, - { EXIFTAG_FNUMBER, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FNumber", NULL }, - { EXIFTAG_EXPOSUREPROGRAM, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureProgram", NULL }, - { EXIFTAG_SPECTRALSENSITIVITY, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SpectralSensitivity", NULL }, - { EXIFTAG_ISOSPEEDRATINGS, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "ISOSpeedRatings", NULL }, - { EXIFTAG_OECF, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "OptoelectricConversionFactor", NULL }, - { EXIFTAG_EXIFVERSION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExifVersion", NULL }, - { EXIFTAG_DATETIMEORIGINAL, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTimeOriginal", NULL }, - { EXIFTAG_DATETIMEDIGITIZED, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTimeDigitized", NULL }, - { EXIFTAG_COMPONENTSCONFIGURATION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ComponentsConfiguration", NULL }, - { EXIFTAG_COMPRESSEDBITSPERPIXEL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CompressedBitsPerPixel", NULL }, - { EXIFTAG_SHUTTERSPEEDVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ShutterSpeedValue", NULL }, - { EXIFTAG_APERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ApertureValue", NULL }, - { EXIFTAG_BRIGHTNESSVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "BrightnessValue", NULL }, - { EXIFTAG_EXPOSUREBIASVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureBiasValue", NULL }, - { EXIFTAG_MAXAPERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MaxApertureValue", NULL }, - { EXIFTAG_SUBJECTDISTANCE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistance", NULL }, - { EXIFTAG_METERINGMODE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MeteringMode", NULL }, - { EXIFTAG_LIGHTSOURCE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LightSource", NULL }, - { EXIFTAG_FLASH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Flash", NULL }, - { EXIFTAG_FOCALLENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalLength", NULL }, - { EXIFTAG_SUBJECTAREA, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "SubjectArea", NULL }, - { EXIFTAG_MAKERNOTE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "MakerNote", NULL }, - { EXIFTAG_USERCOMMENT, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "UserComment", NULL }, - { EXIFTAG_SUBSECTIME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTime", NULL }, - { EXIFTAG_SUBSECTIMEORIGINAL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTimeOriginal", NULL }, - { EXIFTAG_SUBSECTIMEDIGITIZED, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTimeDigitized", NULL }, - { EXIFTAG_FLASHPIXVERSION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FlashpixVersion", NULL }, - { EXIFTAG_COLORSPACE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ColorSpace", NULL }, - { EXIFTAG_PIXELXDIMENSION, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PixelXDimension", NULL }, - { EXIFTAG_PIXELYDIMENSION, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PixelYDimension", NULL }, - { EXIFTAG_RELATEDSOUNDFILE, 13, 13, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "RelatedSoundFile", NULL }, - { EXIFTAG_FLASHENERGY, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FlashEnergy", NULL }, - { EXIFTAG_SPATIALFREQUENCYRESPONSE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "SpatialFrequencyResponse", NULL }, - { EXIFTAG_FOCALPLANEXRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneXResolution", NULL }, - { EXIFTAG_FOCALPLANEYRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneYResolution", NULL }, - { EXIFTAG_FOCALPLANERESOLUTIONUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneResolutionUnit", NULL }, - { EXIFTAG_SUBJECTLOCATION, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectLocation", NULL }, - { EXIFTAG_EXPOSUREINDEX, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureIndex", NULL }, - { EXIFTAG_SENSINGMETHOD, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SensingMethod", NULL }, - { EXIFTAG_FILESOURCE, 1, 1, TIFF_UNDEFINED, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FileSource", NULL }, - { EXIFTAG_SCENETYPE, 1, 1, TIFF_UNDEFINED, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SceneType", NULL }, - { EXIFTAG_CFAPATTERN, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "CFAPattern", NULL }, - { EXIFTAG_CUSTOMRENDERED, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CustomRendered", NULL }, - { EXIFTAG_EXPOSUREMODE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureMode", NULL }, - { EXIFTAG_WHITEBALANCE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "WhiteBalance", NULL }, - { EXIFTAG_DIGITALZOOMRATIO, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DigitalZoomRatio", NULL }, - { EXIFTAG_FOCALLENGTHIN35MMFILM, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalLengthIn35mmFilm", NULL }, - { EXIFTAG_SCENECAPTURETYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SceneCaptureType", NULL }, - { EXIFTAG_GAINCONTROL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "GainControl", NULL }, - { EXIFTAG_CONTRAST, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Contrast", NULL }, - { EXIFTAG_SATURATION, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Saturation", NULL }, - { EXIFTAG_SHARPNESS, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Sharpness", NULL }, - { EXIFTAG_DEVICESETTINGDESCRIPTION, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "DeviceSettingDescription", NULL }, - { EXIFTAG_SUBJECTDISTANCERANGE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistanceRange", NULL }, - { EXIFTAG_IMAGEUNIQUEID, 33, 33, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageUniqueID", NULL } -}; - -static TIFFFieldArray -tiffFieldArray = { tfiatImage, 0, TIFFArrayCount(tiffFields), tiffFields }; -static TIFFFieldArray -exifFieldArray = { tfiatExif, 0, TIFFArrayCount(exifFields), exifFields }; - -/* - * We have our own local lfind() equivelent to avoid subtle differences - * in types passed to lfind() on different systems. - */ - -static void * -td_lfind(const void *key, const void *base, size_t *nmemb, size_t size, - int(*compar)(const void *, const void *)) -{ - char *element, *end; - - end = (char *)base + *nmemb * size; - for (element = (char *)base; element < end; element += size) - if (!compar(key, element)) /* key found */ - return element; - - return NULL; -} - -const TIFFFieldArray* -_TIFFGetFields(void) -{ - return(&tiffFieldArray); -} - -const TIFFFieldArray* -_TIFFGetExifFields(void) -{ - return(&exifFieldArray); -} - -void -_TIFFSetupFields(TIFF* tif, const TIFFFieldArray* fieldarray) -{ - if (tif->tif_fields && tif->tif_nfields > 0) { - uint32 i; - - for (i = 0; i < tif->tif_nfields; i++) { - TIFFField *fld = tif->tif_fields[i]; - if (fld->field_bit == FIELD_CUSTOM && - strncmp("Tag ", fld->field_name, 4) == 0) { - _TIFFfree(fld->field_name); - _TIFFfree(fld); - } - } - - _TIFFfree(tif->tif_fields); - tif->tif_fields = NULL; - tif->tif_nfields = 0; - } - if (!_TIFFMergeFields(tif, fieldarray->fields, fieldarray->count)) { - TIFFErrorExt(tif->tif_clientdata, "_TIFFSetupFields", - "Setting up field info failed"); - } -} - -static int -tagCompare(const void* a, const void* b) -{ - const TIFFField* ta = *(const TIFFField**) a; - const TIFFField* tb = *(const TIFFField**) b; - /* NB: be careful of return values for 16-bit platforms */ - if (ta->field_tag != tb->field_tag) - return (int)ta->field_tag - (int)tb->field_tag; - else - return (ta->field_type == TIFF_ANY) ? - 0 : ((int)tb->field_type - (int)ta->field_type); -} - -static int -tagNameCompare(const void* a, const void* b) -{ - const TIFFField* ta = *(const TIFFField**) a; - const TIFFField* tb = *(const TIFFField**) b; - int ret = strcmp(ta->field_name, tb->field_name); - - if (ret) - return ret; - else - return (ta->field_type == TIFF_ANY) ? - 0 : ((int)tb->field_type - (int)ta->field_type); -} - -int -_TIFFMergeFields(TIFF* tif, const TIFFField info[], uint32 n) -{ - static const char module[] = "_TIFFMergeFields"; - static const char reason[] = "for fields array"; - /* TIFFField** tp; */ - uint32 i; - - tif->tif_foundfield = NULL; - - if (tif->tif_fields && tif->tif_nfields > 0) { - tif->tif_fields = (TIFFField**) - _TIFFCheckRealloc(tif, tif->tif_fields, - (tif->tif_nfields + n), - sizeof(TIFFField *), reason); - } else { - tif->tif_fields = (TIFFField **) - _TIFFCheckMalloc(tif, n, sizeof(TIFFField *), - reason); - } - if (!tif->tif_fields) { - TIFFErrorExt(tif->tif_clientdata, module, - "Failed to allocate fields array"); - return 0; - } - - /* tp = tif->tif_fields + tif->tif_nfields; */ - for (i = 0; i < n; i++) { - const TIFFField *fip = - TIFFFindField(tif, info[i].field_tag, TIFF_ANY); - - /* only add definitions that aren't already present */ - if (!fip) { - tif->tif_fields[tif->tif_nfields] = (TIFFField *) (info+i); - tif->tif_nfields++; - } - } - - /* Sort the field info by tag number */ - qsort(tif->tif_fields, tif->tif_nfields, - sizeof(TIFFField *), tagCompare); - - return n; -} - -void -_TIFFPrintFieldInfo(TIFF* tif, FILE* fd) -{ - uint32 i; - - fprintf(fd, "%s: \n", tif->tif_name); - for (i = 0; i < tif->tif_nfields; i++) { - const TIFFField* fip = tif->tif_fields[i]; - fprintf(fd, "field[%2d] %5lu, %2d, %2d, %d, %2d, %5s, %5s, %s\n" - , (int)i - , (unsigned long) fip->field_tag - , fip->field_readcount, fip->field_writecount - , fip->field_type - , fip->field_bit - , fip->field_oktochange ? "TRUE" : "FALSE" - , fip->field_passcount ? "TRUE" : "FALSE" - , fip->field_name - ); - } -} - -/* - * Return size of TIFFDataType in bytes - */ -int -TIFFDataWidth(TIFFDataType type) -{ - switch(type) - { - case 0: /* nothing */ - case TIFF_BYTE: - case TIFF_ASCII: - case TIFF_SBYTE: - case TIFF_UNDEFINED: - return 1; - case TIFF_SHORT: - case TIFF_SSHORT: - return 2; - case TIFF_LONG: - case TIFF_SLONG: - case TIFF_FLOAT: - case TIFF_IFD: - return 4; - case TIFF_RATIONAL: - case TIFF_SRATIONAL: - case TIFF_DOUBLE: - case TIFF_LONG8: - case TIFF_SLONG8: - case TIFF_IFD8: - return 8; - default: - return 0; /* will return 0 for unknown types */ - } -} - -/* - * Return size of TIFFDataType in bytes. - * - * XXX: We need a separate function to determine the space needed - * to store the value. For TIFF_RATIONAL values TIFFDataWidth() returns 8, - * but we use 4-byte float to represent rationals. - */ -int -_TIFFDataSize(TIFFDataType type) -{ - switch (type) - { - case TIFF_BYTE: - case TIFF_SBYTE: - case TIFF_ASCII: - case TIFF_UNDEFINED: - return 1; - case TIFF_SHORT: - case TIFF_SSHORT: - return 2; - case TIFF_LONG: - case TIFF_SLONG: - case TIFF_FLOAT: - case TIFF_IFD: - case TIFF_RATIONAL: - case TIFF_SRATIONAL: - return 4; - case TIFF_DOUBLE: - case TIFF_LONG8: - case TIFF_SLONG8: - case TIFF_IFD8: - return 8; - default: - return 0; - } -} - -const TIFFField* -TIFFFindField(TIFF* tif, uint32 tag, TIFFDataType dt) -{ - TIFFField key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0, 0, 0, NULL, NULL}; - TIFFField* pkey = &key; - const TIFFField **ret; - if (tif->tif_foundfield && tif->tif_foundfield->field_tag == tag && - (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type)) - return tif->tif_foundfield; - - /* If we are invoked with no field information, then just return. */ - if (!tif->tif_fields) - return NULL; - - /* NB: use sorted search (e.g. binary search) */ - - key.field_tag = tag; - key.field_type = dt; - - ret = (const TIFFField **) bsearch(&pkey, tif->tif_fields, - tif->tif_nfields, - sizeof(TIFFField *), tagCompare); - return tif->tif_foundfield = (ret ? *ret : NULL); -} - -const TIFFField* -_TIFFFindFieldByName(TIFF* tif, const char *field_name, TIFFDataType dt) -{ - TIFFField key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0, 0, 0, NULL, NULL}; - TIFFField* pkey = &key; - const TIFFField **ret; - if (tif->tif_foundfield - && streq(tif->tif_foundfield->field_name, field_name) - && (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type)) - return (tif->tif_foundfield); - - /* If we are invoked with no field information, then just return. */ - if (!tif->tif_fields) - return NULL; - - /* NB: use linear search since list is sorted by key#, not name */ - - key.field_name = (char *)field_name; - key.field_type = dt; - - ret = (const TIFFField **) - td_lfind(&pkey, tif->tif_fields, &tif->tif_nfields, - sizeof(TIFFField *), tagNameCompare); - - return tif->tif_foundfield = (ret ? *ret : NULL); -} - -const TIFFField* -TIFFFieldWithTag(TIFF* tif, uint32 tag) -{ - const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY); - if (!fip) { - TIFFErrorExt(tif->tif_clientdata, "TIFFFieldWithTag", - "Internal error, unknown tag 0x%x", - (unsigned int) tag); - } - return (fip); -} - -const TIFFField* -TIFFFieldWithName(TIFF* tif, const char *field_name) -{ - const TIFFField* fip = - _TIFFFindFieldByName(tif, field_name, TIFF_ANY); - if (!fip) { - TIFFErrorExt(tif->tif_clientdata, "TIFFFieldWithName", - "Internal error, unknown tag %s", field_name); - } - return (fip); -} - -uint32 -TIFFFieldTag(const TIFFField* fip) -{ - return fip->field_tag; -} - -const char * -TIFFFieldName(const TIFFField* fip) -{ - return fip->field_name; -} - -TIFFDataType -TIFFFieldDataType(const TIFFField* fip) -{ - return fip->field_type; -} - -int -TIFFFieldPassCount(const TIFFField* fip) -{ - return fip->field_passcount; -} - -int -TIFFFieldReadCount(const TIFFField* fip) -{ - return fip->field_readcount; -} - -int -TIFFFieldWriteCount(const TIFFField* fip) -{ - return fip->field_writecount; -} - -const TIFFField* -_TIFFFindOrRegisterField(TIFF *tif, uint32 tag, TIFFDataType dt) - -{ - const TIFFField *fld; - - fld = TIFFFindField(tif, tag, dt); - if (fld == NULL) { - fld = _TIFFCreateAnonField(tif, tag, dt); - if (!_TIFFMergeFields(tif, fld, 1)) - return NULL; - } - - return fld; -} - -TIFFField* -_TIFFCreateAnonField(TIFF *tif, uint32 tag, TIFFDataType field_type) -{ - TIFFField *fld; - (void) tif; - - fld = (TIFFField *) _TIFFmalloc(sizeof (TIFFField)); - if (fld == NULL) - return NULL; - _TIFFmemset(fld, 0, sizeof(TIFFField)); - - fld->field_tag = tag; - fld->field_readcount = TIFF_VARIABLE2; - fld->field_writecount = TIFF_VARIABLE2; - fld->field_type = field_type; - fld->reserved = 0; - switch (field_type) - { - case TIFF_BYTE: - case TIFF_UNDEFINED: - fld->set_field_type = TIFF_SETGET_C32_UINT8; - fld->get_field_type = TIFF_SETGET_C32_UINT8; - break; - case TIFF_ASCII: - fld->set_field_type = TIFF_SETGET_C32_ASCII; - fld->get_field_type = TIFF_SETGET_C32_ASCII; - break; - case TIFF_SHORT: - fld->set_field_type = TIFF_SETGET_C32_UINT16; - fld->get_field_type = TIFF_SETGET_C32_UINT16; - break; - case TIFF_LONG: - fld->set_field_type = TIFF_SETGET_C32_UINT32; - fld->get_field_type = TIFF_SETGET_C32_UINT32; - break; - case TIFF_RATIONAL: - case TIFF_SRATIONAL: - case TIFF_FLOAT: - fld->set_field_type = TIFF_SETGET_C32_FLOAT; - fld->get_field_type = TIFF_SETGET_C32_FLOAT; - break; - case TIFF_SBYTE: - fld->set_field_type = TIFF_SETGET_C32_SINT8; - fld->get_field_type = TIFF_SETGET_C32_SINT8; - break; - case TIFF_SSHORT: - fld->set_field_type = TIFF_SETGET_C32_SINT16; - fld->get_field_type = TIFF_SETGET_C32_SINT16; - break; - case TIFF_SLONG: - fld->set_field_type = TIFF_SETGET_C32_SINT32; - fld->get_field_type = TIFF_SETGET_C32_SINT32; - break; - case TIFF_DOUBLE: - fld->set_field_type = TIFF_SETGET_C32_DOUBLE; - fld->get_field_type = TIFF_SETGET_C32_DOUBLE; - break; - case TIFF_IFD: - case TIFF_IFD8: - fld->set_field_type = TIFF_SETGET_C32_IFD8; - fld->get_field_type = TIFF_SETGET_C32_IFD8; - break; - case TIFF_LONG8: - fld->set_field_type = TIFF_SETGET_C32_UINT64; - fld->get_field_type = TIFF_SETGET_C32_UINT64; - break; - case TIFF_SLONG8: - fld->set_field_type = TIFF_SETGET_C32_SINT64; - fld->get_field_type = TIFF_SETGET_C32_SINT64; - break; - default: - fld->set_field_type = TIFF_SETGET_UNDEFINED; - fld->get_field_type = TIFF_SETGET_UNDEFINED; - break; - } - fld->field_bit = FIELD_CUSTOM; - fld->field_oktochange = TRUE; - fld->field_passcount = TRUE; - fld->field_name = (char *) _TIFFmalloc(32); - if (fld->field_name == NULL) { - _TIFFfree(fld); - return NULL; - } - fld->field_subfields = NULL; - - /* - * note that this name is a special sign to TIFFClose() and - * _TIFFSetupFields() to free the field - */ - sprintf(fld->field_name, "Tag %d", (int) tag); - - return fld; -} - -/**************************************************************************** - * O B S O L E T E D I N T E R F A C E S - * - * Don't use this stuff in your applications, it may be removed in the future - * libtiff versions. - ****************************************************************************/ - -static TIFFSetGetFieldType -_TIFFSetGetType(TIFFDataType type, short count, unsigned char passcount) -{ - if (type == TIFF_ASCII && count == TIFF_VARIABLE && passcount == 0) - return TIFF_SETGET_ASCII; - - else if (count == 1 && passcount == 0) { - switch (type) - { - case TIFF_BYTE: - case TIFF_UNDEFINED: - return TIFF_SETGET_UINT8; - case TIFF_ASCII: - return TIFF_SETGET_ASCII; - case TIFF_SHORT: - return TIFF_SETGET_UINT16; - case TIFF_LONG: - return TIFF_SETGET_UINT32; - case TIFF_RATIONAL: - case TIFF_SRATIONAL: - case TIFF_FLOAT: - return TIFF_SETGET_FLOAT; - case TIFF_SBYTE: - return TIFF_SETGET_SINT8; - case TIFF_SSHORT: - return TIFF_SETGET_SINT16; - case TIFF_SLONG: - return TIFF_SETGET_SINT32; - case TIFF_DOUBLE: - return TIFF_SETGET_DOUBLE; - case TIFF_IFD: - case TIFF_IFD8: - return TIFF_SETGET_IFD8; - case TIFF_LONG8: - return TIFF_SETGET_UINT64; - case TIFF_SLONG8: - return TIFF_SETGET_SINT64; - default: - return TIFF_SETGET_UNDEFINED; - } - } - - else if (count >= 1 && passcount == 0) { - switch (type) - { - case TIFF_BYTE: - case TIFF_UNDEFINED: - return TIFF_SETGET_C0_UINT8; - case TIFF_ASCII: - return TIFF_SETGET_C0_ASCII; - case TIFF_SHORT: - return TIFF_SETGET_C0_UINT16; - case TIFF_LONG: - return TIFF_SETGET_C0_UINT32; - case TIFF_RATIONAL: - case TIFF_SRATIONAL: - case TIFF_FLOAT: - return TIFF_SETGET_C0_FLOAT; - case TIFF_SBYTE: - return TIFF_SETGET_C0_SINT8; - case TIFF_SSHORT: - return TIFF_SETGET_C0_SINT16; - case TIFF_SLONG: - return TIFF_SETGET_C0_SINT32; - case TIFF_DOUBLE: - return TIFF_SETGET_C0_DOUBLE; - case TIFF_IFD: - case TIFF_IFD8: - return TIFF_SETGET_C0_IFD8; - case TIFF_LONG8: - return TIFF_SETGET_C0_UINT64; - case TIFF_SLONG8: - return TIFF_SETGET_C0_SINT64; - default: - return TIFF_SETGET_UNDEFINED; - } - } - - else if (count == TIFF_VARIABLE && passcount == 1) { - switch (type) - { - case TIFF_BYTE: - case TIFF_UNDEFINED: - return TIFF_SETGET_C16_UINT8; - case TIFF_ASCII: - return TIFF_SETGET_C16_ASCII; - case TIFF_SHORT: - return TIFF_SETGET_C16_UINT16; - case TIFF_LONG: - return TIFF_SETGET_C16_UINT32; - case TIFF_RATIONAL: - case TIFF_SRATIONAL: - case TIFF_FLOAT: - return TIFF_SETGET_C16_FLOAT; - case TIFF_SBYTE: - return TIFF_SETGET_C16_SINT8; - case TIFF_SSHORT: - return TIFF_SETGET_C16_SINT16; - case TIFF_SLONG: - return TIFF_SETGET_C16_SINT32; - case TIFF_DOUBLE: - return TIFF_SETGET_C16_DOUBLE; - case TIFF_IFD: - case TIFF_IFD8: - return TIFF_SETGET_C16_IFD8; - case TIFF_LONG8: - return TIFF_SETGET_C16_UINT64; - case TIFF_SLONG8: - return TIFF_SETGET_C16_SINT64; - default: - return TIFF_SETGET_UNDEFINED; - } - } - - else if (count == TIFF_VARIABLE2 && passcount == 1) { - switch (type) - { - case TIFF_BYTE: - case TIFF_UNDEFINED: - return TIFF_SETGET_C32_UINT8; - case TIFF_ASCII: - return TIFF_SETGET_C32_ASCII; - case TIFF_SHORT: - return TIFF_SETGET_C32_UINT16; - case TIFF_LONG: - return TIFF_SETGET_C32_UINT32; - case TIFF_RATIONAL: - case TIFF_SRATIONAL: - case TIFF_FLOAT: - return TIFF_SETGET_C32_FLOAT; - case TIFF_SBYTE: - return TIFF_SETGET_C32_SINT8; - case TIFF_SSHORT: - return TIFF_SETGET_C32_SINT16; - case TIFF_SLONG: - return TIFF_SETGET_C32_SINT32; - case TIFF_DOUBLE: - return TIFF_SETGET_C32_DOUBLE; - case TIFF_IFD: - case TIFF_IFD8: - return TIFF_SETGET_C32_IFD8; - case TIFF_LONG8: - return TIFF_SETGET_C32_UINT64; - case TIFF_SLONG8: - return TIFF_SETGET_C32_SINT64; - default: - return TIFF_SETGET_UNDEFINED; - } - } - - return TIFF_SETGET_UNDEFINED; -} - -int -TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], uint32 n) -{ - static const char module[] = "TIFFMergeFieldInfo"; - static const char reason[] = "for fields array"; - TIFFField *tp; - size_t nfields; - uint32 i; - - if (tif->tif_nfieldscompat > 0) { - tif->tif_fieldscompat = (TIFFFieldArray *) - _TIFFCheckRealloc(tif, tif->tif_fieldscompat, - tif->tif_nfieldscompat + 1, - sizeof(TIFFFieldArray), reason); - } else { - tif->tif_fieldscompat = (TIFFFieldArray *) - _TIFFCheckMalloc(tif, 1, sizeof(TIFFFieldArray), - reason); - } - if (!tif->tif_fieldscompat) { - TIFFErrorExt(tif->tif_clientdata, module, - "Failed to allocate fields array"); - return -1; - } - nfields = tif->tif_nfieldscompat++; - - tif->tif_fieldscompat[nfields].type = tfiatOther; - tif->tif_fieldscompat[nfields].allocated_size = n; - tif->tif_fieldscompat[nfields].count = n; - tif->tif_fieldscompat[nfields].fields = - (TIFFField *)_TIFFCheckMalloc(tif, n, sizeof(TIFFField), - reason); - if (!tif->tif_fieldscompat[nfields].fields) { - TIFFErrorExt(tif->tif_clientdata, module, - "Failed to allocate fields array"); - return -1; - } - - tp = tif->tif_fieldscompat[nfields].fields; - for (i = 0; i < n; i++) { - tp->field_tag = info[i].field_tag; - tp->field_readcount = info[i].field_readcount; - tp->field_writecount = info[i].field_writecount; - tp->field_type = info[i].field_type; - tp->reserved = 0; - tp->set_field_type = - _TIFFSetGetType(info[i].field_type, - info[i].field_readcount, - info[i].field_passcount); - tp->get_field_type = - _TIFFSetGetType(info[i].field_type, - info[i].field_readcount, - info[i].field_passcount); - tp->field_bit = info[i].field_bit; - tp->field_oktochange = info[i].field_oktochange; - tp->field_passcount = info[i].field_passcount; - tp->field_name = info[i].field_name; - tp->field_subfields = NULL; - tp++; - } - - if (!_TIFFMergeFields(tif, tif->tif_fieldscompat[nfields].fields, n)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Setting up field info failed"); - return -1; - } - - return 0; -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ - -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_dirinfo.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * + * Core Directory Tag Support. + */ +#include "tiffiop.h" +#include + +/* + * NOTE: THIS ARRAY IS ASSUMED TO BE SORTED BY TAG. + * + * NOTE: The second field (field_readcount) and third field (field_writecount) + * sometimes use the values TIFF_VARIABLE (-1), TIFF_VARIABLE2 (-3) + * and TIFF_SPP (-2). The macros should be used but would throw off + * the formatting of the code, so please interprete the -1, -2 and -3 + * values accordingly. + */ + +static TIFFFieldArray tiffFieldArray; +static TIFFFieldArray exifFieldArray; + +static TIFFField +tiffFields[] = { + { TIFFTAG_SUBFILETYPE, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_SUBFILETYPE, 1, 0, "SubfileType", NULL }, + { TIFFTAG_OSUBFILETYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_SUBFILETYPE, 1, 0, "OldSubfileType", NULL }, + { TIFFTAG_IMAGEWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_IMAGEDIMENSIONS, 0, 0, "ImageWidth", NULL }, + { TIFFTAG_IMAGELENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_IMAGEDIMENSIONS, 1, 0, "ImageLength", NULL }, + { TIFFTAG_BITSPERSAMPLE, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_BITSPERSAMPLE, 0, 0, "BitsPerSample", NULL }, + { TIFFTAG_COMPRESSION, -1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_COMPRESSION, 0, 0, "Compression", NULL }, + { TIFFTAG_PHOTOMETRIC, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_PHOTOMETRIC, 0, 0, "PhotometricInterpretation", NULL }, + { TIFFTAG_THRESHHOLDING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_THRESHHOLDING, 1, 0, "Threshholding", NULL }, + { TIFFTAG_CELLWIDTH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "CellWidth", NULL }, + { TIFFTAG_CELLLENGTH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "CellLength", NULL }, + { TIFFTAG_FILLORDER, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_FILLORDER, 0, 0, "FillOrder", NULL }, + { TIFFTAG_DOCUMENTNAME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DocumentName", NULL }, + { TIFFTAG_IMAGEDESCRIPTION, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageDescription", NULL }, + { TIFFTAG_MAKE, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Make", NULL }, + { TIFFTAG_MODEL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Model", NULL }, + { TIFFTAG_STRIPOFFSETS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPOFFSETS, 0, 0, "StripOffsets", NULL }, + { TIFFTAG_ORIENTATION, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_ORIENTATION, 0, 0, "Orientation", NULL }, + { TIFFTAG_SAMPLESPERPIXEL, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_SAMPLESPERPIXEL, 0, 0, "SamplesPerPixel", NULL }, + { TIFFTAG_ROWSPERSTRIP, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_ROWSPERSTRIP, 0, 0, "RowsPerStrip", NULL }, + { TIFFTAG_STRIPBYTECOUNTS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPBYTECOUNTS, 0, 0, "StripByteCounts", NULL }, + { TIFFTAG_MINSAMPLEVALUE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_MINSAMPLEVALUE, 1, 0, "MinSampleValue", NULL }, + { TIFFTAG_MAXSAMPLEVALUE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_MAXSAMPLEVALUE, 1, 0, "MaxSampleValue", NULL }, + { TIFFTAG_XRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTION, 1, 0, "XResolution", NULL }, + { TIFFTAG_YRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTION, 1, 0, "YResolution", NULL }, + { TIFFTAG_PLANARCONFIG, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_PLANARCONFIG, 0, 0, "PlanarConfiguration", NULL }, + { TIFFTAG_PAGENAME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PageName", NULL }, + { TIFFTAG_XPOSITION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_POSITION, 1, 0, "XPosition", NULL }, + { TIFFTAG_YPOSITION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_POSITION, 1, 0, "YPosition", NULL }, + { TIFFTAG_FREEOFFSETS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 0, 0, "FreeOffsets", NULL }, + { TIFFTAG_FREEBYTECOUNTS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 0, 0, "FreeByteCounts", NULL }, + { TIFFTAG_GRAYRESPONSEUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "GrayResponseUnit", NULL }, + { TIFFTAG_GRAYRESPONSECURVE, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "GrayResponseCurve", NULL }, + { TIFFTAG_RESOLUTIONUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTIONUNIT, 1, 0, "ResolutionUnit", NULL }, + { TIFFTAG_PAGENUMBER, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_PAGENUMBER, 1, 0, "PageNumber", NULL }, + { TIFFTAG_COLORRESPONSEUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "ColorResponseUnit", NULL }, + { TIFFTAG_TRANSFERFUNCTION, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_OTHER, TIFF_SETGET_UNDEFINED, FIELD_TRANSFERFUNCTION, 1, 0, "TransferFunction", NULL }, + { TIFFTAG_SOFTWARE, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Software", NULL }, + { TIFFTAG_DATETIME, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTime", NULL }, + { TIFFTAG_ARTIST, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Artist", NULL }, + { TIFFTAG_HOSTCOMPUTER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "HostComputer", NULL }, + { TIFFTAG_WHITEPOINT, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "WhitePoint", NULL }, + { TIFFTAG_PRIMARYCHROMATICITIES, 6, 6, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PrimaryChromaticities", NULL }, + { TIFFTAG_COLORMAP, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_OTHER, TIFF_SETGET_UNDEFINED, FIELD_COLORMAP, 1, 0, "ColorMap", NULL }, + { TIFFTAG_HALFTONEHINTS, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_HALFTONEHINTS, 1, 0, "HalftoneHints", NULL }, + { TIFFTAG_TILEWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_TILEDIMENSIONS, 0, 0, "TileWidth", NULL }, + { TIFFTAG_TILELENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_TILEDIMENSIONS, 0, 0, "TileLength", NULL }, + { TIFFTAG_TILEOFFSETS, -1, 1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPOFFSETS, 0, 0, "TileOffsets", NULL }, + { TIFFTAG_TILEBYTECOUNTS, -1, 1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPBYTECOUNTS, 0, 0, "TileByteCounts", NULL }, + { TIFFTAG_SUBIFD, -1, -1, TIFF_IFD8, 0, TIFF_SETGET_C16_IFD8, TIFF_SETGET_UNDEFINED, FIELD_SUBIFD, 1, 1, "SubIFD", &tiffFieldArray }, + { TIFFTAG_INKSET, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "InkSet", NULL }, + { TIFFTAG_INKNAMES, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_C16_ASCII, TIFF_SETGET_UNDEFINED, FIELD_INKNAMES, 1, 1, "InkNames", NULL }, + { TIFFTAG_NUMBEROFINKS, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "NumberOfInks", NULL }, + { TIFFTAG_DOTRANGE, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DotRange", NULL }, + { TIFFTAG_TARGETPRINTER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TargetPrinter", NULL }, + { TIFFTAG_EXTRASAMPLES, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_EXTRASAMPLES, 0, 1, "ExtraSamples", NULL }, + { TIFFTAG_SAMPLEFORMAT, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_SAMPLEFORMAT, 0, 0, "SampleFormat", NULL }, + { TIFFTAG_SMINSAMPLEVALUE, -2, -1, TIFF_ANY, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_SMINSAMPLEVALUE, 1, 0, "SMinSampleValue", NULL }, + { TIFFTAG_SMAXSAMPLEVALUE, -2, -1, TIFF_ANY, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_SMAXSAMPLEVALUE, 1, 0, "SMaxSampleValue", NULL }, + { TIFFTAG_CLIPPATH, -1, -3, TIFF_BYTE, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ClipPath", NULL }, + { TIFFTAG_XCLIPPATHUNITS, 1, 1, TIFF_SLONG, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "XClipPathUnits", NULL }, + { TIFFTAG_XCLIPPATHUNITS, 1, 1, TIFF_SBYTE, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "XClipPathUnits", NULL }, + { TIFFTAG_YCLIPPATHUNITS, 1, 1, TIFF_SLONG, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "YClipPathUnits", NULL }, + { TIFFTAG_YCBCRCOEFFICIENTS, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "YCbCrCoefficients", NULL }, + { TIFFTAG_YCBCRSUBSAMPLING, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_YCBCRSUBSAMPLING, 0, 0, "YCbCrSubsampling", NULL }, + { TIFFTAG_YCBCRPOSITIONING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_YCBCRPOSITIONING, 0, 0, "YCbCrPositioning", NULL }, + { TIFFTAG_REFERENCEBLACKWHITE, 6, 6, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_REFBLACKWHITE, 1, 0, "ReferenceBlackWhite", NULL }, + { TIFFTAG_XMLPACKET, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "XMLPacket", NULL }, + /* begin SGI tags */ + { TIFFTAG_MATTEING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_EXTRASAMPLES, 0, 0, "Matteing", NULL }, + { TIFFTAG_DATATYPE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_SAMPLEFORMAT, 0, 0, "DataType", NULL }, + { TIFFTAG_IMAGEDEPTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_IMAGEDEPTH, 0, 0, "ImageDepth", NULL }, + { TIFFTAG_TILEDEPTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_TILEDEPTH, 0, 0, "TileDepth", NULL }, + /* end SGI tags */ + /* begin Pixar tags */ + { TIFFTAG_PIXAR_IMAGEFULLWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageFullWidth", NULL }, + { TIFFTAG_PIXAR_IMAGEFULLLENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageFullLength", NULL }, + { TIFFTAG_PIXAR_TEXTUREFORMAT, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TextureFormat", NULL }, + { TIFFTAG_PIXAR_WRAPMODES, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TextureWrapModes", NULL }, + { TIFFTAG_PIXAR_FOVCOT, 1, 1, TIFF_FLOAT, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FieldOfViewCotangent", NULL }, + { TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN, 16, 16, TIFF_FLOAT, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MatrixWorldToScreen", NULL }, + { TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA, 16, 16, TIFF_FLOAT, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MatrixWorldToCamera", NULL }, + { TIFFTAG_COPYRIGHT, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Copyright", NULL }, + /* end Pixar tags */ + { TIFFTAG_RICHTIFFIPTC, -3, -3, TIFF_LONG, 0, TIFF_SETGET_C32_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "RichTIFFIPTC", NULL }, + { TIFFTAG_PHOTOSHOP, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Photoshop", NULL }, + { TIFFTAG_EXIFIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "EXIFIFDOffset", &exifFieldArray }, + { TIFFTAG_ICCPROFILE, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ICC Profile", NULL }, + { TIFFTAG_GPSIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "GPSIFDOffset", NULL }, + { TIFFTAG_FAXRECVPARAMS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvParams", NULL }, + { TIFFTAG_FAXSUBADDRESS, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_ASCII, FIELD_CUSTOM, TRUE, FALSE, "FaxSubAddress", NULL }, + { TIFFTAG_FAXRECVTIME, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvTime", NULL }, + { TIFFTAG_FAXDCS, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_ASCII, FIELD_CUSTOM, TRUE, FALSE, "FaxDcs", NULL }, + { TIFFTAG_STONITS, 1, 1, TIFF_DOUBLE, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "StoNits", NULL }, + { TIFFTAG_INTEROPERABILITYIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "InteroperabilityIFDOffset", NULL }, + /* begin DNG tags */ + { TIFFTAG_DNGVERSION, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DNGVersion", NULL }, + { TIFFTAG_DNGBACKWARDVERSION, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DNGBackwardVersion", NULL }, + { TIFFTAG_UNIQUECAMERAMODEL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "UniqueCameraModel", NULL }, + { TIFFTAG_LOCALIZEDCAMERAMODEL, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "LocalizedCameraModel", NULL }, + { TIFFTAG_CFAPLANECOLOR, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CFAPlaneColor", NULL }, + { TIFFTAG_CFALAYOUT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CFALayout", NULL }, + { TIFFTAG_LINEARIZATIONTABLE, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "LinearizationTable", NULL }, + { TIFFTAG_BLACKLEVELREPEATDIM, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BlackLevelRepeatDim", NULL }, + { TIFFTAG_BLACKLEVEL, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevel", NULL }, + { TIFFTAG_BLACKLEVELDELTAH, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevelDeltaH", NULL }, + { TIFFTAG_BLACKLEVELDELTAV, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevelDeltaV", NULL }, + { TIFFTAG_WHITELEVEL, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "WhiteLevel", NULL }, + { TIFFTAG_DEFAULTSCALE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultScale", NULL }, + { TIFFTAG_BESTQUALITYSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BestQualityScale", NULL }, + { TIFFTAG_DEFAULTCROPORIGIN, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultCropOrigin", NULL }, + { TIFFTAG_DEFAULTCROPSIZE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultCropSize", NULL }, + { TIFFTAG_COLORMATRIX1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ColorMatrix1", NULL }, + { TIFFTAG_COLORMATRIX2, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ColorMatrix2", NULL }, + { TIFFTAG_CAMERACALIBRATION1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CameraCalibration1", NULL }, + { TIFFTAG_CAMERACALIBRATION2, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CameraCalibration2", NULL }, + { TIFFTAG_REDUCTIONMATRIX1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ReductionMatrix1", NULL }, + { TIFFTAG_REDUCTIONMATRIX2, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ReductionMatrix2", NULL }, + { TIFFTAG_ANALOGBALANCE, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AnalogBalance", NULL }, + { TIFFTAG_ASSHOTNEUTRAL, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotNeutral", NULL }, + { TIFFTAG_ASSHOTWHITEXY, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "AsShotWhiteXY", NULL }, + { TIFFTAG_BASELINEEXPOSURE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineExposure", NULL }, + { TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineNoise", NULL }, + { TIFFTAG_BASELINESHARPNESS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineSharpness", NULL }, + { TIFFTAG_BAYERGREENSPLIT, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BayerGreenSplit", NULL }, + { TIFFTAG_LINEARRESPONSELIMIT, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "LinearResponseLimit", NULL }, + { TIFFTAG_CAMERASERIALNUMBER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CameraSerialNumber", NULL }, + { TIFFTAG_LENSINFO, 4, 4, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "LensInfo", NULL }, + { TIFFTAG_CHROMABLURRADIUS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ChromaBlurRadius", NULL }, + { TIFFTAG_ANTIALIASSTRENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "AntiAliasStrength", NULL }, + { TIFFTAG_SHADOWSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ShadowScale", NULL }, + { TIFFTAG_DNGPRIVATEDATA, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "DNGPrivateData", NULL }, + { TIFFTAG_MAKERNOTESAFETY, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "MakerNoteSafety", NULL }, + { TIFFTAG_CALIBRATIONILLUMINANT1, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CalibrationIlluminant1", NULL }, + { TIFFTAG_CALIBRATIONILLUMINANT2, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CalibrationIlluminant2", NULL }, + { TIFFTAG_RAWDATAUNIQUEID, 16, 16, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "RawDataUniqueID", NULL }, + { TIFFTAG_ORIGINALRAWFILENAME, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "OriginalRawFileName", NULL }, + { TIFFTAG_ORIGINALRAWFILEDATA, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "OriginalRawFileData", NULL }, + { TIFFTAG_ACTIVEAREA, 4, 4, TIFF_LONG, 0, TIFF_SETGET_C0_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ActiveArea", NULL }, + { TIFFTAG_MASKEDAREAS, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "MaskedAreas", NULL }, + { TIFFTAG_ASSHOTICCPROFILE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotICCProfile", NULL }, + { TIFFTAG_ASSHOTPREPROFILEMATRIX, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotPreProfileMatrix", NULL }, + { TIFFTAG_CURRENTICCPROFILE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CurrentICCProfile", NULL }, + { TIFFTAG_CURRENTPREPROFILEMATRIX, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CurrentPreProfileMatrix", NULL }, + { TIFFTAG_PERSAMPLE, 0, 0, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "PerSample", NULL}, + /* end DNG tags */ + /* begin TIFF/FX tags */ + { TIFFTAG_INDEXED, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Indexed" }, + { TIFFTAG_GLOBALPARAMETERSIFD, 1, 1, TIFF_IFD, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "GlobalParametersIFD", NULL }, + { TIFFTAG_PROFILETYPE, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ProfileType", NULL }, + { TIFFTAG_FAXPROFILE, 1, 1, TIFF_BYTE, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "FaxProfile", NULL }, + { TIFFTAG_CODINGMETHODS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CodingMethods", NULL }, + { TIFFTAG_VERSIONYEAR, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "VersionYear", NULL }, + { TIFFTAG_MODENUMBER, 1, 1, TIFF_BYTE, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ModeNumber", NULL }, + { TIFFTAG_DECODE, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Decode", NULL }, + { TIFFTAG_IMAGEBASECOLOR, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ImageBaseColor", NULL }, + { TIFFTAG_T82OPTIONS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "T82Options", NULL }, + { TIFFTAG_STRIPROWCOUNTS, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "StripRowCounts", NULL }, + { TIFFTAG_IMAGELAYER, 2, 2, TIFF_LONG, 0, TIFF_SETGET_C0_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ImageLayer", NULL }, + /* end DNG tags */ + /* begin pseudo tags */ +}; + +static TIFFField +exifFields[] = { + { EXIFTAG_EXPOSURETIME, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureTime", NULL }, + { EXIFTAG_FNUMBER, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FNumber", NULL }, + { EXIFTAG_EXPOSUREPROGRAM, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureProgram", NULL }, + { EXIFTAG_SPECTRALSENSITIVITY, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SpectralSensitivity", NULL }, + { EXIFTAG_ISOSPEEDRATINGS, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "ISOSpeedRatings", NULL }, + { EXIFTAG_OECF, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "OptoelectricConversionFactor", NULL }, + { EXIFTAG_EXIFVERSION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExifVersion", NULL }, + { EXIFTAG_DATETIMEORIGINAL, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTimeOriginal", NULL }, + { EXIFTAG_DATETIMEDIGITIZED, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTimeDigitized", NULL }, + { EXIFTAG_COMPONENTSCONFIGURATION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ComponentsConfiguration", NULL }, + { EXIFTAG_COMPRESSEDBITSPERPIXEL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CompressedBitsPerPixel", NULL }, + { EXIFTAG_SHUTTERSPEEDVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ShutterSpeedValue", NULL }, + { EXIFTAG_APERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ApertureValue", NULL }, + { EXIFTAG_BRIGHTNESSVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "BrightnessValue", NULL }, + { EXIFTAG_EXPOSUREBIASVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureBiasValue", NULL }, + { EXIFTAG_MAXAPERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MaxApertureValue", NULL }, + { EXIFTAG_SUBJECTDISTANCE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistance", NULL }, + { EXIFTAG_METERINGMODE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MeteringMode", NULL }, + { EXIFTAG_LIGHTSOURCE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LightSource", NULL }, + { EXIFTAG_FLASH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Flash", NULL }, + { EXIFTAG_FOCALLENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalLength", NULL }, + { EXIFTAG_SUBJECTAREA, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "SubjectArea", NULL }, + { EXIFTAG_MAKERNOTE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "MakerNote", NULL }, + { EXIFTAG_USERCOMMENT, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "UserComment", NULL }, + { EXIFTAG_SUBSECTIME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTime", NULL }, + { EXIFTAG_SUBSECTIMEORIGINAL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTimeOriginal", NULL }, + { EXIFTAG_SUBSECTIMEDIGITIZED, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTimeDigitized", NULL }, + { EXIFTAG_FLASHPIXVERSION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FlashpixVersion", NULL }, + { EXIFTAG_COLORSPACE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ColorSpace", NULL }, + { EXIFTAG_PIXELXDIMENSION, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PixelXDimension", NULL }, + { EXIFTAG_PIXELYDIMENSION, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PixelYDimension", NULL }, + { EXIFTAG_RELATEDSOUNDFILE, 13, 13, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "RelatedSoundFile", NULL }, + { EXIFTAG_FLASHENERGY, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FlashEnergy", NULL }, + { EXIFTAG_SPATIALFREQUENCYRESPONSE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "SpatialFrequencyResponse", NULL }, + { EXIFTAG_FOCALPLANEXRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneXResolution", NULL }, + { EXIFTAG_FOCALPLANEYRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneYResolution", NULL }, + { EXIFTAG_FOCALPLANERESOLUTIONUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneResolutionUnit", NULL }, + { EXIFTAG_SUBJECTLOCATION, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectLocation", NULL }, + { EXIFTAG_EXPOSUREINDEX, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureIndex", NULL }, + { EXIFTAG_SENSINGMETHOD, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SensingMethod", NULL }, + { EXIFTAG_FILESOURCE, 1, 1, TIFF_UNDEFINED, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FileSource", NULL }, + { EXIFTAG_SCENETYPE, 1, 1, TIFF_UNDEFINED, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SceneType", NULL }, + { EXIFTAG_CFAPATTERN, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "CFAPattern", NULL }, + { EXIFTAG_CUSTOMRENDERED, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CustomRendered", NULL }, + { EXIFTAG_EXPOSUREMODE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureMode", NULL }, + { EXIFTAG_WHITEBALANCE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "WhiteBalance", NULL }, + { EXIFTAG_DIGITALZOOMRATIO, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DigitalZoomRatio", NULL }, + { EXIFTAG_FOCALLENGTHIN35MMFILM, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalLengthIn35mmFilm", NULL }, + { EXIFTAG_SCENECAPTURETYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SceneCaptureType", NULL }, + { EXIFTAG_GAINCONTROL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "GainControl", NULL }, + { EXIFTAG_CONTRAST, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Contrast", NULL }, + { EXIFTAG_SATURATION, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Saturation", NULL }, + { EXIFTAG_SHARPNESS, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Sharpness", NULL }, + { EXIFTAG_DEVICESETTINGDESCRIPTION, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "DeviceSettingDescription", NULL }, + { EXIFTAG_SUBJECTDISTANCERANGE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistanceRange", NULL }, + { EXIFTAG_IMAGEUNIQUEID, 33, 33, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageUniqueID", NULL } +}; + +static TIFFFieldArray +tiffFieldArray = { tfiatImage, 0, TIFFArrayCount(tiffFields), tiffFields }; +static TIFFFieldArray +exifFieldArray = { tfiatExif, 0, TIFFArrayCount(exifFields), exifFields }; + +/* + * We have our own local lfind() equivelent to avoid subtle differences + * in types passed to lfind() on different systems. + */ + +static void * +td_lfind(const void *key, const void *base, size_t *nmemb, size_t size, + int(*compar)(const void *, const void *)) +{ + char *element, *end; + + end = (char *)base + *nmemb * size; + for (element = (char *)base; element < end; element += size) + if (!compar(key, element)) /* key found */ + return element; + + return NULL; +} + +const TIFFFieldArray* +_TIFFGetFields(void) +{ + return(&tiffFieldArray); +} + +const TIFFFieldArray* +_TIFFGetExifFields(void) +{ + return(&exifFieldArray); +} + +void +_TIFFSetupFields(TIFF* tif, const TIFFFieldArray* fieldarray) +{ + if (tif->tif_fields && tif->tif_nfields > 0) { + uint32 i; + + for (i = 0; i < tif->tif_nfields; i++) { + TIFFField *fld = tif->tif_fields[i]; + if (fld->field_bit == FIELD_CUSTOM && + strncmp("Tag ", fld->field_name, 4) == 0) { + _TIFFfree(fld->field_name); + _TIFFfree(fld); + } + } + + _TIFFfree(tif->tif_fields); + tif->tif_fields = NULL; + tif->tif_nfields = 0; + } + if (!_TIFFMergeFields(tif, fieldarray->fields, fieldarray->count)) { + TIFFErrorExt(tif->tif_clientdata, "_TIFFSetupFields", + "Setting up field info failed"); + } +} + +static int +tagCompare(const void* a, const void* b) +{ + const TIFFField* ta = *(const TIFFField**) a; + const TIFFField* tb = *(const TIFFField**) b; + /* NB: be careful of return values for 16-bit platforms */ + if (ta->field_tag != tb->field_tag) + return (int)ta->field_tag - (int)tb->field_tag; + else + return (ta->field_type == TIFF_ANY) ? + 0 : ((int)tb->field_type - (int)ta->field_type); +} + +static int +tagNameCompare(const void* a, const void* b) +{ + const TIFFField* ta = *(const TIFFField**) a; + const TIFFField* tb = *(const TIFFField**) b; + int ret = strcmp(ta->field_name, tb->field_name); + + if (ret) + return ret; + else + return (ta->field_type == TIFF_ANY) ? + 0 : ((int)tb->field_type - (int)ta->field_type); +} + +int +_TIFFMergeFields(TIFF* tif, const TIFFField info[], uint32 n) +{ + static const char module[] = "_TIFFMergeFields"; + static const char reason[] = "for fields array"; + /* TIFFField** tp; */ + uint32 i; + + tif->tif_foundfield = NULL; + + if (tif->tif_fields && tif->tif_nfields > 0) { + tif->tif_fields = (TIFFField**) + _TIFFCheckRealloc(tif, tif->tif_fields, + (tif->tif_nfields + n), + sizeof(TIFFField *), reason); + } else { + tif->tif_fields = (TIFFField **) + _TIFFCheckMalloc(tif, n, sizeof(TIFFField *), + reason); + } + if (!tif->tif_fields) { + TIFFErrorExt(tif->tif_clientdata, module, + "Failed to allocate fields array"); + return 0; + } + + /* tp = tif->tif_fields + tif->tif_nfields; */ + for (i = 0; i < n; i++) { + const TIFFField *fip = + TIFFFindField(tif, info[i].field_tag, TIFF_ANY); + + /* only add definitions that aren't already present */ + if (!fip) { + tif->tif_fields[tif->tif_nfields] = (TIFFField *) (info+i); + tif->tif_nfields++; + } + } + + /* Sort the field info by tag number */ + qsort(tif->tif_fields, tif->tif_nfields, + sizeof(TIFFField *), tagCompare); + + return n; +} + +void +_TIFFPrintFieldInfo(TIFF* tif, FILE* fd) +{ + uint32 i; + + fprintf(fd, "%s: \n", tif->tif_name); + for (i = 0; i < tif->tif_nfields; i++) { + const TIFFField* fip = tif->tif_fields[i]; + fprintf(fd, "field[%2d] %5lu, %2d, %2d, %d, %2d, %5s, %5s, %s\n" + , (int)i + , (unsigned long) fip->field_tag + , fip->field_readcount, fip->field_writecount + , fip->field_type + , fip->field_bit + , fip->field_oktochange ? "TRUE" : "FALSE" + , fip->field_passcount ? "TRUE" : "FALSE" + , fip->field_name + ); + } +} + +/* + * Return size of TIFFDataType in bytes + */ +int +TIFFDataWidth(TIFFDataType type) +{ + switch(type) + { + case 0: /* nothing */ + case TIFF_BYTE: + case TIFF_ASCII: + case TIFF_SBYTE: + case TIFF_UNDEFINED: + return 1; + case TIFF_SHORT: + case TIFF_SSHORT: + return 2; + case TIFF_LONG: + case TIFF_SLONG: + case TIFF_FLOAT: + case TIFF_IFD: + return 4; + case TIFF_RATIONAL: + case TIFF_SRATIONAL: + case TIFF_DOUBLE: + case TIFF_LONG8: + case TIFF_SLONG8: + case TIFF_IFD8: + return 8; + default: + return 0; /* will return 0 for unknown types */ + } +} + +/* + * Return size of TIFFDataType in bytes. + * + * XXX: We need a separate function to determine the space needed + * to store the value. For TIFF_RATIONAL values TIFFDataWidth() returns 8, + * but we use 4-byte float to represent rationals. + */ +int +_TIFFDataSize(TIFFDataType type) +{ + switch (type) + { + case TIFF_BYTE: + case TIFF_SBYTE: + case TIFF_ASCII: + case TIFF_UNDEFINED: + return 1; + case TIFF_SHORT: + case TIFF_SSHORT: + return 2; + case TIFF_LONG: + case TIFF_SLONG: + case TIFF_FLOAT: + case TIFF_IFD: + case TIFF_RATIONAL: + case TIFF_SRATIONAL: + return 4; + case TIFF_DOUBLE: + case TIFF_LONG8: + case TIFF_SLONG8: + case TIFF_IFD8: + return 8; + default: + return 0; + } +} + +const TIFFField* +TIFFFindField(TIFF* tif, uint32 tag, TIFFDataType dt) +{ + TIFFField key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0, 0, 0, NULL, NULL}; + TIFFField* pkey = &key; + const TIFFField **ret; + if (tif->tif_foundfield && tif->tif_foundfield->field_tag == tag && + (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type)) + return tif->tif_foundfield; + + /* If we are invoked with no field information, then just return. */ + if (!tif->tif_fields) + return NULL; + + /* NB: use sorted search (e.g. binary search) */ + + key.field_tag = tag; + key.field_type = dt; + + ret = (const TIFFField **) bsearch(&pkey, tif->tif_fields, + tif->tif_nfields, + sizeof(TIFFField *), tagCompare); + return tif->tif_foundfield = (ret ? *ret : NULL); +} + +const TIFFField* +_TIFFFindFieldByName(TIFF* tif, const char *field_name, TIFFDataType dt) +{ + TIFFField key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0, 0, 0, NULL, NULL}; + TIFFField* pkey = &key; + const TIFFField **ret; + if (tif->tif_foundfield + && streq(tif->tif_foundfield->field_name, field_name) + && (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type)) + return (tif->tif_foundfield); + + /* If we are invoked with no field information, then just return. */ + if (!tif->tif_fields) + return NULL; + + /* NB: use linear search since list is sorted by key#, not name */ + + key.field_name = (char *)field_name; + key.field_type = dt; + + ret = (const TIFFField **) + td_lfind(&pkey, tif->tif_fields, &tif->tif_nfields, + sizeof(TIFFField *), tagNameCompare); + + return tif->tif_foundfield = (ret ? *ret : NULL); +} + +const TIFFField* +TIFFFieldWithTag(TIFF* tif, uint32 tag) +{ + const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY); + if (!fip) { + TIFFErrorExt(tif->tif_clientdata, "TIFFFieldWithTag", + "Internal error, unknown tag 0x%x", + (unsigned int) tag); + } + return (fip); +} + +const TIFFField* +TIFFFieldWithName(TIFF* tif, const char *field_name) +{ + const TIFFField* fip = + _TIFFFindFieldByName(tif, field_name, TIFF_ANY); + if (!fip) { + TIFFErrorExt(tif->tif_clientdata, "TIFFFieldWithName", + "Internal error, unknown tag %s", field_name); + } + return (fip); +} + +uint32 +TIFFFieldTag(const TIFFField* fip) +{ + return fip->field_tag; +} + +const char * +TIFFFieldName(const TIFFField* fip) +{ + return fip->field_name; +} + +TIFFDataType +TIFFFieldDataType(const TIFFField* fip) +{ + return fip->field_type; +} + +int +TIFFFieldPassCount(const TIFFField* fip) +{ + return fip->field_passcount; +} + +int +TIFFFieldReadCount(const TIFFField* fip) +{ + return fip->field_readcount; +} + +int +TIFFFieldWriteCount(const TIFFField* fip) +{ + return fip->field_writecount; +} + +const TIFFField* +_TIFFFindOrRegisterField(TIFF *tif, uint32 tag, TIFFDataType dt) + +{ + const TIFFField *fld; + + fld = TIFFFindField(tif, tag, dt); + if (fld == NULL) { + fld = _TIFFCreateAnonField(tif, tag, dt); + if (!_TIFFMergeFields(tif, fld, 1)) + return NULL; + } + + return fld; +} + +TIFFField* +_TIFFCreateAnonField(TIFF *tif, uint32 tag, TIFFDataType field_type) +{ + TIFFField *fld; + (void) tif; + + fld = (TIFFField *) _TIFFmalloc(sizeof (TIFFField)); + if (fld == NULL) + return NULL; + _TIFFmemset(fld, 0, sizeof(TIFFField)); + + fld->field_tag = tag; + fld->field_readcount = TIFF_VARIABLE2; + fld->field_writecount = TIFF_VARIABLE2; + fld->field_type = field_type; + fld->reserved = 0; + switch (field_type) + { + case TIFF_BYTE: + case TIFF_UNDEFINED: + fld->set_field_type = TIFF_SETGET_C32_UINT8; + fld->get_field_type = TIFF_SETGET_C32_UINT8; + break; + case TIFF_ASCII: + fld->set_field_type = TIFF_SETGET_C32_ASCII; + fld->get_field_type = TIFF_SETGET_C32_ASCII; + break; + case TIFF_SHORT: + fld->set_field_type = TIFF_SETGET_C32_UINT16; + fld->get_field_type = TIFF_SETGET_C32_UINT16; + break; + case TIFF_LONG: + fld->set_field_type = TIFF_SETGET_C32_UINT32; + fld->get_field_type = TIFF_SETGET_C32_UINT32; + break; + case TIFF_RATIONAL: + case TIFF_SRATIONAL: + case TIFF_FLOAT: + fld->set_field_type = TIFF_SETGET_C32_FLOAT; + fld->get_field_type = TIFF_SETGET_C32_FLOAT; + break; + case TIFF_SBYTE: + fld->set_field_type = TIFF_SETGET_C32_SINT8; + fld->get_field_type = TIFF_SETGET_C32_SINT8; + break; + case TIFF_SSHORT: + fld->set_field_type = TIFF_SETGET_C32_SINT16; + fld->get_field_type = TIFF_SETGET_C32_SINT16; + break; + case TIFF_SLONG: + fld->set_field_type = TIFF_SETGET_C32_SINT32; + fld->get_field_type = TIFF_SETGET_C32_SINT32; + break; + case TIFF_DOUBLE: + fld->set_field_type = TIFF_SETGET_C32_DOUBLE; + fld->get_field_type = TIFF_SETGET_C32_DOUBLE; + break; + case TIFF_IFD: + case TIFF_IFD8: + fld->set_field_type = TIFF_SETGET_C32_IFD8; + fld->get_field_type = TIFF_SETGET_C32_IFD8; + break; + case TIFF_LONG8: + fld->set_field_type = TIFF_SETGET_C32_UINT64; + fld->get_field_type = TIFF_SETGET_C32_UINT64; + break; + case TIFF_SLONG8: + fld->set_field_type = TIFF_SETGET_C32_SINT64; + fld->get_field_type = TIFF_SETGET_C32_SINT64; + break; + default: + fld->set_field_type = TIFF_SETGET_UNDEFINED; + fld->get_field_type = TIFF_SETGET_UNDEFINED; + break; + } + fld->field_bit = FIELD_CUSTOM; + fld->field_oktochange = TRUE; + fld->field_passcount = TRUE; + fld->field_name = (char *) _TIFFmalloc(32); + if (fld->field_name == NULL) { + _TIFFfree(fld); + return NULL; + } + fld->field_subfields = NULL; + + /* + * note that this name is a special sign to TIFFClose() and + * _TIFFSetupFields() to free the field + */ + sprintf(fld->field_name, "Tag %d", (int) tag); + + return fld; +} + +/**************************************************************************** + * O B S O L E T E D I N T E R F A C E S + * + * Don't use this stuff in your applications, it may be removed in the future + * libtiff versions. + ****************************************************************************/ + +static TIFFSetGetFieldType +_TIFFSetGetType(TIFFDataType type, short count, unsigned char passcount) +{ + if (type == TIFF_ASCII && count == TIFF_VARIABLE && passcount == 0) + return TIFF_SETGET_ASCII; + + else if (count == 1 && passcount == 0) { + switch (type) + { + case TIFF_BYTE: + case TIFF_UNDEFINED: + return TIFF_SETGET_UINT8; + case TIFF_ASCII: + return TIFF_SETGET_ASCII; + case TIFF_SHORT: + return TIFF_SETGET_UINT16; + case TIFF_LONG: + return TIFF_SETGET_UINT32; + case TIFF_RATIONAL: + case TIFF_SRATIONAL: + case TIFF_FLOAT: + return TIFF_SETGET_FLOAT; + case TIFF_SBYTE: + return TIFF_SETGET_SINT8; + case TIFF_SSHORT: + return TIFF_SETGET_SINT16; + case TIFF_SLONG: + return TIFF_SETGET_SINT32; + case TIFF_DOUBLE: + return TIFF_SETGET_DOUBLE; + case TIFF_IFD: + case TIFF_IFD8: + return TIFF_SETGET_IFD8; + case TIFF_LONG8: + return TIFF_SETGET_UINT64; + case TIFF_SLONG8: + return TIFF_SETGET_SINT64; + default: + return TIFF_SETGET_UNDEFINED; + } + } + + else if (count >= 1 && passcount == 0) { + switch (type) + { + case TIFF_BYTE: + case TIFF_UNDEFINED: + return TIFF_SETGET_C0_UINT8; + case TIFF_ASCII: + return TIFF_SETGET_C0_ASCII; + case TIFF_SHORT: + return TIFF_SETGET_C0_UINT16; + case TIFF_LONG: + return TIFF_SETGET_C0_UINT32; + case TIFF_RATIONAL: + case TIFF_SRATIONAL: + case TIFF_FLOAT: + return TIFF_SETGET_C0_FLOAT; + case TIFF_SBYTE: + return TIFF_SETGET_C0_SINT8; + case TIFF_SSHORT: + return TIFF_SETGET_C0_SINT16; + case TIFF_SLONG: + return TIFF_SETGET_C0_SINT32; + case TIFF_DOUBLE: + return TIFF_SETGET_C0_DOUBLE; + case TIFF_IFD: + case TIFF_IFD8: + return TIFF_SETGET_C0_IFD8; + case TIFF_LONG8: + return TIFF_SETGET_C0_UINT64; + case TIFF_SLONG8: + return TIFF_SETGET_C0_SINT64; + default: + return TIFF_SETGET_UNDEFINED; + } + } + + else if (count == TIFF_VARIABLE && passcount == 1) { + switch (type) + { + case TIFF_BYTE: + case TIFF_UNDEFINED: + return TIFF_SETGET_C16_UINT8; + case TIFF_ASCII: + return TIFF_SETGET_C16_ASCII; + case TIFF_SHORT: + return TIFF_SETGET_C16_UINT16; + case TIFF_LONG: + return TIFF_SETGET_C16_UINT32; + case TIFF_RATIONAL: + case TIFF_SRATIONAL: + case TIFF_FLOAT: + return TIFF_SETGET_C16_FLOAT; + case TIFF_SBYTE: + return TIFF_SETGET_C16_SINT8; + case TIFF_SSHORT: + return TIFF_SETGET_C16_SINT16; + case TIFF_SLONG: + return TIFF_SETGET_C16_SINT32; + case TIFF_DOUBLE: + return TIFF_SETGET_C16_DOUBLE; + case TIFF_IFD: + case TIFF_IFD8: + return TIFF_SETGET_C16_IFD8; + case TIFF_LONG8: + return TIFF_SETGET_C16_UINT64; + case TIFF_SLONG8: + return TIFF_SETGET_C16_SINT64; + default: + return TIFF_SETGET_UNDEFINED; + } + } + + else if (count == TIFF_VARIABLE2 && passcount == 1) { + switch (type) + { + case TIFF_BYTE: + case TIFF_UNDEFINED: + return TIFF_SETGET_C32_UINT8; + case TIFF_ASCII: + return TIFF_SETGET_C32_ASCII; + case TIFF_SHORT: + return TIFF_SETGET_C32_UINT16; + case TIFF_LONG: + return TIFF_SETGET_C32_UINT32; + case TIFF_RATIONAL: + case TIFF_SRATIONAL: + case TIFF_FLOAT: + return TIFF_SETGET_C32_FLOAT; + case TIFF_SBYTE: + return TIFF_SETGET_C32_SINT8; + case TIFF_SSHORT: + return TIFF_SETGET_C32_SINT16; + case TIFF_SLONG: + return TIFF_SETGET_C32_SINT32; + case TIFF_DOUBLE: + return TIFF_SETGET_C32_DOUBLE; + case TIFF_IFD: + case TIFF_IFD8: + return TIFF_SETGET_C32_IFD8; + case TIFF_LONG8: + return TIFF_SETGET_C32_UINT64; + case TIFF_SLONG8: + return TIFF_SETGET_C32_SINT64; + default: + return TIFF_SETGET_UNDEFINED; + } + } + + return TIFF_SETGET_UNDEFINED; +} + +int +TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], uint32 n) +{ + static const char module[] = "TIFFMergeFieldInfo"; + static const char reason[] = "for fields array"; + TIFFField *tp; + size_t nfields; + uint32 i; + + if (tif->tif_nfieldscompat > 0) { + tif->tif_fieldscompat = (TIFFFieldArray *) + _TIFFCheckRealloc(tif, tif->tif_fieldscompat, + tif->tif_nfieldscompat + 1, + sizeof(TIFFFieldArray), reason); + } else { + tif->tif_fieldscompat = (TIFFFieldArray *) + _TIFFCheckMalloc(tif, 1, sizeof(TIFFFieldArray), + reason); + } + if (!tif->tif_fieldscompat) { + TIFFErrorExt(tif->tif_clientdata, module, + "Failed to allocate fields array"); + return -1; + } + nfields = tif->tif_nfieldscompat++; + + tif->tif_fieldscompat[nfields].type = tfiatOther; + tif->tif_fieldscompat[nfields].allocated_size = n; + tif->tif_fieldscompat[nfields].count = n; + tif->tif_fieldscompat[nfields].fields = + (TIFFField *)_TIFFCheckMalloc(tif, n, sizeof(TIFFField), + reason); + if (!tif->tif_fieldscompat[nfields].fields) { + TIFFErrorExt(tif->tif_clientdata, module, + "Failed to allocate fields array"); + return -1; + } + + tp = tif->tif_fieldscompat[nfields].fields; + for (i = 0; i < n; i++) { + tp->field_tag = info[i].field_tag; + tp->field_readcount = info[i].field_readcount; + tp->field_writecount = info[i].field_writecount; + tp->field_type = info[i].field_type; + tp->reserved = 0; + tp->set_field_type = + _TIFFSetGetType(info[i].field_type, + info[i].field_readcount, + info[i].field_passcount); + tp->get_field_type = + _TIFFSetGetType(info[i].field_type, + info[i].field_readcount, + info[i].field_passcount); + tp->field_bit = info[i].field_bit; + tp->field_oktochange = info[i].field_oktochange; + tp->field_passcount = info[i].field_passcount; + tp->field_name = info[i].field_name; + tp->field_subfields = NULL; + tp++; + } + + if (!_TIFFMergeFields(tif, tif->tif_fieldscompat[nfields].fields, n)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Setting up field info failed"); + return -1; + } + + return 0; +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ + +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_dirread.c b/Source/LibTIFF4/tif_dirread.c index 68ade70..9ed6184 100644 --- a/Source/LibTIFF4/tif_dirread.c +++ b/Source/LibTIFF4/tif_dirread.c @@ -1,5613 +1,5613 @@ -/* $Id: tif_dirread.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * - * Directory Read Support Routines. - */ - -/* Suggested pending improvements: - * - add a field 'ignore' to the TIFFDirEntry structure, to flag status, - * eliminating current use of the IGNORE value, and therefore eliminating - * current irrational behaviour on tags with tag id code 0 - * - add a field 'field_info' to the TIFFDirEntry structure, and set that with - * the pointer to the appropriate TIFFField structure early on in - * TIFFReadDirectory, so as to eliminate current possibly repetitive lookup. - */ - -#include "tiffiop.h" - -#define IGNORE 0 /* tag placeholder used below */ -#define FAILED_FII ((uint32) -1) - -#ifdef HAVE_IEEEFP -# define TIFFCvtIEEEFloatToNative(tif, n, fp) -# define TIFFCvtIEEEDoubleToNative(tif, n, dp) -#else -extern void TIFFCvtIEEEFloatToNative(TIFF*, uint32, float*); -extern void TIFFCvtIEEEDoubleToNative(TIFF*, uint32, double*); -#endif - -enum TIFFReadDirEntryErr { - TIFFReadDirEntryErrOk = 0, - TIFFReadDirEntryErrCount = 1, - TIFFReadDirEntryErrType = 2, - TIFFReadDirEntryErrIo = 3, - TIFFReadDirEntryErrRange = 4, - TIFFReadDirEntryErrPsdif = 5, - TIFFReadDirEntryErrSizesan = 6, - TIFFReadDirEntryErrAlloc = 7, -}; - -static enum TIFFReadDirEntryErr TIFFReadDirEntryByte(TIFF* tif, TIFFDirEntry* direntry, uint8* value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryShort(TIFF* tif, TIFFDirEntry* direntry, uint16* value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryLong(TIFF* tif, TIFFDirEntry* direntry, uint32* value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8(TIFF* tif, TIFFDirEntry* direntry, uint64* value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryFloat(TIFF* tif, TIFFDirEntry* direntry, float* value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryDouble(TIFF* tif, TIFFDirEntry* direntry, double* value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8(TIFF* tif, TIFFDirEntry* direntry, uint64* value); - -static enum TIFFReadDirEntryErr TIFFReadDirEntryArray(TIFF* tif, TIFFDirEntry* direntry, uint32* count, uint32 desttypesize, void** value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryByteArray(TIFF* tif, TIFFDirEntry* direntry, uint8** value); -static enum TIFFReadDirEntryErr TIFFReadDirEntrySbyteArray(TIFF* tif, TIFFDirEntry* direntry, int8** value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryShortArray(TIFF* tif, TIFFDirEntry* direntry, uint16** value); -static enum TIFFReadDirEntryErr TIFFReadDirEntrySshortArray(TIFF* tif, TIFFDirEntry* direntry, int16** value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryLongArray(TIFF* tif, TIFFDirEntry* direntry, uint32** value); -static enum TIFFReadDirEntryErr TIFFReadDirEntrySlongArray(TIFF* tif, TIFFDirEntry* direntry, int32** value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8Array(TIFF* tif, TIFFDirEntry* direntry, uint64** value); -static enum TIFFReadDirEntryErr TIFFReadDirEntrySlong8Array(TIFF* tif, TIFFDirEntry* direntry, int64** value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryFloatArray(TIFF* tif, TIFFDirEntry* direntry, float** value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryDoubleArray(TIFF* tif, TIFFDirEntry* direntry, double** value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8Array(TIFF* tif, TIFFDirEntry* direntry, uint64** value); - -static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleShort(TIFF* tif, TIFFDirEntry* direntry, uint16* value); -#if 0 -static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleDouble(TIFF* tif, TIFFDirEntry* direntry, double* value); -#endif - -static void TIFFReadDirEntryCheckedByte(TIFF* tif, TIFFDirEntry* direntry, uint8* value); -static void TIFFReadDirEntryCheckedSbyte(TIFF* tif, TIFFDirEntry* direntry, int8* value); -static void TIFFReadDirEntryCheckedShort(TIFF* tif, TIFFDirEntry* direntry, uint16* value); -static void TIFFReadDirEntryCheckedSshort(TIFF* tif, TIFFDirEntry* direntry, int16* value); -static void TIFFReadDirEntryCheckedLong(TIFF* tif, TIFFDirEntry* direntry, uint32* value); -static void TIFFReadDirEntryCheckedSlong(TIFF* tif, TIFFDirEntry* direntry, int32* value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedLong8(TIFF* tif, TIFFDirEntry* direntry, uint64* value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSlong8(TIFF* tif, TIFFDirEntry* direntry, int64* value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedRational(TIFF* tif, TIFFDirEntry* direntry, double* value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSrational(TIFF* tif, TIFFDirEntry* direntry, double* value); -static void TIFFReadDirEntryCheckedFloat(TIFF* tif, TIFFDirEntry* direntry, float* value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedDouble(TIFF* tif, TIFFDirEntry* direntry, double* value); - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSbyte(int8 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteShort(uint16 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSshort(int16 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong(uint32 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong(int32 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong8(uint64 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong8(int64 value); - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteByte(uint8 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteShort(uint16 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSshort(int16 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteLong(uint32 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSlong(int32 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteLong8(uint64 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSlong8(int64 value); - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSbyte(int8 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSshort(int16 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortLong(uint32 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSlong(int32 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortLong8(uint64 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSlong8(int64 value); - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortShort(uint16 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortLong(uint32 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortSlong(int32 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortLong8(uint64 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortSlong8(int64 value); - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSbyte(int8 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSshort(int16 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSlong(int32 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongLong8(uint64 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSlong8(int64 value); - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlongLong(uint32 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlongLong8(uint64 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlongSlong8(int64 value); - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Sbyte(int8 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Sshort(int16 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Slong(int32 value); -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Slong8(int64 value); - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlong8Long8(uint64 value); - -static enum TIFFReadDirEntryErr TIFFReadDirEntryData(TIFF* tif, uint64 offset, tmsize_t size, void* dest); -static void TIFFReadDirEntryOutputErr(TIFF* tif, enum TIFFReadDirEntryErr err, const char* module, const char* tagname, int recover); - -static void TIFFReadDirectoryCheckOrder(TIFF* tif, TIFFDirEntry* dir, uint16 dircount); -static TIFFDirEntry* TIFFReadDirectoryFindEntry(TIFF* tif, TIFFDirEntry* dir, uint16 dircount, uint16 tagid); -static void TIFFReadDirectoryFindFieldInfo(TIFF* tif, uint16 tagid, uint32* fii); - -static int EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount); -static void MissingRequired(TIFF*, const char*); -static int TIFFCheckDirOffset(TIFF* tif, uint64 diroff); -static int CheckDirCount(TIFF*, TIFFDirEntry*, uint32); -static uint16 TIFFFetchDirectory(TIFF* tif, uint64 diroff, TIFFDirEntry** pdir, uint64* nextdiroff); -static int TIFFFetchNormalTag(TIFF*, TIFFDirEntry*, int recover); -static int TIFFFetchStripThing(TIFF* tif, TIFFDirEntry* dir, uint32 nstrips, uint64** lpp); -static int TIFFFetchSubjectDistance(TIFF*, TIFFDirEntry*); -static void ChopUpSingleUncompressedStrip(TIFF*); -static uint64 TIFFReadUInt64(const uint8 *value); - -typedef union _UInt64Aligned_t -{ - double d; - uint64 l; - uint32 i[2]; - uint16 s[4]; - uint8 c[8]; -} UInt64Aligned_t; - -/* - Unaligned safe copy of a uint64 value from an octet array. -*/ -static uint64 TIFFReadUInt64(const uint8 *value) -{ - UInt64Aligned_t result; - - result.c[0]=value[0]; - result.c[1]=value[1]; - result.c[2]=value[2]; - result.c[3]=value[3]; - result.c[4]=value[4]; - result.c[5]=value[5]; - result.c[6]=value[6]; - result.c[7]=value[7]; - - return result.l; -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryByte(TIFF* tif, TIFFDirEntry* direntry, uint8* value) -{ - enum TIFFReadDirEntryErr err; - if (direntry->tdir_count!=1) - return(TIFFReadDirEntryErrCount); - switch (direntry->tdir_type) - { - case TIFF_BYTE: - TIFFReadDirEntryCheckedByte(tif,direntry,value); - return(TIFFReadDirEntryErrOk); - case TIFF_SBYTE: - { - int8 m; - TIFFReadDirEntryCheckedSbyte(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeByteSbyte(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint8)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SHORT: - { - uint16 m; - TIFFReadDirEntryCheckedShort(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeByteShort(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint8)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SSHORT: - { - int16 m; - TIFFReadDirEntryCheckedSshort(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeByteSshort(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint8)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_LONG: - { - uint32 m; - TIFFReadDirEntryCheckedLong(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeByteLong(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint8)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SLONG: - { - int32 m; - TIFFReadDirEntryCheckedSlong(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeByteSlong(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint8)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_LONG8: - { - uint64 m; - err=TIFFReadDirEntryCheckedLong8(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - err=TIFFReadDirEntryCheckRangeByteLong8(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint8)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SLONG8: - { - int64 m; - err=TIFFReadDirEntryCheckedSlong8(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - err=TIFFReadDirEntryCheckRangeByteSlong8(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint8)m; - return(TIFFReadDirEntryErrOk); - } - default: - return(TIFFReadDirEntryErrType); - } -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryShort(TIFF* tif, TIFFDirEntry* direntry, uint16* value) -{ - enum TIFFReadDirEntryErr err; - if (direntry->tdir_count!=1) - return(TIFFReadDirEntryErrCount); - switch (direntry->tdir_type) - { - case TIFF_BYTE: - { - uint8 m; - TIFFReadDirEntryCheckedByte(tif,direntry,&m); - *value=(uint16)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SBYTE: - { - int8 m; - TIFFReadDirEntryCheckedSbyte(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeShortSbyte(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint16)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SHORT: - TIFFReadDirEntryCheckedShort(tif,direntry,value); - return(TIFFReadDirEntryErrOk); - case TIFF_SSHORT: - { - int16 m; - TIFFReadDirEntryCheckedSshort(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeShortSshort(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint16)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_LONG: - { - uint32 m; - TIFFReadDirEntryCheckedLong(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeShortLong(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint16)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SLONG: - { - int32 m; - TIFFReadDirEntryCheckedSlong(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeShortSlong(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint16)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_LONG8: - { - uint64 m; - err=TIFFReadDirEntryCheckedLong8(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - err=TIFFReadDirEntryCheckRangeShortLong8(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint16)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SLONG8: - { - int64 m; - err=TIFFReadDirEntryCheckedSlong8(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - err=TIFFReadDirEntryCheckRangeShortSlong8(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint16)m; - return(TIFFReadDirEntryErrOk); - } - default: - return(TIFFReadDirEntryErrType); - } -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryLong(TIFF* tif, TIFFDirEntry* direntry, uint32* value) -{ - enum TIFFReadDirEntryErr err; - if (direntry->tdir_count!=1) - return(TIFFReadDirEntryErrCount); - switch (direntry->tdir_type) - { - case TIFF_BYTE: - { - uint8 m; - TIFFReadDirEntryCheckedByte(tif,direntry,&m); - *value=(uint32)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SBYTE: - { - int8 m; - TIFFReadDirEntryCheckedSbyte(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeLongSbyte(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint32)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SHORT: - { - uint16 m; - TIFFReadDirEntryCheckedShort(tif,direntry,&m); - *value=(uint32)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SSHORT: - { - int16 m; - TIFFReadDirEntryCheckedSshort(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeLongSshort(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint32)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_LONG: - TIFFReadDirEntryCheckedLong(tif,direntry,value); - return(TIFFReadDirEntryErrOk); - case TIFF_SLONG: - { - int32 m; - TIFFReadDirEntryCheckedSlong(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeLongSlong(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint32)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_LONG8: - { - uint64 m; - err=TIFFReadDirEntryCheckedLong8(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - err=TIFFReadDirEntryCheckRangeLongLong8(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint32)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SLONG8: - { - int64 m; - err=TIFFReadDirEntryCheckedSlong8(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - err=TIFFReadDirEntryCheckRangeLongSlong8(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint32)m; - return(TIFFReadDirEntryErrOk); - } - default: - return(TIFFReadDirEntryErrType); - } -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8(TIFF* tif, TIFFDirEntry* direntry, uint64* value) -{ - enum TIFFReadDirEntryErr err; - if (direntry->tdir_count!=1) - return(TIFFReadDirEntryErrCount); - switch (direntry->tdir_type) - { - case TIFF_BYTE: - { - uint8 m; - TIFFReadDirEntryCheckedByte(tif,direntry,&m); - *value=(uint64)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SBYTE: - { - int8 m; - TIFFReadDirEntryCheckedSbyte(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeLong8Sbyte(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint64)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SHORT: - { - uint16 m; - TIFFReadDirEntryCheckedShort(tif,direntry,&m); - *value=(uint64)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SSHORT: - { - int16 m; - TIFFReadDirEntryCheckedSshort(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeLong8Sshort(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint64)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_LONG: - { - uint32 m; - TIFFReadDirEntryCheckedLong(tif,direntry,&m); - *value=(uint64)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SLONG: - { - int32 m; - TIFFReadDirEntryCheckedSlong(tif,direntry,&m); - err=TIFFReadDirEntryCheckRangeLong8Slong(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint64)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_LONG8: - err=TIFFReadDirEntryCheckedLong8(tif,direntry,value); - return(err); - case TIFF_SLONG8: - { - int64 m; - err=TIFFReadDirEntryCheckedSlong8(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - err=TIFFReadDirEntryCheckRangeLong8Slong8(m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(uint64)m; - return(TIFFReadDirEntryErrOk); - } - default: - return(TIFFReadDirEntryErrType); - } -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryFloat(TIFF* tif, TIFFDirEntry* direntry, float* value) -{ - enum TIFFReadDirEntryErr err; - if (direntry->tdir_count!=1) - return(TIFFReadDirEntryErrCount); - switch (direntry->tdir_type) - { - case TIFF_BYTE: - { - uint8 m; - TIFFReadDirEntryCheckedByte(tif,direntry,&m); - *value=(float)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SBYTE: - { - int8 m; - TIFFReadDirEntryCheckedSbyte(tif,direntry,&m); - *value=(float)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SHORT: - { - uint16 m; - TIFFReadDirEntryCheckedShort(tif,direntry,&m); - *value=(float)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SSHORT: - { - int16 m; - TIFFReadDirEntryCheckedSshort(tif,direntry,&m); - *value=(float)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_LONG: - { - uint32 m; - TIFFReadDirEntryCheckedLong(tif,direntry,&m); - *value=(float)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SLONG: - { - int32 m; - TIFFReadDirEntryCheckedSlong(tif,direntry,&m); - *value=(float)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_LONG8: - { - uint64 m; - err=TIFFReadDirEntryCheckedLong8(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); -#if defined(__WIN32__) && (_MSC_VER < 1500) - /* - * XXX: MSVC 6.0 does not support conversion - * of 64-bit integers into floating point - * values. - */ - *value = _TIFFUInt64ToFloat(m); -#else - *value=(float)m; -#endif - return(TIFFReadDirEntryErrOk); - } - case TIFF_SLONG8: - { - int64 m; - err=TIFFReadDirEntryCheckedSlong8(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(float)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_RATIONAL: - { - double m; - err=TIFFReadDirEntryCheckedRational(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(float)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SRATIONAL: - { - double m; - err=TIFFReadDirEntryCheckedSrational(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(float)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_FLOAT: - TIFFReadDirEntryCheckedFloat(tif,direntry,value); - return(TIFFReadDirEntryErrOk); - case TIFF_DOUBLE: - { - double m; - err=TIFFReadDirEntryCheckedDouble(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(float)m; - return(TIFFReadDirEntryErrOk); - } - default: - return(TIFFReadDirEntryErrType); - } -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryDouble(TIFF* tif, TIFFDirEntry* direntry, double* value) -{ - enum TIFFReadDirEntryErr err; - if (direntry->tdir_count!=1) - return(TIFFReadDirEntryErrCount); - switch (direntry->tdir_type) - { - case TIFF_BYTE: - { - uint8 m; - TIFFReadDirEntryCheckedByte(tif,direntry,&m); - *value=(double)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SBYTE: - { - int8 m; - TIFFReadDirEntryCheckedSbyte(tif,direntry,&m); - *value=(double)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SHORT: - { - uint16 m; - TIFFReadDirEntryCheckedShort(tif,direntry,&m); - *value=(double)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SSHORT: - { - int16 m; - TIFFReadDirEntryCheckedSshort(tif,direntry,&m); - *value=(double)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_LONG: - { - uint32 m; - TIFFReadDirEntryCheckedLong(tif,direntry,&m); - *value=(double)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SLONG: - { - int32 m; - TIFFReadDirEntryCheckedSlong(tif,direntry,&m); - *value=(double)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_LONG8: - { - uint64 m; - err=TIFFReadDirEntryCheckedLong8(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); -#if defined(__WIN32__) && (_MSC_VER < 1500) - /* - * XXX: MSVC 6.0 does not support conversion - * of 64-bit integers into floating point - * values. - */ - *value = _TIFFUInt64ToDouble(m); -#else - *value = (double)m; -#endif - return(TIFFReadDirEntryErrOk); - } - case TIFF_SLONG8: - { - int64 m; - err=TIFFReadDirEntryCheckedSlong8(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - *value=(double)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_RATIONAL: - err=TIFFReadDirEntryCheckedRational(tif,direntry,value); - return(err); - case TIFF_SRATIONAL: - err=TIFFReadDirEntryCheckedSrational(tif,direntry,value); - return(err); - case TIFF_FLOAT: - { - float m; - TIFFReadDirEntryCheckedFloat(tif,direntry,&m); - *value=(double)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_DOUBLE: - err=TIFFReadDirEntryCheckedDouble(tif,direntry,value); - return(err); - default: - return(TIFFReadDirEntryErrType); - } -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8(TIFF* tif, TIFFDirEntry* direntry, uint64* value) -{ - enum TIFFReadDirEntryErr err; - if (direntry->tdir_count!=1) - return(TIFFReadDirEntryErrCount); - switch (direntry->tdir_type) - { - case TIFF_LONG: - case TIFF_IFD: - { - uint32 m; - TIFFReadDirEntryCheckedLong(tif,direntry,&m); - *value=(uint64)m; - return(TIFFReadDirEntryErrOk); - } - case TIFF_LONG8: - case TIFF_IFD8: - err=TIFFReadDirEntryCheckedLong8(tif,direntry,value); - return(err); - default: - return(TIFFReadDirEntryErrType); - } -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryArray(TIFF* tif, TIFFDirEntry* direntry, uint32* count, uint32 desttypesize, void** value) -{ - int typesize; - uint32 datasize; - void* data; - typesize=TIFFDataWidth(direntry->tdir_type); - if ((direntry->tdir_count==0)||(typesize==0)) - { - *value=0; - return(TIFFReadDirEntryErrOk); - } - (void) desttypesize; - - /* - * As a sanity check, make sure we have no more than a 2GB tag array - * in either the current data type or the dest data type. This also - * avoids problems with overflow of tmsize_t on 32bit systems. - */ - if ((uint64)(2147483647/typesize)tdir_count) - return(TIFFReadDirEntryErrSizesan); - if ((uint64)(2147483647/desttypesize)tdir_count) - return(TIFFReadDirEntryErrSizesan); - - *count=(uint32)direntry->tdir_count; - datasize=(*count)*typesize; - assert((tmsize_t)datasize>0); - data=_TIFFCheckMalloc(tif, *count, typesize, "ReadDirEntryArray"); - if (data==0) - return(TIFFReadDirEntryErrAlloc); - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - if (datasize<=4) - _TIFFmemcpy(data,&direntry->tdir_offset,datasize); - else - { - enum TIFFReadDirEntryErr err; - uint32 offset = direntry->tdir_offset.toff_long; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(&offset); - err=TIFFReadDirEntryData(tif,(uint64)offset,(tmsize_t)datasize,data); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(data); - return(err); - } - } - } - else - { - if (datasize<=8) - _TIFFmemcpy(data,&direntry->tdir_offset,datasize); - else - { - enum TIFFReadDirEntryErr err; - uint64 offset = direntry->tdir_offset.toff_long8; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8(&offset); - err=TIFFReadDirEntryData(tif,offset,(tmsize_t)datasize,data); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(data); - return(err); - } - } - } - *value=data; - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryByteArray(TIFF* tif, TIFFDirEntry* direntry, uint8** value) -{ - enum TIFFReadDirEntryErr err; - uint32 count; - void* origdata; - uint8* data; - switch (direntry->tdir_type) - { - case TIFF_ASCII: - case TIFF_UNDEFINED: - case TIFF_BYTE: - case TIFF_SBYTE: - case TIFF_SHORT: - case TIFF_SSHORT: - case TIFF_LONG: - case TIFF_SLONG: - case TIFF_LONG8: - case TIFF_SLONG8: - break; - default: - return(TIFFReadDirEntryErrType); - } - err=TIFFReadDirEntryArray(tif,direntry,&count,1,&origdata); - if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) - { - *value=0; - return(err); - } - switch (direntry->tdir_type) - { - case TIFF_ASCII: - case TIFF_UNDEFINED: - case TIFF_BYTE: - *value=(uint8*)origdata; - return(TIFFReadDirEntryErrOk); - case TIFF_SBYTE: - { - int8* m; - uint32 n; - m=(int8*)origdata; - for (n=0; ntdir_type) - { - case TIFF_SHORT: - { - uint16* ma; - uint8* mb; - uint32 n; - ma=(uint16*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort(ma); - err=TIFFReadDirEntryCheckRangeByteShort(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint8)(*ma++); - } - } - break; - case TIFF_SSHORT: - { - int16* ma; - uint8* mb; - uint32 n; - ma=(int16*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)ma); - err=TIFFReadDirEntryCheckRangeByteSshort(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint8)(*ma++); - } - } - break; - case TIFF_LONG: - { - uint32* ma; - uint8* mb; - uint32 n; - ma=(uint32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - err=TIFFReadDirEntryCheckRangeByteLong(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint8)(*ma++); - } - } - break; - case TIFF_SLONG: - { - int32* ma; - uint8* mb; - uint32 n; - ma=(int32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)ma); - err=TIFFReadDirEntryCheckRangeByteSlong(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint8)(*ma++); - } - } - break; - case TIFF_LONG8: - { - uint64* ma; - uint8* mb; - uint32 n; - ma=(uint64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8(ma); - err=TIFFReadDirEntryCheckRangeByteLong8(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint8)(*ma++); - } - } - break; - case TIFF_SLONG8: - { - int64* ma; - uint8* mb; - uint32 n; - ma=(int64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)ma); - err=TIFFReadDirEntryCheckRangeByteSlong8(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint8)(*ma++); - } - } - break; - } - _TIFFfree(origdata); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(data); - return(err); - } - *value=data; - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntrySbyteArray(TIFF* tif, TIFFDirEntry* direntry, int8** value) -{ - enum TIFFReadDirEntryErr err; - uint32 count; - void* origdata; - int8* data; - switch (direntry->tdir_type) - { - case TIFF_UNDEFINED: - case TIFF_BYTE: - case TIFF_SBYTE: - case TIFF_SHORT: - case TIFF_SSHORT: - case TIFF_LONG: - case TIFF_SLONG: - case TIFF_LONG8: - case TIFF_SLONG8: - break; - default: - return(TIFFReadDirEntryErrType); - } - err=TIFFReadDirEntryArray(tif,direntry,&count,1,&origdata); - if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) - { - *value=0; - return(err); - } - switch (direntry->tdir_type) - { - case TIFF_UNDEFINED: - case TIFF_BYTE: - { - uint8* m; - uint32 n; - m=(uint8*)origdata; - for (n=0; ntdir_type) - { - case TIFF_SHORT: - { - uint16* ma; - int8* mb; - uint32 n; - ma=(uint16*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort(ma); - err=TIFFReadDirEntryCheckRangeSbyteShort(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(int8)(*ma++); - } - } - break; - case TIFF_SSHORT: - { - int16* ma; - int8* mb; - uint32 n; - ma=(int16*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)ma); - err=TIFFReadDirEntryCheckRangeSbyteSshort(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(int8)(*ma++); - } - } - break; - case TIFF_LONG: - { - uint32* ma; - int8* mb; - uint32 n; - ma=(uint32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - err=TIFFReadDirEntryCheckRangeSbyteLong(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(int8)(*ma++); - } - } - break; - case TIFF_SLONG: - { - int32* ma; - int8* mb; - uint32 n; - ma=(int32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)ma); - err=TIFFReadDirEntryCheckRangeSbyteSlong(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(int8)(*ma++); - } - } - break; - case TIFF_LONG8: - { - uint64* ma; - int8* mb; - uint32 n; - ma=(uint64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8(ma); - err=TIFFReadDirEntryCheckRangeSbyteLong8(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(int8)(*ma++); - } - } - break; - case TIFF_SLONG8: - { - int64* ma; - int8* mb; - uint32 n; - ma=(int64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)ma); - err=TIFFReadDirEntryCheckRangeSbyteSlong8(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(int8)(*ma++); - } - } - break; - } - _TIFFfree(origdata); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(data); - return(err); - } - *value=data; - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryShortArray(TIFF* tif, TIFFDirEntry* direntry, uint16** value) -{ - enum TIFFReadDirEntryErr err; - uint32 count; - void* origdata; - uint16* data; - switch (direntry->tdir_type) - { - case TIFF_BYTE: - case TIFF_SBYTE: - case TIFF_SHORT: - case TIFF_SSHORT: - case TIFF_LONG: - case TIFF_SLONG: - case TIFF_LONG8: - case TIFF_SLONG8: - break; - default: - return(TIFFReadDirEntryErrType); - } - err=TIFFReadDirEntryArray(tif,direntry,&count,2,&origdata); - if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) - { - *value=0; - return(err); - } - switch (direntry->tdir_type) - { - case TIFF_SHORT: - *value=(uint16*)origdata; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfShort(*value,count); - return(TIFFReadDirEntryErrOk); - case TIFF_SSHORT: - { - int16* m; - uint32 n; - m=(int16*)origdata; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)m); - err=TIFFReadDirEntryCheckRangeShortSshort(*m); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(origdata); - return(err); - } - m++; - } - *value=(uint16*)origdata; - return(TIFFReadDirEntryErrOk); - } - } - data=(uint16*)_TIFFmalloc(count*2); - if (data==0) - { - _TIFFfree(origdata); - return(TIFFReadDirEntryErrAlloc); - } - switch (direntry->tdir_type) - { - case TIFF_BYTE: - { - uint8* ma; - uint16* mb; - uint32 n; - ma=(uint8*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - err=TIFFReadDirEntryCheckRangeShortLong(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint16)(*ma++); - } - } - break; - case TIFF_SLONG: - { - int32* ma; - uint16* mb; - uint32 n; - ma=(int32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)ma); - err=TIFFReadDirEntryCheckRangeShortSlong(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint16)(*ma++); - } - } - break; - case TIFF_LONG8: - { - uint64* ma; - uint16* mb; - uint32 n; - ma=(uint64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8(ma); - err=TIFFReadDirEntryCheckRangeShortLong8(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint16)(*ma++); - } - } - break; - case TIFF_SLONG8: - { - int64* ma; - uint16* mb; - uint32 n; - ma=(int64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)ma); - err=TIFFReadDirEntryCheckRangeShortSlong8(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint16)(*ma++); - } - } - break; - } - _TIFFfree(origdata); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(data); - return(err); - } - *value=data; - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntrySshortArray(TIFF* tif, TIFFDirEntry* direntry, int16** value) -{ - enum TIFFReadDirEntryErr err; - uint32 count; - void* origdata; - int16* data; - switch (direntry->tdir_type) - { - case TIFF_BYTE: - case TIFF_SBYTE: - case TIFF_SHORT: - case TIFF_SSHORT: - case TIFF_LONG: - case TIFF_SLONG: - case TIFF_LONG8: - case TIFF_SLONG8: - break; - default: - return(TIFFReadDirEntryErrType); - } - err=TIFFReadDirEntryArray(tif,direntry,&count,2,&origdata); - if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) - { - *value=0; - return(err); - } - switch (direntry->tdir_type) - { - case TIFF_SHORT: - { - uint16* m; - uint32 n; - m=(uint16*)origdata; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort(m); - err=TIFFReadDirEntryCheckRangeSshortShort(*m); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(origdata); - return(err); - } - m++; - } - *value=(int16*)origdata; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SSHORT: - *value=(int16*)origdata; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfShort((uint16*)(*value),count); - return(TIFFReadDirEntryErrOk); - } - data=(int16*)_TIFFmalloc(count*2); - if (data==0) - { - _TIFFfree(origdata); - return(TIFFReadDirEntryErrAlloc); - } - switch (direntry->tdir_type) - { - case TIFF_BYTE: - { - uint8* ma; - int16* mb; - uint32 n; - ma=(uint8*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - err=TIFFReadDirEntryCheckRangeSshortLong(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(int16)(*ma++); - } - } - break; - case TIFF_SLONG: - { - int32* ma; - int16* mb; - uint32 n; - ma=(int32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)ma); - err=TIFFReadDirEntryCheckRangeSshortSlong(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(int16)(*ma++); - } - } - break; - case TIFF_LONG8: - { - uint64* ma; - int16* mb; - uint32 n; - ma=(uint64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8(ma); - err=TIFFReadDirEntryCheckRangeSshortLong8(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(int16)(*ma++); - } - } - break; - case TIFF_SLONG8: - { - int64* ma; - int16* mb; - uint32 n; - ma=(int64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)ma); - err=TIFFReadDirEntryCheckRangeSshortSlong8(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(int16)(*ma++); - } - } - break; - } - _TIFFfree(origdata); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(data); - return(err); - } - *value=data; - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryLongArray(TIFF* tif, TIFFDirEntry* direntry, uint32** value) -{ - enum TIFFReadDirEntryErr err; - uint32 count; - void* origdata; - uint32* data; - switch (direntry->tdir_type) - { - case TIFF_BYTE: - case TIFF_SBYTE: - case TIFF_SHORT: - case TIFF_SSHORT: - case TIFF_LONG: - case TIFF_SLONG: - case TIFF_LONG8: - case TIFF_SLONG8: - break; - default: - return(TIFFReadDirEntryErrType); - } - err=TIFFReadDirEntryArray(tif,direntry,&count,4,&origdata); - if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) - { - *value=0; - return(err); - } - switch (direntry->tdir_type) - { - case TIFF_LONG: - *value=(uint32*)origdata; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong(*value,count); - return(TIFFReadDirEntryErrOk); - case TIFF_SLONG: - { - int32* m; - uint32 n; - m=(int32*)origdata; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)m); - err=TIFFReadDirEntryCheckRangeLongSlong(*m); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(origdata); - return(err); - } - m++; - } - *value=(uint32*)origdata; - return(TIFFReadDirEntryErrOk); - } - } - data=(uint32*)_TIFFmalloc(count*4); - if (data==0) - { - _TIFFfree(origdata); - return(TIFFReadDirEntryErrAlloc); - } - switch (direntry->tdir_type) - { - case TIFF_BYTE: - { - uint8* ma; - uint32* mb; - uint32 n; - ma=(uint8*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort(ma); - *mb++=(uint32)(*ma++); - } - } - break; - case TIFF_SSHORT: - { - int16* ma; - uint32* mb; - uint32 n; - ma=(int16*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)ma); - err=TIFFReadDirEntryCheckRangeLongSshort(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint32)(*ma++); - } - } - break; - case TIFF_LONG8: - { - uint64* ma; - uint32* mb; - uint32 n; - ma=(uint64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8(ma); - err=TIFFReadDirEntryCheckRangeLongLong8(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint32)(*ma++); - } - } - break; - case TIFF_SLONG8: - { - int64* ma; - uint32* mb; - uint32 n; - ma=(int64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)ma); - err=TIFFReadDirEntryCheckRangeLongSlong8(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint32)(*ma++); - } - } - break; - } - _TIFFfree(origdata); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(data); - return(err); - } - *value=data; - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntrySlongArray(TIFF* tif, TIFFDirEntry* direntry, int32** value) -{ - enum TIFFReadDirEntryErr err; - uint32 count; - void* origdata; - int32* data; - switch (direntry->tdir_type) - { - case TIFF_BYTE: - case TIFF_SBYTE: - case TIFF_SHORT: - case TIFF_SSHORT: - case TIFF_LONG: - case TIFF_SLONG: - case TIFF_LONG8: - case TIFF_SLONG8: - break; - default: - return(TIFFReadDirEntryErrType); - } - err=TIFFReadDirEntryArray(tif,direntry,&count,4,&origdata); - if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) - { - *value=0; - return(err); - } - switch (direntry->tdir_type) - { - case TIFF_LONG: - { - uint32* m; - uint32 n; - m=(uint32*)origdata; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)m); - err=TIFFReadDirEntryCheckRangeSlongLong(*m); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(origdata); - return(err); - } - m++; - } - *value=(int32*)origdata; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SLONG: - *value=(int32*)origdata; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong((uint32*)(*value),count); - return(TIFFReadDirEntryErrOk); - } - data=(int32*)_TIFFmalloc(count*4); - if (data==0) - { - _TIFFfree(origdata); - return(TIFFReadDirEntryErrAlloc); - } - switch (direntry->tdir_type) - { - case TIFF_BYTE: - { - uint8* ma; - int32* mb; - uint32 n; - ma=(uint8*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort(ma); - *mb++=(int32)(*ma++); - } - } - break; - case TIFF_SSHORT: - { - int16* ma; - int32* mb; - uint32 n; - ma=(int16*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)ma); - *mb++=(int32)(*ma++); - } - } - break; - case TIFF_LONG8: - { - uint64* ma; - int32* mb; - uint32 n; - ma=(uint64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8(ma); - err=TIFFReadDirEntryCheckRangeSlongLong8(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(int32)(*ma++); - } - } - break; - case TIFF_SLONG8: - { - int64* ma; - int32* mb; - uint32 n; - ma=(int64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)ma); - err=TIFFReadDirEntryCheckRangeSlongSlong8(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(int32)(*ma++); - } - } - break; - } - _TIFFfree(origdata); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(data); - return(err); - } - *value=data; - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8Array(TIFF* tif, TIFFDirEntry* direntry, uint64** value) -{ - enum TIFFReadDirEntryErr err; - uint32 count; - void* origdata; - uint64* data; - switch (direntry->tdir_type) - { - case TIFF_BYTE: - case TIFF_SBYTE: - case TIFF_SHORT: - case TIFF_SSHORT: - case TIFF_LONG: - case TIFF_SLONG: - case TIFF_LONG8: - case TIFF_SLONG8: - break; - default: - return(TIFFReadDirEntryErrType); - } - err=TIFFReadDirEntryArray(tif,direntry,&count,8,&origdata); - if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) - { - *value=0; - return(err); - } - switch (direntry->tdir_type) - { - case TIFF_LONG8: - *value=(uint64*)origdata; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong8(*value,count); - return(TIFFReadDirEntryErrOk); - case TIFF_SLONG8: - { - int64* m; - uint32 n; - m=(int64*)origdata; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)m); - err=TIFFReadDirEntryCheckRangeLong8Slong8(*m); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(origdata); - return(err); - } - m++; - } - *value=(uint64*)origdata; - return(TIFFReadDirEntryErrOk); - } - } - data=(uint64*)_TIFFmalloc(count*8); - if (data==0) - { - _TIFFfree(origdata); - return(TIFFReadDirEntryErrAlloc); - } - switch (direntry->tdir_type) - { - case TIFF_BYTE: - { - uint8* ma; - uint64* mb; - uint32 n; - ma=(uint8*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort(ma); - *mb++=(uint64)(*ma++); - } - } - break; - case TIFF_SSHORT: - { - int16* ma; - uint64* mb; - uint32 n; - ma=(int16*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)ma); - err=TIFFReadDirEntryCheckRangeLong8Sshort(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint64)(*ma++); - } - } - break; - case TIFF_LONG: - { - uint32* ma; - uint64* mb; - uint32 n; - ma=(uint32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - *mb++=(uint64)(*ma++); - } - } - break; - case TIFF_SLONG: - { - int32* ma; - uint64* mb; - uint32 n; - ma=(int32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)ma); - err=TIFFReadDirEntryCheckRangeLong8Slong(*ma); - if (err!=TIFFReadDirEntryErrOk) - break; - *mb++=(uint64)(*ma++); - } - } - break; - } - _TIFFfree(origdata); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(data); - return(err); - } - *value=data; - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntrySlong8Array(TIFF* tif, TIFFDirEntry* direntry, int64** value) -{ - enum TIFFReadDirEntryErr err; - uint32 count; - void* origdata; - int64* data; - switch (direntry->tdir_type) - { - case TIFF_BYTE: - case TIFF_SBYTE: - case TIFF_SHORT: - case TIFF_SSHORT: - case TIFF_LONG: - case TIFF_SLONG: - case TIFF_LONG8: - case TIFF_SLONG8: - break; - default: - return(TIFFReadDirEntryErrType); - } - err=TIFFReadDirEntryArray(tif,direntry,&count,8,&origdata); - if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) - { - *value=0; - return(err); - } - switch (direntry->tdir_type) - { - case TIFF_LONG8: - { - uint64* m; - uint32 n; - m=(uint64*)origdata; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8(m); - err=TIFFReadDirEntryCheckRangeSlong8Long8(*m); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(origdata); - return(err); - } - m++; - } - *value=(int64*)origdata; - return(TIFFReadDirEntryErrOk); - } - case TIFF_SLONG8: - *value=(int64*)origdata; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong8((uint64*)(*value),count); - return(TIFFReadDirEntryErrOk); - } - data=(int64*)_TIFFmalloc(count*8); - if (data==0) - { - _TIFFfree(origdata); - return(TIFFReadDirEntryErrAlloc); - } - switch (direntry->tdir_type) - { - case TIFF_BYTE: - { - uint8* ma; - int64* mb; - uint32 n; - ma=(uint8*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort(ma); - *mb++=(int64)(*ma++); - } - } - break; - case TIFF_SSHORT: - { - int16* ma; - int64* mb; - uint32 n; - ma=(int16*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)ma); - *mb++=(int64)(*ma++); - } - } - break; - case TIFF_LONG: - { - uint32* ma; - int64* mb; - uint32 n; - ma=(uint32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - *mb++=(int64)(*ma++); - } - } - break; - case TIFF_SLONG: - { - int32* ma; - int64* mb; - uint32 n; - ma=(int32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)ma); - *mb++=(int64)(*ma++); - } - } - break; - } - _TIFFfree(origdata); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(data); - return(err); - } - *value=data; - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryFloatArray(TIFF* tif, TIFFDirEntry* direntry, float** value) -{ - enum TIFFReadDirEntryErr err; - uint32 count; - void* origdata; - float* data; - switch (direntry->tdir_type) - { - case TIFF_BYTE: - case TIFF_SBYTE: - case TIFF_SHORT: - case TIFF_SSHORT: - case TIFF_LONG: - case TIFF_SLONG: - case TIFF_LONG8: - case TIFF_SLONG8: - case TIFF_RATIONAL: - case TIFF_SRATIONAL: - case TIFF_FLOAT: - case TIFF_DOUBLE: - break; - default: - return(TIFFReadDirEntryErrType); - } - err=TIFFReadDirEntryArray(tif,direntry,&count,4,&origdata); - if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) - { - *value=0; - return(err); - } - switch (direntry->tdir_type) - { - case TIFF_FLOAT: - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong((uint32*)origdata,count); - TIFFCvtIEEEDoubleToNative(tif,count,(float*)origdata); - *value=(float*)origdata; - return(TIFFReadDirEntryErrOk); - } - data=(float*)_TIFFmalloc(count*sizeof(float)); - if (data==0) - { - _TIFFfree(origdata); - return(TIFFReadDirEntryErrAlloc); - } - switch (direntry->tdir_type) - { - case TIFF_BYTE: - { - uint8* ma; - float* mb; - uint32 n; - ma=(uint8*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort(ma); - *mb++=(float)(*ma++); - } - } - break; - case TIFF_SSHORT: - { - int16* ma; - float* mb; - uint32 n; - ma=(int16*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)ma); - *mb++=(float)(*ma++); - } - } - break; - case TIFF_LONG: - { - uint32* ma; - float* mb; - uint32 n; - ma=(uint32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - *mb++=(float)(*ma++); - } - } - break; - case TIFF_SLONG: - { - int32* ma; - float* mb; - uint32 n; - ma=(int32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)ma); - *mb++=(float)(*ma++); - } - } - break; - case TIFF_LONG8: - { - uint64* ma; - float* mb; - uint32 n; - ma=(uint64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8(ma); -#if defined(__WIN32__) && (_MSC_VER < 1500) - /* - * XXX: MSVC 6.0 does not support - * conversion of 64-bit integers into - * floating point values. - */ - *mb++ = _TIFFUInt64ToFloat(*ma++); -#else - *mb++ = (float)(*ma++); -#endif - } - } - break; - case TIFF_SLONG8: - { - int64* ma; - float* mb; - uint32 n; - ma=(int64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)ma); - *mb++=(float)(*ma++); - } - } - break; - case TIFF_RATIONAL: - { - uint32* ma; - uint32 maa; - uint32 mab; - float* mb; - uint32 n; - ma=(uint32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - maa=*ma++; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - mab=*ma++; - if (mab==0) - *mb++=0.0; - else - *mb++=(float)maa/(float)mab; - } - } - break; - case TIFF_SRATIONAL: - { - uint32* ma; - int32 maa; - uint32 mab; - float* mb; - uint32 n; - ma=(uint32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - maa=*(int32*)ma; - ma++; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - mab=*ma++; - if (mab==0) - *mb++=0.0; - else - *mb++=(float)maa/(float)mab; - } - } - break; - case TIFF_DOUBLE: - { - double* ma; - float* mb; - uint32 n; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong8((uint64*)origdata,count); - TIFFCvtIEEEDoubleToNative(tif,count,(double*)origdata); - ma=(double*)origdata; - mb=data; - for (n=0; ntdir_type) - { - case TIFF_BYTE: - case TIFF_SBYTE: - case TIFF_SHORT: - case TIFF_SSHORT: - case TIFF_LONG: - case TIFF_SLONG: - case TIFF_LONG8: - case TIFF_SLONG8: - case TIFF_RATIONAL: - case TIFF_SRATIONAL: - case TIFF_FLOAT: - case TIFF_DOUBLE: - break; - default: - return(TIFFReadDirEntryErrType); - } - err=TIFFReadDirEntryArray(tif,direntry,&count,8,&origdata); - if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) - { - *value=0; - return(err); - } - switch (direntry->tdir_type) - { - case TIFF_DOUBLE: - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong8((uint64*)origdata,count); - TIFFCvtIEEEDoubleToNative(tif,count,(double*)origdata); - *value=(double*)origdata; - return(TIFFReadDirEntryErrOk); - } - data=(double*)_TIFFmalloc(count*sizeof(double)); - if (data==0) - { - _TIFFfree(origdata); - return(TIFFReadDirEntryErrAlloc); - } - switch (direntry->tdir_type) - { - case TIFF_BYTE: - { - uint8* ma; - double* mb; - uint32 n; - ma=(uint8*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort(ma); - *mb++=(double)(*ma++); - } - } - break; - case TIFF_SSHORT: - { - int16* ma; - double* mb; - uint32 n; - ma=(int16*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)ma); - *mb++=(double)(*ma++); - } - } - break; - case TIFF_LONG: - { - uint32* ma; - double* mb; - uint32 n; - ma=(uint32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - *mb++=(double)(*ma++); - } - } - break; - case TIFF_SLONG: - { - int32* ma; - double* mb; - uint32 n; - ma=(int32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)ma); - *mb++=(double)(*ma++); - } - } - break; - case TIFF_LONG8: - { - uint64* ma; - double* mb; - uint32 n; - ma=(uint64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8(ma); -#if defined(__WIN32__) && (_MSC_VER < 1500) - /* - * XXX: MSVC 6.0 does not support - * conversion of 64-bit integers into - * floating point values. - */ - *mb++ = _TIFFUInt64ToDouble(*ma++); -#else - *mb++ = (double)(*ma++); -#endif - } - } - break; - case TIFF_SLONG8: - { - int64* ma; - double* mb; - uint32 n; - ma=(int64*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)ma); - *mb++=(double)(*ma++); - } - } - break; - case TIFF_RATIONAL: - { - uint32* ma; - uint32 maa; - uint32 mab; - double* mb; - uint32 n; - ma=(uint32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - maa=*ma++; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - mab=*ma++; - if (mab==0) - *mb++=0.0; - else - *mb++=(double)maa/(double)mab; - } - } - break; - case TIFF_SRATIONAL: - { - uint32* ma; - int32 maa; - uint32 mab; - double* mb; - uint32 n; - ma=(uint32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - maa=*(int32*)ma; - ma++; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - mab=*ma++; - if (mab==0) - *mb++=0.0; - else - *mb++=(double)maa/(double)mab; - } - } - break; - case TIFF_FLOAT: - { - float* ma; - double* mb; - uint32 n; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong((uint32*)origdata,count); - TIFFCvtIEEEFloatToNative(tif,count,(float*)origdata); - ma=(float*)origdata; - mb=data; - for (n=0; ntdir_type) - { - case TIFF_LONG: - case TIFF_LONG8: - case TIFF_IFD: - case TIFF_IFD8: - break; - default: - return(TIFFReadDirEntryErrType); - } - err=TIFFReadDirEntryArray(tif,direntry,&count,8,&origdata); - if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) - { - *value=0; - return(err); - } - switch (direntry->tdir_type) - { - case TIFF_LONG8: - case TIFF_IFD8: - *value=(uint64*)origdata; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong8(*value,count); - return(TIFFReadDirEntryErrOk); - } - data=(uint64*)_TIFFmalloc(count*8); - if (data==0) - { - _TIFFfree(origdata); - return(TIFFReadDirEntryErrAlloc); - } - switch (direntry->tdir_type) - { - case TIFF_LONG: - case TIFF_IFD: - { - uint32* ma; - uint64* mb; - uint32 n; - ma=(uint32*)origdata; - mb=data; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabLong(ma); - *mb++=(uint64)(*ma++); - } - } - break; - } - _TIFFfree(origdata); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(data); - return(err); - } - *value=data; - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleShort(TIFF* tif, TIFFDirEntry* direntry, uint16* value) -{ - enum TIFFReadDirEntryErr err; - uint16* m; - uint16* na; - uint16 nb; - if (direntry->tdir_count<(uint64)tif->tif_dir.td_samplesperpixel) - return(TIFFReadDirEntryErrCount); - err=TIFFReadDirEntryShortArray(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - na=m; - nb=tif->tif_dir.td_samplesperpixel; - *value=*na++; - nb--; - while (nb>0) - { - if (*na++!=*value) - { - err=TIFFReadDirEntryErrPsdif; - break; - } - nb--; - } - _TIFFfree(m); - return(err); -} - -#if 0 -static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleDouble(TIFF* tif, TIFFDirEntry* direntry, double* value) -{ - enum TIFFReadDirEntryErr err; - double* m; - double* na; - uint16 nb; - if (direntry->tdir_count<(uint64)tif->tif_dir.td_samplesperpixel) - return(TIFFReadDirEntryErrCount); - err=TIFFReadDirEntryDoubleArray(tif,direntry,&m); - if (err!=TIFFReadDirEntryErrOk) - return(err); - na=m; - nb=tif->tif_dir.td_samplesperpixel; - *value=*na++; - nb--; - while (nb>0) - { - if (*na++!=*value) - { - err=TIFFReadDirEntryErrPsdif; - break; - } - nb--; - } - _TIFFfree(m); - return(err); -} -#endif - -static void TIFFReadDirEntryCheckedByte(TIFF* tif, TIFFDirEntry* direntry, uint8* value) -{ - (void) tif; - *value=*(uint8*)(&direntry->tdir_offset); -} - -static void TIFFReadDirEntryCheckedSbyte(TIFF* tif, TIFFDirEntry* direntry, int8* value) -{ - (void) tif; - *value=*(int8*)(&direntry->tdir_offset); -} - -static void TIFFReadDirEntryCheckedShort(TIFF* tif, TIFFDirEntry* direntry, uint16* value) -{ - *value = direntry->tdir_offset.toff_short; - /* *value=*(uint16*)(&direntry->tdir_offset); */ - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabShort(value); -} - -static void TIFFReadDirEntryCheckedSshort(TIFF* tif, TIFFDirEntry* direntry, int16* value) -{ - *value=*(int16*)(&direntry->tdir_offset); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)value); -} - -static void TIFFReadDirEntryCheckedLong(TIFF* tif, TIFFDirEntry* direntry, uint32* value) -{ - *value=*(uint32*)(&direntry->tdir_offset); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(value); -} - -static void TIFFReadDirEntryCheckedSlong(TIFF* tif, TIFFDirEntry* direntry, int32* value) -{ - *value=*(int32*)(&direntry->tdir_offset); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)value); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedLong8(TIFF* tif, TIFFDirEntry* direntry, uint64* value) -{ - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - enum TIFFReadDirEntryErr err; - uint32 offset = direntry->tdir_offset.toff_long; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(&offset); - err=TIFFReadDirEntryData(tif,offset,8,value); - if (err!=TIFFReadDirEntryErrOk) - return(err); - } - else - *value = direntry->tdir_offset.toff_long8; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8(value); - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSlong8(TIFF* tif, TIFFDirEntry* direntry, int64* value) -{ - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - enum TIFFReadDirEntryErr err; - uint32 offset = direntry->tdir_offset.toff_long; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(&offset); - err=TIFFReadDirEntryData(tif,offset,8,value); - if (err!=TIFFReadDirEntryErrOk) - return(err); - } - else - *value=*(int64*)(&direntry->tdir_offset); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)value); - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedRational(TIFF* tif, TIFFDirEntry* direntry, double* value) -{ - UInt64Aligned_t m; - - assert(sizeof(double)==8); - assert(sizeof(uint64)==8); - assert(sizeof(uint32)==4); - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - enum TIFFReadDirEntryErr err; - uint32 offset = direntry->tdir_offset.toff_long; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(&offset); - err=TIFFReadDirEntryData(tif,offset,8,m.i); - if (err!=TIFFReadDirEntryErrOk) - return(err); - } - else - m.l = direntry->tdir_offset.toff_long8; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong(m.i,2); - if (m.i[0]==0) - *value=0.0; - else - *value=(double)m.i[0]/(double)m.i[1]; - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSrational(TIFF* tif, TIFFDirEntry* direntry, double* value) -{ - UInt64Aligned_t m; - assert(sizeof(double)==8); - assert(sizeof(uint64)==8); - assert(sizeof(int32)==4); - assert(sizeof(uint32)==4); - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - enum TIFFReadDirEntryErr err; - uint32 offset = direntry->tdir_offset.toff_long; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(&offset); - err=TIFFReadDirEntryData(tif,offset,8,m.i); - if (err!=TIFFReadDirEntryErrOk) - return(err); - } - else - m.l=direntry->tdir_offset.toff_long8; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong(m.i,2); - if ((int32)m.i[0]==0) - *value=0.0; - else - *value=(double)((int32)m.i[0])/(double)m.i[1]; - return(TIFFReadDirEntryErrOk); -} - -static void TIFFReadDirEntryCheckedFloat(TIFF* tif, TIFFDirEntry* direntry, float* value) -{ - union - { - float f; - uint32 i; - } float_union; - assert(sizeof(float)==4); - assert(sizeof(uint32)==4); - assert(sizeof(float_union)==4); - float_union.i=*(uint32*)(&direntry->tdir_offset); - *value=float_union.f; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)value); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedDouble(TIFF* tif, TIFFDirEntry* direntry, double* value) -{ - assert(sizeof(double)==8); - assert(sizeof(uint64)==8); - assert(sizeof(UInt64Aligned_t)==8); - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - enum TIFFReadDirEntryErr err; - uint32 offset = direntry->tdir_offset.toff_long; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(&offset); - err=TIFFReadDirEntryData(tif,offset,8,value); - if (err!=TIFFReadDirEntryErrOk) - return(err); - } - else - { - UInt64Aligned_t uint64_union; - uint64_union.l=direntry->tdir_offset.toff_long8; - *value=uint64_union.d; - } - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)value); - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSbyte(int8 value) -{ - if (value<0) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteShort(uint16 value) -{ - if (value>0xFF) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSshort(int16 value) -{ - if ((value<0)||(value>0xFF)) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong(uint32 value) -{ - if (value>0xFF) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong(int32 value) -{ - if ((value<0)||(value>0xFF)) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong8(uint64 value) -{ - if (value>0xFF) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong8(int64 value) -{ - if ((value<0)||(value>0xFF)) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteByte(uint8 value) -{ - if (value>0x7F) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteShort(uint16 value) -{ - if (value>0x7F) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSshort(int16 value) -{ - if ((value<-0x80)||(value>0x7F)) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteLong(uint32 value) -{ - if (value>0x7F) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSlong(int32 value) -{ - if ((value<-0x80)||(value>0x7F)) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteLong8(uint64 value) -{ - if (value>0x7F) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSlong8(int64 value) -{ - if ((value<-0x80)||(value>0x7F)) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSbyte(int8 value) -{ - if (value<0) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSshort(int16 value) -{ - if (value<0) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortLong(uint32 value) -{ - if (value>0xFFFF) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSlong(int32 value) -{ - if ((value<0)||(value>0xFFFF)) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortLong8(uint64 value) -{ - if (value>0xFFFF) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSlong8(int64 value) -{ - if ((value<0)||(value>0xFFFF)) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortShort(uint16 value) -{ - if (value>0x7FFF) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortLong(uint32 value) -{ - if (value>0x7FFF) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortSlong(int32 value) -{ - if ((value<-0x8000)||(value>0x7FFF)) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortLong8(uint64 value) -{ - if (value>0x7FFF) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortSlong8(int64 value) -{ - if ((value<-0x8000)||(value>0x7FFF)) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSbyte(int8 value) -{ - if (value<0) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSshort(int16 value) -{ - if (value<0) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSlong(int32 value) -{ - if (value<0) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -/* - * Largest 32-bit unsigned integer value. - */ -#if defined(__WIN32__) && defined(_MSC_VER) -# define TIFF_UINT32_MAX 0xFFFFFFFFI64 -#else -# define TIFF_UINT32_MAX 0xFFFFFFFFLL -#endif - -static enum TIFFReadDirEntryErr -TIFFReadDirEntryCheckRangeLongLong8(uint64 value) -{ - if (value > TIFF_UINT32_MAX) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr -TIFFReadDirEntryCheckRangeLongSlong8(int64 value) -{ - if ((value<0) || (value > TIFF_UINT32_MAX)) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -#undef TIFF_UINT32_MAX - -static enum TIFFReadDirEntryErr -TIFFReadDirEntryCheckRangeSlongLong(uint32 value) -{ - if (value > 0x7FFFFFFFUL) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr -TIFFReadDirEntryCheckRangeSlongLong8(uint64 value) -{ - if (value > 0x7FFFFFFFUL) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr -TIFFReadDirEntryCheckRangeSlongSlong8(int64 value) -{ - if ((value < 0L-0x80000000L) || (value > 0x7FFFFFFFL)) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr -TIFFReadDirEntryCheckRangeLong8Sbyte(int8 value) -{ - if (value < 0) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr -TIFFReadDirEntryCheckRangeLong8Sshort(int16 value) -{ - if (value < 0) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr -TIFFReadDirEntryCheckRangeLong8Slong(int32 value) -{ - if (value < 0) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -static enum TIFFReadDirEntryErr -TIFFReadDirEntryCheckRangeLong8Slong8(int64 value) -{ - if (value < 0) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -/* - * Largest 64-bit signed integer value. - */ -#if defined(__WIN32__) && defined(_MSC_VER) -# define TIFF_INT64_MAX 0x7FFFFFFFFFFFFFFFI64 -#else -# define TIFF_INT64_MAX 0x7FFFFFFFFFFFFFFFLL -#endif - -static enum TIFFReadDirEntryErr -TIFFReadDirEntryCheckRangeSlong8Long8(uint64 value) -{ - if (value > TIFF_INT64_MAX) - return(TIFFReadDirEntryErrRange); - else - return(TIFFReadDirEntryErrOk); -} - -#undef TIFF_INT64_MAX - -static enum TIFFReadDirEntryErr -TIFFReadDirEntryData(TIFF* tif, uint64 offset, tmsize_t size, void* dest) -{ - assert(size>0); - if (!isMapped(tif)) { - if (!SeekOK(tif,offset)) - return(TIFFReadDirEntryErrIo); - if (!ReadOK(tif,dest,size)) - return(TIFFReadDirEntryErrIo); - } else { - size_t ma,mb; - ma=(size_t)offset; - mb=ma+size; - if (((uint64)ma!=offset) - || (mb < ma) - || (mb - ma != (size_t) size) - || (mb < (size_t)size) - || (mb > (size_t)tif->tif_size) - ) - return(TIFFReadDirEntryErrIo); - _TIFFmemcpy(dest,tif->tif_base+ma,size); - } - return(TIFFReadDirEntryErrOk); -} - -static void TIFFReadDirEntryOutputErr(TIFF* tif, enum TIFFReadDirEntryErr err, const char* module, const char* tagname, int recover) -{ - if (!recover) { - switch (err) { - case TIFFReadDirEntryErrCount: - TIFFErrorExt(tif->tif_clientdata, module, - "Incorrect count for \"%s\"", - tagname); - break; - case TIFFReadDirEntryErrType: - TIFFErrorExt(tif->tif_clientdata, module, - "Incompatible type for \"%s\"", - tagname); - break; - case TIFFReadDirEntryErrIo: - TIFFErrorExt(tif->tif_clientdata, module, - "IO error during reading of \"%s\"", - tagname); - break; - case TIFFReadDirEntryErrRange: - TIFFErrorExt(tif->tif_clientdata, module, - "Incorrect value for \"%s\"", - tagname); - break; - case TIFFReadDirEntryErrPsdif: - TIFFErrorExt(tif->tif_clientdata, module, - "Cannot handle different values per sample for \"%s\"", - tagname); - break; - case TIFFReadDirEntryErrSizesan: - TIFFErrorExt(tif->tif_clientdata, module, - "Sanity check on size of \"%s\" value failed", - tagname); - break; - case TIFFReadDirEntryErrAlloc: - TIFFErrorExt(tif->tif_clientdata, module, - "Out of memory reading of \"%s\"", - tagname); - break; - default: - assert(0); /* we should never get here */ - break; - } - } else { - switch (err) { - case TIFFReadDirEntryErrCount: - TIFFErrorExt(tif->tif_clientdata, module, - "Incorrect count for \"%s\"; tag ignored", - tagname); - break; - case TIFFReadDirEntryErrType: - TIFFWarningExt(tif->tif_clientdata, module, - "Incompatible type for \"%s\"; tag ignored", - tagname); - break; - case TIFFReadDirEntryErrIo: - TIFFWarningExt(tif->tif_clientdata, module, - "IO error during reading of \"%s\"; tag ignored", - tagname); - break; - case TIFFReadDirEntryErrRange: - TIFFWarningExt(tif->tif_clientdata, module, - "Incorrect value for \"%s\"; tag ignored", - tagname); - break; - case TIFFReadDirEntryErrPsdif: - TIFFWarningExt(tif->tif_clientdata, module, - "Cannot handle different values per sample for \"%s\"; tag ignored", - tagname); - break; - case TIFFReadDirEntryErrSizesan: - TIFFWarningExt(tif->tif_clientdata, module, - "Sanity check on size of \"%s\" value failed; tag ignored", - tagname); - break; - case TIFFReadDirEntryErrAlloc: - TIFFWarningExt(tif->tif_clientdata, module, - "Out of memory reading of \"%s\"; tag ignored", - tagname); - break; - default: - assert(0); /* we should never get here */ - break; - } - } -} - -/* - * Read the next TIFF directory from a file and convert it to the internal - * format. We read directories sequentially. - */ -int -TIFFReadDirectory(TIFF* tif) -{ - static const char module[] = "TIFFReadDirectory"; - TIFFDirEntry* dir; - uint16 dircount; - TIFFDirEntry* dp; - uint16 di; - const TIFFField* fip; - uint32 fii=FAILED_FII; - toff_t nextdiroff; - tif->tif_diroff=tif->tif_nextdiroff; - if (!TIFFCheckDirOffset(tif,tif->tif_nextdiroff)) - return 0; /* last offset or bad offset (IFD looping) */ - (*tif->tif_cleanup)(tif); /* cleanup any previous compression state */ - tif->tif_curdir++; - nextdiroff = tif->tif_nextdiroff; - dircount=TIFFFetchDirectory(tif,nextdiroff,&dir,&tif->tif_nextdiroff); - if (!dircount) - { - TIFFErrorExt(tif->tif_clientdata,module, - "Failed to read directory at offset " TIFF_UINT64_FORMAT,nextdiroff); - return 0; - } - TIFFReadDirectoryCheckOrder(tif,dir,dircount); - - /* - * Mark duplicates of any tag to be ignored (bugzilla 1994) - * to avoid certain pathological problems. - */ - { - TIFFDirEntry* ma; - uint16 mb; - for (ma=dir, mb=0; mbtdir_tag==na->tdir_tag) - na->tdir_tag=IGNORE; - } - } - } - - tif->tif_flags &= ~TIFF_BEENWRITING; /* reset before new dir */ - tif->tif_flags &= ~TIFF_BUF4WRITE; /* reset before new dir */ - /* free any old stuff and reinit */ - TIFFFreeDirectory(tif); - TIFFDefaultDirectory(tif); - /* - * Electronic Arts writes gray-scale TIFF files - * without a PlanarConfiguration directory entry. - * Thus we setup a default value here, even though - * the TIFF spec says there is no default value. - */ - TIFFSetField(tif,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG); - /* - * Setup default value and then make a pass over - * the fields to check type and tag information, - * and to extract info required to size data - * structures. A second pass is made afterwards - * to read in everthing not taken in the first pass. - * But we must process the Compression tag first - * in order to merge in codec-private tag definitions (otherwise - * we may get complaints about unknown tags). However, the - * Compression tag may be dependent on the SamplesPerPixel - * tag value because older TIFF specs permited Compression - * to be written as a SamplesPerPixel-count tag entry. - * Thus if we don't first figure out the correct SamplesPerPixel - * tag value then we may end up ignoring the Compression tag - * value because it has an incorrect count value (if the - * true value of SamplesPerPixel is not 1). - */ - dp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_SAMPLESPERPIXEL); - if (dp) - { - if (!TIFFFetchNormalTag(tif,dp,0)) - goto bad; - dp->tdir_tag=IGNORE; - } - dp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_COMPRESSION); - if (dp) - { - /* - * The 5.0 spec says the Compression tag has one value, while - * earlier specs say it has one value per sample. Because of - * this, we accept the tag if one value is supplied with either - * count. - */ - uint16 value; - enum TIFFReadDirEntryErr err; - err=TIFFReadDirEntryShort(tif,dp,&value); - if (err==TIFFReadDirEntryErrCount) - err=TIFFReadDirEntryPersampleShort(tif,dp,&value); - if (err!=TIFFReadDirEntryErrOk) - { - TIFFReadDirEntryOutputErr(tif,err,module,"Compression",0); - goto bad; - } - if (!TIFFSetField(tif,TIFFTAG_COMPRESSION,value)) - goto bad; - dp->tdir_tag=IGNORE; - } - else - { - if (!TIFFSetField(tif,TIFFTAG_COMPRESSION,COMPRESSION_NONE)) - goto bad; - } - /* - * First real pass over the directory. - */ - for (di=0, dp=dir; ditdir_tag!=IGNORE) - { - TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); - if (fii == FAILED_FII) - { - TIFFWarningExt(tif->tif_clientdata, module, - "Unknown field with tag %d (0x%x) encountered", - dp->tdir_tag,dp->tdir_tag); - /* the following knowingly leaks the - anonymous field structure */ - if (!_TIFFMergeFields(tif, - _TIFFCreateAnonField(tif, - dp->tdir_tag, - (TIFFDataType) dp->tdir_type), - 1)) { - TIFFWarningExt(tif->tif_clientdata, - module, - "Registering anonymous field with tag %d (0x%x) failed", - dp->tdir_tag, - dp->tdir_tag); - dp->tdir_tag=IGNORE; - } else { - TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); - assert(fii != FAILED_FII); - } - } - } - if (dp->tdir_tag!=IGNORE) - { - fip=tif->tif_fields[fii]; - if (fip->field_bit==FIELD_IGNORE) - dp->tdir_tag=IGNORE; - else - { - switch (dp->tdir_tag) - { - case TIFFTAG_STRIPOFFSETS: - case TIFFTAG_STRIPBYTECOUNTS: - case TIFFTAG_TILEOFFSETS: - case TIFFTAG_TILEBYTECOUNTS: - TIFFSetFieldBit(tif,fip->field_bit); - break; - case TIFFTAG_IMAGEWIDTH: - case TIFFTAG_IMAGELENGTH: - case TIFFTAG_IMAGEDEPTH: - case TIFFTAG_TILELENGTH: - case TIFFTAG_TILEWIDTH: - case TIFFTAG_TILEDEPTH: - case TIFFTAG_PLANARCONFIG: - case TIFFTAG_ROWSPERSTRIP: - case TIFFTAG_EXTRASAMPLES: - if (!TIFFFetchNormalTag(tif,dp,0)) - goto bad; - dp->tdir_tag=IGNORE; - break; - } - } - } - } - /* - * XXX: OJPEG hack. - * If a) compression is OJPEG, b) planarconfig tag says it's separate, - * c) strip offsets/bytecounts tag are both present and - * d) both contain exactly one value, then we consistently find - * that the buggy implementation of the buggy compression scheme - * matches contig planarconfig best. So we 'fix-up' the tag here - */ - if ((tif->tif_dir.td_compression==COMPRESSION_OJPEG)&& - (tif->tif_dir.td_planarconfig==PLANARCONFIG_SEPARATE)) - { - if (!_TIFFFillStriles(tif)) - goto bad; - dp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_STRIPOFFSETS); - if ((dp!=0)&&(dp->tdir_count==1)) - { - dp=TIFFReadDirectoryFindEntry(tif,dir,dircount, - TIFFTAG_STRIPBYTECOUNTS); - if ((dp!=0)&&(dp->tdir_count==1)) - { - tif->tif_dir.td_planarconfig=PLANARCONFIG_CONTIG; - TIFFWarningExt(tif->tif_clientdata,module, - "Planarconfig tag value assumed incorrect, " - "assuming data is contig instead of chunky"); - } - } - } - /* - * Allocate directory structure and setup defaults. - */ - if (!TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS)) - { - MissingRequired(tif,"ImageLength"); - goto bad; - } - /* - * Setup appropriate structures (by strip or by tile) - */ - if (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) { - tif->tif_dir.td_nstrips = TIFFNumberOfStrips(tif); - tif->tif_dir.td_tilewidth = tif->tif_dir.td_imagewidth; - tif->tif_dir.td_tilelength = tif->tif_dir.td_rowsperstrip; - tif->tif_dir.td_tiledepth = tif->tif_dir.td_imagedepth; - tif->tif_flags &= ~TIFF_ISTILED; - } else { - tif->tif_dir.td_nstrips = TIFFNumberOfTiles(tif); - tif->tif_flags |= TIFF_ISTILED; - } - if (!tif->tif_dir.td_nstrips) { - TIFFErrorExt(tif->tif_clientdata, module, - "Cannot handle zero number of %s", - isTiled(tif) ? "tiles" : "strips"); - goto bad; - } - tif->tif_dir.td_stripsperimage = tif->tif_dir.td_nstrips; - if (tif->tif_dir.td_planarconfig == PLANARCONFIG_SEPARATE) - tif->tif_dir.td_stripsperimage /= tif->tif_dir.td_samplesperpixel; - if (!TIFFFieldSet(tif, FIELD_STRIPOFFSETS)) { - if ((tif->tif_dir.td_compression==COMPRESSION_OJPEG) && - (isTiled(tif)==0) && - (tif->tif_dir.td_nstrips==1)) { - /* - * XXX: OJPEG hack. - * If a) compression is OJPEG, b) it's not a tiled TIFF, - * and c) the number of strips is 1, - * then we tolerate the absence of stripoffsets tag, - * because, presumably, all required data is in the - * JpegInterchangeFormat stream. - */ - TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS); - } else { - MissingRequired(tif, - isTiled(tif) ? "TileOffsets" : "StripOffsets"); - goto bad; - } - } - /* - * Second pass: extract other information. - */ - for (di=0, dp=dir; ditdir_tag) - { - case IGNORE: - break; - case TIFFTAG_MINSAMPLEVALUE: - case TIFFTAG_MAXSAMPLEVALUE: - case TIFFTAG_BITSPERSAMPLE: - case TIFFTAG_DATATYPE: - case TIFFTAG_SAMPLEFORMAT: - /* - * The MinSampleValue, MaxSampleValue, BitsPerSample - * DataType and SampleFormat tags are supposed to be - * written as one value/sample, but some vendors - * incorrectly write one value only -- so we accept - * that as well (yech). Other vendors write correct - * value for NumberOfSamples, but incorrect one for - * BitsPerSample and friends, and we will read this - * too. - */ - { - uint16 value; - enum TIFFReadDirEntryErr err; - err=TIFFReadDirEntryShort(tif,dp,&value); - if (err==TIFFReadDirEntryErrCount) - err=TIFFReadDirEntryPersampleShort(tif,dp,&value); - if (err!=TIFFReadDirEntryErrOk) - { - fip = TIFFFieldWithTag(tif,dp->tdir_tag); - TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0); - goto bad; - } - if (!TIFFSetField(tif,dp->tdir_tag,value)) - goto bad; - } - break; - case TIFFTAG_SMINSAMPLEVALUE: - case TIFFTAG_SMAXSAMPLEVALUE: - { - - double *data; - enum TIFFReadDirEntryErr err; - uint32 saved_flags; - int m; - if (dp->tdir_count != (uint64)tif->tif_dir.td_samplesperpixel) - err = TIFFReadDirEntryErrCount; - else - err = TIFFReadDirEntryDoubleArray(tif, dp, &data); - if (err!=TIFFReadDirEntryErrOk) - { - fip = TIFFFieldWithTag(tif,dp->tdir_tag); - TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0); - goto bad; - } - saved_flags = tif->tif_flags; - tif->tif_flags |= TIFF_PERSAMPLE; - m = TIFFSetField(tif,dp->tdir_tag,data); - tif->tif_flags = saved_flags; - _TIFFfree(data); - if (!m) - goto bad; - } - break; - case TIFFTAG_STRIPOFFSETS: - case TIFFTAG_TILEOFFSETS: -#if defined(DEFER_STRILE_LOAD) - _TIFFmemcpy( &(tif->tif_dir.td_stripoffset_entry), - dp, sizeof(TIFFDirEntry) ); -#else - if (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripoffset)) - goto bad; -#endif - break; - case TIFFTAG_STRIPBYTECOUNTS: - case TIFFTAG_TILEBYTECOUNTS: -#if defined(DEFER_STRILE_LOAD) - _TIFFmemcpy( &(tif->tif_dir.td_stripbytecount_entry), - dp, sizeof(TIFFDirEntry) ); -#else - if (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripbytecount)) - goto bad; -#endif - break; - case TIFFTAG_COLORMAP: - case TIFFTAG_TRANSFERFUNCTION: - { - enum TIFFReadDirEntryErr err; - uint32 countpersample; - uint32 countrequired; - uint32 incrementpersample; - uint16* value=NULL; - countpersample=(1L<tif_dir.td_bitspersample); - if ((dp->tdir_tag==TIFFTAG_TRANSFERFUNCTION)&&(dp->tdir_count==(uint64)countpersample)) - { - countrequired=countpersample; - incrementpersample=0; - } - else - { - countrequired=3*countpersample; - incrementpersample=countpersample; - } - if (dp->tdir_count!=(uint64)countrequired) - err=TIFFReadDirEntryErrCount; - else - err=TIFFReadDirEntryShortArray(tif,dp,&value); - if (err!=TIFFReadDirEntryErrOk) - { - fip = TIFFFieldWithTag(tif,dp->tdir_tag); - TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",1); - } - else - { - TIFFSetField(tif,dp->tdir_tag,value,value+incrementpersample,value+2*incrementpersample); - _TIFFfree(value); - } - } - break; -/* BEGIN REV 4.0 COMPATIBILITY */ - case TIFFTAG_OSUBFILETYPE: - { - uint16 valueo; - uint32 value; - if (TIFFReadDirEntryShort(tif,dp,&valueo)==TIFFReadDirEntryErrOk) - { - switch (valueo) - { - case OFILETYPE_REDUCEDIMAGE: value=FILETYPE_REDUCEDIMAGE; break; - case OFILETYPE_PAGE: value=FILETYPE_PAGE; break; - default: value=0; break; - } - if (value!=0) - TIFFSetField(tif,TIFFTAG_SUBFILETYPE,value); - } - } - break; -/* END REV 4.0 COMPATIBILITY */ - default: - (void) TIFFFetchNormalTag(tif, dp, TRUE); - break; - } - } - /* - * OJPEG hack: - * - If a) compression is OJPEG, and b) photometric tag is missing, - * then we consistently find that photometric should be YCbCr - * - If a) compression is OJPEG, and b) photometric tag says it's RGB, - * then we consistently find that the buggy implementation of the - * buggy compression scheme matches photometric YCbCr instead. - * - If a) compression is OJPEG, and b) bitspersample tag is missing, - * then we consistently find bitspersample should be 8. - * - If a) compression is OJPEG, b) samplesperpixel tag is missing, - * and c) photometric is RGB or YCbCr, then we consistently find - * samplesperpixel should be 3 - * - If a) compression is OJPEG, b) samplesperpixel tag is missing, - * and c) photometric is MINISWHITE or MINISBLACK, then we consistently - * find samplesperpixel should be 3 - */ - if (tif->tif_dir.td_compression==COMPRESSION_OJPEG) - { - if (!TIFFFieldSet(tif,FIELD_PHOTOMETRIC)) - { - TIFFWarningExt(tif->tif_clientdata, module, - "Photometric tag is missing, assuming data is YCbCr"); - if (!TIFFSetField(tif,TIFFTAG_PHOTOMETRIC,PHOTOMETRIC_YCBCR)) - goto bad; - } - else if (tif->tif_dir.td_photometric==PHOTOMETRIC_RGB) - { - tif->tif_dir.td_photometric=PHOTOMETRIC_YCBCR; - TIFFWarningExt(tif->tif_clientdata, module, - "Photometric tag value assumed incorrect, " - "assuming data is YCbCr instead of RGB"); - } - if (!TIFFFieldSet(tif,FIELD_BITSPERSAMPLE)) - { - TIFFWarningExt(tif->tif_clientdata,module, - "BitsPerSample tag is missing, assuming 8 bits per sample"); - if (!TIFFSetField(tif,TIFFTAG_BITSPERSAMPLE,8)) - goto bad; - } - if (!TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL)) - { - if (tif->tif_dir.td_photometric==PHOTOMETRIC_RGB) - { - TIFFWarningExt(tif->tif_clientdata,module, - "SamplesPerPixel tag is missing, " - "assuming correct SamplesPerPixel value is 3"); - if (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,3)) - goto bad; - } - if (tif->tif_dir.td_photometric==PHOTOMETRIC_YCBCR) - { - TIFFWarningExt(tif->tif_clientdata,module, - "SamplesPerPixel tag is missing, " - "applying correct SamplesPerPixel value of 3"); - if (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,3)) - goto bad; - } - else if ((tif->tif_dir.td_photometric==PHOTOMETRIC_MINISWHITE) - || (tif->tif_dir.td_photometric==PHOTOMETRIC_MINISBLACK)) - { - /* - * SamplesPerPixel tag is missing, but is not required - * by spec. Assume correct SamplesPerPixel value of 1. - */ - if (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,1)) - goto bad; - } - } - } - /* - * Verify Palette image has a Colormap. - */ - if (tif->tif_dir.td_photometric == PHOTOMETRIC_PALETTE && - !TIFFFieldSet(tif, FIELD_COLORMAP)) { - if ( tif->tif_dir.td_bitspersample>=8 && tif->tif_dir.td_samplesperpixel==3) - tif->tif_dir.td_photometric = PHOTOMETRIC_RGB; - else if (tif->tif_dir.td_bitspersample>=8) - tif->tif_dir.td_photometric = PHOTOMETRIC_MINISBLACK; - else { - MissingRequired(tif, "Colormap"); - goto bad; - } - } - /* - * OJPEG hack: - * We do no further messing with strip/tile offsets/bytecounts in OJPEG - * TIFFs - */ - if (tif->tif_dir.td_compression!=COMPRESSION_OJPEG) - { - /* - * Attempt to deal with a missing StripByteCounts tag. - */ - if (!TIFFFieldSet(tif, FIELD_STRIPBYTECOUNTS)) { - /* - * Some manufacturers violate the spec by not giving - * the size of the strips. In this case, assume there - * is one uncompressed strip of data. - */ - if ((tif->tif_dir.td_planarconfig == PLANARCONFIG_CONTIG && - tif->tif_dir.td_nstrips > 1) || - (tif->tif_dir.td_planarconfig == PLANARCONFIG_SEPARATE && - tif->tif_dir.td_nstrips != (uint32)tif->tif_dir.td_samplesperpixel)) { - MissingRequired(tif, "StripByteCounts"); - goto bad; - } - TIFFWarningExt(tif->tif_clientdata, module, - "TIFF directory is missing required " - "\"StripByteCounts\" field, calculating from imagelength"); - if (EstimateStripByteCounts(tif, dir, dircount) < 0) - goto bad; - /* - * Assume we have wrong StripByteCount value (in case - * of single strip) in following cases: - * - it is equal to zero along with StripOffset; - * - it is larger than file itself (in case of uncompressed - * image); - * - it is smaller than the size of the bytes per row - * multiplied on the number of rows. The last case should - * not be checked in the case of writing new image, - * because we may do not know the exact strip size - * until the whole image will be written and directory - * dumped out. - */ - #define BYTECOUNTLOOKSBAD \ - ( (tif->tif_dir.td_stripbytecount[0] == 0 && tif->tif_dir.td_stripoffset[0] != 0) || \ - (tif->tif_dir.td_compression == COMPRESSION_NONE && \ - tif->tif_dir.td_stripbytecount[0] > TIFFGetFileSize(tif) - tif->tif_dir.td_stripoffset[0]) || \ - (tif->tif_mode == O_RDONLY && \ - tif->tif_dir.td_compression == COMPRESSION_NONE && \ - tif->tif_dir.td_stripbytecount[0] < TIFFScanlineSize64(tif) * tif->tif_dir.td_imagelength) ) - - } else if (tif->tif_dir.td_nstrips == 1 - && _TIFFFillStriles(tif) - && tif->tif_dir.td_stripoffset[0] != 0 - && BYTECOUNTLOOKSBAD) { - /* - * XXX: Plexus (and others) sometimes give a value of - * zero for a tag when they don't know what the - * correct value is! Try and handle the simple case - * of estimating the size of a one strip image. - */ - TIFFWarningExt(tif->tif_clientdata, module, - "Bogus \"StripByteCounts\" field, ignoring and calculating from imagelength"); - if(EstimateStripByteCounts(tif, dir, dircount) < 0) - goto bad; - -#if !defined(DEFER_STRILE_LOAD) - } else if (tif->tif_dir.td_planarconfig == PLANARCONFIG_CONTIG - && tif->tif_dir.td_nstrips > 2 - && tif->tif_dir.td_compression == COMPRESSION_NONE - && tif->tif_dir.td_stripbytecount[0] != tif->tif_dir.td_stripbytecount[1] - && tif->tif_dir.td_stripbytecount[0] != 0 - && tif->tif_dir.td_stripbytecount[1] != 0 ) { - /* - * XXX: Some vendors fill StripByteCount array with - * absolutely wrong values (it can be equal to - * StripOffset array, for example). Catch this case - * here. - * - * We avoid this check if deferring strile loading - * as it would always force us to load the strip/tile - * information. - */ - TIFFWarningExt(tif->tif_clientdata, module, - "Wrong \"StripByteCounts\" field, ignoring and calculating from imagelength"); - if (EstimateStripByteCounts(tif, dir, dircount) < 0) - goto bad; -#endif /* !defined(DEFER_STRILE_LOAD) */ - } - } - if (dir) - { - _TIFFfree(dir); - dir=NULL; - } - if (!TIFFFieldSet(tif, FIELD_MAXSAMPLEVALUE)) - { - if (tif->tif_dir.td_bitspersample>=16) - tif->tif_dir.td_maxsamplevalue=0xFFFF; - else - tif->tif_dir.td_maxsamplevalue = (uint16)((1L<tif_dir.td_bitspersample)-1); - } - /* - * XXX: We can optimize checking for the strip bounds using the sorted - * bytecounts array. See also comments for TIFFAppendToStrip() - * function in tif_write.c. - */ -#if !defined(DEFER_STRILE_LOAD) - if (tif->tif_dir.td_nstrips > 1) { - uint32 strip; - - tif->tif_dir.td_stripbytecountsorted = 1; - for (strip = 1; strip < tif->tif_dir.td_nstrips; strip++) { - if (tif->tif_dir.td_stripoffset[strip - 1] > - tif->tif_dir.td_stripoffset[strip]) { - tif->tif_dir.td_stripbytecountsorted = 0; - break; - } - } - } -#endif /* !defined(DEFER_STRILE_LOAD) */ - - /* - * An opportunity for compression mode dependent tag fixup - */ - (*tif->tif_fixuptags)(tif); - - /* - * Some manufacturers make life difficult by writing - * large amounts of uncompressed data as a single strip. - * This is contrary to the recommendations of the spec. - * The following makes an attempt at breaking such images - * into strips closer to the recommended 8k bytes. A - * side effect, however, is that the RowsPerStrip tag - * value may be changed. - */ - if ((tif->tif_dir.td_planarconfig==PLANARCONFIG_CONTIG)&& - (tif->tif_dir.td_nstrips==1)&& - (tif->tif_dir.td_compression==COMPRESSION_NONE)&& - ((tif->tif_flags&(TIFF_STRIPCHOP|TIFF_ISTILED))==TIFF_STRIPCHOP)) - { - if ( !_TIFFFillStriles(tif) || !tif->tif_dir.td_stripbytecount ) - return 0; - ChopUpSingleUncompressedStrip(tif); - } - - /* - * Clear the dirty directory flag. - */ - tif->tif_flags &= ~TIFF_DIRTYDIRECT; - tif->tif_flags &= ~TIFF_DIRTYSTRIP; - - /* - * Reinitialize i/o since we are starting on a new directory. - */ - tif->tif_row = (uint32) -1; - tif->tif_curstrip = (uint32) -1; - tif->tif_col = (uint32) -1; - tif->tif_curtile = (uint32) -1; - tif->tif_tilesize = (tmsize_t) -1; - - tif->tif_scanlinesize = TIFFScanlineSize(tif); - if (!tif->tif_scanlinesize) { - TIFFErrorExt(tif->tif_clientdata, module, - "Cannot handle zero scanline size"); - return (0); - } - - if (isTiled(tif)) { - tif->tif_tilesize = TIFFTileSize(tif); - if (!tif->tif_tilesize) { - TIFFErrorExt(tif->tif_clientdata, module, - "Cannot handle zero tile size"); - return (0); - } - } else { - if (!TIFFStripSize(tif)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Cannot handle zero strip size"); - return (0); - } - } - return (1); -bad: - if (dir) - _TIFFfree(dir); - return (0); -} - -static void -TIFFReadDirectoryCheckOrder(TIFF* tif, TIFFDirEntry* dir, uint16 dircount) -{ - static const char module[] = "TIFFReadDirectoryCheckOrder"; - uint16 m; - uint16 n; - TIFFDirEntry* o; - m=0; - for (n=0, o=dir; ntdir_tagtif_clientdata,module, - "Invalid TIFF directory; tags are not sorted in ascending order"); - break; - } - m=o->tdir_tag+1; - } -} - -static TIFFDirEntry* -TIFFReadDirectoryFindEntry(TIFF* tif, TIFFDirEntry* dir, uint16 dircount, uint16 tagid) -{ - TIFFDirEntry* m; - uint16 n; - (void) tif; - for (m=dir, n=0; ntdir_tag==tagid) - return(m); - } - return(0); -} - -static void -TIFFReadDirectoryFindFieldInfo(TIFF* tif, uint16 tagid, uint32* fii) -{ - int32 ma,mb,mc; - ma=-1; - mc=(int32)tif->tif_nfields; - while (1) - { - if (ma+1==mc) - { - *fii = FAILED_FII; - return; - } - mb=(ma+mc)/2; - if (tif->tif_fields[mb]->field_tag==(uint32)tagid) - break; - if (tif->tif_fields[mb]->field_tag<(uint32)tagid) - ma=mb; - else - mc=mb; - } - while (1) - { - if (mb==0) - break; - if (tif->tif_fields[mb-1]->field_tag!=(uint32)tagid) - break; - mb--; - } - *fii=mb; -} - -/* - * Read custom directory from the arbitarry offset. - * The code is very similar to TIFFReadDirectory(). - */ -int -TIFFReadCustomDirectory(TIFF* tif, toff_t diroff, - const TIFFFieldArray* infoarray) -{ - static const char module[] = "TIFFReadCustomDirectory"; - TIFFDirEntry* dir; - uint16 dircount; - TIFFDirEntry* dp; - uint16 di; - const TIFFField* fip; - uint32 fii; - _TIFFSetupFields(tif, infoarray); - dircount=TIFFFetchDirectory(tif,diroff,&dir,NULL); - if (!dircount) - { - TIFFErrorExt(tif->tif_clientdata,module, - "Failed to read custom directory at offset " TIFF_UINT64_FORMAT,diroff); - return 0; - } - TIFFFreeDirectory(tif); - _TIFFmemset(&tif->tif_dir, 0, sizeof(TIFFDirectory)); - TIFFReadDirectoryCheckOrder(tif,dir,dircount); - for (di=0, dp=dir; ditdir_tag,&fii); - if (fii == FAILED_FII) - { - TIFFWarningExt(tif->tif_clientdata, module, - "Unknown field with tag %d (0x%x) encountered", - dp->tdir_tag, dp->tdir_tag); - if (!_TIFFMergeFields(tif, _TIFFCreateAnonField(tif, - dp->tdir_tag, - (TIFFDataType) dp->tdir_type), - 1)) { - TIFFWarningExt(tif->tif_clientdata, module, - "Registering anonymous field with tag %d (0x%x) failed", - dp->tdir_tag, dp->tdir_tag); - dp->tdir_tag=IGNORE; - } else { - TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); - assert( fii != FAILED_FII ); - } - } - if (dp->tdir_tag!=IGNORE) - { - fip=tif->tif_fields[fii]; - if (fip->field_bit==FIELD_IGNORE) - dp->tdir_tag=IGNORE; - else - { - /* check data type */ - while ((fip->field_type!=TIFF_ANY)&&(fip->field_type!=dp->tdir_type)) - { - fii++; - if ((fii==tif->tif_nfields)|| - (tif->tif_fields[fii]->field_tag!=(uint32)dp->tdir_tag)) - { - fii=0xFFFF; - break; - } - fip=tif->tif_fields[fii]; - } - if (fii==0xFFFF) - { - TIFFWarningExt(tif->tif_clientdata, module, - "Wrong data type %d for \"%s\"; tag ignored", - dp->tdir_type,fip->field_name); - dp->tdir_tag=IGNORE; - } - else - { - /* check count if known in advance */ - if ((fip->field_readcount!=TIFF_VARIABLE)&& - (fip->field_readcount!=TIFF_VARIABLE2)) - { - uint32 expected; - if (fip->field_readcount==TIFF_SPP) - expected=(uint32)tif->tif_dir.td_samplesperpixel; - else - expected=(uint32)fip->field_readcount; - if (!CheckDirCount(tif,dp,expected)) - dp->tdir_tag=IGNORE; - } - } - } - switch (dp->tdir_tag) - { - case IGNORE: - break; - case EXIFTAG_SUBJECTDISTANCE: - (void) TIFFFetchSubjectDistance(tif,dp); - break; - default: - (void) TIFFFetchNormalTag(tif, dp, TRUE); - break; - } - } - } - if (dir) - _TIFFfree(dir); - return 1; -} - -/* - * EXIF is important special case of custom IFD, so we have a special - * function to read it. - */ -int -TIFFReadEXIFDirectory(TIFF* tif, toff_t diroff) -{ - const TIFFFieldArray* exifFieldArray; - exifFieldArray = _TIFFGetExifFields(); - return TIFFReadCustomDirectory(tif, diroff, exifFieldArray); -} - -static int -EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount) -{ - static const char module[] = "EstimateStripByteCounts"; - - TIFFDirEntry *dp; - TIFFDirectory *td = &tif->tif_dir; - uint32 strip; - - _TIFFFillStriles( tif ); - - if (td->td_stripbytecount) - _TIFFfree(td->td_stripbytecount); - td->td_stripbytecount = (uint64*) - _TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64), - "for \"StripByteCounts\" array"); - if( td->td_stripbytecount == NULL ) - return -1; - - if (td->td_compression != COMPRESSION_NONE) { - uint64 space; - uint64 filesize; - uint16 n; - filesize = TIFFGetFileSize(tif); - if (!(tif->tif_flags&TIFF_BIGTIFF)) - space=sizeof(TIFFHeaderClassic)+2+dircount*12+4; - else - space=sizeof(TIFFHeaderBig)+8+dircount*20+8; - /* calculate amount of space used by indirect values */ - for (dp = dir, n = dircount; n > 0; n--, dp++) - { - uint32 typewidth = TIFFDataWidth((TIFFDataType) dp->tdir_type); - uint64 datasize; - typewidth = TIFFDataWidth((TIFFDataType) dp->tdir_type); - if (typewidth == 0) { - TIFFErrorExt(tif->tif_clientdata, module, - "Cannot determine size of unknown tag type %d", - dp->tdir_type); - return -1; - } - datasize=(uint64)typewidth*dp->tdir_count; - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - if (datasize<=4) - datasize=0; - } - else - { - if (datasize<=8) - datasize=0; - } - space+=datasize; - } - space = filesize - space; - if (td->td_planarconfig == PLANARCONFIG_SEPARATE) - space /= td->td_samplesperpixel; - for (strip = 0; strip < td->td_nstrips; strip++) - td->td_stripbytecount[strip] = space; - /* - * This gross hack handles the case were the offset to - * the last strip is past the place where we think the strip - * should begin. Since a strip of data must be contiguous, - * it's safe to assume that we've overestimated the amount - * of data in the strip and trim this number back accordingly. - */ - strip--; - if (td->td_stripoffset[strip]+td->td_stripbytecount[strip] > filesize) - td->td_stripbytecount[strip] = filesize - td->td_stripoffset[strip]; - } else if (isTiled(tif)) { - uint64 bytespertile = TIFFTileSize64(tif); - - for (strip = 0; strip < td->td_nstrips; strip++) - td->td_stripbytecount[strip] = bytespertile; - } else { - uint64 rowbytes = TIFFScanlineSize64(tif); - uint32 rowsperstrip = td->td_imagelength/td->td_stripsperimage; - for (strip = 0; strip < td->td_nstrips; strip++) - td->td_stripbytecount[strip] = rowbytes * rowsperstrip; - } - TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS); - if (!TIFFFieldSet(tif, FIELD_ROWSPERSTRIP)) - td->td_rowsperstrip = td->td_imagelength; - return 1; -} - -static void -MissingRequired(TIFF* tif, const char* tagname) -{ - static const char module[] = "MissingRequired"; - - TIFFErrorExt(tif->tif_clientdata, module, - "TIFF directory is missing required \"%s\" field", - tagname); -} - -/* - * Check the directory offset against the list of already seen directory - * offsets. This is a trick to prevent IFD looping. The one can create TIFF - * file with looped directory pointers. We will maintain a list of already - * seen directories and check every IFD offset against that list. - */ -static int -TIFFCheckDirOffset(TIFF* tif, uint64 diroff) -{ - uint16 n; - - if (diroff == 0) /* no more directories */ - return 0; - - for (n = 0; n < tif->tif_dirnumber && tif->tif_dirlist; n++) { - if (tif->tif_dirlist[n] == diroff) - return 0; - } - - tif->tif_dirnumber++; - - if (tif->tif_dirnumber > tif->tif_dirlistsize) { - uint64* new_dirlist; - - /* - * XXX: Reduce memory allocation granularity of the dirlist - * array. - */ - new_dirlist = (uint64*)_TIFFCheckRealloc(tif, tif->tif_dirlist, - tif->tif_dirnumber, 2 * sizeof(uint64), "for IFD list"); - if (!new_dirlist) - return 0; - tif->tif_dirlistsize = 2 * tif->tif_dirnumber; - tif->tif_dirlist = new_dirlist; - } - - tif->tif_dirlist[tif->tif_dirnumber - 1] = diroff; - - return 1; -} - -/* - * Check the count field of a directory entry against a known value. The - * caller is expected to skip/ignore the tag if there is a mismatch. - */ -static int -CheckDirCount(TIFF* tif, TIFFDirEntry* dir, uint32 count) -{ - if ((uint64)count > dir->tdir_count) { - const TIFFField* fip = TIFFFieldWithTag(tif, dir->tdir_tag); - TIFFWarningExt(tif->tif_clientdata, tif->tif_name, - "incorrect count for field \"%s\" (" TIFF_UINT64_FORMAT ", expecting %u); tag ignored", - fip ? fip->field_name : "unknown tagname", - dir->tdir_count, count); - return (0); - } else if ((uint64)count < dir->tdir_count) { - const TIFFField* fip = TIFFFieldWithTag(tif, dir->tdir_tag); - TIFFWarningExt(tif->tif_clientdata, tif->tif_name, - "incorrect count for field \"%s\" (" TIFF_UINT64_FORMAT ", expecting %u); tag trimmed", - fip ? fip->field_name : "unknown tagname", - dir->tdir_count, count); - dir->tdir_count = count; - return (1); - } - return (1); -} - -/* - * Read IFD structure from the specified offset. If the pointer to - * nextdiroff variable has been specified, read it too. Function returns a - * number of fields in the directory or 0 if failed. - */ -static uint16 -TIFFFetchDirectory(TIFF* tif, uint64 diroff, TIFFDirEntry** pdir, - uint64 *nextdiroff) -{ - static const char module[] = "TIFFFetchDirectory"; - - void* origdir; - uint16 dircount16; - uint32 dirsize; - TIFFDirEntry* dir; - uint8* ma; - TIFFDirEntry* mb; - uint16 n; - - assert(pdir); - - tif->tif_diroff = diroff; - if (nextdiroff) - *nextdiroff = 0; - if (!isMapped(tif)) { - if (!SeekOK(tif, tif->tif_diroff)) { - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Seek error accessing TIFF directory", - tif->tif_name); - return 0; - } - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - if (!ReadOK(tif, &dircount16, sizeof (uint16))) { - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Can not read TIFF directory count", - tif->tif_name); - return 0; - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabShort(&dircount16); - if (dircount16>4096) - { - TIFFErrorExt(tif->tif_clientdata, module, - "Sanity check on directory count failed, this is probably not a valid IFD offset"); - return 0; - } - dirsize = 12; - } else { - uint64 dircount64; - if (!ReadOK(tif, &dircount64, sizeof (uint64))) { - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Can not read TIFF directory count", - tif->tif_name); - return 0; - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong8(&dircount64); - if (dircount64>4096) - { - TIFFErrorExt(tif->tif_clientdata, module, - "Sanity check on directory count failed, this is probably not a valid IFD offset"); - return 0; - } - dircount16 = (uint16)dircount64; - dirsize = 20; - } - origdir = _TIFFCheckMalloc(tif, dircount16, - dirsize, "to read TIFF directory"); - if (origdir == NULL) - return 0; - if (!ReadOK(tif, origdir, (tmsize_t)(dircount16*dirsize))) { - TIFFErrorExt(tif->tif_clientdata, module, - "%.100s: Can not read TIFF directory", - tif->tif_name); - _TIFFfree(origdir); - return 0; - } - /* - * Read offset to next directory for sequential scans if - * needed. - */ - if (nextdiroff) - { - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - uint32 nextdiroff32; - if (!ReadOK(tif, &nextdiroff32, sizeof(uint32))) - nextdiroff32 = 0; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(&nextdiroff32); - *nextdiroff=nextdiroff32; - } else { - if (!ReadOK(tif, nextdiroff, sizeof(uint64))) - *nextdiroff = 0; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8(nextdiroff); - } - } - } else { - tmsize_t m; - tmsize_t off = (tmsize_t) tif->tif_diroff; - if ((uint64)off!=tif->tif_diroff) - { - TIFFErrorExt(tif->tif_clientdata,module,"Can not read TIFF directory count"); - return(0); - } - - /* - * Check for integer overflow when validating the dir_off, - * otherwise a very high offset may cause an OOB read and - * crash the client. Make two comparisons instead of - * - * off + sizeof(uint16) > tif->tif_size - * - * to avoid overflow. - */ - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - m=off+sizeof(uint16); - if ((mtif->tif_size)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Can not read TIFF directory count"); - return 0; - } else { - _TIFFmemcpy(&dircount16, tif->tif_base + off, - sizeof(uint16)); - } - off += sizeof (uint16); - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabShort(&dircount16); - if (dircount16>4096) - { - TIFFErrorExt(tif->tif_clientdata, module, - "Sanity check on directory count failed, this is probably not a valid IFD offset"); - return 0; - } - dirsize = 12; - } - else - { - tmsize_t m; - uint64 dircount64; - m=off+sizeof(uint64); - if ((mtif->tif_size)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Can not read TIFF directory count"); - return 0; - } else { - _TIFFmemcpy(&dircount64, tif->tif_base + off, - sizeof(uint64)); - } - off += sizeof (uint64); - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong8(&dircount64); - if (dircount64>4096) - { - TIFFErrorExt(tif->tif_clientdata, module, - "Sanity check on directory count failed, this is probably not a valid IFD offset"); - return 0; - } - dircount16 = (uint16)dircount64; - dirsize = 20; - } - if (dircount16 == 0 ) - { - TIFFErrorExt(tif->tif_clientdata, module, - "Sanity check on directory count failed, zero tag directories not supported"); - return 0; - } - origdir = _TIFFCheckMalloc(tif, dircount16, - dirsize, - "to read TIFF directory"); - if (origdir == NULL) - return 0; - m=off+dircount16*dirsize; - if ((mtif->tif_size)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Can not read TIFF directory"); - _TIFFfree(origdir); - return 0; - } else { - _TIFFmemcpy(origdir, tif->tif_base + off, - dircount16 * dirsize); - } - if (nextdiroff) { - off += dircount16 * dirsize; - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - uint32 nextdiroff32; - m=off+sizeof(uint32); - if ((mtif->tif_size)) - nextdiroff32 = 0; - else - _TIFFmemcpy(&nextdiroff32, tif->tif_base + off, - sizeof (uint32)); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(&nextdiroff32); - *nextdiroff = nextdiroff32; - } - else - { - m=off+sizeof(uint64); - if ((mtif->tif_size)) - *nextdiroff = 0; - else - _TIFFmemcpy(nextdiroff, tif->tif_base + off, - sizeof (uint64)); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8(nextdiroff); - } - } - } - dir = (TIFFDirEntry*)_TIFFCheckMalloc(tif, dircount16, - sizeof(TIFFDirEntry), - "to read TIFF directory"); - if (dir==0) - { - _TIFFfree(origdir); - return 0; - } - ma=(uint8*)origdir; - mb=dir; - for (n=0; ntif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)ma); - mb->tdir_tag=*(uint16*)ma; - ma+=sizeof(uint16); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)ma); - mb->tdir_type=*(uint16*)ma; - ma+=sizeof(uint16); - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)ma); - mb->tdir_count=(uint64)(*(uint32*)ma); - ma+=sizeof(uint32); - *(uint32*)(&mb->tdir_offset)=*(uint32*)ma; - ma+=sizeof(uint32); - } - else - { - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)ma); - mb->tdir_count=TIFFReadUInt64(ma); - ma+=sizeof(uint64); - mb->tdir_offset.toff_long8=TIFFReadUInt64(ma); - ma+=sizeof(uint64); - } - mb++; - } - _TIFFfree(origdir); - *pdir = dir; - return dircount16; -} - -/* - * Fetch a tag that is not handled by special case code. - */ -static int -TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover) -{ - static const char module[] = "TIFFFetchNormalTag"; - enum TIFFReadDirEntryErr err; - uint32 fii; - const TIFFField* fip = NULL; - TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); - if( fii == FAILED_FII ) - { - TIFFErrorExt(tif->tif_clientdata, "TIFFFetchNormalTag", - "No definition found for tag %d", - dp->tdir_tag); - return 0; - } - fip=tif->tif_fields[fii]; - assert(fip->set_field_type!=TIFF_SETGET_OTHER); /* if so, we shouldn't arrive here but deal with this in specialized code */ - assert(fip->set_field_type!=TIFF_SETGET_INT); /* if so, we shouldn't arrive here as this is only the case for pseudo-tags */ - err=TIFFReadDirEntryErrOk; - switch (fip->set_field_type) - { - case TIFF_SETGET_UNDEFINED: - break; - case TIFF_SETGET_ASCII: - { - uint8* data; - assert(fip->field_passcount==0); - err=TIFFReadDirEntryByteArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - uint8* ma; - uint32 mb; - int n; - ma=data; - mb=0; - while (mb<(uint32)dp->tdir_count) - { - if (*ma==0) - break; - ma++; - mb++; - } - if (mb+1<(uint32)dp->tdir_count) - TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" contains null byte in value; value incorrectly truncated during reading due to implementation limitations",fip->field_name); - else if (mb+1>(uint32)dp->tdir_count) - { - uint8* o; - TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte",fip->field_name); - if ((uint32)dp->tdir_count+1!=dp->tdir_count+1) - o=NULL; - else - o=_TIFFmalloc((uint32)dp->tdir_count+1); - if (o==NULL) - { - if (data!=NULL) - _TIFFfree(data); - return(0); - } - _TIFFmemcpy(o,data,(uint32)dp->tdir_count); - o[(uint32)dp->tdir_count]=0; - if (data!=0) - _TIFFfree(data); - data=o; - } - n=TIFFSetField(tif,dp->tdir_tag,data); - if (data!=0) - _TIFFfree(data); - if (!n) - return(0); - } - } - break; - case TIFF_SETGET_UINT8: - { - uint8 data=0; - assert(fip->field_readcount==1); - assert(fip->field_passcount==0); - err=TIFFReadDirEntryByte(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - if (!TIFFSetField(tif,dp->tdir_tag,data)) - return(0); - } - } - break; - case TIFF_SETGET_UINT16: - { - uint16 data; - assert(fip->field_readcount==1); - assert(fip->field_passcount==0); - err=TIFFReadDirEntryShort(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - if (!TIFFSetField(tif,dp->tdir_tag,data)) - return(0); - } - } - break; - case TIFF_SETGET_UINT32: - { - uint32 data; - assert(fip->field_readcount==1); - assert(fip->field_passcount==0); - err=TIFFReadDirEntryLong(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - if (!TIFFSetField(tif,dp->tdir_tag,data)) - return(0); - } - } - break; - case TIFF_SETGET_UINT64: - { - uint64 data; - assert(fip->field_readcount==1); - assert(fip->field_passcount==0); - err=TIFFReadDirEntryLong8(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - if (!TIFFSetField(tif,dp->tdir_tag,data)) - return(0); - } - } - break; - case TIFF_SETGET_FLOAT: - { - float data; - assert(fip->field_readcount==1); - assert(fip->field_passcount==0); - err=TIFFReadDirEntryFloat(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - if (!TIFFSetField(tif,dp->tdir_tag,data)) - return(0); - } - } - break; - case TIFF_SETGET_DOUBLE: - { - double data; - assert(fip->field_readcount==1); - assert(fip->field_passcount==0); - err=TIFFReadDirEntryDouble(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - if (!TIFFSetField(tif,dp->tdir_tag,data)) - return(0); - } - } - break; - case TIFF_SETGET_IFD8: - { - uint64 data; - assert(fip->field_readcount==1); - assert(fip->field_passcount==0); - err=TIFFReadDirEntryIfd8(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - if (!TIFFSetField(tif,dp->tdir_tag,data)) - return(0); - } - } - break; - case TIFF_SETGET_UINT16_PAIR: - { - uint16* data; - assert(fip->field_readcount==2); - assert(fip->field_passcount==0); - if (dp->tdir_count!=2) { - TIFFWarningExt(tif->tif_clientdata,module, - "incorrect count for field \"%s\", expected 2, got %d", - fip->field_name,(int)dp->tdir_count); - return(0); - } - err=TIFFReadDirEntryShortArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,data[0],data[1]); - _TIFFfree(data); - if (!m) - return(0); - } - } - break; - case TIFF_SETGET_C0_UINT8: - { - uint8* data; - assert(fip->field_readcount>=1); - assert(fip->field_passcount==0); - if (dp->tdir_count!=(uint64)fip->field_readcount) { - TIFFWarningExt(tif->tif_clientdata,module, - "incorrect count for field \"%s\", expected %d, got %d", - fip->field_name,(int) fip->field_readcount, (int)dp->tdir_count); - return 0; - } - else - { - err=TIFFReadDirEntryByteArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - } - break; - case TIFF_SETGET_C0_UINT16: - { - uint16* data; - assert(fip->field_readcount>=1); - assert(fip->field_passcount==0); - if (dp->tdir_count!=(uint64)fip->field_readcount) - /* corrupt file */; - else - { - err=TIFFReadDirEntryShortArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - } - break; - case TIFF_SETGET_C0_UINT32: - { - uint32* data; - assert(fip->field_readcount>=1); - assert(fip->field_passcount==0); - if (dp->tdir_count!=(uint64)fip->field_readcount) - /* corrupt file */; - else - { - err=TIFFReadDirEntryLongArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - } - break; - case TIFF_SETGET_C0_FLOAT: - { - float* data; - assert(fip->field_readcount>=1); - assert(fip->field_passcount==0); - if (dp->tdir_count!=(uint64)fip->field_readcount) - /* corrupt file */; - else - { - err=TIFFReadDirEntryFloatArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - } - break; - case TIFF_SETGET_C16_ASCII: - { - uint8* data; - assert(fip->field_readcount==TIFF_VARIABLE); - assert(fip->field_passcount==1); - if (dp->tdir_count>0xFFFF) - err=TIFFReadDirEntryErrCount; - else - { - err=TIFFReadDirEntryByteArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - } - break; - case TIFF_SETGET_C16_UINT8: - { - uint8* data; - assert(fip->field_readcount==TIFF_VARIABLE); - assert(fip->field_passcount==1); - if (dp->tdir_count>0xFFFF) - err=TIFFReadDirEntryErrCount; - else - { - err=TIFFReadDirEntryByteArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - } - break; - case TIFF_SETGET_C16_UINT16: - { - uint16* data; - assert(fip->field_readcount==TIFF_VARIABLE); - assert(fip->field_passcount==1); - if (dp->tdir_count>0xFFFF) - err=TIFFReadDirEntryErrCount; - else - { - err=TIFFReadDirEntryShortArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - } - break; - case TIFF_SETGET_C16_UINT32: - { - uint32* data; - assert(fip->field_readcount==TIFF_VARIABLE); - assert(fip->field_passcount==1); - if (dp->tdir_count>0xFFFF) - err=TIFFReadDirEntryErrCount; - else - { - err=TIFFReadDirEntryLongArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - } - break; - case TIFF_SETGET_C16_UINT64: - { - uint64* data; - assert(fip->field_readcount==TIFF_VARIABLE); - assert(fip->field_passcount==1); - if (dp->tdir_count>0xFFFF) - err=TIFFReadDirEntryErrCount; - else - { - err=TIFFReadDirEntryLong8Array(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - } - break; - case TIFF_SETGET_C16_FLOAT: - { - float* data; - assert(fip->field_readcount==TIFF_VARIABLE); - assert(fip->field_passcount==1); - if (dp->tdir_count>0xFFFF) - err=TIFFReadDirEntryErrCount; - else - { - err=TIFFReadDirEntryFloatArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - } - break; - case TIFF_SETGET_C16_DOUBLE: - { - double* data; - assert(fip->field_readcount==TIFF_VARIABLE); - assert(fip->field_passcount==1); - if (dp->tdir_count>0xFFFF) - err=TIFFReadDirEntryErrCount; - else - { - err=TIFFReadDirEntryDoubleArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - } - break; - case TIFF_SETGET_C16_IFD8: - { - uint64* data; - assert(fip->field_readcount==TIFF_VARIABLE); - assert(fip->field_passcount==1); - if (dp->tdir_count>0xFFFF) - err=TIFFReadDirEntryErrCount; - else - { - err=TIFFReadDirEntryIfd8Array(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - } - break; - case TIFF_SETGET_C32_ASCII: - { - uint8* data; - assert(fip->field_readcount==TIFF_VARIABLE2); - assert(fip->field_passcount==1); - err=TIFFReadDirEntryByteArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - break; - case TIFF_SETGET_C32_UINT8: - { - uint8* data; - assert(fip->field_readcount==TIFF_VARIABLE2); - assert(fip->field_passcount==1); - err=TIFFReadDirEntryByteArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - break; - case TIFF_SETGET_C32_SINT8: - { - int8* data = NULL; - assert(fip->field_readcount==TIFF_VARIABLE2); - assert(fip->field_passcount==1); - err=TIFFReadDirEntrySbyteArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - break; - case TIFF_SETGET_C32_UINT16: - { - uint16* data; - assert(fip->field_readcount==TIFF_VARIABLE2); - assert(fip->field_passcount==1); - err=TIFFReadDirEntryShortArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - break; - case TIFF_SETGET_C32_SINT16: - { - int16* data = NULL; - assert(fip->field_readcount==TIFF_VARIABLE2); - assert(fip->field_passcount==1); - err=TIFFReadDirEntrySshortArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - break; - case TIFF_SETGET_C32_UINT32: - { - uint32* data; - assert(fip->field_readcount==TIFF_VARIABLE2); - assert(fip->field_passcount==1); - err=TIFFReadDirEntryLongArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - break; - case TIFF_SETGET_C32_SINT32: - { - int32* data = NULL; - assert(fip->field_readcount==TIFF_VARIABLE2); - assert(fip->field_passcount==1); - err=TIFFReadDirEntrySlongArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - break; - case TIFF_SETGET_C32_UINT64: - { - uint64* data; - assert(fip->field_readcount==TIFF_VARIABLE2); - assert(fip->field_passcount==1); - err=TIFFReadDirEntryLong8Array(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - break; - case TIFF_SETGET_C32_SINT64: - { - int64* data = NULL; - assert(fip->field_readcount==TIFF_VARIABLE2); - assert(fip->field_passcount==1); - err=TIFFReadDirEntrySlong8Array(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - break; - case TIFF_SETGET_C32_FLOAT: - { - float* data; - assert(fip->field_readcount==TIFF_VARIABLE2); - assert(fip->field_passcount==1); - err=TIFFReadDirEntryFloatArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - break; - case TIFF_SETGET_C32_DOUBLE: - { - double* data; - assert(fip->field_readcount==TIFF_VARIABLE2); - assert(fip->field_passcount==1); - err=TIFFReadDirEntryDoubleArray(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - break; - case TIFF_SETGET_C32_IFD8: - { - uint64* data; - assert(fip->field_readcount==TIFF_VARIABLE2); - assert(fip->field_passcount==1); - err=TIFFReadDirEntryIfd8Array(tif,dp,&data); - if (err==TIFFReadDirEntryErrOk) - { - int m; - m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); - if (!m) - return(0); - } - } - break; - default: - assert(0); /* we should never get here */ - break; - } - if (err!=TIFFReadDirEntryErrOk) - { - TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",recover); - return(0); - } - return(1); -} - -/* - * Fetch a set of offsets or lengths. - * While this routine says "strips", in fact it's also used for tiles. - */ -static int -TIFFFetchStripThing(TIFF* tif, TIFFDirEntry* dir, uint32 nstrips, uint64** lpp) -{ - static const char module[] = "TIFFFetchStripThing"; - enum TIFFReadDirEntryErr err; - uint64* data; - err=TIFFReadDirEntryLong8Array(tif,dir,&data); - if (err!=TIFFReadDirEntryErrOk) - { - const TIFFField* fip = TIFFFieldWithTag(tif,dir->tdir_tag); - TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0); - return(0); - } - if (dir->tdir_count!=(uint64)nstrips) - { - uint64* resizeddata; - resizeddata=(uint64*)_TIFFCheckMalloc(tif,nstrips,sizeof(uint64),"for strip array"); - if (resizeddata==0) { - _TIFFfree(data); - return(0); - } - if (dir->tdir_count<(uint64)nstrips) - { - _TIFFmemcpy(resizeddata,data,(uint32)dir->tdir_count*sizeof(uint64)); - _TIFFmemset(resizeddata+(uint32)dir->tdir_count,0,(nstrips-(uint32)dir->tdir_count)*sizeof(uint64)); - } - else - _TIFFmemcpy(resizeddata,data,nstrips*sizeof(uint64)); - _TIFFfree(data); - data=resizeddata; - } - *lpp=data; - return(1); -} - -/* - * Fetch and set the SubjectDistance EXIF tag. - */ -static int -TIFFFetchSubjectDistance(TIFF* tif, TIFFDirEntry* dir) -{ - static const char module[] = "TIFFFetchSubjectDistance"; - enum TIFFReadDirEntryErr err; - UInt64Aligned_t m; - m.l=0; - assert(sizeof(double)==8); - assert(sizeof(uint64)==8); - assert(sizeof(uint32)==4); - if (dir->tdir_count!=1) - err=TIFFReadDirEntryErrCount; - else if (dir->tdir_type!=TIFF_RATIONAL) - err=TIFFReadDirEntryErrType; - else - { - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - uint32 offset; - offset=*(uint32*)(&dir->tdir_offset); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(&offset); - err=TIFFReadDirEntryData(tif,offset,8,m.i); - } - else - { - m.l=dir->tdir_offset.toff_long8; - err=TIFFReadDirEntryErrOk; - } - } - if (err==TIFFReadDirEntryErrOk) - { - double n; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong(m.i,2); - if (m.i[0]==0) - n=0.0; - else if (m.i[0]==0xFFFFFFFF) - /* - * XXX: Numerator 0xFFFFFFFF means that we have infinite - * distance. Indicate that with a negative floating point - * SubjectDistance value. - */ - n=-1.0; - else - n=(double)m.i[0]/(double)m.i[1]; - return(TIFFSetField(tif,dir->tdir_tag,n)); - } - else - { - TIFFReadDirEntryOutputErr(tif,err,module,"SubjectDistance",TRUE); - return(0); - } -} - -/* - * Replace a single strip (tile) of uncompressed data by multiple strips - * (tiles), each approximately STRIP_SIZE_DEFAULT bytes. This is useful for - * dealing with large images or for dealing with machines with a limited - * amount memory. - */ -static void -ChopUpSingleUncompressedStrip(TIFF* tif) -{ - register TIFFDirectory *td = &tif->tif_dir; - uint64 bytecount; - uint64 offset; - uint32 rowblock; - uint64 rowblockbytes; - uint64 stripbytes; - uint32 strip; - uint64 nstrips64; - uint32 nstrips32; - uint32 rowsperstrip; - uint64* newcounts; - uint64* newoffsets; - - bytecount = td->td_stripbytecount[0]; - offset = td->td_stripoffset[0]; - assert(td->td_planarconfig == PLANARCONFIG_CONTIG); - if ((td->td_photometric == PHOTOMETRIC_YCBCR)&& - (!isUpSampled(tif))) - rowblock = td->td_ycbcrsubsampling[1]; - else - rowblock = 1; - rowblockbytes = TIFFVTileSize64(tif, rowblock); - /* - * Make the rows hold at least one scanline, but fill specified amount - * of data if possible. - */ - if (rowblockbytes > STRIP_SIZE_DEFAULT) { - stripbytes = rowblockbytes; - rowsperstrip = rowblock; - } else if (rowblockbytes > 0 ) { - uint32 rowblocksperstrip; - rowblocksperstrip = (uint32) (STRIP_SIZE_DEFAULT / rowblockbytes); - rowsperstrip = rowblocksperstrip * rowblock; - stripbytes = rowblocksperstrip * rowblockbytes; - } - else - return; - - /* - * never increase the number of strips in an image - */ - if (rowsperstrip >= td->td_rowsperstrip) - return; - nstrips64 = TIFFhowmany_64(bytecount, stripbytes); - if ((nstrips64==0)||(nstrips64>0xFFFFFFFF)) /* something is wonky, do nothing. */ - return; - nstrips32 = (uint32)nstrips64; - - newcounts = (uint64*) _TIFFCheckMalloc(tif, nstrips32, sizeof (uint64), - "for chopped \"StripByteCounts\" array"); - newoffsets = (uint64*) _TIFFCheckMalloc(tif, nstrips32, sizeof (uint64), - "for chopped \"StripOffsets\" array"); - if (newcounts == NULL || newoffsets == NULL) { - /* - * Unable to allocate new strip information, give up and use - * the original one strip information. - */ - if (newcounts != NULL) - _TIFFfree(newcounts); - if (newoffsets != NULL) - _TIFFfree(newoffsets); - return; - } - /* - * Fill the strip information arrays with new bytecounts and offsets - * that reflect the broken-up format. - */ - for (strip = 0; strip < nstrips32; strip++) { - if (stripbytes > bytecount) - stripbytes = bytecount; - newcounts[strip] = stripbytes; - newoffsets[strip] = offset; - offset += stripbytes; - bytecount -= stripbytes; - } - /* - * Replace old single strip info with multi-strip info. - */ - td->td_stripsperimage = td->td_nstrips = nstrips32; - TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip); - - _TIFFfree(td->td_stripbytecount); - _TIFFfree(td->td_stripoffset); - td->td_stripbytecount = newcounts; - td->td_stripoffset = newoffsets; - td->td_stripbytecountsorted = 1; -} - -int _TIFFFillStriles( TIFF *tif ) -{ -#if defined(DEFER_STRILE_LOAD) - register TIFFDirectory *td = &tif->tif_dir; - int return_value = 1; - - if( td->td_stripoffset != NULL ) - return 1; - - if( td->td_stripoffset_entry.tdir_count == 0 ) - return 0; - - if (!TIFFFetchStripThing(tif,&(td->td_stripoffset_entry), - td->td_nstrips,&td->td_stripoffset)) - { - return_value = 0; - } - - if (!TIFFFetchStripThing(tif,&(td->td_stripbytecount_entry), - td->td_nstrips,&td->td_stripbytecount)) - { - return_value = 0; - } - - _TIFFmemset( &(td->td_stripoffset_entry), 0, sizeof(TIFFDirEntry)); - _TIFFmemset( &(td->td_stripbytecount_entry), 0, sizeof(TIFFDirEntry)); - - if (tif->tif_dir.td_nstrips > 1 && return_value == 1 ) { - uint32 strip; - - tif->tif_dir.td_stripbytecountsorted = 1; - for (strip = 1; strip < tif->tif_dir.td_nstrips; strip++) { - if (tif->tif_dir.td_stripoffset[strip - 1] > - tif->tif_dir.td_stripoffset[strip]) { - tif->tif_dir.td_stripbytecountsorted = 0; - break; - } - } - } - - return return_value; -#else /* !defined(DEFER_STRILE_LOAD) */ - (void) tif; - return 1; -#endif -} - - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_dirread.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * + * Directory Read Support Routines. + */ + +/* Suggested pending improvements: + * - add a field 'ignore' to the TIFFDirEntry structure, to flag status, + * eliminating current use of the IGNORE value, and therefore eliminating + * current irrational behaviour on tags with tag id code 0 + * - add a field 'field_info' to the TIFFDirEntry structure, and set that with + * the pointer to the appropriate TIFFField structure early on in + * TIFFReadDirectory, so as to eliminate current possibly repetitive lookup. + */ + +#include "tiffiop.h" + +#define IGNORE 0 /* tag placeholder used below */ +#define FAILED_FII ((uint32) -1) + +#ifdef HAVE_IEEEFP +# define TIFFCvtIEEEFloatToNative(tif, n, fp) +# define TIFFCvtIEEEDoubleToNative(tif, n, dp) +#else +extern void TIFFCvtIEEEFloatToNative(TIFF*, uint32, float*); +extern void TIFFCvtIEEEDoubleToNative(TIFF*, uint32, double*); +#endif + +enum TIFFReadDirEntryErr { + TIFFReadDirEntryErrOk = 0, + TIFFReadDirEntryErrCount = 1, + TIFFReadDirEntryErrType = 2, + TIFFReadDirEntryErrIo = 3, + TIFFReadDirEntryErrRange = 4, + TIFFReadDirEntryErrPsdif = 5, + TIFFReadDirEntryErrSizesan = 6, + TIFFReadDirEntryErrAlloc = 7, +}; + +static enum TIFFReadDirEntryErr TIFFReadDirEntryByte(TIFF* tif, TIFFDirEntry* direntry, uint8* value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryShort(TIFF* tif, TIFFDirEntry* direntry, uint16* value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryLong(TIFF* tif, TIFFDirEntry* direntry, uint32* value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8(TIFF* tif, TIFFDirEntry* direntry, uint64* value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryFloat(TIFF* tif, TIFFDirEntry* direntry, float* value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryDouble(TIFF* tif, TIFFDirEntry* direntry, double* value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8(TIFF* tif, TIFFDirEntry* direntry, uint64* value); + +static enum TIFFReadDirEntryErr TIFFReadDirEntryArray(TIFF* tif, TIFFDirEntry* direntry, uint32* count, uint32 desttypesize, void** value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryByteArray(TIFF* tif, TIFFDirEntry* direntry, uint8** value); +static enum TIFFReadDirEntryErr TIFFReadDirEntrySbyteArray(TIFF* tif, TIFFDirEntry* direntry, int8** value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryShortArray(TIFF* tif, TIFFDirEntry* direntry, uint16** value); +static enum TIFFReadDirEntryErr TIFFReadDirEntrySshortArray(TIFF* tif, TIFFDirEntry* direntry, int16** value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryLongArray(TIFF* tif, TIFFDirEntry* direntry, uint32** value); +static enum TIFFReadDirEntryErr TIFFReadDirEntrySlongArray(TIFF* tif, TIFFDirEntry* direntry, int32** value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8Array(TIFF* tif, TIFFDirEntry* direntry, uint64** value); +static enum TIFFReadDirEntryErr TIFFReadDirEntrySlong8Array(TIFF* tif, TIFFDirEntry* direntry, int64** value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryFloatArray(TIFF* tif, TIFFDirEntry* direntry, float** value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryDoubleArray(TIFF* tif, TIFFDirEntry* direntry, double** value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8Array(TIFF* tif, TIFFDirEntry* direntry, uint64** value); + +static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleShort(TIFF* tif, TIFFDirEntry* direntry, uint16* value); +#if 0 +static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleDouble(TIFF* tif, TIFFDirEntry* direntry, double* value); +#endif + +static void TIFFReadDirEntryCheckedByte(TIFF* tif, TIFFDirEntry* direntry, uint8* value); +static void TIFFReadDirEntryCheckedSbyte(TIFF* tif, TIFFDirEntry* direntry, int8* value); +static void TIFFReadDirEntryCheckedShort(TIFF* tif, TIFFDirEntry* direntry, uint16* value); +static void TIFFReadDirEntryCheckedSshort(TIFF* tif, TIFFDirEntry* direntry, int16* value); +static void TIFFReadDirEntryCheckedLong(TIFF* tif, TIFFDirEntry* direntry, uint32* value); +static void TIFFReadDirEntryCheckedSlong(TIFF* tif, TIFFDirEntry* direntry, int32* value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedLong8(TIFF* tif, TIFFDirEntry* direntry, uint64* value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSlong8(TIFF* tif, TIFFDirEntry* direntry, int64* value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedRational(TIFF* tif, TIFFDirEntry* direntry, double* value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSrational(TIFF* tif, TIFFDirEntry* direntry, double* value); +static void TIFFReadDirEntryCheckedFloat(TIFF* tif, TIFFDirEntry* direntry, float* value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedDouble(TIFF* tif, TIFFDirEntry* direntry, double* value); + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSbyte(int8 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteShort(uint16 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSshort(int16 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong(uint32 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong(int32 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong8(uint64 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong8(int64 value); + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteByte(uint8 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteShort(uint16 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSshort(int16 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteLong(uint32 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSlong(int32 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteLong8(uint64 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSlong8(int64 value); + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSbyte(int8 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSshort(int16 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortLong(uint32 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSlong(int32 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortLong8(uint64 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSlong8(int64 value); + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortShort(uint16 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortLong(uint32 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortSlong(int32 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortLong8(uint64 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortSlong8(int64 value); + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSbyte(int8 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSshort(int16 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSlong(int32 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongLong8(uint64 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSlong8(int64 value); + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlongLong(uint32 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlongLong8(uint64 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlongSlong8(int64 value); + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Sbyte(int8 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Sshort(int16 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Slong(int32 value); +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Slong8(int64 value); + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlong8Long8(uint64 value); + +static enum TIFFReadDirEntryErr TIFFReadDirEntryData(TIFF* tif, uint64 offset, tmsize_t size, void* dest); +static void TIFFReadDirEntryOutputErr(TIFF* tif, enum TIFFReadDirEntryErr err, const char* module, const char* tagname, int recover); + +static void TIFFReadDirectoryCheckOrder(TIFF* tif, TIFFDirEntry* dir, uint16 dircount); +static TIFFDirEntry* TIFFReadDirectoryFindEntry(TIFF* tif, TIFFDirEntry* dir, uint16 dircount, uint16 tagid); +static void TIFFReadDirectoryFindFieldInfo(TIFF* tif, uint16 tagid, uint32* fii); + +static int EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount); +static void MissingRequired(TIFF*, const char*); +static int TIFFCheckDirOffset(TIFF* tif, uint64 diroff); +static int CheckDirCount(TIFF*, TIFFDirEntry*, uint32); +static uint16 TIFFFetchDirectory(TIFF* tif, uint64 diroff, TIFFDirEntry** pdir, uint64* nextdiroff); +static int TIFFFetchNormalTag(TIFF*, TIFFDirEntry*, int recover); +static int TIFFFetchStripThing(TIFF* tif, TIFFDirEntry* dir, uint32 nstrips, uint64** lpp); +static int TIFFFetchSubjectDistance(TIFF*, TIFFDirEntry*); +static void ChopUpSingleUncompressedStrip(TIFF*); +static uint64 TIFFReadUInt64(const uint8 *value); + +typedef union _UInt64Aligned_t +{ + double d; + uint64 l; + uint32 i[2]; + uint16 s[4]; + uint8 c[8]; +} UInt64Aligned_t; + +/* + Unaligned safe copy of a uint64 value from an octet array. +*/ +static uint64 TIFFReadUInt64(const uint8 *value) +{ + UInt64Aligned_t result; + + result.c[0]=value[0]; + result.c[1]=value[1]; + result.c[2]=value[2]; + result.c[3]=value[3]; + result.c[4]=value[4]; + result.c[5]=value[5]; + result.c[6]=value[6]; + result.c[7]=value[7]; + + return result.l; +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryByte(TIFF* tif, TIFFDirEntry* direntry, uint8* value) +{ + enum TIFFReadDirEntryErr err; + if (direntry->tdir_count!=1) + return(TIFFReadDirEntryErrCount); + switch (direntry->tdir_type) + { + case TIFF_BYTE: + TIFFReadDirEntryCheckedByte(tif,direntry,value); + return(TIFFReadDirEntryErrOk); + case TIFF_SBYTE: + { + int8 m; + TIFFReadDirEntryCheckedSbyte(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeByteSbyte(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint8)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SHORT: + { + uint16 m; + TIFFReadDirEntryCheckedShort(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeByteShort(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint8)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SSHORT: + { + int16 m; + TIFFReadDirEntryCheckedSshort(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeByteSshort(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint8)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_LONG: + { + uint32 m; + TIFFReadDirEntryCheckedLong(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeByteLong(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint8)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SLONG: + { + int32 m; + TIFFReadDirEntryCheckedSlong(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeByteSlong(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint8)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_LONG8: + { + uint64 m; + err=TIFFReadDirEntryCheckedLong8(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + err=TIFFReadDirEntryCheckRangeByteLong8(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint8)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SLONG8: + { + int64 m; + err=TIFFReadDirEntryCheckedSlong8(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + err=TIFFReadDirEntryCheckRangeByteSlong8(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint8)m; + return(TIFFReadDirEntryErrOk); + } + default: + return(TIFFReadDirEntryErrType); + } +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryShort(TIFF* tif, TIFFDirEntry* direntry, uint16* value) +{ + enum TIFFReadDirEntryErr err; + if (direntry->tdir_count!=1) + return(TIFFReadDirEntryErrCount); + switch (direntry->tdir_type) + { + case TIFF_BYTE: + { + uint8 m; + TIFFReadDirEntryCheckedByte(tif,direntry,&m); + *value=(uint16)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SBYTE: + { + int8 m; + TIFFReadDirEntryCheckedSbyte(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeShortSbyte(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint16)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SHORT: + TIFFReadDirEntryCheckedShort(tif,direntry,value); + return(TIFFReadDirEntryErrOk); + case TIFF_SSHORT: + { + int16 m; + TIFFReadDirEntryCheckedSshort(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeShortSshort(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint16)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_LONG: + { + uint32 m; + TIFFReadDirEntryCheckedLong(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeShortLong(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint16)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SLONG: + { + int32 m; + TIFFReadDirEntryCheckedSlong(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeShortSlong(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint16)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_LONG8: + { + uint64 m; + err=TIFFReadDirEntryCheckedLong8(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + err=TIFFReadDirEntryCheckRangeShortLong8(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint16)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SLONG8: + { + int64 m; + err=TIFFReadDirEntryCheckedSlong8(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + err=TIFFReadDirEntryCheckRangeShortSlong8(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint16)m; + return(TIFFReadDirEntryErrOk); + } + default: + return(TIFFReadDirEntryErrType); + } +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryLong(TIFF* tif, TIFFDirEntry* direntry, uint32* value) +{ + enum TIFFReadDirEntryErr err; + if (direntry->tdir_count!=1) + return(TIFFReadDirEntryErrCount); + switch (direntry->tdir_type) + { + case TIFF_BYTE: + { + uint8 m; + TIFFReadDirEntryCheckedByte(tif,direntry,&m); + *value=(uint32)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SBYTE: + { + int8 m; + TIFFReadDirEntryCheckedSbyte(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeLongSbyte(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint32)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SHORT: + { + uint16 m; + TIFFReadDirEntryCheckedShort(tif,direntry,&m); + *value=(uint32)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SSHORT: + { + int16 m; + TIFFReadDirEntryCheckedSshort(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeLongSshort(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint32)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_LONG: + TIFFReadDirEntryCheckedLong(tif,direntry,value); + return(TIFFReadDirEntryErrOk); + case TIFF_SLONG: + { + int32 m; + TIFFReadDirEntryCheckedSlong(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeLongSlong(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint32)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_LONG8: + { + uint64 m; + err=TIFFReadDirEntryCheckedLong8(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + err=TIFFReadDirEntryCheckRangeLongLong8(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint32)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SLONG8: + { + int64 m; + err=TIFFReadDirEntryCheckedSlong8(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + err=TIFFReadDirEntryCheckRangeLongSlong8(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint32)m; + return(TIFFReadDirEntryErrOk); + } + default: + return(TIFFReadDirEntryErrType); + } +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8(TIFF* tif, TIFFDirEntry* direntry, uint64* value) +{ + enum TIFFReadDirEntryErr err; + if (direntry->tdir_count!=1) + return(TIFFReadDirEntryErrCount); + switch (direntry->tdir_type) + { + case TIFF_BYTE: + { + uint8 m; + TIFFReadDirEntryCheckedByte(tif,direntry,&m); + *value=(uint64)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SBYTE: + { + int8 m; + TIFFReadDirEntryCheckedSbyte(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeLong8Sbyte(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint64)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SHORT: + { + uint16 m; + TIFFReadDirEntryCheckedShort(tif,direntry,&m); + *value=(uint64)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SSHORT: + { + int16 m; + TIFFReadDirEntryCheckedSshort(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeLong8Sshort(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint64)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_LONG: + { + uint32 m; + TIFFReadDirEntryCheckedLong(tif,direntry,&m); + *value=(uint64)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SLONG: + { + int32 m; + TIFFReadDirEntryCheckedSlong(tif,direntry,&m); + err=TIFFReadDirEntryCheckRangeLong8Slong(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint64)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_LONG8: + err=TIFFReadDirEntryCheckedLong8(tif,direntry,value); + return(err); + case TIFF_SLONG8: + { + int64 m; + err=TIFFReadDirEntryCheckedSlong8(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + err=TIFFReadDirEntryCheckRangeLong8Slong8(m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(uint64)m; + return(TIFFReadDirEntryErrOk); + } + default: + return(TIFFReadDirEntryErrType); + } +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryFloat(TIFF* tif, TIFFDirEntry* direntry, float* value) +{ + enum TIFFReadDirEntryErr err; + if (direntry->tdir_count!=1) + return(TIFFReadDirEntryErrCount); + switch (direntry->tdir_type) + { + case TIFF_BYTE: + { + uint8 m; + TIFFReadDirEntryCheckedByte(tif,direntry,&m); + *value=(float)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SBYTE: + { + int8 m; + TIFFReadDirEntryCheckedSbyte(tif,direntry,&m); + *value=(float)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SHORT: + { + uint16 m; + TIFFReadDirEntryCheckedShort(tif,direntry,&m); + *value=(float)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SSHORT: + { + int16 m; + TIFFReadDirEntryCheckedSshort(tif,direntry,&m); + *value=(float)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_LONG: + { + uint32 m; + TIFFReadDirEntryCheckedLong(tif,direntry,&m); + *value=(float)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SLONG: + { + int32 m; + TIFFReadDirEntryCheckedSlong(tif,direntry,&m); + *value=(float)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_LONG8: + { + uint64 m; + err=TIFFReadDirEntryCheckedLong8(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); +#if defined(__WIN32__) && (_MSC_VER < 1500) + /* + * XXX: MSVC 6.0 does not support conversion + * of 64-bit integers into floating point + * values. + */ + *value = _TIFFUInt64ToFloat(m); +#else + *value=(float)m; +#endif + return(TIFFReadDirEntryErrOk); + } + case TIFF_SLONG8: + { + int64 m; + err=TIFFReadDirEntryCheckedSlong8(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(float)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_RATIONAL: + { + double m; + err=TIFFReadDirEntryCheckedRational(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(float)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SRATIONAL: + { + double m; + err=TIFFReadDirEntryCheckedSrational(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(float)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_FLOAT: + TIFFReadDirEntryCheckedFloat(tif,direntry,value); + return(TIFFReadDirEntryErrOk); + case TIFF_DOUBLE: + { + double m; + err=TIFFReadDirEntryCheckedDouble(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(float)m; + return(TIFFReadDirEntryErrOk); + } + default: + return(TIFFReadDirEntryErrType); + } +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryDouble(TIFF* tif, TIFFDirEntry* direntry, double* value) +{ + enum TIFFReadDirEntryErr err; + if (direntry->tdir_count!=1) + return(TIFFReadDirEntryErrCount); + switch (direntry->tdir_type) + { + case TIFF_BYTE: + { + uint8 m; + TIFFReadDirEntryCheckedByte(tif,direntry,&m); + *value=(double)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SBYTE: + { + int8 m; + TIFFReadDirEntryCheckedSbyte(tif,direntry,&m); + *value=(double)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SHORT: + { + uint16 m; + TIFFReadDirEntryCheckedShort(tif,direntry,&m); + *value=(double)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SSHORT: + { + int16 m; + TIFFReadDirEntryCheckedSshort(tif,direntry,&m); + *value=(double)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_LONG: + { + uint32 m; + TIFFReadDirEntryCheckedLong(tif,direntry,&m); + *value=(double)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SLONG: + { + int32 m; + TIFFReadDirEntryCheckedSlong(tif,direntry,&m); + *value=(double)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_LONG8: + { + uint64 m; + err=TIFFReadDirEntryCheckedLong8(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); +#if defined(__WIN32__) && (_MSC_VER < 1500) + /* + * XXX: MSVC 6.0 does not support conversion + * of 64-bit integers into floating point + * values. + */ + *value = _TIFFUInt64ToDouble(m); +#else + *value = (double)m; +#endif + return(TIFFReadDirEntryErrOk); + } + case TIFF_SLONG8: + { + int64 m; + err=TIFFReadDirEntryCheckedSlong8(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + *value=(double)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_RATIONAL: + err=TIFFReadDirEntryCheckedRational(tif,direntry,value); + return(err); + case TIFF_SRATIONAL: + err=TIFFReadDirEntryCheckedSrational(tif,direntry,value); + return(err); + case TIFF_FLOAT: + { + float m; + TIFFReadDirEntryCheckedFloat(tif,direntry,&m); + *value=(double)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_DOUBLE: + err=TIFFReadDirEntryCheckedDouble(tif,direntry,value); + return(err); + default: + return(TIFFReadDirEntryErrType); + } +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8(TIFF* tif, TIFFDirEntry* direntry, uint64* value) +{ + enum TIFFReadDirEntryErr err; + if (direntry->tdir_count!=1) + return(TIFFReadDirEntryErrCount); + switch (direntry->tdir_type) + { + case TIFF_LONG: + case TIFF_IFD: + { + uint32 m; + TIFFReadDirEntryCheckedLong(tif,direntry,&m); + *value=(uint64)m; + return(TIFFReadDirEntryErrOk); + } + case TIFF_LONG8: + case TIFF_IFD8: + err=TIFFReadDirEntryCheckedLong8(tif,direntry,value); + return(err); + default: + return(TIFFReadDirEntryErrType); + } +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryArray(TIFF* tif, TIFFDirEntry* direntry, uint32* count, uint32 desttypesize, void** value) +{ + int typesize; + uint32 datasize; + void* data; + typesize=TIFFDataWidth(direntry->tdir_type); + if ((direntry->tdir_count==0)||(typesize==0)) + { + *value=0; + return(TIFFReadDirEntryErrOk); + } + (void) desttypesize; + + /* + * As a sanity check, make sure we have no more than a 2GB tag array + * in either the current data type or the dest data type. This also + * avoids problems with overflow of tmsize_t on 32bit systems. + */ + if ((uint64)(2147483647/typesize)tdir_count) + return(TIFFReadDirEntryErrSizesan); + if ((uint64)(2147483647/desttypesize)tdir_count) + return(TIFFReadDirEntryErrSizesan); + + *count=(uint32)direntry->tdir_count; + datasize=(*count)*typesize; + assert((tmsize_t)datasize>0); + data=_TIFFCheckMalloc(tif, *count, typesize, "ReadDirEntryArray"); + if (data==0) + return(TIFFReadDirEntryErrAlloc); + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + if (datasize<=4) + _TIFFmemcpy(data,&direntry->tdir_offset,datasize); + else + { + enum TIFFReadDirEntryErr err; + uint32 offset = direntry->tdir_offset.toff_long; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(&offset); + err=TIFFReadDirEntryData(tif,(uint64)offset,(tmsize_t)datasize,data); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(data); + return(err); + } + } + } + else + { + if (datasize<=8) + _TIFFmemcpy(data,&direntry->tdir_offset,datasize); + else + { + enum TIFFReadDirEntryErr err; + uint64 offset = direntry->tdir_offset.toff_long8; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8(&offset); + err=TIFFReadDirEntryData(tif,offset,(tmsize_t)datasize,data); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(data); + return(err); + } + } + } + *value=data; + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryByteArray(TIFF* tif, TIFFDirEntry* direntry, uint8** value) +{ + enum TIFFReadDirEntryErr err; + uint32 count; + void* origdata; + uint8* data; + switch (direntry->tdir_type) + { + case TIFF_ASCII: + case TIFF_UNDEFINED: + case TIFF_BYTE: + case TIFF_SBYTE: + case TIFF_SHORT: + case TIFF_SSHORT: + case TIFF_LONG: + case TIFF_SLONG: + case TIFF_LONG8: + case TIFF_SLONG8: + break; + default: + return(TIFFReadDirEntryErrType); + } + err=TIFFReadDirEntryArray(tif,direntry,&count,1,&origdata); + if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) + { + *value=0; + return(err); + } + switch (direntry->tdir_type) + { + case TIFF_ASCII: + case TIFF_UNDEFINED: + case TIFF_BYTE: + *value=(uint8*)origdata; + return(TIFFReadDirEntryErrOk); + case TIFF_SBYTE: + { + int8* m; + uint32 n; + m=(int8*)origdata; + for (n=0; ntdir_type) + { + case TIFF_SHORT: + { + uint16* ma; + uint8* mb; + uint32 n; + ma=(uint16*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort(ma); + err=TIFFReadDirEntryCheckRangeByteShort(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint8)(*ma++); + } + } + break; + case TIFF_SSHORT: + { + int16* ma; + uint8* mb; + uint32 n; + ma=(int16*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)ma); + err=TIFFReadDirEntryCheckRangeByteSshort(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint8)(*ma++); + } + } + break; + case TIFF_LONG: + { + uint32* ma; + uint8* mb; + uint32 n; + ma=(uint32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + err=TIFFReadDirEntryCheckRangeByteLong(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint8)(*ma++); + } + } + break; + case TIFF_SLONG: + { + int32* ma; + uint8* mb; + uint32 n; + ma=(int32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)ma); + err=TIFFReadDirEntryCheckRangeByteSlong(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint8)(*ma++); + } + } + break; + case TIFF_LONG8: + { + uint64* ma; + uint8* mb; + uint32 n; + ma=(uint64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8(ma); + err=TIFFReadDirEntryCheckRangeByteLong8(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint8)(*ma++); + } + } + break; + case TIFF_SLONG8: + { + int64* ma; + uint8* mb; + uint32 n; + ma=(int64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)ma); + err=TIFFReadDirEntryCheckRangeByteSlong8(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint8)(*ma++); + } + } + break; + } + _TIFFfree(origdata); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(data); + return(err); + } + *value=data; + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntrySbyteArray(TIFF* tif, TIFFDirEntry* direntry, int8** value) +{ + enum TIFFReadDirEntryErr err; + uint32 count; + void* origdata; + int8* data; + switch (direntry->tdir_type) + { + case TIFF_UNDEFINED: + case TIFF_BYTE: + case TIFF_SBYTE: + case TIFF_SHORT: + case TIFF_SSHORT: + case TIFF_LONG: + case TIFF_SLONG: + case TIFF_LONG8: + case TIFF_SLONG8: + break; + default: + return(TIFFReadDirEntryErrType); + } + err=TIFFReadDirEntryArray(tif,direntry,&count,1,&origdata); + if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) + { + *value=0; + return(err); + } + switch (direntry->tdir_type) + { + case TIFF_UNDEFINED: + case TIFF_BYTE: + { + uint8* m; + uint32 n; + m=(uint8*)origdata; + for (n=0; ntdir_type) + { + case TIFF_SHORT: + { + uint16* ma; + int8* mb; + uint32 n; + ma=(uint16*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort(ma); + err=TIFFReadDirEntryCheckRangeSbyteShort(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(int8)(*ma++); + } + } + break; + case TIFF_SSHORT: + { + int16* ma; + int8* mb; + uint32 n; + ma=(int16*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)ma); + err=TIFFReadDirEntryCheckRangeSbyteSshort(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(int8)(*ma++); + } + } + break; + case TIFF_LONG: + { + uint32* ma; + int8* mb; + uint32 n; + ma=(uint32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + err=TIFFReadDirEntryCheckRangeSbyteLong(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(int8)(*ma++); + } + } + break; + case TIFF_SLONG: + { + int32* ma; + int8* mb; + uint32 n; + ma=(int32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)ma); + err=TIFFReadDirEntryCheckRangeSbyteSlong(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(int8)(*ma++); + } + } + break; + case TIFF_LONG8: + { + uint64* ma; + int8* mb; + uint32 n; + ma=(uint64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8(ma); + err=TIFFReadDirEntryCheckRangeSbyteLong8(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(int8)(*ma++); + } + } + break; + case TIFF_SLONG8: + { + int64* ma; + int8* mb; + uint32 n; + ma=(int64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)ma); + err=TIFFReadDirEntryCheckRangeSbyteSlong8(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(int8)(*ma++); + } + } + break; + } + _TIFFfree(origdata); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(data); + return(err); + } + *value=data; + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryShortArray(TIFF* tif, TIFFDirEntry* direntry, uint16** value) +{ + enum TIFFReadDirEntryErr err; + uint32 count; + void* origdata; + uint16* data; + switch (direntry->tdir_type) + { + case TIFF_BYTE: + case TIFF_SBYTE: + case TIFF_SHORT: + case TIFF_SSHORT: + case TIFF_LONG: + case TIFF_SLONG: + case TIFF_LONG8: + case TIFF_SLONG8: + break; + default: + return(TIFFReadDirEntryErrType); + } + err=TIFFReadDirEntryArray(tif,direntry,&count,2,&origdata); + if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) + { + *value=0; + return(err); + } + switch (direntry->tdir_type) + { + case TIFF_SHORT: + *value=(uint16*)origdata; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfShort(*value,count); + return(TIFFReadDirEntryErrOk); + case TIFF_SSHORT: + { + int16* m; + uint32 n; + m=(int16*)origdata; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)m); + err=TIFFReadDirEntryCheckRangeShortSshort(*m); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(origdata); + return(err); + } + m++; + } + *value=(uint16*)origdata; + return(TIFFReadDirEntryErrOk); + } + } + data=(uint16*)_TIFFmalloc(count*2); + if (data==0) + { + _TIFFfree(origdata); + return(TIFFReadDirEntryErrAlloc); + } + switch (direntry->tdir_type) + { + case TIFF_BYTE: + { + uint8* ma; + uint16* mb; + uint32 n; + ma=(uint8*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + err=TIFFReadDirEntryCheckRangeShortLong(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint16)(*ma++); + } + } + break; + case TIFF_SLONG: + { + int32* ma; + uint16* mb; + uint32 n; + ma=(int32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)ma); + err=TIFFReadDirEntryCheckRangeShortSlong(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint16)(*ma++); + } + } + break; + case TIFF_LONG8: + { + uint64* ma; + uint16* mb; + uint32 n; + ma=(uint64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8(ma); + err=TIFFReadDirEntryCheckRangeShortLong8(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint16)(*ma++); + } + } + break; + case TIFF_SLONG8: + { + int64* ma; + uint16* mb; + uint32 n; + ma=(int64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)ma); + err=TIFFReadDirEntryCheckRangeShortSlong8(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint16)(*ma++); + } + } + break; + } + _TIFFfree(origdata); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(data); + return(err); + } + *value=data; + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntrySshortArray(TIFF* tif, TIFFDirEntry* direntry, int16** value) +{ + enum TIFFReadDirEntryErr err; + uint32 count; + void* origdata; + int16* data; + switch (direntry->tdir_type) + { + case TIFF_BYTE: + case TIFF_SBYTE: + case TIFF_SHORT: + case TIFF_SSHORT: + case TIFF_LONG: + case TIFF_SLONG: + case TIFF_LONG8: + case TIFF_SLONG8: + break; + default: + return(TIFFReadDirEntryErrType); + } + err=TIFFReadDirEntryArray(tif,direntry,&count,2,&origdata); + if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) + { + *value=0; + return(err); + } + switch (direntry->tdir_type) + { + case TIFF_SHORT: + { + uint16* m; + uint32 n; + m=(uint16*)origdata; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort(m); + err=TIFFReadDirEntryCheckRangeSshortShort(*m); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(origdata); + return(err); + } + m++; + } + *value=(int16*)origdata; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SSHORT: + *value=(int16*)origdata; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfShort((uint16*)(*value),count); + return(TIFFReadDirEntryErrOk); + } + data=(int16*)_TIFFmalloc(count*2); + if (data==0) + { + _TIFFfree(origdata); + return(TIFFReadDirEntryErrAlloc); + } + switch (direntry->tdir_type) + { + case TIFF_BYTE: + { + uint8* ma; + int16* mb; + uint32 n; + ma=(uint8*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + err=TIFFReadDirEntryCheckRangeSshortLong(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(int16)(*ma++); + } + } + break; + case TIFF_SLONG: + { + int32* ma; + int16* mb; + uint32 n; + ma=(int32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)ma); + err=TIFFReadDirEntryCheckRangeSshortSlong(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(int16)(*ma++); + } + } + break; + case TIFF_LONG8: + { + uint64* ma; + int16* mb; + uint32 n; + ma=(uint64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8(ma); + err=TIFFReadDirEntryCheckRangeSshortLong8(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(int16)(*ma++); + } + } + break; + case TIFF_SLONG8: + { + int64* ma; + int16* mb; + uint32 n; + ma=(int64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)ma); + err=TIFFReadDirEntryCheckRangeSshortSlong8(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(int16)(*ma++); + } + } + break; + } + _TIFFfree(origdata); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(data); + return(err); + } + *value=data; + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryLongArray(TIFF* tif, TIFFDirEntry* direntry, uint32** value) +{ + enum TIFFReadDirEntryErr err; + uint32 count; + void* origdata; + uint32* data; + switch (direntry->tdir_type) + { + case TIFF_BYTE: + case TIFF_SBYTE: + case TIFF_SHORT: + case TIFF_SSHORT: + case TIFF_LONG: + case TIFF_SLONG: + case TIFF_LONG8: + case TIFF_SLONG8: + break; + default: + return(TIFFReadDirEntryErrType); + } + err=TIFFReadDirEntryArray(tif,direntry,&count,4,&origdata); + if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) + { + *value=0; + return(err); + } + switch (direntry->tdir_type) + { + case TIFF_LONG: + *value=(uint32*)origdata; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong(*value,count); + return(TIFFReadDirEntryErrOk); + case TIFF_SLONG: + { + int32* m; + uint32 n; + m=(int32*)origdata; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)m); + err=TIFFReadDirEntryCheckRangeLongSlong(*m); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(origdata); + return(err); + } + m++; + } + *value=(uint32*)origdata; + return(TIFFReadDirEntryErrOk); + } + } + data=(uint32*)_TIFFmalloc(count*4); + if (data==0) + { + _TIFFfree(origdata); + return(TIFFReadDirEntryErrAlloc); + } + switch (direntry->tdir_type) + { + case TIFF_BYTE: + { + uint8* ma; + uint32* mb; + uint32 n; + ma=(uint8*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort(ma); + *mb++=(uint32)(*ma++); + } + } + break; + case TIFF_SSHORT: + { + int16* ma; + uint32* mb; + uint32 n; + ma=(int16*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)ma); + err=TIFFReadDirEntryCheckRangeLongSshort(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint32)(*ma++); + } + } + break; + case TIFF_LONG8: + { + uint64* ma; + uint32* mb; + uint32 n; + ma=(uint64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8(ma); + err=TIFFReadDirEntryCheckRangeLongLong8(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint32)(*ma++); + } + } + break; + case TIFF_SLONG8: + { + int64* ma; + uint32* mb; + uint32 n; + ma=(int64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)ma); + err=TIFFReadDirEntryCheckRangeLongSlong8(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint32)(*ma++); + } + } + break; + } + _TIFFfree(origdata); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(data); + return(err); + } + *value=data; + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntrySlongArray(TIFF* tif, TIFFDirEntry* direntry, int32** value) +{ + enum TIFFReadDirEntryErr err; + uint32 count; + void* origdata; + int32* data; + switch (direntry->tdir_type) + { + case TIFF_BYTE: + case TIFF_SBYTE: + case TIFF_SHORT: + case TIFF_SSHORT: + case TIFF_LONG: + case TIFF_SLONG: + case TIFF_LONG8: + case TIFF_SLONG8: + break; + default: + return(TIFFReadDirEntryErrType); + } + err=TIFFReadDirEntryArray(tif,direntry,&count,4,&origdata); + if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) + { + *value=0; + return(err); + } + switch (direntry->tdir_type) + { + case TIFF_LONG: + { + uint32* m; + uint32 n; + m=(uint32*)origdata; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)m); + err=TIFFReadDirEntryCheckRangeSlongLong(*m); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(origdata); + return(err); + } + m++; + } + *value=(int32*)origdata; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SLONG: + *value=(int32*)origdata; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong((uint32*)(*value),count); + return(TIFFReadDirEntryErrOk); + } + data=(int32*)_TIFFmalloc(count*4); + if (data==0) + { + _TIFFfree(origdata); + return(TIFFReadDirEntryErrAlloc); + } + switch (direntry->tdir_type) + { + case TIFF_BYTE: + { + uint8* ma; + int32* mb; + uint32 n; + ma=(uint8*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort(ma); + *mb++=(int32)(*ma++); + } + } + break; + case TIFF_SSHORT: + { + int16* ma; + int32* mb; + uint32 n; + ma=(int16*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)ma); + *mb++=(int32)(*ma++); + } + } + break; + case TIFF_LONG8: + { + uint64* ma; + int32* mb; + uint32 n; + ma=(uint64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8(ma); + err=TIFFReadDirEntryCheckRangeSlongLong8(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(int32)(*ma++); + } + } + break; + case TIFF_SLONG8: + { + int64* ma; + int32* mb; + uint32 n; + ma=(int64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)ma); + err=TIFFReadDirEntryCheckRangeSlongSlong8(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(int32)(*ma++); + } + } + break; + } + _TIFFfree(origdata); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(data); + return(err); + } + *value=data; + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8Array(TIFF* tif, TIFFDirEntry* direntry, uint64** value) +{ + enum TIFFReadDirEntryErr err; + uint32 count; + void* origdata; + uint64* data; + switch (direntry->tdir_type) + { + case TIFF_BYTE: + case TIFF_SBYTE: + case TIFF_SHORT: + case TIFF_SSHORT: + case TIFF_LONG: + case TIFF_SLONG: + case TIFF_LONG8: + case TIFF_SLONG8: + break; + default: + return(TIFFReadDirEntryErrType); + } + err=TIFFReadDirEntryArray(tif,direntry,&count,8,&origdata); + if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) + { + *value=0; + return(err); + } + switch (direntry->tdir_type) + { + case TIFF_LONG8: + *value=(uint64*)origdata; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong8(*value,count); + return(TIFFReadDirEntryErrOk); + case TIFF_SLONG8: + { + int64* m; + uint32 n; + m=(int64*)origdata; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)m); + err=TIFFReadDirEntryCheckRangeLong8Slong8(*m); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(origdata); + return(err); + } + m++; + } + *value=(uint64*)origdata; + return(TIFFReadDirEntryErrOk); + } + } + data=(uint64*)_TIFFmalloc(count*8); + if (data==0) + { + _TIFFfree(origdata); + return(TIFFReadDirEntryErrAlloc); + } + switch (direntry->tdir_type) + { + case TIFF_BYTE: + { + uint8* ma; + uint64* mb; + uint32 n; + ma=(uint8*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort(ma); + *mb++=(uint64)(*ma++); + } + } + break; + case TIFF_SSHORT: + { + int16* ma; + uint64* mb; + uint32 n; + ma=(int16*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)ma); + err=TIFFReadDirEntryCheckRangeLong8Sshort(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint64)(*ma++); + } + } + break; + case TIFF_LONG: + { + uint32* ma; + uint64* mb; + uint32 n; + ma=(uint32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + *mb++=(uint64)(*ma++); + } + } + break; + case TIFF_SLONG: + { + int32* ma; + uint64* mb; + uint32 n; + ma=(int32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)ma); + err=TIFFReadDirEntryCheckRangeLong8Slong(*ma); + if (err!=TIFFReadDirEntryErrOk) + break; + *mb++=(uint64)(*ma++); + } + } + break; + } + _TIFFfree(origdata); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(data); + return(err); + } + *value=data; + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntrySlong8Array(TIFF* tif, TIFFDirEntry* direntry, int64** value) +{ + enum TIFFReadDirEntryErr err; + uint32 count; + void* origdata; + int64* data; + switch (direntry->tdir_type) + { + case TIFF_BYTE: + case TIFF_SBYTE: + case TIFF_SHORT: + case TIFF_SSHORT: + case TIFF_LONG: + case TIFF_SLONG: + case TIFF_LONG8: + case TIFF_SLONG8: + break; + default: + return(TIFFReadDirEntryErrType); + } + err=TIFFReadDirEntryArray(tif,direntry,&count,8,&origdata); + if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) + { + *value=0; + return(err); + } + switch (direntry->tdir_type) + { + case TIFF_LONG8: + { + uint64* m; + uint32 n; + m=(uint64*)origdata; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8(m); + err=TIFFReadDirEntryCheckRangeSlong8Long8(*m); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(origdata); + return(err); + } + m++; + } + *value=(int64*)origdata; + return(TIFFReadDirEntryErrOk); + } + case TIFF_SLONG8: + *value=(int64*)origdata; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong8((uint64*)(*value),count); + return(TIFFReadDirEntryErrOk); + } + data=(int64*)_TIFFmalloc(count*8); + if (data==0) + { + _TIFFfree(origdata); + return(TIFFReadDirEntryErrAlloc); + } + switch (direntry->tdir_type) + { + case TIFF_BYTE: + { + uint8* ma; + int64* mb; + uint32 n; + ma=(uint8*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort(ma); + *mb++=(int64)(*ma++); + } + } + break; + case TIFF_SSHORT: + { + int16* ma; + int64* mb; + uint32 n; + ma=(int16*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)ma); + *mb++=(int64)(*ma++); + } + } + break; + case TIFF_LONG: + { + uint32* ma; + int64* mb; + uint32 n; + ma=(uint32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + *mb++=(int64)(*ma++); + } + } + break; + case TIFF_SLONG: + { + int32* ma; + int64* mb; + uint32 n; + ma=(int32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)ma); + *mb++=(int64)(*ma++); + } + } + break; + } + _TIFFfree(origdata); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(data); + return(err); + } + *value=data; + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryFloatArray(TIFF* tif, TIFFDirEntry* direntry, float** value) +{ + enum TIFFReadDirEntryErr err; + uint32 count; + void* origdata; + float* data; + switch (direntry->tdir_type) + { + case TIFF_BYTE: + case TIFF_SBYTE: + case TIFF_SHORT: + case TIFF_SSHORT: + case TIFF_LONG: + case TIFF_SLONG: + case TIFF_LONG8: + case TIFF_SLONG8: + case TIFF_RATIONAL: + case TIFF_SRATIONAL: + case TIFF_FLOAT: + case TIFF_DOUBLE: + break; + default: + return(TIFFReadDirEntryErrType); + } + err=TIFFReadDirEntryArray(tif,direntry,&count,4,&origdata); + if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) + { + *value=0; + return(err); + } + switch (direntry->tdir_type) + { + case TIFF_FLOAT: + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong((uint32*)origdata,count); + TIFFCvtIEEEDoubleToNative(tif,count,(float*)origdata); + *value=(float*)origdata; + return(TIFFReadDirEntryErrOk); + } + data=(float*)_TIFFmalloc(count*sizeof(float)); + if (data==0) + { + _TIFFfree(origdata); + return(TIFFReadDirEntryErrAlloc); + } + switch (direntry->tdir_type) + { + case TIFF_BYTE: + { + uint8* ma; + float* mb; + uint32 n; + ma=(uint8*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort(ma); + *mb++=(float)(*ma++); + } + } + break; + case TIFF_SSHORT: + { + int16* ma; + float* mb; + uint32 n; + ma=(int16*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)ma); + *mb++=(float)(*ma++); + } + } + break; + case TIFF_LONG: + { + uint32* ma; + float* mb; + uint32 n; + ma=(uint32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + *mb++=(float)(*ma++); + } + } + break; + case TIFF_SLONG: + { + int32* ma; + float* mb; + uint32 n; + ma=(int32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)ma); + *mb++=(float)(*ma++); + } + } + break; + case TIFF_LONG8: + { + uint64* ma; + float* mb; + uint32 n; + ma=(uint64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8(ma); +#if defined(__WIN32__) && (_MSC_VER < 1500) + /* + * XXX: MSVC 6.0 does not support + * conversion of 64-bit integers into + * floating point values. + */ + *mb++ = _TIFFUInt64ToFloat(*ma++); +#else + *mb++ = (float)(*ma++); +#endif + } + } + break; + case TIFF_SLONG8: + { + int64* ma; + float* mb; + uint32 n; + ma=(int64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)ma); + *mb++=(float)(*ma++); + } + } + break; + case TIFF_RATIONAL: + { + uint32* ma; + uint32 maa; + uint32 mab; + float* mb; + uint32 n; + ma=(uint32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + maa=*ma++; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + mab=*ma++; + if (mab==0) + *mb++=0.0; + else + *mb++=(float)maa/(float)mab; + } + } + break; + case TIFF_SRATIONAL: + { + uint32* ma; + int32 maa; + uint32 mab; + float* mb; + uint32 n; + ma=(uint32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + maa=*(int32*)ma; + ma++; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + mab=*ma++; + if (mab==0) + *mb++=0.0; + else + *mb++=(float)maa/(float)mab; + } + } + break; + case TIFF_DOUBLE: + { + double* ma; + float* mb; + uint32 n; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong8((uint64*)origdata,count); + TIFFCvtIEEEDoubleToNative(tif,count,(double*)origdata); + ma=(double*)origdata; + mb=data; + for (n=0; ntdir_type) + { + case TIFF_BYTE: + case TIFF_SBYTE: + case TIFF_SHORT: + case TIFF_SSHORT: + case TIFF_LONG: + case TIFF_SLONG: + case TIFF_LONG8: + case TIFF_SLONG8: + case TIFF_RATIONAL: + case TIFF_SRATIONAL: + case TIFF_FLOAT: + case TIFF_DOUBLE: + break; + default: + return(TIFFReadDirEntryErrType); + } + err=TIFFReadDirEntryArray(tif,direntry,&count,8,&origdata); + if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) + { + *value=0; + return(err); + } + switch (direntry->tdir_type) + { + case TIFF_DOUBLE: + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong8((uint64*)origdata,count); + TIFFCvtIEEEDoubleToNative(tif,count,(double*)origdata); + *value=(double*)origdata; + return(TIFFReadDirEntryErrOk); + } + data=(double*)_TIFFmalloc(count*sizeof(double)); + if (data==0) + { + _TIFFfree(origdata); + return(TIFFReadDirEntryErrAlloc); + } + switch (direntry->tdir_type) + { + case TIFF_BYTE: + { + uint8* ma; + double* mb; + uint32 n; + ma=(uint8*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort(ma); + *mb++=(double)(*ma++); + } + } + break; + case TIFF_SSHORT: + { + int16* ma; + double* mb; + uint32 n; + ma=(int16*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)ma); + *mb++=(double)(*ma++); + } + } + break; + case TIFF_LONG: + { + uint32* ma; + double* mb; + uint32 n; + ma=(uint32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + *mb++=(double)(*ma++); + } + } + break; + case TIFF_SLONG: + { + int32* ma; + double* mb; + uint32 n; + ma=(int32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)ma); + *mb++=(double)(*ma++); + } + } + break; + case TIFF_LONG8: + { + uint64* ma; + double* mb; + uint32 n; + ma=(uint64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8(ma); +#if defined(__WIN32__) && (_MSC_VER < 1500) + /* + * XXX: MSVC 6.0 does not support + * conversion of 64-bit integers into + * floating point values. + */ + *mb++ = _TIFFUInt64ToDouble(*ma++); +#else + *mb++ = (double)(*ma++); +#endif + } + } + break; + case TIFF_SLONG8: + { + int64* ma; + double* mb; + uint32 n; + ma=(int64*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)ma); + *mb++=(double)(*ma++); + } + } + break; + case TIFF_RATIONAL: + { + uint32* ma; + uint32 maa; + uint32 mab; + double* mb; + uint32 n; + ma=(uint32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + maa=*ma++; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + mab=*ma++; + if (mab==0) + *mb++=0.0; + else + *mb++=(double)maa/(double)mab; + } + } + break; + case TIFF_SRATIONAL: + { + uint32* ma; + int32 maa; + uint32 mab; + double* mb; + uint32 n; + ma=(uint32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + maa=*(int32*)ma; + ma++; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + mab=*ma++; + if (mab==0) + *mb++=0.0; + else + *mb++=(double)maa/(double)mab; + } + } + break; + case TIFF_FLOAT: + { + float* ma; + double* mb; + uint32 n; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong((uint32*)origdata,count); + TIFFCvtIEEEFloatToNative(tif,count,(float*)origdata); + ma=(float*)origdata; + mb=data; + for (n=0; ntdir_type) + { + case TIFF_LONG: + case TIFF_LONG8: + case TIFF_IFD: + case TIFF_IFD8: + break; + default: + return(TIFFReadDirEntryErrType); + } + err=TIFFReadDirEntryArray(tif,direntry,&count,8,&origdata); + if ((err!=TIFFReadDirEntryErrOk)||(origdata==0)) + { + *value=0; + return(err); + } + switch (direntry->tdir_type) + { + case TIFF_LONG8: + case TIFF_IFD8: + *value=(uint64*)origdata; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong8(*value,count); + return(TIFFReadDirEntryErrOk); + } + data=(uint64*)_TIFFmalloc(count*8); + if (data==0) + { + _TIFFfree(origdata); + return(TIFFReadDirEntryErrAlloc); + } + switch (direntry->tdir_type) + { + case TIFF_LONG: + case TIFF_IFD: + { + uint32* ma; + uint64* mb; + uint32 n; + ma=(uint32*)origdata; + mb=data; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabLong(ma); + *mb++=(uint64)(*ma++); + } + } + break; + } + _TIFFfree(origdata); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(data); + return(err); + } + *value=data; + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleShort(TIFF* tif, TIFFDirEntry* direntry, uint16* value) +{ + enum TIFFReadDirEntryErr err; + uint16* m; + uint16* na; + uint16 nb; + if (direntry->tdir_count<(uint64)tif->tif_dir.td_samplesperpixel) + return(TIFFReadDirEntryErrCount); + err=TIFFReadDirEntryShortArray(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + na=m; + nb=tif->tif_dir.td_samplesperpixel; + *value=*na++; + nb--; + while (nb>0) + { + if (*na++!=*value) + { + err=TIFFReadDirEntryErrPsdif; + break; + } + nb--; + } + _TIFFfree(m); + return(err); +} + +#if 0 +static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleDouble(TIFF* tif, TIFFDirEntry* direntry, double* value) +{ + enum TIFFReadDirEntryErr err; + double* m; + double* na; + uint16 nb; + if (direntry->tdir_count<(uint64)tif->tif_dir.td_samplesperpixel) + return(TIFFReadDirEntryErrCount); + err=TIFFReadDirEntryDoubleArray(tif,direntry,&m); + if (err!=TIFFReadDirEntryErrOk) + return(err); + na=m; + nb=tif->tif_dir.td_samplesperpixel; + *value=*na++; + nb--; + while (nb>0) + { + if (*na++!=*value) + { + err=TIFFReadDirEntryErrPsdif; + break; + } + nb--; + } + _TIFFfree(m); + return(err); +} +#endif + +static void TIFFReadDirEntryCheckedByte(TIFF* tif, TIFFDirEntry* direntry, uint8* value) +{ + (void) tif; + *value=*(uint8*)(&direntry->tdir_offset); +} + +static void TIFFReadDirEntryCheckedSbyte(TIFF* tif, TIFFDirEntry* direntry, int8* value) +{ + (void) tif; + *value=*(int8*)(&direntry->tdir_offset); +} + +static void TIFFReadDirEntryCheckedShort(TIFF* tif, TIFFDirEntry* direntry, uint16* value) +{ + *value = direntry->tdir_offset.toff_short; + /* *value=*(uint16*)(&direntry->tdir_offset); */ + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabShort(value); +} + +static void TIFFReadDirEntryCheckedSshort(TIFF* tif, TIFFDirEntry* direntry, int16* value) +{ + *value=*(int16*)(&direntry->tdir_offset); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)value); +} + +static void TIFFReadDirEntryCheckedLong(TIFF* tif, TIFFDirEntry* direntry, uint32* value) +{ + *value=*(uint32*)(&direntry->tdir_offset); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(value); +} + +static void TIFFReadDirEntryCheckedSlong(TIFF* tif, TIFFDirEntry* direntry, int32* value) +{ + *value=*(int32*)(&direntry->tdir_offset); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)value); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedLong8(TIFF* tif, TIFFDirEntry* direntry, uint64* value) +{ + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + enum TIFFReadDirEntryErr err; + uint32 offset = direntry->tdir_offset.toff_long; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(&offset); + err=TIFFReadDirEntryData(tif,offset,8,value); + if (err!=TIFFReadDirEntryErrOk) + return(err); + } + else + *value = direntry->tdir_offset.toff_long8; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8(value); + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSlong8(TIFF* tif, TIFFDirEntry* direntry, int64* value) +{ + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + enum TIFFReadDirEntryErr err; + uint32 offset = direntry->tdir_offset.toff_long; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(&offset); + err=TIFFReadDirEntryData(tif,offset,8,value); + if (err!=TIFFReadDirEntryErrOk) + return(err); + } + else + *value=*(int64*)(&direntry->tdir_offset); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)value); + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedRational(TIFF* tif, TIFFDirEntry* direntry, double* value) +{ + UInt64Aligned_t m; + + assert(sizeof(double)==8); + assert(sizeof(uint64)==8); + assert(sizeof(uint32)==4); + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + enum TIFFReadDirEntryErr err; + uint32 offset = direntry->tdir_offset.toff_long; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(&offset); + err=TIFFReadDirEntryData(tif,offset,8,m.i); + if (err!=TIFFReadDirEntryErrOk) + return(err); + } + else + m.l = direntry->tdir_offset.toff_long8; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong(m.i,2); + if (m.i[0]==0) + *value=0.0; + else + *value=(double)m.i[0]/(double)m.i[1]; + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSrational(TIFF* tif, TIFFDirEntry* direntry, double* value) +{ + UInt64Aligned_t m; + assert(sizeof(double)==8); + assert(sizeof(uint64)==8); + assert(sizeof(int32)==4); + assert(sizeof(uint32)==4); + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + enum TIFFReadDirEntryErr err; + uint32 offset = direntry->tdir_offset.toff_long; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(&offset); + err=TIFFReadDirEntryData(tif,offset,8,m.i); + if (err!=TIFFReadDirEntryErrOk) + return(err); + } + else + m.l=direntry->tdir_offset.toff_long8; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong(m.i,2); + if ((int32)m.i[0]==0) + *value=0.0; + else + *value=(double)((int32)m.i[0])/(double)m.i[1]; + return(TIFFReadDirEntryErrOk); +} + +static void TIFFReadDirEntryCheckedFloat(TIFF* tif, TIFFDirEntry* direntry, float* value) +{ + union + { + float f; + uint32 i; + } float_union; + assert(sizeof(float)==4); + assert(sizeof(uint32)==4); + assert(sizeof(float_union)==4); + float_union.i=*(uint32*)(&direntry->tdir_offset); + *value=float_union.f; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)value); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedDouble(TIFF* tif, TIFFDirEntry* direntry, double* value) +{ + assert(sizeof(double)==8); + assert(sizeof(uint64)==8); + assert(sizeof(UInt64Aligned_t)==8); + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + enum TIFFReadDirEntryErr err; + uint32 offset = direntry->tdir_offset.toff_long; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(&offset); + err=TIFFReadDirEntryData(tif,offset,8,value); + if (err!=TIFFReadDirEntryErrOk) + return(err); + } + else + { + UInt64Aligned_t uint64_union; + uint64_union.l=direntry->tdir_offset.toff_long8; + *value=uint64_union.d; + } + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)value); + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSbyte(int8 value) +{ + if (value<0) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteShort(uint16 value) +{ + if (value>0xFF) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSshort(int16 value) +{ + if ((value<0)||(value>0xFF)) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong(uint32 value) +{ + if (value>0xFF) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong(int32 value) +{ + if ((value<0)||(value>0xFF)) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong8(uint64 value) +{ + if (value>0xFF) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong8(int64 value) +{ + if ((value<0)||(value>0xFF)) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteByte(uint8 value) +{ + if (value>0x7F) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteShort(uint16 value) +{ + if (value>0x7F) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSshort(int16 value) +{ + if ((value<-0x80)||(value>0x7F)) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteLong(uint32 value) +{ + if (value>0x7F) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSlong(int32 value) +{ + if ((value<-0x80)||(value>0x7F)) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteLong8(uint64 value) +{ + if (value>0x7F) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSlong8(int64 value) +{ + if ((value<-0x80)||(value>0x7F)) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSbyte(int8 value) +{ + if (value<0) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSshort(int16 value) +{ + if (value<0) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortLong(uint32 value) +{ + if (value>0xFFFF) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSlong(int32 value) +{ + if ((value<0)||(value>0xFFFF)) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortLong8(uint64 value) +{ + if (value>0xFFFF) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSlong8(int64 value) +{ + if ((value<0)||(value>0xFFFF)) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortShort(uint16 value) +{ + if (value>0x7FFF) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortLong(uint32 value) +{ + if (value>0x7FFF) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortSlong(int32 value) +{ + if ((value<-0x8000)||(value>0x7FFF)) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortLong8(uint64 value) +{ + if (value>0x7FFF) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortSlong8(int64 value) +{ + if ((value<-0x8000)||(value>0x7FFF)) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSbyte(int8 value) +{ + if (value<0) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSshort(int16 value) +{ + if (value<0) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSlong(int32 value) +{ + if (value<0) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +/* + * Largest 32-bit unsigned integer value. + */ +#if defined(__WIN32__) && defined(_MSC_VER) +# define TIFF_UINT32_MAX 0xFFFFFFFFI64 +#else +# define TIFF_UINT32_MAX 0xFFFFFFFFLL +#endif + +static enum TIFFReadDirEntryErr +TIFFReadDirEntryCheckRangeLongLong8(uint64 value) +{ + if (value > TIFF_UINT32_MAX) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr +TIFFReadDirEntryCheckRangeLongSlong8(int64 value) +{ + if ((value<0) || (value > TIFF_UINT32_MAX)) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +#undef TIFF_UINT32_MAX + +static enum TIFFReadDirEntryErr +TIFFReadDirEntryCheckRangeSlongLong(uint32 value) +{ + if (value > 0x7FFFFFFFUL) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr +TIFFReadDirEntryCheckRangeSlongLong8(uint64 value) +{ + if (value > 0x7FFFFFFFUL) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr +TIFFReadDirEntryCheckRangeSlongSlong8(int64 value) +{ + if ((value < 0L-0x80000000L) || (value > 0x7FFFFFFFL)) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr +TIFFReadDirEntryCheckRangeLong8Sbyte(int8 value) +{ + if (value < 0) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr +TIFFReadDirEntryCheckRangeLong8Sshort(int16 value) +{ + if (value < 0) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr +TIFFReadDirEntryCheckRangeLong8Slong(int32 value) +{ + if (value < 0) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +static enum TIFFReadDirEntryErr +TIFFReadDirEntryCheckRangeLong8Slong8(int64 value) +{ + if (value < 0) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +/* + * Largest 64-bit signed integer value. + */ +#if defined(__WIN32__) && defined(_MSC_VER) +# define TIFF_INT64_MAX 0x7FFFFFFFFFFFFFFFI64 +#else +# define TIFF_INT64_MAX 0x7FFFFFFFFFFFFFFFLL +#endif + +static enum TIFFReadDirEntryErr +TIFFReadDirEntryCheckRangeSlong8Long8(uint64 value) +{ + if (value > TIFF_INT64_MAX) + return(TIFFReadDirEntryErrRange); + else + return(TIFFReadDirEntryErrOk); +} + +#undef TIFF_INT64_MAX + +static enum TIFFReadDirEntryErr +TIFFReadDirEntryData(TIFF* tif, uint64 offset, tmsize_t size, void* dest) +{ + assert(size>0); + if (!isMapped(tif)) { + if (!SeekOK(tif,offset)) + return(TIFFReadDirEntryErrIo); + if (!ReadOK(tif,dest,size)) + return(TIFFReadDirEntryErrIo); + } else { + size_t ma,mb; + ma=(size_t)offset; + mb=ma+size; + if (((uint64)ma!=offset) + || (mb < ma) + || (mb - ma != (size_t) size) + || (mb < (size_t)size) + || (mb > (size_t)tif->tif_size) + ) + return(TIFFReadDirEntryErrIo); + _TIFFmemcpy(dest,tif->tif_base+ma,size); + } + return(TIFFReadDirEntryErrOk); +} + +static void TIFFReadDirEntryOutputErr(TIFF* tif, enum TIFFReadDirEntryErr err, const char* module, const char* tagname, int recover) +{ + if (!recover) { + switch (err) { + case TIFFReadDirEntryErrCount: + TIFFErrorExt(tif->tif_clientdata, module, + "Incorrect count for \"%s\"", + tagname); + break; + case TIFFReadDirEntryErrType: + TIFFErrorExt(tif->tif_clientdata, module, + "Incompatible type for \"%s\"", + tagname); + break; + case TIFFReadDirEntryErrIo: + TIFFErrorExt(tif->tif_clientdata, module, + "IO error during reading of \"%s\"", + tagname); + break; + case TIFFReadDirEntryErrRange: + TIFFErrorExt(tif->tif_clientdata, module, + "Incorrect value for \"%s\"", + tagname); + break; + case TIFFReadDirEntryErrPsdif: + TIFFErrorExt(tif->tif_clientdata, module, + "Cannot handle different values per sample for \"%s\"", + tagname); + break; + case TIFFReadDirEntryErrSizesan: + TIFFErrorExt(tif->tif_clientdata, module, + "Sanity check on size of \"%s\" value failed", + tagname); + break; + case TIFFReadDirEntryErrAlloc: + TIFFErrorExt(tif->tif_clientdata, module, + "Out of memory reading of \"%s\"", + tagname); + break; + default: + assert(0); /* we should never get here */ + break; + } + } else { + switch (err) { + case TIFFReadDirEntryErrCount: + TIFFErrorExt(tif->tif_clientdata, module, + "Incorrect count for \"%s\"; tag ignored", + tagname); + break; + case TIFFReadDirEntryErrType: + TIFFWarningExt(tif->tif_clientdata, module, + "Incompatible type for \"%s\"; tag ignored", + tagname); + break; + case TIFFReadDirEntryErrIo: + TIFFWarningExt(tif->tif_clientdata, module, + "IO error during reading of \"%s\"; tag ignored", + tagname); + break; + case TIFFReadDirEntryErrRange: + TIFFWarningExt(tif->tif_clientdata, module, + "Incorrect value for \"%s\"; tag ignored", + tagname); + break; + case TIFFReadDirEntryErrPsdif: + TIFFWarningExt(tif->tif_clientdata, module, + "Cannot handle different values per sample for \"%s\"; tag ignored", + tagname); + break; + case TIFFReadDirEntryErrSizesan: + TIFFWarningExt(tif->tif_clientdata, module, + "Sanity check on size of \"%s\" value failed; tag ignored", + tagname); + break; + case TIFFReadDirEntryErrAlloc: + TIFFWarningExt(tif->tif_clientdata, module, + "Out of memory reading of \"%s\"; tag ignored", + tagname); + break; + default: + assert(0); /* we should never get here */ + break; + } + } +} + +/* + * Read the next TIFF directory from a file and convert it to the internal + * format. We read directories sequentially. + */ +int +TIFFReadDirectory(TIFF* tif) +{ + static const char module[] = "TIFFReadDirectory"; + TIFFDirEntry* dir; + uint16 dircount; + TIFFDirEntry* dp; + uint16 di; + const TIFFField* fip; + uint32 fii=FAILED_FII; + toff_t nextdiroff; + tif->tif_diroff=tif->tif_nextdiroff; + if (!TIFFCheckDirOffset(tif,tif->tif_nextdiroff)) + return 0; /* last offset or bad offset (IFD looping) */ + (*tif->tif_cleanup)(tif); /* cleanup any previous compression state */ + tif->tif_curdir++; + nextdiroff = tif->tif_nextdiroff; + dircount=TIFFFetchDirectory(tif,nextdiroff,&dir,&tif->tif_nextdiroff); + if (!dircount) + { + TIFFErrorExt(tif->tif_clientdata,module, + "Failed to read directory at offset " TIFF_UINT64_FORMAT,nextdiroff); + return 0; + } + TIFFReadDirectoryCheckOrder(tif,dir,dircount); + + /* + * Mark duplicates of any tag to be ignored (bugzilla 1994) + * to avoid certain pathological problems. + */ + { + TIFFDirEntry* ma; + uint16 mb; + for (ma=dir, mb=0; mbtdir_tag==na->tdir_tag) + na->tdir_tag=IGNORE; + } + } + } + + tif->tif_flags &= ~TIFF_BEENWRITING; /* reset before new dir */ + tif->tif_flags &= ~TIFF_BUF4WRITE; /* reset before new dir */ + /* free any old stuff and reinit */ + TIFFFreeDirectory(tif); + TIFFDefaultDirectory(tif); + /* + * Electronic Arts writes gray-scale TIFF files + * without a PlanarConfiguration directory entry. + * Thus we setup a default value here, even though + * the TIFF spec says there is no default value. + */ + TIFFSetField(tif,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG); + /* + * Setup default value and then make a pass over + * the fields to check type and tag information, + * and to extract info required to size data + * structures. A second pass is made afterwards + * to read in everthing not taken in the first pass. + * But we must process the Compression tag first + * in order to merge in codec-private tag definitions (otherwise + * we may get complaints about unknown tags). However, the + * Compression tag may be dependent on the SamplesPerPixel + * tag value because older TIFF specs permited Compression + * to be written as a SamplesPerPixel-count tag entry. + * Thus if we don't first figure out the correct SamplesPerPixel + * tag value then we may end up ignoring the Compression tag + * value because it has an incorrect count value (if the + * true value of SamplesPerPixel is not 1). + */ + dp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_SAMPLESPERPIXEL); + if (dp) + { + if (!TIFFFetchNormalTag(tif,dp,0)) + goto bad; + dp->tdir_tag=IGNORE; + } + dp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_COMPRESSION); + if (dp) + { + /* + * The 5.0 spec says the Compression tag has one value, while + * earlier specs say it has one value per sample. Because of + * this, we accept the tag if one value is supplied with either + * count. + */ + uint16 value; + enum TIFFReadDirEntryErr err; + err=TIFFReadDirEntryShort(tif,dp,&value); + if (err==TIFFReadDirEntryErrCount) + err=TIFFReadDirEntryPersampleShort(tif,dp,&value); + if (err!=TIFFReadDirEntryErrOk) + { + TIFFReadDirEntryOutputErr(tif,err,module,"Compression",0); + goto bad; + } + if (!TIFFSetField(tif,TIFFTAG_COMPRESSION,value)) + goto bad; + dp->tdir_tag=IGNORE; + } + else + { + if (!TIFFSetField(tif,TIFFTAG_COMPRESSION,COMPRESSION_NONE)) + goto bad; + } + /* + * First real pass over the directory. + */ + for (di=0, dp=dir; ditdir_tag!=IGNORE) + { + TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); + if (fii == FAILED_FII) + { + TIFFWarningExt(tif->tif_clientdata, module, + "Unknown field with tag %d (0x%x) encountered", + dp->tdir_tag,dp->tdir_tag); + /* the following knowingly leaks the + anonymous field structure */ + if (!_TIFFMergeFields(tif, + _TIFFCreateAnonField(tif, + dp->tdir_tag, + (TIFFDataType) dp->tdir_type), + 1)) { + TIFFWarningExt(tif->tif_clientdata, + module, + "Registering anonymous field with tag %d (0x%x) failed", + dp->tdir_tag, + dp->tdir_tag); + dp->tdir_tag=IGNORE; + } else { + TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); + assert(fii != FAILED_FII); + } + } + } + if (dp->tdir_tag!=IGNORE) + { + fip=tif->tif_fields[fii]; + if (fip->field_bit==FIELD_IGNORE) + dp->tdir_tag=IGNORE; + else + { + switch (dp->tdir_tag) + { + case TIFFTAG_STRIPOFFSETS: + case TIFFTAG_STRIPBYTECOUNTS: + case TIFFTAG_TILEOFFSETS: + case TIFFTAG_TILEBYTECOUNTS: + TIFFSetFieldBit(tif,fip->field_bit); + break; + case TIFFTAG_IMAGEWIDTH: + case TIFFTAG_IMAGELENGTH: + case TIFFTAG_IMAGEDEPTH: + case TIFFTAG_TILELENGTH: + case TIFFTAG_TILEWIDTH: + case TIFFTAG_TILEDEPTH: + case TIFFTAG_PLANARCONFIG: + case TIFFTAG_ROWSPERSTRIP: + case TIFFTAG_EXTRASAMPLES: + if (!TIFFFetchNormalTag(tif,dp,0)) + goto bad; + dp->tdir_tag=IGNORE; + break; + } + } + } + } + /* + * XXX: OJPEG hack. + * If a) compression is OJPEG, b) planarconfig tag says it's separate, + * c) strip offsets/bytecounts tag are both present and + * d) both contain exactly one value, then we consistently find + * that the buggy implementation of the buggy compression scheme + * matches contig planarconfig best. So we 'fix-up' the tag here + */ + if ((tif->tif_dir.td_compression==COMPRESSION_OJPEG)&& + (tif->tif_dir.td_planarconfig==PLANARCONFIG_SEPARATE)) + { + if (!_TIFFFillStriles(tif)) + goto bad; + dp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_STRIPOFFSETS); + if ((dp!=0)&&(dp->tdir_count==1)) + { + dp=TIFFReadDirectoryFindEntry(tif,dir,dircount, + TIFFTAG_STRIPBYTECOUNTS); + if ((dp!=0)&&(dp->tdir_count==1)) + { + tif->tif_dir.td_planarconfig=PLANARCONFIG_CONTIG; + TIFFWarningExt(tif->tif_clientdata,module, + "Planarconfig tag value assumed incorrect, " + "assuming data is contig instead of chunky"); + } + } + } + /* + * Allocate directory structure and setup defaults. + */ + if (!TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS)) + { + MissingRequired(tif,"ImageLength"); + goto bad; + } + /* + * Setup appropriate structures (by strip or by tile) + */ + if (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) { + tif->tif_dir.td_nstrips = TIFFNumberOfStrips(tif); + tif->tif_dir.td_tilewidth = tif->tif_dir.td_imagewidth; + tif->tif_dir.td_tilelength = tif->tif_dir.td_rowsperstrip; + tif->tif_dir.td_tiledepth = tif->tif_dir.td_imagedepth; + tif->tif_flags &= ~TIFF_ISTILED; + } else { + tif->tif_dir.td_nstrips = TIFFNumberOfTiles(tif); + tif->tif_flags |= TIFF_ISTILED; + } + if (!tif->tif_dir.td_nstrips) { + TIFFErrorExt(tif->tif_clientdata, module, + "Cannot handle zero number of %s", + isTiled(tif) ? "tiles" : "strips"); + goto bad; + } + tif->tif_dir.td_stripsperimage = tif->tif_dir.td_nstrips; + if (tif->tif_dir.td_planarconfig == PLANARCONFIG_SEPARATE) + tif->tif_dir.td_stripsperimage /= tif->tif_dir.td_samplesperpixel; + if (!TIFFFieldSet(tif, FIELD_STRIPOFFSETS)) { + if ((tif->tif_dir.td_compression==COMPRESSION_OJPEG) && + (isTiled(tif)==0) && + (tif->tif_dir.td_nstrips==1)) { + /* + * XXX: OJPEG hack. + * If a) compression is OJPEG, b) it's not a tiled TIFF, + * and c) the number of strips is 1, + * then we tolerate the absence of stripoffsets tag, + * because, presumably, all required data is in the + * JpegInterchangeFormat stream. + */ + TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS); + } else { + MissingRequired(tif, + isTiled(tif) ? "TileOffsets" : "StripOffsets"); + goto bad; + } + } + /* + * Second pass: extract other information. + */ + for (di=0, dp=dir; ditdir_tag) + { + case IGNORE: + break; + case TIFFTAG_MINSAMPLEVALUE: + case TIFFTAG_MAXSAMPLEVALUE: + case TIFFTAG_BITSPERSAMPLE: + case TIFFTAG_DATATYPE: + case TIFFTAG_SAMPLEFORMAT: + /* + * The MinSampleValue, MaxSampleValue, BitsPerSample + * DataType and SampleFormat tags are supposed to be + * written as one value/sample, but some vendors + * incorrectly write one value only -- so we accept + * that as well (yech). Other vendors write correct + * value for NumberOfSamples, but incorrect one for + * BitsPerSample and friends, and we will read this + * too. + */ + { + uint16 value; + enum TIFFReadDirEntryErr err; + err=TIFFReadDirEntryShort(tif,dp,&value); + if (err==TIFFReadDirEntryErrCount) + err=TIFFReadDirEntryPersampleShort(tif,dp,&value); + if (err!=TIFFReadDirEntryErrOk) + { + fip = TIFFFieldWithTag(tif,dp->tdir_tag); + TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0); + goto bad; + } + if (!TIFFSetField(tif,dp->tdir_tag,value)) + goto bad; + } + break; + case TIFFTAG_SMINSAMPLEVALUE: + case TIFFTAG_SMAXSAMPLEVALUE: + { + + double *data; + enum TIFFReadDirEntryErr err; + uint32 saved_flags; + int m; + if (dp->tdir_count != (uint64)tif->tif_dir.td_samplesperpixel) + err = TIFFReadDirEntryErrCount; + else + err = TIFFReadDirEntryDoubleArray(tif, dp, &data); + if (err!=TIFFReadDirEntryErrOk) + { + fip = TIFFFieldWithTag(tif,dp->tdir_tag); + TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0); + goto bad; + } + saved_flags = tif->tif_flags; + tif->tif_flags |= TIFF_PERSAMPLE; + m = TIFFSetField(tif,dp->tdir_tag,data); + tif->tif_flags = saved_flags; + _TIFFfree(data); + if (!m) + goto bad; + } + break; + case TIFFTAG_STRIPOFFSETS: + case TIFFTAG_TILEOFFSETS: +#if defined(DEFER_STRILE_LOAD) + _TIFFmemcpy( &(tif->tif_dir.td_stripoffset_entry), + dp, sizeof(TIFFDirEntry) ); +#else + if (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripoffset)) + goto bad; +#endif + break; + case TIFFTAG_STRIPBYTECOUNTS: + case TIFFTAG_TILEBYTECOUNTS: +#if defined(DEFER_STRILE_LOAD) + _TIFFmemcpy( &(tif->tif_dir.td_stripbytecount_entry), + dp, sizeof(TIFFDirEntry) ); +#else + if (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripbytecount)) + goto bad; +#endif + break; + case TIFFTAG_COLORMAP: + case TIFFTAG_TRANSFERFUNCTION: + { + enum TIFFReadDirEntryErr err; + uint32 countpersample; + uint32 countrequired; + uint32 incrementpersample; + uint16* value=NULL; + countpersample=(1L<tif_dir.td_bitspersample); + if ((dp->tdir_tag==TIFFTAG_TRANSFERFUNCTION)&&(dp->tdir_count==(uint64)countpersample)) + { + countrequired=countpersample; + incrementpersample=0; + } + else + { + countrequired=3*countpersample; + incrementpersample=countpersample; + } + if (dp->tdir_count!=(uint64)countrequired) + err=TIFFReadDirEntryErrCount; + else + err=TIFFReadDirEntryShortArray(tif,dp,&value); + if (err!=TIFFReadDirEntryErrOk) + { + fip = TIFFFieldWithTag(tif,dp->tdir_tag); + TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",1); + } + else + { + TIFFSetField(tif,dp->tdir_tag,value,value+incrementpersample,value+2*incrementpersample); + _TIFFfree(value); + } + } + break; +/* BEGIN REV 4.0 COMPATIBILITY */ + case TIFFTAG_OSUBFILETYPE: + { + uint16 valueo; + uint32 value; + if (TIFFReadDirEntryShort(tif,dp,&valueo)==TIFFReadDirEntryErrOk) + { + switch (valueo) + { + case OFILETYPE_REDUCEDIMAGE: value=FILETYPE_REDUCEDIMAGE; break; + case OFILETYPE_PAGE: value=FILETYPE_PAGE; break; + default: value=0; break; + } + if (value!=0) + TIFFSetField(tif,TIFFTAG_SUBFILETYPE,value); + } + } + break; +/* END REV 4.0 COMPATIBILITY */ + default: + (void) TIFFFetchNormalTag(tif, dp, TRUE); + break; + } + } + /* + * OJPEG hack: + * - If a) compression is OJPEG, and b) photometric tag is missing, + * then we consistently find that photometric should be YCbCr + * - If a) compression is OJPEG, and b) photometric tag says it's RGB, + * then we consistently find that the buggy implementation of the + * buggy compression scheme matches photometric YCbCr instead. + * - If a) compression is OJPEG, and b) bitspersample tag is missing, + * then we consistently find bitspersample should be 8. + * - If a) compression is OJPEG, b) samplesperpixel tag is missing, + * and c) photometric is RGB or YCbCr, then we consistently find + * samplesperpixel should be 3 + * - If a) compression is OJPEG, b) samplesperpixel tag is missing, + * and c) photometric is MINISWHITE or MINISBLACK, then we consistently + * find samplesperpixel should be 3 + */ + if (tif->tif_dir.td_compression==COMPRESSION_OJPEG) + { + if (!TIFFFieldSet(tif,FIELD_PHOTOMETRIC)) + { + TIFFWarningExt(tif->tif_clientdata, module, + "Photometric tag is missing, assuming data is YCbCr"); + if (!TIFFSetField(tif,TIFFTAG_PHOTOMETRIC,PHOTOMETRIC_YCBCR)) + goto bad; + } + else if (tif->tif_dir.td_photometric==PHOTOMETRIC_RGB) + { + tif->tif_dir.td_photometric=PHOTOMETRIC_YCBCR; + TIFFWarningExt(tif->tif_clientdata, module, + "Photometric tag value assumed incorrect, " + "assuming data is YCbCr instead of RGB"); + } + if (!TIFFFieldSet(tif,FIELD_BITSPERSAMPLE)) + { + TIFFWarningExt(tif->tif_clientdata,module, + "BitsPerSample tag is missing, assuming 8 bits per sample"); + if (!TIFFSetField(tif,TIFFTAG_BITSPERSAMPLE,8)) + goto bad; + } + if (!TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL)) + { + if (tif->tif_dir.td_photometric==PHOTOMETRIC_RGB) + { + TIFFWarningExt(tif->tif_clientdata,module, + "SamplesPerPixel tag is missing, " + "assuming correct SamplesPerPixel value is 3"); + if (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,3)) + goto bad; + } + if (tif->tif_dir.td_photometric==PHOTOMETRIC_YCBCR) + { + TIFFWarningExt(tif->tif_clientdata,module, + "SamplesPerPixel tag is missing, " + "applying correct SamplesPerPixel value of 3"); + if (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,3)) + goto bad; + } + else if ((tif->tif_dir.td_photometric==PHOTOMETRIC_MINISWHITE) + || (tif->tif_dir.td_photometric==PHOTOMETRIC_MINISBLACK)) + { + /* + * SamplesPerPixel tag is missing, but is not required + * by spec. Assume correct SamplesPerPixel value of 1. + */ + if (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,1)) + goto bad; + } + } + } + /* + * Verify Palette image has a Colormap. + */ + if (tif->tif_dir.td_photometric == PHOTOMETRIC_PALETTE && + !TIFFFieldSet(tif, FIELD_COLORMAP)) { + if ( tif->tif_dir.td_bitspersample>=8 && tif->tif_dir.td_samplesperpixel==3) + tif->tif_dir.td_photometric = PHOTOMETRIC_RGB; + else if (tif->tif_dir.td_bitspersample>=8) + tif->tif_dir.td_photometric = PHOTOMETRIC_MINISBLACK; + else { + MissingRequired(tif, "Colormap"); + goto bad; + } + } + /* + * OJPEG hack: + * We do no further messing with strip/tile offsets/bytecounts in OJPEG + * TIFFs + */ + if (tif->tif_dir.td_compression!=COMPRESSION_OJPEG) + { + /* + * Attempt to deal with a missing StripByteCounts tag. + */ + if (!TIFFFieldSet(tif, FIELD_STRIPBYTECOUNTS)) { + /* + * Some manufacturers violate the spec by not giving + * the size of the strips. In this case, assume there + * is one uncompressed strip of data. + */ + if ((tif->tif_dir.td_planarconfig == PLANARCONFIG_CONTIG && + tif->tif_dir.td_nstrips > 1) || + (tif->tif_dir.td_planarconfig == PLANARCONFIG_SEPARATE && + tif->tif_dir.td_nstrips != (uint32)tif->tif_dir.td_samplesperpixel)) { + MissingRequired(tif, "StripByteCounts"); + goto bad; + } + TIFFWarningExt(tif->tif_clientdata, module, + "TIFF directory is missing required " + "\"StripByteCounts\" field, calculating from imagelength"); + if (EstimateStripByteCounts(tif, dir, dircount) < 0) + goto bad; + /* + * Assume we have wrong StripByteCount value (in case + * of single strip) in following cases: + * - it is equal to zero along with StripOffset; + * - it is larger than file itself (in case of uncompressed + * image); + * - it is smaller than the size of the bytes per row + * multiplied on the number of rows. The last case should + * not be checked in the case of writing new image, + * because we may do not know the exact strip size + * until the whole image will be written and directory + * dumped out. + */ + #define BYTECOUNTLOOKSBAD \ + ( (tif->tif_dir.td_stripbytecount[0] == 0 && tif->tif_dir.td_stripoffset[0] != 0) || \ + (tif->tif_dir.td_compression == COMPRESSION_NONE && \ + tif->tif_dir.td_stripbytecount[0] > TIFFGetFileSize(tif) - tif->tif_dir.td_stripoffset[0]) || \ + (tif->tif_mode == O_RDONLY && \ + tif->tif_dir.td_compression == COMPRESSION_NONE && \ + tif->tif_dir.td_stripbytecount[0] < TIFFScanlineSize64(tif) * tif->tif_dir.td_imagelength) ) + + } else if (tif->tif_dir.td_nstrips == 1 + && _TIFFFillStriles(tif) + && tif->tif_dir.td_stripoffset[0] != 0 + && BYTECOUNTLOOKSBAD) { + /* + * XXX: Plexus (and others) sometimes give a value of + * zero for a tag when they don't know what the + * correct value is! Try and handle the simple case + * of estimating the size of a one strip image. + */ + TIFFWarningExt(tif->tif_clientdata, module, + "Bogus \"StripByteCounts\" field, ignoring and calculating from imagelength"); + if(EstimateStripByteCounts(tif, dir, dircount) < 0) + goto bad; + +#if !defined(DEFER_STRILE_LOAD) + } else if (tif->tif_dir.td_planarconfig == PLANARCONFIG_CONTIG + && tif->tif_dir.td_nstrips > 2 + && tif->tif_dir.td_compression == COMPRESSION_NONE + && tif->tif_dir.td_stripbytecount[0] != tif->tif_dir.td_stripbytecount[1] + && tif->tif_dir.td_stripbytecount[0] != 0 + && tif->tif_dir.td_stripbytecount[1] != 0 ) { + /* + * XXX: Some vendors fill StripByteCount array with + * absolutely wrong values (it can be equal to + * StripOffset array, for example). Catch this case + * here. + * + * We avoid this check if deferring strile loading + * as it would always force us to load the strip/tile + * information. + */ + TIFFWarningExt(tif->tif_clientdata, module, + "Wrong \"StripByteCounts\" field, ignoring and calculating from imagelength"); + if (EstimateStripByteCounts(tif, dir, dircount) < 0) + goto bad; +#endif /* !defined(DEFER_STRILE_LOAD) */ + } + } + if (dir) + { + _TIFFfree(dir); + dir=NULL; + } + if (!TIFFFieldSet(tif, FIELD_MAXSAMPLEVALUE)) + { + if (tif->tif_dir.td_bitspersample>=16) + tif->tif_dir.td_maxsamplevalue=0xFFFF; + else + tif->tif_dir.td_maxsamplevalue = (uint16)((1L<tif_dir.td_bitspersample)-1); + } + /* + * XXX: We can optimize checking for the strip bounds using the sorted + * bytecounts array. See also comments for TIFFAppendToStrip() + * function in tif_write.c. + */ +#if !defined(DEFER_STRILE_LOAD) + if (tif->tif_dir.td_nstrips > 1) { + uint32 strip; + + tif->tif_dir.td_stripbytecountsorted = 1; + for (strip = 1; strip < tif->tif_dir.td_nstrips; strip++) { + if (tif->tif_dir.td_stripoffset[strip - 1] > + tif->tif_dir.td_stripoffset[strip]) { + tif->tif_dir.td_stripbytecountsorted = 0; + break; + } + } + } +#endif /* !defined(DEFER_STRILE_LOAD) */ + + /* + * An opportunity for compression mode dependent tag fixup + */ + (*tif->tif_fixuptags)(tif); + + /* + * Some manufacturers make life difficult by writing + * large amounts of uncompressed data as a single strip. + * This is contrary to the recommendations of the spec. + * The following makes an attempt at breaking such images + * into strips closer to the recommended 8k bytes. A + * side effect, however, is that the RowsPerStrip tag + * value may be changed. + */ + if ((tif->tif_dir.td_planarconfig==PLANARCONFIG_CONTIG)&& + (tif->tif_dir.td_nstrips==1)&& + (tif->tif_dir.td_compression==COMPRESSION_NONE)&& + ((tif->tif_flags&(TIFF_STRIPCHOP|TIFF_ISTILED))==TIFF_STRIPCHOP)) + { + if ( !_TIFFFillStriles(tif) || !tif->tif_dir.td_stripbytecount ) + return 0; + ChopUpSingleUncompressedStrip(tif); + } + + /* + * Clear the dirty directory flag. + */ + tif->tif_flags &= ~TIFF_DIRTYDIRECT; + tif->tif_flags &= ~TIFF_DIRTYSTRIP; + + /* + * Reinitialize i/o since we are starting on a new directory. + */ + tif->tif_row = (uint32) -1; + tif->tif_curstrip = (uint32) -1; + tif->tif_col = (uint32) -1; + tif->tif_curtile = (uint32) -1; + tif->tif_tilesize = (tmsize_t) -1; + + tif->tif_scanlinesize = TIFFScanlineSize(tif); + if (!tif->tif_scanlinesize) { + TIFFErrorExt(tif->tif_clientdata, module, + "Cannot handle zero scanline size"); + return (0); + } + + if (isTiled(tif)) { + tif->tif_tilesize = TIFFTileSize(tif); + if (!tif->tif_tilesize) { + TIFFErrorExt(tif->tif_clientdata, module, + "Cannot handle zero tile size"); + return (0); + } + } else { + if (!TIFFStripSize(tif)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Cannot handle zero strip size"); + return (0); + } + } + return (1); +bad: + if (dir) + _TIFFfree(dir); + return (0); +} + +static void +TIFFReadDirectoryCheckOrder(TIFF* tif, TIFFDirEntry* dir, uint16 dircount) +{ + static const char module[] = "TIFFReadDirectoryCheckOrder"; + uint16 m; + uint16 n; + TIFFDirEntry* o; + m=0; + for (n=0, o=dir; ntdir_tagtif_clientdata,module, + "Invalid TIFF directory; tags are not sorted in ascending order"); + break; + } + m=o->tdir_tag+1; + } +} + +static TIFFDirEntry* +TIFFReadDirectoryFindEntry(TIFF* tif, TIFFDirEntry* dir, uint16 dircount, uint16 tagid) +{ + TIFFDirEntry* m; + uint16 n; + (void) tif; + for (m=dir, n=0; ntdir_tag==tagid) + return(m); + } + return(0); +} + +static void +TIFFReadDirectoryFindFieldInfo(TIFF* tif, uint16 tagid, uint32* fii) +{ + int32 ma,mb,mc; + ma=-1; + mc=(int32)tif->tif_nfields; + while (1) + { + if (ma+1==mc) + { + *fii = FAILED_FII; + return; + } + mb=(ma+mc)/2; + if (tif->tif_fields[mb]->field_tag==(uint32)tagid) + break; + if (tif->tif_fields[mb]->field_tag<(uint32)tagid) + ma=mb; + else + mc=mb; + } + while (1) + { + if (mb==0) + break; + if (tif->tif_fields[mb-1]->field_tag!=(uint32)tagid) + break; + mb--; + } + *fii=mb; +} + +/* + * Read custom directory from the arbitarry offset. + * The code is very similar to TIFFReadDirectory(). + */ +int +TIFFReadCustomDirectory(TIFF* tif, toff_t diroff, + const TIFFFieldArray* infoarray) +{ + static const char module[] = "TIFFReadCustomDirectory"; + TIFFDirEntry* dir; + uint16 dircount; + TIFFDirEntry* dp; + uint16 di; + const TIFFField* fip; + uint32 fii; + _TIFFSetupFields(tif, infoarray); + dircount=TIFFFetchDirectory(tif,diroff,&dir,NULL); + if (!dircount) + { + TIFFErrorExt(tif->tif_clientdata,module, + "Failed to read custom directory at offset " TIFF_UINT64_FORMAT,diroff); + return 0; + } + TIFFFreeDirectory(tif); + _TIFFmemset(&tif->tif_dir, 0, sizeof(TIFFDirectory)); + TIFFReadDirectoryCheckOrder(tif,dir,dircount); + for (di=0, dp=dir; ditdir_tag,&fii); + if (fii == FAILED_FII) + { + TIFFWarningExt(tif->tif_clientdata, module, + "Unknown field with tag %d (0x%x) encountered", + dp->tdir_tag, dp->tdir_tag); + if (!_TIFFMergeFields(tif, _TIFFCreateAnonField(tif, + dp->tdir_tag, + (TIFFDataType) dp->tdir_type), + 1)) { + TIFFWarningExt(tif->tif_clientdata, module, + "Registering anonymous field with tag %d (0x%x) failed", + dp->tdir_tag, dp->tdir_tag); + dp->tdir_tag=IGNORE; + } else { + TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); + assert( fii != FAILED_FII ); + } + } + if (dp->tdir_tag!=IGNORE) + { + fip=tif->tif_fields[fii]; + if (fip->field_bit==FIELD_IGNORE) + dp->tdir_tag=IGNORE; + else + { + /* check data type */ + while ((fip->field_type!=TIFF_ANY)&&(fip->field_type!=dp->tdir_type)) + { + fii++; + if ((fii==tif->tif_nfields)|| + (tif->tif_fields[fii]->field_tag!=(uint32)dp->tdir_tag)) + { + fii=0xFFFF; + break; + } + fip=tif->tif_fields[fii]; + } + if (fii==0xFFFF) + { + TIFFWarningExt(tif->tif_clientdata, module, + "Wrong data type %d for \"%s\"; tag ignored", + dp->tdir_type,fip->field_name); + dp->tdir_tag=IGNORE; + } + else + { + /* check count if known in advance */ + if ((fip->field_readcount!=TIFF_VARIABLE)&& + (fip->field_readcount!=TIFF_VARIABLE2)) + { + uint32 expected; + if (fip->field_readcount==TIFF_SPP) + expected=(uint32)tif->tif_dir.td_samplesperpixel; + else + expected=(uint32)fip->field_readcount; + if (!CheckDirCount(tif,dp,expected)) + dp->tdir_tag=IGNORE; + } + } + } + switch (dp->tdir_tag) + { + case IGNORE: + break; + case EXIFTAG_SUBJECTDISTANCE: + (void) TIFFFetchSubjectDistance(tif,dp); + break; + default: + (void) TIFFFetchNormalTag(tif, dp, TRUE); + break; + } + } + } + if (dir) + _TIFFfree(dir); + return 1; +} + +/* + * EXIF is important special case of custom IFD, so we have a special + * function to read it. + */ +int +TIFFReadEXIFDirectory(TIFF* tif, toff_t diroff) +{ + const TIFFFieldArray* exifFieldArray; + exifFieldArray = _TIFFGetExifFields(); + return TIFFReadCustomDirectory(tif, diroff, exifFieldArray); +} + +static int +EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount) +{ + static const char module[] = "EstimateStripByteCounts"; + + TIFFDirEntry *dp; + TIFFDirectory *td = &tif->tif_dir; + uint32 strip; + + _TIFFFillStriles( tif ); + + if (td->td_stripbytecount) + _TIFFfree(td->td_stripbytecount); + td->td_stripbytecount = (uint64*) + _TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64), + "for \"StripByteCounts\" array"); + if( td->td_stripbytecount == NULL ) + return -1; + + if (td->td_compression != COMPRESSION_NONE) { + uint64 space; + uint64 filesize; + uint16 n; + filesize = TIFFGetFileSize(tif); + if (!(tif->tif_flags&TIFF_BIGTIFF)) + space=sizeof(TIFFHeaderClassic)+2+dircount*12+4; + else + space=sizeof(TIFFHeaderBig)+8+dircount*20+8; + /* calculate amount of space used by indirect values */ + for (dp = dir, n = dircount; n > 0; n--, dp++) + { + uint32 typewidth = TIFFDataWidth((TIFFDataType) dp->tdir_type); + uint64 datasize; + typewidth = TIFFDataWidth((TIFFDataType) dp->tdir_type); + if (typewidth == 0) { + TIFFErrorExt(tif->tif_clientdata, module, + "Cannot determine size of unknown tag type %d", + dp->tdir_type); + return -1; + } + datasize=(uint64)typewidth*dp->tdir_count; + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + if (datasize<=4) + datasize=0; + } + else + { + if (datasize<=8) + datasize=0; + } + space+=datasize; + } + space = filesize - space; + if (td->td_planarconfig == PLANARCONFIG_SEPARATE) + space /= td->td_samplesperpixel; + for (strip = 0; strip < td->td_nstrips; strip++) + td->td_stripbytecount[strip] = space; + /* + * This gross hack handles the case were the offset to + * the last strip is past the place where we think the strip + * should begin. Since a strip of data must be contiguous, + * it's safe to assume that we've overestimated the amount + * of data in the strip and trim this number back accordingly. + */ + strip--; + if (td->td_stripoffset[strip]+td->td_stripbytecount[strip] > filesize) + td->td_stripbytecount[strip] = filesize - td->td_stripoffset[strip]; + } else if (isTiled(tif)) { + uint64 bytespertile = TIFFTileSize64(tif); + + for (strip = 0; strip < td->td_nstrips; strip++) + td->td_stripbytecount[strip] = bytespertile; + } else { + uint64 rowbytes = TIFFScanlineSize64(tif); + uint32 rowsperstrip = td->td_imagelength/td->td_stripsperimage; + for (strip = 0; strip < td->td_nstrips; strip++) + td->td_stripbytecount[strip] = rowbytes * rowsperstrip; + } + TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS); + if (!TIFFFieldSet(tif, FIELD_ROWSPERSTRIP)) + td->td_rowsperstrip = td->td_imagelength; + return 1; +} + +static void +MissingRequired(TIFF* tif, const char* tagname) +{ + static const char module[] = "MissingRequired"; + + TIFFErrorExt(tif->tif_clientdata, module, + "TIFF directory is missing required \"%s\" field", + tagname); +} + +/* + * Check the directory offset against the list of already seen directory + * offsets. This is a trick to prevent IFD looping. The one can create TIFF + * file with looped directory pointers. We will maintain a list of already + * seen directories and check every IFD offset against that list. + */ +static int +TIFFCheckDirOffset(TIFF* tif, uint64 diroff) +{ + uint16 n; + + if (diroff == 0) /* no more directories */ + return 0; + + for (n = 0; n < tif->tif_dirnumber && tif->tif_dirlist; n++) { + if (tif->tif_dirlist[n] == diroff) + return 0; + } + + tif->tif_dirnumber++; + + if (tif->tif_dirnumber > tif->tif_dirlistsize) { + uint64* new_dirlist; + + /* + * XXX: Reduce memory allocation granularity of the dirlist + * array. + */ + new_dirlist = (uint64*)_TIFFCheckRealloc(tif, tif->tif_dirlist, + tif->tif_dirnumber, 2 * sizeof(uint64), "for IFD list"); + if (!new_dirlist) + return 0; + tif->tif_dirlistsize = 2 * tif->tif_dirnumber; + tif->tif_dirlist = new_dirlist; + } + + tif->tif_dirlist[tif->tif_dirnumber - 1] = diroff; + + return 1; +} + +/* + * Check the count field of a directory entry against a known value. The + * caller is expected to skip/ignore the tag if there is a mismatch. + */ +static int +CheckDirCount(TIFF* tif, TIFFDirEntry* dir, uint32 count) +{ + if ((uint64)count > dir->tdir_count) { + const TIFFField* fip = TIFFFieldWithTag(tif, dir->tdir_tag); + TIFFWarningExt(tif->tif_clientdata, tif->tif_name, + "incorrect count for field \"%s\" (" TIFF_UINT64_FORMAT ", expecting %u); tag ignored", + fip ? fip->field_name : "unknown tagname", + dir->tdir_count, count); + return (0); + } else if ((uint64)count < dir->tdir_count) { + const TIFFField* fip = TIFFFieldWithTag(tif, dir->tdir_tag); + TIFFWarningExt(tif->tif_clientdata, tif->tif_name, + "incorrect count for field \"%s\" (" TIFF_UINT64_FORMAT ", expecting %u); tag trimmed", + fip ? fip->field_name : "unknown tagname", + dir->tdir_count, count); + dir->tdir_count = count; + return (1); + } + return (1); +} + +/* + * Read IFD structure from the specified offset. If the pointer to + * nextdiroff variable has been specified, read it too. Function returns a + * number of fields in the directory or 0 if failed. + */ +static uint16 +TIFFFetchDirectory(TIFF* tif, uint64 diroff, TIFFDirEntry** pdir, + uint64 *nextdiroff) +{ + static const char module[] = "TIFFFetchDirectory"; + + void* origdir; + uint16 dircount16; + uint32 dirsize; + TIFFDirEntry* dir; + uint8* ma; + TIFFDirEntry* mb; + uint16 n; + + assert(pdir); + + tif->tif_diroff = diroff; + if (nextdiroff) + *nextdiroff = 0; + if (!isMapped(tif)) { + if (!SeekOK(tif, tif->tif_diroff)) { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Seek error accessing TIFF directory", + tif->tif_name); + return 0; + } + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + if (!ReadOK(tif, &dircount16, sizeof (uint16))) { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Can not read TIFF directory count", + tif->tif_name); + return 0; + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabShort(&dircount16); + if (dircount16>4096) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Sanity check on directory count failed, this is probably not a valid IFD offset"); + return 0; + } + dirsize = 12; + } else { + uint64 dircount64; + if (!ReadOK(tif, &dircount64, sizeof (uint64))) { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Can not read TIFF directory count", + tif->tif_name); + return 0; + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong8(&dircount64); + if (dircount64>4096) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Sanity check on directory count failed, this is probably not a valid IFD offset"); + return 0; + } + dircount16 = (uint16)dircount64; + dirsize = 20; + } + origdir = _TIFFCheckMalloc(tif, dircount16, + dirsize, "to read TIFF directory"); + if (origdir == NULL) + return 0; + if (!ReadOK(tif, origdir, (tmsize_t)(dircount16*dirsize))) { + TIFFErrorExt(tif->tif_clientdata, module, + "%.100s: Can not read TIFF directory", + tif->tif_name); + _TIFFfree(origdir); + return 0; + } + /* + * Read offset to next directory for sequential scans if + * needed. + */ + if (nextdiroff) + { + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + uint32 nextdiroff32; + if (!ReadOK(tif, &nextdiroff32, sizeof(uint32))) + nextdiroff32 = 0; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(&nextdiroff32); + *nextdiroff=nextdiroff32; + } else { + if (!ReadOK(tif, nextdiroff, sizeof(uint64))) + *nextdiroff = 0; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8(nextdiroff); + } + } + } else { + tmsize_t m; + tmsize_t off = (tmsize_t) tif->tif_diroff; + if ((uint64)off!=tif->tif_diroff) + { + TIFFErrorExt(tif->tif_clientdata,module,"Can not read TIFF directory count"); + return(0); + } + + /* + * Check for integer overflow when validating the dir_off, + * otherwise a very high offset may cause an OOB read and + * crash the client. Make two comparisons instead of + * + * off + sizeof(uint16) > tif->tif_size + * + * to avoid overflow. + */ + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + m=off+sizeof(uint16); + if ((mtif->tif_size)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Can not read TIFF directory count"); + return 0; + } else { + _TIFFmemcpy(&dircount16, tif->tif_base + off, + sizeof(uint16)); + } + off += sizeof (uint16); + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabShort(&dircount16); + if (dircount16>4096) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Sanity check on directory count failed, this is probably not a valid IFD offset"); + return 0; + } + dirsize = 12; + } + else + { + tmsize_t m; + uint64 dircount64; + m=off+sizeof(uint64); + if ((mtif->tif_size)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Can not read TIFF directory count"); + return 0; + } else { + _TIFFmemcpy(&dircount64, tif->tif_base + off, + sizeof(uint64)); + } + off += sizeof (uint64); + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong8(&dircount64); + if (dircount64>4096) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Sanity check on directory count failed, this is probably not a valid IFD offset"); + return 0; + } + dircount16 = (uint16)dircount64; + dirsize = 20; + } + if (dircount16 == 0 ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Sanity check on directory count failed, zero tag directories not supported"); + return 0; + } + origdir = _TIFFCheckMalloc(tif, dircount16, + dirsize, + "to read TIFF directory"); + if (origdir == NULL) + return 0; + m=off+dircount16*dirsize; + if ((mtif->tif_size)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Can not read TIFF directory"); + _TIFFfree(origdir); + return 0; + } else { + _TIFFmemcpy(origdir, tif->tif_base + off, + dircount16 * dirsize); + } + if (nextdiroff) { + off += dircount16 * dirsize; + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + uint32 nextdiroff32; + m=off+sizeof(uint32); + if ((mtif->tif_size)) + nextdiroff32 = 0; + else + _TIFFmemcpy(&nextdiroff32, tif->tif_base + off, + sizeof (uint32)); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(&nextdiroff32); + *nextdiroff = nextdiroff32; + } + else + { + m=off+sizeof(uint64); + if ((mtif->tif_size)) + *nextdiroff = 0; + else + _TIFFmemcpy(nextdiroff, tif->tif_base + off, + sizeof (uint64)); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8(nextdiroff); + } + } + } + dir = (TIFFDirEntry*)_TIFFCheckMalloc(tif, dircount16, + sizeof(TIFFDirEntry), + "to read TIFF directory"); + if (dir==0) + { + _TIFFfree(origdir); + return 0; + } + ma=(uint8*)origdir; + mb=dir; + for (n=0; ntif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)ma); + mb->tdir_tag=*(uint16*)ma; + ma+=sizeof(uint16); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)ma); + mb->tdir_type=*(uint16*)ma; + ma+=sizeof(uint16); + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)ma); + mb->tdir_count=(uint64)(*(uint32*)ma); + ma+=sizeof(uint32); + *(uint32*)(&mb->tdir_offset)=*(uint32*)ma; + ma+=sizeof(uint32); + } + else + { + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)ma); + mb->tdir_count=TIFFReadUInt64(ma); + ma+=sizeof(uint64); + mb->tdir_offset.toff_long8=TIFFReadUInt64(ma); + ma+=sizeof(uint64); + } + mb++; + } + _TIFFfree(origdir); + *pdir = dir; + return dircount16; +} + +/* + * Fetch a tag that is not handled by special case code. + */ +static int +TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover) +{ + static const char module[] = "TIFFFetchNormalTag"; + enum TIFFReadDirEntryErr err; + uint32 fii; + const TIFFField* fip = NULL; + TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); + if( fii == FAILED_FII ) + { + TIFFErrorExt(tif->tif_clientdata, "TIFFFetchNormalTag", + "No definition found for tag %d", + dp->tdir_tag); + return 0; + } + fip=tif->tif_fields[fii]; + assert(fip->set_field_type!=TIFF_SETGET_OTHER); /* if so, we shouldn't arrive here but deal with this in specialized code */ + assert(fip->set_field_type!=TIFF_SETGET_INT); /* if so, we shouldn't arrive here as this is only the case for pseudo-tags */ + err=TIFFReadDirEntryErrOk; + switch (fip->set_field_type) + { + case TIFF_SETGET_UNDEFINED: + break; + case TIFF_SETGET_ASCII: + { + uint8* data; + assert(fip->field_passcount==0); + err=TIFFReadDirEntryByteArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + uint8* ma; + uint32 mb; + int n; + ma=data; + mb=0; + while (mb<(uint32)dp->tdir_count) + { + if (*ma==0) + break; + ma++; + mb++; + } + if (mb+1<(uint32)dp->tdir_count) + TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" contains null byte in value; value incorrectly truncated during reading due to implementation limitations",fip->field_name); + else if (mb+1>(uint32)dp->tdir_count) + { + uint8* o; + TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte",fip->field_name); + if ((uint32)dp->tdir_count+1!=dp->tdir_count+1) + o=NULL; + else + o=_TIFFmalloc((uint32)dp->tdir_count+1); + if (o==NULL) + { + if (data!=NULL) + _TIFFfree(data); + return(0); + } + _TIFFmemcpy(o,data,(uint32)dp->tdir_count); + o[(uint32)dp->tdir_count]=0; + if (data!=0) + _TIFFfree(data); + data=o; + } + n=TIFFSetField(tif,dp->tdir_tag,data); + if (data!=0) + _TIFFfree(data); + if (!n) + return(0); + } + } + break; + case TIFF_SETGET_UINT8: + { + uint8 data=0; + assert(fip->field_readcount==1); + assert(fip->field_passcount==0); + err=TIFFReadDirEntryByte(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + if (!TIFFSetField(tif,dp->tdir_tag,data)) + return(0); + } + } + break; + case TIFF_SETGET_UINT16: + { + uint16 data; + assert(fip->field_readcount==1); + assert(fip->field_passcount==0); + err=TIFFReadDirEntryShort(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + if (!TIFFSetField(tif,dp->tdir_tag,data)) + return(0); + } + } + break; + case TIFF_SETGET_UINT32: + { + uint32 data; + assert(fip->field_readcount==1); + assert(fip->field_passcount==0); + err=TIFFReadDirEntryLong(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + if (!TIFFSetField(tif,dp->tdir_tag,data)) + return(0); + } + } + break; + case TIFF_SETGET_UINT64: + { + uint64 data; + assert(fip->field_readcount==1); + assert(fip->field_passcount==0); + err=TIFFReadDirEntryLong8(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + if (!TIFFSetField(tif,dp->tdir_tag,data)) + return(0); + } + } + break; + case TIFF_SETGET_FLOAT: + { + float data; + assert(fip->field_readcount==1); + assert(fip->field_passcount==0); + err=TIFFReadDirEntryFloat(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + if (!TIFFSetField(tif,dp->tdir_tag,data)) + return(0); + } + } + break; + case TIFF_SETGET_DOUBLE: + { + double data; + assert(fip->field_readcount==1); + assert(fip->field_passcount==0); + err=TIFFReadDirEntryDouble(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + if (!TIFFSetField(tif,dp->tdir_tag,data)) + return(0); + } + } + break; + case TIFF_SETGET_IFD8: + { + uint64 data; + assert(fip->field_readcount==1); + assert(fip->field_passcount==0); + err=TIFFReadDirEntryIfd8(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + if (!TIFFSetField(tif,dp->tdir_tag,data)) + return(0); + } + } + break; + case TIFF_SETGET_UINT16_PAIR: + { + uint16* data; + assert(fip->field_readcount==2); + assert(fip->field_passcount==0); + if (dp->tdir_count!=2) { + TIFFWarningExt(tif->tif_clientdata,module, + "incorrect count for field \"%s\", expected 2, got %d", + fip->field_name,(int)dp->tdir_count); + return(0); + } + err=TIFFReadDirEntryShortArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,data[0],data[1]); + _TIFFfree(data); + if (!m) + return(0); + } + } + break; + case TIFF_SETGET_C0_UINT8: + { + uint8* data; + assert(fip->field_readcount>=1); + assert(fip->field_passcount==0); + if (dp->tdir_count!=(uint64)fip->field_readcount) { + TIFFWarningExt(tif->tif_clientdata,module, + "incorrect count for field \"%s\", expected %d, got %d", + fip->field_name,(int) fip->field_readcount, (int)dp->tdir_count); + return 0; + } + else + { + err=TIFFReadDirEntryByteArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + } + break; + case TIFF_SETGET_C0_UINT16: + { + uint16* data; + assert(fip->field_readcount>=1); + assert(fip->field_passcount==0); + if (dp->tdir_count!=(uint64)fip->field_readcount) + /* corrupt file */; + else + { + err=TIFFReadDirEntryShortArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + } + break; + case TIFF_SETGET_C0_UINT32: + { + uint32* data; + assert(fip->field_readcount>=1); + assert(fip->field_passcount==0); + if (dp->tdir_count!=(uint64)fip->field_readcount) + /* corrupt file */; + else + { + err=TIFFReadDirEntryLongArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + } + break; + case TIFF_SETGET_C0_FLOAT: + { + float* data; + assert(fip->field_readcount>=1); + assert(fip->field_passcount==0); + if (dp->tdir_count!=(uint64)fip->field_readcount) + /* corrupt file */; + else + { + err=TIFFReadDirEntryFloatArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + } + break; + case TIFF_SETGET_C16_ASCII: + { + uint8* data; + assert(fip->field_readcount==TIFF_VARIABLE); + assert(fip->field_passcount==1); + if (dp->tdir_count>0xFFFF) + err=TIFFReadDirEntryErrCount; + else + { + err=TIFFReadDirEntryByteArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + } + break; + case TIFF_SETGET_C16_UINT8: + { + uint8* data; + assert(fip->field_readcount==TIFF_VARIABLE); + assert(fip->field_passcount==1); + if (dp->tdir_count>0xFFFF) + err=TIFFReadDirEntryErrCount; + else + { + err=TIFFReadDirEntryByteArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + } + break; + case TIFF_SETGET_C16_UINT16: + { + uint16* data; + assert(fip->field_readcount==TIFF_VARIABLE); + assert(fip->field_passcount==1); + if (dp->tdir_count>0xFFFF) + err=TIFFReadDirEntryErrCount; + else + { + err=TIFFReadDirEntryShortArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + } + break; + case TIFF_SETGET_C16_UINT32: + { + uint32* data; + assert(fip->field_readcount==TIFF_VARIABLE); + assert(fip->field_passcount==1); + if (dp->tdir_count>0xFFFF) + err=TIFFReadDirEntryErrCount; + else + { + err=TIFFReadDirEntryLongArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + } + break; + case TIFF_SETGET_C16_UINT64: + { + uint64* data; + assert(fip->field_readcount==TIFF_VARIABLE); + assert(fip->field_passcount==1); + if (dp->tdir_count>0xFFFF) + err=TIFFReadDirEntryErrCount; + else + { + err=TIFFReadDirEntryLong8Array(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + } + break; + case TIFF_SETGET_C16_FLOAT: + { + float* data; + assert(fip->field_readcount==TIFF_VARIABLE); + assert(fip->field_passcount==1); + if (dp->tdir_count>0xFFFF) + err=TIFFReadDirEntryErrCount; + else + { + err=TIFFReadDirEntryFloatArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + } + break; + case TIFF_SETGET_C16_DOUBLE: + { + double* data; + assert(fip->field_readcount==TIFF_VARIABLE); + assert(fip->field_passcount==1); + if (dp->tdir_count>0xFFFF) + err=TIFFReadDirEntryErrCount; + else + { + err=TIFFReadDirEntryDoubleArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + } + break; + case TIFF_SETGET_C16_IFD8: + { + uint64* data; + assert(fip->field_readcount==TIFF_VARIABLE); + assert(fip->field_passcount==1); + if (dp->tdir_count>0xFFFF) + err=TIFFReadDirEntryErrCount; + else + { + err=TIFFReadDirEntryIfd8Array(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + } + break; + case TIFF_SETGET_C32_ASCII: + { + uint8* data; + assert(fip->field_readcount==TIFF_VARIABLE2); + assert(fip->field_passcount==1); + err=TIFFReadDirEntryByteArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + break; + case TIFF_SETGET_C32_UINT8: + { + uint8* data; + assert(fip->field_readcount==TIFF_VARIABLE2); + assert(fip->field_passcount==1); + err=TIFFReadDirEntryByteArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + break; + case TIFF_SETGET_C32_SINT8: + { + int8* data = NULL; + assert(fip->field_readcount==TIFF_VARIABLE2); + assert(fip->field_passcount==1); + err=TIFFReadDirEntrySbyteArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + break; + case TIFF_SETGET_C32_UINT16: + { + uint16* data; + assert(fip->field_readcount==TIFF_VARIABLE2); + assert(fip->field_passcount==1); + err=TIFFReadDirEntryShortArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + break; + case TIFF_SETGET_C32_SINT16: + { + int16* data = NULL; + assert(fip->field_readcount==TIFF_VARIABLE2); + assert(fip->field_passcount==1); + err=TIFFReadDirEntrySshortArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + break; + case TIFF_SETGET_C32_UINT32: + { + uint32* data; + assert(fip->field_readcount==TIFF_VARIABLE2); + assert(fip->field_passcount==1); + err=TIFFReadDirEntryLongArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + break; + case TIFF_SETGET_C32_SINT32: + { + int32* data = NULL; + assert(fip->field_readcount==TIFF_VARIABLE2); + assert(fip->field_passcount==1); + err=TIFFReadDirEntrySlongArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + break; + case TIFF_SETGET_C32_UINT64: + { + uint64* data; + assert(fip->field_readcount==TIFF_VARIABLE2); + assert(fip->field_passcount==1); + err=TIFFReadDirEntryLong8Array(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + break; + case TIFF_SETGET_C32_SINT64: + { + int64* data = NULL; + assert(fip->field_readcount==TIFF_VARIABLE2); + assert(fip->field_passcount==1); + err=TIFFReadDirEntrySlong8Array(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + break; + case TIFF_SETGET_C32_FLOAT: + { + float* data; + assert(fip->field_readcount==TIFF_VARIABLE2); + assert(fip->field_passcount==1); + err=TIFFReadDirEntryFloatArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + break; + case TIFF_SETGET_C32_DOUBLE: + { + double* data; + assert(fip->field_readcount==TIFF_VARIABLE2); + assert(fip->field_passcount==1); + err=TIFFReadDirEntryDoubleArray(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + break; + case TIFF_SETGET_C32_IFD8: + { + uint64* data; + assert(fip->field_readcount==TIFF_VARIABLE2); + assert(fip->field_passcount==1); + err=TIFFReadDirEntryIfd8Array(tif,dp,&data); + if (err==TIFFReadDirEntryErrOk) + { + int m; + m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); + if (data!=0) + _TIFFfree(data); + if (!m) + return(0); + } + } + break; + default: + assert(0); /* we should never get here */ + break; + } + if (err!=TIFFReadDirEntryErrOk) + { + TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",recover); + return(0); + } + return(1); +} + +/* + * Fetch a set of offsets or lengths. + * While this routine says "strips", in fact it's also used for tiles. + */ +static int +TIFFFetchStripThing(TIFF* tif, TIFFDirEntry* dir, uint32 nstrips, uint64** lpp) +{ + static const char module[] = "TIFFFetchStripThing"; + enum TIFFReadDirEntryErr err; + uint64* data; + err=TIFFReadDirEntryLong8Array(tif,dir,&data); + if (err!=TIFFReadDirEntryErrOk) + { + const TIFFField* fip = TIFFFieldWithTag(tif,dir->tdir_tag); + TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0); + return(0); + } + if (dir->tdir_count!=(uint64)nstrips) + { + uint64* resizeddata; + resizeddata=(uint64*)_TIFFCheckMalloc(tif,nstrips,sizeof(uint64),"for strip array"); + if (resizeddata==0) { + _TIFFfree(data); + return(0); + } + if (dir->tdir_count<(uint64)nstrips) + { + _TIFFmemcpy(resizeddata,data,(uint32)dir->tdir_count*sizeof(uint64)); + _TIFFmemset(resizeddata+(uint32)dir->tdir_count,0,(nstrips-(uint32)dir->tdir_count)*sizeof(uint64)); + } + else + _TIFFmemcpy(resizeddata,data,nstrips*sizeof(uint64)); + _TIFFfree(data); + data=resizeddata; + } + *lpp=data; + return(1); +} + +/* + * Fetch and set the SubjectDistance EXIF tag. + */ +static int +TIFFFetchSubjectDistance(TIFF* tif, TIFFDirEntry* dir) +{ + static const char module[] = "TIFFFetchSubjectDistance"; + enum TIFFReadDirEntryErr err; + UInt64Aligned_t m; + m.l=0; + assert(sizeof(double)==8); + assert(sizeof(uint64)==8); + assert(sizeof(uint32)==4); + if (dir->tdir_count!=1) + err=TIFFReadDirEntryErrCount; + else if (dir->tdir_type!=TIFF_RATIONAL) + err=TIFFReadDirEntryErrType; + else + { + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + uint32 offset; + offset=*(uint32*)(&dir->tdir_offset); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(&offset); + err=TIFFReadDirEntryData(tif,offset,8,m.i); + } + else + { + m.l=dir->tdir_offset.toff_long8; + err=TIFFReadDirEntryErrOk; + } + } + if (err==TIFFReadDirEntryErrOk) + { + double n; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong(m.i,2); + if (m.i[0]==0) + n=0.0; + else if (m.i[0]==0xFFFFFFFF) + /* + * XXX: Numerator 0xFFFFFFFF means that we have infinite + * distance. Indicate that with a negative floating point + * SubjectDistance value. + */ + n=-1.0; + else + n=(double)m.i[0]/(double)m.i[1]; + return(TIFFSetField(tif,dir->tdir_tag,n)); + } + else + { + TIFFReadDirEntryOutputErr(tif,err,module,"SubjectDistance",TRUE); + return(0); + } +} + +/* + * Replace a single strip (tile) of uncompressed data by multiple strips + * (tiles), each approximately STRIP_SIZE_DEFAULT bytes. This is useful for + * dealing with large images or for dealing with machines with a limited + * amount memory. + */ +static void +ChopUpSingleUncompressedStrip(TIFF* tif) +{ + register TIFFDirectory *td = &tif->tif_dir; + uint64 bytecount; + uint64 offset; + uint32 rowblock; + uint64 rowblockbytes; + uint64 stripbytes; + uint32 strip; + uint64 nstrips64; + uint32 nstrips32; + uint32 rowsperstrip; + uint64* newcounts; + uint64* newoffsets; + + bytecount = td->td_stripbytecount[0]; + offset = td->td_stripoffset[0]; + assert(td->td_planarconfig == PLANARCONFIG_CONTIG); + if ((td->td_photometric == PHOTOMETRIC_YCBCR)&& + (!isUpSampled(tif))) + rowblock = td->td_ycbcrsubsampling[1]; + else + rowblock = 1; + rowblockbytes = TIFFVTileSize64(tif, rowblock); + /* + * Make the rows hold at least one scanline, but fill specified amount + * of data if possible. + */ + if (rowblockbytes > STRIP_SIZE_DEFAULT) { + stripbytes = rowblockbytes; + rowsperstrip = rowblock; + } else if (rowblockbytes > 0 ) { + uint32 rowblocksperstrip; + rowblocksperstrip = (uint32) (STRIP_SIZE_DEFAULT / rowblockbytes); + rowsperstrip = rowblocksperstrip * rowblock; + stripbytes = rowblocksperstrip * rowblockbytes; + } + else + return; + + /* + * never increase the number of strips in an image + */ + if (rowsperstrip >= td->td_rowsperstrip) + return; + nstrips64 = TIFFhowmany_64(bytecount, stripbytes); + if ((nstrips64==0)||(nstrips64>0xFFFFFFFF)) /* something is wonky, do nothing. */ + return; + nstrips32 = (uint32)nstrips64; + + newcounts = (uint64*) _TIFFCheckMalloc(tif, nstrips32, sizeof (uint64), + "for chopped \"StripByteCounts\" array"); + newoffsets = (uint64*) _TIFFCheckMalloc(tif, nstrips32, sizeof (uint64), + "for chopped \"StripOffsets\" array"); + if (newcounts == NULL || newoffsets == NULL) { + /* + * Unable to allocate new strip information, give up and use + * the original one strip information. + */ + if (newcounts != NULL) + _TIFFfree(newcounts); + if (newoffsets != NULL) + _TIFFfree(newoffsets); + return; + } + /* + * Fill the strip information arrays with new bytecounts and offsets + * that reflect the broken-up format. + */ + for (strip = 0; strip < nstrips32; strip++) { + if (stripbytes > bytecount) + stripbytes = bytecount; + newcounts[strip] = stripbytes; + newoffsets[strip] = offset; + offset += stripbytes; + bytecount -= stripbytes; + } + /* + * Replace old single strip info with multi-strip info. + */ + td->td_stripsperimage = td->td_nstrips = nstrips32; + TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip); + + _TIFFfree(td->td_stripbytecount); + _TIFFfree(td->td_stripoffset); + td->td_stripbytecount = newcounts; + td->td_stripoffset = newoffsets; + td->td_stripbytecountsorted = 1; +} + +int _TIFFFillStriles( TIFF *tif ) +{ +#if defined(DEFER_STRILE_LOAD) + register TIFFDirectory *td = &tif->tif_dir; + int return_value = 1; + + if( td->td_stripoffset != NULL ) + return 1; + + if( td->td_stripoffset_entry.tdir_count == 0 ) + return 0; + + if (!TIFFFetchStripThing(tif,&(td->td_stripoffset_entry), + td->td_nstrips,&td->td_stripoffset)) + { + return_value = 0; + } + + if (!TIFFFetchStripThing(tif,&(td->td_stripbytecount_entry), + td->td_nstrips,&td->td_stripbytecount)) + { + return_value = 0; + } + + _TIFFmemset( &(td->td_stripoffset_entry), 0, sizeof(TIFFDirEntry)); + _TIFFmemset( &(td->td_stripbytecount_entry), 0, sizeof(TIFFDirEntry)); + + if (tif->tif_dir.td_nstrips > 1 && return_value == 1 ) { + uint32 strip; + + tif->tif_dir.td_stripbytecountsorted = 1; + for (strip = 1; strip < tif->tif_dir.td_nstrips; strip++) { + if (tif->tif_dir.td_stripoffset[strip - 1] > + tif->tif_dir.td_stripoffset[strip]) { + tif->tif_dir.td_stripbytecountsorted = 0; + break; + } + } + } + + return return_value; +#else /* !defined(DEFER_STRILE_LOAD) */ + (void) tif; + return 1; +#endif +} + + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_dirwrite.c b/Source/LibTIFF4/tif_dirwrite.c index 312d6a0..5fed7f5 100644 --- a/Source/LibTIFF4/tif_dirwrite.c +++ b/Source/LibTIFF4/tif_dirwrite.c @@ -1,2910 +1,2910 @@ -/* $Id: tif_dirwrite.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * - * Directory Write Support Routines. - */ -#include "tiffiop.h" - -#ifdef HAVE_IEEEFP -#define TIFFCvtNativeToIEEEFloat(tif, n, fp) -#define TIFFCvtNativeToIEEEDouble(tif, n, dp) -#else -extern void TIFFCvtNativeToIEEEFloat(TIFF* tif, uint32 n, float* fp); -extern void TIFFCvtNativeToIEEEDouble(TIFF* tif, uint32 n, double* dp); -#endif - -static int TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff); - -static int TIFFWriteDirectoryTagSampleformatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value); -#if 0 -static int TIFFWriteDirectoryTagSampleformatPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value); -#endif - -static int TIFFWriteDirectoryTagAscii(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, char* value); -static int TIFFWriteDirectoryTagUndefinedArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value); -#ifdef notdef -static int TIFFWriteDirectoryTagByte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint8 value); -#endif -static int TIFFWriteDirectoryTagByteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value); -#if 0 -static int TIFFWriteDirectoryTagBytePerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint8 value); -#endif -#ifdef notdef -static int TIFFWriteDirectoryTagSbyte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int8 value); -#endif -static int TIFFWriteDirectoryTagSbyteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int8* value); -#if 0 -static int TIFFWriteDirectoryTagSbytePerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int8 value); -#endif -static int TIFFWriteDirectoryTagShort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 value); -static int TIFFWriteDirectoryTagShortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint16* value); -static int TIFFWriteDirectoryTagShortPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 value); -#ifdef notdef -static int TIFFWriteDirectoryTagSshort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int16 value); -#endif -static int TIFFWriteDirectoryTagSshortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int16* value); -#if 0 -static int TIFFWriteDirectoryTagSshortPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int16 value); -#endif -static int TIFFWriteDirectoryTagLong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value); -static int TIFFWriteDirectoryTagLongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value); -#if 0 -static int TIFFWriteDirectoryTagLongPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value); -#endif -#ifdef notdef -static int TIFFWriteDirectoryTagSlong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int32 value); -#endif -static int TIFFWriteDirectoryTagSlongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int32* value); -#if 0 -static int TIFFWriteDirectoryTagSlongPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int32 value); -#endif -#ifdef notdef -static int TIFFWriteDirectoryTagLong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint64 value); -#endif -static int TIFFWriteDirectoryTagLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value); -#ifdef notdef -static int TIFFWriteDirectoryTagSlong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int64 value); -#endif -static int TIFFWriteDirectoryTagSlong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int64* value); -static int TIFFWriteDirectoryTagRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value); -static int TIFFWriteDirectoryTagRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value); -static int TIFFWriteDirectoryTagSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value); -#ifdef notdef -static int TIFFWriteDirectoryTagFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value); -#endif -static int TIFFWriteDirectoryTagFloatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value); -#if 0 -static int TIFFWriteDirectoryTagFloatPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value); -#endif -#ifdef notdef -static int TIFFWriteDirectoryTagDouble(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value); -#endif -static int TIFFWriteDirectoryTagDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value); -#if 0 -static int TIFFWriteDirectoryTagDoublePerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value); -#endif -static int TIFFWriteDirectoryTagIfdArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value); -#ifdef notdef -static int TIFFWriteDirectoryTagIfd8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value); -#endif -static int TIFFWriteDirectoryTagShortLong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value); -static int TIFFWriteDirectoryTagLongLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value); -static int TIFFWriteDirectoryTagIfdIfd8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value); -#ifdef notdef -static int TIFFWriteDirectoryTagShortLongLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value); -#endif -static int TIFFWriteDirectoryTagColormap(TIFF* tif, uint32* ndir, TIFFDirEntry* dir); -static int TIFFWriteDirectoryTagTransferfunction(TIFF* tif, uint32* ndir, TIFFDirEntry* dir); -static int TIFFWriteDirectoryTagSubifd(TIFF* tif, uint32* ndir, TIFFDirEntry* dir); - -static int TIFFWriteDirectoryTagCheckedAscii(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, char* value); -static int TIFFWriteDirectoryTagCheckedUndefinedArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value); -#ifdef notdef -static int TIFFWriteDirectoryTagCheckedByte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint8 value); -#endif -static int TIFFWriteDirectoryTagCheckedByteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value); -#ifdef notdef -static int TIFFWriteDirectoryTagCheckedSbyte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int8 value); -#endif -static int TIFFWriteDirectoryTagCheckedSbyteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int8* value); -static int TIFFWriteDirectoryTagCheckedShort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 value); -static int TIFFWriteDirectoryTagCheckedShortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint16* value); -#ifdef notdef -static int TIFFWriteDirectoryTagCheckedSshort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int16 value); -#endif -static int TIFFWriteDirectoryTagCheckedSshortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int16* value); -static int TIFFWriteDirectoryTagCheckedLong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value); -static int TIFFWriteDirectoryTagCheckedLongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value); -#ifdef notdef -static int TIFFWriteDirectoryTagCheckedSlong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int32 value); -#endif -static int TIFFWriteDirectoryTagCheckedSlongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int32* value); -#ifdef notdef -static int TIFFWriteDirectoryTagCheckedLong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint64 value); -#endif -static int TIFFWriteDirectoryTagCheckedLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value); -#ifdef notdef -static int TIFFWriteDirectoryTagCheckedSlong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int64 value); -#endif -static int TIFFWriteDirectoryTagCheckedSlong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int64* value); -static int TIFFWriteDirectoryTagCheckedRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value); -static int TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value); -static int TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value); -#ifdef notdef -static int TIFFWriteDirectoryTagCheckedFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value); -#endif -static int TIFFWriteDirectoryTagCheckedFloatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value); -#ifdef notdef -static int TIFFWriteDirectoryTagCheckedDouble(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value); -#endif -static int TIFFWriteDirectoryTagCheckedDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value); -static int TIFFWriteDirectoryTagCheckedIfdArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value); -static int TIFFWriteDirectoryTagCheckedIfd8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value); - -static int TIFFWriteDirectoryTagData(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 datatype, uint32 count, uint32 datalength, void* data); - -static int TIFFLinkDirectory(TIFF*); - -/* - * Write the contents of the current directory - * to the specified file. This routine doesn't - * handle overwriting a directory with auxiliary - * storage that's been changed. - */ -int -TIFFWriteDirectory(TIFF* tif) -{ - return TIFFWriteDirectorySec(tif,TRUE,TRUE,NULL); -} - -/* - * Similar to TIFFWriteDirectory(), writes the directory out - * but leaves all data structures in memory so that it can be - * written again. This will make a partially written TIFF file - * readable before it is successfully completed/closed. - */ -int -TIFFCheckpointDirectory(TIFF* tif) -{ - int rc; - /* Setup the strips arrays, if they haven't already been. */ - if (tif->tif_dir.td_stripoffset == NULL) - (void) TIFFSetupStrips(tif); - rc = TIFFWriteDirectorySec(tif,TRUE,FALSE,NULL); - (void) TIFFSetWriteOffset(tif, TIFFSeekFile(tif, 0, SEEK_END)); - return rc; -} - -int -TIFFWriteCustomDirectory(TIFF* tif, uint64* pdiroff) -{ - return TIFFWriteDirectorySec(tif,FALSE,FALSE,pdiroff); -} - -/* - * Similar to TIFFWriteDirectory(), but if the directory has already - * been written once, it is relocated to the end of the file, in case it - * has changed in size. Note that this will result in the loss of the - * previously used directory space. - */ -int -TIFFRewriteDirectory( TIFF *tif ) -{ - static const char module[] = "TIFFRewriteDirectory"; - - /* We don't need to do anything special if it hasn't been written. */ - if( tif->tif_diroff == 0 ) - return TIFFWriteDirectory( tif ); - - /* - * Find and zero the pointer to this directory, so that TIFFLinkDirectory - * will cause it to be added after this directories current pre-link. - */ - - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - if (tif->tif_header.classic.tiff_diroff == tif->tif_diroff) - { - tif->tif_header.classic.tiff_diroff = 0; - tif->tif_diroff = 0; - - TIFFSeekFile(tif,4,SEEK_SET); - if (!WriteOK(tif, &(tif->tif_header.classic.tiff_diroff),4)) - { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "Error updating TIFF header"); - return (0); - } - } - else - { - uint32 nextdir; - nextdir = tif->tif_header.classic.tiff_diroff; - while(1) { - uint16 dircount; - uint32 nextnextdir; - - if (!SeekOK(tif, nextdir) || - !ReadOK(tif, &dircount, 2)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error fetching directory count"); - return (0); - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabShort(&dircount); - (void) TIFFSeekFile(tif, - nextdir+2+dircount*12, SEEK_SET); - if (!ReadOK(tif, &nextnextdir, 4)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error fetching directory link"); - return (0); - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong(&nextnextdir); - if (nextnextdir==tif->tif_diroff) - { - uint32 m; - m=0; - (void) TIFFSeekFile(tif, - nextdir+2+dircount*12, SEEK_SET); - if (!WriteOK(tif, &m, 4)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error writing directory link"); - return (0); - } - tif->tif_diroff=0; - break; - } - nextdir=nextnextdir; - } - } - } - else - { - if (tif->tif_header.big.tiff_diroff == tif->tif_diroff) - { - tif->tif_header.big.tiff_diroff = 0; - tif->tif_diroff = 0; - - TIFFSeekFile(tif,8,SEEK_SET); - if (!WriteOK(tif, &(tif->tif_header.big.tiff_diroff),8)) - { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "Error updating TIFF header"); - return (0); - } - } - else - { - uint64 nextdir; - nextdir = tif->tif_header.big.tiff_diroff; - while(1) { - uint64 dircount64; - uint16 dircount; - uint64 nextnextdir; - - if (!SeekOK(tif, nextdir) || - !ReadOK(tif, &dircount64, 8)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error fetching directory count"); - return (0); - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong8(&dircount64); - if (dircount64>0xFFFF) - { - TIFFErrorExt(tif->tif_clientdata, module, - "Sanity check on tag count failed, likely corrupt TIFF"); - return (0); - } - dircount=(uint16)dircount64; - (void) TIFFSeekFile(tif, - nextdir+8+dircount*20, SEEK_SET); - if (!ReadOK(tif, &nextnextdir, 8)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error fetching directory link"); - return (0); - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong8(&nextnextdir); - if (nextnextdir==tif->tif_diroff) - { - uint64 m; - m=0; - (void) TIFFSeekFile(tif, - nextdir+8+dircount*20, SEEK_SET); - if (!WriteOK(tif, &m, 8)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error writing directory link"); - return (0); - } - tif->tif_diroff=0; - break; - } - nextdir=nextnextdir; - } - } - } - - /* - * Now use TIFFWriteDirectory() normally. - */ - - return TIFFWriteDirectory( tif ); -} - -static int -TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff) -{ - static const char module[] = "TIFFWriteDirectorySec"; - uint32 ndir; - TIFFDirEntry* dir; - uint32 dirsize; - void* dirmem; - uint32 m; - if (tif->tif_mode == O_RDONLY) - return (1); - - _TIFFFillStriles( tif ); - - /* - * Clear write state so that subsequent images with - * different characteristics get the right buffers - * setup for them. - */ - if (imagedone) - { - if (tif->tif_flags & TIFF_POSTENCODE) - { - tif->tif_flags &= ~TIFF_POSTENCODE; - if (!(*tif->tif_postencode)(tif)) - { - TIFFErrorExt(tif->tif_clientdata,module, - "Error post-encoding before directory write"); - return (0); - } - } - (*tif->tif_close)(tif); /* shutdown encoder */ - /* - * Flush any data that might have been written - * by the compression close+cleanup routines. But - * be careful not to write stuff if we didn't add data - * in the previous steps as the "rawcc" data may well be - * a previously read tile/strip in mixed read/write mode. - */ - if (tif->tif_rawcc > 0 - && (tif->tif_flags & TIFF_BEENWRITING) != 0 ) - { - if( !TIFFFlushData1(tif) ) - { - TIFFErrorExt(tif->tif_clientdata, module, - "Error flushing data before directory write"); - return (0); - } - } - if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) - { - _TIFFfree(tif->tif_rawdata); - tif->tif_rawdata = NULL; - tif->tif_rawcc = 0; - tif->tif_rawdatasize = 0; - tif->tif_rawdataoff = 0; - tif->tif_rawdataloaded = 0; - } - tif->tif_flags &= ~(TIFF_BEENWRITING|TIFF_BUFFERSETUP); - } - dir=NULL; - dirmem=NULL; - dirsize=0; - while (1) - { - ndir=0; - if (isimage) - { - if (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS)) - { - if (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_IMAGEWIDTH,tif->tif_dir.td_imagewidth)) - goto bad; - if (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_IMAGELENGTH,tif->tif_dir.td_imagelength)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS)) - { - if (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_TILEWIDTH,tif->tif_dir.td_tilewidth)) - goto bad; - if (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_TILELENGTH,tif->tif_dir.td_tilelength)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_RESOLUTION)) - { - if (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_XRESOLUTION,tif->tif_dir.td_xresolution)) - goto bad; - if (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_YRESOLUTION,tif->tif_dir.td_yresolution)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_POSITION)) - { - if (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_XPOSITION,tif->tif_dir.td_xposition)) - goto bad; - if (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_YPOSITION,tif->tif_dir.td_yposition)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) - { - if (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_SUBFILETYPE,tif->tif_dir.td_subfiletype)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE)) - { - if (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_BITSPERSAMPLE,tif->tif_dir.td_bitspersample)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_COMPRESSION)) - { - if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_COMPRESSION,tif->tif_dir.td_compression)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_PHOTOMETRIC)) - { - if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_PHOTOMETRIC,tif->tif_dir.td_photometric)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_THRESHHOLDING)) - { - if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_THRESHHOLDING,tif->tif_dir.td_threshholding)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_FILLORDER)) - { - if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_FILLORDER,tif->tif_dir.td_fillorder)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_ORIENTATION)) - { - if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_ORIENTATION,tif->tif_dir.td_orientation)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL)) - { - if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_SAMPLESPERPIXEL,tif->tif_dir.td_samplesperpixel)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP)) - { - if (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_ROWSPERSTRIP,tif->tif_dir.td_rowsperstrip)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE)) - { - if (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_MINSAMPLEVALUE,tif->tif_dir.td_minsamplevalue)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE)) - { - if (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_MAXSAMPLEVALUE,tif->tif_dir.td_maxsamplevalue)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_PLANARCONFIG)) - { - if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_PLANARCONFIG,tif->tif_dir.td_planarconfig)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT)) - { - if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_RESOLUTIONUNIT,tif->tif_dir.td_resolutionunit)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_PAGENUMBER)) - { - if (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_PAGENUMBER,2,&tif->tif_dir.td_pagenumber[0])) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_STRIPBYTECOUNTS)) - { - if (!isTiled(tif)) - { - if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount)) - goto bad; - } - else - { - if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount)) - goto bad; - } - } - if (TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) - { - if (!isTiled(tif)) - { - if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset)) - goto bad; - } - else - { - if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset)) - goto bad; - } - } - if (TIFFFieldSet(tif,FIELD_COLORMAP)) - { - if (!TIFFWriteDirectoryTagColormap(tif,&ndir,dir)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_EXTRASAMPLES)) - { - if (tif->tif_dir.td_extrasamples) - { - uint16 na; - uint16* nb; - TIFFGetFieldDefaulted(tif,TIFFTAG_EXTRASAMPLES,&na,&nb); - if (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_EXTRASAMPLES,na,nb)) - goto bad; - } - } - if (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT)) - { - if (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_SAMPLEFORMAT,tif->tif_dir.td_sampleformat)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE)) - { - if (!TIFFWriteDirectoryTagSampleformatArray(tif,&ndir,dir,TIFFTAG_SMINSAMPLEVALUE,tif->tif_dir.td_samplesperpixel,tif->tif_dir.td_sminsamplevalue)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE)) - { - if (!TIFFWriteDirectoryTagSampleformatArray(tif,&ndir,dir,TIFFTAG_SMAXSAMPLEVALUE,tif->tif_dir.td_samplesperpixel,tif->tif_dir.td_smaxsamplevalue)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_IMAGEDEPTH)) - { - if (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_IMAGEDEPTH,tif->tif_dir.td_imagedepth)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_TILEDEPTH)) - { - if (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_TILEDEPTH,tif->tif_dir.td_tiledepth)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_HALFTONEHINTS)) - { - if (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_HALFTONEHINTS,2,&tif->tif_dir.td_halftonehints[0])) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING)) - { - if (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_YCBCRSUBSAMPLING,2,&tif->tif_dir.td_ycbcrsubsampling[0])) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) - { - if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_YCBCRPOSITIONING,tif->tif_dir.td_ycbcrpositioning)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_REFBLACKWHITE)) - { - if (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,TIFFTAG_REFERENCEBLACKWHITE,6,tif->tif_dir.td_refblackwhite)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION)) - { - if (!TIFFWriteDirectoryTagTransferfunction(tif,&ndir,dir)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_INKNAMES)) - { - if (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,TIFFTAG_INKNAMES,tif->tif_dir.td_inknameslen,tif->tif_dir.td_inknames)) - goto bad; - } - if (TIFFFieldSet(tif,FIELD_SUBIFD)) - { - if (!TIFFWriteDirectoryTagSubifd(tif,&ndir,dir)) - goto bad; - } - { - uint32 n; - for (n=0; ntif_nfields; n++) { - const TIFFField* o; - o = tif->tif_fields[n]; - if ((o->field_bit>=FIELD_CODEC)&&(TIFFFieldSet(tif,o->field_bit))) - { - switch (o->get_field_type) - { - case TIFF_SETGET_ASCII: - { - uint32 pa; - char* pb; - assert(o->field_type==TIFF_ASCII); - assert(o->field_readcount==TIFF_VARIABLE); - assert(o->field_passcount==0); - TIFFGetField(tif,o->field_tag,&pb); - pa=(uint32)(strlen(pb)); - if (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,o->field_tag,pa,pb)) - goto bad; - } - break; - case TIFF_SETGET_UINT16: - { - uint16 p; - assert(o->field_type==TIFF_SHORT); - assert(o->field_readcount==1); - assert(o->field_passcount==0); - TIFFGetField(tif,o->field_tag,&p); - if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,o->field_tag,p)) - goto bad; - } - break; - case TIFF_SETGET_UINT32: - { - uint32 p; - assert(o->field_type==TIFF_LONG); - assert(o->field_readcount==1); - assert(o->field_passcount==0); - TIFFGetField(tif,o->field_tag,&p); - if (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,o->field_tag,p)) - goto bad; - } - break; - case TIFF_SETGET_C32_UINT8: - { - uint32 pa; - void* pb; - assert(o->field_type==TIFF_UNDEFINED); - assert(o->field_readcount==TIFF_VARIABLE2); - assert(o->field_passcount==1); - TIFFGetField(tif,o->field_tag,&pa,&pb); - if (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,o->field_tag,pa,pb)) - goto bad; - } - break; - default: - assert(0); /* we should never get here */ - break; - } - } - } - } - } - for (m=0; m<(uint32)(tif->tif_dir.td_customValueCount); m++) - { - switch (tif->tif_dir.td_customValues[m].info->field_type) - { - case TIFF_ASCII: - if (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_UNDEFINED: - if (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_BYTE: - if (!TIFFWriteDirectoryTagByteArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_SBYTE: - if (!TIFFWriteDirectoryTagSbyteArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_SHORT: - if (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_SSHORT: - if (!TIFFWriteDirectoryTagSshortArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_LONG: - if (!TIFFWriteDirectoryTagLongArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_SLONG: - if (!TIFFWriteDirectoryTagSlongArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_LONG8: - if (!TIFFWriteDirectoryTagLong8Array(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_SLONG8: - if (!TIFFWriteDirectoryTagSlong8Array(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_RATIONAL: - if (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_SRATIONAL: - if (!TIFFWriteDirectoryTagSrationalArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_FLOAT: - if (!TIFFWriteDirectoryTagFloatArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_DOUBLE: - if (!TIFFWriteDirectoryTagDoubleArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_IFD: - if (!TIFFWriteDirectoryTagIfdArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - case TIFF_IFD8: - if (!TIFFWriteDirectoryTagIfdIfd8Array(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) - goto bad; - break; - default: - assert(0); /* we should never get here */ - break; - } - } - if (dir!=NULL) - break; - dir=_TIFFmalloc(ndir*sizeof(TIFFDirEntry)); - if (dir==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - goto bad; - } - if (isimage) - { - if ((tif->tif_diroff==0)&&(!TIFFLinkDirectory(tif))) - goto bad; - } - else - tif->tif_diroff=(TIFFSeekFile(tif,0,SEEK_END)+1)&(~1); - if (pdiroff!=NULL) - *pdiroff=tif->tif_diroff; - if (!(tif->tif_flags&TIFF_BIGTIFF)) - dirsize=2+ndir*12+4; - else - dirsize=8+ndir*20+8; - tif->tif_dataoff=tif->tif_diroff+dirsize; - if (!(tif->tif_flags&TIFF_BIGTIFF)) - tif->tif_dataoff=(uint32)tif->tif_dataoff; - if ((tif->tif_dataofftif_diroff)||(tif->tif_dataoff<(uint64)dirsize)) - { - TIFFErrorExt(tif->tif_clientdata,module,"Maximum TIFF file size exceeded"); - goto bad; - } - if (tif->tif_dataoff&1) - tif->tif_dataoff++; - if (isimage) - tif->tif_curdir++; - } - if (isimage) - { - if (TIFFFieldSet(tif,FIELD_SUBIFD)&&(tif->tif_subifdoff==0)) - { - uint32 na; - TIFFDirEntry* nb; - for (na=0, nb=dir; ; na++, nb++) - { - assert(natdir_tag==TIFFTAG_SUBIFD) - break; - } - if (!(tif->tif_flags&TIFF_BIGTIFF)) - tif->tif_subifdoff=tif->tif_diroff+2+na*12+8; - else - tif->tif_subifdoff=tif->tif_diroff+8+na*20+12; - } - } - dirmem=_TIFFmalloc(dirsize); - if (dirmem==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - goto bad; - } - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - uint8* n; - uint32 nTmp; - TIFFDirEntry* o; - n=dirmem; - *(uint16*)n=ndir; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)n); - n+=2; - o=dir; - for (m=0; mtdir_tag; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)n); - n+=2; - *(uint16*)n=o->tdir_type; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)n); - n+=2; - nTmp = (uint32)o->tdir_count; - _TIFFmemcpy(n,&nTmp,4); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)n); - n+=4; - /* This is correct. The data has been */ - /* swabbed previously in TIFFWriteDirectoryTagData */ - _TIFFmemcpy(n,&o->tdir_offset,4); - n+=4; - o++; - } - nTmp = (uint32)tif->tif_nextdiroff; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(&nTmp); - _TIFFmemcpy(n,&nTmp,4); - } - else - { - uint8* n; - TIFFDirEntry* o; - n=dirmem; - *(uint64*)n=ndir; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)n); - n+=8; - o=dir; - for (m=0; mtdir_tag; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)n); - n+=2; - *(uint16*)n=o->tdir_type; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)n); - n+=2; - _TIFFmemcpy(n,&o->tdir_count,8); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)n); - n+=8; - _TIFFmemcpy(n,&o->tdir_offset,8); - n+=8; - o++; - } - _TIFFmemcpy(n,&tif->tif_nextdiroff,8); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)n); - } - _TIFFfree(dir); - dir=NULL; - if (!SeekOK(tif,tif->tif_diroff)) - { - TIFFErrorExt(tif->tif_clientdata,module,"IO error writing directory"); - goto bad; - } - if (!WriteOK(tif,dirmem,(tmsize_t)dirsize)) - { - TIFFErrorExt(tif->tif_clientdata,module,"IO error writing directory"); - goto bad; - } - _TIFFfree(dirmem); - if (imagedone) - { - TIFFFreeDirectory(tif); - tif->tif_flags &= ~TIFF_DIRTYDIRECT; - tif->tif_flags &= ~TIFF_DIRTYSTRIP; - (*tif->tif_cleanup)(tif); - /* - * Reset directory-related state for subsequent - * directories. - */ - TIFFCreateDirectory(tif); - } - return(1); -bad: - if (dir!=NULL) - _TIFFfree(dir); - if (dirmem!=NULL) - _TIFFfree(dirmem); - return(0); -} - -static int -TIFFWriteDirectoryTagSampleformatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value) -{ - static const char module[] = "TIFFWriteDirectoryTagSampleformatArray"; - void* conv; - uint32 i; - int ok; - conv = _TIFFmalloc(count*sizeof(double)); - if (conv == NULL) - { - TIFFErrorExt(tif->tif_clientdata, module, "Out of memory"); - return (0); - } - - switch (tif->tif_dir.td_sampleformat) - { - case SAMPLEFORMAT_IEEEFP: - if (tif->tif_dir.td_bitspersample<=32) - { - for (i = 0; i < count; ++i) - ((float*)conv)[i] = (float)value[i]; - ok = TIFFWriteDirectoryTagFloatArray(tif,ndir,dir,tag,count,(float*)conv); - } - else - { - ok = TIFFWriteDirectoryTagDoubleArray(tif,ndir,dir,tag,count,value); - } - break; - case SAMPLEFORMAT_INT: - if (tif->tif_dir.td_bitspersample<=8) - { - for (i = 0; i < count; ++i) - ((int8*)conv)[i] = (int8)value[i]; - ok = TIFFWriteDirectoryTagSbyteArray(tif,ndir,dir,tag,count,(int8*)conv); - } - else if (tif->tif_dir.td_bitspersample<=16) - { - for (i = 0; i < count; ++i) - ((int16*)conv)[i] = (int16)value[i]; - ok = TIFFWriteDirectoryTagSshortArray(tif,ndir,dir,tag,count,(int16*)conv); - } - else - { - for (i = 0; i < count; ++i) - ((int32*)conv)[i] = (int32)value[i]; - ok = TIFFWriteDirectoryTagSlongArray(tif,ndir,dir,tag,count,(int32*)conv); - } - break; - case SAMPLEFORMAT_UINT: - if (tif->tif_dir.td_bitspersample<=8) - { - for (i = 0; i < count; ++i) - ((uint8*)conv)[i] = (uint8)value[i]; - ok = TIFFWriteDirectoryTagByteArray(tif,ndir,dir,tag,count,(uint8*)conv); - } - else if (tif->tif_dir.td_bitspersample<=16) - { - for (i = 0; i < count; ++i) - ((uint16*)conv)[i] = (uint16)value[i]; - ok = TIFFWriteDirectoryTagShortArray(tif,ndir,dir,tag,count,(uint16*)conv); - } - else - { - for (i = 0; i < count; ++i) - ((uint32*)conv)[i] = (uint32)value[i]; - ok = TIFFWriteDirectoryTagLongArray(tif,ndir,dir,tag,count,(uint32*)conv); - } - break; - default: - ok = 0; - } - - _TIFFfree(conv); - return (ok); -} - -#if 0 -static int -TIFFWriteDirectoryTagSampleformatPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value) -{ - switch (tif->tif_dir.td_sampleformat) - { - case SAMPLEFORMAT_IEEEFP: - if (tif->tif_dir.td_bitspersample<=32) - return(TIFFWriteDirectoryTagFloatPerSample(tif,ndir,dir,tag,(float)value)); - else - return(TIFFWriteDirectoryTagDoublePerSample(tif,ndir,dir,tag,value)); - case SAMPLEFORMAT_INT: - if (tif->tif_dir.td_bitspersample<=8) - return(TIFFWriteDirectoryTagSbytePerSample(tif,ndir,dir,tag,(int8)value)); - else if (tif->tif_dir.td_bitspersample<=16) - return(TIFFWriteDirectoryTagSshortPerSample(tif,ndir,dir,tag,(int16)value)); - else - return(TIFFWriteDirectoryTagSlongPerSample(tif,ndir,dir,tag,(int32)value)); - case SAMPLEFORMAT_UINT: - if (tif->tif_dir.td_bitspersample<=8) - return(TIFFWriteDirectoryTagBytePerSample(tif,ndir,dir,tag,(uint8)value)); - else if (tif->tif_dir.td_bitspersample<=16) - return(TIFFWriteDirectoryTagShortPerSample(tif,ndir,dir,tag,(uint16)value)); - else - return(TIFFWriteDirectoryTagLongPerSample(tif,ndir,dir,tag,(uint32)value)); - default: - return(1); - } -} -#endif - -static int -TIFFWriteDirectoryTagAscii(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, char* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedAscii(tif,ndir,dir,tag,count,value)); -} - -static int -TIFFWriteDirectoryTagUndefinedArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedUndefinedArray(tif,ndir,dir,tag,count,value)); -} - -#ifdef notdef -static int -TIFFWriteDirectoryTagByte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint8 value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedByte(tif,ndir,dir,tag,value)); -} -#endif - -static int -TIFFWriteDirectoryTagByteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedByteArray(tif,ndir,dir,tag,count,value)); -} - -#if 0 -static int -TIFFWriteDirectoryTagBytePerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint8 value) -{ - static const char module[] = "TIFFWriteDirectoryTagBytePerSample"; - uint8* m; - uint8* na; - uint16 nb; - int o; - if (dir==NULL) - { - (*ndir)++; - return(1); - } - m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(uint8)); - if (m==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) - *na=value; - o=TIFFWriteDirectoryTagCheckedByteArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); - _TIFFfree(m); - return(o); -} -#endif - -#ifdef notdef -static int -TIFFWriteDirectoryTagSbyte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int8 value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedSbyte(tif,ndir,dir,tag,value)); -} -#endif - -static int -TIFFWriteDirectoryTagSbyteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int8* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedSbyteArray(tif,ndir,dir,tag,count,value)); -} - -#if 0 -static int -TIFFWriteDirectoryTagSbytePerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int8 value) -{ - static const char module[] = "TIFFWriteDirectoryTagSbytePerSample"; - int8* m; - int8* na; - uint16 nb; - int o; - if (dir==NULL) - { - (*ndir)++; - return(1); - } - m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(int8)); - if (m==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) - *na=value; - o=TIFFWriteDirectoryTagCheckedSbyteArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); - _TIFFfree(m); - return(o); -} -#endif - -static int -TIFFWriteDirectoryTagShort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedShort(tif,ndir,dir,tag,value)); -} - -static int -TIFFWriteDirectoryTagShortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint16* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedShortArray(tif,ndir,dir,tag,count,value)); -} - -static int -TIFFWriteDirectoryTagShortPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 value) -{ - static const char module[] = "TIFFWriteDirectoryTagShortPerSample"; - uint16* m; - uint16* na; - uint16 nb; - int o; - if (dir==NULL) - { - (*ndir)++; - return(1); - } - m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(uint16)); - if (m==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) - *na=value; - o=TIFFWriteDirectoryTagCheckedShortArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); - _TIFFfree(m); - return(o); -} - -#ifdef notdef -static int -TIFFWriteDirectoryTagSshort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int16 value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedSshort(tif,ndir,dir,tag,value)); -} -#endif - -static int -TIFFWriteDirectoryTagSshortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int16* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedSshortArray(tif,ndir,dir,tag,count,value)); -} - -#if 0 -static int -TIFFWriteDirectoryTagSshortPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int16 value) -{ - static const char module[] = "TIFFWriteDirectoryTagSshortPerSample"; - int16* m; - int16* na; - uint16 nb; - int o; - if (dir==NULL) - { - (*ndir)++; - return(1); - } - m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(int16)); - if (m==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) - *na=value; - o=TIFFWriteDirectoryTagCheckedSshortArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); - _TIFFfree(m); - return(o); -} -#endif - -static int -TIFFWriteDirectoryTagLong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedLong(tif,ndir,dir,tag,value)); -} - -static int -TIFFWriteDirectoryTagLongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedLongArray(tif,ndir,dir,tag,count,value)); -} - -#if 0 -static int -TIFFWriteDirectoryTagLongPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value) -{ - static const char module[] = "TIFFWriteDirectoryTagLongPerSample"; - uint32* m; - uint32* na; - uint16 nb; - int o; - if (dir==NULL) - { - (*ndir)++; - return(1); - } - m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(uint32)); - if (m==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) - *na=value; - o=TIFFWriteDirectoryTagCheckedLongArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); - _TIFFfree(m); - return(o); -} -#endif - -#ifdef notdef -static int -TIFFWriteDirectoryTagSlong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int32 value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedSlong(tif,ndir,dir,tag,value)); -} -#endif - -static int -TIFFWriteDirectoryTagSlongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int32* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedSlongArray(tif,ndir,dir,tag,count,value)); -} - -#if 0 -static int -TIFFWriteDirectoryTagSlongPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int32 value) -{ - static const char module[] = "TIFFWriteDirectoryTagSlongPerSample"; - int32* m; - int32* na; - uint16 nb; - int o; - if (dir==NULL) - { - (*ndir)++; - return(1); - } - m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(int32)); - if (m==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) - *na=value; - o=TIFFWriteDirectoryTagCheckedSlongArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); - _TIFFfree(m); - return(o); -} -#endif - -#ifdef notdef -static int -TIFFWriteDirectoryTagLong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint64 value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedLong8(tif,ndir,dir,tag,value)); -} -#endif - -static int -TIFFWriteDirectoryTagLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedLong8Array(tif,ndir,dir,tag,count,value)); -} - -#ifdef notdef -static int -TIFFWriteDirectoryTagSlong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int64 value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedSlong8(tif,ndir,dir,tag,value)); -} -#endif - -static int -TIFFWriteDirectoryTagSlong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int64* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedSlong8Array(tif,ndir,dir,tag,count,value)); -} - -static int -TIFFWriteDirectoryTagRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedRational(tif,ndir,dir,tag,value)); -} - -static int -TIFFWriteDirectoryTagRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedRationalArray(tif,ndir,dir,tag,count,value)); -} - -static int -TIFFWriteDirectoryTagSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedSrationalArray(tif,ndir,dir,tag,count,value)); -} - -#ifdef notdef -static int TIFFWriteDirectoryTagFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedFloat(tif,ndir,dir,tag,value)); -} -#endif - -static int TIFFWriteDirectoryTagFloatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedFloatArray(tif,ndir,dir,tag,count,value)); -} - -#if 0 -static int TIFFWriteDirectoryTagFloatPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value) -{ - static const char module[] = "TIFFWriteDirectoryTagFloatPerSample"; - float* m; - float* na; - uint16 nb; - int o; - if (dir==NULL) - { - (*ndir)++; - return(1); - } - m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(float)); - if (m==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) - *na=value; - o=TIFFWriteDirectoryTagCheckedFloatArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); - _TIFFfree(m); - return(o); -} -#endif - -#ifdef notdef -static int TIFFWriteDirectoryTagDouble(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedDouble(tif,ndir,dir,tag,value)); -} -#endif - -static int TIFFWriteDirectoryTagDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedDoubleArray(tif,ndir,dir,tag,count,value)); -} - -#if 0 -static int TIFFWriteDirectoryTagDoublePerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value) -{ - static const char module[] = "TIFFWriteDirectoryTagDoublePerSample"; - double* m; - double* na; - uint16 nb; - int o; - if (dir==NULL) - { - (*ndir)++; - return(1); - } - m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(double)); - if (m==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) - *na=value; - o=TIFFWriteDirectoryTagCheckedDoubleArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); - _TIFFfree(m); - return(o); -} -#endif - -static int -TIFFWriteDirectoryTagIfdArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedIfdArray(tif,ndir,dir,tag,count,value)); -} - -#ifdef notdef -static int -TIFFWriteDirectoryTagIfd8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - return(TIFFWriteDirectoryTagCheckedIfd8Array(tif,ndir,dir,tag,count,value)); -} -#endif - -static int -TIFFWriteDirectoryTagShortLong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value) -{ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - if (value<=0xFFFF) - return(TIFFWriteDirectoryTagCheckedShort(tif,ndir,dir,tag,(uint16)value)); - else - return(TIFFWriteDirectoryTagCheckedLong(tif,ndir,dir,tag,value)); -} - -/************************************************************************/ -/* TIFFWriteDirectoryTagLongLong8Array() */ -/* */ -/* Write out LONG8 array as LONG8 for BigTIFF or LONG for */ -/* Classic TIFF with some checking. */ -/************************************************************************/ - -static int -TIFFWriteDirectoryTagLongLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value) -{ - static const char module[] = "TIFFWriteDirectoryTagLongLong8Array"; - uint64* ma; - uint32 mb; - uint32* p; - uint32* q; - int o; - - /* is this just a counting pass? */ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - - /* We always write LONG8 for BigTIFF, no checking needed. */ - if( tif->tif_flags&TIFF_BIGTIFF ) - return TIFFWriteDirectoryTagCheckedLong8Array(tif,ndir,dir, - tag,count,value); - - /* - ** For classic tiff we want to verify everything is in range for LONG - ** and convert to long format. - */ - - p = _TIFFmalloc(count*sizeof(uint32)); - if (p==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - - for (q=p, ma=value, mb=0; mb0xFFFFFFFF) - { - TIFFErrorExt(tif->tif_clientdata,module, - "Attempt to write value larger than 0xFFFFFFFF in Classic TIFF file."); - _TIFFfree(p); - return(0); - } - *q= (uint32)(*ma); - } - - o=TIFFWriteDirectoryTagCheckedLongArray(tif,ndir,dir,tag,count,p); - _TIFFfree(p); - - return(o); -} - -/************************************************************************/ -/* TIFFWriteDirectoryTagIfdIfd8Array() */ -/* */ -/* Write either IFD8 or IFD array depending on file type. */ -/************************************************************************/ - -static int -TIFFWriteDirectoryTagIfdIfd8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value) -{ - static const char module[] = "TIFFWriteDirectoryTagIfdIfd8Array"; - uint64* ma; - uint32 mb; - uint32* p; - uint32* q; - int o; - - /* is this just a counting pass? */ - if (dir==NULL) - { - (*ndir)++; - return(1); - } - - /* We always write IFD8 for BigTIFF, no checking needed. */ - if( tif->tif_flags&TIFF_BIGTIFF ) - return TIFFWriteDirectoryTagCheckedIfd8Array(tif,ndir,dir, - tag,count,value); - - /* - ** For classic tiff we want to verify everything is in range for IFD - ** and convert to long format. - */ - - p = _TIFFmalloc(count*sizeof(uint32)); - if (p==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - - for (q=p, ma=value, mb=0; mb0xFFFFFFFF) - { - TIFFErrorExt(tif->tif_clientdata,module, - "Attempt to write value larger than 0xFFFFFFFF in Classic TIFF file."); - _TIFFfree(p); - return(0); - } - *q= (uint32)(*ma); - } - - o=TIFFWriteDirectoryTagCheckedIfdArray(tif,ndir,dir,tag,count,p); - _TIFFfree(p); - - return(o); -} - -#ifdef notdef -static int -TIFFWriteDirectoryTagShortLongLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value) -{ - static const char module[] = "TIFFWriteDirectoryTagShortLongLong8Array"; - uint64* ma; - uint32 mb; - uint8 n; - int o; - if (dir==NULL) - { - (*ndir)++; - return(1); - } - n=0; - for (ma=value, mb=0; mb0xFFFF)) - n=1; - if ((n==1)&&(*ma>0xFFFFFFFF)) - { - n=2; - break; - } - } - if (n==0) - { - uint16* p; - uint16* q; - p=_TIFFmalloc(count*sizeof(uint16)); - if (p==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - for (ma=value, mb=0, q=p; mbtif_clientdata,module,"Out of memory"); - return(0); - } - for (ma=value, mb=0, q=p; mbtif_dir.td_bitspersample); - n=_TIFFmalloc(3*m*sizeof(uint16)); - if (n==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - _TIFFmemcpy(&n[0],tif->tif_dir.td_colormap[0],m*sizeof(uint16)); - _TIFFmemcpy(&n[m],tif->tif_dir.td_colormap[1],m*sizeof(uint16)); - _TIFFmemcpy(&n[2*m],tif->tif_dir.td_colormap[2],m*sizeof(uint16)); - o=TIFFWriteDirectoryTagCheckedShortArray(tif,ndir,dir,TIFFTAG_COLORMAP,3*m,n); - _TIFFfree(n); - return(o); -} - -static int -TIFFWriteDirectoryTagTransferfunction(TIFF* tif, uint32* ndir, TIFFDirEntry* dir) -{ - static const char module[] = "TIFFWriteDirectoryTagTransferfunction"; - uint32 m; - uint16 n; - uint16* o; - int p; - if (dir==NULL) - { - (*ndir)++; - return(1); - } - m=(1<tif_dir.td_bitspersample); - n=tif->tif_dir.td_samplesperpixel-tif->tif_dir.td_extrasamples; - /* - * Check if the table can be written as a single column, - * or if it must be written as 3 columns. Note that we - * write a 3-column tag if there are 2 samples/pixel and - * a single column of data won't suffice--hmm. - */ - if (n>3) - n=3; - if (n==3) - { - if (!_TIFFmemcmp(tif->tif_dir.td_transferfunction[0],tif->tif_dir.td_transferfunction[2],m*sizeof(uint16))) - n=2; - } - if (n==2) - { - if (!_TIFFmemcmp(tif->tif_dir.td_transferfunction[0],tif->tif_dir.td_transferfunction[1],m*sizeof(uint16))) - n=1; - } - if (n==0) - n=1; - o=_TIFFmalloc(n*m*sizeof(uint16)); - if (o==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - _TIFFmemcpy(&o[0],tif->tif_dir.td_transferfunction[0],m*sizeof(uint16)); - if (n>1) - _TIFFmemcpy(&o[m],tif->tif_dir.td_transferfunction[1],m*sizeof(uint16)); - if (n>2) - _TIFFmemcpy(&o[2*m],tif->tif_dir.td_transferfunction[2],m*sizeof(uint16)); - p=TIFFWriteDirectoryTagCheckedShortArray(tif,ndir,dir,TIFFTAG_TRANSFERFUNCTION,n*m,o); - _TIFFfree(o); - return(p); -} - -static int -TIFFWriteDirectoryTagSubifd(TIFF* tif, uint32* ndir, TIFFDirEntry* dir) -{ - static const char module[] = "TIFFWriteDirectoryTagSubifd"; - uint64 m; - int n; - if (tif->tif_dir.td_nsubifd==0) - return(1); - if (dir==NULL) - { - (*ndir)++; - return(1); - } - m=tif->tif_dataoff; - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - uint32* o; - uint64* pa; - uint32* pb; - uint16 p; - o=_TIFFmalloc(tif->tif_dir.td_nsubifd*sizeof(uint32)); - if (o==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - pa=tif->tif_dir.td_subifd; - pb=o; - for (p=0; p < tif->tif_dir.td_nsubifd; p++) - { - assert(pa != 0); - assert(*pa <= 0xFFFFFFFFUL); - *pb++=(uint32)(*pa++); - } - n=TIFFWriteDirectoryTagCheckedIfdArray(tif,ndir,dir,TIFFTAG_SUBIFD,tif->tif_dir.td_nsubifd,o); - _TIFFfree(o); - } - else - n=TIFFWriteDirectoryTagCheckedIfd8Array(tif,ndir,dir,TIFFTAG_SUBIFD,tif->tif_dir.td_nsubifd,tif->tif_dir.td_subifd); - if (!n) - return(0); - /* - * Total hack: if this directory includes a SubIFD - * tag then force the next directories to be - * written as ``sub directories'' of this one. This - * is used to write things like thumbnails and - * image masks that one wants to keep out of the - * normal directory linkage access mechanism. - */ - tif->tif_flags|=TIFF_INSUBIFD; - tif->tif_nsubifd=tif->tif_dir.td_nsubifd; - if (tif->tif_dir.td_nsubifd==1) - tif->tif_subifdoff=0; - else - tif->tif_subifdoff=m; - return(1); -} - -static int -TIFFWriteDirectoryTagCheckedAscii(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, char* value) -{ - assert(sizeof(char)==1); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_ASCII,count,count,value)); -} - -static int -TIFFWriteDirectoryTagCheckedUndefinedArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value) -{ - assert(sizeof(uint8)==1); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_UNDEFINED,count,count,value)); -} - -#ifdef notdef -static int -TIFFWriteDirectoryTagCheckedByte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint8 value) -{ - assert(sizeof(uint8)==1); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_BYTE,1,1,&value)); -} -#endif - -static int -TIFFWriteDirectoryTagCheckedByteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value) -{ - assert(sizeof(uint8)==1); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_BYTE,count,count,value)); -} - -#ifdef notdef -static int -TIFFWriteDirectoryTagCheckedSbyte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int8 value) -{ - assert(sizeof(int8)==1); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SBYTE,1,1,&value)); -} -#endif - -static int -TIFFWriteDirectoryTagCheckedSbyteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int8* value) -{ - assert(sizeof(int8)==1); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SBYTE,count,count,value)); -} - -static int -TIFFWriteDirectoryTagCheckedShort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 value) -{ - uint16 m; - assert(sizeof(uint16)==2); - m=value; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabShort(&m); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SHORT,1,2,&m)); -} - -static int -TIFFWriteDirectoryTagCheckedShortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint16* value) -{ - assert(count<0x80000000); - assert(sizeof(uint16)==2); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfShort(value,count); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SHORT,count,count*2,value)); -} - -#ifdef notdef -static int -TIFFWriteDirectoryTagCheckedSshort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int16 value) -{ - int16 m; - assert(sizeof(int16)==2); - m=value; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabShort((uint16*)(&m)); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SSHORT,1,2,&m)); -} -#endif - -static int -TIFFWriteDirectoryTagCheckedSshortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int16* value) -{ - assert(count<0x80000000); - assert(sizeof(int16)==2); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfShort((uint16*)value,count); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SSHORT,count,count*2,value)); -} - -static int -TIFFWriteDirectoryTagCheckedLong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value) -{ - uint32 m; - assert(sizeof(uint32)==4); - m=value; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(&m); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_LONG,1,4,&m)); -} - -static int -TIFFWriteDirectoryTagCheckedLongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value) -{ - assert(count<0x40000000); - assert(sizeof(uint32)==4); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong(value,count); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_LONG,count,count*4,value)); -} - -#ifdef notdef -static int -TIFFWriteDirectoryTagCheckedSlong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int32 value) -{ - int32 m; - assert(sizeof(int32)==4); - m=value; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong((uint32*)(&m)); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SLONG,1,4,&m)); -} -#endif - -static int -TIFFWriteDirectoryTagCheckedSlongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int32* value) -{ - assert(count<0x40000000); - assert(sizeof(int32)==4); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong((uint32*)value,count); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SLONG,count,count*4,value)); -} - -#ifdef notdef -static int -TIFFWriteDirectoryTagCheckedLong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint64 value) -{ - uint64 m; - assert(sizeof(uint64)==8); - assert(tif->tif_flags&TIFF_BIGTIFF); - m=value; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8(&m); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_LONG8,1,8,&m)); -} -#endif - -static int -TIFFWriteDirectoryTagCheckedLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value) -{ - assert(count<0x20000000); - assert(sizeof(uint64)==8); - assert(tif->tif_flags&TIFF_BIGTIFF); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong8(value,count); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_LONG8,count,count*8,value)); -} - -#ifdef notdef -static int -TIFFWriteDirectoryTagCheckedSlong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int64 value) -{ - int64 m; - assert(sizeof(int64)==8); - assert(tif->tif_flags&TIFF_BIGTIFF); - m=value; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8((uint64*)(&m)); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SLONG8,1,8,&m)); -} -#endif - -static int -TIFFWriteDirectoryTagCheckedSlong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int64* value) -{ - assert(count<0x20000000); - assert(sizeof(int64)==8); - assert(tif->tif_flags&TIFF_BIGTIFF); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong8((uint64*)value,count); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SLONG8,count,count*8,value)); -} - -static int -TIFFWriteDirectoryTagCheckedRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value) -{ - uint32 m[2]; - assert(value>=0.0); - assert(sizeof(uint32)==4); - if (value<=0.0) - { - m[0]=0; - m[1]=1; - } - else if (value==(double)(uint32)value) - { - m[0]=(uint32)value; - m[1]=1; - } - else if (value<1.0) - { - m[0]=(uint32)(value*0xFFFFFFFF); - m[1]=0xFFFFFFFF; - } - else - { - m[0]=0xFFFFFFFF; - m[1]=(uint32)(0xFFFFFFFF/value); - } - if (tif->tif_flags&TIFF_SWAB) - { - TIFFSwabLong(&m[0]); - TIFFSwabLong(&m[1]); - } - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_RATIONAL,1,8,&m[0])); -} - -static int -TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value) -{ - static const char module[] = "TIFFWriteDirectoryTagCheckedRationalArray"; - uint32* m; - float* na; - uint32* nb; - uint32 nc; - int o; - assert(sizeof(uint32)==4); - m=_TIFFmalloc(count*2*sizeof(uint32)); - if (m==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - for (na=value, nb=m, nc=0; nctif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong(m,count*2); - o=TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_RATIONAL,count,count*8,&m[0]); - _TIFFfree(m); - return(o); -} - -static int -TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value) -{ - static const char module[] = "TIFFWriteDirectoryTagCheckedSrationalArray"; - int32* m; - float* na; - int32* nb; - uint32 nc; - int o; - assert(sizeof(int32)==4); - m=_TIFFmalloc(count*2*sizeof(int32)); - if (m==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - for (na=value, nb=m, nc=0; nc-1.0) - { - nb[0]=-(int32)((-*na)*0x7FFFFFFF); - nb[1]=0x7FFFFFFF; - } - else - { - nb[0]=-0x7FFFFFFF; - nb[1]=(int32)(0x7FFFFFFF/(-*na)); - } - } - else - { - if (*na==(int32)(*na)) - { - nb[0]=(int32)(*na); - nb[1]=1; - } - else if (*na<1.0) - { - nb[0]=(int32)((*na)*0x7FFFFFFF); - nb[1]=0x7FFFFFFF; - } - else - { - nb[0]=0x7FFFFFFF; - nb[1]=(int32)(0x7FFFFFFF/(*na)); - } - } - } - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong((uint32*)m,count*2); - o=TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SRATIONAL,count,count*8,&m[0]); - _TIFFfree(m); - return(o); -} - -#ifdef notdef -static int -TIFFWriteDirectoryTagCheckedFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value) -{ - float m; - assert(sizeof(float)==4); - m=value; - TIFFCvtNativeToIEEEFloat(tif,1,&m); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabFloat(&m); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_FLOAT,1,4,&m)); -} -#endif - -static int -TIFFWriteDirectoryTagCheckedFloatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value) -{ - assert(count<0x40000000); - assert(sizeof(float)==4); - TIFFCvtNativeToIEEEFloat(tif,count,&value); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfFloat(value,count); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_FLOAT,count,count*4,value)); -} - -#ifdef notdef -static int -TIFFWriteDirectoryTagCheckedDouble(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value) -{ - double m; - assert(sizeof(double)==8); - m=value; - TIFFCvtNativeToIEEEDouble(tif,1,&m); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabDouble(&m); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_DOUBLE,1,8,&m)); -} -#endif - -static int -TIFFWriteDirectoryTagCheckedDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value) -{ - assert(count<0x20000000); - assert(sizeof(double)==8); - TIFFCvtNativeToIEEEDouble(tif,count,&value); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfDouble(value,count); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_DOUBLE,count,count*8,value)); -} - -static int -TIFFWriteDirectoryTagCheckedIfdArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value) -{ - assert(count<0x40000000); - assert(sizeof(uint32)==4); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong(value,count); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_IFD,count,count*4,value)); -} - -static int -TIFFWriteDirectoryTagCheckedIfd8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value) -{ - assert(count<0x20000000); - assert(sizeof(uint64)==8); - assert(tif->tif_flags&TIFF_BIGTIFF); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong8(value,count); - return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_IFD8,count,count*8,value)); -} - -static int -TIFFWriteDirectoryTagData(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 datatype, uint32 count, uint32 datalength, void* data) -{ - static const char module[] = "TIFFWriteDirectoryTagData"; - uint32 m; - m=0; - while (m<(*ndir)) - { - assert(dir[m].tdir_tag!=tag); - if (dir[m].tdir_tag>tag) - break; - m++; - } - if (m<(*ndir)) - { - uint32 n; - for (n=*ndir; n>m; n--) - dir[n]=dir[n-1]; - } - dir[m].tdir_tag=tag; - dir[m].tdir_type=datatype; - dir[m].tdir_count=count; - dir[m].tdir_offset.toff_long8 = 0; - if (datalength<=((tif->tif_flags&TIFF_BIGTIFF)?0x8U:0x4U)) - _TIFFmemcpy(&dir[m].tdir_offset,data,datalength); - else - { - uint64 na,nb; - na=tif->tif_dataoff; - nb=na+datalength; - if (!(tif->tif_flags&TIFF_BIGTIFF)) - nb=(uint32)nb; - if ((nbtif_clientdata,module,"Maximum TIFF file size exceeded"); - return(0); - } - if (!SeekOK(tif,na)) - { - TIFFErrorExt(tif->tif_clientdata,module,"IO error writing tag data"); - return(0); - } - assert(datalength<0x80000000UL); - if (!WriteOK(tif,data,(tmsize_t)datalength)) - { - TIFFErrorExt(tif->tif_clientdata,module,"IO error writing tag data"); - return(0); - } - tif->tif_dataoff=nb; - if (tif->tif_dataoff&1) - tif->tif_dataoff++; - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - uint32 o; - o=(uint32)na; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(&o); - _TIFFmemcpy(&dir[m].tdir_offset,&o,4); - } - else - { - dir[m].tdir_offset.toff_long8 = na; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8(&dir[m].tdir_offset.toff_long8); - } - } - (*ndir)++; - return(1); -} - -/* - * Link the current directory into the directory chain for the file. - */ -static int -TIFFLinkDirectory(TIFF* tif) -{ - static const char module[] = "TIFFLinkDirectory"; - - tif->tif_diroff = (TIFFSeekFile(tif,0,SEEK_END)+1) &~ 1; - - /* - * Handle SubIFDs - */ - if (tif->tif_flags & TIFF_INSUBIFD) - { - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - uint32 m; - m = (uint32)tif->tif_diroff; - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong(&m); - (void) TIFFSeekFile(tif, tif->tif_subifdoff, SEEK_SET); - if (!WriteOK(tif, &m, 4)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error writing SubIFD directory link"); - return (0); - } - /* - * Advance to the next SubIFD or, if this is - * the last one configured, revert back to the - * normal directory linkage. - */ - if (--tif->tif_nsubifd) - tif->tif_subifdoff += 4; - else - tif->tif_flags &= ~TIFF_INSUBIFD; - return (1); - } - else - { - uint64 m; - m = tif->tif_diroff; - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong8(&m); - (void) TIFFSeekFile(tif, tif->tif_subifdoff, SEEK_SET); - if (!WriteOK(tif, &m, 8)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error writing SubIFD directory link"); - return (0); - } - /* - * Advance to the next SubIFD or, if this is - * the last one configured, revert back to the - * normal directory linkage. - */ - if (--tif->tif_nsubifd) - tif->tif_subifdoff += 8; - else - tif->tif_flags &= ~TIFF_INSUBIFD; - return (1); - } - } - - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - uint32 m; - uint32 nextdir; - m = (uint32)(tif->tif_diroff); - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong(&m); - if (tif->tif_header.classic.tiff_diroff == 0) { - /* - * First directory, overwrite offset in header. - */ - tif->tif_header.classic.tiff_diroff = (uint32) tif->tif_diroff; - (void) TIFFSeekFile(tif,4, SEEK_SET); - if (!WriteOK(tif, &m, 4)) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "Error writing TIFF header"); - return (0); - } - return (1); - } - /* - * Not the first directory, search to the last and append. - */ - nextdir = tif->tif_header.classic.tiff_diroff; - while(1) { - uint16 dircount; - uint32 nextnextdir; - - if (!SeekOK(tif, nextdir) || - !ReadOK(tif, &dircount, 2)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error fetching directory count"); - return (0); - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabShort(&dircount); - (void) TIFFSeekFile(tif, - nextdir+2+dircount*12, SEEK_SET); - if (!ReadOK(tif, &nextnextdir, 4)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error fetching directory link"); - return (0); - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong(&nextnextdir); - if (nextnextdir==0) - { - (void) TIFFSeekFile(tif, - nextdir+2+dircount*12, SEEK_SET); - if (!WriteOK(tif, &m, 4)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error writing directory link"); - return (0); - } - break; - } - nextdir=nextnextdir; - } - } - else - { - uint64 m; - uint64 nextdir; - m = tif->tif_diroff; - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong8(&m); - if (tif->tif_header.big.tiff_diroff == 0) { - /* - * First directory, overwrite offset in header. - */ - tif->tif_header.big.tiff_diroff = tif->tif_diroff; - (void) TIFFSeekFile(tif,8, SEEK_SET); - if (!WriteOK(tif, &m, 8)) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "Error writing TIFF header"); - return (0); - } - return (1); - } - /* - * Not the first directory, search to the last and append. - */ - nextdir = tif->tif_header.big.tiff_diroff; - while(1) { - uint64 dircount64; - uint16 dircount; - uint64 nextnextdir; - - if (!SeekOK(tif, nextdir) || - !ReadOK(tif, &dircount64, 8)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error fetching directory count"); - return (0); - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong8(&dircount64); - if (dircount64>0xFFFF) - { - TIFFErrorExt(tif->tif_clientdata, module, - "Sanity check on tag count failed, likely corrupt TIFF"); - return (0); - } - dircount=(uint16)dircount64; - (void) TIFFSeekFile(tif, - nextdir+8+dircount*20, SEEK_SET); - if (!ReadOK(tif, &nextnextdir, 8)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error fetching directory link"); - return (0); - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong8(&nextnextdir); - if (nextnextdir==0) - { - (void) TIFFSeekFile(tif, - nextdir+8+dircount*20, SEEK_SET); - if (!WriteOK(tif, &m, 8)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error writing directory link"); - return (0); - } - break; - } - nextdir=nextnextdir; - } - } - return (1); -} - -/************************************************************************/ -/* TIFFRewriteField() */ -/* */ -/* Rewrite a field in the directory on disk without regard to */ -/* updating the TIFF directory structure in memory. Currently */ -/* only supported for field that already exist in the on-disk */ -/* directory. Mainly used for updating stripoffset / */ -/* stripbytecount values after the directory is already on */ -/* disk. */ -/* */ -/* Returns zero on failure, and one on success. */ -/************************************************************************/ - -int -_TIFFRewriteField(TIFF* tif, uint16 tag, TIFFDataType in_datatype, - tmsize_t count, void* data) -{ - static const char module[] = "TIFFResetField"; - /* const TIFFField* fip = NULL; */ - uint16 dircount; - tmsize_t dirsize; - uint8 direntry_raw[20]; - uint16 entry_tag = 0; - uint16 entry_type = 0; - uint64 entry_count = 0; - uint64 entry_offset = 0; - int value_in_entry = 0; - uint64 read_offset; - uint8 *buf_to_write = NULL; - TIFFDataType datatype; - -/* -------------------------------------------------------------------- */ -/* Find field definition. */ -/* -------------------------------------------------------------------- */ - /*fip =*/ TIFFFindField(tif, tag, TIFF_ANY); - -/* -------------------------------------------------------------------- */ -/* Do some checking this is a straight forward case. */ -/* -------------------------------------------------------------------- */ - if( isMapped(tif) ) - { - TIFFErrorExt( tif->tif_clientdata, module, - "Memory mapped files not currently supported for this operation." ); - return 0; - } - - if( tif->tif_diroff == 0 ) - { - TIFFErrorExt( tif->tif_clientdata, module, - "Attempt to reset field on directory not already on disk." ); - return 0; - } - -/* -------------------------------------------------------------------- */ -/* Read the directory entry count. */ -/* -------------------------------------------------------------------- */ - if (!SeekOK(tif, tif->tif_diroff)) { - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Seek error accessing TIFF directory", - tif->tif_name); - return 0; - } - - read_offset = tif->tif_diroff; - - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - if (!ReadOK(tif, &dircount, sizeof (uint16))) { - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Can not read TIFF directory count", - tif->tif_name); - return 0; - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabShort(&dircount); - dirsize = 12; - read_offset += 2; - } else { - uint64 dircount64; - if (!ReadOK(tif, &dircount64, sizeof (uint64))) { - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Can not read TIFF directory count", - tif->tif_name); - return 0; - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong8(&dircount64); - dircount = (uint16)dircount64; - dirsize = 20; - read_offset += 8; - } - -/* -------------------------------------------------------------------- */ -/* Read through directory to find target tag. */ -/* -------------------------------------------------------------------- */ - while( dircount > 0 ) - { - if (!ReadOK(tif, direntry_raw, dirsize)) { - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Can not read TIFF directory entry.", - tif->tif_name); - return 0; - } - - memcpy( &entry_tag, direntry_raw + 0, sizeof(uint16) ); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabShort( &entry_tag ); - - if( entry_tag == tag ) - break; - - read_offset += dirsize; - } - - if( entry_tag != tag ) - { - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Could not find tag %d.", - tif->tif_name, tag ); - return 0; - } - -/* -------------------------------------------------------------------- */ -/* Extract the type, count and offset for this entry. */ -/* -------------------------------------------------------------------- */ - memcpy( &entry_type, direntry_raw + 2, sizeof(uint16) ); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabShort( &entry_type ); - - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - uint32 value; - - memcpy( &value, direntry_raw + 4, sizeof(uint32) ); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong( &value ); - entry_count = value; - - memcpy( &value, direntry_raw + 8, sizeof(uint32) ); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong( &value ); - entry_offset = value; - } - else - { - memcpy( &entry_count, direntry_raw + 4, sizeof(uint64) ); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8( &entry_count ); - - memcpy( &entry_offset, direntry_raw + 12, sizeof(uint64) ); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8( &entry_offset ); - } - -/* -------------------------------------------------------------------- */ -/* What data type do we want to write this as? */ -/* -------------------------------------------------------------------- */ - if( TIFFDataWidth(in_datatype) == 8 && !(tif->tif_flags&TIFF_BIGTIFF) ) - { - if( in_datatype == TIFF_LONG8 ) - datatype = TIFF_LONG; - else if( in_datatype == TIFF_SLONG8 ) - datatype = TIFF_SLONG; - else if( in_datatype == TIFF_IFD8 ) - datatype = TIFF_IFD; - else - datatype = in_datatype; - } - else - datatype = in_datatype; - -/* -------------------------------------------------------------------- */ -/* Prepare buffer of actual data to write. This includes */ -/* swabbing as needed. */ -/* -------------------------------------------------------------------- */ - buf_to_write = - (uint8 *)_TIFFCheckMalloc(tif, count, TIFFDataWidth(datatype), - "for field buffer."); - if (!buf_to_write) - return 0; - - if( datatype == in_datatype ) - memcpy( buf_to_write, data, count * TIFFDataWidth(datatype) ); - else if( datatype == TIFF_SLONG && in_datatype == TIFF_SLONG8 ) - { - tmsize_t i; - - for( i = 0; i < count; i++ ) - { - ((int32 *) buf_to_write)[i] = - (int32) ((int64 *) data)[i]; - if( (int64) ((int32 *) buf_to_write)[i] != ((int64 *) data)[i] ) - { - _TIFFfree( buf_to_write ); - TIFFErrorExt( tif->tif_clientdata, module, - "Value exceeds 32bit range of output type." ); - return 0; - } - } - } - else if( (datatype == TIFF_LONG && in_datatype == TIFF_LONG8) - || (datatype == TIFF_IFD && in_datatype == TIFF_IFD8) ) - { - tmsize_t i; - - for( i = 0; i < count; i++ ) - { - ((uint32 *) buf_to_write)[i] = - (uint32) ((uint64 *) data)[i]; - if( (uint64) ((uint32 *) buf_to_write)[i] != ((uint64 *) data)[i] ) - { - _TIFFfree( buf_to_write ); - TIFFErrorExt( tif->tif_clientdata, module, - "Value exceeds 32bit range of output type." ); - return 0; - } - } - } - - if( TIFFDataWidth(datatype) > 1 && (tif->tif_flags&TIFF_SWAB) ) - { - if( TIFFDataWidth(datatype) == 2 ) - TIFFSwabArrayOfShort( (uint16 *) buf_to_write, count ); - else if( TIFFDataWidth(datatype) == 4 ) - TIFFSwabArrayOfLong( (uint32 *) buf_to_write, count ); - else if( TIFFDataWidth(datatype) == 8 ) - TIFFSwabArrayOfLong8( (uint64 *) buf_to_write, count ); - } - -/* -------------------------------------------------------------------- */ -/* Is this a value that fits into the directory entry? */ -/* -------------------------------------------------------------------- */ - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - if( TIFFDataWidth(datatype) * count <= 4 ) - { - entry_offset = read_offset + 8; - value_in_entry = 1; - } - } - else - { - if( TIFFDataWidth(datatype) * count <= 8 ) - { - entry_offset = read_offset + 12; - value_in_entry = 1; - } - } - -/* -------------------------------------------------------------------- */ -/* If the tag type, and count match, then we just write it out */ -/* over the old values without altering the directory entry at */ -/* all. */ -/* -------------------------------------------------------------------- */ - if( entry_count == (uint64)count && entry_type == (uint16) datatype ) - { - if (!SeekOK(tif, entry_offset)) { - _TIFFfree( buf_to_write ); - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Seek error accessing TIFF directory", - tif->tif_name); - return 0; - } - if (!WriteOK(tif, buf_to_write, count*TIFFDataWidth(datatype))) { - _TIFFfree( buf_to_write ); - TIFFErrorExt(tif->tif_clientdata, module, - "Error writing directory link"); - return (0); - } - - _TIFFfree( buf_to_write ); - return 1; - } - -/* -------------------------------------------------------------------- */ -/* Otherwise, we write the new tag data at the end of the file. */ -/* -------------------------------------------------------------------- */ - if( !value_in_entry ) - { - entry_offset = TIFFSeekFile(tif,0,SEEK_END); - - if (!WriteOK(tif, buf_to_write, count*TIFFDataWidth(datatype))) { - _TIFFfree( buf_to_write ); - TIFFErrorExt(tif->tif_clientdata, module, - "Error writing directory link"); - return (0); - } - - _TIFFfree( buf_to_write ); - } - else - { - memcpy( &entry_offset, buf_to_write, count*TIFFDataWidth(datatype)); - } - -/* -------------------------------------------------------------------- */ -/* Adjust the directory entry. */ -/* -------------------------------------------------------------------- */ - entry_type = datatype; - memcpy( direntry_raw + 2, &entry_type, sizeof(uint16) ); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabShort( (uint16 *) (direntry_raw + 2) ); - - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - uint32 value; - - value = (uint32) entry_count; - memcpy( direntry_raw + 4, &value, sizeof(uint32) ); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong( (uint32 *) (direntry_raw + 4) ); - - value = (uint32) entry_offset; - memcpy( direntry_raw + 8, &value, sizeof(uint32) ); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong( (uint32 *) (direntry_raw + 8) ); - } - else - { - memcpy( direntry_raw + 4, &entry_count, sizeof(uint64) ); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8( (uint64 *) (direntry_raw + 4) ); - - memcpy( direntry_raw + 12, &entry_offset, sizeof(uint64) ); - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8( (uint64 *) (direntry_raw + 12) ); - } - -/* -------------------------------------------------------------------- */ -/* Write the directory entry out to disk. */ -/* -------------------------------------------------------------------- */ - if (!SeekOK(tif, read_offset )) { - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Seek error accessing TIFF directory", - tif->tif_name); - return 0; - } - - if (!WriteOK(tif, direntry_raw,dirsize)) - { - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Can not write TIFF directory entry.", - tif->tif_name); - return 0; - } - - return 1; -} -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_dirwrite.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * + * Directory Write Support Routines. + */ +#include "tiffiop.h" + +#ifdef HAVE_IEEEFP +#define TIFFCvtNativeToIEEEFloat(tif, n, fp) +#define TIFFCvtNativeToIEEEDouble(tif, n, dp) +#else +extern void TIFFCvtNativeToIEEEFloat(TIFF* tif, uint32 n, float* fp); +extern void TIFFCvtNativeToIEEEDouble(TIFF* tif, uint32 n, double* dp); +#endif + +static int TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff); + +static int TIFFWriteDirectoryTagSampleformatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value); +#if 0 +static int TIFFWriteDirectoryTagSampleformatPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value); +#endif + +static int TIFFWriteDirectoryTagAscii(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, char* value); +static int TIFFWriteDirectoryTagUndefinedArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value); +#ifdef notdef +static int TIFFWriteDirectoryTagByte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint8 value); +#endif +static int TIFFWriteDirectoryTagByteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value); +#if 0 +static int TIFFWriteDirectoryTagBytePerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint8 value); +#endif +#ifdef notdef +static int TIFFWriteDirectoryTagSbyte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int8 value); +#endif +static int TIFFWriteDirectoryTagSbyteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int8* value); +#if 0 +static int TIFFWriteDirectoryTagSbytePerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int8 value); +#endif +static int TIFFWriteDirectoryTagShort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 value); +static int TIFFWriteDirectoryTagShortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint16* value); +static int TIFFWriteDirectoryTagShortPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 value); +#ifdef notdef +static int TIFFWriteDirectoryTagSshort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int16 value); +#endif +static int TIFFWriteDirectoryTagSshortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int16* value); +#if 0 +static int TIFFWriteDirectoryTagSshortPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int16 value); +#endif +static int TIFFWriteDirectoryTagLong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value); +static int TIFFWriteDirectoryTagLongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value); +#if 0 +static int TIFFWriteDirectoryTagLongPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value); +#endif +#ifdef notdef +static int TIFFWriteDirectoryTagSlong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int32 value); +#endif +static int TIFFWriteDirectoryTagSlongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int32* value); +#if 0 +static int TIFFWriteDirectoryTagSlongPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int32 value); +#endif +#ifdef notdef +static int TIFFWriteDirectoryTagLong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint64 value); +#endif +static int TIFFWriteDirectoryTagLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value); +#ifdef notdef +static int TIFFWriteDirectoryTagSlong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int64 value); +#endif +static int TIFFWriteDirectoryTagSlong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int64* value); +static int TIFFWriteDirectoryTagRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value); +static int TIFFWriteDirectoryTagRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value); +static int TIFFWriteDirectoryTagSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value); +#ifdef notdef +static int TIFFWriteDirectoryTagFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value); +#endif +static int TIFFWriteDirectoryTagFloatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value); +#if 0 +static int TIFFWriteDirectoryTagFloatPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value); +#endif +#ifdef notdef +static int TIFFWriteDirectoryTagDouble(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value); +#endif +static int TIFFWriteDirectoryTagDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value); +#if 0 +static int TIFFWriteDirectoryTagDoublePerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value); +#endif +static int TIFFWriteDirectoryTagIfdArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value); +#ifdef notdef +static int TIFFWriteDirectoryTagIfd8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value); +#endif +static int TIFFWriteDirectoryTagShortLong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value); +static int TIFFWriteDirectoryTagLongLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value); +static int TIFFWriteDirectoryTagIfdIfd8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value); +#ifdef notdef +static int TIFFWriteDirectoryTagShortLongLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value); +#endif +static int TIFFWriteDirectoryTagColormap(TIFF* tif, uint32* ndir, TIFFDirEntry* dir); +static int TIFFWriteDirectoryTagTransferfunction(TIFF* tif, uint32* ndir, TIFFDirEntry* dir); +static int TIFFWriteDirectoryTagSubifd(TIFF* tif, uint32* ndir, TIFFDirEntry* dir); + +static int TIFFWriteDirectoryTagCheckedAscii(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, char* value); +static int TIFFWriteDirectoryTagCheckedUndefinedArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value); +#ifdef notdef +static int TIFFWriteDirectoryTagCheckedByte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint8 value); +#endif +static int TIFFWriteDirectoryTagCheckedByteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value); +#ifdef notdef +static int TIFFWriteDirectoryTagCheckedSbyte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int8 value); +#endif +static int TIFFWriteDirectoryTagCheckedSbyteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int8* value); +static int TIFFWriteDirectoryTagCheckedShort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 value); +static int TIFFWriteDirectoryTagCheckedShortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint16* value); +#ifdef notdef +static int TIFFWriteDirectoryTagCheckedSshort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int16 value); +#endif +static int TIFFWriteDirectoryTagCheckedSshortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int16* value); +static int TIFFWriteDirectoryTagCheckedLong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value); +static int TIFFWriteDirectoryTagCheckedLongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value); +#ifdef notdef +static int TIFFWriteDirectoryTagCheckedSlong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int32 value); +#endif +static int TIFFWriteDirectoryTagCheckedSlongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int32* value); +#ifdef notdef +static int TIFFWriteDirectoryTagCheckedLong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint64 value); +#endif +static int TIFFWriteDirectoryTagCheckedLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value); +#ifdef notdef +static int TIFFWriteDirectoryTagCheckedSlong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int64 value); +#endif +static int TIFFWriteDirectoryTagCheckedSlong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int64* value); +static int TIFFWriteDirectoryTagCheckedRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value); +static int TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value); +static int TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value); +#ifdef notdef +static int TIFFWriteDirectoryTagCheckedFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value); +#endif +static int TIFFWriteDirectoryTagCheckedFloatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value); +#ifdef notdef +static int TIFFWriteDirectoryTagCheckedDouble(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value); +#endif +static int TIFFWriteDirectoryTagCheckedDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value); +static int TIFFWriteDirectoryTagCheckedIfdArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value); +static int TIFFWriteDirectoryTagCheckedIfd8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value); + +static int TIFFWriteDirectoryTagData(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 datatype, uint32 count, uint32 datalength, void* data); + +static int TIFFLinkDirectory(TIFF*); + +/* + * Write the contents of the current directory + * to the specified file. This routine doesn't + * handle overwriting a directory with auxiliary + * storage that's been changed. + */ +int +TIFFWriteDirectory(TIFF* tif) +{ + return TIFFWriteDirectorySec(tif,TRUE,TRUE,NULL); +} + +/* + * Similar to TIFFWriteDirectory(), writes the directory out + * but leaves all data structures in memory so that it can be + * written again. This will make a partially written TIFF file + * readable before it is successfully completed/closed. + */ +int +TIFFCheckpointDirectory(TIFF* tif) +{ + int rc; + /* Setup the strips arrays, if they haven't already been. */ + if (tif->tif_dir.td_stripoffset == NULL) + (void) TIFFSetupStrips(tif); + rc = TIFFWriteDirectorySec(tif,TRUE,FALSE,NULL); + (void) TIFFSetWriteOffset(tif, TIFFSeekFile(tif, 0, SEEK_END)); + return rc; +} + +int +TIFFWriteCustomDirectory(TIFF* tif, uint64* pdiroff) +{ + return TIFFWriteDirectorySec(tif,FALSE,FALSE,pdiroff); +} + +/* + * Similar to TIFFWriteDirectory(), but if the directory has already + * been written once, it is relocated to the end of the file, in case it + * has changed in size. Note that this will result in the loss of the + * previously used directory space. + */ +int +TIFFRewriteDirectory( TIFF *tif ) +{ + static const char module[] = "TIFFRewriteDirectory"; + + /* We don't need to do anything special if it hasn't been written. */ + if( tif->tif_diroff == 0 ) + return TIFFWriteDirectory( tif ); + + /* + * Find and zero the pointer to this directory, so that TIFFLinkDirectory + * will cause it to be added after this directories current pre-link. + */ + + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + if (tif->tif_header.classic.tiff_diroff == tif->tif_diroff) + { + tif->tif_header.classic.tiff_diroff = 0; + tif->tif_diroff = 0; + + TIFFSeekFile(tif,4,SEEK_SET); + if (!WriteOK(tif, &(tif->tif_header.classic.tiff_diroff),4)) + { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "Error updating TIFF header"); + return (0); + } + } + else + { + uint32 nextdir; + nextdir = tif->tif_header.classic.tiff_diroff; + while(1) { + uint16 dircount; + uint32 nextnextdir; + + if (!SeekOK(tif, nextdir) || + !ReadOK(tif, &dircount, 2)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error fetching directory count"); + return (0); + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabShort(&dircount); + (void) TIFFSeekFile(tif, + nextdir+2+dircount*12, SEEK_SET); + if (!ReadOK(tif, &nextnextdir, 4)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error fetching directory link"); + return (0); + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong(&nextnextdir); + if (nextnextdir==tif->tif_diroff) + { + uint32 m; + m=0; + (void) TIFFSeekFile(tif, + nextdir+2+dircount*12, SEEK_SET); + if (!WriteOK(tif, &m, 4)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error writing directory link"); + return (0); + } + tif->tif_diroff=0; + break; + } + nextdir=nextnextdir; + } + } + } + else + { + if (tif->tif_header.big.tiff_diroff == tif->tif_diroff) + { + tif->tif_header.big.tiff_diroff = 0; + tif->tif_diroff = 0; + + TIFFSeekFile(tif,8,SEEK_SET); + if (!WriteOK(tif, &(tif->tif_header.big.tiff_diroff),8)) + { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "Error updating TIFF header"); + return (0); + } + } + else + { + uint64 nextdir; + nextdir = tif->tif_header.big.tiff_diroff; + while(1) { + uint64 dircount64; + uint16 dircount; + uint64 nextnextdir; + + if (!SeekOK(tif, nextdir) || + !ReadOK(tif, &dircount64, 8)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error fetching directory count"); + return (0); + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong8(&dircount64); + if (dircount64>0xFFFF) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Sanity check on tag count failed, likely corrupt TIFF"); + return (0); + } + dircount=(uint16)dircount64; + (void) TIFFSeekFile(tif, + nextdir+8+dircount*20, SEEK_SET); + if (!ReadOK(tif, &nextnextdir, 8)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error fetching directory link"); + return (0); + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong8(&nextnextdir); + if (nextnextdir==tif->tif_diroff) + { + uint64 m; + m=0; + (void) TIFFSeekFile(tif, + nextdir+8+dircount*20, SEEK_SET); + if (!WriteOK(tif, &m, 8)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error writing directory link"); + return (0); + } + tif->tif_diroff=0; + break; + } + nextdir=nextnextdir; + } + } + } + + /* + * Now use TIFFWriteDirectory() normally. + */ + + return TIFFWriteDirectory( tif ); +} + +static int +TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff) +{ + static const char module[] = "TIFFWriteDirectorySec"; + uint32 ndir; + TIFFDirEntry* dir; + uint32 dirsize; + void* dirmem; + uint32 m; + if (tif->tif_mode == O_RDONLY) + return (1); + + _TIFFFillStriles( tif ); + + /* + * Clear write state so that subsequent images with + * different characteristics get the right buffers + * setup for them. + */ + if (imagedone) + { + if (tif->tif_flags & TIFF_POSTENCODE) + { + tif->tif_flags &= ~TIFF_POSTENCODE; + if (!(*tif->tif_postencode)(tif)) + { + TIFFErrorExt(tif->tif_clientdata,module, + "Error post-encoding before directory write"); + return (0); + } + } + (*tif->tif_close)(tif); /* shutdown encoder */ + /* + * Flush any data that might have been written + * by the compression close+cleanup routines. But + * be careful not to write stuff if we didn't add data + * in the previous steps as the "rawcc" data may well be + * a previously read tile/strip in mixed read/write mode. + */ + if (tif->tif_rawcc > 0 + && (tif->tif_flags & TIFF_BEENWRITING) != 0 ) + { + if( !TIFFFlushData1(tif) ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Error flushing data before directory write"); + return (0); + } + } + if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) + { + _TIFFfree(tif->tif_rawdata); + tif->tif_rawdata = NULL; + tif->tif_rawcc = 0; + tif->tif_rawdatasize = 0; + tif->tif_rawdataoff = 0; + tif->tif_rawdataloaded = 0; + } + tif->tif_flags &= ~(TIFF_BEENWRITING|TIFF_BUFFERSETUP); + } + dir=NULL; + dirmem=NULL; + dirsize=0; + while (1) + { + ndir=0; + if (isimage) + { + if (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS)) + { + if (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_IMAGEWIDTH,tif->tif_dir.td_imagewidth)) + goto bad; + if (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_IMAGELENGTH,tif->tif_dir.td_imagelength)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS)) + { + if (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_TILEWIDTH,tif->tif_dir.td_tilewidth)) + goto bad; + if (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_TILELENGTH,tif->tif_dir.td_tilelength)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_RESOLUTION)) + { + if (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_XRESOLUTION,tif->tif_dir.td_xresolution)) + goto bad; + if (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_YRESOLUTION,tif->tif_dir.td_yresolution)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_POSITION)) + { + if (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_XPOSITION,tif->tif_dir.td_xposition)) + goto bad; + if (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_YPOSITION,tif->tif_dir.td_yposition)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) + { + if (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_SUBFILETYPE,tif->tif_dir.td_subfiletype)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE)) + { + if (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_BITSPERSAMPLE,tif->tif_dir.td_bitspersample)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_COMPRESSION)) + { + if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_COMPRESSION,tif->tif_dir.td_compression)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_PHOTOMETRIC)) + { + if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_PHOTOMETRIC,tif->tif_dir.td_photometric)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_THRESHHOLDING)) + { + if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_THRESHHOLDING,tif->tif_dir.td_threshholding)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_FILLORDER)) + { + if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_FILLORDER,tif->tif_dir.td_fillorder)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_ORIENTATION)) + { + if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_ORIENTATION,tif->tif_dir.td_orientation)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL)) + { + if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_SAMPLESPERPIXEL,tif->tif_dir.td_samplesperpixel)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP)) + { + if (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_ROWSPERSTRIP,tif->tif_dir.td_rowsperstrip)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE)) + { + if (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_MINSAMPLEVALUE,tif->tif_dir.td_minsamplevalue)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE)) + { + if (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_MAXSAMPLEVALUE,tif->tif_dir.td_maxsamplevalue)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_PLANARCONFIG)) + { + if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_PLANARCONFIG,tif->tif_dir.td_planarconfig)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT)) + { + if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_RESOLUTIONUNIT,tif->tif_dir.td_resolutionunit)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_PAGENUMBER)) + { + if (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_PAGENUMBER,2,&tif->tif_dir.td_pagenumber[0])) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_STRIPBYTECOUNTS)) + { + if (!isTiled(tif)) + { + if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount)) + goto bad; + } + else + { + if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount)) + goto bad; + } + } + if (TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) + { + if (!isTiled(tif)) + { + if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset)) + goto bad; + } + else + { + if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset)) + goto bad; + } + } + if (TIFFFieldSet(tif,FIELD_COLORMAP)) + { + if (!TIFFWriteDirectoryTagColormap(tif,&ndir,dir)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_EXTRASAMPLES)) + { + if (tif->tif_dir.td_extrasamples) + { + uint16 na; + uint16* nb; + TIFFGetFieldDefaulted(tif,TIFFTAG_EXTRASAMPLES,&na,&nb); + if (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_EXTRASAMPLES,na,nb)) + goto bad; + } + } + if (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT)) + { + if (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_SAMPLEFORMAT,tif->tif_dir.td_sampleformat)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE)) + { + if (!TIFFWriteDirectoryTagSampleformatArray(tif,&ndir,dir,TIFFTAG_SMINSAMPLEVALUE,tif->tif_dir.td_samplesperpixel,tif->tif_dir.td_sminsamplevalue)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE)) + { + if (!TIFFWriteDirectoryTagSampleformatArray(tif,&ndir,dir,TIFFTAG_SMAXSAMPLEVALUE,tif->tif_dir.td_samplesperpixel,tif->tif_dir.td_smaxsamplevalue)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_IMAGEDEPTH)) + { + if (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_IMAGEDEPTH,tif->tif_dir.td_imagedepth)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_TILEDEPTH)) + { + if (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_TILEDEPTH,tif->tif_dir.td_tiledepth)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_HALFTONEHINTS)) + { + if (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_HALFTONEHINTS,2,&tif->tif_dir.td_halftonehints[0])) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING)) + { + if (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_YCBCRSUBSAMPLING,2,&tif->tif_dir.td_ycbcrsubsampling[0])) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) + { + if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_YCBCRPOSITIONING,tif->tif_dir.td_ycbcrpositioning)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_REFBLACKWHITE)) + { + if (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,TIFFTAG_REFERENCEBLACKWHITE,6,tif->tif_dir.td_refblackwhite)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION)) + { + if (!TIFFWriteDirectoryTagTransferfunction(tif,&ndir,dir)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_INKNAMES)) + { + if (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,TIFFTAG_INKNAMES,tif->tif_dir.td_inknameslen,tif->tif_dir.td_inknames)) + goto bad; + } + if (TIFFFieldSet(tif,FIELD_SUBIFD)) + { + if (!TIFFWriteDirectoryTagSubifd(tif,&ndir,dir)) + goto bad; + } + { + uint32 n; + for (n=0; ntif_nfields; n++) { + const TIFFField* o; + o = tif->tif_fields[n]; + if ((o->field_bit>=FIELD_CODEC)&&(TIFFFieldSet(tif,o->field_bit))) + { + switch (o->get_field_type) + { + case TIFF_SETGET_ASCII: + { + uint32 pa; + char* pb; + assert(o->field_type==TIFF_ASCII); + assert(o->field_readcount==TIFF_VARIABLE); + assert(o->field_passcount==0); + TIFFGetField(tif,o->field_tag,&pb); + pa=(uint32)(strlen(pb)); + if (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,o->field_tag,pa,pb)) + goto bad; + } + break; + case TIFF_SETGET_UINT16: + { + uint16 p; + assert(o->field_type==TIFF_SHORT); + assert(o->field_readcount==1); + assert(o->field_passcount==0); + TIFFGetField(tif,o->field_tag,&p); + if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,o->field_tag,p)) + goto bad; + } + break; + case TIFF_SETGET_UINT32: + { + uint32 p; + assert(o->field_type==TIFF_LONG); + assert(o->field_readcount==1); + assert(o->field_passcount==0); + TIFFGetField(tif,o->field_tag,&p); + if (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,o->field_tag,p)) + goto bad; + } + break; + case TIFF_SETGET_C32_UINT8: + { + uint32 pa; + void* pb; + assert(o->field_type==TIFF_UNDEFINED); + assert(o->field_readcount==TIFF_VARIABLE2); + assert(o->field_passcount==1); + TIFFGetField(tif,o->field_tag,&pa,&pb); + if (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,o->field_tag,pa,pb)) + goto bad; + } + break; + default: + assert(0); /* we should never get here */ + break; + } + } + } + } + } + for (m=0; m<(uint32)(tif->tif_dir.td_customValueCount); m++) + { + switch (tif->tif_dir.td_customValues[m].info->field_type) + { + case TIFF_ASCII: + if (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_UNDEFINED: + if (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_BYTE: + if (!TIFFWriteDirectoryTagByteArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_SBYTE: + if (!TIFFWriteDirectoryTagSbyteArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_SHORT: + if (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_SSHORT: + if (!TIFFWriteDirectoryTagSshortArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_LONG: + if (!TIFFWriteDirectoryTagLongArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_SLONG: + if (!TIFFWriteDirectoryTagSlongArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_LONG8: + if (!TIFFWriteDirectoryTagLong8Array(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_SLONG8: + if (!TIFFWriteDirectoryTagSlong8Array(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_RATIONAL: + if (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_SRATIONAL: + if (!TIFFWriteDirectoryTagSrationalArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_FLOAT: + if (!TIFFWriteDirectoryTagFloatArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_DOUBLE: + if (!TIFFWriteDirectoryTagDoubleArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_IFD: + if (!TIFFWriteDirectoryTagIfdArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + case TIFF_IFD8: + if (!TIFFWriteDirectoryTagIfdIfd8Array(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + goto bad; + break; + default: + assert(0); /* we should never get here */ + break; + } + } + if (dir!=NULL) + break; + dir=_TIFFmalloc(ndir*sizeof(TIFFDirEntry)); + if (dir==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + goto bad; + } + if (isimage) + { + if ((tif->tif_diroff==0)&&(!TIFFLinkDirectory(tif))) + goto bad; + } + else + tif->tif_diroff=(TIFFSeekFile(tif,0,SEEK_END)+1)&(~1); + if (pdiroff!=NULL) + *pdiroff=tif->tif_diroff; + if (!(tif->tif_flags&TIFF_BIGTIFF)) + dirsize=2+ndir*12+4; + else + dirsize=8+ndir*20+8; + tif->tif_dataoff=tif->tif_diroff+dirsize; + if (!(tif->tif_flags&TIFF_BIGTIFF)) + tif->tif_dataoff=(uint32)tif->tif_dataoff; + if ((tif->tif_dataofftif_diroff)||(tif->tif_dataoff<(uint64)dirsize)) + { + TIFFErrorExt(tif->tif_clientdata,module,"Maximum TIFF file size exceeded"); + goto bad; + } + if (tif->tif_dataoff&1) + tif->tif_dataoff++; + if (isimage) + tif->tif_curdir++; + } + if (isimage) + { + if (TIFFFieldSet(tif,FIELD_SUBIFD)&&(tif->tif_subifdoff==0)) + { + uint32 na; + TIFFDirEntry* nb; + for (na=0, nb=dir; ; na++, nb++) + { + assert(natdir_tag==TIFFTAG_SUBIFD) + break; + } + if (!(tif->tif_flags&TIFF_BIGTIFF)) + tif->tif_subifdoff=tif->tif_diroff+2+na*12+8; + else + tif->tif_subifdoff=tif->tif_diroff+8+na*20+12; + } + } + dirmem=_TIFFmalloc(dirsize); + if (dirmem==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + goto bad; + } + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + uint8* n; + uint32 nTmp; + TIFFDirEntry* o; + n=dirmem; + *(uint16*)n=ndir; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)n); + n+=2; + o=dir; + for (m=0; mtdir_tag; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)n); + n+=2; + *(uint16*)n=o->tdir_type; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)n); + n+=2; + nTmp = (uint32)o->tdir_count; + _TIFFmemcpy(n,&nTmp,4); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)n); + n+=4; + /* This is correct. The data has been */ + /* swabbed previously in TIFFWriteDirectoryTagData */ + _TIFFmemcpy(n,&o->tdir_offset,4); + n+=4; + o++; + } + nTmp = (uint32)tif->tif_nextdiroff; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(&nTmp); + _TIFFmemcpy(n,&nTmp,4); + } + else + { + uint8* n; + TIFFDirEntry* o; + n=dirmem; + *(uint64*)n=ndir; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)n); + n+=8; + o=dir; + for (m=0; mtdir_tag; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)n); + n+=2; + *(uint16*)n=o->tdir_type; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)n); + n+=2; + _TIFFmemcpy(n,&o->tdir_count,8); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)n); + n+=8; + _TIFFmemcpy(n,&o->tdir_offset,8); + n+=8; + o++; + } + _TIFFmemcpy(n,&tif->tif_nextdiroff,8); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)n); + } + _TIFFfree(dir); + dir=NULL; + if (!SeekOK(tif,tif->tif_diroff)) + { + TIFFErrorExt(tif->tif_clientdata,module,"IO error writing directory"); + goto bad; + } + if (!WriteOK(tif,dirmem,(tmsize_t)dirsize)) + { + TIFFErrorExt(tif->tif_clientdata,module,"IO error writing directory"); + goto bad; + } + _TIFFfree(dirmem); + if (imagedone) + { + TIFFFreeDirectory(tif); + tif->tif_flags &= ~TIFF_DIRTYDIRECT; + tif->tif_flags &= ~TIFF_DIRTYSTRIP; + (*tif->tif_cleanup)(tif); + /* + * Reset directory-related state for subsequent + * directories. + */ + TIFFCreateDirectory(tif); + } + return(1); +bad: + if (dir!=NULL) + _TIFFfree(dir); + if (dirmem!=NULL) + _TIFFfree(dirmem); + return(0); +} + +static int +TIFFWriteDirectoryTagSampleformatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value) +{ + static const char module[] = "TIFFWriteDirectoryTagSampleformatArray"; + void* conv; + uint32 i; + int ok; + conv = _TIFFmalloc(count*sizeof(double)); + if (conv == NULL) + { + TIFFErrorExt(tif->tif_clientdata, module, "Out of memory"); + return (0); + } + + switch (tif->tif_dir.td_sampleformat) + { + case SAMPLEFORMAT_IEEEFP: + if (tif->tif_dir.td_bitspersample<=32) + { + for (i = 0; i < count; ++i) + ((float*)conv)[i] = (float)value[i]; + ok = TIFFWriteDirectoryTagFloatArray(tif,ndir,dir,tag,count,(float*)conv); + } + else + { + ok = TIFFWriteDirectoryTagDoubleArray(tif,ndir,dir,tag,count,value); + } + break; + case SAMPLEFORMAT_INT: + if (tif->tif_dir.td_bitspersample<=8) + { + for (i = 0; i < count; ++i) + ((int8*)conv)[i] = (int8)value[i]; + ok = TIFFWriteDirectoryTagSbyteArray(tif,ndir,dir,tag,count,(int8*)conv); + } + else if (tif->tif_dir.td_bitspersample<=16) + { + for (i = 0; i < count; ++i) + ((int16*)conv)[i] = (int16)value[i]; + ok = TIFFWriteDirectoryTagSshortArray(tif,ndir,dir,tag,count,(int16*)conv); + } + else + { + for (i = 0; i < count; ++i) + ((int32*)conv)[i] = (int32)value[i]; + ok = TIFFWriteDirectoryTagSlongArray(tif,ndir,dir,tag,count,(int32*)conv); + } + break; + case SAMPLEFORMAT_UINT: + if (tif->tif_dir.td_bitspersample<=8) + { + for (i = 0; i < count; ++i) + ((uint8*)conv)[i] = (uint8)value[i]; + ok = TIFFWriteDirectoryTagByteArray(tif,ndir,dir,tag,count,(uint8*)conv); + } + else if (tif->tif_dir.td_bitspersample<=16) + { + for (i = 0; i < count; ++i) + ((uint16*)conv)[i] = (uint16)value[i]; + ok = TIFFWriteDirectoryTagShortArray(tif,ndir,dir,tag,count,(uint16*)conv); + } + else + { + for (i = 0; i < count; ++i) + ((uint32*)conv)[i] = (uint32)value[i]; + ok = TIFFWriteDirectoryTagLongArray(tif,ndir,dir,tag,count,(uint32*)conv); + } + break; + default: + ok = 0; + } + + _TIFFfree(conv); + return (ok); +} + +#if 0 +static int +TIFFWriteDirectoryTagSampleformatPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value) +{ + switch (tif->tif_dir.td_sampleformat) + { + case SAMPLEFORMAT_IEEEFP: + if (tif->tif_dir.td_bitspersample<=32) + return(TIFFWriteDirectoryTagFloatPerSample(tif,ndir,dir,tag,(float)value)); + else + return(TIFFWriteDirectoryTagDoublePerSample(tif,ndir,dir,tag,value)); + case SAMPLEFORMAT_INT: + if (tif->tif_dir.td_bitspersample<=8) + return(TIFFWriteDirectoryTagSbytePerSample(tif,ndir,dir,tag,(int8)value)); + else if (tif->tif_dir.td_bitspersample<=16) + return(TIFFWriteDirectoryTagSshortPerSample(tif,ndir,dir,tag,(int16)value)); + else + return(TIFFWriteDirectoryTagSlongPerSample(tif,ndir,dir,tag,(int32)value)); + case SAMPLEFORMAT_UINT: + if (tif->tif_dir.td_bitspersample<=8) + return(TIFFWriteDirectoryTagBytePerSample(tif,ndir,dir,tag,(uint8)value)); + else if (tif->tif_dir.td_bitspersample<=16) + return(TIFFWriteDirectoryTagShortPerSample(tif,ndir,dir,tag,(uint16)value)); + else + return(TIFFWriteDirectoryTagLongPerSample(tif,ndir,dir,tag,(uint32)value)); + default: + return(1); + } +} +#endif + +static int +TIFFWriteDirectoryTagAscii(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, char* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedAscii(tif,ndir,dir,tag,count,value)); +} + +static int +TIFFWriteDirectoryTagUndefinedArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedUndefinedArray(tif,ndir,dir,tag,count,value)); +} + +#ifdef notdef +static int +TIFFWriteDirectoryTagByte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint8 value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedByte(tif,ndir,dir,tag,value)); +} +#endif + +static int +TIFFWriteDirectoryTagByteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedByteArray(tif,ndir,dir,tag,count,value)); +} + +#if 0 +static int +TIFFWriteDirectoryTagBytePerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint8 value) +{ + static const char module[] = "TIFFWriteDirectoryTagBytePerSample"; + uint8* m; + uint8* na; + uint16 nb; + int o; + if (dir==NULL) + { + (*ndir)++; + return(1); + } + m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(uint8)); + if (m==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) + *na=value; + o=TIFFWriteDirectoryTagCheckedByteArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); + _TIFFfree(m); + return(o); +} +#endif + +#ifdef notdef +static int +TIFFWriteDirectoryTagSbyte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int8 value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedSbyte(tif,ndir,dir,tag,value)); +} +#endif + +static int +TIFFWriteDirectoryTagSbyteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int8* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedSbyteArray(tif,ndir,dir,tag,count,value)); +} + +#if 0 +static int +TIFFWriteDirectoryTagSbytePerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int8 value) +{ + static const char module[] = "TIFFWriteDirectoryTagSbytePerSample"; + int8* m; + int8* na; + uint16 nb; + int o; + if (dir==NULL) + { + (*ndir)++; + return(1); + } + m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(int8)); + if (m==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) + *na=value; + o=TIFFWriteDirectoryTagCheckedSbyteArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); + _TIFFfree(m); + return(o); +} +#endif + +static int +TIFFWriteDirectoryTagShort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedShort(tif,ndir,dir,tag,value)); +} + +static int +TIFFWriteDirectoryTagShortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint16* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedShortArray(tif,ndir,dir,tag,count,value)); +} + +static int +TIFFWriteDirectoryTagShortPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 value) +{ + static const char module[] = "TIFFWriteDirectoryTagShortPerSample"; + uint16* m; + uint16* na; + uint16 nb; + int o; + if (dir==NULL) + { + (*ndir)++; + return(1); + } + m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(uint16)); + if (m==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) + *na=value; + o=TIFFWriteDirectoryTagCheckedShortArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); + _TIFFfree(m); + return(o); +} + +#ifdef notdef +static int +TIFFWriteDirectoryTagSshort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int16 value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedSshort(tif,ndir,dir,tag,value)); +} +#endif + +static int +TIFFWriteDirectoryTagSshortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int16* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedSshortArray(tif,ndir,dir,tag,count,value)); +} + +#if 0 +static int +TIFFWriteDirectoryTagSshortPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int16 value) +{ + static const char module[] = "TIFFWriteDirectoryTagSshortPerSample"; + int16* m; + int16* na; + uint16 nb; + int o; + if (dir==NULL) + { + (*ndir)++; + return(1); + } + m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(int16)); + if (m==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) + *na=value; + o=TIFFWriteDirectoryTagCheckedSshortArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); + _TIFFfree(m); + return(o); +} +#endif + +static int +TIFFWriteDirectoryTagLong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedLong(tif,ndir,dir,tag,value)); +} + +static int +TIFFWriteDirectoryTagLongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedLongArray(tif,ndir,dir,tag,count,value)); +} + +#if 0 +static int +TIFFWriteDirectoryTagLongPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value) +{ + static const char module[] = "TIFFWriteDirectoryTagLongPerSample"; + uint32* m; + uint32* na; + uint16 nb; + int o; + if (dir==NULL) + { + (*ndir)++; + return(1); + } + m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(uint32)); + if (m==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) + *na=value; + o=TIFFWriteDirectoryTagCheckedLongArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); + _TIFFfree(m); + return(o); +} +#endif + +#ifdef notdef +static int +TIFFWriteDirectoryTagSlong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int32 value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedSlong(tif,ndir,dir,tag,value)); +} +#endif + +static int +TIFFWriteDirectoryTagSlongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int32* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedSlongArray(tif,ndir,dir,tag,count,value)); +} + +#if 0 +static int +TIFFWriteDirectoryTagSlongPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int32 value) +{ + static const char module[] = "TIFFWriteDirectoryTagSlongPerSample"; + int32* m; + int32* na; + uint16 nb; + int o; + if (dir==NULL) + { + (*ndir)++; + return(1); + } + m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(int32)); + if (m==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) + *na=value; + o=TIFFWriteDirectoryTagCheckedSlongArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); + _TIFFfree(m); + return(o); +} +#endif + +#ifdef notdef +static int +TIFFWriteDirectoryTagLong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint64 value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedLong8(tif,ndir,dir,tag,value)); +} +#endif + +static int +TIFFWriteDirectoryTagLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedLong8Array(tif,ndir,dir,tag,count,value)); +} + +#ifdef notdef +static int +TIFFWriteDirectoryTagSlong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int64 value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedSlong8(tif,ndir,dir,tag,value)); +} +#endif + +static int +TIFFWriteDirectoryTagSlong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int64* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedSlong8Array(tif,ndir,dir,tag,count,value)); +} + +static int +TIFFWriteDirectoryTagRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedRational(tif,ndir,dir,tag,value)); +} + +static int +TIFFWriteDirectoryTagRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedRationalArray(tif,ndir,dir,tag,count,value)); +} + +static int +TIFFWriteDirectoryTagSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedSrationalArray(tif,ndir,dir,tag,count,value)); +} + +#ifdef notdef +static int TIFFWriteDirectoryTagFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedFloat(tif,ndir,dir,tag,value)); +} +#endif + +static int TIFFWriteDirectoryTagFloatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedFloatArray(tif,ndir,dir,tag,count,value)); +} + +#if 0 +static int TIFFWriteDirectoryTagFloatPerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value) +{ + static const char module[] = "TIFFWriteDirectoryTagFloatPerSample"; + float* m; + float* na; + uint16 nb; + int o; + if (dir==NULL) + { + (*ndir)++; + return(1); + } + m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(float)); + if (m==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) + *na=value; + o=TIFFWriteDirectoryTagCheckedFloatArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); + _TIFFfree(m); + return(o); +} +#endif + +#ifdef notdef +static int TIFFWriteDirectoryTagDouble(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedDouble(tif,ndir,dir,tag,value)); +} +#endif + +static int TIFFWriteDirectoryTagDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedDoubleArray(tif,ndir,dir,tag,count,value)); +} + +#if 0 +static int TIFFWriteDirectoryTagDoublePerSample(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value) +{ + static const char module[] = "TIFFWriteDirectoryTagDoublePerSample"; + double* m; + double* na; + uint16 nb; + int o; + if (dir==NULL) + { + (*ndir)++; + return(1); + } + m=_TIFFmalloc(tif->tif_dir.td_samplesperpixel*sizeof(double)); + if (m==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + for (na=m, nb=0; nbtif_dir.td_samplesperpixel; na++, nb++) + *na=value; + o=TIFFWriteDirectoryTagCheckedDoubleArray(tif,ndir,dir,tag,tif->tif_dir.td_samplesperpixel,m); + _TIFFfree(m); + return(o); +} +#endif + +static int +TIFFWriteDirectoryTagIfdArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedIfdArray(tif,ndir,dir,tag,count,value)); +} + +#ifdef notdef +static int +TIFFWriteDirectoryTagIfd8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + return(TIFFWriteDirectoryTagCheckedIfd8Array(tif,ndir,dir,tag,count,value)); +} +#endif + +static int +TIFFWriteDirectoryTagShortLong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value) +{ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + if (value<=0xFFFF) + return(TIFFWriteDirectoryTagCheckedShort(tif,ndir,dir,tag,(uint16)value)); + else + return(TIFFWriteDirectoryTagCheckedLong(tif,ndir,dir,tag,value)); +} + +/************************************************************************/ +/* TIFFWriteDirectoryTagLongLong8Array() */ +/* */ +/* Write out LONG8 array as LONG8 for BigTIFF or LONG for */ +/* Classic TIFF with some checking. */ +/************************************************************************/ + +static int +TIFFWriteDirectoryTagLongLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value) +{ + static const char module[] = "TIFFWriteDirectoryTagLongLong8Array"; + uint64* ma; + uint32 mb; + uint32* p; + uint32* q; + int o; + + /* is this just a counting pass? */ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + + /* We always write LONG8 for BigTIFF, no checking needed. */ + if( tif->tif_flags&TIFF_BIGTIFF ) + return TIFFWriteDirectoryTagCheckedLong8Array(tif,ndir,dir, + tag,count,value); + + /* + ** For classic tiff we want to verify everything is in range for LONG + ** and convert to long format. + */ + + p = _TIFFmalloc(count*sizeof(uint32)); + if (p==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + + for (q=p, ma=value, mb=0; mb0xFFFFFFFF) + { + TIFFErrorExt(tif->tif_clientdata,module, + "Attempt to write value larger than 0xFFFFFFFF in Classic TIFF file."); + _TIFFfree(p); + return(0); + } + *q= (uint32)(*ma); + } + + o=TIFFWriteDirectoryTagCheckedLongArray(tif,ndir,dir,tag,count,p); + _TIFFfree(p); + + return(o); +} + +/************************************************************************/ +/* TIFFWriteDirectoryTagIfdIfd8Array() */ +/* */ +/* Write either IFD8 or IFD array depending on file type. */ +/************************************************************************/ + +static int +TIFFWriteDirectoryTagIfdIfd8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value) +{ + static const char module[] = "TIFFWriteDirectoryTagIfdIfd8Array"; + uint64* ma; + uint32 mb; + uint32* p; + uint32* q; + int o; + + /* is this just a counting pass? */ + if (dir==NULL) + { + (*ndir)++; + return(1); + } + + /* We always write IFD8 for BigTIFF, no checking needed. */ + if( tif->tif_flags&TIFF_BIGTIFF ) + return TIFFWriteDirectoryTagCheckedIfd8Array(tif,ndir,dir, + tag,count,value); + + /* + ** For classic tiff we want to verify everything is in range for IFD + ** and convert to long format. + */ + + p = _TIFFmalloc(count*sizeof(uint32)); + if (p==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + + for (q=p, ma=value, mb=0; mb0xFFFFFFFF) + { + TIFFErrorExt(tif->tif_clientdata,module, + "Attempt to write value larger than 0xFFFFFFFF in Classic TIFF file."); + _TIFFfree(p); + return(0); + } + *q= (uint32)(*ma); + } + + o=TIFFWriteDirectoryTagCheckedIfdArray(tif,ndir,dir,tag,count,p); + _TIFFfree(p); + + return(o); +} + +#ifdef notdef +static int +TIFFWriteDirectoryTagShortLongLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value) +{ + static const char module[] = "TIFFWriteDirectoryTagShortLongLong8Array"; + uint64* ma; + uint32 mb; + uint8 n; + int o; + if (dir==NULL) + { + (*ndir)++; + return(1); + } + n=0; + for (ma=value, mb=0; mb0xFFFF)) + n=1; + if ((n==1)&&(*ma>0xFFFFFFFF)) + { + n=2; + break; + } + } + if (n==0) + { + uint16* p; + uint16* q; + p=_TIFFmalloc(count*sizeof(uint16)); + if (p==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + for (ma=value, mb=0, q=p; mbtif_clientdata,module,"Out of memory"); + return(0); + } + for (ma=value, mb=0, q=p; mbtif_dir.td_bitspersample); + n=_TIFFmalloc(3*m*sizeof(uint16)); + if (n==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + _TIFFmemcpy(&n[0],tif->tif_dir.td_colormap[0],m*sizeof(uint16)); + _TIFFmemcpy(&n[m],tif->tif_dir.td_colormap[1],m*sizeof(uint16)); + _TIFFmemcpy(&n[2*m],tif->tif_dir.td_colormap[2],m*sizeof(uint16)); + o=TIFFWriteDirectoryTagCheckedShortArray(tif,ndir,dir,TIFFTAG_COLORMAP,3*m,n); + _TIFFfree(n); + return(o); +} + +static int +TIFFWriteDirectoryTagTransferfunction(TIFF* tif, uint32* ndir, TIFFDirEntry* dir) +{ + static const char module[] = "TIFFWriteDirectoryTagTransferfunction"; + uint32 m; + uint16 n; + uint16* o; + int p; + if (dir==NULL) + { + (*ndir)++; + return(1); + } + m=(1<tif_dir.td_bitspersample); + n=tif->tif_dir.td_samplesperpixel-tif->tif_dir.td_extrasamples; + /* + * Check if the table can be written as a single column, + * or if it must be written as 3 columns. Note that we + * write a 3-column tag if there are 2 samples/pixel and + * a single column of data won't suffice--hmm. + */ + if (n>3) + n=3; + if (n==3) + { + if (!_TIFFmemcmp(tif->tif_dir.td_transferfunction[0],tif->tif_dir.td_transferfunction[2],m*sizeof(uint16))) + n=2; + } + if (n==2) + { + if (!_TIFFmemcmp(tif->tif_dir.td_transferfunction[0],tif->tif_dir.td_transferfunction[1],m*sizeof(uint16))) + n=1; + } + if (n==0) + n=1; + o=_TIFFmalloc(n*m*sizeof(uint16)); + if (o==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + _TIFFmemcpy(&o[0],tif->tif_dir.td_transferfunction[0],m*sizeof(uint16)); + if (n>1) + _TIFFmemcpy(&o[m],tif->tif_dir.td_transferfunction[1],m*sizeof(uint16)); + if (n>2) + _TIFFmemcpy(&o[2*m],tif->tif_dir.td_transferfunction[2],m*sizeof(uint16)); + p=TIFFWriteDirectoryTagCheckedShortArray(tif,ndir,dir,TIFFTAG_TRANSFERFUNCTION,n*m,o); + _TIFFfree(o); + return(p); +} + +static int +TIFFWriteDirectoryTagSubifd(TIFF* tif, uint32* ndir, TIFFDirEntry* dir) +{ + static const char module[] = "TIFFWriteDirectoryTagSubifd"; + uint64 m; + int n; + if (tif->tif_dir.td_nsubifd==0) + return(1); + if (dir==NULL) + { + (*ndir)++; + return(1); + } + m=tif->tif_dataoff; + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + uint32* o; + uint64* pa; + uint32* pb; + uint16 p; + o=_TIFFmalloc(tif->tif_dir.td_nsubifd*sizeof(uint32)); + if (o==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + pa=tif->tif_dir.td_subifd; + pb=o; + for (p=0; p < tif->tif_dir.td_nsubifd; p++) + { + assert(pa != 0); + assert(*pa <= 0xFFFFFFFFUL); + *pb++=(uint32)(*pa++); + } + n=TIFFWriteDirectoryTagCheckedIfdArray(tif,ndir,dir,TIFFTAG_SUBIFD,tif->tif_dir.td_nsubifd,o); + _TIFFfree(o); + } + else + n=TIFFWriteDirectoryTagCheckedIfd8Array(tif,ndir,dir,TIFFTAG_SUBIFD,tif->tif_dir.td_nsubifd,tif->tif_dir.td_subifd); + if (!n) + return(0); + /* + * Total hack: if this directory includes a SubIFD + * tag then force the next directories to be + * written as ``sub directories'' of this one. This + * is used to write things like thumbnails and + * image masks that one wants to keep out of the + * normal directory linkage access mechanism. + */ + tif->tif_flags|=TIFF_INSUBIFD; + tif->tif_nsubifd=tif->tif_dir.td_nsubifd; + if (tif->tif_dir.td_nsubifd==1) + tif->tif_subifdoff=0; + else + tif->tif_subifdoff=m; + return(1); +} + +static int +TIFFWriteDirectoryTagCheckedAscii(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, char* value) +{ + assert(sizeof(char)==1); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_ASCII,count,count,value)); +} + +static int +TIFFWriteDirectoryTagCheckedUndefinedArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value) +{ + assert(sizeof(uint8)==1); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_UNDEFINED,count,count,value)); +} + +#ifdef notdef +static int +TIFFWriteDirectoryTagCheckedByte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint8 value) +{ + assert(sizeof(uint8)==1); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_BYTE,1,1,&value)); +} +#endif + +static int +TIFFWriteDirectoryTagCheckedByteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint8* value) +{ + assert(sizeof(uint8)==1); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_BYTE,count,count,value)); +} + +#ifdef notdef +static int +TIFFWriteDirectoryTagCheckedSbyte(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int8 value) +{ + assert(sizeof(int8)==1); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SBYTE,1,1,&value)); +} +#endif + +static int +TIFFWriteDirectoryTagCheckedSbyteArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int8* value) +{ + assert(sizeof(int8)==1); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SBYTE,count,count,value)); +} + +static int +TIFFWriteDirectoryTagCheckedShort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 value) +{ + uint16 m; + assert(sizeof(uint16)==2); + m=value; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabShort(&m); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SHORT,1,2,&m)); +} + +static int +TIFFWriteDirectoryTagCheckedShortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint16* value) +{ + assert(count<0x80000000); + assert(sizeof(uint16)==2); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfShort(value,count); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SHORT,count,count*2,value)); +} + +#ifdef notdef +static int +TIFFWriteDirectoryTagCheckedSshort(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int16 value) +{ + int16 m; + assert(sizeof(int16)==2); + m=value; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabShort((uint16*)(&m)); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SSHORT,1,2,&m)); +} +#endif + +static int +TIFFWriteDirectoryTagCheckedSshortArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int16* value) +{ + assert(count<0x80000000); + assert(sizeof(int16)==2); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfShort((uint16*)value,count); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SSHORT,count,count*2,value)); +} + +static int +TIFFWriteDirectoryTagCheckedLong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 value) +{ + uint32 m; + assert(sizeof(uint32)==4); + m=value; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(&m); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_LONG,1,4,&m)); +} + +static int +TIFFWriteDirectoryTagCheckedLongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value) +{ + assert(count<0x40000000); + assert(sizeof(uint32)==4); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong(value,count); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_LONG,count,count*4,value)); +} + +#ifdef notdef +static int +TIFFWriteDirectoryTagCheckedSlong(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int32 value) +{ + int32 m; + assert(sizeof(int32)==4); + m=value; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong((uint32*)(&m)); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SLONG,1,4,&m)); +} +#endif + +static int +TIFFWriteDirectoryTagCheckedSlongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int32* value) +{ + assert(count<0x40000000); + assert(sizeof(int32)==4); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong((uint32*)value,count); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SLONG,count,count*4,value)); +} + +#ifdef notdef +static int +TIFFWriteDirectoryTagCheckedLong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint64 value) +{ + uint64 m; + assert(sizeof(uint64)==8); + assert(tif->tif_flags&TIFF_BIGTIFF); + m=value; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8(&m); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_LONG8,1,8,&m)); +} +#endif + +static int +TIFFWriteDirectoryTagCheckedLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value) +{ + assert(count<0x20000000); + assert(sizeof(uint64)==8); + assert(tif->tif_flags&TIFF_BIGTIFF); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong8(value,count); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_LONG8,count,count*8,value)); +} + +#ifdef notdef +static int +TIFFWriteDirectoryTagCheckedSlong8(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, int64 value) +{ + int64 m; + assert(sizeof(int64)==8); + assert(tif->tif_flags&TIFF_BIGTIFF); + m=value; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8((uint64*)(&m)); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SLONG8,1,8,&m)); +} +#endif + +static int +TIFFWriteDirectoryTagCheckedSlong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int64* value) +{ + assert(count<0x20000000); + assert(sizeof(int64)==8); + assert(tif->tif_flags&TIFF_BIGTIFF); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong8((uint64*)value,count); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SLONG8,count,count*8,value)); +} + +static int +TIFFWriteDirectoryTagCheckedRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value) +{ + uint32 m[2]; + assert(value>=0.0); + assert(sizeof(uint32)==4); + if (value<=0.0) + { + m[0]=0; + m[1]=1; + } + else if (value==(double)(uint32)value) + { + m[0]=(uint32)value; + m[1]=1; + } + else if (value<1.0) + { + m[0]=(uint32)(value*0xFFFFFFFF); + m[1]=0xFFFFFFFF; + } + else + { + m[0]=0xFFFFFFFF; + m[1]=(uint32)(0xFFFFFFFF/value); + } + if (tif->tif_flags&TIFF_SWAB) + { + TIFFSwabLong(&m[0]); + TIFFSwabLong(&m[1]); + } + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_RATIONAL,1,8,&m[0])); +} + +static int +TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value) +{ + static const char module[] = "TIFFWriteDirectoryTagCheckedRationalArray"; + uint32* m; + float* na; + uint32* nb; + uint32 nc; + int o; + assert(sizeof(uint32)==4); + m=_TIFFmalloc(count*2*sizeof(uint32)); + if (m==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + for (na=value, nb=m, nc=0; nctif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong(m,count*2); + o=TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_RATIONAL,count,count*8,&m[0]); + _TIFFfree(m); + return(o); +} + +static int +TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value) +{ + static const char module[] = "TIFFWriteDirectoryTagCheckedSrationalArray"; + int32* m; + float* na; + int32* nb; + uint32 nc; + int o; + assert(sizeof(int32)==4); + m=_TIFFmalloc(count*2*sizeof(int32)); + if (m==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + for (na=value, nb=m, nc=0; nc-1.0) + { + nb[0]=-(int32)((-*na)*0x7FFFFFFF); + nb[1]=0x7FFFFFFF; + } + else + { + nb[0]=-0x7FFFFFFF; + nb[1]=(int32)(0x7FFFFFFF/(-*na)); + } + } + else + { + if (*na==(int32)(*na)) + { + nb[0]=(int32)(*na); + nb[1]=1; + } + else if (*na<1.0) + { + nb[0]=(int32)((*na)*0x7FFFFFFF); + nb[1]=0x7FFFFFFF; + } + else + { + nb[0]=0x7FFFFFFF; + nb[1]=(int32)(0x7FFFFFFF/(*na)); + } + } + } + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong((uint32*)m,count*2); + o=TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SRATIONAL,count,count*8,&m[0]); + _TIFFfree(m); + return(o); +} + +#ifdef notdef +static int +TIFFWriteDirectoryTagCheckedFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value) +{ + float m; + assert(sizeof(float)==4); + m=value; + TIFFCvtNativeToIEEEFloat(tif,1,&m); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabFloat(&m); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_FLOAT,1,4,&m)); +} +#endif + +static int +TIFFWriteDirectoryTagCheckedFloatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value) +{ + assert(count<0x40000000); + assert(sizeof(float)==4); + TIFFCvtNativeToIEEEFloat(tif,count,&value); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfFloat(value,count); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_FLOAT,count,count*4,value)); +} + +#ifdef notdef +static int +TIFFWriteDirectoryTagCheckedDouble(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value) +{ + double m; + assert(sizeof(double)==8); + m=value; + TIFFCvtNativeToIEEEDouble(tif,1,&m); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabDouble(&m); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_DOUBLE,1,8,&m)); +} +#endif + +static int +TIFFWriteDirectoryTagCheckedDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value) +{ + assert(count<0x20000000); + assert(sizeof(double)==8); + TIFFCvtNativeToIEEEDouble(tif,count,&value); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfDouble(value,count); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_DOUBLE,count,count*8,value)); +} + +static int +TIFFWriteDirectoryTagCheckedIfdArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value) +{ + assert(count<0x40000000); + assert(sizeof(uint32)==4); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong(value,count); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_IFD,count,count*4,value)); +} + +static int +TIFFWriteDirectoryTagCheckedIfd8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value) +{ + assert(count<0x20000000); + assert(sizeof(uint64)==8); + assert(tif->tif_flags&TIFF_BIGTIFF); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong8(value,count); + return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_IFD8,count,count*8,value)); +} + +static int +TIFFWriteDirectoryTagData(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint16 datatype, uint32 count, uint32 datalength, void* data) +{ + static const char module[] = "TIFFWriteDirectoryTagData"; + uint32 m; + m=0; + while (m<(*ndir)) + { + assert(dir[m].tdir_tag!=tag); + if (dir[m].tdir_tag>tag) + break; + m++; + } + if (m<(*ndir)) + { + uint32 n; + for (n=*ndir; n>m; n--) + dir[n]=dir[n-1]; + } + dir[m].tdir_tag=tag; + dir[m].tdir_type=datatype; + dir[m].tdir_count=count; + dir[m].tdir_offset.toff_long8 = 0; + if (datalength<=((tif->tif_flags&TIFF_BIGTIFF)?0x8U:0x4U)) + _TIFFmemcpy(&dir[m].tdir_offset,data,datalength); + else + { + uint64 na,nb; + na=tif->tif_dataoff; + nb=na+datalength; + if (!(tif->tif_flags&TIFF_BIGTIFF)) + nb=(uint32)nb; + if ((nbtif_clientdata,module,"Maximum TIFF file size exceeded"); + return(0); + } + if (!SeekOK(tif,na)) + { + TIFFErrorExt(tif->tif_clientdata,module,"IO error writing tag data"); + return(0); + } + assert(datalength<0x80000000UL); + if (!WriteOK(tif,data,(tmsize_t)datalength)) + { + TIFFErrorExt(tif->tif_clientdata,module,"IO error writing tag data"); + return(0); + } + tif->tif_dataoff=nb; + if (tif->tif_dataoff&1) + tif->tif_dataoff++; + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + uint32 o; + o=(uint32)na; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(&o); + _TIFFmemcpy(&dir[m].tdir_offset,&o,4); + } + else + { + dir[m].tdir_offset.toff_long8 = na; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8(&dir[m].tdir_offset.toff_long8); + } + } + (*ndir)++; + return(1); +} + +/* + * Link the current directory into the directory chain for the file. + */ +static int +TIFFLinkDirectory(TIFF* tif) +{ + static const char module[] = "TIFFLinkDirectory"; + + tif->tif_diroff = (TIFFSeekFile(tif,0,SEEK_END)+1) &~ 1; + + /* + * Handle SubIFDs + */ + if (tif->tif_flags & TIFF_INSUBIFD) + { + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + uint32 m; + m = (uint32)tif->tif_diroff; + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong(&m); + (void) TIFFSeekFile(tif, tif->tif_subifdoff, SEEK_SET); + if (!WriteOK(tif, &m, 4)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error writing SubIFD directory link"); + return (0); + } + /* + * Advance to the next SubIFD or, if this is + * the last one configured, revert back to the + * normal directory linkage. + */ + if (--tif->tif_nsubifd) + tif->tif_subifdoff += 4; + else + tif->tif_flags &= ~TIFF_INSUBIFD; + return (1); + } + else + { + uint64 m; + m = tif->tif_diroff; + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong8(&m); + (void) TIFFSeekFile(tif, tif->tif_subifdoff, SEEK_SET); + if (!WriteOK(tif, &m, 8)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error writing SubIFD directory link"); + return (0); + } + /* + * Advance to the next SubIFD or, if this is + * the last one configured, revert back to the + * normal directory linkage. + */ + if (--tif->tif_nsubifd) + tif->tif_subifdoff += 8; + else + tif->tif_flags &= ~TIFF_INSUBIFD; + return (1); + } + } + + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + uint32 m; + uint32 nextdir; + m = (uint32)(tif->tif_diroff); + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong(&m); + if (tif->tif_header.classic.tiff_diroff == 0) { + /* + * First directory, overwrite offset in header. + */ + tif->tif_header.classic.tiff_diroff = (uint32) tif->tif_diroff; + (void) TIFFSeekFile(tif,4, SEEK_SET); + if (!WriteOK(tif, &m, 4)) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "Error writing TIFF header"); + return (0); + } + return (1); + } + /* + * Not the first directory, search to the last and append. + */ + nextdir = tif->tif_header.classic.tiff_diroff; + while(1) { + uint16 dircount; + uint32 nextnextdir; + + if (!SeekOK(tif, nextdir) || + !ReadOK(tif, &dircount, 2)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error fetching directory count"); + return (0); + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabShort(&dircount); + (void) TIFFSeekFile(tif, + nextdir+2+dircount*12, SEEK_SET); + if (!ReadOK(tif, &nextnextdir, 4)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error fetching directory link"); + return (0); + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong(&nextnextdir); + if (nextnextdir==0) + { + (void) TIFFSeekFile(tif, + nextdir+2+dircount*12, SEEK_SET); + if (!WriteOK(tif, &m, 4)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error writing directory link"); + return (0); + } + break; + } + nextdir=nextnextdir; + } + } + else + { + uint64 m; + uint64 nextdir; + m = tif->tif_diroff; + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong8(&m); + if (tif->tif_header.big.tiff_diroff == 0) { + /* + * First directory, overwrite offset in header. + */ + tif->tif_header.big.tiff_diroff = tif->tif_diroff; + (void) TIFFSeekFile(tif,8, SEEK_SET); + if (!WriteOK(tif, &m, 8)) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "Error writing TIFF header"); + return (0); + } + return (1); + } + /* + * Not the first directory, search to the last and append. + */ + nextdir = tif->tif_header.big.tiff_diroff; + while(1) { + uint64 dircount64; + uint16 dircount; + uint64 nextnextdir; + + if (!SeekOK(tif, nextdir) || + !ReadOK(tif, &dircount64, 8)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error fetching directory count"); + return (0); + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong8(&dircount64); + if (dircount64>0xFFFF) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Sanity check on tag count failed, likely corrupt TIFF"); + return (0); + } + dircount=(uint16)dircount64; + (void) TIFFSeekFile(tif, + nextdir+8+dircount*20, SEEK_SET); + if (!ReadOK(tif, &nextnextdir, 8)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error fetching directory link"); + return (0); + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong8(&nextnextdir); + if (nextnextdir==0) + { + (void) TIFFSeekFile(tif, + nextdir+8+dircount*20, SEEK_SET); + if (!WriteOK(tif, &m, 8)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error writing directory link"); + return (0); + } + break; + } + nextdir=nextnextdir; + } + } + return (1); +} + +/************************************************************************/ +/* TIFFRewriteField() */ +/* */ +/* Rewrite a field in the directory on disk without regard to */ +/* updating the TIFF directory structure in memory. Currently */ +/* only supported for field that already exist in the on-disk */ +/* directory. Mainly used for updating stripoffset / */ +/* stripbytecount values after the directory is already on */ +/* disk. */ +/* */ +/* Returns zero on failure, and one on success. */ +/************************************************************************/ + +int +_TIFFRewriteField(TIFF* tif, uint16 tag, TIFFDataType in_datatype, + tmsize_t count, void* data) +{ + static const char module[] = "TIFFResetField"; + /* const TIFFField* fip = NULL; */ + uint16 dircount; + tmsize_t dirsize; + uint8 direntry_raw[20]; + uint16 entry_tag = 0; + uint16 entry_type = 0; + uint64 entry_count = 0; + uint64 entry_offset = 0; + int value_in_entry = 0; + uint64 read_offset; + uint8 *buf_to_write = NULL; + TIFFDataType datatype; + +/* -------------------------------------------------------------------- */ +/* Find field definition. */ +/* -------------------------------------------------------------------- */ + /*fip =*/ TIFFFindField(tif, tag, TIFF_ANY); + +/* -------------------------------------------------------------------- */ +/* Do some checking this is a straight forward case. */ +/* -------------------------------------------------------------------- */ + if( isMapped(tif) ) + { + TIFFErrorExt( tif->tif_clientdata, module, + "Memory mapped files not currently supported for this operation." ); + return 0; + } + + if( tif->tif_diroff == 0 ) + { + TIFFErrorExt( tif->tif_clientdata, module, + "Attempt to reset field on directory not already on disk." ); + return 0; + } + +/* -------------------------------------------------------------------- */ +/* Read the directory entry count. */ +/* -------------------------------------------------------------------- */ + if (!SeekOK(tif, tif->tif_diroff)) { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Seek error accessing TIFF directory", + tif->tif_name); + return 0; + } + + read_offset = tif->tif_diroff; + + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + if (!ReadOK(tif, &dircount, sizeof (uint16))) { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Can not read TIFF directory count", + tif->tif_name); + return 0; + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabShort(&dircount); + dirsize = 12; + read_offset += 2; + } else { + uint64 dircount64; + if (!ReadOK(tif, &dircount64, sizeof (uint64))) { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Can not read TIFF directory count", + tif->tif_name); + return 0; + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong8(&dircount64); + dircount = (uint16)dircount64; + dirsize = 20; + read_offset += 8; + } + +/* -------------------------------------------------------------------- */ +/* Read through directory to find target tag. */ +/* -------------------------------------------------------------------- */ + while( dircount > 0 ) + { + if (!ReadOK(tif, direntry_raw, dirsize)) { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Can not read TIFF directory entry.", + tif->tif_name); + return 0; + } + + memcpy( &entry_tag, direntry_raw + 0, sizeof(uint16) ); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabShort( &entry_tag ); + + if( entry_tag == tag ) + break; + + read_offset += dirsize; + } + + if( entry_tag != tag ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Could not find tag %d.", + tif->tif_name, tag ); + return 0; + } + +/* -------------------------------------------------------------------- */ +/* Extract the type, count and offset for this entry. */ +/* -------------------------------------------------------------------- */ + memcpy( &entry_type, direntry_raw + 2, sizeof(uint16) ); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabShort( &entry_type ); + + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + uint32 value; + + memcpy( &value, direntry_raw + 4, sizeof(uint32) ); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong( &value ); + entry_count = value; + + memcpy( &value, direntry_raw + 8, sizeof(uint32) ); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong( &value ); + entry_offset = value; + } + else + { + memcpy( &entry_count, direntry_raw + 4, sizeof(uint64) ); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8( &entry_count ); + + memcpy( &entry_offset, direntry_raw + 12, sizeof(uint64) ); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8( &entry_offset ); + } + +/* -------------------------------------------------------------------- */ +/* What data type do we want to write this as? */ +/* -------------------------------------------------------------------- */ + if( TIFFDataWidth(in_datatype) == 8 && !(tif->tif_flags&TIFF_BIGTIFF) ) + { + if( in_datatype == TIFF_LONG8 ) + datatype = TIFF_LONG; + else if( in_datatype == TIFF_SLONG8 ) + datatype = TIFF_SLONG; + else if( in_datatype == TIFF_IFD8 ) + datatype = TIFF_IFD; + else + datatype = in_datatype; + } + else + datatype = in_datatype; + +/* -------------------------------------------------------------------- */ +/* Prepare buffer of actual data to write. This includes */ +/* swabbing as needed. */ +/* -------------------------------------------------------------------- */ + buf_to_write = + (uint8 *)_TIFFCheckMalloc(tif, count, TIFFDataWidth(datatype), + "for field buffer."); + if (!buf_to_write) + return 0; + + if( datatype == in_datatype ) + memcpy( buf_to_write, data, count * TIFFDataWidth(datatype) ); + else if( datatype == TIFF_SLONG && in_datatype == TIFF_SLONG8 ) + { + tmsize_t i; + + for( i = 0; i < count; i++ ) + { + ((int32 *) buf_to_write)[i] = + (int32) ((int64 *) data)[i]; + if( (int64) ((int32 *) buf_to_write)[i] != ((int64 *) data)[i] ) + { + _TIFFfree( buf_to_write ); + TIFFErrorExt( tif->tif_clientdata, module, + "Value exceeds 32bit range of output type." ); + return 0; + } + } + } + else if( (datatype == TIFF_LONG && in_datatype == TIFF_LONG8) + || (datatype == TIFF_IFD && in_datatype == TIFF_IFD8) ) + { + tmsize_t i; + + for( i = 0; i < count; i++ ) + { + ((uint32 *) buf_to_write)[i] = + (uint32) ((uint64 *) data)[i]; + if( (uint64) ((uint32 *) buf_to_write)[i] != ((uint64 *) data)[i] ) + { + _TIFFfree( buf_to_write ); + TIFFErrorExt( tif->tif_clientdata, module, + "Value exceeds 32bit range of output type." ); + return 0; + } + } + } + + if( TIFFDataWidth(datatype) > 1 && (tif->tif_flags&TIFF_SWAB) ) + { + if( TIFFDataWidth(datatype) == 2 ) + TIFFSwabArrayOfShort( (uint16 *) buf_to_write, count ); + else if( TIFFDataWidth(datatype) == 4 ) + TIFFSwabArrayOfLong( (uint32 *) buf_to_write, count ); + else if( TIFFDataWidth(datatype) == 8 ) + TIFFSwabArrayOfLong8( (uint64 *) buf_to_write, count ); + } + +/* -------------------------------------------------------------------- */ +/* Is this a value that fits into the directory entry? */ +/* -------------------------------------------------------------------- */ + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + if( TIFFDataWidth(datatype) * count <= 4 ) + { + entry_offset = read_offset + 8; + value_in_entry = 1; + } + } + else + { + if( TIFFDataWidth(datatype) * count <= 8 ) + { + entry_offset = read_offset + 12; + value_in_entry = 1; + } + } + +/* -------------------------------------------------------------------- */ +/* If the tag type, and count match, then we just write it out */ +/* over the old values without altering the directory entry at */ +/* all. */ +/* -------------------------------------------------------------------- */ + if( entry_count == (uint64)count && entry_type == (uint16) datatype ) + { + if (!SeekOK(tif, entry_offset)) { + _TIFFfree( buf_to_write ); + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Seek error accessing TIFF directory", + tif->tif_name); + return 0; + } + if (!WriteOK(tif, buf_to_write, count*TIFFDataWidth(datatype))) { + _TIFFfree( buf_to_write ); + TIFFErrorExt(tif->tif_clientdata, module, + "Error writing directory link"); + return (0); + } + + _TIFFfree( buf_to_write ); + return 1; + } + +/* -------------------------------------------------------------------- */ +/* Otherwise, we write the new tag data at the end of the file. */ +/* -------------------------------------------------------------------- */ + if( !value_in_entry ) + { + entry_offset = TIFFSeekFile(tif,0,SEEK_END); + + if (!WriteOK(tif, buf_to_write, count*TIFFDataWidth(datatype))) { + _TIFFfree( buf_to_write ); + TIFFErrorExt(tif->tif_clientdata, module, + "Error writing directory link"); + return (0); + } + + _TIFFfree( buf_to_write ); + } + else + { + memcpy( &entry_offset, buf_to_write, count*TIFFDataWidth(datatype)); + } + +/* -------------------------------------------------------------------- */ +/* Adjust the directory entry. */ +/* -------------------------------------------------------------------- */ + entry_type = datatype; + memcpy( direntry_raw + 2, &entry_type, sizeof(uint16) ); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabShort( (uint16 *) (direntry_raw + 2) ); + + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + uint32 value; + + value = (uint32) entry_count; + memcpy( direntry_raw + 4, &value, sizeof(uint32) ); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong( (uint32 *) (direntry_raw + 4) ); + + value = (uint32) entry_offset; + memcpy( direntry_raw + 8, &value, sizeof(uint32) ); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong( (uint32 *) (direntry_raw + 8) ); + } + else + { + memcpy( direntry_raw + 4, &entry_count, sizeof(uint64) ); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8( (uint64 *) (direntry_raw + 4) ); + + memcpy( direntry_raw + 12, &entry_offset, sizeof(uint64) ); + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8( (uint64 *) (direntry_raw + 12) ); + } + +/* -------------------------------------------------------------------- */ +/* Write the directory entry out to disk. */ +/* -------------------------------------------------------------------- */ + if (!SeekOK(tif, read_offset )) { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Seek error accessing TIFF directory", + tif->tif_name); + return 0; + } + + if (!WriteOK(tif, direntry_raw,dirsize)) + { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Can not write TIFF directory entry.", + tif->tif_name); + return 0; + } + + return 1; +} +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_dumpmode.c b/Source/LibTIFF4/tif_dumpmode.c index 4cae954..23fba05 100644 --- a/Source/LibTIFF4/tif_dumpmode.c +++ b/Source/LibTIFF4/tif_dumpmode.c @@ -1,143 +1,143 @@ -/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF4/tif_dumpmode.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * - * "Null" Compression Algorithm Support. - */ -#include "tiffiop.h" - -static int -DumpFixupTags(TIFF* tif) -{ - (void) tif; - return (1); -} - -/* - * Encode a hunk of pixels. - */ -static int -DumpModeEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) -{ - (void) s; - while (cc > 0) { - tmsize_t n; - - n = cc; - if (tif->tif_rawcc + n > tif->tif_rawdatasize) - n = tif->tif_rawdatasize - tif->tif_rawcc; - - assert( n > 0 ); - - /* - * Avoid copy if client has setup raw - * data buffer to avoid extra copy. - */ - if (tif->tif_rawcp != pp) - _TIFFmemcpy(tif->tif_rawcp, pp, n); - tif->tif_rawcp += n; - tif->tif_rawcc += n; - pp += n; - cc -= n; - if (tif->tif_rawcc >= tif->tif_rawdatasize && - !TIFFFlushData1(tif)) - return (-1); - } - return (1); -} - -/* - * Decode a hunk of pixels. - */ -static int -DumpModeDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) -{ - static const char module[] = "DumpModeDecode"; - (void) s; - if (tif->tif_rawcc < cc) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, -"Not enough data for scanline %lu, expected a request for at most %I64d bytes, got a request for %I64d bytes", - (unsigned long) tif->tif_row, - (signed __int64) tif->tif_rawcc, - (signed __int64) cc); -#else - TIFFErrorExt(tif->tif_clientdata, module, -"Not enough data for scanline %lu, expected a request for at most %lld bytes, got a request for %lld bytes", - (unsigned long) tif->tif_row, - (signed long long) tif->tif_rawcc, - (signed long long) cc); -#endif - return (0); - } - /* - * Avoid copy if client has setup raw - * data buffer to avoid extra copy. - */ - if (tif->tif_rawcp != buf) - _TIFFmemcpy(buf, tif->tif_rawcp, cc); - tif->tif_rawcp += cc; - tif->tif_rawcc -= cc; - return (1); -} - -/* - * Seek forwards nrows in the current strip. - */ -static int -DumpModeSeek(TIFF* tif, uint32 nrows) -{ - tif->tif_rawcp += nrows * tif->tif_scanlinesize; - tif->tif_rawcc -= nrows * tif->tif_scanlinesize; - return (1); -} - -/* - * Initialize dump mode. - */ -int -TIFFInitDumpMode(TIFF* tif, int scheme) -{ - (void) scheme; - tif->tif_fixuptags = DumpFixupTags; - tif->tif_decoderow = DumpModeDecode; - tif->tif_decodestrip = DumpModeDecode; - tif->tif_decodetile = DumpModeDecode; - tif->tif_encoderow = DumpModeEncode; - tif->tif_encodestrip = DumpModeEncode; - tif->tif_encodetile = DumpModeEncode; - tif->tif_seek = DumpModeSeek; - return (1); -} -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF4/tif_dumpmode.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * + * "Null" Compression Algorithm Support. + */ +#include "tiffiop.h" + +static int +DumpFixupTags(TIFF* tif) +{ + (void) tif; + return (1); +} + +/* + * Encode a hunk of pixels. + */ +static int +DumpModeEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) +{ + (void) s; + while (cc > 0) { + tmsize_t n; + + n = cc; + if (tif->tif_rawcc + n > tif->tif_rawdatasize) + n = tif->tif_rawdatasize - tif->tif_rawcc; + + assert( n > 0 ); + + /* + * Avoid copy if client has setup raw + * data buffer to avoid extra copy. + */ + if (tif->tif_rawcp != pp) + _TIFFmemcpy(tif->tif_rawcp, pp, n); + tif->tif_rawcp += n; + tif->tif_rawcc += n; + pp += n; + cc -= n; + if (tif->tif_rawcc >= tif->tif_rawdatasize && + !TIFFFlushData1(tif)) + return (-1); + } + return (1); +} + +/* + * Decode a hunk of pixels. + */ +static int +DumpModeDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) +{ + static const char module[] = "DumpModeDecode"; + (void) s; + if (tif->tif_rawcc < cc) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, +"Not enough data for scanline %lu, expected a request for at most %I64d bytes, got a request for %I64d bytes", + (unsigned long) tif->tif_row, + (signed __int64) tif->tif_rawcc, + (signed __int64) cc); +#else + TIFFErrorExt(tif->tif_clientdata, module, +"Not enough data for scanline %lu, expected a request for at most %lld bytes, got a request for %lld bytes", + (unsigned long) tif->tif_row, + (signed long long) tif->tif_rawcc, + (signed long long) cc); +#endif + return (0); + } + /* + * Avoid copy if client has setup raw + * data buffer to avoid extra copy. + */ + if (tif->tif_rawcp != buf) + _TIFFmemcpy(buf, tif->tif_rawcp, cc); + tif->tif_rawcp += cc; + tif->tif_rawcc -= cc; + return (1); +} + +/* + * Seek forwards nrows in the current strip. + */ +static int +DumpModeSeek(TIFF* tif, uint32 nrows) +{ + tif->tif_rawcp += nrows * tif->tif_scanlinesize; + tif->tif_rawcc -= nrows * tif->tif_scanlinesize; + return (1); +} + +/* + * Initialize dump mode. + */ +int +TIFFInitDumpMode(TIFF* tif, int scheme) +{ + (void) scheme; + tif->tif_fixuptags = DumpFixupTags; + tif->tif_decoderow = DumpModeDecode; + tif->tif_decodestrip = DumpModeDecode; + tif->tif_decodetile = DumpModeDecode; + tif->tif_encoderow = DumpModeEncode; + tif->tif_encodestrip = DumpModeEncode; + tif->tif_encodetile = DumpModeEncode; + tif->tif_seek = DumpModeSeek; + return (1); +} +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_error.c b/Source/LibTIFF4/tif_error.c index c2fd071..2a83516 100644 --- a/Source/LibTIFF4/tif_error.c +++ b/Source/LibTIFF4/tif_error.c @@ -1,80 +1,80 @@ -/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF4/tif_error.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - */ -#include "tiffiop.h" - -TIFFErrorHandlerExt _TIFFerrorHandlerExt = NULL; - -TIFFErrorHandler -TIFFSetErrorHandler(TIFFErrorHandler handler) -{ - TIFFErrorHandler prev = _TIFFerrorHandler; - _TIFFerrorHandler = handler; - return (prev); -} - -TIFFErrorHandlerExt -TIFFSetErrorHandlerExt(TIFFErrorHandlerExt handler) -{ - TIFFErrorHandlerExt prev = _TIFFerrorHandlerExt; - _TIFFerrorHandlerExt = handler; - return (prev); -} - -void -TIFFError(const char* module, const char* fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - if (_TIFFerrorHandler) - (*_TIFFerrorHandler)(module, fmt, ap); - if (_TIFFerrorHandlerExt) - (*_TIFFerrorHandlerExt)(0, module, fmt, ap); - va_end(ap); -} - -void -TIFFErrorExt(thandle_t fd, const char* module, const char* fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - if (_TIFFerrorHandler) - (*_TIFFerrorHandler)(module, fmt, ap); - if (_TIFFerrorHandlerExt) - (*_TIFFerrorHandlerExt)(fd, module, fmt, ap); - va_end(ap); -} - -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF4/tif_error.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + */ +#include "tiffiop.h" + +TIFFErrorHandlerExt _TIFFerrorHandlerExt = NULL; + +TIFFErrorHandler +TIFFSetErrorHandler(TIFFErrorHandler handler) +{ + TIFFErrorHandler prev = _TIFFerrorHandler; + _TIFFerrorHandler = handler; + return (prev); +} + +TIFFErrorHandlerExt +TIFFSetErrorHandlerExt(TIFFErrorHandlerExt handler) +{ + TIFFErrorHandlerExt prev = _TIFFerrorHandlerExt; + _TIFFerrorHandlerExt = handler; + return (prev); +} + +void +TIFFError(const char* module, const char* fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + if (_TIFFerrorHandler) + (*_TIFFerrorHandler)(module, fmt, ap); + if (_TIFFerrorHandlerExt) + (*_TIFFerrorHandlerExt)(0, module, fmt, ap); + va_end(ap); +} + +void +TIFFErrorExt(thandle_t fd, const char* module, const char* fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + if (_TIFFerrorHandler) + (*_TIFFerrorHandler)(module, fmt, ap); + if (_TIFFerrorHandlerExt) + (*_TIFFerrorHandlerExt)(fd, module, fmt, ap); + va_end(ap); +} + +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_extension.c b/Source/LibTIFF4/tif_extension.c index c84ac2a..cd131ec 100644 --- a/Source/LibTIFF4/tif_extension.c +++ b/Source/LibTIFF4/tif_extension.c @@ -1,118 +1,118 @@ -/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF4/tif_extension.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * - * Various routines support external extension of the tag set, and other - * application extension capabilities. - */ - -#include "tiffiop.h" - -int TIFFGetTagListCount( TIFF *tif ) - -{ - TIFFDirectory* td = &tif->tif_dir; - - return td->td_customValueCount; -} - -uint32 TIFFGetTagListEntry( TIFF *tif, int tag_index ) - -{ - TIFFDirectory* td = &tif->tif_dir; - - if( tag_index < 0 || tag_index >= td->td_customValueCount ) - return (uint32)(-1); - else - return td->td_customValues[tag_index].info->field_tag; -} - -/* -** This provides read/write access to the TIFFTagMethods within the TIFF -** structure to application code without giving access to the private -** TIFF structure. -*/ -TIFFTagMethods *TIFFAccessTagMethods( TIFF *tif ) - -{ - return &(tif->tif_tagmethods); -} - -void *TIFFGetClientInfo( TIFF *tif, const char *name ) - -{ - TIFFClientInfoLink *link = tif->tif_clientinfo; - - while( link != NULL && strcmp(link->name,name) != 0 ) - link = link->next; - - if( link != NULL ) - return link->data; - else - return NULL; -} - -void TIFFSetClientInfo( TIFF *tif, void *data, const char *name ) - -{ - TIFFClientInfoLink *link = tif->tif_clientinfo; - - /* - ** Do we have an existing link with this name? If so, just - ** set it. - */ - while( link != NULL && strcmp(link->name,name) != 0 ) - link = link->next; - - if( link != NULL ) - { - link->data = data; - return; - } - - /* - ** Create a new link. - */ - - link = (TIFFClientInfoLink *) _TIFFmalloc(sizeof(TIFFClientInfoLink)); - assert (link != NULL); - link->next = tif->tif_clientinfo; - link->name = (char *) _TIFFmalloc((tmsize_t)(strlen(name)+1)); - assert (link->name != NULL); - strcpy(link->name, name); - link->data = data; - - tif->tif_clientinfo = link; -} -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF4/tif_extension.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * + * Various routines support external extension of the tag set, and other + * application extension capabilities. + */ + +#include "tiffiop.h" + +int TIFFGetTagListCount( TIFF *tif ) + +{ + TIFFDirectory* td = &tif->tif_dir; + + return td->td_customValueCount; +} + +uint32 TIFFGetTagListEntry( TIFF *tif, int tag_index ) + +{ + TIFFDirectory* td = &tif->tif_dir; + + if( tag_index < 0 || tag_index >= td->td_customValueCount ) + return (uint32)(-1); + else + return td->td_customValues[tag_index].info->field_tag; +} + +/* +** This provides read/write access to the TIFFTagMethods within the TIFF +** structure to application code without giving access to the private +** TIFF structure. +*/ +TIFFTagMethods *TIFFAccessTagMethods( TIFF *tif ) + +{ + return &(tif->tif_tagmethods); +} + +void *TIFFGetClientInfo( TIFF *tif, const char *name ) + +{ + TIFFClientInfoLink *link = tif->tif_clientinfo; + + while( link != NULL && strcmp(link->name,name) != 0 ) + link = link->next; + + if( link != NULL ) + return link->data; + else + return NULL; +} + +void TIFFSetClientInfo( TIFF *tif, void *data, const char *name ) + +{ + TIFFClientInfoLink *link = tif->tif_clientinfo; + + /* + ** Do we have an existing link with this name? If so, just + ** set it. + */ + while( link != NULL && strcmp(link->name,name) != 0 ) + link = link->next; + + if( link != NULL ) + { + link->data = data; + return; + } + + /* + ** Create a new link. + */ + + link = (TIFFClientInfoLink *) _TIFFmalloc(sizeof(TIFFClientInfoLink)); + assert (link != NULL); + link->next = tif->tif_clientinfo; + link->name = (char *) _TIFFmalloc((tmsize_t)(strlen(name)+1)); + assert (link->name != NULL); + strcpy(link->name, name); + link->data = data; + + tif->tif_clientinfo = link; +} +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_fax3.c b/Source/LibTIFF4/tif_fax3.c index 496b10f..1f6afb4 100644 --- a/Source/LibTIFF4/tif_fax3.c +++ b/Source/LibTIFF4/tif_fax3.c @@ -1,1595 +1,1595 @@ -/* $Id: tif_fax3.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1990-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "tiffiop.h" -#ifdef CCITT_SUPPORT -/* - * TIFF Library. - * - * CCITT Group 3 (T.4) and Group 4 (T.6) Compression Support. - * - * This file contains support for decoding and encoding TIFF - * compression algorithms 2, 3, 4, and 32771. - * - * Decoder support is derived, with permission, from the code - * in Frank Cringle's viewfax program; - * Copyright (C) 1990, 1995 Frank D. Cringle. - */ -#include "tif_fax3.h" -#define G3CODES -#include "t4.h" -#include - -/* - * Compression+decompression state blocks are - * derived from this ``base state'' block. - */ -typedef struct { - int rw_mode; /* O_RDONLY for decode, else encode */ - int mode; /* operating mode */ - tmsize_t rowbytes; /* bytes in a decoded scanline */ - uint32 rowpixels; /* pixels in a scanline */ - - uint16 cleanfaxdata; /* CleanFaxData tag */ - uint32 badfaxrun; /* BadFaxRun tag */ - uint32 badfaxlines; /* BadFaxLines tag */ - uint32 groupoptions; /* Group 3/4 options tag */ - - TIFFVGetMethod vgetparent; /* super-class method */ - TIFFVSetMethod vsetparent; /* super-class method */ - TIFFPrintMethod printdir; /* super-class method */ -} Fax3BaseState; -#define Fax3State(tif) ((Fax3BaseState*) (tif)->tif_data) - -typedef enum { G3_1D, G3_2D } Ttag; -typedef struct { - Fax3BaseState b; - - /* Decoder state info */ - const unsigned char* bitmap; /* bit reversal table */ - uint32 data; /* current i/o byte/word */ - int bit; /* current i/o bit in byte */ - int EOLcnt; /* count of EOL codes recognized */ - TIFFFaxFillFunc fill; /* fill routine */ - uint32* runs; /* b&w runs for current/previous row */ - uint32* refruns; /* runs for reference line */ - uint32* curruns; /* runs for current line */ - - /* Encoder state info */ - Ttag tag; /* encoding state */ - unsigned char* refline; /* reference line for 2d decoding */ - int k; /* #rows left that can be 2d encoded */ - int maxk; /* max #rows that can be 2d encoded */ - - int line; -} Fax3CodecState; -#define DecoderState(tif) ((Fax3CodecState*) Fax3State(tif)) -#define EncoderState(tif) ((Fax3CodecState*) Fax3State(tif)) - -#define is2DEncoding(sp) (sp->b.groupoptions & GROUP3OPT_2DENCODING) -#define isAligned(p,t) ((((size_t)(p)) & (sizeof (t)-1)) == 0) - -/* - * Group 3 and Group 4 Decoding. - */ - -/* - * These macros glue the TIFF library state to - * the state expected by Frank's decoder. - */ -#define DECLARE_STATE(tif, sp, mod) \ - static const char module[] = mod; \ - Fax3CodecState* sp = DecoderState(tif); \ - int a0; /* reference element */ \ - int lastx = sp->b.rowpixels; /* last element in row */ \ - uint32 BitAcc; /* bit accumulator */ \ - int BitsAvail; /* # valid bits in BitAcc */ \ - int RunLength; /* length of current run */ \ - unsigned char* cp; /* next byte of input data */ \ - unsigned char* ep; /* end of input data */ \ - uint32* pa; /* place to stuff next run */ \ - uint32* thisrun; /* current row's run array */ \ - int EOLcnt; /* # EOL codes recognized */ \ - const unsigned char* bitmap = sp->bitmap; /* input data bit reverser */ \ - const TIFFFaxTabEnt* TabEnt -#define DECLARE_STATE_2D(tif, sp, mod) \ - DECLARE_STATE(tif, sp, mod); \ - int b1; /* next change on prev line */ \ - uint32* pb /* next run in reference line */\ -/* - * Load any state that may be changed during decoding. - */ -#define CACHE_STATE(tif, sp) do { \ - BitAcc = sp->data; \ - BitsAvail = sp->bit; \ - EOLcnt = sp->EOLcnt; \ - cp = (unsigned char*) tif->tif_rawcp; \ - ep = cp + tif->tif_rawcc; \ -} while (0) -/* - * Save state possibly changed during decoding. - */ -#define UNCACHE_STATE(tif, sp) do { \ - sp->bit = BitsAvail; \ - sp->data = BitAcc; \ - sp->EOLcnt = EOLcnt; \ - tif->tif_rawcc -= (tmsize_t)((uint8*) cp - tif->tif_rawcp); \ - tif->tif_rawcp = (uint8*) cp; \ -} while (0) - -/* - * Setup state for decoding a strip. - */ -static int -Fax3PreDecode(TIFF* tif, uint16 s) -{ - Fax3CodecState* sp = DecoderState(tif); - - (void) s; - assert(sp != NULL); - sp->bit = 0; /* force initial read */ - sp->data = 0; - sp->EOLcnt = 0; /* force initial scan for EOL */ - /* - * Decoder assumes lsb-to-msb bit order. Note that we select - * this here rather than in Fax3SetupState so that viewers can - * hold the image open, fiddle with the FillOrder tag value, - * and then re-decode the image. Otherwise they'd need to close - * and open the image to get the state reset. - */ - sp->bitmap = - TIFFGetBitRevTable(tif->tif_dir.td_fillorder != FILLORDER_LSB2MSB); - if (sp->refruns) { /* init reference line to white */ - sp->refruns[0] = (uint32) sp->b.rowpixels; - sp->refruns[1] = 0; - } - sp->line = 0; - return (1); -} - -/* - * Routine for handling various errors/conditions. - * Note how they are "glued into the decoder" by - * overriding the definitions used by the decoder. - */ - -static void -Fax3Unexpected(const char* module, TIFF* tif, uint32 line, uint32 a0) -{ - TIFFErrorExt(tif->tif_clientdata, module, "Bad code word at line %u of %s %u (x %u)", - line, isTiled(tif) ? "tile" : "strip", - (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip), - a0); -} -#define unexpected(table, a0) Fax3Unexpected(module, tif, sp->line, a0) - -static void -Fax3Extension(const char* module, TIFF* tif, uint32 line, uint32 a0) -{ - TIFFErrorExt(tif->tif_clientdata, module, - "Uncompressed data (not supported) at line %u of %s %u (x %u)", - line, isTiled(tif) ? "tile" : "strip", - (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip), - a0); -} -#define extension(a0) Fax3Extension(module, tif, sp->line, a0) - -static void -Fax3BadLength(const char* module, TIFF* tif, uint32 line, uint32 a0, uint32 lastx) -{ - TIFFWarningExt(tif->tif_clientdata, module, "%s at line %u of %s %u (got %u, expected %u)", - a0 < lastx ? "Premature EOL" : "Line length mismatch", - line, isTiled(tif) ? "tile" : "strip", - (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip), - a0, lastx); -} -#define badlength(a0,lastx) Fax3BadLength(module, tif, sp->line, a0, lastx) - -static void -Fax3PrematureEOF(const char* module, TIFF* tif, uint32 line, uint32 a0) -{ - TIFFWarningExt(tif->tif_clientdata, module, "Premature EOF at line %u of %s %u (x %u)", - line, isTiled(tif) ? "tile" : "strip", - (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip), - a0); -} -#define prematureEOF(a0) Fax3PrematureEOF(module, tif, sp->line, a0) - -#define Nop - -/* - * Decode the requested amount of G3 1D-encoded data. - */ -static int -Fax3Decode1D(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) -{ - DECLARE_STATE(tif, sp, "Fax3Decode1D"); - (void) s; - if (occ % sp->b.rowbytes) - { - TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read"); - return (-1); - } - CACHE_STATE(tif, sp); - thisrun = sp->curruns; - while (occ > 0) { - a0 = 0; - RunLength = 0; - pa = thisrun; -#ifdef FAX3_DEBUG - printf("\nBitAcc=%08X, BitsAvail = %d\n", BitAcc, BitsAvail); - printf("-------------------- %d\n", tif->tif_row); - fflush(stdout); -#endif - SYNC_EOL(EOF1D); - EXPAND1D(EOF1Da); - (*sp->fill)(buf, thisrun, pa, lastx); - buf += sp->b.rowbytes; - occ -= sp->b.rowbytes; - sp->line++; - continue; - EOF1D: /* premature EOF */ - CLEANUP_RUNS(); - EOF1Da: /* premature EOF */ - (*sp->fill)(buf, thisrun, pa, lastx); - UNCACHE_STATE(tif, sp); - return (-1); - } - UNCACHE_STATE(tif, sp); - return (1); -} - -#define SWAP(t,a,b) { t x; x = (a); (a) = (b); (b) = x; } -/* - * Decode the requested amount of G3 2D-encoded data. - */ -static int -Fax3Decode2D(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) -{ - DECLARE_STATE_2D(tif, sp, "Fax3Decode2D"); - int is1D; /* current line is 1d/2d-encoded */ - (void) s; - if (occ % sp->b.rowbytes) - { - TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read"); - return (-1); - } - CACHE_STATE(tif, sp); - while (occ > 0) { - a0 = 0; - RunLength = 0; - pa = thisrun = sp->curruns; -#ifdef FAX3_DEBUG - printf("\nBitAcc=%08X, BitsAvail = %d EOLcnt = %d", - BitAcc, BitsAvail, EOLcnt); -#endif - SYNC_EOL(EOF2D); - NeedBits8(1, EOF2D); - is1D = GetBits(1); /* 1D/2D-encoding tag bit */ - ClrBits(1); -#ifdef FAX3_DEBUG - printf(" %s\n-------------------- %d\n", - is1D ? "1D" : "2D", tif->tif_row); - fflush(stdout); -#endif - pb = sp->refruns; - b1 = *pb++; - if (is1D) - EXPAND1D(EOF2Da); - else - EXPAND2D(EOF2Da); - (*sp->fill)(buf, thisrun, pa, lastx); - SETVALUE(0); /* imaginary change for reference */ - SWAP(uint32*, sp->curruns, sp->refruns); - buf += sp->b.rowbytes; - occ -= sp->b.rowbytes; - sp->line++; - continue; - EOF2D: /* premature EOF */ - CLEANUP_RUNS(); - EOF2Da: /* premature EOF */ - (*sp->fill)(buf, thisrun, pa, lastx); - UNCACHE_STATE(tif, sp); - return (-1); - } - UNCACHE_STATE(tif, sp); - return (1); -} -#undef SWAP - -/* - * The ZERO & FILL macros must handle spans < 2*sizeof(long) bytes. - * For machines with 64-bit longs this is <16 bytes; otherwise - * this is <8 bytes. We optimize the code here to reflect the - * machine characteristics. - */ -#if SIZEOF_UNSIGNED_LONG == 8 -# define FILL(n, cp) \ - switch (n) { \ - case 15:(cp)[14] = 0xff; case 14:(cp)[13] = 0xff; case 13: (cp)[12] = 0xff;\ - case 12:(cp)[11] = 0xff; case 11:(cp)[10] = 0xff; case 10: (cp)[9] = 0xff;\ - case 9: (cp)[8] = 0xff; case 8: (cp)[7] = 0xff; case 7: (cp)[6] = 0xff;\ - case 6: (cp)[5] = 0xff; case 5: (cp)[4] = 0xff; case 4: (cp)[3] = 0xff;\ - case 3: (cp)[2] = 0xff; case 2: (cp)[1] = 0xff; \ - case 1: (cp)[0] = 0xff; (cp) += (n); case 0: ; \ - } -# define ZERO(n, cp) \ - switch (n) { \ - case 15:(cp)[14] = 0; case 14:(cp)[13] = 0; case 13: (cp)[12] = 0; \ - case 12:(cp)[11] = 0; case 11:(cp)[10] = 0; case 10: (cp)[9] = 0; \ - case 9: (cp)[8] = 0; case 8: (cp)[7] = 0; case 7: (cp)[6] = 0; \ - case 6: (cp)[5] = 0; case 5: (cp)[4] = 0; case 4: (cp)[3] = 0; \ - case 3: (cp)[2] = 0; case 2: (cp)[1] = 0; \ - case 1: (cp)[0] = 0; (cp) += (n); case 0: ; \ - } -#else -# define FILL(n, cp) \ - switch (n) { \ - case 7: (cp)[6] = 0xff; case 6: (cp)[5] = 0xff; case 5: (cp)[4] = 0xff; \ - case 4: (cp)[3] = 0xff; case 3: (cp)[2] = 0xff; case 2: (cp)[1] = 0xff; \ - case 1: (cp)[0] = 0xff; (cp) += (n); case 0: ; \ - } -# define ZERO(n, cp) \ - switch (n) { \ - case 7: (cp)[6] = 0; case 6: (cp)[5] = 0; case 5: (cp)[4] = 0; \ - case 4: (cp)[3] = 0; case 3: (cp)[2] = 0; case 2: (cp)[1] = 0; \ - case 1: (cp)[0] = 0; (cp) += (n); case 0: ; \ - } -#endif - -/* - * Bit-fill a row according to the white/black - * runs generated during G3/G4 decoding. - */ -void -_TIFFFax3fillruns(unsigned char* buf, uint32* runs, uint32* erun, uint32 lastx) -{ - static const unsigned char _fillmasks[] = - { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff }; - unsigned char* cp; - uint32 x, bx, run; - int32 n, nw; - long* lp; - - if ((erun-runs)&1) - *erun++ = 0; - x = 0; - for (; runs < erun; runs += 2) { - run = runs[0]; - if (x+run > lastx || run > lastx ) - run = runs[0] = (uint32) (lastx - x); - if (run) { - cp = buf + (x>>3); - bx = x&7; - if (run > 8-bx) { - if (bx) { /* align to byte boundary */ - *cp++ &= 0xff << (8-bx); - run -= 8-bx; - } - if( (n = run >> 3) != 0 ) { /* multiple bytes to fill */ - if ((n/sizeof (long)) > 1) { - /* - * Align to longword boundary and fill. - */ - for (; n && !isAligned(cp, long); n--) - *cp++ = 0x00; - lp = (long*) cp; - nw = (int32)(n / sizeof (long)); - n -= nw * sizeof (long); - do { - *lp++ = 0L; - } while (--nw); - cp = (unsigned char*) lp; - } - ZERO(n, cp); - run &= 7; - } - if (run) - cp[0] &= 0xff >> run; - } else - cp[0] &= ~(_fillmasks[run]>>bx); - x += runs[0]; - } - run = runs[1]; - if (x+run > lastx || run > lastx ) - run = runs[1] = lastx - x; - if (run) { - cp = buf + (x>>3); - bx = x&7; - if (run > 8-bx) { - if (bx) { /* align to byte boundary */ - *cp++ |= 0xff >> bx; - run -= 8-bx; - } - if( (n = run>>3) != 0 ) { /* multiple bytes to fill */ - if ((n/sizeof (long)) > 1) { - /* - * Align to longword boundary and fill. - */ - for (; n && !isAligned(cp, long); n--) - *cp++ = 0xff; - lp = (long*) cp; - nw = (int32)(n / sizeof (long)); - n -= nw * sizeof (long); - do { - *lp++ = -1L; - } while (--nw); - cp = (unsigned char*) lp; - } - FILL(n, cp); - run &= 7; - } - if (run) - cp[0] |= 0xff00 >> run; - } else - cp[0] |= _fillmasks[run]>>bx; - x += runs[1]; - } - } - assert(x == lastx); -} -#undef ZERO -#undef FILL - -static int -Fax3FixupTags(TIFF* tif) -{ - (void) tif; - return (1); -} - -/* - * Setup G3/G4-related compression/decompression state - * before data is processed. This routine is called once - * per image -- it sets up different state based on whether - * or not decoding or encoding is being done and whether - * 1D- or 2D-encoded data is involved. - */ -static int -Fax3SetupState(TIFF* tif) -{ - static const char module[] = "Fax3SetupState"; - TIFFDirectory* td = &tif->tif_dir; - Fax3BaseState* sp = Fax3State(tif); - int needsRefLine; - Fax3CodecState* dsp = (Fax3CodecState*) Fax3State(tif); - tmsize_t rowbytes; - uint32 rowpixels, nruns; - - if (td->td_bitspersample != 1) { - TIFFErrorExt(tif->tif_clientdata, module, - "Bits/sample must be 1 for Group 3/4 encoding/decoding"); - return (0); - } - /* - * Calculate the scanline/tile widths. - */ - if (isTiled(tif)) { - rowbytes = TIFFTileRowSize(tif); - rowpixels = td->td_tilewidth; - } else { - rowbytes = TIFFScanlineSize(tif); - rowpixels = td->td_imagewidth; - } - sp->rowbytes = rowbytes; - sp->rowpixels = rowpixels; - /* - * Allocate any additional space required for decoding/encoding. - */ - needsRefLine = ( - (sp->groupoptions & GROUP3OPT_2DENCODING) || - td->td_compression == COMPRESSION_CCITTFAX4 - ); - - /* - Assure that allocation computations do not overflow. - - TIFFroundup and TIFFSafeMultiply return zero on integer overflow - */ - dsp->runs=(uint32*) NULL; - nruns = TIFFroundup_32(rowpixels,32); - if (needsRefLine) { - nruns = TIFFSafeMultiply(uint32,nruns,2); - } - if ((nruns == 0) || (TIFFSafeMultiply(uint32,nruns,2) == 0)) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "Row pixels integer overflow (rowpixels %u)", - rowpixels); - return (0); - } - dsp->runs = (uint32*) _TIFFCheckMalloc(tif, - TIFFSafeMultiply(uint32,nruns,2), - sizeof (uint32), - "for Group 3/4 run arrays"); - if (dsp->runs == NULL) - return (0); - memset( dsp->runs, 0, TIFFSafeMultiply(uint32,nruns,2)*sizeof(uint32)); - dsp->curruns = dsp->runs; - if (needsRefLine) - dsp->refruns = dsp->runs + nruns; - else - dsp->refruns = NULL; - if (td->td_compression == COMPRESSION_CCITTFAX3 - && is2DEncoding(dsp)) { /* NB: default is 1D routine */ - tif->tif_decoderow = Fax3Decode2D; - tif->tif_decodestrip = Fax3Decode2D; - tif->tif_decodetile = Fax3Decode2D; - } - - if (needsRefLine) { /* 2d encoding */ - Fax3CodecState* esp = EncoderState(tif); - /* - * 2d encoding requires a scanline - * buffer for the ``reference line''; the - * scanline against which delta encoding - * is referenced. The reference line must - * be initialized to be ``white'' (done elsewhere). - */ - esp->refline = (unsigned char*) _TIFFmalloc(rowbytes); - if (esp->refline == NULL) { - TIFFErrorExt(tif->tif_clientdata, module, - "No space for Group 3/4 reference line"); - return (0); - } - } else /* 1d encoding */ - EncoderState(tif)->refline = NULL; - - return (1); -} - -/* - * CCITT Group 3 FAX Encoding. - */ - -#define Fax3FlushBits(tif, sp) { \ - if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize) \ - (void) TIFFFlushData1(tif); \ - *(tif)->tif_rawcp++ = (uint8) (sp)->data; \ - (tif)->tif_rawcc++; \ - (sp)->data = 0, (sp)->bit = 8; \ -} -#define _FlushBits(tif) { \ - if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize) \ - (void) TIFFFlushData1(tif); \ - *(tif)->tif_rawcp++ = (uint8) data; \ - (tif)->tif_rawcc++; \ - data = 0, bit = 8; \ -} -static const int _msbmask[9] = - { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff }; -#define _PutBits(tif, bits, length) { \ - while (length > bit) { \ - data |= bits >> (length - bit); \ - length -= bit; \ - _FlushBits(tif); \ - } \ - assert( length < 9 ); \ - data |= (bits & _msbmask[length]) << (bit - length); \ - bit -= length; \ - if (bit == 0) \ - _FlushBits(tif); \ -} - -/* - * Write a variable-length bit-value to - * the output stream. Values are - * assumed to be at most 16 bits. - */ -static void -Fax3PutBits(TIFF* tif, unsigned int bits, unsigned int length) -{ - Fax3CodecState* sp = EncoderState(tif); - unsigned int bit = sp->bit; - int data = sp->data; - - _PutBits(tif, bits, length); - - sp->data = data; - sp->bit = bit; -} - -/* - * Write a code to the output stream. - */ -#define putcode(tif, te) Fax3PutBits(tif, (te)->code, (te)->length) - -#ifdef FAX3_DEBUG -#define DEBUG_COLOR(w) (tab == TIFFFaxWhiteCodes ? w "W" : w "B") -#define DEBUG_PRINT(what,len) { \ - int t; \ - printf("%08X/%-2d: %s%5d\t", data, bit, DEBUG_COLOR(what), len); \ - for (t = length-1; t >= 0; t--) \ - putchar(code & (1<bit; - int data = sp->data; - unsigned int code, length; - - while (span >= 2624) { - const tableentry* te = &tab[63 + (2560>>6)]; - code = te->code, length = te->length; -#ifdef FAX3_DEBUG - DEBUG_PRINT("MakeUp", te->runlen); -#endif - _PutBits(tif, code, length); - span -= te->runlen; - } - if (span >= 64) { - const tableentry* te = &tab[63 + (span>>6)]; - assert(te->runlen == 64*(span>>6)); - code = te->code, length = te->length; -#ifdef FAX3_DEBUG - DEBUG_PRINT("MakeUp", te->runlen); -#endif - _PutBits(tif, code, length); - span -= te->runlen; - } - code = tab[span].code, length = tab[span].length; -#ifdef FAX3_DEBUG - DEBUG_PRINT(" Term", tab[span].runlen); -#endif - _PutBits(tif, code, length); - - sp->data = data; - sp->bit = bit; -} - -/* - * Write an EOL code to the output stream. The zero-fill - * logic for byte-aligning encoded scanlines is handled - * here. We also handle writing the tag bit for the next - * scanline when doing 2d encoding. - */ -static void -Fax3PutEOL(TIFF* tif) -{ - Fax3CodecState* sp = EncoderState(tif); - unsigned int bit = sp->bit; - int data = sp->data; - unsigned int code, length, tparm; - - if (sp->b.groupoptions & GROUP3OPT_FILLBITS) { - /* - * Force bit alignment so EOL will terminate on - * a byte boundary. That is, force the bit alignment - * to 16-12 = 4 before putting out the EOL code. - */ - int align = 8 - 4; - if (align != sp->bit) { - if (align > sp->bit) - align = sp->bit + (8 - align); - else - align = sp->bit - align; - code = 0; - tparm=align; - _PutBits(tif, 0, tparm); - } - } - code = EOL, length = 12; - if (is2DEncoding(sp)) - code = (code<<1) | (sp->tag == G3_1D), length++; - _PutBits(tif, code, length); - - sp->data = data; - sp->bit = bit; -} - -/* - * Reset encoding state at the start of a strip. - */ -static int -Fax3PreEncode(TIFF* tif, uint16 s) -{ - Fax3CodecState* sp = EncoderState(tif); - - (void) s; - assert(sp != NULL); - sp->bit = 8; - sp->data = 0; - sp->tag = G3_1D; - /* - * This is necessary for Group 4; otherwise it isn't - * needed because the first scanline of each strip ends - * up being copied into the refline. - */ - if (sp->refline) - _TIFFmemset(sp->refline, 0x00, sp->b.rowbytes); - if (is2DEncoding(sp)) { - float res = tif->tif_dir.td_yresolution; - /* - * The CCITT spec says that when doing 2d encoding, you - * should only do it on K consecutive scanlines, where K - * depends on the resolution of the image being encoded - * (2 for <= 200 lpi, 4 for > 200 lpi). Since the directory - * code initializes td_yresolution to 0, this code will - * select a K of 2 unless the YResolution tag is set - * appropriately. (Note also that we fudge a little here - * and use 150 lpi to avoid problems with units conversion.) - */ - if (tif->tif_dir.td_resolutionunit == RESUNIT_CENTIMETER) - res *= 2.54f; /* convert to inches */ - sp->maxk = (res > 150 ? 4 : 2); - sp->k = sp->maxk-1; - } else - sp->k = sp->maxk = 0; - sp->line = 0; - return (1); -} - -static const unsigned char zeroruns[256] = { - 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, /* 0x00 - 0x0f */ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 0x10 - 0x1f */ - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x20 - 0x2f */ - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x30 - 0x3f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 - 0x4f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x50 - 0x5f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60 - 0x6f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x70 - 0x7f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 - 0x8f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 - 0x9f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xa0 - 0xaf */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xb0 - 0xbf */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xc0 - 0xcf */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xd0 - 0xdf */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xe0 - 0xef */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xf0 - 0xff */ -}; -static const unsigned char oneruns[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 - 0x0f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 - 0x1f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 - 0x2f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x30 - 0x3f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x40 - 0x4f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 - 0x5f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x6f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x7f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x80 - 0x8f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x90 - 0x9f */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xa0 - 0xaf */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xb0 - 0xbf */ - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0xc0 - 0xcf */ - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0xd0 - 0xdf */ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 0xe0 - 0xef */ - 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 8, /* 0xf0 - 0xff */ -}; - -/* - * On certain systems it pays to inline - * the routines that find pixel spans. - */ -#ifdef VAXC -static int32 find0span(unsigned char*, int32, int32); -static int32 find1span(unsigned char*, int32, int32); -#pragma inline(find0span,find1span) -#endif - -/* - * Find a span of ones or zeros using the supplied - * table. The ``base'' of the bit string is supplied - * along with the start+end bit indices. - */ -inline static int32 -find0span(unsigned char* bp, int32 bs, int32 be) -{ - int32 bits = be - bs; - int32 n, span; - - bp += bs>>3; - /* - * Check partial byte on lhs. - */ - if (bits > 0 && (n = (bs & 7))) { - span = zeroruns[(*bp << n) & 0xff]; - if (span > 8-n) /* table value too generous */ - span = 8-n; - if (span > bits) /* constrain span to bit range */ - span = bits; - if (n+span < 8) /* doesn't extend to edge of byte */ - return (span); - bits -= span; - bp++; - } else - span = 0; - if (bits >= (int32)(2 * 8 * sizeof(long))) { - long* lp; - /* - * Align to longword boundary and check longwords. - */ - while (!isAligned(bp, long)) { - if (*bp != 0x00) - return (span + zeroruns[*bp]); - span += 8, bits -= 8; - bp++; - } - lp = (long*) bp; - while ((bits >= (int32)(8 * sizeof(long))) && (0 == *lp)) { - span += 8*sizeof (long), bits -= 8*sizeof (long); - lp++; - } - bp = (unsigned char*) lp; - } - /* - * Scan full bytes for all 0's. - */ - while (bits >= 8) { - if (*bp != 0x00) /* end of run */ - return (span + zeroruns[*bp]); - span += 8, bits -= 8; - bp++; - } - /* - * Check partial byte on rhs. - */ - if (bits > 0) { - n = zeroruns[*bp]; - span += (n > bits ? bits : n); - } - return (span); -} - -inline static int32 -find1span(unsigned char* bp, int32 bs, int32 be) -{ - int32 bits = be - bs; - int32 n, span; - - bp += bs>>3; - /* - * Check partial byte on lhs. - */ - if (bits > 0 && (n = (bs & 7))) { - span = oneruns[(*bp << n) & 0xff]; - if (span > 8-n) /* table value too generous */ - span = 8-n; - if (span > bits) /* constrain span to bit range */ - span = bits; - if (n+span < 8) /* doesn't extend to edge of byte */ - return (span); - bits -= span; - bp++; - } else - span = 0; - if (bits >= (int32)(2 * 8 * sizeof(long))) { - long* lp; - /* - * Align to longword boundary and check longwords. - */ - while (!isAligned(bp, long)) { - if (*bp != 0xff) - return (span + oneruns[*bp]); - span += 8, bits -= 8; - bp++; - } - lp = (long*) bp; - while ((bits >= (int32)(8 * sizeof(long))) && (~0 == *lp)) { - span += 8*sizeof (long), bits -= 8*sizeof (long); - lp++; - } - bp = (unsigned char*) lp; - } - /* - * Scan full bytes for all 1's. - */ - while (bits >= 8) { - if (*bp != 0xff) /* end of run */ - return (span + oneruns[*bp]); - span += 8, bits -= 8; - bp++; - } - /* - * Check partial byte on rhs. - */ - if (bits > 0) { - n = oneruns[*bp]; - span += (n > bits ? bits : n); - } - return (span); -} - -/* - * Return the offset of the next bit in the range - * [bs..be] that is different from the specified - * color. The end, be, is returned if no such bit - * exists. - */ -#define finddiff(_cp, _bs, _be, _color) \ - (_bs + (_color ? find1span(_cp,_bs,_be) : find0span(_cp,_bs,_be))) -/* - * Like finddiff, but also check the starting bit - * against the end in case start > end. - */ -#define finddiff2(_cp, _bs, _be, _color) \ - (_bs < _be ? finddiff(_cp,_bs,_be,_color) : _be) - -/* - * 1d-encode a row of pixels. The encoding is - * a sequence of all-white or all-black spans - * of pixels encoded with Huffman codes. - */ -static int -Fax3Encode1DRow(TIFF* tif, unsigned char* bp, uint32 bits) -{ - Fax3CodecState* sp = EncoderState(tif); - int32 span; - uint32 bs = 0; - - for (;;) { - span = find0span(bp, bs, bits); /* white span */ - putspan(tif, span, TIFFFaxWhiteCodes); - bs += span; - if (bs >= bits) - break; - span = find1span(bp, bs, bits); /* black span */ - putspan(tif, span, TIFFFaxBlackCodes); - bs += span; - if (bs >= bits) - break; - } - if (sp->b.mode & (FAXMODE_BYTEALIGN|FAXMODE_WORDALIGN)) { - if (sp->bit != 8) /* byte-align */ - Fax3FlushBits(tif, sp); - if ((sp->b.mode&FAXMODE_WORDALIGN) && - !isAligned(tif->tif_rawcp, uint16)) - Fax3FlushBits(tif, sp); - } - return (1); -} - -static const tableentry horizcode = - { 3, 0x1, 0 }; /* 001 */ -static const tableentry passcode = - { 4, 0x1, 0 }; /* 0001 */ -static const tableentry vcodes[7] = { - { 7, 0x03, 0 }, /* 0000 011 */ - { 6, 0x03, 0 }, /* 0000 11 */ - { 3, 0x03, 0 }, /* 011 */ - { 1, 0x1, 0 }, /* 1 */ - { 3, 0x2, 0 }, /* 010 */ - { 6, 0x02, 0 }, /* 0000 10 */ - { 7, 0x02, 0 } /* 0000 010 */ -}; - -/* - * 2d-encode a row of pixels. Consult the CCITT - * documentation for the algorithm. - */ -static int -Fax3Encode2DRow(TIFF* tif, unsigned char* bp, unsigned char* rp, uint32 bits) -{ -#define PIXEL(buf,ix) ((((buf)[(ix)>>3]) >> (7-((ix)&7))) & 1) - uint32 a0 = 0; - uint32 a1 = (PIXEL(bp, 0) != 0 ? 0 : finddiff(bp, 0, bits, 0)); - uint32 b1 = (PIXEL(rp, 0) != 0 ? 0 : finddiff(rp, 0, bits, 0)); - uint32 a2, b2; - - for (;;) { - b2 = finddiff2(rp, b1, bits, PIXEL(rp,b1)); - if (b2 >= a1) { - int32 d = b1 - a1; - if (!(-3 <= d && d <= 3)) { /* horizontal mode */ - a2 = finddiff2(bp, a1, bits, PIXEL(bp,a1)); - putcode(tif, &horizcode); - if (a0+a1 == 0 || PIXEL(bp, a0) == 0) { - putspan(tif, a1-a0, TIFFFaxWhiteCodes); - putspan(tif, a2-a1, TIFFFaxBlackCodes); - } else { - putspan(tif, a1-a0, TIFFFaxBlackCodes); - putspan(tif, a2-a1, TIFFFaxWhiteCodes); - } - a0 = a2; - } else { /* vertical mode */ - putcode(tif, &vcodes[d+3]); - a0 = a1; - } - } else { /* pass mode */ - putcode(tif, &passcode); - a0 = b2; - } - if (a0 >= bits) - break; - a1 = finddiff(bp, a0, bits, PIXEL(bp,a0)); - b1 = finddiff(rp, a0, bits, !PIXEL(bp,a0)); - b1 = finddiff(rp, b1, bits, PIXEL(bp,a0)); - } - return (1); -#undef PIXEL -} - -/* - * Encode a buffer of pixels. - */ -static int -Fax3Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - static const char module[] = "Fax3Encode"; - Fax3CodecState* sp = EncoderState(tif); - (void) s; - if (cc % sp->b.rowbytes) - { - TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be written"); - return (0); - } - while (cc > 0) { - if ((sp->b.mode & FAXMODE_NOEOL) == 0) - Fax3PutEOL(tif); - if (is2DEncoding(sp)) { - if (sp->tag == G3_1D) { - if (!Fax3Encode1DRow(tif, bp, sp->b.rowpixels)) - return (0); - sp->tag = G3_2D; - } else { - if (!Fax3Encode2DRow(tif, bp, sp->refline, - sp->b.rowpixels)) - return (0); - sp->k--; - } - if (sp->k == 0) { - sp->tag = G3_1D; - sp->k = sp->maxk-1; - } else - _TIFFmemcpy(sp->refline, bp, sp->b.rowbytes); - } else { - if (!Fax3Encode1DRow(tif, bp, sp->b.rowpixels)) - return (0); - } - bp += sp->b.rowbytes; - cc -= sp->b.rowbytes; - } - return (1); -} - -static int -Fax3PostEncode(TIFF* tif) -{ - Fax3CodecState* sp = EncoderState(tif); - - if (sp->bit != 8) - Fax3FlushBits(tif, sp); - return (1); -} - -static void -Fax3Close(TIFF* tif) -{ - if ((Fax3State(tif)->mode & FAXMODE_NORTC) == 0) { - Fax3CodecState* sp = EncoderState(tif); - unsigned int code = EOL; - unsigned int length = 12; - int i; - - if (is2DEncoding(sp)) - code = (code<<1) | (sp->tag == G3_1D), length++; - for (i = 0; i < 6; i++) - Fax3PutBits(tif, code, length); - Fax3FlushBits(tif, sp); - } -} - -static void -Fax3Cleanup(TIFF* tif) -{ - Fax3CodecState* sp = DecoderState(tif); - - assert(sp != 0); - - tif->tif_tagmethods.vgetfield = sp->b.vgetparent; - tif->tif_tagmethods.vsetfield = sp->b.vsetparent; - tif->tif_tagmethods.printdir = sp->b.printdir; - - if (sp->runs) - _TIFFfree(sp->runs); - if (sp->refline) - _TIFFfree(sp->refline); - - _TIFFfree(tif->tif_data); - tif->tif_data = NULL; - - _TIFFSetDefaultCompressionState(tif); -} - -#define FIELD_BADFAXLINES (FIELD_CODEC+0) -#define FIELD_CLEANFAXDATA (FIELD_CODEC+1) -#define FIELD_BADFAXRUN (FIELD_CODEC+2) - -#define FIELD_OPTIONS (FIELD_CODEC+7) - -static const TIFFField faxFields[] = { - { TIFFTAG_FAXMODE, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "FaxMode", NULL }, - { TIFFTAG_FAXFILLFUNC, 0, 0, TIFF_ANY, 0, TIFF_SETGET_OTHER, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "FaxFillFunc", NULL }, - { TIFFTAG_BADFAXLINES, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_BADFAXLINES, TRUE, FALSE, "BadFaxLines", NULL }, - { TIFFTAG_CLEANFAXDATA, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UINT16, FIELD_CLEANFAXDATA, TRUE, FALSE, "CleanFaxData", NULL }, - { TIFFTAG_CONSECUTIVEBADFAXLINES, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_BADFAXRUN, TRUE, FALSE, "ConsecutiveBadFaxLines", NULL }}; -static const TIFFField fax3Fields[] = { - { TIFFTAG_GROUP3OPTIONS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_OPTIONS, FALSE, FALSE, "Group3Options", NULL }, -}; -static const TIFFField fax4Fields[] = { - { TIFFTAG_GROUP4OPTIONS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_OPTIONS, FALSE, FALSE, "Group4Options", NULL }, -}; - -static int -Fax3VSetField(TIFF* tif, uint32 tag, va_list ap) -{ - Fax3BaseState* sp = Fax3State(tif); - const TIFFField* fip; - - assert(sp != 0); - assert(sp->vsetparent != 0); - - switch (tag) { - case TIFFTAG_FAXMODE: - sp->mode = (int) va_arg(ap, int); - return 1; /* NB: pseudo tag */ - case TIFFTAG_FAXFILLFUNC: - DecoderState(tif)->fill = va_arg(ap, TIFFFaxFillFunc); - return 1; /* NB: pseudo tag */ - case TIFFTAG_GROUP3OPTIONS: - /* XXX: avoid reading options if compression mismatches. */ - if (tif->tif_dir.td_compression == COMPRESSION_CCITTFAX3) - sp->groupoptions = (uint32) va_arg(ap, uint32); - break; - case TIFFTAG_GROUP4OPTIONS: - /* XXX: avoid reading options if compression mismatches. */ - if (tif->tif_dir.td_compression == COMPRESSION_CCITTFAX4) - sp->groupoptions = (uint32) va_arg(ap, uint32); - break; - case TIFFTAG_BADFAXLINES: - sp->badfaxlines = (uint32) va_arg(ap, uint32); - break; - case TIFFTAG_CLEANFAXDATA: - sp->cleanfaxdata = (uint16) va_arg(ap, uint16_vap); - break; - case TIFFTAG_CONSECUTIVEBADFAXLINES: - sp->badfaxrun = (uint32) va_arg(ap, uint32); - break; - default: - return (*sp->vsetparent)(tif, tag, ap); - } - - if ((fip = TIFFFieldWithTag(tif, tag))) - TIFFSetFieldBit(tif, fip->field_bit); - else - return 0; - - tif->tif_flags |= TIFF_DIRTYDIRECT; - return 1; -} - -static int -Fax3VGetField(TIFF* tif, uint32 tag, va_list ap) -{ - Fax3BaseState* sp = Fax3State(tif); - - assert(sp != 0); - - switch (tag) { - case TIFFTAG_FAXMODE: - *va_arg(ap, int*) = sp->mode; - break; - case TIFFTAG_FAXFILLFUNC: - *va_arg(ap, TIFFFaxFillFunc*) = DecoderState(tif)->fill; - break; - case TIFFTAG_GROUP3OPTIONS: - case TIFFTAG_GROUP4OPTIONS: - *va_arg(ap, uint32*) = sp->groupoptions; - break; - case TIFFTAG_BADFAXLINES: - *va_arg(ap, uint32*) = sp->badfaxlines; - break; - case TIFFTAG_CLEANFAXDATA: - *va_arg(ap, uint16*) = sp->cleanfaxdata; - break; - case TIFFTAG_CONSECUTIVEBADFAXLINES: - *va_arg(ap, uint32*) = sp->badfaxrun; - break; - default: - return (*sp->vgetparent)(tif, tag, ap); - } - return (1); -} - -static void -Fax3PrintDir(TIFF* tif, FILE* fd, long flags) -{ - Fax3BaseState* sp = Fax3State(tif); - - assert(sp != 0); - - (void) flags; - if (TIFFFieldSet(tif,FIELD_OPTIONS)) { - const char* sep = " "; - if (tif->tif_dir.td_compression == COMPRESSION_CCITTFAX4) { - fprintf(fd, " Group 4 Options:"); - if (sp->groupoptions & GROUP4OPT_UNCOMPRESSED) - fprintf(fd, "%suncompressed data", sep); - } else { - - fprintf(fd, " Group 3 Options:"); - if (sp->groupoptions & GROUP3OPT_2DENCODING) - fprintf(fd, "%s2-d encoding", sep), sep = "+"; - if (sp->groupoptions & GROUP3OPT_FILLBITS) - fprintf(fd, "%sEOL padding", sep), sep = "+"; - if (sp->groupoptions & GROUP3OPT_UNCOMPRESSED) - fprintf(fd, "%suncompressed data", sep); - } - fprintf(fd, " (%lu = 0x%lx)\n", - (unsigned long) sp->groupoptions, - (unsigned long) sp->groupoptions); - } - if (TIFFFieldSet(tif,FIELD_CLEANFAXDATA)) { - fprintf(fd, " Fax Data:"); - switch (sp->cleanfaxdata) { - case CLEANFAXDATA_CLEAN: - fprintf(fd, " clean"); - break; - case CLEANFAXDATA_REGENERATED: - fprintf(fd, " receiver regenerated"); - break; - case CLEANFAXDATA_UNCLEAN: - fprintf(fd, " uncorrected errors"); - break; - } - fprintf(fd, " (%u = 0x%x)\n", - sp->cleanfaxdata, sp->cleanfaxdata); - } - if (TIFFFieldSet(tif,FIELD_BADFAXLINES)) - fprintf(fd, " Bad Fax Lines: %lu\n", - (unsigned long) sp->badfaxlines); - if (TIFFFieldSet(tif,FIELD_BADFAXRUN)) - fprintf(fd, " Consecutive Bad Fax Lines: %lu\n", - (unsigned long) sp->badfaxrun); - if (sp->printdir) - (*sp->printdir)(tif, fd, flags); -} - -static int -InitCCITTFax3(TIFF* tif) -{ - static const char module[] = "InitCCITTFax3"; - Fax3BaseState* sp; - - /* - * Merge codec-specific tag information. - */ - if (!_TIFFMergeFields(tif, faxFields, TIFFArrayCount(faxFields))) { - TIFFErrorExt(tif->tif_clientdata, "InitCCITTFax3", - "Merging common CCITT Fax codec-specific tags failed"); - return 0; - } - - /* - * Allocate state block so tag methods have storage to record values. - */ - tif->tif_data = (uint8*) - _TIFFmalloc(sizeof (Fax3CodecState)); - - if (tif->tif_data == NULL) { - TIFFErrorExt(tif->tif_clientdata, module, - "No space for state block"); - return (0); - } - - sp = Fax3State(tif); - sp->rw_mode = tif->tif_mode; - - /* - * Override parent get/set field methods. - */ - sp->vgetparent = tif->tif_tagmethods.vgetfield; - tif->tif_tagmethods.vgetfield = Fax3VGetField; /* hook for codec tags */ - sp->vsetparent = tif->tif_tagmethods.vsetfield; - tif->tif_tagmethods.vsetfield = Fax3VSetField; /* hook for codec tags */ - sp->printdir = tif->tif_tagmethods.printdir; - tif->tif_tagmethods.printdir = Fax3PrintDir; /* hook for codec tags */ - sp->groupoptions = 0; - - if (sp->rw_mode == O_RDONLY) /* FIXME: improve for in place update */ - tif->tif_flags |= TIFF_NOBITREV; /* decoder does bit reversal */ - DecoderState(tif)->runs = NULL; - TIFFSetField(tif, TIFFTAG_FAXFILLFUNC, _TIFFFax3fillruns); - EncoderState(tif)->refline = NULL; - - /* - * Install codec methods. - */ - tif->tif_fixuptags = Fax3FixupTags; - tif->tif_setupdecode = Fax3SetupState; - tif->tif_predecode = Fax3PreDecode; - tif->tif_decoderow = Fax3Decode1D; - tif->tif_decodestrip = Fax3Decode1D; - tif->tif_decodetile = Fax3Decode1D; - tif->tif_setupencode = Fax3SetupState; - tif->tif_preencode = Fax3PreEncode; - tif->tif_postencode = Fax3PostEncode; - tif->tif_encoderow = Fax3Encode; - tif->tif_encodestrip = Fax3Encode; - tif->tif_encodetile = Fax3Encode; - tif->tif_close = Fax3Close; - tif->tif_cleanup = Fax3Cleanup; - - return (1); -} - -int -TIFFInitCCITTFax3(TIFF* tif, int scheme) -{ - (void) scheme; - if (InitCCITTFax3(tif)) { - /* - * Merge codec-specific tag information. - */ - if (!_TIFFMergeFields(tif, fax3Fields, - TIFFArrayCount(fax3Fields))) { - TIFFErrorExt(tif->tif_clientdata, "TIFFInitCCITTFax3", - "Merging CCITT Fax 3 codec-specific tags failed"); - return 0; - } - - /* - * The default format is Class/F-style w/o RTC. - */ - return TIFFSetField(tif, TIFFTAG_FAXMODE, FAXMODE_CLASSF); - } else - return 01; -} - -/* - * CCITT Group 4 (T.6) Facsimile-compatible - * Compression Scheme Support. - */ - -#define SWAP(t,a,b) { t x; x = (a); (a) = (b); (b) = x; } -/* - * Decode the requested amount of G4-encoded data. - */ -static int -Fax4Decode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) -{ - DECLARE_STATE_2D(tif, sp, "Fax4Decode"); - (void) s; - if (occ % sp->b.rowbytes) - { - TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read"); - return (-1); - } - CACHE_STATE(tif, sp); - while (occ > 0) { - a0 = 0; - RunLength = 0; - pa = thisrun = sp->curruns; - pb = sp->refruns; - b1 = *pb++; -#ifdef FAX3_DEBUG - printf("\nBitAcc=%08X, BitsAvail = %d\n", BitAcc, BitsAvail); - printf("-------------------- %d\n", tif->tif_row); - fflush(stdout); -#endif - EXPAND2D(EOFG4); - if (EOLcnt) - goto EOFG4; - (*sp->fill)(buf, thisrun, pa, lastx); - SETVALUE(0); /* imaginary change for reference */ - SWAP(uint32*, sp->curruns, sp->refruns); - buf += sp->b.rowbytes; - occ -= sp->b.rowbytes; - sp->line++; - continue; - EOFG4: - NeedBits16( 13, BADG4 ); - BADG4: -#ifdef FAX3_DEBUG - if( GetBits(13) != 0x1001 ) - fputs( "Bad EOFB\n", stderr ); -#endif - ClrBits( 13 ); - (*sp->fill)(buf, thisrun, pa, lastx); - UNCACHE_STATE(tif, sp); - return ( sp->line ? 1 : -1); /* don't error on badly-terminated strips */ - } - UNCACHE_STATE(tif, sp); - return (1); -} -#undef SWAP - -/* - * Encode the requested amount of data. - */ -static int -Fax4Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - static const char module[] = "Fax4Encode"; - Fax3CodecState *sp = EncoderState(tif); - (void) s; - if (cc % sp->b.rowbytes) - { - TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be written"); - return (0); - } - while (cc > 0) { - if (!Fax3Encode2DRow(tif, bp, sp->refline, sp->b.rowpixels)) - return (0); - _TIFFmemcpy(sp->refline, bp, sp->b.rowbytes); - bp += sp->b.rowbytes; - cc -= sp->b.rowbytes; - } - return (1); -} - -static int -Fax4PostEncode(TIFF* tif) -{ - Fax3CodecState *sp = EncoderState(tif); - - /* terminate strip w/ EOFB */ - Fax3PutBits(tif, EOL, 12); - Fax3PutBits(tif, EOL, 12); - if (sp->bit != 8) - Fax3FlushBits(tif, sp); - return (1); -} - -int -TIFFInitCCITTFax4(TIFF* tif, int scheme) -{ - (void) scheme; - if (InitCCITTFax3(tif)) { /* reuse G3 support */ - /* - * Merge codec-specific tag information. - */ - if (!_TIFFMergeFields(tif, fax4Fields, - TIFFArrayCount(fax4Fields))) { - TIFFErrorExt(tif->tif_clientdata, "TIFFInitCCITTFax4", - "Merging CCITT Fax 4 codec-specific tags failed"); - return 0; - } - - tif->tif_decoderow = Fax4Decode; - tif->tif_decodestrip = Fax4Decode; - tif->tif_decodetile = Fax4Decode; - tif->tif_encoderow = Fax4Encode; - tif->tif_encodestrip = Fax4Encode; - tif->tif_encodetile = Fax4Encode; - tif->tif_postencode = Fax4PostEncode; - /* - * Suppress RTC at the end of each strip. - */ - return TIFFSetField(tif, TIFFTAG_FAXMODE, FAXMODE_NORTC); - } else - return (0); -} - -/* - * CCITT Group 3 1-D Modified Huffman RLE Compression Support. - * (Compression algorithms 2 and 32771) - */ - -/* - * Decode the requested amount of RLE-encoded data. - */ -static int -Fax3DecodeRLE(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) -{ - DECLARE_STATE(tif, sp, "Fax3DecodeRLE"); - int mode = sp->b.mode; - (void) s; - if (occ % sp->b.rowbytes) - { - TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read"); - return (-1); - } - CACHE_STATE(tif, sp); - thisrun = sp->curruns; - while (occ > 0) { - a0 = 0; - RunLength = 0; - pa = thisrun; -#ifdef FAX3_DEBUG - printf("\nBitAcc=%08X, BitsAvail = %d\n", BitAcc, BitsAvail); - printf("-------------------- %d\n", tif->tif_row); - fflush(stdout); -#endif - EXPAND1D(EOFRLE); - (*sp->fill)(buf, thisrun, pa, lastx); - /* - * Cleanup at the end of the row. - */ - if (mode & FAXMODE_BYTEALIGN) { - int n = BitsAvail - (BitsAvail &~ 7); - ClrBits(n); - } else if (mode & FAXMODE_WORDALIGN) { - int n = BitsAvail - (BitsAvail &~ 15); - ClrBits(n); - if (BitsAvail == 0 && !isAligned(cp, uint16)) - cp++; - } - buf += sp->b.rowbytes; - occ -= sp->b.rowbytes; - sp->line++; - continue; - EOFRLE: /* premature EOF */ - (*sp->fill)(buf, thisrun, pa, lastx); - UNCACHE_STATE(tif, sp); - return (-1); - } - UNCACHE_STATE(tif, sp); - return (1); -} - -int -TIFFInitCCITTRLE(TIFF* tif, int scheme) -{ - (void) scheme; - if (InitCCITTFax3(tif)) { /* reuse G3 support */ - tif->tif_decoderow = Fax3DecodeRLE; - tif->tif_decodestrip = Fax3DecodeRLE; - tif->tif_decodetile = Fax3DecodeRLE; - /* - * Suppress RTC+EOLs when encoding and byte-align data. - */ - return TIFFSetField(tif, TIFFTAG_FAXMODE, - FAXMODE_NORTC|FAXMODE_NOEOL|FAXMODE_BYTEALIGN); - } else - return (0); -} - -int -TIFFInitCCITTRLEW(TIFF* tif, int scheme) -{ - (void) scheme; - if (InitCCITTFax3(tif)) { /* reuse G3 support */ - tif->tif_decoderow = Fax3DecodeRLE; - tif->tif_decodestrip = Fax3DecodeRLE; - tif->tif_decodetile = Fax3DecodeRLE; - /* - * Suppress RTC+EOLs when encoding and word-align data. - */ - return TIFFSetField(tif, TIFFTAG_FAXMODE, - FAXMODE_NORTC|FAXMODE_NOEOL|FAXMODE_WORDALIGN); - } else - return (0); -} -#endif /* CCITT_SUPPORT */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_fax3.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1990-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include "tiffiop.h" +#ifdef CCITT_SUPPORT +/* + * TIFF Library. + * + * CCITT Group 3 (T.4) and Group 4 (T.6) Compression Support. + * + * This file contains support for decoding and encoding TIFF + * compression algorithms 2, 3, 4, and 32771. + * + * Decoder support is derived, with permission, from the code + * in Frank Cringle's viewfax program; + * Copyright (C) 1990, 1995 Frank D. Cringle. + */ +#include "tif_fax3.h" +#define G3CODES +#include "t4.h" +#include + +/* + * Compression+decompression state blocks are + * derived from this ``base state'' block. + */ +typedef struct { + int rw_mode; /* O_RDONLY for decode, else encode */ + int mode; /* operating mode */ + tmsize_t rowbytes; /* bytes in a decoded scanline */ + uint32 rowpixels; /* pixels in a scanline */ + + uint16 cleanfaxdata; /* CleanFaxData tag */ + uint32 badfaxrun; /* BadFaxRun tag */ + uint32 badfaxlines; /* BadFaxLines tag */ + uint32 groupoptions; /* Group 3/4 options tag */ + + TIFFVGetMethod vgetparent; /* super-class method */ + TIFFVSetMethod vsetparent; /* super-class method */ + TIFFPrintMethod printdir; /* super-class method */ +} Fax3BaseState; +#define Fax3State(tif) ((Fax3BaseState*) (tif)->tif_data) + +typedef enum { G3_1D, G3_2D } Ttag; +typedef struct { + Fax3BaseState b; + + /* Decoder state info */ + const unsigned char* bitmap; /* bit reversal table */ + uint32 data; /* current i/o byte/word */ + int bit; /* current i/o bit in byte */ + int EOLcnt; /* count of EOL codes recognized */ + TIFFFaxFillFunc fill; /* fill routine */ + uint32* runs; /* b&w runs for current/previous row */ + uint32* refruns; /* runs for reference line */ + uint32* curruns; /* runs for current line */ + + /* Encoder state info */ + Ttag tag; /* encoding state */ + unsigned char* refline; /* reference line for 2d decoding */ + int k; /* #rows left that can be 2d encoded */ + int maxk; /* max #rows that can be 2d encoded */ + + int line; +} Fax3CodecState; +#define DecoderState(tif) ((Fax3CodecState*) Fax3State(tif)) +#define EncoderState(tif) ((Fax3CodecState*) Fax3State(tif)) + +#define is2DEncoding(sp) (sp->b.groupoptions & GROUP3OPT_2DENCODING) +#define isAligned(p,t) ((((size_t)(p)) & (sizeof (t)-1)) == 0) + +/* + * Group 3 and Group 4 Decoding. + */ + +/* + * These macros glue the TIFF library state to + * the state expected by Frank's decoder. + */ +#define DECLARE_STATE(tif, sp, mod) \ + static const char module[] = mod; \ + Fax3CodecState* sp = DecoderState(tif); \ + int a0; /* reference element */ \ + int lastx = sp->b.rowpixels; /* last element in row */ \ + uint32 BitAcc; /* bit accumulator */ \ + int BitsAvail; /* # valid bits in BitAcc */ \ + int RunLength; /* length of current run */ \ + unsigned char* cp; /* next byte of input data */ \ + unsigned char* ep; /* end of input data */ \ + uint32* pa; /* place to stuff next run */ \ + uint32* thisrun; /* current row's run array */ \ + int EOLcnt; /* # EOL codes recognized */ \ + const unsigned char* bitmap = sp->bitmap; /* input data bit reverser */ \ + const TIFFFaxTabEnt* TabEnt +#define DECLARE_STATE_2D(tif, sp, mod) \ + DECLARE_STATE(tif, sp, mod); \ + int b1; /* next change on prev line */ \ + uint32* pb /* next run in reference line */\ +/* + * Load any state that may be changed during decoding. + */ +#define CACHE_STATE(tif, sp) do { \ + BitAcc = sp->data; \ + BitsAvail = sp->bit; \ + EOLcnt = sp->EOLcnt; \ + cp = (unsigned char*) tif->tif_rawcp; \ + ep = cp + tif->tif_rawcc; \ +} while (0) +/* + * Save state possibly changed during decoding. + */ +#define UNCACHE_STATE(tif, sp) do { \ + sp->bit = BitsAvail; \ + sp->data = BitAcc; \ + sp->EOLcnt = EOLcnt; \ + tif->tif_rawcc -= (tmsize_t)((uint8*) cp - tif->tif_rawcp); \ + tif->tif_rawcp = (uint8*) cp; \ +} while (0) + +/* + * Setup state for decoding a strip. + */ +static int +Fax3PreDecode(TIFF* tif, uint16 s) +{ + Fax3CodecState* sp = DecoderState(tif); + + (void) s; + assert(sp != NULL); + sp->bit = 0; /* force initial read */ + sp->data = 0; + sp->EOLcnt = 0; /* force initial scan for EOL */ + /* + * Decoder assumes lsb-to-msb bit order. Note that we select + * this here rather than in Fax3SetupState so that viewers can + * hold the image open, fiddle with the FillOrder tag value, + * and then re-decode the image. Otherwise they'd need to close + * and open the image to get the state reset. + */ + sp->bitmap = + TIFFGetBitRevTable(tif->tif_dir.td_fillorder != FILLORDER_LSB2MSB); + if (sp->refruns) { /* init reference line to white */ + sp->refruns[0] = (uint32) sp->b.rowpixels; + sp->refruns[1] = 0; + } + sp->line = 0; + return (1); +} + +/* + * Routine for handling various errors/conditions. + * Note how they are "glued into the decoder" by + * overriding the definitions used by the decoder. + */ + +static void +Fax3Unexpected(const char* module, TIFF* tif, uint32 line, uint32 a0) +{ + TIFFErrorExt(tif->tif_clientdata, module, "Bad code word at line %u of %s %u (x %u)", + line, isTiled(tif) ? "tile" : "strip", + (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip), + a0); +} +#define unexpected(table, a0) Fax3Unexpected(module, tif, sp->line, a0) + +static void +Fax3Extension(const char* module, TIFF* tif, uint32 line, uint32 a0) +{ + TIFFErrorExt(tif->tif_clientdata, module, + "Uncompressed data (not supported) at line %u of %s %u (x %u)", + line, isTiled(tif) ? "tile" : "strip", + (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip), + a0); +} +#define extension(a0) Fax3Extension(module, tif, sp->line, a0) + +static void +Fax3BadLength(const char* module, TIFF* tif, uint32 line, uint32 a0, uint32 lastx) +{ + TIFFWarningExt(tif->tif_clientdata, module, "%s at line %u of %s %u (got %u, expected %u)", + a0 < lastx ? "Premature EOL" : "Line length mismatch", + line, isTiled(tif) ? "tile" : "strip", + (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip), + a0, lastx); +} +#define badlength(a0,lastx) Fax3BadLength(module, tif, sp->line, a0, lastx) + +static void +Fax3PrematureEOF(const char* module, TIFF* tif, uint32 line, uint32 a0) +{ + TIFFWarningExt(tif->tif_clientdata, module, "Premature EOF at line %u of %s %u (x %u)", + line, isTiled(tif) ? "tile" : "strip", + (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip), + a0); +} +#define prematureEOF(a0) Fax3PrematureEOF(module, tif, sp->line, a0) + +#define Nop + +/* + * Decode the requested amount of G3 1D-encoded data. + */ +static int +Fax3Decode1D(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) +{ + DECLARE_STATE(tif, sp, "Fax3Decode1D"); + (void) s; + if (occ % sp->b.rowbytes) + { + TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read"); + return (-1); + } + CACHE_STATE(tif, sp); + thisrun = sp->curruns; + while (occ > 0) { + a0 = 0; + RunLength = 0; + pa = thisrun; +#ifdef FAX3_DEBUG + printf("\nBitAcc=%08X, BitsAvail = %d\n", BitAcc, BitsAvail); + printf("-------------------- %d\n", tif->tif_row); + fflush(stdout); +#endif + SYNC_EOL(EOF1D); + EXPAND1D(EOF1Da); + (*sp->fill)(buf, thisrun, pa, lastx); + buf += sp->b.rowbytes; + occ -= sp->b.rowbytes; + sp->line++; + continue; + EOF1D: /* premature EOF */ + CLEANUP_RUNS(); + EOF1Da: /* premature EOF */ + (*sp->fill)(buf, thisrun, pa, lastx); + UNCACHE_STATE(tif, sp); + return (-1); + } + UNCACHE_STATE(tif, sp); + return (1); +} + +#define SWAP(t,a,b) { t x; x = (a); (a) = (b); (b) = x; } +/* + * Decode the requested amount of G3 2D-encoded data. + */ +static int +Fax3Decode2D(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) +{ + DECLARE_STATE_2D(tif, sp, "Fax3Decode2D"); + int is1D; /* current line is 1d/2d-encoded */ + (void) s; + if (occ % sp->b.rowbytes) + { + TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read"); + return (-1); + } + CACHE_STATE(tif, sp); + while (occ > 0) { + a0 = 0; + RunLength = 0; + pa = thisrun = sp->curruns; +#ifdef FAX3_DEBUG + printf("\nBitAcc=%08X, BitsAvail = %d EOLcnt = %d", + BitAcc, BitsAvail, EOLcnt); +#endif + SYNC_EOL(EOF2D); + NeedBits8(1, EOF2D); + is1D = GetBits(1); /* 1D/2D-encoding tag bit */ + ClrBits(1); +#ifdef FAX3_DEBUG + printf(" %s\n-------------------- %d\n", + is1D ? "1D" : "2D", tif->tif_row); + fflush(stdout); +#endif + pb = sp->refruns; + b1 = *pb++; + if (is1D) + EXPAND1D(EOF2Da); + else + EXPAND2D(EOF2Da); + (*sp->fill)(buf, thisrun, pa, lastx); + SETVALUE(0); /* imaginary change for reference */ + SWAP(uint32*, sp->curruns, sp->refruns); + buf += sp->b.rowbytes; + occ -= sp->b.rowbytes; + sp->line++; + continue; + EOF2D: /* premature EOF */ + CLEANUP_RUNS(); + EOF2Da: /* premature EOF */ + (*sp->fill)(buf, thisrun, pa, lastx); + UNCACHE_STATE(tif, sp); + return (-1); + } + UNCACHE_STATE(tif, sp); + return (1); +} +#undef SWAP + +/* + * The ZERO & FILL macros must handle spans < 2*sizeof(long) bytes. + * For machines with 64-bit longs this is <16 bytes; otherwise + * this is <8 bytes. We optimize the code here to reflect the + * machine characteristics. + */ +#if SIZEOF_UNSIGNED_LONG == 8 +# define FILL(n, cp) \ + switch (n) { \ + case 15:(cp)[14] = 0xff; case 14:(cp)[13] = 0xff; case 13: (cp)[12] = 0xff;\ + case 12:(cp)[11] = 0xff; case 11:(cp)[10] = 0xff; case 10: (cp)[9] = 0xff;\ + case 9: (cp)[8] = 0xff; case 8: (cp)[7] = 0xff; case 7: (cp)[6] = 0xff;\ + case 6: (cp)[5] = 0xff; case 5: (cp)[4] = 0xff; case 4: (cp)[3] = 0xff;\ + case 3: (cp)[2] = 0xff; case 2: (cp)[1] = 0xff; \ + case 1: (cp)[0] = 0xff; (cp) += (n); case 0: ; \ + } +# define ZERO(n, cp) \ + switch (n) { \ + case 15:(cp)[14] = 0; case 14:(cp)[13] = 0; case 13: (cp)[12] = 0; \ + case 12:(cp)[11] = 0; case 11:(cp)[10] = 0; case 10: (cp)[9] = 0; \ + case 9: (cp)[8] = 0; case 8: (cp)[7] = 0; case 7: (cp)[6] = 0; \ + case 6: (cp)[5] = 0; case 5: (cp)[4] = 0; case 4: (cp)[3] = 0; \ + case 3: (cp)[2] = 0; case 2: (cp)[1] = 0; \ + case 1: (cp)[0] = 0; (cp) += (n); case 0: ; \ + } +#else +# define FILL(n, cp) \ + switch (n) { \ + case 7: (cp)[6] = 0xff; case 6: (cp)[5] = 0xff; case 5: (cp)[4] = 0xff; \ + case 4: (cp)[3] = 0xff; case 3: (cp)[2] = 0xff; case 2: (cp)[1] = 0xff; \ + case 1: (cp)[0] = 0xff; (cp) += (n); case 0: ; \ + } +# define ZERO(n, cp) \ + switch (n) { \ + case 7: (cp)[6] = 0; case 6: (cp)[5] = 0; case 5: (cp)[4] = 0; \ + case 4: (cp)[3] = 0; case 3: (cp)[2] = 0; case 2: (cp)[1] = 0; \ + case 1: (cp)[0] = 0; (cp) += (n); case 0: ; \ + } +#endif + +/* + * Bit-fill a row according to the white/black + * runs generated during G3/G4 decoding. + */ +void +_TIFFFax3fillruns(unsigned char* buf, uint32* runs, uint32* erun, uint32 lastx) +{ + static const unsigned char _fillmasks[] = + { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff }; + unsigned char* cp; + uint32 x, bx, run; + int32 n, nw; + long* lp; + + if ((erun-runs)&1) + *erun++ = 0; + x = 0; + for (; runs < erun; runs += 2) { + run = runs[0]; + if (x+run > lastx || run > lastx ) + run = runs[0] = (uint32) (lastx - x); + if (run) { + cp = buf + (x>>3); + bx = x&7; + if (run > 8-bx) { + if (bx) { /* align to byte boundary */ + *cp++ &= 0xff << (8-bx); + run -= 8-bx; + } + if( (n = run >> 3) != 0 ) { /* multiple bytes to fill */ + if ((n/sizeof (long)) > 1) { + /* + * Align to longword boundary and fill. + */ + for (; n && !isAligned(cp, long); n--) + *cp++ = 0x00; + lp = (long*) cp; + nw = (int32)(n / sizeof (long)); + n -= nw * sizeof (long); + do { + *lp++ = 0L; + } while (--nw); + cp = (unsigned char*) lp; + } + ZERO(n, cp); + run &= 7; + } + if (run) + cp[0] &= 0xff >> run; + } else + cp[0] &= ~(_fillmasks[run]>>bx); + x += runs[0]; + } + run = runs[1]; + if (x+run > lastx || run > lastx ) + run = runs[1] = lastx - x; + if (run) { + cp = buf + (x>>3); + bx = x&7; + if (run > 8-bx) { + if (bx) { /* align to byte boundary */ + *cp++ |= 0xff >> bx; + run -= 8-bx; + } + if( (n = run>>3) != 0 ) { /* multiple bytes to fill */ + if ((n/sizeof (long)) > 1) { + /* + * Align to longword boundary and fill. + */ + for (; n && !isAligned(cp, long); n--) + *cp++ = 0xff; + lp = (long*) cp; + nw = (int32)(n / sizeof (long)); + n -= nw * sizeof (long); + do { + *lp++ = -1L; + } while (--nw); + cp = (unsigned char*) lp; + } + FILL(n, cp); + run &= 7; + } + if (run) + cp[0] |= 0xff00 >> run; + } else + cp[0] |= _fillmasks[run]>>bx; + x += runs[1]; + } + } + assert(x == lastx); +} +#undef ZERO +#undef FILL + +static int +Fax3FixupTags(TIFF* tif) +{ + (void) tif; + return (1); +} + +/* + * Setup G3/G4-related compression/decompression state + * before data is processed. This routine is called once + * per image -- it sets up different state based on whether + * or not decoding or encoding is being done and whether + * 1D- or 2D-encoded data is involved. + */ +static int +Fax3SetupState(TIFF* tif) +{ + static const char module[] = "Fax3SetupState"; + TIFFDirectory* td = &tif->tif_dir; + Fax3BaseState* sp = Fax3State(tif); + int needsRefLine; + Fax3CodecState* dsp = (Fax3CodecState*) Fax3State(tif); + tmsize_t rowbytes; + uint32 rowpixels, nruns; + + if (td->td_bitspersample != 1) { + TIFFErrorExt(tif->tif_clientdata, module, + "Bits/sample must be 1 for Group 3/4 encoding/decoding"); + return (0); + } + /* + * Calculate the scanline/tile widths. + */ + if (isTiled(tif)) { + rowbytes = TIFFTileRowSize(tif); + rowpixels = td->td_tilewidth; + } else { + rowbytes = TIFFScanlineSize(tif); + rowpixels = td->td_imagewidth; + } + sp->rowbytes = rowbytes; + sp->rowpixels = rowpixels; + /* + * Allocate any additional space required for decoding/encoding. + */ + needsRefLine = ( + (sp->groupoptions & GROUP3OPT_2DENCODING) || + td->td_compression == COMPRESSION_CCITTFAX4 + ); + + /* + Assure that allocation computations do not overflow. + + TIFFroundup and TIFFSafeMultiply return zero on integer overflow + */ + dsp->runs=(uint32*) NULL; + nruns = TIFFroundup_32(rowpixels,32); + if (needsRefLine) { + nruns = TIFFSafeMultiply(uint32,nruns,2); + } + if ((nruns == 0) || (TIFFSafeMultiply(uint32,nruns,2) == 0)) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "Row pixels integer overflow (rowpixels %u)", + rowpixels); + return (0); + } + dsp->runs = (uint32*) _TIFFCheckMalloc(tif, + TIFFSafeMultiply(uint32,nruns,2), + sizeof (uint32), + "for Group 3/4 run arrays"); + if (dsp->runs == NULL) + return (0); + memset( dsp->runs, 0, TIFFSafeMultiply(uint32,nruns,2)*sizeof(uint32)); + dsp->curruns = dsp->runs; + if (needsRefLine) + dsp->refruns = dsp->runs + nruns; + else + dsp->refruns = NULL; + if (td->td_compression == COMPRESSION_CCITTFAX3 + && is2DEncoding(dsp)) { /* NB: default is 1D routine */ + tif->tif_decoderow = Fax3Decode2D; + tif->tif_decodestrip = Fax3Decode2D; + tif->tif_decodetile = Fax3Decode2D; + } + + if (needsRefLine) { /* 2d encoding */ + Fax3CodecState* esp = EncoderState(tif); + /* + * 2d encoding requires a scanline + * buffer for the ``reference line''; the + * scanline against which delta encoding + * is referenced. The reference line must + * be initialized to be ``white'' (done elsewhere). + */ + esp->refline = (unsigned char*) _TIFFmalloc(rowbytes); + if (esp->refline == NULL) { + TIFFErrorExt(tif->tif_clientdata, module, + "No space for Group 3/4 reference line"); + return (0); + } + } else /* 1d encoding */ + EncoderState(tif)->refline = NULL; + + return (1); +} + +/* + * CCITT Group 3 FAX Encoding. + */ + +#define Fax3FlushBits(tif, sp) { \ + if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize) \ + (void) TIFFFlushData1(tif); \ + *(tif)->tif_rawcp++ = (uint8) (sp)->data; \ + (tif)->tif_rawcc++; \ + (sp)->data = 0, (sp)->bit = 8; \ +} +#define _FlushBits(tif) { \ + if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize) \ + (void) TIFFFlushData1(tif); \ + *(tif)->tif_rawcp++ = (uint8) data; \ + (tif)->tif_rawcc++; \ + data = 0, bit = 8; \ +} +static const int _msbmask[9] = + { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff }; +#define _PutBits(tif, bits, length) { \ + while (length > bit) { \ + data |= bits >> (length - bit); \ + length -= bit; \ + _FlushBits(tif); \ + } \ + assert( length < 9 ); \ + data |= (bits & _msbmask[length]) << (bit - length); \ + bit -= length; \ + if (bit == 0) \ + _FlushBits(tif); \ +} + +/* + * Write a variable-length bit-value to + * the output stream. Values are + * assumed to be at most 16 bits. + */ +static void +Fax3PutBits(TIFF* tif, unsigned int bits, unsigned int length) +{ + Fax3CodecState* sp = EncoderState(tif); + unsigned int bit = sp->bit; + int data = sp->data; + + _PutBits(tif, bits, length); + + sp->data = data; + sp->bit = bit; +} + +/* + * Write a code to the output stream. + */ +#define putcode(tif, te) Fax3PutBits(tif, (te)->code, (te)->length) + +#ifdef FAX3_DEBUG +#define DEBUG_COLOR(w) (tab == TIFFFaxWhiteCodes ? w "W" : w "B") +#define DEBUG_PRINT(what,len) { \ + int t; \ + printf("%08X/%-2d: %s%5d\t", data, bit, DEBUG_COLOR(what), len); \ + for (t = length-1; t >= 0; t--) \ + putchar(code & (1<bit; + int data = sp->data; + unsigned int code, length; + + while (span >= 2624) { + const tableentry* te = &tab[63 + (2560>>6)]; + code = te->code, length = te->length; +#ifdef FAX3_DEBUG + DEBUG_PRINT("MakeUp", te->runlen); +#endif + _PutBits(tif, code, length); + span -= te->runlen; + } + if (span >= 64) { + const tableentry* te = &tab[63 + (span>>6)]; + assert(te->runlen == 64*(span>>6)); + code = te->code, length = te->length; +#ifdef FAX3_DEBUG + DEBUG_PRINT("MakeUp", te->runlen); +#endif + _PutBits(tif, code, length); + span -= te->runlen; + } + code = tab[span].code, length = tab[span].length; +#ifdef FAX3_DEBUG + DEBUG_PRINT(" Term", tab[span].runlen); +#endif + _PutBits(tif, code, length); + + sp->data = data; + sp->bit = bit; +} + +/* + * Write an EOL code to the output stream. The zero-fill + * logic for byte-aligning encoded scanlines is handled + * here. We also handle writing the tag bit for the next + * scanline when doing 2d encoding. + */ +static void +Fax3PutEOL(TIFF* tif) +{ + Fax3CodecState* sp = EncoderState(tif); + unsigned int bit = sp->bit; + int data = sp->data; + unsigned int code, length, tparm; + + if (sp->b.groupoptions & GROUP3OPT_FILLBITS) { + /* + * Force bit alignment so EOL will terminate on + * a byte boundary. That is, force the bit alignment + * to 16-12 = 4 before putting out the EOL code. + */ + int align = 8 - 4; + if (align != sp->bit) { + if (align > sp->bit) + align = sp->bit + (8 - align); + else + align = sp->bit - align; + code = 0; + tparm=align; + _PutBits(tif, 0, tparm); + } + } + code = EOL, length = 12; + if (is2DEncoding(sp)) + code = (code<<1) | (sp->tag == G3_1D), length++; + _PutBits(tif, code, length); + + sp->data = data; + sp->bit = bit; +} + +/* + * Reset encoding state at the start of a strip. + */ +static int +Fax3PreEncode(TIFF* tif, uint16 s) +{ + Fax3CodecState* sp = EncoderState(tif); + + (void) s; + assert(sp != NULL); + sp->bit = 8; + sp->data = 0; + sp->tag = G3_1D; + /* + * This is necessary for Group 4; otherwise it isn't + * needed because the first scanline of each strip ends + * up being copied into the refline. + */ + if (sp->refline) + _TIFFmemset(sp->refline, 0x00, sp->b.rowbytes); + if (is2DEncoding(sp)) { + float res = tif->tif_dir.td_yresolution; + /* + * The CCITT spec says that when doing 2d encoding, you + * should only do it on K consecutive scanlines, where K + * depends on the resolution of the image being encoded + * (2 for <= 200 lpi, 4 for > 200 lpi). Since the directory + * code initializes td_yresolution to 0, this code will + * select a K of 2 unless the YResolution tag is set + * appropriately. (Note also that we fudge a little here + * and use 150 lpi to avoid problems with units conversion.) + */ + if (tif->tif_dir.td_resolutionunit == RESUNIT_CENTIMETER) + res *= 2.54f; /* convert to inches */ + sp->maxk = (res > 150 ? 4 : 2); + sp->k = sp->maxk-1; + } else + sp->k = sp->maxk = 0; + sp->line = 0; + return (1); +} + +static const unsigned char zeroruns[256] = { + 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, /* 0x00 - 0x0f */ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 0x10 - 0x1f */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x20 - 0x2f */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x30 - 0x3f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 - 0x4f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x50 - 0x5f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60 - 0x6f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x70 - 0x7f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 - 0x8f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 - 0x9f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xa0 - 0xaf */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xb0 - 0xbf */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xc0 - 0xcf */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xd0 - 0xdf */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xe0 - 0xef */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xf0 - 0xff */ +}; +static const unsigned char oneruns[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 - 0x0f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 - 0x1f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 - 0x2f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x30 - 0x3f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x40 - 0x4f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 - 0x5f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x6f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x7f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x80 - 0x8f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x90 - 0x9f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xa0 - 0xaf */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xb0 - 0xbf */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0xc0 - 0xcf */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0xd0 - 0xdf */ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 0xe0 - 0xef */ + 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 8, /* 0xf0 - 0xff */ +}; + +/* + * On certain systems it pays to inline + * the routines that find pixel spans. + */ +#ifdef VAXC +static int32 find0span(unsigned char*, int32, int32); +static int32 find1span(unsigned char*, int32, int32); +#pragma inline(find0span,find1span) +#endif + +/* + * Find a span of ones or zeros using the supplied + * table. The ``base'' of the bit string is supplied + * along with the start+end bit indices. + */ +inline static int32 +find0span(unsigned char* bp, int32 bs, int32 be) +{ + int32 bits = be - bs; + int32 n, span; + + bp += bs>>3; + /* + * Check partial byte on lhs. + */ + if (bits > 0 && (n = (bs & 7))) { + span = zeroruns[(*bp << n) & 0xff]; + if (span > 8-n) /* table value too generous */ + span = 8-n; + if (span > bits) /* constrain span to bit range */ + span = bits; + if (n+span < 8) /* doesn't extend to edge of byte */ + return (span); + bits -= span; + bp++; + } else + span = 0; + if (bits >= (int32)(2 * 8 * sizeof(long))) { + long* lp; + /* + * Align to longword boundary and check longwords. + */ + while (!isAligned(bp, long)) { + if (*bp != 0x00) + return (span + zeroruns[*bp]); + span += 8, bits -= 8; + bp++; + } + lp = (long*) bp; + while ((bits >= (int32)(8 * sizeof(long))) && (0 == *lp)) { + span += 8*sizeof (long), bits -= 8*sizeof (long); + lp++; + } + bp = (unsigned char*) lp; + } + /* + * Scan full bytes for all 0's. + */ + while (bits >= 8) { + if (*bp != 0x00) /* end of run */ + return (span + zeroruns[*bp]); + span += 8, bits -= 8; + bp++; + } + /* + * Check partial byte on rhs. + */ + if (bits > 0) { + n = zeroruns[*bp]; + span += (n > bits ? bits : n); + } + return (span); +} + +inline static int32 +find1span(unsigned char* bp, int32 bs, int32 be) +{ + int32 bits = be - bs; + int32 n, span; + + bp += bs>>3; + /* + * Check partial byte on lhs. + */ + if (bits > 0 && (n = (bs & 7))) { + span = oneruns[(*bp << n) & 0xff]; + if (span > 8-n) /* table value too generous */ + span = 8-n; + if (span > bits) /* constrain span to bit range */ + span = bits; + if (n+span < 8) /* doesn't extend to edge of byte */ + return (span); + bits -= span; + bp++; + } else + span = 0; + if (bits >= (int32)(2 * 8 * sizeof(long))) { + long* lp; + /* + * Align to longword boundary and check longwords. + */ + while (!isAligned(bp, long)) { + if (*bp != 0xff) + return (span + oneruns[*bp]); + span += 8, bits -= 8; + bp++; + } + lp = (long*) bp; + while ((bits >= (int32)(8 * sizeof(long))) && (~0 == *lp)) { + span += 8*sizeof (long), bits -= 8*sizeof (long); + lp++; + } + bp = (unsigned char*) lp; + } + /* + * Scan full bytes for all 1's. + */ + while (bits >= 8) { + if (*bp != 0xff) /* end of run */ + return (span + oneruns[*bp]); + span += 8, bits -= 8; + bp++; + } + /* + * Check partial byte on rhs. + */ + if (bits > 0) { + n = oneruns[*bp]; + span += (n > bits ? bits : n); + } + return (span); +} + +/* + * Return the offset of the next bit in the range + * [bs..be] that is different from the specified + * color. The end, be, is returned if no such bit + * exists. + */ +#define finddiff(_cp, _bs, _be, _color) \ + (_bs + (_color ? find1span(_cp,_bs,_be) : find0span(_cp,_bs,_be))) +/* + * Like finddiff, but also check the starting bit + * against the end in case start > end. + */ +#define finddiff2(_cp, _bs, _be, _color) \ + (_bs < _be ? finddiff(_cp,_bs,_be,_color) : _be) + +/* + * 1d-encode a row of pixels. The encoding is + * a sequence of all-white or all-black spans + * of pixels encoded with Huffman codes. + */ +static int +Fax3Encode1DRow(TIFF* tif, unsigned char* bp, uint32 bits) +{ + Fax3CodecState* sp = EncoderState(tif); + int32 span; + uint32 bs = 0; + + for (;;) { + span = find0span(bp, bs, bits); /* white span */ + putspan(tif, span, TIFFFaxWhiteCodes); + bs += span; + if (bs >= bits) + break; + span = find1span(bp, bs, bits); /* black span */ + putspan(tif, span, TIFFFaxBlackCodes); + bs += span; + if (bs >= bits) + break; + } + if (sp->b.mode & (FAXMODE_BYTEALIGN|FAXMODE_WORDALIGN)) { + if (sp->bit != 8) /* byte-align */ + Fax3FlushBits(tif, sp); + if ((sp->b.mode&FAXMODE_WORDALIGN) && + !isAligned(tif->tif_rawcp, uint16)) + Fax3FlushBits(tif, sp); + } + return (1); +} + +static const tableentry horizcode = + { 3, 0x1, 0 }; /* 001 */ +static const tableentry passcode = + { 4, 0x1, 0 }; /* 0001 */ +static const tableentry vcodes[7] = { + { 7, 0x03, 0 }, /* 0000 011 */ + { 6, 0x03, 0 }, /* 0000 11 */ + { 3, 0x03, 0 }, /* 011 */ + { 1, 0x1, 0 }, /* 1 */ + { 3, 0x2, 0 }, /* 010 */ + { 6, 0x02, 0 }, /* 0000 10 */ + { 7, 0x02, 0 } /* 0000 010 */ +}; + +/* + * 2d-encode a row of pixels. Consult the CCITT + * documentation for the algorithm. + */ +static int +Fax3Encode2DRow(TIFF* tif, unsigned char* bp, unsigned char* rp, uint32 bits) +{ +#define PIXEL(buf,ix) ((((buf)[(ix)>>3]) >> (7-((ix)&7))) & 1) + uint32 a0 = 0; + uint32 a1 = (PIXEL(bp, 0) != 0 ? 0 : finddiff(bp, 0, bits, 0)); + uint32 b1 = (PIXEL(rp, 0) != 0 ? 0 : finddiff(rp, 0, bits, 0)); + uint32 a2, b2; + + for (;;) { + b2 = finddiff2(rp, b1, bits, PIXEL(rp,b1)); + if (b2 >= a1) { + int32 d = b1 - a1; + if (!(-3 <= d && d <= 3)) { /* horizontal mode */ + a2 = finddiff2(bp, a1, bits, PIXEL(bp,a1)); + putcode(tif, &horizcode); + if (a0+a1 == 0 || PIXEL(bp, a0) == 0) { + putspan(tif, a1-a0, TIFFFaxWhiteCodes); + putspan(tif, a2-a1, TIFFFaxBlackCodes); + } else { + putspan(tif, a1-a0, TIFFFaxBlackCodes); + putspan(tif, a2-a1, TIFFFaxWhiteCodes); + } + a0 = a2; + } else { /* vertical mode */ + putcode(tif, &vcodes[d+3]); + a0 = a1; + } + } else { /* pass mode */ + putcode(tif, &passcode); + a0 = b2; + } + if (a0 >= bits) + break; + a1 = finddiff(bp, a0, bits, PIXEL(bp,a0)); + b1 = finddiff(rp, a0, bits, !PIXEL(bp,a0)); + b1 = finddiff(rp, b1, bits, PIXEL(bp,a0)); + } + return (1); +#undef PIXEL +} + +/* + * Encode a buffer of pixels. + */ +static int +Fax3Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + static const char module[] = "Fax3Encode"; + Fax3CodecState* sp = EncoderState(tif); + (void) s; + if (cc % sp->b.rowbytes) + { + TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be written"); + return (0); + } + while (cc > 0) { + if ((sp->b.mode & FAXMODE_NOEOL) == 0) + Fax3PutEOL(tif); + if (is2DEncoding(sp)) { + if (sp->tag == G3_1D) { + if (!Fax3Encode1DRow(tif, bp, sp->b.rowpixels)) + return (0); + sp->tag = G3_2D; + } else { + if (!Fax3Encode2DRow(tif, bp, sp->refline, + sp->b.rowpixels)) + return (0); + sp->k--; + } + if (sp->k == 0) { + sp->tag = G3_1D; + sp->k = sp->maxk-1; + } else + _TIFFmemcpy(sp->refline, bp, sp->b.rowbytes); + } else { + if (!Fax3Encode1DRow(tif, bp, sp->b.rowpixels)) + return (0); + } + bp += sp->b.rowbytes; + cc -= sp->b.rowbytes; + } + return (1); +} + +static int +Fax3PostEncode(TIFF* tif) +{ + Fax3CodecState* sp = EncoderState(tif); + + if (sp->bit != 8) + Fax3FlushBits(tif, sp); + return (1); +} + +static void +Fax3Close(TIFF* tif) +{ + if ((Fax3State(tif)->mode & FAXMODE_NORTC) == 0) { + Fax3CodecState* sp = EncoderState(tif); + unsigned int code = EOL; + unsigned int length = 12; + int i; + + if (is2DEncoding(sp)) + code = (code<<1) | (sp->tag == G3_1D), length++; + for (i = 0; i < 6; i++) + Fax3PutBits(tif, code, length); + Fax3FlushBits(tif, sp); + } +} + +static void +Fax3Cleanup(TIFF* tif) +{ + Fax3CodecState* sp = DecoderState(tif); + + assert(sp != 0); + + tif->tif_tagmethods.vgetfield = sp->b.vgetparent; + tif->tif_tagmethods.vsetfield = sp->b.vsetparent; + tif->tif_tagmethods.printdir = sp->b.printdir; + + if (sp->runs) + _TIFFfree(sp->runs); + if (sp->refline) + _TIFFfree(sp->refline); + + _TIFFfree(tif->tif_data); + tif->tif_data = NULL; + + _TIFFSetDefaultCompressionState(tif); +} + +#define FIELD_BADFAXLINES (FIELD_CODEC+0) +#define FIELD_CLEANFAXDATA (FIELD_CODEC+1) +#define FIELD_BADFAXRUN (FIELD_CODEC+2) + +#define FIELD_OPTIONS (FIELD_CODEC+7) + +static const TIFFField faxFields[] = { + { TIFFTAG_FAXMODE, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "FaxMode", NULL }, + { TIFFTAG_FAXFILLFUNC, 0, 0, TIFF_ANY, 0, TIFF_SETGET_OTHER, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "FaxFillFunc", NULL }, + { TIFFTAG_BADFAXLINES, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_BADFAXLINES, TRUE, FALSE, "BadFaxLines", NULL }, + { TIFFTAG_CLEANFAXDATA, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UINT16, FIELD_CLEANFAXDATA, TRUE, FALSE, "CleanFaxData", NULL }, + { TIFFTAG_CONSECUTIVEBADFAXLINES, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_BADFAXRUN, TRUE, FALSE, "ConsecutiveBadFaxLines", NULL }}; +static const TIFFField fax3Fields[] = { + { TIFFTAG_GROUP3OPTIONS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_OPTIONS, FALSE, FALSE, "Group3Options", NULL }, +}; +static const TIFFField fax4Fields[] = { + { TIFFTAG_GROUP4OPTIONS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_OPTIONS, FALSE, FALSE, "Group4Options", NULL }, +}; + +static int +Fax3VSetField(TIFF* tif, uint32 tag, va_list ap) +{ + Fax3BaseState* sp = Fax3State(tif); + const TIFFField* fip; + + assert(sp != 0); + assert(sp->vsetparent != 0); + + switch (tag) { + case TIFFTAG_FAXMODE: + sp->mode = (int) va_arg(ap, int); + return 1; /* NB: pseudo tag */ + case TIFFTAG_FAXFILLFUNC: + DecoderState(tif)->fill = va_arg(ap, TIFFFaxFillFunc); + return 1; /* NB: pseudo tag */ + case TIFFTAG_GROUP3OPTIONS: + /* XXX: avoid reading options if compression mismatches. */ + if (tif->tif_dir.td_compression == COMPRESSION_CCITTFAX3) + sp->groupoptions = (uint32) va_arg(ap, uint32); + break; + case TIFFTAG_GROUP4OPTIONS: + /* XXX: avoid reading options if compression mismatches. */ + if (tif->tif_dir.td_compression == COMPRESSION_CCITTFAX4) + sp->groupoptions = (uint32) va_arg(ap, uint32); + break; + case TIFFTAG_BADFAXLINES: + sp->badfaxlines = (uint32) va_arg(ap, uint32); + break; + case TIFFTAG_CLEANFAXDATA: + sp->cleanfaxdata = (uint16) va_arg(ap, uint16_vap); + break; + case TIFFTAG_CONSECUTIVEBADFAXLINES: + sp->badfaxrun = (uint32) va_arg(ap, uint32); + break; + default: + return (*sp->vsetparent)(tif, tag, ap); + } + + if ((fip = TIFFFieldWithTag(tif, tag))) + TIFFSetFieldBit(tif, fip->field_bit); + else + return 0; + + tif->tif_flags |= TIFF_DIRTYDIRECT; + return 1; +} + +static int +Fax3VGetField(TIFF* tif, uint32 tag, va_list ap) +{ + Fax3BaseState* sp = Fax3State(tif); + + assert(sp != 0); + + switch (tag) { + case TIFFTAG_FAXMODE: + *va_arg(ap, int*) = sp->mode; + break; + case TIFFTAG_FAXFILLFUNC: + *va_arg(ap, TIFFFaxFillFunc*) = DecoderState(tif)->fill; + break; + case TIFFTAG_GROUP3OPTIONS: + case TIFFTAG_GROUP4OPTIONS: + *va_arg(ap, uint32*) = sp->groupoptions; + break; + case TIFFTAG_BADFAXLINES: + *va_arg(ap, uint32*) = sp->badfaxlines; + break; + case TIFFTAG_CLEANFAXDATA: + *va_arg(ap, uint16*) = sp->cleanfaxdata; + break; + case TIFFTAG_CONSECUTIVEBADFAXLINES: + *va_arg(ap, uint32*) = sp->badfaxrun; + break; + default: + return (*sp->vgetparent)(tif, tag, ap); + } + return (1); +} + +static void +Fax3PrintDir(TIFF* tif, FILE* fd, long flags) +{ + Fax3BaseState* sp = Fax3State(tif); + + assert(sp != 0); + + (void) flags; + if (TIFFFieldSet(tif,FIELD_OPTIONS)) { + const char* sep = " "; + if (tif->tif_dir.td_compression == COMPRESSION_CCITTFAX4) { + fprintf(fd, " Group 4 Options:"); + if (sp->groupoptions & GROUP4OPT_UNCOMPRESSED) + fprintf(fd, "%suncompressed data", sep); + } else { + + fprintf(fd, " Group 3 Options:"); + if (sp->groupoptions & GROUP3OPT_2DENCODING) + fprintf(fd, "%s2-d encoding", sep), sep = "+"; + if (sp->groupoptions & GROUP3OPT_FILLBITS) + fprintf(fd, "%sEOL padding", sep), sep = "+"; + if (sp->groupoptions & GROUP3OPT_UNCOMPRESSED) + fprintf(fd, "%suncompressed data", sep); + } + fprintf(fd, " (%lu = 0x%lx)\n", + (unsigned long) sp->groupoptions, + (unsigned long) sp->groupoptions); + } + if (TIFFFieldSet(tif,FIELD_CLEANFAXDATA)) { + fprintf(fd, " Fax Data:"); + switch (sp->cleanfaxdata) { + case CLEANFAXDATA_CLEAN: + fprintf(fd, " clean"); + break; + case CLEANFAXDATA_REGENERATED: + fprintf(fd, " receiver regenerated"); + break; + case CLEANFAXDATA_UNCLEAN: + fprintf(fd, " uncorrected errors"); + break; + } + fprintf(fd, " (%u = 0x%x)\n", + sp->cleanfaxdata, sp->cleanfaxdata); + } + if (TIFFFieldSet(tif,FIELD_BADFAXLINES)) + fprintf(fd, " Bad Fax Lines: %lu\n", + (unsigned long) sp->badfaxlines); + if (TIFFFieldSet(tif,FIELD_BADFAXRUN)) + fprintf(fd, " Consecutive Bad Fax Lines: %lu\n", + (unsigned long) sp->badfaxrun); + if (sp->printdir) + (*sp->printdir)(tif, fd, flags); +} + +static int +InitCCITTFax3(TIFF* tif) +{ + static const char module[] = "InitCCITTFax3"; + Fax3BaseState* sp; + + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFields(tif, faxFields, TIFFArrayCount(faxFields))) { + TIFFErrorExt(tif->tif_clientdata, "InitCCITTFax3", + "Merging common CCITT Fax codec-specific tags failed"); + return 0; + } + + /* + * Allocate state block so tag methods have storage to record values. + */ + tif->tif_data = (uint8*) + _TIFFmalloc(sizeof (Fax3CodecState)); + + if (tif->tif_data == NULL) { + TIFFErrorExt(tif->tif_clientdata, module, + "No space for state block"); + return (0); + } + + sp = Fax3State(tif); + sp->rw_mode = tif->tif_mode; + + /* + * Override parent get/set field methods. + */ + sp->vgetparent = tif->tif_tagmethods.vgetfield; + tif->tif_tagmethods.vgetfield = Fax3VGetField; /* hook for codec tags */ + sp->vsetparent = tif->tif_tagmethods.vsetfield; + tif->tif_tagmethods.vsetfield = Fax3VSetField; /* hook for codec tags */ + sp->printdir = tif->tif_tagmethods.printdir; + tif->tif_tagmethods.printdir = Fax3PrintDir; /* hook for codec tags */ + sp->groupoptions = 0; + + if (sp->rw_mode == O_RDONLY) /* FIXME: improve for in place update */ + tif->tif_flags |= TIFF_NOBITREV; /* decoder does bit reversal */ + DecoderState(tif)->runs = NULL; + TIFFSetField(tif, TIFFTAG_FAXFILLFUNC, _TIFFFax3fillruns); + EncoderState(tif)->refline = NULL; + + /* + * Install codec methods. + */ + tif->tif_fixuptags = Fax3FixupTags; + tif->tif_setupdecode = Fax3SetupState; + tif->tif_predecode = Fax3PreDecode; + tif->tif_decoderow = Fax3Decode1D; + tif->tif_decodestrip = Fax3Decode1D; + tif->tif_decodetile = Fax3Decode1D; + tif->tif_setupencode = Fax3SetupState; + tif->tif_preencode = Fax3PreEncode; + tif->tif_postencode = Fax3PostEncode; + tif->tif_encoderow = Fax3Encode; + tif->tif_encodestrip = Fax3Encode; + tif->tif_encodetile = Fax3Encode; + tif->tif_close = Fax3Close; + tif->tif_cleanup = Fax3Cleanup; + + return (1); +} + +int +TIFFInitCCITTFax3(TIFF* tif, int scheme) +{ + (void) scheme; + if (InitCCITTFax3(tif)) { + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFields(tif, fax3Fields, + TIFFArrayCount(fax3Fields))) { + TIFFErrorExt(tif->tif_clientdata, "TIFFInitCCITTFax3", + "Merging CCITT Fax 3 codec-specific tags failed"); + return 0; + } + + /* + * The default format is Class/F-style w/o RTC. + */ + return TIFFSetField(tif, TIFFTAG_FAXMODE, FAXMODE_CLASSF); + } else + return 01; +} + +/* + * CCITT Group 4 (T.6) Facsimile-compatible + * Compression Scheme Support. + */ + +#define SWAP(t,a,b) { t x; x = (a); (a) = (b); (b) = x; } +/* + * Decode the requested amount of G4-encoded data. + */ +static int +Fax4Decode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) +{ + DECLARE_STATE_2D(tif, sp, "Fax4Decode"); + (void) s; + if (occ % sp->b.rowbytes) + { + TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read"); + return (-1); + } + CACHE_STATE(tif, sp); + while (occ > 0) { + a0 = 0; + RunLength = 0; + pa = thisrun = sp->curruns; + pb = sp->refruns; + b1 = *pb++; +#ifdef FAX3_DEBUG + printf("\nBitAcc=%08X, BitsAvail = %d\n", BitAcc, BitsAvail); + printf("-------------------- %d\n", tif->tif_row); + fflush(stdout); +#endif + EXPAND2D(EOFG4); + if (EOLcnt) + goto EOFG4; + (*sp->fill)(buf, thisrun, pa, lastx); + SETVALUE(0); /* imaginary change for reference */ + SWAP(uint32*, sp->curruns, sp->refruns); + buf += sp->b.rowbytes; + occ -= sp->b.rowbytes; + sp->line++; + continue; + EOFG4: + NeedBits16( 13, BADG4 ); + BADG4: +#ifdef FAX3_DEBUG + if( GetBits(13) != 0x1001 ) + fputs( "Bad EOFB\n", stderr ); +#endif + ClrBits( 13 ); + (*sp->fill)(buf, thisrun, pa, lastx); + UNCACHE_STATE(tif, sp); + return ( sp->line ? 1 : -1); /* don't error on badly-terminated strips */ + } + UNCACHE_STATE(tif, sp); + return (1); +} +#undef SWAP + +/* + * Encode the requested amount of data. + */ +static int +Fax4Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + static const char module[] = "Fax4Encode"; + Fax3CodecState *sp = EncoderState(tif); + (void) s; + if (cc % sp->b.rowbytes) + { + TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be written"); + return (0); + } + while (cc > 0) { + if (!Fax3Encode2DRow(tif, bp, sp->refline, sp->b.rowpixels)) + return (0); + _TIFFmemcpy(sp->refline, bp, sp->b.rowbytes); + bp += sp->b.rowbytes; + cc -= sp->b.rowbytes; + } + return (1); +} + +static int +Fax4PostEncode(TIFF* tif) +{ + Fax3CodecState *sp = EncoderState(tif); + + /* terminate strip w/ EOFB */ + Fax3PutBits(tif, EOL, 12); + Fax3PutBits(tif, EOL, 12); + if (sp->bit != 8) + Fax3FlushBits(tif, sp); + return (1); +} + +int +TIFFInitCCITTFax4(TIFF* tif, int scheme) +{ + (void) scheme; + if (InitCCITTFax3(tif)) { /* reuse G3 support */ + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFields(tif, fax4Fields, + TIFFArrayCount(fax4Fields))) { + TIFFErrorExt(tif->tif_clientdata, "TIFFInitCCITTFax4", + "Merging CCITT Fax 4 codec-specific tags failed"); + return 0; + } + + tif->tif_decoderow = Fax4Decode; + tif->tif_decodestrip = Fax4Decode; + tif->tif_decodetile = Fax4Decode; + tif->tif_encoderow = Fax4Encode; + tif->tif_encodestrip = Fax4Encode; + tif->tif_encodetile = Fax4Encode; + tif->tif_postencode = Fax4PostEncode; + /* + * Suppress RTC at the end of each strip. + */ + return TIFFSetField(tif, TIFFTAG_FAXMODE, FAXMODE_NORTC); + } else + return (0); +} + +/* + * CCITT Group 3 1-D Modified Huffman RLE Compression Support. + * (Compression algorithms 2 and 32771) + */ + +/* + * Decode the requested amount of RLE-encoded data. + */ +static int +Fax3DecodeRLE(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) +{ + DECLARE_STATE(tif, sp, "Fax3DecodeRLE"); + int mode = sp->b.mode; + (void) s; + if (occ % sp->b.rowbytes) + { + TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read"); + return (-1); + } + CACHE_STATE(tif, sp); + thisrun = sp->curruns; + while (occ > 0) { + a0 = 0; + RunLength = 0; + pa = thisrun; +#ifdef FAX3_DEBUG + printf("\nBitAcc=%08X, BitsAvail = %d\n", BitAcc, BitsAvail); + printf("-------------------- %d\n", tif->tif_row); + fflush(stdout); +#endif + EXPAND1D(EOFRLE); + (*sp->fill)(buf, thisrun, pa, lastx); + /* + * Cleanup at the end of the row. + */ + if (mode & FAXMODE_BYTEALIGN) { + int n = BitsAvail - (BitsAvail &~ 7); + ClrBits(n); + } else if (mode & FAXMODE_WORDALIGN) { + int n = BitsAvail - (BitsAvail &~ 15); + ClrBits(n); + if (BitsAvail == 0 && !isAligned(cp, uint16)) + cp++; + } + buf += sp->b.rowbytes; + occ -= sp->b.rowbytes; + sp->line++; + continue; + EOFRLE: /* premature EOF */ + (*sp->fill)(buf, thisrun, pa, lastx); + UNCACHE_STATE(tif, sp); + return (-1); + } + UNCACHE_STATE(tif, sp); + return (1); +} + +int +TIFFInitCCITTRLE(TIFF* tif, int scheme) +{ + (void) scheme; + if (InitCCITTFax3(tif)) { /* reuse G3 support */ + tif->tif_decoderow = Fax3DecodeRLE; + tif->tif_decodestrip = Fax3DecodeRLE; + tif->tif_decodetile = Fax3DecodeRLE; + /* + * Suppress RTC+EOLs when encoding and byte-align data. + */ + return TIFFSetField(tif, TIFFTAG_FAXMODE, + FAXMODE_NORTC|FAXMODE_NOEOL|FAXMODE_BYTEALIGN); + } else + return (0); +} + +int +TIFFInitCCITTRLEW(TIFF* tif, int scheme) +{ + (void) scheme; + if (InitCCITTFax3(tif)) { /* reuse G3 support */ + tif->tif_decoderow = Fax3DecodeRLE; + tif->tif_decodestrip = Fax3DecodeRLE; + tif->tif_decodetile = Fax3DecodeRLE; + /* + * Suppress RTC+EOLs when encoding and word-align data. + */ + return TIFFSetField(tif, TIFFTAG_FAXMODE, + FAXMODE_NORTC|FAXMODE_NOEOL|FAXMODE_WORDALIGN); + } else + return (0); +} +#endif /* CCITT_SUPPORT */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_fax3.h b/Source/LibTIFF4/tif_fax3.h index fd304c9..652bb6e 100644 --- a/Source/LibTIFF4/tif_fax3.h +++ b/Source/LibTIFF4/tif_fax3.h @@ -1,538 +1,538 @@ -/* $Id: tif_fax3.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1990-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifndef _FAX3_ -#define _FAX3_ -/* - * TIFF Library. - * - * CCITT Group 3 (T.4) and Group 4 (T.6) Decompression Support. - * - * Decoder support is derived, with permission, from the code - * in Frank Cringle's viewfax program; - * Copyright (C) 1990, 1995 Frank D. Cringle. - */ -#include "tiff.h" - -/* - * To override the default routine used to image decoded - * spans one can use the pseduo tag TIFFTAG_FAXFILLFUNC. - * The routine must have the type signature given below; - * for example: - * - * fillruns(unsigned char* buf, uint32* runs, uint32* erun, uint32 lastx) - * - * where buf is place to set the bits, runs is the array of b&w run - * lengths (white then black), erun is the last run in the array, and - * lastx is the width of the row in pixels. Fill routines can assume - * the run array has room for at least lastx runs and can overwrite - * data in the run array as needed (e.g. to append zero runs to bring - * the count up to a nice multiple). - */ -typedef void (*TIFFFaxFillFunc)(unsigned char*, uint32*, uint32*, uint32); - -/* - * The default run filler; made external for other decoders. - */ -#if defined(__cplusplus) -extern "C" { -#endif -extern void _TIFFFax3fillruns(unsigned char*, uint32*, uint32*, uint32); -#if defined(__cplusplus) -} -#endif - - -/* finite state machine codes */ -#define S_Null 0 -#define S_Pass 1 -#define S_Horiz 2 -#define S_V0 3 -#define S_VR 4 -#define S_VL 5 -#define S_Ext 6 -#define S_TermW 7 -#define S_TermB 8 -#define S_MakeUpW 9 -#define S_MakeUpB 10 -#define S_MakeUp 11 -#define S_EOL 12 - -typedef struct { /* state table entry */ - unsigned char State; /* see above */ - unsigned char Width; /* width of code in bits */ - uint32 Param; /* unsigned 32-bit run length in bits */ -} TIFFFaxTabEnt; - -extern const TIFFFaxTabEnt TIFFFaxMainTable[]; -extern const TIFFFaxTabEnt TIFFFaxWhiteTable[]; -extern const TIFFFaxTabEnt TIFFFaxBlackTable[]; - -/* - * The following macros define the majority of the G3/G4 decoder - * algorithm using the state tables defined elsewhere. To build - * a decoder you need some setup code and some glue code. Note - * that you may also need/want to change the way the NeedBits* - * macros get input data if, for example, you know the data to be - * decoded is properly aligned and oriented (doing so before running - * the decoder can be a big performance win). - * - * Consult the decoder in the TIFF library for an idea of what you - * need to define and setup to make use of these definitions. - * - * NB: to enable a debugging version of these macros define FAX3_DEBUG - * before including this file. Trace output goes to stdout. - */ - -#ifndef EndOfData -#define EndOfData() (cp >= ep) -#endif -/* - * Need <=8 or <=16 bits of input data. Unlike viewfax we - * cannot use/assume a word-aligned, properly bit swizzled - * input data set because data may come from an arbitrarily - * aligned, read-only source such as a memory-mapped file. - * Note also that the viewfax decoder does not check for - * running off the end of the input data buffer. This is - * possible for G3-encoded data because it prescans the input - * data to count EOL markers, but can cause problems for G4 - * data. In any event, we don't prescan and must watch for - * running out of data since we can't permit the library to - * scan past the end of the input data buffer. - * - * Finally, note that we must handle remaindered data at the end - * of a strip specially. The coder asks for a fixed number of - * bits when scanning for the next code. This may be more bits - * than are actually present in the data stream. If we appear - * to run out of data but still have some number of valid bits - * remaining then we makeup the requested amount with zeros and - * return successfully. If the returned data is incorrect then - * we should be called again and get a premature EOF error; - * otherwise we should get the right answer. - */ -#ifndef NeedBits8 -#define NeedBits8(n,eoflab) do { \ - if (BitsAvail < (n)) { \ - if (EndOfData()) { \ - if (BitsAvail == 0) /* no valid bits */ \ - goto eoflab; \ - BitsAvail = (n); /* pad with zeros */ \ - } else { \ - BitAcc |= ((uint32) bitmap[*cp++])<>= (n); \ -} while (0) - -#ifdef FAX3_DEBUG -static const char* StateNames[] = { - "Null ", - "Pass ", - "Horiz ", - "V0 ", - "VR ", - "VL ", - "Ext ", - "TermW ", - "TermB ", - "MakeUpW", - "MakeUpB", - "MakeUp ", - "EOL ", -}; -#define DEBUG_SHOW putchar(BitAcc & (1 << t) ? '1' : '0') -#define LOOKUP8(wid,tab,eoflab) do { \ - int t; \ - NeedBits8(wid,eoflab); \ - TabEnt = tab + GetBits(wid); \ - printf("%08lX/%d: %s%5d\t", (long) BitAcc, BitsAvail, \ - StateNames[TabEnt->State], TabEnt->Param); \ - for (t = 0; t < TabEnt->Width; t++) \ - DEBUG_SHOW; \ - putchar('\n'); \ - fflush(stdout); \ - ClrBits(TabEnt->Width); \ -} while (0) -#define LOOKUP16(wid,tab,eoflab) do { \ - int t; \ - NeedBits16(wid,eoflab); \ - TabEnt = tab + GetBits(wid); \ - printf("%08lX/%d: %s%5d\t", (long) BitAcc, BitsAvail, \ - StateNames[TabEnt->State], TabEnt->Param); \ - for (t = 0; t < TabEnt->Width; t++) \ - DEBUG_SHOW; \ - putchar('\n'); \ - fflush(stdout); \ - ClrBits(TabEnt->Width); \ -} while (0) - -#define SETVALUE(x) do { \ - *pa++ = RunLength + (x); \ - printf("SETVALUE: %d\t%d\n", RunLength + (x), a0); \ - a0 += x; \ - RunLength = 0; \ -} while (0) -#else -#define LOOKUP8(wid,tab,eoflab) do { \ - NeedBits8(wid,eoflab); \ - TabEnt = tab + GetBits(wid); \ - ClrBits(TabEnt->Width); \ -} while (0) -#define LOOKUP16(wid,tab,eoflab) do { \ - NeedBits16(wid,eoflab); \ - TabEnt = tab + GetBits(wid); \ - ClrBits(TabEnt->Width); \ -} while (0) - -/* - * Append a run to the run length array for the - * current row and reset decoding state. - */ -#define SETVALUE(x) do { \ - *pa++ = RunLength + (x); \ - a0 += (x); \ - RunLength = 0; \ -} while (0) -#endif - -/* - * Synchronize input decoding at the start of each - * row by scanning for an EOL (if appropriate) and - * skipping any trash data that might be present - * after a decoding error. Note that the decoding - * done elsewhere that recognizes an EOL only consumes - * 11 consecutive zero bits. This means that if EOLcnt - * is non-zero then we still need to scan for the final flag - * bit that is part of the EOL code. - */ -#define SYNC_EOL(eoflab) do { \ - if (EOLcnt == 0) { \ - for (;;) { \ - NeedBits16(11,eoflab); \ - if (GetBits(11) == 0) \ - break; \ - ClrBits(1); \ - } \ - } \ - for (;;) { \ - NeedBits8(8,eoflab); \ - if (GetBits(8)) \ - break; \ - ClrBits(8); \ - } \ - while (GetBits(1) == 0) \ - ClrBits(1); \ - ClrBits(1); /* EOL bit */ \ - EOLcnt = 0; /* reset EOL counter/flag */ \ -} while (0) - -/* - * Cleanup the array of runs after decoding a row. - * We adjust final runs to insure the user buffer is not - * overwritten and/or undecoded area is white filled. - */ -#define CLEANUP_RUNS() do { \ - if (RunLength) \ - SETVALUE(0); \ - if (a0 != lastx) { \ - badlength(a0, lastx); \ - while (a0 > lastx && pa > thisrun) \ - a0 -= *--pa; \ - if (a0 < lastx) { \ - if (a0 < 0) \ - a0 = 0; \ - if ((pa-thisrun)&1) \ - SETVALUE(0); \ - SETVALUE(lastx - a0); \ - } else if (a0 > lastx) { \ - SETVALUE(lastx); \ - SETVALUE(0); \ - } \ - } \ -} while (0) - -/* - * Decode a line of 1D-encoded data. - * - * The line expanders are written as macros so that they can be reused - * but still have direct access to the local variables of the "calling" - * function. - * - * Note that unlike the original version we have to explicitly test for - * a0 >= lastx after each black/white run is decoded. This is because - * the original code depended on the input data being zero-padded to - * insure the decoder recognized an EOL before running out of data. - */ -#define EXPAND1D(eoflab) do { \ - for (;;) { \ - for (;;) { \ - LOOKUP16(12, TIFFFaxWhiteTable, eof1d); \ - switch (TabEnt->State) { \ - case S_EOL: \ - EOLcnt = 1; \ - goto done1d; \ - case S_TermW: \ - SETVALUE(TabEnt->Param); \ - goto doneWhite1d; \ - case S_MakeUpW: \ - case S_MakeUp: \ - a0 += TabEnt->Param; \ - RunLength += TabEnt->Param; \ - break; \ - default: \ - unexpected("WhiteTable", a0); \ - goto done1d; \ - } \ - } \ - doneWhite1d: \ - if (a0 >= lastx) \ - goto done1d; \ - for (;;) { \ - LOOKUP16(13, TIFFFaxBlackTable, eof1d); \ - switch (TabEnt->State) { \ - case S_EOL: \ - EOLcnt = 1; \ - goto done1d; \ - case S_TermB: \ - SETVALUE(TabEnt->Param); \ - goto doneBlack1d; \ - case S_MakeUpB: \ - case S_MakeUp: \ - a0 += TabEnt->Param; \ - RunLength += TabEnt->Param; \ - break; \ - default: \ - unexpected("BlackTable", a0); \ - goto done1d; \ - } \ - } \ - doneBlack1d: \ - if (a0 >= lastx) \ - goto done1d; \ - if( *(pa-1) == 0 && *(pa-2) == 0 ) \ - pa -= 2; \ - } \ -eof1d: \ - prematureEOF(a0); \ - CLEANUP_RUNS(); \ - goto eoflab; \ -done1d: \ - CLEANUP_RUNS(); \ -} while (0) - -/* - * Update the value of b1 using the array - * of runs for the reference line. - */ -#define CHECK_b1 do { \ - if (pa != thisrun) while (b1 <= a0 && b1 < lastx) { \ - b1 += pb[0] + pb[1]; \ - pb += 2; \ - } \ -} while (0) - -/* - * Expand a row of 2D-encoded data. - */ -#define EXPAND2D(eoflab) do { \ - while (a0 < lastx) { \ - LOOKUP8(7, TIFFFaxMainTable, eof2d); \ - switch (TabEnt->State) { \ - case S_Pass: \ - CHECK_b1; \ - b1 += *pb++; \ - RunLength += b1 - a0; \ - a0 = b1; \ - b1 += *pb++; \ - break; \ - case S_Horiz: \ - if ((pa-thisrun)&1) { \ - for (;;) { /* black first */ \ - LOOKUP16(13, TIFFFaxBlackTable, eof2d); \ - switch (TabEnt->State) { \ - case S_TermB: \ - SETVALUE(TabEnt->Param); \ - goto doneWhite2da; \ - case S_MakeUpB: \ - case S_MakeUp: \ - a0 += TabEnt->Param; \ - RunLength += TabEnt->Param; \ - break; \ - default: \ - goto badBlack2d; \ - } \ - } \ - doneWhite2da:; \ - for (;;) { /* then white */ \ - LOOKUP16(12, TIFFFaxWhiteTable, eof2d); \ - switch (TabEnt->State) { \ - case S_TermW: \ - SETVALUE(TabEnt->Param); \ - goto doneBlack2da; \ - case S_MakeUpW: \ - case S_MakeUp: \ - a0 += TabEnt->Param; \ - RunLength += TabEnt->Param; \ - break; \ - default: \ - goto badWhite2d; \ - } \ - } \ - doneBlack2da:; \ - } else { \ - for (;;) { /* white first */ \ - LOOKUP16(12, TIFFFaxWhiteTable, eof2d); \ - switch (TabEnt->State) { \ - case S_TermW: \ - SETVALUE(TabEnt->Param); \ - goto doneWhite2db; \ - case S_MakeUpW: \ - case S_MakeUp: \ - a0 += TabEnt->Param; \ - RunLength += TabEnt->Param; \ - break; \ - default: \ - goto badWhite2d; \ - } \ - } \ - doneWhite2db:; \ - for (;;) { /* then black */ \ - LOOKUP16(13, TIFFFaxBlackTable, eof2d); \ - switch (TabEnt->State) { \ - case S_TermB: \ - SETVALUE(TabEnt->Param); \ - goto doneBlack2db; \ - case S_MakeUpB: \ - case S_MakeUp: \ - a0 += TabEnt->Param; \ - RunLength += TabEnt->Param; \ - break; \ - default: \ - goto badBlack2d; \ - } \ - } \ - doneBlack2db:; \ - } \ - CHECK_b1; \ - break; \ - case S_V0: \ - CHECK_b1; \ - SETVALUE(b1 - a0); \ - b1 += *pb++; \ - break; \ - case S_VR: \ - CHECK_b1; \ - SETVALUE(b1 - a0 + TabEnt->Param); \ - b1 += *pb++; \ - break; \ - case S_VL: \ - CHECK_b1; \ - if (b1 <= (int) (a0 + TabEnt->Param)) { \ - if (b1 < (int) (a0 + TabEnt->Param) || pa != thisrun) { \ - unexpected("VL", a0); \ - goto eol2d; \ - } \ - } \ - SETVALUE(b1 - a0 - TabEnt->Param); \ - b1 -= *--pb; \ - break; \ - case S_Ext: \ - *pa++ = lastx - a0; \ - extension(a0); \ - goto eol2d; \ - case S_EOL: \ - *pa++ = lastx - a0; \ - NeedBits8(4,eof2d); \ - if (GetBits(4)) \ - unexpected("EOL", a0); \ - ClrBits(4); \ - EOLcnt = 1; \ - goto eol2d; \ - default: \ - badMain2d: \ - unexpected("MainTable", a0); \ - goto eol2d; \ - badBlack2d: \ - unexpected("BlackTable", a0); \ - goto eol2d; \ - badWhite2d: \ - unexpected("WhiteTable", a0); \ - goto eol2d; \ - eof2d: \ - prematureEOF(a0); \ - CLEANUP_RUNS(); \ - goto eoflab; \ - } \ - } \ - if (RunLength) { \ - if (RunLength + a0 < lastx) { \ - /* expect a final V0 */ \ - NeedBits8(1,eof2d); \ - if (!GetBits(1)) \ - goto badMain2d; \ - ClrBits(1); \ - } \ - SETVALUE(0); \ - } \ -eol2d: \ - CLEANUP_RUNS(); \ -} while (0) -#endif /* _FAX3_ */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_fax3.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1990-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef _FAX3_ +#define _FAX3_ +/* + * TIFF Library. + * + * CCITT Group 3 (T.4) and Group 4 (T.6) Decompression Support. + * + * Decoder support is derived, with permission, from the code + * in Frank Cringle's viewfax program; + * Copyright (C) 1990, 1995 Frank D. Cringle. + */ +#include "tiff.h" + +/* + * To override the default routine used to image decoded + * spans one can use the pseduo tag TIFFTAG_FAXFILLFUNC. + * The routine must have the type signature given below; + * for example: + * + * fillruns(unsigned char* buf, uint32* runs, uint32* erun, uint32 lastx) + * + * where buf is place to set the bits, runs is the array of b&w run + * lengths (white then black), erun is the last run in the array, and + * lastx is the width of the row in pixels. Fill routines can assume + * the run array has room for at least lastx runs and can overwrite + * data in the run array as needed (e.g. to append zero runs to bring + * the count up to a nice multiple). + */ +typedef void (*TIFFFaxFillFunc)(unsigned char*, uint32*, uint32*, uint32); + +/* + * The default run filler; made external for other decoders. + */ +#if defined(__cplusplus) +extern "C" { +#endif +extern void _TIFFFax3fillruns(unsigned char*, uint32*, uint32*, uint32); +#if defined(__cplusplus) +} +#endif + + +/* finite state machine codes */ +#define S_Null 0 +#define S_Pass 1 +#define S_Horiz 2 +#define S_V0 3 +#define S_VR 4 +#define S_VL 5 +#define S_Ext 6 +#define S_TermW 7 +#define S_TermB 8 +#define S_MakeUpW 9 +#define S_MakeUpB 10 +#define S_MakeUp 11 +#define S_EOL 12 + +typedef struct { /* state table entry */ + unsigned char State; /* see above */ + unsigned char Width; /* width of code in bits */ + uint32 Param; /* unsigned 32-bit run length in bits */ +} TIFFFaxTabEnt; + +extern const TIFFFaxTabEnt TIFFFaxMainTable[]; +extern const TIFFFaxTabEnt TIFFFaxWhiteTable[]; +extern const TIFFFaxTabEnt TIFFFaxBlackTable[]; + +/* + * The following macros define the majority of the G3/G4 decoder + * algorithm using the state tables defined elsewhere. To build + * a decoder you need some setup code and some glue code. Note + * that you may also need/want to change the way the NeedBits* + * macros get input data if, for example, you know the data to be + * decoded is properly aligned and oriented (doing so before running + * the decoder can be a big performance win). + * + * Consult the decoder in the TIFF library for an idea of what you + * need to define and setup to make use of these definitions. + * + * NB: to enable a debugging version of these macros define FAX3_DEBUG + * before including this file. Trace output goes to stdout. + */ + +#ifndef EndOfData +#define EndOfData() (cp >= ep) +#endif +/* + * Need <=8 or <=16 bits of input data. Unlike viewfax we + * cannot use/assume a word-aligned, properly bit swizzled + * input data set because data may come from an arbitrarily + * aligned, read-only source such as a memory-mapped file. + * Note also that the viewfax decoder does not check for + * running off the end of the input data buffer. This is + * possible for G3-encoded data because it prescans the input + * data to count EOL markers, but can cause problems for G4 + * data. In any event, we don't prescan and must watch for + * running out of data since we can't permit the library to + * scan past the end of the input data buffer. + * + * Finally, note that we must handle remaindered data at the end + * of a strip specially. The coder asks for a fixed number of + * bits when scanning for the next code. This may be more bits + * than are actually present in the data stream. If we appear + * to run out of data but still have some number of valid bits + * remaining then we makeup the requested amount with zeros and + * return successfully. If the returned data is incorrect then + * we should be called again and get a premature EOF error; + * otherwise we should get the right answer. + */ +#ifndef NeedBits8 +#define NeedBits8(n,eoflab) do { \ + if (BitsAvail < (n)) { \ + if (EndOfData()) { \ + if (BitsAvail == 0) /* no valid bits */ \ + goto eoflab; \ + BitsAvail = (n); /* pad with zeros */ \ + } else { \ + BitAcc |= ((uint32) bitmap[*cp++])<>= (n); \ +} while (0) + +#ifdef FAX3_DEBUG +static const char* StateNames[] = { + "Null ", + "Pass ", + "Horiz ", + "V0 ", + "VR ", + "VL ", + "Ext ", + "TermW ", + "TermB ", + "MakeUpW", + "MakeUpB", + "MakeUp ", + "EOL ", +}; +#define DEBUG_SHOW putchar(BitAcc & (1 << t) ? '1' : '0') +#define LOOKUP8(wid,tab,eoflab) do { \ + int t; \ + NeedBits8(wid,eoflab); \ + TabEnt = tab + GetBits(wid); \ + printf("%08lX/%d: %s%5d\t", (long) BitAcc, BitsAvail, \ + StateNames[TabEnt->State], TabEnt->Param); \ + for (t = 0; t < TabEnt->Width; t++) \ + DEBUG_SHOW; \ + putchar('\n'); \ + fflush(stdout); \ + ClrBits(TabEnt->Width); \ +} while (0) +#define LOOKUP16(wid,tab,eoflab) do { \ + int t; \ + NeedBits16(wid,eoflab); \ + TabEnt = tab + GetBits(wid); \ + printf("%08lX/%d: %s%5d\t", (long) BitAcc, BitsAvail, \ + StateNames[TabEnt->State], TabEnt->Param); \ + for (t = 0; t < TabEnt->Width; t++) \ + DEBUG_SHOW; \ + putchar('\n'); \ + fflush(stdout); \ + ClrBits(TabEnt->Width); \ +} while (0) + +#define SETVALUE(x) do { \ + *pa++ = RunLength + (x); \ + printf("SETVALUE: %d\t%d\n", RunLength + (x), a0); \ + a0 += x; \ + RunLength = 0; \ +} while (0) +#else +#define LOOKUP8(wid,tab,eoflab) do { \ + NeedBits8(wid,eoflab); \ + TabEnt = tab + GetBits(wid); \ + ClrBits(TabEnt->Width); \ +} while (0) +#define LOOKUP16(wid,tab,eoflab) do { \ + NeedBits16(wid,eoflab); \ + TabEnt = tab + GetBits(wid); \ + ClrBits(TabEnt->Width); \ +} while (0) + +/* + * Append a run to the run length array for the + * current row and reset decoding state. + */ +#define SETVALUE(x) do { \ + *pa++ = RunLength + (x); \ + a0 += (x); \ + RunLength = 0; \ +} while (0) +#endif + +/* + * Synchronize input decoding at the start of each + * row by scanning for an EOL (if appropriate) and + * skipping any trash data that might be present + * after a decoding error. Note that the decoding + * done elsewhere that recognizes an EOL only consumes + * 11 consecutive zero bits. This means that if EOLcnt + * is non-zero then we still need to scan for the final flag + * bit that is part of the EOL code. + */ +#define SYNC_EOL(eoflab) do { \ + if (EOLcnt == 0) { \ + for (;;) { \ + NeedBits16(11,eoflab); \ + if (GetBits(11) == 0) \ + break; \ + ClrBits(1); \ + } \ + } \ + for (;;) { \ + NeedBits8(8,eoflab); \ + if (GetBits(8)) \ + break; \ + ClrBits(8); \ + } \ + while (GetBits(1) == 0) \ + ClrBits(1); \ + ClrBits(1); /* EOL bit */ \ + EOLcnt = 0; /* reset EOL counter/flag */ \ +} while (0) + +/* + * Cleanup the array of runs after decoding a row. + * We adjust final runs to insure the user buffer is not + * overwritten and/or undecoded area is white filled. + */ +#define CLEANUP_RUNS() do { \ + if (RunLength) \ + SETVALUE(0); \ + if (a0 != lastx) { \ + badlength(a0, lastx); \ + while (a0 > lastx && pa > thisrun) \ + a0 -= *--pa; \ + if (a0 < lastx) { \ + if (a0 < 0) \ + a0 = 0; \ + if ((pa-thisrun)&1) \ + SETVALUE(0); \ + SETVALUE(lastx - a0); \ + } else if (a0 > lastx) { \ + SETVALUE(lastx); \ + SETVALUE(0); \ + } \ + } \ +} while (0) + +/* + * Decode a line of 1D-encoded data. + * + * The line expanders are written as macros so that they can be reused + * but still have direct access to the local variables of the "calling" + * function. + * + * Note that unlike the original version we have to explicitly test for + * a0 >= lastx after each black/white run is decoded. This is because + * the original code depended on the input data being zero-padded to + * insure the decoder recognized an EOL before running out of data. + */ +#define EXPAND1D(eoflab) do { \ + for (;;) { \ + for (;;) { \ + LOOKUP16(12, TIFFFaxWhiteTable, eof1d); \ + switch (TabEnt->State) { \ + case S_EOL: \ + EOLcnt = 1; \ + goto done1d; \ + case S_TermW: \ + SETVALUE(TabEnt->Param); \ + goto doneWhite1d; \ + case S_MakeUpW: \ + case S_MakeUp: \ + a0 += TabEnt->Param; \ + RunLength += TabEnt->Param; \ + break; \ + default: \ + unexpected("WhiteTable", a0); \ + goto done1d; \ + } \ + } \ + doneWhite1d: \ + if (a0 >= lastx) \ + goto done1d; \ + for (;;) { \ + LOOKUP16(13, TIFFFaxBlackTable, eof1d); \ + switch (TabEnt->State) { \ + case S_EOL: \ + EOLcnt = 1; \ + goto done1d; \ + case S_TermB: \ + SETVALUE(TabEnt->Param); \ + goto doneBlack1d; \ + case S_MakeUpB: \ + case S_MakeUp: \ + a0 += TabEnt->Param; \ + RunLength += TabEnt->Param; \ + break; \ + default: \ + unexpected("BlackTable", a0); \ + goto done1d; \ + } \ + } \ + doneBlack1d: \ + if (a0 >= lastx) \ + goto done1d; \ + if( *(pa-1) == 0 && *(pa-2) == 0 ) \ + pa -= 2; \ + } \ +eof1d: \ + prematureEOF(a0); \ + CLEANUP_RUNS(); \ + goto eoflab; \ +done1d: \ + CLEANUP_RUNS(); \ +} while (0) + +/* + * Update the value of b1 using the array + * of runs for the reference line. + */ +#define CHECK_b1 do { \ + if (pa != thisrun) while (b1 <= a0 && b1 < lastx) { \ + b1 += pb[0] + pb[1]; \ + pb += 2; \ + } \ +} while (0) + +/* + * Expand a row of 2D-encoded data. + */ +#define EXPAND2D(eoflab) do { \ + while (a0 < lastx) { \ + LOOKUP8(7, TIFFFaxMainTable, eof2d); \ + switch (TabEnt->State) { \ + case S_Pass: \ + CHECK_b1; \ + b1 += *pb++; \ + RunLength += b1 - a0; \ + a0 = b1; \ + b1 += *pb++; \ + break; \ + case S_Horiz: \ + if ((pa-thisrun)&1) { \ + for (;;) { /* black first */ \ + LOOKUP16(13, TIFFFaxBlackTable, eof2d); \ + switch (TabEnt->State) { \ + case S_TermB: \ + SETVALUE(TabEnt->Param); \ + goto doneWhite2da; \ + case S_MakeUpB: \ + case S_MakeUp: \ + a0 += TabEnt->Param; \ + RunLength += TabEnt->Param; \ + break; \ + default: \ + goto badBlack2d; \ + } \ + } \ + doneWhite2da:; \ + for (;;) { /* then white */ \ + LOOKUP16(12, TIFFFaxWhiteTable, eof2d); \ + switch (TabEnt->State) { \ + case S_TermW: \ + SETVALUE(TabEnt->Param); \ + goto doneBlack2da; \ + case S_MakeUpW: \ + case S_MakeUp: \ + a0 += TabEnt->Param; \ + RunLength += TabEnt->Param; \ + break; \ + default: \ + goto badWhite2d; \ + } \ + } \ + doneBlack2da:; \ + } else { \ + for (;;) { /* white first */ \ + LOOKUP16(12, TIFFFaxWhiteTable, eof2d); \ + switch (TabEnt->State) { \ + case S_TermW: \ + SETVALUE(TabEnt->Param); \ + goto doneWhite2db; \ + case S_MakeUpW: \ + case S_MakeUp: \ + a0 += TabEnt->Param; \ + RunLength += TabEnt->Param; \ + break; \ + default: \ + goto badWhite2d; \ + } \ + } \ + doneWhite2db:; \ + for (;;) { /* then black */ \ + LOOKUP16(13, TIFFFaxBlackTable, eof2d); \ + switch (TabEnt->State) { \ + case S_TermB: \ + SETVALUE(TabEnt->Param); \ + goto doneBlack2db; \ + case S_MakeUpB: \ + case S_MakeUp: \ + a0 += TabEnt->Param; \ + RunLength += TabEnt->Param; \ + break; \ + default: \ + goto badBlack2d; \ + } \ + } \ + doneBlack2db:; \ + } \ + CHECK_b1; \ + break; \ + case S_V0: \ + CHECK_b1; \ + SETVALUE(b1 - a0); \ + b1 += *pb++; \ + break; \ + case S_VR: \ + CHECK_b1; \ + SETVALUE(b1 - a0 + TabEnt->Param); \ + b1 += *pb++; \ + break; \ + case S_VL: \ + CHECK_b1; \ + if (b1 <= (int) (a0 + TabEnt->Param)) { \ + if (b1 < (int) (a0 + TabEnt->Param) || pa != thisrun) { \ + unexpected("VL", a0); \ + goto eol2d; \ + } \ + } \ + SETVALUE(b1 - a0 - TabEnt->Param); \ + b1 -= *--pb; \ + break; \ + case S_Ext: \ + *pa++ = lastx - a0; \ + extension(a0); \ + goto eol2d; \ + case S_EOL: \ + *pa++ = lastx - a0; \ + NeedBits8(4,eof2d); \ + if (GetBits(4)) \ + unexpected("EOL", a0); \ + ClrBits(4); \ + EOLcnt = 1; \ + goto eol2d; \ + default: \ + badMain2d: \ + unexpected("MainTable", a0); \ + goto eol2d; \ + badBlack2d: \ + unexpected("BlackTable", a0); \ + goto eol2d; \ + badWhite2d: \ + unexpected("WhiteTable", a0); \ + goto eol2d; \ + eof2d: \ + prematureEOF(a0); \ + CLEANUP_RUNS(); \ + goto eoflab; \ + } \ + } \ + if (RunLength) { \ + if (RunLength + a0 < lastx) { \ + /* expect a final V0 */ \ + NeedBits8(1,eof2d); \ + if (!GetBits(1)) \ + goto badMain2d; \ + ClrBits(1); \ + } \ + SETVALUE(0); \ + } \ +eol2d: \ + CLEANUP_RUNS(); \ +} while (0) +#endif /* _FAX3_ */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_fax3sm.c b/Source/LibTIFF4/tif_fax3sm.c index 1e2fe42..822191e 100644 --- a/Source/LibTIFF4/tif_fax3sm.c +++ b/Source/LibTIFF4/tif_fax3sm.c @@ -1,1260 +1,1260 @@ -/* WARNING, this file was automatically generated by the - mkg3states program */ -#include "tiff.h" -#include "tif_fax3.h" - const TIFFFaxTabEnt TIFFFaxMainTable[128] = { -{12,7,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0},{1,4,0},{3,1,0}, -{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0},{5,6,2},{3,1,0},{5,3,1},{3,1,0}, -{2,3,0},{3,1,0},{4,3,1},{3,1,0},{1,4,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0}, -{4,3,1},{3,1,0},{5,7,3},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0}, -{1,4,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0},{4,6,2},{3,1,0}, -{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0},{1,4,0},{3,1,0},{5,3,1},{3,1,0}, -{2,3,0},{3,1,0},{4,3,1},{3,1,0},{6,7,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0}, -{4,3,1},{3,1,0},{1,4,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0}, -{5,6,2},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0},{1,4,0},{3,1,0}, -{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0},{4,7,3},{3,1,0},{5,3,1},{3,1,0}, -{2,3,0},{3,1,0},{4,3,1},{3,1,0},{1,4,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0}, -{4,3,1},{3,1,0},{4,6,2},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0}, -{1,4,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0} -}; - const TIFFFaxTabEnt TIFFFaxWhiteTable[4096] = { -{12,11,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128}, -{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5}, -{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6}, -{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, -{9,9,1472},{7,4,5},{7,8,43},{7,6,17},{9,9,1216},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, -{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7}, -{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,960},{7,4,6},{7,8,31},{7,5,8}, -{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5}, -{7,7,26},{7,5,9},{9,9,704},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4}, -{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6}, -{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,11,1792},{7,4,3}, -{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14}, -{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16}, -{9,9,832},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128}, -{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1600},{7,4,5}, -{7,8,44},{7,6,17},{9,9,1344},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, -{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3}, -{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1088},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9}, -{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7}, -{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8}, -{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5}, -{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4}, -{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6}, -{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3}, -{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15}, -{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1536},{7,4,5},{7,8,43},{7,6,17}, -{9,9,1280},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128}, -{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5}, -{7,8,41},{7,6,16},{9,9,1024},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,768},{7,4,6}, -{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, -{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,11,1856},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, -{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7}, -{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,896},{7,4,6},{7,7,19},{7,5,8}, -{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5}, -{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4}, -{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1728},{7,4,5},{7,8,44},{7,6,17},{9,9,1408},{7,4,6}, -{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3}, -{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14}, -{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16}, -{9,9,1152},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128}, -{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5}, -{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, -{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3}, -{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9}, -{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7}, -{7,6,13},{7,4,3},{9,9,1472},{7,4,5},{7,8,43},{7,6,17},{9,9,1216},{7,4,6},{7,6,1},{7,5,8}, -{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5}, -{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4}, -{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,960},{7,4,6}, -{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3}, -{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,704},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15}, -{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17}, -{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{11,12,2112},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128}, -{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5}, -{7,8,40},{7,6,16},{9,9,832},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6}, -{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, -{9,9,1600},{7,4,5},{7,8,44},{7,6,17},{9,9,1344},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, -{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7}, -{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1088},{7,4,6},{7,8,32},{7,5,8}, -{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5}, -{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4}, -{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6}, -{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3}, -{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14}, -{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16}, -{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128}, -{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1536},{7,4,5}, -{7,8,43},{7,6,17},{9,9,1280},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, -{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3}, -{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,1024},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9}, -{9,9,768},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7}, -{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8}, -{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,12,2368},{7,4,3},{7,5,11},{7,4,5}, -{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4}, -{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,896},{7,4,6}, -{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3}, -{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15}, -{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1728},{7,4,5},{7,8,44},{7,6,17}, -{9,9,1408},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128}, -{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5}, -{7,8,42},{7,6,16},{9,9,1152},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6}, -{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, -{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, -{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7}, -{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8}, -{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5}, -{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4}, -{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1472},{7,4,5},{7,8,43},{7,6,17},{9,9,1216},{7,4,6}, -{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3}, -{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14}, -{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16}, -{9,9,960},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,704},{7,4,6},{7,8,37},{9,5,128}, -{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5}, -{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{11,12,1984},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, -{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3}, -{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,832},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9}, -{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7}, -{7,6,13},{7,4,3},{9,9,1600},{7,4,5},{7,8,44},{7,6,17},{9,9,1344},{7,4,6},{7,6,1},{7,5,8}, -{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5}, -{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4}, -{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1088},{7,4,6}, -{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3}, -{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15}, -{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17}, -{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128}, -{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5}, -{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6}, -{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, -{9,9,1536},{7,4,5},{7,8,43},{7,6,17},{9,9,1280},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, -{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7}, -{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,1024},{7,4,6},{7,8,31},{7,5,8}, -{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5}, -{7,7,26},{7,5,9},{9,9,768},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4}, -{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6}, -{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,11,1920},{7,4,3}, -{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14}, -{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16}, -{9,9,896},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128}, -{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1728},{7,4,5}, -{7,8,44},{7,6,17},{9,9,1408},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, -{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3}, -{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1152},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9}, -{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7}, -{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8}, -{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5}, -{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4}, -{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6}, -{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3}, -{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15}, -{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1472},{7,4,5},{7,8,43},{7,6,17}, -{9,9,1216},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128}, -{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5}, -{7,8,41},{7,6,16},{9,9,960},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,704},{7,4,6}, -{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, -{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,12,2240},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, -{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7}, -{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,832},{7,4,6},{7,7,19},{7,5,8}, -{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5}, -{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4}, -{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1600},{7,4,5},{7,8,44},{7,6,17},{9,9,1344},{7,4,6}, -{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3}, -{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14}, -{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16}, -{9,9,1088},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128}, -{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5}, -{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, -{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3}, -{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9}, -{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7}, -{7,6,13},{7,4,3},{9,9,1536},{7,4,5},{7,8,43},{7,6,17},{9,9,1280},{7,4,6},{7,6,1},{7,5,8}, -{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5}, -{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4}, -{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,1024},{7,4,6}, -{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3}, -{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,768},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15}, -{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17}, -{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{11,12,2496},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128}, -{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5}, -{7,8,40},{7,6,16},{9,9,896},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6}, -{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, -{9,9,1728},{7,4,5},{7,8,44},{7,6,17},{9,9,1408},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, -{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7}, -{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1152},{7,4,6},{7,8,32},{7,5,8}, -{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5}, -{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4}, -{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6}, -{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{12,11,0},{7,4,3}, -{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14}, -{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16}, -{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128}, -{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1472},{7,4,5}, -{7,8,43},{7,6,17},{9,9,1216},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, -{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3}, -{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,960},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9}, -{9,9,704},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7}, -{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8}, -{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,11,1792},{7,4,3},{7,5,11},{7,4,5}, -{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4}, -{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,832},{7,4,6}, -{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3}, -{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15}, -{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1600},{7,4,5},{7,8,44},{7,6,17}, -{9,9,1344},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128}, -{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5}, -{7,8,42},{7,6,16},{9,9,1088},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6}, -{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, -{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, -{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7}, -{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8}, -{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5}, -{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4}, -{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1536},{7,4,5},{7,8,43},{7,6,17},{9,9,1280},{7,4,6}, -{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3}, -{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14}, -{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16}, -{9,9,1024},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,768},{7,4,6},{7,8,37},{9,5,128}, -{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5}, -{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{11,11,1856},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, -{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3}, -{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,896},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9}, -{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7}, -{7,6,13},{7,4,3},{9,9,1728},{7,4,5},{7,8,44},{7,6,17},{9,9,1408},{7,4,6},{7,6,1},{7,5,8}, -{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5}, -{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4}, -{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1152},{7,4,6}, -{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3}, -{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15}, -{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17}, -{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128}, -{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5}, -{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6}, -{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, -{9,9,1472},{7,4,5},{7,8,43},{7,6,17},{9,9,1216},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, -{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7}, -{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,960},{7,4,6},{7,8,31},{7,5,8}, -{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5}, -{7,7,26},{7,5,9},{9,9,704},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4}, -{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6}, -{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,12,2176},{7,4,3}, -{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14}, -{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16}, -{9,9,832},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128}, -{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1600},{7,4,5}, -{7,8,44},{7,6,17},{9,9,1344},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, -{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3}, -{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1088},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9}, -{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7}, -{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8}, -{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5}, -{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4}, -{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6}, -{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3}, -{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15}, -{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1536},{7,4,5},{7,8,43},{7,6,17}, -{9,9,1280},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128}, -{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5}, -{7,8,41},{7,6,16},{9,9,1024},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,768},{7,4,6}, -{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, -{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,12,2432},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, -{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7}, -{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,896},{7,4,6},{7,7,19},{7,5,8}, -{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5}, -{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4}, -{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1728},{7,4,5},{7,8,44},{7,6,17},{9,9,1408},{7,4,6}, -{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3}, -{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14}, -{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16}, -{9,9,1152},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128}, -{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5}, -{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, -{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3}, -{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9}, -{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7}, -{7,6,13},{7,4,3},{9,9,1472},{7,4,5},{7,8,43},{7,6,17},{9,9,1216},{7,4,6},{7,6,1},{7,5,8}, -{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5}, -{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4}, -{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,960},{7,4,6}, -{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3}, -{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,704},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15}, -{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17}, -{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{11,12,2048},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128}, -{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5}, -{7,8,40},{7,6,16},{9,9,832},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6}, -{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, -{9,9,1600},{7,4,5},{7,8,44},{7,6,17},{9,9,1344},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, -{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7}, -{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1088},{7,4,6},{7,8,32},{7,5,8}, -{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5}, -{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4}, -{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6}, -{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3}, -{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14}, -{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16}, -{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128}, -{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1536},{7,4,5}, -{7,8,43},{7,6,17},{9,9,1280},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, -{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3}, -{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,1024},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9}, -{9,9,768},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7}, -{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8}, -{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,11,1920},{7,4,3},{7,5,11},{7,4,5}, -{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4}, -{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,896},{7,4,6}, -{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3}, -{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15}, -{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1728},{7,4,5},{7,8,44},{7,6,17}, -{9,9,1408},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128}, -{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5}, -{7,8,42},{7,6,16},{9,9,1152},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6}, -{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, -{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, -{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7}, -{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8}, -{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5}, -{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4}, -{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1472},{7,4,5},{7,8,43},{7,6,17},{9,9,1216},{7,4,6}, -{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3}, -{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14}, -{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16}, -{9,9,960},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,704},{7,4,6},{7,8,37},{9,5,128}, -{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5}, -{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{11,12,2304},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, -{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3}, -{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,832},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9}, -{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7}, -{7,6,13},{7,4,3},{9,9,1600},{7,4,5},{7,8,44},{7,6,17},{9,9,1344},{7,4,6},{7,6,1},{7,5,8}, -{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5}, -{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4}, -{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1088},{7,4,6}, -{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3}, -{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15}, -{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17}, -{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128}, -{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5}, -{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6}, -{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, -{9,9,1536},{7,4,5},{7,8,43},{7,6,17},{9,9,1280},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, -{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7}, -{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,1024},{7,4,6},{7,8,31},{7,5,8}, -{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5}, -{7,7,26},{7,5,9},{9,9,768},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4}, -{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6}, -{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,12,2560},{7,4,3}, -{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14}, -{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16}, -{9,9,896},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, -{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128}, -{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1728},{7,4,5}, -{7,8,44},{7,6,17},{9,9,1408},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, -{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, -{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3}, -{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1152},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64}, -{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9}, -{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7}, -{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8}, -{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7} -}; - const TIFFFaxTabEnt TIFFFaxBlackTable[8192] = { -{12,11,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,18},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,17},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1792},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,11,23},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,20},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,11,25},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,12,128},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,12,56},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,30},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1856},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,57},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,11,21},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,54},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,52},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,48},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{11,12,2112},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,44},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,36},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,12,384},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,28},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,60},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,40},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2368},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,16},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{10,10,64},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,18},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,10,17},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{11,12,1984},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,50},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,12,34},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,1664},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,26},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,1408},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,32},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1920},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,12,61},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,42},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{10,13,1024},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{10,13,768},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,62},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2240},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,46},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,38},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,512},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,11,19},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,24},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,22},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{11,12,2496},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,10,16},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,0},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,10,64},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{12,11,0},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,10,18},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,17},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1792},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,23},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,20},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,11,25},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{10,12,192},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,1280},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,12,31},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{11,11,1856},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,58},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,11,21},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,896},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,640},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,49},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2176},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,12,45},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,37},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{10,12,448},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,29},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{10,13,1536},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,41},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2432},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,16},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,10,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,10,64},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,18},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,17},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{11,12,2048},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,51},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,35},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,12,320},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,27},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,59},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,33},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1920},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,12,256},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,43},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{10,13,1152},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,55},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,12,63},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{11,12,2304},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,47},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,12,39},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,53},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,19},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,24},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,22},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2560},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,10,16},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,0},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{10,10,64},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{12,11,0},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,10,18},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,10,17},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1792},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,23},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,11,20},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,25},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{10,12,128},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,56},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,30},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{11,11,1856},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,57},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,21},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,54},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,52},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,48},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2112},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,44},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,36},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{10,12,384},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,28},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,60},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,12,40},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{11,12,2368},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,16},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,10,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,10,64},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,18},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,17},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,1984},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,12,50},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,34},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{10,13,1728},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,26},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{10,13,1472},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,32},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1920},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,61},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,42},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,1088},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,832},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,62},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{11,12,2240},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,46},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,38},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,576},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,19},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,11,24},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,22},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2496},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,16},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{10,10,64},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{12,11,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,18},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,10,17},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{11,11,1792},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,23},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,11,20},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,25},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,12,192},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,1344},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,31},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1856},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,12,58},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,21},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{10,13,960},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{10,13,704},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,49},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2176},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,45},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,37},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,12,448},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,12,29},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,1600},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,41},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{11,12,2432},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,10,16},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,0},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,10,64},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,10,18},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,17},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2048},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,51},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,35},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{10,12,320},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,27},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,59},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,12,33},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{11,11,1920},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,12,256},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,12,43},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,1216},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,55},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,63},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2304},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,12,47},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,39},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,12,53},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,19},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,11,24},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,11,22},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2560},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,16},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2},{8,10,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, -{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,10,64},{8,2,3}, -{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, -{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, -{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, -{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, -{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, -{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, -{8,3,4},{8,2,2} -}; -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* WARNING, this file was automatically generated by the + mkg3states program */ +#include "tiff.h" +#include "tif_fax3.h" + const TIFFFaxTabEnt TIFFFaxMainTable[128] = { +{12,7,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0},{1,4,0},{3,1,0}, +{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0},{5,6,2},{3,1,0},{5,3,1},{3,1,0}, +{2,3,0},{3,1,0},{4,3,1},{3,1,0},{1,4,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0}, +{4,3,1},{3,1,0},{5,7,3},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0}, +{1,4,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0},{4,6,2},{3,1,0}, +{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0},{1,4,0},{3,1,0},{5,3,1},{3,1,0}, +{2,3,0},{3,1,0},{4,3,1},{3,1,0},{6,7,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0}, +{4,3,1},{3,1,0},{1,4,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0}, +{5,6,2},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0},{1,4,0},{3,1,0}, +{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0},{4,7,3},{3,1,0},{5,3,1},{3,1,0}, +{2,3,0},{3,1,0},{4,3,1},{3,1,0},{1,4,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0}, +{4,3,1},{3,1,0},{4,6,2},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0}, +{1,4,0},{3,1,0},{5,3,1},{3,1,0},{2,3,0},{3,1,0},{4,3,1},{3,1,0} +}; + const TIFFFaxTabEnt TIFFFaxWhiteTable[4096] = { +{12,11,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128}, +{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5}, +{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6}, +{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, +{9,9,1472},{7,4,5},{7,8,43},{7,6,17},{9,9,1216},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, +{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7}, +{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,960},{7,4,6},{7,8,31},{7,5,8}, +{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5}, +{7,7,26},{7,5,9},{9,9,704},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4}, +{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6}, +{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,11,1792},{7,4,3}, +{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14}, +{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16}, +{9,9,832},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128}, +{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1600},{7,4,5}, +{7,8,44},{7,6,17},{9,9,1344},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, +{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3}, +{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1088},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9}, +{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7}, +{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8}, +{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5}, +{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4}, +{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6}, +{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3}, +{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15}, +{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1536},{7,4,5},{7,8,43},{7,6,17}, +{9,9,1280},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128}, +{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5}, +{7,8,41},{7,6,16},{9,9,1024},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,768},{7,4,6}, +{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, +{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,11,1856},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, +{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7}, +{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,896},{7,4,6},{7,7,19},{7,5,8}, +{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5}, +{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4}, +{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1728},{7,4,5},{7,8,44},{7,6,17},{9,9,1408},{7,4,6}, +{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3}, +{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14}, +{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16}, +{9,9,1152},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128}, +{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5}, +{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, +{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3}, +{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9}, +{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7}, +{7,6,13},{7,4,3},{9,9,1472},{7,4,5},{7,8,43},{7,6,17},{9,9,1216},{7,4,6},{7,6,1},{7,5,8}, +{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5}, +{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4}, +{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,960},{7,4,6}, +{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3}, +{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,704},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15}, +{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17}, +{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{11,12,2112},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128}, +{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5}, +{7,8,40},{7,6,16},{9,9,832},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6}, +{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, +{9,9,1600},{7,4,5},{7,8,44},{7,6,17},{9,9,1344},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, +{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7}, +{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1088},{7,4,6},{7,8,32},{7,5,8}, +{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5}, +{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4}, +{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6}, +{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3}, +{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14}, +{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16}, +{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128}, +{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1536},{7,4,5}, +{7,8,43},{7,6,17},{9,9,1280},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, +{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3}, +{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,1024},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9}, +{9,9,768},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7}, +{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8}, +{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,12,2368},{7,4,3},{7,5,11},{7,4,5}, +{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4}, +{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,896},{7,4,6}, +{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3}, +{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15}, +{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1728},{7,4,5},{7,8,44},{7,6,17}, +{9,9,1408},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128}, +{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5}, +{7,8,42},{7,6,16},{9,9,1152},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6}, +{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, +{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, +{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7}, +{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8}, +{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5}, +{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4}, +{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1472},{7,4,5},{7,8,43},{7,6,17},{9,9,1216},{7,4,6}, +{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3}, +{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14}, +{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16}, +{9,9,960},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,704},{7,4,6},{7,8,37},{9,5,128}, +{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5}, +{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{11,12,1984},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, +{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3}, +{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,832},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9}, +{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7}, +{7,6,13},{7,4,3},{9,9,1600},{7,4,5},{7,8,44},{7,6,17},{9,9,1344},{7,4,6},{7,6,1},{7,5,8}, +{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5}, +{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4}, +{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1088},{7,4,6}, +{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3}, +{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15}, +{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17}, +{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128}, +{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5}, +{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6}, +{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, +{9,9,1536},{7,4,5},{7,8,43},{7,6,17},{9,9,1280},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, +{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7}, +{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,1024},{7,4,6},{7,8,31},{7,5,8}, +{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5}, +{7,7,26},{7,5,9},{9,9,768},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4}, +{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6}, +{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,11,1920},{7,4,3}, +{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14}, +{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16}, +{9,9,896},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128}, +{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1728},{7,4,5}, +{7,8,44},{7,6,17},{9,9,1408},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, +{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3}, +{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1152},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9}, +{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7}, +{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8}, +{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5}, +{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4}, +{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6}, +{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3}, +{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15}, +{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1472},{7,4,5},{7,8,43},{7,6,17}, +{9,9,1216},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128}, +{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5}, +{7,8,41},{7,6,16},{9,9,960},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,704},{7,4,6}, +{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, +{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,12,2240},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, +{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7}, +{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,832},{7,4,6},{7,7,19},{7,5,8}, +{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5}, +{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4}, +{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1600},{7,4,5},{7,8,44},{7,6,17},{9,9,1344},{7,4,6}, +{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3}, +{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14}, +{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16}, +{9,9,1088},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128}, +{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5}, +{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, +{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3}, +{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9}, +{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7}, +{7,6,13},{7,4,3},{9,9,1536},{7,4,5},{7,8,43},{7,6,17},{9,9,1280},{7,4,6},{7,6,1},{7,5,8}, +{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5}, +{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4}, +{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,1024},{7,4,6}, +{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3}, +{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,768},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15}, +{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17}, +{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{11,12,2496},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128}, +{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5}, +{7,8,40},{7,6,16},{9,9,896},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6}, +{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, +{9,9,1728},{7,4,5},{7,8,44},{7,6,17},{9,9,1408},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, +{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7}, +{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1152},{7,4,6},{7,8,32},{7,5,8}, +{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5}, +{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4}, +{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6}, +{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{12,11,0},{7,4,3}, +{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14}, +{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16}, +{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128}, +{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1472},{7,4,5}, +{7,8,43},{7,6,17},{9,9,1216},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, +{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3}, +{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,960},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9}, +{9,9,704},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7}, +{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8}, +{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,11,1792},{7,4,3},{7,5,11},{7,4,5}, +{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4}, +{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,832},{7,4,6}, +{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3}, +{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15}, +{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1600},{7,4,5},{7,8,44},{7,6,17}, +{9,9,1344},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128}, +{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5}, +{7,8,42},{7,6,16},{9,9,1088},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6}, +{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, +{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, +{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7}, +{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8}, +{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5}, +{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4}, +{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1536},{7,4,5},{7,8,43},{7,6,17},{9,9,1280},{7,4,6}, +{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3}, +{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14}, +{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16}, +{9,9,1024},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,768},{7,4,6},{7,8,37},{9,5,128}, +{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5}, +{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{11,11,1856},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, +{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3}, +{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,896},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9}, +{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7}, +{7,6,13},{7,4,3},{9,9,1728},{7,4,5},{7,8,44},{7,6,17},{9,9,1408},{7,4,6},{7,6,1},{7,5,8}, +{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5}, +{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4}, +{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1152},{7,4,6}, +{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3}, +{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15}, +{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17}, +{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128}, +{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5}, +{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6}, +{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, +{9,9,1472},{7,4,5},{7,8,43},{7,6,17},{9,9,1216},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, +{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7}, +{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,960},{7,4,6},{7,8,31},{7,5,8}, +{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5}, +{7,7,26},{7,5,9},{9,9,704},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4}, +{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6}, +{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,12,2176},{7,4,3}, +{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14}, +{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16}, +{9,9,832},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128}, +{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1600},{7,4,5}, +{7,8,44},{7,6,17},{9,9,1344},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, +{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3}, +{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1088},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9}, +{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7}, +{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8}, +{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5}, +{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4}, +{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6}, +{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3}, +{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15}, +{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1536},{7,4,5},{7,8,43},{7,6,17}, +{9,9,1280},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128}, +{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5}, +{7,8,41},{7,6,16},{9,9,1024},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,768},{7,4,6}, +{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, +{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,12,2432},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, +{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7}, +{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,896},{7,4,6},{7,7,19},{7,5,8}, +{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5}, +{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4}, +{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1728},{7,4,5},{7,8,44},{7,6,17},{9,9,1408},{7,4,6}, +{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3}, +{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14}, +{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16}, +{9,9,1152},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128}, +{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5}, +{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, +{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3}, +{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9}, +{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7}, +{7,6,13},{7,4,3},{9,9,1472},{7,4,5},{7,8,43},{7,6,17},{9,9,1216},{7,4,6},{7,6,1},{7,5,8}, +{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5}, +{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4}, +{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,960},{7,4,6}, +{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3}, +{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,704},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15}, +{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17}, +{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{11,12,2048},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128}, +{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5}, +{7,8,40},{7,6,16},{9,9,832},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6}, +{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, +{9,9,1600},{7,4,5},{7,8,44},{7,6,17},{9,9,1344},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, +{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7}, +{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1088},{7,4,6},{7,8,32},{7,5,8}, +{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5}, +{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4}, +{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6}, +{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3}, +{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14}, +{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16}, +{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128}, +{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1536},{7,4,5}, +{7,8,43},{7,6,17},{9,9,1280},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, +{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3}, +{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,1024},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9}, +{9,9,768},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7}, +{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8}, +{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,11,1920},{7,4,3},{7,5,11},{7,4,5}, +{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4}, +{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,896},{7,4,6}, +{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3}, +{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15}, +{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1728},{7,4,5},{7,8,44},{7,6,17}, +{9,9,1408},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128}, +{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5}, +{7,8,42},{7,6,16},{9,9,1152},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6}, +{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, +{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, +{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7}, +{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8}, +{7,8,55},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5}, +{7,8,53},{7,5,9},{9,8,448},{7,4,6},{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4}, +{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1472},{7,4,5},{7,8,43},{7,6,17},{9,9,1216},{7,4,6}, +{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3}, +{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14}, +{7,8,61},{7,4,4},{7,4,2},{7,4,7},{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16}, +{9,9,960},{7,4,6},{7,8,31},{7,5,8},{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,9,704},{7,4,6},{7,8,37},{9,5,128}, +{7,7,25},{7,6,15},{9,8,320},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5}, +{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{11,12,2304},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, +{7,7,20},{9,5,128},{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3}, +{7,7,27},{7,4,5},{7,8,40},{7,6,16},{9,9,832},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9}, +{9,8,512},{7,4,6},{7,8,36},{9,5,128},{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7}, +{7,6,13},{7,4,3},{9,9,1600},{7,4,5},{7,8,44},{7,6,17},{9,9,1344},{7,4,6},{7,6,1},{7,5,8}, +{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5}, +{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4}, +{7,4,2},{7,4,7},{7,8,48},{7,4,3},{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1088},{7,4,6}, +{7,8,32},{7,5,8},{7,8,58},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3}, +{7,5,11},{7,4,5},{7,7,26},{7,5,9},{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15}, +{9,8,384},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17}, +{9,7,256},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{0,0,0},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128}, +{7,7,24},{7,6,14},{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5}, +{7,8,39},{7,6,16},{9,8,576},{7,4,6},{7,7,19},{7,5,8},{7,8,55},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,8,45},{7,4,3},{7,5,11},{7,4,5},{7,8,53},{7,5,9},{9,8,448},{7,4,6}, +{7,8,35},{9,5,128},{7,8,51},{7,6,15},{7,8,63},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3}, +{9,9,1536},{7,4,5},{7,8,43},{7,6,17},{9,9,1280},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,8,29},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9}, +{9,6,1664},{7,4,6},{7,8,33},{9,5,128},{7,8,49},{7,6,14},{7,8,61},{7,4,4},{7,4,2},{7,4,7}, +{7,8,47},{7,4,3},{7,8,59},{7,4,5},{7,8,41},{7,6,16},{9,9,1024},{7,4,6},{7,8,31},{7,5,8}, +{7,8,57},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5}, +{7,7,26},{7,5,9},{9,9,768},{7,4,6},{7,8,37},{9,5,128},{7,7,25},{7,6,15},{9,8,320},{7,4,4}, +{7,4,2},{7,4,7},{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6}, +{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7},{11,12,2560},{7,4,3}, +{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6},{7,7,20},{9,5,128},{7,7,24},{7,6,14}, +{7,7,28},{7,4,4},{7,4,2},{7,4,7},{7,7,23},{7,4,3},{7,7,27},{7,4,5},{7,8,40},{7,6,16}, +{9,9,896},{7,4,6},{7,7,19},{7,5,8},{7,8,56},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7}, +{7,8,46},{7,4,3},{7,5,11},{7,4,5},{7,8,54},{7,5,9},{9,8,512},{7,4,6},{7,8,36},{9,5,128}, +{7,8,52},{7,6,15},{7,8,0},{7,4,4},{7,4,2},{7,4,7},{7,6,13},{7,4,3},{9,9,1728},{7,4,5}, +{7,8,44},{7,6,17},{9,9,1408},{7,4,6},{7,6,1},{7,5,8},{9,6,192},{9,5,64},{7,5,10},{7,4,4}, +{7,4,2},{7,4,7},{7,8,30},{7,4,3},{7,5,11},{7,4,5},{7,6,12},{7,5,9},{9,6,1664},{7,4,6}, +{7,8,34},{9,5,128},{7,8,50},{7,6,14},{7,8,62},{7,4,4},{7,4,2},{7,4,7},{7,8,48},{7,4,3}, +{7,8,60},{7,4,5},{7,8,42},{7,6,16},{9,9,1152},{7,4,6},{7,8,32},{7,5,8},{7,8,58},{9,5,64}, +{7,5,10},{7,4,4},{7,4,2},{7,4,7},{7,7,22},{7,4,3},{7,5,11},{7,4,5},{7,7,26},{7,5,9}, +{9,8,640},{7,4,6},{7,8,38},{9,5,128},{7,7,25},{7,6,15},{9,8,384},{7,4,4},{7,4,2},{7,4,7}, +{7,6,13},{7,4,3},{7,7,18},{7,4,5},{7,7,21},{7,6,17},{9,7,256},{7,4,6},{7,6,1},{7,5,8}, +{9,6,192},{9,5,64},{7,5,10},{7,4,4},{7,4,2},{7,4,7} +}; + const TIFFFaxTabEnt TIFFFaxBlackTable[8192] = { +{12,11,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,18},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,17},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1792},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,11,23},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,20},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,11,25},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,12,128},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,12,56},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,30},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1856},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,57},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,11,21},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,54},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,52},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,48},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{11,12,2112},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,44},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,36},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,12,384},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,28},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,60},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,40},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2368},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,16},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{10,10,64},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,18},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,10,17},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{11,12,1984},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,50},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,12,34},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,1664},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,26},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,1408},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,32},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1920},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,12,61},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,42},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{10,13,1024},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{10,13,768},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,62},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2240},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,46},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,38},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,512},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,11,19},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,24},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,22},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{11,12,2496},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,10,16},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,0},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,10,64},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{12,11,0},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,10,18},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,17},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1792},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,23},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,20},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,11,25},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{10,12,192},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,1280},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,12,31},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{11,11,1856},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,58},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,11,21},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,896},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,640},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,49},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2176},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,12,45},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,37},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{10,12,448},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,29},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{10,13,1536},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,41},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2432},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,16},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,10,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,10,64},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,18},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,17},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{11,12,2048},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,51},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,35},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,12,320},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,27},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,59},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,33},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1920},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,12,256},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,43},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{10,13,1152},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,55},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,12,63},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{11,12,2304},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,47},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,12,39},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,53},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,19},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,24},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,22},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2560},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,10,16},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,0},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{10,10,64},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{12,11,0},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,10,18},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,10,17},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1792},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,23},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,11,20},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,25},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{10,12,128},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,56},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,30},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{11,11,1856},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,57},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,21},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,54},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,52},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,48},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2112},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,44},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,36},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{10,12,384},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,28},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,60},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,12,40},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{11,12,2368},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,16},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,10,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,10,64},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,18},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,17},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,1984},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,12,50},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,34},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{10,13,1728},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,26},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{10,13,1472},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,32},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1920},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,61},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,42},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,1088},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,832},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,62},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{11,12,2240},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,46},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,38},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,576},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,19},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,11,24},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,22},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2496},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,16},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{10,10,64},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{12,11,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,18},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,10,17},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{11,11,1792},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,23},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,11,20},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,25},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,12,192},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,1344},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,31},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,11,1856},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,12,58},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,21},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{10,13,960},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{10,13,704},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,49},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2176},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,45},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,37},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,12,448},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,12,29},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,1600},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,41},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{11,12,2432},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,10,16},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,0},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,10,64},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,10,18},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,17},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2048},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,51},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,35},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{10,12,320},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,27},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,59},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,12,33},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{11,11,1920},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,12,256},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,12,43},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,13,1216},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{0,0,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,8,13},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,9,15},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,55},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,63},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2304},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,12,47},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,12,39},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,12,53},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,12},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{0,0,0},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,8,13},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,11,19},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,11,24},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,11,22},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{11,12,2560},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,7,10},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,10,16},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2},{8,10,0},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2}, +{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{10,10,64},{8,2,3}, +{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,9},{8,2,3},{8,3,1},{8,2,2}, +{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,11},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3}, +{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2}, +{8,8,14},{8,2,3},{8,3,1},{8,2,2},{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,6,8},{8,2,3}, +{8,3,1},{8,2,2},{8,4,5},{8,2,3},{8,3,4},{8,2,2},{8,7,12},{8,2,3},{8,3,1},{8,2,2}, +{8,4,6},{8,2,3},{8,3,4},{8,2,2},{8,5,7},{8,2,3},{8,3,1},{8,2,2},{8,4,5},{8,2,3}, +{8,3,4},{8,2,2} +}; +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_flush.c b/Source/LibTIFF4/tif_flush.c index 50b4ec5..1301e89 100644 --- a/Source/LibTIFF4/tif_flush.c +++ b/Source/LibTIFF4/tif_flush.c @@ -1,118 +1,118 @@ -/* $Id: tif_flush.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - */ -#include "tiffiop.h" - -int -TIFFFlush(TIFF* tif) -{ - if( tif->tif_mode == O_RDONLY ) - return 1; - - if (!TIFFFlushData(tif)) - return (0); - - /* In update (r+) mode we try to detect the case where - only the strip/tile map has been altered, and we try to - rewrite only that portion of the directory without - making any other changes */ - - if( (tif->tif_flags & TIFF_DIRTYSTRIP) - && !(tif->tif_flags & TIFF_DIRTYDIRECT) - && tif->tif_mode == O_RDWR ) - { - uint64 *offsets=NULL, *sizes=NULL; - - if( TIFFIsTiled(tif) ) - { - if( TIFFGetField( tif, TIFFTAG_TILEOFFSETS, &offsets ) - && TIFFGetField( tif, TIFFTAG_TILEBYTECOUNTS, &sizes ) - && _TIFFRewriteField( tif, TIFFTAG_TILEOFFSETS, TIFF_LONG8, - tif->tif_dir.td_nstrips, offsets ) - && _TIFFRewriteField( tif, TIFFTAG_TILEBYTECOUNTS, TIFF_LONG8, - tif->tif_dir.td_nstrips, sizes ) ) - { - tif->tif_flags &= ~TIFF_DIRTYSTRIP; - tif->tif_flags &= ~TIFF_BEENWRITING; - return 1; - } - } - else - { - if( TIFFGetField( tif, TIFFTAG_STRIPOFFSETS, &offsets ) - && TIFFGetField( tif, TIFFTAG_STRIPBYTECOUNTS, &sizes ) - && _TIFFRewriteField( tif, TIFFTAG_STRIPOFFSETS, TIFF_LONG8, - tif->tif_dir.td_nstrips, offsets ) - && _TIFFRewriteField( tif, TIFFTAG_STRIPBYTECOUNTS, TIFF_LONG8, - tif->tif_dir.td_nstrips, sizes ) ) - { - tif->tif_flags &= ~TIFF_DIRTYSTRIP; - tif->tif_flags &= ~TIFF_BEENWRITING; - return 1; - } - } - } - - if ((tif->tif_flags & (TIFF_DIRTYDIRECT|TIFF_DIRTYSTRIP)) - && !TIFFRewriteDirectory(tif)) - return (0); - - return (1); -} - -/* - * Flush buffered data to the file. - * - * Frank Warmerdam'2000: I modified this to return 1 if TIFF_BEENWRITING - * is not set, so that TIFFFlush() will proceed to write out the directory. - * The documentation says returning 1 is an error indicator, but not having - * been writing isn't exactly a an error. Hopefully this doesn't cause - * problems for other people. - */ -int -TIFFFlushData(TIFF* tif) -{ - if ((tif->tif_flags & TIFF_BEENWRITING) == 0) - return (1); - if (tif->tif_flags & TIFF_POSTENCODE) { - tif->tif_flags &= ~TIFF_POSTENCODE; - if (!(*tif->tif_postencode)(tif)) - return (0); - } - return (TIFFFlushData1(tif)); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_flush.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + */ +#include "tiffiop.h" + +int +TIFFFlush(TIFF* tif) +{ + if( tif->tif_mode == O_RDONLY ) + return 1; + + if (!TIFFFlushData(tif)) + return (0); + + /* In update (r+) mode we try to detect the case where + only the strip/tile map has been altered, and we try to + rewrite only that portion of the directory without + making any other changes */ + + if( (tif->tif_flags & TIFF_DIRTYSTRIP) + && !(tif->tif_flags & TIFF_DIRTYDIRECT) + && tif->tif_mode == O_RDWR ) + { + uint64 *offsets=NULL, *sizes=NULL; + + if( TIFFIsTiled(tif) ) + { + if( TIFFGetField( tif, TIFFTAG_TILEOFFSETS, &offsets ) + && TIFFGetField( tif, TIFFTAG_TILEBYTECOUNTS, &sizes ) + && _TIFFRewriteField( tif, TIFFTAG_TILEOFFSETS, TIFF_LONG8, + tif->tif_dir.td_nstrips, offsets ) + && _TIFFRewriteField( tif, TIFFTAG_TILEBYTECOUNTS, TIFF_LONG8, + tif->tif_dir.td_nstrips, sizes ) ) + { + tif->tif_flags &= ~TIFF_DIRTYSTRIP; + tif->tif_flags &= ~TIFF_BEENWRITING; + return 1; + } + } + else + { + if( TIFFGetField( tif, TIFFTAG_STRIPOFFSETS, &offsets ) + && TIFFGetField( tif, TIFFTAG_STRIPBYTECOUNTS, &sizes ) + && _TIFFRewriteField( tif, TIFFTAG_STRIPOFFSETS, TIFF_LONG8, + tif->tif_dir.td_nstrips, offsets ) + && _TIFFRewriteField( tif, TIFFTAG_STRIPBYTECOUNTS, TIFF_LONG8, + tif->tif_dir.td_nstrips, sizes ) ) + { + tif->tif_flags &= ~TIFF_DIRTYSTRIP; + tif->tif_flags &= ~TIFF_BEENWRITING; + return 1; + } + } + } + + if ((tif->tif_flags & (TIFF_DIRTYDIRECT|TIFF_DIRTYSTRIP)) + && !TIFFRewriteDirectory(tif)) + return (0); + + return (1); +} + +/* + * Flush buffered data to the file. + * + * Frank Warmerdam'2000: I modified this to return 1 if TIFF_BEENWRITING + * is not set, so that TIFFFlush() will proceed to write out the directory. + * The documentation says returning 1 is an error indicator, but not having + * been writing isn't exactly a an error. Hopefully this doesn't cause + * problems for other people. + */ +int +TIFFFlushData(TIFF* tif) +{ + if ((tif->tif_flags & TIFF_BEENWRITING) == 0) + return (1); + if (tif->tif_flags & TIFF_POSTENCODE) { + tif->tif_flags &= ~TIFF_POSTENCODE; + if (!(*tif->tif_postencode)(tif)) + return (0); + } + return (TIFFFlushData1(tif)); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_getimage.c b/Source/LibTIFF4/tif_getimage.c index dc06f30..effe592 100644 --- a/Source/LibTIFF4/tif_getimage.c +++ b/Source/LibTIFF4/tif_getimage.c @@ -1,2867 +1,2867 @@ -/* $Id: tif_getimage.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1991-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library - * - * Read and return a packed RGBA image. - */ -#include "tiffiop.h" -#include - -static int gtTileContig(TIFFRGBAImage*, uint32*, uint32, uint32); -static int gtTileSeparate(TIFFRGBAImage*, uint32*, uint32, uint32); -static int gtStripContig(TIFFRGBAImage*, uint32*, uint32, uint32); -static int gtStripSeparate(TIFFRGBAImage*, uint32*, uint32, uint32); -static int PickContigCase(TIFFRGBAImage*); -static int PickSeparateCase(TIFFRGBAImage*); - -static int BuildMapUaToAa(TIFFRGBAImage* img); -static int BuildMapBitdepth16To8(TIFFRGBAImage* img); - -static const char photoTag[] = "PhotometricInterpretation"; - -/* - * Helper constants used in Orientation tag handling - */ -#define FLIP_VERTICALLY 0x01 -#define FLIP_HORIZONTALLY 0x02 - -/* - * Color conversion constants. We will define display types here. - */ - -static const TIFFDisplay display_sRGB = { - { /* XYZ -> luminance matrix */ - { 3.2410F, -1.5374F, -0.4986F }, - { -0.9692F, 1.8760F, 0.0416F }, - { 0.0556F, -0.2040F, 1.0570F } - }, - 100.0F, 100.0F, 100.0F, /* Light o/p for reference white */ - 255, 255, 255, /* Pixel values for ref. white */ - 1.0F, 1.0F, 1.0F, /* Residual light o/p for black pixel */ - 2.4F, 2.4F, 2.4F, /* Gamma values for the three guns */ -}; - -/* - * Check the image to see if TIFFReadRGBAImage can deal with it. - * 1/0 is returned according to whether or not the image can - * be handled. If 0 is returned, emsg contains the reason - * why it is being rejected. - */ -int -TIFFRGBAImageOK(TIFF* tif, char emsg[1024]) -{ - TIFFDirectory* td = &tif->tif_dir; - uint16 photometric; - int colorchannels; - - if (!tif->tif_decodestatus) { - sprintf(emsg, "Sorry, requested compression method is not configured"); - return (0); - } - switch (td->td_bitspersample) { - case 1: - case 2: - case 4: - case 8: - case 16: - break; - default: - sprintf(emsg, "Sorry, can not handle images with %d-bit samples", - td->td_bitspersample); - return (0); - } - colorchannels = td->td_samplesperpixel - td->td_extrasamples; - if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric)) { - switch (colorchannels) { - case 1: - photometric = PHOTOMETRIC_MINISBLACK; - break; - case 3: - photometric = PHOTOMETRIC_RGB; - break; - default: - sprintf(emsg, "Missing needed %s tag", photoTag); - return (0); - } - } - switch (photometric) { - case PHOTOMETRIC_MINISWHITE: - case PHOTOMETRIC_MINISBLACK: - case PHOTOMETRIC_PALETTE: - if (td->td_planarconfig == PLANARCONFIG_CONTIG - && td->td_samplesperpixel != 1 - && td->td_bitspersample < 8 ) { - sprintf(emsg, - "Sorry, can not handle contiguous data with %s=%d, " - "and %s=%d and Bits/Sample=%d", - photoTag, photometric, - "Samples/pixel", td->td_samplesperpixel, - td->td_bitspersample); - return (0); - } - /* - * We should likely validate that any extra samples are either - * to be ignored, or are alpha, and if alpha we should try to use - * them. But for now we won't bother with this. - */ - break; - case PHOTOMETRIC_YCBCR: - /* - * TODO: if at all meaningful and useful, make more complete - * support check here, or better still, refactor to let supporting - * code decide whether there is support and what meaningfull - * error to return - */ - break; - case PHOTOMETRIC_RGB: - if (colorchannels < 3) { - sprintf(emsg, "Sorry, can not handle RGB image with %s=%d", - "Color channels", colorchannels); - return (0); - } - break; - case PHOTOMETRIC_SEPARATED: - { - uint16 inkset; - TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset); - if (inkset != INKSET_CMYK) { - sprintf(emsg, - "Sorry, can not handle separated image with %s=%d", - "InkSet", inkset); - return 0; - } - if (td->td_samplesperpixel < 4) { - sprintf(emsg, - "Sorry, can not handle separated image with %s=%d", - "Samples/pixel", td->td_samplesperpixel); - return 0; - } - break; - } - case PHOTOMETRIC_LOGL: - if (td->td_compression != COMPRESSION_SGILOG) { - sprintf(emsg, "Sorry, LogL data must have %s=%d", - "Compression", COMPRESSION_SGILOG); - return (0); - } - break; - case PHOTOMETRIC_LOGLUV: - if (td->td_compression != COMPRESSION_SGILOG && - td->td_compression != COMPRESSION_SGILOG24) { - sprintf(emsg, "Sorry, LogLuv data must have %s=%d or %d", - "Compression", COMPRESSION_SGILOG, COMPRESSION_SGILOG24); - return (0); - } - if (td->td_planarconfig != PLANARCONFIG_CONTIG) { - sprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d", - "Planarconfiguration", td->td_planarconfig); - return (0); - } - break; - case PHOTOMETRIC_CIELAB: - break; - default: - sprintf(emsg, "Sorry, can not handle image with %s=%d", - photoTag, photometric); - return (0); - } - return (1); -} - -void -TIFFRGBAImageEnd(TIFFRGBAImage* img) -{ - if (img->Map) - _TIFFfree(img->Map), img->Map = NULL; - if (img->BWmap) - _TIFFfree(img->BWmap), img->BWmap = NULL; - if (img->PALmap) - _TIFFfree(img->PALmap), img->PALmap = NULL; - if (img->ycbcr) - _TIFFfree(img->ycbcr), img->ycbcr = NULL; - if (img->cielab) - _TIFFfree(img->cielab), img->cielab = NULL; - if (img->UaToAa) - _TIFFfree(img->UaToAa), img->UaToAa = NULL; - if (img->Bitdepth16To8) - _TIFFfree(img->Bitdepth16To8), img->Bitdepth16To8 = NULL; - - if( img->redcmap ) { - _TIFFfree( img->redcmap ); - _TIFFfree( img->greencmap ); - _TIFFfree( img->bluecmap ); - img->redcmap = img->greencmap = img->bluecmap = NULL; - } -} - -static int -isCCITTCompression(TIFF* tif) -{ - uint16 compress; - TIFFGetField(tif, TIFFTAG_COMPRESSION, &compress); - return (compress == COMPRESSION_CCITTFAX3 || - compress == COMPRESSION_CCITTFAX4 || - compress == COMPRESSION_CCITTRLE || - compress == COMPRESSION_CCITTRLEW); -} - -int -TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) -{ - uint16* sampleinfo; - uint16 extrasamples; - uint16 planarconfig; - uint16 compress; - int colorchannels; - uint16 *red_orig, *green_orig, *blue_orig; - int n_color; - - /* Initialize to normal values */ - img->row_offset = 0; - img->col_offset = 0; - img->redcmap = NULL; - img->greencmap = NULL; - img->bluecmap = NULL; - img->req_orientation = ORIENTATION_BOTLEFT; /* It is the default */ - - img->tif = tif; - img->stoponerr = stop; - TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &img->bitspersample); - switch (img->bitspersample) { - case 1: - case 2: - case 4: - case 8: - case 16: - break; - default: - sprintf(emsg, "Sorry, can not handle images with %d-bit samples", - img->bitspersample); - goto fail_return; - } - img->alpha = 0; - TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &img->samplesperpixel); - TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, - &extrasamples, &sampleinfo); - if (extrasamples >= 1) - { - switch (sampleinfo[0]) { - case EXTRASAMPLE_UNSPECIFIED: /* Workaround for some images without */ - if (img->samplesperpixel > 3) /* correct info about alpha channel */ - img->alpha = EXTRASAMPLE_ASSOCALPHA; - break; - case EXTRASAMPLE_ASSOCALPHA: /* data is pre-multiplied */ - case EXTRASAMPLE_UNASSALPHA: /* data is not pre-multiplied */ - img->alpha = sampleinfo[0]; - break; - } - } - -#ifdef DEFAULT_EXTRASAMPLE_AS_ALPHA - if( !TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) - img->photometric = PHOTOMETRIC_MINISWHITE; - - if( extrasamples == 0 - && img->samplesperpixel == 4 - && img->photometric == PHOTOMETRIC_RGB ) - { - img->alpha = EXTRASAMPLE_ASSOCALPHA; - extrasamples = 1; - } -#endif - - colorchannels = img->samplesperpixel - extrasamples; - TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &compress); - TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfig); - if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) { - switch (colorchannels) { - case 1: - if (isCCITTCompression(tif)) - img->photometric = PHOTOMETRIC_MINISWHITE; - else - img->photometric = PHOTOMETRIC_MINISBLACK; - break; - case 3: - img->photometric = PHOTOMETRIC_RGB; - break; - default: - sprintf(emsg, "Missing needed %s tag", photoTag); - goto fail_return; - } - } - switch (img->photometric) { - case PHOTOMETRIC_PALETTE: - if (!TIFFGetField(tif, TIFFTAG_COLORMAP, - &red_orig, &green_orig, &blue_orig)) { - sprintf(emsg, "Missing required \"Colormap\" tag"); - goto fail_return; - } - - /* copy the colormaps so we can modify them */ - n_color = (1L << img->bitspersample); - img->redcmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); - img->greencmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); - img->bluecmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); - if( !img->redcmap || !img->greencmap || !img->bluecmap ) { - sprintf(emsg, "Out of memory for colormap copy"); - goto fail_return; - } - - _TIFFmemcpy( img->redcmap, red_orig, n_color * 2 ); - _TIFFmemcpy( img->greencmap, green_orig, n_color * 2 ); - _TIFFmemcpy( img->bluecmap, blue_orig, n_color * 2 ); - - /* fall thru... */ - case PHOTOMETRIC_MINISWHITE: - case PHOTOMETRIC_MINISBLACK: - if (planarconfig == PLANARCONFIG_CONTIG - && img->samplesperpixel != 1 - && img->bitspersample < 8 ) { - sprintf(emsg, - "Sorry, can not handle contiguous data with %s=%d, " - "and %s=%d and Bits/Sample=%d", - photoTag, img->photometric, - "Samples/pixel", img->samplesperpixel, - img->bitspersample); - goto fail_return; - } - break; - case PHOTOMETRIC_YCBCR: - /* It would probably be nice to have a reality check here. */ - if (planarconfig == PLANARCONFIG_CONTIG) - /* can rely on libjpeg to convert to RGB */ - /* XXX should restore current state on exit */ - switch (compress) { - case COMPRESSION_JPEG: - /* - * TODO: when complete tests verify complete desubsampling - * and YCbCr handling, remove use of TIFFTAG_JPEGCOLORMODE in - * favor of tif_getimage.c native handling - */ - TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB); - img->photometric = PHOTOMETRIC_RGB; - break; - default: - /* do nothing */; - break; - } - /* - * TODO: if at all meaningful and useful, make more complete - * support check here, or better still, refactor to let supporting - * code decide whether there is support and what meaningfull - * error to return - */ - break; - case PHOTOMETRIC_RGB: - if (colorchannels < 3) { - sprintf(emsg, "Sorry, can not handle RGB image with %s=%d", - "Color channels", colorchannels); - goto fail_return; - } - break; - case PHOTOMETRIC_SEPARATED: - { - uint16 inkset; - TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset); - if (inkset != INKSET_CMYK) { - sprintf(emsg, "Sorry, can not handle separated image with %s=%d", - "InkSet", inkset); - goto fail_return; - } - if (img->samplesperpixel < 4) { - sprintf(emsg, "Sorry, can not handle separated image with %s=%d", - "Samples/pixel", img->samplesperpixel); - goto fail_return; - } - } - break; - case PHOTOMETRIC_LOGL: - if (compress != COMPRESSION_SGILOG) { - sprintf(emsg, "Sorry, LogL data must have %s=%d", - "Compression", COMPRESSION_SGILOG); - goto fail_return; - } - TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT); - img->photometric = PHOTOMETRIC_MINISBLACK; /* little white lie */ - img->bitspersample = 8; - break; - case PHOTOMETRIC_LOGLUV: - if (compress != COMPRESSION_SGILOG && compress != COMPRESSION_SGILOG24) { - sprintf(emsg, "Sorry, LogLuv data must have %s=%d or %d", - "Compression", COMPRESSION_SGILOG, COMPRESSION_SGILOG24); - goto fail_return; - } - if (planarconfig != PLANARCONFIG_CONTIG) { - sprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d", - "Planarconfiguration", planarconfig); - return (0); - } - TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT); - img->photometric = PHOTOMETRIC_RGB; /* little white lie */ - img->bitspersample = 8; - break; - case PHOTOMETRIC_CIELAB: - break; - default: - sprintf(emsg, "Sorry, can not handle image with %s=%d", - photoTag, img->photometric); - goto fail_return; - } - img->Map = NULL; - img->BWmap = NULL; - img->PALmap = NULL; - img->ycbcr = NULL; - img->cielab = NULL; - img->UaToAa = NULL; - img->Bitdepth16To8 = NULL; - TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width); - TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height); - TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation); - img->isContig = - !(planarconfig == PLANARCONFIG_SEPARATE && img->samplesperpixel > 1); - if (img->isContig) { - if (!PickContigCase(img)) { - sprintf(emsg, "Sorry, can not handle image"); - goto fail_return; - } - } else { - if (!PickSeparateCase(img)) { - sprintf(emsg, "Sorry, can not handle image"); - goto fail_return; - } - } - return 1; - - fail_return: - _TIFFfree( img->redcmap ); - _TIFFfree( img->greencmap ); - _TIFFfree( img->bluecmap ); - img->redcmap = img->greencmap = img->bluecmap = NULL; - return 0; -} - -int -TIFFRGBAImageGet(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) -{ - if (img->get == NULL) { - TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "No \"get\" routine setup"); - return (0); - } - if (img->put.any == NULL) { - TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), - "No \"put\" routine setupl; probably can not handle image format"); - return (0); - } - return (*img->get)(img, raster, w, h); -} - -/* - * Read the specified image into an ABGR-format rastertaking in account - * specified orientation. - */ -int -TIFFReadRGBAImageOriented(TIFF* tif, - uint32 rwidth, uint32 rheight, uint32* raster, - int orientation, int stop) -{ - char emsg[1024] = ""; - TIFFRGBAImage img; - int ok; - - if (TIFFRGBAImageOK(tif, emsg) && TIFFRGBAImageBegin(&img, tif, stop, emsg)) { - img.req_orientation = orientation; - /* XXX verify rwidth and rheight against width and height */ - ok = TIFFRGBAImageGet(&img, raster+(rheight-img.height)*rwidth, - rwidth, img.height); - TIFFRGBAImageEnd(&img); - } else { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", emsg); - ok = 0; - } - return (ok); -} - -/* - * Read the specified image into an ABGR-format raster. Use bottom left - * origin for raster by default. - */ -int -TIFFReadRGBAImage(TIFF* tif, - uint32 rwidth, uint32 rheight, uint32* raster, int stop) -{ - return TIFFReadRGBAImageOriented(tif, rwidth, rheight, raster, - ORIENTATION_BOTLEFT, stop); -} - -static int -setorientation(TIFFRGBAImage* img) -{ - switch (img->orientation) { - case ORIENTATION_TOPLEFT: - case ORIENTATION_LEFTTOP: - if (img->req_orientation == ORIENTATION_TOPRIGHT || - img->req_orientation == ORIENTATION_RIGHTTOP) - return FLIP_HORIZONTALLY; - else if (img->req_orientation == ORIENTATION_BOTRIGHT || - img->req_orientation == ORIENTATION_RIGHTBOT) - return FLIP_HORIZONTALLY | FLIP_VERTICALLY; - else if (img->req_orientation == ORIENTATION_BOTLEFT || - img->req_orientation == ORIENTATION_LEFTBOT) - return FLIP_VERTICALLY; - else - return 0; - case ORIENTATION_TOPRIGHT: - case ORIENTATION_RIGHTTOP: - if (img->req_orientation == ORIENTATION_TOPLEFT || - img->req_orientation == ORIENTATION_LEFTTOP) - return FLIP_HORIZONTALLY; - else if (img->req_orientation == ORIENTATION_BOTRIGHT || - img->req_orientation == ORIENTATION_RIGHTBOT) - return FLIP_VERTICALLY; - else if (img->req_orientation == ORIENTATION_BOTLEFT || - img->req_orientation == ORIENTATION_LEFTBOT) - return FLIP_HORIZONTALLY | FLIP_VERTICALLY; - else - return 0; - case ORIENTATION_BOTRIGHT: - case ORIENTATION_RIGHTBOT: - if (img->req_orientation == ORIENTATION_TOPLEFT || - img->req_orientation == ORIENTATION_LEFTTOP) - return FLIP_HORIZONTALLY | FLIP_VERTICALLY; - else if (img->req_orientation == ORIENTATION_TOPRIGHT || - img->req_orientation == ORIENTATION_RIGHTTOP) - return FLIP_VERTICALLY; - else if (img->req_orientation == ORIENTATION_BOTLEFT || - img->req_orientation == ORIENTATION_LEFTBOT) - return FLIP_HORIZONTALLY; - else - return 0; - case ORIENTATION_BOTLEFT: - case ORIENTATION_LEFTBOT: - if (img->req_orientation == ORIENTATION_TOPLEFT || - img->req_orientation == ORIENTATION_LEFTTOP) - return FLIP_VERTICALLY; - else if (img->req_orientation == ORIENTATION_TOPRIGHT || - img->req_orientation == ORIENTATION_RIGHTTOP) - return FLIP_HORIZONTALLY | FLIP_VERTICALLY; - else if (img->req_orientation == ORIENTATION_BOTRIGHT || - img->req_orientation == ORIENTATION_RIGHTBOT) - return FLIP_HORIZONTALLY; - else - return 0; - default: /* NOTREACHED */ - return 0; - } -} - -/* - * Get an tile-organized image that has - * PlanarConfiguration contiguous if SamplesPerPixel > 1 - * or - * SamplesPerPixel == 1 - */ -static int -gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) -{ - TIFF* tif = img->tif; - tileContigRoutine put = img->put.contig; - uint32 col, row, y, rowstoread; - tmsize_t pos; - uint32 tw, th; - unsigned char* buf; - int32 fromskew, toskew; - uint32 nrow; - int ret = 1, flip; - - buf = (unsigned char*) _TIFFmalloc(TIFFTileSize(tif)); - if (buf == 0) { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "No space for tile buffer"); - return (0); - } - _TIFFmemset(buf, 0, TIFFTileSize(tif)); - TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw); - TIFFGetField(tif, TIFFTAG_TILELENGTH, &th); - - flip = setorientation(img); - if (flip & FLIP_VERTICALLY) { - y = h - 1; - toskew = -(int32)(tw + w); - } - else { - y = 0; - toskew = -(int32)(tw - w); - } - - for (row = 0; row < h; row += nrow) - { - rowstoread = th - (row + img->row_offset) % th; - nrow = (row + rowstoread > h ? h - row : rowstoread); - for (col = 0; col < w; col += tw) - { - if (TIFFReadTile(tif, buf, col+img->col_offset, - row+img->row_offset, 0, 0)==(tmsize_t)(-1) && img->stoponerr) - { - ret = 0; - break; - } - - pos = ((row+img->row_offset) % th) * TIFFTileRowSize(tif); - - if (col + tw > w) - { - /* - * Tile is clipped horizontally. Calculate - * visible portion and skewing factors. - */ - uint32 npix = w - col; - fromskew = tw - npix; - (*put)(img, raster+y*w+col, col, y, - npix, nrow, fromskew, toskew + fromskew, buf + pos); - } - else - { - (*put)(img, raster+y*w+col, col, y, tw, nrow, 0, toskew, buf + pos); - } - } - - y += (flip & FLIP_VERTICALLY ? -(int32) nrow : (int32) nrow); - } - _TIFFfree(buf); - - if (flip & FLIP_HORIZONTALLY) { - uint32 line; - - for (line = 0; line < h; line++) { - uint32 *left = raster + (line * w); - uint32 *right = left + w - 1; - - while ( left < right ) { - uint32 temp = *left; - *left = *right; - *right = temp; - left++, right--; - } - } - } - - return (ret); -} - -/* - * Get an tile-organized image that has - * SamplesPerPixel > 1 - * PlanarConfiguration separated - * We assume that all such images are RGB. - */ -static int -gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) -{ - TIFF* tif = img->tif; - tileSeparateRoutine put = img->put.separate; - uint32 col, row, y, rowstoread; - tmsize_t pos; - uint32 tw, th; - unsigned char* buf; - unsigned char* p0; - unsigned char* p1; - unsigned char* p2; - unsigned char* pa; - tmsize_t tilesize; - tmsize_t bufsize; - int32 fromskew, toskew; - int alpha = img->alpha; - uint32 nrow; - int ret = 1, flip; - int colorchannels; - - tilesize = TIFFTileSize(tif); - bufsize = TIFFSafeMultiply(tmsize_t,alpha?4:3,tilesize); - if (bufsize == 0) { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtTileSeparate"); - return (0); - } - buf = (unsigned char*) _TIFFmalloc(bufsize); - if (buf == 0) { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "No space for tile buffer"); - return (0); - } - _TIFFmemset(buf, 0, bufsize); - p0 = buf; - p1 = p0 + tilesize; - p2 = p1 + tilesize; - pa = (alpha?(p2+tilesize):NULL); - TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw); - TIFFGetField(tif, TIFFTAG_TILELENGTH, &th); - - flip = setorientation(img); - if (flip & FLIP_VERTICALLY) { - y = h - 1; - toskew = -(int32)(tw + w); - } - else { - y = 0; - toskew = -(int32)(tw - w); - } - - switch( img->photometric ) - { - case PHOTOMETRIC_MINISWHITE: - case PHOTOMETRIC_MINISBLACK: - case PHOTOMETRIC_PALETTE: - colorchannels = 1; - p2 = p1 = p0; - break; - - default: - colorchannels = 3; - break; - } - - for (row = 0; row < h; row += nrow) - { - rowstoread = th - (row + img->row_offset) % th; - nrow = (row + rowstoread > h ? h - row : rowstoread); - for (col = 0; col < w; col += tw) - { - if (TIFFReadTile(tif, p0, col+img->col_offset, - row+img->row_offset,0,0)==(tmsize_t)(-1) && img->stoponerr) - { - ret = 0; - break; - } - if (colorchannels > 1 - && TIFFReadTile(tif, p1, col+img->col_offset, - row+img->row_offset,0,1) == (tmsize_t)(-1) - && img->stoponerr) - { - ret = 0; - break; - } - if (colorchannels > 1 - && TIFFReadTile(tif, p2, col+img->col_offset, - row+img->row_offset,0,2) == (tmsize_t)(-1) - && img->stoponerr) - { - ret = 0; - break; - } - if (alpha - && TIFFReadTile(tif,pa,col+img->col_offset, - row+img->row_offset,0,colorchannels) == (tmsize_t)(-1) - && img->stoponerr) - { - ret = 0; - break; - } - - pos = ((row+img->row_offset) % th) * TIFFTileRowSize(tif); - - if (col + tw > w) - { - /* - * Tile is clipped horizontally. Calculate - * visible portion and skewing factors. - */ - uint32 npix = w - col; - fromskew = tw - npix; - (*put)(img, raster+y*w+col, col, y, - npix, nrow, fromskew, toskew + fromskew, - p0 + pos, p1 + pos, p2 + pos, (alpha?(pa+pos):NULL)); - } else { - (*put)(img, raster+y*w+col, col, y, - tw, nrow, 0, toskew, p0 + pos, p1 + pos, p2 + pos, (alpha?(pa+pos):NULL)); - } - } - - y += (flip & FLIP_VERTICALLY ?-(int32) nrow : (int32) nrow); - } - - if (flip & FLIP_HORIZONTALLY) { - uint32 line; - - for (line = 0; line < h; line++) { - uint32 *left = raster + (line * w); - uint32 *right = left + w - 1; - - while ( left < right ) { - uint32 temp = *left; - *left = *right; - *right = temp; - left++, right--; - } - } - } - - _TIFFfree(buf); - return (ret); -} - -/* - * Get a strip-organized image that has - * PlanarConfiguration contiguous if SamplesPerPixel > 1 - * or - * SamplesPerPixel == 1 - */ -static int -gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) -{ - TIFF* tif = img->tif; - tileContigRoutine put = img->put.contig; - uint32 row, y, nrow, nrowsub, rowstoread; - tmsize_t pos; - unsigned char* buf; - uint32 rowsperstrip; - uint16 subsamplinghor,subsamplingver; - uint32 imagewidth = img->width; - tmsize_t scanline; - int32 fromskew, toskew; - int ret = 1, flip; - - buf = (unsigned char*) _TIFFmalloc(TIFFStripSize(tif)); - if (buf == 0) { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for strip buffer"); - return (0); - } - _TIFFmemset(buf, 0, TIFFStripSize(tif)); - - flip = setorientation(img); - if (flip & FLIP_VERTICALLY) { - y = h - 1; - toskew = -(int32)(w + w); - } else { - y = 0; - toskew = -(int32)(w - w); - } - - TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); - TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRSUBSAMPLING, &subsamplinghor, &subsamplingver); - scanline = TIFFScanlineSize(tif); - fromskew = (w < imagewidth ? imagewidth - w : 0); - for (row = 0; row < h; row += nrow) - { - rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip; - nrow = (row + rowstoread > h ? h - row : rowstoread); - nrowsub = nrow; - if ((nrowsub%subsamplingver)!=0) - nrowsub+=subsamplingver-nrowsub%subsamplingver; - if (TIFFReadEncodedStrip(tif, - TIFFComputeStrip(tif,row+img->row_offset, 0), - buf, - ((row + img->row_offset)%rowsperstrip + nrowsub) * scanline)==(tmsize_t)(-1) - && img->stoponerr) - { - ret = 0; - break; - } - - pos = ((row + img->row_offset) % rowsperstrip) * scanline; - (*put)(img, raster+y*w, 0, y, w, nrow, fromskew, toskew, buf + pos); - y += (flip & FLIP_VERTICALLY ? -(int32) nrow : (int32) nrow); - } - - if (flip & FLIP_HORIZONTALLY) { - uint32 line; - - for (line = 0; line < h; line++) { - uint32 *left = raster + (line * w); - uint32 *right = left + w - 1; - - while ( left < right ) { - uint32 temp = *left; - *left = *right; - *right = temp; - left++, right--; - } - } - } - - _TIFFfree(buf); - return (ret); -} - -/* - * Get a strip-organized image with - * SamplesPerPixel > 1 - * PlanarConfiguration separated - * We assume that all such images are RGB. - */ -static int -gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) -{ - TIFF* tif = img->tif; - tileSeparateRoutine put = img->put.separate; - unsigned char *buf; - unsigned char *p0, *p1, *p2, *pa; - uint32 row, y, nrow, rowstoread; - tmsize_t pos; - tmsize_t scanline; - uint32 rowsperstrip, offset_row; - uint32 imagewidth = img->width; - tmsize_t stripsize; - tmsize_t bufsize; - int32 fromskew, toskew; - int alpha = img->alpha; - int ret = 1, flip, colorchannels; - - stripsize = TIFFStripSize(tif); - bufsize = TIFFSafeMultiply(tmsize_t,alpha?4:3,stripsize); - if (bufsize == 0) { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtStripSeparate"); - return (0); - } - p0 = buf = (unsigned char *)_TIFFmalloc(bufsize); - if (buf == 0) { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for tile buffer"); - return (0); - } - _TIFFmemset(buf, 0, bufsize); - p1 = p0 + stripsize; - p2 = p1 + stripsize; - pa = (alpha?(p2+stripsize):NULL); - - flip = setorientation(img); - if (flip & FLIP_VERTICALLY) { - y = h - 1; - toskew = -(int32)(w + w); - } - else { - y = 0; - toskew = -(int32)(w - w); - } - - switch( img->photometric ) - { - case PHOTOMETRIC_MINISWHITE: - case PHOTOMETRIC_MINISBLACK: - case PHOTOMETRIC_PALETTE: - colorchannels = 1; - p2 = p1 = p0; - break; - - default: - colorchannels = 3; - break; - } - - TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); - scanline = TIFFScanlineSize(tif); - fromskew = (w < imagewidth ? imagewidth - w : 0); - for (row = 0; row < h; row += nrow) - { - rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip; - nrow = (row + rowstoread > h ? h - row : rowstoread); - offset_row = row + img->row_offset; - if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0), - p0, ((row + img->row_offset)%rowsperstrip + nrow) * scanline)==(tmsize_t)(-1) - && img->stoponerr) - { - ret = 0; - break; - } - if (colorchannels > 1 - && TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 1), - p1, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) == (tmsize_t)(-1) - && img->stoponerr) - { - ret = 0; - break; - } - if (colorchannels > 1 - && TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 2), - p2, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) == (tmsize_t)(-1) - && img->stoponerr) - { - ret = 0; - break; - } - if (alpha) - { - if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, colorchannels), - pa, ((row + img->row_offset)%rowsperstrip + nrow) * scanline)==(tmsize_t)(-1) - && img->stoponerr) - { - ret = 0; - break; - } - } - - pos = ((row + img->row_offset) % rowsperstrip) * scanline; - (*put)(img, raster+y*w, 0, y, w, nrow, fromskew, toskew, p0 + pos, p1 + pos, - p2 + pos, (alpha?(pa+pos):NULL)); - y += (flip & FLIP_VERTICALLY ? -(int32) nrow : (int32) nrow); - } - - if (flip & FLIP_HORIZONTALLY) { - uint32 line; - - for (line = 0; line < h; line++) { - uint32 *left = raster + (line * w); - uint32 *right = left + w - 1; - - while ( left < right ) { - uint32 temp = *left; - *left = *right; - *right = temp; - left++, right--; - } - } - } - - _TIFFfree(buf); - return (ret); -} - -/* - * The following routines move decoded data returned - * from the TIFF library into rasters filled with packed - * ABGR pixels (i.e. suitable for passing to lrecwrite.) - * - * The routines have been created according to the most - * important cases and optimized. PickContigCase and - * PickSeparateCase analyze the parameters and select - * the appropriate "get" and "put" routine to use. - */ -#define REPEAT8(op) REPEAT4(op); REPEAT4(op) -#define REPEAT4(op) REPEAT2(op); REPEAT2(op) -#define REPEAT2(op) op; op -#define CASE8(x,op) \ - switch (x) { \ - case 7: op; case 6: op; case 5: op; \ - case 4: op; case 3: op; case 2: op; \ - case 1: op; \ - } -#define CASE4(x,op) switch (x) { case 3: op; case 2: op; case 1: op; } -#define NOP - -#define UNROLL8(w, op1, op2) { \ - uint32 _x; \ - for (_x = w; _x >= 8; _x -= 8) { \ - op1; \ - REPEAT8(op2); \ - } \ - if (_x > 0) { \ - op1; \ - CASE8(_x,op2); \ - } \ -} -#define UNROLL4(w, op1, op2) { \ - uint32 _x; \ - for (_x = w; _x >= 4; _x -= 4) { \ - op1; \ - REPEAT4(op2); \ - } \ - if (_x > 0) { \ - op1; \ - CASE4(_x,op2); \ - } \ -} -#define UNROLL2(w, op1, op2) { \ - uint32 _x; \ - for (_x = w; _x >= 2; _x -= 2) { \ - op1; \ - REPEAT2(op2); \ - } \ - if (_x) { \ - op1; \ - op2; \ - } \ -} - -#define SKEW(r,g,b,skew) { r += skew; g += skew; b += skew; } -#define SKEW4(r,g,b,a,skew) { r += skew; g += skew; b += skew; a+= skew; } - -#define A1 (((uint32)0xffL)<<24) -#define PACK(r,g,b) \ - ((uint32)(r)|((uint32)(g)<<8)|((uint32)(b)<<16)|A1) -#define PACK4(r,g,b,a) \ - ((uint32)(r)|((uint32)(g)<<8)|((uint32)(b)<<16)|((uint32)(a)<<24)) -#define W2B(v) (((v)>>8)&0xff) -/* TODO: PACKW should have be made redundant in favor of Bitdepth16To8 LUT */ -#define PACKW(r,g,b) \ - ((uint32)W2B(r)|((uint32)W2B(g)<<8)|((uint32)W2B(b)<<16)|A1) -#define PACKW4(r,g,b,a) \ - ((uint32)W2B(r)|((uint32)W2B(g)<<8)|((uint32)W2B(b)<<16)|((uint32)W2B(a)<<24)) - -#define DECLAREContigPutFunc(name) \ -static void name(\ - TIFFRGBAImage* img, \ - uint32* cp, \ - uint32 x, uint32 y, \ - uint32 w, uint32 h, \ - int32 fromskew, int32 toskew, \ - unsigned char* pp \ -) - -/* - * 8-bit palette => colormap/RGB - */ -DECLAREContigPutFunc(put8bitcmaptile) -{ - uint32** PALmap = img->PALmap; - int samplesperpixel = img->samplesperpixel; - - (void) y; - while (h-- > 0) { - for (x = w; x-- > 0;) - { - *cp++ = PALmap[*pp][0]; - pp += samplesperpixel; - } - cp += toskew; - pp += fromskew; - } -} - -/* - * 4-bit palette => colormap/RGB - */ -DECLAREContigPutFunc(put4bitcmaptile) -{ - uint32** PALmap = img->PALmap; - - (void) x; (void) y; - fromskew /= 2; - while (h-- > 0) { - uint32* bw; - UNROLL2(w, bw = PALmap[*pp++], *cp++ = *bw++); - cp += toskew; - pp += fromskew; - } -} - -/* - * 2-bit palette => colormap/RGB - */ -DECLAREContigPutFunc(put2bitcmaptile) -{ - uint32** PALmap = img->PALmap; - - (void) x; (void) y; - fromskew /= 4; - while (h-- > 0) { - uint32* bw; - UNROLL4(w, bw = PALmap[*pp++], *cp++ = *bw++); - cp += toskew; - pp += fromskew; - } -} - -/* - * 1-bit palette => colormap/RGB - */ -DECLAREContigPutFunc(put1bitcmaptile) -{ - uint32** PALmap = img->PALmap; - - (void) x; (void) y; - fromskew /= 8; - while (h-- > 0) { - uint32* bw; - UNROLL8(w, bw = PALmap[*pp++], *cp++ = *bw++); - cp += toskew; - pp += fromskew; - } -} - -/* - * 8-bit greyscale => colormap/RGB - */ -DECLAREContigPutFunc(putgreytile) -{ - int samplesperpixel = img->samplesperpixel; - uint32** BWmap = img->BWmap; - - (void) y; - while (h-- > 0) { - for (x = w; x-- > 0;) - { - *cp++ = BWmap[*pp][0]; - pp += samplesperpixel; - } - cp += toskew; - pp += fromskew; - } -} - -/* - * 8-bit greyscale with associated alpha => colormap/RGBA - */ -DECLAREContigPutFunc(putagreytile) -{ - int samplesperpixel = img->samplesperpixel; - uint32** BWmap = img->BWmap; - - (void) y; - while (h-- > 0) { - for (x = w; x-- > 0;) - { - *cp++ = BWmap[*pp][0] & (*(pp+1) << 24 | ~A1); - pp += samplesperpixel; - } - cp += toskew; - pp += fromskew; - } -} - -/* - * 16-bit greyscale => colormap/RGB - */ -DECLAREContigPutFunc(put16bitbwtile) -{ - int samplesperpixel = img->samplesperpixel; - uint32** BWmap = img->BWmap; - - (void) y; - while (h-- > 0) { - uint16 *wp = (uint16 *) pp; - - for (x = w; x-- > 0;) - { - /* use high order byte of 16bit value */ - - *cp++ = BWmap[*wp >> 8][0]; - pp += 2 * samplesperpixel; - wp += samplesperpixel; - } - cp += toskew; - pp += fromskew; - } -} - -/* - * 1-bit bilevel => colormap/RGB - */ -DECLAREContigPutFunc(put1bitbwtile) -{ - uint32** BWmap = img->BWmap; - - (void) x; (void) y; - fromskew /= 8; - while (h-- > 0) { - uint32* bw; - UNROLL8(w, bw = BWmap[*pp++], *cp++ = *bw++); - cp += toskew; - pp += fromskew; - } -} - -/* - * 2-bit greyscale => colormap/RGB - */ -DECLAREContigPutFunc(put2bitbwtile) -{ - uint32** BWmap = img->BWmap; - - (void) x; (void) y; - fromskew /= 4; - while (h-- > 0) { - uint32* bw; - UNROLL4(w, bw = BWmap[*pp++], *cp++ = *bw++); - cp += toskew; - pp += fromskew; - } -} - -/* - * 4-bit greyscale => colormap/RGB - */ -DECLAREContigPutFunc(put4bitbwtile) -{ - uint32** BWmap = img->BWmap; - - (void) x; (void) y; - fromskew /= 2; - while (h-- > 0) { - uint32* bw; - UNROLL2(w, bw = BWmap[*pp++], *cp++ = *bw++); - cp += toskew; - pp += fromskew; - } -} - -/* - * 8-bit packed samples, no Map => RGB - */ -DECLAREContigPutFunc(putRGBcontig8bittile) -{ - int samplesperpixel = img->samplesperpixel; - - (void) x; (void) y; - fromskew *= samplesperpixel; - while (h-- > 0) { - UNROLL8(w, NOP, - *cp++ = PACK(pp[0], pp[1], pp[2]); - pp += samplesperpixel); - cp += toskew; - pp += fromskew; - } -} - -/* - * 8-bit packed samples => RGBA w/ associated alpha - * (known to have Map == NULL) - */ -DECLAREContigPutFunc(putRGBAAcontig8bittile) -{ - int samplesperpixel = img->samplesperpixel; - - (void) x; (void) y; - fromskew *= samplesperpixel; - while (h-- > 0) { - UNROLL8(w, NOP, - *cp++ = PACK4(pp[0], pp[1], pp[2], pp[3]); - pp += samplesperpixel); - cp += toskew; - pp += fromskew; - } -} - -/* - * 8-bit packed samples => RGBA w/ unassociated alpha - * (known to have Map == NULL) - */ -DECLAREContigPutFunc(putRGBUAcontig8bittile) -{ - int samplesperpixel = img->samplesperpixel; - (void) y; - fromskew *= samplesperpixel; - while (h-- > 0) { - uint32 r, g, b, a; - uint8* m; - for (x = w; x-- > 0;) { - a = pp[3]; - m = img->UaToAa+(a<<8); - r = m[pp[0]]; - g = m[pp[1]]; - b = m[pp[2]]; - *cp++ = PACK4(r,g,b,a); - pp += samplesperpixel; - } - cp += toskew; - pp += fromskew; - } -} - -/* - * 16-bit packed samples => RGB - */ -DECLAREContigPutFunc(putRGBcontig16bittile) -{ - int samplesperpixel = img->samplesperpixel; - uint16 *wp = (uint16 *)pp; - (void) y; - fromskew *= samplesperpixel; - while (h-- > 0) { - for (x = w; x-- > 0;) { - *cp++ = PACK(img->Bitdepth16To8[wp[0]], - img->Bitdepth16To8[wp[1]], - img->Bitdepth16To8[wp[2]]); - wp += samplesperpixel; - } - cp += toskew; - wp += fromskew; - } -} - -/* - * 16-bit packed samples => RGBA w/ associated alpha - * (known to have Map == NULL) - */ -DECLAREContigPutFunc(putRGBAAcontig16bittile) -{ - int samplesperpixel = img->samplesperpixel; - uint16 *wp = (uint16 *)pp; - (void) y; - fromskew *= samplesperpixel; - while (h-- > 0) { - for (x = w; x-- > 0;) { - *cp++ = PACK4(img->Bitdepth16To8[wp[0]], - img->Bitdepth16To8[wp[1]], - img->Bitdepth16To8[wp[2]], - img->Bitdepth16To8[wp[3]]); - wp += samplesperpixel; - } - cp += toskew; - wp += fromskew; - } -} - -/* - * 16-bit packed samples => RGBA w/ unassociated alpha - * (known to have Map == NULL) - */ -DECLAREContigPutFunc(putRGBUAcontig16bittile) -{ - int samplesperpixel = img->samplesperpixel; - uint16 *wp = (uint16 *)pp; - (void) y; - fromskew *= samplesperpixel; - while (h-- > 0) { - uint32 r,g,b,a; - uint8* m; - for (x = w; x-- > 0;) { - a = img->Bitdepth16To8[wp[3]]; - m = img->UaToAa+(a<<8); - r = m[img->Bitdepth16To8[wp[0]]]; - g = m[img->Bitdepth16To8[wp[1]]]; - b = m[img->Bitdepth16To8[wp[2]]]; - *cp++ = PACK4(r,g,b,a); - wp += samplesperpixel; - } - cp += toskew; - wp += fromskew; - } -} - -/* - * 8-bit packed CMYK samples w/o Map => RGB - * - * NB: The conversion of CMYK->RGB is *very* crude. - */ -DECLAREContigPutFunc(putRGBcontig8bitCMYKtile) -{ - int samplesperpixel = img->samplesperpixel; - uint16 r, g, b, k; - - (void) x; (void) y; - fromskew *= samplesperpixel; - while (h-- > 0) { - UNROLL8(w, NOP, - k = 255 - pp[3]; - r = (k*(255-pp[0]))/255; - g = (k*(255-pp[1]))/255; - b = (k*(255-pp[2]))/255; - *cp++ = PACK(r, g, b); - pp += samplesperpixel); - cp += toskew; - pp += fromskew; - } -} - -/* - * 8-bit packed CMYK samples w/Map => RGB - * - * NB: The conversion of CMYK->RGB is *very* crude. - */ -DECLAREContigPutFunc(putRGBcontig8bitCMYKMaptile) -{ - int samplesperpixel = img->samplesperpixel; - TIFFRGBValue* Map = img->Map; - uint16 r, g, b, k; - - (void) y; - fromskew *= samplesperpixel; - while (h-- > 0) { - for (x = w; x-- > 0;) { - k = 255 - pp[3]; - r = (k*(255-pp[0]))/255; - g = (k*(255-pp[1]))/255; - b = (k*(255-pp[2]))/255; - *cp++ = PACK(Map[r], Map[g], Map[b]); - pp += samplesperpixel; - } - pp += fromskew; - cp += toskew; - } -} - -#define DECLARESepPutFunc(name) \ -static void name(\ - TIFFRGBAImage* img,\ - uint32* cp,\ - uint32 x, uint32 y, \ - uint32 w, uint32 h,\ - int32 fromskew, int32 toskew,\ - unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a\ -) - -/* - * 8-bit unpacked samples => RGB - */ -DECLARESepPutFunc(putRGBseparate8bittile) -{ - (void) img; (void) x; (void) y; (void) a; - while (h-- > 0) { - UNROLL8(w, NOP, *cp++ = PACK(*r++, *g++, *b++)); - SKEW(r, g, b, fromskew); - cp += toskew; - } -} - -/* - * 8-bit unpacked samples => RGBA w/ associated alpha - */ -DECLARESepPutFunc(putRGBAAseparate8bittile) -{ - (void) img; (void) x; (void) y; - while (h-- > 0) { - UNROLL8(w, NOP, *cp++ = PACK4(*r++, *g++, *b++, *a++)); - SKEW4(r, g, b, a, fromskew); - cp += toskew; - } -} - -/* - * 8-bit unpacked CMYK samples => RGBA - */ -DECLARESepPutFunc(putCMYKseparate8bittile) -{ - (void) img; (void) y; - while (h-- > 0) { - uint32 rv, gv, bv, kv; - for (x = w; x-- > 0;) { - kv = 255 - *a++; - rv = (kv*(255-*r++))/255; - gv = (kv*(255-*g++))/255; - bv = (kv*(255-*b++))/255; - *cp++ = PACK4(rv,gv,bv,255); - } - SKEW4(r, g, b, a, fromskew); - cp += toskew; - } -} - -/* - * 8-bit unpacked samples => RGBA w/ unassociated alpha - */ -DECLARESepPutFunc(putRGBUAseparate8bittile) -{ - (void) img; (void) y; - while (h-- > 0) { - uint32 rv, gv, bv, av; - uint8* m; - for (x = w; x-- > 0;) { - av = *a++; - m = img->UaToAa+(av<<8); - rv = m[*r++]; - gv = m[*g++]; - bv = m[*b++]; - *cp++ = PACK4(rv,gv,bv,av); - } - SKEW4(r, g, b, a, fromskew); - cp += toskew; - } -} - -/* - * 16-bit unpacked samples => RGB - */ -DECLARESepPutFunc(putRGBseparate16bittile) -{ - uint16 *wr = (uint16*) r; - uint16 *wg = (uint16*) g; - uint16 *wb = (uint16*) b; - (void) img; (void) y; (void) a; - while (h-- > 0) { - for (x = 0; x < w; x++) - *cp++ = PACK(img->Bitdepth16To8[*wr++], - img->Bitdepth16To8[*wg++], - img->Bitdepth16To8[*wb++]); - SKEW(wr, wg, wb, fromskew); - cp += toskew; - } -} - -/* - * 16-bit unpacked samples => RGBA w/ associated alpha - */ -DECLARESepPutFunc(putRGBAAseparate16bittile) -{ - uint16 *wr = (uint16*) r; - uint16 *wg = (uint16*) g; - uint16 *wb = (uint16*) b; - uint16 *wa = (uint16*) a; - (void) img; (void) y; - while (h-- > 0) { - for (x = 0; x < w; x++) - *cp++ = PACK4(img->Bitdepth16To8[*wr++], - img->Bitdepth16To8[*wg++], - img->Bitdepth16To8[*wb++], - img->Bitdepth16To8[*wa++]); - SKEW4(wr, wg, wb, wa, fromskew); - cp += toskew; - } -} - -/* - * 16-bit unpacked samples => RGBA w/ unassociated alpha - */ -DECLARESepPutFunc(putRGBUAseparate16bittile) -{ - uint16 *wr = (uint16*) r; - uint16 *wg = (uint16*) g; - uint16 *wb = (uint16*) b; - uint16 *wa = (uint16*) a; - (void) img; (void) y; - while (h-- > 0) { - uint32 r,g,b,a; - uint8* m; - for (x = w; x-- > 0;) { - a = img->Bitdepth16To8[*wa++]; - m = img->UaToAa+(a<<8); - r = m[img->Bitdepth16To8[*wr++]]; - g = m[img->Bitdepth16To8[*wg++]]; - b = m[img->Bitdepth16To8[*wb++]]; - *cp++ = PACK4(r,g,b,a); - } - SKEW4(wr, wg, wb, wa, fromskew); - cp += toskew; - } -} - -/* - * 8-bit packed CIE L*a*b 1976 samples => RGB - */ -DECLAREContigPutFunc(putcontig8bitCIELab) -{ - float X, Y, Z; - uint32 r, g, b; - (void) y; - fromskew *= 3; - while (h-- > 0) { - for (x = w; x-- > 0;) { - TIFFCIELabToXYZ(img->cielab, - (unsigned char)pp[0], - (signed char)pp[1], - (signed char)pp[2], - &X, &Y, &Z); - TIFFXYZToRGB(img->cielab, X, Y, Z, &r, &g, &b); - *cp++ = PACK(r, g, b); - pp += 3; - } - cp += toskew; - pp += fromskew; - } -} - -/* - * YCbCr -> RGB conversion and packing routines. - */ - -#define YCbCrtoRGB(dst, Y) { \ - uint32 r, g, b; \ - TIFFYCbCrtoRGB(img->ycbcr, (Y), Cb, Cr, &r, &g, &b); \ - dst = PACK(r, g, b); \ -} - -/* - * 8-bit packed YCbCr samples => RGB - * This function is generic for different sampling sizes, - * and can handle blocks sizes that aren't multiples of the - * sampling size. However, it is substantially less optimized - * than the specific sampling cases. It is used as a fallback - * for difficult blocks. - */ -#ifdef notdef -static void putcontig8bitYCbCrGenericTile( - TIFFRGBAImage* img, - uint32* cp, - uint32 x, uint32 y, - uint32 w, uint32 h, - int32 fromskew, int32 toskew, - unsigned char* pp, - int h_group, - int v_group ) - -{ - uint32* cp1 = cp+w+toskew; - uint32* cp2 = cp1+w+toskew; - uint32* cp3 = cp2+w+toskew; - int32 incr = 3*w+4*toskew; - int32 Cb, Cr; - int group_size = v_group * h_group + 2; - - (void) y; - fromskew = (fromskew * group_size) / h_group; - - for( yy = 0; yy < h; yy++ ) - { - unsigned char *pp_line; - int y_line_group = yy / v_group; - int y_remainder = yy - y_line_group * v_group; - - pp_line = pp + v_line_group * - - - for( xx = 0; xx < w; xx++ ) - { - Cb = pp - } - } - for (; h >= 4; h -= 4) { - x = w>>2; - do { - Cb = pp[16]; - Cr = pp[17]; - - YCbCrtoRGB(cp [0], pp[ 0]); - YCbCrtoRGB(cp [1], pp[ 1]); - YCbCrtoRGB(cp [2], pp[ 2]); - YCbCrtoRGB(cp [3], pp[ 3]); - YCbCrtoRGB(cp1[0], pp[ 4]); - YCbCrtoRGB(cp1[1], pp[ 5]); - YCbCrtoRGB(cp1[2], pp[ 6]); - YCbCrtoRGB(cp1[3], pp[ 7]); - YCbCrtoRGB(cp2[0], pp[ 8]); - YCbCrtoRGB(cp2[1], pp[ 9]); - YCbCrtoRGB(cp2[2], pp[10]); - YCbCrtoRGB(cp2[3], pp[11]); - YCbCrtoRGB(cp3[0], pp[12]); - YCbCrtoRGB(cp3[1], pp[13]); - YCbCrtoRGB(cp3[2], pp[14]); - YCbCrtoRGB(cp3[3], pp[15]); - - cp += 4, cp1 += 4, cp2 += 4, cp3 += 4; - pp += 18; - } while (--x); - cp += incr, cp1 += incr, cp2 += incr, cp3 += incr; - pp += fromskew; - } -} -#endif - -/* - * 8-bit packed YCbCr samples w/ 4,4 subsampling => RGB - */ -DECLAREContigPutFunc(putcontig8bitYCbCr44tile) -{ - uint32* cp1 = cp+w+toskew; - uint32* cp2 = cp1+w+toskew; - uint32* cp3 = cp2+w+toskew; - int32 incr = 3*w+4*toskew; - - (void) y; - /* adjust fromskew */ - fromskew = (fromskew * 18) / 4; - if ((h & 3) == 0 && (w & 3) == 0) { - for (; h >= 4; h -= 4) { - x = w>>2; - do { - int32 Cb = pp[16]; - int32 Cr = pp[17]; - - YCbCrtoRGB(cp [0], pp[ 0]); - YCbCrtoRGB(cp [1], pp[ 1]); - YCbCrtoRGB(cp [2], pp[ 2]); - YCbCrtoRGB(cp [3], pp[ 3]); - YCbCrtoRGB(cp1[0], pp[ 4]); - YCbCrtoRGB(cp1[1], pp[ 5]); - YCbCrtoRGB(cp1[2], pp[ 6]); - YCbCrtoRGB(cp1[3], pp[ 7]); - YCbCrtoRGB(cp2[0], pp[ 8]); - YCbCrtoRGB(cp2[1], pp[ 9]); - YCbCrtoRGB(cp2[2], pp[10]); - YCbCrtoRGB(cp2[3], pp[11]); - YCbCrtoRGB(cp3[0], pp[12]); - YCbCrtoRGB(cp3[1], pp[13]); - YCbCrtoRGB(cp3[2], pp[14]); - YCbCrtoRGB(cp3[3], pp[15]); - - cp += 4, cp1 += 4, cp2 += 4, cp3 += 4; - pp += 18; - } while (--x); - cp += incr, cp1 += incr, cp2 += incr, cp3 += incr; - pp += fromskew; - } - } else { - while (h > 0) { - for (x = w; x > 0;) { - int32 Cb = pp[16]; - int32 Cr = pp[17]; - switch (x) { - default: - switch (h) { - default: YCbCrtoRGB(cp3[3], pp[15]); /* FALLTHROUGH */ - case 3: YCbCrtoRGB(cp2[3], pp[11]); /* FALLTHROUGH */ - case 2: YCbCrtoRGB(cp1[3], pp[ 7]); /* FALLTHROUGH */ - case 1: YCbCrtoRGB(cp [3], pp[ 3]); /* FALLTHROUGH */ - } /* FALLTHROUGH */ - case 3: - switch (h) { - default: YCbCrtoRGB(cp3[2], pp[14]); /* FALLTHROUGH */ - case 3: YCbCrtoRGB(cp2[2], pp[10]); /* FALLTHROUGH */ - case 2: YCbCrtoRGB(cp1[2], pp[ 6]); /* FALLTHROUGH */ - case 1: YCbCrtoRGB(cp [2], pp[ 2]); /* FALLTHROUGH */ - } /* FALLTHROUGH */ - case 2: - switch (h) { - default: YCbCrtoRGB(cp3[1], pp[13]); /* FALLTHROUGH */ - case 3: YCbCrtoRGB(cp2[1], pp[ 9]); /* FALLTHROUGH */ - case 2: YCbCrtoRGB(cp1[1], pp[ 5]); /* FALLTHROUGH */ - case 1: YCbCrtoRGB(cp [1], pp[ 1]); /* FALLTHROUGH */ - } /* FALLTHROUGH */ - case 1: - switch (h) { - default: YCbCrtoRGB(cp3[0], pp[12]); /* FALLTHROUGH */ - case 3: YCbCrtoRGB(cp2[0], pp[ 8]); /* FALLTHROUGH */ - case 2: YCbCrtoRGB(cp1[0], pp[ 4]); /* FALLTHROUGH */ - case 1: YCbCrtoRGB(cp [0], pp[ 0]); /* FALLTHROUGH */ - } /* FALLTHROUGH */ - } - if (x < 4) { - cp += x; cp1 += x; cp2 += x; cp3 += x; - x = 0; - } - else { - cp += 4; cp1 += 4; cp2 += 4; cp3 += 4; - x -= 4; - } - pp += 18; - } - if (h <= 4) - break; - h -= 4; - cp += incr, cp1 += incr, cp2 += incr, cp3 += incr; - pp += fromskew; - } - } -} - -/* - * 8-bit packed YCbCr samples w/ 4,2 subsampling => RGB - */ -DECLAREContigPutFunc(putcontig8bitYCbCr42tile) -{ - uint32* cp1 = cp+w+toskew; - int32 incr = 2*toskew+w; - - (void) y; - fromskew = (fromskew * 10) / 4; - if ((h & 3) == 0 && (w & 1) == 0) { - for (; h >= 2; h -= 2) { - x = w>>2; - do { - int32 Cb = pp[8]; - int32 Cr = pp[9]; - - YCbCrtoRGB(cp [0], pp[0]); - YCbCrtoRGB(cp [1], pp[1]); - YCbCrtoRGB(cp [2], pp[2]); - YCbCrtoRGB(cp [3], pp[3]); - YCbCrtoRGB(cp1[0], pp[4]); - YCbCrtoRGB(cp1[1], pp[5]); - YCbCrtoRGB(cp1[2], pp[6]); - YCbCrtoRGB(cp1[3], pp[7]); - - cp += 4, cp1 += 4; - pp += 10; - } while (--x); - cp += incr, cp1 += incr; - pp += fromskew; - } - } else { - while (h > 0) { - for (x = w; x > 0;) { - int32 Cb = pp[8]; - int32 Cr = pp[9]; - switch (x) { - default: - switch (h) { - default: YCbCrtoRGB(cp1[3], pp[ 7]); /* FALLTHROUGH */ - case 1: YCbCrtoRGB(cp [3], pp[ 3]); /* FALLTHROUGH */ - } /* FALLTHROUGH */ - case 3: - switch (h) { - default: YCbCrtoRGB(cp1[2], pp[ 6]); /* FALLTHROUGH */ - case 1: YCbCrtoRGB(cp [2], pp[ 2]); /* FALLTHROUGH */ - } /* FALLTHROUGH */ - case 2: - switch (h) { - default: YCbCrtoRGB(cp1[1], pp[ 5]); /* FALLTHROUGH */ - case 1: YCbCrtoRGB(cp [1], pp[ 1]); /* FALLTHROUGH */ - } /* FALLTHROUGH */ - case 1: - switch (h) { - default: YCbCrtoRGB(cp1[0], pp[ 4]); /* FALLTHROUGH */ - case 1: YCbCrtoRGB(cp [0], pp[ 0]); /* FALLTHROUGH */ - } /* FALLTHROUGH */ - } - if (x < 4) { - cp += x; cp1 += x; - x = 0; - } - else { - cp += 4; cp1 += 4; - x -= 4; - } - pp += 10; - } - if (h <= 2) - break; - h -= 2; - cp += incr, cp1 += incr; - pp += fromskew; - } - } -} - -/* - * 8-bit packed YCbCr samples w/ 4,1 subsampling => RGB - */ -DECLAREContigPutFunc(putcontig8bitYCbCr41tile) -{ - (void) y; - /* XXX adjust fromskew */ - do { - x = w>>2; - do { - int32 Cb = pp[4]; - int32 Cr = pp[5]; - - YCbCrtoRGB(cp [0], pp[0]); - YCbCrtoRGB(cp [1], pp[1]); - YCbCrtoRGB(cp [2], pp[2]); - YCbCrtoRGB(cp [3], pp[3]); - - cp += 4; - pp += 6; - } while (--x); - - if( (w&3) != 0 ) - { - int32 Cb = pp[4]; - int32 Cr = pp[5]; - - switch( (w&3) ) { - case 3: YCbCrtoRGB(cp [2], pp[2]); - case 2: YCbCrtoRGB(cp [1], pp[1]); - case 1: YCbCrtoRGB(cp [0], pp[0]); - case 0: break; - } - - cp += (w&3); - pp += 6; - } - - cp += toskew; - pp += fromskew; - } while (--h); - -} - -/* - * 8-bit packed YCbCr samples w/ 2,2 subsampling => RGB - */ -DECLAREContigPutFunc(putcontig8bitYCbCr22tile) -{ - uint32* cp2; - int32 incr = 2*toskew+w; - (void) y; - fromskew = (fromskew / 2) * 6; - cp2 = cp+w+toskew; - while (h>=2) { - x = w; - while (x>=2) { - uint32 Cb = pp[4]; - uint32 Cr = pp[5]; - YCbCrtoRGB(cp[0], pp[0]); - YCbCrtoRGB(cp[1], pp[1]); - YCbCrtoRGB(cp2[0], pp[2]); - YCbCrtoRGB(cp2[1], pp[3]); - cp += 2; - cp2 += 2; - pp += 6; - x -= 2; - } - if (x==1) { - uint32 Cb = pp[4]; - uint32 Cr = pp[5]; - YCbCrtoRGB(cp[0], pp[0]); - YCbCrtoRGB(cp2[0], pp[2]); - cp ++ ; - cp2 ++ ; - pp += 6; - } - cp += incr; - cp2 += incr; - pp += fromskew; - h-=2; - } - if (h==1) { - x = w; - while (x>=2) { - uint32 Cb = pp[4]; - uint32 Cr = pp[5]; - YCbCrtoRGB(cp[0], pp[0]); - YCbCrtoRGB(cp[1], pp[1]); - cp += 2; - cp2 += 2; - pp += 6; - x -= 2; - } - if (x==1) { - uint32 Cb = pp[4]; - uint32 Cr = pp[5]; - YCbCrtoRGB(cp[0], pp[0]); - } - } -} - -/* - * 8-bit packed YCbCr samples w/ 2,1 subsampling => RGB - */ -DECLAREContigPutFunc(putcontig8bitYCbCr21tile) -{ - (void) y; - fromskew = (fromskew * 4) / 2; - do { - x = w>>1; - do { - int32 Cb = pp[2]; - int32 Cr = pp[3]; - - YCbCrtoRGB(cp[0], pp[0]); - YCbCrtoRGB(cp[1], pp[1]); - - cp += 2; - pp += 4; - } while (--x); - - if( (w&1) != 0 ) - { - int32 Cb = pp[2]; - int32 Cr = pp[3]; - - YCbCrtoRGB(cp[0], pp[0]); - - cp += 1; - pp += 4; - } - - cp += toskew; - pp += fromskew; - } while (--h); -} - -/* - * 8-bit packed YCbCr samples w/ 1,2 subsampling => RGB - */ -DECLAREContigPutFunc(putcontig8bitYCbCr12tile) -{ - uint32* cp2; - int32 incr = 2*toskew+w; - (void) y; - fromskew = (fromskew / 2) * 4; - cp2 = cp+w+toskew; - while (h>=2) { - x = w; - do { - uint32 Cb = pp[2]; - uint32 Cr = pp[3]; - YCbCrtoRGB(cp[0], pp[0]); - YCbCrtoRGB(cp2[0], pp[1]); - cp ++; - cp2 ++; - pp += 4; - } while (--x); - cp += incr; - cp2 += incr; - pp += fromskew; - h-=2; - } - if (h==1) { - x = w; - do { - uint32 Cb = pp[2]; - uint32 Cr = pp[3]; - YCbCrtoRGB(cp[0], pp[0]); - cp ++; - pp += 4; - } while (--x); - } -} - -/* - * 8-bit packed YCbCr samples w/ no subsampling => RGB - */ -DECLAREContigPutFunc(putcontig8bitYCbCr11tile) -{ - (void) y; - fromskew *= 3; - do { - x = w; /* was x = w>>1; patched 2000/09/25 warmerda@home.com */ - do { - int32 Cb = pp[1]; - int32 Cr = pp[2]; - - YCbCrtoRGB(*cp++, pp[0]); - - pp += 3; - } while (--x); - cp += toskew; - pp += fromskew; - } while (--h); -} - -/* - * 8-bit packed YCbCr samples w/ no subsampling => RGB - */ -DECLARESepPutFunc(putseparate8bitYCbCr11tile) -{ - (void) y; - (void) a; - /* TODO: naming of input vars is still off, change obfuscating declaration inside define, or resolve obfuscation */ - while (h-- > 0) { - x = w; - do { - uint32 dr, dg, db; - TIFFYCbCrtoRGB(img->ycbcr,*r++,*g++,*b++,&dr,&dg,&db); - *cp++ = PACK(dr,dg,db); - } while (--x); - SKEW(r, g, b, fromskew); - cp += toskew; - } -} -#undef YCbCrtoRGB - -static int -initYCbCrConversion(TIFFRGBAImage* img) -{ - static const char module[] = "initYCbCrConversion"; - - float *luma, *refBlackWhite; - - if (img->ycbcr == NULL) { - img->ycbcr = (TIFFYCbCrToRGB*) _TIFFmalloc( - TIFFroundup_32(sizeof (TIFFYCbCrToRGB), sizeof (long)) - + 4*256*sizeof (TIFFRGBValue) - + 2*256*sizeof (int) - + 3*256*sizeof (int32) - ); - if (img->ycbcr == NULL) { - TIFFErrorExt(img->tif->tif_clientdata, module, - "No space for YCbCr->RGB conversion state"); - return (0); - } - } - - TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRCOEFFICIENTS, &luma); - TIFFGetFieldDefaulted(img->tif, TIFFTAG_REFERENCEBLACKWHITE, - &refBlackWhite); - if (TIFFYCbCrToRGBInit(img->ycbcr, luma, refBlackWhite) < 0) - return(0); - return (1); -} - -static tileContigRoutine -initCIELabConversion(TIFFRGBAImage* img) -{ - static const char module[] = "initCIELabConversion"; - - float *whitePoint; - float refWhite[3]; - - if (!img->cielab) { - img->cielab = (TIFFCIELabToRGB *) - _TIFFmalloc(sizeof(TIFFCIELabToRGB)); - if (!img->cielab) { - TIFFErrorExt(img->tif->tif_clientdata, module, - "No space for CIE L*a*b*->RGB conversion state."); - return NULL; - } - } - - TIFFGetFieldDefaulted(img->tif, TIFFTAG_WHITEPOINT, &whitePoint); - refWhite[1] = 100.0F; - refWhite[0] = whitePoint[0] / whitePoint[1] * refWhite[1]; - refWhite[2] = (1.0F - whitePoint[0] - whitePoint[1]) - / whitePoint[1] * refWhite[1]; - if (TIFFCIELabToRGBInit(img->cielab, &display_sRGB, refWhite) < 0) { - TIFFErrorExt(img->tif->tif_clientdata, module, - "Failed to initialize CIE L*a*b*->RGB conversion state."); - _TIFFfree(img->cielab); - return NULL; - } - - return putcontig8bitCIELab; -} - -/* - * Greyscale images with less than 8 bits/sample are handled - * with a table to avoid lots of shifts and masks. The table - * is setup so that put*bwtile (below) can retrieve 8/bitspersample - * pixel values simply by indexing into the table with one - * number. - */ -static int -makebwmap(TIFFRGBAImage* img) -{ - TIFFRGBValue* Map = img->Map; - int bitspersample = img->bitspersample; - int nsamples = 8 / bitspersample; - int i; - uint32* p; - - if( nsamples == 0 ) - nsamples = 1; - - img->BWmap = (uint32**) _TIFFmalloc( - 256*sizeof (uint32 *)+(256*nsamples*sizeof(uint32))); - if (img->BWmap == NULL) { - TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "No space for B&W mapping table"); - return (0); - } - p = (uint32*)(img->BWmap + 256); - for (i = 0; i < 256; i++) { - TIFFRGBValue c; - img->BWmap[i] = p; - switch (bitspersample) { -#define GREY(x) c = Map[x]; *p++ = PACK(c,c,c); - case 1: - GREY(i>>7); - GREY((i>>6)&1); - GREY((i>>5)&1); - GREY((i>>4)&1); - GREY((i>>3)&1); - GREY((i>>2)&1); - GREY((i>>1)&1); - GREY(i&1); - break; - case 2: - GREY(i>>6); - GREY((i>>4)&3); - GREY((i>>2)&3); - GREY(i&3); - break; - case 4: - GREY(i>>4); - GREY(i&0xf); - break; - case 8: - case 16: - GREY(i); - break; - } -#undef GREY - } - return (1); -} - -/* - * Construct a mapping table to convert from the range - * of the data samples to [0,255] --for display. This - * process also handles inverting B&W images when needed. - */ -static int -setupMap(TIFFRGBAImage* img) -{ - int32 x, range; - - range = (int32)((1L<bitspersample)-1); - - /* treat 16 bit the same as eight bit */ - if( img->bitspersample == 16 ) - range = (int32) 255; - - img->Map = (TIFFRGBValue*) _TIFFmalloc((range+1) * sizeof (TIFFRGBValue)); - if (img->Map == NULL) { - TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), - "No space for photometric conversion table"); - return (0); - } - if (img->photometric == PHOTOMETRIC_MINISWHITE) { - for (x = 0; x <= range; x++) - img->Map[x] = (TIFFRGBValue) (((range - x) * 255) / range); - } else { - for (x = 0; x <= range; x++) - img->Map[x] = (TIFFRGBValue) ((x * 255) / range); - } - if (img->bitspersample <= 16 && - (img->photometric == PHOTOMETRIC_MINISBLACK || - img->photometric == PHOTOMETRIC_MINISWHITE)) { - /* - * Use photometric mapping table to construct - * unpacking tables for samples <= 8 bits. - */ - if (!makebwmap(img)) - return (0); - /* no longer need Map, free it */ - _TIFFfree(img->Map), img->Map = NULL; - } - return (1); -} - -static int -checkcmap(TIFFRGBAImage* img) -{ - uint16* r = img->redcmap; - uint16* g = img->greencmap; - uint16* b = img->bluecmap; - long n = 1L<bitspersample; - - while (n-- > 0) - if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256) - return (16); - return (8); -} - -static void -cvtcmap(TIFFRGBAImage* img) -{ - uint16* r = img->redcmap; - uint16* g = img->greencmap; - uint16* b = img->bluecmap; - long i; - - for (i = (1L<bitspersample)-1; i >= 0; i--) { -#define CVT(x) ((uint16)((x)>>8)) - r[i] = CVT(r[i]); - g[i] = CVT(g[i]); - b[i] = CVT(b[i]); -#undef CVT - } -} - -/* - * Palette images with <= 8 bits/sample are handled - * with a table to avoid lots of shifts and masks. The table - * is setup so that put*cmaptile (below) can retrieve 8/bitspersample - * pixel values simply by indexing into the table with one - * number. - */ -static int -makecmap(TIFFRGBAImage* img) -{ - int bitspersample = img->bitspersample; - int nsamples = 8 / bitspersample; - uint16* r = img->redcmap; - uint16* g = img->greencmap; - uint16* b = img->bluecmap; - uint32 *p; - int i; - - img->PALmap = (uint32**) _TIFFmalloc( - 256*sizeof (uint32 *)+(256*nsamples*sizeof(uint32))); - if (img->PALmap == NULL) { - TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "No space for Palette mapping table"); - return (0); - } - p = (uint32*)(img->PALmap + 256); - for (i = 0; i < 256; i++) { - TIFFRGBValue c; - img->PALmap[i] = p; -#define CMAP(x) c = (TIFFRGBValue) x; *p++ = PACK(r[c]&0xff, g[c]&0xff, b[c]&0xff); - switch (bitspersample) { - case 1: - CMAP(i>>7); - CMAP((i>>6)&1); - CMAP((i>>5)&1); - CMAP((i>>4)&1); - CMAP((i>>3)&1); - CMAP((i>>2)&1); - CMAP((i>>1)&1); - CMAP(i&1); - break; - case 2: - CMAP(i>>6); - CMAP((i>>4)&3); - CMAP((i>>2)&3); - CMAP(i&3); - break; - case 4: - CMAP(i>>4); - CMAP(i&0xf); - break; - case 8: - CMAP(i); - break; - } -#undef CMAP - } - return (1); -} - -/* - * Construct any mapping table used - * by the associated put routine. - */ -static int -buildMap(TIFFRGBAImage* img) -{ - switch (img->photometric) { - case PHOTOMETRIC_RGB: - case PHOTOMETRIC_YCBCR: - case PHOTOMETRIC_SEPARATED: - if (img->bitspersample == 8) - break; - /* fall thru... */ - case PHOTOMETRIC_MINISBLACK: - case PHOTOMETRIC_MINISWHITE: - if (!setupMap(img)) - return (0); - break; - case PHOTOMETRIC_PALETTE: - /* - * Convert 16-bit colormap to 8-bit (unless it looks - * like an old-style 8-bit colormap). - */ - if (checkcmap(img) == 16) - cvtcmap(img); - else - TIFFWarningExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "Assuming 8-bit colormap"); - /* - * Use mapping table and colormap to construct - * unpacking tables for samples < 8 bits. - */ - if (img->bitspersample <= 8 && !makecmap(img)) - return (0); - break; - } - return (1); -} - -/* - * Select the appropriate conversion routine for packed data. - */ -static int -PickContigCase(TIFFRGBAImage* img) -{ - img->get = TIFFIsTiled(img->tif) ? gtTileContig : gtStripContig; - img->put.contig = NULL; - switch (img->photometric) { - case PHOTOMETRIC_RGB: - switch (img->bitspersample) { - case 8: - if (img->alpha == EXTRASAMPLE_ASSOCALPHA) - img->put.contig = putRGBAAcontig8bittile; - else if (img->alpha == EXTRASAMPLE_UNASSALPHA) - { - if (BuildMapUaToAa(img)) - img->put.contig = putRGBUAcontig8bittile; - } - else - img->put.contig = putRGBcontig8bittile; - break; - case 16: - if (img->alpha == EXTRASAMPLE_ASSOCALPHA) - { - if (BuildMapBitdepth16To8(img)) - img->put.contig = putRGBAAcontig16bittile; - } - else if (img->alpha == EXTRASAMPLE_UNASSALPHA) - { - if (BuildMapBitdepth16To8(img) && - BuildMapUaToAa(img)) - img->put.contig = putRGBUAcontig16bittile; - } - else - { - if (BuildMapBitdepth16To8(img)) - img->put.contig = putRGBcontig16bittile; - } - break; - } - break; - case PHOTOMETRIC_SEPARATED: - if (buildMap(img)) { - if (img->bitspersample == 8) { - if (!img->Map) - img->put.contig = putRGBcontig8bitCMYKtile; - else - img->put.contig = putRGBcontig8bitCMYKMaptile; - } - } - break; - case PHOTOMETRIC_PALETTE: - if (buildMap(img)) { - switch (img->bitspersample) { - case 8: - img->put.contig = put8bitcmaptile; - break; - case 4: - img->put.contig = put4bitcmaptile; - break; - case 2: - img->put.contig = put2bitcmaptile; - break; - case 1: - img->put.contig = put1bitcmaptile; - break; - } - } - break; - case PHOTOMETRIC_MINISWHITE: - case PHOTOMETRIC_MINISBLACK: - if (buildMap(img)) { - switch (img->bitspersample) { - case 16: - img->put.contig = put16bitbwtile; - break; - case 8: - if (img->alpha && img->samplesperpixel == 2) - img->put.contig = putagreytile; - else - img->put.contig = putgreytile; - break; - case 4: - img->put.contig = put4bitbwtile; - break; - case 2: - img->put.contig = put2bitbwtile; - break; - case 1: - img->put.contig = put1bitbwtile; - break; - } - } - break; - case PHOTOMETRIC_YCBCR: - if ((img->bitspersample==8) && (img->samplesperpixel==3)) - { - if (initYCbCrConversion(img)!=0) - { - /* - * The 6.0 spec says that subsampling must be - * one of 1, 2, or 4, and that vertical subsampling - * must always be <= horizontal subsampling; so - * there are only a few possibilities and we just - * enumerate the cases. - * Joris: added support for the [1,2] case, nonetheless, to accomodate - * some OJPEG files - */ - uint16 SubsamplingHor; - uint16 SubsamplingVer; - TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRSUBSAMPLING, &SubsamplingHor, &SubsamplingVer); - switch ((SubsamplingHor<<4)|SubsamplingVer) { - case 0x44: - img->put.contig = putcontig8bitYCbCr44tile; - break; - case 0x42: - img->put.contig = putcontig8bitYCbCr42tile; - break; - case 0x41: - img->put.contig = putcontig8bitYCbCr41tile; - break; - case 0x22: - img->put.contig = putcontig8bitYCbCr22tile; - break; - case 0x21: - img->put.contig = putcontig8bitYCbCr21tile; - break; - case 0x12: - img->put.contig = putcontig8bitYCbCr12tile; - break; - case 0x11: - img->put.contig = putcontig8bitYCbCr11tile; - break; - } - } - } - break; - case PHOTOMETRIC_CIELAB: - if (buildMap(img)) { - if (img->bitspersample == 8) - img->put.contig = initCIELabConversion(img); - break; - } - } - return ((img->get!=NULL) && (img->put.contig!=NULL)); -} - -/* - * Select the appropriate conversion routine for unpacked data. - * - * NB: we assume that unpacked single channel data is directed - * to the "packed routines. - */ -static int -PickSeparateCase(TIFFRGBAImage* img) -{ - img->get = TIFFIsTiled(img->tif) ? gtTileSeparate : gtStripSeparate; - img->put.separate = NULL; - switch (img->photometric) { - case PHOTOMETRIC_MINISWHITE: - case PHOTOMETRIC_MINISBLACK: - /* greyscale images processed pretty much as RGB by gtTileSeparate */ - case PHOTOMETRIC_RGB: - switch (img->bitspersample) { - case 8: - if (img->alpha == EXTRASAMPLE_ASSOCALPHA) - img->put.separate = putRGBAAseparate8bittile; - else if (img->alpha == EXTRASAMPLE_UNASSALPHA) - { - if (BuildMapUaToAa(img)) - img->put.separate = putRGBUAseparate8bittile; - } - else - img->put.separate = putRGBseparate8bittile; - break; - case 16: - if (img->alpha == EXTRASAMPLE_ASSOCALPHA) - { - if (BuildMapBitdepth16To8(img)) - img->put.separate = putRGBAAseparate16bittile; - } - else if (img->alpha == EXTRASAMPLE_UNASSALPHA) - { - if (BuildMapBitdepth16To8(img) && - BuildMapUaToAa(img)) - img->put.separate = putRGBUAseparate16bittile; - } - else - { - if (BuildMapBitdepth16To8(img)) - img->put.separate = putRGBseparate16bittile; - } - break; - } - break; - case PHOTOMETRIC_SEPARATED: - if (img->bitspersample == 8 && img->samplesperpixel == 4) - { - img->alpha = 1; // Not alpha, but seems like the only way to get 4th band - img->put.separate = putCMYKseparate8bittile; - } - break; - case PHOTOMETRIC_YCBCR: - if ((img->bitspersample==8) && (img->samplesperpixel==3)) - { - if (initYCbCrConversion(img)!=0) - { - uint16 hs, vs; - TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRSUBSAMPLING, &hs, &vs); - switch ((hs<<4)|vs) { - case 0x11: - img->put.separate = putseparate8bitYCbCr11tile; - break; - /* TODO: add other cases here */ - } - } - } - break; - } - return ((img->get!=NULL) && (img->put.separate!=NULL)); -} - -static int -BuildMapUaToAa(TIFFRGBAImage* img) -{ - static const char module[]="BuildMapUaToAa"; - uint8* m; - uint16 na,nv; - assert(img->UaToAa==NULL); - img->UaToAa=_TIFFmalloc(65536); - if (img->UaToAa==NULL) - { - TIFFErrorExt(img->tif->tif_clientdata,module,"Out of memory"); - return(0); - } - m=img->UaToAa; - for (na=0; na<256; na++) - { - for (nv=0; nv<256; nv++) - *m++=(nv*na+127)/255; - } - return(1); -} - -static int -BuildMapBitdepth16To8(TIFFRGBAImage* img) -{ - static const char module[]="BuildMapBitdepth16To8"; - uint8* m; - uint32 n; - assert(img->Bitdepth16To8==NULL); - img->Bitdepth16To8=_TIFFmalloc(65536); - if (img->Bitdepth16To8==NULL) - { - TIFFErrorExt(img->tif->tif_clientdata,module,"Out of memory"); - return(0); - } - m=img->Bitdepth16To8; - for (n=0; n<65536; n++) - *m++=(n+128)/257; - return(1); -} - - -/* - * Read a whole strip off data from the file, and convert to RGBA form. - * If this is the last strip, then it will only contain the portion of - * the strip that is actually within the image space. The result is - * organized in bottom to top form. - */ - - -int -TIFFReadRGBAStrip(TIFF* tif, uint32 row, uint32 * raster ) - -{ - char emsg[1024] = ""; - TIFFRGBAImage img; - int ok; - uint32 rowsperstrip, rows_to_read; - - if( TIFFIsTiled( tif ) ) - { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), - "Can't use TIFFReadRGBAStrip() with tiled file."); - return (0); - } - - TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); - if( (row % rowsperstrip) != 0 ) - { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), - "Row passed to TIFFReadRGBAStrip() must be first in a strip."); - return (0); - } - - if (TIFFRGBAImageOK(tif, emsg) && TIFFRGBAImageBegin(&img, tif, 0, emsg)) { - - img.row_offset = row; - img.col_offset = 0; - - if( row + rowsperstrip > img.height ) - rows_to_read = img.height - row; - else - rows_to_read = rowsperstrip; - - ok = TIFFRGBAImageGet(&img, raster, img.width, rows_to_read ); - - TIFFRGBAImageEnd(&img); - } else { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", emsg); - ok = 0; - } - - return (ok); -} - -/* - * Read a whole tile off data from the file, and convert to RGBA form. - * The returned RGBA data is organized from bottom to top of tile, - * and may include zeroed areas if the tile extends off the image. - */ - -int -TIFFReadRGBATile(TIFF* tif, uint32 col, uint32 row, uint32 * raster) - -{ - char emsg[1024] = ""; - TIFFRGBAImage img; - int ok; - uint32 tile_xsize, tile_ysize; - uint32 read_xsize, read_ysize; - uint32 i_row; - - /* - * Verify that our request is legal - on a tile file, and on a - * tile boundary. - */ - - if( !TIFFIsTiled( tif ) ) - { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), - "Can't use TIFFReadRGBATile() with stripped file."); - return (0); - } - - TIFFGetFieldDefaulted(tif, TIFFTAG_TILEWIDTH, &tile_xsize); - TIFFGetFieldDefaulted(tif, TIFFTAG_TILELENGTH, &tile_ysize); - if( (col % tile_xsize) != 0 || (row % tile_ysize) != 0 ) - { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), - "Row/col passed to TIFFReadRGBATile() must be top" - "left corner of a tile."); - return (0); - } - - /* - * Setup the RGBA reader. - */ - - if (!TIFFRGBAImageOK(tif, emsg) - || !TIFFRGBAImageBegin(&img, tif, 0, emsg)) { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", emsg); - return( 0 ); - } - - /* - * The TIFFRGBAImageGet() function doesn't allow us to get off the - * edge of the image, even to fill an otherwise valid tile. So we - * figure out how much we can read, and fix up the tile buffer to - * a full tile configuration afterwards. - */ - - if( row + tile_ysize > img.height ) - read_ysize = img.height - row; - else - read_ysize = tile_ysize; - - if( col + tile_xsize > img.width ) - read_xsize = img.width - col; - else - read_xsize = tile_xsize; - - /* - * Read the chunk of imagery. - */ - - img.row_offset = row; - img.col_offset = col; - - ok = TIFFRGBAImageGet(&img, raster, read_xsize, read_ysize ); - - TIFFRGBAImageEnd(&img); - - /* - * If our read was incomplete we will need to fix up the tile by - * shifting the data around as if a full tile of data is being returned. - * - * This is all the more complicated because the image is organized in - * bottom to top format. - */ - - if( read_xsize == tile_xsize && read_ysize == tile_ysize ) - return( ok ); - - for( i_row = 0; i_row < read_ysize; i_row++ ) { - memmove( raster + (tile_ysize - i_row - 1) * tile_xsize, - raster + (read_ysize - i_row - 1) * read_xsize, - read_xsize * sizeof(uint32) ); - _TIFFmemset( raster + (tile_ysize - i_row - 1) * tile_xsize+read_xsize, - 0, sizeof(uint32) * (tile_xsize - read_xsize) ); - } - - for( i_row = read_ysize; i_row < tile_ysize; i_row++ ) { - _TIFFmemset( raster + (tile_ysize - i_row - 1) * tile_xsize, - 0, sizeof(uint32) * tile_xsize ); - } - - return (ok); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_getimage.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1991-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library + * + * Read and return a packed RGBA image. + */ +#include "tiffiop.h" +#include + +static int gtTileContig(TIFFRGBAImage*, uint32*, uint32, uint32); +static int gtTileSeparate(TIFFRGBAImage*, uint32*, uint32, uint32); +static int gtStripContig(TIFFRGBAImage*, uint32*, uint32, uint32); +static int gtStripSeparate(TIFFRGBAImage*, uint32*, uint32, uint32); +static int PickContigCase(TIFFRGBAImage*); +static int PickSeparateCase(TIFFRGBAImage*); + +static int BuildMapUaToAa(TIFFRGBAImage* img); +static int BuildMapBitdepth16To8(TIFFRGBAImage* img); + +static const char photoTag[] = "PhotometricInterpretation"; + +/* + * Helper constants used in Orientation tag handling + */ +#define FLIP_VERTICALLY 0x01 +#define FLIP_HORIZONTALLY 0x02 + +/* + * Color conversion constants. We will define display types here. + */ + +static const TIFFDisplay display_sRGB = { + { /* XYZ -> luminance matrix */ + { 3.2410F, -1.5374F, -0.4986F }, + { -0.9692F, 1.8760F, 0.0416F }, + { 0.0556F, -0.2040F, 1.0570F } + }, + 100.0F, 100.0F, 100.0F, /* Light o/p for reference white */ + 255, 255, 255, /* Pixel values for ref. white */ + 1.0F, 1.0F, 1.0F, /* Residual light o/p for black pixel */ + 2.4F, 2.4F, 2.4F, /* Gamma values for the three guns */ +}; + +/* + * Check the image to see if TIFFReadRGBAImage can deal with it. + * 1/0 is returned according to whether or not the image can + * be handled. If 0 is returned, emsg contains the reason + * why it is being rejected. + */ +int +TIFFRGBAImageOK(TIFF* tif, char emsg[1024]) +{ + TIFFDirectory* td = &tif->tif_dir; + uint16 photometric; + int colorchannels; + + if (!tif->tif_decodestatus) { + sprintf(emsg, "Sorry, requested compression method is not configured"); + return (0); + } + switch (td->td_bitspersample) { + case 1: + case 2: + case 4: + case 8: + case 16: + break; + default: + sprintf(emsg, "Sorry, can not handle images with %d-bit samples", + td->td_bitspersample); + return (0); + } + colorchannels = td->td_samplesperpixel - td->td_extrasamples; + if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric)) { + switch (colorchannels) { + case 1: + photometric = PHOTOMETRIC_MINISBLACK; + break; + case 3: + photometric = PHOTOMETRIC_RGB; + break; + default: + sprintf(emsg, "Missing needed %s tag", photoTag); + return (0); + } + } + switch (photometric) { + case PHOTOMETRIC_MINISWHITE: + case PHOTOMETRIC_MINISBLACK: + case PHOTOMETRIC_PALETTE: + if (td->td_planarconfig == PLANARCONFIG_CONTIG + && td->td_samplesperpixel != 1 + && td->td_bitspersample < 8 ) { + sprintf(emsg, + "Sorry, can not handle contiguous data with %s=%d, " + "and %s=%d and Bits/Sample=%d", + photoTag, photometric, + "Samples/pixel", td->td_samplesperpixel, + td->td_bitspersample); + return (0); + } + /* + * We should likely validate that any extra samples are either + * to be ignored, or are alpha, and if alpha we should try to use + * them. But for now we won't bother with this. + */ + break; + case PHOTOMETRIC_YCBCR: + /* + * TODO: if at all meaningful and useful, make more complete + * support check here, or better still, refactor to let supporting + * code decide whether there is support and what meaningfull + * error to return + */ + break; + case PHOTOMETRIC_RGB: + if (colorchannels < 3) { + sprintf(emsg, "Sorry, can not handle RGB image with %s=%d", + "Color channels", colorchannels); + return (0); + } + break; + case PHOTOMETRIC_SEPARATED: + { + uint16 inkset; + TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset); + if (inkset != INKSET_CMYK) { + sprintf(emsg, + "Sorry, can not handle separated image with %s=%d", + "InkSet", inkset); + return 0; + } + if (td->td_samplesperpixel < 4) { + sprintf(emsg, + "Sorry, can not handle separated image with %s=%d", + "Samples/pixel", td->td_samplesperpixel); + return 0; + } + break; + } + case PHOTOMETRIC_LOGL: + if (td->td_compression != COMPRESSION_SGILOG) { + sprintf(emsg, "Sorry, LogL data must have %s=%d", + "Compression", COMPRESSION_SGILOG); + return (0); + } + break; + case PHOTOMETRIC_LOGLUV: + if (td->td_compression != COMPRESSION_SGILOG && + td->td_compression != COMPRESSION_SGILOG24) { + sprintf(emsg, "Sorry, LogLuv data must have %s=%d or %d", + "Compression", COMPRESSION_SGILOG, COMPRESSION_SGILOG24); + return (0); + } + if (td->td_planarconfig != PLANARCONFIG_CONTIG) { + sprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d", + "Planarconfiguration", td->td_planarconfig); + return (0); + } + break; + case PHOTOMETRIC_CIELAB: + break; + default: + sprintf(emsg, "Sorry, can not handle image with %s=%d", + photoTag, photometric); + return (0); + } + return (1); +} + +void +TIFFRGBAImageEnd(TIFFRGBAImage* img) +{ + if (img->Map) + _TIFFfree(img->Map), img->Map = NULL; + if (img->BWmap) + _TIFFfree(img->BWmap), img->BWmap = NULL; + if (img->PALmap) + _TIFFfree(img->PALmap), img->PALmap = NULL; + if (img->ycbcr) + _TIFFfree(img->ycbcr), img->ycbcr = NULL; + if (img->cielab) + _TIFFfree(img->cielab), img->cielab = NULL; + if (img->UaToAa) + _TIFFfree(img->UaToAa), img->UaToAa = NULL; + if (img->Bitdepth16To8) + _TIFFfree(img->Bitdepth16To8), img->Bitdepth16To8 = NULL; + + if( img->redcmap ) { + _TIFFfree( img->redcmap ); + _TIFFfree( img->greencmap ); + _TIFFfree( img->bluecmap ); + img->redcmap = img->greencmap = img->bluecmap = NULL; + } +} + +static int +isCCITTCompression(TIFF* tif) +{ + uint16 compress; + TIFFGetField(tif, TIFFTAG_COMPRESSION, &compress); + return (compress == COMPRESSION_CCITTFAX3 || + compress == COMPRESSION_CCITTFAX4 || + compress == COMPRESSION_CCITTRLE || + compress == COMPRESSION_CCITTRLEW); +} + +int +TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) +{ + uint16* sampleinfo; + uint16 extrasamples; + uint16 planarconfig; + uint16 compress; + int colorchannels; + uint16 *red_orig, *green_orig, *blue_orig; + int n_color; + + /* Initialize to normal values */ + img->row_offset = 0; + img->col_offset = 0; + img->redcmap = NULL; + img->greencmap = NULL; + img->bluecmap = NULL; + img->req_orientation = ORIENTATION_BOTLEFT; /* It is the default */ + + img->tif = tif; + img->stoponerr = stop; + TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &img->bitspersample); + switch (img->bitspersample) { + case 1: + case 2: + case 4: + case 8: + case 16: + break; + default: + sprintf(emsg, "Sorry, can not handle images with %d-bit samples", + img->bitspersample); + goto fail_return; + } + img->alpha = 0; + TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &img->samplesperpixel); + TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, + &extrasamples, &sampleinfo); + if (extrasamples >= 1) + { + switch (sampleinfo[0]) { + case EXTRASAMPLE_UNSPECIFIED: /* Workaround for some images without */ + if (img->samplesperpixel > 3) /* correct info about alpha channel */ + img->alpha = EXTRASAMPLE_ASSOCALPHA; + break; + case EXTRASAMPLE_ASSOCALPHA: /* data is pre-multiplied */ + case EXTRASAMPLE_UNASSALPHA: /* data is not pre-multiplied */ + img->alpha = sampleinfo[0]; + break; + } + } + +#ifdef DEFAULT_EXTRASAMPLE_AS_ALPHA + if( !TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) + img->photometric = PHOTOMETRIC_MINISWHITE; + + if( extrasamples == 0 + && img->samplesperpixel == 4 + && img->photometric == PHOTOMETRIC_RGB ) + { + img->alpha = EXTRASAMPLE_ASSOCALPHA; + extrasamples = 1; + } +#endif + + colorchannels = img->samplesperpixel - extrasamples; + TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &compress); + TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfig); + if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) { + switch (colorchannels) { + case 1: + if (isCCITTCompression(tif)) + img->photometric = PHOTOMETRIC_MINISWHITE; + else + img->photometric = PHOTOMETRIC_MINISBLACK; + break; + case 3: + img->photometric = PHOTOMETRIC_RGB; + break; + default: + sprintf(emsg, "Missing needed %s tag", photoTag); + goto fail_return; + } + } + switch (img->photometric) { + case PHOTOMETRIC_PALETTE: + if (!TIFFGetField(tif, TIFFTAG_COLORMAP, + &red_orig, &green_orig, &blue_orig)) { + sprintf(emsg, "Missing required \"Colormap\" tag"); + goto fail_return; + } + + /* copy the colormaps so we can modify them */ + n_color = (1L << img->bitspersample); + img->redcmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); + img->greencmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); + img->bluecmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); + if( !img->redcmap || !img->greencmap || !img->bluecmap ) { + sprintf(emsg, "Out of memory for colormap copy"); + goto fail_return; + } + + _TIFFmemcpy( img->redcmap, red_orig, n_color * 2 ); + _TIFFmemcpy( img->greencmap, green_orig, n_color * 2 ); + _TIFFmemcpy( img->bluecmap, blue_orig, n_color * 2 ); + + /* fall thru... */ + case PHOTOMETRIC_MINISWHITE: + case PHOTOMETRIC_MINISBLACK: + if (planarconfig == PLANARCONFIG_CONTIG + && img->samplesperpixel != 1 + && img->bitspersample < 8 ) { + sprintf(emsg, + "Sorry, can not handle contiguous data with %s=%d, " + "and %s=%d and Bits/Sample=%d", + photoTag, img->photometric, + "Samples/pixel", img->samplesperpixel, + img->bitspersample); + goto fail_return; + } + break; + case PHOTOMETRIC_YCBCR: + /* It would probably be nice to have a reality check here. */ + if (planarconfig == PLANARCONFIG_CONTIG) + /* can rely on libjpeg to convert to RGB */ + /* XXX should restore current state on exit */ + switch (compress) { + case COMPRESSION_JPEG: + /* + * TODO: when complete tests verify complete desubsampling + * and YCbCr handling, remove use of TIFFTAG_JPEGCOLORMODE in + * favor of tif_getimage.c native handling + */ + TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB); + img->photometric = PHOTOMETRIC_RGB; + break; + default: + /* do nothing */; + break; + } + /* + * TODO: if at all meaningful and useful, make more complete + * support check here, or better still, refactor to let supporting + * code decide whether there is support and what meaningfull + * error to return + */ + break; + case PHOTOMETRIC_RGB: + if (colorchannels < 3) { + sprintf(emsg, "Sorry, can not handle RGB image with %s=%d", + "Color channels", colorchannels); + goto fail_return; + } + break; + case PHOTOMETRIC_SEPARATED: + { + uint16 inkset; + TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset); + if (inkset != INKSET_CMYK) { + sprintf(emsg, "Sorry, can not handle separated image with %s=%d", + "InkSet", inkset); + goto fail_return; + } + if (img->samplesperpixel < 4) { + sprintf(emsg, "Sorry, can not handle separated image with %s=%d", + "Samples/pixel", img->samplesperpixel); + goto fail_return; + } + } + break; + case PHOTOMETRIC_LOGL: + if (compress != COMPRESSION_SGILOG) { + sprintf(emsg, "Sorry, LogL data must have %s=%d", + "Compression", COMPRESSION_SGILOG); + goto fail_return; + } + TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT); + img->photometric = PHOTOMETRIC_MINISBLACK; /* little white lie */ + img->bitspersample = 8; + break; + case PHOTOMETRIC_LOGLUV: + if (compress != COMPRESSION_SGILOG && compress != COMPRESSION_SGILOG24) { + sprintf(emsg, "Sorry, LogLuv data must have %s=%d or %d", + "Compression", COMPRESSION_SGILOG, COMPRESSION_SGILOG24); + goto fail_return; + } + if (planarconfig != PLANARCONFIG_CONTIG) { + sprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d", + "Planarconfiguration", planarconfig); + return (0); + } + TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT); + img->photometric = PHOTOMETRIC_RGB; /* little white lie */ + img->bitspersample = 8; + break; + case PHOTOMETRIC_CIELAB: + break; + default: + sprintf(emsg, "Sorry, can not handle image with %s=%d", + photoTag, img->photometric); + goto fail_return; + } + img->Map = NULL; + img->BWmap = NULL; + img->PALmap = NULL; + img->ycbcr = NULL; + img->cielab = NULL; + img->UaToAa = NULL; + img->Bitdepth16To8 = NULL; + TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width); + TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height); + TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation); + img->isContig = + !(planarconfig == PLANARCONFIG_SEPARATE && img->samplesperpixel > 1); + if (img->isContig) { + if (!PickContigCase(img)) { + sprintf(emsg, "Sorry, can not handle image"); + goto fail_return; + } + } else { + if (!PickSeparateCase(img)) { + sprintf(emsg, "Sorry, can not handle image"); + goto fail_return; + } + } + return 1; + + fail_return: + _TIFFfree( img->redcmap ); + _TIFFfree( img->greencmap ); + _TIFFfree( img->bluecmap ); + img->redcmap = img->greencmap = img->bluecmap = NULL; + return 0; +} + +int +TIFFRGBAImageGet(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) +{ + if (img->get == NULL) { + TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "No \"get\" routine setup"); + return (0); + } + if (img->put.any == NULL) { + TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), + "No \"put\" routine setupl; probably can not handle image format"); + return (0); + } + return (*img->get)(img, raster, w, h); +} + +/* + * Read the specified image into an ABGR-format rastertaking in account + * specified orientation. + */ +int +TIFFReadRGBAImageOriented(TIFF* tif, + uint32 rwidth, uint32 rheight, uint32* raster, + int orientation, int stop) +{ + char emsg[1024] = ""; + TIFFRGBAImage img; + int ok; + + if (TIFFRGBAImageOK(tif, emsg) && TIFFRGBAImageBegin(&img, tif, stop, emsg)) { + img.req_orientation = orientation; + /* XXX verify rwidth and rheight against width and height */ + ok = TIFFRGBAImageGet(&img, raster+(rheight-img.height)*rwidth, + rwidth, img.height); + TIFFRGBAImageEnd(&img); + } else { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", emsg); + ok = 0; + } + return (ok); +} + +/* + * Read the specified image into an ABGR-format raster. Use bottom left + * origin for raster by default. + */ +int +TIFFReadRGBAImage(TIFF* tif, + uint32 rwidth, uint32 rheight, uint32* raster, int stop) +{ + return TIFFReadRGBAImageOriented(tif, rwidth, rheight, raster, + ORIENTATION_BOTLEFT, stop); +} + +static int +setorientation(TIFFRGBAImage* img) +{ + switch (img->orientation) { + case ORIENTATION_TOPLEFT: + case ORIENTATION_LEFTTOP: + if (img->req_orientation == ORIENTATION_TOPRIGHT || + img->req_orientation == ORIENTATION_RIGHTTOP) + return FLIP_HORIZONTALLY; + else if (img->req_orientation == ORIENTATION_BOTRIGHT || + img->req_orientation == ORIENTATION_RIGHTBOT) + return FLIP_HORIZONTALLY | FLIP_VERTICALLY; + else if (img->req_orientation == ORIENTATION_BOTLEFT || + img->req_orientation == ORIENTATION_LEFTBOT) + return FLIP_VERTICALLY; + else + return 0; + case ORIENTATION_TOPRIGHT: + case ORIENTATION_RIGHTTOP: + if (img->req_orientation == ORIENTATION_TOPLEFT || + img->req_orientation == ORIENTATION_LEFTTOP) + return FLIP_HORIZONTALLY; + else if (img->req_orientation == ORIENTATION_BOTRIGHT || + img->req_orientation == ORIENTATION_RIGHTBOT) + return FLIP_VERTICALLY; + else if (img->req_orientation == ORIENTATION_BOTLEFT || + img->req_orientation == ORIENTATION_LEFTBOT) + return FLIP_HORIZONTALLY | FLIP_VERTICALLY; + else + return 0; + case ORIENTATION_BOTRIGHT: + case ORIENTATION_RIGHTBOT: + if (img->req_orientation == ORIENTATION_TOPLEFT || + img->req_orientation == ORIENTATION_LEFTTOP) + return FLIP_HORIZONTALLY | FLIP_VERTICALLY; + else if (img->req_orientation == ORIENTATION_TOPRIGHT || + img->req_orientation == ORIENTATION_RIGHTTOP) + return FLIP_VERTICALLY; + else if (img->req_orientation == ORIENTATION_BOTLEFT || + img->req_orientation == ORIENTATION_LEFTBOT) + return FLIP_HORIZONTALLY; + else + return 0; + case ORIENTATION_BOTLEFT: + case ORIENTATION_LEFTBOT: + if (img->req_orientation == ORIENTATION_TOPLEFT || + img->req_orientation == ORIENTATION_LEFTTOP) + return FLIP_VERTICALLY; + else if (img->req_orientation == ORIENTATION_TOPRIGHT || + img->req_orientation == ORIENTATION_RIGHTTOP) + return FLIP_HORIZONTALLY | FLIP_VERTICALLY; + else if (img->req_orientation == ORIENTATION_BOTRIGHT || + img->req_orientation == ORIENTATION_RIGHTBOT) + return FLIP_HORIZONTALLY; + else + return 0; + default: /* NOTREACHED */ + return 0; + } +} + +/* + * Get an tile-organized image that has + * PlanarConfiguration contiguous if SamplesPerPixel > 1 + * or + * SamplesPerPixel == 1 + */ +static int +gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) +{ + TIFF* tif = img->tif; + tileContigRoutine put = img->put.contig; + uint32 col, row, y, rowstoread; + tmsize_t pos; + uint32 tw, th; + unsigned char* buf; + int32 fromskew, toskew; + uint32 nrow; + int ret = 1, flip; + + buf = (unsigned char*) _TIFFmalloc(TIFFTileSize(tif)); + if (buf == 0) { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "No space for tile buffer"); + return (0); + } + _TIFFmemset(buf, 0, TIFFTileSize(tif)); + TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw); + TIFFGetField(tif, TIFFTAG_TILELENGTH, &th); + + flip = setorientation(img); + if (flip & FLIP_VERTICALLY) { + y = h - 1; + toskew = -(int32)(tw + w); + } + else { + y = 0; + toskew = -(int32)(tw - w); + } + + for (row = 0; row < h; row += nrow) + { + rowstoread = th - (row + img->row_offset) % th; + nrow = (row + rowstoread > h ? h - row : rowstoread); + for (col = 0; col < w; col += tw) + { + if (TIFFReadTile(tif, buf, col+img->col_offset, + row+img->row_offset, 0, 0)==(tmsize_t)(-1) && img->stoponerr) + { + ret = 0; + break; + } + + pos = ((row+img->row_offset) % th) * TIFFTileRowSize(tif); + + if (col + tw > w) + { + /* + * Tile is clipped horizontally. Calculate + * visible portion and skewing factors. + */ + uint32 npix = w - col; + fromskew = tw - npix; + (*put)(img, raster+y*w+col, col, y, + npix, nrow, fromskew, toskew + fromskew, buf + pos); + } + else + { + (*put)(img, raster+y*w+col, col, y, tw, nrow, 0, toskew, buf + pos); + } + } + + y += (flip & FLIP_VERTICALLY ? -(int32) nrow : (int32) nrow); + } + _TIFFfree(buf); + + if (flip & FLIP_HORIZONTALLY) { + uint32 line; + + for (line = 0; line < h; line++) { + uint32 *left = raster + (line * w); + uint32 *right = left + w - 1; + + while ( left < right ) { + uint32 temp = *left; + *left = *right; + *right = temp; + left++, right--; + } + } + } + + return (ret); +} + +/* + * Get an tile-organized image that has + * SamplesPerPixel > 1 + * PlanarConfiguration separated + * We assume that all such images are RGB. + */ +static int +gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) +{ + TIFF* tif = img->tif; + tileSeparateRoutine put = img->put.separate; + uint32 col, row, y, rowstoread; + tmsize_t pos; + uint32 tw, th; + unsigned char* buf; + unsigned char* p0; + unsigned char* p1; + unsigned char* p2; + unsigned char* pa; + tmsize_t tilesize; + tmsize_t bufsize; + int32 fromskew, toskew; + int alpha = img->alpha; + uint32 nrow; + int ret = 1, flip; + int colorchannels; + + tilesize = TIFFTileSize(tif); + bufsize = TIFFSafeMultiply(tmsize_t,alpha?4:3,tilesize); + if (bufsize == 0) { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtTileSeparate"); + return (0); + } + buf = (unsigned char*) _TIFFmalloc(bufsize); + if (buf == 0) { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "No space for tile buffer"); + return (0); + } + _TIFFmemset(buf, 0, bufsize); + p0 = buf; + p1 = p0 + tilesize; + p2 = p1 + tilesize; + pa = (alpha?(p2+tilesize):NULL); + TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw); + TIFFGetField(tif, TIFFTAG_TILELENGTH, &th); + + flip = setorientation(img); + if (flip & FLIP_VERTICALLY) { + y = h - 1; + toskew = -(int32)(tw + w); + } + else { + y = 0; + toskew = -(int32)(tw - w); + } + + switch( img->photometric ) + { + case PHOTOMETRIC_MINISWHITE: + case PHOTOMETRIC_MINISBLACK: + case PHOTOMETRIC_PALETTE: + colorchannels = 1; + p2 = p1 = p0; + break; + + default: + colorchannels = 3; + break; + } + + for (row = 0; row < h; row += nrow) + { + rowstoread = th - (row + img->row_offset) % th; + nrow = (row + rowstoread > h ? h - row : rowstoread); + for (col = 0; col < w; col += tw) + { + if (TIFFReadTile(tif, p0, col+img->col_offset, + row+img->row_offset,0,0)==(tmsize_t)(-1) && img->stoponerr) + { + ret = 0; + break; + } + if (colorchannels > 1 + && TIFFReadTile(tif, p1, col+img->col_offset, + row+img->row_offset,0,1) == (tmsize_t)(-1) + && img->stoponerr) + { + ret = 0; + break; + } + if (colorchannels > 1 + && TIFFReadTile(tif, p2, col+img->col_offset, + row+img->row_offset,0,2) == (tmsize_t)(-1) + && img->stoponerr) + { + ret = 0; + break; + } + if (alpha + && TIFFReadTile(tif,pa,col+img->col_offset, + row+img->row_offset,0,colorchannels) == (tmsize_t)(-1) + && img->stoponerr) + { + ret = 0; + break; + } + + pos = ((row+img->row_offset) % th) * TIFFTileRowSize(tif); + + if (col + tw > w) + { + /* + * Tile is clipped horizontally. Calculate + * visible portion and skewing factors. + */ + uint32 npix = w - col; + fromskew = tw - npix; + (*put)(img, raster+y*w+col, col, y, + npix, nrow, fromskew, toskew + fromskew, + p0 + pos, p1 + pos, p2 + pos, (alpha?(pa+pos):NULL)); + } else { + (*put)(img, raster+y*w+col, col, y, + tw, nrow, 0, toskew, p0 + pos, p1 + pos, p2 + pos, (alpha?(pa+pos):NULL)); + } + } + + y += (flip & FLIP_VERTICALLY ?-(int32) nrow : (int32) nrow); + } + + if (flip & FLIP_HORIZONTALLY) { + uint32 line; + + for (line = 0; line < h; line++) { + uint32 *left = raster + (line * w); + uint32 *right = left + w - 1; + + while ( left < right ) { + uint32 temp = *left; + *left = *right; + *right = temp; + left++, right--; + } + } + } + + _TIFFfree(buf); + return (ret); +} + +/* + * Get a strip-organized image that has + * PlanarConfiguration contiguous if SamplesPerPixel > 1 + * or + * SamplesPerPixel == 1 + */ +static int +gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) +{ + TIFF* tif = img->tif; + tileContigRoutine put = img->put.contig; + uint32 row, y, nrow, nrowsub, rowstoread; + tmsize_t pos; + unsigned char* buf; + uint32 rowsperstrip; + uint16 subsamplinghor,subsamplingver; + uint32 imagewidth = img->width; + tmsize_t scanline; + int32 fromskew, toskew; + int ret = 1, flip; + + buf = (unsigned char*) _TIFFmalloc(TIFFStripSize(tif)); + if (buf == 0) { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for strip buffer"); + return (0); + } + _TIFFmemset(buf, 0, TIFFStripSize(tif)); + + flip = setorientation(img); + if (flip & FLIP_VERTICALLY) { + y = h - 1; + toskew = -(int32)(w + w); + } else { + y = 0; + toskew = -(int32)(w - w); + } + + TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); + TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRSUBSAMPLING, &subsamplinghor, &subsamplingver); + scanline = TIFFScanlineSize(tif); + fromskew = (w < imagewidth ? imagewidth - w : 0); + for (row = 0; row < h; row += nrow) + { + rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip; + nrow = (row + rowstoread > h ? h - row : rowstoread); + nrowsub = nrow; + if ((nrowsub%subsamplingver)!=0) + nrowsub+=subsamplingver-nrowsub%subsamplingver; + if (TIFFReadEncodedStrip(tif, + TIFFComputeStrip(tif,row+img->row_offset, 0), + buf, + ((row + img->row_offset)%rowsperstrip + nrowsub) * scanline)==(tmsize_t)(-1) + && img->stoponerr) + { + ret = 0; + break; + } + + pos = ((row + img->row_offset) % rowsperstrip) * scanline; + (*put)(img, raster+y*w, 0, y, w, nrow, fromskew, toskew, buf + pos); + y += (flip & FLIP_VERTICALLY ? -(int32) nrow : (int32) nrow); + } + + if (flip & FLIP_HORIZONTALLY) { + uint32 line; + + for (line = 0; line < h; line++) { + uint32 *left = raster + (line * w); + uint32 *right = left + w - 1; + + while ( left < right ) { + uint32 temp = *left; + *left = *right; + *right = temp; + left++, right--; + } + } + } + + _TIFFfree(buf); + return (ret); +} + +/* + * Get a strip-organized image with + * SamplesPerPixel > 1 + * PlanarConfiguration separated + * We assume that all such images are RGB. + */ +static int +gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) +{ + TIFF* tif = img->tif; + tileSeparateRoutine put = img->put.separate; + unsigned char *buf; + unsigned char *p0, *p1, *p2, *pa; + uint32 row, y, nrow, rowstoread; + tmsize_t pos; + tmsize_t scanline; + uint32 rowsperstrip, offset_row; + uint32 imagewidth = img->width; + tmsize_t stripsize; + tmsize_t bufsize; + int32 fromskew, toskew; + int alpha = img->alpha; + int ret = 1, flip, colorchannels; + + stripsize = TIFFStripSize(tif); + bufsize = TIFFSafeMultiply(tmsize_t,alpha?4:3,stripsize); + if (bufsize == 0) { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtStripSeparate"); + return (0); + } + p0 = buf = (unsigned char *)_TIFFmalloc(bufsize); + if (buf == 0) { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for tile buffer"); + return (0); + } + _TIFFmemset(buf, 0, bufsize); + p1 = p0 + stripsize; + p2 = p1 + stripsize; + pa = (alpha?(p2+stripsize):NULL); + + flip = setorientation(img); + if (flip & FLIP_VERTICALLY) { + y = h - 1; + toskew = -(int32)(w + w); + } + else { + y = 0; + toskew = -(int32)(w - w); + } + + switch( img->photometric ) + { + case PHOTOMETRIC_MINISWHITE: + case PHOTOMETRIC_MINISBLACK: + case PHOTOMETRIC_PALETTE: + colorchannels = 1; + p2 = p1 = p0; + break; + + default: + colorchannels = 3; + break; + } + + TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); + scanline = TIFFScanlineSize(tif); + fromskew = (w < imagewidth ? imagewidth - w : 0); + for (row = 0; row < h; row += nrow) + { + rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip; + nrow = (row + rowstoread > h ? h - row : rowstoread); + offset_row = row + img->row_offset; + if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0), + p0, ((row + img->row_offset)%rowsperstrip + nrow) * scanline)==(tmsize_t)(-1) + && img->stoponerr) + { + ret = 0; + break; + } + if (colorchannels > 1 + && TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 1), + p1, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) == (tmsize_t)(-1) + && img->stoponerr) + { + ret = 0; + break; + } + if (colorchannels > 1 + && TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 2), + p2, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) == (tmsize_t)(-1) + && img->stoponerr) + { + ret = 0; + break; + } + if (alpha) + { + if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, colorchannels), + pa, ((row + img->row_offset)%rowsperstrip + nrow) * scanline)==(tmsize_t)(-1) + && img->stoponerr) + { + ret = 0; + break; + } + } + + pos = ((row + img->row_offset) % rowsperstrip) * scanline; + (*put)(img, raster+y*w, 0, y, w, nrow, fromskew, toskew, p0 + pos, p1 + pos, + p2 + pos, (alpha?(pa+pos):NULL)); + y += (flip & FLIP_VERTICALLY ? -(int32) nrow : (int32) nrow); + } + + if (flip & FLIP_HORIZONTALLY) { + uint32 line; + + for (line = 0; line < h; line++) { + uint32 *left = raster + (line * w); + uint32 *right = left + w - 1; + + while ( left < right ) { + uint32 temp = *left; + *left = *right; + *right = temp; + left++, right--; + } + } + } + + _TIFFfree(buf); + return (ret); +} + +/* + * The following routines move decoded data returned + * from the TIFF library into rasters filled with packed + * ABGR pixels (i.e. suitable for passing to lrecwrite.) + * + * The routines have been created according to the most + * important cases and optimized. PickContigCase and + * PickSeparateCase analyze the parameters and select + * the appropriate "get" and "put" routine to use. + */ +#define REPEAT8(op) REPEAT4(op); REPEAT4(op) +#define REPEAT4(op) REPEAT2(op); REPEAT2(op) +#define REPEAT2(op) op; op +#define CASE8(x,op) \ + switch (x) { \ + case 7: op; case 6: op; case 5: op; \ + case 4: op; case 3: op; case 2: op; \ + case 1: op; \ + } +#define CASE4(x,op) switch (x) { case 3: op; case 2: op; case 1: op; } +#define NOP + +#define UNROLL8(w, op1, op2) { \ + uint32 _x; \ + for (_x = w; _x >= 8; _x -= 8) { \ + op1; \ + REPEAT8(op2); \ + } \ + if (_x > 0) { \ + op1; \ + CASE8(_x,op2); \ + } \ +} +#define UNROLL4(w, op1, op2) { \ + uint32 _x; \ + for (_x = w; _x >= 4; _x -= 4) { \ + op1; \ + REPEAT4(op2); \ + } \ + if (_x > 0) { \ + op1; \ + CASE4(_x,op2); \ + } \ +} +#define UNROLL2(w, op1, op2) { \ + uint32 _x; \ + for (_x = w; _x >= 2; _x -= 2) { \ + op1; \ + REPEAT2(op2); \ + } \ + if (_x) { \ + op1; \ + op2; \ + } \ +} + +#define SKEW(r,g,b,skew) { r += skew; g += skew; b += skew; } +#define SKEW4(r,g,b,a,skew) { r += skew; g += skew; b += skew; a+= skew; } + +#define A1 (((uint32)0xffL)<<24) +#define PACK(r,g,b) \ + ((uint32)(r)|((uint32)(g)<<8)|((uint32)(b)<<16)|A1) +#define PACK4(r,g,b,a) \ + ((uint32)(r)|((uint32)(g)<<8)|((uint32)(b)<<16)|((uint32)(a)<<24)) +#define W2B(v) (((v)>>8)&0xff) +/* TODO: PACKW should have be made redundant in favor of Bitdepth16To8 LUT */ +#define PACKW(r,g,b) \ + ((uint32)W2B(r)|((uint32)W2B(g)<<8)|((uint32)W2B(b)<<16)|A1) +#define PACKW4(r,g,b,a) \ + ((uint32)W2B(r)|((uint32)W2B(g)<<8)|((uint32)W2B(b)<<16)|((uint32)W2B(a)<<24)) + +#define DECLAREContigPutFunc(name) \ +static void name(\ + TIFFRGBAImage* img, \ + uint32* cp, \ + uint32 x, uint32 y, \ + uint32 w, uint32 h, \ + int32 fromskew, int32 toskew, \ + unsigned char* pp \ +) + +/* + * 8-bit palette => colormap/RGB + */ +DECLAREContigPutFunc(put8bitcmaptile) +{ + uint32** PALmap = img->PALmap; + int samplesperpixel = img->samplesperpixel; + + (void) y; + while (h-- > 0) { + for (x = w; x-- > 0;) + { + *cp++ = PALmap[*pp][0]; + pp += samplesperpixel; + } + cp += toskew; + pp += fromskew; + } +} + +/* + * 4-bit palette => colormap/RGB + */ +DECLAREContigPutFunc(put4bitcmaptile) +{ + uint32** PALmap = img->PALmap; + + (void) x; (void) y; + fromskew /= 2; + while (h-- > 0) { + uint32* bw; + UNROLL2(w, bw = PALmap[*pp++], *cp++ = *bw++); + cp += toskew; + pp += fromskew; + } +} + +/* + * 2-bit palette => colormap/RGB + */ +DECLAREContigPutFunc(put2bitcmaptile) +{ + uint32** PALmap = img->PALmap; + + (void) x; (void) y; + fromskew /= 4; + while (h-- > 0) { + uint32* bw; + UNROLL4(w, bw = PALmap[*pp++], *cp++ = *bw++); + cp += toskew; + pp += fromskew; + } +} + +/* + * 1-bit palette => colormap/RGB + */ +DECLAREContigPutFunc(put1bitcmaptile) +{ + uint32** PALmap = img->PALmap; + + (void) x; (void) y; + fromskew /= 8; + while (h-- > 0) { + uint32* bw; + UNROLL8(w, bw = PALmap[*pp++], *cp++ = *bw++); + cp += toskew; + pp += fromskew; + } +} + +/* + * 8-bit greyscale => colormap/RGB + */ +DECLAREContigPutFunc(putgreytile) +{ + int samplesperpixel = img->samplesperpixel; + uint32** BWmap = img->BWmap; + + (void) y; + while (h-- > 0) { + for (x = w; x-- > 0;) + { + *cp++ = BWmap[*pp][0]; + pp += samplesperpixel; + } + cp += toskew; + pp += fromskew; + } +} + +/* + * 8-bit greyscale with associated alpha => colormap/RGBA + */ +DECLAREContigPutFunc(putagreytile) +{ + int samplesperpixel = img->samplesperpixel; + uint32** BWmap = img->BWmap; + + (void) y; + while (h-- > 0) { + for (x = w; x-- > 0;) + { + *cp++ = BWmap[*pp][0] & (*(pp+1) << 24 | ~A1); + pp += samplesperpixel; + } + cp += toskew; + pp += fromskew; + } +} + +/* + * 16-bit greyscale => colormap/RGB + */ +DECLAREContigPutFunc(put16bitbwtile) +{ + int samplesperpixel = img->samplesperpixel; + uint32** BWmap = img->BWmap; + + (void) y; + while (h-- > 0) { + uint16 *wp = (uint16 *) pp; + + for (x = w; x-- > 0;) + { + /* use high order byte of 16bit value */ + + *cp++ = BWmap[*wp >> 8][0]; + pp += 2 * samplesperpixel; + wp += samplesperpixel; + } + cp += toskew; + pp += fromskew; + } +} + +/* + * 1-bit bilevel => colormap/RGB + */ +DECLAREContigPutFunc(put1bitbwtile) +{ + uint32** BWmap = img->BWmap; + + (void) x; (void) y; + fromskew /= 8; + while (h-- > 0) { + uint32* bw; + UNROLL8(w, bw = BWmap[*pp++], *cp++ = *bw++); + cp += toskew; + pp += fromskew; + } +} + +/* + * 2-bit greyscale => colormap/RGB + */ +DECLAREContigPutFunc(put2bitbwtile) +{ + uint32** BWmap = img->BWmap; + + (void) x; (void) y; + fromskew /= 4; + while (h-- > 0) { + uint32* bw; + UNROLL4(w, bw = BWmap[*pp++], *cp++ = *bw++); + cp += toskew; + pp += fromskew; + } +} + +/* + * 4-bit greyscale => colormap/RGB + */ +DECLAREContigPutFunc(put4bitbwtile) +{ + uint32** BWmap = img->BWmap; + + (void) x; (void) y; + fromskew /= 2; + while (h-- > 0) { + uint32* bw; + UNROLL2(w, bw = BWmap[*pp++], *cp++ = *bw++); + cp += toskew; + pp += fromskew; + } +} + +/* + * 8-bit packed samples, no Map => RGB + */ +DECLAREContigPutFunc(putRGBcontig8bittile) +{ + int samplesperpixel = img->samplesperpixel; + + (void) x; (void) y; + fromskew *= samplesperpixel; + while (h-- > 0) { + UNROLL8(w, NOP, + *cp++ = PACK(pp[0], pp[1], pp[2]); + pp += samplesperpixel); + cp += toskew; + pp += fromskew; + } +} + +/* + * 8-bit packed samples => RGBA w/ associated alpha + * (known to have Map == NULL) + */ +DECLAREContigPutFunc(putRGBAAcontig8bittile) +{ + int samplesperpixel = img->samplesperpixel; + + (void) x; (void) y; + fromskew *= samplesperpixel; + while (h-- > 0) { + UNROLL8(w, NOP, + *cp++ = PACK4(pp[0], pp[1], pp[2], pp[3]); + pp += samplesperpixel); + cp += toskew; + pp += fromskew; + } +} + +/* + * 8-bit packed samples => RGBA w/ unassociated alpha + * (known to have Map == NULL) + */ +DECLAREContigPutFunc(putRGBUAcontig8bittile) +{ + int samplesperpixel = img->samplesperpixel; + (void) y; + fromskew *= samplesperpixel; + while (h-- > 0) { + uint32 r, g, b, a; + uint8* m; + for (x = w; x-- > 0;) { + a = pp[3]; + m = img->UaToAa+(a<<8); + r = m[pp[0]]; + g = m[pp[1]]; + b = m[pp[2]]; + *cp++ = PACK4(r,g,b,a); + pp += samplesperpixel; + } + cp += toskew; + pp += fromskew; + } +} + +/* + * 16-bit packed samples => RGB + */ +DECLAREContigPutFunc(putRGBcontig16bittile) +{ + int samplesperpixel = img->samplesperpixel; + uint16 *wp = (uint16 *)pp; + (void) y; + fromskew *= samplesperpixel; + while (h-- > 0) { + for (x = w; x-- > 0;) { + *cp++ = PACK(img->Bitdepth16To8[wp[0]], + img->Bitdepth16To8[wp[1]], + img->Bitdepth16To8[wp[2]]); + wp += samplesperpixel; + } + cp += toskew; + wp += fromskew; + } +} + +/* + * 16-bit packed samples => RGBA w/ associated alpha + * (known to have Map == NULL) + */ +DECLAREContigPutFunc(putRGBAAcontig16bittile) +{ + int samplesperpixel = img->samplesperpixel; + uint16 *wp = (uint16 *)pp; + (void) y; + fromskew *= samplesperpixel; + while (h-- > 0) { + for (x = w; x-- > 0;) { + *cp++ = PACK4(img->Bitdepth16To8[wp[0]], + img->Bitdepth16To8[wp[1]], + img->Bitdepth16To8[wp[2]], + img->Bitdepth16To8[wp[3]]); + wp += samplesperpixel; + } + cp += toskew; + wp += fromskew; + } +} + +/* + * 16-bit packed samples => RGBA w/ unassociated alpha + * (known to have Map == NULL) + */ +DECLAREContigPutFunc(putRGBUAcontig16bittile) +{ + int samplesperpixel = img->samplesperpixel; + uint16 *wp = (uint16 *)pp; + (void) y; + fromskew *= samplesperpixel; + while (h-- > 0) { + uint32 r,g,b,a; + uint8* m; + for (x = w; x-- > 0;) { + a = img->Bitdepth16To8[wp[3]]; + m = img->UaToAa+(a<<8); + r = m[img->Bitdepth16To8[wp[0]]]; + g = m[img->Bitdepth16To8[wp[1]]]; + b = m[img->Bitdepth16To8[wp[2]]]; + *cp++ = PACK4(r,g,b,a); + wp += samplesperpixel; + } + cp += toskew; + wp += fromskew; + } +} + +/* + * 8-bit packed CMYK samples w/o Map => RGB + * + * NB: The conversion of CMYK->RGB is *very* crude. + */ +DECLAREContigPutFunc(putRGBcontig8bitCMYKtile) +{ + int samplesperpixel = img->samplesperpixel; + uint16 r, g, b, k; + + (void) x; (void) y; + fromskew *= samplesperpixel; + while (h-- > 0) { + UNROLL8(w, NOP, + k = 255 - pp[3]; + r = (k*(255-pp[0]))/255; + g = (k*(255-pp[1]))/255; + b = (k*(255-pp[2]))/255; + *cp++ = PACK(r, g, b); + pp += samplesperpixel); + cp += toskew; + pp += fromskew; + } +} + +/* + * 8-bit packed CMYK samples w/Map => RGB + * + * NB: The conversion of CMYK->RGB is *very* crude. + */ +DECLAREContigPutFunc(putRGBcontig8bitCMYKMaptile) +{ + int samplesperpixel = img->samplesperpixel; + TIFFRGBValue* Map = img->Map; + uint16 r, g, b, k; + + (void) y; + fromskew *= samplesperpixel; + while (h-- > 0) { + for (x = w; x-- > 0;) { + k = 255 - pp[3]; + r = (k*(255-pp[0]))/255; + g = (k*(255-pp[1]))/255; + b = (k*(255-pp[2]))/255; + *cp++ = PACK(Map[r], Map[g], Map[b]); + pp += samplesperpixel; + } + pp += fromskew; + cp += toskew; + } +} + +#define DECLARESepPutFunc(name) \ +static void name(\ + TIFFRGBAImage* img,\ + uint32* cp,\ + uint32 x, uint32 y, \ + uint32 w, uint32 h,\ + int32 fromskew, int32 toskew,\ + unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a\ +) + +/* + * 8-bit unpacked samples => RGB + */ +DECLARESepPutFunc(putRGBseparate8bittile) +{ + (void) img; (void) x; (void) y; (void) a; + while (h-- > 0) { + UNROLL8(w, NOP, *cp++ = PACK(*r++, *g++, *b++)); + SKEW(r, g, b, fromskew); + cp += toskew; + } +} + +/* + * 8-bit unpacked samples => RGBA w/ associated alpha + */ +DECLARESepPutFunc(putRGBAAseparate8bittile) +{ + (void) img; (void) x; (void) y; + while (h-- > 0) { + UNROLL8(w, NOP, *cp++ = PACK4(*r++, *g++, *b++, *a++)); + SKEW4(r, g, b, a, fromskew); + cp += toskew; + } +} + +/* + * 8-bit unpacked CMYK samples => RGBA + */ +DECLARESepPutFunc(putCMYKseparate8bittile) +{ + (void) img; (void) y; + while (h-- > 0) { + uint32 rv, gv, bv, kv; + for (x = w; x-- > 0;) { + kv = 255 - *a++; + rv = (kv*(255-*r++))/255; + gv = (kv*(255-*g++))/255; + bv = (kv*(255-*b++))/255; + *cp++ = PACK4(rv,gv,bv,255); + } + SKEW4(r, g, b, a, fromskew); + cp += toskew; + } +} + +/* + * 8-bit unpacked samples => RGBA w/ unassociated alpha + */ +DECLARESepPutFunc(putRGBUAseparate8bittile) +{ + (void) img; (void) y; + while (h-- > 0) { + uint32 rv, gv, bv, av; + uint8* m; + for (x = w; x-- > 0;) { + av = *a++; + m = img->UaToAa+(av<<8); + rv = m[*r++]; + gv = m[*g++]; + bv = m[*b++]; + *cp++ = PACK4(rv,gv,bv,av); + } + SKEW4(r, g, b, a, fromskew); + cp += toskew; + } +} + +/* + * 16-bit unpacked samples => RGB + */ +DECLARESepPutFunc(putRGBseparate16bittile) +{ + uint16 *wr = (uint16*) r; + uint16 *wg = (uint16*) g; + uint16 *wb = (uint16*) b; + (void) img; (void) y; (void) a; + while (h-- > 0) { + for (x = 0; x < w; x++) + *cp++ = PACK(img->Bitdepth16To8[*wr++], + img->Bitdepth16To8[*wg++], + img->Bitdepth16To8[*wb++]); + SKEW(wr, wg, wb, fromskew); + cp += toskew; + } +} + +/* + * 16-bit unpacked samples => RGBA w/ associated alpha + */ +DECLARESepPutFunc(putRGBAAseparate16bittile) +{ + uint16 *wr = (uint16*) r; + uint16 *wg = (uint16*) g; + uint16 *wb = (uint16*) b; + uint16 *wa = (uint16*) a; + (void) img; (void) y; + while (h-- > 0) { + for (x = 0; x < w; x++) + *cp++ = PACK4(img->Bitdepth16To8[*wr++], + img->Bitdepth16To8[*wg++], + img->Bitdepth16To8[*wb++], + img->Bitdepth16To8[*wa++]); + SKEW4(wr, wg, wb, wa, fromskew); + cp += toskew; + } +} + +/* + * 16-bit unpacked samples => RGBA w/ unassociated alpha + */ +DECLARESepPutFunc(putRGBUAseparate16bittile) +{ + uint16 *wr = (uint16*) r; + uint16 *wg = (uint16*) g; + uint16 *wb = (uint16*) b; + uint16 *wa = (uint16*) a; + (void) img; (void) y; + while (h-- > 0) { + uint32 r,g,b,a; + uint8* m; + for (x = w; x-- > 0;) { + a = img->Bitdepth16To8[*wa++]; + m = img->UaToAa+(a<<8); + r = m[img->Bitdepth16To8[*wr++]]; + g = m[img->Bitdepth16To8[*wg++]]; + b = m[img->Bitdepth16To8[*wb++]]; + *cp++ = PACK4(r,g,b,a); + } + SKEW4(wr, wg, wb, wa, fromskew); + cp += toskew; + } +} + +/* + * 8-bit packed CIE L*a*b 1976 samples => RGB + */ +DECLAREContigPutFunc(putcontig8bitCIELab) +{ + float X, Y, Z; + uint32 r, g, b; + (void) y; + fromskew *= 3; + while (h-- > 0) { + for (x = w; x-- > 0;) { + TIFFCIELabToXYZ(img->cielab, + (unsigned char)pp[0], + (signed char)pp[1], + (signed char)pp[2], + &X, &Y, &Z); + TIFFXYZToRGB(img->cielab, X, Y, Z, &r, &g, &b); + *cp++ = PACK(r, g, b); + pp += 3; + } + cp += toskew; + pp += fromskew; + } +} + +/* + * YCbCr -> RGB conversion and packing routines. + */ + +#define YCbCrtoRGB(dst, Y) { \ + uint32 r, g, b; \ + TIFFYCbCrtoRGB(img->ycbcr, (Y), Cb, Cr, &r, &g, &b); \ + dst = PACK(r, g, b); \ +} + +/* + * 8-bit packed YCbCr samples => RGB + * This function is generic for different sampling sizes, + * and can handle blocks sizes that aren't multiples of the + * sampling size. However, it is substantially less optimized + * than the specific sampling cases. It is used as a fallback + * for difficult blocks. + */ +#ifdef notdef +static void putcontig8bitYCbCrGenericTile( + TIFFRGBAImage* img, + uint32* cp, + uint32 x, uint32 y, + uint32 w, uint32 h, + int32 fromskew, int32 toskew, + unsigned char* pp, + int h_group, + int v_group ) + +{ + uint32* cp1 = cp+w+toskew; + uint32* cp2 = cp1+w+toskew; + uint32* cp3 = cp2+w+toskew; + int32 incr = 3*w+4*toskew; + int32 Cb, Cr; + int group_size = v_group * h_group + 2; + + (void) y; + fromskew = (fromskew * group_size) / h_group; + + for( yy = 0; yy < h; yy++ ) + { + unsigned char *pp_line; + int y_line_group = yy / v_group; + int y_remainder = yy - y_line_group * v_group; + + pp_line = pp + v_line_group * + + + for( xx = 0; xx < w; xx++ ) + { + Cb = pp + } + } + for (; h >= 4; h -= 4) { + x = w>>2; + do { + Cb = pp[16]; + Cr = pp[17]; + + YCbCrtoRGB(cp [0], pp[ 0]); + YCbCrtoRGB(cp [1], pp[ 1]); + YCbCrtoRGB(cp [2], pp[ 2]); + YCbCrtoRGB(cp [3], pp[ 3]); + YCbCrtoRGB(cp1[0], pp[ 4]); + YCbCrtoRGB(cp1[1], pp[ 5]); + YCbCrtoRGB(cp1[2], pp[ 6]); + YCbCrtoRGB(cp1[3], pp[ 7]); + YCbCrtoRGB(cp2[0], pp[ 8]); + YCbCrtoRGB(cp2[1], pp[ 9]); + YCbCrtoRGB(cp2[2], pp[10]); + YCbCrtoRGB(cp2[3], pp[11]); + YCbCrtoRGB(cp3[0], pp[12]); + YCbCrtoRGB(cp3[1], pp[13]); + YCbCrtoRGB(cp3[2], pp[14]); + YCbCrtoRGB(cp3[3], pp[15]); + + cp += 4, cp1 += 4, cp2 += 4, cp3 += 4; + pp += 18; + } while (--x); + cp += incr, cp1 += incr, cp2 += incr, cp3 += incr; + pp += fromskew; + } +} +#endif + +/* + * 8-bit packed YCbCr samples w/ 4,4 subsampling => RGB + */ +DECLAREContigPutFunc(putcontig8bitYCbCr44tile) +{ + uint32* cp1 = cp+w+toskew; + uint32* cp2 = cp1+w+toskew; + uint32* cp3 = cp2+w+toskew; + int32 incr = 3*w+4*toskew; + + (void) y; + /* adjust fromskew */ + fromskew = (fromskew * 18) / 4; + if ((h & 3) == 0 && (w & 3) == 0) { + for (; h >= 4; h -= 4) { + x = w>>2; + do { + int32 Cb = pp[16]; + int32 Cr = pp[17]; + + YCbCrtoRGB(cp [0], pp[ 0]); + YCbCrtoRGB(cp [1], pp[ 1]); + YCbCrtoRGB(cp [2], pp[ 2]); + YCbCrtoRGB(cp [3], pp[ 3]); + YCbCrtoRGB(cp1[0], pp[ 4]); + YCbCrtoRGB(cp1[1], pp[ 5]); + YCbCrtoRGB(cp1[2], pp[ 6]); + YCbCrtoRGB(cp1[3], pp[ 7]); + YCbCrtoRGB(cp2[0], pp[ 8]); + YCbCrtoRGB(cp2[1], pp[ 9]); + YCbCrtoRGB(cp2[2], pp[10]); + YCbCrtoRGB(cp2[3], pp[11]); + YCbCrtoRGB(cp3[0], pp[12]); + YCbCrtoRGB(cp3[1], pp[13]); + YCbCrtoRGB(cp3[2], pp[14]); + YCbCrtoRGB(cp3[3], pp[15]); + + cp += 4, cp1 += 4, cp2 += 4, cp3 += 4; + pp += 18; + } while (--x); + cp += incr, cp1 += incr, cp2 += incr, cp3 += incr; + pp += fromskew; + } + } else { + while (h > 0) { + for (x = w; x > 0;) { + int32 Cb = pp[16]; + int32 Cr = pp[17]; + switch (x) { + default: + switch (h) { + default: YCbCrtoRGB(cp3[3], pp[15]); /* FALLTHROUGH */ + case 3: YCbCrtoRGB(cp2[3], pp[11]); /* FALLTHROUGH */ + case 2: YCbCrtoRGB(cp1[3], pp[ 7]); /* FALLTHROUGH */ + case 1: YCbCrtoRGB(cp [3], pp[ 3]); /* FALLTHROUGH */ + } /* FALLTHROUGH */ + case 3: + switch (h) { + default: YCbCrtoRGB(cp3[2], pp[14]); /* FALLTHROUGH */ + case 3: YCbCrtoRGB(cp2[2], pp[10]); /* FALLTHROUGH */ + case 2: YCbCrtoRGB(cp1[2], pp[ 6]); /* FALLTHROUGH */ + case 1: YCbCrtoRGB(cp [2], pp[ 2]); /* FALLTHROUGH */ + } /* FALLTHROUGH */ + case 2: + switch (h) { + default: YCbCrtoRGB(cp3[1], pp[13]); /* FALLTHROUGH */ + case 3: YCbCrtoRGB(cp2[1], pp[ 9]); /* FALLTHROUGH */ + case 2: YCbCrtoRGB(cp1[1], pp[ 5]); /* FALLTHROUGH */ + case 1: YCbCrtoRGB(cp [1], pp[ 1]); /* FALLTHROUGH */ + } /* FALLTHROUGH */ + case 1: + switch (h) { + default: YCbCrtoRGB(cp3[0], pp[12]); /* FALLTHROUGH */ + case 3: YCbCrtoRGB(cp2[0], pp[ 8]); /* FALLTHROUGH */ + case 2: YCbCrtoRGB(cp1[0], pp[ 4]); /* FALLTHROUGH */ + case 1: YCbCrtoRGB(cp [0], pp[ 0]); /* FALLTHROUGH */ + } /* FALLTHROUGH */ + } + if (x < 4) { + cp += x; cp1 += x; cp2 += x; cp3 += x; + x = 0; + } + else { + cp += 4; cp1 += 4; cp2 += 4; cp3 += 4; + x -= 4; + } + pp += 18; + } + if (h <= 4) + break; + h -= 4; + cp += incr, cp1 += incr, cp2 += incr, cp3 += incr; + pp += fromskew; + } + } +} + +/* + * 8-bit packed YCbCr samples w/ 4,2 subsampling => RGB + */ +DECLAREContigPutFunc(putcontig8bitYCbCr42tile) +{ + uint32* cp1 = cp+w+toskew; + int32 incr = 2*toskew+w; + + (void) y; + fromskew = (fromskew * 10) / 4; + if ((h & 3) == 0 && (w & 1) == 0) { + for (; h >= 2; h -= 2) { + x = w>>2; + do { + int32 Cb = pp[8]; + int32 Cr = pp[9]; + + YCbCrtoRGB(cp [0], pp[0]); + YCbCrtoRGB(cp [1], pp[1]); + YCbCrtoRGB(cp [2], pp[2]); + YCbCrtoRGB(cp [3], pp[3]); + YCbCrtoRGB(cp1[0], pp[4]); + YCbCrtoRGB(cp1[1], pp[5]); + YCbCrtoRGB(cp1[2], pp[6]); + YCbCrtoRGB(cp1[3], pp[7]); + + cp += 4, cp1 += 4; + pp += 10; + } while (--x); + cp += incr, cp1 += incr; + pp += fromskew; + } + } else { + while (h > 0) { + for (x = w; x > 0;) { + int32 Cb = pp[8]; + int32 Cr = pp[9]; + switch (x) { + default: + switch (h) { + default: YCbCrtoRGB(cp1[3], pp[ 7]); /* FALLTHROUGH */ + case 1: YCbCrtoRGB(cp [3], pp[ 3]); /* FALLTHROUGH */ + } /* FALLTHROUGH */ + case 3: + switch (h) { + default: YCbCrtoRGB(cp1[2], pp[ 6]); /* FALLTHROUGH */ + case 1: YCbCrtoRGB(cp [2], pp[ 2]); /* FALLTHROUGH */ + } /* FALLTHROUGH */ + case 2: + switch (h) { + default: YCbCrtoRGB(cp1[1], pp[ 5]); /* FALLTHROUGH */ + case 1: YCbCrtoRGB(cp [1], pp[ 1]); /* FALLTHROUGH */ + } /* FALLTHROUGH */ + case 1: + switch (h) { + default: YCbCrtoRGB(cp1[0], pp[ 4]); /* FALLTHROUGH */ + case 1: YCbCrtoRGB(cp [0], pp[ 0]); /* FALLTHROUGH */ + } /* FALLTHROUGH */ + } + if (x < 4) { + cp += x; cp1 += x; + x = 0; + } + else { + cp += 4; cp1 += 4; + x -= 4; + } + pp += 10; + } + if (h <= 2) + break; + h -= 2; + cp += incr, cp1 += incr; + pp += fromskew; + } + } +} + +/* + * 8-bit packed YCbCr samples w/ 4,1 subsampling => RGB + */ +DECLAREContigPutFunc(putcontig8bitYCbCr41tile) +{ + (void) y; + /* XXX adjust fromskew */ + do { + x = w>>2; + do { + int32 Cb = pp[4]; + int32 Cr = pp[5]; + + YCbCrtoRGB(cp [0], pp[0]); + YCbCrtoRGB(cp [1], pp[1]); + YCbCrtoRGB(cp [2], pp[2]); + YCbCrtoRGB(cp [3], pp[3]); + + cp += 4; + pp += 6; + } while (--x); + + if( (w&3) != 0 ) + { + int32 Cb = pp[4]; + int32 Cr = pp[5]; + + switch( (w&3) ) { + case 3: YCbCrtoRGB(cp [2], pp[2]); + case 2: YCbCrtoRGB(cp [1], pp[1]); + case 1: YCbCrtoRGB(cp [0], pp[0]); + case 0: break; + } + + cp += (w&3); + pp += 6; + } + + cp += toskew; + pp += fromskew; + } while (--h); + +} + +/* + * 8-bit packed YCbCr samples w/ 2,2 subsampling => RGB + */ +DECLAREContigPutFunc(putcontig8bitYCbCr22tile) +{ + uint32* cp2; + int32 incr = 2*toskew+w; + (void) y; + fromskew = (fromskew / 2) * 6; + cp2 = cp+w+toskew; + while (h>=2) { + x = w; + while (x>=2) { + uint32 Cb = pp[4]; + uint32 Cr = pp[5]; + YCbCrtoRGB(cp[0], pp[0]); + YCbCrtoRGB(cp[1], pp[1]); + YCbCrtoRGB(cp2[0], pp[2]); + YCbCrtoRGB(cp2[1], pp[3]); + cp += 2; + cp2 += 2; + pp += 6; + x -= 2; + } + if (x==1) { + uint32 Cb = pp[4]; + uint32 Cr = pp[5]; + YCbCrtoRGB(cp[0], pp[0]); + YCbCrtoRGB(cp2[0], pp[2]); + cp ++ ; + cp2 ++ ; + pp += 6; + } + cp += incr; + cp2 += incr; + pp += fromskew; + h-=2; + } + if (h==1) { + x = w; + while (x>=2) { + uint32 Cb = pp[4]; + uint32 Cr = pp[5]; + YCbCrtoRGB(cp[0], pp[0]); + YCbCrtoRGB(cp[1], pp[1]); + cp += 2; + cp2 += 2; + pp += 6; + x -= 2; + } + if (x==1) { + uint32 Cb = pp[4]; + uint32 Cr = pp[5]; + YCbCrtoRGB(cp[0], pp[0]); + } + } +} + +/* + * 8-bit packed YCbCr samples w/ 2,1 subsampling => RGB + */ +DECLAREContigPutFunc(putcontig8bitYCbCr21tile) +{ + (void) y; + fromskew = (fromskew * 4) / 2; + do { + x = w>>1; + do { + int32 Cb = pp[2]; + int32 Cr = pp[3]; + + YCbCrtoRGB(cp[0], pp[0]); + YCbCrtoRGB(cp[1], pp[1]); + + cp += 2; + pp += 4; + } while (--x); + + if( (w&1) != 0 ) + { + int32 Cb = pp[2]; + int32 Cr = pp[3]; + + YCbCrtoRGB(cp[0], pp[0]); + + cp += 1; + pp += 4; + } + + cp += toskew; + pp += fromskew; + } while (--h); +} + +/* + * 8-bit packed YCbCr samples w/ 1,2 subsampling => RGB + */ +DECLAREContigPutFunc(putcontig8bitYCbCr12tile) +{ + uint32* cp2; + int32 incr = 2*toskew+w; + (void) y; + fromskew = (fromskew / 2) * 4; + cp2 = cp+w+toskew; + while (h>=2) { + x = w; + do { + uint32 Cb = pp[2]; + uint32 Cr = pp[3]; + YCbCrtoRGB(cp[0], pp[0]); + YCbCrtoRGB(cp2[0], pp[1]); + cp ++; + cp2 ++; + pp += 4; + } while (--x); + cp += incr; + cp2 += incr; + pp += fromskew; + h-=2; + } + if (h==1) { + x = w; + do { + uint32 Cb = pp[2]; + uint32 Cr = pp[3]; + YCbCrtoRGB(cp[0], pp[0]); + cp ++; + pp += 4; + } while (--x); + } +} + +/* + * 8-bit packed YCbCr samples w/ no subsampling => RGB + */ +DECLAREContigPutFunc(putcontig8bitYCbCr11tile) +{ + (void) y; + fromskew *= 3; + do { + x = w; /* was x = w>>1; patched 2000/09/25 warmerda@home.com */ + do { + int32 Cb = pp[1]; + int32 Cr = pp[2]; + + YCbCrtoRGB(*cp++, pp[0]); + + pp += 3; + } while (--x); + cp += toskew; + pp += fromskew; + } while (--h); +} + +/* + * 8-bit packed YCbCr samples w/ no subsampling => RGB + */ +DECLARESepPutFunc(putseparate8bitYCbCr11tile) +{ + (void) y; + (void) a; + /* TODO: naming of input vars is still off, change obfuscating declaration inside define, or resolve obfuscation */ + while (h-- > 0) { + x = w; + do { + uint32 dr, dg, db; + TIFFYCbCrtoRGB(img->ycbcr,*r++,*g++,*b++,&dr,&dg,&db); + *cp++ = PACK(dr,dg,db); + } while (--x); + SKEW(r, g, b, fromskew); + cp += toskew; + } +} +#undef YCbCrtoRGB + +static int +initYCbCrConversion(TIFFRGBAImage* img) +{ + static const char module[] = "initYCbCrConversion"; + + float *luma, *refBlackWhite; + + if (img->ycbcr == NULL) { + img->ycbcr = (TIFFYCbCrToRGB*) _TIFFmalloc( + TIFFroundup_32(sizeof (TIFFYCbCrToRGB), sizeof (long)) + + 4*256*sizeof (TIFFRGBValue) + + 2*256*sizeof (int) + + 3*256*sizeof (int32) + ); + if (img->ycbcr == NULL) { + TIFFErrorExt(img->tif->tif_clientdata, module, + "No space for YCbCr->RGB conversion state"); + return (0); + } + } + + TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRCOEFFICIENTS, &luma); + TIFFGetFieldDefaulted(img->tif, TIFFTAG_REFERENCEBLACKWHITE, + &refBlackWhite); + if (TIFFYCbCrToRGBInit(img->ycbcr, luma, refBlackWhite) < 0) + return(0); + return (1); +} + +static tileContigRoutine +initCIELabConversion(TIFFRGBAImage* img) +{ + static const char module[] = "initCIELabConversion"; + + float *whitePoint; + float refWhite[3]; + + if (!img->cielab) { + img->cielab = (TIFFCIELabToRGB *) + _TIFFmalloc(sizeof(TIFFCIELabToRGB)); + if (!img->cielab) { + TIFFErrorExt(img->tif->tif_clientdata, module, + "No space for CIE L*a*b*->RGB conversion state."); + return NULL; + } + } + + TIFFGetFieldDefaulted(img->tif, TIFFTAG_WHITEPOINT, &whitePoint); + refWhite[1] = 100.0F; + refWhite[0] = whitePoint[0] / whitePoint[1] * refWhite[1]; + refWhite[2] = (1.0F - whitePoint[0] - whitePoint[1]) + / whitePoint[1] * refWhite[1]; + if (TIFFCIELabToRGBInit(img->cielab, &display_sRGB, refWhite) < 0) { + TIFFErrorExt(img->tif->tif_clientdata, module, + "Failed to initialize CIE L*a*b*->RGB conversion state."); + _TIFFfree(img->cielab); + return NULL; + } + + return putcontig8bitCIELab; +} + +/* + * Greyscale images with less than 8 bits/sample are handled + * with a table to avoid lots of shifts and masks. The table + * is setup so that put*bwtile (below) can retrieve 8/bitspersample + * pixel values simply by indexing into the table with one + * number. + */ +static int +makebwmap(TIFFRGBAImage* img) +{ + TIFFRGBValue* Map = img->Map; + int bitspersample = img->bitspersample; + int nsamples = 8 / bitspersample; + int i; + uint32* p; + + if( nsamples == 0 ) + nsamples = 1; + + img->BWmap = (uint32**) _TIFFmalloc( + 256*sizeof (uint32 *)+(256*nsamples*sizeof(uint32))); + if (img->BWmap == NULL) { + TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "No space for B&W mapping table"); + return (0); + } + p = (uint32*)(img->BWmap + 256); + for (i = 0; i < 256; i++) { + TIFFRGBValue c; + img->BWmap[i] = p; + switch (bitspersample) { +#define GREY(x) c = Map[x]; *p++ = PACK(c,c,c); + case 1: + GREY(i>>7); + GREY((i>>6)&1); + GREY((i>>5)&1); + GREY((i>>4)&1); + GREY((i>>3)&1); + GREY((i>>2)&1); + GREY((i>>1)&1); + GREY(i&1); + break; + case 2: + GREY(i>>6); + GREY((i>>4)&3); + GREY((i>>2)&3); + GREY(i&3); + break; + case 4: + GREY(i>>4); + GREY(i&0xf); + break; + case 8: + case 16: + GREY(i); + break; + } +#undef GREY + } + return (1); +} + +/* + * Construct a mapping table to convert from the range + * of the data samples to [0,255] --for display. This + * process also handles inverting B&W images when needed. + */ +static int +setupMap(TIFFRGBAImage* img) +{ + int32 x, range; + + range = (int32)((1L<bitspersample)-1); + + /* treat 16 bit the same as eight bit */ + if( img->bitspersample == 16 ) + range = (int32) 255; + + img->Map = (TIFFRGBValue*) _TIFFmalloc((range+1) * sizeof (TIFFRGBValue)); + if (img->Map == NULL) { + TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), + "No space for photometric conversion table"); + return (0); + } + if (img->photometric == PHOTOMETRIC_MINISWHITE) { + for (x = 0; x <= range; x++) + img->Map[x] = (TIFFRGBValue) (((range - x) * 255) / range); + } else { + for (x = 0; x <= range; x++) + img->Map[x] = (TIFFRGBValue) ((x * 255) / range); + } + if (img->bitspersample <= 16 && + (img->photometric == PHOTOMETRIC_MINISBLACK || + img->photometric == PHOTOMETRIC_MINISWHITE)) { + /* + * Use photometric mapping table to construct + * unpacking tables for samples <= 8 bits. + */ + if (!makebwmap(img)) + return (0); + /* no longer need Map, free it */ + _TIFFfree(img->Map), img->Map = NULL; + } + return (1); +} + +static int +checkcmap(TIFFRGBAImage* img) +{ + uint16* r = img->redcmap; + uint16* g = img->greencmap; + uint16* b = img->bluecmap; + long n = 1L<bitspersample; + + while (n-- > 0) + if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256) + return (16); + return (8); +} + +static void +cvtcmap(TIFFRGBAImage* img) +{ + uint16* r = img->redcmap; + uint16* g = img->greencmap; + uint16* b = img->bluecmap; + long i; + + for (i = (1L<bitspersample)-1; i >= 0; i--) { +#define CVT(x) ((uint16)((x)>>8)) + r[i] = CVT(r[i]); + g[i] = CVT(g[i]); + b[i] = CVT(b[i]); +#undef CVT + } +} + +/* + * Palette images with <= 8 bits/sample are handled + * with a table to avoid lots of shifts and masks. The table + * is setup so that put*cmaptile (below) can retrieve 8/bitspersample + * pixel values simply by indexing into the table with one + * number. + */ +static int +makecmap(TIFFRGBAImage* img) +{ + int bitspersample = img->bitspersample; + int nsamples = 8 / bitspersample; + uint16* r = img->redcmap; + uint16* g = img->greencmap; + uint16* b = img->bluecmap; + uint32 *p; + int i; + + img->PALmap = (uint32**) _TIFFmalloc( + 256*sizeof (uint32 *)+(256*nsamples*sizeof(uint32))); + if (img->PALmap == NULL) { + TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "No space for Palette mapping table"); + return (0); + } + p = (uint32*)(img->PALmap + 256); + for (i = 0; i < 256; i++) { + TIFFRGBValue c; + img->PALmap[i] = p; +#define CMAP(x) c = (TIFFRGBValue) x; *p++ = PACK(r[c]&0xff, g[c]&0xff, b[c]&0xff); + switch (bitspersample) { + case 1: + CMAP(i>>7); + CMAP((i>>6)&1); + CMAP((i>>5)&1); + CMAP((i>>4)&1); + CMAP((i>>3)&1); + CMAP((i>>2)&1); + CMAP((i>>1)&1); + CMAP(i&1); + break; + case 2: + CMAP(i>>6); + CMAP((i>>4)&3); + CMAP((i>>2)&3); + CMAP(i&3); + break; + case 4: + CMAP(i>>4); + CMAP(i&0xf); + break; + case 8: + CMAP(i); + break; + } +#undef CMAP + } + return (1); +} + +/* + * Construct any mapping table used + * by the associated put routine. + */ +static int +buildMap(TIFFRGBAImage* img) +{ + switch (img->photometric) { + case PHOTOMETRIC_RGB: + case PHOTOMETRIC_YCBCR: + case PHOTOMETRIC_SEPARATED: + if (img->bitspersample == 8) + break; + /* fall thru... */ + case PHOTOMETRIC_MINISBLACK: + case PHOTOMETRIC_MINISWHITE: + if (!setupMap(img)) + return (0); + break; + case PHOTOMETRIC_PALETTE: + /* + * Convert 16-bit colormap to 8-bit (unless it looks + * like an old-style 8-bit colormap). + */ + if (checkcmap(img) == 16) + cvtcmap(img); + else + TIFFWarningExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "Assuming 8-bit colormap"); + /* + * Use mapping table and colormap to construct + * unpacking tables for samples < 8 bits. + */ + if (img->bitspersample <= 8 && !makecmap(img)) + return (0); + break; + } + return (1); +} + +/* + * Select the appropriate conversion routine for packed data. + */ +static int +PickContigCase(TIFFRGBAImage* img) +{ + img->get = TIFFIsTiled(img->tif) ? gtTileContig : gtStripContig; + img->put.contig = NULL; + switch (img->photometric) { + case PHOTOMETRIC_RGB: + switch (img->bitspersample) { + case 8: + if (img->alpha == EXTRASAMPLE_ASSOCALPHA) + img->put.contig = putRGBAAcontig8bittile; + else if (img->alpha == EXTRASAMPLE_UNASSALPHA) + { + if (BuildMapUaToAa(img)) + img->put.contig = putRGBUAcontig8bittile; + } + else + img->put.contig = putRGBcontig8bittile; + break; + case 16: + if (img->alpha == EXTRASAMPLE_ASSOCALPHA) + { + if (BuildMapBitdepth16To8(img)) + img->put.contig = putRGBAAcontig16bittile; + } + else if (img->alpha == EXTRASAMPLE_UNASSALPHA) + { + if (BuildMapBitdepth16To8(img) && + BuildMapUaToAa(img)) + img->put.contig = putRGBUAcontig16bittile; + } + else + { + if (BuildMapBitdepth16To8(img)) + img->put.contig = putRGBcontig16bittile; + } + break; + } + break; + case PHOTOMETRIC_SEPARATED: + if (buildMap(img)) { + if (img->bitspersample == 8) { + if (!img->Map) + img->put.contig = putRGBcontig8bitCMYKtile; + else + img->put.contig = putRGBcontig8bitCMYKMaptile; + } + } + break; + case PHOTOMETRIC_PALETTE: + if (buildMap(img)) { + switch (img->bitspersample) { + case 8: + img->put.contig = put8bitcmaptile; + break; + case 4: + img->put.contig = put4bitcmaptile; + break; + case 2: + img->put.contig = put2bitcmaptile; + break; + case 1: + img->put.contig = put1bitcmaptile; + break; + } + } + break; + case PHOTOMETRIC_MINISWHITE: + case PHOTOMETRIC_MINISBLACK: + if (buildMap(img)) { + switch (img->bitspersample) { + case 16: + img->put.contig = put16bitbwtile; + break; + case 8: + if (img->alpha && img->samplesperpixel == 2) + img->put.contig = putagreytile; + else + img->put.contig = putgreytile; + break; + case 4: + img->put.contig = put4bitbwtile; + break; + case 2: + img->put.contig = put2bitbwtile; + break; + case 1: + img->put.contig = put1bitbwtile; + break; + } + } + break; + case PHOTOMETRIC_YCBCR: + if ((img->bitspersample==8) && (img->samplesperpixel==3)) + { + if (initYCbCrConversion(img)!=0) + { + /* + * The 6.0 spec says that subsampling must be + * one of 1, 2, or 4, and that vertical subsampling + * must always be <= horizontal subsampling; so + * there are only a few possibilities and we just + * enumerate the cases. + * Joris: added support for the [1,2] case, nonetheless, to accomodate + * some OJPEG files + */ + uint16 SubsamplingHor; + uint16 SubsamplingVer; + TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRSUBSAMPLING, &SubsamplingHor, &SubsamplingVer); + switch ((SubsamplingHor<<4)|SubsamplingVer) { + case 0x44: + img->put.contig = putcontig8bitYCbCr44tile; + break; + case 0x42: + img->put.contig = putcontig8bitYCbCr42tile; + break; + case 0x41: + img->put.contig = putcontig8bitYCbCr41tile; + break; + case 0x22: + img->put.contig = putcontig8bitYCbCr22tile; + break; + case 0x21: + img->put.contig = putcontig8bitYCbCr21tile; + break; + case 0x12: + img->put.contig = putcontig8bitYCbCr12tile; + break; + case 0x11: + img->put.contig = putcontig8bitYCbCr11tile; + break; + } + } + } + break; + case PHOTOMETRIC_CIELAB: + if (buildMap(img)) { + if (img->bitspersample == 8) + img->put.contig = initCIELabConversion(img); + break; + } + } + return ((img->get!=NULL) && (img->put.contig!=NULL)); +} + +/* + * Select the appropriate conversion routine for unpacked data. + * + * NB: we assume that unpacked single channel data is directed + * to the "packed routines. + */ +static int +PickSeparateCase(TIFFRGBAImage* img) +{ + img->get = TIFFIsTiled(img->tif) ? gtTileSeparate : gtStripSeparate; + img->put.separate = NULL; + switch (img->photometric) { + case PHOTOMETRIC_MINISWHITE: + case PHOTOMETRIC_MINISBLACK: + /* greyscale images processed pretty much as RGB by gtTileSeparate */ + case PHOTOMETRIC_RGB: + switch (img->bitspersample) { + case 8: + if (img->alpha == EXTRASAMPLE_ASSOCALPHA) + img->put.separate = putRGBAAseparate8bittile; + else if (img->alpha == EXTRASAMPLE_UNASSALPHA) + { + if (BuildMapUaToAa(img)) + img->put.separate = putRGBUAseparate8bittile; + } + else + img->put.separate = putRGBseparate8bittile; + break; + case 16: + if (img->alpha == EXTRASAMPLE_ASSOCALPHA) + { + if (BuildMapBitdepth16To8(img)) + img->put.separate = putRGBAAseparate16bittile; + } + else if (img->alpha == EXTRASAMPLE_UNASSALPHA) + { + if (BuildMapBitdepth16To8(img) && + BuildMapUaToAa(img)) + img->put.separate = putRGBUAseparate16bittile; + } + else + { + if (BuildMapBitdepth16To8(img)) + img->put.separate = putRGBseparate16bittile; + } + break; + } + break; + case PHOTOMETRIC_SEPARATED: + if (img->bitspersample == 8 && img->samplesperpixel == 4) + { + img->alpha = 1; // Not alpha, but seems like the only way to get 4th band + img->put.separate = putCMYKseparate8bittile; + } + break; + case PHOTOMETRIC_YCBCR: + if ((img->bitspersample==8) && (img->samplesperpixel==3)) + { + if (initYCbCrConversion(img)!=0) + { + uint16 hs, vs; + TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRSUBSAMPLING, &hs, &vs); + switch ((hs<<4)|vs) { + case 0x11: + img->put.separate = putseparate8bitYCbCr11tile; + break; + /* TODO: add other cases here */ + } + } + } + break; + } + return ((img->get!=NULL) && (img->put.separate!=NULL)); +} + +static int +BuildMapUaToAa(TIFFRGBAImage* img) +{ + static const char module[]="BuildMapUaToAa"; + uint8* m; + uint16 na,nv; + assert(img->UaToAa==NULL); + img->UaToAa=_TIFFmalloc(65536); + if (img->UaToAa==NULL) + { + TIFFErrorExt(img->tif->tif_clientdata,module,"Out of memory"); + return(0); + } + m=img->UaToAa; + for (na=0; na<256; na++) + { + for (nv=0; nv<256; nv++) + *m++=(nv*na+127)/255; + } + return(1); +} + +static int +BuildMapBitdepth16To8(TIFFRGBAImage* img) +{ + static const char module[]="BuildMapBitdepth16To8"; + uint8* m; + uint32 n; + assert(img->Bitdepth16To8==NULL); + img->Bitdepth16To8=_TIFFmalloc(65536); + if (img->Bitdepth16To8==NULL) + { + TIFFErrorExt(img->tif->tif_clientdata,module,"Out of memory"); + return(0); + } + m=img->Bitdepth16To8; + for (n=0; n<65536; n++) + *m++=(n+128)/257; + return(1); +} + + +/* + * Read a whole strip off data from the file, and convert to RGBA form. + * If this is the last strip, then it will only contain the portion of + * the strip that is actually within the image space. The result is + * organized in bottom to top form. + */ + + +int +TIFFReadRGBAStrip(TIFF* tif, uint32 row, uint32 * raster ) + +{ + char emsg[1024] = ""; + TIFFRGBAImage img; + int ok; + uint32 rowsperstrip, rows_to_read; + + if( TIFFIsTiled( tif ) ) + { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), + "Can't use TIFFReadRGBAStrip() with tiled file."); + return (0); + } + + TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); + if( (row % rowsperstrip) != 0 ) + { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), + "Row passed to TIFFReadRGBAStrip() must be first in a strip."); + return (0); + } + + if (TIFFRGBAImageOK(tif, emsg) && TIFFRGBAImageBegin(&img, tif, 0, emsg)) { + + img.row_offset = row; + img.col_offset = 0; + + if( row + rowsperstrip > img.height ) + rows_to_read = img.height - row; + else + rows_to_read = rowsperstrip; + + ok = TIFFRGBAImageGet(&img, raster, img.width, rows_to_read ); + + TIFFRGBAImageEnd(&img); + } else { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", emsg); + ok = 0; + } + + return (ok); +} + +/* + * Read a whole tile off data from the file, and convert to RGBA form. + * The returned RGBA data is organized from bottom to top of tile, + * and may include zeroed areas if the tile extends off the image. + */ + +int +TIFFReadRGBATile(TIFF* tif, uint32 col, uint32 row, uint32 * raster) + +{ + char emsg[1024] = ""; + TIFFRGBAImage img; + int ok; + uint32 tile_xsize, tile_ysize; + uint32 read_xsize, read_ysize; + uint32 i_row; + + /* + * Verify that our request is legal - on a tile file, and on a + * tile boundary. + */ + + if( !TIFFIsTiled( tif ) ) + { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), + "Can't use TIFFReadRGBATile() with stripped file."); + return (0); + } + + TIFFGetFieldDefaulted(tif, TIFFTAG_TILEWIDTH, &tile_xsize); + TIFFGetFieldDefaulted(tif, TIFFTAG_TILELENGTH, &tile_ysize); + if( (col % tile_xsize) != 0 || (row % tile_ysize) != 0 ) + { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), + "Row/col passed to TIFFReadRGBATile() must be top" + "left corner of a tile."); + return (0); + } + + /* + * Setup the RGBA reader. + */ + + if (!TIFFRGBAImageOK(tif, emsg) + || !TIFFRGBAImageBegin(&img, tif, 0, emsg)) { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", emsg); + return( 0 ); + } + + /* + * The TIFFRGBAImageGet() function doesn't allow us to get off the + * edge of the image, even to fill an otherwise valid tile. So we + * figure out how much we can read, and fix up the tile buffer to + * a full tile configuration afterwards. + */ + + if( row + tile_ysize > img.height ) + read_ysize = img.height - row; + else + read_ysize = tile_ysize; + + if( col + tile_xsize > img.width ) + read_xsize = img.width - col; + else + read_xsize = tile_xsize; + + /* + * Read the chunk of imagery. + */ + + img.row_offset = row; + img.col_offset = col; + + ok = TIFFRGBAImageGet(&img, raster, read_xsize, read_ysize ); + + TIFFRGBAImageEnd(&img); + + /* + * If our read was incomplete we will need to fix up the tile by + * shifting the data around as if a full tile of data is being returned. + * + * This is all the more complicated because the image is organized in + * bottom to top format. + */ + + if( read_xsize == tile_xsize && read_ysize == tile_ysize ) + return( ok ); + + for( i_row = 0; i_row < read_ysize; i_row++ ) { + memmove( raster + (tile_ysize - i_row - 1) * tile_xsize, + raster + (read_ysize - i_row - 1) * read_xsize, + read_xsize * sizeof(uint32) ); + _TIFFmemset( raster + (tile_ysize - i_row - 1) * tile_xsize+read_xsize, + 0, sizeof(uint32) * (tile_xsize - read_xsize) ); + } + + for( i_row = read_ysize; i_row < tile_ysize; i_row++ ) { + _TIFFmemset( raster + (tile_ysize - i_row - 1) * tile_xsize, + 0, sizeof(uint32) * tile_xsize ); + } + + return (ok); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_jbig.c b/Source/LibTIFF4/tif_jbig.c index 644ea90..c67aaa0 100644 --- a/Source/LibTIFF4/tif_jbig.c +++ b/Source/LibTIFF4/tif_jbig.c @@ -1,213 +1,213 @@ -/* $Id: tif_jbig.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * - * JBIG Compression Algorithm Support. - * Contributed by Lee Howard - * - */ - -#include "tiffiop.h" - -#ifdef JBIG_SUPPORT -#include "jbig.h" - -static int JBIGSetupDecode(TIFF* tif) -{ - if (TIFFNumberOfStrips(tif) != 1) - { - TIFFErrorExt(tif->tif_clientdata, "JBIG", "Multistrip images not supported in decoder"); - return 0; - } - - return 1; -} - -static int JBIGDecode(TIFF* tif, uint8* buffer, tmsize_t size, uint16 s) -{ - struct jbg_dec_state decoder; - int decodeStatus = 0; - unsigned char* pImage = NULL; - (void) size, (void) s; - - if (isFillOrder(tif, tif->tif_dir.td_fillorder)) - { - TIFFReverseBits(tif->tif_rawdata, tif->tif_rawdatasize); - } - - jbg_dec_init(&decoder); - -#if defined(HAVE_JBG_NEWLEN) - jbg_newlen(tif->tif_rawdata, (size_t)tif->tif_rawdatasize); - /* - * I do not check the return status of jbg_newlen because even if this - * function fails it does not necessarily mean that decoding the image - * will fail. It is generally only needed for received fax images - * that do not contain the actual length of the image in the BIE - * header. I do not log when an error occurs because that will cause - * problems when converting JBIG encoded TIFF's to - * PostScript. As long as the actual image length is contained in the - * BIE header jbg_dec_in should succeed. - */ -#endif /* HAVE_JBG_NEWLEN */ - - decodeStatus = jbg_dec_in(&decoder, (unsigned char*)tif->tif_rawdata, - (size_t)tif->tif_rawdatasize, NULL); - if (JBG_EOK != decodeStatus) - { - /* - * XXX: JBG_EN constant was defined in pre-2.0 releases of the - * JBIG-KIT. Since the 2.0 the error reporting functions were - * changed. We will handle both cases here. - */ - TIFFErrorExt(tif->tif_clientdata, - "JBIG", "Error (%d) decoding: %s", - decodeStatus, -#if defined(JBG_EN) - jbg_strerror(decodeStatus, JBG_EN) -#else - jbg_strerror(decodeStatus) -#endif - ); - return 0; - } - - pImage = jbg_dec_getimage(&decoder, 0); - _TIFFmemcpy(buffer, pImage, jbg_dec_getsize(&decoder)); - jbg_dec_free(&decoder); - return 1; -} - -static int JBIGSetupEncode(TIFF* tif) -{ - if (TIFFNumberOfStrips(tif) != 1) - { - TIFFErrorExt(tif->tif_clientdata, "JBIG", "Multistrip images not supported in encoder"); - return 0; - } - - return 1; -} - -static int JBIGCopyEncodedData(TIFF* tif, unsigned char* pp, size_t cc, uint16 s) -{ - (void) s; - while (cc > 0) - { - tmsize_t n = (tmsize_t)cc; - - if (tif->tif_rawcc + n > tif->tif_rawdatasize) - { - n = tif->tif_rawdatasize - tif->tif_rawcc; - } - - assert(n > 0); - _TIFFmemcpy(tif->tif_rawcp, pp, n); - tif->tif_rawcp += n; - tif->tif_rawcc += n; - pp += n; - cc -= (size_t)n; - if (tif->tif_rawcc >= tif->tif_rawdatasize && - !TIFFFlushData1(tif)) - { - return (-1); - } - } - - return (1); -} - -static void JBIGOutputBie(unsigned char* buffer, size_t len, void* userData) -{ - TIFF* tif = (TIFF*)userData; - - if (isFillOrder(tif, tif->tif_dir.td_fillorder)) - { - TIFFReverseBits(buffer, (tmsize_t)len); - } - - JBIGCopyEncodedData(tif, buffer, len, 0); -} - -static int JBIGEncode(TIFF* tif, uint8* buffer, tmsize_t size, uint16 s) -{ - TIFFDirectory* dir = &tif->tif_dir; - struct jbg_enc_state encoder; - - (void) size, (void) s; - - jbg_enc_init(&encoder, - dir->td_imagewidth, - dir->td_imagelength, - 1, - &buffer, - JBIGOutputBie, - tif); - /* - * jbg_enc_out does the "real" encoding. As data is encoded, - * JBIGOutputBie is called, which writes the data to the directory. - */ - jbg_enc_out(&encoder); - jbg_enc_free(&encoder); - - return 1; -} - -int TIFFInitJBIG(TIFF* tif, int scheme) -{ - assert(scheme == COMPRESSION_JBIG); - - /* - * These flags are set so the JBIG Codec can control when to reverse - * bits and when not to and to allow the jbig decoder and bit reverser - * to write to memory when necessary. - */ - tif->tif_flags |= TIFF_NOBITREV; - tif->tif_flags &= ~TIFF_MAPPED; - - /* Setup the function pointers for encode, decode, and cleanup. */ - tif->tif_setupdecode = JBIGSetupDecode; - tif->tif_decodestrip = JBIGDecode; - - tif->tif_setupencode = JBIGSetupEncode; - tif->tif_encodestrip = JBIGEncode; - - return 1; -} - -#endif /* JBIG_SUPPORT */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ - -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_jbig.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * + * JBIG Compression Algorithm Support. + * Contributed by Lee Howard + * + */ + +#include "tiffiop.h" + +#ifdef JBIG_SUPPORT +#include "jbig.h" + +static int JBIGSetupDecode(TIFF* tif) +{ + if (TIFFNumberOfStrips(tif) != 1) + { + TIFFErrorExt(tif->tif_clientdata, "JBIG", "Multistrip images not supported in decoder"); + return 0; + } + + return 1; +} + +static int JBIGDecode(TIFF* tif, uint8* buffer, tmsize_t size, uint16 s) +{ + struct jbg_dec_state decoder; + int decodeStatus = 0; + unsigned char* pImage = NULL; + (void) size, (void) s; + + if (isFillOrder(tif, tif->tif_dir.td_fillorder)) + { + TIFFReverseBits(tif->tif_rawdata, tif->tif_rawdatasize); + } + + jbg_dec_init(&decoder); + +#if defined(HAVE_JBG_NEWLEN) + jbg_newlen(tif->tif_rawdata, (size_t)tif->tif_rawdatasize); + /* + * I do not check the return status of jbg_newlen because even if this + * function fails it does not necessarily mean that decoding the image + * will fail. It is generally only needed for received fax images + * that do not contain the actual length of the image in the BIE + * header. I do not log when an error occurs because that will cause + * problems when converting JBIG encoded TIFF's to + * PostScript. As long as the actual image length is contained in the + * BIE header jbg_dec_in should succeed. + */ +#endif /* HAVE_JBG_NEWLEN */ + + decodeStatus = jbg_dec_in(&decoder, (unsigned char*)tif->tif_rawdata, + (size_t)tif->tif_rawdatasize, NULL); + if (JBG_EOK != decodeStatus) + { + /* + * XXX: JBG_EN constant was defined in pre-2.0 releases of the + * JBIG-KIT. Since the 2.0 the error reporting functions were + * changed. We will handle both cases here. + */ + TIFFErrorExt(tif->tif_clientdata, + "JBIG", "Error (%d) decoding: %s", + decodeStatus, +#if defined(JBG_EN) + jbg_strerror(decodeStatus, JBG_EN) +#else + jbg_strerror(decodeStatus) +#endif + ); + return 0; + } + + pImage = jbg_dec_getimage(&decoder, 0); + _TIFFmemcpy(buffer, pImage, jbg_dec_getsize(&decoder)); + jbg_dec_free(&decoder); + return 1; +} + +static int JBIGSetupEncode(TIFF* tif) +{ + if (TIFFNumberOfStrips(tif) != 1) + { + TIFFErrorExt(tif->tif_clientdata, "JBIG", "Multistrip images not supported in encoder"); + return 0; + } + + return 1; +} + +static int JBIGCopyEncodedData(TIFF* tif, unsigned char* pp, size_t cc, uint16 s) +{ + (void) s; + while (cc > 0) + { + tmsize_t n = (tmsize_t)cc; + + if (tif->tif_rawcc + n > tif->tif_rawdatasize) + { + n = tif->tif_rawdatasize - tif->tif_rawcc; + } + + assert(n > 0); + _TIFFmemcpy(tif->tif_rawcp, pp, n); + tif->tif_rawcp += n; + tif->tif_rawcc += n; + pp += n; + cc -= (size_t)n; + if (tif->tif_rawcc >= tif->tif_rawdatasize && + !TIFFFlushData1(tif)) + { + return (-1); + } + } + + return (1); +} + +static void JBIGOutputBie(unsigned char* buffer, size_t len, void* userData) +{ + TIFF* tif = (TIFF*)userData; + + if (isFillOrder(tif, tif->tif_dir.td_fillorder)) + { + TIFFReverseBits(buffer, (tmsize_t)len); + } + + JBIGCopyEncodedData(tif, buffer, len, 0); +} + +static int JBIGEncode(TIFF* tif, uint8* buffer, tmsize_t size, uint16 s) +{ + TIFFDirectory* dir = &tif->tif_dir; + struct jbg_enc_state encoder; + + (void) size, (void) s; + + jbg_enc_init(&encoder, + dir->td_imagewidth, + dir->td_imagelength, + 1, + &buffer, + JBIGOutputBie, + tif); + /* + * jbg_enc_out does the "real" encoding. As data is encoded, + * JBIGOutputBie is called, which writes the data to the directory. + */ + jbg_enc_out(&encoder); + jbg_enc_free(&encoder); + + return 1; +} + +int TIFFInitJBIG(TIFF* tif, int scheme) +{ + assert(scheme == COMPRESSION_JBIG); + + /* + * These flags are set so the JBIG Codec can control when to reverse + * bits and when not to and to allow the jbig decoder and bit reverser + * to write to memory when necessary. + */ + tif->tif_flags |= TIFF_NOBITREV; + tif->tif_flags &= ~TIFF_MAPPED; + + /* Setup the function pointers for encode, decode, and cleanup. */ + tif->tif_setupdecode = JBIGSetupDecode; + tif->tif_decodestrip = JBIGDecode; + + tif->tif_setupencode = JBIGSetupEncode; + tif->tif_encodestrip = JBIGEncode; + + return 1; +} + +#endif /* JBIG_SUPPORT */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ + +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_jpeg.c b/Source/LibTIFF4/tif_jpeg.c index e087e8a..8853aec 100644 --- a/Source/LibTIFF4/tif_jpeg.c +++ b/Source/LibTIFF4/tif_jpeg.c @@ -1,2304 +1,2304 @@ -/* $Id: tif_jpeg.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1994-1997 Sam Leffler - * Copyright (c) 1994-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#define WIN32_LEAN_AND_MEAN -#define VC_EXTRALEAN - -#include "tiffiop.h" -#ifdef JPEG_SUPPORT - -/* - * TIFF Library - * - * JPEG Compression support per TIFF Technical Note #2 - * (*not* per the original TIFF 6.0 spec). - * - * This file is simply an interface to the libjpeg library written by - * the Independent JPEG Group. You need release 5 or later of the IJG - * code, which you can find on the Internet at ftp.uu.net:/graphics/jpeg/. - * - * Contributed by Tom Lane . - */ -#include - -int TIFFFillStrip(TIFF* tif, uint32 strip); -int TIFFFillTile(TIFF* tif, uint32 tile); -int TIFFReInitJPEG_12( TIFF *tif, int scheme, int is_encode ); - -/* We undefine FAR to avoid conflict with JPEG definition */ - -#ifdef FAR -#undef FAR -#endif - -/* - Libjpeg's jmorecfg.h defines INT16 and INT32, but only if XMD_H is - not defined. Unfortunately, the MinGW and Borland compilers include - a typedef for INT32, which causes a conflict. MSVC does not include - a conficting typedef given the headers which are included. -*/ -#if defined(__BORLANDC__) || defined(__MINGW32__) -# define XMD_H 1 -#endif - -/* - The windows RPCNDR.H file defines boolean, but defines it with the - unsigned char size. You should compile JPEG library using appropriate - definitions in jconfig.h header, but many users compile library in wrong - way. That causes errors of the following type: - - "JPEGLib: JPEG parameter struct mismatch: library thinks size is 432, - caller expects 464" - - For such users we wil fix the problem here. See install.doc file from - the JPEG library distribution for details. -*/ - -/* Define "boolean" as unsigned char, not int, per Windows custom. */ -#if defined(__WIN32__) && !defined(__MINGW32__) -# ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ - typedef unsigned char boolean; -# endif -# define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ -#endif - -#include "../LibJPEG/jpeglib.h" -#include "../LibJPEG/jerror.h" - -/* - * Do we want to do special processing suitable for when JSAMPLE is a - * 16bit value? - */ - -#if defined(JPEG_LIB_MK1) -# define JPEG_LIB_MK1_OR_12BIT 1 -#elif BITS_IN_JSAMPLE == 12 -# define JPEG_LIB_MK1_OR_12BIT 1 -#endif - -/* - * We are using width_in_blocks which is supposed to be private to - * libjpeg. Unfortunately, the libjpeg delivered with Cygwin has - * renamed this member to width_in_data_units. Since the header has - * also renamed a define, use that unique define name in order to - * detect the problem header and adjust to suit. - */ -#if defined(D_MAX_DATA_UNITS_IN_MCU) -#define width_in_blocks width_in_data_units -#endif - -/* - * On some machines it may be worthwhile to use _setjmp or sigsetjmp - * in place of plain setjmp. These macros will make it easier. - */ -#define SETJMP(jbuf) setjmp(jbuf) -#define LONGJMP(jbuf,code) longjmp(jbuf,code) -#define JMP_BUF jmp_buf - -typedef struct jpeg_destination_mgr jpeg_destination_mgr; -typedef struct jpeg_source_mgr jpeg_source_mgr; -typedef struct jpeg_error_mgr jpeg_error_mgr; - -/* - * State block for each open TIFF file using - * libjpeg to do JPEG compression/decompression. - * - * libjpeg's visible state is either a jpeg_compress_struct - * or jpeg_decompress_struct depending on which way we - * are going. comm can be used to refer to the fields - * which are common to both. - * - * NB: cinfo is required to be the first member of JPEGState, - * so we can safely cast JPEGState* -> jpeg_xxx_struct* - * and vice versa! - */ -typedef struct { - union { - struct jpeg_compress_struct c; - struct jpeg_decompress_struct d; - struct jpeg_common_struct comm; - } cinfo; /* NB: must be first */ - int cinfo_initialized; - - jpeg_error_mgr err; /* libjpeg error manager */ - JMP_BUF exit_jmpbuf; /* for catching libjpeg failures */ - /* - * The following two members could be a union, but - * they're small enough that it's not worth the effort. - */ - jpeg_destination_mgr dest; /* data dest for compression */ - jpeg_source_mgr src; /* data source for decompression */ - /* private state */ - TIFF* tif; /* back link needed by some code */ - uint16 photometric; /* copy of PhotometricInterpretation */ - uint16 h_sampling; /* luminance sampling factors */ - uint16 v_sampling; - tmsize_t bytesperline; /* decompressed bytes per scanline */ - /* pointers to intermediate buffers when processing downsampled data */ - JSAMPARRAY ds_buffer[MAX_COMPONENTS]; - int scancount; /* number of "scanlines" accumulated */ - int samplesperclump; - - TIFFVGetMethod vgetparent; /* super-class method */ - TIFFVSetMethod vsetparent; /* super-class method */ - TIFFPrintMethod printdir; /* super-class method */ - TIFFStripMethod defsparent; /* super-class method */ - TIFFTileMethod deftparent; /* super-class method */ - /* pseudo-tag fields */ - void* jpegtables; /* JPEGTables tag value, or NULL */ - uint32 jpegtables_length; /* number of bytes in same */ - int jpegquality; /* Compression quality level */ - int jpegcolormode; /* Auto RGB<=>YCbCr convert? */ - int jpegtablesmode; /* What to put in JPEGTables */ - - int ycbcrsampling_fetched; -} JPEGState; - -#define JState(tif) ((JPEGState*)(tif)->tif_data) - -static int JPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s); -static int JPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s); -static int JPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s); -static int JPEGEncodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s); -static int JPEGInitializeLibJPEG(TIFF * tif, int decode ); -static int DecodeRowError(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s); - -#define FIELD_JPEGTABLES (FIELD_CODEC+0) - -static const TIFFField jpegFields[] = { - { TIFFTAG_JPEGTABLES, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_C32_UINT8, FIELD_JPEGTABLES, FALSE, TRUE, "JPEGTables", NULL }, - { TIFFTAG_JPEGQUALITY, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "", NULL }, - { TIFFTAG_JPEGCOLORMODE, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "", NULL }, - { TIFFTAG_JPEGTABLESMODE, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "", NULL } -}; - -/* - * libjpeg interface layer. - * - * We use setjmp/longjmp to return control to libtiff - * when a fatal error is encountered within the JPEG - * library. We also direct libjpeg error and warning - * messages through the appropriate libtiff handlers. - */ - -/* - * Error handling routines (these replace corresponding - * IJG routines from jerror.c). These are used for both - * compression and decompression. - */ -static void -TIFFjpeg_error_exit(j_common_ptr cinfo) -{ - JPEGState *sp = (JPEGState *) cinfo; /* NB: cinfo assumed first */ - char buffer[JMSG_LENGTH_MAX]; - - (*cinfo->err->format_message) (cinfo, buffer); - TIFFErrorExt(sp->tif->tif_clientdata, "JPEGLib", "%s", buffer); /* display the error message */ - jpeg_abort(cinfo); /* clean up libjpeg state */ - LONGJMP(sp->exit_jmpbuf, 1); /* return to libtiff caller */ -} - -/* - * This routine is invoked only for warning messages, - * since error_exit does its own thing and trace_level - * is never set > 0. - */ -static void -TIFFjpeg_output_message(j_common_ptr cinfo) -{ - char buffer[JMSG_LENGTH_MAX]; - - (*cinfo->err->format_message) (cinfo, buffer); - TIFFWarningExt(((JPEGState *) cinfo)->tif->tif_clientdata, "JPEGLib", "%s", buffer); -} - -/* - * Interface routines. This layer of routines exists - * primarily to limit side-effects from using setjmp. - * Also, normal/error returns are converted into return - * values per libtiff practice. - */ -#define CALLJPEG(sp, fail, op) (SETJMP((sp)->exit_jmpbuf) ? (fail) : (op)) -#define CALLVJPEG(sp, op) CALLJPEG(sp, 0, ((op),1)) - -static int -TIFFjpeg_create_compress(JPEGState* sp) -{ - /* initialize JPEG error handling */ - sp->cinfo.c.err = jpeg_std_error(&sp->err); - sp->err.error_exit = TIFFjpeg_error_exit; - sp->err.output_message = TIFFjpeg_output_message; - - return CALLVJPEG(sp, jpeg_create_compress(&sp->cinfo.c)); -} - -static int -TIFFjpeg_create_decompress(JPEGState* sp) -{ - /* initialize JPEG error handling */ - sp->cinfo.d.err = jpeg_std_error(&sp->err); - sp->err.error_exit = TIFFjpeg_error_exit; - sp->err.output_message = TIFFjpeg_output_message; - - return CALLVJPEG(sp, jpeg_create_decompress(&sp->cinfo.d)); -} - -static int -TIFFjpeg_set_defaults(JPEGState* sp) -{ - return CALLVJPEG(sp, jpeg_set_defaults(&sp->cinfo.c)); -} - -static int -TIFFjpeg_set_colorspace(JPEGState* sp, J_COLOR_SPACE colorspace) -{ - return CALLVJPEG(sp, jpeg_set_colorspace(&sp->cinfo.c, colorspace)); -} - -static int -TIFFjpeg_set_quality(JPEGState* sp, int quality, boolean force_baseline) -{ - return CALLVJPEG(sp, - jpeg_set_quality(&sp->cinfo.c, quality, force_baseline)); -} - -static int -TIFFjpeg_suppress_tables(JPEGState* sp, boolean suppress) -{ - return CALLVJPEG(sp, jpeg_suppress_tables(&sp->cinfo.c, suppress)); -} - -static int -TIFFjpeg_start_compress(JPEGState* sp, boolean write_all_tables) -{ - return CALLVJPEG(sp, - jpeg_start_compress(&sp->cinfo.c, write_all_tables)); -} - -static int -TIFFjpeg_write_scanlines(JPEGState* sp, JSAMPARRAY scanlines, int num_lines) -{ - return CALLJPEG(sp, -1, (int) jpeg_write_scanlines(&sp->cinfo.c, - scanlines, (JDIMENSION) num_lines)); -} - -static int -TIFFjpeg_write_raw_data(JPEGState* sp, JSAMPIMAGE data, int num_lines) -{ - return CALLJPEG(sp, -1, (int) jpeg_write_raw_data(&sp->cinfo.c, - data, (JDIMENSION) num_lines)); -} - -static int -TIFFjpeg_finish_compress(JPEGState* sp) -{ - return CALLVJPEG(sp, jpeg_finish_compress(&sp->cinfo.c)); -} - -static int -TIFFjpeg_write_tables(JPEGState* sp) -{ - return CALLVJPEG(sp, jpeg_write_tables(&sp->cinfo.c)); -} - -static int -TIFFjpeg_read_header(JPEGState* sp, boolean require_image) -{ - return CALLJPEG(sp, -1, jpeg_read_header(&sp->cinfo.d, require_image)); -} - -static int -TIFFjpeg_start_decompress(JPEGState* sp) -{ - return CALLVJPEG(sp, jpeg_start_decompress(&sp->cinfo.d)); -} - -static int -TIFFjpeg_read_scanlines(JPEGState* sp, JSAMPARRAY scanlines, int max_lines) -{ - return CALLJPEG(sp, -1, (int) jpeg_read_scanlines(&sp->cinfo.d, - scanlines, (JDIMENSION) max_lines)); -} - -static int -TIFFjpeg_read_raw_data(JPEGState* sp, JSAMPIMAGE data, int max_lines) -{ - return CALLJPEG(sp, -1, (int) jpeg_read_raw_data(&sp->cinfo.d, - data, (JDIMENSION) max_lines)); -} - -static int -TIFFjpeg_finish_decompress(JPEGState* sp) -{ - return CALLJPEG(sp, -1, (int) jpeg_finish_decompress(&sp->cinfo.d)); -} - -static int -TIFFjpeg_abort(JPEGState* sp) -{ - return CALLVJPEG(sp, jpeg_abort(&sp->cinfo.comm)); -} - -static int -TIFFjpeg_destroy(JPEGState* sp) -{ - return CALLVJPEG(sp, jpeg_destroy(&sp->cinfo.comm)); -} - -static JSAMPARRAY -TIFFjpeg_alloc_sarray(JPEGState* sp, int pool_id, - JDIMENSION samplesperrow, JDIMENSION numrows) -{ - return CALLJPEG(sp, (JSAMPARRAY) NULL, - (*sp->cinfo.comm.mem->alloc_sarray) - (&sp->cinfo.comm, pool_id, samplesperrow, numrows)); -} - -/* - * JPEG library destination data manager. - * These routines direct compressed data from libjpeg into the - * libtiff output buffer. - */ - -static void -std_init_destination(j_compress_ptr cinfo) -{ - JPEGState* sp = (JPEGState*) cinfo; - TIFF* tif = sp->tif; - - sp->dest.next_output_byte = (JOCTET*) tif->tif_rawdata; - sp->dest.free_in_buffer = (size_t) tif->tif_rawdatasize; -} - -static boolean -std_empty_output_buffer(j_compress_ptr cinfo) -{ - JPEGState* sp = (JPEGState*) cinfo; - TIFF* tif = sp->tif; - - /* the entire buffer has been filled */ - tif->tif_rawcc = tif->tif_rawdatasize; - -#ifdef IPPJ_HUFF - /* - * The Intel IPP performance library does not necessarily fill up - * the whole output buffer on each pass, so only dump out the parts - * that have been filled. - * http://trac.osgeo.org/gdal/wiki/JpegIPP - */ - if ( sp->dest.free_in_buffer >= 0 ) { - tif->tif_rawcc = tif->tif_rawdatasize - sp->dest.free_in_buffer; - } -#endif - - TIFFFlushData1(tif); - sp->dest.next_output_byte = (JOCTET*) tif->tif_rawdata; - sp->dest.free_in_buffer = (size_t) tif->tif_rawdatasize; - - return (TRUE); -} - -static void -std_term_destination(j_compress_ptr cinfo) -{ - JPEGState* sp = (JPEGState*) cinfo; - TIFF* tif = sp->tif; - - tif->tif_rawcp = (uint8*) sp->dest.next_output_byte; - tif->tif_rawcc = - tif->tif_rawdatasize - (tmsize_t) sp->dest.free_in_buffer; - /* NB: libtiff does the final buffer flush */ -} - -static void -TIFFjpeg_data_dest(JPEGState* sp, TIFF* tif) -{ - (void) tif; - sp->cinfo.c.dest = &sp->dest; - sp->dest.init_destination = std_init_destination; - sp->dest.empty_output_buffer = std_empty_output_buffer; - sp->dest.term_destination = std_term_destination; -} - -/* - * Alternate destination manager for outputting to JPEGTables field. - */ - -static void -tables_init_destination(j_compress_ptr cinfo) -{ - JPEGState* sp = (JPEGState*) cinfo; - - /* while building, jpegtables_length is allocated buffer size */ - sp->dest.next_output_byte = (JOCTET*) sp->jpegtables; - sp->dest.free_in_buffer = (size_t) sp->jpegtables_length; -} - -static boolean -tables_empty_output_buffer(j_compress_ptr cinfo) -{ - JPEGState* sp = (JPEGState*) cinfo; - void* newbuf; - - /* the entire buffer has been filled; enlarge it by 1000 bytes */ - newbuf = _TIFFrealloc((void*) sp->jpegtables, - (tmsize_t) (sp->jpegtables_length + 1000)); - if (newbuf == NULL) - ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 100); - sp->dest.next_output_byte = (JOCTET*) newbuf + sp->jpegtables_length; - sp->dest.free_in_buffer = (size_t) 1000; - sp->jpegtables = newbuf; - sp->jpegtables_length += 1000; - return (TRUE); -} - -static void -tables_term_destination(j_compress_ptr cinfo) -{ - JPEGState* sp = (JPEGState*) cinfo; - - /* set tables length to number of bytes actually emitted */ - sp->jpegtables_length -= (uint32) sp->dest.free_in_buffer; -} - -static int -TIFFjpeg_tables_dest(JPEGState* sp, TIFF* tif) -{ - (void) tif; - /* - * Allocate a working buffer for building tables. - * Initial size is 1000 bytes, which is usually adequate. - */ - if (sp->jpegtables) - _TIFFfree(sp->jpegtables); - sp->jpegtables_length = 1000; - sp->jpegtables = (void*) _TIFFmalloc((tmsize_t) sp->jpegtables_length); - if (sp->jpegtables == NULL) { - sp->jpegtables_length = 0; - TIFFErrorExt(sp->tif->tif_clientdata, "TIFFjpeg_tables_dest", "No space for JPEGTables"); - return (0); - } - sp->cinfo.c.dest = &sp->dest; - sp->dest.init_destination = tables_init_destination; - sp->dest.empty_output_buffer = tables_empty_output_buffer; - sp->dest.term_destination = tables_term_destination; - return (1); -} - -/* - * JPEG library source data manager. - * These routines supply compressed data to libjpeg. - */ - -static void -std_init_source(j_decompress_ptr cinfo) -{ - JPEGState* sp = (JPEGState*) cinfo; - TIFF* tif = sp->tif; - - sp->src.next_input_byte = (const JOCTET*) tif->tif_rawdata; - sp->src.bytes_in_buffer = (size_t) tif->tif_rawcc; -} - -static boolean -std_fill_input_buffer(j_decompress_ptr cinfo) -{ - JPEGState* sp = (JPEGState* ) cinfo; - static const JOCTET dummy_EOI[2] = { 0xFF, JPEG_EOI }; - -#ifdef IPPJ_HUFF - /* - * The Intel IPP performance library does not necessarily read the whole - * input buffer in one pass, so it is possible to get here with data - * yet to read. - * - * We just return without doing anything, until the entire buffer has - * been read. - * http://trac.osgeo.org/gdal/wiki/JpegIPP - */ - if( sp->src.bytes_in_buffer > 0 ) { - return (TRUE); - } -#endif - - /* - * Normally the whole strip/tile is read and so we don't need to do - * a fill. In the case of CHUNKY_STRIP_READ_SUPPORT we might not have - * all the data, but the rawdata is refreshed between scanlines and - * we push this into the io machinery in JPEGDecode(). - * http://trac.osgeo.org/gdal/ticket/3894 - */ - - WARNMS(cinfo, JWRN_JPEG_EOF); - /* insert a fake EOI marker */ - sp->src.next_input_byte = dummy_EOI; - sp->src.bytes_in_buffer = 2; - return (TRUE); -} - -static void -std_skip_input_data(j_decompress_ptr cinfo, long num_bytes) -{ - JPEGState* sp = (JPEGState*) cinfo; - - if (num_bytes > 0) { - if ((size_t)num_bytes > sp->src.bytes_in_buffer) { - /* oops, buffer overrun */ - (void) std_fill_input_buffer(cinfo); - } else { - sp->src.next_input_byte += (size_t) num_bytes; - sp->src.bytes_in_buffer -= (size_t) num_bytes; - } - } -} - -static void -std_term_source(j_decompress_ptr cinfo) -{ - /* No work necessary here */ - (void) cinfo; -} - -static void -TIFFjpeg_data_src(JPEGState* sp, TIFF* tif) -{ - (void) tif; - sp->cinfo.d.src = &sp->src; - sp->src.init_source = std_init_source; - sp->src.fill_input_buffer = std_fill_input_buffer; - sp->src.skip_input_data = std_skip_input_data; - sp->src.resync_to_restart = jpeg_resync_to_restart; - sp->src.term_source = std_term_source; - sp->src.bytes_in_buffer = 0; /* for safety */ - sp->src.next_input_byte = NULL; -} - -/* - * Alternate source manager for reading from JPEGTables. - * We can share all the code except for the init routine. - */ - -static void -tables_init_source(j_decompress_ptr cinfo) -{ - JPEGState* sp = (JPEGState*) cinfo; - - sp->src.next_input_byte = (const JOCTET*) sp->jpegtables; - sp->src.bytes_in_buffer = (size_t) sp->jpegtables_length; -} - -static void -TIFFjpeg_tables_src(JPEGState* sp, TIFF* tif) -{ - TIFFjpeg_data_src(sp, tif); - sp->src.init_source = tables_init_source; -} - -/* - * Allocate downsampled-data buffers needed for downsampled I/O. - * We use values computed in jpeg_start_compress or jpeg_start_decompress. - * We use libjpeg's allocator so that buffers will be released automatically - * when done with strip/tile. - * This is also a handy place to compute samplesperclump, bytesperline. - */ -static int -alloc_downsampled_buffers(TIFF* tif, jpeg_component_info* comp_info, - int num_components) -{ - JPEGState* sp = JState(tif); - int ci; - jpeg_component_info* compptr; - JSAMPARRAY buf; - int samples_per_clump = 0; - - for (ci = 0, compptr = comp_info; ci < num_components; - ci++, compptr++) { - samples_per_clump += compptr->h_samp_factor * - compptr->v_samp_factor; - buf = TIFFjpeg_alloc_sarray(sp, JPOOL_IMAGE, - compptr->width_in_blocks * DCTSIZE, - (JDIMENSION) (compptr->v_samp_factor*DCTSIZE)); - if (buf == NULL) - return (0); - sp->ds_buffer[ci] = buf; - } - sp->samplesperclump = samples_per_clump; - return (1); -} - - -/* - * JPEG Decoding. - */ - -#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING - -#define JPEG_MARKER_SOF0 0xC0 -#define JPEG_MARKER_SOF1 0xC1 -#define JPEG_MARKER_SOF3 0xC3 -#define JPEG_MARKER_DHT 0xC4 -#define JPEG_MARKER_SOI 0xD8 -#define JPEG_MARKER_SOS 0xDA -#define JPEG_MARKER_DQT 0xDB -#define JPEG_MARKER_DRI 0xDD -#define JPEG_MARKER_APP0 0xE0 -#define JPEG_MARKER_COM 0xFE -struct JPEGFixupTagsSubsamplingData -{ - TIFF* tif; - void* buffer; - uint32 buffersize; - uint8* buffercurrentbyte; - uint32 bufferbytesleft; - uint64 fileoffset; - uint64 filebytesleft; - uint8 filepositioned; -}; -static void JPEGFixupTagsSubsampling(TIFF* tif); -static int JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* data); -static int JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData* data, uint8* result); -static int JPEGFixupTagsSubsamplingReadWord(struct JPEGFixupTagsSubsamplingData* data, uint16* result); -static void JPEGFixupTagsSubsamplingSkip(struct JPEGFixupTagsSubsamplingData* data, uint16 skiplength); - -#endif - -static int -JPEGFixupTags(TIFF* tif) -{ -#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING - if ((tif->tif_dir.td_photometric==PHOTOMETRIC_YCBCR)&& - (tif->tif_dir.td_planarconfig==PLANARCONFIG_CONTIG)&& - (tif->tif_dir.td_samplesperpixel==3)) - JPEGFixupTagsSubsampling(tif); -#endif - - return(1); -} - -#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING - -static void -JPEGFixupTagsSubsampling(TIFF* tif) -{ - /* - * Some JPEG-in-TIFF produces do not emit the YCBCRSUBSAMPLING values in - * the TIFF tags, but still use non-default (2,2) values within the jpeg - * data stream itself. In order for TIFF applications to work properly - * - for instance to get the strip buffer size right - it is imperative - * that the subsampling be available before we start reading the image - * data normally. This function will attempt to analyze the first strip in - * order to get the sampling values from the jpeg data stream. - * - * Note that JPEGPreDeocode() will produce a fairly loud warning when the - * discovered sampling does not match the default sampling (2,2) or whatever - * was actually in the tiff tags. - * - * See the bug in bugzilla for details: - * - * http://bugzilla.remotesensing.org/show_bug.cgi?id=168 - * - * Frank Warmerdam, July 2002 - * Joris Van Damme, May 2007 - */ - static const char module[] = "JPEGFixupTagsSubsampling"; - struct JPEGFixupTagsSubsamplingData m; - - _TIFFFillStriles( tif ); - - if( tif->tif_dir.td_stripbytecount == NULL - || tif->tif_dir.td_stripbytecount[0] == 0 ) - { - /* Do not even try to check if the first strip/tile does not - yet exist, as occurs when GDAL has created a new NULL file - for instance. */ - return; - } - - m.tif=tif; - m.buffersize=2048; - m.buffer=_TIFFmalloc(m.buffersize); - if (m.buffer==NULL) - { - TIFFWarningExt(tif->tif_clientdata,module, - "Unable to allocate memory for auto-correcting of subsampling values; auto-correcting skipped"); - return; - } - m.buffercurrentbyte=NULL; - m.bufferbytesleft=0; - m.fileoffset=tif->tif_dir.td_stripoffset[0]; - m.filepositioned=0; - m.filebytesleft=tif->tif_dir.td_stripbytecount[0]; - if (!JPEGFixupTagsSubsamplingSec(&m)) - TIFFWarningExt(tif->tif_clientdata,module, - "Unable to auto-correct subsampling values, likely corrupt JPEG compressed data in first strip/tile; auto-correcting skipped"); - _TIFFfree(m.buffer); -} - -static int -JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* data) -{ - static const char module[] = "JPEGFixupTagsSubsamplingSec"; - uint8 m; - while (1) - { - while (1) - { - if (!JPEGFixupTagsSubsamplingReadByte(data,&m)) - return(0); - if (m==255) - break; - } - while (1) - { - if (!JPEGFixupTagsSubsamplingReadByte(data,&m)) - return(0); - if (m!=255) - break; - } - switch (m) - { - case JPEG_MARKER_SOI: - /* this type of marker has no data and should be skipped */ - break; - case JPEG_MARKER_COM: - case JPEG_MARKER_APP0: - case JPEG_MARKER_APP0+1: - case JPEG_MARKER_APP0+2: - case JPEG_MARKER_APP0+3: - case JPEG_MARKER_APP0+4: - case JPEG_MARKER_APP0+5: - case JPEG_MARKER_APP0+6: - case JPEG_MARKER_APP0+7: - case JPEG_MARKER_APP0+8: - case JPEG_MARKER_APP0+9: - case JPEG_MARKER_APP0+10: - case JPEG_MARKER_APP0+11: - case JPEG_MARKER_APP0+12: - case JPEG_MARKER_APP0+13: - case JPEG_MARKER_APP0+14: - case JPEG_MARKER_APP0+15: - case JPEG_MARKER_DQT: - case JPEG_MARKER_SOS: - case JPEG_MARKER_DHT: - case JPEG_MARKER_DRI: - /* this type of marker has data, but it has no use to us and should be skipped */ - { - uint16 n; - if (!JPEGFixupTagsSubsamplingReadWord(data,&n)) - return(0); - if (n<2) - return(0); - n-=2; - if (n>0) - JPEGFixupTagsSubsamplingSkip(data,n); - } - break; - case JPEG_MARKER_SOF0: - case JPEG_MARKER_SOF1: - /* this marker contains the subsampling factors we're scanning for */ - { - uint16 n; - uint16 o; - uint8 p; - uint8 ph,pv; - if (!JPEGFixupTagsSubsamplingReadWord(data,&n)) - return(0); - if (n!=8+data->tif->tif_dir.td_samplesperpixel*3) - return(0); - JPEGFixupTagsSubsamplingSkip(data,7); - if (!JPEGFixupTagsSubsamplingReadByte(data,&p)) - return(0); - ph=(p>>4); - pv=(p&15); - JPEGFixupTagsSubsamplingSkip(data,1); - for (o=1; otif->tif_dir.td_samplesperpixel; o++) - { - JPEGFixupTagsSubsamplingSkip(data,1); - if (!JPEGFixupTagsSubsamplingReadByte(data,&p)) - return(0); - if (p!=0x11) - { - TIFFWarningExt(data->tif->tif_clientdata,module, - "Subsampling values inside JPEG compressed data have no TIFF equivalent, auto-correction of TIFF subsampling values failed"); - return(1); - } - JPEGFixupTagsSubsamplingSkip(data,1); - } - if (((ph!=1)&&(ph!=2)&&(ph!=4))||((pv!=1)&&(pv!=2)&&(pv!=4))) - { - TIFFWarningExt(data->tif->tif_clientdata,module, - "Subsampling values inside JPEG compressed data have no TIFF equivalent, auto-correction of TIFF subsampling values failed"); - return(1); - } - if ((ph!=data->tif->tif_dir.td_ycbcrsubsampling[0])||(pv!=data->tif->tif_dir.td_ycbcrsubsampling[1])) - { - TIFFWarningExt(data->tif->tif_clientdata,module, - "Auto-corrected former TIFF subsampling values [%d,%d] to match subsampling values inside JPEG compressed data [%d,%d]", - (int)data->tif->tif_dir.td_ycbcrsubsampling[0], - (int)data->tif->tif_dir.td_ycbcrsubsampling[1], - (int)ph,(int)pv); - data->tif->tif_dir.td_ycbcrsubsampling[0]=ph; - data->tif->tif_dir.td_ycbcrsubsampling[1]=pv; - } - } - return(1); - default: - return(0); - } - } -} - -static int -JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData* data, uint8* result) -{ - if (data->bufferbytesleft==0) - { - uint32 m; - if (data->filebytesleft==0) - return(0); - if (!data->filepositioned) - { - TIFFSeekFile(data->tif,data->fileoffset,SEEK_SET); - data->filepositioned=1; - } - m=data->buffersize; - if ((uint64)m>data->filebytesleft) - m=(uint32)data->filebytesleft; - assert(m<0x80000000UL); - if (TIFFReadFile(data->tif,data->buffer,(tmsize_t)m)!=(tmsize_t)m) - return(0); - data->buffercurrentbyte=data->buffer; - data->bufferbytesleft=m; - data->fileoffset+=m; - data->filebytesleft-=m; - } - *result=*data->buffercurrentbyte; - data->buffercurrentbyte++; - data->bufferbytesleft--; - return(1); -} - -static int -JPEGFixupTagsSubsamplingReadWord(struct JPEGFixupTagsSubsamplingData* data, uint16* result) -{ - uint8 ma; - uint8 mb; - if (!JPEGFixupTagsSubsamplingReadByte(data,&ma)) - return(0); - if (!JPEGFixupTagsSubsamplingReadByte(data,&mb)) - return(0); - *result=(ma<<8)|mb; - return(1); -} - -static void -JPEGFixupTagsSubsamplingSkip(struct JPEGFixupTagsSubsamplingData* data, uint16 skiplength) -{ - if ((uint32)skiplength<=data->bufferbytesleft) - { - data->buffercurrentbyte+=skiplength; - data->bufferbytesleft-=skiplength; - } - else - { - uint16 m; - m=skiplength-data->bufferbytesleft; - if (m<=data->filebytesleft) - { - data->bufferbytesleft=0; - data->fileoffset+=m; - data->filebytesleft-=m; - data->filepositioned=0; - } - else - { - data->bufferbytesleft=0; - data->filebytesleft=0; - } - } -} - -#endif - - -static int -JPEGSetupDecode(TIFF* tif) -{ - JPEGState* sp = JState(tif); - TIFFDirectory *td = &tif->tif_dir; - -#if defined(JPEG_DUAL_MODE_8_12) && !defined(TIFFInitJPEG) - if( tif->tif_dir.td_bitspersample == 12 ) - return TIFFReInitJPEG_12( tif, COMPRESSION_JPEG, 0 ); -#endif - - JPEGInitializeLibJPEG( tif, TRUE ); - - assert(sp != NULL); - assert(sp->cinfo.comm.is_decompressor); - - /* Read JPEGTables if it is present */ - if (TIFFFieldSet(tif,FIELD_JPEGTABLES)) { - TIFFjpeg_tables_src(sp, tif); - if(TIFFjpeg_read_header(sp,FALSE) != JPEG_HEADER_TABLES_ONLY) { - TIFFErrorExt(tif->tif_clientdata, "JPEGSetupDecode", "Bogus JPEGTables field"); - return (0); - } - } - - /* Grab parameters that are same for all strips/tiles */ - sp->photometric = td->td_photometric; - switch (sp->photometric) { - case PHOTOMETRIC_YCBCR: - sp->h_sampling = td->td_ycbcrsubsampling[0]; - sp->v_sampling = td->td_ycbcrsubsampling[1]; - break; - default: - /* TIFF 6.0 forbids subsampling of all other color spaces */ - sp->h_sampling = 1; - sp->v_sampling = 1; - break; - } - - /* Set up for reading normal data */ - TIFFjpeg_data_src(sp, tif); - tif->tif_postdecode = _TIFFNoPostDecode; /* override byte swapping */ - return (1); -} - -/* - * Set up for decoding a strip or tile. - */ -static int -JPEGPreDecode(TIFF* tif, uint16 s) -{ - JPEGState *sp = JState(tif); - TIFFDirectory *td = &tif->tif_dir; - static const char module[] = "JPEGPreDecode"; - uint32 segment_width, segment_height; - int downsampled_output; - int ci; - - assert(sp != NULL); - - if (sp->cinfo.comm.is_decompressor == 0) - { - tif->tif_setupdecode( tif ); - } - - assert(sp->cinfo.comm.is_decompressor); - /* - * Reset decoder state from any previous strip/tile, - * in case application didn't read the whole strip. - */ - if (!TIFFjpeg_abort(sp)) - return (0); - /* - * Read the header for this strip/tile. - */ - - if (TIFFjpeg_read_header(sp, TRUE) != JPEG_HEADER_OK) - return (0); - - tif->tif_rawcp = (uint8*) sp->src.next_input_byte; - tif->tif_rawcc = sp->src.bytes_in_buffer; - - /* - * Check image parameters and set decompression parameters. - */ - segment_width = td->td_imagewidth; - segment_height = td->td_imagelength - tif->tif_row; - if (isTiled(tif)) { - segment_width = td->td_tilewidth; - segment_height = td->td_tilelength; - sp->bytesperline = TIFFTileRowSize(tif); - } else { - if (segment_height > td->td_rowsperstrip) - segment_height = td->td_rowsperstrip; - sp->bytesperline = TIFFScanlineSize(tif); - } - if (td->td_planarconfig == PLANARCONFIG_SEPARATE && s > 0) { - /* - * For PC 2, scale down the expected strip/tile size - * to match a downsampled component - */ - segment_width = TIFFhowmany_32(segment_width, sp->h_sampling); - segment_height = TIFFhowmany_32(segment_height, sp->v_sampling); - } - if (sp->cinfo.d.image_width < segment_width || - sp->cinfo.d.image_height < segment_height) { - TIFFWarningExt(tif->tif_clientdata, module, - "Improper JPEG strip/tile size, " - "expected %dx%d, got %dx%d", - segment_width, segment_height, - sp->cinfo.d.image_width, - sp->cinfo.d.image_height); - } - if (sp->cinfo.d.image_width > segment_width || - sp->cinfo.d.image_height > segment_height) { - /* - * This case could be dangerous, if the strip or tile size has - * been reported as less than the amount of data jpeg will - * return, some potential security issues arise. Catch this - * case and error out. - */ - TIFFErrorExt(tif->tif_clientdata, module, - "JPEG strip/tile size exceeds expected dimensions," - " expected %dx%d, got %dx%d", - segment_width, segment_height, - sp->cinfo.d.image_width, sp->cinfo.d.image_height); - return (0); - } - if (sp->cinfo.d.num_components != - (td->td_planarconfig == PLANARCONFIG_CONTIG ? - td->td_samplesperpixel : 1)) { - TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG component count"); - return (0); - } -#ifdef JPEG_LIB_MK1 - if (12 != td->td_bitspersample && 8 != td->td_bitspersample) { - TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG data precision"); - return (0); - } - sp->cinfo.d.data_precision = td->td_bitspersample; - sp->cinfo.d.bits_in_jsample = td->td_bitspersample; -#else - if (sp->cinfo.d.data_precision != td->td_bitspersample) { - TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG data precision"); - return (0); - } -#endif - if (td->td_planarconfig == PLANARCONFIG_CONTIG) { - /* Component 0 should have expected sampling factors */ - if (sp->cinfo.d.comp_info[0].h_samp_factor != sp->h_sampling || - sp->cinfo.d.comp_info[0].v_samp_factor != sp->v_sampling) { - TIFFErrorExt(tif->tif_clientdata, module, - "Improper JPEG sampling factors %d,%d\n" - "Apparently should be %d,%d.", - sp->cinfo.d.comp_info[0].h_samp_factor, - sp->cinfo.d.comp_info[0].v_samp_factor, - sp->h_sampling, sp->v_sampling); - return (0); - } - /* Rest should have sampling factors 1,1 */ - for (ci = 1; ci < sp->cinfo.d.num_components; ci++) { - if (sp->cinfo.d.comp_info[ci].h_samp_factor != 1 || - sp->cinfo.d.comp_info[ci].v_samp_factor != 1) { - TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG sampling factors"); - return (0); - } - } - } else { - /* PC 2's single component should have sampling factors 1,1 */ - if (sp->cinfo.d.comp_info[0].h_samp_factor != 1 || - sp->cinfo.d.comp_info[0].v_samp_factor != 1) { - TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG sampling factors"); - return (0); - } - } - downsampled_output = FALSE; - if (td->td_planarconfig == PLANARCONFIG_CONTIG && - sp->photometric == PHOTOMETRIC_YCBCR && - sp->jpegcolormode == JPEGCOLORMODE_RGB) { - /* Convert YCbCr to RGB */ - sp->cinfo.d.jpeg_color_space = JCS_YCbCr; - sp->cinfo.d.out_color_space = JCS_RGB; - } else { - /* Suppress colorspace handling */ - sp->cinfo.d.jpeg_color_space = JCS_UNKNOWN; - sp->cinfo.d.out_color_space = JCS_UNKNOWN; - if (td->td_planarconfig == PLANARCONFIG_CONTIG && - (sp->h_sampling != 1 || sp->v_sampling != 1)) - downsampled_output = TRUE; - /* XXX what about up-sampling? */ - } - if (downsampled_output) { - /* Need to use raw-data interface to libjpeg */ - sp->cinfo.d.raw_data_out = TRUE; -#if JPEG_LIB_VERSION >= 70 - sp->cinfo.d.do_fancy_upsampling = FALSE; -#endif /* JPEG_LIB_VERSION >= 70 */ - tif->tif_decoderow = DecodeRowError; - tif->tif_decodestrip = JPEGDecodeRaw; - tif->tif_decodetile = JPEGDecodeRaw; - } else { - /* Use normal interface to libjpeg */ - sp->cinfo.d.raw_data_out = FALSE; - tif->tif_decoderow = JPEGDecode; - tif->tif_decodestrip = JPEGDecode; - tif->tif_decodetile = JPEGDecode; - } - /* Start JPEG decompressor */ - if (!TIFFjpeg_start_decompress(sp)) - return (0); - /* Allocate downsampled-data buffers if needed */ - if (downsampled_output) { - if (!alloc_downsampled_buffers(tif, sp->cinfo.d.comp_info, - sp->cinfo.d.num_components)) - return (0); - sp->scancount = DCTSIZE; /* mark buffer empty */ - } - return (1); -} - -/* - * Decode a chunk of pixels. - * "Standard" case: returned data is not downsampled. - */ -/*ARGSUSED*/ static int -JPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) -{ - JPEGState *sp = JState(tif); - tmsize_t nrows; - (void) s; - - /* - ** Update available information, buffer may have been refilled - ** between decode requests - */ - sp->src.next_input_byte = (const JOCTET*) tif->tif_rawcp; - sp->src.bytes_in_buffer = (size_t) tif->tif_rawcc; - - if( sp->bytesperline == 0 ) - return 0; - - nrows = cc / sp->bytesperline; - if (cc % sp->bytesperline) - TIFFWarningExt(tif->tif_clientdata, tif->tif_name, "fractional scanline not read"); - - if( nrows > (tmsize_t) sp->cinfo.d.image_height ) - nrows = sp->cinfo.d.image_height; - - /* data is expected to be read in multiples of a scanline */ - if (nrows) - { - JSAMPROW line_work_buf = NULL; - - /* - * For 6B, only use temporary buffer for 12 bit imagery. - * For Mk1 always use it. - */ -#if !defined(JPEG_LIB_MK1) - if( sp->cinfo.d.data_precision == 12 ) -#endif - { - line_work_buf = (JSAMPROW) - _TIFFmalloc(sizeof(short) * sp->cinfo.d.output_width - * sp->cinfo.d.num_components ); - } - - do { - if( line_work_buf != NULL ) - { - /* - * In the MK1 case, we aways read into a 16bit buffer, and then - * pack down to 12bit or 8bit. In 6B case we only read into 16 - * bit buffer for 12bit data, which we need to repack. - */ - if (TIFFjpeg_read_scanlines(sp, &line_work_buf, 1) != 1) - return (0); - - if( sp->cinfo.d.data_precision == 12 ) - { - int value_pairs = (sp->cinfo.d.output_width - * sp->cinfo.d.num_components) / 2; - int iPair; - - for( iPair = 0; iPair < value_pairs; iPair++ ) - { - unsigned char *out_ptr = - ((unsigned char *) buf) + iPair * 3; - JSAMPLE *in_ptr = line_work_buf + iPair * 2; - - out_ptr[0] = (in_ptr[0] & 0xff0) >> 4; - out_ptr[1] = ((in_ptr[0] & 0xf) << 4) - | ((in_ptr[1] & 0xf00) >> 8); - out_ptr[2] = ((in_ptr[1] & 0xff) >> 0); - } - } - else if( sp->cinfo.d.data_precision == 8 ) - { - int value_count = (sp->cinfo.d.output_width - * sp->cinfo.d.num_components); - int iValue; - - for( iValue = 0; iValue < value_count; iValue++ ) - { - ((unsigned char *) buf)[iValue] = - line_work_buf[iValue] & 0xff; - } - } - } - else - { - /* - * In the libjpeg6b 8bit case. We read directly into the - * TIFF buffer. - */ - JSAMPROW bufptr = (JSAMPROW)buf; - - if (TIFFjpeg_read_scanlines(sp, &bufptr, 1) != 1) - return (0); - } - - ++tif->tif_row; - buf += sp->bytesperline; - cc -= sp->bytesperline; - } while (--nrows > 0); - - if( line_work_buf != NULL ) - _TIFFfree( line_work_buf ); - } - - /* Update information on consumed data */ - tif->tif_rawcp = (uint8*) sp->src.next_input_byte; - tif->tif_rawcc = sp->src.bytes_in_buffer; - - /* Close down the decompressor if we've finished the strip or tile. */ - return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height - || TIFFjpeg_finish_decompress(sp); -} - -/*ARGSUSED*/ static int -DecodeRowError(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) - -{ - (void) buf; - (void) cc; - (void) s; - - TIFFErrorExt(tif->tif_clientdata, "TIFFReadScanline", - "scanline oriented access is not supported for downsampled JPEG compressed images, consider enabling TIFF_JPEGCOLORMODE as JPEGCOLORMODE_RGB." ); - return 0; -} - -/* - * Decode a chunk of pixels. - * Returned data is downsampled per sampling factors. - */ -/*ARGSUSED*/ static int -JPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) -{ - JPEGState *sp = JState(tif); - tmsize_t nrows; - (void) s; - - /* data is expected to be read in multiples of a scanline */ - if ( (nrows = sp->cinfo.d.image_height) ) { - - /* Cb,Cr both have sampling factors 1, so this is correct */ - JDIMENSION clumps_per_line = sp->cinfo.d.comp_info[1].downsampled_width; - int samples_per_clump = sp->samplesperclump; - -#if defined(JPEG_LIB_MK1_OR_12BIT) - unsigned short* tmpbuf = _TIFFmalloc(sizeof(unsigned short) * - sp->cinfo.d.output_width * - sp->cinfo.d.num_components); - if(tmpbuf==NULL) { - TIFFErrorExt(tif->tif_clientdata, "JPEGDecodeRaw", - "Out of memory"); - return 0; - } -#endif - - do { - jpeg_component_info *compptr; - int ci, clumpoffset; - - if( cc < sp->bytesperline ) { - TIFFErrorExt(tif->tif_clientdata, "JPEGDecodeRaw", - "application buffer not large enough for all data."); - return 0; - } - - /* Reload downsampled-data buffer if needed */ - if (sp->scancount >= DCTSIZE) { - int n = sp->cinfo.d.max_v_samp_factor * DCTSIZE; - if (TIFFjpeg_read_raw_data(sp, sp->ds_buffer, n) != n) - return (0); - sp->scancount = 0; - } - /* - * Fastest way to unseparate data is to make one pass - * over the scanline for each row of each component. - */ - clumpoffset = 0; /* first sample in clump */ - for (ci = 0, compptr = sp->cinfo.d.comp_info; - ci < sp->cinfo.d.num_components; - ci++, compptr++) { - int hsamp = compptr->h_samp_factor; - int vsamp = compptr->v_samp_factor; - int ypos; - - for (ypos = 0; ypos < vsamp; ypos++) { - JSAMPLE *inptr = sp->ds_buffer[ci][sp->scancount*vsamp + ypos]; - JDIMENSION nclump; -#if defined(JPEG_LIB_MK1_OR_12BIT) - JSAMPLE *outptr = (JSAMPLE*)tmpbuf + clumpoffset; -#else - JSAMPLE *outptr = (JSAMPLE*)buf + clumpoffset; - if (cc < (tmsize_t) (clumpoffset + samples_per_clump*(clumps_per_line-1) + hsamp)) { - TIFFErrorExt(tif->tif_clientdata, "JPEGDecodeRaw", - "application buffer not large enough for all data, possible subsampling issue"); - return 0; - } -#endif - - if (hsamp == 1) { - /* fast path for at least Cb and Cr */ - for (nclump = clumps_per_line; nclump-- > 0; ) { - outptr[0] = *inptr++; - outptr += samples_per_clump; - } - } else { - int xpos; - - /* general case */ - for (nclump = clumps_per_line; nclump-- > 0; ) { - for (xpos = 0; xpos < hsamp; xpos++) - outptr[xpos] = *inptr++; - outptr += samples_per_clump; - } - } - clumpoffset += hsamp; - } - } - -#if defined(JPEG_LIB_MK1_OR_12BIT) - { - if (sp->cinfo.d.data_precision == 8) - { - int i=0; - int len = sp->cinfo.d.output_width * sp->cinfo.d.num_components; - for (i=0; icinfo.d.output_width - * sp->cinfo.d.num_components) / 2; - int iPair; - for( iPair = 0; iPair < value_pairs; iPair++ ) - { - unsigned char *out_ptr = ((unsigned char *) buf) + iPair * 3; - JSAMPLE *in_ptr = (JSAMPLE *) (tmpbuf + iPair * 2); - out_ptr[0] = (in_ptr[0] & 0xff0) >> 4; - out_ptr[1] = ((in_ptr[0] & 0xf) << 4) - | ((in_ptr[1] & 0xf00) >> 8); - out_ptr[2] = ((in_ptr[1] & 0xff) >> 0); - } - } - } -#endif - - sp->scancount ++; - tif->tif_row += sp->v_sampling; - - buf += sp->bytesperline; - cc -= sp->bytesperline; - - nrows -= sp->v_sampling; - } while (nrows > 0); - -#if defined(JPEG_LIB_MK1_OR_12BIT) - _TIFFfree(tmpbuf); -#endif - - } - - /* Close down the decompressor if done. */ - return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height - || TIFFjpeg_finish_decompress(sp); -} - - -/* - * JPEG Encoding. - */ - -static void -unsuppress_quant_table (JPEGState* sp, int tblno) -{ - JQUANT_TBL* qtbl; - - if ((qtbl = sp->cinfo.c.quant_tbl_ptrs[tblno]) != NULL) - qtbl->sent_table = FALSE; -} - -static void -unsuppress_huff_table (JPEGState* sp, int tblno) -{ - JHUFF_TBL* htbl; - - if ((htbl = sp->cinfo.c.dc_huff_tbl_ptrs[tblno]) != NULL) - htbl->sent_table = FALSE; - if ((htbl = sp->cinfo.c.ac_huff_tbl_ptrs[tblno]) != NULL) - htbl->sent_table = FALSE; -} - -static int -prepare_JPEGTables(TIFF* tif) -{ - JPEGState* sp = JState(tif); - - /* Initialize quant tables for current quality setting */ - if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE)) - return (0); - /* Mark only the tables we want for output */ - /* NB: chrominance tables are currently used only with YCbCr */ - if (!TIFFjpeg_suppress_tables(sp, TRUE)) - return (0); - if (sp->jpegtablesmode & JPEGTABLESMODE_QUANT) { - unsuppress_quant_table(sp, 0); - if (sp->photometric == PHOTOMETRIC_YCBCR) - unsuppress_quant_table(sp, 1); - } - if (sp->jpegtablesmode & JPEGTABLESMODE_HUFF) { - unsuppress_huff_table(sp, 0); - if (sp->photometric == PHOTOMETRIC_YCBCR) - unsuppress_huff_table(sp, 1); - } - /* Direct libjpeg output into jpegtables */ - if (!TIFFjpeg_tables_dest(sp, tif)) - return (0); - /* Emit tables-only datastream */ - if (!TIFFjpeg_write_tables(sp)) - return (0); - - return (1); -} - -static int -JPEGSetupEncode(TIFF* tif) -{ - JPEGState* sp = JState(tif); - TIFFDirectory *td = &tif->tif_dir; - static const char module[] = "JPEGSetupEncode"; - -#if defined(JPEG_DUAL_MODE_8_12) && !defined(TIFFInitJPEG) - if( tif->tif_dir.td_bitspersample == 12 ) - return TIFFReInitJPEG_12( tif, COMPRESSION_JPEG, 1 ); -#endif - - JPEGInitializeLibJPEG( tif, FALSE ); - - assert(sp != NULL); - assert(!sp->cinfo.comm.is_decompressor); - - /* - * Initialize all JPEG parameters to default values. - * Note that jpeg_set_defaults needs legal values for - * in_color_space and input_components. - */ - sp->cinfo.c.in_color_space = JCS_UNKNOWN; - sp->cinfo.c.input_components = 1; - if (!TIFFjpeg_set_defaults(sp)) - return (0); - /* Set per-file parameters */ - sp->photometric = td->td_photometric; - switch (sp->photometric) { - case PHOTOMETRIC_YCBCR: - sp->h_sampling = td->td_ycbcrsubsampling[0]; - sp->v_sampling = td->td_ycbcrsubsampling[1]; - /* - * A ReferenceBlackWhite field *must* be present since the - * default value is inappropriate for YCbCr. Fill in the - * proper value if application didn't set it. - */ - { - float *ref; - if (!TIFFGetField(tif, TIFFTAG_REFERENCEBLACKWHITE, - &ref)) { - float refbw[6]; - long top = 1L << td->td_bitspersample; - refbw[0] = 0; - refbw[1] = (float)(top-1L); - refbw[2] = (float)(top>>1); - refbw[3] = refbw[1]; - refbw[4] = refbw[2]; - refbw[5] = refbw[1]; - TIFFSetField(tif, TIFFTAG_REFERENCEBLACKWHITE, - refbw); - } - } - break; - case PHOTOMETRIC_PALETTE: /* disallowed by Tech Note */ - case PHOTOMETRIC_MASK: - TIFFErrorExt(tif->tif_clientdata, module, - "PhotometricInterpretation %d not allowed for JPEG", - (int) sp->photometric); - return (0); - default: - /* TIFF 6.0 forbids subsampling of all other color spaces */ - sp->h_sampling = 1; - sp->v_sampling = 1; - break; - } - - /* Verify miscellaneous parameters */ - - /* - * This would need work if libtiff ever supports different - * depths for different components, or if libjpeg ever supports - * run-time selection of depth. Neither is imminent. - */ -#ifdef JPEG_LIB_MK1 - /* BITS_IN_JSAMPLE now permits 8 and 12 --- dgilbert */ - if (td->td_bitspersample != 8 && td->td_bitspersample != 12) -#else - if (td->td_bitspersample != BITS_IN_JSAMPLE ) -#endif - { - TIFFErrorExt(tif->tif_clientdata, module, "BitsPerSample %d not allowed for JPEG", - (int) td->td_bitspersample); - return (0); - } - sp->cinfo.c.data_precision = td->td_bitspersample; -#ifdef JPEG_LIB_MK1 - sp->cinfo.c.bits_in_jsample = td->td_bitspersample; -#endif - if (isTiled(tif)) { - if ((td->td_tilelength % (sp->v_sampling * DCTSIZE)) != 0) { - TIFFErrorExt(tif->tif_clientdata, module, - "JPEG tile height must be multiple of %d", - sp->v_sampling * DCTSIZE); - return (0); - } - if ((td->td_tilewidth % (sp->h_sampling * DCTSIZE)) != 0) { - TIFFErrorExt(tif->tif_clientdata, module, - "JPEG tile width must be multiple of %d", - sp->h_sampling * DCTSIZE); - return (0); - } - } else { - if (td->td_rowsperstrip < td->td_imagelength && - (td->td_rowsperstrip % (sp->v_sampling * DCTSIZE)) != 0) { - TIFFErrorExt(tif->tif_clientdata, module, - "RowsPerStrip must be multiple of %d for JPEG", - sp->v_sampling * DCTSIZE); - return (0); - } - } - - /* Create a JPEGTables field if appropriate */ - if (sp->jpegtablesmode & (JPEGTABLESMODE_QUANT|JPEGTABLESMODE_HUFF)) { - if( sp->jpegtables == NULL - || memcmp(sp->jpegtables,"\0\0\0\0\0\0\0\0\0",8) == 0 ) - { - if (!prepare_JPEGTables(tif)) - return (0); - /* Mark the field present */ - /* Can't use TIFFSetField since BEENWRITING is already set! */ - tif->tif_flags |= TIFF_DIRTYDIRECT; - TIFFSetFieldBit(tif, FIELD_JPEGTABLES); - } - } else { - /* We do not support application-supplied JPEGTables, */ - /* so mark the field not present */ - TIFFClrFieldBit(tif, FIELD_JPEGTABLES); - } - - /* Direct libjpeg output to libtiff's output buffer */ - TIFFjpeg_data_dest(sp, tif); - - return (1); -} - -/* - * Set encoding state at the start of a strip or tile. - */ -static int -JPEGPreEncode(TIFF* tif, uint16 s) -{ - JPEGState *sp = JState(tif); - TIFFDirectory *td = &tif->tif_dir; - static const char module[] = "JPEGPreEncode"; - uint32 segment_width, segment_height; - int downsampled_input; - - assert(sp != NULL); - - if (sp->cinfo.comm.is_decompressor == 1) - { - tif->tif_setupencode( tif ); - } - - assert(!sp->cinfo.comm.is_decompressor); - /* - * Set encoding parameters for this strip/tile. - */ - if (isTiled(tif)) { - segment_width = td->td_tilewidth; - segment_height = td->td_tilelength; - sp->bytesperline = TIFFTileRowSize(tif); - } else { - segment_width = td->td_imagewidth; - segment_height = td->td_imagelength - tif->tif_row; - if (segment_height > td->td_rowsperstrip) - segment_height = td->td_rowsperstrip; - sp->bytesperline = TIFFScanlineSize(tif); - } - if (td->td_planarconfig == PLANARCONFIG_SEPARATE && s > 0) { - /* for PC 2, scale down the strip/tile size - * to match a downsampled component - */ - segment_width = TIFFhowmany_32(segment_width, sp->h_sampling); - segment_height = TIFFhowmany_32(segment_height, sp->v_sampling); - } - if (segment_width > 65535 || segment_height > 65535) { - TIFFErrorExt(tif->tif_clientdata, module, "Strip/tile too large for JPEG"); - return (0); - } - sp->cinfo.c.image_width = segment_width; - sp->cinfo.c.image_height = segment_height; - downsampled_input = FALSE; - if (td->td_planarconfig == PLANARCONFIG_CONTIG) { - sp->cinfo.c.input_components = td->td_samplesperpixel; - if (sp->photometric == PHOTOMETRIC_YCBCR) { - if (sp->jpegcolormode == JPEGCOLORMODE_RGB) { - sp->cinfo.c.in_color_space = JCS_RGB; - } else { - sp->cinfo.c.in_color_space = JCS_YCbCr; - if (sp->h_sampling != 1 || sp->v_sampling != 1) - downsampled_input = TRUE; - } - if (!TIFFjpeg_set_colorspace(sp, JCS_YCbCr)) - return (0); - /* - * Set Y sampling factors; - * we assume jpeg_set_colorspace() set the rest to 1 - */ - sp->cinfo.c.comp_info[0].h_samp_factor = sp->h_sampling; - sp->cinfo.c.comp_info[0].v_samp_factor = sp->v_sampling; - } else { - if ((td->td_photometric == PHOTOMETRIC_MINISWHITE || td->td_photometric == PHOTOMETRIC_MINISBLACK) && td->td_samplesperpixel == 1) - sp->cinfo.c.in_color_space = JCS_GRAYSCALE; - else if (td->td_photometric == PHOTOMETRIC_RGB && td->td_samplesperpixel == 3) - sp->cinfo.c.in_color_space = JCS_RGB; - else if (td->td_photometric == PHOTOMETRIC_SEPARATED && td->td_samplesperpixel == 4) - sp->cinfo.c.in_color_space = JCS_CMYK; - else - sp->cinfo.c.in_color_space = JCS_UNKNOWN; - if (!TIFFjpeg_set_colorspace(sp, sp->cinfo.c.in_color_space)) - return (0); - /* jpeg_set_colorspace set all sampling factors to 1 */ - } - } else { - sp->cinfo.c.input_components = 1; - sp->cinfo.c.in_color_space = JCS_UNKNOWN; - if (!TIFFjpeg_set_colorspace(sp, JCS_UNKNOWN)) - return (0); - sp->cinfo.c.comp_info[0].component_id = s; - /* jpeg_set_colorspace() set sampling factors to 1 */ - if (sp->photometric == PHOTOMETRIC_YCBCR && s > 0) { - sp->cinfo.c.comp_info[0].quant_tbl_no = 1; - sp->cinfo.c.comp_info[0].dc_tbl_no = 1; - sp->cinfo.c.comp_info[0].ac_tbl_no = 1; - } - } - /* ensure libjpeg won't write any extraneous markers */ - sp->cinfo.c.write_JFIF_header = FALSE; - sp->cinfo.c.write_Adobe_marker = FALSE; - /* set up table handling correctly */ - if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE)) - return (0); - if (! (sp->jpegtablesmode & JPEGTABLESMODE_QUANT)) { - unsuppress_quant_table(sp, 0); - unsuppress_quant_table(sp, 1); - } - if (sp->jpegtablesmode & JPEGTABLESMODE_HUFF) - sp->cinfo.c.optimize_coding = FALSE; - else - sp->cinfo.c.optimize_coding = TRUE; - if (downsampled_input) { - /* Need to use raw-data interface to libjpeg */ - sp->cinfo.c.raw_data_in = TRUE; - tif->tif_encoderow = JPEGEncodeRaw; - tif->tif_encodestrip = JPEGEncodeRaw; - tif->tif_encodetile = JPEGEncodeRaw; - } else { - /* Use normal interface to libjpeg */ - sp->cinfo.c.raw_data_in = FALSE; - tif->tif_encoderow = JPEGEncode; - tif->tif_encodestrip = JPEGEncode; - tif->tif_encodetile = JPEGEncode; - } - /* Start JPEG compressor */ - if (!TIFFjpeg_start_compress(sp, FALSE)) - return (0); - /* Allocate downsampled-data buffers if needed */ - if (downsampled_input) { - if (!alloc_downsampled_buffers(tif, sp->cinfo.c.comp_info, - sp->cinfo.c.num_components)) - return (0); - } - sp->scancount = 0; - - return (1); -} - -/* - * Encode a chunk of pixels. - * "Standard" case: incoming data is not downsampled. - */ -static int -JPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) -{ - JPEGState *sp = JState(tif); - tmsize_t nrows; - JSAMPROW bufptr[1]; - short *line16 = NULL; - int line16_count = 0; - - (void) s; - assert(sp != NULL); - /* data is expected to be supplied in multiples of a scanline */ - nrows = cc / sp->bytesperline; - if (cc % sp->bytesperline) - TIFFWarningExt(tif->tif_clientdata, tif->tif_name, - "fractional scanline discarded"); - - /* The last strip will be limited to image size */ - if( !isTiled(tif) && tif->tif_row+nrows > tif->tif_dir.td_imagelength ) - nrows = tif->tif_dir.td_imagelength - tif->tif_row; - - if( sp->cinfo.c.data_precision == 12 ) - { - line16_count = (sp->bytesperline * 2) / 3; - line16 = (short *) _TIFFmalloc(sizeof(short) * line16_count); - // FIXME: undiagnosed malloc failure - } - - while (nrows-- > 0) { - - if( sp->cinfo.c.data_precision == 12 ) - { - - int value_pairs = line16_count / 2; - int iPair; - - bufptr[0] = (JSAMPROW) line16; - - for( iPair = 0; iPair < value_pairs; iPair++ ) - { - unsigned char *in_ptr = - ((unsigned char *) buf) + iPair * 3; - JSAMPLE *out_ptr = (JSAMPLE *) (line16 + iPair * 2); - - out_ptr[0] = (in_ptr[0] << 4) | ((in_ptr[1] & 0xf0) >> 4); - out_ptr[1] = ((in_ptr[1] & 0x0f) << 8) | in_ptr[2]; - } - } - else - { - bufptr[0] = (JSAMPROW) buf; - } - if (TIFFjpeg_write_scanlines(sp, bufptr, 1) != 1) - return (0); - if (nrows > 0) - tif->tif_row++; - buf += sp->bytesperline; - } - - if( sp->cinfo.c.data_precision == 12 ) - { - _TIFFfree( line16 ); - } - - return (1); -} - -/* - * Encode a chunk of pixels. - * Incoming data is expected to be downsampled per sampling factors. - */ -static int -JPEGEncodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) -{ - JPEGState *sp = JState(tif); - JSAMPLE* inptr; - JSAMPLE* outptr; - tmsize_t nrows; - JDIMENSION clumps_per_line, nclump; - int clumpoffset, ci, xpos, ypos; - jpeg_component_info* compptr; - int samples_per_clump = sp->samplesperclump; - tmsize_t bytesperclumpline; - - (void) s; - assert(sp != NULL); - /* data is expected to be supplied in multiples of a clumpline */ - /* a clumpline is equivalent to v_sampling desubsampled scanlines */ - /* TODO: the following calculation of bytesperclumpline, should substitute calculation of sp->bytesperline, except that it is per v_sampling lines */ - bytesperclumpline = (((sp->cinfo.c.image_width+sp->h_sampling-1)/sp->h_sampling) - *(sp->h_sampling*sp->v_sampling+2)*sp->cinfo.c.data_precision+7) - /8; - - nrows = ( cc / bytesperclumpline ) * sp->v_sampling; - if (cc % bytesperclumpline) - TIFFWarningExt(tif->tif_clientdata, tif->tif_name, "fractional scanline discarded"); - - /* Cb,Cr both have sampling factors 1, so this is correct */ - clumps_per_line = sp->cinfo.c.comp_info[1].downsampled_width; - - while (nrows > 0) { - /* - * Fastest way to separate the data is to make one pass - * over the scanline for each row of each component. - */ - clumpoffset = 0; /* first sample in clump */ - for (ci = 0, compptr = sp->cinfo.c.comp_info; - ci < sp->cinfo.c.num_components; - ci++, compptr++) { - int hsamp = compptr->h_samp_factor; - int vsamp = compptr->v_samp_factor; - int padding = (int) (compptr->width_in_blocks * DCTSIZE - - clumps_per_line * hsamp); - for (ypos = 0; ypos < vsamp; ypos++) { - inptr = ((JSAMPLE*) buf) + clumpoffset; - outptr = sp->ds_buffer[ci][sp->scancount*vsamp + ypos]; - if (hsamp == 1) { - /* fast path for at least Cb and Cr */ - for (nclump = clumps_per_line; nclump-- > 0; ) { - *outptr++ = inptr[0]; - inptr += samples_per_clump; - } - } else { - /* general case */ - for (nclump = clumps_per_line; nclump-- > 0; ) { - for (xpos = 0; xpos < hsamp; xpos++) - *outptr++ = inptr[xpos]; - inptr += samples_per_clump; - } - } - /* pad each scanline as needed */ - for (xpos = 0; xpos < padding; xpos++) { - *outptr = outptr[-1]; - outptr++; - } - clumpoffset += hsamp; - } - } - sp->scancount++; - if (sp->scancount >= DCTSIZE) { - int n = sp->cinfo.c.max_v_samp_factor * DCTSIZE; - if (TIFFjpeg_write_raw_data(sp, sp->ds_buffer, n) != n) - return (0); - sp->scancount = 0; - } - tif->tif_row += sp->v_sampling; - buf += bytesperclumpline; - nrows -= sp->v_sampling; - } - return (1); -} - -/* - * Finish up at the end of a strip or tile. - */ -static int -JPEGPostEncode(TIFF* tif) -{ - JPEGState *sp = JState(tif); - - if (sp->scancount > 0) { - /* - * Need to emit a partial bufferload of downsampled data. - * Pad the data vertically. - */ - int ci, ypos, n; - jpeg_component_info* compptr; - - for (ci = 0, compptr = sp->cinfo.c.comp_info; - ci < sp->cinfo.c.num_components; - ci++, compptr++) { - int vsamp = compptr->v_samp_factor; - tmsize_t row_width = compptr->width_in_blocks * DCTSIZE - * sizeof(JSAMPLE); - for (ypos = sp->scancount * vsamp; - ypos < DCTSIZE * vsamp; ypos++) { - _TIFFmemcpy((void*)sp->ds_buffer[ci][ypos], - (void*)sp->ds_buffer[ci][ypos-1], - row_width); - - } - } - n = sp->cinfo.c.max_v_samp_factor * DCTSIZE; - if (TIFFjpeg_write_raw_data(sp, sp->ds_buffer, n) != n) - return (0); - } - - return (TIFFjpeg_finish_compress(JState(tif))); -} - -static void -JPEGCleanup(TIFF* tif) -{ - JPEGState *sp = JState(tif); - - assert(sp != 0); - - tif->tif_tagmethods.vgetfield = sp->vgetparent; - tif->tif_tagmethods.vsetfield = sp->vsetparent; - tif->tif_tagmethods.printdir = sp->printdir; - - if( sp != NULL ) { - if( sp->cinfo_initialized ) - TIFFjpeg_destroy(sp); /* release libjpeg resources */ - if (sp->jpegtables) /* tag value */ - _TIFFfree(sp->jpegtables); - } - _TIFFfree(tif->tif_data); /* release local state */ - tif->tif_data = NULL; - - _TIFFSetDefaultCompressionState(tif); -} - -static void -JPEGResetUpsampled( TIFF* tif ) -{ - JPEGState* sp = JState(tif); - TIFFDirectory* td = &tif->tif_dir; - - /* - * Mark whether returned data is up-sampled or not so TIFFStripSize - * and TIFFTileSize return values that reflect the true amount of - * data. - */ - tif->tif_flags &= ~TIFF_UPSAMPLED; - if (td->td_planarconfig == PLANARCONFIG_CONTIG) { - if (td->td_photometric == PHOTOMETRIC_YCBCR && - sp->jpegcolormode == JPEGCOLORMODE_RGB) { - tif->tif_flags |= TIFF_UPSAMPLED; - } else { -#ifdef notdef - if (td->td_ycbcrsubsampling[0] != 1 || - td->td_ycbcrsubsampling[1] != 1) - ; /* XXX what about up-sampling? */ -#endif - } - } - - /* - * Must recalculate cached tile size in case sampling state changed. - * Should we really be doing this now if image size isn't set? - */ - if( tif->tif_tilesize > 0 ) - tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tmsize_t)(-1); - if( tif->tif_scanlinesize > 0 ) - tif->tif_scanlinesize = TIFFScanlineSize(tif); -} - -static int -JPEGVSetField(TIFF* tif, uint32 tag, va_list ap) -{ - JPEGState* sp = JState(tif); - const TIFFField* fip; - uint32 v32; - - assert(sp != NULL); - - switch (tag) { - case TIFFTAG_JPEGTABLES: - v32 = (uint32) va_arg(ap, uint32); - if (v32 == 0) { - /* XXX */ - return (0); - } - _TIFFsetByteArray(&sp->jpegtables, va_arg(ap, void*), - (long) v32); - sp->jpegtables_length = v32; - TIFFSetFieldBit(tif, FIELD_JPEGTABLES); - break; - case TIFFTAG_JPEGQUALITY: - sp->jpegquality = (int) va_arg(ap, int); - return (1); /* pseudo tag */ - case TIFFTAG_JPEGCOLORMODE: - sp->jpegcolormode = (int) va_arg(ap, int); - JPEGResetUpsampled( tif ); - return (1); /* pseudo tag */ - case TIFFTAG_PHOTOMETRIC: - { - int ret_value = (*sp->vsetparent)(tif, tag, ap); - JPEGResetUpsampled( tif ); - return ret_value; - } - case TIFFTAG_JPEGTABLESMODE: - sp->jpegtablesmode = (int) va_arg(ap, int); - return (1); /* pseudo tag */ - case TIFFTAG_YCBCRSUBSAMPLING: - /* mark the fact that we have a real ycbcrsubsampling! */ - sp->ycbcrsampling_fetched = 1; - /* should we be recomputing upsampling info here? */ - return (*sp->vsetparent)(tif, tag, ap); - default: - return (*sp->vsetparent)(tif, tag, ap); - } - - if ((fip = TIFFFieldWithTag(tif, tag))) { - TIFFSetFieldBit(tif, fip->field_bit); - } else { - return (0); - } - - tif->tif_flags |= TIFF_DIRTYDIRECT; - return (1); -} - -static int -JPEGVGetField(TIFF* tif, uint32 tag, va_list ap) -{ - JPEGState* sp = JState(tif); - - assert(sp != NULL); - - switch (tag) { - case TIFFTAG_JPEGTABLES: - *va_arg(ap, uint32*) = sp->jpegtables_length; - *va_arg(ap, void**) = sp->jpegtables; - break; - case TIFFTAG_JPEGQUALITY: - *va_arg(ap, int*) = sp->jpegquality; - break; - case TIFFTAG_JPEGCOLORMODE: - *va_arg(ap, int*) = sp->jpegcolormode; - break; - case TIFFTAG_JPEGTABLESMODE: - *va_arg(ap, int*) = sp->jpegtablesmode; - break; - default: - return (*sp->vgetparent)(tif, tag, ap); - } - return (1); -} - -static void -JPEGPrintDir(TIFF* tif, FILE* fd, long flags) -{ - JPEGState* sp = JState(tif); - - assert(sp != NULL); - (void) flags; - - if( sp != NULL ) { - if (TIFFFieldSet(tif,FIELD_JPEGTABLES)) - fprintf(fd, " JPEG Tables: (%lu bytes)\n", - (unsigned long) sp->jpegtables_length); - if (sp->printdir) - (*sp->printdir)(tif, fd, flags); - } -} - -static uint32 -JPEGDefaultStripSize(TIFF* tif, uint32 s) -{ - JPEGState* sp = JState(tif); - TIFFDirectory *td = &tif->tif_dir; - - s = (*sp->defsparent)(tif, s); - if (s < td->td_imagelength) - s = TIFFroundup_32(s, td->td_ycbcrsubsampling[1] * DCTSIZE); - return (s); -} - -static void -JPEGDefaultTileSize(TIFF* tif, uint32* tw, uint32* th) -{ - JPEGState* sp = JState(tif); - TIFFDirectory *td = &tif->tif_dir; - - (*sp->deftparent)(tif, tw, th); - *tw = TIFFroundup_32(*tw, td->td_ycbcrsubsampling[0] * DCTSIZE); - *th = TIFFroundup_32(*th, td->td_ycbcrsubsampling[1] * DCTSIZE); -} - -/* - * The JPEG library initialized used to be done in TIFFInitJPEG(), but - * now that we allow a TIFF file to be opened in update mode it is necessary - * to have some way of deciding whether compression or decompression is - * desired other than looking at tif->tif_mode. We accomplish this by - * examining {TILE/STRIP}BYTECOUNTS to see if there is a non-zero entry. - * If so, we assume decompression is desired. - * - * This is tricky, because TIFFInitJPEG() is called while the directory is - * being read, and generally speaking the BYTECOUNTS tag won't have been read - * at that point. So we try to defer jpeg library initialization till we - * do have that tag ... basically any access that might require the compressor - * or decompressor that occurs after the reading of the directory. - * - * In an ideal world compressors or decompressors would be setup - * at the point where a single tile or strip was accessed (for read or write) - * so that stuff like update of missing tiles, or replacement of tiles could - * be done. However, we aren't trying to crack that nut just yet ... - * - * NFW, Feb 3rd, 2003. - */ - -static int JPEGInitializeLibJPEG( TIFF * tif, int decompress ) -{ - JPEGState* sp = JState(tif); - - if(sp->cinfo_initialized) - { - if( !decompress && sp->cinfo.comm.is_decompressor ) - TIFFjpeg_destroy( sp ); - else if( decompress && !sp->cinfo.comm.is_decompressor ) - TIFFjpeg_destroy( sp ); - else - return 1; - - sp->cinfo_initialized = 0; - } - - /* - * Initialize libjpeg. - */ - if ( decompress ) { - if (!TIFFjpeg_create_decompress(sp)) - return (0); - } else { - if (!TIFFjpeg_create_compress(sp)) - return (0); - } - - sp->cinfo_initialized = TRUE; - - return 1; -} - -int -TIFFInitJPEG(TIFF* tif, int scheme) -{ - JPEGState* sp; - - assert(scheme == COMPRESSION_JPEG); - - /* - * Merge codec-specific tag information. - */ - if (!_TIFFMergeFields(tif, jpegFields, TIFFArrayCount(jpegFields))) { - TIFFErrorExt(tif->tif_clientdata, - "TIFFInitJPEG", - "Merging JPEG codec-specific tags failed"); - return 0; - } - - /* - * Allocate state block so tag methods have storage to record values. - */ - tif->tif_data = (uint8*) _TIFFmalloc(sizeof (JPEGState)); - - if (tif->tif_data == NULL) { - TIFFErrorExt(tif->tif_clientdata, - "TIFFInitJPEG", "No space for JPEG state block"); - return 0; - } - _TIFFmemset(tif->tif_data, 0, sizeof(JPEGState)); - - sp = JState(tif); - sp->tif = tif; /* back link */ - - /* - * Override parent get/set field methods. - */ - sp->vgetparent = tif->tif_tagmethods.vgetfield; - tif->tif_tagmethods.vgetfield = JPEGVGetField; /* hook for codec tags */ - sp->vsetparent = tif->tif_tagmethods.vsetfield; - tif->tif_tagmethods.vsetfield = JPEGVSetField; /* hook for codec tags */ - sp->printdir = tif->tif_tagmethods.printdir; - tif->tif_tagmethods.printdir = JPEGPrintDir; /* hook for codec tags */ - - /* Default values for codec-specific fields */ - sp->jpegtables = NULL; - sp->jpegtables_length = 0; - sp->jpegquality = 75; /* Default IJG quality */ - sp->jpegcolormode = JPEGCOLORMODE_RAW; - sp->jpegtablesmode = JPEGTABLESMODE_QUANT | JPEGTABLESMODE_HUFF; - sp->ycbcrsampling_fetched = 0; - - /* - * Install codec methods. - */ - tif->tif_fixuptags = JPEGFixupTags; - tif->tif_setupdecode = JPEGSetupDecode; - tif->tif_predecode = JPEGPreDecode; - tif->tif_decoderow = JPEGDecode; - tif->tif_decodestrip = JPEGDecode; - tif->tif_decodetile = JPEGDecode; - tif->tif_setupencode = JPEGSetupEncode; - tif->tif_preencode = JPEGPreEncode; - tif->tif_postencode = JPEGPostEncode; - tif->tif_encoderow = JPEGEncode; - tif->tif_encodestrip = JPEGEncode; - tif->tif_encodetile = JPEGEncode; - tif->tif_cleanup = JPEGCleanup; - sp->defsparent = tif->tif_defstripsize; - tif->tif_defstripsize = JPEGDefaultStripSize; - sp->deftparent = tif->tif_deftilesize; - tif->tif_deftilesize = JPEGDefaultTileSize; - tif->tif_flags |= TIFF_NOBITREV; /* no bit reversal, please */ - - sp->cinfo_initialized = FALSE; - - /* - ** Create a JPEGTables field if no directory has yet been created. - ** We do this just to ensure that sufficient space is reserved for - ** the JPEGTables field. It will be properly created the right - ** size later. - */ - if( tif->tif_diroff == 0 ) - { -#define SIZE_OF_JPEGTABLES 2000 -/* -The following line assumes incorrectly that all JPEG-in-TIFF files will have -a JPEGTABLES tag generated and causes null-filled JPEGTABLES tags to be written -when the JPEG data is placed with TIFFWriteRawStrip. The field bit should be -set, anyway, later when actual JPEGTABLES header is generated, so removing it -here hopefully is harmless. - TIFFSetFieldBit(tif, FIELD_JPEGTABLES); -*/ - sp->jpegtables_length = SIZE_OF_JPEGTABLES; - sp->jpegtables = (void *) _TIFFmalloc(sp->jpegtables_length); - // FIXME: NULL-deref after malloc failure - _TIFFmemset(sp->jpegtables, 0, SIZE_OF_JPEGTABLES); -#undef SIZE_OF_JPEGTABLES - } - - return 1; -} -#endif /* JPEG_SUPPORT */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ - -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_jpeg.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1994-1997 Sam Leffler + * Copyright (c) 1994-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#define WIN32_LEAN_AND_MEAN +#define VC_EXTRALEAN + +#include "tiffiop.h" +#ifdef JPEG_SUPPORT + +/* + * TIFF Library + * + * JPEG Compression support per TIFF Technical Note #2 + * (*not* per the original TIFF 6.0 spec). + * + * This file is simply an interface to the libjpeg library written by + * the Independent JPEG Group. You need release 5 or later of the IJG + * code, which you can find on the Internet at ftp.uu.net:/graphics/jpeg/. + * + * Contributed by Tom Lane . + */ +#include + +int TIFFFillStrip(TIFF* tif, uint32 strip); +int TIFFFillTile(TIFF* tif, uint32 tile); +int TIFFReInitJPEG_12( TIFF *tif, int scheme, int is_encode ); + +/* We undefine FAR to avoid conflict with JPEG definition */ + +#ifdef FAR +#undef FAR +#endif + +/* + Libjpeg's jmorecfg.h defines INT16 and INT32, but only if XMD_H is + not defined. Unfortunately, the MinGW and Borland compilers include + a typedef for INT32, which causes a conflict. MSVC does not include + a conficting typedef given the headers which are included. +*/ +#if defined(__BORLANDC__) || defined(__MINGW32__) +# define XMD_H 1 +#endif + +/* + The windows RPCNDR.H file defines boolean, but defines it with the + unsigned char size. You should compile JPEG library using appropriate + definitions in jconfig.h header, but many users compile library in wrong + way. That causes errors of the following type: + + "JPEGLib: JPEG parameter struct mismatch: library thinks size is 432, + caller expects 464" + + For such users we wil fix the problem here. See install.doc file from + the JPEG library distribution for details. +*/ + +/* Define "boolean" as unsigned char, not int, per Windows custom. */ +#if defined(__WIN32__) && !defined(__MINGW32__) +# ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ + typedef unsigned char boolean; +# endif +# define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ +#endif + +#include "../LibJPEG/jpeglib.h" +#include "../LibJPEG/jerror.h" + +/* + * Do we want to do special processing suitable for when JSAMPLE is a + * 16bit value? + */ + +#if defined(JPEG_LIB_MK1) +# define JPEG_LIB_MK1_OR_12BIT 1 +#elif BITS_IN_JSAMPLE == 12 +# define JPEG_LIB_MK1_OR_12BIT 1 +#endif + +/* + * We are using width_in_blocks which is supposed to be private to + * libjpeg. Unfortunately, the libjpeg delivered with Cygwin has + * renamed this member to width_in_data_units. Since the header has + * also renamed a define, use that unique define name in order to + * detect the problem header and adjust to suit. + */ +#if defined(D_MAX_DATA_UNITS_IN_MCU) +#define width_in_blocks width_in_data_units +#endif + +/* + * On some machines it may be worthwhile to use _setjmp or sigsetjmp + * in place of plain setjmp. These macros will make it easier. + */ +#define SETJMP(jbuf) setjmp(jbuf) +#define LONGJMP(jbuf,code) longjmp(jbuf,code) +#define JMP_BUF jmp_buf + +typedef struct jpeg_destination_mgr jpeg_destination_mgr; +typedef struct jpeg_source_mgr jpeg_source_mgr; +typedef struct jpeg_error_mgr jpeg_error_mgr; + +/* + * State block for each open TIFF file using + * libjpeg to do JPEG compression/decompression. + * + * libjpeg's visible state is either a jpeg_compress_struct + * or jpeg_decompress_struct depending on which way we + * are going. comm can be used to refer to the fields + * which are common to both. + * + * NB: cinfo is required to be the first member of JPEGState, + * so we can safely cast JPEGState* -> jpeg_xxx_struct* + * and vice versa! + */ +typedef struct { + union { + struct jpeg_compress_struct c; + struct jpeg_decompress_struct d; + struct jpeg_common_struct comm; + } cinfo; /* NB: must be first */ + int cinfo_initialized; + + jpeg_error_mgr err; /* libjpeg error manager */ + JMP_BUF exit_jmpbuf; /* for catching libjpeg failures */ + /* + * The following two members could be a union, but + * they're small enough that it's not worth the effort. + */ + jpeg_destination_mgr dest; /* data dest for compression */ + jpeg_source_mgr src; /* data source for decompression */ + /* private state */ + TIFF* tif; /* back link needed by some code */ + uint16 photometric; /* copy of PhotometricInterpretation */ + uint16 h_sampling; /* luminance sampling factors */ + uint16 v_sampling; + tmsize_t bytesperline; /* decompressed bytes per scanline */ + /* pointers to intermediate buffers when processing downsampled data */ + JSAMPARRAY ds_buffer[MAX_COMPONENTS]; + int scancount; /* number of "scanlines" accumulated */ + int samplesperclump; + + TIFFVGetMethod vgetparent; /* super-class method */ + TIFFVSetMethod vsetparent; /* super-class method */ + TIFFPrintMethod printdir; /* super-class method */ + TIFFStripMethod defsparent; /* super-class method */ + TIFFTileMethod deftparent; /* super-class method */ + /* pseudo-tag fields */ + void* jpegtables; /* JPEGTables tag value, or NULL */ + uint32 jpegtables_length; /* number of bytes in same */ + int jpegquality; /* Compression quality level */ + int jpegcolormode; /* Auto RGB<=>YCbCr convert? */ + int jpegtablesmode; /* What to put in JPEGTables */ + + int ycbcrsampling_fetched; +} JPEGState; + +#define JState(tif) ((JPEGState*)(tif)->tif_data) + +static int JPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s); +static int JPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s); +static int JPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s); +static int JPEGEncodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s); +static int JPEGInitializeLibJPEG(TIFF * tif, int decode ); +static int DecodeRowError(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s); + +#define FIELD_JPEGTABLES (FIELD_CODEC+0) + +static const TIFFField jpegFields[] = { + { TIFFTAG_JPEGTABLES, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_C32_UINT8, FIELD_JPEGTABLES, FALSE, TRUE, "JPEGTables", NULL }, + { TIFFTAG_JPEGQUALITY, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "", NULL }, + { TIFFTAG_JPEGCOLORMODE, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "", NULL }, + { TIFFTAG_JPEGTABLESMODE, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "", NULL } +}; + +/* + * libjpeg interface layer. + * + * We use setjmp/longjmp to return control to libtiff + * when a fatal error is encountered within the JPEG + * library. We also direct libjpeg error and warning + * messages through the appropriate libtiff handlers. + */ + +/* + * Error handling routines (these replace corresponding + * IJG routines from jerror.c). These are used for both + * compression and decompression. + */ +static void +TIFFjpeg_error_exit(j_common_ptr cinfo) +{ + JPEGState *sp = (JPEGState *) cinfo; /* NB: cinfo assumed first */ + char buffer[JMSG_LENGTH_MAX]; + + (*cinfo->err->format_message) (cinfo, buffer); + TIFFErrorExt(sp->tif->tif_clientdata, "JPEGLib", "%s", buffer); /* display the error message */ + jpeg_abort(cinfo); /* clean up libjpeg state */ + LONGJMP(sp->exit_jmpbuf, 1); /* return to libtiff caller */ +} + +/* + * This routine is invoked only for warning messages, + * since error_exit does its own thing and trace_level + * is never set > 0. + */ +static void +TIFFjpeg_output_message(j_common_ptr cinfo) +{ + char buffer[JMSG_LENGTH_MAX]; + + (*cinfo->err->format_message) (cinfo, buffer); + TIFFWarningExt(((JPEGState *) cinfo)->tif->tif_clientdata, "JPEGLib", "%s", buffer); +} + +/* + * Interface routines. This layer of routines exists + * primarily to limit side-effects from using setjmp. + * Also, normal/error returns are converted into return + * values per libtiff practice. + */ +#define CALLJPEG(sp, fail, op) (SETJMP((sp)->exit_jmpbuf) ? (fail) : (op)) +#define CALLVJPEG(sp, op) CALLJPEG(sp, 0, ((op),1)) + +static int +TIFFjpeg_create_compress(JPEGState* sp) +{ + /* initialize JPEG error handling */ + sp->cinfo.c.err = jpeg_std_error(&sp->err); + sp->err.error_exit = TIFFjpeg_error_exit; + sp->err.output_message = TIFFjpeg_output_message; + + return CALLVJPEG(sp, jpeg_create_compress(&sp->cinfo.c)); +} + +static int +TIFFjpeg_create_decompress(JPEGState* sp) +{ + /* initialize JPEG error handling */ + sp->cinfo.d.err = jpeg_std_error(&sp->err); + sp->err.error_exit = TIFFjpeg_error_exit; + sp->err.output_message = TIFFjpeg_output_message; + + return CALLVJPEG(sp, jpeg_create_decompress(&sp->cinfo.d)); +} + +static int +TIFFjpeg_set_defaults(JPEGState* sp) +{ + return CALLVJPEG(sp, jpeg_set_defaults(&sp->cinfo.c)); +} + +static int +TIFFjpeg_set_colorspace(JPEGState* sp, J_COLOR_SPACE colorspace) +{ + return CALLVJPEG(sp, jpeg_set_colorspace(&sp->cinfo.c, colorspace)); +} + +static int +TIFFjpeg_set_quality(JPEGState* sp, int quality, boolean force_baseline) +{ + return CALLVJPEG(sp, + jpeg_set_quality(&sp->cinfo.c, quality, force_baseline)); +} + +static int +TIFFjpeg_suppress_tables(JPEGState* sp, boolean suppress) +{ + return CALLVJPEG(sp, jpeg_suppress_tables(&sp->cinfo.c, suppress)); +} + +static int +TIFFjpeg_start_compress(JPEGState* sp, boolean write_all_tables) +{ + return CALLVJPEG(sp, + jpeg_start_compress(&sp->cinfo.c, write_all_tables)); +} + +static int +TIFFjpeg_write_scanlines(JPEGState* sp, JSAMPARRAY scanlines, int num_lines) +{ + return CALLJPEG(sp, -1, (int) jpeg_write_scanlines(&sp->cinfo.c, + scanlines, (JDIMENSION) num_lines)); +} + +static int +TIFFjpeg_write_raw_data(JPEGState* sp, JSAMPIMAGE data, int num_lines) +{ + return CALLJPEG(sp, -1, (int) jpeg_write_raw_data(&sp->cinfo.c, + data, (JDIMENSION) num_lines)); +} + +static int +TIFFjpeg_finish_compress(JPEGState* sp) +{ + return CALLVJPEG(sp, jpeg_finish_compress(&sp->cinfo.c)); +} + +static int +TIFFjpeg_write_tables(JPEGState* sp) +{ + return CALLVJPEG(sp, jpeg_write_tables(&sp->cinfo.c)); +} + +static int +TIFFjpeg_read_header(JPEGState* sp, boolean require_image) +{ + return CALLJPEG(sp, -1, jpeg_read_header(&sp->cinfo.d, require_image)); +} + +static int +TIFFjpeg_start_decompress(JPEGState* sp) +{ + return CALLVJPEG(sp, jpeg_start_decompress(&sp->cinfo.d)); +} + +static int +TIFFjpeg_read_scanlines(JPEGState* sp, JSAMPARRAY scanlines, int max_lines) +{ + return CALLJPEG(sp, -1, (int) jpeg_read_scanlines(&sp->cinfo.d, + scanlines, (JDIMENSION) max_lines)); +} + +static int +TIFFjpeg_read_raw_data(JPEGState* sp, JSAMPIMAGE data, int max_lines) +{ + return CALLJPEG(sp, -1, (int) jpeg_read_raw_data(&sp->cinfo.d, + data, (JDIMENSION) max_lines)); +} + +static int +TIFFjpeg_finish_decompress(JPEGState* sp) +{ + return CALLJPEG(sp, -1, (int) jpeg_finish_decompress(&sp->cinfo.d)); +} + +static int +TIFFjpeg_abort(JPEGState* sp) +{ + return CALLVJPEG(sp, jpeg_abort(&sp->cinfo.comm)); +} + +static int +TIFFjpeg_destroy(JPEGState* sp) +{ + return CALLVJPEG(sp, jpeg_destroy(&sp->cinfo.comm)); +} + +static JSAMPARRAY +TIFFjpeg_alloc_sarray(JPEGState* sp, int pool_id, + JDIMENSION samplesperrow, JDIMENSION numrows) +{ + return CALLJPEG(sp, (JSAMPARRAY) NULL, + (*sp->cinfo.comm.mem->alloc_sarray) + (&sp->cinfo.comm, pool_id, samplesperrow, numrows)); +} + +/* + * JPEG library destination data manager. + * These routines direct compressed data from libjpeg into the + * libtiff output buffer. + */ + +static void +std_init_destination(j_compress_ptr cinfo) +{ + JPEGState* sp = (JPEGState*) cinfo; + TIFF* tif = sp->tif; + + sp->dest.next_output_byte = (JOCTET*) tif->tif_rawdata; + sp->dest.free_in_buffer = (size_t) tif->tif_rawdatasize; +} + +static boolean +std_empty_output_buffer(j_compress_ptr cinfo) +{ + JPEGState* sp = (JPEGState*) cinfo; + TIFF* tif = sp->tif; + + /* the entire buffer has been filled */ + tif->tif_rawcc = tif->tif_rawdatasize; + +#ifdef IPPJ_HUFF + /* + * The Intel IPP performance library does not necessarily fill up + * the whole output buffer on each pass, so only dump out the parts + * that have been filled. + * http://trac.osgeo.org/gdal/wiki/JpegIPP + */ + if ( sp->dest.free_in_buffer >= 0 ) { + tif->tif_rawcc = tif->tif_rawdatasize - sp->dest.free_in_buffer; + } +#endif + + TIFFFlushData1(tif); + sp->dest.next_output_byte = (JOCTET*) tif->tif_rawdata; + sp->dest.free_in_buffer = (size_t) tif->tif_rawdatasize; + + return (TRUE); +} + +static void +std_term_destination(j_compress_ptr cinfo) +{ + JPEGState* sp = (JPEGState*) cinfo; + TIFF* tif = sp->tif; + + tif->tif_rawcp = (uint8*) sp->dest.next_output_byte; + tif->tif_rawcc = + tif->tif_rawdatasize - (tmsize_t) sp->dest.free_in_buffer; + /* NB: libtiff does the final buffer flush */ +} + +static void +TIFFjpeg_data_dest(JPEGState* sp, TIFF* tif) +{ + (void) tif; + sp->cinfo.c.dest = &sp->dest; + sp->dest.init_destination = std_init_destination; + sp->dest.empty_output_buffer = std_empty_output_buffer; + sp->dest.term_destination = std_term_destination; +} + +/* + * Alternate destination manager for outputting to JPEGTables field. + */ + +static void +tables_init_destination(j_compress_ptr cinfo) +{ + JPEGState* sp = (JPEGState*) cinfo; + + /* while building, jpegtables_length is allocated buffer size */ + sp->dest.next_output_byte = (JOCTET*) sp->jpegtables; + sp->dest.free_in_buffer = (size_t) sp->jpegtables_length; +} + +static boolean +tables_empty_output_buffer(j_compress_ptr cinfo) +{ + JPEGState* sp = (JPEGState*) cinfo; + void* newbuf; + + /* the entire buffer has been filled; enlarge it by 1000 bytes */ + newbuf = _TIFFrealloc((void*) sp->jpegtables, + (tmsize_t) (sp->jpegtables_length + 1000)); + if (newbuf == NULL) + ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 100); + sp->dest.next_output_byte = (JOCTET*) newbuf + sp->jpegtables_length; + sp->dest.free_in_buffer = (size_t) 1000; + sp->jpegtables = newbuf; + sp->jpegtables_length += 1000; + return (TRUE); +} + +static void +tables_term_destination(j_compress_ptr cinfo) +{ + JPEGState* sp = (JPEGState*) cinfo; + + /* set tables length to number of bytes actually emitted */ + sp->jpegtables_length -= (uint32) sp->dest.free_in_buffer; +} + +static int +TIFFjpeg_tables_dest(JPEGState* sp, TIFF* tif) +{ + (void) tif; + /* + * Allocate a working buffer for building tables. + * Initial size is 1000 bytes, which is usually adequate. + */ + if (sp->jpegtables) + _TIFFfree(sp->jpegtables); + sp->jpegtables_length = 1000; + sp->jpegtables = (void*) _TIFFmalloc((tmsize_t) sp->jpegtables_length); + if (sp->jpegtables == NULL) { + sp->jpegtables_length = 0; + TIFFErrorExt(sp->tif->tif_clientdata, "TIFFjpeg_tables_dest", "No space for JPEGTables"); + return (0); + } + sp->cinfo.c.dest = &sp->dest; + sp->dest.init_destination = tables_init_destination; + sp->dest.empty_output_buffer = tables_empty_output_buffer; + sp->dest.term_destination = tables_term_destination; + return (1); +} + +/* + * JPEG library source data manager. + * These routines supply compressed data to libjpeg. + */ + +static void +std_init_source(j_decompress_ptr cinfo) +{ + JPEGState* sp = (JPEGState*) cinfo; + TIFF* tif = sp->tif; + + sp->src.next_input_byte = (const JOCTET*) tif->tif_rawdata; + sp->src.bytes_in_buffer = (size_t) tif->tif_rawcc; +} + +static boolean +std_fill_input_buffer(j_decompress_ptr cinfo) +{ + JPEGState* sp = (JPEGState* ) cinfo; + static const JOCTET dummy_EOI[2] = { 0xFF, JPEG_EOI }; + +#ifdef IPPJ_HUFF + /* + * The Intel IPP performance library does not necessarily read the whole + * input buffer in one pass, so it is possible to get here with data + * yet to read. + * + * We just return without doing anything, until the entire buffer has + * been read. + * http://trac.osgeo.org/gdal/wiki/JpegIPP + */ + if( sp->src.bytes_in_buffer > 0 ) { + return (TRUE); + } +#endif + + /* + * Normally the whole strip/tile is read and so we don't need to do + * a fill. In the case of CHUNKY_STRIP_READ_SUPPORT we might not have + * all the data, but the rawdata is refreshed between scanlines and + * we push this into the io machinery in JPEGDecode(). + * http://trac.osgeo.org/gdal/ticket/3894 + */ + + WARNMS(cinfo, JWRN_JPEG_EOF); + /* insert a fake EOI marker */ + sp->src.next_input_byte = dummy_EOI; + sp->src.bytes_in_buffer = 2; + return (TRUE); +} + +static void +std_skip_input_data(j_decompress_ptr cinfo, long num_bytes) +{ + JPEGState* sp = (JPEGState*) cinfo; + + if (num_bytes > 0) { + if ((size_t)num_bytes > sp->src.bytes_in_buffer) { + /* oops, buffer overrun */ + (void) std_fill_input_buffer(cinfo); + } else { + sp->src.next_input_byte += (size_t) num_bytes; + sp->src.bytes_in_buffer -= (size_t) num_bytes; + } + } +} + +static void +std_term_source(j_decompress_ptr cinfo) +{ + /* No work necessary here */ + (void) cinfo; +} + +static void +TIFFjpeg_data_src(JPEGState* sp, TIFF* tif) +{ + (void) tif; + sp->cinfo.d.src = &sp->src; + sp->src.init_source = std_init_source; + sp->src.fill_input_buffer = std_fill_input_buffer; + sp->src.skip_input_data = std_skip_input_data; + sp->src.resync_to_restart = jpeg_resync_to_restart; + sp->src.term_source = std_term_source; + sp->src.bytes_in_buffer = 0; /* for safety */ + sp->src.next_input_byte = NULL; +} + +/* + * Alternate source manager for reading from JPEGTables. + * We can share all the code except for the init routine. + */ + +static void +tables_init_source(j_decompress_ptr cinfo) +{ + JPEGState* sp = (JPEGState*) cinfo; + + sp->src.next_input_byte = (const JOCTET*) sp->jpegtables; + sp->src.bytes_in_buffer = (size_t) sp->jpegtables_length; +} + +static void +TIFFjpeg_tables_src(JPEGState* sp, TIFF* tif) +{ + TIFFjpeg_data_src(sp, tif); + sp->src.init_source = tables_init_source; +} + +/* + * Allocate downsampled-data buffers needed for downsampled I/O. + * We use values computed in jpeg_start_compress or jpeg_start_decompress. + * We use libjpeg's allocator so that buffers will be released automatically + * when done with strip/tile. + * This is also a handy place to compute samplesperclump, bytesperline. + */ +static int +alloc_downsampled_buffers(TIFF* tif, jpeg_component_info* comp_info, + int num_components) +{ + JPEGState* sp = JState(tif); + int ci; + jpeg_component_info* compptr; + JSAMPARRAY buf; + int samples_per_clump = 0; + + for (ci = 0, compptr = comp_info; ci < num_components; + ci++, compptr++) { + samples_per_clump += compptr->h_samp_factor * + compptr->v_samp_factor; + buf = TIFFjpeg_alloc_sarray(sp, JPOOL_IMAGE, + compptr->width_in_blocks * DCTSIZE, + (JDIMENSION) (compptr->v_samp_factor*DCTSIZE)); + if (buf == NULL) + return (0); + sp->ds_buffer[ci] = buf; + } + sp->samplesperclump = samples_per_clump; + return (1); +} + + +/* + * JPEG Decoding. + */ + +#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING + +#define JPEG_MARKER_SOF0 0xC0 +#define JPEG_MARKER_SOF1 0xC1 +#define JPEG_MARKER_SOF3 0xC3 +#define JPEG_MARKER_DHT 0xC4 +#define JPEG_MARKER_SOI 0xD8 +#define JPEG_MARKER_SOS 0xDA +#define JPEG_MARKER_DQT 0xDB +#define JPEG_MARKER_DRI 0xDD +#define JPEG_MARKER_APP0 0xE0 +#define JPEG_MARKER_COM 0xFE +struct JPEGFixupTagsSubsamplingData +{ + TIFF* tif; + void* buffer; + uint32 buffersize; + uint8* buffercurrentbyte; + uint32 bufferbytesleft; + uint64 fileoffset; + uint64 filebytesleft; + uint8 filepositioned; +}; +static void JPEGFixupTagsSubsampling(TIFF* tif); +static int JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* data); +static int JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData* data, uint8* result); +static int JPEGFixupTagsSubsamplingReadWord(struct JPEGFixupTagsSubsamplingData* data, uint16* result); +static void JPEGFixupTagsSubsamplingSkip(struct JPEGFixupTagsSubsamplingData* data, uint16 skiplength); + +#endif + +static int +JPEGFixupTags(TIFF* tif) +{ +#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING + if ((tif->tif_dir.td_photometric==PHOTOMETRIC_YCBCR)&& + (tif->tif_dir.td_planarconfig==PLANARCONFIG_CONTIG)&& + (tif->tif_dir.td_samplesperpixel==3)) + JPEGFixupTagsSubsampling(tif); +#endif + + return(1); +} + +#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING + +static void +JPEGFixupTagsSubsampling(TIFF* tif) +{ + /* + * Some JPEG-in-TIFF produces do not emit the YCBCRSUBSAMPLING values in + * the TIFF tags, but still use non-default (2,2) values within the jpeg + * data stream itself. In order for TIFF applications to work properly + * - for instance to get the strip buffer size right - it is imperative + * that the subsampling be available before we start reading the image + * data normally. This function will attempt to analyze the first strip in + * order to get the sampling values from the jpeg data stream. + * + * Note that JPEGPreDeocode() will produce a fairly loud warning when the + * discovered sampling does not match the default sampling (2,2) or whatever + * was actually in the tiff tags. + * + * See the bug in bugzilla for details: + * + * http://bugzilla.remotesensing.org/show_bug.cgi?id=168 + * + * Frank Warmerdam, July 2002 + * Joris Van Damme, May 2007 + */ + static const char module[] = "JPEGFixupTagsSubsampling"; + struct JPEGFixupTagsSubsamplingData m; + + _TIFFFillStriles( tif ); + + if( tif->tif_dir.td_stripbytecount == NULL + || tif->tif_dir.td_stripbytecount[0] == 0 ) + { + /* Do not even try to check if the first strip/tile does not + yet exist, as occurs when GDAL has created a new NULL file + for instance. */ + return; + } + + m.tif=tif; + m.buffersize=2048; + m.buffer=_TIFFmalloc(m.buffersize); + if (m.buffer==NULL) + { + TIFFWarningExt(tif->tif_clientdata,module, + "Unable to allocate memory for auto-correcting of subsampling values; auto-correcting skipped"); + return; + } + m.buffercurrentbyte=NULL; + m.bufferbytesleft=0; + m.fileoffset=tif->tif_dir.td_stripoffset[0]; + m.filepositioned=0; + m.filebytesleft=tif->tif_dir.td_stripbytecount[0]; + if (!JPEGFixupTagsSubsamplingSec(&m)) + TIFFWarningExt(tif->tif_clientdata,module, + "Unable to auto-correct subsampling values, likely corrupt JPEG compressed data in first strip/tile; auto-correcting skipped"); + _TIFFfree(m.buffer); +} + +static int +JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* data) +{ + static const char module[] = "JPEGFixupTagsSubsamplingSec"; + uint8 m; + while (1) + { + while (1) + { + if (!JPEGFixupTagsSubsamplingReadByte(data,&m)) + return(0); + if (m==255) + break; + } + while (1) + { + if (!JPEGFixupTagsSubsamplingReadByte(data,&m)) + return(0); + if (m!=255) + break; + } + switch (m) + { + case JPEG_MARKER_SOI: + /* this type of marker has no data and should be skipped */ + break; + case JPEG_MARKER_COM: + case JPEG_MARKER_APP0: + case JPEG_MARKER_APP0+1: + case JPEG_MARKER_APP0+2: + case JPEG_MARKER_APP0+3: + case JPEG_MARKER_APP0+4: + case JPEG_MARKER_APP0+5: + case JPEG_MARKER_APP0+6: + case JPEG_MARKER_APP0+7: + case JPEG_MARKER_APP0+8: + case JPEG_MARKER_APP0+9: + case JPEG_MARKER_APP0+10: + case JPEG_MARKER_APP0+11: + case JPEG_MARKER_APP0+12: + case JPEG_MARKER_APP0+13: + case JPEG_MARKER_APP0+14: + case JPEG_MARKER_APP0+15: + case JPEG_MARKER_DQT: + case JPEG_MARKER_SOS: + case JPEG_MARKER_DHT: + case JPEG_MARKER_DRI: + /* this type of marker has data, but it has no use to us and should be skipped */ + { + uint16 n; + if (!JPEGFixupTagsSubsamplingReadWord(data,&n)) + return(0); + if (n<2) + return(0); + n-=2; + if (n>0) + JPEGFixupTagsSubsamplingSkip(data,n); + } + break; + case JPEG_MARKER_SOF0: + case JPEG_MARKER_SOF1: + /* this marker contains the subsampling factors we're scanning for */ + { + uint16 n; + uint16 o; + uint8 p; + uint8 ph,pv; + if (!JPEGFixupTagsSubsamplingReadWord(data,&n)) + return(0); + if (n!=8+data->tif->tif_dir.td_samplesperpixel*3) + return(0); + JPEGFixupTagsSubsamplingSkip(data,7); + if (!JPEGFixupTagsSubsamplingReadByte(data,&p)) + return(0); + ph=(p>>4); + pv=(p&15); + JPEGFixupTagsSubsamplingSkip(data,1); + for (o=1; otif->tif_dir.td_samplesperpixel; o++) + { + JPEGFixupTagsSubsamplingSkip(data,1); + if (!JPEGFixupTagsSubsamplingReadByte(data,&p)) + return(0); + if (p!=0x11) + { + TIFFWarningExt(data->tif->tif_clientdata,module, + "Subsampling values inside JPEG compressed data have no TIFF equivalent, auto-correction of TIFF subsampling values failed"); + return(1); + } + JPEGFixupTagsSubsamplingSkip(data,1); + } + if (((ph!=1)&&(ph!=2)&&(ph!=4))||((pv!=1)&&(pv!=2)&&(pv!=4))) + { + TIFFWarningExt(data->tif->tif_clientdata,module, + "Subsampling values inside JPEG compressed data have no TIFF equivalent, auto-correction of TIFF subsampling values failed"); + return(1); + } + if ((ph!=data->tif->tif_dir.td_ycbcrsubsampling[0])||(pv!=data->tif->tif_dir.td_ycbcrsubsampling[1])) + { + TIFFWarningExt(data->tif->tif_clientdata,module, + "Auto-corrected former TIFF subsampling values [%d,%d] to match subsampling values inside JPEG compressed data [%d,%d]", + (int)data->tif->tif_dir.td_ycbcrsubsampling[0], + (int)data->tif->tif_dir.td_ycbcrsubsampling[1], + (int)ph,(int)pv); + data->tif->tif_dir.td_ycbcrsubsampling[0]=ph; + data->tif->tif_dir.td_ycbcrsubsampling[1]=pv; + } + } + return(1); + default: + return(0); + } + } +} + +static int +JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData* data, uint8* result) +{ + if (data->bufferbytesleft==0) + { + uint32 m; + if (data->filebytesleft==0) + return(0); + if (!data->filepositioned) + { + TIFFSeekFile(data->tif,data->fileoffset,SEEK_SET); + data->filepositioned=1; + } + m=data->buffersize; + if ((uint64)m>data->filebytesleft) + m=(uint32)data->filebytesleft; + assert(m<0x80000000UL); + if (TIFFReadFile(data->tif,data->buffer,(tmsize_t)m)!=(tmsize_t)m) + return(0); + data->buffercurrentbyte=data->buffer; + data->bufferbytesleft=m; + data->fileoffset+=m; + data->filebytesleft-=m; + } + *result=*data->buffercurrentbyte; + data->buffercurrentbyte++; + data->bufferbytesleft--; + return(1); +} + +static int +JPEGFixupTagsSubsamplingReadWord(struct JPEGFixupTagsSubsamplingData* data, uint16* result) +{ + uint8 ma; + uint8 mb; + if (!JPEGFixupTagsSubsamplingReadByte(data,&ma)) + return(0); + if (!JPEGFixupTagsSubsamplingReadByte(data,&mb)) + return(0); + *result=(ma<<8)|mb; + return(1); +} + +static void +JPEGFixupTagsSubsamplingSkip(struct JPEGFixupTagsSubsamplingData* data, uint16 skiplength) +{ + if ((uint32)skiplength<=data->bufferbytesleft) + { + data->buffercurrentbyte+=skiplength; + data->bufferbytesleft-=skiplength; + } + else + { + uint16 m; + m=skiplength-data->bufferbytesleft; + if (m<=data->filebytesleft) + { + data->bufferbytesleft=0; + data->fileoffset+=m; + data->filebytesleft-=m; + data->filepositioned=0; + } + else + { + data->bufferbytesleft=0; + data->filebytesleft=0; + } + } +} + +#endif + + +static int +JPEGSetupDecode(TIFF* tif) +{ + JPEGState* sp = JState(tif); + TIFFDirectory *td = &tif->tif_dir; + +#if defined(JPEG_DUAL_MODE_8_12) && !defined(TIFFInitJPEG) + if( tif->tif_dir.td_bitspersample == 12 ) + return TIFFReInitJPEG_12( tif, COMPRESSION_JPEG, 0 ); +#endif + + JPEGInitializeLibJPEG( tif, TRUE ); + + assert(sp != NULL); + assert(sp->cinfo.comm.is_decompressor); + + /* Read JPEGTables if it is present */ + if (TIFFFieldSet(tif,FIELD_JPEGTABLES)) { + TIFFjpeg_tables_src(sp, tif); + if(TIFFjpeg_read_header(sp,FALSE) != JPEG_HEADER_TABLES_ONLY) { + TIFFErrorExt(tif->tif_clientdata, "JPEGSetupDecode", "Bogus JPEGTables field"); + return (0); + } + } + + /* Grab parameters that are same for all strips/tiles */ + sp->photometric = td->td_photometric; + switch (sp->photometric) { + case PHOTOMETRIC_YCBCR: + sp->h_sampling = td->td_ycbcrsubsampling[0]; + sp->v_sampling = td->td_ycbcrsubsampling[1]; + break; + default: + /* TIFF 6.0 forbids subsampling of all other color spaces */ + sp->h_sampling = 1; + sp->v_sampling = 1; + break; + } + + /* Set up for reading normal data */ + TIFFjpeg_data_src(sp, tif); + tif->tif_postdecode = _TIFFNoPostDecode; /* override byte swapping */ + return (1); +} + +/* + * Set up for decoding a strip or tile. + */ +static int +JPEGPreDecode(TIFF* tif, uint16 s) +{ + JPEGState *sp = JState(tif); + TIFFDirectory *td = &tif->tif_dir; + static const char module[] = "JPEGPreDecode"; + uint32 segment_width, segment_height; + int downsampled_output; + int ci; + + assert(sp != NULL); + + if (sp->cinfo.comm.is_decompressor == 0) + { + tif->tif_setupdecode( tif ); + } + + assert(sp->cinfo.comm.is_decompressor); + /* + * Reset decoder state from any previous strip/tile, + * in case application didn't read the whole strip. + */ + if (!TIFFjpeg_abort(sp)) + return (0); + /* + * Read the header for this strip/tile. + */ + + if (TIFFjpeg_read_header(sp, TRUE) != JPEG_HEADER_OK) + return (0); + + tif->tif_rawcp = (uint8*) sp->src.next_input_byte; + tif->tif_rawcc = sp->src.bytes_in_buffer; + + /* + * Check image parameters and set decompression parameters. + */ + segment_width = td->td_imagewidth; + segment_height = td->td_imagelength - tif->tif_row; + if (isTiled(tif)) { + segment_width = td->td_tilewidth; + segment_height = td->td_tilelength; + sp->bytesperline = TIFFTileRowSize(tif); + } else { + if (segment_height > td->td_rowsperstrip) + segment_height = td->td_rowsperstrip; + sp->bytesperline = TIFFScanlineSize(tif); + } + if (td->td_planarconfig == PLANARCONFIG_SEPARATE && s > 0) { + /* + * For PC 2, scale down the expected strip/tile size + * to match a downsampled component + */ + segment_width = TIFFhowmany_32(segment_width, sp->h_sampling); + segment_height = TIFFhowmany_32(segment_height, sp->v_sampling); + } + if (sp->cinfo.d.image_width < segment_width || + sp->cinfo.d.image_height < segment_height) { + TIFFWarningExt(tif->tif_clientdata, module, + "Improper JPEG strip/tile size, " + "expected %dx%d, got %dx%d", + segment_width, segment_height, + sp->cinfo.d.image_width, + sp->cinfo.d.image_height); + } + if (sp->cinfo.d.image_width > segment_width || + sp->cinfo.d.image_height > segment_height) { + /* + * This case could be dangerous, if the strip or tile size has + * been reported as less than the amount of data jpeg will + * return, some potential security issues arise. Catch this + * case and error out. + */ + TIFFErrorExt(tif->tif_clientdata, module, + "JPEG strip/tile size exceeds expected dimensions," + " expected %dx%d, got %dx%d", + segment_width, segment_height, + sp->cinfo.d.image_width, sp->cinfo.d.image_height); + return (0); + } + if (sp->cinfo.d.num_components != + (td->td_planarconfig == PLANARCONFIG_CONTIG ? + td->td_samplesperpixel : 1)) { + TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG component count"); + return (0); + } +#ifdef JPEG_LIB_MK1 + if (12 != td->td_bitspersample && 8 != td->td_bitspersample) { + TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG data precision"); + return (0); + } + sp->cinfo.d.data_precision = td->td_bitspersample; + sp->cinfo.d.bits_in_jsample = td->td_bitspersample; +#else + if (sp->cinfo.d.data_precision != td->td_bitspersample) { + TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG data precision"); + return (0); + } +#endif + if (td->td_planarconfig == PLANARCONFIG_CONTIG) { + /* Component 0 should have expected sampling factors */ + if (sp->cinfo.d.comp_info[0].h_samp_factor != sp->h_sampling || + sp->cinfo.d.comp_info[0].v_samp_factor != sp->v_sampling) { + TIFFErrorExt(tif->tif_clientdata, module, + "Improper JPEG sampling factors %d,%d\n" + "Apparently should be %d,%d.", + sp->cinfo.d.comp_info[0].h_samp_factor, + sp->cinfo.d.comp_info[0].v_samp_factor, + sp->h_sampling, sp->v_sampling); + return (0); + } + /* Rest should have sampling factors 1,1 */ + for (ci = 1; ci < sp->cinfo.d.num_components; ci++) { + if (sp->cinfo.d.comp_info[ci].h_samp_factor != 1 || + sp->cinfo.d.comp_info[ci].v_samp_factor != 1) { + TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG sampling factors"); + return (0); + } + } + } else { + /* PC 2's single component should have sampling factors 1,1 */ + if (sp->cinfo.d.comp_info[0].h_samp_factor != 1 || + sp->cinfo.d.comp_info[0].v_samp_factor != 1) { + TIFFErrorExt(tif->tif_clientdata, module, "Improper JPEG sampling factors"); + return (0); + } + } + downsampled_output = FALSE; + if (td->td_planarconfig == PLANARCONFIG_CONTIG && + sp->photometric == PHOTOMETRIC_YCBCR && + sp->jpegcolormode == JPEGCOLORMODE_RGB) { + /* Convert YCbCr to RGB */ + sp->cinfo.d.jpeg_color_space = JCS_YCbCr; + sp->cinfo.d.out_color_space = JCS_RGB; + } else { + /* Suppress colorspace handling */ + sp->cinfo.d.jpeg_color_space = JCS_UNKNOWN; + sp->cinfo.d.out_color_space = JCS_UNKNOWN; + if (td->td_planarconfig == PLANARCONFIG_CONTIG && + (sp->h_sampling != 1 || sp->v_sampling != 1)) + downsampled_output = TRUE; + /* XXX what about up-sampling? */ + } + if (downsampled_output) { + /* Need to use raw-data interface to libjpeg */ + sp->cinfo.d.raw_data_out = TRUE; +#if JPEG_LIB_VERSION >= 70 + sp->cinfo.d.do_fancy_upsampling = FALSE; +#endif /* JPEG_LIB_VERSION >= 70 */ + tif->tif_decoderow = DecodeRowError; + tif->tif_decodestrip = JPEGDecodeRaw; + tif->tif_decodetile = JPEGDecodeRaw; + } else { + /* Use normal interface to libjpeg */ + sp->cinfo.d.raw_data_out = FALSE; + tif->tif_decoderow = JPEGDecode; + tif->tif_decodestrip = JPEGDecode; + tif->tif_decodetile = JPEGDecode; + } + /* Start JPEG decompressor */ + if (!TIFFjpeg_start_decompress(sp)) + return (0); + /* Allocate downsampled-data buffers if needed */ + if (downsampled_output) { + if (!alloc_downsampled_buffers(tif, sp->cinfo.d.comp_info, + sp->cinfo.d.num_components)) + return (0); + sp->scancount = DCTSIZE; /* mark buffer empty */ + } + return (1); +} + +/* + * Decode a chunk of pixels. + * "Standard" case: returned data is not downsampled. + */ +/*ARGSUSED*/ static int +JPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) +{ + JPEGState *sp = JState(tif); + tmsize_t nrows; + (void) s; + + /* + ** Update available information, buffer may have been refilled + ** between decode requests + */ + sp->src.next_input_byte = (const JOCTET*) tif->tif_rawcp; + sp->src.bytes_in_buffer = (size_t) tif->tif_rawcc; + + if( sp->bytesperline == 0 ) + return 0; + + nrows = cc / sp->bytesperline; + if (cc % sp->bytesperline) + TIFFWarningExt(tif->tif_clientdata, tif->tif_name, "fractional scanline not read"); + + if( nrows > (tmsize_t) sp->cinfo.d.image_height ) + nrows = sp->cinfo.d.image_height; + + /* data is expected to be read in multiples of a scanline */ + if (nrows) + { + JSAMPROW line_work_buf = NULL; + + /* + * For 6B, only use temporary buffer for 12 bit imagery. + * For Mk1 always use it. + */ +#if !defined(JPEG_LIB_MK1) + if( sp->cinfo.d.data_precision == 12 ) +#endif + { + line_work_buf = (JSAMPROW) + _TIFFmalloc(sizeof(short) * sp->cinfo.d.output_width + * sp->cinfo.d.num_components ); + } + + do { + if( line_work_buf != NULL ) + { + /* + * In the MK1 case, we aways read into a 16bit buffer, and then + * pack down to 12bit or 8bit. In 6B case we only read into 16 + * bit buffer for 12bit data, which we need to repack. + */ + if (TIFFjpeg_read_scanlines(sp, &line_work_buf, 1) != 1) + return (0); + + if( sp->cinfo.d.data_precision == 12 ) + { + int value_pairs = (sp->cinfo.d.output_width + * sp->cinfo.d.num_components) / 2; + int iPair; + + for( iPair = 0; iPair < value_pairs; iPair++ ) + { + unsigned char *out_ptr = + ((unsigned char *) buf) + iPair * 3; + JSAMPLE *in_ptr = line_work_buf + iPair * 2; + + out_ptr[0] = (in_ptr[0] & 0xff0) >> 4; + out_ptr[1] = ((in_ptr[0] & 0xf) << 4) + | ((in_ptr[1] & 0xf00) >> 8); + out_ptr[2] = ((in_ptr[1] & 0xff) >> 0); + } + } + else if( sp->cinfo.d.data_precision == 8 ) + { + int value_count = (sp->cinfo.d.output_width + * sp->cinfo.d.num_components); + int iValue; + + for( iValue = 0; iValue < value_count; iValue++ ) + { + ((unsigned char *) buf)[iValue] = + line_work_buf[iValue] & 0xff; + } + } + } + else + { + /* + * In the libjpeg6b 8bit case. We read directly into the + * TIFF buffer. + */ + JSAMPROW bufptr = (JSAMPROW)buf; + + if (TIFFjpeg_read_scanlines(sp, &bufptr, 1) != 1) + return (0); + } + + ++tif->tif_row; + buf += sp->bytesperline; + cc -= sp->bytesperline; + } while (--nrows > 0); + + if( line_work_buf != NULL ) + _TIFFfree( line_work_buf ); + } + + /* Update information on consumed data */ + tif->tif_rawcp = (uint8*) sp->src.next_input_byte; + tif->tif_rawcc = sp->src.bytes_in_buffer; + + /* Close down the decompressor if we've finished the strip or tile. */ + return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height + || TIFFjpeg_finish_decompress(sp); +} + +/*ARGSUSED*/ static int +DecodeRowError(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) + +{ + (void) buf; + (void) cc; + (void) s; + + TIFFErrorExt(tif->tif_clientdata, "TIFFReadScanline", + "scanline oriented access is not supported for downsampled JPEG compressed images, consider enabling TIFF_JPEGCOLORMODE as JPEGCOLORMODE_RGB." ); + return 0; +} + +/* + * Decode a chunk of pixels. + * Returned data is downsampled per sampling factors. + */ +/*ARGSUSED*/ static int +JPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) +{ + JPEGState *sp = JState(tif); + tmsize_t nrows; + (void) s; + + /* data is expected to be read in multiples of a scanline */ + if ( (nrows = sp->cinfo.d.image_height) ) { + + /* Cb,Cr both have sampling factors 1, so this is correct */ + JDIMENSION clumps_per_line = sp->cinfo.d.comp_info[1].downsampled_width; + int samples_per_clump = sp->samplesperclump; + +#if defined(JPEG_LIB_MK1_OR_12BIT) + unsigned short* tmpbuf = _TIFFmalloc(sizeof(unsigned short) * + sp->cinfo.d.output_width * + sp->cinfo.d.num_components); + if(tmpbuf==NULL) { + TIFFErrorExt(tif->tif_clientdata, "JPEGDecodeRaw", + "Out of memory"); + return 0; + } +#endif + + do { + jpeg_component_info *compptr; + int ci, clumpoffset; + + if( cc < sp->bytesperline ) { + TIFFErrorExt(tif->tif_clientdata, "JPEGDecodeRaw", + "application buffer not large enough for all data."); + return 0; + } + + /* Reload downsampled-data buffer if needed */ + if (sp->scancount >= DCTSIZE) { + int n = sp->cinfo.d.max_v_samp_factor * DCTSIZE; + if (TIFFjpeg_read_raw_data(sp, sp->ds_buffer, n) != n) + return (0); + sp->scancount = 0; + } + /* + * Fastest way to unseparate data is to make one pass + * over the scanline for each row of each component. + */ + clumpoffset = 0; /* first sample in clump */ + for (ci = 0, compptr = sp->cinfo.d.comp_info; + ci < sp->cinfo.d.num_components; + ci++, compptr++) { + int hsamp = compptr->h_samp_factor; + int vsamp = compptr->v_samp_factor; + int ypos; + + for (ypos = 0; ypos < vsamp; ypos++) { + JSAMPLE *inptr = sp->ds_buffer[ci][sp->scancount*vsamp + ypos]; + JDIMENSION nclump; +#if defined(JPEG_LIB_MK1_OR_12BIT) + JSAMPLE *outptr = (JSAMPLE*)tmpbuf + clumpoffset; +#else + JSAMPLE *outptr = (JSAMPLE*)buf + clumpoffset; + if (cc < (tmsize_t) (clumpoffset + samples_per_clump*(clumps_per_line-1) + hsamp)) { + TIFFErrorExt(tif->tif_clientdata, "JPEGDecodeRaw", + "application buffer not large enough for all data, possible subsampling issue"); + return 0; + } +#endif + + if (hsamp == 1) { + /* fast path for at least Cb and Cr */ + for (nclump = clumps_per_line; nclump-- > 0; ) { + outptr[0] = *inptr++; + outptr += samples_per_clump; + } + } else { + int xpos; + + /* general case */ + for (nclump = clumps_per_line; nclump-- > 0; ) { + for (xpos = 0; xpos < hsamp; xpos++) + outptr[xpos] = *inptr++; + outptr += samples_per_clump; + } + } + clumpoffset += hsamp; + } + } + +#if defined(JPEG_LIB_MK1_OR_12BIT) + { + if (sp->cinfo.d.data_precision == 8) + { + int i=0; + int len = sp->cinfo.d.output_width * sp->cinfo.d.num_components; + for (i=0; icinfo.d.output_width + * sp->cinfo.d.num_components) / 2; + int iPair; + for( iPair = 0; iPair < value_pairs; iPair++ ) + { + unsigned char *out_ptr = ((unsigned char *) buf) + iPair * 3; + JSAMPLE *in_ptr = (JSAMPLE *) (tmpbuf + iPair * 2); + out_ptr[0] = (in_ptr[0] & 0xff0) >> 4; + out_ptr[1] = ((in_ptr[0] & 0xf) << 4) + | ((in_ptr[1] & 0xf00) >> 8); + out_ptr[2] = ((in_ptr[1] & 0xff) >> 0); + } + } + } +#endif + + sp->scancount ++; + tif->tif_row += sp->v_sampling; + + buf += sp->bytesperline; + cc -= sp->bytesperline; + + nrows -= sp->v_sampling; + } while (nrows > 0); + +#if defined(JPEG_LIB_MK1_OR_12BIT) + _TIFFfree(tmpbuf); +#endif + + } + + /* Close down the decompressor if done. */ + return sp->cinfo.d.output_scanline < sp->cinfo.d.output_height + || TIFFjpeg_finish_decompress(sp); +} + + +/* + * JPEG Encoding. + */ + +static void +unsuppress_quant_table (JPEGState* sp, int tblno) +{ + JQUANT_TBL* qtbl; + + if ((qtbl = sp->cinfo.c.quant_tbl_ptrs[tblno]) != NULL) + qtbl->sent_table = FALSE; +} + +static void +unsuppress_huff_table (JPEGState* sp, int tblno) +{ + JHUFF_TBL* htbl; + + if ((htbl = sp->cinfo.c.dc_huff_tbl_ptrs[tblno]) != NULL) + htbl->sent_table = FALSE; + if ((htbl = sp->cinfo.c.ac_huff_tbl_ptrs[tblno]) != NULL) + htbl->sent_table = FALSE; +} + +static int +prepare_JPEGTables(TIFF* tif) +{ + JPEGState* sp = JState(tif); + + /* Initialize quant tables for current quality setting */ + if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE)) + return (0); + /* Mark only the tables we want for output */ + /* NB: chrominance tables are currently used only with YCbCr */ + if (!TIFFjpeg_suppress_tables(sp, TRUE)) + return (0); + if (sp->jpegtablesmode & JPEGTABLESMODE_QUANT) { + unsuppress_quant_table(sp, 0); + if (sp->photometric == PHOTOMETRIC_YCBCR) + unsuppress_quant_table(sp, 1); + } + if (sp->jpegtablesmode & JPEGTABLESMODE_HUFF) { + unsuppress_huff_table(sp, 0); + if (sp->photometric == PHOTOMETRIC_YCBCR) + unsuppress_huff_table(sp, 1); + } + /* Direct libjpeg output into jpegtables */ + if (!TIFFjpeg_tables_dest(sp, tif)) + return (0); + /* Emit tables-only datastream */ + if (!TIFFjpeg_write_tables(sp)) + return (0); + + return (1); +} + +static int +JPEGSetupEncode(TIFF* tif) +{ + JPEGState* sp = JState(tif); + TIFFDirectory *td = &tif->tif_dir; + static const char module[] = "JPEGSetupEncode"; + +#if defined(JPEG_DUAL_MODE_8_12) && !defined(TIFFInitJPEG) + if( tif->tif_dir.td_bitspersample == 12 ) + return TIFFReInitJPEG_12( tif, COMPRESSION_JPEG, 1 ); +#endif + + JPEGInitializeLibJPEG( tif, FALSE ); + + assert(sp != NULL); + assert(!sp->cinfo.comm.is_decompressor); + + /* + * Initialize all JPEG parameters to default values. + * Note that jpeg_set_defaults needs legal values for + * in_color_space and input_components. + */ + sp->cinfo.c.in_color_space = JCS_UNKNOWN; + sp->cinfo.c.input_components = 1; + if (!TIFFjpeg_set_defaults(sp)) + return (0); + /* Set per-file parameters */ + sp->photometric = td->td_photometric; + switch (sp->photometric) { + case PHOTOMETRIC_YCBCR: + sp->h_sampling = td->td_ycbcrsubsampling[0]; + sp->v_sampling = td->td_ycbcrsubsampling[1]; + /* + * A ReferenceBlackWhite field *must* be present since the + * default value is inappropriate for YCbCr. Fill in the + * proper value if application didn't set it. + */ + { + float *ref; + if (!TIFFGetField(tif, TIFFTAG_REFERENCEBLACKWHITE, + &ref)) { + float refbw[6]; + long top = 1L << td->td_bitspersample; + refbw[0] = 0; + refbw[1] = (float)(top-1L); + refbw[2] = (float)(top>>1); + refbw[3] = refbw[1]; + refbw[4] = refbw[2]; + refbw[5] = refbw[1]; + TIFFSetField(tif, TIFFTAG_REFERENCEBLACKWHITE, + refbw); + } + } + break; + case PHOTOMETRIC_PALETTE: /* disallowed by Tech Note */ + case PHOTOMETRIC_MASK: + TIFFErrorExt(tif->tif_clientdata, module, + "PhotometricInterpretation %d not allowed for JPEG", + (int) sp->photometric); + return (0); + default: + /* TIFF 6.0 forbids subsampling of all other color spaces */ + sp->h_sampling = 1; + sp->v_sampling = 1; + break; + } + + /* Verify miscellaneous parameters */ + + /* + * This would need work if libtiff ever supports different + * depths for different components, or if libjpeg ever supports + * run-time selection of depth. Neither is imminent. + */ +#ifdef JPEG_LIB_MK1 + /* BITS_IN_JSAMPLE now permits 8 and 12 --- dgilbert */ + if (td->td_bitspersample != 8 && td->td_bitspersample != 12) +#else + if (td->td_bitspersample != BITS_IN_JSAMPLE ) +#endif + { + TIFFErrorExt(tif->tif_clientdata, module, "BitsPerSample %d not allowed for JPEG", + (int) td->td_bitspersample); + return (0); + } + sp->cinfo.c.data_precision = td->td_bitspersample; +#ifdef JPEG_LIB_MK1 + sp->cinfo.c.bits_in_jsample = td->td_bitspersample; +#endif + if (isTiled(tif)) { + if ((td->td_tilelength % (sp->v_sampling * DCTSIZE)) != 0) { + TIFFErrorExt(tif->tif_clientdata, module, + "JPEG tile height must be multiple of %d", + sp->v_sampling * DCTSIZE); + return (0); + } + if ((td->td_tilewidth % (sp->h_sampling * DCTSIZE)) != 0) { + TIFFErrorExt(tif->tif_clientdata, module, + "JPEG tile width must be multiple of %d", + sp->h_sampling * DCTSIZE); + return (0); + } + } else { + if (td->td_rowsperstrip < td->td_imagelength && + (td->td_rowsperstrip % (sp->v_sampling * DCTSIZE)) != 0) { + TIFFErrorExt(tif->tif_clientdata, module, + "RowsPerStrip must be multiple of %d for JPEG", + sp->v_sampling * DCTSIZE); + return (0); + } + } + + /* Create a JPEGTables field if appropriate */ + if (sp->jpegtablesmode & (JPEGTABLESMODE_QUANT|JPEGTABLESMODE_HUFF)) { + if( sp->jpegtables == NULL + || memcmp(sp->jpegtables,"\0\0\0\0\0\0\0\0\0",8) == 0 ) + { + if (!prepare_JPEGTables(tif)) + return (0); + /* Mark the field present */ + /* Can't use TIFFSetField since BEENWRITING is already set! */ + tif->tif_flags |= TIFF_DIRTYDIRECT; + TIFFSetFieldBit(tif, FIELD_JPEGTABLES); + } + } else { + /* We do not support application-supplied JPEGTables, */ + /* so mark the field not present */ + TIFFClrFieldBit(tif, FIELD_JPEGTABLES); + } + + /* Direct libjpeg output to libtiff's output buffer */ + TIFFjpeg_data_dest(sp, tif); + + return (1); +} + +/* + * Set encoding state at the start of a strip or tile. + */ +static int +JPEGPreEncode(TIFF* tif, uint16 s) +{ + JPEGState *sp = JState(tif); + TIFFDirectory *td = &tif->tif_dir; + static const char module[] = "JPEGPreEncode"; + uint32 segment_width, segment_height; + int downsampled_input; + + assert(sp != NULL); + + if (sp->cinfo.comm.is_decompressor == 1) + { + tif->tif_setupencode( tif ); + } + + assert(!sp->cinfo.comm.is_decompressor); + /* + * Set encoding parameters for this strip/tile. + */ + if (isTiled(tif)) { + segment_width = td->td_tilewidth; + segment_height = td->td_tilelength; + sp->bytesperline = TIFFTileRowSize(tif); + } else { + segment_width = td->td_imagewidth; + segment_height = td->td_imagelength - tif->tif_row; + if (segment_height > td->td_rowsperstrip) + segment_height = td->td_rowsperstrip; + sp->bytesperline = TIFFScanlineSize(tif); + } + if (td->td_planarconfig == PLANARCONFIG_SEPARATE && s > 0) { + /* for PC 2, scale down the strip/tile size + * to match a downsampled component + */ + segment_width = TIFFhowmany_32(segment_width, sp->h_sampling); + segment_height = TIFFhowmany_32(segment_height, sp->v_sampling); + } + if (segment_width > 65535 || segment_height > 65535) { + TIFFErrorExt(tif->tif_clientdata, module, "Strip/tile too large for JPEG"); + return (0); + } + sp->cinfo.c.image_width = segment_width; + sp->cinfo.c.image_height = segment_height; + downsampled_input = FALSE; + if (td->td_planarconfig == PLANARCONFIG_CONTIG) { + sp->cinfo.c.input_components = td->td_samplesperpixel; + if (sp->photometric == PHOTOMETRIC_YCBCR) { + if (sp->jpegcolormode == JPEGCOLORMODE_RGB) { + sp->cinfo.c.in_color_space = JCS_RGB; + } else { + sp->cinfo.c.in_color_space = JCS_YCbCr; + if (sp->h_sampling != 1 || sp->v_sampling != 1) + downsampled_input = TRUE; + } + if (!TIFFjpeg_set_colorspace(sp, JCS_YCbCr)) + return (0); + /* + * Set Y sampling factors; + * we assume jpeg_set_colorspace() set the rest to 1 + */ + sp->cinfo.c.comp_info[0].h_samp_factor = sp->h_sampling; + sp->cinfo.c.comp_info[0].v_samp_factor = sp->v_sampling; + } else { + if ((td->td_photometric == PHOTOMETRIC_MINISWHITE || td->td_photometric == PHOTOMETRIC_MINISBLACK) && td->td_samplesperpixel == 1) + sp->cinfo.c.in_color_space = JCS_GRAYSCALE; + else if (td->td_photometric == PHOTOMETRIC_RGB && td->td_samplesperpixel == 3) + sp->cinfo.c.in_color_space = JCS_RGB; + else if (td->td_photometric == PHOTOMETRIC_SEPARATED && td->td_samplesperpixel == 4) + sp->cinfo.c.in_color_space = JCS_CMYK; + else + sp->cinfo.c.in_color_space = JCS_UNKNOWN; + if (!TIFFjpeg_set_colorspace(sp, sp->cinfo.c.in_color_space)) + return (0); + /* jpeg_set_colorspace set all sampling factors to 1 */ + } + } else { + sp->cinfo.c.input_components = 1; + sp->cinfo.c.in_color_space = JCS_UNKNOWN; + if (!TIFFjpeg_set_colorspace(sp, JCS_UNKNOWN)) + return (0); + sp->cinfo.c.comp_info[0].component_id = s; + /* jpeg_set_colorspace() set sampling factors to 1 */ + if (sp->photometric == PHOTOMETRIC_YCBCR && s > 0) { + sp->cinfo.c.comp_info[0].quant_tbl_no = 1; + sp->cinfo.c.comp_info[0].dc_tbl_no = 1; + sp->cinfo.c.comp_info[0].ac_tbl_no = 1; + } + } + /* ensure libjpeg won't write any extraneous markers */ + sp->cinfo.c.write_JFIF_header = FALSE; + sp->cinfo.c.write_Adobe_marker = FALSE; + /* set up table handling correctly */ + if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE)) + return (0); + if (! (sp->jpegtablesmode & JPEGTABLESMODE_QUANT)) { + unsuppress_quant_table(sp, 0); + unsuppress_quant_table(sp, 1); + } + if (sp->jpegtablesmode & JPEGTABLESMODE_HUFF) + sp->cinfo.c.optimize_coding = FALSE; + else + sp->cinfo.c.optimize_coding = TRUE; + if (downsampled_input) { + /* Need to use raw-data interface to libjpeg */ + sp->cinfo.c.raw_data_in = TRUE; + tif->tif_encoderow = JPEGEncodeRaw; + tif->tif_encodestrip = JPEGEncodeRaw; + tif->tif_encodetile = JPEGEncodeRaw; + } else { + /* Use normal interface to libjpeg */ + sp->cinfo.c.raw_data_in = FALSE; + tif->tif_encoderow = JPEGEncode; + tif->tif_encodestrip = JPEGEncode; + tif->tif_encodetile = JPEGEncode; + } + /* Start JPEG compressor */ + if (!TIFFjpeg_start_compress(sp, FALSE)) + return (0); + /* Allocate downsampled-data buffers if needed */ + if (downsampled_input) { + if (!alloc_downsampled_buffers(tif, sp->cinfo.c.comp_info, + sp->cinfo.c.num_components)) + return (0); + } + sp->scancount = 0; + + return (1); +} + +/* + * Encode a chunk of pixels. + * "Standard" case: incoming data is not downsampled. + */ +static int +JPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) +{ + JPEGState *sp = JState(tif); + tmsize_t nrows; + JSAMPROW bufptr[1]; + short *line16 = NULL; + int line16_count = 0; + + (void) s; + assert(sp != NULL); + /* data is expected to be supplied in multiples of a scanline */ + nrows = cc / sp->bytesperline; + if (cc % sp->bytesperline) + TIFFWarningExt(tif->tif_clientdata, tif->tif_name, + "fractional scanline discarded"); + + /* The last strip will be limited to image size */ + if( !isTiled(tif) && tif->tif_row+nrows > tif->tif_dir.td_imagelength ) + nrows = tif->tif_dir.td_imagelength - tif->tif_row; + + if( sp->cinfo.c.data_precision == 12 ) + { + line16_count = (sp->bytesperline * 2) / 3; + line16 = (short *) _TIFFmalloc(sizeof(short) * line16_count); + // FIXME: undiagnosed malloc failure + } + + while (nrows-- > 0) { + + if( sp->cinfo.c.data_precision == 12 ) + { + + int value_pairs = line16_count / 2; + int iPair; + + bufptr[0] = (JSAMPROW) line16; + + for( iPair = 0; iPair < value_pairs; iPair++ ) + { + unsigned char *in_ptr = + ((unsigned char *) buf) + iPair * 3; + JSAMPLE *out_ptr = (JSAMPLE *) (line16 + iPair * 2); + + out_ptr[0] = (in_ptr[0] << 4) | ((in_ptr[1] & 0xf0) >> 4); + out_ptr[1] = ((in_ptr[1] & 0x0f) << 8) | in_ptr[2]; + } + } + else + { + bufptr[0] = (JSAMPROW) buf; + } + if (TIFFjpeg_write_scanlines(sp, bufptr, 1) != 1) + return (0); + if (nrows > 0) + tif->tif_row++; + buf += sp->bytesperline; + } + + if( sp->cinfo.c.data_precision == 12 ) + { + _TIFFfree( line16 ); + } + + return (1); +} + +/* + * Encode a chunk of pixels. + * Incoming data is expected to be downsampled per sampling factors. + */ +static int +JPEGEncodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) +{ + JPEGState *sp = JState(tif); + JSAMPLE* inptr; + JSAMPLE* outptr; + tmsize_t nrows; + JDIMENSION clumps_per_line, nclump; + int clumpoffset, ci, xpos, ypos; + jpeg_component_info* compptr; + int samples_per_clump = sp->samplesperclump; + tmsize_t bytesperclumpline; + + (void) s; + assert(sp != NULL); + /* data is expected to be supplied in multiples of a clumpline */ + /* a clumpline is equivalent to v_sampling desubsampled scanlines */ + /* TODO: the following calculation of bytesperclumpline, should substitute calculation of sp->bytesperline, except that it is per v_sampling lines */ + bytesperclumpline = (((sp->cinfo.c.image_width+sp->h_sampling-1)/sp->h_sampling) + *(sp->h_sampling*sp->v_sampling+2)*sp->cinfo.c.data_precision+7) + /8; + + nrows = ( cc / bytesperclumpline ) * sp->v_sampling; + if (cc % bytesperclumpline) + TIFFWarningExt(tif->tif_clientdata, tif->tif_name, "fractional scanline discarded"); + + /* Cb,Cr both have sampling factors 1, so this is correct */ + clumps_per_line = sp->cinfo.c.comp_info[1].downsampled_width; + + while (nrows > 0) { + /* + * Fastest way to separate the data is to make one pass + * over the scanline for each row of each component. + */ + clumpoffset = 0; /* first sample in clump */ + for (ci = 0, compptr = sp->cinfo.c.comp_info; + ci < sp->cinfo.c.num_components; + ci++, compptr++) { + int hsamp = compptr->h_samp_factor; + int vsamp = compptr->v_samp_factor; + int padding = (int) (compptr->width_in_blocks * DCTSIZE - + clumps_per_line * hsamp); + for (ypos = 0; ypos < vsamp; ypos++) { + inptr = ((JSAMPLE*) buf) + clumpoffset; + outptr = sp->ds_buffer[ci][sp->scancount*vsamp + ypos]; + if (hsamp == 1) { + /* fast path for at least Cb and Cr */ + for (nclump = clumps_per_line; nclump-- > 0; ) { + *outptr++ = inptr[0]; + inptr += samples_per_clump; + } + } else { + /* general case */ + for (nclump = clumps_per_line; nclump-- > 0; ) { + for (xpos = 0; xpos < hsamp; xpos++) + *outptr++ = inptr[xpos]; + inptr += samples_per_clump; + } + } + /* pad each scanline as needed */ + for (xpos = 0; xpos < padding; xpos++) { + *outptr = outptr[-1]; + outptr++; + } + clumpoffset += hsamp; + } + } + sp->scancount++; + if (sp->scancount >= DCTSIZE) { + int n = sp->cinfo.c.max_v_samp_factor * DCTSIZE; + if (TIFFjpeg_write_raw_data(sp, sp->ds_buffer, n) != n) + return (0); + sp->scancount = 0; + } + tif->tif_row += sp->v_sampling; + buf += bytesperclumpline; + nrows -= sp->v_sampling; + } + return (1); +} + +/* + * Finish up at the end of a strip or tile. + */ +static int +JPEGPostEncode(TIFF* tif) +{ + JPEGState *sp = JState(tif); + + if (sp->scancount > 0) { + /* + * Need to emit a partial bufferload of downsampled data. + * Pad the data vertically. + */ + int ci, ypos, n; + jpeg_component_info* compptr; + + for (ci = 0, compptr = sp->cinfo.c.comp_info; + ci < sp->cinfo.c.num_components; + ci++, compptr++) { + int vsamp = compptr->v_samp_factor; + tmsize_t row_width = compptr->width_in_blocks * DCTSIZE + * sizeof(JSAMPLE); + for (ypos = sp->scancount * vsamp; + ypos < DCTSIZE * vsamp; ypos++) { + _TIFFmemcpy((void*)sp->ds_buffer[ci][ypos], + (void*)sp->ds_buffer[ci][ypos-1], + row_width); + + } + } + n = sp->cinfo.c.max_v_samp_factor * DCTSIZE; + if (TIFFjpeg_write_raw_data(sp, sp->ds_buffer, n) != n) + return (0); + } + + return (TIFFjpeg_finish_compress(JState(tif))); +} + +static void +JPEGCleanup(TIFF* tif) +{ + JPEGState *sp = JState(tif); + + assert(sp != 0); + + tif->tif_tagmethods.vgetfield = sp->vgetparent; + tif->tif_tagmethods.vsetfield = sp->vsetparent; + tif->tif_tagmethods.printdir = sp->printdir; + + if( sp != NULL ) { + if( sp->cinfo_initialized ) + TIFFjpeg_destroy(sp); /* release libjpeg resources */ + if (sp->jpegtables) /* tag value */ + _TIFFfree(sp->jpegtables); + } + _TIFFfree(tif->tif_data); /* release local state */ + tif->tif_data = NULL; + + _TIFFSetDefaultCompressionState(tif); +} + +static void +JPEGResetUpsampled( TIFF* tif ) +{ + JPEGState* sp = JState(tif); + TIFFDirectory* td = &tif->tif_dir; + + /* + * Mark whether returned data is up-sampled or not so TIFFStripSize + * and TIFFTileSize return values that reflect the true amount of + * data. + */ + tif->tif_flags &= ~TIFF_UPSAMPLED; + if (td->td_planarconfig == PLANARCONFIG_CONTIG) { + if (td->td_photometric == PHOTOMETRIC_YCBCR && + sp->jpegcolormode == JPEGCOLORMODE_RGB) { + tif->tif_flags |= TIFF_UPSAMPLED; + } else { +#ifdef notdef + if (td->td_ycbcrsubsampling[0] != 1 || + td->td_ycbcrsubsampling[1] != 1) + ; /* XXX what about up-sampling? */ +#endif + } + } + + /* + * Must recalculate cached tile size in case sampling state changed. + * Should we really be doing this now if image size isn't set? + */ + if( tif->tif_tilesize > 0 ) + tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tmsize_t)(-1); + if( tif->tif_scanlinesize > 0 ) + tif->tif_scanlinesize = TIFFScanlineSize(tif); +} + +static int +JPEGVSetField(TIFF* tif, uint32 tag, va_list ap) +{ + JPEGState* sp = JState(tif); + const TIFFField* fip; + uint32 v32; + + assert(sp != NULL); + + switch (tag) { + case TIFFTAG_JPEGTABLES: + v32 = (uint32) va_arg(ap, uint32); + if (v32 == 0) { + /* XXX */ + return (0); + } + _TIFFsetByteArray(&sp->jpegtables, va_arg(ap, void*), + (long) v32); + sp->jpegtables_length = v32; + TIFFSetFieldBit(tif, FIELD_JPEGTABLES); + break; + case TIFFTAG_JPEGQUALITY: + sp->jpegquality = (int) va_arg(ap, int); + return (1); /* pseudo tag */ + case TIFFTAG_JPEGCOLORMODE: + sp->jpegcolormode = (int) va_arg(ap, int); + JPEGResetUpsampled( tif ); + return (1); /* pseudo tag */ + case TIFFTAG_PHOTOMETRIC: + { + int ret_value = (*sp->vsetparent)(tif, tag, ap); + JPEGResetUpsampled( tif ); + return ret_value; + } + case TIFFTAG_JPEGTABLESMODE: + sp->jpegtablesmode = (int) va_arg(ap, int); + return (1); /* pseudo tag */ + case TIFFTAG_YCBCRSUBSAMPLING: + /* mark the fact that we have a real ycbcrsubsampling! */ + sp->ycbcrsampling_fetched = 1; + /* should we be recomputing upsampling info here? */ + return (*sp->vsetparent)(tif, tag, ap); + default: + return (*sp->vsetparent)(tif, tag, ap); + } + + if ((fip = TIFFFieldWithTag(tif, tag))) { + TIFFSetFieldBit(tif, fip->field_bit); + } else { + return (0); + } + + tif->tif_flags |= TIFF_DIRTYDIRECT; + return (1); +} + +static int +JPEGVGetField(TIFF* tif, uint32 tag, va_list ap) +{ + JPEGState* sp = JState(tif); + + assert(sp != NULL); + + switch (tag) { + case TIFFTAG_JPEGTABLES: + *va_arg(ap, uint32*) = sp->jpegtables_length; + *va_arg(ap, void**) = sp->jpegtables; + break; + case TIFFTAG_JPEGQUALITY: + *va_arg(ap, int*) = sp->jpegquality; + break; + case TIFFTAG_JPEGCOLORMODE: + *va_arg(ap, int*) = sp->jpegcolormode; + break; + case TIFFTAG_JPEGTABLESMODE: + *va_arg(ap, int*) = sp->jpegtablesmode; + break; + default: + return (*sp->vgetparent)(tif, tag, ap); + } + return (1); +} + +static void +JPEGPrintDir(TIFF* tif, FILE* fd, long flags) +{ + JPEGState* sp = JState(tif); + + assert(sp != NULL); + (void) flags; + + if( sp != NULL ) { + if (TIFFFieldSet(tif,FIELD_JPEGTABLES)) + fprintf(fd, " JPEG Tables: (%lu bytes)\n", + (unsigned long) sp->jpegtables_length); + if (sp->printdir) + (*sp->printdir)(tif, fd, flags); + } +} + +static uint32 +JPEGDefaultStripSize(TIFF* tif, uint32 s) +{ + JPEGState* sp = JState(tif); + TIFFDirectory *td = &tif->tif_dir; + + s = (*sp->defsparent)(tif, s); + if (s < td->td_imagelength) + s = TIFFroundup_32(s, td->td_ycbcrsubsampling[1] * DCTSIZE); + return (s); +} + +static void +JPEGDefaultTileSize(TIFF* tif, uint32* tw, uint32* th) +{ + JPEGState* sp = JState(tif); + TIFFDirectory *td = &tif->tif_dir; + + (*sp->deftparent)(tif, tw, th); + *tw = TIFFroundup_32(*tw, td->td_ycbcrsubsampling[0] * DCTSIZE); + *th = TIFFroundup_32(*th, td->td_ycbcrsubsampling[1] * DCTSIZE); +} + +/* + * The JPEG library initialized used to be done in TIFFInitJPEG(), but + * now that we allow a TIFF file to be opened in update mode it is necessary + * to have some way of deciding whether compression or decompression is + * desired other than looking at tif->tif_mode. We accomplish this by + * examining {TILE/STRIP}BYTECOUNTS to see if there is a non-zero entry. + * If so, we assume decompression is desired. + * + * This is tricky, because TIFFInitJPEG() is called while the directory is + * being read, and generally speaking the BYTECOUNTS tag won't have been read + * at that point. So we try to defer jpeg library initialization till we + * do have that tag ... basically any access that might require the compressor + * or decompressor that occurs after the reading of the directory. + * + * In an ideal world compressors or decompressors would be setup + * at the point where a single tile or strip was accessed (for read or write) + * so that stuff like update of missing tiles, or replacement of tiles could + * be done. However, we aren't trying to crack that nut just yet ... + * + * NFW, Feb 3rd, 2003. + */ + +static int JPEGInitializeLibJPEG( TIFF * tif, int decompress ) +{ + JPEGState* sp = JState(tif); + + if(sp->cinfo_initialized) + { + if( !decompress && sp->cinfo.comm.is_decompressor ) + TIFFjpeg_destroy( sp ); + else if( decompress && !sp->cinfo.comm.is_decompressor ) + TIFFjpeg_destroy( sp ); + else + return 1; + + sp->cinfo_initialized = 0; + } + + /* + * Initialize libjpeg. + */ + if ( decompress ) { + if (!TIFFjpeg_create_decompress(sp)) + return (0); + } else { + if (!TIFFjpeg_create_compress(sp)) + return (0); + } + + sp->cinfo_initialized = TRUE; + + return 1; +} + +int +TIFFInitJPEG(TIFF* tif, int scheme) +{ + JPEGState* sp; + + assert(scheme == COMPRESSION_JPEG); + + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFields(tif, jpegFields, TIFFArrayCount(jpegFields))) { + TIFFErrorExt(tif->tif_clientdata, + "TIFFInitJPEG", + "Merging JPEG codec-specific tags failed"); + return 0; + } + + /* + * Allocate state block so tag methods have storage to record values. + */ + tif->tif_data = (uint8*) _TIFFmalloc(sizeof (JPEGState)); + + if (tif->tif_data == NULL) { + TIFFErrorExt(tif->tif_clientdata, + "TIFFInitJPEG", "No space for JPEG state block"); + return 0; + } + _TIFFmemset(tif->tif_data, 0, sizeof(JPEGState)); + + sp = JState(tif); + sp->tif = tif; /* back link */ + + /* + * Override parent get/set field methods. + */ + sp->vgetparent = tif->tif_tagmethods.vgetfield; + tif->tif_tagmethods.vgetfield = JPEGVGetField; /* hook for codec tags */ + sp->vsetparent = tif->tif_tagmethods.vsetfield; + tif->tif_tagmethods.vsetfield = JPEGVSetField; /* hook for codec tags */ + sp->printdir = tif->tif_tagmethods.printdir; + tif->tif_tagmethods.printdir = JPEGPrintDir; /* hook for codec tags */ + + /* Default values for codec-specific fields */ + sp->jpegtables = NULL; + sp->jpegtables_length = 0; + sp->jpegquality = 75; /* Default IJG quality */ + sp->jpegcolormode = JPEGCOLORMODE_RAW; + sp->jpegtablesmode = JPEGTABLESMODE_QUANT | JPEGTABLESMODE_HUFF; + sp->ycbcrsampling_fetched = 0; + + /* + * Install codec methods. + */ + tif->tif_fixuptags = JPEGFixupTags; + tif->tif_setupdecode = JPEGSetupDecode; + tif->tif_predecode = JPEGPreDecode; + tif->tif_decoderow = JPEGDecode; + tif->tif_decodestrip = JPEGDecode; + tif->tif_decodetile = JPEGDecode; + tif->tif_setupencode = JPEGSetupEncode; + tif->tif_preencode = JPEGPreEncode; + tif->tif_postencode = JPEGPostEncode; + tif->tif_encoderow = JPEGEncode; + tif->tif_encodestrip = JPEGEncode; + tif->tif_encodetile = JPEGEncode; + tif->tif_cleanup = JPEGCleanup; + sp->defsparent = tif->tif_defstripsize; + tif->tif_defstripsize = JPEGDefaultStripSize; + sp->deftparent = tif->tif_deftilesize; + tif->tif_deftilesize = JPEGDefaultTileSize; + tif->tif_flags |= TIFF_NOBITREV; /* no bit reversal, please */ + + sp->cinfo_initialized = FALSE; + + /* + ** Create a JPEGTables field if no directory has yet been created. + ** We do this just to ensure that sufficient space is reserved for + ** the JPEGTables field. It will be properly created the right + ** size later. + */ + if( tif->tif_diroff == 0 ) + { +#define SIZE_OF_JPEGTABLES 2000 +/* +The following line assumes incorrectly that all JPEG-in-TIFF files will have +a JPEGTABLES tag generated and causes null-filled JPEGTABLES tags to be written +when the JPEG data is placed with TIFFWriteRawStrip. The field bit should be +set, anyway, later when actual JPEGTABLES header is generated, so removing it +here hopefully is harmless. + TIFFSetFieldBit(tif, FIELD_JPEGTABLES); +*/ + sp->jpegtables_length = SIZE_OF_JPEGTABLES; + sp->jpegtables = (void *) _TIFFmalloc(sp->jpegtables_length); + // FIXME: NULL-deref after malloc failure + _TIFFmemset(sp->jpegtables, 0, SIZE_OF_JPEGTABLES); +#undef SIZE_OF_JPEGTABLES + } + + return 1; +} +#endif /* JPEG_SUPPORT */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ + +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_jpeg_12.c b/Source/LibTIFF4/tif_jpeg_12.c index e788ae6..87aaa19 100644 --- a/Source/LibTIFF4/tif_jpeg_12.c +++ b/Source/LibTIFF4/tif_jpeg_12.c @@ -1,65 +1,65 @@ - -#include "tiffiop.h" - -#if defined(JPEG_DUAL_MODE_8_12) - -# define TIFFInitJPEG TIFFInitJPEG_12 - -# include LIBJPEG_12_PATH - -# include "tif_jpeg.c" - -int TIFFReInitJPEG_12( TIFF *tif, int scheme, int is_encode ) - -{ - JPEGState* sp; - - assert(scheme == COMPRESSION_JPEG); - - sp = JState(tif); - sp->tif = tif; /* back link */ - - /* - * Override parent get/set field methods. - */ - tif->tif_tagmethods.vgetfield = JPEGVGetField; /* hook for codec tags */ - tif->tif_tagmethods.vsetfield = JPEGVSetField; /* hook for codec tags */ - tif->tif_tagmethods.printdir = JPEGPrintDir; /* hook for codec tags */ - - /* - * Install codec methods. - */ - tif->tif_fixuptags = JPEGFixupTags; - tif->tif_setupdecode = JPEGSetupDecode; - tif->tif_predecode = JPEGPreDecode; - tif->tif_decoderow = JPEGDecode; - tif->tif_decodestrip = JPEGDecode; - tif->tif_decodetile = JPEGDecode; - tif->tif_setupencode = JPEGSetupEncode; - tif->tif_preencode = JPEGPreEncode; - tif->tif_postencode = JPEGPostEncode; - tif->tif_encoderow = JPEGEncode; - tif->tif_encodestrip = JPEGEncode; - tif->tif_encodetile = JPEGEncode; - tif->tif_cleanup = JPEGCleanup; - tif->tif_defstripsize = JPEGDefaultStripSize; - tif->tif_deftilesize = JPEGDefaultTileSize; - tif->tif_flags |= TIFF_NOBITREV; /* no bit reversal, please */ - - sp->cinfo_initialized = FALSE; - - if( is_encode ) - return JPEGSetupEncode(tif); - else - return JPEGSetupDecode(tif); -} - -#endif /* defined(JPEG_DUAL_MODE_8_12) */ - -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ + +#include "tiffiop.h" + +#if defined(JPEG_DUAL_MODE_8_12) + +# define TIFFInitJPEG TIFFInitJPEG_12 + +# include LIBJPEG_12_PATH + +# include "tif_jpeg.c" + +int TIFFReInitJPEG_12( TIFF *tif, int scheme, int is_encode ) + +{ + JPEGState* sp; + + assert(scheme == COMPRESSION_JPEG); + + sp = JState(tif); + sp->tif = tif; /* back link */ + + /* + * Override parent get/set field methods. + */ + tif->tif_tagmethods.vgetfield = JPEGVGetField; /* hook for codec tags */ + tif->tif_tagmethods.vsetfield = JPEGVSetField; /* hook for codec tags */ + tif->tif_tagmethods.printdir = JPEGPrintDir; /* hook for codec tags */ + + /* + * Install codec methods. + */ + tif->tif_fixuptags = JPEGFixupTags; + tif->tif_setupdecode = JPEGSetupDecode; + tif->tif_predecode = JPEGPreDecode; + tif->tif_decoderow = JPEGDecode; + tif->tif_decodestrip = JPEGDecode; + tif->tif_decodetile = JPEGDecode; + tif->tif_setupencode = JPEGSetupEncode; + tif->tif_preencode = JPEGPreEncode; + tif->tif_postencode = JPEGPostEncode; + tif->tif_encoderow = JPEGEncode; + tif->tif_encodestrip = JPEGEncode; + tif->tif_encodetile = JPEGEncode; + tif->tif_cleanup = JPEGCleanup; + tif->tif_defstripsize = JPEGDefaultStripSize; + tif->tif_deftilesize = JPEGDefaultTileSize; + tif->tif_flags |= TIFF_NOBITREV; /* no bit reversal, please */ + + sp->cinfo_initialized = FALSE; + + if( is_encode ) + return JPEGSetupEncode(tif); + else + return JPEGSetupDecode(tif); +} + +#endif /* defined(JPEG_DUAL_MODE_8_12) */ + +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_luv.c b/Source/LibTIFF4/tif_luv.c index 113509c..f80e81f 100644 --- a/Source/LibTIFF4/tif_luv.c +++ b/Source/LibTIFF4/tif_luv.c @@ -1,1683 +1,1683 @@ -/* $Id: tif_luv.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1997 Greg Ward Larson - * Copyright (c) 1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler, Greg Larson and Silicon Graphics may not be used in any - * advertising or publicity relating to the software without the specific, - * prior written permission of Sam Leffler, Greg Larson and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER, GREG LARSON OR SILICON GRAPHICS BE LIABLE - * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "tiffiop.h" -#ifdef LOGLUV_SUPPORT - -/* - * TIFF Library. - * LogLuv compression support for high dynamic range images. - * - * Contributed by Greg Larson. - * - * LogLuv image support uses the TIFF library to store 16 or 10-bit - * log luminance values with 8 bits each of u and v or a 14-bit index. - * - * The codec can take as input and produce as output 32-bit IEEE float values - * as well as 16-bit integer values. A 16-bit luminance is interpreted - * as a sign bit followed by a 15-bit integer that is converted - * to and from a linear magnitude using the transformation: - * - * L = 2^( (Le+.5)/256 - 64 ) # real from 15-bit - * - * Le = floor( 256*(log2(L) + 64) ) # 15-bit from real - * - * The actual conversion to world luminance units in candelas per sq. meter - * requires an additional multiplier, which is stored in the TIFFTAG_STONITS. - * This value is usually set such that a reasonable exposure comes from - * clamping decoded luminances above 1 to 1 in the displayed image. - * - * The 16-bit values for u and v may be converted to real values by dividing - * each by 32768. (This allows for negative values, which aren't useful as - * far as we know, but are left in case of future improvements in human - * color vision.) - * - * Conversion from (u,v), which is actually the CIE (u',v') system for - * you color scientists, is accomplished by the following transformation: - * - * u = 4*x / (-2*x + 12*y + 3) - * v = 9*y / (-2*x + 12*y + 3) - * - * x = 9*u / (6*u - 16*v + 12) - * y = 4*v / (6*u - 16*v + 12) - * - * This process is greatly simplified by passing 32-bit IEEE floats - * for each of three CIE XYZ coordinates. The codec then takes care - * of conversion to and from LogLuv, though the application is still - * responsible for interpreting the TIFFTAG_STONITS calibration factor. - * - * By definition, a CIE XYZ vector of [1 1 1] corresponds to a neutral white - * point of (x,y)=(1/3,1/3). However, most color systems assume some other - * white point, such as D65, and an absolute color conversion to XYZ then - * to another color space with a different white point may introduce an - * unwanted color cast to the image. It is often desirable, therefore, to - * perform a white point conversion that maps the input white to [1 1 1] - * in XYZ, then record the original white point using the TIFFTAG_WHITEPOINT - * tag value. A decoder that demands absolute color calibration may use - * this white point tag to get back the original colors, but usually it - * will be ignored and the new white point will be used instead that - * matches the output color space. - * - * Pixel information is compressed into one of two basic encodings, depending - * on the setting of the compression tag, which is one of COMPRESSION_SGILOG - * or COMPRESSION_SGILOG24. For COMPRESSION_SGILOG, greyscale data is - * stored as: - * - * 1 15 - * |-+---------------| - * - * COMPRESSION_SGILOG color data is stored as: - * - * 1 15 8 8 - * |-+---------------|--------+--------| - * S Le ue ve - * - * For the 24-bit COMPRESSION_SGILOG24 color format, the data is stored as: - * - * 10 14 - * |----------|--------------| - * Le' Ce - * - * There is no sign bit in the 24-bit case, and the (u,v) chromaticity is - * encoded as an index for optimal color resolution. The 10 log bits are - * defined by the following conversions: - * - * L = 2^((Le'+.5)/64 - 12) # real from 10-bit - * - * Le' = floor( 64*(log2(L) + 12) ) # 10-bit from real - * - * The 10 bits of the smaller format may be converted into the 15 bits of - * the larger format by multiplying by 4 and adding 13314. Obviously, - * a smaller range of magnitudes is covered (about 5 orders of magnitude - * instead of 38), and the lack of a sign bit means that negative luminances - * are not allowed. (Well, they aren't allowed in the real world, either, - * but they are useful for certain types of image processing.) - * - * The desired user format is controlled by the setting the internal - * pseudo tag TIFFTAG_SGILOGDATAFMT to one of: - * SGILOGDATAFMT_FLOAT = IEEE 32-bit float XYZ values - * SGILOGDATAFMT_16BIT = 16-bit integer encodings of logL, u and v - * Raw data i/o is also possible using: - * SGILOGDATAFMT_RAW = 32-bit unsigned integer with encoded pixel - * In addition, the following decoding is provided for ease of display: - * SGILOGDATAFMT_8BIT = 8-bit default RGB gamma-corrected values - * - * For grayscale images, we provide the following data formats: - * SGILOGDATAFMT_FLOAT = IEEE 32-bit float Y values - * SGILOGDATAFMT_16BIT = 16-bit integer w/ encoded luminance - * SGILOGDATAFMT_8BIT = 8-bit gray monitor values - * - * Note that the COMPRESSION_SGILOG applies a simple run-length encoding - * scheme by separating the logL, u and v bytes for each row and applying - * a PackBits type of compression. Since the 24-bit encoding is not - * adaptive, the 32-bit color format takes less space in many cases. - * - * Further control is provided over the conversion from higher-resolution - * formats to final encoded values through the pseudo tag - * TIFFTAG_SGILOGENCODE: - * SGILOGENCODE_NODITHER = do not dither encoded values - * SGILOGENCODE_RANDITHER = apply random dithering during encoding - * - * The default value of this tag is SGILOGENCODE_NODITHER for - * COMPRESSION_SGILOG to maximize run-length encoding and - * SGILOGENCODE_RANDITHER for COMPRESSION_SGILOG24 to turn - * quantization errors into noise. - */ - -#include -#include -#include - -/* - * State block for each open TIFF - * file using LogLuv compression/decompression. - */ -typedef struct logLuvState LogLuvState; - -struct logLuvState { - int user_datafmt; /* user data format */ - int encode_meth; /* encoding method */ - int pixel_size; /* bytes per pixel */ - - uint8* tbuf; /* translation buffer */ - tmsize_t tbuflen; /* buffer length */ - void (*tfunc)(LogLuvState*, uint8*, tmsize_t); - - TIFFVSetMethod vgetparent; /* super-class method */ - TIFFVSetMethod vsetparent; /* super-class method */ -}; - -#define DecoderState(tif) ((LogLuvState*) (tif)->tif_data) -#define EncoderState(tif) ((LogLuvState*) (tif)->tif_data) - -#define SGILOGDATAFMT_UNKNOWN -1 - -#define MINRUN 4 /* minimum run length */ - -/* - * Decode a string of 16-bit gray pixels. - */ -static int -LogL16Decode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) -{ - static const char module[] = "LogL16Decode"; - LogLuvState* sp = DecoderState(tif); - int shft; - tmsize_t i; - tmsize_t npixels; - unsigned char* bp; - int16* tp; - int16 b; - tmsize_t cc; - int rc; - - assert(s == 0); - assert(sp != NULL); - - npixels = occ / sp->pixel_size; - - if (sp->user_datafmt == SGILOGDATAFMT_16BIT) - tp = (int16*) op; - else { - assert(sp->tbuflen >= npixels); - tp = (int16*) sp->tbuf; - } - _TIFFmemset((void*) tp, 0, npixels*sizeof (tp[0])); - - bp = (unsigned char*) tif->tif_rawcp; - cc = tif->tif_rawcc; - /* get each byte string */ - for (shft = 2*8; (shft -= 8) >= 0; ) { - for (i = 0; i < npixels && cc > 0; ) - if (*bp >= 128) { /* run */ - rc = *bp++ + (2-128); /* TODO: potential input buffer overrun when decoding corrupt or truncated data */ - b = (int16)(*bp++ << shft); - cc -= 2; - while (rc-- && i < npixels) - tp[i++] |= b; - } else { /* non-run */ - rc = *bp++; /* nul is noop */ - while (--cc && rc-- && i < npixels) - tp[i++] |= (int16)*bp++ << shft; - } - if (i != npixels) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data at row %lu (short %I64d pixels)", - (unsigned long) tif->tif_row, - (unsigned __int64) (npixels - i)); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data at row %lu (short %llu pixels)", - (unsigned long) tif->tif_row, - (unsigned long long) (npixels - i)); -#endif - tif->tif_rawcp = (uint8*) bp; - tif->tif_rawcc = cc; - return (0); - } - } - (*sp->tfunc)(sp, op, npixels); - tif->tif_rawcp = (uint8*) bp; - tif->tif_rawcc = cc; - return (1); -} - -/* - * Decode a string of 24-bit pixels. - */ -static int -LogLuvDecode24(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) -{ - static const char module[] = "LogLuvDecode24"; - LogLuvState* sp = DecoderState(tif); - tmsize_t cc; - tmsize_t i; - tmsize_t npixels; - unsigned char* bp; - uint32* tp; - - assert(s == 0); - assert(sp != NULL); - - npixels = occ / sp->pixel_size; - - if (sp->user_datafmt == SGILOGDATAFMT_RAW) - tp = (uint32 *)op; - else { - assert(sp->tbuflen >= npixels); - tp = (uint32 *) sp->tbuf; - } - /* copy to array of uint32 */ - bp = (unsigned char*) tif->tif_rawcp; - cc = tif->tif_rawcc; - for (i = 0; i < npixels && cc > 0; i++) { - tp[i] = bp[0] << 16 | bp[1] << 8 | bp[2]; - bp += 3; - cc -= 3; - } - tif->tif_rawcp = (uint8*) bp; - tif->tif_rawcc = cc; - if (i != npixels) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data at row %lu (short %I64d pixels)", - (unsigned long) tif->tif_row, - (unsigned __int64) (npixels - i)); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data at row %lu (short %llu pixels)", - (unsigned long) tif->tif_row, - (unsigned long long) (npixels - i)); -#endif - return (0); - } - (*sp->tfunc)(sp, op, npixels); - return (1); -} - -/* - * Decode a string of 32-bit pixels. - */ -static int -LogLuvDecode32(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) -{ - static const char module[] = "LogLuvDecode32"; - LogLuvState* sp; - int shft; - tmsize_t i; - tmsize_t npixels; - unsigned char* bp; - uint32* tp; - uint32 b; - tmsize_t cc; - int rc; - - assert(s == 0); - sp = DecoderState(tif); - assert(sp != NULL); - - npixels = occ / sp->pixel_size; - - if (sp->user_datafmt == SGILOGDATAFMT_RAW) - tp = (uint32*) op; - else { - assert(sp->tbuflen >= npixels); - tp = (uint32*) sp->tbuf; - } - _TIFFmemset((void*) tp, 0, npixels*sizeof (tp[0])); - - bp = (unsigned char*) tif->tif_rawcp; - cc = tif->tif_rawcc; - /* get each byte string */ - for (shft = 4*8; (shft -= 8) >= 0; ) { - for (i = 0; i < npixels && cc > 0; ) - if (*bp >= 128) { /* run */ - rc = *bp++ + (2-128); - b = (uint32)*bp++ << shft; - cc -= 2; /* TODO: potential input buffer overrun when decoding corrupt or truncated data */ - while (rc-- && i < npixels) - tp[i++] |= b; - } else { /* non-run */ - rc = *bp++; /* nul is noop */ - while (--cc && rc-- && i < npixels) - tp[i++] |= (uint32)*bp++ << shft; - } - if (i != npixels) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data at row %lu (short %I64d pixels)", - (unsigned long) tif->tif_row, - (unsigned __int64) (npixels - i)); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data at row %lu (short %llu pixels)", - (unsigned long) tif->tif_row, - (unsigned long long) (npixels - i)); -#endif - tif->tif_rawcp = (uint8*) bp; - tif->tif_rawcc = cc; - return (0); - } - } - (*sp->tfunc)(sp, op, npixels); - tif->tif_rawcp = (uint8*) bp; - tif->tif_rawcc = cc; - return (1); -} - -/* - * Decode a strip of pixels. We break it into rows to - * maintain synchrony with the encode algorithm, which - * is row by row. - */ -static int -LogLuvDecodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - tmsize_t rowlen = TIFFScanlineSize(tif); - - assert(cc%rowlen == 0); - while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) - bp += rowlen, cc -= rowlen; - return (cc == 0); -} - -/* - * Decode a tile of pixels. We break it into rows to - * maintain synchrony with the encode algorithm, which - * is row by row. - */ -static int -LogLuvDecodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - tmsize_t rowlen = TIFFTileRowSize(tif); - - assert(cc%rowlen == 0); - while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) - bp += rowlen, cc -= rowlen; - return (cc == 0); -} - -/* - * Encode a row of 16-bit pixels. - */ -static int -LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - LogLuvState* sp = EncoderState(tif); - int shft; - tmsize_t i; - tmsize_t j; - tmsize_t npixels; - uint8* op; - int16* tp; - int16 b; - tmsize_t occ; - int rc=0, mask; - tmsize_t beg; - - assert(s == 0); - assert(sp != NULL); - npixels = cc / sp->pixel_size; - - if (sp->user_datafmt == SGILOGDATAFMT_16BIT) - tp = (int16*) bp; - else { - tp = (int16*) sp->tbuf; - assert(sp->tbuflen >= npixels); - (*sp->tfunc)(sp, bp, npixels); - } - /* compress each byte string */ - op = tif->tif_rawcp; - occ = tif->tif_rawdatasize - tif->tif_rawcc; - for (shft = 2*8; (shft -= 8) >= 0; ) - for (i = 0; i < npixels; i += rc) { - if (occ < 4) { - tif->tif_rawcp = op; - tif->tif_rawcc = tif->tif_rawdatasize - occ; - if (!TIFFFlushData1(tif)) - return (-1); - op = tif->tif_rawcp; - occ = tif->tif_rawdatasize - tif->tif_rawcc; - } - mask = 0xff << shft; /* find next run */ - for (beg = i; beg < npixels; beg += rc) { - b = (int16) (tp[beg] & mask); - rc = 1; - while (rc < 127+2 && beg+rc < npixels && - (tp[beg+rc] & mask) == b) - rc++; - if (rc >= MINRUN) - break; /* long enough */ - } - if (beg-i > 1 && beg-i < MINRUN) { - b = (int16) (tp[i] & mask);/*check short run */ - j = i+1; - while ((tp[j++] & mask) == b) - if (j == beg) { - *op++ = (uint8)(128-2+j-i); - *op++ = (uint8)(b >> shft); - occ -= 2; - i = beg; - break; - } - } - while (i < beg) { /* write out non-run */ - if ((j = beg-i) > 127) j = 127; - if (occ < j+3) { - tif->tif_rawcp = op; - tif->tif_rawcc = tif->tif_rawdatasize - occ; - if (!TIFFFlushData1(tif)) - return (-1); - op = tif->tif_rawcp; - occ = tif->tif_rawdatasize - tif->tif_rawcc; - } - *op++ = (uint8) j; occ--; - while (j--) { - *op++ = (uint8) (tp[i++] >> shft & 0xff); - occ--; - } - } - if (rc >= MINRUN) { /* write out run */ - *op++ = (uint8) (128-2+rc); - *op++ = (uint8) (tp[beg] >> shft & 0xff); - occ -= 2; - } else - rc = 0; - } - tif->tif_rawcp = op; - tif->tif_rawcc = tif->tif_rawdatasize - occ; - - return (1); -} - -/* - * Encode a row of 24-bit pixels. - */ -static int -LogLuvEncode24(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - LogLuvState* sp = EncoderState(tif); - tmsize_t i; - tmsize_t npixels; - tmsize_t occ; - uint8* op; - uint32* tp; - - assert(s == 0); - assert(sp != NULL); - npixels = cc / sp->pixel_size; - - if (sp->user_datafmt == SGILOGDATAFMT_RAW) - tp = (uint32*) bp; - else { - tp = (uint32*) sp->tbuf; - assert(sp->tbuflen >= npixels); - (*sp->tfunc)(sp, bp, npixels); - } - /* write out encoded pixels */ - op = tif->tif_rawcp; - occ = tif->tif_rawdatasize - tif->tif_rawcc; - for (i = npixels; i--; ) { - if (occ < 3) { - tif->tif_rawcp = op; - tif->tif_rawcc = tif->tif_rawdatasize - occ; - if (!TIFFFlushData1(tif)) - return (-1); - op = tif->tif_rawcp; - occ = tif->tif_rawdatasize - tif->tif_rawcc; - } - *op++ = (uint8)(*tp >> 16); - *op++ = (uint8)(*tp >> 8 & 0xff); - *op++ = (uint8)(*tp++ & 0xff); - occ -= 3; - } - tif->tif_rawcp = op; - tif->tif_rawcc = tif->tif_rawdatasize - occ; - - return (1); -} - -/* - * Encode a row of 32-bit pixels. - */ -static int -LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - LogLuvState* sp = EncoderState(tif); - int shft; - tmsize_t i; - tmsize_t j; - tmsize_t npixels; - uint8* op; - uint32* tp; - uint32 b; - tmsize_t occ; - int rc=0, mask; - tmsize_t beg; - - assert(s == 0); - assert(sp != NULL); - - npixels = cc / sp->pixel_size; - - if (sp->user_datafmt == SGILOGDATAFMT_RAW) - tp = (uint32*) bp; - else { - tp = (uint32*) sp->tbuf; - assert(sp->tbuflen >= npixels); - (*sp->tfunc)(sp, bp, npixels); - } - /* compress each byte string */ - op = tif->tif_rawcp; - occ = tif->tif_rawdatasize - tif->tif_rawcc; - for (shft = 4*8; (shft -= 8) >= 0; ) - for (i = 0; i < npixels; i += rc) { - if (occ < 4) { - tif->tif_rawcp = op; - tif->tif_rawcc = tif->tif_rawdatasize - occ; - if (!TIFFFlushData1(tif)) - return (-1); - op = tif->tif_rawcp; - occ = tif->tif_rawdatasize - tif->tif_rawcc; - } - mask = 0xff << shft; /* find next run */ - for (beg = i; beg < npixels; beg += rc) { - b = tp[beg] & mask; - rc = 1; - while (rc < 127+2 && beg+rc < npixels && - (tp[beg+rc] & mask) == b) - rc++; - if (rc >= MINRUN) - break; /* long enough */ - } - if (beg-i > 1 && beg-i < MINRUN) { - b = tp[i] & mask; /* check short run */ - j = i+1; - while ((tp[j++] & mask) == b) - if (j == beg) { - *op++ = (uint8)(128-2+j-i); - *op++ = (uint8)(b >> shft); - occ -= 2; - i = beg; - break; - } - } - while (i < beg) { /* write out non-run */ - if ((j = beg-i) > 127) j = 127; - if (occ < j+3) { - tif->tif_rawcp = op; - tif->tif_rawcc = tif->tif_rawdatasize - occ; - if (!TIFFFlushData1(tif)) - return (-1); - op = tif->tif_rawcp; - occ = tif->tif_rawdatasize - tif->tif_rawcc; - } - *op++ = (uint8) j; occ--; - while (j--) { - *op++ = (uint8)(tp[i++] >> shft & 0xff); - occ--; - } - } - if (rc >= MINRUN) { /* write out run */ - *op++ = (uint8) (128-2+rc); - *op++ = (uint8)(tp[beg] >> shft & 0xff); - occ -= 2; - } else - rc = 0; - } - tif->tif_rawcp = op; - tif->tif_rawcc = tif->tif_rawdatasize - occ; - - return (1); -} - -/* - * Encode a strip of pixels. We break it into rows to - * avoid encoding runs across row boundaries. - */ -static int -LogLuvEncodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - tmsize_t rowlen = TIFFScanlineSize(tif); - - assert(cc%rowlen == 0); - while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) - bp += rowlen, cc -= rowlen; - return (cc == 0); -} - -/* - * Encode a tile of pixels. We break it into rows to - * avoid encoding runs across row boundaries. - */ -static int -LogLuvEncodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - tmsize_t rowlen = TIFFTileRowSize(tif); - - assert(cc%rowlen == 0); - while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) - bp += rowlen, cc -= rowlen; - return (cc == 0); -} - -/* - * Encode/Decode functions for converting to and from user formats. - */ - -#include "uvcode.h" - -#ifndef UVSCALE -#define U_NEU 0.210526316 -#define V_NEU 0.473684211 -#define UVSCALE 410. -#endif - -#ifndef M_LN2 -#define M_LN2 0.69314718055994530942 -#endif -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif -#define log2(x) ((1./M_LN2)*log(x)) -#define exp2(x) exp(M_LN2*(x)) - -#define itrunc(x,m) ((m)==SGILOGENCODE_NODITHER ? \ - (int)(x) : \ - (int)((x) + rand()*(1./RAND_MAX) - .5)) - -#if !LOGLUV_PUBLIC -static -#endif -double -LogL16toY(int p16) /* compute luminance from 16-bit LogL */ -{ - int Le = p16 & 0x7fff; - double Y; - - if (!Le) - return (0.); - Y = exp(M_LN2/256.*(Le+.5) - M_LN2*64.); - return (!(p16 & 0x8000) ? Y : -Y); -} - -#if !LOGLUV_PUBLIC -static -#endif -int -LogL16fromY(double Y, int em) /* get 16-bit LogL from Y */ -{ - if (Y >= 1.8371976e19) - return (0x7fff); - if (Y <= -1.8371976e19) - return (0xffff); - if (Y > 5.4136769e-20) - return itrunc(256.*(log2(Y) + 64.), em); - if (Y < -5.4136769e-20) - return (~0x7fff | itrunc(256.*(log2(-Y) + 64.), em)); - return (0); -} - -static void -L16toY(LogLuvState* sp, uint8* op, tmsize_t n) -{ - int16* l16 = (int16*) sp->tbuf; - float* yp = (float*) op; - - while (n-- > 0) - *yp++ = (float)LogL16toY(*l16++); -} - -static void -L16toGry(LogLuvState* sp, uint8* op, tmsize_t n) -{ - int16* l16 = (int16*) sp->tbuf; - uint8* gp = (uint8*) op; - - while (n-- > 0) { - double Y = LogL16toY(*l16++); - *gp++ = (uint8) ((Y <= 0.) ? 0 : (Y >= 1.) ? 255 : (int)(256.*sqrt(Y))); - } -} - -static void -L16fromY(LogLuvState* sp, uint8* op, tmsize_t n) -{ - int16* l16 = (int16*) sp->tbuf; - float* yp = (float*) op; - - while (n-- > 0) - *l16++ = (int16) (LogL16fromY(*yp++, sp->encode_meth)); -} - -#if !LOGLUV_PUBLIC -static -#endif -void -XYZtoRGB24(float xyz[3], uint8 rgb[3]) -{ - double r, g, b; - /* assume CCIR-709 primaries */ - r = 2.690*xyz[0] + -1.276*xyz[1] + -0.414*xyz[2]; - g = -1.022*xyz[0] + 1.978*xyz[1] + 0.044*xyz[2]; - b = 0.061*xyz[0] + -0.224*xyz[1] + 1.163*xyz[2]; - /* assume 2.0 gamma for speed */ - /* could use integer sqrt approx., but this is probably faster */ - rgb[0] = (uint8)((r<=0.) ? 0 : (r >= 1.) ? 255 : (int)(256.*sqrt(r))); - rgb[1] = (uint8)((g<=0.) ? 0 : (g >= 1.) ? 255 : (int)(256.*sqrt(g))); - rgb[2] = (uint8)((b<=0.) ? 0 : (b >= 1.) ? 255 : (int)(256.*sqrt(b))); -} - -#if !LOGLUV_PUBLIC -static -#endif -double -LogL10toY(int p10) /* compute luminance from 10-bit LogL */ -{ - if (p10 == 0) - return (0.); - return (exp(M_LN2/64.*(p10+.5) - M_LN2*12.)); -} - -#if !LOGLUV_PUBLIC -static -#endif -int -LogL10fromY(double Y, int em) /* get 10-bit LogL from Y */ -{ - if (Y >= 15.742) - return (0x3ff); - else if (Y <= .00024283) - return (0); - else - return itrunc(64.*(log2(Y) + 12.), em); -} - -#define NANGLES 100 -#define uv2ang(u, v) ( (NANGLES*.499999999/M_PI) \ - * atan2((v)-V_NEU,(u)-U_NEU) + .5*NANGLES ) - -static int -oog_encode(double u, double v) /* encode out-of-gamut chroma */ -{ - static int oog_table[NANGLES]; - static int initialized = 0; - register int i; - - if (!initialized) { /* set up perimeter table */ - double eps[NANGLES], ua, va, ang, epsa; - int ui, vi, ustep; - for (i = NANGLES; i--; ) - eps[i] = 2.; - for (vi = UV_NVS; vi--; ) { - va = UV_VSTART + (vi+.5)*UV_SQSIZ; - ustep = uv_row[vi].nus-1; - if (vi == UV_NVS-1 || vi == 0 || ustep <= 0) - ustep = 1; - for (ui = uv_row[vi].nus-1; ui >= 0; ui -= ustep) { - ua = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ; - ang = uv2ang(ua, va); - i = (int) ang; - epsa = fabs(ang - (i+.5)); - if (epsa < eps[i]) { - oog_table[i] = uv_row[vi].ncum + ui; - eps[i] = epsa; - } - } - } - for (i = NANGLES; i--; ) /* fill any holes */ - if (eps[i] > 1.5) { - int i1, i2; - for (i1 = 1; i1 < NANGLES/2; i1++) - if (eps[(i+i1)%NANGLES] < 1.5) - break; - for (i2 = 1; i2 < NANGLES/2; i2++) - if (eps[(i+NANGLES-i2)%NANGLES] < 1.5) - break; - if (i1 < i2) - oog_table[i] = - oog_table[(i+i1)%NANGLES]; - else - oog_table[i] = - oog_table[(i+NANGLES-i2)%NANGLES]; - } - initialized = 1; - } - i = (int) uv2ang(u, v); /* look up hue angle */ - return (oog_table[i]); -} - -#undef uv2ang -#undef NANGLES - -#if !LOGLUV_PUBLIC -static -#endif -int -uv_encode(double u, double v, int em) /* encode (u',v') coordinates */ -{ - register int vi, ui; - - if (v < UV_VSTART) - return oog_encode(u, v); - vi = itrunc((v - UV_VSTART)*(1./UV_SQSIZ), em); - if (vi >= UV_NVS) - return oog_encode(u, v); - if (u < uv_row[vi].ustart) - return oog_encode(u, v); - ui = itrunc((u - uv_row[vi].ustart)*(1./UV_SQSIZ), em); - if (ui >= uv_row[vi].nus) - return oog_encode(u, v); - - return (uv_row[vi].ncum + ui); -} - -#if !LOGLUV_PUBLIC -static -#endif -int -uv_decode(double *up, double *vp, int c) /* decode (u',v') index */ -{ - int upper, lower; - register int ui, vi; - - if (c < 0 || c >= UV_NDIVS) - return (-1); - lower = 0; /* binary search */ - upper = UV_NVS; - while (upper - lower > 1) { - vi = (lower + upper) >> 1; - ui = c - uv_row[vi].ncum; - if (ui > 0) - lower = vi; - else if (ui < 0) - upper = vi; - else { - lower = vi; - break; - } - } - vi = lower; - ui = c - uv_row[vi].ncum; - *up = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ; - *vp = UV_VSTART + (vi+.5)*UV_SQSIZ; - return (0); -} - -#if !LOGLUV_PUBLIC -static -#endif -void -LogLuv24toXYZ(uint32 p, float XYZ[3]) -{ - int Ce; - double L, u, v, s, x, y; - /* decode luminance */ - L = LogL10toY(p>>14 & 0x3ff); - if (L <= 0.) { - XYZ[0] = XYZ[1] = XYZ[2] = 0.; - return; - } - /* decode color */ - Ce = p & 0x3fff; - if (uv_decode(&u, &v, Ce) < 0) { - u = U_NEU; v = V_NEU; - } - s = 1./(6.*u - 16.*v + 12.); - x = 9.*u * s; - y = 4.*v * s; - /* convert to XYZ */ - XYZ[0] = (float)(x/y * L); - XYZ[1] = (float)L; - XYZ[2] = (float)((1.-x-y)/y * L); -} - -#if !LOGLUV_PUBLIC -static -#endif -uint32 -LogLuv24fromXYZ(float XYZ[3], int em) -{ - int Le, Ce; - double u, v, s; - /* encode luminance */ - Le = LogL10fromY(XYZ[1], em); - /* encode color */ - s = XYZ[0] + 15.*XYZ[1] + 3.*XYZ[2]; - if (!Le || s <= 0.) { - u = U_NEU; - v = V_NEU; - } else { - u = 4.*XYZ[0] / s; - v = 9.*XYZ[1] / s; - } - Ce = uv_encode(u, v, em); - if (Ce < 0) /* never happens */ - Ce = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER); - /* combine encodings */ - return (Le << 14 | Ce); -} - -static void -Luv24toXYZ(LogLuvState* sp, uint8* op, tmsize_t n) -{ - uint32* luv = (uint32*) sp->tbuf; - float* xyz = (float*) op; - - while (n-- > 0) { - LogLuv24toXYZ(*luv, xyz); - xyz += 3; - luv++; - } -} - -static void -Luv24toLuv48(LogLuvState* sp, uint8* op, tmsize_t n) -{ - uint32* luv = (uint32*) sp->tbuf; - int16* luv3 = (int16*) op; - - while (n-- > 0) { - double u, v; - - *luv3++ = (int16)((*luv >> 12 & 0xffd) + 13314); - if (uv_decode(&u, &v, *luv&0x3fff) < 0) { - u = U_NEU; - v = V_NEU; - } - *luv3++ = (int16)(u * (1L<<15)); - *luv3++ = (int16)(v * (1L<<15)); - luv++; - } -} - -static void -Luv24toRGB(LogLuvState* sp, uint8* op, tmsize_t n) -{ - uint32* luv = (uint32*) sp->tbuf; - uint8* rgb = (uint8*) op; - - while (n-- > 0) { - float xyz[3]; - - LogLuv24toXYZ(*luv++, xyz); - XYZtoRGB24(xyz, rgb); - rgb += 3; - } -} - -static void -Luv24fromXYZ(LogLuvState* sp, uint8* op, tmsize_t n) -{ - uint32* luv = (uint32*) sp->tbuf; - float* xyz = (float*) op; - - while (n-- > 0) { - *luv++ = LogLuv24fromXYZ(xyz, sp->encode_meth); - xyz += 3; - } -} - -static void -Luv24fromLuv48(LogLuvState* sp, uint8* op, tmsize_t n) -{ - uint32* luv = (uint32*) sp->tbuf; - int16* luv3 = (int16*) op; - - while (n-- > 0) { - int Le, Ce; - - if (luv3[0] <= 0) - Le = 0; - else if (luv3[0] >= (1<<12)+3314) - Le = (1<<10) - 1; - else if (sp->encode_meth == SGILOGENCODE_NODITHER) - Le = (luv3[0]-3314) >> 2; - else - Le = itrunc(.25*(luv3[0]-3314.), sp->encode_meth); - - Ce = uv_encode((luv3[1]+.5)/(1<<15), (luv3[2]+.5)/(1<<15), - sp->encode_meth); - if (Ce < 0) /* never happens */ - Ce = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER); - *luv++ = (uint32)Le << 14 | Ce; - luv3 += 3; - } -} - -#if !LOGLUV_PUBLIC -static -#endif -void -LogLuv32toXYZ(uint32 p, float XYZ[3]) -{ - double L, u, v, s, x, y; - /* decode luminance */ - L = LogL16toY((int)p >> 16); - if (L <= 0.) { - XYZ[0] = XYZ[1] = XYZ[2] = 0.; - return; - } - /* decode color */ - u = 1./UVSCALE * ((p>>8 & 0xff) + .5); - v = 1./UVSCALE * ((p & 0xff) + .5); - s = 1./(6.*u - 16.*v + 12.); - x = 9.*u * s; - y = 4.*v * s; - /* convert to XYZ */ - XYZ[0] = (float)(x/y * L); - XYZ[1] = (float)L; - XYZ[2] = (float)((1.-x-y)/y * L); -} - -#if !LOGLUV_PUBLIC -static -#endif -uint32 -LogLuv32fromXYZ(float XYZ[3], int em) -{ - unsigned int Le, ue, ve; - double u, v, s; - /* encode luminance */ - Le = (unsigned int)LogL16fromY(XYZ[1], em); - /* encode color */ - s = XYZ[0] + 15.*XYZ[1] + 3.*XYZ[2]; - if (!Le || s <= 0.) { - u = U_NEU; - v = V_NEU; - } else { - u = 4.*XYZ[0] / s; - v = 9.*XYZ[1] / s; - } - if (u <= 0.) ue = 0; - else ue = itrunc(UVSCALE*u, em); - if (ue > 255) ue = 255; - if (v <= 0.) ve = 0; - else ve = itrunc(UVSCALE*v, em); - if (ve > 255) ve = 255; - /* combine encodings */ - return (Le << 16 | ue << 8 | ve); -} - -static void -Luv32toXYZ(LogLuvState* sp, uint8* op, tmsize_t n) -{ - uint32* luv = (uint32*) sp->tbuf; - float* xyz = (float*) op; - - while (n-- > 0) { - LogLuv32toXYZ(*luv++, xyz); - xyz += 3; - } -} - -static void -Luv32toLuv48(LogLuvState* sp, uint8* op, tmsize_t n) -{ - uint32* luv = (uint32*) sp->tbuf; - int16* luv3 = (int16*) op; - - while (n-- > 0) { - double u, v; - - *luv3++ = (int16)(*luv >> 16); - u = 1./UVSCALE * ((*luv>>8 & 0xff) + .5); - v = 1./UVSCALE * ((*luv & 0xff) + .5); - *luv3++ = (int16)(u * (1L<<15)); - *luv3++ = (int16)(v * (1L<<15)); - luv++; - } -} - -static void -Luv32toRGB(LogLuvState* sp, uint8* op, tmsize_t n) -{ - uint32* luv = (uint32*) sp->tbuf; - uint8* rgb = (uint8*) op; - - while (n-- > 0) { - float xyz[3]; - - LogLuv32toXYZ(*luv++, xyz); - XYZtoRGB24(xyz, rgb); - rgb += 3; - } -} - -static void -Luv32fromXYZ(LogLuvState* sp, uint8* op, tmsize_t n) -{ - uint32* luv = (uint32*) sp->tbuf; - float* xyz = (float*) op; - - while (n-- > 0) { - *luv++ = LogLuv32fromXYZ(xyz, sp->encode_meth); - xyz += 3; - } -} - -static void -Luv32fromLuv48(LogLuvState* sp, uint8* op, tmsize_t n) -{ - uint32* luv = (uint32*) sp->tbuf; - int16* luv3 = (int16*) op; - - if (sp->encode_meth == SGILOGENCODE_NODITHER) { - while (n-- > 0) { - *luv++ = (uint32)luv3[0] << 16 | - (luv3[1]*(uint32)(UVSCALE+.5) >> 7 & 0xff00) | - (luv3[2]*(uint32)(UVSCALE+.5) >> 15 & 0xff); - luv3 += 3; - } - return; - } - while (n-- > 0) { - *luv++ = (uint32)luv3[0] << 16 | - (itrunc(luv3[1]*(UVSCALE/(1<<15)), sp->encode_meth) << 8 & 0xff00) | - (itrunc(luv3[2]*(UVSCALE/(1<<15)), sp->encode_meth) & 0xff); - luv3 += 3; - } -} - -static void -_logLuvNop(LogLuvState* sp, uint8* op, tmsize_t n) -{ - (void) sp; (void) op; (void) n; -} - -static int -LogL16GuessDataFmt(TIFFDirectory *td) -{ -#define PACK(s,b,f) (((b)<<6)|((s)<<3)|(f)) - switch (PACK(td->td_samplesperpixel, td->td_bitspersample, td->td_sampleformat)) { - case PACK(1, 32, SAMPLEFORMAT_IEEEFP): - return (SGILOGDATAFMT_FLOAT); - case PACK(1, 16, SAMPLEFORMAT_VOID): - case PACK(1, 16, SAMPLEFORMAT_INT): - case PACK(1, 16, SAMPLEFORMAT_UINT): - return (SGILOGDATAFMT_16BIT); - case PACK(1, 8, SAMPLEFORMAT_VOID): - case PACK(1, 8, SAMPLEFORMAT_UINT): - return (SGILOGDATAFMT_8BIT); - } -#undef PACK - return (SGILOGDATAFMT_UNKNOWN); -} - -static tmsize_t -multiply_ms(tmsize_t m1, tmsize_t m2) -{ - tmsize_t bytes = m1 * m2; - - if (m1 && bytes / m1 != m2) - bytes = 0; - - return bytes; -} - -static int -LogL16InitState(TIFF* tif) -{ - static const char module[] = "LogL16InitState"; - TIFFDirectory *td = &tif->tif_dir; - LogLuvState* sp = DecoderState(tif); - - assert(sp != NULL); - assert(td->td_photometric == PHOTOMETRIC_LOGL); - - /* for some reason, we can't do this in TIFFInitLogL16 */ - if (sp->user_datafmt == SGILOGDATAFMT_UNKNOWN) - sp->user_datafmt = LogL16GuessDataFmt(td); - switch (sp->user_datafmt) { - case SGILOGDATAFMT_FLOAT: - sp->pixel_size = sizeof (float); - break; - case SGILOGDATAFMT_16BIT: - sp->pixel_size = sizeof (int16); - break; - case SGILOGDATAFMT_8BIT: - sp->pixel_size = sizeof (uint8); - break; - default: - TIFFErrorExt(tif->tif_clientdata, module, - "No support for converting user data format to LogL"); - return (0); - } - if( isTiled(tif) ) - sp->tbuflen = multiply_ms(td->td_tilewidth, td->td_tilelength); - else - sp->tbuflen = multiply_ms(td->td_imagewidth, td->td_rowsperstrip); - if (multiply_ms(sp->tbuflen, sizeof (int16)) == 0 || - (sp->tbuf = (uint8*) _TIFFmalloc(sp->tbuflen * sizeof (int16))) == NULL) { - TIFFErrorExt(tif->tif_clientdata, module, "No space for SGILog translation buffer"); - return (0); - } - return (1); -} - -static int -LogLuvGuessDataFmt(TIFFDirectory *td) -{ - int guess; - - /* - * If the user didn't tell us their datafmt, - * take our best guess from the bitspersample. - */ -#define PACK(a,b) (((a)<<3)|(b)) - switch (PACK(td->td_bitspersample, td->td_sampleformat)) { - case PACK(32, SAMPLEFORMAT_IEEEFP): - guess = SGILOGDATAFMT_FLOAT; - break; - case PACK(32, SAMPLEFORMAT_VOID): - case PACK(32, SAMPLEFORMAT_UINT): - case PACK(32, SAMPLEFORMAT_INT): - guess = SGILOGDATAFMT_RAW; - break; - case PACK(16, SAMPLEFORMAT_VOID): - case PACK(16, SAMPLEFORMAT_INT): - case PACK(16, SAMPLEFORMAT_UINT): - guess = SGILOGDATAFMT_16BIT; - break; - case PACK( 8, SAMPLEFORMAT_VOID): - case PACK( 8, SAMPLEFORMAT_UINT): - guess = SGILOGDATAFMT_8BIT; - break; - default: - guess = SGILOGDATAFMT_UNKNOWN; - break; -#undef PACK - } - /* - * Double-check samples per pixel. - */ - switch (td->td_samplesperpixel) { - case 1: - if (guess != SGILOGDATAFMT_RAW) - guess = SGILOGDATAFMT_UNKNOWN; - break; - case 3: - if (guess == SGILOGDATAFMT_RAW) - guess = SGILOGDATAFMT_UNKNOWN; - break; - default: - guess = SGILOGDATAFMT_UNKNOWN; - break; - } - return (guess); -} - -static int -LogLuvInitState(TIFF* tif) -{ - static const char module[] = "LogLuvInitState"; - TIFFDirectory* td = &tif->tif_dir; - LogLuvState* sp = DecoderState(tif); - - assert(sp != NULL); - assert(td->td_photometric == PHOTOMETRIC_LOGLUV); - - /* for some reason, we can't do this in TIFFInitLogLuv */ - if (td->td_planarconfig != PLANARCONFIG_CONTIG) { - TIFFErrorExt(tif->tif_clientdata, module, - "SGILog compression cannot handle non-contiguous data"); - return (0); - } - if (sp->user_datafmt == SGILOGDATAFMT_UNKNOWN) - sp->user_datafmt = LogLuvGuessDataFmt(td); - switch (sp->user_datafmt) { - case SGILOGDATAFMT_FLOAT: - sp->pixel_size = 3*sizeof (float); - break; - case SGILOGDATAFMT_16BIT: - sp->pixel_size = 3*sizeof (int16); - break; - case SGILOGDATAFMT_RAW: - sp->pixel_size = sizeof (uint32); - break; - case SGILOGDATAFMT_8BIT: - sp->pixel_size = 3*sizeof (uint8); - break; - default: - TIFFErrorExt(tif->tif_clientdata, module, - "No support for converting user data format to LogLuv"); - return (0); - } - if( isTiled(tif) ) - sp->tbuflen = multiply_ms(td->td_tilewidth, td->td_tilelength); - else - sp->tbuflen = multiply_ms(td->td_imagewidth, td->td_rowsperstrip); - if (multiply_ms(sp->tbuflen, sizeof (uint32)) == 0 || - (sp->tbuf = (uint8*) _TIFFmalloc(sp->tbuflen * sizeof (uint32))) == NULL) { - TIFFErrorExt(tif->tif_clientdata, module, "No space for SGILog translation buffer"); - return (0); - } - return (1); -} - -static int -LogLuvFixupTags(TIFF* tif) -{ - (void) tif; - return (1); -} - -static int -LogLuvSetupDecode(TIFF* tif) -{ - static const char module[] = "LogLuvSetupDecode"; - LogLuvState* sp = DecoderState(tif); - TIFFDirectory* td = &tif->tif_dir; - - tif->tif_postdecode = _TIFFNoPostDecode; - switch (td->td_photometric) { - case PHOTOMETRIC_LOGLUV: - if (!LogLuvInitState(tif)) - break; - if (td->td_compression == COMPRESSION_SGILOG24) { - tif->tif_decoderow = LogLuvDecode24; - switch (sp->user_datafmt) { - case SGILOGDATAFMT_FLOAT: - sp->tfunc = Luv24toXYZ; - break; - case SGILOGDATAFMT_16BIT: - sp->tfunc = Luv24toLuv48; - break; - case SGILOGDATAFMT_8BIT: - sp->tfunc = Luv24toRGB; - break; - } - } else { - tif->tif_decoderow = LogLuvDecode32; - switch (sp->user_datafmt) { - case SGILOGDATAFMT_FLOAT: - sp->tfunc = Luv32toXYZ; - break; - case SGILOGDATAFMT_16BIT: - sp->tfunc = Luv32toLuv48; - break; - case SGILOGDATAFMT_8BIT: - sp->tfunc = Luv32toRGB; - break; - } - } - return (1); - case PHOTOMETRIC_LOGL: - if (!LogL16InitState(tif)) - break; - tif->tif_decoderow = LogL16Decode; - switch (sp->user_datafmt) { - case SGILOGDATAFMT_FLOAT: - sp->tfunc = L16toY; - break; - case SGILOGDATAFMT_8BIT: - sp->tfunc = L16toGry; - break; - } - return (1); - default: - TIFFErrorExt(tif->tif_clientdata, module, - "Inappropriate photometric interpretation %d for SGILog compression; %s", - td->td_photometric, "must be either LogLUV or LogL"); - break; - } - return (0); -} - -static int -LogLuvSetupEncode(TIFF* tif) -{ - static const char module[] = "LogLuvSetupEncode"; - LogLuvState* sp = EncoderState(tif); - TIFFDirectory* td = &tif->tif_dir; - - switch (td->td_photometric) { - case PHOTOMETRIC_LOGLUV: - if (!LogLuvInitState(tif)) - break; - if (td->td_compression == COMPRESSION_SGILOG24) { - tif->tif_encoderow = LogLuvEncode24; - switch (sp->user_datafmt) { - case SGILOGDATAFMT_FLOAT: - sp->tfunc = Luv24fromXYZ; - break; - case SGILOGDATAFMT_16BIT: - sp->tfunc = Luv24fromLuv48; - break; - case SGILOGDATAFMT_RAW: - break; - default: - goto notsupported; - } - } else { - tif->tif_encoderow = LogLuvEncode32; - switch (sp->user_datafmt) { - case SGILOGDATAFMT_FLOAT: - sp->tfunc = Luv32fromXYZ; - break; - case SGILOGDATAFMT_16BIT: - sp->tfunc = Luv32fromLuv48; - break; - case SGILOGDATAFMT_RAW: - break; - default: - goto notsupported; - } - } - break; - case PHOTOMETRIC_LOGL: - if (!LogL16InitState(tif)) - break; - tif->tif_encoderow = LogL16Encode; - switch (sp->user_datafmt) { - case SGILOGDATAFMT_FLOAT: - sp->tfunc = L16fromY; - break; - case SGILOGDATAFMT_16BIT: - break; - default: - goto notsupported; - } - break; - default: - TIFFErrorExt(tif->tif_clientdata, module, - "Inappropriate photometric interpretation %d for SGILog compression; %s", - td->td_photometric, "must be either LogLUV or LogL"); - break; - } - return (1); -notsupported: - TIFFErrorExt(tif->tif_clientdata, module, - "SGILog compression supported only for %s, or raw data", - td->td_photometric == PHOTOMETRIC_LOGL ? "Y, L" : "XYZ, Luv"); - return (0); -} - -static void -LogLuvClose(TIFF* tif) -{ - TIFFDirectory *td = &tif->tif_dir; - - /* - * For consistency, we always want to write out the same - * bitspersample and sampleformat for our TIFF file, - * regardless of the data format being used by the application. - * Since this routine is called after tags have been set but - * before they have been recorded in the file, we reset them here. - */ - td->td_samplesperpixel = - (td->td_photometric == PHOTOMETRIC_LOGL) ? 1 : 3; - td->td_bitspersample = 16; - td->td_sampleformat = SAMPLEFORMAT_INT; -} - -static void -LogLuvCleanup(TIFF* tif) -{ - LogLuvState* sp = (LogLuvState *)tif->tif_data; - - assert(sp != 0); - - tif->tif_tagmethods.vgetfield = sp->vgetparent; - tif->tif_tagmethods.vsetfield = sp->vsetparent; - - if (sp->tbuf) - _TIFFfree(sp->tbuf); - _TIFFfree(sp); - tif->tif_data = NULL; - - _TIFFSetDefaultCompressionState(tif); -} - -static int -LogLuvVSetField(TIFF* tif, uint32 tag, va_list ap) -{ - static const char module[] = "LogLuvVSetField"; - LogLuvState* sp = DecoderState(tif); - int bps, fmt; - - switch (tag) { - case TIFFTAG_SGILOGDATAFMT: - sp->user_datafmt = (int) va_arg(ap, int); - /* - * Tweak the TIFF header so that the rest of libtiff knows what - * size of data will be passed between app and library, and - * assume that the app knows what it is doing and is not - * confused by these header manipulations... - */ - switch (sp->user_datafmt) { - case SGILOGDATAFMT_FLOAT: - bps = 32, fmt = SAMPLEFORMAT_IEEEFP; - break; - case SGILOGDATAFMT_16BIT: - bps = 16, fmt = SAMPLEFORMAT_INT; - break; - case SGILOGDATAFMT_RAW: - bps = 32, fmt = SAMPLEFORMAT_UINT; - TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1); - break; - case SGILOGDATAFMT_8BIT: - bps = 8, fmt = SAMPLEFORMAT_UINT; - break; - default: - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "Unknown data format %d for LogLuv compression", - sp->user_datafmt); - return (0); - } - TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps); - TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, fmt); - /* - * Must recalculate sizes should bits/sample change. - */ - tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tmsize_t) -1; - tif->tif_scanlinesize = TIFFScanlineSize(tif); - return (1); - case TIFFTAG_SGILOGENCODE: - sp->encode_meth = (int) va_arg(ap, int); - if (sp->encode_meth != SGILOGENCODE_NODITHER && - sp->encode_meth != SGILOGENCODE_RANDITHER) { - TIFFErrorExt(tif->tif_clientdata, module, - "Unknown encoding %d for LogLuv compression", - sp->encode_meth); - return (0); - } - return (1); - default: - return (*sp->vsetparent)(tif, tag, ap); - } -} - -static int -LogLuvVGetField(TIFF* tif, uint32 tag, va_list ap) -{ - LogLuvState *sp = (LogLuvState *)tif->tif_data; - - switch (tag) { - case TIFFTAG_SGILOGDATAFMT: - *va_arg(ap, int*) = sp->user_datafmt; - return (1); - default: - return (*sp->vgetparent)(tif, tag, ap); - } -} - -static const TIFFField LogLuvFields[] = { - { TIFFTAG_SGILOGDATAFMT, 0, 0, TIFF_SHORT, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "SGILogDataFmt", NULL}, - { TIFFTAG_SGILOGENCODE, 0, 0, TIFF_SHORT, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "SGILogEncode", NULL} -}; - -int -TIFFInitSGILog(TIFF* tif, int scheme) -{ - static const char module[] = "TIFFInitSGILog"; - LogLuvState* sp; - - assert(scheme == COMPRESSION_SGILOG24 || scheme == COMPRESSION_SGILOG); - - /* - * Merge codec-specific tag information. - */ - if (!_TIFFMergeFields(tif, LogLuvFields, - TIFFArrayCount(LogLuvFields))) { - TIFFErrorExt(tif->tif_clientdata, module, - "Merging SGILog codec-specific tags failed"); - return 0; - } - - /* - * Allocate state block so tag methods have storage to record values. - */ - tif->tif_data = (uint8*) _TIFFmalloc(sizeof (LogLuvState)); - if (tif->tif_data == NULL) - goto bad; - sp = (LogLuvState*) tif->tif_data; - _TIFFmemset((void*)sp, 0, sizeof (*sp)); - sp->user_datafmt = SGILOGDATAFMT_UNKNOWN; - sp->encode_meth = (scheme == COMPRESSION_SGILOG24) ? - SGILOGENCODE_RANDITHER : SGILOGENCODE_NODITHER; - sp->tfunc = _logLuvNop; - - /* - * Install codec methods. - * NB: tif_decoderow & tif_encoderow are filled - * in at setup time. - */ - tif->tif_fixuptags = LogLuvFixupTags; - tif->tif_setupdecode = LogLuvSetupDecode; - tif->tif_decodestrip = LogLuvDecodeStrip; - tif->tif_decodetile = LogLuvDecodeTile; - tif->tif_setupencode = LogLuvSetupEncode; - tif->tif_encodestrip = LogLuvEncodeStrip; - tif->tif_encodetile = LogLuvEncodeTile; - tif->tif_close = LogLuvClose; - tif->tif_cleanup = LogLuvCleanup; - - /* - * Override parent get/set field methods. - */ - sp->vgetparent = tif->tif_tagmethods.vgetfield; - tif->tif_tagmethods.vgetfield = LogLuvVGetField; /* hook for codec tags */ - sp->vsetparent = tif->tif_tagmethods.vsetfield; - tif->tif_tagmethods.vsetfield = LogLuvVSetField; /* hook for codec tags */ - - return (1); -bad: - TIFFErrorExt(tif->tif_clientdata, module, - "%s: No space for LogLuv state block", tif->tif_name); - return (0); -} -#endif /* LOGLUV_SUPPORT */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_luv.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1997 Greg Ward Larson + * Copyright (c) 1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler, Greg Larson and Silicon Graphics may not be used in any + * advertising or publicity relating to the software without the specific, + * prior written permission of Sam Leffler, Greg Larson and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER, GREG LARSON OR SILICON GRAPHICS BE LIABLE + * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include "tiffiop.h" +#ifdef LOGLUV_SUPPORT + +/* + * TIFF Library. + * LogLuv compression support for high dynamic range images. + * + * Contributed by Greg Larson. + * + * LogLuv image support uses the TIFF library to store 16 or 10-bit + * log luminance values with 8 bits each of u and v or a 14-bit index. + * + * The codec can take as input and produce as output 32-bit IEEE float values + * as well as 16-bit integer values. A 16-bit luminance is interpreted + * as a sign bit followed by a 15-bit integer that is converted + * to and from a linear magnitude using the transformation: + * + * L = 2^( (Le+.5)/256 - 64 ) # real from 15-bit + * + * Le = floor( 256*(log2(L) + 64) ) # 15-bit from real + * + * The actual conversion to world luminance units in candelas per sq. meter + * requires an additional multiplier, which is stored in the TIFFTAG_STONITS. + * This value is usually set such that a reasonable exposure comes from + * clamping decoded luminances above 1 to 1 in the displayed image. + * + * The 16-bit values for u and v may be converted to real values by dividing + * each by 32768. (This allows for negative values, which aren't useful as + * far as we know, but are left in case of future improvements in human + * color vision.) + * + * Conversion from (u,v), which is actually the CIE (u',v') system for + * you color scientists, is accomplished by the following transformation: + * + * u = 4*x / (-2*x + 12*y + 3) + * v = 9*y / (-2*x + 12*y + 3) + * + * x = 9*u / (6*u - 16*v + 12) + * y = 4*v / (6*u - 16*v + 12) + * + * This process is greatly simplified by passing 32-bit IEEE floats + * for each of three CIE XYZ coordinates. The codec then takes care + * of conversion to and from LogLuv, though the application is still + * responsible for interpreting the TIFFTAG_STONITS calibration factor. + * + * By definition, a CIE XYZ vector of [1 1 1] corresponds to a neutral white + * point of (x,y)=(1/3,1/3). However, most color systems assume some other + * white point, such as D65, and an absolute color conversion to XYZ then + * to another color space with a different white point may introduce an + * unwanted color cast to the image. It is often desirable, therefore, to + * perform a white point conversion that maps the input white to [1 1 1] + * in XYZ, then record the original white point using the TIFFTAG_WHITEPOINT + * tag value. A decoder that demands absolute color calibration may use + * this white point tag to get back the original colors, but usually it + * will be ignored and the new white point will be used instead that + * matches the output color space. + * + * Pixel information is compressed into one of two basic encodings, depending + * on the setting of the compression tag, which is one of COMPRESSION_SGILOG + * or COMPRESSION_SGILOG24. For COMPRESSION_SGILOG, greyscale data is + * stored as: + * + * 1 15 + * |-+---------------| + * + * COMPRESSION_SGILOG color data is stored as: + * + * 1 15 8 8 + * |-+---------------|--------+--------| + * S Le ue ve + * + * For the 24-bit COMPRESSION_SGILOG24 color format, the data is stored as: + * + * 10 14 + * |----------|--------------| + * Le' Ce + * + * There is no sign bit in the 24-bit case, and the (u,v) chromaticity is + * encoded as an index for optimal color resolution. The 10 log bits are + * defined by the following conversions: + * + * L = 2^((Le'+.5)/64 - 12) # real from 10-bit + * + * Le' = floor( 64*(log2(L) + 12) ) # 10-bit from real + * + * The 10 bits of the smaller format may be converted into the 15 bits of + * the larger format by multiplying by 4 and adding 13314. Obviously, + * a smaller range of magnitudes is covered (about 5 orders of magnitude + * instead of 38), and the lack of a sign bit means that negative luminances + * are not allowed. (Well, they aren't allowed in the real world, either, + * but they are useful for certain types of image processing.) + * + * The desired user format is controlled by the setting the internal + * pseudo tag TIFFTAG_SGILOGDATAFMT to one of: + * SGILOGDATAFMT_FLOAT = IEEE 32-bit float XYZ values + * SGILOGDATAFMT_16BIT = 16-bit integer encodings of logL, u and v + * Raw data i/o is also possible using: + * SGILOGDATAFMT_RAW = 32-bit unsigned integer with encoded pixel + * In addition, the following decoding is provided for ease of display: + * SGILOGDATAFMT_8BIT = 8-bit default RGB gamma-corrected values + * + * For grayscale images, we provide the following data formats: + * SGILOGDATAFMT_FLOAT = IEEE 32-bit float Y values + * SGILOGDATAFMT_16BIT = 16-bit integer w/ encoded luminance + * SGILOGDATAFMT_8BIT = 8-bit gray monitor values + * + * Note that the COMPRESSION_SGILOG applies a simple run-length encoding + * scheme by separating the logL, u and v bytes for each row and applying + * a PackBits type of compression. Since the 24-bit encoding is not + * adaptive, the 32-bit color format takes less space in many cases. + * + * Further control is provided over the conversion from higher-resolution + * formats to final encoded values through the pseudo tag + * TIFFTAG_SGILOGENCODE: + * SGILOGENCODE_NODITHER = do not dither encoded values + * SGILOGENCODE_RANDITHER = apply random dithering during encoding + * + * The default value of this tag is SGILOGENCODE_NODITHER for + * COMPRESSION_SGILOG to maximize run-length encoding and + * SGILOGENCODE_RANDITHER for COMPRESSION_SGILOG24 to turn + * quantization errors into noise. + */ + +#include +#include +#include + +/* + * State block for each open TIFF + * file using LogLuv compression/decompression. + */ +typedef struct logLuvState LogLuvState; + +struct logLuvState { + int user_datafmt; /* user data format */ + int encode_meth; /* encoding method */ + int pixel_size; /* bytes per pixel */ + + uint8* tbuf; /* translation buffer */ + tmsize_t tbuflen; /* buffer length */ + void (*tfunc)(LogLuvState*, uint8*, tmsize_t); + + TIFFVSetMethod vgetparent; /* super-class method */ + TIFFVSetMethod vsetparent; /* super-class method */ +}; + +#define DecoderState(tif) ((LogLuvState*) (tif)->tif_data) +#define EncoderState(tif) ((LogLuvState*) (tif)->tif_data) + +#define SGILOGDATAFMT_UNKNOWN -1 + +#define MINRUN 4 /* minimum run length */ + +/* + * Decode a string of 16-bit gray pixels. + */ +static int +LogL16Decode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) +{ + static const char module[] = "LogL16Decode"; + LogLuvState* sp = DecoderState(tif); + int shft; + tmsize_t i; + tmsize_t npixels; + unsigned char* bp; + int16* tp; + int16 b; + tmsize_t cc; + int rc; + + assert(s == 0); + assert(sp != NULL); + + npixels = occ / sp->pixel_size; + + if (sp->user_datafmt == SGILOGDATAFMT_16BIT) + tp = (int16*) op; + else { + assert(sp->tbuflen >= npixels); + tp = (int16*) sp->tbuf; + } + _TIFFmemset((void*) tp, 0, npixels*sizeof (tp[0])); + + bp = (unsigned char*) tif->tif_rawcp; + cc = tif->tif_rawcc; + /* get each byte string */ + for (shft = 2*8; (shft -= 8) >= 0; ) { + for (i = 0; i < npixels && cc > 0; ) + if (*bp >= 128) { /* run */ + rc = *bp++ + (2-128); /* TODO: potential input buffer overrun when decoding corrupt or truncated data */ + b = (int16)(*bp++ << shft); + cc -= 2; + while (rc-- && i < npixels) + tp[i++] |= b; + } else { /* non-run */ + rc = *bp++; /* nul is noop */ + while (--cc && rc-- && i < npixels) + tp[i++] |= (int16)*bp++ << shft; + } + if (i != npixels) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + "Not enough data at row %lu (short %I64d pixels)", + (unsigned long) tif->tif_row, + (unsigned __int64) (npixels - i)); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "Not enough data at row %lu (short %llu pixels)", + (unsigned long) tif->tif_row, + (unsigned long long) (npixels - i)); +#endif + tif->tif_rawcp = (uint8*) bp; + tif->tif_rawcc = cc; + return (0); + } + } + (*sp->tfunc)(sp, op, npixels); + tif->tif_rawcp = (uint8*) bp; + tif->tif_rawcc = cc; + return (1); +} + +/* + * Decode a string of 24-bit pixels. + */ +static int +LogLuvDecode24(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) +{ + static const char module[] = "LogLuvDecode24"; + LogLuvState* sp = DecoderState(tif); + tmsize_t cc; + tmsize_t i; + tmsize_t npixels; + unsigned char* bp; + uint32* tp; + + assert(s == 0); + assert(sp != NULL); + + npixels = occ / sp->pixel_size; + + if (sp->user_datafmt == SGILOGDATAFMT_RAW) + tp = (uint32 *)op; + else { + assert(sp->tbuflen >= npixels); + tp = (uint32 *) sp->tbuf; + } + /* copy to array of uint32 */ + bp = (unsigned char*) tif->tif_rawcp; + cc = tif->tif_rawcc; + for (i = 0; i < npixels && cc > 0; i++) { + tp[i] = bp[0] << 16 | bp[1] << 8 | bp[2]; + bp += 3; + cc -= 3; + } + tif->tif_rawcp = (uint8*) bp; + tif->tif_rawcc = cc; + if (i != npixels) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + "Not enough data at row %lu (short %I64d pixels)", + (unsigned long) tif->tif_row, + (unsigned __int64) (npixels - i)); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "Not enough data at row %lu (short %llu pixels)", + (unsigned long) tif->tif_row, + (unsigned long long) (npixels - i)); +#endif + return (0); + } + (*sp->tfunc)(sp, op, npixels); + return (1); +} + +/* + * Decode a string of 32-bit pixels. + */ +static int +LogLuvDecode32(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) +{ + static const char module[] = "LogLuvDecode32"; + LogLuvState* sp; + int shft; + tmsize_t i; + tmsize_t npixels; + unsigned char* bp; + uint32* tp; + uint32 b; + tmsize_t cc; + int rc; + + assert(s == 0); + sp = DecoderState(tif); + assert(sp != NULL); + + npixels = occ / sp->pixel_size; + + if (sp->user_datafmt == SGILOGDATAFMT_RAW) + tp = (uint32*) op; + else { + assert(sp->tbuflen >= npixels); + tp = (uint32*) sp->tbuf; + } + _TIFFmemset((void*) tp, 0, npixels*sizeof (tp[0])); + + bp = (unsigned char*) tif->tif_rawcp; + cc = tif->tif_rawcc; + /* get each byte string */ + for (shft = 4*8; (shft -= 8) >= 0; ) { + for (i = 0; i < npixels && cc > 0; ) + if (*bp >= 128) { /* run */ + rc = *bp++ + (2-128); + b = (uint32)*bp++ << shft; + cc -= 2; /* TODO: potential input buffer overrun when decoding corrupt or truncated data */ + while (rc-- && i < npixels) + tp[i++] |= b; + } else { /* non-run */ + rc = *bp++; /* nul is noop */ + while (--cc && rc-- && i < npixels) + tp[i++] |= (uint32)*bp++ << shft; + } + if (i != npixels) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + "Not enough data at row %lu (short %I64d pixels)", + (unsigned long) tif->tif_row, + (unsigned __int64) (npixels - i)); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "Not enough data at row %lu (short %llu pixels)", + (unsigned long) tif->tif_row, + (unsigned long long) (npixels - i)); +#endif + tif->tif_rawcp = (uint8*) bp; + tif->tif_rawcc = cc; + return (0); + } + } + (*sp->tfunc)(sp, op, npixels); + tif->tif_rawcp = (uint8*) bp; + tif->tif_rawcc = cc; + return (1); +} + +/* + * Decode a strip of pixels. We break it into rows to + * maintain synchrony with the encode algorithm, which + * is row by row. + */ +static int +LogLuvDecodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + tmsize_t rowlen = TIFFScanlineSize(tif); + + assert(cc%rowlen == 0); + while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) + bp += rowlen, cc -= rowlen; + return (cc == 0); +} + +/* + * Decode a tile of pixels. We break it into rows to + * maintain synchrony with the encode algorithm, which + * is row by row. + */ +static int +LogLuvDecodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + tmsize_t rowlen = TIFFTileRowSize(tif); + + assert(cc%rowlen == 0); + while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) + bp += rowlen, cc -= rowlen; + return (cc == 0); +} + +/* + * Encode a row of 16-bit pixels. + */ +static int +LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + LogLuvState* sp = EncoderState(tif); + int shft; + tmsize_t i; + tmsize_t j; + tmsize_t npixels; + uint8* op; + int16* tp; + int16 b; + tmsize_t occ; + int rc=0, mask; + tmsize_t beg; + + assert(s == 0); + assert(sp != NULL); + npixels = cc / sp->pixel_size; + + if (sp->user_datafmt == SGILOGDATAFMT_16BIT) + tp = (int16*) bp; + else { + tp = (int16*) sp->tbuf; + assert(sp->tbuflen >= npixels); + (*sp->tfunc)(sp, bp, npixels); + } + /* compress each byte string */ + op = tif->tif_rawcp; + occ = tif->tif_rawdatasize - tif->tif_rawcc; + for (shft = 2*8; (shft -= 8) >= 0; ) + for (i = 0; i < npixels; i += rc) { + if (occ < 4) { + tif->tif_rawcp = op; + tif->tif_rawcc = tif->tif_rawdatasize - occ; + if (!TIFFFlushData1(tif)) + return (-1); + op = tif->tif_rawcp; + occ = tif->tif_rawdatasize - tif->tif_rawcc; + } + mask = 0xff << shft; /* find next run */ + for (beg = i; beg < npixels; beg += rc) { + b = (int16) (tp[beg] & mask); + rc = 1; + while (rc < 127+2 && beg+rc < npixels && + (tp[beg+rc] & mask) == b) + rc++; + if (rc >= MINRUN) + break; /* long enough */ + } + if (beg-i > 1 && beg-i < MINRUN) { + b = (int16) (tp[i] & mask);/*check short run */ + j = i+1; + while ((tp[j++] & mask) == b) + if (j == beg) { + *op++ = (uint8)(128-2+j-i); + *op++ = (uint8)(b >> shft); + occ -= 2; + i = beg; + break; + } + } + while (i < beg) { /* write out non-run */ + if ((j = beg-i) > 127) j = 127; + if (occ < j+3) { + tif->tif_rawcp = op; + tif->tif_rawcc = tif->tif_rawdatasize - occ; + if (!TIFFFlushData1(tif)) + return (-1); + op = tif->tif_rawcp; + occ = tif->tif_rawdatasize - tif->tif_rawcc; + } + *op++ = (uint8) j; occ--; + while (j--) { + *op++ = (uint8) (tp[i++] >> shft & 0xff); + occ--; + } + } + if (rc >= MINRUN) { /* write out run */ + *op++ = (uint8) (128-2+rc); + *op++ = (uint8) (tp[beg] >> shft & 0xff); + occ -= 2; + } else + rc = 0; + } + tif->tif_rawcp = op; + tif->tif_rawcc = tif->tif_rawdatasize - occ; + + return (1); +} + +/* + * Encode a row of 24-bit pixels. + */ +static int +LogLuvEncode24(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + LogLuvState* sp = EncoderState(tif); + tmsize_t i; + tmsize_t npixels; + tmsize_t occ; + uint8* op; + uint32* tp; + + assert(s == 0); + assert(sp != NULL); + npixels = cc / sp->pixel_size; + + if (sp->user_datafmt == SGILOGDATAFMT_RAW) + tp = (uint32*) bp; + else { + tp = (uint32*) sp->tbuf; + assert(sp->tbuflen >= npixels); + (*sp->tfunc)(sp, bp, npixels); + } + /* write out encoded pixels */ + op = tif->tif_rawcp; + occ = tif->tif_rawdatasize - tif->tif_rawcc; + for (i = npixels; i--; ) { + if (occ < 3) { + tif->tif_rawcp = op; + tif->tif_rawcc = tif->tif_rawdatasize - occ; + if (!TIFFFlushData1(tif)) + return (-1); + op = tif->tif_rawcp; + occ = tif->tif_rawdatasize - tif->tif_rawcc; + } + *op++ = (uint8)(*tp >> 16); + *op++ = (uint8)(*tp >> 8 & 0xff); + *op++ = (uint8)(*tp++ & 0xff); + occ -= 3; + } + tif->tif_rawcp = op; + tif->tif_rawcc = tif->tif_rawdatasize - occ; + + return (1); +} + +/* + * Encode a row of 32-bit pixels. + */ +static int +LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + LogLuvState* sp = EncoderState(tif); + int shft; + tmsize_t i; + tmsize_t j; + tmsize_t npixels; + uint8* op; + uint32* tp; + uint32 b; + tmsize_t occ; + int rc=0, mask; + tmsize_t beg; + + assert(s == 0); + assert(sp != NULL); + + npixels = cc / sp->pixel_size; + + if (sp->user_datafmt == SGILOGDATAFMT_RAW) + tp = (uint32*) bp; + else { + tp = (uint32*) sp->tbuf; + assert(sp->tbuflen >= npixels); + (*sp->tfunc)(sp, bp, npixels); + } + /* compress each byte string */ + op = tif->tif_rawcp; + occ = tif->tif_rawdatasize - tif->tif_rawcc; + for (shft = 4*8; (shft -= 8) >= 0; ) + for (i = 0; i < npixels; i += rc) { + if (occ < 4) { + tif->tif_rawcp = op; + tif->tif_rawcc = tif->tif_rawdatasize - occ; + if (!TIFFFlushData1(tif)) + return (-1); + op = tif->tif_rawcp; + occ = tif->tif_rawdatasize - tif->tif_rawcc; + } + mask = 0xff << shft; /* find next run */ + for (beg = i; beg < npixels; beg += rc) { + b = tp[beg] & mask; + rc = 1; + while (rc < 127+2 && beg+rc < npixels && + (tp[beg+rc] & mask) == b) + rc++; + if (rc >= MINRUN) + break; /* long enough */ + } + if (beg-i > 1 && beg-i < MINRUN) { + b = tp[i] & mask; /* check short run */ + j = i+1; + while ((tp[j++] & mask) == b) + if (j == beg) { + *op++ = (uint8)(128-2+j-i); + *op++ = (uint8)(b >> shft); + occ -= 2; + i = beg; + break; + } + } + while (i < beg) { /* write out non-run */ + if ((j = beg-i) > 127) j = 127; + if (occ < j+3) { + tif->tif_rawcp = op; + tif->tif_rawcc = tif->tif_rawdatasize - occ; + if (!TIFFFlushData1(tif)) + return (-1); + op = tif->tif_rawcp; + occ = tif->tif_rawdatasize - tif->tif_rawcc; + } + *op++ = (uint8) j; occ--; + while (j--) { + *op++ = (uint8)(tp[i++] >> shft & 0xff); + occ--; + } + } + if (rc >= MINRUN) { /* write out run */ + *op++ = (uint8) (128-2+rc); + *op++ = (uint8)(tp[beg] >> shft & 0xff); + occ -= 2; + } else + rc = 0; + } + tif->tif_rawcp = op; + tif->tif_rawcc = tif->tif_rawdatasize - occ; + + return (1); +} + +/* + * Encode a strip of pixels. We break it into rows to + * avoid encoding runs across row boundaries. + */ +static int +LogLuvEncodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + tmsize_t rowlen = TIFFScanlineSize(tif); + + assert(cc%rowlen == 0); + while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) + bp += rowlen, cc -= rowlen; + return (cc == 0); +} + +/* + * Encode a tile of pixels. We break it into rows to + * avoid encoding runs across row boundaries. + */ +static int +LogLuvEncodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + tmsize_t rowlen = TIFFTileRowSize(tif); + + assert(cc%rowlen == 0); + while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) + bp += rowlen, cc -= rowlen; + return (cc == 0); +} + +/* + * Encode/Decode functions for converting to and from user formats. + */ + +#include "uvcode.h" + +#ifndef UVSCALE +#define U_NEU 0.210526316 +#define V_NEU 0.473684211 +#define UVSCALE 410. +#endif + +#ifndef M_LN2 +#define M_LN2 0.69314718055994530942 +#endif +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif +#define log2(x) ((1./M_LN2)*log(x)) +#define exp2(x) exp(M_LN2*(x)) + +#define itrunc(x,m) ((m)==SGILOGENCODE_NODITHER ? \ + (int)(x) : \ + (int)((x) + rand()*(1./RAND_MAX) - .5)) + +#if !LOGLUV_PUBLIC +static +#endif +double +LogL16toY(int p16) /* compute luminance from 16-bit LogL */ +{ + int Le = p16 & 0x7fff; + double Y; + + if (!Le) + return (0.); + Y = exp(M_LN2/256.*(Le+.5) - M_LN2*64.); + return (!(p16 & 0x8000) ? Y : -Y); +} + +#if !LOGLUV_PUBLIC +static +#endif +int +LogL16fromY(double Y, int em) /* get 16-bit LogL from Y */ +{ + if (Y >= 1.8371976e19) + return (0x7fff); + if (Y <= -1.8371976e19) + return (0xffff); + if (Y > 5.4136769e-20) + return itrunc(256.*(log2(Y) + 64.), em); + if (Y < -5.4136769e-20) + return (~0x7fff | itrunc(256.*(log2(-Y) + 64.), em)); + return (0); +} + +static void +L16toY(LogLuvState* sp, uint8* op, tmsize_t n) +{ + int16* l16 = (int16*) sp->tbuf; + float* yp = (float*) op; + + while (n-- > 0) + *yp++ = (float)LogL16toY(*l16++); +} + +static void +L16toGry(LogLuvState* sp, uint8* op, tmsize_t n) +{ + int16* l16 = (int16*) sp->tbuf; + uint8* gp = (uint8*) op; + + while (n-- > 0) { + double Y = LogL16toY(*l16++); + *gp++ = (uint8) ((Y <= 0.) ? 0 : (Y >= 1.) ? 255 : (int)(256.*sqrt(Y))); + } +} + +static void +L16fromY(LogLuvState* sp, uint8* op, tmsize_t n) +{ + int16* l16 = (int16*) sp->tbuf; + float* yp = (float*) op; + + while (n-- > 0) + *l16++ = (int16) (LogL16fromY(*yp++, sp->encode_meth)); +} + +#if !LOGLUV_PUBLIC +static +#endif +void +XYZtoRGB24(float xyz[3], uint8 rgb[3]) +{ + double r, g, b; + /* assume CCIR-709 primaries */ + r = 2.690*xyz[0] + -1.276*xyz[1] + -0.414*xyz[2]; + g = -1.022*xyz[0] + 1.978*xyz[1] + 0.044*xyz[2]; + b = 0.061*xyz[0] + -0.224*xyz[1] + 1.163*xyz[2]; + /* assume 2.0 gamma for speed */ + /* could use integer sqrt approx., but this is probably faster */ + rgb[0] = (uint8)((r<=0.) ? 0 : (r >= 1.) ? 255 : (int)(256.*sqrt(r))); + rgb[1] = (uint8)((g<=0.) ? 0 : (g >= 1.) ? 255 : (int)(256.*sqrt(g))); + rgb[2] = (uint8)((b<=0.) ? 0 : (b >= 1.) ? 255 : (int)(256.*sqrt(b))); +} + +#if !LOGLUV_PUBLIC +static +#endif +double +LogL10toY(int p10) /* compute luminance from 10-bit LogL */ +{ + if (p10 == 0) + return (0.); + return (exp(M_LN2/64.*(p10+.5) - M_LN2*12.)); +} + +#if !LOGLUV_PUBLIC +static +#endif +int +LogL10fromY(double Y, int em) /* get 10-bit LogL from Y */ +{ + if (Y >= 15.742) + return (0x3ff); + else if (Y <= .00024283) + return (0); + else + return itrunc(64.*(log2(Y) + 12.), em); +} + +#define NANGLES 100 +#define uv2ang(u, v) ( (NANGLES*.499999999/M_PI) \ + * atan2((v)-V_NEU,(u)-U_NEU) + .5*NANGLES ) + +static int +oog_encode(double u, double v) /* encode out-of-gamut chroma */ +{ + static int oog_table[NANGLES]; + static int initialized = 0; + register int i; + + if (!initialized) { /* set up perimeter table */ + double eps[NANGLES], ua, va, ang, epsa; + int ui, vi, ustep; + for (i = NANGLES; i--; ) + eps[i] = 2.; + for (vi = UV_NVS; vi--; ) { + va = UV_VSTART + (vi+.5)*UV_SQSIZ; + ustep = uv_row[vi].nus-1; + if (vi == UV_NVS-1 || vi == 0 || ustep <= 0) + ustep = 1; + for (ui = uv_row[vi].nus-1; ui >= 0; ui -= ustep) { + ua = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ; + ang = uv2ang(ua, va); + i = (int) ang; + epsa = fabs(ang - (i+.5)); + if (epsa < eps[i]) { + oog_table[i] = uv_row[vi].ncum + ui; + eps[i] = epsa; + } + } + } + for (i = NANGLES; i--; ) /* fill any holes */ + if (eps[i] > 1.5) { + int i1, i2; + for (i1 = 1; i1 < NANGLES/2; i1++) + if (eps[(i+i1)%NANGLES] < 1.5) + break; + for (i2 = 1; i2 < NANGLES/2; i2++) + if (eps[(i+NANGLES-i2)%NANGLES] < 1.5) + break; + if (i1 < i2) + oog_table[i] = + oog_table[(i+i1)%NANGLES]; + else + oog_table[i] = + oog_table[(i+NANGLES-i2)%NANGLES]; + } + initialized = 1; + } + i = (int) uv2ang(u, v); /* look up hue angle */ + return (oog_table[i]); +} + +#undef uv2ang +#undef NANGLES + +#if !LOGLUV_PUBLIC +static +#endif +int +uv_encode(double u, double v, int em) /* encode (u',v') coordinates */ +{ + register int vi, ui; + + if (v < UV_VSTART) + return oog_encode(u, v); + vi = itrunc((v - UV_VSTART)*(1./UV_SQSIZ), em); + if (vi >= UV_NVS) + return oog_encode(u, v); + if (u < uv_row[vi].ustart) + return oog_encode(u, v); + ui = itrunc((u - uv_row[vi].ustart)*(1./UV_SQSIZ), em); + if (ui >= uv_row[vi].nus) + return oog_encode(u, v); + + return (uv_row[vi].ncum + ui); +} + +#if !LOGLUV_PUBLIC +static +#endif +int +uv_decode(double *up, double *vp, int c) /* decode (u',v') index */ +{ + int upper, lower; + register int ui, vi; + + if (c < 0 || c >= UV_NDIVS) + return (-1); + lower = 0; /* binary search */ + upper = UV_NVS; + while (upper - lower > 1) { + vi = (lower + upper) >> 1; + ui = c - uv_row[vi].ncum; + if (ui > 0) + lower = vi; + else if (ui < 0) + upper = vi; + else { + lower = vi; + break; + } + } + vi = lower; + ui = c - uv_row[vi].ncum; + *up = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ; + *vp = UV_VSTART + (vi+.5)*UV_SQSIZ; + return (0); +} + +#if !LOGLUV_PUBLIC +static +#endif +void +LogLuv24toXYZ(uint32 p, float XYZ[3]) +{ + int Ce; + double L, u, v, s, x, y; + /* decode luminance */ + L = LogL10toY(p>>14 & 0x3ff); + if (L <= 0.) { + XYZ[0] = XYZ[1] = XYZ[2] = 0.; + return; + } + /* decode color */ + Ce = p & 0x3fff; + if (uv_decode(&u, &v, Ce) < 0) { + u = U_NEU; v = V_NEU; + } + s = 1./(6.*u - 16.*v + 12.); + x = 9.*u * s; + y = 4.*v * s; + /* convert to XYZ */ + XYZ[0] = (float)(x/y * L); + XYZ[1] = (float)L; + XYZ[2] = (float)((1.-x-y)/y * L); +} + +#if !LOGLUV_PUBLIC +static +#endif +uint32 +LogLuv24fromXYZ(float XYZ[3], int em) +{ + int Le, Ce; + double u, v, s; + /* encode luminance */ + Le = LogL10fromY(XYZ[1], em); + /* encode color */ + s = XYZ[0] + 15.*XYZ[1] + 3.*XYZ[2]; + if (!Le || s <= 0.) { + u = U_NEU; + v = V_NEU; + } else { + u = 4.*XYZ[0] / s; + v = 9.*XYZ[1] / s; + } + Ce = uv_encode(u, v, em); + if (Ce < 0) /* never happens */ + Ce = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER); + /* combine encodings */ + return (Le << 14 | Ce); +} + +static void +Luv24toXYZ(LogLuvState* sp, uint8* op, tmsize_t n) +{ + uint32* luv = (uint32*) sp->tbuf; + float* xyz = (float*) op; + + while (n-- > 0) { + LogLuv24toXYZ(*luv, xyz); + xyz += 3; + luv++; + } +} + +static void +Luv24toLuv48(LogLuvState* sp, uint8* op, tmsize_t n) +{ + uint32* luv = (uint32*) sp->tbuf; + int16* luv3 = (int16*) op; + + while (n-- > 0) { + double u, v; + + *luv3++ = (int16)((*luv >> 12 & 0xffd) + 13314); + if (uv_decode(&u, &v, *luv&0x3fff) < 0) { + u = U_NEU; + v = V_NEU; + } + *luv3++ = (int16)(u * (1L<<15)); + *luv3++ = (int16)(v * (1L<<15)); + luv++; + } +} + +static void +Luv24toRGB(LogLuvState* sp, uint8* op, tmsize_t n) +{ + uint32* luv = (uint32*) sp->tbuf; + uint8* rgb = (uint8*) op; + + while (n-- > 0) { + float xyz[3]; + + LogLuv24toXYZ(*luv++, xyz); + XYZtoRGB24(xyz, rgb); + rgb += 3; + } +} + +static void +Luv24fromXYZ(LogLuvState* sp, uint8* op, tmsize_t n) +{ + uint32* luv = (uint32*) sp->tbuf; + float* xyz = (float*) op; + + while (n-- > 0) { + *luv++ = LogLuv24fromXYZ(xyz, sp->encode_meth); + xyz += 3; + } +} + +static void +Luv24fromLuv48(LogLuvState* sp, uint8* op, tmsize_t n) +{ + uint32* luv = (uint32*) sp->tbuf; + int16* luv3 = (int16*) op; + + while (n-- > 0) { + int Le, Ce; + + if (luv3[0] <= 0) + Le = 0; + else if (luv3[0] >= (1<<12)+3314) + Le = (1<<10) - 1; + else if (sp->encode_meth == SGILOGENCODE_NODITHER) + Le = (luv3[0]-3314) >> 2; + else + Le = itrunc(.25*(luv3[0]-3314.), sp->encode_meth); + + Ce = uv_encode((luv3[1]+.5)/(1<<15), (luv3[2]+.5)/(1<<15), + sp->encode_meth); + if (Ce < 0) /* never happens */ + Ce = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER); + *luv++ = (uint32)Le << 14 | Ce; + luv3 += 3; + } +} + +#if !LOGLUV_PUBLIC +static +#endif +void +LogLuv32toXYZ(uint32 p, float XYZ[3]) +{ + double L, u, v, s, x, y; + /* decode luminance */ + L = LogL16toY((int)p >> 16); + if (L <= 0.) { + XYZ[0] = XYZ[1] = XYZ[2] = 0.; + return; + } + /* decode color */ + u = 1./UVSCALE * ((p>>8 & 0xff) + .5); + v = 1./UVSCALE * ((p & 0xff) + .5); + s = 1./(6.*u - 16.*v + 12.); + x = 9.*u * s; + y = 4.*v * s; + /* convert to XYZ */ + XYZ[0] = (float)(x/y * L); + XYZ[1] = (float)L; + XYZ[2] = (float)((1.-x-y)/y * L); +} + +#if !LOGLUV_PUBLIC +static +#endif +uint32 +LogLuv32fromXYZ(float XYZ[3], int em) +{ + unsigned int Le, ue, ve; + double u, v, s; + /* encode luminance */ + Le = (unsigned int)LogL16fromY(XYZ[1], em); + /* encode color */ + s = XYZ[0] + 15.*XYZ[1] + 3.*XYZ[2]; + if (!Le || s <= 0.) { + u = U_NEU; + v = V_NEU; + } else { + u = 4.*XYZ[0] / s; + v = 9.*XYZ[1] / s; + } + if (u <= 0.) ue = 0; + else ue = itrunc(UVSCALE*u, em); + if (ue > 255) ue = 255; + if (v <= 0.) ve = 0; + else ve = itrunc(UVSCALE*v, em); + if (ve > 255) ve = 255; + /* combine encodings */ + return (Le << 16 | ue << 8 | ve); +} + +static void +Luv32toXYZ(LogLuvState* sp, uint8* op, tmsize_t n) +{ + uint32* luv = (uint32*) sp->tbuf; + float* xyz = (float*) op; + + while (n-- > 0) { + LogLuv32toXYZ(*luv++, xyz); + xyz += 3; + } +} + +static void +Luv32toLuv48(LogLuvState* sp, uint8* op, tmsize_t n) +{ + uint32* luv = (uint32*) sp->tbuf; + int16* luv3 = (int16*) op; + + while (n-- > 0) { + double u, v; + + *luv3++ = (int16)(*luv >> 16); + u = 1./UVSCALE * ((*luv>>8 & 0xff) + .5); + v = 1./UVSCALE * ((*luv & 0xff) + .5); + *luv3++ = (int16)(u * (1L<<15)); + *luv3++ = (int16)(v * (1L<<15)); + luv++; + } +} + +static void +Luv32toRGB(LogLuvState* sp, uint8* op, tmsize_t n) +{ + uint32* luv = (uint32*) sp->tbuf; + uint8* rgb = (uint8*) op; + + while (n-- > 0) { + float xyz[3]; + + LogLuv32toXYZ(*luv++, xyz); + XYZtoRGB24(xyz, rgb); + rgb += 3; + } +} + +static void +Luv32fromXYZ(LogLuvState* sp, uint8* op, tmsize_t n) +{ + uint32* luv = (uint32*) sp->tbuf; + float* xyz = (float*) op; + + while (n-- > 0) { + *luv++ = LogLuv32fromXYZ(xyz, sp->encode_meth); + xyz += 3; + } +} + +static void +Luv32fromLuv48(LogLuvState* sp, uint8* op, tmsize_t n) +{ + uint32* luv = (uint32*) sp->tbuf; + int16* luv3 = (int16*) op; + + if (sp->encode_meth == SGILOGENCODE_NODITHER) { + while (n-- > 0) { + *luv++ = (uint32)luv3[0] << 16 | + (luv3[1]*(uint32)(UVSCALE+.5) >> 7 & 0xff00) | + (luv3[2]*(uint32)(UVSCALE+.5) >> 15 & 0xff); + luv3 += 3; + } + return; + } + while (n-- > 0) { + *luv++ = (uint32)luv3[0] << 16 | + (itrunc(luv3[1]*(UVSCALE/(1<<15)), sp->encode_meth) << 8 & 0xff00) | + (itrunc(luv3[2]*(UVSCALE/(1<<15)), sp->encode_meth) & 0xff); + luv3 += 3; + } +} + +static void +_logLuvNop(LogLuvState* sp, uint8* op, tmsize_t n) +{ + (void) sp; (void) op; (void) n; +} + +static int +LogL16GuessDataFmt(TIFFDirectory *td) +{ +#define PACK(s,b,f) (((b)<<6)|((s)<<3)|(f)) + switch (PACK(td->td_samplesperpixel, td->td_bitspersample, td->td_sampleformat)) { + case PACK(1, 32, SAMPLEFORMAT_IEEEFP): + return (SGILOGDATAFMT_FLOAT); + case PACK(1, 16, SAMPLEFORMAT_VOID): + case PACK(1, 16, SAMPLEFORMAT_INT): + case PACK(1, 16, SAMPLEFORMAT_UINT): + return (SGILOGDATAFMT_16BIT); + case PACK(1, 8, SAMPLEFORMAT_VOID): + case PACK(1, 8, SAMPLEFORMAT_UINT): + return (SGILOGDATAFMT_8BIT); + } +#undef PACK + return (SGILOGDATAFMT_UNKNOWN); +} + +static tmsize_t +multiply_ms(tmsize_t m1, tmsize_t m2) +{ + tmsize_t bytes = m1 * m2; + + if (m1 && bytes / m1 != m2) + bytes = 0; + + return bytes; +} + +static int +LogL16InitState(TIFF* tif) +{ + static const char module[] = "LogL16InitState"; + TIFFDirectory *td = &tif->tif_dir; + LogLuvState* sp = DecoderState(tif); + + assert(sp != NULL); + assert(td->td_photometric == PHOTOMETRIC_LOGL); + + /* for some reason, we can't do this in TIFFInitLogL16 */ + if (sp->user_datafmt == SGILOGDATAFMT_UNKNOWN) + sp->user_datafmt = LogL16GuessDataFmt(td); + switch (sp->user_datafmt) { + case SGILOGDATAFMT_FLOAT: + sp->pixel_size = sizeof (float); + break; + case SGILOGDATAFMT_16BIT: + sp->pixel_size = sizeof (int16); + break; + case SGILOGDATAFMT_8BIT: + sp->pixel_size = sizeof (uint8); + break; + default: + TIFFErrorExt(tif->tif_clientdata, module, + "No support for converting user data format to LogL"); + return (0); + } + if( isTiled(tif) ) + sp->tbuflen = multiply_ms(td->td_tilewidth, td->td_tilelength); + else + sp->tbuflen = multiply_ms(td->td_imagewidth, td->td_rowsperstrip); + if (multiply_ms(sp->tbuflen, sizeof (int16)) == 0 || + (sp->tbuf = (uint8*) _TIFFmalloc(sp->tbuflen * sizeof (int16))) == NULL) { + TIFFErrorExt(tif->tif_clientdata, module, "No space for SGILog translation buffer"); + return (0); + } + return (1); +} + +static int +LogLuvGuessDataFmt(TIFFDirectory *td) +{ + int guess; + + /* + * If the user didn't tell us their datafmt, + * take our best guess from the bitspersample. + */ +#define PACK(a,b) (((a)<<3)|(b)) + switch (PACK(td->td_bitspersample, td->td_sampleformat)) { + case PACK(32, SAMPLEFORMAT_IEEEFP): + guess = SGILOGDATAFMT_FLOAT; + break; + case PACK(32, SAMPLEFORMAT_VOID): + case PACK(32, SAMPLEFORMAT_UINT): + case PACK(32, SAMPLEFORMAT_INT): + guess = SGILOGDATAFMT_RAW; + break; + case PACK(16, SAMPLEFORMAT_VOID): + case PACK(16, SAMPLEFORMAT_INT): + case PACK(16, SAMPLEFORMAT_UINT): + guess = SGILOGDATAFMT_16BIT; + break; + case PACK( 8, SAMPLEFORMAT_VOID): + case PACK( 8, SAMPLEFORMAT_UINT): + guess = SGILOGDATAFMT_8BIT; + break; + default: + guess = SGILOGDATAFMT_UNKNOWN; + break; +#undef PACK + } + /* + * Double-check samples per pixel. + */ + switch (td->td_samplesperpixel) { + case 1: + if (guess != SGILOGDATAFMT_RAW) + guess = SGILOGDATAFMT_UNKNOWN; + break; + case 3: + if (guess == SGILOGDATAFMT_RAW) + guess = SGILOGDATAFMT_UNKNOWN; + break; + default: + guess = SGILOGDATAFMT_UNKNOWN; + break; + } + return (guess); +} + +static int +LogLuvInitState(TIFF* tif) +{ + static const char module[] = "LogLuvInitState"; + TIFFDirectory* td = &tif->tif_dir; + LogLuvState* sp = DecoderState(tif); + + assert(sp != NULL); + assert(td->td_photometric == PHOTOMETRIC_LOGLUV); + + /* for some reason, we can't do this in TIFFInitLogLuv */ + if (td->td_planarconfig != PLANARCONFIG_CONTIG) { + TIFFErrorExt(tif->tif_clientdata, module, + "SGILog compression cannot handle non-contiguous data"); + return (0); + } + if (sp->user_datafmt == SGILOGDATAFMT_UNKNOWN) + sp->user_datafmt = LogLuvGuessDataFmt(td); + switch (sp->user_datafmt) { + case SGILOGDATAFMT_FLOAT: + sp->pixel_size = 3*sizeof (float); + break; + case SGILOGDATAFMT_16BIT: + sp->pixel_size = 3*sizeof (int16); + break; + case SGILOGDATAFMT_RAW: + sp->pixel_size = sizeof (uint32); + break; + case SGILOGDATAFMT_8BIT: + sp->pixel_size = 3*sizeof (uint8); + break; + default: + TIFFErrorExt(tif->tif_clientdata, module, + "No support for converting user data format to LogLuv"); + return (0); + } + if( isTiled(tif) ) + sp->tbuflen = multiply_ms(td->td_tilewidth, td->td_tilelength); + else + sp->tbuflen = multiply_ms(td->td_imagewidth, td->td_rowsperstrip); + if (multiply_ms(sp->tbuflen, sizeof (uint32)) == 0 || + (sp->tbuf = (uint8*) _TIFFmalloc(sp->tbuflen * sizeof (uint32))) == NULL) { + TIFFErrorExt(tif->tif_clientdata, module, "No space for SGILog translation buffer"); + return (0); + } + return (1); +} + +static int +LogLuvFixupTags(TIFF* tif) +{ + (void) tif; + return (1); +} + +static int +LogLuvSetupDecode(TIFF* tif) +{ + static const char module[] = "LogLuvSetupDecode"; + LogLuvState* sp = DecoderState(tif); + TIFFDirectory* td = &tif->tif_dir; + + tif->tif_postdecode = _TIFFNoPostDecode; + switch (td->td_photometric) { + case PHOTOMETRIC_LOGLUV: + if (!LogLuvInitState(tif)) + break; + if (td->td_compression == COMPRESSION_SGILOG24) { + tif->tif_decoderow = LogLuvDecode24; + switch (sp->user_datafmt) { + case SGILOGDATAFMT_FLOAT: + sp->tfunc = Luv24toXYZ; + break; + case SGILOGDATAFMT_16BIT: + sp->tfunc = Luv24toLuv48; + break; + case SGILOGDATAFMT_8BIT: + sp->tfunc = Luv24toRGB; + break; + } + } else { + tif->tif_decoderow = LogLuvDecode32; + switch (sp->user_datafmt) { + case SGILOGDATAFMT_FLOAT: + sp->tfunc = Luv32toXYZ; + break; + case SGILOGDATAFMT_16BIT: + sp->tfunc = Luv32toLuv48; + break; + case SGILOGDATAFMT_8BIT: + sp->tfunc = Luv32toRGB; + break; + } + } + return (1); + case PHOTOMETRIC_LOGL: + if (!LogL16InitState(tif)) + break; + tif->tif_decoderow = LogL16Decode; + switch (sp->user_datafmt) { + case SGILOGDATAFMT_FLOAT: + sp->tfunc = L16toY; + break; + case SGILOGDATAFMT_8BIT: + sp->tfunc = L16toGry; + break; + } + return (1); + default: + TIFFErrorExt(tif->tif_clientdata, module, + "Inappropriate photometric interpretation %d for SGILog compression; %s", + td->td_photometric, "must be either LogLUV or LogL"); + break; + } + return (0); +} + +static int +LogLuvSetupEncode(TIFF* tif) +{ + static const char module[] = "LogLuvSetupEncode"; + LogLuvState* sp = EncoderState(tif); + TIFFDirectory* td = &tif->tif_dir; + + switch (td->td_photometric) { + case PHOTOMETRIC_LOGLUV: + if (!LogLuvInitState(tif)) + break; + if (td->td_compression == COMPRESSION_SGILOG24) { + tif->tif_encoderow = LogLuvEncode24; + switch (sp->user_datafmt) { + case SGILOGDATAFMT_FLOAT: + sp->tfunc = Luv24fromXYZ; + break; + case SGILOGDATAFMT_16BIT: + sp->tfunc = Luv24fromLuv48; + break; + case SGILOGDATAFMT_RAW: + break; + default: + goto notsupported; + } + } else { + tif->tif_encoderow = LogLuvEncode32; + switch (sp->user_datafmt) { + case SGILOGDATAFMT_FLOAT: + sp->tfunc = Luv32fromXYZ; + break; + case SGILOGDATAFMT_16BIT: + sp->tfunc = Luv32fromLuv48; + break; + case SGILOGDATAFMT_RAW: + break; + default: + goto notsupported; + } + } + break; + case PHOTOMETRIC_LOGL: + if (!LogL16InitState(tif)) + break; + tif->tif_encoderow = LogL16Encode; + switch (sp->user_datafmt) { + case SGILOGDATAFMT_FLOAT: + sp->tfunc = L16fromY; + break; + case SGILOGDATAFMT_16BIT: + break; + default: + goto notsupported; + } + break; + default: + TIFFErrorExt(tif->tif_clientdata, module, + "Inappropriate photometric interpretation %d for SGILog compression; %s", + td->td_photometric, "must be either LogLUV or LogL"); + break; + } + return (1); +notsupported: + TIFFErrorExt(tif->tif_clientdata, module, + "SGILog compression supported only for %s, or raw data", + td->td_photometric == PHOTOMETRIC_LOGL ? "Y, L" : "XYZ, Luv"); + return (0); +} + +static void +LogLuvClose(TIFF* tif) +{ + TIFFDirectory *td = &tif->tif_dir; + + /* + * For consistency, we always want to write out the same + * bitspersample and sampleformat for our TIFF file, + * regardless of the data format being used by the application. + * Since this routine is called after tags have been set but + * before they have been recorded in the file, we reset them here. + */ + td->td_samplesperpixel = + (td->td_photometric == PHOTOMETRIC_LOGL) ? 1 : 3; + td->td_bitspersample = 16; + td->td_sampleformat = SAMPLEFORMAT_INT; +} + +static void +LogLuvCleanup(TIFF* tif) +{ + LogLuvState* sp = (LogLuvState *)tif->tif_data; + + assert(sp != 0); + + tif->tif_tagmethods.vgetfield = sp->vgetparent; + tif->tif_tagmethods.vsetfield = sp->vsetparent; + + if (sp->tbuf) + _TIFFfree(sp->tbuf); + _TIFFfree(sp); + tif->tif_data = NULL; + + _TIFFSetDefaultCompressionState(tif); +} + +static int +LogLuvVSetField(TIFF* tif, uint32 tag, va_list ap) +{ + static const char module[] = "LogLuvVSetField"; + LogLuvState* sp = DecoderState(tif); + int bps, fmt; + + switch (tag) { + case TIFFTAG_SGILOGDATAFMT: + sp->user_datafmt = (int) va_arg(ap, int); + /* + * Tweak the TIFF header so that the rest of libtiff knows what + * size of data will be passed between app and library, and + * assume that the app knows what it is doing and is not + * confused by these header manipulations... + */ + switch (sp->user_datafmt) { + case SGILOGDATAFMT_FLOAT: + bps = 32, fmt = SAMPLEFORMAT_IEEEFP; + break; + case SGILOGDATAFMT_16BIT: + bps = 16, fmt = SAMPLEFORMAT_INT; + break; + case SGILOGDATAFMT_RAW: + bps = 32, fmt = SAMPLEFORMAT_UINT; + TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1); + break; + case SGILOGDATAFMT_8BIT: + bps = 8, fmt = SAMPLEFORMAT_UINT; + break; + default: + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "Unknown data format %d for LogLuv compression", + sp->user_datafmt); + return (0); + } + TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps); + TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, fmt); + /* + * Must recalculate sizes should bits/sample change. + */ + tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tmsize_t) -1; + tif->tif_scanlinesize = TIFFScanlineSize(tif); + return (1); + case TIFFTAG_SGILOGENCODE: + sp->encode_meth = (int) va_arg(ap, int); + if (sp->encode_meth != SGILOGENCODE_NODITHER && + sp->encode_meth != SGILOGENCODE_RANDITHER) { + TIFFErrorExt(tif->tif_clientdata, module, + "Unknown encoding %d for LogLuv compression", + sp->encode_meth); + return (0); + } + return (1); + default: + return (*sp->vsetparent)(tif, tag, ap); + } +} + +static int +LogLuvVGetField(TIFF* tif, uint32 tag, va_list ap) +{ + LogLuvState *sp = (LogLuvState *)tif->tif_data; + + switch (tag) { + case TIFFTAG_SGILOGDATAFMT: + *va_arg(ap, int*) = sp->user_datafmt; + return (1); + default: + return (*sp->vgetparent)(tif, tag, ap); + } +} + +static const TIFFField LogLuvFields[] = { + { TIFFTAG_SGILOGDATAFMT, 0, 0, TIFF_SHORT, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "SGILogDataFmt", NULL}, + { TIFFTAG_SGILOGENCODE, 0, 0, TIFF_SHORT, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "SGILogEncode", NULL} +}; + +int +TIFFInitSGILog(TIFF* tif, int scheme) +{ + static const char module[] = "TIFFInitSGILog"; + LogLuvState* sp; + + assert(scheme == COMPRESSION_SGILOG24 || scheme == COMPRESSION_SGILOG); + + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFields(tif, LogLuvFields, + TIFFArrayCount(LogLuvFields))) { + TIFFErrorExt(tif->tif_clientdata, module, + "Merging SGILog codec-specific tags failed"); + return 0; + } + + /* + * Allocate state block so tag methods have storage to record values. + */ + tif->tif_data = (uint8*) _TIFFmalloc(sizeof (LogLuvState)); + if (tif->tif_data == NULL) + goto bad; + sp = (LogLuvState*) tif->tif_data; + _TIFFmemset((void*)sp, 0, sizeof (*sp)); + sp->user_datafmt = SGILOGDATAFMT_UNKNOWN; + sp->encode_meth = (scheme == COMPRESSION_SGILOG24) ? + SGILOGENCODE_RANDITHER : SGILOGENCODE_NODITHER; + sp->tfunc = _logLuvNop; + + /* + * Install codec methods. + * NB: tif_decoderow & tif_encoderow are filled + * in at setup time. + */ + tif->tif_fixuptags = LogLuvFixupTags; + tif->tif_setupdecode = LogLuvSetupDecode; + tif->tif_decodestrip = LogLuvDecodeStrip; + tif->tif_decodetile = LogLuvDecodeTile; + tif->tif_setupencode = LogLuvSetupEncode; + tif->tif_encodestrip = LogLuvEncodeStrip; + tif->tif_encodetile = LogLuvEncodeTile; + tif->tif_close = LogLuvClose; + tif->tif_cleanup = LogLuvCleanup; + + /* + * Override parent get/set field methods. + */ + sp->vgetparent = tif->tif_tagmethods.vgetfield; + tif->tif_tagmethods.vgetfield = LogLuvVGetField; /* hook for codec tags */ + sp->vsetparent = tif->tif_tagmethods.vsetfield; + tif->tif_tagmethods.vsetfield = LogLuvVSetField; /* hook for codec tags */ + + return (1); +bad: + TIFFErrorExt(tif->tif_clientdata, module, + "%s: No space for LogLuv state block", tif->tif_name); + return (0); +} +#endif /* LOGLUV_SUPPORT */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_lzma.c b/Source/LibTIFF4/tif_lzma.c index 31c2ff3..229c970 100644 --- a/Source/LibTIFF4/tif_lzma.c +++ b/Source/LibTIFF4/tif_lzma.c @@ -1,495 +1,495 @@ -/* $Id: tif_lzma.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 2010, Andrey Kiselev - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "tiffiop.h" -#ifdef LZMA_SUPPORT -/* - * TIFF Library. - * - * LZMA2 Compression Support - * - * You need an LZMA2 SDK to link with. See http://tukaani.org/xz/ for details. - * - * The codec is derived from ZLIB codec (tif_zip.c). - */ - -#include "tif_predict.h" -#include "lzma.h" - -#include - -/* - * State block for each open TIFF file using LZMA2 compression/decompression. - */ -typedef struct { - TIFFPredictorState predict; - lzma_stream stream; - lzma_filter filters[LZMA_FILTERS_MAX + 1]; - lzma_options_delta opt_delta; /* delta filter options */ - lzma_options_lzma opt_lzma; /* LZMA2 filter options */ - int preset; /* compression level */ - lzma_check check; /* type of the integrity check */ - int state; /* state flags */ -#define LSTATE_INIT_DECODE 0x01 -#define LSTATE_INIT_ENCODE 0x02 - - TIFFVGetMethod vgetparent; /* super-class method */ - TIFFVSetMethod vsetparent; /* super-class method */ -} LZMAState; - -#define LState(tif) ((LZMAState*) (tif)->tif_data) -#define DecoderState(tif) LState(tif) -#define EncoderState(tif) LState(tif) - -static int LZMAEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s); -static int LZMADecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s); - -static const char * -LZMAStrerror(lzma_ret ret) -{ - switch (ret) { - case LZMA_OK: - return "operation completed successfully"; - case LZMA_STREAM_END: - return "end of stream was reached"; - case LZMA_NO_CHECK: - return "input stream has no integrity check"; - case LZMA_UNSUPPORTED_CHECK: - return "cannot calculate the integrity check"; - case LZMA_GET_CHECK: - return "integrity check type is now available"; - case LZMA_MEM_ERROR: - return "cannot allocate memory"; - case LZMA_MEMLIMIT_ERROR: - return "memory usage limit was reached"; - case LZMA_FORMAT_ERROR: - return "file format not recognized"; - case LZMA_OPTIONS_ERROR: - return "invalid or unsupported options"; - case LZMA_DATA_ERROR: - return "data is corrupt"; - case LZMA_BUF_ERROR: - return "no progress is possible (stream is truncated or corrupt)"; - case LZMA_PROG_ERROR: - return "programming error"; - default: - return "unindentified liblzma error"; - } -} - -static int -LZMAFixupTags(TIFF* tif) -{ - (void) tif; - return 1; -} - -static int -LZMASetupDecode(TIFF* tif) -{ - LZMAState* sp = DecoderState(tif); - - assert(sp != NULL); - - /* if we were last encoding, terminate this mode */ - if (sp->state & LSTATE_INIT_ENCODE) { - lzma_end(&sp->stream); - sp->state = 0; - } - - sp->state |= LSTATE_INIT_DECODE; - return 1; -} - -/* - * Setup state for decoding a strip. - */ -static int -LZMAPreDecode(TIFF* tif, uint16 s) -{ - static const char module[] = "LZMAPreDecode"; - LZMAState* sp = DecoderState(tif); - lzma_ret ret; - - (void) s; - assert(sp != NULL); - - if( (sp->state & LSTATE_INIT_DECODE) == 0 ) - tif->tif_setupdecode(tif); - - sp->stream.next_in = tif->tif_rawdata; - sp->stream.avail_in = (size_t) tif->tif_rawcc; - if ((tmsize_t)sp->stream.avail_in != tif->tif_rawcc) { - TIFFErrorExt(tif->tif_clientdata, module, - "Liblzma cannot deal with buffers this size"); - return 0; - } - - /* - * Disable memory limit when decoding. UINT64_MAX is a flag to disable - * the limit, we are passing (uint64_t)-1 which should be the same. - */ - ret = lzma_stream_decoder(&sp->stream, (uint64_t)-1, 0); - if (ret != LZMA_OK) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error initializing the stream decoder, %s", - LZMAStrerror(ret)); - return 0; - } - return 1; -} - -static int -LZMADecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) -{ - static const char module[] = "LZMADecode"; - LZMAState* sp = DecoderState(tif); - - (void) s; - assert(sp != NULL); - assert(sp->state == LSTATE_INIT_DECODE); - - sp->stream.next_in = tif->tif_rawcp; - sp->stream.avail_in = (size_t) tif->tif_rawcc; - - sp->stream.next_out = op; - sp->stream.avail_out = (size_t) occ; - if ((tmsize_t)sp->stream.avail_out != occ) { - TIFFErrorExt(tif->tif_clientdata, module, - "Liblzma cannot deal with buffers this size"); - return 0; - } - - do { - /* - * Save the current stream state to properly recover from the - * decoding errors later. - */ - const uint8_t *next_in = sp->stream.next_in; - size_t avail_in = sp->stream.avail_in; - - lzma_ret ret = lzma_code(&sp->stream, LZMA_RUN); - if (ret == LZMA_STREAM_END) - break; - if (ret == LZMA_MEMLIMIT_ERROR) { - lzma_ret r = lzma_stream_decoder(&sp->stream, - lzma_memusage(&sp->stream), 0); - if (r != LZMA_OK) { - TIFFErrorExt(tif->tif_clientdata, module, - "Error initializing the stream decoder, %s", - LZMAStrerror(r)); - break; - } - sp->stream.next_in = next_in; - sp->stream.avail_in = avail_in; - continue; - } - if (ret != LZMA_OK) { - TIFFErrorExt(tif->tif_clientdata, module, - "Decoding error at scanline %lu, %s", - (unsigned long) tif->tif_row, LZMAStrerror(ret)); - break; - } - } while (sp->stream.avail_out > 0); - if (sp->stream.avail_out != 0) { - TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data at scanline %lu (short %lu bytes)", - (unsigned long) tif->tif_row, (unsigned long) sp->stream.avail_out); - return 0; - } - - tif->tif_rawcp = (uint8 *)sp->stream.next_in; /* cast away const */ - tif->tif_rawcc = sp->stream.avail_in; - - return 1; -} - -static int -LZMASetupEncode(TIFF* tif) -{ - LZMAState* sp = EncoderState(tif); - - assert(sp != NULL); - if (sp->state & LSTATE_INIT_DECODE) { - lzma_end(&sp->stream); - sp->state = 0; - } - - sp->state |= LSTATE_INIT_ENCODE; - return 1; -} - -/* - * Reset encoding state at the start of a strip. - */ -static int -LZMAPreEncode(TIFF* tif, uint16 s) -{ - static const char module[] = "LZMAPreEncode"; - LZMAState *sp = EncoderState(tif); - - (void) s; - assert(sp != NULL); - if( sp->state != LSTATE_INIT_ENCODE ) - tif->tif_setupencode(tif); - - sp->stream.next_out = tif->tif_rawdata; - sp->stream.avail_out = (size_t)tif->tif_rawdatasize; - if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) { - TIFFErrorExt(tif->tif_clientdata, module, - "Liblzma cannot deal with buffers this size"); - return 0; - } - return (lzma_stream_encoder(&sp->stream, sp->filters, sp->check) == LZMA_OK); -} - -/* - * Encode a chunk of pixels. - */ -static int -LZMAEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - static const char module[] = "LZMAEncode"; - LZMAState *sp = EncoderState(tif); - - assert(sp != NULL); - assert(sp->state == LSTATE_INIT_ENCODE); - - (void) s; - sp->stream.next_in = bp; - sp->stream.avail_in = (size_t) cc; - if ((tmsize_t)sp->stream.avail_in != cc) { - TIFFErrorExt(tif->tif_clientdata, module, - "Liblzma cannot deal with buffers this size"); - return 0; - } - do { - lzma_ret ret = lzma_code(&sp->stream, LZMA_RUN); - if (ret != LZMA_OK) { - TIFFErrorExt(tif->tif_clientdata, module, - "Encoding error at scanline %lu, %s", - (unsigned long) tif->tif_row, LZMAStrerror(ret)); - return 0; - } - if (sp->stream.avail_out == 0) { - tif->tif_rawcc = tif->tif_rawdatasize; - TIFFFlushData1(tif); - sp->stream.next_out = tif->tif_rawdata; - sp->stream.avail_out = (size_t)tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in LZMAPreEncode */ - } - } while (sp->stream.avail_in > 0); - return 1; -} - -/* - * Finish off an encoded strip by flushing the last - * string and tacking on an End Of Information code. - */ -static int -LZMAPostEncode(TIFF* tif) -{ - static const char module[] = "LZMAPostEncode"; - LZMAState *sp = EncoderState(tif); - lzma_ret ret; - - sp->stream.avail_in = 0; - do { - ret = lzma_code(&sp->stream, LZMA_FINISH); - switch (ret) { - case LZMA_STREAM_END: - case LZMA_OK: - if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) { - tif->tif_rawcc = - tif->tif_rawdatasize - sp->stream.avail_out; - TIFFFlushData1(tif); - sp->stream.next_out = tif->tif_rawdata; - sp->stream.avail_out = (size_t)tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in ZIPPreEncode */ - } - break; - default: - TIFFErrorExt(tif->tif_clientdata, module, "Liblzma error: %s", - LZMAStrerror(ret)); - return 0; - } - } while (ret != LZMA_STREAM_END); - return 1; -} - -static void -LZMACleanup(TIFF* tif) -{ - LZMAState* sp = LState(tif); - - assert(sp != 0); - - (void)TIFFPredictorCleanup(tif); - - tif->tif_tagmethods.vgetfield = sp->vgetparent; - tif->tif_tagmethods.vsetfield = sp->vsetparent; - - if (sp->state) { - lzma_end(&sp->stream); - sp->state = 0; - } - _TIFFfree(sp); - tif->tif_data = NULL; - - _TIFFSetDefaultCompressionState(tif); -} - -static int -LZMAVSetField(TIFF* tif, uint32 tag, va_list ap) -{ - static const char module[] = "LZMAVSetField"; - LZMAState* sp = LState(tif); - - switch (tag) { - case TIFFTAG_LZMAPRESET: - sp->preset = (int) va_arg(ap, int); - lzma_lzma_preset(&sp->opt_lzma, sp->preset); - if (sp->state & LSTATE_INIT_ENCODE) { - lzma_ret ret = lzma_stream_encoder(&sp->stream, - sp->filters, - sp->check); - if (ret != LZMA_OK) { - TIFFErrorExt(tif->tif_clientdata, module, - "Liblzma error: %s", - LZMAStrerror(ret)); - } - } - return 1; - default: - return (*sp->vsetparent)(tif, tag, ap); - } - /*NOTREACHED*/ -} - -static int -LZMAVGetField(TIFF* tif, uint32 tag, va_list ap) -{ - LZMAState* sp = LState(tif); - - switch (tag) { - case TIFFTAG_LZMAPRESET: - *va_arg(ap, int*) = sp->preset; - break; - default: - return (*sp->vgetparent)(tif, tag, ap); - } - return 1; -} - -static const TIFFField lzmaFields[] = { - { TIFFTAG_LZMAPRESET, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, - FIELD_PSEUDO, TRUE, FALSE, "LZMA2 Compression Preset", NULL }, -}; - -int -TIFFInitLZMA(TIFF* tif, int scheme) -{ - static const char module[] = "TIFFInitLZMA"; - LZMAState* sp; - lzma_stream tmp_stream = LZMA_STREAM_INIT; - - assert( scheme == COMPRESSION_LZMA ); - - /* - * Merge codec-specific tag information. - */ - if (!_TIFFMergeFields(tif, lzmaFields, TIFFArrayCount(lzmaFields))) { - TIFFErrorExt(tif->tif_clientdata, module, - "Merging LZMA2 codec-specific tags failed"); - return 0; - } - - /* - * Allocate state block so tag methods have storage to record values. - */ - tif->tif_data = (uint8*) _TIFFmalloc(sizeof(LZMAState)); - if (tif->tif_data == NULL) - goto bad; - sp = LState(tif); - memcpy(&sp->stream, &tmp_stream, sizeof(lzma_stream)); - - /* - * Override parent get/set field methods. - */ - sp->vgetparent = tif->tif_tagmethods.vgetfield; - tif->tif_tagmethods.vgetfield = LZMAVGetField; /* hook for codec tags */ - sp->vsetparent = tif->tif_tagmethods.vsetfield; - tif->tif_tagmethods.vsetfield = LZMAVSetField; /* hook for codec tags */ - - /* Default values for codec-specific fields */ - sp->preset = LZMA_PRESET_DEFAULT; /* default comp. level */ - sp->check = LZMA_CHECK_NONE; - sp->state = 0; - - /* Data filters. So far we are using delta and LZMA2 filters only. */ - sp->opt_delta.type = LZMA_DELTA_TYPE_BYTE; - /* - * The sample size in bytes seems to be reasonable distance for delta - * filter. - */ - sp->opt_delta.dist = (tif->tif_dir.td_bitspersample % 8) ? - 1 : tif->tif_dir.td_bitspersample / 8; - sp->filters[0].id = LZMA_FILTER_DELTA; - sp->filters[0].options = &sp->opt_delta; - - lzma_lzma_preset(&sp->opt_lzma, sp->preset); - sp->filters[1].id = LZMA_FILTER_LZMA2; - sp->filters[1].options = &sp->opt_lzma; - - sp->filters[2].id = LZMA_VLI_UNKNOWN; - sp->filters[2].options = NULL; - - /* - * Install codec methods. - */ - tif->tif_fixuptags = LZMAFixupTags; - tif->tif_setupdecode = LZMASetupDecode; - tif->tif_predecode = LZMAPreDecode; - tif->tif_decoderow = LZMADecode; - tif->tif_decodestrip = LZMADecode; - tif->tif_decodetile = LZMADecode; - tif->tif_setupencode = LZMASetupEncode; - tif->tif_preencode = LZMAPreEncode; - tif->tif_postencode = LZMAPostEncode; - tif->tif_encoderow = LZMAEncode; - tif->tif_encodestrip = LZMAEncode; - tif->tif_encodetile = LZMAEncode; - tif->tif_cleanup = LZMACleanup; - /* - * Setup predictor setup. - */ - (void) TIFFPredictorInit(tif); - return 1; -bad: - TIFFErrorExt(tif->tif_clientdata, module, - "No space for LZMA2 state block"); - return 0; -} -#endif /* LZMA_SUPORT */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ +/* $Id: tif_lzma.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 2010, Andrey Kiselev + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include "tiffiop.h" +#ifdef LZMA_SUPPORT +/* + * TIFF Library. + * + * LZMA2 Compression Support + * + * You need an LZMA2 SDK to link with. See http://tukaani.org/xz/ for details. + * + * The codec is derived from ZLIB codec (tif_zip.c). + */ + +#include "tif_predict.h" +#include "lzma.h" + +#include + +/* + * State block for each open TIFF file using LZMA2 compression/decompression. + */ +typedef struct { + TIFFPredictorState predict; + lzma_stream stream; + lzma_filter filters[LZMA_FILTERS_MAX + 1]; + lzma_options_delta opt_delta; /* delta filter options */ + lzma_options_lzma opt_lzma; /* LZMA2 filter options */ + int preset; /* compression level */ + lzma_check check; /* type of the integrity check */ + int state; /* state flags */ +#define LSTATE_INIT_DECODE 0x01 +#define LSTATE_INIT_ENCODE 0x02 + + TIFFVGetMethod vgetparent; /* super-class method */ + TIFFVSetMethod vsetparent; /* super-class method */ +} LZMAState; + +#define LState(tif) ((LZMAState*) (tif)->tif_data) +#define DecoderState(tif) LState(tif) +#define EncoderState(tif) LState(tif) + +static int LZMAEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s); +static int LZMADecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s); + +static const char * +LZMAStrerror(lzma_ret ret) +{ + switch (ret) { + case LZMA_OK: + return "operation completed successfully"; + case LZMA_STREAM_END: + return "end of stream was reached"; + case LZMA_NO_CHECK: + return "input stream has no integrity check"; + case LZMA_UNSUPPORTED_CHECK: + return "cannot calculate the integrity check"; + case LZMA_GET_CHECK: + return "integrity check type is now available"; + case LZMA_MEM_ERROR: + return "cannot allocate memory"; + case LZMA_MEMLIMIT_ERROR: + return "memory usage limit was reached"; + case LZMA_FORMAT_ERROR: + return "file format not recognized"; + case LZMA_OPTIONS_ERROR: + return "invalid or unsupported options"; + case LZMA_DATA_ERROR: + return "data is corrupt"; + case LZMA_BUF_ERROR: + return "no progress is possible (stream is truncated or corrupt)"; + case LZMA_PROG_ERROR: + return "programming error"; + default: + return "unindentified liblzma error"; + } +} + +static int +LZMAFixupTags(TIFF* tif) +{ + (void) tif; + return 1; +} + +static int +LZMASetupDecode(TIFF* tif) +{ + LZMAState* sp = DecoderState(tif); + + assert(sp != NULL); + + /* if we were last encoding, terminate this mode */ + if (sp->state & LSTATE_INIT_ENCODE) { + lzma_end(&sp->stream); + sp->state = 0; + } + + sp->state |= LSTATE_INIT_DECODE; + return 1; +} + +/* + * Setup state for decoding a strip. + */ +static int +LZMAPreDecode(TIFF* tif, uint16 s) +{ + static const char module[] = "LZMAPreDecode"; + LZMAState* sp = DecoderState(tif); + lzma_ret ret; + + (void) s; + assert(sp != NULL); + + if( (sp->state & LSTATE_INIT_DECODE) == 0 ) + tif->tif_setupdecode(tif); + + sp->stream.next_in = tif->tif_rawdata; + sp->stream.avail_in = (size_t) tif->tif_rawcc; + if ((tmsize_t)sp->stream.avail_in != tif->tif_rawcc) { + TIFFErrorExt(tif->tif_clientdata, module, + "Liblzma cannot deal with buffers this size"); + return 0; + } + + /* + * Disable memory limit when decoding. UINT64_MAX is a flag to disable + * the limit, we are passing (uint64_t)-1 which should be the same. + */ + ret = lzma_stream_decoder(&sp->stream, (uint64_t)-1, 0); + if (ret != LZMA_OK) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error initializing the stream decoder, %s", + LZMAStrerror(ret)); + return 0; + } + return 1; +} + +static int +LZMADecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) +{ + static const char module[] = "LZMADecode"; + LZMAState* sp = DecoderState(tif); + + (void) s; + assert(sp != NULL); + assert(sp->state == LSTATE_INIT_DECODE); + + sp->stream.next_in = tif->tif_rawcp; + sp->stream.avail_in = (size_t) tif->tif_rawcc; + + sp->stream.next_out = op; + sp->stream.avail_out = (size_t) occ; + if ((tmsize_t)sp->stream.avail_out != occ) { + TIFFErrorExt(tif->tif_clientdata, module, + "Liblzma cannot deal with buffers this size"); + return 0; + } + + do { + /* + * Save the current stream state to properly recover from the + * decoding errors later. + */ + const uint8_t *next_in = sp->stream.next_in; + size_t avail_in = sp->stream.avail_in; + + lzma_ret ret = lzma_code(&sp->stream, LZMA_RUN); + if (ret == LZMA_STREAM_END) + break; + if (ret == LZMA_MEMLIMIT_ERROR) { + lzma_ret r = lzma_stream_decoder(&sp->stream, + lzma_memusage(&sp->stream), 0); + if (r != LZMA_OK) { + TIFFErrorExt(tif->tif_clientdata, module, + "Error initializing the stream decoder, %s", + LZMAStrerror(r)); + break; + } + sp->stream.next_in = next_in; + sp->stream.avail_in = avail_in; + continue; + } + if (ret != LZMA_OK) { + TIFFErrorExt(tif->tif_clientdata, module, + "Decoding error at scanline %lu, %s", + (unsigned long) tif->tif_row, LZMAStrerror(ret)); + break; + } + } while (sp->stream.avail_out > 0); + if (sp->stream.avail_out != 0) { + TIFFErrorExt(tif->tif_clientdata, module, + "Not enough data at scanline %lu (short %lu bytes)", + (unsigned long) tif->tif_row, (unsigned long) sp->stream.avail_out); + return 0; + } + + tif->tif_rawcp = (uint8 *)sp->stream.next_in; /* cast away const */ + tif->tif_rawcc = sp->stream.avail_in; + + return 1; +} + +static int +LZMASetupEncode(TIFF* tif) +{ + LZMAState* sp = EncoderState(tif); + + assert(sp != NULL); + if (sp->state & LSTATE_INIT_DECODE) { + lzma_end(&sp->stream); + sp->state = 0; + } + + sp->state |= LSTATE_INIT_ENCODE; + return 1; +} + +/* + * Reset encoding state at the start of a strip. + */ +static int +LZMAPreEncode(TIFF* tif, uint16 s) +{ + static const char module[] = "LZMAPreEncode"; + LZMAState *sp = EncoderState(tif); + + (void) s; + assert(sp != NULL); + if( sp->state != LSTATE_INIT_ENCODE ) + tif->tif_setupencode(tif); + + sp->stream.next_out = tif->tif_rawdata; + sp->stream.avail_out = (size_t)tif->tif_rawdatasize; + if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) { + TIFFErrorExt(tif->tif_clientdata, module, + "Liblzma cannot deal with buffers this size"); + return 0; + } + return (lzma_stream_encoder(&sp->stream, sp->filters, sp->check) == LZMA_OK); +} + +/* + * Encode a chunk of pixels. + */ +static int +LZMAEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + static const char module[] = "LZMAEncode"; + LZMAState *sp = EncoderState(tif); + + assert(sp != NULL); + assert(sp->state == LSTATE_INIT_ENCODE); + + (void) s; + sp->stream.next_in = bp; + sp->stream.avail_in = (size_t) cc; + if ((tmsize_t)sp->stream.avail_in != cc) { + TIFFErrorExt(tif->tif_clientdata, module, + "Liblzma cannot deal with buffers this size"); + return 0; + } + do { + lzma_ret ret = lzma_code(&sp->stream, LZMA_RUN); + if (ret != LZMA_OK) { + TIFFErrorExt(tif->tif_clientdata, module, + "Encoding error at scanline %lu, %s", + (unsigned long) tif->tif_row, LZMAStrerror(ret)); + return 0; + } + if (sp->stream.avail_out == 0) { + tif->tif_rawcc = tif->tif_rawdatasize; + TIFFFlushData1(tif); + sp->stream.next_out = tif->tif_rawdata; + sp->stream.avail_out = (size_t)tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in LZMAPreEncode */ + } + } while (sp->stream.avail_in > 0); + return 1; +} + +/* + * Finish off an encoded strip by flushing the last + * string and tacking on an End Of Information code. + */ +static int +LZMAPostEncode(TIFF* tif) +{ + static const char module[] = "LZMAPostEncode"; + LZMAState *sp = EncoderState(tif); + lzma_ret ret; + + sp->stream.avail_in = 0; + do { + ret = lzma_code(&sp->stream, LZMA_FINISH); + switch (ret) { + case LZMA_STREAM_END: + case LZMA_OK: + if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) { + tif->tif_rawcc = + tif->tif_rawdatasize - sp->stream.avail_out; + TIFFFlushData1(tif); + sp->stream.next_out = tif->tif_rawdata; + sp->stream.avail_out = (size_t)tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in ZIPPreEncode */ + } + break; + default: + TIFFErrorExt(tif->tif_clientdata, module, "Liblzma error: %s", + LZMAStrerror(ret)); + return 0; + } + } while (ret != LZMA_STREAM_END); + return 1; +} + +static void +LZMACleanup(TIFF* tif) +{ + LZMAState* sp = LState(tif); + + assert(sp != 0); + + (void)TIFFPredictorCleanup(tif); + + tif->tif_tagmethods.vgetfield = sp->vgetparent; + tif->tif_tagmethods.vsetfield = sp->vsetparent; + + if (sp->state) { + lzma_end(&sp->stream); + sp->state = 0; + } + _TIFFfree(sp); + tif->tif_data = NULL; + + _TIFFSetDefaultCompressionState(tif); +} + +static int +LZMAVSetField(TIFF* tif, uint32 tag, va_list ap) +{ + static const char module[] = "LZMAVSetField"; + LZMAState* sp = LState(tif); + + switch (tag) { + case TIFFTAG_LZMAPRESET: + sp->preset = (int) va_arg(ap, int); + lzma_lzma_preset(&sp->opt_lzma, sp->preset); + if (sp->state & LSTATE_INIT_ENCODE) { + lzma_ret ret = lzma_stream_encoder(&sp->stream, + sp->filters, + sp->check); + if (ret != LZMA_OK) { + TIFFErrorExt(tif->tif_clientdata, module, + "Liblzma error: %s", + LZMAStrerror(ret)); + } + } + return 1; + default: + return (*sp->vsetparent)(tif, tag, ap); + } + /*NOTREACHED*/ +} + +static int +LZMAVGetField(TIFF* tif, uint32 tag, va_list ap) +{ + LZMAState* sp = LState(tif); + + switch (tag) { + case TIFFTAG_LZMAPRESET: + *va_arg(ap, int*) = sp->preset; + break; + default: + return (*sp->vgetparent)(tif, tag, ap); + } + return 1; +} + +static const TIFFField lzmaFields[] = { + { TIFFTAG_LZMAPRESET, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, + FIELD_PSEUDO, TRUE, FALSE, "LZMA2 Compression Preset", NULL }, +}; + +int +TIFFInitLZMA(TIFF* tif, int scheme) +{ + static const char module[] = "TIFFInitLZMA"; + LZMAState* sp; + lzma_stream tmp_stream = LZMA_STREAM_INIT; + + assert( scheme == COMPRESSION_LZMA ); + + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFields(tif, lzmaFields, TIFFArrayCount(lzmaFields))) { + TIFFErrorExt(tif->tif_clientdata, module, + "Merging LZMA2 codec-specific tags failed"); + return 0; + } + + /* + * Allocate state block so tag methods have storage to record values. + */ + tif->tif_data = (uint8*) _TIFFmalloc(sizeof(LZMAState)); + if (tif->tif_data == NULL) + goto bad; + sp = LState(tif); + memcpy(&sp->stream, &tmp_stream, sizeof(lzma_stream)); + + /* + * Override parent get/set field methods. + */ + sp->vgetparent = tif->tif_tagmethods.vgetfield; + tif->tif_tagmethods.vgetfield = LZMAVGetField; /* hook for codec tags */ + sp->vsetparent = tif->tif_tagmethods.vsetfield; + tif->tif_tagmethods.vsetfield = LZMAVSetField; /* hook for codec tags */ + + /* Default values for codec-specific fields */ + sp->preset = LZMA_PRESET_DEFAULT; /* default comp. level */ + sp->check = LZMA_CHECK_NONE; + sp->state = 0; + + /* Data filters. So far we are using delta and LZMA2 filters only. */ + sp->opt_delta.type = LZMA_DELTA_TYPE_BYTE; + /* + * The sample size in bytes seems to be reasonable distance for delta + * filter. + */ + sp->opt_delta.dist = (tif->tif_dir.td_bitspersample % 8) ? + 1 : tif->tif_dir.td_bitspersample / 8; + sp->filters[0].id = LZMA_FILTER_DELTA; + sp->filters[0].options = &sp->opt_delta; + + lzma_lzma_preset(&sp->opt_lzma, sp->preset); + sp->filters[1].id = LZMA_FILTER_LZMA2; + sp->filters[1].options = &sp->opt_lzma; + + sp->filters[2].id = LZMA_VLI_UNKNOWN; + sp->filters[2].options = NULL; + + /* + * Install codec methods. + */ + tif->tif_fixuptags = LZMAFixupTags; + tif->tif_setupdecode = LZMASetupDecode; + tif->tif_predecode = LZMAPreDecode; + tif->tif_decoderow = LZMADecode; + tif->tif_decodestrip = LZMADecode; + tif->tif_decodetile = LZMADecode; + tif->tif_setupencode = LZMASetupEncode; + tif->tif_preencode = LZMAPreEncode; + tif->tif_postencode = LZMAPostEncode; + tif->tif_encoderow = LZMAEncode; + tif->tif_encodestrip = LZMAEncode; + tif->tif_encodetile = LZMAEncode; + tif->tif_cleanup = LZMACleanup; + /* + * Setup predictor setup. + */ + (void) TIFFPredictorInit(tif); + return 1; +bad: + TIFFErrorExt(tif->tif_clientdata, module, + "No space for LZMA2 state block"); + return 0; +} +#endif /* LZMA_SUPORT */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ diff --git a/Source/LibTIFF4/tif_lzw.c b/Source/LibTIFF4/tif_lzw.c index 972f92b..b600cfd 100644 --- a/Source/LibTIFF4/tif_lzw.c +++ b/Source/LibTIFF4/tif_lzw.c @@ -1,1167 +1,1167 @@ -/* $Id: tif_lzw.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "tiffiop.h" -#ifdef LZW_SUPPORT -/* - * TIFF Library. - * Rev 5.0 Lempel-Ziv & Welch Compression Support - * - * This code is derived from the compress program whose code is - * derived from software contributed to Berkeley by James A. Woods, - * derived from original work by Spencer Thomas and Joseph Orost. - * - * The original Berkeley copyright notice appears below in its entirety. - */ -#include "tif_predict.h" - -#include - -/* - * NB: The 5.0 spec describes a different algorithm than Aldus - * implements. Specifically, Aldus does code length transitions - * one code earlier than should be done (for real LZW). - * Earlier versions of this library implemented the correct - * LZW algorithm, but emitted codes in a bit order opposite - * to the TIFF spec. Thus, to maintain compatibility w/ Aldus - * we interpret MSB-LSB ordered codes to be images written w/ - * old versions of this library, but otherwise adhere to the - * Aldus "off by one" algorithm. - * - * Future revisions to the TIFF spec are expected to "clarify this issue". - */ -#define LZW_COMPAT /* include backwards compatibility code */ -/* - * Each strip of data is supposed to be terminated by a CODE_EOI. - * If the following #define is included, the decoder will also - * check for end-of-strip w/o seeing this code. This makes the - * library more robust, but also slower. - */ -#define LZW_CHECKEOS /* include checks for strips w/o EOI code */ - -#define MAXCODE(n) ((1L<<(n))-1) -/* - * The TIFF spec specifies that encoded bit - * strings range from 9 to 12 bits. - */ -#define BITS_MIN 9 /* start with 9 bits */ -#define BITS_MAX 12 /* max of 12 bit strings */ -/* predefined codes */ -#define CODE_CLEAR 256 /* code to clear string table */ -#define CODE_EOI 257 /* end-of-information code */ -#define CODE_FIRST 258 /* first free code entry */ -#define CODE_MAX MAXCODE(BITS_MAX) -#define HSIZE 9001L /* 91% occupancy */ -#define HSHIFT (13-8) -#ifdef LZW_COMPAT -/* NB: +1024 is for compatibility with old files */ -#define CSIZE (MAXCODE(BITS_MAX)+1024L) -#else -#define CSIZE (MAXCODE(BITS_MAX)+1L) -#endif - -/* - * State block for each open TIFF file using LZW - * compression/decompression. Note that the predictor - * state block must be first in this data structure. - */ -typedef struct { - TIFFPredictorState predict; /* predictor super class */ - - unsigned short nbits; /* # of bits/code */ - unsigned short maxcode; /* maximum code for lzw_nbits */ - unsigned short free_ent; /* next free entry in hash table */ - long nextdata; /* next bits of i/o */ - long nextbits; /* # of valid bits in lzw_nextdata */ - - int rw_mode; /* preserve rw_mode from init */ -} LZWBaseState; - -#define lzw_nbits base.nbits -#define lzw_maxcode base.maxcode -#define lzw_free_ent base.free_ent -#define lzw_nextdata base.nextdata -#define lzw_nextbits base.nextbits - -/* - * Encoding-specific state. - */ -typedef uint16 hcode_t; /* codes fit in 16 bits */ -typedef struct { - long hash; - hcode_t code; -} hash_t; - -/* - * Decoding-specific state. - */ -typedef struct code_ent { - struct code_ent *next; - unsigned short length; /* string len, including this token */ - unsigned char value; /* data value */ - unsigned char firstchar; /* first token of string */ -} code_t; - -typedef int (*decodeFunc)(TIFF*, uint8*, tmsize_t, uint16); - -typedef struct { - LZWBaseState base; - - /* Decoding specific data */ - long dec_nbitsmask; /* lzw_nbits 1 bits, right adjusted */ - long dec_restart; /* restart count */ -#ifdef LZW_CHECKEOS - uint64 dec_bitsleft; /* available bits in raw data */ -#endif - decodeFunc dec_decode; /* regular or backwards compatible */ - code_t* dec_codep; /* current recognized code */ - code_t* dec_oldcodep; /* previously recognized code */ - code_t* dec_free_entp; /* next free entry */ - code_t* dec_maxcodep; /* max available entry */ - code_t* dec_codetab; /* kept separate for small machines */ - - /* Encoding specific data */ - int enc_oldcode; /* last code encountered */ - long enc_checkpoint; /* point at which to clear table */ -#define CHECK_GAP 10000 /* enc_ratio check interval */ - long enc_ratio; /* current compression ratio */ - long enc_incount; /* (input) data bytes encoded */ - long enc_outcount; /* encoded (output) bytes */ - uint8* enc_rawlimit; /* bound on tif_rawdata buffer */ - hash_t* enc_hashtab; /* kept separate for small machines */ -} LZWCodecState; - -#define LZWState(tif) ((LZWBaseState*) (tif)->tif_data) -#define DecoderState(tif) ((LZWCodecState*) LZWState(tif)) -#define EncoderState(tif) ((LZWCodecState*) LZWState(tif)) - -static int LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); -#ifdef LZW_COMPAT -static int LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); -#endif -static void cl_hash(LZWCodecState*); - -/* - * LZW Decoder. - */ - -#ifdef LZW_CHECKEOS -/* - * This check shouldn't be necessary because each - * strip is suppose to be terminated with CODE_EOI. - */ -#define NextCode(_tif, _sp, _bp, _code, _get) { \ - if ((_sp)->dec_bitsleft < (uint64)nbits) { \ - TIFFWarningExt(_tif->tif_clientdata, module, \ - "LZWDecode: Strip %d not terminated with EOI code", \ - _tif->tif_curstrip); \ - _code = CODE_EOI; \ - } else { \ - _get(_sp,_bp,_code); \ - (_sp)->dec_bitsleft -= nbits; \ - } \ -} -#else -#define NextCode(tif, sp, bp, code, get) get(sp, bp, code) -#endif - -static int -LZWFixupTags(TIFF* tif) -{ - (void) tif; - return (1); -} - -static int -LZWSetupDecode(TIFF* tif) -{ - static const char module[] = "LZWSetupDecode"; - LZWCodecState* sp = DecoderState(tif); - int code; - - if( sp == NULL ) - { - /* - * Allocate state block so tag methods have storage to record - * values. - */ - tif->tif_data = (uint8*) _TIFFmalloc(sizeof(LZWCodecState)); - if (tif->tif_data == NULL) - { - TIFFErrorExt(tif->tif_clientdata, module, "No space for LZW state block"); - return (0); - } - - DecoderState(tif)->dec_codetab = NULL; - DecoderState(tif)->dec_decode = NULL; - - /* - * Setup predictor setup. - */ - (void) TIFFPredictorInit(tif); - - sp = DecoderState(tif); - } - - assert(sp != NULL); - - if (sp->dec_codetab == NULL) { - sp->dec_codetab = (code_t*)_TIFFmalloc(CSIZE*sizeof (code_t)); - if (sp->dec_codetab == NULL) { - TIFFErrorExt(tif->tif_clientdata, module, - "No space for LZW code table"); - return (0); - } - /* - * Pre-load the table. - */ - code = 255; - do { - sp->dec_codetab[code].value = code; - sp->dec_codetab[code].firstchar = code; - sp->dec_codetab[code].length = 1; - sp->dec_codetab[code].next = NULL; - } while (code--); - /* - * Zero-out the unused entries - */ - _TIFFmemset(&sp->dec_codetab[CODE_CLEAR], 0, - (CODE_FIRST - CODE_CLEAR) * sizeof (code_t)); - } - return (1); -} - -/* - * Setup state for decoding a strip. - */ -static int -LZWPreDecode(TIFF* tif, uint16 s) -{ - static const char module[] = "LZWPreDecode"; - LZWCodecState *sp = DecoderState(tif); - - (void) s; - assert(sp != NULL); - if( sp->dec_codetab == NULL ) - { - tif->tif_setupdecode( tif ); - } - - /* - * Check for old bit-reversed codes. - */ - if (tif->tif_rawdata[0] == 0 && (tif->tif_rawdata[1] & 0x1)) { -#ifdef LZW_COMPAT - if (!sp->dec_decode) { - TIFFWarningExt(tif->tif_clientdata, module, - "Old-style LZW codes, convert file"); - /* - * Override default decoding methods with - * ones that deal with the old coding. - * Otherwise the predictor versions set - * above will call the compatibility routines - * through the dec_decode method. - */ - tif->tif_decoderow = LZWDecodeCompat; - tif->tif_decodestrip = LZWDecodeCompat; - tif->tif_decodetile = LZWDecodeCompat; - /* - * If doing horizontal differencing, must - * re-setup the predictor logic since we - * switched the basic decoder methods... - */ - (*tif->tif_setupdecode)(tif); - sp->dec_decode = LZWDecodeCompat; - } - sp->lzw_maxcode = MAXCODE(BITS_MIN); -#else /* !LZW_COMPAT */ - if (!sp->dec_decode) { - TIFFErrorExt(tif->tif_clientdata, module, - "Old-style LZW codes not supported"); - sp->dec_decode = LZWDecode; - } - return (0); -#endif/* !LZW_COMPAT */ - } else { - sp->lzw_maxcode = MAXCODE(BITS_MIN)-1; - sp->dec_decode = LZWDecode; - } - sp->lzw_nbits = BITS_MIN; - sp->lzw_nextbits = 0; - sp->lzw_nextdata = 0; - - sp->dec_restart = 0; - sp->dec_nbitsmask = MAXCODE(BITS_MIN); -#ifdef LZW_CHECKEOS - sp->dec_bitsleft = ((uint64)tif->tif_rawcc) << 3; -#endif - sp->dec_free_entp = sp->dec_codetab + CODE_FIRST; - /* - * Zero entries that are not yet filled in. We do - * this to guard against bogus input data that causes - * us to index into undefined entries. If you can - * come up with a way to safely bounds-check input codes - * while decoding then you can remove this operation. - */ - _TIFFmemset(sp->dec_free_entp, 0, (CSIZE-CODE_FIRST)*sizeof (code_t)); - sp->dec_oldcodep = &sp->dec_codetab[-1]; - sp->dec_maxcodep = &sp->dec_codetab[sp->dec_nbitsmask-1]; - return (1); -} - -/* - * Decode a "hunk of data". - */ -#define GetNextCode(sp, bp, code) { \ - nextdata = (nextdata<<8) | *(bp)++; \ - nextbits += 8; \ - if (nextbits < nbits) { \ - nextdata = (nextdata<<8) | *(bp)++; \ - nextbits += 8; \ - } \ - code = (hcode_t)((nextdata >> (nextbits-nbits)) & nbitsmask); \ - nextbits -= nbits; \ -} - -static void -codeLoop(TIFF* tif, const char* module) -{ - TIFFErrorExt(tif->tif_clientdata, module, - "Bogus encoding, loop in the code table; scanline %d", - tif->tif_row); -} - -static int -LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) -{ - static const char module[] = "LZWDecode"; - LZWCodecState *sp = DecoderState(tif); - char *op = (char*) op0; - long occ = (long) occ0; - char *tp; - unsigned char *bp; - hcode_t code; - int len; - long nbits, nextbits, nextdata, nbitsmask; - code_t *codep, *free_entp, *maxcodep, *oldcodep; - - (void) s; - assert(sp != NULL); - assert(sp->dec_codetab != NULL); - - /* - Fail if value does not fit in long. - */ - if ((tmsize_t) occ != occ0) - return (0); - /* - * Restart interrupted output operation. - */ - if (sp->dec_restart) { - long residue; - - codep = sp->dec_codep; - residue = codep->length - sp->dec_restart; - if (residue > occ) { - /* - * Residue from previous decode is sufficient - * to satisfy decode request. Skip to the - * start of the decoded string, place decoded - * values in the output buffer, and return. - */ - sp->dec_restart += occ; - do { - codep = codep->next; - } while (--residue > occ && codep); - if (codep) { - tp = op + occ; - do { - *--tp = codep->value; - codep = codep->next; - } while (--occ && codep); - } - return (1); - } - /* - * Residue satisfies only part of the decode request. - */ - op += residue, occ -= residue; - tp = op; - do { - int t; - --tp; - t = codep->value; - codep = codep->next; - *tp = t; - } while (--residue && codep); - sp->dec_restart = 0; - } - - bp = (unsigned char *)tif->tif_rawcp; - nbits = sp->lzw_nbits; - nextdata = sp->lzw_nextdata; - nextbits = sp->lzw_nextbits; - nbitsmask = sp->dec_nbitsmask; - oldcodep = sp->dec_oldcodep; - free_entp = sp->dec_free_entp; - maxcodep = sp->dec_maxcodep; - - while (occ > 0) { - NextCode(tif, sp, bp, code, GetNextCode); - if (code == CODE_EOI) - break; - if (code == CODE_CLEAR) { - free_entp = sp->dec_codetab + CODE_FIRST; - _TIFFmemset(free_entp, 0, - (CSIZE - CODE_FIRST) * sizeof (code_t)); - nbits = BITS_MIN; - nbitsmask = MAXCODE(BITS_MIN); - maxcodep = sp->dec_codetab + nbitsmask-1; - NextCode(tif, sp, bp, code, GetNextCode); - if (code == CODE_EOI) - break; - if (code >= CODE_CLEAR) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "LZWDecode: Corrupted LZW table at scanline %d", - tif->tif_row); - return (0); - } - *op++ = (char)code, occ--; - oldcodep = sp->dec_codetab + code; - continue; - } - codep = sp->dec_codetab + code; - - /* - * Add the new entry to the code table. - */ - if (free_entp < &sp->dec_codetab[0] || - free_entp >= &sp->dec_codetab[CSIZE]) { - TIFFErrorExt(tif->tif_clientdata, module, - "Corrupted LZW table at scanline %d", - tif->tif_row); - return (0); - } - - free_entp->next = oldcodep; - if (free_entp->next < &sp->dec_codetab[0] || - free_entp->next >= &sp->dec_codetab[CSIZE]) { - TIFFErrorExt(tif->tif_clientdata, module, - "Corrupted LZW table at scanline %d", - tif->tif_row); - return (0); - } - free_entp->firstchar = free_entp->next->firstchar; - free_entp->length = free_entp->next->length+1; - free_entp->value = (codep < free_entp) ? - codep->firstchar : free_entp->firstchar; - if (++free_entp > maxcodep) { - if (++nbits > BITS_MAX) /* should not happen */ - nbits = BITS_MAX; - nbitsmask = MAXCODE(nbits); - maxcodep = sp->dec_codetab + nbitsmask-1; - } - oldcodep = codep; - if (code >= 256) { - /* - * Code maps to a string, copy string - * value to output (written in reverse). - */ - if(codep->length == 0) { - TIFFErrorExt(tif->tif_clientdata, module, - "Wrong length of decoded string: " - "data probably corrupted at scanline %d", - tif->tif_row); - return (0); - } - if (codep->length > occ) { - /* - * String is too long for decode buffer, - * locate portion that will fit, copy to - * the decode buffer, and setup restart - * logic for the next decoding call. - */ - sp->dec_codep = codep; - do { - codep = codep->next; - } while (codep && codep->length > occ); - if (codep) { - sp->dec_restart = (long)occ; - tp = op + occ; - do { - *--tp = codep->value; - codep = codep->next; - } while (--occ && codep); - if (codep) - codeLoop(tif, module); - } - break; - } - len = codep->length; - tp = op + len; - do { - int t; - --tp; - t = codep->value; - codep = codep->next; - *tp = t; - } while (codep && tp > op); - if (codep) { - codeLoop(tif, module); - break; - } - assert(occ >= len); - op += len, occ -= len; - } else - *op++ = (char)code, occ--; - } - - tif->tif_rawcp = (uint8*) bp; - sp->lzw_nbits = (unsigned short) nbits; - sp->lzw_nextdata = nextdata; - sp->lzw_nextbits = nextbits; - sp->dec_nbitsmask = nbitsmask; - sp->dec_oldcodep = oldcodep; - sp->dec_free_entp = free_entp; - sp->dec_maxcodep = maxcodep; - - if (occ > 0) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data at scanline %d (short %I64d bytes)", - tif->tif_row, (unsigned __int64) occ); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data at scanline %d (short %llu bytes)", - tif->tif_row, (unsigned long long) occ); -#endif - return (0); - } - return (1); -} - -#ifdef LZW_COMPAT -/* - * Decode a "hunk of data" for old images. - */ -#define GetNextCodeCompat(sp, bp, code) { \ - nextdata |= (unsigned long) *(bp)++ << nextbits; \ - nextbits += 8; \ - if (nextbits < nbits) { \ - nextdata |= (unsigned long) *(bp)++ << nextbits;\ - nextbits += 8; \ - } \ - code = (hcode_t)(nextdata & nbitsmask); \ - nextdata >>= nbits; \ - nextbits -= nbits; \ -} - -static int -LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) -{ - static const char module[] = "LZWDecodeCompat"; - LZWCodecState *sp = DecoderState(tif); - char *op = (char*) op0; - long occ = (long) occ0; - char *tp; - unsigned char *bp; - int code, nbits; - long nextbits, nextdata, nbitsmask; - code_t *codep, *free_entp, *maxcodep, *oldcodep; - - (void) s; - assert(sp != NULL); - - /* - Fail if value does not fit in long. - */ - if ((tmsize_t) occ != occ0) - return (0); - - /* - * Restart interrupted output operation. - */ - if (sp->dec_restart) { - long residue; - - codep = sp->dec_codep; - residue = codep->length - sp->dec_restart; - if (residue > occ) { - /* - * Residue from previous decode is sufficient - * to satisfy decode request. Skip to the - * start of the decoded string, place decoded - * values in the output buffer, and return. - */ - sp->dec_restart += occ; - do { - codep = codep->next; - } while (--residue > occ); - tp = op + occ; - do { - *--tp = codep->value; - codep = codep->next; - } while (--occ); - return (1); - } - /* - * Residue satisfies only part of the decode request. - */ - op += residue, occ -= residue; - tp = op; - do { - *--tp = codep->value; - codep = codep->next; - } while (--residue); - sp->dec_restart = 0; - } - - bp = (unsigned char *)tif->tif_rawcp; - nbits = sp->lzw_nbits; - nextdata = sp->lzw_nextdata; - nextbits = sp->lzw_nextbits; - nbitsmask = sp->dec_nbitsmask; - oldcodep = sp->dec_oldcodep; - free_entp = sp->dec_free_entp; - maxcodep = sp->dec_maxcodep; - - while (occ > 0) { - NextCode(tif, sp, bp, code, GetNextCodeCompat); - if (code == CODE_EOI) - break; - if (code == CODE_CLEAR) { - free_entp = sp->dec_codetab + CODE_FIRST; - _TIFFmemset(free_entp, 0, - (CSIZE - CODE_FIRST) * sizeof (code_t)); - nbits = BITS_MIN; - nbitsmask = MAXCODE(BITS_MIN); - maxcodep = sp->dec_codetab + nbitsmask; - NextCode(tif, sp, bp, code, GetNextCodeCompat); - if (code == CODE_EOI) - break; - if (code >= CODE_CLEAR) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "LZWDecode: Corrupted LZW table at scanline %d", - tif->tif_row); - return (0); - } - *op++ = code, occ--; - oldcodep = sp->dec_codetab + code; - continue; - } - codep = sp->dec_codetab + code; - - /* - * Add the new entry to the code table. - */ - if (free_entp < &sp->dec_codetab[0] || - free_entp >= &sp->dec_codetab[CSIZE]) { - TIFFErrorExt(tif->tif_clientdata, module, - "Corrupted LZW table at scanline %d", tif->tif_row); - return (0); - } - - free_entp->next = oldcodep; - if (free_entp->next < &sp->dec_codetab[0] || - free_entp->next >= &sp->dec_codetab[CSIZE]) { - TIFFErrorExt(tif->tif_clientdata, module, - "Corrupted LZW table at scanline %d", tif->tif_row); - return (0); - } - free_entp->firstchar = free_entp->next->firstchar; - free_entp->length = free_entp->next->length+1; - free_entp->value = (codep < free_entp) ? - codep->firstchar : free_entp->firstchar; - if (++free_entp > maxcodep) { - if (++nbits > BITS_MAX) /* should not happen */ - nbits = BITS_MAX; - nbitsmask = MAXCODE(nbits); - maxcodep = sp->dec_codetab + nbitsmask; - } - oldcodep = codep; - if (code >= 256) { - /* - * Code maps to a string, copy string - * value to output (written in reverse). - */ - if(codep->length == 0) { - TIFFErrorExt(tif->tif_clientdata, module, - "Wrong length of decoded " - "string: data probably corrupted at scanline %d", - tif->tif_row); - return (0); - } - if (codep->length > occ) { - /* - * String is too long for decode buffer, - * locate portion that will fit, copy to - * the decode buffer, and setup restart - * logic for the next decoding call. - */ - sp->dec_codep = codep; - do { - codep = codep->next; - } while (codep->length > occ); - sp->dec_restart = occ; - tp = op + occ; - do { - *--tp = codep->value; - codep = codep->next; - } while (--occ); - break; - } - assert(occ >= codep->length); - op += codep->length, occ -= codep->length; - tp = op; - do { - *--tp = codep->value; - } while( (codep = codep->next) != NULL ); - } else - *op++ = code, occ--; - } - - tif->tif_rawcp = (uint8*) bp; - sp->lzw_nbits = nbits; - sp->lzw_nextdata = nextdata; - sp->lzw_nextbits = nextbits; - sp->dec_nbitsmask = nbitsmask; - sp->dec_oldcodep = oldcodep; - sp->dec_free_entp = free_entp; - sp->dec_maxcodep = maxcodep; - - if (occ > 0) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data at scanline %d (short %I64d bytes)", - tif->tif_row, (unsigned __int64) occ); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data at scanline %d (short %llu bytes)", - tif->tif_row, (unsigned long long) occ); -#endif - return (0); - } - return (1); -} -#endif /* LZW_COMPAT */ - -/* - * LZW Encoding. - */ - -static int -LZWSetupEncode(TIFF* tif) -{ - static const char module[] = "LZWSetupEncode"; - LZWCodecState* sp = EncoderState(tif); - - assert(sp != NULL); - sp->enc_hashtab = (hash_t*) _TIFFmalloc(HSIZE*sizeof (hash_t)); - if (sp->enc_hashtab == NULL) { - TIFFErrorExt(tif->tif_clientdata, module, - "No space for LZW hash table"); - return (0); - } - return (1); -} - -/* - * Reset encoding state at the start of a strip. - */ -static int -LZWPreEncode(TIFF* tif, uint16 s) -{ - LZWCodecState *sp = EncoderState(tif); - - (void) s; - assert(sp != NULL); - - if( sp->enc_hashtab == NULL ) - { - tif->tif_setupencode( tif ); - } - - sp->lzw_nbits = BITS_MIN; - sp->lzw_maxcode = MAXCODE(BITS_MIN); - sp->lzw_free_ent = CODE_FIRST; - sp->lzw_nextbits = 0; - sp->lzw_nextdata = 0; - sp->enc_checkpoint = CHECK_GAP; - sp->enc_ratio = 0; - sp->enc_incount = 0; - sp->enc_outcount = 0; - /* - * The 4 here insures there is space for 2 max-sized - * codes in LZWEncode and LZWPostDecode. - */ - sp->enc_rawlimit = tif->tif_rawdata + tif->tif_rawdatasize-1 - 4; - cl_hash(sp); /* clear hash table */ - sp->enc_oldcode = (hcode_t) -1; /* generates CODE_CLEAR in LZWEncode */ - return (1); -} - -#define CALCRATIO(sp, rat) { \ - if (incount > 0x007fffff) { /* NB: shift will overflow */\ - rat = outcount >> 8; \ - rat = (rat == 0 ? 0x7fffffff : incount/rat); \ - } else \ - rat = (incount<<8) / outcount; \ -} -#define PutNextCode(op, c) { \ - nextdata = (nextdata << nbits) | c; \ - nextbits += nbits; \ - *op++ = (unsigned char)(nextdata >> (nextbits-8)); \ - nextbits -= 8; \ - if (nextbits >= 8) { \ - *op++ = (unsigned char)(nextdata >> (nextbits-8)); \ - nextbits -= 8; \ - } \ - outcount += nbits; \ -} - -/* - * Encode a chunk of pixels. - * - * Uses an open addressing double hashing (no chaining) on the - * prefix code/next character combination. We do a variant of - * Knuth's algorithm D (vol. 3, sec. 6.4) along with G. Knott's - * relatively-prime secondary probe. Here, the modular division - * first probe is gives way to a faster exclusive-or manipulation. - * Also do block compression with an adaptive reset, whereby the - * code table is cleared when the compression ratio decreases, - * but after the table fills. The variable-length output codes - * are re-sized at this point, and a CODE_CLEAR is generated - * for the decoder. - */ -static int -LZWEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - register LZWCodecState *sp = EncoderState(tif); - register long fcode; - register hash_t *hp; - register int h, c; - hcode_t ent; - long disp; - long incount, outcount, checkpoint; - long nextdata, nextbits; - int free_ent, maxcode, nbits; - uint8* op; - uint8* limit; - - (void) s; - if (sp == NULL) - return (0); - - assert(sp->enc_hashtab != NULL); - - /* - * Load local state. - */ - incount = sp->enc_incount; - outcount = sp->enc_outcount; - checkpoint = sp->enc_checkpoint; - nextdata = sp->lzw_nextdata; - nextbits = sp->lzw_nextbits; - free_ent = sp->lzw_free_ent; - maxcode = sp->lzw_maxcode; - nbits = sp->lzw_nbits; - op = tif->tif_rawcp; - limit = sp->enc_rawlimit; - ent = sp->enc_oldcode; - - if (ent == (hcode_t) -1 && cc > 0) { - /* - * NB: This is safe because it can only happen - * at the start of a strip where we know there - * is space in the data buffer. - */ - PutNextCode(op, CODE_CLEAR); - ent = *bp++; cc--; incount++; - } - while (cc > 0) { - c = *bp++; cc--; incount++; - fcode = ((long)c << BITS_MAX) + ent; - h = (c << HSHIFT) ^ ent; /* xor hashing */ -#ifdef _WINDOWS - /* - * Check hash index for an overflow. - */ - if (h >= HSIZE) - h -= HSIZE; -#endif - hp = &sp->enc_hashtab[h]; - if (hp->hash == fcode) { - ent = hp->code; - continue; - } - if (hp->hash >= 0) { - /* - * Primary hash failed, check secondary hash. - */ - disp = HSIZE - h; - if (h == 0) - disp = 1; - do { - /* - * Avoid pointer arithmetic 'cuz of - * wraparound problems with segments. - */ - if ((h -= disp) < 0) - h += HSIZE; - hp = &sp->enc_hashtab[h]; - if (hp->hash == fcode) { - ent = hp->code; - goto hit; - } - } while (hp->hash >= 0); - } - /* - * New entry, emit code and add to table. - */ - /* - * Verify there is space in the buffer for the code - * and any potential Clear code that might be emitted - * below. The value of limit is setup so that there - * are at least 4 bytes free--room for 2 codes. - */ - if (op > limit) { - tif->tif_rawcc = (tmsize_t)(op - tif->tif_rawdata); - TIFFFlushData1(tif); - op = tif->tif_rawdata; - } - PutNextCode(op, ent); - ent = c; - hp->code = free_ent++; - hp->hash = fcode; - if (free_ent == CODE_MAX-1) { - /* table is full, emit clear code and reset */ - cl_hash(sp); - sp->enc_ratio = 0; - incount = 0; - outcount = 0; - free_ent = CODE_FIRST; - PutNextCode(op, CODE_CLEAR); - nbits = BITS_MIN; - maxcode = MAXCODE(BITS_MIN); - } else { - /* - * If the next entry is going to be too big for - * the code size, then increase it, if possible. - */ - if (free_ent > maxcode) { - nbits++; - assert(nbits <= BITS_MAX); - maxcode = (int) MAXCODE(nbits); - } else if (incount >= checkpoint) { - long rat; - /* - * Check compression ratio and, if things seem - * to be slipping, clear the hash table and - * reset state. The compression ratio is a - * 24+8-bit fractional number. - */ - checkpoint = incount+CHECK_GAP; - CALCRATIO(sp, rat); - if (rat <= sp->enc_ratio) { - cl_hash(sp); - sp->enc_ratio = 0; - incount = 0; - outcount = 0; - free_ent = CODE_FIRST; - PutNextCode(op, CODE_CLEAR); - nbits = BITS_MIN; - maxcode = MAXCODE(BITS_MIN); - } else - sp->enc_ratio = rat; - } - } - hit: - ; - } - - /* - * Restore global state. - */ - sp->enc_incount = incount; - sp->enc_outcount = outcount; - sp->enc_checkpoint = checkpoint; - sp->enc_oldcode = ent; - sp->lzw_nextdata = nextdata; - sp->lzw_nextbits = nextbits; - sp->lzw_free_ent = free_ent; - sp->lzw_maxcode = maxcode; - sp->lzw_nbits = nbits; - tif->tif_rawcp = op; - return (1); -} - -/* - * Finish off an encoded strip by flushing the last - * string and tacking on an End Of Information code. - */ -static int -LZWPostEncode(TIFF* tif) -{ - register LZWCodecState *sp = EncoderState(tif); - uint8* op = tif->tif_rawcp; - long nextbits = sp->lzw_nextbits; - long nextdata = sp->lzw_nextdata; - long outcount = sp->enc_outcount; - int nbits = sp->lzw_nbits; - - if (op > sp->enc_rawlimit) { - tif->tif_rawcc = (tmsize_t)(op - tif->tif_rawdata); - TIFFFlushData1(tif); - op = tif->tif_rawdata; - } - if (sp->enc_oldcode != (hcode_t) -1) { - PutNextCode(op, sp->enc_oldcode); - sp->enc_oldcode = (hcode_t) -1; - } - PutNextCode(op, CODE_EOI); - if (nextbits > 0) - *op++ = (unsigned char)(nextdata << (8-nextbits)); - tif->tif_rawcc = (tmsize_t)(op - tif->tif_rawdata); - return (1); -} - -/* - * Reset encoding hash table. - */ -static void -cl_hash(LZWCodecState* sp) -{ - register hash_t *hp = &sp->enc_hashtab[HSIZE-1]; - register long i = HSIZE-8; - - do { - i -= 8; - hp[-7].hash = -1; - hp[-6].hash = -1; - hp[-5].hash = -1; - hp[-4].hash = -1; - hp[-3].hash = -1; - hp[-2].hash = -1; - hp[-1].hash = -1; - hp[ 0].hash = -1; - hp -= 8; - } while (i >= 0); - for (i += 8; i > 0; i--, hp--) - hp->hash = -1; -} - -static void -LZWCleanup(TIFF* tif) -{ - (void)TIFFPredictorCleanup(tif); - - assert(tif->tif_data != 0); - - if (DecoderState(tif)->dec_codetab) - _TIFFfree(DecoderState(tif)->dec_codetab); - - if (EncoderState(tif)->enc_hashtab) - _TIFFfree(EncoderState(tif)->enc_hashtab); - - _TIFFfree(tif->tif_data); - tif->tif_data = NULL; - - _TIFFSetDefaultCompressionState(tif); -} - -int -TIFFInitLZW(TIFF* tif, int scheme) -{ - static const char module[] = "TIFFInitLZW"; - assert(scheme == COMPRESSION_LZW); - /* - * Allocate state block so tag methods have storage to record values. - */ - tif->tif_data = (uint8*) _TIFFmalloc(sizeof (LZWCodecState)); - if (tif->tif_data == NULL) - goto bad; - DecoderState(tif)->dec_codetab = NULL; - DecoderState(tif)->dec_decode = NULL; - EncoderState(tif)->enc_hashtab = NULL; - LZWState(tif)->rw_mode = tif->tif_mode; - - /* - * Install codec methods. - */ - tif->tif_fixuptags = LZWFixupTags; - tif->tif_setupdecode = LZWSetupDecode; - tif->tif_predecode = LZWPreDecode; - tif->tif_decoderow = LZWDecode; - tif->tif_decodestrip = LZWDecode; - tif->tif_decodetile = LZWDecode; - tif->tif_setupencode = LZWSetupEncode; - tif->tif_preencode = LZWPreEncode; - tif->tif_postencode = LZWPostEncode; - tif->tif_encoderow = LZWEncode; - tif->tif_encodestrip = LZWEncode; - tif->tif_encodetile = LZWEncode; - tif->tif_cleanup = LZWCleanup; - /* - * Setup predictor setup. - */ - (void) TIFFPredictorInit(tif); - return (1); -bad: - TIFFErrorExt(tif->tif_clientdata, module, - "No space for LZW state block"); - return (0); -} - -/* - * Copyright (c) 1985, 1986 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * James A. Woods, derived from original work by Spencer Thomas - * and Joseph Orost. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - */ -#endif /* LZW_SUPPORT */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_lzw.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include "tiffiop.h" +#ifdef LZW_SUPPORT +/* + * TIFF Library. + * Rev 5.0 Lempel-Ziv & Welch Compression Support + * + * This code is derived from the compress program whose code is + * derived from software contributed to Berkeley by James A. Woods, + * derived from original work by Spencer Thomas and Joseph Orost. + * + * The original Berkeley copyright notice appears below in its entirety. + */ +#include "tif_predict.h" + +#include + +/* + * NB: The 5.0 spec describes a different algorithm than Aldus + * implements. Specifically, Aldus does code length transitions + * one code earlier than should be done (for real LZW). + * Earlier versions of this library implemented the correct + * LZW algorithm, but emitted codes in a bit order opposite + * to the TIFF spec. Thus, to maintain compatibility w/ Aldus + * we interpret MSB-LSB ordered codes to be images written w/ + * old versions of this library, but otherwise adhere to the + * Aldus "off by one" algorithm. + * + * Future revisions to the TIFF spec are expected to "clarify this issue". + */ +#define LZW_COMPAT /* include backwards compatibility code */ +/* + * Each strip of data is supposed to be terminated by a CODE_EOI. + * If the following #define is included, the decoder will also + * check for end-of-strip w/o seeing this code. This makes the + * library more robust, but also slower. + */ +#define LZW_CHECKEOS /* include checks for strips w/o EOI code */ + +#define MAXCODE(n) ((1L<<(n))-1) +/* + * The TIFF spec specifies that encoded bit + * strings range from 9 to 12 bits. + */ +#define BITS_MIN 9 /* start with 9 bits */ +#define BITS_MAX 12 /* max of 12 bit strings */ +/* predefined codes */ +#define CODE_CLEAR 256 /* code to clear string table */ +#define CODE_EOI 257 /* end-of-information code */ +#define CODE_FIRST 258 /* first free code entry */ +#define CODE_MAX MAXCODE(BITS_MAX) +#define HSIZE 9001L /* 91% occupancy */ +#define HSHIFT (13-8) +#ifdef LZW_COMPAT +/* NB: +1024 is for compatibility with old files */ +#define CSIZE (MAXCODE(BITS_MAX)+1024L) +#else +#define CSIZE (MAXCODE(BITS_MAX)+1L) +#endif + +/* + * State block for each open TIFF file using LZW + * compression/decompression. Note that the predictor + * state block must be first in this data structure. + */ +typedef struct { + TIFFPredictorState predict; /* predictor super class */ + + unsigned short nbits; /* # of bits/code */ + unsigned short maxcode; /* maximum code for lzw_nbits */ + unsigned short free_ent; /* next free entry in hash table */ + long nextdata; /* next bits of i/o */ + long nextbits; /* # of valid bits in lzw_nextdata */ + + int rw_mode; /* preserve rw_mode from init */ +} LZWBaseState; + +#define lzw_nbits base.nbits +#define lzw_maxcode base.maxcode +#define lzw_free_ent base.free_ent +#define lzw_nextdata base.nextdata +#define lzw_nextbits base.nextbits + +/* + * Encoding-specific state. + */ +typedef uint16 hcode_t; /* codes fit in 16 bits */ +typedef struct { + long hash; + hcode_t code; +} hash_t; + +/* + * Decoding-specific state. + */ +typedef struct code_ent { + struct code_ent *next; + unsigned short length; /* string len, including this token */ + unsigned char value; /* data value */ + unsigned char firstchar; /* first token of string */ +} code_t; + +typedef int (*decodeFunc)(TIFF*, uint8*, tmsize_t, uint16); + +typedef struct { + LZWBaseState base; + + /* Decoding specific data */ + long dec_nbitsmask; /* lzw_nbits 1 bits, right adjusted */ + long dec_restart; /* restart count */ +#ifdef LZW_CHECKEOS + uint64 dec_bitsleft; /* available bits in raw data */ +#endif + decodeFunc dec_decode; /* regular or backwards compatible */ + code_t* dec_codep; /* current recognized code */ + code_t* dec_oldcodep; /* previously recognized code */ + code_t* dec_free_entp; /* next free entry */ + code_t* dec_maxcodep; /* max available entry */ + code_t* dec_codetab; /* kept separate for small machines */ + + /* Encoding specific data */ + int enc_oldcode; /* last code encountered */ + long enc_checkpoint; /* point at which to clear table */ +#define CHECK_GAP 10000 /* enc_ratio check interval */ + long enc_ratio; /* current compression ratio */ + long enc_incount; /* (input) data bytes encoded */ + long enc_outcount; /* encoded (output) bytes */ + uint8* enc_rawlimit; /* bound on tif_rawdata buffer */ + hash_t* enc_hashtab; /* kept separate for small machines */ +} LZWCodecState; + +#define LZWState(tif) ((LZWBaseState*) (tif)->tif_data) +#define DecoderState(tif) ((LZWCodecState*) LZWState(tif)) +#define EncoderState(tif) ((LZWCodecState*) LZWState(tif)) + +static int LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); +#ifdef LZW_COMPAT +static int LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); +#endif +static void cl_hash(LZWCodecState*); + +/* + * LZW Decoder. + */ + +#ifdef LZW_CHECKEOS +/* + * This check shouldn't be necessary because each + * strip is suppose to be terminated with CODE_EOI. + */ +#define NextCode(_tif, _sp, _bp, _code, _get) { \ + if ((_sp)->dec_bitsleft < (uint64)nbits) { \ + TIFFWarningExt(_tif->tif_clientdata, module, \ + "LZWDecode: Strip %d not terminated with EOI code", \ + _tif->tif_curstrip); \ + _code = CODE_EOI; \ + } else { \ + _get(_sp,_bp,_code); \ + (_sp)->dec_bitsleft -= nbits; \ + } \ +} +#else +#define NextCode(tif, sp, bp, code, get) get(sp, bp, code) +#endif + +static int +LZWFixupTags(TIFF* tif) +{ + (void) tif; + return (1); +} + +static int +LZWSetupDecode(TIFF* tif) +{ + static const char module[] = "LZWSetupDecode"; + LZWCodecState* sp = DecoderState(tif); + int code; + + if( sp == NULL ) + { + /* + * Allocate state block so tag methods have storage to record + * values. + */ + tif->tif_data = (uint8*) _TIFFmalloc(sizeof(LZWCodecState)); + if (tif->tif_data == NULL) + { + TIFFErrorExt(tif->tif_clientdata, module, "No space for LZW state block"); + return (0); + } + + DecoderState(tif)->dec_codetab = NULL; + DecoderState(tif)->dec_decode = NULL; + + /* + * Setup predictor setup. + */ + (void) TIFFPredictorInit(tif); + + sp = DecoderState(tif); + } + + assert(sp != NULL); + + if (sp->dec_codetab == NULL) { + sp->dec_codetab = (code_t*)_TIFFmalloc(CSIZE*sizeof (code_t)); + if (sp->dec_codetab == NULL) { + TIFFErrorExt(tif->tif_clientdata, module, + "No space for LZW code table"); + return (0); + } + /* + * Pre-load the table. + */ + code = 255; + do { + sp->dec_codetab[code].value = code; + sp->dec_codetab[code].firstchar = code; + sp->dec_codetab[code].length = 1; + sp->dec_codetab[code].next = NULL; + } while (code--); + /* + * Zero-out the unused entries + */ + _TIFFmemset(&sp->dec_codetab[CODE_CLEAR], 0, + (CODE_FIRST - CODE_CLEAR) * sizeof (code_t)); + } + return (1); +} + +/* + * Setup state for decoding a strip. + */ +static int +LZWPreDecode(TIFF* tif, uint16 s) +{ + static const char module[] = "LZWPreDecode"; + LZWCodecState *sp = DecoderState(tif); + + (void) s; + assert(sp != NULL); + if( sp->dec_codetab == NULL ) + { + tif->tif_setupdecode( tif ); + } + + /* + * Check for old bit-reversed codes. + */ + if (tif->tif_rawdata[0] == 0 && (tif->tif_rawdata[1] & 0x1)) { +#ifdef LZW_COMPAT + if (!sp->dec_decode) { + TIFFWarningExt(tif->tif_clientdata, module, + "Old-style LZW codes, convert file"); + /* + * Override default decoding methods with + * ones that deal with the old coding. + * Otherwise the predictor versions set + * above will call the compatibility routines + * through the dec_decode method. + */ + tif->tif_decoderow = LZWDecodeCompat; + tif->tif_decodestrip = LZWDecodeCompat; + tif->tif_decodetile = LZWDecodeCompat; + /* + * If doing horizontal differencing, must + * re-setup the predictor logic since we + * switched the basic decoder methods... + */ + (*tif->tif_setupdecode)(tif); + sp->dec_decode = LZWDecodeCompat; + } + sp->lzw_maxcode = MAXCODE(BITS_MIN); +#else /* !LZW_COMPAT */ + if (!sp->dec_decode) { + TIFFErrorExt(tif->tif_clientdata, module, + "Old-style LZW codes not supported"); + sp->dec_decode = LZWDecode; + } + return (0); +#endif/* !LZW_COMPAT */ + } else { + sp->lzw_maxcode = MAXCODE(BITS_MIN)-1; + sp->dec_decode = LZWDecode; + } + sp->lzw_nbits = BITS_MIN; + sp->lzw_nextbits = 0; + sp->lzw_nextdata = 0; + + sp->dec_restart = 0; + sp->dec_nbitsmask = MAXCODE(BITS_MIN); +#ifdef LZW_CHECKEOS + sp->dec_bitsleft = ((uint64)tif->tif_rawcc) << 3; +#endif + sp->dec_free_entp = sp->dec_codetab + CODE_FIRST; + /* + * Zero entries that are not yet filled in. We do + * this to guard against bogus input data that causes + * us to index into undefined entries. If you can + * come up with a way to safely bounds-check input codes + * while decoding then you can remove this operation. + */ + _TIFFmemset(sp->dec_free_entp, 0, (CSIZE-CODE_FIRST)*sizeof (code_t)); + sp->dec_oldcodep = &sp->dec_codetab[-1]; + sp->dec_maxcodep = &sp->dec_codetab[sp->dec_nbitsmask-1]; + return (1); +} + +/* + * Decode a "hunk of data". + */ +#define GetNextCode(sp, bp, code) { \ + nextdata = (nextdata<<8) | *(bp)++; \ + nextbits += 8; \ + if (nextbits < nbits) { \ + nextdata = (nextdata<<8) | *(bp)++; \ + nextbits += 8; \ + } \ + code = (hcode_t)((nextdata >> (nextbits-nbits)) & nbitsmask); \ + nextbits -= nbits; \ +} + +static void +codeLoop(TIFF* tif, const char* module) +{ + TIFFErrorExt(tif->tif_clientdata, module, + "Bogus encoding, loop in the code table; scanline %d", + tif->tif_row); +} + +static int +LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) +{ + static const char module[] = "LZWDecode"; + LZWCodecState *sp = DecoderState(tif); + char *op = (char*) op0; + long occ = (long) occ0; + char *tp; + unsigned char *bp; + hcode_t code; + int len; + long nbits, nextbits, nextdata, nbitsmask; + code_t *codep, *free_entp, *maxcodep, *oldcodep; + + (void) s; + assert(sp != NULL); + assert(sp->dec_codetab != NULL); + + /* + Fail if value does not fit in long. + */ + if ((tmsize_t) occ != occ0) + return (0); + /* + * Restart interrupted output operation. + */ + if (sp->dec_restart) { + long residue; + + codep = sp->dec_codep; + residue = codep->length - sp->dec_restart; + if (residue > occ) { + /* + * Residue from previous decode is sufficient + * to satisfy decode request. Skip to the + * start of the decoded string, place decoded + * values in the output buffer, and return. + */ + sp->dec_restart += occ; + do { + codep = codep->next; + } while (--residue > occ && codep); + if (codep) { + tp = op + occ; + do { + *--tp = codep->value; + codep = codep->next; + } while (--occ && codep); + } + return (1); + } + /* + * Residue satisfies only part of the decode request. + */ + op += residue, occ -= residue; + tp = op; + do { + int t; + --tp; + t = codep->value; + codep = codep->next; + *tp = t; + } while (--residue && codep); + sp->dec_restart = 0; + } + + bp = (unsigned char *)tif->tif_rawcp; + nbits = sp->lzw_nbits; + nextdata = sp->lzw_nextdata; + nextbits = sp->lzw_nextbits; + nbitsmask = sp->dec_nbitsmask; + oldcodep = sp->dec_oldcodep; + free_entp = sp->dec_free_entp; + maxcodep = sp->dec_maxcodep; + + while (occ > 0) { + NextCode(tif, sp, bp, code, GetNextCode); + if (code == CODE_EOI) + break; + if (code == CODE_CLEAR) { + free_entp = sp->dec_codetab + CODE_FIRST; + _TIFFmemset(free_entp, 0, + (CSIZE - CODE_FIRST) * sizeof (code_t)); + nbits = BITS_MIN; + nbitsmask = MAXCODE(BITS_MIN); + maxcodep = sp->dec_codetab + nbitsmask-1; + NextCode(tif, sp, bp, code, GetNextCode); + if (code == CODE_EOI) + break; + if (code >= CODE_CLEAR) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "LZWDecode: Corrupted LZW table at scanline %d", + tif->tif_row); + return (0); + } + *op++ = (char)code, occ--; + oldcodep = sp->dec_codetab + code; + continue; + } + codep = sp->dec_codetab + code; + + /* + * Add the new entry to the code table. + */ + if (free_entp < &sp->dec_codetab[0] || + free_entp >= &sp->dec_codetab[CSIZE]) { + TIFFErrorExt(tif->tif_clientdata, module, + "Corrupted LZW table at scanline %d", + tif->tif_row); + return (0); + } + + free_entp->next = oldcodep; + if (free_entp->next < &sp->dec_codetab[0] || + free_entp->next >= &sp->dec_codetab[CSIZE]) { + TIFFErrorExt(tif->tif_clientdata, module, + "Corrupted LZW table at scanline %d", + tif->tif_row); + return (0); + } + free_entp->firstchar = free_entp->next->firstchar; + free_entp->length = free_entp->next->length+1; + free_entp->value = (codep < free_entp) ? + codep->firstchar : free_entp->firstchar; + if (++free_entp > maxcodep) { + if (++nbits > BITS_MAX) /* should not happen */ + nbits = BITS_MAX; + nbitsmask = MAXCODE(nbits); + maxcodep = sp->dec_codetab + nbitsmask-1; + } + oldcodep = codep; + if (code >= 256) { + /* + * Code maps to a string, copy string + * value to output (written in reverse). + */ + if(codep->length == 0) { + TIFFErrorExt(tif->tif_clientdata, module, + "Wrong length of decoded string: " + "data probably corrupted at scanline %d", + tif->tif_row); + return (0); + } + if (codep->length > occ) { + /* + * String is too long for decode buffer, + * locate portion that will fit, copy to + * the decode buffer, and setup restart + * logic for the next decoding call. + */ + sp->dec_codep = codep; + do { + codep = codep->next; + } while (codep && codep->length > occ); + if (codep) { + sp->dec_restart = (long)occ; + tp = op + occ; + do { + *--tp = codep->value; + codep = codep->next; + } while (--occ && codep); + if (codep) + codeLoop(tif, module); + } + break; + } + len = codep->length; + tp = op + len; + do { + int t; + --tp; + t = codep->value; + codep = codep->next; + *tp = t; + } while (codep && tp > op); + if (codep) { + codeLoop(tif, module); + break; + } + assert(occ >= len); + op += len, occ -= len; + } else + *op++ = (char)code, occ--; + } + + tif->tif_rawcp = (uint8*) bp; + sp->lzw_nbits = (unsigned short) nbits; + sp->lzw_nextdata = nextdata; + sp->lzw_nextbits = nextbits; + sp->dec_nbitsmask = nbitsmask; + sp->dec_oldcodep = oldcodep; + sp->dec_free_entp = free_entp; + sp->dec_maxcodep = maxcodep; + + if (occ > 0) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + "Not enough data at scanline %d (short %I64d bytes)", + tif->tif_row, (unsigned __int64) occ); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "Not enough data at scanline %d (short %llu bytes)", + tif->tif_row, (unsigned long long) occ); +#endif + return (0); + } + return (1); +} + +#ifdef LZW_COMPAT +/* + * Decode a "hunk of data" for old images. + */ +#define GetNextCodeCompat(sp, bp, code) { \ + nextdata |= (unsigned long) *(bp)++ << nextbits; \ + nextbits += 8; \ + if (nextbits < nbits) { \ + nextdata |= (unsigned long) *(bp)++ << nextbits;\ + nextbits += 8; \ + } \ + code = (hcode_t)(nextdata & nbitsmask); \ + nextdata >>= nbits; \ + nextbits -= nbits; \ +} + +static int +LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) +{ + static const char module[] = "LZWDecodeCompat"; + LZWCodecState *sp = DecoderState(tif); + char *op = (char*) op0; + long occ = (long) occ0; + char *tp; + unsigned char *bp; + int code, nbits; + long nextbits, nextdata, nbitsmask; + code_t *codep, *free_entp, *maxcodep, *oldcodep; + + (void) s; + assert(sp != NULL); + + /* + Fail if value does not fit in long. + */ + if ((tmsize_t) occ != occ0) + return (0); + + /* + * Restart interrupted output operation. + */ + if (sp->dec_restart) { + long residue; + + codep = sp->dec_codep; + residue = codep->length - sp->dec_restart; + if (residue > occ) { + /* + * Residue from previous decode is sufficient + * to satisfy decode request. Skip to the + * start of the decoded string, place decoded + * values in the output buffer, and return. + */ + sp->dec_restart += occ; + do { + codep = codep->next; + } while (--residue > occ); + tp = op + occ; + do { + *--tp = codep->value; + codep = codep->next; + } while (--occ); + return (1); + } + /* + * Residue satisfies only part of the decode request. + */ + op += residue, occ -= residue; + tp = op; + do { + *--tp = codep->value; + codep = codep->next; + } while (--residue); + sp->dec_restart = 0; + } + + bp = (unsigned char *)tif->tif_rawcp; + nbits = sp->lzw_nbits; + nextdata = sp->lzw_nextdata; + nextbits = sp->lzw_nextbits; + nbitsmask = sp->dec_nbitsmask; + oldcodep = sp->dec_oldcodep; + free_entp = sp->dec_free_entp; + maxcodep = sp->dec_maxcodep; + + while (occ > 0) { + NextCode(tif, sp, bp, code, GetNextCodeCompat); + if (code == CODE_EOI) + break; + if (code == CODE_CLEAR) { + free_entp = sp->dec_codetab + CODE_FIRST; + _TIFFmemset(free_entp, 0, + (CSIZE - CODE_FIRST) * sizeof (code_t)); + nbits = BITS_MIN; + nbitsmask = MAXCODE(BITS_MIN); + maxcodep = sp->dec_codetab + nbitsmask; + NextCode(tif, sp, bp, code, GetNextCodeCompat); + if (code == CODE_EOI) + break; + if (code >= CODE_CLEAR) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "LZWDecode: Corrupted LZW table at scanline %d", + tif->tif_row); + return (0); + } + *op++ = code, occ--; + oldcodep = sp->dec_codetab + code; + continue; + } + codep = sp->dec_codetab + code; + + /* + * Add the new entry to the code table. + */ + if (free_entp < &sp->dec_codetab[0] || + free_entp >= &sp->dec_codetab[CSIZE]) { + TIFFErrorExt(tif->tif_clientdata, module, + "Corrupted LZW table at scanline %d", tif->tif_row); + return (0); + } + + free_entp->next = oldcodep; + if (free_entp->next < &sp->dec_codetab[0] || + free_entp->next >= &sp->dec_codetab[CSIZE]) { + TIFFErrorExt(tif->tif_clientdata, module, + "Corrupted LZW table at scanline %d", tif->tif_row); + return (0); + } + free_entp->firstchar = free_entp->next->firstchar; + free_entp->length = free_entp->next->length+1; + free_entp->value = (codep < free_entp) ? + codep->firstchar : free_entp->firstchar; + if (++free_entp > maxcodep) { + if (++nbits > BITS_MAX) /* should not happen */ + nbits = BITS_MAX; + nbitsmask = MAXCODE(nbits); + maxcodep = sp->dec_codetab + nbitsmask; + } + oldcodep = codep; + if (code >= 256) { + /* + * Code maps to a string, copy string + * value to output (written in reverse). + */ + if(codep->length == 0) { + TIFFErrorExt(tif->tif_clientdata, module, + "Wrong length of decoded " + "string: data probably corrupted at scanline %d", + tif->tif_row); + return (0); + } + if (codep->length > occ) { + /* + * String is too long for decode buffer, + * locate portion that will fit, copy to + * the decode buffer, and setup restart + * logic for the next decoding call. + */ + sp->dec_codep = codep; + do { + codep = codep->next; + } while (codep->length > occ); + sp->dec_restart = occ; + tp = op + occ; + do { + *--tp = codep->value; + codep = codep->next; + } while (--occ); + break; + } + assert(occ >= codep->length); + op += codep->length, occ -= codep->length; + tp = op; + do { + *--tp = codep->value; + } while( (codep = codep->next) != NULL ); + } else + *op++ = code, occ--; + } + + tif->tif_rawcp = (uint8*) bp; + sp->lzw_nbits = nbits; + sp->lzw_nextdata = nextdata; + sp->lzw_nextbits = nextbits; + sp->dec_nbitsmask = nbitsmask; + sp->dec_oldcodep = oldcodep; + sp->dec_free_entp = free_entp; + sp->dec_maxcodep = maxcodep; + + if (occ > 0) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + "Not enough data at scanline %d (short %I64d bytes)", + tif->tif_row, (unsigned __int64) occ); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "Not enough data at scanline %d (short %llu bytes)", + tif->tif_row, (unsigned long long) occ); +#endif + return (0); + } + return (1); +} +#endif /* LZW_COMPAT */ + +/* + * LZW Encoding. + */ + +static int +LZWSetupEncode(TIFF* tif) +{ + static const char module[] = "LZWSetupEncode"; + LZWCodecState* sp = EncoderState(tif); + + assert(sp != NULL); + sp->enc_hashtab = (hash_t*) _TIFFmalloc(HSIZE*sizeof (hash_t)); + if (sp->enc_hashtab == NULL) { + TIFFErrorExt(tif->tif_clientdata, module, + "No space for LZW hash table"); + return (0); + } + return (1); +} + +/* + * Reset encoding state at the start of a strip. + */ +static int +LZWPreEncode(TIFF* tif, uint16 s) +{ + LZWCodecState *sp = EncoderState(tif); + + (void) s; + assert(sp != NULL); + + if( sp->enc_hashtab == NULL ) + { + tif->tif_setupencode( tif ); + } + + sp->lzw_nbits = BITS_MIN; + sp->lzw_maxcode = MAXCODE(BITS_MIN); + sp->lzw_free_ent = CODE_FIRST; + sp->lzw_nextbits = 0; + sp->lzw_nextdata = 0; + sp->enc_checkpoint = CHECK_GAP; + sp->enc_ratio = 0; + sp->enc_incount = 0; + sp->enc_outcount = 0; + /* + * The 4 here insures there is space for 2 max-sized + * codes in LZWEncode and LZWPostDecode. + */ + sp->enc_rawlimit = tif->tif_rawdata + tif->tif_rawdatasize-1 - 4; + cl_hash(sp); /* clear hash table */ + sp->enc_oldcode = (hcode_t) -1; /* generates CODE_CLEAR in LZWEncode */ + return (1); +} + +#define CALCRATIO(sp, rat) { \ + if (incount > 0x007fffff) { /* NB: shift will overflow */\ + rat = outcount >> 8; \ + rat = (rat == 0 ? 0x7fffffff : incount/rat); \ + } else \ + rat = (incount<<8) / outcount; \ +} +#define PutNextCode(op, c) { \ + nextdata = (nextdata << nbits) | c; \ + nextbits += nbits; \ + *op++ = (unsigned char)(nextdata >> (nextbits-8)); \ + nextbits -= 8; \ + if (nextbits >= 8) { \ + *op++ = (unsigned char)(nextdata >> (nextbits-8)); \ + nextbits -= 8; \ + } \ + outcount += nbits; \ +} + +/* + * Encode a chunk of pixels. + * + * Uses an open addressing double hashing (no chaining) on the + * prefix code/next character combination. We do a variant of + * Knuth's algorithm D (vol. 3, sec. 6.4) along with G. Knott's + * relatively-prime secondary probe. Here, the modular division + * first probe is gives way to a faster exclusive-or manipulation. + * Also do block compression with an adaptive reset, whereby the + * code table is cleared when the compression ratio decreases, + * but after the table fills. The variable-length output codes + * are re-sized at this point, and a CODE_CLEAR is generated + * for the decoder. + */ +static int +LZWEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + register LZWCodecState *sp = EncoderState(tif); + register long fcode; + register hash_t *hp; + register int h, c; + hcode_t ent; + long disp; + long incount, outcount, checkpoint; + long nextdata, nextbits; + int free_ent, maxcode, nbits; + uint8* op; + uint8* limit; + + (void) s; + if (sp == NULL) + return (0); + + assert(sp->enc_hashtab != NULL); + + /* + * Load local state. + */ + incount = sp->enc_incount; + outcount = sp->enc_outcount; + checkpoint = sp->enc_checkpoint; + nextdata = sp->lzw_nextdata; + nextbits = sp->lzw_nextbits; + free_ent = sp->lzw_free_ent; + maxcode = sp->lzw_maxcode; + nbits = sp->lzw_nbits; + op = tif->tif_rawcp; + limit = sp->enc_rawlimit; + ent = sp->enc_oldcode; + + if (ent == (hcode_t) -1 && cc > 0) { + /* + * NB: This is safe because it can only happen + * at the start of a strip where we know there + * is space in the data buffer. + */ + PutNextCode(op, CODE_CLEAR); + ent = *bp++; cc--; incount++; + } + while (cc > 0) { + c = *bp++; cc--; incount++; + fcode = ((long)c << BITS_MAX) + ent; + h = (c << HSHIFT) ^ ent; /* xor hashing */ +#ifdef _WINDOWS + /* + * Check hash index for an overflow. + */ + if (h >= HSIZE) + h -= HSIZE; +#endif + hp = &sp->enc_hashtab[h]; + if (hp->hash == fcode) { + ent = hp->code; + continue; + } + if (hp->hash >= 0) { + /* + * Primary hash failed, check secondary hash. + */ + disp = HSIZE - h; + if (h == 0) + disp = 1; + do { + /* + * Avoid pointer arithmetic 'cuz of + * wraparound problems with segments. + */ + if ((h -= disp) < 0) + h += HSIZE; + hp = &sp->enc_hashtab[h]; + if (hp->hash == fcode) { + ent = hp->code; + goto hit; + } + } while (hp->hash >= 0); + } + /* + * New entry, emit code and add to table. + */ + /* + * Verify there is space in the buffer for the code + * and any potential Clear code that might be emitted + * below. The value of limit is setup so that there + * are at least 4 bytes free--room for 2 codes. + */ + if (op > limit) { + tif->tif_rawcc = (tmsize_t)(op - tif->tif_rawdata); + TIFFFlushData1(tif); + op = tif->tif_rawdata; + } + PutNextCode(op, ent); + ent = c; + hp->code = free_ent++; + hp->hash = fcode; + if (free_ent == CODE_MAX-1) { + /* table is full, emit clear code and reset */ + cl_hash(sp); + sp->enc_ratio = 0; + incount = 0; + outcount = 0; + free_ent = CODE_FIRST; + PutNextCode(op, CODE_CLEAR); + nbits = BITS_MIN; + maxcode = MAXCODE(BITS_MIN); + } else { + /* + * If the next entry is going to be too big for + * the code size, then increase it, if possible. + */ + if (free_ent > maxcode) { + nbits++; + assert(nbits <= BITS_MAX); + maxcode = (int) MAXCODE(nbits); + } else if (incount >= checkpoint) { + long rat; + /* + * Check compression ratio and, if things seem + * to be slipping, clear the hash table and + * reset state. The compression ratio is a + * 24+8-bit fractional number. + */ + checkpoint = incount+CHECK_GAP; + CALCRATIO(sp, rat); + if (rat <= sp->enc_ratio) { + cl_hash(sp); + sp->enc_ratio = 0; + incount = 0; + outcount = 0; + free_ent = CODE_FIRST; + PutNextCode(op, CODE_CLEAR); + nbits = BITS_MIN; + maxcode = MAXCODE(BITS_MIN); + } else + sp->enc_ratio = rat; + } + } + hit: + ; + } + + /* + * Restore global state. + */ + sp->enc_incount = incount; + sp->enc_outcount = outcount; + sp->enc_checkpoint = checkpoint; + sp->enc_oldcode = ent; + sp->lzw_nextdata = nextdata; + sp->lzw_nextbits = nextbits; + sp->lzw_free_ent = free_ent; + sp->lzw_maxcode = maxcode; + sp->lzw_nbits = nbits; + tif->tif_rawcp = op; + return (1); +} + +/* + * Finish off an encoded strip by flushing the last + * string and tacking on an End Of Information code. + */ +static int +LZWPostEncode(TIFF* tif) +{ + register LZWCodecState *sp = EncoderState(tif); + uint8* op = tif->tif_rawcp; + long nextbits = sp->lzw_nextbits; + long nextdata = sp->lzw_nextdata; + long outcount = sp->enc_outcount; + int nbits = sp->lzw_nbits; + + if (op > sp->enc_rawlimit) { + tif->tif_rawcc = (tmsize_t)(op - tif->tif_rawdata); + TIFFFlushData1(tif); + op = tif->tif_rawdata; + } + if (sp->enc_oldcode != (hcode_t) -1) { + PutNextCode(op, sp->enc_oldcode); + sp->enc_oldcode = (hcode_t) -1; + } + PutNextCode(op, CODE_EOI); + if (nextbits > 0) + *op++ = (unsigned char)(nextdata << (8-nextbits)); + tif->tif_rawcc = (tmsize_t)(op - tif->tif_rawdata); + return (1); +} + +/* + * Reset encoding hash table. + */ +static void +cl_hash(LZWCodecState* sp) +{ + register hash_t *hp = &sp->enc_hashtab[HSIZE-1]; + register long i = HSIZE-8; + + do { + i -= 8; + hp[-7].hash = -1; + hp[-6].hash = -1; + hp[-5].hash = -1; + hp[-4].hash = -1; + hp[-3].hash = -1; + hp[-2].hash = -1; + hp[-1].hash = -1; + hp[ 0].hash = -1; + hp -= 8; + } while (i >= 0); + for (i += 8; i > 0; i--, hp--) + hp->hash = -1; +} + +static void +LZWCleanup(TIFF* tif) +{ + (void)TIFFPredictorCleanup(tif); + + assert(tif->tif_data != 0); + + if (DecoderState(tif)->dec_codetab) + _TIFFfree(DecoderState(tif)->dec_codetab); + + if (EncoderState(tif)->enc_hashtab) + _TIFFfree(EncoderState(tif)->enc_hashtab); + + _TIFFfree(tif->tif_data); + tif->tif_data = NULL; + + _TIFFSetDefaultCompressionState(tif); +} + +int +TIFFInitLZW(TIFF* tif, int scheme) +{ + static const char module[] = "TIFFInitLZW"; + assert(scheme == COMPRESSION_LZW); + /* + * Allocate state block so tag methods have storage to record values. + */ + tif->tif_data = (uint8*) _TIFFmalloc(sizeof (LZWCodecState)); + if (tif->tif_data == NULL) + goto bad; + DecoderState(tif)->dec_codetab = NULL; + DecoderState(tif)->dec_decode = NULL; + EncoderState(tif)->enc_hashtab = NULL; + LZWState(tif)->rw_mode = tif->tif_mode; + + /* + * Install codec methods. + */ + tif->tif_fixuptags = LZWFixupTags; + tif->tif_setupdecode = LZWSetupDecode; + tif->tif_predecode = LZWPreDecode; + tif->tif_decoderow = LZWDecode; + tif->tif_decodestrip = LZWDecode; + tif->tif_decodetile = LZWDecode; + tif->tif_setupencode = LZWSetupEncode; + tif->tif_preencode = LZWPreEncode; + tif->tif_postencode = LZWPostEncode; + tif->tif_encoderow = LZWEncode; + tif->tif_encodestrip = LZWEncode; + tif->tif_encodetile = LZWEncode; + tif->tif_cleanup = LZWCleanup; + /* + * Setup predictor setup. + */ + (void) TIFFPredictorInit(tif); + return (1); +bad: + TIFFErrorExt(tif->tif_clientdata, module, + "No space for LZW state block"); + return (0); +} + +/* + * Copyright (c) 1985, 1986 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * James A. Woods, derived from original work by Spencer Thomas + * and Joseph Orost. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ +#endif /* LZW_SUPPORT */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_next.c b/Source/LibTIFF4/tif_next.c index cfe2ead..b2c5508 100644 --- a/Source/LibTIFF4/tif_next.c +++ b/Source/LibTIFF4/tif_next.c @@ -1,160 +1,160 @@ -/* $Id: tif_next.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "tiffiop.h" -#ifdef NEXT_SUPPORT -/* - * TIFF Library. - * - * NeXT 2-bit Grey Scale Compression Algorithm Support - */ - -#define SETPIXEL(op, v) { \ - switch (npixels++ & 3) { \ - case 0: op[0] = (unsigned char) ((v) << 6); break; \ - case 1: op[0] |= (v) << 4; break; \ - case 2: op[0] |= (v) << 2; break; \ - case 3: *op++ |= (v); break; \ - } \ -} - -#define LITERALROW 0x00 -#define LITERALSPAN 0x40 -#define WHITE ((1<<2)-1) - -static int -NeXTDecode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) -{ - static const char module[] = "NeXTDecode"; - unsigned char *bp, *op; - tmsize_t cc; - uint8* row; - tmsize_t scanline, n; - - (void) s; - /* - * Each scanline is assumed to start off as all - * white (we assume a PhotometricInterpretation - * of ``min-is-black''). - */ - for (op = (unsigned char*) buf, cc = occ; cc-- > 0;) - *op++ = 0xff; - - bp = (unsigned char *)tif->tif_rawcp; - cc = tif->tif_rawcc; - scanline = tif->tif_scanlinesize; - if (occ % scanline) - { - TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read"); - return (0); - } - for (row = buf; occ > 0; occ -= scanline, row += scanline) { - n = *bp++, cc--; - switch (n) { - case LITERALROW: - /* - * The entire scanline is given as literal values. - */ - if (cc < scanline) - goto bad; - _TIFFmemcpy(row, bp, scanline); - bp += scanline; - cc -= scanline; - break; - case LITERALSPAN: { - tmsize_t off; - /* - * The scanline has a literal span that begins at some - * offset. - */ - off = (bp[0] * 256) + bp[1]; - n = (bp[2] * 256) + bp[3]; - if (cc < 4+n || off+n > scanline) - goto bad; - _TIFFmemcpy(row+off, bp+4, n); - bp += 4+n; - cc -= 4+n; - break; - } - default: { - uint32 npixels = 0, grey; - uint32 imagewidth = tif->tif_dir.td_imagewidth; - - /* - * The scanline is composed of a sequence of constant - * color ``runs''. We shift into ``run mode'' and - * interpret bytes as codes of the form - * until we've filled the scanline. - */ - op = row; - for (;;) { - grey = (uint32)((n>>6) & 0x3); - n &= 0x3f; - /* - * Ensure the run does not exceed the scanline - * bounds, potentially resulting in a security - * issue. - */ - while (n-- > 0 && npixels < imagewidth) - SETPIXEL(op, grey); - if (npixels >= imagewidth) - break; - if (cc == 0) - goto bad; - n = *bp++, cc--; - } - break; - } - } - } - tif->tif_rawcp = (uint8*) bp; - tif->tif_rawcc = cc; - return (1); -bad: - TIFFErrorExt(tif->tif_clientdata, module, "Not enough data for scanline %ld", - (long) tif->tif_row); - return (0); -} - -int -TIFFInitNeXT(TIFF* tif, int scheme) -{ - (void) scheme; - tif->tif_decoderow = NeXTDecode; - tif->tif_decodestrip = NeXTDecode; - tif->tif_decodetile = NeXTDecode; - return (1); -} -#endif /* NEXT_SUPPORT */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_next.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include "tiffiop.h" +#ifdef NEXT_SUPPORT +/* + * TIFF Library. + * + * NeXT 2-bit Grey Scale Compression Algorithm Support + */ + +#define SETPIXEL(op, v) { \ + switch (npixels++ & 3) { \ + case 0: op[0] = (unsigned char) ((v) << 6); break; \ + case 1: op[0] |= (v) << 4; break; \ + case 2: op[0] |= (v) << 2; break; \ + case 3: *op++ |= (v); break; \ + } \ +} + +#define LITERALROW 0x00 +#define LITERALSPAN 0x40 +#define WHITE ((1<<2)-1) + +static int +NeXTDecode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) +{ + static const char module[] = "NeXTDecode"; + unsigned char *bp, *op; + tmsize_t cc; + uint8* row; + tmsize_t scanline, n; + + (void) s; + /* + * Each scanline is assumed to start off as all + * white (we assume a PhotometricInterpretation + * of ``min-is-black''). + */ + for (op = (unsigned char*) buf, cc = occ; cc-- > 0;) + *op++ = 0xff; + + bp = (unsigned char *)tif->tif_rawcp; + cc = tif->tif_rawcc; + scanline = tif->tif_scanlinesize; + if (occ % scanline) + { + TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read"); + return (0); + } + for (row = buf; occ > 0; occ -= scanline, row += scanline) { + n = *bp++, cc--; + switch (n) { + case LITERALROW: + /* + * The entire scanline is given as literal values. + */ + if (cc < scanline) + goto bad; + _TIFFmemcpy(row, bp, scanline); + bp += scanline; + cc -= scanline; + break; + case LITERALSPAN: { + tmsize_t off; + /* + * The scanline has a literal span that begins at some + * offset. + */ + off = (bp[0] * 256) + bp[1]; + n = (bp[2] * 256) + bp[3]; + if (cc < 4+n || off+n > scanline) + goto bad; + _TIFFmemcpy(row+off, bp+4, n); + bp += 4+n; + cc -= 4+n; + break; + } + default: { + uint32 npixels = 0, grey; + uint32 imagewidth = tif->tif_dir.td_imagewidth; + + /* + * The scanline is composed of a sequence of constant + * color ``runs''. We shift into ``run mode'' and + * interpret bytes as codes of the form + * until we've filled the scanline. + */ + op = row; + for (;;) { + grey = (uint32)((n>>6) & 0x3); + n &= 0x3f; + /* + * Ensure the run does not exceed the scanline + * bounds, potentially resulting in a security + * issue. + */ + while (n-- > 0 && npixels < imagewidth) + SETPIXEL(op, grey); + if (npixels >= imagewidth) + break; + if (cc == 0) + goto bad; + n = *bp++, cc--; + } + break; + } + } + } + tif->tif_rawcp = (uint8*) bp; + tif->tif_rawcc = cc; + return (1); +bad: + TIFFErrorExt(tif->tif_clientdata, module, "Not enough data for scanline %ld", + (long) tif->tif_row); + return (0); +} + +int +TIFFInitNeXT(TIFF* tif, int scheme) +{ + (void) scheme; + tif->tif_decoderow = NeXTDecode; + tif->tif_decodestrip = NeXTDecode; + tif->tif_decodetile = NeXTDecode; + return (1); +} +#endif /* NEXT_SUPPORT */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_ojpeg.c b/Source/LibTIFF4/tif_ojpeg.c index fe74748..17f82c6 100644 --- a/Source/LibTIFF4/tif_ojpeg.c +++ b/Source/LibTIFF4/tif_ojpeg.c @@ -1,2496 +1,2496 @@ -/* $Id: tif_ojpeg.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* WARNING: The type of JPEG encapsulation defined by the TIFF Version 6.0 - specification is now totally obsolete and deprecated for new applications and - images. This file was was created solely in order to read unconverted images - still present on some users' computer systems. It will never be extended - to write such files. Writing new-style JPEG compressed TIFFs is implemented - in tif_jpeg.c. - - The code is carefully crafted to robustly read all gathered JPEG-in-TIFF - testfiles, and anticipate as much as possible all other... But still, it may - fail on some. If you encounter problems, please report them on the TIFF - mailing list and/or to Joris Van Damme . - - Please read the file called "TIFF Technical Note #2" if you need to be - convinced this compression scheme is bad and breaks TIFF. That document - is linked to from the LibTiff site - and from AWare Systems' TIFF section - . It is also absorbed - in Adobe's specification supplements, marked "draft" up to this day, but - supported by the TIFF community. - - This file interfaces with Release 6B of the JPEG Library written by the - Independent JPEG Group. Previous versions of this file required a hack inside - the LibJpeg library. This version no longer requires that. Remember to - remove the hack if you update from the old version. - - Copyright (c) Joris Van Damme - Copyright (c) AWare Systems - - The licence agreement for this file is the same as the rest of the LibTiff - library. - - IN NO EVENT SHALL JORIS VAN DAMME OR AWARE SYSTEMS BE LIABLE FOR - ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - OF THIS SOFTWARE. - - Joris Van Damme and/or AWare Systems may be available for custom - developement. If you like what you see, and need anything similar or related, - contact . -*/ - -/* What is what, and what is not? - - This decoder starts with an input stream, that is essentially the JpegInterchangeFormat - stream, if any, followed by the strile data, if any. This stream is read in - OJPEGReadByte and related functions. - - It analyzes the start of this stream, until it encounters non-marker data, i.e. - compressed image data. Some of the header markers it sees have no actual content, - like the SOI marker, and APP/COM markers that really shouldn't even be there. Some - other markers do have content, and the valuable bits and pieces of information - in these markers are saved, checking all to verify that the stream is more or - less within expected bounds. This happens inside the OJPEGReadHeaderInfoSecStreamXxx - functions. - - Some OJPEG imagery contains no valid JPEG header markers. This situation is picked - up on if we've seen no SOF marker when we're at the start of the compressed image - data. In this case, the tables are read from JpegXxxTables tags, and the other - bits and pieces of information is initialized to its most basic value. This is - implemented in the OJPEGReadHeaderInfoSecTablesXxx functions. - - When this is complete, a good and valid JPEG header can be assembled, and this is - passed through to LibJpeg. When that's done, the remainder of the input stream, i.e. - the compressed image data, can be passed through unchanged. This is done in - OJPEGWriteStream functions. - - LibTiff rightly expects to know the subsampling values before decompression. Just like - in new-style JPEG-in-TIFF, though, or even more so, actually, the YCbCrsubsampling - tag is notoriously unreliable. To correct these tag values with the ones inside - the JPEG stream, the first part of the input stream is pre-scanned in - OJPEGSubsamplingCorrect, making no note of any other data, reporting no warnings - or errors, up to the point where either these values are read, or it's clear they - aren't there. This means that some of the data is read twice, but we feel speed - in correcting these values is important enough to warrant this sacrifice. Allthough - there is currently no define or other configuration mechanism to disable this behaviour, - the actual header scanning is build to robustly respond with error report if it - should encounter an uncorrected mismatch of subsampling values. See - OJPEGReadHeaderInfoSecStreamSof. - - The restart interval and restart markers are the most tricky part... The restart - interval can be specified in a tag. It can also be set inside the input JPEG stream. - It can be used inside the input JPEG stream. If reading from strile data, we've - consistenly discovered the need to insert restart markers in between the different - striles, as is also probably the most likely interpretation of the original TIFF 6.0 - specification. With all this setting of interval, and actual use of markers that is not - predictable at the time of valid JPEG header assembly, the restart thing may turn - out the Achilles heel of this implementation. Fortunately, most OJPEG writer vendors - succeed in reading back what they write, which may be the reason why we've been able - to discover ways that seem to work. - - Some special provision is made for planarconfig separate OJPEG files. These seem - to consistently contain header info, a SOS marker, a plane, SOS marker, plane, SOS, - and plane. This may or may not be a valid JPEG configuration, we don't know and don't - care. We want LibTiff to be able to access the planes individually, without huge - buffering inside LibJpeg, anyway. So we compose headers to feed to LibJpeg, in this - case, that allow us to pass a single plane such that LibJpeg sees a valid - single-channel JPEG stream. Locating subsequent SOS markers, and thus subsequent - planes, is done inside OJPEGReadSecondarySos. - - The benefit of the scheme is... that it works, basically. We know of no other that - does. It works without checking software tag, or otherwise going about things in an - OJPEG flavor specific manner. Instead, it is a single scheme, that covers the cases - with and without JpegInterchangeFormat, with and without striles, with part of - the header in JpegInterchangeFormat and remainder in first strile, etc. It is forgiving - and robust, may likely work with OJPEG flavors we've not seen yet, and makes most out - of the data. - - Another nice side-effect is that a complete JPEG single valid stream is build if - planarconfig is not separate (vast majority). We may one day use that to build - converters to JPEG, and/or to new-style JPEG compression inside TIFF. - - A dissadvantage is the lack of random access to the individual striles. This is the - reason for much of the complicated restart-and-position stuff inside OJPEGPreDecode. - Applications would do well accessing all striles in order, as this will result in - a single sequential scan of the input stream, and no restarting of LibJpeg decoding - session. -*/ - -#define WIN32_LEAN_AND_MEAN -#define VC_EXTRALEAN - -#include "tiffiop.h" -#ifdef OJPEG_SUPPORT - -/* Configuration defines here are: - * JPEG_ENCAP_EXTERNAL: The normal way to call libjpeg, uses longjump. In some environments, - * like eg LibTiffDelphi, this is not possible. For this reason, the actual calls to - * libjpeg, with longjump stuff, are encapsulated in dedicated functions. When - * JPEG_ENCAP_EXTERNAL is defined, these encapsulating functions are declared external - * to this unit, and can be defined elsewhere to use stuff other then longjump. - * The default mode, without JPEG_ENCAP_EXTERNAL, implements the call encapsulators - * here, internally, with normal longjump. - * SETJMP, LONGJMP, JMP_BUF: On some machines/environments a longjump equivalent is - * conviniently available, but still it may be worthwhile to use _setjmp or sigsetjmp - * in place of plain setjmp. These macros will make it easier. It is useless - * to fiddle with these if you define JPEG_ENCAP_EXTERNAL. - * OJPEG_BUFFER: Define the size of the desired buffer here. Should be small enough so as to guarantee - * instant processing, optimal streaming and optimal use of processor cache, but also big - * enough so as to not result in significant call overhead. It should be at least a few - * bytes to accomodate some structures (this is verified in asserts), but it would not be - * sensible to make it this small anyway, and it should be at most 64K since it is indexed - * with uint16. We recommend 2K. - * EGYPTIANWALK: You could also define EGYPTIANWALK here, but it is not used anywhere and has - * absolutely no effect. That is why most people insist the EGYPTIANWALK is a bit silly. - */ - -/* define LIBJPEG_ENCAP_EXTERNAL */ -#define SETJMP(jbuf) setjmp(jbuf) -#define LONGJMP(jbuf,code) longjmp(jbuf,code) -#define JMP_BUF jmp_buf -#define OJPEG_BUFFER 2048 -/* define EGYPTIANWALK */ - -#define JPEG_MARKER_SOF0 0xC0 -#define JPEG_MARKER_SOF1 0xC1 -#define JPEG_MARKER_SOF3 0xC3 -#define JPEG_MARKER_DHT 0xC4 -#define JPEG_MARKER_RST0 0XD0 -#define JPEG_MARKER_SOI 0xD8 -#define JPEG_MARKER_EOI 0xD9 -#define JPEG_MARKER_SOS 0xDA -#define JPEG_MARKER_DQT 0xDB -#define JPEG_MARKER_DRI 0xDD -#define JPEG_MARKER_APP0 0xE0 -#define JPEG_MARKER_COM 0xFE - -#define FIELD_OJPEG_JPEGINTERCHANGEFORMAT (FIELD_CODEC+0) -#define FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH (FIELD_CODEC+1) -#define FIELD_OJPEG_JPEGQTABLES (FIELD_CODEC+2) -#define FIELD_OJPEG_JPEGDCTABLES (FIELD_CODEC+3) -#define FIELD_OJPEG_JPEGACTABLES (FIELD_CODEC+4) -#define FIELD_OJPEG_JPEGPROC (FIELD_CODEC+5) -#define FIELD_OJPEG_JPEGRESTARTINTERVAL (FIELD_CODEC+6) - -static const TIFFField ojpegFields[] = { - {TIFFTAG_JPEGIFOFFSET,1,1,TIFF_LONG8,0,TIFF_SETGET_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGINTERCHANGEFORMAT,TRUE,FALSE,"JpegInterchangeFormat",NULL}, - {TIFFTAG_JPEGIFBYTECOUNT,1,1,TIFF_LONG8,0,TIFF_SETGET_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH,TRUE,FALSE,"JpegInterchangeFormatLength",NULL}, - {TIFFTAG_JPEGQTABLES,TIFF_VARIABLE2,TIFF_VARIABLE2,TIFF_LONG8,0,TIFF_SETGET_C32_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGQTABLES,FALSE,TRUE,"JpegQTables",NULL}, - {TIFFTAG_JPEGDCTABLES,TIFF_VARIABLE2,TIFF_VARIABLE2,TIFF_LONG8,0,TIFF_SETGET_C32_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGDCTABLES,FALSE,TRUE,"JpegDcTables",NULL}, - {TIFFTAG_JPEGACTABLES,TIFF_VARIABLE2,TIFF_VARIABLE2,TIFF_LONG8,0,TIFF_SETGET_C32_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGACTABLES,FALSE,TRUE,"JpegAcTables",NULL}, - {TIFFTAG_JPEGPROC,1,1,TIFF_SHORT,0,TIFF_SETGET_UINT16,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGPROC,FALSE,FALSE,"JpegProc",NULL}, - {TIFFTAG_JPEGRESTARTINTERVAL,1,1,TIFF_SHORT,0,TIFF_SETGET_UINT16,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGRESTARTINTERVAL,FALSE,FALSE,"JpegRestartInterval",NULL}, -}; - -#ifndef LIBJPEG_ENCAP_EXTERNAL -#include -#endif - -/* We undefine FAR to avoid conflict with JPEG definition */ - -#ifdef FAR -#undef FAR -#endif - -/* - Libjpeg's jmorecfg.h defines INT16 and INT32, but only if XMD_H is - not defined. Unfortunately, the MinGW and Borland compilers include - a typedef for INT32, which causes a conflict. MSVC does not include - a conficting typedef given the headers which are included. -*/ -#if defined(__BORLANDC__) || defined(__MINGW32__) -# define XMD_H 1 -#endif - -/* Define "boolean" as unsigned char, not int, per Windows custom. */ -#if defined(__WIN32__) && !defined(__MINGW32__) -# ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ - typedef unsigned char boolean; -# endif -# define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ -#endif - -#include "../LibJPEG/jpeglib.h" -#include "../LibJPEG/jerror.h" - -typedef struct jpeg_error_mgr jpeg_error_mgr; -typedef struct jpeg_common_struct jpeg_common_struct; -typedef struct jpeg_decompress_struct jpeg_decompress_struct; -typedef struct jpeg_source_mgr jpeg_source_mgr; - -typedef enum { - osibsNotSetYet, - osibsJpegInterchangeFormat, - osibsStrile, - osibsEof -} OJPEGStateInBufferSource; - -typedef enum { - ososSoi, - ososQTable0,ososQTable1,ososQTable2,ososQTable3, - ososDcTable0,ososDcTable1,ososDcTable2,ososDcTable3, - ososAcTable0,ososAcTable1,ososAcTable2,ososAcTable3, - ososDri, - ososSof, - ososSos, - ososCompressed, - ososRst, - ososEoi -} OJPEGStateOutState; - -typedef struct { - TIFF* tif; - #ifndef LIBJPEG_ENCAP_EXTERNAL - JMP_BUF exit_jmpbuf; - #endif - TIFFVGetMethod vgetparent; - TIFFVSetMethod vsetparent; - TIFFPrintMethod printdir; - uint64 file_size; - uint32 image_width; - uint32 image_length; - uint32 strile_width; - uint32 strile_length; - uint32 strile_length_total; - uint8 samples_per_pixel; - uint8 plane_sample_offset; - uint8 samples_per_pixel_per_plane; - uint64 jpeg_interchange_format; - uint64 jpeg_interchange_format_length; - uint8 jpeg_proc; - uint8 subsamplingcorrect; - uint8 subsamplingcorrect_done; - uint8 subsampling_tag; - uint8 subsampling_hor; - uint8 subsampling_ver; - uint8 subsampling_force_desubsampling_inside_decompression; - uint8 qtable_offset_count; - uint8 dctable_offset_count; - uint8 actable_offset_count; - uint64 qtable_offset[3]; - uint64 dctable_offset[3]; - uint64 actable_offset[3]; - uint8* qtable[4]; - uint8* dctable[4]; - uint8* actable[4]; - uint16 restart_interval; - uint8 restart_index; - uint8 sof_log; - uint8 sof_marker_id; - uint32 sof_x; - uint32 sof_y; - uint8 sof_c[3]; - uint8 sof_hv[3]; - uint8 sof_tq[3]; - uint8 sos_cs[3]; - uint8 sos_tda[3]; - struct { - uint8 log; - OJPEGStateInBufferSource in_buffer_source; - uint32 in_buffer_next_strile; - uint64 in_buffer_file_pos; - uint64 in_buffer_file_togo; - } sos_end[3]; - uint8 readheader_done; - uint8 writeheader_done; - uint16 write_cursample; - uint32 write_curstrile; - uint8 libjpeg_session_active; - uint8 libjpeg_jpeg_query_style; - jpeg_error_mgr libjpeg_jpeg_error_mgr; - jpeg_decompress_struct libjpeg_jpeg_decompress_struct; - jpeg_source_mgr libjpeg_jpeg_source_mgr; - uint8 subsampling_convert_log; - uint32 subsampling_convert_ylinelen; - uint32 subsampling_convert_ylines; - uint32 subsampling_convert_clinelen; - uint32 subsampling_convert_clines; - uint32 subsampling_convert_ybuflen; - uint32 subsampling_convert_cbuflen; - uint32 subsampling_convert_ycbcrbuflen; - uint8* subsampling_convert_ycbcrbuf; - uint8* subsampling_convert_ybuf; - uint8* subsampling_convert_cbbuf; - uint8* subsampling_convert_crbuf; - uint32 subsampling_convert_ycbcrimagelen; - uint8** subsampling_convert_ycbcrimage; - uint32 subsampling_convert_clinelenout; - uint32 subsampling_convert_state; - uint32 bytes_per_line; /* if the codec outputs subsampled data, a 'line' in bytes_per_line */ - uint32 lines_per_strile; /* and lines_per_strile means subsampling_ver desubsampled rows */ - OJPEGStateInBufferSource in_buffer_source; - uint32 in_buffer_next_strile; - uint32 in_buffer_strile_count; - uint64 in_buffer_file_pos; - uint8 in_buffer_file_pos_log; - uint64 in_buffer_file_togo; - uint16 in_buffer_togo; - uint8* in_buffer_cur; - uint8 in_buffer[OJPEG_BUFFER]; - OJPEGStateOutState out_state; - uint8 out_buffer[OJPEG_BUFFER]; - uint8* skip_buffer; -} OJPEGState; - -static int OJPEGVGetField(TIFF* tif, uint32 tag, va_list ap); -static int OJPEGVSetField(TIFF* tif, uint32 tag, va_list ap); -static void OJPEGPrintDir(TIFF* tif, FILE* fd, long flags); - -static int OJPEGFixupTags(TIFF* tif); -static int OJPEGSetupDecode(TIFF* tif); -static int OJPEGPreDecode(TIFF* tif, uint16 s); -static int OJPEGPreDecodeSkipRaw(TIFF* tif); -static int OJPEGPreDecodeSkipScanlines(TIFF* tif); -static int OJPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s); -static int OJPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc); -static int OJPEGDecodeScanlines(TIFF* tif, uint8* buf, tmsize_t cc); -static void OJPEGPostDecode(TIFF* tif, uint8* buf, tmsize_t cc); -static int OJPEGSetupEncode(TIFF* tif); -static int OJPEGPreEncode(TIFF* tif, uint16 s); -static int OJPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s); -static int OJPEGPostEncode(TIFF* tif); -static void OJPEGCleanup(TIFF* tif); - -static void OJPEGSubsamplingCorrect(TIFF* tif); -static int OJPEGReadHeaderInfo(TIFF* tif); -static int OJPEGReadSecondarySos(TIFF* tif, uint16 s); -static int OJPEGWriteHeaderInfo(TIFF* tif); -static void OJPEGLibjpegSessionAbort(TIFF* tif); - -static int OJPEGReadHeaderInfoSec(TIFF* tif); -static int OJPEGReadHeaderInfoSecStreamDri(TIFF* tif); -static int OJPEGReadHeaderInfoSecStreamDqt(TIFF* tif); -static int OJPEGReadHeaderInfoSecStreamDht(TIFF* tif); -static int OJPEGReadHeaderInfoSecStreamSof(TIFF* tif, uint8 marker_id); -static int OJPEGReadHeaderInfoSecStreamSos(TIFF* tif); -static int OJPEGReadHeaderInfoSecTablesQTable(TIFF* tif); -static int OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif); -static int OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif); - -static int OJPEGReadBufferFill(OJPEGState* sp); -static int OJPEGReadByte(OJPEGState* sp, uint8* byte); -static int OJPEGReadBytePeek(OJPEGState* sp, uint8* byte); -static void OJPEGReadByteAdvance(OJPEGState* sp); -static int OJPEGReadWord(OJPEGState* sp, uint16* word); -static int OJPEGReadBlock(OJPEGState* sp, uint16 len, void* mem); -static void OJPEGReadSkip(OJPEGState* sp, uint16 len); - -static int OJPEGWriteStream(TIFF* tif, void** mem, uint32* len); -static void OJPEGWriteStreamSoi(TIFF* tif, void** mem, uint32* len); -static void OJPEGWriteStreamQTable(TIFF* tif, uint8 table_index, void** mem, uint32* len); -static void OJPEGWriteStreamDcTable(TIFF* tif, uint8 table_index, void** mem, uint32* len); -static void OJPEGWriteStreamAcTable(TIFF* tif, uint8 table_index, void** mem, uint32* len); -static void OJPEGWriteStreamDri(TIFF* tif, void** mem, uint32* len); -static void OJPEGWriteStreamSof(TIFF* tif, void** mem, uint32* len); -static void OJPEGWriteStreamSos(TIFF* tif, void** mem, uint32* len); -static int OJPEGWriteStreamCompressed(TIFF* tif, void** mem, uint32* len); -static void OJPEGWriteStreamRst(TIFF* tif, void** mem, uint32* len); -static void OJPEGWriteStreamEoi(TIFF* tif, void** mem, uint32* len); - -#ifdef LIBJPEG_ENCAP_EXTERNAL -extern int jpeg_create_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo); -extern int jpeg_read_header_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, uint8 require_image); -extern int jpeg_start_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo); -extern int jpeg_read_scanlines_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* scanlines, uint32 max_lines); -extern int jpeg_read_raw_data_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* data, uint32 max_lines); -extern void jpeg_encap_unwind(TIFF* tif); -#else -static int jpeg_create_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* j); -static int jpeg_read_header_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, uint8 require_image); -static int jpeg_start_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo); -static int jpeg_read_scanlines_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* scanlines, uint32 max_lines); -static int jpeg_read_raw_data_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* data, uint32 max_lines); -static void jpeg_encap_unwind(TIFF* tif); -#endif - -static void OJPEGLibjpegJpegErrorMgrOutputMessage(jpeg_common_struct* cinfo); -static void OJPEGLibjpegJpegErrorMgrErrorExit(jpeg_common_struct* cinfo); -static void OJPEGLibjpegJpegSourceMgrInitSource(jpeg_decompress_struct* cinfo); -static boolean OJPEGLibjpegJpegSourceMgrFillInputBuffer(jpeg_decompress_struct* cinfo); -static void OJPEGLibjpegJpegSourceMgrSkipInputData(jpeg_decompress_struct* cinfo, long num_bytes); -static boolean OJPEGLibjpegJpegSourceMgrResyncToRestart(jpeg_decompress_struct* cinfo, int desired); -static void OJPEGLibjpegJpegSourceMgrTermSource(jpeg_decompress_struct* cinfo); - -int -TIFFInitOJPEG(TIFF* tif, int scheme) -{ - static const char module[]="TIFFInitOJPEG"; - OJPEGState* sp; - - assert(scheme==COMPRESSION_OJPEG); - - /* - * Merge codec-specific tag information. - */ - if (!_TIFFMergeFields(tif, ojpegFields, TIFFArrayCount(ojpegFields))) { - TIFFErrorExt(tif->tif_clientdata, module, - "Merging Old JPEG codec-specific tags failed"); - return 0; - } - - /* state block */ - sp=_TIFFmalloc(sizeof(OJPEGState)); - if (sp==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"No space for OJPEG state block"); - return(0); - } - _TIFFmemset(sp,0,sizeof(OJPEGState)); - sp->tif=tif; - sp->jpeg_proc=1; - sp->subsampling_hor=2; - sp->subsampling_ver=2; - TIFFSetField(tif,TIFFTAG_YCBCRSUBSAMPLING,2,2); - /* tif codec methods */ - tif->tif_fixuptags=OJPEGFixupTags; - tif->tif_setupdecode=OJPEGSetupDecode; - tif->tif_predecode=OJPEGPreDecode; - tif->tif_postdecode=OJPEGPostDecode; - tif->tif_decoderow=OJPEGDecode; - tif->tif_decodestrip=OJPEGDecode; - tif->tif_decodetile=OJPEGDecode; - tif->tif_setupencode=OJPEGSetupEncode; - tif->tif_preencode=OJPEGPreEncode; - tif->tif_postencode=OJPEGPostEncode; - tif->tif_encoderow=OJPEGEncode; - tif->tif_encodestrip=OJPEGEncode; - tif->tif_encodetile=OJPEGEncode; - tif->tif_cleanup=OJPEGCleanup; - tif->tif_data=(uint8*)sp; - /* tif tag methods */ - sp->vgetparent=tif->tif_tagmethods.vgetfield; - tif->tif_tagmethods.vgetfield=OJPEGVGetField; - sp->vsetparent=tif->tif_tagmethods.vsetfield; - tif->tif_tagmethods.vsetfield=OJPEGVSetField; - sp->printdir=tif->tif_tagmethods.printdir; - tif->tif_tagmethods.printdir=OJPEGPrintDir; - /* Some OJPEG files don't have strip or tile offsets or bytecounts tags. - Some others do, but have totally meaningless or corrupt values - in these tags. In these cases, the JpegInterchangeFormat stream is - reliable. In any case, this decoder reads the compressed data itself, - from the most reliable locations, and we need to notify encapsulating - LibTiff not to read raw strips or tiles for us. */ - tif->tif_flags|=TIFF_NOREADRAW; - return(1); -} - -static int -OJPEGVGetField(TIFF* tif, uint32 tag, va_list ap) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - switch(tag) - { - case TIFFTAG_JPEGIFOFFSET: - *va_arg(ap,uint64*)=(uint64)sp->jpeg_interchange_format; - break; - case TIFFTAG_JPEGIFBYTECOUNT: - *va_arg(ap,uint64*)=(uint64)sp->jpeg_interchange_format_length; - break; - case TIFFTAG_YCBCRSUBSAMPLING: - if (sp->subsamplingcorrect_done==0) - OJPEGSubsamplingCorrect(tif); - *va_arg(ap,uint16*)=(uint16)sp->subsampling_hor; - *va_arg(ap,uint16*)=(uint16)sp->subsampling_ver; - break; - case TIFFTAG_JPEGQTABLES: - *va_arg(ap,uint32*)=(uint32)sp->qtable_offset_count; - *va_arg(ap,void**)=(void*)sp->qtable_offset; - break; - case TIFFTAG_JPEGDCTABLES: - *va_arg(ap,uint32*)=(uint32)sp->dctable_offset_count; - *va_arg(ap,void**)=(void*)sp->dctable_offset; - break; - case TIFFTAG_JPEGACTABLES: - *va_arg(ap,uint32*)=(uint32)sp->actable_offset_count; - *va_arg(ap,void**)=(void*)sp->actable_offset; - break; - case TIFFTAG_JPEGPROC: - *va_arg(ap,uint16*)=(uint16)sp->jpeg_proc; - break; - case TIFFTAG_JPEGRESTARTINTERVAL: - *va_arg(ap,uint16*)=sp->restart_interval; - break; - default: - return (*sp->vgetparent)(tif,tag,ap); - } - return (1); -} - -static int -OJPEGVSetField(TIFF* tif, uint32 tag, va_list ap) -{ - static const char module[]="OJPEGVSetField"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint32 ma; - uint64* mb; - uint32 n; - switch(tag) - { - case TIFFTAG_JPEGIFOFFSET: - sp->jpeg_interchange_format=(uint64)va_arg(ap,uint64); - break; - case TIFFTAG_JPEGIFBYTECOUNT: - sp->jpeg_interchange_format_length=(uint64)va_arg(ap,uint64); - break; - case TIFFTAG_YCBCRSUBSAMPLING: - sp->subsampling_tag=1; - sp->subsampling_hor=(uint8)va_arg(ap,uint16_vap); - sp->subsampling_ver=(uint8)va_arg(ap,uint16_vap); - tif->tif_dir.td_ycbcrsubsampling[0]=sp->subsampling_hor; - tif->tif_dir.td_ycbcrsubsampling[1]=sp->subsampling_ver; - break; - case TIFFTAG_JPEGQTABLES: - ma=(uint32)va_arg(ap,uint32); - if (ma!=0) - { - if (ma>3) - { - TIFFErrorExt(tif->tif_clientdata,module,"JpegQTables tag has incorrect count"); - return(0); - } - sp->qtable_offset_count=(uint8)ma; - mb=(uint64*)va_arg(ap,uint64*); - for (n=0; nqtable_offset[n]=mb[n]; - } - break; - case TIFFTAG_JPEGDCTABLES: - ma=(uint32)va_arg(ap,uint32); - if (ma!=0) - { - if (ma>3) - { - TIFFErrorExt(tif->tif_clientdata,module,"JpegDcTables tag has incorrect count"); - return(0); - } - sp->dctable_offset_count=(uint8)ma; - mb=(uint64*)va_arg(ap,uint64*); - for (n=0; ndctable_offset[n]=mb[n]; - } - break; - case TIFFTAG_JPEGACTABLES: - ma=(uint32)va_arg(ap,uint32); - if (ma!=0) - { - if (ma>3) - { - TIFFErrorExt(tif->tif_clientdata,module,"JpegAcTables tag has incorrect count"); - return(0); - } - sp->actable_offset_count=(uint8)ma; - mb=(uint64*)va_arg(ap,uint64*); - for (n=0; nactable_offset[n]=mb[n]; - } - break; - case TIFFTAG_JPEGPROC: - sp->jpeg_proc=(uint8)va_arg(ap,uint16_vap); - break; - case TIFFTAG_JPEGRESTARTINTERVAL: - sp->restart_interval=(uint16)va_arg(ap,uint16_vap); - break; - default: - return (*sp->vsetparent)(tif,tag,ap); - } - TIFFSetFieldBit(tif,TIFFFieldWithTag(tif,tag)->field_bit); - tif->tif_flags|=TIFF_DIRTYDIRECT; - return(1); -} - -static void -OJPEGPrintDir(TIFF* tif, FILE* fd, long flags) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint8 m; - (void)flags; - assert(sp!=NULL); - if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGINTERCHANGEFORMAT)) - fprintf(fd," JpegInterchangeFormat: " TIFF_UINT64_FORMAT "\n",(TIFF_UINT64_T)sp->jpeg_interchange_format); - if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH)) - fprintf(fd," JpegInterchangeFormatLength: " TIFF_UINT64_FORMAT "\n",(TIFF_UINT64_T)sp->jpeg_interchange_format_length); - if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGQTABLES)) - { - fprintf(fd," JpegQTables:"); - for (m=0; mqtable_offset_count; m++) - fprintf(fd," " TIFF_UINT64_FORMAT,(TIFF_UINT64_T)sp->qtable_offset[m]); - fprintf(fd,"\n"); - } - if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGDCTABLES)) - { - fprintf(fd," JpegDcTables:"); - for (m=0; mdctable_offset_count; m++) - fprintf(fd," " TIFF_UINT64_FORMAT,(TIFF_UINT64_T)sp->dctable_offset[m]); - fprintf(fd,"\n"); - } - if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGACTABLES)) - { - fprintf(fd," JpegAcTables:"); - for (m=0; mactable_offset_count; m++) - fprintf(fd," " TIFF_UINT64_FORMAT,(TIFF_UINT64_T)sp->actable_offset[m]); - fprintf(fd,"\n"); - } - if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGPROC)) - fprintf(fd," JpegProc: %u\n",(unsigned int)sp->jpeg_proc); - if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGRESTARTINTERVAL)) - fprintf(fd," JpegRestartInterval: %u\n",(unsigned int)sp->restart_interval); - if (sp->printdir) - (*sp->printdir)(tif, fd, flags); -} - -static int -OJPEGFixupTags(TIFF* tif) -{ - (void) tif; - return(1); -} - -static int -OJPEGSetupDecode(TIFF* tif) -{ - static const char module[]="OJPEGSetupDecode"; - TIFFWarningExt(tif->tif_clientdata,module,"Depreciated and troublesome old-style JPEG compression mode, please convert to new-style JPEG compression and notify vendor of writing software"); - return(1); -} - -static int -OJPEGPreDecode(TIFF* tif, uint16 s) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint32 m; - if (sp->subsamplingcorrect_done==0) - OJPEGSubsamplingCorrect(tif); - if (sp->readheader_done==0) - { - if (OJPEGReadHeaderInfo(tif)==0) - return(0); - } - if (sp->sos_end[s].log==0) - { - if (OJPEGReadSecondarySos(tif,s)==0) - return(0); - } - if isTiled(tif) - m=tif->tif_curtile; - else - m=tif->tif_curstrip; - if ((sp->writeheader_done!=0) && ((sp->write_cursample!=s) || (sp->write_curstrile>m))) - { - if (sp->libjpeg_session_active!=0) - OJPEGLibjpegSessionAbort(tif); - sp->writeheader_done=0; - } - if (sp->writeheader_done==0) - { - sp->plane_sample_offset=(uint8)s; - sp->write_cursample=s; - sp->write_curstrile=s*tif->tif_dir.td_stripsperimage; - if ((sp->in_buffer_file_pos_log==0) || - (sp->in_buffer_file_pos-sp->in_buffer_togo!=sp->sos_end[s].in_buffer_file_pos)) - { - sp->in_buffer_source=sp->sos_end[s].in_buffer_source; - sp->in_buffer_next_strile=sp->sos_end[s].in_buffer_next_strile; - sp->in_buffer_file_pos=sp->sos_end[s].in_buffer_file_pos; - sp->in_buffer_file_pos_log=0; - sp->in_buffer_file_togo=sp->sos_end[s].in_buffer_file_togo; - sp->in_buffer_togo=0; - sp->in_buffer_cur=0; - } - if (OJPEGWriteHeaderInfo(tif)==0) - return(0); - } - while (sp->write_curstrilelibjpeg_jpeg_query_style==0) - { - if (OJPEGPreDecodeSkipRaw(tif)==0) - return(0); - } - else - { - if (OJPEGPreDecodeSkipScanlines(tif)==0) - return(0); - } - sp->write_curstrile++; - } - return(1); -} - -static int -OJPEGPreDecodeSkipRaw(TIFF* tif) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint32 m; - m=sp->lines_per_strile; - if (sp->subsampling_convert_state!=0) - { - if (sp->subsampling_convert_clines-sp->subsampling_convert_state>=m) - { - sp->subsampling_convert_state+=m; - if (sp->subsampling_convert_state==sp->subsampling_convert_clines) - sp->subsampling_convert_state=0; - return(1); - } - m-=sp->subsampling_convert_clines-sp->subsampling_convert_state; - sp->subsampling_convert_state=0; - } - while (m>=sp->subsampling_convert_clines) - { - if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0) - return(0); - m-=sp->subsampling_convert_clines; - } - if (m>0) - { - if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0) - return(0); - sp->subsampling_convert_state=m; - } - return(1); -} - -static int -OJPEGPreDecodeSkipScanlines(TIFF* tif) -{ - static const char module[]="OJPEGPreDecodeSkipScanlines"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint32 m; - if (sp->skip_buffer==NULL) - { - sp->skip_buffer=_TIFFmalloc(sp->bytes_per_line); - if (sp->skip_buffer==NULL) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - } - for (m=0; mlines_per_strile; m++) - { - if (jpeg_read_scanlines_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),&sp->skip_buffer,1)==0) - return(0); - } - return(1); -} - -static int -OJPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - (void)s; - if (sp->libjpeg_jpeg_query_style==0) - { - if (OJPEGDecodeRaw(tif,buf,cc)==0) - return(0); - } - else - { - if (OJPEGDecodeScanlines(tif,buf,cc)==0) - return(0); - } - return(1); -} - -static int -OJPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc) -{ - static const char module[]="OJPEGDecodeRaw"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint8* m; - tmsize_t n; - uint8* oy; - uint8* ocb; - uint8* ocr; - uint8* p; - uint32 q; - uint8* r; - uint8 sx,sy; - if (cc%sp->bytes_per_line!=0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Fractional scanline not read"); - return(0); - } - assert(cc>0); - m=buf; - n=cc; - do - { - if (sp->subsampling_convert_state==0) - { - if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0) - return(0); - } - oy=sp->subsampling_convert_ybuf+sp->subsampling_convert_state*sp->subsampling_ver*sp->subsampling_convert_ylinelen; - ocb=sp->subsampling_convert_cbbuf+sp->subsampling_convert_state*sp->subsampling_convert_clinelen; - ocr=sp->subsampling_convert_crbuf+sp->subsampling_convert_state*sp->subsampling_convert_clinelen; - p=m; - for (q=0; qsubsampling_convert_clinelenout; q++) - { - r=oy; - for (sy=0; sysubsampling_ver; sy++) - { - for (sx=0; sxsubsampling_hor; sx++) - *p++=*r++; - r+=sp->subsampling_convert_ylinelen-sp->subsampling_hor; - } - oy+=sp->subsampling_hor; - *p++=*ocb++; - *p++=*ocr++; - } - sp->subsampling_convert_state++; - if (sp->subsampling_convert_state==sp->subsampling_convert_clines) - sp->subsampling_convert_state=0; - m+=sp->bytes_per_line; - n-=sp->bytes_per_line; - } while(n>0); - return(1); -} - -static int -OJPEGDecodeScanlines(TIFF* tif, uint8* buf, tmsize_t cc) -{ - static const char module[]="OJPEGDecodeScanlines"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint8* m; - tmsize_t n; - if (cc%sp->bytes_per_line!=0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Fractional scanline not read"); - return(0); - } - assert(cc>0); - m=buf; - n=cc; - do - { - if (jpeg_read_scanlines_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),&m,1)==0) - return(0); - m+=sp->bytes_per_line; - n-=sp->bytes_per_line; - } while(n>0); - return(1); -} - -static void -OJPEGPostDecode(TIFF* tif, uint8* buf, tmsize_t cc) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - (void)buf; - (void)cc; - sp->write_curstrile++; - if (sp->write_curstrile%tif->tif_dir.td_stripsperimage==0) - { - assert(sp->libjpeg_session_active!=0); - OJPEGLibjpegSessionAbort(tif); - sp->writeheader_done=0; - } -} - -static int -OJPEGSetupEncode(TIFF* tif) -{ - static const char module[]="OJPEGSetupEncode"; - TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead"); - return(0); -} - -static int -OJPEGPreEncode(TIFF* tif, uint16 s) -{ - static const char module[]="OJPEGPreEncode"; - (void)s; - TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead"); - return(0); -} - -static int -OJPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) -{ - static const char module[]="OJPEGEncode"; - (void)buf; - (void)cc; - (void)s; - TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead"); - return(0); -} - -static int -OJPEGPostEncode(TIFF* tif) -{ - static const char module[]="OJPEGPostEncode"; - TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead"); - return(0); -} - -static void -OJPEGCleanup(TIFF* tif) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - if (sp!=0) - { - tif->tif_tagmethods.vgetfield=sp->vgetparent; - tif->tif_tagmethods.vsetfield=sp->vsetparent; - tif->tif_tagmethods.printdir=sp->printdir; - if (sp->qtable[0]!=0) - _TIFFfree(sp->qtable[0]); - if (sp->qtable[1]!=0) - _TIFFfree(sp->qtable[1]); - if (sp->qtable[2]!=0) - _TIFFfree(sp->qtable[2]); - if (sp->qtable[3]!=0) - _TIFFfree(sp->qtable[3]); - if (sp->dctable[0]!=0) - _TIFFfree(sp->dctable[0]); - if (sp->dctable[1]!=0) - _TIFFfree(sp->dctable[1]); - if (sp->dctable[2]!=0) - _TIFFfree(sp->dctable[2]); - if (sp->dctable[3]!=0) - _TIFFfree(sp->dctable[3]); - if (sp->actable[0]!=0) - _TIFFfree(sp->actable[0]); - if (sp->actable[1]!=0) - _TIFFfree(sp->actable[1]); - if (sp->actable[2]!=0) - _TIFFfree(sp->actable[2]); - if (sp->actable[3]!=0) - _TIFFfree(sp->actable[3]); - if (sp->libjpeg_session_active!=0) - OJPEGLibjpegSessionAbort(tif); - if (sp->subsampling_convert_ycbcrbuf!=0) - _TIFFfree(sp->subsampling_convert_ycbcrbuf); - if (sp->subsampling_convert_ycbcrimage!=0) - _TIFFfree(sp->subsampling_convert_ycbcrimage); - if (sp->skip_buffer!=0) - _TIFFfree(sp->skip_buffer); - _TIFFfree(sp); - tif->tif_data=NULL; - _TIFFSetDefaultCompressionState(tif); - } -} - -static void -OJPEGSubsamplingCorrect(TIFF* tif) -{ - static const char module[]="OJPEGSubsamplingCorrect"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint8 mh; - uint8 mv; - _TIFFFillStriles( tif ); - - assert(sp->subsamplingcorrect_done==0); - if ((tif->tif_dir.td_samplesperpixel!=3) || ((tif->tif_dir.td_photometric!=PHOTOMETRIC_YCBCR) && - (tif->tif_dir.td_photometric!=PHOTOMETRIC_ITULAB))) - { - if (sp->subsampling_tag!=0) - TIFFWarningExt(tif->tif_clientdata,module,"Subsampling tag not appropriate for this Photometric and/or SamplesPerPixel"); - sp->subsampling_hor=1; - sp->subsampling_ver=1; - sp->subsampling_force_desubsampling_inside_decompression=0; - } - else - { - sp->subsamplingcorrect_done=1; - mh=sp->subsampling_hor; - mv=sp->subsampling_ver; - sp->subsamplingcorrect=1; - OJPEGReadHeaderInfoSec(tif); - if (sp->subsampling_force_desubsampling_inside_decompression!=0) - { - sp->subsampling_hor=1; - sp->subsampling_ver=1; - } - sp->subsamplingcorrect=0; - if (((sp->subsampling_hor!=mh) || (sp->subsampling_ver!=mv)) && (sp->subsampling_force_desubsampling_inside_decompression==0)) - { - if (sp->subsampling_tag==0) - TIFFWarningExt(tif->tif_clientdata,module,"Subsampling tag is not set, yet subsampling inside JPEG data [%d,%d] does not match default values [2,2]; assuming subsampling inside JPEG data is correct",sp->subsampling_hor,sp->subsampling_ver); - else - TIFFWarningExt(tif->tif_clientdata,module,"Subsampling inside JPEG data [%d,%d] does not match subsampling tag values [%d,%d]; assuming subsampling inside JPEG data is correct",sp->subsampling_hor,sp->subsampling_ver,mh,mv); - } - if (sp->subsampling_force_desubsampling_inside_decompression!=0) - { - if (sp->subsampling_tag==0) - TIFFWarningExt(tif->tif_clientdata,module,"Subsampling tag is not set, yet subsampling inside JPEG data does not match default values [2,2] (nor any other values allowed in TIFF); assuming subsampling inside JPEG data is correct and desubsampling inside JPEG decompression"); - else - TIFFWarningExt(tif->tif_clientdata,module,"Subsampling inside JPEG data does not match subsampling tag values [%d,%d] (nor any other values allowed in TIFF); assuming subsampling inside JPEG data is correct and desubsampling inside JPEG decompression",mh,mv); - } - if (sp->subsampling_force_desubsampling_inside_decompression==0) - { - if (sp->subsampling_horsubsampling_ver) - TIFFWarningExt(tif->tif_clientdata,module,"Subsampling values [%d,%d] are not allowed in TIFF",sp->subsampling_hor,sp->subsampling_ver); - } - } - sp->subsamplingcorrect_done=1; -} - -static int -OJPEGReadHeaderInfo(TIFF* tif) -{ - static const char module[]="OJPEGReadHeaderInfo"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - assert(sp->readheader_done==0); - sp->image_width=tif->tif_dir.td_imagewidth; - sp->image_length=tif->tif_dir.td_imagelength; - if isTiled(tif) - { - sp->strile_width=tif->tif_dir.td_tilewidth; - sp->strile_length=tif->tif_dir.td_tilelength; - sp->strile_length_total=((sp->image_length+sp->strile_length-1)/sp->strile_length)*sp->strile_length; - } - else - { - sp->strile_width=sp->image_width; - sp->strile_length=tif->tif_dir.td_rowsperstrip; - sp->strile_length_total=sp->image_length; - } - if (tif->tif_dir.td_samplesperpixel==1) - { - sp->samples_per_pixel=1; - sp->plane_sample_offset=0; - sp->samples_per_pixel_per_plane=sp->samples_per_pixel; - sp->subsampling_hor=1; - sp->subsampling_ver=1; - } - else - { - if (tif->tif_dir.td_samplesperpixel!=3) - { - TIFFErrorExt(tif->tif_clientdata,module,"SamplesPerPixel %d not supported for this compression scheme",sp->samples_per_pixel); - return(0); - } - sp->samples_per_pixel=3; - sp->plane_sample_offset=0; - if (tif->tif_dir.td_planarconfig==PLANARCONFIG_CONTIG) - sp->samples_per_pixel_per_plane=3; - else - sp->samples_per_pixel_per_plane=1; - } - if (sp->strile_lengthimage_length) - { - if (sp->strile_length%(sp->subsampling_ver*8)!=0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Incompatible vertical subsampling and image strip/tile length"); - return(0); - } - sp->restart_interval=((sp->strile_width+sp->subsampling_hor*8-1)/(sp->subsampling_hor*8))*(sp->strile_length/(sp->subsampling_ver*8)); - } - if (OJPEGReadHeaderInfoSec(tif)==0) - return(0); - sp->sos_end[0].log=1; - sp->sos_end[0].in_buffer_source=sp->in_buffer_source; - sp->sos_end[0].in_buffer_next_strile=sp->in_buffer_next_strile; - sp->sos_end[0].in_buffer_file_pos=sp->in_buffer_file_pos-sp->in_buffer_togo; - sp->sos_end[0].in_buffer_file_togo=sp->in_buffer_file_togo+sp->in_buffer_togo; - sp->readheader_done=1; - return(1); -} - -static int -OJPEGReadSecondarySos(TIFF* tif, uint16 s) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint8 m; - assert(s>0); - assert(s<3); - assert(sp->sos_end[0].log!=0); - assert(sp->sos_end[s].log==0); - sp->plane_sample_offset=s-1; - while(sp->sos_end[sp->plane_sample_offset].log==0) - sp->plane_sample_offset--; - sp->in_buffer_source=sp->sos_end[sp->plane_sample_offset].in_buffer_source; - sp->in_buffer_next_strile=sp->sos_end[sp->plane_sample_offset].in_buffer_next_strile; - sp->in_buffer_file_pos=sp->sos_end[sp->plane_sample_offset].in_buffer_file_pos; - sp->in_buffer_file_pos_log=0; - sp->in_buffer_file_togo=sp->sos_end[sp->plane_sample_offset].in_buffer_file_togo; - sp->in_buffer_togo=0; - sp->in_buffer_cur=0; - while(sp->plane_sample_offsetplane_sample_offset++; - if (OJPEGReadHeaderInfoSecStreamSos(tif)==0) - return(0); - sp->sos_end[sp->plane_sample_offset].log=1; - sp->sos_end[sp->plane_sample_offset].in_buffer_source=sp->in_buffer_source; - sp->sos_end[sp->plane_sample_offset].in_buffer_next_strile=sp->in_buffer_next_strile; - sp->sos_end[sp->plane_sample_offset].in_buffer_file_pos=sp->in_buffer_file_pos-sp->in_buffer_togo; - sp->sos_end[sp->plane_sample_offset].in_buffer_file_togo=sp->in_buffer_file_togo+sp->in_buffer_togo; - } - return(1); -} - -static int -OJPEGWriteHeaderInfo(TIFF* tif) -{ - static const char module[]="OJPEGWriteHeaderInfo"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint8** m; - uint32 n; - /* if a previous attempt failed, don't try again */ - if (sp->libjpeg_session_active != 0) - return 0; - sp->out_state=ososSoi; - sp->restart_index=0; - jpeg_std_error(&(sp->libjpeg_jpeg_error_mgr)); - sp->libjpeg_jpeg_error_mgr.output_message=OJPEGLibjpegJpegErrorMgrOutputMessage; - sp->libjpeg_jpeg_error_mgr.error_exit=OJPEGLibjpegJpegErrorMgrErrorExit; - sp->libjpeg_jpeg_decompress_struct.err=&(sp->libjpeg_jpeg_error_mgr); - sp->libjpeg_jpeg_decompress_struct.client_data=(void*)tif; - if (jpeg_create_decompress_encap(sp,&(sp->libjpeg_jpeg_decompress_struct))==0) - return(0); - sp->libjpeg_session_active=1; - sp->libjpeg_jpeg_source_mgr.bytes_in_buffer=0; - sp->libjpeg_jpeg_source_mgr.init_source=OJPEGLibjpegJpegSourceMgrInitSource; - sp->libjpeg_jpeg_source_mgr.fill_input_buffer=OJPEGLibjpegJpegSourceMgrFillInputBuffer; - sp->libjpeg_jpeg_source_mgr.skip_input_data=OJPEGLibjpegJpegSourceMgrSkipInputData; - sp->libjpeg_jpeg_source_mgr.resync_to_restart=OJPEGLibjpegJpegSourceMgrResyncToRestart; - sp->libjpeg_jpeg_source_mgr.term_source=OJPEGLibjpegJpegSourceMgrTermSource; - sp->libjpeg_jpeg_decompress_struct.src=&(sp->libjpeg_jpeg_source_mgr); - if (jpeg_read_header_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),1)==0) - return(0); - if ((sp->subsampling_force_desubsampling_inside_decompression==0) && (sp->samples_per_pixel_per_plane>1)) - { - sp->libjpeg_jpeg_decompress_struct.raw_data_out=1; -#if JPEG_LIB_VERSION >= 70 - sp->libjpeg_jpeg_decompress_struct.do_fancy_upsampling=FALSE; -#endif - sp->libjpeg_jpeg_query_style=0; - if (sp->subsampling_convert_log==0) - { - assert(sp->subsampling_convert_ycbcrbuf==0); - assert(sp->subsampling_convert_ycbcrimage==0); - sp->subsampling_convert_ylinelen=((sp->strile_width+sp->subsampling_hor*8-1)/(sp->subsampling_hor*8)*sp->subsampling_hor*8); - sp->subsampling_convert_ylines=sp->subsampling_ver*8; - sp->subsampling_convert_clinelen=sp->subsampling_convert_ylinelen/sp->subsampling_hor; - sp->subsampling_convert_clines=8; - sp->subsampling_convert_ybuflen=sp->subsampling_convert_ylinelen*sp->subsampling_convert_ylines; - sp->subsampling_convert_cbuflen=sp->subsampling_convert_clinelen*sp->subsampling_convert_clines; - sp->subsampling_convert_ycbcrbuflen=sp->subsampling_convert_ybuflen+2*sp->subsampling_convert_cbuflen; - sp->subsampling_convert_ycbcrbuf=_TIFFmalloc(sp->subsampling_convert_ycbcrbuflen); - if (sp->subsampling_convert_ycbcrbuf==0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - sp->subsampling_convert_ybuf=sp->subsampling_convert_ycbcrbuf; - sp->subsampling_convert_cbbuf=sp->subsampling_convert_ybuf+sp->subsampling_convert_ybuflen; - sp->subsampling_convert_crbuf=sp->subsampling_convert_cbbuf+sp->subsampling_convert_cbuflen; - sp->subsampling_convert_ycbcrimagelen=3+sp->subsampling_convert_ylines+2*sp->subsampling_convert_clines; - sp->subsampling_convert_ycbcrimage=_TIFFmalloc(sp->subsampling_convert_ycbcrimagelen*sizeof(uint8*)); - if (sp->subsampling_convert_ycbcrimage==0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - m=sp->subsampling_convert_ycbcrimage; - *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3); - *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3+sp->subsampling_convert_ylines); - *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3+sp->subsampling_convert_ylines+sp->subsampling_convert_clines); - for (n=0; nsubsampling_convert_ylines; n++) - *m++=sp->subsampling_convert_ybuf+n*sp->subsampling_convert_ylinelen; - for (n=0; nsubsampling_convert_clines; n++) - *m++=sp->subsampling_convert_cbbuf+n*sp->subsampling_convert_clinelen; - for (n=0; nsubsampling_convert_clines; n++) - *m++=sp->subsampling_convert_crbuf+n*sp->subsampling_convert_clinelen; - sp->subsampling_convert_clinelenout=((sp->strile_width+sp->subsampling_hor-1)/sp->subsampling_hor); - sp->subsampling_convert_state=0; - sp->bytes_per_line=sp->subsampling_convert_clinelenout*(sp->subsampling_ver*sp->subsampling_hor+2); - sp->lines_per_strile=((sp->strile_length+sp->subsampling_ver-1)/sp->subsampling_ver); - sp->subsampling_convert_log=1; - } - } - else - { - sp->libjpeg_jpeg_decompress_struct.jpeg_color_space=JCS_UNKNOWN; - sp->libjpeg_jpeg_decompress_struct.out_color_space=JCS_UNKNOWN; - sp->libjpeg_jpeg_query_style=1; - sp->bytes_per_line=sp->samples_per_pixel_per_plane*sp->strile_width; - sp->lines_per_strile=sp->strile_length; - } - if (jpeg_start_decompress_encap(sp,&(sp->libjpeg_jpeg_decompress_struct))==0) - return(0); - sp->writeheader_done=1; - return(1); -} - -static void -OJPEGLibjpegSessionAbort(TIFF* tif) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - assert(sp->libjpeg_session_active!=0); - jpeg_destroy((jpeg_common_struct*)(&(sp->libjpeg_jpeg_decompress_struct))); - sp->libjpeg_session_active=0; -} - -static int -OJPEGReadHeaderInfoSec(TIFF* tif) -{ - static const char module[]="OJPEGReadHeaderInfoSec"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint8 m; - uint16 n; - uint8 o; - if (sp->file_size==0) - sp->file_size=TIFFGetFileSize(tif); - if (sp->jpeg_interchange_format!=0) - { - if (sp->jpeg_interchange_format>=sp->file_size) - { - sp->jpeg_interchange_format=0; - sp->jpeg_interchange_format_length=0; - } - else - { - if ((sp->jpeg_interchange_format_length==0) || (sp->jpeg_interchange_format+sp->jpeg_interchange_format_length>sp->file_size)) - sp->jpeg_interchange_format_length=sp->file_size-sp->jpeg_interchange_format; - } - } - sp->in_buffer_source=osibsNotSetYet; - sp->in_buffer_next_strile=0; - sp->in_buffer_strile_count=tif->tif_dir.td_nstrips; - sp->in_buffer_file_togo=0; - sp->in_buffer_togo=0; - do - { - if (OJPEGReadBytePeek(sp,&m)==0) - return(0); - if (m!=255) - break; - OJPEGReadByteAdvance(sp); - do - { - if (OJPEGReadByte(sp,&m)==0) - return(0); - } while(m==255); - switch(m) - { - case JPEG_MARKER_SOI: - /* this type of marker has no data, and should be skipped */ - break; - case JPEG_MARKER_COM: - case JPEG_MARKER_APP0: - case JPEG_MARKER_APP0+1: - case JPEG_MARKER_APP0+2: - case JPEG_MARKER_APP0+3: - case JPEG_MARKER_APP0+4: - case JPEG_MARKER_APP0+5: - case JPEG_MARKER_APP0+6: - case JPEG_MARKER_APP0+7: - case JPEG_MARKER_APP0+8: - case JPEG_MARKER_APP0+9: - case JPEG_MARKER_APP0+10: - case JPEG_MARKER_APP0+11: - case JPEG_MARKER_APP0+12: - case JPEG_MARKER_APP0+13: - case JPEG_MARKER_APP0+14: - case JPEG_MARKER_APP0+15: - /* this type of marker has data, but it has no use to us (and no place here) and should be skipped */ - if (OJPEGReadWord(sp,&n)==0) - return(0); - if (n<2) - { - if (sp->subsamplingcorrect==0) - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JPEG data"); - return(0); - } - if (n>2) - OJPEGReadSkip(sp,n-2); - break; - case JPEG_MARKER_DRI: - if (OJPEGReadHeaderInfoSecStreamDri(tif)==0) - return(0); - break; - case JPEG_MARKER_DQT: - if (OJPEGReadHeaderInfoSecStreamDqt(tif)==0) - return(0); - break; - case JPEG_MARKER_DHT: - if (OJPEGReadHeaderInfoSecStreamDht(tif)==0) - return(0); - break; - case JPEG_MARKER_SOF0: - case JPEG_MARKER_SOF1: - case JPEG_MARKER_SOF3: - if (OJPEGReadHeaderInfoSecStreamSof(tif,m)==0) - return(0); - if (sp->subsamplingcorrect!=0) - return(1); - break; - case JPEG_MARKER_SOS: - if (sp->subsamplingcorrect!=0) - return(1); - assert(sp->plane_sample_offset==0); - if (OJPEGReadHeaderInfoSecStreamSos(tif)==0) - return(0); - break; - default: - TIFFErrorExt(tif->tif_clientdata,module,"Unknown marker type %d in JPEG data",m); - return(0); - } - } while(m!=JPEG_MARKER_SOS); - if (sp->subsamplingcorrect) - return(1); - if (sp->sof_log==0) - { - if (OJPEGReadHeaderInfoSecTablesQTable(tif)==0) - return(0); - sp->sof_marker_id=JPEG_MARKER_SOF0; - for (o=0; osamples_per_pixel; o++) - sp->sof_c[o]=o; - sp->sof_hv[0]=((sp->subsampling_hor<<4)|sp->subsampling_ver); - for (o=1; osamples_per_pixel; o++) - sp->sof_hv[o]=17; - sp->sof_x=sp->strile_width; - sp->sof_y=sp->strile_length_total; - sp->sof_log=1; - if (OJPEGReadHeaderInfoSecTablesDcTable(tif)==0) - return(0); - if (OJPEGReadHeaderInfoSecTablesAcTable(tif)==0) - return(0); - for (o=1; osamples_per_pixel; o++) - sp->sos_cs[o]=o; - } - return(1); -} - -static int -OJPEGReadHeaderInfoSecStreamDri(TIFF* tif) -{ - /* this could easilly cause trouble in some cases... but no such cases have occured sofar */ - static const char module[]="OJPEGReadHeaderInfoSecStreamDri"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint16 m; - if (OJPEGReadWord(sp,&m)==0) - return(0); - if (m!=4) - { - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DRI marker in JPEG data"); - return(0); - } - if (OJPEGReadWord(sp,&m)==0) - return(0); - sp->restart_interval=m; - return(1); -} - -static int -OJPEGReadHeaderInfoSecStreamDqt(TIFF* tif) -{ - /* this is a table marker, and it is to be saved as a whole for exact pushing on the jpeg stream later on */ - static const char module[]="OJPEGReadHeaderInfoSecStreamDqt"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint16 m; - uint32 na; - uint8* nb; - uint8 o; - if (OJPEGReadWord(sp,&m)==0) - return(0); - if (m<=2) - { - if (sp->subsamplingcorrect==0) - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DQT marker in JPEG data"); - return(0); - } - if (sp->subsamplingcorrect!=0) - OJPEGReadSkip(sp,m-2); - else - { - m-=2; - do - { - if (m<65) - { - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DQT marker in JPEG data"); - return(0); - } - na=sizeof(uint32)+69; - nb=_TIFFmalloc(na); - if (nb==0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - *(uint32*)nb=na; - nb[sizeof(uint32)]=255; - nb[sizeof(uint32)+1]=JPEG_MARKER_DQT; - nb[sizeof(uint32)+2]=0; - nb[sizeof(uint32)+3]=67; - if (OJPEGReadBlock(sp,65,&nb[sizeof(uint32)+4])==0) { - _TIFFfree(nb); - return(0); - } - o=nb[sizeof(uint32)+4]&15; - if (3tif_clientdata,module,"Corrupt DQT marker in JPEG data"); - _TIFFfree(nb); - return(0); - } - if (sp->qtable[o]!=0) - _TIFFfree(sp->qtable[o]); - sp->qtable[o]=nb; - m-=65; - } while(m>0); - } - return(1); -} - -static int -OJPEGReadHeaderInfoSecStreamDht(TIFF* tif) -{ - /* this is a table marker, and it is to be saved as a whole for exact pushing on the jpeg stream later on */ - /* TODO: the following assumes there is only one table in this marker... but i'm not quite sure that assumption is guaranteed correct */ - static const char module[]="OJPEGReadHeaderInfoSecStreamDht"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint16 m; - uint32 na; - uint8* nb; - uint8 o; - if (OJPEGReadWord(sp,&m)==0) - return(0); - if (m<=2) - { - if (sp->subsamplingcorrect==0) - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data"); - return(0); - } - if (sp->subsamplingcorrect!=0) - { - OJPEGReadSkip(sp,m-2); - } - else - { - na=sizeof(uint32)+2+m; - nb=_TIFFmalloc(na); - if (nb==0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - *(uint32*)nb=na; - nb[sizeof(uint32)]=255; - nb[sizeof(uint32)+1]=JPEG_MARKER_DHT; - nb[sizeof(uint32)+2]=(m>>8); - nb[sizeof(uint32)+3]=(m&255); - if (OJPEGReadBlock(sp,m-2,&nb[sizeof(uint32)+4])==0) - return(0); - o=nb[sizeof(uint32)+4]; - if ((o&240)==0) - { - if (3tif_clientdata,module,"Corrupt DHT marker in JPEG data"); - return(0); - } - if (sp->dctable[o]!=0) - _TIFFfree(sp->dctable[o]); - sp->dctable[o]=nb; - } - else - { - if ((o&240)!=16) - { - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data"); - return(0); - } - o&=15; - if (3tif_clientdata,module,"Corrupt DHT marker in JPEG data"); - return(0); - } - if (sp->actable[o]!=0) - _TIFFfree(sp->actable[o]); - sp->actable[o]=nb; - } - } - return(1); -} - -static int -OJPEGReadHeaderInfoSecStreamSof(TIFF* tif, uint8 marker_id) -{ - /* this marker needs to be checked, and part of its data needs to be saved for regeneration later on */ - static const char module[]="OJPEGReadHeaderInfoSecStreamSof"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint16 m; - uint16 n; - uint8 o; - uint16 p; - uint16 q; - if (sp->sof_log!=0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JPEG data"); - return(0); - } - if (sp->subsamplingcorrect==0) - sp->sof_marker_id=marker_id; - /* Lf: data length */ - if (OJPEGReadWord(sp,&m)==0) - return(0); - if (m<11) - { - if (sp->subsamplingcorrect==0) - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOF marker in JPEG data"); - return(0); - } - m-=8; - if (m%3!=0) - { - if (sp->subsamplingcorrect==0) - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOF marker in JPEG data"); - return(0); - } - n=m/3; - if (sp->subsamplingcorrect==0) - { - if (n!=sp->samples_per_pixel) - { - TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected number of samples"); - return(0); - } - } - /* P: Sample precision */ - if (OJPEGReadByte(sp,&o)==0) - return(0); - if (o!=8) - { - if (sp->subsamplingcorrect==0) - TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected number of bits per sample"); - return(0); - } - /* Y: Number of lines, X: Number of samples per line */ - if (sp->subsamplingcorrect) - OJPEGReadSkip(sp,4); - else - { - /* Y: Number of lines */ - if (OJPEGReadWord(sp,&p)==0) - return(0); - if (((uint32)pimage_length) && ((uint32)pstrile_length_total)) - { - TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected height"); - return(0); - } - sp->sof_y=p; - /* X: Number of samples per line */ - if (OJPEGReadWord(sp,&p)==0) - return(0); - if (((uint32)pimage_width) && ((uint32)pstrile_width)) - { - TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected width"); - return(0); - } - if ((uint32)p>sp->strile_width) - { - TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data image width exceeds expected image width"); - return(0); - } - sp->sof_x=p; - } - /* Nf: Number of image components in frame */ - if (OJPEGReadByte(sp,&o)==0) - return(0); - if (o!=n) - { - if (sp->subsamplingcorrect==0) - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOF marker in JPEG data"); - return(0); - } - /* per component stuff */ - /* TODO: double-check that flow implies that n cannot be as big as to make us overflow sof_c, sof_hv and sof_tq arrays */ - for (q=0; qsubsamplingcorrect==0) - sp->sof_c[q]=o; - /* H: Horizontal sampling factor, and V: Vertical sampling factor */ - if (OJPEGReadByte(sp,&o)==0) - return(0); - if (sp->subsamplingcorrect!=0) - { - if (q==0) - { - sp->subsampling_hor=(o>>4); - sp->subsampling_ver=(o&15); - if (((sp->subsampling_hor!=1) && (sp->subsampling_hor!=2) && (sp->subsampling_hor!=4)) || - ((sp->subsampling_ver!=1) && (sp->subsampling_ver!=2) && (sp->subsampling_ver!=4))) - sp->subsampling_force_desubsampling_inside_decompression=1; - } - else - { - if (o!=17) - sp->subsampling_force_desubsampling_inside_decompression=1; - } - } - else - { - sp->sof_hv[q]=o; - if (sp->subsampling_force_desubsampling_inside_decompression==0) - { - if (q==0) - { - if (o!=((sp->subsampling_hor<<4)|sp->subsampling_ver)) - { - TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected subsampling values"); - return(0); - } - } - else - { - if (o!=17) - { - TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected subsampling values"); - return(0); - } - } - } - } - /* Tq: Quantization table destination selector */ - if (OJPEGReadByte(sp,&o)==0) - return(0); - if (sp->subsamplingcorrect==0) - sp->sof_tq[q]=o; - } - if (sp->subsamplingcorrect==0) - sp->sof_log=1; - return(1); -} - -static int -OJPEGReadHeaderInfoSecStreamSos(TIFF* tif) -{ - /* this marker needs to be checked, and part of its data needs to be saved for regeneration later on */ - static const char module[]="OJPEGReadHeaderInfoSecStreamSos"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint16 m; - uint8 n; - uint8 o; - assert(sp->subsamplingcorrect==0); - if (sp->sof_log==0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOS marker in JPEG data"); - return(0); - } - /* Ls */ - if (OJPEGReadWord(sp,&m)==0) - return(0); - if (m!=6+sp->samples_per_pixel_per_plane*2) - { - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOS marker in JPEG data"); - return(0); - } - /* Ns */ - if (OJPEGReadByte(sp,&n)==0) - return(0); - if (n!=sp->samples_per_pixel_per_plane) - { - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOS marker in JPEG data"); - return(0); - } - /* Cs, Td, and Ta */ - for (o=0; osamples_per_pixel_per_plane; o++) - { - /* Cs */ - if (OJPEGReadByte(sp,&n)==0) - return(0); - sp->sos_cs[sp->plane_sample_offset+o]=n; - /* Td and Ta */ - if (OJPEGReadByte(sp,&n)==0) - return(0); - sp->sos_tda[sp->plane_sample_offset+o]=n; - } - /* skip Ss, Se, Ah, en Al -> no check, as per Tom Lane recommendation, as per LibJpeg source */ - OJPEGReadSkip(sp,3); - return(1); -} - -static int -OJPEGReadHeaderInfoSecTablesQTable(TIFF* tif) -{ - static const char module[]="OJPEGReadHeaderInfoSecTablesQTable"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint8 m; - uint8 n; - uint32 oa; - uint8* ob; - uint32 p; - if (sp->qtable_offset[0]==0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Missing JPEG tables"); - return(0); - } - sp->in_buffer_file_pos_log=0; - for (m=0; msamples_per_pixel; m++) - { - if ((sp->qtable_offset[m]!=0) && ((m==0) || (sp->qtable_offset[m]!=sp->qtable_offset[m-1]))) - { - for (n=0; nqtable_offset[m]==sp->qtable_offset[n]) - { - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JpegQTables tag value"); - return(0); - } - } - oa=sizeof(uint32)+69; - ob=_TIFFmalloc(oa); - if (ob==0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - *(uint32*)ob=oa; - ob[sizeof(uint32)]=255; - ob[sizeof(uint32)+1]=JPEG_MARKER_DQT; - ob[sizeof(uint32)+2]=0; - ob[sizeof(uint32)+3]=67; - ob[sizeof(uint32)+4]=m; - TIFFSeekFile(tif,sp->qtable_offset[m],SEEK_SET); - p=TIFFReadFile(tif,&ob[sizeof(uint32)+5],64); - if (p!=64) - return(0); - sp->qtable[m]=ob; - sp->sof_tq[m]=m; - } - else - sp->sof_tq[m]=sp->sof_tq[m-1]; - } - return(1); -} - -static int -OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif) -{ - static const char module[]="OJPEGReadHeaderInfoSecTablesDcTable"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint8 m; - uint8 n; - uint8 o[16]; - uint32 p; - uint32 q; - uint32 ra; - uint8* rb; - if (sp->dctable_offset[0]==0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Missing JPEG tables"); - return(0); - } - sp->in_buffer_file_pos_log=0; - for (m=0; msamples_per_pixel; m++) - { - if ((sp->dctable_offset[m]!=0) && ((m==0) || (sp->dctable_offset[m]!=sp->dctable_offset[m-1]))) - { - for (n=0; ndctable_offset[m]==sp->dctable_offset[n]) - { - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JpegDcTables tag value"); - return(0); - } - } - TIFFSeekFile(tif,sp->dctable_offset[m],SEEK_SET); - p=TIFFReadFile(tif,o,16); - if (p!=16) - return(0); - q=0; - for (n=0; n<16; n++) - q+=o[n]; - ra=sizeof(uint32)+21+q; - rb=_TIFFmalloc(ra); - if (rb==0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - *(uint32*)rb=ra; - rb[sizeof(uint32)]=255; - rb[sizeof(uint32)+1]=JPEG_MARKER_DHT; - rb[sizeof(uint32)+2]=((19+q)>>8); - rb[sizeof(uint32)+3]=((19+q)&255); - rb[sizeof(uint32)+4]=m; - for (n=0; n<16; n++) - rb[sizeof(uint32)+5+n]=o[n]; - p=TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); - if (p!=q) - return(0); - sp->dctable[m]=rb; - sp->sos_tda[m]=(m<<4); - } - else - sp->sos_tda[m]=sp->sos_tda[m-1]; - } - return(1); -} - -static int -OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif) -{ - static const char module[]="OJPEGReadHeaderInfoSecTablesAcTable"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint8 m; - uint8 n; - uint8 o[16]; - uint32 p; - uint32 q; - uint32 ra; - uint8* rb; - if (sp->actable_offset[0]==0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Missing JPEG tables"); - return(0); - } - sp->in_buffer_file_pos_log=0; - for (m=0; msamples_per_pixel; m++) - { - if ((sp->actable_offset[m]!=0) && ((m==0) || (sp->actable_offset[m]!=sp->actable_offset[m-1]))) - { - for (n=0; nactable_offset[m]==sp->actable_offset[n]) - { - TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JpegAcTables tag value"); - return(0); - } - } - TIFFSeekFile(tif,sp->actable_offset[m],SEEK_SET); - p=TIFFReadFile(tif,o,16); - if (p!=16) - return(0); - q=0; - for (n=0; n<16; n++) - q+=o[n]; - ra=sizeof(uint32)+21+q; - rb=_TIFFmalloc(ra); - if (rb==0) - { - TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); - return(0); - } - *(uint32*)rb=ra; - rb[sizeof(uint32)]=255; - rb[sizeof(uint32)+1]=JPEG_MARKER_DHT; - rb[sizeof(uint32)+2]=((19+q)>>8); - rb[sizeof(uint32)+3]=((19+q)&255); - rb[sizeof(uint32)+4]=(16|m); - for (n=0; n<16; n++) - rb[sizeof(uint32)+5+n]=o[n]; - p=TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); - if (p!=q) - return(0); - sp->actable[m]=rb; - sp->sos_tda[m]=(sp->sos_tda[m]|m); - } - else - sp->sos_tda[m]=(sp->sos_tda[m]|(sp->sos_tda[m-1]&15)); - } - return(1); -} - -static int -OJPEGReadBufferFill(OJPEGState* sp) -{ - uint16 m; - tmsize_t n; - /* TODO: double-check: when subsamplingcorrect is set, no call to TIFFErrorExt or TIFFWarningExt should be made - * in any other case, seek or read errors should be passed through */ - do - { - if (sp->in_buffer_file_togo!=0) - { - if (sp->in_buffer_file_pos_log==0) - { - TIFFSeekFile(sp->tif,sp->in_buffer_file_pos,SEEK_SET); - sp->in_buffer_file_pos_log=1; - } - m=OJPEG_BUFFER; - if ((uint64)m>sp->in_buffer_file_togo) - m=(uint16)sp->in_buffer_file_togo; - n=TIFFReadFile(sp->tif,sp->in_buffer,(tmsize_t)m); - if (n==0) - return(0); - assert(n>0); - assert(n<=OJPEG_BUFFER); - assert(n<65536); - assert((uint64)n<=sp->in_buffer_file_togo); - m=(uint16)n; - sp->in_buffer_togo=m; - sp->in_buffer_cur=sp->in_buffer; - sp->in_buffer_file_togo-=m; - sp->in_buffer_file_pos+=m; - break; - } - sp->in_buffer_file_pos_log=0; - switch(sp->in_buffer_source) - { - case osibsNotSetYet: - if (sp->jpeg_interchange_format!=0) - { - sp->in_buffer_file_pos=sp->jpeg_interchange_format; - sp->in_buffer_file_togo=sp->jpeg_interchange_format_length; - } - sp->in_buffer_source=osibsJpegInterchangeFormat; - break; - case osibsJpegInterchangeFormat: - sp->in_buffer_source=osibsStrile; - case osibsStrile: - if (!_TIFFFillStriles( sp->tif ) - || sp->tif->tif_dir.td_stripoffset == NULL - || sp->tif->tif_dir.td_stripbytecount == NULL) - return 0; - - if (sp->in_buffer_next_strile==sp->in_buffer_strile_count) - sp->in_buffer_source=osibsEof; - else - { - sp->in_buffer_file_pos=sp->tif->tif_dir.td_stripoffset[sp->in_buffer_next_strile]; - if (sp->in_buffer_file_pos!=0) - { - if (sp->in_buffer_file_pos>=sp->file_size) - sp->in_buffer_file_pos=0; - else if (sp->tif->tif_dir.td_stripbytecount==NULL) - sp->in_buffer_file_togo=sp->file_size-sp->in_buffer_file_pos; - else - { - if (sp->tif->tif_dir.td_stripbytecount == 0) { - TIFFErrorExt(sp->tif->tif_clientdata,sp->tif->tif_name,"Strip byte counts are missing"); - return(0); - } - sp->in_buffer_file_togo=sp->tif->tif_dir.td_stripbytecount[sp->in_buffer_next_strile]; - if (sp->in_buffer_file_togo==0) - sp->in_buffer_file_pos=0; - else if (sp->in_buffer_file_pos+sp->in_buffer_file_togo>sp->file_size) - sp->in_buffer_file_togo=sp->file_size-sp->in_buffer_file_pos; - } - } - sp->in_buffer_next_strile++; - } - break; - default: - return(0); - } - } while (1); - return(1); -} - -static int -OJPEGReadByte(OJPEGState* sp, uint8* byte) -{ - if (sp->in_buffer_togo==0) - { - if (OJPEGReadBufferFill(sp)==0) - return(0); - assert(sp->in_buffer_togo>0); - } - *byte=*(sp->in_buffer_cur); - sp->in_buffer_cur++; - sp->in_buffer_togo--; - return(1); -} - -static int -OJPEGReadBytePeek(OJPEGState* sp, uint8* byte) -{ - if (sp->in_buffer_togo==0) - { - if (OJPEGReadBufferFill(sp)==0) - return(0); - assert(sp->in_buffer_togo>0); - } - *byte=*(sp->in_buffer_cur); - return(1); -} - -static void -OJPEGReadByteAdvance(OJPEGState* sp) -{ - assert(sp->in_buffer_togo>0); - sp->in_buffer_cur++; - sp->in_buffer_togo--; -} - -static int -OJPEGReadWord(OJPEGState* sp, uint16* word) -{ - uint8 m; - if (OJPEGReadByte(sp,&m)==0) - return(0); - *word=(m<<8); - if (OJPEGReadByte(sp,&m)==0) - return(0); - *word|=m; - return(1); -} - -static int -OJPEGReadBlock(OJPEGState* sp, uint16 len, void* mem) -{ - uint16 mlen; - uint8* mmem; - uint16 n; - assert(len>0); - mlen=len; - mmem=mem; - do - { - if (sp->in_buffer_togo==0) - { - if (OJPEGReadBufferFill(sp)==0) - return(0); - assert(sp->in_buffer_togo>0); - } - n=mlen; - if (n>sp->in_buffer_togo) - n=sp->in_buffer_togo; - _TIFFmemcpy(mmem,sp->in_buffer_cur,n); - sp->in_buffer_cur+=n; - sp->in_buffer_togo-=n; - mlen-=n; - mmem+=n; - } while(mlen>0); - return(1); -} - -static void -OJPEGReadSkip(OJPEGState* sp, uint16 len) -{ - uint16 m; - uint16 n; - m=len; - n=m; - if (n>sp->in_buffer_togo) - n=sp->in_buffer_togo; - sp->in_buffer_cur+=n; - sp->in_buffer_togo-=n; - m-=n; - if (m>0) - { - assert(sp->in_buffer_togo==0); - n=m; - if ((uint64)n>sp->in_buffer_file_togo) - n=(uint16)sp->in_buffer_file_togo; - sp->in_buffer_file_pos+=n; - sp->in_buffer_file_togo-=n; - sp->in_buffer_file_pos_log=0; - /* we don't skip past jpeginterchangeformat/strile block... - * if that is asked from us, we're dealing with totally bazurk - * data anyway, and we've not seen this happening on any - * testfile, so we might as well likely cause some other - * meaningless error to be passed at some later time - */ - } -} - -static int -OJPEGWriteStream(TIFF* tif, void** mem, uint32* len) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - *len=0; - do - { - assert(sp->out_state<=ososEoi); - switch(sp->out_state) - { - case ososSoi: - OJPEGWriteStreamSoi(tif,mem,len); - break; - case ososQTable0: - OJPEGWriteStreamQTable(tif,0,mem,len); - break; - case ososQTable1: - OJPEGWriteStreamQTable(tif,1,mem,len); - break; - case ososQTable2: - OJPEGWriteStreamQTable(tif,2,mem,len); - break; - case ososQTable3: - OJPEGWriteStreamQTable(tif,3,mem,len); - break; - case ososDcTable0: - OJPEGWriteStreamDcTable(tif,0,mem,len); - break; - case ososDcTable1: - OJPEGWriteStreamDcTable(tif,1,mem,len); - break; - case ososDcTable2: - OJPEGWriteStreamDcTable(tif,2,mem,len); - break; - case ososDcTable3: - OJPEGWriteStreamDcTable(tif,3,mem,len); - break; - case ososAcTable0: - OJPEGWriteStreamAcTable(tif,0,mem,len); - break; - case ososAcTable1: - OJPEGWriteStreamAcTable(tif,1,mem,len); - break; - case ososAcTable2: - OJPEGWriteStreamAcTable(tif,2,mem,len); - break; - case ososAcTable3: - OJPEGWriteStreamAcTable(tif,3,mem,len); - break; - case ososDri: - OJPEGWriteStreamDri(tif,mem,len); - break; - case ososSof: - OJPEGWriteStreamSof(tif,mem,len); - break; - case ososSos: - OJPEGWriteStreamSos(tif,mem,len); - break; - case ososCompressed: - if (OJPEGWriteStreamCompressed(tif,mem,len)==0) - return(0); - break; - case ososRst: - OJPEGWriteStreamRst(tif,mem,len); - break; - case ososEoi: - OJPEGWriteStreamEoi(tif,mem,len); - break; - } - } while (*len==0); - return(1); -} - -static void -OJPEGWriteStreamSoi(TIFF* tif, void** mem, uint32* len) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - assert(OJPEG_BUFFER>=2); - sp->out_buffer[0]=255; - sp->out_buffer[1]=JPEG_MARKER_SOI; - *len=2; - *mem=(void*)sp->out_buffer; - sp->out_state++; -} - -static void -OJPEGWriteStreamQTable(TIFF* tif, uint8 table_index, void** mem, uint32* len) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - if (sp->qtable[table_index]!=0) - { - *mem=(void*)(sp->qtable[table_index]+sizeof(uint32)); - *len=*((uint32*)sp->qtable[table_index])-sizeof(uint32); - } - sp->out_state++; -} - -static void -OJPEGWriteStreamDcTable(TIFF* tif, uint8 table_index, void** mem, uint32* len) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - if (sp->dctable[table_index]!=0) - { - *mem=(void*)(sp->dctable[table_index]+sizeof(uint32)); - *len=*((uint32*)sp->dctable[table_index])-sizeof(uint32); - } - sp->out_state++; -} - -static void -OJPEGWriteStreamAcTable(TIFF* tif, uint8 table_index, void** mem, uint32* len) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - if (sp->actable[table_index]!=0) - { - *mem=(void*)(sp->actable[table_index]+sizeof(uint32)); - *len=*((uint32*)sp->actable[table_index])-sizeof(uint32); - } - sp->out_state++; -} - -static void -OJPEGWriteStreamDri(TIFF* tif, void** mem, uint32* len) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - assert(OJPEG_BUFFER>=6); - if (sp->restart_interval!=0) - { - sp->out_buffer[0]=255; - sp->out_buffer[1]=JPEG_MARKER_DRI; - sp->out_buffer[2]=0; - sp->out_buffer[3]=4; - sp->out_buffer[4]=(sp->restart_interval>>8); - sp->out_buffer[5]=(sp->restart_interval&255); - *len=6; - *mem=(void*)sp->out_buffer; - } - sp->out_state++; -} - -static void -OJPEGWriteStreamSof(TIFF* tif, void** mem, uint32* len) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint8 m; - assert(OJPEG_BUFFER>=2+8+sp->samples_per_pixel_per_plane*3); - assert(255>=8+sp->samples_per_pixel_per_plane*3); - sp->out_buffer[0]=255; - sp->out_buffer[1]=sp->sof_marker_id; - /* Lf */ - sp->out_buffer[2]=0; - sp->out_buffer[3]=8+sp->samples_per_pixel_per_plane*3; - /* P */ - sp->out_buffer[4]=8; - /* Y */ - sp->out_buffer[5]=(sp->sof_y>>8); - sp->out_buffer[6]=(sp->sof_y&255); - /* X */ - sp->out_buffer[7]=(sp->sof_x>>8); - sp->out_buffer[8]=(sp->sof_x&255); - /* Nf */ - sp->out_buffer[9]=sp->samples_per_pixel_per_plane; - for (m=0; msamples_per_pixel_per_plane; m++) - { - /* C */ - sp->out_buffer[10+m*3]=sp->sof_c[sp->plane_sample_offset+m]; - /* H and V */ - sp->out_buffer[10+m*3+1]=sp->sof_hv[sp->plane_sample_offset+m]; - /* Tq */ - sp->out_buffer[10+m*3+2]=sp->sof_tq[sp->plane_sample_offset+m]; - } - *len=10+sp->samples_per_pixel_per_plane*3; - *mem=(void*)sp->out_buffer; - sp->out_state++; -} - -static void -OJPEGWriteStreamSos(TIFF* tif, void** mem, uint32* len) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - uint8 m; - assert(OJPEG_BUFFER>=2+6+sp->samples_per_pixel_per_plane*2); - assert(255>=6+sp->samples_per_pixel_per_plane*2); - sp->out_buffer[0]=255; - sp->out_buffer[1]=JPEG_MARKER_SOS; - /* Ls */ - sp->out_buffer[2]=0; - sp->out_buffer[3]=6+sp->samples_per_pixel_per_plane*2; - /* Ns */ - sp->out_buffer[4]=sp->samples_per_pixel_per_plane; - for (m=0; msamples_per_pixel_per_plane; m++) - { - /* Cs */ - sp->out_buffer[5+m*2]=sp->sos_cs[sp->plane_sample_offset+m]; - /* Td and Ta */ - sp->out_buffer[5+m*2+1]=sp->sos_tda[sp->plane_sample_offset+m]; - } - /* Ss */ - sp->out_buffer[5+sp->samples_per_pixel_per_plane*2]=0; - /* Se */ - sp->out_buffer[5+sp->samples_per_pixel_per_plane*2+1]=63; - /* Ah and Al */ - sp->out_buffer[5+sp->samples_per_pixel_per_plane*2+2]=0; - *len=8+sp->samples_per_pixel_per_plane*2; - *mem=(void*)sp->out_buffer; - sp->out_state++; -} - -static int -OJPEGWriteStreamCompressed(TIFF* tif, void** mem, uint32* len) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - if (sp->in_buffer_togo==0) - { - if (OJPEGReadBufferFill(sp)==0) - return(0); - assert(sp->in_buffer_togo>0); - } - *len=sp->in_buffer_togo; - *mem=(void*)sp->in_buffer_cur; - sp->in_buffer_togo=0; - if (sp->in_buffer_file_togo==0) - { - switch(sp->in_buffer_source) - { - case osibsStrile: - if (sp->in_buffer_next_strilein_buffer_strile_count) - sp->out_state=ososRst; - else - sp->out_state=ososEoi; - break; - case osibsEof: - sp->out_state=ososEoi; - break; - default: - break; - } - } - return(1); -} - -static void -OJPEGWriteStreamRst(TIFF* tif, void** mem, uint32* len) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - assert(OJPEG_BUFFER>=2); - sp->out_buffer[0]=255; - sp->out_buffer[1]=JPEG_MARKER_RST0+sp->restart_index; - sp->restart_index++; - if (sp->restart_index==8) - sp->restart_index=0; - *len=2; - *mem=(void*)sp->out_buffer; - sp->out_state=ososCompressed; -} - -static void -OJPEGWriteStreamEoi(TIFF* tif, void** mem, uint32* len) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - assert(OJPEG_BUFFER>=2); - sp->out_buffer[0]=255; - sp->out_buffer[1]=JPEG_MARKER_EOI; - *len=2; - *mem=(void*)sp->out_buffer; -} - -#ifndef LIBJPEG_ENCAP_EXTERNAL -static int -jpeg_create_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo) -{ - return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_create_decompress(cinfo),1)); -} -#endif - -#ifndef LIBJPEG_ENCAP_EXTERNAL -static int -jpeg_read_header_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, uint8 require_image) -{ - return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_read_header(cinfo,require_image),1)); -} -#endif - -#ifndef LIBJPEG_ENCAP_EXTERNAL -static int -jpeg_start_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo) -{ - return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_start_decompress(cinfo),1)); -} -#endif - -#ifndef LIBJPEG_ENCAP_EXTERNAL -static int -jpeg_read_scanlines_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* scanlines, uint32 max_lines) -{ - return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_read_scanlines(cinfo,scanlines,max_lines),1)); -} -#endif - -#ifndef LIBJPEG_ENCAP_EXTERNAL -static int -jpeg_read_raw_data_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* data, uint32 max_lines) -{ - return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_read_raw_data(cinfo,data,max_lines),1)); -} -#endif - -#ifndef LIBJPEG_ENCAP_EXTERNAL -static void -jpeg_encap_unwind(TIFF* tif) -{ - OJPEGState* sp=(OJPEGState*)tif->tif_data; - LONGJMP(sp->exit_jmpbuf,1); -} -#endif - -static void -OJPEGLibjpegJpegErrorMgrOutputMessage(jpeg_common_struct* cinfo) -{ - char buffer[JMSG_LENGTH_MAX]; - (*cinfo->err->format_message)(cinfo,buffer); - TIFFWarningExt(((TIFF*)(cinfo->client_data))->tif_clientdata,"LibJpeg","%s",buffer); -} - -static void -OJPEGLibjpegJpegErrorMgrErrorExit(jpeg_common_struct* cinfo) -{ - char buffer[JMSG_LENGTH_MAX]; - (*cinfo->err->format_message)(cinfo,buffer); - TIFFErrorExt(((TIFF*)(cinfo->client_data))->tif_clientdata,"LibJpeg","%s",buffer); - jpeg_encap_unwind((TIFF*)(cinfo->client_data)); -} - -static void -OJPEGLibjpegJpegSourceMgrInitSource(jpeg_decompress_struct* cinfo) -{ - (void)cinfo; -} - -static boolean -OJPEGLibjpegJpegSourceMgrFillInputBuffer(jpeg_decompress_struct* cinfo) -{ - TIFF* tif=(TIFF*)cinfo->client_data; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - void* mem=0; - uint32 len=0U; - if (OJPEGWriteStream(tif,&mem,&len)==0) - { - TIFFErrorExt(tif->tif_clientdata,"LibJpeg","Premature end of JPEG data"); - jpeg_encap_unwind(tif); - } - sp->libjpeg_jpeg_source_mgr.bytes_in_buffer=len; - sp->libjpeg_jpeg_source_mgr.next_input_byte=mem; - return(1); -} - -static void -OJPEGLibjpegJpegSourceMgrSkipInputData(jpeg_decompress_struct* cinfo, long num_bytes) -{ - TIFF* tif=(TIFF*)cinfo->client_data; - (void)num_bytes; - TIFFErrorExt(tif->tif_clientdata,"LibJpeg","Unexpected error"); - jpeg_encap_unwind(tif); -} - -static boolean -OJPEGLibjpegJpegSourceMgrResyncToRestart(jpeg_decompress_struct* cinfo, int desired) -{ - TIFF* tif=(TIFF*)cinfo->client_data; - (void)desired; - TIFFErrorExt(tif->tif_clientdata,"LibJpeg","Unexpected error"); - jpeg_encap_unwind(tif); - return(0); -} - -static void -OJPEGLibjpegJpegSourceMgrTermSource(jpeg_decompress_struct* cinfo) -{ - (void)cinfo; -} - -#endif - - -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_ojpeg.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* WARNING: The type of JPEG encapsulation defined by the TIFF Version 6.0 + specification is now totally obsolete and deprecated for new applications and + images. This file was was created solely in order to read unconverted images + still present on some users' computer systems. It will never be extended + to write such files. Writing new-style JPEG compressed TIFFs is implemented + in tif_jpeg.c. + + The code is carefully crafted to robustly read all gathered JPEG-in-TIFF + testfiles, and anticipate as much as possible all other... But still, it may + fail on some. If you encounter problems, please report them on the TIFF + mailing list and/or to Joris Van Damme . + + Please read the file called "TIFF Technical Note #2" if you need to be + convinced this compression scheme is bad and breaks TIFF. That document + is linked to from the LibTiff site + and from AWare Systems' TIFF section + . It is also absorbed + in Adobe's specification supplements, marked "draft" up to this day, but + supported by the TIFF community. + + This file interfaces with Release 6B of the JPEG Library written by the + Independent JPEG Group. Previous versions of this file required a hack inside + the LibJpeg library. This version no longer requires that. Remember to + remove the hack if you update from the old version. + + Copyright (c) Joris Van Damme + Copyright (c) AWare Systems + + The licence agreement for this file is the same as the rest of the LibTiff + library. + + IN NO EVENT SHALL JORIS VAN DAMME OR AWARE SYSTEMS BE LIABLE FOR + ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + OF THIS SOFTWARE. + + Joris Van Damme and/or AWare Systems may be available for custom + developement. If you like what you see, and need anything similar or related, + contact . +*/ + +/* What is what, and what is not? + + This decoder starts with an input stream, that is essentially the JpegInterchangeFormat + stream, if any, followed by the strile data, if any. This stream is read in + OJPEGReadByte and related functions. + + It analyzes the start of this stream, until it encounters non-marker data, i.e. + compressed image data. Some of the header markers it sees have no actual content, + like the SOI marker, and APP/COM markers that really shouldn't even be there. Some + other markers do have content, and the valuable bits and pieces of information + in these markers are saved, checking all to verify that the stream is more or + less within expected bounds. This happens inside the OJPEGReadHeaderInfoSecStreamXxx + functions. + + Some OJPEG imagery contains no valid JPEG header markers. This situation is picked + up on if we've seen no SOF marker when we're at the start of the compressed image + data. In this case, the tables are read from JpegXxxTables tags, and the other + bits and pieces of information is initialized to its most basic value. This is + implemented in the OJPEGReadHeaderInfoSecTablesXxx functions. + + When this is complete, a good and valid JPEG header can be assembled, and this is + passed through to LibJpeg. When that's done, the remainder of the input stream, i.e. + the compressed image data, can be passed through unchanged. This is done in + OJPEGWriteStream functions. + + LibTiff rightly expects to know the subsampling values before decompression. Just like + in new-style JPEG-in-TIFF, though, or even more so, actually, the YCbCrsubsampling + tag is notoriously unreliable. To correct these tag values with the ones inside + the JPEG stream, the first part of the input stream is pre-scanned in + OJPEGSubsamplingCorrect, making no note of any other data, reporting no warnings + or errors, up to the point where either these values are read, or it's clear they + aren't there. This means that some of the data is read twice, but we feel speed + in correcting these values is important enough to warrant this sacrifice. Allthough + there is currently no define or other configuration mechanism to disable this behaviour, + the actual header scanning is build to robustly respond with error report if it + should encounter an uncorrected mismatch of subsampling values. See + OJPEGReadHeaderInfoSecStreamSof. + + The restart interval and restart markers are the most tricky part... The restart + interval can be specified in a tag. It can also be set inside the input JPEG stream. + It can be used inside the input JPEG stream. If reading from strile data, we've + consistenly discovered the need to insert restart markers in between the different + striles, as is also probably the most likely interpretation of the original TIFF 6.0 + specification. With all this setting of interval, and actual use of markers that is not + predictable at the time of valid JPEG header assembly, the restart thing may turn + out the Achilles heel of this implementation. Fortunately, most OJPEG writer vendors + succeed in reading back what they write, which may be the reason why we've been able + to discover ways that seem to work. + + Some special provision is made for planarconfig separate OJPEG files. These seem + to consistently contain header info, a SOS marker, a plane, SOS marker, plane, SOS, + and plane. This may or may not be a valid JPEG configuration, we don't know and don't + care. We want LibTiff to be able to access the planes individually, without huge + buffering inside LibJpeg, anyway. So we compose headers to feed to LibJpeg, in this + case, that allow us to pass a single plane such that LibJpeg sees a valid + single-channel JPEG stream. Locating subsequent SOS markers, and thus subsequent + planes, is done inside OJPEGReadSecondarySos. + + The benefit of the scheme is... that it works, basically. We know of no other that + does. It works without checking software tag, or otherwise going about things in an + OJPEG flavor specific manner. Instead, it is a single scheme, that covers the cases + with and without JpegInterchangeFormat, with and without striles, with part of + the header in JpegInterchangeFormat and remainder in first strile, etc. It is forgiving + and robust, may likely work with OJPEG flavors we've not seen yet, and makes most out + of the data. + + Another nice side-effect is that a complete JPEG single valid stream is build if + planarconfig is not separate (vast majority). We may one day use that to build + converters to JPEG, and/or to new-style JPEG compression inside TIFF. + + A dissadvantage is the lack of random access to the individual striles. This is the + reason for much of the complicated restart-and-position stuff inside OJPEGPreDecode. + Applications would do well accessing all striles in order, as this will result in + a single sequential scan of the input stream, and no restarting of LibJpeg decoding + session. +*/ + +#define WIN32_LEAN_AND_MEAN +#define VC_EXTRALEAN + +#include "tiffiop.h" +#ifdef OJPEG_SUPPORT + +/* Configuration defines here are: + * JPEG_ENCAP_EXTERNAL: The normal way to call libjpeg, uses longjump. In some environments, + * like eg LibTiffDelphi, this is not possible. For this reason, the actual calls to + * libjpeg, with longjump stuff, are encapsulated in dedicated functions. When + * JPEG_ENCAP_EXTERNAL is defined, these encapsulating functions are declared external + * to this unit, and can be defined elsewhere to use stuff other then longjump. + * The default mode, without JPEG_ENCAP_EXTERNAL, implements the call encapsulators + * here, internally, with normal longjump. + * SETJMP, LONGJMP, JMP_BUF: On some machines/environments a longjump equivalent is + * conviniently available, but still it may be worthwhile to use _setjmp or sigsetjmp + * in place of plain setjmp. These macros will make it easier. It is useless + * to fiddle with these if you define JPEG_ENCAP_EXTERNAL. + * OJPEG_BUFFER: Define the size of the desired buffer here. Should be small enough so as to guarantee + * instant processing, optimal streaming and optimal use of processor cache, but also big + * enough so as to not result in significant call overhead. It should be at least a few + * bytes to accomodate some structures (this is verified in asserts), but it would not be + * sensible to make it this small anyway, and it should be at most 64K since it is indexed + * with uint16. We recommend 2K. + * EGYPTIANWALK: You could also define EGYPTIANWALK here, but it is not used anywhere and has + * absolutely no effect. That is why most people insist the EGYPTIANWALK is a bit silly. + */ + +/* define LIBJPEG_ENCAP_EXTERNAL */ +#define SETJMP(jbuf) setjmp(jbuf) +#define LONGJMP(jbuf,code) longjmp(jbuf,code) +#define JMP_BUF jmp_buf +#define OJPEG_BUFFER 2048 +/* define EGYPTIANWALK */ + +#define JPEG_MARKER_SOF0 0xC0 +#define JPEG_MARKER_SOF1 0xC1 +#define JPEG_MARKER_SOF3 0xC3 +#define JPEG_MARKER_DHT 0xC4 +#define JPEG_MARKER_RST0 0XD0 +#define JPEG_MARKER_SOI 0xD8 +#define JPEG_MARKER_EOI 0xD9 +#define JPEG_MARKER_SOS 0xDA +#define JPEG_MARKER_DQT 0xDB +#define JPEG_MARKER_DRI 0xDD +#define JPEG_MARKER_APP0 0xE0 +#define JPEG_MARKER_COM 0xFE + +#define FIELD_OJPEG_JPEGINTERCHANGEFORMAT (FIELD_CODEC+0) +#define FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH (FIELD_CODEC+1) +#define FIELD_OJPEG_JPEGQTABLES (FIELD_CODEC+2) +#define FIELD_OJPEG_JPEGDCTABLES (FIELD_CODEC+3) +#define FIELD_OJPEG_JPEGACTABLES (FIELD_CODEC+4) +#define FIELD_OJPEG_JPEGPROC (FIELD_CODEC+5) +#define FIELD_OJPEG_JPEGRESTARTINTERVAL (FIELD_CODEC+6) + +static const TIFFField ojpegFields[] = { + {TIFFTAG_JPEGIFOFFSET,1,1,TIFF_LONG8,0,TIFF_SETGET_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGINTERCHANGEFORMAT,TRUE,FALSE,"JpegInterchangeFormat",NULL}, + {TIFFTAG_JPEGIFBYTECOUNT,1,1,TIFF_LONG8,0,TIFF_SETGET_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH,TRUE,FALSE,"JpegInterchangeFormatLength",NULL}, + {TIFFTAG_JPEGQTABLES,TIFF_VARIABLE2,TIFF_VARIABLE2,TIFF_LONG8,0,TIFF_SETGET_C32_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGQTABLES,FALSE,TRUE,"JpegQTables",NULL}, + {TIFFTAG_JPEGDCTABLES,TIFF_VARIABLE2,TIFF_VARIABLE2,TIFF_LONG8,0,TIFF_SETGET_C32_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGDCTABLES,FALSE,TRUE,"JpegDcTables",NULL}, + {TIFFTAG_JPEGACTABLES,TIFF_VARIABLE2,TIFF_VARIABLE2,TIFF_LONG8,0,TIFF_SETGET_C32_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGACTABLES,FALSE,TRUE,"JpegAcTables",NULL}, + {TIFFTAG_JPEGPROC,1,1,TIFF_SHORT,0,TIFF_SETGET_UINT16,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGPROC,FALSE,FALSE,"JpegProc",NULL}, + {TIFFTAG_JPEGRESTARTINTERVAL,1,1,TIFF_SHORT,0,TIFF_SETGET_UINT16,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGRESTARTINTERVAL,FALSE,FALSE,"JpegRestartInterval",NULL}, +}; + +#ifndef LIBJPEG_ENCAP_EXTERNAL +#include +#endif + +/* We undefine FAR to avoid conflict with JPEG definition */ + +#ifdef FAR +#undef FAR +#endif + +/* + Libjpeg's jmorecfg.h defines INT16 and INT32, but only if XMD_H is + not defined. Unfortunately, the MinGW and Borland compilers include + a typedef for INT32, which causes a conflict. MSVC does not include + a conficting typedef given the headers which are included. +*/ +#if defined(__BORLANDC__) || defined(__MINGW32__) +# define XMD_H 1 +#endif + +/* Define "boolean" as unsigned char, not int, per Windows custom. */ +#if defined(__WIN32__) && !defined(__MINGW32__) +# ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ + typedef unsigned char boolean; +# endif +# define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ +#endif + +#include "../LibJPEG/jpeglib.h" +#include "../LibJPEG/jerror.h" + +typedef struct jpeg_error_mgr jpeg_error_mgr; +typedef struct jpeg_common_struct jpeg_common_struct; +typedef struct jpeg_decompress_struct jpeg_decompress_struct; +typedef struct jpeg_source_mgr jpeg_source_mgr; + +typedef enum { + osibsNotSetYet, + osibsJpegInterchangeFormat, + osibsStrile, + osibsEof +} OJPEGStateInBufferSource; + +typedef enum { + ososSoi, + ososQTable0,ososQTable1,ososQTable2,ososQTable3, + ososDcTable0,ososDcTable1,ososDcTable2,ososDcTable3, + ososAcTable0,ososAcTable1,ososAcTable2,ososAcTable3, + ososDri, + ososSof, + ososSos, + ososCompressed, + ososRst, + ososEoi +} OJPEGStateOutState; + +typedef struct { + TIFF* tif; + #ifndef LIBJPEG_ENCAP_EXTERNAL + JMP_BUF exit_jmpbuf; + #endif + TIFFVGetMethod vgetparent; + TIFFVSetMethod vsetparent; + TIFFPrintMethod printdir; + uint64 file_size; + uint32 image_width; + uint32 image_length; + uint32 strile_width; + uint32 strile_length; + uint32 strile_length_total; + uint8 samples_per_pixel; + uint8 plane_sample_offset; + uint8 samples_per_pixel_per_plane; + uint64 jpeg_interchange_format; + uint64 jpeg_interchange_format_length; + uint8 jpeg_proc; + uint8 subsamplingcorrect; + uint8 subsamplingcorrect_done; + uint8 subsampling_tag; + uint8 subsampling_hor; + uint8 subsampling_ver; + uint8 subsampling_force_desubsampling_inside_decompression; + uint8 qtable_offset_count; + uint8 dctable_offset_count; + uint8 actable_offset_count; + uint64 qtable_offset[3]; + uint64 dctable_offset[3]; + uint64 actable_offset[3]; + uint8* qtable[4]; + uint8* dctable[4]; + uint8* actable[4]; + uint16 restart_interval; + uint8 restart_index; + uint8 sof_log; + uint8 sof_marker_id; + uint32 sof_x; + uint32 sof_y; + uint8 sof_c[3]; + uint8 sof_hv[3]; + uint8 sof_tq[3]; + uint8 sos_cs[3]; + uint8 sos_tda[3]; + struct { + uint8 log; + OJPEGStateInBufferSource in_buffer_source; + uint32 in_buffer_next_strile; + uint64 in_buffer_file_pos; + uint64 in_buffer_file_togo; + } sos_end[3]; + uint8 readheader_done; + uint8 writeheader_done; + uint16 write_cursample; + uint32 write_curstrile; + uint8 libjpeg_session_active; + uint8 libjpeg_jpeg_query_style; + jpeg_error_mgr libjpeg_jpeg_error_mgr; + jpeg_decompress_struct libjpeg_jpeg_decompress_struct; + jpeg_source_mgr libjpeg_jpeg_source_mgr; + uint8 subsampling_convert_log; + uint32 subsampling_convert_ylinelen; + uint32 subsampling_convert_ylines; + uint32 subsampling_convert_clinelen; + uint32 subsampling_convert_clines; + uint32 subsampling_convert_ybuflen; + uint32 subsampling_convert_cbuflen; + uint32 subsampling_convert_ycbcrbuflen; + uint8* subsampling_convert_ycbcrbuf; + uint8* subsampling_convert_ybuf; + uint8* subsampling_convert_cbbuf; + uint8* subsampling_convert_crbuf; + uint32 subsampling_convert_ycbcrimagelen; + uint8** subsampling_convert_ycbcrimage; + uint32 subsampling_convert_clinelenout; + uint32 subsampling_convert_state; + uint32 bytes_per_line; /* if the codec outputs subsampled data, a 'line' in bytes_per_line */ + uint32 lines_per_strile; /* and lines_per_strile means subsampling_ver desubsampled rows */ + OJPEGStateInBufferSource in_buffer_source; + uint32 in_buffer_next_strile; + uint32 in_buffer_strile_count; + uint64 in_buffer_file_pos; + uint8 in_buffer_file_pos_log; + uint64 in_buffer_file_togo; + uint16 in_buffer_togo; + uint8* in_buffer_cur; + uint8 in_buffer[OJPEG_BUFFER]; + OJPEGStateOutState out_state; + uint8 out_buffer[OJPEG_BUFFER]; + uint8* skip_buffer; +} OJPEGState; + +static int OJPEGVGetField(TIFF* tif, uint32 tag, va_list ap); +static int OJPEGVSetField(TIFF* tif, uint32 tag, va_list ap); +static void OJPEGPrintDir(TIFF* tif, FILE* fd, long flags); + +static int OJPEGFixupTags(TIFF* tif); +static int OJPEGSetupDecode(TIFF* tif); +static int OJPEGPreDecode(TIFF* tif, uint16 s); +static int OJPEGPreDecodeSkipRaw(TIFF* tif); +static int OJPEGPreDecodeSkipScanlines(TIFF* tif); +static int OJPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s); +static int OJPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc); +static int OJPEGDecodeScanlines(TIFF* tif, uint8* buf, tmsize_t cc); +static void OJPEGPostDecode(TIFF* tif, uint8* buf, tmsize_t cc); +static int OJPEGSetupEncode(TIFF* tif); +static int OJPEGPreEncode(TIFF* tif, uint16 s); +static int OJPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s); +static int OJPEGPostEncode(TIFF* tif); +static void OJPEGCleanup(TIFF* tif); + +static void OJPEGSubsamplingCorrect(TIFF* tif); +static int OJPEGReadHeaderInfo(TIFF* tif); +static int OJPEGReadSecondarySos(TIFF* tif, uint16 s); +static int OJPEGWriteHeaderInfo(TIFF* tif); +static void OJPEGLibjpegSessionAbort(TIFF* tif); + +static int OJPEGReadHeaderInfoSec(TIFF* tif); +static int OJPEGReadHeaderInfoSecStreamDri(TIFF* tif); +static int OJPEGReadHeaderInfoSecStreamDqt(TIFF* tif); +static int OJPEGReadHeaderInfoSecStreamDht(TIFF* tif); +static int OJPEGReadHeaderInfoSecStreamSof(TIFF* tif, uint8 marker_id); +static int OJPEGReadHeaderInfoSecStreamSos(TIFF* tif); +static int OJPEGReadHeaderInfoSecTablesQTable(TIFF* tif); +static int OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif); +static int OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif); + +static int OJPEGReadBufferFill(OJPEGState* sp); +static int OJPEGReadByte(OJPEGState* sp, uint8* byte); +static int OJPEGReadBytePeek(OJPEGState* sp, uint8* byte); +static void OJPEGReadByteAdvance(OJPEGState* sp); +static int OJPEGReadWord(OJPEGState* sp, uint16* word); +static int OJPEGReadBlock(OJPEGState* sp, uint16 len, void* mem); +static void OJPEGReadSkip(OJPEGState* sp, uint16 len); + +static int OJPEGWriteStream(TIFF* tif, void** mem, uint32* len); +static void OJPEGWriteStreamSoi(TIFF* tif, void** mem, uint32* len); +static void OJPEGWriteStreamQTable(TIFF* tif, uint8 table_index, void** mem, uint32* len); +static void OJPEGWriteStreamDcTable(TIFF* tif, uint8 table_index, void** mem, uint32* len); +static void OJPEGWriteStreamAcTable(TIFF* tif, uint8 table_index, void** mem, uint32* len); +static void OJPEGWriteStreamDri(TIFF* tif, void** mem, uint32* len); +static void OJPEGWriteStreamSof(TIFF* tif, void** mem, uint32* len); +static void OJPEGWriteStreamSos(TIFF* tif, void** mem, uint32* len); +static int OJPEGWriteStreamCompressed(TIFF* tif, void** mem, uint32* len); +static void OJPEGWriteStreamRst(TIFF* tif, void** mem, uint32* len); +static void OJPEGWriteStreamEoi(TIFF* tif, void** mem, uint32* len); + +#ifdef LIBJPEG_ENCAP_EXTERNAL +extern int jpeg_create_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo); +extern int jpeg_read_header_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, uint8 require_image); +extern int jpeg_start_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo); +extern int jpeg_read_scanlines_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* scanlines, uint32 max_lines); +extern int jpeg_read_raw_data_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* data, uint32 max_lines); +extern void jpeg_encap_unwind(TIFF* tif); +#else +static int jpeg_create_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* j); +static int jpeg_read_header_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, uint8 require_image); +static int jpeg_start_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo); +static int jpeg_read_scanlines_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* scanlines, uint32 max_lines); +static int jpeg_read_raw_data_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* data, uint32 max_lines); +static void jpeg_encap_unwind(TIFF* tif); +#endif + +static void OJPEGLibjpegJpegErrorMgrOutputMessage(jpeg_common_struct* cinfo); +static void OJPEGLibjpegJpegErrorMgrErrorExit(jpeg_common_struct* cinfo); +static void OJPEGLibjpegJpegSourceMgrInitSource(jpeg_decompress_struct* cinfo); +static boolean OJPEGLibjpegJpegSourceMgrFillInputBuffer(jpeg_decompress_struct* cinfo); +static void OJPEGLibjpegJpegSourceMgrSkipInputData(jpeg_decompress_struct* cinfo, long num_bytes); +static boolean OJPEGLibjpegJpegSourceMgrResyncToRestart(jpeg_decompress_struct* cinfo, int desired); +static void OJPEGLibjpegJpegSourceMgrTermSource(jpeg_decompress_struct* cinfo); + +int +TIFFInitOJPEG(TIFF* tif, int scheme) +{ + static const char module[]="TIFFInitOJPEG"; + OJPEGState* sp; + + assert(scheme==COMPRESSION_OJPEG); + + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFields(tif, ojpegFields, TIFFArrayCount(ojpegFields))) { + TIFFErrorExt(tif->tif_clientdata, module, + "Merging Old JPEG codec-specific tags failed"); + return 0; + } + + /* state block */ + sp=_TIFFmalloc(sizeof(OJPEGState)); + if (sp==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"No space for OJPEG state block"); + return(0); + } + _TIFFmemset(sp,0,sizeof(OJPEGState)); + sp->tif=tif; + sp->jpeg_proc=1; + sp->subsampling_hor=2; + sp->subsampling_ver=2; + TIFFSetField(tif,TIFFTAG_YCBCRSUBSAMPLING,2,2); + /* tif codec methods */ + tif->tif_fixuptags=OJPEGFixupTags; + tif->tif_setupdecode=OJPEGSetupDecode; + tif->tif_predecode=OJPEGPreDecode; + tif->tif_postdecode=OJPEGPostDecode; + tif->tif_decoderow=OJPEGDecode; + tif->tif_decodestrip=OJPEGDecode; + tif->tif_decodetile=OJPEGDecode; + tif->tif_setupencode=OJPEGSetupEncode; + tif->tif_preencode=OJPEGPreEncode; + tif->tif_postencode=OJPEGPostEncode; + tif->tif_encoderow=OJPEGEncode; + tif->tif_encodestrip=OJPEGEncode; + tif->tif_encodetile=OJPEGEncode; + tif->tif_cleanup=OJPEGCleanup; + tif->tif_data=(uint8*)sp; + /* tif tag methods */ + sp->vgetparent=tif->tif_tagmethods.vgetfield; + tif->tif_tagmethods.vgetfield=OJPEGVGetField; + sp->vsetparent=tif->tif_tagmethods.vsetfield; + tif->tif_tagmethods.vsetfield=OJPEGVSetField; + sp->printdir=tif->tif_tagmethods.printdir; + tif->tif_tagmethods.printdir=OJPEGPrintDir; + /* Some OJPEG files don't have strip or tile offsets or bytecounts tags. + Some others do, but have totally meaningless or corrupt values + in these tags. In these cases, the JpegInterchangeFormat stream is + reliable. In any case, this decoder reads the compressed data itself, + from the most reliable locations, and we need to notify encapsulating + LibTiff not to read raw strips or tiles for us. */ + tif->tif_flags|=TIFF_NOREADRAW; + return(1); +} + +static int +OJPEGVGetField(TIFF* tif, uint32 tag, va_list ap) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + switch(tag) + { + case TIFFTAG_JPEGIFOFFSET: + *va_arg(ap,uint64*)=(uint64)sp->jpeg_interchange_format; + break; + case TIFFTAG_JPEGIFBYTECOUNT: + *va_arg(ap,uint64*)=(uint64)sp->jpeg_interchange_format_length; + break; + case TIFFTAG_YCBCRSUBSAMPLING: + if (sp->subsamplingcorrect_done==0) + OJPEGSubsamplingCorrect(tif); + *va_arg(ap,uint16*)=(uint16)sp->subsampling_hor; + *va_arg(ap,uint16*)=(uint16)sp->subsampling_ver; + break; + case TIFFTAG_JPEGQTABLES: + *va_arg(ap,uint32*)=(uint32)sp->qtable_offset_count; + *va_arg(ap,void**)=(void*)sp->qtable_offset; + break; + case TIFFTAG_JPEGDCTABLES: + *va_arg(ap,uint32*)=(uint32)sp->dctable_offset_count; + *va_arg(ap,void**)=(void*)sp->dctable_offset; + break; + case TIFFTAG_JPEGACTABLES: + *va_arg(ap,uint32*)=(uint32)sp->actable_offset_count; + *va_arg(ap,void**)=(void*)sp->actable_offset; + break; + case TIFFTAG_JPEGPROC: + *va_arg(ap,uint16*)=(uint16)sp->jpeg_proc; + break; + case TIFFTAG_JPEGRESTARTINTERVAL: + *va_arg(ap,uint16*)=sp->restart_interval; + break; + default: + return (*sp->vgetparent)(tif,tag,ap); + } + return (1); +} + +static int +OJPEGVSetField(TIFF* tif, uint32 tag, va_list ap) +{ + static const char module[]="OJPEGVSetField"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint32 ma; + uint64* mb; + uint32 n; + switch(tag) + { + case TIFFTAG_JPEGIFOFFSET: + sp->jpeg_interchange_format=(uint64)va_arg(ap,uint64); + break; + case TIFFTAG_JPEGIFBYTECOUNT: + sp->jpeg_interchange_format_length=(uint64)va_arg(ap,uint64); + break; + case TIFFTAG_YCBCRSUBSAMPLING: + sp->subsampling_tag=1; + sp->subsampling_hor=(uint8)va_arg(ap,uint16_vap); + sp->subsampling_ver=(uint8)va_arg(ap,uint16_vap); + tif->tif_dir.td_ycbcrsubsampling[0]=sp->subsampling_hor; + tif->tif_dir.td_ycbcrsubsampling[1]=sp->subsampling_ver; + break; + case TIFFTAG_JPEGQTABLES: + ma=(uint32)va_arg(ap,uint32); + if (ma!=0) + { + if (ma>3) + { + TIFFErrorExt(tif->tif_clientdata,module,"JpegQTables tag has incorrect count"); + return(0); + } + sp->qtable_offset_count=(uint8)ma; + mb=(uint64*)va_arg(ap,uint64*); + for (n=0; nqtable_offset[n]=mb[n]; + } + break; + case TIFFTAG_JPEGDCTABLES: + ma=(uint32)va_arg(ap,uint32); + if (ma!=0) + { + if (ma>3) + { + TIFFErrorExt(tif->tif_clientdata,module,"JpegDcTables tag has incorrect count"); + return(0); + } + sp->dctable_offset_count=(uint8)ma; + mb=(uint64*)va_arg(ap,uint64*); + for (n=0; ndctable_offset[n]=mb[n]; + } + break; + case TIFFTAG_JPEGACTABLES: + ma=(uint32)va_arg(ap,uint32); + if (ma!=0) + { + if (ma>3) + { + TIFFErrorExt(tif->tif_clientdata,module,"JpegAcTables tag has incorrect count"); + return(0); + } + sp->actable_offset_count=(uint8)ma; + mb=(uint64*)va_arg(ap,uint64*); + for (n=0; nactable_offset[n]=mb[n]; + } + break; + case TIFFTAG_JPEGPROC: + sp->jpeg_proc=(uint8)va_arg(ap,uint16_vap); + break; + case TIFFTAG_JPEGRESTARTINTERVAL: + sp->restart_interval=(uint16)va_arg(ap,uint16_vap); + break; + default: + return (*sp->vsetparent)(tif,tag,ap); + } + TIFFSetFieldBit(tif,TIFFFieldWithTag(tif,tag)->field_bit); + tif->tif_flags|=TIFF_DIRTYDIRECT; + return(1); +} + +static void +OJPEGPrintDir(TIFF* tif, FILE* fd, long flags) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint8 m; + (void)flags; + assert(sp!=NULL); + if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGINTERCHANGEFORMAT)) + fprintf(fd," JpegInterchangeFormat: " TIFF_UINT64_FORMAT "\n",(TIFF_UINT64_T)sp->jpeg_interchange_format); + if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH)) + fprintf(fd," JpegInterchangeFormatLength: " TIFF_UINT64_FORMAT "\n",(TIFF_UINT64_T)sp->jpeg_interchange_format_length); + if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGQTABLES)) + { + fprintf(fd," JpegQTables:"); + for (m=0; mqtable_offset_count; m++) + fprintf(fd," " TIFF_UINT64_FORMAT,(TIFF_UINT64_T)sp->qtable_offset[m]); + fprintf(fd,"\n"); + } + if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGDCTABLES)) + { + fprintf(fd," JpegDcTables:"); + for (m=0; mdctable_offset_count; m++) + fprintf(fd," " TIFF_UINT64_FORMAT,(TIFF_UINT64_T)sp->dctable_offset[m]); + fprintf(fd,"\n"); + } + if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGACTABLES)) + { + fprintf(fd," JpegAcTables:"); + for (m=0; mactable_offset_count; m++) + fprintf(fd," " TIFF_UINT64_FORMAT,(TIFF_UINT64_T)sp->actable_offset[m]); + fprintf(fd,"\n"); + } + if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGPROC)) + fprintf(fd," JpegProc: %u\n",(unsigned int)sp->jpeg_proc); + if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGRESTARTINTERVAL)) + fprintf(fd," JpegRestartInterval: %u\n",(unsigned int)sp->restart_interval); + if (sp->printdir) + (*sp->printdir)(tif, fd, flags); +} + +static int +OJPEGFixupTags(TIFF* tif) +{ + (void) tif; + return(1); +} + +static int +OJPEGSetupDecode(TIFF* tif) +{ + static const char module[]="OJPEGSetupDecode"; + TIFFWarningExt(tif->tif_clientdata,module,"Depreciated and troublesome old-style JPEG compression mode, please convert to new-style JPEG compression and notify vendor of writing software"); + return(1); +} + +static int +OJPEGPreDecode(TIFF* tif, uint16 s) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint32 m; + if (sp->subsamplingcorrect_done==0) + OJPEGSubsamplingCorrect(tif); + if (sp->readheader_done==0) + { + if (OJPEGReadHeaderInfo(tif)==0) + return(0); + } + if (sp->sos_end[s].log==0) + { + if (OJPEGReadSecondarySos(tif,s)==0) + return(0); + } + if isTiled(tif) + m=tif->tif_curtile; + else + m=tif->tif_curstrip; + if ((sp->writeheader_done!=0) && ((sp->write_cursample!=s) || (sp->write_curstrile>m))) + { + if (sp->libjpeg_session_active!=0) + OJPEGLibjpegSessionAbort(tif); + sp->writeheader_done=0; + } + if (sp->writeheader_done==0) + { + sp->plane_sample_offset=(uint8)s; + sp->write_cursample=s; + sp->write_curstrile=s*tif->tif_dir.td_stripsperimage; + if ((sp->in_buffer_file_pos_log==0) || + (sp->in_buffer_file_pos-sp->in_buffer_togo!=sp->sos_end[s].in_buffer_file_pos)) + { + sp->in_buffer_source=sp->sos_end[s].in_buffer_source; + sp->in_buffer_next_strile=sp->sos_end[s].in_buffer_next_strile; + sp->in_buffer_file_pos=sp->sos_end[s].in_buffer_file_pos; + sp->in_buffer_file_pos_log=0; + sp->in_buffer_file_togo=sp->sos_end[s].in_buffer_file_togo; + sp->in_buffer_togo=0; + sp->in_buffer_cur=0; + } + if (OJPEGWriteHeaderInfo(tif)==0) + return(0); + } + while (sp->write_curstrilelibjpeg_jpeg_query_style==0) + { + if (OJPEGPreDecodeSkipRaw(tif)==0) + return(0); + } + else + { + if (OJPEGPreDecodeSkipScanlines(tif)==0) + return(0); + } + sp->write_curstrile++; + } + return(1); +} + +static int +OJPEGPreDecodeSkipRaw(TIFF* tif) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint32 m; + m=sp->lines_per_strile; + if (sp->subsampling_convert_state!=0) + { + if (sp->subsampling_convert_clines-sp->subsampling_convert_state>=m) + { + sp->subsampling_convert_state+=m; + if (sp->subsampling_convert_state==sp->subsampling_convert_clines) + sp->subsampling_convert_state=0; + return(1); + } + m-=sp->subsampling_convert_clines-sp->subsampling_convert_state; + sp->subsampling_convert_state=0; + } + while (m>=sp->subsampling_convert_clines) + { + if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0) + return(0); + m-=sp->subsampling_convert_clines; + } + if (m>0) + { + if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0) + return(0); + sp->subsampling_convert_state=m; + } + return(1); +} + +static int +OJPEGPreDecodeSkipScanlines(TIFF* tif) +{ + static const char module[]="OJPEGPreDecodeSkipScanlines"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint32 m; + if (sp->skip_buffer==NULL) + { + sp->skip_buffer=_TIFFmalloc(sp->bytes_per_line); + if (sp->skip_buffer==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + } + for (m=0; mlines_per_strile; m++) + { + if (jpeg_read_scanlines_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),&sp->skip_buffer,1)==0) + return(0); + } + return(1); +} + +static int +OJPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + (void)s; + if (sp->libjpeg_jpeg_query_style==0) + { + if (OJPEGDecodeRaw(tif,buf,cc)==0) + return(0); + } + else + { + if (OJPEGDecodeScanlines(tif,buf,cc)==0) + return(0); + } + return(1); +} + +static int +OJPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc) +{ + static const char module[]="OJPEGDecodeRaw"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint8* m; + tmsize_t n; + uint8* oy; + uint8* ocb; + uint8* ocr; + uint8* p; + uint32 q; + uint8* r; + uint8 sx,sy; + if (cc%sp->bytes_per_line!=0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Fractional scanline not read"); + return(0); + } + assert(cc>0); + m=buf; + n=cc; + do + { + if (sp->subsampling_convert_state==0) + { + if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0) + return(0); + } + oy=sp->subsampling_convert_ybuf+sp->subsampling_convert_state*sp->subsampling_ver*sp->subsampling_convert_ylinelen; + ocb=sp->subsampling_convert_cbbuf+sp->subsampling_convert_state*sp->subsampling_convert_clinelen; + ocr=sp->subsampling_convert_crbuf+sp->subsampling_convert_state*sp->subsampling_convert_clinelen; + p=m; + for (q=0; qsubsampling_convert_clinelenout; q++) + { + r=oy; + for (sy=0; sysubsampling_ver; sy++) + { + for (sx=0; sxsubsampling_hor; sx++) + *p++=*r++; + r+=sp->subsampling_convert_ylinelen-sp->subsampling_hor; + } + oy+=sp->subsampling_hor; + *p++=*ocb++; + *p++=*ocr++; + } + sp->subsampling_convert_state++; + if (sp->subsampling_convert_state==sp->subsampling_convert_clines) + sp->subsampling_convert_state=0; + m+=sp->bytes_per_line; + n-=sp->bytes_per_line; + } while(n>0); + return(1); +} + +static int +OJPEGDecodeScanlines(TIFF* tif, uint8* buf, tmsize_t cc) +{ + static const char module[]="OJPEGDecodeScanlines"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint8* m; + tmsize_t n; + if (cc%sp->bytes_per_line!=0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Fractional scanline not read"); + return(0); + } + assert(cc>0); + m=buf; + n=cc; + do + { + if (jpeg_read_scanlines_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),&m,1)==0) + return(0); + m+=sp->bytes_per_line; + n-=sp->bytes_per_line; + } while(n>0); + return(1); +} + +static void +OJPEGPostDecode(TIFF* tif, uint8* buf, tmsize_t cc) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + (void)buf; + (void)cc; + sp->write_curstrile++; + if (sp->write_curstrile%tif->tif_dir.td_stripsperimage==0) + { + assert(sp->libjpeg_session_active!=0); + OJPEGLibjpegSessionAbort(tif); + sp->writeheader_done=0; + } +} + +static int +OJPEGSetupEncode(TIFF* tif) +{ + static const char module[]="OJPEGSetupEncode"; + TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead"); + return(0); +} + +static int +OJPEGPreEncode(TIFF* tif, uint16 s) +{ + static const char module[]="OJPEGPreEncode"; + (void)s; + TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead"); + return(0); +} + +static int +OJPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) +{ + static const char module[]="OJPEGEncode"; + (void)buf; + (void)cc; + (void)s; + TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead"); + return(0); +} + +static int +OJPEGPostEncode(TIFF* tif) +{ + static const char module[]="OJPEGPostEncode"; + TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead"); + return(0); +} + +static void +OJPEGCleanup(TIFF* tif) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + if (sp!=0) + { + tif->tif_tagmethods.vgetfield=sp->vgetparent; + tif->tif_tagmethods.vsetfield=sp->vsetparent; + tif->tif_tagmethods.printdir=sp->printdir; + if (sp->qtable[0]!=0) + _TIFFfree(sp->qtable[0]); + if (sp->qtable[1]!=0) + _TIFFfree(sp->qtable[1]); + if (sp->qtable[2]!=0) + _TIFFfree(sp->qtable[2]); + if (sp->qtable[3]!=0) + _TIFFfree(sp->qtable[3]); + if (sp->dctable[0]!=0) + _TIFFfree(sp->dctable[0]); + if (sp->dctable[1]!=0) + _TIFFfree(sp->dctable[1]); + if (sp->dctable[2]!=0) + _TIFFfree(sp->dctable[2]); + if (sp->dctable[3]!=0) + _TIFFfree(sp->dctable[3]); + if (sp->actable[0]!=0) + _TIFFfree(sp->actable[0]); + if (sp->actable[1]!=0) + _TIFFfree(sp->actable[1]); + if (sp->actable[2]!=0) + _TIFFfree(sp->actable[2]); + if (sp->actable[3]!=0) + _TIFFfree(sp->actable[3]); + if (sp->libjpeg_session_active!=0) + OJPEGLibjpegSessionAbort(tif); + if (sp->subsampling_convert_ycbcrbuf!=0) + _TIFFfree(sp->subsampling_convert_ycbcrbuf); + if (sp->subsampling_convert_ycbcrimage!=0) + _TIFFfree(sp->subsampling_convert_ycbcrimage); + if (sp->skip_buffer!=0) + _TIFFfree(sp->skip_buffer); + _TIFFfree(sp); + tif->tif_data=NULL; + _TIFFSetDefaultCompressionState(tif); + } +} + +static void +OJPEGSubsamplingCorrect(TIFF* tif) +{ + static const char module[]="OJPEGSubsamplingCorrect"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint8 mh; + uint8 mv; + _TIFFFillStriles( tif ); + + assert(sp->subsamplingcorrect_done==0); + if ((tif->tif_dir.td_samplesperpixel!=3) || ((tif->tif_dir.td_photometric!=PHOTOMETRIC_YCBCR) && + (tif->tif_dir.td_photometric!=PHOTOMETRIC_ITULAB))) + { + if (sp->subsampling_tag!=0) + TIFFWarningExt(tif->tif_clientdata,module,"Subsampling tag not appropriate for this Photometric and/or SamplesPerPixel"); + sp->subsampling_hor=1; + sp->subsampling_ver=1; + sp->subsampling_force_desubsampling_inside_decompression=0; + } + else + { + sp->subsamplingcorrect_done=1; + mh=sp->subsampling_hor; + mv=sp->subsampling_ver; + sp->subsamplingcorrect=1; + OJPEGReadHeaderInfoSec(tif); + if (sp->subsampling_force_desubsampling_inside_decompression!=0) + { + sp->subsampling_hor=1; + sp->subsampling_ver=1; + } + sp->subsamplingcorrect=0; + if (((sp->subsampling_hor!=mh) || (sp->subsampling_ver!=mv)) && (sp->subsampling_force_desubsampling_inside_decompression==0)) + { + if (sp->subsampling_tag==0) + TIFFWarningExt(tif->tif_clientdata,module,"Subsampling tag is not set, yet subsampling inside JPEG data [%d,%d] does not match default values [2,2]; assuming subsampling inside JPEG data is correct",sp->subsampling_hor,sp->subsampling_ver); + else + TIFFWarningExt(tif->tif_clientdata,module,"Subsampling inside JPEG data [%d,%d] does not match subsampling tag values [%d,%d]; assuming subsampling inside JPEG data is correct",sp->subsampling_hor,sp->subsampling_ver,mh,mv); + } + if (sp->subsampling_force_desubsampling_inside_decompression!=0) + { + if (sp->subsampling_tag==0) + TIFFWarningExt(tif->tif_clientdata,module,"Subsampling tag is not set, yet subsampling inside JPEG data does not match default values [2,2] (nor any other values allowed in TIFF); assuming subsampling inside JPEG data is correct and desubsampling inside JPEG decompression"); + else + TIFFWarningExt(tif->tif_clientdata,module,"Subsampling inside JPEG data does not match subsampling tag values [%d,%d] (nor any other values allowed in TIFF); assuming subsampling inside JPEG data is correct and desubsampling inside JPEG decompression",mh,mv); + } + if (sp->subsampling_force_desubsampling_inside_decompression==0) + { + if (sp->subsampling_horsubsampling_ver) + TIFFWarningExt(tif->tif_clientdata,module,"Subsampling values [%d,%d] are not allowed in TIFF",sp->subsampling_hor,sp->subsampling_ver); + } + } + sp->subsamplingcorrect_done=1; +} + +static int +OJPEGReadHeaderInfo(TIFF* tif) +{ + static const char module[]="OJPEGReadHeaderInfo"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + assert(sp->readheader_done==0); + sp->image_width=tif->tif_dir.td_imagewidth; + sp->image_length=tif->tif_dir.td_imagelength; + if isTiled(tif) + { + sp->strile_width=tif->tif_dir.td_tilewidth; + sp->strile_length=tif->tif_dir.td_tilelength; + sp->strile_length_total=((sp->image_length+sp->strile_length-1)/sp->strile_length)*sp->strile_length; + } + else + { + sp->strile_width=sp->image_width; + sp->strile_length=tif->tif_dir.td_rowsperstrip; + sp->strile_length_total=sp->image_length; + } + if (tif->tif_dir.td_samplesperpixel==1) + { + sp->samples_per_pixel=1; + sp->plane_sample_offset=0; + sp->samples_per_pixel_per_plane=sp->samples_per_pixel; + sp->subsampling_hor=1; + sp->subsampling_ver=1; + } + else + { + if (tif->tif_dir.td_samplesperpixel!=3) + { + TIFFErrorExt(tif->tif_clientdata,module,"SamplesPerPixel %d not supported for this compression scheme",sp->samples_per_pixel); + return(0); + } + sp->samples_per_pixel=3; + sp->plane_sample_offset=0; + if (tif->tif_dir.td_planarconfig==PLANARCONFIG_CONTIG) + sp->samples_per_pixel_per_plane=3; + else + sp->samples_per_pixel_per_plane=1; + } + if (sp->strile_lengthimage_length) + { + if (sp->strile_length%(sp->subsampling_ver*8)!=0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Incompatible vertical subsampling and image strip/tile length"); + return(0); + } + sp->restart_interval=((sp->strile_width+sp->subsampling_hor*8-1)/(sp->subsampling_hor*8))*(sp->strile_length/(sp->subsampling_ver*8)); + } + if (OJPEGReadHeaderInfoSec(tif)==0) + return(0); + sp->sos_end[0].log=1; + sp->sos_end[0].in_buffer_source=sp->in_buffer_source; + sp->sos_end[0].in_buffer_next_strile=sp->in_buffer_next_strile; + sp->sos_end[0].in_buffer_file_pos=sp->in_buffer_file_pos-sp->in_buffer_togo; + sp->sos_end[0].in_buffer_file_togo=sp->in_buffer_file_togo+sp->in_buffer_togo; + sp->readheader_done=1; + return(1); +} + +static int +OJPEGReadSecondarySos(TIFF* tif, uint16 s) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint8 m; + assert(s>0); + assert(s<3); + assert(sp->sos_end[0].log!=0); + assert(sp->sos_end[s].log==0); + sp->plane_sample_offset=s-1; + while(sp->sos_end[sp->plane_sample_offset].log==0) + sp->plane_sample_offset--; + sp->in_buffer_source=sp->sos_end[sp->plane_sample_offset].in_buffer_source; + sp->in_buffer_next_strile=sp->sos_end[sp->plane_sample_offset].in_buffer_next_strile; + sp->in_buffer_file_pos=sp->sos_end[sp->plane_sample_offset].in_buffer_file_pos; + sp->in_buffer_file_pos_log=0; + sp->in_buffer_file_togo=sp->sos_end[sp->plane_sample_offset].in_buffer_file_togo; + sp->in_buffer_togo=0; + sp->in_buffer_cur=0; + while(sp->plane_sample_offsetplane_sample_offset++; + if (OJPEGReadHeaderInfoSecStreamSos(tif)==0) + return(0); + sp->sos_end[sp->plane_sample_offset].log=1; + sp->sos_end[sp->plane_sample_offset].in_buffer_source=sp->in_buffer_source; + sp->sos_end[sp->plane_sample_offset].in_buffer_next_strile=sp->in_buffer_next_strile; + sp->sos_end[sp->plane_sample_offset].in_buffer_file_pos=sp->in_buffer_file_pos-sp->in_buffer_togo; + sp->sos_end[sp->plane_sample_offset].in_buffer_file_togo=sp->in_buffer_file_togo+sp->in_buffer_togo; + } + return(1); +} + +static int +OJPEGWriteHeaderInfo(TIFF* tif) +{ + static const char module[]="OJPEGWriteHeaderInfo"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint8** m; + uint32 n; + /* if a previous attempt failed, don't try again */ + if (sp->libjpeg_session_active != 0) + return 0; + sp->out_state=ososSoi; + sp->restart_index=0; + jpeg_std_error(&(sp->libjpeg_jpeg_error_mgr)); + sp->libjpeg_jpeg_error_mgr.output_message=OJPEGLibjpegJpegErrorMgrOutputMessage; + sp->libjpeg_jpeg_error_mgr.error_exit=OJPEGLibjpegJpegErrorMgrErrorExit; + sp->libjpeg_jpeg_decompress_struct.err=&(sp->libjpeg_jpeg_error_mgr); + sp->libjpeg_jpeg_decompress_struct.client_data=(void*)tif; + if (jpeg_create_decompress_encap(sp,&(sp->libjpeg_jpeg_decompress_struct))==0) + return(0); + sp->libjpeg_session_active=1; + sp->libjpeg_jpeg_source_mgr.bytes_in_buffer=0; + sp->libjpeg_jpeg_source_mgr.init_source=OJPEGLibjpegJpegSourceMgrInitSource; + sp->libjpeg_jpeg_source_mgr.fill_input_buffer=OJPEGLibjpegJpegSourceMgrFillInputBuffer; + sp->libjpeg_jpeg_source_mgr.skip_input_data=OJPEGLibjpegJpegSourceMgrSkipInputData; + sp->libjpeg_jpeg_source_mgr.resync_to_restart=OJPEGLibjpegJpegSourceMgrResyncToRestart; + sp->libjpeg_jpeg_source_mgr.term_source=OJPEGLibjpegJpegSourceMgrTermSource; + sp->libjpeg_jpeg_decompress_struct.src=&(sp->libjpeg_jpeg_source_mgr); + if (jpeg_read_header_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),1)==0) + return(0); + if ((sp->subsampling_force_desubsampling_inside_decompression==0) && (sp->samples_per_pixel_per_plane>1)) + { + sp->libjpeg_jpeg_decompress_struct.raw_data_out=1; +#if JPEG_LIB_VERSION >= 70 + sp->libjpeg_jpeg_decompress_struct.do_fancy_upsampling=FALSE; +#endif + sp->libjpeg_jpeg_query_style=0; + if (sp->subsampling_convert_log==0) + { + assert(sp->subsampling_convert_ycbcrbuf==0); + assert(sp->subsampling_convert_ycbcrimage==0); + sp->subsampling_convert_ylinelen=((sp->strile_width+sp->subsampling_hor*8-1)/(sp->subsampling_hor*8)*sp->subsampling_hor*8); + sp->subsampling_convert_ylines=sp->subsampling_ver*8; + sp->subsampling_convert_clinelen=sp->subsampling_convert_ylinelen/sp->subsampling_hor; + sp->subsampling_convert_clines=8; + sp->subsampling_convert_ybuflen=sp->subsampling_convert_ylinelen*sp->subsampling_convert_ylines; + sp->subsampling_convert_cbuflen=sp->subsampling_convert_clinelen*sp->subsampling_convert_clines; + sp->subsampling_convert_ycbcrbuflen=sp->subsampling_convert_ybuflen+2*sp->subsampling_convert_cbuflen; + sp->subsampling_convert_ycbcrbuf=_TIFFmalloc(sp->subsampling_convert_ycbcrbuflen); + if (sp->subsampling_convert_ycbcrbuf==0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + sp->subsampling_convert_ybuf=sp->subsampling_convert_ycbcrbuf; + sp->subsampling_convert_cbbuf=sp->subsampling_convert_ybuf+sp->subsampling_convert_ybuflen; + sp->subsampling_convert_crbuf=sp->subsampling_convert_cbbuf+sp->subsampling_convert_cbuflen; + sp->subsampling_convert_ycbcrimagelen=3+sp->subsampling_convert_ylines+2*sp->subsampling_convert_clines; + sp->subsampling_convert_ycbcrimage=_TIFFmalloc(sp->subsampling_convert_ycbcrimagelen*sizeof(uint8*)); + if (sp->subsampling_convert_ycbcrimage==0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + m=sp->subsampling_convert_ycbcrimage; + *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3); + *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3+sp->subsampling_convert_ylines); + *m++=(uint8*)(sp->subsampling_convert_ycbcrimage+3+sp->subsampling_convert_ylines+sp->subsampling_convert_clines); + for (n=0; nsubsampling_convert_ylines; n++) + *m++=sp->subsampling_convert_ybuf+n*sp->subsampling_convert_ylinelen; + for (n=0; nsubsampling_convert_clines; n++) + *m++=sp->subsampling_convert_cbbuf+n*sp->subsampling_convert_clinelen; + for (n=0; nsubsampling_convert_clines; n++) + *m++=sp->subsampling_convert_crbuf+n*sp->subsampling_convert_clinelen; + sp->subsampling_convert_clinelenout=((sp->strile_width+sp->subsampling_hor-1)/sp->subsampling_hor); + sp->subsampling_convert_state=0; + sp->bytes_per_line=sp->subsampling_convert_clinelenout*(sp->subsampling_ver*sp->subsampling_hor+2); + sp->lines_per_strile=((sp->strile_length+sp->subsampling_ver-1)/sp->subsampling_ver); + sp->subsampling_convert_log=1; + } + } + else + { + sp->libjpeg_jpeg_decompress_struct.jpeg_color_space=JCS_UNKNOWN; + sp->libjpeg_jpeg_decompress_struct.out_color_space=JCS_UNKNOWN; + sp->libjpeg_jpeg_query_style=1; + sp->bytes_per_line=sp->samples_per_pixel_per_plane*sp->strile_width; + sp->lines_per_strile=sp->strile_length; + } + if (jpeg_start_decompress_encap(sp,&(sp->libjpeg_jpeg_decompress_struct))==0) + return(0); + sp->writeheader_done=1; + return(1); +} + +static void +OJPEGLibjpegSessionAbort(TIFF* tif) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + assert(sp->libjpeg_session_active!=0); + jpeg_destroy((jpeg_common_struct*)(&(sp->libjpeg_jpeg_decompress_struct))); + sp->libjpeg_session_active=0; +} + +static int +OJPEGReadHeaderInfoSec(TIFF* tif) +{ + static const char module[]="OJPEGReadHeaderInfoSec"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint8 m; + uint16 n; + uint8 o; + if (sp->file_size==0) + sp->file_size=TIFFGetFileSize(tif); + if (sp->jpeg_interchange_format!=0) + { + if (sp->jpeg_interchange_format>=sp->file_size) + { + sp->jpeg_interchange_format=0; + sp->jpeg_interchange_format_length=0; + } + else + { + if ((sp->jpeg_interchange_format_length==0) || (sp->jpeg_interchange_format+sp->jpeg_interchange_format_length>sp->file_size)) + sp->jpeg_interchange_format_length=sp->file_size-sp->jpeg_interchange_format; + } + } + sp->in_buffer_source=osibsNotSetYet; + sp->in_buffer_next_strile=0; + sp->in_buffer_strile_count=tif->tif_dir.td_nstrips; + sp->in_buffer_file_togo=0; + sp->in_buffer_togo=0; + do + { + if (OJPEGReadBytePeek(sp,&m)==0) + return(0); + if (m!=255) + break; + OJPEGReadByteAdvance(sp); + do + { + if (OJPEGReadByte(sp,&m)==0) + return(0); + } while(m==255); + switch(m) + { + case JPEG_MARKER_SOI: + /* this type of marker has no data, and should be skipped */ + break; + case JPEG_MARKER_COM: + case JPEG_MARKER_APP0: + case JPEG_MARKER_APP0+1: + case JPEG_MARKER_APP0+2: + case JPEG_MARKER_APP0+3: + case JPEG_MARKER_APP0+4: + case JPEG_MARKER_APP0+5: + case JPEG_MARKER_APP0+6: + case JPEG_MARKER_APP0+7: + case JPEG_MARKER_APP0+8: + case JPEG_MARKER_APP0+9: + case JPEG_MARKER_APP0+10: + case JPEG_MARKER_APP0+11: + case JPEG_MARKER_APP0+12: + case JPEG_MARKER_APP0+13: + case JPEG_MARKER_APP0+14: + case JPEG_MARKER_APP0+15: + /* this type of marker has data, but it has no use to us (and no place here) and should be skipped */ + if (OJPEGReadWord(sp,&n)==0) + return(0); + if (n<2) + { + if (sp->subsamplingcorrect==0) + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JPEG data"); + return(0); + } + if (n>2) + OJPEGReadSkip(sp,n-2); + break; + case JPEG_MARKER_DRI: + if (OJPEGReadHeaderInfoSecStreamDri(tif)==0) + return(0); + break; + case JPEG_MARKER_DQT: + if (OJPEGReadHeaderInfoSecStreamDqt(tif)==0) + return(0); + break; + case JPEG_MARKER_DHT: + if (OJPEGReadHeaderInfoSecStreamDht(tif)==0) + return(0); + break; + case JPEG_MARKER_SOF0: + case JPEG_MARKER_SOF1: + case JPEG_MARKER_SOF3: + if (OJPEGReadHeaderInfoSecStreamSof(tif,m)==0) + return(0); + if (sp->subsamplingcorrect!=0) + return(1); + break; + case JPEG_MARKER_SOS: + if (sp->subsamplingcorrect!=0) + return(1); + assert(sp->plane_sample_offset==0); + if (OJPEGReadHeaderInfoSecStreamSos(tif)==0) + return(0); + break; + default: + TIFFErrorExt(tif->tif_clientdata,module,"Unknown marker type %d in JPEG data",m); + return(0); + } + } while(m!=JPEG_MARKER_SOS); + if (sp->subsamplingcorrect) + return(1); + if (sp->sof_log==0) + { + if (OJPEGReadHeaderInfoSecTablesQTable(tif)==0) + return(0); + sp->sof_marker_id=JPEG_MARKER_SOF0; + for (o=0; osamples_per_pixel; o++) + sp->sof_c[o]=o; + sp->sof_hv[0]=((sp->subsampling_hor<<4)|sp->subsampling_ver); + for (o=1; osamples_per_pixel; o++) + sp->sof_hv[o]=17; + sp->sof_x=sp->strile_width; + sp->sof_y=sp->strile_length_total; + sp->sof_log=1; + if (OJPEGReadHeaderInfoSecTablesDcTable(tif)==0) + return(0); + if (OJPEGReadHeaderInfoSecTablesAcTable(tif)==0) + return(0); + for (o=1; osamples_per_pixel; o++) + sp->sos_cs[o]=o; + } + return(1); +} + +static int +OJPEGReadHeaderInfoSecStreamDri(TIFF* tif) +{ + /* this could easilly cause trouble in some cases... but no such cases have occured sofar */ + static const char module[]="OJPEGReadHeaderInfoSecStreamDri"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint16 m; + if (OJPEGReadWord(sp,&m)==0) + return(0); + if (m!=4) + { + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DRI marker in JPEG data"); + return(0); + } + if (OJPEGReadWord(sp,&m)==0) + return(0); + sp->restart_interval=m; + return(1); +} + +static int +OJPEGReadHeaderInfoSecStreamDqt(TIFF* tif) +{ + /* this is a table marker, and it is to be saved as a whole for exact pushing on the jpeg stream later on */ + static const char module[]="OJPEGReadHeaderInfoSecStreamDqt"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint16 m; + uint32 na; + uint8* nb; + uint8 o; + if (OJPEGReadWord(sp,&m)==0) + return(0); + if (m<=2) + { + if (sp->subsamplingcorrect==0) + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DQT marker in JPEG data"); + return(0); + } + if (sp->subsamplingcorrect!=0) + OJPEGReadSkip(sp,m-2); + else + { + m-=2; + do + { + if (m<65) + { + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DQT marker in JPEG data"); + return(0); + } + na=sizeof(uint32)+69; + nb=_TIFFmalloc(na); + if (nb==0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + *(uint32*)nb=na; + nb[sizeof(uint32)]=255; + nb[sizeof(uint32)+1]=JPEG_MARKER_DQT; + nb[sizeof(uint32)+2]=0; + nb[sizeof(uint32)+3]=67; + if (OJPEGReadBlock(sp,65,&nb[sizeof(uint32)+4])==0) { + _TIFFfree(nb); + return(0); + } + o=nb[sizeof(uint32)+4]&15; + if (3tif_clientdata,module,"Corrupt DQT marker in JPEG data"); + _TIFFfree(nb); + return(0); + } + if (sp->qtable[o]!=0) + _TIFFfree(sp->qtable[o]); + sp->qtable[o]=nb; + m-=65; + } while(m>0); + } + return(1); +} + +static int +OJPEGReadHeaderInfoSecStreamDht(TIFF* tif) +{ + /* this is a table marker, and it is to be saved as a whole for exact pushing on the jpeg stream later on */ + /* TODO: the following assumes there is only one table in this marker... but i'm not quite sure that assumption is guaranteed correct */ + static const char module[]="OJPEGReadHeaderInfoSecStreamDht"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint16 m; + uint32 na; + uint8* nb; + uint8 o; + if (OJPEGReadWord(sp,&m)==0) + return(0); + if (m<=2) + { + if (sp->subsamplingcorrect==0) + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data"); + return(0); + } + if (sp->subsamplingcorrect!=0) + { + OJPEGReadSkip(sp,m-2); + } + else + { + na=sizeof(uint32)+2+m; + nb=_TIFFmalloc(na); + if (nb==0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + *(uint32*)nb=na; + nb[sizeof(uint32)]=255; + nb[sizeof(uint32)+1]=JPEG_MARKER_DHT; + nb[sizeof(uint32)+2]=(m>>8); + nb[sizeof(uint32)+3]=(m&255); + if (OJPEGReadBlock(sp,m-2,&nb[sizeof(uint32)+4])==0) + return(0); + o=nb[sizeof(uint32)+4]; + if ((o&240)==0) + { + if (3tif_clientdata,module,"Corrupt DHT marker in JPEG data"); + return(0); + } + if (sp->dctable[o]!=0) + _TIFFfree(sp->dctable[o]); + sp->dctable[o]=nb; + } + else + { + if ((o&240)!=16) + { + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data"); + return(0); + } + o&=15; + if (3tif_clientdata,module,"Corrupt DHT marker in JPEG data"); + return(0); + } + if (sp->actable[o]!=0) + _TIFFfree(sp->actable[o]); + sp->actable[o]=nb; + } + } + return(1); +} + +static int +OJPEGReadHeaderInfoSecStreamSof(TIFF* tif, uint8 marker_id) +{ + /* this marker needs to be checked, and part of its data needs to be saved for regeneration later on */ + static const char module[]="OJPEGReadHeaderInfoSecStreamSof"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint16 m; + uint16 n; + uint8 o; + uint16 p; + uint16 q; + if (sp->sof_log!=0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JPEG data"); + return(0); + } + if (sp->subsamplingcorrect==0) + sp->sof_marker_id=marker_id; + /* Lf: data length */ + if (OJPEGReadWord(sp,&m)==0) + return(0); + if (m<11) + { + if (sp->subsamplingcorrect==0) + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOF marker in JPEG data"); + return(0); + } + m-=8; + if (m%3!=0) + { + if (sp->subsamplingcorrect==0) + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOF marker in JPEG data"); + return(0); + } + n=m/3; + if (sp->subsamplingcorrect==0) + { + if (n!=sp->samples_per_pixel) + { + TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected number of samples"); + return(0); + } + } + /* P: Sample precision */ + if (OJPEGReadByte(sp,&o)==0) + return(0); + if (o!=8) + { + if (sp->subsamplingcorrect==0) + TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected number of bits per sample"); + return(0); + } + /* Y: Number of lines, X: Number of samples per line */ + if (sp->subsamplingcorrect) + OJPEGReadSkip(sp,4); + else + { + /* Y: Number of lines */ + if (OJPEGReadWord(sp,&p)==0) + return(0); + if (((uint32)pimage_length) && ((uint32)pstrile_length_total)) + { + TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected height"); + return(0); + } + sp->sof_y=p; + /* X: Number of samples per line */ + if (OJPEGReadWord(sp,&p)==0) + return(0); + if (((uint32)pimage_width) && ((uint32)pstrile_width)) + { + TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected width"); + return(0); + } + if ((uint32)p>sp->strile_width) + { + TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data image width exceeds expected image width"); + return(0); + } + sp->sof_x=p; + } + /* Nf: Number of image components in frame */ + if (OJPEGReadByte(sp,&o)==0) + return(0); + if (o!=n) + { + if (sp->subsamplingcorrect==0) + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOF marker in JPEG data"); + return(0); + } + /* per component stuff */ + /* TODO: double-check that flow implies that n cannot be as big as to make us overflow sof_c, sof_hv and sof_tq arrays */ + for (q=0; qsubsamplingcorrect==0) + sp->sof_c[q]=o; + /* H: Horizontal sampling factor, and V: Vertical sampling factor */ + if (OJPEGReadByte(sp,&o)==0) + return(0); + if (sp->subsamplingcorrect!=0) + { + if (q==0) + { + sp->subsampling_hor=(o>>4); + sp->subsampling_ver=(o&15); + if (((sp->subsampling_hor!=1) && (sp->subsampling_hor!=2) && (sp->subsampling_hor!=4)) || + ((sp->subsampling_ver!=1) && (sp->subsampling_ver!=2) && (sp->subsampling_ver!=4))) + sp->subsampling_force_desubsampling_inside_decompression=1; + } + else + { + if (o!=17) + sp->subsampling_force_desubsampling_inside_decompression=1; + } + } + else + { + sp->sof_hv[q]=o; + if (sp->subsampling_force_desubsampling_inside_decompression==0) + { + if (q==0) + { + if (o!=((sp->subsampling_hor<<4)|sp->subsampling_ver)) + { + TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected subsampling values"); + return(0); + } + } + else + { + if (o!=17) + { + TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected subsampling values"); + return(0); + } + } + } + } + /* Tq: Quantization table destination selector */ + if (OJPEGReadByte(sp,&o)==0) + return(0); + if (sp->subsamplingcorrect==0) + sp->sof_tq[q]=o; + } + if (sp->subsamplingcorrect==0) + sp->sof_log=1; + return(1); +} + +static int +OJPEGReadHeaderInfoSecStreamSos(TIFF* tif) +{ + /* this marker needs to be checked, and part of its data needs to be saved for regeneration later on */ + static const char module[]="OJPEGReadHeaderInfoSecStreamSos"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint16 m; + uint8 n; + uint8 o; + assert(sp->subsamplingcorrect==0); + if (sp->sof_log==0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOS marker in JPEG data"); + return(0); + } + /* Ls */ + if (OJPEGReadWord(sp,&m)==0) + return(0); + if (m!=6+sp->samples_per_pixel_per_plane*2) + { + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOS marker in JPEG data"); + return(0); + } + /* Ns */ + if (OJPEGReadByte(sp,&n)==0) + return(0); + if (n!=sp->samples_per_pixel_per_plane) + { + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt SOS marker in JPEG data"); + return(0); + } + /* Cs, Td, and Ta */ + for (o=0; osamples_per_pixel_per_plane; o++) + { + /* Cs */ + if (OJPEGReadByte(sp,&n)==0) + return(0); + sp->sos_cs[sp->plane_sample_offset+o]=n; + /* Td and Ta */ + if (OJPEGReadByte(sp,&n)==0) + return(0); + sp->sos_tda[sp->plane_sample_offset+o]=n; + } + /* skip Ss, Se, Ah, en Al -> no check, as per Tom Lane recommendation, as per LibJpeg source */ + OJPEGReadSkip(sp,3); + return(1); +} + +static int +OJPEGReadHeaderInfoSecTablesQTable(TIFF* tif) +{ + static const char module[]="OJPEGReadHeaderInfoSecTablesQTable"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint8 m; + uint8 n; + uint32 oa; + uint8* ob; + uint32 p; + if (sp->qtable_offset[0]==0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Missing JPEG tables"); + return(0); + } + sp->in_buffer_file_pos_log=0; + for (m=0; msamples_per_pixel; m++) + { + if ((sp->qtable_offset[m]!=0) && ((m==0) || (sp->qtable_offset[m]!=sp->qtable_offset[m-1]))) + { + for (n=0; nqtable_offset[m]==sp->qtable_offset[n]) + { + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JpegQTables tag value"); + return(0); + } + } + oa=sizeof(uint32)+69; + ob=_TIFFmalloc(oa); + if (ob==0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + *(uint32*)ob=oa; + ob[sizeof(uint32)]=255; + ob[sizeof(uint32)+1]=JPEG_MARKER_DQT; + ob[sizeof(uint32)+2]=0; + ob[sizeof(uint32)+3]=67; + ob[sizeof(uint32)+4]=m; + TIFFSeekFile(tif,sp->qtable_offset[m],SEEK_SET); + p=TIFFReadFile(tif,&ob[sizeof(uint32)+5],64); + if (p!=64) + return(0); + sp->qtable[m]=ob; + sp->sof_tq[m]=m; + } + else + sp->sof_tq[m]=sp->sof_tq[m-1]; + } + return(1); +} + +static int +OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif) +{ + static const char module[]="OJPEGReadHeaderInfoSecTablesDcTable"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint8 m; + uint8 n; + uint8 o[16]; + uint32 p; + uint32 q; + uint32 ra; + uint8* rb; + if (sp->dctable_offset[0]==0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Missing JPEG tables"); + return(0); + } + sp->in_buffer_file_pos_log=0; + for (m=0; msamples_per_pixel; m++) + { + if ((sp->dctable_offset[m]!=0) && ((m==0) || (sp->dctable_offset[m]!=sp->dctable_offset[m-1]))) + { + for (n=0; ndctable_offset[m]==sp->dctable_offset[n]) + { + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JpegDcTables tag value"); + return(0); + } + } + TIFFSeekFile(tif,sp->dctable_offset[m],SEEK_SET); + p=TIFFReadFile(tif,o,16); + if (p!=16) + return(0); + q=0; + for (n=0; n<16; n++) + q+=o[n]; + ra=sizeof(uint32)+21+q; + rb=_TIFFmalloc(ra); + if (rb==0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + *(uint32*)rb=ra; + rb[sizeof(uint32)]=255; + rb[sizeof(uint32)+1]=JPEG_MARKER_DHT; + rb[sizeof(uint32)+2]=((19+q)>>8); + rb[sizeof(uint32)+3]=((19+q)&255); + rb[sizeof(uint32)+4]=m; + for (n=0; n<16; n++) + rb[sizeof(uint32)+5+n]=o[n]; + p=TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); + if (p!=q) + return(0); + sp->dctable[m]=rb; + sp->sos_tda[m]=(m<<4); + } + else + sp->sos_tda[m]=sp->sos_tda[m-1]; + } + return(1); +} + +static int +OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif) +{ + static const char module[]="OJPEGReadHeaderInfoSecTablesAcTable"; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint8 m; + uint8 n; + uint8 o[16]; + uint32 p; + uint32 q; + uint32 ra; + uint8* rb; + if (sp->actable_offset[0]==0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Missing JPEG tables"); + return(0); + } + sp->in_buffer_file_pos_log=0; + for (m=0; msamples_per_pixel; m++) + { + if ((sp->actable_offset[m]!=0) && ((m==0) || (sp->actable_offset[m]!=sp->actable_offset[m-1]))) + { + for (n=0; nactable_offset[m]==sp->actable_offset[n]) + { + TIFFErrorExt(tif->tif_clientdata,module,"Corrupt JpegAcTables tag value"); + return(0); + } + } + TIFFSeekFile(tif,sp->actable_offset[m],SEEK_SET); + p=TIFFReadFile(tif,o,16); + if (p!=16) + return(0); + q=0; + for (n=0; n<16; n++) + q+=o[n]; + ra=sizeof(uint32)+21+q; + rb=_TIFFmalloc(ra); + if (rb==0) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + *(uint32*)rb=ra; + rb[sizeof(uint32)]=255; + rb[sizeof(uint32)+1]=JPEG_MARKER_DHT; + rb[sizeof(uint32)+2]=((19+q)>>8); + rb[sizeof(uint32)+3]=((19+q)&255); + rb[sizeof(uint32)+4]=(16|m); + for (n=0; n<16; n++) + rb[sizeof(uint32)+5+n]=o[n]; + p=TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); + if (p!=q) + return(0); + sp->actable[m]=rb; + sp->sos_tda[m]=(sp->sos_tda[m]|m); + } + else + sp->sos_tda[m]=(sp->sos_tda[m]|(sp->sos_tda[m-1]&15)); + } + return(1); +} + +static int +OJPEGReadBufferFill(OJPEGState* sp) +{ + uint16 m; + tmsize_t n; + /* TODO: double-check: when subsamplingcorrect is set, no call to TIFFErrorExt or TIFFWarningExt should be made + * in any other case, seek or read errors should be passed through */ + do + { + if (sp->in_buffer_file_togo!=0) + { + if (sp->in_buffer_file_pos_log==0) + { + TIFFSeekFile(sp->tif,sp->in_buffer_file_pos,SEEK_SET); + sp->in_buffer_file_pos_log=1; + } + m=OJPEG_BUFFER; + if ((uint64)m>sp->in_buffer_file_togo) + m=(uint16)sp->in_buffer_file_togo; + n=TIFFReadFile(sp->tif,sp->in_buffer,(tmsize_t)m); + if (n==0) + return(0); + assert(n>0); + assert(n<=OJPEG_BUFFER); + assert(n<65536); + assert((uint64)n<=sp->in_buffer_file_togo); + m=(uint16)n; + sp->in_buffer_togo=m; + sp->in_buffer_cur=sp->in_buffer; + sp->in_buffer_file_togo-=m; + sp->in_buffer_file_pos+=m; + break; + } + sp->in_buffer_file_pos_log=0; + switch(sp->in_buffer_source) + { + case osibsNotSetYet: + if (sp->jpeg_interchange_format!=0) + { + sp->in_buffer_file_pos=sp->jpeg_interchange_format; + sp->in_buffer_file_togo=sp->jpeg_interchange_format_length; + } + sp->in_buffer_source=osibsJpegInterchangeFormat; + break; + case osibsJpegInterchangeFormat: + sp->in_buffer_source=osibsStrile; + case osibsStrile: + if (!_TIFFFillStriles( sp->tif ) + || sp->tif->tif_dir.td_stripoffset == NULL + || sp->tif->tif_dir.td_stripbytecount == NULL) + return 0; + + if (sp->in_buffer_next_strile==sp->in_buffer_strile_count) + sp->in_buffer_source=osibsEof; + else + { + sp->in_buffer_file_pos=sp->tif->tif_dir.td_stripoffset[sp->in_buffer_next_strile]; + if (sp->in_buffer_file_pos!=0) + { + if (sp->in_buffer_file_pos>=sp->file_size) + sp->in_buffer_file_pos=0; + else if (sp->tif->tif_dir.td_stripbytecount==NULL) + sp->in_buffer_file_togo=sp->file_size-sp->in_buffer_file_pos; + else + { + if (sp->tif->tif_dir.td_stripbytecount == 0) { + TIFFErrorExt(sp->tif->tif_clientdata,sp->tif->tif_name,"Strip byte counts are missing"); + return(0); + } + sp->in_buffer_file_togo=sp->tif->tif_dir.td_stripbytecount[sp->in_buffer_next_strile]; + if (sp->in_buffer_file_togo==0) + sp->in_buffer_file_pos=0; + else if (sp->in_buffer_file_pos+sp->in_buffer_file_togo>sp->file_size) + sp->in_buffer_file_togo=sp->file_size-sp->in_buffer_file_pos; + } + } + sp->in_buffer_next_strile++; + } + break; + default: + return(0); + } + } while (1); + return(1); +} + +static int +OJPEGReadByte(OJPEGState* sp, uint8* byte) +{ + if (sp->in_buffer_togo==0) + { + if (OJPEGReadBufferFill(sp)==0) + return(0); + assert(sp->in_buffer_togo>0); + } + *byte=*(sp->in_buffer_cur); + sp->in_buffer_cur++; + sp->in_buffer_togo--; + return(1); +} + +static int +OJPEGReadBytePeek(OJPEGState* sp, uint8* byte) +{ + if (sp->in_buffer_togo==0) + { + if (OJPEGReadBufferFill(sp)==0) + return(0); + assert(sp->in_buffer_togo>0); + } + *byte=*(sp->in_buffer_cur); + return(1); +} + +static void +OJPEGReadByteAdvance(OJPEGState* sp) +{ + assert(sp->in_buffer_togo>0); + sp->in_buffer_cur++; + sp->in_buffer_togo--; +} + +static int +OJPEGReadWord(OJPEGState* sp, uint16* word) +{ + uint8 m; + if (OJPEGReadByte(sp,&m)==0) + return(0); + *word=(m<<8); + if (OJPEGReadByte(sp,&m)==0) + return(0); + *word|=m; + return(1); +} + +static int +OJPEGReadBlock(OJPEGState* sp, uint16 len, void* mem) +{ + uint16 mlen; + uint8* mmem; + uint16 n; + assert(len>0); + mlen=len; + mmem=mem; + do + { + if (sp->in_buffer_togo==0) + { + if (OJPEGReadBufferFill(sp)==0) + return(0); + assert(sp->in_buffer_togo>0); + } + n=mlen; + if (n>sp->in_buffer_togo) + n=sp->in_buffer_togo; + _TIFFmemcpy(mmem,sp->in_buffer_cur,n); + sp->in_buffer_cur+=n; + sp->in_buffer_togo-=n; + mlen-=n; + mmem+=n; + } while(mlen>0); + return(1); +} + +static void +OJPEGReadSkip(OJPEGState* sp, uint16 len) +{ + uint16 m; + uint16 n; + m=len; + n=m; + if (n>sp->in_buffer_togo) + n=sp->in_buffer_togo; + sp->in_buffer_cur+=n; + sp->in_buffer_togo-=n; + m-=n; + if (m>0) + { + assert(sp->in_buffer_togo==0); + n=m; + if ((uint64)n>sp->in_buffer_file_togo) + n=(uint16)sp->in_buffer_file_togo; + sp->in_buffer_file_pos+=n; + sp->in_buffer_file_togo-=n; + sp->in_buffer_file_pos_log=0; + /* we don't skip past jpeginterchangeformat/strile block... + * if that is asked from us, we're dealing with totally bazurk + * data anyway, and we've not seen this happening on any + * testfile, so we might as well likely cause some other + * meaningless error to be passed at some later time + */ + } +} + +static int +OJPEGWriteStream(TIFF* tif, void** mem, uint32* len) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + *len=0; + do + { + assert(sp->out_state<=ososEoi); + switch(sp->out_state) + { + case ososSoi: + OJPEGWriteStreamSoi(tif,mem,len); + break; + case ososQTable0: + OJPEGWriteStreamQTable(tif,0,mem,len); + break; + case ososQTable1: + OJPEGWriteStreamQTable(tif,1,mem,len); + break; + case ososQTable2: + OJPEGWriteStreamQTable(tif,2,mem,len); + break; + case ososQTable3: + OJPEGWriteStreamQTable(tif,3,mem,len); + break; + case ososDcTable0: + OJPEGWriteStreamDcTable(tif,0,mem,len); + break; + case ososDcTable1: + OJPEGWriteStreamDcTable(tif,1,mem,len); + break; + case ososDcTable2: + OJPEGWriteStreamDcTable(tif,2,mem,len); + break; + case ososDcTable3: + OJPEGWriteStreamDcTable(tif,3,mem,len); + break; + case ososAcTable0: + OJPEGWriteStreamAcTable(tif,0,mem,len); + break; + case ososAcTable1: + OJPEGWriteStreamAcTable(tif,1,mem,len); + break; + case ososAcTable2: + OJPEGWriteStreamAcTable(tif,2,mem,len); + break; + case ososAcTable3: + OJPEGWriteStreamAcTable(tif,3,mem,len); + break; + case ososDri: + OJPEGWriteStreamDri(tif,mem,len); + break; + case ososSof: + OJPEGWriteStreamSof(tif,mem,len); + break; + case ososSos: + OJPEGWriteStreamSos(tif,mem,len); + break; + case ososCompressed: + if (OJPEGWriteStreamCompressed(tif,mem,len)==0) + return(0); + break; + case ososRst: + OJPEGWriteStreamRst(tif,mem,len); + break; + case ososEoi: + OJPEGWriteStreamEoi(tif,mem,len); + break; + } + } while (*len==0); + return(1); +} + +static void +OJPEGWriteStreamSoi(TIFF* tif, void** mem, uint32* len) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + assert(OJPEG_BUFFER>=2); + sp->out_buffer[0]=255; + sp->out_buffer[1]=JPEG_MARKER_SOI; + *len=2; + *mem=(void*)sp->out_buffer; + sp->out_state++; +} + +static void +OJPEGWriteStreamQTable(TIFF* tif, uint8 table_index, void** mem, uint32* len) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + if (sp->qtable[table_index]!=0) + { + *mem=(void*)(sp->qtable[table_index]+sizeof(uint32)); + *len=*((uint32*)sp->qtable[table_index])-sizeof(uint32); + } + sp->out_state++; +} + +static void +OJPEGWriteStreamDcTable(TIFF* tif, uint8 table_index, void** mem, uint32* len) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + if (sp->dctable[table_index]!=0) + { + *mem=(void*)(sp->dctable[table_index]+sizeof(uint32)); + *len=*((uint32*)sp->dctable[table_index])-sizeof(uint32); + } + sp->out_state++; +} + +static void +OJPEGWriteStreamAcTable(TIFF* tif, uint8 table_index, void** mem, uint32* len) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + if (sp->actable[table_index]!=0) + { + *mem=(void*)(sp->actable[table_index]+sizeof(uint32)); + *len=*((uint32*)sp->actable[table_index])-sizeof(uint32); + } + sp->out_state++; +} + +static void +OJPEGWriteStreamDri(TIFF* tif, void** mem, uint32* len) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + assert(OJPEG_BUFFER>=6); + if (sp->restart_interval!=0) + { + sp->out_buffer[0]=255; + sp->out_buffer[1]=JPEG_MARKER_DRI; + sp->out_buffer[2]=0; + sp->out_buffer[3]=4; + sp->out_buffer[4]=(sp->restart_interval>>8); + sp->out_buffer[5]=(sp->restart_interval&255); + *len=6; + *mem=(void*)sp->out_buffer; + } + sp->out_state++; +} + +static void +OJPEGWriteStreamSof(TIFF* tif, void** mem, uint32* len) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint8 m; + assert(OJPEG_BUFFER>=2+8+sp->samples_per_pixel_per_plane*3); + assert(255>=8+sp->samples_per_pixel_per_plane*3); + sp->out_buffer[0]=255; + sp->out_buffer[1]=sp->sof_marker_id; + /* Lf */ + sp->out_buffer[2]=0; + sp->out_buffer[3]=8+sp->samples_per_pixel_per_plane*3; + /* P */ + sp->out_buffer[4]=8; + /* Y */ + sp->out_buffer[5]=(sp->sof_y>>8); + sp->out_buffer[6]=(sp->sof_y&255); + /* X */ + sp->out_buffer[7]=(sp->sof_x>>8); + sp->out_buffer[8]=(sp->sof_x&255); + /* Nf */ + sp->out_buffer[9]=sp->samples_per_pixel_per_plane; + for (m=0; msamples_per_pixel_per_plane; m++) + { + /* C */ + sp->out_buffer[10+m*3]=sp->sof_c[sp->plane_sample_offset+m]; + /* H and V */ + sp->out_buffer[10+m*3+1]=sp->sof_hv[sp->plane_sample_offset+m]; + /* Tq */ + sp->out_buffer[10+m*3+2]=sp->sof_tq[sp->plane_sample_offset+m]; + } + *len=10+sp->samples_per_pixel_per_plane*3; + *mem=(void*)sp->out_buffer; + sp->out_state++; +} + +static void +OJPEGWriteStreamSos(TIFF* tif, void** mem, uint32* len) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + uint8 m; + assert(OJPEG_BUFFER>=2+6+sp->samples_per_pixel_per_plane*2); + assert(255>=6+sp->samples_per_pixel_per_plane*2); + sp->out_buffer[0]=255; + sp->out_buffer[1]=JPEG_MARKER_SOS; + /* Ls */ + sp->out_buffer[2]=0; + sp->out_buffer[3]=6+sp->samples_per_pixel_per_plane*2; + /* Ns */ + sp->out_buffer[4]=sp->samples_per_pixel_per_plane; + for (m=0; msamples_per_pixel_per_plane; m++) + { + /* Cs */ + sp->out_buffer[5+m*2]=sp->sos_cs[sp->plane_sample_offset+m]; + /* Td and Ta */ + sp->out_buffer[5+m*2+1]=sp->sos_tda[sp->plane_sample_offset+m]; + } + /* Ss */ + sp->out_buffer[5+sp->samples_per_pixel_per_plane*2]=0; + /* Se */ + sp->out_buffer[5+sp->samples_per_pixel_per_plane*2+1]=63; + /* Ah and Al */ + sp->out_buffer[5+sp->samples_per_pixel_per_plane*2+2]=0; + *len=8+sp->samples_per_pixel_per_plane*2; + *mem=(void*)sp->out_buffer; + sp->out_state++; +} + +static int +OJPEGWriteStreamCompressed(TIFF* tif, void** mem, uint32* len) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + if (sp->in_buffer_togo==0) + { + if (OJPEGReadBufferFill(sp)==0) + return(0); + assert(sp->in_buffer_togo>0); + } + *len=sp->in_buffer_togo; + *mem=(void*)sp->in_buffer_cur; + sp->in_buffer_togo=0; + if (sp->in_buffer_file_togo==0) + { + switch(sp->in_buffer_source) + { + case osibsStrile: + if (sp->in_buffer_next_strilein_buffer_strile_count) + sp->out_state=ososRst; + else + sp->out_state=ososEoi; + break; + case osibsEof: + sp->out_state=ososEoi; + break; + default: + break; + } + } + return(1); +} + +static void +OJPEGWriteStreamRst(TIFF* tif, void** mem, uint32* len) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + assert(OJPEG_BUFFER>=2); + sp->out_buffer[0]=255; + sp->out_buffer[1]=JPEG_MARKER_RST0+sp->restart_index; + sp->restart_index++; + if (sp->restart_index==8) + sp->restart_index=0; + *len=2; + *mem=(void*)sp->out_buffer; + sp->out_state=ososCompressed; +} + +static void +OJPEGWriteStreamEoi(TIFF* tif, void** mem, uint32* len) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + assert(OJPEG_BUFFER>=2); + sp->out_buffer[0]=255; + sp->out_buffer[1]=JPEG_MARKER_EOI; + *len=2; + *mem=(void*)sp->out_buffer; +} + +#ifndef LIBJPEG_ENCAP_EXTERNAL +static int +jpeg_create_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo) +{ + return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_create_decompress(cinfo),1)); +} +#endif + +#ifndef LIBJPEG_ENCAP_EXTERNAL +static int +jpeg_read_header_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, uint8 require_image) +{ + return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_read_header(cinfo,require_image),1)); +} +#endif + +#ifndef LIBJPEG_ENCAP_EXTERNAL +static int +jpeg_start_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo) +{ + return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_start_decompress(cinfo),1)); +} +#endif + +#ifndef LIBJPEG_ENCAP_EXTERNAL +static int +jpeg_read_scanlines_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* scanlines, uint32 max_lines) +{ + return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_read_scanlines(cinfo,scanlines,max_lines),1)); +} +#endif + +#ifndef LIBJPEG_ENCAP_EXTERNAL +static int +jpeg_read_raw_data_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* data, uint32 max_lines) +{ + return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_read_raw_data(cinfo,data,max_lines),1)); +} +#endif + +#ifndef LIBJPEG_ENCAP_EXTERNAL +static void +jpeg_encap_unwind(TIFF* tif) +{ + OJPEGState* sp=(OJPEGState*)tif->tif_data; + LONGJMP(sp->exit_jmpbuf,1); +} +#endif + +static void +OJPEGLibjpegJpegErrorMgrOutputMessage(jpeg_common_struct* cinfo) +{ + char buffer[JMSG_LENGTH_MAX]; + (*cinfo->err->format_message)(cinfo,buffer); + TIFFWarningExt(((TIFF*)(cinfo->client_data))->tif_clientdata,"LibJpeg","%s",buffer); +} + +static void +OJPEGLibjpegJpegErrorMgrErrorExit(jpeg_common_struct* cinfo) +{ + char buffer[JMSG_LENGTH_MAX]; + (*cinfo->err->format_message)(cinfo,buffer); + TIFFErrorExt(((TIFF*)(cinfo->client_data))->tif_clientdata,"LibJpeg","%s",buffer); + jpeg_encap_unwind((TIFF*)(cinfo->client_data)); +} + +static void +OJPEGLibjpegJpegSourceMgrInitSource(jpeg_decompress_struct* cinfo) +{ + (void)cinfo; +} + +static boolean +OJPEGLibjpegJpegSourceMgrFillInputBuffer(jpeg_decompress_struct* cinfo) +{ + TIFF* tif=(TIFF*)cinfo->client_data; + OJPEGState* sp=(OJPEGState*)tif->tif_data; + void* mem=0; + uint32 len=0U; + if (OJPEGWriteStream(tif,&mem,&len)==0) + { + TIFFErrorExt(tif->tif_clientdata,"LibJpeg","Premature end of JPEG data"); + jpeg_encap_unwind(tif); + } + sp->libjpeg_jpeg_source_mgr.bytes_in_buffer=len; + sp->libjpeg_jpeg_source_mgr.next_input_byte=mem; + return(1); +} + +static void +OJPEGLibjpegJpegSourceMgrSkipInputData(jpeg_decompress_struct* cinfo, long num_bytes) +{ + TIFF* tif=(TIFF*)cinfo->client_data; + (void)num_bytes; + TIFFErrorExt(tif->tif_clientdata,"LibJpeg","Unexpected error"); + jpeg_encap_unwind(tif); +} + +static boolean +OJPEGLibjpegJpegSourceMgrResyncToRestart(jpeg_decompress_struct* cinfo, int desired) +{ + TIFF* tif=(TIFF*)cinfo->client_data; + (void)desired; + TIFFErrorExt(tif->tif_clientdata,"LibJpeg","Unexpected error"); + jpeg_encap_unwind(tif); + return(0); +} + +static void +OJPEGLibjpegJpegSourceMgrTermSource(jpeg_decompress_struct* cinfo) +{ + (void)cinfo; +} + +#endif + + +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_open.c b/Source/LibTIFF4/tif_open.c index 14cc6ee..9fd5718 100644 --- a/Source/LibTIFF4/tif_open.c +++ b/Source/LibTIFF4/tif_open.c @@ -1,725 +1,725 @@ -/* $Id: tif_open.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - */ -#include "tiffiop.h" - -/* - * Dummy functions to fill the omitted client procedures. - */ -static int -_tiffDummyMapProc(thandle_t fd, void** pbase, toff_t* psize) -{ - (void) fd; (void) pbase; (void) psize; - return (0); -} - -static void -_tiffDummyUnmapProc(thandle_t fd, void* base, toff_t size) -{ - (void) fd; (void) base; (void) size; -} - -int -_TIFFgetMode(const char* mode, const char* module) -{ - int m = -1; - - switch (mode[0]) { - case 'r': - m = O_RDONLY; - if (mode[1] == '+') - m = O_RDWR; - break; - case 'w': - case 'a': - m = O_RDWR|O_CREAT; - if (mode[0] == 'w') - m |= O_TRUNC; - break; - default: - TIFFErrorExt(0, module, "\"%s\": Bad mode", mode); - break; - } - return (m); -} - -TIFF* -TIFFClientOpen( - const char* name, const char* mode, - thandle_t clientdata, - TIFFReadWriteProc readproc, - TIFFReadWriteProc writeproc, - TIFFSeekProc seekproc, - TIFFCloseProc closeproc, - TIFFSizeProc sizeproc, - TIFFMapFileProc mapproc, - TIFFUnmapFileProc unmapproc -) -{ - static const char module[] = "TIFFClientOpen"; - TIFF *tif; - int m; - const char* cp; - - /* The following are configuration checks. They should be redundant, but should not - * compile to any actual code in an optimised release build anyway. If any of them - * fail, (makefile-based or other) configuration is not correct */ - assert(sizeof(uint8)==1); - assert(sizeof(int8)==1); - assert(sizeof(uint16)==2); - assert(sizeof(int16)==2); - assert(sizeof(uint32)==4); - assert(sizeof(int32)==4); - assert(sizeof(uint64)==8); - assert(sizeof(int64)==8); - assert(sizeof(tmsize_t)==sizeof(void*)); - { - union{ - uint8 a8[2]; - uint16 a16; - } n; - n.a8[0]=1; - n.a8[1]=0; - #ifdef WORDS_BIGENDIAN - assert(n.a16==256); - #else - assert(n.a16==1); - #endif - } - - m = _TIFFgetMode(mode, module); - if (m == -1) - goto bad2; - tif = (TIFF *)_TIFFmalloc((tmsize_t)(sizeof (TIFF) + strlen(name) + 1)); - if (tif == NULL) { - TIFFErrorExt(clientdata, module, "%s: Out of memory (TIFF structure)", name); - goto bad2; - } - _TIFFmemset(tif, 0, sizeof (*tif)); - tif->tif_name = (char *)tif + sizeof (TIFF); - strcpy(tif->tif_name, name); - tif->tif_mode = m &~ (O_CREAT|O_TRUNC); - tif->tif_curdir = (uint16) -1; /* non-existent directory */ - tif->tif_curoff = 0; - tif->tif_curstrip = (uint32) -1; /* invalid strip */ - tif->tif_row = (uint32) -1; /* read/write pre-increment */ - tif->tif_clientdata = clientdata; - if (!readproc || !writeproc || !seekproc || !closeproc || !sizeproc) { - TIFFErrorExt(clientdata, module, - "One of the client procedures is NULL pointer."); - goto bad2; - } - tif->tif_readproc = readproc; - tif->tif_writeproc = writeproc; - tif->tif_seekproc = seekproc; - tif->tif_closeproc = closeproc; - tif->tif_sizeproc = sizeproc; - if (mapproc) - tif->tif_mapproc = mapproc; - else - tif->tif_mapproc = _tiffDummyMapProc; - if (unmapproc) - tif->tif_unmapproc = unmapproc; - else - tif->tif_unmapproc = _tiffDummyUnmapProc; - _TIFFSetDefaultCompressionState(tif); /* setup default state */ - /* - * Default is to return data MSB2LSB and enable the - * use of memory-mapped files and strip chopping when - * a file is opened read-only. - */ - tif->tif_flags = FILLORDER_MSB2LSB; - if (m == O_RDONLY ) - tif->tif_flags |= TIFF_MAPPED; - - #ifdef STRIPCHOP_DEFAULT - if (m == O_RDONLY || m == O_RDWR) - tif->tif_flags |= STRIPCHOP_DEFAULT; - #endif - - /* - * Process library-specific flags in the open mode string. - * The following flags may be used to control intrinsic library - * behaviour that may or may not be desirable (usually for - * compatibility with some application that claims to support - * TIFF but only supports some braindead idea of what the - * vendor thinks TIFF is): - * - * 'l' use little-endian byte order for creating a file - * 'b' use big-endian byte order for creating a file - * 'L' read/write information using LSB2MSB bit order - * 'B' read/write information using MSB2LSB bit order - * 'H' read/write information using host bit order - * 'M' enable use of memory-mapped files when supported - * 'm' disable use of memory-mapped files - * 'C' enable strip chopping support when reading - * 'c' disable strip chopping support - * 'h' read TIFF header only, do not load the first IFD - * '4' ClassicTIFF for creating a file (default) - * '8' BigTIFF for creating a file - * - * The use of the 'l' and 'b' flags is strongly discouraged. - * These flags are provided solely because numerous vendors, - * typically on the PC, do not correctly support TIFF; they - * only support the Intel little-endian byte order. This - * support is not configured by default because it supports - * the violation of the TIFF spec that says that readers *MUST* - * support both byte orders. It is strongly recommended that - * you not use this feature except to deal with busted apps - * that write invalid TIFF. And even in those cases you should - * bang on the vendors to fix their software. - * - * The 'L', 'B', and 'H' flags are intended for applications - * that can optimize operations on data by using a particular - * bit order. By default the library returns data in MSB2LSB - * bit order for compatibiltiy with older versions of this - * library. Returning data in the bit order of the native cpu - * makes the most sense but also requires applications to check - * the value of the FillOrder tag; something they probably do - * not do right now. - * - * The 'M' and 'm' flags are provided because some virtual memory - * systems exhibit poor behaviour when large images are mapped. - * These options permit clients to control the use of memory-mapped - * files on a per-file basis. - * - * The 'C' and 'c' flags are provided because the library support - * for chopping up large strips into multiple smaller strips is not - * application-transparent and as such can cause problems. The 'c' - * option permits applications that only want to look at the tags, - * for example, to get the unadulterated TIFF tag information. - */ - for (cp = mode; *cp; cp++) - switch (*cp) { - case 'b': - #ifndef WORDS_BIGENDIAN - if (m&O_CREAT) - tif->tif_flags |= TIFF_SWAB; - #endif - break; - case 'l': - #ifdef WORDS_BIGENDIAN - if ((m&O_CREAT)) - tif->tif_flags |= TIFF_SWAB; - #endif - break; - case 'B': - tif->tif_flags = (tif->tif_flags &~ TIFF_FILLORDER) | - FILLORDER_MSB2LSB; - break; - case 'L': - tif->tif_flags = (tif->tif_flags &~ TIFF_FILLORDER) | - FILLORDER_LSB2MSB; - break; - case 'H': - tif->tif_flags = (tif->tif_flags &~ TIFF_FILLORDER) | - HOST_FILLORDER; - break; - case 'M': - if (m == O_RDONLY) - tif->tif_flags |= TIFF_MAPPED; - break; - case 'm': - if (m == O_RDONLY) - tif->tif_flags &= ~TIFF_MAPPED; - break; - case 'C': - if (m == O_RDONLY) - tif->tif_flags |= TIFF_STRIPCHOP; - break; - case 'c': - if (m == O_RDONLY) - tif->tif_flags &= ~TIFF_STRIPCHOP; - break; - case 'h': - tif->tif_flags |= TIFF_HEADERONLY; - break; - case '8': - if (m&O_CREAT) - tif->tif_flags |= TIFF_BIGTIFF; - break; - } - /* - * Read in TIFF header. - */ - if ((m & O_TRUNC) || - !ReadOK(tif, &tif->tif_header, sizeof (TIFFHeaderClassic))) { - if (tif->tif_mode == O_RDONLY) { - TIFFErrorExt(tif->tif_clientdata, name, - "Cannot read TIFF header"); - goto bad; - } - /* - * Setup header and write. - */ - #ifdef WORDS_BIGENDIAN - tif->tif_header.common.tiff_magic = tif->tif_flags & TIFF_SWAB - ? TIFF_LITTLEENDIAN : TIFF_BIGENDIAN; - #else - tif->tif_header.common.tiff_magic = tif->tif_flags & TIFF_SWAB - ? TIFF_BIGENDIAN : TIFF_LITTLEENDIAN; - #endif - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { - tif->tif_header.common.tiff_version = TIFF_VERSION_CLASSIC; - tif->tif_header.classic.tiff_diroff = 0; - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabShort(&tif->tif_header.common.tiff_version); - tif->tif_header_size = sizeof(TIFFHeaderClassic); - } - else - { - tif->tif_header.common.tiff_version = TIFF_VERSION_BIG; - tif->tif_header.big.tiff_offsetsize = 8; - tif->tif_header.big.tiff_unused = 0; - tif->tif_header.big.tiff_diroff = 0; - if (tif->tif_flags & TIFF_SWAB) - { - TIFFSwabShort(&tif->tif_header.common.tiff_version); - TIFFSwabShort(&tif->tif_header.big.tiff_offsetsize); - } - tif->tif_header_size = sizeof (TIFFHeaderBig); - } - /* - * The doc for "fopen" for some STD_C_LIBs says that if you - * open a file for modify ("+"), then you must fseek (or - * fflush?) between any freads and fwrites. This is not - * necessary on most systems, but has been shown to be needed - * on Solaris. - */ - TIFFSeekFile( tif, 0, SEEK_SET ); - if (!WriteOK(tif, &tif->tif_header, (tmsize_t)(tif->tif_header_size))) { - TIFFErrorExt(tif->tif_clientdata, name, - "Error writing TIFF header"); - goto bad; - } - /* - * Setup the byte order handling. - */ - if (tif->tif_header.common.tiff_magic == TIFF_BIGENDIAN) { - #ifndef WORDS_BIGENDIAN - tif->tif_flags |= TIFF_SWAB; - #endif - } else { - #ifdef WORDS_BIGENDIAN - tif->tif_flags |= TIFF_SWAB; - #endif - } - /* - * Setup default directory. - */ - if (!TIFFDefaultDirectory(tif)) - goto bad; - tif->tif_diroff = 0; - tif->tif_dirlist = NULL; - tif->tif_dirlistsize = 0; - tif->tif_dirnumber = 0; - return (tif); - } - /* - * Setup the byte order handling. - */ - if (tif->tif_header.common.tiff_magic != TIFF_BIGENDIAN && - tif->tif_header.common.tiff_magic != TIFF_LITTLEENDIAN - #if MDI_SUPPORT - && - #if HOST_BIGENDIAN - tif->tif_header.common.tiff_magic != MDI_BIGENDIAN - #else - tif->tif_header.common.tiff_magic != MDI_LITTLEENDIAN - #endif - ) { - TIFFErrorExt(tif->tif_clientdata, name, - "Not a TIFF or MDI file, bad magic number %d (0x%x)", - #else - ) { - TIFFErrorExt(tif->tif_clientdata, name, - "Not a TIFF file, bad magic number %d (0x%x)", - #endif - tif->tif_header.common.tiff_magic, - tif->tif_header.common.tiff_magic); - goto bad; - } - if (tif->tif_header.common.tiff_magic == TIFF_BIGENDIAN) { - #ifndef WORDS_BIGENDIAN - tif->tif_flags |= TIFF_SWAB; - #endif - } else { - #ifdef WORDS_BIGENDIAN - tif->tif_flags |= TIFF_SWAB; - #endif - } - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabShort(&tif->tif_header.common.tiff_version); - if ((tif->tif_header.common.tiff_version != TIFF_VERSION_CLASSIC)&& - (tif->tif_header.common.tiff_version != TIFF_VERSION_BIG)) { - TIFFErrorExt(tif->tif_clientdata, name, - "Not a TIFF file, bad version number %d (0x%x)", - tif->tif_header.common.tiff_version, - tif->tif_header.common.tiff_version); - goto bad; - } - if (tif->tif_header.common.tiff_version == TIFF_VERSION_CLASSIC) - { - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabLong(&tif->tif_header.classic.tiff_diroff); - tif->tif_header_size = sizeof(TIFFHeaderClassic); - } - else - { - if (!ReadOK(tif, ((uint8*)(&tif->tif_header) + sizeof(TIFFHeaderClassic)), (sizeof(TIFFHeaderBig)-sizeof(TIFFHeaderClassic)))) - { - TIFFErrorExt(tif->tif_clientdata, name, - "Cannot read TIFF header"); - goto bad; - } - if (tif->tif_flags & TIFF_SWAB) - { - TIFFSwabShort(&tif->tif_header.big.tiff_offsetsize); - TIFFSwabLong8(&tif->tif_header.big.tiff_diroff); - } - if (tif->tif_header.big.tiff_offsetsize != 8) - { - TIFFErrorExt(tif->tif_clientdata, name, - "Not a TIFF file, bad BigTIFF offsetsize %d (0x%x)", - tif->tif_header.big.tiff_offsetsize, - tif->tif_header.big.tiff_offsetsize); - goto bad; - } - if (tif->tif_header.big.tiff_unused != 0) - { - TIFFErrorExt(tif->tif_clientdata, name, - "Not a TIFF file, bad BigTIFF unused %d (0x%x)", - tif->tif_header.big.tiff_unused, - tif->tif_header.big.tiff_unused); - goto bad; - } - tif->tif_header_size = sizeof(TIFFHeaderBig); - tif->tif_flags |= TIFF_BIGTIFF; - } - tif->tif_flags |= TIFF_MYBUFFER; - tif->tif_rawcp = tif->tif_rawdata = 0; - tif->tif_rawdatasize = 0; - tif->tif_rawdataoff = 0; - tif->tif_rawdataloaded = 0; - - switch (mode[0]) { - case 'r': - if (!(tif->tif_flags&TIFF_BIGTIFF)) - tif->tif_nextdiroff = tif->tif_header.classic.tiff_diroff; - else - tif->tif_nextdiroff = tif->tif_header.big.tiff_diroff; - /* - * Try to use a memory-mapped file if the client - * has not explicitly suppressed usage with the - * 'm' flag in the open mode (see above). - */ - if (tif->tif_flags & TIFF_MAPPED) - { - toff_t n; - if (TIFFMapFileContents(tif,(void**)(&tif->tif_base),&n)) - { - tif->tif_size=(tmsize_t)n; - assert((toff_t)tif->tif_size==n); - } - else - tif->tif_flags &= ~TIFF_MAPPED; - } - /* - * Sometimes we do not want to read the first directory (for example, - * it may be broken) and want to proceed to other directories. I this - * case we use the TIFF_HEADERONLY flag to open file and return - * immediately after reading TIFF header. - */ - if (tif->tif_flags & TIFF_HEADERONLY) - return (tif); - - /* - * Setup initial directory. - */ - if (TIFFReadDirectory(tif)) { - tif->tif_rawcc = (tmsize_t)-1; - tif->tif_flags |= TIFF_BUFFERSETUP; - return (tif); - } - break; - case 'a': - /* - * New directories are automatically append - * to the end of the directory chain when they - * are written out (see TIFFWriteDirectory). - */ - if (!TIFFDefaultDirectory(tif)) - goto bad; - return (tif); - } -bad: - tif->tif_mode = O_RDONLY; /* XXX avoid flush */ - TIFFCleanup(tif); -bad2: - return ((TIFF*)0); -} - -/* - * Query functions to access private data. - */ - -/* - * Return open file's name. - */ -const char * -TIFFFileName(TIFF* tif) -{ - return (tif->tif_name); -} - -/* - * Set the file name. - */ -const char * -TIFFSetFileName(TIFF* tif, const char *name) -{ - const char* old_name = tif->tif_name; - tif->tif_name = (char *)name; - return (old_name); -} - -/* - * Return open file's I/O descriptor. - */ -int -TIFFFileno(TIFF* tif) -{ - return (tif->tif_fd); -} - -/* - * Set open file's I/O descriptor, and return previous value. - */ -int -TIFFSetFileno(TIFF* tif, int fd) -{ - int old_fd = tif->tif_fd; - tif->tif_fd = fd; - return old_fd; -} - -/* - * Return open file's clientdata. - */ -thandle_t -TIFFClientdata(TIFF* tif) -{ - return (tif->tif_clientdata); -} - -/* - * Set open file's clientdata, and return previous value. - */ -thandle_t -TIFFSetClientdata(TIFF* tif, thandle_t newvalue) -{ - thandle_t m = tif->tif_clientdata; - tif->tif_clientdata = newvalue; - return m; -} - -/* - * Return read/write mode. - */ -int -TIFFGetMode(TIFF* tif) -{ - return (tif->tif_mode); -} - -/* - * Return read/write mode. - */ -int -TIFFSetMode(TIFF* tif, int mode) -{ - int old_mode = tif->tif_mode; - tif->tif_mode = mode; - return (old_mode); -} - -/* - * Return nonzero if file is organized in - * tiles; zero if organized as strips. - */ -int -TIFFIsTiled(TIFF* tif) -{ - return (isTiled(tif)); -} - -/* - * Return current row being read/written. - */ -uint32 -TIFFCurrentRow(TIFF* tif) -{ - return (tif->tif_row); -} - -/* - * Return index of the current directory. - */ -uint16 -TIFFCurrentDirectory(TIFF* tif) -{ - return (tif->tif_curdir); -} - -/* - * Return current strip. - */ -uint32 -TIFFCurrentStrip(TIFF* tif) -{ - return (tif->tif_curstrip); -} - -/* - * Return current tile. - */ -uint32 -TIFFCurrentTile(TIFF* tif) -{ - return (tif->tif_curtile); -} - -/* - * Return nonzero if the file has byte-swapped data. - */ -int -TIFFIsByteSwapped(TIFF* tif) -{ - return ((tif->tif_flags & TIFF_SWAB) != 0); -} - -/* - * Return nonzero if the data is returned up-sampled. - */ -int -TIFFIsUpSampled(TIFF* tif) -{ - return (isUpSampled(tif)); -} - -/* - * Return nonzero if the data is returned in MSB-to-LSB bit order. - */ -int -TIFFIsMSB2LSB(TIFF* tif) -{ - return (isFillOrder(tif, FILLORDER_MSB2LSB)); -} - -/* - * Return nonzero if given file was written in big-endian order. - */ -int -TIFFIsBigEndian(TIFF* tif) -{ - return (tif->tif_header.common.tiff_magic == TIFF_BIGENDIAN); -} - -/* - * Return pointer to file read method. - */ -TIFFReadWriteProc -TIFFGetReadProc(TIFF* tif) -{ - return (tif->tif_readproc); -} - -/* - * Return pointer to file write method. - */ -TIFFReadWriteProc -TIFFGetWriteProc(TIFF* tif) -{ - return (tif->tif_writeproc); -} - -/* - * Return pointer to file seek method. - */ -TIFFSeekProc -TIFFGetSeekProc(TIFF* tif) -{ - return (tif->tif_seekproc); -} - -/* - * Return pointer to file close method. - */ -TIFFCloseProc -TIFFGetCloseProc(TIFF* tif) -{ - return (tif->tif_closeproc); -} - -/* - * Return pointer to file size requesting method. - */ -TIFFSizeProc -TIFFGetSizeProc(TIFF* tif) -{ - return (tif->tif_sizeproc); -} - -/* - * Return pointer to memory mapping method. - */ -TIFFMapFileProc -TIFFGetMapFileProc(TIFF* tif) -{ - return (tif->tif_mapproc); -} - -/* - * Return pointer to memory unmapping method. - */ -TIFFUnmapFileProc -TIFFGetUnmapFileProc(TIFF* tif) -{ - return (tif->tif_unmapproc); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_open.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + */ +#include "tiffiop.h" + +/* + * Dummy functions to fill the omitted client procedures. + */ +static int +_tiffDummyMapProc(thandle_t fd, void** pbase, toff_t* psize) +{ + (void) fd; (void) pbase; (void) psize; + return (0); +} + +static void +_tiffDummyUnmapProc(thandle_t fd, void* base, toff_t size) +{ + (void) fd; (void) base; (void) size; +} + +int +_TIFFgetMode(const char* mode, const char* module) +{ + int m = -1; + + switch (mode[0]) { + case 'r': + m = O_RDONLY; + if (mode[1] == '+') + m = O_RDWR; + break; + case 'w': + case 'a': + m = O_RDWR|O_CREAT; + if (mode[0] == 'w') + m |= O_TRUNC; + break; + default: + TIFFErrorExt(0, module, "\"%s\": Bad mode", mode); + break; + } + return (m); +} + +TIFF* +TIFFClientOpen( + const char* name, const char* mode, + thandle_t clientdata, + TIFFReadWriteProc readproc, + TIFFReadWriteProc writeproc, + TIFFSeekProc seekproc, + TIFFCloseProc closeproc, + TIFFSizeProc sizeproc, + TIFFMapFileProc mapproc, + TIFFUnmapFileProc unmapproc +) +{ + static const char module[] = "TIFFClientOpen"; + TIFF *tif; + int m; + const char* cp; + + /* The following are configuration checks. They should be redundant, but should not + * compile to any actual code in an optimised release build anyway. If any of them + * fail, (makefile-based or other) configuration is not correct */ + assert(sizeof(uint8)==1); + assert(sizeof(int8)==1); + assert(sizeof(uint16)==2); + assert(sizeof(int16)==2); + assert(sizeof(uint32)==4); + assert(sizeof(int32)==4); + assert(sizeof(uint64)==8); + assert(sizeof(int64)==8); + assert(sizeof(tmsize_t)==sizeof(void*)); + { + union{ + uint8 a8[2]; + uint16 a16; + } n; + n.a8[0]=1; + n.a8[1]=0; + #ifdef WORDS_BIGENDIAN + assert(n.a16==256); + #else + assert(n.a16==1); + #endif + } + + m = _TIFFgetMode(mode, module); + if (m == -1) + goto bad2; + tif = (TIFF *)_TIFFmalloc((tmsize_t)(sizeof (TIFF) + strlen(name) + 1)); + if (tif == NULL) { + TIFFErrorExt(clientdata, module, "%s: Out of memory (TIFF structure)", name); + goto bad2; + } + _TIFFmemset(tif, 0, sizeof (*tif)); + tif->tif_name = (char *)tif + sizeof (TIFF); + strcpy(tif->tif_name, name); + tif->tif_mode = m &~ (O_CREAT|O_TRUNC); + tif->tif_curdir = (uint16) -1; /* non-existent directory */ + tif->tif_curoff = 0; + tif->tif_curstrip = (uint32) -1; /* invalid strip */ + tif->tif_row = (uint32) -1; /* read/write pre-increment */ + tif->tif_clientdata = clientdata; + if (!readproc || !writeproc || !seekproc || !closeproc || !sizeproc) { + TIFFErrorExt(clientdata, module, + "One of the client procedures is NULL pointer."); + goto bad2; + } + tif->tif_readproc = readproc; + tif->tif_writeproc = writeproc; + tif->tif_seekproc = seekproc; + tif->tif_closeproc = closeproc; + tif->tif_sizeproc = sizeproc; + if (mapproc) + tif->tif_mapproc = mapproc; + else + tif->tif_mapproc = _tiffDummyMapProc; + if (unmapproc) + tif->tif_unmapproc = unmapproc; + else + tif->tif_unmapproc = _tiffDummyUnmapProc; + _TIFFSetDefaultCompressionState(tif); /* setup default state */ + /* + * Default is to return data MSB2LSB and enable the + * use of memory-mapped files and strip chopping when + * a file is opened read-only. + */ + tif->tif_flags = FILLORDER_MSB2LSB; + if (m == O_RDONLY ) + tif->tif_flags |= TIFF_MAPPED; + + #ifdef STRIPCHOP_DEFAULT + if (m == O_RDONLY || m == O_RDWR) + tif->tif_flags |= STRIPCHOP_DEFAULT; + #endif + + /* + * Process library-specific flags in the open mode string. + * The following flags may be used to control intrinsic library + * behaviour that may or may not be desirable (usually for + * compatibility with some application that claims to support + * TIFF but only supports some braindead idea of what the + * vendor thinks TIFF is): + * + * 'l' use little-endian byte order for creating a file + * 'b' use big-endian byte order for creating a file + * 'L' read/write information using LSB2MSB bit order + * 'B' read/write information using MSB2LSB bit order + * 'H' read/write information using host bit order + * 'M' enable use of memory-mapped files when supported + * 'm' disable use of memory-mapped files + * 'C' enable strip chopping support when reading + * 'c' disable strip chopping support + * 'h' read TIFF header only, do not load the first IFD + * '4' ClassicTIFF for creating a file (default) + * '8' BigTIFF for creating a file + * + * The use of the 'l' and 'b' flags is strongly discouraged. + * These flags are provided solely because numerous vendors, + * typically on the PC, do not correctly support TIFF; they + * only support the Intel little-endian byte order. This + * support is not configured by default because it supports + * the violation of the TIFF spec that says that readers *MUST* + * support both byte orders. It is strongly recommended that + * you not use this feature except to deal with busted apps + * that write invalid TIFF. And even in those cases you should + * bang on the vendors to fix their software. + * + * The 'L', 'B', and 'H' flags are intended for applications + * that can optimize operations on data by using a particular + * bit order. By default the library returns data in MSB2LSB + * bit order for compatibiltiy with older versions of this + * library. Returning data in the bit order of the native cpu + * makes the most sense but also requires applications to check + * the value of the FillOrder tag; something they probably do + * not do right now. + * + * The 'M' and 'm' flags are provided because some virtual memory + * systems exhibit poor behaviour when large images are mapped. + * These options permit clients to control the use of memory-mapped + * files on a per-file basis. + * + * The 'C' and 'c' flags are provided because the library support + * for chopping up large strips into multiple smaller strips is not + * application-transparent and as such can cause problems. The 'c' + * option permits applications that only want to look at the tags, + * for example, to get the unadulterated TIFF tag information. + */ + for (cp = mode; *cp; cp++) + switch (*cp) { + case 'b': + #ifndef WORDS_BIGENDIAN + if (m&O_CREAT) + tif->tif_flags |= TIFF_SWAB; + #endif + break; + case 'l': + #ifdef WORDS_BIGENDIAN + if ((m&O_CREAT)) + tif->tif_flags |= TIFF_SWAB; + #endif + break; + case 'B': + tif->tif_flags = (tif->tif_flags &~ TIFF_FILLORDER) | + FILLORDER_MSB2LSB; + break; + case 'L': + tif->tif_flags = (tif->tif_flags &~ TIFF_FILLORDER) | + FILLORDER_LSB2MSB; + break; + case 'H': + tif->tif_flags = (tif->tif_flags &~ TIFF_FILLORDER) | + HOST_FILLORDER; + break; + case 'M': + if (m == O_RDONLY) + tif->tif_flags |= TIFF_MAPPED; + break; + case 'm': + if (m == O_RDONLY) + tif->tif_flags &= ~TIFF_MAPPED; + break; + case 'C': + if (m == O_RDONLY) + tif->tif_flags |= TIFF_STRIPCHOP; + break; + case 'c': + if (m == O_RDONLY) + tif->tif_flags &= ~TIFF_STRIPCHOP; + break; + case 'h': + tif->tif_flags |= TIFF_HEADERONLY; + break; + case '8': + if (m&O_CREAT) + tif->tif_flags |= TIFF_BIGTIFF; + break; + } + /* + * Read in TIFF header. + */ + if ((m & O_TRUNC) || + !ReadOK(tif, &tif->tif_header, sizeof (TIFFHeaderClassic))) { + if (tif->tif_mode == O_RDONLY) { + TIFFErrorExt(tif->tif_clientdata, name, + "Cannot read TIFF header"); + goto bad; + } + /* + * Setup header and write. + */ + #ifdef WORDS_BIGENDIAN + tif->tif_header.common.tiff_magic = tif->tif_flags & TIFF_SWAB + ? TIFF_LITTLEENDIAN : TIFF_BIGENDIAN; + #else + tif->tif_header.common.tiff_magic = tif->tif_flags & TIFF_SWAB + ? TIFF_BIGENDIAN : TIFF_LITTLEENDIAN; + #endif + if (!(tif->tif_flags&TIFF_BIGTIFF)) + { + tif->tif_header.common.tiff_version = TIFF_VERSION_CLASSIC; + tif->tif_header.classic.tiff_diroff = 0; + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabShort(&tif->tif_header.common.tiff_version); + tif->tif_header_size = sizeof(TIFFHeaderClassic); + } + else + { + tif->tif_header.common.tiff_version = TIFF_VERSION_BIG; + tif->tif_header.big.tiff_offsetsize = 8; + tif->tif_header.big.tiff_unused = 0; + tif->tif_header.big.tiff_diroff = 0; + if (tif->tif_flags & TIFF_SWAB) + { + TIFFSwabShort(&tif->tif_header.common.tiff_version); + TIFFSwabShort(&tif->tif_header.big.tiff_offsetsize); + } + tif->tif_header_size = sizeof (TIFFHeaderBig); + } + /* + * The doc for "fopen" for some STD_C_LIBs says that if you + * open a file for modify ("+"), then you must fseek (or + * fflush?) between any freads and fwrites. This is not + * necessary on most systems, but has been shown to be needed + * on Solaris. + */ + TIFFSeekFile( tif, 0, SEEK_SET ); + if (!WriteOK(tif, &tif->tif_header, (tmsize_t)(tif->tif_header_size))) { + TIFFErrorExt(tif->tif_clientdata, name, + "Error writing TIFF header"); + goto bad; + } + /* + * Setup the byte order handling. + */ + if (tif->tif_header.common.tiff_magic == TIFF_BIGENDIAN) { + #ifndef WORDS_BIGENDIAN + tif->tif_flags |= TIFF_SWAB; + #endif + } else { + #ifdef WORDS_BIGENDIAN + tif->tif_flags |= TIFF_SWAB; + #endif + } + /* + * Setup default directory. + */ + if (!TIFFDefaultDirectory(tif)) + goto bad; + tif->tif_diroff = 0; + tif->tif_dirlist = NULL; + tif->tif_dirlistsize = 0; + tif->tif_dirnumber = 0; + return (tif); + } + /* + * Setup the byte order handling. + */ + if (tif->tif_header.common.tiff_magic != TIFF_BIGENDIAN && + tif->tif_header.common.tiff_magic != TIFF_LITTLEENDIAN + #if MDI_SUPPORT + && + #if HOST_BIGENDIAN + tif->tif_header.common.tiff_magic != MDI_BIGENDIAN + #else + tif->tif_header.common.tiff_magic != MDI_LITTLEENDIAN + #endif + ) { + TIFFErrorExt(tif->tif_clientdata, name, + "Not a TIFF or MDI file, bad magic number %d (0x%x)", + #else + ) { + TIFFErrorExt(tif->tif_clientdata, name, + "Not a TIFF file, bad magic number %d (0x%x)", + #endif + tif->tif_header.common.tiff_magic, + tif->tif_header.common.tiff_magic); + goto bad; + } + if (tif->tif_header.common.tiff_magic == TIFF_BIGENDIAN) { + #ifndef WORDS_BIGENDIAN + tif->tif_flags |= TIFF_SWAB; + #endif + } else { + #ifdef WORDS_BIGENDIAN + tif->tif_flags |= TIFF_SWAB; + #endif + } + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabShort(&tif->tif_header.common.tiff_version); + if ((tif->tif_header.common.tiff_version != TIFF_VERSION_CLASSIC)&& + (tif->tif_header.common.tiff_version != TIFF_VERSION_BIG)) { + TIFFErrorExt(tif->tif_clientdata, name, + "Not a TIFF file, bad version number %d (0x%x)", + tif->tif_header.common.tiff_version, + tif->tif_header.common.tiff_version); + goto bad; + } + if (tif->tif_header.common.tiff_version == TIFF_VERSION_CLASSIC) + { + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabLong(&tif->tif_header.classic.tiff_diroff); + tif->tif_header_size = sizeof(TIFFHeaderClassic); + } + else + { + if (!ReadOK(tif, ((uint8*)(&tif->tif_header) + sizeof(TIFFHeaderClassic)), (sizeof(TIFFHeaderBig)-sizeof(TIFFHeaderClassic)))) + { + TIFFErrorExt(tif->tif_clientdata, name, + "Cannot read TIFF header"); + goto bad; + } + if (tif->tif_flags & TIFF_SWAB) + { + TIFFSwabShort(&tif->tif_header.big.tiff_offsetsize); + TIFFSwabLong8(&tif->tif_header.big.tiff_diroff); + } + if (tif->tif_header.big.tiff_offsetsize != 8) + { + TIFFErrorExt(tif->tif_clientdata, name, + "Not a TIFF file, bad BigTIFF offsetsize %d (0x%x)", + tif->tif_header.big.tiff_offsetsize, + tif->tif_header.big.tiff_offsetsize); + goto bad; + } + if (tif->tif_header.big.tiff_unused != 0) + { + TIFFErrorExt(tif->tif_clientdata, name, + "Not a TIFF file, bad BigTIFF unused %d (0x%x)", + tif->tif_header.big.tiff_unused, + tif->tif_header.big.tiff_unused); + goto bad; + } + tif->tif_header_size = sizeof(TIFFHeaderBig); + tif->tif_flags |= TIFF_BIGTIFF; + } + tif->tif_flags |= TIFF_MYBUFFER; + tif->tif_rawcp = tif->tif_rawdata = 0; + tif->tif_rawdatasize = 0; + tif->tif_rawdataoff = 0; + tif->tif_rawdataloaded = 0; + + switch (mode[0]) { + case 'r': + if (!(tif->tif_flags&TIFF_BIGTIFF)) + tif->tif_nextdiroff = tif->tif_header.classic.tiff_diroff; + else + tif->tif_nextdiroff = tif->tif_header.big.tiff_diroff; + /* + * Try to use a memory-mapped file if the client + * has not explicitly suppressed usage with the + * 'm' flag in the open mode (see above). + */ + if (tif->tif_flags & TIFF_MAPPED) + { + toff_t n; + if (TIFFMapFileContents(tif,(void**)(&tif->tif_base),&n)) + { + tif->tif_size=(tmsize_t)n; + assert((toff_t)tif->tif_size==n); + } + else + tif->tif_flags &= ~TIFF_MAPPED; + } + /* + * Sometimes we do not want to read the first directory (for example, + * it may be broken) and want to proceed to other directories. I this + * case we use the TIFF_HEADERONLY flag to open file and return + * immediately after reading TIFF header. + */ + if (tif->tif_flags & TIFF_HEADERONLY) + return (tif); + + /* + * Setup initial directory. + */ + if (TIFFReadDirectory(tif)) { + tif->tif_rawcc = (tmsize_t)-1; + tif->tif_flags |= TIFF_BUFFERSETUP; + return (tif); + } + break; + case 'a': + /* + * New directories are automatically append + * to the end of the directory chain when they + * are written out (see TIFFWriteDirectory). + */ + if (!TIFFDefaultDirectory(tif)) + goto bad; + return (tif); + } +bad: + tif->tif_mode = O_RDONLY; /* XXX avoid flush */ + TIFFCleanup(tif); +bad2: + return ((TIFF*)0); +} + +/* + * Query functions to access private data. + */ + +/* + * Return open file's name. + */ +const char * +TIFFFileName(TIFF* tif) +{ + return (tif->tif_name); +} + +/* + * Set the file name. + */ +const char * +TIFFSetFileName(TIFF* tif, const char *name) +{ + const char* old_name = tif->tif_name; + tif->tif_name = (char *)name; + return (old_name); +} + +/* + * Return open file's I/O descriptor. + */ +int +TIFFFileno(TIFF* tif) +{ + return (tif->tif_fd); +} + +/* + * Set open file's I/O descriptor, and return previous value. + */ +int +TIFFSetFileno(TIFF* tif, int fd) +{ + int old_fd = tif->tif_fd; + tif->tif_fd = fd; + return old_fd; +} + +/* + * Return open file's clientdata. + */ +thandle_t +TIFFClientdata(TIFF* tif) +{ + return (tif->tif_clientdata); +} + +/* + * Set open file's clientdata, and return previous value. + */ +thandle_t +TIFFSetClientdata(TIFF* tif, thandle_t newvalue) +{ + thandle_t m = tif->tif_clientdata; + tif->tif_clientdata = newvalue; + return m; +} + +/* + * Return read/write mode. + */ +int +TIFFGetMode(TIFF* tif) +{ + return (tif->tif_mode); +} + +/* + * Return read/write mode. + */ +int +TIFFSetMode(TIFF* tif, int mode) +{ + int old_mode = tif->tif_mode; + tif->tif_mode = mode; + return (old_mode); +} + +/* + * Return nonzero if file is organized in + * tiles; zero if organized as strips. + */ +int +TIFFIsTiled(TIFF* tif) +{ + return (isTiled(tif)); +} + +/* + * Return current row being read/written. + */ +uint32 +TIFFCurrentRow(TIFF* tif) +{ + return (tif->tif_row); +} + +/* + * Return index of the current directory. + */ +uint16 +TIFFCurrentDirectory(TIFF* tif) +{ + return (tif->tif_curdir); +} + +/* + * Return current strip. + */ +uint32 +TIFFCurrentStrip(TIFF* tif) +{ + return (tif->tif_curstrip); +} + +/* + * Return current tile. + */ +uint32 +TIFFCurrentTile(TIFF* tif) +{ + return (tif->tif_curtile); +} + +/* + * Return nonzero if the file has byte-swapped data. + */ +int +TIFFIsByteSwapped(TIFF* tif) +{ + return ((tif->tif_flags & TIFF_SWAB) != 0); +} + +/* + * Return nonzero if the data is returned up-sampled. + */ +int +TIFFIsUpSampled(TIFF* tif) +{ + return (isUpSampled(tif)); +} + +/* + * Return nonzero if the data is returned in MSB-to-LSB bit order. + */ +int +TIFFIsMSB2LSB(TIFF* tif) +{ + return (isFillOrder(tif, FILLORDER_MSB2LSB)); +} + +/* + * Return nonzero if given file was written in big-endian order. + */ +int +TIFFIsBigEndian(TIFF* tif) +{ + return (tif->tif_header.common.tiff_magic == TIFF_BIGENDIAN); +} + +/* + * Return pointer to file read method. + */ +TIFFReadWriteProc +TIFFGetReadProc(TIFF* tif) +{ + return (tif->tif_readproc); +} + +/* + * Return pointer to file write method. + */ +TIFFReadWriteProc +TIFFGetWriteProc(TIFF* tif) +{ + return (tif->tif_writeproc); +} + +/* + * Return pointer to file seek method. + */ +TIFFSeekProc +TIFFGetSeekProc(TIFF* tif) +{ + return (tif->tif_seekproc); +} + +/* + * Return pointer to file close method. + */ +TIFFCloseProc +TIFFGetCloseProc(TIFF* tif) +{ + return (tif->tif_closeproc); +} + +/* + * Return pointer to file size requesting method. + */ +TIFFSizeProc +TIFFGetSizeProc(TIFF* tif) +{ + return (tif->tif_sizeproc); +} + +/* + * Return pointer to memory mapping method. + */ +TIFFMapFileProc +TIFFGetMapFileProc(TIFF* tif) +{ + return (tif->tif_mapproc); +} + +/* + * Return pointer to memory unmapping method. + */ +TIFFUnmapFileProc +TIFFGetUnmapFileProc(TIFF* tif) +{ + return (tif->tif_unmapproc); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_packbits.c b/Source/LibTIFF4/tif_packbits.c index 56d5969..4d041b1 100644 --- a/Source/LibTIFF4/tif_packbits.c +++ b/Source/LibTIFF4/tif_packbits.c @@ -1,300 +1,300 @@ -/* $Id: tif_packbits.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "tiffiop.h" -#ifdef PACKBITS_SUPPORT -/* - * TIFF Library. - * - * PackBits Compression Algorithm Support - */ -#include - -static int -PackBitsPreEncode(TIFF* tif, uint16 s) -{ - (void) s; - - if (!(tif->tif_data = (uint8*)_TIFFmalloc(sizeof(tmsize_t)))) - return (0); - /* - * Calculate the scanline/tile-width size in bytes. - */ - if (isTiled(tif)) - *(tmsize_t*)tif->tif_data = TIFFTileRowSize(tif); - else - *(tmsize_t*)tif->tif_data = TIFFScanlineSize(tif); - return (1); -} - -static int -PackBitsPostEncode(TIFF* tif) -{ - if (tif->tif_data) - _TIFFfree(tif->tif_data); - return (1); -} - -/* - * Encode a run of pixels. - */ -static int -PackBitsEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) -{ - unsigned char* bp = (unsigned char*) buf; - uint8* op; - uint8* ep; - uint8* lastliteral; - long n, slop; - int b; - enum { BASE, LITERAL, RUN, LITERAL_RUN } state; - - (void) s; - op = tif->tif_rawcp; - ep = tif->tif_rawdata + tif->tif_rawdatasize; - state = BASE; - lastliteral = 0; - while (cc > 0) { - /* - * Find the longest string of identical bytes. - */ - b = *bp++, cc--, n = 1; - for (; cc > 0 && b == *bp; cc--, bp++) - n++; - again: - if (op + 2 >= ep) { /* insure space for new data */ - /* - * Be careful about writing the last - * literal. Must write up to that point - * and then copy the remainder to the - * front of the buffer. - */ - if (state == LITERAL || state == LITERAL_RUN) { - slop = (long)(op - lastliteral); - tif->tif_rawcc += (tmsize_t)(lastliteral - tif->tif_rawcp); - if (!TIFFFlushData1(tif)) - return (-1); - op = tif->tif_rawcp; - while (slop-- > 0) - *op++ = *lastliteral++; - lastliteral = tif->tif_rawcp; - } else { - tif->tif_rawcc += (tmsize_t)(op - tif->tif_rawcp); - if (!TIFFFlushData1(tif)) - return (-1); - op = tif->tif_rawcp; - } - } - switch (state) { - case BASE: /* initial state, set run/literal */ - if (n > 1) { - state = RUN; - if (n > 128) { - *op++ = (uint8) -127; - *op++ = (uint8) b; - n -= 128; - goto again; - } - *op++ = (uint8)(-(n-1)); - *op++ = (uint8) b; - } else { - lastliteral = op; - *op++ = 0; - *op++ = (uint8) b; - state = LITERAL; - } - break; - case LITERAL: /* last object was literal string */ - if (n > 1) { - state = LITERAL_RUN; - if (n > 128) { - *op++ = (uint8) -127; - *op++ = (uint8) b; - n -= 128; - goto again; - } - *op++ = (uint8)(-(n-1)); /* encode run */ - *op++ = (uint8) b; - } else { /* extend literal */ - if (++(*lastliteral) == 127) - state = BASE; - *op++ = (uint8) b; - } - break; - case RUN: /* last object was run */ - if (n > 1) { - if (n > 128) { - *op++ = (uint8) -127; - *op++ = (uint8) b; - n -= 128; - goto again; - } - *op++ = (uint8)(-(n-1)); - *op++ = (uint8) b; - } else { - lastliteral = op; - *op++ = 0; - *op++ = (uint8) b; - state = LITERAL; - } - break; - case LITERAL_RUN: /* literal followed by a run */ - /* - * Check to see if previous run should - * be converted to a literal, in which - * case we convert literal-run-literal - * to a single literal. - */ - if (n == 1 && op[-2] == (uint8) -1 && - *lastliteral < 126) { - state = (((*lastliteral) += 2) == 127 ? - BASE : LITERAL); - op[-2] = op[-1]; /* replicate */ - } else - state = RUN; - goto again; - } - } - tif->tif_rawcc += (tmsize_t)(op - tif->tif_rawcp); - tif->tif_rawcp = op; - return (1); -} - -/* - * Encode a rectangular chunk of pixels. We break it up - * into row-sized pieces to insure that encoded runs do - * not span rows. Otherwise, there can be problems with - * the decoder if data is read, for example, by scanlines - * when it was encoded by strips. - */ -static int -PackBitsEncodeChunk(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - tmsize_t rowsize = *(tmsize_t*)tif->tif_data; - - while (cc > 0) { - tmsize_t chunk = rowsize; - - if( cc < chunk ) - chunk = cc; - - if (PackBitsEncode(tif, bp, chunk, s) < 0) - return (-1); - bp += chunk; - cc -= chunk; - } - return (1); -} - -static int -PackBitsDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) -{ - static const char module[] = "PackBitsDecode"; - char *bp; - tmsize_t cc; - long n; - int b; - - (void) s; - bp = (char*) tif->tif_rawcp; - cc = tif->tif_rawcc; - while (cc > 0 && occ > 0) { - n = (long) *bp++, cc--; - /* - * Watch out for compilers that - * don't sign extend chars... - */ - if (n >= 128) - n -= 256; - if (n < 0) { /* replicate next byte -n+1 times */ - if (n == -128) /* nop */ - continue; - n = -n + 1; - if( occ < (tmsize_t)n ) - { - TIFFWarningExt(tif->tif_clientdata, module, - "Discarding %lu bytes to avoid buffer overrun", - (unsigned long) ((tmsize_t)n - occ)); - n = (long)occ; - } - occ -= n; - b = *bp++, cc--; - while (n-- > 0) - *op++ = (uint8) b; - } else { /* copy next n+1 bytes literally */ - if (occ < (tmsize_t)(n + 1)) - { - TIFFWarningExt(tif->tif_clientdata, module, - "Discarding %lu bytes to avoid buffer overrun", - (unsigned long) ((tmsize_t)n - occ + 1)); - n = (long)occ - 1; - } - if (cc < (tmsize_t) (n+1)) - { - TIFFWarningExt(tif->tif_clientdata, module, - "Terminating PackBitsDecode due to lack of data."); - break; - } - _TIFFmemcpy(op, bp, ++n); - op += n; occ -= n; - bp += n; cc -= n; - } - } - tif->tif_rawcp = (uint8*) bp; - tif->tif_rawcc = cc; - if (occ > 0) { - TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data for scanline %lu", - (unsigned long) tif->tif_row); - return (0); - } - return (1); -} - -int -TIFFInitPackBits(TIFF* tif, int scheme) -{ - (void) scheme; - tif->tif_decoderow = PackBitsDecode; - tif->tif_decodestrip = PackBitsDecode; - tif->tif_decodetile = PackBitsDecode; - tif->tif_preencode = PackBitsPreEncode; - tif->tif_postencode = PackBitsPostEncode; - tif->tif_encoderow = PackBitsEncode; - tif->tif_encodestrip = PackBitsEncodeChunk; - tif->tif_encodetile = PackBitsEncodeChunk; - return (1); -} -#endif /* PACKBITS_SUPPORT */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_packbits.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include "tiffiop.h" +#ifdef PACKBITS_SUPPORT +/* + * TIFF Library. + * + * PackBits Compression Algorithm Support + */ +#include + +static int +PackBitsPreEncode(TIFF* tif, uint16 s) +{ + (void) s; + + if (!(tif->tif_data = (uint8*)_TIFFmalloc(sizeof(tmsize_t)))) + return (0); + /* + * Calculate the scanline/tile-width size in bytes. + */ + if (isTiled(tif)) + *(tmsize_t*)tif->tif_data = TIFFTileRowSize(tif); + else + *(tmsize_t*)tif->tif_data = TIFFScanlineSize(tif); + return (1); +} + +static int +PackBitsPostEncode(TIFF* tif) +{ + if (tif->tif_data) + _TIFFfree(tif->tif_data); + return (1); +} + +/* + * Encode a run of pixels. + */ +static int +PackBitsEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) +{ + unsigned char* bp = (unsigned char*) buf; + uint8* op; + uint8* ep; + uint8* lastliteral; + long n, slop; + int b; + enum { BASE, LITERAL, RUN, LITERAL_RUN } state; + + (void) s; + op = tif->tif_rawcp; + ep = tif->tif_rawdata + tif->tif_rawdatasize; + state = BASE; + lastliteral = 0; + while (cc > 0) { + /* + * Find the longest string of identical bytes. + */ + b = *bp++, cc--, n = 1; + for (; cc > 0 && b == *bp; cc--, bp++) + n++; + again: + if (op + 2 >= ep) { /* insure space for new data */ + /* + * Be careful about writing the last + * literal. Must write up to that point + * and then copy the remainder to the + * front of the buffer. + */ + if (state == LITERAL || state == LITERAL_RUN) { + slop = (long)(op - lastliteral); + tif->tif_rawcc += (tmsize_t)(lastliteral - tif->tif_rawcp); + if (!TIFFFlushData1(tif)) + return (-1); + op = tif->tif_rawcp; + while (slop-- > 0) + *op++ = *lastliteral++; + lastliteral = tif->tif_rawcp; + } else { + tif->tif_rawcc += (tmsize_t)(op - tif->tif_rawcp); + if (!TIFFFlushData1(tif)) + return (-1); + op = tif->tif_rawcp; + } + } + switch (state) { + case BASE: /* initial state, set run/literal */ + if (n > 1) { + state = RUN; + if (n > 128) { + *op++ = (uint8) -127; + *op++ = (uint8) b; + n -= 128; + goto again; + } + *op++ = (uint8)(-(n-1)); + *op++ = (uint8) b; + } else { + lastliteral = op; + *op++ = 0; + *op++ = (uint8) b; + state = LITERAL; + } + break; + case LITERAL: /* last object was literal string */ + if (n > 1) { + state = LITERAL_RUN; + if (n > 128) { + *op++ = (uint8) -127; + *op++ = (uint8) b; + n -= 128; + goto again; + } + *op++ = (uint8)(-(n-1)); /* encode run */ + *op++ = (uint8) b; + } else { /* extend literal */ + if (++(*lastliteral) == 127) + state = BASE; + *op++ = (uint8) b; + } + break; + case RUN: /* last object was run */ + if (n > 1) { + if (n > 128) { + *op++ = (uint8) -127; + *op++ = (uint8) b; + n -= 128; + goto again; + } + *op++ = (uint8)(-(n-1)); + *op++ = (uint8) b; + } else { + lastliteral = op; + *op++ = 0; + *op++ = (uint8) b; + state = LITERAL; + } + break; + case LITERAL_RUN: /* literal followed by a run */ + /* + * Check to see if previous run should + * be converted to a literal, in which + * case we convert literal-run-literal + * to a single literal. + */ + if (n == 1 && op[-2] == (uint8) -1 && + *lastliteral < 126) { + state = (((*lastliteral) += 2) == 127 ? + BASE : LITERAL); + op[-2] = op[-1]; /* replicate */ + } else + state = RUN; + goto again; + } + } + tif->tif_rawcc += (tmsize_t)(op - tif->tif_rawcp); + tif->tif_rawcp = op; + return (1); +} + +/* + * Encode a rectangular chunk of pixels. We break it up + * into row-sized pieces to insure that encoded runs do + * not span rows. Otherwise, there can be problems with + * the decoder if data is read, for example, by scanlines + * when it was encoded by strips. + */ +static int +PackBitsEncodeChunk(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + tmsize_t rowsize = *(tmsize_t*)tif->tif_data; + + while (cc > 0) { + tmsize_t chunk = rowsize; + + if( cc < chunk ) + chunk = cc; + + if (PackBitsEncode(tif, bp, chunk, s) < 0) + return (-1); + bp += chunk; + cc -= chunk; + } + return (1); +} + +static int +PackBitsDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) +{ + static const char module[] = "PackBitsDecode"; + char *bp; + tmsize_t cc; + long n; + int b; + + (void) s; + bp = (char*) tif->tif_rawcp; + cc = tif->tif_rawcc; + while (cc > 0 && occ > 0) { + n = (long) *bp++, cc--; + /* + * Watch out for compilers that + * don't sign extend chars... + */ + if (n >= 128) + n -= 256; + if (n < 0) { /* replicate next byte -n+1 times */ + if (n == -128) /* nop */ + continue; + n = -n + 1; + if( occ < (tmsize_t)n ) + { + TIFFWarningExt(tif->tif_clientdata, module, + "Discarding %lu bytes to avoid buffer overrun", + (unsigned long) ((tmsize_t)n - occ)); + n = (long)occ; + } + occ -= n; + b = *bp++, cc--; + while (n-- > 0) + *op++ = (uint8) b; + } else { /* copy next n+1 bytes literally */ + if (occ < (tmsize_t)(n + 1)) + { + TIFFWarningExt(tif->tif_clientdata, module, + "Discarding %lu bytes to avoid buffer overrun", + (unsigned long) ((tmsize_t)n - occ + 1)); + n = (long)occ - 1; + } + if (cc < (tmsize_t) (n+1)) + { + TIFFWarningExt(tif->tif_clientdata, module, + "Terminating PackBitsDecode due to lack of data."); + break; + } + _TIFFmemcpy(op, bp, ++n); + op += n; occ -= n; + bp += n; cc -= n; + } + } + tif->tif_rawcp = (uint8*) bp; + tif->tif_rawcc = cc; + if (occ > 0) { + TIFFErrorExt(tif->tif_clientdata, module, + "Not enough data for scanline %lu", + (unsigned long) tif->tif_row); + return (0); + } + return (1); +} + +int +TIFFInitPackBits(TIFF* tif, int scheme) +{ + (void) scheme; + tif->tif_decoderow = PackBitsDecode; + tif->tif_decodestrip = PackBitsDecode; + tif->tif_decodetile = PackBitsDecode; + tif->tif_preencode = PackBitsPreEncode; + tif->tif_postencode = PackBitsPostEncode; + tif->tif_encoderow = PackBitsEncode; + tif->tif_encodestrip = PackBitsEncodeChunk; + tif->tif_encodetile = PackBitsEncodeChunk; + return (1); +} +#endif /* PACKBITS_SUPPORT */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_pixarlog.c b/Source/LibTIFF4/tif_pixarlog.c index 1a38d0d..0495b15 100644 --- a/Source/LibTIFF4/tif_pixarlog.c +++ b/Source/LibTIFF4/tif_pixarlog.c @@ -1,1426 +1,1426 @@ -/* $Id: tif_pixarlog.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1996-1997 Sam Leffler - * Copyright (c) 1996 Pixar - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Pixar, Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Pixar, Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL PIXAR, SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "tiffiop.h" -#ifdef PIXARLOG_SUPPORT - -/* - * TIFF Library. - * PixarLog Compression Support - * - * Contributed by Dan McCoy. - * - * PixarLog film support uses the TIFF library to store companded - * 11 bit values into a tiff file, which are compressed using the - * zip compressor. - * - * The codec can take as input and produce as output 32-bit IEEE float values - * as well as 16-bit or 8-bit unsigned integer values. - * - * On writing any of the above are converted into the internal - * 11-bit log format. In the case of 8 and 16 bit values, the - * input is assumed to be unsigned linear color values that represent - * the range 0-1. In the case of IEEE values, the 0-1 range is assumed to - * be the normal linear color range, in addition over 1 values are - * accepted up to a value of about 25.0 to encode "hot" hightlights and such. - * The encoding is lossless for 8-bit values, slightly lossy for the - * other bit depths. The actual color precision should be better - * than the human eye can perceive with extra room to allow for - * error introduced by further image computation. As with any quantized - * color format, it is possible to perform image calculations which - * expose the quantization error. This format should certainly be less - * susceptable to such errors than standard 8-bit encodings, but more - * susceptable than straight 16-bit or 32-bit encodings. - * - * On reading the internal format is converted to the desired output format. - * The program can request which format it desires by setting the internal - * pseudo tag TIFFTAG_PIXARLOGDATAFMT to one of these possible values: - * PIXARLOGDATAFMT_FLOAT = provide IEEE float values. - * PIXARLOGDATAFMT_16BIT = provide unsigned 16-bit integer values - * PIXARLOGDATAFMT_8BIT = provide unsigned 8-bit integer values - * - * alternately PIXARLOGDATAFMT_8BITABGR provides unsigned 8-bit integer - * values with the difference that if there are exactly three or four channels - * (rgb or rgba) it swaps the channel order (bgr or abgr). - * - * PIXARLOGDATAFMT_11BITLOG provides the internal encoding directly - * packed in 16-bit values. However no tools are supplied for interpreting - * these values. - * - * "hot" (over 1.0) areas written in floating point get clamped to - * 1.0 in the integer data types. - * - * When the file is closed after writing, the bit depth and sample format - * are set always to appear as if 8-bit data has been written into it. - * That way a naive program unaware of the particulars of the encoding - * gets the format it is most likely able to handle. - * - * The codec does it's own horizontal differencing step on the coded - * values so the libraries predictor stuff should be turned off. - * The codec also handle byte swapping the encoded values as necessary - * since the library does not have the information necessary - * to know the bit depth of the raw unencoded buffer. - * - * NOTE: This decoder does not appear to update tif_rawcp, and tif_rawcc. - * This can cause problems with the implementation of CHUNKY_STRIP_READ_SUPPORT - * as noted in http://trac.osgeo.org/gdal/ticket/3894. FrankW - Jan'11 - */ - -#include "tif_predict.h" -#include "../ZLib/zlib.h" - -#include -#include -#include - -/* Tables for converting to/from 11 bit coded values */ - -#define TSIZE 2048 /* decode table size (11-bit tokens) */ -#define TSIZEP1 2049 /* Plus one for slop */ -#define ONE 1250 /* token value of 1.0 exactly */ -#define RATIO 1.004 /* nominal ratio for log part */ - -#define CODE_MASK 0x7ff /* 11 bits. */ - -static float Fltsize; -static float LogK1, LogK2; - -#define REPEAT(n, op) { int i; i=n; do { i--; op; } while (i>0); } - -static void -horizontalAccumulateF(uint16 *wp, int n, int stride, float *op, - float *ToLinearF) -{ - register unsigned int cr, cg, cb, ca, mask; - register float t0, t1, t2, t3; - - if (n >= stride) { - mask = CODE_MASK; - if (stride == 3) { - t0 = ToLinearF[cr = (wp[0] & mask)]; - t1 = ToLinearF[cg = (wp[1] & mask)]; - t2 = ToLinearF[cb = (wp[2] & mask)]; - op[0] = t0; - op[1] = t1; - op[2] = t2; - n -= 3; - while (n > 0) { - wp += 3; - op += 3; - n -= 3; - t0 = ToLinearF[(cr += wp[0]) & mask]; - t1 = ToLinearF[(cg += wp[1]) & mask]; - t2 = ToLinearF[(cb += wp[2]) & mask]; - op[0] = t0; - op[1] = t1; - op[2] = t2; - } - } else if (stride == 4) { - t0 = ToLinearF[cr = (wp[0] & mask)]; - t1 = ToLinearF[cg = (wp[1] & mask)]; - t2 = ToLinearF[cb = (wp[2] & mask)]; - t3 = ToLinearF[ca = (wp[3] & mask)]; - op[0] = t0; - op[1] = t1; - op[2] = t2; - op[3] = t3; - n -= 4; - while (n > 0) { - wp += 4; - op += 4; - n -= 4; - t0 = ToLinearF[(cr += wp[0]) & mask]; - t1 = ToLinearF[(cg += wp[1]) & mask]; - t2 = ToLinearF[(cb += wp[2]) & mask]; - t3 = ToLinearF[(ca += wp[3]) & mask]; - op[0] = t0; - op[1] = t1; - op[2] = t2; - op[3] = t3; - } - } else { - REPEAT(stride, *op = ToLinearF[*wp&mask]; wp++; op++) - n -= stride; - while (n > 0) { - REPEAT(stride, - wp[stride] += *wp; *op = ToLinearF[*wp&mask]; wp++; op++) - n -= stride; - } - } - } -} - -static void -horizontalAccumulate12(uint16 *wp, int n, int stride, int16 *op, - float *ToLinearF) -{ - register unsigned int cr, cg, cb, ca, mask; - register float t0, t1, t2, t3; - -#define SCALE12 2048.0F -#define CLAMP12(t) (((t) < 3071) ? (uint16) (t) : 3071) - - if (n >= stride) { - mask = CODE_MASK; - if (stride == 3) { - t0 = ToLinearF[cr = (wp[0] & mask)] * SCALE12; - t1 = ToLinearF[cg = (wp[1] & mask)] * SCALE12; - t2 = ToLinearF[cb = (wp[2] & mask)] * SCALE12; - op[0] = CLAMP12(t0); - op[1] = CLAMP12(t1); - op[2] = CLAMP12(t2); - n -= 3; - while (n > 0) { - wp += 3; - op += 3; - n -= 3; - t0 = ToLinearF[(cr += wp[0]) & mask] * SCALE12; - t1 = ToLinearF[(cg += wp[1]) & mask] * SCALE12; - t2 = ToLinearF[(cb += wp[2]) & mask] * SCALE12; - op[0] = CLAMP12(t0); - op[1] = CLAMP12(t1); - op[2] = CLAMP12(t2); - } - } else if (stride == 4) { - t0 = ToLinearF[cr = (wp[0] & mask)] * SCALE12; - t1 = ToLinearF[cg = (wp[1] & mask)] * SCALE12; - t2 = ToLinearF[cb = (wp[2] & mask)] * SCALE12; - t3 = ToLinearF[ca = (wp[3] & mask)] * SCALE12; - op[0] = CLAMP12(t0); - op[1] = CLAMP12(t1); - op[2] = CLAMP12(t2); - op[3] = CLAMP12(t3); - n -= 4; - while (n > 0) { - wp += 4; - op += 4; - n -= 4; - t0 = ToLinearF[(cr += wp[0]) & mask] * SCALE12; - t1 = ToLinearF[(cg += wp[1]) & mask] * SCALE12; - t2 = ToLinearF[(cb += wp[2]) & mask] * SCALE12; - t3 = ToLinearF[(ca += wp[3]) & mask] * SCALE12; - op[0] = CLAMP12(t0); - op[1] = CLAMP12(t1); - op[2] = CLAMP12(t2); - op[3] = CLAMP12(t3); - } - } else { - REPEAT(stride, t0 = ToLinearF[*wp&mask] * SCALE12; - *op = CLAMP12(t0); wp++; op++) - n -= stride; - while (n > 0) { - REPEAT(stride, - wp[stride] += *wp; t0 = ToLinearF[wp[stride]&mask]*SCALE12; - *op = CLAMP12(t0); wp++; op++) - n -= stride; - } - } - } -} - -static void -horizontalAccumulate16(uint16 *wp, int n, int stride, uint16 *op, - uint16 *ToLinear16) -{ - register unsigned int cr, cg, cb, ca, mask; - - if (n >= stride) { - mask = CODE_MASK; - if (stride == 3) { - op[0] = ToLinear16[cr = (wp[0] & mask)]; - op[1] = ToLinear16[cg = (wp[1] & mask)]; - op[2] = ToLinear16[cb = (wp[2] & mask)]; - n -= 3; - while (n > 0) { - wp += 3; - op += 3; - n -= 3; - op[0] = ToLinear16[(cr += wp[0]) & mask]; - op[1] = ToLinear16[(cg += wp[1]) & mask]; - op[2] = ToLinear16[(cb += wp[2]) & mask]; - } - } else if (stride == 4) { - op[0] = ToLinear16[cr = (wp[0] & mask)]; - op[1] = ToLinear16[cg = (wp[1] & mask)]; - op[2] = ToLinear16[cb = (wp[2] & mask)]; - op[3] = ToLinear16[ca = (wp[3] & mask)]; - n -= 4; - while (n > 0) { - wp += 4; - op += 4; - n -= 4; - op[0] = ToLinear16[(cr += wp[0]) & mask]; - op[1] = ToLinear16[(cg += wp[1]) & mask]; - op[2] = ToLinear16[(cb += wp[2]) & mask]; - op[3] = ToLinear16[(ca += wp[3]) & mask]; - } - } else { - REPEAT(stride, *op = ToLinear16[*wp&mask]; wp++; op++) - n -= stride; - while (n > 0) { - REPEAT(stride, - wp[stride] += *wp; *op = ToLinear16[*wp&mask]; wp++; op++) - n -= stride; - } - } - } -} - -/* - * Returns the log encoded 11-bit values with the horizontal - * differencing undone. - */ -static void -horizontalAccumulate11(uint16 *wp, int n, int stride, uint16 *op) -{ - register unsigned int cr, cg, cb, ca, mask; - - if (n >= stride) { - mask = CODE_MASK; - if (stride == 3) { - op[0] = cr = wp[0]; op[1] = cg = wp[1]; op[2] = cb = wp[2]; - n -= 3; - while (n > 0) { - wp += 3; - op += 3; - n -= 3; - op[0] = (cr += wp[0]) & mask; - op[1] = (cg += wp[1]) & mask; - op[2] = (cb += wp[2]) & mask; - } - } else if (stride == 4) { - op[0] = cr = wp[0]; op[1] = cg = wp[1]; - op[2] = cb = wp[2]; op[3] = ca = wp[3]; - n -= 4; - while (n > 0) { - wp += 4; - op += 4; - n -= 4; - op[0] = (cr += wp[0]) & mask; - op[1] = (cg += wp[1]) & mask; - op[2] = (cb += wp[2]) & mask; - op[3] = (ca += wp[3]) & mask; - } - } else { - REPEAT(stride, *op = *wp&mask; wp++; op++) - n -= stride; - while (n > 0) { - REPEAT(stride, - wp[stride] += *wp; *op = *wp&mask; wp++; op++) - n -= stride; - } - } - } -} - -static void -horizontalAccumulate8(uint16 *wp, int n, int stride, unsigned char *op, - unsigned char *ToLinear8) -{ - register unsigned int cr, cg, cb, ca, mask; - - if (n >= stride) { - mask = CODE_MASK; - if (stride == 3) { - op[0] = ToLinear8[cr = (wp[0] & mask)]; - op[1] = ToLinear8[cg = (wp[1] & mask)]; - op[2] = ToLinear8[cb = (wp[2] & mask)]; - n -= 3; - while (n > 0) { - n -= 3; - wp += 3; - op += 3; - op[0] = ToLinear8[(cr += wp[0]) & mask]; - op[1] = ToLinear8[(cg += wp[1]) & mask]; - op[2] = ToLinear8[(cb += wp[2]) & mask]; - } - } else if (stride == 4) { - op[0] = ToLinear8[cr = (wp[0] & mask)]; - op[1] = ToLinear8[cg = (wp[1] & mask)]; - op[2] = ToLinear8[cb = (wp[2] & mask)]; - op[3] = ToLinear8[ca = (wp[3] & mask)]; - n -= 4; - while (n > 0) { - n -= 4; - wp += 4; - op += 4; - op[0] = ToLinear8[(cr += wp[0]) & mask]; - op[1] = ToLinear8[(cg += wp[1]) & mask]; - op[2] = ToLinear8[(cb += wp[2]) & mask]; - op[3] = ToLinear8[(ca += wp[3]) & mask]; - } - } else { - REPEAT(stride, *op = ToLinear8[*wp&mask]; wp++; op++) - n -= stride; - while (n > 0) { - REPEAT(stride, - wp[stride] += *wp; *op = ToLinear8[*wp&mask]; wp++; op++) - n -= stride; - } - } - } -} - - -static void -horizontalAccumulate8abgr(uint16 *wp, int n, int stride, unsigned char *op, - unsigned char *ToLinear8) -{ - register unsigned int cr, cg, cb, ca, mask; - register unsigned char t0, t1, t2, t3; - - if (n >= stride) { - mask = CODE_MASK; - if (stride == 3) { - op[0] = 0; - t1 = ToLinear8[cb = (wp[2] & mask)]; - t2 = ToLinear8[cg = (wp[1] & mask)]; - t3 = ToLinear8[cr = (wp[0] & mask)]; - op[1] = t1; - op[2] = t2; - op[3] = t3; - n -= 3; - while (n > 0) { - n -= 3; - wp += 3; - op += 4; - op[0] = 0; - t1 = ToLinear8[(cb += wp[2]) & mask]; - t2 = ToLinear8[(cg += wp[1]) & mask]; - t3 = ToLinear8[(cr += wp[0]) & mask]; - op[1] = t1; - op[2] = t2; - op[3] = t3; - } - } else if (stride == 4) { - t0 = ToLinear8[ca = (wp[3] & mask)]; - t1 = ToLinear8[cb = (wp[2] & mask)]; - t2 = ToLinear8[cg = (wp[1] & mask)]; - t3 = ToLinear8[cr = (wp[0] & mask)]; - op[0] = t0; - op[1] = t1; - op[2] = t2; - op[3] = t3; - n -= 4; - while (n > 0) { - n -= 4; - wp += 4; - op += 4; - t0 = ToLinear8[(ca += wp[3]) & mask]; - t1 = ToLinear8[(cb += wp[2]) & mask]; - t2 = ToLinear8[(cg += wp[1]) & mask]; - t3 = ToLinear8[(cr += wp[0]) & mask]; - op[0] = t0; - op[1] = t1; - op[2] = t2; - op[3] = t3; - } - } else { - REPEAT(stride, *op = ToLinear8[*wp&mask]; wp++; op++) - n -= stride; - while (n > 0) { - REPEAT(stride, - wp[stride] += *wp; *op = ToLinear8[*wp&mask]; wp++; op++) - n -= stride; - } - } - } -} - -/* - * State block for each open TIFF - * file using PixarLog compression/decompression. - */ -typedef struct { - TIFFPredictorState predict; - z_stream stream; - uint16 *tbuf; - uint16 stride; - int state; - int user_datafmt; - int quality; -#define PLSTATE_INIT 1 - - TIFFVSetMethod vgetparent; /* super-class method */ - TIFFVSetMethod vsetparent; /* super-class method */ - - float *ToLinearF; - uint16 *ToLinear16; - unsigned char *ToLinear8; - uint16 *FromLT2; - uint16 *From14; /* Really for 16-bit data, but we shift down 2 */ - uint16 *From8; - -} PixarLogState; - -static int -PixarLogMakeTables(PixarLogState *sp) -{ - -/* - * We make several tables here to convert between various external - * representations (float, 16-bit, and 8-bit) and the internal - * 11-bit companded representation. The 11-bit representation has two - * distinct regions. A linear bottom end up through .018316 in steps - * of about .000073, and a region of constant ratio up to about 25. - * These floating point numbers are stored in the main table ToLinearF. - * All other tables are derived from this one. The tables (and the - * ratios) are continuous at the internal seam. - */ - - int nlin, lt2size; - int i, j; - double b, c, linstep, v; - float *ToLinearF; - uint16 *ToLinear16; - unsigned char *ToLinear8; - uint16 *FromLT2; - uint16 *From14; /* Really for 16-bit data, but we shift down 2 */ - uint16 *From8; - - c = log(RATIO); - nlin = (int)(1./c); /* nlin must be an integer */ - c = 1./nlin; - b = exp(-c*ONE); /* multiplicative scale factor [b*exp(c*ONE) = 1] */ - linstep = b*c*exp(1.); - - LogK1 = (float)(1./c); /* if (v >= 2) token = k1*log(v*k2) */ - LogK2 = (float)(1./b); - lt2size = (int)(2./linstep) + 1; - FromLT2 = (uint16 *)_TIFFmalloc(lt2size*sizeof(uint16)); - From14 = (uint16 *)_TIFFmalloc(16384*sizeof(uint16)); - From8 = (uint16 *)_TIFFmalloc(256*sizeof(uint16)); - ToLinearF = (float *)_TIFFmalloc(TSIZEP1 * sizeof(float)); - ToLinear16 = (uint16 *)_TIFFmalloc(TSIZEP1 * sizeof(uint16)); - ToLinear8 = (unsigned char *)_TIFFmalloc(TSIZEP1 * sizeof(unsigned char)); - if (FromLT2 == NULL || From14 == NULL || From8 == NULL || - ToLinearF == NULL || ToLinear16 == NULL || ToLinear8 == NULL) { - if (FromLT2) _TIFFfree(FromLT2); - if (From14) _TIFFfree(From14); - if (From8) _TIFFfree(From8); - if (ToLinearF) _TIFFfree(ToLinearF); - if (ToLinear16) _TIFFfree(ToLinear16); - if (ToLinear8) _TIFFfree(ToLinear8); - sp->FromLT2 = NULL; - sp->From14 = NULL; - sp->From8 = NULL; - sp->ToLinearF = NULL; - sp->ToLinear16 = NULL; - sp->ToLinear8 = NULL; - return 0; - } - - j = 0; - - for (i = 0; i < nlin; i++) { - v = i * linstep; - ToLinearF[j++] = (float)v; - } - - for (i = nlin; i < TSIZE; i++) - ToLinearF[j++] = (float)(b*exp(c*i)); - - ToLinearF[2048] = ToLinearF[2047]; - - for (i = 0; i < TSIZEP1; i++) { - v = ToLinearF[i]*65535.0 + 0.5; - ToLinear16[i] = (v > 65535.0) ? 65535 : (uint16)v; - v = ToLinearF[i]*255.0 + 0.5; - ToLinear8[i] = (v > 255.0) ? 255 : (unsigned char)v; - } - - j = 0; - for (i = 0; i < lt2size; i++) { - if ((i*linstep)*(i*linstep) > ToLinearF[j]*ToLinearF[j+1]) - j++; - FromLT2[i] = j; - } - - /* - * Since we lose info anyway on 16-bit data, we set up a 14-bit - * table and shift 16-bit values down two bits on input. - * saves a little table space. - */ - j = 0; - for (i = 0; i < 16384; i++) { - while ((i/16383.)*(i/16383.) > ToLinearF[j]*ToLinearF[j+1]) - j++; - From14[i] = j; - } - - j = 0; - for (i = 0; i < 256; i++) { - while ((i/255.)*(i/255.) > ToLinearF[j]*ToLinearF[j+1]) - j++; - From8[i] = j; - } - - Fltsize = (float)(lt2size/2); - - sp->ToLinearF = ToLinearF; - sp->ToLinear16 = ToLinear16; - sp->ToLinear8 = ToLinear8; - sp->FromLT2 = FromLT2; - sp->From14 = From14; - sp->From8 = From8; - - return 1; -} - -#define DecoderState(tif) ((PixarLogState*) (tif)->tif_data) -#define EncoderState(tif) ((PixarLogState*) (tif)->tif_data) - -static int PixarLogEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s); -static int PixarLogDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s); - -#define PIXARLOGDATAFMT_UNKNOWN -1 - -static int -PixarLogGuessDataFmt(TIFFDirectory *td) -{ - int guess = PIXARLOGDATAFMT_UNKNOWN; - int format = td->td_sampleformat; - - /* If the user didn't tell us his datafmt, - * take our best guess from the bitspersample. - */ - switch (td->td_bitspersample) { - case 32: - if (format == SAMPLEFORMAT_IEEEFP) - guess = PIXARLOGDATAFMT_FLOAT; - break; - case 16: - if (format == SAMPLEFORMAT_VOID || format == SAMPLEFORMAT_UINT) - guess = PIXARLOGDATAFMT_16BIT; - break; - case 12: - if (format == SAMPLEFORMAT_VOID || format == SAMPLEFORMAT_INT) - guess = PIXARLOGDATAFMT_12BITPICIO; - break; - case 11: - if (format == SAMPLEFORMAT_VOID || format == SAMPLEFORMAT_UINT) - guess = PIXARLOGDATAFMT_11BITLOG; - break; - case 8: - if (format == SAMPLEFORMAT_VOID || format == SAMPLEFORMAT_UINT) - guess = PIXARLOGDATAFMT_8BIT; - break; - } - - return guess; -} - -static tmsize_t -multiply_ms(tmsize_t m1, tmsize_t m2) -{ - tmsize_t bytes = m1 * m2; - - if (m1 && bytes / m1 != m2) - bytes = 0; - - return bytes; -} - -static int -PixarLogFixupTags(TIFF* tif) -{ - (void) tif; - return (1); -} - -static int -PixarLogSetupDecode(TIFF* tif) -{ - static const char module[] = "PixarLogSetupDecode"; - TIFFDirectory *td = &tif->tif_dir; - PixarLogState* sp = DecoderState(tif); - tmsize_t tbuf_size; - - assert(sp != NULL); - - /* Make sure no byte swapping happens on the data - * after decompression. */ - tif->tif_postdecode = _TIFFNoPostDecode; - - /* for some reason, we can't do this in TIFFInitPixarLog */ - - sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ? - td->td_samplesperpixel : 1); - tbuf_size = multiply_ms(multiply_ms(multiply_ms(sp->stride, td->td_imagewidth), - td->td_rowsperstrip), sizeof(uint16)); - if (tbuf_size == 0) - return (0); /* TODO: this is an error return without error report through TIFFErrorExt */ - sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size+sizeof(uint16)*sp->stride); - if (sp->tbuf == NULL) - return (0); - if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) - sp->user_datafmt = PixarLogGuessDataFmt(td); - if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) { - TIFFErrorExt(tif->tif_clientdata, module, - "PixarLog compression can't handle bits depth/data format combination (depth: %d)", - td->td_bitspersample); - return (0); - } - - if (inflateInit(&sp->stream) != Z_OK) { - TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg); - return (0); - } else { - sp->state |= PLSTATE_INIT; - return (1); - } -} - -/* - * Setup state for decoding a strip. - */ -static int -PixarLogPreDecode(TIFF* tif, uint16 s) -{ - static const char module[] = "PixarLogPreDecode"; - PixarLogState* sp = DecoderState(tif); - - (void) s; - assert(sp != NULL); - sp->stream.next_in = tif->tif_rawdata; - assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised, - we need to simplify this code to reflect a ZLib that is likely updated - to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ - sp->stream.avail_in = (uInt) tif->tif_rawcc; - if ((tmsize_t)sp->stream.avail_in != tif->tif_rawcc) - { - TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); - return (0); - } - return (inflateReset(&sp->stream) == Z_OK); -} - -static int -PixarLogDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) -{ - static const char module[] = "PixarLogDecode"; - TIFFDirectory *td = &tif->tif_dir; - PixarLogState* sp = DecoderState(tif); - tmsize_t i; - tmsize_t nsamples; - int llen; - uint16 *up; - - switch (sp->user_datafmt) { - case PIXARLOGDATAFMT_FLOAT: - nsamples = occ / sizeof(float); /* XXX float == 32 bits */ - break; - case PIXARLOGDATAFMT_16BIT: - case PIXARLOGDATAFMT_12BITPICIO: - case PIXARLOGDATAFMT_11BITLOG: - nsamples = occ / sizeof(uint16); /* XXX uint16 == 16 bits */ - break; - case PIXARLOGDATAFMT_8BIT: - case PIXARLOGDATAFMT_8BITABGR: - nsamples = occ; - break; - default: - TIFFErrorExt(tif->tif_clientdata, module, - "%d bit input not supported in PixarLog", - td->td_bitspersample); - return 0; - } - - llen = sp->stride * td->td_imagewidth; - - (void) s; - assert(sp != NULL); - sp->stream.next_out = (unsigned char *) sp->tbuf; - assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, - we need to simplify this code to reflect a ZLib that is likely updated - to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ - sp->stream.avail_out = (uInt) (nsamples * sizeof(uint16)); - if (sp->stream.avail_out != nsamples * sizeof(uint16)) - { - TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); - return (0); - } - do { - int state = inflate(&sp->stream, Z_PARTIAL_FLUSH); - if (state == Z_STREAM_END) { - break; /* XXX */ - } - if (state == Z_DATA_ERROR) { - TIFFErrorExt(tif->tif_clientdata, module, - "Decoding error at scanline %lu, %s", - (unsigned long) tif->tif_row, sp->stream.msg); - if (inflateSync(&sp->stream) != Z_OK) - return (0); - continue; - } - if (state != Z_OK) { - TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", - sp->stream.msg); - return (0); - } - } while (sp->stream.avail_out > 0); - - /* hopefully, we got all the bytes we needed */ - if (sp->stream.avail_out != 0) { - TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data at scanline %lu (short " TIFF_UINT64_FORMAT " bytes)", - (unsigned long) tif->tif_row, (TIFF_UINT64_T) sp->stream.avail_out); - return (0); - } - - up = sp->tbuf; - /* Swap bytes in the data if from a different endian machine. */ - if (tif->tif_flags & TIFF_SWAB) - TIFFSwabArrayOfShort(up, nsamples); - - /* - * if llen is not an exact multiple of nsamples, the decode operation - * may overflow the output buffer, so truncate it enough to prevent - * that but still salvage as much data as possible. - */ - if (nsamples % llen) { - TIFFWarningExt(tif->tif_clientdata, module, - "stride %lu is not a multiple of sample count, " - "%lu, data truncated.", (unsigned long) llen, (unsigned long) nsamples); - nsamples -= nsamples % llen; - } - - for (i = 0; i < nsamples; i += llen, up += llen) { - switch (sp->user_datafmt) { - case PIXARLOGDATAFMT_FLOAT: - horizontalAccumulateF(up, llen, sp->stride, - (float *)op, sp->ToLinearF); - op += llen * sizeof(float); - break; - case PIXARLOGDATAFMT_16BIT: - horizontalAccumulate16(up, llen, sp->stride, - (uint16 *)op, sp->ToLinear16); - op += llen * sizeof(uint16); - break; - case PIXARLOGDATAFMT_12BITPICIO: - horizontalAccumulate12(up, llen, sp->stride, - (int16 *)op, sp->ToLinearF); - op += llen * sizeof(int16); - break; - case PIXARLOGDATAFMT_11BITLOG: - horizontalAccumulate11(up, llen, sp->stride, - (uint16 *)op); - op += llen * sizeof(uint16); - break; - case PIXARLOGDATAFMT_8BIT: - horizontalAccumulate8(up, llen, sp->stride, - (unsigned char *)op, sp->ToLinear8); - op += llen * sizeof(unsigned char); - break; - case PIXARLOGDATAFMT_8BITABGR: - horizontalAccumulate8abgr(up, llen, sp->stride, - (unsigned char *)op, sp->ToLinear8); - op += llen * sizeof(unsigned char); - break; - default: - TIFFErrorExt(tif->tif_clientdata, module, - "Unsupported bits/sample: %d", - td->td_bitspersample); - return (0); - } - } - - return (1); -} - -static int -PixarLogSetupEncode(TIFF* tif) -{ - static const char module[] = "PixarLogSetupEncode"; - TIFFDirectory *td = &tif->tif_dir; - PixarLogState* sp = EncoderState(tif); - tmsize_t tbuf_size; - - assert(sp != NULL); - - /* for some reason, we can't do this in TIFFInitPixarLog */ - - sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ? - td->td_samplesperpixel : 1); - tbuf_size = multiply_ms(multiply_ms(multiply_ms(sp->stride, td->td_imagewidth), - td->td_rowsperstrip), sizeof(uint16)); - if (tbuf_size == 0) - return (0); /* TODO: this is an error return without error report through TIFFErrorExt */ - sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size); - if (sp->tbuf == NULL) - return (0); - if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) - sp->user_datafmt = PixarLogGuessDataFmt(td); - if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) { - TIFFErrorExt(tif->tif_clientdata, module, "PixarLog compression can't handle %d bit linear encodings", td->td_bitspersample); - return (0); - } - - if (deflateInit(&sp->stream, sp->quality) != Z_OK) { - TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg); - return (0); - } else { - sp->state |= PLSTATE_INIT; - return (1); - } -} - -/* - * Reset encoding state at the start of a strip. - */ -static int -PixarLogPreEncode(TIFF* tif, uint16 s) -{ - static const char module[] = "PixarLogPreEncode"; - PixarLogState *sp = EncoderState(tif); - - (void) s; - assert(sp != NULL); - sp->stream.next_out = tif->tif_rawdata; - assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, - we need to simplify this code to reflect a ZLib that is likely updated - to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ - sp->stream.avail_out = tif->tif_rawdatasize; - if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) - { - TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); - return (0); - } - return (deflateReset(&sp->stream) == Z_OK); -} - -static void -horizontalDifferenceF(float *ip, int n, int stride, uint16 *wp, uint16 *FromLT2) -{ - int32 r1, g1, b1, a1, r2, g2, b2, a2, mask; - float fltsize = Fltsize; - -#define CLAMP(v) ( (v<(float)0.) ? 0 \ - : (v<(float)2.) ? FromLT2[(int)(v*fltsize)] \ - : (v>(float)24.2) ? 2047 \ - : LogK1*log(v*LogK2) + 0.5 ) - - mask = CODE_MASK; - if (n >= stride) { - if (stride == 3) { - r2 = wp[0] = (uint16) CLAMP(ip[0]); - g2 = wp[1] = (uint16) CLAMP(ip[1]); - b2 = wp[2] = (uint16) CLAMP(ip[2]); - n -= 3; - while (n > 0) { - n -= 3; - wp += 3; - ip += 3; - r1 = (int32) CLAMP(ip[0]); wp[0] = (r1-r2) & mask; r2 = r1; - g1 = (int32) CLAMP(ip[1]); wp[1] = (g1-g2) & mask; g2 = g1; - b1 = (int32) CLAMP(ip[2]); wp[2] = (b1-b2) & mask; b2 = b1; - } - } else if (stride == 4) { - r2 = wp[0] = (uint16) CLAMP(ip[0]); - g2 = wp[1] = (uint16) CLAMP(ip[1]); - b2 = wp[2] = (uint16) CLAMP(ip[2]); - a2 = wp[3] = (uint16) CLAMP(ip[3]); - n -= 4; - while (n > 0) { - n -= 4; - wp += 4; - ip += 4; - r1 = (int32) CLAMP(ip[0]); wp[0] = (r1-r2) & mask; r2 = r1; - g1 = (int32) CLAMP(ip[1]); wp[1] = (g1-g2) & mask; g2 = g1; - b1 = (int32) CLAMP(ip[2]); wp[2] = (b1-b2) & mask; b2 = b1; - a1 = (int32) CLAMP(ip[3]); wp[3] = (a1-a2) & mask; a2 = a1; - } - } else { - ip += n - 1; /* point to last one */ - wp += n - 1; /* point to last one */ - n -= stride; - while (n > 0) { - REPEAT(stride, wp[0] = (uint16) CLAMP(ip[0]); - wp[stride] -= wp[0]; - wp[stride] &= mask; - wp--; ip--) - n -= stride; - } - REPEAT(stride, wp[0] = (uint16) CLAMP(ip[0]); wp--; ip--) - } - } -} - -static void -horizontalDifference16(unsigned short *ip, int n, int stride, - unsigned short *wp, uint16 *From14) -{ - register int r1, g1, b1, a1, r2, g2, b2, a2, mask; - -/* assumption is unsigned pixel values */ -#undef CLAMP -#define CLAMP(v) From14[(v) >> 2] - - mask = CODE_MASK; - if (n >= stride) { - if (stride == 3) { - r2 = wp[0] = CLAMP(ip[0]); g2 = wp[1] = CLAMP(ip[1]); - b2 = wp[2] = CLAMP(ip[2]); - n -= 3; - while (n > 0) { - n -= 3; - wp += 3; - ip += 3; - r1 = CLAMP(ip[0]); wp[0] = (r1-r2) & mask; r2 = r1; - g1 = CLAMP(ip[1]); wp[1] = (g1-g2) & mask; g2 = g1; - b1 = CLAMP(ip[2]); wp[2] = (b1-b2) & mask; b2 = b1; - } - } else if (stride == 4) { - r2 = wp[0] = CLAMP(ip[0]); g2 = wp[1] = CLAMP(ip[1]); - b2 = wp[2] = CLAMP(ip[2]); a2 = wp[3] = CLAMP(ip[3]); - n -= 4; - while (n > 0) { - n -= 4; - wp += 4; - ip += 4; - r1 = CLAMP(ip[0]); wp[0] = (r1-r2) & mask; r2 = r1; - g1 = CLAMP(ip[1]); wp[1] = (g1-g2) & mask; g2 = g1; - b1 = CLAMP(ip[2]); wp[2] = (b1-b2) & mask; b2 = b1; - a1 = CLAMP(ip[3]); wp[3] = (a1-a2) & mask; a2 = a1; - } - } else { - ip += n - 1; /* point to last one */ - wp += n - 1; /* point to last one */ - n -= stride; - while (n > 0) { - REPEAT(stride, wp[0] = CLAMP(ip[0]); - wp[stride] -= wp[0]; - wp[stride] &= mask; - wp--; ip--) - n -= stride; - } - REPEAT(stride, wp[0] = CLAMP(ip[0]); wp--; ip--) - } - } -} - - -static void -horizontalDifference8(unsigned char *ip, int n, int stride, - unsigned short *wp, uint16 *From8) -{ - register int r1, g1, b1, a1, r2, g2, b2, a2, mask; - -#undef CLAMP -#define CLAMP(v) (From8[(v)]) - - mask = CODE_MASK; - if (n >= stride) { - if (stride == 3) { - r2 = wp[0] = CLAMP(ip[0]); g2 = wp[1] = CLAMP(ip[1]); - b2 = wp[2] = CLAMP(ip[2]); - n -= 3; - while (n > 0) { - n -= 3; - r1 = CLAMP(ip[3]); wp[3] = (r1-r2) & mask; r2 = r1; - g1 = CLAMP(ip[4]); wp[4] = (g1-g2) & mask; g2 = g1; - b1 = CLAMP(ip[5]); wp[5] = (b1-b2) & mask; b2 = b1; - wp += 3; - ip += 3; - } - } else if (stride == 4) { - r2 = wp[0] = CLAMP(ip[0]); g2 = wp[1] = CLAMP(ip[1]); - b2 = wp[2] = CLAMP(ip[2]); a2 = wp[3] = CLAMP(ip[3]); - n -= 4; - while (n > 0) { - n -= 4; - r1 = CLAMP(ip[4]); wp[4] = (r1-r2) & mask; r2 = r1; - g1 = CLAMP(ip[5]); wp[5] = (g1-g2) & mask; g2 = g1; - b1 = CLAMP(ip[6]); wp[6] = (b1-b2) & mask; b2 = b1; - a1 = CLAMP(ip[7]); wp[7] = (a1-a2) & mask; a2 = a1; - wp += 4; - ip += 4; - } - } else { - wp += n + stride - 1; /* point to last one */ - ip += n + stride - 1; /* point to last one */ - n -= stride; - while (n > 0) { - REPEAT(stride, wp[0] = CLAMP(ip[0]); - wp[stride] -= wp[0]; - wp[stride] &= mask; - wp--; ip--) - n -= stride; - } - REPEAT(stride, wp[0] = CLAMP(ip[0]); wp--; ip--) - } - } -} - -/* - * Encode a chunk of pixels. - */ -static int -PixarLogEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - static const char module[] = "PixarLogEncode"; - TIFFDirectory *td = &tif->tif_dir; - PixarLogState *sp = EncoderState(tif); - tmsize_t i; - tmsize_t n; - int llen; - unsigned short * up; - - (void) s; - - switch (sp->user_datafmt) { - case PIXARLOGDATAFMT_FLOAT: - n = cc / sizeof(float); /* XXX float == 32 bits */ - break; - case PIXARLOGDATAFMT_16BIT: - case PIXARLOGDATAFMT_12BITPICIO: - case PIXARLOGDATAFMT_11BITLOG: - n = cc / sizeof(uint16); /* XXX uint16 == 16 bits */ - break; - case PIXARLOGDATAFMT_8BIT: - case PIXARLOGDATAFMT_8BITABGR: - n = cc; - break; - default: - TIFFErrorExt(tif->tif_clientdata, module, - "%d bit input not supported in PixarLog", - td->td_bitspersample); - return 0; - } - - llen = sp->stride * td->td_imagewidth; - - for (i = 0, up = sp->tbuf; i < n; i += llen, up += llen) { - switch (sp->user_datafmt) { - case PIXARLOGDATAFMT_FLOAT: - horizontalDifferenceF((float *)bp, llen, - sp->stride, up, sp->FromLT2); - bp += llen * sizeof(float); - break; - case PIXARLOGDATAFMT_16BIT: - horizontalDifference16((uint16 *)bp, llen, - sp->stride, up, sp->From14); - bp += llen * sizeof(uint16); - break; - case PIXARLOGDATAFMT_8BIT: - horizontalDifference8((unsigned char *)bp, llen, - sp->stride, up, sp->From8); - bp += llen * sizeof(unsigned char); - break; - default: - TIFFErrorExt(tif->tif_clientdata, module, - "%d bit input not supported in PixarLog", - td->td_bitspersample); - return 0; - } - } - - sp->stream.next_in = (unsigned char *) sp->tbuf; - assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised, - we need to simplify this code to reflect a ZLib that is likely updated - to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ - sp->stream.avail_in = (uInt) (n * sizeof(uint16)); - if ((sp->stream.avail_in / sizeof(uint16)) != (uInt) n) - { - TIFFErrorExt(tif->tif_clientdata, module, - "ZLib cannot deal with buffers this size"); - return (0); - } - - do { - if (deflate(&sp->stream, Z_NO_FLUSH) != Z_OK) { - TIFFErrorExt(tif->tif_clientdata, module, "Encoder error: %s", - sp->stream.msg); - return (0); - } - if (sp->stream.avail_out == 0) { - tif->tif_rawcc = tif->tif_rawdatasize; - TIFFFlushData1(tif); - sp->stream.next_out = tif->tif_rawdata; - sp->stream.avail_out = (uInt) tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in PixarLogPreEncode */ - } - } while (sp->stream.avail_in > 0); - return (1); -} - -/* - * Finish off an encoded strip by flushing the last - * string and tacking on an End Of Information code. - */ - -static int -PixarLogPostEncode(TIFF* tif) -{ - static const char module[] = "PixarLogPostEncode"; - PixarLogState *sp = EncoderState(tif); - int state; - - sp->stream.avail_in = 0; - - do { - state = deflate(&sp->stream, Z_FINISH); - switch (state) { - case Z_STREAM_END: - case Z_OK: - if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) { - tif->tif_rawcc = - tif->tif_rawdatasize - sp->stream.avail_out; - TIFFFlushData1(tif); - sp->stream.next_out = tif->tif_rawdata; - sp->stream.avail_out = (uInt) tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in PixarLogPreEncode */ - } - break; - default: - TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", - sp->stream.msg); - return (0); - } - } while (state != Z_STREAM_END); - return (1); -} - -static void -PixarLogClose(TIFF* tif) -{ - TIFFDirectory *td = &tif->tif_dir; - - /* In a really sneaky (and really incorrect, and untruthfull, and - * troublesome, and error-prone) maneuver that completely goes against - * the spirit of TIFF, and breaks TIFF, on close, we covertly - * modify both bitspersample and sampleformat in the directory to - * indicate 8-bit linear. This way, the decode "just works" even for - * readers that don't know about PixarLog, or how to set - * the PIXARLOGDATFMT pseudo-tag. - */ - td->td_bitspersample = 8; - td->td_sampleformat = SAMPLEFORMAT_UINT; -} - -static void -PixarLogCleanup(TIFF* tif) -{ - PixarLogState* sp = (PixarLogState*) tif->tif_data; - - assert(sp != 0); - - (void)TIFFPredictorCleanup(tif); - - tif->tif_tagmethods.vgetfield = sp->vgetparent; - tif->tif_tagmethods.vsetfield = sp->vsetparent; - - if (sp->FromLT2) _TIFFfree(sp->FromLT2); - if (sp->From14) _TIFFfree(sp->From14); - if (sp->From8) _TIFFfree(sp->From8); - if (sp->ToLinearF) _TIFFfree(sp->ToLinearF); - if (sp->ToLinear16) _TIFFfree(sp->ToLinear16); - if (sp->ToLinear8) _TIFFfree(sp->ToLinear8); - if (sp->state&PLSTATE_INIT) { - if (tif->tif_mode == O_RDONLY) - inflateEnd(&sp->stream); - else - deflateEnd(&sp->stream); - } - if (sp->tbuf) - _TIFFfree(sp->tbuf); - _TIFFfree(sp); - tif->tif_data = NULL; - - _TIFFSetDefaultCompressionState(tif); -} - -static int -PixarLogVSetField(TIFF* tif, uint32 tag, va_list ap) -{ - static const char module[] = "PixarLogVSetField"; - PixarLogState *sp = (PixarLogState *)tif->tif_data; - int result; - - switch (tag) { - case TIFFTAG_PIXARLOGQUALITY: - sp->quality = (int) va_arg(ap, int); - if (tif->tif_mode != O_RDONLY && (sp->state&PLSTATE_INIT)) { - if (deflateParams(&sp->stream, - sp->quality, Z_DEFAULT_STRATEGY) != Z_OK) { - TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", - sp->stream.msg); - return (0); - } - } - return (1); - case TIFFTAG_PIXARLOGDATAFMT: - sp->user_datafmt = (int) va_arg(ap, int); - /* Tweak the TIFF header so that the rest of libtiff knows what - * size of data will be passed between app and library, and - * assume that the app knows what it is doing and is not - * confused by these header manipulations... - */ - switch (sp->user_datafmt) { - case PIXARLOGDATAFMT_8BIT: - case PIXARLOGDATAFMT_8BITABGR: - TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); - TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT); - break; - case PIXARLOGDATAFMT_11BITLOG: - TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16); - TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT); - break; - case PIXARLOGDATAFMT_12BITPICIO: - TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16); - TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_INT); - break; - case PIXARLOGDATAFMT_16BIT: - TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16); - TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT); - break; - case PIXARLOGDATAFMT_FLOAT: - TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 32); - TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP); - break; - } - /* - * Must recalculate sizes should bits/sample change. - */ - tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tmsize_t)(-1); - tif->tif_scanlinesize = TIFFScanlineSize(tif); - result = 1; /* NB: pseudo tag */ - break; - default: - result = (*sp->vsetparent)(tif, tag, ap); - } - return (result); -} - -static int -PixarLogVGetField(TIFF* tif, uint32 tag, va_list ap) -{ - PixarLogState *sp = (PixarLogState *)tif->tif_data; - - switch (tag) { - case TIFFTAG_PIXARLOGQUALITY: - *va_arg(ap, int*) = sp->quality; - break; - case TIFFTAG_PIXARLOGDATAFMT: - *va_arg(ap, int*) = sp->user_datafmt; - break; - default: - return (*sp->vgetparent)(tif, tag, ap); - } - return (1); -} - -static const TIFFField pixarlogFields[] = { - {TIFFTAG_PIXARLOGDATAFMT, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "", NULL}, - {TIFFTAG_PIXARLOGQUALITY, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "", NULL} -}; - -int -TIFFInitPixarLog(TIFF* tif, int scheme) -{ - static const char module[] = "TIFFInitPixarLog"; - - PixarLogState* sp; - - assert(scheme == COMPRESSION_PIXARLOG); - - /* - * Merge codec-specific tag information. - */ - if (!_TIFFMergeFields(tif, pixarlogFields, - TIFFArrayCount(pixarlogFields))) { - TIFFErrorExt(tif->tif_clientdata, module, - "Merging PixarLog codec-specific tags failed"); - return 0; - } - - /* - * Allocate state block so tag methods have storage to record values. - */ - tif->tif_data = (uint8*) _TIFFmalloc(sizeof (PixarLogState)); - if (tif->tif_data == NULL) - goto bad; - sp = (PixarLogState*) tif->tif_data; - _TIFFmemset(sp, 0, sizeof (*sp)); - sp->stream.data_type = Z_BINARY; - sp->user_datafmt = PIXARLOGDATAFMT_UNKNOWN; - - /* - * Install codec methods. - */ - tif->tif_fixuptags = PixarLogFixupTags; - tif->tif_setupdecode = PixarLogSetupDecode; - tif->tif_predecode = PixarLogPreDecode; - tif->tif_decoderow = PixarLogDecode; - tif->tif_decodestrip = PixarLogDecode; - tif->tif_decodetile = PixarLogDecode; - tif->tif_setupencode = PixarLogSetupEncode; - tif->tif_preencode = PixarLogPreEncode; - tif->tif_postencode = PixarLogPostEncode; - tif->tif_encoderow = PixarLogEncode; - tif->tif_encodestrip = PixarLogEncode; - tif->tif_encodetile = PixarLogEncode; - tif->tif_close = PixarLogClose; - tif->tif_cleanup = PixarLogCleanup; - - /* Override SetField so we can handle our private pseudo-tag */ - sp->vgetparent = tif->tif_tagmethods.vgetfield; - tif->tif_tagmethods.vgetfield = PixarLogVGetField; /* hook for codec tags */ - sp->vsetparent = tif->tif_tagmethods.vsetfield; - tif->tif_tagmethods.vsetfield = PixarLogVSetField; /* hook for codec tags */ - - /* Default values for codec-specific fields */ - sp->quality = Z_DEFAULT_COMPRESSION; /* default comp. level */ - sp->state = 0; - - /* we don't wish to use the predictor, - * the default is none, which predictor value 1 - */ - (void) TIFFPredictorInit(tif); - - /* - * build the companding tables - */ - PixarLogMakeTables(sp); - - return (1); -bad: - TIFFErrorExt(tif->tif_clientdata, module, - "No space for PixarLog state block"); - return (0); -} -#endif /* PIXARLOG_SUPPORT */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_pixarlog.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1996-1997 Sam Leffler + * Copyright (c) 1996 Pixar + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Pixar, Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Pixar, Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL PIXAR, SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include "tiffiop.h" +#ifdef PIXARLOG_SUPPORT + +/* + * TIFF Library. + * PixarLog Compression Support + * + * Contributed by Dan McCoy. + * + * PixarLog film support uses the TIFF library to store companded + * 11 bit values into a tiff file, which are compressed using the + * zip compressor. + * + * The codec can take as input and produce as output 32-bit IEEE float values + * as well as 16-bit or 8-bit unsigned integer values. + * + * On writing any of the above are converted into the internal + * 11-bit log format. In the case of 8 and 16 bit values, the + * input is assumed to be unsigned linear color values that represent + * the range 0-1. In the case of IEEE values, the 0-1 range is assumed to + * be the normal linear color range, in addition over 1 values are + * accepted up to a value of about 25.0 to encode "hot" hightlights and such. + * The encoding is lossless for 8-bit values, slightly lossy for the + * other bit depths. The actual color precision should be better + * than the human eye can perceive with extra room to allow for + * error introduced by further image computation. As with any quantized + * color format, it is possible to perform image calculations which + * expose the quantization error. This format should certainly be less + * susceptable to such errors than standard 8-bit encodings, but more + * susceptable than straight 16-bit or 32-bit encodings. + * + * On reading the internal format is converted to the desired output format. + * The program can request which format it desires by setting the internal + * pseudo tag TIFFTAG_PIXARLOGDATAFMT to one of these possible values: + * PIXARLOGDATAFMT_FLOAT = provide IEEE float values. + * PIXARLOGDATAFMT_16BIT = provide unsigned 16-bit integer values + * PIXARLOGDATAFMT_8BIT = provide unsigned 8-bit integer values + * + * alternately PIXARLOGDATAFMT_8BITABGR provides unsigned 8-bit integer + * values with the difference that if there are exactly three or four channels + * (rgb or rgba) it swaps the channel order (bgr or abgr). + * + * PIXARLOGDATAFMT_11BITLOG provides the internal encoding directly + * packed in 16-bit values. However no tools are supplied for interpreting + * these values. + * + * "hot" (over 1.0) areas written in floating point get clamped to + * 1.0 in the integer data types. + * + * When the file is closed after writing, the bit depth and sample format + * are set always to appear as if 8-bit data has been written into it. + * That way a naive program unaware of the particulars of the encoding + * gets the format it is most likely able to handle. + * + * The codec does it's own horizontal differencing step on the coded + * values so the libraries predictor stuff should be turned off. + * The codec also handle byte swapping the encoded values as necessary + * since the library does not have the information necessary + * to know the bit depth of the raw unencoded buffer. + * + * NOTE: This decoder does not appear to update tif_rawcp, and tif_rawcc. + * This can cause problems with the implementation of CHUNKY_STRIP_READ_SUPPORT + * as noted in http://trac.osgeo.org/gdal/ticket/3894. FrankW - Jan'11 + */ + +#include "tif_predict.h" +#include "../ZLib/zlib.h" + +#include +#include +#include + +/* Tables for converting to/from 11 bit coded values */ + +#define TSIZE 2048 /* decode table size (11-bit tokens) */ +#define TSIZEP1 2049 /* Plus one for slop */ +#define ONE 1250 /* token value of 1.0 exactly */ +#define RATIO 1.004 /* nominal ratio for log part */ + +#define CODE_MASK 0x7ff /* 11 bits. */ + +static float Fltsize; +static float LogK1, LogK2; + +#define REPEAT(n, op) { int i; i=n; do { i--; op; } while (i>0); } + +static void +horizontalAccumulateF(uint16 *wp, int n, int stride, float *op, + float *ToLinearF) +{ + register unsigned int cr, cg, cb, ca, mask; + register float t0, t1, t2, t3; + + if (n >= stride) { + mask = CODE_MASK; + if (stride == 3) { + t0 = ToLinearF[cr = (wp[0] & mask)]; + t1 = ToLinearF[cg = (wp[1] & mask)]; + t2 = ToLinearF[cb = (wp[2] & mask)]; + op[0] = t0; + op[1] = t1; + op[2] = t2; + n -= 3; + while (n > 0) { + wp += 3; + op += 3; + n -= 3; + t0 = ToLinearF[(cr += wp[0]) & mask]; + t1 = ToLinearF[(cg += wp[1]) & mask]; + t2 = ToLinearF[(cb += wp[2]) & mask]; + op[0] = t0; + op[1] = t1; + op[2] = t2; + } + } else if (stride == 4) { + t0 = ToLinearF[cr = (wp[0] & mask)]; + t1 = ToLinearF[cg = (wp[1] & mask)]; + t2 = ToLinearF[cb = (wp[2] & mask)]; + t3 = ToLinearF[ca = (wp[3] & mask)]; + op[0] = t0; + op[1] = t1; + op[2] = t2; + op[3] = t3; + n -= 4; + while (n > 0) { + wp += 4; + op += 4; + n -= 4; + t0 = ToLinearF[(cr += wp[0]) & mask]; + t1 = ToLinearF[(cg += wp[1]) & mask]; + t2 = ToLinearF[(cb += wp[2]) & mask]; + t3 = ToLinearF[(ca += wp[3]) & mask]; + op[0] = t0; + op[1] = t1; + op[2] = t2; + op[3] = t3; + } + } else { + REPEAT(stride, *op = ToLinearF[*wp&mask]; wp++; op++) + n -= stride; + while (n > 0) { + REPEAT(stride, + wp[stride] += *wp; *op = ToLinearF[*wp&mask]; wp++; op++) + n -= stride; + } + } + } +} + +static void +horizontalAccumulate12(uint16 *wp, int n, int stride, int16 *op, + float *ToLinearF) +{ + register unsigned int cr, cg, cb, ca, mask; + register float t0, t1, t2, t3; + +#define SCALE12 2048.0F +#define CLAMP12(t) (((t) < 3071) ? (uint16) (t) : 3071) + + if (n >= stride) { + mask = CODE_MASK; + if (stride == 3) { + t0 = ToLinearF[cr = (wp[0] & mask)] * SCALE12; + t1 = ToLinearF[cg = (wp[1] & mask)] * SCALE12; + t2 = ToLinearF[cb = (wp[2] & mask)] * SCALE12; + op[0] = CLAMP12(t0); + op[1] = CLAMP12(t1); + op[2] = CLAMP12(t2); + n -= 3; + while (n > 0) { + wp += 3; + op += 3; + n -= 3; + t0 = ToLinearF[(cr += wp[0]) & mask] * SCALE12; + t1 = ToLinearF[(cg += wp[1]) & mask] * SCALE12; + t2 = ToLinearF[(cb += wp[2]) & mask] * SCALE12; + op[0] = CLAMP12(t0); + op[1] = CLAMP12(t1); + op[2] = CLAMP12(t2); + } + } else if (stride == 4) { + t0 = ToLinearF[cr = (wp[0] & mask)] * SCALE12; + t1 = ToLinearF[cg = (wp[1] & mask)] * SCALE12; + t2 = ToLinearF[cb = (wp[2] & mask)] * SCALE12; + t3 = ToLinearF[ca = (wp[3] & mask)] * SCALE12; + op[0] = CLAMP12(t0); + op[1] = CLAMP12(t1); + op[2] = CLAMP12(t2); + op[3] = CLAMP12(t3); + n -= 4; + while (n > 0) { + wp += 4; + op += 4; + n -= 4; + t0 = ToLinearF[(cr += wp[0]) & mask] * SCALE12; + t1 = ToLinearF[(cg += wp[1]) & mask] * SCALE12; + t2 = ToLinearF[(cb += wp[2]) & mask] * SCALE12; + t3 = ToLinearF[(ca += wp[3]) & mask] * SCALE12; + op[0] = CLAMP12(t0); + op[1] = CLAMP12(t1); + op[2] = CLAMP12(t2); + op[3] = CLAMP12(t3); + } + } else { + REPEAT(stride, t0 = ToLinearF[*wp&mask] * SCALE12; + *op = CLAMP12(t0); wp++; op++) + n -= stride; + while (n > 0) { + REPEAT(stride, + wp[stride] += *wp; t0 = ToLinearF[wp[stride]&mask]*SCALE12; + *op = CLAMP12(t0); wp++; op++) + n -= stride; + } + } + } +} + +static void +horizontalAccumulate16(uint16 *wp, int n, int stride, uint16 *op, + uint16 *ToLinear16) +{ + register unsigned int cr, cg, cb, ca, mask; + + if (n >= stride) { + mask = CODE_MASK; + if (stride == 3) { + op[0] = ToLinear16[cr = (wp[0] & mask)]; + op[1] = ToLinear16[cg = (wp[1] & mask)]; + op[2] = ToLinear16[cb = (wp[2] & mask)]; + n -= 3; + while (n > 0) { + wp += 3; + op += 3; + n -= 3; + op[0] = ToLinear16[(cr += wp[0]) & mask]; + op[1] = ToLinear16[(cg += wp[1]) & mask]; + op[2] = ToLinear16[(cb += wp[2]) & mask]; + } + } else if (stride == 4) { + op[0] = ToLinear16[cr = (wp[0] & mask)]; + op[1] = ToLinear16[cg = (wp[1] & mask)]; + op[2] = ToLinear16[cb = (wp[2] & mask)]; + op[3] = ToLinear16[ca = (wp[3] & mask)]; + n -= 4; + while (n > 0) { + wp += 4; + op += 4; + n -= 4; + op[0] = ToLinear16[(cr += wp[0]) & mask]; + op[1] = ToLinear16[(cg += wp[1]) & mask]; + op[2] = ToLinear16[(cb += wp[2]) & mask]; + op[3] = ToLinear16[(ca += wp[3]) & mask]; + } + } else { + REPEAT(stride, *op = ToLinear16[*wp&mask]; wp++; op++) + n -= stride; + while (n > 0) { + REPEAT(stride, + wp[stride] += *wp; *op = ToLinear16[*wp&mask]; wp++; op++) + n -= stride; + } + } + } +} + +/* + * Returns the log encoded 11-bit values with the horizontal + * differencing undone. + */ +static void +horizontalAccumulate11(uint16 *wp, int n, int stride, uint16 *op) +{ + register unsigned int cr, cg, cb, ca, mask; + + if (n >= stride) { + mask = CODE_MASK; + if (stride == 3) { + op[0] = cr = wp[0]; op[1] = cg = wp[1]; op[2] = cb = wp[2]; + n -= 3; + while (n > 0) { + wp += 3; + op += 3; + n -= 3; + op[0] = (cr += wp[0]) & mask; + op[1] = (cg += wp[1]) & mask; + op[2] = (cb += wp[2]) & mask; + } + } else if (stride == 4) { + op[0] = cr = wp[0]; op[1] = cg = wp[1]; + op[2] = cb = wp[2]; op[3] = ca = wp[3]; + n -= 4; + while (n > 0) { + wp += 4; + op += 4; + n -= 4; + op[0] = (cr += wp[0]) & mask; + op[1] = (cg += wp[1]) & mask; + op[2] = (cb += wp[2]) & mask; + op[3] = (ca += wp[3]) & mask; + } + } else { + REPEAT(stride, *op = *wp&mask; wp++; op++) + n -= stride; + while (n > 0) { + REPEAT(stride, + wp[stride] += *wp; *op = *wp&mask; wp++; op++) + n -= stride; + } + } + } +} + +static void +horizontalAccumulate8(uint16 *wp, int n, int stride, unsigned char *op, + unsigned char *ToLinear8) +{ + register unsigned int cr, cg, cb, ca, mask; + + if (n >= stride) { + mask = CODE_MASK; + if (stride == 3) { + op[0] = ToLinear8[cr = (wp[0] & mask)]; + op[1] = ToLinear8[cg = (wp[1] & mask)]; + op[2] = ToLinear8[cb = (wp[2] & mask)]; + n -= 3; + while (n > 0) { + n -= 3; + wp += 3; + op += 3; + op[0] = ToLinear8[(cr += wp[0]) & mask]; + op[1] = ToLinear8[(cg += wp[1]) & mask]; + op[2] = ToLinear8[(cb += wp[2]) & mask]; + } + } else if (stride == 4) { + op[0] = ToLinear8[cr = (wp[0] & mask)]; + op[1] = ToLinear8[cg = (wp[1] & mask)]; + op[2] = ToLinear8[cb = (wp[2] & mask)]; + op[3] = ToLinear8[ca = (wp[3] & mask)]; + n -= 4; + while (n > 0) { + n -= 4; + wp += 4; + op += 4; + op[0] = ToLinear8[(cr += wp[0]) & mask]; + op[1] = ToLinear8[(cg += wp[1]) & mask]; + op[2] = ToLinear8[(cb += wp[2]) & mask]; + op[3] = ToLinear8[(ca += wp[3]) & mask]; + } + } else { + REPEAT(stride, *op = ToLinear8[*wp&mask]; wp++; op++) + n -= stride; + while (n > 0) { + REPEAT(stride, + wp[stride] += *wp; *op = ToLinear8[*wp&mask]; wp++; op++) + n -= stride; + } + } + } +} + + +static void +horizontalAccumulate8abgr(uint16 *wp, int n, int stride, unsigned char *op, + unsigned char *ToLinear8) +{ + register unsigned int cr, cg, cb, ca, mask; + register unsigned char t0, t1, t2, t3; + + if (n >= stride) { + mask = CODE_MASK; + if (stride == 3) { + op[0] = 0; + t1 = ToLinear8[cb = (wp[2] & mask)]; + t2 = ToLinear8[cg = (wp[1] & mask)]; + t3 = ToLinear8[cr = (wp[0] & mask)]; + op[1] = t1; + op[2] = t2; + op[3] = t3; + n -= 3; + while (n > 0) { + n -= 3; + wp += 3; + op += 4; + op[0] = 0; + t1 = ToLinear8[(cb += wp[2]) & mask]; + t2 = ToLinear8[(cg += wp[1]) & mask]; + t3 = ToLinear8[(cr += wp[0]) & mask]; + op[1] = t1; + op[2] = t2; + op[3] = t3; + } + } else if (stride == 4) { + t0 = ToLinear8[ca = (wp[3] & mask)]; + t1 = ToLinear8[cb = (wp[2] & mask)]; + t2 = ToLinear8[cg = (wp[1] & mask)]; + t3 = ToLinear8[cr = (wp[0] & mask)]; + op[0] = t0; + op[1] = t1; + op[2] = t2; + op[3] = t3; + n -= 4; + while (n > 0) { + n -= 4; + wp += 4; + op += 4; + t0 = ToLinear8[(ca += wp[3]) & mask]; + t1 = ToLinear8[(cb += wp[2]) & mask]; + t2 = ToLinear8[(cg += wp[1]) & mask]; + t3 = ToLinear8[(cr += wp[0]) & mask]; + op[0] = t0; + op[1] = t1; + op[2] = t2; + op[3] = t3; + } + } else { + REPEAT(stride, *op = ToLinear8[*wp&mask]; wp++; op++) + n -= stride; + while (n > 0) { + REPEAT(stride, + wp[stride] += *wp; *op = ToLinear8[*wp&mask]; wp++; op++) + n -= stride; + } + } + } +} + +/* + * State block for each open TIFF + * file using PixarLog compression/decompression. + */ +typedef struct { + TIFFPredictorState predict; + z_stream stream; + uint16 *tbuf; + uint16 stride; + int state; + int user_datafmt; + int quality; +#define PLSTATE_INIT 1 + + TIFFVSetMethod vgetparent; /* super-class method */ + TIFFVSetMethod vsetparent; /* super-class method */ + + float *ToLinearF; + uint16 *ToLinear16; + unsigned char *ToLinear8; + uint16 *FromLT2; + uint16 *From14; /* Really for 16-bit data, but we shift down 2 */ + uint16 *From8; + +} PixarLogState; + +static int +PixarLogMakeTables(PixarLogState *sp) +{ + +/* + * We make several tables here to convert between various external + * representations (float, 16-bit, and 8-bit) and the internal + * 11-bit companded representation. The 11-bit representation has two + * distinct regions. A linear bottom end up through .018316 in steps + * of about .000073, and a region of constant ratio up to about 25. + * These floating point numbers are stored in the main table ToLinearF. + * All other tables are derived from this one. The tables (and the + * ratios) are continuous at the internal seam. + */ + + int nlin, lt2size; + int i, j; + double b, c, linstep, v; + float *ToLinearF; + uint16 *ToLinear16; + unsigned char *ToLinear8; + uint16 *FromLT2; + uint16 *From14; /* Really for 16-bit data, but we shift down 2 */ + uint16 *From8; + + c = log(RATIO); + nlin = (int)(1./c); /* nlin must be an integer */ + c = 1./nlin; + b = exp(-c*ONE); /* multiplicative scale factor [b*exp(c*ONE) = 1] */ + linstep = b*c*exp(1.); + + LogK1 = (float)(1./c); /* if (v >= 2) token = k1*log(v*k2) */ + LogK2 = (float)(1./b); + lt2size = (int)(2./linstep) + 1; + FromLT2 = (uint16 *)_TIFFmalloc(lt2size*sizeof(uint16)); + From14 = (uint16 *)_TIFFmalloc(16384*sizeof(uint16)); + From8 = (uint16 *)_TIFFmalloc(256*sizeof(uint16)); + ToLinearF = (float *)_TIFFmalloc(TSIZEP1 * sizeof(float)); + ToLinear16 = (uint16 *)_TIFFmalloc(TSIZEP1 * sizeof(uint16)); + ToLinear8 = (unsigned char *)_TIFFmalloc(TSIZEP1 * sizeof(unsigned char)); + if (FromLT2 == NULL || From14 == NULL || From8 == NULL || + ToLinearF == NULL || ToLinear16 == NULL || ToLinear8 == NULL) { + if (FromLT2) _TIFFfree(FromLT2); + if (From14) _TIFFfree(From14); + if (From8) _TIFFfree(From8); + if (ToLinearF) _TIFFfree(ToLinearF); + if (ToLinear16) _TIFFfree(ToLinear16); + if (ToLinear8) _TIFFfree(ToLinear8); + sp->FromLT2 = NULL; + sp->From14 = NULL; + sp->From8 = NULL; + sp->ToLinearF = NULL; + sp->ToLinear16 = NULL; + sp->ToLinear8 = NULL; + return 0; + } + + j = 0; + + for (i = 0; i < nlin; i++) { + v = i * linstep; + ToLinearF[j++] = (float)v; + } + + for (i = nlin; i < TSIZE; i++) + ToLinearF[j++] = (float)(b*exp(c*i)); + + ToLinearF[2048] = ToLinearF[2047]; + + for (i = 0; i < TSIZEP1; i++) { + v = ToLinearF[i]*65535.0 + 0.5; + ToLinear16[i] = (v > 65535.0) ? 65535 : (uint16)v; + v = ToLinearF[i]*255.0 + 0.5; + ToLinear8[i] = (v > 255.0) ? 255 : (unsigned char)v; + } + + j = 0; + for (i = 0; i < lt2size; i++) { + if ((i*linstep)*(i*linstep) > ToLinearF[j]*ToLinearF[j+1]) + j++; + FromLT2[i] = j; + } + + /* + * Since we lose info anyway on 16-bit data, we set up a 14-bit + * table and shift 16-bit values down two bits on input. + * saves a little table space. + */ + j = 0; + for (i = 0; i < 16384; i++) { + while ((i/16383.)*(i/16383.) > ToLinearF[j]*ToLinearF[j+1]) + j++; + From14[i] = j; + } + + j = 0; + for (i = 0; i < 256; i++) { + while ((i/255.)*(i/255.) > ToLinearF[j]*ToLinearF[j+1]) + j++; + From8[i] = j; + } + + Fltsize = (float)(lt2size/2); + + sp->ToLinearF = ToLinearF; + sp->ToLinear16 = ToLinear16; + sp->ToLinear8 = ToLinear8; + sp->FromLT2 = FromLT2; + sp->From14 = From14; + sp->From8 = From8; + + return 1; +} + +#define DecoderState(tif) ((PixarLogState*) (tif)->tif_data) +#define EncoderState(tif) ((PixarLogState*) (tif)->tif_data) + +static int PixarLogEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s); +static int PixarLogDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s); + +#define PIXARLOGDATAFMT_UNKNOWN -1 + +static int +PixarLogGuessDataFmt(TIFFDirectory *td) +{ + int guess = PIXARLOGDATAFMT_UNKNOWN; + int format = td->td_sampleformat; + + /* If the user didn't tell us his datafmt, + * take our best guess from the bitspersample. + */ + switch (td->td_bitspersample) { + case 32: + if (format == SAMPLEFORMAT_IEEEFP) + guess = PIXARLOGDATAFMT_FLOAT; + break; + case 16: + if (format == SAMPLEFORMAT_VOID || format == SAMPLEFORMAT_UINT) + guess = PIXARLOGDATAFMT_16BIT; + break; + case 12: + if (format == SAMPLEFORMAT_VOID || format == SAMPLEFORMAT_INT) + guess = PIXARLOGDATAFMT_12BITPICIO; + break; + case 11: + if (format == SAMPLEFORMAT_VOID || format == SAMPLEFORMAT_UINT) + guess = PIXARLOGDATAFMT_11BITLOG; + break; + case 8: + if (format == SAMPLEFORMAT_VOID || format == SAMPLEFORMAT_UINT) + guess = PIXARLOGDATAFMT_8BIT; + break; + } + + return guess; +} + +static tmsize_t +multiply_ms(tmsize_t m1, tmsize_t m2) +{ + tmsize_t bytes = m1 * m2; + + if (m1 && bytes / m1 != m2) + bytes = 0; + + return bytes; +} + +static int +PixarLogFixupTags(TIFF* tif) +{ + (void) tif; + return (1); +} + +static int +PixarLogSetupDecode(TIFF* tif) +{ + static const char module[] = "PixarLogSetupDecode"; + TIFFDirectory *td = &tif->tif_dir; + PixarLogState* sp = DecoderState(tif); + tmsize_t tbuf_size; + + assert(sp != NULL); + + /* Make sure no byte swapping happens on the data + * after decompression. */ + tif->tif_postdecode = _TIFFNoPostDecode; + + /* for some reason, we can't do this in TIFFInitPixarLog */ + + sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ? + td->td_samplesperpixel : 1); + tbuf_size = multiply_ms(multiply_ms(multiply_ms(sp->stride, td->td_imagewidth), + td->td_rowsperstrip), sizeof(uint16)); + if (tbuf_size == 0) + return (0); /* TODO: this is an error return without error report through TIFFErrorExt */ + sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size+sizeof(uint16)*sp->stride); + if (sp->tbuf == NULL) + return (0); + if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) + sp->user_datafmt = PixarLogGuessDataFmt(td); + if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) { + TIFFErrorExt(tif->tif_clientdata, module, + "PixarLog compression can't handle bits depth/data format combination (depth: %d)", + td->td_bitspersample); + return (0); + } + + if (inflateInit(&sp->stream) != Z_OK) { + TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg); + return (0); + } else { + sp->state |= PLSTATE_INIT; + return (1); + } +} + +/* + * Setup state for decoding a strip. + */ +static int +PixarLogPreDecode(TIFF* tif, uint16 s) +{ + static const char module[] = "PixarLogPreDecode"; + PixarLogState* sp = DecoderState(tif); + + (void) s; + assert(sp != NULL); + sp->stream.next_in = tif->tif_rawdata; + assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised, + we need to simplify this code to reflect a ZLib that is likely updated + to deal with 8byte memory sizes, though this code will respond + apropriately even before we simplify it */ + sp->stream.avail_in = (uInt) tif->tif_rawcc; + if ((tmsize_t)sp->stream.avail_in != tif->tif_rawcc) + { + TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); + return (0); + } + return (inflateReset(&sp->stream) == Z_OK); +} + +static int +PixarLogDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) +{ + static const char module[] = "PixarLogDecode"; + TIFFDirectory *td = &tif->tif_dir; + PixarLogState* sp = DecoderState(tif); + tmsize_t i; + tmsize_t nsamples; + int llen; + uint16 *up; + + switch (sp->user_datafmt) { + case PIXARLOGDATAFMT_FLOAT: + nsamples = occ / sizeof(float); /* XXX float == 32 bits */ + break; + case PIXARLOGDATAFMT_16BIT: + case PIXARLOGDATAFMT_12BITPICIO: + case PIXARLOGDATAFMT_11BITLOG: + nsamples = occ / sizeof(uint16); /* XXX uint16 == 16 bits */ + break; + case PIXARLOGDATAFMT_8BIT: + case PIXARLOGDATAFMT_8BITABGR: + nsamples = occ; + break; + default: + TIFFErrorExt(tif->tif_clientdata, module, + "%d bit input not supported in PixarLog", + td->td_bitspersample); + return 0; + } + + llen = sp->stride * td->td_imagewidth; + + (void) s; + assert(sp != NULL); + sp->stream.next_out = (unsigned char *) sp->tbuf; + assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, + we need to simplify this code to reflect a ZLib that is likely updated + to deal with 8byte memory sizes, though this code will respond + apropriately even before we simplify it */ + sp->stream.avail_out = (uInt) (nsamples * sizeof(uint16)); + if (sp->stream.avail_out != nsamples * sizeof(uint16)) + { + TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); + return (0); + } + do { + int state = inflate(&sp->stream, Z_PARTIAL_FLUSH); + if (state == Z_STREAM_END) { + break; /* XXX */ + } + if (state == Z_DATA_ERROR) { + TIFFErrorExt(tif->tif_clientdata, module, + "Decoding error at scanline %lu, %s", + (unsigned long) tif->tif_row, sp->stream.msg); + if (inflateSync(&sp->stream) != Z_OK) + return (0); + continue; + } + if (state != Z_OK) { + TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", + sp->stream.msg); + return (0); + } + } while (sp->stream.avail_out > 0); + + /* hopefully, we got all the bytes we needed */ + if (sp->stream.avail_out != 0) { + TIFFErrorExt(tif->tif_clientdata, module, + "Not enough data at scanline %lu (short " TIFF_UINT64_FORMAT " bytes)", + (unsigned long) tif->tif_row, (TIFF_UINT64_T) sp->stream.avail_out); + return (0); + } + + up = sp->tbuf; + /* Swap bytes in the data if from a different endian machine. */ + if (tif->tif_flags & TIFF_SWAB) + TIFFSwabArrayOfShort(up, nsamples); + + /* + * if llen is not an exact multiple of nsamples, the decode operation + * may overflow the output buffer, so truncate it enough to prevent + * that but still salvage as much data as possible. + */ + if (nsamples % llen) { + TIFFWarningExt(tif->tif_clientdata, module, + "stride %lu is not a multiple of sample count, " + "%lu, data truncated.", (unsigned long) llen, (unsigned long) nsamples); + nsamples -= nsamples % llen; + } + + for (i = 0; i < nsamples; i += llen, up += llen) { + switch (sp->user_datafmt) { + case PIXARLOGDATAFMT_FLOAT: + horizontalAccumulateF(up, llen, sp->stride, + (float *)op, sp->ToLinearF); + op += llen * sizeof(float); + break; + case PIXARLOGDATAFMT_16BIT: + horizontalAccumulate16(up, llen, sp->stride, + (uint16 *)op, sp->ToLinear16); + op += llen * sizeof(uint16); + break; + case PIXARLOGDATAFMT_12BITPICIO: + horizontalAccumulate12(up, llen, sp->stride, + (int16 *)op, sp->ToLinearF); + op += llen * sizeof(int16); + break; + case PIXARLOGDATAFMT_11BITLOG: + horizontalAccumulate11(up, llen, sp->stride, + (uint16 *)op); + op += llen * sizeof(uint16); + break; + case PIXARLOGDATAFMT_8BIT: + horizontalAccumulate8(up, llen, sp->stride, + (unsigned char *)op, sp->ToLinear8); + op += llen * sizeof(unsigned char); + break; + case PIXARLOGDATAFMT_8BITABGR: + horizontalAccumulate8abgr(up, llen, sp->stride, + (unsigned char *)op, sp->ToLinear8); + op += llen * sizeof(unsigned char); + break; + default: + TIFFErrorExt(tif->tif_clientdata, module, + "Unsupported bits/sample: %d", + td->td_bitspersample); + return (0); + } + } + + return (1); +} + +static int +PixarLogSetupEncode(TIFF* tif) +{ + static const char module[] = "PixarLogSetupEncode"; + TIFFDirectory *td = &tif->tif_dir; + PixarLogState* sp = EncoderState(tif); + tmsize_t tbuf_size; + + assert(sp != NULL); + + /* for some reason, we can't do this in TIFFInitPixarLog */ + + sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ? + td->td_samplesperpixel : 1); + tbuf_size = multiply_ms(multiply_ms(multiply_ms(sp->stride, td->td_imagewidth), + td->td_rowsperstrip), sizeof(uint16)); + if (tbuf_size == 0) + return (0); /* TODO: this is an error return without error report through TIFFErrorExt */ + sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size); + if (sp->tbuf == NULL) + return (0); + if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) + sp->user_datafmt = PixarLogGuessDataFmt(td); + if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) { + TIFFErrorExt(tif->tif_clientdata, module, "PixarLog compression can't handle %d bit linear encodings", td->td_bitspersample); + return (0); + } + + if (deflateInit(&sp->stream, sp->quality) != Z_OK) { + TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg); + return (0); + } else { + sp->state |= PLSTATE_INIT; + return (1); + } +} + +/* + * Reset encoding state at the start of a strip. + */ +static int +PixarLogPreEncode(TIFF* tif, uint16 s) +{ + static const char module[] = "PixarLogPreEncode"; + PixarLogState *sp = EncoderState(tif); + + (void) s; + assert(sp != NULL); + sp->stream.next_out = tif->tif_rawdata; + assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, + we need to simplify this code to reflect a ZLib that is likely updated + to deal with 8byte memory sizes, though this code will respond + apropriately even before we simplify it */ + sp->stream.avail_out = tif->tif_rawdatasize; + if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) + { + TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); + return (0); + } + return (deflateReset(&sp->stream) == Z_OK); +} + +static void +horizontalDifferenceF(float *ip, int n, int stride, uint16 *wp, uint16 *FromLT2) +{ + int32 r1, g1, b1, a1, r2, g2, b2, a2, mask; + float fltsize = Fltsize; + +#define CLAMP(v) ( (v<(float)0.) ? 0 \ + : (v<(float)2.) ? FromLT2[(int)(v*fltsize)] \ + : (v>(float)24.2) ? 2047 \ + : LogK1*log(v*LogK2) + 0.5 ) + + mask = CODE_MASK; + if (n >= stride) { + if (stride == 3) { + r2 = wp[0] = (uint16) CLAMP(ip[0]); + g2 = wp[1] = (uint16) CLAMP(ip[1]); + b2 = wp[2] = (uint16) CLAMP(ip[2]); + n -= 3; + while (n > 0) { + n -= 3; + wp += 3; + ip += 3; + r1 = (int32) CLAMP(ip[0]); wp[0] = (r1-r2) & mask; r2 = r1; + g1 = (int32) CLAMP(ip[1]); wp[1] = (g1-g2) & mask; g2 = g1; + b1 = (int32) CLAMP(ip[2]); wp[2] = (b1-b2) & mask; b2 = b1; + } + } else if (stride == 4) { + r2 = wp[0] = (uint16) CLAMP(ip[0]); + g2 = wp[1] = (uint16) CLAMP(ip[1]); + b2 = wp[2] = (uint16) CLAMP(ip[2]); + a2 = wp[3] = (uint16) CLAMP(ip[3]); + n -= 4; + while (n > 0) { + n -= 4; + wp += 4; + ip += 4; + r1 = (int32) CLAMP(ip[0]); wp[0] = (r1-r2) & mask; r2 = r1; + g1 = (int32) CLAMP(ip[1]); wp[1] = (g1-g2) & mask; g2 = g1; + b1 = (int32) CLAMP(ip[2]); wp[2] = (b1-b2) & mask; b2 = b1; + a1 = (int32) CLAMP(ip[3]); wp[3] = (a1-a2) & mask; a2 = a1; + } + } else { + ip += n - 1; /* point to last one */ + wp += n - 1; /* point to last one */ + n -= stride; + while (n > 0) { + REPEAT(stride, wp[0] = (uint16) CLAMP(ip[0]); + wp[stride] -= wp[0]; + wp[stride] &= mask; + wp--; ip--) + n -= stride; + } + REPEAT(stride, wp[0] = (uint16) CLAMP(ip[0]); wp--; ip--) + } + } +} + +static void +horizontalDifference16(unsigned short *ip, int n, int stride, + unsigned short *wp, uint16 *From14) +{ + register int r1, g1, b1, a1, r2, g2, b2, a2, mask; + +/* assumption is unsigned pixel values */ +#undef CLAMP +#define CLAMP(v) From14[(v) >> 2] + + mask = CODE_MASK; + if (n >= stride) { + if (stride == 3) { + r2 = wp[0] = CLAMP(ip[0]); g2 = wp[1] = CLAMP(ip[1]); + b2 = wp[2] = CLAMP(ip[2]); + n -= 3; + while (n > 0) { + n -= 3; + wp += 3; + ip += 3; + r1 = CLAMP(ip[0]); wp[0] = (r1-r2) & mask; r2 = r1; + g1 = CLAMP(ip[1]); wp[1] = (g1-g2) & mask; g2 = g1; + b1 = CLAMP(ip[2]); wp[2] = (b1-b2) & mask; b2 = b1; + } + } else if (stride == 4) { + r2 = wp[0] = CLAMP(ip[0]); g2 = wp[1] = CLAMP(ip[1]); + b2 = wp[2] = CLAMP(ip[2]); a2 = wp[3] = CLAMP(ip[3]); + n -= 4; + while (n > 0) { + n -= 4; + wp += 4; + ip += 4; + r1 = CLAMP(ip[0]); wp[0] = (r1-r2) & mask; r2 = r1; + g1 = CLAMP(ip[1]); wp[1] = (g1-g2) & mask; g2 = g1; + b1 = CLAMP(ip[2]); wp[2] = (b1-b2) & mask; b2 = b1; + a1 = CLAMP(ip[3]); wp[3] = (a1-a2) & mask; a2 = a1; + } + } else { + ip += n - 1; /* point to last one */ + wp += n - 1; /* point to last one */ + n -= stride; + while (n > 0) { + REPEAT(stride, wp[0] = CLAMP(ip[0]); + wp[stride] -= wp[0]; + wp[stride] &= mask; + wp--; ip--) + n -= stride; + } + REPEAT(stride, wp[0] = CLAMP(ip[0]); wp--; ip--) + } + } +} + + +static void +horizontalDifference8(unsigned char *ip, int n, int stride, + unsigned short *wp, uint16 *From8) +{ + register int r1, g1, b1, a1, r2, g2, b2, a2, mask; + +#undef CLAMP +#define CLAMP(v) (From8[(v)]) + + mask = CODE_MASK; + if (n >= stride) { + if (stride == 3) { + r2 = wp[0] = CLAMP(ip[0]); g2 = wp[1] = CLAMP(ip[1]); + b2 = wp[2] = CLAMP(ip[2]); + n -= 3; + while (n > 0) { + n -= 3; + r1 = CLAMP(ip[3]); wp[3] = (r1-r2) & mask; r2 = r1; + g1 = CLAMP(ip[4]); wp[4] = (g1-g2) & mask; g2 = g1; + b1 = CLAMP(ip[5]); wp[5] = (b1-b2) & mask; b2 = b1; + wp += 3; + ip += 3; + } + } else if (stride == 4) { + r2 = wp[0] = CLAMP(ip[0]); g2 = wp[1] = CLAMP(ip[1]); + b2 = wp[2] = CLAMP(ip[2]); a2 = wp[3] = CLAMP(ip[3]); + n -= 4; + while (n > 0) { + n -= 4; + r1 = CLAMP(ip[4]); wp[4] = (r1-r2) & mask; r2 = r1; + g1 = CLAMP(ip[5]); wp[5] = (g1-g2) & mask; g2 = g1; + b1 = CLAMP(ip[6]); wp[6] = (b1-b2) & mask; b2 = b1; + a1 = CLAMP(ip[7]); wp[7] = (a1-a2) & mask; a2 = a1; + wp += 4; + ip += 4; + } + } else { + wp += n + stride - 1; /* point to last one */ + ip += n + stride - 1; /* point to last one */ + n -= stride; + while (n > 0) { + REPEAT(stride, wp[0] = CLAMP(ip[0]); + wp[stride] -= wp[0]; + wp[stride] &= mask; + wp--; ip--) + n -= stride; + } + REPEAT(stride, wp[0] = CLAMP(ip[0]); wp--; ip--) + } + } +} + +/* + * Encode a chunk of pixels. + */ +static int +PixarLogEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + static const char module[] = "PixarLogEncode"; + TIFFDirectory *td = &tif->tif_dir; + PixarLogState *sp = EncoderState(tif); + tmsize_t i; + tmsize_t n; + int llen; + unsigned short * up; + + (void) s; + + switch (sp->user_datafmt) { + case PIXARLOGDATAFMT_FLOAT: + n = cc / sizeof(float); /* XXX float == 32 bits */ + break; + case PIXARLOGDATAFMT_16BIT: + case PIXARLOGDATAFMT_12BITPICIO: + case PIXARLOGDATAFMT_11BITLOG: + n = cc / sizeof(uint16); /* XXX uint16 == 16 bits */ + break; + case PIXARLOGDATAFMT_8BIT: + case PIXARLOGDATAFMT_8BITABGR: + n = cc; + break; + default: + TIFFErrorExt(tif->tif_clientdata, module, + "%d bit input not supported in PixarLog", + td->td_bitspersample); + return 0; + } + + llen = sp->stride * td->td_imagewidth; + + for (i = 0, up = sp->tbuf; i < n; i += llen, up += llen) { + switch (sp->user_datafmt) { + case PIXARLOGDATAFMT_FLOAT: + horizontalDifferenceF((float *)bp, llen, + sp->stride, up, sp->FromLT2); + bp += llen * sizeof(float); + break; + case PIXARLOGDATAFMT_16BIT: + horizontalDifference16((uint16 *)bp, llen, + sp->stride, up, sp->From14); + bp += llen * sizeof(uint16); + break; + case PIXARLOGDATAFMT_8BIT: + horizontalDifference8((unsigned char *)bp, llen, + sp->stride, up, sp->From8); + bp += llen * sizeof(unsigned char); + break; + default: + TIFFErrorExt(tif->tif_clientdata, module, + "%d bit input not supported in PixarLog", + td->td_bitspersample); + return 0; + } + } + + sp->stream.next_in = (unsigned char *) sp->tbuf; + assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised, + we need to simplify this code to reflect a ZLib that is likely updated + to deal with 8byte memory sizes, though this code will respond + apropriately even before we simplify it */ + sp->stream.avail_in = (uInt) (n * sizeof(uint16)); + if ((sp->stream.avail_in / sizeof(uint16)) != (uInt) n) + { + TIFFErrorExt(tif->tif_clientdata, module, + "ZLib cannot deal with buffers this size"); + return (0); + } + + do { + if (deflate(&sp->stream, Z_NO_FLUSH) != Z_OK) { + TIFFErrorExt(tif->tif_clientdata, module, "Encoder error: %s", + sp->stream.msg); + return (0); + } + if (sp->stream.avail_out == 0) { + tif->tif_rawcc = tif->tif_rawdatasize; + TIFFFlushData1(tif); + sp->stream.next_out = tif->tif_rawdata; + sp->stream.avail_out = (uInt) tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in PixarLogPreEncode */ + } + } while (sp->stream.avail_in > 0); + return (1); +} + +/* + * Finish off an encoded strip by flushing the last + * string and tacking on an End Of Information code. + */ + +static int +PixarLogPostEncode(TIFF* tif) +{ + static const char module[] = "PixarLogPostEncode"; + PixarLogState *sp = EncoderState(tif); + int state; + + sp->stream.avail_in = 0; + + do { + state = deflate(&sp->stream, Z_FINISH); + switch (state) { + case Z_STREAM_END: + case Z_OK: + if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) { + tif->tif_rawcc = + tif->tif_rawdatasize - sp->stream.avail_out; + TIFFFlushData1(tif); + sp->stream.next_out = tif->tif_rawdata; + sp->stream.avail_out = (uInt) tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in PixarLogPreEncode */ + } + break; + default: + TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", + sp->stream.msg); + return (0); + } + } while (state != Z_STREAM_END); + return (1); +} + +static void +PixarLogClose(TIFF* tif) +{ + TIFFDirectory *td = &tif->tif_dir; + + /* In a really sneaky (and really incorrect, and untruthfull, and + * troublesome, and error-prone) maneuver that completely goes against + * the spirit of TIFF, and breaks TIFF, on close, we covertly + * modify both bitspersample and sampleformat in the directory to + * indicate 8-bit linear. This way, the decode "just works" even for + * readers that don't know about PixarLog, or how to set + * the PIXARLOGDATFMT pseudo-tag. + */ + td->td_bitspersample = 8; + td->td_sampleformat = SAMPLEFORMAT_UINT; +} + +static void +PixarLogCleanup(TIFF* tif) +{ + PixarLogState* sp = (PixarLogState*) tif->tif_data; + + assert(sp != 0); + + (void)TIFFPredictorCleanup(tif); + + tif->tif_tagmethods.vgetfield = sp->vgetparent; + tif->tif_tagmethods.vsetfield = sp->vsetparent; + + if (sp->FromLT2) _TIFFfree(sp->FromLT2); + if (sp->From14) _TIFFfree(sp->From14); + if (sp->From8) _TIFFfree(sp->From8); + if (sp->ToLinearF) _TIFFfree(sp->ToLinearF); + if (sp->ToLinear16) _TIFFfree(sp->ToLinear16); + if (sp->ToLinear8) _TIFFfree(sp->ToLinear8); + if (sp->state&PLSTATE_INIT) { + if (tif->tif_mode == O_RDONLY) + inflateEnd(&sp->stream); + else + deflateEnd(&sp->stream); + } + if (sp->tbuf) + _TIFFfree(sp->tbuf); + _TIFFfree(sp); + tif->tif_data = NULL; + + _TIFFSetDefaultCompressionState(tif); +} + +static int +PixarLogVSetField(TIFF* tif, uint32 tag, va_list ap) +{ + static const char module[] = "PixarLogVSetField"; + PixarLogState *sp = (PixarLogState *)tif->tif_data; + int result; + + switch (tag) { + case TIFFTAG_PIXARLOGQUALITY: + sp->quality = (int) va_arg(ap, int); + if (tif->tif_mode != O_RDONLY && (sp->state&PLSTATE_INIT)) { + if (deflateParams(&sp->stream, + sp->quality, Z_DEFAULT_STRATEGY) != Z_OK) { + TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", + sp->stream.msg); + return (0); + } + } + return (1); + case TIFFTAG_PIXARLOGDATAFMT: + sp->user_datafmt = (int) va_arg(ap, int); + /* Tweak the TIFF header so that the rest of libtiff knows what + * size of data will be passed between app and library, and + * assume that the app knows what it is doing and is not + * confused by these header manipulations... + */ + switch (sp->user_datafmt) { + case PIXARLOGDATAFMT_8BIT: + case PIXARLOGDATAFMT_8BITABGR: + TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); + TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT); + break; + case PIXARLOGDATAFMT_11BITLOG: + TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16); + TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT); + break; + case PIXARLOGDATAFMT_12BITPICIO: + TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16); + TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_INT); + break; + case PIXARLOGDATAFMT_16BIT: + TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16); + TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT); + break; + case PIXARLOGDATAFMT_FLOAT: + TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 32); + TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP); + break; + } + /* + * Must recalculate sizes should bits/sample change. + */ + tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tmsize_t)(-1); + tif->tif_scanlinesize = TIFFScanlineSize(tif); + result = 1; /* NB: pseudo tag */ + break; + default: + result = (*sp->vsetparent)(tif, tag, ap); + } + return (result); +} + +static int +PixarLogVGetField(TIFF* tif, uint32 tag, va_list ap) +{ + PixarLogState *sp = (PixarLogState *)tif->tif_data; + + switch (tag) { + case TIFFTAG_PIXARLOGQUALITY: + *va_arg(ap, int*) = sp->quality; + break; + case TIFFTAG_PIXARLOGDATAFMT: + *va_arg(ap, int*) = sp->user_datafmt; + break; + default: + return (*sp->vgetparent)(tif, tag, ap); + } + return (1); +} + +static const TIFFField pixarlogFields[] = { + {TIFFTAG_PIXARLOGDATAFMT, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "", NULL}, + {TIFFTAG_PIXARLOGQUALITY, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "", NULL} +}; + +int +TIFFInitPixarLog(TIFF* tif, int scheme) +{ + static const char module[] = "TIFFInitPixarLog"; + + PixarLogState* sp; + + assert(scheme == COMPRESSION_PIXARLOG); + + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFields(tif, pixarlogFields, + TIFFArrayCount(pixarlogFields))) { + TIFFErrorExt(tif->tif_clientdata, module, + "Merging PixarLog codec-specific tags failed"); + return 0; + } + + /* + * Allocate state block so tag methods have storage to record values. + */ + tif->tif_data = (uint8*) _TIFFmalloc(sizeof (PixarLogState)); + if (tif->tif_data == NULL) + goto bad; + sp = (PixarLogState*) tif->tif_data; + _TIFFmemset(sp, 0, sizeof (*sp)); + sp->stream.data_type = Z_BINARY; + sp->user_datafmt = PIXARLOGDATAFMT_UNKNOWN; + + /* + * Install codec methods. + */ + tif->tif_fixuptags = PixarLogFixupTags; + tif->tif_setupdecode = PixarLogSetupDecode; + tif->tif_predecode = PixarLogPreDecode; + tif->tif_decoderow = PixarLogDecode; + tif->tif_decodestrip = PixarLogDecode; + tif->tif_decodetile = PixarLogDecode; + tif->tif_setupencode = PixarLogSetupEncode; + tif->tif_preencode = PixarLogPreEncode; + tif->tif_postencode = PixarLogPostEncode; + tif->tif_encoderow = PixarLogEncode; + tif->tif_encodestrip = PixarLogEncode; + tif->tif_encodetile = PixarLogEncode; + tif->tif_close = PixarLogClose; + tif->tif_cleanup = PixarLogCleanup; + + /* Override SetField so we can handle our private pseudo-tag */ + sp->vgetparent = tif->tif_tagmethods.vgetfield; + tif->tif_tagmethods.vgetfield = PixarLogVGetField; /* hook for codec tags */ + sp->vsetparent = tif->tif_tagmethods.vsetfield; + tif->tif_tagmethods.vsetfield = PixarLogVSetField; /* hook for codec tags */ + + /* Default values for codec-specific fields */ + sp->quality = Z_DEFAULT_COMPRESSION; /* default comp. level */ + sp->state = 0; + + /* we don't wish to use the predictor, + * the default is none, which predictor value 1 + */ + (void) TIFFPredictorInit(tif); + + /* + * build the companding tables + */ + PixarLogMakeTables(sp); + + return (1); +bad: + TIFFErrorExt(tif->tif_clientdata, module, + "No space for PixarLog state block"); + return (0); +} +#endif /* PIXARLOG_SUPPORT */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_predict.c b/Source/LibTIFF4/tif_predict.c index dfe1a38..8d6b0e6 100644 --- a/Source/LibTIFF4/tif_predict.c +++ b/Source/LibTIFF4/tif_predict.c @@ -1,764 +1,764 @@ -/* $Id: tif_predict.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * - * Predictor Tag Support (used by multiple codecs). - */ -#include "tiffiop.h" -#include "tif_predict.h" - -#define PredictorState(tif) ((TIFFPredictorState*) (tif)->tif_data) - -static void horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc); -static void horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc); -static void horAcc32(TIFF* tif, uint8* cp0, tmsize_t cc); -static void swabHorAcc16(TIFF* tif, uint8* cp0, tmsize_t cc); -static void swabHorAcc32(TIFF* tif, uint8* cp0, tmsize_t cc); -static void horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc); -static void horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc); -static void horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc); -static void fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc); -static void fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc); -static int PredictorDecodeRow(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); -static int PredictorDecodeTile(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); -static int PredictorEncodeRow(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s); -static int PredictorEncodeTile(TIFF* tif, uint8* bp0, tmsize_t cc0, uint16 s); - -static int -PredictorSetup(TIFF* tif) -{ - static const char module[] = "PredictorSetup"; - - TIFFPredictorState* sp = PredictorState(tif); - TIFFDirectory* td = &tif->tif_dir; - - switch (sp->predictor) /* no differencing */ - { - case PREDICTOR_NONE: - return 1; - case PREDICTOR_HORIZONTAL: - if (td->td_bitspersample != 8 - && td->td_bitspersample != 16 - && td->td_bitspersample != 32) { - TIFFErrorExt(tif->tif_clientdata, module, - "Horizontal differencing \"Predictor\" not supported with %d-bit samples", - td->td_bitspersample); - return 0; - } - break; - case PREDICTOR_FLOATINGPOINT: - if (td->td_sampleformat != SAMPLEFORMAT_IEEEFP) { - TIFFErrorExt(tif->tif_clientdata, module, - "Floating point \"Predictor\" not supported with %d data format", - td->td_sampleformat); - return 0; - } - break; - default: - TIFFErrorExt(tif->tif_clientdata, module, - "\"Predictor\" value %d not supported", - sp->predictor); - return 0; - } - sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ? - td->td_samplesperpixel : 1); - /* - * Calculate the scanline/tile-width size in bytes. - */ - if (isTiled(tif)) - sp->rowsize = TIFFTileRowSize(tif); - else - sp->rowsize = TIFFScanlineSize(tif); - if (sp->rowsize == 0) - return 0; - - return 1; -} - -static int -PredictorSetupDecode(TIFF* tif) -{ - TIFFPredictorState* sp = PredictorState(tif); - TIFFDirectory* td = &tif->tif_dir; - - if (!(*sp->setupdecode)(tif) || !PredictorSetup(tif)) - return 0; - - if (sp->predictor == 2) { - switch (td->td_bitspersample) { - case 8: sp->decodepfunc = horAcc8; break; - case 16: sp->decodepfunc = horAcc16; break; - case 32: sp->decodepfunc = horAcc32; break; - } - /* - * Override default decoding method with one that does the - * predictor stuff. - */ - if( tif->tif_decoderow != PredictorDecodeRow ) - { - sp->decoderow = tif->tif_decoderow; - tif->tif_decoderow = PredictorDecodeRow; - sp->decodestrip = tif->tif_decodestrip; - tif->tif_decodestrip = PredictorDecodeTile; - sp->decodetile = tif->tif_decodetile; - tif->tif_decodetile = PredictorDecodeTile; - } - - /* - * If the data is horizontally differenced 16-bit data that - * requires byte-swapping, then it must be byte swapped before - * the accumulation step. We do this with a special-purpose - * routine and override the normal post decoding logic that - * the library setup when the directory was read. - */ - if (tif->tif_flags & TIFF_SWAB) { - if (sp->decodepfunc == horAcc16) { - sp->decodepfunc = swabHorAcc16; - tif->tif_postdecode = _TIFFNoPostDecode; - } else if (sp->decodepfunc == horAcc32) { - sp->decodepfunc = swabHorAcc32; - tif->tif_postdecode = _TIFFNoPostDecode; - } - } - } - - else if (sp->predictor == 3) { - sp->decodepfunc = fpAcc; - /* - * Override default decoding method with one that does the - * predictor stuff. - */ - if( tif->tif_decoderow != PredictorDecodeRow ) - { - sp->decoderow = tif->tif_decoderow; - tif->tif_decoderow = PredictorDecodeRow; - sp->decodestrip = tif->tif_decodestrip; - tif->tif_decodestrip = PredictorDecodeTile; - sp->decodetile = tif->tif_decodetile; - tif->tif_decodetile = PredictorDecodeTile; - } - /* - * The data should not be swapped outside of the floating - * point predictor, the accumulation routine should return - * byres in the native order. - */ - if (tif->tif_flags & TIFF_SWAB) { - tif->tif_postdecode = _TIFFNoPostDecode; - } - /* - * Allocate buffer to keep the decoded bytes before - * rearranging in the ight order - */ - } - - return 1; -} - -static int -PredictorSetupEncode(TIFF* tif) -{ - TIFFPredictorState* sp = PredictorState(tif); - TIFFDirectory* td = &tif->tif_dir; - - if (!(*sp->setupencode)(tif) || !PredictorSetup(tif)) - return 0; - - if (sp->predictor == 2) { - switch (td->td_bitspersample) { - case 8: sp->encodepfunc = horDiff8; break; - case 16: sp->encodepfunc = horDiff16; break; - case 32: sp->encodepfunc = horDiff32; break; - } - /* - * Override default encoding method with one that does the - * predictor stuff. - */ - if( tif->tif_encoderow != PredictorEncodeRow ) - { - sp->encoderow = tif->tif_encoderow; - tif->tif_encoderow = PredictorEncodeRow; - sp->encodestrip = tif->tif_encodestrip; - tif->tif_encodestrip = PredictorEncodeTile; - sp->encodetile = tif->tif_encodetile; - tif->tif_encodetile = PredictorEncodeTile; - } - } - - else if (sp->predictor == 3) { - sp->encodepfunc = fpDiff; - /* - * Override default encoding method with one that does the - * predictor stuff. - */ - if( tif->tif_encoderow != PredictorEncodeRow ) - { - sp->encoderow = tif->tif_encoderow; - tif->tif_encoderow = PredictorEncodeRow; - sp->encodestrip = tif->tif_encodestrip; - tif->tif_encodestrip = PredictorEncodeTile; - sp->encodetile = tif->tif_encodetile; - tif->tif_encodetile = PredictorEncodeTile; - } - } - - return 1; -} - -#define REPEAT4(n, op) \ - switch (n) { \ - default: { tmsize_t i; for (i = n-4; i > 0; i--) { op; } } \ - case 4: op; \ - case 3: op; \ - case 2: op; \ - case 1: op; \ - case 0: ; \ - } - -static void -horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) -{ - tmsize_t stride = PredictorState(tif)->stride; - - char* cp = (char*) cp0; - assert((cc%stride)==0); - if (cc > stride) { - /* - * Pipeline the most common cases. - */ - if (stride == 3) { - unsigned int cr = cp[0]; - unsigned int cg = cp[1]; - unsigned int cb = cp[2]; - cc -= 3; - cp += 3; - while (cc>0) { - cp[0] = (char) (cr += cp[0]); - cp[1] = (char) (cg += cp[1]); - cp[2] = (char) (cb += cp[2]); - cc -= 3; - cp += 3; - } - } else if (stride == 4) { - unsigned int cr = cp[0]; - unsigned int cg = cp[1]; - unsigned int cb = cp[2]; - unsigned int ca = cp[3]; - cc -= 4; - cp += 4; - while (cc>0) { - cp[0] = (char) (cr += cp[0]); - cp[1] = (char) (cg += cp[1]); - cp[2] = (char) (cb += cp[2]); - cp[3] = (char) (ca += cp[3]); - cc -= 4; - cp += 4; - } - } else { - cc -= stride; - do { - REPEAT4(stride, cp[stride] = - (char) (cp[stride] + *cp); cp++) - cc -= stride; - } while (cc>0); - } - } -} - -static void -swabHorAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) -{ - tmsize_t stride = PredictorState(tif)->stride; - uint16* wp = (uint16*) cp0; - tmsize_t wc = cc / 2; - - assert((cc%(2*stride))==0); - - if (wc > stride) { - TIFFSwabArrayOfShort(wp, wc); - wc -= stride; - do { - REPEAT4(stride, wp[stride] += wp[0]; wp++) - wc -= stride; - } while (wc > 0); - } -} - -static void -horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) -{ - tmsize_t stride = PredictorState(tif)->stride; - uint16* wp = (uint16*) cp0; - tmsize_t wc = cc / 2; - - assert((cc%(2*stride))==0); - - if (wc > stride) { - wc -= stride; - do { - REPEAT4(stride, wp[stride] += wp[0]; wp++) - wc -= stride; - } while (wc > 0); - } -} - -static void -swabHorAcc32(TIFF* tif, uint8* cp0, tmsize_t cc) -{ - tmsize_t stride = PredictorState(tif)->stride; - uint32* wp = (uint32*) cp0; - tmsize_t wc = cc / 4; - - assert((cc%(4*stride))==0); - - if (wc > stride) { - TIFFSwabArrayOfLong(wp, wc); - wc -= stride; - do { - REPEAT4(stride, wp[stride] += wp[0]; wp++) - wc -= stride; - } while (wc > 0); - } -} - -static void -horAcc32(TIFF* tif, uint8* cp0, tmsize_t cc) -{ - tmsize_t stride = PredictorState(tif)->stride; - uint32* wp = (uint32*) cp0; - tmsize_t wc = cc / 4; - - assert((cc%(4*stride))==0); - - if (wc > stride) { - wc -= stride; - do { - REPEAT4(stride, wp[stride] += wp[0]; wp++) - wc -= stride; - } while (wc > 0); - } -} - -/* - * Floating point predictor accumulation routine. - */ -static void -fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc) -{ - tmsize_t stride = PredictorState(tif)->stride; - uint32 bps = tif->tif_dir.td_bitspersample / 8; - tmsize_t wc = cc / bps; - tmsize_t count = cc; - uint8 *cp = (uint8 *) cp0; - uint8 *tmp = (uint8 *)_TIFFmalloc(cc); - - assert((cc%(bps*stride))==0); - - if (!tmp) - return; - - while (count > stride) { - REPEAT4(stride, cp[stride] += cp[0]; cp++) - count -= stride; - } - - _TIFFmemcpy(tmp, cp0, cc); - cp = (uint8 *) cp0; - for (count = 0; count < wc; count++) { - uint32 byte; - for (byte = 0; byte < bps; byte++) { - #if WORDS_BIGENDIAN - cp[bps * count + byte] = tmp[byte * wc + count]; - #else - cp[bps * count + byte] = - tmp[(bps - byte - 1) * wc + count]; - #endif - } - } - _TIFFfree(tmp); -} - -/* - * Decode a scanline and apply the predictor routine. - */ -static int -PredictorDecodeRow(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) -{ - TIFFPredictorState *sp = PredictorState(tif); - - assert(sp != NULL); - assert(sp->decoderow != NULL); - assert(sp->decodepfunc != NULL); - - if ((*sp->decoderow)(tif, op0, occ0, s)) { - (*sp->decodepfunc)(tif, op0, occ0); - return 1; - } else - return 0; -} - -/* - * Decode a tile/strip and apply the predictor routine. - * Note that horizontal differencing must be done on a - * row-by-row basis. The width of a "row" has already - * been calculated at pre-decode time according to the - * strip/tile dimensions. - */ -static int -PredictorDecodeTile(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) -{ - TIFFPredictorState *sp = PredictorState(tif); - - assert(sp != NULL); - assert(sp->decodetile != NULL); - - if ((*sp->decodetile)(tif, op0, occ0, s)) { - tmsize_t rowsize = sp->rowsize; - assert(rowsize > 0); - assert((occ0%rowsize)==0); - assert(sp->decodepfunc != NULL); - while (occ0 > 0) { - (*sp->decodepfunc)(tif, op0, rowsize); - occ0 -= rowsize; - op0 += rowsize; - } - return 1; - } else - return 0; -} - -static void -horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc) -{ - TIFFPredictorState* sp = PredictorState(tif); - tmsize_t stride = sp->stride; - char* cp = (char*) cp0; - - assert((cc%stride)==0); - - if (cc > stride) { - cc -= stride; - /* - * Pipeline the most common cases. - */ - if (stride == 3) { - int r1, g1, b1; - int r2 = cp[0]; - int g2 = cp[1]; - int b2 = cp[2]; - do { - r1 = cp[3]; cp[3] = r1-r2; r2 = r1; - g1 = cp[4]; cp[4] = g1-g2; g2 = g1; - b1 = cp[5]; cp[5] = b1-b2; b2 = b1; - cp += 3; - } while ((cc -= 3) > 0); - } else if (stride == 4) { - int r1, g1, b1, a1; - int r2 = cp[0]; - int g2 = cp[1]; - int b2 = cp[2]; - int a2 = cp[3]; - do { - r1 = cp[4]; cp[4] = r1-r2; r2 = r1; - g1 = cp[5]; cp[5] = g1-g2; g2 = g1; - b1 = cp[6]; cp[6] = b1-b2; b2 = b1; - a1 = cp[7]; cp[7] = a1-a2; a2 = a1; - cp += 4; - } while ((cc -= 4) > 0); - } else { - cp += cc - 1; - do { - REPEAT4(stride, cp[stride] -= cp[0]; cp--) - } while ((cc -= stride) > 0); - } - } -} - -static void -horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc) -{ - TIFFPredictorState* sp = PredictorState(tif); - tmsize_t stride = sp->stride; - int16 *wp = (int16*) cp0; - tmsize_t wc = cc/2; - - assert((cc%(2*stride))==0); - - if (wc > stride) { - wc -= stride; - wp += wc - 1; - do { - REPEAT4(stride, wp[stride] -= wp[0]; wp--) - wc -= stride; - } while (wc > 0); - } -} - -static void -horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc) -{ - TIFFPredictorState* sp = PredictorState(tif); - tmsize_t stride = sp->stride; - int32 *wp = (int32*) cp0; - tmsize_t wc = cc/4; - - assert((cc%(4*stride))==0); - - if (wc > stride) { - wc -= stride; - wp += wc - 1; - do { - REPEAT4(stride, wp[stride] -= wp[0]; wp--) - wc -= stride; - } while (wc > 0); - } -} - -/* - * Floating point predictor differencing routine. - */ -static void -fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc) -{ - tmsize_t stride = PredictorState(tif)->stride; - uint32 bps = tif->tif_dir.td_bitspersample / 8; - tmsize_t wc = cc / bps; - tmsize_t count; - uint8 *cp = (uint8 *) cp0; - uint8 *tmp = (uint8 *)_TIFFmalloc(cc); - - assert((cc%(bps*stride))==0); - - if (!tmp) - return; - - _TIFFmemcpy(tmp, cp0, cc); - for (count = 0; count < wc; count++) { - uint32 byte; - for (byte = 0; byte < bps; byte++) { - #if WORDS_BIGENDIAN - cp[byte * wc + count] = tmp[bps * count + byte]; - #else - cp[(bps - byte - 1) * wc + count] = - tmp[bps * count + byte]; - #endif - } - } - _TIFFfree(tmp); - - cp = (uint8 *) cp0; - cp += cc - stride - 1; - for (count = cc; count > stride; count -= stride) - REPEAT4(stride, cp[stride] -= cp[0]; cp--) -} - -static int -PredictorEncodeRow(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - TIFFPredictorState *sp = PredictorState(tif); - - assert(sp != NULL); - assert(sp->encodepfunc != NULL); - assert(sp->encoderow != NULL); - - /* XXX horizontal differencing alters user's data XXX */ - (*sp->encodepfunc)(tif, bp, cc); - return (*sp->encoderow)(tif, bp, cc, s); -} - -static int -PredictorEncodeTile(TIFF* tif, uint8* bp0, tmsize_t cc0, uint16 s) -{ - static const char module[] = "PredictorEncodeTile"; - TIFFPredictorState *sp = PredictorState(tif); - uint8 *working_copy; - tmsize_t cc = cc0, rowsize; - unsigned char* bp; - int result_code; - - assert(sp != NULL); - assert(sp->encodepfunc != NULL); - assert(sp->encodetile != NULL); - - /* - * Do predictor manipulation in a working buffer to avoid altering - * the callers buffer. http://trac.osgeo.org/gdal/ticket/1965 - */ - working_copy = (uint8*) _TIFFmalloc(cc0); - if( working_copy == NULL ) - { - TIFFErrorExt(tif->tif_clientdata, module, - "Out of memory allocating " TIFF_SSIZE_FORMAT " byte temp buffer.", - cc0 ); - return 0; - } - memcpy( working_copy, bp0, cc0 ); - bp = working_copy; - - rowsize = sp->rowsize; - assert(rowsize > 0); - assert((cc0%rowsize)==0); - while (cc > 0) { - (*sp->encodepfunc)(tif, bp, rowsize); - cc -= rowsize; - bp += rowsize; - } - result_code = (*sp->encodetile)(tif, working_copy, cc0, s); - - _TIFFfree( working_copy ); - - return result_code; -} - -#define FIELD_PREDICTOR (FIELD_CODEC+0) /* XXX */ - -static const TIFFField predictFields[] = { - { TIFFTAG_PREDICTOR, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UINT16, FIELD_PREDICTOR, FALSE, FALSE, "Predictor", NULL }, -}; - -static int -PredictorVSetField(TIFF* tif, uint32 tag, va_list ap) -{ - TIFFPredictorState *sp = PredictorState(tif); - - assert(sp != NULL); - assert(sp->vsetparent != NULL); - - switch (tag) { - case TIFFTAG_PREDICTOR: - sp->predictor = (uint16) va_arg(ap, uint16_vap); - TIFFSetFieldBit(tif, FIELD_PREDICTOR); - break; - default: - return (*sp->vsetparent)(tif, tag, ap); - } - tif->tif_flags |= TIFF_DIRTYDIRECT; - return 1; -} - -static int -PredictorVGetField(TIFF* tif, uint32 tag, va_list ap) -{ - TIFFPredictorState *sp = PredictorState(tif); - - assert(sp != NULL); - assert(sp->vgetparent != NULL); - - switch (tag) { - case TIFFTAG_PREDICTOR: - *va_arg(ap, uint16*) = sp->predictor; - break; - default: - return (*sp->vgetparent)(tif, tag, ap); - } - return 1; -} - -static void -PredictorPrintDir(TIFF* tif, FILE* fd, long flags) -{ - TIFFPredictorState* sp = PredictorState(tif); - - (void) flags; - if (TIFFFieldSet(tif,FIELD_PREDICTOR)) { - fprintf(fd, " Predictor: "); - switch (sp->predictor) { - case 1: fprintf(fd, "none "); break; - case 2: fprintf(fd, "horizontal differencing "); break; - case 3: fprintf(fd, "floating point predictor "); break; - } - fprintf(fd, "%u (0x%x)\n", sp->predictor, sp->predictor); - } - if (sp->printdir) - (*sp->printdir)(tif, fd, flags); -} - -int -TIFFPredictorInit(TIFF* tif) -{ - TIFFPredictorState* sp = PredictorState(tif); - - assert(sp != 0); - - /* - * Merge codec-specific tag information. - */ - if (!_TIFFMergeFields(tif, predictFields, - TIFFArrayCount(predictFields))) { - TIFFErrorExt(tif->tif_clientdata, "TIFFPredictorInit", - "Merging Predictor codec-specific tags failed"); - return 0; - } - - /* - * Override parent get/set field methods. - */ - sp->vgetparent = tif->tif_tagmethods.vgetfield; - tif->tif_tagmethods.vgetfield = - PredictorVGetField;/* hook for predictor tag */ - sp->vsetparent = tif->tif_tagmethods.vsetfield; - tif->tif_tagmethods.vsetfield = - PredictorVSetField;/* hook for predictor tag */ - sp->printdir = tif->tif_tagmethods.printdir; - tif->tif_tagmethods.printdir = - PredictorPrintDir; /* hook for predictor tag */ - - sp->setupdecode = tif->tif_setupdecode; - tif->tif_setupdecode = PredictorSetupDecode; - sp->setupencode = tif->tif_setupencode; - tif->tif_setupencode = PredictorSetupEncode; - - sp->predictor = 1; /* default value */ - sp->encodepfunc = NULL; /* no predictor routine */ - sp->decodepfunc = NULL; /* no predictor routine */ - return 1; -} - -int -TIFFPredictorCleanup(TIFF* tif) -{ - TIFFPredictorState* sp = PredictorState(tif); - - assert(sp != 0); - - tif->tif_tagmethods.vgetfield = sp->vgetparent; - tif->tif_tagmethods.vsetfield = sp->vsetparent; - tif->tif_tagmethods.printdir = sp->printdir; - tif->tif_setupdecode = sp->setupdecode; - tif->tif_setupencode = sp->setupencode; - - return 1; -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_predict.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * + * Predictor Tag Support (used by multiple codecs). + */ +#include "tiffiop.h" +#include "tif_predict.h" + +#define PredictorState(tif) ((TIFFPredictorState*) (tif)->tif_data) + +static void horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc); +static void horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc); +static void horAcc32(TIFF* tif, uint8* cp0, tmsize_t cc); +static void swabHorAcc16(TIFF* tif, uint8* cp0, tmsize_t cc); +static void swabHorAcc32(TIFF* tif, uint8* cp0, tmsize_t cc); +static void horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc); +static void horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc); +static void horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc); +static void fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc); +static void fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc); +static int PredictorDecodeRow(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); +static int PredictorDecodeTile(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); +static int PredictorEncodeRow(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s); +static int PredictorEncodeTile(TIFF* tif, uint8* bp0, tmsize_t cc0, uint16 s); + +static int +PredictorSetup(TIFF* tif) +{ + static const char module[] = "PredictorSetup"; + + TIFFPredictorState* sp = PredictorState(tif); + TIFFDirectory* td = &tif->tif_dir; + + switch (sp->predictor) /* no differencing */ + { + case PREDICTOR_NONE: + return 1; + case PREDICTOR_HORIZONTAL: + if (td->td_bitspersample != 8 + && td->td_bitspersample != 16 + && td->td_bitspersample != 32) { + TIFFErrorExt(tif->tif_clientdata, module, + "Horizontal differencing \"Predictor\" not supported with %d-bit samples", + td->td_bitspersample); + return 0; + } + break; + case PREDICTOR_FLOATINGPOINT: + if (td->td_sampleformat != SAMPLEFORMAT_IEEEFP) { + TIFFErrorExt(tif->tif_clientdata, module, + "Floating point \"Predictor\" not supported with %d data format", + td->td_sampleformat); + return 0; + } + break; + default: + TIFFErrorExt(tif->tif_clientdata, module, + "\"Predictor\" value %d not supported", + sp->predictor); + return 0; + } + sp->stride = (td->td_planarconfig == PLANARCONFIG_CONTIG ? + td->td_samplesperpixel : 1); + /* + * Calculate the scanline/tile-width size in bytes. + */ + if (isTiled(tif)) + sp->rowsize = TIFFTileRowSize(tif); + else + sp->rowsize = TIFFScanlineSize(tif); + if (sp->rowsize == 0) + return 0; + + return 1; +} + +static int +PredictorSetupDecode(TIFF* tif) +{ + TIFFPredictorState* sp = PredictorState(tif); + TIFFDirectory* td = &tif->tif_dir; + + if (!(*sp->setupdecode)(tif) || !PredictorSetup(tif)) + return 0; + + if (sp->predictor == 2) { + switch (td->td_bitspersample) { + case 8: sp->decodepfunc = horAcc8; break; + case 16: sp->decodepfunc = horAcc16; break; + case 32: sp->decodepfunc = horAcc32; break; + } + /* + * Override default decoding method with one that does the + * predictor stuff. + */ + if( tif->tif_decoderow != PredictorDecodeRow ) + { + sp->decoderow = tif->tif_decoderow; + tif->tif_decoderow = PredictorDecodeRow; + sp->decodestrip = tif->tif_decodestrip; + tif->tif_decodestrip = PredictorDecodeTile; + sp->decodetile = tif->tif_decodetile; + tif->tif_decodetile = PredictorDecodeTile; + } + + /* + * If the data is horizontally differenced 16-bit data that + * requires byte-swapping, then it must be byte swapped before + * the accumulation step. We do this with a special-purpose + * routine and override the normal post decoding logic that + * the library setup when the directory was read. + */ + if (tif->tif_flags & TIFF_SWAB) { + if (sp->decodepfunc == horAcc16) { + sp->decodepfunc = swabHorAcc16; + tif->tif_postdecode = _TIFFNoPostDecode; + } else if (sp->decodepfunc == horAcc32) { + sp->decodepfunc = swabHorAcc32; + tif->tif_postdecode = _TIFFNoPostDecode; + } + } + } + + else if (sp->predictor == 3) { + sp->decodepfunc = fpAcc; + /* + * Override default decoding method with one that does the + * predictor stuff. + */ + if( tif->tif_decoderow != PredictorDecodeRow ) + { + sp->decoderow = tif->tif_decoderow; + tif->tif_decoderow = PredictorDecodeRow; + sp->decodestrip = tif->tif_decodestrip; + tif->tif_decodestrip = PredictorDecodeTile; + sp->decodetile = tif->tif_decodetile; + tif->tif_decodetile = PredictorDecodeTile; + } + /* + * The data should not be swapped outside of the floating + * point predictor, the accumulation routine should return + * byres in the native order. + */ + if (tif->tif_flags & TIFF_SWAB) { + tif->tif_postdecode = _TIFFNoPostDecode; + } + /* + * Allocate buffer to keep the decoded bytes before + * rearranging in the ight order + */ + } + + return 1; +} + +static int +PredictorSetupEncode(TIFF* tif) +{ + TIFFPredictorState* sp = PredictorState(tif); + TIFFDirectory* td = &tif->tif_dir; + + if (!(*sp->setupencode)(tif) || !PredictorSetup(tif)) + return 0; + + if (sp->predictor == 2) { + switch (td->td_bitspersample) { + case 8: sp->encodepfunc = horDiff8; break; + case 16: sp->encodepfunc = horDiff16; break; + case 32: sp->encodepfunc = horDiff32; break; + } + /* + * Override default encoding method with one that does the + * predictor stuff. + */ + if( tif->tif_encoderow != PredictorEncodeRow ) + { + sp->encoderow = tif->tif_encoderow; + tif->tif_encoderow = PredictorEncodeRow; + sp->encodestrip = tif->tif_encodestrip; + tif->tif_encodestrip = PredictorEncodeTile; + sp->encodetile = tif->tif_encodetile; + tif->tif_encodetile = PredictorEncodeTile; + } + } + + else if (sp->predictor == 3) { + sp->encodepfunc = fpDiff; + /* + * Override default encoding method with one that does the + * predictor stuff. + */ + if( tif->tif_encoderow != PredictorEncodeRow ) + { + sp->encoderow = tif->tif_encoderow; + tif->tif_encoderow = PredictorEncodeRow; + sp->encodestrip = tif->tif_encodestrip; + tif->tif_encodestrip = PredictorEncodeTile; + sp->encodetile = tif->tif_encodetile; + tif->tif_encodetile = PredictorEncodeTile; + } + } + + return 1; +} + +#define REPEAT4(n, op) \ + switch (n) { \ + default: { tmsize_t i; for (i = n-4; i > 0; i--) { op; } } \ + case 4: op; \ + case 3: op; \ + case 2: op; \ + case 1: op; \ + case 0: ; \ + } + +static void +horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) +{ + tmsize_t stride = PredictorState(tif)->stride; + + char* cp = (char*) cp0; + assert((cc%stride)==0); + if (cc > stride) { + /* + * Pipeline the most common cases. + */ + if (stride == 3) { + unsigned int cr = cp[0]; + unsigned int cg = cp[1]; + unsigned int cb = cp[2]; + cc -= 3; + cp += 3; + while (cc>0) { + cp[0] = (char) (cr += cp[0]); + cp[1] = (char) (cg += cp[1]); + cp[2] = (char) (cb += cp[2]); + cc -= 3; + cp += 3; + } + } else if (stride == 4) { + unsigned int cr = cp[0]; + unsigned int cg = cp[1]; + unsigned int cb = cp[2]; + unsigned int ca = cp[3]; + cc -= 4; + cp += 4; + while (cc>0) { + cp[0] = (char) (cr += cp[0]); + cp[1] = (char) (cg += cp[1]); + cp[2] = (char) (cb += cp[2]); + cp[3] = (char) (ca += cp[3]); + cc -= 4; + cp += 4; + } + } else { + cc -= stride; + do { + REPEAT4(stride, cp[stride] = + (char) (cp[stride] + *cp); cp++) + cc -= stride; + } while (cc>0); + } + } +} + +static void +swabHorAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) +{ + tmsize_t stride = PredictorState(tif)->stride; + uint16* wp = (uint16*) cp0; + tmsize_t wc = cc / 2; + + assert((cc%(2*stride))==0); + + if (wc > stride) { + TIFFSwabArrayOfShort(wp, wc); + wc -= stride; + do { + REPEAT4(stride, wp[stride] += wp[0]; wp++) + wc -= stride; + } while (wc > 0); + } +} + +static void +horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) +{ + tmsize_t stride = PredictorState(tif)->stride; + uint16* wp = (uint16*) cp0; + tmsize_t wc = cc / 2; + + assert((cc%(2*stride))==0); + + if (wc > stride) { + wc -= stride; + do { + REPEAT4(stride, wp[stride] += wp[0]; wp++) + wc -= stride; + } while (wc > 0); + } +} + +static void +swabHorAcc32(TIFF* tif, uint8* cp0, tmsize_t cc) +{ + tmsize_t stride = PredictorState(tif)->stride; + uint32* wp = (uint32*) cp0; + tmsize_t wc = cc / 4; + + assert((cc%(4*stride))==0); + + if (wc > stride) { + TIFFSwabArrayOfLong(wp, wc); + wc -= stride; + do { + REPEAT4(stride, wp[stride] += wp[0]; wp++) + wc -= stride; + } while (wc > 0); + } +} + +static void +horAcc32(TIFF* tif, uint8* cp0, tmsize_t cc) +{ + tmsize_t stride = PredictorState(tif)->stride; + uint32* wp = (uint32*) cp0; + tmsize_t wc = cc / 4; + + assert((cc%(4*stride))==0); + + if (wc > stride) { + wc -= stride; + do { + REPEAT4(stride, wp[stride] += wp[0]; wp++) + wc -= stride; + } while (wc > 0); + } +} + +/* + * Floating point predictor accumulation routine. + */ +static void +fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc) +{ + tmsize_t stride = PredictorState(tif)->stride; + uint32 bps = tif->tif_dir.td_bitspersample / 8; + tmsize_t wc = cc / bps; + tmsize_t count = cc; + uint8 *cp = (uint8 *) cp0; + uint8 *tmp = (uint8 *)_TIFFmalloc(cc); + + assert((cc%(bps*stride))==0); + + if (!tmp) + return; + + while (count > stride) { + REPEAT4(stride, cp[stride] += cp[0]; cp++) + count -= stride; + } + + _TIFFmemcpy(tmp, cp0, cc); + cp = (uint8 *) cp0; + for (count = 0; count < wc; count++) { + uint32 byte; + for (byte = 0; byte < bps; byte++) { + #if WORDS_BIGENDIAN + cp[bps * count + byte] = tmp[byte * wc + count]; + #else + cp[bps * count + byte] = + tmp[(bps - byte - 1) * wc + count]; + #endif + } + } + _TIFFfree(tmp); +} + +/* + * Decode a scanline and apply the predictor routine. + */ +static int +PredictorDecodeRow(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) +{ + TIFFPredictorState *sp = PredictorState(tif); + + assert(sp != NULL); + assert(sp->decoderow != NULL); + assert(sp->decodepfunc != NULL); + + if ((*sp->decoderow)(tif, op0, occ0, s)) { + (*sp->decodepfunc)(tif, op0, occ0); + return 1; + } else + return 0; +} + +/* + * Decode a tile/strip and apply the predictor routine. + * Note that horizontal differencing must be done on a + * row-by-row basis. The width of a "row" has already + * been calculated at pre-decode time according to the + * strip/tile dimensions. + */ +static int +PredictorDecodeTile(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) +{ + TIFFPredictorState *sp = PredictorState(tif); + + assert(sp != NULL); + assert(sp->decodetile != NULL); + + if ((*sp->decodetile)(tif, op0, occ0, s)) { + tmsize_t rowsize = sp->rowsize; + assert(rowsize > 0); + assert((occ0%rowsize)==0); + assert(sp->decodepfunc != NULL); + while (occ0 > 0) { + (*sp->decodepfunc)(tif, op0, rowsize); + occ0 -= rowsize; + op0 += rowsize; + } + return 1; + } else + return 0; +} + +static void +horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc) +{ + TIFFPredictorState* sp = PredictorState(tif); + tmsize_t stride = sp->stride; + char* cp = (char*) cp0; + + assert((cc%stride)==0); + + if (cc > stride) { + cc -= stride; + /* + * Pipeline the most common cases. + */ + if (stride == 3) { + int r1, g1, b1; + int r2 = cp[0]; + int g2 = cp[1]; + int b2 = cp[2]; + do { + r1 = cp[3]; cp[3] = r1-r2; r2 = r1; + g1 = cp[4]; cp[4] = g1-g2; g2 = g1; + b1 = cp[5]; cp[5] = b1-b2; b2 = b1; + cp += 3; + } while ((cc -= 3) > 0); + } else if (stride == 4) { + int r1, g1, b1, a1; + int r2 = cp[0]; + int g2 = cp[1]; + int b2 = cp[2]; + int a2 = cp[3]; + do { + r1 = cp[4]; cp[4] = r1-r2; r2 = r1; + g1 = cp[5]; cp[5] = g1-g2; g2 = g1; + b1 = cp[6]; cp[6] = b1-b2; b2 = b1; + a1 = cp[7]; cp[7] = a1-a2; a2 = a1; + cp += 4; + } while ((cc -= 4) > 0); + } else { + cp += cc - 1; + do { + REPEAT4(stride, cp[stride] -= cp[0]; cp--) + } while ((cc -= stride) > 0); + } + } +} + +static void +horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc) +{ + TIFFPredictorState* sp = PredictorState(tif); + tmsize_t stride = sp->stride; + int16 *wp = (int16*) cp0; + tmsize_t wc = cc/2; + + assert((cc%(2*stride))==0); + + if (wc > stride) { + wc -= stride; + wp += wc - 1; + do { + REPEAT4(stride, wp[stride] -= wp[0]; wp--) + wc -= stride; + } while (wc > 0); + } +} + +static void +horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc) +{ + TIFFPredictorState* sp = PredictorState(tif); + tmsize_t stride = sp->stride; + int32 *wp = (int32*) cp0; + tmsize_t wc = cc/4; + + assert((cc%(4*stride))==0); + + if (wc > stride) { + wc -= stride; + wp += wc - 1; + do { + REPEAT4(stride, wp[stride] -= wp[0]; wp--) + wc -= stride; + } while (wc > 0); + } +} + +/* + * Floating point predictor differencing routine. + */ +static void +fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc) +{ + tmsize_t stride = PredictorState(tif)->stride; + uint32 bps = tif->tif_dir.td_bitspersample / 8; + tmsize_t wc = cc / bps; + tmsize_t count; + uint8 *cp = (uint8 *) cp0; + uint8 *tmp = (uint8 *)_TIFFmalloc(cc); + + assert((cc%(bps*stride))==0); + + if (!tmp) + return; + + _TIFFmemcpy(tmp, cp0, cc); + for (count = 0; count < wc; count++) { + uint32 byte; + for (byte = 0; byte < bps; byte++) { + #if WORDS_BIGENDIAN + cp[byte * wc + count] = tmp[bps * count + byte]; + #else + cp[(bps - byte - 1) * wc + count] = + tmp[bps * count + byte]; + #endif + } + } + _TIFFfree(tmp); + + cp = (uint8 *) cp0; + cp += cc - stride - 1; + for (count = cc; count > stride; count -= stride) + REPEAT4(stride, cp[stride] -= cp[0]; cp--) +} + +static int +PredictorEncodeRow(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + TIFFPredictorState *sp = PredictorState(tif); + + assert(sp != NULL); + assert(sp->encodepfunc != NULL); + assert(sp->encoderow != NULL); + + /* XXX horizontal differencing alters user's data XXX */ + (*sp->encodepfunc)(tif, bp, cc); + return (*sp->encoderow)(tif, bp, cc, s); +} + +static int +PredictorEncodeTile(TIFF* tif, uint8* bp0, tmsize_t cc0, uint16 s) +{ + static const char module[] = "PredictorEncodeTile"; + TIFFPredictorState *sp = PredictorState(tif); + uint8 *working_copy; + tmsize_t cc = cc0, rowsize; + unsigned char* bp; + int result_code; + + assert(sp != NULL); + assert(sp->encodepfunc != NULL); + assert(sp->encodetile != NULL); + + /* + * Do predictor manipulation in a working buffer to avoid altering + * the callers buffer. http://trac.osgeo.org/gdal/ticket/1965 + */ + working_copy = (uint8*) _TIFFmalloc(cc0); + if( working_copy == NULL ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Out of memory allocating " TIFF_SSIZE_FORMAT " byte temp buffer.", + cc0 ); + return 0; + } + memcpy( working_copy, bp0, cc0 ); + bp = working_copy; + + rowsize = sp->rowsize; + assert(rowsize > 0); + assert((cc0%rowsize)==0); + while (cc > 0) { + (*sp->encodepfunc)(tif, bp, rowsize); + cc -= rowsize; + bp += rowsize; + } + result_code = (*sp->encodetile)(tif, working_copy, cc0, s); + + _TIFFfree( working_copy ); + + return result_code; +} + +#define FIELD_PREDICTOR (FIELD_CODEC+0) /* XXX */ + +static const TIFFField predictFields[] = { + { TIFFTAG_PREDICTOR, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UINT16, FIELD_PREDICTOR, FALSE, FALSE, "Predictor", NULL }, +}; + +static int +PredictorVSetField(TIFF* tif, uint32 tag, va_list ap) +{ + TIFFPredictorState *sp = PredictorState(tif); + + assert(sp != NULL); + assert(sp->vsetparent != NULL); + + switch (tag) { + case TIFFTAG_PREDICTOR: + sp->predictor = (uint16) va_arg(ap, uint16_vap); + TIFFSetFieldBit(tif, FIELD_PREDICTOR); + break; + default: + return (*sp->vsetparent)(tif, tag, ap); + } + tif->tif_flags |= TIFF_DIRTYDIRECT; + return 1; +} + +static int +PredictorVGetField(TIFF* tif, uint32 tag, va_list ap) +{ + TIFFPredictorState *sp = PredictorState(tif); + + assert(sp != NULL); + assert(sp->vgetparent != NULL); + + switch (tag) { + case TIFFTAG_PREDICTOR: + *va_arg(ap, uint16*) = sp->predictor; + break; + default: + return (*sp->vgetparent)(tif, tag, ap); + } + return 1; +} + +static void +PredictorPrintDir(TIFF* tif, FILE* fd, long flags) +{ + TIFFPredictorState* sp = PredictorState(tif); + + (void) flags; + if (TIFFFieldSet(tif,FIELD_PREDICTOR)) { + fprintf(fd, " Predictor: "); + switch (sp->predictor) { + case 1: fprintf(fd, "none "); break; + case 2: fprintf(fd, "horizontal differencing "); break; + case 3: fprintf(fd, "floating point predictor "); break; + } + fprintf(fd, "%u (0x%x)\n", sp->predictor, sp->predictor); + } + if (sp->printdir) + (*sp->printdir)(tif, fd, flags); +} + +int +TIFFPredictorInit(TIFF* tif) +{ + TIFFPredictorState* sp = PredictorState(tif); + + assert(sp != 0); + + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFields(tif, predictFields, + TIFFArrayCount(predictFields))) { + TIFFErrorExt(tif->tif_clientdata, "TIFFPredictorInit", + "Merging Predictor codec-specific tags failed"); + return 0; + } + + /* + * Override parent get/set field methods. + */ + sp->vgetparent = tif->tif_tagmethods.vgetfield; + tif->tif_tagmethods.vgetfield = + PredictorVGetField;/* hook for predictor tag */ + sp->vsetparent = tif->tif_tagmethods.vsetfield; + tif->tif_tagmethods.vsetfield = + PredictorVSetField;/* hook for predictor tag */ + sp->printdir = tif->tif_tagmethods.printdir; + tif->tif_tagmethods.printdir = + PredictorPrintDir; /* hook for predictor tag */ + + sp->setupdecode = tif->tif_setupdecode; + tif->tif_setupdecode = PredictorSetupDecode; + sp->setupencode = tif->tif_setupencode; + tif->tif_setupencode = PredictorSetupEncode; + + sp->predictor = 1; /* default value */ + sp->encodepfunc = NULL; /* no predictor routine */ + sp->decodepfunc = NULL; /* no predictor routine */ + return 1; +} + +int +TIFFPredictorCleanup(TIFF* tif) +{ + TIFFPredictorState* sp = PredictorState(tif); + + assert(sp != 0); + + tif->tif_tagmethods.vgetfield = sp->vgetparent; + tif->tif_tagmethods.vsetfield = sp->vsetparent; + tif->tif_tagmethods.printdir = sp->printdir; + tif->tif_setupdecode = sp->setupdecode; + tif->tif_setupencode = sp->setupencode; + + return 1; +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_predict.h b/Source/LibTIFF4/tif_predict.h index 7df6066..33fdca0 100644 --- a/Source/LibTIFF4/tif_predict.h +++ b/Source/LibTIFF4/tif_predict.h @@ -1,77 +1,77 @@ -/* $Id: tif_predict.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1995-1997 Sam Leffler - * Copyright (c) 1995-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifndef _TIFFPREDICT_ -#define _TIFFPREDICT_ -/* - * ``Library-private'' Support for the Predictor Tag - */ - -/* - * Codecs that want to support the Predictor tag must place - * this structure first in their private state block so that - * the predictor code can cast tif_data to find its state. - */ -typedef struct { - int predictor; /* predictor tag value */ - tmsize_t stride; /* sample stride over data */ - tmsize_t rowsize; /* tile/strip row size */ - - TIFFCodeMethod encoderow; /* parent codec encode/decode row */ - TIFFCodeMethod encodestrip; /* parent codec encode/decode strip */ - TIFFCodeMethod encodetile; /* parent codec encode/decode tile */ - TIFFPostMethod encodepfunc; /* horizontal differencer */ - - TIFFCodeMethod decoderow; /* parent codec encode/decode row */ - TIFFCodeMethod decodestrip; /* parent codec encode/decode strip */ - TIFFCodeMethod decodetile; /* parent codec encode/decode tile */ - TIFFPostMethod decodepfunc; /* horizontal accumulator */ - - TIFFVGetMethod vgetparent; /* super-class method */ - TIFFVSetMethod vsetparent; /* super-class method */ - TIFFPrintMethod printdir; /* super-class method */ - TIFFBoolMethod setupdecode; /* super-class method */ - TIFFBoolMethod setupencode; /* super-class method */ -} TIFFPredictorState; - -#if defined(__cplusplus) -extern "C" { -#endif -extern int TIFFPredictorInit(TIFF*); -extern int TIFFPredictorCleanup(TIFF*); -#if defined(__cplusplus) -} -#endif -#endif /* _TIFFPREDICT_ */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_predict.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1995-1997 Sam Leffler + * Copyright (c) 1995-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef _TIFFPREDICT_ +#define _TIFFPREDICT_ +/* + * ``Library-private'' Support for the Predictor Tag + */ + +/* + * Codecs that want to support the Predictor tag must place + * this structure first in their private state block so that + * the predictor code can cast tif_data to find its state. + */ +typedef struct { + int predictor; /* predictor tag value */ + tmsize_t stride; /* sample stride over data */ + tmsize_t rowsize; /* tile/strip row size */ + + TIFFCodeMethod encoderow; /* parent codec encode/decode row */ + TIFFCodeMethod encodestrip; /* parent codec encode/decode strip */ + TIFFCodeMethod encodetile; /* parent codec encode/decode tile */ + TIFFPostMethod encodepfunc; /* horizontal differencer */ + + TIFFCodeMethod decoderow; /* parent codec encode/decode row */ + TIFFCodeMethod decodestrip; /* parent codec encode/decode strip */ + TIFFCodeMethod decodetile; /* parent codec encode/decode tile */ + TIFFPostMethod decodepfunc; /* horizontal accumulator */ + + TIFFVGetMethod vgetparent; /* super-class method */ + TIFFVSetMethod vsetparent; /* super-class method */ + TIFFPrintMethod printdir; /* super-class method */ + TIFFBoolMethod setupdecode; /* super-class method */ + TIFFBoolMethod setupencode; /* super-class method */ +} TIFFPredictorState; + +#if defined(__cplusplus) +extern "C" { +#endif +extern int TIFFPredictorInit(TIFF*); +extern int TIFFPredictorCleanup(TIFF*); +#if defined(__cplusplus) +} +#endif +#endif /* _TIFFPREDICT_ */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_print.c b/Source/LibTIFF4/tif_print.c index 9b2b09e..1de3cb1 100644 --- a/Source/LibTIFF4/tif_print.c +++ b/Source/LibTIFF4/tif_print.c @@ -1,716 +1,716 @@ -/* $Id: tif_print.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * - * Directory Printing Support - */ -#include "tiffiop.h" -#include - -#include - -static void -_TIFFprintAsciiBounded(FILE* fd, const char* cp, int max_chars); - -static const char *photoNames[] = { - "min-is-white", /* PHOTOMETRIC_MINISWHITE */ - "min-is-black", /* PHOTOMETRIC_MINISBLACK */ - "RGB color", /* PHOTOMETRIC_RGB */ - "palette color (RGB from colormap)", /* PHOTOMETRIC_PALETTE */ - "transparency mask", /* PHOTOMETRIC_MASK */ - "separated", /* PHOTOMETRIC_SEPARATED */ - "YCbCr", /* PHOTOMETRIC_YCBCR */ - "7 (0x7)", - "CIE L*a*b*", /* PHOTOMETRIC_CIELAB */ - "ICC L*a*b*", /* PHOTOMETRIC_ICCLAB */ - "ITU L*a*b*" /* PHOTOMETRIC_ITULAB */ -}; -#define NPHOTONAMES (sizeof (photoNames) / sizeof (photoNames[0])) - -static const char *orientNames[] = { - "0 (0x0)", - "row 0 top, col 0 lhs", /* ORIENTATION_TOPLEFT */ - "row 0 top, col 0 rhs", /* ORIENTATION_TOPRIGHT */ - "row 0 bottom, col 0 rhs", /* ORIENTATION_BOTRIGHT */ - "row 0 bottom, col 0 lhs", /* ORIENTATION_BOTLEFT */ - "row 0 lhs, col 0 top", /* ORIENTATION_LEFTTOP */ - "row 0 rhs, col 0 top", /* ORIENTATION_RIGHTTOP */ - "row 0 rhs, col 0 bottom", /* ORIENTATION_RIGHTBOT */ - "row 0 lhs, col 0 bottom", /* ORIENTATION_LEFTBOT */ -}; -#define NORIENTNAMES (sizeof (orientNames) / sizeof (orientNames[0])) - -static void -_TIFFPrintField(FILE* fd, const TIFFField *fip, - uint32 value_count, void *raw_data) -{ - uint32 j; - - fprintf(fd, " %s: ", fip->field_name); - - for(j = 0; j < value_count; j++) { - if(fip->field_type == TIFF_BYTE) - fprintf(fd, "%u", ((uint8 *) raw_data)[j]); - else if(fip->field_type == TIFF_UNDEFINED) - fprintf(fd, "0x%x", - (unsigned int) ((unsigned char *) raw_data)[j]); - else if(fip->field_type == TIFF_SBYTE) - fprintf(fd, "%d", ((int8 *) raw_data)[j]); - else if(fip->field_type == TIFF_SHORT) - fprintf(fd, "%u", ((uint16 *) raw_data)[j]); - else if(fip->field_type == TIFF_SSHORT) - fprintf(fd, "%d", ((int16 *) raw_data)[j]); - else if(fip->field_type == TIFF_LONG) - fprintf(fd, "%lu", - (unsigned long)((uint32 *) raw_data)[j]); - else if(fip->field_type == TIFF_SLONG) - fprintf(fd, "%ld", (long)((int32 *) raw_data)[j]); - else if(fip->field_type == TIFF_IFD) - fprintf(fd, "0x%lx", - (unsigned long)((uint32 *) raw_data)[j]); - else if(fip->field_type == TIFF_RATIONAL - || fip->field_type == TIFF_SRATIONAL - || fip->field_type == TIFF_FLOAT) - fprintf(fd, "%f", ((float *) raw_data)[j]); - else if(fip->field_type == TIFF_LONG8) -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - fprintf(fd, "%I64u", - (unsigned __int64)((uint64 *) raw_data)[j]); -#else - fprintf(fd, "%llu", - (unsigned long long)((uint64 *) raw_data)[j]); -#endif - else if(fip->field_type == TIFF_SLONG8) -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - fprintf(fd, "%I64d", (__int64)((int64 *) raw_data)[j]); -#else - fprintf(fd, "%lld", (long long)((int64 *) raw_data)[j]); -#endif - else if(fip->field_type == TIFF_IFD8) -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - fprintf(fd, "0x%I64x", - (unsigned __int64)((uint64 *) raw_data)[j]); -#else - fprintf(fd, "0x%llx", - (unsigned long long)((uint64 *) raw_data)[j]); -#endif - else if(fip->field_type == TIFF_FLOAT) - fprintf(fd, "%f", ((float *)raw_data)[j]); - else if(fip->field_type == TIFF_DOUBLE) - fprintf(fd, "%f", ((double *) raw_data)[j]); - else if(fip->field_type == TIFF_ASCII) { - fprintf(fd, "%s", (char *) raw_data); - break; - } - else { - fprintf(fd, ""); - break; - } - - if(j < value_count - 1) - fprintf(fd, ","); - } - - fprintf(fd, "\n"); -} - -static int -_TIFFPrettyPrintField(TIFF* tif, const TIFFField *fip, FILE* fd, uint32 tag, - uint32 value_count, void *raw_data) -{ - (void) tif; - - /* do not try to pretty print auto-defined fields */ - if (strncmp(fip->field_name,"Tag ", 4) == 0) { - return 0; - } - - switch (tag) - { - case TIFFTAG_INKSET: - if (value_count == 2 && fip->field_type == TIFF_SHORT) { - fprintf(fd, " Ink Set: "); - switch (*((uint16*)raw_data)) { - case INKSET_CMYK: - fprintf(fd, "CMYK\n"); - break; - default: - fprintf(fd, "%u (0x%x)\n", - *((uint16*)raw_data), - *((uint16*)raw_data)); - break; - } - return 1; - } - return 0; - - case TIFFTAG_DOTRANGE: - if (value_count == 2 && fip->field_type == TIFF_SHORT) { - fprintf(fd, " Dot Range: %u-%u\n", - ((uint16*)raw_data)[0], ((uint16*)raw_data)[1]); - return 1; - } - return 0; - - case TIFFTAG_WHITEPOINT: - if (value_count == 2 && fip->field_type == TIFF_RATIONAL) { - fprintf(fd, " White Point: %g-%g\n", - ((float *)raw_data)[0], ((float *)raw_data)[1]); - return 1; - } - return 0; - - case TIFFTAG_XMLPACKET: - { - uint32 i; - - fprintf(fd, " XMLPacket (XMP Metadata):\n" ); - for(i = 0; i < value_count; i++) - fputc(((char *)raw_data)[i], fd); - fprintf( fd, "\n" ); - return 1; - } - case TIFFTAG_RICHTIFFIPTC: - /* - * XXX: for some weird reason RichTIFFIPTC tag - * defined as array of LONG values. - */ - fprintf(fd, - " RichTIFFIPTC Data: , %lu bytes\n", - (unsigned long) value_count * 4); - return 1; - - case TIFFTAG_PHOTOSHOP: - fprintf(fd, " Photoshop Data: , %lu bytes\n", - (unsigned long) value_count); - return 1; - - case TIFFTAG_ICCPROFILE: - fprintf(fd, " ICC Profile: , %lu bytes\n", - (unsigned long) value_count); - return 1; - - case TIFFTAG_STONITS: - if (value_count == 1 && fip->field_type == TIFF_DOUBLE) { - fprintf(fd, - " Sample to Nits conversion factor: %.4e\n", - *((double*)raw_data)); - return 1; - } - return 0; - } - - return 0; -} - -/* - * Print the contents of the current directory - * to the specified stdio file stream. - */ -void -TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) -{ - TIFFDirectory *td = &tif->tif_dir; - char *sep; - uint16 i; - long l, n; - -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - fprintf(fd, "TIFF Directory at offset 0x%I64x (%I64u)\n", - (unsigned __int64) tif->tif_diroff, - (unsigned __int64) tif->tif_diroff); -#else - fprintf(fd, "TIFF Directory at offset 0x%llx (%llu)\n", - (unsigned long long) tif->tif_diroff, - (unsigned long long) tif->tif_diroff); -#endif - if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) { - fprintf(fd, " Subfile Type:"); - sep = " "; - if (td->td_subfiletype & FILETYPE_REDUCEDIMAGE) { - fprintf(fd, "%sreduced-resolution image", sep); - sep = "/"; - } - if (td->td_subfiletype & FILETYPE_PAGE) { - fprintf(fd, "%smulti-page document", sep); - sep = "/"; - } - if (td->td_subfiletype & FILETYPE_MASK) - fprintf(fd, "%stransparency mask", sep); - fprintf(fd, " (%lu = 0x%lx)\n", - (long) td->td_subfiletype, (long) td->td_subfiletype); - } - if (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS)) { - fprintf(fd, " Image Width: %lu Image Length: %lu", - (unsigned long) td->td_imagewidth, (unsigned long) td->td_imagelength); - if (TIFFFieldSet(tif,FIELD_IMAGEDEPTH)) - fprintf(fd, " Image Depth: %lu", - (unsigned long) td->td_imagedepth); - fprintf(fd, "\n"); - } - if (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS)) { - fprintf(fd, " Tile Width: %lu Tile Length: %lu", - (unsigned long) td->td_tilewidth, (unsigned long) td->td_tilelength); - if (TIFFFieldSet(tif,FIELD_TILEDEPTH)) - fprintf(fd, " Tile Depth: %lu", - (unsigned long) td->td_tiledepth); - fprintf(fd, "\n"); - } - if (TIFFFieldSet(tif,FIELD_RESOLUTION)) { - fprintf(fd, " Resolution: %g, %g", - td->td_xresolution, td->td_yresolution); - if (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT)) { - switch (td->td_resolutionunit) { - case RESUNIT_NONE: - fprintf(fd, " (unitless)"); - break; - case RESUNIT_INCH: - fprintf(fd, " pixels/inch"); - break; - case RESUNIT_CENTIMETER: - fprintf(fd, " pixels/cm"); - break; - default: - fprintf(fd, " (unit %u = 0x%x)", - td->td_resolutionunit, - td->td_resolutionunit); - break; - } - } - fprintf(fd, "\n"); - } - if (TIFFFieldSet(tif,FIELD_POSITION)) - fprintf(fd, " Position: %g, %g\n", - td->td_xposition, td->td_yposition); - if (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE)) - fprintf(fd, " Bits/Sample: %u\n", td->td_bitspersample); - if (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT)) { - fprintf(fd, " Sample Format: "); - switch (td->td_sampleformat) { - case SAMPLEFORMAT_VOID: - fprintf(fd, "void\n"); - break; - case SAMPLEFORMAT_INT: - fprintf(fd, "signed integer\n"); - break; - case SAMPLEFORMAT_UINT: - fprintf(fd, "unsigned integer\n"); - break; - case SAMPLEFORMAT_IEEEFP: - fprintf(fd, "IEEE floating point\n"); - break; - case SAMPLEFORMAT_COMPLEXINT: - fprintf(fd, "complex signed integer\n"); - break; - case SAMPLEFORMAT_COMPLEXIEEEFP: - fprintf(fd, "complex IEEE floating point\n"); - break; - default: - fprintf(fd, "%u (0x%x)\n", - td->td_sampleformat, td->td_sampleformat); - break; - } - } - if (TIFFFieldSet(tif,FIELD_COMPRESSION)) { - const TIFFCodec* c = TIFFFindCODEC(td->td_compression); - fprintf(fd, " Compression Scheme: "); - if (c) - fprintf(fd, "%s\n", c->name); - else - fprintf(fd, "%u (0x%x)\n", - td->td_compression, td->td_compression); - } - if (TIFFFieldSet(tif,FIELD_PHOTOMETRIC)) { - fprintf(fd, " Photometric Interpretation: "); - if (td->td_photometric < NPHOTONAMES) - fprintf(fd, "%s\n", photoNames[td->td_photometric]); - else { - switch (td->td_photometric) { - case PHOTOMETRIC_LOGL: - fprintf(fd, "CIE Log2(L)\n"); - break; - case PHOTOMETRIC_LOGLUV: - fprintf(fd, "CIE Log2(L) (u',v')\n"); - break; - default: - fprintf(fd, "%u (0x%x)\n", - td->td_photometric, td->td_photometric); - break; - } - } - } - if (TIFFFieldSet(tif,FIELD_EXTRASAMPLES) && td->td_extrasamples) { - fprintf(fd, " Extra Samples: %u<", td->td_extrasamples); - sep = ""; - for (i = 0; i < td->td_extrasamples; i++) { - switch (td->td_sampleinfo[i]) { - case EXTRASAMPLE_UNSPECIFIED: - fprintf(fd, "%sunspecified", sep); - break; - case EXTRASAMPLE_ASSOCALPHA: - fprintf(fd, "%sassoc-alpha", sep); - break; - case EXTRASAMPLE_UNASSALPHA: - fprintf(fd, "%sunassoc-alpha", sep); - break; - default: - fprintf(fd, "%s%u (0x%x)", sep, - td->td_sampleinfo[i], td->td_sampleinfo[i]); - break; - } - sep = ", "; - } - fprintf(fd, ">\n"); - } - if (TIFFFieldSet(tif,FIELD_INKNAMES)) { - char* cp; - fprintf(fd, " Ink Names: "); - i = td->td_samplesperpixel; - sep = ""; - for (cp = td->td_inknames; - i > 0 && cp < td->td_inknames + td->td_inknameslen; - cp = strchr(cp,'\0')+1, i--) { - int max_chars = - td->td_inknameslen - (cp - td->td_inknames); - fputs(sep, fd); - _TIFFprintAsciiBounded(fd, cp, max_chars); - sep = ", "; - } - fputs("\n", fd); - } - if (TIFFFieldSet(tif,FIELD_THRESHHOLDING)) { - fprintf(fd, " Thresholding: "); - switch (td->td_threshholding) { - case THRESHHOLD_BILEVEL: - fprintf(fd, "bilevel art scan\n"); - break; - case THRESHHOLD_HALFTONE: - fprintf(fd, "halftone or dithered scan\n"); - break; - case THRESHHOLD_ERRORDIFFUSE: - fprintf(fd, "error diffused\n"); - break; - default: - fprintf(fd, "%u (0x%x)\n", - td->td_threshholding, td->td_threshholding); - break; - } - } - if (TIFFFieldSet(tif,FIELD_FILLORDER)) { - fprintf(fd, " FillOrder: "); - switch (td->td_fillorder) { - case FILLORDER_MSB2LSB: - fprintf(fd, "msb-to-lsb\n"); - break; - case FILLORDER_LSB2MSB: - fprintf(fd, "lsb-to-msb\n"); - break; - default: - fprintf(fd, "%u (0x%x)\n", - td->td_fillorder, td->td_fillorder); - break; - } - } - if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING)) - { - fprintf(fd, " YCbCr Subsampling: %u, %u\n", - td->td_ycbcrsubsampling[0], td->td_ycbcrsubsampling[1] ); - } - if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) { - fprintf(fd, " YCbCr Positioning: "); - switch (td->td_ycbcrpositioning) { - case YCBCRPOSITION_CENTERED: - fprintf(fd, "centered\n"); - break; - case YCBCRPOSITION_COSITED: - fprintf(fd, "cosited\n"); - break; - default: - fprintf(fd, "%u (0x%x)\n", - td->td_ycbcrpositioning, td->td_ycbcrpositioning); - break; - } - } - if (TIFFFieldSet(tif,FIELD_HALFTONEHINTS)) - fprintf(fd, " Halftone Hints: light %u dark %u\n", - td->td_halftonehints[0], td->td_halftonehints[1]); - if (TIFFFieldSet(tif,FIELD_ORIENTATION)) { - fprintf(fd, " Orientation: "); - if (td->td_orientation < NORIENTNAMES) - fprintf(fd, "%s\n", orientNames[td->td_orientation]); - else - fprintf(fd, "%u (0x%x)\n", - td->td_orientation, td->td_orientation); - } - if (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL)) - fprintf(fd, " Samples/Pixel: %u\n", td->td_samplesperpixel); - if (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP)) { - fprintf(fd, " Rows/Strip: "); - if (td->td_rowsperstrip == (uint32) -1) - fprintf(fd, "(infinite)\n"); - else - fprintf(fd, "%lu\n", (unsigned long) td->td_rowsperstrip); - } - if (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE)) - fprintf(fd, " Min Sample Value: %u\n", td->td_minsamplevalue); - if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE)) - fprintf(fd, " Max Sample Value: %u\n", td->td_maxsamplevalue); - if (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE)) { - int count = (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1; - fprintf(fd, " SMin Sample Value:"); - for (i = 0; i < count; ++i) - fprintf(fd, " %g", td->td_sminsamplevalue[i]); - fprintf(fd, "\n"); - } - if (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE)) { - int count = (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1; - fprintf(fd, " SMax Sample Value:"); - for (i = 0; i < count; ++i) - fprintf(fd, " %g", td->td_smaxsamplevalue[i]); - fprintf(fd, "\n"); - } - if (TIFFFieldSet(tif,FIELD_PLANARCONFIG)) { - fprintf(fd, " Planar Configuration: "); - switch (td->td_planarconfig) { - case PLANARCONFIG_CONTIG: - fprintf(fd, "single image plane\n"); - break; - case PLANARCONFIG_SEPARATE: - fprintf(fd, "separate image planes\n"); - break; - default: - fprintf(fd, "%u (0x%x)\n", - td->td_planarconfig, td->td_planarconfig); - break; - } - } - if (TIFFFieldSet(tif,FIELD_PAGENUMBER)) - fprintf(fd, " Page Number: %u-%u\n", - td->td_pagenumber[0], td->td_pagenumber[1]); - if (TIFFFieldSet(tif,FIELD_COLORMAP)) { - fprintf(fd, " Color Map: "); - if (flags & TIFFPRINT_COLORMAP) { - fprintf(fd, "\n"); - n = 1L<td_bitspersample; - for (l = 0; l < n; l++) - fprintf(fd, " %5lu: %5u %5u %5u\n", - l, - td->td_colormap[0][l], - td->td_colormap[1][l], - td->td_colormap[2][l]); - } else - fprintf(fd, "(present)\n"); - } - if (TIFFFieldSet(tif,FIELD_REFBLACKWHITE)) { - fprintf(fd, " Reference Black/White:\n"); - for (i = 0; i < 3; i++) - fprintf(fd, " %2d: %5g %5g\n", i, - td->td_refblackwhite[2*i+0], - td->td_refblackwhite[2*i+1]); - } - if (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION)) { - fprintf(fd, " Transfer Function: "); - if (flags & TIFFPRINT_CURVES) { - fprintf(fd, "\n"); - n = 1L<td_bitspersample; - for (l = 0; l < n; l++) { - fprintf(fd, " %2lu: %5u", - l, td->td_transferfunction[0][l]); - for (i = 1; i < td->td_samplesperpixel; i++) - fprintf(fd, " %5u", - td->td_transferfunction[i][l]); - fputc('\n', fd); - } - } else - fprintf(fd, "(present)\n"); - } - if (TIFFFieldSet(tif, FIELD_SUBIFD) && (td->td_subifd)) { - fprintf(fd, " SubIFD Offsets:"); - for (i = 0; i < td->td_nsubifd; i++) -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - fprintf(fd, " %5I64u", - (unsigned __int64) td->td_subifd[i]); -#else - fprintf(fd, " %5llu", - (unsigned long long) td->td_subifd[i]); -#endif - fputc('\n', fd); - } - - /* - ** Custom tag support. - */ - { - int i; - short count; - - count = (short) TIFFGetTagListCount(tif); - for(i = 0; i < count; i++) { - uint32 tag = TIFFGetTagListEntry(tif, i); - const TIFFField *fip; - uint32 value_count; - int mem_alloc = 0; - void *raw_data; - - fip = TIFFFieldWithTag(tif, tag); - if(fip == NULL) - continue; - - if(fip->field_passcount) { - if (fip->field_readcount == TIFF_VARIABLE ) { - if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1) - continue; - } else if (fip->field_readcount == TIFF_VARIABLE2 ) { - uint16 small_value_count; - if(TIFFGetField(tif, tag, &small_value_count, &raw_data) != 1) - continue; - value_count = small_value_count; - } else { - assert (fip->field_readcount == TIFF_VARIABLE - || fip->field_readcount == TIFF_VARIABLE2); - continue; - } - } else { - if (fip->field_readcount == TIFF_VARIABLE - || fip->field_readcount == TIFF_VARIABLE2) - value_count = 1; - else if (fip->field_readcount == TIFF_SPP) - value_count = td->td_samplesperpixel; - else - value_count = fip->field_readcount; - if (fip->field_tag == TIFFTAG_DOTRANGE - && strcmp(fip->field_name,"DotRange") == 0) { - /* TODO: This is an evil exception and should not have been - handled this way ... likely best if we move it into - the directory structure with an explicit field in - libtiff 4.1 and assign it a FIELD_ value */ - static uint16 dotrange[2]; - raw_data = dotrange; - TIFFGetField(tif, tag, dotrange+0, dotrange+1); - } else if (fip->field_type == TIFF_ASCII - || fip->field_readcount == TIFF_VARIABLE - || fip->field_readcount == TIFF_VARIABLE2 - || fip->field_readcount == TIFF_SPP - || value_count > 1) { - if(TIFFGetField(tif, tag, &raw_data) != 1) - continue; - } else { - raw_data = _TIFFmalloc( - _TIFFDataSize(fip->field_type) - * value_count); - mem_alloc = 1; - if(TIFFGetField(tif, tag, raw_data) != 1) { - _TIFFfree(raw_data); - continue; - } - } - } - - /* - * Catch the tags which needs to be specially handled - * and pretty print them. If tag not handled in - * _TIFFPrettyPrintField() fall down and print it as - * any other tag. - */ - if (!_TIFFPrettyPrintField(tif, fip, fd, tag, value_count, raw_data)) - _TIFFPrintField(fd, fip, value_count, raw_data); - - if(mem_alloc) - _TIFFfree(raw_data); - } - } - - if (tif->tif_tagmethods.printdir) - (*tif->tif_tagmethods.printdir)(tif, fd, flags); - - _TIFFFillStriles( tif ); - - if ((flags & TIFFPRINT_STRIPS) && - TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) { - uint32 s; - - fprintf(fd, " %lu %s:\n", - (long) td->td_nstrips, - isTiled(tif) ? "Tiles" : "Strips"); - for (s = 0; s < td->td_nstrips; s++) -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - fprintf(fd, " %3lu: [%8I64u, %8I64u]\n", - (unsigned long) s, - (unsigned __int64) td->td_stripoffset[s], - (unsigned __int64) td->td_stripbytecount[s]); -#else - fprintf(fd, " %3lu: [%8llu, %8llu]\n", - (unsigned long) s, - (unsigned long long) td->td_stripoffset[s], - (unsigned long long) td->td_stripbytecount[s]); -#endif - } -} - -void -_TIFFprintAscii(FILE* fd, const char* cp) -{ - _TIFFprintAsciiBounded( fd, cp, strlen(cp)); -} - -static void -_TIFFprintAsciiBounded(FILE* fd, const char* cp, int max_chars) -{ - for (; max_chars > 0 && *cp != '\0'; cp++, max_chars--) { - const char* tp; - - if (isprint((int)*cp)) { - fputc(*cp, fd); - continue; - } - for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++) - if (*tp++ == *cp) - break; - if (*tp) - fprintf(fd, "\\%c", *tp); - else - fprintf(fd, "\\%03o", *cp & 0xff); - } -} - -void -_TIFFprintAsciiTag(FILE* fd, const char* name, const char* value) -{ - fprintf(fd, " %s: \"", name); - _TIFFprintAscii(fd, value); - fprintf(fd, "\"\n"); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_print.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * + * Directory Printing Support + */ +#include "tiffiop.h" +#include + +#include + +static void +_TIFFprintAsciiBounded(FILE* fd, const char* cp, int max_chars); + +static const char *photoNames[] = { + "min-is-white", /* PHOTOMETRIC_MINISWHITE */ + "min-is-black", /* PHOTOMETRIC_MINISBLACK */ + "RGB color", /* PHOTOMETRIC_RGB */ + "palette color (RGB from colormap)", /* PHOTOMETRIC_PALETTE */ + "transparency mask", /* PHOTOMETRIC_MASK */ + "separated", /* PHOTOMETRIC_SEPARATED */ + "YCbCr", /* PHOTOMETRIC_YCBCR */ + "7 (0x7)", + "CIE L*a*b*", /* PHOTOMETRIC_CIELAB */ + "ICC L*a*b*", /* PHOTOMETRIC_ICCLAB */ + "ITU L*a*b*" /* PHOTOMETRIC_ITULAB */ +}; +#define NPHOTONAMES (sizeof (photoNames) / sizeof (photoNames[0])) + +static const char *orientNames[] = { + "0 (0x0)", + "row 0 top, col 0 lhs", /* ORIENTATION_TOPLEFT */ + "row 0 top, col 0 rhs", /* ORIENTATION_TOPRIGHT */ + "row 0 bottom, col 0 rhs", /* ORIENTATION_BOTRIGHT */ + "row 0 bottom, col 0 lhs", /* ORIENTATION_BOTLEFT */ + "row 0 lhs, col 0 top", /* ORIENTATION_LEFTTOP */ + "row 0 rhs, col 0 top", /* ORIENTATION_RIGHTTOP */ + "row 0 rhs, col 0 bottom", /* ORIENTATION_RIGHTBOT */ + "row 0 lhs, col 0 bottom", /* ORIENTATION_LEFTBOT */ +}; +#define NORIENTNAMES (sizeof (orientNames) / sizeof (orientNames[0])) + +static void +_TIFFPrintField(FILE* fd, const TIFFField *fip, + uint32 value_count, void *raw_data) +{ + uint32 j; + + fprintf(fd, " %s: ", fip->field_name); + + for(j = 0; j < value_count; j++) { + if(fip->field_type == TIFF_BYTE) + fprintf(fd, "%u", ((uint8 *) raw_data)[j]); + else if(fip->field_type == TIFF_UNDEFINED) + fprintf(fd, "0x%x", + (unsigned int) ((unsigned char *) raw_data)[j]); + else if(fip->field_type == TIFF_SBYTE) + fprintf(fd, "%d", ((int8 *) raw_data)[j]); + else if(fip->field_type == TIFF_SHORT) + fprintf(fd, "%u", ((uint16 *) raw_data)[j]); + else if(fip->field_type == TIFF_SSHORT) + fprintf(fd, "%d", ((int16 *) raw_data)[j]); + else if(fip->field_type == TIFF_LONG) + fprintf(fd, "%lu", + (unsigned long)((uint32 *) raw_data)[j]); + else if(fip->field_type == TIFF_SLONG) + fprintf(fd, "%ld", (long)((int32 *) raw_data)[j]); + else if(fip->field_type == TIFF_IFD) + fprintf(fd, "0x%lx", + (unsigned long)((uint32 *) raw_data)[j]); + else if(fip->field_type == TIFF_RATIONAL + || fip->field_type == TIFF_SRATIONAL + || fip->field_type == TIFF_FLOAT) + fprintf(fd, "%f", ((float *) raw_data)[j]); + else if(fip->field_type == TIFF_LONG8) +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + fprintf(fd, "%I64u", + (unsigned __int64)((uint64 *) raw_data)[j]); +#else + fprintf(fd, "%llu", + (unsigned long long)((uint64 *) raw_data)[j]); +#endif + else if(fip->field_type == TIFF_SLONG8) +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + fprintf(fd, "%I64d", (__int64)((int64 *) raw_data)[j]); +#else + fprintf(fd, "%lld", (long long)((int64 *) raw_data)[j]); +#endif + else if(fip->field_type == TIFF_IFD8) +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + fprintf(fd, "0x%I64x", + (unsigned __int64)((uint64 *) raw_data)[j]); +#else + fprintf(fd, "0x%llx", + (unsigned long long)((uint64 *) raw_data)[j]); +#endif + else if(fip->field_type == TIFF_FLOAT) + fprintf(fd, "%f", ((float *)raw_data)[j]); + else if(fip->field_type == TIFF_DOUBLE) + fprintf(fd, "%f", ((double *) raw_data)[j]); + else if(fip->field_type == TIFF_ASCII) { + fprintf(fd, "%s", (char *) raw_data); + break; + } + else { + fprintf(fd, ""); + break; + } + + if(j < value_count - 1) + fprintf(fd, ","); + } + + fprintf(fd, "\n"); +} + +static int +_TIFFPrettyPrintField(TIFF* tif, const TIFFField *fip, FILE* fd, uint32 tag, + uint32 value_count, void *raw_data) +{ + (void) tif; + + /* do not try to pretty print auto-defined fields */ + if (strncmp(fip->field_name,"Tag ", 4) == 0) { + return 0; + } + + switch (tag) + { + case TIFFTAG_INKSET: + if (value_count == 2 && fip->field_type == TIFF_SHORT) { + fprintf(fd, " Ink Set: "); + switch (*((uint16*)raw_data)) { + case INKSET_CMYK: + fprintf(fd, "CMYK\n"); + break; + default: + fprintf(fd, "%u (0x%x)\n", + *((uint16*)raw_data), + *((uint16*)raw_data)); + break; + } + return 1; + } + return 0; + + case TIFFTAG_DOTRANGE: + if (value_count == 2 && fip->field_type == TIFF_SHORT) { + fprintf(fd, " Dot Range: %u-%u\n", + ((uint16*)raw_data)[0], ((uint16*)raw_data)[1]); + return 1; + } + return 0; + + case TIFFTAG_WHITEPOINT: + if (value_count == 2 && fip->field_type == TIFF_RATIONAL) { + fprintf(fd, " White Point: %g-%g\n", + ((float *)raw_data)[0], ((float *)raw_data)[1]); + return 1; + } + return 0; + + case TIFFTAG_XMLPACKET: + { + uint32 i; + + fprintf(fd, " XMLPacket (XMP Metadata):\n" ); + for(i = 0; i < value_count; i++) + fputc(((char *)raw_data)[i], fd); + fprintf( fd, "\n" ); + return 1; + } + case TIFFTAG_RICHTIFFIPTC: + /* + * XXX: for some weird reason RichTIFFIPTC tag + * defined as array of LONG values. + */ + fprintf(fd, + " RichTIFFIPTC Data: , %lu bytes\n", + (unsigned long) value_count * 4); + return 1; + + case TIFFTAG_PHOTOSHOP: + fprintf(fd, " Photoshop Data: , %lu bytes\n", + (unsigned long) value_count); + return 1; + + case TIFFTAG_ICCPROFILE: + fprintf(fd, " ICC Profile: , %lu bytes\n", + (unsigned long) value_count); + return 1; + + case TIFFTAG_STONITS: + if (value_count == 1 && fip->field_type == TIFF_DOUBLE) { + fprintf(fd, + " Sample to Nits conversion factor: %.4e\n", + *((double*)raw_data)); + return 1; + } + return 0; + } + + return 0; +} + +/* + * Print the contents of the current directory + * to the specified stdio file stream. + */ +void +TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) +{ + TIFFDirectory *td = &tif->tif_dir; + char *sep; + uint16 i; + long l, n; + +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + fprintf(fd, "TIFF Directory at offset 0x%I64x (%I64u)\n", + (unsigned __int64) tif->tif_diroff, + (unsigned __int64) tif->tif_diroff); +#else + fprintf(fd, "TIFF Directory at offset 0x%llx (%llu)\n", + (unsigned long long) tif->tif_diroff, + (unsigned long long) tif->tif_diroff); +#endif + if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) { + fprintf(fd, " Subfile Type:"); + sep = " "; + if (td->td_subfiletype & FILETYPE_REDUCEDIMAGE) { + fprintf(fd, "%sreduced-resolution image", sep); + sep = "/"; + } + if (td->td_subfiletype & FILETYPE_PAGE) { + fprintf(fd, "%smulti-page document", sep); + sep = "/"; + } + if (td->td_subfiletype & FILETYPE_MASK) + fprintf(fd, "%stransparency mask", sep); + fprintf(fd, " (%lu = 0x%lx)\n", + (long) td->td_subfiletype, (long) td->td_subfiletype); + } + if (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS)) { + fprintf(fd, " Image Width: %lu Image Length: %lu", + (unsigned long) td->td_imagewidth, (unsigned long) td->td_imagelength); + if (TIFFFieldSet(tif,FIELD_IMAGEDEPTH)) + fprintf(fd, " Image Depth: %lu", + (unsigned long) td->td_imagedepth); + fprintf(fd, "\n"); + } + if (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS)) { + fprintf(fd, " Tile Width: %lu Tile Length: %lu", + (unsigned long) td->td_tilewidth, (unsigned long) td->td_tilelength); + if (TIFFFieldSet(tif,FIELD_TILEDEPTH)) + fprintf(fd, " Tile Depth: %lu", + (unsigned long) td->td_tiledepth); + fprintf(fd, "\n"); + } + if (TIFFFieldSet(tif,FIELD_RESOLUTION)) { + fprintf(fd, " Resolution: %g, %g", + td->td_xresolution, td->td_yresolution); + if (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT)) { + switch (td->td_resolutionunit) { + case RESUNIT_NONE: + fprintf(fd, " (unitless)"); + break; + case RESUNIT_INCH: + fprintf(fd, " pixels/inch"); + break; + case RESUNIT_CENTIMETER: + fprintf(fd, " pixels/cm"); + break; + default: + fprintf(fd, " (unit %u = 0x%x)", + td->td_resolutionunit, + td->td_resolutionunit); + break; + } + } + fprintf(fd, "\n"); + } + if (TIFFFieldSet(tif,FIELD_POSITION)) + fprintf(fd, " Position: %g, %g\n", + td->td_xposition, td->td_yposition); + if (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE)) + fprintf(fd, " Bits/Sample: %u\n", td->td_bitspersample); + if (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT)) { + fprintf(fd, " Sample Format: "); + switch (td->td_sampleformat) { + case SAMPLEFORMAT_VOID: + fprintf(fd, "void\n"); + break; + case SAMPLEFORMAT_INT: + fprintf(fd, "signed integer\n"); + break; + case SAMPLEFORMAT_UINT: + fprintf(fd, "unsigned integer\n"); + break; + case SAMPLEFORMAT_IEEEFP: + fprintf(fd, "IEEE floating point\n"); + break; + case SAMPLEFORMAT_COMPLEXINT: + fprintf(fd, "complex signed integer\n"); + break; + case SAMPLEFORMAT_COMPLEXIEEEFP: + fprintf(fd, "complex IEEE floating point\n"); + break; + default: + fprintf(fd, "%u (0x%x)\n", + td->td_sampleformat, td->td_sampleformat); + break; + } + } + if (TIFFFieldSet(tif,FIELD_COMPRESSION)) { + const TIFFCodec* c = TIFFFindCODEC(td->td_compression); + fprintf(fd, " Compression Scheme: "); + if (c) + fprintf(fd, "%s\n", c->name); + else + fprintf(fd, "%u (0x%x)\n", + td->td_compression, td->td_compression); + } + if (TIFFFieldSet(tif,FIELD_PHOTOMETRIC)) { + fprintf(fd, " Photometric Interpretation: "); + if (td->td_photometric < NPHOTONAMES) + fprintf(fd, "%s\n", photoNames[td->td_photometric]); + else { + switch (td->td_photometric) { + case PHOTOMETRIC_LOGL: + fprintf(fd, "CIE Log2(L)\n"); + break; + case PHOTOMETRIC_LOGLUV: + fprintf(fd, "CIE Log2(L) (u',v')\n"); + break; + default: + fprintf(fd, "%u (0x%x)\n", + td->td_photometric, td->td_photometric); + break; + } + } + } + if (TIFFFieldSet(tif,FIELD_EXTRASAMPLES) && td->td_extrasamples) { + fprintf(fd, " Extra Samples: %u<", td->td_extrasamples); + sep = ""; + for (i = 0; i < td->td_extrasamples; i++) { + switch (td->td_sampleinfo[i]) { + case EXTRASAMPLE_UNSPECIFIED: + fprintf(fd, "%sunspecified", sep); + break; + case EXTRASAMPLE_ASSOCALPHA: + fprintf(fd, "%sassoc-alpha", sep); + break; + case EXTRASAMPLE_UNASSALPHA: + fprintf(fd, "%sunassoc-alpha", sep); + break; + default: + fprintf(fd, "%s%u (0x%x)", sep, + td->td_sampleinfo[i], td->td_sampleinfo[i]); + break; + } + sep = ", "; + } + fprintf(fd, ">\n"); + } + if (TIFFFieldSet(tif,FIELD_INKNAMES)) { + char* cp; + fprintf(fd, " Ink Names: "); + i = td->td_samplesperpixel; + sep = ""; + for (cp = td->td_inknames; + i > 0 && cp < td->td_inknames + td->td_inknameslen; + cp = strchr(cp,'\0')+1, i--) { + int max_chars = + td->td_inknameslen - (cp - td->td_inknames); + fputs(sep, fd); + _TIFFprintAsciiBounded(fd, cp, max_chars); + sep = ", "; + } + fputs("\n", fd); + } + if (TIFFFieldSet(tif,FIELD_THRESHHOLDING)) { + fprintf(fd, " Thresholding: "); + switch (td->td_threshholding) { + case THRESHHOLD_BILEVEL: + fprintf(fd, "bilevel art scan\n"); + break; + case THRESHHOLD_HALFTONE: + fprintf(fd, "halftone or dithered scan\n"); + break; + case THRESHHOLD_ERRORDIFFUSE: + fprintf(fd, "error diffused\n"); + break; + default: + fprintf(fd, "%u (0x%x)\n", + td->td_threshholding, td->td_threshholding); + break; + } + } + if (TIFFFieldSet(tif,FIELD_FILLORDER)) { + fprintf(fd, " FillOrder: "); + switch (td->td_fillorder) { + case FILLORDER_MSB2LSB: + fprintf(fd, "msb-to-lsb\n"); + break; + case FILLORDER_LSB2MSB: + fprintf(fd, "lsb-to-msb\n"); + break; + default: + fprintf(fd, "%u (0x%x)\n", + td->td_fillorder, td->td_fillorder); + break; + } + } + if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING)) + { + fprintf(fd, " YCbCr Subsampling: %u, %u\n", + td->td_ycbcrsubsampling[0], td->td_ycbcrsubsampling[1] ); + } + if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) { + fprintf(fd, " YCbCr Positioning: "); + switch (td->td_ycbcrpositioning) { + case YCBCRPOSITION_CENTERED: + fprintf(fd, "centered\n"); + break; + case YCBCRPOSITION_COSITED: + fprintf(fd, "cosited\n"); + break; + default: + fprintf(fd, "%u (0x%x)\n", + td->td_ycbcrpositioning, td->td_ycbcrpositioning); + break; + } + } + if (TIFFFieldSet(tif,FIELD_HALFTONEHINTS)) + fprintf(fd, " Halftone Hints: light %u dark %u\n", + td->td_halftonehints[0], td->td_halftonehints[1]); + if (TIFFFieldSet(tif,FIELD_ORIENTATION)) { + fprintf(fd, " Orientation: "); + if (td->td_orientation < NORIENTNAMES) + fprintf(fd, "%s\n", orientNames[td->td_orientation]); + else + fprintf(fd, "%u (0x%x)\n", + td->td_orientation, td->td_orientation); + } + if (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL)) + fprintf(fd, " Samples/Pixel: %u\n", td->td_samplesperpixel); + if (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP)) { + fprintf(fd, " Rows/Strip: "); + if (td->td_rowsperstrip == (uint32) -1) + fprintf(fd, "(infinite)\n"); + else + fprintf(fd, "%lu\n", (unsigned long) td->td_rowsperstrip); + } + if (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE)) + fprintf(fd, " Min Sample Value: %u\n", td->td_minsamplevalue); + if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE)) + fprintf(fd, " Max Sample Value: %u\n", td->td_maxsamplevalue); + if (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE)) { + int count = (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1; + fprintf(fd, " SMin Sample Value:"); + for (i = 0; i < count; ++i) + fprintf(fd, " %g", td->td_sminsamplevalue[i]); + fprintf(fd, "\n"); + } + if (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE)) { + int count = (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1; + fprintf(fd, " SMax Sample Value:"); + for (i = 0; i < count; ++i) + fprintf(fd, " %g", td->td_smaxsamplevalue[i]); + fprintf(fd, "\n"); + } + if (TIFFFieldSet(tif,FIELD_PLANARCONFIG)) { + fprintf(fd, " Planar Configuration: "); + switch (td->td_planarconfig) { + case PLANARCONFIG_CONTIG: + fprintf(fd, "single image plane\n"); + break; + case PLANARCONFIG_SEPARATE: + fprintf(fd, "separate image planes\n"); + break; + default: + fprintf(fd, "%u (0x%x)\n", + td->td_planarconfig, td->td_planarconfig); + break; + } + } + if (TIFFFieldSet(tif,FIELD_PAGENUMBER)) + fprintf(fd, " Page Number: %u-%u\n", + td->td_pagenumber[0], td->td_pagenumber[1]); + if (TIFFFieldSet(tif,FIELD_COLORMAP)) { + fprintf(fd, " Color Map: "); + if (flags & TIFFPRINT_COLORMAP) { + fprintf(fd, "\n"); + n = 1L<td_bitspersample; + for (l = 0; l < n; l++) + fprintf(fd, " %5lu: %5u %5u %5u\n", + l, + td->td_colormap[0][l], + td->td_colormap[1][l], + td->td_colormap[2][l]); + } else + fprintf(fd, "(present)\n"); + } + if (TIFFFieldSet(tif,FIELD_REFBLACKWHITE)) { + fprintf(fd, " Reference Black/White:\n"); + for (i = 0; i < 3; i++) + fprintf(fd, " %2d: %5g %5g\n", i, + td->td_refblackwhite[2*i+0], + td->td_refblackwhite[2*i+1]); + } + if (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION)) { + fprintf(fd, " Transfer Function: "); + if (flags & TIFFPRINT_CURVES) { + fprintf(fd, "\n"); + n = 1L<td_bitspersample; + for (l = 0; l < n; l++) { + fprintf(fd, " %2lu: %5u", + l, td->td_transferfunction[0][l]); + for (i = 1; i < td->td_samplesperpixel; i++) + fprintf(fd, " %5u", + td->td_transferfunction[i][l]); + fputc('\n', fd); + } + } else + fprintf(fd, "(present)\n"); + } + if (TIFFFieldSet(tif, FIELD_SUBIFD) && (td->td_subifd)) { + fprintf(fd, " SubIFD Offsets:"); + for (i = 0; i < td->td_nsubifd; i++) +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + fprintf(fd, " %5I64u", + (unsigned __int64) td->td_subifd[i]); +#else + fprintf(fd, " %5llu", + (unsigned long long) td->td_subifd[i]); +#endif + fputc('\n', fd); + } + + /* + ** Custom tag support. + */ + { + int i; + short count; + + count = (short) TIFFGetTagListCount(tif); + for(i = 0; i < count; i++) { + uint32 tag = TIFFGetTagListEntry(tif, i); + const TIFFField *fip; + uint32 value_count; + int mem_alloc = 0; + void *raw_data; + + fip = TIFFFieldWithTag(tif, tag); + if(fip == NULL) + continue; + + if(fip->field_passcount) { + if (fip->field_readcount == TIFF_VARIABLE ) { + if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1) + continue; + } else if (fip->field_readcount == TIFF_VARIABLE2 ) { + uint16 small_value_count; + if(TIFFGetField(tif, tag, &small_value_count, &raw_data) != 1) + continue; + value_count = small_value_count; + } else { + assert (fip->field_readcount == TIFF_VARIABLE + || fip->field_readcount == TIFF_VARIABLE2); + continue; + } + } else { + if (fip->field_readcount == TIFF_VARIABLE + || fip->field_readcount == TIFF_VARIABLE2) + value_count = 1; + else if (fip->field_readcount == TIFF_SPP) + value_count = td->td_samplesperpixel; + else + value_count = fip->field_readcount; + if (fip->field_tag == TIFFTAG_DOTRANGE + && strcmp(fip->field_name,"DotRange") == 0) { + /* TODO: This is an evil exception and should not have been + handled this way ... likely best if we move it into + the directory structure with an explicit field in + libtiff 4.1 and assign it a FIELD_ value */ + static uint16 dotrange[2]; + raw_data = dotrange; + TIFFGetField(tif, tag, dotrange+0, dotrange+1); + } else if (fip->field_type == TIFF_ASCII + || fip->field_readcount == TIFF_VARIABLE + || fip->field_readcount == TIFF_VARIABLE2 + || fip->field_readcount == TIFF_SPP + || value_count > 1) { + if(TIFFGetField(tif, tag, &raw_data) != 1) + continue; + } else { + raw_data = _TIFFmalloc( + _TIFFDataSize(fip->field_type) + * value_count); + mem_alloc = 1; + if(TIFFGetField(tif, tag, raw_data) != 1) { + _TIFFfree(raw_data); + continue; + } + } + } + + /* + * Catch the tags which needs to be specially handled + * and pretty print them. If tag not handled in + * _TIFFPrettyPrintField() fall down and print it as + * any other tag. + */ + if (!_TIFFPrettyPrintField(tif, fip, fd, tag, value_count, raw_data)) + _TIFFPrintField(fd, fip, value_count, raw_data); + + if(mem_alloc) + _TIFFfree(raw_data); + } + } + + if (tif->tif_tagmethods.printdir) + (*tif->tif_tagmethods.printdir)(tif, fd, flags); + + _TIFFFillStriles( tif ); + + if ((flags & TIFFPRINT_STRIPS) && + TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) { + uint32 s; + + fprintf(fd, " %lu %s:\n", + (long) td->td_nstrips, + isTiled(tif) ? "Tiles" : "Strips"); + for (s = 0; s < td->td_nstrips; s++) +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + fprintf(fd, " %3lu: [%8I64u, %8I64u]\n", + (unsigned long) s, + (unsigned __int64) td->td_stripoffset[s], + (unsigned __int64) td->td_stripbytecount[s]); +#else + fprintf(fd, " %3lu: [%8llu, %8llu]\n", + (unsigned long) s, + (unsigned long long) td->td_stripoffset[s], + (unsigned long long) td->td_stripbytecount[s]); +#endif + } +} + +void +_TIFFprintAscii(FILE* fd, const char* cp) +{ + _TIFFprintAsciiBounded( fd, cp, strlen(cp)); +} + +static void +_TIFFprintAsciiBounded(FILE* fd, const char* cp, int max_chars) +{ + for (; max_chars > 0 && *cp != '\0'; cp++, max_chars--) { + const char* tp; + + if (isprint((int)*cp)) { + fputc(*cp, fd); + continue; + } + for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++) + if (*tp++ == *cp) + break; + if (*tp) + fprintf(fd, "\\%c", *tp); + else + fprintf(fd, "\\%03o", *cp & 0xff); + } +} + +void +_TIFFprintAsciiTag(FILE* fd, const char* name, const char* value) +{ + fprintf(fd, " %s: \"", name); + _TIFFprintAscii(fd, value); + fprintf(fd, "\"\n"); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_read.c b/Source/LibTIFF4/tif_read.c index 4198a22..716f9ee 100644 --- a/Source/LibTIFF4/tif_read.c +++ b/Source/LibTIFF4/tif_read.c @@ -1,1083 +1,1083 @@ -/* $Id: tif_read.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * Scanline-oriented Read Support - */ -#include "tiffiop.h" -#include - -int TIFFFillStrip(TIFF* tif, uint32 strip); -int TIFFFillTile(TIFF* tif, uint32 tile); -static int TIFFStartStrip(TIFF* tif, uint32 strip); -static int TIFFStartTile(TIFF* tif, uint32 tile); -static int TIFFCheckRead(TIFF*, int); -static tmsize_t -TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size,const char* module); - -#define NOSTRIP ((uint32)(-1)) /* undefined state */ -#define NOTILE ((uint32)(-1)) /* undefined state */ - -static int -TIFFFillStripPartial( TIFF *tif, int strip, tmsize_t read_ahead, int restart ) -{ - static const char module[] = "TIFFFillStripPartial"; - register TIFFDirectory *td = &tif->tif_dir; - uint64 unused_data; - uint64 read_offset; - tmsize_t cc, to_read; - /* tmsize_t bytecountm; */ - - if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) - return 0; - - /* - * Expand raw data buffer, if needed, to hold data - * strip coming from file (perhaps should set upper - * bound on the size of a buffer we'll use?). - */ - - /* bytecountm=(tmsize_t) td->td_stripbytecount[strip]; */ - if (read_ahead*2 > tif->tif_rawdatasize) { - assert( restart ); - - tif->tif_curstrip = NOSTRIP; - if ((tif->tif_flags & TIFF_MYBUFFER) == 0) { - TIFFErrorExt(tif->tif_clientdata, module, - "Data buffer too small to hold part of strip %lu", - (unsigned long) strip); - return (0); - } - if (!TIFFReadBufferSetup(tif, 0, read_ahead*2)) - return (0); - } - - if( restart ) - { - tif->tif_rawdataloaded = 0; - tif->tif_rawdataoff = 0; - } - - /* - ** If we are reading more data, move any unused data to the - ** start of the buffer. - */ - if( tif->tif_rawdataloaded > 0 ) - unused_data = tif->tif_rawdataloaded - (tif->tif_rawcp - tif->tif_rawdata); - else - unused_data = 0; - - if( unused_data > 0 ) - { - assert((tif->tif_flags&TIFF_BUFFERMMAP)==0); - memmove( tif->tif_rawdata, tif->tif_rawcp, unused_data ); - } - - /* - ** Seek to the point in the file where more data should be read. - */ - read_offset = td->td_stripoffset[strip] - + tif->tif_rawdataoff + tif->tif_rawdataloaded; - - if (!SeekOK(tif, read_offset)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Seek error at scanline %lu, strip %lu", - (unsigned long) tif->tif_row, (unsigned long) strip); - return 0; - } - - /* - ** How much do we want to read? - */ - to_read = tif->tif_rawdatasize - unused_data; - if( (uint64) to_read > td->td_stripbytecount[strip] - - tif->tif_rawdataoff - tif->tif_rawdataloaded ) - { - to_read = td->td_stripbytecount[strip] - - tif->tif_rawdataoff - tif->tif_rawdataloaded; - } - - assert((tif->tif_flags&TIFF_BUFFERMMAP)==0); - cc = TIFFReadFile(tif, tif->tif_rawdata + unused_data, to_read); - - if (cc != to_read) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "Read error at scanline %lu; got %I64u bytes, expected %I64u", - (unsigned long) tif->tif_row, - (unsigned __int64) cc, - (unsigned __int64) to_read); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "Read error at scanline %lu; got %llu bytes, expected %llu", - (unsigned long) tif->tif_row, - (unsigned long long) cc, - (unsigned long long) to_read); -#endif - return 0; - } - - tif->tif_rawdataoff = tif->tif_rawdataoff + tif->tif_rawdataloaded - unused_data ; - tif->tif_rawdataloaded = unused_data + to_read; - - tif->tif_rawcp = tif->tif_rawdata; - - if (!isFillOrder(tif, td->td_fillorder) && - (tif->tif_flags & TIFF_NOBITREV) == 0) { - assert((tif->tif_flags&TIFF_BUFFERMMAP)==0); - TIFFReverseBits(tif->tif_rawdata + unused_data, to_read ); - } - - /* - ** When starting a strip from the beginning we need to - ** restart the decoder. - */ - if( restart ) - return TIFFStartStrip(tif, strip); - else - return 1; -} - -/* - * Seek to a random row+sample in a file. - * - * Only used by TIFFReadScanline, and is only used on - * strip organized files. We do some tricky stuff to try - * and avoid reading the whole compressed raw data for big - * strips. - */ -static int -TIFFSeek(TIFF* tif, uint32 row, uint16 sample ) -{ - register TIFFDirectory *td = &tif->tif_dir; - uint32 strip; - int whole_strip; - tmsize_t read_ahead = 0; - - /* - ** Establish what strip we are working from. - */ - if (row >= td->td_imagelength) { /* out of range */ - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "%lu: Row out of range, max %lu", - (unsigned long) row, - (unsigned long) td->td_imagelength); - return (0); - } - if (td->td_planarconfig == PLANARCONFIG_SEPARATE) { - if (sample >= td->td_samplesperpixel) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "%lu: Sample out of range, max %lu", - (unsigned long) sample, (unsigned long) td->td_samplesperpixel); - return (0); - } - strip = (uint32)sample*td->td_stripsperimage + row/td->td_rowsperstrip; - } else - strip = row / td->td_rowsperstrip; - - /* - * Do we want to treat this strip as one whole chunk or - * read it a few lines at a time? - */ -#if defined(CHUNKY_STRIP_READ_SUPPORT) - if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) - return 0; - whole_strip = tif->tif_dir.td_stripbytecount[strip] < 10 - || isMapped(tif); -#else - whole_strip = 1; -#endif - - if( !whole_strip ) - { - read_ahead = tif->tif_scanlinesize * 16 + 5000; - } - - /* - * If we haven't loaded this strip, do so now, possibly - * only reading the first part. - */ - if (strip != tif->tif_curstrip) { /* different strip, refill */ - - if( whole_strip ) - { - if (!TIFFFillStrip(tif, strip)) - return (0); - } - else - { - if( !TIFFFillStripPartial(tif,strip,read_ahead,1) ) - return 0; - } - } - - /* - ** If we already have some data loaded, do we need to read some more? - */ - else if( !whole_strip ) - { - if( ((tif->tif_rawdata + tif->tif_rawdataloaded) - tif->tif_rawcp) < read_ahead - && (uint64) tif->tif_rawdataoff+tif->tif_rawdataloaded < td->td_stripbytecount[strip] ) - { - if( !TIFFFillStripPartial(tif,strip,read_ahead,0) ) - return 0; - } - } - - if (row < tif->tif_row) { - /* - * Moving backwards within the same strip: backup - * to the start and then decode forward (below). - * - * NB: If you're planning on lots of random access within a - * strip, it's better to just read and decode the entire - * strip, and then access the decoded data in a random fashion. - */ - - if( tif->tif_rawdataoff != 0 ) - { - if( !TIFFFillStripPartial(tif,strip,read_ahead,1) ) - return 0; - } - else - { - if (!TIFFStartStrip(tif, strip)) - return (0); - } - } - - if (row != tif->tif_row) { - /* - * Seek forward to the desired row. - */ - - /* TODO: Will this really work with partial buffers? */ - - if (!(*tif->tif_seek)(tif, row - tif->tif_row)) - return (0); - tif->tif_row = row; - } - - return (1); -} - -int -TIFFReadScanline(TIFF* tif, void* buf, uint32 row, uint16 sample) -{ - int e; - - if (!TIFFCheckRead(tif, 0)) - return (-1); - if( (e = TIFFSeek(tif, row, sample)) != 0) { - /* - * Decompress desired row into user buffer. - */ - e = (*tif->tif_decoderow) - (tif, (uint8*) buf, tif->tif_scanlinesize, sample); - - /* we are now poised at the beginning of the next row */ - tif->tif_row = row + 1; - - if (e) - (*tif->tif_postdecode)(tif, (uint8*) buf, - tif->tif_scanlinesize); - } - return (e > 0 ? 1 : -1); -} - -/* - * Read a strip of data and decompress the specified - * amount into the user-supplied buffer. - */ -tmsize_t -TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size) -{ - static const char module[] = "TIFFReadEncodedStrip"; - TIFFDirectory *td = &tif->tif_dir; - uint32 rowsperstrip; - uint32 stripsperplane; - uint32 stripinplane; - uint16 plane; - uint32 rows; - tmsize_t stripsize; - if (!TIFFCheckRead(tif,0)) - return((tmsize_t)(-1)); - if (strip>=td->td_nstrips) - { - TIFFErrorExt(tif->tif_clientdata,module, - "%lu: Strip out of range, max %lu",(unsigned long)strip, - (unsigned long)td->td_nstrips); - return((tmsize_t)(-1)); - } - /* - * Calculate the strip size according to the number of - * rows in the strip (check for truncated last strip on any - * of the separations). - */ - rowsperstrip=td->td_rowsperstrip; - if (rowsperstrip>td->td_imagelength) - rowsperstrip=td->td_imagelength; - stripsperplane=((td->td_imagelength+rowsperstrip-1)/rowsperstrip); - stripinplane=(strip%stripsperplane); - plane=(strip/stripsperplane); - rows=td->td_imagelength-stripinplane*rowsperstrip; - if (rows>rowsperstrip) - rows=rowsperstrip; - stripsize=TIFFVStripSize(tif,rows); - if (stripsize==0) - return((tmsize_t)(-1)); - if ((size!=(tmsize_t)(-1))&&(sizetif_decodestrip)(tif,buf,stripsize,plane)<=0) - return((tmsize_t)(-1)); - (*tif->tif_postdecode)(tif,buf,stripsize); - return(stripsize); -} - -static tmsize_t -TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size, - const char* module) -{ - TIFFDirectory *td = &tif->tif_dir; - - if (!_TIFFFillStriles( tif )) - return ((tmsize_t)(-1)); - - assert((tif->tif_flags&TIFF_NOREADRAW)==0); - if (!isMapped(tif)) { - tmsize_t cc; - - if (!SeekOK(tif, td->td_stripoffset[strip])) { - TIFFErrorExt(tif->tif_clientdata, module, - "Seek error at scanline %lu, strip %lu", - (unsigned long) tif->tif_row, (unsigned long) strip); - return ((tmsize_t)(-1)); - } - cc = TIFFReadFile(tif, buf, size); - if (cc != size) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "Read error at scanline %lu; got %I64u bytes, expected %I64u", - (unsigned long) tif->tif_row, - (unsigned __int64) cc, - (unsigned __int64) size); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "Read error at scanline %lu; got %llu bytes, expected %llu", - (unsigned long) tif->tif_row, - (unsigned long long) cc, - (unsigned long long) size); -#endif - return ((tmsize_t)(-1)); - } - } else { - tmsize_t ma,mb; - tmsize_t n; - ma=(tmsize_t)td->td_stripoffset[strip]; - mb=ma+size; - if (((uint64)ma!=td->td_stripoffset[strip])||(ma>tif->tif_size)) - n=0; - else if ((mbtif->tif_size)) - n=tif->tif_size-ma; - else - n=size; - if (n!=size) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "Read error at scanline %lu, strip %lu; got %I64u bytes, expected %I64u", - (unsigned long) tif->tif_row, - (unsigned long) strip, - (unsigned __int64) n, - (unsigned __int64) size); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "Read error at scanline %lu, strip %lu; got %llu bytes, expected %llu", - (unsigned long) tif->tif_row, - (unsigned long) strip, - (unsigned long long) n, - (unsigned long long) size); -#endif - return ((tmsize_t)(-1)); - } - _TIFFmemcpy(buf, tif->tif_base + ma, - size); - } - return (size); -} - -/* - * Read a strip of data from the file. - */ -tmsize_t -TIFFReadRawStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size) -{ - static const char module[] = "TIFFReadRawStrip"; - TIFFDirectory *td = &tif->tif_dir; - uint64 bytecount; - tmsize_t bytecountm; - - if (!TIFFCheckRead(tif, 0)) - return ((tmsize_t)(-1)); - if (strip >= td->td_nstrips) { - TIFFErrorExt(tif->tif_clientdata, module, - "%lu: Strip out of range, max %lu", - (unsigned long) strip, - (unsigned long) td->td_nstrips); - return ((tmsize_t)(-1)); - } - if (tif->tif_flags&TIFF_NOREADRAW) - { - TIFFErrorExt(tif->tif_clientdata, module, - "Compression scheme does not support access to raw uncompressed data"); - return ((tmsize_t)(-1)); - } - bytecount = td->td_stripbytecount[strip]; - if (bytecount <= 0) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "%I64u: Invalid strip byte count, strip %lu", - (unsigned __int64) bytecount, - (unsigned long) strip); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "%llu: Invalid strip byte count, strip %lu", - (unsigned long long) bytecount, - (unsigned long) strip); -#endif - return ((tmsize_t)(-1)); - } - bytecountm = (tmsize_t)bytecount; - if ((uint64)bytecountm!=bytecount) { - TIFFErrorExt(tif->tif_clientdata, module, "Integer overflow"); - return ((tmsize_t)(-1)); - } - if (size != (tmsize_t)(-1) && size < bytecountm) - bytecountm = size; - return (TIFFReadRawStrip1(tif, strip, buf, bytecountm, module)); -} - -/* - * Read the specified strip and setup for decoding. The data buffer is - * expanded, as necessary, to hold the strip's data. - */ -int -TIFFFillStrip(TIFF* tif, uint32 strip) -{ - static const char module[] = "TIFFFillStrip"; - TIFFDirectory *td = &tif->tif_dir; - - if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) - return 0; - - if ((tif->tif_flags&TIFF_NOREADRAW)==0) - { - uint64 bytecount = td->td_stripbytecount[strip]; - if (bytecount <= 0) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "Invalid strip byte count %I64u, strip %lu", - (unsigned __int64) bytecount, - (unsigned long) strip); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "Invalid strip byte count %llu, strip %lu", - (unsigned long long) bytecount, - (unsigned long) strip); -#endif - return (0); - } - if (isMapped(tif) && - (isFillOrder(tif, td->td_fillorder) - || (tif->tif_flags & TIFF_NOBITREV))) { - /* - * The image is mapped into memory and we either don't - * need to flip bits or the compression routine is - * going to handle this operation itself. In this - * case, avoid copying the raw data and instead just - * reference the data from the memory mapped file - * image. This assumes that the decompression - * routines do not modify the contents of the raw data - * buffer (if they try to, the application will get a - * fault since the file is mapped read-only). - */ - if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) { - _TIFFfree(tif->tif_rawdata); - tif->tif_rawdata = NULL; - tif->tif_rawdatasize = 0; - } - tif->tif_flags &= ~TIFF_MYBUFFER; - /* - * We must check for overflow, potentially causing - * an OOB read. Instead of simple - * - * td->td_stripoffset[strip]+bytecount > tif->tif_size - * - * comparison (which can overflow) we do the following - * two comparisons: - */ - if (bytecount > (uint64)tif->tif_size || - td->td_stripoffset[strip] > (uint64)tif->tif_size - bytecount) { - /* - * This error message might seem strange, but - * it's what would happen if a read were done - * instead. - */ -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - - "Read error on strip %lu; " - "got %I64u bytes, expected %I64u", - (unsigned long) strip, - (unsigned __int64) tif->tif_size - td->td_stripoffset[strip], - (unsigned __int64) bytecount); -#else - TIFFErrorExt(tif->tif_clientdata, module, - - "Read error on strip %lu; " - "got %llu bytes, expected %llu", - (unsigned long) strip, - (unsigned long long) tif->tif_size - td->td_stripoffset[strip], - (unsigned long long) bytecount); -#endif - tif->tif_curstrip = NOSTRIP; - return (0); - } - tif->tif_rawdatasize = (tmsize_t)bytecount; - tif->tif_rawdata = tif->tif_base + (tmsize_t)td->td_stripoffset[strip]; - tif->tif_rawdataoff = 0; - tif->tif_rawdataloaded = (tmsize_t) bytecount; - - /* - * When we have tif_rawdata reference directly into the memory mapped file - * we need to be pretty careful about how we use the rawdata. It is not - * a general purpose working buffer as it normally otherwise is. So we - * keep track of this fact to avoid using it improperly. - */ - tif->tif_flags |= TIFF_BUFFERMMAP; - } else { - /* - * Expand raw data buffer, if needed, to hold data - * strip coming from file (perhaps should set upper - * bound on the size of a buffer we'll use?). - */ - tmsize_t bytecountm; - bytecountm=(tmsize_t)bytecount; - if ((uint64)bytecountm!=bytecount) - { - TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); - return(0); - } - if (bytecountm > tif->tif_rawdatasize) { - tif->tif_curstrip = NOSTRIP; - if ((tif->tif_flags & TIFF_MYBUFFER) == 0) { - TIFFErrorExt(tif->tif_clientdata, module, - "Data buffer too small to hold strip %lu", - (unsigned long) strip); - return (0); - } - if (!TIFFReadBufferSetup(tif, 0, bytecountm)) - return (0); - } - if (tif->tif_flags&TIFF_BUFFERMMAP) { - tif->tif_curstrip = NOSTRIP; - if (!TIFFReadBufferSetup(tif, 0, bytecountm)) - return (0); - } - if (TIFFReadRawStrip1(tif, strip, tif->tif_rawdata, - bytecountm, module) != bytecountm) - return (0); - - tif->tif_rawdataoff = 0; - tif->tif_rawdataloaded = bytecountm; - - if (!isFillOrder(tif, td->td_fillorder) && - (tif->tif_flags & TIFF_NOBITREV) == 0) - TIFFReverseBits(tif->tif_rawdata, bytecountm); - } - } - return (TIFFStartStrip(tif, strip)); -} - -/* - * Tile-oriented Read Support - * Contributed by Nancy Cam (Silicon Graphics). - */ - -/* - * Read and decompress a tile of data. The - * tile is selected by the (x,y,z,s) coordinates. - */ -tmsize_t -TIFFReadTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s) -{ - if (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s)) - return ((tmsize_t)(-1)); - return (TIFFReadEncodedTile(tif, - TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1))); -} - -/* - * Read a tile of data and decompress the specified - * amount into the user-supplied buffer. - */ -tmsize_t -TIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size) -{ - static const char module[] = "TIFFReadEncodedTile"; - TIFFDirectory *td = &tif->tif_dir; - tmsize_t tilesize = tif->tif_tilesize; - - if (!TIFFCheckRead(tif, 1)) - return ((tmsize_t)(-1)); - if (tile >= td->td_nstrips) { - TIFFErrorExt(tif->tif_clientdata, module, - "%lu: Tile out of range, max %lu", - (unsigned long) tile, (unsigned long) td->td_nstrips); - return ((tmsize_t)(-1)); - } - if (size == (tmsize_t)(-1)) - size = tilesize; - else if (size > tilesize) - size = tilesize; - if (TIFFFillTile(tif, tile) && (*tif->tif_decodetile)(tif, - (uint8*) buf, size, (uint16)(tile/td->td_stripsperimage))) { - (*tif->tif_postdecode)(tif, (uint8*) buf, size); - return (size); - } else - return ((tmsize_t)(-1)); -} - -static tmsize_t -TIFFReadRawTile1(TIFF* tif, uint32 tile, void* buf, tmsize_t size, const char* module) -{ - TIFFDirectory *td = &tif->tif_dir; - - if (!_TIFFFillStriles( tif )) - return ((tmsize_t)(-1)); - - assert((tif->tif_flags&TIFF_NOREADRAW)==0); - if (!isMapped(tif)) { - tmsize_t cc; - - if (!SeekOK(tif, td->td_stripoffset[tile])) { - TIFFErrorExt(tif->tif_clientdata, module, - "Seek error at row %lu, col %lu, tile %lu", - (unsigned long) tif->tif_row, - (unsigned long) tif->tif_col, - (unsigned long) tile); - return ((tmsize_t)(-1)); - } - cc = TIFFReadFile(tif, buf, size); - if (cc != size) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "Read error at row %lu, col %lu; got %I64u bytes, expected %I64u", - (unsigned long) tif->tif_row, - (unsigned long) tif->tif_col, - (unsigned __int64) cc, - (unsigned __int64) size); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "Read error at row %lu, col %lu; got %llu bytes, expected %llu", - (unsigned long) tif->tif_row, - (unsigned long) tif->tif_col, - (unsigned long long) cc, - (unsigned long long) size); -#endif - return ((tmsize_t)(-1)); - } - } else { - tmsize_t ma,mb; - tmsize_t n; - ma=(tmsize_t)td->td_stripoffset[tile]; - mb=ma+size; - if (((uint64)ma!=td->td_stripoffset[tile])||(ma>tif->tif_size)) - n=0; - else if ((mbtif->tif_size)) - n=tif->tif_size-ma; - else - n=size; - if (n!=size) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, -"Read error at row %lu, col %lu, tile %lu; got %I64u bytes, expected %I64u", - (unsigned long) tif->tif_row, - (unsigned long) tif->tif_col, - (unsigned long) tile, - (unsigned __int64) n, - (unsigned __int64) size); -#else - TIFFErrorExt(tif->tif_clientdata, module, -"Read error at row %lu, col %lu, tile %lu; got %llu bytes, expected %llu", - (unsigned long) tif->tif_row, - (unsigned long) tif->tif_col, - (unsigned long) tile, - (unsigned long long) n, - (unsigned long long) size); -#endif - return ((tmsize_t)(-1)); - } - _TIFFmemcpy(buf, tif->tif_base + ma, size); - } - return (size); -} - -/* - * Read a tile of data from the file. - */ -tmsize_t -TIFFReadRawTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size) -{ - static const char module[] = "TIFFReadRawTile"; - TIFFDirectory *td = &tif->tif_dir; - uint64 bytecount64; - tmsize_t bytecountm; - - if (!TIFFCheckRead(tif, 1)) - return ((tmsize_t)(-1)); - if (tile >= td->td_nstrips) { - TIFFErrorExt(tif->tif_clientdata, module, - "%lu: Tile out of range, max %lu", - (unsigned long) tile, (unsigned long) td->td_nstrips); - return ((tmsize_t)(-1)); - } - if (tif->tif_flags&TIFF_NOREADRAW) - { - TIFFErrorExt(tif->tif_clientdata, module, - "Compression scheme does not support access to raw uncompressed data"); - return ((tmsize_t)(-1)); - } - bytecount64 = td->td_stripbytecount[tile]; - if (size != (tmsize_t)(-1) && (uint64)size < bytecount64) - bytecount64 = (uint64)size; - bytecountm = (tmsize_t)bytecount64; - if ((uint64)bytecountm!=bytecount64) - { - TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); - return ((tmsize_t)(-1)); - } - return (TIFFReadRawTile1(tif, tile, buf, bytecountm, module)); -} - -/* - * Read the specified tile and setup for decoding. The data buffer is - * expanded, as necessary, to hold the tile's data. - */ -int -TIFFFillTile(TIFF* tif, uint32 tile) -{ - static const char module[] = "TIFFFillTile"; - TIFFDirectory *td = &tif->tif_dir; - - if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) - return 0; - - if ((tif->tif_flags&TIFF_NOREADRAW)==0) - { - uint64 bytecount = td->td_stripbytecount[tile]; - if (bytecount <= 0) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "%I64u: Invalid tile byte count, tile %lu", - (unsigned __int64) bytecount, - (unsigned long) tile); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "%llu: Invalid tile byte count, tile %lu", - (unsigned long long) bytecount, - (unsigned long) tile); -#endif - return (0); - } - if (isMapped(tif) && - (isFillOrder(tif, td->td_fillorder) - || (tif->tif_flags & TIFF_NOBITREV))) { - /* - * The image is mapped into memory and we either don't - * need to flip bits or the compression routine is - * going to handle this operation itself. In this - * case, avoid copying the raw data and instead just - * reference the data from the memory mapped file - * image. This assumes that the decompression - * routines do not modify the contents of the raw data - * buffer (if they try to, the application will get a - * fault since the file is mapped read-only). - */ - if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) { - _TIFFfree(tif->tif_rawdata); - tif->tif_rawdata = NULL; - tif->tif_rawdatasize = 0; - } - tif->tif_flags &= ~TIFF_MYBUFFER; - /* - * We must check for overflow, potentially causing - * an OOB read. Instead of simple - * - * td->td_stripoffset[tile]+bytecount > tif->tif_size - * - * comparison (which can overflow) we do the following - * two comparisons: - */ - if (bytecount > (uint64)tif->tif_size || - td->td_stripoffset[tile] > (uint64)tif->tif_size - bytecount) { - tif->tif_curtile = NOTILE; - return (0); - } - tif->tif_rawdatasize = (tmsize_t)bytecount; - tif->tif_rawdata = - tif->tif_base + (tmsize_t)td->td_stripoffset[tile]; - tif->tif_rawdataoff = 0; - tif->tif_rawdataloaded = (tmsize_t) bytecount; - tif->tif_flags |= TIFF_BUFFERMMAP; - } else { - /* - * Expand raw data buffer, if needed, to hold data - * tile coming from file (perhaps should set upper - * bound on the size of a buffer we'll use?). - */ - tmsize_t bytecountm; - bytecountm=(tmsize_t)bytecount; - if ((uint64)bytecountm!=bytecount) - { - TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); - return(0); - } - if (bytecountm > tif->tif_rawdatasize) { - tif->tif_curtile = NOTILE; - if ((tif->tif_flags & TIFF_MYBUFFER) == 0) { - TIFFErrorExt(tif->tif_clientdata, module, - "Data buffer too small to hold tile %lu", - (unsigned long) tile); - return (0); - } - if (!TIFFReadBufferSetup(tif, 0, bytecountm)) - return (0); - } - if (tif->tif_flags&TIFF_BUFFERMMAP) { - tif->tif_curtile = NOTILE; - if (!TIFFReadBufferSetup(tif, 0, bytecountm)) - return (0); - } - - if (TIFFReadRawTile1(tif, tile, tif->tif_rawdata, - bytecountm, module) != bytecountm) - return (0); - - tif->tif_rawdataoff = 0; - tif->tif_rawdataloaded = bytecountm; - - if (!isFillOrder(tif, td->td_fillorder) && - (tif->tif_flags & TIFF_NOBITREV) == 0) - TIFFReverseBits(tif->tif_rawdata, - tif->tif_rawdataloaded); - } - } - return (TIFFStartTile(tif, tile)); -} - -/* - * Setup the raw data buffer in preparation for - * reading a strip of raw data. If the buffer - * is specified as zero, then a buffer of appropriate - * size is allocated by the library. Otherwise, - * the client must guarantee that the buffer is - * large enough to hold any individual strip of - * raw data. - */ -int -TIFFReadBufferSetup(TIFF* tif, void* bp, tmsize_t size) -{ - static const char module[] = "TIFFReadBufferSetup"; - - assert((tif->tif_flags&TIFF_NOREADRAW)==0); - tif->tif_flags &= ~TIFF_BUFFERMMAP; - - if (tif->tif_rawdata) { - if (tif->tif_flags & TIFF_MYBUFFER) - _TIFFfree(tif->tif_rawdata); - tif->tif_rawdata = NULL; - tif->tif_rawdatasize = 0; - } - if (bp) { - tif->tif_rawdatasize = size; - tif->tif_rawdata = (uint8*) bp; - tif->tif_flags &= ~TIFF_MYBUFFER; - } else { - tif->tif_rawdatasize = (tmsize_t)TIFFroundup_64((uint64)size, 1024); - if (tif->tif_rawdatasize==0) - tif->tif_rawdatasize=(tmsize_t)(-1); - tif->tif_rawdata = (uint8*) _TIFFmalloc(tif->tif_rawdatasize); - tif->tif_flags |= TIFF_MYBUFFER; - } - if (tif->tif_rawdata == NULL) { - TIFFErrorExt(tif->tif_clientdata, module, - "No space for data buffer at scanline %lu", - (unsigned long) tif->tif_row); - tif->tif_rawdatasize = 0; - return (0); - } - return (1); -} - -/* - * Set state to appear as if a - * strip has just been read in. - */ -static int -TIFFStartStrip(TIFF* tif, uint32 strip) -{ - TIFFDirectory *td = &tif->tif_dir; - - if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) - return 0; - - if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { - if (!(*tif->tif_setupdecode)(tif)) - return (0); - tif->tif_flags |= TIFF_CODERSETUP; - } - tif->tif_curstrip = strip; - tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip; - tif->tif_flags &= ~TIFF_BUF4WRITE; - - if (tif->tif_flags&TIFF_NOREADRAW) - { - tif->tif_rawcp = NULL; - tif->tif_rawcc = 0; - } - else - { - tif->tif_rawcp = tif->tif_rawdata; - tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[strip]; - } - return ((*tif->tif_predecode)(tif, - (uint16)(strip / td->td_stripsperimage))); -} - -/* - * Set state to appear as if a - * tile has just been read in. - */ -static int -TIFFStartTile(TIFF* tif, uint32 tile) -{ - TIFFDirectory *td = &tif->tif_dir; - - if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) - return 0; - - if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { - if (!(*tif->tif_setupdecode)(tif)) - return (0); - tif->tif_flags |= TIFF_CODERSETUP; - } - tif->tif_curtile = tile; - tif->tif_row = - (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) * - td->td_tilelength; - tif->tif_col = - (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) * - td->td_tilewidth; - tif->tif_flags &= ~TIFF_BUF4WRITE; - if (tif->tif_flags&TIFF_NOREADRAW) - { - tif->tif_rawcp = NULL; - tif->tif_rawcc = 0; - } - else - { - tif->tif_rawcp = tif->tif_rawdata; - tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile]; - } - return ((*tif->tif_predecode)(tif, - (uint16)(tile/td->td_stripsperimage))); -} - -static int -TIFFCheckRead(TIFF* tif, int tiles) -{ - if (tif->tif_mode == O_WRONLY) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "File not open for reading"); - return (0); - } - if (tiles ^ isTiled(tif)) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, tiles ? - "Can not read tiles from a stripped image" : - "Can not read scanlines from a tiled image"); - return (0); - } - return (1); -} - -void -_TIFFNoPostDecode(TIFF* tif, uint8* buf, tmsize_t cc) -{ - (void) tif; (void) buf; (void) cc; -} - -void -_TIFFSwab16BitData(TIFF* tif, uint8* buf, tmsize_t cc) -{ - (void) tif; - assert((cc & 1) == 0); - TIFFSwabArrayOfShort((uint16*) buf, cc/2); -} - -void -_TIFFSwab24BitData(TIFF* tif, uint8* buf, tmsize_t cc) -{ - (void) tif; - assert((cc % 3) == 0); - TIFFSwabArrayOfTriples((uint8*) buf, cc/3); -} - -void -_TIFFSwab32BitData(TIFF* tif, uint8* buf, tmsize_t cc) -{ - (void) tif; - assert((cc & 3) == 0); - TIFFSwabArrayOfLong((uint32*) buf, cc/4); -} - -void -_TIFFSwab64BitData(TIFF* tif, uint8* buf, tmsize_t cc) -{ - (void) tif; - assert((cc & 7) == 0); - TIFFSwabArrayOfDouble((double*) buf, cc/8); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_read.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * Scanline-oriented Read Support + */ +#include "tiffiop.h" +#include + +int TIFFFillStrip(TIFF* tif, uint32 strip); +int TIFFFillTile(TIFF* tif, uint32 tile); +static int TIFFStartStrip(TIFF* tif, uint32 strip); +static int TIFFStartTile(TIFF* tif, uint32 tile); +static int TIFFCheckRead(TIFF*, int); +static tmsize_t +TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size,const char* module); + +#define NOSTRIP ((uint32)(-1)) /* undefined state */ +#define NOTILE ((uint32)(-1)) /* undefined state */ + +static int +TIFFFillStripPartial( TIFF *tif, int strip, tmsize_t read_ahead, int restart ) +{ + static const char module[] = "TIFFFillStripPartial"; + register TIFFDirectory *td = &tif->tif_dir; + uint64 unused_data; + uint64 read_offset; + tmsize_t cc, to_read; + /* tmsize_t bytecountm; */ + + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; + + /* + * Expand raw data buffer, if needed, to hold data + * strip coming from file (perhaps should set upper + * bound on the size of a buffer we'll use?). + */ + + /* bytecountm=(tmsize_t) td->td_stripbytecount[strip]; */ + if (read_ahead*2 > tif->tif_rawdatasize) { + assert( restart ); + + tif->tif_curstrip = NOSTRIP; + if ((tif->tif_flags & TIFF_MYBUFFER) == 0) { + TIFFErrorExt(tif->tif_clientdata, module, + "Data buffer too small to hold part of strip %lu", + (unsigned long) strip); + return (0); + } + if (!TIFFReadBufferSetup(tif, 0, read_ahead*2)) + return (0); + } + + if( restart ) + { + tif->tif_rawdataloaded = 0; + tif->tif_rawdataoff = 0; + } + + /* + ** If we are reading more data, move any unused data to the + ** start of the buffer. + */ + if( tif->tif_rawdataloaded > 0 ) + unused_data = tif->tif_rawdataloaded - (tif->tif_rawcp - tif->tif_rawdata); + else + unused_data = 0; + + if( unused_data > 0 ) + { + assert((tif->tif_flags&TIFF_BUFFERMMAP)==0); + memmove( tif->tif_rawdata, tif->tif_rawcp, unused_data ); + } + + /* + ** Seek to the point in the file where more data should be read. + */ + read_offset = td->td_stripoffset[strip] + + tif->tif_rawdataoff + tif->tif_rawdataloaded; + + if (!SeekOK(tif, read_offset)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Seek error at scanline %lu, strip %lu", + (unsigned long) tif->tif_row, (unsigned long) strip); + return 0; + } + + /* + ** How much do we want to read? + */ + to_read = tif->tif_rawdatasize - unused_data; + if( (uint64) to_read > td->td_stripbytecount[strip] + - tif->tif_rawdataoff - tif->tif_rawdataloaded ) + { + to_read = td->td_stripbytecount[strip] + - tif->tif_rawdataoff - tif->tif_rawdataloaded; + } + + assert((tif->tif_flags&TIFF_BUFFERMMAP)==0); + cc = TIFFReadFile(tif, tif->tif_rawdata + unused_data, to_read); + + if (cc != to_read) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + "Read error at scanline %lu; got %I64u bytes, expected %I64u", + (unsigned long) tif->tif_row, + (unsigned __int64) cc, + (unsigned __int64) to_read); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "Read error at scanline %lu; got %llu bytes, expected %llu", + (unsigned long) tif->tif_row, + (unsigned long long) cc, + (unsigned long long) to_read); +#endif + return 0; + } + + tif->tif_rawdataoff = tif->tif_rawdataoff + tif->tif_rawdataloaded - unused_data ; + tif->tif_rawdataloaded = unused_data + to_read; + + tif->tif_rawcp = tif->tif_rawdata; + + if (!isFillOrder(tif, td->td_fillorder) && + (tif->tif_flags & TIFF_NOBITREV) == 0) { + assert((tif->tif_flags&TIFF_BUFFERMMAP)==0); + TIFFReverseBits(tif->tif_rawdata + unused_data, to_read ); + } + + /* + ** When starting a strip from the beginning we need to + ** restart the decoder. + */ + if( restart ) + return TIFFStartStrip(tif, strip); + else + return 1; +} + +/* + * Seek to a random row+sample in a file. + * + * Only used by TIFFReadScanline, and is only used on + * strip organized files. We do some tricky stuff to try + * and avoid reading the whole compressed raw data for big + * strips. + */ +static int +TIFFSeek(TIFF* tif, uint32 row, uint16 sample ) +{ + register TIFFDirectory *td = &tif->tif_dir; + uint32 strip; + int whole_strip; + tmsize_t read_ahead = 0; + + /* + ** Establish what strip we are working from. + */ + if (row >= td->td_imagelength) { /* out of range */ + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "%lu: Row out of range, max %lu", + (unsigned long) row, + (unsigned long) td->td_imagelength); + return (0); + } + if (td->td_planarconfig == PLANARCONFIG_SEPARATE) { + if (sample >= td->td_samplesperpixel) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "%lu: Sample out of range, max %lu", + (unsigned long) sample, (unsigned long) td->td_samplesperpixel); + return (0); + } + strip = (uint32)sample*td->td_stripsperimage + row/td->td_rowsperstrip; + } else + strip = row / td->td_rowsperstrip; + + /* + * Do we want to treat this strip as one whole chunk or + * read it a few lines at a time? + */ +#if defined(CHUNKY_STRIP_READ_SUPPORT) + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; + whole_strip = tif->tif_dir.td_stripbytecount[strip] < 10 + || isMapped(tif); +#else + whole_strip = 1; +#endif + + if( !whole_strip ) + { + read_ahead = tif->tif_scanlinesize * 16 + 5000; + } + + /* + * If we haven't loaded this strip, do so now, possibly + * only reading the first part. + */ + if (strip != tif->tif_curstrip) { /* different strip, refill */ + + if( whole_strip ) + { + if (!TIFFFillStrip(tif, strip)) + return (0); + } + else + { + if( !TIFFFillStripPartial(tif,strip,read_ahead,1) ) + return 0; + } + } + + /* + ** If we already have some data loaded, do we need to read some more? + */ + else if( !whole_strip ) + { + if( ((tif->tif_rawdata + tif->tif_rawdataloaded) - tif->tif_rawcp) < read_ahead + && (uint64) tif->tif_rawdataoff+tif->tif_rawdataloaded < td->td_stripbytecount[strip] ) + { + if( !TIFFFillStripPartial(tif,strip,read_ahead,0) ) + return 0; + } + } + + if (row < tif->tif_row) { + /* + * Moving backwards within the same strip: backup + * to the start and then decode forward (below). + * + * NB: If you're planning on lots of random access within a + * strip, it's better to just read and decode the entire + * strip, and then access the decoded data in a random fashion. + */ + + if( tif->tif_rawdataoff != 0 ) + { + if( !TIFFFillStripPartial(tif,strip,read_ahead,1) ) + return 0; + } + else + { + if (!TIFFStartStrip(tif, strip)) + return (0); + } + } + + if (row != tif->tif_row) { + /* + * Seek forward to the desired row. + */ + + /* TODO: Will this really work with partial buffers? */ + + if (!(*tif->tif_seek)(tif, row - tif->tif_row)) + return (0); + tif->tif_row = row; + } + + return (1); +} + +int +TIFFReadScanline(TIFF* tif, void* buf, uint32 row, uint16 sample) +{ + int e; + + if (!TIFFCheckRead(tif, 0)) + return (-1); + if( (e = TIFFSeek(tif, row, sample)) != 0) { + /* + * Decompress desired row into user buffer. + */ + e = (*tif->tif_decoderow) + (tif, (uint8*) buf, tif->tif_scanlinesize, sample); + + /* we are now poised at the beginning of the next row */ + tif->tif_row = row + 1; + + if (e) + (*tif->tif_postdecode)(tif, (uint8*) buf, + tif->tif_scanlinesize); + } + return (e > 0 ? 1 : -1); +} + +/* + * Read a strip of data and decompress the specified + * amount into the user-supplied buffer. + */ +tmsize_t +TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size) +{ + static const char module[] = "TIFFReadEncodedStrip"; + TIFFDirectory *td = &tif->tif_dir; + uint32 rowsperstrip; + uint32 stripsperplane; + uint32 stripinplane; + uint16 plane; + uint32 rows; + tmsize_t stripsize; + if (!TIFFCheckRead(tif,0)) + return((tmsize_t)(-1)); + if (strip>=td->td_nstrips) + { + TIFFErrorExt(tif->tif_clientdata,module, + "%lu: Strip out of range, max %lu",(unsigned long)strip, + (unsigned long)td->td_nstrips); + return((tmsize_t)(-1)); + } + /* + * Calculate the strip size according to the number of + * rows in the strip (check for truncated last strip on any + * of the separations). + */ + rowsperstrip=td->td_rowsperstrip; + if (rowsperstrip>td->td_imagelength) + rowsperstrip=td->td_imagelength; + stripsperplane=((td->td_imagelength+rowsperstrip-1)/rowsperstrip); + stripinplane=(strip%stripsperplane); + plane=(strip/stripsperplane); + rows=td->td_imagelength-stripinplane*rowsperstrip; + if (rows>rowsperstrip) + rows=rowsperstrip; + stripsize=TIFFVStripSize(tif,rows); + if (stripsize==0) + return((tmsize_t)(-1)); + if ((size!=(tmsize_t)(-1))&&(sizetif_decodestrip)(tif,buf,stripsize,plane)<=0) + return((tmsize_t)(-1)); + (*tif->tif_postdecode)(tif,buf,stripsize); + return(stripsize); +} + +static tmsize_t +TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size, + const char* module) +{ + TIFFDirectory *td = &tif->tif_dir; + + if (!_TIFFFillStriles( tif )) + return ((tmsize_t)(-1)); + + assert((tif->tif_flags&TIFF_NOREADRAW)==0); + if (!isMapped(tif)) { + tmsize_t cc; + + if (!SeekOK(tif, td->td_stripoffset[strip])) { + TIFFErrorExt(tif->tif_clientdata, module, + "Seek error at scanline %lu, strip %lu", + (unsigned long) tif->tif_row, (unsigned long) strip); + return ((tmsize_t)(-1)); + } + cc = TIFFReadFile(tif, buf, size); + if (cc != size) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + "Read error at scanline %lu; got %I64u bytes, expected %I64u", + (unsigned long) tif->tif_row, + (unsigned __int64) cc, + (unsigned __int64) size); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "Read error at scanline %lu; got %llu bytes, expected %llu", + (unsigned long) tif->tif_row, + (unsigned long long) cc, + (unsigned long long) size); +#endif + return ((tmsize_t)(-1)); + } + } else { + tmsize_t ma,mb; + tmsize_t n; + ma=(tmsize_t)td->td_stripoffset[strip]; + mb=ma+size; + if (((uint64)ma!=td->td_stripoffset[strip])||(ma>tif->tif_size)) + n=0; + else if ((mbtif->tif_size)) + n=tif->tif_size-ma; + else + n=size; + if (n!=size) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + "Read error at scanline %lu, strip %lu; got %I64u bytes, expected %I64u", + (unsigned long) tif->tif_row, + (unsigned long) strip, + (unsigned __int64) n, + (unsigned __int64) size); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "Read error at scanline %lu, strip %lu; got %llu bytes, expected %llu", + (unsigned long) tif->tif_row, + (unsigned long) strip, + (unsigned long long) n, + (unsigned long long) size); +#endif + return ((tmsize_t)(-1)); + } + _TIFFmemcpy(buf, tif->tif_base + ma, + size); + } + return (size); +} + +/* + * Read a strip of data from the file. + */ +tmsize_t +TIFFReadRawStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size) +{ + static const char module[] = "TIFFReadRawStrip"; + TIFFDirectory *td = &tif->tif_dir; + uint64 bytecount; + tmsize_t bytecountm; + + if (!TIFFCheckRead(tif, 0)) + return ((tmsize_t)(-1)); + if (strip >= td->td_nstrips) { + TIFFErrorExt(tif->tif_clientdata, module, + "%lu: Strip out of range, max %lu", + (unsigned long) strip, + (unsigned long) td->td_nstrips); + return ((tmsize_t)(-1)); + } + if (tif->tif_flags&TIFF_NOREADRAW) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Compression scheme does not support access to raw uncompressed data"); + return ((tmsize_t)(-1)); + } + bytecount = td->td_stripbytecount[strip]; + if (bytecount <= 0) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + "%I64u: Invalid strip byte count, strip %lu", + (unsigned __int64) bytecount, + (unsigned long) strip); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "%llu: Invalid strip byte count, strip %lu", + (unsigned long long) bytecount, + (unsigned long) strip); +#endif + return ((tmsize_t)(-1)); + } + bytecountm = (tmsize_t)bytecount; + if ((uint64)bytecountm!=bytecount) { + TIFFErrorExt(tif->tif_clientdata, module, "Integer overflow"); + return ((tmsize_t)(-1)); + } + if (size != (tmsize_t)(-1) && size < bytecountm) + bytecountm = size; + return (TIFFReadRawStrip1(tif, strip, buf, bytecountm, module)); +} + +/* + * Read the specified strip and setup for decoding. The data buffer is + * expanded, as necessary, to hold the strip's data. + */ +int +TIFFFillStrip(TIFF* tif, uint32 strip) +{ + static const char module[] = "TIFFFillStrip"; + TIFFDirectory *td = &tif->tif_dir; + + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; + + if ((tif->tif_flags&TIFF_NOREADRAW)==0) + { + uint64 bytecount = td->td_stripbytecount[strip]; + if (bytecount <= 0) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + "Invalid strip byte count %I64u, strip %lu", + (unsigned __int64) bytecount, + (unsigned long) strip); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "Invalid strip byte count %llu, strip %lu", + (unsigned long long) bytecount, + (unsigned long) strip); +#endif + return (0); + } + if (isMapped(tif) && + (isFillOrder(tif, td->td_fillorder) + || (tif->tif_flags & TIFF_NOBITREV))) { + /* + * The image is mapped into memory and we either don't + * need to flip bits or the compression routine is + * going to handle this operation itself. In this + * case, avoid copying the raw data and instead just + * reference the data from the memory mapped file + * image. This assumes that the decompression + * routines do not modify the contents of the raw data + * buffer (if they try to, the application will get a + * fault since the file is mapped read-only). + */ + if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) { + _TIFFfree(tif->tif_rawdata); + tif->tif_rawdata = NULL; + tif->tif_rawdatasize = 0; + } + tif->tif_flags &= ~TIFF_MYBUFFER; + /* + * We must check for overflow, potentially causing + * an OOB read. Instead of simple + * + * td->td_stripoffset[strip]+bytecount > tif->tif_size + * + * comparison (which can overflow) we do the following + * two comparisons: + */ + if (bytecount > (uint64)tif->tif_size || + td->td_stripoffset[strip] > (uint64)tif->tif_size - bytecount) { + /* + * This error message might seem strange, but + * it's what would happen if a read were done + * instead. + */ +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + + "Read error on strip %lu; " + "got %I64u bytes, expected %I64u", + (unsigned long) strip, + (unsigned __int64) tif->tif_size - td->td_stripoffset[strip], + (unsigned __int64) bytecount); +#else + TIFFErrorExt(tif->tif_clientdata, module, + + "Read error on strip %lu; " + "got %llu bytes, expected %llu", + (unsigned long) strip, + (unsigned long long) tif->tif_size - td->td_stripoffset[strip], + (unsigned long long) bytecount); +#endif + tif->tif_curstrip = NOSTRIP; + return (0); + } + tif->tif_rawdatasize = (tmsize_t)bytecount; + tif->tif_rawdata = tif->tif_base + (tmsize_t)td->td_stripoffset[strip]; + tif->tif_rawdataoff = 0; + tif->tif_rawdataloaded = (tmsize_t) bytecount; + + /* + * When we have tif_rawdata reference directly into the memory mapped file + * we need to be pretty careful about how we use the rawdata. It is not + * a general purpose working buffer as it normally otherwise is. So we + * keep track of this fact to avoid using it improperly. + */ + tif->tif_flags |= TIFF_BUFFERMMAP; + } else { + /* + * Expand raw data buffer, if needed, to hold data + * strip coming from file (perhaps should set upper + * bound on the size of a buffer we'll use?). + */ + tmsize_t bytecountm; + bytecountm=(tmsize_t)bytecount; + if ((uint64)bytecountm!=bytecount) + { + TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); + return(0); + } + if (bytecountm > tif->tif_rawdatasize) { + tif->tif_curstrip = NOSTRIP; + if ((tif->tif_flags & TIFF_MYBUFFER) == 0) { + TIFFErrorExt(tif->tif_clientdata, module, + "Data buffer too small to hold strip %lu", + (unsigned long) strip); + return (0); + } + if (!TIFFReadBufferSetup(tif, 0, bytecountm)) + return (0); + } + if (tif->tif_flags&TIFF_BUFFERMMAP) { + tif->tif_curstrip = NOSTRIP; + if (!TIFFReadBufferSetup(tif, 0, bytecountm)) + return (0); + } + if (TIFFReadRawStrip1(tif, strip, tif->tif_rawdata, + bytecountm, module) != bytecountm) + return (0); + + tif->tif_rawdataoff = 0; + tif->tif_rawdataloaded = bytecountm; + + if (!isFillOrder(tif, td->td_fillorder) && + (tif->tif_flags & TIFF_NOBITREV) == 0) + TIFFReverseBits(tif->tif_rawdata, bytecountm); + } + } + return (TIFFStartStrip(tif, strip)); +} + +/* + * Tile-oriented Read Support + * Contributed by Nancy Cam (Silicon Graphics). + */ + +/* + * Read and decompress a tile of data. The + * tile is selected by the (x,y,z,s) coordinates. + */ +tmsize_t +TIFFReadTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s) +{ + if (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s)) + return ((tmsize_t)(-1)); + return (TIFFReadEncodedTile(tif, + TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1))); +} + +/* + * Read a tile of data and decompress the specified + * amount into the user-supplied buffer. + */ +tmsize_t +TIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size) +{ + static const char module[] = "TIFFReadEncodedTile"; + TIFFDirectory *td = &tif->tif_dir; + tmsize_t tilesize = tif->tif_tilesize; + + if (!TIFFCheckRead(tif, 1)) + return ((tmsize_t)(-1)); + if (tile >= td->td_nstrips) { + TIFFErrorExt(tif->tif_clientdata, module, + "%lu: Tile out of range, max %lu", + (unsigned long) tile, (unsigned long) td->td_nstrips); + return ((tmsize_t)(-1)); + } + if (size == (tmsize_t)(-1)) + size = tilesize; + else if (size > tilesize) + size = tilesize; + if (TIFFFillTile(tif, tile) && (*tif->tif_decodetile)(tif, + (uint8*) buf, size, (uint16)(tile/td->td_stripsperimage))) { + (*tif->tif_postdecode)(tif, (uint8*) buf, size); + return (size); + } else + return ((tmsize_t)(-1)); +} + +static tmsize_t +TIFFReadRawTile1(TIFF* tif, uint32 tile, void* buf, tmsize_t size, const char* module) +{ + TIFFDirectory *td = &tif->tif_dir; + + if (!_TIFFFillStriles( tif )) + return ((tmsize_t)(-1)); + + assert((tif->tif_flags&TIFF_NOREADRAW)==0); + if (!isMapped(tif)) { + tmsize_t cc; + + if (!SeekOK(tif, td->td_stripoffset[tile])) { + TIFFErrorExt(tif->tif_clientdata, module, + "Seek error at row %lu, col %lu, tile %lu", + (unsigned long) tif->tif_row, + (unsigned long) tif->tif_col, + (unsigned long) tile); + return ((tmsize_t)(-1)); + } + cc = TIFFReadFile(tif, buf, size); + if (cc != size) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + "Read error at row %lu, col %lu; got %I64u bytes, expected %I64u", + (unsigned long) tif->tif_row, + (unsigned long) tif->tif_col, + (unsigned __int64) cc, + (unsigned __int64) size); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "Read error at row %lu, col %lu; got %llu bytes, expected %llu", + (unsigned long) tif->tif_row, + (unsigned long) tif->tif_col, + (unsigned long long) cc, + (unsigned long long) size); +#endif + return ((tmsize_t)(-1)); + } + } else { + tmsize_t ma,mb; + tmsize_t n; + ma=(tmsize_t)td->td_stripoffset[tile]; + mb=ma+size; + if (((uint64)ma!=td->td_stripoffset[tile])||(ma>tif->tif_size)) + n=0; + else if ((mbtif->tif_size)) + n=tif->tif_size-ma; + else + n=size; + if (n!=size) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, +"Read error at row %lu, col %lu, tile %lu; got %I64u bytes, expected %I64u", + (unsigned long) tif->tif_row, + (unsigned long) tif->tif_col, + (unsigned long) tile, + (unsigned __int64) n, + (unsigned __int64) size); +#else + TIFFErrorExt(tif->tif_clientdata, module, +"Read error at row %lu, col %lu, tile %lu; got %llu bytes, expected %llu", + (unsigned long) tif->tif_row, + (unsigned long) tif->tif_col, + (unsigned long) tile, + (unsigned long long) n, + (unsigned long long) size); +#endif + return ((tmsize_t)(-1)); + } + _TIFFmemcpy(buf, tif->tif_base + ma, size); + } + return (size); +} + +/* + * Read a tile of data from the file. + */ +tmsize_t +TIFFReadRawTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size) +{ + static const char module[] = "TIFFReadRawTile"; + TIFFDirectory *td = &tif->tif_dir; + uint64 bytecount64; + tmsize_t bytecountm; + + if (!TIFFCheckRead(tif, 1)) + return ((tmsize_t)(-1)); + if (tile >= td->td_nstrips) { + TIFFErrorExt(tif->tif_clientdata, module, + "%lu: Tile out of range, max %lu", + (unsigned long) tile, (unsigned long) td->td_nstrips); + return ((tmsize_t)(-1)); + } + if (tif->tif_flags&TIFF_NOREADRAW) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Compression scheme does not support access to raw uncompressed data"); + return ((tmsize_t)(-1)); + } + bytecount64 = td->td_stripbytecount[tile]; + if (size != (tmsize_t)(-1) && (uint64)size < bytecount64) + bytecount64 = (uint64)size; + bytecountm = (tmsize_t)bytecount64; + if ((uint64)bytecountm!=bytecount64) + { + TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); + return ((tmsize_t)(-1)); + } + return (TIFFReadRawTile1(tif, tile, buf, bytecountm, module)); +} + +/* + * Read the specified tile and setup for decoding. The data buffer is + * expanded, as necessary, to hold the tile's data. + */ +int +TIFFFillTile(TIFF* tif, uint32 tile) +{ + static const char module[] = "TIFFFillTile"; + TIFFDirectory *td = &tif->tif_dir; + + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; + + if ((tif->tif_flags&TIFF_NOREADRAW)==0) + { + uint64 bytecount = td->td_stripbytecount[tile]; + if (bytecount <= 0) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + "%I64u: Invalid tile byte count, tile %lu", + (unsigned __int64) bytecount, + (unsigned long) tile); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "%llu: Invalid tile byte count, tile %lu", + (unsigned long long) bytecount, + (unsigned long) tile); +#endif + return (0); + } + if (isMapped(tif) && + (isFillOrder(tif, td->td_fillorder) + || (tif->tif_flags & TIFF_NOBITREV))) { + /* + * The image is mapped into memory and we either don't + * need to flip bits or the compression routine is + * going to handle this operation itself. In this + * case, avoid copying the raw data and instead just + * reference the data from the memory mapped file + * image. This assumes that the decompression + * routines do not modify the contents of the raw data + * buffer (if they try to, the application will get a + * fault since the file is mapped read-only). + */ + if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) { + _TIFFfree(tif->tif_rawdata); + tif->tif_rawdata = NULL; + tif->tif_rawdatasize = 0; + } + tif->tif_flags &= ~TIFF_MYBUFFER; + /* + * We must check for overflow, potentially causing + * an OOB read. Instead of simple + * + * td->td_stripoffset[tile]+bytecount > tif->tif_size + * + * comparison (which can overflow) we do the following + * two comparisons: + */ + if (bytecount > (uint64)tif->tif_size || + td->td_stripoffset[tile] > (uint64)tif->tif_size - bytecount) { + tif->tif_curtile = NOTILE; + return (0); + } + tif->tif_rawdatasize = (tmsize_t)bytecount; + tif->tif_rawdata = + tif->tif_base + (tmsize_t)td->td_stripoffset[tile]; + tif->tif_rawdataoff = 0; + tif->tif_rawdataloaded = (tmsize_t) bytecount; + tif->tif_flags |= TIFF_BUFFERMMAP; + } else { + /* + * Expand raw data buffer, if needed, to hold data + * tile coming from file (perhaps should set upper + * bound on the size of a buffer we'll use?). + */ + tmsize_t bytecountm; + bytecountm=(tmsize_t)bytecount; + if ((uint64)bytecountm!=bytecount) + { + TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); + return(0); + } + if (bytecountm > tif->tif_rawdatasize) { + tif->tif_curtile = NOTILE; + if ((tif->tif_flags & TIFF_MYBUFFER) == 0) { + TIFFErrorExt(tif->tif_clientdata, module, + "Data buffer too small to hold tile %lu", + (unsigned long) tile); + return (0); + } + if (!TIFFReadBufferSetup(tif, 0, bytecountm)) + return (0); + } + if (tif->tif_flags&TIFF_BUFFERMMAP) { + tif->tif_curtile = NOTILE; + if (!TIFFReadBufferSetup(tif, 0, bytecountm)) + return (0); + } + + if (TIFFReadRawTile1(tif, tile, tif->tif_rawdata, + bytecountm, module) != bytecountm) + return (0); + + tif->tif_rawdataoff = 0; + tif->tif_rawdataloaded = bytecountm; + + if (!isFillOrder(tif, td->td_fillorder) && + (tif->tif_flags & TIFF_NOBITREV) == 0) + TIFFReverseBits(tif->tif_rawdata, + tif->tif_rawdataloaded); + } + } + return (TIFFStartTile(tif, tile)); +} + +/* + * Setup the raw data buffer in preparation for + * reading a strip of raw data. If the buffer + * is specified as zero, then a buffer of appropriate + * size is allocated by the library. Otherwise, + * the client must guarantee that the buffer is + * large enough to hold any individual strip of + * raw data. + */ +int +TIFFReadBufferSetup(TIFF* tif, void* bp, tmsize_t size) +{ + static const char module[] = "TIFFReadBufferSetup"; + + assert((tif->tif_flags&TIFF_NOREADRAW)==0); + tif->tif_flags &= ~TIFF_BUFFERMMAP; + + if (tif->tif_rawdata) { + if (tif->tif_flags & TIFF_MYBUFFER) + _TIFFfree(tif->tif_rawdata); + tif->tif_rawdata = NULL; + tif->tif_rawdatasize = 0; + } + if (bp) { + tif->tif_rawdatasize = size; + tif->tif_rawdata = (uint8*) bp; + tif->tif_flags &= ~TIFF_MYBUFFER; + } else { + tif->tif_rawdatasize = (tmsize_t)TIFFroundup_64((uint64)size, 1024); + if (tif->tif_rawdatasize==0) + tif->tif_rawdatasize=(tmsize_t)(-1); + tif->tif_rawdata = (uint8*) _TIFFmalloc(tif->tif_rawdatasize); + tif->tif_flags |= TIFF_MYBUFFER; + } + if (tif->tif_rawdata == NULL) { + TIFFErrorExt(tif->tif_clientdata, module, + "No space for data buffer at scanline %lu", + (unsigned long) tif->tif_row); + tif->tif_rawdatasize = 0; + return (0); + } + return (1); +} + +/* + * Set state to appear as if a + * strip has just been read in. + */ +static int +TIFFStartStrip(TIFF* tif, uint32 strip) +{ + TIFFDirectory *td = &tif->tif_dir; + + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; + + if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { + if (!(*tif->tif_setupdecode)(tif)) + return (0); + tif->tif_flags |= TIFF_CODERSETUP; + } + tif->tif_curstrip = strip; + tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip; + tif->tif_flags &= ~TIFF_BUF4WRITE; + + if (tif->tif_flags&TIFF_NOREADRAW) + { + tif->tif_rawcp = NULL; + tif->tif_rawcc = 0; + } + else + { + tif->tif_rawcp = tif->tif_rawdata; + tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[strip]; + } + return ((*tif->tif_predecode)(tif, + (uint16)(strip / td->td_stripsperimage))); +} + +/* + * Set state to appear as if a + * tile has just been read in. + */ +static int +TIFFStartTile(TIFF* tif, uint32 tile) +{ + TIFFDirectory *td = &tif->tif_dir; + + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; + + if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { + if (!(*tif->tif_setupdecode)(tif)) + return (0); + tif->tif_flags |= TIFF_CODERSETUP; + } + tif->tif_curtile = tile; + tif->tif_row = + (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) * + td->td_tilelength; + tif->tif_col = + (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) * + td->td_tilewidth; + tif->tif_flags &= ~TIFF_BUF4WRITE; + if (tif->tif_flags&TIFF_NOREADRAW) + { + tif->tif_rawcp = NULL; + tif->tif_rawcc = 0; + } + else + { + tif->tif_rawcp = tif->tif_rawdata; + tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile]; + } + return ((*tif->tif_predecode)(tif, + (uint16)(tile/td->td_stripsperimage))); +} + +static int +TIFFCheckRead(TIFF* tif, int tiles) +{ + if (tif->tif_mode == O_WRONLY) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "File not open for reading"); + return (0); + } + if (tiles ^ isTiled(tif)) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, tiles ? + "Can not read tiles from a stripped image" : + "Can not read scanlines from a tiled image"); + return (0); + } + return (1); +} + +void +_TIFFNoPostDecode(TIFF* tif, uint8* buf, tmsize_t cc) +{ + (void) tif; (void) buf; (void) cc; +} + +void +_TIFFSwab16BitData(TIFF* tif, uint8* buf, tmsize_t cc) +{ + (void) tif; + assert((cc & 1) == 0); + TIFFSwabArrayOfShort((uint16*) buf, cc/2); +} + +void +_TIFFSwab24BitData(TIFF* tif, uint8* buf, tmsize_t cc) +{ + (void) tif; + assert((cc % 3) == 0); + TIFFSwabArrayOfTriples((uint8*) buf, cc/3); +} + +void +_TIFFSwab32BitData(TIFF* tif, uint8* buf, tmsize_t cc) +{ + (void) tif; + assert((cc & 3) == 0); + TIFFSwabArrayOfLong((uint32*) buf, cc/4); +} + +void +_TIFFSwab64BitData(TIFF* tif, uint8* buf, tmsize_t cc) +{ + (void) tif; + assert((cc & 7) == 0); + TIFFSwabArrayOfDouble((double*) buf, cc/8); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_stream.cxx b/Source/LibTIFF4/tif_stream.cxx index 20d47d7..07378df 100644 --- a/Source/LibTIFF4/tif_stream.cxx +++ b/Source/LibTIFF4/tif_stream.cxx @@ -1,425 +1,425 @@ -/* $Id: tif_stream.cxx,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1996 Sam Leffler - * Copyright (c) 1991-1996 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library UNIX-specific Routines. - */ -#include "tiffiop.h" -#include - -#ifndef __VMS -using namespace std; -#endif - -/* - ISO C++ uses a 'std::streamsize' type to define counts. This makes - it similar to, (but perhaps not the same as) size_t. - - The std::ios::pos_type is used to represent stream positions as used - by tellg(), tellp(), seekg(), and seekp(). This makes it similar to - (but perhaps not the same as) 'off_t'. The std::ios::streampos type - is used for character streams, but is documented to not be an - integral type anymore, so it should *not* be assigned to an integral - type. - - The std::ios::off_type is used to specify relative offsets needed by - the variants of seekg() and seekp() which accept a relative offset - argument. - - Useful prototype knowledge: - - Obtain read position - ios::pos_type basic_istream::tellg() - - Set read position - basic_istream& basic_istream::seekg(ios::pos_type) - basic_istream& basic_istream::seekg(ios::off_type, ios_base::seekdir) - - Read data - basic_istream& istream::read(char *str, streamsize count) - - Number of characters read in last unformatted read - streamsize istream::gcount(); - - Obtain write position - ios::pos_type basic_ostream::tellp() - - Set write position - basic_ostream& basic_ostream::seekp(ios::pos_type) - basic_ostream& basic_ostream::seekp(ios::off_type, ios_base::seekdir) - - Write data - basic_ostream& ostream::write(const char *str, streamsize count) -*/ - -struct tiffis_data; -struct tiffos_data; - -extern "C" { - - static tmsize_t _tiffosReadProc(thandle_t, void*, tmsize_t); - static tmsize_t _tiffisReadProc(thandle_t fd, void* buf, tmsize_t size); - static tmsize_t _tiffosWriteProc(thandle_t fd, void* buf, tmsize_t size); - static tmsize_t _tiffisWriteProc(thandle_t, void*, tmsize_t); - static uint64 _tiffosSeekProc(thandle_t fd, uint64 off, int whence); - static uint64 _tiffisSeekProc(thandle_t fd, uint64 off, int whence); - static uint64 _tiffosSizeProc(thandle_t fd); - static uint64 _tiffisSizeProc(thandle_t fd); - static int _tiffosCloseProc(thandle_t fd); - static int _tiffisCloseProc(thandle_t fd); - static int _tiffDummyMapProc(thandle_t , void** base, toff_t* size ); - static void _tiffDummyUnmapProc(thandle_t , void* base, toff_t size ); - static TIFF* _tiffStreamOpen(const char* name, const char* mode, void *fd); - -struct tiffis_data -{ - istream *stream; - ios::pos_type start_pos; -}; - -struct tiffos_data -{ - ostream *stream; - ios::pos_type start_pos; -}; - -static tmsize_t -_tiffosReadProc(thandle_t, void*, tmsize_t) -{ - return 0; -} - -static tmsize_t -_tiffisReadProc(thandle_t fd, void* buf, tmsize_t size) -{ - tiffis_data *data = reinterpret_cast(fd); - - // Verify that type does not overflow. - streamsize request_size = size; - if (static_cast(request_size) != size) - return static_cast(-1); - - data->stream->read((char *) buf, request_size); - - return static_cast(data->stream->gcount()); -} - -static tmsize_t -_tiffosWriteProc(thandle_t fd, void* buf, tmsize_t size) -{ - tiffos_data *data = reinterpret_cast(fd); - ostream *os = data->stream; - ios::pos_type pos = os->tellp(); - - // Verify that type does not overflow. - streamsize request_size = size; - if (static_cast(request_size) != size) - return static_cast(-1); - - os->write(reinterpret_cast(buf), request_size); - - return static_cast(os->tellp() - pos); -} - -static tmsize_t -_tiffisWriteProc(thandle_t, void*, tmsize_t) -{ - return 0; -} - -static uint64 -_tiffosSeekProc(thandle_t fd, uint64 off, int whence) -{ - tiffos_data *data = reinterpret_cast(fd); - ostream *os = data->stream; - - // if the stream has already failed, don't do anything - if( os->fail() ) - return static_cast(-1); - - switch(whence) { - case SEEK_SET: - { - // Compute 64-bit offset - uint64 new_offset = static_cast(data->start_pos) + off; - - // Verify that value does not overflow - ios::off_type offset = static_cast(new_offset); - if (static_cast(offset) != new_offset) - return static_cast(-1); - - os->seekp(offset, ios::beg); - break; - } - case SEEK_CUR: - { - // Verify that value does not overflow - ios::off_type offset = static_cast(off); - if (static_cast(offset) != off) - return static_cast(-1); - - os->seekp(offset, ios::cur); - break; - } - case SEEK_END: - { - // Verify that value does not overflow - ios::off_type offset = static_cast(off); - if (static_cast(offset) != off) - return static_cast(-1); - - os->seekp(offset, ios::end); - break; - } - } - - // Attempt to workaround problems with seeking past the end of the - // stream. ofstream doesn't have a problem with this but - // ostrstream/ostringstream does. In that situation, add intermediate - // '\0' characters. - if( os->fail() ) { -#ifdef __VMS - int old_state; -#else - ios::iostate old_state; -#endif - ios::pos_type origin; - - old_state = os->rdstate(); - // reset the fail bit or else tellp() won't work below - os->clear(os->rdstate() & ~ios::failbit); - switch( whence ) { - case SEEK_SET: - default: - origin = data->start_pos; - break; - case SEEK_CUR: - origin = os->tellp(); - break; - case SEEK_END: - os->seekp(0, ios::end); - origin = os->tellp(); - break; - } - // restore original stream state - os->clear(old_state); - - // only do something if desired seek position is valid - if( (static_cast(origin) + off) > static_cast(data->start_pos) ) { - uint64 num_fill; - - // clear the fail bit - os->clear(os->rdstate() & ~ios::failbit); - - // extend the stream to the expected size - os->seekp(0, ios::end); - num_fill = (static_cast(origin)) + off - os->tellp(); - for( uint64 i = 0; i < num_fill; i++ ) - os->put('\0'); - - // retry the seek - os->seekp(static_cast(static_cast(origin) + off), ios::beg); - } - } - - return static_cast(os->tellp()); -} - -static uint64 -_tiffisSeekProc(thandle_t fd, uint64 off, int whence) -{ - tiffis_data *data = reinterpret_cast(fd); - - switch(whence) { - case SEEK_SET: - { - // Compute 64-bit offset - uint64 new_offset = static_cast(data->start_pos) + off; - - // Verify that value does not overflow - ios::off_type offset = static_cast(new_offset); - if (static_cast(offset) != new_offset) - return static_cast(-1); - - data->stream->seekg(offset, ios::beg); - break; - } - case SEEK_CUR: - { - // Verify that value does not overflow - ios::off_type offset = static_cast(off); - if (static_cast(offset) != off) - return static_cast(-1); - - data->stream->seekg(offset, ios::cur); - break; - } - case SEEK_END: - { - // Verify that value does not overflow - ios::off_type offset = static_cast(off); - if (static_cast(offset) != off) - return static_cast(-1); - - data->stream->seekg(offset, ios::end); - break; - } - } - - return (uint64) (data->stream->tellg() - data->start_pos); -} - -static uint64 -_tiffosSizeProc(thandle_t fd) -{ - tiffos_data *data = reinterpret_cast(fd); - ostream *os = data->stream; - ios::pos_type pos = os->tellp(); - ios::pos_type len; - - os->seekp(0, ios::end); - len = os->tellp(); - os->seekp(pos); - - return (uint64) len; -} - -static uint64 -_tiffisSizeProc(thandle_t fd) -{ - tiffis_data *data = reinterpret_cast(fd); - ios::pos_type pos = data->stream->tellg(); - ios::pos_type len; - - data->stream->seekg(0, ios::end); - len = data->stream->tellg(); - data->stream->seekg(pos); - - return (uint64) len; -} - -static int -_tiffosCloseProc(thandle_t fd) -{ - // Our stream was not allocated by us, so it shouldn't be closed by us. - delete reinterpret_cast(fd); - return 0; -} - -static int -_tiffisCloseProc(thandle_t fd) -{ - // Our stream was not allocated by us, so it shouldn't be closed by us. - delete reinterpret_cast(fd); - return 0; -} - -static int -_tiffDummyMapProc(thandle_t , void** base, toff_t* size ) -{ - return (0); -} - -static void -_tiffDummyUnmapProc(thandle_t , void* base, toff_t size ) -{ -} - -/* - * Open a TIFF file descriptor for read/writing. - */ -static TIFF* -_tiffStreamOpen(const char* name, const char* mode, void *fd) -{ - TIFF* tif; - - if( strchr(mode, 'w') ) { - tiffos_data *data = new tiffos_data; - data->stream = reinterpret_cast(fd); - data->start_pos = data->stream->tellp(); - - // Open for writing. - tif = TIFFClientOpen(name, mode, - reinterpret_cast(data), - _tiffosReadProc, - _tiffosWriteProc, - _tiffosSeekProc, - _tiffosCloseProc, - _tiffosSizeProc, - _tiffDummyMapProc, - _tiffDummyUnmapProc); - } else { - tiffis_data *data = new tiffis_data; - data->stream = reinterpret_cast(fd); - data->start_pos = data->stream->tellg(); - // Open for reading. - tif = TIFFClientOpen(name, mode, - reinterpret_cast(data), - _tiffisReadProc, - _tiffisWriteProc, - _tiffisSeekProc, - _tiffisCloseProc, - _tiffisSizeProc, - _tiffDummyMapProc, - _tiffDummyUnmapProc); - } - - return (tif); -} - -} /* extern "C" */ - -TIFF* -TIFFStreamOpen(const char* name, ostream *os) -{ - // If os is either a ostrstream or ostringstream, and has no data - // written to it yet, then tellp() will return -1 which will break us. - // We workaround this by writing out a dummy character and - // then seek back to the beginning. - if( !os->fail() && static_cast(os->tellp()) < 0 ) { - *os << '\0'; - os->seekp(0); - } - - // NB: We don't support mapped files with streams so add 'm' - return _tiffStreamOpen(name, "wm", os); -} - -TIFF* -TIFFStreamOpen(const char* name, istream *is) -{ - // NB: We don't support mapped files with streams so add 'm' - return _tiffStreamOpen(name, "rm", is); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - Local Variables: - mode: c - indent-tabs-mode: true - c-basic-offset: 8 - End: -*/ +/* $Id: tif_stream.cxx,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1996 Sam Leffler + * Copyright (c) 1991-1996 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library UNIX-specific Routines. + */ +#include "tiffiop.h" +#include + +#ifndef __VMS +using namespace std; +#endif + +/* + ISO C++ uses a 'std::streamsize' type to define counts. This makes + it similar to, (but perhaps not the same as) size_t. + + The std::ios::pos_type is used to represent stream positions as used + by tellg(), tellp(), seekg(), and seekp(). This makes it similar to + (but perhaps not the same as) 'off_t'. The std::ios::streampos type + is used for character streams, but is documented to not be an + integral type anymore, so it should *not* be assigned to an integral + type. + + The std::ios::off_type is used to specify relative offsets needed by + the variants of seekg() and seekp() which accept a relative offset + argument. + + Useful prototype knowledge: + + Obtain read position + ios::pos_type basic_istream::tellg() + + Set read position + basic_istream& basic_istream::seekg(ios::pos_type) + basic_istream& basic_istream::seekg(ios::off_type, ios_base::seekdir) + + Read data + basic_istream& istream::read(char *str, streamsize count) + + Number of characters read in last unformatted read + streamsize istream::gcount(); + + Obtain write position + ios::pos_type basic_ostream::tellp() + + Set write position + basic_ostream& basic_ostream::seekp(ios::pos_type) + basic_ostream& basic_ostream::seekp(ios::off_type, ios_base::seekdir) + + Write data + basic_ostream& ostream::write(const char *str, streamsize count) +*/ + +struct tiffis_data; +struct tiffos_data; + +extern "C" { + + static tmsize_t _tiffosReadProc(thandle_t, void*, tmsize_t); + static tmsize_t _tiffisReadProc(thandle_t fd, void* buf, tmsize_t size); + static tmsize_t _tiffosWriteProc(thandle_t fd, void* buf, tmsize_t size); + static tmsize_t _tiffisWriteProc(thandle_t, void*, tmsize_t); + static uint64 _tiffosSeekProc(thandle_t fd, uint64 off, int whence); + static uint64 _tiffisSeekProc(thandle_t fd, uint64 off, int whence); + static uint64 _tiffosSizeProc(thandle_t fd); + static uint64 _tiffisSizeProc(thandle_t fd); + static int _tiffosCloseProc(thandle_t fd); + static int _tiffisCloseProc(thandle_t fd); + static int _tiffDummyMapProc(thandle_t , void** base, toff_t* size ); + static void _tiffDummyUnmapProc(thandle_t , void* base, toff_t size ); + static TIFF* _tiffStreamOpen(const char* name, const char* mode, void *fd); + +struct tiffis_data +{ + istream *stream; + ios::pos_type start_pos; +}; + +struct tiffos_data +{ + ostream *stream; + ios::pos_type start_pos; +}; + +static tmsize_t +_tiffosReadProc(thandle_t, void*, tmsize_t) +{ + return 0; +} + +static tmsize_t +_tiffisReadProc(thandle_t fd, void* buf, tmsize_t size) +{ + tiffis_data *data = reinterpret_cast(fd); + + // Verify that type does not overflow. + streamsize request_size = size; + if (static_cast(request_size) != size) + return static_cast(-1); + + data->stream->read((char *) buf, request_size); + + return static_cast(data->stream->gcount()); +} + +static tmsize_t +_tiffosWriteProc(thandle_t fd, void* buf, tmsize_t size) +{ + tiffos_data *data = reinterpret_cast(fd); + ostream *os = data->stream; + ios::pos_type pos = os->tellp(); + + // Verify that type does not overflow. + streamsize request_size = size; + if (static_cast(request_size) != size) + return static_cast(-1); + + os->write(reinterpret_cast(buf), request_size); + + return static_cast(os->tellp() - pos); +} + +static tmsize_t +_tiffisWriteProc(thandle_t, void*, tmsize_t) +{ + return 0; +} + +static uint64 +_tiffosSeekProc(thandle_t fd, uint64 off, int whence) +{ + tiffos_data *data = reinterpret_cast(fd); + ostream *os = data->stream; + + // if the stream has already failed, don't do anything + if( os->fail() ) + return static_cast(-1); + + switch(whence) { + case SEEK_SET: + { + // Compute 64-bit offset + uint64 new_offset = static_cast(data->start_pos) + off; + + // Verify that value does not overflow + ios::off_type offset = static_cast(new_offset); + if (static_cast(offset) != new_offset) + return static_cast(-1); + + os->seekp(offset, ios::beg); + break; + } + case SEEK_CUR: + { + // Verify that value does not overflow + ios::off_type offset = static_cast(off); + if (static_cast(offset) != off) + return static_cast(-1); + + os->seekp(offset, ios::cur); + break; + } + case SEEK_END: + { + // Verify that value does not overflow + ios::off_type offset = static_cast(off); + if (static_cast(offset) != off) + return static_cast(-1); + + os->seekp(offset, ios::end); + break; + } + } + + // Attempt to workaround problems with seeking past the end of the + // stream. ofstream doesn't have a problem with this but + // ostrstream/ostringstream does. In that situation, add intermediate + // '\0' characters. + if( os->fail() ) { +#ifdef __VMS + int old_state; +#else + ios::iostate old_state; +#endif + ios::pos_type origin; + + old_state = os->rdstate(); + // reset the fail bit or else tellp() won't work below + os->clear(os->rdstate() & ~ios::failbit); + switch( whence ) { + case SEEK_SET: + default: + origin = data->start_pos; + break; + case SEEK_CUR: + origin = os->tellp(); + break; + case SEEK_END: + os->seekp(0, ios::end); + origin = os->tellp(); + break; + } + // restore original stream state + os->clear(old_state); + + // only do something if desired seek position is valid + if( (static_cast(origin) + off) > static_cast(data->start_pos) ) { + uint64 num_fill; + + // clear the fail bit + os->clear(os->rdstate() & ~ios::failbit); + + // extend the stream to the expected size + os->seekp(0, ios::end); + num_fill = (static_cast(origin)) + off - os->tellp(); + for( uint64 i = 0; i < num_fill; i++ ) + os->put('\0'); + + // retry the seek + os->seekp(static_cast(static_cast(origin) + off), ios::beg); + } + } + + return static_cast(os->tellp()); +} + +static uint64 +_tiffisSeekProc(thandle_t fd, uint64 off, int whence) +{ + tiffis_data *data = reinterpret_cast(fd); + + switch(whence) { + case SEEK_SET: + { + // Compute 64-bit offset + uint64 new_offset = static_cast(data->start_pos) + off; + + // Verify that value does not overflow + ios::off_type offset = static_cast(new_offset); + if (static_cast(offset) != new_offset) + return static_cast(-1); + + data->stream->seekg(offset, ios::beg); + break; + } + case SEEK_CUR: + { + // Verify that value does not overflow + ios::off_type offset = static_cast(off); + if (static_cast(offset) != off) + return static_cast(-1); + + data->stream->seekg(offset, ios::cur); + break; + } + case SEEK_END: + { + // Verify that value does not overflow + ios::off_type offset = static_cast(off); + if (static_cast(offset) != off) + return static_cast(-1); + + data->stream->seekg(offset, ios::end); + break; + } + } + + return (uint64) (data->stream->tellg() - data->start_pos); +} + +static uint64 +_tiffosSizeProc(thandle_t fd) +{ + tiffos_data *data = reinterpret_cast(fd); + ostream *os = data->stream; + ios::pos_type pos = os->tellp(); + ios::pos_type len; + + os->seekp(0, ios::end); + len = os->tellp(); + os->seekp(pos); + + return (uint64) len; +} + +static uint64 +_tiffisSizeProc(thandle_t fd) +{ + tiffis_data *data = reinterpret_cast(fd); + ios::pos_type pos = data->stream->tellg(); + ios::pos_type len; + + data->stream->seekg(0, ios::end); + len = data->stream->tellg(); + data->stream->seekg(pos); + + return (uint64) len; +} + +static int +_tiffosCloseProc(thandle_t fd) +{ + // Our stream was not allocated by us, so it shouldn't be closed by us. + delete reinterpret_cast(fd); + return 0; +} + +static int +_tiffisCloseProc(thandle_t fd) +{ + // Our stream was not allocated by us, so it shouldn't be closed by us. + delete reinterpret_cast(fd); + return 0; +} + +static int +_tiffDummyMapProc(thandle_t , void** base, toff_t* size ) +{ + return (0); +} + +static void +_tiffDummyUnmapProc(thandle_t , void* base, toff_t size ) +{ +} + +/* + * Open a TIFF file descriptor for read/writing. + */ +static TIFF* +_tiffStreamOpen(const char* name, const char* mode, void *fd) +{ + TIFF* tif; + + if( strchr(mode, 'w') ) { + tiffos_data *data = new tiffos_data; + data->stream = reinterpret_cast(fd); + data->start_pos = data->stream->tellp(); + + // Open for writing. + tif = TIFFClientOpen(name, mode, + reinterpret_cast(data), + _tiffosReadProc, + _tiffosWriteProc, + _tiffosSeekProc, + _tiffosCloseProc, + _tiffosSizeProc, + _tiffDummyMapProc, + _tiffDummyUnmapProc); + } else { + tiffis_data *data = new tiffis_data; + data->stream = reinterpret_cast(fd); + data->start_pos = data->stream->tellg(); + // Open for reading. + tif = TIFFClientOpen(name, mode, + reinterpret_cast(data), + _tiffisReadProc, + _tiffisWriteProc, + _tiffisSeekProc, + _tiffisCloseProc, + _tiffisSizeProc, + _tiffDummyMapProc, + _tiffDummyUnmapProc); + } + + return (tif); +} + +} /* extern "C" */ + +TIFF* +TIFFStreamOpen(const char* name, ostream *os) +{ + // If os is either a ostrstream or ostringstream, and has no data + // written to it yet, then tellp() will return -1 which will break us. + // We workaround this by writing out a dummy character and + // then seek back to the beginning. + if( !os->fail() && static_cast(os->tellp()) < 0 ) { + *os << '\0'; + os->seekp(0); + } + + // NB: We don't support mapped files with streams so add 'm' + return _tiffStreamOpen(name, "wm", os); +} + +TIFF* +TIFFStreamOpen(const char* name, istream *is) +{ + // NB: We don't support mapped files with streams so add 'm' + return _tiffStreamOpen(name, "rm", is); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + Local Variables: + mode: c + indent-tabs-mode: true + c-basic-offset: 8 + End: +*/ diff --git a/Source/LibTIFF4/tif_strip.c b/Source/LibTIFF4/tif_strip.c index e214d79..2c5788e 100644 --- a/Source/LibTIFF4/tif_strip.c +++ b/Source/LibTIFF4/tif_strip.c @@ -1,383 +1,383 @@ -/* $Id: tif_strip.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1991-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * - * Strip-organized Image Support Routines. - */ -#include "tiffiop.h" - -/* - * Compute which strip a (row,sample) value is in. - */ -uint32 -TIFFComputeStrip(TIFF* tif, uint32 row, uint16 sample) -{ - static const char module[] = "TIFFComputeStrip"; - TIFFDirectory *td = &tif->tif_dir; - uint32 strip; - - strip = row / td->td_rowsperstrip; - if (td->td_planarconfig == PLANARCONFIG_SEPARATE) { - if (sample >= td->td_samplesperpixel) { - TIFFErrorExt(tif->tif_clientdata, module, - "%lu: Sample out of range, max %lu", - (unsigned long) sample, (unsigned long) td->td_samplesperpixel); - return (0); - } - strip += (uint32)sample*td->td_stripsperimage; - } - return (strip); -} - -/* - * Compute how many strips are in an image. - */ -uint32 -TIFFNumberOfStrips(TIFF* tif) -{ - TIFFDirectory *td = &tif->tif_dir; - uint32 nstrips; - - nstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 : - TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip)); - if (td->td_planarconfig == PLANARCONFIG_SEPARATE) - nstrips = _TIFFMultiply32(tif, nstrips, (uint32)td->td_samplesperpixel, - "TIFFNumberOfStrips"); - return (nstrips); -} - -/* - * Compute the # bytes in a variable height, row-aligned strip. - */ -uint64 -TIFFVStripSize64(TIFF* tif, uint32 nrows) -{ - static const char module[] = "TIFFVStripSize64"; - TIFFDirectory *td = &tif->tif_dir; - if (nrows==(uint32)(-1)) - nrows=td->td_imagelength; - if ((td->td_planarconfig==PLANARCONFIG_CONTIG)&& - (td->td_photometric == PHOTOMETRIC_YCBCR)&& - (!isUpSampled(tif))) - { - /* - * Packed YCbCr data contain one Cb+Cr for every - * HorizontalSampling*VerticalSampling Y values. - * Must also roundup width and height when calculating - * since images that are not a multiple of the - * horizontal/vertical subsampling area include - * YCbCr data for the extended image. - */ - uint16 ycbcrsubsampling[2]; - uint16 samplingblock_samples; - uint32 samplingblocks_hor; - uint32 samplingblocks_ver; - uint64 samplingrow_samples; - uint64 samplingrow_size; - if(td->td_samplesperpixel!=3) - { - TIFFErrorExt(tif->tif_clientdata,module, - "Invalid td_samplesperpixel value"); - return 0; - } - TIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0, - ycbcrsubsampling+1); - if ((ycbcrsubsampling[0] != 1 && ycbcrsubsampling[0] != 2 && ycbcrsubsampling[0] != 4) - ||(ycbcrsubsampling[1] != 1 && ycbcrsubsampling[1] != 2 && ycbcrsubsampling[1] != 4)) - { - TIFFErrorExt(tif->tif_clientdata,module, - "Invalid YCbCr subsampling (%dx%d)", - ycbcrsubsampling[0], - ycbcrsubsampling[1] ); - return 0; - } - samplingblock_samples=ycbcrsubsampling[0]*ycbcrsubsampling[1]+2; - samplingblocks_hor=TIFFhowmany_32(td->td_imagewidth,ycbcrsubsampling[0]); - samplingblocks_ver=TIFFhowmany_32(nrows,ycbcrsubsampling[1]); - samplingrow_samples=_TIFFMultiply64(tif,samplingblocks_hor,samplingblock_samples,module); - samplingrow_size=TIFFhowmany8_64(_TIFFMultiply64(tif,samplingrow_samples,td->td_bitspersample,module)); - return(_TIFFMultiply64(tif,samplingrow_size,samplingblocks_ver,module)); - } - else - return(_TIFFMultiply64(tif,nrows,TIFFScanlineSize64(tif),module)); -} -tmsize_t -TIFFVStripSize(TIFF* tif, uint32 nrows) -{ - static const char module[] = "TIFFVStripSize"; - uint64 m; - tmsize_t n; - m=TIFFVStripSize64(tif,nrows); - n=(tmsize_t)m; - if ((uint64)n!=m) - { - TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); - n=0; - } - return(n); -} - -/* - * Compute the # bytes in a raw strip. - */ -uint64 -TIFFRawStripSize64(TIFF* tif, uint32 strip) -{ - static const char module[] = "TIFFRawStripSize64"; - TIFFDirectory* td = &tif->tif_dir; - uint64 bytecount = td->td_stripbytecount[strip]; - - if (bytecount == 0) - { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "%I64u: Invalid strip byte count, strip %lu", - (unsigned __int64) bytecount, - (unsigned long) strip); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "%llu: Invalid strip byte count, strip %lu", - (unsigned long long) bytecount, - (unsigned long) strip); -#endif - bytecount = (uint64) -1; - } - - return bytecount; -} -tmsize_t -TIFFRawStripSize(TIFF* tif, uint32 strip) -{ - static const char module[] = "TIFFRawStripSize"; - uint64 m; - tmsize_t n; - m=TIFFRawStripSize64(tif,strip); - if (m==(uint64)(-1)) - n=(tmsize_t)(-1); - else - { - n=(tmsize_t)m; - if ((uint64)n!=m) - { - TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); - n=0; - } - } - return(n); -} - -/* - * Compute the # bytes in a (row-aligned) strip. - * - * Note that if RowsPerStrip is larger than the - * recorded ImageLength, then the strip size is - * truncated to reflect the actual space required - * to hold the strip. - */ -uint64 -TIFFStripSize64(TIFF* tif) -{ - TIFFDirectory* td = &tif->tif_dir; - uint32 rps = td->td_rowsperstrip; - if (rps > td->td_imagelength) - rps = td->td_imagelength; - return (TIFFVStripSize64(tif, rps)); -} -tmsize_t -TIFFStripSize(TIFF* tif) -{ - static const char module[] = "TIFFStripSize"; - uint64 m; - tmsize_t n; - m=TIFFStripSize64(tif); - n=(tmsize_t)m; - if ((uint64)n!=m) - { - TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); - n=0; - } - return(n); -} - -/* - * Compute a default strip size based on the image - * characteristics and a requested value. If the - * request is <1 then we choose a strip size according - * to certain heuristics. - */ -uint32 -TIFFDefaultStripSize(TIFF* tif, uint32 request) -{ - return (*tif->tif_defstripsize)(tif, request); -} - -uint32 -_TIFFDefaultStripSize(TIFF* tif, uint32 s) -{ - if ((int32) s < 1) { - /* - * If RowsPerStrip is unspecified, try to break the - * image up into strips that are approximately - * STRIP_SIZE_DEFAULT bytes long. - */ - uint64 scanlinesize; - uint64 rows; - scanlinesize=TIFFScanlineSize64(tif); - if (scanlinesize==0) - scanlinesize=1; - rows=(uint64)STRIP_SIZE_DEFAULT/scanlinesize; - if (rows==0) - rows=1; - else if (rows>0xFFFFFFFF) - rows=0xFFFFFFFF; - s=(uint32)rows; - } - return (s); -} - -/* - * Return the number of bytes to read/write in a call to - * one of the scanline-oriented i/o routines. Note that - * this number may be 1/samples-per-pixel if data is - * stored as separate planes. - * The ScanlineSize in case of YCbCrSubsampling is defined as the - * strip size divided by the strip height, i.e. the size of a pack of vertical - * subsampling lines divided by vertical subsampling. It should thus make - * sense when multiplied by a multiple of vertical subsampling. - */ -uint64 -TIFFScanlineSize64(TIFF* tif) -{ - static const char module[] = "TIFFScanlineSize64"; - TIFFDirectory *td = &tif->tif_dir; - uint64 scanline_size; - if (td->td_planarconfig==PLANARCONFIG_CONTIG) - { - if ((td->td_photometric==PHOTOMETRIC_YCBCR)&& - (td->td_samplesperpixel==3)&& - (!isUpSampled(tif))) - { - uint16 ycbcrsubsampling[2]; - uint16 samplingblock_samples; - uint32 samplingblocks_hor; - uint64 samplingrow_samples; - uint64 samplingrow_size; - if(td->td_samplesperpixel!=3) - { - TIFFErrorExt(tif->tif_clientdata,module, - "Invalid td_samplesperpixel value"); - return 0; - } - TIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING, - ycbcrsubsampling+0, - ycbcrsubsampling+1); - if (((ycbcrsubsampling[0]!=1)&&(ycbcrsubsampling[0]!=2)&&(ycbcrsubsampling[0]!=4)) || - ((ycbcrsubsampling[1]!=1)&&(ycbcrsubsampling[1]!=2)&&(ycbcrsubsampling[1]!=4))) - { - TIFFErrorExt(tif->tif_clientdata,module, - "Invalid YCbCr subsampling"); - return 0; - } - samplingblock_samples = ycbcrsubsampling[0]*ycbcrsubsampling[1]+2; - samplingblocks_hor = TIFFhowmany_32(td->td_imagewidth,ycbcrsubsampling[0]); - samplingrow_samples = _TIFFMultiply64(tif,samplingblocks_hor,samplingblock_samples,module); - samplingrow_size = TIFFhowmany_64(_TIFFMultiply64(tif,samplingrow_samples,td->td_bitspersample,module),8); - scanline_size = (samplingrow_size/ycbcrsubsampling[1]); - } - else - { - uint64 scanline_samples; - scanline_samples=_TIFFMultiply64(tif,td->td_imagewidth,td->td_samplesperpixel,module); - scanline_size=TIFFhowmany_64(_TIFFMultiply64(tif,scanline_samples,td->td_bitspersample,module),8); - } - } - else - scanline_size=TIFFhowmany_64(_TIFFMultiply64(tif,td->td_imagewidth,td->td_bitspersample,module),8); - return(scanline_size); -} -tmsize_t -TIFFScanlineSize(TIFF* tif) -{ - static const char module[] = "TIFFScanlineSize"; - uint64 m; - tmsize_t n; - m=TIFFScanlineSize64(tif); - n=(tmsize_t)m; - if ((uint64)n!=m) - { - TIFFErrorExt(tif->tif_clientdata,module,"Integer arithmetic overflow"); - n=0; - } - return(n); -} - -/* - * Return the number of bytes required to store a complete - * decoded and packed raster scanline (as opposed to the - * I/O size returned by TIFFScanlineSize which may be less - * if data is store as separate planes). - */ -uint64 -TIFFRasterScanlineSize64(TIFF* tif) -{ - static const char module[] = "TIFFRasterScanlineSize64"; - TIFFDirectory *td = &tif->tif_dir; - uint64 scanline; - - scanline = _TIFFMultiply64(tif, td->td_bitspersample, td->td_imagewidth, module); - if (td->td_planarconfig == PLANARCONFIG_CONTIG) { - scanline = _TIFFMultiply64(tif, scanline, td->td_samplesperpixel, module); - return (TIFFhowmany8_64(scanline)); - } else - return (_TIFFMultiply64(tif, TIFFhowmany8_64(scanline), - td->td_samplesperpixel, module)); -} -tmsize_t -TIFFRasterScanlineSize(TIFF* tif) -{ - static const char module[] = "TIFFRasterScanlineSize"; - uint64 m; - tmsize_t n; - m=TIFFRasterScanlineSize64(tif); - n=(tmsize_t)m; - if ((uint64)n!=m) - { - TIFFErrorExt(tif->tif_clientdata,module,"Integer arithmetic overflow"); - n=0; - } - return(n); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_strip.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1991-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * + * Strip-organized Image Support Routines. + */ +#include "tiffiop.h" + +/* + * Compute which strip a (row,sample) value is in. + */ +uint32 +TIFFComputeStrip(TIFF* tif, uint32 row, uint16 sample) +{ + static const char module[] = "TIFFComputeStrip"; + TIFFDirectory *td = &tif->tif_dir; + uint32 strip; + + strip = row / td->td_rowsperstrip; + if (td->td_planarconfig == PLANARCONFIG_SEPARATE) { + if (sample >= td->td_samplesperpixel) { + TIFFErrorExt(tif->tif_clientdata, module, + "%lu: Sample out of range, max %lu", + (unsigned long) sample, (unsigned long) td->td_samplesperpixel); + return (0); + } + strip += (uint32)sample*td->td_stripsperimage; + } + return (strip); +} + +/* + * Compute how many strips are in an image. + */ +uint32 +TIFFNumberOfStrips(TIFF* tif) +{ + TIFFDirectory *td = &tif->tif_dir; + uint32 nstrips; + + nstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 : + TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip)); + if (td->td_planarconfig == PLANARCONFIG_SEPARATE) + nstrips = _TIFFMultiply32(tif, nstrips, (uint32)td->td_samplesperpixel, + "TIFFNumberOfStrips"); + return (nstrips); +} + +/* + * Compute the # bytes in a variable height, row-aligned strip. + */ +uint64 +TIFFVStripSize64(TIFF* tif, uint32 nrows) +{ + static const char module[] = "TIFFVStripSize64"; + TIFFDirectory *td = &tif->tif_dir; + if (nrows==(uint32)(-1)) + nrows=td->td_imagelength; + if ((td->td_planarconfig==PLANARCONFIG_CONTIG)&& + (td->td_photometric == PHOTOMETRIC_YCBCR)&& + (!isUpSampled(tif))) + { + /* + * Packed YCbCr data contain one Cb+Cr for every + * HorizontalSampling*VerticalSampling Y values. + * Must also roundup width and height when calculating + * since images that are not a multiple of the + * horizontal/vertical subsampling area include + * YCbCr data for the extended image. + */ + uint16 ycbcrsubsampling[2]; + uint16 samplingblock_samples; + uint32 samplingblocks_hor; + uint32 samplingblocks_ver; + uint64 samplingrow_samples; + uint64 samplingrow_size; + if(td->td_samplesperpixel!=3) + { + TIFFErrorExt(tif->tif_clientdata,module, + "Invalid td_samplesperpixel value"); + return 0; + } + TIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0, + ycbcrsubsampling+1); + if ((ycbcrsubsampling[0] != 1 && ycbcrsubsampling[0] != 2 && ycbcrsubsampling[0] != 4) + ||(ycbcrsubsampling[1] != 1 && ycbcrsubsampling[1] != 2 && ycbcrsubsampling[1] != 4)) + { + TIFFErrorExt(tif->tif_clientdata,module, + "Invalid YCbCr subsampling (%dx%d)", + ycbcrsubsampling[0], + ycbcrsubsampling[1] ); + return 0; + } + samplingblock_samples=ycbcrsubsampling[0]*ycbcrsubsampling[1]+2; + samplingblocks_hor=TIFFhowmany_32(td->td_imagewidth,ycbcrsubsampling[0]); + samplingblocks_ver=TIFFhowmany_32(nrows,ycbcrsubsampling[1]); + samplingrow_samples=_TIFFMultiply64(tif,samplingblocks_hor,samplingblock_samples,module); + samplingrow_size=TIFFhowmany8_64(_TIFFMultiply64(tif,samplingrow_samples,td->td_bitspersample,module)); + return(_TIFFMultiply64(tif,samplingrow_size,samplingblocks_ver,module)); + } + else + return(_TIFFMultiply64(tif,nrows,TIFFScanlineSize64(tif),module)); +} +tmsize_t +TIFFVStripSize(TIFF* tif, uint32 nrows) +{ + static const char module[] = "TIFFVStripSize"; + uint64 m; + tmsize_t n; + m=TIFFVStripSize64(tif,nrows); + n=(tmsize_t)m; + if ((uint64)n!=m) + { + TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); + n=0; + } + return(n); +} + +/* + * Compute the # bytes in a raw strip. + */ +uint64 +TIFFRawStripSize64(TIFF* tif, uint32 strip) +{ + static const char module[] = "TIFFRawStripSize64"; + TIFFDirectory* td = &tif->tif_dir; + uint64 bytecount = td->td_stripbytecount[strip]; + + if (bytecount == 0) + { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + "%I64u: Invalid strip byte count, strip %lu", + (unsigned __int64) bytecount, + (unsigned long) strip); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "%llu: Invalid strip byte count, strip %lu", + (unsigned long long) bytecount, + (unsigned long) strip); +#endif + bytecount = (uint64) -1; + } + + return bytecount; +} +tmsize_t +TIFFRawStripSize(TIFF* tif, uint32 strip) +{ + static const char module[] = "TIFFRawStripSize"; + uint64 m; + tmsize_t n; + m=TIFFRawStripSize64(tif,strip); + if (m==(uint64)(-1)) + n=(tmsize_t)(-1); + else + { + n=(tmsize_t)m; + if ((uint64)n!=m) + { + TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); + n=0; + } + } + return(n); +} + +/* + * Compute the # bytes in a (row-aligned) strip. + * + * Note that if RowsPerStrip is larger than the + * recorded ImageLength, then the strip size is + * truncated to reflect the actual space required + * to hold the strip. + */ +uint64 +TIFFStripSize64(TIFF* tif) +{ + TIFFDirectory* td = &tif->tif_dir; + uint32 rps = td->td_rowsperstrip; + if (rps > td->td_imagelength) + rps = td->td_imagelength; + return (TIFFVStripSize64(tif, rps)); +} +tmsize_t +TIFFStripSize(TIFF* tif) +{ + static const char module[] = "TIFFStripSize"; + uint64 m; + tmsize_t n; + m=TIFFStripSize64(tif); + n=(tmsize_t)m; + if ((uint64)n!=m) + { + TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); + n=0; + } + return(n); +} + +/* + * Compute a default strip size based on the image + * characteristics and a requested value. If the + * request is <1 then we choose a strip size according + * to certain heuristics. + */ +uint32 +TIFFDefaultStripSize(TIFF* tif, uint32 request) +{ + return (*tif->tif_defstripsize)(tif, request); +} + +uint32 +_TIFFDefaultStripSize(TIFF* tif, uint32 s) +{ + if ((int32) s < 1) { + /* + * If RowsPerStrip is unspecified, try to break the + * image up into strips that are approximately + * STRIP_SIZE_DEFAULT bytes long. + */ + uint64 scanlinesize; + uint64 rows; + scanlinesize=TIFFScanlineSize64(tif); + if (scanlinesize==0) + scanlinesize=1; + rows=(uint64)STRIP_SIZE_DEFAULT/scanlinesize; + if (rows==0) + rows=1; + else if (rows>0xFFFFFFFF) + rows=0xFFFFFFFF; + s=(uint32)rows; + } + return (s); +} + +/* + * Return the number of bytes to read/write in a call to + * one of the scanline-oriented i/o routines. Note that + * this number may be 1/samples-per-pixel if data is + * stored as separate planes. + * The ScanlineSize in case of YCbCrSubsampling is defined as the + * strip size divided by the strip height, i.e. the size of a pack of vertical + * subsampling lines divided by vertical subsampling. It should thus make + * sense when multiplied by a multiple of vertical subsampling. + */ +uint64 +TIFFScanlineSize64(TIFF* tif) +{ + static const char module[] = "TIFFScanlineSize64"; + TIFFDirectory *td = &tif->tif_dir; + uint64 scanline_size; + if (td->td_planarconfig==PLANARCONFIG_CONTIG) + { + if ((td->td_photometric==PHOTOMETRIC_YCBCR)&& + (td->td_samplesperpixel==3)&& + (!isUpSampled(tif))) + { + uint16 ycbcrsubsampling[2]; + uint16 samplingblock_samples; + uint32 samplingblocks_hor; + uint64 samplingrow_samples; + uint64 samplingrow_size; + if(td->td_samplesperpixel!=3) + { + TIFFErrorExt(tif->tif_clientdata,module, + "Invalid td_samplesperpixel value"); + return 0; + } + TIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING, + ycbcrsubsampling+0, + ycbcrsubsampling+1); + if (((ycbcrsubsampling[0]!=1)&&(ycbcrsubsampling[0]!=2)&&(ycbcrsubsampling[0]!=4)) || + ((ycbcrsubsampling[1]!=1)&&(ycbcrsubsampling[1]!=2)&&(ycbcrsubsampling[1]!=4))) + { + TIFFErrorExt(tif->tif_clientdata,module, + "Invalid YCbCr subsampling"); + return 0; + } + samplingblock_samples = ycbcrsubsampling[0]*ycbcrsubsampling[1]+2; + samplingblocks_hor = TIFFhowmany_32(td->td_imagewidth,ycbcrsubsampling[0]); + samplingrow_samples = _TIFFMultiply64(tif,samplingblocks_hor,samplingblock_samples,module); + samplingrow_size = TIFFhowmany_64(_TIFFMultiply64(tif,samplingrow_samples,td->td_bitspersample,module),8); + scanline_size = (samplingrow_size/ycbcrsubsampling[1]); + } + else + { + uint64 scanline_samples; + scanline_samples=_TIFFMultiply64(tif,td->td_imagewidth,td->td_samplesperpixel,module); + scanline_size=TIFFhowmany_64(_TIFFMultiply64(tif,scanline_samples,td->td_bitspersample,module),8); + } + } + else + scanline_size=TIFFhowmany_64(_TIFFMultiply64(tif,td->td_imagewidth,td->td_bitspersample,module),8); + return(scanline_size); +} +tmsize_t +TIFFScanlineSize(TIFF* tif) +{ + static const char module[] = "TIFFScanlineSize"; + uint64 m; + tmsize_t n; + m=TIFFScanlineSize64(tif); + n=(tmsize_t)m; + if ((uint64)n!=m) + { + TIFFErrorExt(tif->tif_clientdata,module,"Integer arithmetic overflow"); + n=0; + } + return(n); +} + +/* + * Return the number of bytes required to store a complete + * decoded and packed raster scanline (as opposed to the + * I/O size returned by TIFFScanlineSize which may be less + * if data is store as separate planes). + */ +uint64 +TIFFRasterScanlineSize64(TIFF* tif) +{ + static const char module[] = "TIFFRasterScanlineSize64"; + TIFFDirectory *td = &tif->tif_dir; + uint64 scanline; + + scanline = _TIFFMultiply64(tif, td->td_bitspersample, td->td_imagewidth, module); + if (td->td_planarconfig == PLANARCONFIG_CONTIG) { + scanline = _TIFFMultiply64(tif, scanline, td->td_samplesperpixel, module); + return (TIFFhowmany8_64(scanline)); + } else + return (_TIFFMultiply64(tif, TIFFhowmany8_64(scanline), + td->td_samplesperpixel, module)); +} +tmsize_t +TIFFRasterScanlineSize(TIFF* tif) +{ + static const char module[] = "TIFFRasterScanlineSize"; + uint64 m; + tmsize_t n; + m=TIFFRasterScanlineSize64(tif); + n=(tmsize_t)m; + if ((uint64)n!=m) + { + TIFFErrorExt(tif->tif_clientdata,module,"Integer arithmetic overflow"); + n=0; + } + return(n); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_swab.c b/Source/LibTIFF4/tif_swab.c index 29125f1..dc46eba 100644 --- a/Source/LibTIFF4/tif_swab.c +++ b/Source/LibTIFF4/tif_swab.c @@ -1,310 +1,310 @@ -/* $Id: tif_swab.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library Bit & Byte Swapping Support. - * - * XXX We assume short = 16-bits and long = 32-bits XXX - */ -#include "tiffiop.h" - -#ifndef TIFFSwabShort -void -TIFFSwabShort(uint16* wp) -{ - register unsigned char* cp = (unsigned char*) wp; - unsigned char t; - assert(sizeof(uint16)==2); - t = cp[1]; cp[1] = cp[0]; cp[0] = t; -} -#endif - -#ifndef TIFFSwabLong -void -TIFFSwabLong(uint32* lp) -{ - register unsigned char* cp = (unsigned char*) lp; - unsigned char t; - assert(sizeof(uint32)==4); - t = cp[3]; cp[3] = cp[0]; cp[0] = t; - t = cp[2]; cp[2] = cp[1]; cp[1] = t; -} -#endif - -#ifndef TIFFSwabLong8 -void -TIFFSwabLong8(uint64* lp) -{ - register unsigned char* cp = (unsigned char*) lp; - unsigned char t; - assert(sizeof(uint64)==8); - t = cp[7]; cp[7] = cp[0]; cp[0] = t; - t = cp[6]; cp[6] = cp[1]; cp[1] = t; - t = cp[5]; cp[5] = cp[2]; cp[2] = t; - t = cp[4]; cp[4] = cp[3]; cp[3] = t; -} -#endif - -#ifndef TIFFSwabArrayOfShort -void -TIFFSwabArrayOfShort(register uint16* wp, tmsize_t n) -{ - register unsigned char* cp; - register unsigned char t; - assert(sizeof(uint16)==2); - /* XXX unroll loop some */ - while (n-- > 0) { - cp = (unsigned char*) wp; - t = cp[1]; cp[1] = cp[0]; cp[0] = t; - wp++; - } -} -#endif - -#ifndef TIFFSwabArrayOfTriples -void -TIFFSwabArrayOfTriples(register uint8* tp, tmsize_t n) -{ - unsigned char* cp; - unsigned char t; - - /* XXX unroll loop some */ - while (n-- > 0) { - cp = (unsigned char*) tp; - t = cp[2]; cp[2] = cp[0]; cp[0] = t; - tp += 3; - } -} -#endif - -#ifndef TIFFSwabArrayOfLong -void -TIFFSwabArrayOfLong(register uint32* lp, tmsize_t n) -{ - register unsigned char *cp; - register unsigned char t; - assert(sizeof(uint32)==4); - /* XXX unroll loop some */ - while (n-- > 0) { - cp = (unsigned char *)lp; - t = cp[3]; cp[3] = cp[0]; cp[0] = t; - t = cp[2]; cp[2] = cp[1]; cp[1] = t; - lp++; - } -} -#endif - -#ifndef TIFFSwabArrayOfLong8 -void -TIFFSwabArrayOfLong8(register uint64* lp, tmsize_t n) -{ - register unsigned char *cp; - register unsigned char t; - assert(sizeof(uint64)==8); - /* XXX unroll loop some */ - while (n-- > 0) { - cp = (unsigned char *)lp; - t = cp[7]; cp[7] = cp[0]; cp[0] = t; - t = cp[6]; cp[6] = cp[1]; cp[1] = t; - t = cp[5]; cp[5] = cp[2]; cp[2] = t; - t = cp[4]; cp[4] = cp[3]; cp[3] = t; - lp++; - } -} -#endif - -#ifndef TIFFSwabFloat -void -TIFFSwabFloat(float* fp) -{ - register unsigned char* cp = (unsigned char*) fp; - unsigned char t; - assert(sizeof(float)==4); - t = cp[3]; cp[3] = cp[0]; cp[0] = t; - t = cp[2]; cp[2] = cp[1]; cp[1] = t; -} -#endif - -#ifndef TIFFSwabArrayOfFloat -void -TIFFSwabArrayOfFloat(register float* fp, tmsize_t n) -{ - register unsigned char *cp; - register unsigned char t; - assert(sizeof(float)==4); - /* XXX unroll loop some */ - while (n-- > 0) { - cp = (unsigned char *)fp; - t = cp[3]; cp[3] = cp[0]; cp[0] = t; - t = cp[2]; cp[2] = cp[1]; cp[1] = t; - fp++; - } -} -#endif - -#ifndef TIFFSwabDouble -void -TIFFSwabDouble(double *dp) -{ - register unsigned char* cp = (unsigned char*) dp; - unsigned char t; - assert(sizeof(double)==8); - t = cp[7]; cp[7] = cp[0]; cp[0] = t; - t = cp[6]; cp[6] = cp[1]; cp[1] = t; - t = cp[5]; cp[5] = cp[2]; cp[2] = t; - t = cp[4]; cp[4] = cp[3]; cp[3] = t; -} -#endif - -#ifndef TIFFSwabArrayOfDouble -void -TIFFSwabArrayOfDouble(double* dp, tmsize_t n) -{ - register unsigned char *cp; - register unsigned char t; - assert(sizeof(double)==8); - /* XXX unroll loop some */ - while (n-- > 0) { - cp = (unsigned char *)dp; - t = cp[7]; cp[7] = cp[0]; cp[0] = t; - t = cp[6]; cp[6] = cp[1]; cp[1] = t; - t = cp[5]; cp[5] = cp[2]; cp[2] = t; - t = cp[4]; cp[4] = cp[3]; cp[3] = t; - dp++; - } -} -#endif - -/* - * Bit reversal tables. TIFFBitRevTable[] gives - * the bit reversed value of . Used in various - * places in the library when the FillOrder requires - * bit reversal of byte values (e.g. CCITT Fax 3 - * encoding/decoding). TIFFNoBitRevTable is provided - * for algorithms that want an equivalent table that - * do not reverse bit values. - */ -static const unsigned char TIFFBitRevTable[256] = { - 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, - 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, - 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, - 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, - 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, - 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, - 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, - 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, - 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, - 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, - 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, - 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, - 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, - 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, - 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, - 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, - 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, - 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, - 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, - 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, - 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, - 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, - 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, - 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, - 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, - 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, - 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, - 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, - 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, - 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, - 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, - 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff -}; -static const unsigned char TIFFNoBitRevTable[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, - 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, - 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, - 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, - 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, - 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, - 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, - 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, -}; - -const unsigned char* -TIFFGetBitRevTable(int reversed) -{ - return (reversed ? TIFFBitRevTable : TIFFNoBitRevTable); -} - -void -TIFFReverseBits(uint8* cp, tmsize_t n) -{ - for (; n > 8; n -= 8) { - cp[0] = TIFFBitRevTable[cp[0]]; - cp[1] = TIFFBitRevTable[cp[1]]; - cp[2] = TIFFBitRevTable[cp[2]]; - cp[3] = TIFFBitRevTable[cp[3]]; - cp[4] = TIFFBitRevTable[cp[4]]; - cp[5] = TIFFBitRevTable[cp[5]]; - cp[6] = TIFFBitRevTable[cp[6]]; - cp[7] = TIFFBitRevTable[cp[7]]; - cp += 8; - } - while (n-- > 0) - *cp = TIFFBitRevTable[*cp], cp++; -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_swab.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library Bit & Byte Swapping Support. + * + * XXX We assume short = 16-bits and long = 32-bits XXX + */ +#include "tiffiop.h" + +#ifndef TIFFSwabShort +void +TIFFSwabShort(uint16* wp) +{ + register unsigned char* cp = (unsigned char*) wp; + unsigned char t; + assert(sizeof(uint16)==2); + t = cp[1]; cp[1] = cp[0]; cp[0] = t; +} +#endif + +#ifndef TIFFSwabLong +void +TIFFSwabLong(uint32* lp) +{ + register unsigned char* cp = (unsigned char*) lp; + unsigned char t; + assert(sizeof(uint32)==4); + t = cp[3]; cp[3] = cp[0]; cp[0] = t; + t = cp[2]; cp[2] = cp[1]; cp[1] = t; +} +#endif + +#ifndef TIFFSwabLong8 +void +TIFFSwabLong8(uint64* lp) +{ + register unsigned char* cp = (unsigned char*) lp; + unsigned char t; + assert(sizeof(uint64)==8); + t = cp[7]; cp[7] = cp[0]; cp[0] = t; + t = cp[6]; cp[6] = cp[1]; cp[1] = t; + t = cp[5]; cp[5] = cp[2]; cp[2] = t; + t = cp[4]; cp[4] = cp[3]; cp[3] = t; +} +#endif + +#ifndef TIFFSwabArrayOfShort +void +TIFFSwabArrayOfShort(register uint16* wp, tmsize_t n) +{ + register unsigned char* cp; + register unsigned char t; + assert(sizeof(uint16)==2); + /* XXX unroll loop some */ + while (n-- > 0) { + cp = (unsigned char*) wp; + t = cp[1]; cp[1] = cp[0]; cp[0] = t; + wp++; + } +} +#endif + +#ifndef TIFFSwabArrayOfTriples +void +TIFFSwabArrayOfTriples(register uint8* tp, tmsize_t n) +{ + unsigned char* cp; + unsigned char t; + + /* XXX unroll loop some */ + while (n-- > 0) { + cp = (unsigned char*) tp; + t = cp[2]; cp[2] = cp[0]; cp[0] = t; + tp += 3; + } +} +#endif + +#ifndef TIFFSwabArrayOfLong +void +TIFFSwabArrayOfLong(register uint32* lp, tmsize_t n) +{ + register unsigned char *cp; + register unsigned char t; + assert(sizeof(uint32)==4); + /* XXX unroll loop some */ + while (n-- > 0) { + cp = (unsigned char *)lp; + t = cp[3]; cp[3] = cp[0]; cp[0] = t; + t = cp[2]; cp[2] = cp[1]; cp[1] = t; + lp++; + } +} +#endif + +#ifndef TIFFSwabArrayOfLong8 +void +TIFFSwabArrayOfLong8(register uint64* lp, tmsize_t n) +{ + register unsigned char *cp; + register unsigned char t; + assert(sizeof(uint64)==8); + /* XXX unroll loop some */ + while (n-- > 0) { + cp = (unsigned char *)lp; + t = cp[7]; cp[7] = cp[0]; cp[0] = t; + t = cp[6]; cp[6] = cp[1]; cp[1] = t; + t = cp[5]; cp[5] = cp[2]; cp[2] = t; + t = cp[4]; cp[4] = cp[3]; cp[3] = t; + lp++; + } +} +#endif + +#ifndef TIFFSwabFloat +void +TIFFSwabFloat(float* fp) +{ + register unsigned char* cp = (unsigned char*) fp; + unsigned char t; + assert(sizeof(float)==4); + t = cp[3]; cp[3] = cp[0]; cp[0] = t; + t = cp[2]; cp[2] = cp[1]; cp[1] = t; +} +#endif + +#ifndef TIFFSwabArrayOfFloat +void +TIFFSwabArrayOfFloat(register float* fp, tmsize_t n) +{ + register unsigned char *cp; + register unsigned char t; + assert(sizeof(float)==4); + /* XXX unroll loop some */ + while (n-- > 0) { + cp = (unsigned char *)fp; + t = cp[3]; cp[3] = cp[0]; cp[0] = t; + t = cp[2]; cp[2] = cp[1]; cp[1] = t; + fp++; + } +} +#endif + +#ifndef TIFFSwabDouble +void +TIFFSwabDouble(double *dp) +{ + register unsigned char* cp = (unsigned char*) dp; + unsigned char t; + assert(sizeof(double)==8); + t = cp[7]; cp[7] = cp[0]; cp[0] = t; + t = cp[6]; cp[6] = cp[1]; cp[1] = t; + t = cp[5]; cp[5] = cp[2]; cp[2] = t; + t = cp[4]; cp[4] = cp[3]; cp[3] = t; +} +#endif + +#ifndef TIFFSwabArrayOfDouble +void +TIFFSwabArrayOfDouble(double* dp, tmsize_t n) +{ + register unsigned char *cp; + register unsigned char t; + assert(sizeof(double)==8); + /* XXX unroll loop some */ + while (n-- > 0) { + cp = (unsigned char *)dp; + t = cp[7]; cp[7] = cp[0]; cp[0] = t; + t = cp[6]; cp[6] = cp[1]; cp[1] = t; + t = cp[5]; cp[5] = cp[2]; cp[2] = t; + t = cp[4]; cp[4] = cp[3]; cp[3] = t; + dp++; + } +} +#endif + +/* + * Bit reversal tables. TIFFBitRevTable[] gives + * the bit reversed value of . Used in various + * places in the library when the FillOrder requires + * bit reversal of byte values (e.g. CCITT Fax 3 + * encoding/decoding). TIFFNoBitRevTable is provided + * for algorithms that want an equivalent table that + * do not reverse bit values. + */ +static const unsigned char TIFFBitRevTable[256] = { + 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, + 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, + 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, + 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, + 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, + 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, + 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, + 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, + 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, + 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, + 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, + 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, + 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, + 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, + 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, + 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, + 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, + 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, + 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, + 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, + 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, + 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, + 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, + 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, + 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, + 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, + 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, + 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, + 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, + 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, + 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, + 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff +}; +static const unsigned char TIFFNoBitRevTable[256] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, +}; + +const unsigned char* +TIFFGetBitRevTable(int reversed) +{ + return (reversed ? TIFFBitRevTable : TIFFNoBitRevTable); +} + +void +TIFFReverseBits(uint8* cp, tmsize_t n) +{ + for (; n > 8; n -= 8) { + cp[0] = TIFFBitRevTable[cp[0]]; + cp[1] = TIFFBitRevTable[cp[1]]; + cp[2] = TIFFBitRevTable[cp[2]]; + cp[3] = TIFFBitRevTable[cp[3]]; + cp[4] = TIFFBitRevTable[cp[4]]; + cp[5] = TIFFBitRevTable[cp[5]]; + cp[6] = TIFFBitRevTable[cp[6]]; + cp[7] = TIFFBitRevTable[cp[7]]; + cp += 8; + } + while (n-- > 0) + *cp = TIFFBitRevTable[*cp], cp++; +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_thunder.c b/Source/LibTIFF4/tif_thunder.c index 3d0d6f9..f21c4d5 100644 --- a/Source/LibTIFF4/tif_thunder.c +++ b/Source/LibTIFF4/tif_thunder.c @@ -1,207 +1,207 @@ -/* $Id: tif_thunder.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "tiffiop.h" -#include -#ifdef THUNDER_SUPPORT -/* - * TIFF Library. - * - * ThunderScan 4-bit Compression Algorithm Support - */ - -/* - * ThunderScan uses an encoding scheme designed for - * 4-bit pixel values. Data is encoded in bytes, with - * each byte split into a 2-bit code word and a 6-bit - * data value. The encoding gives raw data, runs of - * pixels, or pixel values encoded as a delta from the - * previous pixel value. For the latter, either 2-bit - * or 3-bit delta values are used, with the deltas packed - * into a single byte. - */ -#define THUNDER_DATA 0x3f /* mask for 6-bit data */ -#define THUNDER_CODE 0xc0 /* mask for 2-bit code word */ -/* code values */ -#define THUNDER_RUN 0x00 /* run of pixels w/ encoded count */ -#define THUNDER_2BITDELTAS 0x40 /* 3 pixels w/ encoded 2-bit deltas */ -#define DELTA2_SKIP 2 /* skip code for 2-bit deltas */ -#define THUNDER_3BITDELTAS 0x80 /* 2 pixels w/ encoded 3-bit deltas */ -#define DELTA3_SKIP 4 /* skip code for 3-bit deltas */ -#define THUNDER_RAW 0xc0 /* raw data encoded */ - -static const int twobitdeltas[4] = { 0, 1, 0, -1 }; -static const int threebitdeltas[8] = { 0, 1, 2, 3, 0, -3, -2, -1 }; - -#define SETPIXEL(op, v) { \ - lastpixel = (v) & 0xf; \ - if ( npixels < maxpixels ) \ - { \ - if (npixels++ & 1) \ - *op++ |= lastpixel; \ - else \ - op[0] = (uint8) (lastpixel << 4); \ - } \ -} - -static int -ThunderSetupDecode(TIFF* tif) -{ - static const char module[] = "ThunderSetupDecode"; - - if( tif->tif_dir.td_bitspersample != 4 ) - { - TIFFErrorExt(tif->tif_clientdata, module, - "Wrong bitspersample value (%d), Thunder decoder only supports 4bits per sample.", - (int) tif->tif_dir.td_bitspersample ); - return 0; - } - - - return (1); -} - -static int -ThunderDecode(TIFF* tif, uint8* op, tmsize_t maxpixels) -{ - static const char module[] = "ThunderDecode"; - register unsigned char *bp; - register tmsize_t cc; - unsigned int lastpixel; - tmsize_t npixels; - - bp = (unsigned char *)tif->tif_rawcp; - cc = tif->tif_rawcc; - lastpixel = 0; - npixels = 0; - while (cc > 0 && npixels < maxpixels) { - int n, delta; - - n = *bp++, cc--; - switch (n & THUNDER_CODE) { - case THUNDER_RUN: /* pixel run */ - /* - * Replicate the last pixel n times, - * where n is the lower-order 6 bits. - */ - if (npixels & 1) { - op[0] |= lastpixel; - lastpixel = *op++; npixels++; n--; - } else - lastpixel |= lastpixel << 4; - npixels += n; - if (npixels < maxpixels) { - for (; n > 0; n -= 2) - *op++ = (uint8) lastpixel; - } - if (n == -1) - *--op &= 0xf0; - lastpixel &= 0xf; - break; - case THUNDER_2BITDELTAS: /* 2-bit deltas */ - if ((delta = ((n >> 4) & 3)) != DELTA2_SKIP) - SETPIXEL(op, lastpixel + twobitdeltas[delta]); - if ((delta = ((n >> 2) & 3)) != DELTA2_SKIP) - SETPIXEL(op, lastpixel + twobitdeltas[delta]); - if ((delta = (n & 3)) != DELTA2_SKIP) - SETPIXEL(op, lastpixel + twobitdeltas[delta]); - break; - case THUNDER_3BITDELTAS: /* 3-bit deltas */ - if ((delta = ((n >> 3) & 7)) != DELTA3_SKIP) - SETPIXEL(op, lastpixel + threebitdeltas[delta]); - if ((delta = (n & 7)) != DELTA3_SKIP) - SETPIXEL(op, lastpixel + threebitdeltas[delta]); - break; - case THUNDER_RAW: /* raw data */ - SETPIXEL(op, n); - break; - } - } - tif->tif_rawcp = (uint8*) bp; - tif->tif_rawcc = cc; - if (npixels != maxpixels) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "%s data at scanline %lu (%I64u != %I64u)", - npixels < maxpixels ? "Not enough" : "Too much", - (unsigned long) tif->tif_row, - (unsigned __int64) npixels, - (unsigned __int64) maxpixels); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "%s data at scanline %lu (%llu != %llu)", - npixels < maxpixels ? "Not enough" : "Too much", - (unsigned long) tif->tif_row, - (unsigned long long) npixels, - (unsigned long long) maxpixels); -#endif - return (0); - } - - return (1); -} - -static int -ThunderDecodeRow(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) -{ - static const char module[] = "ThunderDecodeRow"; - uint8* row = buf; - - (void) s; - if (occ % tif->tif_scanlinesize) - { - TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read"); - return (0); - } - while (occ > 0) { - if (!ThunderDecode(tif, row, tif->tif_dir.td_imagewidth)) - return (0); - occ -= tif->tif_scanlinesize; - row += tif->tif_scanlinesize; - } - return (1); -} - -int -TIFFInitThunderScan(TIFF* tif, int scheme) -{ - (void) scheme; - - tif->tif_setupdecode = ThunderSetupDecode; - tif->tif_decoderow = ThunderDecodeRow; - tif->tif_decodestrip = ThunderDecodeRow; - return (1); -} -#endif /* THUNDER_SUPPORT */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_thunder.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include "tiffiop.h" +#include +#ifdef THUNDER_SUPPORT +/* + * TIFF Library. + * + * ThunderScan 4-bit Compression Algorithm Support + */ + +/* + * ThunderScan uses an encoding scheme designed for + * 4-bit pixel values. Data is encoded in bytes, with + * each byte split into a 2-bit code word and a 6-bit + * data value. The encoding gives raw data, runs of + * pixels, or pixel values encoded as a delta from the + * previous pixel value. For the latter, either 2-bit + * or 3-bit delta values are used, with the deltas packed + * into a single byte. + */ +#define THUNDER_DATA 0x3f /* mask for 6-bit data */ +#define THUNDER_CODE 0xc0 /* mask for 2-bit code word */ +/* code values */ +#define THUNDER_RUN 0x00 /* run of pixels w/ encoded count */ +#define THUNDER_2BITDELTAS 0x40 /* 3 pixels w/ encoded 2-bit deltas */ +#define DELTA2_SKIP 2 /* skip code for 2-bit deltas */ +#define THUNDER_3BITDELTAS 0x80 /* 2 pixels w/ encoded 3-bit deltas */ +#define DELTA3_SKIP 4 /* skip code for 3-bit deltas */ +#define THUNDER_RAW 0xc0 /* raw data encoded */ + +static const int twobitdeltas[4] = { 0, 1, 0, -1 }; +static const int threebitdeltas[8] = { 0, 1, 2, 3, 0, -3, -2, -1 }; + +#define SETPIXEL(op, v) { \ + lastpixel = (v) & 0xf; \ + if ( npixels < maxpixels ) \ + { \ + if (npixels++ & 1) \ + *op++ |= lastpixel; \ + else \ + op[0] = (uint8) (lastpixel << 4); \ + } \ +} + +static int +ThunderSetupDecode(TIFF* tif) +{ + static const char module[] = "ThunderSetupDecode"; + + if( tif->tif_dir.td_bitspersample != 4 ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Wrong bitspersample value (%d), Thunder decoder only supports 4bits per sample.", + (int) tif->tif_dir.td_bitspersample ); + return 0; + } + + + return (1); +} + +static int +ThunderDecode(TIFF* tif, uint8* op, tmsize_t maxpixels) +{ + static const char module[] = "ThunderDecode"; + register unsigned char *bp; + register tmsize_t cc; + unsigned int lastpixel; + tmsize_t npixels; + + bp = (unsigned char *)tif->tif_rawcp; + cc = tif->tif_rawcc; + lastpixel = 0; + npixels = 0; + while (cc > 0 && npixels < maxpixels) { + int n, delta; + + n = *bp++, cc--; + switch (n & THUNDER_CODE) { + case THUNDER_RUN: /* pixel run */ + /* + * Replicate the last pixel n times, + * where n is the lower-order 6 bits. + */ + if (npixels & 1) { + op[0] |= lastpixel; + lastpixel = *op++; npixels++; n--; + } else + lastpixel |= lastpixel << 4; + npixels += n; + if (npixels < maxpixels) { + for (; n > 0; n -= 2) + *op++ = (uint8) lastpixel; + } + if (n == -1) + *--op &= 0xf0; + lastpixel &= 0xf; + break; + case THUNDER_2BITDELTAS: /* 2-bit deltas */ + if ((delta = ((n >> 4) & 3)) != DELTA2_SKIP) + SETPIXEL(op, lastpixel + twobitdeltas[delta]); + if ((delta = ((n >> 2) & 3)) != DELTA2_SKIP) + SETPIXEL(op, lastpixel + twobitdeltas[delta]); + if ((delta = (n & 3)) != DELTA2_SKIP) + SETPIXEL(op, lastpixel + twobitdeltas[delta]); + break; + case THUNDER_3BITDELTAS: /* 3-bit deltas */ + if ((delta = ((n >> 3) & 7)) != DELTA3_SKIP) + SETPIXEL(op, lastpixel + threebitdeltas[delta]); + if ((delta = (n & 7)) != DELTA3_SKIP) + SETPIXEL(op, lastpixel + threebitdeltas[delta]); + break; + case THUNDER_RAW: /* raw data */ + SETPIXEL(op, n); + break; + } + } + tif->tif_rawcp = (uint8*) bp; + tif->tif_rawcc = cc; + if (npixels != maxpixels) { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFErrorExt(tif->tif_clientdata, module, + "%s data at scanline %lu (%I64u != %I64u)", + npixels < maxpixels ? "Not enough" : "Too much", + (unsigned long) tif->tif_row, + (unsigned __int64) npixels, + (unsigned __int64) maxpixels); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "%s data at scanline %lu (%llu != %llu)", + npixels < maxpixels ? "Not enough" : "Too much", + (unsigned long) tif->tif_row, + (unsigned long long) npixels, + (unsigned long long) maxpixels); +#endif + return (0); + } + + return (1); +} + +static int +ThunderDecodeRow(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) +{ + static const char module[] = "ThunderDecodeRow"; + uint8* row = buf; + + (void) s; + if (occ % tif->tif_scanlinesize) + { + TIFFErrorExt(tif->tif_clientdata, module, "Fractional scanlines cannot be read"); + return (0); + } + while (occ > 0) { + if (!ThunderDecode(tif, row, tif->tif_dir.td_imagewidth)) + return (0); + occ -= tif->tif_scanlinesize; + row += tif->tif_scanlinesize; + } + return (1); +} + +int +TIFFInitThunderScan(TIFF* tif, int scheme) +{ + (void) scheme; + + tif->tif_setupdecode = ThunderSetupDecode; + tif->tif_decoderow = ThunderDecodeRow; + tif->tif_decodestrip = ThunderDecodeRow; + return (1); +} +#endif /* THUNDER_SUPPORT */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_tile.c b/Source/LibTIFF4/tif_tile.c index 18f0a71..f97d71f 100644 --- a/Source/LibTIFF4/tif_tile.c +++ b/Source/LibTIFF4/tif_tile.c @@ -1,299 +1,299 @@ -/* $Id: tif_tile.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1991-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * - * Tiled Image Support Routines. - */ -#include "tiffiop.h" - -/* - * Compute which tile an (x,y,z,s) value is in. - */ -uint32 -TIFFComputeTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s) -{ - TIFFDirectory *td = &tif->tif_dir; - uint32 dx = td->td_tilewidth; - uint32 dy = td->td_tilelength; - uint32 dz = td->td_tiledepth; - uint32 tile = 1; - - if (td->td_imagedepth == 1) - z = 0; - if (dx == (uint32) -1) - dx = td->td_imagewidth; - if (dy == (uint32) -1) - dy = td->td_imagelength; - if (dz == (uint32) -1) - dz = td->td_imagedepth; - if (dx != 0 && dy != 0 && dz != 0) { - uint32 xpt = TIFFhowmany_32(td->td_imagewidth, dx); - uint32 ypt = TIFFhowmany_32(td->td_imagelength, dy); - uint32 zpt = TIFFhowmany_32(td->td_imagedepth, dz); - - if (td->td_planarconfig == PLANARCONFIG_SEPARATE) - tile = (xpt*ypt*zpt)*s + - (xpt*ypt)*(z/dz) + - xpt*(y/dy) + - x/dx; - else - tile = (xpt*ypt)*(z/dz) + xpt*(y/dy) + x/dx; - } - return (tile); -} - -/* - * Check an (x,y,z,s) coordinate - * against the image bounds. - */ -int -TIFFCheckTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s) -{ - TIFFDirectory *td = &tif->tif_dir; - - if (x >= td->td_imagewidth) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "%lu: Col out of range, max %lu", - (unsigned long) x, - (unsigned long) (td->td_imagewidth - 1)); - return (0); - } - if (y >= td->td_imagelength) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "%lu: Row out of range, max %lu", - (unsigned long) y, - (unsigned long) (td->td_imagelength - 1)); - return (0); - } - if (z >= td->td_imagedepth) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "%lu: Depth out of range, max %lu", - (unsigned long) z, - (unsigned long) (td->td_imagedepth - 1)); - return (0); - } - if (td->td_planarconfig == PLANARCONFIG_SEPARATE && - s >= td->td_samplesperpixel) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "%lu: Sample out of range, max %lu", - (unsigned long) s, - (unsigned long) (td->td_samplesperpixel - 1)); - return (0); - } - return (1); -} - -/* - * Compute how many tiles are in an image. - */ -uint32 -TIFFNumberOfTiles(TIFF* tif) -{ - TIFFDirectory *td = &tif->tif_dir; - uint32 dx = td->td_tilewidth; - uint32 dy = td->td_tilelength; - uint32 dz = td->td_tiledepth; - uint32 ntiles; - - if (dx == (uint32) -1) - dx = td->td_imagewidth; - if (dy == (uint32) -1) - dy = td->td_imagelength; - if (dz == (uint32) -1) - dz = td->td_imagedepth; - ntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 : - _TIFFMultiply32(tif, _TIFFMultiply32(tif, TIFFhowmany_32(td->td_imagewidth, dx), - TIFFhowmany_32(td->td_imagelength, dy), - "TIFFNumberOfTiles"), - TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles"); - if (td->td_planarconfig == PLANARCONFIG_SEPARATE) - ntiles = _TIFFMultiply32(tif, ntiles, td->td_samplesperpixel, - "TIFFNumberOfTiles"); - return (ntiles); -} - -/* - * Compute the # bytes in each row of a tile. - */ -uint64 -TIFFTileRowSize64(TIFF* tif) -{ - TIFFDirectory *td = &tif->tif_dir; - uint64 rowsize; - - if (td->td_tilelength == 0 || td->td_tilewidth == 0) - return (0); - rowsize = _TIFFMultiply64(tif, td->td_bitspersample, td->td_tilewidth, - "TIFFTileRowSize"); - if (td->td_planarconfig == PLANARCONFIG_CONTIG) - rowsize = _TIFFMultiply64(tif, rowsize, td->td_samplesperpixel, - "TIFFTileRowSize"); - return (TIFFhowmany8_64(rowsize)); -} -tmsize_t -TIFFTileRowSize(TIFF* tif) -{ - static const char module[] = "TIFFTileRowSize"; - uint64 m; - tmsize_t n; - m=TIFFTileRowSize64(tif); - n=(tmsize_t)m; - if ((uint64)n!=m) - { - TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); - n=0; - } - return(n); -} - -/* - * Compute the # bytes in a variable length, row-aligned tile. - */ -uint64 -TIFFVTileSize64(TIFF* tif, uint32 nrows) -{ - static const char module[] = "TIFFVTileSize64"; - TIFFDirectory *td = &tif->tif_dir; - if (td->td_tilelength == 0 || td->td_tilewidth == 0 || - td->td_tiledepth == 0) - return (0); - if ((td->td_planarconfig==PLANARCONFIG_CONTIG)&& - (td->td_photometric==PHOTOMETRIC_YCBCR)&& - (td->td_samplesperpixel==3)&& - (!isUpSampled(tif))) - { - /* - * Packed YCbCr data contain one Cb+Cr for every - * HorizontalSampling*VerticalSampling Y values. - * Must also roundup width and height when calculating - * since images that are not a multiple of the - * horizontal/vertical subsampling area include - * YCbCr data for the extended image. - */ - uint16 ycbcrsubsampling[2]; - uint16 samplingblock_samples; - uint32 samplingblocks_hor; - uint32 samplingblocks_ver; - uint64 samplingrow_samples; - uint64 samplingrow_size; - TIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0, - ycbcrsubsampling+1); - if ((ycbcrsubsampling[0] != 1 && ycbcrsubsampling[0] != 2 && ycbcrsubsampling[0] != 4) - ||(ycbcrsubsampling[1] != 1 && ycbcrsubsampling[1] != 2 && ycbcrsubsampling[1] != 4)) - { - TIFFErrorExt(tif->tif_clientdata,module, - "Invalid YCbCr subsampling (%dx%d)", - ycbcrsubsampling[0], - ycbcrsubsampling[1] ); - return 0; - } - samplingblock_samples=ycbcrsubsampling[0]*ycbcrsubsampling[1]+2; - samplingblocks_hor=TIFFhowmany_32(td->td_tilewidth,ycbcrsubsampling[0]); - samplingblocks_ver=TIFFhowmany_32(nrows,ycbcrsubsampling[1]); - samplingrow_samples=_TIFFMultiply64(tif,samplingblocks_hor,samplingblock_samples,module); - samplingrow_size=TIFFhowmany8_64(_TIFFMultiply64(tif,samplingrow_samples,td->td_bitspersample,module)); - return(_TIFFMultiply64(tif,samplingrow_size,samplingblocks_ver,module)); - } - else - return(_TIFFMultiply64(tif,nrows,TIFFTileRowSize64(tif),module)); -} -tmsize_t -TIFFVTileSize(TIFF* tif, uint32 nrows) -{ - static const char module[] = "TIFFVTileSize"; - uint64 m; - tmsize_t n; - m=TIFFVTileSize64(tif,nrows); - n=(tmsize_t)m; - if ((uint64)n!=m) - { - TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); - n=0; - } - return(n); -} - -/* - * Compute the # bytes in a row-aligned tile. - */ -uint64 -TIFFTileSize64(TIFF* tif) -{ - return (TIFFVTileSize64(tif, tif->tif_dir.td_tilelength)); -} -tmsize_t -TIFFTileSize(TIFF* tif) -{ - static const char module[] = "TIFFTileSize"; - uint64 m; - tmsize_t n; - m=TIFFTileSize64(tif); - n=(tmsize_t)m; - if ((uint64)n!=m) - { - TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); - n=0; - } - return(n); -} - -/* - * Compute a default tile size based on the image - * characteristics and a requested value. If a - * request is <1 then we choose a size according - * to certain heuristics. - */ -void -TIFFDefaultTileSize(TIFF* tif, uint32* tw, uint32* th) -{ - (*tif->tif_deftilesize)(tif, tw, th); -} - -void -_TIFFDefaultTileSize(TIFF* tif, uint32* tw, uint32* th) -{ - (void) tif; - if (*(int32*) tw < 1) - *tw = 256; - if (*(int32*) th < 1) - *th = 256; - /* roundup to a multiple of 16 per the spec */ - if (*tw & 0xf) - *tw = TIFFroundup_32(*tw, 16); - if (*th & 0xf) - *th = TIFFroundup_32(*th, 16); -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_tile.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1991-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * + * Tiled Image Support Routines. + */ +#include "tiffiop.h" + +/* + * Compute which tile an (x,y,z,s) value is in. + */ +uint32 +TIFFComputeTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s) +{ + TIFFDirectory *td = &tif->tif_dir; + uint32 dx = td->td_tilewidth; + uint32 dy = td->td_tilelength; + uint32 dz = td->td_tiledepth; + uint32 tile = 1; + + if (td->td_imagedepth == 1) + z = 0; + if (dx == (uint32) -1) + dx = td->td_imagewidth; + if (dy == (uint32) -1) + dy = td->td_imagelength; + if (dz == (uint32) -1) + dz = td->td_imagedepth; + if (dx != 0 && dy != 0 && dz != 0) { + uint32 xpt = TIFFhowmany_32(td->td_imagewidth, dx); + uint32 ypt = TIFFhowmany_32(td->td_imagelength, dy); + uint32 zpt = TIFFhowmany_32(td->td_imagedepth, dz); + + if (td->td_planarconfig == PLANARCONFIG_SEPARATE) + tile = (xpt*ypt*zpt)*s + + (xpt*ypt)*(z/dz) + + xpt*(y/dy) + + x/dx; + else + tile = (xpt*ypt)*(z/dz) + xpt*(y/dy) + x/dx; + } + return (tile); +} + +/* + * Check an (x,y,z,s) coordinate + * against the image bounds. + */ +int +TIFFCheckTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s) +{ + TIFFDirectory *td = &tif->tif_dir; + + if (x >= td->td_imagewidth) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "%lu: Col out of range, max %lu", + (unsigned long) x, + (unsigned long) (td->td_imagewidth - 1)); + return (0); + } + if (y >= td->td_imagelength) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "%lu: Row out of range, max %lu", + (unsigned long) y, + (unsigned long) (td->td_imagelength - 1)); + return (0); + } + if (z >= td->td_imagedepth) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "%lu: Depth out of range, max %lu", + (unsigned long) z, + (unsigned long) (td->td_imagedepth - 1)); + return (0); + } + if (td->td_planarconfig == PLANARCONFIG_SEPARATE && + s >= td->td_samplesperpixel) { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "%lu: Sample out of range, max %lu", + (unsigned long) s, + (unsigned long) (td->td_samplesperpixel - 1)); + return (0); + } + return (1); +} + +/* + * Compute how many tiles are in an image. + */ +uint32 +TIFFNumberOfTiles(TIFF* tif) +{ + TIFFDirectory *td = &tif->tif_dir; + uint32 dx = td->td_tilewidth; + uint32 dy = td->td_tilelength; + uint32 dz = td->td_tiledepth; + uint32 ntiles; + + if (dx == (uint32) -1) + dx = td->td_imagewidth; + if (dy == (uint32) -1) + dy = td->td_imagelength; + if (dz == (uint32) -1) + dz = td->td_imagedepth; + ntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 : + _TIFFMultiply32(tif, _TIFFMultiply32(tif, TIFFhowmany_32(td->td_imagewidth, dx), + TIFFhowmany_32(td->td_imagelength, dy), + "TIFFNumberOfTiles"), + TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles"); + if (td->td_planarconfig == PLANARCONFIG_SEPARATE) + ntiles = _TIFFMultiply32(tif, ntiles, td->td_samplesperpixel, + "TIFFNumberOfTiles"); + return (ntiles); +} + +/* + * Compute the # bytes in each row of a tile. + */ +uint64 +TIFFTileRowSize64(TIFF* tif) +{ + TIFFDirectory *td = &tif->tif_dir; + uint64 rowsize; + + if (td->td_tilelength == 0 || td->td_tilewidth == 0) + return (0); + rowsize = _TIFFMultiply64(tif, td->td_bitspersample, td->td_tilewidth, + "TIFFTileRowSize"); + if (td->td_planarconfig == PLANARCONFIG_CONTIG) + rowsize = _TIFFMultiply64(tif, rowsize, td->td_samplesperpixel, + "TIFFTileRowSize"); + return (TIFFhowmany8_64(rowsize)); +} +tmsize_t +TIFFTileRowSize(TIFF* tif) +{ + static const char module[] = "TIFFTileRowSize"; + uint64 m; + tmsize_t n; + m=TIFFTileRowSize64(tif); + n=(tmsize_t)m; + if ((uint64)n!=m) + { + TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); + n=0; + } + return(n); +} + +/* + * Compute the # bytes in a variable length, row-aligned tile. + */ +uint64 +TIFFVTileSize64(TIFF* tif, uint32 nrows) +{ + static const char module[] = "TIFFVTileSize64"; + TIFFDirectory *td = &tif->tif_dir; + if (td->td_tilelength == 0 || td->td_tilewidth == 0 || + td->td_tiledepth == 0) + return (0); + if ((td->td_planarconfig==PLANARCONFIG_CONTIG)&& + (td->td_photometric==PHOTOMETRIC_YCBCR)&& + (td->td_samplesperpixel==3)&& + (!isUpSampled(tif))) + { + /* + * Packed YCbCr data contain one Cb+Cr for every + * HorizontalSampling*VerticalSampling Y values. + * Must also roundup width and height when calculating + * since images that are not a multiple of the + * horizontal/vertical subsampling area include + * YCbCr data for the extended image. + */ + uint16 ycbcrsubsampling[2]; + uint16 samplingblock_samples; + uint32 samplingblocks_hor; + uint32 samplingblocks_ver; + uint64 samplingrow_samples; + uint64 samplingrow_size; + TIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0, + ycbcrsubsampling+1); + if ((ycbcrsubsampling[0] != 1 && ycbcrsubsampling[0] != 2 && ycbcrsubsampling[0] != 4) + ||(ycbcrsubsampling[1] != 1 && ycbcrsubsampling[1] != 2 && ycbcrsubsampling[1] != 4)) + { + TIFFErrorExt(tif->tif_clientdata,module, + "Invalid YCbCr subsampling (%dx%d)", + ycbcrsubsampling[0], + ycbcrsubsampling[1] ); + return 0; + } + samplingblock_samples=ycbcrsubsampling[0]*ycbcrsubsampling[1]+2; + samplingblocks_hor=TIFFhowmany_32(td->td_tilewidth,ycbcrsubsampling[0]); + samplingblocks_ver=TIFFhowmany_32(nrows,ycbcrsubsampling[1]); + samplingrow_samples=_TIFFMultiply64(tif,samplingblocks_hor,samplingblock_samples,module); + samplingrow_size=TIFFhowmany8_64(_TIFFMultiply64(tif,samplingrow_samples,td->td_bitspersample,module)); + return(_TIFFMultiply64(tif,samplingrow_size,samplingblocks_ver,module)); + } + else + return(_TIFFMultiply64(tif,nrows,TIFFTileRowSize64(tif),module)); +} +tmsize_t +TIFFVTileSize(TIFF* tif, uint32 nrows) +{ + static const char module[] = "TIFFVTileSize"; + uint64 m; + tmsize_t n; + m=TIFFVTileSize64(tif,nrows); + n=(tmsize_t)m; + if ((uint64)n!=m) + { + TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); + n=0; + } + return(n); +} + +/* + * Compute the # bytes in a row-aligned tile. + */ +uint64 +TIFFTileSize64(TIFF* tif) +{ + return (TIFFVTileSize64(tif, tif->tif_dir.td_tilelength)); +} +tmsize_t +TIFFTileSize(TIFF* tif) +{ + static const char module[] = "TIFFTileSize"; + uint64 m; + tmsize_t n; + m=TIFFTileSize64(tif); + n=(tmsize_t)m; + if ((uint64)n!=m) + { + TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); + n=0; + } + return(n); +} + +/* + * Compute a default tile size based on the image + * characteristics and a requested value. If a + * request is <1 then we choose a size according + * to certain heuristics. + */ +void +TIFFDefaultTileSize(TIFF* tif, uint32* tw, uint32* th) +{ + (*tif->tif_deftilesize)(tif, tw, th); +} + +void +_TIFFDefaultTileSize(TIFF* tif, uint32* tw, uint32* th) +{ + (void) tif; + if (*(int32*) tw < 1) + *tw = 256; + if (*(int32*) th < 1) + *th = 256; + /* roundup to a multiple of 16 per the spec */ + if (*tw & 0xf) + *tw = TIFFroundup_32(*tw, 16); + if (*th & 0xf) + *th = TIFFroundup_32(*th, 16); +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_unix.c b/Source/LibTIFF4/tif_unix.c index ffe99e2..f7ae3af 100644 --- a/Source/LibTIFF4/tif_unix.c +++ b/Source/LibTIFF4/tif_unix.c @@ -1,322 +1,322 @@ -/* $Id: tif_unix.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library UNIX-specific Routines. These are should also work with the - * Windows Common RunTime Library. - */ - -#include "tif_config.h" - -#ifdef HAVE_SYS_TYPES_H -# include -#endif - -#include - -#include -#include -#include - -#ifdef HAVE_UNISTD_H -# include -#endif - -#ifdef HAVE_FCNTL_H -# include -#endif - -#ifdef HAVE_IO_H -# include -#endif - -#include "tiffiop.h" - -static tmsize_t -_tiffReadProc(thandle_t fd, void* buf, tmsize_t size) -{ - size_t size_io = (size_t) size; - if ((tmsize_t) size_io != size) - { - errno=EINVAL; - return (tmsize_t) -1; - } - return ((tmsize_t) read((int) fd, buf, size_io)); -} - -static tmsize_t -_tiffWriteProc(thandle_t fd, void* buf, tmsize_t size) -{ - size_t size_io = (size_t) size; - if ((tmsize_t) size_io != size) - { - errno=EINVAL; - return (tmsize_t) -1; - } - return ((tmsize_t) write((int) fd, buf, size_io)); -} - -static uint64 -_tiffSeekProc(thandle_t fd, uint64 off, int whence) -{ - off_t off_io = (off_t) off; - if ((uint64) off_io != off) - { - errno=EINVAL; - return (uint64) -1; /* this is really gross */ - } - return((uint64)lseek((int)fd,off_io,whence)); -} - -static int -_tiffCloseProc(thandle_t fd) -{ - return(close((int)fd)); -} - -static uint64 -_tiffSizeProc(thandle_t fd) -{ - struct stat sb; - if (fstat((int)fd,&sb)<0) - return(0); - else - return((uint64)sb.st_size); -} - -#ifdef HAVE_MMAP -#include - -static int -_tiffMapProc(thandle_t fd, void** pbase, toff_t* psize) -{ - uint64 size64 = _tiffSizeProc(fd); - tmsize_t sizem = (tmsize_t)size64; - if ((uint64)sizem==size64) { - *pbase = (void*) - mmap(0, (size_t)sizem, PROT_READ, MAP_SHARED, (int) fd, 0); - if (*pbase != (void*) -1) { - *psize = (tmsize_t)sizem; - return (1); - } - } - return (0); -} - -static void -_tiffUnmapProc(thandle_t fd, void* base, toff_t size) -{ - (void) fd; - (void) munmap(base, (off_t) size); -} -#else /* !HAVE_MMAP */ -static int -_tiffMapProc(thandle_t fd, void** pbase, toff_t* psize) -{ - (void) fd; (void) pbase; (void) psize; - return (0); -} - -static void -_tiffUnmapProc(thandle_t fd, void* base, toff_t size) -{ - (void) fd; (void) base; (void) size; -} -#endif /* !HAVE_MMAP */ - -/* - * Open a TIFF file descriptor for read/writing. - */ -TIFF* -TIFFFdOpen(int fd, const char* name, const char* mode) -{ - TIFF* tif; - - tif = TIFFClientOpen(name, mode, - (thandle_t) fd, - _tiffReadProc, _tiffWriteProc, - _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, - _tiffMapProc, _tiffUnmapProc); - if (tif) - tif->tif_fd = fd; - return (tif); -} - -/* - * Open a TIFF file for read/writing. - */ -TIFF* -TIFFOpen(const char* name, const char* mode) -{ - static const char module[] = "TIFFOpen"; - int m, fd; - TIFF* tif; - - m = _TIFFgetMode(mode, module); - if (m == -1) - return ((TIFF*)0); - -/* for cygwin and mingw */ -#ifdef O_BINARY - m |= O_BINARY; -#endif - - fd = open(name, m, 0666); - if (fd < 0) { - if (errno > 0 && strerror(errno) != NULL ) { - TIFFErrorExt(0, module, "%s: %s", name, strerror(errno) ); - } else { - TIFFErrorExt(0, module, "%s: Cannot open", name); - } - return ((TIFF *)0); - } - - tif = TIFFFdOpen((int)fd, name, mode); - if(!tif) - close(fd); - return tif; -} - -#ifdef __WIN32__ -#include -/* - * Open a TIFF file with a Unicode filename, for read/writing. - */ -TIFF* -TIFFOpenW(const wchar_t* name, const char* mode) -{ - static const char module[] = "TIFFOpenW"; - int m, fd; - int mbsize; - char *mbname; - TIFF* tif; - - m = _TIFFgetMode(mode, module); - if (m == -1) - return ((TIFF*)0); - -/* for cygwin and mingw */ -#ifdef O_BINARY - m |= O_BINARY; -#endif - - fd = _wopen(name, m, 0666); - if (fd < 0) { - TIFFErrorExt(0, module, "%s: Cannot open", name); - return ((TIFF *)0); - } - - mbname = NULL; - mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL); - if (mbsize > 0) { - mbname = _TIFFmalloc(mbsize); - if (!mbname) { - TIFFErrorExt(0, module, - "Can't allocate space for filename conversion buffer"); - return ((TIFF*)0); - } - - WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, - NULL, NULL); - } - - tif = TIFFFdOpen((int)fd, (mbname != NULL) ? mbname : "", - mode); - - _TIFFfree(mbname); - - if(!tif) - close(fd); - return tif; -} -#endif - -void* -_TIFFmalloc(tmsize_t s) -{ - return (malloc((size_t) s)); -} - -void -_TIFFfree(void* p) -{ - free(p); -} - -void* -_TIFFrealloc(void* p, tmsize_t s) -{ - return (realloc(p, (size_t) s)); -} - -void -_TIFFmemset(void* p, int v, tmsize_t c) -{ - memset(p, v, (size_t) c); -} - -void -_TIFFmemcpy(void* d, const void* s, tmsize_t c) -{ - memcpy(d, s, (size_t) c); -} - -int -_TIFFmemcmp(const void* p1, const void* p2, tmsize_t c) -{ - return (memcmp(p1, p2, (size_t) c)); -} - -static void -unixWarningHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - fprintf(stderr, "%s: ", module); - fprintf(stderr, "Warning, "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} -TIFFErrorHandler _TIFFwarningHandler = unixWarningHandler; - -static void -unixErrorHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - fprintf(stderr, "%s: ", module); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} -TIFFErrorHandler _TIFFerrorHandler = unixErrorHandler; - -/* vim: set ts=8 sts=8 sw=8 noet: */ - -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_unix.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library UNIX-specific Routines. These are should also work with the + * Windows Common RunTime Library. + */ + +#include "tif_config.h" + +#ifdef HAVE_SYS_TYPES_H +# include +#endif + +#include + +#include +#include +#include + +#ifdef HAVE_UNISTD_H +# include +#endif + +#ifdef HAVE_FCNTL_H +# include +#endif + +#ifdef HAVE_IO_H +# include +#endif + +#include "tiffiop.h" + +static tmsize_t +_tiffReadProc(thandle_t fd, void* buf, tmsize_t size) +{ + size_t size_io = (size_t) size; + if ((tmsize_t) size_io != size) + { + errno=EINVAL; + return (tmsize_t) -1; + } + return ((tmsize_t) read((int) fd, buf, size_io)); +} + +static tmsize_t +_tiffWriteProc(thandle_t fd, void* buf, tmsize_t size) +{ + size_t size_io = (size_t) size; + if ((tmsize_t) size_io != size) + { + errno=EINVAL; + return (tmsize_t) -1; + } + return ((tmsize_t) write((int) fd, buf, size_io)); +} + +static uint64 +_tiffSeekProc(thandle_t fd, uint64 off, int whence) +{ + off_t off_io = (off_t) off; + if ((uint64) off_io != off) + { + errno=EINVAL; + return (uint64) -1; /* this is really gross */ + } + return((uint64)lseek((int)fd,off_io,whence)); +} + +static int +_tiffCloseProc(thandle_t fd) +{ + return(close((int)fd)); +} + +static uint64 +_tiffSizeProc(thandle_t fd) +{ + struct stat sb; + if (fstat((int)fd,&sb)<0) + return(0); + else + return((uint64)sb.st_size); +} + +#ifdef HAVE_MMAP +#include + +static int +_tiffMapProc(thandle_t fd, void** pbase, toff_t* psize) +{ + uint64 size64 = _tiffSizeProc(fd); + tmsize_t sizem = (tmsize_t)size64; + if ((uint64)sizem==size64) { + *pbase = (void*) + mmap(0, (size_t)sizem, PROT_READ, MAP_SHARED, (int) fd, 0); + if (*pbase != (void*) -1) { + *psize = (tmsize_t)sizem; + return (1); + } + } + return (0); +} + +static void +_tiffUnmapProc(thandle_t fd, void* base, toff_t size) +{ + (void) fd; + (void) munmap(base, (off_t) size); +} +#else /* !HAVE_MMAP */ +static int +_tiffMapProc(thandle_t fd, void** pbase, toff_t* psize) +{ + (void) fd; (void) pbase; (void) psize; + return (0); +} + +static void +_tiffUnmapProc(thandle_t fd, void* base, toff_t size) +{ + (void) fd; (void) base; (void) size; +} +#endif /* !HAVE_MMAP */ + +/* + * Open a TIFF file descriptor for read/writing. + */ +TIFF* +TIFFFdOpen(int fd, const char* name, const char* mode) +{ + TIFF* tif; + + tif = TIFFClientOpen(name, mode, + (thandle_t) fd, + _tiffReadProc, _tiffWriteProc, + _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, + _tiffMapProc, _tiffUnmapProc); + if (tif) + tif->tif_fd = fd; + return (tif); +} + +/* + * Open a TIFF file for read/writing. + */ +TIFF* +TIFFOpen(const char* name, const char* mode) +{ + static const char module[] = "TIFFOpen"; + int m, fd; + TIFF* tif; + + m = _TIFFgetMode(mode, module); + if (m == -1) + return ((TIFF*)0); + +/* for cygwin and mingw */ +#ifdef O_BINARY + m |= O_BINARY; +#endif + + fd = open(name, m, 0666); + if (fd < 0) { + if (errno > 0 && strerror(errno) != NULL ) { + TIFFErrorExt(0, module, "%s: %s", name, strerror(errno) ); + } else { + TIFFErrorExt(0, module, "%s: Cannot open", name); + } + return ((TIFF *)0); + } + + tif = TIFFFdOpen((int)fd, name, mode); + if(!tif) + close(fd); + return tif; +} + +#ifdef __WIN32__ +#include +/* + * Open a TIFF file with a Unicode filename, for read/writing. + */ +TIFF* +TIFFOpenW(const wchar_t* name, const char* mode) +{ + static const char module[] = "TIFFOpenW"; + int m, fd; + int mbsize; + char *mbname; + TIFF* tif; + + m = _TIFFgetMode(mode, module); + if (m == -1) + return ((TIFF*)0); + +/* for cygwin and mingw */ +#ifdef O_BINARY + m |= O_BINARY; +#endif + + fd = _wopen(name, m, 0666); + if (fd < 0) { + TIFFErrorExt(0, module, "%s: Cannot open", name); + return ((TIFF *)0); + } + + mbname = NULL; + mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL); + if (mbsize > 0) { + mbname = _TIFFmalloc(mbsize); + if (!mbname) { + TIFFErrorExt(0, module, + "Can't allocate space for filename conversion buffer"); + return ((TIFF*)0); + } + + WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, + NULL, NULL); + } + + tif = TIFFFdOpen((int)fd, (mbname != NULL) ? mbname : "", + mode); + + _TIFFfree(mbname); + + if(!tif) + close(fd); + return tif; +} +#endif + +void* +_TIFFmalloc(tmsize_t s) +{ + return (malloc((size_t) s)); +} + +void +_TIFFfree(void* p) +{ + free(p); +} + +void* +_TIFFrealloc(void* p, tmsize_t s) +{ + return (realloc(p, (size_t) s)); +} + +void +_TIFFmemset(void* p, int v, tmsize_t c) +{ + memset(p, v, (size_t) c); +} + +void +_TIFFmemcpy(void* d, const void* s, tmsize_t c) +{ + memcpy(d, s, (size_t) c); +} + +int +_TIFFmemcmp(const void* p1, const void* p2, tmsize_t c) +{ + return (memcmp(p1, p2, (size_t) c)); +} + +static void +unixWarningHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + fprintf(stderr, "%s: ", module); + fprintf(stderr, "Warning, "); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} +TIFFErrorHandler _TIFFwarningHandler = unixWarningHandler; + +static void +unixErrorHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + fprintf(stderr, "%s: ", module); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} +TIFFErrorHandler _TIFFerrorHandler = unixErrorHandler; + +/* vim: set ts=8 sts=8 sw=8 noet: */ + +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_version.c b/Source/LibTIFF4/tif_version.c index 1019e1a..88eb814 100644 --- a/Source/LibTIFF4/tif_version.c +++ b/Source/LibTIFF4/tif_version.c @@ -1,40 +1,40 @@ -/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF4/tif_version.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ -/* - * Copyright (c) 1992-1997 Sam Leffler - * Copyright (c) 1992-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ -#include "tiffiop.h" - -static const char TIFFVersion[] = TIFFLIB_VERSION_STR; - -const char* -TIFFGetVersion(void) -{ - return (TIFFVersion); -} -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF4/tif_version.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ +/* + * Copyright (c) 1992-1997 Sam Leffler + * Copyright (c) 1992-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ +#include "tiffiop.h" + +static const char TIFFVersion[] = TIFFLIB_VERSION_STR; + +const char* +TIFFGetVersion(void) +{ + return (TIFFVersion); +} +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_vms.c b/Source/LibTIFF4/tif_vms.c index 30a1345..338bfeb 100644 --- a/Source/LibTIFF4/tif_vms.c +++ b/Source/LibTIFF4/tif_vms.c @@ -1,600 +1,600 @@ -/* $Id: tif_vms.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library VMS-specific Routines. - */ - -#include -#include -#include "tiffiop.h" -#if !HAVE_IEEEFP -#include -#endif - -#ifdef VAXC -#define NOSHARE noshare -#else -#define NOSHARE -#endif - -COMPILATION SHOULD FAIL -This file is not yet updated to reflect changes in LibTiff 4.0. If you have -the opportunity to update and test this file, please contact LibTiff folks -for all assistance you may require and contribute the results - -#ifdef __alpha -/* Dummy entry point for backwards compatibility */ -void TIFFModeCCITTFax3(void){} -#endif - -static tsize_t -_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - return (read((int) fd, buf, size)); -} - -static tsize_t -_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) -{ - return (write((int) fd, buf, size)); -} - -static toff_t -_tiffSeekProc(thandle_t fd, toff_t off, int whence) -{ - return ((toff_t) lseek((int) fd, (off_t) off, whence)); -} - -static int -_tiffCloseProc(thandle_t fd) -{ - return (close((int) fd)); -} - -#include - -static toff_t -_tiffSizeProc(thandle_t fd) -{ - struct stat sb; - return (toff_t) (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size); -} - -#ifdef HAVE_MMAP -#include -#include -#include - -/* - * Table for storing information on current open sections. - * (Should really be a linked list) - */ -#define MAX_MAPPED 100 -static int no_mapped = 0; -static struct { - char *base; - char *top; - unsigned short channel; -} map_table[MAX_MAPPED]; - -/* - * This routine maps a file into a private section. Note that this - * method of accessing a file is by far the fastest under VMS. - * The routine may fail (i.e. return 0) for several reasons, for - * example: - * - There is no more room for storing the info on sections. - * - The process is out of open file quota, channels, ... - * - fd does not describe an opened file. - * - The file is already opened for write access by this process - * or another process - * - There is no free "hole" in virtual memory that fits the - * size of the file - */ -static int -_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) -{ - char name[256]; - struct FAB fab; - unsigned short channel; - char *inadr[2], *retadr[2]; - unsigned long status; - long size; - - if (no_mapped >= MAX_MAPPED) - return(0); - /* - * We cannot use a file descriptor, we - * must open the file once more. - */ - if (getname((int)fd, name, 1) == NULL) - return(0); - /* prepare the FAB for a user file open */ - fab = cc$rms_fab; - fab.fab$l_fop |= FAB$V_UFO; - fab.fab$b_fac = FAB$M_GET; - fab.fab$b_shr = FAB$M_SHRGET; - fab.fab$l_fna = name; - fab.fab$b_fns = strlen(name); - status = sys$open(&fab); /* open file & get channel number */ - if ((status&1) == 0) - return(0); - channel = (unsigned short)fab.fab$l_stv; - inadr[0] = inadr[1] = (char *)0; /* just an address in P0 space */ - /* - * Map the blocks of the file up to - * the EOF block into virtual memory. - */ - size = _tiffSizeProc(fd); - status = sys$crmpsc(inadr, retadr, 0, SEC$M_EXPREG, 0,0,0, channel, - TIFFhowmany(size,512), 0,0,0); ddd - if ((status&1) == 0){ - sys$dassgn(channel); - return(0); - } - *pbase = (tdata_t) retadr[0]; /* starting virtual address */ - /* - * Use the size of the file up to the - * EOF mark for UNIX compatibility. - */ - *psize = (toff_t) size; - /* Record the section in the table */ - map_table[no_mapped].base = retadr[0]; - map_table[no_mapped].top = retadr[1]; - map_table[no_mapped].channel = channel; - no_mapped++; - - return(1); -} - -/* - * This routine unmaps a section from the virtual address space of - * the process, but only if the base was the one returned from a - * call to TIFFMapFileContents. - */ -static void -_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) -{ - char *inadr[2]; - int i, j; - - /* Find the section in the table */ - for (i = 0;i < no_mapped; i++) { - if (map_table[i].base == (char *) base) { - /* Unmap the section */ - inadr[0] = (char *) base; - inadr[1] = map_table[i].top; - sys$deltva(inadr, 0, 0); - sys$dassgn(map_table[i].channel); - /* Remove this section from the list */ - for (j = i+1; j < no_mapped; j++) - map_table[j-1] = map_table[j]; - no_mapped--; - return; - } - } -} -#else /* !HAVE_MMAP */ -static int -_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) -{ - return (0); -} - -static void -_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) -{ -} -#endif /* !HAVE_MMAP */ - -/* - * Open a TIFF file descriptor for read/writing. - */ -TIFF* -TIFFFdOpen(int fd, const char* name, const char* mode) -{ - TIFF* tif; - - tif = TIFFClientOpen(name, mode, ddd - (thandle_t) fd, - _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, - _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); - if (tif) - tif->tif_fd = fd; - return (tif); -} - -/* - * Open a TIFF file for read/writing. - */ -TIFF* -TIFFOpen(const char* name, const char* mode) -{ - static const char module[] = "TIFFOpen"; - int m, fd; - - m = _TIFFgetMode(mode, module); - if (m == -1) - return ((TIFF*)0); - if (m&O_TRUNC){ - /* - * There is a bug in open in VAXC. If you use - * open w/ m=O_RDWR|O_CREAT|O_TRUNC the - * wrong thing happens. On the other hand - * creat does the right thing. - */ - fd = creat((char *) /* bug in stdio.h */ name, 0666, - "alq = 128", "deq = 64", "mbc = 32", - "fop = tef"); - } else if (m&O_RDWR) { - fd = open(name, m, 0666, - "deq = 64", "mbc = 32", "fop = tef", "ctx = stm"); - } else - fd = open(name, m, 0666, "mbc = 32", "ctx = stm"); - if (fd < 0) { - TIFFErrorExt(0, module, "%s: Cannot open", name); - return ((TIFF*)0); - } - return (TIFFFdOpen(fd, name, mode)); -} - -tdata_t -_TIFFmalloc(tsize_t s) -{ - return (malloc((size_t) s)); -} - -void -_TIFFfree(tdata_t p) -{ - free(p); -} - -tdata_t -_TIFFrealloc(tdata_t p, tsize_t s) -{ - return (realloc(p, (size_t) s)); -} - -void -_TIFFmemset(tdata_t p, int v, tsize_t c) -{ - memset(p, v, (size_t) c); -} - -void -_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) -{ - memcpy(d, s, (size_t) c); -} - -int -_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) -{ - return (memcmp(p1, p2, (size_t) c)); -} - -/* - * On the VAX, we need to make those global, writable pointers - * non-shareable, otherwise they would be made shareable by default. - * On the AXP, this brain damage has been corrected. - * - * I (Karsten Spang, krs@kampsax.dk) have dug around in the GCC - * manual and the GAS code and have come up with the following - * construct, but I don't have GCC on my VAX, so it is untested. - * Please tell me if it does not work. - */ - -static void -vmsWarningHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - fprintf(stderr, "%s: ", module); - fprintf(stderr, "Warning, "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} - -NOSHARE TIFFErrorHandler _TIFFwarningHandler = vmsWarningHandler -#if defined(VAX) && defined(__GNUC__) -asm("_$$PsectAttributes_NOSHR$$_TIFFwarningHandler") -#endif -; - -static void -vmsErrorHandler(const char* module, const char* fmt, va_list ap) -{ - if (module != NULL) - fprintf(stderr, "%s: ", module); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -} - -NOSHARE TIFFErrorHandler _TIFFerrorHandler = vmsErrorHandler -#if defined(VAX) && defined(__GNUC__) -asm("_$$PsectAttributes_NOSHR$$_TIFFerrorHandler") -#endif -; - - -#if !HAVE_IEEEFP -/* IEEE floting point handling */ - -typedef struct ieeedouble { - unsigned long mant2; /* fix NDR: full 8-byte swap */ - unsigned long mant : 20, - exp : 11, - sign : 1; -} ieeedouble; -typedef struct ieeefloat { - unsigned long mant : 23, - exp : 8, - sign : 1; -} ieeefloat; - -/* - * NB: These are D_FLOAT's, not G_FLOAT's. A G_FLOAT is - * simply a reverse-IEEE float/double. - */ - -typedef struct { - unsigned long mant1 : 7, - exp : 8, - sign : 1, - mant2 : 16, - mant3 : 16, - mant4 : 16; -} nativedouble; -typedef struct { - unsigned long mant1 : 7, - exp : 8, - sign : 1, - mant2 : 16; -} nativefloat; - -typedef union { - ieeedouble ieee; - nativedouble native; - char b[8]; - uint32 l[2]; - double d; -} double_t; - -typedef union { - ieeefloat ieee; - nativefloat native; - char b[4]; - uint32 l; - float f; -} float_t; - -#if defined(VAXC) || defined(DECC) -#pragma inline(ieeetod,dtoieee) -#endif - -/* - * Convert an IEEE double precision number to native double precision. - * The source is contained in two longwords, the second holding the sign, - * exponent and the higher order bits of the mantissa, and the first - * holding the rest of the mantissa as follows: - * (Note: It is assumed that the number has been eight-byte swapped to - * LSB first.) - * - * First longword: - * 32 least significant bits of mantissa - * Second longword: - * 0-19: 20 most significant bits of mantissa - * 20-30: exponent - * 31: sign - * The exponent is stored as excess 1023. - * The most significant bit of the mantissa is implied 1, and not stored. - * If the exponent and mantissa are zero, the number is zero. - * If the exponent is 0 (i.e. -1023) and the mantissa is non-zero, it is an - * unnormalized number with the most significant bit NOT implied. - * If the exponent is 2047, the number is invalid, in case the mantissa is zero, - * this means overflow (+/- depending of the sign bit), otherwise - * it simply means invalid number. - * - * If the number is too large for the machine or was specified as overflow, - * +/-HUGE_VAL is returned. - */ -INLINE static void -ieeetod(double *dp) -{ - double_t source; - long sign,exp,mant; - double dmant; - - source.ieee = ((double_t*)dp)->ieee; - sign = source.ieee.sign; - exp = source.ieee.exp; - mant = source.ieee.mant; - - if (exp == 2047) { - if (mant) /* Not a Number (NAN) */ - *dp = HUGE_VAL; - else /* +/- infinity */ - *dp = (sign ? -HUGE_VAL : HUGE_VAL); - return; - } - if (!exp) { - if (!(mant || source.ieee.mant2)) { /* zero */ - *dp=0; - return; - } else { /* Unnormalized number */ - /* NB: not -1023, the 1 bit is not implied */ - exp= -1022; - } - } else { - mant |= 1<<20; - exp -= 1023; - } - dmant = (((double) mant) + - ((double) source.ieee.mant2) / (((double) (1<<16)) * - ((double) (1<<16)))) / (double) (1<<20); - dmant = ldexp(dmant, exp); - if (sign) - dmant= -dmant; - *dp = dmant; -} - -INLINE static void -dtoieee(double *dp) -{ - double_t num; - double x; - int exp; - - num.d = *dp; - if (!num.d) { /* Zero is just binary all zeros */ - num.l[0] = num.l[1] = 0; - return; - } - - if (num.d < 0) { /* Sign is encoded separately */ - num.d = -num.d; - num.ieee.sign = 1; - } else { - num.ieee.sign = 0; - } - - /* Now separate the absolute value into mantissa and exponent */ - x = frexp(num.d, &exp); - - /* - * Handle cases where the value is outside the - * range for IEEE floating point numbers. - * (Overflow cannot happen on a VAX, but underflow - * can happen for G float.) - */ - if (exp < -1022) { /* Unnormalized number */ - x = ldexp(x, -1023-exp); - exp = 0; - } else if (exp > 1023) { /* +/- infinity */ - x = 0; - exp = 2047; - } else { /* Get rid of most significant bit */ - x *= 2; - x -= 1; - exp += 1022; /* fix NDR: 1.0 -> x=0.5, exp=1 -> ieee.exp = 1023 */ - } - num.ieee.exp = exp; - - x *= (double) (1<<20); - num.ieee.mant = (long) x; - x -= (double) num.ieee.mant; - num.ieee.mant2 = (long) (x*((double) (1<<16)*(double) (1<<16))); - - if (!(num.ieee.mant || num.ieee.exp || num.ieee.mant2)) { - /* Avoid negative zero */ - num.ieee.sign = 0; - } - ((double_t*)dp)->ieee = num.ieee; -} - -/* - * Beware, these do not handle over/under-flow - * during conversion from ieee to native format. - */ -#define NATIVE2IEEEFLOAT(fp) { \ - float_t t; \ - if (t.ieee.exp = (fp)->native.exp) \ - t.ieee.exp += -129 + 127; \ - t.ieee.sign = (fp)->native.sign; \ - t.ieee.mant = ((fp)->native.mant1<<16)|(fp)->native.mant2; \ - *(fp) = t; \ -} -#define IEEEFLOAT2NATIVE(fp) { \ - float_t t; int v = (fp)->ieee.exp; \ - if (v) v += -127 + 129; /* alter bias of exponent */\ - t.native.exp = v; /* implicit truncation of exponent */\ - t.native.sign = (fp)->ieee.sign; \ - v = (fp)->ieee.mant; \ - t.native.mant1 = v >> 16; \ - t.native.mant2 = v;\ - *(fp) = t; \ -} - -#define IEEEDOUBLE2NATIVE(dp) ieeetod(dp) - -#define NATIVE2IEEEDOUBLE(dp) dtoieee(dp) - - -/* - * These unions are used during floating point - * conversions. The above macros define the - * conversion operations. - */ -void -TIFFCvtIEEEFloatToNative(TIFF* tif, u_int n, float* f) -{ - float_t* fp = (float_t*) f; - - while (n-- > 0) { - IEEEFLOAT2NATIVE(fp); - fp++; - } -} - -void -TIFFCvtNativeToIEEEFloat(TIFF* tif, u_int n, float* f) -{ - float_t* fp = (float_t*) f; - - while (n-- > 0) { - NATIVE2IEEEFLOAT(fp); - fp++; - } -} -void -TIFFCvtIEEEDoubleToNative(TIFF* tif, u_int n, double* f) -{ - double_t* fp = (double_t*) f; - - while (n-- > 0) { - IEEEDOUBLE2NATIVE(fp); - fp++; - } -} - -void -TIFFCvtNativeToIEEEDouble(TIFF* tif, u_int n, double* f) -{ - double_t* fp = (double_t*) f; - - while (n-- > 0) { - NATIVE2IEEEDOUBLE(fp); - fp++; - } -} -#endif -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_vms.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library VMS-specific Routines. + */ + +#include +#include +#include "tiffiop.h" +#if !HAVE_IEEEFP +#include +#endif + +#ifdef VAXC +#define NOSHARE noshare +#else +#define NOSHARE +#endif + +COMPILATION SHOULD FAIL +This file is not yet updated to reflect changes in LibTiff 4.0. If you have +the opportunity to update and test this file, please contact LibTiff folks +for all assistance you may require and contribute the results + +#ifdef __alpha +/* Dummy entry point for backwards compatibility */ +void TIFFModeCCITTFax3(void){} +#endif + +static tsize_t +_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + return (read((int) fd, buf, size)); +} + +static tsize_t +_tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) +{ + return (write((int) fd, buf, size)); +} + +static toff_t +_tiffSeekProc(thandle_t fd, toff_t off, int whence) +{ + return ((toff_t) lseek((int) fd, (off_t) off, whence)); +} + +static int +_tiffCloseProc(thandle_t fd) +{ + return (close((int) fd)); +} + +#include + +static toff_t +_tiffSizeProc(thandle_t fd) +{ + struct stat sb; + return (toff_t) (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size); +} + +#ifdef HAVE_MMAP +#include +#include +#include + +/* + * Table for storing information on current open sections. + * (Should really be a linked list) + */ +#define MAX_MAPPED 100 +static int no_mapped = 0; +static struct { + char *base; + char *top; + unsigned short channel; +} map_table[MAX_MAPPED]; + +/* + * This routine maps a file into a private section. Note that this + * method of accessing a file is by far the fastest under VMS. + * The routine may fail (i.e. return 0) for several reasons, for + * example: + * - There is no more room for storing the info on sections. + * - The process is out of open file quota, channels, ... + * - fd does not describe an opened file. + * - The file is already opened for write access by this process + * or another process + * - There is no free "hole" in virtual memory that fits the + * size of the file + */ +static int +_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) +{ + char name[256]; + struct FAB fab; + unsigned short channel; + char *inadr[2], *retadr[2]; + unsigned long status; + long size; + + if (no_mapped >= MAX_MAPPED) + return(0); + /* + * We cannot use a file descriptor, we + * must open the file once more. + */ + if (getname((int)fd, name, 1) == NULL) + return(0); + /* prepare the FAB for a user file open */ + fab = cc$rms_fab; + fab.fab$l_fop |= FAB$V_UFO; + fab.fab$b_fac = FAB$M_GET; + fab.fab$b_shr = FAB$M_SHRGET; + fab.fab$l_fna = name; + fab.fab$b_fns = strlen(name); + status = sys$open(&fab); /* open file & get channel number */ + if ((status&1) == 0) + return(0); + channel = (unsigned short)fab.fab$l_stv; + inadr[0] = inadr[1] = (char *)0; /* just an address in P0 space */ + /* + * Map the blocks of the file up to + * the EOF block into virtual memory. + */ + size = _tiffSizeProc(fd); + status = sys$crmpsc(inadr, retadr, 0, SEC$M_EXPREG, 0,0,0, channel, + TIFFhowmany(size,512), 0,0,0); ddd + if ((status&1) == 0){ + sys$dassgn(channel); + return(0); + } + *pbase = (tdata_t) retadr[0]; /* starting virtual address */ + /* + * Use the size of the file up to the + * EOF mark for UNIX compatibility. + */ + *psize = (toff_t) size; + /* Record the section in the table */ + map_table[no_mapped].base = retadr[0]; + map_table[no_mapped].top = retadr[1]; + map_table[no_mapped].channel = channel; + no_mapped++; + + return(1); +} + +/* + * This routine unmaps a section from the virtual address space of + * the process, but only if the base was the one returned from a + * call to TIFFMapFileContents. + */ +static void +_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) +{ + char *inadr[2]; + int i, j; + + /* Find the section in the table */ + for (i = 0;i < no_mapped; i++) { + if (map_table[i].base == (char *) base) { + /* Unmap the section */ + inadr[0] = (char *) base; + inadr[1] = map_table[i].top; + sys$deltva(inadr, 0, 0); + sys$dassgn(map_table[i].channel); + /* Remove this section from the list */ + for (j = i+1; j < no_mapped; j++) + map_table[j-1] = map_table[j]; + no_mapped--; + return; + } + } +} +#else /* !HAVE_MMAP */ +static int +_tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) +{ + return (0); +} + +static void +_tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) +{ +} +#endif /* !HAVE_MMAP */ + +/* + * Open a TIFF file descriptor for read/writing. + */ +TIFF* +TIFFFdOpen(int fd, const char* name, const char* mode) +{ + TIFF* tif; + + tif = TIFFClientOpen(name, mode, ddd + (thandle_t) fd, + _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, + _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); + if (tif) + tif->tif_fd = fd; + return (tif); +} + +/* + * Open a TIFF file for read/writing. + */ +TIFF* +TIFFOpen(const char* name, const char* mode) +{ + static const char module[] = "TIFFOpen"; + int m, fd; + + m = _TIFFgetMode(mode, module); + if (m == -1) + return ((TIFF*)0); + if (m&O_TRUNC){ + /* + * There is a bug in open in VAXC. If you use + * open w/ m=O_RDWR|O_CREAT|O_TRUNC the + * wrong thing happens. On the other hand + * creat does the right thing. + */ + fd = creat((char *) /* bug in stdio.h */ name, 0666, + "alq = 128", "deq = 64", "mbc = 32", + "fop = tef"); + } else if (m&O_RDWR) { + fd = open(name, m, 0666, + "deq = 64", "mbc = 32", "fop = tef", "ctx = stm"); + } else + fd = open(name, m, 0666, "mbc = 32", "ctx = stm"); + if (fd < 0) { + TIFFErrorExt(0, module, "%s: Cannot open", name); + return ((TIFF*)0); + } + return (TIFFFdOpen(fd, name, mode)); +} + +tdata_t +_TIFFmalloc(tsize_t s) +{ + return (malloc((size_t) s)); +} + +void +_TIFFfree(tdata_t p) +{ + free(p); +} + +tdata_t +_TIFFrealloc(tdata_t p, tsize_t s) +{ + return (realloc(p, (size_t) s)); +} + +void +_TIFFmemset(tdata_t p, int v, tsize_t c) +{ + memset(p, v, (size_t) c); +} + +void +_TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) +{ + memcpy(d, s, (size_t) c); +} + +int +_TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) +{ + return (memcmp(p1, p2, (size_t) c)); +} + +/* + * On the VAX, we need to make those global, writable pointers + * non-shareable, otherwise they would be made shareable by default. + * On the AXP, this brain damage has been corrected. + * + * I (Karsten Spang, krs@kampsax.dk) have dug around in the GCC + * manual and the GAS code and have come up with the following + * construct, but I don't have GCC on my VAX, so it is untested. + * Please tell me if it does not work. + */ + +static void +vmsWarningHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + fprintf(stderr, "%s: ", module); + fprintf(stderr, "Warning, "); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} + +NOSHARE TIFFErrorHandler _TIFFwarningHandler = vmsWarningHandler +#if defined(VAX) && defined(__GNUC__) +asm("_$$PsectAttributes_NOSHR$$_TIFFwarningHandler") +#endif +; + +static void +vmsErrorHandler(const char* module, const char* fmt, va_list ap) +{ + if (module != NULL) + fprintf(stderr, "%s: ", module); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +} + +NOSHARE TIFFErrorHandler _TIFFerrorHandler = vmsErrorHandler +#if defined(VAX) && defined(__GNUC__) +asm("_$$PsectAttributes_NOSHR$$_TIFFerrorHandler") +#endif +; + + +#if !HAVE_IEEEFP +/* IEEE floting point handling */ + +typedef struct ieeedouble { + unsigned long mant2; /* fix NDR: full 8-byte swap */ + unsigned long mant : 20, + exp : 11, + sign : 1; +} ieeedouble; +typedef struct ieeefloat { + unsigned long mant : 23, + exp : 8, + sign : 1; +} ieeefloat; + +/* + * NB: These are D_FLOAT's, not G_FLOAT's. A G_FLOAT is + * simply a reverse-IEEE float/double. + */ + +typedef struct { + unsigned long mant1 : 7, + exp : 8, + sign : 1, + mant2 : 16, + mant3 : 16, + mant4 : 16; +} nativedouble; +typedef struct { + unsigned long mant1 : 7, + exp : 8, + sign : 1, + mant2 : 16; +} nativefloat; + +typedef union { + ieeedouble ieee; + nativedouble native; + char b[8]; + uint32 l[2]; + double d; +} double_t; + +typedef union { + ieeefloat ieee; + nativefloat native; + char b[4]; + uint32 l; + float f; +} float_t; + +#if defined(VAXC) || defined(DECC) +#pragma inline(ieeetod,dtoieee) +#endif + +/* + * Convert an IEEE double precision number to native double precision. + * The source is contained in two longwords, the second holding the sign, + * exponent and the higher order bits of the mantissa, and the first + * holding the rest of the mantissa as follows: + * (Note: It is assumed that the number has been eight-byte swapped to + * LSB first.) + * + * First longword: + * 32 least significant bits of mantissa + * Second longword: + * 0-19: 20 most significant bits of mantissa + * 20-30: exponent + * 31: sign + * The exponent is stored as excess 1023. + * The most significant bit of the mantissa is implied 1, and not stored. + * If the exponent and mantissa are zero, the number is zero. + * If the exponent is 0 (i.e. -1023) and the mantissa is non-zero, it is an + * unnormalized number with the most significant bit NOT implied. + * If the exponent is 2047, the number is invalid, in case the mantissa is zero, + * this means overflow (+/- depending of the sign bit), otherwise + * it simply means invalid number. + * + * If the number is too large for the machine or was specified as overflow, + * +/-HUGE_VAL is returned. + */ +INLINE static void +ieeetod(double *dp) +{ + double_t source; + long sign,exp,mant; + double dmant; + + source.ieee = ((double_t*)dp)->ieee; + sign = source.ieee.sign; + exp = source.ieee.exp; + mant = source.ieee.mant; + + if (exp == 2047) { + if (mant) /* Not a Number (NAN) */ + *dp = HUGE_VAL; + else /* +/- infinity */ + *dp = (sign ? -HUGE_VAL : HUGE_VAL); + return; + } + if (!exp) { + if (!(mant || source.ieee.mant2)) { /* zero */ + *dp=0; + return; + } else { /* Unnormalized number */ + /* NB: not -1023, the 1 bit is not implied */ + exp= -1022; + } + } else { + mant |= 1<<20; + exp -= 1023; + } + dmant = (((double) mant) + + ((double) source.ieee.mant2) / (((double) (1<<16)) * + ((double) (1<<16)))) / (double) (1<<20); + dmant = ldexp(dmant, exp); + if (sign) + dmant= -dmant; + *dp = dmant; +} + +INLINE static void +dtoieee(double *dp) +{ + double_t num; + double x; + int exp; + + num.d = *dp; + if (!num.d) { /* Zero is just binary all zeros */ + num.l[0] = num.l[1] = 0; + return; + } + + if (num.d < 0) { /* Sign is encoded separately */ + num.d = -num.d; + num.ieee.sign = 1; + } else { + num.ieee.sign = 0; + } + + /* Now separate the absolute value into mantissa and exponent */ + x = frexp(num.d, &exp); + + /* + * Handle cases where the value is outside the + * range for IEEE floating point numbers. + * (Overflow cannot happen on a VAX, but underflow + * can happen for G float.) + */ + if (exp < -1022) { /* Unnormalized number */ + x = ldexp(x, -1023-exp); + exp = 0; + } else if (exp > 1023) { /* +/- infinity */ + x = 0; + exp = 2047; + } else { /* Get rid of most significant bit */ + x *= 2; + x -= 1; + exp += 1022; /* fix NDR: 1.0 -> x=0.5, exp=1 -> ieee.exp = 1023 */ + } + num.ieee.exp = exp; + + x *= (double) (1<<20); + num.ieee.mant = (long) x; + x -= (double) num.ieee.mant; + num.ieee.mant2 = (long) (x*((double) (1<<16)*(double) (1<<16))); + + if (!(num.ieee.mant || num.ieee.exp || num.ieee.mant2)) { + /* Avoid negative zero */ + num.ieee.sign = 0; + } + ((double_t*)dp)->ieee = num.ieee; +} + +/* + * Beware, these do not handle over/under-flow + * during conversion from ieee to native format. + */ +#define NATIVE2IEEEFLOAT(fp) { \ + float_t t; \ + if (t.ieee.exp = (fp)->native.exp) \ + t.ieee.exp += -129 + 127; \ + t.ieee.sign = (fp)->native.sign; \ + t.ieee.mant = ((fp)->native.mant1<<16)|(fp)->native.mant2; \ + *(fp) = t; \ +} +#define IEEEFLOAT2NATIVE(fp) { \ + float_t t; int v = (fp)->ieee.exp; \ + if (v) v += -127 + 129; /* alter bias of exponent */\ + t.native.exp = v; /* implicit truncation of exponent */\ + t.native.sign = (fp)->ieee.sign; \ + v = (fp)->ieee.mant; \ + t.native.mant1 = v >> 16; \ + t.native.mant2 = v;\ + *(fp) = t; \ +} + +#define IEEEDOUBLE2NATIVE(dp) ieeetod(dp) + +#define NATIVE2IEEEDOUBLE(dp) dtoieee(dp) + + +/* + * These unions are used during floating point + * conversions. The above macros define the + * conversion operations. + */ +void +TIFFCvtIEEEFloatToNative(TIFF* tif, u_int n, float* f) +{ + float_t* fp = (float_t*) f; + + while (n-- > 0) { + IEEEFLOAT2NATIVE(fp); + fp++; + } +} + +void +TIFFCvtNativeToIEEEFloat(TIFF* tif, u_int n, float* f) +{ + float_t* fp = (float_t*) f; + + while (n-- > 0) { + NATIVE2IEEEFLOAT(fp); + fp++; + } +} +void +TIFFCvtIEEEDoubleToNative(TIFF* tif, u_int n, double* f) +{ + double_t* fp = (double_t*) f; + + while (n-- > 0) { + IEEEDOUBLE2NATIVE(fp); + fp++; + } +} + +void +TIFFCvtNativeToIEEEDouble(TIFF* tif, u_int n, double* f) +{ + double_t* fp = (double_t*) f; + + while (n-- > 0) { + NATIVE2IEEEDOUBLE(fp); + fp++; + } +} +#endif +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_warning.c b/Source/LibTIFF4/tif_warning.c index 1dd09a6..ee941af 100644 --- a/Source/LibTIFF4/tif_warning.c +++ b/Source/LibTIFF4/tif_warning.c @@ -1,81 +1,81 @@ -/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF4/tif_warning.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - */ -#include "tiffiop.h" - -TIFFErrorHandlerExt _TIFFwarningHandlerExt = NULL; - -TIFFErrorHandler -TIFFSetWarningHandler(TIFFErrorHandler handler) -{ - TIFFErrorHandler prev = _TIFFwarningHandler; - _TIFFwarningHandler = handler; - return (prev); -} - -TIFFErrorHandlerExt -TIFFSetWarningHandlerExt(TIFFErrorHandlerExt handler) -{ - TIFFErrorHandlerExt prev = _TIFFwarningHandlerExt; - _TIFFwarningHandlerExt = handler; - return (prev); -} - -void -TIFFWarning(const char* module, const char* fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - if (_TIFFwarningHandler) - (*_TIFFwarningHandler)(module, fmt, ap); - if (_TIFFwarningHandlerExt) - (*_TIFFwarningHandlerExt)(0, module, fmt, ap); - va_end(ap); -} - -void -TIFFWarningExt(thandle_t fd, const char* module, const char* fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - if (_TIFFwarningHandler) - (*_TIFFwarningHandler)(module, fmt, ap); - if (_TIFFwarningHandlerExt) - (*_TIFFwarningHandlerExt)(fd, module, fmt, ap); - va_end(ap); -} - - -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Header: /cvsroot/freeimage/FreeImage/Source/LibTIFF4/tif_warning.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + */ +#include "tiffiop.h" + +TIFFErrorHandlerExt _TIFFwarningHandlerExt = NULL; + +TIFFErrorHandler +TIFFSetWarningHandler(TIFFErrorHandler handler) +{ + TIFFErrorHandler prev = _TIFFwarningHandler; + _TIFFwarningHandler = handler; + return (prev); +} + +TIFFErrorHandlerExt +TIFFSetWarningHandlerExt(TIFFErrorHandlerExt handler) +{ + TIFFErrorHandlerExt prev = _TIFFwarningHandlerExt; + _TIFFwarningHandlerExt = handler; + return (prev); +} + +void +TIFFWarning(const char* module, const char* fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + if (_TIFFwarningHandler) + (*_TIFFwarningHandler)(module, fmt, ap); + if (_TIFFwarningHandlerExt) + (*_TIFFwarningHandlerExt)(0, module, fmt, ap); + va_end(ap); +} + +void +TIFFWarningExt(thandle_t fd, const char* module, const char* fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + if (_TIFFwarningHandler) + (*_TIFFwarningHandler)(module, fmt, ap); + if (_TIFFwarningHandlerExt) + (*_TIFFwarningHandlerExt)(fd, module, fmt, ap); + va_end(ap); +} + + +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_win32.c b/Source/LibTIFF4/tif_win32.c index 010596f..8340802 100644 --- a/Source/LibTIFF4/tif_win32.c +++ b/Source/LibTIFF4/tif_win32.c @@ -1,440 +1,440 @@ -/* $Id: tif_win32.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library Win32-specific Routines. Adapted from tif_unix.c 4/5/95 by - * Scott Wagner (wagner@itek.com), Itek Graphix, Rochester, NY USA - */ -#include "tiffiop.h" - -#include - -static tmsize_t -_tiffReadProc(thandle_t fd, void* buf, tmsize_t size) -{ - /* tmsize_t is 64bit on 64bit systems, but the WinAPI ReadFile takes - * 32bit sizes, so we loop through the data in suitable 32bit sized - * chunks */ - uint8* ma; - uint64 mb; - DWORD n; - DWORD o; - tmsize_t p; - ma=(uint8*)buf; - mb=size; - p=0; - while (mb>0) - { - n=0x80000000UL; - if ((uint64)n>mb) - n=(DWORD)mb; - if (!ReadFile(fd,(LPVOID)ma,n,&o,NULL)) - return(0); - ma+=o; - mb-=o; - p+=o; - if (o!=n) - break; - } - return(p); -} - -static tmsize_t -_tiffWriteProc(thandle_t fd, void* buf, tmsize_t size) -{ - /* tmsize_t is 64bit on 64bit systems, but the WinAPI WriteFile takes - * 32bit sizes, so we loop through the data in suitable 32bit sized - * chunks */ - uint8* ma; - uint64 mb; - DWORD n; - DWORD o; - tmsize_t p; - ma=(uint8*)buf; - mb=size; - p=0; - while (mb>0) - { - n=0x80000000UL; - if ((uint64)n>mb) - n=(DWORD)mb; - if (!WriteFile(fd,(LPVOID)ma,n,&o,NULL)) - return(0); - ma+=o; - mb-=o; - p+=o; - if (o!=n) - break; - } - return(p); -} - -static uint64 -_tiffSeekProc(thandle_t fd, uint64 off, int whence) -{ - LARGE_INTEGER offli; - DWORD dwMoveMethod; - offli.QuadPart = off; - switch(whence) - { - case SEEK_SET: - dwMoveMethod = FILE_BEGIN; - break; - case SEEK_CUR: - dwMoveMethod = FILE_CURRENT; - break; - case SEEK_END: - dwMoveMethod = FILE_END; - break; - default: - dwMoveMethod = FILE_BEGIN; - break; - } - offli.LowPart=SetFilePointer(fd,offli.LowPart,&offli.HighPart,dwMoveMethod); - if ((offli.LowPart==INVALID_SET_FILE_POINTER)&&(GetLastError()!=NO_ERROR)) - offli.QuadPart=0; - return(offli.QuadPart); -} - -static int -_tiffCloseProc(thandle_t fd) -{ - return (CloseHandle(fd) ? 0 : -1); -} - -static uint64 -_tiffSizeProc(thandle_t fd) -{ - ULARGE_INTEGER m; - m.LowPart=GetFileSize(fd,&m.HighPart); - return(m.QuadPart); -} - -static int -_tiffDummyMapProc(thandle_t fd, void** pbase, toff_t* psize) -{ - (void) fd; - (void) pbase; - (void) psize; - return (0); -} - -/* - * From "Hermann Josef Hill" : - * - * Windows uses both a handle and a pointer for file mapping, - * but according to the SDK documentation and Richter's book - * "Advanced Windows Programming" it is safe to free the handle - * after obtaining the file mapping pointer - * - * This removes a nasty OS dependency and cures a problem - * with Visual C++ 5.0 - */ -static int -_tiffMapProc(thandle_t fd, void** pbase, toff_t* psize) -{ - uint64 size; - tmsize_t sizem; - HANDLE hMapFile; - - size = _tiffSizeProc(fd); - sizem = (tmsize_t)size; - if ((uint64)sizem!=size) - return (0); - - /* By passing in 0 for the maximum file size, it specifies that we - create a file mapping object for the full file size. */ - hMapFile = CreateFileMapping(fd, NULL, PAGE_READONLY, 0, 0, NULL); - if (hMapFile == NULL) - return (0); - *pbase = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0); - CloseHandle(hMapFile); - if (*pbase == NULL) - return (0); - *psize = size; - return(1); -} - -static void -_tiffDummyUnmapProc(thandle_t fd, void* base, toff_t size) -{ - (void) fd; - (void) base; - (void) size; -} - -static void -_tiffUnmapProc(thandle_t fd, void* base, toff_t size) -{ - (void) fd; - (void) size; - UnmapViewOfFile(base); -} - -/* - * Open a TIFF file descriptor for read/writing. - * Note that TIFFFdOpen and TIFFOpen recognise the character 'u' in the mode - * string, which forces the file to be opened unmapped. - */ -TIFF* -TIFFFdOpen(int ifd, const char* name, const char* mode) -{ - TIFF* tif; - int fSuppressMap; - int m; - fSuppressMap=0; - for (m=0; mode[m]!=0; m++) - { - if (mode[m]=='u') - { - fSuppressMap=1; - break; - } - } - tif = TIFFClientOpen(name, mode, (thandle_t)ifd, - _tiffReadProc, _tiffWriteProc, - _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, - fSuppressMap ? _tiffDummyMapProc : _tiffMapProc, - fSuppressMap ? _tiffDummyUnmapProc : _tiffUnmapProc); - if (tif) - tif->tif_fd = ifd; - return (tif); -} - -#ifndef _WIN32_WCE - -/* - * Open a TIFF file for read/writing. - */ -TIFF* -TIFFOpen(const char* name, const char* mode) -{ - static const char module[] = "TIFFOpen"; - thandle_t fd; - int m; - DWORD dwMode; - TIFF* tif; - - m = _TIFFgetMode(mode, module); - - switch(m) { - case O_RDONLY: dwMode = OPEN_EXISTING; break; - case O_RDWR: dwMode = OPEN_ALWAYS; break; - case O_RDWR|O_CREAT: dwMode = OPEN_ALWAYS; break; - case O_RDWR|O_TRUNC: dwMode = CREATE_ALWAYS; break; - case O_RDWR|O_CREAT|O_TRUNC: dwMode = CREATE_ALWAYS; break; - default: return ((TIFF*)0); - } - - fd = (thandle_t)CreateFileA(name, - (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ | GENERIC_WRITE), - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, - (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, - NULL); - if (fd == INVALID_HANDLE_VALUE) { - TIFFErrorExt(0, module, "%s: Cannot open", name); - return ((TIFF *)0); - } - - tif = TIFFFdOpen((int)fd, name, mode); - if(!tif) - CloseHandle(fd); - return tif; -} - -/* - * Open a TIFF file with a Unicode filename, for read/writing. - */ -TIFF* -TIFFOpenW(const wchar_t* name, const char* mode) -{ - static const char module[] = "TIFFOpenW"; - thandle_t fd; - int m; - DWORD dwMode; - int mbsize; - char *mbname; - TIFF *tif; - - m = _TIFFgetMode(mode, module); - - switch(m) { - case O_RDONLY: dwMode = OPEN_EXISTING; break; - case O_RDWR: dwMode = OPEN_ALWAYS; break; - case O_RDWR|O_CREAT: dwMode = OPEN_ALWAYS; break; - case O_RDWR|O_TRUNC: dwMode = CREATE_ALWAYS; break; - case O_RDWR|O_CREAT|O_TRUNC: dwMode = CREATE_ALWAYS; break; - default: return ((TIFF*)0); - } - - fd = (thandle_t)CreateFileW(name, - (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ|GENERIC_WRITE), - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, - (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, - NULL); - if (fd == INVALID_HANDLE_VALUE) { - TIFFErrorExt(0, module, "%S: Cannot open", name); - return ((TIFF *)0); - } - - mbname = NULL; - mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL); - if (mbsize > 0) { - mbname = (char *)_TIFFmalloc(mbsize); - if (!mbname) { - TIFFErrorExt(0, module, - "Can't allocate space for filename conversion buffer"); - return ((TIFF*)0); - } - - WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, - NULL, NULL); - } - - tif = TIFFFdOpen((int)fd, - (mbname != NULL) ? mbname : "", mode); - if(!tif) - CloseHandle(fd); - - _TIFFfree(mbname); - - return tif; -} - -#endif /* ndef _WIN32_WCE */ - -void* -_TIFFmalloc(tmsize_t s) -{ - return (malloc((size_t) s)); -} - -void -_TIFFfree(void* p) -{ - free(p); -} - -void* -_TIFFrealloc(void* p, tmsize_t s) -{ - return (realloc(p, (size_t) s)); -} - -void -_TIFFmemset(void* p, int v, tmsize_t c) -{ - memset(p, v, (size_t) c); -} - -void -_TIFFmemcpy(void* d, const void* s, tmsize_t c) -{ - memcpy(d, s, (size_t) c); -} - -int -_TIFFmemcmp(const void* p1, const void* p2, tmsize_t c) -{ - return (memcmp(p1, p2, (size_t) c)); -} - -#ifndef _WIN32_WCE - -#if (_MSC_VER < 1500) -# define vsnprintf _vsnprintf -#endif - -static void -Win32WarningHandler(const char* module, const char* fmt, va_list ap) -{ -#ifndef TIF_PLATFORM_CONSOLE - LPTSTR szTitle; - LPTSTR szTmp; - LPCTSTR szTitleText = "%s Warning"; - LPCTSTR szDefaultModule = "LIBTIFF"; - LPCTSTR szTmpModule = (module == NULL) ? szDefaultModule : module; - SIZE_T nBufSize = (strlen(szTmpModule) + - strlen(szTitleText) + strlen(fmt) + 256)*sizeof(char); - - if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, nBufSize)) == NULL) - return; - sprintf(szTitle, szTitleText, szTmpModule); - szTmp = szTitle + (strlen(szTitle)+2)*sizeof(char); - vsnprintf(szTmp, nBufSize-(strlen(szTitle)+2)*sizeof(char), fmt, ap); - MessageBoxA(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONINFORMATION); - LocalFree(szTitle); - - return; -#else - if (module != NULL) - fprintf(stderr, "%s: ", module); - fprintf(stderr, "Warning, "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -#endif -} -TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler; - -static void -Win32ErrorHandler(const char* module, const char* fmt, va_list ap) -{ -#ifndef TIF_PLATFORM_CONSOLE - LPTSTR szTitle; - LPTSTR szTmp; - LPCTSTR szTitleText = "%s Error"; - LPCTSTR szDefaultModule = "LIBTIFF"; - LPCTSTR szTmpModule = (module == NULL) ? szDefaultModule : module; - SIZE_T nBufSize = (strlen(szTmpModule) + - strlen(szTitleText) + strlen(fmt) + 256)*sizeof(char); - - if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, nBufSize)) == NULL) - return; - sprintf(szTitle, szTitleText, szTmpModule); - szTmp = szTitle + (strlen(szTitle)+2)*sizeof(char); - vsnprintf(szTmp, nBufSize-(strlen(szTitle)+2)*sizeof(char), fmt, ap); - MessageBoxA(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONEXCLAMATION); - LocalFree(szTitle); - return; -#else - if (module != NULL) - fprintf(stderr, "%s: ", module); - vfprintf(stderr, fmt, ap); - fprintf(stderr, ".\n"); -#endif -} -TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler; - -#endif /* ndef _WIN32_WCE */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_win32.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library Win32-specific Routines. Adapted from tif_unix.c 4/5/95 by + * Scott Wagner (wagner@itek.com), Itek Graphix, Rochester, NY USA + */ +#include "tiffiop.h" + +#include + +static tmsize_t +_tiffReadProc(thandle_t fd, void* buf, tmsize_t size) +{ + /* tmsize_t is 64bit on 64bit systems, but the WinAPI ReadFile takes + * 32bit sizes, so we loop through the data in suitable 32bit sized + * chunks */ + uint8* ma; + uint64 mb; + DWORD n; + DWORD o; + tmsize_t p; + ma=(uint8*)buf; + mb=size; + p=0; + while (mb>0) + { + n=0x80000000UL; + if ((uint64)n>mb) + n=(DWORD)mb; + if (!ReadFile(fd,(LPVOID)ma,n,&o,NULL)) + return(0); + ma+=o; + mb-=o; + p+=o; + if (o!=n) + break; + } + return(p); +} + +static tmsize_t +_tiffWriteProc(thandle_t fd, void* buf, tmsize_t size) +{ + /* tmsize_t is 64bit on 64bit systems, but the WinAPI WriteFile takes + * 32bit sizes, so we loop through the data in suitable 32bit sized + * chunks */ + uint8* ma; + uint64 mb; + DWORD n; + DWORD o; + tmsize_t p; + ma=(uint8*)buf; + mb=size; + p=0; + while (mb>0) + { + n=0x80000000UL; + if ((uint64)n>mb) + n=(DWORD)mb; + if (!WriteFile(fd,(LPVOID)ma,n,&o,NULL)) + return(0); + ma+=o; + mb-=o; + p+=o; + if (o!=n) + break; + } + return(p); +} + +static uint64 +_tiffSeekProc(thandle_t fd, uint64 off, int whence) +{ + LARGE_INTEGER offli; + DWORD dwMoveMethod; + offli.QuadPart = off; + switch(whence) + { + case SEEK_SET: + dwMoveMethod = FILE_BEGIN; + break; + case SEEK_CUR: + dwMoveMethod = FILE_CURRENT; + break; + case SEEK_END: + dwMoveMethod = FILE_END; + break; + default: + dwMoveMethod = FILE_BEGIN; + break; + } + offli.LowPart=SetFilePointer(fd,offli.LowPart,&offli.HighPart,dwMoveMethod); + if ((offli.LowPart==INVALID_SET_FILE_POINTER)&&(GetLastError()!=NO_ERROR)) + offli.QuadPart=0; + return(offli.QuadPart); +} + +static int +_tiffCloseProc(thandle_t fd) +{ + return (CloseHandle(fd) ? 0 : -1); +} + +static uint64 +_tiffSizeProc(thandle_t fd) +{ + ULARGE_INTEGER m; + m.LowPart=GetFileSize(fd,&m.HighPart); + return(m.QuadPart); +} + +static int +_tiffDummyMapProc(thandle_t fd, void** pbase, toff_t* psize) +{ + (void) fd; + (void) pbase; + (void) psize; + return (0); +} + +/* + * From "Hermann Josef Hill" : + * + * Windows uses both a handle and a pointer for file mapping, + * but according to the SDK documentation and Richter's book + * "Advanced Windows Programming" it is safe to free the handle + * after obtaining the file mapping pointer + * + * This removes a nasty OS dependency and cures a problem + * with Visual C++ 5.0 + */ +static int +_tiffMapProc(thandle_t fd, void** pbase, toff_t* psize) +{ + uint64 size; + tmsize_t sizem; + HANDLE hMapFile; + + size = _tiffSizeProc(fd); + sizem = (tmsize_t)size; + if ((uint64)sizem!=size) + return (0); + + /* By passing in 0 for the maximum file size, it specifies that we + create a file mapping object for the full file size. */ + hMapFile = CreateFileMapping(fd, NULL, PAGE_READONLY, 0, 0, NULL); + if (hMapFile == NULL) + return (0); + *pbase = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0); + CloseHandle(hMapFile); + if (*pbase == NULL) + return (0); + *psize = size; + return(1); +} + +static void +_tiffDummyUnmapProc(thandle_t fd, void* base, toff_t size) +{ + (void) fd; + (void) base; + (void) size; +} + +static void +_tiffUnmapProc(thandle_t fd, void* base, toff_t size) +{ + (void) fd; + (void) size; + UnmapViewOfFile(base); +} + +/* + * Open a TIFF file descriptor for read/writing. + * Note that TIFFFdOpen and TIFFOpen recognise the character 'u' in the mode + * string, which forces the file to be opened unmapped. + */ +TIFF* +TIFFFdOpen(int ifd, const char* name, const char* mode) +{ + TIFF* tif; + int fSuppressMap; + int m; + fSuppressMap=0; + for (m=0; mode[m]!=0; m++) + { + if (mode[m]=='u') + { + fSuppressMap=1; + break; + } + } + tif = TIFFClientOpen(name, mode, (thandle_t)ifd, + _tiffReadProc, _tiffWriteProc, + _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, + fSuppressMap ? _tiffDummyMapProc : _tiffMapProc, + fSuppressMap ? _tiffDummyUnmapProc : _tiffUnmapProc); + if (tif) + tif->tif_fd = ifd; + return (tif); +} + +#ifndef _WIN32_WCE + +/* + * Open a TIFF file for read/writing. + */ +TIFF* +TIFFOpen(const char* name, const char* mode) +{ + static const char module[] = "TIFFOpen"; + thandle_t fd; + int m; + DWORD dwMode; + TIFF* tif; + + m = _TIFFgetMode(mode, module); + + switch(m) { + case O_RDONLY: dwMode = OPEN_EXISTING; break; + case O_RDWR: dwMode = OPEN_ALWAYS; break; + case O_RDWR|O_CREAT: dwMode = OPEN_ALWAYS; break; + case O_RDWR|O_TRUNC: dwMode = CREATE_ALWAYS; break; + case O_RDWR|O_CREAT|O_TRUNC: dwMode = CREATE_ALWAYS; break; + default: return ((TIFF*)0); + } + + fd = (thandle_t)CreateFileA(name, + (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ | GENERIC_WRITE), + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, + (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, + NULL); + if (fd == INVALID_HANDLE_VALUE) { + TIFFErrorExt(0, module, "%s: Cannot open", name); + return ((TIFF *)0); + } + + tif = TIFFFdOpen((int)fd, name, mode); + if(!tif) + CloseHandle(fd); + return tif; +} + +/* + * Open a TIFF file with a Unicode filename, for read/writing. + */ +TIFF* +TIFFOpenW(const wchar_t* name, const char* mode) +{ + static const char module[] = "TIFFOpenW"; + thandle_t fd; + int m; + DWORD dwMode; + int mbsize; + char *mbname; + TIFF *tif; + + m = _TIFFgetMode(mode, module); + + switch(m) { + case O_RDONLY: dwMode = OPEN_EXISTING; break; + case O_RDWR: dwMode = OPEN_ALWAYS; break; + case O_RDWR|O_CREAT: dwMode = OPEN_ALWAYS; break; + case O_RDWR|O_TRUNC: dwMode = CREATE_ALWAYS; break; + case O_RDWR|O_CREAT|O_TRUNC: dwMode = CREATE_ALWAYS; break; + default: return ((TIFF*)0); + } + + fd = (thandle_t)CreateFileW(name, + (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ|GENERIC_WRITE), + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, + (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, + NULL); + if (fd == INVALID_HANDLE_VALUE) { + TIFFErrorExt(0, module, "%S: Cannot open", name); + return ((TIFF *)0); + } + + mbname = NULL; + mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL); + if (mbsize > 0) { + mbname = (char *)_TIFFmalloc(mbsize); + if (!mbname) { + TIFFErrorExt(0, module, + "Can't allocate space for filename conversion buffer"); + return ((TIFF*)0); + } + + WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, + NULL, NULL); + } + + tif = TIFFFdOpen((int)fd, + (mbname != NULL) ? mbname : "", mode); + if(!tif) + CloseHandle(fd); + + _TIFFfree(mbname); + + return tif; +} + +#endif /* ndef _WIN32_WCE */ + +void* +_TIFFmalloc(tmsize_t s) +{ + return (malloc((size_t) s)); +} + +void +_TIFFfree(void* p) +{ + free(p); +} + +void* +_TIFFrealloc(void* p, tmsize_t s) +{ + return (realloc(p, (size_t) s)); +} + +void +_TIFFmemset(void* p, int v, tmsize_t c) +{ + memset(p, v, (size_t) c); +} + +void +_TIFFmemcpy(void* d, const void* s, tmsize_t c) +{ + memcpy(d, s, (size_t) c); +} + +int +_TIFFmemcmp(const void* p1, const void* p2, tmsize_t c) +{ + return (memcmp(p1, p2, (size_t) c)); +} + +#ifndef _WIN32_WCE + +#if (_MSC_VER < 1500) +# define vsnprintf _vsnprintf +#endif + +static void +Win32WarningHandler(const char* module, const char* fmt, va_list ap) +{ +#ifndef TIF_PLATFORM_CONSOLE + LPTSTR szTitle; + LPTSTR szTmp; + LPCTSTR szTitleText = "%s Warning"; + LPCTSTR szDefaultModule = "LIBTIFF"; + LPCTSTR szTmpModule = (module == NULL) ? szDefaultModule : module; + SIZE_T nBufSize = (strlen(szTmpModule) + + strlen(szTitleText) + strlen(fmt) + 256)*sizeof(char); + + if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, nBufSize)) == NULL) + return; + sprintf(szTitle, szTitleText, szTmpModule); + szTmp = szTitle + (strlen(szTitle)+2)*sizeof(char); + vsnprintf(szTmp, nBufSize-(strlen(szTitle)+2)*sizeof(char), fmt, ap); + MessageBoxA(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONINFORMATION); + LocalFree(szTitle); + + return; +#else + if (module != NULL) + fprintf(stderr, "%s: ", module); + fprintf(stderr, "Warning, "); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +#endif +} +TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler; + +static void +Win32ErrorHandler(const char* module, const char* fmt, va_list ap) +{ +#ifndef TIF_PLATFORM_CONSOLE + LPTSTR szTitle; + LPTSTR szTmp; + LPCTSTR szTitleText = "%s Error"; + LPCTSTR szDefaultModule = "LIBTIFF"; + LPCTSTR szTmpModule = (module == NULL) ? szDefaultModule : module; + SIZE_T nBufSize = (strlen(szTmpModule) + + strlen(szTitleText) + strlen(fmt) + 256)*sizeof(char); + + if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, nBufSize)) == NULL) + return; + sprintf(szTitle, szTitleText, szTmpModule); + szTmp = szTitle + (strlen(szTitle)+2)*sizeof(char); + vsnprintf(szTmp, nBufSize-(strlen(szTitle)+2)*sizeof(char), fmt, ap); + MessageBoxA(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONEXCLAMATION); + LocalFree(szTitle); + return; +#else + if (module != NULL) + fprintf(stderr, "%s: ", module); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ".\n"); +#endif +} +TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler; + +#endif /* ndef _WIN32_WCE */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_wince.c b/Source/LibTIFF4/tif_wince.c index aeb1170..9b380b4 100644 --- a/Source/LibTIFF4/tif_wince.c +++ b/Source/LibTIFF4/tif_wince.c @@ -1,293 +1,293 @@ -/* $Id: tif_wince.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * Windows CE-specific routines for TIFF Library. - * Adapted from tif_win32.c 01/10/2006 by Mateusz Loskot (mateusz@loskot.net) - */ - -#ifndef _WIN32_WCE -# error "Only Windows CE target is supported!" -#endif - -#include "tiffiop.h" -#include - -/* Turn off console support on Windows CE. */ -#undef TIF_PLATFORM_CONSOLE - -COMPILATION SHOULD FAIL -This file is not yet updated to reflect changes in LibTiff 4.0. If you have -the opportunity to update and test this file, please contact LibTiff folks -for all assistance you may require and contribute the results - - -/* - * Open a TIFF file for read/writing. - */ -TIFF* -TIFFOpen(const char* name, const char* mode) -{ - static const char module[] = "TIFFOpen"; - thandle_t fd; - int m; - DWORD dwMode; - TIFF* tif; - size_t nLen; - size_t nWideLen; - wchar_t* wchName; - - m = _TIFFgetMode(mode, module); - - switch(m) - { - case O_RDONLY: - dwMode = OPEN_EXISTING; - break; - case O_RDWR: - dwMode = OPEN_ALWAYS; - break; - case O_RDWR|O_CREAT: - dwMode = OPEN_ALWAYS; - break; - case O_RDWR|O_TRUNC: - dwMode = CREATE_ALWAYS; - break; - case O_RDWR|O_CREAT|O_TRUNC: - dwMode = CREATE_ALWAYS; - break; - default: - return ((TIFF*)0); - } - - /* On Windows CE, CreateFile is mapped to CreateFileW, - * but file path is passed as char-based string, - * so the path has to be converted to wchar_t. - */ - - nWideLen = 0; - wchName = NULL; - nLen = strlen(name) + 1; - - nWideLen = MultiByteToWideChar(CP_ACP, 0, name, nLen, NULL, 0); - wchName = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); - if (NULL == wchName) - { - TIFFErrorExt(0, module, "Memory allocation error!"); - return ((TIFF *)0); - } - memset(wchName, 0, sizeof(wchar_t) * nWideLen); - MultiByteToWideChar(CP_ACP, 0, name, nLen, wchName, nWideLen); - - fd = (thandle_t)CreateFile(wchName, - (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ | GENERIC_WRITE), - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, - (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, - NULL); - - free(wchName); - - if (fd == INVALID_HANDLE_VALUE) { - TIFFErrorExt(0, module, "%s: Cannot open", name); - return ((TIFF *)0); - } - - /* TODO - mloskot: change to TIFFdOpenW and pass wchar path */ - - tif = TIFFFdOpen((int)fd, name, mode); - if(!tif) - CloseHandle(fd); - return tif; -} - -/* - * Open a TIFF file with a Unicode filename, for read/writing. - */ -TIFF* -TIFFOpenW(const wchar_t* name, const char* mode) -{ - static const char module[] = "TIFFOpenW"; - thandle_t fd; - int m; - DWORD dwMode; - int mbsize; - char *mbname; - TIFF *tif; - - m = _TIFFgetMode(mode, module); - - switch(m) { - case O_RDONLY: dwMode = OPEN_EXISTING; break; - case O_RDWR: dwMode = OPEN_ALWAYS; break; - case O_RDWR|O_CREAT: dwMode = OPEN_ALWAYS; break; - case O_RDWR|O_TRUNC: dwMode = CREATE_ALWAYS; break; - case O_RDWR|O_CREAT|O_TRUNC: dwMode = CREATE_ALWAYS; break; - default: return ((TIFF*)0); - } - - /* On Windows CE, CreateFile is mapped to CreateFileW, - * so no conversion of wchar_t to char is required. - */ - - fd = (thandle_t)CreateFile(name, - (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ|GENERIC_WRITE), - FILE_SHARE_READ, NULL, dwMode, - (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, - NULL); - if (fd == INVALID_HANDLE_VALUE) { - TIFFErrorExt(0, module, "%S: Cannot open", name); - return ((TIFF *)0); - } - - mbname = NULL; - mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL); - if (mbsize > 0) { - mbname = (char *)_TIFFmalloc(mbsize); - if (!mbname) { - TIFFErrorExt(0, module, - "Can't allocate space for filename conversion buffer"); - return ((TIFF*)0); - } - - WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, - NULL, NULL); - } - - tif = TIFFFdOpen((int)fd, - (mbname != NULL) ? mbname : "", mode); - if(!tif) - CloseHandle(fd); - - _TIFFfree(mbname); - - return tif; -} - -static void -Win32WarningHandler(const char* module, const char* fmt, va_list ap) -{ - /* On Windows CE, MessageBox is mapped to wide-char based MessageBoxW. */ - - size_t nWideLen = 0; - LPTSTR szWideTitle = NULL; - LPTSTR szWideMsg = NULL; - - LPSTR szTitle; - LPSTR szTmp; - LPCSTR szTitleText = "%s Warning"; - LPCSTR szDefaultModule = "LIBTIFF"; - LPCSTR szTmpModule; - - szTmpModule = (module == NULL) ? szDefaultModule : module; - if ((szTitle = (LPSTR)LocalAlloc(LMEM_FIXED, - (strlen(szTmpModule) + strlen(szTitleText) - + strlen(fmt) + 128) * sizeof(char))) == NULL) - return; - - sprintf(szTitle, szTitleText, szTmpModule); - szTmp = szTitle + (strlen(szTitle) + 2) * sizeof(char); - vsprintf(szTmp, fmt, ap); - - /* Convert error message to Unicode. */ - - nWideLen = MultiByteToWideChar(CP_ACP, 0, szTitle, -1, NULL, 0); - szWideTitle = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); - MultiByteToWideChar(CP_ACP, 0, szTitle, -1, szWideTitle, nWideLen); - - nWideLen = MultiByteToWideChar(CP_ACP, 0, szTmp, -1, NULL, 0); - szWideMsg = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); - MultiByteToWideChar(CP_ACP, 0, szTmp, -1, szWideMsg, nWideLen); - - /* Display message */ - - MessageBox(GetFocus(), szWideMsg, szWideTitle, MB_OK | MB_ICONEXCLAMATION); - - /* Free resources */ - - LocalFree(szTitle); - free(szWideMsg); - free(szWideTitle); -} - -TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler; - -static void -Win32ErrorHandler(const char* module, const char* fmt, va_list ap) -{ - /* On Windows CE, MessageBox is mapped to wide-char based MessageBoxW. */ - - size_t nWideLen = 0; - LPTSTR szWideTitle = NULL; - LPTSTR szWideMsg = NULL; - - LPSTR szTitle; - LPSTR szTmp; - LPCSTR szTitleText = "%s Error"; - LPCSTR szDefaultModule = "LIBTIFF"; - LPCSTR szTmpModule; - - szTmpModule = (module == NULL) ? szDefaultModule : module; - if ((szTitle = (LPSTR)LocalAlloc(LMEM_FIXED, - (strlen(szTmpModule) + strlen(szTitleText) - + strlen(fmt) + 128) * sizeof(char))) == NULL) - return; - - sprintf(szTitle, szTitleText, szTmpModule); - szTmp = szTitle + (strlen(szTitle) + 2) * sizeof(char); - vsprintf(szTmp, fmt, ap); - - /* Convert error message to Unicode. */ - - nWideLen = MultiByteToWideChar(CP_ACP, 0, szTitle, -1, NULL, 0); - szWideTitle = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); - MultiByteToWideChar(CP_ACP, 0, szTitle, -1, szWideTitle, nWideLen); - - nWideLen = MultiByteToWideChar(CP_ACP, 0, szTmp, -1, NULL, 0); - szWideMsg = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); - MultiByteToWideChar(CP_ACP, 0, szTmp, -1, szWideMsg, nWideLen); - - /* Display message */ - - MessageBox(GetFocus(), szWideMsg, szWideTitle, MB_OK | MB_ICONEXCLAMATION); - - /* Free resources */ - - LocalFree(szTitle); - free(szWideMsg); - free(szWideTitle); -} - -TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler; - - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_wince.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * Windows CE-specific routines for TIFF Library. + * Adapted from tif_win32.c 01/10/2006 by Mateusz Loskot (mateusz@loskot.net) + */ + +#ifndef _WIN32_WCE +# error "Only Windows CE target is supported!" +#endif + +#include "tiffiop.h" +#include + +/* Turn off console support on Windows CE. */ +#undef TIF_PLATFORM_CONSOLE + +COMPILATION SHOULD FAIL +This file is not yet updated to reflect changes in LibTiff 4.0. If you have +the opportunity to update and test this file, please contact LibTiff folks +for all assistance you may require and contribute the results + + +/* + * Open a TIFF file for read/writing. + */ +TIFF* +TIFFOpen(const char* name, const char* mode) +{ + static const char module[] = "TIFFOpen"; + thandle_t fd; + int m; + DWORD dwMode; + TIFF* tif; + size_t nLen; + size_t nWideLen; + wchar_t* wchName; + + m = _TIFFgetMode(mode, module); + + switch(m) + { + case O_RDONLY: + dwMode = OPEN_EXISTING; + break; + case O_RDWR: + dwMode = OPEN_ALWAYS; + break; + case O_RDWR|O_CREAT: + dwMode = OPEN_ALWAYS; + break; + case O_RDWR|O_TRUNC: + dwMode = CREATE_ALWAYS; + break; + case O_RDWR|O_CREAT|O_TRUNC: + dwMode = CREATE_ALWAYS; + break; + default: + return ((TIFF*)0); + } + + /* On Windows CE, CreateFile is mapped to CreateFileW, + * but file path is passed as char-based string, + * so the path has to be converted to wchar_t. + */ + + nWideLen = 0; + wchName = NULL; + nLen = strlen(name) + 1; + + nWideLen = MultiByteToWideChar(CP_ACP, 0, name, nLen, NULL, 0); + wchName = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); + if (NULL == wchName) + { + TIFFErrorExt(0, module, "Memory allocation error!"); + return ((TIFF *)0); + } + memset(wchName, 0, sizeof(wchar_t) * nWideLen); + MultiByteToWideChar(CP_ACP, 0, name, nLen, wchName, nWideLen); + + fd = (thandle_t)CreateFile(wchName, + (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ | GENERIC_WRITE), + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, + (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, + NULL); + + free(wchName); + + if (fd == INVALID_HANDLE_VALUE) { + TIFFErrorExt(0, module, "%s: Cannot open", name); + return ((TIFF *)0); + } + + /* TODO - mloskot: change to TIFFdOpenW and pass wchar path */ + + tif = TIFFFdOpen((int)fd, name, mode); + if(!tif) + CloseHandle(fd); + return tif; +} + +/* + * Open a TIFF file with a Unicode filename, for read/writing. + */ +TIFF* +TIFFOpenW(const wchar_t* name, const char* mode) +{ + static const char module[] = "TIFFOpenW"; + thandle_t fd; + int m; + DWORD dwMode; + int mbsize; + char *mbname; + TIFF *tif; + + m = _TIFFgetMode(mode, module); + + switch(m) { + case O_RDONLY: dwMode = OPEN_EXISTING; break; + case O_RDWR: dwMode = OPEN_ALWAYS; break; + case O_RDWR|O_CREAT: dwMode = OPEN_ALWAYS; break; + case O_RDWR|O_TRUNC: dwMode = CREATE_ALWAYS; break; + case O_RDWR|O_CREAT|O_TRUNC: dwMode = CREATE_ALWAYS; break; + default: return ((TIFF*)0); + } + + /* On Windows CE, CreateFile is mapped to CreateFileW, + * so no conversion of wchar_t to char is required. + */ + + fd = (thandle_t)CreateFile(name, + (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ|GENERIC_WRITE), + FILE_SHARE_READ, NULL, dwMode, + (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, + NULL); + if (fd == INVALID_HANDLE_VALUE) { + TIFFErrorExt(0, module, "%S: Cannot open", name); + return ((TIFF *)0); + } + + mbname = NULL; + mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL); + if (mbsize > 0) { + mbname = (char *)_TIFFmalloc(mbsize); + if (!mbname) { + TIFFErrorExt(0, module, + "Can't allocate space for filename conversion buffer"); + return ((TIFF*)0); + } + + WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, + NULL, NULL); + } + + tif = TIFFFdOpen((int)fd, + (mbname != NULL) ? mbname : "", mode); + if(!tif) + CloseHandle(fd); + + _TIFFfree(mbname); + + return tif; +} + +static void +Win32WarningHandler(const char* module, const char* fmt, va_list ap) +{ + /* On Windows CE, MessageBox is mapped to wide-char based MessageBoxW. */ + + size_t nWideLen = 0; + LPTSTR szWideTitle = NULL; + LPTSTR szWideMsg = NULL; + + LPSTR szTitle; + LPSTR szTmp; + LPCSTR szTitleText = "%s Warning"; + LPCSTR szDefaultModule = "LIBTIFF"; + LPCSTR szTmpModule; + + szTmpModule = (module == NULL) ? szDefaultModule : module; + if ((szTitle = (LPSTR)LocalAlloc(LMEM_FIXED, + (strlen(szTmpModule) + strlen(szTitleText) + + strlen(fmt) + 128) * sizeof(char))) == NULL) + return; + + sprintf(szTitle, szTitleText, szTmpModule); + szTmp = szTitle + (strlen(szTitle) + 2) * sizeof(char); + vsprintf(szTmp, fmt, ap); + + /* Convert error message to Unicode. */ + + nWideLen = MultiByteToWideChar(CP_ACP, 0, szTitle, -1, NULL, 0); + szWideTitle = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); + MultiByteToWideChar(CP_ACP, 0, szTitle, -1, szWideTitle, nWideLen); + + nWideLen = MultiByteToWideChar(CP_ACP, 0, szTmp, -1, NULL, 0); + szWideMsg = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); + MultiByteToWideChar(CP_ACP, 0, szTmp, -1, szWideMsg, nWideLen); + + /* Display message */ + + MessageBox(GetFocus(), szWideMsg, szWideTitle, MB_OK | MB_ICONEXCLAMATION); + + /* Free resources */ + + LocalFree(szTitle); + free(szWideMsg); + free(szWideTitle); +} + +TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler; + +static void +Win32ErrorHandler(const char* module, const char* fmt, va_list ap) +{ + /* On Windows CE, MessageBox is mapped to wide-char based MessageBoxW. */ + + size_t nWideLen = 0; + LPTSTR szWideTitle = NULL; + LPTSTR szWideMsg = NULL; + + LPSTR szTitle; + LPSTR szTmp; + LPCSTR szTitleText = "%s Error"; + LPCSTR szDefaultModule = "LIBTIFF"; + LPCSTR szTmpModule; + + szTmpModule = (module == NULL) ? szDefaultModule : module; + if ((szTitle = (LPSTR)LocalAlloc(LMEM_FIXED, + (strlen(szTmpModule) + strlen(szTitleText) + + strlen(fmt) + 128) * sizeof(char))) == NULL) + return; + + sprintf(szTitle, szTitleText, szTmpModule); + szTmp = szTitle + (strlen(szTitle) + 2) * sizeof(char); + vsprintf(szTmp, fmt, ap); + + /* Convert error message to Unicode. */ + + nWideLen = MultiByteToWideChar(CP_ACP, 0, szTitle, -1, NULL, 0); + szWideTitle = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); + MultiByteToWideChar(CP_ACP, 0, szTitle, -1, szWideTitle, nWideLen); + + nWideLen = MultiByteToWideChar(CP_ACP, 0, szTmp, -1, NULL, 0); + szWideMsg = (wchar_t*)malloc(sizeof(wchar_t) * nWideLen); + MultiByteToWideChar(CP_ACP, 0, szTmp, -1, szWideMsg, nWideLen); + + /* Display message */ + + MessageBox(GetFocus(), szWideMsg, szWideTitle, MB_OK | MB_ICONEXCLAMATION); + + /* Free resources */ + + LocalFree(szTitle); + free(szWideMsg); + free(szWideTitle); +} + +TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler; + + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_write.c b/Source/LibTIFF4/tif_write.c index 87341ff..86e01c2 100644 --- a/Source/LibTIFF4/tif_write.c +++ b/Source/LibTIFF4/tif_write.c @@ -1,771 +1,771 @@ -/* $Id: tif_write.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/* - * TIFF Library. - * - * Scanline-oriented Write Support - */ -#include "tiffiop.h" -#include - -#define STRIPINCR 20 /* expansion factor on strip array */ - -#define WRITECHECKSTRIPS(tif, module) \ - (((tif)->tif_flags&TIFF_BEENWRITING) || TIFFWriteCheck((tif),0,module)) -#define WRITECHECKTILES(tif, module) \ - (((tif)->tif_flags&TIFF_BEENWRITING) || TIFFWriteCheck((tif),1,module)) -#define BUFFERCHECK(tif) \ - ((((tif)->tif_flags & TIFF_BUFFERSETUP) && tif->tif_rawdata) || \ - TIFFWriteBufferSetup((tif), NULL, (tmsize_t) -1)) - -static int TIFFGrowStrips(TIFF* tif, uint32 delta, const char* module); -static int TIFFAppendToStrip(TIFF* tif, uint32 strip, uint8* data, tmsize_t cc); - -int -TIFFWriteScanline(TIFF* tif, void* buf, uint32 row, uint16 sample) -{ - static const char module[] = "TIFFWriteScanline"; - register TIFFDirectory *td; - int status, imagegrew = 0; - uint32 strip; - - if (!WRITECHECKSTRIPS(tif, module)) - return (-1); - /* - * Handle delayed allocation of data buffer. This - * permits it to be sized more intelligently (using - * directory information). - */ - if (!BUFFERCHECK(tif)) - return (-1); - tif->tif_flags |= TIFF_BUF4WRITE; /* not strictly sure this is right*/ - - td = &tif->tif_dir; - /* - * Extend image length if needed - * (but only for PlanarConfig=1). - */ - if (row >= td->td_imagelength) { /* extend image */ - if (td->td_planarconfig == PLANARCONFIG_SEPARATE) { - TIFFErrorExt(tif->tif_clientdata, module, - "Can not change \"ImageLength\" when using separate planes"); - return (-1); - } - td->td_imagelength = row+1; - imagegrew = 1; - } - /* - * Calculate strip and check for crossings. - */ - if (td->td_planarconfig == PLANARCONFIG_SEPARATE) { - if (sample >= td->td_samplesperpixel) { - TIFFErrorExt(tif->tif_clientdata, module, - "%lu: Sample out of range, max %lu", - (unsigned long) sample, (unsigned long) td->td_samplesperpixel); - return (-1); - } - strip = sample*td->td_stripsperimage + row/td->td_rowsperstrip; - } else - strip = row / td->td_rowsperstrip; - /* - * Check strip array to make sure there's space. We don't support - * dynamically growing files that have data organized in separate - * bitplanes because it's too painful. In that case we require that - * the imagelength be set properly before the first write (so that the - * strips array will be fully allocated above). - */ - if (strip >= td->td_nstrips && !TIFFGrowStrips(tif, 1, module)) - return (-1); - if (strip != tif->tif_curstrip) { - /* - * Changing strips -- flush any data present. - */ - if (!TIFFFlushData(tif)) - return (-1); - tif->tif_curstrip = strip; - /* - * Watch out for a growing image. The value of strips/image - * will initially be 1 (since it can't be deduced until the - * imagelength is known). - */ - if (strip >= td->td_stripsperimage && imagegrew) - td->td_stripsperimage = - TIFFhowmany_32(td->td_imagelength,td->td_rowsperstrip); - tif->tif_row = - (strip % td->td_stripsperimage) * td->td_rowsperstrip; - if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { - if (!(*tif->tif_setupencode)(tif)) - return (-1); - tif->tif_flags |= TIFF_CODERSETUP; - } - - tif->tif_rawcc = 0; - tif->tif_rawcp = tif->tif_rawdata; - - if( td->td_stripbytecount[strip] > 0 ) - { - /* if we are writing over existing tiles, zero length */ - td->td_stripbytecount[strip] = 0; - - /* this forces TIFFAppendToStrip() to do a seek */ - tif->tif_curoff = 0; - } - - if (!(*tif->tif_preencode)(tif, sample)) - return (-1); - tif->tif_flags |= TIFF_POSTENCODE; - } - /* - * Ensure the write is either sequential or at the - * beginning of a strip (or that we can randomly - * access the data -- i.e. no encoding). - */ - if (row != tif->tif_row) { - if (row < tif->tif_row) { - /* - * Moving backwards within the same strip: - * backup to the start and then decode - * forward (below). - */ - tif->tif_row = (strip % td->td_stripsperimage) * - td->td_rowsperstrip; - tif->tif_rawcp = tif->tif_rawdata; - } - /* - * Seek forward to the desired row. - */ - if (!(*tif->tif_seek)(tif, row - tif->tif_row)) - return (-1); - tif->tif_row = row; - } - - /* swab if needed - note that source buffer will be altered */ - tif->tif_postdecode( tif, (uint8*) buf, tif->tif_scanlinesize ); - - status = (*tif->tif_encoderow)(tif, (uint8*) buf, - tif->tif_scanlinesize, sample); - - /* we are now poised at the beginning of the next row */ - tif->tif_row = row + 1; - return (status); -} - -/* - * Encode the supplied data and write it to the - * specified strip. - * - * NB: Image length must be setup before writing. - */ -tmsize_t -TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc) -{ - static const char module[] = "TIFFWriteEncodedStrip"; - TIFFDirectory *td = &tif->tif_dir; - uint16 sample; - - if (!WRITECHECKSTRIPS(tif, module)) - return ((tmsize_t) -1); - /* - * Check strip array to make sure there's space. - * We don't support dynamically growing files that - * have data organized in separate bitplanes because - * it's too painful. In that case we require that - * the imagelength be set properly before the first - * write (so that the strips array will be fully - * allocated above). - */ - if (strip >= td->td_nstrips) { - if (td->td_planarconfig == PLANARCONFIG_SEPARATE) { - TIFFErrorExt(tif->tif_clientdata, module, - "Can not grow image by strips when using separate planes"); - return ((tmsize_t) -1); - } - if (!TIFFGrowStrips(tif, 1, module)) - return ((tmsize_t) -1); - td->td_stripsperimage = - TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip); - } - /* - * Handle delayed allocation of data buffer. This - * permits it to be sized according to the directory - * info. - */ - if (!BUFFERCHECK(tif)) - return ((tmsize_t) -1); - - tif->tif_flags |= TIFF_BUF4WRITE; - tif->tif_curstrip = strip; - - tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip; - if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { - if (!(*tif->tif_setupencode)(tif)) - return ((tmsize_t) -1); - tif->tif_flags |= TIFF_CODERSETUP; - } - - if( td->td_stripbytecount[strip] > 0 ) - { - /* Make sure that at the first attempt of rewriting the tile, we will have */ - /* more bytes available in the output buffer than the previous byte count, */ - /* so that TIFFAppendToStrip() will detect the overflow when it is called the first */ - /* time if the new compressed tile is bigger than the older one. (GDAL #4771) */ - if( tif->tif_rawdatasize <= td->td_stripbytecount[strip] ) - { - if( !(TIFFWriteBufferSetup(tif, NULL, - (tmsize_t)TIFFroundup_64((uint64)(td->td_stripbytecount[strip] + 1), 1024))) ) - return ((tmsize_t)(-1)); - } - - /* Force TIFFAppendToStrip() to consider placing data at end - of file. */ - tif->tif_curoff = 0; - } - - tif->tif_rawcc = 0; - tif->tif_rawcp = tif->tif_rawdata; - - tif->tif_flags &= ~TIFF_POSTENCODE; - sample = (uint16)(strip / td->td_stripsperimage); - if (!(*tif->tif_preencode)(tif, sample)) - return ((tmsize_t) -1); - - /* swab if needed - note that source buffer will be altered */ - tif->tif_postdecode( tif, (uint8*) data, cc ); - - if (!(*tif->tif_encodestrip)(tif, (uint8*) data, cc, sample)) - return (0); - if (!(*tif->tif_postencode)(tif)) - return ((tmsize_t) -1); - if (!isFillOrder(tif, td->td_fillorder) && - (tif->tif_flags & TIFF_NOBITREV) == 0) - TIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc); - if (tif->tif_rawcc > 0 && - !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc)) - return ((tmsize_t) -1); - tif->tif_rawcc = 0; - tif->tif_rawcp = tif->tif_rawdata; - return (cc); -} - -/* - * Write the supplied data to the specified strip. - * - * NB: Image length must be setup before writing. - */ -tmsize_t -TIFFWriteRawStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc) -{ - static const char module[] = "TIFFWriteRawStrip"; - TIFFDirectory *td = &tif->tif_dir; - - if (!WRITECHECKSTRIPS(tif, module)) - return ((tmsize_t) -1); - /* - * Check strip array to make sure there's space. - * We don't support dynamically growing files that - * have data organized in separate bitplanes because - * it's too painful. In that case we require that - * the imagelength be set properly before the first - * write (so that the strips array will be fully - * allocated above). - */ - if (strip >= td->td_nstrips) { - if (td->td_planarconfig == PLANARCONFIG_SEPARATE) { - TIFFErrorExt(tif->tif_clientdata, module, - "Can not grow image by strips when using separate planes"); - return ((tmsize_t) -1); - } - /* - * Watch out for a growing image. The value of - * strips/image will initially be 1 (since it - * can't be deduced until the imagelength is known). - */ - if (strip >= td->td_stripsperimage) - td->td_stripsperimage = - TIFFhowmany_32(td->td_imagelength,td->td_rowsperstrip); - if (!TIFFGrowStrips(tif, 1, module)) - return ((tmsize_t) -1); - } - tif->tif_curstrip = strip; - tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip; - return (TIFFAppendToStrip(tif, strip, (uint8*) data, cc) ? - cc : (tmsize_t) -1); -} - -/* - * Write and compress a tile of data. The - * tile is selected by the (x,y,z,s) coordinates. - */ -tmsize_t -TIFFWriteTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s) -{ - if (!TIFFCheckTile(tif, x, y, z, s)) - return ((tmsize_t)(-1)); - /* - * NB: A tile size of -1 is used instead of tif_tilesize knowing - * that TIFFWriteEncodedTile will clamp this to the tile size. - * This is done because the tile size may not be defined until - * after the output buffer is setup in TIFFWriteBufferSetup. - */ - return (TIFFWriteEncodedTile(tif, - TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1))); -} - -/* - * Encode the supplied data and write it to the - * specified tile. There must be space for the - * data. The function clamps individual writes - * to a tile to the tile size, but does not (and - * can not) check that multiple writes to the same - * tile do not write more than tile size data. - * - * NB: Image length must be setup before writing; this - * interface does not support automatically growing - * the image on each write (as TIFFWriteScanline does). - */ -tmsize_t -TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc) -{ - static const char module[] = "TIFFWriteEncodedTile"; - TIFFDirectory *td; - uint16 sample; - - if (!WRITECHECKTILES(tif, module)) - return ((tmsize_t)(-1)); - td = &tif->tif_dir; - if (tile >= td->td_nstrips) { - TIFFErrorExt(tif->tif_clientdata, module, "Tile %lu out of range, max %lu", - (unsigned long) tile, (unsigned long) td->td_nstrips); - return ((tmsize_t)(-1)); - } - /* - * Handle delayed allocation of data buffer. This - * permits it to be sized more intelligently (using - * directory information). - */ - if (!BUFFERCHECK(tif)) - return ((tmsize_t)(-1)); - - tif->tif_flags |= TIFF_BUF4WRITE; - tif->tif_curtile = tile; - - if( td->td_stripbytecount[tile] > 0 ) - { - /* Make sure that at the first attempt of rewriting the tile, we will have */ - /* more bytes available in the output buffer than the previous byte count, */ - /* so that TIFFAppendToStrip() will detect the overflow when it is called the first */ - /* time if the new compressed tile is bigger than the older one. (GDAL #4771) */ - if( tif->tif_rawdatasize <= td->td_stripbytecount[tile] ) - { - if( !(TIFFWriteBufferSetup(tif, NULL, - (tmsize_t)TIFFroundup_64((uint64)(td->td_stripbytecount[tile] + 1), 1024))) ) - return ((tmsize_t)(-1)); - } - - /* Force TIFFAppendToStrip() to consider placing data at end - of file. */ - tif->tif_curoff = 0; - } - - tif->tif_rawcc = 0; - tif->tif_rawcp = tif->tif_rawdata; - - /* - * Compute tiles per row & per column to compute - * current row and column - */ - tif->tif_row = (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) - * td->td_tilelength; - tif->tif_col = (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) - * td->td_tilewidth; - - if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { - if (!(*tif->tif_setupencode)(tif)) - return ((tmsize_t)(-1)); - tif->tif_flags |= TIFF_CODERSETUP; - } - tif->tif_flags &= ~TIFF_POSTENCODE; - sample = (uint16)(tile/td->td_stripsperimage); - if (!(*tif->tif_preencode)(tif, sample)) - return ((tmsize_t)(-1)); - /* - * Clamp write amount to the tile size. This is mostly - * done so that callers can pass in some large number - * (e.g. -1) and have the tile size used instead. - */ - if ( cc < 1 || cc > tif->tif_tilesize) - cc = tif->tif_tilesize; - - /* swab if needed - note that source buffer will be altered */ - tif->tif_postdecode( tif, (uint8*) data, cc ); - - if (!(*tif->tif_encodetile)(tif, (uint8*) data, cc, sample)) - return (0); - if (!(*tif->tif_postencode)(tif)) - return ((tmsize_t)(-1)); - if (!isFillOrder(tif, td->td_fillorder) && - (tif->tif_flags & TIFF_NOBITREV) == 0) - TIFFReverseBits((uint8*)tif->tif_rawdata, tif->tif_rawcc); - if (tif->tif_rawcc > 0 && !TIFFAppendToStrip(tif, tile, - tif->tif_rawdata, tif->tif_rawcc)) - return ((tmsize_t)(-1)); - tif->tif_rawcc = 0; - tif->tif_rawcp = tif->tif_rawdata; - return (cc); -} - -/* - * Write the supplied data to the specified strip. - * There must be space for the data; we don't check - * if strips overlap! - * - * NB: Image length must be setup before writing; this - * interface does not support automatically growing - * the image on each write (as TIFFWriteScanline does). - */ -tmsize_t -TIFFWriteRawTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc) -{ - static const char module[] = "TIFFWriteRawTile"; - - if (!WRITECHECKTILES(tif, module)) - return ((tmsize_t)(-1)); - if (tile >= tif->tif_dir.td_nstrips) { - TIFFErrorExt(tif->tif_clientdata, module, "Tile %lu out of range, max %lu", - (unsigned long) tile, - (unsigned long) tif->tif_dir.td_nstrips); - return ((tmsize_t)(-1)); - } - return (TIFFAppendToStrip(tif, tile, (uint8*) data, cc) ? - cc : (tmsize_t)(-1)); -} - -#define isUnspecified(tif, f) \ - (TIFFFieldSet(tif,f) && (tif)->tif_dir.td_imagelength == 0) - -int -TIFFSetupStrips(TIFF* tif) -{ - TIFFDirectory* td = &tif->tif_dir; - - if (isTiled(tif)) - td->td_stripsperimage = - isUnspecified(tif, FIELD_TILEDIMENSIONS) ? - td->td_samplesperpixel : TIFFNumberOfTiles(tif); - else - td->td_stripsperimage = - isUnspecified(tif, FIELD_ROWSPERSTRIP) ? - td->td_samplesperpixel : TIFFNumberOfStrips(tif); - td->td_nstrips = td->td_stripsperimage; - if (td->td_planarconfig == PLANARCONFIG_SEPARATE) - td->td_stripsperimage /= td->td_samplesperpixel; - td->td_stripoffset = (uint64 *) - _TIFFmalloc(td->td_nstrips * sizeof (uint64)); - td->td_stripbytecount = (uint64 *) - _TIFFmalloc(td->td_nstrips * sizeof (uint64)); - if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL) - return (0); - /* - * Place data at the end-of-file - * (by setting offsets to zero). - */ - _TIFFmemset(td->td_stripoffset, 0, td->td_nstrips*sizeof (uint64)); - _TIFFmemset(td->td_stripbytecount, 0, td->td_nstrips*sizeof (uint64)); - TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS); - TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS); - return (1); -} -#undef isUnspecified - -/* - * Verify file is writable and that the directory - * information is setup properly. In doing the latter - * we also "freeze" the state of the directory so - * that important information is not changed. - */ -int -TIFFWriteCheck(TIFF* tif, int tiles, const char* module) -{ - if (tif->tif_mode == O_RDONLY) { - TIFFErrorExt(tif->tif_clientdata, module, "File not open for writing"); - return (0); - } - if (tiles ^ isTiled(tif)) { - TIFFErrorExt(tif->tif_clientdata, module, tiles ? - "Can not write tiles to a stripped image" : - "Can not write scanlines to a tiled image"); - return (0); - } - - _TIFFFillStriles( tif ); - - /* - * On the first write verify all the required information - * has been setup and initialize any data structures that - * had to wait until directory information was set. - * Note that a lot of our work is assumed to remain valid - * because we disallow any of the important parameters - * from changing after we start writing (i.e. once - * TIFF_BEENWRITING is set, TIFFSetField will only allow - * the image's length to be changed). - */ - if (!TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Must set \"ImageWidth\" before writing data"); - return (0); - } - if (tif->tif_dir.td_samplesperpixel == 1) { - /* - * Planarconfiguration is irrelevant in case of single band - * images and need not be included. We will set it anyway, - * because this field is used in other parts of library even - * in the single band case. - */ - if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) - tif->tif_dir.td_planarconfig = PLANARCONFIG_CONTIG; - } else { - if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) { - TIFFErrorExt(tif->tif_clientdata, module, - "Must set \"PlanarConfiguration\" before writing data"); - return (0); - } - } - if (tif->tif_dir.td_stripoffset == NULL && !TIFFSetupStrips(tif)) { - tif->tif_dir.td_nstrips = 0; - TIFFErrorExt(tif->tif_clientdata, module, "No space for %s arrays", - isTiled(tif) ? "tile" : "strip"); - return (0); - } - if (isTiled(tif)) - { - tif->tif_tilesize = TIFFTileSize(tif); - if (tif->tif_tilesize == 0) - return (0); - } - else - tif->tif_tilesize = (tmsize_t)(-1); - tif->tif_scanlinesize = TIFFScanlineSize(tif); - if (tif->tif_scanlinesize == 0) - return (0); - tif->tif_flags |= TIFF_BEENWRITING; - return (1); -} - -/* - * Setup the raw data buffer used for encoding. - */ -int -TIFFWriteBufferSetup(TIFF* tif, void* bp, tmsize_t size) -{ - static const char module[] = "TIFFWriteBufferSetup"; - - if (tif->tif_rawdata) { - if (tif->tif_flags & TIFF_MYBUFFER) { - _TIFFfree(tif->tif_rawdata); - tif->tif_flags &= ~TIFF_MYBUFFER; - } - tif->tif_rawdata = NULL; - } - if (size == (tmsize_t)(-1)) { - size = (isTiled(tif) ? - tif->tif_tilesize : TIFFStripSize(tif)); - /* - * Make raw data buffer at least 8K - */ - if (size < 8*1024) - size = 8*1024; - bp = NULL; /* NB: force malloc */ - } - if (bp == NULL) { - bp = _TIFFmalloc(size); - if (bp == NULL) { - TIFFErrorExt(tif->tif_clientdata, module, "No space for output buffer"); - return (0); - } - tif->tif_flags |= TIFF_MYBUFFER; - } else - tif->tif_flags &= ~TIFF_MYBUFFER; - tif->tif_rawdata = (uint8*) bp; - tif->tif_rawdatasize = size; - tif->tif_rawcc = 0; - tif->tif_rawcp = tif->tif_rawdata; - tif->tif_flags |= TIFF_BUFFERSETUP; - return (1); -} - -/* - * Grow the strip data structures by delta strips. - */ -static int -TIFFGrowStrips(TIFF* tif, uint32 delta, const char* module) -{ - TIFFDirectory *td = &tif->tif_dir; - uint64* new_stripoffset; - uint64* new_stripbytecount; - - assert(td->td_planarconfig == PLANARCONFIG_CONTIG); - new_stripoffset = (uint64*)_TIFFrealloc(td->td_stripoffset, - (td->td_nstrips + delta) * sizeof (uint64)); - new_stripbytecount = (uint64*)_TIFFrealloc(td->td_stripbytecount, - (td->td_nstrips + delta) * sizeof (uint64)); - if (new_stripoffset == NULL || new_stripbytecount == NULL) { - if (new_stripoffset) - _TIFFfree(new_stripoffset); - if (new_stripbytecount) - _TIFFfree(new_stripbytecount); - td->td_nstrips = 0; - TIFFErrorExt(tif->tif_clientdata, module, "No space to expand strip arrays"); - return (0); - } - td->td_stripoffset = new_stripoffset; - td->td_stripbytecount = new_stripbytecount; - _TIFFmemset(td->td_stripoffset + td->td_nstrips, - 0, delta*sizeof (uint64)); - _TIFFmemset(td->td_stripbytecount + td->td_nstrips, - 0, delta*sizeof (uint64)); - td->td_nstrips += delta; - tif->tif_flags |= TIFF_DIRTYDIRECT; - - return (1); -} - -/* - * Append the data to the specified strip. - */ -static int -TIFFAppendToStrip(TIFF* tif, uint32 strip, uint8* data, tmsize_t cc) -{ - static const char module[] = "TIFFAppendToStrip"; - TIFFDirectory *td = &tif->tif_dir; - uint64 m; - int64 old_byte_count = -1; - - if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) { - assert(td->td_nstrips > 0); - - if( td->td_stripbytecount[strip] != 0 - && td->td_stripoffset[strip] != 0 - && td->td_stripbytecount[strip] >= (uint64) cc ) - { - /* - * There is already tile data on disk, and the new tile - * data we have will fit in the same space. The only - * aspect of this that is risky is that there could be - * more data to append to this strip before we are done - * depending on how we are getting called. - */ - if (!SeekOK(tif, td->td_stripoffset[strip])) { - TIFFErrorExt(tif->tif_clientdata, module, - "Seek error at scanline %lu", - (unsigned long)tif->tif_row); - return (0); - } - } - else - { - /* - * Seek to end of file, and set that as our location to - * write this strip. - */ - td->td_stripoffset[strip] = TIFFSeekFile(tif, 0, SEEK_END); - tif->tif_flags |= TIFF_DIRTYSTRIP; - } - - tif->tif_curoff = td->td_stripoffset[strip]; - - /* - * We are starting a fresh strip/tile, so set the size to zero. - */ - old_byte_count = td->td_stripbytecount[strip]; - td->td_stripbytecount[strip] = 0; - } - - m = tif->tif_curoff+cc; - if (!(tif->tif_flags&TIFF_BIGTIFF)) - m = (uint32)m; - if ((mtif_curoff)||(m<(uint64)cc)) - { - TIFFErrorExt(tif->tif_clientdata, module, "Maximum TIFF file size exceeded"); - return (0); - } - if (!WriteOK(tif, data, cc)) { - TIFFErrorExt(tif->tif_clientdata, module, "Write error at scanline %lu", - (unsigned long) tif->tif_row); - return (0); - } - tif->tif_curoff = m; - td->td_stripbytecount[strip] += cc; - - if( (int64) td->td_stripbytecount[strip] != old_byte_count ) - tif->tif_flags |= TIFF_DIRTYSTRIP; - - return (1); -} - -/* - * Internal version of TIFFFlushData that can be - * called by ``encodestrip routines'' w/o concern - * for infinite recursion. - */ -int -TIFFFlushData1(TIFF* tif) -{ - if (tif->tif_rawcc > 0 && tif->tif_flags & TIFF_BUF4WRITE ) { - if (!isFillOrder(tif, tif->tif_dir.td_fillorder) && - (tif->tif_flags & TIFF_NOBITREV) == 0) - TIFFReverseBits((uint8*)tif->tif_rawdata, - tif->tif_rawcc); - if (!TIFFAppendToStrip(tif, - isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip, - tif->tif_rawdata, tif->tif_rawcc)) - return (0); - tif->tif_rawcc = 0; - tif->tif_rawcp = tif->tif_rawdata; - } - return (1); -} - -/* - * Set the current write offset. This should only be - * used to set the offset to a known previous location - * (very carefully), or to 0 so that the next write gets - * appended to the end of the file. - */ -void -TIFFSetWriteOffset(TIFF* tif, toff_t off) -{ - tif->tif_curoff = off; -} - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_write.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library. + * + * Scanline-oriented Write Support + */ +#include "tiffiop.h" +#include + +#define STRIPINCR 20 /* expansion factor on strip array */ + +#define WRITECHECKSTRIPS(tif, module) \ + (((tif)->tif_flags&TIFF_BEENWRITING) || TIFFWriteCheck((tif),0,module)) +#define WRITECHECKTILES(tif, module) \ + (((tif)->tif_flags&TIFF_BEENWRITING) || TIFFWriteCheck((tif),1,module)) +#define BUFFERCHECK(tif) \ + ((((tif)->tif_flags & TIFF_BUFFERSETUP) && tif->tif_rawdata) || \ + TIFFWriteBufferSetup((tif), NULL, (tmsize_t) -1)) + +static int TIFFGrowStrips(TIFF* tif, uint32 delta, const char* module); +static int TIFFAppendToStrip(TIFF* tif, uint32 strip, uint8* data, tmsize_t cc); + +int +TIFFWriteScanline(TIFF* tif, void* buf, uint32 row, uint16 sample) +{ + static const char module[] = "TIFFWriteScanline"; + register TIFFDirectory *td; + int status, imagegrew = 0; + uint32 strip; + + if (!WRITECHECKSTRIPS(tif, module)) + return (-1); + /* + * Handle delayed allocation of data buffer. This + * permits it to be sized more intelligently (using + * directory information). + */ + if (!BUFFERCHECK(tif)) + return (-1); + tif->tif_flags |= TIFF_BUF4WRITE; /* not strictly sure this is right*/ + + td = &tif->tif_dir; + /* + * Extend image length if needed + * (but only for PlanarConfig=1). + */ + if (row >= td->td_imagelength) { /* extend image */ + if (td->td_planarconfig == PLANARCONFIG_SEPARATE) { + TIFFErrorExt(tif->tif_clientdata, module, + "Can not change \"ImageLength\" when using separate planes"); + return (-1); + } + td->td_imagelength = row+1; + imagegrew = 1; + } + /* + * Calculate strip and check for crossings. + */ + if (td->td_planarconfig == PLANARCONFIG_SEPARATE) { + if (sample >= td->td_samplesperpixel) { + TIFFErrorExt(tif->tif_clientdata, module, + "%lu: Sample out of range, max %lu", + (unsigned long) sample, (unsigned long) td->td_samplesperpixel); + return (-1); + } + strip = sample*td->td_stripsperimage + row/td->td_rowsperstrip; + } else + strip = row / td->td_rowsperstrip; + /* + * Check strip array to make sure there's space. We don't support + * dynamically growing files that have data organized in separate + * bitplanes because it's too painful. In that case we require that + * the imagelength be set properly before the first write (so that the + * strips array will be fully allocated above). + */ + if (strip >= td->td_nstrips && !TIFFGrowStrips(tif, 1, module)) + return (-1); + if (strip != tif->tif_curstrip) { + /* + * Changing strips -- flush any data present. + */ + if (!TIFFFlushData(tif)) + return (-1); + tif->tif_curstrip = strip; + /* + * Watch out for a growing image. The value of strips/image + * will initially be 1 (since it can't be deduced until the + * imagelength is known). + */ + if (strip >= td->td_stripsperimage && imagegrew) + td->td_stripsperimage = + TIFFhowmany_32(td->td_imagelength,td->td_rowsperstrip); + tif->tif_row = + (strip % td->td_stripsperimage) * td->td_rowsperstrip; + if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { + if (!(*tif->tif_setupencode)(tif)) + return (-1); + tif->tif_flags |= TIFF_CODERSETUP; + } + + tif->tif_rawcc = 0; + tif->tif_rawcp = tif->tif_rawdata; + + if( td->td_stripbytecount[strip] > 0 ) + { + /* if we are writing over existing tiles, zero length */ + td->td_stripbytecount[strip] = 0; + + /* this forces TIFFAppendToStrip() to do a seek */ + tif->tif_curoff = 0; + } + + if (!(*tif->tif_preencode)(tif, sample)) + return (-1); + tif->tif_flags |= TIFF_POSTENCODE; + } + /* + * Ensure the write is either sequential or at the + * beginning of a strip (or that we can randomly + * access the data -- i.e. no encoding). + */ + if (row != tif->tif_row) { + if (row < tif->tif_row) { + /* + * Moving backwards within the same strip: + * backup to the start and then decode + * forward (below). + */ + tif->tif_row = (strip % td->td_stripsperimage) * + td->td_rowsperstrip; + tif->tif_rawcp = tif->tif_rawdata; + } + /* + * Seek forward to the desired row. + */ + if (!(*tif->tif_seek)(tif, row - tif->tif_row)) + return (-1); + tif->tif_row = row; + } + + /* swab if needed - note that source buffer will be altered */ + tif->tif_postdecode( tif, (uint8*) buf, tif->tif_scanlinesize ); + + status = (*tif->tif_encoderow)(tif, (uint8*) buf, + tif->tif_scanlinesize, sample); + + /* we are now poised at the beginning of the next row */ + tif->tif_row = row + 1; + return (status); +} + +/* + * Encode the supplied data and write it to the + * specified strip. + * + * NB: Image length must be setup before writing. + */ +tmsize_t +TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc) +{ + static const char module[] = "TIFFWriteEncodedStrip"; + TIFFDirectory *td = &tif->tif_dir; + uint16 sample; + + if (!WRITECHECKSTRIPS(tif, module)) + return ((tmsize_t) -1); + /* + * Check strip array to make sure there's space. + * We don't support dynamically growing files that + * have data organized in separate bitplanes because + * it's too painful. In that case we require that + * the imagelength be set properly before the first + * write (so that the strips array will be fully + * allocated above). + */ + if (strip >= td->td_nstrips) { + if (td->td_planarconfig == PLANARCONFIG_SEPARATE) { + TIFFErrorExt(tif->tif_clientdata, module, + "Can not grow image by strips when using separate planes"); + return ((tmsize_t) -1); + } + if (!TIFFGrowStrips(tif, 1, module)) + return ((tmsize_t) -1); + td->td_stripsperimage = + TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip); + } + /* + * Handle delayed allocation of data buffer. This + * permits it to be sized according to the directory + * info. + */ + if (!BUFFERCHECK(tif)) + return ((tmsize_t) -1); + + tif->tif_flags |= TIFF_BUF4WRITE; + tif->tif_curstrip = strip; + + tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip; + if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { + if (!(*tif->tif_setupencode)(tif)) + return ((tmsize_t) -1); + tif->tif_flags |= TIFF_CODERSETUP; + } + + if( td->td_stripbytecount[strip] > 0 ) + { + /* Make sure that at the first attempt of rewriting the tile, we will have */ + /* more bytes available in the output buffer than the previous byte count, */ + /* so that TIFFAppendToStrip() will detect the overflow when it is called the first */ + /* time if the new compressed tile is bigger than the older one. (GDAL #4771) */ + if( tif->tif_rawdatasize <= td->td_stripbytecount[strip] ) + { + if( !(TIFFWriteBufferSetup(tif, NULL, + (tmsize_t)TIFFroundup_64((uint64)(td->td_stripbytecount[strip] + 1), 1024))) ) + return ((tmsize_t)(-1)); + } + + /* Force TIFFAppendToStrip() to consider placing data at end + of file. */ + tif->tif_curoff = 0; + } + + tif->tif_rawcc = 0; + tif->tif_rawcp = tif->tif_rawdata; + + tif->tif_flags &= ~TIFF_POSTENCODE; + sample = (uint16)(strip / td->td_stripsperimage); + if (!(*tif->tif_preencode)(tif, sample)) + return ((tmsize_t) -1); + + /* swab if needed - note that source buffer will be altered */ + tif->tif_postdecode( tif, (uint8*) data, cc ); + + if (!(*tif->tif_encodestrip)(tif, (uint8*) data, cc, sample)) + return (0); + if (!(*tif->tif_postencode)(tif)) + return ((tmsize_t) -1); + if (!isFillOrder(tif, td->td_fillorder) && + (tif->tif_flags & TIFF_NOBITREV) == 0) + TIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc); + if (tif->tif_rawcc > 0 && + !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc)) + return ((tmsize_t) -1); + tif->tif_rawcc = 0; + tif->tif_rawcp = tif->tif_rawdata; + return (cc); +} + +/* + * Write the supplied data to the specified strip. + * + * NB: Image length must be setup before writing. + */ +tmsize_t +TIFFWriteRawStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc) +{ + static const char module[] = "TIFFWriteRawStrip"; + TIFFDirectory *td = &tif->tif_dir; + + if (!WRITECHECKSTRIPS(tif, module)) + return ((tmsize_t) -1); + /* + * Check strip array to make sure there's space. + * We don't support dynamically growing files that + * have data organized in separate bitplanes because + * it's too painful. In that case we require that + * the imagelength be set properly before the first + * write (so that the strips array will be fully + * allocated above). + */ + if (strip >= td->td_nstrips) { + if (td->td_planarconfig == PLANARCONFIG_SEPARATE) { + TIFFErrorExt(tif->tif_clientdata, module, + "Can not grow image by strips when using separate planes"); + return ((tmsize_t) -1); + } + /* + * Watch out for a growing image. The value of + * strips/image will initially be 1 (since it + * can't be deduced until the imagelength is known). + */ + if (strip >= td->td_stripsperimage) + td->td_stripsperimage = + TIFFhowmany_32(td->td_imagelength,td->td_rowsperstrip); + if (!TIFFGrowStrips(tif, 1, module)) + return ((tmsize_t) -1); + } + tif->tif_curstrip = strip; + tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip; + return (TIFFAppendToStrip(tif, strip, (uint8*) data, cc) ? + cc : (tmsize_t) -1); +} + +/* + * Write and compress a tile of data. The + * tile is selected by the (x,y,z,s) coordinates. + */ +tmsize_t +TIFFWriteTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s) +{ + if (!TIFFCheckTile(tif, x, y, z, s)) + return ((tmsize_t)(-1)); + /* + * NB: A tile size of -1 is used instead of tif_tilesize knowing + * that TIFFWriteEncodedTile will clamp this to the tile size. + * This is done because the tile size may not be defined until + * after the output buffer is setup in TIFFWriteBufferSetup. + */ + return (TIFFWriteEncodedTile(tif, + TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1))); +} + +/* + * Encode the supplied data and write it to the + * specified tile. There must be space for the + * data. The function clamps individual writes + * to a tile to the tile size, but does not (and + * can not) check that multiple writes to the same + * tile do not write more than tile size data. + * + * NB: Image length must be setup before writing; this + * interface does not support automatically growing + * the image on each write (as TIFFWriteScanline does). + */ +tmsize_t +TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc) +{ + static const char module[] = "TIFFWriteEncodedTile"; + TIFFDirectory *td; + uint16 sample; + + if (!WRITECHECKTILES(tif, module)) + return ((tmsize_t)(-1)); + td = &tif->tif_dir; + if (tile >= td->td_nstrips) { + TIFFErrorExt(tif->tif_clientdata, module, "Tile %lu out of range, max %lu", + (unsigned long) tile, (unsigned long) td->td_nstrips); + return ((tmsize_t)(-1)); + } + /* + * Handle delayed allocation of data buffer. This + * permits it to be sized more intelligently (using + * directory information). + */ + if (!BUFFERCHECK(tif)) + return ((tmsize_t)(-1)); + + tif->tif_flags |= TIFF_BUF4WRITE; + tif->tif_curtile = tile; + + if( td->td_stripbytecount[tile] > 0 ) + { + /* Make sure that at the first attempt of rewriting the tile, we will have */ + /* more bytes available in the output buffer than the previous byte count, */ + /* so that TIFFAppendToStrip() will detect the overflow when it is called the first */ + /* time if the new compressed tile is bigger than the older one. (GDAL #4771) */ + if( tif->tif_rawdatasize <= td->td_stripbytecount[tile] ) + { + if( !(TIFFWriteBufferSetup(tif, NULL, + (tmsize_t)TIFFroundup_64((uint64)(td->td_stripbytecount[tile] + 1), 1024))) ) + return ((tmsize_t)(-1)); + } + + /* Force TIFFAppendToStrip() to consider placing data at end + of file. */ + tif->tif_curoff = 0; + } + + tif->tif_rawcc = 0; + tif->tif_rawcp = tif->tif_rawdata; + + /* + * Compute tiles per row & per column to compute + * current row and column + */ + tif->tif_row = (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) + * td->td_tilelength; + tif->tif_col = (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) + * td->td_tilewidth; + + if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { + if (!(*tif->tif_setupencode)(tif)) + return ((tmsize_t)(-1)); + tif->tif_flags |= TIFF_CODERSETUP; + } + tif->tif_flags &= ~TIFF_POSTENCODE; + sample = (uint16)(tile/td->td_stripsperimage); + if (!(*tif->tif_preencode)(tif, sample)) + return ((tmsize_t)(-1)); + /* + * Clamp write amount to the tile size. This is mostly + * done so that callers can pass in some large number + * (e.g. -1) and have the tile size used instead. + */ + if ( cc < 1 || cc > tif->tif_tilesize) + cc = tif->tif_tilesize; + + /* swab if needed - note that source buffer will be altered */ + tif->tif_postdecode( tif, (uint8*) data, cc ); + + if (!(*tif->tif_encodetile)(tif, (uint8*) data, cc, sample)) + return (0); + if (!(*tif->tif_postencode)(tif)) + return ((tmsize_t)(-1)); + if (!isFillOrder(tif, td->td_fillorder) && + (tif->tif_flags & TIFF_NOBITREV) == 0) + TIFFReverseBits((uint8*)tif->tif_rawdata, tif->tif_rawcc); + if (tif->tif_rawcc > 0 && !TIFFAppendToStrip(tif, tile, + tif->tif_rawdata, tif->tif_rawcc)) + return ((tmsize_t)(-1)); + tif->tif_rawcc = 0; + tif->tif_rawcp = tif->tif_rawdata; + return (cc); +} + +/* + * Write the supplied data to the specified strip. + * There must be space for the data; we don't check + * if strips overlap! + * + * NB: Image length must be setup before writing; this + * interface does not support automatically growing + * the image on each write (as TIFFWriteScanline does). + */ +tmsize_t +TIFFWriteRawTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc) +{ + static const char module[] = "TIFFWriteRawTile"; + + if (!WRITECHECKTILES(tif, module)) + return ((tmsize_t)(-1)); + if (tile >= tif->tif_dir.td_nstrips) { + TIFFErrorExt(tif->tif_clientdata, module, "Tile %lu out of range, max %lu", + (unsigned long) tile, + (unsigned long) tif->tif_dir.td_nstrips); + return ((tmsize_t)(-1)); + } + return (TIFFAppendToStrip(tif, tile, (uint8*) data, cc) ? + cc : (tmsize_t)(-1)); +} + +#define isUnspecified(tif, f) \ + (TIFFFieldSet(tif,f) && (tif)->tif_dir.td_imagelength == 0) + +int +TIFFSetupStrips(TIFF* tif) +{ + TIFFDirectory* td = &tif->tif_dir; + + if (isTiled(tif)) + td->td_stripsperimage = + isUnspecified(tif, FIELD_TILEDIMENSIONS) ? + td->td_samplesperpixel : TIFFNumberOfTiles(tif); + else + td->td_stripsperimage = + isUnspecified(tif, FIELD_ROWSPERSTRIP) ? + td->td_samplesperpixel : TIFFNumberOfStrips(tif); + td->td_nstrips = td->td_stripsperimage; + if (td->td_planarconfig == PLANARCONFIG_SEPARATE) + td->td_stripsperimage /= td->td_samplesperpixel; + td->td_stripoffset = (uint64 *) + _TIFFmalloc(td->td_nstrips * sizeof (uint64)); + td->td_stripbytecount = (uint64 *) + _TIFFmalloc(td->td_nstrips * sizeof (uint64)); + if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL) + return (0); + /* + * Place data at the end-of-file + * (by setting offsets to zero). + */ + _TIFFmemset(td->td_stripoffset, 0, td->td_nstrips*sizeof (uint64)); + _TIFFmemset(td->td_stripbytecount, 0, td->td_nstrips*sizeof (uint64)); + TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS); + TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS); + return (1); +} +#undef isUnspecified + +/* + * Verify file is writable and that the directory + * information is setup properly. In doing the latter + * we also "freeze" the state of the directory so + * that important information is not changed. + */ +int +TIFFWriteCheck(TIFF* tif, int tiles, const char* module) +{ + if (tif->tif_mode == O_RDONLY) { + TIFFErrorExt(tif->tif_clientdata, module, "File not open for writing"); + return (0); + } + if (tiles ^ isTiled(tif)) { + TIFFErrorExt(tif->tif_clientdata, module, tiles ? + "Can not write tiles to a stripped image" : + "Can not write scanlines to a tiled image"); + return (0); + } + + _TIFFFillStriles( tif ); + + /* + * On the first write verify all the required information + * has been setup and initialize any data structures that + * had to wait until directory information was set. + * Note that a lot of our work is assumed to remain valid + * because we disallow any of the important parameters + * from changing after we start writing (i.e. once + * TIFF_BEENWRITING is set, TIFFSetField will only allow + * the image's length to be changed). + */ + if (!TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Must set \"ImageWidth\" before writing data"); + return (0); + } + if (tif->tif_dir.td_samplesperpixel == 1) { + /* + * Planarconfiguration is irrelevant in case of single band + * images and need not be included. We will set it anyway, + * because this field is used in other parts of library even + * in the single band case. + */ + if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) + tif->tif_dir.td_planarconfig = PLANARCONFIG_CONTIG; + } else { + if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Must set \"PlanarConfiguration\" before writing data"); + return (0); + } + } + if (tif->tif_dir.td_stripoffset == NULL && !TIFFSetupStrips(tif)) { + tif->tif_dir.td_nstrips = 0; + TIFFErrorExt(tif->tif_clientdata, module, "No space for %s arrays", + isTiled(tif) ? "tile" : "strip"); + return (0); + } + if (isTiled(tif)) + { + tif->tif_tilesize = TIFFTileSize(tif); + if (tif->tif_tilesize == 0) + return (0); + } + else + tif->tif_tilesize = (tmsize_t)(-1); + tif->tif_scanlinesize = TIFFScanlineSize(tif); + if (tif->tif_scanlinesize == 0) + return (0); + tif->tif_flags |= TIFF_BEENWRITING; + return (1); +} + +/* + * Setup the raw data buffer used for encoding. + */ +int +TIFFWriteBufferSetup(TIFF* tif, void* bp, tmsize_t size) +{ + static const char module[] = "TIFFWriteBufferSetup"; + + if (tif->tif_rawdata) { + if (tif->tif_flags & TIFF_MYBUFFER) { + _TIFFfree(tif->tif_rawdata); + tif->tif_flags &= ~TIFF_MYBUFFER; + } + tif->tif_rawdata = NULL; + } + if (size == (tmsize_t)(-1)) { + size = (isTiled(tif) ? + tif->tif_tilesize : TIFFStripSize(tif)); + /* + * Make raw data buffer at least 8K + */ + if (size < 8*1024) + size = 8*1024; + bp = NULL; /* NB: force malloc */ + } + if (bp == NULL) { + bp = _TIFFmalloc(size); + if (bp == NULL) { + TIFFErrorExt(tif->tif_clientdata, module, "No space for output buffer"); + return (0); + } + tif->tif_flags |= TIFF_MYBUFFER; + } else + tif->tif_flags &= ~TIFF_MYBUFFER; + tif->tif_rawdata = (uint8*) bp; + tif->tif_rawdatasize = size; + tif->tif_rawcc = 0; + tif->tif_rawcp = tif->tif_rawdata; + tif->tif_flags |= TIFF_BUFFERSETUP; + return (1); +} + +/* + * Grow the strip data structures by delta strips. + */ +static int +TIFFGrowStrips(TIFF* tif, uint32 delta, const char* module) +{ + TIFFDirectory *td = &tif->tif_dir; + uint64* new_stripoffset; + uint64* new_stripbytecount; + + assert(td->td_planarconfig == PLANARCONFIG_CONTIG); + new_stripoffset = (uint64*)_TIFFrealloc(td->td_stripoffset, + (td->td_nstrips + delta) * sizeof (uint64)); + new_stripbytecount = (uint64*)_TIFFrealloc(td->td_stripbytecount, + (td->td_nstrips + delta) * sizeof (uint64)); + if (new_stripoffset == NULL || new_stripbytecount == NULL) { + if (new_stripoffset) + _TIFFfree(new_stripoffset); + if (new_stripbytecount) + _TIFFfree(new_stripbytecount); + td->td_nstrips = 0; + TIFFErrorExt(tif->tif_clientdata, module, "No space to expand strip arrays"); + return (0); + } + td->td_stripoffset = new_stripoffset; + td->td_stripbytecount = new_stripbytecount; + _TIFFmemset(td->td_stripoffset + td->td_nstrips, + 0, delta*sizeof (uint64)); + _TIFFmemset(td->td_stripbytecount + td->td_nstrips, + 0, delta*sizeof (uint64)); + td->td_nstrips += delta; + tif->tif_flags |= TIFF_DIRTYDIRECT; + + return (1); +} + +/* + * Append the data to the specified strip. + */ +static int +TIFFAppendToStrip(TIFF* tif, uint32 strip, uint8* data, tmsize_t cc) +{ + static const char module[] = "TIFFAppendToStrip"; + TIFFDirectory *td = &tif->tif_dir; + uint64 m; + int64 old_byte_count = -1; + + if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) { + assert(td->td_nstrips > 0); + + if( td->td_stripbytecount[strip] != 0 + && td->td_stripoffset[strip] != 0 + && td->td_stripbytecount[strip] >= (uint64) cc ) + { + /* + * There is already tile data on disk, and the new tile + * data we have will fit in the same space. The only + * aspect of this that is risky is that there could be + * more data to append to this strip before we are done + * depending on how we are getting called. + */ + if (!SeekOK(tif, td->td_stripoffset[strip])) { + TIFFErrorExt(tif->tif_clientdata, module, + "Seek error at scanline %lu", + (unsigned long)tif->tif_row); + return (0); + } + } + else + { + /* + * Seek to end of file, and set that as our location to + * write this strip. + */ + td->td_stripoffset[strip] = TIFFSeekFile(tif, 0, SEEK_END); + tif->tif_flags |= TIFF_DIRTYSTRIP; + } + + tif->tif_curoff = td->td_stripoffset[strip]; + + /* + * We are starting a fresh strip/tile, so set the size to zero. + */ + old_byte_count = td->td_stripbytecount[strip]; + td->td_stripbytecount[strip] = 0; + } + + m = tif->tif_curoff+cc; + if (!(tif->tif_flags&TIFF_BIGTIFF)) + m = (uint32)m; + if ((mtif_curoff)||(m<(uint64)cc)) + { + TIFFErrorExt(tif->tif_clientdata, module, "Maximum TIFF file size exceeded"); + return (0); + } + if (!WriteOK(tif, data, cc)) { + TIFFErrorExt(tif->tif_clientdata, module, "Write error at scanline %lu", + (unsigned long) tif->tif_row); + return (0); + } + tif->tif_curoff = m; + td->td_stripbytecount[strip] += cc; + + if( (int64) td->td_stripbytecount[strip] != old_byte_count ) + tif->tif_flags |= TIFF_DIRTYSTRIP; + + return (1); +} + +/* + * Internal version of TIFFFlushData that can be + * called by ``encodestrip routines'' w/o concern + * for infinite recursion. + */ +int +TIFFFlushData1(TIFF* tif) +{ + if (tif->tif_rawcc > 0 && tif->tif_flags & TIFF_BUF4WRITE ) { + if (!isFillOrder(tif, tif->tif_dir.td_fillorder) && + (tif->tif_flags & TIFF_NOBITREV) == 0) + TIFFReverseBits((uint8*)tif->tif_rawdata, + tif->tif_rawcc); + if (!TIFFAppendToStrip(tif, + isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip, + tif->tif_rawdata, tif->tif_rawcc)) + return (0); + tif->tif_rawcc = 0; + tif->tif_rawcp = tif->tif_rawdata; + } + return (1); +} + +/* + * Set the current write offset. This should only be + * used to set the offset to a known previous location + * (very carefully), or to 0 so that the next write gets + * appended to the end of the file. + */ +void +TIFFSetWriteOffset(TIFF* tif, toff_t off) +{ + tif->tif_curoff = off; +} + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tif_zip.c b/Source/LibTIFF4/tif_zip.c index a975d2c..eda87a4 100644 --- a/Source/LibTIFF4/tif_zip.c +++ b/Source/LibTIFF4/tif_zip.c @@ -1,469 +1,469 @@ -/* $Id: tif_zip.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1995-1997 Sam Leffler - * Copyright (c) 1995-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "tiffiop.h" -#ifdef ZIP_SUPPORT -/* - * TIFF Library. - * - * ZIP (aka Deflate) Compression Support - * - * This file is simply an interface to the zlib library written by - * Jean-loup Gailly and Mark Adler. You must use version 1.0 or later - * of the library: this code assumes the 1.0 API and also depends on - * the ability to write the zlib header multiple times (one per strip) - * which was not possible with versions prior to 0.95. Note also that - * older versions of this codec avoided this bug by supressing the header - * entirely. This means that files written with the old library cannot - * be read; they should be converted to a different compression scheme - * and then reconverted. - * - * The data format used by the zlib library is described in the files - * zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available in the - * directory ftp://ftp.uu.net/pub/archiving/zip/doc. The library was - * last found at ftp://ftp.uu.net/pub/archiving/zip/zlib/zlib-0.99.tar.gz. - */ -#include "tif_predict.h" -#include "../ZLib/zlib.h" - -#include - -/* - * Sigh, ZLIB_VERSION is defined as a string so there's no - * way to do a proper check here. Instead we guess based - * on the presence of #defines that were added between the - * 0.95 and 1.0 distributions. - */ -#if !defined(Z_NO_COMPRESSION) || !defined(Z_DEFLATED) -#error "Antiquated ZLIB software; you must use version 1.0 or later" -#endif - -/* - * State block for each open TIFF - * file using ZIP compression/decompression. - */ -typedef struct { - TIFFPredictorState predict; - z_stream stream; - int zipquality; /* compression level */ - int state; /* state flags */ -#define ZSTATE_INIT_DECODE 0x01 -#define ZSTATE_INIT_ENCODE 0x02 - - TIFFVGetMethod vgetparent; /* super-class method */ - TIFFVSetMethod vsetparent; /* super-class method */ -} ZIPState; - -#define ZState(tif) ((ZIPState*) (tif)->tif_data) -#define DecoderState(tif) ZState(tif) -#define EncoderState(tif) ZState(tif) - -static int ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s); -static int ZIPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s); - -static int -ZIPFixupTags(TIFF* tif) -{ - (void) tif; - return (1); -} - -static int -ZIPSetupDecode(TIFF* tif) -{ - static const char module[] = "ZIPSetupDecode"; - ZIPState* sp = DecoderState(tif); - - assert(sp != NULL); - - /* if we were last encoding, terminate this mode */ - if (sp->state & ZSTATE_INIT_ENCODE) { - deflateEnd(&sp->stream); - sp->state = 0; - } - - if (inflateInit(&sp->stream) != Z_OK) { - TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg); - return (0); - } else { - sp->state |= ZSTATE_INIT_DECODE; - return (1); - } -} - -/* - * Setup state for decoding a strip. - */ -static int -ZIPPreDecode(TIFF* tif, uint16 s) -{ - static const char module[] = "ZIPPreDecode"; - ZIPState* sp = DecoderState(tif); - - (void) s; - assert(sp != NULL); - - if( (sp->state & ZSTATE_INIT_DECODE) == 0 ) - tif->tif_setupdecode( tif ); - - sp->stream.next_in = tif->tif_rawdata; - assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised, - we need to simplify this code to reflect a ZLib that is likely updated - to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ - sp->stream.avail_in = (uInt) tif->tif_rawcc; - if ((tmsize_t)sp->stream.avail_in != tif->tif_rawcc) - { - TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); - return (0); - } - return (inflateReset(&sp->stream) == Z_OK); -} - -static int -ZIPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) -{ - static const char module[] = "ZIPDecode"; - ZIPState* sp = DecoderState(tif); - - (void) s; - assert(sp != NULL); - assert(sp->state == ZSTATE_INIT_DECODE); - - sp->stream.next_in = tif->tif_rawcp; - sp->stream.avail_in = (uInt) tif->tif_rawcc; - - sp->stream.next_out = op; - assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, - we need to simplify this code to reflect a ZLib that is likely updated - to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ - sp->stream.avail_out = (uInt) occ; - if ((tmsize_t)sp->stream.avail_out != occ) - { - TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); - return (0); - } - do { - int state = inflate(&sp->stream, Z_PARTIAL_FLUSH); - if (state == Z_STREAM_END) - break; - if (state == Z_DATA_ERROR) { - TIFFErrorExt(tif->tif_clientdata, module, - "Decoding error at scanline %lu, %s", - (unsigned long) tif->tif_row, sp->stream.msg); - if (inflateSync(&sp->stream) != Z_OK) - return (0); - continue; - } - if (state != Z_OK) { - TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", - sp->stream.msg); - return (0); - } - } while (sp->stream.avail_out > 0); - if (sp->stream.avail_out != 0) { - TIFFErrorExt(tif->tif_clientdata, module, - "Not enough data at scanline %lu (short " TIFF_UINT64_FORMAT " bytes)", - (unsigned long) tif->tif_row, (TIFF_UINT64_T) sp->stream.avail_out); - return (0); - } - - tif->tif_rawcp = sp->stream.next_in; - tif->tif_rawcc = sp->stream.avail_in; - - return (1); -} - -static int -ZIPSetupEncode(TIFF* tif) -{ - static const char module[] = "ZIPSetupEncode"; - ZIPState* sp = EncoderState(tif); - - assert(sp != NULL); - if (sp->state & ZSTATE_INIT_DECODE) { - inflateEnd(&sp->stream); - sp->state = 0; - } - - if (deflateInit(&sp->stream, sp->zipquality) != Z_OK) { - TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg); - return (0); - } else { - sp->state |= ZSTATE_INIT_ENCODE; - return (1); - } -} - -/* - * Reset encoding state at the start of a strip. - */ -static int -ZIPPreEncode(TIFF* tif, uint16 s) -{ - static const char module[] = "ZIPPreEncode"; - ZIPState *sp = EncoderState(tif); - - (void) s; - assert(sp != NULL); - if( sp->state != ZSTATE_INIT_ENCODE ) - tif->tif_setupencode( tif ); - - sp->stream.next_out = tif->tif_rawdata; - assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, - we need to simplify this code to reflect a ZLib that is likely updated - to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ - sp->stream.avail_out = tif->tif_rawdatasize; - if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) - { - TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); - return (0); - } - return (deflateReset(&sp->stream) == Z_OK); -} - -/* - * Encode a chunk of pixels. - */ -static int -ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) -{ - static const char module[] = "ZIPEncode"; - ZIPState *sp = EncoderState(tif); - - assert(sp != NULL); - assert(sp->state == ZSTATE_INIT_ENCODE); - - (void) s; - sp->stream.next_in = bp; - assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised, - we need to simplify this code to reflect a ZLib that is likely updated - to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ - sp->stream.avail_in = (uInt) cc; - if ((tmsize_t)sp->stream.avail_in != cc) - { - TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); - return (0); - } - do { - if (deflate(&sp->stream, Z_NO_FLUSH) != Z_OK) { - TIFFErrorExt(tif->tif_clientdata, module, "Encoder error: %s", - sp->stream.msg); - return (0); - } - if (sp->stream.avail_out == 0) { - tif->tif_rawcc = tif->tif_rawdatasize; - TIFFFlushData1(tif); - sp->stream.next_out = tif->tif_rawdata; - sp->stream.avail_out = (uInt) tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in ZIPPreEncode */ - } - } while (sp->stream.avail_in > 0); - return (1); -} - -/* - * Finish off an encoded strip by flushing the last - * string and tacking on an End Of Information code. - */ -static int -ZIPPostEncode(TIFF* tif) -{ - static const char module[] = "ZIPPostEncode"; - ZIPState *sp = EncoderState(tif); - int state; - - sp->stream.avail_in = 0; - do { - state = deflate(&sp->stream, Z_FINISH); - switch (state) { - case Z_STREAM_END: - case Z_OK: - if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) - { - tif->tif_rawcc = tif->tif_rawdatasize - sp->stream.avail_out; - TIFFFlushData1(tif); - sp->stream.next_out = tif->tif_rawdata; - sp->stream.avail_out = (uInt) tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in ZIPPreEncode */ - } - break; - default: - TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", - sp->stream.msg); - return (0); - } - } while (state != Z_STREAM_END); - return (1); -} - -static void -ZIPCleanup(TIFF* tif) -{ - ZIPState* sp = ZState(tif); - - assert(sp != 0); - - (void)TIFFPredictorCleanup(tif); - - tif->tif_tagmethods.vgetfield = sp->vgetparent; - tif->tif_tagmethods.vsetfield = sp->vsetparent; - - if (sp->state & ZSTATE_INIT_ENCODE) { - deflateEnd(&sp->stream); - sp->state = 0; - } else if( sp->state & ZSTATE_INIT_DECODE) { - inflateEnd(&sp->stream); - sp->state = 0; - } - _TIFFfree(sp); - tif->tif_data = NULL; - - _TIFFSetDefaultCompressionState(tif); -} - -static int -ZIPVSetField(TIFF* tif, uint32 tag, va_list ap) -{ - static const char module[] = "ZIPVSetField"; - ZIPState* sp = ZState(tif); - - switch (tag) { - case TIFFTAG_ZIPQUALITY: - sp->zipquality = (int) va_arg(ap, int); - if ( sp->state&ZSTATE_INIT_ENCODE ) { - if (deflateParams(&sp->stream, - sp->zipquality, Z_DEFAULT_STRATEGY) != Z_OK) { - TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", - sp->stream.msg); - return (0); - } - } - return (1); - default: - return (*sp->vsetparent)(tif, tag, ap); - } - /*NOTREACHED*/ -} - -static int -ZIPVGetField(TIFF* tif, uint32 tag, va_list ap) -{ - ZIPState* sp = ZState(tif); - - switch (tag) { - case TIFFTAG_ZIPQUALITY: - *va_arg(ap, int*) = sp->zipquality; - break; - default: - return (*sp->vgetparent)(tif, tag, ap); - } - return (1); -} - -static const TIFFField zipFields[] = { - { TIFFTAG_ZIPQUALITY, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "", NULL }, -}; - -int -TIFFInitZIP(TIFF* tif, int scheme) -{ - static const char module[] = "TIFFInitZIP"; - ZIPState* sp; - - assert( (scheme == COMPRESSION_DEFLATE) - || (scheme == COMPRESSION_ADOBE_DEFLATE)); - - /* - * Merge codec-specific tag information. - */ - if (!_TIFFMergeFields(tif, zipFields, TIFFArrayCount(zipFields))) { - TIFFErrorExt(tif->tif_clientdata, module, - "Merging Deflate codec-specific tags failed"); - return 0; - } - - /* - * Allocate state block so tag methods have storage to record values. - */ - tif->tif_data = (uint8*) _TIFFmalloc(sizeof (ZIPState)); - if (tif->tif_data == NULL) - goto bad; - sp = ZState(tif); - sp->stream.zalloc = NULL; - sp->stream.zfree = NULL; - sp->stream.opaque = NULL; - sp->stream.data_type = Z_BINARY; - - /* - * Override parent get/set field methods. - */ - sp->vgetparent = tif->tif_tagmethods.vgetfield; - tif->tif_tagmethods.vgetfield = ZIPVGetField; /* hook for codec tags */ - sp->vsetparent = tif->tif_tagmethods.vsetfield; - tif->tif_tagmethods.vsetfield = ZIPVSetField; /* hook for codec tags */ - - /* Default values for codec-specific fields */ - sp->zipquality = Z_DEFAULT_COMPRESSION; /* default comp. level */ - sp->state = 0; - - /* - * Install codec methods. - */ - tif->tif_fixuptags = ZIPFixupTags; - tif->tif_setupdecode = ZIPSetupDecode; - tif->tif_predecode = ZIPPreDecode; - tif->tif_decoderow = ZIPDecode; - tif->tif_decodestrip = ZIPDecode; - tif->tif_decodetile = ZIPDecode; - tif->tif_setupencode = ZIPSetupEncode; - tif->tif_preencode = ZIPPreEncode; - tif->tif_postencode = ZIPPostEncode; - tif->tif_encoderow = ZIPEncode; - tif->tif_encodestrip = ZIPEncode; - tif->tif_encodetile = ZIPEncode; - tif->tif_cleanup = ZIPCleanup; - /* - * Setup predictor setup. - */ - (void) TIFFPredictorInit(tif); - return (1); -bad: - TIFFErrorExt(tif->tif_clientdata, module, - "No space for ZIP state block"); - return (0); -} -#endif /* ZIP_SUPORT */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tif_zip.c,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1995-1997 Sam Leffler + * Copyright (c) 1995-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include "tiffiop.h" +#ifdef ZIP_SUPPORT +/* + * TIFF Library. + * + * ZIP (aka Deflate) Compression Support + * + * This file is simply an interface to the zlib library written by + * Jean-loup Gailly and Mark Adler. You must use version 1.0 or later + * of the library: this code assumes the 1.0 API and also depends on + * the ability to write the zlib header multiple times (one per strip) + * which was not possible with versions prior to 0.95. Note also that + * older versions of this codec avoided this bug by supressing the header + * entirely. This means that files written with the old library cannot + * be read; they should be converted to a different compression scheme + * and then reconverted. + * + * The data format used by the zlib library is described in the files + * zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available in the + * directory ftp://ftp.uu.net/pub/archiving/zip/doc. The library was + * last found at ftp://ftp.uu.net/pub/archiving/zip/zlib/zlib-0.99.tar.gz. + */ +#include "tif_predict.h" +#include "../ZLib/zlib.h" + +#include + +/* + * Sigh, ZLIB_VERSION is defined as a string so there's no + * way to do a proper check here. Instead we guess based + * on the presence of #defines that were added between the + * 0.95 and 1.0 distributions. + */ +#if !defined(Z_NO_COMPRESSION) || !defined(Z_DEFLATED) +#error "Antiquated ZLIB software; you must use version 1.0 or later" +#endif + +/* + * State block for each open TIFF + * file using ZIP compression/decompression. + */ +typedef struct { + TIFFPredictorState predict; + z_stream stream; + int zipquality; /* compression level */ + int state; /* state flags */ +#define ZSTATE_INIT_DECODE 0x01 +#define ZSTATE_INIT_ENCODE 0x02 + + TIFFVGetMethod vgetparent; /* super-class method */ + TIFFVSetMethod vsetparent; /* super-class method */ +} ZIPState; + +#define ZState(tif) ((ZIPState*) (tif)->tif_data) +#define DecoderState(tif) ZState(tif) +#define EncoderState(tif) ZState(tif) + +static int ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s); +static int ZIPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s); + +static int +ZIPFixupTags(TIFF* tif) +{ + (void) tif; + return (1); +} + +static int +ZIPSetupDecode(TIFF* tif) +{ + static const char module[] = "ZIPSetupDecode"; + ZIPState* sp = DecoderState(tif); + + assert(sp != NULL); + + /* if we were last encoding, terminate this mode */ + if (sp->state & ZSTATE_INIT_ENCODE) { + deflateEnd(&sp->stream); + sp->state = 0; + } + + if (inflateInit(&sp->stream) != Z_OK) { + TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg); + return (0); + } else { + sp->state |= ZSTATE_INIT_DECODE; + return (1); + } +} + +/* + * Setup state for decoding a strip. + */ +static int +ZIPPreDecode(TIFF* tif, uint16 s) +{ + static const char module[] = "ZIPPreDecode"; + ZIPState* sp = DecoderState(tif); + + (void) s; + assert(sp != NULL); + + if( (sp->state & ZSTATE_INIT_DECODE) == 0 ) + tif->tif_setupdecode( tif ); + + sp->stream.next_in = tif->tif_rawdata; + assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised, + we need to simplify this code to reflect a ZLib that is likely updated + to deal with 8byte memory sizes, though this code will respond + apropriately even before we simplify it */ + sp->stream.avail_in = (uInt) tif->tif_rawcc; + if ((tmsize_t)sp->stream.avail_in != tif->tif_rawcc) + { + TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); + return (0); + } + return (inflateReset(&sp->stream) == Z_OK); +} + +static int +ZIPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) +{ + static const char module[] = "ZIPDecode"; + ZIPState* sp = DecoderState(tif); + + (void) s; + assert(sp != NULL); + assert(sp->state == ZSTATE_INIT_DECODE); + + sp->stream.next_in = tif->tif_rawcp; + sp->stream.avail_in = (uInt) tif->tif_rawcc; + + sp->stream.next_out = op; + assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, + we need to simplify this code to reflect a ZLib that is likely updated + to deal with 8byte memory sizes, though this code will respond + apropriately even before we simplify it */ + sp->stream.avail_out = (uInt) occ; + if ((tmsize_t)sp->stream.avail_out != occ) + { + TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); + return (0); + } + do { + int state = inflate(&sp->stream, Z_PARTIAL_FLUSH); + if (state == Z_STREAM_END) + break; + if (state == Z_DATA_ERROR) { + TIFFErrorExt(tif->tif_clientdata, module, + "Decoding error at scanline %lu, %s", + (unsigned long) tif->tif_row, sp->stream.msg); + if (inflateSync(&sp->stream) != Z_OK) + return (0); + continue; + } + if (state != Z_OK) { + TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", + sp->stream.msg); + return (0); + } + } while (sp->stream.avail_out > 0); + if (sp->stream.avail_out != 0) { + TIFFErrorExt(tif->tif_clientdata, module, + "Not enough data at scanline %lu (short " TIFF_UINT64_FORMAT " bytes)", + (unsigned long) tif->tif_row, (TIFF_UINT64_T) sp->stream.avail_out); + return (0); + } + + tif->tif_rawcp = sp->stream.next_in; + tif->tif_rawcc = sp->stream.avail_in; + + return (1); +} + +static int +ZIPSetupEncode(TIFF* tif) +{ + static const char module[] = "ZIPSetupEncode"; + ZIPState* sp = EncoderState(tif); + + assert(sp != NULL); + if (sp->state & ZSTATE_INIT_DECODE) { + inflateEnd(&sp->stream); + sp->state = 0; + } + + if (deflateInit(&sp->stream, sp->zipquality) != Z_OK) { + TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg); + return (0); + } else { + sp->state |= ZSTATE_INIT_ENCODE; + return (1); + } +} + +/* + * Reset encoding state at the start of a strip. + */ +static int +ZIPPreEncode(TIFF* tif, uint16 s) +{ + static const char module[] = "ZIPPreEncode"; + ZIPState *sp = EncoderState(tif); + + (void) s; + assert(sp != NULL); + if( sp->state != ZSTATE_INIT_ENCODE ) + tif->tif_setupencode( tif ); + + sp->stream.next_out = tif->tif_rawdata; + assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, + we need to simplify this code to reflect a ZLib that is likely updated + to deal with 8byte memory sizes, though this code will respond + apropriately even before we simplify it */ + sp->stream.avail_out = tif->tif_rawdatasize; + if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) + { + TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); + return (0); + } + return (deflateReset(&sp->stream) == Z_OK); +} + +/* + * Encode a chunk of pixels. + */ +static int +ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) +{ + static const char module[] = "ZIPEncode"; + ZIPState *sp = EncoderState(tif); + + assert(sp != NULL); + assert(sp->state == ZSTATE_INIT_ENCODE); + + (void) s; + sp->stream.next_in = bp; + assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised, + we need to simplify this code to reflect a ZLib that is likely updated + to deal with 8byte memory sizes, though this code will respond + apropriately even before we simplify it */ + sp->stream.avail_in = (uInt) cc; + if ((tmsize_t)sp->stream.avail_in != cc) + { + TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); + return (0); + } + do { + if (deflate(&sp->stream, Z_NO_FLUSH) != Z_OK) { + TIFFErrorExt(tif->tif_clientdata, module, "Encoder error: %s", + sp->stream.msg); + return (0); + } + if (sp->stream.avail_out == 0) { + tif->tif_rawcc = tif->tif_rawdatasize; + TIFFFlushData1(tif); + sp->stream.next_out = tif->tif_rawdata; + sp->stream.avail_out = (uInt) tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in ZIPPreEncode */ + } + } while (sp->stream.avail_in > 0); + return (1); +} + +/* + * Finish off an encoded strip by flushing the last + * string and tacking on an End Of Information code. + */ +static int +ZIPPostEncode(TIFF* tif) +{ + static const char module[] = "ZIPPostEncode"; + ZIPState *sp = EncoderState(tif); + int state; + + sp->stream.avail_in = 0; + do { + state = deflate(&sp->stream, Z_FINISH); + switch (state) { + case Z_STREAM_END: + case Z_OK: + if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) + { + tif->tif_rawcc = tif->tif_rawdatasize - sp->stream.avail_out; + TIFFFlushData1(tif); + sp->stream.next_out = tif->tif_rawdata; + sp->stream.avail_out = (uInt) tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in ZIPPreEncode */ + } + break; + default: + TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", + sp->stream.msg); + return (0); + } + } while (state != Z_STREAM_END); + return (1); +} + +static void +ZIPCleanup(TIFF* tif) +{ + ZIPState* sp = ZState(tif); + + assert(sp != 0); + + (void)TIFFPredictorCleanup(tif); + + tif->tif_tagmethods.vgetfield = sp->vgetparent; + tif->tif_tagmethods.vsetfield = sp->vsetparent; + + if (sp->state & ZSTATE_INIT_ENCODE) { + deflateEnd(&sp->stream); + sp->state = 0; + } else if( sp->state & ZSTATE_INIT_DECODE) { + inflateEnd(&sp->stream); + sp->state = 0; + } + _TIFFfree(sp); + tif->tif_data = NULL; + + _TIFFSetDefaultCompressionState(tif); +} + +static int +ZIPVSetField(TIFF* tif, uint32 tag, va_list ap) +{ + static const char module[] = "ZIPVSetField"; + ZIPState* sp = ZState(tif); + + switch (tag) { + case TIFFTAG_ZIPQUALITY: + sp->zipquality = (int) va_arg(ap, int); + if ( sp->state&ZSTATE_INIT_ENCODE ) { + if (deflateParams(&sp->stream, + sp->zipquality, Z_DEFAULT_STRATEGY) != Z_OK) { + TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", + sp->stream.msg); + return (0); + } + } + return (1); + default: + return (*sp->vsetparent)(tif, tag, ap); + } + /*NOTREACHED*/ +} + +static int +ZIPVGetField(TIFF* tif, uint32 tag, va_list ap) +{ + ZIPState* sp = ZState(tif); + + switch (tag) { + case TIFFTAG_ZIPQUALITY: + *va_arg(ap, int*) = sp->zipquality; + break; + default: + return (*sp->vgetparent)(tif, tag, ap); + } + return (1); +} + +static const TIFFField zipFields[] = { + { TIFFTAG_ZIPQUALITY, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "", NULL }, +}; + +int +TIFFInitZIP(TIFF* tif, int scheme) +{ + static const char module[] = "TIFFInitZIP"; + ZIPState* sp; + + assert( (scheme == COMPRESSION_DEFLATE) + || (scheme == COMPRESSION_ADOBE_DEFLATE)); + + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFields(tif, zipFields, TIFFArrayCount(zipFields))) { + TIFFErrorExt(tif->tif_clientdata, module, + "Merging Deflate codec-specific tags failed"); + return 0; + } + + /* + * Allocate state block so tag methods have storage to record values. + */ + tif->tif_data = (uint8*) _TIFFmalloc(sizeof (ZIPState)); + if (tif->tif_data == NULL) + goto bad; + sp = ZState(tif); + sp->stream.zalloc = NULL; + sp->stream.zfree = NULL; + sp->stream.opaque = NULL; + sp->stream.data_type = Z_BINARY; + + /* + * Override parent get/set field methods. + */ + sp->vgetparent = tif->tif_tagmethods.vgetfield; + tif->tif_tagmethods.vgetfield = ZIPVGetField; /* hook for codec tags */ + sp->vsetparent = tif->tif_tagmethods.vsetfield; + tif->tif_tagmethods.vsetfield = ZIPVSetField; /* hook for codec tags */ + + /* Default values for codec-specific fields */ + sp->zipquality = Z_DEFAULT_COMPRESSION; /* default comp. level */ + sp->state = 0; + + /* + * Install codec methods. + */ + tif->tif_fixuptags = ZIPFixupTags; + tif->tif_setupdecode = ZIPSetupDecode; + tif->tif_predecode = ZIPPreDecode; + tif->tif_decoderow = ZIPDecode; + tif->tif_decodestrip = ZIPDecode; + tif->tif_decodetile = ZIPDecode; + tif->tif_setupencode = ZIPSetupEncode; + tif->tif_preencode = ZIPPreEncode; + tif->tif_postencode = ZIPPostEncode; + tif->tif_encoderow = ZIPEncode; + tif->tif_encodestrip = ZIPEncode; + tif->tif_encodetile = ZIPEncode; + tif->tif_cleanup = ZIPCleanup; + /* + * Setup predictor setup. + */ + (void) TIFFPredictorInit(tif); + return (1); +bad: + TIFFErrorExt(tif->tif_clientdata, module, + "No space for ZIP state block"); + return (0); +} +#endif /* ZIP_SUPORT */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tiff.h b/Source/LibTIFF4/tiff.h index f5317ed..4cc3a3b 100644 --- a/Source/LibTIFF4/tiff.h +++ b/Source/LibTIFF4/tiff.h @@ -1,678 +1,678 @@ -/* $Id: tiff.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifndef _TIFF_ -#define _TIFF_ - -#include "tiffconf.h" - -/* - * Tag Image File Format (TIFF) - * - * Based on Rev 6.0 from: - * Developer's Desk - * Aldus Corporation - * 411 First Ave. South - * Suite 200 - * Seattle, WA 98104 - * 206-622-5500 - * - * (http://partners.adobe.com/asn/developer/PDFS/TN/TIFF6.pdf) - * - * For BigTIFF design notes see the following links - * http://www.remotesensing.org/libtiff/bigtiffdesign.html - * http://www.awaresystems.be/imaging/tiff/bigtiff.html - */ - -#define TIFF_VERSION_CLASSIC 42 -#define TIFF_VERSION_BIG 43 - -#define TIFF_BIGENDIAN 0x4d4d -#define TIFF_LITTLEENDIAN 0x4949 -#define MDI_LITTLEENDIAN 0x5045 -#define MDI_BIGENDIAN 0x4550 - -/* - * Intrinsic data types required by the file format: - * - * 8-bit quantities int8/uint8 - * 16-bit quantities int16/uint16 - * 32-bit quantities int32/uint32 - * 64-bit quantities int64/uint64 - * strings unsigned char* - */ - -typedef TIFF_INT8_T int8; -typedef TIFF_UINT8_T uint8; - -typedef TIFF_INT16_T int16; -typedef TIFF_UINT16_T uint16; - -typedef TIFF_INT32_T int32; -typedef TIFF_UINT32_T uint32; - -typedef TIFF_INT64_T int64; -typedef TIFF_UINT64_T uint64; - -/* - * Some types as promoted in a variable argument list - * We use uint16_vap rather then directly using int, because this way - * we document the type we actually want to pass through, conceptually, - * rather then confusing the issue by merely stating the type it gets - * promoted to - */ - -typedef int uint16_vap; - -/* - * TIFF header. - */ -typedef struct { - uint16 tiff_magic; /* magic number (defines byte order) */ - uint16 tiff_version; /* TIFF version number */ -} TIFFHeaderCommon; -typedef struct { - uint16 tiff_magic; /* magic number (defines byte order) */ - uint16 tiff_version; /* TIFF version number */ - uint32 tiff_diroff; /* byte offset to first directory */ -} TIFFHeaderClassic; -typedef struct { - uint16 tiff_magic; /* magic number (defines byte order) */ - uint16 tiff_version; /* TIFF version number */ - uint16 tiff_offsetsize; /* size of offsets, should be 8 */ - uint16 tiff_unused; /* unused word, should be 0 */ - uint64 tiff_diroff; /* byte offset to first directory */ -} TIFFHeaderBig; - - -/* - * NB: In the comments below, - * - items marked with a + are obsoleted by revision 5.0, - * - items marked with a ! are introduced in revision 6.0. - * - items marked with a % are introduced post revision 6.0. - * - items marked with a $ are obsoleted by revision 6.0. - * - items marked with a & are introduced by Adobe DNG specification. - */ - -/* - * Tag data type information. - * - * Note: RATIONALs are the ratio of two 32-bit integer values. - */ -typedef enum { - TIFF_NOTYPE = 0, /* placeholder */ - TIFF_BYTE = 1, /* 8-bit unsigned integer */ - TIFF_ASCII = 2, /* 8-bit bytes w/ last byte null */ - TIFF_SHORT = 3, /* 16-bit unsigned integer */ - TIFF_LONG = 4, /* 32-bit unsigned integer */ - TIFF_RATIONAL = 5, /* 64-bit unsigned fraction */ - TIFF_SBYTE = 6, /* !8-bit signed integer */ - TIFF_UNDEFINED = 7, /* !8-bit untyped data */ - TIFF_SSHORT = 8, /* !16-bit signed integer */ - TIFF_SLONG = 9, /* !32-bit signed integer */ - TIFF_SRATIONAL = 10, /* !64-bit signed fraction */ - TIFF_FLOAT = 11, /* !32-bit IEEE floating point */ - TIFF_DOUBLE = 12, /* !64-bit IEEE floating point */ - TIFF_IFD = 13, /* %32-bit unsigned integer (offset) */ - TIFF_LONG8 = 16, /* BigTIFF 64-bit unsigned integer */ - TIFF_SLONG8 = 17, /* BigTIFF 64-bit signed integer */ - TIFF_IFD8 = 18 /* BigTIFF 64-bit unsigned integer (offset) */ -} TIFFDataType; - -/* - * TIFF Tag Definitions. - */ -#define TIFFTAG_SUBFILETYPE 254 /* subfile data descriptor */ -#define FILETYPE_REDUCEDIMAGE 0x1 /* reduced resolution version */ -#define FILETYPE_PAGE 0x2 /* one page of many */ -#define FILETYPE_MASK 0x4 /* transparency mask */ -#define TIFFTAG_OSUBFILETYPE 255 /* +kind of data in subfile */ -#define OFILETYPE_IMAGE 1 /* full resolution image data */ -#define OFILETYPE_REDUCEDIMAGE 2 /* reduced size image data */ -#define OFILETYPE_PAGE 3 /* one page of many */ -#define TIFFTAG_IMAGEWIDTH 256 /* image width in pixels */ -#define TIFFTAG_IMAGELENGTH 257 /* image height in pixels */ -#define TIFFTAG_BITSPERSAMPLE 258 /* bits per channel (sample) */ -#define TIFFTAG_COMPRESSION 259 /* data compression technique */ -#define COMPRESSION_NONE 1 /* dump mode */ -#define COMPRESSION_CCITTRLE 2 /* CCITT modified Huffman RLE */ -#define COMPRESSION_CCITTFAX3 3 /* CCITT Group 3 fax encoding */ -#define COMPRESSION_CCITT_T4 3 /* CCITT T.4 (TIFF 6 name) */ -#define COMPRESSION_CCITTFAX4 4 /* CCITT Group 4 fax encoding */ -#define COMPRESSION_CCITT_T6 4 /* CCITT T.6 (TIFF 6 name) */ -#define COMPRESSION_LZW 5 /* Lempel-Ziv & Welch */ -#define COMPRESSION_OJPEG 6 /* !6.0 JPEG */ -#define COMPRESSION_JPEG 7 /* %JPEG DCT compression */ -#define COMPRESSION_T85 9 /* !TIFF/FX T.85 JBIG compression */ -#define COMPRESSION_T43 10 /* !TIFF/FX T.43 colour by layered JBIG compression */ -#define COMPRESSION_NEXT 32766 /* NeXT 2-bit RLE */ -#define COMPRESSION_CCITTRLEW 32771 /* #1 w/ word alignment */ -#define COMPRESSION_PACKBITS 32773 /* Macintosh RLE */ -#define COMPRESSION_THUNDERSCAN 32809 /* ThunderScan RLE */ -/* codes 32895-32898 are reserved for ANSI IT8 TIFF/IT */ -#define COMPRESSION_DCS 32947 /* Kodak DCS encoding */ -#define COMPRESSION_JBIG 34661 /* ISO JBIG */ -#define COMPRESSION_SGILOG 34676 /* SGI Log Luminance RLE */ -#define COMPRESSION_SGILOG24 34677 /* SGI Log 24-bit packed */ -#define COMPRESSION_JP2000 34712 /* Leadtools JPEG2000 */ -#define COMPRESSION_LZMA 34925 /* LZMA2 */ -#define TIFFTAG_PHOTOMETRIC 262 /* photometric interpretation */ -#define PHOTOMETRIC_MINISWHITE 0 /* min value is white */ -#define PHOTOMETRIC_MINISBLACK 1 /* min value is black */ -#define PHOTOMETRIC_RGB 2 /* RGB color model */ -#define PHOTOMETRIC_PALETTE 3 /* color map indexed */ -#define PHOTOMETRIC_MASK 4 /* $holdout mask */ -#define PHOTOMETRIC_SEPARATED 5 /* !color separations */ -#define PHOTOMETRIC_YCBCR 6 /* !CCIR 601 */ -#define PHOTOMETRIC_CIELAB 8 /* !1976 CIE L*a*b* */ -#define PHOTOMETRIC_ICCLAB 9 /* ICC L*a*b* [Adobe TIFF Technote 4] */ -#define PHOTOMETRIC_ITULAB 10 /* ITU L*a*b* */ -#define PHOTOMETRIC_LOGL 32844 /* CIE Log2(L) */ -#define PHOTOMETRIC_LOGLUV 32845 /* CIE Log2(L) (u',v') */ -#define TIFFTAG_THRESHHOLDING 263 /* +thresholding used on data */ -#define THRESHHOLD_BILEVEL 1 /* b&w art scan */ -#define THRESHHOLD_HALFTONE 2 /* or dithered scan */ -#define THRESHHOLD_ERRORDIFFUSE 3 /* usually floyd-steinberg */ -#define TIFFTAG_CELLWIDTH 264 /* +dithering matrix width */ -#define TIFFTAG_CELLLENGTH 265 /* +dithering matrix height */ -#define TIFFTAG_FILLORDER 266 /* data order within a byte */ -#define FILLORDER_MSB2LSB 1 /* most significant -> least */ -#define FILLORDER_LSB2MSB 2 /* least significant -> most */ -#define TIFFTAG_DOCUMENTNAME 269 /* name of doc. image is from */ -#define TIFFTAG_IMAGEDESCRIPTION 270 /* info about image */ -#define TIFFTAG_MAKE 271 /* scanner manufacturer name */ -#define TIFFTAG_MODEL 272 /* scanner model name/number */ -#define TIFFTAG_STRIPOFFSETS 273 /* offsets to data strips */ -#define TIFFTAG_ORIENTATION 274 /* +image orientation */ -#define ORIENTATION_TOPLEFT 1 /* row 0 top, col 0 lhs */ -#define ORIENTATION_TOPRIGHT 2 /* row 0 top, col 0 rhs */ -#define ORIENTATION_BOTRIGHT 3 /* row 0 bottom, col 0 rhs */ -#define ORIENTATION_BOTLEFT 4 /* row 0 bottom, col 0 lhs */ -#define ORIENTATION_LEFTTOP 5 /* row 0 lhs, col 0 top */ -#define ORIENTATION_RIGHTTOP 6 /* row 0 rhs, col 0 top */ -#define ORIENTATION_RIGHTBOT 7 /* row 0 rhs, col 0 bottom */ -#define ORIENTATION_LEFTBOT 8 /* row 0 lhs, col 0 bottom */ -#define TIFFTAG_SAMPLESPERPIXEL 277 /* samples per pixel */ -#define TIFFTAG_ROWSPERSTRIP 278 /* rows per strip of data */ -#define TIFFTAG_STRIPBYTECOUNTS 279 /* bytes counts for strips */ -#define TIFFTAG_MINSAMPLEVALUE 280 /* +minimum sample value */ -#define TIFFTAG_MAXSAMPLEVALUE 281 /* +maximum sample value */ -#define TIFFTAG_XRESOLUTION 282 /* pixels/resolution in x */ -#define TIFFTAG_YRESOLUTION 283 /* pixels/resolution in y */ -#define TIFFTAG_PLANARCONFIG 284 /* storage organization */ -#define PLANARCONFIG_CONTIG 1 /* single image plane */ -#define PLANARCONFIG_SEPARATE 2 /* separate planes of data */ -#define TIFFTAG_PAGENAME 285 /* page name image is from */ -#define TIFFTAG_XPOSITION 286 /* x page offset of image lhs */ -#define TIFFTAG_YPOSITION 287 /* y page offset of image lhs */ -#define TIFFTAG_FREEOFFSETS 288 /* +byte offset to free block */ -#define TIFFTAG_FREEBYTECOUNTS 289 /* +sizes of free blocks */ -#define TIFFTAG_GRAYRESPONSEUNIT 290 /* $gray scale curve accuracy */ -#define GRAYRESPONSEUNIT_10S 1 /* tenths of a unit */ -#define GRAYRESPONSEUNIT_100S 2 /* hundredths of a unit */ -#define GRAYRESPONSEUNIT_1000S 3 /* thousandths of a unit */ -#define GRAYRESPONSEUNIT_10000S 4 /* ten-thousandths of a unit */ -#define GRAYRESPONSEUNIT_100000S 5 /* hundred-thousandths */ -#define TIFFTAG_GRAYRESPONSECURVE 291 /* $gray scale response curve */ -#define TIFFTAG_GROUP3OPTIONS 292 /* 32 flag bits */ -#define TIFFTAG_T4OPTIONS 292 /* TIFF 6.0 proper name alias */ -#define GROUP3OPT_2DENCODING 0x1 /* 2-dimensional coding */ -#define GROUP3OPT_UNCOMPRESSED 0x2 /* data not compressed */ -#define GROUP3OPT_FILLBITS 0x4 /* fill to byte boundary */ -#define TIFFTAG_GROUP4OPTIONS 293 /* 32 flag bits */ -#define TIFFTAG_T6OPTIONS 293 /* TIFF 6.0 proper name */ -#define GROUP4OPT_UNCOMPRESSED 0x2 /* data not compressed */ -#define TIFFTAG_RESOLUTIONUNIT 296 /* units of resolutions */ -#define RESUNIT_NONE 1 /* no meaningful units */ -#define RESUNIT_INCH 2 /* english */ -#define RESUNIT_CENTIMETER 3 /* metric */ -#define TIFFTAG_PAGENUMBER 297 /* page numbers of multi-page */ -#define TIFFTAG_COLORRESPONSEUNIT 300 /* $color curve accuracy */ -#define COLORRESPONSEUNIT_10S 1 /* tenths of a unit */ -#define COLORRESPONSEUNIT_100S 2 /* hundredths of a unit */ -#define COLORRESPONSEUNIT_1000S 3 /* thousandths of a unit */ -#define COLORRESPONSEUNIT_10000S 4 /* ten-thousandths of a unit */ -#define COLORRESPONSEUNIT_100000S 5 /* hundred-thousandths */ -#define TIFFTAG_TRANSFERFUNCTION 301 /* !colorimetry info */ -#define TIFFTAG_SOFTWARE 305 /* name & release */ -#define TIFFTAG_DATETIME 306 /* creation date and time */ -#define TIFFTAG_ARTIST 315 /* creator of image */ -#define TIFFTAG_HOSTCOMPUTER 316 /* machine where created */ -#define TIFFTAG_PREDICTOR 317 /* prediction scheme w/ LZW */ -#define PREDICTOR_NONE 1 /* no prediction scheme used */ -#define PREDICTOR_HORIZONTAL 2 /* horizontal differencing */ -#define PREDICTOR_FLOATINGPOINT 3 /* floating point predictor */ -#define TIFFTAG_WHITEPOINT 318 /* image white point */ -#define TIFFTAG_PRIMARYCHROMATICITIES 319 /* !primary chromaticities */ -#define TIFFTAG_COLORMAP 320 /* RGB map for pallette image */ -#define TIFFTAG_HALFTONEHINTS 321 /* !highlight+shadow info */ -#define TIFFTAG_TILEWIDTH 322 /* !tile width in pixels */ -#define TIFFTAG_TILELENGTH 323 /* !tile height in pixels */ -#define TIFFTAG_TILEOFFSETS 324 /* !offsets to data tiles */ -#define TIFFTAG_TILEBYTECOUNTS 325 /* !byte counts for tiles */ -#define TIFFTAG_BADFAXLINES 326 /* lines w/ wrong pixel count */ -#define TIFFTAG_CLEANFAXDATA 327 /* regenerated line info */ -#define CLEANFAXDATA_CLEAN 0 /* no errors detected */ -#define CLEANFAXDATA_REGENERATED 1 /* receiver regenerated lines */ -#define CLEANFAXDATA_UNCLEAN 2 /* uncorrected errors exist */ -#define TIFFTAG_CONSECUTIVEBADFAXLINES 328 /* max consecutive bad lines */ -#define TIFFTAG_SUBIFD 330 /* subimage descriptors */ -#define TIFFTAG_INKSET 332 /* !inks in separated image */ -#define INKSET_CMYK 1 /* !cyan-magenta-yellow-black color */ -#define INKSET_MULTIINK 2 /* !multi-ink or hi-fi color */ -#define TIFFTAG_INKNAMES 333 /* !ascii names of inks */ -#define TIFFTAG_NUMBEROFINKS 334 /* !number of inks */ -#define TIFFTAG_DOTRANGE 336 /* !0% and 100% dot codes */ -#define TIFFTAG_TARGETPRINTER 337 /* !separation target */ -#define TIFFTAG_EXTRASAMPLES 338 /* !info about extra samples */ -#define EXTRASAMPLE_UNSPECIFIED 0 /* !unspecified data */ -#define EXTRASAMPLE_ASSOCALPHA 1 /* !associated alpha data */ -#define EXTRASAMPLE_UNASSALPHA 2 /* !unassociated alpha data */ -#define TIFFTAG_SAMPLEFORMAT 339 /* !data sample format */ -#define SAMPLEFORMAT_UINT 1 /* !unsigned integer data */ -#define SAMPLEFORMAT_INT 2 /* !signed integer data */ -#define SAMPLEFORMAT_IEEEFP 3 /* !IEEE floating point data */ -#define SAMPLEFORMAT_VOID 4 /* !untyped data */ -#define SAMPLEFORMAT_COMPLEXINT 5 /* !complex signed int */ -#define SAMPLEFORMAT_COMPLEXIEEEFP 6 /* !complex ieee floating */ -#define TIFFTAG_SMINSAMPLEVALUE 340 /* !variable MinSampleValue */ -#define TIFFTAG_SMAXSAMPLEVALUE 341 /* !variable MaxSampleValue */ -#define TIFFTAG_CLIPPATH 343 /* %ClipPath - [Adobe TIFF technote 2] */ -#define TIFFTAG_XCLIPPATHUNITS 344 /* %XClipPathUnits - [Adobe TIFF technote 2] */ -#define TIFFTAG_YCLIPPATHUNITS 345 /* %YClipPathUnits - [Adobe TIFF technote 2] */ -#define TIFFTAG_INDEXED 346 /* %Indexed - [Adobe TIFF Technote 3] */ -#define TIFFTAG_JPEGTABLES 347 /* %JPEG table stream */ -#define TIFFTAG_OPIPROXY 351 /* %OPI Proxy [Adobe TIFF technote] */ -/* Tags 400-435 are from the TIFF/FX spec */ -#define TIFFTAG_GLOBALPARAMETERSIFD 400 /* ! */ -#define TIFFTAG_PROFILETYPE 401 /* ! */ -#define PROFILETYPE_UNSPECIFIED 0 /* ! */ -#define PROFILETYPE_G3_FAX 1 /* ! */ -#define TIFFTAG_FAXPROFILE 402 /* ! */ -#define FAXPROFILE_S 1 /* !TIFF/FX FAX profile S */ -#define FAXPROFILE_F 2 /* !TIFF/FX FAX profile F */ -#define FAXPROFILE_J 3 /* !TIFF/FX FAX profile J */ -#define FAXPROFILE_C 4 /* !TIFF/FX FAX profile C */ -#define FAXPROFILE_L 5 /* !TIFF/FX FAX profile L */ -#define FAXPROFILE_M 6 /* !TIFF/FX FAX profile LM */ -#define TIFFTAG_CODINGMETHODS 403 /* !TIFF/FX coding methods */ -#define CODINGMETHODS_T4_1D (1 << 1) /* !T.4 1D */ -#define CODINGMETHODS_T4_2D (1 << 2) /* !T.4 2D */ -#define CODINGMETHODS_T6 (1 << 3) /* !T.6 */ -#define CODINGMETHODS_T85 (1 << 4) /* !T.85 JBIG */ -#define CODINGMETHODS_T42 (1 << 5) /* !T.42 JPEG */ -#define CODINGMETHODS_T43 (1 << 6) /* !T.43 colour by layered JBIG */ -#define TIFFTAG_VERSIONYEAR 404 /* !TIFF/FX version year */ -#define TIFFTAG_MODENUMBER 405 /* !TIFF/FX mode number */ -#define TIFFTAG_DECODE 433 /* !TIFF/FX decode */ -#define TIFFTAG_IMAGEBASECOLOR 434 /* !TIFF/FX image base colour */ -#define TIFFTAG_T82OPTIONS 435 /* !TIFF/FX T.82 options */ -/* - * Tags 512-521 are obsoleted by Technical Note #2 which specifies a - * revised JPEG-in-TIFF scheme. - */ -#define TIFFTAG_JPEGPROC 512 /* !JPEG processing algorithm */ -#define JPEGPROC_BASELINE 1 /* !baseline sequential */ -#define JPEGPROC_LOSSLESS 14 /* !Huffman coded lossless */ -#define TIFFTAG_JPEGIFOFFSET 513 /* !pointer to SOI marker */ -#define TIFFTAG_JPEGIFBYTECOUNT 514 /* !JFIF stream length */ -#define TIFFTAG_JPEGRESTARTINTERVAL 515 /* !restart interval length */ -#define TIFFTAG_JPEGLOSSLESSPREDICTORS 517 /* !lossless proc predictor */ -#define TIFFTAG_JPEGPOINTTRANSFORM 518 /* !lossless point transform */ -#define TIFFTAG_JPEGQTABLES 519 /* !Q matrice offsets */ -#define TIFFTAG_JPEGDCTABLES 520 /* !DCT table offsets */ -#define TIFFTAG_JPEGACTABLES 521 /* !AC coefficient offsets */ -#define TIFFTAG_YCBCRCOEFFICIENTS 529 /* !RGB -> YCbCr transform */ -#define TIFFTAG_YCBCRSUBSAMPLING 530 /* !YCbCr subsampling factors */ -#define TIFFTAG_YCBCRPOSITIONING 531 /* !subsample positioning */ -#define YCBCRPOSITION_CENTERED 1 /* !as in PostScript Level 2 */ -#define YCBCRPOSITION_COSITED 2 /* !as in CCIR 601-1 */ -#define TIFFTAG_REFERENCEBLACKWHITE 532 /* !colorimetry info */ -#define TIFFTAG_STRIPROWCOUNTS 559 /* !TIFF/FX strip row counts */ -#define TIFFTAG_XMLPACKET 700 /* %XML packet - [Adobe XMP Specification, - January 2004 */ -#define TIFFTAG_OPIIMAGEID 32781 /* %OPI ImageID - [Adobe TIFF technote] */ -/* tags 32952-32956 are private tags registered to Island Graphics */ -#define TIFFTAG_REFPTS 32953 /* image reference points */ -#define TIFFTAG_REGIONTACKPOINT 32954 /* region-xform tack point */ -#define TIFFTAG_REGIONWARPCORNERS 32955 /* warp quadrilateral */ -#define TIFFTAG_REGIONAFFINE 32956 /* affine transformation mat */ -/* tags 32995-32999 are private tags registered to SGI */ -#define TIFFTAG_MATTEING 32995 /* $use ExtraSamples */ -#define TIFFTAG_DATATYPE 32996 /* $use SampleFormat */ -#define TIFFTAG_IMAGEDEPTH 32997 /* z depth of image */ -#define TIFFTAG_TILEDEPTH 32998 /* z depth/data tile */ -/* tags 33300-33309 are private tags registered to Pixar */ -/* - * TIFFTAG_PIXAR_IMAGEFULLWIDTH and TIFFTAG_PIXAR_IMAGEFULLLENGTH - * are set when an image has been cropped out of a larger image. - * They reflect the size of the original uncropped image. - * The TIFFTAG_XPOSITION and TIFFTAG_YPOSITION can be used - * to determine the position of the smaller image in the larger one. - */ -#define TIFFTAG_PIXAR_IMAGEFULLWIDTH 33300 /* full image size in x */ -#define TIFFTAG_PIXAR_IMAGEFULLLENGTH 33301 /* full image size in y */ - /* Tags 33302-33306 are used to identify special image modes and data - * used by Pixar's texture formats. - */ -#define TIFFTAG_PIXAR_TEXTUREFORMAT 33302 /* texture map format */ -#define TIFFTAG_PIXAR_WRAPMODES 33303 /* s & t wrap modes */ -#define TIFFTAG_PIXAR_FOVCOT 33304 /* cotan(fov) for env. maps */ -#define TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN 33305 -#define TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA 33306 -/* tag 33405 is a private tag registered to Eastman Kodak */ -#define TIFFTAG_WRITERSERIALNUMBER 33405 /* device serial number */ -/* tag 33432 is listed in the 6.0 spec w/ unknown ownership */ -#define TIFFTAG_COPYRIGHT 33432 /* copyright string */ -/* IPTC TAG from RichTIFF specifications */ -#define TIFFTAG_RICHTIFFIPTC 33723 -/* 34016-34029 are reserved for ANSI IT8 TIFF/IT */ -#define TIFFTAG_STONITS 37439 /* Sample value to Nits */ -/* tag 34929 is a private tag registered to FedEx */ -#define TIFFTAG_FEDEX_EDR 34929 /* unknown use */ -#define TIFFTAG_INTEROPERABILITYIFD 40965 /* Pointer to Interoperability private directory */ -/* Adobe Digital Negative (DNG) format tags */ -#define TIFFTAG_DNGVERSION 50706 /* &DNG version number */ -#define TIFFTAG_DNGBACKWARDVERSION 50707 /* &DNG compatibility version */ -#define TIFFTAG_UNIQUECAMERAMODEL 50708 /* &name for the camera model */ -#define TIFFTAG_LOCALIZEDCAMERAMODEL 50709 /* &localized camera model - name */ -#define TIFFTAG_CFAPLANECOLOR 50710 /* &CFAPattern->LinearRaw space - mapping */ -#define TIFFTAG_CFALAYOUT 50711 /* &spatial layout of the CFA */ -#define TIFFTAG_LINEARIZATIONTABLE 50712 /* &lookup table description */ -#define TIFFTAG_BLACKLEVELREPEATDIM 50713 /* &repeat pattern size for - the BlackLevel tag */ -#define TIFFTAG_BLACKLEVEL 50714 /* &zero light encoding level */ -#define TIFFTAG_BLACKLEVELDELTAH 50715 /* &zero light encoding level - differences (columns) */ -#define TIFFTAG_BLACKLEVELDELTAV 50716 /* &zero light encoding level - differences (rows) */ -#define TIFFTAG_WHITELEVEL 50717 /* &fully saturated encoding - level */ -#define TIFFTAG_DEFAULTSCALE 50718 /* &default scale factors */ -#define TIFFTAG_DEFAULTCROPORIGIN 50719 /* &origin of the final image - area */ -#define TIFFTAG_DEFAULTCROPSIZE 50720 /* &size of the final image - area */ -#define TIFFTAG_COLORMATRIX1 50721 /* &XYZ->reference color space - transformation matrix 1 */ -#define TIFFTAG_COLORMATRIX2 50722 /* &XYZ->reference color space - transformation matrix 2 */ -#define TIFFTAG_CAMERACALIBRATION1 50723 /* &calibration matrix 1 */ -#define TIFFTAG_CAMERACALIBRATION2 50724 /* &calibration matrix 2 */ -#define TIFFTAG_REDUCTIONMATRIX1 50725 /* &dimensionality reduction - matrix 1 */ -#define TIFFTAG_REDUCTIONMATRIX2 50726 /* &dimensionality reduction - matrix 2 */ -#define TIFFTAG_ANALOGBALANCE 50727 /* &gain applied the stored raw - values*/ -#define TIFFTAG_ASSHOTNEUTRAL 50728 /* &selected white balance in - linear reference space */ -#define TIFFTAG_ASSHOTWHITEXY 50729 /* &selected white balance in - x-y chromaticity - coordinates */ -#define TIFFTAG_BASELINEEXPOSURE 50730 /* &how much to move the zero - point */ -#define TIFFTAG_BASELINENOISE 50731 /* &relative noise level */ -#define TIFFTAG_BASELINESHARPNESS 50732 /* &relative amount of - sharpening */ -#define TIFFTAG_BAYERGREENSPLIT 50733 /* &how closely the values of - the green pixels in the - blue/green rows track the - values of the green pixels - in the red/green rows */ -#define TIFFTAG_LINEARRESPONSELIMIT 50734 /* &non-linear encoding range */ -#define TIFFTAG_CAMERASERIALNUMBER 50735 /* &camera's serial number */ -#define TIFFTAG_LENSINFO 50736 /* info about the lens */ -#define TIFFTAG_CHROMABLURRADIUS 50737 /* &chroma blur radius */ -#define TIFFTAG_ANTIALIASSTRENGTH 50738 /* &relative strength of the - camera's anti-alias filter */ -#define TIFFTAG_SHADOWSCALE 50739 /* &used by Adobe Camera Raw */ -#define TIFFTAG_DNGPRIVATEDATA 50740 /* &manufacturer's private data */ -#define TIFFTAG_MAKERNOTESAFETY 50741 /* &whether the EXIF MakerNote - tag is safe to preserve - along with the rest of the - EXIF data */ -#define TIFFTAG_CALIBRATIONILLUMINANT1 50778 /* &illuminant 1 */ -#define TIFFTAG_CALIBRATIONILLUMINANT2 50779 /* &illuminant 2 */ -#define TIFFTAG_BESTQUALITYSCALE 50780 /* &best quality multiplier */ -#define TIFFTAG_RAWDATAUNIQUEID 50781 /* &unique identifier for - the raw image data */ -#define TIFFTAG_ORIGINALRAWFILENAME 50827 /* &file name of the original - raw file */ -#define TIFFTAG_ORIGINALRAWFILEDATA 50828 /* &contents of the original - raw file */ -#define TIFFTAG_ACTIVEAREA 50829 /* &active (non-masked) pixels - of the sensor */ -#define TIFFTAG_MASKEDAREAS 50830 /* &list of coordinates - of fully masked pixels */ -#define TIFFTAG_ASSHOTICCPROFILE 50831 /* &these two tags used to */ -#define TIFFTAG_ASSHOTPREPROFILEMATRIX 50832 /* map cameras's color space - into ICC profile space */ -#define TIFFTAG_CURRENTICCPROFILE 50833 /* & */ -#define TIFFTAG_CURRENTPREPROFILEMATRIX 50834 /* & */ -/* tag 65535 is an undefined tag used by Eastman Kodak */ -#define TIFFTAG_DCSHUESHIFTVALUES 65535 /* hue shift correction data */ - -/* - * The following are ``pseudo tags'' that can be used to control - * codec-specific functionality. These tags are not written to file. - * Note that these values start at 0xffff+1 so that they'll never - * collide with Aldus-assigned tags. - * - * If you want your private pseudo tags ``registered'' (i.e. added to - * this file), please post a bug report via the tracking system at - * http://www.remotesensing.org/libtiff/bugs.html with the appropriate - * C definitions to add. - */ -#define TIFFTAG_FAXMODE 65536 /* Group 3/4 format control */ -#define FAXMODE_CLASSIC 0x0000 /* default, include RTC */ -#define FAXMODE_NORTC 0x0001 /* no RTC at end of data */ -#define FAXMODE_NOEOL 0x0002 /* no EOL code at end of row */ -#define FAXMODE_BYTEALIGN 0x0004 /* byte align row */ -#define FAXMODE_WORDALIGN 0x0008 /* word align row */ -#define FAXMODE_CLASSF FAXMODE_NORTC /* TIFF Class F */ -#define TIFFTAG_JPEGQUALITY 65537 /* Compression quality level */ -/* Note: quality level is on the IJG 0-100 scale. Default value is 75 */ -#define TIFFTAG_JPEGCOLORMODE 65538 /* Auto RGB<=>YCbCr convert? */ -#define JPEGCOLORMODE_RAW 0x0000 /* no conversion (default) */ -#define JPEGCOLORMODE_RGB 0x0001 /* do auto conversion */ -#define TIFFTAG_JPEGTABLESMODE 65539 /* What to put in JPEGTables */ -#define JPEGTABLESMODE_QUANT 0x0001 /* include quantization tbls */ -#define JPEGTABLESMODE_HUFF 0x0002 /* include Huffman tbls */ -/* Note: default is JPEGTABLESMODE_QUANT | JPEGTABLESMODE_HUFF */ -#define TIFFTAG_FAXFILLFUNC 65540 /* G3/G4 fill function */ -#define TIFFTAG_PIXARLOGDATAFMT 65549 /* PixarLogCodec I/O data sz */ -#define PIXARLOGDATAFMT_8BIT 0 /* regular u_char samples */ -#define PIXARLOGDATAFMT_8BITABGR 1 /* ABGR-order u_chars */ -#define PIXARLOGDATAFMT_11BITLOG 2 /* 11-bit log-encoded (raw) */ -#define PIXARLOGDATAFMT_12BITPICIO 3 /* as per PICIO (1.0==2048) */ -#define PIXARLOGDATAFMT_16BIT 4 /* signed short samples */ -#define PIXARLOGDATAFMT_FLOAT 5 /* IEEE float samples */ -/* 65550-65556 are allocated to Oceana Matrix */ -#define TIFFTAG_DCSIMAGERTYPE 65550 /* imager model & filter */ -#define DCSIMAGERMODEL_M3 0 /* M3 chip (1280 x 1024) */ -#define DCSIMAGERMODEL_M5 1 /* M5 chip (1536 x 1024) */ -#define DCSIMAGERMODEL_M6 2 /* M6 chip (3072 x 2048) */ -#define DCSIMAGERFILTER_IR 0 /* infrared filter */ -#define DCSIMAGERFILTER_MONO 1 /* monochrome filter */ -#define DCSIMAGERFILTER_CFA 2 /* color filter array */ -#define DCSIMAGERFILTER_OTHER 3 /* other filter */ -#define TIFFTAG_DCSINTERPMODE 65551 /* interpolation mode */ -#define DCSINTERPMODE_NORMAL 0x0 /* whole image, default */ -#define DCSINTERPMODE_PREVIEW 0x1 /* preview of image (384x256) */ -#define TIFFTAG_DCSBALANCEARRAY 65552 /* color balance values */ -#define TIFFTAG_DCSCORRECTMATRIX 65553 /* color correction values */ -#define TIFFTAG_DCSGAMMA 65554 /* gamma value */ -#define TIFFTAG_DCSTOESHOULDERPTS 65555 /* toe & shoulder points */ -#define TIFFTAG_DCSCALIBRATIONFD 65556 /* calibration file desc */ -/* Note: quality level is on the ZLIB 1-9 scale. Default value is -1 */ -#define TIFFTAG_ZIPQUALITY 65557 /* compression quality level */ -#define TIFFTAG_PIXARLOGQUALITY 65558 /* PixarLog uses same scale */ -/* 65559 is allocated to Oceana Matrix */ -#define TIFFTAG_DCSCLIPRECTANGLE 65559 /* area of image to acquire */ -#define TIFFTAG_SGILOGDATAFMT 65560 /* SGILog user data format */ -#define SGILOGDATAFMT_FLOAT 0 /* IEEE float samples */ -#define SGILOGDATAFMT_16BIT 1 /* 16-bit samples */ -#define SGILOGDATAFMT_RAW 2 /* uninterpreted data */ -#define SGILOGDATAFMT_8BIT 3 /* 8-bit RGB monitor values */ -#define TIFFTAG_SGILOGENCODE 65561 /* SGILog data encoding control*/ -#define SGILOGENCODE_NODITHER 0 /* do not dither encoded values*/ -#define SGILOGENCODE_RANDITHER 1 /* randomly dither encd values */ -#define TIFFTAG_LZMAPRESET 65562 /* LZMA2 preset (compression level) */ -#define TIFFTAG_PERSAMPLE 65563 /* interface for per sample tags */ -#define PERSAMPLE_MERGED 0 /* present as a single value */ -#define PERSAMPLE_MULTI 1 /* present as multiple values */ - -/* - * EXIF tags - */ -#define EXIFTAG_EXPOSURETIME 33434 /* Exposure time */ -#define EXIFTAG_FNUMBER 33437 /* F number */ -#define EXIFTAG_EXPOSUREPROGRAM 34850 /* Exposure program */ -#define EXIFTAG_SPECTRALSENSITIVITY 34852 /* Spectral sensitivity */ -#define EXIFTAG_ISOSPEEDRATINGS 34855 /* ISO speed rating */ -#define EXIFTAG_OECF 34856 /* Optoelectric conversion - factor */ -#define EXIFTAG_EXIFVERSION 36864 /* Exif version */ -#define EXIFTAG_DATETIMEORIGINAL 36867 /* Date and time of original - data generation */ -#define EXIFTAG_DATETIMEDIGITIZED 36868 /* Date and time of digital - data generation */ -#define EXIFTAG_COMPONENTSCONFIGURATION 37121 /* Meaning of each component */ -#define EXIFTAG_COMPRESSEDBITSPERPIXEL 37122 /* Image compression mode */ -#define EXIFTAG_SHUTTERSPEEDVALUE 37377 /* Shutter speed */ -#define EXIFTAG_APERTUREVALUE 37378 /* Aperture */ -#define EXIFTAG_BRIGHTNESSVALUE 37379 /* Brightness */ -#define EXIFTAG_EXPOSUREBIASVALUE 37380 /* Exposure bias */ -#define EXIFTAG_MAXAPERTUREVALUE 37381 /* Maximum lens aperture */ -#define EXIFTAG_SUBJECTDISTANCE 37382 /* Subject distance */ -#define EXIFTAG_METERINGMODE 37383 /* Metering mode */ -#define EXIFTAG_LIGHTSOURCE 37384 /* Light source */ -#define EXIFTAG_FLASH 37385 /* Flash */ -#define EXIFTAG_FOCALLENGTH 37386 /* Lens focal length */ -#define EXIFTAG_SUBJECTAREA 37396 /* Subject area */ -#define EXIFTAG_MAKERNOTE 37500 /* Manufacturer notes */ -#define EXIFTAG_USERCOMMENT 37510 /* User comments */ -#define EXIFTAG_SUBSECTIME 37520 /* DateTime subseconds */ -#define EXIFTAG_SUBSECTIMEORIGINAL 37521 /* DateTimeOriginal subseconds */ -#define EXIFTAG_SUBSECTIMEDIGITIZED 37522 /* DateTimeDigitized subseconds */ -#define EXIFTAG_FLASHPIXVERSION 40960 /* Supported Flashpix version */ -#define EXIFTAG_COLORSPACE 40961 /* Color space information */ -#define EXIFTAG_PIXELXDIMENSION 40962 /* Valid image width */ -#define EXIFTAG_PIXELYDIMENSION 40963 /* Valid image height */ -#define EXIFTAG_RELATEDSOUNDFILE 40964 /* Related audio file */ -#define EXIFTAG_FLASHENERGY 41483 /* Flash energy */ -#define EXIFTAG_SPATIALFREQUENCYRESPONSE 41484 /* Spatial frequency response */ -#define EXIFTAG_FOCALPLANEXRESOLUTION 41486 /* Focal plane X resolution */ -#define EXIFTAG_FOCALPLANEYRESOLUTION 41487 /* Focal plane Y resolution */ -#define EXIFTAG_FOCALPLANERESOLUTIONUNIT 41488 /* Focal plane resolution unit */ -#define EXIFTAG_SUBJECTLOCATION 41492 /* Subject location */ -#define EXIFTAG_EXPOSUREINDEX 41493 /* Exposure index */ -#define EXIFTAG_SENSINGMETHOD 41495 /* Sensing method */ -#define EXIFTAG_FILESOURCE 41728 /* File source */ -#define EXIFTAG_SCENETYPE 41729 /* Scene type */ -#define EXIFTAG_CFAPATTERN 41730 /* CFA pattern */ -#define EXIFTAG_CUSTOMRENDERED 41985 /* Custom image processing */ -#define EXIFTAG_EXPOSUREMODE 41986 /* Exposure mode */ -#define EXIFTAG_WHITEBALANCE 41987 /* White balance */ -#define EXIFTAG_DIGITALZOOMRATIO 41988 /* Digital zoom ratio */ -#define EXIFTAG_FOCALLENGTHIN35MMFILM 41989 /* Focal length in 35 mm film */ -#define EXIFTAG_SCENECAPTURETYPE 41990 /* Scene capture type */ -#define EXIFTAG_GAINCONTROL 41991 /* Gain control */ -#define EXIFTAG_CONTRAST 41992 /* Contrast */ -#define EXIFTAG_SATURATION 41993 /* Saturation */ -#define EXIFTAG_SHARPNESS 41994 /* Sharpness */ -#define EXIFTAG_DEVICESETTINGDESCRIPTION 41995 /* Device settings description */ -#define EXIFTAG_SUBJECTDISTANCERANGE 41996 /* Subject distance range */ -#define EXIFTAG_GAINCONTROL 41991 /* Gain control */ -#define EXIFTAG_GAINCONTROL 41991 /* Gain control */ -#define EXIFTAG_IMAGEUNIQUEID 42016 /* Unique image ID */ - -#endif /* _TIFF_ */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tiff.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef _TIFF_ +#define _TIFF_ + +#include "tiffconf.h" + +/* + * Tag Image File Format (TIFF) + * + * Based on Rev 6.0 from: + * Developer's Desk + * Aldus Corporation + * 411 First Ave. South + * Suite 200 + * Seattle, WA 98104 + * 206-622-5500 + * + * (http://partners.adobe.com/asn/developer/PDFS/TN/TIFF6.pdf) + * + * For BigTIFF design notes see the following links + * http://www.remotesensing.org/libtiff/bigtiffdesign.html + * http://www.awaresystems.be/imaging/tiff/bigtiff.html + */ + +#define TIFF_VERSION_CLASSIC 42 +#define TIFF_VERSION_BIG 43 + +#define TIFF_BIGENDIAN 0x4d4d +#define TIFF_LITTLEENDIAN 0x4949 +#define MDI_LITTLEENDIAN 0x5045 +#define MDI_BIGENDIAN 0x4550 + +/* + * Intrinsic data types required by the file format: + * + * 8-bit quantities int8/uint8 + * 16-bit quantities int16/uint16 + * 32-bit quantities int32/uint32 + * 64-bit quantities int64/uint64 + * strings unsigned char* + */ + +typedef TIFF_INT8_T int8; +typedef TIFF_UINT8_T uint8; + +typedef TIFF_INT16_T int16; +typedef TIFF_UINT16_T uint16; + +typedef TIFF_INT32_T int32; +typedef TIFF_UINT32_T uint32; + +typedef TIFF_INT64_T int64; +typedef TIFF_UINT64_T uint64; + +/* + * Some types as promoted in a variable argument list + * We use uint16_vap rather then directly using int, because this way + * we document the type we actually want to pass through, conceptually, + * rather then confusing the issue by merely stating the type it gets + * promoted to + */ + +typedef int uint16_vap; + +/* + * TIFF header. + */ +typedef struct { + uint16 tiff_magic; /* magic number (defines byte order) */ + uint16 tiff_version; /* TIFF version number */ +} TIFFHeaderCommon; +typedef struct { + uint16 tiff_magic; /* magic number (defines byte order) */ + uint16 tiff_version; /* TIFF version number */ + uint32 tiff_diroff; /* byte offset to first directory */ +} TIFFHeaderClassic; +typedef struct { + uint16 tiff_magic; /* magic number (defines byte order) */ + uint16 tiff_version; /* TIFF version number */ + uint16 tiff_offsetsize; /* size of offsets, should be 8 */ + uint16 tiff_unused; /* unused word, should be 0 */ + uint64 tiff_diroff; /* byte offset to first directory */ +} TIFFHeaderBig; + + +/* + * NB: In the comments below, + * - items marked with a + are obsoleted by revision 5.0, + * - items marked with a ! are introduced in revision 6.0. + * - items marked with a % are introduced post revision 6.0. + * - items marked with a $ are obsoleted by revision 6.0. + * - items marked with a & are introduced by Adobe DNG specification. + */ + +/* + * Tag data type information. + * + * Note: RATIONALs are the ratio of two 32-bit integer values. + */ +typedef enum { + TIFF_NOTYPE = 0, /* placeholder */ + TIFF_BYTE = 1, /* 8-bit unsigned integer */ + TIFF_ASCII = 2, /* 8-bit bytes w/ last byte null */ + TIFF_SHORT = 3, /* 16-bit unsigned integer */ + TIFF_LONG = 4, /* 32-bit unsigned integer */ + TIFF_RATIONAL = 5, /* 64-bit unsigned fraction */ + TIFF_SBYTE = 6, /* !8-bit signed integer */ + TIFF_UNDEFINED = 7, /* !8-bit untyped data */ + TIFF_SSHORT = 8, /* !16-bit signed integer */ + TIFF_SLONG = 9, /* !32-bit signed integer */ + TIFF_SRATIONAL = 10, /* !64-bit signed fraction */ + TIFF_FLOAT = 11, /* !32-bit IEEE floating point */ + TIFF_DOUBLE = 12, /* !64-bit IEEE floating point */ + TIFF_IFD = 13, /* %32-bit unsigned integer (offset) */ + TIFF_LONG8 = 16, /* BigTIFF 64-bit unsigned integer */ + TIFF_SLONG8 = 17, /* BigTIFF 64-bit signed integer */ + TIFF_IFD8 = 18 /* BigTIFF 64-bit unsigned integer (offset) */ +} TIFFDataType; + +/* + * TIFF Tag Definitions. + */ +#define TIFFTAG_SUBFILETYPE 254 /* subfile data descriptor */ +#define FILETYPE_REDUCEDIMAGE 0x1 /* reduced resolution version */ +#define FILETYPE_PAGE 0x2 /* one page of many */ +#define FILETYPE_MASK 0x4 /* transparency mask */ +#define TIFFTAG_OSUBFILETYPE 255 /* +kind of data in subfile */ +#define OFILETYPE_IMAGE 1 /* full resolution image data */ +#define OFILETYPE_REDUCEDIMAGE 2 /* reduced size image data */ +#define OFILETYPE_PAGE 3 /* one page of many */ +#define TIFFTAG_IMAGEWIDTH 256 /* image width in pixels */ +#define TIFFTAG_IMAGELENGTH 257 /* image height in pixels */ +#define TIFFTAG_BITSPERSAMPLE 258 /* bits per channel (sample) */ +#define TIFFTAG_COMPRESSION 259 /* data compression technique */ +#define COMPRESSION_NONE 1 /* dump mode */ +#define COMPRESSION_CCITTRLE 2 /* CCITT modified Huffman RLE */ +#define COMPRESSION_CCITTFAX3 3 /* CCITT Group 3 fax encoding */ +#define COMPRESSION_CCITT_T4 3 /* CCITT T.4 (TIFF 6 name) */ +#define COMPRESSION_CCITTFAX4 4 /* CCITT Group 4 fax encoding */ +#define COMPRESSION_CCITT_T6 4 /* CCITT T.6 (TIFF 6 name) */ +#define COMPRESSION_LZW 5 /* Lempel-Ziv & Welch */ +#define COMPRESSION_OJPEG 6 /* !6.0 JPEG */ +#define COMPRESSION_JPEG 7 /* %JPEG DCT compression */ +#define COMPRESSION_T85 9 /* !TIFF/FX T.85 JBIG compression */ +#define COMPRESSION_T43 10 /* !TIFF/FX T.43 colour by layered JBIG compression */ +#define COMPRESSION_NEXT 32766 /* NeXT 2-bit RLE */ +#define COMPRESSION_CCITTRLEW 32771 /* #1 w/ word alignment */ +#define COMPRESSION_PACKBITS 32773 /* Macintosh RLE */ +#define COMPRESSION_THUNDERSCAN 32809 /* ThunderScan RLE */ +/* codes 32895-32898 are reserved for ANSI IT8 TIFF/IT */ +#define COMPRESSION_DCS 32947 /* Kodak DCS encoding */ +#define COMPRESSION_JBIG 34661 /* ISO JBIG */ +#define COMPRESSION_SGILOG 34676 /* SGI Log Luminance RLE */ +#define COMPRESSION_SGILOG24 34677 /* SGI Log 24-bit packed */ +#define COMPRESSION_JP2000 34712 /* Leadtools JPEG2000 */ +#define COMPRESSION_LZMA 34925 /* LZMA2 */ +#define TIFFTAG_PHOTOMETRIC 262 /* photometric interpretation */ +#define PHOTOMETRIC_MINISWHITE 0 /* min value is white */ +#define PHOTOMETRIC_MINISBLACK 1 /* min value is black */ +#define PHOTOMETRIC_RGB 2 /* RGB color model */ +#define PHOTOMETRIC_PALETTE 3 /* color map indexed */ +#define PHOTOMETRIC_MASK 4 /* $holdout mask */ +#define PHOTOMETRIC_SEPARATED 5 /* !color separations */ +#define PHOTOMETRIC_YCBCR 6 /* !CCIR 601 */ +#define PHOTOMETRIC_CIELAB 8 /* !1976 CIE L*a*b* */ +#define PHOTOMETRIC_ICCLAB 9 /* ICC L*a*b* [Adobe TIFF Technote 4] */ +#define PHOTOMETRIC_ITULAB 10 /* ITU L*a*b* */ +#define PHOTOMETRIC_LOGL 32844 /* CIE Log2(L) */ +#define PHOTOMETRIC_LOGLUV 32845 /* CIE Log2(L) (u',v') */ +#define TIFFTAG_THRESHHOLDING 263 /* +thresholding used on data */ +#define THRESHHOLD_BILEVEL 1 /* b&w art scan */ +#define THRESHHOLD_HALFTONE 2 /* or dithered scan */ +#define THRESHHOLD_ERRORDIFFUSE 3 /* usually floyd-steinberg */ +#define TIFFTAG_CELLWIDTH 264 /* +dithering matrix width */ +#define TIFFTAG_CELLLENGTH 265 /* +dithering matrix height */ +#define TIFFTAG_FILLORDER 266 /* data order within a byte */ +#define FILLORDER_MSB2LSB 1 /* most significant -> least */ +#define FILLORDER_LSB2MSB 2 /* least significant -> most */ +#define TIFFTAG_DOCUMENTNAME 269 /* name of doc. image is from */ +#define TIFFTAG_IMAGEDESCRIPTION 270 /* info about image */ +#define TIFFTAG_MAKE 271 /* scanner manufacturer name */ +#define TIFFTAG_MODEL 272 /* scanner model name/number */ +#define TIFFTAG_STRIPOFFSETS 273 /* offsets to data strips */ +#define TIFFTAG_ORIENTATION 274 /* +image orientation */ +#define ORIENTATION_TOPLEFT 1 /* row 0 top, col 0 lhs */ +#define ORIENTATION_TOPRIGHT 2 /* row 0 top, col 0 rhs */ +#define ORIENTATION_BOTRIGHT 3 /* row 0 bottom, col 0 rhs */ +#define ORIENTATION_BOTLEFT 4 /* row 0 bottom, col 0 lhs */ +#define ORIENTATION_LEFTTOP 5 /* row 0 lhs, col 0 top */ +#define ORIENTATION_RIGHTTOP 6 /* row 0 rhs, col 0 top */ +#define ORIENTATION_RIGHTBOT 7 /* row 0 rhs, col 0 bottom */ +#define ORIENTATION_LEFTBOT 8 /* row 0 lhs, col 0 bottom */ +#define TIFFTAG_SAMPLESPERPIXEL 277 /* samples per pixel */ +#define TIFFTAG_ROWSPERSTRIP 278 /* rows per strip of data */ +#define TIFFTAG_STRIPBYTECOUNTS 279 /* bytes counts for strips */ +#define TIFFTAG_MINSAMPLEVALUE 280 /* +minimum sample value */ +#define TIFFTAG_MAXSAMPLEVALUE 281 /* +maximum sample value */ +#define TIFFTAG_XRESOLUTION 282 /* pixels/resolution in x */ +#define TIFFTAG_YRESOLUTION 283 /* pixels/resolution in y */ +#define TIFFTAG_PLANARCONFIG 284 /* storage organization */ +#define PLANARCONFIG_CONTIG 1 /* single image plane */ +#define PLANARCONFIG_SEPARATE 2 /* separate planes of data */ +#define TIFFTAG_PAGENAME 285 /* page name image is from */ +#define TIFFTAG_XPOSITION 286 /* x page offset of image lhs */ +#define TIFFTAG_YPOSITION 287 /* y page offset of image lhs */ +#define TIFFTAG_FREEOFFSETS 288 /* +byte offset to free block */ +#define TIFFTAG_FREEBYTECOUNTS 289 /* +sizes of free blocks */ +#define TIFFTAG_GRAYRESPONSEUNIT 290 /* $gray scale curve accuracy */ +#define GRAYRESPONSEUNIT_10S 1 /* tenths of a unit */ +#define GRAYRESPONSEUNIT_100S 2 /* hundredths of a unit */ +#define GRAYRESPONSEUNIT_1000S 3 /* thousandths of a unit */ +#define GRAYRESPONSEUNIT_10000S 4 /* ten-thousandths of a unit */ +#define GRAYRESPONSEUNIT_100000S 5 /* hundred-thousandths */ +#define TIFFTAG_GRAYRESPONSECURVE 291 /* $gray scale response curve */ +#define TIFFTAG_GROUP3OPTIONS 292 /* 32 flag bits */ +#define TIFFTAG_T4OPTIONS 292 /* TIFF 6.0 proper name alias */ +#define GROUP3OPT_2DENCODING 0x1 /* 2-dimensional coding */ +#define GROUP3OPT_UNCOMPRESSED 0x2 /* data not compressed */ +#define GROUP3OPT_FILLBITS 0x4 /* fill to byte boundary */ +#define TIFFTAG_GROUP4OPTIONS 293 /* 32 flag bits */ +#define TIFFTAG_T6OPTIONS 293 /* TIFF 6.0 proper name */ +#define GROUP4OPT_UNCOMPRESSED 0x2 /* data not compressed */ +#define TIFFTAG_RESOLUTIONUNIT 296 /* units of resolutions */ +#define RESUNIT_NONE 1 /* no meaningful units */ +#define RESUNIT_INCH 2 /* english */ +#define RESUNIT_CENTIMETER 3 /* metric */ +#define TIFFTAG_PAGENUMBER 297 /* page numbers of multi-page */ +#define TIFFTAG_COLORRESPONSEUNIT 300 /* $color curve accuracy */ +#define COLORRESPONSEUNIT_10S 1 /* tenths of a unit */ +#define COLORRESPONSEUNIT_100S 2 /* hundredths of a unit */ +#define COLORRESPONSEUNIT_1000S 3 /* thousandths of a unit */ +#define COLORRESPONSEUNIT_10000S 4 /* ten-thousandths of a unit */ +#define COLORRESPONSEUNIT_100000S 5 /* hundred-thousandths */ +#define TIFFTAG_TRANSFERFUNCTION 301 /* !colorimetry info */ +#define TIFFTAG_SOFTWARE 305 /* name & release */ +#define TIFFTAG_DATETIME 306 /* creation date and time */ +#define TIFFTAG_ARTIST 315 /* creator of image */ +#define TIFFTAG_HOSTCOMPUTER 316 /* machine where created */ +#define TIFFTAG_PREDICTOR 317 /* prediction scheme w/ LZW */ +#define PREDICTOR_NONE 1 /* no prediction scheme used */ +#define PREDICTOR_HORIZONTAL 2 /* horizontal differencing */ +#define PREDICTOR_FLOATINGPOINT 3 /* floating point predictor */ +#define TIFFTAG_WHITEPOINT 318 /* image white point */ +#define TIFFTAG_PRIMARYCHROMATICITIES 319 /* !primary chromaticities */ +#define TIFFTAG_COLORMAP 320 /* RGB map for pallette image */ +#define TIFFTAG_HALFTONEHINTS 321 /* !highlight+shadow info */ +#define TIFFTAG_TILEWIDTH 322 /* !tile width in pixels */ +#define TIFFTAG_TILELENGTH 323 /* !tile height in pixels */ +#define TIFFTAG_TILEOFFSETS 324 /* !offsets to data tiles */ +#define TIFFTAG_TILEBYTECOUNTS 325 /* !byte counts for tiles */ +#define TIFFTAG_BADFAXLINES 326 /* lines w/ wrong pixel count */ +#define TIFFTAG_CLEANFAXDATA 327 /* regenerated line info */ +#define CLEANFAXDATA_CLEAN 0 /* no errors detected */ +#define CLEANFAXDATA_REGENERATED 1 /* receiver regenerated lines */ +#define CLEANFAXDATA_UNCLEAN 2 /* uncorrected errors exist */ +#define TIFFTAG_CONSECUTIVEBADFAXLINES 328 /* max consecutive bad lines */ +#define TIFFTAG_SUBIFD 330 /* subimage descriptors */ +#define TIFFTAG_INKSET 332 /* !inks in separated image */ +#define INKSET_CMYK 1 /* !cyan-magenta-yellow-black color */ +#define INKSET_MULTIINK 2 /* !multi-ink or hi-fi color */ +#define TIFFTAG_INKNAMES 333 /* !ascii names of inks */ +#define TIFFTAG_NUMBEROFINKS 334 /* !number of inks */ +#define TIFFTAG_DOTRANGE 336 /* !0% and 100% dot codes */ +#define TIFFTAG_TARGETPRINTER 337 /* !separation target */ +#define TIFFTAG_EXTRASAMPLES 338 /* !info about extra samples */ +#define EXTRASAMPLE_UNSPECIFIED 0 /* !unspecified data */ +#define EXTRASAMPLE_ASSOCALPHA 1 /* !associated alpha data */ +#define EXTRASAMPLE_UNASSALPHA 2 /* !unassociated alpha data */ +#define TIFFTAG_SAMPLEFORMAT 339 /* !data sample format */ +#define SAMPLEFORMAT_UINT 1 /* !unsigned integer data */ +#define SAMPLEFORMAT_INT 2 /* !signed integer data */ +#define SAMPLEFORMAT_IEEEFP 3 /* !IEEE floating point data */ +#define SAMPLEFORMAT_VOID 4 /* !untyped data */ +#define SAMPLEFORMAT_COMPLEXINT 5 /* !complex signed int */ +#define SAMPLEFORMAT_COMPLEXIEEEFP 6 /* !complex ieee floating */ +#define TIFFTAG_SMINSAMPLEVALUE 340 /* !variable MinSampleValue */ +#define TIFFTAG_SMAXSAMPLEVALUE 341 /* !variable MaxSampleValue */ +#define TIFFTAG_CLIPPATH 343 /* %ClipPath + [Adobe TIFF technote 2] */ +#define TIFFTAG_XCLIPPATHUNITS 344 /* %XClipPathUnits + [Adobe TIFF technote 2] */ +#define TIFFTAG_YCLIPPATHUNITS 345 /* %YClipPathUnits + [Adobe TIFF technote 2] */ +#define TIFFTAG_INDEXED 346 /* %Indexed + [Adobe TIFF Technote 3] */ +#define TIFFTAG_JPEGTABLES 347 /* %JPEG table stream */ +#define TIFFTAG_OPIPROXY 351 /* %OPI Proxy [Adobe TIFF technote] */ +/* Tags 400-435 are from the TIFF/FX spec */ +#define TIFFTAG_GLOBALPARAMETERSIFD 400 /* ! */ +#define TIFFTAG_PROFILETYPE 401 /* ! */ +#define PROFILETYPE_UNSPECIFIED 0 /* ! */ +#define PROFILETYPE_G3_FAX 1 /* ! */ +#define TIFFTAG_FAXPROFILE 402 /* ! */ +#define FAXPROFILE_S 1 /* !TIFF/FX FAX profile S */ +#define FAXPROFILE_F 2 /* !TIFF/FX FAX profile F */ +#define FAXPROFILE_J 3 /* !TIFF/FX FAX profile J */ +#define FAXPROFILE_C 4 /* !TIFF/FX FAX profile C */ +#define FAXPROFILE_L 5 /* !TIFF/FX FAX profile L */ +#define FAXPROFILE_M 6 /* !TIFF/FX FAX profile LM */ +#define TIFFTAG_CODINGMETHODS 403 /* !TIFF/FX coding methods */ +#define CODINGMETHODS_T4_1D (1 << 1) /* !T.4 1D */ +#define CODINGMETHODS_T4_2D (1 << 2) /* !T.4 2D */ +#define CODINGMETHODS_T6 (1 << 3) /* !T.6 */ +#define CODINGMETHODS_T85 (1 << 4) /* !T.85 JBIG */ +#define CODINGMETHODS_T42 (1 << 5) /* !T.42 JPEG */ +#define CODINGMETHODS_T43 (1 << 6) /* !T.43 colour by layered JBIG */ +#define TIFFTAG_VERSIONYEAR 404 /* !TIFF/FX version year */ +#define TIFFTAG_MODENUMBER 405 /* !TIFF/FX mode number */ +#define TIFFTAG_DECODE 433 /* !TIFF/FX decode */ +#define TIFFTAG_IMAGEBASECOLOR 434 /* !TIFF/FX image base colour */ +#define TIFFTAG_T82OPTIONS 435 /* !TIFF/FX T.82 options */ +/* + * Tags 512-521 are obsoleted by Technical Note #2 which specifies a + * revised JPEG-in-TIFF scheme. + */ +#define TIFFTAG_JPEGPROC 512 /* !JPEG processing algorithm */ +#define JPEGPROC_BASELINE 1 /* !baseline sequential */ +#define JPEGPROC_LOSSLESS 14 /* !Huffman coded lossless */ +#define TIFFTAG_JPEGIFOFFSET 513 /* !pointer to SOI marker */ +#define TIFFTAG_JPEGIFBYTECOUNT 514 /* !JFIF stream length */ +#define TIFFTAG_JPEGRESTARTINTERVAL 515 /* !restart interval length */ +#define TIFFTAG_JPEGLOSSLESSPREDICTORS 517 /* !lossless proc predictor */ +#define TIFFTAG_JPEGPOINTTRANSFORM 518 /* !lossless point transform */ +#define TIFFTAG_JPEGQTABLES 519 /* !Q matrice offsets */ +#define TIFFTAG_JPEGDCTABLES 520 /* !DCT table offsets */ +#define TIFFTAG_JPEGACTABLES 521 /* !AC coefficient offsets */ +#define TIFFTAG_YCBCRCOEFFICIENTS 529 /* !RGB -> YCbCr transform */ +#define TIFFTAG_YCBCRSUBSAMPLING 530 /* !YCbCr subsampling factors */ +#define TIFFTAG_YCBCRPOSITIONING 531 /* !subsample positioning */ +#define YCBCRPOSITION_CENTERED 1 /* !as in PostScript Level 2 */ +#define YCBCRPOSITION_COSITED 2 /* !as in CCIR 601-1 */ +#define TIFFTAG_REFERENCEBLACKWHITE 532 /* !colorimetry info */ +#define TIFFTAG_STRIPROWCOUNTS 559 /* !TIFF/FX strip row counts */ +#define TIFFTAG_XMLPACKET 700 /* %XML packet + [Adobe XMP Specification, + January 2004 */ +#define TIFFTAG_OPIIMAGEID 32781 /* %OPI ImageID + [Adobe TIFF technote] */ +/* tags 32952-32956 are private tags registered to Island Graphics */ +#define TIFFTAG_REFPTS 32953 /* image reference points */ +#define TIFFTAG_REGIONTACKPOINT 32954 /* region-xform tack point */ +#define TIFFTAG_REGIONWARPCORNERS 32955 /* warp quadrilateral */ +#define TIFFTAG_REGIONAFFINE 32956 /* affine transformation mat */ +/* tags 32995-32999 are private tags registered to SGI */ +#define TIFFTAG_MATTEING 32995 /* $use ExtraSamples */ +#define TIFFTAG_DATATYPE 32996 /* $use SampleFormat */ +#define TIFFTAG_IMAGEDEPTH 32997 /* z depth of image */ +#define TIFFTAG_TILEDEPTH 32998 /* z depth/data tile */ +/* tags 33300-33309 are private tags registered to Pixar */ +/* + * TIFFTAG_PIXAR_IMAGEFULLWIDTH and TIFFTAG_PIXAR_IMAGEFULLLENGTH + * are set when an image has been cropped out of a larger image. + * They reflect the size of the original uncropped image. + * The TIFFTAG_XPOSITION and TIFFTAG_YPOSITION can be used + * to determine the position of the smaller image in the larger one. + */ +#define TIFFTAG_PIXAR_IMAGEFULLWIDTH 33300 /* full image size in x */ +#define TIFFTAG_PIXAR_IMAGEFULLLENGTH 33301 /* full image size in y */ + /* Tags 33302-33306 are used to identify special image modes and data + * used by Pixar's texture formats. + */ +#define TIFFTAG_PIXAR_TEXTUREFORMAT 33302 /* texture map format */ +#define TIFFTAG_PIXAR_WRAPMODES 33303 /* s & t wrap modes */ +#define TIFFTAG_PIXAR_FOVCOT 33304 /* cotan(fov) for env. maps */ +#define TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN 33305 +#define TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA 33306 +/* tag 33405 is a private tag registered to Eastman Kodak */ +#define TIFFTAG_WRITERSERIALNUMBER 33405 /* device serial number */ +/* tag 33432 is listed in the 6.0 spec w/ unknown ownership */ +#define TIFFTAG_COPYRIGHT 33432 /* copyright string */ +/* IPTC TAG from RichTIFF specifications */ +#define TIFFTAG_RICHTIFFIPTC 33723 +/* 34016-34029 are reserved for ANSI IT8 TIFF/IT */ +#define TIFFTAG_STONITS 37439 /* Sample value to Nits */ +/* tag 34929 is a private tag registered to FedEx */ +#define TIFFTAG_FEDEX_EDR 34929 /* unknown use */ +#define TIFFTAG_INTEROPERABILITYIFD 40965 /* Pointer to Interoperability private directory */ +/* Adobe Digital Negative (DNG) format tags */ +#define TIFFTAG_DNGVERSION 50706 /* &DNG version number */ +#define TIFFTAG_DNGBACKWARDVERSION 50707 /* &DNG compatibility version */ +#define TIFFTAG_UNIQUECAMERAMODEL 50708 /* &name for the camera model */ +#define TIFFTAG_LOCALIZEDCAMERAMODEL 50709 /* &localized camera model + name */ +#define TIFFTAG_CFAPLANECOLOR 50710 /* &CFAPattern->LinearRaw space + mapping */ +#define TIFFTAG_CFALAYOUT 50711 /* &spatial layout of the CFA */ +#define TIFFTAG_LINEARIZATIONTABLE 50712 /* &lookup table description */ +#define TIFFTAG_BLACKLEVELREPEATDIM 50713 /* &repeat pattern size for + the BlackLevel tag */ +#define TIFFTAG_BLACKLEVEL 50714 /* &zero light encoding level */ +#define TIFFTAG_BLACKLEVELDELTAH 50715 /* &zero light encoding level + differences (columns) */ +#define TIFFTAG_BLACKLEVELDELTAV 50716 /* &zero light encoding level + differences (rows) */ +#define TIFFTAG_WHITELEVEL 50717 /* &fully saturated encoding + level */ +#define TIFFTAG_DEFAULTSCALE 50718 /* &default scale factors */ +#define TIFFTAG_DEFAULTCROPORIGIN 50719 /* &origin of the final image + area */ +#define TIFFTAG_DEFAULTCROPSIZE 50720 /* &size of the final image + area */ +#define TIFFTAG_COLORMATRIX1 50721 /* &XYZ->reference color space + transformation matrix 1 */ +#define TIFFTAG_COLORMATRIX2 50722 /* &XYZ->reference color space + transformation matrix 2 */ +#define TIFFTAG_CAMERACALIBRATION1 50723 /* &calibration matrix 1 */ +#define TIFFTAG_CAMERACALIBRATION2 50724 /* &calibration matrix 2 */ +#define TIFFTAG_REDUCTIONMATRIX1 50725 /* &dimensionality reduction + matrix 1 */ +#define TIFFTAG_REDUCTIONMATRIX2 50726 /* &dimensionality reduction + matrix 2 */ +#define TIFFTAG_ANALOGBALANCE 50727 /* &gain applied the stored raw + values*/ +#define TIFFTAG_ASSHOTNEUTRAL 50728 /* &selected white balance in + linear reference space */ +#define TIFFTAG_ASSHOTWHITEXY 50729 /* &selected white balance in + x-y chromaticity + coordinates */ +#define TIFFTAG_BASELINEEXPOSURE 50730 /* &how much to move the zero + point */ +#define TIFFTAG_BASELINENOISE 50731 /* &relative noise level */ +#define TIFFTAG_BASELINESHARPNESS 50732 /* &relative amount of + sharpening */ +#define TIFFTAG_BAYERGREENSPLIT 50733 /* &how closely the values of + the green pixels in the + blue/green rows track the + values of the green pixels + in the red/green rows */ +#define TIFFTAG_LINEARRESPONSELIMIT 50734 /* &non-linear encoding range */ +#define TIFFTAG_CAMERASERIALNUMBER 50735 /* &camera's serial number */ +#define TIFFTAG_LENSINFO 50736 /* info about the lens */ +#define TIFFTAG_CHROMABLURRADIUS 50737 /* &chroma blur radius */ +#define TIFFTAG_ANTIALIASSTRENGTH 50738 /* &relative strength of the + camera's anti-alias filter */ +#define TIFFTAG_SHADOWSCALE 50739 /* &used by Adobe Camera Raw */ +#define TIFFTAG_DNGPRIVATEDATA 50740 /* &manufacturer's private data */ +#define TIFFTAG_MAKERNOTESAFETY 50741 /* &whether the EXIF MakerNote + tag is safe to preserve + along with the rest of the + EXIF data */ +#define TIFFTAG_CALIBRATIONILLUMINANT1 50778 /* &illuminant 1 */ +#define TIFFTAG_CALIBRATIONILLUMINANT2 50779 /* &illuminant 2 */ +#define TIFFTAG_BESTQUALITYSCALE 50780 /* &best quality multiplier */ +#define TIFFTAG_RAWDATAUNIQUEID 50781 /* &unique identifier for + the raw image data */ +#define TIFFTAG_ORIGINALRAWFILENAME 50827 /* &file name of the original + raw file */ +#define TIFFTAG_ORIGINALRAWFILEDATA 50828 /* &contents of the original + raw file */ +#define TIFFTAG_ACTIVEAREA 50829 /* &active (non-masked) pixels + of the sensor */ +#define TIFFTAG_MASKEDAREAS 50830 /* &list of coordinates + of fully masked pixels */ +#define TIFFTAG_ASSHOTICCPROFILE 50831 /* &these two tags used to */ +#define TIFFTAG_ASSHOTPREPROFILEMATRIX 50832 /* map cameras's color space + into ICC profile space */ +#define TIFFTAG_CURRENTICCPROFILE 50833 /* & */ +#define TIFFTAG_CURRENTPREPROFILEMATRIX 50834 /* & */ +/* tag 65535 is an undefined tag used by Eastman Kodak */ +#define TIFFTAG_DCSHUESHIFTVALUES 65535 /* hue shift correction data */ + +/* + * The following are ``pseudo tags'' that can be used to control + * codec-specific functionality. These tags are not written to file. + * Note that these values start at 0xffff+1 so that they'll never + * collide with Aldus-assigned tags. + * + * If you want your private pseudo tags ``registered'' (i.e. added to + * this file), please post a bug report via the tracking system at + * http://www.remotesensing.org/libtiff/bugs.html with the appropriate + * C definitions to add. + */ +#define TIFFTAG_FAXMODE 65536 /* Group 3/4 format control */ +#define FAXMODE_CLASSIC 0x0000 /* default, include RTC */ +#define FAXMODE_NORTC 0x0001 /* no RTC at end of data */ +#define FAXMODE_NOEOL 0x0002 /* no EOL code at end of row */ +#define FAXMODE_BYTEALIGN 0x0004 /* byte align row */ +#define FAXMODE_WORDALIGN 0x0008 /* word align row */ +#define FAXMODE_CLASSF FAXMODE_NORTC /* TIFF Class F */ +#define TIFFTAG_JPEGQUALITY 65537 /* Compression quality level */ +/* Note: quality level is on the IJG 0-100 scale. Default value is 75 */ +#define TIFFTAG_JPEGCOLORMODE 65538 /* Auto RGB<=>YCbCr convert? */ +#define JPEGCOLORMODE_RAW 0x0000 /* no conversion (default) */ +#define JPEGCOLORMODE_RGB 0x0001 /* do auto conversion */ +#define TIFFTAG_JPEGTABLESMODE 65539 /* What to put in JPEGTables */ +#define JPEGTABLESMODE_QUANT 0x0001 /* include quantization tbls */ +#define JPEGTABLESMODE_HUFF 0x0002 /* include Huffman tbls */ +/* Note: default is JPEGTABLESMODE_QUANT | JPEGTABLESMODE_HUFF */ +#define TIFFTAG_FAXFILLFUNC 65540 /* G3/G4 fill function */ +#define TIFFTAG_PIXARLOGDATAFMT 65549 /* PixarLogCodec I/O data sz */ +#define PIXARLOGDATAFMT_8BIT 0 /* regular u_char samples */ +#define PIXARLOGDATAFMT_8BITABGR 1 /* ABGR-order u_chars */ +#define PIXARLOGDATAFMT_11BITLOG 2 /* 11-bit log-encoded (raw) */ +#define PIXARLOGDATAFMT_12BITPICIO 3 /* as per PICIO (1.0==2048) */ +#define PIXARLOGDATAFMT_16BIT 4 /* signed short samples */ +#define PIXARLOGDATAFMT_FLOAT 5 /* IEEE float samples */ +/* 65550-65556 are allocated to Oceana Matrix */ +#define TIFFTAG_DCSIMAGERTYPE 65550 /* imager model & filter */ +#define DCSIMAGERMODEL_M3 0 /* M3 chip (1280 x 1024) */ +#define DCSIMAGERMODEL_M5 1 /* M5 chip (1536 x 1024) */ +#define DCSIMAGERMODEL_M6 2 /* M6 chip (3072 x 2048) */ +#define DCSIMAGERFILTER_IR 0 /* infrared filter */ +#define DCSIMAGERFILTER_MONO 1 /* monochrome filter */ +#define DCSIMAGERFILTER_CFA 2 /* color filter array */ +#define DCSIMAGERFILTER_OTHER 3 /* other filter */ +#define TIFFTAG_DCSINTERPMODE 65551 /* interpolation mode */ +#define DCSINTERPMODE_NORMAL 0x0 /* whole image, default */ +#define DCSINTERPMODE_PREVIEW 0x1 /* preview of image (384x256) */ +#define TIFFTAG_DCSBALANCEARRAY 65552 /* color balance values */ +#define TIFFTAG_DCSCORRECTMATRIX 65553 /* color correction values */ +#define TIFFTAG_DCSGAMMA 65554 /* gamma value */ +#define TIFFTAG_DCSTOESHOULDERPTS 65555 /* toe & shoulder points */ +#define TIFFTAG_DCSCALIBRATIONFD 65556 /* calibration file desc */ +/* Note: quality level is on the ZLIB 1-9 scale. Default value is -1 */ +#define TIFFTAG_ZIPQUALITY 65557 /* compression quality level */ +#define TIFFTAG_PIXARLOGQUALITY 65558 /* PixarLog uses same scale */ +/* 65559 is allocated to Oceana Matrix */ +#define TIFFTAG_DCSCLIPRECTANGLE 65559 /* area of image to acquire */ +#define TIFFTAG_SGILOGDATAFMT 65560 /* SGILog user data format */ +#define SGILOGDATAFMT_FLOAT 0 /* IEEE float samples */ +#define SGILOGDATAFMT_16BIT 1 /* 16-bit samples */ +#define SGILOGDATAFMT_RAW 2 /* uninterpreted data */ +#define SGILOGDATAFMT_8BIT 3 /* 8-bit RGB monitor values */ +#define TIFFTAG_SGILOGENCODE 65561 /* SGILog data encoding control*/ +#define SGILOGENCODE_NODITHER 0 /* do not dither encoded values*/ +#define SGILOGENCODE_RANDITHER 1 /* randomly dither encd values */ +#define TIFFTAG_LZMAPRESET 65562 /* LZMA2 preset (compression level) */ +#define TIFFTAG_PERSAMPLE 65563 /* interface for per sample tags */ +#define PERSAMPLE_MERGED 0 /* present as a single value */ +#define PERSAMPLE_MULTI 1 /* present as multiple values */ + +/* + * EXIF tags + */ +#define EXIFTAG_EXPOSURETIME 33434 /* Exposure time */ +#define EXIFTAG_FNUMBER 33437 /* F number */ +#define EXIFTAG_EXPOSUREPROGRAM 34850 /* Exposure program */ +#define EXIFTAG_SPECTRALSENSITIVITY 34852 /* Spectral sensitivity */ +#define EXIFTAG_ISOSPEEDRATINGS 34855 /* ISO speed rating */ +#define EXIFTAG_OECF 34856 /* Optoelectric conversion + factor */ +#define EXIFTAG_EXIFVERSION 36864 /* Exif version */ +#define EXIFTAG_DATETIMEORIGINAL 36867 /* Date and time of original + data generation */ +#define EXIFTAG_DATETIMEDIGITIZED 36868 /* Date and time of digital + data generation */ +#define EXIFTAG_COMPONENTSCONFIGURATION 37121 /* Meaning of each component */ +#define EXIFTAG_COMPRESSEDBITSPERPIXEL 37122 /* Image compression mode */ +#define EXIFTAG_SHUTTERSPEEDVALUE 37377 /* Shutter speed */ +#define EXIFTAG_APERTUREVALUE 37378 /* Aperture */ +#define EXIFTAG_BRIGHTNESSVALUE 37379 /* Brightness */ +#define EXIFTAG_EXPOSUREBIASVALUE 37380 /* Exposure bias */ +#define EXIFTAG_MAXAPERTUREVALUE 37381 /* Maximum lens aperture */ +#define EXIFTAG_SUBJECTDISTANCE 37382 /* Subject distance */ +#define EXIFTAG_METERINGMODE 37383 /* Metering mode */ +#define EXIFTAG_LIGHTSOURCE 37384 /* Light source */ +#define EXIFTAG_FLASH 37385 /* Flash */ +#define EXIFTAG_FOCALLENGTH 37386 /* Lens focal length */ +#define EXIFTAG_SUBJECTAREA 37396 /* Subject area */ +#define EXIFTAG_MAKERNOTE 37500 /* Manufacturer notes */ +#define EXIFTAG_USERCOMMENT 37510 /* User comments */ +#define EXIFTAG_SUBSECTIME 37520 /* DateTime subseconds */ +#define EXIFTAG_SUBSECTIMEORIGINAL 37521 /* DateTimeOriginal subseconds */ +#define EXIFTAG_SUBSECTIMEDIGITIZED 37522 /* DateTimeDigitized subseconds */ +#define EXIFTAG_FLASHPIXVERSION 40960 /* Supported Flashpix version */ +#define EXIFTAG_COLORSPACE 40961 /* Color space information */ +#define EXIFTAG_PIXELXDIMENSION 40962 /* Valid image width */ +#define EXIFTAG_PIXELYDIMENSION 40963 /* Valid image height */ +#define EXIFTAG_RELATEDSOUNDFILE 40964 /* Related audio file */ +#define EXIFTAG_FLASHENERGY 41483 /* Flash energy */ +#define EXIFTAG_SPATIALFREQUENCYRESPONSE 41484 /* Spatial frequency response */ +#define EXIFTAG_FOCALPLANEXRESOLUTION 41486 /* Focal plane X resolution */ +#define EXIFTAG_FOCALPLANEYRESOLUTION 41487 /* Focal plane Y resolution */ +#define EXIFTAG_FOCALPLANERESOLUTIONUNIT 41488 /* Focal plane resolution unit */ +#define EXIFTAG_SUBJECTLOCATION 41492 /* Subject location */ +#define EXIFTAG_EXPOSUREINDEX 41493 /* Exposure index */ +#define EXIFTAG_SENSINGMETHOD 41495 /* Sensing method */ +#define EXIFTAG_FILESOURCE 41728 /* File source */ +#define EXIFTAG_SCENETYPE 41729 /* Scene type */ +#define EXIFTAG_CFAPATTERN 41730 /* CFA pattern */ +#define EXIFTAG_CUSTOMRENDERED 41985 /* Custom image processing */ +#define EXIFTAG_EXPOSUREMODE 41986 /* Exposure mode */ +#define EXIFTAG_WHITEBALANCE 41987 /* White balance */ +#define EXIFTAG_DIGITALZOOMRATIO 41988 /* Digital zoom ratio */ +#define EXIFTAG_FOCALLENGTHIN35MMFILM 41989 /* Focal length in 35 mm film */ +#define EXIFTAG_SCENECAPTURETYPE 41990 /* Scene capture type */ +#define EXIFTAG_GAINCONTROL 41991 /* Gain control */ +#define EXIFTAG_CONTRAST 41992 /* Contrast */ +#define EXIFTAG_SATURATION 41993 /* Saturation */ +#define EXIFTAG_SHARPNESS 41994 /* Sharpness */ +#define EXIFTAG_DEVICESETTINGDESCRIPTION 41995 /* Device settings description */ +#define EXIFTAG_SUBJECTDISTANCERANGE 41996 /* Subject distance range */ +#define EXIFTAG_GAINCONTROL 41991 /* Gain control */ +#define EXIFTAG_GAINCONTROL 41991 /* Gain control */ +#define EXIFTAG_IMAGEUNIQUEID 42016 /* Unique image ID */ + +#endif /* _TIFF_ */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tiffconf.h b/Source/LibTIFF4/tiffconf.h index 39b38a5..d4b4280 100644 --- a/Source/LibTIFF4/tiffconf.h +++ b/Source/LibTIFF4/tiffconf.h @@ -1,174 +1,174 @@ -/* - Configuration defines for installed libtiff. - This file maintained for backward compatibility. Do not use definitions - from this file in your programs. -*/ - -#ifndef _TIFFCONF_ -#define _TIFFCONF_ - -/* The size of a `int', as computed by sizeof. */ -#define SIZEOF_INT 4 - -/* The size of a `long', as computed by sizeof. */ -#include -#if (LONG_MAX == +9223372036854775807L) -#define SIZEOF_LONG 8 -#define SIZEOF_UNSIGNED_LONG 8 -#elif (LONG_MAX == +2147483647) -#define SIZEOF_LONG 4 -#define SIZEOF_UNSIGNED_LONG 4 -#else -#error "Cannot detect SIZEOF_LONG" -#endif - -/* Signed 8-bit type */ -#define TIFF_INT8_T signed char - -/* Unsigned 8-bit type */ -#define TIFF_UINT8_T unsigned char - -/* Signed 16-bit type */ -#define TIFF_INT16_T signed short - -/* Unsigned 16-bit type */ -#define TIFF_UINT16_T unsigned short - -/* Signed 32-bit type */ -#define TIFF_INT32_T signed int - -/* Unsigned 32-bit type */ -#define TIFF_UINT32_T unsigned int - -/* Signed 64-bit type */ -#ifdef _MSC_VER -#define TIFF_INT64_T signed __int64 -#else -#define TIFF_INT64_T signed long -#endif // _MSC_VER - -/* Unsigned 64-bit type */ -#ifdef _MSC_VER -#define TIFF_UINT64_T unsigned __int64 -#else -#define TIFF_UINT64_T unsigned long -#endif // _MSC_VER - -/* Signed 64-bit type */ -#if defined(_WIN64) -#define TIFF_SSIZE_T signed __int64 -#else -#define TIFF_SSIZE_T signed long -#endif - -/* Pointer difference type */ -#define TIFF_PTRDIFF_T ptrdiff_t - -/* Compatibility stuff. */ - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#define HAVE_IEEEFP 1 - -/* ------------------------------------------------------------------------ -Byte order ------------------------------------------------------------------------ -*/ - -/* -Define WORDS_BIGENDIAN to 1 if your processor stores words with the most -significant byte first (like Motorola and SPARC, unlike Intel). -Some versions of gcc may have BYTE_ORDER or __BYTE_ORDER defined -If your big endian system isn't being detected, add an OS specific check -*/ -#if (defined(BYTE_ORDER) && BYTE_ORDER==BIG_ENDIAN) || \ - (defined(__BYTE_ORDER) && __BYTE_ORDER==__BIG_ENDIAN) || \ - defined(__BIG_ENDIAN__) -/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ -#define HOST_FILLORDER FILLORDER_MSB2LSB -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ -#define WORDS_BIGENDIAN 1 -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ -#define HOST_BIGENDIAN 1 -#else -/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ -#define HOST_FILLORDER FILLORDER_LSB2MSB -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ -#undef WORDS_BIGENDIAN -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ -#undef HOST_BIGENDIAN -#endif // BYTE_ORDER - -/* Support CCITT Group 3 & 4 algorithms */ -#define CCITT_SUPPORT 1 - -/* Support JPEG compression (requires IJG JPEG library) */ -#define JPEG_SUPPORT 1 - -/* Support JBIG compression (requires JBIG-KIT library) */ -/* #undef JBIG_SUPPORT */ - -/* Support LogLuv high dynamic range encoding */ -#define LOGLUV_SUPPORT 1 - -/* Support LZW algorithm */ -#define LZW_SUPPORT 1 - -/* Support NeXT 2-bit RLE algorithm */ -#define NEXT_SUPPORT 1 - -/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation - fails with unpatched IJG JPEG library) */ -#define OJPEG_SUPPORT 1 - -/* Support Macintosh PackBits algorithm */ -#define PACKBITS_SUPPORT 1 - -/* Support Pixar log-format algorithm (requires Zlib) */ -#define PIXARLOG_SUPPORT 1 - -/* Support ThunderScan 4-bit RLE algorithm */ -#define THUNDER_SUPPORT 1 - -/* Support Deflate compression */ -#define ZIP_SUPPORT 1 - -/* Support LZMA2 compression */ -#undef LZMA_SUPPORT - -/* Support Microsoft Document Imaging format */ -#undef MDI_SUPPORT - -/* Support strip chopping (whether or not to convert single-strip uncompressed - images to mutiple strips of ~8Kb to reduce memory usage) */ -#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP - -/* Enable SubIFD tag (330) support */ -#define SUBIFD_SUPPORT 1 - -/* Treat extra sample as alpha (default enabled). The RGBA interface will - treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many - packages produce RGBA files but don't mark the alpha properly. */ -#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1 - -/* Pick up YCbCr subsampling info from the JPEG data stream to support files - lacking the tag (default enabled). */ -#define CHECK_JPEG_YCBCR_SUBSAMPLING 1 - -/* Support MS MDI magic number files as TIFF */ -/* #undef MDI_SUPPORT */ - -/* - * Feature support definitions. - * XXX: These macros are obsoleted. Don't use them in your apps! - * Macros stays here for backward compatibility and should be always defined. - */ -#define COLORIMETRY_SUPPORT -#define YCBCR_SUPPORT -#define CMYK_SUPPORT -#define ICC_SUPPORT -#define PHOTOSHOP_SUPPORT -#define IPTC_SUPPORT - -#endif /* _TIFFCONF_ */ +/* + Configuration defines for installed libtiff. + This file maintained for backward compatibility. Do not use definitions + from this file in your programs. +*/ + +#ifndef _TIFFCONF_ +#define _TIFFCONF_ + +/* The size of a `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of a `long', as computed by sizeof. */ +#include +#if (LONG_MAX == +9223372036854775807L) +#define SIZEOF_LONG 8 +#define SIZEOF_UNSIGNED_LONG 8 +#elif (LONG_MAX == +2147483647) +#define SIZEOF_LONG 4 +#define SIZEOF_UNSIGNED_LONG 4 +#else +#error "Cannot detect SIZEOF_LONG" +#endif + +/* Signed 8-bit type */ +#define TIFF_INT8_T signed char + +/* Unsigned 8-bit type */ +#define TIFF_UINT8_T unsigned char + +/* Signed 16-bit type */ +#define TIFF_INT16_T signed short + +/* Unsigned 16-bit type */ +#define TIFF_UINT16_T unsigned short + +/* Signed 32-bit type */ +#define TIFF_INT32_T signed int + +/* Unsigned 32-bit type */ +#define TIFF_UINT32_T unsigned int + +/* Signed 64-bit type */ +#ifdef _MSC_VER +#define TIFF_INT64_T signed __int64 +#else +#define TIFF_INT64_T signed long +#endif // _MSC_VER + +/* Unsigned 64-bit type */ +#ifdef _MSC_VER +#define TIFF_UINT64_T unsigned __int64 +#else +#define TIFF_UINT64_T unsigned long +#endif // _MSC_VER + +/* Signed 64-bit type */ +#if defined(_WIN64) +#define TIFF_SSIZE_T signed __int64 +#else +#define TIFF_SSIZE_T signed long +#endif + +/* Pointer difference type */ +#define TIFF_PTRDIFF_T ptrdiff_t + +/* Compatibility stuff. */ + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#define HAVE_IEEEFP 1 + +/* +----------------------------------------------------------------------- +Byte order +----------------------------------------------------------------------- +*/ + +/* +Define WORDS_BIGENDIAN to 1 if your processor stores words with the most +significant byte first (like Motorola and SPARC, unlike Intel). +Some versions of gcc may have BYTE_ORDER or __BYTE_ORDER defined +If your big endian system isn't being detected, add an OS specific check +*/ +#if (defined(BYTE_ORDER) && BYTE_ORDER==BIG_ENDIAN) || \ + (defined(__BYTE_ORDER) && __BYTE_ORDER==__BIG_ENDIAN) || \ + defined(__BIG_ENDIAN__) +/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ +#define HOST_FILLORDER FILLORDER_MSB2LSB +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ +#define WORDS_BIGENDIAN 1 +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ +#define HOST_BIGENDIAN 1 +#else +/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ +#define HOST_FILLORDER FILLORDER_LSB2MSB +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ +#undef WORDS_BIGENDIAN +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian (Intel) */ +#undef HOST_BIGENDIAN +#endif // BYTE_ORDER + +/* Support CCITT Group 3 & 4 algorithms */ +#define CCITT_SUPPORT 1 + +/* Support JPEG compression (requires IJG JPEG library) */ +#define JPEG_SUPPORT 1 + +/* Support JBIG compression (requires JBIG-KIT library) */ +/* #undef JBIG_SUPPORT */ + +/* Support LogLuv high dynamic range encoding */ +#define LOGLUV_SUPPORT 1 + +/* Support LZW algorithm */ +#define LZW_SUPPORT 1 + +/* Support NeXT 2-bit RLE algorithm */ +#define NEXT_SUPPORT 1 + +/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation + fails with unpatched IJG JPEG library) */ +#define OJPEG_SUPPORT 1 + +/* Support Macintosh PackBits algorithm */ +#define PACKBITS_SUPPORT 1 + +/* Support Pixar log-format algorithm (requires Zlib) */ +#define PIXARLOG_SUPPORT 1 + +/* Support ThunderScan 4-bit RLE algorithm */ +#define THUNDER_SUPPORT 1 + +/* Support Deflate compression */ +#define ZIP_SUPPORT 1 + +/* Support LZMA2 compression */ +#undef LZMA_SUPPORT + +/* Support Microsoft Document Imaging format */ +#undef MDI_SUPPORT + +/* Support strip chopping (whether or not to convert single-strip uncompressed + images to mutiple strips of ~8Kb to reduce memory usage) */ +#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP + +/* Enable SubIFD tag (330) support */ +#define SUBIFD_SUPPORT 1 + +/* Treat extra sample as alpha (default enabled). The RGBA interface will + treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many + packages produce RGBA files but don't mark the alpha properly. */ +#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1 + +/* Pick up YCbCr subsampling info from the JPEG data stream to support files + lacking the tag (default enabled). */ +#define CHECK_JPEG_YCBCR_SUBSAMPLING 1 + +/* Support MS MDI magic number files as TIFF */ +/* #undef MDI_SUPPORT */ + +/* + * Feature support definitions. + * XXX: These macros are obsoleted. Don't use them in your apps! + * Macros stays here for backward compatibility and should be always defined. + */ +#define COLORIMETRY_SUPPORT +#define YCBCR_SUPPORT +#define CMYK_SUPPORT +#define ICC_SUPPORT +#define PHOTOSHOP_SUPPORT +#define IPTC_SUPPORT + +#endif /* _TIFFCONF_ */ diff --git a/Source/LibTIFF4/tiffconf.h-vms b/Source/LibTIFF4/tiffconf.h-vms index de717ec..8d52893 100644 --- a/Source/LibTIFF4/tiffconf.h-vms +++ b/Source/LibTIFF4/tiffconf.h-vms @@ -1,99 +1,99 @@ -/* - Configuration defines for installed libtiff. - This file maintained for backward compatibility. Do not use definitions - from this file in your programs. -*/ - -#ifndef _TIFFCONF_ -#define _TIFFCONF_ - -/* Define to 1 if the system has the type `int16'. */ -//#define HAVE_INT16 - -/* Define to 1 if the system has the type `int32'. */ -//#define HAVE_INT32 - -/* Define to 1 if the system has the type `int8'. */ -//#define HAVE_INT8 - -/* The size of a `int', as computed by sizeof. */ -#define SIZEOF_INT 4 - -/* The size of a `long', as computed by sizeof. */ -#define SIZEOF_LONG 4 - -/* Compatibility stuff. */ - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#define HAVE_IEEEFP 1 - -#define HAVE_GETOPT 1 - -/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ -#define HOST_FILLORDER FILLORDER_LSB2MSB - -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian - (Intel) */ -#define HOST_BIGENDIAN 0 - -/* Support CCITT Group 3 & 4 algorithms */ -#define CCITT_SUPPORT 1 - -/* Support JPEG compression (requires IJG JPEG library) */ -#define JPEG_SUPPORT - -/* Support LogLuv high dynamic range encoding */ -#define LOGLUV_SUPPORT 1 - -/* Support LZW algorithm */ -#define LZW_SUPPORT 1 - -/* Support NeXT 2-bit RLE algorithm */ -#define NEXT_SUPPORT 1 - -/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation - fails with unpatched IJG JPEG library) */ -/* #undef OJPEG_SUPPORT */ - -/* Support Macintosh PackBits algorithm */ -#define PACKBITS_SUPPORT 1 - -/* Support Pixar log-format algorithm (requires Zlib) */ -/* #undef PIXARLOG_SUPPORT */ - -/* Support ThunderScan 4-bit RLE algorithm */ -#define THUNDER_SUPPORT 1 - -/* Support Deflate compression */ -/* #undef ZIP_SUPPORT */ - -/* Support strip chopping (whether or not to convert single-strip uncompressed - images to mutiple strips of ~8Kb to reduce memory usage) */ -#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP - -/* Enable SubIFD tag (330) support */ -#define SUBIFD_SUPPORT 1 - -/* Treat extra sample as alpha (default enabled). The RGBA interface will - treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many - packages produce RGBA files but don't mark the alpha properly. */ -#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1 - -/* Pick up YCbCr subsampling info from the JPEG data stream to support files - lacking the tag (default enabled). */ -#define CHECK_JPEG_YCBCR_SUBSAMPLING 1 - -/* - * Feature support definitions. - * XXX: These macros are obsoleted. Don't use them in your apps! - * Macros stays here for backward compatibility and should be always defined. - */ -#define COLORIMETRY_SUPPORT -#define YCBCR_SUPPORT -#define CMYK_SUPPORT -#define ICC_SUPPORT -#define PHOTOSHOP_SUPPORT -#define IPTC_SUPPORT - -#endif /* _TIFFCONF_ */ +/* + Configuration defines for installed libtiff. + This file maintained for backward compatibility. Do not use definitions + from this file in your programs. +*/ + +#ifndef _TIFFCONF_ +#define _TIFFCONF_ + +/* Define to 1 if the system has the type `int16'. */ +//#define HAVE_INT16 + +/* Define to 1 if the system has the type `int32'. */ +//#define HAVE_INT32 + +/* Define to 1 if the system has the type `int8'. */ +//#define HAVE_INT8 + +/* The size of a `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of a `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* Compatibility stuff. */ + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#define HAVE_IEEEFP 1 + +#define HAVE_GETOPT 1 + +/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ +#define HOST_FILLORDER FILLORDER_LSB2MSB + +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian + (Intel) */ +#define HOST_BIGENDIAN 0 + +/* Support CCITT Group 3 & 4 algorithms */ +#define CCITT_SUPPORT 1 + +/* Support JPEG compression (requires IJG JPEG library) */ +#define JPEG_SUPPORT + +/* Support LogLuv high dynamic range encoding */ +#define LOGLUV_SUPPORT 1 + +/* Support LZW algorithm */ +#define LZW_SUPPORT 1 + +/* Support NeXT 2-bit RLE algorithm */ +#define NEXT_SUPPORT 1 + +/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation + fails with unpatched IJG JPEG library) */ +/* #undef OJPEG_SUPPORT */ + +/* Support Macintosh PackBits algorithm */ +#define PACKBITS_SUPPORT 1 + +/* Support Pixar log-format algorithm (requires Zlib) */ +/* #undef PIXARLOG_SUPPORT */ + +/* Support ThunderScan 4-bit RLE algorithm */ +#define THUNDER_SUPPORT 1 + +/* Support Deflate compression */ +/* #undef ZIP_SUPPORT */ + +/* Support strip chopping (whether or not to convert single-strip uncompressed + images to mutiple strips of ~8Kb to reduce memory usage) */ +#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP + +/* Enable SubIFD tag (330) support */ +#define SUBIFD_SUPPORT 1 + +/* Treat extra sample as alpha (default enabled). The RGBA interface will + treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many + packages produce RGBA files but don't mark the alpha properly. */ +#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1 + +/* Pick up YCbCr subsampling info from the JPEG data stream to support files + lacking the tag (default enabled). */ +#define CHECK_JPEG_YCBCR_SUBSAMPLING 1 + +/* + * Feature support definitions. + * XXX: These macros are obsoleted. Don't use them in your apps! + * Macros stays here for backward compatibility and should be always defined. + */ +#define COLORIMETRY_SUPPORT +#define YCBCR_SUPPORT +#define CMYK_SUPPORT +#define ICC_SUPPORT +#define PHOTOSHOP_SUPPORT +#define IPTC_SUPPORT + +#endif /* _TIFFCONF_ */ diff --git a/Source/LibTIFF4/tiffconf.h.in b/Source/LibTIFF4/tiffconf.h.in index 695a78e..6da9c5a 100644 --- a/Source/LibTIFF4/tiffconf.h.in +++ b/Source/LibTIFF4/tiffconf.h.in @@ -1,127 +1,127 @@ -/* - Configuration defines for installed libtiff. - This file maintained for backward compatibility. Do not use definitions - from this file in your programs. -*/ - -#ifndef _TIFFCONF_ -#define _TIFFCONF_ - -/* Signed 16-bit type */ -#undef TIFF_INT16_T - -/* Signed 32-bit type */ -#undef TIFF_INT32_T - -/* Signed 64-bit type */ -#undef TIFF_INT64_T - -/* Signed 8-bit type */ -#undef TIFF_INT8_T - -/* Unsigned 16-bit type */ -#undef TIFF_UINT16_T - -/* Unsigned 32-bit type */ -#undef TIFF_UINT32_T - -/* Unsigned 64-bit type */ -#undef TIFF_UINT64_T - -/* Unsigned 8-bit type */ -#undef TIFF_UINT8_T - -/* Signed size type */ -#undef TIFF_SSIZE_T - -/* Pointer difference type */ -#undef TIFF_PTRDIFF_T - -/* Define to 1 if the system has the type `int16'. */ -#undef HAVE_INT16 - -/* Define to 1 if the system has the type `int32'. */ -#undef HAVE_INT32 - -/* Define to 1 if the system has the type `int8'. */ -#undef HAVE_INT8 - -/* Compatibility stuff. */ - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#undef HAVE_IEEEFP - -/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ -#undef HOST_FILLORDER - -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian - (Intel) */ -#undef HOST_BIGENDIAN - -/* Support CCITT Group 3 & 4 algorithms */ -#undef CCITT_SUPPORT - -/* Support JPEG compression (requires IJG JPEG library) */ -#undef JPEG_SUPPORT - -/* Support JBIG compression (requires JBIG-KIT library) */ -#undef JBIG_SUPPORT - -/* Support LogLuv high dynamic range encoding */ -#undef LOGLUV_SUPPORT - -/* Support LZW algorithm */ -#undef LZW_SUPPORT - -/* Support NeXT 2-bit RLE algorithm */ -#undef NEXT_SUPPORT - -/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation - fails with unpatched IJG JPEG library) */ -#undef OJPEG_SUPPORT - -/* Support Macintosh PackBits algorithm */ -#undef PACKBITS_SUPPORT - -/* Support Pixar log-format algorithm (requires Zlib) */ -#undef PIXARLOG_SUPPORT - -/* Support ThunderScan 4-bit RLE algorithm */ -#undef THUNDER_SUPPORT - -/* Support Deflate compression */ -#undef ZIP_SUPPORT - -/* Support strip chopping (whether or not to convert single-strip uncompressed - images to mutiple strips of ~8Kb to reduce memory usage) */ -#undef STRIPCHOP_DEFAULT - -/* Enable SubIFD tag (330) support */ -#undef SUBIFD_SUPPORT - -/* Treat extra sample as alpha (default enabled). The RGBA interface will - treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many - packages produce RGBA files but don't mark the alpha properly. */ -#undef DEFAULT_EXTRASAMPLE_AS_ALPHA - -/* Pick up YCbCr subsampling info from the JPEG data stream to support files - lacking the tag (default enabled). */ -#undef CHECK_JPEG_YCBCR_SUBSAMPLING - -/* Support MS MDI magic number files as TIFF */ -#undef MDI_SUPPORT - -/* - * Feature support definitions. - * XXX: These macros are obsoleted. Don't use them in your apps! - * Macros stays here for backward compatibility and should be always defined. - */ -#define COLORIMETRY_SUPPORT -#define YCBCR_SUPPORT -#define CMYK_SUPPORT -#define ICC_SUPPORT -#define PHOTOSHOP_SUPPORT -#define IPTC_SUPPORT - -#endif /* _TIFFCONF_ */ +/* + Configuration defines for installed libtiff. + This file maintained for backward compatibility. Do not use definitions + from this file in your programs. +*/ + +#ifndef _TIFFCONF_ +#define _TIFFCONF_ + +/* Signed 16-bit type */ +#undef TIFF_INT16_T + +/* Signed 32-bit type */ +#undef TIFF_INT32_T + +/* Signed 64-bit type */ +#undef TIFF_INT64_T + +/* Signed 8-bit type */ +#undef TIFF_INT8_T + +/* Unsigned 16-bit type */ +#undef TIFF_UINT16_T + +/* Unsigned 32-bit type */ +#undef TIFF_UINT32_T + +/* Unsigned 64-bit type */ +#undef TIFF_UINT64_T + +/* Unsigned 8-bit type */ +#undef TIFF_UINT8_T + +/* Signed size type */ +#undef TIFF_SSIZE_T + +/* Pointer difference type */ +#undef TIFF_PTRDIFF_T + +/* Define to 1 if the system has the type `int16'. */ +#undef HAVE_INT16 + +/* Define to 1 if the system has the type `int32'. */ +#undef HAVE_INT32 + +/* Define to 1 if the system has the type `int8'. */ +#undef HAVE_INT8 + +/* Compatibility stuff. */ + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#undef HAVE_IEEEFP + +/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ +#undef HOST_FILLORDER + +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian + (Intel) */ +#undef HOST_BIGENDIAN + +/* Support CCITT Group 3 & 4 algorithms */ +#undef CCITT_SUPPORT + +/* Support JPEG compression (requires IJG JPEG library) */ +#undef JPEG_SUPPORT + +/* Support JBIG compression (requires JBIG-KIT library) */ +#undef JBIG_SUPPORT + +/* Support LogLuv high dynamic range encoding */ +#undef LOGLUV_SUPPORT + +/* Support LZW algorithm */ +#undef LZW_SUPPORT + +/* Support NeXT 2-bit RLE algorithm */ +#undef NEXT_SUPPORT + +/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation + fails with unpatched IJG JPEG library) */ +#undef OJPEG_SUPPORT + +/* Support Macintosh PackBits algorithm */ +#undef PACKBITS_SUPPORT + +/* Support Pixar log-format algorithm (requires Zlib) */ +#undef PIXARLOG_SUPPORT + +/* Support ThunderScan 4-bit RLE algorithm */ +#undef THUNDER_SUPPORT + +/* Support Deflate compression */ +#undef ZIP_SUPPORT + +/* Support strip chopping (whether or not to convert single-strip uncompressed + images to mutiple strips of ~8Kb to reduce memory usage) */ +#undef STRIPCHOP_DEFAULT + +/* Enable SubIFD tag (330) support */ +#undef SUBIFD_SUPPORT + +/* Treat extra sample as alpha (default enabled). The RGBA interface will + treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many + packages produce RGBA files but don't mark the alpha properly. */ +#undef DEFAULT_EXTRASAMPLE_AS_ALPHA + +/* Pick up YCbCr subsampling info from the JPEG data stream to support files + lacking the tag (default enabled). */ +#undef CHECK_JPEG_YCBCR_SUBSAMPLING + +/* Support MS MDI magic number files as TIFF */ +#undef MDI_SUPPORT + +/* + * Feature support definitions. + * XXX: These macros are obsoleted. Don't use them in your apps! + * Macros stays here for backward compatibility and should be always defined. + */ +#define COLORIMETRY_SUPPORT +#define YCBCR_SUPPORT +#define CMYK_SUPPORT +#define ICC_SUPPORT +#define PHOTOSHOP_SUPPORT +#define IPTC_SUPPORT + +#endif /* _TIFFCONF_ */ diff --git a/Source/LibTIFF4/tiffconf.vc.h b/Source/LibTIFF4/tiffconf.vc.h index 0584b59..680f839 100644 --- a/Source/LibTIFF4/tiffconf.vc.h +++ b/Source/LibTIFF4/tiffconf.vc.h @@ -1,160 +1,160 @@ -/* - Configuration defines for installed libtiff. - This file maintained for backward compatibility. Do not use definitions - from this file in your programs. -*/ - -#ifndef _TIFFCONF_ -#define _TIFFCONF_ - -/* Define to 1 if the system has the type `int16'. */ -/* #undef HAVE_INT16 */ - -/* Define to 1 if the system has the type `int32'. */ -/* #undef HAVE_INT32 */ - -/* Define to 1 if the system has the type `int8'. */ -/* #undef HAVE_INT8 */ - -/* The size of a `int', as computed by sizeof. */ -#define SIZEOF_INT 4 - -/* Signed 8-bit type */ -#define TIFF_INT8_T signed char - -/* Unsigned 8-bit type */ -#define TIFF_UINT8_T unsigned char - -/* Signed 16-bit type */ -#define TIFF_INT16_T signed short - -/* Unsigned 16-bit type */ -#define TIFF_UINT16_T unsigned short - -/* Signed 32-bit type formatter */ -#define TIFF_INT32_FORMAT "%d" - -/* Signed 32-bit type */ -#define TIFF_INT32_T signed int - -/* Unsigned 32-bit type formatter */ -#define TIFF_UINT32_FORMAT "%u" - -/* Unsigned 32-bit type */ -#define TIFF_UINT32_T unsigned int - -/* Signed 64-bit type formatter */ -#define TIFF_INT64_FORMAT "%I64d" - -/* Signed 64-bit type */ -#define TIFF_INT64_T signed __int64 - -/* Unsigned 64-bit type formatter */ -#define TIFF_UINT64_FORMAT "%I64u" - -/* Unsigned 64-bit type */ -#define TIFF_UINT64_T unsigned __int64 - -/* Signed size type */ -#if defined(_WIN64) -#define TIFF_SSIZE_T signed __int64 -#else -#define TIFF_SSIZE_T signed int -#endif - -/* Signed size type formatter */ -#if defined(_WIN64) -#define TIFF_SSIZE_FORMAT "%I64d" -#else -#define TIFF_SSIZE_FORMAT "%ld" -#endif - -/* Pointer difference type */ -#define TIFF_PTRDIFF_T long - -/* Compatibility stuff. */ - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#define HAVE_IEEEFP 1 - -/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ -#define HOST_FILLORDER FILLORDER_LSB2MSB - -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian - (Intel) */ -#define HOST_BIGENDIAN 0 - -/* Support CCITT Group 3 & 4 algorithms */ -#define CCITT_SUPPORT 1 - -/* Support JPEG compression (requires IJG JPEG library) */ -/* #undef JPEG_SUPPORT */ - -/* Support JBIG compression (requires JBIG-KIT library) */ -/* #undef JBIG_SUPPORT */ - -/* Support LogLuv high dynamic range encoding */ -#define LOGLUV_SUPPORT 1 - -/* Support LZW algorithm */ -#define LZW_SUPPORT 1 - -/* Support NeXT 2-bit RLE algorithm */ -#define NEXT_SUPPORT 1 - -/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation - fails with unpatched IJG JPEG library) */ -/* #undef OJPEG_SUPPORT */ - -/* Support Macintosh PackBits algorithm */ -#define PACKBITS_SUPPORT 1 - -/* Support Pixar log-format algorithm (requires Zlib) */ -/* #undef PIXARLOG_SUPPORT */ - -/* Support ThunderScan 4-bit RLE algorithm */ -#define THUNDER_SUPPORT 1 - -/* Support Deflate compression */ -/* #undef ZIP_SUPPORT */ - -/* Support strip chopping (whether or not to convert single-strip uncompressed - images to mutiple strips of ~8Kb to reduce memory usage) */ -#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP - -/* Enable SubIFD tag (330) support */ -#define SUBIFD_SUPPORT 1 - -/* Treat extra sample as alpha (default enabled). The RGBA interface will - treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many - packages produce RGBA files but don't mark the alpha properly. */ -#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1 - -/* Pick up YCbCr subsampling info from the JPEG data stream to support files - lacking the tag (default enabled). */ -#define CHECK_JPEG_YCBCR_SUBSAMPLING 1 - -/* Support MS MDI magic number files as TIFF */ -/* #undef MDI_SUPPORT */ - -/* - * Feature support definitions. - * XXX: These macros are obsoleted. Don't use them in your apps! - * Macros stays here for backward compatibility and should be always defined. - */ -#define COLORIMETRY_SUPPORT -#define YCBCR_SUPPORT -#define CMYK_SUPPORT -#define ICC_SUPPORT -#define PHOTOSHOP_SUPPORT -#define IPTC_SUPPORT - -#endif /* _TIFFCONF_ */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* + Configuration defines for installed libtiff. + This file maintained for backward compatibility. Do not use definitions + from this file in your programs. +*/ + +#ifndef _TIFFCONF_ +#define _TIFFCONF_ + +/* Define to 1 if the system has the type `int16'. */ +/* #undef HAVE_INT16 */ + +/* Define to 1 if the system has the type `int32'. */ +/* #undef HAVE_INT32 */ + +/* Define to 1 if the system has the type `int8'. */ +/* #undef HAVE_INT8 */ + +/* The size of a `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* Signed 8-bit type */ +#define TIFF_INT8_T signed char + +/* Unsigned 8-bit type */ +#define TIFF_UINT8_T unsigned char + +/* Signed 16-bit type */ +#define TIFF_INT16_T signed short + +/* Unsigned 16-bit type */ +#define TIFF_UINT16_T unsigned short + +/* Signed 32-bit type formatter */ +#define TIFF_INT32_FORMAT "%d" + +/* Signed 32-bit type */ +#define TIFF_INT32_T signed int + +/* Unsigned 32-bit type formatter */ +#define TIFF_UINT32_FORMAT "%u" + +/* Unsigned 32-bit type */ +#define TIFF_UINT32_T unsigned int + +/* Signed 64-bit type formatter */ +#define TIFF_INT64_FORMAT "%I64d" + +/* Signed 64-bit type */ +#define TIFF_INT64_T signed __int64 + +/* Unsigned 64-bit type formatter */ +#define TIFF_UINT64_FORMAT "%I64u" + +/* Unsigned 64-bit type */ +#define TIFF_UINT64_T unsigned __int64 + +/* Signed size type */ +#if defined(_WIN64) +#define TIFF_SSIZE_T signed __int64 +#else +#define TIFF_SSIZE_T signed int +#endif + +/* Signed size type formatter */ +#if defined(_WIN64) +#define TIFF_SSIZE_FORMAT "%I64d" +#else +#define TIFF_SSIZE_FORMAT "%ld" +#endif + +/* Pointer difference type */ +#define TIFF_PTRDIFF_T long + +/* Compatibility stuff. */ + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#define HAVE_IEEEFP 1 + +/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ +#define HOST_FILLORDER FILLORDER_LSB2MSB + +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian + (Intel) */ +#define HOST_BIGENDIAN 0 + +/* Support CCITT Group 3 & 4 algorithms */ +#define CCITT_SUPPORT 1 + +/* Support JPEG compression (requires IJG JPEG library) */ +/* #undef JPEG_SUPPORT */ + +/* Support JBIG compression (requires JBIG-KIT library) */ +/* #undef JBIG_SUPPORT */ + +/* Support LogLuv high dynamic range encoding */ +#define LOGLUV_SUPPORT 1 + +/* Support LZW algorithm */ +#define LZW_SUPPORT 1 + +/* Support NeXT 2-bit RLE algorithm */ +#define NEXT_SUPPORT 1 + +/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation + fails with unpatched IJG JPEG library) */ +/* #undef OJPEG_SUPPORT */ + +/* Support Macintosh PackBits algorithm */ +#define PACKBITS_SUPPORT 1 + +/* Support Pixar log-format algorithm (requires Zlib) */ +/* #undef PIXARLOG_SUPPORT */ + +/* Support ThunderScan 4-bit RLE algorithm */ +#define THUNDER_SUPPORT 1 + +/* Support Deflate compression */ +/* #undef ZIP_SUPPORT */ + +/* Support strip chopping (whether or not to convert single-strip uncompressed + images to mutiple strips of ~8Kb to reduce memory usage) */ +#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP + +/* Enable SubIFD tag (330) support */ +#define SUBIFD_SUPPORT 1 + +/* Treat extra sample as alpha (default enabled). The RGBA interface will + treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many + packages produce RGBA files but don't mark the alpha properly. */ +#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1 + +/* Pick up YCbCr subsampling info from the JPEG data stream to support files + lacking the tag (default enabled). */ +#define CHECK_JPEG_YCBCR_SUBSAMPLING 1 + +/* Support MS MDI magic number files as TIFF */ +/* #undef MDI_SUPPORT */ + +/* + * Feature support definitions. + * XXX: These macros are obsoleted. Don't use them in your apps! + * Macros stays here for backward compatibility and should be always defined. + */ +#define COLORIMETRY_SUPPORT +#define YCBCR_SUPPORT +#define CMYK_SUPPORT +#define ICC_SUPPORT +#define PHOTOSHOP_SUPPORT +#define IPTC_SUPPORT + +#endif /* _TIFFCONF_ */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tiffconf.wince.h b/Source/LibTIFF4/tiffconf.wince.h index b832751..54dc7f0 100644 --- a/Source/LibTIFF4/tiffconf.wince.h +++ b/Source/LibTIFF4/tiffconf.wince.h @@ -1,121 +1,121 @@ -/* $Id: tiffconf.wince.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Windows CE platform tiffconf.wince.h - * Created by Mateusz Loskot (mateusz@loskot.net) - * - * NOTE: Requires WCELIBCEX library with wceex_* functions, - * It's an extension to C library on Windows CE platform. - * For example, HAVE_STDIO_H definition indicates there are - * following files available: - * stdio.h - from Windows CE / Windows Mobile SDK - * wce_stdio.h - from WCELIBCEX library - */ - - -/* - Configuration defines for installed libtiff. - This file maintained for backward compatibility. Do not use definitions - from this file in your programs. -*/ - -#ifndef _WIN32_WCE -# error This version of tif_config.h header is dedicated for Windows CE platform! -#endif - - -#ifndef _TIFFCONF_ -#define _TIFFCONF_ - -/* Define to 1 if the system has the type `int16'. */ -/* #undef HAVE_INT16 */ - -/* Define to 1 if the system has the type `int32'. */ -/* #undef HAVE_INT32 */ - -/* Define to 1 if the system has the type `int8'. */ -/* #undef HAVE_INT8 */ - -/* The size of a `int', as computed by sizeof. */ -#define SIZEOF_INT 4 - -/* Compatibility stuff. */ - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#define HAVE_IEEEFP 1 - -/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ -#define HOST_FILLORDER FILLORDER_LSB2MSB - -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian - (Intel) */ -#define HOST_BIGENDIAN 0 - -/* Support CCITT Group 3 & 4 algorithms */ -#define CCITT_SUPPORT 1 - -/* Support JPEG compression (requires IJG JPEG library) */ -/* #undef JPEG_SUPPORT */ - -/* Support LogLuv high dynamic range encoding */ -#define LOGLUV_SUPPORT 1 - -/* Support LZW algorithm */ -#define LZW_SUPPORT 1 - -/* Support NeXT 2-bit RLE algorithm */ -#define NEXT_SUPPORT 1 - -/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation - fails with unpatched IJG JPEG library) */ -/* #undef OJPEG_SUPPORT */ - -/* Support Macintosh PackBits algorithm */ -#define PACKBITS_SUPPORT 1 - -/* Support Pixar log-format algorithm (requires Zlib) */ -/* #undef PIXARLOG_SUPPORT */ - -/* Support ThunderScan 4-bit RLE algorithm */ -#define THUNDER_SUPPORT 1 - -/* Support Deflate compression */ -/* #undef ZIP_SUPPORT */ - -/* Support strip chopping (whether or not to convert single-strip uncompressed - images to mutiple strips of ~8Kb to reduce memory usage) */ -#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP - -/* Enable SubIFD tag (330) support */ -#define SUBIFD_SUPPORT 1 - -/* Treat extra sample as alpha (default enabled). The RGBA interface will - treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many - packages produce RGBA files but don't mark the alpha properly. */ -#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1 - -/* Pick up YCbCr subsampling info from the JPEG data stream to support files - lacking the tag (default enabled). */ -#define CHECK_JPEG_YCBCR_SUBSAMPLING 1 - -/* - * Feature support definitions. - * XXX: These macros are obsoleted. Don't use them in your apps! - * Macros stays here for backward compatibility and should be always defined. - */ -#define COLORIMETRY_SUPPORT -#define YCBCR_SUPPORT -#define CMYK_SUPPORT -#define ICC_SUPPORT -#define PHOTOSHOP_SUPPORT -#define IPTC_SUPPORT - -#endif /* _TIFFCONF_ */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tiffconf.wince.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Windows CE platform tiffconf.wince.h + * Created by Mateusz Loskot (mateusz@loskot.net) + * + * NOTE: Requires WCELIBCEX library with wceex_* functions, + * It's an extension to C library on Windows CE platform. + * For example, HAVE_STDIO_H definition indicates there are + * following files available: + * stdio.h - from Windows CE / Windows Mobile SDK + * wce_stdio.h - from WCELIBCEX library + */ + + +/* + Configuration defines for installed libtiff. + This file maintained for backward compatibility. Do not use definitions + from this file in your programs. +*/ + +#ifndef _WIN32_WCE +# error This version of tif_config.h header is dedicated for Windows CE platform! +#endif + + +#ifndef _TIFFCONF_ +#define _TIFFCONF_ + +/* Define to 1 if the system has the type `int16'. */ +/* #undef HAVE_INT16 */ + +/* Define to 1 if the system has the type `int32'. */ +/* #undef HAVE_INT32 */ + +/* Define to 1 if the system has the type `int8'. */ +/* #undef HAVE_INT8 */ + +/* The size of a `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* Compatibility stuff. */ + +/* Define as 0 or 1 according to the floating point format suported by the + machine */ +#define HAVE_IEEEFP 1 + +/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ +#define HOST_FILLORDER FILLORDER_LSB2MSB + +/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian + (Intel) */ +#define HOST_BIGENDIAN 0 + +/* Support CCITT Group 3 & 4 algorithms */ +#define CCITT_SUPPORT 1 + +/* Support JPEG compression (requires IJG JPEG library) */ +/* #undef JPEG_SUPPORT */ + +/* Support LogLuv high dynamic range encoding */ +#define LOGLUV_SUPPORT 1 + +/* Support LZW algorithm */ +#define LZW_SUPPORT 1 + +/* Support NeXT 2-bit RLE algorithm */ +#define NEXT_SUPPORT 1 + +/* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation + fails with unpatched IJG JPEG library) */ +/* #undef OJPEG_SUPPORT */ + +/* Support Macintosh PackBits algorithm */ +#define PACKBITS_SUPPORT 1 + +/* Support Pixar log-format algorithm (requires Zlib) */ +/* #undef PIXARLOG_SUPPORT */ + +/* Support ThunderScan 4-bit RLE algorithm */ +#define THUNDER_SUPPORT 1 + +/* Support Deflate compression */ +/* #undef ZIP_SUPPORT */ + +/* Support strip chopping (whether or not to convert single-strip uncompressed + images to mutiple strips of ~8Kb to reduce memory usage) */ +#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP + +/* Enable SubIFD tag (330) support */ +#define SUBIFD_SUPPORT 1 + +/* Treat extra sample as alpha (default enabled). The RGBA interface will + treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many + packages produce RGBA files but don't mark the alpha properly. */ +#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1 + +/* Pick up YCbCr subsampling info from the JPEG data stream to support files + lacking the tag (default enabled). */ +#define CHECK_JPEG_YCBCR_SUBSAMPLING 1 + +/* + * Feature support definitions. + * XXX: These macros are obsoleted. Don't use them in your apps! + * Macros stays here for backward compatibility and should be always defined. + */ +#define COLORIMETRY_SUPPORT +#define YCBCR_SUPPORT +#define CMYK_SUPPORT +#define ICC_SUPPORT +#define PHOTOSHOP_SUPPORT +#define IPTC_SUPPORT + +#endif /* _TIFFCONF_ */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tiffio.h b/Source/LibTIFF4/tiffio.h index 482574a..407f93a 100644 --- a/Source/LibTIFF4/tiffio.h +++ b/Source/LibTIFF4/tiffio.h @@ -1,557 +1,557 @@ -/* $Id: tiffio.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifndef _TIFFIO_ -#define _TIFFIO_ - -/* - * TIFF I/O Library Definitions. - */ -#include "tiff.h" -#include "tiffvers.h" - -/* - * TIFF is defined as an incomplete type to hide the - * library's internal data structures from clients. - */ -typedef struct tiff TIFF; - -/* - * The following typedefs define the intrinsic size of - * data types used in the *exported* interfaces. These - * definitions depend on the proper definition of types - * in tiff.h. Note also that the varargs interface used - * to pass tag types and values uses the types defined in - * tiff.h directly. - * - * NB: ttag_t is unsigned int and not unsigned short because - * ANSI C requires that the type before the ellipsis be a - * promoted type (i.e. one of int, unsigned int, pointer, - * or double) and because we defined pseudo-tags that are - * outside the range of legal Aldus-assigned tags. - * NB: tsize_t is int32 and not uint32 because some functions - * return -1. - * NB: toff_t is not off_t for many reasons; TIFFs max out at - * 32-bit file offsets, and BigTIFF maxes out at 64-bit - * offsets being the most important, and to ensure use of - * a consistently unsigned type across architectures. - * Prior to libtiff 4.0, this was an unsigned 32 bit type. - */ -/* - * this is the machine addressing size type, only it's signed, so make it - * int32 on 32bit machines, int64 on 64bit machines - */ -typedef TIFF_SSIZE_T tmsize_t; -typedef uint64 toff_t; /* file offset */ -/* the following are deprecated and should be replaced by their defining - counterparts */ -typedef uint32 ttag_t; /* directory tag */ -typedef uint16 tdir_t; /* directory index */ -typedef uint16 tsample_t; /* sample number */ -typedef uint32 tstrile_t; /* strip or tile number */ -typedef tstrile_t tstrip_t; /* strip number */ -typedef tstrile_t ttile_t; /* tile number */ -typedef tmsize_t tsize_t; /* i/o size in bytes */ -typedef void* tdata_t; /* image data ref */ - -#if !defined(__WIN32__) && (defined(_WIN32) || defined(WIN32)) -#define __WIN32__ -#endif - -/* - * On windows you should define USE_WIN32_FILEIO if you are using tif_win32.c - * or AVOID_WIN32_FILEIO if you are using something else (like tif_unix.c). - * - * By default tif_unix.c is assumed. - */ - -#if defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows) -# if !defined(__CYGWIN) && !defined(AVOID_WIN32_FILEIO) && !defined(USE_WIN32_FILEIO) -# define AVOID_WIN32_FILEIO -# endif -#endif - -#if defined(USE_WIN32_FILEIO) -# define VC_EXTRALEAN -# include -# ifdef __WIN32__ -DECLARE_HANDLE(thandle_t); /* Win32 file handle */ -# else -typedef HFILE thandle_t; /* client data handle */ -# endif /* __WIN32__ */ -#else -typedef void* thandle_t; /* client data handle */ -#endif /* USE_WIN32_FILEIO */ - -/* - * Flags to pass to TIFFPrintDirectory to control - * printing of data structures that are potentially - * very large. Bit-or these flags to enable printing - * multiple items. - */ -#define TIFFPRINT_NONE 0x0 /* no extra info */ -#define TIFFPRINT_STRIPS 0x1 /* strips/tiles info */ -#define TIFFPRINT_CURVES 0x2 /* color/gray response curves */ -#define TIFFPRINT_COLORMAP 0x4 /* colormap */ -#define TIFFPRINT_JPEGQTABLES 0x100 /* JPEG Q matrices */ -#define TIFFPRINT_JPEGACTABLES 0x200 /* JPEG AC tables */ -#define TIFFPRINT_JPEGDCTABLES 0x200 /* JPEG DC tables */ - -/* - * Colour conversion stuff - */ - -/* reference white */ -#define D65_X0 (95.0470F) -#define D65_Y0 (100.0F) -#define D65_Z0 (108.8827F) - -#define D50_X0 (96.4250F) -#define D50_Y0 (100.0F) -#define D50_Z0 (82.4680F) - -/* Structure for holding information about a display device. */ - -typedef unsigned char TIFFRGBValue; /* 8-bit samples */ - -typedef struct { - float d_mat[3][3]; /* XYZ -> luminance matrix */ - float d_YCR; /* Light o/p for reference white */ - float d_YCG; - float d_YCB; - uint32 d_Vrwr; /* Pixel values for ref. white */ - uint32 d_Vrwg; - uint32 d_Vrwb; - float d_Y0R; /* Residual light for black pixel */ - float d_Y0G; - float d_Y0B; - float d_gammaR; /* Gamma values for the three guns */ - float d_gammaG; - float d_gammaB; -} TIFFDisplay; - -typedef struct { /* YCbCr->RGB support */ - TIFFRGBValue* clamptab; /* range clamping table */ - int* Cr_r_tab; - int* Cb_b_tab; - int32* Cr_g_tab; - int32* Cb_g_tab; - int32* Y_tab; -} TIFFYCbCrToRGB; - -typedef struct { /* CIE Lab 1976->RGB support */ - int range; /* Size of conversion table */ -#define CIELABTORGB_TABLE_RANGE 1500 - float rstep, gstep, bstep; - float X0, Y0, Z0; /* Reference white point */ - TIFFDisplay display; - float Yr2r[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yr to r */ - float Yg2g[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yg to g */ - float Yb2b[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yb to b */ -} TIFFCIELabToRGB; - -/* - * RGBA-style image support. - */ -typedef struct _TIFFRGBAImage TIFFRGBAImage; -/* - * The image reading and conversion routines invoke - * ``put routines'' to copy/image/whatever tiles of - * raw image data. A default set of routines are - * provided to convert/copy raw image data to 8-bit - * packed ABGR format rasters. Applications can supply - * alternate routines that unpack the data into a - * different format or, for example, unpack the data - * and draw the unpacked raster on the display. - */ -typedef void (*tileContigRoutine) - (TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32, - unsigned char*); -typedef void (*tileSeparateRoutine) - (TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32, - unsigned char*, unsigned char*, unsigned char*, unsigned char*); -/* - * RGBA-reader state. - */ -struct _TIFFRGBAImage { - TIFF* tif; /* image handle */ - int stoponerr; /* stop on read error */ - int isContig; /* data is packed/separate */ - int alpha; /* type of alpha data present */ - uint32 width; /* image width */ - uint32 height; /* image height */ - uint16 bitspersample; /* image bits/sample */ - uint16 samplesperpixel; /* image samples/pixel */ - uint16 orientation; /* image orientation */ - uint16 req_orientation; /* requested orientation */ - uint16 photometric; /* image photometric interp */ - uint16* redcmap; /* colormap pallete */ - uint16* greencmap; - uint16* bluecmap; - /* get image data routine */ - int (*get)(TIFFRGBAImage*, uint32*, uint32, uint32); - /* put decoded strip/tile */ - union { - void (*any)(TIFFRGBAImage*); - tileContigRoutine contig; - tileSeparateRoutine separate; - } put; - TIFFRGBValue* Map; /* sample mapping array */ - uint32** BWmap; /* black&white map */ - uint32** PALmap; /* palette image map */ - TIFFYCbCrToRGB* ycbcr; /* YCbCr conversion state */ - TIFFCIELabToRGB* cielab; /* CIE L*a*b conversion state */ - - uint8* UaToAa; /* Unassociated alpha to associated alpha convertion LUT */ - uint8* Bitdepth16To8; /* LUT for conversion from 16bit to 8bit values */ - - int row_offset; - int col_offset; -}; - -/* - * Macros for extracting components from the - * packed ABGR form returned by TIFFReadRGBAImage. - */ -#define TIFFGetR(abgr) ((abgr) & 0xff) -#define TIFFGetG(abgr) (((abgr) >> 8) & 0xff) -#define TIFFGetB(abgr) (((abgr) >> 16) & 0xff) -#define TIFFGetA(abgr) (((abgr) >> 24) & 0xff) - -/* - * A CODEC is a software package that implements decoding, - * encoding, or decoding+encoding of a compression algorithm. - * The library provides a collection of builtin codecs. - * More codecs may be registered through calls to the library - * and/or the builtin implementations may be overridden. - */ -typedef int (*TIFFInitMethod)(TIFF*, int); -typedef struct { - char* name; - uint16 scheme; - TIFFInitMethod init; -} TIFFCodec; - -#include -#include - -/* share internal LogLuv conversion routines? */ -#ifndef LOGLUV_PUBLIC -#define LOGLUV_PUBLIC 1 -#endif - -#if !defined(__GNUC__) && !defined(__attribute__) -# define __attribute__(x) /*nothing*/ -#endif - -#if defined(c_plusplus) || defined(__cplusplus) -extern "C" { -#endif -typedef void (*TIFFErrorHandler)(const char*, const char*, va_list); -typedef void (*TIFFErrorHandlerExt)(thandle_t, const char*, const char*, va_list); -typedef tmsize_t (*TIFFReadWriteProc)(thandle_t, void*, tmsize_t); -typedef toff_t (*TIFFSeekProc)(thandle_t, toff_t, int); -typedef int (*TIFFCloseProc)(thandle_t); -typedef toff_t (*TIFFSizeProc)(thandle_t); -typedef int (*TIFFMapFileProc)(thandle_t, void** base, toff_t* size); -typedef void (*TIFFUnmapFileProc)(thandle_t, void* base, toff_t size); -typedef void (*TIFFExtendProc)(TIFF*); - -extern const char* TIFFGetVersion(void); - -extern const TIFFCodec* TIFFFindCODEC(uint16); -extern TIFFCodec* TIFFRegisterCODEC(uint16, const char*, TIFFInitMethod); -extern void TIFFUnRegisterCODEC(TIFFCodec*); -extern int TIFFIsCODECConfigured(uint16); -extern TIFFCodec* TIFFGetConfiguredCODECs(void); - -/* - * Auxiliary functions. - */ - -extern void* _TIFFmalloc(tmsize_t s); -extern void* _TIFFrealloc(void* p, tmsize_t s); -extern void _TIFFmemset(void* p, int v, tmsize_t c); -extern void _TIFFmemcpy(void* d, const void* s, tmsize_t c); -extern int _TIFFmemcmp(const void* p1, const void* p2, tmsize_t c); -extern void _TIFFfree(void* p); - -/* -** Stuff, related to tag handling and creating custom tags. -*/ -extern int TIFFGetTagListCount( TIFF * ); -extern uint32 TIFFGetTagListEntry( TIFF *, int tag_index ); - -#define TIFF_ANY TIFF_NOTYPE /* for field descriptor searching */ -#define TIFF_VARIABLE -1 /* marker for variable length tags */ -#define TIFF_SPP -2 /* marker for SamplesPerPixel tags */ -#define TIFF_VARIABLE2 -3 /* marker for uint32 var-length tags */ - -#define FIELD_CUSTOM 65 - -typedef struct _TIFFField TIFFField; -typedef struct _TIFFFieldArray TIFFFieldArray; - -extern const TIFFField* TIFFFindField(TIFF *, uint32, TIFFDataType); -extern const TIFFField* TIFFFieldWithTag(TIFF*, uint32); -extern const TIFFField* TIFFFieldWithName(TIFF*, const char *); - -extern uint32 TIFFFieldTag(const TIFFField*); -extern const char* TIFFFieldName(const TIFFField*); -extern TIFFDataType TIFFFieldDataType(const TIFFField*); -extern int TIFFFieldPassCount(const TIFFField*); -extern int TIFFFieldReadCount(const TIFFField*); -extern int TIFFFieldWriteCount(const TIFFField*); - -typedef int (*TIFFVSetMethod)(TIFF*, uint32, va_list); -typedef int (*TIFFVGetMethod)(TIFF*, uint32, va_list); -typedef void (*TIFFPrintMethod)(TIFF*, FILE*, long); - -typedef struct { - TIFFVSetMethod vsetfield; /* tag set routine */ - TIFFVGetMethod vgetfield; /* tag get routine */ - TIFFPrintMethod printdir; /* directory print routine */ -} TIFFTagMethods; - -extern TIFFTagMethods *TIFFAccessTagMethods(TIFF *); -extern void *TIFFGetClientInfo(TIFF *, const char *); -extern void TIFFSetClientInfo(TIFF *, void *, const char *); - -extern void TIFFCleanup(TIFF* tif); -extern void TIFFClose(TIFF* tif); -extern int TIFFFlush(TIFF* tif); -extern int TIFFFlushData(TIFF* tif); -extern int TIFFGetField(TIFF* tif, uint32 tag, ...); -extern int TIFFVGetField(TIFF* tif, uint32 tag, va_list ap); -extern int TIFFGetFieldDefaulted(TIFF* tif, uint32 tag, ...); -extern int TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap); -extern int TIFFReadDirectory(TIFF* tif); -extern int TIFFReadCustomDirectory(TIFF* tif, toff_t diroff, const TIFFFieldArray* infoarray); -extern int TIFFReadEXIFDirectory(TIFF* tif, toff_t diroff); -extern uint64 TIFFScanlineSize64(TIFF* tif); -extern tmsize_t TIFFScanlineSize(TIFF* tif); -extern uint64 TIFFRasterScanlineSize64(TIFF* tif); -extern tmsize_t TIFFRasterScanlineSize(TIFF* tif); -extern uint64 TIFFStripSize64(TIFF* tif); -extern tmsize_t TIFFStripSize(TIFF* tif); -extern uint64 TIFFRawStripSize64(TIFF* tif, uint32 strip); -extern tmsize_t TIFFRawStripSize(TIFF* tif, uint32 strip); -extern uint64 TIFFVStripSize64(TIFF* tif, uint32 nrows); -extern tmsize_t TIFFVStripSize(TIFF* tif, uint32 nrows); -extern uint64 TIFFTileRowSize64(TIFF* tif); -extern tmsize_t TIFFTileRowSize(TIFF* tif); -extern uint64 TIFFTileSize64(TIFF* tif); -extern tmsize_t TIFFTileSize(TIFF* tif); -extern uint64 TIFFVTileSize64(TIFF* tif, uint32 nrows); -extern tmsize_t TIFFVTileSize(TIFF* tif, uint32 nrows); -extern uint32 TIFFDefaultStripSize(TIFF* tif, uint32 request); -extern void TIFFDefaultTileSize(TIFF*, uint32*, uint32*); -extern int TIFFFileno(TIFF*); -extern int TIFFSetFileno(TIFF*, int); -extern thandle_t TIFFClientdata(TIFF*); -extern thandle_t TIFFSetClientdata(TIFF*, thandle_t); -extern int TIFFGetMode(TIFF*); -extern int TIFFSetMode(TIFF*, int); -extern int TIFFIsTiled(TIFF*); -extern int TIFFIsByteSwapped(TIFF*); -extern int TIFFIsUpSampled(TIFF*); -extern int TIFFIsMSB2LSB(TIFF*); -extern int TIFFIsBigEndian(TIFF*); -extern TIFFReadWriteProc TIFFGetReadProc(TIFF*); -extern TIFFReadWriteProc TIFFGetWriteProc(TIFF*); -extern TIFFSeekProc TIFFGetSeekProc(TIFF*); -extern TIFFCloseProc TIFFGetCloseProc(TIFF*); -extern TIFFSizeProc TIFFGetSizeProc(TIFF*); -extern TIFFMapFileProc TIFFGetMapFileProc(TIFF*); -extern TIFFUnmapFileProc TIFFGetUnmapFileProc(TIFF*); -extern uint32 TIFFCurrentRow(TIFF*); -extern uint16 TIFFCurrentDirectory(TIFF*); -extern uint16 TIFFNumberOfDirectories(TIFF*); -extern uint64 TIFFCurrentDirOffset(TIFF*); -extern uint32 TIFFCurrentStrip(TIFF*); -extern uint32 TIFFCurrentTile(TIFF* tif); -extern int TIFFReadBufferSetup(TIFF* tif, void* bp, tmsize_t size); -extern int TIFFWriteBufferSetup(TIFF* tif, void* bp, tmsize_t size); -extern int TIFFSetupStrips(TIFF *); -extern int TIFFWriteCheck(TIFF*, int, const char *); -extern void TIFFFreeDirectory(TIFF*); -extern int TIFFCreateDirectory(TIFF*); -extern int TIFFCreateCustomDirectory(TIFF*,const TIFFFieldArray*); -extern int TIFFCreateEXIFDirectory(TIFF*); -extern int TIFFLastDirectory(TIFF*); -extern int TIFFSetDirectory(TIFF*, uint16); -extern int TIFFSetSubDirectory(TIFF*, uint64); -extern int TIFFUnlinkDirectory(TIFF*, uint16); -extern int TIFFSetField(TIFF*, uint32, ...); -extern int TIFFVSetField(TIFF*, uint32, va_list); -extern int TIFFUnsetField(TIFF*, uint32); -extern int TIFFWriteDirectory(TIFF *); -extern int TIFFWriteCustomDirectory(TIFF *, uint64 *); -extern int TIFFCheckpointDirectory(TIFF *); -extern int TIFFRewriteDirectory(TIFF *); - -#if defined(c_plusplus) || defined(__cplusplus) -extern void TIFFPrintDirectory(TIFF*, FILE*, long = 0); -extern int TIFFReadScanline(TIFF* tif, void* buf, uint32 row, uint16 sample = 0); -extern int TIFFWriteScanline(TIFF* tif, void* buf, uint32 row, uint16 sample = 0); -extern int TIFFReadRGBAImage(TIFF*, uint32, uint32, uint32*, int = 0); -extern int TIFFReadRGBAImageOriented(TIFF*, uint32, uint32, uint32*, - int = ORIENTATION_BOTLEFT, int = 0); -#else -extern void TIFFPrintDirectory(TIFF*, FILE*, long); -extern int TIFFReadScanline(TIFF* tif, void* buf, uint32 row, uint16 sample); -extern int TIFFWriteScanline(TIFF* tif, void* buf, uint32 row, uint16 sample); -extern int TIFFReadRGBAImage(TIFF*, uint32, uint32, uint32*, int); -extern int TIFFReadRGBAImageOriented(TIFF*, uint32, uint32, uint32*, int, int); -#endif - -extern int TIFFReadRGBAStrip(TIFF*, uint32, uint32 * ); -extern int TIFFReadRGBATile(TIFF*, uint32, uint32, uint32 * ); -extern int TIFFRGBAImageOK(TIFF*, char [1024]); -extern int TIFFRGBAImageBegin(TIFFRGBAImage*, TIFF*, int, char [1024]); -extern int TIFFRGBAImageGet(TIFFRGBAImage*, uint32*, uint32, uint32); -extern void TIFFRGBAImageEnd(TIFFRGBAImage*); -extern TIFF* TIFFOpen(const char*, const char*); -# ifdef __WIN32__ -extern TIFF* TIFFOpenW(const wchar_t*, const char*); -# endif /* __WIN32__ */ -extern TIFF* TIFFFdOpen(int, const char*, const char*); -extern TIFF* TIFFClientOpen(const char*, const char*, - thandle_t, - TIFFReadWriteProc, TIFFReadWriteProc, - TIFFSeekProc, TIFFCloseProc, - TIFFSizeProc, - TIFFMapFileProc, TIFFUnmapFileProc); -extern const char* TIFFFileName(TIFF*); -extern const char* TIFFSetFileName(TIFF*, const char *); -extern void TIFFError(const char*, const char*, ...) __attribute__((__format__ (__printf__,2,3))); -extern void TIFFErrorExt(thandle_t, const char*, const char*, ...) __attribute__((__format__ (__printf__,3,4))); -extern void TIFFWarning(const char*, const char*, ...) __attribute__((__format__ (__printf__,2,3))); -extern void TIFFWarningExt(thandle_t, const char*, const char*, ...) __attribute__((__format__ (__printf__,3,4))); -extern TIFFErrorHandler TIFFSetErrorHandler(TIFFErrorHandler); -extern TIFFErrorHandlerExt TIFFSetErrorHandlerExt(TIFFErrorHandlerExt); -extern TIFFErrorHandler TIFFSetWarningHandler(TIFFErrorHandler); -extern TIFFErrorHandlerExt TIFFSetWarningHandlerExt(TIFFErrorHandlerExt); -extern TIFFExtendProc TIFFSetTagExtender(TIFFExtendProc); -extern uint32 TIFFComputeTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s); -extern int TIFFCheckTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s); -extern uint32 TIFFNumberOfTiles(TIFF*); -extern tmsize_t TIFFReadTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s); -extern tmsize_t TIFFWriteTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s); -extern uint32 TIFFComputeStrip(TIFF*, uint32, uint16); -extern uint32 TIFFNumberOfStrips(TIFF*); -extern tmsize_t TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size); -extern tmsize_t TIFFReadRawStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size); -extern tmsize_t TIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size); -extern tmsize_t TIFFReadRawTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size); -extern tmsize_t TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc); -extern tmsize_t TIFFWriteRawStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc); -extern tmsize_t TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc); -extern tmsize_t TIFFWriteRawTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc); -extern int TIFFDataWidth(TIFFDataType); /* table of tag datatype widths */ -extern void TIFFSetWriteOffset(TIFF* tif, toff_t off); -extern void TIFFSwabShort(uint16*); -extern void TIFFSwabLong(uint32*); -extern void TIFFSwabLong8(uint64*); -extern void TIFFSwabFloat(float*); -extern void TIFFSwabDouble(double*); -extern void TIFFSwabArrayOfShort(uint16* wp, tmsize_t n); -extern void TIFFSwabArrayOfTriples(uint8* tp, tmsize_t n); -extern void TIFFSwabArrayOfLong(uint32* lp, tmsize_t n); -extern void TIFFSwabArrayOfLong8(uint64* lp, tmsize_t n); -extern void TIFFSwabArrayOfFloat(float* fp, tmsize_t n); -extern void TIFFSwabArrayOfDouble(double* dp, tmsize_t n); -extern void TIFFReverseBits(uint8* cp, tmsize_t n); -extern const unsigned char* TIFFGetBitRevTable(int); - -#ifdef LOGLUV_PUBLIC -#define U_NEU 0.210526316 -#define V_NEU 0.473684211 -#define UVSCALE 410. -extern double LogL16toY(int); -extern double LogL10toY(int); -extern void XYZtoRGB24(float*, uint8*); -extern int uv_decode(double*, double*, int); -extern void LogLuv24toXYZ(uint32, float*); -extern void LogLuv32toXYZ(uint32, float*); -#if defined(c_plusplus) || defined(__cplusplus) -extern int LogL16fromY(double, int = SGILOGENCODE_NODITHER); -extern int LogL10fromY(double, int = SGILOGENCODE_NODITHER); -extern int uv_encode(double, double, int = SGILOGENCODE_NODITHER); -extern uint32 LogLuv24fromXYZ(float*, int = SGILOGENCODE_NODITHER); -extern uint32 LogLuv32fromXYZ(float*, int = SGILOGENCODE_NODITHER); -#else -extern int LogL16fromY(double, int); -extern int LogL10fromY(double, int); -extern int uv_encode(double, double, int); -extern uint32 LogLuv24fromXYZ(float*, int); -extern uint32 LogLuv32fromXYZ(float*, int); -#endif -#endif /* LOGLUV_PUBLIC */ - -extern int TIFFCIELabToRGBInit(TIFFCIELabToRGB*, const TIFFDisplay *, float*); -extern void TIFFCIELabToXYZ(TIFFCIELabToRGB *, uint32, int32, int32, - float *, float *, float *); -extern void TIFFXYZToRGB(TIFFCIELabToRGB *, float, float, float, - uint32 *, uint32 *, uint32 *); - -extern int TIFFYCbCrToRGBInit(TIFFYCbCrToRGB*, float*, float*); -extern void TIFFYCbCrtoRGB(TIFFYCbCrToRGB *, uint32, int32, int32, - uint32 *, uint32 *, uint32 *); - -/**************************************************************************** - * O B S O L E T E D I N T E R F A C E S - * - * Don't use this stuff in your applications, it may be removed in the future - * libtiff versions. - ****************************************************************************/ -typedef struct { - ttag_t field_tag; /* field's tag */ - short field_readcount; /* read count/TIFF_VARIABLE/TIFF_SPP */ - short field_writecount; /* write count/TIFF_VARIABLE */ - TIFFDataType field_type; /* type of associated data */ - unsigned short field_bit; /* bit in fieldsset bit vector */ - unsigned char field_oktochange; /* if true, can change while writing */ - unsigned char field_passcount; /* if true, pass dir count on set */ - char *field_name; /* ASCII name */ -} TIFFFieldInfo; - -extern int TIFFMergeFieldInfo(TIFF*, const TIFFFieldInfo[], uint32); - -#if defined(c_plusplus) || defined(__cplusplus) -} -#endif - -#endif /* _TIFFIO_ */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tiffio.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef _TIFFIO_ +#define _TIFFIO_ + +/* + * TIFF I/O Library Definitions. + */ +#include "tiff.h" +#include "tiffvers.h" + +/* + * TIFF is defined as an incomplete type to hide the + * library's internal data structures from clients. + */ +typedef struct tiff TIFF; + +/* + * The following typedefs define the intrinsic size of + * data types used in the *exported* interfaces. These + * definitions depend on the proper definition of types + * in tiff.h. Note also that the varargs interface used + * to pass tag types and values uses the types defined in + * tiff.h directly. + * + * NB: ttag_t is unsigned int and not unsigned short because + * ANSI C requires that the type before the ellipsis be a + * promoted type (i.e. one of int, unsigned int, pointer, + * or double) and because we defined pseudo-tags that are + * outside the range of legal Aldus-assigned tags. + * NB: tsize_t is int32 and not uint32 because some functions + * return -1. + * NB: toff_t is not off_t for many reasons; TIFFs max out at + * 32-bit file offsets, and BigTIFF maxes out at 64-bit + * offsets being the most important, and to ensure use of + * a consistently unsigned type across architectures. + * Prior to libtiff 4.0, this was an unsigned 32 bit type. + */ +/* + * this is the machine addressing size type, only it's signed, so make it + * int32 on 32bit machines, int64 on 64bit machines + */ +typedef TIFF_SSIZE_T tmsize_t; +typedef uint64 toff_t; /* file offset */ +/* the following are deprecated and should be replaced by their defining + counterparts */ +typedef uint32 ttag_t; /* directory tag */ +typedef uint16 tdir_t; /* directory index */ +typedef uint16 tsample_t; /* sample number */ +typedef uint32 tstrile_t; /* strip or tile number */ +typedef tstrile_t tstrip_t; /* strip number */ +typedef tstrile_t ttile_t; /* tile number */ +typedef tmsize_t tsize_t; /* i/o size in bytes */ +typedef void* tdata_t; /* image data ref */ + +#if !defined(__WIN32__) && (defined(_WIN32) || defined(WIN32)) +#define __WIN32__ +#endif + +/* + * On windows you should define USE_WIN32_FILEIO if you are using tif_win32.c + * or AVOID_WIN32_FILEIO if you are using something else (like tif_unix.c). + * + * By default tif_unix.c is assumed. + */ + +#if defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows) +# if !defined(__CYGWIN) && !defined(AVOID_WIN32_FILEIO) && !defined(USE_WIN32_FILEIO) +# define AVOID_WIN32_FILEIO +# endif +#endif + +#if defined(USE_WIN32_FILEIO) +# define VC_EXTRALEAN +# include +# ifdef __WIN32__ +DECLARE_HANDLE(thandle_t); /* Win32 file handle */ +# else +typedef HFILE thandle_t; /* client data handle */ +# endif /* __WIN32__ */ +#else +typedef void* thandle_t; /* client data handle */ +#endif /* USE_WIN32_FILEIO */ + +/* + * Flags to pass to TIFFPrintDirectory to control + * printing of data structures that are potentially + * very large. Bit-or these flags to enable printing + * multiple items. + */ +#define TIFFPRINT_NONE 0x0 /* no extra info */ +#define TIFFPRINT_STRIPS 0x1 /* strips/tiles info */ +#define TIFFPRINT_CURVES 0x2 /* color/gray response curves */ +#define TIFFPRINT_COLORMAP 0x4 /* colormap */ +#define TIFFPRINT_JPEGQTABLES 0x100 /* JPEG Q matrices */ +#define TIFFPRINT_JPEGACTABLES 0x200 /* JPEG AC tables */ +#define TIFFPRINT_JPEGDCTABLES 0x200 /* JPEG DC tables */ + +/* + * Colour conversion stuff + */ + +/* reference white */ +#define D65_X0 (95.0470F) +#define D65_Y0 (100.0F) +#define D65_Z0 (108.8827F) + +#define D50_X0 (96.4250F) +#define D50_Y0 (100.0F) +#define D50_Z0 (82.4680F) + +/* Structure for holding information about a display device. */ + +typedef unsigned char TIFFRGBValue; /* 8-bit samples */ + +typedef struct { + float d_mat[3][3]; /* XYZ -> luminance matrix */ + float d_YCR; /* Light o/p for reference white */ + float d_YCG; + float d_YCB; + uint32 d_Vrwr; /* Pixel values for ref. white */ + uint32 d_Vrwg; + uint32 d_Vrwb; + float d_Y0R; /* Residual light for black pixel */ + float d_Y0G; + float d_Y0B; + float d_gammaR; /* Gamma values for the three guns */ + float d_gammaG; + float d_gammaB; +} TIFFDisplay; + +typedef struct { /* YCbCr->RGB support */ + TIFFRGBValue* clamptab; /* range clamping table */ + int* Cr_r_tab; + int* Cb_b_tab; + int32* Cr_g_tab; + int32* Cb_g_tab; + int32* Y_tab; +} TIFFYCbCrToRGB; + +typedef struct { /* CIE Lab 1976->RGB support */ + int range; /* Size of conversion table */ +#define CIELABTORGB_TABLE_RANGE 1500 + float rstep, gstep, bstep; + float X0, Y0, Z0; /* Reference white point */ + TIFFDisplay display; + float Yr2r[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yr to r */ + float Yg2g[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yg to g */ + float Yb2b[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yb to b */ +} TIFFCIELabToRGB; + +/* + * RGBA-style image support. + */ +typedef struct _TIFFRGBAImage TIFFRGBAImage; +/* + * The image reading and conversion routines invoke + * ``put routines'' to copy/image/whatever tiles of + * raw image data. A default set of routines are + * provided to convert/copy raw image data to 8-bit + * packed ABGR format rasters. Applications can supply + * alternate routines that unpack the data into a + * different format or, for example, unpack the data + * and draw the unpacked raster on the display. + */ +typedef void (*tileContigRoutine) + (TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32, + unsigned char*); +typedef void (*tileSeparateRoutine) + (TIFFRGBAImage*, uint32*, uint32, uint32, uint32, uint32, int32, int32, + unsigned char*, unsigned char*, unsigned char*, unsigned char*); +/* + * RGBA-reader state. + */ +struct _TIFFRGBAImage { + TIFF* tif; /* image handle */ + int stoponerr; /* stop on read error */ + int isContig; /* data is packed/separate */ + int alpha; /* type of alpha data present */ + uint32 width; /* image width */ + uint32 height; /* image height */ + uint16 bitspersample; /* image bits/sample */ + uint16 samplesperpixel; /* image samples/pixel */ + uint16 orientation; /* image orientation */ + uint16 req_orientation; /* requested orientation */ + uint16 photometric; /* image photometric interp */ + uint16* redcmap; /* colormap pallete */ + uint16* greencmap; + uint16* bluecmap; + /* get image data routine */ + int (*get)(TIFFRGBAImage*, uint32*, uint32, uint32); + /* put decoded strip/tile */ + union { + void (*any)(TIFFRGBAImage*); + tileContigRoutine contig; + tileSeparateRoutine separate; + } put; + TIFFRGBValue* Map; /* sample mapping array */ + uint32** BWmap; /* black&white map */ + uint32** PALmap; /* palette image map */ + TIFFYCbCrToRGB* ycbcr; /* YCbCr conversion state */ + TIFFCIELabToRGB* cielab; /* CIE L*a*b conversion state */ + + uint8* UaToAa; /* Unassociated alpha to associated alpha convertion LUT */ + uint8* Bitdepth16To8; /* LUT for conversion from 16bit to 8bit values */ + + int row_offset; + int col_offset; +}; + +/* + * Macros for extracting components from the + * packed ABGR form returned by TIFFReadRGBAImage. + */ +#define TIFFGetR(abgr) ((abgr) & 0xff) +#define TIFFGetG(abgr) (((abgr) >> 8) & 0xff) +#define TIFFGetB(abgr) (((abgr) >> 16) & 0xff) +#define TIFFGetA(abgr) (((abgr) >> 24) & 0xff) + +/* + * A CODEC is a software package that implements decoding, + * encoding, or decoding+encoding of a compression algorithm. + * The library provides a collection of builtin codecs. + * More codecs may be registered through calls to the library + * and/or the builtin implementations may be overridden. + */ +typedef int (*TIFFInitMethod)(TIFF*, int); +typedef struct { + char* name; + uint16 scheme; + TIFFInitMethod init; +} TIFFCodec; + +#include +#include + +/* share internal LogLuv conversion routines? */ +#ifndef LOGLUV_PUBLIC +#define LOGLUV_PUBLIC 1 +#endif + +#if !defined(__GNUC__) && !defined(__attribute__) +# define __attribute__(x) /*nothing*/ +#endif + +#if defined(c_plusplus) || defined(__cplusplus) +extern "C" { +#endif +typedef void (*TIFFErrorHandler)(const char*, const char*, va_list); +typedef void (*TIFFErrorHandlerExt)(thandle_t, const char*, const char*, va_list); +typedef tmsize_t (*TIFFReadWriteProc)(thandle_t, void*, tmsize_t); +typedef toff_t (*TIFFSeekProc)(thandle_t, toff_t, int); +typedef int (*TIFFCloseProc)(thandle_t); +typedef toff_t (*TIFFSizeProc)(thandle_t); +typedef int (*TIFFMapFileProc)(thandle_t, void** base, toff_t* size); +typedef void (*TIFFUnmapFileProc)(thandle_t, void* base, toff_t size); +typedef void (*TIFFExtendProc)(TIFF*); + +extern const char* TIFFGetVersion(void); + +extern const TIFFCodec* TIFFFindCODEC(uint16); +extern TIFFCodec* TIFFRegisterCODEC(uint16, const char*, TIFFInitMethod); +extern void TIFFUnRegisterCODEC(TIFFCodec*); +extern int TIFFIsCODECConfigured(uint16); +extern TIFFCodec* TIFFGetConfiguredCODECs(void); + +/* + * Auxiliary functions. + */ + +extern void* _TIFFmalloc(tmsize_t s); +extern void* _TIFFrealloc(void* p, tmsize_t s); +extern void _TIFFmemset(void* p, int v, tmsize_t c); +extern void _TIFFmemcpy(void* d, const void* s, tmsize_t c); +extern int _TIFFmemcmp(const void* p1, const void* p2, tmsize_t c); +extern void _TIFFfree(void* p); + +/* +** Stuff, related to tag handling and creating custom tags. +*/ +extern int TIFFGetTagListCount( TIFF * ); +extern uint32 TIFFGetTagListEntry( TIFF *, int tag_index ); + +#define TIFF_ANY TIFF_NOTYPE /* for field descriptor searching */ +#define TIFF_VARIABLE -1 /* marker for variable length tags */ +#define TIFF_SPP -2 /* marker for SamplesPerPixel tags */ +#define TIFF_VARIABLE2 -3 /* marker for uint32 var-length tags */ + +#define FIELD_CUSTOM 65 + +typedef struct _TIFFField TIFFField; +typedef struct _TIFFFieldArray TIFFFieldArray; + +extern const TIFFField* TIFFFindField(TIFF *, uint32, TIFFDataType); +extern const TIFFField* TIFFFieldWithTag(TIFF*, uint32); +extern const TIFFField* TIFFFieldWithName(TIFF*, const char *); + +extern uint32 TIFFFieldTag(const TIFFField*); +extern const char* TIFFFieldName(const TIFFField*); +extern TIFFDataType TIFFFieldDataType(const TIFFField*); +extern int TIFFFieldPassCount(const TIFFField*); +extern int TIFFFieldReadCount(const TIFFField*); +extern int TIFFFieldWriteCount(const TIFFField*); + +typedef int (*TIFFVSetMethod)(TIFF*, uint32, va_list); +typedef int (*TIFFVGetMethod)(TIFF*, uint32, va_list); +typedef void (*TIFFPrintMethod)(TIFF*, FILE*, long); + +typedef struct { + TIFFVSetMethod vsetfield; /* tag set routine */ + TIFFVGetMethod vgetfield; /* tag get routine */ + TIFFPrintMethod printdir; /* directory print routine */ +} TIFFTagMethods; + +extern TIFFTagMethods *TIFFAccessTagMethods(TIFF *); +extern void *TIFFGetClientInfo(TIFF *, const char *); +extern void TIFFSetClientInfo(TIFF *, void *, const char *); + +extern void TIFFCleanup(TIFF* tif); +extern void TIFFClose(TIFF* tif); +extern int TIFFFlush(TIFF* tif); +extern int TIFFFlushData(TIFF* tif); +extern int TIFFGetField(TIFF* tif, uint32 tag, ...); +extern int TIFFVGetField(TIFF* tif, uint32 tag, va_list ap); +extern int TIFFGetFieldDefaulted(TIFF* tif, uint32 tag, ...); +extern int TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap); +extern int TIFFReadDirectory(TIFF* tif); +extern int TIFFReadCustomDirectory(TIFF* tif, toff_t diroff, const TIFFFieldArray* infoarray); +extern int TIFFReadEXIFDirectory(TIFF* tif, toff_t diroff); +extern uint64 TIFFScanlineSize64(TIFF* tif); +extern tmsize_t TIFFScanlineSize(TIFF* tif); +extern uint64 TIFFRasterScanlineSize64(TIFF* tif); +extern tmsize_t TIFFRasterScanlineSize(TIFF* tif); +extern uint64 TIFFStripSize64(TIFF* tif); +extern tmsize_t TIFFStripSize(TIFF* tif); +extern uint64 TIFFRawStripSize64(TIFF* tif, uint32 strip); +extern tmsize_t TIFFRawStripSize(TIFF* tif, uint32 strip); +extern uint64 TIFFVStripSize64(TIFF* tif, uint32 nrows); +extern tmsize_t TIFFVStripSize(TIFF* tif, uint32 nrows); +extern uint64 TIFFTileRowSize64(TIFF* tif); +extern tmsize_t TIFFTileRowSize(TIFF* tif); +extern uint64 TIFFTileSize64(TIFF* tif); +extern tmsize_t TIFFTileSize(TIFF* tif); +extern uint64 TIFFVTileSize64(TIFF* tif, uint32 nrows); +extern tmsize_t TIFFVTileSize(TIFF* tif, uint32 nrows); +extern uint32 TIFFDefaultStripSize(TIFF* tif, uint32 request); +extern void TIFFDefaultTileSize(TIFF*, uint32*, uint32*); +extern int TIFFFileno(TIFF*); +extern int TIFFSetFileno(TIFF*, int); +extern thandle_t TIFFClientdata(TIFF*); +extern thandle_t TIFFSetClientdata(TIFF*, thandle_t); +extern int TIFFGetMode(TIFF*); +extern int TIFFSetMode(TIFF*, int); +extern int TIFFIsTiled(TIFF*); +extern int TIFFIsByteSwapped(TIFF*); +extern int TIFFIsUpSampled(TIFF*); +extern int TIFFIsMSB2LSB(TIFF*); +extern int TIFFIsBigEndian(TIFF*); +extern TIFFReadWriteProc TIFFGetReadProc(TIFF*); +extern TIFFReadWriteProc TIFFGetWriteProc(TIFF*); +extern TIFFSeekProc TIFFGetSeekProc(TIFF*); +extern TIFFCloseProc TIFFGetCloseProc(TIFF*); +extern TIFFSizeProc TIFFGetSizeProc(TIFF*); +extern TIFFMapFileProc TIFFGetMapFileProc(TIFF*); +extern TIFFUnmapFileProc TIFFGetUnmapFileProc(TIFF*); +extern uint32 TIFFCurrentRow(TIFF*); +extern uint16 TIFFCurrentDirectory(TIFF*); +extern uint16 TIFFNumberOfDirectories(TIFF*); +extern uint64 TIFFCurrentDirOffset(TIFF*); +extern uint32 TIFFCurrentStrip(TIFF*); +extern uint32 TIFFCurrentTile(TIFF* tif); +extern int TIFFReadBufferSetup(TIFF* tif, void* bp, tmsize_t size); +extern int TIFFWriteBufferSetup(TIFF* tif, void* bp, tmsize_t size); +extern int TIFFSetupStrips(TIFF *); +extern int TIFFWriteCheck(TIFF*, int, const char *); +extern void TIFFFreeDirectory(TIFF*); +extern int TIFFCreateDirectory(TIFF*); +extern int TIFFCreateCustomDirectory(TIFF*,const TIFFFieldArray*); +extern int TIFFCreateEXIFDirectory(TIFF*); +extern int TIFFLastDirectory(TIFF*); +extern int TIFFSetDirectory(TIFF*, uint16); +extern int TIFFSetSubDirectory(TIFF*, uint64); +extern int TIFFUnlinkDirectory(TIFF*, uint16); +extern int TIFFSetField(TIFF*, uint32, ...); +extern int TIFFVSetField(TIFF*, uint32, va_list); +extern int TIFFUnsetField(TIFF*, uint32); +extern int TIFFWriteDirectory(TIFF *); +extern int TIFFWriteCustomDirectory(TIFF *, uint64 *); +extern int TIFFCheckpointDirectory(TIFF *); +extern int TIFFRewriteDirectory(TIFF *); + +#if defined(c_plusplus) || defined(__cplusplus) +extern void TIFFPrintDirectory(TIFF*, FILE*, long = 0); +extern int TIFFReadScanline(TIFF* tif, void* buf, uint32 row, uint16 sample = 0); +extern int TIFFWriteScanline(TIFF* tif, void* buf, uint32 row, uint16 sample = 0); +extern int TIFFReadRGBAImage(TIFF*, uint32, uint32, uint32*, int = 0); +extern int TIFFReadRGBAImageOriented(TIFF*, uint32, uint32, uint32*, + int = ORIENTATION_BOTLEFT, int = 0); +#else +extern void TIFFPrintDirectory(TIFF*, FILE*, long); +extern int TIFFReadScanline(TIFF* tif, void* buf, uint32 row, uint16 sample); +extern int TIFFWriteScanline(TIFF* tif, void* buf, uint32 row, uint16 sample); +extern int TIFFReadRGBAImage(TIFF*, uint32, uint32, uint32*, int); +extern int TIFFReadRGBAImageOriented(TIFF*, uint32, uint32, uint32*, int, int); +#endif + +extern int TIFFReadRGBAStrip(TIFF*, uint32, uint32 * ); +extern int TIFFReadRGBATile(TIFF*, uint32, uint32, uint32 * ); +extern int TIFFRGBAImageOK(TIFF*, char [1024]); +extern int TIFFRGBAImageBegin(TIFFRGBAImage*, TIFF*, int, char [1024]); +extern int TIFFRGBAImageGet(TIFFRGBAImage*, uint32*, uint32, uint32); +extern void TIFFRGBAImageEnd(TIFFRGBAImage*); +extern TIFF* TIFFOpen(const char*, const char*); +# ifdef __WIN32__ +extern TIFF* TIFFOpenW(const wchar_t*, const char*); +# endif /* __WIN32__ */ +extern TIFF* TIFFFdOpen(int, const char*, const char*); +extern TIFF* TIFFClientOpen(const char*, const char*, + thandle_t, + TIFFReadWriteProc, TIFFReadWriteProc, + TIFFSeekProc, TIFFCloseProc, + TIFFSizeProc, + TIFFMapFileProc, TIFFUnmapFileProc); +extern const char* TIFFFileName(TIFF*); +extern const char* TIFFSetFileName(TIFF*, const char *); +extern void TIFFError(const char*, const char*, ...) __attribute__((__format__ (__printf__,2,3))); +extern void TIFFErrorExt(thandle_t, const char*, const char*, ...) __attribute__((__format__ (__printf__,3,4))); +extern void TIFFWarning(const char*, const char*, ...) __attribute__((__format__ (__printf__,2,3))); +extern void TIFFWarningExt(thandle_t, const char*, const char*, ...) __attribute__((__format__ (__printf__,3,4))); +extern TIFFErrorHandler TIFFSetErrorHandler(TIFFErrorHandler); +extern TIFFErrorHandlerExt TIFFSetErrorHandlerExt(TIFFErrorHandlerExt); +extern TIFFErrorHandler TIFFSetWarningHandler(TIFFErrorHandler); +extern TIFFErrorHandlerExt TIFFSetWarningHandlerExt(TIFFErrorHandlerExt); +extern TIFFExtendProc TIFFSetTagExtender(TIFFExtendProc); +extern uint32 TIFFComputeTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s); +extern int TIFFCheckTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s); +extern uint32 TIFFNumberOfTiles(TIFF*); +extern tmsize_t TIFFReadTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s); +extern tmsize_t TIFFWriteTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s); +extern uint32 TIFFComputeStrip(TIFF*, uint32, uint16); +extern uint32 TIFFNumberOfStrips(TIFF*); +extern tmsize_t TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size); +extern tmsize_t TIFFReadRawStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size); +extern tmsize_t TIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size); +extern tmsize_t TIFFReadRawTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size); +extern tmsize_t TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc); +extern tmsize_t TIFFWriteRawStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc); +extern tmsize_t TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc); +extern tmsize_t TIFFWriteRawTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc); +extern int TIFFDataWidth(TIFFDataType); /* table of tag datatype widths */ +extern void TIFFSetWriteOffset(TIFF* tif, toff_t off); +extern void TIFFSwabShort(uint16*); +extern void TIFFSwabLong(uint32*); +extern void TIFFSwabLong8(uint64*); +extern void TIFFSwabFloat(float*); +extern void TIFFSwabDouble(double*); +extern void TIFFSwabArrayOfShort(uint16* wp, tmsize_t n); +extern void TIFFSwabArrayOfTriples(uint8* tp, tmsize_t n); +extern void TIFFSwabArrayOfLong(uint32* lp, tmsize_t n); +extern void TIFFSwabArrayOfLong8(uint64* lp, tmsize_t n); +extern void TIFFSwabArrayOfFloat(float* fp, tmsize_t n); +extern void TIFFSwabArrayOfDouble(double* dp, tmsize_t n); +extern void TIFFReverseBits(uint8* cp, tmsize_t n); +extern const unsigned char* TIFFGetBitRevTable(int); + +#ifdef LOGLUV_PUBLIC +#define U_NEU 0.210526316 +#define V_NEU 0.473684211 +#define UVSCALE 410. +extern double LogL16toY(int); +extern double LogL10toY(int); +extern void XYZtoRGB24(float*, uint8*); +extern int uv_decode(double*, double*, int); +extern void LogLuv24toXYZ(uint32, float*); +extern void LogLuv32toXYZ(uint32, float*); +#if defined(c_plusplus) || defined(__cplusplus) +extern int LogL16fromY(double, int = SGILOGENCODE_NODITHER); +extern int LogL10fromY(double, int = SGILOGENCODE_NODITHER); +extern int uv_encode(double, double, int = SGILOGENCODE_NODITHER); +extern uint32 LogLuv24fromXYZ(float*, int = SGILOGENCODE_NODITHER); +extern uint32 LogLuv32fromXYZ(float*, int = SGILOGENCODE_NODITHER); +#else +extern int LogL16fromY(double, int); +extern int LogL10fromY(double, int); +extern int uv_encode(double, double, int); +extern uint32 LogLuv24fromXYZ(float*, int); +extern uint32 LogLuv32fromXYZ(float*, int); +#endif +#endif /* LOGLUV_PUBLIC */ + +extern int TIFFCIELabToRGBInit(TIFFCIELabToRGB*, const TIFFDisplay *, float*); +extern void TIFFCIELabToXYZ(TIFFCIELabToRGB *, uint32, int32, int32, + float *, float *, float *); +extern void TIFFXYZToRGB(TIFFCIELabToRGB *, float, float, float, + uint32 *, uint32 *, uint32 *); + +extern int TIFFYCbCrToRGBInit(TIFFYCbCrToRGB*, float*, float*); +extern void TIFFYCbCrtoRGB(TIFFYCbCrToRGB *, uint32, int32, int32, + uint32 *, uint32 *, uint32 *); + +/**************************************************************************** + * O B S O L E T E D I N T E R F A C E S + * + * Don't use this stuff in your applications, it may be removed in the future + * libtiff versions. + ****************************************************************************/ +typedef struct { + ttag_t field_tag; /* field's tag */ + short field_readcount; /* read count/TIFF_VARIABLE/TIFF_SPP */ + short field_writecount; /* write count/TIFF_VARIABLE */ + TIFFDataType field_type; /* type of associated data */ + unsigned short field_bit; /* bit in fieldsset bit vector */ + unsigned char field_oktochange; /* if true, can change while writing */ + unsigned char field_passcount; /* if true, pass dir count on set */ + char *field_name; /* ASCII name */ +} TIFFFieldInfo; + +extern int TIFFMergeFieldInfo(TIFF*, const TIFFFieldInfo[], uint32); + +#if defined(c_plusplus) || defined(__cplusplus) +} +#endif + +#endif /* _TIFFIO_ */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tiffio.hxx b/Source/LibTIFF4/tiffio.hxx index 7bf2cd1..852e033 100644 --- a/Source/LibTIFF4/tiffio.hxx +++ b/Source/LibTIFF4/tiffio.hxx @@ -1,49 +1,49 @@ -/* $Id: tiffio.hxx,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifndef _TIFFIO_HXX_ -#define _TIFFIO_HXX_ - -/* - * TIFF I/O library definitions which provide C++ streams API. - */ - -#include -#include "tiff.h" - -extern TIFF* TIFFStreamOpen(const char*, std::ostream *); -extern TIFF* TIFFStreamOpen(const char*, std::istream *); - -#endif /* _TIFFIO_HXX_ */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c++ - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tiffio.hxx,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef _TIFFIO_HXX_ +#define _TIFFIO_HXX_ + +/* + * TIFF I/O library definitions which provide C++ streams API. + */ + +#include +#include "tiff.h" + +extern TIFF* TIFFStreamOpen(const char*, std::ostream *); +extern TIFF* TIFFStreamOpen(const char*, std::istream *); + +#endif /* _TIFFIO_HXX_ */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c++ + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tiffiop.h b/Source/LibTIFF4/tiffiop.h index 35174e6..0a1206e 100644 --- a/Source/LibTIFF4/tiffiop.h +++ b/Source/LibTIFF4/tiffiop.h @@ -1,367 +1,367 @@ -/* $Id: tiffiop.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ - -/* - * Copyright (c) 1988-1997 Sam Leffler - * Copyright (c) 1991-1997 Silicon Graphics, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and - * its documentation for any purpose is hereby granted without fee, provided - * that (i) the above copyright notices and this permission notice appear in - * all copies of the software and related documentation, and (ii) the names of - * Sam Leffler and Silicon Graphics may not be used in any advertising or - * publicity relating to the software without the specific, prior written - * permission of Sam Leffler and Silicon Graphics. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR - * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifndef _TIFFIOP_ -#define _TIFFIOP_ -/* - * ``Library-private'' definitions. - */ - -#include "tif_config.h" - -#ifdef HAVE_FCNTL_H -# include -#endif - -#ifdef HAVE_SYS_TYPES_H -# include -#endif - -#ifdef HAVE_STRING_H -# include -#endif - -#ifdef HAVE_ASSERT_H -# include -#else -# define assert(x) -#endif - -#ifdef HAVE_SEARCH_H -# include -#else -extern void *lfind(const void *, const void *, size_t *, size_t, - int (*)(const void *, const void *)); -#endif - -#include "tiffio.h" - -#include "tif_dir.h" - -#ifndef STRIP_SIZE_DEFAULT -# define STRIP_SIZE_DEFAULT 8192 -#endif - -#define streq(a,b) (strcmp(a,b) == 0) - -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 -#endif - -typedef struct client_info { - struct client_info *next; - void *data; - char *name; -} TIFFClientInfoLink; - -/* - * Typedefs for ``method pointers'' used internally. - * these are depriciated and provided only for backwards compatibility - */ -typedef unsigned char tidataval_t; /* internal image data value type */ -typedef tidataval_t* tidata_t; /* reference to internal image data */ - -typedef void (*TIFFVoidMethod)(TIFF*); -typedef int (*TIFFBoolMethod)(TIFF*); -typedef int (*TIFFPreMethod)(TIFF*, uint16); -typedef int (*TIFFCodeMethod)(TIFF* tif, uint8* buf, tmsize_t size, uint16 sample); -typedef int (*TIFFSeekMethod)(TIFF*, uint32); -typedef void (*TIFFPostMethod)(TIFF* tif, uint8* buf, tmsize_t size); -typedef uint32 (*TIFFStripMethod)(TIFF*, uint32); -typedef void (*TIFFTileMethod)(TIFF*, uint32*, uint32*); - -struct tiff { - char* tif_name; /* name of open file */ - int tif_fd; /* open file descriptor */ - int tif_mode; /* open mode (O_*) */ - uint32 tif_flags; - #define TIFF_FILLORDER 0x00003 /* natural bit fill order for machine */ - #define TIFF_DIRTYHEADER 0x00004 /* header must be written on close */ - #define TIFF_DIRTYDIRECT 0x00008 /* current directory must be written */ - #define TIFF_BUFFERSETUP 0x00010 /* data buffers setup */ - #define TIFF_CODERSETUP 0x00020 /* encoder/decoder setup done */ - #define TIFF_BEENWRITING 0x00040 /* written 1+ scanlines to file */ - #define TIFF_SWAB 0x00080 /* byte swap file information */ - #define TIFF_NOBITREV 0x00100 /* inhibit bit reversal logic */ - #define TIFF_MYBUFFER 0x00200 /* my raw data buffer; free on close */ - #define TIFF_ISTILED 0x00400 /* file is tile, not strip- based */ - #define TIFF_MAPPED 0x00800 /* file is mapped into memory */ - #define TIFF_POSTENCODE 0x01000 /* need call to postencode routine */ - #define TIFF_INSUBIFD 0x02000 /* currently writing a subifd */ - #define TIFF_UPSAMPLED 0x04000 /* library is doing data up-sampling */ - #define TIFF_STRIPCHOP 0x08000 /* enable strip chopping support */ - #define TIFF_HEADERONLY 0x10000 /* read header only, do not process the first directory */ - #define TIFF_NOREADRAW 0x20000 /* skip reading of raw uncompressed image data */ - #define TIFF_INCUSTOMIFD 0x40000 /* currently writing a custom IFD */ - #define TIFF_BIGTIFF 0x80000 /* read/write bigtiff */ - #define TIFF_BUF4WRITE 0x100000 /* rawcc bytes are for writing */ - #define TIFF_DIRTYSTRIP 0x200000 /* stripoffsets/stripbytecount dirty*/ - #define TIFF_PERSAMPLE 0x400000 /* get/set per sample tags as arrays */ - #define TIFF_BUFFERMMAP 0x800000 /* read buffer (tif_rawdata) points into mmap() memory */ - uint64 tif_diroff; /* file offset of current directory */ - uint64 tif_nextdiroff; /* file offset of following directory */ - uint64* tif_dirlist; /* list of offsets to already seen directories to prevent IFD looping */ - uint16 tif_dirlistsize; /* number of entires in offset list */ - uint16 tif_dirnumber; /* number of already seen directories */ - TIFFDirectory tif_dir; /* internal rep of current directory */ - TIFFDirectory tif_customdir; /* custom IFDs are separated from the main ones */ - union { - TIFFHeaderCommon common; - TIFFHeaderClassic classic; - TIFFHeaderBig big; - } tif_header; - uint16 tif_header_size; /* file's header block and its length */ - uint32 tif_row; /* current scanline */ - uint16 tif_curdir; /* current directory (index) */ - uint32 tif_curstrip; /* current strip for read/write */ - uint64 tif_curoff; /* current offset for read/write */ - uint64 tif_dataoff; /* current offset for writing dir */ - /* SubIFD support */ - uint16 tif_nsubifd; /* remaining subifds to write */ - uint64 tif_subifdoff; /* offset for patching SubIFD link */ - /* tiling support */ - uint32 tif_col; /* current column (offset by row too) */ - uint32 tif_curtile; /* current tile for read/write */ - tmsize_t tif_tilesize; /* # of bytes in a tile */ - /* compression scheme hooks */ - int tif_decodestatus; - TIFFBoolMethod tif_fixuptags; /* called in TIFFReadDirectory */ - TIFFBoolMethod tif_setupdecode; /* called once before predecode */ - TIFFPreMethod tif_predecode; /* pre- row/strip/tile decoding */ - TIFFBoolMethod tif_setupencode; /* called once before preencode */ - int tif_encodestatus; - TIFFPreMethod tif_preencode; /* pre- row/strip/tile encoding */ - TIFFBoolMethod tif_postencode; /* post- row/strip/tile encoding */ - TIFFCodeMethod tif_decoderow; /* scanline decoding routine */ - TIFFCodeMethod tif_encoderow; /* scanline encoding routine */ - TIFFCodeMethod tif_decodestrip; /* strip decoding routine */ - TIFFCodeMethod tif_encodestrip; /* strip encoding routine */ - TIFFCodeMethod tif_decodetile; /* tile decoding routine */ - TIFFCodeMethod tif_encodetile; /* tile encoding routine */ - TIFFVoidMethod tif_close; /* cleanup-on-close routine */ - TIFFSeekMethod tif_seek; /* position within a strip routine */ - TIFFVoidMethod tif_cleanup; /* cleanup state routine */ - TIFFStripMethod tif_defstripsize; /* calculate/constrain strip size */ - TIFFTileMethod tif_deftilesize; /* calculate/constrain tile size */ - uint8* tif_data; /* compression scheme private data */ - /* input/output buffering */ - tmsize_t tif_scanlinesize; /* # of bytes in a scanline */ - tmsize_t tif_scanlineskew; /* scanline skew for reading strips */ - uint8* tif_rawdata; /* raw data buffer */ - tmsize_t tif_rawdatasize; /* # of bytes in raw data buffer */ - tmsize_t tif_rawdataoff; /* rawdata offset within strip */ - tmsize_t tif_rawdataloaded;/* amount of data in rawdata */ - uint8* tif_rawcp; /* current spot in raw buffer */ - tmsize_t tif_rawcc; /* bytes unread from raw buffer */ - /* memory-mapped file support */ - uint8* tif_base; /* base of mapped file */ - tmsize_t tif_size; /* size of mapped file region (bytes, thus tmsize_t) */ - TIFFMapFileProc tif_mapproc; /* map file method */ - TIFFUnmapFileProc tif_unmapproc; /* unmap file method */ - /* input/output callback methods */ - thandle_t tif_clientdata; /* callback parameter */ - TIFFReadWriteProc tif_readproc; /* read method */ - TIFFReadWriteProc tif_writeproc; /* write method */ - TIFFSeekProc tif_seekproc; /* lseek method */ - TIFFCloseProc tif_closeproc; /* close method */ - TIFFSizeProc tif_sizeproc; /* filesize method */ - /* post-decoding support */ - TIFFPostMethod tif_postdecode; /* post decoding routine */ - /* tag support */ - TIFFField** tif_fields; /* sorted table of registered tags */ - size_t tif_nfields; /* # entries in registered tag table */ - const TIFFField* tif_foundfield; /* cached pointer to already found tag */ - TIFFTagMethods tif_tagmethods; /* tag get/set/print routines */ - TIFFClientInfoLink* tif_clientinfo; /* extra client information. */ - /* Backward compatibility stuff. We need these two fields for - * setting up an old tag extension scheme. */ - TIFFFieldArray* tif_fieldscompat; - size_t tif_nfieldscompat; -}; - -#define isPseudoTag(t) (t > 0xffff) /* is tag value normal or pseudo */ - -#define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0) -#define isMapped(tif) (((tif)->tif_flags & TIFF_MAPPED) != 0) -#define isFillOrder(tif, o) (((tif)->tif_flags & (o)) != 0) -#define isUpSampled(tif) (((tif)->tif_flags & TIFF_UPSAMPLED) != 0) -#define TIFFReadFile(tif, buf, size) \ - ((*(tif)->tif_readproc)((tif)->tif_clientdata,(buf),(size))) -#define TIFFWriteFile(tif, buf, size) \ - ((*(tif)->tif_writeproc)((tif)->tif_clientdata,(buf),(size))) -#define TIFFSeekFile(tif, off, whence) \ - ((*(tif)->tif_seekproc)((tif)->tif_clientdata,(off),(whence))) -#define TIFFCloseFile(tif) \ - ((*(tif)->tif_closeproc)((tif)->tif_clientdata)) -#define TIFFGetFileSize(tif) \ - ((*(tif)->tif_sizeproc)((tif)->tif_clientdata)) -#define TIFFMapFileContents(tif, paddr, psize) \ - ((*(tif)->tif_mapproc)((tif)->tif_clientdata,(paddr),(psize))) -#define TIFFUnmapFileContents(tif, addr, size) \ - ((*(tif)->tif_unmapproc)((tif)->tif_clientdata,(addr),(size))) - -/* - * Default Read/Seek/Write definitions. - */ -#ifndef ReadOK -#define ReadOK(tif, buf, size) \ - (TIFFReadFile((tif),(buf),(size))==(size)) -#endif -#ifndef SeekOK -#define SeekOK(tif, off) \ - (TIFFSeekFile((tif),(off),SEEK_SET)==(off)) -#endif -#ifndef WriteOK -#define WriteOK(tif, buf, size) \ - (TIFFWriteFile((tif),(buf),(size))==(size)) -#endif - -/* NB: the uint32 casts are to silence certain ANSI-C compilers */ -#define TIFFhowmany_32(x, y) (((uint32)x < (0xffffffff - (uint32)(y-1))) ? \ - ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y))) : \ - 0U) -#define TIFFhowmany8_32(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3) -#define TIFFroundup_32(x, y) (TIFFhowmany_32(x,y)*(y)) -#define TIFFhowmany_64(x, y) ((((uint64)(x))+(((uint64)(y))-1))/((uint64)(y))) -#define TIFFhowmany8_64(x) (((x)&0x07)?((uint64)(x)>>3)+1:(uint64)(x)>>3) -#define TIFFroundup_64(x, y) (TIFFhowmany_64(x,y)*(y)) - -/* Safe multiply which returns zero if there is an integer overflow */ -#define TIFFSafeMultiply(t,v,m) ((((t)(m) != (t)0) && (((t)(((v)*(m))/(m))) == (t)(v))) ? (t)((v)*(m)) : (t)0) - -#define TIFFmax(A,B) ((A)>(B)?(A):(B)) -#define TIFFmin(A,B) ((A)<(B)?(A):(B)) - -#define TIFFArrayCount(a) (sizeof (a) / sizeof ((a)[0])) - -#if defined(__cplusplus) -extern "C" { -#endif -extern int _TIFFgetMode(const char* mode, const char* module); -extern int _TIFFNoRowEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s); -extern int _TIFFNoStripEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s); -extern int _TIFFNoTileEncode(TIFF*, uint8* pp, tmsize_t cc, uint16 s); -extern int _TIFFNoRowDecode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s); -extern int _TIFFNoStripDecode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s); -extern int _TIFFNoTileDecode(TIFF*, uint8* pp, tmsize_t cc, uint16 s); -extern void _TIFFNoPostDecode(TIFF* tif, uint8* buf, tmsize_t cc); -extern int _TIFFNoPreCode(TIFF* tif, uint16 s); -extern int _TIFFNoSeek(TIFF* tif, uint32 off); -extern void _TIFFSwab16BitData(TIFF* tif, uint8* buf, tmsize_t cc); -extern void _TIFFSwab24BitData(TIFF* tif, uint8* buf, tmsize_t cc); -extern void _TIFFSwab32BitData(TIFF* tif, uint8* buf, tmsize_t cc); -extern void _TIFFSwab64BitData(TIFF* tif, uint8* buf, tmsize_t cc); -extern int TIFFFlushData1(TIFF* tif); -extern int TIFFDefaultDirectory(TIFF* tif); -extern void _TIFFSetDefaultCompressionState(TIFF* tif); -extern int _TIFFRewriteField(TIFF *, uint16, TIFFDataType, tmsize_t, void *); -extern int TIFFSetCompressionScheme(TIFF* tif, int scheme); -extern int TIFFSetDefaultCompressionState(TIFF* tif); -extern uint32 _TIFFDefaultStripSize(TIFF* tif, uint32 s); -extern void _TIFFDefaultTileSize(TIFF* tif, uint32* tw, uint32* th); -extern int _TIFFDataSize(TIFFDataType type); - -extern void _TIFFsetByteArray(void**, void*, uint32); -extern void _TIFFsetString(char**, char*); -extern void _TIFFsetShortArray(uint16**, uint16*, uint32); -extern void _TIFFsetLongArray(uint32**, uint32*, uint32); -extern void _TIFFsetFloatArray(float**, float*, uint32); -extern void _TIFFsetDoubleArray(double**, double*, uint32); - -extern void _TIFFprintAscii(FILE*, const char*); -extern void _TIFFprintAsciiTag(FILE*, const char*, const char*); - -extern TIFFErrorHandler _TIFFwarningHandler; -extern TIFFErrorHandler _TIFFerrorHandler; -extern TIFFErrorHandlerExt _TIFFwarningHandlerExt; -extern TIFFErrorHandlerExt _TIFFerrorHandlerExt; - -extern uint32 _TIFFMultiply32(TIFF*, uint32, uint32, const char*); -extern uint64 _TIFFMultiply64(TIFF*, uint64, uint64, const char*); -extern void* _TIFFCheckMalloc(TIFF*, tmsize_t, tmsize_t, const char*); -extern void* _TIFFCheckRealloc(TIFF*, void*, tmsize_t, tmsize_t, const char*); - -extern double _TIFFUInt64ToDouble(uint64); -extern float _TIFFUInt64ToFloat(uint64); - -extern int TIFFInitDumpMode(TIFF*, int); -#ifdef PACKBITS_SUPPORT -extern int TIFFInitPackBits(TIFF*, int); -#endif -#ifdef CCITT_SUPPORT -extern int TIFFInitCCITTRLE(TIFF*, int), TIFFInitCCITTRLEW(TIFF*, int); -extern int TIFFInitCCITTFax3(TIFF*, int), TIFFInitCCITTFax4(TIFF*, int); -#endif -#ifdef THUNDER_SUPPORT -extern int TIFFInitThunderScan(TIFF*, int); -#endif -#ifdef NEXT_SUPPORT -extern int TIFFInitNeXT(TIFF*, int); -#endif -#ifdef LZW_SUPPORT -extern int TIFFInitLZW(TIFF*, int); -#endif -#ifdef OJPEG_SUPPORT -extern int TIFFInitOJPEG(TIFF*, int); -#endif -#ifdef JPEG_SUPPORT -extern int TIFFInitJPEG(TIFF*, int); -#endif -#ifdef JBIG_SUPPORT -extern int TIFFInitJBIG(TIFF*, int); -#endif -#ifdef ZIP_SUPPORT -extern int TIFFInitZIP(TIFF*, int); -#endif -#ifdef PIXARLOG_SUPPORT -extern int TIFFInitPixarLog(TIFF*, int); -#endif -#ifdef LOGLUV_SUPPORT -extern int TIFFInitSGILog(TIFF*, int); -#endif -#ifdef LZMA_SUPPORT -extern int TIFFInitLZMA(TIFF*, int); -#endif -#ifdef VMS -extern const TIFFCodec _TIFFBuiltinCODECS[]; -#else -extern TIFFCodec _TIFFBuiltinCODECS[]; -#endif - -#if defined(__cplusplus) -} -#endif -#endif /* _TIFFIOP_ */ - -/* vim: set ts=8 sts=8 sw=8 noet: */ -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* $Id: tiffiop.h,v 1.4 2012/10/07 15:54:03 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef _TIFFIOP_ +#define _TIFFIOP_ +/* + * ``Library-private'' definitions. + */ + +#include "tif_config.h" + +#ifdef HAVE_FCNTL_H +# include +#endif + +#ifdef HAVE_SYS_TYPES_H +# include +#endif + +#ifdef HAVE_STRING_H +# include +#endif + +#ifdef HAVE_ASSERT_H +# include +#else +# define assert(x) +#endif + +#ifdef HAVE_SEARCH_H +# include +#else +extern void *lfind(const void *, const void *, size_t *, size_t, + int (*)(const void *, const void *)); +#endif + +#include "tiffio.h" + +#include "tif_dir.h" + +#ifndef STRIP_SIZE_DEFAULT +# define STRIP_SIZE_DEFAULT 8192 +#endif + +#define streq(a,b) (strcmp(a,b) == 0) + +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif + +typedef struct client_info { + struct client_info *next; + void *data; + char *name; +} TIFFClientInfoLink; + +/* + * Typedefs for ``method pointers'' used internally. + * these are depriciated and provided only for backwards compatibility + */ +typedef unsigned char tidataval_t; /* internal image data value type */ +typedef tidataval_t* tidata_t; /* reference to internal image data */ + +typedef void (*TIFFVoidMethod)(TIFF*); +typedef int (*TIFFBoolMethod)(TIFF*); +typedef int (*TIFFPreMethod)(TIFF*, uint16); +typedef int (*TIFFCodeMethod)(TIFF* tif, uint8* buf, tmsize_t size, uint16 sample); +typedef int (*TIFFSeekMethod)(TIFF*, uint32); +typedef void (*TIFFPostMethod)(TIFF* tif, uint8* buf, tmsize_t size); +typedef uint32 (*TIFFStripMethod)(TIFF*, uint32); +typedef void (*TIFFTileMethod)(TIFF*, uint32*, uint32*); + +struct tiff { + char* tif_name; /* name of open file */ + int tif_fd; /* open file descriptor */ + int tif_mode; /* open mode (O_*) */ + uint32 tif_flags; + #define TIFF_FILLORDER 0x00003 /* natural bit fill order for machine */ + #define TIFF_DIRTYHEADER 0x00004 /* header must be written on close */ + #define TIFF_DIRTYDIRECT 0x00008 /* current directory must be written */ + #define TIFF_BUFFERSETUP 0x00010 /* data buffers setup */ + #define TIFF_CODERSETUP 0x00020 /* encoder/decoder setup done */ + #define TIFF_BEENWRITING 0x00040 /* written 1+ scanlines to file */ + #define TIFF_SWAB 0x00080 /* byte swap file information */ + #define TIFF_NOBITREV 0x00100 /* inhibit bit reversal logic */ + #define TIFF_MYBUFFER 0x00200 /* my raw data buffer; free on close */ + #define TIFF_ISTILED 0x00400 /* file is tile, not strip- based */ + #define TIFF_MAPPED 0x00800 /* file is mapped into memory */ + #define TIFF_POSTENCODE 0x01000 /* need call to postencode routine */ + #define TIFF_INSUBIFD 0x02000 /* currently writing a subifd */ + #define TIFF_UPSAMPLED 0x04000 /* library is doing data up-sampling */ + #define TIFF_STRIPCHOP 0x08000 /* enable strip chopping support */ + #define TIFF_HEADERONLY 0x10000 /* read header only, do not process the first directory */ + #define TIFF_NOREADRAW 0x20000 /* skip reading of raw uncompressed image data */ + #define TIFF_INCUSTOMIFD 0x40000 /* currently writing a custom IFD */ + #define TIFF_BIGTIFF 0x80000 /* read/write bigtiff */ + #define TIFF_BUF4WRITE 0x100000 /* rawcc bytes are for writing */ + #define TIFF_DIRTYSTRIP 0x200000 /* stripoffsets/stripbytecount dirty*/ + #define TIFF_PERSAMPLE 0x400000 /* get/set per sample tags as arrays */ + #define TIFF_BUFFERMMAP 0x800000 /* read buffer (tif_rawdata) points into mmap() memory */ + uint64 tif_diroff; /* file offset of current directory */ + uint64 tif_nextdiroff; /* file offset of following directory */ + uint64* tif_dirlist; /* list of offsets to already seen directories to prevent IFD looping */ + uint16 tif_dirlistsize; /* number of entires in offset list */ + uint16 tif_dirnumber; /* number of already seen directories */ + TIFFDirectory tif_dir; /* internal rep of current directory */ + TIFFDirectory tif_customdir; /* custom IFDs are separated from the main ones */ + union { + TIFFHeaderCommon common; + TIFFHeaderClassic classic; + TIFFHeaderBig big; + } tif_header; + uint16 tif_header_size; /* file's header block and its length */ + uint32 tif_row; /* current scanline */ + uint16 tif_curdir; /* current directory (index) */ + uint32 tif_curstrip; /* current strip for read/write */ + uint64 tif_curoff; /* current offset for read/write */ + uint64 tif_dataoff; /* current offset for writing dir */ + /* SubIFD support */ + uint16 tif_nsubifd; /* remaining subifds to write */ + uint64 tif_subifdoff; /* offset for patching SubIFD link */ + /* tiling support */ + uint32 tif_col; /* current column (offset by row too) */ + uint32 tif_curtile; /* current tile for read/write */ + tmsize_t tif_tilesize; /* # of bytes in a tile */ + /* compression scheme hooks */ + int tif_decodestatus; + TIFFBoolMethod tif_fixuptags; /* called in TIFFReadDirectory */ + TIFFBoolMethod tif_setupdecode; /* called once before predecode */ + TIFFPreMethod tif_predecode; /* pre- row/strip/tile decoding */ + TIFFBoolMethod tif_setupencode; /* called once before preencode */ + int tif_encodestatus; + TIFFPreMethod tif_preencode; /* pre- row/strip/tile encoding */ + TIFFBoolMethod tif_postencode; /* post- row/strip/tile encoding */ + TIFFCodeMethod tif_decoderow; /* scanline decoding routine */ + TIFFCodeMethod tif_encoderow; /* scanline encoding routine */ + TIFFCodeMethod tif_decodestrip; /* strip decoding routine */ + TIFFCodeMethod tif_encodestrip; /* strip encoding routine */ + TIFFCodeMethod tif_decodetile; /* tile decoding routine */ + TIFFCodeMethod tif_encodetile; /* tile encoding routine */ + TIFFVoidMethod tif_close; /* cleanup-on-close routine */ + TIFFSeekMethod tif_seek; /* position within a strip routine */ + TIFFVoidMethod tif_cleanup; /* cleanup state routine */ + TIFFStripMethod tif_defstripsize; /* calculate/constrain strip size */ + TIFFTileMethod tif_deftilesize; /* calculate/constrain tile size */ + uint8* tif_data; /* compression scheme private data */ + /* input/output buffering */ + tmsize_t tif_scanlinesize; /* # of bytes in a scanline */ + tmsize_t tif_scanlineskew; /* scanline skew for reading strips */ + uint8* tif_rawdata; /* raw data buffer */ + tmsize_t tif_rawdatasize; /* # of bytes in raw data buffer */ + tmsize_t tif_rawdataoff; /* rawdata offset within strip */ + tmsize_t tif_rawdataloaded;/* amount of data in rawdata */ + uint8* tif_rawcp; /* current spot in raw buffer */ + tmsize_t tif_rawcc; /* bytes unread from raw buffer */ + /* memory-mapped file support */ + uint8* tif_base; /* base of mapped file */ + tmsize_t tif_size; /* size of mapped file region (bytes, thus tmsize_t) */ + TIFFMapFileProc tif_mapproc; /* map file method */ + TIFFUnmapFileProc tif_unmapproc; /* unmap file method */ + /* input/output callback methods */ + thandle_t tif_clientdata; /* callback parameter */ + TIFFReadWriteProc tif_readproc; /* read method */ + TIFFReadWriteProc tif_writeproc; /* write method */ + TIFFSeekProc tif_seekproc; /* lseek method */ + TIFFCloseProc tif_closeproc; /* close method */ + TIFFSizeProc tif_sizeproc; /* filesize method */ + /* post-decoding support */ + TIFFPostMethod tif_postdecode; /* post decoding routine */ + /* tag support */ + TIFFField** tif_fields; /* sorted table of registered tags */ + size_t tif_nfields; /* # entries in registered tag table */ + const TIFFField* tif_foundfield; /* cached pointer to already found tag */ + TIFFTagMethods tif_tagmethods; /* tag get/set/print routines */ + TIFFClientInfoLink* tif_clientinfo; /* extra client information. */ + /* Backward compatibility stuff. We need these two fields for + * setting up an old tag extension scheme. */ + TIFFFieldArray* tif_fieldscompat; + size_t tif_nfieldscompat; +}; + +#define isPseudoTag(t) (t > 0xffff) /* is tag value normal or pseudo */ + +#define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0) +#define isMapped(tif) (((tif)->tif_flags & TIFF_MAPPED) != 0) +#define isFillOrder(tif, o) (((tif)->tif_flags & (o)) != 0) +#define isUpSampled(tif) (((tif)->tif_flags & TIFF_UPSAMPLED) != 0) +#define TIFFReadFile(tif, buf, size) \ + ((*(tif)->tif_readproc)((tif)->tif_clientdata,(buf),(size))) +#define TIFFWriteFile(tif, buf, size) \ + ((*(tif)->tif_writeproc)((tif)->tif_clientdata,(buf),(size))) +#define TIFFSeekFile(tif, off, whence) \ + ((*(tif)->tif_seekproc)((tif)->tif_clientdata,(off),(whence))) +#define TIFFCloseFile(tif) \ + ((*(tif)->tif_closeproc)((tif)->tif_clientdata)) +#define TIFFGetFileSize(tif) \ + ((*(tif)->tif_sizeproc)((tif)->tif_clientdata)) +#define TIFFMapFileContents(tif, paddr, psize) \ + ((*(tif)->tif_mapproc)((tif)->tif_clientdata,(paddr),(psize))) +#define TIFFUnmapFileContents(tif, addr, size) \ + ((*(tif)->tif_unmapproc)((tif)->tif_clientdata,(addr),(size))) + +/* + * Default Read/Seek/Write definitions. + */ +#ifndef ReadOK +#define ReadOK(tif, buf, size) \ + (TIFFReadFile((tif),(buf),(size))==(size)) +#endif +#ifndef SeekOK +#define SeekOK(tif, off) \ + (TIFFSeekFile((tif),(off),SEEK_SET)==(off)) +#endif +#ifndef WriteOK +#define WriteOK(tif, buf, size) \ + (TIFFWriteFile((tif),(buf),(size))==(size)) +#endif + +/* NB: the uint32 casts are to silence certain ANSI-C compilers */ +#define TIFFhowmany_32(x, y) (((uint32)x < (0xffffffff - (uint32)(y-1))) ? \ + ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y))) : \ + 0U) +#define TIFFhowmany8_32(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3) +#define TIFFroundup_32(x, y) (TIFFhowmany_32(x,y)*(y)) +#define TIFFhowmany_64(x, y) ((((uint64)(x))+(((uint64)(y))-1))/((uint64)(y))) +#define TIFFhowmany8_64(x) (((x)&0x07)?((uint64)(x)>>3)+1:(uint64)(x)>>3) +#define TIFFroundup_64(x, y) (TIFFhowmany_64(x,y)*(y)) + +/* Safe multiply which returns zero if there is an integer overflow */ +#define TIFFSafeMultiply(t,v,m) ((((t)(m) != (t)0) && (((t)(((v)*(m))/(m))) == (t)(v))) ? (t)((v)*(m)) : (t)0) + +#define TIFFmax(A,B) ((A)>(B)?(A):(B)) +#define TIFFmin(A,B) ((A)<(B)?(A):(B)) + +#define TIFFArrayCount(a) (sizeof (a) / sizeof ((a)[0])) + +#if defined(__cplusplus) +extern "C" { +#endif +extern int _TIFFgetMode(const char* mode, const char* module); +extern int _TIFFNoRowEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s); +extern int _TIFFNoStripEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s); +extern int _TIFFNoTileEncode(TIFF*, uint8* pp, tmsize_t cc, uint16 s); +extern int _TIFFNoRowDecode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s); +extern int _TIFFNoStripDecode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s); +extern int _TIFFNoTileDecode(TIFF*, uint8* pp, tmsize_t cc, uint16 s); +extern void _TIFFNoPostDecode(TIFF* tif, uint8* buf, tmsize_t cc); +extern int _TIFFNoPreCode(TIFF* tif, uint16 s); +extern int _TIFFNoSeek(TIFF* tif, uint32 off); +extern void _TIFFSwab16BitData(TIFF* tif, uint8* buf, tmsize_t cc); +extern void _TIFFSwab24BitData(TIFF* tif, uint8* buf, tmsize_t cc); +extern void _TIFFSwab32BitData(TIFF* tif, uint8* buf, tmsize_t cc); +extern void _TIFFSwab64BitData(TIFF* tif, uint8* buf, tmsize_t cc); +extern int TIFFFlushData1(TIFF* tif); +extern int TIFFDefaultDirectory(TIFF* tif); +extern void _TIFFSetDefaultCompressionState(TIFF* tif); +extern int _TIFFRewriteField(TIFF *, uint16, TIFFDataType, tmsize_t, void *); +extern int TIFFSetCompressionScheme(TIFF* tif, int scheme); +extern int TIFFSetDefaultCompressionState(TIFF* tif); +extern uint32 _TIFFDefaultStripSize(TIFF* tif, uint32 s); +extern void _TIFFDefaultTileSize(TIFF* tif, uint32* tw, uint32* th); +extern int _TIFFDataSize(TIFFDataType type); + +extern void _TIFFsetByteArray(void**, void*, uint32); +extern void _TIFFsetString(char**, char*); +extern void _TIFFsetShortArray(uint16**, uint16*, uint32); +extern void _TIFFsetLongArray(uint32**, uint32*, uint32); +extern void _TIFFsetFloatArray(float**, float*, uint32); +extern void _TIFFsetDoubleArray(double**, double*, uint32); + +extern void _TIFFprintAscii(FILE*, const char*); +extern void _TIFFprintAsciiTag(FILE*, const char*, const char*); + +extern TIFFErrorHandler _TIFFwarningHandler; +extern TIFFErrorHandler _TIFFerrorHandler; +extern TIFFErrorHandlerExt _TIFFwarningHandlerExt; +extern TIFFErrorHandlerExt _TIFFerrorHandlerExt; + +extern uint32 _TIFFMultiply32(TIFF*, uint32, uint32, const char*); +extern uint64 _TIFFMultiply64(TIFF*, uint64, uint64, const char*); +extern void* _TIFFCheckMalloc(TIFF*, tmsize_t, tmsize_t, const char*); +extern void* _TIFFCheckRealloc(TIFF*, void*, tmsize_t, tmsize_t, const char*); + +extern double _TIFFUInt64ToDouble(uint64); +extern float _TIFFUInt64ToFloat(uint64); + +extern int TIFFInitDumpMode(TIFF*, int); +#ifdef PACKBITS_SUPPORT +extern int TIFFInitPackBits(TIFF*, int); +#endif +#ifdef CCITT_SUPPORT +extern int TIFFInitCCITTRLE(TIFF*, int), TIFFInitCCITTRLEW(TIFF*, int); +extern int TIFFInitCCITTFax3(TIFF*, int), TIFFInitCCITTFax4(TIFF*, int); +#endif +#ifdef THUNDER_SUPPORT +extern int TIFFInitThunderScan(TIFF*, int); +#endif +#ifdef NEXT_SUPPORT +extern int TIFFInitNeXT(TIFF*, int); +#endif +#ifdef LZW_SUPPORT +extern int TIFFInitLZW(TIFF*, int); +#endif +#ifdef OJPEG_SUPPORT +extern int TIFFInitOJPEG(TIFF*, int); +#endif +#ifdef JPEG_SUPPORT +extern int TIFFInitJPEG(TIFF*, int); +#endif +#ifdef JBIG_SUPPORT +extern int TIFFInitJBIG(TIFF*, int); +#endif +#ifdef ZIP_SUPPORT +extern int TIFFInitZIP(TIFF*, int); +#endif +#ifdef PIXARLOG_SUPPORT +extern int TIFFInitPixarLog(TIFF*, int); +#endif +#ifdef LOGLUV_SUPPORT +extern int TIFFInitSGILog(TIFF*, int); +#endif +#ifdef LZMA_SUPPORT +extern int TIFFInitLZMA(TIFF*, int); +#endif +#ifdef VMS +extern const TIFFCodec _TIFFBuiltinCODECS[]; +#else +extern TIFFCodec _TIFFBuiltinCODECS[]; +#endif + +#if defined(__cplusplus) +} +#endif +#endif /* _TIFFIOP_ */ + +/* vim: set ts=8 sts=8 sw=8 noet: */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/LibTIFF4/tiffvers.h b/Source/LibTIFF4/tiffvers.h index 5e0ff31..40edc81 100644 --- a/Source/LibTIFF4/tiffvers.h +++ b/Source/LibTIFF4/tiffvers.h @@ -1,9 +1,9 @@ -#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.3\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." -/* - * This define can be used in code that requires - * compilation-related definitions specific to a - * version or versions of the library. Runtime - * version checking should be done based on the - * string returned by TIFFGetVersion. - */ -#define TIFFLIB_VERSION 20120922 +#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.3\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." +/* + * This define can be used in code that requires + * compilation-related definitions specific to a + * version or versions of the library. Runtime + * version checking should be done based on the + * string returned by TIFFGetVersion. + */ +#define TIFFLIB_VERSION 20120922 diff --git a/Source/LibTIFF4/tiffvers.h.in b/Source/LibTIFF4/tiffvers.h.in index c855630..48ec0eb 100644 --- a/Source/LibTIFF4/tiffvers.h.in +++ b/Source/LibTIFF4/tiffvers.h.in @@ -1,9 +1,9 @@ -#define TIFFLIB_VERSION_STR "LIBTIFF, Version LIBTIFF_VERSION\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." -/* - * This define can be used in code that requires - * compilation-related definitions specific to a - * version or versions of the library. Runtime - * version checking should be done based on the - * string returned by TIFFGetVersion. - */ -#define TIFFLIB_VERSION LIBTIFF_RELEASE_DATE +#define TIFFLIB_VERSION_STR "LIBTIFF, Version LIBTIFF_VERSION\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." +/* + * This define can be used in code that requires + * compilation-related definitions specific to a + * version or versions of the library. Runtime + * version checking should be done based on the + * string returned by TIFFGetVersion. + */ +#define TIFFLIB_VERSION LIBTIFF_RELEASE_DATE diff --git a/Source/LibTIFF4/uvcode.h b/Source/LibTIFF4/uvcode.h index 8f22325..50f11d7 100644 --- a/Source/LibTIFF4/uvcode.h +++ b/Source/LibTIFF4/uvcode.h @@ -1,180 +1,180 @@ -/* Version 1.0 generated April 7, 1997 by Greg Ward Larson, SGI */ -#define UV_SQSIZ (float)0.003500 -#define UV_NDIVS 16289 -#define UV_VSTART (float)0.016940 -#define UV_NVS 163 -static struct { - float ustart; - short nus, ncum; -} uv_row[UV_NVS] = { - { (float)0.247663, 4, 0 }, - { (float)0.243779, 6, 4 }, - { (float)0.241684, 7, 10 }, - { (float)0.237874, 9, 17 }, - { (float)0.235906, 10, 26 }, - { (float)0.232153, 12, 36 }, - { (float)0.228352, 14, 48 }, - { (float)0.226259, 15, 62 }, - { (float)0.222371, 17, 77 }, - { (float)0.220410, 18, 94 }, - { (float)0.214710, 21, 112 }, - { (float)0.212714, 22, 133 }, - { (float)0.210721, 23, 155 }, - { (float)0.204976, 26, 178 }, - { (float)0.202986, 27, 204 }, - { (float)0.199245, 29, 231 }, - { (float)0.195525, 31, 260 }, - { (float)0.193560, 32, 291 }, - { (float)0.189878, 34, 323 }, - { (float)0.186216, 36, 357 }, - { (float)0.186216, 36, 393 }, - { (float)0.182592, 38, 429 }, - { (float)0.179003, 40, 467 }, - { (float)0.175466, 42, 507 }, - { (float)0.172001, 44, 549 }, - { (float)0.172001, 44, 593 }, - { (float)0.168612, 46, 637 }, - { (float)0.168612, 46, 683 }, - { (float)0.163575, 49, 729 }, - { (float)0.158642, 52, 778 }, - { (float)0.158642, 52, 830 }, - { (float)0.158642, 52, 882 }, - { (float)0.153815, 55, 934 }, - { (float)0.153815, 55, 989 }, - { (float)0.149097, 58, 1044 }, - { (float)0.149097, 58, 1102 }, - { (float)0.142746, 62, 1160 }, - { (float)0.142746, 62, 1222 }, - { (float)0.142746, 62, 1284 }, - { (float)0.138270, 65, 1346 }, - { (float)0.138270, 65, 1411 }, - { (float)0.138270, 65, 1476 }, - { (float)0.132166, 69, 1541 }, - { (float)0.132166, 69, 1610 }, - { (float)0.126204, 73, 1679 }, - { (float)0.126204, 73, 1752 }, - { (float)0.126204, 73, 1825 }, - { (float)0.120381, 77, 1898 }, - { (float)0.120381, 77, 1975 }, - { (float)0.120381, 77, 2052 }, - { (float)0.120381, 77, 2129 }, - { (float)0.112962, 82, 2206 }, - { (float)0.112962, 82, 2288 }, - { (float)0.112962, 82, 2370 }, - { (float)0.107450, 86, 2452 }, - { (float)0.107450, 86, 2538 }, - { (float)0.107450, 86, 2624 }, - { (float)0.107450, 86, 2710 }, - { (float)0.100343, 91, 2796 }, - { (float)0.100343, 91, 2887 }, - { (float)0.100343, 91, 2978 }, - { (float)0.095126, 95, 3069 }, - { (float)0.095126, 95, 3164 }, - { (float)0.095126, 95, 3259 }, - { (float)0.095126, 95, 3354 }, - { (float)0.088276, 100, 3449 }, - { (float)0.088276, 100, 3549 }, - { (float)0.088276, 100, 3649 }, - { (float)0.088276, 100, 3749 }, - { (float)0.081523, 105, 3849 }, - { (float)0.081523, 105, 3954 }, - { (float)0.081523, 105, 4059 }, - { (float)0.081523, 105, 4164 }, - { (float)0.074861, 110, 4269 }, - { (float)0.074861, 110, 4379 }, - { (float)0.074861, 110, 4489 }, - { (float)0.074861, 110, 4599 }, - { (float)0.068290, 115, 4709 }, - { (float)0.068290, 115, 4824 }, - { (float)0.068290, 115, 4939 }, - { (float)0.068290, 115, 5054 }, - { (float)0.063573, 119, 5169 }, - { (float)0.063573, 119, 5288 }, - { (float)0.063573, 119, 5407 }, - { (float)0.063573, 119, 5526 }, - { (float)0.057219, 124, 5645 }, - { (float)0.057219, 124, 5769 }, - { (float)0.057219, 124, 5893 }, - { (float)0.057219, 124, 6017 }, - { (float)0.050985, 129, 6141 }, - { (float)0.050985, 129, 6270 }, - { (float)0.050985, 129, 6399 }, - { (float)0.050985, 129, 6528 }, - { (float)0.050985, 129, 6657 }, - { (float)0.044859, 134, 6786 }, - { (float)0.044859, 134, 6920 }, - { (float)0.044859, 134, 7054 }, - { (float)0.044859, 134, 7188 }, - { (float)0.040571, 138, 7322 }, - { (float)0.040571, 138, 7460 }, - { (float)0.040571, 138, 7598 }, - { (float)0.040571, 138, 7736 }, - { (float)0.036339, 142, 7874 }, - { (float)0.036339, 142, 8016 }, - { (float)0.036339, 142, 8158 }, - { (float)0.036339, 142, 8300 }, - { (float)0.032139, 146, 8442 }, - { (float)0.032139, 146, 8588 }, - { (float)0.032139, 146, 8734 }, - { (float)0.032139, 146, 8880 }, - { (float)0.027947, 150, 9026 }, - { (float)0.027947, 150, 9176 }, - { (float)0.027947, 150, 9326 }, - { (float)0.023739, 154, 9476 }, - { (float)0.023739, 154, 9630 }, - { (float)0.023739, 154, 9784 }, - { (float)0.023739, 154, 9938 }, - { (float)0.019504, 158, 10092 }, - { (float)0.019504, 158, 10250 }, - { (float)0.019504, 158, 10408 }, - { (float)0.016976, 161, 10566 }, - { (float)0.016976, 161, 10727 }, - { (float)0.016976, 161, 10888 }, - { (float)0.016976, 161, 11049 }, - { (float)0.012639, 165, 11210 }, - { (float)0.012639, 165, 11375 }, - { (float)0.012639, 165, 11540 }, - { (float)0.009991, 168, 11705 }, - { (float)0.009991, 168, 11873 }, - { (float)0.009991, 168, 12041 }, - { (float)0.009016, 170, 12209 }, - { (float)0.009016, 170, 12379 }, - { (float)0.009016, 170, 12549 }, - { (float)0.006217, 173, 12719 }, - { (float)0.006217, 173, 12892 }, - { (float)0.005097, 175, 13065 }, - { (float)0.005097, 175, 13240 }, - { (float)0.005097, 175, 13415 }, - { (float)0.003909, 177, 13590 }, - { (float)0.003909, 177, 13767 }, - { (float)0.002340, 177, 13944 }, - { (float)0.002389, 170, 14121 }, - { (float)0.001068, 164, 14291 }, - { (float)0.001653, 157, 14455 }, - { (float)0.000717, 150, 14612 }, - { (float)0.001614, 143, 14762 }, - { (float)0.000270, 136, 14905 }, - { (float)0.000484, 129, 15041 }, - { (float)0.001103, 123, 15170 }, - { (float)0.001242, 115, 15293 }, - { (float)0.001188, 109, 15408 }, - { (float)0.001011, 103, 15517 }, - { (float)0.000709, 97, 15620 }, - { (float)0.000301, 89, 15717 }, - { (float)0.002416, 82, 15806 }, - { (float)0.003251, 76, 15888 }, - { (float)0.003246, 69, 15964 }, - { (float)0.004141, 62, 16033 }, - { (float)0.005963, 55, 16095 }, - { (float)0.008839, 47, 16150 }, - { (float)0.010490, 40, 16197 }, - { (float)0.016994, 31, 16237 }, - { (float)0.023659, 21, 16268 }, -}; -/* - * Local Variables: - * mode: c - * c-basic-offset: 8 - * fill-column: 78 - * End: - */ +/* Version 1.0 generated April 7, 1997 by Greg Ward Larson, SGI */ +#define UV_SQSIZ (float)0.003500 +#define UV_NDIVS 16289 +#define UV_VSTART (float)0.016940 +#define UV_NVS 163 +static struct { + float ustart; + short nus, ncum; +} uv_row[UV_NVS] = { + { (float)0.247663, 4, 0 }, + { (float)0.243779, 6, 4 }, + { (float)0.241684, 7, 10 }, + { (float)0.237874, 9, 17 }, + { (float)0.235906, 10, 26 }, + { (float)0.232153, 12, 36 }, + { (float)0.228352, 14, 48 }, + { (float)0.226259, 15, 62 }, + { (float)0.222371, 17, 77 }, + { (float)0.220410, 18, 94 }, + { (float)0.214710, 21, 112 }, + { (float)0.212714, 22, 133 }, + { (float)0.210721, 23, 155 }, + { (float)0.204976, 26, 178 }, + { (float)0.202986, 27, 204 }, + { (float)0.199245, 29, 231 }, + { (float)0.195525, 31, 260 }, + { (float)0.193560, 32, 291 }, + { (float)0.189878, 34, 323 }, + { (float)0.186216, 36, 357 }, + { (float)0.186216, 36, 393 }, + { (float)0.182592, 38, 429 }, + { (float)0.179003, 40, 467 }, + { (float)0.175466, 42, 507 }, + { (float)0.172001, 44, 549 }, + { (float)0.172001, 44, 593 }, + { (float)0.168612, 46, 637 }, + { (float)0.168612, 46, 683 }, + { (float)0.163575, 49, 729 }, + { (float)0.158642, 52, 778 }, + { (float)0.158642, 52, 830 }, + { (float)0.158642, 52, 882 }, + { (float)0.153815, 55, 934 }, + { (float)0.153815, 55, 989 }, + { (float)0.149097, 58, 1044 }, + { (float)0.149097, 58, 1102 }, + { (float)0.142746, 62, 1160 }, + { (float)0.142746, 62, 1222 }, + { (float)0.142746, 62, 1284 }, + { (float)0.138270, 65, 1346 }, + { (float)0.138270, 65, 1411 }, + { (float)0.138270, 65, 1476 }, + { (float)0.132166, 69, 1541 }, + { (float)0.132166, 69, 1610 }, + { (float)0.126204, 73, 1679 }, + { (float)0.126204, 73, 1752 }, + { (float)0.126204, 73, 1825 }, + { (float)0.120381, 77, 1898 }, + { (float)0.120381, 77, 1975 }, + { (float)0.120381, 77, 2052 }, + { (float)0.120381, 77, 2129 }, + { (float)0.112962, 82, 2206 }, + { (float)0.112962, 82, 2288 }, + { (float)0.112962, 82, 2370 }, + { (float)0.107450, 86, 2452 }, + { (float)0.107450, 86, 2538 }, + { (float)0.107450, 86, 2624 }, + { (float)0.107450, 86, 2710 }, + { (float)0.100343, 91, 2796 }, + { (float)0.100343, 91, 2887 }, + { (float)0.100343, 91, 2978 }, + { (float)0.095126, 95, 3069 }, + { (float)0.095126, 95, 3164 }, + { (float)0.095126, 95, 3259 }, + { (float)0.095126, 95, 3354 }, + { (float)0.088276, 100, 3449 }, + { (float)0.088276, 100, 3549 }, + { (float)0.088276, 100, 3649 }, + { (float)0.088276, 100, 3749 }, + { (float)0.081523, 105, 3849 }, + { (float)0.081523, 105, 3954 }, + { (float)0.081523, 105, 4059 }, + { (float)0.081523, 105, 4164 }, + { (float)0.074861, 110, 4269 }, + { (float)0.074861, 110, 4379 }, + { (float)0.074861, 110, 4489 }, + { (float)0.074861, 110, 4599 }, + { (float)0.068290, 115, 4709 }, + { (float)0.068290, 115, 4824 }, + { (float)0.068290, 115, 4939 }, + { (float)0.068290, 115, 5054 }, + { (float)0.063573, 119, 5169 }, + { (float)0.063573, 119, 5288 }, + { (float)0.063573, 119, 5407 }, + { (float)0.063573, 119, 5526 }, + { (float)0.057219, 124, 5645 }, + { (float)0.057219, 124, 5769 }, + { (float)0.057219, 124, 5893 }, + { (float)0.057219, 124, 6017 }, + { (float)0.050985, 129, 6141 }, + { (float)0.050985, 129, 6270 }, + { (float)0.050985, 129, 6399 }, + { (float)0.050985, 129, 6528 }, + { (float)0.050985, 129, 6657 }, + { (float)0.044859, 134, 6786 }, + { (float)0.044859, 134, 6920 }, + { (float)0.044859, 134, 7054 }, + { (float)0.044859, 134, 7188 }, + { (float)0.040571, 138, 7322 }, + { (float)0.040571, 138, 7460 }, + { (float)0.040571, 138, 7598 }, + { (float)0.040571, 138, 7736 }, + { (float)0.036339, 142, 7874 }, + { (float)0.036339, 142, 8016 }, + { (float)0.036339, 142, 8158 }, + { (float)0.036339, 142, 8300 }, + { (float)0.032139, 146, 8442 }, + { (float)0.032139, 146, 8588 }, + { (float)0.032139, 146, 8734 }, + { (float)0.032139, 146, 8880 }, + { (float)0.027947, 150, 9026 }, + { (float)0.027947, 150, 9176 }, + { (float)0.027947, 150, 9326 }, + { (float)0.023739, 154, 9476 }, + { (float)0.023739, 154, 9630 }, + { (float)0.023739, 154, 9784 }, + { (float)0.023739, 154, 9938 }, + { (float)0.019504, 158, 10092 }, + { (float)0.019504, 158, 10250 }, + { (float)0.019504, 158, 10408 }, + { (float)0.016976, 161, 10566 }, + { (float)0.016976, 161, 10727 }, + { (float)0.016976, 161, 10888 }, + { (float)0.016976, 161, 11049 }, + { (float)0.012639, 165, 11210 }, + { (float)0.012639, 165, 11375 }, + { (float)0.012639, 165, 11540 }, + { (float)0.009991, 168, 11705 }, + { (float)0.009991, 168, 11873 }, + { (float)0.009991, 168, 12041 }, + { (float)0.009016, 170, 12209 }, + { (float)0.009016, 170, 12379 }, + { (float)0.009016, 170, 12549 }, + { (float)0.006217, 173, 12719 }, + { (float)0.006217, 173, 12892 }, + { (float)0.005097, 175, 13065 }, + { (float)0.005097, 175, 13240 }, + { (float)0.005097, 175, 13415 }, + { (float)0.003909, 177, 13590 }, + { (float)0.003909, 177, 13767 }, + { (float)0.002340, 177, 13944 }, + { (float)0.002389, 170, 14121 }, + { (float)0.001068, 164, 14291 }, + { (float)0.001653, 157, 14455 }, + { (float)0.000717, 150, 14612 }, + { (float)0.001614, 143, 14762 }, + { (float)0.000270, 136, 14905 }, + { (float)0.000484, 129, 15041 }, + { (float)0.001103, 123, 15170 }, + { (float)0.001242, 115, 15293 }, + { (float)0.001188, 109, 15408 }, + { (float)0.001011, 103, 15517 }, + { (float)0.000709, 97, 15620 }, + { (float)0.000301, 89, 15717 }, + { (float)0.002416, 82, 15806 }, + { (float)0.003251, 76, 15888 }, + { (float)0.003246, 69, 15964 }, + { (float)0.004141, 62, 16033 }, + { (float)0.005963, 55, 16095 }, + { (float)0.008839, 47, 16150 }, + { (float)0.010490, 40, 16197 }, + { (float)0.016994, 31, 16237 }, + { (float)0.023659, 21, 16268 }, +}; +/* + * Local Variables: + * mode: c + * c-basic-offset: 8 + * fill-column: 78 + * End: + */ diff --git a/Source/Metadata/FreeImageTag.cpp b/Source/Metadata/FreeImageTag.cpp index 5d9f303..45a6b1e 100644 --- a/Source/Metadata/FreeImageTag.cpp +++ b/Source/Metadata/FreeImageTag.cpp @@ -305,9 +305,9 @@ FreeImage_TagDataWidth(FREE_IMAGE_MDTYPE type) { 4, // FIDT_FLOAT = 11, // 32-bit IEEE floating point 8, // FIDT_DOUBLE = 12, // 64-bit IEEE floating point 4, // FIDT_IFD = 13, // 32-bit unsigned integer (offset) - 4, // FIDT_PALETTE = 14 // 32-bit RGBQUAD - 0, // placeholder (15) - 8, // FIDT_LONG8 = 16, // 64-bit unsigned integer + 4, // FIDT_PALETTE = 14 // 32-bit RGBQUAD + 0, // placeholder (15) + 8, // FIDT_LONG8 = 16, // 64-bit unsigned integer 8, // FIDT_SLONG8 = 17, // 64-bit signed integer 8 // FIDT_IFD8 = 18 // 64-bit unsigned integer (offset) }; diff --git a/Source/Metadata/FreeImageTag.h b/Source/Metadata/FreeImageTag.h index 4f3bffa..8ba6a1c 100644 --- a/Source/Metadata/FreeImageTag.h +++ b/Source/Metadata/FreeImageTag.h @@ -321,15 +321,15 @@ TagInfo *tag_info = s.getTagInfo(EXIF_MAIN, 0x0100); Note on multi-threaded applications : - -The singleton pattern must be carefully constructed in multi-threaded applications. -If two threads are to execute the creation method at the same time when a singleton -does not yet exist, they both must check for an instance of the singleton and then -only one should create the new one. -The classic solution to this problem is to use mutual exclusion on the class that -indicates that the object is being instantiated. -The FreeImage solution is to instantiate the singleton before any other thread is launched, -i.e. inside the FreeImage_Initialise function (see Plugin.cpp). + +The singleton pattern must be carefully constructed in multi-threaded applications. +If two threads are to execute the creation method at the same time when a singleton +does not yet exist, they both must check for an instance of the singleton and then +only one should create the new one. +The classic solution to this problem is to use mutual exclusion on the class that +indicates that the object is being instantiated. +The FreeImage solution is to instantiate the singleton before any other thread is launched, +i.e. inside the FreeImage_Initialise function (see Plugin.cpp). */ class TagLib { diff --git a/Source/Metadata/TagConversion.cpp b/Source/Metadata/TagConversion.cpp index 06a1970..f058186 100644 --- a/Source/Metadata/TagConversion.cpp +++ b/Source/Metadata/TagConversion.cpp @@ -1,1094 +1,1094 @@ -// ========================================================== -// Tag to string conversion functions -// -// Design and implementation by -// - Hervé Drolon -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#ifdef _MSC_VER -#pragma warning (disable : 4786) // identifier was truncated to 'number' characters -#endif - -#include "FreeImage.h" -#include "Utilities.h" -#include "FreeImageTag.h" -#include "FIRational.h" - -#define MAX_TEXT_EXTENT 512 - -/** -Convert a tag to a C string -*/ -static const char* -ConvertAnyTag(FITAG *tag) { - char format[MAX_TEXT_EXTENT]; - static std::string buffer; - DWORD i; - - if(!tag) - return NULL; - - buffer.erase(); - - // convert the tag value to a string buffer - - FREE_IMAGE_MDTYPE tag_type = FreeImage_GetTagType(tag); - DWORD tag_count = FreeImage_GetTagCount(tag); - - switch(tag_type) { - case FIDT_BYTE: // N x 8-bit unsigned integer - { - BYTE *pvalue = (BYTE*)FreeImage_GetTagValue(tag); - - sprintf(format, "%ld", (LONG) pvalue[0]); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, " %ld", (LONG) pvalue[i]); - buffer += format; - } - break; - } - case FIDT_SHORT: // N x 16-bit unsigned integer - { - unsigned short *pvalue = (unsigned short *)FreeImage_GetTagValue(tag); - - sprintf(format, "%hu", pvalue[0]); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, " %hu", pvalue[i]); - buffer += format; - } - break; - } - case FIDT_LONG: // N x 32-bit unsigned integer - { - DWORD *pvalue = (DWORD *)FreeImage_GetTagValue(tag); - - sprintf(format, "%lu", pvalue[0]); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, " %lu", pvalue[i]); - buffer += format; - } - break; - } - case FIDT_RATIONAL: // N x 64-bit unsigned fraction - { - DWORD *pvalue = (DWORD*)FreeImage_GetTagValue(tag); - - sprintf(format, "%ld/%ld", pvalue[0], pvalue[1]); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, " %ld/%ld", pvalue[2*i], pvalue[2*i+1]); - buffer += format; - } - break; - } - case FIDT_SBYTE: // N x 8-bit signed integer - { - char *pvalue = (char*)FreeImage_GetTagValue(tag); - - sprintf(format, "%ld", (LONG) pvalue[0]); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, " %ld", (LONG) pvalue[i]); - buffer += format; - } - break; - } - case FIDT_SSHORT: // N x 16-bit signed integer - { - short *pvalue = (short *)FreeImage_GetTagValue(tag); - - sprintf(format, "%hd", pvalue[0]); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, " %hd", pvalue[i]); - buffer += format; - } - break; - } - case FIDT_SLONG: // N x 32-bit signed integer - { - LONG *pvalue = (LONG *)FreeImage_GetTagValue(tag); - - sprintf(format, "%ld", pvalue[0]); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, " %ld", pvalue[i]); - buffer += format; - } - break; - } - case FIDT_SRATIONAL:// N x 64-bit signed fraction - { - LONG *pvalue = (LONG*)FreeImage_GetTagValue(tag); - - sprintf(format, "%ld/%ld", pvalue[0], pvalue[1]); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, " %ld/%ld", pvalue[2*i], pvalue[2*i+1]); - buffer += format; - } - break; - } - case FIDT_FLOAT: // N x 32-bit IEEE floating point - { - float *pvalue = (float *)FreeImage_GetTagValue(tag); - - sprintf(format, "%f", (double) pvalue[0]); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, "%f", (double) pvalue[i]); - buffer += format; - } - break; - } - case FIDT_DOUBLE: // N x 64-bit IEEE floating point - { - double *pvalue = (double *)FreeImage_GetTagValue(tag); - - sprintf(format, "%f", pvalue[0]); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, "%f", pvalue[i]); - buffer += format; - } - break; - } - case FIDT_IFD: // N x 32-bit unsigned integer (offset) - { - DWORD *pvalue = (DWORD *)FreeImage_GetTagValue(tag); - - sprintf(format, "%X", pvalue[0]); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, " %X", pvalue[i]); - buffer += format; - } - break; - } - case FIDT_PALETTE: // N x 32-bit RGBQUAD - { - RGBQUAD *pvalue = (RGBQUAD *)FreeImage_GetTagValue(tag); - - sprintf(format, "(%d,%d,%d,%d)", pvalue[0].rgbRed, pvalue[0].rgbGreen, pvalue[0].rgbBlue, pvalue[0].rgbReserved); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, " (%d,%d,%d,%d)", pvalue[i].rgbRed, pvalue[i].rgbGreen, pvalue[i].rgbBlue, pvalue[i].rgbReserved); - buffer += format; - } - break; - } - - case FIDT_LONG8: // N x 64-bit unsigned integer - { - UINT64 *pvalue = (UINT64 *)FreeImage_GetTagValue(tag); - - sprintf(format, "%ld", pvalue[0]); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, "%ld", pvalue[i]); - buffer += format; - } - break; - } - - case FIDT_IFD8: // N x 64-bit unsigned integer (offset) - { - UINT64 *pvalue = (UINT64 *)FreeImage_GetTagValue(tag); - - sprintf(format, "%X", pvalue[0]); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, "%X", pvalue[i]); - buffer += format; - } - break; - } - - case FIDT_SLONG8: // N x 64-bit signed integer - { - INT64 *pvalue = (INT64 *)FreeImage_GetTagValue(tag); - - sprintf(format, "%ld", pvalue[0]); - buffer += format; - for(i = 1; i < tag_count; i++) { - sprintf(format, "%ld", pvalue[i]); - buffer += format; - } - break; - } - - case FIDT_ASCII: // 8-bit bytes w/ last byte null - case FIDT_UNDEFINED:// 8-bit untyped data - default: - { - int max_size = MIN((int)FreeImage_GetTagLength(tag), (int)MAX_TEXT_EXTENT); - if(max_size == MAX_TEXT_EXTENT) - max_size--; - memcpy(format, (char*)FreeImage_GetTagValue(tag), max_size); - format[max_size] = '\0'; - buffer += format; - break; - } - } - - return buffer.c_str(); -} - -/** -Convert a Exif tag to a C string -*/ -static const char* -ConvertExifTag(FITAG *tag) { - char format[MAX_TEXT_EXTENT]; - static std::string buffer; - - if(!tag) - return NULL; - - buffer.erase(); - - // convert the tag value to a string buffer - - switch(FreeImage_GetTagID(tag)) { - case TAG_ORIENTATION: - { - unsigned short orientation = *((unsigned short *)FreeImage_GetTagValue(tag)); - switch (orientation) { - case 1: - return "top, left side"; - case 2: - return "top, right side"; - case 3: - return "bottom, right side"; - case 4: - return "bottom, left side"; - case 5: - return "left side, top"; - case 6: - return "right side, top"; - case 7: - return "right side, bottom"; - case 8: - return "left side, bottom"; - default: - break; - } - } - break; - - case TAG_REFERENCE_BLACK_WHITE: - { - DWORD *pvalue = (DWORD*)FreeImage_GetTagValue(tag); - if(FreeImage_GetTagLength(tag) == 48) { - // reference black point value and reference white point value (ReferenceBlackWhite) - int blackR = 0, whiteR = 0, blackG = 0, whiteG = 0, blackB = 0, whiteB = 0; - if(pvalue[1]) - blackR = (int)(pvalue[0] / pvalue[1]); - if(pvalue[3]) - whiteR = (int)(pvalue[2] / pvalue[3]); - if(pvalue[5]) - blackG = (int)(pvalue[4] / pvalue[5]); - if(pvalue[7]) - whiteG = (int)(pvalue[6] / pvalue[7]); - if(pvalue[9]) - blackB = (int)(pvalue[8] / pvalue[9]); - if(pvalue[11]) - whiteB = (int)(pvalue[10] / pvalue[11]); - - sprintf(format, "[%d,%d,%d] [%d,%d,%d]", blackR, blackG, blackB, whiteR, whiteG, whiteB); - buffer += format; - return buffer.c_str(); - } - - } - break; - - case TAG_COLOR_SPACE: - { - unsigned short colorSpace = *((unsigned short *)FreeImage_GetTagValue(tag)); - if (colorSpace == 1) { - return "sRGB"; - } else if (colorSpace == 65535) { - return "Undefined"; - } else { - return "Unknown"; - } - } - break; - - case TAG_COMPONENTS_CONFIGURATION: - { - const char *componentStrings[7] = {"", "Y", "Cb", "Cr", "R", "G", "B"}; - BYTE *pvalue = (BYTE*)FreeImage_GetTagValue(tag); - for(DWORD i = 0; i < MIN((DWORD)4, FreeImage_GetTagCount(tag)); i++) { - int j = pvalue[i]; - if(j > 0 && j < 7) - buffer += componentStrings[j]; - } - return buffer.c_str(); - } - break; - - case TAG_COMPRESSED_BITS_PER_PIXEL: - { - FIRational r(tag); - buffer = r.toString(); - if(buffer == "1") - buffer += " bit/pixel"; - else - buffer += " bits/pixel"; - return buffer.c_str(); - } - break; - - case TAG_X_RESOLUTION: - case TAG_Y_RESOLUTION: - case TAG_FOCAL_PLANE_X_RES: - case TAG_FOCAL_PLANE_Y_RES: - case TAG_BRIGHTNESS_VALUE: - case TAG_EXPOSURE_BIAS_VALUE: - { - FIRational r(tag); - buffer = r.toString(); - return buffer.c_str(); - } - break; - - case TAG_RESOLUTION_UNIT: - case TAG_FOCAL_PLANE_UNIT: - { - unsigned short resolutionUnit = *((unsigned short *)FreeImage_GetTagValue(tag)); - switch (resolutionUnit) { - case 1: - return "(No unit)"; - case 2: - return "inches"; - case 3: - return "cm"; - default: - break; - } - } - break; - - case TAG_YCBCR_POSITIONING: - { - unsigned short yCbCrPosition = *((unsigned short *)FreeImage_GetTagValue(tag)); - switch (yCbCrPosition) { - case 1: - return "Center of pixel array"; - case 2: - return "Datum point"; - default: - break; - } - } - break; - - case TAG_EXPOSURE_TIME: - { - FIRational r(tag); - buffer = r.toString(); - buffer += " sec"; - return buffer.c_str(); - } - break; - - case TAG_SHUTTER_SPEED_VALUE: - { - FIRational r(tag); - LONG apexValue = r.longValue(); - LONG apexPower = 1 << apexValue; - sprintf(format, "1/%d sec", (int)apexPower); - buffer += format; - return buffer.c_str(); - } - break; - - case TAG_APERTURE_VALUE: - case TAG_MAX_APERTURE_VALUE: - { - FIRational r(tag); - double apertureApex = r.doubleValue(); - double rootTwo = sqrt((double)2); - double fStop = pow(rootTwo, apertureApex); - sprintf(format, "F%.1f", fStop); - buffer += format; - return buffer.c_str(); - } - break; - - case TAG_FNUMBER: - { - FIRational r(tag); - double fnumber = r.doubleValue(); - sprintf(format, "F%.1f", fnumber); - buffer += format; - return buffer.c_str(); - } - break; - - case TAG_FOCAL_LENGTH: - { - FIRational r(tag); - double focalLength = r.doubleValue(); - sprintf(format, "%.1f mm", focalLength); - buffer += format; - return buffer.c_str(); - } - break; - - case TAG_FOCAL_LENGTH_IN_35MM_FILM: - { - unsigned short focalLength = *((unsigned short *)FreeImage_GetTagValue(tag)); - sprintf(format, "%hu mm", focalLength); - buffer += format; - return buffer.c_str(); - } - break; - - case TAG_FLASH: - { - unsigned short flash = *((unsigned short *)FreeImage_GetTagValue(tag)); - switch(flash) { - case 0x0000: - return "Flash did not fire"; - case 0x0001: - return "Flash fired"; - case 0x0005: - return "Strobe return light not detected"; - case 0x0007: - return "Strobe return light detected"; - case 0x0009: - return "Flash fired, compulsory flash mode"; - case 0x000D: - return "Flash fired, compulsory flash mode, return light not detected"; - case 0x000F: - return "Flash fired, compulsory flash mode, return light detected"; - case 0x0010: - return "Flash did not fire, compulsory flash mode"; - case 0x0018: - return "Flash did not fire, auto mode"; - case 0x0019: - return "Flash fired, auto mode"; - case 0x001D: - return "Flash fired, auto mode, return light not detected"; - case 0x001F: - return "Flash fired, auto mode, return light detected"; - case 0x0020: - return "No flash function"; - case 0x0041: - return "Flash fired, red-eye reduction mode"; - case 0x0045: - return "Flash fired, red-eye reduction mode, return light not detected"; - case 0x0047: - return "Flash fired, red-eye reduction mode, return light detected"; - case 0x0049: - return "Flash fired, compulsory flash mode, red-eye reduction mode"; - case 0x004D: - return "Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected"; - case 0x004F: - return "Flash fired, compulsory flash mode, red-eye reduction mode, return light detected"; - case 0x0059: - return "Flash fired, auto mode, red-eye reduction mode"; - case 0x005D: - return "Flash fired, auto mode, return light not detected, red-eye reduction mode"; - case 0x005F: - return "Flash fired, auto mode, return light detected, red-eye reduction mode"; - default: - sprintf(format, "Unknown (%d)", flash); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_SCENE_TYPE: - { - BYTE sceneType = *((BYTE*)FreeImage_GetTagValue(tag)); - if (sceneType == 1) { - return "Directly photographed image"; - } else { - sprintf(format, "Unknown (%d)", sceneType); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_SUBJECT_DISTANCE: - { - FIRational r(tag); - if(r.getNumerator() == 0xFFFFFFFF) { - return "Infinity"; - } else if(r.getNumerator() == 0) { - return "Distance unknown"; - } else { - double distance = r.doubleValue(); - sprintf(format, "%.3f meters", distance); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_METERING_MODE: - { - unsigned short meteringMode = *((unsigned short *)FreeImage_GetTagValue(tag)); - switch (meteringMode) { - case 0: - return "Unknown"; - case 1: - return "Average"; - case 2: - return "Center weighted average"; - case 3: - return "Spot"; - case 4: - return "Multi-spot"; - case 5: - return "Multi-segment"; - case 6: - return "Partial"; - case 255: - return "(Other)"; - default: - return ""; - } - } - break; - - case TAG_LIGHT_SOURCE: - { - unsigned short lightSource = *((unsigned short *)FreeImage_GetTagValue(tag)); - switch (lightSource) { - case 0: - return "Unknown"; - case 1: - return "Daylight"; - case 2: - return "Fluorescent"; - case 3: - return "Tungsten (incandescent light)"; - case 4: - return "Flash"; - case 9: - return "Fine weather"; - case 10: - return "Cloudy weather"; - case 11: - return "Shade"; - case 12: - return "Daylight fluorescent (D 5700 - 7100K)"; - case 13: - return "Day white fluorescent (N 4600 - 5400K)"; - case 14: - return "Cool white fluorescent (W 3900 - 4500K)"; - case 15: - return "White fluorescent (WW 3200 - 3700K)"; - case 17: - return "Standard light A"; - case 18: - return "Standard light B"; - case 19: - return "Standard light C"; - case 20: - return "D55"; - case 21: - return "D65"; - case 22: - return "D75"; - case 23: - return "D50"; - case 24: - return "ISO studio tungsten"; - case 255: - return "(Other)"; - default: - return ""; - } - } - break; - - case TAG_SENSING_METHOD: - { - unsigned short sensingMethod = *((unsigned short *)FreeImage_GetTagValue(tag)); - - switch (sensingMethod) { - case 1: - return "(Not defined)"; - case 2: - return "One-chip color area sensor"; - case 3: - return "Two-chip color area sensor"; - case 4: - return "Three-chip color area sensor"; - case 5: - return "Color sequential area sensor"; - case 7: - return "Trilinear sensor"; - case 8: - return "Color sequential linear sensor"; - default: - return ""; - } - } - break; - - case TAG_FILE_SOURCE: - { - BYTE fileSource = *((BYTE*)FreeImage_GetTagValue(tag)); - if (fileSource == 3) { - return "Digital Still Camera (DSC)"; - } else { - sprintf(format, "Unknown (%d)", fileSource); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_EXPOSURE_PROGRAM: - { - unsigned short exposureProgram = *((unsigned short *)FreeImage_GetTagValue(tag)); - - switch (exposureProgram) { - case 1: - return "Manual control"; - case 2: - return "Program normal"; - case 3: - return "Aperture priority"; - case 4: - return "Shutter priority"; - case 5: - return "Program creative (slow program)"; - case 6: - return "Program action (high-speed program)"; - case 7: - return "Portrait mode"; - case 8: - return "Landscape mode"; - default: - sprintf(format, "Unknown program (%d)", exposureProgram); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_CUSTOM_RENDERED: - { - unsigned short customRendered = *((unsigned short *)FreeImage_GetTagValue(tag)); - - switch (customRendered) { - case 0: - return "Normal process"; - case 1: - return "Custom process"; - default: - sprintf(format, "Unknown rendering (%d)", customRendered); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_EXPOSURE_MODE: - { - unsigned short exposureMode = *((unsigned short *)FreeImage_GetTagValue(tag)); - - switch (exposureMode) { - case 0: - return "Auto exposure"; - case 1: - return "Manual exposure"; - case 2: - return "Auto bracket"; - default: - sprintf(format, "Unknown mode (%d)", exposureMode); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_WHITE_BALANCE: - { - unsigned short whiteBalance = *((unsigned short *)FreeImage_GetTagValue(tag)); - - switch (whiteBalance) { - case 0: - return "Auto white balance"; - case 1: - return "Manual white balance"; - default: - sprintf(format, "Unknown (%d)", whiteBalance); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_SCENE_CAPTURE_TYPE: - { - unsigned short sceneType = *((unsigned short *)FreeImage_GetTagValue(tag)); - - switch (sceneType) { - case 0: - return "Standard"; - case 1: - return "Landscape"; - case 2: - return "Portrait"; - case 3: - return "Night scene"; - default: - sprintf(format, "Unknown (%d)", sceneType); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_GAIN_CONTROL: - { - unsigned short gainControl = *((unsigned short *)FreeImage_GetTagValue(tag)); - - switch (gainControl) { - case 0: - return "None"; - case 1: - return "Low gain up"; - case 2: - return "High gain up"; - case 3: - return "Low gain down"; - case 4: - return "High gain down"; - default: - sprintf(format, "Unknown (%d)", gainControl); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_CONTRAST: - { - unsigned short contrast = *((unsigned short *)FreeImage_GetTagValue(tag)); - - switch (contrast) { - case 0: - return "Normal"; - case 1: - return "Soft"; - case 2: - return "Hard"; - default: - sprintf(format, "Unknown (%d)", contrast); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_SATURATION: - { - unsigned short saturation = *((unsigned short *)FreeImage_GetTagValue(tag)); - - switch (saturation) { - case 0: - return "Normal"; - case 1: - return "Low saturation"; - case 2: - return "High saturation"; - default: - sprintf(format, "Unknown (%d)", saturation); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_SHARPNESS: - { - unsigned short sharpness = *((unsigned short *)FreeImage_GetTagValue(tag)); - - switch (sharpness) { - case 0: - return "Normal"; - case 1: - return "Soft"; - case 2: - return "Hard"; - default: - sprintf(format, "Unknown (%d)", sharpness); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_SUBJECT_DISTANCE_RANGE: - { - unsigned short distanceRange = *((unsigned short *)FreeImage_GetTagValue(tag)); - - switch (distanceRange) { - case 0: - return "unknown"; - case 1: - return "Macro"; - case 2: - return "Close view"; - case 3: - return "Distant view"; - default: - sprintf(format, "Unknown (%d)", distanceRange); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_ISO_SPEED_RATINGS: - { - unsigned short isoEquiv = *((unsigned short *)FreeImage_GetTagValue(tag)); - if (isoEquiv < 50) { - isoEquiv *= 200; - } - sprintf(format, "%d", isoEquiv); - buffer += format; - return buffer.c_str(); - } - break; - - case TAG_USER_COMMENT: - { - // first 8 bytes are used to define an ID code - // we assume this is an ASCII string - const BYTE *userComment = (BYTE*)FreeImage_GetTagValue(tag); - for(DWORD i = 8; i < FreeImage_GetTagLength(tag); i++) { - buffer += userComment[i]; - } - buffer += '\0'; - return buffer.c_str(); - } - break; - - case TAG_COMPRESSION: - { - WORD compression = *((WORD*)FreeImage_GetTagValue(tag)); - switch(compression) { - case TAG_COMPRESSION_NONE: - sprintf(format, "dump mode (%d)", compression); - break; - case TAG_COMPRESSION_CCITTRLE: - sprintf(format, "CCITT modified Huffman RLE (%d)", compression); - break; - case TAG_COMPRESSION_CCITTFAX3: - sprintf(format, "CCITT Group 3 fax encoding (%d)", compression); - break; - /* - case TAG_COMPRESSION_CCITT_T4: - sprintf(format, "CCITT T.4 (TIFF 6 name) (%d)", compression); - break; - */ - case TAG_COMPRESSION_CCITTFAX4: - sprintf(format, "CCITT Group 4 fax encoding (%d)", compression); - break; - /* - case TAG_COMPRESSION_CCITT_T6: - sprintf(format, "CCITT T.6 (TIFF 6 name) (%d)", compression); - break; - */ - case TAG_COMPRESSION_LZW: - sprintf(format, "LZW (%d)", compression); - break; - case TAG_COMPRESSION_OJPEG: - sprintf(format, "!6.0 JPEG (%d)", compression); - break; - case TAG_COMPRESSION_JPEG: - sprintf(format, "JPEG (%d)", compression); - break; - case TAG_COMPRESSION_NEXT: - sprintf(format, "NeXT 2-bit RLE (%d)", compression); - break; - case TAG_COMPRESSION_CCITTRLEW: - sprintf(format, "CCITTRLEW (%d)", compression); - break; - case TAG_COMPRESSION_PACKBITS: - sprintf(format, "PackBits Macintosh RLE (%d)", compression); - break; - case TAG_COMPRESSION_THUNDERSCAN: - sprintf(format, "ThunderScan RLE (%d)", compression); - break; - case TAG_COMPRESSION_PIXARFILM: - sprintf(format, "Pixar companded 10bit LZW (%d)", compression); - break; - case TAG_COMPRESSION_PIXARLOG: - sprintf(format, "Pixar companded 11bit ZIP (%d)", compression); - break; - case TAG_COMPRESSION_DEFLATE: - sprintf(format, "Deflate compression (%d)", compression); - break; - case TAG_COMPRESSION_ADOBE_DEFLATE: - sprintf(format, "Adobe Deflate compression (%d)", compression); - break; - case TAG_COMPRESSION_DCS: - sprintf(format, "Kodak DCS encoding (%d)", compression); - break; - case TAG_COMPRESSION_JBIG: - sprintf(format, "ISO JBIG (%d)", compression); - break; - case TAG_COMPRESSION_SGILOG: - sprintf(format, "SGI Log Luminance RLE (%d)", compression); - break; - case TAG_COMPRESSION_SGILOG24: - sprintf(format, "SGI Log 24-bit packed (%d)", compression); - break; - case TAG_COMPRESSION_JP2000: - sprintf(format, "Leadtools JPEG2000 (%d)", compression); - break; - case TAG_COMPRESSION_LZMA: - sprintf(format, "LZMA2 (%d)", compression); - break; - default: - sprintf(format, "Unknown type (%d)", compression); - break; - } - - buffer += format; - return buffer.c_str(); - } - break; - } - - return ConvertAnyTag(tag); -} - -/** -Convert a Exif GPS tag to a C string -*/ -static const char* -ConvertExifGPSTag(FITAG *tag) { - char format[MAX_TEXT_EXTENT]; - static std::string buffer; - - if(!tag) - return NULL; - - buffer.erase(); - - // convert the tag value to a string buffer - - switch(FreeImage_GetTagID(tag)) { - case TAG_GPS_LATITUDE: - case TAG_GPS_LONGITUDE: - case TAG_GPS_TIME_STAMP: - { - DWORD *pvalue = (DWORD*)FreeImage_GetTagValue(tag); - if(FreeImage_GetTagLength(tag) == 24) { - // dd:mm:ss or hh:mm:ss - int dd = 0, mm = 0; - double ss = 0; - - // convert to seconds - if(pvalue[1]) - ss += ((double)pvalue[0] / (double)pvalue[1]) * 3600; - if(pvalue[3]) - ss += ((double)pvalue[2] / (double)pvalue[3]) * 60; - if(pvalue[5]) - ss += ((double)pvalue[4] / (double)pvalue[5]); - - // convert to dd:mm:ss.ss - dd = (int)(ss / 3600); - mm = (int)(ss / 60) - dd * 60; - ss = ss - dd * 3600 - mm * 60; - - sprintf(format, "%d:%d:%.2f", dd, mm, ss); - buffer += format; - return buffer.c_str(); - } - } - break; - - case TAG_GPS_VERSION_ID: - case TAG_GPS_LATITUDE_REF: - case TAG_GPS_LONGITUDE_REF: - case TAG_GPS_ALTITUDE_REF: - case TAG_GPS_ALTITUDE: - case TAG_GPS_SATELLITES: - case TAG_GPS_STATUS: - case TAG_GPS_MEASURE_MODE: - case TAG_GPS_DOP: - case TAG_GPS_SPEED_REF: - case TAG_GPS_SPEED: - case TAG_GPS_TRACK_REF: - case TAG_GPS_TRACK: - case TAG_GPS_IMG_DIRECTION_REF: - case TAG_GPS_IMG_DIRECTION: - case TAG_GPS_MAP_DATUM: - case TAG_GPS_DEST_LATITUDE_REF: - case TAG_GPS_DEST_LATITUDE: - case TAG_GPS_DEST_LONGITUDE_REF: - case TAG_GPS_DEST_LONGITUDE: - case TAG_GPS_DEST_BEARING_REF: - case TAG_GPS_DEST_BEARING: - case TAG_GPS_DEST_DISTANCE_REF: - case TAG_GPS_DEST_DISTANCE: - case TAG_GPS_PROCESSING_METHOD: - case TAG_GPS_AREA_INFORMATION: - case TAG_GPS_DATE_STAMP: - case TAG_GPS_DIFFERENTIAL: - break; - } - - return ConvertAnyTag(tag); -} - -// ========================================================== -// Tag to string conversion function -// - -const char* DLL_CALLCONV -FreeImage_TagToString(FREE_IMAGE_MDMODEL model, FITAG *tag, char *Make) { - switch(model) { - case FIMD_EXIF_MAIN: - case FIMD_EXIF_EXIF: - return ConvertExifTag(tag); - - case FIMD_EXIF_GPS: - return ConvertExifGPSTag(tag); - - case FIMD_EXIF_MAKERNOTE: - // We should use the Make string to select an appropriate conversion function - // TO DO ... - break; - - case FIMD_EXIF_INTEROP: - default: - break; - } - - return ConvertAnyTag(tag); -} - +// ========================================================== +// Tag to string conversion functions +// +// Design and implementation by +// - Hervé Drolon +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#ifdef _MSC_VER +#pragma warning (disable : 4786) // identifier was truncated to 'number' characters +#endif + +#include "FreeImage.h" +#include "Utilities.h" +#include "FreeImageTag.h" +#include "FIRational.h" + +#define MAX_TEXT_EXTENT 512 + +/** +Convert a tag to a C string +*/ +static const char* +ConvertAnyTag(FITAG *tag) { + char format[MAX_TEXT_EXTENT]; + static std::string buffer; + DWORD i; + + if(!tag) + return NULL; + + buffer.erase(); + + // convert the tag value to a string buffer + + FREE_IMAGE_MDTYPE tag_type = FreeImage_GetTagType(tag); + DWORD tag_count = FreeImage_GetTagCount(tag); + + switch(tag_type) { + case FIDT_BYTE: // N x 8-bit unsigned integer + { + BYTE *pvalue = (BYTE*)FreeImage_GetTagValue(tag); + + sprintf(format, "%ld", (LONG) pvalue[0]); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, " %ld", (LONG) pvalue[i]); + buffer += format; + } + break; + } + case FIDT_SHORT: // N x 16-bit unsigned integer + { + unsigned short *pvalue = (unsigned short *)FreeImage_GetTagValue(tag); + + sprintf(format, "%hu", pvalue[0]); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, " %hu", pvalue[i]); + buffer += format; + } + break; + } + case FIDT_LONG: // N x 32-bit unsigned integer + { + DWORD *pvalue = (DWORD *)FreeImage_GetTagValue(tag); + + sprintf(format, "%lu", pvalue[0]); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, " %lu", pvalue[i]); + buffer += format; + } + break; + } + case FIDT_RATIONAL: // N x 64-bit unsigned fraction + { + DWORD *pvalue = (DWORD*)FreeImage_GetTagValue(tag); + + sprintf(format, "%ld/%ld", pvalue[0], pvalue[1]); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, " %ld/%ld", pvalue[2*i], pvalue[2*i+1]); + buffer += format; + } + break; + } + case FIDT_SBYTE: // N x 8-bit signed integer + { + char *pvalue = (char*)FreeImage_GetTagValue(tag); + + sprintf(format, "%ld", (LONG) pvalue[0]); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, " %ld", (LONG) pvalue[i]); + buffer += format; + } + break; + } + case FIDT_SSHORT: // N x 16-bit signed integer + { + short *pvalue = (short *)FreeImage_GetTagValue(tag); + + sprintf(format, "%hd", pvalue[0]); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, " %hd", pvalue[i]); + buffer += format; + } + break; + } + case FIDT_SLONG: // N x 32-bit signed integer + { + LONG *pvalue = (LONG *)FreeImage_GetTagValue(tag); + + sprintf(format, "%ld", pvalue[0]); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, " %ld", pvalue[i]); + buffer += format; + } + break; + } + case FIDT_SRATIONAL:// N x 64-bit signed fraction + { + LONG *pvalue = (LONG*)FreeImage_GetTagValue(tag); + + sprintf(format, "%ld/%ld", pvalue[0], pvalue[1]); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, " %ld/%ld", pvalue[2*i], pvalue[2*i+1]); + buffer += format; + } + break; + } + case FIDT_FLOAT: // N x 32-bit IEEE floating point + { + float *pvalue = (float *)FreeImage_GetTagValue(tag); + + sprintf(format, "%f", (double) pvalue[0]); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, "%f", (double) pvalue[i]); + buffer += format; + } + break; + } + case FIDT_DOUBLE: // N x 64-bit IEEE floating point + { + double *pvalue = (double *)FreeImage_GetTagValue(tag); + + sprintf(format, "%f", pvalue[0]); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, "%f", pvalue[i]); + buffer += format; + } + break; + } + case FIDT_IFD: // N x 32-bit unsigned integer (offset) + { + DWORD *pvalue = (DWORD *)FreeImage_GetTagValue(tag); + + sprintf(format, "%X", pvalue[0]); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, " %X", pvalue[i]); + buffer += format; + } + break; + } + case FIDT_PALETTE: // N x 32-bit RGBQUAD + { + RGBQUAD *pvalue = (RGBQUAD *)FreeImage_GetTagValue(tag); + + sprintf(format, "(%d,%d,%d,%d)", pvalue[0].rgbRed, pvalue[0].rgbGreen, pvalue[0].rgbBlue, pvalue[0].rgbReserved); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, " (%d,%d,%d,%d)", pvalue[i].rgbRed, pvalue[i].rgbGreen, pvalue[i].rgbBlue, pvalue[i].rgbReserved); + buffer += format; + } + break; + } + + case FIDT_LONG8: // N x 64-bit unsigned integer + { + UINT64 *pvalue = (UINT64 *)FreeImage_GetTagValue(tag); + + sprintf(format, "%ld", pvalue[0]); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, "%ld", pvalue[i]); + buffer += format; + } + break; + } + + case FIDT_IFD8: // N x 64-bit unsigned integer (offset) + { + UINT64 *pvalue = (UINT64 *)FreeImage_GetTagValue(tag); + + sprintf(format, "%X", pvalue[0]); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, "%X", pvalue[i]); + buffer += format; + } + break; + } + + case FIDT_SLONG8: // N x 64-bit signed integer + { + INT64 *pvalue = (INT64 *)FreeImage_GetTagValue(tag); + + sprintf(format, "%ld", pvalue[0]); + buffer += format; + for(i = 1; i < tag_count; i++) { + sprintf(format, "%ld", pvalue[i]); + buffer += format; + } + break; + } + + case FIDT_ASCII: // 8-bit bytes w/ last byte null + case FIDT_UNDEFINED:// 8-bit untyped data + default: + { + int max_size = MIN((int)FreeImage_GetTagLength(tag), (int)MAX_TEXT_EXTENT); + if(max_size == MAX_TEXT_EXTENT) + max_size--; + memcpy(format, (char*)FreeImage_GetTagValue(tag), max_size); + format[max_size] = '\0'; + buffer += format; + break; + } + } + + return buffer.c_str(); +} + +/** +Convert a Exif tag to a C string +*/ +static const char* +ConvertExifTag(FITAG *tag) { + char format[MAX_TEXT_EXTENT]; + static std::string buffer; + + if(!tag) + return NULL; + + buffer.erase(); + + // convert the tag value to a string buffer + + switch(FreeImage_GetTagID(tag)) { + case TAG_ORIENTATION: + { + unsigned short orientation = *((unsigned short *)FreeImage_GetTagValue(tag)); + switch (orientation) { + case 1: + return "top, left side"; + case 2: + return "top, right side"; + case 3: + return "bottom, right side"; + case 4: + return "bottom, left side"; + case 5: + return "left side, top"; + case 6: + return "right side, top"; + case 7: + return "right side, bottom"; + case 8: + return "left side, bottom"; + default: + break; + } + } + break; + + case TAG_REFERENCE_BLACK_WHITE: + { + DWORD *pvalue = (DWORD*)FreeImage_GetTagValue(tag); + if(FreeImage_GetTagLength(tag) == 48) { + // reference black point value and reference white point value (ReferenceBlackWhite) + int blackR = 0, whiteR = 0, blackG = 0, whiteG = 0, blackB = 0, whiteB = 0; + if(pvalue[1]) + blackR = (int)(pvalue[0] / pvalue[1]); + if(pvalue[3]) + whiteR = (int)(pvalue[2] / pvalue[3]); + if(pvalue[5]) + blackG = (int)(pvalue[4] / pvalue[5]); + if(pvalue[7]) + whiteG = (int)(pvalue[6] / pvalue[7]); + if(pvalue[9]) + blackB = (int)(pvalue[8] / pvalue[9]); + if(pvalue[11]) + whiteB = (int)(pvalue[10] / pvalue[11]); + + sprintf(format, "[%d,%d,%d] [%d,%d,%d]", blackR, blackG, blackB, whiteR, whiteG, whiteB); + buffer += format; + return buffer.c_str(); + } + + } + break; + + case TAG_COLOR_SPACE: + { + unsigned short colorSpace = *((unsigned short *)FreeImage_GetTagValue(tag)); + if (colorSpace == 1) { + return "sRGB"; + } else if (colorSpace == 65535) { + return "Undefined"; + } else { + return "Unknown"; + } + } + break; + + case TAG_COMPONENTS_CONFIGURATION: + { + const char *componentStrings[7] = {"", "Y", "Cb", "Cr", "R", "G", "B"}; + BYTE *pvalue = (BYTE*)FreeImage_GetTagValue(tag); + for(DWORD i = 0; i < MIN((DWORD)4, FreeImage_GetTagCount(tag)); i++) { + int j = pvalue[i]; + if(j > 0 && j < 7) + buffer += componentStrings[j]; + } + return buffer.c_str(); + } + break; + + case TAG_COMPRESSED_BITS_PER_PIXEL: + { + FIRational r(tag); + buffer = r.toString(); + if(buffer == "1") + buffer += " bit/pixel"; + else + buffer += " bits/pixel"; + return buffer.c_str(); + } + break; + + case TAG_X_RESOLUTION: + case TAG_Y_RESOLUTION: + case TAG_FOCAL_PLANE_X_RES: + case TAG_FOCAL_PLANE_Y_RES: + case TAG_BRIGHTNESS_VALUE: + case TAG_EXPOSURE_BIAS_VALUE: + { + FIRational r(tag); + buffer = r.toString(); + return buffer.c_str(); + } + break; + + case TAG_RESOLUTION_UNIT: + case TAG_FOCAL_PLANE_UNIT: + { + unsigned short resolutionUnit = *((unsigned short *)FreeImage_GetTagValue(tag)); + switch (resolutionUnit) { + case 1: + return "(No unit)"; + case 2: + return "inches"; + case 3: + return "cm"; + default: + break; + } + } + break; + + case TAG_YCBCR_POSITIONING: + { + unsigned short yCbCrPosition = *((unsigned short *)FreeImage_GetTagValue(tag)); + switch (yCbCrPosition) { + case 1: + return "Center of pixel array"; + case 2: + return "Datum point"; + default: + break; + } + } + break; + + case TAG_EXPOSURE_TIME: + { + FIRational r(tag); + buffer = r.toString(); + buffer += " sec"; + return buffer.c_str(); + } + break; + + case TAG_SHUTTER_SPEED_VALUE: + { + FIRational r(tag); + LONG apexValue = r.longValue(); + LONG apexPower = 1 << apexValue; + sprintf(format, "1/%d sec", (int)apexPower); + buffer += format; + return buffer.c_str(); + } + break; + + case TAG_APERTURE_VALUE: + case TAG_MAX_APERTURE_VALUE: + { + FIRational r(tag); + double apertureApex = r.doubleValue(); + double rootTwo = sqrt((double)2); + double fStop = pow(rootTwo, apertureApex); + sprintf(format, "F%.1f", fStop); + buffer += format; + return buffer.c_str(); + } + break; + + case TAG_FNUMBER: + { + FIRational r(tag); + double fnumber = r.doubleValue(); + sprintf(format, "F%.1f", fnumber); + buffer += format; + return buffer.c_str(); + } + break; + + case TAG_FOCAL_LENGTH: + { + FIRational r(tag); + double focalLength = r.doubleValue(); + sprintf(format, "%.1f mm", focalLength); + buffer += format; + return buffer.c_str(); + } + break; + + case TAG_FOCAL_LENGTH_IN_35MM_FILM: + { + unsigned short focalLength = *((unsigned short *)FreeImage_GetTagValue(tag)); + sprintf(format, "%hu mm", focalLength); + buffer += format; + return buffer.c_str(); + } + break; + + case TAG_FLASH: + { + unsigned short flash = *((unsigned short *)FreeImage_GetTagValue(tag)); + switch(flash) { + case 0x0000: + return "Flash did not fire"; + case 0x0001: + return "Flash fired"; + case 0x0005: + return "Strobe return light not detected"; + case 0x0007: + return "Strobe return light detected"; + case 0x0009: + return "Flash fired, compulsory flash mode"; + case 0x000D: + return "Flash fired, compulsory flash mode, return light not detected"; + case 0x000F: + return "Flash fired, compulsory flash mode, return light detected"; + case 0x0010: + return "Flash did not fire, compulsory flash mode"; + case 0x0018: + return "Flash did not fire, auto mode"; + case 0x0019: + return "Flash fired, auto mode"; + case 0x001D: + return "Flash fired, auto mode, return light not detected"; + case 0x001F: + return "Flash fired, auto mode, return light detected"; + case 0x0020: + return "No flash function"; + case 0x0041: + return "Flash fired, red-eye reduction mode"; + case 0x0045: + return "Flash fired, red-eye reduction mode, return light not detected"; + case 0x0047: + return "Flash fired, red-eye reduction mode, return light detected"; + case 0x0049: + return "Flash fired, compulsory flash mode, red-eye reduction mode"; + case 0x004D: + return "Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected"; + case 0x004F: + return "Flash fired, compulsory flash mode, red-eye reduction mode, return light detected"; + case 0x0059: + return "Flash fired, auto mode, red-eye reduction mode"; + case 0x005D: + return "Flash fired, auto mode, return light not detected, red-eye reduction mode"; + case 0x005F: + return "Flash fired, auto mode, return light detected, red-eye reduction mode"; + default: + sprintf(format, "Unknown (%d)", flash); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_SCENE_TYPE: + { + BYTE sceneType = *((BYTE*)FreeImage_GetTagValue(tag)); + if (sceneType == 1) { + return "Directly photographed image"; + } else { + sprintf(format, "Unknown (%d)", sceneType); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_SUBJECT_DISTANCE: + { + FIRational r(tag); + if(r.getNumerator() == 0xFFFFFFFF) { + return "Infinity"; + } else if(r.getNumerator() == 0) { + return "Distance unknown"; + } else { + double distance = r.doubleValue(); + sprintf(format, "%.3f meters", distance); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_METERING_MODE: + { + unsigned short meteringMode = *((unsigned short *)FreeImage_GetTagValue(tag)); + switch (meteringMode) { + case 0: + return "Unknown"; + case 1: + return "Average"; + case 2: + return "Center weighted average"; + case 3: + return "Spot"; + case 4: + return "Multi-spot"; + case 5: + return "Multi-segment"; + case 6: + return "Partial"; + case 255: + return "(Other)"; + default: + return ""; + } + } + break; + + case TAG_LIGHT_SOURCE: + { + unsigned short lightSource = *((unsigned short *)FreeImage_GetTagValue(tag)); + switch (lightSource) { + case 0: + return "Unknown"; + case 1: + return "Daylight"; + case 2: + return "Fluorescent"; + case 3: + return "Tungsten (incandescent light)"; + case 4: + return "Flash"; + case 9: + return "Fine weather"; + case 10: + return "Cloudy weather"; + case 11: + return "Shade"; + case 12: + return "Daylight fluorescent (D 5700 - 7100K)"; + case 13: + return "Day white fluorescent (N 4600 - 5400K)"; + case 14: + return "Cool white fluorescent (W 3900 - 4500K)"; + case 15: + return "White fluorescent (WW 3200 - 3700K)"; + case 17: + return "Standard light A"; + case 18: + return "Standard light B"; + case 19: + return "Standard light C"; + case 20: + return "D55"; + case 21: + return "D65"; + case 22: + return "D75"; + case 23: + return "D50"; + case 24: + return "ISO studio tungsten"; + case 255: + return "(Other)"; + default: + return ""; + } + } + break; + + case TAG_SENSING_METHOD: + { + unsigned short sensingMethod = *((unsigned short *)FreeImage_GetTagValue(tag)); + + switch (sensingMethod) { + case 1: + return "(Not defined)"; + case 2: + return "One-chip color area sensor"; + case 3: + return "Two-chip color area sensor"; + case 4: + return "Three-chip color area sensor"; + case 5: + return "Color sequential area sensor"; + case 7: + return "Trilinear sensor"; + case 8: + return "Color sequential linear sensor"; + default: + return ""; + } + } + break; + + case TAG_FILE_SOURCE: + { + BYTE fileSource = *((BYTE*)FreeImage_GetTagValue(tag)); + if (fileSource == 3) { + return "Digital Still Camera (DSC)"; + } else { + sprintf(format, "Unknown (%d)", fileSource); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_EXPOSURE_PROGRAM: + { + unsigned short exposureProgram = *((unsigned short *)FreeImage_GetTagValue(tag)); + + switch (exposureProgram) { + case 1: + return "Manual control"; + case 2: + return "Program normal"; + case 3: + return "Aperture priority"; + case 4: + return "Shutter priority"; + case 5: + return "Program creative (slow program)"; + case 6: + return "Program action (high-speed program)"; + case 7: + return "Portrait mode"; + case 8: + return "Landscape mode"; + default: + sprintf(format, "Unknown program (%d)", exposureProgram); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_CUSTOM_RENDERED: + { + unsigned short customRendered = *((unsigned short *)FreeImage_GetTagValue(tag)); + + switch (customRendered) { + case 0: + return "Normal process"; + case 1: + return "Custom process"; + default: + sprintf(format, "Unknown rendering (%d)", customRendered); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_EXPOSURE_MODE: + { + unsigned short exposureMode = *((unsigned short *)FreeImage_GetTagValue(tag)); + + switch (exposureMode) { + case 0: + return "Auto exposure"; + case 1: + return "Manual exposure"; + case 2: + return "Auto bracket"; + default: + sprintf(format, "Unknown mode (%d)", exposureMode); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_WHITE_BALANCE: + { + unsigned short whiteBalance = *((unsigned short *)FreeImage_GetTagValue(tag)); + + switch (whiteBalance) { + case 0: + return "Auto white balance"; + case 1: + return "Manual white balance"; + default: + sprintf(format, "Unknown (%d)", whiteBalance); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_SCENE_CAPTURE_TYPE: + { + unsigned short sceneType = *((unsigned short *)FreeImage_GetTagValue(tag)); + + switch (sceneType) { + case 0: + return "Standard"; + case 1: + return "Landscape"; + case 2: + return "Portrait"; + case 3: + return "Night scene"; + default: + sprintf(format, "Unknown (%d)", sceneType); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_GAIN_CONTROL: + { + unsigned short gainControl = *((unsigned short *)FreeImage_GetTagValue(tag)); + + switch (gainControl) { + case 0: + return "None"; + case 1: + return "Low gain up"; + case 2: + return "High gain up"; + case 3: + return "Low gain down"; + case 4: + return "High gain down"; + default: + sprintf(format, "Unknown (%d)", gainControl); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_CONTRAST: + { + unsigned short contrast = *((unsigned short *)FreeImage_GetTagValue(tag)); + + switch (contrast) { + case 0: + return "Normal"; + case 1: + return "Soft"; + case 2: + return "Hard"; + default: + sprintf(format, "Unknown (%d)", contrast); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_SATURATION: + { + unsigned short saturation = *((unsigned short *)FreeImage_GetTagValue(tag)); + + switch (saturation) { + case 0: + return "Normal"; + case 1: + return "Low saturation"; + case 2: + return "High saturation"; + default: + sprintf(format, "Unknown (%d)", saturation); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_SHARPNESS: + { + unsigned short sharpness = *((unsigned short *)FreeImage_GetTagValue(tag)); + + switch (sharpness) { + case 0: + return "Normal"; + case 1: + return "Soft"; + case 2: + return "Hard"; + default: + sprintf(format, "Unknown (%d)", sharpness); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_SUBJECT_DISTANCE_RANGE: + { + unsigned short distanceRange = *((unsigned short *)FreeImage_GetTagValue(tag)); + + switch (distanceRange) { + case 0: + return "unknown"; + case 1: + return "Macro"; + case 2: + return "Close view"; + case 3: + return "Distant view"; + default: + sprintf(format, "Unknown (%d)", distanceRange); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_ISO_SPEED_RATINGS: + { + unsigned short isoEquiv = *((unsigned short *)FreeImage_GetTagValue(tag)); + if (isoEquiv < 50) { + isoEquiv *= 200; + } + sprintf(format, "%d", isoEquiv); + buffer += format; + return buffer.c_str(); + } + break; + + case TAG_USER_COMMENT: + { + // first 8 bytes are used to define an ID code + // we assume this is an ASCII string + const BYTE *userComment = (BYTE*)FreeImage_GetTagValue(tag); + for(DWORD i = 8; i < FreeImage_GetTagLength(tag); i++) { + buffer += userComment[i]; + } + buffer += '\0'; + return buffer.c_str(); + } + break; + + case TAG_COMPRESSION: + { + WORD compression = *((WORD*)FreeImage_GetTagValue(tag)); + switch(compression) { + case TAG_COMPRESSION_NONE: + sprintf(format, "dump mode (%d)", compression); + break; + case TAG_COMPRESSION_CCITTRLE: + sprintf(format, "CCITT modified Huffman RLE (%d)", compression); + break; + case TAG_COMPRESSION_CCITTFAX3: + sprintf(format, "CCITT Group 3 fax encoding (%d)", compression); + break; + /* + case TAG_COMPRESSION_CCITT_T4: + sprintf(format, "CCITT T.4 (TIFF 6 name) (%d)", compression); + break; + */ + case TAG_COMPRESSION_CCITTFAX4: + sprintf(format, "CCITT Group 4 fax encoding (%d)", compression); + break; + /* + case TAG_COMPRESSION_CCITT_T6: + sprintf(format, "CCITT T.6 (TIFF 6 name) (%d)", compression); + break; + */ + case TAG_COMPRESSION_LZW: + sprintf(format, "LZW (%d)", compression); + break; + case TAG_COMPRESSION_OJPEG: + sprintf(format, "!6.0 JPEG (%d)", compression); + break; + case TAG_COMPRESSION_JPEG: + sprintf(format, "JPEG (%d)", compression); + break; + case TAG_COMPRESSION_NEXT: + sprintf(format, "NeXT 2-bit RLE (%d)", compression); + break; + case TAG_COMPRESSION_CCITTRLEW: + sprintf(format, "CCITTRLEW (%d)", compression); + break; + case TAG_COMPRESSION_PACKBITS: + sprintf(format, "PackBits Macintosh RLE (%d)", compression); + break; + case TAG_COMPRESSION_THUNDERSCAN: + sprintf(format, "ThunderScan RLE (%d)", compression); + break; + case TAG_COMPRESSION_PIXARFILM: + sprintf(format, "Pixar companded 10bit LZW (%d)", compression); + break; + case TAG_COMPRESSION_PIXARLOG: + sprintf(format, "Pixar companded 11bit ZIP (%d)", compression); + break; + case TAG_COMPRESSION_DEFLATE: + sprintf(format, "Deflate compression (%d)", compression); + break; + case TAG_COMPRESSION_ADOBE_DEFLATE: + sprintf(format, "Adobe Deflate compression (%d)", compression); + break; + case TAG_COMPRESSION_DCS: + sprintf(format, "Kodak DCS encoding (%d)", compression); + break; + case TAG_COMPRESSION_JBIG: + sprintf(format, "ISO JBIG (%d)", compression); + break; + case TAG_COMPRESSION_SGILOG: + sprintf(format, "SGI Log Luminance RLE (%d)", compression); + break; + case TAG_COMPRESSION_SGILOG24: + sprintf(format, "SGI Log 24-bit packed (%d)", compression); + break; + case TAG_COMPRESSION_JP2000: + sprintf(format, "Leadtools JPEG2000 (%d)", compression); + break; + case TAG_COMPRESSION_LZMA: + sprintf(format, "LZMA2 (%d)", compression); + break; + default: + sprintf(format, "Unknown type (%d)", compression); + break; + } + + buffer += format; + return buffer.c_str(); + } + break; + } + + return ConvertAnyTag(tag); +} + +/** +Convert a Exif GPS tag to a C string +*/ +static const char* +ConvertExifGPSTag(FITAG *tag) { + char format[MAX_TEXT_EXTENT]; + static std::string buffer; + + if(!tag) + return NULL; + + buffer.erase(); + + // convert the tag value to a string buffer + + switch(FreeImage_GetTagID(tag)) { + case TAG_GPS_LATITUDE: + case TAG_GPS_LONGITUDE: + case TAG_GPS_TIME_STAMP: + { + DWORD *pvalue = (DWORD*)FreeImage_GetTagValue(tag); + if(FreeImage_GetTagLength(tag) == 24) { + // dd:mm:ss or hh:mm:ss + int dd = 0, mm = 0; + double ss = 0; + + // convert to seconds + if(pvalue[1]) + ss += ((double)pvalue[0] / (double)pvalue[1]) * 3600; + if(pvalue[3]) + ss += ((double)pvalue[2] / (double)pvalue[3]) * 60; + if(pvalue[5]) + ss += ((double)pvalue[4] / (double)pvalue[5]); + + // convert to dd:mm:ss.ss + dd = (int)(ss / 3600); + mm = (int)(ss / 60) - dd * 60; + ss = ss - dd * 3600 - mm * 60; + + sprintf(format, "%d:%d:%.2f", dd, mm, ss); + buffer += format; + return buffer.c_str(); + } + } + break; + + case TAG_GPS_VERSION_ID: + case TAG_GPS_LATITUDE_REF: + case TAG_GPS_LONGITUDE_REF: + case TAG_GPS_ALTITUDE_REF: + case TAG_GPS_ALTITUDE: + case TAG_GPS_SATELLITES: + case TAG_GPS_STATUS: + case TAG_GPS_MEASURE_MODE: + case TAG_GPS_DOP: + case TAG_GPS_SPEED_REF: + case TAG_GPS_SPEED: + case TAG_GPS_TRACK_REF: + case TAG_GPS_TRACK: + case TAG_GPS_IMG_DIRECTION_REF: + case TAG_GPS_IMG_DIRECTION: + case TAG_GPS_MAP_DATUM: + case TAG_GPS_DEST_LATITUDE_REF: + case TAG_GPS_DEST_LATITUDE: + case TAG_GPS_DEST_LONGITUDE_REF: + case TAG_GPS_DEST_LONGITUDE: + case TAG_GPS_DEST_BEARING_REF: + case TAG_GPS_DEST_BEARING: + case TAG_GPS_DEST_DISTANCE_REF: + case TAG_GPS_DEST_DISTANCE: + case TAG_GPS_PROCESSING_METHOD: + case TAG_GPS_AREA_INFORMATION: + case TAG_GPS_DATE_STAMP: + case TAG_GPS_DIFFERENTIAL: + break; + } + + return ConvertAnyTag(tag); +} + +// ========================================================== +// Tag to string conversion function +// + +const char* DLL_CALLCONV +FreeImage_TagToString(FREE_IMAGE_MDMODEL model, FITAG *tag, char *Make) { + switch(model) { + case FIMD_EXIF_MAIN: + case FIMD_EXIF_EXIF: + return ConvertExifTag(tag); + + case FIMD_EXIF_GPS: + return ConvertExifGPSTag(tag); + + case FIMD_EXIF_MAKERNOTE: + // We should use the Make string to select an appropriate conversion function + // TO DO ... + break; + + case FIMD_EXIF_INTEROP: + default: + break; + } + + return ConvertAnyTag(tag); +} + diff --git a/Source/Metadata/XTIFF.cpp b/Source/Metadata/XTIFF.cpp index e6f6bdd..94ccc48 100644 --- a/Source/Metadata/XTIFF.cpp +++ b/Source/Metadata/XTIFF.cpp @@ -1,665 +1,665 @@ -// ========================================================== -// Metadata functions implementation -// Extended TIFF Directory GEO Tag Support -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// - Thorsten Radde (support@IdealSoftware.com) -// - Berend Engelbrecht (softwarecave@users.sourceforge.net) -// - Mihail Naydenov (mnaydenov@users.sourceforge.net) -// -// Based on the LibTIFF xtiffio sample and on LibGeoTIFF -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#ifdef _MSC_VER -#pragma warning (disable : 4786) // identifier was truncated to 'number' characters -#endif - -#include "../LibTIFF4/tiffiop.h" - -#include "FreeImage.h" -#include "Utilities.h" -#include "FreeImageTag.h" -#include "FIRational.h" - -// ---------------------------------------------------------- -// Extended TIFF Directory GEO Tag Support -// ---------------------------------------------------------- - -/** - Tiff info structure. - Entry format: - { TAGNUMBER, ReadCount, WriteCount, DataType, FIELDNUM, OkToChange, PassDirCountOnSet, AsciiName } - - For ReadCount, WriteCount, -1 = unknown. -*/ -static const TIFFFieldInfo xtiffFieldInfo[] = { - { TIFFTAG_GEOPIXELSCALE, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoPixelScale" }, - { TIFFTAG_INTERGRAPH_MATRIX, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "Intergraph TransformationMatrix" }, - { TIFFTAG_GEOTRANSMATRIX, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoTransformationMatrix" }, - { TIFFTAG_GEOTIEPOINTS, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoTiePoints" }, - { TIFFTAG_GEOKEYDIRECTORY,-1,-1, TIFF_SHORT, FIELD_CUSTOM, TRUE, TRUE, "GeoKeyDirectory" }, - { TIFFTAG_GEODOUBLEPARAMS, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoDoubleParams" }, - { TIFFTAG_GEOASCIIPARAMS, -1, -1, TIFF_ASCII, FIELD_CUSTOM, TRUE, FALSE, "GeoASCIIParams" }, - { TIFFTAG_JPL_CARTO_IFD, 1, 1, TIFF_LONG, FIELD_CUSTOM, TRUE, TRUE, "JPL Carto IFD offset" } /** Don't use this! **/ -}; - -static void -_XTIFFLocalDefaultDirectory(TIFF *tif) { - int tag_size = sizeof(xtiffFieldInfo) / sizeof(xtiffFieldInfo[0]); - // Install the extended Tag field info - TIFFMergeFieldInfo(tif, xtiffFieldInfo, tag_size); -} - -static TIFFExtendProc _ParentExtender; - -/** -This is the callback procedure, and is -called by the DefaultDirectory method -every time a new TIFF directory is opened. -*/ -static void -_XTIFFDefaultDirectory(TIFF *tif) { - // set up our own defaults - _XTIFFLocalDefaultDirectory(tif); - - /* - Since an XTIFF client module may have overridden - the default directory method, we call it now to - allow it to set up the rest of its own methods. - */ - if (_ParentExtender) - (*_ParentExtender)(tif); -} - -/** -XTIFF Initializer -- sets up the callback procedure for the TIFF module -*/ -void -XTIFFInitialize(void) { - static int first_time = 1; - - if (! first_time) - return; /* Been there. Done that. */ - first_time = 0; - - // Grab the inherited method and install - _ParentExtender = TIFFSetTagExtender(_XTIFFDefaultDirectory); -} - -// ---------------------------------------------------------- -// GeoTIFF tag reading / writing -// ---------------------------------------------------------- - -void -tiff_read_geotiff_profile(TIFF *tif, FIBITMAP *dib) { - char defaultKey[16]; - - size_t tag_size = sizeof(xtiffFieldInfo) / sizeof(xtiffFieldInfo[0]); - - TagLib& tag_lib = TagLib::instance(); - - for(unsigned i = 0; i < tag_size; i++) { - - const TIFFFieldInfo *fieldInfo = &xtiffFieldInfo[i]; - - if(fieldInfo->field_type == TIFF_ASCII) { - char *params = NULL; - - if(TIFFGetField(tif, fieldInfo->field_tag, ¶ms)) { - // create a tag - FITAG *tag = FreeImage_CreateTag(); - if(!tag) - return; - - WORD tag_id = (WORD)fieldInfo->field_tag; - - FreeImage_SetTagType(tag, (FREE_IMAGE_MDTYPE)fieldInfo->field_type); - FreeImage_SetTagID(tag, tag_id); - FreeImage_SetTagKey(tag, tag_lib.getTagFieldName(TagLib::GEOTIFF, tag_id, defaultKey)); - FreeImage_SetTagDescription(tag, tag_lib.getTagDescription(TagLib::GEOTIFF, tag_id)); - FreeImage_SetTagLength(tag, (DWORD)strlen(params) + 1); - FreeImage_SetTagCount(tag, FreeImage_GetTagLength(tag)); - FreeImage_SetTagValue(tag, params); - FreeImage_SetMetadata(FIMD_GEOTIFF, dib, FreeImage_GetTagKey(tag), tag); - - // delete the tag - FreeImage_DeleteTag(tag); - } - } else { - short tag_count = 0; - void* data = NULL; - - if(TIFFGetField(tif, fieldInfo->field_tag, &tag_count, &data)) { - // create a tag - FITAG *tag = FreeImage_CreateTag(); - if(!tag) - return; - - WORD tag_id = (WORD)fieldInfo->field_tag; - FREE_IMAGE_MDTYPE tag_type = (FREE_IMAGE_MDTYPE)fieldInfo->field_type; - - FreeImage_SetTagType(tag, tag_type); - FreeImage_SetTagID(tag, tag_id); - FreeImage_SetTagKey(tag, tag_lib.getTagFieldName(TagLib::GEOTIFF, tag_id, defaultKey)); - FreeImage_SetTagDescription(tag, tag_lib.getTagDescription(TagLib::GEOTIFF, tag_id)); - FreeImage_SetTagLength(tag, FreeImage_TagDataWidth(tag_type) * tag_count); - FreeImage_SetTagCount(tag, tag_count); - FreeImage_SetTagValue(tag, data); - FreeImage_SetMetadata(FIMD_GEOTIFF, dib, FreeImage_GetTagKey(tag), tag); - - // delete the tag - FreeImage_DeleteTag(tag); - } - } - } // for(tag_size) -} - -void -tiff_write_geotiff_profile(TIFF *tif, FIBITMAP *dib) { - char defaultKey[16]; - - if(FreeImage_GetMetadataCount(FIMD_GEOTIFF, dib) == 0) { - return; - } - - size_t tag_size = sizeof(xtiffFieldInfo) / sizeof(xtiffFieldInfo[0]); - - TagLib& tag_lib = TagLib::instance(); - - for(unsigned i = 0; i < tag_size; i++) { - const TIFFFieldInfo *fieldInfo = &xtiffFieldInfo[i]; - - FITAG *tag = NULL; - const char *key = tag_lib.getTagFieldName(TagLib::GEOTIFF, (WORD)fieldInfo->field_tag, defaultKey); - - if(FreeImage_GetMetadata(FIMD_GEOTIFF, dib, key, &tag)) { - if(FreeImage_GetTagType(tag) == FIDT_ASCII) { - TIFFSetField(tif, fieldInfo->field_tag, FreeImage_GetTagValue(tag)); - } else { - TIFFSetField(tif, fieldInfo->field_tag, FreeImage_GetTagCount(tag), FreeImage_GetTagValue(tag)); - } - } - } -} - -// ---------------------------------------------------------- -// EXIF tag reading & writing -// ---------------------------------------------------------- - -/** -Read a single exif tag -*/ -static BOOL -tiff_read_exif_tag(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib, TagLib& tagLib, TIFFDirectory *td, uint32 tag) { - const TIFFField *fip; - uint32 value_count; - int mem_alloc = 0; - void *raw_data = NULL; - - if(tag == TIFFTAG_EXIFIFD) { - return TRUE; - } - - // get the tag key - use NULL to avoid reading GeoTIFF tags - const char *key = tagLib.getTagFieldName(md_model, (WORD)tag, NULL); - if(key == NULL) { - return TRUE; - } - - fip = TIFFFieldWithTag(tif, tag); - if(fip == NULL) { - return TRUE; - } - - if(fip->field_passcount) { //<- "passcount" means "returns count" - if (fip->field_readcount != TIFF_VARIABLE2) { //<- TIFF_VARIABLE2 means "uses LONG count" - - // assume TIFF_VARIABLE (uses SHORT count) - uint16 value_count16; - if(TIFFGetField(tif, tag, &value_count16, &raw_data) != 1) { - return TRUE; - } - value_count = value_count16; - } else { - if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1) { - return TRUE; - } - } - } else { - - // determine count - - if (fip->field_readcount == TIFF_VARIABLE || fip->field_readcount == TIFF_VARIABLE2) { - value_count = 1; - } else if (fip->field_readcount == TIFF_SPP) { - value_count = td->td_samplesperpixel; - } else { - value_count = fip->field_readcount; - } - - // access fields as pointers to data - // (### determining this is NOT robust... and hardly can be. It is implemented looking the _TIFFVGetField code) - - if(fip->field_tag == TIFFTAG_TRANSFERFUNCTION) { - // reading this tag cause a bug probably located somewhere inside libtiff - return TRUE; - } - - if ((fip->field_type == TIFF_ASCII - || fip->field_readcount == TIFF_VARIABLE - || fip->field_readcount == TIFF_VARIABLE2 - || fip->field_readcount == TIFF_SPP - || value_count > 1) - - && fip->field_tag != TIFFTAG_PAGENUMBER - && fip->field_tag != TIFFTAG_HALFTONEHINTS - && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING - && fip->field_tag != TIFFTAG_DOTRANGE - - && fip->field_tag != TIFFTAG_BITSPERSAMPLE //<- these two are tricky - - && fip->field_tag != TIFFTAG_COMPRESSION //<- they are defined as TIFF_VARIABLE but in reality return a single value - ) { - if(TIFFGetField(tif, tag, &raw_data) != 1) { - return TRUE; - } - } else { - - // access fields as values - - const int value_size = _TIFFDataSize(fip->field_type); - raw_data = _TIFFmalloc(value_size * value_count); - mem_alloc = 1; - int ok = FALSE; - - // ### if value_count > 1, tag is PAGENUMBER or HALFTONEHINTS or YCBCRSUBSAMPLING or DOTRANGE, - // all off which are value_count == 2 (see tif_dirinfo.c) - switch(value_count) - { - case 1: - ok = TIFFGetField(tif, tag, raw_data); - break; - case 2: - ok = TIFFGetField(tif, tag, raw_data, (BYTE*)(raw_data) + value_size*1); - break; -/* # we might need more in the future: - case 3: - ok = TIFFGetField(tif, tag, raw_data, (BYTE*)(raw_data) + value_size*1, (BYTE*)(raw_data) + value_size*2); - break; -*/ - default: - FreeImage_OutputMessageProc(FIF_TIFF, "Unimplemented variable number of parameters for Tiff Tag %s", fip->field_name); - break; - } - if(ok != 1) { - _TIFFfree(raw_data); - return TRUE; - } - } - } - - // build FreeImage tag from Tiff Tag data we collected - - FITAG *fitag = FreeImage_CreateTag(); - if(!fitag) { - if(mem_alloc) { - _TIFFfree(raw_data); - } - return FALSE; - } - - FreeImage_SetTagID(fitag, (WORD)tag); - FreeImage_SetTagKey(fitag, key); - - switch(fip->field_type) { - case TIFF_BYTE: - FreeImage_SetTagType(fitag, FIDT_BYTE); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_UNDEFINED: - FreeImage_SetTagType(fitag, FIDT_UNDEFINED); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_SBYTE: - FreeImage_SetTagType(fitag, FIDT_SBYTE); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_SHORT: - FreeImage_SetTagType(fitag, FIDT_SHORT); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_SSHORT: - FreeImage_SetTagType(fitag, FIDT_SSHORT); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_LONG: - FreeImage_SetTagType(fitag, FIDT_LONG); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_IFD: - FreeImage_SetTagType(fitag, FIDT_IFD); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_SLONG: - FreeImage_SetTagType(fitag, FIDT_SLONG); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_RATIONAL: { - // LibTIFF converts rational to floats : reconvert floats to rationals - DWORD *rvalue = (DWORD*)malloc(2 * value_count * sizeof(DWORD)); - for(uint32 i = 0; i < value_count; i++) { - float *fv = (float*)raw_data; - FIRational rational(fv[i]); - rvalue[2*i] = rational.getNumerator(); - rvalue[2*i+1] = rational.getDenominator(); - } - FreeImage_SetTagType(fitag, FIDT_RATIONAL); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, rvalue); - free(rvalue); - } - break; - - case TIFF_SRATIONAL: { - // LibTIFF converts rational to floats : reconvert floats to rationals - LONG *rvalue = (LONG*)malloc(2 * value_count * sizeof(LONG)); - for(uint32 i = 0; i < value_count; i++) { - float *fv = (float*)raw_data; - FIRational rational(fv[i]); - rvalue[2*i] = rational.getNumerator(); - rvalue[2*i+1] = rational.getDenominator(); - } - FreeImage_SetTagType(fitag, FIDT_RATIONAL); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, rvalue); - free(rvalue); - } - break; - - case TIFF_FLOAT: - FreeImage_SetTagType(fitag, FIDT_FLOAT); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_DOUBLE: - FreeImage_SetTagType(fitag, FIDT_DOUBLE); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_LONG8: // BigTIFF 64-bit unsigned integer - FreeImage_SetTagType(fitag, FIDT_LONG8); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_IFD8: // BigTIFF 64-bit unsigned integer (offset) - FreeImage_SetTagType(fitag, FIDT_IFD8); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - case TIFF_SLONG8: // BigTIFF 64-bit signed integer - FreeImage_SetTagType(fitag, FIDT_SLONG8); - FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); - FreeImage_SetTagCount(fitag, value_count); - FreeImage_SetTagValue(fitag, raw_data); - break; - - default: { - // remember that raw_data = _TIFFmalloc(value_size * value_count); - const int value_size = _TIFFDataSize(fip->field_type); - size_t length = value_size * value_count; - FreeImage_SetTagType(fitag, FIDT_ASCII); - FreeImage_SetTagLength(fitag, (DWORD)length); - FreeImage_SetTagCount(fitag, (DWORD)length); - FreeImage_SetTagValue(fitag, raw_data); - } - break; - } - - const char *description = tagLib.getTagDescription(md_model, (WORD)tag); - if(description) { - FreeImage_SetTagDescription(fitag, description); - } - // store the tag - FreeImage_SetMetadata(tagLib.getFreeImageModel(md_model), dib, FreeImage_GetTagKey(fitag), fitag); - - // destroy the tag - FreeImage_DeleteTag(fitag); - - if(mem_alloc) { - _TIFFfree(raw_data); - } - return TRUE; -} - -/** -Read all known exif tags -*/ -BOOL -tiff_read_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib) { - int i; - short count; - - TagLib& tagLib = TagLib::instance(); - - TIFFDirectory *td = &tif->tif_dir; - - count = (short) TIFFGetTagListCount(tif); - for(i = 0; i < count; i++) { - uint32 tag = TIFFGetTagListEntry(tif, i); - // read the tag - if (!tiff_read_exif_tag(tif, md_model, dib, tagLib, td, tag)) - return FALSE; - } - - // we want to know values of standard tags too!! - - // loop over all Core Directory Tags - // ### uses private data, but there is no other way - if(md_model == TagLib::EXIF_MAIN) { - - uint32 lastTag = 0; //<- used to prevent reading some tags twice (as stored in tif_fieldinfo) - - for (int fi = 0, nfi = (int)tif->tif_nfields; nfi > 0; nfi--, fi++) { - const TIFFField *fld = tif->tif_fields[fi]; - - if(fld->field_tag == lastTag) - continue; - - // test if tag value is set - // (lifted directly form LibTiff _TIFFWriteDirectory) - - if( fld->field_bit == FIELD_CUSTOM ) { - int ci, is_set = FALSE; - - for( ci = 0; ci < td->td_customValueCount; ci++ ) { - is_set |= (td->td_customValues[ci].info == fld); - } - - if( !is_set ) { - continue; - } - - } else if(!TIFFFieldSet(tif, fld->field_bit)) { - continue; - } - - // process *all* other tags (some will be ignored) - - tiff_read_exif_tag(tif, md_model, dib, tagLib, td, fld->field_tag); - - - lastTag = fld->field_tag; - } - - } - - return TRUE; - -} - - -/** -Skip tags that are already handled by the LibTIFF writing process -*/ -static BOOL -skip_write_field(TIFF* tif, uint32 tag) { - switch (tag) { - case TIFFTAG_SAMPLEFORMAT: - case TIFFTAG_IMAGEWIDTH: - case TIFFTAG_IMAGELENGTH: - case TIFFTAG_SAMPLESPERPIXEL: - case TIFFTAG_BITSPERSAMPLE: - case TIFFTAG_PHOTOMETRIC: - case TIFFTAG_PLANARCONFIG: - case TIFFTAG_ROWSPERSTRIP: - case TIFFTAG_STRIPBYTECOUNTS: - case TIFFTAG_STRIPOFFSETS: - case TIFFTAG_RESOLUTIONUNIT: - case TIFFTAG_XRESOLUTION: - case TIFFTAG_YRESOLUTION: - case TIFFTAG_SUBFILETYPE: - case TIFFTAG_PAGENUMBER: - case TIFFTAG_COLORMAP: - case TIFFTAG_ORIENTATION: - case TIFFTAG_COMPRESSION: - case TIFFTAG_PREDICTOR: - case TIFFTAG_GROUP3OPTIONS: - case TIFFTAG_FILLORDER: - // skip always, values have been set in SaveOneTIFF() - return TRUE; - break; - - case TIFFTAG_RICHTIFFIPTC: - // skip always, IPTC metadata model is set in tiff_write_iptc_profile() - return TRUE; - break; - - case TIFFTAG_YCBCRCOEFFICIENTS: - case TIFFTAG_REFERENCEBLACKWHITE: - case TIFFTAG_YCBCRSUBSAMPLING: - // skip as they cannot be filled yet - return TRUE; - break; - - case TIFFTAG_PAGENAME: - { - char *value = NULL; - TIFFGetField(tif, TIFFTAG_PAGENAME, &value); - // only skip if no value has been set - if(value == NULL) { - return FALSE; - } else { - return TRUE; - } - } - default: - return FALSE; - break; - } -} - -/** -Write all known exif tags -*/ -BOOL -tiff_write_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib) { - char defaultKey[16]; - - // only EXIF_MAIN so far - if(md_model != TagLib::EXIF_MAIN) { - return FALSE; - } - - if(FreeImage_GetMetadataCount(FIMD_EXIF_MAIN, dib) == 0) { - return FALSE; - } - - TagLib& tag_lib = TagLib::instance(); - - for (int fi = 0, nfi = (int)tif->tif_nfields; nfi > 0; nfi--, fi++) { - const TIFFField *fld = tif->tif_fields[fi]; - - if(skip_write_field(tif, fld->field_tag)) { - // skip tags that are already handled by the LibTIFF writing process - continue; - } - - FITAG *tag = NULL; - // get the tag key - const char *key = tag_lib.getTagFieldName(TagLib::EXIF_MAIN, (WORD)fld->field_tag, defaultKey); - - if(FreeImage_GetMetadata(FIMD_EXIF_MAIN, dib, key, &tag)) { - FREE_IMAGE_MDTYPE tag_type = FreeImage_GetTagType(tag); - TIFFDataType tif_tag_type = fld->field_type; - - // check for identical formats - - // (enum value are the sames between FREE_IMAGE_MDTYPE and TIFFDataType types) - if((int)tif_tag_type != (int)tag_type) { - // skip tag or _TIFFmemcpy will fail - continue; - } - // type of storage may differ (e.g. rationnal array vs float array type) - if(_TIFFDataSize(tif_tag_type) != FreeImage_TagDataWidth(tag_type)) { - // skip tag or _TIFFmemcpy will fail - continue; - } - - if(tag_type == FIDT_ASCII) { - TIFFSetField(tif, fld->field_tag, FreeImage_GetTagValue(tag)); - } else { - TIFFSetField(tif, fld->field_tag, FreeImage_GetTagCount(tag), FreeImage_GetTagValue(tag)); - } - } - } - - return TRUE; -} +// ========================================================== +// Metadata functions implementation +// Extended TIFF Directory GEO Tag Support +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// - Thorsten Radde (support@IdealSoftware.com) +// - Berend Engelbrecht (softwarecave@users.sourceforge.net) +// - Mihail Naydenov (mnaydenov@users.sourceforge.net) +// +// Based on the LibTIFF xtiffio sample and on LibGeoTIFF +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#ifdef _MSC_VER +#pragma warning (disable : 4786) // identifier was truncated to 'number' characters +#endif + +#include "../LibTIFF4/tiffiop.h" + +#include "FreeImage.h" +#include "Utilities.h" +#include "FreeImageTag.h" +#include "FIRational.h" + +// ---------------------------------------------------------- +// Extended TIFF Directory GEO Tag Support +// ---------------------------------------------------------- + +/** + Tiff info structure. + Entry format: + { TAGNUMBER, ReadCount, WriteCount, DataType, FIELDNUM, OkToChange, PassDirCountOnSet, AsciiName } + + For ReadCount, WriteCount, -1 = unknown. +*/ +static const TIFFFieldInfo xtiffFieldInfo[] = { + { TIFFTAG_GEOPIXELSCALE, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoPixelScale" }, + { TIFFTAG_INTERGRAPH_MATRIX, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "Intergraph TransformationMatrix" }, + { TIFFTAG_GEOTRANSMATRIX, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoTransformationMatrix" }, + { TIFFTAG_GEOTIEPOINTS, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoTiePoints" }, + { TIFFTAG_GEOKEYDIRECTORY,-1,-1, TIFF_SHORT, FIELD_CUSTOM, TRUE, TRUE, "GeoKeyDirectory" }, + { TIFFTAG_GEODOUBLEPARAMS, -1, -1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoDoubleParams" }, + { TIFFTAG_GEOASCIIPARAMS, -1, -1, TIFF_ASCII, FIELD_CUSTOM, TRUE, FALSE, "GeoASCIIParams" }, + { TIFFTAG_JPL_CARTO_IFD, 1, 1, TIFF_LONG, FIELD_CUSTOM, TRUE, TRUE, "JPL Carto IFD offset" } /** Don't use this! **/ +}; + +static void +_XTIFFLocalDefaultDirectory(TIFF *tif) { + int tag_size = sizeof(xtiffFieldInfo) / sizeof(xtiffFieldInfo[0]); + // Install the extended Tag field info + TIFFMergeFieldInfo(tif, xtiffFieldInfo, tag_size); +} + +static TIFFExtendProc _ParentExtender; + +/** +This is the callback procedure, and is +called by the DefaultDirectory method +every time a new TIFF directory is opened. +*/ +static void +_XTIFFDefaultDirectory(TIFF *tif) { + // set up our own defaults + _XTIFFLocalDefaultDirectory(tif); + + /* + Since an XTIFF client module may have overridden + the default directory method, we call it now to + allow it to set up the rest of its own methods. + */ + if (_ParentExtender) + (*_ParentExtender)(tif); +} + +/** +XTIFF Initializer -- sets up the callback procedure for the TIFF module +*/ +void +XTIFFInitialize(void) { + static int first_time = 1; + + if (! first_time) + return; /* Been there. Done that. */ + first_time = 0; + + // Grab the inherited method and install + _ParentExtender = TIFFSetTagExtender(_XTIFFDefaultDirectory); +} + +// ---------------------------------------------------------- +// GeoTIFF tag reading / writing +// ---------------------------------------------------------- + +void +tiff_read_geotiff_profile(TIFF *tif, FIBITMAP *dib) { + char defaultKey[16]; + + size_t tag_size = sizeof(xtiffFieldInfo) / sizeof(xtiffFieldInfo[0]); + + TagLib& tag_lib = TagLib::instance(); + + for(unsigned i = 0; i < tag_size; i++) { + + const TIFFFieldInfo *fieldInfo = &xtiffFieldInfo[i]; + + if(fieldInfo->field_type == TIFF_ASCII) { + char *params = NULL; + + if(TIFFGetField(tif, fieldInfo->field_tag, ¶ms)) { + // create a tag + FITAG *tag = FreeImage_CreateTag(); + if(!tag) + return; + + WORD tag_id = (WORD)fieldInfo->field_tag; + + FreeImage_SetTagType(tag, (FREE_IMAGE_MDTYPE)fieldInfo->field_type); + FreeImage_SetTagID(tag, tag_id); + FreeImage_SetTagKey(tag, tag_lib.getTagFieldName(TagLib::GEOTIFF, tag_id, defaultKey)); + FreeImage_SetTagDescription(tag, tag_lib.getTagDescription(TagLib::GEOTIFF, tag_id)); + FreeImage_SetTagLength(tag, (DWORD)strlen(params) + 1); + FreeImage_SetTagCount(tag, FreeImage_GetTagLength(tag)); + FreeImage_SetTagValue(tag, params); + FreeImage_SetMetadata(FIMD_GEOTIFF, dib, FreeImage_GetTagKey(tag), tag); + + // delete the tag + FreeImage_DeleteTag(tag); + } + } else { + short tag_count = 0; + void* data = NULL; + + if(TIFFGetField(tif, fieldInfo->field_tag, &tag_count, &data)) { + // create a tag + FITAG *tag = FreeImage_CreateTag(); + if(!tag) + return; + + WORD tag_id = (WORD)fieldInfo->field_tag; + FREE_IMAGE_MDTYPE tag_type = (FREE_IMAGE_MDTYPE)fieldInfo->field_type; + + FreeImage_SetTagType(tag, tag_type); + FreeImage_SetTagID(tag, tag_id); + FreeImage_SetTagKey(tag, tag_lib.getTagFieldName(TagLib::GEOTIFF, tag_id, defaultKey)); + FreeImage_SetTagDescription(tag, tag_lib.getTagDescription(TagLib::GEOTIFF, tag_id)); + FreeImage_SetTagLength(tag, FreeImage_TagDataWidth(tag_type) * tag_count); + FreeImage_SetTagCount(tag, tag_count); + FreeImage_SetTagValue(tag, data); + FreeImage_SetMetadata(FIMD_GEOTIFF, dib, FreeImage_GetTagKey(tag), tag); + + // delete the tag + FreeImage_DeleteTag(tag); + } + } + } // for(tag_size) +} + +void +tiff_write_geotiff_profile(TIFF *tif, FIBITMAP *dib) { + char defaultKey[16]; + + if(FreeImage_GetMetadataCount(FIMD_GEOTIFF, dib) == 0) { + return; + } + + size_t tag_size = sizeof(xtiffFieldInfo) / sizeof(xtiffFieldInfo[0]); + + TagLib& tag_lib = TagLib::instance(); + + for(unsigned i = 0; i < tag_size; i++) { + const TIFFFieldInfo *fieldInfo = &xtiffFieldInfo[i]; + + FITAG *tag = NULL; + const char *key = tag_lib.getTagFieldName(TagLib::GEOTIFF, (WORD)fieldInfo->field_tag, defaultKey); + + if(FreeImage_GetMetadata(FIMD_GEOTIFF, dib, key, &tag)) { + if(FreeImage_GetTagType(tag) == FIDT_ASCII) { + TIFFSetField(tif, fieldInfo->field_tag, FreeImage_GetTagValue(tag)); + } else { + TIFFSetField(tif, fieldInfo->field_tag, FreeImage_GetTagCount(tag), FreeImage_GetTagValue(tag)); + } + } + } +} + +// ---------------------------------------------------------- +// EXIF tag reading & writing +// ---------------------------------------------------------- + +/** +Read a single exif tag +*/ +static BOOL +tiff_read_exif_tag(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib, TagLib& tagLib, TIFFDirectory *td, uint32 tag) { + const TIFFField *fip; + uint32 value_count; + int mem_alloc = 0; + void *raw_data = NULL; + + if(tag == TIFFTAG_EXIFIFD) { + return TRUE; + } + + // get the tag key - use NULL to avoid reading GeoTIFF tags + const char *key = tagLib.getTagFieldName(md_model, (WORD)tag, NULL); + if(key == NULL) { + return TRUE; + } + + fip = TIFFFieldWithTag(tif, tag); + if(fip == NULL) { + return TRUE; + } + + if(fip->field_passcount) { //<- "passcount" means "returns count" + if (fip->field_readcount != TIFF_VARIABLE2) { //<- TIFF_VARIABLE2 means "uses LONG count" + + // assume TIFF_VARIABLE (uses SHORT count) + uint16 value_count16; + if(TIFFGetField(tif, tag, &value_count16, &raw_data) != 1) { + return TRUE; + } + value_count = value_count16; + } else { + if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1) { + return TRUE; + } + } + } else { + + // determine count + + if (fip->field_readcount == TIFF_VARIABLE || fip->field_readcount == TIFF_VARIABLE2) { + value_count = 1; + } else if (fip->field_readcount == TIFF_SPP) { + value_count = td->td_samplesperpixel; + } else { + value_count = fip->field_readcount; + } + + // access fields as pointers to data + // (### determining this is NOT robust... and hardly can be. It is implemented looking the _TIFFVGetField code) + + if(fip->field_tag == TIFFTAG_TRANSFERFUNCTION) { + // reading this tag cause a bug probably located somewhere inside libtiff + return TRUE; + } + + if ((fip->field_type == TIFF_ASCII + || fip->field_readcount == TIFF_VARIABLE + || fip->field_readcount == TIFF_VARIABLE2 + || fip->field_readcount == TIFF_SPP + || value_count > 1) + + && fip->field_tag != TIFFTAG_PAGENUMBER + && fip->field_tag != TIFFTAG_HALFTONEHINTS + && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING + && fip->field_tag != TIFFTAG_DOTRANGE + + && fip->field_tag != TIFFTAG_BITSPERSAMPLE //<- these two are tricky - + && fip->field_tag != TIFFTAG_COMPRESSION //<- they are defined as TIFF_VARIABLE but in reality return a single value + ) { + if(TIFFGetField(tif, tag, &raw_data) != 1) { + return TRUE; + } + } else { + + // access fields as values + + const int value_size = _TIFFDataSize(fip->field_type); + raw_data = _TIFFmalloc(value_size * value_count); + mem_alloc = 1; + int ok = FALSE; + + // ### if value_count > 1, tag is PAGENUMBER or HALFTONEHINTS or YCBCRSUBSAMPLING or DOTRANGE, + // all off which are value_count == 2 (see tif_dirinfo.c) + switch(value_count) + { + case 1: + ok = TIFFGetField(tif, tag, raw_data); + break; + case 2: + ok = TIFFGetField(tif, tag, raw_data, (BYTE*)(raw_data) + value_size*1); + break; +/* # we might need more in the future: + case 3: + ok = TIFFGetField(tif, tag, raw_data, (BYTE*)(raw_data) + value_size*1, (BYTE*)(raw_data) + value_size*2); + break; +*/ + default: + FreeImage_OutputMessageProc(FIF_TIFF, "Unimplemented variable number of parameters for Tiff Tag %s", fip->field_name); + break; + } + if(ok != 1) { + _TIFFfree(raw_data); + return TRUE; + } + } + } + + // build FreeImage tag from Tiff Tag data we collected + + FITAG *fitag = FreeImage_CreateTag(); + if(!fitag) { + if(mem_alloc) { + _TIFFfree(raw_data); + } + return FALSE; + } + + FreeImage_SetTagID(fitag, (WORD)tag); + FreeImage_SetTagKey(fitag, key); + + switch(fip->field_type) { + case TIFF_BYTE: + FreeImage_SetTagType(fitag, FIDT_BYTE); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_UNDEFINED: + FreeImage_SetTagType(fitag, FIDT_UNDEFINED); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_SBYTE: + FreeImage_SetTagType(fitag, FIDT_SBYTE); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_SHORT: + FreeImage_SetTagType(fitag, FIDT_SHORT); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_SSHORT: + FreeImage_SetTagType(fitag, FIDT_SSHORT); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_LONG: + FreeImage_SetTagType(fitag, FIDT_LONG); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_IFD: + FreeImage_SetTagType(fitag, FIDT_IFD); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_SLONG: + FreeImage_SetTagType(fitag, FIDT_SLONG); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_RATIONAL: { + // LibTIFF converts rational to floats : reconvert floats to rationals + DWORD *rvalue = (DWORD*)malloc(2 * value_count * sizeof(DWORD)); + for(uint32 i = 0; i < value_count; i++) { + float *fv = (float*)raw_data; + FIRational rational(fv[i]); + rvalue[2*i] = rational.getNumerator(); + rvalue[2*i+1] = rational.getDenominator(); + } + FreeImage_SetTagType(fitag, FIDT_RATIONAL); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, rvalue); + free(rvalue); + } + break; + + case TIFF_SRATIONAL: { + // LibTIFF converts rational to floats : reconvert floats to rationals + LONG *rvalue = (LONG*)malloc(2 * value_count * sizeof(LONG)); + for(uint32 i = 0; i < value_count; i++) { + float *fv = (float*)raw_data; + FIRational rational(fv[i]); + rvalue[2*i] = rational.getNumerator(); + rvalue[2*i+1] = rational.getDenominator(); + } + FreeImage_SetTagType(fitag, FIDT_RATIONAL); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, rvalue); + free(rvalue); + } + break; + + case TIFF_FLOAT: + FreeImage_SetTagType(fitag, FIDT_FLOAT); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_DOUBLE: + FreeImage_SetTagType(fitag, FIDT_DOUBLE); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_LONG8: // BigTIFF 64-bit unsigned integer + FreeImage_SetTagType(fitag, FIDT_LONG8); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_IFD8: // BigTIFF 64-bit unsigned integer (offset) + FreeImage_SetTagType(fitag, FIDT_IFD8); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + case TIFF_SLONG8: // BigTIFF 64-bit signed integer + FreeImage_SetTagType(fitag, FIDT_SLONG8); + FreeImage_SetTagLength(fitag, TIFFDataWidth(fip->field_type) * value_count); + FreeImage_SetTagCount(fitag, value_count); + FreeImage_SetTagValue(fitag, raw_data); + break; + + default: { + // remember that raw_data = _TIFFmalloc(value_size * value_count); + const int value_size = _TIFFDataSize(fip->field_type); + size_t length = value_size * value_count; + FreeImage_SetTagType(fitag, FIDT_ASCII); + FreeImage_SetTagLength(fitag, (DWORD)length); + FreeImage_SetTagCount(fitag, (DWORD)length); + FreeImage_SetTagValue(fitag, raw_data); + } + break; + } + + const char *description = tagLib.getTagDescription(md_model, (WORD)tag); + if(description) { + FreeImage_SetTagDescription(fitag, description); + } + // store the tag + FreeImage_SetMetadata(tagLib.getFreeImageModel(md_model), dib, FreeImage_GetTagKey(fitag), fitag); + + // destroy the tag + FreeImage_DeleteTag(fitag); + + if(mem_alloc) { + _TIFFfree(raw_data); + } + return TRUE; +} + +/** +Read all known exif tags +*/ +BOOL +tiff_read_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib) { + int i; + short count; + + TagLib& tagLib = TagLib::instance(); + + TIFFDirectory *td = &tif->tif_dir; + + count = (short) TIFFGetTagListCount(tif); + for(i = 0; i < count; i++) { + uint32 tag = TIFFGetTagListEntry(tif, i); + // read the tag + if (!tiff_read_exif_tag(tif, md_model, dib, tagLib, td, tag)) + return FALSE; + } + + // we want to know values of standard tags too!! + + // loop over all Core Directory Tags + // ### uses private data, but there is no other way + if(md_model == TagLib::EXIF_MAIN) { + + uint32 lastTag = 0; //<- used to prevent reading some tags twice (as stored in tif_fieldinfo) + + for (int fi = 0, nfi = (int)tif->tif_nfields; nfi > 0; nfi--, fi++) { + const TIFFField *fld = tif->tif_fields[fi]; + + if(fld->field_tag == lastTag) + continue; + + // test if tag value is set + // (lifted directly form LibTiff _TIFFWriteDirectory) + + if( fld->field_bit == FIELD_CUSTOM ) { + int ci, is_set = FALSE; + + for( ci = 0; ci < td->td_customValueCount; ci++ ) { + is_set |= (td->td_customValues[ci].info == fld); + } + + if( !is_set ) { + continue; + } + + } else if(!TIFFFieldSet(tif, fld->field_bit)) { + continue; + } + + // process *all* other tags (some will be ignored) + + tiff_read_exif_tag(tif, md_model, dib, tagLib, td, fld->field_tag); + + + lastTag = fld->field_tag; + } + + } + + return TRUE; + +} + + +/** +Skip tags that are already handled by the LibTIFF writing process +*/ +static BOOL +skip_write_field(TIFF* tif, uint32 tag) { + switch (tag) { + case TIFFTAG_SAMPLEFORMAT: + case TIFFTAG_IMAGEWIDTH: + case TIFFTAG_IMAGELENGTH: + case TIFFTAG_SAMPLESPERPIXEL: + case TIFFTAG_BITSPERSAMPLE: + case TIFFTAG_PHOTOMETRIC: + case TIFFTAG_PLANARCONFIG: + case TIFFTAG_ROWSPERSTRIP: + case TIFFTAG_STRIPBYTECOUNTS: + case TIFFTAG_STRIPOFFSETS: + case TIFFTAG_RESOLUTIONUNIT: + case TIFFTAG_XRESOLUTION: + case TIFFTAG_YRESOLUTION: + case TIFFTAG_SUBFILETYPE: + case TIFFTAG_PAGENUMBER: + case TIFFTAG_COLORMAP: + case TIFFTAG_ORIENTATION: + case TIFFTAG_COMPRESSION: + case TIFFTAG_PREDICTOR: + case TIFFTAG_GROUP3OPTIONS: + case TIFFTAG_FILLORDER: + // skip always, values have been set in SaveOneTIFF() + return TRUE; + break; + + case TIFFTAG_RICHTIFFIPTC: + // skip always, IPTC metadata model is set in tiff_write_iptc_profile() + return TRUE; + break; + + case TIFFTAG_YCBCRCOEFFICIENTS: + case TIFFTAG_REFERENCEBLACKWHITE: + case TIFFTAG_YCBCRSUBSAMPLING: + // skip as they cannot be filled yet + return TRUE; + break; + + case TIFFTAG_PAGENAME: + { + char *value = NULL; + TIFFGetField(tif, TIFFTAG_PAGENAME, &value); + // only skip if no value has been set + if(value == NULL) { + return FALSE; + } else { + return TRUE; + } + } + default: + return FALSE; + break; + } +} + +/** +Write all known exif tags +*/ +BOOL +tiff_write_exif_tags(TIFF *tif, TagLib::MDMODEL md_model, FIBITMAP *dib) { + char defaultKey[16]; + + // only EXIF_MAIN so far + if(md_model != TagLib::EXIF_MAIN) { + return FALSE; + } + + if(FreeImage_GetMetadataCount(FIMD_EXIF_MAIN, dib) == 0) { + return FALSE; + } + + TagLib& tag_lib = TagLib::instance(); + + for (int fi = 0, nfi = (int)tif->tif_nfields; nfi > 0; nfi--, fi++) { + const TIFFField *fld = tif->tif_fields[fi]; + + if(skip_write_field(tif, fld->field_tag)) { + // skip tags that are already handled by the LibTIFF writing process + continue; + } + + FITAG *tag = NULL; + // get the tag key + const char *key = tag_lib.getTagFieldName(TagLib::EXIF_MAIN, (WORD)fld->field_tag, defaultKey); + + if(FreeImage_GetMetadata(FIMD_EXIF_MAIN, dib, key, &tag)) { + FREE_IMAGE_MDTYPE tag_type = FreeImage_GetTagType(tag); + TIFFDataType tif_tag_type = fld->field_type; + + // check for identical formats + + // (enum value are the sames between FREE_IMAGE_MDTYPE and TIFFDataType types) + if((int)tif_tag_type != (int)tag_type) { + // skip tag or _TIFFmemcpy will fail + continue; + } + // type of storage may differ (e.g. rationnal array vs float array type) + if(_TIFFDataSize(tif_tag_type) != FreeImage_TagDataWidth(tag_type)) { + // skip tag or _TIFFmemcpy will fail + continue; + } + + if(tag_type == FIDT_ASCII) { + TIFFSetField(tif, fld->field_tag, FreeImage_GetTagValue(tag)); + } else { + TIFFSetField(tif, fld->field_tag, FreeImage_GetTagCount(tag), FreeImage_GetTagValue(tag)); + } + } + } + + return TRUE; +} diff --git a/Source/OpenEXR/Copyrights/ilmbase/README.win32 b/Source/OpenEXR/Copyrights/ilmbase/README.win32 index 0e4b3ca..e428f2d 100644 --- a/Source/OpenEXR/Copyrights/ilmbase/README.win32 +++ b/Source/OpenEXR/Copyrights/ilmbase/README.win32 @@ -1,196 +1,196 @@ -IlmBase is one of five software packages that were designed to work -together: IlmBase, OpenEXR, OpenEXR_Viewers, CTL and OpenEXR_CTL. -You may want to build Imath by itself, or together with one or more -of the other packages. - -What follows are instructions for building all five packages. -If you want to build only IlmBase, stop after step 1. - -A couple of notes before getting started: - -- This is not the only way to do this. This document describes a path -that doesn't involve installing libraries into default system paths, -but rather, creates a standalone universe. -- Some of these steps may be a bit redundant, and will be optimized in -the future. -- The Debug versions of the libraries and tools are not required if -you are not going to be doing any debugging, and can be optionally -built. - -The source will build under both Visual Studio versions 7 and 8, and -there are separate directories for the corresponding build files. The -tag is used in this document to describe the appropriate folder -in the path that corresponds to your the version of Visual Studio. - -The Visual Studio project files assume, and help build out, a directory -called "Deploy". In the end, this directory will contain the objects -that might then be moved away from the source for general running of the -compiled programs. The directory structure at the end of compiling all -the related tools looks like this: - -Deploy - include - lib - Debug - Release - bin - Debug - Release -openexr-cvs (name as desired) - IlmBase - OpenEXR - OpenEXR_Viewers -ctl-cvs (name as desired) - CTL - OpenEXR_CTL -fltk - FL - GL - lib -nvidia - include - GL - glh - lib - -If OpenEXR_Viewers is not being compiled, then fltk and nvidia will -not be needed, but that will be covered later. - -Step 1. Compile IlmBase - - a. Point Visual Studio at the .sln file in vc\\IlmBase in the - IlmBase subdirectory - - b. Select the Release configuration and hit Build Solution. This - will create the Deploy directory, and copy the relevant parts to it. - - c. If the debug versions are desired, select the Debug configuration - and hit Build Solution. This will add the Debug directories to Deploy. - -Step 2. Compile OpenEXR support - - a. Retrieve the zlib binaries. The project files are set up to link - against the dll version of zlib, but can easily be changed to link - against a static version, or a self-built version if desired. - - 1. Go to http://www.zlib.net and download the precompiled DLL - version of zlib (as of writing, zlib123-dll.zip) - - 2. If you don't wish to put the files into your MS visual studio - directories and install the dll into windows\system32: - - a. Put a copy of zlib1.dll into Deploy\bin\Release and - Deploy\bin\Debug - - b. Copy the header files into Deploy\include - - c. Copy zdll.lib and zdll.exp into Deploy\lib\Release and - Deploy\lib\Debug - - b. Open the Visual Studio project in OpenEXR\vc\\OpenEXR. - - c. Select the Release configuration and build. The IlmImfTest - program runs a confidence test of your build to make sure - it is able to work, and may take some time to complete. - - d. Optionally select the Debug configuration and build. - -Step 3. Compile CTL support - - a. Open the Visual Studio project in CTL\vc\\CTL. - - b. Select the Release configuration and build. The IlmCtlTest - program runs a confidence test of your build to make sure it is - able to work, and may take some time to complete. - - c. Optionally select the Debug configuration and build. - -Step 4. Compile OpenEXR_CTL support - - a. Open the Visual Studio project in OpenEXR_CTL\vc\\OpenEXR_CTL. - - b. Select the Release configuration and build. - - c. Optionally select the Debug configuration and build. - -Step 5. Compile OpenEXR_Viewers - - a. Open the appropriate Visual Studio project in - OpenEXR_Viewers\vc\\OpenEXR_Viewers depending on whether or not - you want CTL support. - - b. exrdisplay requires fltk to work. - - 1. Go to http://www.fltk.org and download fltk 1.1.7 - - 2. Open its project files and compile using the instructions they - provide. - - 3. Create the fltk directory at the top level of your directory - structure as presented above and copy the FL, GL, and lib folders - into the fltk directory - - 4. exrdisplay links fltk statically, so no dll is needed. - - c. playexr requires the nvidia cg library as well as glut and glew. - - 1. Setup the cg toolkit - - a. Go to http://developer.nvidia.com, the developer section and - download the cg toolkit, version 1.5, and install it. The path - where you choose to install Cg is referred to by the - tag in the steps below. - - b. During the installation, if the integrate with visual studio - option is selected, the header files will be automatically found. - Otherwise, copy the directory \Cg\include\Cg - to Deploy\include\Cg - - b. Copy the cg.dll and cgGL.dll from the \Cg\bin - into Deploy\bin\Release and Deploy\bin\Debug, or otherwise make - them available (put them in system32, add to path, etc.) - - c. Copy the cg.lib and cgGL.lib from \Cg\lib - into Deploy\lib\Release and Deploy\lib\Debug - - 2. Make glut available. This can be done via several mechanisms. - See step 4 below. - - 3. Make glew available. This can be done via several mechanisms. - http://glew.sourceforge.net is the master site for this - library. See step 4 below. - - 4. nVidia makes both glut and glew available in their SDK package, - which is a fairly large download, but provides a wealth of other - information on programming for the GPU, and is generally a useful - package, so that is the path chosen for this set up. - - a. Go to http://developer.nvidia.com and download version 10 of the - SDK and install it. It will prompt you to install the Cg toolkit, - but this is not necessary as it was handled in step 1. The path - where you choose to install the SDK is referred to by the - tag in the steps below. - - b. Make an nvidia folder at the top level, with an include and - lib folder inside it. Inside the lib folder, make Debug and - Release folders. - - c. Copy the \external\include\GL directory into - nvidia\include the GL and glh folders into nvidia\include. - - d. Copy the glew headers in \common\GLEW\include\GL - into nvidia\include\GL. - - e. Copy \common\GLEW\lib\glew32.lib and - \external\lib\glut32.lib into Deploy\bin\Release. - - f. Copy bin\glut32.dll and bin\glew32.dll into Deploy\bin\Release. - - d. Build the Release configuration of the OpenEXR_Viewers. - - e. Build the Debug configuration if desired. - -At this point, the Deploy folder should be fully built out and ready -to be used. Both exrdisplay and playexr are meant to be launched from -the command line, as they originated as unix commands, so open a command -prompt, cd to the Deploy\bin\Release folder and enjoy. +IlmBase is one of five software packages that were designed to work +together: IlmBase, OpenEXR, OpenEXR_Viewers, CTL and OpenEXR_CTL. +You may want to build Imath by itself, or together with one or more +of the other packages. + +What follows are instructions for building all five packages. +If you want to build only IlmBase, stop after step 1. + +A couple of notes before getting started: + +- This is not the only way to do this. This document describes a path +that doesn't involve installing libraries into default system paths, +but rather, creates a standalone universe. +- Some of these steps may be a bit redundant, and will be optimized in +the future. +- The Debug versions of the libraries and tools are not required if +you are not going to be doing any debugging, and can be optionally +built. + +The source will build under both Visual Studio versions 7 and 8, and +there are separate directories for the corresponding build files. The +tag is used in this document to describe the appropriate folder +in the path that corresponds to your the version of Visual Studio. + +The Visual Studio project files assume, and help build out, a directory +called "Deploy". In the end, this directory will contain the objects +that might then be moved away from the source for general running of the +compiled programs. The directory structure at the end of compiling all +the related tools looks like this: + +Deploy + include + lib + Debug + Release + bin + Debug + Release +openexr-cvs (name as desired) + IlmBase + OpenEXR + OpenEXR_Viewers +ctl-cvs (name as desired) + CTL + OpenEXR_CTL +fltk + FL + GL + lib +nvidia + include + GL + glh + lib + +If OpenEXR_Viewers is not being compiled, then fltk and nvidia will +not be needed, but that will be covered later. + +Step 1. Compile IlmBase + + a. Point Visual Studio at the .sln file in vc\\IlmBase in the + IlmBase subdirectory + + b. Select the Release configuration and hit Build Solution. This + will create the Deploy directory, and copy the relevant parts to it. + + c. If the debug versions are desired, select the Debug configuration + and hit Build Solution. This will add the Debug directories to Deploy. + +Step 2. Compile OpenEXR support + + a. Retrieve the zlib binaries. The project files are set up to link + against the dll version of zlib, but can easily be changed to link + against a static version, or a self-built version if desired. + + 1. Go to http://www.zlib.net and download the precompiled DLL + version of zlib (as of writing, zlib123-dll.zip) + + 2. If you don't wish to put the files into your MS visual studio + directories and install the dll into windows\system32: + + a. Put a copy of zlib1.dll into Deploy\bin\Release and + Deploy\bin\Debug + + b. Copy the header files into Deploy\include + + c. Copy zdll.lib and zdll.exp into Deploy\lib\Release and + Deploy\lib\Debug + + b. Open the Visual Studio project in OpenEXR\vc\\OpenEXR. + + c. Select the Release configuration and build. The IlmImfTest + program runs a confidence test of your build to make sure + it is able to work, and may take some time to complete. + + d. Optionally select the Debug configuration and build. + +Step 3. Compile CTL support + + a. Open the Visual Studio project in CTL\vc\\CTL. + + b. Select the Release configuration and build. The IlmCtlTest + program runs a confidence test of your build to make sure it is + able to work, and may take some time to complete. + + c. Optionally select the Debug configuration and build. + +Step 4. Compile OpenEXR_CTL support + + a. Open the Visual Studio project in OpenEXR_CTL\vc\\OpenEXR_CTL. + + b. Select the Release configuration and build. + + c. Optionally select the Debug configuration and build. + +Step 5. Compile OpenEXR_Viewers + + a. Open the appropriate Visual Studio project in + OpenEXR_Viewers\vc\\OpenEXR_Viewers depending on whether or not + you want CTL support. + + b. exrdisplay requires fltk to work. + + 1. Go to http://www.fltk.org and download fltk 1.1.7 + + 2. Open its project files and compile using the instructions they + provide. + + 3. Create the fltk directory at the top level of your directory + structure as presented above and copy the FL, GL, and lib folders + into the fltk directory + + 4. exrdisplay links fltk statically, so no dll is needed. + + c. playexr requires the nvidia cg library as well as glut and glew. + + 1. Setup the cg toolkit + + a. Go to http://developer.nvidia.com, the developer section and + download the cg toolkit, version 1.5, and install it. The path + where you choose to install Cg is referred to by the + tag in the steps below. + + b. During the installation, if the integrate with visual studio + option is selected, the header files will be automatically found. + Otherwise, copy the directory \Cg\include\Cg + to Deploy\include\Cg + + b. Copy the cg.dll and cgGL.dll from the \Cg\bin + into Deploy\bin\Release and Deploy\bin\Debug, or otherwise make + them available (put them in system32, add to path, etc.) + + c. Copy the cg.lib and cgGL.lib from \Cg\lib + into Deploy\lib\Release and Deploy\lib\Debug + + 2. Make glut available. This can be done via several mechanisms. + See step 4 below. + + 3. Make glew available. This can be done via several mechanisms. + http://glew.sourceforge.net is the master site for this + library. See step 4 below. + + 4. nVidia makes both glut and glew available in their SDK package, + which is a fairly large download, but provides a wealth of other + information on programming for the GPU, and is generally a useful + package, so that is the path chosen for this set up. + + a. Go to http://developer.nvidia.com and download version 10 of the + SDK and install it. It will prompt you to install the Cg toolkit, + but this is not necessary as it was handled in step 1. The path + where you choose to install the SDK is referred to by the + tag in the steps below. + + b. Make an nvidia folder at the top level, with an include and + lib folder inside it. Inside the lib folder, make Debug and + Release folders. + + c. Copy the \external\include\GL directory into + nvidia\include the GL and glh folders into nvidia\include. + + d. Copy the glew headers in \common\GLEW\include\GL + into nvidia\include\GL. + + e. Copy \common\GLEW\lib\glew32.lib and + \external\lib\glut32.lib into Deploy\bin\Release. + + f. Copy bin\glut32.dll and bin\glew32.dll into Deploy\bin\Release. + + d. Build the Release configuration of the OpenEXR_Viewers. + + e. Build the Debug configuration if desired. + +At this point, the Deploy folder should be fully built out and ready +to be used. Both exrdisplay and playexr are meant to be launched from +the command line, as they originated as unix commands, so open a command +prompt, cd to the Deploy\bin\Release folder and enjoy. diff --git a/Source/OpenEXR/Copyrights/openexr/README.win32 b/Source/OpenEXR/Copyrights/openexr/README.win32 index 060908d..0f7a884 100644 --- a/Source/OpenEXR/Copyrights/openexr/README.win32 +++ b/Source/OpenEXR/Copyrights/openexr/README.win32 @@ -1,197 +1,197 @@ -OpenEXR is one of six software packages that were designed to work -together: IlmBase, PyIlmBase, OpenEXR, OpenEXR_Viewers, CTL and -OpenEXR_CTL. You may only be interested in OpenEXR or you may want -to build it together wth the other packages. - -What follows are instructions for building all five packages. -If you are only interested in OpenEXR, stop after step 2. - -A couple of notes before getting started: - -- This is not the only way to do this. This document describes a path -that doesn't involve installing libraries into default system paths, -but rather, creates a standalone universe. -- Some of these steps may be a bit redundant, and will be optimized in -the future. -- The Debug versions of the libraries and tools are not required if -you are not going to be doing any debugging, and can be optionally -built. - -The source will build under both Visual Studio versions 7 and 8, and -there are separate directories for the corresponding build files. The -tag is used in this document to describe the appropriate folder -in the path that corresponds to your the version of Visual Studio. - -The Visual Studio project files assume, and help build out, a directory -called "Deploy". In the end, this directory will contain the objects -that might then be moved away from the source for general running of the -compiled programs. The directory structure at the end of compiling all -the related tools looks like this: - -Deploy - include - lib - Debug - Release - bin - Debug - Release -openexr-cvs (name as desired) - IlmBase - PyIlmBase - OpenEXR - OpenEXR_Viewers -ctl-cvs (name as desired) - CTL - OpenEXR_CTL -fltk - FL - GL - lib -nvidia - include - GL - glh - lib - -If OpenEXR_Viewers is not being compiled, then fltk and nvidia will -not be needed, but that will be covered later. - -Step 1. Compile IlmBase - - a. Point Visual Studio at the .sln file in vc\\IlmBase in the - IlmBase subdirectory - - b. Select the Release configuration and hit Build Solution. This - will create the Deploy directory, and copy the relevant parts to it. - - c. If the debug versions are desired, select the Debug configuration - and hit Build Solution. This will add the Debug directories to Deploy. - -Step 2. Compile OpenEXR support - - a. Retrieve the zlib binaries. The project files are set up to link - against the dll version of zlib, but can easily be changed to link - against a static version, or a self-built version if desired. - - 1. Go to http://www.zlib.net and download the precompiled DLL - version of zlib (as of writing, zlib123-dll.zip) - - 2. If you don't wish to put the files into your MS visual studio - directories and install the dll into windows\system32: - - a. Put a copy of zlib1.dll into Deploy\bin\Release and - Deploy\bin\Debug - - b. Copy the header files into Deploy\include - - c. Copy zdll.lib and zdll.exp into Deploy\lib\Release and - Deploy\lib\Debug - - b. Open the Visual Studio project in OpenEXR\vc\\OpenEXR. - - c. Select the Release configuration and build. The IlmImfTest - program runs a confidence test of your build to make sure - it is able to work, and may take some time to complete. - - d. Optionally select the Debug configuration and build. - -Step 3. Compile CTL support - - a. Open the Visual Studio project in CTL\vc\\CTL. - - b. Select the Release configuration and build. The IlmCtlTest - program runs a confidence test of your build to make sure it is - able to work, and may take some time to complete. - - c. Optionally select the Debug configuration and build. - -Step 4. Compile OpenEXR_CTL support - - a. Open the Visual Studio project in OpenEXR_CTL\vc\\OpenEXR_CTL. - - b. Select the Release configuration and build. - - c. Optionally select the Debug configuration and build. - -Step 5. Compile OpenEXR_Viewers - - a. Open the appropriate Visual Studio project in - OpenEXR_Viewers\vc\\OpenEXR_Viewers depending on whether or not - you want CTL support. - - b. exrdisplay requires fltk to work. - - 1. Go to http://www.fltk.org and download fltk 1.1.7 - - 2. Open its project files and compile using the instructions they - provide. - - 3. Create the fltk directory at the top level of your directory - structure as presented above and copy the FL, GL, and lib folders - into the fltk directory - - 4. exrdisplay links fltk statically, so no dll is needed. - - c. playexr requires the nvidia cg library as well as glut and glew. - - 1. Setup the cg toolkit - - a. Go to http://developer.nvidia.com, the developer section and - download the cg toolkit, version 1.5, and install it. The path - where you choose to install Cg is referred to by the - tag in the steps below. - - b. During the installation, if the integrate with visual studio - option is selected, the header files will be automatically found. - Otherwise, copy the directory \Cg\include\Cg - to Deploy\include\Cg - - b. Copy the cg.dll and cgGL.dll from the \Cg\bin - into Deploy\bin\Release and Deploy\bin\Debug, or otherwise make - them available (put them in system32, add to path, etc.) - - c. Copy the cg.lib and cgGL.lib from \Cg\lib - into Deploy\lib\Release and Deploy\lib\Debug - - 2. Make glut available. This can be done via several mechanisms. - See step 4 below. - - 3. Make glew available. This can be done via several mechanisms. - http://glew.sourceforge.net is the master site for this - library. See step 4 below. - - 4. nVidia makes both glut and glew available in their SDK package, - which is a fairly large download, but provides a wealth of other - information on programming for the GPU, and is generally a useful - package, so that is the path chosen for this set up. - - a. Go to http://developer.nvidia.com and download version 10 of the - SDK and install it. It will prompt you to install the Cg toolkit, - but this is not necessary as it was handled in step 1. The path - where you choose to install the SDK is referred to by the - tag in the steps below. - - b. Make an nvidia folder at the top level, with an include and - lib folder inside it. Inside the lib folder, make Debug and - Release folders. - - c. Copy the \external\include\GL directory into - nvidia\include the GL and glh folders into nvidia\include. - - d. Copy the glew headers in \common\GLEW\include\GL - into nvidia\include\GL. - - e. Copy \common\GLEW\lib\glew32.lib and - \external\lib\glut32.lib into Deploy\bin\Release. - - f. Copy bin\glut32.dll and bin\glew32.dll into Deploy\bin\Release. - - d. Build the Release configuration of the OpenEXR_Viewers. - - e. Build the Debug configuration if desired. - -At this point, the Deploy folder should be fully built out and ready -to be used. Both exrdisplay and playexr are meant to be launched from -the command line, as they originated as unix commands, so open a command -prompt, cd to the Deploy\bin\Release folder and enjoy. +OpenEXR is one of six software packages that were designed to work +together: IlmBase, PyIlmBase, OpenEXR, OpenEXR_Viewers, CTL and +OpenEXR_CTL. You may only be interested in OpenEXR or you may want +to build it together wth the other packages. + +What follows are instructions for building all five packages. +If you are only interested in OpenEXR, stop after step 2. + +A couple of notes before getting started: + +- This is not the only way to do this. This document describes a path +that doesn't involve installing libraries into default system paths, +but rather, creates a standalone universe. +- Some of these steps may be a bit redundant, and will be optimized in +the future. +- The Debug versions of the libraries and tools are not required if +you are not going to be doing any debugging, and can be optionally +built. + +The source will build under both Visual Studio versions 7 and 8, and +there are separate directories for the corresponding build files. The +tag is used in this document to describe the appropriate folder +in the path that corresponds to your the version of Visual Studio. + +The Visual Studio project files assume, and help build out, a directory +called "Deploy". In the end, this directory will contain the objects +that might then be moved away from the source for general running of the +compiled programs. The directory structure at the end of compiling all +the related tools looks like this: + +Deploy + include + lib + Debug + Release + bin + Debug + Release +openexr-cvs (name as desired) + IlmBase + PyIlmBase + OpenEXR + OpenEXR_Viewers +ctl-cvs (name as desired) + CTL + OpenEXR_CTL +fltk + FL + GL + lib +nvidia + include + GL + glh + lib + +If OpenEXR_Viewers is not being compiled, then fltk and nvidia will +not be needed, but that will be covered later. + +Step 1. Compile IlmBase + + a. Point Visual Studio at the .sln file in vc\\IlmBase in the + IlmBase subdirectory + + b. Select the Release configuration and hit Build Solution. This + will create the Deploy directory, and copy the relevant parts to it. + + c. If the debug versions are desired, select the Debug configuration + and hit Build Solution. This will add the Debug directories to Deploy. + +Step 2. Compile OpenEXR support + + a. Retrieve the zlib binaries. The project files are set up to link + against the dll version of zlib, but can easily be changed to link + against a static version, or a self-built version if desired. + + 1. Go to http://www.zlib.net and download the precompiled DLL + version of zlib (as of writing, zlib123-dll.zip) + + 2. If you don't wish to put the files into your MS visual studio + directories and install the dll into windows\system32: + + a. Put a copy of zlib1.dll into Deploy\bin\Release and + Deploy\bin\Debug + + b. Copy the header files into Deploy\include + + c. Copy zdll.lib and zdll.exp into Deploy\lib\Release and + Deploy\lib\Debug + + b. Open the Visual Studio project in OpenEXR\vc\\OpenEXR. + + c. Select the Release configuration and build. The IlmImfTest + program runs a confidence test of your build to make sure + it is able to work, and may take some time to complete. + + d. Optionally select the Debug configuration and build. + +Step 3. Compile CTL support + + a. Open the Visual Studio project in CTL\vc\\CTL. + + b. Select the Release configuration and build. The IlmCtlTest + program runs a confidence test of your build to make sure it is + able to work, and may take some time to complete. + + c. Optionally select the Debug configuration and build. + +Step 4. Compile OpenEXR_CTL support + + a. Open the Visual Studio project in OpenEXR_CTL\vc\\OpenEXR_CTL. + + b. Select the Release configuration and build. + + c. Optionally select the Debug configuration and build. + +Step 5. Compile OpenEXR_Viewers + + a. Open the appropriate Visual Studio project in + OpenEXR_Viewers\vc\\OpenEXR_Viewers depending on whether or not + you want CTL support. + + b. exrdisplay requires fltk to work. + + 1. Go to http://www.fltk.org and download fltk 1.1.7 + + 2. Open its project files and compile using the instructions they + provide. + + 3. Create the fltk directory at the top level of your directory + structure as presented above and copy the FL, GL, and lib folders + into the fltk directory + + 4. exrdisplay links fltk statically, so no dll is needed. + + c. playexr requires the nvidia cg library as well as glut and glew. + + 1. Setup the cg toolkit + + a. Go to http://developer.nvidia.com, the developer section and + download the cg toolkit, version 1.5, and install it. The path + where you choose to install Cg is referred to by the + tag in the steps below. + + b. During the installation, if the integrate with visual studio + option is selected, the header files will be automatically found. + Otherwise, copy the directory \Cg\include\Cg + to Deploy\include\Cg + + b. Copy the cg.dll and cgGL.dll from the \Cg\bin + into Deploy\bin\Release and Deploy\bin\Debug, or otherwise make + them available (put them in system32, add to path, etc.) + + c. Copy the cg.lib and cgGL.lib from \Cg\lib + into Deploy\lib\Release and Deploy\lib\Debug + + 2. Make glut available. This can be done via several mechanisms. + See step 4 below. + + 3. Make glew available. This can be done via several mechanisms. + http://glew.sourceforge.net is the master site for this + library. See step 4 below. + + 4. nVidia makes both glut and glew available in their SDK package, + which is a fairly large download, but provides a wealth of other + information on programming for the GPU, and is generally a useful + package, so that is the path chosen for this set up. + + a. Go to http://developer.nvidia.com and download version 10 of the + SDK and install it. It will prompt you to install the Cg toolkit, + but this is not necessary as it was handled in step 1. The path + where you choose to install the SDK is referred to by the + tag in the steps below. + + b. Make an nvidia folder at the top level, with an include and + lib folder inside it. Inside the lib folder, make Debug and + Release folders. + + c. Copy the \external\include\GL directory into + nvidia\include the GL and glh folders into nvidia\include. + + d. Copy the glew headers in \common\GLEW\include\GL + into nvidia\include\GL. + + e. Copy \common\GLEW\lib\glew32.lib and + \external\lib\glut32.lib into Deploy\bin\Release. + + f. Copy bin\glut32.dll and bin\glew32.dll into Deploy\bin\Release. + + d. Build the Release configuration of the OpenEXR_Viewers. + + e. Build the Debug configuration if desired. + +At this point, the Deploy folder should be fully built out and ready +to be used. Both exrdisplay and playexr are meant to be launched from +the command line, as they originated as unix commands, so open a command +prompt, cd to the Deploy\bin\Release folder and enjoy. diff --git a/Source/Utilities.h b/Source/Utilities.h index ab0243c..dfbff64 100644 --- a/Source/Utilities.h +++ b/Source/Utilities.h @@ -98,9 +98,9 @@ DLL_API FIBITMAP * DLL_CALLCONV FreeImage_AllocateHeader(BOOL header_only, int w /** Helper for 16-bit FIT_BITMAP -@see FreeImage_GetRGBMasks -*/ -DLL_API BOOL DLL_CALLCONV FreeImage_HasRGBMasks(FIBITMAP *dib); +@see FreeImage_GetRGBMasks +*/ +DLL_API BOOL DLL_CALLCONV FreeImage_HasRGBMasks(FIBITMAP *dib); #if defined(__cplusplus) } diff --git a/Source/ZLib/ChangeLog b/Source/ZLib/ChangeLog index 84999ee..2c985f8 100644 --- a/Source/ZLib/ChangeLog +++ b/Source/ZLib/ChangeLog @@ -1,1409 +1,1409 @@ - - ChangeLog file for zlib - -Changes in 1.2.7 (2 May 2012) -- Replace use of memmove() with a simple copy for portability -- Test for existence of strerror -- Restore gzgetc_ for backward compatibility with 1.2.6 -- Fix build with non-GNU make on Solaris -- Require gcc 4.0 or later on Mac OS X to use the hidden attribute -- Include unistd.h for Watcom C -- Use __WATCOMC__ instead of __WATCOM__ -- Do not use the visibility attribute if NO_VIZ defined -- Improve the detection of no hidden visibility attribute -- Avoid using __int64 for gcc or solo compilation -- Cast to char * in gzprintf to avoid warnings [Zinser] -- Fix make_vms.com for VAX [Zinser] -- Don't use library or built-in byte swaps -- Simplify test and use of gcc hidden attribute -- Fix bug in gzclose_w() when gzwrite() fails to allocate memory -- Add "x" (O_EXCL) and "e" (O_CLOEXEC) modes support to gzopen() -- Fix bug in test/minigzip.c for configure --solo -- Fix contrib/vstudio project link errors [Mohanathas] -- Add ability to choose the builder in make_vms.com [Schweda] -- Add DESTDIR support to mingw32 win32/Makefile.gcc -- Fix comments in win32/Makefile.gcc for proper usage -- Allow overriding the default install locations for cmake -- Generate and install the pkg-config file with cmake -- Build both a static and a shared version of zlib with cmake -- Include version symbols for cmake builds -- If using cmake with MSVC, add the source directory to the includes -- Remove unneeded EXTRA_CFLAGS from win32/Makefile.gcc [Truta] -- Move obsolete emx makefile to old [Truta] -- Allow the use of -Wundef when compiling or using zlib -- Avoid the use of the -u option with mktemp -- Improve inflate() documentation on the use of Z_FINISH -- Recognize clang as gcc -- Add gzopen_w() in Windows for wide character path names -- Rename zconf.h in CMakeLists.txt to move it out of the way -- Add source directory in CMakeLists.txt for building examples -- Look in build directory for zlib.pc in CMakeLists.txt -- Remove gzflags from zlibvc.def in vc9 and vc10 -- Fix contrib/minizip compilation in the MinGW environment -- Update ./configure for Solaris, support --64 [Mooney] -- Remove -R. from Solaris shared build (possible security issue) -- Avoid race condition for parallel make (-j) running example -- Fix type mismatch between get_crc_table() and crc_table -- Fix parsing of version with "-" in CMakeLists.txt [Snider, Ziegler] -- Fix the path to zlib.map in CMakeLists.txt -- Force the native libtool in Mac OS X to avoid GNU libtool [Beebe] -- Add instructions to win32/Makefile.gcc for shared install [Torri] - -Changes in 1.2.6.1 (12 Feb 2012) -- Avoid the use of the Objective-C reserved name "id" -- Include io.h in gzguts.h for Microsoft compilers -- Fix problem with ./configure --prefix and gzgetc macro -- Include gz_header definition when compiling zlib solo -- Put gzflags() functionality back in zutil.c -- Avoid library header include in crc32.c for Z_SOLO -- Use name in GCC_CLASSIC as C compiler for coverage testing, if set -- Minor cleanup in contrib/minizip/zip.c [Vollant] -- Update make_vms.com [Zinser] -- Remove unnecessary gzgetc_ function -- Use optimized byte swap operations for Microsoft and GNU [Snyder] -- Fix minor typo in zlib.h comments [Rzesniowiecki] - -Changes in 1.2.6 (29 Jan 2012) -- Update the Pascal interface in contrib/pascal -- Fix function numbers for gzgetc_ in zlibvc.def files -- Fix configure.ac for contrib/minizip [Schiffer] -- Fix large-entry detection in minizip on 64-bit systems [Schiffer] -- Have ./configure use the compiler return code for error indication -- Fix CMakeLists.txt for cross compilation [McClure] -- Fix contrib/minizip/zip.c for 64-bit architectures [Dalsnes] -- Fix compilation of contrib/minizip on FreeBSD [Marquez] -- Correct suggested usages in win32/Makefile.msc [Shachar, Horvath] -- Include io.h for Turbo C / Borland C on all platforms [Truta] -- Make version explicit in contrib/minizip/configure.ac [Bosmans] -- Avoid warning for no encryption in contrib/minizip/zip.c [Vollant] -- Minor cleanup up contrib/minizip/unzip.c [Vollant] -- Fix bug when compiling minizip with C++ [Vollant] -- Protect for long name and extra fields in contrib/minizip [Vollant] -- Avoid some warnings in contrib/minizip [Vollant] -- Add -I../.. -L../.. to CFLAGS for minizip and miniunzip -- Add missing libs to minizip linker command -- Add support for VPATH builds in contrib/minizip -- Add an --enable-demos option to contrib/minizip/configure -- Add the generation of configure.log by ./configure -- Exit when required parameters not provided to win32/Makefile.gcc -- Have gzputc return the character written instead of the argument -- Use the -m option on ldconfig for BSD systems [Tobias] -- Correct in zlib.map when deflateResetKeep was added - -Changes in 1.2.5.3 (15 Jan 2012) -- Restore gzgetc function for binary compatibility -- Do not use _lseeki64 under Borland C++ [Truta] -- Update win32/Makefile.msc to build test/*.c [Truta] -- Remove old/visualc6 given CMakefile and other alternatives -- Update AS400 build files and documentation [Monnerat] -- Update win32/Makefile.gcc to build test/*.c [Truta] -- Permit stronger flushes after Z_BLOCK flushes -- Avoid extraneous empty blocks when doing empty flushes -- Permit Z_NULL arguments to deflatePending -- Allow deflatePrime() to insert bits in the middle of a stream -- Remove second empty static block for Z_PARTIAL_FLUSH -- Write out all of the available bits when using Z_BLOCK -- Insert the first two strings in the hash table after a flush - -Changes in 1.2.5.2 (17 Dec 2011) -- fix ld error: unable to find version dependency 'ZLIB_1.2.5' -- use relative symlinks for shared libs -- Avoid searching past window for Z_RLE strategy -- Assure that high-water mark initialization is always applied in deflate -- Add assertions to fill_window() in deflate.c to match comments -- Update python link in README -- Correct spelling error in gzread.c -- Fix bug in gzgets() for a concatenated empty gzip stream -- Correct error in comment for gz_make() -- Change gzread() and related to ignore junk after gzip streams -- Allow gzread() and related to continue after gzclearerr() -- Allow gzrewind() and gzseek() after a premature end-of-file -- Simplify gzseek() now that raw after gzip is ignored -- Change gzgetc() to a macro for speed (~40% speedup in testing) -- Fix gzclose() to return the actual error last encountered -- Always add large file support for windows -- Include zconf.h for windows large file support -- Include zconf.h.cmakein for windows large file support -- Update zconf.h.cmakein on make distclean -- Merge vestigial vsnprintf determination from zutil.h to gzguts.h -- Clarify how gzopen() appends in zlib.h comments -- Correct documentation of gzdirect() since junk at end now ignored -- Add a transparent write mode to gzopen() when 'T' is in the mode -- Update python link in zlib man page -- Get inffixed.h and MAKEFIXED result to match -- Add a ./config --solo option to make zlib subset with no libary use -- Add undocumented inflateResetKeep() function for CAB file decoding -- Add --cover option to ./configure for gcc coverage testing -- Add #define ZLIB_CONST option to use const in the z_stream interface -- Add comment to gzdopen() in zlib.h to use dup() when using fileno() -- Note behavior of uncompress() to provide as much data as it can -- Add files in contrib/minizip to aid in building libminizip -- Split off AR options in Makefile.in and configure -- Change ON macro to Z_ARG to avoid application conflicts -- Facilitate compilation with Borland C++ for pragmas and vsnprintf -- Include io.h for Turbo C / Borland C++ -- Move example.c and minigzip.c to test/ -- Simplify incomplete code table filling in inflate_table() -- Remove code from inflate.c and infback.c that is impossible to execute -- Test the inflate code with full coverage -- Allow deflateSetDictionary, inflateSetDictionary at any time (in raw) -- Add deflateResetKeep and fix inflateResetKeep to retain dictionary -- Fix gzwrite.c to accommodate reduced memory zlib compilation -- Have inflate() with Z_FINISH avoid the allocation of a window -- Do not set strm->adler when doing raw inflate -- Fix gzeof() to behave just like feof() when read is not past end of file -- Fix bug in gzread.c when end-of-file is reached -- Avoid use of Z_BUF_ERROR in gz* functions except for premature EOF -- Document gzread() capability to read concurrently written files -- Remove hard-coding of resource compiler in CMakeLists.txt [Blammo] - -Changes in 1.2.5.1 (10 Sep 2011) -- Update FAQ entry on shared builds (#13) -- Avoid symbolic argument to chmod in Makefile.in -- Fix bug and add consts in contrib/puff [Oberhumer] -- Update contrib/puff/zeros.raw test file to have all block types -- Add full coverage test for puff in contrib/puff/Makefile -- Fix static-only-build install in Makefile.in -- Fix bug in unzGetCurrentFileInfo() in contrib/minizip [Kuno] -- Add libz.a dependency to shared in Makefile.in for parallel builds -- Spell out "number" (instead of "nb") in zlib.h for total_in, total_out -- Replace $(...) with `...` in configure for non-bash sh [Bowler] -- Add darwin* to Darwin* and solaris* to SunOS\ 5* in configure [Groffen] -- Add solaris* to Linux* in configure to allow gcc use [Groffen] -- Add *bsd* to Linux* case in configure [Bar-Lev] -- Add inffast.obj to dependencies in win32/Makefile.msc -- Correct spelling error in deflate.h [Kohler] -- Change libzdll.a again to libz.dll.a (!) in win32/Makefile.gcc -- Add test to configure for GNU C looking for gcc in output of $cc -v -- Add zlib.pc generation to win32/Makefile.gcc [Weigelt] -- Fix bug in zlib.h for _FILE_OFFSET_BITS set and _LARGEFILE64_SOURCE not -- Add comment in zlib.h that adler32_combine with len2 < 0 makes no sense -- Make NO_DIVIDE option in adler32.c much faster (thanks to John Reiser) -- Make stronger test in zconf.h to include unistd.h for LFS -- Apply Darwin patches for 64-bit file offsets to contrib/minizip [Slack] -- Fix zlib.h LFS support when Z_PREFIX used -- Add updated as400 support (removed from old) [Monnerat] -- Avoid deflate sensitivity to volatile input data -- Avoid division in adler32_combine for NO_DIVIDE -- Clarify the use of Z_FINISH with deflateBound() amount of space -- Set binary for output file in puff.c -- Use u4 type for crc_table to avoid conversion warnings -- Apply casts in zlib.h to avoid conversion warnings -- Add OF to prototypes for adler32_combine_ and crc32_combine_ [Miller] -- Improve inflateSync() documentation to note indeterminancy -- Add deflatePending() function to return the amount of pending output -- Correct the spelling of "specification" in FAQ [Randers-Pehrson] -- Add a check in configure for stdarg.h, use for gzprintf() -- Check that pointers fit in ints when gzprint() compiled old style -- Add dummy name before $(SHAREDLIBV) in Makefile [Bar-Lev, Bowler] -- Delete line in configure that adds -L. libz.a to LDFLAGS [Weigelt] -- Add debug records in assmebler code [Londer] -- Update RFC references to use http://tools.ietf.org/html/... [Li] -- Add --archs option, use of libtool to configure for Mac OS X [Borstel] - -Changes in 1.2.5 (19 Apr 2010) -- Disable visibility attribute in win32/Makefile.gcc [Bar-Lev] -- Default to libdir as sharedlibdir in configure [Nieder] -- Update copyright dates on modified source files -- Update trees.c to be able to generate modified trees.h -- Exit configure for MinGW, suggesting win32/Makefile.gcc -- Check for NULL path in gz_open [Homurlu] - -Changes in 1.2.4.5 (18 Apr 2010) -- Set sharedlibdir in configure [Torok] -- Set LDFLAGS in Makefile.in [Bar-Lev] -- Avoid mkdir objs race condition in Makefile.in [Bowler] -- Add ZLIB_INTERNAL in front of internal inter-module functions and arrays -- Define ZLIB_INTERNAL to hide internal functions and arrays for GNU C -- Don't use hidden attribute when it is a warning generator (e.g. Solaris) - -Changes in 1.2.4.4 (18 Apr 2010) -- Fix CROSS_PREFIX executable testing, CHOST extract, mingw* [Torok] -- Undefine _LARGEFILE64_SOURCE in zconf.h if it is zero, but not if empty -- Try to use bash or ksh regardless of functionality of /bin/sh -- Fix configure incompatibility with NetBSD sh -- Remove attempt to run under bash or ksh since have better NetBSD fix -- Fix win32/Makefile.gcc for MinGW [Bar-Lev] -- Add diagnostic messages when using CROSS_PREFIX in configure -- Added --sharedlibdir option to configure [Weigelt] -- Use hidden visibility attribute when available [Frysinger] - -Changes in 1.2.4.3 (10 Apr 2010) -- Only use CROSS_PREFIX in configure for ar and ranlib if they exist -- Use CROSS_PREFIX for nm [Bar-Lev] -- Assume _LARGEFILE64_SOURCE defined is equivalent to true -- Avoid use of undefined symbols in #if with && and || -- Make *64 prototypes in gzguts.h consistent with functions -- Add -shared load option for MinGW in configure [Bowler] -- Move z_off64_t to public interface, use instead of off64_t -- Remove ! from shell test in configure (not portable to Solaris) -- Change +0 macro tests to -0 for possibly increased portability - -Changes in 1.2.4.2 (9 Apr 2010) -- Add consistent carriage returns to readme.txt's in masmx86 and masmx64 -- Really provide prototypes for *64 functions when building without LFS -- Only define unlink() in minigzip.c if unistd.h not included -- Update README to point to contrib/vstudio project files -- Move projects/vc6 to old/ and remove projects/ -- Include stdlib.h in minigzip.c for setmode() definition under WinCE -- Clean up assembler builds in win32/Makefile.msc [Rowe] -- Include sys/types.h for Microsoft for off_t definition -- Fix memory leak on error in gz_open() -- Symbolize nm as $NM in configure [Weigelt] -- Use TEST_LDSHARED instead of LDSHARED to link test programs [Weigelt] -- Add +0 to _FILE_OFFSET_BITS and _LFS64_LARGEFILE in case not defined -- Fix bug in gzeof() to take into account unused input data -- Avoid initialization of structures with variables in puff.c -- Updated win32/README-WIN32.txt [Rowe] - -Changes in 1.2.4.1 (28 Mar 2010) -- Remove the use of [a-z] constructs for sed in configure [gentoo 310225] -- Remove $(SHAREDLIB) from LIBS in Makefile.in [Creech] -- Restore "for debugging" comment on sprintf() in gzlib.c -- Remove fdopen for MVS from gzguts.h -- Put new README-WIN32.txt in win32 [Rowe] -- Add check for shell to configure and invoke another shell if needed -- Fix big fat stinking bug in gzseek() on uncompressed files -- Remove vestigial F_OPEN64 define in zutil.h -- Set and check the value of _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE -- Avoid errors on non-LFS systems when applications define LFS macros -- Set EXE to ".exe" in configure for MINGW [Kahle] -- Match crc32() in crc32.c exactly to the prototype in zlib.h [Sherrill] -- Add prefix for cross-compilation in win32/makefile.gcc [Bar-Lev] -- Add DLL install in win32/makefile.gcc [Bar-Lev] -- Allow Linux* or linux* from uname in configure [Bar-Lev] -- Allow ldconfig to be redefined in configure and Makefile.in [Bar-Lev] -- Add cross-compilation prefixes to configure [Bar-Lev] -- Match type exactly in gz_load() invocation in gzread.c -- Match type exactly of zcalloc() in zutil.c to zlib.h alloc_func -- Provide prototypes for *64 functions when building zlib without LFS -- Don't use -lc when linking shared library on MinGW -- Remove errno.h check in configure and vestigial errno code in zutil.h - -Changes in 1.2.4 (14 Mar 2010) -- Fix VER3 extraction in configure for no fourth subversion -- Update zlib.3, add docs to Makefile.in to make .pdf out of it -- Add zlib.3.pdf to distribution -- Don't set error code in gzerror() if passed pointer is NULL -- Apply destination directory fixes to CMakeLists.txt [Lowman] -- Move #cmakedefine's to a new zconf.in.cmakein -- Restore zconf.h for builds that don't use configure or cmake -- Add distclean to dummy Makefile for convenience -- Update and improve INDEX, README, and FAQ -- Update CMakeLists.txt for the return of zconf.h [Lowman] -- Update contrib/vstudio/vc9 and vc10 [Vollant] -- Change libz.dll.a back to libzdll.a in win32/Makefile.gcc -- Apply license and readme changes to contrib/asm686 [Raiter] -- Check file name lengths and add -c option in minigzip.c [Li] -- Update contrib/amd64 and contrib/masmx86/ [Vollant] -- Avoid use of "eof" parameter in trees.c to not shadow library variable -- Update make_vms.com for removal of zlibdefs.h [Zinser] -- Update assembler code and vstudio projects in contrib [Vollant] -- Remove outdated assembler code contrib/masm686 and contrib/asm586 -- Remove old vc7 and vc8 from contrib/vstudio -- Update win32/Makefile.msc, add ZLIB_VER_SUBREVISION [Rowe] -- Fix memory leaks in gzclose_r() and gzclose_w(), file leak in gz_open() -- Add contrib/gcc_gvmat64 for longest_match and inflate_fast [Vollant] -- Remove *64 functions from win32/zlib.def (they're not 64-bit yet) -- Fix bug in void-returning vsprintf() case in gzwrite.c -- Fix name change from inflate.h in contrib/inflate86/inffas86.c -- Check if temporary file exists before removing in make_vms.com [Zinser] -- Fix make install and uninstall for --static option -- Fix usage of _MSC_VER in gzguts.h and zutil.h [Truta] -- Update readme.txt in contrib/masmx64 and masmx86 to assemble - -Changes in 1.2.3.9 (21 Feb 2010) -- Expunge gzio.c -- Move as400 build information to old -- Fix updates in contrib/minizip and contrib/vstudio -- Add const to vsnprintf test in configure to avoid warnings [Weigelt] -- Delete zconf.h (made by configure) [Weigelt] -- Change zconf.in.h to zconf.h.in per convention [Weigelt] -- Check for NULL buf in gzgets() -- Return empty string for gzgets() with len == 1 (like fgets()) -- Fix description of gzgets() in zlib.h for end-of-file, NULL return -- Update minizip to 1.1 [Vollant] -- Avoid MSVC loss of data warnings in gzread.c, gzwrite.c -- Note in zlib.h that gzerror() should be used to distinguish from EOF -- Remove use of snprintf() from gzlib.c -- Fix bug in gzseek() -- Update contrib/vstudio, adding vc9 and vc10 [Kuno, Vollant] -- Fix zconf.h generation in CMakeLists.txt [Lowman] -- Improve comments in zconf.h where modified by configure - -Changes in 1.2.3.8 (13 Feb 2010) -- Clean up text files (tabs, trailing whitespace, etc.) [Oberhumer] -- Use z_off64_t in gz_zero() and gz_skip() to match state->skip -- Avoid comparison problem when sizeof(int) == sizeof(z_off64_t) -- Revert to Makefile.in from 1.2.3.6 (live with the clutter) -- Fix missing error return in gzflush(), add zlib.h note -- Add *64 functions to zlib.map [Levin] -- Fix signed/unsigned comparison in gz_comp() -- Use SFLAGS when testing shared linking in configure -- Add --64 option to ./configure to use -m64 with gcc -- Fix ./configure --help to correctly name options -- Have make fail if a test fails [Levin] -- Avoid buffer overrun in contrib/masmx64/gvmat64.asm [Simpson] -- Remove assembler object files from contrib - -Changes in 1.2.3.7 (24 Jan 2010) -- Always gzopen() with O_LARGEFILE if available -- Fix gzdirect() to work immediately after gzopen() or gzdopen() -- Make gzdirect() more precise when the state changes while reading -- Improve zlib.h documentation in many places -- Catch memory allocation failure in gz_open() -- Complete close operation if seek forward in gzclose_w() fails -- Return Z_ERRNO from gzclose_r() if close() fails -- Return Z_STREAM_ERROR instead of EOF for gzclose() being passed NULL -- Return zero for gzwrite() errors to match zlib.h description -- Return -1 on gzputs() error to match zlib.h description -- Add zconf.in.h to allow recovery from configure modification [Weigelt] -- Fix static library permissions in Makefile.in [Weigelt] -- Avoid warnings in configure tests that hide functionality [Weigelt] -- Add *BSD and DragonFly to Linux case in configure [gentoo 123571] -- Change libzdll.a to libz.dll.a in win32/Makefile.gcc [gentoo 288212] -- Avoid access of uninitialized data for first inflateReset2 call [Gomes] -- Keep object files in subdirectories to reduce the clutter somewhat -- Remove default Makefile and zlibdefs.h, add dummy Makefile -- Add new external functions to Z_PREFIX, remove duplicates, z_z_ -> z_ -- Remove zlibdefs.h completely -- modify zconf.h instead - -Changes in 1.2.3.6 (17 Jan 2010) -- Avoid void * arithmetic in gzread.c and gzwrite.c -- Make compilers happier with const char * for gz_error message -- Avoid unused parameter warning in inflate.c -- Avoid signed-unsigned comparison warning in inflate.c -- Indent #pragma's for traditional C -- Fix usage of strwinerror() in glib.c, change to gz_strwinerror() -- Correct email address in configure for system options -- Update make_vms.com and add make_vms.com to contrib/minizip [Zinser] -- Update zlib.map [Brown] -- Fix Makefile.in for Solaris 10 make of example64 and minizip64 [Torok] -- Apply various fixes to CMakeLists.txt [Lowman] -- Add checks on len in gzread() and gzwrite() -- Add error message for no more room for gzungetc() -- Remove zlib version check in gzwrite() -- Defer compression of gzprintf() result until need to -- Use snprintf() in gzdopen() if available -- Remove USE_MMAP configuration determination (only used by minigzip) -- Remove examples/pigz.c (available separately) -- Update examples/gun.c to 1.6 - -Changes in 1.2.3.5 (8 Jan 2010) -- Add space after #if in zutil.h for some compilers -- Fix relatively harmless bug in deflate_fast() [Exarevsky] -- Fix same problem in deflate_slow() -- Add $(SHAREDLIBV) to LIBS in Makefile.in [Brown] -- Add deflate_rle() for faster Z_RLE strategy run-length encoding -- Add deflate_huff() for faster Z_HUFFMAN_ONLY encoding -- Change name of "write" variable in inffast.c to avoid library collisions -- Fix premature EOF from gzread() in gzio.c [Brown] -- Use zlib header window size if windowBits is 0 in inflateInit2() -- Remove compressBound() call in deflate.c to avoid linking compress.o -- Replace use of errno in gz* with functions, support WinCE [Alves] -- Provide alternative to perror() in minigzip.c for WinCE [Alves] -- Don't use _vsnprintf on later versions of MSVC [Lowman] -- Add CMake build script and input file [Lowman] -- Update contrib/minizip to 1.1 [Svensson, Vollant] -- Moved nintendods directory from contrib to . -- Replace gzio.c with a new set of routines with the same functionality -- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above -- Update contrib/minizip to 1.1b -- Change gzeof() to return 0 on error instead of -1 to agree with zlib.h - -Changes in 1.2.3.4 (21 Dec 2009) -- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility -- Update comments in configure and Makefile.in for default --shared -- Fix test -z's in configure [Marquess] -- Build examplesh and minigzipsh when not testing -- Change NULL's to Z_NULL's in deflate.c and in comments in zlib.h -- Import LDFLAGS from the environment in configure -- Fix configure to populate SFLAGS with discovered CFLAGS options -- Adapt make_vms.com to the new Makefile.in [Zinser] -- Add zlib2ansi script for C++ compilation [Marquess] -- Add _FILE_OFFSET_BITS=64 test to make test (when applicable) -- Add AMD64 assembler code for longest match to contrib [Teterin] -- Include options from $SFLAGS when doing $LDSHARED -- Simplify 64-bit file support by introducing z_off64_t type -- Make shared object files in objs directory to work around old Sun cc -- Use only three-part version number for Darwin shared compiles -- Add rc option to ar in Makefile.in for when ./configure not run -- Add -WI,-rpath,. to LDFLAGS for OSF 1 V4* -- Set LD_LIBRARYN32_PATH for SGI IRIX shared compile -- Protect against _FILE_OFFSET_BITS being defined when compiling zlib -- Rename Makefile.in targets allstatic to static and allshared to shared -- Fix static and shared Makefile.in targets to be independent -- Correct error return bug in gz_open() by setting state [Brown] -- Put spaces before ;;'s in configure for better sh compatibility -- Add pigz.c (parallel implementation of gzip) to examples/ -- Correct constant in crc32.c to UL [Leventhal] -- Reject negative lengths in crc32_combine() -- Add inflateReset2() function to work like inflateEnd()/inflateInit2() -- Include sys/types.h for _LARGEFILE64_SOURCE [Brown] -- Correct typo in doc/algorithm.txt [Janik] -- Fix bug in adler32_combine() [Zhu] -- Catch missing-end-of-block-code error in all inflates and in puff - Assures that random input to inflate eventually results in an error -- Added enough.c (calculation of ENOUGH for inftrees.h) to examples/ -- Update ENOUGH and its usage to reflect discovered bounds -- Fix gzerror() error report on empty input file [Brown] -- Add ush casts in trees.c to avoid pedantic runtime errors -- Fix typo in zlib.h uncompress() description [Reiss] -- Correct inflate() comments with regard to automatic header detection -- Remove deprecation comment on Z_PARTIAL_FLUSH (it stays) -- Put new version of gzlog (2.0) in examples with interruption recovery -- Add puff compile option to permit invalid distance-too-far streams -- Add puff TEST command options, ability to read piped input -- Prototype the *64 functions in zlib.h when _FILE_OFFSET_BITS == 64, but - _LARGEFILE64_SOURCE not defined -- Fix Z_FULL_FLUSH to truly erase the past by resetting s->strstart -- Fix deflateSetDictionary() to use all 32K for output consistency -- Remove extraneous #define MIN_LOOKAHEAD in deflate.c (in deflate.h) -- Clear bytes after deflate lookahead to avoid use of uninitialized data -- Change a limit in inftrees.c to be more transparent to Coverity Prevent -- Update win32/zlib.def with exported symbols from zlib.h -- Correct spelling errors in zlib.h [Willem, Sobrado] -- Allow Z_BLOCK for deflate() to force a new block -- Allow negative bits in inflatePrime() to delete existing bit buffer -- Add Z_TREES flush option to inflate() to return at end of trees -- Add inflateMark() to return current state information for random access -- Add Makefile for NintendoDS to contrib [Costa] -- Add -w in configure compile tests to avoid spurious warnings [Beucler] -- Fix typos in zlib.h comments for deflateSetDictionary() -- Fix EOF detection in transparent gzread() [Maier] - -Changes in 1.2.3.3 (2 October 2006) -- Make --shared the default for configure, add a --static option -- Add compile option to permit invalid distance-too-far streams -- Add inflateUndermine() function which is required to enable above -- Remove use of "this" variable name for C++ compatibility [Marquess] -- Add testing of shared library in make test, if shared library built -- Use ftello() and fseeko() if available instead of ftell() and fseek() -- Provide two versions of all functions that use the z_off_t type for - binary compatibility -- a normal version and a 64-bit offset version, - per the Large File Support Extension when _LARGEFILE64_SOURCE is - defined; use the 64-bit versions by default when _FILE_OFFSET_BITS - is defined to be 64 -- Add a --uname= option to configure to perhaps help with cross-compiling - -Changes in 1.2.3.2 (3 September 2006) -- Turn off silly Borland warnings [Hay] -- Use off64_t and define _LARGEFILE64_SOURCE when present -- Fix missing dependency on inffixed.h in Makefile.in -- Rig configure --shared to build both shared and static [Teredesai, Truta] -- Remove zconf.in.h and instead create a new zlibdefs.h file -- Fix contrib/minizip/unzip.c non-encrypted after encrypted [Vollant] -- Add treebuild.xml (see http://treebuild.metux.de/) [Weigelt] - -Changes in 1.2.3.1 (16 August 2006) -- Add watcom directory with OpenWatcom make files [Daniel] -- Remove #undef of FAR in zconf.in.h for MVS [Fedtke] -- Update make_vms.com [Zinser] -- Use -fPIC for shared build in configure [Teredesai, Nicholson] -- Use only major version number for libz.so on IRIX and OSF1 [Reinholdtsen] -- Use fdopen() (not _fdopen()) for Interix in zutil.h [BŠck] -- Add some FAQ entries about the contrib directory -- Update the MVS question in the FAQ -- Avoid extraneous reads after EOF in gzio.c [Brown] -- Correct spelling of "successfully" in gzio.c [Randers-Pehrson] -- Add comments to zlib.h about gzerror() usage [Brown] -- Set extra flags in gzip header in gzopen() like deflate() does -- Make configure options more compatible with double-dash conventions - [Weigelt] -- Clean up compilation under Solaris SunStudio cc [Rowe, Reinholdtsen] -- Fix uninstall target in Makefile.in [Truta] -- Add pkgconfig support [Weigelt] -- Use $(DESTDIR) macro in Makefile.in [Reinholdtsen, Weigelt] -- Replace set_data_type() with a more accurate detect_data_type() in - trees.c, according to the txtvsbin.txt document [Truta] -- Swap the order of #include and #include "zlib.h" in - gzio.c, example.c and minigzip.c [Truta] -- Shut up annoying VS2005 warnings about standard C deprecation [Rowe, - Truta] (where?) -- Fix target "clean" from win32/Makefile.bor [Truta] -- Create .pdb and .manifest files in win32/makefile.msc [Ziegler, Rowe] -- Update zlib www home address in win32/DLL_FAQ.txt [Truta] -- Update contrib/masmx86/inffas32.asm for VS2005 [Vollant, Van Wassenhove] -- Enable browse info in the "Debug" and "ASM Debug" configurations in - the Visual C++ 6 project, and set (non-ASM) "Debug" as default [Truta] -- Add pkgconfig support [Weigelt] -- Add ZLIB_VER_MAJOR, ZLIB_VER_MINOR and ZLIB_VER_REVISION in zlib.h, - for use in win32/zlib1.rc [Polushin, Rowe, Truta] -- Add a document that explains the new text detection scheme to - doc/txtvsbin.txt [Truta] -- Add rfc1950.txt, rfc1951.txt and rfc1952.txt to doc/ [Truta] -- Move algorithm.txt into doc/ [Truta] -- Synchronize FAQ with website -- Fix compressBound(), was low for some pathological cases [Fearnley] -- Take into account wrapper variations in deflateBound() -- Set examples/zpipe.c input and output to binary mode for Windows -- Update examples/zlib_how.html with new zpipe.c (also web site) -- Fix some warnings in examples/gzlog.c and examples/zran.c (it seems - that gcc became pickier in 4.0) -- Add zlib.map for Linux: "All symbols from zlib-1.1.4 remain - un-versioned, the patch adds versioning only for symbols introduced in - zlib-1.2.0 or later. It also declares as local those symbols which are - not designed to be exported." [Levin] -- Update Z_PREFIX list in zconf.in.h, add --zprefix option to configure -- Do not initialize global static by default in trees.c, add a response - NO_INIT_GLOBAL_POINTERS to initialize them if needed [Marquess] -- Don't use strerror() in gzio.c under WinCE [Yakimov] -- Don't use errno.h in zutil.h under WinCE [Yakimov] -- Move arguments for AR to its usage to allow replacing ar [Marot] -- Add HAVE_VISIBILITY_PRAGMA in zconf.in.h for Mozilla [Randers-Pehrson] -- Improve inflateInit() and inflateInit2() documentation -- Fix structure size comment in inflate.h -- Change configure help option from --h* to --help [Santos] - -Changes in 1.2.3 (18 July 2005) -- Apply security vulnerability fixes to contrib/infback9 as well -- Clean up some text files (carriage returns, trailing space) -- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant] - -Changes in 1.2.2.4 (11 July 2005) -- Add inflatePrime() function for starting inflation at bit boundary -- Avoid some Visual C warnings in deflate.c -- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit - compile -- Fix some spelling errors in comments [Betts] -- Correct inflateInit2() error return documentation in zlib.h -- Add zran.c example of compressed data random access to examples - directory, shows use of inflatePrime() -- Fix cast for assignments to strm->state in inflate.c and infback.c -- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer] -- Move declarations of gf2 functions to right place in crc32.c [Oberhumer] -- Add cast in trees.c t avoid a warning [Oberhumer] -- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer] -- Update make_vms.com [Zinser] -- Initialize state->write in inflateReset() since copied in inflate_fast() -- Be more strict on incomplete code sets in inflate_table() and increase - ENOUGH and MAXD -- this repairs a possible security vulnerability for - invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for - discovering the vulnerability and providing test cases. -- Add ia64 support to configure for HP-UX [Smith] -- Add error return to gzread() for format or i/o error [Levin] -- Use malloc.h for OS/2 [Necasek] - -Changes in 1.2.2.3 (27 May 2005) -- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile -- Typecast fread() return values in gzio.c [Vollant] -- Remove trailing space in minigzip.c outmode (VC++ can't deal with it) -- Fix crc check bug in gzread() after gzungetc() [Heiner] -- Add the deflateTune() function to adjust internal compression parameters -- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack) -- Remove an incorrect assertion in examples/zpipe.c -- Add C++ wrapper in infback9.h [Donais] -- Fix bug in inflateCopy() when decoding fixed codes -- Note in zlib.h how much deflateSetDictionary() actually uses -- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used) -- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer] -- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer] -- Add gzdirect() function to indicate transparent reads -- Update contrib/minizip [Vollant] -- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer] -- Add casts in crc32.c to avoid warnings [Oberhumer] -- Add contrib/masmx64 [Vollant] -- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant] - -Changes in 1.2.2.2 (30 December 2004) -- Replace structure assignments in deflate.c and inflate.c with zmemcpy to - avoid implicit memcpy calls (portability for no-library compilation) -- Increase sprintf() buffer size in gzdopen() to allow for large numbers -- Add INFLATE_STRICT to check distances against zlib header -- Improve WinCE errno handling and comments [Chang] -- Remove comment about no gzip header processing in FAQ -- Add Z_FIXED strategy option to deflateInit2() to force fixed trees -- Add updated make_vms.com [Coghlan], update README -- Create a new "examples" directory, move gzappend.c there, add zpipe.c, - fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html. -- Add FAQ entry and comments in deflate.c on uninitialized memory access -- Add Solaris 9 make options in configure [Gilbert] -- Allow strerror() usage in gzio.c for STDC -- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer] -- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant] -- Use z_off_t for adler32_combine() and crc32_combine() lengths -- Make adler32() much faster for small len -- Use OS_CODE in deflate() default gzip header - -Changes in 1.2.2.1 (31 October 2004) -- Allow inflateSetDictionary() call for raw inflate -- Fix inflate header crc check bug for file names and comments -- Add deflateSetHeader() and gz_header structure for custom gzip headers -- Add inflateGetheader() to retrieve gzip headers -- Add crc32_combine() and adler32_combine() functions -- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list -- Use zstreamp consistently in zlib.h (inflate_back functions) -- Remove GUNZIP condition from definition of inflate_mode in inflate.h - and in contrib/inflate86/inffast.S [Truta, Anderson] -- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson] -- Update projects/README.projects and projects/visualc6 [Truta] -- Update win32/DLL_FAQ.txt [Truta] -- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta] -- Deprecate Z_ASCII; use Z_TEXT instead [Truta] -- Use a new algorithm for setting strm->data_type in trees.c [Truta] -- Do not define an exit() prototype in zutil.c unless DEBUG defined -- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta] -- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate() -- Fix Darwin build version identification [Peterson] - -Changes in 1.2.2 (3 October 2004) -- Update zlib.h comments on gzip in-memory processing -- Set adler to 1 in inflateReset() to support Java test suite [Walles] -- Add contrib/dotzlib [Ravn] -- Update win32/DLL_FAQ.txt [Truta] -- Update contrib/minizip [Vollant] -- Move contrib/visual-basic.txt to old/ [Truta] -- Fix assembler builds in projects/visualc6/ [Truta] - -Changes in 1.2.1.2 (9 September 2004) -- Update INDEX file -- Fix trees.c to update strm->data_type (no one ever noticed!) -- Fix bug in error case in inflate.c, infback.c, and infback9.c [Brown] -- Add "volatile" to crc table flag declaration (for DYNAMIC_CRC_TABLE) -- Add limited multitasking protection to DYNAMIC_CRC_TABLE -- Add NO_vsnprintf for VMS in zutil.h [Mozilla] -- Don't declare strerror() under VMS [Mozilla] -- Add comment to DYNAMIC_CRC_TABLE to use get_crc_table() to initialize -- Update contrib/ada [Anisimkov] -- Update contrib/minizip [Vollant] -- Fix configure to not hardcode directories for Darwin [Peterson] -- Fix gzio.c to not return error on empty files [Brown] -- Fix indentation; update version in contrib/delphi/ZLib.pas and - contrib/pascal/zlibpas.pas [Truta] -- Update mkasm.bat in contrib/masmx86 [Truta] -- Update contrib/untgz [Truta] -- Add projects/README.projects [Truta] -- Add project for MS Visual C++ 6.0 in projects/visualc6 [Cadieux, Truta] -- Update win32/DLL_FAQ.txt [Truta] -- Update list of Z_PREFIX symbols in zconf.h [Randers-Pehrson, Truta] -- Remove an unnecessary assignment to curr in inftrees.c [Truta] -- Add OS/2 to exe builds in configure [Poltorak] -- Remove err dummy parameter in zlib.h [Kientzle] - -Changes in 1.2.1.1 (9 January 2004) -- Update email address in README -- Several FAQ updates -- Fix a big fat bug in inftrees.c that prevented decoding valid - dynamic blocks with only literals and no distance codes -- - Thanks to "Hot Emu" for the bug report and sample file -- Add a note to puff.c on no distance codes case. - -Changes in 1.2.1 (17 November 2003) -- Remove a tab in contrib/gzappend/gzappend.c -- Update some interfaces in contrib for new zlib functions -- Update zlib version number in some contrib entries -- Add Windows CE definition for ptrdiff_t in zutil.h [Mai, Truta] -- Support shared libraries on Hurd and KFreeBSD [Brown] -- Fix error in NO_DIVIDE option of adler32.c - -Changes in 1.2.0.8 (4 November 2003) -- Update version in contrib/delphi/ZLib.pas and contrib/pascal/zlibpas.pas -- Add experimental NO_DIVIDE #define in adler32.c - - Possibly faster on some processors (let me know if it is) -- Correct Z_BLOCK to not return on first inflate call if no wrap -- Fix strm->data_type on inflate() return to correctly indicate EOB -- Add deflatePrime() function for appending in the middle of a byte -- Add contrib/gzappend for an example of appending to a stream -- Update win32/DLL_FAQ.txt [Truta] -- Delete Turbo C comment in README [Truta] -- Improve some indentation in zconf.h [Truta] -- Fix infinite loop on bad input in configure script [Church] -- Fix gzeof() for concatenated gzip files [Johnson] -- Add example to contrib/visual-basic.txt [Michael B.] -- Add -p to mkdir's in Makefile.in [vda] -- Fix configure to properly detect presence or lack of printf functions -- Add AS400 support [Monnerat] -- Add a little Cygwin support [Wilson] - -Changes in 1.2.0.7 (21 September 2003) -- Correct some debug formats in contrib/infback9 -- Cast a type in a debug statement in trees.c -- Change search and replace delimiter in configure from % to # [Beebe] -- Update contrib/untgz to 0.2 with various fixes [Truta] -- Add build support for Amiga [Nikl] -- Remove some directories in old that have been updated to 1.2 -- Add dylib building for Mac OS X in configure and Makefile.in -- Remove old distribution stuff from Makefile -- Update README to point to DLL_FAQ.txt, and add comment on Mac OS X -- Update links in README - -Changes in 1.2.0.6 (13 September 2003) -- Minor FAQ updates -- Update contrib/minizip to 1.00 [Vollant] -- Remove test of gz functions in example.c when GZ_COMPRESS defined [Truta] -- Update POSTINC comment for 68060 [Nikl] -- Add contrib/infback9 with deflate64 decoding (unsupported) -- For MVS define NO_vsnprintf and undefine FAR [van Burik] -- Add pragma for fdopen on MVS [van Burik] - -Changes in 1.2.0.5 (8 September 2003) -- Add OF to inflateBackEnd() declaration in zlib.h -- Remember start when using gzdopen in the middle of a file -- Use internal off_t counters in gz* functions to properly handle seeks -- Perform more rigorous check for distance-too-far in inffast.c -- Add Z_BLOCK flush option to return from inflate at block boundary -- Set strm->data_type on return from inflate - - Indicate bits unused, if at block boundary, and if in last block -- Replace size_t with ptrdiff_t in crc32.c, and check for correct size -- Add condition so old NO_DEFLATE define still works for compatibility -- FAQ update regarding the Windows DLL [Truta] -- INDEX update: add qnx entry, remove aix entry [Truta] -- Install zlib.3 into mandir [Wilson] -- Move contrib/zlib_dll_FAQ.txt to win32/DLL_FAQ.txt; update [Truta] -- Adapt the zlib interface to the new DLL convention guidelines [Truta] -- Introduce ZLIB_WINAPI macro to allow the export of functions using - the WINAPI calling convention, for Visual Basic [Vollant, Truta] -- Update msdos and win32 scripts and makefiles [Truta] -- Export symbols by name, not by ordinal, in win32/zlib.def [Truta] -- Add contrib/ada [Anisimkov] -- Move asm files from contrib/vstudio/vc70_32 to contrib/asm386 [Truta] -- Rename contrib/asm386 to contrib/masmx86 [Truta, Vollant] -- Add contrib/masm686 [Truta] -- Fix offsets in contrib/inflate86 and contrib/masmx86/inffas32.asm - [Truta, Vollant] -- Update contrib/delphi; rename to contrib/pascal; add example [Truta] -- Remove contrib/delphi2; add a new contrib/delphi [Truta] -- Avoid inclusion of the nonstandard in contrib/iostream, - and fix some method prototypes [Truta] -- Fix the ZCR_SEED2 constant to avoid warnings in contrib/minizip - [Truta] -- Avoid the use of backslash (\) in contrib/minizip [Vollant] -- Fix file time handling in contrib/untgz; update makefiles [Truta] -- Update contrib/vstudio/vc70_32 to comply with the new DLL guidelines - [Vollant] -- Remove contrib/vstudio/vc15_16 [Vollant] -- Rename contrib/vstudio/vc70_32 to contrib/vstudio/vc7 [Truta] -- Update README.contrib [Truta] -- Invert the assignment order of match_head and s->prev[...] in - INSERT_STRING [Truta] -- Compare TOO_FAR with 32767 instead of 32768, to avoid 16-bit warnings - [Truta] -- Compare function pointers with 0, not with NULL or Z_NULL [Truta] -- Fix prototype of syncsearch in inflate.c [Truta] -- Introduce ASMINF macro to be enabled when using an ASM implementation - of inflate_fast [Truta] -- Change NO_DEFLATE to NO_GZCOMPRESS [Truta] -- Modify test_gzio in example.c to take a single file name as a - parameter [Truta] -- Exit the example.c program if gzopen fails [Truta] -- Add type casts around strlen in example.c [Truta] -- Remove casting to sizeof in minigzip.c; give a proper type - to the variable compared with SUFFIX_LEN [Truta] -- Update definitions of STDC and STDC99 in zconf.h [Truta] -- Synchronize zconf.h with the new Windows DLL interface [Truta] -- Use SYS16BIT instead of __32BIT__ to distinguish between - 16- and 32-bit platforms [Truta] -- Use far memory allocators in small 16-bit memory models for - Turbo C [Truta] -- Add info about the use of ASMV, ASMINF and ZLIB_WINAPI in - zlibCompileFlags [Truta] -- Cygwin has vsnprintf [Wilson] -- In Windows16, OS_CODE is 0, as in MSDOS [Truta] -- In Cygwin, OS_CODE is 3 (Unix), not 11 (Windows32) [Wilson] - -Changes in 1.2.0.4 (10 August 2003) -- Minor FAQ updates -- Be more strict when checking inflateInit2's windowBits parameter -- Change NO_GUNZIP compile option to NO_GZIP to cover deflate as well -- Add gzip wrapper option to deflateInit2 using windowBits -- Add updated QNX rule in configure and qnx directory [Bonnefoy] -- Make inflate distance-too-far checks more rigorous -- Clean up FAR usage in inflate -- Add casting to sizeof() in gzio.c and minigzip.c - -Changes in 1.2.0.3 (19 July 2003) -- Fix silly error in gzungetc() implementation [Vollant] -- Update contrib/minizip and contrib/vstudio [Vollant] -- Fix printf format in example.c -- Correct cdecl support in zconf.in.h [Anisimkov] -- Minor FAQ updates - -Changes in 1.2.0.2 (13 July 2003) -- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons -- Attempt to avoid warnings in crc32.c for pointer-int conversion -- Add AIX to configure, remove aix directory [Bakker] -- Add some casts to minigzip.c -- Improve checking after insecure sprintf() or vsprintf() calls -- Remove #elif's from crc32.c -- Change leave label to inf_leave in inflate.c and infback.c to avoid - library conflicts -- Remove inflate gzip decoding by default--only enable gzip decoding by - special request for stricter backward compatibility -- Add zlibCompileFlags() function to return compilation information -- More typecasting in deflate.c to avoid warnings -- Remove leading underscore from _Capital #defines [Truta] -- Fix configure to link shared library when testing -- Add some Windows CE target adjustments [Mai] -- Remove #define ZLIB_DLL in zconf.h [Vollant] -- Add zlib.3 [Rodgers] -- Update RFC URL in deflate.c and algorithm.txt [Mai] -- Add zlib_dll_FAQ.txt to contrib [Truta] -- Add UL to some constants [Truta] -- Update minizip and vstudio [Vollant] -- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h -- Expand use of NO_DUMMY_DECL to avoid all dummy structures -- Added iostream3 to contrib [Schwardt] -- Replace rewind() with fseek() for WinCE [Truta] -- Improve setting of zlib format compression level flags - - Report 0 for huffman and rle strategies and for level == 0 or 1 - - Report 2 only for level == 6 -- Only deal with 64K limit when necessary at compile time [Truta] -- Allow TOO_FAR check to be turned off at compile time [Truta] -- Add gzclearerr() function [Souza] -- Add gzungetc() function - -Changes in 1.2.0.1 (17 March 2003) -- Add Z_RLE strategy for run-length encoding [Truta] - - When Z_RLE requested, restrict matches to distance one - - Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE -- Correct FASTEST compilation to allow level == 0 -- Clean up what gets compiled for FASTEST -- Incorporate changes to zconf.in.h [Vollant] - - Refine detection of Turbo C need for dummy returns - - Refine ZLIB_DLL compilation - - Include additional header file on VMS for off_t typedef -- Try to use _vsnprintf where it supplants vsprintf [Vollant] -- Add some casts in inffast.c -- Enchance comments in zlib.h on what happens if gzprintf() tries to - write more than 4095 bytes before compression -- Remove unused state from inflateBackEnd() -- Remove exit(0) from minigzip.c, example.c -- Get rid of all those darn tabs -- Add "check" target to Makefile.in that does the same thing as "test" -- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in -- Update contrib/inflate86 [Anderson] -- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant] -- Add msdos and win32 directories with makefiles [Truta] -- More additions and improvements to the FAQ - -Changes in 1.2.0 (9 March 2003) -- New and improved inflate code - - About 20% faster - - Does not allocate 32K window unless and until needed - - Automatically detects and decompresses gzip streams - - Raw inflate no longer needs an extra dummy byte at end - - Added inflateBack functions using a callback interface--even faster - than inflate, useful for file utilities (gzip, zip) - - Added inflateCopy() function to record state for random access on - externally generated deflate streams (e.g. in gzip files) - - More readable code (I hope) -- New and improved crc32() - - About 50% faster, thanks to suggestions from Rodney Brown -- Add deflateBound() and compressBound() functions -- Fix memory leak in deflateInit2() -- Permit setting dictionary for raw deflate (for parallel deflate) -- Fix const declaration for gzwrite() -- Check for some malloc() failures in gzio.c -- Fix bug in gzopen() on single-byte file 0x1f -- Fix bug in gzread() on concatenated file with 0x1f at end of buffer - and next buffer doesn't start with 0x8b -- Fix uncompress() to return Z_DATA_ERROR on truncated input -- Free memory at end of example.c -- Remove MAX #define in trees.c (conflicted with some libraries) -- Fix static const's in deflate.c, gzio.c, and zutil.[ch] -- Declare malloc() and free() in gzio.c if STDC not defined -- Use malloc() instead of calloc() in zutil.c if int big enough -- Define STDC for AIX -- Add aix/ with approach for compiling shared library on AIX -- Add HP-UX support for shared libraries in configure -- Add OpenUNIX support for shared libraries in configure -- Use $cc instead of gcc to build shared library -- Make prefix directory if needed when installing -- Correct Macintosh avoidance of typedef Byte in zconf.h -- Correct Turbo C memory allocation when under Linux -- Use libz.a instead of -lz in Makefile (assure use of compiled library) -- Update configure to check for snprintf or vsnprintf functions and their - return value, warn during make if using an insecure function -- Fix configure problem with compile-time knowledge of HAVE_UNISTD_H that - is lost when library is used--resolution is to build new zconf.h -- Documentation improvements (in zlib.h): - - Document raw deflate and inflate - - Update RFCs URL - - Point out that zlib and gzip formats are different - - Note that Z_BUF_ERROR is not fatal - - Document string limit for gzprintf() and possible buffer overflow - - Note requirement on avail_out when flushing - - Note permitted values of flush parameter of inflate() -- Add some FAQs (and even answers) to the FAQ -- Add contrib/inflate86/ for x86 faster inflate -- Add contrib/blast/ for PKWare Data Compression Library decompression -- Add contrib/puff/ simple inflate for deflate format description - -Changes in 1.1.4 (11 March 2002) -- ZFREE was repeated on same allocation on some error conditions. - This creates a security problem described in - http://www.zlib.org/advisory-2002-03-11.txt -- Returned incorrect error (Z_MEM_ERROR) on some invalid data -- Avoid accesses before window for invalid distances with inflate window - less than 32K. -- force windowBits > 8 to avoid a bug in the encoder for a window size - of 256 bytes. (A complete fix will be available in 1.1.5). - -Changes in 1.1.3 (9 July 1998) -- fix "an inflate input buffer bug that shows up on rare but persistent - occasions" (Mark) -- fix gzread and gztell for concatenated .gz files (Didier Le Botlan) -- fix gzseek(..., SEEK_SET) in write mode -- fix crc check after a gzeek (Frank Faubert) -- fix miniunzip when the last entry in a zip file is itself a zip file - (J Lillge) -- add contrib/asm586 and contrib/asm686 (Brian Raiter) - See http://www.muppetlabs.com/~breadbox/software/assembly.html -- add support for Delphi 3 in contrib/delphi (Bob Dellaca) -- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti) -- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren) -- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks) -- added a FAQ file - -- Support gzdopen on Mac with Metrowerks (Jason Linhart) -- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart) -- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young) -- avoid some warnings with Borland C (Tom Tanner) -- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant) -- emulate utime() for WIN32 in contrib/untgz (Gilles Vollant) -- allow several arguments to configure (Tim Mooney, Frodo Looijaard) -- use libdir and includedir in Makefile.in (Tim Mooney) -- support shared libraries on OSF1 V4 (Tim Mooney) -- remove so_locations in "make clean" (Tim Mooney) -- fix maketree.c compilation error (Glenn, Mark) -- Python interface to zlib now in Python 1.5 (Jeremy Hylton) -- new Makefile.riscos (Rich Walker) -- initialize static descriptors in trees.c for embedded targets (Nick Smith) -- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith) -- add the OS/2 files in Makefile.in too (Andrew Zabolotny) -- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane) -- fix maketree.c to allow clean compilation of inffixed.h (Mark) -- fix parameter check in deflateCopy (Gunther Nikl) -- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler) -- Many portability patches by Christian Spieler: - . zutil.c, zutil.h: added "const" for zmem* - . Make_vms.com: fixed some typos - . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists - . msdos/Makefile.msc: remove "default rtl link library" info from obj files - . msdos/Makefile.*: use model-dependent name for the built zlib library - . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc: - new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT) -- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane) -- replace __far with _far for better portability (Christian Spieler, Tom Lane) -- fix test for errno.h in configure (Tim Newsham) - -Changes in 1.1.2 (19 March 98) -- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant) - See http://www.winimage.com/zLibDll/unzip.html -- preinitialize the inflate tables for fixed codes, to make the code - completely thread safe (Mark) -- some simplifications and slight speed-up to the inflate code (Mark) -- fix gzeof on non-compressed files (Allan Schrum) -- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs) -- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn) -- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny) -- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori) -- do not wrap extern "C" around system includes (Tom Lane) -- mention zlib binding for TCL in README (Andreas Kupries) -- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert) -- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson) -- allow "configure --prefix $HOME" (Tim Mooney) -- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson) -- move Makefile.sas to amiga/Makefile.sas - -Changes in 1.1.1 (27 Feb 98) -- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson) -- remove block truncation heuristic which had very marginal effect for zlib - (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the - compression ratio on some files. This also allows inlining _tr_tally for - matches in deflate_slow. -- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier) - -Changes in 1.1.0 (24 Feb 98) -- do not return STREAM_END prematurely in inflate (John Bowler) -- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler) -- compile with -DFASTEST to get compression code optimized for speed only -- in minigzip, try mmap'ing the input file first (Miguel Albrecht) -- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain - on Sun but significant on HP) - -- add a pointer to experimental unzip library in README (Gilles Vollant) -- initialize variable gcc in configure (Chris Herborth) - -Changes in 1.0.9 (17 Feb 1998) -- added gzputs and gzgets functions -- do not clear eof flag in gzseek (Mark Diekhans) -- fix gzseek for files in transparent mode (Mark Diekhans) -- do not assume that vsprintf returns the number of bytes written (Jens Krinke) -- replace EXPORT with ZEXPORT to avoid conflict with other programs -- added compress2 in zconf.h, zlib.def, zlib.dnt -- new asm code from Gilles Vollant in contrib/asm386 -- simplify the inflate code (Mark): - . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new() - . ZALLOC the length list in inflate_trees_fixed() instead of using stack - . ZALLOC the value area for huft_build() instead of using stack - . Simplify Z_FINISH check in inflate() - -- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8 -- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi) -- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with - the declaration of FAR (Gilles VOllant) -- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann) -- read_buf buf parameter of type Bytef* instead of charf* -- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout) -- do not redeclare unlink in minigzip.c for WIN32 (John Bowler) -- fix check for presence of directories in "make install" (Ian Willis) - -Changes in 1.0.8 (27 Jan 1998) -- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant) -- fix gzgetc and gzputc for big endian systems (Markus Oberhumer) -- added compress2() to allow setting the compression level -- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong) -- use constant arrays for the static trees in trees.c instead of computing - them at run time (thanks to Ken Raeburn for this suggestion). To create - trees.h, compile with GEN_TREES_H and run "make test". -- check return code of example in "make test" and display result -- pass minigzip command line options to file_compress -- simplifying code of inflateSync to avoid gcc 2.8 bug - -- support CC="gcc -Wall" in configure -s (QingLong) -- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn) -- fix test for shared library support to avoid compiler warnings -- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant) -- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit) -- do not use fdopen for Metrowerks on Mac (Brad Pettit)) -- add checks for gzputc and gzputc in example.c -- avoid warnings in gzio.c and deflate.c (Andreas Kleinert) -- use const for the CRC table (Ken Raeburn) -- fixed "make uninstall" for shared libraries -- use Tracev instead of Trace in infblock.c -- in example.c use correct compressed length for test_sync -- suppress +vnocompatwarnings in configure for HPUX (not always supported) - -Changes in 1.0.7 (20 Jan 1998) -- fix gzseek which was broken in write mode -- return error for gzseek to negative absolute position -- fix configure for Linux (Chun-Chung Chen) -- increase stack space for MSC (Tim Wegner) -- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant) -- define EXPORTVA for gzprintf (Gilles Vollant) -- added man page zlib.3 (Rick Rodgers) -- for contrib/untgz, fix makedir() and improve Makefile - -- check gzseek in write mode in example.c -- allocate extra buffer for seeks only if gzseek is actually called -- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant) -- add inflateSyncPoint in zconf.h -- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def - -Changes in 1.0.6 (19 Jan 1998) -- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and - gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code) -- Fix a deflate bug occurring only with compression level 0 (thanks to - Andy Buckler for finding this one). -- In minigzip, pass transparently also the first byte for .Z files. -- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress() -- check Z_FINISH in inflate (thanks to Marc Schluper) -- Implement deflateCopy (thanks to Adam Costello) -- make static libraries by default in configure, add --shared option. -- move MSDOS or Windows specific files to directory msdos -- suppress the notion of partial flush to simplify the interface - (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4) -- suppress history buffer provided by application to simplify the interface - (this feature was not implemented anyway in 1.0.4) -- next_in and avail_in must be initialized before calling inflateInit or - inflateInit2 -- add EXPORT in all exported functions (for Windows DLL) -- added Makefile.nt (thanks to Stephen Williams) -- added the unsupported "contrib" directory: - contrib/asm386/ by Gilles Vollant - 386 asm code replacing longest_match(). - contrib/iostream/ by Kevin Ruland - A C++ I/O streams interface to the zlib gz* functions - contrib/iostream2/ by Tyge Løvset - Another C++ I/O streams interface - contrib/untgz/ by "Pedro A. Aranda Guti\irrez" - A very simple tar.gz file extractor using zlib - contrib/visual-basic.txt by Carlos Rios - How to use compress(), uncompress() and the gz* functions from VB. -- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression - level) in minigzip (thanks to Tom Lane) - -- use const for rommable constants in deflate -- added test for gzseek and gztell in example.c -- add undocumented function inflateSyncPoint() (hack for Paul Mackerras) -- add undocumented function zError to convert error code to string - (for Tim Smithers) -- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code. -- Use default memcpy for Symantec MSDOS compiler. -- Add EXPORT keyword for check_func (needed for Windows DLL) -- add current directory to LD_LIBRARY_PATH for "make test" -- create also a link for libz.so.1 -- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura) -- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX) -- added -soname for Linux in configure (Chun-Chung Chen, -- assign numbers to the exported functions in zlib.def (for Windows DLL) -- add advice in zlib.h for best usage of deflateSetDictionary -- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn) -- allow compilation with ANSI keywords only enabled for TurboC in large model -- avoid "versionString"[0] (Borland bug) -- add NEED_DUMMY_RETURN for Borland -- use variable z_verbose for tracing in debug mode (L. Peter Deutsch). -- allow compilation with CC -- defined STDC for OS/2 (David Charlap) -- limit external names to 8 chars for MVS (Thomas Lund) -- in minigzip.c, use static buffers only for 16-bit systems -- fix suffix check for "minigzip -d foo.gz" -- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee) -- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau) -- added makelcc.bat for lcc-win32 (Tom St Denis) -- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe) -- Avoid expanded $Id: ChangeLog,v 1.7 2012/05/13 12:18:39 drolon Exp $. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion. -- check for unistd.h in configure (for off_t) -- remove useless check parameter in inflate_blocks_free -- avoid useless assignment of s->check to itself in inflate_blocks_new -- do not flush twice in gzclose (thanks to Ken Raeburn) -- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h -- use NO_ERRNO_H instead of enumeration of operating systems with errno.h -- work around buggy fclose on pipes for HP/UX -- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson) -- fix configure if CC is already equal to gcc - -Changes in 1.0.5 (3 Jan 98) -- Fix inflate to terminate gracefully when fed corrupted or invalid data -- Use const for rommable constants in inflate -- Eliminate memory leaks on error conditions in inflate -- Removed some vestigial code in inflate -- Update web address in README - -Changes in 1.0.4 (24 Jul 96) -- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF - bit, so the decompressor could decompress all the correct data but went - on to attempt decompressing extra garbage data. This affected minigzip too. -- zlibVersion and gzerror return const char* (needed for DLL) -- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno) -- use z_error only for DEBUG (avoid problem with DLLs) - -Changes in 1.0.3 (2 Jul 96) -- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS - small and medium models; this makes the library incompatible with previous - versions for these models. (No effect in large model or on other systems.) -- return OK instead of BUF_ERROR if previous deflate call returned with - avail_out as zero but there is nothing to do -- added memcmp for non STDC compilers -- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly) -- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO) -- better check for 16-bit mode MSC (avoids problem with Symantec) - -Changes in 1.0.2 (23 May 96) -- added Windows DLL support -- added a function zlibVersion (for the DLL support) -- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model) -- Bytef is define's instead of typedef'd only for Borland C -- avoid reading uninitialized memory in example.c -- mention in README that the zlib format is now RFC1950 -- updated Makefile.dj2 -- added algorithm.doc - -Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion] -- fix array overlay in deflate.c which sometimes caused bad compressed data -- fix inflate bug with empty stored block -- fix MSDOS medium model which was broken in 0.99 -- fix deflateParams() which could generated bad compressed data. -- Bytef is define'd instead of typedef'ed (work around Borland bug) -- added an INDEX file -- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32), - Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas) -- speed up adler32 for modern machines without auto-increment -- added -ansi for IRIX in configure -- static_init_done in trees.c is an int -- define unlink as delete for VMS -- fix configure for QNX -- add configure branch for SCO and HPUX -- avoid many warnings (unused variables, dead assignments, etc...) -- no fdopen for BeOS -- fix the Watcom fix for 32 bit mode (define FAR as empty) -- removed redefinition of Byte for MKWERKS -- work around an MWKERKS bug (incorrect merge of all .h files) - -Changes in 0.99 (27 Jan 96) -- allow preset dictionary shared between compressor and decompressor -- allow compression level 0 (no compression) -- add deflateParams in zlib.h: allow dynamic change of compression level - and compression strategy. -- test large buffers and deflateParams in example.c -- add optional "configure" to build zlib as a shared library -- suppress Makefile.qnx, use configure instead -- fixed deflate for 64-bit systems (detected on Cray) -- fixed inflate_blocks for 64-bit systems (detected on Alpha) -- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2) -- always return Z_BUF_ERROR when deflate() has nothing to do -- deflateInit and inflateInit are now macros to allow version checking -- prefix all global functions and types with z_ with -DZ_PREFIX -- make falloc completely reentrant (inftrees.c) -- fixed very unlikely race condition in ct_static_init -- free in reverse order of allocation to help memory manager -- use zlib-1.0/* instead of zlib/* inside the tar.gz -- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith - -Wconversion -Wstrict-prototypes -Wmissing-prototypes" -- allow gzread on concatenated .gz files -- deflateEnd now returns Z_DATA_ERROR if it was premature -- deflate is finally (?) fully deterministic (no matches beyond end of input) -- Document Z_SYNC_FLUSH -- add uninstall in Makefile -- Check for __cpluplus in zlib.h -- Better test in ct_align for partial flush -- avoid harmless warnings for Borland C++ -- initialize hash_head in deflate.c -- avoid warning on fdopen (gzio.c) for HP cc -Aa -- include stdlib.h for STDC compilers -- include errno.h for Cray -- ignore error if ranlib doesn't exist -- call ranlib twice for NeXTSTEP -- use exec_prefix instead of prefix for libz.a -- renamed ct_* as _tr_* to avoid conflict with applications -- clear z->msg in inflateInit2 before any error return -- initialize opaque in example.c, gzio.c, deflate.c and inflate.c -- fixed typo in zconf.h (_GNUC__ => __GNUC__) -- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode) -- fix typo in Make_vms.com (f$trnlnm -> f$getsyi) -- in fcalloc, normalize pointer if size > 65520 bytes -- don't use special fcalloc for 32 bit Borland C++ -- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc... -- use Z_BINARY instead of BINARY -- document that gzclose after gzdopen will close the file -- allow "a" as mode in gzopen. -- fix error checking in gzread -- allow skipping .gz extra-field on pipes -- added reference to Perl interface in README -- put the crc table in FAR data (I dislike more and more the medium model :) -- added get_crc_table -- added a dimension to all arrays (Borland C can't count). -- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast -- guard against multiple inclusion of *.h (for precompiled header on Mac) -- Watcom C pretends to be Microsoft C small model even in 32 bit mode. -- don't use unsized arrays to avoid silly warnings by Visual C++: - warning C4746: 'inflate_mask' : unsized array treated as '__far' - (what's wrong with far data in far model?). -- define enum out of inflate_blocks_state to allow compilation with C++ - -Changes in 0.95 (16 Aug 95) -- fix MSDOS small and medium model (now easier to adapt to any compiler) -- inlined send_bits -- fix the final (:-) bug for deflate with flush (output was correct but - not completely flushed in rare occasions). -- default window size is same for compression and decompression - (it's now sufficient to set MAX_WBITS in zconf.h). -- voidp -> voidpf and voidnp -> voidp (for consistency with other - typedefs and because voidnp was not near in large model). - -Changes in 0.94 (13 Aug 95) -- support MSDOS medium model -- fix deflate with flush (could sometimes generate bad output) -- fix deflateReset (zlib header was incorrectly suppressed) -- added support for VMS -- allow a compression level in gzopen() -- gzflush now calls fflush -- For deflate with flush, flush even if no more input is provided. -- rename libgz.a as libz.a -- avoid complex expression in infcodes.c triggering Turbo C bug -- work around a problem with gcc on Alpha (in INSERT_STRING) -- don't use inline functions (problem with some gcc versions) -- allow renaming of Byte, uInt, etc... with #define. -- avoid warning about (unused) pointer before start of array in deflate.c -- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c -- avoid reserved word 'new' in trees.c - -Changes in 0.93 (25 June 95) -- temporarily disable inline functions -- make deflate deterministic -- give enough lookahead for PARTIAL_FLUSH -- Set binary mode for stdin/stdout in minigzip.c for OS/2 -- don't even use signed char in inflate (not portable enough) -- fix inflate memory leak for segmented architectures - -Changes in 0.92 (3 May 95) -- don't assume that char is signed (problem on SGI) -- Clear bit buffer when starting a stored block -- no memcpy on Pyramid -- suppressed inftest.c -- optimized fill_window, put longest_match inline for gcc -- optimized inflate on stored blocks. -- untabify all sources to simplify patches - -Changes in 0.91 (2 May 95) -- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h -- Document the memory requirements in zconf.h -- added "make install" -- fix sync search logic in inflateSync -- deflate(Z_FULL_FLUSH) now works even if output buffer too short -- after inflateSync, don't scare people with just "lo world" -- added support for DJGPP - -Changes in 0.9 (1 May 95) -- don't assume that zalloc clears the allocated memory (the TurboC bug - was Mark's bug after all :) -- let again gzread copy uncompressed data unchanged (was working in 0.71) -- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented -- added a test of inflateSync in example.c -- moved MAX_WBITS to zconf.h because users might want to change that. -- document explicitly that zalloc(64K) on MSDOS must return a normalized - pointer (zero offset) -- added Makefiles for Microsoft C, Turbo C, Borland C++ -- faster crc32() - -Changes in 0.8 (29 April 95) -- added fast inflate (inffast.c) -- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this - is incompatible with previous versions of zlib which returned Z_OK. -- work around a TurboC compiler bug (bad code for b << 0, see infutil.h) - (actually that was not a compiler bug, see 0.81 above) -- gzread no longer reads one extra byte in certain cases -- In gzio destroy(), don't reference a freed structure -- avoid many warnings for MSDOS -- avoid the ERROR symbol which is used by MS Windows - -Changes in 0.71 (14 April 95) -- Fixed more MSDOS compilation problems :( There is still a bug with - TurboC large model. - -Changes in 0.7 (14 April 95) -- Added full inflate support. -- Simplified the crc32() interface. The pre- and post-conditioning - (one's complement) is now done inside crc32(). WARNING: this is - incompatible with previous versions; see zlib.h for the new usage. - -Changes in 0.61 (12 April 95) -- workaround for a bug in TurboC. example and minigzip now work on MSDOS. - -Changes in 0.6 (11 April 95) -- added minigzip.c -- added gzdopen to reopen a file descriptor as gzFile -- added transparent reading of non-gziped files in gzread. -- fixed bug in gzread (don't read crc as data) -- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose). -- don't allocate big arrays in the stack (for MSDOS) -- fix some MSDOS compilation problems - -Changes in 0.5: -- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but - not yet Z_FULL_FLUSH. -- support decompression but only in a single step (forced Z_FINISH) -- added opaque object for zalloc and zfree. -- added deflateReset and inflateReset -- added a variable zlib_version for consistency checking. -- renamed the 'filter' parameter of deflateInit2 as 'strategy'. - Added Z_FILTERED and Z_HUFFMAN_ONLY constants. - -Changes in 0.4: -- avoid "zip" everywhere, use zlib instead of ziplib. -- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush - if compression method == 8. -- added adler32 and crc32 -- renamed deflateOptions as deflateInit2, call one or the other but not both -- added the method parameter for deflateInit2. -- added inflateInit2 -- simplied considerably deflateInit and inflateInit by not supporting - user-provided history buffer. This is supported only in deflateInit2 - and inflateInit2. - -Changes in 0.3: -- prefix all macro names with Z_ -- use Z_FINISH instead of deflateEnd to finish compression. -- added Z_HUFFMAN_ONLY -- added gzerror() + + ChangeLog file for zlib + +Changes in 1.2.7 (2 May 2012) +- Replace use of memmove() with a simple copy for portability +- Test for existence of strerror +- Restore gzgetc_ for backward compatibility with 1.2.6 +- Fix build with non-GNU make on Solaris +- Require gcc 4.0 or later on Mac OS X to use the hidden attribute +- Include unistd.h for Watcom C +- Use __WATCOMC__ instead of __WATCOM__ +- Do not use the visibility attribute if NO_VIZ defined +- Improve the detection of no hidden visibility attribute +- Avoid using __int64 for gcc or solo compilation +- Cast to char * in gzprintf to avoid warnings [Zinser] +- Fix make_vms.com for VAX [Zinser] +- Don't use library or built-in byte swaps +- Simplify test and use of gcc hidden attribute +- Fix bug in gzclose_w() when gzwrite() fails to allocate memory +- Add "x" (O_EXCL) and "e" (O_CLOEXEC) modes support to gzopen() +- Fix bug in test/minigzip.c for configure --solo +- Fix contrib/vstudio project link errors [Mohanathas] +- Add ability to choose the builder in make_vms.com [Schweda] +- Add DESTDIR support to mingw32 win32/Makefile.gcc +- Fix comments in win32/Makefile.gcc for proper usage +- Allow overriding the default install locations for cmake +- Generate and install the pkg-config file with cmake +- Build both a static and a shared version of zlib with cmake +- Include version symbols for cmake builds +- If using cmake with MSVC, add the source directory to the includes +- Remove unneeded EXTRA_CFLAGS from win32/Makefile.gcc [Truta] +- Move obsolete emx makefile to old [Truta] +- Allow the use of -Wundef when compiling or using zlib +- Avoid the use of the -u option with mktemp +- Improve inflate() documentation on the use of Z_FINISH +- Recognize clang as gcc +- Add gzopen_w() in Windows for wide character path names +- Rename zconf.h in CMakeLists.txt to move it out of the way +- Add source directory in CMakeLists.txt for building examples +- Look in build directory for zlib.pc in CMakeLists.txt +- Remove gzflags from zlibvc.def in vc9 and vc10 +- Fix contrib/minizip compilation in the MinGW environment +- Update ./configure for Solaris, support --64 [Mooney] +- Remove -R. from Solaris shared build (possible security issue) +- Avoid race condition for parallel make (-j) running example +- Fix type mismatch between get_crc_table() and crc_table +- Fix parsing of version with "-" in CMakeLists.txt [Snider, Ziegler] +- Fix the path to zlib.map in CMakeLists.txt +- Force the native libtool in Mac OS X to avoid GNU libtool [Beebe] +- Add instructions to win32/Makefile.gcc for shared install [Torri] + +Changes in 1.2.6.1 (12 Feb 2012) +- Avoid the use of the Objective-C reserved name "id" +- Include io.h in gzguts.h for Microsoft compilers +- Fix problem with ./configure --prefix and gzgetc macro +- Include gz_header definition when compiling zlib solo +- Put gzflags() functionality back in zutil.c +- Avoid library header include in crc32.c for Z_SOLO +- Use name in GCC_CLASSIC as C compiler for coverage testing, if set +- Minor cleanup in contrib/minizip/zip.c [Vollant] +- Update make_vms.com [Zinser] +- Remove unnecessary gzgetc_ function +- Use optimized byte swap operations for Microsoft and GNU [Snyder] +- Fix minor typo in zlib.h comments [Rzesniowiecki] + +Changes in 1.2.6 (29 Jan 2012) +- Update the Pascal interface in contrib/pascal +- Fix function numbers for gzgetc_ in zlibvc.def files +- Fix configure.ac for contrib/minizip [Schiffer] +- Fix large-entry detection in minizip on 64-bit systems [Schiffer] +- Have ./configure use the compiler return code for error indication +- Fix CMakeLists.txt for cross compilation [McClure] +- Fix contrib/minizip/zip.c for 64-bit architectures [Dalsnes] +- Fix compilation of contrib/minizip on FreeBSD [Marquez] +- Correct suggested usages in win32/Makefile.msc [Shachar, Horvath] +- Include io.h for Turbo C / Borland C on all platforms [Truta] +- Make version explicit in contrib/minizip/configure.ac [Bosmans] +- Avoid warning for no encryption in contrib/minizip/zip.c [Vollant] +- Minor cleanup up contrib/minizip/unzip.c [Vollant] +- Fix bug when compiling minizip with C++ [Vollant] +- Protect for long name and extra fields in contrib/minizip [Vollant] +- Avoid some warnings in contrib/minizip [Vollant] +- Add -I../.. -L../.. to CFLAGS for minizip and miniunzip +- Add missing libs to minizip linker command +- Add support for VPATH builds in contrib/minizip +- Add an --enable-demos option to contrib/minizip/configure +- Add the generation of configure.log by ./configure +- Exit when required parameters not provided to win32/Makefile.gcc +- Have gzputc return the character written instead of the argument +- Use the -m option on ldconfig for BSD systems [Tobias] +- Correct in zlib.map when deflateResetKeep was added + +Changes in 1.2.5.3 (15 Jan 2012) +- Restore gzgetc function for binary compatibility +- Do not use _lseeki64 under Borland C++ [Truta] +- Update win32/Makefile.msc to build test/*.c [Truta] +- Remove old/visualc6 given CMakefile and other alternatives +- Update AS400 build files and documentation [Monnerat] +- Update win32/Makefile.gcc to build test/*.c [Truta] +- Permit stronger flushes after Z_BLOCK flushes +- Avoid extraneous empty blocks when doing empty flushes +- Permit Z_NULL arguments to deflatePending +- Allow deflatePrime() to insert bits in the middle of a stream +- Remove second empty static block for Z_PARTIAL_FLUSH +- Write out all of the available bits when using Z_BLOCK +- Insert the first two strings in the hash table after a flush + +Changes in 1.2.5.2 (17 Dec 2011) +- fix ld error: unable to find version dependency 'ZLIB_1.2.5' +- use relative symlinks for shared libs +- Avoid searching past window for Z_RLE strategy +- Assure that high-water mark initialization is always applied in deflate +- Add assertions to fill_window() in deflate.c to match comments +- Update python link in README +- Correct spelling error in gzread.c +- Fix bug in gzgets() for a concatenated empty gzip stream +- Correct error in comment for gz_make() +- Change gzread() and related to ignore junk after gzip streams +- Allow gzread() and related to continue after gzclearerr() +- Allow gzrewind() and gzseek() after a premature end-of-file +- Simplify gzseek() now that raw after gzip is ignored +- Change gzgetc() to a macro for speed (~40% speedup in testing) +- Fix gzclose() to return the actual error last encountered +- Always add large file support for windows +- Include zconf.h for windows large file support +- Include zconf.h.cmakein for windows large file support +- Update zconf.h.cmakein on make distclean +- Merge vestigial vsnprintf determination from zutil.h to gzguts.h +- Clarify how gzopen() appends in zlib.h comments +- Correct documentation of gzdirect() since junk at end now ignored +- Add a transparent write mode to gzopen() when 'T' is in the mode +- Update python link in zlib man page +- Get inffixed.h and MAKEFIXED result to match +- Add a ./config --solo option to make zlib subset with no libary use +- Add undocumented inflateResetKeep() function for CAB file decoding +- Add --cover option to ./configure for gcc coverage testing +- Add #define ZLIB_CONST option to use const in the z_stream interface +- Add comment to gzdopen() in zlib.h to use dup() when using fileno() +- Note behavior of uncompress() to provide as much data as it can +- Add files in contrib/minizip to aid in building libminizip +- Split off AR options in Makefile.in and configure +- Change ON macro to Z_ARG to avoid application conflicts +- Facilitate compilation with Borland C++ for pragmas and vsnprintf +- Include io.h for Turbo C / Borland C++ +- Move example.c and minigzip.c to test/ +- Simplify incomplete code table filling in inflate_table() +- Remove code from inflate.c and infback.c that is impossible to execute +- Test the inflate code with full coverage +- Allow deflateSetDictionary, inflateSetDictionary at any time (in raw) +- Add deflateResetKeep and fix inflateResetKeep to retain dictionary +- Fix gzwrite.c to accommodate reduced memory zlib compilation +- Have inflate() with Z_FINISH avoid the allocation of a window +- Do not set strm->adler when doing raw inflate +- Fix gzeof() to behave just like feof() when read is not past end of file +- Fix bug in gzread.c when end-of-file is reached +- Avoid use of Z_BUF_ERROR in gz* functions except for premature EOF +- Document gzread() capability to read concurrently written files +- Remove hard-coding of resource compiler in CMakeLists.txt [Blammo] + +Changes in 1.2.5.1 (10 Sep 2011) +- Update FAQ entry on shared builds (#13) +- Avoid symbolic argument to chmod in Makefile.in +- Fix bug and add consts in contrib/puff [Oberhumer] +- Update contrib/puff/zeros.raw test file to have all block types +- Add full coverage test for puff in contrib/puff/Makefile +- Fix static-only-build install in Makefile.in +- Fix bug in unzGetCurrentFileInfo() in contrib/minizip [Kuno] +- Add libz.a dependency to shared in Makefile.in for parallel builds +- Spell out "number" (instead of "nb") in zlib.h for total_in, total_out +- Replace $(...) with `...` in configure for non-bash sh [Bowler] +- Add darwin* to Darwin* and solaris* to SunOS\ 5* in configure [Groffen] +- Add solaris* to Linux* in configure to allow gcc use [Groffen] +- Add *bsd* to Linux* case in configure [Bar-Lev] +- Add inffast.obj to dependencies in win32/Makefile.msc +- Correct spelling error in deflate.h [Kohler] +- Change libzdll.a again to libz.dll.a (!) in win32/Makefile.gcc +- Add test to configure for GNU C looking for gcc in output of $cc -v +- Add zlib.pc generation to win32/Makefile.gcc [Weigelt] +- Fix bug in zlib.h for _FILE_OFFSET_BITS set and _LARGEFILE64_SOURCE not +- Add comment in zlib.h that adler32_combine with len2 < 0 makes no sense +- Make NO_DIVIDE option in adler32.c much faster (thanks to John Reiser) +- Make stronger test in zconf.h to include unistd.h for LFS +- Apply Darwin patches for 64-bit file offsets to contrib/minizip [Slack] +- Fix zlib.h LFS support when Z_PREFIX used +- Add updated as400 support (removed from old) [Monnerat] +- Avoid deflate sensitivity to volatile input data +- Avoid division in adler32_combine for NO_DIVIDE +- Clarify the use of Z_FINISH with deflateBound() amount of space +- Set binary for output file in puff.c +- Use u4 type for crc_table to avoid conversion warnings +- Apply casts in zlib.h to avoid conversion warnings +- Add OF to prototypes for adler32_combine_ and crc32_combine_ [Miller] +- Improve inflateSync() documentation to note indeterminancy +- Add deflatePending() function to return the amount of pending output +- Correct the spelling of "specification" in FAQ [Randers-Pehrson] +- Add a check in configure for stdarg.h, use for gzprintf() +- Check that pointers fit in ints when gzprint() compiled old style +- Add dummy name before $(SHAREDLIBV) in Makefile [Bar-Lev, Bowler] +- Delete line in configure that adds -L. libz.a to LDFLAGS [Weigelt] +- Add debug records in assmebler code [Londer] +- Update RFC references to use http://tools.ietf.org/html/... [Li] +- Add --archs option, use of libtool to configure for Mac OS X [Borstel] + +Changes in 1.2.5 (19 Apr 2010) +- Disable visibility attribute in win32/Makefile.gcc [Bar-Lev] +- Default to libdir as sharedlibdir in configure [Nieder] +- Update copyright dates on modified source files +- Update trees.c to be able to generate modified trees.h +- Exit configure for MinGW, suggesting win32/Makefile.gcc +- Check for NULL path in gz_open [Homurlu] + +Changes in 1.2.4.5 (18 Apr 2010) +- Set sharedlibdir in configure [Torok] +- Set LDFLAGS in Makefile.in [Bar-Lev] +- Avoid mkdir objs race condition in Makefile.in [Bowler] +- Add ZLIB_INTERNAL in front of internal inter-module functions and arrays +- Define ZLIB_INTERNAL to hide internal functions and arrays for GNU C +- Don't use hidden attribute when it is a warning generator (e.g. Solaris) + +Changes in 1.2.4.4 (18 Apr 2010) +- Fix CROSS_PREFIX executable testing, CHOST extract, mingw* [Torok] +- Undefine _LARGEFILE64_SOURCE in zconf.h if it is zero, but not if empty +- Try to use bash or ksh regardless of functionality of /bin/sh +- Fix configure incompatibility with NetBSD sh +- Remove attempt to run under bash or ksh since have better NetBSD fix +- Fix win32/Makefile.gcc for MinGW [Bar-Lev] +- Add diagnostic messages when using CROSS_PREFIX in configure +- Added --sharedlibdir option to configure [Weigelt] +- Use hidden visibility attribute when available [Frysinger] + +Changes in 1.2.4.3 (10 Apr 2010) +- Only use CROSS_PREFIX in configure for ar and ranlib if they exist +- Use CROSS_PREFIX for nm [Bar-Lev] +- Assume _LARGEFILE64_SOURCE defined is equivalent to true +- Avoid use of undefined symbols in #if with && and || +- Make *64 prototypes in gzguts.h consistent with functions +- Add -shared load option for MinGW in configure [Bowler] +- Move z_off64_t to public interface, use instead of off64_t +- Remove ! from shell test in configure (not portable to Solaris) +- Change +0 macro tests to -0 for possibly increased portability + +Changes in 1.2.4.2 (9 Apr 2010) +- Add consistent carriage returns to readme.txt's in masmx86 and masmx64 +- Really provide prototypes for *64 functions when building without LFS +- Only define unlink() in minigzip.c if unistd.h not included +- Update README to point to contrib/vstudio project files +- Move projects/vc6 to old/ and remove projects/ +- Include stdlib.h in minigzip.c for setmode() definition under WinCE +- Clean up assembler builds in win32/Makefile.msc [Rowe] +- Include sys/types.h for Microsoft for off_t definition +- Fix memory leak on error in gz_open() +- Symbolize nm as $NM in configure [Weigelt] +- Use TEST_LDSHARED instead of LDSHARED to link test programs [Weigelt] +- Add +0 to _FILE_OFFSET_BITS and _LFS64_LARGEFILE in case not defined +- Fix bug in gzeof() to take into account unused input data +- Avoid initialization of structures with variables in puff.c +- Updated win32/README-WIN32.txt [Rowe] + +Changes in 1.2.4.1 (28 Mar 2010) +- Remove the use of [a-z] constructs for sed in configure [gentoo 310225] +- Remove $(SHAREDLIB) from LIBS in Makefile.in [Creech] +- Restore "for debugging" comment on sprintf() in gzlib.c +- Remove fdopen for MVS from gzguts.h +- Put new README-WIN32.txt in win32 [Rowe] +- Add check for shell to configure and invoke another shell if needed +- Fix big fat stinking bug in gzseek() on uncompressed files +- Remove vestigial F_OPEN64 define in zutil.h +- Set and check the value of _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE +- Avoid errors on non-LFS systems when applications define LFS macros +- Set EXE to ".exe" in configure for MINGW [Kahle] +- Match crc32() in crc32.c exactly to the prototype in zlib.h [Sherrill] +- Add prefix for cross-compilation in win32/makefile.gcc [Bar-Lev] +- Add DLL install in win32/makefile.gcc [Bar-Lev] +- Allow Linux* or linux* from uname in configure [Bar-Lev] +- Allow ldconfig to be redefined in configure and Makefile.in [Bar-Lev] +- Add cross-compilation prefixes to configure [Bar-Lev] +- Match type exactly in gz_load() invocation in gzread.c +- Match type exactly of zcalloc() in zutil.c to zlib.h alloc_func +- Provide prototypes for *64 functions when building zlib without LFS +- Don't use -lc when linking shared library on MinGW +- Remove errno.h check in configure and vestigial errno code in zutil.h + +Changes in 1.2.4 (14 Mar 2010) +- Fix VER3 extraction in configure for no fourth subversion +- Update zlib.3, add docs to Makefile.in to make .pdf out of it +- Add zlib.3.pdf to distribution +- Don't set error code in gzerror() if passed pointer is NULL +- Apply destination directory fixes to CMakeLists.txt [Lowman] +- Move #cmakedefine's to a new zconf.in.cmakein +- Restore zconf.h for builds that don't use configure or cmake +- Add distclean to dummy Makefile for convenience +- Update and improve INDEX, README, and FAQ +- Update CMakeLists.txt for the return of zconf.h [Lowman] +- Update contrib/vstudio/vc9 and vc10 [Vollant] +- Change libz.dll.a back to libzdll.a in win32/Makefile.gcc +- Apply license and readme changes to contrib/asm686 [Raiter] +- Check file name lengths and add -c option in minigzip.c [Li] +- Update contrib/amd64 and contrib/masmx86/ [Vollant] +- Avoid use of "eof" parameter in trees.c to not shadow library variable +- Update make_vms.com for removal of zlibdefs.h [Zinser] +- Update assembler code and vstudio projects in contrib [Vollant] +- Remove outdated assembler code contrib/masm686 and contrib/asm586 +- Remove old vc7 and vc8 from contrib/vstudio +- Update win32/Makefile.msc, add ZLIB_VER_SUBREVISION [Rowe] +- Fix memory leaks in gzclose_r() and gzclose_w(), file leak in gz_open() +- Add contrib/gcc_gvmat64 for longest_match and inflate_fast [Vollant] +- Remove *64 functions from win32/zlib.def (they're not 64-bit yet) +- Fix bug in void-returning vsprintf() case in gzwrite.c +- Fix name change from inflate.h in contrib/inflate86/inffas86.c +- Check if temporary file exists before removing in make_vms.com [Zinser] +- Fix make install and uninstall for --static option +- Fix usage of _MSC_VER in gzguts.h and zutil.h [Truta] +- Update readme.txt in contrib/masmx64 and masmx86 to assemble + +Changes in 1.2.3.9 (21 Feb 2010) +- Expunge gzio.c +- Move as400 build information to old +- Fix updates in contrib/minizip and contrib/vstudio +- Add const to vsnprintf test in configure to avoid warnings [Weigelt] +- Delete zconf.h (made by configure) [Weigelt] +- Change zconf.in.h to zconf.h.in per convention [Weigelt] +- Check for NULL buf in gzgets() +- Return empty string for gzgets() with len == 1 (like fgets()) +- Fix description of gzgets() in zlib.h for end-of-file, NULL return +- Update minizip to 1.1 [Vollant] +- Avoid MSVC loss of data warnings in gzread.c, gzwrite.c +- Note in zlib.h that gzerror() should be used to distinguish from EOF +- Remove use of snprintf() from gzlib.c +- Fix bug in gzseek() +- Update contrib/vstudio, adding vc9 and vc10 [Kuno, Vollant] +- Fix zconf.h generation in CMakeLists.txt [Lowman] +- Improve comments in zconf.h where modified by configure + +Changes in 1.2.3.8 (13 Feb 2010) +- Clean up text files (tabs, trailing whitespace, etc.) [Oberhumer] +- Use z_off64_t in gz_zero() and gz_skip() to match state->skip +- Avoid comparison problem when sizeof(int) == sizeof(z_off64_t) +- Revert to Makefile.in from 1.2.3.6 (live with the clutter) +- Fix missing error return in gzflush(), add zlib.h note +- Add *64 functions to zlib.map [Levin] +- Fix signed/unsigned comparison in gz_comp() +- Use SFLAGS when testing shared linking in configure +- Add --64 option to ./configure to use -m64 with gcc +- Fix ./configure --help to correctly name options +- Have make fail if a test fails [Levin] +- Avoid buffer overrun in contrib/masmx64/gvmat64.asm [Simpson] +- Remove assembler object files from contrib + +Changes in 1.2.3.7 (24 Jan 2010) +- Always gzopen() with O_LARGEFILE if available +- Fix gzdirect() to work immediately after gzopen() or gzdopen() +- Make gzdirect() more precise when the state changes while reading +- Improve zlib.h documentation in many places +- Catch memory allocation failure in gz_open() +- Complete close operation if seek forward in gzclose_w() fails +- Return Z_ERRNO from gzclose_r() if close() fails +- Return Z_STREAM_ERROR instead of EOF for gzclose() being passed NULL +- Return zero for gzwrite() errors to match zlib.h description +- Return -1 on gzputs() error to match zlib.h description +- Add zconf.in.h to allow recovery from configure modification [Weigelt] +- Fix static library permissions in Makefile.in [Weigelt] +- Avoid warnings in configure tests that hide functionality [Weigelt] +- Add *BSD and DragonFly to Linux case in configure [gentoo 123571] +- Change libzdll.a to libz.dll.a in win32/Makefile.gcc [gentoo 288212] +- Avoid access of uninitialized data for first inflateReset2 call [Gomes] +- Keep object files in subdirectories to reduce the clutter somewhat +- Remove default Makefile and zlibdefs.h, add dummy Makefile +- Add new external functions to Z_PREFIX, remove duplicates, z_z_ -> z_ +- Remove zlibdefs.h completely -- modify zconf.h instead + +Changes in 1.2.3.6 (17 Jan 2010) +- Avoid void * arithmetic in gzread.c and gzwrite.c +- Make compilers happier with const char * for gz_error message +- Avoid unused parameter warning in inflate.c +- Avoid signed-unsigned comparison warning in inflate.c +- Indent #pragma's for traditional C +- Fix usage of strwinerror() in glib.c, change to gz_strwinerror() +- Correct email address in configure for system options +- Update make_vms.com and add make_vms.com to contrib/minizip [Zinser] +- Update zlib.map [Brown] +- Fix Makefile.in for Solaris 10 make of example64 and minizip64 [Torok] +- Apply various fixes to CMakeLists.txt [Lowman] +- Add checks on len in gzread() and gzwrite() +- Add error message for no more room for gzungetc() +- Remove zlib version check in gzwrite() +- Defer compression of gzprintf() result until need to +- Use snprintf() in gzdopen() if available +- Remove USE_MMAP configuration determination (only used by minigzip) +- Remove examples/pigz.c (available separately) +- Update examples/gun.c to 1.6 + +Changes in 1.2.3.5 (8 Jan 2010) +- Add space after #if in zutil.h for some compilers +- Fix relatively harmless bug in deflate_fast() [Exarevsky] +- Fix same problem in deflate_slow() +- Add $(SHAREDLIBV) to LIBS in Makefile.in [Brown] +- Add deflate_rle() for faster Z_RLE strategy run-length encoding +- Add deflate_huff() for faster Z_HUFFMAN_ONLY encoding +- Change name of "write" variable in inffast.c to avoid library collisions +- Fix premature EOF from gzread() in gzio.c [Brown] +- Use zlib header window size if windowBits is 0 in inflateInit2() +- Remove compressBound() call in deflate.c to avoid linking compress.o +- Replace use of errno in gz* with functions, support WinCE [Alves] +- Provide alternative to perror() in minigzip.c for WinCE [Alves] +- Don't use _vsnprintf on later versions of MSVC [Lowman] +- Add CMake build script and input file [Lowman] +- Update contrib/minizip to 1.1 [Svensson, Vollant] +- Moved nintendods directory from contrib to . +- Replace gzio.c with a new set of routines with the same functionality +- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above +- Update contrib/minizip to 1.1b +- Change gzeof() to return 0 on error instead of -1 to agree with zlib.h + +Changes in 1.2.3.4 (21 Dec 2009) +- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility +- Update comments in configure and Makefile.in for default --shared +- Fix test -z's in configure [Marquess] +- Build examplesh and minigzipsh when not testing +- Change NULL's to Z_NULL's in deflate.c and in comments in zlib.h +- Import LDFLAGS from the environment in configure +- Fix configure to populate SFLAGS with discovered CFLAGS options +- Adapt make_vms.com to the new Makefile.in [Zinser] +- Add zlib2ansi script for C++ compilation [Marquess] +- Add _FILE_OFFSET_BITS=64 test to make test (when applicable) +- Add AMD64 assembler code for longest match to contrib [Teterin] +- Include options from $SFLAGS when doing $LDSHARED +- Simplify 64-bit file support by introducing z_off64_t type +- Make shared object files in objs directory to work around old Sun cc +- Use only three-part version number for Darwin shared compiles +- Add rc option to ar in Makefile.in for when ./configure not run +- Add -WI,-rpath,. to LDFLAGS for OSF 1 V4* +- Set LD_LIBRARYN32_PATH for SGI IRIX shared compile +- Protect against _FILE_OFFSET_BITS being defined when compiling zlib +- Rename Makefile.in targets allstatic to static and allshared to shared +- Fix static and shared Makefile.in targets to be independent +- Correct error return bug in gz_open() by setting state [Brown] +- Put spaces before ;;'s in configure for better sh compatibility +- Add pigz.c (parallel implementation of gzip) to examples/ +- Correct constant in crc32.c to UL [Leventhal] +- Reject negative lengths in crc32_combine() +- Add inflateReset2() function to work like inflateEnd()/inflateInit2() +- Include sys/types.h for _LARGEFILE64_SOURCE [Brown] +- Correct typo in doc/algorithm.txt [Janik] +- Fix bug in adler32_combine() [Zhu] +- Catch missing-end-of-block-code error in all inflates and in puff + Assures that random input to inflate eventually results in an error +- Added enough.c (calculation of ENOUGH for inftrees.h) to examples/ +- Update ENOUGH and its usage to reflect discovered bounds +- Fix gzerror() error report on empty input file [Brown] +- Add ush casts in trees.c to avoid pedantic runtime errors +- Fix typo in zlib.h uncompress() description [Reiss] +- Correct inflate() comments with regard to automatic header detection +- Remove deprecation comment on Z_PARTIAL_FLUSH (it stays) +- Put new version of gzlog (2.0) in examples with interruption recovery +- Add puff compile option to permit invalid distance-too-far streams +- Add puff TEST command options, ability to read piped input +- Prototype the *64 functions in zlib.h when _FILE_OFFSET_BITS == 64, but + _LARGEFILE64_SOURCE not defined +- Fix Z_FULL_FLUSH to truly erase the past by resetting s->strstart +- Fix deflateSetDictionary() to use all 32K for output consistency +- Remove extraneous #define MIN_LOOKAHEAD in deflate.c (in deflate.h) +- Clear bytes after deflate lookahead to avoid use of uninitialized data +- Change a limit in inftrees.c to be more transparent to Coverity Prevent +- Update win32/zlib.def with exported symbols from zlib.h +- Correct spelling errors in zlib.h [Willem, Sobrado] +- Allow Z_BLOCK for deflate() to force a new block +- Allow negative bits in inflatePrime() to delete existing bit buffer +- Add Z_TREES flush option to inflate() to return at end of trees +- Add inflateMark() to return current state information for random access +- Add Makefile for NintendoDS to contrib [Costa] +- Add -w in configure compile tests to avoid spurious warnings [Beucler] +- Fix typos in zlib.h comments for deflateSetDictionary() +- Fix EOF detection in transparent gzread() [Maier] + +Changes in 1.2.3.3 (2 October 2006) +- Make --shared the default for configure, add a --static option +- Add compile option to permit invalid distance-too-far streams +- Add inflateUndermine() function which is required to enable above +- Remove use of "this" variable name for C++ compatibility [Marquess] +- Add testing of shared library in make test, if shared library built +- Use ftello() and fseeko() if available instead of ftell() and fseek() +- Provide two versions of all functions that use the z_off_t type for + binary compatibility -- a normal version and a 64-bit offset version, + per the Large File Support Extension when _LARGEFILE64_SOURCE is + defined; use the 64-bit versions by default when _FILE_OFFSET_BITS + is defined to be 64 +- Add a --uname= option to configure to perhaps help with cross-compiling + +Changes in 1.2.3.2 (3 September 2006) +- Turn off silly Borland warnings [Hay] +- Use off64_t and define _LARGEFILE64_SOURCE when present +- Fix missing dependency on inffixed.h in Makefile.in +- Rig configure --shared to build both shared and static [Teredesai, Truta] +- Remove zconf.in.h and instead create a new zlibdefs.h file +- Fix contrib/minizip/unzip.c non-encrypted after encrypted [Vollant] +- Add treebuild.xml (see http://treebuild.metux.de/) [Weigelt] + +Changes in 1.2.3.1 (16 August 2006) +- Add watcom directory with OpenWatcom make files [Daniel] +- Remove #undef of FAR in zconf.in.h for MVS [Fedtke] +- Update make_vms.com [Zinser] +- Use -fPIC for shared build in configure [Teredesai, Nicholson] +- Use only major version number for libz.so on IRIX and OSF1 [Reinholdtsen] +- Use fdopen() (not _fdopen()) for Interix in zutil.h [BŠck] +- Add some FAQ entries about the contrib directory +- Update the MVS question in the FAQ +- Avoid extraneous reads after EOF in gzio.c [Brown] +- Correct spelling of "successfully" in gzio.c [Randers-Pehrson] +- Add comments to zlib.h about gzerror() usage [Brown] +- Set extra flags in gzip header in gzopen() like deflate() does +- Make configure options more compatible with double-dash conventions + [Weigelt] +- Clean up compilation under Solaris SunStudio cc [Rowe, Reinholdtsen] +- Fix uninstall target in Makefile.in [Truta] +- Add pkgconfig support [Weigelt] +- Use $(DESTDIR) macro in Makefile.in [Reinholdtsen, Weigelt] +- Replace set_data_type() with a more accurate detect_data_type() in + trees.c, according to the txtvsbin.txt document [Truta] +- Swap the order of #include and #include "zlib.h" in + gzio.c, example.c and minigzip.c [Truta] +- Shut up annoying VS2005 warnings about standard C deprecation [Rowe, + Truta] (where?) +- Fix target "clean" from win32/Makefile.bor [Truta] +- Create .pdb and .manifest files in win32/makefile.msc [Ziegler, Rowe] +- Update zlib www home address in win32/DLL_FAQ.txt [Truta] +- Update contrib/masmx86/inffas32.asm for VS2005 [Vollant, Van Wassenhove] +- Enable browse info in the "Debug" and "ASM Debug" configurations in + the Visual C++ 6 project, and set (non-ASM) "Debug" as default [Truta] +- Add pkgconfig support [Weigelt] +- Add ZLIB_VER_MAJOR, ZLIB_VER_MINOR and ZLIB_VER_REVISION in zlib.h, + for use in win32/zlib1.rc [Polushin, Rowe, Truta] +- Add a document that explains the new text detection scheme to + doc/txtvsbin.txt [Truta] +- Add rfc1950.txt, rfc1951.txt and rfc1952.txt to doc/ [Truta] +- Move algorithm.txt into doc/ [Truta] +- Synchronize FAQ with website +- Fix compressBound(), was low for some pathological cases [Fearnley] +- Take into account wrapper variations in deflateBound() +- Set examples/zpipe.c input and output to binary mode for Windows +- Update examples/zlib_how.html with new zpipe.c (also web site) +- Fix some warnings in examples/gzlog.c and examples/zran.c (it seems + that gcc became pickier in 4.0) +- Add zlib.map for Linux: "All symbols from zlib-1.1.4 remain + un-versioned, the patch adds versioning only for symbols introduced in + zlib-1.2.0 or later. It also declares as local those symbols which are + not designed to be exported." [Levin] +- Update Z_PREFIX list in zconf.in.h, add --zprefix option to configure +- Do not initialize global static by default in trees.c, add a response + NO_INIT_GLOBAL_POINTERS to initialize them if needed [Marquess] +- Don't use strerror() in gzio.c under WinCE [Yakimov] +- Don't use errno.h in zutil.h under WinCE [Yakimov] +- Move arguments for AR to its usage to allow replacing ar [Marot] +- Add HAVE_VISIBILITY_PRAGMA in zconf.in.h for Mozilla [Randers-Pehrson] +- Improve inflateInit() and inflateInit2() documentation +- Fix structure size comment in inflate.h +- Change configure help option from --h* to --help [Santos] + +Changes in 1.2.3 (18 July 2005) +- Apply security vulnerability fixes to contrib/infback9 as well +- Clean up some text files (carriage returns, trailing space) +- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant] + +Changes in 1.2.2.4 (11 July 2005) +- Add inflatePrime() function for starting inflation at bit boundary +- Avoid some Visual C warnings in deflate.c +- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit + compile +- Fix some spelling errors in comments [Betts] +- Correct inflateInit2() error return documentation in zlib.h +- Add zran.c example of compressed data random access to examples + directory, shows use of inflatePrime() +- Fix cast for assignments to strm->state in inflate.c and infback.c +- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer] +- Move declarations of gf2 functions to right place in crc32.c [Oberhumer] +- Add cast in trees.c t avoid a warning [Oberhumer] +- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer] +- Update make_vms.com [Zinser] +- Initialize state->write in inflateReset() since copied in inflate_fast() +- Be more strict on incomplete code sets in inflate_table() and increase + ENOUGH and MAXD -- this repairs a possible security vulnerability for + invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for + discovering the vulnerability and providing test cases. +- Add ia64 support to configure for HP-UX [Smith] +- Add error return to gzread() for format or i/o error [Levin] +- Use malloc.h for OS/2 [Necasek] + +Changes in 1.2.2.3 (27 May 2005) +- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile +- Typecast fread() return values in gzio.c [Vollant] +- Remove trailing space in minigzip.c outmode (VC++ can't deal with it) +- Fix crc check bug in gzread() after gzungetc() [Heiner] +- Add the deflateTune() function to adjust internal compression parameters +- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack) +- Remove an incorrect assertion in examples/zpipe.c +- Add C++ wrapper in infback9.h [Donais] +- Fix bug in inflateCopy() when decoding fixed codes +- Note in zlib.h how much deflateSetDictionary() actually uses +- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used) +- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer] +- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer] +- Add gzdirect() function to indicate transparent reads +- Update contrib/minizip [Vollant] +- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer] +- Add casts in crc32.c to avoid warnings [Oberhumer] +- Add contrib/masmx64 [Vollant] +- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant] + +Changes in 1.2.2.2 (30 December 2004) +- Replace structure assignments in deflate.c and inflate.c with zmemcpy to + avoid implicit memcpy calls (portability for no-library compilation) +- Increase sprintf() buffer size in gzdopen() to allow for large numbers +- Add INFLATE_STRICT to check distances against zlib header +- Improve WinCE errno handling and comments [Chang] +- Remove comment about no gzip header processing in FAQ +- Add Z_FIXED strategy option to deflateInit2() to force fixed trees +- Add updated make_vms.com [Coghlan], update README +- Create a new "examples" directory, move gzappend.c there, add zpipe.c, + fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html. +- Add FAQ entry and comments in deflate.c on uninitialized memory access +- Add Solaris 9 make options in configure [Gilbert] +- Allow strerror() usage in gzio.c for STDC +- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer] +- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant] +- Use z_off_t for adler32_combine() and crc32_combine() lengths +- Make adler32() much faster for small len +- Use OS_CODE in deflate() default gzip header + +Changes in 1.2.2.1 (31 October 2004) +- Allow inflateSetDictionary() call for raw inflate +- Fix inflate header crc check bug for file names and comments +- Add deflateSetHeader() and gz_header structure for custom gzip headers +- Add inflateGetheader() to retrieve gzip headers +- Add crc32_combine() and adler32_combine() functions +- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list +- Use zstreamp consistently in zlib.h (inflate_back functions) +- Remove GUNZIP condition from definition of inflate_mode in inflate.h + and in contrib/inflate86/inffast.S [Truta, Anderson] +- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson] +- Update projects/README.projects and projects/visualc6 [Truta] +- Update win32/DLL_FAQ.txt [Truta] +- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta] +- Deprecate Z_ASCII; use Z_TEXT instead [Truta] +- Use a new algorithm for setting strm->data_type in trees.c [Truta] +- Do not define an exit() prototype in zutil.c unless DEBUG defined +- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta] +- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate() +- Fix Darwin build version identification [Peterson] + +Changes in 1.2.2 (3 October 2004) +- Update zlib.h comments on gzip in-memory processing +- Set adler to 1 in inflateReset() to support Java test suite [Walles] +- Add contrib/dotzlib [Ravn] +- Update win32/DLL_FAQ.txt [Truta] +- Update contrib/minizip [Vollant] +- Move contrib/visual-basic.txt to old/ [Truta] +- Fix assembler builds in projects/visualc6/ [Truta] + +Changes in 1.2.1.2 (9 September 2004) +- Update INDEX file +- Fix trees.c to update strm->data_type (no one ever noticed!) +- Fix bug in error case in inflate.c, infback.c, and infback9.c [Brown] +- Add "volatile" to crc table flag declaration (for DYNAMIC_CRC_TABLE) +- Add limited multitasking protection to DYNAMIC_CRC_TABLE +- Add NO_vsnprintf for VMS in zutil.h [Mozilla] +- Don't declare strerror() under VMS [Mozilla] +- Add comment to DYNAMIC_CRC_TABLE to use get_crc_table() to initialize +- Update contrib/ada [Anisimkov] +- Update contrib/minizip [Vollant] +- Fix configure to not hardcode directories for Darwin [Peterson] +- Fix gzio.c to not return error on empty files [Brown] +- Fix indentation; update version in contrib/delphi/ZLib.pas and + contrib/pascal/zlibpas.pas [Truta] +- Update mkasm.bat in contrib/masmx86 [Truta] +- Update contrib/untgz [Truta] +- Add projects/README.projects [Truta] +- Add project for MS Visual C++ 6.0 in projects/visualc6 [Cadieux, Truta] +- Update win32/DLL_FAQ.txt [Truta] +- Update list of Z_PREFIX symbols in zconf.h [Randers-Pehrson, Truta] +- Remove an unnecessary assignment to curr in inftrees.c [Truta] +- Add OS/2 to exe builds in configure [Poltorak] +- Remove err dummy parameter in zlib.h [Kientzle] + +Changes in 1.2.1.1 (9 January 2004) +- Update email address in README +- Several FAQ updates +- Fix a big fat bug in inftrees.c that prevented decoding valid + dynamic blocks with only literals and no distance codes -- + Thanks to "Hot Emu" for the bug report and sample file +- Add a note to puff.c on no distance codes case. + +Changes in 1.2.1 (17 November 2003) +- Remove a tab in contrib/gzappend/gzappend.c +- Update some interfaces in contrib for new zlib functions +- Update zlib version number in some contrib entries +- Add Windows CE definition for ptrdiff_t in zutil.h [Mai, Truta] +- Support shared libraries on Hurd and KFreeBSD [Brown] +- Fix error in NO_DIVIDE option of adler32.c + +Changes in 1.2.0.8 (4 November 2003) +- Update version in contrib/delphi/ZLib.pas and contrib/pascal/zlibpas.pas +- Add experimental NO_DIVIDE #define in adler32.c + - Possibly faster on some processors (let me know if it is) +- Correct Z_BLOCK to not return on first inflate call if no wrap +- Fix strm->data_type on inflate() return to correctly indicate EOB +- Add deflatePrime() function for appending in the middle of a byte +- Add contrib/gzappend for an example of appending to a stream +- Update win32/DLL_FAQ.txt [Truta] +- Delete Turbo C comment in README [Truta] +- Improve some indentation in zconf.h [Truta] +- Fix infinite loop on bad input in configure script [Church] +- Fix gzeof() for concatenated gzip files [Johnson] +- Add example to contrib/visual-basic.txt [Michael B.] +- Add -p to mkdir's in Makefile.in [vda] +- Fix configure to properly detect presence or lack of printf functions +- Add AS400 support [Monnerat] +- Add a little Cygwin support [Wilson] + +Changes in 1.2.0.7 (21 September 2003) +- Correct some debug formats in contrib/infback9 +- Cast a type in a debug statement in trees.c +- Change search and replace delimiter in configure from % to # [Beebe] +- Update contrib/untgz to 0.2 with various fixes [Truta] +- Add build support for Amiga [Nikl] +- Remove some directories in old that have been updated to 1.2 +- Add dylib building for Mac OS X in configure and Makefile.in +- Remove old distribution stuff from Makefile +- Update README to point to DLL_FAQ.txt, and add comment on Mac OS X +- Update links in README + +Changes in 1.2.0.6 (13 September 2003) +- Minor FAQ updates +- Update contrib/minizip to 1.00 [Vollant] +- Remove test of gz functions in example.c when GZ_COMPRESS defined [Truta] +- Update POSTINC comment for 68060 [Nikl] +- Add contrib/infback9 with deflate64 decoding (unsupported) +- For MVS define NO_vsnprintf and undefine FAR [van Burik] +- Add pragma for fdopen on MVS [van Burik] + +Changes in 1.2.0.5 (8 September 2003) +- Add OF to inflateBackEnd() declaration in zlib.h +- Remember start when using gzdopen in the middle of a file +- Use internal off_t counters in gz* functions to properly handle seeks +- Perform more rigorous check for distance-too-far in inffast.c +- Add Z_BLOCK flush option to return from inflate at block boundary +- Set strm->data_type on return from inflate + - Indicate bits unused, if at block boundary, and if in last block +- Replace size_t with ptrdiff_t in crc32.c, and check for correct size +- Add condition so old NO_DEFLATE define still works for compatibility +- FAQ update regarding the Windows DLL [Truta] +- INDEX update: add qnx entry, remove aix entry [Truta] +- Install zlib.3 into mandir [Wilson] +- Move contrib/zlib_dll_FAQ.txt to win32/DLL_FAQ.txt; update [Truta] +- Adapt the zlib interface to the new DLL convention guidelines [Truta] +- Introduce ZLIB_WINAPI macro to allow the export of functions using + the WINAPI calling convention, for Visual Basic [Vollant, Truta] +- Update msdos and win32 scripts and makefiles [Truta] +- Export symbols by name, not by ordinal, in win32/zlib.def [Truta] +- Add contrib/ada [Anisimkov] +- Move asm files from contrib/vstudio/vc70_32 to contrib/asm386 [Truta] +- Rename contrib/asm386 to contrib/masmx86 [Truta, Vollant] +- Add contrib/masm686 [Truta] +- Fix offsets in contrib/inflate86 and contrib/masmx86/inffas32.asm + [Truta, Vollant] +- Update contrib/delphi; rename to contrib/pascal; add example [Truta] +- Remove contrib/delphi2; add a new contrib/delphi [Truta] +- Avoid inclusion of the nonstandard in contrib/iostream, + and fix some method prototypes [Truta] +- Fix the ZCR_SEED2 constant to avoid warnings in contrib/minizip + [Truta] +- Avoid the use of backslash (\) in contrib/minizip [Vollant] +- Fix file time handling in contrib/untgz; update makefiles [Truta] +- Update contrib/vstudio/vc70_32 to comply with the new DLL guidelines + [Vollant] +- Remove contrib/vstudio/vc15_16 [Vollant] +- Rename contrib/vstudio/vc70_32 to contrib/vstudio/vc7 [Truta] +- Update README.contrib [Truta] +- Invert the assignment order of match_head and s->prev[...] in + INSERT_STRING [Truta] +- Compare TOO_FAR with 32767 instead of 32768, to avoid 16-bit warnings + [Truta] +- Compare function pointers with 0, not with NULL or Z_NULL [Truta] +- Fix prototype of syncsearch in inflate.c [Truta] +- Introduce ASMINF macro to be enabled when using an ASM implementation + of inflate_fast [Truta] +- Change NO_DEFLATE to NO_GZCOMPRESS [Truta] +- Modify test_gzio in example.c to take a single file name as a + parameter [Truta] +- Exit the example.c program if gzopen fails [Truta] +- Add type casts around strlen in example.c [Truta] +- Remove casting to sizeof in minigzip.c; give a proper type + to the variable compared with SUFFIX_LEN [Truta] +- Update definitions of STDC and STDC99 in zconf.h [Truta] +- Synchronize zconf.h with the new Windows DLL interface [Truta] +- Use SYS16BIT instead of __32BIT__ to distinguish between + 16- and 32-bit platforms [Truta] +- Use far memory allocators in small 16-bit memory models for + Turbo C [Truta] +- Add info about the use of ASMV, ASMINF and ZLIB_WINAPI in + zlibCompileFlags [Truta] +- Cygwin has vsnprintf [Wilson] +- In Windows16, OS_CODE is 0, as in MSDOS [Truta] +- In Cygwin, OS_CODE is 3 (Unix), not 11 (Windows32) [Wilson] + +Changes in 1.2.0.4 (10 August 2003) +- Minor FAQ updates +- Be more strict when checking inflateInit2's windowBits parameter +- Change NO_GUNZIP compile option to NO_GZIP to cover deflate as well +- Add gzip wrapper option to deflateInit2 using windowBits +- Add updated QNX rule in configure and qnx directory [Bonnefoy] +- Make inflate distance-too-far checks more rigorous +- Clean up FAR usage in inflate +- Add casting to sizeof() in gzio.c and minigzip.c + +Changes in 1.2.0.3 (19 July 2003) +- Fix silly error in gzungetc() implementation [Vollant] +- Update contrib/minizip and contrib/vstudio [Vollant] +- Fix printf format in example.c +- Correct cdecl support in zconf.in.h [Anisimkov] +- Minor FAQ updates + +Changes in 1.2.0.2 (13 July 2003) +- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons +- Attempt to avoid warnings in crc32.c for pointer-int conversion +- Add AIX to configure, remove aix directory [Bakker] +- Add some casts to minigzip.c +- Improve checking after insecure sprintf() or vsprintf() calls +- Remove #elif's from crc32.c +- Change leave label to inf_leave in inflate.c and infback.c to avoid + library conflicts +- Remove inflate gzip decoding by default--only enable gzip decoding by + special request for stricter backward compatibility +- Add zlibCompileFlags() function to return compilation information +- More typecasting in deflate.c to avoid warnings +- Remove leading underscore from _Capital #defines [Truta] +- Fix configure to link shared library when testing +- Add some Windows CE target adjustments [Mai] +- Remove #define ZLIB_DLL in zconf.h [Vollant] +- Add zlib.3 [Rodgers] +- Update RFC URL in deflate.c and algorithm.txt [Mai] +- Add zlib_dll_FAQ.txt to contrib [Truta] +- Add UL to some constants [Truta] +- Update minizip and vstudio [Vollant] +- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h +- Expand use of NO_DUMMY_DECL to avoid all dummy structures +- Added iostream3 to contrib [Schwardt] +- Replace rewind() with fseek() for WinCE [Truta] +- Improve setting of zlib format compression level flags + - Report 0 for huffman and rle strategies and for level == 0 or 1 + - Report 2 only for level == 6 +- Only deal with 64K limit when necessary at compile time [Truta] +- Allow TOO_FAR check to be turned off at compile time [Truta] +- Add gzclearerr() function [Souza] +- Add gzungetc() function + +Changes in 1.2.0.1 (17 March 2003) +- Add Z_RLE strategy for run-length encoding [Truta] + - When Z_RLE requested, restrict matches to distance one + - Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE +- Correct FASTEST compilation to allow level == 0 +- Clean up what gets compiled for FASTEST +- Incorporate changes to zconf.in.h [Vollant] + - Refine detection of Turbo C need for dummy returns + - Refine ZLIB_DLL compilation + - Include additional header file on VMS for off_t typedef +- Try to use _vsnprintf where it supplants vsprintf [Vollant] +- Add some casts in inffast.c +- Enchance comments in zlib.h on what happens if gzprintf() tries to + write more than 4095 bytes before compression +- Remove unused state from inflateBackEnd() +- Remove exit(0) from minigzip.c, example.c +- Get rid of all those darn tabs +- Add "check" target to Makefile.in that does the same thing as "test" +- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in +- Update contrib/inflate86 [Anderson] +- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant] +- Add msdos and win32 directories with makefiles [Truta] +- More additions and improvements to the FAQ + +Changes in 1.2.0 (9 March 2003) +- New and improved inflate code + - About 20% faster + - Does not allocate 32K window unless and until needed + - Automatically detects and decompresses gzip streams + - Raw inflate no longer needs an extra dummy byte at end + - Added inflateBack functions using a callback interface--even faster + than inflate, useful for file utilities (gzip, zip) + - Added inflateCopy() function to record state for random access on + externally generated deflate streams (e.g. in gzip files) + - More readable code (I hope) +- New and improved crc32() + - About 50% faster, thanks to suggestions from Rodney Brown +- Add deflateBound() and compressBound() functions +- Fix memory leak in deflateInit2() +- Permit setting dictionary for raw deflate (for parallel deflate) +- Fix const declaration for gzwrite() +- Check for some malloc() failures in gzio.c +- Fix bug in gzopen() on single-byte file 0x1f +- Fix bug in gzread() on concatenated file with 0x1f at end of buffer + and next buffer doesn't start with 0x8b +- Fix uncompress() to return Z_DATA_ERROR on truncated input +- Free memory at end of example.c +- Remove MAX #define in trees.c (conflicted with some libraries) +- Fix static const's in deflate.c, gzio.c, and zutil.[ch] +- Declare malloc() and free() in gzio.c if STDC not defined +- Use malloc() instead of calloc() in zutil.c if int big enough +- Define STDC for AIX +- Add aix/ with approach for compiling shared library on AIX +- Add HP-UX support for shared libraries in configure +- Add OpenUNIX support for shared libraries in configure +- Use $cc instead of gcc to build shared library +- Make prefix directory if needed when installing +- Correct Macintosh avoidance of typedef Byte in zconf.h +- Correct Turbo C memory allocation when under Linux +- Use libz.a instead of -lz in Makefile (assure use of compiled library) +- Update configure to check for snprintf or vsnprintf functions and their + return value, warn during make if using an insecure function +- Fix configure problem with compile-time knowledge of HAVE_UNISTD_H that + is lost when library is used--resolution is to build new zconf.h +- Documentation improvements (in zlib.h): + - Document raw deflate and inflate + - Update RFCs URL + - Point out that zlib and gzip formats are different + - Note that Z_BUF_ERROR is not fatal + - Document string limit for gzprintf() and possible buffer overflow + - Note requirement on avail_out when flushing + - Note permitted values of flush parameter of inflate() +- Add some FAQs (and even answers) to the FAQ +- Add contrib/inflate86/ for x86 faster inflate +- Add contrib/blast/ for PKWare Data Compression Library decompression +- Add contrib/puff/ simple inflate for deflate format description + +Changes in 1.1.4 (11 March 2002) +- ZFREE was repeated on same allocation on some error conditions. + This creates a security problem described in + http://www.zlib.org/advisory-2002-03-11.txt +- Returned incorrect error (Z_MEM_ERROR) on some invalid data +- Avoid accesses before window for invalid distances with inflate window + less than 32K. +- force windowBits > 8 to avoid a bug in the encoder for a window size + of 256 bytes. (A complete fix will be available in 1.1.5). + +Changes in 1.1.3 (9 July 1998) +- fix "an inflate input buffer bug that shows up on rare but persistent + occasions" (Mark) +- fix gzread and gztell for concatenated .gz files (Didier Le Botlan) +- fix gzseek(..., SEEK_SET) in write mode +- fix crc check after a gzeek (Frank Faubert) +- fix miniunzip when the last entry in a zip file is itself a zip file + (J Lillge) +- add contrib/asm586 and contrib/asm686 (Brian Raiter) + See http://www.muppetlabs.com/~breadbox/software/assembly.html +- add support for Delphi 3 in contrib/delphi (Bob Dellaca) +- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti) +- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren) +- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks) +- added a FAQ file + +- Support gzdopen on Mac with Metrowerks (Jason Linhart) +- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart) +- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young) +- avoid some warnings with Borland C (Tom Tanner) +- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant) +- emulate utime() for WIN32 in contrib/untgz (Gilles Vollant) +- allow several arguments to configure (Tim Mooney, Frodo Looijaard) +- use libdir and includedir in Makefile.in (Tim Mooney) +- support shared libraries on OSF1 V4 (Tim Mooney) +- remove so_locations in "make clean" (Tim Mooney) +- fix maketree.c compilation error (Glenn, Mark) +- Python interface to zlib now in Python 1.5 (Jeremy Hylton) +- new Makefile.riscos (Rich Walker) +- initialize static descriptors in trees.c for embedded targets (Nick Smith) +- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith) +- add the OS/2 files in Makefile.in too (Andrew Zabolotny) +- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane) +- fix maketree.c to allow clean compilation of inffixed.h (Mark) +- fix parameter check in deflateCopy (Gunther Nikl) +- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler) +- Many portability patches by Christian Spieler: + . zutil.c, zutil.h: added "const" for zmem* + . Make_vms.com: fixed some typos + . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists + . msdos/Makefile.msc: remove "default rtl link library" info from obj files + . msdos/Makefile.*: use model-dependent name for the built zlib library + . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc: + new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT) +- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane) +- replace __far with _far for better portability (Christian Spieler, Tom Lane) +- fix test for errno.h in configure (Tim Newsham) + +Changes in 1.1.2 (19 March 98) +- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant) + See http://www.winimage.com/zLibDll/unzip.html +- preinitialize the inflate tables for fixed codes, to make the code + completely thread safe (Mark) +- some simplifications and slight speed-up to the inflate code (Mark) +- fix gzeof on non-compressed files (Allan Schrum) +- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs) +- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn) +- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny) +- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori) +- do not wrap extern "C" around system includes (Tom Lane) +- mention zlib binding for TCL in README (Andreas Kupries) +- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert) +- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson) +- allow "configure --prefix $HOME" (Tim Mooney) +- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson) +- move Makefile.sas to amiga/Makefile.sas + +Changes in 1.1.1 (27 Feb 98) +- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson) +- remove block truncation heuristic which had very marginal effect for zlib + (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the + compression ratio on some files. This also allows inlining _tr_tally for + matches in deflate_slow. +- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier) + +Changes in 1.1.0 (24 Feb 98) +- do not return STREAM_END prematurely in inflate (John Bowler) +- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler) +- compile with -DFASTEST to get compression code optimized for speed only +- in minigzip, try mmap'ing the input file first (Miguel Albrecht) +- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain + on Sun but significant on HP) + +- add a pointer to experimental unzip library in README (Gilles Vollant) +- initialize variable gcc in configure (Chris Herborth) + +Changes in 1.0.9 (17 Feb 1998) +- added gzputs and gzgets functions +- do not clear eof flag in gzseek (Mark Diekhans) +- fix gzseek for files in transparent mode (Mark Diekhans) +- do not assume that vsprintf returns the number of bytes written (Jens Krinke) +- replace EXPORT with ZEXPORT to avoid conflict with other programs +- added compress2 in zconf.h, zlib.def, zlib.dnt +- new asm code from Gilles Vollant in contrib/asm386 +- simplify the inflate code (Mark): + . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new() + . ZALLOC the length list in inflate_trees_fixed() instead of using stack + . ZALLOC the value area for huft_build() instead of using stack + . Simplify Z_FINISH check in inflate() + +- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8 +- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi) +- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with + the declaration of FAR (Gilles VOllant) +- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann) +- read_buf buf parameter of type Bytef* instead of charf* +- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout) +- do not redeclare unlink in minigzip.c for WIN32 (John Bowler) +- fix check for presence of directories in "make install" (Ian Willis) + +Changes in 1.0.8 (27 Jan 1998) +- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant) +- fix gzgetc and gzputc for big endian systems (Markus Oberhumer) +- added compress2() to allow setting the compression level +- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong) +- use constant arrays for the static trees in trees.c instead of computing + them at run time (thanks to Ken Raeburn for this suggestion). To create + trees.h, compile with GEN_TREES_H and run "make test". +- check return code of example in "make test" and display result +- pass minigzip command line options to file_compress +- simplifying code of inflateSync to avoid gcc 2.8 bug + +- support CC="gcc -Wall" in configure -s (QingLong) +- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn) +- fix test for shared library support to avoid compiler warnings +- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant) +- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit) +- do not use fdopen for Metrowerks on Mac (Brad Pettit)) +- add checks for gzputc and gzputc in example.c +- avoid warnings in gzio.c and deflate.c (Andreas Kleinert) +- use const for the CRC table (Ken Raeburn) +- fixed "make uninstall" for shared libraries +- use Tracev instead of Trace in infblock.c +- in example.c use correct compressed length for test_sync +- suppress +vnocompatwarnings in configure for HPUX (not always supported) + +Changes in 1.0.7 (20 Jan 1998) +- fix gzseek which was broken in write mode +- return error for gzseek to negative absolute position +- fix configure for Linux (Chun-Chung Chen) +- increase stack space for MSC (Tim Wegner) +- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant) +- define EXPORTVA for gzprintf (Gilles Vollant) +- added man page zlib.3 (Rick Rodgers) +- for contrib/untgz, fix makedir() and improve Makefile + +- check gzseek in write mode in example.c +- allocate extra buffer for seeks only if gzseek is actually called +- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant) +- add inflateSyncPoint in zconf.h +- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def + +Changes in 1.0.6 (19 Jan 1998) +- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and + gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code) +- Fix a deflate bug occurring only with compression level 0 (thanks to + Andy Buckler for finding this one). +- In minigzip, pass transparently also the first byte for .Z files. +- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress() +- check Z_FINISH in inflate (thanks to Marc Schluper) +- Implement deflateCopy (thanks to Adam Costello) +- make static libraries by default in configure, add --shared option. +- move MSDOS or Windows specific files to directory msdos +- suppress the notion of partial flush to simplify the interface + (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4) +- suppress history buffer provided by application to simplify the interface + (this feature was not implemented anyway in 1.0.4) +- next_in and avail_in must be initialized before calling inflateInit or + inflateInit2 +- add EXPORT in all exported functions (for Windows DLL) +- added Makefile.nt (thanks to Stephen Williams) +- added the unsupported "contrib" directory: + contrib/asm386/ by Gilles Vollant + 386 asm code replacing longest_match(). + contrib/iostream/ by Kevin Ruland + A C++ I/O streams interface to the zlib gz* functions + contrib/iostream2/ by Tyge Løvset + Another C++ I/O streams interface + contrib/untgz/ by "Pedro A. Aranda Guti\irrez" + A very simple tar.gz file extractor using zlib + contrib/visual-basic.txt by Carlos Rios + How to use compress(), uncompress() and the gz* functions from VB. +- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression + level) in minigzip (thanks to Tom Lane) + +- use const for rommable constants in deflate +- added test for gzseek and gztell in example.c +- add undocumented function inflateSyncPoint() (hack for Paul Mackerras) +- add undocumented function zError to convert error code to string + (for Tim Smithers) +- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code. +- Use default memcpy for Symantec MSDOS compiler. +- Add EXPORT keyword for check_func (needed for Windows DLL) +- add current directory to LD_LIBRARY_PATH for "make test" +- create also a link for libz.so.1 +- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura) +- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX) +- added -soname for Linux in configure (Chun-Chung Chen, +- assign numbers to the exported functions in zlib.def (for Windows DLL) +- add advice in zlib.h for best usage of deflateSetDictionary +- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn) +- allow compilation with ANSI keywords only enabled for TurboC in large model +- avoid "versionString"[0] (Borland bug) +- add NEED_DUMMY_RETURN for Borland +- use variable z_verbose for tracing in debug mode (L. Peter Deutsch). +- allow compilation with CC +- defined STDC for OS/2 (David Charlap) +- limit external names to 8 chars for MVS (Thomas Lund) +- in minigzip.c, use static buffers only for 16-bit systems +- fix suffix check for "minigzip -d foo.gz" +- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee) +- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau) +- added makelcc.bat for lcc-win32 (Tom St Denis) +- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe) +- Avoid expanded $Id: ChangeLog,v 1.7 2012/05/13 12:18:39 drolon Exp $. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion. +- check for unistd.h in configure (for off_t) +- remove useless check parameter in inflate_blocks_free +- avoid useless assignment of s->check to itself in inflate_blocks_new +- do not flush twice in gzclose (thanks to Ken Raeburn) +- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h +- use NO_ERRNO_H instead of enumeration of operating systems with errno.h +- work around buggy fclose on pipes for HP/UX +- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson) +- fix configure if CC is already equal to gcc + +Changes in 1.0.5 (3 Jan 98) +- Fix inflate to terminate gracefully when fed corrupted or invalid data +- Use const for rommable constants in inflate +- Eliminate memory leaks on error conditions in inflate +- Removed some vestigial code in inflate +- Update web address in README + +Changes in 1.0.4 (24 Jul 96) +- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF + bit, so the decompressor could decompress all the correct data but went + on to attempt decompressing extra garbage data. This affected minigzip too. +- zlibVersion and gzerror return const char* (needed for DLL) +- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno) +- use z_error only for DEBUG (avoid problem with DLLs) + +Changes in 1.0.3 (2 Jul 96) +- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS + small and medium models; this makes the library incompatible with previous + versions for these models. (No effect in large model or on other systems.) +- return OK instead of BUF_ERROR if previous deflate call returned with + avail_out as zero but there is nothing to do +- added memcmp for non STDC compilers +- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly) +- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO) +- better check for 16-bit mode MSC (avoids problem with Symantec) + +Changes in 1.0.2 (23 May 96) +- added Windows DLL support +- added a function zlibVersion (for the DLL support) +- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model) +- Bytef is define's instead of typedef'd only for Borland C +- avoid reading uninitialized memory in example.c +- mention in README that the zlib format is now RFC1950 +- updated Makefile.dj2 +- added algorithm.doc + +Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion] +- fix array overlay in deflate.c which sometimes caused bad compressed data +- fix inflate bug with empty stored block +- fix MSDOS medium model which was broken in 0.99 +- fix deflateParams() which could generated bad compressed data. +- Bytef is define'd instead of typedef'ed (work around Borland bug) +- added an INDEX file +- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32), + Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas) +- speed up adler32 for modern machines without auto-increment +- added -ansi for IRIX in configure +- static_init_done in trees.c is an int +- define unlink as delete for VMS +- fix configure for QNX +- add configure branch for SCO and HPUX +- avoid many warnings (unused variables, dead assignments, etc...) +- no fdopen for BeOS +- fix the Watcom fix for 32 bit mode (define FAR as empty) +- removed redefinition of Byte for MKWERKS +- work around an MWKERKS bug (incorrect merge of all .h files) + +Changes in 0.99 (27 Jan 96) +- allow preset dictionary shared between compressor and decompressor +- allow compression level 0 (no compression) +- add deflateParams in zlib.h: allow dynamic change of compression level + and compression strategy. +- test large buffers and deflateParams in example.c +- add optional "configure" to build zlib as a shared library +- suppress Makefile.qnx, use configure instead +- fixed deflate for 64-bit systems (detected on Cray) +- fixed inflate_blocks for 64-bit systems (detected on Alpha) +- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2) +- always return Z_BUF_ERROR when deflate() has nothing to do +- deflateInit and inflateInit are now macros to allow version checking +- prefix all global functions and types with z_ with -DZ_PREFIX +- make falloc completely reentrant (inftrees.c) +- fixed very unlikely race condition in ct_static_init +- free in reverse order of allocation to help memory manager +- use zlib-1.0/* instead of zlib/* inside the tar.gz +- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith + -Wconversion -Wstrict-prototypes -Wmissing-prototypes" +- allow gzread on concatenated .gz files +- deflateEnd now returns Z_DATA_ERROR if it was premature +- deflate is finally (?) fully deterministic (no matches beyond end of input) +- Document Z_SYNC_FLUSH +- add uninstall in Makefile +- Check for __cpluplus in zlib.h +- Better test in ct_align for partial flush +- avoid harmless warnings for Borland C++ +- initialize hash_head in deflate.c +- avoid warning on fdopen (gzio.c) for HP cc -Aa +- include stdlib.h for STDC compilers +- include errno.h for Cray +- ignore error if ranlib doesn't exist +- call ranlib twice for NeXTSTEP +- use exec_prefix instead of prefix for libz.a +- renamed ct_* as _tr_* to avoid conflict with applications +- clear z->msg in inflateInit2 before any error return +- initialize opaque in example.c, gzio.c, deflate.c and inflate.c +- fixed typo in zconf.h (_GNUC__ => __GNUC__) +- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode) +- fix typo in Make_vms.com (f$trnlnm -> f$getsyi) +- in fcalloc, normalize pointer if size > 65520 bytes +- don't use special fcalloc for 32 bit Borland C++ +- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc... +- use Z_BINARY instead of BINARY +- document that gzclose after gzdopen will close the file +- allow "a" as mode in gzopen. +- fix error checking in gzread +- allow skipping .gz extra-field on pipes +- added reference to Perl interface in README +- put the crc table in FAR data (I dislike more and more the medium model :) +- added get_crc_table +- added a dimension to all arrays (Borland C can't count). +- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast +- guard against multiple inclusion of *.h (for precompiled header on Mac) +- Watcom C pretends to be Microsoft C small model even in 32 bit mode. +- don't use unsized arrays to avoid silly warnings by Visual C++: + warning C4746: 'inflate_mask' : unsized array treated as '__far' + (what's wrong with far data in far model?). +- define enum out of inflate_blocks_state to allow compilation with C++ + +Changes in 0.95 (16 Aug 95) +- fix MSDOS small and medium model (now easier to adapt to any compiler) +- inlined send_bits +- fix the final (:-) bug for deflate with flush (output was correct but + not completely flushed in rare occasions). +- default window size is same for compression and decompression + (it's now sufficient to set MAX_WBITS in zconf.h). +- voidp -> voidpf and voidnp -> voidp (for consistency with other + typedefs and because voidnp was not near in large model). + +Changes in 0.94 (13 Aug 95) +- support MSDOS medium model +- fix deflate with flush (could sometimes generate bad output) +- fix deflateReset (zlib header was incorrectly suppressed) +- added support for VMS +- allow a compression level in gzopen() +- gzflush now calls fflush +- For deflate with flush, flush even if no more input is provided. +- rename libgz.a as libz.a +- avoid complex expression in infcodes.c triggering Turbo C bug +- work around a problem with gcc on Alpha (in INSERT_STRING) +- don't use inline functions (problem with some gcc versions) +- allow renaming of Byte, uInt, etc... with #define. +- avoid warning about (unused) pointer before start of array in deflate.c +- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c +- avoid reserved word 'new' in trees.c + +Changes in 0.93 (25 June 95) +- temporarily disable inline functions +- make deflate deterministic +- give enough lookahead for PARTIAL_FLUSH +- Set binary mode for stdin/stdout in minigzip.c for OS/2 +- don't even use signed char in inflate (not portable enough) +- fix inflate memory leak for segmented architectures + +Changes in 0.92 (3 May 95) +- don't assume that char is signed (problem on SGI) +- Clear bit buffer when starting a stored block +- no memcpy on Pyramid +- suppressed inftest.c +- optimized fill_window, put longest_match inline for gcc +- optimized inflate on stored blocks. +- untabify all sources to simplify patches + +Changes in 0.91 (2 May 95) +- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h +- Document the memory requirements in zconf.h +- added "make install" +- fix sync search logic in inflateSync +- deflate(Z_FULL_FLUSH) now works even if output buffer too short +- after inflateSync, don't scare people with just "lo world" +- added support for DJGPP + +Changes in 0.9 (1 May 95) +- don't assume that zalloc clears the allocated memory (the TurboC bug + was Mark's bug after all :) +- let again gzread copy uncompressed data unchanged (was working in 0.71) +- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented +- added a test of inflateSync in example.c +- moved MAX_WBITS to zconf.h because users might want to change that. +- document explicitly that zalloc(64K) on MSDOS must return a normalized + pointer (zero offset) +- added Makefiles for Microsoft C, Turbo C, Borland C++ +- faster crc32() + +Changes in 0.8 (29 April 95) +- added fast inflate (inffast.c) +- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this + is incompatible with previous versions of zlib which returned Z_OK. +- work around a TurboC compiler bug (bad code for b << 0, see infutil.h) + (actually that was not a compiler bug, see 0.81 above) +- gzread no longer reads one extra byte in certain cases +- In gzio destroy(), don't reference a freed structure +- avoid many warnings for MSDOS +- avoid the ERROR symbol which is used by MS Windows + +Changes in 0.71 (14 April 95) +- Fixed more MSDOS compilation problems :( There is still a bug with + TurboC large model. + +Changes in 0.7 (14 April 95) +- Added full inflate support. +- Simplified the crc32() interface. The pre- and post-conditioning + (one's complement) is now done inside crc32(). WARNING: this is + incompatible with previous versions; see zlib.h for the new usage. + +Changes in 0.61 (12 April 95) +- workaround for a bug in TurboC. example and minigzip now work on MSDOS. + +Changes in 0.6 (11 April 95) +- added minigzip.c +- added gzdopen to reopen a file descriptor as gzFile +- added transparent reading of non-gziped files in gzread. +- fixed bug in gzread (don't read crc as data) +- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose). +- don't allocate big arrays in the stack (for MSDOS) +- fix some MSDOS compilation problems + +Changes in 0.5: +- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but + not yet Z_FULL_FLUSH. +- support decompression but only in a single step (forced Z_FINISH) +- added opaque object for zalloc and zfree. +- added deflateReset and inflateReset +- added a variable zlib_version for consistency checking. +- renamed the 'filter' parameter of deflateInit2 as 'strategy'. + Added Z_FILTERED and Z_HUFFMAN_ONLY constants. + +Changes in 0.4: +- avoid "zip" everywhere, use zlib instead of ziplib. +- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush + if compression method == 8. +- added adler32 and crc32 +- renamed deflateOptions as deflateInit2, call one or the other but not both +- added the method parameter for deflateInit2. +- added inflateInit2 +- simplied considerably deflateInit and inflateInit by not supporting + user-provided history buffer. This is supported only in deflateInit2 + and inflateInit2. + +Changes in 0.3: +- prefix all macro names with Z_ +- use Z_FINISH instead of deflateEnd to finish compression. +- added Z_HUFFMAN_ONLY +- added gzerror() diff --git a/Source/ZLib/adler32.c b/Source/ZLib/adler32.c index 28f1919..49dee68 100644 --- a/Source/ZLib/adler32.c +++ b/Source/ZLib/adler32.c @@ -1,179 +1,179 @@ -/* adler32.c -- compute the Adler-32 checksum of a data stream - * Copyright (C) 1995-2011 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id: adler32.c,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ - -#include "zutil.h" - -#define local static - -local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); - -#define BASE 65521 /* largest prime smaller than 65536 */ -#define NMAX 5552 -/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ - -#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} -#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); -#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); -#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); -#define DO16(buf) DO8(buf,0); DO8(buf,8); - -/* use NO_DIVIDE if your processor does not do division in hardware -- - try it both ways to see which is faster */ -#ifdef NO_DIVIDE -/* note that this assumes BASE is 65521, where 65536 % 65521 == 15 - (thank you to John Reiser for pointing this out) */ -# define CHOP(a) \ - do { \ - unsigned long tmp = a >> 16; \ - a &= 0xffffUL; \ - a += (tmp << 4) - tmp; \ - } while (0) -# define MOD28(a) \ - do { \ - CHOP(a); \ - if (a >= BASE) a -= BASE; \ - } while (0) -# define MOD(a) \ - do { \ - CHOP(a); \ - MOD28(a); \ - } while (0) -# define MOD63(a) \ - do { /* this assumes a is not negative */ \ - z_off64_t tmp = a >> 32; \ - a &= 0xffffffffL; \ - a += (tmp << 8) - (tmp << 5) + tmp; \ - tmp = a >> 16; \ - a &= 0xffffL; \ - a += (tmp << 4) - tmp; \ - tmp = a >> 16; \ - a &= 0xffffL; \ - a += (tmp << 4) - tmp; \ - if (a >= BASE) a -= BASE; \ - } while (0) -#else -# define MOD(a) a %= BASE -# define MOD28(a) a %= BASE -# define MOD63(a) a %= BASE -#endif - -/* ========================================================================= */ -uLong ZEXPORT adler32(adler, buf, len) - uLong adler; - const Bytef *buf; - uInt len; -{ - unsigned long sum2; - unsigned n; - - /* split Adler-32 into component sums */ - sum2 = (adler >> 16) & 0xffff; - adler &= 0xffff; - - /* in case user likes doing a byte at a time, keep it fast */ - if (len == 1) { - adler += buf[0]; - if (adler >= BASE) - adler -= BASE; - sum2 += adler; - if (sum2 >= BASE) - sum2 -= BASE; - return adler | (sum2 << 16); - } - - /* initial Adler-32 value (deferred check for len == 1 speed) */ - if (buf == Z_NULL) - return 1L; - - /* in case short lengths are provided, keep it somewhat fast */ - if (len < 16) { - while (len--) { - adler += *buf++; - sum2 += adler; - } - if (adler >= BASE) - adler -= BASE; - MOD28(sum2); /* only added so many BASE's */ - return adler | (sum2 << 16); - } - - /* do length NMAX blocks -- requires just one modulo operation */ - while (len >= NMAX) { - len -= NMAX; - n = NMAX / 16; /* NMAX is divisible by 16 */ - do { - DO16(buf); /* 16 sums unrolled */ - buf += 16; - } while (--n); - MOD(adler); - MOD(sum2); - } - - /* do remaining bytes (less than NMAX, still just one modulo) */ - if (len) { /* avoid modulos if none remaining */ - while (len >= 16) { - len -= 16; - DO16(buf); - buf += 16; - } - while (len--) { - adler += *buf++; - sum2 += adler; - } - MOD(adler); - MOD(sum2); - } - - /* return recombined sums */ - return adler | (sum2 << 16); -} - -/* ========================================================================= */ -local uLong adler32_combine_(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ - unsigned long sum1; - unsigned long sum2; - unsigned rem; - - /* for negative len, return invalid adler32 as a clue for debugging */ - if (len2 < 0) - return 0xffffffffUL; - - /* the derivation of this formula is left as an exercise for the reader */ - MOD63(len2); /* assumes len2 >= 0 */ - rem = (unsigned)len2; - sum1 = adler1 & 0xffff; - sum2 = rem * sum1; - MOD(sum2); - sum1 += (adler2 & 0xffff) + BASE - 1; - sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; - if (sum1 >= BASE) sum1 -= BASE; - if (sum1 >= BASE) sum1 -= BASE; - if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); - if (sum2 >= BASE) sum2 -= BASE; - return sum1 | (sum2 << 16); -} - -/* ========================================================================= */ -uLong ZEXPORT adler32_combine(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off_t len2; -{ - return adler32_combine_(adler1, adler2, len2); -} - -uLong ZEXPORT adler32_combine64(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ - return adler32_combine_(adler1, adler2, len2); -} +/* adler32.c -- compute the Adler-32 checksum of a data stream + * Copyright (C) 1995-2011 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: adler32.c,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ + +#include "zutil.h" + +#define local static + +local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); + +#define BASE 65521 /* largest prime smaller than 65536 */ +#define NMAX 5552 +/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ + +#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} +#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); +#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); +#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); +#define DO16(buf) DO8(buf,0); DO8(buf,8); + +/* use NO_DIVIDE if your processor does not do division in hardware -- + try it both ways to see which is faster */ +#ifdef NO_DIVIDE +/* note that this assumes BASE is 65521, where 65536 % 65521 == 15 + (thank you to John Reiser for pointing this out) */ +# define CHOP(a) \ + do { \ + unsigned long tmp = a >> 16; \ + a &= 0xffffUL; \ + a += (tmp << 4) - tmp; \ + } while (0) +# define MOD28(a) \ + do { \ + CHOP(a); \ + if (a >= BASE) a -= BASE; \ + } while (0) +# define MOD(a) \ + do { \ + CHOP(a); \ + MOD28(a); \ + } while (0) +# define MOD63(a) \ + do { /* this assumes a is not negative */ \ + z_off64_t tmp = a >> 32; \ + a &= 0xffffffffL; \ + a += (tmp << 8) - (tmp << 5) + tmp; \ + tmp = a >> 16; \ + a &= 0xffffL; \ + a += (tmp << 4) - tmp; \ + tmp = a >> 16; \ + a &= 0xffffL; \ + a += (tmp << 4) - tmp; \ + if (a >= BASE) a -= BASE; \ + } while (0) +#else +# define MOD(a) a %= BASE +# define MOD28(a) a %= BASE +# define MOD63(a) a %= BASE +#endif + +/* ========================================================================= */ +uLong ZEXPORT adler32(adler, buf, len) + uLong adler; + const Bytef *buf; + uInt len; +{ + unsigned long sum2; + unsigned n; + + /* split Adler-32 into component sums */ + sum2 = (adler >> 16) & 0xffff; + adler &= 0xffff; + + /* in case user likes doing a byte at a time, keep it fast */ + if (len == 1) { + adler += buf[0]; + if (adler >= BASE) + adler -= BASE; + sum2 += adler; + if (sum2 >= BASE) + sum2 -= BASE; + return adler | (sum2 << 16); + } + + /* initial Adler-32 value (deferred check for len == 1 speed) */ + if (buf == Z_NULL) + return 1L; + + /* in case short lengths are provided, keep it somewhat fast */ + if (len < 16) { + while (len--) { + adler += *buf++; + sum2 += adler; + } + if (adler >= BASE) + adler -= BASE; + MOD28(sum2); /* only added so many BASE's */ + return adler | (sum2 << 16); + } + + /* do length NMAX blocks -- requires just one modulo operation */ + while (len >= NMAX) { + len -= NMAX; + n = NMAX / 16; /* NMAX is divisible by 16 */ + do { + DO16(buf); /* 16 sums unrolled */ + buf += 16; + } while (--n); + MOD(adler); + MOD(sum2); + } + + /* do remaining bytes (less than NMAX, still just one modulo) */ + if (len) { /* avoid modulos if none remaining */ + while (len >= 16) { + len -= 16; + DO16(buf); + buf += 16; + } + while (len--) { + adler += *buf++; + sum2 += adler; + } + MOD(adler); + MOD(sum2); + } + + /* return recombined sums */ + return adler | (sum2 << 16); +} + +/* ========================================================================= */ +local uLong adler32_combine_(adler1, adler2, len2) + uLong adler1; + uLong adler2; + z_off64_t len2; +{ + unsigned long sum1; + unsigned long sum2; + unsigned rem; + + /* for negative len, return invalid adler32 as a clue for debugging */ + if (len2 < 0) + return 0xffffffffUL; + + /* the derivation of this formula is left as an exercise for the reader */ + MOD63(len2); /* assumes len2 >= 0 */ + rem = (unsigned)len2; + sum1 = adler1 & 0xffff; + sum2 = rem * sum1; + MOD(sum2); + sum1 += (adler2 & 0xffff) + BASE - 1; + sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; + if (sum1 >= BASE) sum1 -= BASE; + if (sum1 >= BASE) sum1 -= BASE; + if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); + if (sum2 >= BASE) sum2 -= BASE; + return sum1 | (sum2 << 16); +} + +/* ========================================================================= */ +uLong ZEXPORT adler32_combine(adler1, adler2, len2) + uLong adler1; + uLong adler2; + z_off_t len2; +{ + return adler32_combine_(adler1, adler2, len2); +} + +uLong ZEXPORT adler32_combine64(adler1, adler2, len2) + uLong adler1; + uLong adler2; + z_off64_t len2; +{ + return adler32_combine_(adler1, adler2, len2); +} diff --git a/Source/ZLib/compress.c b/Source/ZLib/compress.c index 91dea5c..2ee86dd 100644 --- a/Source/ZLib/compress.c +++ b/Source/ZLib/compress.c @@ -1,80 +1,80 @@ -/* compress.c -- compress a memory buffer - * Copyright (C) 1995-2005 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id: compress.c,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ - -#define ZLIB_INTERNAL -#include "zlib.h" - -/* =========================================================================== - Compresses the source buffer into the destination buffer. The level - parameter has the same meaning as in deflateInit. sourceLen is the byte - length of the source buffer. Upon entry, destLen is the total size of the - destination buffer, which must be at least 0.1% larger than sourceLen plus - 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. - - compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_BUF_ERROR if there was not enough room in the output buffer, - Z_STREAM_ERROR if the level parameter is invalid. -*/ -int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; - int level; -{ - z_stream stream; - int err; - - stream.next_in = (Bytef*)source; - stream.avail_in = (uInt)sourceLen; -#ifdef MAXSEG_64K - /* Check for source > 64K on 16-bit machine: */ - if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; -#endif - stream.next_out = dest; - stream.avail_out = (uInt)*destLen; - if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; - - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; - stream.opaque = (voidpf)0; - - err = deflateInit(&stream, level); - if (err != Z_OK) return err; - - err = deflate(&stream, Z_FINISH); - if (err != Z_STREAM_END) { - deflateEnd(&stream); - return err == Z_OK ? Z_BUF_ERROR : err; - } - *destLen = stream.total_out; - - err = deflateEnd(&stream); - return err; -} - -/* =========================================================================== - */ -int ZEXPORT compress (dest, destLen, source, sourceLen) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; -{ - return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); -} - -/* =========================================================================== - If the default memLevel or windowBits for deflateInit() is changed, then - this function needs to be updated. - */ -uLong ZEXPORT compressBound (sourceLen) - uLong sourceLen; -{ - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + - (sourceLen >> 25) + 13; -} +/* compress.c -- compress a memory buffer + * Copyright (C) 1995-2005 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: compress.c,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ + +#define ZLIB_INTERNAL +#include "zlib.h" + +/* =========================================================================== + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least 0.1% larger than sourceLen plus + 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ +int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) + Bytef *dest; + uLongf *destLen; + const Bytef *source; + uLong sourceLen; + int level; +{ + z_stream stream; + int err; + + stream.next_in = (Bytef*)source; + stream.avail_in = (uInt)sourceLen; +#ifdef MAXSEG_64K + /* Check for source > 64K on 16-bit machine: */ + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; +#endif + stream.next_out = dest; + stream.avail_out = (uInt)*destLen; + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; + + stream.zalloc = (alloc_func)0; + stream.zfree = (free_func)0; + stream.opaque = (voidpf)0; + + err = deflateInit(&stream, level); + if (err != Z_OK) return err; + + err = deflate(&stream, Z_FINISH); + if (err != Z_STREAM_END) { + deflateEnd(&stream); + return err == Z_OK ? Z_BUF_ERROR : err; + } + *destLen = stream.total_out; + + err = deflateEnd(&stream); + return err; +} + +/* =========================================================================== + */ +int ZEXPORT compress (dest, destLen, source, sourceLen) + Bytef *dest; + uLongf *destLen; + const Bytef *source; + uLong sourceLen; +{ + return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); +} + +/* =========================================================================== + If the default memLevel or windowBits for deflateInit() is changed, then + this function needs to be updated. + */ +uLong ZEXPORT compressBound (sourceLen) + uLong sourceLen; +{ + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + + (sourceLen >> 25) + 13; +} diff --git a/Source/ZLib/crc32.c b/Source/ZLib/crc32.c index e2ed675..4e5df20 100644 --- a/Source/ZLib/crc32.c +++ b/Source/ZLib/crc32.c @@ -1,425 +1,425 @@ -/* crc32.c -- compute the CRC-32 of a data stream - * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - * - * Thanks to Rodney Brown for his contribution of faster - * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing - * tables for updating the shift register in one step with three exclusive-ors - * instead of four steps with four exclusive-ors. This results in about a - * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. - */ - -/* @(#) $Id: crc32.c,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ - -/* - Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore - protection on the static variables used to control the first-use generation - of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should - first call get_crc_table() to initialize the tables before allowing more than - one thread to use crc32(). - - DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h. - */ - -#ifdef MAKECRCH -# include -# ifndef DYNAMIC_CRC_TABLE -# define DYNAMIC_CRC_TABLE -# endif /* !DYNAMIC_CRC_TABLE */ -#endif /* MAKECRCH */ - -#include "zutil.h" /* for STDC and FAR definitions */ - -#define local static - -/* Definitions for doing the crc four data bytes at a time. */ -#if !defined(NOBYFOUR) && defined(Z_U4) -# define BYFOUR -#endif -#ifdef BYFOUR - local unsigned long crc32_little OF((unsigned long, - const unsigned char FAR *, unsigned)); - local unsigned long crc32_big OF((unsigned long, - const unsigned char FAR *, unsigned)); -# define TBLS 8 -#else -# define TBLS 1 -#endif /* BYFOUR */ - -/* Local functions for crc concatenation */ -local unsigned long gf2_matrix_times OF((unsigned long *mat, - unsigned long vec)); -local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); -local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2)); - - -#ifdef DYNAMIC_CRC_TABLE - -local volatile int crc_table_empty = 1; -local z_crc_t FAR crc_table[TBLS][256]; -local void make_crc_table OF((void)); -#ifdef MAKECRCH - local void write_table OF((FILE *, const z_crc_t FAR *)); -#endif /* MAKECRCH */ -/* - Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: - x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. - - Polynomials over GF(2) are represented in binary, one bit per coefficient, - with the lowest powers in the most significant bit. Then adding polynomials - is just exclusive-or, and multiplying a polynomial by x is a right shift by - one. If we call the above polynomial p, and represent a byte as the - polynomial q, also with the lowest power in the most significant bit (so the - byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, - where a mod b means the remainder after dividing a by b. - - This calculation is done using the shift-register method of multiplying and - taking the remainder. The register is initialized to zero, and for each - incoming bit, x^32 is added mod p to the register if the bit is a one (where - x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by - x (which is shifting right by one and adding x^32 mod p if the bit shifted - out is a one). We start with the highest power (least significant bit) of - q and repeat for all eight bits of q. - - The first table is simply the CRC of all possible eight bit values. This is - all the information needed to generate CRCs on data a byte at a time for all - combinations of CRC register values and incoming bytes. The remaining tables - allow for word-at-a-time CRC calculation for both big-endian and little- - endian machines, where a word is four bytes. -*/ -local void make_crc_table() -{ - z_crc_t c; - int n, k; - z_crc_t poly; /* polynomial exclusive-or pattern */ - /* terms of polynomial defining this crc (except x^32): */ - static volatile int first = 1; /* flag to limit concurrent making */ - static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; - - /* See if another task is already doing this (not thread-safe, but better - than nothing -- significantly reduces duration of vulnerability in - case the advice about DYNAMIC_CRC_TABLE is ignored) */ - if (first) { - first = 0; - - /* make exclusive-or pattern from polynomial (0xedb88320UL) */ - poly = 0; - for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++) - poly |= (z_crc_t)1 << (31 - p[n]); - - /* generate a crc for every 8-bit value */ - for (n = 0; n < 256; n++) { - c = (z_crc_t)n; - for (k = 0; k < 8; k++) - c = c & 1 ? poly ^ (c >> 1) : c >> 1; - crc_table[0][n] = c; - } - -#ifdef BYFOUR - /* generate crc for each value followed by one, two, and three zeros, - and then the byte reversal of those as well as the first table */ - for (n = 0; n < 256; n++) { - c = crc_table[0][n]; - crc_table[4][n] = ZSWAP32(c); - for (k = 1; k < 4; k++) { - c = crc_table[0][c & 0xff] ^ (c >> 8); - crc_table[k][n] = c; - crc_table[k + 4][n] = ZSWAP32(c); - } - } -#endif /* BYFOUR */ - - crc_table_empty = 0; - } - else { /* not first */ - /* wait for the other guy to finish (not efficient, but rare) */ - while (crc_table_empty) - ; - } - -#ifdef MAKECRCH - /* write out CRC tables to crc32.h */ - { - FILE *out; - - out = fopen("crc32.h", "w"); - if (out == NULL) return; - fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); - fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); - fprintf(out, "local const z_crc_t FAR "); - fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); - write_table(out, crc_table[0]); -# ifdef BYFOUR - fprintf(out, "#ifdef BYFOUR\n"); - for (k = 1; k < 8; k++) { - fprintf(out, " },\n {\n"); - write_table(out, crc_table[k]); - } - fprintf(out, "#endif\n"); -# endif /* BYFOUR */ - fprintf(out, " }\n};\n"); - fclose(out); - } -#endif /* MAKECRCH */ -} - -#ifdef MAKECRCH -local void write_table(out, table) - FILE *out; - const z_crc_t FAR *table; -{ - int n; - - for (n = 0; n < 256; n++) - fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", - (unsigned long)(table[n]), - n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); -} -#endif /* MAKECRCH */ - -#else /* !DYNAMIC_CRC_TABLE */ -/* ======================================================================== - * Tables of CRC-32s of all single-byte values, made by make_crc_table(). - */ -#include "crc32.h" -#endif /* DYNAMIC_CRC_TABLE */ - -/* ========================================================================= - * This function can be used by asm versions of crc32() - */ -const z_crc_t FAR * ZEXPORT get_crc_table() -{ -#ifdef DYNAMIC_CRC_TABLE - if (crc_table_empty) - make_crc_table(); -#endif /* DYNAMIC_CRC_TABLE */ - return (const z_crc_t FAR *)crc_table; -} - -/* ========================================================================= */ -#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) -#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 - -/* ========================================================================= */ -unsigned long ZEXPORT crc32(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - uInt len; -{ - if (buf == Z_NULL) return 0UL; - -#ifdef DYNAMIC_CRC_TABLE - if (crc_table_empty) - make_crc_table(); -#endif /* DYNAMIC_CRC_TABLE */ - -#ifdef BYFOUR - if (sizeof(void *) == sizeof(ptrdiff_t)) { - z_crc_t endian; - - endian = 1; - if (*((unsigned char *)(&endian))) - return crc32_little(crc, buf, len); - else - return crc32_big(crc, buf, len); - } -#endif /* BYFOUR */ - crc = crc ^ 0xffffffffUL; - while (len >= 8) { - DO8; - len -= 8; - } - if (len) do { - DO1; - } while (--len); - return crc ^ 0xffffffffUL; -} - -#ifdef BYFOUR - -/* ========================================================================= */ -#define DOLIT4 c ^= *buf4++; \ - c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ - crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] -#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 - -/* ========================================================================= */ -local unsigned long crc32_little(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - unsigned len; -{ - register z_crc_t c; - register const z_crc_t FAR *buf4; - - c = (z_crc_t)crc; - c = ~c; - while (len && ((ptrdiff_t)buf & 3)) { - c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); - len--; - } - - buf4 = (const z_crc_t FAR *)(const void FAR *)buf; - while (len >= 32) { - DOLIT32; - len -= 32; - } - while (len >= 4) { - DOLIT4; - len -= 4; - } - buf = (const unsigned char FAR *)buf4; - - if (len) do { - c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); - } while (--len); - c = ~c; - return (unsigned long)c; -} - -/* ========================================================================= */ -#define DOBIG4 c ^= *++buf4; \ - c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ - crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] -#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 - -/* ========================================================================= */ -local unsigned long crc32_big(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - unsigned len; -{ - register z_crc_t c; - register const z_crc_t FAR *buf4; - - c = ZSWAP32((z_crc_t)crc); - c = ~c; - while (len && ((ptrdiff_t)buf & 3)) { - c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); - len--; - } - - buf4 = (const z_crc_t FAR *)(const void FAR *)buf; - buf4--; - while (len >= 32) { - DOBIG32; - len -= 32; - } - while (len >= 4) { - DOBIG4; - len -= 4; - } - buf4++; - buf = (const unsigned char FAR *)buf4; - - if (len) do { - c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); - } while (--len); - c = ~c; - return (unsigned long)(ZSWAP32(c)); -} - -#endif /* BYFOUR */ - -#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ - -/* ========================================================================= */ -local unsigned long gf2_matrix_times(mat, vec) - unsigned long *mat; - unsigned long vec; -{ - unsigned long sum; - - sum = 0; - while (vec) { - if (vec & 1) - sum ^= *mat; - vec >>= 1; - mat++; - } - return sum; -} - -/* ========================================================================= */ -local void gf2_matrix_square(square, mat) - unsigned long *square; - unsigned long *mat; -{ - int n; - - for (n = 0; n < GF2_DIM; n++) - square[n] = gf2_matrix_times(mat, mat[n]); -} - -/* ========================================================================= */ -local uLong crc32_combine_(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off64_t len2; -{ - int n; - unsigned long row; - unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ - unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ - - /* degenerate case (also disallow negative lengths) */ - if (len2 <= 0) - return crc1; - - /* put operator for one zero bit in odd */ - odd[0] = 0xedb88320UL; /* CRC-32 polynomial */ - row = 1; - for (n = 1; n < GF2_DIM; n++) { - odd[n] = row; - row <<= 1; - } - - /* put operator for two zero bits in even */ - gf2_matrix_square(even, odd); - - /* put operator for four zero bits in odd */ - gf2_matrix_square(odd, even); - - /* apply len2 zeros to crc1 (first square will put the operator for one - zero byte, eight zero bits, in even) */ - do { - /* apply zeros operator for this bit of len2 */ - gf2_matrix_square(even, odd); - if (len2 & 1) - crc1 = gf2_matrix_times(even, crc1); - len2 >>= 1; - - /* if no more bits set, then done */ - if (len2 == 0) - break; - - /* another iteration of the loop with odd and even swapped */ - gf2_matrix_square(odd, even); - if (len2 & 1) - crc1 = gf2_matrix_times(odd, crc1); - len2 >>= 1; - - /* if no more bits set, then done */ - } while (len2 != 0); - - /* return combined crc */ - crc1 ^= crc2; - return crc1; -} - -/* ========================================================================= */ -uLong ZEXPORT crc32_combine(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off_t len2; -{ - return crc32_combine_(crc1, crc2, len2); -} - -uLong ZEXPORT crc32_combine64(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off64_t len2; -{ - return crc32_combine_(crc1, crc2, len2); -} +/* crc32.c -- compute the CRC-32 of a data stream + * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + * + * Thanks to Rodney Brown for his contribution of faster + * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing + * tables for updating the shift register in one step with three exclusive-ors + * instead of four steps with four exclusive-ors. This results in about a + * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. + */ + +/* @(#) $Id: crc32.c,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ + +/* + Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore + protection on the static variables used to control the first-use generation + of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should + first call get_crc_table() to initialize the tables before allowing more than + one thread to use crc32(). + + DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h. + */ + +#ifdef MAKECRCH +# include +# ifndef DYNAMIC_CRC_TABLE +# define DYNAMIC_CRC_TABLE +# endif /* !DYNAMIC_CRC_TABLE */ +#endif /* MAKECRCH */ + +#include "zutil.h" /* for STDC and FAR definitions */ + +#define local static + +/* Definitions for doing the crc four data bytes at a time. */ +#if !defined(NOBYFOUR) && defined(Z_U4) +# define BYFOUR +#endif +#ifdef BYFOUR + local unsigned long crc32_little OF((unsigned long, + const unsigned char FAR *, unsigned)); + local unsigned long crc32_big OF((unsigned long, + const unsigned char FAR *, unsigned)); +# define TBLS 8 +#else +# define TBLS 1 +#endif /* BYFOUR */ + +/* Local functions for crc concatenation */ +local unsigned long gf2_matrix_times OF((unsigned long *mat, + unsigned long vec)); +local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); +local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2)); + + +#ifdef DYNAMIC_CRC_TABLE + +local volatile int crc_table_empty = 1; +local z_crc_t FAR crc_table[TBLS][256]; +local void make_crc_table OF((void)); +#ifdef MAKECRCH + local void write_table OF((FILE *, const z_crc_t FAR *)); +#endif /* MAKECRCH */ +/* + Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: + x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. + + Polynomials over GF(2) are represented in binary, one bit per coefficient, + with the lowest powers in the most significant bit. Then adding polynomials + is just exclusive-or, and multiplying a polynomial by x is a right shift by + one. If we call the above polynomial p, and represent a byte as the + polynomial q, also with the lowest power in the most significant bit (so the + byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, + where a mod b means the remainder after dividing a by b. + + This calculation is done using the shift-register method of multiplying and + taking the remainder. The register is initialized to zero, and for each + incoming bit, x^32 is added mod p to the register if the bit is a one (where + x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by + x (which is shifting right by one and adding x^32 mod p if the bit shifted + out is a one). We start with the highest power (least significant bit) of + q and repeat for all eight bits of q. + + The first table is simply the CRC of all possible eight bit values. This is + all the information needed to generate CRCs on data a byte at a time for all + combinations of CRC register values and incoming bytes. The remaining tables + allow for word-at-a-time CRC calculation for both big-endian and little- + endian machines, where a word is four bytes. +*/ +local void make_crc_table() +{ + z_crc_t c; + int n, k; + z_crc_t poly; /* polynomial exclusive-or pattern */ + /* terms of polynomial defining this crc (except x^32): */ + static volatile int first = 1; /* flag to limit concurrent making */ + static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; + + /* See if another task is already doing this (not thread-safe, but better + than nothing -- significantly reduces duration of vulnerability in + case the advice about DYNAMIC_CRC_TABLE is ignored) */ + if (first) { + first = 0; + + /* make exclusive-or pattern from polynomial (0xedb88320UL) */ + poly = 0; + for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++) + poly |= (z_crc_t)1 << (31 - p[n]); + + /* generate a crc for every 8-bit value */ + for (n = 0; n < 256; n++) { + c = (z_crc_t)n; + for (k = 0; k < 8; k++) + c = c & 1 ? poly ^ (c >> 1) : c >> 1; + crc_table[0][n] = c; + } + +#ifdef BYFOUR + /* generate crc for each value followed by one, two, and three zeros, + and then the byte reversal of those as well as the first table */ + for (n = 0; n < 256; n++) { + c = crc_table[0][n]; + crc_table[4][n] = ZSWAP32(c); + for (k = 1; k < 4; k++) { + c = crc_table[0][c & 0xff] ^ (c >> 8); + crc_table[k][n] = c; + crc_table[k + 4][n] = ZSWAP32(c); + } + } +#endif /* BYFOUR */ + + crc_table_empty = 0; + } + else { /* not first */ + /* wait for the other guy to finish (not efficient, but rare) */ + while (crc_table_empty) + ; + } + +#ifdef MAKECRCH + /* write out CRC tables to crc32.h */ + { + FILE *out; + + out = fopen("crc32.h", "w"); + if (out == NULL) return; + fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); + fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); + fprintf(out, "local const z_crc_t FAR "); + fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); + write_table(out, crc_table[0]); +# ifdef BYFOUR + fprintf(out, "#ifdef BYFOUR\n"); + for (k = 1; k < 8; k++) { + fprintf(out, " },\n {\n"); + write_table(out, crc_table[k]); + } + fprintf(out, "#endif\n"); +# endif /* BYFOUR */ + fprintf(out, " }\n};\n"); + fclose(out); + } +#endif /* MAKECRCH */ +} + +#ifdef MAKECRCH +local void write_table(out, table) + FILE *out; + const z_crc_t FAR *table; +{ + int n; + + for (n = 0; n < 256; n++) + fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", + (unsigned long)(table[n]), + n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); +} +#endif /* MAKECRCH */ + +#else /* !DYNAMIC_CRC_TABLE */ +/* ======================================================================== + * Tables of CRC-32s of all single-byte values, made by make_crc_table(). + */ +#include "crc32.h" +#endif /* DYNAMIC_CRC_TABLE */ + +/* ========================================================================= + * This function can be used by asm versions of crc32() + */ +const z_crc_t FAR * ZEXPORT get_crc_table() +{ +#ifdef DYNAMIC_CRC_TABLE + if (crc_table_empty) + make_crc_table(); +#endif /* DYNAMIC_CRC_TABLE */ + return (const z_crc_t FAR *)crc_table; +} + +/* ========================================================================= */ +#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) +#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 + +/* ========================================================================= */ +unsigned long ZEXPORT crc32(crc, buf, len) + unsigned long crc; + const unsigned char FAR *buf; + uInt len; +{ + if (buf == Z_NULL) return 0UL; + +#ifdef DYNAMIC_CRC_TABLE + if (crc_table_empty) + make_crc_table(); +#endif /* DYNAMIC_CRC_TABLE */ + +#ifdef BYFOUR + if (sizeof(void *) == sizeof(ptrdiff_t)) { + z_crc_t endian; + + endian = 1; + if (*((unsigned char *)(&endian))) + return crc32_little(crc, buf, len); + else + return crc32_big(crc, buf, len); + } +#endif /* BYFOUR */ + crc = crc ^ 0xffffffffUL; + while (len >= 8) { + DO8; + len -= 8; + } + if (len) do { + DO1; + } while (--len); + return crc ^ 0xffffffffUL; +} + +#ifdef BYFOUR + +/* ========================================================================= */ +#define DOLIT4 c ^= *buf4++; \ + c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ + crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] +#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 + +/* ========================================================================= */ +local unsigned long crc32_little(crc, buf, len) + unsigned long crc; + const unsigned char FAR *buf; + unsigned len; +{ + register z_crc_t c; + register const z_crc_t FAR *buf4; + + c = (z_crc_t)crc; + c = ~c; + while (len && ((ptrdiff_t)buf & 3)) { + c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); + len--; + } + + buf4 = (const z_crc_t FAR *)(const void FAR *)buf; + while (len >= 32) { + DOLIT32; + len -= 32; + } + while (len >= 4) { + DOLIT4; + len -= 4; + } + buf = (const unsigned char FAR *)buf4; + + if (len) do { + c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); + } while (--len); + c = ~c; + return (unsigned long)c; +} + +/* ========================================================================= */ +#define DOBIG4 c ^= *++buf4; \ + c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ + crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] +#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 + +/* ========================================================================= */ +local unsigned long crc32_big(crc, buf, len) + unsigned long crc; + const unsigned char FAR *buf; + unsigned len; +{ + register z_crc_t c; + register const z_crc_t FAR *buf4; + + c = ZSWAP32((z_crc_t)crc); + c = ~c; + while (len && ((ptrdiff_t)buf & 3)) { + c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); + len--; + } + + buf4 = (const z_crc_t FAR *)(const void FAR *)buf; + buf4--; + while (len >= 32) { + DOBIG32; + len -= 32; + } + while (len >= 4) { + DOBIG4; + len -= 4; + } + buf4++; + buf = (const unsigned char FAR *)buf4; + + if (len) do { + c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); + } while (--len); + c = ~c; + return (unsigned long)(ZSWAP32(c)); +} + +#endif /* BYFOUR */ + +#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ + +/* ========================================================================= */ +local unsigned long gf2_matrix_times(mat, vec) + unsigned long *mat; + unsigned long vec; +{ + unsigned long sum; + + sum = 0; + while (vec) { + if (vec & 1) + sum ^= *mat; + vec >>= 1; + mat++; + } + return sum; +} + +/* ========================================================================= */ +local void gf2_matrix_square(square, mat) + unsigned long *square; + unsigned long *mat; +{ + int n; + + for (n = 0; n < GF2_DIM; n++) + square[n] = gf2_matrix_times(mat, mat[n]); +} + +/* ========================================================================= */ +local uLong crc32_combine_(crc1, crc2, len2) + uLong crc1; + uLong crc2; + z_off64_t len2; +{ + int n; + unsigned long row; + unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ + unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ + + /* degenerate case (also disallow negative lengths) */ + if (len2 <= 0) + return crc1; + + /* put operator for one zero bit in odd */ + odd[0] = 0xedb88320UL; /* CRC-32 polynomial */ + row = 1; + for (n = 1; n < GF2_DIM; n++) { + odd[n] = row; + row <<= 1; + } + + /* put operator for two zero bits in even */ + gf2_matrix_square(even, odd); + + /* put operator for four zero bits in odd */ + gf2_matrix_square(odd, even); + + /* apply len2 zeros to crc1 (first square will put the operator for one + zero byte, eight zero bits, in even) */ + do { + /* apply zeros operator for this bit of len2 */ + gf2_matrix_square(even, odd); + if (len2 & 1) + crc1 = gf2_matrix_times(even, crc1); + len2 >>= 1; + + /* if no more bits set, then done */ + if (len2 == 0) + break; + + /* another iteration of the loop with odd and even swapped */ + gf2_matrix_square(odd, even); + if (len2 & 1) + crc1 = gf2_matrix_times(odd, crc1); + len2 >>= 1; + + /* if no more bits set, then done */ + } while (len2 != 0); + + /* return combined crc */ + crc1 ^= crc2; + return crc1; +} + +/* ========================================================================= */ +uLong ZEXPORT crc32_combine(crc1, crc2, len2) + uLong crc1; + uLong crc2; + z_off_t len2; +{ + return crc32_combine_(crc1, crc2, len2); +} + +uLong ZEXPORT crc32_combine64(crc1, crc2, len2) + uLong crc1; + uLong crc2; + z_off64_t len2; +{ + return crc32_combine_(crc1, crc2, len2); +} diff --git a/Source/ZLib/deflate.c b/Source/ZLib/deflate.c index 3f3063d..7fa23b4 100644 --- a/Source/ZLib/deflate.c +++ b/Source/ZLib/deflate.c @@ -1,1965 +1,1965 @@ -/* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * ALGORITHM - * - * The "deflation" process depends on being able to identify portions - * of the input text which are identical to earlier input (within a - * sliding window trailing behind the input currently being processed). - * - * The most straightforward technique turns out to be the fastest for - * most input files: try all possible matches and select the longest. - * The key feature of this algorithm is that insertions into the string - * dictionary are very simple and thus fast, and deletions are avoided - * completely. Insertions are performed at each input character, whereas - * string matches are performed only when the previous match ends. So it - * is preferable to spend more time in matches to allow very fast string - * insertions and avoid deletions. The matching algorithm for small - * strings is inspired from that of Rabin & Karp. A brute force approach - * is used to find longer strings when a small match has been found. - * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze - * (by Leonid Broukhis). - * A previous version of this file used a more sophisticated algorithm - * (by Fiala and Greene) which is guaranteed to run in linear amortized - * time, but has a larger average cost, uses more memory and is patented. - * However the F&G algorithm may be faster for some highly redundant - * files if the parameter max_chain_length (described below) is too large. - * - * ACKNOWLEDGEMENTS - * - * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and - * I found it in 'freeze' written by Leonid Broukhis. - * Thanks to many people for bug reports and testing. - * - * REFERENCES - * - * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". - * Available in http://tools.ietf.org/html/rfc1951 - * - * A description of the Rabin and Karp algorithm is given in the book - * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. - * - * Fiala,E.R., and Greene,D.H. - * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 - * - */ - -/* @(#) $Id: deflate.c,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ - -#include "deflate.h" - -const char deflate_copyright[] = - " deflate 1.2.7 Copyright 1995-2012 Jean-loup Gailly and Mark Adler "; -/* - If you use the zlib library in a product, an acknowledgment is welcome - in the documentation of your product. If for some reason you cannot - include such an acknowledgment, I would appreciate that you keep this - copyright string in the executable of your product. - */ - -/* =========================================================================== - * Function prototypes. - */ -typedef enum { - need_more, /* block not completed, need more input or more output */ - block_done, /* block flush performed */ - finish_started, /* finish started, need only more output at next deflate */ - finish_done /* finish done, accept no more input or output */ -} block_state; - -typedef block_state (*compress_func) OF((deflate_state *s, int flush)); -/* Compression function. Returns the block state after the call. */ - -local void fill_window OF((deflate_state *s)); -local block_state deflate_stored OF((deflate_state *s, int flush)); -local block_state deflate_fast OF((deflate_state *s, int flush)); -#ifndef FASTEST -local block_state deflate_slow OF((deflate_state *s, int flush)); -#endif -local block_state deflate_rle OF((deflate_state *s, int flush)); -local block_state deflate_huff OF((deflate_state *s, int flush)); -local void lm_init OF((deflate_state *s)); -local void putShortMSB OF((deflate_state *s, uInt b)); -local void flush_pending OF((z_streamp strm)); -local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); -#ifdef ASMV - void match_init OF((void)); /* asm code initialization */ - uInt longest_match OF((deflate_state *s, IPos cur_match)); -#else -local uInt longest_match OF((deflate_state *s, IPos cur_match)); -#endif - -#ifdef DEBUG -local void check_match OF((deflate_state *s, IPos start, IPos match, - int length)); -#endif - -/* =========================================================================== - * Local data - */ - -#define NIL 0 -/* Tail of hash chains */ - -#ifndef TOO_FAR -# define TOO_FAR 4096 -#endif -/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ - -/* Values for max_lazy_match, good_match and max_chain_length, depending on - * the desired pack level (0..9). The values given below have been tuned to - * exclude worst case performance for pathological files. Better values may be - * found for specific files. - */ -typedef struct config_s { - ush good_length; /* reduce lazy search above this match length */ - ush max_lazy; /* do not perform lazy search above this match length */ - ush nice_length; /* quit search above this match length */ - ush max_chain; - compress_func func; -} config; - -#ifdef FASTEST -local const config configuration_table[2] = { -/* good lazy nice chain */ -/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ -/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */ -#else -local const config configuration_table[10] = { -/* good lazy nice chain */ -/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ -/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */ -/* 2 */ {4, 5, 16, 8, deflate_fast}, -/* 3 */ {4, 6, 32, 32, deflate_fast}, - -/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ -/* 5 */ {8, 16, 32, 32, deflate_slow}, -/* 6 */ {8, 16, 128, 128, deflate_slow}, -/* 7 */ {8, 32, 128, 256, deflate_slow}, -/* 8 */ {32, 128, 258, 1024, deflate_slow}, -/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */ -#endif - -/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 - * For deflate_fast() (levels <= 3) good is ignored and lazy has a different - * meaning. - */ - -#define EQUAL 0 -/* result of memcmp for equal strings */ - -#ifndef NO_DUMMY_DECL -struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ -#endif - -/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */ -#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0)) - -/* =========================================================================== - * Update a hash value with the given input byte - * IN assertion: all calls to to UPDATE_HASH are made with consecutive - * input characters, so that a running hash key can be computed from the - * previous key instead of complete recalculation each time. - */ -#define UPDATE_HASH(s,h,c) (h = (((h)<hash_shift) ^ (c)) & s->hash_mask) - - -/* =========================================================================== - * Insert string str in the dictionary and set match_head to the previous head - * of the hash chain (the most recent string with same hash key). Return - * the previous length of the hash chain. - * If this file is compiled with -DFASTEST, the compression level is forced - * to 1, and no hash chains are maintained. - * IN assertion: all calls to to INSERT_STRING are made with consecutive - * input characters and the first MIN_MATCH bytes of str are valid - * (except for the last MIN_MATCH-1 bytes of the input file). - */ -#ifdef FASTEST -#define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) -#else -#define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) -#endif - -/* =========================================================================== - * Initialize the hash table (avoiding 64K overflow for 16 bit systems). - * prev[] will be initialized on the fly. - */ -#define CLEAR_HASH(s) \ - s->head[s->hash_size-1] = NIL; \ - zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); - -/* ========================================================================= */ -int ZEXPORT deflateInit_(strm, level, version, stream_size) - z_streamp strm; - int level; - const char *version; - int stream_size; -{ - return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, version, stream_size); - /* To do: ignore strm->next_in if we use it as window */ -} - -/* ========================================================================= */ -int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, - version, stream_size) - z_streamp strm; - int level; - int method; - int windowBits; - int memLevel; - int strategy; - const char *version; - int stream_size; -{ - deflate_state *s; - int wrap = 1; - static const char my_version[] = ZLIB_VERSION; - - ushf *overlay; - /* We overlay pending_buf and d_buf+l_buf. This works since the average - * output size for (length,distance) codes is <= 24 bits. - */ - - if (version == Z_NULL || version[0] != my_version[0] || - stream_size != sizeof(z_stream)) { - return Z_VERSION_ERROR; - } - if (strm == Z_NULL) return Z_STREAM_ERROR; - - strm->msg = Z_NULL; - if (strm->zalloc == (alloc_func)0) { -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; -#endif - } - if (strm->zfree == (free_func)0) -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zfree = zcfree; -#endif - -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif - - if (windowBits < 0) { /* suppress zlib wrapper */ - wrap = 0; - windowBits = -windowBits; - } -#ifdef GZIP - else if (windowBits > 15) { - wrap = 2; /* write gzip wrapper instead */ - windowBits -= 16; - } -#endif - if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || - windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || - strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; - } - if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ - s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); - if (s == Z_NULL) return Z_MEM_ERROR; - strm->state = (struct internal_state FAR *)s; - s->strm = strm; - - s->wrap = wrap; - s->gzhead = Z_NULL; - s->w_bits = windowBits; - s->w_size = 1 << s->w_bits; - s->w_mask = s->w_size - 1; - - s->hash_bits = memLevel + 7; - s->hash_size = 1 << s->hash_bits; - s->hash_mask = s->hash_size - 1; - s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); - - s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); - s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); - s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); - - s->high_water = 0; /* nothing written to s->window yet */ - - s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ - - overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); - s->pending_buf = (uchf *) overlay; - s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); - - if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || - s->pending_buf == Z_NULL) { - s->status = FINISH_STATE; - strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); - deflateEnd (strm); - return Z_MEM_ERROR; - } - s->d_buf = overlay + s->lit_bufsize/sizeof(ush); - s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; - - s->level = level; - s->strategy = strategy; - s->method = (Byte)method; - - return deflateReset(strm); -} - -/* ========================================================================= */ -int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) - z_streamp strm; - const Bytef *dictionary; - uInt dictLength; -{ - deflate_state *s; - uInt str, n; - int wrap; - unsigned avail; - unsigned char *next; - - if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL) - return Z_STREAM_ERROR; - s = strm->state; - wrap = s->wrap; - if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead) - return Z_STREAM_ERROR; - - /* when using zlib wrappers, compute Adler-32 for provided dictionary */ - if (wrap == 1) - strm->adler = adler32(strm->adler, dictionary, dictLength); - s->wrap = 0; /* avoid computing Adler-32 in read_buf */ - - /* if dictionary would fill window, just replace the history */ - if (dictLength >= s->w_size) { - if (wrap == 0) { /* already empty otherwise */ - CLEAR_HASH(s); - s->strstart = 0; - s->block_start = 0L; - s->insert = 0; - } - dictionary += dictLength - s->w_size; /* use the tail */ - dictLength = s->w_size; - } - - /* insert dictionary into window and hash */ - avail = strm->avail_in; - next = strm->next_in; - strm->avail_in = dictLength; - strm->next_in = (Bytef *)dictionary; - fill_window(s); - while (s->lookahead >= MIN_MATCH) { - str = s->strstart; - n = s->lookahead - (MIN_MATCH-1); - do { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - } while (--n); - s->strstart = str; - s->lookahead = MIN_MATCH-1; - fill_window(s); - } - s->strstart += s->lookahead; - s->block_start = (long)s->strstart; - s->insert = s->lookahead; - s->lookahead = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - strm->next_in = next; - strm->avail_in = avail; - s->wrap = wrap; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateResetKeep (strm) - z_streamp strm; -{ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL || - strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) { - return Z_STREAM_ERROR; - } - - strm->total_in = strm->total_out = 0; - strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ - strm->data_type = Z_UNKNOWN; - - s = (deflate_state *)strm->state; - s->pending = 0; - s->pending_out = s->pending_buf; - - if (s->wrap < 0) { - s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ - } - s->status = s->wrap ? INIT_STATE : BUSY_STATE; - strm->adler = -#ifdef GZIP - s->wrap == 2 ? crc32(0L, Z_NULL, 0) : -#endif - adler32(0L, Z_NULL, 0); - s->last_flush = Z_NO_FLUSH; - - _tr_init(s); - - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateReset (strm) - z_streamp strm; -{ - int ret; - - ret = deflateResetKeep(strm); - if (ret == Z_OK) - lm_init(strm->state); - return ret; -} - -/* ========================================================================= */ -int ZEXPORT deflateSetHeader (strm, head) - z_streamp strm; - gz_headerp head; -{ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - if (strm->state->wrap != 2) return Z_STREAM_ERROR; - strm->state->gzhead = head; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflatePending (strm, pending, bits) - unsigned *pending; - int *bits; - z_streamp strm; -{ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - if (pending != Z_NULL) - *pending = strm->state->pending; - if (bits != Z_NULL) - *bits = strm->state->bi_valid; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflatePrime (strm, bits, value) - z_streamp strm; - int bits; - int value; -{ - deflate_state *s; - int put; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3)) - return Z_BUF_ERROR; - do { - put = Buf_size - s->bi_valid; - if (put > bits) - put = bits; - s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid); - s->bi_valid += put; - _tr_flush_bits(s); - value >>= put; - bits -= put; - } while (bits); - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateParams(strm, level, strategy) - z_streamp strm; - int level; - int strategy; -{ - deflate_state *s; - compress_func func; - int err = Z_OK; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif - if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; - } - func = configuration_table[s->level].func; - - if ((strategy != s->strategy || func != configuration_table[level].func) && - strm->total_in != 0) { - /* Flush the last buffer: */ - err = deflate(strm, Z_BLOCK); - } - if (s->level != level) { - s->level = level; - s->max_lazy_match = configuration_table[level].max_lazy; - s->good_match = configuration_table[level].good_length; - s->nice_match = configuration_table[level].nice_length; - s->max_chain_length = configuration_table[level].max_chain; - } - s->strategy = strategy; - return err; -} - -/* ========================================================================= */ -int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) - z_streamp strm; - int good_length; - int max_lazy; - int nice_length; - int max_chain; -{ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - s->good_match = good_length; - s->max_lazy_match = max_lazy; - s->nice_match = nice_length; - s->max_chain_length = max_chain; - return Z_OK; -} - -/* ========================================================================= - * For the default windowBits of 15 and memLevel of 8, this function returns - * a close to exact, as well as small, upper bound on the compressed size. - * They are coded as constants here for a reason--if the #define's are - * changed, then this function needs to be changed as well. The return - * value for 15 and 8 only works for those exact settings. - * - * For any setting other than those defaults for windowBits and memLevel, - * the value returned is a conservative worst case for the maximum expansion - * resulting from using fixed blocks instead of stored blocks, which deflate - * can emit on compressed data for some combinations of the parameters. - * - * This function could be more sophisticated to provide closer upper bounds for - * every combination of windowBits and memLevel. But even the conservative - * upper bound of about 14% expansion does not seem onerous for output buffer - * allocation. - */ -uLong ZEXPORT deflateBound(strm, sourceLen) - z_streamp strm; - uLong sourceLen; -{ - deflate_state *s; - uLong complen, wraplen; - Bytef *str; - - /* conservative upper bound for compressed data */ - complen = sourceLen + - ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; - - /* if can't get parameters, return conservative bound plus zlib wrapper */ - if (strm == Z_NULL || strm->state == Z_NULL) - return complen + 6; - - /* compute wrapper length */ - s = strm->state; - switch (s->wrap) { - case 0: /* raw deflate */ - wraplen = 0; - break; - case 1: /* zlib wrapper */ - wraplen = 6 + (s->strstart ? 4 : 0); - break; - case 2: /* gzip wrapper */ - wraplen = 18; - if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ - if (s->gzhead->extra != Z_NULL) - wraplen += 2 + s->gzhead->extra_len; - str = s->gzhead->name; - if (str != Z_NULL) - do { - wraplen++; - } while (*str++); - str = s->gzhead->comment; - if (str != Z_NULL) - do { - wraplen++; - } while (*str++); - if (s->gzhead->hcrc) - wraplen += 2; - } - break; - default: /* for compiler happiness */ - wraplen = 6; - } - - /* if not default parameters, return conservative bound */ - if (s->w_bits != 15 || s->hash_bits != 8 + 7) - return complen + wraplen; - - /* default settings: return tight bound for that case */ - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + - (sourceLen >> 25) + 13 - 6 + wraplen; -} - -/* ========================================================================= - * Put a short in the pending buffer. The 16-bit value is put in MSB order. - * IN assertion: the stream state is correct and there is enough room in - * pending_buf. - */ -local void putShortMSB (s, b) - deflate_state *s; - uInt b; -{ - put_byte(s, (Byte)(b >> 8)); - put_byte(s, (Byte)(b & 0xff)); -} - -/* ========================================================================= - * Flush as much pending output as possible. All deflate() output goes - * through this function so some applications may wish to modify it - * to avoid allocating a large strm->next_out buffer and copying into it. - * (See also read_buf()). - */ -local void flush_pending(strm) - z_streamp strm; -{ - unsigned len; - deflate_state *s = strm->state; - - _tr_flush_bits(s); - len = s->pending; - if (len > strm->avail_out) len = strm->avail_out; - if (len == 0) return; - - zmemcpy(strm->next_out, s->pending_out, len); - strm->next_out += len; - s->pending_out += len; - strm->total_out += len; - strm->avail_out -= len; - s->pending -= len; - if (s->pending == 0) { - s->pending_out = s->pending_buf; - } -} - -/* ========================================================================= */ -int ZEXPORT deflate (strm, flush) - z_streamp strm; - int flush; -{ - int old_flush; /* value of flush param for previous deflate call */ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL || - flush > Z_BLOCK || flush < 0) { - return Z_STREAM_ERROR; - } - s = strm->state; - - if (strm->next_out == Z_NULL || - (strm->next_in == Z_NULL && strm->avail_in != 0) || - (s->status == FINISH_STATE && flush != Z_FINISH)) { - ERR_RETURN(strm, Z_STREAM_ERROR); - } - if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); - - s->strm = strm; /* just in case */ - old_flush = s->last_flush; - s->last_flush = flush; - - /* Write the header */ - if (s->status == INIT_STATE) { -#ifdef GZIP - if (s->wrap == 2) { - strm->adler = crc32(0L, Z_NULL, 0); - put_byte(s, 31); - put_byte(s, 139); - put_byte(s, 8); - if (s->gzhead == Z_NULL) { - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, s->level == 9 ? 2 : - (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? - 4 : 0)); - put_byte(s, OS_CODE); - s->status = BUSY_STATE; - } - else { - put_byte(s, (s->gzhead->text ? 1 : 0) + - (s->gzhead->hcrc ? 2 : 0) + - (s->gzhead->extra == Z_NULL ? 0 : 4) + - (s->gzhead->name == Z_NULL ? 0 : 8) + - (s->gzhead->comment == Z_NULL ? 0 : 16) - ); - put_byte(s, (Byte)(s->gzhead->time & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); - put_byte(s, s->level == 9 ? 2 : - (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? - 4 : 0)); - put_byte(s, s->gzhead->os & 0xff); - if (s->gzhead->extra != Z_NULL) { - put_byte(s, s->gzhead->extra_len & 0xff); - put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); - } - if (s->gzhead->hcrc) - strm->adler = crc32(strm->adler, s->pending_buf, - s->pending); - s->gzindex = 0; - s->status = EXTRA_STATE; - } - } - else -#endif - { - uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; - uInt level_flags; - - if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) - level_flags = 0; - else if (s->level < 6) - level_flags = 1; - else if (s->level == 6) - level_flags = 2; - else - level_flags = 3; - header |= (level_flags << 6); - if (s->strstart != 0) header |= PRESET_DICT; - header += 31 - (header % 31); - - s->status = BUSY_STATE; - putShortMSB(s, header); - - /* Save the adler32 of the preset dictionary: */ - if (s->strstart != 0) { - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - } - strm->adler = adler32(0L, Z_NULL, 0); - } - } -#ifdef GZIP - if (s->status == EXTRA_STATE) { - if (s->gzhead->extra != Z_NULL) { - uInt beg = s->pending; /* start of bytes to update crc */ - - while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { - if (s->pending == s->pending_buf_size) { - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - flush_pending(strm); - beg = s->pending; - if (s->pending == s->pending_buf_size) - break; - } - put_byte(s, s->gzhead->extra[s->gzindex]); - s->gzindex++; - } - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - if (s->gzindex == s->gzhead->extra_len) { - s->gzindex = 0; - s->status = NAME_STATE; - } - } - else - s->status = NAME_STATE; - } - if (s->status == NAME_STATE) { - if (s->gzhead->name != Z_NULL) { - uInt beg = s->pending; /* start of bytes to update crc */ - int val; - - do { - if (s->pending == s->pending_buf_size) { - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - flush_pending(strm); - beg = s->pending; - if (s->pending == s->pending_buf_size) { - val = 1; - break; - } - } - val = s->gzhead->name[s->gzindex++]; - put_byte(s, val); - } while (val != 0); - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - if (val == 0) { - s->gzindex = 0; - s->status = COMMENT_STATE; - } - } - else - s->status = COMMENT_STATE; - } - if (s->status == COMMENT_STATE) { - if (s->gzhead->comment != Z_NULL) { - uInt beg = s->pending; /* start of bytes to update crc */ - int val; - - do { - if (s->pending == s->pending_buf_size) { - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - flush_pending(strm); - beg = s->pending; - if (s->pending == s->pending_buf_size) { - val = 1; - break; - } - } - val = s->gzhead->comment[s->gzindex++]; - put_byte(s, val); - } while (val != 0); - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - if (val == 0) - s->status = HCRC_STATE; - } - else - s->status = HCRC_STATE; - } - if (s->status == HCRC_STATE) { - if (s->gzhead->hcrc) { - if (s->pending + 2 > s->pending_buf_size) - flush_pending(strm); - if (s->pending + 2 <= s->pending_buf_size) { - put_byte(s, (Byte)(strm->adler & 0xff)); - put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); - strm->adler = crc32(0L, Z_NULL, 0); - s->status = BUSY_STATE; - } - } - else - s->status = BUSY_STATE; - } -#endif - - /* Flush as much pending output as possible */ - if (s->pending != 0) { - flush_pending(strm); - if (strm->avail_out == 0) { - /* Since avail_out is 0, deflate will be called again with - * more output space, but possibly with both pending and - * avail_in equal to zero. There won't be anything to do, - * but this is not an error situation so make sure we - * return OK instead of BUF_ERROR at next call of deflate: - */ - s->last_flush = -1; - return Z_OK; - } - - /* Make sure there is something to do and avoid duplicate consecutive - * flushes. For repeated and useless calls with Z_FINISH, we keep - * returning Z_STREAM_END instead of Z_BUF_ERROR. - */ - } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) && - flush != Z_FINISH) { - ERR_RETURN(strm, Z_BUF_ERROR); - } - - /* User must not provide more input after the first FINISH: */ - if (s->status == FINISH_STATE && strm->avail_in != 0) { - ERR_RETURN(strm, Z_BUF_ERROR); - } - - /* Start a new block or continue the current one. - */ - if (strm->avail_in != 0 || s->lookahead != 0 || - (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { - block_state bstate; - - bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : - (s->strategy == Z_RLE ? deflate_rle(s, flush) : - (*(configuration_table[s->level].func))(s, flush)); - - if (bstate == finish_started || bstate == finish_done) { - s->status = FINISH_STATE; - } - if (bstate == need_more || bstate == finish_started) { - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ - } - return Z_OK; - /* If flush != Z_NO_FLUSH && avail_out == 0, the next call - * of deflate should use the same flush parameter to make sure - * that the flush is complete. So we don't have to output an - * empty block here, this will be done at next call. This also - * ensures that for a very small output buffer, we emit at most - * one empty block. - */ - } - if (bstate == block_done) { - if (flush == Z_PARTIAL_FLUSH) { - _tr_align(s); - } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ - _tr_stored_block(s, (char*)0, 0L, 0); - /* For a full flush, this empty block will be recognized - * as a special marker by inflate_sync(). - */ - if (flush == Z_FULL_FLUSH) { - CLEAR_HASH(s); /* forget history */ - if (s->lookahead == 0) { - s->strstart = 0; - s->block_start = 0L; - s->insert = 0; - } - } - } - flush_pending(strm); - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ - return Z_OK; - } - } - } - Assert(strm->avail_out > 0, "bug2"); - - if (flush != Z_FINISH) return Z_OK; - if (s->wrap <= 0) return Z_STREAM_END; - - /* Write the trailer */ -#ifdef GZIP - if (s->wrap == 2) { - put_byte(s, (Byte)(strm->adler & 0xff)); - put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); - put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); - put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); - put_byte(s, (Byte)(strm->total_in & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); - } - else -#endif - { - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - } - flush_pending(strm); - /* If avail_out is zero, the application will call deflate again - * to flush the rest. - */ - if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ - return s->pending != 0 ? Z_OK : Z_STREAM_END; -} - -/* ========================================================================= */ -int ZEXPORT deflateEnd (strm) - z_streamp strm; -{ - int status; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - - status = strm->state->status; - if (status != INIT_STATE && - status != EXTRA_STATE && - status != NAME_STATE && - status != COMMENT_STATE && - status != HCRC_STATE && - status != BUSY_STATE && - status != FINISH_STATE) { - return Z_STREAM_ERROR; - } - - /* Deallocate in reverse order of allocations: */ - TRY_FREE(strm, strm->state->pending_buf); - TRY_FREE(strm, strm->state->head); - TRY_FREE(strm, strm->state->prev); - TRY_FREE(strm, strm->state->window); - - ZFREE(strm, strm->state); - strm->state = Z_NULL; - - return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; -} - -/* ========================================================================= - * Copy the source state to the destination state. - * To simplify the source, this is not supported for 16-bit MSDOS (which - * doesn't have enough memory anyway to duplicate compression states). - */ -int ZEXPORT deflateCopy (dest, source) - z_streamp dest; - z_streamp source; -{ -#ifdef MAXSEG_64K - return Z_STREAM_ERROR; -#else - deflate_state *ds; - deflate_state *ss; - ushf *overlay; - - - if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { - return Z_STREAM_ERROR; - } - - ss = source->state; - - zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); - - ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); - if (ds == Z_NULL) return Z_MEM_ERROR; - dest->state = (struct internal_state FAR *) ds; - zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); - ds->strm = dest; - - ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); - ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); - ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); - ds->pending_buf = (uchf *) overlay; - - if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || - ds->pending_buf == Z_NULL) { - deflateEnd (dest); - return Z_MEM_ERROR; - } - /* following zmemcpy do not work for 16-bit MSDOS */ - zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); - zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); - zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); - zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); - - ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); - ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); - ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; - - ds->l_desc.dyn_tree = ds->dyn_ltree; - ds->d_desc.dyn_tree = ds->dyn_dtree; - ds->bl_desc.dyn_tree = ds->bl_tree; - - return Z_OK; -#endif /* MAXSEG_64K */ -} - -/* =========================================================================== - * Read a new buffer from the current input stream, update the adler32 - * and total number of bytes read. All deflate() input goes through - * this function so some applications may wish to modify it to avoid - * allocating a large strm->next_in buffer and copying from it. - * (See also flush_pending()). - */ -local int read_buf(strm, buf, size) - z_streamp strm; - Bytef *buf; - unsigned size; -{ - unsigned len = strm->avail_in; - - if (len > size) len = size; - if (len == 0) return 0; - - strm->avail_in -= len; - - zmemcpy(buf, strm->next_in, len); - if (strm->state->wrap == 1) { - strm->adler = adler32(strm->adler, buf, len); - } -#ifdef GZIP - else if (strm->state->wrap == 2) { - strm->adler = crc32(strm->adler, buf, len); - } -#endif - strm->next_in += len; - strm->total_in += len; - - return (int)len; -} - -/* =========================================================================== - * Initialize the "longest match" routines for a new zlib stream - */ -local void lm_init (s) - deflate_state *s; -{ - s->window_size = (ulg)2L*s->w_size; - - CLEAR_HASH(s); - - /* Set the default configuration parameters: - */ - s->max_lazy_match = configuration_table[s->level].max_lazy; - s->good_match = configuration_table[s->level].good_length; - s->nice_match = configuration_table[s->level].nice_length; - s->max_chain_length = configuration_table[s->level].max_chain; - - s->strstart = 0; - s->block_start = 0L; - s->lookahead = 0; - s->insert = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - s->ins_h = 0; -#ifndef FASTEST -#ifdef ASMV - match_init(); /* initialize the asm code */ -#endif -#endif -} - -#ifndef FASTEST -/* =========================================================================== - * Set match_start to the longest match starting at the given string and - * return its length. Matches shorter or equal to prev_length are discarded, - * in which case the result is equal to prev_length and match_start is - * garbage. - * IN assertions: cur_match is the head of the hash chain for the current - * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 - * OUT assertion: the match length is not greater than s->lookahead. - */ -#ifndef ASMV -/* For 80x86 and 680x0, an optimized version will be provided in match.asm or - * match.S. The code will be functionally equivalent. - */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ - unsigned chain_length = s->max_chain_length;/* max hash chain length */ - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - int best_len = s->prev_length; /* best match length so far */ - int nice_match = s->nice_match; /* stop if match long enough */ - IPos limit = s->strstart > (IPos)MAX_DIST(s) ? - s->strstart - (IPos)MAX_DIST(s) : NIL; - /* Stop when cur_match becomes <= limit. To simplify the code, - * we prevent matches with the string of window index 0. - */ - Posf *prev = s->prev; - uInt wmask = s->w_mask; - -#ifdef UNALIGNED_OK - /* Compare two bytes at a time. Note: this is not always beneficial. - * Try with and without -DUNALIGNED_OK to check. - */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; - register ush scan_start = *(ushf*)scan; - register ush scan_end = *(ushf*)(scan+best_len-1); -#else - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - register Byte scan_end1 = scan[best_len-1]; - register Byte scan_end = scan[best_len]; -#endif - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - /* Do not waste too much time if we already have a good match: */ - if (s->prev_length >= s->good_match) { - chain_length >>= 2; - } - /* Do not look for matches beyond the end of the input. This is necessary - * to make deflate deterministic. - */ - if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; - - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); - - do { - Assert(cur_match < s->strstart, "no future"); - match = s->window + cur_match; - - /* Skip to next match if the match length cannot increase - * or if the match length is less than 2. Note that the checks below - * for insufficient lookahead only occur occasionally for performance - * reasons. Therefore uninitialized memory will be accessed, and - * conditional jumps will be made that depend on those values. - * However the length of the match is limited to the lookahead, so - * the output of deflate is not affected by the uninitialized values. - */ -#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) - /* This code assumes sizeof(unsigned short) == 2. Do not use - * UNALIGNED_OK if your compiler uses a different size. - */ - if (*(ushf*)(match+best_len-1) != scan_end || - *(ushf*)match != scan_start) continue; - - /* It is not necessary to compare scan[2] and match[2] since they are - * always equal when the other bytes match, given that the hash keys - * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at - * strstart+3, +5, ... up to strstart+257. We check for insufficient - * lookahead only every 4th comparison; the 128th check will be made - * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is - * necessary to put more guard bytes at the end of the window, or - * to check more often for insufficient lookahead. - */ - Assert(scan[2] == match[2], "scan[2]?"); - scan++, match++; - do { - } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - scan < strend); - /* The funny "do {}" generates better code on most compilers */ - - /* Here, scan <= window+strstart+257 */ - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - if (*scan == *match) scan++; - - len = (MAX_MATCH - 1) - (int)(strend-scan); - scan = strend - (MAX_MATCH-1); - -#else /* UNALIGNED_OK */ - - if (match[best_len] != scan_end || - match[best_len-1] != scan_end1 || - *match != *scan || - *++match != scan[1]) continue; - - /* The check at best_len-1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match++; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart+258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - scan = strend - MAX_MATCH; - -#endif /* UNALIGNED_OK */ - - if (len > best_len) { - s->match_start = cur_match; - best_len = len; - if (len >= nice_match) break; -#ifdef UNALIGNED_OK - scan_end = *(ushf*)(scan+best_len-1); -#else - scan_end1 = scan[best_len-1]; - scan_end = scan[best_len]; -#endif - } - } while ((cur_match = prev[cur_match & wmask]) > limit - && --chain_length != 0); - - if ((uInt)best_len <= s->lookahead) return (uInt)best_len; - return s->lookahead; -} -#endif /* ASMV */ - -#else /* FASTEST */ - -/* --------------------------------------------------------------------------- - * Optimized version for FASTEST only - */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); - - Assert(cur_match < s->strstart, "no future"); - - match = s->window + cur_match; - - /* Return failure if the match length is less than 2: - */ - if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; - - /* The check at best_len-1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match += 2; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart+258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - - if (len < MIN_MATCH) return MIN_MATCH - 1; - - s->match_start = cur_match; - return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; -} - -#endif /* FASTEST */ - -#ifdef DEBUG -/* =========================================================================== - * Check that the match at match_start is indeed a match. - */ -local void check_match(s, start, match, length) - deflate_state *s; - IPos start, match; - int length; -{ - /* check that the match is indeed a match */ - if (zmemcmp(s->window + match, - s->window + start, length) != EQUAL) { - fprintf(stderr, " start %u, match %u, length %d\n", - start, match, length); - do { - fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); - } while (--length != 0); - z_error("invalid match"); - } - if (z_verbose > 1) { - fprintf(stderr,"\\[%d,%d]", start-match, length); - do { putc(s->window[start++], stderr); } while (--length != 0); - } -} -#else -# define check_match(s, start, match, length) -#endif /* DEBUG */ - -/* =========================================================================== - * Fill the window when the lookahead becomes insufficient. - * Updates strstart and lookahead. - * - * IN assertion: lookahead < MIN_LOOKAHEAD - * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD - * At least one byte has been read, or avail_in == 0; reads are - * performed for at least two bytes (required for the zip translate_eol - * option -- not supported here). - */ -local void fill_window(s) - deflate_state *s; -{ - register unsigned n, m; - register Posf *p; - unsigned more; /* Amount of free space at the end of the window. */ - uInt wsize = s->w_size; - - Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); - - do { - more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); - - /* Deal with !@#$% 64K limit: */ - if (sizeof(int) <= 2) { - if (more == 0 && s->strstart == 0 && s->lookahead == 0) { - more = wsize; - - } else if (more == (unsigned)(-1)) { - /* Very unlikely, but possible on 16 bit machine if - * strstart == 0 && lookahead == 1 (input done a byte at time) - */ - more--; - } - } - - /* If the window is almost full and there is insufficient lookahead, - * move the upper half to the lower one to make room in the upper half. - */ - if (s->strstart >= wsize+MAX_DIST(s)) { - - zmemcpy(s->window, s->window+wsize, (unsigned)wsize); - s->match_start -= wsize; - s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ - s->block_start -= (long) wsize; - - /* Slide the hash table (could be avoided with 32 bit values - at the expense of memory usage). We slide even when level == 0 - to keep the hash table consistent if we switch back to level > 0 - later. (Using level 0 permanently is not an optimal usage of - zlib, so we don't care about this pathological case.) - */ - n = s->hash_size; - p = &s->head[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m-wsize : NIL); - } while (--n); - - n = wsize; -#ifndef FASTEST - p = &s->prev[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m-wsize : NIL); - /* If n is not on any hash chain, prev[n] is garbage but - * its value will never be used. - */ - } while (--n); -#endif - more += wsize; - } - if (s->strm->avail_in == 0) break; - - /* If there was no sliding: - * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && - * more == window_size - lookahead - strstart - * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) - * => more >= window_size - 2*WSIZE + 2 - * In the BIG_MEM or MMAP case (not yet supported), - * window_size == input_size + MIN_LOOKAHEAD && - * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. - * Otherwise, window_size == 2*WSIZE so more >= 2. - * If there was sliding, more >= WSIZE. So in all cases, more >= 2. - */ - Assert(more >= 2, "more < 2"); - - n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); - s->lookahead += n; - - /* Initialize the hash value now that we have some input: */ - if (s->lookahead + s->insert >= MIN_MATCH) { - uInt str = s->strstart - s->insert; - s->ins_h = s->window[str]; - UPDATE_HASH(s, s->ins_h, s->window[str + 1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - while (s->insert) { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - s->insert--; - if (s->lookahead + s->insert < MIN_MATCH) - break; - } - } - /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, - * but this is not important since only literal bytes will be emitted. - */ - - } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); - - /* If the WIN_INIT bytes after the end of the current data have never been - * written, then zero those bytes in order to avoid memory check reports of - * the use of uninitialized (or uninitialised as Julian writes) bytes by - * the longest match routines. Update the high water mark for the next - * time through here. WIN_INIT is set to MAX_MATCH since the longest match - * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. - */ - if (s->high_water < s->window_size) { - ulg curr = s->strstart + (ulg)(s->lookahead); - ulg init; - - if (s->high_water < curr) { - /* Previous high water mark below current data -- zero WIN_INIT - * bytes or up to end of window, whichever is less. - */ - init = s->window_size - curr; - if (init > WIN_INIT) - init = WIN_INIT; - zmemzero(s->window + curr, (unsigned)init); - s->high_water = curr + init; - } - else if (s->high_water < (ulg)curr + WIN_INIT) { - /* High water mark at or above current data, but below current data - * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up - * to end of window, whichever is less. - */ - init = (ulg)curr + WIN_INIT - s->high_water; - if (init > s->window_size - s->high_water) - init = s->window_size - s->high_water; - zmemzero(s->window + s->high_water, (unsigned)init); - s->high_water += init; - } - } - - Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, - "not enough room for search"); -} - -/* =========================================================================== - * Flush the current block, with given end-of-file flag. - * IN assertion: strstart is set to the end of the current match. - */ -#define FLUSH_BLOCK_ONLY(s, last) { \ - _tr_flush_block(s, (s->block_start >= 0L ? \ - (charf *)&s->window[(unsigned)s->block_start] : \ - (charf *)Z_NULL), \ - (ulg)((long)s->strstart - s->block_start), \ - (last)); \ - s->block_start = s->strstart; \ - flush_pending(s->strm); \ - Tracev((stderr,"[FLUSH]")); \ -} - -/* Same but force premature exit if necessary. */ -#define FLUSH_BLOCK(s, last) { \ - FLUSH_BLOCK_ONLY(s, last); \ - if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ -} - -/* =========================================================================== - * Copy without compression as much as possible from the input stream, return - * the current block state. - * This function does not insert new strings in the dictionary since - * uncompressible data is probably not useful. This function is used - * only for the level=0 compression option. - * NOTE: this function should be optimized to avoid extra copying from - * window to pending_buf. - */ -local block_state deflate_stored(s, flush) - deflate_state *s; - int flush; -{ - /* Stored blocks are limited to 0xffff bytes, pending_buf is limited - * to pending_buf_size, and each stored block has a 5 byte header: - */ - ulg max_block_size = 0xffff; - ulg max_start; - - if (max_block_size > s->pending_buf_size - 5) { - max_block_size = s->pending_buf_size - 5; - } - - /* Copy as much as possible from input to output: */ - for (;;) { - /* Fill the window as much as possible: */ - if (s->lookahead <= 1) { - - Assert(s->strstart < s->w_size+MAX_DIST(s) || - s->block_start >= (long)s->w_size, "slide too late"); - - fill_window(s); - if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; - - if (s->lookahead == 0) break; /* flush the current block */ - } - Assert(s->block_start >= 0L, "block gone"); - - s->strstart += s->lookahead; - s->lookahead = 0; - - /* Emit a stored block if pending_buf will be full: */ - max_start = s->block_start + max_block_size; - if (s->strstart == 0 || (ulg)s->strstart >= max_start) { - /* strstart == 0 is possible when wraparound on 16-bit machine */ - s->lookahead = (uInt)(s->strstart - max_start); - s->strstart = (uInt)max_start; - FLUSH_BLOCK(s, 0); - } - /* Flush if we may have to slide, otherwise block_start may become - * negative and the data will be gone: - */ - if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { - FLUSH_BLOCK(s, 0); - } - } - s->insert = 0; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if ((long)s->strstart > s->block_start) - FLUSH_BLOCK(s, 0); - return block_done; -} - -/* =========================================================================== - * Compress as much as possible from the input stream, return the current - * block state. - * This function does not perform lazy evaluation of matches and inserts - * new strings in the dictionary only for unmatched strings or for short - * matches. It is used only for the fast compression options. - */ -local block_state deflate_fast(s, flush) - deflate_state *s; - int flush; -{ - IPos hash_head; /* head of the hash chain */ - int bflush; /* set if current block must be flushed */ - - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the next match, plus MIN_MATCH bytes to insert the - * string following the next match. - */ - if (s->lookahead < MIN_LOOKAHEAD) { - fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart+2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - hash_head = NIL; - if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - * At this point we have always match_length < MIN_MATCH - */ - if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - s->match_length = longest_match (s, hash_head); - /* longest_match() sets match_start */ - } - if (s->match_length >= MIN_MATCH) { - check_match(s, s->strstart, s->match_start, s->match_length); - - _tr_tally_dist(s, s->strstart - s->match_start, - s->match_length - MIN_MATCH, bflush); - - s->lookahead -= s->match_length; - - /* Insert new strings in the hash table only if the match length - * is not too large. This saves time but degrades compression. - */ -#ifndef FASTEST - if (s->match_length <= s->max_insert_length && - s->lookahead >= MIN_MATCH) { - s->match_length--; /* string at strstart already in table */ - do { - s->strstart++; - INSERT_STRING(s, s->strstart, hash_head); - /* strstart never exceeds WSIZE-MAX_MATCH, so there are - * always MIN_MATCH bytes ahead. - */ - } while (--s->match_length != 0); - s->strstart++; - } else -#endif - { - s->strstart += s->match_length; - s->match_length = 0; - s->ins_h = s->window[s->strstart]; - UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not - * matter since it will be recomputed at next deflate call. - */ - } - } else { - /* No match, output a literal byte */ - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit (s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - } - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->last_lit) - FLUSH_BLOCK(s, 0); - return block_done; -} - -#ifndef FASTEST -/* =========================================================================== - * Same as above, but achieves better compression. We use a lazy - * evaluation for matches: a match is finally adopted only if there is - * no better match at the next window position. - */ -local block_state deflate_slow(s, flush) - deflate_state *s; - int flush; -{ - IPos hash_head; /* head of hash chain */ - int bflush; /* set if current block must be flushed */ - - /* Process the input block. */ - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the next match, plus MIN_MATCH bytes to insert the - * string following the next match. - */ - if (s->lookahead < MIN_LOOKAHEAD) { - fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart+2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - hash_head = NIL; - if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - */ - s->prev_length = s->match_length, s->prev_match = s->match_start; - s->match_length = MIN_MATCH-1; - - if (hash_head != NIL && s->prev_length < s->max_lazy_match && - s->strstart - hash_head <= MAX_DIST(s)) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - s->match_length = longest_match (s, hash_head); - /* longest_match() sets match_start */ - - if (s->match_length <= 5 && (s->strategy == Z_FILTERED -#if TOO_FAR <= 32767 - || (s->match_length == MIN_MATCH && - s->strstart - s->match_start > TOO_FAR) -#endif - )) { - - /* If prev_match is also MIN_MATCH, match_start is garbage - * but we will ignore the current match anyway. - */ - s->match_length = MIN_MATCH-1; - } - } - /* If there was a match at the previous step and the current - * match is not better, output the previous match: - */ - if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { - uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; - /* Do not insert strings in hash table beyond this. */ - - check_match(s, s->strstart-1, s->prev_match, s->prev_length); - - _tr_tally_dist(s, s->strstart -1 - s->prev_match, - s->prev_length - MIN_MATCH, bflush); - - /* Insert in hash table all strings up to the end of the match. - * strstart-1 and strstart are already inserted. If there is not - * enough lookahead, the last two strings are not inserted in - * the hash table. - */ - s->lookahead -= s->prev_length-1; - s->prev_length -= 2; - do { - if (++s->strstart <= max_insert) { - INSERT_STRING(s, s->strstart, hash_head); - } - } while (--s->prev_length != 0); - s->match_available = 0; - s->match_length = MIN_MATCH-1; - s->strstart++; - - if (bflush) FLUSH_BLOCK(s, 0); - - } else if (s->match_available) { - /* If there was no match at the previous position, output a - * single literal. If there was a match but the current match - * is longer, truncate the previous match to a single literal. - */ - Tracevv((stderr,"%c", s->window[s->strstart-1])); - _tr_tally_lit(s, s->window[s->strstart-1], bflush); - if (bflush) { - FLUSH_BLOCK_ONLY(s, 0); - } - s->strstart++; - s->lookahead--; - if (s->strm->avail_out == 0) return need_more; - } else { - /* There is no previous match to compare with, wait for - * the next step to decide. - */ - s->match_available = 1; - s->strstart++; - s->lookahead--; - } - } - Assert (flush != Z_NO_FLUSH, "no flush?"); - if (s->match_available) { - Tracevv((stderr,"%c", s->window[s->strstart-1])); - _tr_tally_lit(s, s->window[s->strstart-1], bflush); - s->match_available = 0; - } - s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->last_lit) - FLUSH_BLOCK(s, 0); - return block_done; -} -#endif /* FASTEST */ - -/* =========================================================================== - * For Z_RLE, simply look for runs of bytes, generate matches only of distance - * one. Do not maintain a hash table. (It will be regenerated if this run of - * deflate switches away from Z_RLE.) - */ -local block_state deflate_rle(s, flush) - deflate_state *s; - int flush; -{ - int bflush; /* set if current block must be flushed */ - uInt prev; /* byte at distance one to match */ - Bytef *scan, *strend; /* scan goes up to strend for length of run */ - - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the longest run, plus one for the unrolled loop. - */ - if (s->lookahead <= MAX_MATCH) { - fill_window(s); - if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* See how many times the previous byte repeats */ - s->match_length = 0; - if (s->lookahead >= MIN_MATCH && s->strstart > 0) { - scan = s->window + s->strstart - 1; - prev = *scan; - if (prev == *++scan && prev == *++scan && prev == *++scan) { - strend = s->window + s->strstart + MAX_MATCH; - do { - } while (prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - scan < strend); - s->match_length = MAX_MATCH - (int)(strend - scan); - if (s->match_length > s->lookahead) - s->match_length = s->lookahead; - } - Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); - } - - /* Emit match if have run of MIN_MATCH or longer, else emit literal */ - if (s->match_length >= MIN_MATCH) { - check_match(s, s->strstart, s->strstart - 1, s->match_length); - - _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); - - s->lookahead -= s->match_length; - s->strstart += s->match_length; - s->match_length = 0; - } else { - /* No match, output a literal byte */ - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit (s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - } - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = 0; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->last_lit) - FLUSH_BLOCK(s, 0); - return block_done; -} - -/* =========================================================================== - * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. - * (It will be regenerated if this run of deflate switches away from Huffman.) - */ -local block_state deflate_huff(s, flush) - deflate_state *s; - int flush; -{ - int bflush; /* set if current block must be flushed */ - - for (;;) { - /* Make sure that we have a literal to write. */ - if (s->lookahead == 0) { - fill_window(s); - if (s->lookahead == 0) { - if (flush == Z_NO_FLUSH) - return need_more; - break; /* flush the current block */ - } - } - - /* Output a literal byte */ - s->match_length = 0; - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit (s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = 0; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->last_lit) - FLUSH_BLOCK(s, 0); - return block_done; -} +/* deflate.c -- compress data using the deflation algorithm + * Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + * ALGORITHM + * + * The "deflation" process depends on being able to identify portions + * of the input text which are identical to earlier input (within a + * sliding window trailing behind the input currently being processed). + * + * The most straightforward technique turns out to be the fastest for + * most input files: try all possible matches and select the longest. + * The key feature of this algorithm is that insertions into the string + * dictionary are very simple and thus fast, and deletions are avoided + * completely. Insertions are performed at each input character, whereas + * string matches are performed only when the previous match ends. So it + * is preferable to spend more time in matches to allow very fast string + * insertions and avoid deletions. The matching algorithm for small + * strings is inspired from that of Rabin & Karp. A brute force approach + * is used to find longer strings when a small match has been found. + * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze + * (by Leonid Broukhis). + * A previous version of this file used a more sophisticated algorithm + * (by Fiala and Greene) which is guaranteed to run in linear amortized + * time, but has a larger average cost, uses more memory and is patented. + * However the F&G algorithm may be faster for some highly redundant + * files if the parameter max_chain_length (described below) is too large. + * + * ACKNOWLEDGEMENTS + * + * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and + * I found it in 'freeze' written by Leonid Broukhis. + * Thanks to many people for bug reports and testing. + * + * REFERENCES + * + * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". + * Available in http://tools.ietf.org/html/rfc1951 + * + * A description of the Rabin and Karp algorithm is given in the book + * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. + * + * Fiala,E.R., and Greene,D.H. + * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 + * + */ + +/* @(#) $Id: deflate.c,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ + +#include "deflate.h" + +const char deflate_copyright[] = + " deflate 1.2.7 Copyright 1995-2012 Jean-loup Gailly and Mark Adler "; +/* + If you use the zlib library in a product, an acknowledgment is welcome + in the documentation of your product. If for some reason you cannot + include such an acknowledgment, I would appreciate that you keep this + copyright string in the executable of your product. + */ + +/* =========================================================================== + * Function prototypes. + */ +typedef enum { + need_more, /* block not completed, need more input or more output */ + block_done, /* block flush performed */ + finish_started, /* finish started, need only more output at next deflate */ + finish_done /* finish done, accept no more input or output */ +} block_state; + +typedef block_state (*compress_func) OF((deflate_state *s, int flush)); +/* Compression function. Returns the block state after the call. */ + +local void fill_window OF((deflate_state *s)); +local block_state deflate_stored OF((deflate_state *s, int flush)); +local block_state deflate_fast OF((deflate_state *s, int flush)); +#ifndef FASTEST +local block_state deflate_slow OF((deflate_state *s, int flush)); +#endif +local block_state deflate_rle OF((deflate_state *s, int flush)); +local block_state deflate_huff OF((deflate_state *s, int flush)); +local void lm_init OF((deflate_state *s)); +local void putShortMSB OF((deflate_state *s, uInt b)); +local void flush_pending OF((z_streamp strm)); +local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); +#ifdef ASMV + void match_init OF((void)); /* asm code initialization */ + uInt longest_match OF((deflate_state *s, IPos cur_match)); +#else +local uInt longest_match OF((deflate_state *s, IPos cur_match)); +#endif + +#ifdef DEBUG +local void check_match OF((deflate_state *s, IPos start, IPos match, + int length)); +#endif + +/* =========================================================================== + * Local data + */ + +#define NIL 0 +/* Tail of hash chains */ + +#ifndef TOO_FAR +# define TOO_FAR 4096 +#endif +/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ + +/* Values for max_lazy_match, good_match and max_chain_length, depending on + * the desired pack level (0..9). The values given below have been tuned to + * exclude worst case performance for pathological files. Better values may be + * found for specific files. + */ +typedef struct config_s { + ush good_length; /* reduce lazy search above this match length */ + ush max_lazy; /* do not perform lazy search above this match length */ + ush nice_length; /* quit search above this match length */ + ush max_chain; + compress_func func; +} config; + +#ifdef FASTEST +local const config configuration_table[2] = { +/* good lazy nice chain */ +/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ +/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */ +#else +local const config configuration_table[10] = { +/* good lazy nice chain */ +/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ +/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */ +/* 2 */ {4, 5, 16, 8, deflate_fast}, +/* 3 */ {4, 6, 32, 32, deflate_fast}, + +/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ +/* 5 */ {8, 16, 32, 32, deflate_slow}, +/* 6 */ {8, 16, 128, 128, deflate_slow}, +/* 7 */ {8, 32, 128, 256, deflate_slow}, +/* 8 */ {32, 128, 258, 1024, deflate_slow}, +/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */ +#endif + +/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 + * For deflate_fast() (levels <= 3) good is ignored and lazy has a different + * meaning. + */ + +#define EQUAL 0 +/* result of memcmp for equal strings */ + +#ifndef NO_DUMMY_DECL +struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ +#endif + +/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */ +#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0)) + +/* =========================================================================== + * Update a hash value with the given input byte + * IN assertion: all calls to to UPDATE_HASH are made with consecutive + * input characters, so that a running hash key can be computed from the + * previous key instead of complete recalculation each time. + */ +#define UPDATE_HASH(s,h,c) (h = (((h)<hash_shift) ^ (c)) & s->hash_mask) + + +/* =========================================================================== + * Insert string str in the dictionary and set match_head to the previous head + * of the hash chain (the most recent string with same hash key). Return + * the previous length of the hash chain. + * If this file is compiled with -DFASTEST, the compression level is forced + * to 1, and no hash chains are maintained. + * IN assertion: all calls to to INSERT_STRING are made with consecutive + * input characters and the first MIN_MATCH bytes of str are valid + * (except for the last MIN_MATCH-1 bytes of the input file). + */ +#ifdef FASTEST +#define INSERT_STRING(s, str, match_head) \ + (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ + match_head = s->head[s->ins_h], \ + s->head[s->ins_h] = (Pos)(str)) +#else +#define INSERT_STRING(s, str, match_head) \ + (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ + match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ + s->head[s->ins_h] = (Pos)(str)) +#endif + +/* =========================================================================== + * Initialize the hash table (avoiding 64K overflow for 16 bit systems). + * prev[] will be initialized on the fly. + */ +#define CLEAR_HASH(s) \ + s->head[s->hash_size-1] = NIL; \ + zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); + +/* ========================================================================= */ +int ZEXPORT deflateInit_(strm, level, version, stream_size) + z_streamp strm; + int level; + const char *version; + int stream_size; +{ + return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, + Z_DEFAULT_STRATEGY, version, stream_size); + /* To do: ignore strm->next_in if we use it as window */ +} + +/* ========================================================================= */ +int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, + version, stream_size) + z_streamp strm; + int level; + int method; + int windowBits; + int memLevel; + int strategy; + const char *version; + int stream_size; +{ + deflate_state *s; + int wrap = 1; + static const char my_version[] = ZLIB_VERSION; + + ushf *overlay; + /* We overlay pending_buf and d_buf+l_buf. This works since the average + * output size for (length,distance) codes is <= 24 bits. + */ + + if (version == Z_NULL || version[0] != my_version[0] || + stream_size != sizeof(z_stream)) { + return Z_VERSION_ERROR; + } + if (strm == Z_NULL) return Z_STREAM_ERROR; + + strm->msg = Z_NULL; + if (strm->zalloc == (alloc_func)0) { +#ifdef Z_SOLO + return Z_STREAM_ERROR; +#else + strm->zalloc = zcalloc; + strm->opaque = (voidpf)0; +#endif + } + if (strm->zfree == (free_func)0) +#ifdef Z_SOLO + return Z_STREAM_ERROR; +#else + strm->zfree = zcfree; +#endif + +#ifdef FASTEST + if (level != 0) level = 1; +#else + if (level == Z_DEFAULT_COMPRESSION) level = 6; +#endif + + if (windowBits < 0) { /* suppress zlib wrapper */ + wrap = 0; + windowBits = -windowBits; + } +#ifdef GZIP + else if (windowBits > 15) { + wrap = 2; /* write gzip wrapper instead */ + windowBits -= 16; + } +#endif + if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || + windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || + strategy < 0 || strategy > Z_FIXED) { + return Z_STREAM_ERROR; + } + if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ + s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); + if (s == Z_NULL) return Z_MEM_ERROR; + strm->state = (struct internal_state FAR *)s; + s->strm = strm; + + s->wrap = wrap; + s->gzhead = Z_NULL; + s->w_bits = windowBits; + s->w_size = 1 << s->w_bits; + s->w_mask = s->w_size - 1; + + s->hash_bits = memLevel + 7; + s->hash_size = 1 << s->hash_bits; + s->hash_mask = s->hash_size - 1; + s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); + + s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); + s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); + s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); + + s->high_water = 0; /* nothing written to s->window yet */ + + s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ + + overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); + s->pending_buf = (uchf *) overlay; + s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); + + if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || + s->pending_buf == Z_NULL) { + s->status = FINISH_STATE; + strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); + deflateEnd (strm); + return Z_MEM_ERROR; + } + s->d_buf = overlay + s->lit_bufsize/sizeof(ush); + s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; + + s->level = level; + s->strategy = strategy; + s->method = (Byte)method; + + return deflateReset(strm); +} + +/* ========================================================================= */ +int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) + z_streamp strm; + const Bytef *dictionary; + uInt dictLength; +{ + deflate_state *s; + uInt str, n; + int wrap; + unsigned avail; + unsigned char *next; + + if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL) + return Z_STREAM_ERROR; + s = strm->state; + wrap = s->wrap; + if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead) + return Z_STREAM_ERROR; + + /* when using zlib wrappers, compute Adler-32 for provided dictionary */ + if (wrap == 1) + strm->adler = adler32(strm->adler, dictionary, dictLength); + s->wrap = 0; /* avoid computing Adler-32 in read_buf */ + + /* if dictionary would fill window, just replace the history */ + if (dictLength >= s->w_size) { + if (wrap == 0) { /* already empty otherwise */ + CLEAR_HASH(s); + s->strstart = 0; + s->block_start = 0L; + s->insert = 0; + } + dictionary += dictLength - s->w_size; /* use the tail */ + dictLength = s->w_size; + } + + /* insert dictionary into window and hash */ + avail = strm->avail_in; + next = strm->next_in; + strm->avail_in = dictLength; + strm->next_in = (Bytef *)dictionary; + fill_window(s); + while (s->lookahead >= MIN_MATCH) { + str = s->strstart; + n = s->lookahead - (MIN_MATCH-1); + do { + UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); +#ifndef FASTEST + s->prev[str & s->w_mask] = s->head[s->ins_h]; +#endif + s->head[s->ins_h] = (Pos)str; + str++; + } while (--n); + s->strstart = str; + s->lookahead = MIN_MATCH-1; + fill_window(s); + } + s->strstart += s->lookahead; + s->block_start = (long)s->strstart; + s->insert = s->lookahead; + s->lookahead = 0; + s->match_length = s->prev_length = MIN_MATCH-1; + s->match_available = 0; + strm->next_in = next; + strm->avail_in = avail; + s->wrap = wrap; + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflateResetKeep (strm) + z_streamp strm; +{ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL || + strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) { + return Z_STREAM_ERROR; + } + + strm->total_in = strm->total_out = 0; + strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ + strm->data_type = Z_UNKNOWN; + + s = (deflate_state *)strm->state; + s->pending = 0; + s->pending_out = s->pending_buf; + + if (s->wrap < 0) { + s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ + } + s->status = s->wrap ? INIT_STATE : BUSY_STATE; + strm->adler = +#ifdef GZIP + s->wrap == 2 ? crc32(0L, Z_NULL, 0) : +#endif + adler32(0L, Z_NULL, 0); + s->last_flush = Z_NO_FLUSH; + + _tr_init(s); + + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflateReset (strm) + z_streamp strm; +{ + int ret; + + ret = deflateResetKeep(strm); + if (ret == Z_OK) + lm_init(strm->state); + return ret; +} + +/* ========================================================================= */ +int ZEXPORT deflateSetHeader (strm, head) + z_streamp strm; + gz_headerp head; +{ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + if (strm->state->wrap != 2) return Z_STREAM_ERROR; + strm->state->gzhead = head; + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflatePending (strm, pending, bits) + unsigned *pending; + int *bits; + z_streamp strm; +{ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + if (pending != Z_NULL) + *pending = strm->state->pending; + if (bits != Z_NULL) + *bits = strm->state->bi_valid; + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflatePrime (strm, bits, value) + z_streamp strm; + int bits; + int value; +{ + deflate_state *s; + int put; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + s = strm->state; + if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3)) + return Z_BUF_ERROR; + do { + put = Buf_size - s->bi_valid; + if (put > bits) + put = bits; + s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid); + s->bi_valid += put; + _tr_flush_bits(s); + value >>= put; + bits -= put; + } while (bits); + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflateParams(strm, level, strategy) + z_streamp strm; + int level; + int strategy; +{ + deflate_state *s; + compress_func func; + int err = Z_OK; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + s = strm->state; + +#ifdef FASTEST + if (level != 0) level = 1; +#else + if (level == Z_DEFAULT_COMPRESSION) level = 6; +#endif + if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { + return Z_STREAM_ERROR; + } + func = configuration_table[s->level].func; + + if ((strategy != s->strategy || func != configuration_table[level].func) && + strm->total_in != 0) { + /* Flush the last buffer: */ + err = deflate(strm, Z_BLOCK); + } + if (s->level != level) { + s->level = level; + s->max_lazy_match = configuration_table[level].max_lazy; + s->good_match = configuration_table[level].good_length; + s->nice_match = configuration_table[level].nice_length; + s->max_chain_length = configuration_table[level].max_chain; + } + s->strategy = strategy; + return err; +} + +/* ========================================================================= */ +int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) + z_streamp strm; + int good_length; + int max_lazy; + int nice_length; + int max_chain; +{ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + s = strm->state; + s->good_match = good_length; + s->max_lazy_match = max_lazy; + s->nice_match = nice_length; + s->max_chain_length = max_chain; + return Z_OK; +} + +/* ========================================================================= + * For the default windowBits of 15 and memLevel of 8, this function returns + * a close to exact, as well as small, upper bound on the compressed size. + * They are coded as constants here for a reason--if the #define's are + * changed, then this function needs to be changed as well. The return + * value for 15 and 8 only works for those exact settings. + * + * For any setting other than those defaults for windowBits and memLevel, + * the value returned is a conservative worst case for the maximum expansion + * resulting from using fixed blocks instead of stored blocks, which deflate + * can emit on compressed data for some combinations of the parameters. + * + * This function could be more sophisticated to provide closer upper bounds for + * every combination of windowBits and memLevel. But even the conservative + * upper bound of about 14% expansion does not seem onerous for output buffer + * allocation. + */ +uLong ZEXPORT deflateBound(strm, sourceLen) + z_streamp strm; + uLong sourceLen; +{ + deflate_state *s; + uLong complen, wraplen; + Bytef *str; + + /* conservative upper bound for compressed data */ + complen = sourceLen + + ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; + + /* if can't get parameters, return conservative bound plus zlib wrapper */ + if (strm == Z_NULL || strm->state == Z_NULL) + return complen + 6; + + /* compute wrapper length */ + s = strm->state; + switch (s->wrap) { + case 0: /* raw deflate */ + wraplen = 0; + break; + case 1: /* zlib wrapper */ + wraplen = 6 + (s->strstart ? 4 : 0); + break; + case 2: /* gzip wrapper */ + wraplen = 18; + if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ + if (s->gzhead->extra != Z_NULL) + wraplen += 2 + s->gzhead->extra_len; + str = s->gzhead->name; + if (str != Z_NULL) + do { + wraplen++; + } while (*str++); + str = s->gzhead->comment; + if (str != Z_NULL) + do { + wraplen++; + } while (*str++); + if (s->gzhead->hcrc) + wraplen += 2; + } + break; + default: /* for compiler happiness */ + wraplen = 6; + } + + /* if not default parameters, return conservative bound */ + if (s->w_bits != 15 || s->hash_bits != 8 + 7) + return complen + wraplen; + + /* default settings: return tight bound for that case */ + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + + (sourceLen >> 25) + 13 - 6 + wraplen; +} + +/* ========================================================================= + * Put a short in the pending buffer. The 16-bit value is put in MSB order. + * IN assertion: the stream state is correct and there is enough room in + * pending_buf. + */ +local void putShortMSB (s, b) + deflate_state *s; + uInt b; +{ + put_byte(s, (Byte)(b >> 8)); + put_byte(s, (Byte)(b & 0xff)); +} + +/* ========================================================================= + * Flush as much pending output as possible. All deflate() output goes + * through this function so some applications may wish to modify it + * to avoid allocating a large strm->next_out buffer and copying into it. + * (See also read_buf()). + */ +local void flush_pending(strm) + z_streamp strm; +{ + unsigned len; + deflate_state *s = strm->state; + + _tr_flush_bits(s); + len = s->pending; + if (len > strm->avail_out) len = strm->avail_out; + if (len == 0) return; + + zmemcpy(strm->next_out, s->pending_out, len); + strm->next_out += len; + s->pending_out += len; + strm->total_out += len; + strm->avail_out -= len; + s->pending -= len; + if (s->pending == 0) { + s->pending_out = s->pending_buf; + } +} + +/* ========================================================================= */ +int ZEXPORT deflate (strm, flush) + z_streamp strm; + int flush; +{ + int old_flush; /* value of flush param for previous deflate call */ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL || + flush > Z_BLOCK || flush < 0) { + return Z_STREAM_ERROR; + } + s = strm->state; + + if (strm->next_out == Z_NULL || + (strm->next_in == Z_NULL && strm->avail_in != 0) || + (s->status == FINISH_STATE && flush != Z_FINISH)) { + ERR_RETURN(strm, Z_STREAM_ERROR); + } + if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); + + s->strm = strm; /* just in case */ + old_flush = s->last_flush; + s->last_flush = flush; + + /* Write the header */ + if (s->status == INIT_STATE) { +#ifdef GZIP + if (s->wrap == 2) { + strm->adler = crc32(0L, Z_NULL, 0); + put_byte(s, 31); + put_byte(s, 139); + put_byte(s, 8); + if (s->gzhead == Z_NULL) { + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, s->level == 9 ? 2 : + (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? + 4 : 0)); + put_byte(s, OS_CODE); + s->status = BUSY_STATE; + } + else { + put_byte(s, (s->gzhead->text ? 1 : 0) + + (s->gzhead->hcrc ? 2 : 0) + + (s->gzhead->extra == Z_NULL ? 0 : 4) + + (s->gzhead->name == Z_NULL ? 0 : 8) + + (s->gzhead->comment == Z_NULL ? 0 : 16) + ); + put_byte(s, (Byte)(s->gzhead->time & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); + put_byte(s, s->level == 9 ? 2 : + (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? + 4 : 0)); + put_byte(s, s->gzhead->os & 0xff); + if (s->gzhead->extra != Z_NULL) { + put_byte(s, s->gzhead->extra_len & 0xff); + put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); + } + if (s->gzhead->hcrc) + strm->adler = crc32(strm->adler, s->pending_buf, + s->pending); + s->gzindex = 0; + s->status = EXTRA_STATE; + } + } + else +#endif + { + uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; + uInt level_flags; + + if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) + level_flags = 0; + else if (s->level < 6) + level_flags = 1; + else if (s->level == 6) + level_flags = 2; + else + level_flags = 3; + header |= (level_flags << 6); + if (s->strstart != 0) header |= PRESET_DICT; + header += 31 - (header % 31); + + s->status = BUSY_STATE; + putShortMSB(s, header); + + /* Save the adler32 of the preset dictionary: */ + if (s->strstart != 0) { + putShortMSB(s, (uInt)(strm->adler >> 16)); + putShortMSB(s, (uInt)(strm->adler & 0xffff)); + } + strm->adler = adler32(0L, Z_NULL, 0); + } + } +#ifdef GZIP + if (s->status == EXTRA_STATE) { + if (s->gzhead->extra != Z_NULL) { + uInt beg = s->pending; /* start of bytes to update crc */ + + while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) + break; + } + put_byte(s, s->gzhead->extra[s->gzindex]); + s->gzindex++; + } + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (s->gzindex == s->gzhead->extra_len) { + s->gzindex = 0; + s->status = NAME_STATE; + } + } + else + s->status = NAME_STATE; + } + if (s->status == NAME_STATE) { + if (s->gzhead->name != Z_NULL) { + uInt beg = s->pending; /* start of bytes to update crc */ + int val; + + do { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) { + val = 1; + break; + } + } + val = s->gzhead->name[s->gzindex++]; + put_byte(s, val); + } while (val != 0); + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (val == 0) { + s->gzindex = 0; + s->status = COMMENT_STATE; + } + } + else + s->status = COMMENT_STATE; + } + if (s->status == COMMENT_STATE) { + if (s->gzhead->comment != Z_NULL) { + uInt beg = s->pending; /* start of bytes to update crc */ + int val; + + do { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) { + val = 1; + break; + } + } + val = s->gzhead->comment[s->gzindex++]; + put_byte(s, val); + } while (val != 0); + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (val == 0) + s->status = HCRC_STATE; + } + else + s->status = HCRC_STATE; + } + if (s->status == HCRC_STATE) { + if (s->gzhead->hcrc) { + if (s->pending + 2 > s->pending_buf_size) + flush_pending(strm); + if (s->pending + 2 <= s->pending_buf_size) { + put_byte(s, (Byte)(strm->adler & 0xff)); + put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); + strm->adler = crc32(0L, Z_NULL, 0); + s->status = BUSY_STATE; + } + } + else + s->status = BUSY_STATE; + } +#endif + + /* Flush as much pending output as possible */ + if (s->pending != 0) { + flush_pending(strm); + if (strm->avail_out == 0) { + /* Since avail_out is 0, deflate will be called again with + * more output space, but possibly with both pending and + * avail_in equal to zero. There won't be anything to do, + * but this is not an error situation so make sure we + * return OK instead of BUF_ERROR at next call of deflate: + */ + s->last_flush = -1; + return Z_OK; + } + + /* Make sure there is something to do and avoid duplicate consecutive + * flushes. For repeated and useless calls with Z_FINISH, we keep + * returning Z_STREAM_END instead of Z_BUF_ERROR. + */ + } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) && + flush != Z_FINISH) { + ERR_RETURN(strm, Z_BUF_ERROR); + } + + /* User must not provide more input after the first FINISH: */ + if (s->status == FINISH_STATE && strm->avail_in != 0) { + ERR_RETURN(strm, Z_BUF_ERROR); + } + + /* Start a new block or continue the current one. + */ + if (strm->avail_in != 0 || s->lookahead != 0 || + (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { + block_state bstate; + + bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : + (s->strategy == Z_RLE ? deflate_rle(s, flush) : + (*(configuration_table[s->level].func))(s, flush)); + + if (bstate == finish_started || bstate == finish_done) { + s->status = FINISH_STATE; + } + if (bstate == need_more || bstate == finish_started) { + if (strm->avail_out == 0) { + s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ + } + return Z_OK; + /* If flush != Z_NO_FLUSH && avail_out == 0, the next call + * of deflate should use the same flush parameter to make sure + * that the flush is complete. So we don't have to output an + * empty block here, this will be done at next call. This also + * ensures that for a very small output buffer, we emit at most + * one empty block. + */ + } + if (bstate == block_done) { + if (flush == Z_PARTIAL_FLUSH) { + _tr_align(s); + } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ + _tr_stored_block(s, (char*)0, 0L, 0); + /* For a full flush, this empty block will be recognized + * as a special marker by inflate_sync(). + */ + if (flush == Z_FULL_FLUSH) { + CLEAR_HASH(s); /* forget history */ + if (s->lookahead == 0) { + s->strstart = 0; + s->block_start = 0L; + s->insert = 0; + } + } + } + flush_pending(strm); + if (strm->avail_out == 0) { + s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ + return Z_OK; + } + } + } + Assert(strm->avail_out > 0, "bug2"); + + if (flush != Z_FINISH) return Z_OK; + if (s->wrap <= 0) return Z_STREAM_END; + + /* Write the trailer */ +#ifdef GZIP + if (s->wrap == 2) { + put_byte(s, (Byte)(strm->adler & 0xff)); + put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); + put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); + put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); + put_byte(s, (Byte)(strm->total_in & 0xff)); + put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); + put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); + put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); + } + else +#endif + { + putShortMSB(s, (uInt)(strm->adler >> 16)); + putShortMSB(s, (uInt)(strm->adler & 0xffff)); + } + flush_pending(strm); + /* If avail_out is zero, the application will call deflate again + * to flush the rest. + */ + if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ + return s->pending != 0 ? Z_OK : Z_STREAM_END; +} + +/* ========================================================================= */ +int ZEXPORT deflateEnd (strm) + z_streamp strm; +{ + int status; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + + status = strm->state->status; + if (status != INIT_STATE && + status != EXTRA_STATE && + status != NAME_STATE && + status != COMMENT_STATE && + status != HCRC_STATE && + status != BUSY_STATE && + status != FINISH_STATE) { + return Z_STREAM_ERROR; + } + + /* Deallocate in reverse order of allocations: */ + TRY_FREE(strm, strm->state->pending_buf); + TRY_FREE(strm, strm->state->head); + TRY_FREE(strm, strm->state->prev); + TRY_FREE(strm, strm->state->window); + + ZFREE(strm, strm->state); + strm->state = Z_NULL; + + return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; +} + +/* ========================================================================= + * Copy the source state to the destination state. + * To simplify the source, this is not supported for 16-bit MSDOS (which + * doesn't have enough memory anyway to duplicate compression states). + */ +int ZEXPORT deflateCopy (dest, source) + z_streamp dest; + z_streamp source; +{ +#ifdef MAXSEG_64K + return Z_STREAM_ERROR; +#else + deflate_state *ds; + deflate_state *ss; + ushf *overlay; + + + if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { + return Z_STREAM_ERROR; + } + + ss = source->state; + + zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); + + ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); + if (ds == Z_NULL) return Z_MEM_ERROR; + dest->state = (struct internal_state FAR *) ds; + zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); + ds->strm = dest; + + ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); + ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); + ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); + overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); + ds->pending_buf = (uchf *) overlay; + + if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || + ds->pending_buf == Z_NULL) { + deflateEnd (dest); + return Z_MEM_ERROR; + } + /* following zmemcpy do not work for 16-bit MSDOS */ + zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); + zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); + zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); + zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); + + ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); + ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); + ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; + + ds->l_desc.dyn_tree = ds->dyn_ltree; + ds->d_desc.dyn_tree = ds->dyn_dtree; + ds->bl_desc.dyn_tree = ds->bl_tree; + + return Z_OK; +#endif /* MAXSEG_64K */ +} + +/* =========================================================================== + * Read a new buffer from the current input stream, update the adler32 + * and total number of bytes read. All deflate() input goes through + * this function so some applications may wish to modify it to avoid + * allocating a large strm->next_in buffer and copying from it. + * (See also flush_pending()). + */ +local int read_buf(strm, buf, size) + z_streamp strm; + Bytef *buf; + unsigned size; +{ + unsigned len = strm->avail_in; + + if (len > size) len = size; + if (len == 0) return 0; + + strm->avail_in -= len; + + zmemcpy(buf, strm->next_in, len); + if (strm->state->wrap == 1) { + strm->adler = adler32(strm->adler, buf, len); + } +#ifdef GZIP + else if (strm->state->wrap == 2) { + strm->adler = crc32(strm->adler, buf, len); + } +#endif + strm->next_in += len; + strm->total_in += len; + + return (int)len; +} + +/* =========================================================================== + * Initialize the "longest match" routines for a new zlib stream + */ +local void lm_init (s) + deflate_state *s; +{ + s->window_size = (ulg)2L*s->w_size; + + CLEAR_HASH(s); + + /* Set the default configuration parameters: + */ + s->max_lazy_match = configuration_table[s->level].max_lazy; + s->good_match = configuration_table[s->level].good_length; + s->nice_match = configuration_table[s->level].nice_length; + s->max_chain_length = configuration_table[s->level].max_chain; + + s->strstart = 0; + s->block_start = 0L; + s->lookahead = 0; + s->insert = 0; + s->match_length = s->prev_length = MIN_MATCH-1; + s->match_available = 0; + s->ins_h = 0; +#ifndef FASTEST +#ifdef ASMV + match_init(); /* initialize the asm code */ +#endif +#endif +} + +#ifndef FASTEST +/* =========================================================================== + * Set match_start to the longest match starting at the given string and + * return its length. Matches shorter or equal to prev_length are discarded, + * in which case the result is equal to prev_length and match_start is + * garbage. + * IN assertions: cur_match is the head of the hash chain for the current + * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 + * OUT assertion: the match length is not greater than s->lookahead. + */ +#ifndef ASMV +/* For 80x86 and 680x0, an optimized version will be provided in match.asm or + * match.S. The code will be functionally equivalent. + */ +local uInt longest_match(s, cur_match) + deflate_state *s; + IPos cur_match; /* current match */ +{ + unsigned chain_length = s->max_chain_length;/* max hash chain length */ + register Bytef *scan = s->window + s->strstart; /* current string */ + register Bytef *match; /* matched string */ + register int len; /* length of current match */ + int best_len = s->prev_length; /* best match length so far */ + int nice_match = s->nice_match; /* stop if match long enough */ + IPos limit = s->strstart > (IPos)MAX_DIST(s) ? + s->strstart - (IPos)MAX_DIST(s) : NIL; + /* Stop when cur_match becomes <= limit. To simplify the code, + * we prevent matches with the string of window index 0. + */ + Posf *prev = s->prev; + uInt wmask = s->w_mask; + +#ifdef UNALIGNED_OK + /* Compare two bytes at a time. Note: this is not always beneficial. + * Try with and without -DUNALIGNED_OK to check. + */ + register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; + register ush scan_start = *(ushf*)scan; + register ush scan_end = *(ushf*)(scan+best_len-1); +#else + register Bytef *strend = s->window + s->strstart + MAX_MATCH; + register Byte scan_end1 = scan[best_len-1]; + register Byte scan_end = scan[best_len]; +#endif + + /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. + * It is easy to get rid of this optimization if necessary. + */ + Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); + + /* Do not waste too much time if we already have a good match: */ + if (s->prev_length >= s->good_match) { + chain_length >>= 2; + } + /* Do not look for matches beyond the end of the input. This is necessary + * to make deflate deterministic. + */ + if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; + + Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + + do { + Assert(cur_match < s->strstart, "no future"); + match = s->window + cur_match; + + /* Skip to next match if the match length cannot increase + * or if the match length is less than 2. Note that the checks below + * for insufficient lookahead only occur occasionally for performance + * reasons. Therefore uninitialized memory will be accessed, and + * conditional jumps will be made that depend on those values. + * However the length of the match is limited to the lookahead, so + * the output of deflate is not affected by the uninitialized values. + */ +#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) + /* This code assumes sizeof(unsigned short) == 2. Do not use + * UNALIGNED_OK if your compiler uses a different size. + */ + if (*(ushf*)(match+best_len-1) != scan_end || + *(ushf*)match != scan_start) continue; + + /* It is not necessary to compare scan[2] and match[2] since they are + * always equal when the other bytes match, given that the hash keys + * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at + * strstart+3, +5, ... up to strstart+257. We check for insufficient + * lookahead only every 4th comparison; the 128th check will be made + * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is + * necessary to put more guard bytes at the end of the window, or + * to check more often for insufficient lookahead. + */ + Assert(scan[2] == match[2], "scan[2]?"); + scan++, match++; + do { + } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + scan < strend); + /* The funny "do {}" generates better code on most compilers */ + + /* Here, scan <= window+strstart+257 */ + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + if (*scan == *match) scan++; + + len = (MAX_MATCH - 1) - (int)(strend-scan); + scan = strend - (MAX_MATCH-1); + +#else /* UNALIGNED_OK */ + + if (match[best_len] != scan_end || + match[best_len-1] != scan_end1 || + *match != *scan || + *++match != scan[1]) continue; + + /* The check at best_len-1 can be removed because it will be made + * again later. (This heuristic is not always a win.) + * It is not necessary to compare scan[2] and match[2] since they + * are always equal when the other bytes match, given that + * the hash keys are equal and that HASH_BITS >= 8. + */ + scan += 2, match++; + Assert(*scan == *match, "match[2]?"); + + /* We check for insufficient lookahead only every 8th comparison; + * the 256th check will be made at strstart+258. + */ + do { + } while (*++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + scan < strend); + + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + + len = MAX_MATCH - (int)(strend - scan); + scan = strend - MAX_MATCH; + +#endif /* UNALIGNED_OK */ + + if (len > best_len) { + s->match_start = cur_match; + best_len = len; + if (len >= nice_match) break; +#ifdef UNALIGNED_OK + scan_end = *(ushf*)(scan+best_len-1); +#else + scan_end1 = scan[best_len-1]; + scan_end = scan[best_len]; +#endif + } + } while ((cur_match = prev[cur_match & wmask]) > limit + && --chain_length != 0); + + if ((uInt)best_len <= s->lookahead) return (uInt)best_len; + return s->lookahead; +} +#endif /* ASMV */ + +#else /* FASTEST */ + +/* --------------------------------------------------------------------------- + * Optimized version for FASTEST only + */ +local uInt longest_match(s, cur_match) + deflate_state *s; + IPos cur_match; /* current match */ +{ + register Bytef *scan = s->window + s->strstart; /* current string */ + register Bytef *match; /* matched string */ + register int len; /* length of current match */ + register Bytef *strend = s->window + s->strstart + MAX_MATCH; + + /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. + * It is easy to get rid of this optimization if necessary. + */ + Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); + + Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + + Assert(cur_match < s->strstart, "no future"); + + match = s->window + cur_match; + + /* Return failure if the match length is less than 2: + */ + if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; + + /* The check at best_len-1 can be removed because it will be made + * again later. (This heuristic is not always a win.) + * It is not necessary to compare scan[2] and match[2] since they + * are always equal when the other bytes match, given that + * the hash keys are equal and that HASH_BITS >= 8. + */ + scan += 2, match += 2; + Assert(*scan == *match, "match[2]?"); + + /* We check for insufficient lookahead only every 8th comparison; + * the 256th check will be made at strstart+258. + */ + do { + } while (*++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + scan < strend); + + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + + len = MAX_MATCH - (int)(strend - scan); + + if (len < MIN_MATCH) return MIN_MATCH - 1; + + s->match_start = cur_match; + return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; +} + +#endif /* FASTEST */ + +#ifdef DEBUG +/* =========================================================================== + * Check that the match at match_start is indeed a match. + */ +local void check_match(s, start, match, length) + deflate_state *s; + IPos start, match; + int length; +{ + /* check that the match is indeed a match */ + if (zmemcmp(s->window + match, + s->window + start, length) != EQUAL) { + fprintf(stderr, " start %u, match %u, length %d\n", + start, match, length); + do { + fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); + } while (--length != 0); + z_error("invalid match"); + } + if (z_verbose > 1) { + fprintf(stderr,"\\[%d,%d]", start-match, length); + do { putc(s->window[start++], stderr); } while (--length != 0); + } +} +#else +# define check_match(s, start, match, length) +#endif /* DEBUG */ + +/* =========================================================================== + * Fill the window when the lookahead becomes insufficient. + * Updates strstart and lookahead. + * + * IN assertion: lookahead < MIN_LOOKAHEAD + * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD + * At least one byte has been read, or avail_in == 0; reads are + * performed for at least two bytes (required for the zip translate_eol + * option -- not supported here). + */ +local void fill_window(s) + deflate_state *s; +{ + register unsigned n, m; + register Posf *p; + unsigned more; /* Amount of free space at the end of the window. */ + uInt wsize = s->w_size; + + Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); + + do { + more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); + + /* Deal with !@#$% 64K limit: */ + if (sizeof(int) <= 2) { + if (more == 0 && s->strstart == 0 && s->lookahead == 0) { + more = wsize; + + } else if (more == (unsigned)(-1)) { + /* Very unlikely, but possible on 16 bit machine if + * strstart == 0 && lookahead == 1 (input done a byte at time) + */ + more--; + } + } + + /* If the window is almost full and there is insufficient lookahead, + * move the upper half to the lower one to make room in the upper half. + */ + if (s->strstart >= wsize+MAX_DIST(s)) { + + zmemcpy(s->window, s->window+wsize, (unsigned)wsize); + s->match_start -= wsize; + s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ + s->block_start -= (long) wsize; + + /* Slide the hash table (could be avoided with 32 bit values + at the expense of memory usage). We slide even when level == 0 + to keep the hash table consistent if we switch back to level > 0 + later. (Using level 0 permanently is not an optimal usage of + zlib, so we don't care about this pathological case.) + */ + n = s->hash_size; + p = &s->head[n]; + do { + m = *--p; + *p = (Pos)(m >= wsize ? m-wsize : NIL); + } while (--n); + + n = wsize; +#ifndef FASTEST + p = &s->prev[n]; + do { + m = *--p; + *p = (Pos)(m >= wsize ? m-wsize : NIL); + /* If n is not on any hash chain, prev[n] is garbage but + * its value will never be used. + */ + } while (--n); +#endif + more += wsize; + } + if (s->strm->avail_in == 0) break; + + /* If there was no sliding: + * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && + * more == window_size - lookahead - strstart + * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) + * => more >= window_size - 2*WSIZE + 2 + * In the BIG_MEM or MMAP case (not yet supported), + * window_size == input_size + MIN_LOOKAHEAD && + * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. + * Otherwise, window_size == 2*WSIZE so more >= 2. + * If there was sliding, more >= WSIZE. So in all cases, more >= 2. + */ + Assert(more >= 2, "more < 2"); + + n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); + s->lookahead += n; + + /* Initialize the hash value now that we have some input: */ + if (s->lookahead + s->insert >= MIN_MATCH) { + uInt str = s->strstart - s->insert; + s->ins_h = s->window[str]; + UPDATE_HASH(s, s->ins_h, s->window[str + 1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + while (s->insert) { + UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); +#ifndef FASTEST + s->prev[str & s->w_mask] = s->head[s->ins_h]; +#endif + s->head[s->ins_h] = (Pos)str; + str++; + s->insert--; + if (s->lookahead + s->insert < MIN_MATCH) + break; + } + } + /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, + * but this is not important since only literal bytes will be emitted. + */ + + } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); + + /* If the WIN_INIT bytes after the end of the current data have never been + * written, then zero those bytes in order to avoid memory check reports of + * the use of uninitialized (or uninitialised as Julian writes) bytes by + * the longest match routines. Update the high water mark for the next + * time through here. WIN_INIT is set to MAX_MATCH since the longest match + * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. + */ + if (s->high_water < s->window_size) { + ulg curr = s->strstart + (ulg)(s->lookahead); + ulg init; + + if (s->high_water < curr) { + /* Previous high water mark below current data -- zero WIN_INIT + * bytes or up to end of window, whichever is less. + */ + init = s->window_size - curr; + if (init > WIN_INIT) + init = WIN_INIT; + zmemzero(s->window + curr, (unsigned)init); + s->high_water = curr + init; + } + else if (s->high_water < (ulg)curr + WIN_INIT) { + /* High water mark at or above current data, but below current data + * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up + * to end of window, whichever is less. + */ + init = (ulg)curr + WIN_INIT - s->high_water; + if (init > s->window_size - s->high_water) + init = s->window_size - s->high_water; + zmemzero(s->window + s->high_water, (unsigned)init); + s->high_water += init; + } + } + + Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, + "not enough room for search"); +} + +/* =========================================================================== + * Flush the current block, with given end-of-file flag. + * IN assertion: strstart is set to the end of the current match. + */ +#define FLUSH_BLOCK_ONLY(s, last) { \ + _tr_flush_block(s, (s->block_start >= 0L ? \ + (charf *)&s->window[(unsigned)s->block_start] : \ + (charf *)Z_NULL), \ + (ulg)((long)s->strstart - s->block_start), \ + (last)); \ + s->block_start = s->strstart; \ + flush_pending(s->strm); \ + Tracev((stderr,"[FLUSH]")); \ +} + +/* Same but force premature exit if necessary. */ +#define FLUSH_BLOCK(s, last) { \ + FLUSH_BLOCK_ONLY(s, last); \ + if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ +} + +/* =========================================================================== + * Copy without compression as much as possible from the input stream, return + * the current block state. + * This function does not insert new strings in the dictionary since + * uncompressible data is probably not useful. This function is used + * only for the level=0 compression option. + * NOTE: this function should be optimized to avoid extra copying from + * window to pending_buf. + */ +local block_state deflate_stored(s, flush) + deflate_state *s; + int flush; +{ + /* Stored blocks are limited to 0xffff bytes, pending_buf is limited + * to pending_buf_size, and each stored block has a 5 byte header: + */ + ulg max_block_size = 0xffff; + ulg max_start; + + if (max_block_size > s->pending_buf_size - 5) { + max_block_size = s->pending_buf_size - 5; + } + + /* Copy as much as possible from input to output: */ + for (;;) { + /* Fill the window as much as possible: */ + if (s->lookahead <= 1) { + + Assert(s->strstart < s->w_size+MAX_DIST(s) || + s->block_start >= (long)s->w_size, "slide too late"); + + fill_window(s); + if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; + + if (s->lookahead == 0) break; /* flush the current block */ + } + Assert(s->block_start >= 0L, "block gone"); + + s->strstart += s->lookahead; + s->lookahead = 0; + + /* Emit a stored block if pending_buf will be full: */ + max_start = s->block_start + max_block_size; + if (s->strstart == 0 || (ulg)s->strstart >= max_start) { + /* strstart == 0 is possible when wraparound on 16-bit machine */ + s->lookahead = (uInt)(s->strstart - max_start); + s->strstart = (uInt)max_start; + FLUSH_BLOCK(s, 0); + } + /* Flush if we may have to slide, otherwise block_start may become + * negative and the data will be gone: + */ + if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { + FLUSH_BLOCK(s, 0); + } + } + s->insert = 0; + if (flush == Z_FINISH) { + FLUSH_BLOCK(s, 1); + return finish_done; + } + if ((long)s->strstart > s->block_start) + FLUSH_BLOCK(s, 0); + return block_done; +} + +/* =========================================================================== + * Compress as much as possible from the input stream, return the current + * block state. + * This function does not perform lazy evaluation of matches and inserts + * new strings in the dictionary only for unmatched strings or for short + * matches. It is used only for the fast compression options. + */ +local block_state deflate_fast(s, flush) + deflate_state *s; + int flush; +{ + IPos hash_head; /* head of the hash chain */ + int bflush; /* set if current block must be flushed */ + + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + if (s->lookahead < MIN_LOOKAHEAD) { + fill_window(s); + if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + hash_head = NIL; + if (s->lookahead >= MIN_MATCH) { + INSERT_STRING(s, s->strstart, hash_head); + } + + /* Find the longest match, discarding those <= prev_length. + * At this point we have always match_length < MIN_MATCH + */ + if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ + s->match_length = longest_match (s, hash_head); + /* longest_match() sets match_start */ + } + if (s->match_length >= MIN_MATCH) { + check_match(s, s->strstart, s->match_start, s->match_length); + + _tr_tally_dist(s, s->strstart - s->match_start, + s->match_length - MIN_MATCH, bflush); + + s->lookahead -= s->match_length; + + /* Insert new strings in the hash table only if the match length + * is not too large. This saves time but degrades compression. + */ +#ifndef FASTEST + if (s->match_length <= s->max_insert_length && + s->lookahead >= MIN_MATCH) { + s->match_length--; /* string at strstart already in table */ + do { + s->strstart++; + INSERT_STRING(s, s->strstart, hash_head); + /* strstart never exceeds WSIZE-MAX_MATCH, so there are + * always MIN_MATCH bytes ahead. + */ + } while (--s->match_length != 0); + s->strstart++; + } else +#endif + { + s->strstart += s->match_length; + s->match_length = 0; + s->ins_h = s->window[s->strstart]; + UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not + * matter since it will be recomputed at next deflate call. + */ + } + } else { + /* No match, output a literal byte */ + Tracevv((stderr,"%c", s->window[s->strstart])); + _tr_tally_lit (s, s->window[s->strstart], bflush); + s->lookahead--; + s->strstart++; + } + if (bflush) FLUSH_BLOCK(s, 0); + } + s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; + if (flush == Z_FINISH) { + FLUSH_BLOCK(s, 1); + return finish_done; + } + if (s->last_lit) + FLUSH_BLOCK(s, 0); + return block_done; +} + +#ifndef FASTEST +/* =========================================================================== + * Same as above, but achieves better compression. We use a lazy + * evaluation for matches: a match is finally adopted only if there is + * no better match at the next window position. + */ +local block_state deflate_slow(s, flush) + deflate_state *s; + int flush; +{ + IPos hash_head; /* head of hash chain */ + int bflush; /* set if current block must be flushed */ + + /* Process the input block. */ + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + if (s->lookahead < MIN_LOOKAHEAD) { + fill_window(s); + if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + hash_head = NIL; + if (s->lookahead >= MIN_MATCH) { + INSERT_STRING(s, s->strstart, hash_head); + } + + /* Find the longest match, discarding those <= prev_length. + */ + s->prev_length = s->match_length, s->prev_match = s->match_start; + s->match_length = MIN_MATCH-1; + + if (hash_head != NIL && s->prev_length < s->max_lazy_match && + s->strstart - hash_head <= MAX_DIST(s)) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ + s->match_length = longest_match (s, hash_head); + /* longest_match() sets match_start */ + + if (s->match_length <= 5 && (s->strategy == Z_FILTERED +#if TOO_FAR <= 32767 + || (s->match_length == MIN_MATCH && + s->strstart - s->match_start > TOO_FAR) +#endif + )) { + + /* If prev_match is also MIN_MATCH, match_start is garbage + * but we will ignore the current match anyway. + */ + s->match_length = MIN_MATCH-1; + } + } + /* If there was a match at the previous step and the current + * match is not better, output the previous match: + */ + if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { + uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; + /* Do not insert strings in hash table beyond this. */ + + check_match(s, s->strstart-1, s->prev_match, s->prev_length); + + _tr_tally_dist(s, s->strstart -1 - s->prev_match, + s->prev_length - MIN_MATCH, bflush); + + /* Insert in hash table all strings up to the end of the match. + * strstart-1 and strstart are already inserted. If there is not + * enough lookahead, the last two strings are not inserted in + * the hash table. + */ + s->lookahead -= s->prev_length-1; + s->prev_length -= 2; + do { + if (++s->strstart <= max_insert) { + INSERT_STRING(s, s->strstart, hash_head); + } + } while (--s->prev_length != 0); + s->match_available = 0; + s->match_length = MIN_MATCH-1; + s->strstart++; + + if (bflush) FLUSH_BLOCK(s, 0); + + } else if (s->match_available) { + /* If there was no match at the previous position, output a + * single literal. If there was a match but the current match + * is longer, truncate the previous match to a single literal. + */ + Tracevv((stderr,"%c", s->window[s->strstart-1])); + _tr_tally_lit(s, s->window[s->strstart-1], bflush); + if (bflush) { + FLUSH_BLOCK_ONLY(s, 0); + } + s->strstart++; + s->lookahead--; + if (s->strm->avail_out == 0) return need_more; + } else { + /* There is no previous match to compare with, wait for + * the next step to decide. + */ + s->match_available = 1; + s->strstart++; + s->lookahead--; + } + } + Assert (flush != Z_NO_FLUSH, "no flush?"); + if (s->match_available) { + Tracevv((stderr,"%c", s->window[s->strstart-1])); + _tr_tally_lit(s, s->window[s->strstart-1], bflush); + s->match_available = 0; + } + s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; + if (flush == Z_FINISH) { + FLUSH_BLOCK(s, 1); + return finish_done; + } + if (s->last_lit) + FLUSH_BLOCK(s, 0); + return block_done; +} +#endif /* FASTEST */ + +/* =========================================================================== + * For Z_RLE, simply look for runs of bytes, generate matches only of distance + * one. Do not maintain a hash table. (It will be regenerated if this run of + * deflate switches away from Z_RLE.) + */ +local block_state deflate_rle(s, flush) + deflate_state *s; + int flush; +{ + int bflush; /* set if current block must be flushed */ + uInt prev; /* byte at distance one to match */ + Bytef *scan, *strend; /* scan goes up to strend for length of run */ + + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the longest run, plus one for the unrolled loop. + */ + if (s->lookahead <= MAX_MATCH) { + fill_window(s); + if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* See how many times the previous byte repeats */ + s->match_length = 0; + if (s->lookahead >= MIN_MATCH && s->strstart > 0) { + scan = s->window + s->strstart - 1; + prev = *scan; + if (prev == *++scan && prev == *++scan && prev == *++scan) { + strend = s->window + s->strstart + MAX_MATCH; + do { + } while (prev == *++scan && prev == *++scan && + prev == *++scan && prev == *++scan && + prev == *++scan && prev == *++scan && + prev == *++scan && prev == *++scan && + scan < strend); + s->match_length = MAX_MATCH - (int)(strend - scan); + if (s->match_length > s->lookahead) + s->match_length = s->lookahead; + } + Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); + } + + /* Emit match if have run of MIN_MATCH or longer, else emit literal */ + if (s->match_length >= MIN_MATCH) { + check_match(s, s->strstart, s->strstart - 1, s->match_length); + + _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); + + s->lookahead -= s->match_length; + s->strstart += s->match_length; + s->match_length = 0; + } else { + /* No match, output a literal byte */ + Tracevv((stderr,"%c", s->window[s->strstart])); + _tr_tally_lit (s, s->window[s->strstart], bflush); + s->lookahead--; + s->strstart++; + } + if (bflush) FLUSH_BLOCK(s, 0); + } + s->insert = 0; + if (flush == Z_FINISH) { + FLUSH_BLOCK(s, 1); + return finish_done; + } + if (s->last_lit) + FLUSH_BLOCK(s, 0); + return block_done; +} + +/* =========================================================================== + * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. + * (It will be regenerated if this run of deflate switches away from Huffman.) + */ +local block_state deflate_huff(s, flush) + deflate_state *s; + int flush; +{ + int bflush; /* set if current block must be flushed */ + + for (;;) { + /* Make sure that we have a literal to write. */ + if (s->lookahead == 0) { + fill_window(s); + if (s->lookahead == 0) { + if (flush == Z_NO_FLUSH) + return need_more; + break; /* flush the current block */ + } + } + + /* Output a literal byte */ + s->match_length = 0; + Tracevv((stderr,"%c", s->window[s->strstart])); + _tr_tally_lit (s, s->window[s->strstart], bflush); + s->lookahead--; + s->strstart++; + if (bflush) FLUSH_BLOCK(s, 0); + } + s->insert = 0; + if (flush == Z_FINISH) { + FLUSH_BLOCK(s, 1); + return finish_done; + } + if (s->last_lit) + FLUSH_BLOCK(s, 0); + return block_done; +} diff --git a/Source/ZLib/deflate.h b/Source/ZLib/deflate.h index 297b4f0..e289b13 100644 --- a/Source/ZLib/deflate.h +++ b/Source/ZLib/deflate.h @@ -1,346 +1,346 @@ -/* deflate.h -- internal compression state - * Copyright (C) 1995-2012 Jean-loup Gailly - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* @(#) $Id: deflate.h,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ - -#ifndef DEFLATE_H -#define DEFLATE_H - -#include "zutil.h" - -/* define NO_GZIP when compiling if you want to disable gzip header and - trailer creation by deflate(). NO_GZIP would be used to avoid linking in - the crc code when it is not needed. For shared libraries, gzip encoding - should be left enabled. */ -#ifndef NO_GZIP -# define GZIP -#endif - -/* =========================================================================== - * Internal compression state. - */ - -#define LENGTH_CODES 29 -/* number of length codes, not counting the special END_BLOCK code */ - -#define LITERALS 256 -/* number of literal bytes 0..255 */ - -#define L_CODES (LITERALS+1+LENGTH_CODES) -/* number of Literal or Length codes, including the END_BLOCK code */ - -#define D_CODES 30 -/* number of distance codes */ - -#define BL_CODES 19 -/* number of codes used to transfer the bit lengths */ - -#define HEAP_SIZE (2*L_CODES+1) -/* maximum heap size */ - -#define MAX_BITS 15 -/* All codes must not exceed MAX_BITS bits */ - -#define Buf_size 16 -/* size of bit buffer in bi_buf */ - -#define INIT_STATE 42 -#define EXTRA_STATE 69 -#define NAME_STATE 73 -#define COMMENT_STATE 91 -#define HCRC_STATE 103 -#define BUSY_STATE 113 -#define FINISH_STATE 666 -/* Stream status */ - - -/* Data structure describing a single value and its code string. */ -typedef struct ct_data_s { - union { - ush freq; /* frequency count */ - ush code; /* bit string */ - } fc; - union { - ush dad; /* father node in Huffman tree */ - ush len; /* length of bit string */ - } dl; -} FAR ct_data; - -#define Freq fc.freq -#define Code fc.code -#define Dad dl.dad -#define Len dl.len - -typedef struct static_tree_desc_s static_tree_desc; - -typedef struct tree_desc_s { - ct_data *dyn_tree; /* the dynamic tree */ - int max_code; /* largest code with non zero frequency */ - static_tree_desc *stat_desc; /* the corresponding static tree */ -} FAR tree_desc; - -typedef ush Pos; -typedef Pos FAR Posf; -typedef unsigned IPos; - -/* A Pos is an index in the character window. We use short instead of int to - * save space in the various tables. IPos is used only for parameter passing. - */ - -typedef struct internal_state { - z_streamp strm; /* pointer back to this zlib stream */ - int status; /* as the name implies */ - Bytef *pending_buf; /* output still pending */ - ulg pending_buf_size; /* size of pending_buf */ - Bytef *pending_out; /* next pending byte to output to the stream */ - uInt pending; /* nb of bytes in the pending buffer */ - int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ - gz_headerp gzhead; /* gzip header information to write */ - uInt gzindex; /* where in extra, name, or comment */ - Byte method; /* STORED (for zip only) or DEFLATED */ - int last_flush; /* value of flush param for previous deflate call */ - - /* used by deflate.c: */ - - uInt w_size; /* LZ77 window size (32K by default) */ - uInt w_bits; /* log2(w_size) (8..16) */ - uInt w_mask; /* w_size - 1 */ - - Bytef *window; - /* Sliding window. Input bytes are read into the second half of the window, - * and move to the first half later to keep a dictionary of at least wSize - * bytes. With this organization, matches are limited to a distance of - * wSize-MAX_MATCH bytes, but this ensures that IO is always - * performed with a length multiple of the block size. Also, it limits - * the window size to 64K, which is quite useful on MSDOS. - * To do: use the user input buffer as sliding window. - */ - - ulg window_size; - /* Actual size of window: 2*wSize, except when the user input buffer - * is directly used as sliding window. - */ - - Posf *prev; - /* Link to older string with same hash index. To limit the size of this - * array to 64K, this link is maintained only for the last 32K strings. - * An index in this array is thus a window index modulo 32K. - */ - - Posf *head; /* Heads of the hash chains or NIL. */ - - uInt ins_h; /* hash index of string to be inserted */ - uInt hash_size; /* number of elements in hash table */ - uInt hash_bits; /* log2(hash_size) */ - uInt hash_mask; /* hash_size-1 */ - - uInt hash_shift; - /* Number of bits by which ins_h must be shifted at each input - * step. It must be such that after MIN_MATCH steps, the oldest - * byte no longer takes part in the hash key, that is: - * hash_shift * MIN_MATCH >= hash_bits - */ - - long block_start; - /* Window position at the beginning of the current output block. Gets - * negative when the window is moved backwards. - */ - - uInt match_length; /* length of best match */ - IPos prev_match; /* previous match */ - int match_available; /* set if previous match exists */ - uInt strstart; /* start of string to insert */ - uInt match_start; /* start of matching string */ - uInt lookahead; /* number of valid bytes ahead in window */ - - uInt prev_length; - /* Length of the best match at previous step. Matches not greater than this - * are discarded. This is used in the lazy match evaluation. - */ - - uInt max_chain_length; - /* To speed up deflation, hash chains are never searched beyond this - * length. A higher limit improves compression ratio but degrades the - * speed. - */ - - uInt max_lazy_match; - /* Attempt to find a better match only when the current match is strictly - * smaller than this value. This mechanism is used only for compression - * levels >= 4. - */ -# define max_insert_length max_lazy_match - /* Insert new strings in the hash table only if the match length is not - * greater than this length. This saves time but degrades compression. - * max_insert_length is used only for compression levels <= 3. - */ - - int level; /* compression level (1..9) */ - int strategy; /* favor or force Huffman coding*/ - - uInt good_match; - /* Use a faster search when the previous match is longer than this */ - - int nice_match; /* Stop searching when current match exceeds this */ - - /* used by trees.c: */ - /* Didn't use ct_data typedef below to suppress compiler warning */ - struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ - struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ - struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ - - struct tree_desc_s l_desc; /* desc. for literal tree */ - struct tree_desc_s d_desc; /* desc. for distance tree */ - struct tree_desc_s bl_desc; /* desc. for bit length tree */ - - ush bl_count[MAX_BITS+1]; - /* number of codes at each bit length for an optimal tree */ - - int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ - int heap_len; /* number of elements in the heap */ - int heap_max; /* element of largest frequency */ - /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. - * The same heap array is used to build all trees. - */ - - uch depth[2*L_CODES+1]; - /* Depth of each subtree used as tie breaker for trees of equal frequency - */ - - uchf *l_buf; /* buffer for literals or lengths */ - - uInt lit_bufsize; - /* Size of match buffer for literals/lengths. There are 4 reasons for - * limiting lit_bufsize to 64K: - * - frequencies can be kept in 16 bit counters - * - if compression is not successful for the first block, all input - * data is still in the window so we can still emit a stored block even - * when input comes from standard input. (This can also be done for - * all blocks if lit_bufsize is not greater than 32K.) - * - if compression is not successful for a file smaller than 64K, we can - * even emit a stored file instead of a stored block (saving 5 bytes). - * This is applicable only for zip (not gzip or zlib). - * - creating new Huffman trees less frequently may not provide fast - * adaptation to changes in the input data statistics. (Take for - * example a binary file with poorly compressible code followed by - * a highly compressible string table.) Smaller buffer sizes give - * fast adaptation but have of course the overhead of transmitting - * trees more frequently. - * - I can't count above 4 - */ - - uInt last_lit; /* running index in l_buf */ - - ushf *d_buf; - /* Buffer for distances. To simplify the code, d_buf and l_buf have - * the same number of elements. To use different lengths, an extra flag - * array would be necessary. - */ - - ulg opt_len; /* bit length of current block with optimal trees */ - ulg static_len; /* bit length of current block with static trees */ - uInt matches; /* number of string matches in current block */ - uInt insert; /* bytes at end of window left to insert */ - -#ifdef DEBUG - ulg compressed_len; /* total bit length of compressed file mod 2^32 */ - ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ -#endif - - ush bi_buf; - /* Output buffer. bits are inserted starting at the bottom (least - * significant bits). - */ - int bi_valid; - /* Number of valid bits in bi_buf. All bits above the last valid bit - * are always zero. - */ - - ulg high_water; - /* High water mark offset in window for initialized bytes -- bytes above - * this are set to zero in order to avoid memory check warnings when - * longest match routines access bytes past the input. This is then - * updated to the new high water mark. - */ - -} FAR deflate_state; - -/* Output a byte on the stream. - * IN assertion: there is enough room in pending_buf. - */ -#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} - - -#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) -/* Minimum amount of lookahead, except at the end of the input file. - * See deflate.c for comments about the MIN_MATCH+1. - */ - -#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) -/* In order to simplify the code, particularly on 16 bit machines, match - * distances are limited to MAX_DIST instead of WSIZE. - */ - -#define WIN_INIT MAX_MATCH -/* Number of bytes after end of data in window to initialize in order to avoid - memory checker errors from longest match routines */ - - /* in trees.c */ -void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); -int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); -void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); -void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); - -#define d_code(dist) \ - ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) -/* Mapping from a distance to a distance code. dist is the distance - 1 and - * must not have side effects. _dist_code[256] and _dist_code[257] are never - * used. - */ - -#ifndef DEBUG -/* Inline versions of _tr_tally for speed: */ - -#if defined(GEN_TREES_H) || !defined(STDC) - extern uch ZLIB_INTERNAL _length_code[]; - extern uch ZLIB_INTERNAL _dist_code[]; -#else - extern const uch ZLIB_INTERNAL _length_code[]; - extern const uch ZLIB_INTERNAL _dist_code[]; -#endif - -# define _tr_tally_lit(s, c, flush) \ - { uch cc = (c); \ - s->d_buf[s->last_lit] = 0; \ - s->l_buf[s->last_lit++] = cc; \ - s->dyn_ltree[cc].Freq++; \ - flush = (s->last_lit == s->lit_bufsize-1); \ - } -# define _tr_tally_dist(s, distance, length, flush) \ - { uch len = (length); \ - ush dist = (distance); \ - s->d_buf[s->last_lit] = dist; \ - s->l_buf[s->last_lit++] = len; \ - dist--; \ - s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ - s->dyn_dtree[d_code(dist)].Freq++; \ - flush = (s->last_lit == s->lit_bufsize-1); \ - } -#else -# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) -# define _tr_tally_dist(s, distance, length, flush) \ - flush = _tr_tally(s, distance, length) -#endif - -#endif /* DEFLATE_H */ +/* deflate.h -- internal compression state + * Copyright (C) 1995-2012 Jean-loup Gailly + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* @(#) $Id: deflate.h,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ + +#ifndef DEFLATE_H +#define DEFLATE_H + +#include "zutil.h" + +/* define NO_GZIP when compiling if you want to disable gzip header and + trailer creation by deflate(). NO_GZIP would be used to avoid linking in + the crc code when it is not needed. For shared libraries, gzip encoding + should be left enabled. */ +#ifndef NO_GZIP +# define GZIP +#endif + +/* =========================================================================== + * Internal compression state. + */ + +#define LENGTH_CODES 29 +/* number of length codes, not counting the special END_BLOCK code */ + +#define LITERALS 256 +/* number of literal bytes 0..255 */ + +#define L_CODES (LITERALS+1+LENGTH_CODES) +/* number of Literal or Length codes, including the END_BLOCK code */ + +#define D_CODES 30 +/* number of distance codes */ + +#define BL_CODES 19 +/* number of codes used to transfer the bit lengths */ + +#define HEAP_SIZE (2*L_CODES+1) +/* maximum heap size */ + +#define MAX_BITS 15 +/* All codes must not exceed MAX_BITS bits */ + +#define Buf_size 16 +/* size of bit buffer in bi_buf */ + +#define INIT_STATE 42 +#define EXTRA_STATE 69 +#define NAME_STATE 73 +#define COMMENT_STATE 91 +#define HCRC_STATE 103 +#define BUSY_STATE 113 +#define FINISH_STATE 666 +/* Stream status */ + + +/* Data structure describing a single value and its code string. */ +typedef struct ct_data_s { + union { + ush freq; /* frequency count */ + ush code; /* bit string */ + } fc; + union { + ush dad; /* father node in Huffman tree */ + ush len; /* length of bit string */ + } dl; +} FAR ct_data; + +#define Freq fc.freq +#define Code fc.code +#define Dad dl.dad +#define Len dl.len + +typedef struct static_tree_desc_s static_tree_desc; + +typedef struct tree_desc_s { + ct_data *dyn_tree; /* the dynamic tree */ + int max_code; /* largest code with non zero frequency */ + static_tree_desc *stat_desc; /* the corresponding static tree */ +} FAR tree_desc; + +typedef ush Pos; +typedef Pos FAR Posf; +typedef unsigned IPos; + +/* A Pos is an index in the character window. We use short instead of int to + * save space in the various tables. IPos is used only for parameter passing. + */ + +typedef struct internal_state { + z_streamp strm; /* pointer back to this zlib stream */ + int status; /* as the name implies */ + Bytef *pending_buf; /* output still pending */ + ulg pending_buf_size; /* size of pending_buf */ + Bytef *pending_out; /* next pending byte to output to the stream */ + uInt pending; /* nb of bytes in the pending buffer */ + int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ + gz_headerp gzhead; /* gzip header information to write */ + uInt gzindex; /* where in extra, name, or comment */ + Byte method; /* STORED (for zip only) or DEFLATED */ + int last_flush; /* value of flush param for previous deflate call */ + + /* used by deflate.c: */ + + uInt w_size; /* LZ77 window size (32K by default) */ + uInt w_bits; /* log2(w_size) (8..16) */ + uInt w_mask; /* w_size - 1 */ + + Bytef *window; + /* Sliding window. Input bytes are read into the second half of the window, + * and move to the first half later to keep a dictionary of at least wSize + * bytes. With this organization, matches are limited to a distance of + * wSize-MAX_MATCH bytes, but this ensures that IO is always + * performed with a length multiple of the block size. Also, it limits + * the window size to 64K, which is quite useful on MSDOS. + * To do: use the user input buffer as sliding window. + */ + + ulg window_size; + /* Actual size of window: 2*wSize, except when the user input buffer + * is directly used as sliding window. + */ + + Posf *prev; + /* Link to older string with same hash index. To limit the size of this + * array to 64K, this link is maintained only for the last 32K strings. + * An index in this array is thus a window index modulo 32K. + */ + + Posf *head; /* Heads of the hash chains or NIL. */ + + uInt ins_h; /* hash index of string to be inserted */ + uInt hash_size; /* number of elements in hash table */ + uInt hash_bits; /* log2(hash_size) */ + uInt hash_mask; /* hash_size-1 */ + + uInt hash_shift; + /* Number of bits by which ins_h must be shifted at each input + * step. It must be such that after MIN_MATCH steps, the oldest + * byte no longer takes part in the hash key, that is: + * hash_shift * MIN_MATCH >= hash_bits + */ + + long block_start; + /* Window position at the beginning of the current output block. Gets + * negative when the window is moved backwards. + */ + + uInt match_length; /* length of best match */ + IPos prev_match; /* previous match */ + int match_available; /* set if previous match exists */ + uInt strstart; /* start of string to insert */ + uInt match_start; /* start of matching string */ + uInt lookahead; /* number of valid bytes ahead in window */ + + uInt prev_length; + /* Length of the best match at previous step. Matches not greater than this + * are discarded. This is used in the lazy match evaluation. + */ + + uInt max_chain_length; + /* To speed up deflation, hash chains are never searched beyond this + * length. A higher limit improves compression ratio but degrades the + * speed. + */ + + uInt max_lazy_match; + /* Attempt to find a better match only when the current match is strictly + * smaller than this value. This mechanism is used only for compression + * levels >= 4. + */ +# define max_insert_length max_lazy_match + /* Insert new strings in the hash table only if the match length is not + * greater than this length. This saves time but degrades compression. + * max_insert_length is used only for compression levels <= 3. + */ + + int level; /* compression level (1..9) */ + int strategy; /* favor or force Huffman coding*/ + + uInt good_match; + /* Use a faster search when the previous match is longer than this */ + + int nice_match; /* Stop searching when current match exceeds this */ + + /* used by trees.c: */ + /* Didn't use ct_data typedef below to suppress compiler warning */ + struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ + struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ + struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ + + struct tree_desc_s l_desc; /* desc. for literal tree */ + struct tree_desc_s d_desc; /* desc. for distance tree */ + struct tree_desc_s bl_desc; /* desc. for bit length tree */ + + ush bl_count[MAX_BITS+1]; + /* number of codes at each bit length for an optimal tree */ + + int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ + int heap_len; /* number of elements in the heap */ + int heap_max; /* element of largest frequency */ + /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. + * The same heap array is used to build all trees. + */ + + uch depth[2*L_CODES+1]; + /* Depth of each subtree used as tie breaker for trees of equal frequency + */ + + uchf *l_buf; /* buffer for literals or lengths */ + + uInt lit_bufsize; + /* Size of match buffer for literals/lengths. There are 4 reasons for + * limiting lit_bufsize to 64K: + * - frequencies can be kept in 16 bit counters + * - if compression is not successful for the first block, all input + * data is still in the window so we can still emit a stored block even + * when input comes from standard input. (This can also be done for + * all blocks if lit_bufsize is not greater than 32K.) + * - if compression is not successful for a file smaller than 64K, we can + * even emit a stored file instead of a stored block (saving 5 bytes). + * This is applicable only for zip (not gzip or zlib). + * - creating new Huffman trees less frequently may not provide fast + * adaptation to changes in the input data statistics. (Take for + * example a binary file with poorly compressible code followed by + * a highly compressible string table.) Smaller buffer sizes give + * fast adaptation but have of course the overhead of transmitting + * trees more frequently. + * - I can't count above 4 + */ + + uInt last_lit; /* running index in l_buf */ + + ushf *d_buf; + /* Buffer for distances. To simplify the code, d_buf and l_buf have + * the same number of elements. To use different lengths, an extra flag + * array would be necessary. + */ + + ulg opt_len; /* bit length of current block with optimal trees */ + ulg static_len; /* bit length of current block with static trees */ + uInt matches; /* number of string matches in current block */ + uInt insert; /* bytes at end of window left to insert */ + +#ifdef DEBUG + ulg compressed_len; /* total bit length of compressed file mod 2^32 */ + ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ +#endif + + ush bi_buf; + /* Output buffer. bits are inserted starting at the bottom (least + * significant bits). + */ + int bi_valid; + /* Number of valid bits in bi_buf. All bits above the last valid bit + * are always zero. + */ + + ulg high_water; + /* High water mark offset in window for initialized bytes -- bytes above + * this are set to zero in order to avoid memory check warnings when + * longest match routines access bytes past the input. This is then + * updated to the new high water mark. + */ + +} FAR deflate_state; + +/* Output a byte on the stream. + * IN assertion: there is enough room in pending_buf. + */ +#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} + + +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) +/* Minimum amount of lookahead, except at the end of the input file. + * See deflate.c for comments about the MIN_MATCH+1. + */ + +#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) +/* In order to simplify the code, particularly on 16 bit machines, match + * distances are limited to MAX_DIST instead of WSIZE. + */ + +#define WIN_INIT MAX_MATCH +/* Number of bytes after end of data in window to initialize in order to avoid + memory checker errors from longest match routines */ + + /* in trees.c */ +void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); +int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); +void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, + ulg stored_len, int last)); +void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); +void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); +void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, + ulg stored_len, int last)); + +#define d_code(dist) \ + ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) +/* Mapping from a distance to a distance code. dist is the distance - 1 and + * must not have side effects. _dist_code[256] and _dist_code[257] are never + * used. + */ + +#ifndef DEBUG +/* Inline versions of _tr_tally for speed: */ + +#if defined(GEN_TREES_H) || !defined(STDC) + extern uch ZLIB_INTERNAL _length_code[]; + extern uch ZLIB_INTERNAL _dist_code[]; +#else + extern const uch ZLIB_INTERNAL _length_code[]; + extern const uch ZLIB_INTERNAL _dist_code[]; +#endif + +# define _tr_tally_lit(s, c, flush) \ + { uch cc = (c); \ + s->d_buf[s->last_lit] = 0; \ + s->l_buf[s->last_lit++] = cc; \ + s->dyn_ltree[cc].Freq++; \ + flush = (s->last_lit == s->lit_bufsize-1); \ + } +# define _tr_tally_dist(s, distance, length, flush) \ + { uch len = (length); \ + ush dist = (distance); \ + s->d_buf[s->last_lit] = dist; \ + s->l_buf[s->last_lit++] = len; \ + dist--; \ + s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ + s->dyn_dtree[d_code(dist)].Freq++; \ + flush = (s->last_lit == s->lit_bufsize-1); \ + } +#else +# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) +# define _tr_tally_dist(s, distance, length, flush) \ + flush = _tr_tally(s, distance, length) +#endif + +#endif /* DEFLATE_H */ diff --git a/Source/ZLib/trees.c b/Source/ZLib/trees.c index ac98942..ac2696b 100644 --- a/Source/ZLib/trees.c +++ b/Source/ZLib/trees.c @@ -1,1224 +1,1224 @@ -/* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2012 Jean-loup Gailly - * detect_data_type() function provided freely by Cosmin Truta, 2006 - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * ALGORITHM - * - * The "deflation" process uses several Huffman trees. The more - * common source values are represented by shorter bit sequences. - * - * Each code tree is stored in a compressed form which is itself - * a Huffman encoding of the lengths of all the code strings (in - * ascending order by source values). The actual code strings are - * reconstructed from the lengths in the inflate process, as described - * in the deflate specification. - * - * REFERENCES - * - * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". - * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc - * - * Storer, James A. - * Data Compression: Methods and Theory, pp. 49-50. - * Computer Science Press, 1988. ISBN 0-7167-8156-5. - * - * Sedgewick, R. - * Algorithms, p290. - * Addison-Wesley, 1983. ISBN 0-201-06672-6. - */ - -/* @(#) $Id: trees.c,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ - -/* #define GEN_TREES_H */ - -#include "deflate.h" - -#ifdef DEBUG -# include -#endif - -/* =========================================================================== - * Constants - */ - -#define MAX_BL_BITS 7 -/* Bit length codes must not exceed MAX_BL_BITS bits */ - -#define END_BLOCK 256 -/* end of block literal code */ - -#define REP_3_6 16 -/* repeat previous bit length 3-6 times (2 bits of repeat count) */ - -#define REPZ_3_10 17 -/* repeat a zero length 3-10 times (3 bits of repeat count) */ - -#define REPZ_11_138 18 -/* repeat a zero length 11-138 times (7 bits of repeat count) */ - -local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ - = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; - -local const int extra_dbits[D_CODES] /* extra bits for each distance code */ - = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; - -local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ - = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; - -local const uch bl_order[BL_CODES] - = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; -/* The lengths of the bit length codes are sent in order of decreasing - * probability, to avoid transmitting the lengths for unused bit length codes. - */ - -/* =========================================================================== - * Local data. These are initialized only once. - */ - -#define DIST_CODE_LEN 512 /* see definition of array dist_code below */ - -#if defined(GEN_TREES_H) || !defined(STDC) -/* non ANSI compilers may not accept trees.h */ - -local ct_data static_ltree[L_CODES+2]; -/* The static literal tree. Since the bit lengths are imposed, there is no - * need for the L_CODES extra codes used during heap construction. However - * The codes 286 and 287 are needed to build a canonical tree (see _tr_init - * below). - */ - -local ct_data static_dtree[D_CODES]; -/* The static distance tree. (Actually a trivial tree since all codes use - * 5 bits.) - */ - -uch _dist_code[DIST_CODE_LEN]; -/* Distance codes. The first 256 values correspond to the distances - * 3 .. 258, the last 256 values correspond to the top 8 bits of - * the 15 bit distances. - */ - -uch _length_code[MAX_MATCH-MIN_MATCH+1]; -/* length code for each normalized match length (0 == MIN_MATCH) */ - -local int base_length[LENGTH_CODES]; -/* First normalized length for each code (0 = MIN_MATCH) */ - -local int base_dist[D_CODES]; -/* First normalized distance for each code (0 = distance of 1) */ - -#else -# include "trees.h" -#endif /* GEN_TREES_H */ - -struct static_tree_desc_s { - const ct_data *static_tree; /* static tree or NULL */ - const intf *extra_bits; /* extra bits for each code or NULL */ - int extra_base; /* base index for extra_bits */ - int elems; /* max number of elements in the tree */ - int max_length; /* max bit length for the codes */ -}; - -local static_tree_desc static_l_desc = -{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; - -local static_tree_desc static_d_desc = -{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; - -local static_tree_desc static_bl_desc = -{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; - -/* =========================================================================== - * Local (static) routines in this file. - */ - -local void tr_static_init OF((void)); -local void init_block OF((deflate_state *s)); -local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); -local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); -local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); -local void build_tree OF((deflate_state *s, tree_desc *desc)); -local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local int build_bl_tree OF((deflate_state *s)); -local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, - int blcodes)); -local void compress_block OF((deflate_state *s, ct_data *ltree, - ct_data *dtree)); -local int detect_data_type OF((deflate_state *s)); -local unsigned bi_reverse OF((unsigned value, int length)); -local void bi_windup OF((deflate_state *s)); -local void bi_flush OF((deflate_state *s)); -local void copy_block OF((deflate_state *s, charf *buf, unsigned len, - int header)); - -#ifdef GEN_TREES_H -local void gen_trees_header OF((void)); -#endif - -#ifndef DEBUG -# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) - /* Send a code of the given tree. c and tree must not have side effects */ - -#else /* DEBUG */ -# define send_code(s, c, tree) \ - { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ - send_bits(s, tree[c].Code, tree[c].Len); } -#endif - -/* =========================================================================== - * Output a short LSB first on the stream. - * IN assertion: there is enough room in pendingBuf. - */ -#define put_short(s, w) { \ - put_byte(s, (uch)((w) & 0xff)); \ - put_byte(s, (uch)((ush)(w) >> 8)); \ -} - -/* =========================================================================== - * Send a value on a given number of bits. - * IN assertion: length <= 16 and value fits in length bits. - */ -#ifdef DEBUG -local void send_bits OF((deflate_state *s, int value, int length)); - -local void send_bits(s, value, length) - deflate_state *s; - int value; /* value to send */ - int length; /* number of bits */ -{ - Tracevv((stderr," l %2d v %4x ", length, value)); - Assert(length > 0 && length <= 15, "invalid length"); - s->bits_sent += (ulg)length; - - /* If not enough room in bi_buf, use (valid) bits from bi_buf and - * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) - * unused bits in value. - */ - if (s->bi_valid > (int)Buf_size - length) { - s->bi_buf |= (ush)value << s->bi_valid; - put_short(s, s->bi_buf); - s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); - s->bi_valid += length - Buf_size; - } else { - s->bi_buf |= (ush)value << s->bi_valid; - s->bi_valid += length; - } -} -#else /* !DEBUG */ - -#define send_bits(s, value, length) \ -{ int len = length;\ - if (s->bi_valid > (int)Buf_size - len) {\ - int val = value;\ - s->bi_buf |= (ush)val << s->bi_valid;\ - put_short(s, s->bi_buf);\ - s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ - s->bi_valid += len - Buf_size;\ - } else {\ - s->bi_buf |= (ush)(value) << s->bi_valid;\ - s->bi_valid += len;\ - }\ -} -#endif /* DEBUG */ - - -/* the arguments must not have side effects */ - -/* =========================================================================== - * Initialize the various 'constant' tables. - */ -local void tr_static_init() -{ -#if defined(GEN_TREES_H) || !defined(STDC) - static int static_init_done = 0; - int n; /* iterates over tree elements */ - int bits; /* bit counter */ - int length; /* length value */ - int code; /* code value */ - int dist; /* distance index */ - ush bl_count[MAX_BITS+1]; - /* number of codes at each bit length for an optimal tree */ - - if (static_init_done) return; - - /* For some embedded targets, global variables are not initialized: */ -#ifdef NO_INIT_GLOBAL_POINTERS - static_l_desc.static_tree = static_ltree; - static_l_desc.extra_bits = extra_lbits; - static_d_desc.static_tree = static_dtree; - static_d_desc.extra_bits = extra_dbits; - static_bl_desc.extra_bits = extra_blbits; -#endif - - /* Initialize the mapping length (0..255) -> length code (0..28) */ - length = 0; - for (code = 0; code < LENGTH_CODES-1; code++) { - base_length[code] = length; - for (n = 0; n < (1< dist code (0..29) */ - dist = 0; - for (code = 0 ; code < 16; code++) { - base_dist[code] = dist; - for (n = 0; n < (1<>= 7; /* from now on, all distances are divided by 128 */ - for ( ; code < D_CODES; code++) { - base_dist[code] = dist << 7; - for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { - _dist_code[256 + dist++] = (uch)code; - } - } - Assert (dist == 256, "tr_static_init: 256+dist != 512"); - - /* Construct the codes of the static literal tree */ - for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; - n = 0; - while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; - while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; - while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; - while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; - /* Codes 286 and 287 do not exist, but we must include them in the - * tree construction to get a canonical Huffman tree (longest code - * all ones) - */ - gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); - - /* The static distance tree is trivial: */ - for (n = 0; n < D_CODES; n++) { - static_dtree[n].Len = 5; - static_dtree[n].Code = bi_reverse((unsigned)n, 5); - } - static_init_done = 1; - -# ifdef GEN_TREES_H - gen_trees_header(); -# endif -#endif /* defined(GEN_TREES_H) || !defined(STDC) */ -} - -/* =========================================================================== - * Genererate the file trees.h describing the static trees. - */ -#ifdef GEN_TREES_H -# ifndef DEBUG -# include -# endif - -# define SEPARATOR(i, last, width) \ - ((i) == (last)? "\n};\n\n" : \ - ((i) % (width) == (width)-1 ? ",\n" : ", ")) - -void gen_trees_header() -{ - FILE *header = fopen("trees.h", "w"); - int i; - - Assert (header != NULL, "Can't open trees.h"); - fprintf(header, - "/* header created automatically with -DGEN_TREES_H */\n\n"); - - fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); - for (i = 0; i < L_CODES+2; i++) { - fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, - static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); - } - - fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); - for (i = 0; i < D_CODES; i++) { - fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, - static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); - } - - fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n"); - for (i = 0; i < DIST_CODE_LEN; i++) { - fprintf(header, "%2u%s", _dist_code[i], - SEPARATOR(i, DIST_CODE_LEN-1, 20)); - } - - fprintf(header, - "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); - for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { - fprintf(header, "%2u%s", _length_code[i], - SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); - } - - fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); - for (i = 0; i < LENGTH_CODES; i++) { - fprintf(header, "%1u%s", base_length[i], - SEPARATOR(i, LENGTH_CODES-1, 20)); - } - - fprintf(header, "local const int base_dist[D_CODES] = {\n"); - for (i = 0; i < D_CODES; i++) { - fprintf(header, "%5u%s", base_dist[i], - SEPARATOR(i, D_CODES-1, 10)); - } - - fclose(header); -} -#endif /* GEN_TREES_H */ - -/* =========================================================================== - * Initialize the tree data structures for a new zlib stream. - */ -void ZLIB_INTERNAL _tr_init(s) - deflate_state *s; -{ - tr_static_init(); - - s->l_desc.dyn_tree = s->dyn_ltree; - s->l_desc.stat_desc = &static_l_desc; - - s->d_desc.dyn_tree = s->dyn_dtree; - s->d_desc.stat_desc = &static_d_desc; - - s->bl_desc.dyn_tree = s->bl_tree; - s->bl_desc.stat_desc = &static_bl_desc; - - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef DEBUG - s->compressed_len = 0L; - s->bits_sent = 0L; -#endif - - /* Initialize the first block of the first file: */ - init_block(s); -} - -/* =========================================================================== - * Initialize a new block. - */ -local void init_block(s) - deflate_state *s; -{ - int n; /* iterates over tree elements */ - - /* Initialize the trees. */ - for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; - for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; - for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; - - s->dyn_ltree[END_BLOCK].Freq = 1; - s->opt_len = s->static_len = 0L; - s->last_lit = s->matches = 0; -} - -#define SMALLEST 1 -/* Index within the heap array of least frequent node in the Huffman tree */ - - -/* =========================================================================== - * Remove the smallest element from the heap and recreate the heap with - * one less element. Updates heap and heap_len. - */ -#define pqremove(s, tree, top) \ -{\ - top = s->heap[SMALLEST]; \ - s->heap[SMALLEST] = s->heap[s->heap_len--]; \ - pqdownheap(s, tree, SMALLEST); \ -} - -/* =========================================================================== - * Compares to subtrees, using the tree depth as tie breaker when - * the subtrees have equal frequency. This minimizes the worst case length. - */ -#define smaller(tree, n, m, depth) \ - (tree[n].Freq < tree[m].Freq || \ - (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) - -/* =========================================================================== - * Restore the heap property by moving down the tree starting at node k, - * exchanging a node with the smallest of its two sons if necessary, stopping - * when the heap property is re-established (each father smaller than its - * two sons). - */ -local void pqdownheap(s, tree, k) - deflate_state *s; - ct_data *tree; /* the tree to restore */ - int k; /* node to move down */ -{ - int v = s->heap[k]; - int j = k << 1; /* left son of k */ - while (j <= s->heap_len) { - /* Set j to the smallest of the two sons: */ - if (j < s->heap_len && - smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { - j++; - } - /* Exit if v is smaller than both sons */ - if (smaller(tree, v, s->heap[j], s->depth)) break; - - /* Exchange v with the smallest son */ - s->heap[k] = s->heap[j]; k = j; - - /* And continue down the tree, setting j to the left son of k */ - j <<= 1; - } - s->heap[k] = v; -} - -/* =========================================================================== - * Compute the optimal bit lengths for a tree and update the total bit length - * for the current block. - * IN assertion: the fields freq and dad are set, heap[heap_max] and - * above are the tree nodes sorted by increasing frequency. - * OUT assertions: the field len is set to the optimal bit length, the - * array bl_count contains the frequencies for each bit length. - * The length opt_len is updated; static_len is also updated if stree is - * not null. - */ -local void gen_bitlen(s, desc) - deflate_state *s; - tree_desc *desc; /* the tree descriptor */ -{ - ct_data *tree = desc->dyn_tree; - int max_code = desc->max_code; - const ct_data *stree = desc->stat_desc->static_tree; - const intf *extra = desc->stat_desc->extra_bits; - int base = desc->stat_desc->extra_base; - int max_length = desc->stat_desc->max_length; - int h; /* heap index */ - int n, m; /* iterate over the tree elements */ - int bits; /* bit length */ - int xbits; /* extra bits */ - ush f; /* frequency */ - int overflow = 0; /* number of elements with bit length too large */ - - for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; - - /* In a first pass, compute the optimal bit lengths (which may - * overflow in the case of the bit length tree). - */ - tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ - - for (h = s->heap_max+1; h < HEAP_SIZE; h++) { - n = s->heap[h]; - bits = tree[tree[n].Dad].Len + 1; - if (bits > max_length) bits = max_length, overflow++; - tree[n].Len = (ush)bits; - /* We overwrite tree[n].Dad which is no longer needed */ - - if (n > max_code) continue; /* not a leaf node */ - - s->bl_count[bits]++; - xbits = 0; - if (n >= base) xbits = extra[n-base]; - f = tree[n].Freq; - s->opt_len += (ulg)f * (bits + xbits); - if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); - } - if (overflow == 0) return; - - Trace((stderr,"\nbit length overflow\n")); - /* This happens for example on obj2 and pic of the Calgary corpus */ - - /* Find the first bit length which could increase: */ - do { - bits = max_length-1; - while (s->bl_count[bits] == 0) bits--; - s->bl_count[bits]--; /* move one leaf down the tree */ - s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ - s->bl_count[max_length]--; - /* The brother of the overflow item also moves one step up, - * but this does not affect bl_count[max_length] - */ - overflow -= 2; - } while (overflow > 0); - - /* Now recompute all bit lengths, scanning in increasing frequency. - * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all - * lengths instead of fixing only the wrong ones. This idea is taken - * from 'ar' written by Haruhiko Okumura.) - */ - for (bits = max_length; bits != 0; bits--) { - n = s->bl_count[bits]; - while (n != 0) { - m = s->heap[--h]; - if (m > max_code) continue; - if ((unsigned) tree[m].Len != (unsigned) bits) { - Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); - s->opt_len += ((long)bits - (long)tree[m].Len) - *(long)tree[m].Freq; - tree[m].Len = (ush)bits; - } - n--; - } - } -} - -/* =========================================================================== - * Generate the codes for a given tree and bit counts (which need not be - * optimal). - * IN assertion: the array bl_count contains the bit length statistics for - * the given tree and the field len is set for all tree elements. - * OUT assertion: the field code is set for all tree elements of non - * zero code length. - */ -local void gen_codes (tree, max_code, bl_count) - ct_data *tree; /* the tree to decorate */ - int max_code; /* largest code with non zero frequency */ - ushf *bl_count; /* number of codes at each bit length */ -{ - ush next_code[MAX_BITS+1]; /* next code value for each bit length */ - ush code = 0; /* running code value */ - int bits; /* bit index */ - int n; /* code index */ - - /* The distribution counts are first used to generate the code values - * without bit reversal. - */ - for (bits = 1; bits <= MAX_BITS; bits++) { - next_code[bits] = code = (code + bl_count[bits-1]) << 1; - } - /* Check that the bit counts in bl_count are consistent. The last code - * must be all ones. - */ - Assert (code + bl_count[MAX_BITS]-1 == (1<dyn_tree; - const ct_data *stree = desc->stat_desc->static_tree; - int elems = desc->stat_desc->elems; - int n, m; /* iterate over heap elements */ - int max_code = -1; /* largest code with non zero frequency */ - int node; /* new node being created */ - - /* Construct the initial heap, with least frequent element in - * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. - * heap[0] is not used. - */ - s->heap_len = 0, s->heap_max = HEAP_SIZE; - - for (n = 0; n < elems; n++) { - if (tree[n].Freq != 0) { - s->heap[++(s->heap_len)] = max_code = n; - s->depth[n] = 0; - } else { - tree[n].Len = 0; - } - } - - /* The pkzip format requires that at least one distance code exists, - * and that at least one bit should be sent even if there is only one - * possible code. So to avoid special checks later on we force at least - * two codes of non zero frequency. - */ - while (s->heap_len < 2) { - node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); - tree[node].Freq = 1; - s->depth[node] = 0; - s->opt_len--; if (stree) s->static_len -= stree[node].Len; - /* node is 0 or 1 so it does not have extra bits */ - } - desc->max_code = max_code; - - /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, - * establish sub-heaps of increasing lengths: - */ - for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); - - /* Construct the Huffman tree by repeatedly combining the least two - * frequent nodes. - */ - node = elems; /* next internal node of the tree */ - do { - pqremove(s, tree, n); /* n = node of least frequency */ - m = s->heap[SMALLEST]; /* m = node of next least frequency */ - - s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ - s->heap[--(s->heap_max)] = m; - - /* Create a new node father of n and m */ - tree[node].Freq = tree[n].Freq + tree[m].Freq; - s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? - s->depth[n] : s->depth[m]) + 1); - tree[n].Dad = tree[m].Dad = (ush)node; -#ifdef DUMP_BL_TREE - if (tree == s->bl_tree) { - fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", - node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); - } -#endif - /* and insert the new node in the heap */ - s->heap[SMALLEST] = node++; - pqdownheap(s, tree, SMALLEST); - - } while (s->heap_len >= 2); - - s->heap[--(s->heap_max)] = s->heap[SMALLEST]; - - /* At this point, the fields freq and dad are set. We can now - * generate the bit lengths. - */ - gen_bitlen(s, (tree_desc *)desc); - - /* The field len is now set, we can generate the bit codes */ - gen_codes ((ct_data *)tree, max_code, s->bl_count); -} - -/* =========================================================================== - * Scan a literal or distance tree to determine the frequencies of the codes - * in the bit length tree. - */ -local void scan_tree (s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ -{ - int n; /* iterates over all tree elements */ - int prevlen = -1; /* last emitted length */ - int curlen; /* length of current code */ - int nextlen = tree[0].Len; /* length of next code */ - int count = 0; /* repeat count of the current code */ - int max_count = 7; /* max repeat count */ - int min_count = 4; /* min repeat count */ - - if (nextlen == 0) max_count = 138, min_count = 3; - tree[max_code+1].Len = (ush)0xffff; /* guard */ - - for (n = 0; n <= max_code; n++) { - curlen = nextlen; nextlen = tree[n+1].Len; - if (++count < max_count && curlen == nextlen) { - continue; - } else if (count < min_count) { - s->bl_tree[curlen].Freq += count; - } else if (curlen != 0) { - if (curlen != prevlen) s->bl_tree[curlen].Freq++; - s->bl_tree[REP_3_6].Freq++; - } else if (count <= 10) { - s->bl_tree[REPZ_3_10].Freq++; - } else { - s->bl_tree[REPZ_11_138].Freq++; - } - count = 0; prevlen = curlen; - if (nextlen == 0) { - max_count = 138, min_count = 3; - } else if (curlen == nextlen) { - max_count = 6, min_count = 3; - } else { - max_count = 7, min_count = 4; - } - } -} - -/* =========================================================================== - * Send a literal or distance tree in compressed form, using the codes in - * bl_tree. - */ -local void send_tree (s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ -{ - int n; /* iterates over all tree elements */ - int prevlen = -1; /* last emitted length */ - int curlen; /* length of current code */ - int nextlen = tree[0].Len; /* length of next code */ - int count = 0; /* repeat count of the current code */ - int max_count = 7; /* max repeat count */ - int min_count = 4; /* min repeat count */ - - /* tree[max_code+1].Len = -1; */ /* guard already set */ - if (nextlen == 0) max_count = 138, min_count = 3; - - for (n = 0; n <= max_code; n++) { - curlen = nextlen; nextlen = tree[n+1].Len; - if (++count < max_count && curlen == nextlen) { - continue; - } else if (count < min_count) { - do { send_code(s, curlen, s->bl_tree); } while (--count != 0); - - } else if (curlen != 0) { - if (curlen != prevlen) { - send_code(s, curlen, s->bl_tree); count--; - } - Assert(count >= 3 && count <= 6, " 3_6?"); - send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); - - } else if (count <= 10) { - send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); - - } else { - send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); - } - count = 0; prevlen = curlen; - if (nextlen == 0) { - max_count = 138, min_count = 3; - } else if (curlen == nextlen) { - max_count = 6, min_count = 3; - } else { - max_count = 7, min_count = 4; - } - } -} - -/* =========================================================================== - * Construct the Huffman tree for the bit lengths and return the index in - * bl_order of the last bit length code to send. - */ -local int build_bl_tree(s) - deflate_state *s; -{ - int max_blindex; /* index of last bit length code of non zero freq */ - - /* Determine the bit length frequencies for literal and distance trees */ - scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); - scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); - - /* Build the bit length tree: */ - build_tree(s, (tree_desc *)(&(s->bl_desc))); - /* opt_len now includes the length of the tree representations, except - * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. - */ - - /* Determine the number of bit length codes to send. The pkzip format - * requires that at least 4 bit length codes be sent. (appnote.txt says - * 3 but the actual value used is 4.) - */ - for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { - if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; - } - /* Update opt_len to include the bit length tree and counts */ - s->opt_len += 3*(max_blindex+1) + 5+5+4; - Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", - s->opt_len, s->static_len)); - - return max_blindex; -} - -/* =========================================================================== - * Send the header for a block using dynamic Huffman trees: the counts, the - * lengths of the bit length codes, the literal tree and the distance tree. - * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. - */ -local void send_all_trees(s, lcodes, dcodes, blcodes) - deflate_state *s; - int lcodes, dcodes, blcodes; /* number of codes for each tree */ -{ - int rank; /* index in bl_order */ - - Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); - Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, - "too many codes"); - Tracev((stderr, "\nbl counts: ")); - send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ - send_bits(s, dcodes-1, 5); - send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ - for (rank = 0; rank < blcodes; rank++) { - Tracev((stderr, "\nbl code %2d ", bl_order[rank])); - send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); - } - Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); - - send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ - Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); - - send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ - Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); -} - -/* =========================================================================== - * Send a stored block - */ -void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) - deflate_state *s; - charf *buf; /* input block */ - ulg stored_len; /* length of input block */ - int last; /* one if this is the last block for a file */ -{ - send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ -#ifdef DEBUG - s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; - s->compressed_len += (stored_len + 4) << 3; -#endif - copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ -} - -/* =========================================================================== - * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) - */ -void ZLIB_INTERNAL _tr_flush_bits(s) - deflate_state *s; -{ - bi_flush(s); -} - -/* =========================================================================== - * Send one empty static block to give enough lookahead for inflate. - * This takes 10 bits, of which 7 may remain in the bit buffer. - */ -void ZLIB_INTERNAL _tr_align(s) - deflate_state *s; -{ - send_bits(s, STATIC_TREES<<1, 3); - send_code(s, END_BLOCK, static_ltree); -#ifdef DEBUG - s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ -#endif - bi_flush(s); -} - -/* =========================================================================== - * Determine the best encoding for the current block: dynamic trees, static - * trees or store, and output the encoded block to the zip file. - */ -void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) - deflate_state *s; - charf *buf; /* input block, or NULL if too old */ - ulg stored_len; /* length of input block */ - int last; /* one if this is the last block for a file */ -{ - ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ - int max_blindex = 0; /* index of last bit length code of non zero freq */ - - /* Build the Huffman trees unless a stored block is forced */ - if (s->level > 0) { - - /* Check if the file is binary or text */ - if (s->strm->data_type == Z_UNKNOWN) - s->strm->data_type = detect_data_type(s); - - /* Construct the literal and distance trees */ - build_tree(s, (tree_desc *)(&(s->l_desc))); - Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, - s->static_len)); - - build_tree(s, (tree_desc *)(&(s->d_desc))); - Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, - s->static_len)); - /* At this point, opt_len and static_len are the total bit lengths of - * the compressed block data, excluding the tree representations. - */ - - /* Build the bit length tree for the above two trees, and get the index - * in bl_order of the last bit length code to send. - */ - max_blindex = build_bl_tree(s); - - /* Determine the best encoding. Compute the block lengths in bytes. */ - opt_lenb = (s->opt_len+3+7)>>3; - static_lenb = (s->static_len+3+7)>>3; - - Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", - opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, - s->last_lit)); - - if (static_lenb <= opt_lenb) opt_lenb = static_lenb; - - } else { - Assert(buf != (char*)0, "lost buf"); - opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ - } - -#ifdef FORCE_STORED - if (buf != (char*)0) { /* force stored block */ -#else - if (stored_len+4 <= opt_lenb && buf != (char*)0) { - /* 4: two words for the lengths */ -#endif - /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. - * Otherwise we can't have processed more than WSIZE input bytes since - * the last block flush, because compression would have been - * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to - * transform a block into a stored block. - */ - _tr_stored_block(s, buf, stored_len, last); - -#ifdef FORCE_STATIC - } else if (static_lenb >= 0) { /* force static trees */ -#else - } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { -#endif - send_bits(s, (STATIC_TREES<<1)+last, 3); - compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); -#ifdef DEBUG - s->compressed_len += 3 + s->static_len; -#endif - } else { - send_bits(s, (DYN_TREES<<1)+last, 3); - send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, - max_blindex+1); - compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); -#ifdef DEBUG - s->compressed_len += 3 + s->opt_len; -#endif - } - Assert (s->compressed_len == s->bits_sent, "bad compressed size"); - /* The above check is made mod 2^32, for files larger than 512 MB - * and uLong implemented on 32 bits. - */ - init_block(s); - - if (last) { - bi_windup(s); -#ifdef DEBUG - s->compressed_len += 7; /* align on byte boundary */ -#endif - } - Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, - s->compressed_len-7*last)); -} - -/* =========================================================================== - * Save the match info and tally the frequency counts. Return true if - * the current block must be flushed. - */ -int ZLIB_INTERNAL _tr_tally (s, dist, lc) - deflate_state *s; - unsigned dist; /* distance of matched string */ - unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ -{ - s->d_buf[s->last_lit] = (ush)dist; - s->l_buf[s->last_lit++] = (uch)lc; - if (dist == 0) { - /* lc is the unmatched char */ - s->dyn_ltree[lc].Freq++; - } else { - s->matches++; - /* Here, lc is the match length - MIN_MATCH */ - dist--; /* dist = match distance - 1 */ - Assert((ush)dist < (ush)MAX_DIST(s) && - (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && - (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); - - s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; - s->dyn_dtree[d_code(dist)].Freq++; - } - -#ifdef TRUNCATE_BLOCK - /* Try to guess if it is profitable to stop the current block here */ - if ((s->last_lit & 0x1fff) == 0 && s->level > 2) { - /* Compute an upper bound for the compressed length */ - ulg out_length = (ulg)s->last_lit*8L; - ulg in_length = (ulg)((long)s->strstart - s->block_start); - int dcode; - for (dcode = 0; dcode < D_CODES; dcode++) { - out_length += (ulg)s->dyn_dtree[dcode].Freq * - (5L+extra_dbits[dcode]); - } - out_length >>= 3; - Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", - s->last_lit, in_length, out_length, - 100L - out_length*100L/in_length)); - if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; - } -#endif - return (s->last_lit == s->lit_bufsize-1); - /* We avoid equality with lit_bufsize because of wraparound at 64K - * on 16 bit machines and because stored blocks are restricted to - * 64K-1 bytes. - */ -} - -/* =========================================================================== - * Send the block data compressed using the given Huffman trees - */ -local void compress_block(s, ltree, dtree) - deflate_state *s; - ct_data *ltree; /* literal tree */ - ct_data *dtree; /* distance tree */ -{ - unsigned dist; /* distance of matched string */ - int lc; /* match length or unmatched char (if dist == 0) */ - unsigned lx = 0; /* running index in l_buf */ - unsigned code; /* the code to send */ - int extra; /* number of extra bits to send */ - - if (s->last_lit != 0) do { - dist = s->d_buf[lx]; - lc = s->l_buf[lx++]; - if (dist == 0) { - send_code(s, lc, ltree); /* send a literal byte */ - Tracecv(isgraph(lc), (stderr," '%c' ", lc)); - } else { - /* Here, lc is the match length - MIN_MATCH */ - code = _length_code[lc]; - send_code(s, code+LITERALS+1, ltree); /* send the length code */ - extra = extra_lbits[code]; - if (extra != 0) { - lc -= base_length[code]; - send_bits(s, lc, extra); /* send the extra length bits */ - } - dist--; /* dist is now the match distance - 1 */ - code = d_code(dist); - Assert (code < D_CODES, "bad d_code"); - - send_code(s, code, dtree); /* send the distance code */ - extra = extra_dbits[code]; - if (extra != 0) { - dist -= base_dist[code]; - send_bits(s, dist, extra); /* send the extra distance bits */ - } - } /* literal or match pair ? */ - - /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ - Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, - "pendingBuf overflow"); - - } while (lx < s->last_lit); - - send_code(s, END_BLOCK, ltree); -} - -/* =========================================================================== - * Check if the data type is TEXT or BINARY, using the following algorithm: - * - TEXT if the two conditions below are satisfied: - * a) There are no non-portable control characters belonging to the - * "black list" (0..6, 14..25, 28..31). - * b) There is at least one printable character belonging to the - * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). - * - BINARY otherwise. - * - The following partially-portable control characters form a - * "gray list" that is ignored in this detection algorithm: - * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). - * IN assertion: the fields Freq of dyn_ltree are set. - */ -local int detect_data_type(s) - deflate_state *s; -{ - /* black_mask is the bit mask of black-listed bytes - * set bits 0..6, 14..25, and 28..31 - * 0xf3ffc07f = binary 11110011111111111100000001111111 - */ - unsigned long black_mask = 0xf3ffc07fUL; - int n; - - /* Check for non-textual ("black-listed") bytes. */ - for (n = 0; n <= 31; n++, black_mask >>= 1) - if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0)) - return Z_BINARY; - - /* Check for textual ("white-listed") bytes. */ - if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 - || s->dyn_ltree[13].Freq != 0) - return Z_TEXT; - for (n = 32; n < LITERALS; n++) - if (s->dyn_ltree[n].Freq != 0) - return Z_TEXT; - - /* There are no "black-listed" or "white-listed" bytes: - * this stream either is empty or has tolerated ("gray-listed") bytes only. - */ - return Z_BINARY; -} - -/* =========================================================================== - * Reverse the first len bits of a code, using straightforward code (a faster - * method would use a table) - * IN assertion: 1 <= len <= 15 - */ -local unsigned bi_reverse(code, len) - unsigned code; /* the value to invert */ - int len; /* its bit length */ -{ - register unsigned res = 0; - do { - res |= code & 1; - code >>= 1, res <<= 1; - } while (--len > 0); - return res >> 1; -} - -/* =========================================================================== - * Flush the bit buffer, keeping at most 7 bits in it. - */ -local void bi_flush(s) - deflate_state *s; -{ - if (s->bi_valid == 16) { - put_short(s, s->bi_buf); - s->bi_buf = 0; - s->bi_valid = 0; - } else if (s->bi_valid >= 8) { - put_byte(s, (Byte)s->bi_buf); - s->bi_buf >>= 8; - s->bi_valid -= 8; - } -} - -/* =========================================================================== - * Flush the bit buffer and align the output on a byte boundary - */ -local void bi_windup(s) - deflate_state *s; -{ - if (s->bi_valid > 8) { - put_short(s, s->bi_buf); - } else if (s->bi_valid > 0) { - put_byte(s, (Byte)s->bi_buf); - } - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef DEBUG - s->bits_sent = (s->bits_sent+7) & ~7; -#endif -} - -/* =========================================================================== - * Copy a stored block, storing first the length and its - * one's complement if requested. - */ -local void copy_block(s, buf, len, header) - deflate_state *s; - charf *buf; /* the input data */ - unsigned len; /* its length */ - int header; /* true if block header must be written */ -{ - bi_windup(s); /* align on byte boundary */ - - if (header) { - put_short(s, (ush)len); - put_short(s, (ush)~len); -#ifdef DEBUG - s->bits_sent += 2*16; -#endif - } -#ifdef DEBUG - s->bits_sent += (ulg)len<<3; -#endif - while (len--) { - put_byte(s, *buf++); - } -} +/* trees.c -- output deflated data using Huffman coding + * Copyright (C) 1995-2012 Jean-loup Gailly + * detect_data_type() function provided freely by Cosmin Truta, 2006 + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + * ALGORITHM + * + * The "deflation" process uses several Huffman trees. The more + * common source values are represented by shorter bit sequences. + * + * Each code tree is stored in a compressed form which is itself + * a Huffman encoding of the lengths of all the code strings (in + * ascending order by source values). The actual code strings are + * reconstructed from the lengths in the inflate process, as described + * in the deflate specification. + * + * REFERENCES + * + * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". + * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc + * + * Storer, James A. + * Data Compression: Methods and Theory, pp. 49-50. + * Computer Science Press, 1988. ISBN 0-7167-8156-5. + * + * Sedgewick, R. + * Algorithms, p290. + * Addison-Wesley, 1983. ISBN 0-201-06672-6. + */ + +/* @(#) $Id: trees.c,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ + +/* #define GEN_TREES_H */ + +#include "deflate.h" + +#ifdef DEBUG +# include +#endif + +/* =========================================================================== + * Constants + */ + +#define MAX_BL_BITS 7 +/* Bit length codes must not exceed MAX_BL_BITS bits */ + +#define END_BLOCK 256 +/* end of block literal code */ + +#define REP_3_6 16 +/* repeat previous bit length 3-6 times (2 bits of repeat count) */ + +#define REPZ_3_10 17 +/* repeat a zero length 3-10 times (3 bits of repeat count) */ + +#define REPZ_11_138 18 +/* repeat a zero length 11-138 times (7 bits of repeat count) */ + +local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ + = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; + +local const int extra_dbits[D_CODES] /* extra bits for each distance code */ + = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; + +local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ + = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; + +local const uch bl_order[BL_CODES] + = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; +/* The lengths of the bit length codes are sent in order of decreasing + * probability, to avoid transmitting the lengths for unused bit length codes. + */ + +/* =========================================================================== + * Local data. These are initialized only once. + */ + +#define DIST_CODE_LEN 512 /* see definition of array dist_code below */ + +#if defined(GEN_TREES_H) || !defined(STDC) +/* non ANSI compilers may not accept trees.h */ + +local ct_data static_ltree[L_CODES+2]; +/* The static literal tree. Since the bit lengths are imposed, there is no + * need for the L_CODES extra codes used during heap construction. However + * The codes 286 and 287 are needed to build a canonical tree (see _tr_init + * below). + */ + +local ct_data static_dtree[D_CODES]; +/* The static distance tree. (Actually a trivial tree since all codes use + * 5 bits.) + */ + +uch _dist_code[DIST_CODE_LEN]; +/* Distance codes. The first 256 values correspond to the distances + * 3 .. 258, the last 256 values correspond to the top 8 bits of + * the 15 bit distances. + */ + +uch _length_code[MAX_MATCH-MIN_MATCH+1]; +/* length code for each normalized match length (0 == MIN_MATCH) */ + +local int base_length[LENGTH_CODES]; +/* First normalized length for each code (0 = MIN_MATCH) */ + +local int base_dist[D_CODES]; +/* First normalized distance for each code (0 = distance of 1) */ + +#else +# include "trees.h" +#endif /* GEN_TREES_H */ + +struct static_tree_desc_s { + const ct_data *static_tree; /* static tree or NULL */ + const intf *extra_bits; /* extra bits for each code or NULL */ + int extra_base; /* base index for extra_bits */ + int elems; /* max number of elements in the tree */ + int max_length; /* max bit length for the codes */ +}; + +local static_tree_desc static_l_desc = +{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; + +local static_tree_desc static_d_desc = +{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; + +local static_tree_desc static_bl_desc = +{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; + +/* =========================================================================== + * Local (static) routines in this file. + */ + +local void tr_static_init OF((void)); +local void init_block OF((deflate_state *s)); +local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); +local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); +local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); +local void build_tree OF((deflate_state *s, tree_desc *desc)); +local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); +local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); +local int build_bl_tree OF((deflate_state *s)); +local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, + int blcodes)); +local void compress_block OF((deflate_state *s, ct_data *ltree, + ct_data *dtree)); +local int detect_data_type OF((deflate_state *s)); +local unsigned bi_reverse OF((unsigned value, int length)); +local void bi_windup OF((deflate_state *s)); +local void bi_flush OF((deflate_state *s)); +local void copy_block OF((deflate_state *s, charf *buf, unsigned len, + int header)); + +#ifdef GEN_TREES_H +local void gen_trees_header OF((void)); +#endif + +#ifndef DEBUG +# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) + /* Send a code of the given tree. c and tree must not have side effects */ + +#else /* DEBUG */ +# define send_code(s, c, tree) \ + { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ + send_bits(s, tree[c].Code, tree[c].Len); } +#endif + +/* =========================================================================== + * Output a short LSB first on the stream. + * IN assertion: there is enough room in pendingBuf. + */ +#define put_short(s, w) { \ + put_byte(s, (uch)((w) & 0xff)); \ + put_byte(s, (uch)((ush)(w) >> 8)); \ +} + +/* =========================================================================== + * Send a value on a given number of bits. + * IN assertion: length <= 16 and value fits in length bits. + */ +#ifdef DEBUG +local void send_bits OF((deflate_state *s, int value, int length)); + +local void send_bits(s, value, length) + deflate_state *s; + int value; /* value to send */ + int length; /* number of bits */ +{ + Tracevv((stderr," l %2d v %4x ", length, value)); + Assert(length > 0 && length <= 15, "invalid length"); + s->bits_sent += (ulg)length; + + /* If not enough room in bi_buf, use (valid) bits from bi_buf and + * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) + * unused bits in value. + */ + if (s->bi_valid > (int)Buf_size - length) { + s->bi_buf |= (ush)value << s->bi_valid; + put_short(s, s->bi_buf); + s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); + s->bi_valid += length - Buf_size; + } else { + s->bi_buf |= (ush)value << s->bi_valid; + s->bi_valid += length; + } +} +#else /* !DEBUG */ + +#define send_bits(s, value, length) \ +{ int len = length;\ + if (s->bi_valid > (int)Buf_size - len) {\ + int val = value;\ + s->bi_buf |= (ush)val << s->bi_valid;\ + put_short(s, s->bi_buf);\ + s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ + s->bi_valid += len - Buf_size;\ + } else {\ + s->bi_buf |= (ush)(value) << s->bi_valid;\ + s->bi_valid += len;\ + }\ +} +#endif /* DEBUG */ + + +/* the arguments must not have side effects */ + +/* =========================================================================== + * Initialize the various 'constant' tables. + */ +local void tr_static_init() +{ +#if defined(GEN_TREES_H) || !defined(STDC) + static int static_init_done = 0; + int n; /* iterates over tree elements */ + int bits; /* bit counter */ + int length; /* length value */ + int code; /* code value */ + int dist; /* distance index */ + ush bl_count[MAX_BITS+1]; + /* number of codes at each bit length for an optimal tree */ + + if (static_init_done) return; + + /* For some embedded targets, global variables are not initialized: */ +#ifdef NO_INIT_GLOBAL_POINTERS + static_l_desc.static_tree = static_ltree; + static_l_desc.extra_bits = extra_lbits; + static_d_desc.static_tree = static_dtree; + static_d_desc.extra_bits = extra_dbits; + static_bl_desc.extra_bits = extra_blbits; +#endif + + /* Initialize the mapping length (0..255) -> length code (0..28) */ + length = 0; + for (code = 0; code < LENGTH_CODES-1; code++) { + base_length[code] = length; + for (n = 0; n < (1< dist code (0..29) */ + dist = 0; + for (code = 0 ; code < 16; code++) { + base_dist[code] = dist; + for (n = 0; n < (1<>= 7; /* from now on, all distances are divided by 128 */ + for ( ; code < D_CODES; code++) { + base_dist[code] = dist << 7; + for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { + _dist_code[256 + dist++] = (uch)code; + } + } + Assert (dist == 256, "tr_static_init: 256+dist != 512"); + + /* Construct the codes of the static literal tree */ + for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; + n = 0; + while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; + while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; + while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; + while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; + /* Codes 286 and 287 do not exist, but we must include them in the + * tree construction to get a canonical Huffman tree (longest code + * all ones) + */ + gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); + + /* The static distance tree is trivial: */ + for (n = 0; n < D_CODES; n++) { + static_dtree[n].Len = 5; + static_dtree[n].Code = bi_reverse((unsigned)n, 5); + } + static_init_done = 1; + +# ifdef GEN_TREES_H + gen_trees_header(); +# endif +#endif /* defined(GEN_TREES_H) || !defined(STDC) */ +} + +/* =========================================================================== + * Genererate the file trees.h describing the static trees. + */ +#ifdef GEN_TREES_H +# ifndef DEBUG +# include +# endif + +# define SEPARATOR(i, last, width) \ + ((i) == (last)? "\n};\n\n" : \ + ((i) % (width) == (width)-1 ? ",\n" : ", ")) + +void gen_trees_header() +{ + FILE *header = fopen("trees.h", "w"); + int i; + + Assert (header != NULL, "Can't open trees.h"); + fprintf(header, + "/* header created automatically with -DGEN_TREES_H */\n\n"); + + fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); + for (i = 0; i < L_CODES+2; i++) { + fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, + static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); + } + + fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); + for (i = 0; i < D_CODES; i++) { + fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, + static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); + } + + fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n"); + for (i = 0; i < DIST_CODE_LEN; i++) { + fprintf(header, "%2u%s", _dist_code[i], + SEPARATOR(i, DIST_CODE_LEN-1, 20)); + } + + fprintf(header, + "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); + for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { + fprintf(header, "%2u%s", _length_code[i], + SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); + } + + fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); + for (i = 0; i < LENGTH_CODES; i++) { + fprintf(header, "%1u%s", base_length[i], + SEPARATOR(i, LENGTH_CODES-1, 20)); + } + + fprintf(header, "local const int base_dist[D_CODES] = {\n"); + for (i = 0; i < D_CODES; i++) { + fprintf(header, "%5u%s", base_dist[i], + SEPARATOR(i, D_CODES-1, 10)); + } + + fclose(header); +} +#endif /* GEN_TREES_H */ + +/* =========================================================================== + * Initialize the tree data structures for a new zlib stream. + */ +void ZLIB_INTERNAL _tr_init(s) + deflate_state *s; +{ + tr_static_init(); + + s->l_desc.dyn_tree = s->dyn_ltree; + s->l_desc.stat_desc = &static_l_desc; + + s->d_desc.dyn_tree = s->dyn_dtree; + s->d_desc.stat_desc = &static_d_desc; + + s->bl_desc.dyn_tree = s->bl_tree; + s->bl_desc.stat_desc = &static_bl_desc; + + s->bi_buf = 0; + s->bi_valid = 0; +#ifdef DEBUG + s->compressed_len = 0L; + s->bits_sent = 0L; +#endif + + /* Initialize the first block of the first file: */ + init_block(s); +} + +/* =========================================================================== + * Initialize a new block. + */ +local void init_block(s) + deflate_state *s; +{ + int n; /* iterates over tree elements */ + + /* Initialize the trees. */ + for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; + for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; + for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; + + s->dyn_ltree[END_BLOCK].Freq = 1; + s->opt_len = s->static_len = 0L; + s->last_lit = s->matches = 0; +} + +#define SMALLEST 1 +/* Index within the heap array of least frequent node in the Huffman tree */ + + +/* =========================================================================== + * Remove the smallest element from the heap and recreate the heap with + * one less element. Updates heap and heap_len. + */ +#define pqremove(s, tree, top) \ +{\ + top = s->heap[SMALLEST]; \ + s->heap[SMALLEST] = s->heap[s->heap_len--]; \ + pqdownheap(s, tree, SMALLEST); \ +} + +/* =========================================================================== + * Compares to subtrees, using the tree depth as tie breaker when + * the subtrees have equal frequency. This minimizes the worst case length. + */ +#define smaller(tree, n, m, depth) \ + (tree[n].Freq < tree[m].Freq || \ + (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) + +/* =========================================================================== + * Restore the heap property by moving down the tree starting at node k, + * exchanging a node with the smallest of its two sons if necessary, stopping + * when the heap property is re-established (each father smaller than its + * two sons). + */ +local void pqdownheap(s, tree, k) + deflate_state *s; + ct_data *tree; /* the tree to restore */ + int k; /* node to move down */ +{ + int v = s->heap[k]; + int j = k << 1; /* left son of k */ + while (j <= s->heap_len) { + /* Set j to the smallest of the two sons: */ + if (j < s->heap_len && + smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { + j++; + } + /* Exit if v is smaller than both sons */ + if (smaller(tree, v, s->heap[j], s->depth)) break; + + /* Exchange v with the smallest son */ + s->heap[k] = s->heap[j]; k = j; + + /* And continue down the tree, setting j to the left son of k */ + j <<= 1; + } + s->heap[k] = v; +} + +/* =========================================================================== + * Compute the optimal bit lengths for a tree and update the total bit length + * for the current block. + * IN assertion: the fields freq and dad are set, heap[heap_max] and + * above are the tree nodes sorted by increasing frequency. + * OUT assertions: the field len is set to the optimal bit length, the + * array bl_count contains the frequencies for each bit length. + * The length opt_len is updated; static_len is also updated if stree is + * not null. + */ +local void gen_bitlen(s, desc) + deflate_state *s; + tree_desc *desc; /* the tree descriptor */ +{ + ct_data *tree = desc->dyn_tree; + int max_code = desc->max_code; + const ct_data *stree = desc->stat_desc->static_tree; + const intf *extra = desc->stat_desc->extra_bits; + int base = desc->stat_desc->extra_base; + int max_length = desc->stat_desc->max_length; + int h; /* heap index */ + int n, m; /* iterate over the tree elements */ + int bits; /* bit length */ + int xbits; /* extra bits */ + ush f; /* frequency */ + int overflow = 0; /* number of elements with bit length too large */ + + for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; + + /* In a first pass, compute the optimal bit lengths (which may + * overflow in the case of the bit length tree). + */ + tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ + + for (h = s->heap_max+1; h < HEAP_SIZE; h++) { + n = s->heap[h]; + bits = tree[tree[n].Dad].Len + 1; + if (bits > max_length) bits = max_length, overflow++; + tree[n].Len = (ush)bits; + /* We overwrite tree[n].Dad which is no longer needed */ + + if (n > max_code) continue; /* not a leaf node */ + + s->bl_count[bits]++; + xbits = 0; + if (n >= base) xbits = extra[n-base]; + f = tree[n].Freq; + s->opt_len += (ulg)f * (bits + xbits); + if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); + } + if (overflow == 0) return; + + Trace((stderr,"\nbit length overflow\n")); + /* This happens for example on obj2 and pic of the Calgary corpus */ + + /* Find the first bit length which could increase: */ + do { + bits = max_length-1; + while (s->bl_count[bits] == 0) bits--; + s->bl_count[bits]--; /* move one leaf down the tree */ + s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ + s->bl_count[max_length]--; + /* The brother of the overflow item also moves one step up, + * but this does not affect bl_count[max_length] + */ + overflow -= 2; + } while (overflow > 0); + + /* Now recompute all bit lengths, scanning in increasing frequency. + * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all + * lengths instead of fixing only the wrong ones. This idea is taken + * from 'ar' written by Haruhiko Okumura.) + */ + for (bits = max_length; bits != 0; bits--) { + n = s->bl_count[bits]; + while (n != 0) { + m = s->heap[--h]; + if (m > max_code) continue; + if ((unsigned) tree[m].Len != (unsigned) bits) { + Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); + s->opt_len += ((long)bits - (long)tree[m].Len) + *(long)tree[m].Freq; + tree[m].Len = (ush)bits; + } + n--; + } + } +} + +/* =========================================================================== + * Generate the codes for a given tree and bit counts (which need not be + * optimal). + * IN assertion: the array bl_count contains the bit length statistics for + * the given tree and the field len is set for all tree elements. + * OUT assertion: the field code is set for all tree elements of non + * zero code length. + */ +local void gen_codes (tree, max_code, bl_count) + ct_data *tree; /* the tree to decorate */ + int max_code; /* largest code with non zero frequency */ + ushf *bl_count; /* number of codes at each bit length */ +{ + ush next_code[MAX_BITS+1]; /* next code value for each bit length */ + ush code = 0; /* running code value */ + int bits; /* bit index */ + int n; /* code index */ + + /* The distribution counts are first used to generate the code values + * without bit reversal. + */ + for (bits = 1; bits <= MAX_BITS; bits++) { + next_code[bits] = code = (code + bl_count[bits-1]) << 1; + } + /* Check that the bit counts in bl_count are consistent. The last code + * must be all ones. + */ + Assert (code + bl_count[MAX_BITS]-1 == (1<dyn_tree; + const ct_data *stree = desc->stat_desc->static_tree; + int elems = desc->stat_desc->elems; + int n, m; /* iterate over heap elements */ + int max_code = -1; /* largest code with non zero frequency */ + int node; /* new node being created */ + + /* Construct the initial heap, with least frequent element in + * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. + * heap[0] is not used. + */ + s->heap_len = 0, s->heap_max = HEAP_SIZE; + + for (n = 0; n < elems; n++) { + if (tree[n].Freq != 0) { + s->heap[++(s->heap_len)] = max_code = n; + s->depth[n] = 0; + } else { + tree[n].Len = 0; + } + } + + /* The pkzip format requires that at least one distance code exists, + * and that at least one bit should be sent even if there is only one + * possible code. So to avoid special checks later on we force at least + * two codes of non zero frequency. + */ + while (s->heap_len < 2) { + node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); + tree[node].Freq = 1; + s->depth[node] = 0; + s->opt_len--; if (stree) s->static_len -= stree[node].Len; + /* node is 0 or 1 so it does not have extra bits */ + } + desc->max_code = max_code; + + /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, + * establish sub-heaps of increasing lengths: + */ + for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); + + /* Construct the Huffman tree by repeatedly combining the least two + * frequent nodes. + */ + node = elems; /* next internal node of the tree */ + do { + pqremove(s, tree, n); /* n = node of least frequency */ + m = s->heap[SMALLEST]; /* m = node of next least frequency */ + + s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ + s->heap[--(s->heap_max)] = m; + + /* Create a new node father of n and m */ + tree[node].Freq = tree[n].Freq + tree[m].Freq; + s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? + s->depth[n] : s->depth[m]) + 1); + tree[n].Dad = tree[m].Dad = (ush)node; +#ifdef DUMP_BL_TREE + if (tree == s->bl_tree) { + fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", + node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); + } +#endif + /* and insert the new node in the heap */ + s->heap[SMALLEST] = node++; + pqdownheap(s, tree, SMALLEST); + + } while (s->heap_len >= 2); + + s->heap[--(s->heap_max)] = s->heap[SMALLEST]; + + /* At this point, the fields freq and dad are set. We can now + * generate the bit lengths. + */ + gen_bitlen(s, (tree_desc *)desc); + + /* The field len is now set, we can generate the bit codes */ + gen_codes ((ct_data *)tree, max_code, s->bl_count); +} + +/* =========================================================================== + * Scan a literal or distance tree to determine the frequencies of the codes + * in the bit length tree. + */ +local void scan_tree (s, tree, max_code) + deflate_state *s; + ct_data *tree; /* the tree to be scanned */ + int max_code; /* and its largest code of non zero frequency */ +{ + int n; /* iterates over all tree elements */ + int prevlen = -1; /* last emitted length */ + int curlen; /* length of current code */ + int nextlen = tree[0].Len; /* length of next code */ + int count = 0; /* repeat count of the current code */ + int max_count = 7; /* max repeat count */ + int min_count = 4; /* min repeat count */ + + if (nextlen == 0) max_count = 138, min_count = 3; + tree[max_code+1].Len = (ush)0xffff; /* guard */ + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; nextlen = tree[n+1].Len; + if (++count < max_count && curlen == nextlen) { + continue; + } else if (count < min_count) { + s->bl_tree[curlen].Freq += count; + } else if (curlen != 0) { + if (curlen != prevlen) s->bl_tree[curlen].Freq++; + s->bl_tree[REP_3_6].Freq++; + } else if (count <= 10) { + s->bl_tree[REPZ_3_10].Freq++; + } else { + s->bl_tree[REPZ_11_138].Freq++; + } + count = 0; prevlen = curlen; + if (nextlen == 0) { + max_count = 138, min_count = 3; + } else if (curlen == nextlen) { + max_count = 6, min_count = 3; + } else { + max_count = 7, min_count = 4; + } + } +} + +/* =========================================================================== + * Send a literal or distance tree in compressed form, using the codes in + * bl_tree. + */ +local void send_tree (s, tree, max_code) + deflate_state *s; + ct_data *tree; /* the tree to be scanned */ + int max_code; /* and its largest code of non zero frequency */ +{ + int n; /* iterates over all tree elements */ + int prevlen = -1; /* last emitted length */ + int curlen; /* length of current code */ + int nextlen = tree[0].Len; /* length of next code */ + int count = 0; /* repeat count of the current code */ + int max_count = 7; /* max repeat count */ + int min_count = 4; /* min repeat count */ + + /* tree[max_code+1].Len = -1; */ /* guard already set */ + if (nextlen == 0) max_count = 138, min_count = 3; + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; nextlen = tree[n+1].Len; + if (++count < max_count && curlen == nextlen) { + continue; + } else if (count < min_count) { + do { send_code(s, curlen, s->bl_tree); } while (--count != 0); + + } else if (curlen != 0) { + if (curlen != prevlen) { + send_code(s, curlen, s->bl_tree); count--; + } + Assert(count >= 3 && count <= 6, " 3_6?"); + send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); + + } else if (count <= 10) { + send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); + + } else { + send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); + } + count = 0; prevlen = curlen; + if (nextlen == 0) { + max_count = 138, min_count = 3; + } else if (curlen == nextlen) { + max_count = 6, min_count = 3; + } else { + max_count = 7, min_count = 4; + } + } +} + +/* =========================================================================== + * Construct the Huffman tree for the bit lengths and return the index in + * bl_order of the last bit length code to send. + */ +local int build_bl_tree(s) + deflate_state *s; +{ + int max_blindex; /* index of last bit length code of non zero freq */ + + /* Determine the bit length frequencies for literal and distance trees */ + scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); + scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); + + /* Build the bit length tree: */ + build_tree(s, (tree_desc *)(&(s->bl_desc))); + /* opt_len now includes the length of the tree representations, except + * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. + */ + + /* Determine the number of bit length codes to send. The pkzip format + * requires that at least 4 bit length codes be sent. (appnote.txt says + * 3 but the actual value used is 4.) + */ + for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { + if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; + } + /* Update opt_len to include the bit length tree and counts */ + s->opt_len += 3*(max_blindex+1) + 5+5+4; + Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", + s->opt_len, s->static_len)); + + return max_blindex; +} + +/* =========================================================================== + * Send the header for a block using dynamic Huffman trees: the counts, the + * lengths of the bit length codes, the literal tree and the distance tree. + * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. + */ +local void send_all_trees(s, lcodes, dcodes, blcodes) + deflate_state *s; + int lcodes, dcodes, blcodes; /* number of codes for each tree */ +{ + int rank; /* index in bl_order */ + + Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); + Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, + "too many codes"); + Tracev((stderr, "\nbl counts: ")); + send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ + send_bits(s, dcodes-1, 5); + send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ + for (rank = 0; rank < blcodes; rank++) { + Tracev((stderr, "\nbl code %2d ", bl_order[rank])); + send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); + } + Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); + + send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ + Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); + + send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ + Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); +} + +/* =========================================================================== + * Send a stored block + */ +void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) + deflate_state *s; + charf *buf; /* input block */ + ulg stored_len; /* length of input block */ + int last; /* one if this is the last block for a file */ +{ + send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ +#ifdef DEBUG + s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; + s->compressed_len += (stored_len + 4) << 3; +#endif + copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ +} + +/* =========================================================================== + * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) + */ +void ZLIB_INTERNAL _tr_flush_bits(s) + deflate_state *s; +{ + bi_flush(s); +} + +/* =========================================================================== + * Send one empty static block to give enough lookahead for inflate. + * This takes 10 bits, of which 7 may remain in the bit buffer. + */ +void ZLIB_INTERNAL _tr_align(s) + deflate_state *s; +{ + send_bits(s, STATIC_TREES<<1, 3); + send_code(s, END_BLOCK, static_ltree); +#ifdef DEBUG + s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ +#endif + bi_flush(s); +} + +/* =========================================================================== + * Determine the best encoding for the current block: dynamic trees, static + * trees or store, and output the encoded block to the zip file. + */ +void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) + deflate_state *s; + charf *buf; /* input block, or NULL if too old */ + ulg stored_len; /* length of input block */ + int last; /* one if this is the last block for a file */ +{ + ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ + int max_blindex = 0; /* index of last bit length code of non zero freq */ + + /* Build the Huffman trees unless a stored block is forced */ + if (s->level > 0) { + + /* Check if the file is binary or text */ + if (s->strm->data_type == Z_UNKNOWN) + s->strm->data_type = detect_data_type(s); + + /* Construct the literal and distance trees */ + build_tree(s, (tree_desc *)(&(s->l_desc))); + Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, + s->static_len)); + + build_tree(s, (tree_desc *)(&(s->d_desc))); + Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, + s->static_len)); + /* At this point, opt_len and static_len are the total bit lengths of + * the compressed block data, excluding the tree representations. + */ + + /* Build the bit length tree for the above two trees, and get the index + * in bl_order of the last bit length code to send. + */ + max_blindex = build_bl_tree(s); + + /* Determine the best encoding. Compute the block lengths in bytes. */ + opt_lenb = (s->opt_len+3+7)>>3; + static_lenb = (s->static_len+3+7)>>3; + + Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", + opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, + s->last_lit)); + + if (static_lenb <= opt_lenb) opt_lenb = static_lenb; + + } else { + Assert(buf != (char*)0, "lost buf"); + opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ + } + +#ifdef FORCE_STORED + if (buf != (char*)0) { /* force stored block */ +#else + if (stored_len+4 <= opt_lenb && buf != (char*)0) { + /* 4: two words for the lengths */ +#endif + /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. + * Otherwise we can't have processed more than WSIZE input bytes since + * the last block flush, because compression would have been + * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to + * transform a block into a stored block. + */ + _tr_stored_block(s, buf, stored_len, last); + +#ifdef FORCE_STATIC + } else if (static_lenb >= 0) { /* force static trees */ +#else + } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { +#endif + send_bits(s, (STATIC_TREES<<1)+last, 3); + compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); +#ifdef DEBUG + s->compressed_len += 3 + s->static_len; +#endif + } else { + send_bits(s, (DYN_TREES<<1)+last, 3); + send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, + max_blindex+1); + compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); +#ifdef DEBUG + s->compressed_len += 3 + s->opt_len; +#endif + } + Assert (s->compressed_len == s->bits_sent, "bad compressed size"); + /* The above check is made mod 2^32, for files larger than 512 MB + * and uLong implemented on 32 bits. + */ + init_block(s); + + if (last) { + bi_windup(s); +#ifdef DEBUG + s->compressed_len += 7; /* align on byte boundary */ +#endif + } + Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, + s->compressed_len-7*last)); +} + +/* =========================================================================== + * Save the match info and tally the frequency counts. Return true if + * the current block must be flushed. + */ +int ZLIB_INTERNAL _tr_tally (s, dist, lc) + deflate_state *s; + unsigned dist; /* distance of matched string */ + unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ +{ + s->d_buf[s->last_lit] = (ush)dist; + s->l_buf[s->last_lit++] = (uch)lc; + if (dist == 0) { + /* lc is the unmatched char */ + s->dyn_ltree[lc].Freq++; + } else { + s->matches++; + /* Here, lc is the match length - MIN_MATCH */ + dist--; /* dist = match distance - 1 */ + Assert((ush)dist < (ush)MAX_DIST(s) && + (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && + (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); + + s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; + s->dyn_dtree[d_code(dist)].Freq++; + } + +#ifdef TRUNCATE_BLOCK + /* Try to guess if it is profitable to stop the current block here */ + if ((s->last_lit & 0x1fff) == 0 && s->level > 2) { + /* Compute an upper bound for the compressed length */ + ulg out_length = (ulg)s->last_lit*8L; + ulg in_length = (ulg)((long)s->strstart - s->block_start); + int dcode; + for (dcode = 0; dcode < D_CODES; dcode++) { + out_length += (ulg)s->dyn_dtree[dcode].Freq * + (5L+extra_dbits[dcode]); + } + out_length >>= 3; + Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", + s->last_lit, in_length, out_length, + 100L - out_length*100L/in_length)); + if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; + } +#endif + return (s->last_lit == s->lit_bufsize-1); + /* We avoid equality with lit_bufsize because of wraparound at 64K + * on 16 bit machines and because stored blocks are restricted to + * 64K-1 bytes. + */ +} + +/* =========================================================================== + * Send the block data compressed using the given Huffman trees + */ +local void compress_block(s, ltree, dtree) + deflate_state *s; + ct_data *ltree; /* literal tree */ + ct_data *dtree; /* distance tree */ +{ + unsigned dist; /* distance of matched string */ + int lc; /* match length or unmatched char (if dist == 0) */ + unsigned lx = 0; /* running index in l_buf */ + unsigned code; /* the code to send */ + int extra; /* number of extra bits to send */ + + if (s->last_lit != 0) do { + dist = s->d_buf[lx]; + lc = s->l_buf[lx++]; + if (dist == 0) { + send_code(s, lc, ltree); /* send a literal byte */ + Tracecv(isgraph(lc), (stderr," '%c' ", lc)); + } else { + /* Here, lc is the match length - MIN_MATCH */ + code = _length_code[lc]; + send_code(s, code+LITERALS+1, ltree); /* send the length code */ + extra = extra_lbits[code]; + if (extra != 0) { + lc -= base_length[code]; + send_bits(s, lc, extra); /* send the extra length bits */ + } + dist--; /* dist is now the match distance - 1 */ + code = d_code(dist); + Assert (code < D_CODES, "bad d_code"); + + send_code(s, code, dtree); /* send the distance code */ + extra = extra_dbits[code]; + if (extra != 0) { + dist -= base_dist[code]; + send_bits(s, dist, extra); /* send the extra distance bits */ + } + } /* literal or match pair ? */ + + /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ + Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, + "pendingBuf overflow"); + + } while (lx < s->last_lit); + + send_code(s, END_BLOCK, ltree); +} + +/* =========================================================================== + * Check if the data type is TEXT or BINARY, using the following algorithm: + * - TEXT if the two conditions below are satisfied: + * a) There are no non-portable control characters belonging to the + * "black list" (0..6, 14..25, 28..31). + * b) There is at least one printable character belonging to the + * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). + * - BINARY otherwise. + * - The following partially-portable control characters form a + * "gray list" that is ignored in this detection algorithm: + * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). + * IN assertion: the fields Freq of dyn_ltree are set. + */ +local int detect_data_type(s) + deflate_state *s; +{ + /* black_mask is the bit mask of black-listed bytes + * set bits 0..6, 14..25, and 28..31 + * 0xf3ffc07f = binary 11110011111111111100000001111111 + */ + unsigned long black_mask = 0xf3ffc07fUL; + int n; + + /* Check for non-textual ("black-listed") bytes. */ + for (n = 0; n <= 31; n++, black_mask >>= 1) + if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0)) + return Z_BINARY; + + /* Check for textual ("white-listed") bytes. */ + if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 + || s->dyn_ltree[13].Freq != 0) + return Z_TEXT; + for (n = 32; n < LITERALS; n++) + if (s->dyn_ltree[n].Freq != 0) + return Z_TEXT; + + /* There are no "black-listed" or "white-listed" bytes: + * this stream either is empty or has tolerated ("gray-listed") bytes only. + */ + return Z_BINARY; +} + +/* =========================================================================== + * Reverse the first len bits of a code, using straightforward code (a faster + * method would use a table) + * IN assertion: 1 <= len <= 15 + */ +local unsigned bi_reverse(code, len) + unsigned code; /* the value to invert */ + int len; /* its bit length */ +{ + register unsigned res = 0; + do { + res |= code & 1; + code >>= 1, res <<= 1; + } while (--len > 0); + return res >> 1; +} + +/* =========================================================================== + * Flush the bit buffer, keeping at most 7 bits in it. + */ +local void bi_flush(s) + deflate_state *s; +{ + if (s->bi_valid == 16) { + put_short(s, s->bi_buf); + s->bi_buf = 0; + s->bi_valid = 0; + } else if (s->bi_valid >= 8) { + put_byte(s, (Byte)s->bi_buf); + s->bi_buf >>= 8; + s->bi_valid -= 8; + } +} + +/* =========================================================================== + * Flush the bit buffer and align the output on a byte boundary + */ +local void bi_windup(s) + deflate_state *s; +{ + if (s->bi_valid > 8) { + put_short(s, s->bi_buf); + } else if (s->bi_valid > 0) { + put_byte(s, (Byte)s->bi_buf); + } + s->bi_buf = 0; + s->bi_valid = 0; +#ifdef DEBUG + s->bits_sent = (s->bits_sent+7) & ~7; +#endif +} + +/* =========================================================================== + * Copy a stored block, storing first the length and its + * one's complement if requested. + */ +local void copy_block(s, buf, len, header) + deflate_state *s; + charf *buf; /* the input data */ + unsigned len; /* its length */ + int header; /* true if block header must be written */ +{ + bi_windup(s); /* align on byte boundary */ + + if (header) { + put_short(s, (ush)len); + put_short(s, (ush)~len); +#ifdef DEBUG + s->bits_sent += 2*16; +#endif + } +#ifdef DEBUG + s->bits_sent += (ulg)len<<3; +#endif + while (len--) { + put_byte(s, *buf++); + } +} diff --git a/Source/ZLib/uncompr.c b/Source/ZLib/uncompr.c index cfee71d..bd4041e 100644 --- a/Source/ZLib/uncompr.c +++ b/Source/ZLib/uncompr.c @@ -1,59 +1,59 @@ -/* uncompr.c -- decompress a memory buffer - * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id: uncompr.c,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ - -#define ZLIB_INTERNAL -#include "zlib.h" - -/* =========================================================================== - Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be large enough to hold the - entire uncompressed data. (The size of the uncompressed data must have - been saved previously by the compressor and transmitted to the decompressor - by some mechanism outside the scope of this compression library.) - Upon exit, destLen is the actual size of the compressed buffer. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted. -*/ -int ZEXPORT uncompress (dest, destLen, source, sourceLen) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; -{ - z_stream stream; - int err; - - stream.next_in = (Bytef*)source; - stream.avail_in = (uInt)sourceLen; - /* Check for source > 64K on 16-bit machine: */ - if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; - - stream.next_out = dest; - stream.avail_out = (uInt)*destLen; - if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; - - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; - - err = inflateInit(&stream); - if (err != Z_OK) return err; - - err = inflate(&stream, Z_FINISH); - if (err != Z_STREAM_END) { - inflateEnd(&stream); - if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) - return Z_DATA_ERROR; - return err; - } - *destLen = stream.total_out; - - err = inflateEnd(&stream); - return err; -} +/* uncompr.c -- decompress a memory buffer + * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: uncompr.c,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ + +#define ZLIB_INTERNAL +#include "zlib.h" + +/* =========================================================================== + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total + size of the destination buffer, which must be large enough to hold the + entire uncompressed data. (The size of the uncompressed data must have + been saved previously by the compressor and transmitted to the decompressor + by some mechanism outside the scope of this compression library.) + Upon exit, destLen is the actual size of the compressed buffer. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted. +*/ +int ZEXPORT uncompress (dest, destLen, source, sourceLen) + Bytef *dest; + uLongf *destLen; + const Bytef *source; + uLong sourceLen; +{ + z_stream stream; + int err; + + stream.next_in = (Bytef*)source; + stream.avail_in = (uInt)sourceLen; + /* Check for source > 64K on 16-bit machine: */ + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; + + stream.next_out = dest; + stream.avail_out = (uInt)*destLen; + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; + + stream.zalloc = (alloc_func)0; + stream.zfree = (free_func)0; + + err = inflateInit(&stream); + if (err != Z_OK) return err; + + err = inflate(&stream, Z_FINISH); + if (err != Z_STREAM_END) { + inflateEnd(&stream); + if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) + return Z_DATA_ERROR; + return err; + } + *destLen = stream.total_out; + + err = inflateEnd(&stream); + return err; +} diff --git a/Source/ZLib/zconf.h b/Source/ZLib/zconf.h index 54b82a3..05ee2ff 100644 --- a/Source/ZLib/zconf.h +++ b/Source/ZLib/zconf.h @@ -1,506 +1,506 @@ -/* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2012 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id: zconf.h,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ - -#ifndef ZCONF_H -#define ZCONF_H - -/* - * If you *really* need a unique prefix for all types and library functions, - * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. - * Even better than compiling with -DZ_PREFIX would be to use configure to set - * this permanently in zconf.h using "./configure --zprefix". - */ -#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ -# define Z_PREFIX_SET - -/* all linked symbols */ -# define _dist_code z__dist_code -# define _length_code z__length_code -# define _tr_align z__tr_align -# define _tr_flush_block z__tr_flush_block -# define _tr_init z__tr_init -# define _tr_stored_block z__tr_stored_block -# define _tr_tally z__tr_tally -# define adler32 z_adler32 -# define adler32_combine z_adler32_combine -# define adler32_combine64 z_adler32_combine64 -# ifndef Z_SOLO -# define compress z_compress -# define compress2 z_compress2 -# define compressBound z_compressBound -# endif -# define crc32 z_crc32 -# define crc32_combine z_crc32_combine -# define crc32_combine64 z_crc32_combine64 -# define deflate z_deflate -# define deflateBound z_deflateBound -# define deflateCopy z_deflateCopy -# define deflateEnd z_deflateEnd -# define deflateInit2_ z_deflateInit2_ -# define deflateInit_ z_deflateInit_ -# define deflateParams z_deflateParams -# define deflatePending z_deflatePending -# define deflatePrime z_deflatePrime -# define deflateReset z_deflateReset -# define deflateResetKeep z_deflateResetKeep -# define deflateSetDictionary z_deflateSetDictionary -# define deflateSetHeader z_deflateSetHeader -# define deflateTune z_deflateTune -# define deflate_copyright z_deflate_copyright -# define get_crc_table z_get_crc_table -# ifndef Z_SOLO -# define gz_error z_gz_error -# define gz_intmax z_gz_intmax -# define gz_strwinerror z_gz_strwinerror -# define gzbuffer z_gzbuffer -# define gzclearerr z_gzclearerr -# define gzclose z_gzclose -# define gzclose_r z_gzclose_r -# define gzclose_w z_gzclose_w -# define gzdirect z_gzdirect -# define gzdopen z_gzdopen -# define gzeof z_gzeof -# define gzerror z_gzerror -# define gzflush z_gzflush -# define gzgetc z_gzgetc -# define gzgetc_ z_gzgetc_ -# define gzgets z_gzgets -# define gzoffset z_gzoffset -# define gzoffset64 z_gzoffset64 -# define gzopen z_gzopen -# define gzopen64 z_gzopen64 -# ifdef _WIN32 -# define gzopen_w z_gzopen_w -# endif -# define gzprintf z_gzprintf -# define gzputc z_gzputc -# define gzputs z_gzputs -# define gzread z_gzread -# define gzrewind z_gzrewind -# define gzseek z_gzseek -# define gzseek64 z_gzseek64 -# define gzsetparams z_gzsetparams -# define gztell z_gztell -# define gztell64 z_gztell64 -# define gzungetc z_gzungetc -# define gzwrite z_gzwrite -# endif -# define inflate z_inflate -# define inflateBack z_inflateBack -# define inflateBackEnd z_inflateBackEnd -# define inflateBackInit_ z_inflateBackInit_ -# define inflateCopy z_inflateCopy -# define inflateEnd z_inflateEnd -# define inflateGetHeader z_inflateGetHeader -# define inflateInit2_ z_inflateInit2_ -# define inflateInit_ z_inflateInit_ -# define inflateMark z_inflateMark -# define inflatePrime z_inflatePrime -# define inflateReset z_inflateReset -# define inflateReset2 z_inflateReset2 -# define inflateSetDictionary z_inflateSetDictionary -# define inflateSync z_inflateSync -# define inflateSyncPoint z_inflateSyncPoint -# define inflateUndermine z_inflateUndermine -# define inflateResetKeep z_inflateResetKeep -# define inflate_copyright z_inflate_copyright -# define inflate_fast z_inflate_fast -# define inflate_table z_inflate_table -# ifndef Z_SOLO -# define uncompress z_uncompress -# endif -# define zError z_zError -# ifndef Z_SOLO -# define zcalloc z_zcalloc -# define zcfree z_zcfree -# endif -# define zlibCompileFlags z_zlibCompileFlags -# define zlibVersion z_zlibVersion - -/* all zlib typedefs in zlib.h and zconf.h */ -# define Byte z_Byte -# define Bytef z_Bytef -# define alloc_func z_alloc_func -# define charf z_charf -# define free_func z_free_func -# ifndef Z_SOLO -# define gzFile z_gzFile -# endif -# define gz_header z_gz_header -# define gz_headerp z_gz_headerp -# define in_func z_in_func -# define intf z_intf -# define out_func z_out_func -# define uInt z_uInt -# define uIntf z_uIntf -# define uLong z_uLong -# define uLongf z_uLongf -# define voidp z_voidp -# define voidpc z_voidpc -# define voidpf z_voidpf - -/* all zlib structs in zlib.h and zconf.h */ -# define gz_header_s z_gz_header_s -# define internal_state z_internal_state - -#endif - -#if defined(__MSDOS__) && !defined(MSDOS) -# define MSDOS -#endif -#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) -# define OS2 -#endif -#if defined(_WINDOWS) && !defined(WINDOWS) -# define WINDOWS -#endif -#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) -# ifndef WIN32 -# define WIN32 -# endif -#endif -#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) -# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) -# ifndef SYS16BIT -# define SYS16BIT -# endif -# endif -#endif - -/* - * Compile with -DMAXSEG_64K if the alloc function cannot allocate more - * than 64k bytes at a time (needed on systems with 16-bit int). - */ -#ifdef SYS16BIT -# define MAXSEG_64K -#endif -#ifdef MSDOS -# define UNALIGNED_OK -#endif - -#ifdef __STDC_VERSION__ -# ifndef STDC -# define STDC -# endif -# if __STDC_VERSION__ >= 199901L -# ifndef STDC99 -# define STDC99 -# endif -# endif -#endif -#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) -# define STDC -#endif -#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) -# define STDC -#endif -#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) -# define STDC -#endif -#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) -# define STDC -#endif - -#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ -# define STDC -#endif - -#ifndef STDC -# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ -# define const /* note: need a more gentle solution here */ -# endif -#endif - -#if defined(ZLIB_CONST) && !defined(z_const) -# define z_const const -#else -# define z_const -#endif - -/* Some Mac compilers merge all .h files incorrectly: */ -#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) -# define NO_DUMMY_DECL -#endif - -/* Maximum value for memLevel in deflateInit2 */ -#ifndef MAX_MEM_LEVEL -# ifdef MAXSEG_64K -# define MAX_MEM_LEVEL 8 -# else -# define MAX_MEM_LEVEL 9 -# endif -#endif - -/* Maximum value for windowBits in deflateInit2 and inflateInit2. - * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files - * created by gzip. (Files created by minigzip can still be extracted by - * gzip.) - */ -#ifndef MAX_WBITS -# define MAX_WBITS 15 /* 32K LZ77 window */ -#endif - -/* The memory requirements for deflate are (in bytes): - (1 << (windowBits+2)) + (1 << (memLevel+9)) - that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) - plus a few kilobytes for small objects. For example, if you want to reduce - the default memory requirements from 256K to 128K, compile with - make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" - Of course this will generally degrade compression (there's no free lunch). - - The memory requirements for inflate are (in bytes) 1 << windowBits - that is, 32K for windowBits=15 (default value) plus a few kilobytes - for small objects. -*/ - - /* Type declarations */ - -#ifndef OF /* function prototypes */ -# ifdef STDC -# define OF(args) args -# else -# define OF(args) () -# endif -#endif - -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - -/* The following definitions for FAR are needed only for MSDOS mixed - * model programming (small or medium model with some far allocations). - * This was tested only with MSC; for other MSDOS compilers you may have - * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, - * just define FAR to be empty. - */ -#ifdef SYS16BIT -# if defined(M_I86SM) || defined(M_I86MM) - /* MSC small or medium model */ -# define SMALL_MEDIUM -# ifdef _MSC_VER -# define FAR _far -# else -# define FAR far -# endif -# endif -# if (defined(__SMALL__) || defined(__MEDIUM__)) - /* Turbo C small or medium model */ -# define SMALL_MEDIUM -# ifdef __BORLANDC__ -# define FAR _far -# else -# define FAR far -# endif -# endif -#endif - -#if defined(WINDOWS) || defined(WIN32) - /* If building or using zlib as a DLL, define ZLIB_DLL. - * This is not mandatory, but it offers a little performance increase. - */ -# ifdef ZLIB_DLL -# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) -# ifdef ZLIB_INTERNAL -# define ZEXTERN extern __declspec(dllexport) -# else -# define ZEXTERN extern __declspec(dllimport) -# endif -# endif -# endif /* ZLIB_DLL */ - /* If building or using zlib with the WINAPI/WINAPIV calling convention, - * define ZLIB_WINAPI. - * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. - */ -# ifdef ZLIB_WINAPI -# ifdef FAR -# undef FAR -# endif -# include - /* No need for _export, use ZLIB.DEF instead. */ - /* For complete Windows compatibility, use WINAPI, not __stdcall. */ -# define ZEXPORT WINAPI -# ifdef WIN32 -# define ZEXPORTVA WINAPIV -# else -# define ZEXPORTVA FAR CDECL -# endif -# endif -#endif - -#if defined (__BEOS__) -# ifdef ZLIB_DLL -# ifdef ZLIB_INTERNAL -# define ZEXPORT __declspec(dllexport) -# define ZEXPORTVA __declspec(dllexport) -# else -# define ZEXPORT __declspec(dllimport) -# define ZEXPORTVA __declspec(dllimport) -# endif -# endif -#endif - -#ifndef ZEXTERN -# define ZEXTERN extern -#endif -#ifndef ZEXPORT -# define ZEXPORT -#endif -#ifndef ZEXPORTVA -# define ZEXPORTVA -#endif - -#ifndef FAR -# define FAR -#endif - -#if !defined(__MACTYPES__) -typedef unsigned char Byte; /* 8 bits */ -#endif -typedef unsigned int uInt; /* 16 bits or more */ -typedef unsigned long uLong; /* 32 bits or more */ - -#ifdef SMALL_MEDIUM - /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ -# define Bytef Byte FAR -#else - typedef Byte FAR Bytef; -#endif -typedef char FAR charf; -typedef int FAR intf; -typedef uInt FAR uIntf; -typedef uLong FAR uLongf; - -#ifdef STDC - typedef void const *voidpc; - typedef void FAR *voidpf; - typedef void *voidp; -#else - typedef Byte const *voidpc; - typedef Byte FAR *voidpf; - typedef Byte *voidp; -#endif - -/* ./configure may #define Z_U4 here */ - -#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) -# include -# if (UINT_MAX == 0xffffffffUL) -# define Z_U4 unsigned -# else -# if (ULONG_MAX == 0xffffffffUL) -# define Z_U4 unsigned long -# else -# if (USHRT_MAX == 0xffffffffUL) -# define Z_U4 unsigned short -# endif -# endif -# endif -#endif - -#ifdef Z_U4 - typedef Z_U4 z_crc_t; -#else - typedef unsigned long z_crc_t; -#endif - -#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ -# define Z_HAVE_UNISTD_H -#endif - -#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ -# define Z_HAVE_STDARG_H -#endif - -#ifdef STDC -# ifndef Z_SOLO -# include /* for off_t */ -# endif -#endif - -#ifdef _WIN32 -# include /* for wchar_t */ -#endif - -/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and - * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even - * though the former does not conform to the LFS document), but considering - * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as - * equivalently requesting no 64-bit operations - */ -#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 -# undef _LARGEFILE64_SOURCE -#endif - -#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) -# define Z_HAVE_UNISTD_H -#endif -#ifndef Z_SOLO -# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE) -# include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ -# ifdef VMS -# include /* for off_t */ -# endif -# ifndef z_off_t -# define z_off_t off_t -# endif -# endif -#endif - -#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 -# define Z_LFS64 -#endif - -#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) -# define Z_LARGE64 -#endif - -#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) -# define Z_WANT64 -#endif - -#if !defined(SEEK_SET) && !defined(Z_SOLO) -# define SEEK_SET 0 /* Seek from beginning of file. */ -# define SEEK_CUR 1 /* Seek from current position. */ -# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ -#endif - -#ifndef z_off_t -# define z_off_t long -#endif - -#if !defined(_WIN32) && defined(Z_LARGE64) -# define z_off64_t off64_t -#else -# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) -# define z_off64_t __int64 -# else -# define z_off64_t z_off_t -# endif -#endif - -/* MVS linker does not support external names larger than 8 bytes */ -#if defined(__MVS__) - #pragma map(deflateInit_,"DEIN") - #pragma map(deflateInit2_,"DEIN2") - #pragma map(deflateEnd,"DEEND") - #pragma map(deflateBound,"DEBND") - #pragma map(inflateInit_,"ININ") - #pragma map(inflateInit2_,"ININ2") - #pragma map(inflateEnd,"INEND") - #pragma map(inflateSync,"INSY") - #pragma map(inflateSetDictionary,"INSEDI") - #pragma map(compressBound,"CMBND") - #pragma map(inflate_table,"INTABL") - #pragma map(inflate_fast,"INFA") - #pragma map(inflate_copyright,"INCOPY") -#endif - -#endif /* ZCONF_H */ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2012 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: zconf.h,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ + +#ifndef ZCONF_H +#define ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + * Even better than compiling with -DZ_PREFIX would be to use configure to set + * this permanently in zconf.h using "./configure --zprefix". + */ +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ +# define Z_PREFIX_SET + +/* all linked symbols */ +# define _dist_code z__dist_code +# define _length_code z__length_code +# define _tr_align z__tr_align +# define _tr_flush_block z__tr_flush_block +# define _tr_init z__tr_init +# define _tr_stored_block z__tr_stored_block +# define _tr_tally z__tr_tally +# define adler32 z_adler32 +# define adler32_combine z_adler32_combine +# define adler32_combine64 z_adler32_combine64 +# ifndef Z_SOLO +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# endif +# define crc32 z_crc32 +# define crc32_combine z_crc32_combine +# define crc32_combine64 z_crc32_combine64 +# define deflate z_deflate +# define deflateBound z_deflateBound +# define deflateCopy z_deflateCopy +# define deflateEnd z_deflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateInit_ z_deflateInit_ +# define deflateParams z_deflateParams +# define deflatePending z_deflatePending +# define deflatePrime z_deflatePrime +# define deflateReset z_deflateReset +# define deflateResetKeep z_deflateResetKeep +# define deflateSetDictionary z_deflateSetDictionary +# define deflateSetHeader z_deflateSetHeader +# define deflateTune z_deflateTune +# define deflate_copyright z_deflate_copyright +# define get_crc_table z_get_crc_table +# ifndef Z_SOLO +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflush z_gzflush +# define gzgetc z_gzgetc +# define gzgetc_ z_gzgetc_ +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# ifdef _WIN32 +# define gzopen_w z_gzopen_w +# endif +# define gzprintf z_gzprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzwrite z_gzwrite +# endif +# define inflate z_inflate +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define inflateBackInit_ z_inflateBackInit_ +# define inflateCopy z_inflateCopy +# define inflateEnd z_inflateEnd +# define inflateGetHeader z_inflateGetHeader +# define inflateInit2_ z_inflateInit2_ +# define inflateInit_ z_inflateInit_ +# define inflateMark z_inflateMark +# define inflatePrime z_inflatePrime +# define inflateReset z_inflateReset +# define inflateReset2 z_inflateReset2 +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateUndermine z_inflateUndermine +# define inflateResetKeep z_inflateResetKeep +# define inflate_copyright z_inflate_copyright +# define inflate_fast z_inflate_fast +# define inflate_table z_inflate_table +# ifndef Z_SOLO +# define uncompress z_uncompress +# endif +# define zError z_zError +# ifndef Z_SOLO +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# endif +# define zlibCompileFlags z_zlibCompileFlags +# define zlibVersion z_zlibVersion + +/* all zlib typedefs in zlib.h and zconf.h */ +# define Byte z_Byte +# define Bytef z_Bytef +# define alloc_func z_alloc_func +# define charf z_charf +# define free_func z_free_func +# ifndef Z_SOLO +# define gzFile z_gzFile +# endif +# define gz_header z_gz_header +# define gz_headerp z_gz_headerp +# define in_func z_in_func +# define intf z_intf +# define out_func z_out_func +# define uInt z_uInt +# define uIntf z_uIntf +# define uLong z_uLong +# define uLongf z_uLongf +# define voidp z_voidp +# define voidpc z_voidpc +# define voidpf z_voidpf + +/* all zlib structs in zlib.h and zconf.h */ +# define gz_header_s z_gz_header_s +# define internal_state z_internal_state + +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +#if defined(ZLIB_CONST) && !defined(z_const) +# define z_const const +#else +# define z_const +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +#ifndef Z_ARG /* function prototypes for stdarg */ +# if defined(STDC) || defined(Z_HAVE_STDARG_H) +# define Z_ARG(args) args +# else +# define Z_ARG(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte const *voidpc; + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +/* ./configure may #define Z_U4 here */ + +#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) +# include +# if (UINT_MAX == 0xffffffffUL) +# define Z_U4 unsigned +# else +# if (ULONG_MAX == 0xffffffffUL) +# define Z_U4 unsigned long +# else +# if (USHRT_MAX == 0xffffffffUL) +# define Z_U4 unsigned short +# endif +# endif +# endif +#endif + +#ifdef Z_U4 + typedef Z_U4 z_crc_t; +#else + typedef unsigned long z_crc_t; +#endif + +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_UNISTD_H +#endif + +#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_STDARG_H +#endif + +#ifdef STDC +# ifndef Z_SOLO +# include /* for off_t */ +# endif +#endif + +#ifdef _WIN32 +# include /* for wchar_t */ +#endif + +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even + * though the former does not conform to the LFS document), but considering + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as + * equivalently requesting no 64-bit operations + */ +#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 +# undef _LARGEFILE64_SOURCE +#endif + +#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) +# define Z_HAVE_UNISTD_H +#endif +#ifndef Z_SOLO +# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE) +# include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ +# ifdef VMS +# include /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif +# endif +#endif + +#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 +# define Z_LFS64 +#endif + +#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) +# define Z_LARGE64 +#endif + +#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) +# define Z_WANT64 +#endif + +#if !defined(SEEK_SET) && !defined(Z_SOLO) +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif + +#ifndef z_off_t +# define z_off_t long +#endif + +#if !defined(_WIN32) && defined(Z_LARGE64) +# define z_off64_t off64_t +#else +# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# define z_off64_t __int64 +# else +# define z_off64_t z_off_t +# endif +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) + #pragma map(deflateInit_,"DEIN") + #pragma map(deflateInit2_,"DEIN2") + #pragma map(deflateEnd,"DEEND") + #pragma map(deflateBound,"DEBND") + #pragma map(inflateInit_,"ININ") + #pragma map(inflateInit2_,"ININ2") + #pragma map(inflateEnd,"INEND") + #pragma map(inflateSync,"INSY") + #pragma map(inflateSetDictionary,"INSEDI") + #pragma map(compressBound,"CMBND") + #pragma map(inflate_table,"INTABL") + #pragma map(inflate_fast,"INFA") + #pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff --git a/Source/ZLib/zconf.h.in b/Source/ZLib/zconf.h.in index 49e4057..ce1cb33 100644 --- a/Source/ZLib/zconf.h.in +++ b/Source/ZLib/zconf.h.in @@ -1,506 +1,506 @@ -/* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2012 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id: zconf.h.in,v 1.4 2012/05/13 12:18:39 drolon Exp $ */ - -#ifndef ZCONF_H -#define ZCONF_H - -/* - * If you *really* need a unique prefix for all types and library functions, - * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. - * Even better than compiling with -DZ_PREFIX would be to use configure to set - * this permanently in zconf.h using "./configure --zprefix". - */ -#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ -# define Z_PREFIX_SET - -/* all linked symbols */ -# define _dist_code z__dist_code -# define _length_code z__length_code -# define _tr_align z__tr_align -# define _tr_flush_block z__tr_flush_block -# define _tr_init z__tr_init -# define _tr_stored_block z__tr_stored_block -# define _tr_tally z__tr_tally -# define adler32 z_adler32 -# define adler32_combine z_adler32_combine -# define adler32_combine64 z_adler32_combine64 -# ifndef Z_SOLO -# define compress z_compress -# define compress2 z_compress2 -# define compressBound z_compressBound -# endif -# define crc32 z_crc32 -# define crc32_combine z_crc32_combine -# define crc32_combine64 z_crc32_combine64 -# define deflate z_deflate -# define deflateBound z_deflateBound -# define deflateCopy z_deflateCopy -# define deflateEnd z_deflateEnd -# define deflateInit2_ z_deflateInit2_ -# define deflateInit_ z_deflateInit_ -# define deflateParams z_deflateParams -# define deflatePending z_deflatePending -# define deflatePrime z_deflatePrime -# define deflateReset z_deflateReset -# define deflateResetKeep z_deflateResetKeep -# define deflateSetDictionary z_deflateSetDictionary -# define deflateSetHeader z_deflateSetHeader -# define deflateTune z_deflateTune -# define deflate_copyright z_deflate_copyright -# define get_crc_table z_get_crc_table -# ifndef Z_SOLO -# define gz_error z_gz_error -# define gz_intmax z_gz_intmax -# define gz_strwinerror z_gz_strwinerror -# define gzbuffer z_gzbuffer -# define gzclearerr z_gzclearerr -# define gzclose z_gzclose -# define gzclose_r z_gzclose_r -# define gzclose_w z_gzclose_w -# define gzdirect z_gzdirect -# define gzdopen z_gzdopen -# define gzeof z_gzeof -# define gzerror z_gzerror -# define gzflush z_gzflush -# define gzgetc z_gzgetc -# define gzgetc_ z_gzgetc_ -# define gzgets z_gzgets -# define gzoffset z_gzoffset -# define gzoffset64 z_gzoffset64 -# define gzopen z_gzopen -# define gzopen64 z_gzopen64 -# ifdef _WIN32 -# define gzopen_w z_gzopen_w -# endif -# define gzprintf z_gzprintf -# define gzputc z_gzputc -# define gzputs z_gzputs -# define gzread z_gzread -# define gzrewind z_gzrewind -# define gzseek z_gzseek -# define gzseek64 z_gzseek64 -# define gzsetparams z_gzsetparams -# define gztell z_gztell -# define gztell64 z_gztell64 -# define gzungetc z_gzungetc -# define gzwrite z_gzwrite -# endif -# define inflate z_inflate -# define inflateBack z_inflateBack -# define inflateBackEnd z_inflateBackEnd -# define inflateBackInit_ z_inflateBackInit_ -# define inflateCopy z_inflateCopy -# define inflateEnd z_inflateEnd -# define inflateGetHeader z_inflateGetHeader -# define inflateInit2_ z_inflateInit2_ -# define inflateInit_ z_inflateInit_ -# define inflateMark z_inflateMark -# define inflatePrime z_inflatePrime -# define inflateReset z_inflateReset -# define inflateReset2 z_inflateReset2 -# define inflateSetDictionary z_inflateSetDictionary -# define inflateSync z_inflateSync -# define inflateSyncPoint z_inflateSyncPoint -# define inflateUndermine z_inflateUndermine -# define inflateResetKeep z_inflateResetKeep -# define inflate_copyright z_inflate_copyright -# define inflate_fast z_inflate_fast -# define inflate_table z_inflate_table -# ifndef Z_SOLO -# define uncompress z_uncompress -# endif -# define zError z_zError -# ifndef Z_SOLO -# define zcalloc z_zcalloc -# define zcfree z_zcfree -# endif -# define zlibCompileFlags z_zlibCompileFlags -# define zlibVersion z_zlibVersion - -/* all zlib typedefs in zlib.h and zconf.h */ -# define Byte z_Byte -# define Bytef z_Bytef -# define alloc_func z_alloc_func -# define charf z_charf -# define free_func z_free_func -# ifndef Z_SOLO -# define gzFile z_gzFile -# endif -# define gz_header z_gz_header -# define gz_headerp z_gz_headerp -# define in_func z_in_func -# define intf z_intf -# define out_func z_out_func -# define uInt z_uInt -# define uIntf z_uIntf -# define uLong z_uLong -# define uLongf z_uLongf -# define voidp z_voidp -# define voidpc z_voidpc -# define voidpf z_voidpf - -/* all zlib structs in zlib.h and zconf.h */ -# define gz_header_s z_gz_header_s -# define internal_state z_internal_state - -#endif - -#if defined(__MSDOS__) && !defined(MSDOS) -# define MSDOS -#endif -#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) -# define OS2 -#endif -#if defined(_WINDOWS) && !defined(WINDOWS) -# define WINDOWS -#endif -#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) -# ifndef WIN32 -# define WIN32 -# endif -#endif -#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) -# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) -# ifndef SYS16BIT -# define SYS16BIT -# endif -# endif -#endif - -/* - * Compile with -DMAXSEG_64K if the alloc function cannot allocate more - * than 64k bytes at a time (needed on systems with 16-bit int). - */ -#ifdef SYS16BIT -# define MAXSEG_64K -#endif -#ifdef MSDOS -# define UNALIGNED_OK -#endif - -#ifdef __STDC_VERSION__ -# ifndef STDC -# define STDC -# endif -# if __STDC_VERSION__ >= 199901L -# ifndef STDC99 -# define STDC99 -# endif -# endif -#endif -#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) -# define STDC -#endif -#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) -# define STDC -#endif -#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) -# define STDC -#endif -#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) -# define STDC -#endif - -#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ -# define STDC -#endif - -#ifndef STDC -# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ -# define const /* note: need a more gentle solution here */ -# endif -#endif - -#if defined(ZLIB_CONST) && !defined(z_const) -# define z_const const -#else -# define z_const -#endif - -/* Some Mac compilers merge all .h files incorrectly: */ -#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) -# define NO_DUMMY_DECL -#endif - -/* Maximum value for memLevel in deflateInit2 */ -#ifndef MAX_MEM_LEVEL -# ifdef MAXSEG_64K -# define MAX_MEM_LEVEL 8 -# else -# define MAX_MEM_LEVEL 9 -# endif -#endif - -/* Maximum value for windowBits in deflateInit2 and inflateInit2. - * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files - * created by gzip. (Files created by minigzip can still be extracted by - * gzip.) - */ -#ifndef MAX_WBITS -# define MAX_WBITS 15 /* 32K LZ77 window */ -#endif - -/* The memory requirements for deflate are (in bytes): - (1 << (windowBits+2)) + (1 << (memLevel+9)) - that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) - plus a few kilobytes for small objects. For example, if you want to reduce - the default memory requirements from 256K to 128K, compile with - make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" - Of course this will generally degrade compression (there's no free lunch). - - The memory requirements for inflate are (in bytes) 1 << windowBits - that is, 32K for windowBits=15 (default value) plus a few kilobytes - for small objects. -*/ - - /* Type declarations */ - -#ifndef OF /* function prototypes */ -# ifdef STDC -# define OF(args) args -# else -# define OF(args) () -# endif -#endif - -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - -/* The following definitions for FAR are needed only for MSDOS mixed - * model programming (small or medium model with some far allocations). - * This was tested only with MSC; for other MSDOS compilers you may have - * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, - * just define FAR to be empty. - */ -#ifdef SYS16BIT -# if defined(M_I86SM) || defined(M_I86MM) - /* MSC small or medium model */ -# define SMALL_MEDIUM -# ifdef _MSC_VER -# define FAR _far -# else -# define FAR far -# endif -# endif -# if (defined(__SMALL__) || defined(__MEDIUM__)) - /* Turbo C small or medium model */ -# define SMALL_MEDIUM -# ifdef __BORLANDC__ -# define FAR _far -# else -# define FAR far -# endif -# endif -#endif - -#if defined(WINDOWS) || defined(WIN32) - /* If building or using zlib as a DLL, define ZLIB_DLL. - * This is not mandatory, but it offers a little performance increase. - */ -# ifdef ZLIB_DLL -# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) -# ifdef ZLIB_INTERNAL -# define ZEXTERN extern __declspec(dllexport) -# else -# define ZEXTERN extern __declspec(dllimport) -# endif -# endif -# endif /* ZLIB_DLL */ - /* If building or using zlib with the WINAPI/WINAPIV calling convention, - * define ZLIB_WINAPI. - * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. - */ -# ifdef ZLIB_WINAPI -# ifdef FAR -# undef FAR -# endif -# include - /* No need for _export, use ZLIB.DEF instead. */ - /* For complete Windows compatibility, use WINAPI, not __stdcall. */ -# define ZEXPORT WINAPI -# ifdef WIN32 -# define ZEXPORTVA WINAPIV -# else -# define ZEXPORTVA FAR CDECL -# endif -# endif -#endif - -#if defined (__BEOS__) -# ifdef ZLIB_DLL -# ifdef ZLIB_INTERNAL -# define ZEXPORT __declspec(dllexport) -# define ZEXPORTVA __declspec(dllexport) -# else -# define ZEXPORT __declspec(dllimport) -# define ZEXPORTVA __declspec(dllimport) -# endif -# endif -#endif - -#ifndef ZEXTERN -# define ZEXTERN extern -#endif -#ifndef ZEXPORT -# define ZEXPORT -#endif -#ifndef ZEXPORTVA -# define ZEXPORTVA -#endif - -#ifndef FAR -# define FAR -#endif - -#if !defined(__MACTYPES__) -typedef unsigned char Byte; /* 8 bits */ -#endif -typedef unsigned int uInt; /* 16 bits or more */ -typedef unsigned long uLong; /* 32 bits or more */ - -#ifdef SMALL_MEDIUM - /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ -# define Bytef Byte FAR -#else - typedef Byte FAR Bytef; -#endif -typedef char FAR charf; -typedef int FAR intf; -typedef uInt FAR uIntf; -typedef uLong FAR uLongf; - -#ifdef STDC - typedef void const *voidpc; - typedef void FAR *voidpf; - typedef void *voidp; -#else - typedef Byte const *voidpc; - typedef Byte FAR *voidpf; - typedef Byte *voidp; -#endif - -/* ./configure may #define Z_U4 here */ - -#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) -# include -# if (UINT_MAX == 0xffffffffUL) -# define Z_U4 unsigned -# else -# if (ULONG_MAX == 0xffffffffUL) -# define Z_U4 unsigned long -# else -# if (USHRT_MAX == 0xffffffffUL) -# define Z_U4 unsigned short -# endif -# endif -# endif -#endif - -#ifdef Z_U4 - typedef Z_U4 z_crc_t; -#else - typedef unsigned long z_crc_t; -#endif - -#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ -# define Z_HAVE_UNISTD_H -#endif - -#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ -# define Z_HAVE_STDARG_H -#endif - -#ifdef STDC -# ifndef Z_SOLO -# include /* for off_t */ -# endif -#endif - -#ifdef _WIN32 -# include /* for wchar_t */ -#endif - -/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and - * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even - * though the former does not conform to the LFS document), but considering - * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as - * equivalently requesting no 64-bit operations - */ -#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 -# undef _LARGEFILE64_SOURCE -#endif - -#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) -# define Z_HAVE_UNISTD_H -#endif -#ifndef Z_SOLO -# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE) -# include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ -# ifdef VMS -# include /* for off_t */ -# endif -# ifndef z_off_t -# define z_off_t off_t -# endif -# endif -#endif - -#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 -# define Z_LFS64 -#endif - -#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) -# define Z_LARGE64 -#endif - -#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) -# define Z_WANT64 -#endif - -#if !defined(SEEK_SET) && !defined(Z_SOLO) -# define SEEK_SET 0 /* Seek from beginning of file. */ -# define SEEK_CUR 1 /* Seek from current position. */ -# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ -#endif - -#ifndef z_off_t -# define z_off_t long -#endif - -#if !defined(_WIN32) && defined(Z_LARGE64) -# define z_off64_t off64_t -#else -# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) -# define z_off64_t __int64 -# else -# define z_off64_t z_off_t -# endif -#endif - -/* MVS linker does not support external names larger than 8 bytes */ -#if defined(__MVS__) - #pragma map(deflateInit_,"DEIN") - #pragma map(deflateInit2_,"DEIN2") - #pragma map(deflateEnd,"DEEND") - #pragma map(deflateBound,"DEBND") - #pragma map(inflateInit_,"ININ") - #pragma map(inflateInit2_,"ININ2") - #pragma map(inflateEnd,"INEND") - #pragma map(inflateSync,"INSY") - #pragma map(inflateSetDictionary,"INSEDI") - #pragma map(compressBound,"CMBND") - #pragma map(inflate_table,"INTABL") - #pragma map(inflate_fast,"INFA") - #pragma map(inflate_copyright,"INCOPY") -#endif - -#endif /* ZCONF_H */ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2012 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: zconf.h.in,v 1.4 2012/05/13 12:18:39 drolon Exp $ */ + +#ifndef ZCONF_H +#define ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + * Even better than compiling with -DZ_PREFIX would be to use configure to set + * this permanently in zconf.h using "./configure --zprefix". + */ +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ +# define Z_PREFIX_SET + +/* all linked symbols */ +# define _dist_code z__dist_code +# define _length_code z__length_code +# define _tr_align z__tr_align +# define _tr_flush_block z__tr_flush_block +# define _tr_init z__tr_init +# define _tr_stored_block z__tr_stored_block +# define _tr_tally z__tr_tally +# define adler32 z_adler32 +# define adler32_combine z_adler32_combine +# define adler32_combine64 z_adler32_combine64 +# ifndef Z_SOLO +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# endif +# define crc32 z_crc32 +# define crc32_combine z_crc32_combine +# define crc32_combine64 z_crc32_combine64 +# define deflate z_deflate +# define deflateBound z_deflateBound +# define deflateCopy z_deflateCopy +# define deflateEnd z_deflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateInit_ z_deflateInit_ +# define deflateParams z_deflateParams +# define deflatePending z_deflatePending +# define deflatePrime z_deflatePrime +# define deflateReset z_deflateReset +# define deflateResetKeep z_deflateResetKeep +# define deflateSetDictionary z_deflateSetDictionary +# define deflateSetHeader z_deflateSetHeader +# define deflateTune z_deflateTune +# define deflate_copyright z_deflate_copyright +# define get_crc_table z_get_crc_table +# ifndef Z_SOLO +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflush z_gzflush +# define gzgetc z_gzgetc +# define gzgetc_ z_gzgetc_ +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# ifdef _WIN32 +# define gzopen_w z_gzopen_w +# endif +# define gzprintf z_gzprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzwrite z_gzwrite +# endif +# define inflate z_inflate +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define inflateBackInit_ z_inflateBackInit_ +# define inflateCopy z_inflateCopy +# define inflateEnd z_inflateEnd +# define inflateGetHeader z_inflateGetHeader +# define inflateInit2_ z_inflateInit2_ +# define inflateInit_ z_inflateInit_ +# define inflateMark z_inflateMark +# define inflatePrime z_inflatePrime +# define inflateReset z_inflateReset +# define inflateReset2 z_inflateReset2 +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateUndermine z_inflateUndermine +# define inflateResetKeep z_inflateResetKeep +# define inflate_copyright z_inflate_copyright +# define inflate_fast z_inflate_fast +# define inflate_table z_inflate_table +# ifndef Z_SOLO +# define uncompress z_uncompress +# endif +# define zError z_zError +# ifndef Z_SOLO +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# endif +# define zlibCompileFlags z_zlibCompileFlags +# define zlibVersion z_zlibVersion + +/* all zlib typedefs in zlib.h and zconf.h */ +# define Byte z_Byte +# define Bytef z_Bytef +# define alloc_func z_alloc_func +# define charf z_charf +# define free_func z_free_func +# ifndef Z_SOLO +# define gzFile z_gzFile +# endif +# define gz_header z_gz_header +# define gz_headerp z_gz_headerp +# define in_func z_in_func +# define intf z_intf +# define out_func z_out_func +# define uInt z_uInt +# define uIntf z_uIntf +# define uLong z_uLong +# define uLongf z_uLongf +# define voidp z_voidp +# define voidpc z_voidpc +# define voidpf z_voidpf + +/* all zlib structs in zlib.h and zconf.h */ +# define gz_header_s z_gz_header_s +# define internal_state z_internal_state + +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +#if defined(ZLIB_CONST) && !defined(z_const) +# define z_const const +#else +# define z_const +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +#ifndef Z_ARG /* function prototypes for stdarg */ +# if defined(STDC) || defined(Z_HAVE_STDARG_H) +# define Z_ARG(args) args +# else +# define Z_ARG(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte const *voidpc; + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +/* ./configure may #define Z_U4 here */ + +#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) +# include +# if (UINT_MAX == 0xffffffffUL) +# define Z_U4 unsigned +# else +# if (ULONG_MAX == 0xffffffffUL) +# define Z_U4 unsigned long +# else +# if (USHRT_MAX == 0xffffffffUL) +# define Z_U4 unsigned short +# endif +# endif +# endif +#endif + +#ifdef Z_U4 + typedef Z_U4 z_crc_t; +#else + typedef unsigned long z_crc_t; +#endif + +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_UNISTD_H +#endif + +#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_STDARG_H +#endif + +#ifdef STDC +# ifndef Z_SOLO +# include /* for off_t */ +# endif +#endif + +#ifdef _WIN32 +# include /* for wchar_t */ +#endif + +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even + * though the former does not conform to the LFS document), but considering + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as + * equivalently requesting no 64-bit operations + */ +#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 +# undef _LARGEFILE64_SOURCE +#endif + +#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) +# define Z_HAVE_UNISTD_H +#endif +#ifndef Z_SOLO +# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE) +# include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ +# ifdef VMS +# include /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif +# endif +#endif + +#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 +# define Z_LFS64 +#endif + +#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) +# define Z_LARGE64 +#endif + +#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) +# define Z_WANT64 +#endif + +#if !defined(SEEK_SET) && !defined(Z_SOLO) +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif + +#ifndef z_off_t +# define z_off_t long +#endif + +#if !defined(_WIN32) && defined(Z_LARGE64) +# define z_off64_t off64_t +#else +# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# define z_off64_t __int64 +# else +# define z_off64_t z_off_t +# endif +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) + #pragma map(deflateInit_,"DEIN") + #pragma map(deflateInit2_,"DEIN2") + #pragma map(deflateEnd,"DEEND") + #pragma map(deflateBound,"DEBND") + #pragma map(inflateInit_,"ININ") + #pragma map(inflateInit2_,"ININ2") + #pragma map(inflateEnd,"INEND") + #pragma map(inflateSync,"INSY") + #pragma map(inflateSetDictionary,"INSEDI") + #pragma map(compressBound,"CMBND") + #pragma map(inflate_table,"INTABL") + #pragma map(inflate_fast,"INFA") + #pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff --git a/Source/ZLib/zutil.c b/Source/ZLib/zutil.c index 344fcf7..b11e5b5 100644 --- a/Source/ZLib/zutil.c +++ b/Source/ZLib/zutil.c @@ -1,324 +1,324 @@ -/* zutil.c -- target dependent utility functions for the compression library - * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id: zutil.c,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ - -#include "zutil.h" -#ifndef Z_SOLO -# include "gzguts.h" -#endif - -#ifndef NO_DUMMY_DECL -struct internal_state {int dummy;}; /* for buggy compilers */ -#endif - -const char * const z_errmsg[10] = { -"need dictionary", /* Z_NEED_DICT 2 */ -"stream end", /* Z_STREAM_END 1 */ -"", /* Z_OK 0 */ -"file error", /* Z_ERRNO (-1) */ -"stream error", /* Z_STREAM_ERROR (-2) */ -"data error", /* Z_DATA_ERROR (-3) */ -"insufficient memory", /* Z_MEM_ERROR (-4) */ -"buffer error", /* Z_BUF_ERROR (-5) */ -"incompatible version",/* Z_VERSION_ERROR (-6) */ -""}; - - -const char * ZEXPORT zlibVersion() -{ - return ZLIB_VERSION; -} - -uLong ZEXPORT zlibCompileFlags() -{ - uLong flags; - - flags = 0; - switch ((int)(sizeof(uInt))) { - case 2: break; - case 4: flags += 1; break; - case 8: flags += 2; break; - default: flags += 3; - } - switch ((int)(sizeof(uLong))) { - case 2: break; - case 4: flags += 1 << 2; break; - case 8: flags += 2 << 2; break; - default: flags += 3 << 2; - } - switch ((int)(sizeof(voidpf))) { - case 2: break; - case 4: flags += 1 << 4; break; - case 8: flags += 2 << 4; break; - default: flags += 3 << 4; - } - switch ((int)(sizeof(z_off_t))) { - case 2: break; - case 4: flags += 1 << 6; break; - case 8: flags += 2 << 6; break; - default: flags += 3 << 6; - } -#ifdef DEBUG - flags += 1 << 8; -#endif -#if defined(ASMV) || defined(ASMINF) - flags += 1 << 9; -#endif -#ifdef ZLIB_WINAPI - flags += 1 << 10; -#endif -#ifdef BUILDFIXED - flags += 1 << 12; -#endif -#ifdef DYNAMIC_CRC_TABLE - flags += 1 << 13; -#endif -#ifdef NO_GZCOMPRESS - flags += 1L << 16; -#endif -#ifdef NO_GZIP - flags += 1L << 17; -#endif -#ifdef PKZIP_BUG_WORKAROUND - flags += 1L << 20; -#endif -#ifdef FASTEST - flags += 1L << 21; -#endif -#if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifdef NO_vsnprintf - flags += 1L << 25; -# ifdef HAS_vsprintf_void - flags += 1L << 26; -# endif -# else -# ifdef HAS_vsnprintf_void - flags += 1L << 26; -# endif -# endif -#else - flags += 1L << 24; -# ifdef NO_snprintf - flags += 1L << 25; -# ifdef HAS_sprintf_void - flags += 1L << 26; -# endif -# else -# ifdef HAS_snprintf_void - flags += 1L << 26; -# endif -# endif -#endif - return flags; -} - -#ifdef DEBUG - -# ifndef verbose -# define verbose 0 -# endif -int ZLIB_INTERNAL z_verbose = verbose; - -void ZLIB_INTERNAL z_error (m) - char *m; -{ - fprintf(stderr, "%s\n", m); - exit(1); -} -#endif - -/* exported to allow conversion of error code to string for compress() and - * uncompress() - */ -const char * ZEXPORT zError(err) - int err; -{ - return ERR_MSG(err); -} - -#if defined(_WIN32_WCE) - /* The Microsoft C Run-Time Library for Windows CE doesn't have - * errno. We define it as a global variable to simplify porting. - * Its value is always 0 and should not be used. - */ - int errno = 0; -#endif - -#ifndef HAVE_MEMCPY - -void ZLIB_INTERNAL zmemcpy(dest, source, len) - Bytef* dest; - const Bytef* source; - uInt len; -{ - if (len == 0) return; - do { - *dest++ = *source++; /* ??? to be unrolled */ - } while (--len != 0); -} - -int ZLIB_INTERNAL zmemcmp(s1, s2, len) - const Bytef* s1; - const Bytef* s2; - uInt len; -{ - uInt j; - - for (j = 0; j < len; j++) { - if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; - } - return 0; -} - -void ZLIB_INTERNAL zmemzero(dest, len) - Bytef* dest; - uInt len; -{ - if (len == 0) return; - do { - *dest++ = 0; /* ??? to be unrolled */ - } while (--len != 0); -} -#endif - -#ifndef Z_SOLO - -#ifdef SYS16BIT - -#ifdef __TURBOC__ -/* Turbo C in 16-bit mode */ - -# define MY_ZCALLOC - -/* Turbo C malloc() does not allow dynamic allocation of 64K bytes - * and farmalloc(64K) returns a pointer with an offset of 8, so we - * must fix the pointer. Warning: the pointer must be put back to its - * original form in order to free it, use zcfree(). - */ - -#define MAX_PTR 10 -/* 10*64K = 640K */ - -local int next_ptr = 0; - -typedef struct ptr_table_s { - voidpf org_ptr; - voidpf new_ptr; -} ptr_table; - -local ptr_table table[MAX_PTR]; -/* This table is used to remember the original form of pointers - * to large buffers (64K). Such pointers are normalized with a zero offset. - * Since MSDOS is not a preemptive multitasking OS, this table is not - * protected from concurrent access. This hack doesn't work anyway on - * a protected system like OS/2. Use Microsoft C instead. - */ - -voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) -{ - voidpf buf = opaque; /* just to make some compilers happy */ - ulg bsize = (ulg)items*size; - - /* If we allocate less than 65520 bytes, we assume that farmalloc - * will return a usable pointer which doesn't have to be normalized. - */ - if (bsize < 65520L) { - buf = farmalloc(bsize); - if (*(ush*)&buf != 0) return buf; - } else { - buf = farmalloc(bsize + 16L); - } - if (buf == NULL || next_ptr >= MAX_PTR) return NULL; - table[next_ptr].org_ptr = buf; - - /* Normalize the pointer to seg:0 */ - *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; - *(ush*)&buf = 0; - table[next_ptr++].new_ptr = buf; - return buf; -} - -void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) -{ - int n; - if (*(ush*)&ptr != 0) { /* object < 64K */ - farfree(ptr); - return; - } - /* Find the original pointer */ - for (n = 0; n < next_ptr; n++) { - if (ptr != table[n].new_ptr) continue; - - farfree(table[n].org_ptr); - while (++n < next_ptr) { - table[n-1] = table[n]; - } - next_ptr--; - return; - } - ptr = opaque; /* just to make some compilers happy */ - Assert(0, "zcfree: ptr not found"); -} - -#endif /* __TURBOC__ */ - - -#ifdef M_I86 -/* Microsoft C in 16-bit mode */ - -# define MY_ZCALLOC - -#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) -# define _halloc halloc -# define _hfree hfree -#endif - -voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) -{ - if (opaque) opaque = 0; /* to make compiler happy */ - return _halloc((long)items, size); -} - -void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) -{ - if (opaque) opaque = 0; /* to make compiler happy */ - _hfree(ptr); -} - -#endif /* M_I86 */ - -#endif /* SYS16BIT */ - - -#ifndef MY_ZCALLOC /* Any system without a special alloc function */ - -#ifndef STDC -extern voidp malloc OF((uInt size)); -extern voidp calloc OF((uInt items, uInt size)); -extern void free OF((voidpf ptr)); -#endif - -voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) - voidpf opaque; - unsigned items; - unsigned size; -{ - if (opaque) items += size - size; /* make compiler happy */ - return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : - (voidpf)calloc(items, size); -} - -void ZLIB_INTERNAL zcfree (opaque, ptr) - voidpf opaque; - voidpf ptr; -{ - free(ptr); - if (opaque) return; /* make compiler happy */ -} - -#endif /* MY_ZCALLOC */ - -#endif /* !Z_SOLO */ +/* zutil.c -- target dependent utility functions for the compression library + * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: zutil.c,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ + +#include "zutil.h" +#ifndef Z_SOLO +# include "gzguts.h" +#endif + +#ifndef NO_DUMMY_DECL +struct internal_state {int dummy;}; /* for buggy compilers */ +#endif + +const char * const z_errmsg[10] = { +"need dictionary", /* Z_NEED_DICT 2 */ +"stream end", /* Z_STREAM_END 1 */ +"", /* Z_OK 0 */ +"file error", /* Z_ERRNO (-1) */ +"stream error", /* Z_STREAM_ERROR (-2) */ +"data error", /* Z_DATA_ERROR (-3) */ +"insufficient memory", /* Z_MEM_ERROR (-4) */ +"buffer error", /* Z_BUF_ERROR (-5) */ +"incompatible version",/* Z_VERSION_ERROR (-6) */ +""}; + + +const char * ZEXPORT zlibVersion() +{ + return ZLIB_VERSION; +} + +uLong ZEXPORT zlibCompileFlags() +{ + uLong flags; + + flags = 0; + switch ((int)(sizeof(uInt))) { + case 2: break; + case 4: flags += 1; break; + case 8: flags += 2; break; + default: flags += 3; + } + switch ((int)(sizeof(uLong))) { + case 2: break; + case 4: flags += 1 << 2; break; + case 8: flags += 2 << 2; break; + default: flags += 3 << 2; + } + switch ((int)(sizeof(voidpf))) { + case 2: break; + case 4: flags += 1 << 4; break; + case 8: flags += 2 << 4; break; + default: flags += 3 << 4; + } + switch ((int)(sizeof(z_off_t))) { + case 2: break; + case 4: flags += 1 << 6; break; + case 8: flags += 2 << 6; break; + default: flags += 3 << 6; + } +#ifdef DEBUG + flags += 1 << 8; +#endif +#if defined(ASMV) || defined(ASMINF) + flags += 1 << 9; +#endif +#ifdef ZLIB_WINAPI + flags += 1 << 10; +#endif +#ifdef BUILDFIXED + flags += 1 << 12; +#endif +#ifdef DYNAMIC_CRC_TABLE + flags += 1 << 13; +#endif +#ifdef NO_GZCOMPRESS + flags += 1L << 16; +#endif +#ifdef NO_GZIP + flags += 1L << 17; +#endif +#ifdef PKZIP_BUG_WORKAROUND + flags += 1L << 20; +#endif +#ifdef FASTEST + flags += 1L << 21; +#endif +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +# ifdef NO_vsnprintf + flags += 1L << 25; +# ifdef HAS_vsprintf_void + flags += 1L << 26; +# endif +# else +# ifdef HAS_vsnprintf_void + flags += 1L << 26; +# endif +# endif +#else + flags += 1L << 24; +# ifdef NO_snprintf + flags += 1L << 25; +# ifdef HAS_sprintf_void + flags += 1L << 26; +# endif +# else +# ifdef HAS_snprintf_void + flags += 1L << 26; +# endif +# endif +#endif + return flags; +} + +#ifdef DEBUG + +# ifndef verbose +# define verbose 0 +# endif +int ZLIB_INTERNAL z_verbose = verbose; + +void ZLIB_INTERNAL z_error (m) + char *m; +{ + fprintf(stderr, "%s\n", m); + exit(1); +} +#endif + +/* exported to allow conversion of error code to string for compress() and + * uncompress() + */ +const char * ZEXPORT zError(err) + int err; +{ + return ERR_MSG(err); +} + +#if defined(_WIN32_WCE) + /* The Microsoft C Run-Time Library for Windows CE doesn't have + * errno. We define it as a global variable to simplify porting. + * Its value is always 0 and should not be used. + */ + int errno = 0; +#endif + +#ifndef HAVE_MEMCPY + +void ZLIB_INTERNAL zmemcpy(dest, source, len) + Bytef* dest; + const Bytef* source; + uInt len; +{ + if (len == 0) return; + do { + *dest++ = *source++; /* ??? to be unrolled */ + } while (--len != 0); +} + +int ZLIB_INTERNAL zmemcmp(s1, s2, len) + const Bytef* s1; + const Bytef* s2; + uInt len; +{ + uInt j; + + for (j = 0; j < len; j++) { + if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; + } + return 0; +} + +void ZLIB_INTERNAL zmemzero(dest, len) + Bytef* dest; + uInt len; +{ + if (len == 0) return; + do { + *dest++ = 0; /* ??? to be unrolled */ + } while (--len != 0); +} +#endif + +#ifndef Z_SOLO + +#ifdef SYS16BIT + +#ifdef __TURBOC__ +/* Turbo C in 16-bit mode */ + +# define MY_ZCALLOC + +/* Turbo C malloc() does not allow dynamic allocation of 64K bytes + * and farmalloc(64K) returns a pointer with an offset of 8, so we + * must fix the pointer. Warning: the pointer must be put back to its + * original form in order to free it, use zcfree(). + */ + +#define MAX_PTR 10 +/* 10*64K = 640K */ + +local int next_ptr = 0; + +typedef struct ptr_table_s { + voidpf org_ptr; + voidpf new_ptr; +} ptr_table; + +local ptr_table table[MAX_PTR]; +/* This table is used to remember the original form of pointers + * to large buffers (64K). Such pointers are normalized with a zero offset. + * Since MSDOS is not a preemptive multitasking OS, this table is not + * protected from concurrent access. This hack doesn't work anyway on + * a protected system like OS/2. Use Microsoft C instead. + */ + +voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) +{ + voidpf buf = opaque; /* just to make some compilers happy */ + ulg bsize = (ulg)items*size; + + /* If we allocate less than 65520 bytes, we assume that farmalloc + * will return a usable pointer which doesn't have to be normalized. + */ + if (bsize < 65520L) { + buf = farmalloc(bsize); + if (*(ush*)&buf != 0) return buf; + } else { + buf = farmalloc(bsize + 16L); + } + if (buf == NULL || next_ptr >= MAX_PTR) return NULL; + table[next_ptr].org_ptr = buf; + + /* Normalize the pointer to seg:0 */ + *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; + *(ush*)&buf = 0; + table[next_ptr++].new_ptr = buf; + return buf; +} + +void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) +{ + int n; + if (*(ush*)&ptr != 0) { /* object < 64K */ + farfree(ptr); + return; + } + /* Find the original pointer */ + for (n = 0; n < next_ptr; n++) { + if (ptr != table[n].new_ptr) continue; + + farfree(table[n].org_ptr); + while (++n < next_ptr) { + table[n-1] = table[n]; + } + next_ptr--; + return; + } + ptr = opaque; /* just to make some compilers happy */ + Assert(0, "zcfree: ptr not found"); +} + +#endif /* __TURBOC__ */ + + +#ifdef M_I86 +/* Microsoft C in 16-bit mode */ + +# define MY_ZCALLOC + +#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) +# define _halloc halloc +# define _hfree hfree +#endif + +voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) +{ + if (opaque) opaque = 0; /* to make compiler happy */ + return _halloc((long)items, size); +} + +void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) +{ + if (opaque) opaque = 0; /* to make compiler happy */ + _hfree(ptr); +} + +#endif /* M_I86 */ + +#endif /* SYS16BIT */ + + +#ifndef MY_ZCALLOC /* Any system without a special alloc function */ + +#ifndef STDC +extern voidp malloc OF((uInt size)); +extern voidp calloc OF((uInt items, uInt size)); +extern void free OF((voidpf ptr)); +#endif + +voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) + voidpf opaque; + unsigned items; + unsigned size; +{ + if (opaque) items += size - size; /* make compiler happy */ + return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : + (voidpf)calloc(items, size); +} + +void ZLIB_INTERNAL zcfree (opaque, ptr) + voidpf opaque; + voidpf ptr; +{ + free(ptr); + if (opaque) return; /* make compiler happy */ +} + +#endif /* MY_ZCALLOC */ + +#endif /* !Z_SOLO */ diff --git a/Source/ZLib/zutil.h b/Source/ZLib/zutil.h index 9a54275..12eeab2 100644 --- a/Source/ZLib/zutil.h +++ b/Source/ZLib/zutil.h @@ -1,252 +1,252 @@ -/* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-2012 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* @(#) $Id: zutil.h,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ - -#ifndef ZUTIL_H -#define ZUTIL_H - -#ifdef HAVE_HIDDEN -# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) -#else -# define ZLIB_INTERNAL -#endif - -#include "zlib.h" - -#if defined(STDC) && !defined(Z_SOLO) -# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) -# include -# endif -# include -# include -#endif - -#ifdef Z_SOLO - typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */ -#endif - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - -typedef unsigned char uch; -typedef uch FAR uchf; -typedef unsigned short ush; -typedef ush FAR ushf; -typedef unsigned long ulg; - -extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ -/* (size given to avoid silly warnings with Visual C++) */ - -#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] - -#define ERR_RETURN(strm,err) \ - return (strm->msg = (char*)ERR_MSG(err), (err)) -/* To be used only when the state is known to be valid */ - - /* common constants */ - -#ifndef DEF_WBITS -# define DEF_WBITS MAX_WBITS -#endif -/* default windowBits for decompression. MAX_WBITS is for compression only */ - -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif -/* default memLevel */ - -#define STORED_BLOCK 0 -#define STATIC_TREES 1 -#define DYN_TREES 2 -/* The three kinds of block type */ - -#define MIN_MATCH 3 -#define MAX_MATCH 258 -/* The minimum and maximum match lengths */ - -#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ - - /* target dependencies */ - -#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) -# define OS_CODE 0x00 -# ifndef Z_SOLO -# if defined(__TURBOC__) || defined(__BORLANDC__) -# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) - /* Allow compilation with ANSI keywords only enabled */ - void _Cdecl farfree( void *block ); - void *_Cdecl farmalloc( unsigned long nbytes ); -# else -# include -# endif -# else /* MSC or DJGPP */ -# include -# endif -# endif -#endif - -#ifdef AMIGA -# define OS_CODE 0x01 -#endif - -#if defined(VAXC) || defined(VMS) -# define OS_CODE 0x02 -# define F_OPEN(name, mode) \ - fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") -#endif - -#if defined(ATARI) || defined(atarist) -# define OS_CODE 0x05 -#endif - -#ifdef OS2 -# define OS_CODE 0x06 -# if defined(M_I86) && !defined(Z_SOLO) -# include -# endif -#endif - -#if defined(MACOS) || defined(TARGET_OS_MAC) -# define OS_CODE 0x07 -# ifndef Z_SOLO -# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -# include /* for fdopen */ -# else -# ifndef fdopen -# define fdopen(fd,mode) NULL /* No fdopen() */ -# endif -# endif -# endif -#endif - -#ifdef TOPS20 -# define OS_CODE 0x0a -#endif - -#ifdef WIN32 -# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ -# define OS_CODE 0x0b -# endif -#endif - -#ifdef __50SERIES /* Prime/PRIMOS */ -# define OS_CODE 0x0f -#endif - -#if defined(_BEOS_) || defined(RISCOS) -# define fdopen(fd,mode) NULL /* No fdopen() */ -#endif - -#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX -# if defined(_WIN32_WCE) -# define fdopen(fd,mode) NULL /* No fdopen() */ -# ifndef _PTRDIFF_T_DEFINED - typedef int ptrdiff_t; -# define _PTRDIFF_T_DEFINED -# endif -# else -# define fdopen(fd,type) _fdopen(fd,type) -# endif -#endif - -#if defined(__BORLANDC__) && !defined(MSDOS) - #pragma warn -8004 - #pragma warn -8008 - #pragma warn -8066 -#endif - -/* provide prototypes for these when building zlib without LFS */ -#if !defined(_WIN32) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); -#endif - - /* common defaults */ - -#ifndef OS_CODE -# define OS_CODE 0x03 /* assume Unix */ -#endif - -#ifndef F_OPEN -# define F_OPEN(name, mode) fopen((name), (mode)) -#endif - - /* functions */ - -#if defined(pyr) || defined(Z_SOLO) -# define NO_MEMCPY -#endif -#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) - /* Use our own functions for small and medium model with MSC <= 5.0. - * You may have to use the same strategy for Borland C (untested). - * The __SC__ check is for Symantec. - */ -# define NO_MEMCPY -#endif -#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) -# define HAVE_MEMCPY -#endif -#ifdef HAVE_MEMCPY -# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ -# define zmemcpy _fmemcpy -# define zmemcmp _fmemcmp -# define zmemzero(dest, len) _fmemset(dest, 0, len) -# else -# define zmemcpy memcpy -# define zmemcmp memcmp -# define zmemzero(dest, len) memset(dest, 0, len) -# endif -#else - void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); - int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); - void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); -#endif - -/* Diagnostic functions */ -#ifdef DEBUG -# include - extern int ZLIB_INTERNAL z_verbose; - extern void ZLIB_INTERNAL z_error OF((char *m)); -# define Assert(cond,msg) {if(!(cond)) z_error(msg);} -# define Trace(x) {if (z_verbose>=0) fprintf x ;} -# define Tracev(x) {if (z_verbose>0) fprintf x ;} -# define Tracevv(x) {if (z_verbose>1) fprintf x ;} -# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} -# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} -#else -# define Assert(cond,msg) -# define Trace(x) -# define Tracev(x) -# define Tracevv(x) -# define Tracec(c,x) -# define Tracecv(c,x) -#endif - -#ifndef Z_SOLO - voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, - unsigned size)); - void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); -#endif - -#define ZALLOC(strm, items, size) \ - (*((strm)->zalloc))((strm)->opaque, (items), (size)) -#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) -#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} - -/* Reverse the bytes in a 32-bit value */ -#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ - (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) - -#endif /* ZUTIL_H */ +/* zutil.h -- internal interface and configuration of the compression library + * Copyright (C) 1995-2012 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* @(#) $Id: zutil.h,v 1.9 2012/05/13 12:18:39 drolon Exp $ */ + +#ifndef ZUTIL_H +#define ZUTIL_H + +#ifdef HAVE_HIDDEN +# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) +#else +# define ZLIB_INTERNAL +#endif + +#include "zlib.h" + +#if defined(STDC) && !defined(Z_SOLO) +# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) +# include +# endif +# include +# include +#endif + +#ifdef Z_SOLO + typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */ +#endif + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + +typedef unsigned char uch; +typedef uch FAR uchf; +typedef unsigned short ush; +typedef ush FAR ushf; +typedef unsigned long ulg; + +extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ +/* (size given to avoid silly warnings with Visual C++) */ + +#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] + +#define ERR_RETURN(strm,err) \ + return (strm->msg = (char*)ERR_MSG(err), (err)) +/* To be used only when the state is known to be valid */ + + /* common constants */ + +#ifndef DEF_WBITS +# define DEF_WBITS MAX_WBITS +#endif +/* default windowBits for decompression. MAX_WBITS is for compression only */ + +#if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +#else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +#endif +/* default memLevel */ + +#define STORED_BLOCK 0 +#define STATIC_TREES 1 +#define DYN_TREES 2 +/* The three kinds of block type */ + +#define MIN_MATCH 3 +#define MAX_MATCH 258 +/* The minimum and maximum match lengths */ + +#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ + + /* target dependencies */ + +#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) +# define OS_CODE 0x00 +# ifndef Z_SOLO +# if defined(__TURBOC__) || defined(__BORLANDC__) +# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) + /* Allow compilation with ANSI keywords only enabled */ + void _Cdecl farfree( void *block ); + void *_Cdecl farmalloc( unsigned long nbytes ); +# else +# include +# endif +# else /* MSC or DJGPP */ +# include +# endif +# endif +#endif + +#ifdef AMIGA +# define OS_CODE 0x01 +#endif + +#if defined(VAXC) || defined(VMS) +# define OS_CODE 0x02 +# define F_OPEN(name, mode) \ + fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") +#endif + +#if defined(ATARI) || defined(atarist) +# define OS_CODE 0x05 +#endif + +#ifdef OS2 +# define OS_CODE 0x06 +# if defined(M_I86) && !defined(Z_SOLO) +# include +# endif +#endif + +#if defined(MACOS) || defined(TARGET_OS_MAC) +# define OS_CODE 0x07 +# ifndef Z_SOLO +# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os +# include /* for fdopen */ +# else +# ifndef fdopen +# define fdopen(fd,mode) NULL /* No fdopen() */ +# endif +# endif +# endif +#endif + +#ifdef TOPS20 +# define OS_CODE 0x0a +#endif + +#ifdef WIN32 +# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ +# define OS_CODE 0x0b +# endif +#endif + +#ifdef __50SERIES /* Prime/PRIMOS */ +# define OS_CODE 0x0f +#endif + +#if defined(_BEOS_) || defined(RISCOS) +# define fdopen(fd,mode) NULL /* No fdopen() */ +#endif + +#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX +# if defined(_WIN32_WCE) +# define fdopen(fd,mode) NULL /* No fdopen() */ +# ifndef _PTRDIFF_T_DEFINED + typedef int ptrdiff_t; +# define _PTRDIFF_T_DEFINED +# endif +# else +# define fdopen(fd,type) _fdopen(fd,type) +# endif +#endif + +#if defined(__BORLANDC__) && !defined(MSDOS) + #pragma warn -8004 + #pragma warn -8008 + #pragma warn -8066 +#endif + +/* provide prototypes for these when building zlib without LFS */ +#if !defined(_WIN32) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); +#endif + + /* common defaults */ + +#ifndef OS_CODE +# define OS_CODE 0x03 /* assume Unix */ +#endif + +#ifndef F_OPEN +# define F_OPEN(name, mode) fopen((name), (mode)) +#endif + + /* functions */ + +#if defined(pyr) || defined(Z_SOLO) +# define NO_MEMCPY +#endif +#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) + /* Use our own functions for small and medium model with MSC <= 5.0. + * You may have to use the same strategy for Borland C (untested). + * The __SC__ check is for Symantec. + */ +# define NO_MEMCPY +#endif +#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) +# define HAVE_MEMCPY +#endif +#ifdef HAVE_MEMCPY +# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ +# define zmemcpy _fmemcpy +# define zmemcmp _fmemcmp +# define zmemzero(dest, len) _fmemset(dest, 0, len) +# else +# define zmemcpy memcpy +# define zmemcmp memcmp +# define zmemzero(dest, len) memset(dest, 0, len) +# endif +#else + void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); + int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); + void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); +#endif + +/* Diagnostic functions */ +#ifdef DEBUG +# include + extern int ZLIB_INTERNAL z_verbose; + extern void ZLIB_INTERNAL z_error OF((char *m)); +# define Assert(cond,msg) {if(!(cond)) z_error(msg);} +# define Trace(x) {if (z_verbose>=0) fprintf x ;} +# define Tracev(x) {if (z_verbose>0) fprintf x ;} +# define Tracevv(x) {if (z_verbose>1) fprintf x ;} +# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} +# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} +#else +# define Assert(cond,msg) +# define Trace(x) +# define Tracev(x) +# define Tracevv(x) +# define Tracec(c,x) +# define Tracecv(c,x) +#endif + +#ifndef Z_SOLO + voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, + unsigned size)); + void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); +#endif + +#define ZALLOC(strm, items, size) \ + (*((strm)->zalloc))((strm)->opaque, (items), (size)) +#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) +#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} + +/* Reverse the bytes in a 32-bit value */ +#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ + (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) + +#endif /* ZUTIL_H */ diff --git a/TestAPI/MainTestSuite.cpp b/TestAPI/MainTestSuite.cpp index af7ebdf..76d2d0e 100644 --- a/TestAPI/MainTestSuite.cpp +++ b/TestAPI/MainTestSuite.cpp @@ -1,107 +1,107 @@ -// ========================================================== -// FreeImage 3 Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "TestSuite.h" - -// ---------------------------------------------------------- - -/** - FreeImage error handler - @param fif Format / Plugin responsible for the error - @param message Error message -*/ -void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) { - printf("\n*** "); - if(fif != FIF_UNKNOWN) { - printf("%s Format\n", FreeImage_GetFormatFromFIF(fif)); - } - printf(message); - printf(" ***\n"); -} - -// ---------------------------------------------------------- - -int main(int argc, char *argv[]) { - unsigned width = 512; - unsigned height = 512; - -#if defined(_DEBUG) && defined(WIN32) - // check for memory leaks at program exit (after the 'return 0') - // through a call to _CrtDumpMemoryLeaks - // note that in debug mode, objects allocated with the new operator - // may be destroyed *after* the end of the main function. - _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF); -#endif - -#if defined(FREEIMAGE_LIB) || !defined(WIN32) - FreeImage_Initialise(); -#endif - - // initialize our own FreeImage error handler - FreeImage_SetOutputMessage(FreeImageErrorHandler); - - // test plugins capabilities - showPlugins(); - - // test the clone function - testAllocateCloneUnload("exif.jpg"); - - // test internal image types - testImageType(width, height); - - // test loading / saving / converting image types using the TIFF plugin - testImageTypeTIFF(width, height); - - // test memory IO - testMemIO("sample.png"); - - // test multipage functions - testMultiPage("sample.png"); - - // test multipage streaming - testStreamMultiPage("sample.tif"); - - // test multipage streaming with memory IO - testMultiPageMemory("sample.tif"); - - // test JPEG lossless transform & cropping - testJPEG(); - - // test get/set channel - testImageChannels(width, height); - - // test loading header only - testHeaderOnly(); - - // test Exif raw metadata loading & saving - testExifRaw(); - - // test thumbnail functions - testThumbnail("exif.jpg", 0); - -#if defined(FREEIMAGE_LIB) || !defined(WIN32) - FreeImage_DeInitialise(); -#endif - - return 0; -} - +// ========================================================== +// FreeImage 3 Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "TestSuite.h" + +// ---------------------------------------------------------- + +/** + FreeImage error handler + @param fif Format / Plugin responsible for the error + @param message Error message +*/ +void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) { + printf("\n*** "); + if(fif != FIF_UNKNOWN) { + printf("%s Format\n", FreeImage_GetFormatFromFIF(fif)); + } + printf(message); + printf(" ***\n"); +} + +// ---------------------------------------------------------- + +int main(int argc, char *argv[]) { + unsigned width = 512; + unsigned height = 512; + +#if defined(_DEBUG) && defined(WIN32) + // check for memory leaks at program exit (after the 'return 0') + // through a call to _CrtDumpMemoryLeaks + // note that in debug mode, objects allocated with the new operator + // may be destroyed *after* the end of the main function. + _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF); +#endif + +#if defined(FREEIMAGE_LIB) || !defined(WIN32) + FreeImage_Initialise(); +#endif + + // initialize our own FreeImage error handler + FreeImage_SetOutputMessage(FreeImageErrorHandler); + + // test plugins capabilities + showPlugins(); + + // test the clone function + testAllocateCloneUnload("exif.jpg"); + + // test internal image types + testImageType(width, height); + + // test loading / saving / converting image types using the TIFF plugin + testImageTypeTIFF(width, height); + + // test memory IO + testMemIO("sample.png"); + + // test multipage functions + testMultiPage("sample.png"); + + // test multipage streaming + testStreamMultiPage("sample.tif"); + + // test multipage streaming with memory IO + testMultiPageMemory("sample.tif"); + + // test JPEG lossless transform & cropping + testJPEG(); + + // test get/set channel + testImageChannels(width, height); + + // test loading header only + testHeaderOnly(); + + // test Exif raw metadata loading & saving + testExifRaw(); + + // test thumbnail functions + testThumbnail("exif.jpg", 0); + +#if defined(FREEIMAGE_LIB) || !defined(WIN32) + FreeImage_DeInitialise(); +#endif + + return 0; +} + diff --git a/TestAPI/Makefile b/TestAPI/Makefile index 0ff3e21..f204849 100644 --- a/TestAPI/Makefile +++ b/TestAPI/Makefile @@ -1,8 +1,8 @@ - -default: all - -all: - g++ -I../Dist/ *.cpp ../Dist/libfreeimage.a -o testAPI - -clean: - rm -f *.o testAPI *.png *.tif + +default: all + +all: + g++ -I../Dist/ *.cpp ../Dist/libfreeimage.a -o testAPI + +clean: + rm -f *.o testAPI *.png *.tif diff --git a/TestAPI/testChannels.cpp b/TestAPI/testChannels.cpp index f81f32b..d4c852c 100644 --- a/TestAPI/testChannels.cpp +++ b/TestAPI/testChannels.cpp @@ -1,127 +1,127 @@ -// ========================================================== -// FreeImage 3 Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "TestSuite.h" - -// Local test functions -// ---------------------------------------------------------- - -void test24BitsChannels(unsigned width, unsigned height) { - BOOL bResult = FALSE; - - // create a test 8-bit image - FIBITMAP *src = createZonePlateImage(width, height, 128); - if(src != NULL) { - // convert to 24-bit - FIBITMAP *tmp = FreeImage_ConvertTo24Bits(src); - FreeImage_Unload(src); - src = tmp; - } - assert(src != NULL); - - // save for further examination - bResult = FreeImage_Save(FIF_PNG, src, "zoneplate.png", PNG_DEFAULT); - assert(bResult); - - // test get/set channel - // ------------------------- - FIBITMAP *channel = FreeImage_GetChannel(src, FICC_GREEN); - assert(channel != NULL); - bResult = FreeImage_SetChannel(src, channel, FICC_GREEN); - assert(bResult); - FreeImage_Unload(channel); - - FreeImage_Unload(src); -} - -void test32BitsChannels(unsigned width, unsigned height) { - BOOL bResult = FALSE; - - // create a test 8-bit image - FIBITMAP *src = createZonePlateImage(width, height, 128); - if(src != NULL) { - // convert to 32-bit - FIBITMAP *tmp = FreeImage_ConvertTo32Bits(src); - FreeImage_Unload(src); - src = tmp; - } - assert(src != NULL); - - // save for further examination - bResult = FreeImage_Save(FIF_PNG, src, "zoneplate.png", PNG_DEFAULT); - assert(bResult); - - // test get/set channel - // ------------------------- - FIBITMAP *channel = FreeImage_GetChannel(src, FICC_ALPHA); - assert(channel != NULL); - bResult = FreeImage_SetChannel(src, channel, FICC_ALPHA); - assert(bResult); - FreeImage_Unload(channel); - - FreeImage_Unload(src); -} - -void testRGBAChannels(FREE_IMAGE_TYPE image_type, unsigned width, unsigned height, BOOL bUseAlpha) { - BOOL bResult = FALSE; - - // create a test image - FIBITMAP *src = FreeImage_AllocateT(image_type, width, height); - assert(src != NULL); - - // test get/set channel - // ------------------------- - { - FIBITMAP *channel = FreeImage_GetChannel(src, FICC_GREEN); - assert(channel != NULL); - bResult = FreeImage_SetChannel(src, channel, FICC_GREEN); - assert(bResult); - FreeImage_Unload(channel); - } - - if(bUseAlpha) { - FIBITMAP *alpha = FreeImage_GetChannel(src, FICC_ALPHA); - assert(alpha != NULL); - bResult = FreeImage_SetChannel(src, alpha, FICC_ALPHA); - assert(bResult); - FreeImage_Unload(alpha); - } - - FreeImage_Unload(src); -} - -// Main test functions -// ---------------------------------------------------------- - -void testImageChannels(unsigned width, unsigned height) { - - printf("testImageChannels ...\n"); - - test24BitsChannels(width, height); - test32BitsChannels(width, height); - - testRGBAChannels(FIT_RGB16, width, height, FALSE); - testRGBAChannels(FIT_RGBA16, width, height, TRUE); - - testRGBAChannels(FIT_RGBF, width, height, FALSE); - testRGBAChannels(FIT_RGBAF, width, height, TRUE); -} +// ========================================================== +// FreeImage 3 Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "TestSuite.h" + +// Local test functions +// ---------------------------------------------------------- + +void test24BitsChannels(unsigned width, unsigned height) { + BOOL bResult = FALSE; + + // create a test 8-bit image + FIBITMAP *src = createZonePlateImage(width, height, 128); + if(src != NULL) { + // convert to 24-bit + FIBITMAP *tmp = FreeImage_ConvertTo24Bits(src); + FreeImage_Unload(src); + src = tmp; + } + assert(src != NULL); + + // save for further examination + bResult = FreeImage_Save(FIF_PNG, src, "zoneplate.png", PNG_DEFAULT); + assert(bResult); + + // test get/set channel + // ------------------------- + FIBITMAP *channel = FreeImage_GetChannel(src, FICC_GREEN); + assert(channel != NULL); + bResult = FreeImage_SetChannel(src, channel, FICC_GREEN); + assert(bResult); + FreeImage_Unload(channel); + + FreeImage_Unload(src); +} + +void test32BitsChannels(unsigned width, unsigned height) { + BOOL bResult = FALSE; + + // create a test 8-bit image + FIBITMAP *src = createZonePlateImage(width, height, 128); + if(src != NULL) { + // convert to 32-bit + FIBITMAP *tmp = FreeImage_ConvertTo32Bits(src); + FreeImage_Unload(src); + src = tmp; + } + assert(src != NULL); + + // save for further examination + bResult = FreeImage_Save(FIF_PNG, src, "zoneplate.png", PNG_DEFAULT); + assert(bResult); + + // test get/set channel + // ------------------------- + FIBITMAP *channel = FreeImage_GetChannel(src, FICC_ALPHA); + assert(channel != NULL); + bResult = FreeImage_SetChannel(src, channel, FICC_ALPHA); + assert(bResult); + FreeImage_Unload(channel); + + FreeImage_Unload(src); +} + +void testRGBAChannels(FREE_IMAGE_TYPE image_type, unsigned width, unsigned height, BOOL bUseAlpha) { + BOOL bResult = FALSE; + + // create a test image + FIBITMAP *src = FreeImage_AllocateT(image_type, width, height); + assert(src != NULL); + + // test get/set channel + // ------------------------- + { + FIBITMAP *channel = FreeImage_GetChannel(src, FICC_GREEN); + assert(channel != NULL); + bResult = FreeImage_SetChannel(src, channel, FICC_GREEN); + assert(bResult); + FreeImage_Unload(channel); + } + + if(bUseAlpha) { + FIBITMAP *alpha = FreeImage_GetChannel(src, FICC_ALPHA); + assert(alpha != NULL); + bResult = FreeImage_SetChannel(src, alpha, FICC_ALPHA); + assert(bResult); + FreeImage_Unload(alpha); + } + + FreeImage_Unload(src); +} + +// Main test functions +// ---------------------------------------------------------- + +void testImageChannels(unsigned width, unsigned height) { + + printf("testImageChannels ...\n"); + + test24BitsChannels(width, height); + test32BitsChannels(width, height); + + testRGBAChannels(FIT_RGB16, width, height, FALSE); + testRGBAChannels(FIT_RGBA16, width, height, TRUE); + + testRGBAChannels(FIT_RGBF, width, height, FALSE); + testRGBAChannels(FIT_RGBAF, width, height, TRUE); +} diff --git a/TestAPI/testHeaderOnly.cpp b/TestAPI/testHeaderOnly.cpp index be40233..c533be0 100644 --- a/TestAPI/testHeaderOnly.cpp +++ b/TestAPI/testHeaderOnly.cpp @@ -1,257 +1,257 @@ -// ========================================================== -// FreeImage 3 Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "TestSuite.h" - -// Local test functions -// ---------------------------------------------------------- - -void testSupportsNoPixels() { - for (int i = 0; i < FreeImage_GetFIFCount(); i++) { - FREE_IMAGE_FORMAT fmt = (FREE_IMAGE_FORMAT)i; - if (!FreeImage_FIFSupportsNoPixels(fmt)) { - // 'header only' loading mode is not supported - continue; - } - printf("testSupportsNoPixels (%s) ...\n", FreeImage_GetFormatFromFIF(fmt)); - } -} - -/** -Test header only bitmap allocation -*/ -BOOL testHeader(const char *lpszPathName) { - int flags = FIF_LOAD_NOPIXELS; - - FIBITMAP *dib1 = NULL, *dib2 = NULL; - - try { - FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(lpszPathName); - - dib1 = FreeImage_Load(fif, lpszPathName, flags); - if(!dib1) throw(1); - - dib2 = FreeImage_Clone(dib1); - if(!dib2) throw(1); - - FreeImage_Unload(dib1); - FreeImage_Unload(dib2); - - return TRUE; - } - catch(int) { - if(dib1) FreeImage_Unload(dib1); - if(dib2) FreeImage_Unload(dib2); - } - - return FALSE; -} - -/** -Parse metadata attached to a dib -*/ -static void ParseMetadata(FIBITMAP *dib, FREE_IMAGE_MDMODEL model) { - FITAG *tag = NULL; - FIMETADATA *mdhandle = NULL; - - mdhandle = FreeImage_FindFirstMetadata(model, dib, &tag); - - if(mdhandle) { - do { - // get the tag key - const char *key = FreeImage_GetTagKey(tag); - // convert the tag value to a string - const char *value = FreeImage_TagToString(model, tag); - - // print the tag - // note that most tags do not have a description, - // especially when the metadata specifications are not available - if(FreeImage_GetTagDescription(tag)) { - //cout << FreeImage_GetTagKey(tag) << "=" << value << " - " << FreeImage_GetTagDescription(tag) << "\n"; - } else { - //cout << FreeImage_GetTagKey(tag) << "=" << value << " - " << "\n"; - } - - } while(FreeImage_FindNextMetadata(mdhandle, &tag)); - } - - FreeImage_FindCloseMetadata(mdhandle); -} - -/** -Load the header of a bitmap (without pixel data) -*/ -BOOL testHeaderData(const char *lpszPathName) { - int flags = FIF_LOAD_NOPIXELS; - - FIBITMAP *dib = NULL; - - try { - // load a file using the FIF_LOAD_NOPIXELS flag - FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(lpszPathName); - assert(FreeImage_FIFSupportsNoPixels(fif) == TRUE); - - dib = FreeImage_Load(fif, lpszPathName, flags); - if(!dib) throw(1); - - // check that dib does not contains pixels - BOOL bHasPixel = FreeImage_HasPixels(dib); - assert(bHasPixel == FALSE); - - // use accessors - FREE_IMAGE_TYPE type = FreeImage_GetImageType(dib); - unsigned width = FreeImage_GetWidth(dib); - unsigned height = FreeImage_GetHeight(dib); - unsigned bpp = FreeImage_GetBPP(dib); - // parse some metadata (see e.g. FreeImage_FindFirstMetadata) - ParseMetadata(dib, FIMD_COMMENTS); - ParseMetadata(dib, FIMD_EXIF_MAIN); - ParseMetadata(dib, FIMD_EXIF_EXIF); - ParseMetadata(dib, FIMD_EXIF_GPS); - ParseMetadata(dib, FIMD_EXIF_MAKERNOTE); - ParseMetadata(dib, FIMD_IPTC); - ParseMetadata(dib, FIMD_XMP); - - // you cannot access pixels - BYTE *bits = FreeImage_GetBits(dib); - assert(bits == NULL); - - FreeImage_Unload(dib); - - return TRUE; - } - catch(int) { - if(dib) FreeImage_Unload(dib); - } - - return FALSE; -} - -/** -Test loading and saving of Exif raw data -*/ -static BOOL -testExifRawFile(const char *lpszPathName, int load_flags, int save_flags) { - const char *lpszDstPathName = "raw_exif.jpg"; - - FIBITMAP *dib = NULL, *dst = NULL; - - try { - // load an Exif file (jpeg file) - FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(lpszPathName); - - dib = FreeImage_Load(fif, lpszPathName, load_flags); - if(!dib) throw(1); - - // check access to raw Exif data - FITAG *tag = NULL; - BOOL bResult = FreeImage_GetMetadata(FIMD_EXIF_RAW, dib, "ExifRaw", &tag); - if(tag) { - const char *key = FreeImage_GetTagKey(tag); - WORD id = FreeImage_GetTagID(tag); - FREE_IMAGE_MDTYPE type = FreeImage_GetTagType(tag); - DWORD count = FreeImage_GetTagCount(tag); - DWORD length = FreeImage_GetTagLength(tag); - BYTE *value = (BYTE*)FreeImage_GetTagValue(tag); - - // save as jpeg : Exif data should be preserved - FreeImage_Save(fif, dib, lpszDstPathName, save_flags); - - // load and check Exif raw data - fif = FreeImage_GetFileType(lpszDstPathName); - - dst = FreeImage_Load(fif, lpszDstPathName, load_flags); - if(!dst) throw(1); - - FITAG *dst_tag = NULL; - BOOL bResult = FreeImage_GetMetadata(FIMD_EXIF_RAW, dib, "ExifRaw", &dst_tag); - if(dst_tag) { - const char *key = FreeImage_GetTagKey(dst_tag); - WORD dst_id = FreeImage_GetTagID(dst_tag); - FREE_IMAGE_MDTYPE dst_type = FreeImage_GetTagType(dst_tag); - DWORD dst_count = FreeImage_GetTagCount(dst_tag); - DWORD dst_length = FreeImage_GetTagLength(dst_tag); - BYTE *dst_value = (BYTE*)FreeImage_GetTagValue(dst_tag); - - assert(length == dst_length); - } - - FreeImage_Unload(dst); - } - - FreeImage_Unload(dib); - - return TRUE; - } - catch(int) { - if(dib) FreeImage_Unload(dib); - } - - return FALSE; -} - -// Main test functions -// ---------------------------------------------------------- - -void testHeaderOnly() { - const char *src_file_jpg = "exif.jpg"; - const char *src_file_png = "sample.png"; - - BOOL bResult = TRUE; - - printf("testHeaderOnly ...\n"); - - testSupportsNoPixels(); - - // JPEG plugin - bResult = testHeader(src_file_jpg); - assert(bResult); - - bResult = testHeaderData(src_file_jpg); - assert(bResult); - - // PNG plugin - bResult = testHeader(src_file_png); - assert(bResult); - - bResult = testHeaderData(src_file_png); - assert(bResult); - - // you cannot save 'header only' FIBITMAP - bResult = testExifRawFile(src_file_jpg, FIF_LOAD_NOPIXELS, 0); - assert(bResult == FALSE); -} - -void testExifRaw() { - const char *src_file_jpg = "exif.jpg"; - - BOOL bResult = TRUE; - - printf("testExifRaw ...\n"); - - // Exif raw metadata loading & saving - - // check Exif raw metadata loading & saving - bResult = testExifRawFile(src_file_jpg, 0, 0); - assert(bResult); - -} +// ========================================================== +// FreeImage 3 Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "TestSuite.h" + +// Local test functions +// ---------------------------------------------------------- + +void testSupportsNoPixels() { + for (int i = 0; i < FreeImage_GetFIFCount(); i++) { + FREE_IMAGE_FORMAT fmt = (FREE_IMAGE_FORMAT)i; + if (!FreeImage_FIFSupportsNoPixels(fmt)) { + // 'header only' loading mode is not supported + continue; + } + printf("testSupportsNoPixels (%s) ...\n", FreeImage_GetFormatFromFIF(fmt)); + } +} + +/** +Test header only bitmap allocation +*/ +BOOL testHeader(const char *lpszPathName) { + int flags = FIF_LOAD_NOPIXELS; + + FIBITMAP *dib1 = NULL, *dib2 = NULL; + + try { + FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(lpszPathName); + + dib1 = FreeImage_Load(fif, lpszPathName, flags); + if(!dib1) throw(1); + + dib2 = FreeImage_Clone(dib1); + if(!dib2) throw(1); + + FreeImage_Unload(dib1); + FreeImage_Unload(dib2); + + return TRUE; + } + catch(int) { + if(dib1) FreeImage_Unload(dib1); + if(dib2) FreeImage_Unload(dib2); + } + + return FALSE; +} + +/** +Parse metadata attached to a dib +*/ +static void ParseMetadata(FIBITMAP *dib, FREE_IMAGE_MDMODEL model) { + FITAG *tag = NULL; + FIMETADATA *mdhandle = NULL; + + mdhandle = FreeImage_FindFirstMetadata(model, dib, &tag); + + if(mdhandle) { + do { + // get the tag key + const char *key = FreeImage_GetTagKey(tag); + // convert the tag value to a string + const char *value = FreeImage_TagToString(model, tag); + + // print the tag + // note that most tags do not have a description, + // especially when the metadata specifications are not available + if(FreeImage_GetTagDescription(tag)) { + //cout << FreeImage_GetTagKey(tag) << "=" << value << " - " << FreeImage_GetTagDescription(tag) << "\n"; + } else { + //cout << FreeImage_GetTagKey(tag) << "=" << value << " - " << "\n"; + } + + } while(FreeImage_FindNextMetadata(mdhandle, &tag)); + } + + FreeImage_FindCloseMetadata(mdhandle); +} + +/** +Load the header of a bitmap (without pixel data) +*/ +BOOL testHeaderData(const char *lpszPathName) { + int flags = FIF_LOAD_NOPIXELS; + + FIBITMAP *dib = NULL; + + try { + // load a file using the FIF_LOAD_NOPIXELS flag + FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(lpszPathName); + assert(FreeImage_FIFSupportsNoPixels(fif) == TRUE); + + dib = FreeImage_Load(fif, lpszPathName, flags); + if(!dib) throw(1); + + // check that dib does not contains pixels + BOOL bHasPixel = FreeImage_HasPixels(dib); + assert(bHasPixel == FALSE); + + // use accessors + FREE_IMAGE_TYPE type = FreeImage_GetImageType(dib); + unsigned width = FreeImage_GetWidth(dib); + unsigned height = FreeImage_GetHeight(dib); + unsigned bpp = FreeImage_GetBPP(dib); + // parse some metadata (see e.g. FreeImage_FindFirstMetadata) + ParseMetadata(dib, FIMD_COMMENTS); + ParseMetadata(dib, FIMD_EXIF_MAIN); + ParseMetadata(dib, FIMD_EXIF_EXIF); + ParseMetadata(dib, FIMD_EXIF_GPS); + ParseMetadata(dib, FIMD_EXIF_MAKERNOTE); + ParseMetadata(dib, FIMD_IPTC); + ParseMetadata(dib, FIMD_XMP); + + // you cannot access pixels + BYTE *bits = FreeImage_GetBits(dib); + assert(bits == NULL); + + FreeImage_Unload(dib); + + return TRUE; + } + catch(int) { + if(dib) FreeImage_Unload(dib); + } + + return FALSE; +} + +/** +Test loading and saving of Exif raw data +*/ +static BOOL +testExifRawFile(const char *lpszPathName, int load_flags, int save_flags) { + const char *lpszDstPathName = "raw_exif.jpg"; + + FIBITMAP *dib = NULL, *dst = NULL; + + try { + // load an Exif file (jpeg file) + FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(lpszPathName); + + dib = FreeImage_Load(fif, lpszPathName, load_flags); + if(!dib) throw(1); + + // check access to raw Exif data + FITAG *tag = NULL; + BOOL bResult = FreeImage_GetMetadata(FIMD_EXIF_RAW, dib, "ExifRaw", &tag); + if(tag) { + const char *key = FreeImage_GetTagKey(tag); + WORD id = FreeImage_GetTagID(tag); + FREE_IMAGE_MDTYPE type = FreeImage_GetTagType(tag); + DWORD count = FreeImage_GetTagCount(tag); + DWORD length = FreeImage_GetTagLength(tag); + BYTE *value = (BYTE*)FreeImage_GetTagValue(tag); + + // save as jpeg : Exif data should be preserved + FreeImage_Save(fif, dib, lpszDstPathName, save_flags); + + // load and check Exif raw data + fif = FreeImage_GetFileType(lpszDstPathName); + + dst = FreeImage_Load(fif, lpszDstPathName, load_flags); + if(!dst) throw(1); + + FITAG *dst_tag = NULL; + BOOL bResult = FreeImage_GetMetadata(FIMD_EXIF_RAW, dib, "ExifRaw", &dst_tag); + if(dst_tag) { + const char *key = FreeImage_GetTagKey(dst_tag); + WORD dst_id = FreeImage_GetTagID(dst_tag); + FREE_IMAGE_MDTYPE dst_type = FreeImage_GetTagType(dst_tag); + DWORD dst_count = FreeImage_GetTagCount(dst_tag); + DWORD dst_length = FreeImage_GetTagLength(dst_tag); + BYTE *dst_value = (BYTE*)FreeImage_GetTagValue(dst_tag); + + assert(length == dst_length); + } + + FreeImage_Unload(dst); + } + + FreeImage_Unload(dib); + + return TRUE; + } + catch(int) { + if(dib) FreeImage_Unload(dib); + } + + return FALSE; +} + +// Main test functions +// ---------------------------------------------------------- + +void testHeaderOnly() { + const char *src_file_jpg = "exif.jpg"; + const char *src_file_png = "sample.png"; + + BOOL bResult = TRUE; + + printf("testHeaderOnly ...\n"); + + testSupportsNoPixels(); + + // JPEG plugin + bResult = testHeader(src_file_jpg); + assert(bResult); + + bResult = testHeaderData(src_file_jpg); + assert(bResult); + + // PNG plugin + bResult = testHeader(src_file_png); + assert(bResult); + + bResult = testHeaderData(src_file_png); + assert(bResult); + + // you cannot save 'header only' FIBITMAP + bResult = testExifRawFile(src_file_jpg, FIF_LOAD_NOPIXELS, 0); + assert(bResult == FALSE); +} + +void testExifRaw() { + const char *src_file_jpg = "exif.jpg"; + + BOOL bResult = TRUE; + + printf("testExifRaw ...\n"); + + // Exif raw metadata loading & saving + + // check Exif raw metadata loading & saving + bResult = testExifRawFile(src_file_jpg, 0, 0); + assert(bResult); + +} diff --git a/TestAPI/testImageType.cpp b/TestAPI/testImageType.cpp index 0e316af..a93e886 100644 --- a/TestAPI/testImageType.cpp +++ b/TestAPI/testImageType.cpp @@ -1,498 +1,498 @@ -// ========================================================== -// FreeImage 3 Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "TestSuite.h" - -// Local test functions -// ---------------------------------------------------------- - -BOOL testClone(const char *lpszPathName) { - FIBITMAP *dib1 = NULL, *dib2 = NULL; - - try { - FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(lpszPathName); - - dib1 = FreeImage_Load(fif, lpszPathName, 0); - if(!dib1) throw(1); - - dib2 = FreeImage_Clone(dib1); - if(!dib2) throw(1); - - FreeImage_Unload(dib1); - FreeImage_Unload(dib2); - - return TRUE; - } - catch(int) { - if(dib1) FreeImage_Unload(dib1); - if(dib2) FreeImage_Unload(dib2); - } - - return FALSE; -} - -void testAllocateCloneUnload(const char *lpszPathName) { - printf("testAllocateCloneUnload ...\n"); - - BOOL bResult = testClone(lpszPathName); - assert(bResult); -} - -BOOL testAllocateCloneUnloadType(FREE_IMAGE_TYPE image_type, unsigned width, unsigned height) { - FIBITMAP *image = NULL; - FIBITMAP *clone = NULL; - - unsigned x, y; - - try { - // test allocation function - image = FreeImage_AllocateT(image_type, width, height, 8); - if(!image) throw(1); - - FREE_IMAGE_TYPE type = FreeImage_GetImageType(image); - if(image_type != type) throw(1); - - // test pixel access - switch(image_type) { - case FIT_BITMAP: - if(FreeImage_GetBPP(image) == 8) { - for(y = 0; y < FreeImage_GetHeight(image); y++) { - BYTE *bits = (BYTE *)FreeImage_GetScanLine(image, y); - for(x = 0; x < FreeImage_GetWidth(image); x++) { - bits[x] = 128; - } - } - } - break; - case FIT_UINT16: - for(y = 0; y < FreeImage_GetHeight(image); y++) { - unsigned short *bits = (unsigned short *)FreeImage_GetScanLine(image, y); - for(x = 0; x < FreeImage_GetWidth(image); x++) { - bits[x] = 128; - } - } - break; - case FIT_INT16: - for(y = 0; y < FreeImage_GetHeight(image); y++) { - short *bits = (short *)FreeImage_GetScanLine(image, y); - for(x = 0; x < FreeImage_GetWidth(image); x++) { - bits[x] = 128; - } - } - break; - case FIT_UINT32: - for(y = 0; y < FreeImage_GetHeight(image); y++) { - DWORD *bits = (DWORD *)FreeImage_GetScanLine(image, y); - for(x = 0; x < FreeImage_GetWidth(image); x++) { - bits[x] = 128; - } - } - break; - case FIT_INT32: - for(y = 0; y < FreeImage_GetHeight(image); y++) { - LONG *bits = (LONG *)FreeImage_GetScanLine(image, y); - for(x = 0; x < FreeImage_GetWidth(image); x++) { - bits[x] = 128; - } - } - break; - case FIT_FLOAT: - for(y = 0; y < FreeImage_GetHeight(image); y++) { - float *bits = (float *)FreeImage_GetScanLine(image, y); - for(x = 0; x < FreeImage_GetWidth(image); x++) { - bits[x] = 128; - } - } - break; - case FIT_DOUBLE: - for(y = 0; y < FreeImage_GetHeight(image); y++) { - double *bits = (double *)FreeImage_GetScanLine(image, y); - for(x = 0; x < FreeImage_GetWidth(image); x++) { - bits[x] = 128; - } - } - break; - case FIT_COMPLEX: - for(y = 0; y < FreeImage_GetHeight(image); y++) { - FICOMPLEX *bits = (FICOMPLEX *)FreeImage_GetScanLine(image, y); - for(x = 0; x < FreeImage_GetWidth(image); x++) { - bits[x].r = 128; - bits[x].i = 128; - } - } - break; - case FIT_RGB16: - for(y = 0; y < FreeImage_GetHeight(image); y++) { - FIRGB16 *bits = (FIRGB16 *)FreeImage_GetScanLine(image, y); - for(x = 0; x < FreeImage_GetWidth(image); x++) { - bits[x].red = 128; - bits[x].green = 128; - bits[x].blue = 128; - } - } - break; - case FIT_RGBF: - for(y = 0; y < FreeImage_GetHeight(image); y++) { - FIRGBF *bits = (FIRGBF *)FreeImage_GetScanLine(image, y); - for(x = 0; x < FreeImage_GetWidth(image); x++) { - bits[x].red = 128; - bits[x].green = 128; - bits[x].blue = 128; - } - } - break; - case FIT_RGBA16: - for(y = 0; y < FreeImage_GetHeight(image); y++) { - FIRGBA16 *bits = (FIRGBA16 *)FreeImage_GetScanLine(image, y); - for(x = 0; x < FreeImage_GetWidth(image); x++) { - bits[x].red = 128; - bits[x].green = 128; - bits[x].blue = 128; - bits[x].alpha = 128; - } - } - break; - case FIT_RGBAF: - for(y = 0; y < FreeImage_GetHeight(image); y++) { - FIRGBAF *bits = (FIRGBAF *)FreeImage_GetScanLine(image, y); - for(x = 0; x < FreeImage_GetWidth(image); x++) { - bits[x].red = 128; - bits[x].green = 128; - bits[x].blue = 128; - bits[x].alpha = 128; - } - } - break; - } - - - // test clone function - clone = FreeImage_Clone(image); - if(!clone) throw(1); - - if(FreeImage_GetImageType(clone) != image_type) throw(1); - - switch(image_type) { - case FIT_BITMAP: - if(FreeImage_GetBPP(clone) == 8) { - for(y = 0; y < FreeImage_GetHeight(clone); y++) { - BYTE *bits = (BYTE *)FreeImage_GetScanLine(clone, y); - for(x = 0; x < FreeImage_GetWidth(clone); x++) { - if(bits[x] != 128) - throw(1); - } - } - } - break; - case FIT_UINT16: - for(y = 0; y < FreeImage_GetHeight(clone); y++) { - unsigned short *bits = (unsigned short *)FreeImage_GetScanLine(clone, y); - for(x = 0; x < FreeImage_GetWidth(clone); x++) { - if(bits[x] != 128) - throw(1); - } - } - break; - case FIT_INT16: - for(y = 0; y < FreeImage_GetHeight(clone); y++) { - short *bits = (short *)FreeImage_GetScanLine(clone, y); - for(x = 0; x < FreeImage_GetWidth(clone); x++) { - if(bits[x] != 128) - throw(1); - } - } - break; - case FIT_UINT32: - for(y = 0; y < FreeImage_GetHeight(clone); y++) { - DWORD *bits = (DWORD *)FreeImage_GetScanLine(clone, y); - for(x = 0; x < FreeImage_GetWidth(clone); x++) { - if(bits[x] != 128) - throw(1); - } - } - break; - case FIT_INT32: - for(y = 0; y < FreeImage_GetHeight(clone); y++) { - LONG *bits = (LONG *)FreeImage_GetScanLine(clone, y); - for(x = 0; x < FreeImage_GetWidth(clone); x++) { - if(bits[x] != 128) - throw(1); - } - } - break; - case FIT_FLOAT: - for(y = 0; y < FreeImage_GetHeight(clone); y++) { - float *bits = (float *)FreeImage_GetScanLine(clone, y); - for(x = 0; x < FreeImage_GetWidth(clone); x++) { - if(bits[x] != 128) - throw(1); - } - } - break; - case FIT_DOUBLE: - for(y = 0; y < FreeImage_GetHeight(clone); y++) { - double *bits = (double *)FreeImage_GetScanLine(clone, y); - for(x = 0; x < FreeImage_GetWidth(clone); x++) { - if(bits[x] != 128) - throw(1); - } - } - break; - case FIT_COMPLEX: - for(y = 0; y < FreeImage_GetHeight(clone); y++) { - FICOMPLEX *bits = (FICOMPLEX *)FreeImage_GetScanLine(clone, y); - for(x = 0; x < FreeImage_GetWidth(clone); x++) { - if((bits[x].r != 128) || ((bits[x].r - bits[x].i) != 0)) - throw(1); - } - } - break; - case FIT_RGB16: - for(y = 0; y < FreeImage_GetHeight(clone); y++) { - FIRGB16 *bits = (FIRGB16 *)FreeImage_GetScanLine(clone, y); - for(x = 0; x < FreeImage_GetWidth(clone); x++) { - if((bits[x].red != 128) || (bits[x].green != 128) || (bits[x].blue != 128)) - throw(1); - } - } - break; - case FIT_RGBF: - for(y = 0; y < FreeImage_GetHeight(clone); y++) { - FIRGBF *bits = (FIRGBF *)FreeImage_GetScanLine(clone, y); - for(x = 0; x < FreeImage_GetWidth(clone); x++) { - if((bits[x].red != 128) || (bits[x].green != 128) || (bits[x].blue != 128)) - throw(1); - } - } - break; - case FIT_RGBA16: - for(y = 0; y < FreeImage_GetHeight(clone); y++) { - FIRGBA16 *bits = (FIRGBA16 *)FreeImage_GetScanLine(clone, y); - for(x = 0; x < FreeImage_GetWidth(clone); x++) { - if((bits[x].red != 128) || (bits[x].green != 128) || (bits[x].blue != 128) || (bits[x].alpha != 128)) - throw(1); - } - } - break; - case FIT_RGBAF: - for(y = 0; y < FreeImage_GetHeight(clone); y++) { - FIRGBAF *bits = (FIRGBAF *)FreeImage_GetScanLine(clone, y); - for(x = 0; x < FreeImage_GetWidth(clone); x++) { - if((bits[x].red != 128) || (bits[x].green != 128) || (bits[x].blue != 128) || (bits[x].alpha != 128)) - throw(1); - } - } - break; - - } - - // test unload function - FreeImage_Unload(clone); - clone = NULL; - FreeImage_Unload(image); - image = NULL; - - } catch(int) { - if(image) FreeImage_Unload(image); - if(clone) FreeImage_Unload(clone); - return FALSE; - } - return TRUE; -} - -BOOL testLoadSaveConvertImageType(FIBITMAP *src, FREE_IMAGE_TYPE image_type) { - FIBITMAP *dst = NULL; - FIBITMAP *chk = NULL; - BOOL bResult = TRUE; - - try { - // convert to type image_type - dst = FreeImage_ConvertToType(src, image_type); - if(!dst) throw(1); - - // save image as TIFF - bResult = FreeImage_Save(FIF_TIFF, dst, "TestImageType.tif", TIFF_DEFAULT); - if(!bResult) throw(1); - - // destroy dst - FreeImage_Unload(dst); - dst = NULL; - - // load image - dst = FreeImage_Load(FIF_TIFF, "TestImageType.tif", TIFF_DEFAULT); - if(!dst) throw(1); - - // convert to standard bitmap (linear scaling) - chk = FreeImage_ConvertToType(dst, FIT_BITMAP, TRUE); - if(!chk) throw(1); - FreeImage_Unload(dst); - dst = NULL; - - // save image as TIFF - bResult = FreeImage_Save(FIF_TIFF, chk, "TestImageType.tif", TIFF_DEFAULT); - if(!bResult) throw(1); - FreeImage_Unload(chk); - chk = NULL; - - - } catch(int) { - if(dst) FreeImage_Unload(dst); - if(chk) FreeImage_Unload(chk); - return FALSE; - } - - return TRUE; -} - -BOOL testLoadSaveConvertComplexType(FIBITMAP *src, FREE_IMAGE_COLOR_CHANNEL channel) { - FIBITMAP *dst = NULL; - FIBITMAP *chk_double = NULL; - FIBITMAP *chk = NULL; - BOOL bResult = TRUE; - - try { - // convert to type FICOMPLEX - dst = FreeImage_ConvertToType(src, FIT_COMPLEX); - if(!dst) throw(1); - - // save image as TIFF - bResult = FreeImage_Save(FIF_TIFF, dst, "TestImageType.tif", TIFF_DEFAULT); - if(!bResult) throw(1); - - // destroy dst - FreeImage_Unload(dst); - dst = NULL; - - // load image - dst = FreeImage_Load(FIF_TIFF, "TestImageType.tif", TIFF_DEFAULT); - if(!dst) throw(1); - - - // convert to type FIT_DOUBLE - chk_double = FreeImage_GetComplexChannel(dst, channel); - if(!chk_double) throw(1); - FreeImage_Unload(dst); - dst = NULL; - - // convert to standard bitmap (linear scaling) - chk = FreeImage_ConvertToType(chk_double, FIT_BITMAP, TRUE); - if(!chk) throw(1); - FreeImage_Unload(chk_double); - chk_double = NULL; - - // save image as TIFF - bResult = FreeImage_Save(FIF_TIFF, chk, "TestImageType.tif", TIFF_DEFAULT); - if(!bResult) throw(1); - FreeImage_Unload(chk); - chk = NULL; - - - } catch(int) { - if(dst) FreeImage_Unload(dst); - if(chk_double) FreeImage_Unload(chk_double); - if(chk) FreeImage_Unload(chk); - return FALSE; - } - - return TRUE; -} - -// Main test functions -// ---------------------------------------------------------- - -void testImageType(unsigned width, unsigned height) { - BOOL bResult = FALSE; - - printf("testImageType ...\n"); - - bResult = testAllocateCloneUnloadType(FIT_BITMAP, width, height); - assert(bResult); - bResult = testAllocateCloneUnloadType(FIT_UINT16, width, height); - assert(bResult); - bResult = testAllocateCloneUnloadType(FIT_INT16, width, height); - assert(bResult); - bResult = testAllocateCloneUnloadType(FIT_UINT32, width, height); - assert(bResult); - bResult = testAllocateCloneUnloadType(FIT_INT32, width, height); - assert(bResult); - bResult = testAllocateCloneUnloadType(FIT_FLOAT, width, height); - assert(bResult); - bResult = testAllocateCloneUnloadType(FIT_DOUBLE, width, height); - assert(bResult); - bResult = testAllocateCloneUnloadType(FIT_COMPLEX, width, height); - assert(bResult); - bResult = testAllocateCloneUnloadType(FIT_RGB16, width, height); - assert(bResult); - bResult = testAllocateCloneUnloadType(FIT_RGBA16, width, height); - assert(bResult); - bResult = testAllocateCloneUnloadType(FIT_RGBF, width, height); - assert(bResult); - bResult = testAllocateCloneUnloadType(FIT_RGBAF, width, height); - assert(bResult); -} - - -void testImageTypeTIFF(unsigned width, unsigned height) { - BOOL bResult = FALSE; - - printf("testImageTypeTIFF ...\n"); - - // create a test 8-bit image - FIBITMAP *src = createZonePlateImage(width, height, 128); - assert(src != NULL); - - // save for further examination - bResult = FreeImage_Save(FIF_PNG, src, "zoneplate.png", PNG_DEFAULT); - assert(bResult); - - // test load /save / convert - // ------------------------- - - bResult = testLoadSaveConvertImageType(src, FIT_BITMAP); - assert(bResult); - bResult = testLoadSaveConvertImageType(src, FIT_UINT16); - assert(bResult); - bResult = testLoadSaveConvertImageType(src, FIT_INT16); - assert(bResult); - bResult = testLoadSaveConvertImageType(src, FIT_UINT32); - assert(bResult); - bResult = testLoadSaveConvertImageType(src, FIT_INT32); - assert(bResult); - bResult = testLoadSaveConvertImageType(src, FIT_FLOAT); - assert(bResult); - bResult = testLoadSaveConvertImageType(src, FIT_DOUBLE); - assert(bResult); - - // complex type - bResult = testLoadSaveConvertComplexType(src, FICC_REAL); - assert(bResult); - bResult = testLoadSaveConvertComplexType(src, FICC_IMAG); - assert(bResult); - bResult = testLoadSaveConvertComplexType(src, FICC_MAG); - assert(bResult); - bResult = testLoadSaveConvertComplexType(src, FICC_PHASE); - assert(bResult); - - // free test image - FreeImage_Unload(src); - -} +// ========================================================== +// FreeImage 3 Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "TestSuite.h" + +// Local test functions +// ---------------------------------------------------------- + +BOOL testClone(const char *lpszPathName) { + FIBITMAP *dib1 = NULL, *dib2 = NULL; + + try { + FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(lpszPathName); + + dib1 = FreeImage_Load(fif, lpszPathName, 0); + if(!dib1) throw(1); + + dib2 = FreeImage_Clone(dib1); + if(!dib2) throw(1); + + FreeImage_Unload(dib1); + FreeImage_Unload(dib2); + + return TRUE; + } + catch(int) { + if(dib1) FreeImage_Unload(dib1); + if(dib2) FreeImage_Unload(dib2); + } + + return FALSE; +} + +void testAllocateCloneUnload(const char *lpszPathName) { + printf("testAllocateCloneUnload ...\n"); + + BOOL bResult = testClone(lpszPathName); + assert(bResult); +} + +BOOL testAllocateCloneUnloadType(FREE_IMAGE_TYPE image_type, unsigned width, unsigned height) { + FIBITMAP *image = NULL; + FIBITMAP *clone = NULL; + + unsigned x, y; + + try { + // test allocation function + image = FreeImage_AllocateT(image_type, width, height, 8); + if(!image) throw(1); + + FREE_IMAGE_TYPE type = FreeImage_GetImageType(image); + if(image_type != type) throw(1); + + // test pixel access + switch(image_type) { + case FIT_BITMAP: + if(FreeImage_GetBPP(image) == 8) { + for(y = 0; y < FreeImage_GetHeight(image); y++) { + BYTE *bits = (BYTE *)FreeImage_GetScanLine(image, y); + for(x = 0; x < FreeImage_GetWidth(image); x++) { + bits[x] = 128; + } + } + } + break; + case FIT_UINT16: + for(y = 0; y < FreeImage_GetHeight(image); y++) { + unsigned short *bits = (unsigned short *)FreeImage_GetScanLine(image, y); + for(x = 0; x < FreeImage_GetWidth(image); x++) { + bits[x] = 128; + } + } + break; + case FIT_INT16: + for(y = 0; y < FreeImage_GetHeight(image); y++) { + short *bits = (short *)FreeImage_GetScanLine(image, y); + for(x = 0; x < FreeImage_GetWidth(image); x++) { + bits[x] = 128; + } + } + break; + case FIT_UINT32: + for(y = 0; y < FreeImage_GetHeight(image); y++) { + DWORD *bits = (DWORD *)FreeImage_GetScanLine(image, y); + for(x = 0; x < FreeImage_GetWidth(image); x++) { + bits[x] = 128; + } + } + break; + case FIT_INT32: + for(y = 0; y < FreeImage_GetHeight(image); y++) { + LONG *bits = (LONG *)FreeImage_GetScanLine(image, y); + for(x = 0; x < FreeImage_GetWidth(image); x++) { + bits[x] = 128; + } + } + break; + case FIT_FLOAT: + for(y = 0; y < FreeImage_GetHeight(image); y++) { + float *bits = (float *)FreeImage_GetScanLine(image, y); + for(x = 0; x < FreeImage_GetWidth(image); x++) { + bits[x] = 128; + } + } + break; + case FIT_DOUBLE: + for(y = 0; y < FreeImage_GetHeight(image); y++) { + double *bits = (double *)FreeImage_GetScanLine(image, y); + for(x = 0; x < FreeImage_GetWidth(image); x++) { + bits[x] = 128; + } + } + break; + case FIT_COMPLEX: + for(y = 0; y < FreeImage_GetHeight(image); y++) { + FICOMPLEX *bits = (FICOMPLEX *)FreeImage_GetScanLine(image, y); + for(x = 0; x < FreeImage_GetWidth(image); x++) { + bits[x].r = 128; + bits[x].i = 128; + } + } + break; + case FIT_RGB16: + for(y = 0; y < FreeImage_GetHeight(image); y++) { + FIRGB16 *bits = (FIRGB16 *)FreeImage_GetScanLine(image, y); + for(x = 0; x < FreeImage_GetWidth(image); x++) { + bits[x].red = 128; + bits[x].green = 128; + bits[x].blue = 128; + } + } + break; + case FIT_RGBF: + for(y = 0; y < FreeImage_GetHeight(image); y++) { + FIRGBF *bits = (FIRGBF *)FreeImage_GetScanLine(image, y); + for(x = 0; x < FreeImage_GetWidth(image); x++) { + bits[x].red = 128; + bits[x].green = 128; + bits[x].blue = 128; + } + } + break; + case FIT_RGBA16: + for(y = 0; y < FreeImage_GetHeight(image); y++) { + FIRGBA16 *bits = (FIRGBA16 *)FreeImage_GetScanLine(image, y); + for(x = 0; x < FreeImage_GetWidth(image); x++) { + bits[x].red = 128; + bits[x].green = 128; + bits[x].blue = 128; + bits[x].alpha = 128; + } + } + break; + case FIT_RGBAF: + for(y = 0; y < FreeImage_GetHeight(image); y++) { + FIRGBAF *bits = (FIRGBAF *)FreeImage_GetScanLine(image, y); + for(x = 0; x < FreeImage_GetWidth(image); x++) { + bits[x].red = 128; + bits[x].green = 128; + bits[x].blue = 128; + bits[x].alpha = 128; + } + } + break; + } + + + // test clone function + clone = FreeImage_Clone(image); + if(!clone) throw(1); + + if(FreeImage_GetImageType(clone) != image_type) throw(1); + + switch(image_type) { + case FIT_BITMAP: + if(FreeImage_GetBPP(clone) == 8) { + for(y = 0; y < FreeImage_GetHeight(clone); y++) { + BYTE *bits = (BYTE *)FreeImage_GetScanLine(clone, y); + for(x = 0; x < FreeImage_GetWidth(clone); x++) { + if(bits[x] != 128) + throw(1); + } + } + } + break; + case FIT_UINT16: + for(y = 0; y < FreeImage_GetHeight(clone); y++) { + unsigned short *bits = (unsigned short *)FreeImage_GetScanLine(clone, y); + for(x = 0; x < FreeImage_GetWidth(clone); x++) { + if(bits[x] != 128) + throw(1); + } + } + break; + case FIT_INT16: + for(y = 0; y < FreeImage_GetHeight(clone); y++) { + short *bits = (short *)FreeImage_GetScanLine(clone, y); + for(x = 0; x < FreeImage_GetWidth(clone); x++) { + if(bits[x] != 128) + throw(1); + } + } + break; + case FIT_UINT32: + for(y = 0; y < FreeImage_GetHeight(clone); y++) { + DWORD *bits = (DWORD *)FreeImage_GetScanLine(clone, y); + for(x = 0; x < FreeImage_GetWidth(clone); x++) { + if(bits[x] != 128) + throw(1); + } + } + break; + case FIT_INT32: + for(y = 0; y < FreeImage_GetHeight(clone); y++) { + LONG *bits = (LONG *)FreeImage_GetScanLine(clone, y); + for(x = 0; x < FreeImage_GetWidth(clone); x++) { + if(bits[x] != 128) + throw(1); + } + } + break; + case FIT_FLOAT: + for(y = 0; y < FreeImage_GetHeight(clone); y++) { + float *bits = (float *)FreeImage_GetScanLine(clone, y); + for(x = 0; x < FreeImage_GetWidth(clone); x++) { + if(bits[x] != 128) + throw(1); + } + } + break; + case FIT_DOUBLE: + for(y = 0; y < FreeImage_GetHeight(clone); y++) { + double *bits = (double *)FreeImage_GetScanLine(clone, y); + for(x = 0; x < FreeImage_GetWidth(clone); x++) { + if(bits[x] != 128) + throw(1); + } + } + break; + case FIT_COMPLEX: + for(y = 0; y < FreeImage_GetHeight(clone); y++) { + FICOMPLEX *bits = (FICOMPLEX *)FreeImage_GetScanLine(clone, y); + for(x = 0; x < FreeImage_GetWidth(clone); x++) { + if((bits[x].r != 128) || ((bits[x].r - bits[x].i) != 0)) + throw(1); + } + } + break; + case FIT_RGB16: + for(y = 0; y < FreeImage_GetHeight(clone); y++) { + FIRGB16 *bits = (FIRGB16 *)FreeImage_GetScanLine(clone, y); + for(x = 0; x < FreeImage_GetWidth(clone); x++) { + if((bits[x].red != 128) || (bits[x].green != 128) || (bits[x].blue != 128)) + throw(1); + } + } + break; + case FIT_RGBF: + for(y = 0; y < FreeImage_GetHeight(clone); y++) { + FIRGBF *bits = (FIRGBF *)FreeImage_GetScanLine(clone, y); + for(x = 0; x < FreeImage_GetWidth(clone); x++) { + if((bits[x].red != 128) || (bits[x].green != 128) || (bits[x].blue != 128)) + throw(1); + } + } + break; + case FIT_RGBA16: + for(y = 0; y < FreeImage_GetHeight(clone); y++) { + FIRGBA16 *bits = (FIRGBA16 *)FreeImage_GetScanLine(clone, y); + for(x = 0; x < FreeImage_GetWidth(clone); x++) { + if((bits[x].red != 128) || (bits[x].green != 128) || (bits[x].blue != 128) || (bits[x].alpha != 128)) + throw(1); + } + } + break; + case FIT_RGBAF: + for(y = 0; y < FreeImage_GetHeight(clone); y++) { + FIRGBAF *bits = (FIRGBAF *)FreeImage_GetScanLine(clone, y); + for(x = 0; x < FreeImage_GetWidth(clone); x++) { + if((bits[x].red != 128) || (bits[x].green != 128) || (bits[x].blue != 128) || (bits[x].alpha != 128)) + throw(1); + } + } + break; + + } + + // test unload function + FreeImage_Unload(clone); + clone = NULL; + FreeImage_Unload(image); + image = NULL; + + } catch(int) { + if(image) FreeImage_Unload(image); + if(clone) FreeImage_Unload(clone); + return FALSE; + } + return TRUE; +} + +BOOL testLoadSaveConvertImageType(FIBITMAP *src, FREE_IMAGE_TYPE image_type) { + FIBITMAP *dst = NULL; + FIBITMAP *chk = NULL; + BOOL bResult = TRUE; + + try { + // convert to type image_type + dst = FreeImage_ConvertToType(src, image_type); + if(!dst) throw(1); + + // save image as TIFF + bResult = FreeImage_Save(FIF_TIFF, dst, "TestImageType.tif", TIFF_DEFAULT); + if(!bResult) throw(1); + + // destroy dst + FreeImage_Unload(dst); + dst = NULL; + + // load image + dst = FreeImage_Load(FIF_TIFF, "TestImageType.tif", TIFF_DEFAULT); + if(!dst) throw(1); + + // convert to standard bitmap (linear scaling) + chk = FreeImage_ConvertToType(dst, FIT_BITMAP, TRUE); + if(!chk) throw(1); + FreeImage_Unload(dst); + dst = NULL; + + // save image as TIFF + bResult = FreeImage_Save(FIF_TIFF, chk, "TestImageType.tif", TIFF_DEFAULT); + if(!bResult) throw(1); + FreeImage_Unload(chk); + chk = NULL; + + + } catch(int) { + if(dst) FreeImage_Unload(dst); + if(chk) FreeImage_Unload(chk); + return FALSE; + } + + return TRUE; +} + +BOOL testLoadSaveConvertComplexType(FIBITMAP *src, FREE_IMAGE_COLOR_CHANNEL channel) { + FIBITMAP *dst = NULL; + FIBITMAP *chk_double = NULL; + FIBITMAP *chk = NULL; + BOOL bResult = TRUE; + + try { + // convert to type FICOMPLEX + dst = FreeImage_ConvertToType(src, FIT_COMPLEX); + if(!dst) throw(1); + + // save image as TIFF + bResult = FreeImage_Save(FIF_TIFF, dst, "TestImageType.tif", TIFF_DEFAULT); + if(!bResult) throw(1); + + // destroy dst + FreeImage_Unload(dst); + dst = NULL; + + // load image + dst = FreeImage_Load(FIF_TIFF, "TestImageType.tif", TIFF_DEFAULT); + if(!dst) throw(1); + + + // convert to type FIT_DOUBLE + chk_double = FreeImage_GetComplexChannel(dst, channel); + if(!chk_double) throw(1); + FreeImage_Unload(dst); + dst = NULL; + + // convert to standard bitmap (linear scaling) + chk = FreeImage_ConvertToType(chk_double, FIT_BITMAP, TRUE); + if(!chk) throw(1); + FreeImage_Unload(chk_double); + chk_double = NULL; + + // save image as TIFF + bResult = FreeImage_Save(FIF_TIFF, chk, "TestImageType.tif", TIFF_DEFAULT); + if(!bResult) throw(1); + FreeImage_Unload(chk); + chk = NULL; + + + } catch(int) { + if(dst) FreeImage_Unload(dst); + if(chk_double) FreeImage_Unload(chk_double); + if(chk) FreeImage_Unload(chk); + return FALSE; + } + + return TRUE; +} + +// Main test functions +// ---------------------------------------------------------- + +void testImageType(unsigned width, unsigned height) { + BOOL bResult = FALSE; + + printf("testImageType ...\n"); + + bResult = testAllocateCloneUnloadType(FIT_BITMAP, width, height); + assert(bResult); + bResult = testAllocateCloneUnloadType(FIT_UINT16, width, height); + assert(bResult); + bResult = testAllocateCloneUnloadType(FIT_INT16, width, height); + assert(bResult); + bResult = testAllocateCloneUnloadType(FIT_UINT32, width, height); + assert(bResult); + bResult = testAllocateCloneUnloadType(FIT_INT32, width, height); + assert(bResult); + bResult = testAllocateCloneUnloadType(FIT_FLOAT, width, height); + assert(bResult); + bResult = testAllocateCloneUnloadType(FIT_DOUBLE, width, height); + assert(bResult); + bResult = testAllocateCloneUnloadType(FIT_COMPLEX, width, height); + assert(bResult); + bResult = testAllocateCloneUnloadType(FIT_RGB16, width, height); + assert(bResult); + bResult = testAllocateCloneUnloadType(FIT_RGBA16, width, height); + assert(bResult); + bResult = testAllocateCloneUnloadType(FIT_RGBF, width, height); + assert(bResult); + bResult = testAllocateCloneUnloadType(FIT_RGBAF, width, height); + assert(bResult); +} + + +void testImageTypeTIFF(unsigned width, unsigned height) { + BOOL bResult = FALSE; + + printf("testImageTypeTIFF ...\n"); + + // create a test 8-bit image + FIBITMAP *src = createZonePlateImage(width, height, 128); + assert(src != NULL); + + // save for further examination + bResult = FreeImage_Save(FIF_PNG, src, "zoneplate.png", PNG_DEFAULT); + assert(bResult); + + // test load /save / convert + // ------------------------- + + bResult = testLoadSaveConvertImageType(src, FIT_BITMAP); + assert(bResult); + bResult = testLoadSaveConvertImageType(src, FIT_UINT16); + assert(bResult); + bResult = testLoadSaveConvertImageType(src, FIT_INT16); + assert(bResult); + bResult = testLoadSaveConvertImageType(src, FIT_UINT32); + assert(bResult); + bResult = testLoadSaveConvertImageType(src, FIT_INT32); + assert(bResult); + bResult = testLoadSaveConvertImageType(src, FIT_FLOAT); + assert(bResult); + bResult = testLoadSaveConvertImageType(src, FIT_DOUBLE); + assert(bResult); + + // complex type + bResult = testLoadSaveConvertComplexType(src, FICC_REAL); + assert(bResult); + bResult = testLoadSaveConvertComplexType(src, FICC_IMAG); + assert(bResult); + bResult = testLoadSaveConvertComplexType(src, FICC_MAG); + assert(bResult); + bResult = testLoadSaveConvertComplexType(src, FICC_PHASE); + assert(bResult); + + // free test image + FreeImage_Unload(src); + +} diff --git a/TestAPI/testJPEG.cpp b/TestAPI/testJPEG.cpp index b655f41..bb8f426 100644 --- a/TestAPI/testJPEG.cpp +++ b/TestAPI/testJPEG.cpp @@ -1,88 +1,88 @@ -// ========================================================== -// FreeImage 3 Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "TestSuite.h" - -// Local test functions -// ---------------------------------------------------------- - -void testJPEGTransform(const char *src_file) { - BOOL bResult; - BOOL perfect; - - // perfect transformation - perfect = TRUE; - bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_FLIP_H, perfect); - assert(bResult == FALSE); - bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_FLIP_V, perfect); - assert(bResult); - bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_TRANSPOSE, perfect); - assert(bResult); - bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_TRANSVERSE, perfect); - assert(bResult == FALSE); - bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_ROTATE_90, perfect); - assert(bResult); - bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_ROTATE_180, perfect); - assert(bResult == FALSE); - bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_ROTATE_270, perfect); - assert(bResult == FALSE); - - // non perfect transformation - perfect = FALSE; - bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_FLIP_H, perfect); - assert(bResult); - bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_FLIP_V, perfect); - assert(bResult); - bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_TRANSPOSE, perfect); - assert(bResult); - bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_TRANSVERSE, perfect); - assert(bResult); - bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_ROTATE_90, perfect); - assert(bResult); - bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_ROTATE_180, perfect); - assert(bResult); - bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_ROTATE_270, perfect); - assert(bResult); - -} - -void testJPEGCrop(const char *src_file) { - BOOL bResult; - bResult = FreeImage_JPEGCrop(src_file, "test.jpg", 50, 100, 359, 354); - assert(bResult); - bResult = FreeImage_JPEGCrop(src_file, "test.jpg", 50, 100, 650, 500); - assert(bResult == FALSE); -} - -// Main test function -// ---------------------------------------------------------- - -void testJPEG() { - const char *src_file = "exif.jpg"; - - printf("testJPEG (should throw exceptions) ...\n"); - - // lossless transform - both perfect/non perfect - testJPEGTransform(src_file); - // cropping - both perfect/non perfect - testJPEGCrop(src_file); -} +// ========================================================== +// FreeImage 3 Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "TestSuite.h" + +// Local test functions +// ---------------------------------------------------------- + +void testJPEGTransform(const char *src_file) { + BOOL bResult; + BOOL perfect; + + // perfect transformation + perfect = TRUE; + bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_FLIP_H, perfect); + assert(bResult == FALSE); + bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_FLIP_V, perfect); + assert(bResult); + bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_TRANSPOSE, perfect); + assert(bResult); + bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_TRANSVERSE, perfect); + assert(bResult == FALSE); + bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_ROTATE_90, perfect); + assert(bResult); + bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_ROTATE_180, perfect); + assert(bResult == FALSE); + bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_ROTATE_270, perfect); + assert(bResult == FALSE); + + // non perfect transformation + perfect = FALSE; + bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_FLIP_H, perfect); + assert(bResult); + bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_FLIP_V, perfect); + assert(bResult); + bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_TRANSPOSE, perfect); + assert(bResult); + bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_TRANSVERSE, perfect); + assert(bResult); + bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_ROTATE_90, perfect); + assert(bResult); + bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_ROTATE_180, perfect); + assert(bResult); + bResult = FreeImage_JPEGTransform(src_file, "test.jpg", FIJPEG_OP_ROTATE_270, perfect); + assert(bResult); + +} + +void testJPEGCrop(const char *src_file) { + BOOL bResult; + bResult = FreeImage_JPEGCrop(src_file, "test.jpg", 50, 100, 359, 354); + assert(bResult); + bResult = FreeImage_JPEGCrop(src_file, "test.jpg", 50, 100, 650, 500); + assert(bResult == FALSE); +} + +// Main test function +// ---------------------------------------------------------- + +void testJPEG() { + const char *src_file = "exif.jpg"; + + printf("testJPEG (should throw exceptions) ...\n"); + + // lossless transform - both perfect/non perfect + testJPEGTransform(src_file); + // cropping - both perfect/non perfect + testJPEGCrop(src_file); +} diff --git a/TestAPI/testMPage.cpp b/TestAPI/testMPage.cpp index 49bc7f3..a120784 100644 --- a/TestAPI/testMPage.cpp +++ b/TestAPI/testMPage.cpp @@ -1,193 +1,193 @@ -// ========================================================== -// FreeImage 3 Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "TestSuite.h" - -void -testBuildMPage(const char *src_filename, const char *dst_filename, FREE_IMAGE_FORMAT dst_fif, unsigned bpp) { - // get the file type - FREE_IMAGE_FORMAT src_fif = FreeImage_GetFileType(src_filename); - // load the file - FIBITMAP *src = FreeImage_Load(src_fif, src_filename, 0); //24bit image - - FIMULTIBITMAP *out = FreeImage_OpenMultiBitmap(dst_fif, dst_filename, TRUE, FALSE, FALSE); - for(int size = 16; size <= 48; size += 16 ) { - FIBITMAP *rescaled = FreeImage_Rescale(src, size, size, FILTER_CATMULLROM); - - if(FreeImage_GetBPP(rescaled) != bpp) { - // convert to the requested bitdepth - FIBITMAP *tmp = NULL; - switch(bpp) { - case 8: - tmp = FreeImage_ConvertTo8Bits(rescaled); - break; - case 24: - tmp = FreeImage_ConvertTo24Bits(rescaled); - break; - } - assert(tmp != NULL); - FreeImage_Unload(rescaled); - rescaled = tmp; - } - - FreeImage_AppendPage(out, rescaled); - FreeImage_Unload(rescaled); - } - - FreeImage_Unload(src); - - FreeImage_CloseMultiBitmap(out, 0); - -} - -void testMPageCache(const char *src_filename, const char *dst_filename) { - - BOOL keep_cache_in_memory = FALSE; - - // get the file type - FREE_IMAGE_FORMAT src_fif = FreeImage_GetFileType(src_filename); - // load the file - FIBITMAP *src = FreeImage_Load(src_fif, src_filename, 0); //24bit image - assert(src != NULL); - - // convert to 24-bit - if(FreeImage_GetBPP(src) != 24) { - FIBITMAP *tmp = FreeImage_ConvertTo24Bits(src); - assert(tmp != NULL); - FreeImage_Unload(src); - src = tmp; - } - - FIMULTIBITMAP *out = FreeImage_OpenMultiBitmap(FIF_TIFF, dst_filename, TRUE, FALSE, keep_cache_in_memory); - - // attempt to create 16 480X360 images in a 24-bit TIFF multipage file - FIBITMAP *rescaled = FreeImage_Rescale(src, 480, 360, FILTER_CATMULLROM); - for(int i = 0; i < 16; i++) { - FreeImage_AppendPage(out, rescaled); - } - FreeImage_Unload(rescaled); - - FreeImage_Unload(src); - - FreeImage_CloseMultiBitmap(out, 0); -} - -// -------------------------------------------------------------------------- - -BOOL testCloneMultiPage(FREE_IMAGE_FORMAT fif, const char *input, const char *output, int output_flag) { - - BOOL bMemoryCache = TRUE; - - // Open src file (read-only, use memory cache) - FIMULTIBITMAP *src = FreeImage_OpenMultiBitmap(fif, input, FALSE, TRUE, bMemoryCache); - - if(src) { - // Open dst file (creation, use memory cache) - FIMULTIBITMAP *dst = FreeImage_OpenMultiBitmap(fif, output, TRUE, FALSE, bMemoryCache); - - // Get src page count - int count = FreeImage_GetPageCount(src); - - // Clone src to dst - for(int page = 0; page < count; page++) { - // Load the bitmap at position 'page' - FIBITMAP *dib = FreeImage_LockPage(src, page); - if(dib) { - // add a new bitmap to dst - FreeImage_AppendPage(dst, dib); - // Unload the bitmap (do not apply any change to src) - FreeImage_UnlockPage(src, dib, FALSE); - } - } - - // Close src - FreeImage_CloseMultiBitmap(src, 0); - // Save and close dst - FreeImage_CloseMultiBitmap(dst, output_flag); - - return TRUE; - } - - return FALSE; -} - -// -------------------------------------------------------------------------- - -void testLockDeleteMultiPage(const char *input) { - - BOOL bCreateNew = FALSE; - BOOL bReadOnly = FALSE; - BOOL bMemoryCache = TRUE; - - // Open src file (read/write, use memory cache) - FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(input); - FIMULTIBITMAP *src = FreeImage_OpenMultiBitmap(fif, input, bCreateNew, bReadOnly, bMemoryCache); - - if(src) { - // get the page count - int count = FreeImage_GetPageCount(src); - if(count > 2) { - // Load the bitmap at position '2' - FIBITMAP *dib = FreeImage_LockPage(src, 2); - if(dib) { - FreeImage_Invert(dib); - // Unload the bitmap (apply change to src) - FreeImage_UnlockPage(src, dib, TRUE); - } - } - // Close src - FreeImage_CloseMultiBitmap(src, 0); - } - - src = FreeImage_OpenMultiBitmap(fif, input, bCreateNew, bReadOnly, bMemoryCache); - - if(src) { - // get the page count - int count = FreeImage_GetPageCount(src); - if(count > 1) { - // delete page 0 - FreeImage_DeletePage(src, 0); - } - // Close src - FreeImage_CloseMultiBitmap(src, 0); - } -} - -// -------------------------------------------------------------------------- - -void testMultiPage(const char *lpszPathName) { - printf("testMultiPage ...\n"); - - // test multipage creation - testBuildMPage(lpszPathName, "sample.ico", FIF_ICO, 24); - testBuildMPage(lpszPathName, "sample.tif", FIF_TIFF, 24); - testBuildMPage(lpszPathName, "sample.gif", FIF_GIF, 8); - - // test multipage copy - testCloneMultiPage(FIF_TIFF, "sample.tif", "clone.tif", TIFF_LZW); - - // test multipage lock & delete - testLockDeleteMultiPage("clone.tif"); - - // test multipage cache - testMPageCache(lpszPathName, "mpages.tif"); -} +// ========================================================== +// FreeImage 3 Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "TestSuite.h" + +void +testBuildMPage(const char *src_filename, const char *dst_filename, FREE_IMAGE_FORMAT dst_fif, unsigned bpp) { + // get the file type + FREE_IMAGE_FORMAT src_fif = FreeImage_GetFileType(src_filename); + // load the file + FIBITMAP *src = FreeImage_Load(src_fif, src_filename, 0); //24bit image + + FIMULTIBITMAP *out = FreeImage_OpenMultiBitmap(dst_fif, dst_filename, TRUE, FALSE, FALSE); + for(int size = 16; size <= 48; size += 16 ) { + FIBITMAP *rescaled = FreeImage_Rescale(src, size, size, FILTER_CATMULLROM); + + if(FreeImage_GetBPP(rescaled) != bpp) { + // convert to the requested bitdepth + FIBITMAP *tmp = NULL; + switch(bpp) { + case 8: + tmp = FreeImage_ConvertTo8Bits(rescaled); + break; + case 24: + tmp = FreeImage_ConvertTo24Bits(rescaled); + break; + } + assert(tmp != NULL); + FreeImage_Unload(rescaled); + rescaled = tmp; + } + + FreeImage_AppendPage(out, rescaled); + FreeImage_Unload(rescaled); + } + + FreeImage_Unload(src); + + FreeImage_CloseMultiBitmap(out, 0); + +} + +void testMPageCache(const char *src_filename, const char *dst_filename) { + + BOOL keep_cache_in_memory = FALSE; + + // get the file type + FREE_IMAGE_FORMAT src_fif = FreeImage_GetFileType(src_filename); + // load the file + FIBITMAP *src = FreeImage_Load(src_fif, src_filename, 0); //24bit image + assert(src != NULL); + + // convert to 24-bit + if(FreeImage_GetBPP(src) != 24) { + FIBITMAP *tmp = FreeImage_ConvertTo24Bits(src); + assert(tmp != NULL); + FreeImage_Unload(src); + src = tmp; + } + + FIMULTIBITMAP *out = FreeImage_OpenMultiBitmap(FIF_TIFF, dst_filename, TRUE, FALSE, keep_cache_in_memory); + + // attempt to create 16 480X360 images in a 24-bit TIFF multipage file + FIBITMAP *rescaled = FreeImage_Rescale(src, 480, 360, FILTER_CATMULLROM); + for(int i = 0; i < 16; i++) { + FreeImage_AppendPage(out, rescaled); + } + FreeImage_Unload(rescaled); + + FreeImage_Unload(src); + + FreeImage_CloseMultiBitmap(out, 0); +} + +// -------------------------------------------------------------------------- + +BOOL testCloneMultiPage(FREE_IMAGE_FORMAT fif, const char *input, const char *output, int output_flag) { + + BOOL bMemoryCache = TRUE; + + // Open src file (read-only, use memory cache) + FIMULTIBITMAP *src = FreeImage_OpenMultiBitmap(fif, input, FALSE, TRUE, bMemoryCache); + + if(src) { + // Open dst file (creation, use memory cache) + FIMULTIBITMAP *dst = FreeImage_OpenMultiBitmap(fif, output, TRUE, FALSE, bMemoryCache); + + // Get src page count + int count = FreeImage_GetPageCount(src); + + // Clone src to dst + for(int page = 0; page < count; page++) { + // Load the bitmap at position 'page' + FIBITMAP *dib = FreeImage_LockPage(src, page); + if(dib) { + // add a new bitmap to dst + FreeImage_AppendPage(dst, dib); + // Unload the bitmap (do not apply any change to src) + FreeImage_UnlockPage(src, dib, FALSE); + } + } + + // Close src + FreeImage_CloseMultiBitmap(src, 0); + // Save and close dst + FreeImage_CloseMultiBitmap(dst, output_flag); + + return TRUE; + } + + return FALSE; +} + +// -------------------------------------------------------------------------- + +void testLockDeleteMultiPage(const char *input) { + + BOOL bCreateNew = FALSE; + BOOL bReadOnly = FALSE; + BOOL bMemoryCache = TRUE; + + // Open src file (read/write, use memory cache) + FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(input); + FIMULTIBITMAP *src = FreeImage_OpenMultiBitmap(fif, input, bCreateNew, bReadOnly, bMemoryCache); + + if(src) { + // get the page count + int count = FreeImage_GetPageCount(src); + if(count > 2) { + // Load the bitmap at position '2' + FIBITMAP *dib = FreeImage_LockPage(src, 2); + if(dib) { + FreeImage_Invert(dib); + // Unload the bitmap (apply change to src) + FreeImage_UnlockPage(src, dib, TRUE); + } + } + // Close src + FreeImage_CloseMultiBitmap(src, 0); + } + + src = FreeImage_OpenMultiBitmap(fif, input, bCreateNew, bReadOnly, bMemoryCache); + + if(src) { + // get the page count + int count = FreeImage_GetPageCount(src); + if(count > 1) { + // delete page 0 + FreeImage_DeletePage(src, 0); + } + // Close src + FreeImage_CloseMultiBitmap(src, 0); + } +} + +// -------------------------------------------------------------------------- + +void testMultiPage(const char *lpszPathName) { + printf("testMultiPage ...\n"); + + // test multipage creation + testBuildMPage(lpszPathName, "sample.ico", FIF_ICO, 24); + testBuildMPage(lpszPathName, "sample.tif", FIF_TIFF, 24); + testBuildMPage(lpszPathName, "sample.gif", FIF_GIF, 8); + + // test multipage copy + testCloneMultiPage(FIF_TIFF, "sample.tif", "clone.tif", TIFF_LZW); + + // test multipage lock & delete + testLockDeleteMultiPage("clone.tif"); + + // test multipage cache + testMPageCache(lpszPathName, "mpages.tif"); +} diff --git a/TestAPI/testMPageMemory.cpp b/TestAPI/testMPageMemory.cpp index 122ac25..a4576ae 100644 --- a/TestAPI/testMPageMemory.cpp +++ b/TestAPI/testMPageMemory.cpp @@ -1,271 +1,271 @@ -// ========================================================== -// FreeImage 3 Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "TestSuite.h" - -// -------------------------------------------------------------------------- - -static BOOL -extractPagesFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream) { - char filename[256]; - // open the multipage bitmap stream as read-only - FIMULTIBITMAP *src = FreeImage_LoadMultiBitmapFromMemory(fif, stream, 0); - if(src) { - // get the page count - int count = FreeImage_GetPageCount(src); - // extract all pages - for(int page = 0; page < count; page++) { - // load the bitmap at position 'page' - FIBITMAP *dib = FreeImage_LockPage(src, page); - if(dib) { - // save the page - sprintf(filename, "page%d.%s", page, FreeImage_GetFormatFromFIF(fif)); - FreeImage_Save(fif, dib, filename, 0); - // Unload the bitmap (do not apply any change to src) - FreeImage_UnlockPage(src, dib, FALSE); - } else { - // an error occured: free the multipage bitmap handle and return - FreeImage_CloseMultiBitmap(src, 0); - return FALSE; - } - } - } - // make sure to close the multipage bitmap handle on exit - return FreeImage_CloseMultiBitmap(src, 0); -} - -void testLoadMultiBitmapFromMemory(const char *lpszPathName) { - struct stat buf; - int result; - - // get data associated with lpszPathName - result = stat(lpszPathName, &buf); - if(result == 0) { - // allocate a memory buffer and load temporary data - BYTE *mem_buffer = (BYTE*)malloc(buf.st_size * sizeof(BYTE)); - if(mem_buffer) { - FILE *stream = fopen(lpszPathName, "rb"); - if(stream) { - fread(mem_buffer, sizeof(BYTE), buf.st_size, stream); - fclose(stream); - - // attach the binary data to a memory stream - FIMEMORY *hmem = FreeImage_OpenMemory(mem_buffer, buf.st_size); - - // get the file type - FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(hmem, 0); - - // extract pages - BOOL bSuccess = extractPagesFromMemory(fif, hmem); - assert(bSuccess); - - // close the stream - FreeImage_CloseMemory(hmem); - - } - } - // user is responsible for freeing the data - free(mem_buffer); - } -} - -// -------------------------------------------------------------------------- - -BOOL testSaveMultiBitmapToMemory(const char *input, const char *output, int output_flag) { - BOOL bSuccess; - - BOOL bCreateNew = FALSE; - BOOL bReadOnly = TRUE; - BOOL bMemoryCache = TRUE; - - // Open src file (read-only, use memory cache) - FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(input); - FIMULTIBITMAP *src = FreeImage_OpenMultiBitmap(fif, input, bCreateNew, bReadOnly, bMemoryCache); - - if(src) { - // open and allocate a memory stream - FIMEMORY *dst_memory = FreeImage_OpenMemory(); - - // save the file to memory - bSuccess = FreeImage_SaveMultiBitmapToMemory(fif, src, dst_memory, output_flag); - assert(bSuccess); - - // src is no longer needed: close and free src file - FreeImage_CloseMultiBitmap(src, 0); - - // get the buffer from the memory stream - BYTE *mem_buffer = NULL; - DWORD size_in_bytes = 0; - - bSuccess = FreeImage_AcquireMemory(dst_memory, &mem_buffer, &size_in_bytes); - assert(bSuccess); - - // save the buffer in a file stream - FILE *stream = fopen(output, "wb"); - if(stream) { - fwrite(mem_buffer, sizeof(BYTE), size_in_bytes, stream); - fclose(stream); - } - - // close and free the memory stream - FreeImage_CloseMemory(dst_memory); - - return TRUE; - } - - return FALSE; -} - -// -------------------------------------------------------------------------- - -static BOOL -loadBuffer(const char *lpszPathName, BYTE **buffer, DWORD *length) { - struct stat file_info; - int result; - - // get data associated with lpszPathName - result = stat(lpszPathName, &file_info); - if(result == 0) { - // allocate a memory buffer and load temporary data - *buffer = (BYTE*)malloc(file_info.st_size * sizeof(BYTE)); - if(*buffer) { - FILE *stream = fopen(lpszPathName, "rb"); - if(stream) { - *length = (DWORD)fread(*buffer, sizeof(BYTE), file_info.st_size, stream); - fclose(stream); - - return TRUE; - } - } - } - - return FALSE; -} - -BOOL testMemoryStreamMultiPageOpenSave(const char *lpszPathName, char *output, int input_flag, int output_flag) { - BOOL bSuccess = FALSE; - - BYTE *buffer = NULL; - DWORD buffer_size = 0; - - // load source stream as a buffer, i.e. - // allocate a memory buffer and load temporary data - bSuccess = loadBuffer(lpszPathName, &buffer, &buffer_size); - assert(bSuccess); - - // attach the binary data to a memory stream - FIMEMORY *src_stream = FreeImage_OpenMemory(buffer, buffer_size); - assert(src_stream); - - // open the multipage bitmap stream - FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(src_stream, 0); - FIMULTIBITMAP *src = FreeImage_LoadMultiBitmapFromMemory(fif, src_stream, input_flag); - - // apply some modifications (everything being stored to the cache) ... - - if(src) { - // get the page count - int count = FreeImage_GetPageCount(src); - assert(count > 2); - - // Load the bitmap at position '2' - FIBITMAP *dib = FreeImage_LockPage(src, 2); - if(dib) { - FreeImage_Invert(dib); - // Unload the bitmap (apply change to src, modifications are stored to the cache) - FreeImage_UnlockPage(src, dib, TRUE); - } - - // delete page 0 (modifications are stored to the cache) - FreeImage_DeletePage(src, 0); - - // insert a new page at position '0' (modifications are stored to the cache) - FIBITMAP *page = createZonePlateImage(512, 512, 128); - FreeImage_InsertPage(src, 0, page); - FreeImage_Unload(page); - } - - // save the modification into the output stream ... - - if(src) { - // open and allocate a memory stream - FIMEMORY *dst_stream = FreeImage_OpenMemory(); - assert(dst_stream); - - // save the file to memory - FreeImage_SaveMultiBitmapToMemory(fif, src, dst_stream, output_flag); - - // src is no longer needed - // close and free the memory stream - FreeImage_CloseMemory(src_stream); - // close and free src file (nothing is done, the cache is cleared) - FreeImage_CloseMultiBitmap(src, 0); - - // at this point, the input buffer is no longer needed - // !!! user is responsible for freeing the initial source buffer !!! - free(buffer); buffer = NULL; - - // get the dst buffer from the memory stream - BYTE *dst_buffer = NULL; - DWORD size_in_bytes = 0; - - FreeImage_AcquireMemory(dst_stream, &dst_buffer, &size_in_bytes); - - // save the buffer in a file stream - FILE *stream = fopen(output, "wb"); - if(stream) { - fwrite(dst_buffer, sizeof(BYTE), size_in_bytes, stream); - fclose(stream); - } - - // close and free the memory stream - FreeImage_CloseMemory(dst_stream); - - return TRUE; - } - - if(buffer) { - free(buffer); - } - - return FALSE; -} - -// -------------------------------------------------------------------------- - -void testMultiPageMemory(const char *lpszPathName) { - BOOL bSuccess; - - printf("testMultiPageMemory ...\n"); - - // test FreeImage_LoadMultiBitmapFromMemory - testLoadMultiBitmapFromMemory(lpszPathName); - - // test FreeImage_SaveMultiBitmapToMemory - bSuccess = testSaveMultiBitmapToMemory("sample.tif", "mpage-mstream.tif", 0); - assert(bSuccess); - - // test FreeImage_LoadMultiBitmapFromMemory & FreeImage_SaveMultiBitmapToMemory - bSuccess = testMemoryStreamMultiPageOpenSave("sample.tif", "mpage-mstream-redirect.tif", 0, 0); - assert(bSuccess); - -} +// ========================================================== +// FreeImage 3 Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "TestSuite.h" + +// -------------------------------------------------------------------------- + +static BOOL +extractPagesFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream) { + char filename[256]; + // open the multipage bitmap stream as read-only + FIMULTIBITMAP *src = FreeImage_LoadMultiBitmapFromMemory(fif, stream, 0); + if(src) { + // get the page count + int count = FreeImage_GetPageCount(src); + // extract all pages + for(int page = 0; page < count; page++) { + // load the bitmap at position 'page' + FIBITMAP *dib = FreeImage_LockPage(src, page); + if(dib) { + // save the page + sprintf(filename, "page%d.%s", page, FreeImage_GetFormatFromFIF(fif)); + FreeImage_Save(fif, dib, filename, 0); + // Unload the bitmap (do not apply any change to src) + FreeImage_UnlockPage(src, dib, FALSE); + } else { + // an error occured: free the multipage bitmap handle and return + FreeImage_CloseMultiBitmap(src, 0); + return FALSE; + } + } + } + // make sure to close the multipage bitmap handle on exit + return FreeImage_CloseMultiBitmap(src, 0); +} + +void testLoadMultiBitmapFromMemory(const char *lpszPathName) { + struct stat buf; + int result; + + // get data associated with lpszPathName + result = stat(lpszPathName, &buf); + if(result == 0) { + // allocate a memory buffer and load temporary data + BYTE *mem_buffer = (BYTE*)malloc(buf.st_size * sizeof(BYTE)); + if(mem_buffer) { + FILE *stream = fopen(lpszPathName, "rb"); + if(stream) { + fread(mem_buffer, sizeof(BYTE), buf.st_size, stream); + fclose(stream); + + // attach the binary data to a memory stream + FIMEMORY *hmem = FreeImage_OpenMemory(mem_buffer, buf.st_size); + + // get the file type + FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(hmem, 0); + + // extract pages + BOOL bSuccess = extractPagesFromMemory(fif, hmem); + assert(bSuccess); + + // close the stream + FreeImage_CloseMemory(hmem); + + } + } + // user is responsible for freeing the data + free(mem_buffer); + } +} + +// -------------------------------------------------------------------------- + +BOOL testSaveMultiBitmapToMemory(const char *input, const char *output, int output_flag) { + BOOL bSuccess; + + BOOL bCreateNew = FALSE; + BOOL bReadOnly = TRUE; + BOOL bMemoryCache = TRUE; + + // Open src file (read-only, use memory cache) + FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(input); + FIMULTIBITMAP *src = FreeImage_OpenMultiBitmap(fif, input, bCreateNew, bReadOnly, bMemoryCache); + + if(src) { + // open and allocate a memory stream + FIMEMORY *dst_memory = FreeImage_OpenMemory(); + + // save the file to memory + bSuccess = FreeImage_SaveMultiBitmapToMemory(fif, src, dst_memory, output_flag); + assert(bSuccess); + + // src is no longer needed: close and free src file + FreeImage_CloseMultiBitmap(src, 0); + + // get the buffer from the memory stream + BYTE *mem_buffer = NULL; + DWORD size_in_bytes = 0; + + bSuccess = FreeImage_AcquireMemory(dst_memory, &mem_buffer, &size_in_bytes); + assert(bSuccess); + + // save the buffer in a file stream + FILE *stream = fopen(output, "wb"); + if(stream) { + fwrite(mem_buffer, sizeof(BYTE), size_in_bytes, stream); + fclose(stream); + } + + // close and free the memory stream + FreeImage_CloseMemory(dst_memory); + + return TRUE; + } + + return FALSE; +} + +// -------------------------------------------------------------------------- + +static BOOL +loadBuffer(const char *lpszPathName, BYTE **buffer, DWORD *length) { + struct stat file_info; + int result; + + // get data associated with lpszPathName + result = stat(lpszPathName, &file_info); + if(result == 0) { + // allocate a memory buffer and load temporary data + *buffer = (BYTE*)malloc(file_info.st_size * sizeof(BYTE)); + if(*buffer) { + FILE *stream = fopen(lpszPathName, "rb"); + if(stream) { + *length = (DWORD)fread(*buffer, sizeof(BYTE), file_info.st_size, stream); + fclose(stream); + + return TRUE; + } + } + } + + return FALSE; +} + +BOOL testMemoryStreamMultiPageOpenSave(const char *lpszPathName, char *output, int input_flag, int output_flag) { + BOOL bSuccess = FALSE; + + BYTE *buffer = NULL; + DWORD buffer_size = 0; + + // load source stream as a buffer, i.e. + // allocate a memory buffer and load temporary data + bSuccess = loadBuffer(lpszPathName, &buffer, &buffer_size); + assert(bSuccess); + + // attach the binary data to a memory stream + FIMEMORY *src_stream = FreeImage_OpenMemory(buffer, buffer_size); + assert(src_stream); + + // open the multipage bitmap stream + FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(src_stream, 0); + FIMULTIBITMAP *src = FreeImage_LoadMultiBitmapFromMemory(fif, src_stream, input_flag); + + // apply some modifications (everything being stored to the cache) ... + + if(src) { + // get the page count + int count = FreeImage_GetPageCount(src); + assert(count > 2); + + // Load the bitmap at position '2' + FIBITMAP *dib = FreeImage_LockPage(src, 2); + if(dib) { + FreeImage_Invert(dib); + // Unload the bitmap (apply change to src, modifications are stored to the cache) + FreeImage_UnlockPage(src, dib, TRUE); + } + + // delete page 0 (modifications are stored to the cache) + FreeImage_DeletePage(src, 0); + + // insert a new page at position '0' (modifications are stored to the cache) + FIBITMAP *page = createZonePlateImage(512, 512, 128); + FreeImage_InsertPage(src, 0, page); + FreeImage_Unload(page); + } + + // save the modification into the output stream ... + + if(src) { + // open and allocate a memory stream + FIMEMORY *dst_stream = FreeImage_OpenMemory(); + assert(dst_stream); + + // save the file to memory + FreeImage_SaveMultiBitmapToMemory(fif, src, dst_stream, output_flag); + + // src is no longer needed + // close and free the memory stream + FreeImage_CloseMemory(src_stream); + // close and free src file (nothing is done, the cache is cleared) + FreeImage_CloseMultiBitmap(src, 0); + + // at this point, the input buffer is no longer needed + // !!! user is responsible for freeing the initial source buffer !!! + free(buffer); buffer = NULL; + + // get the dst buffer from the memory stream + BYTE *dst_buffer = NULL; + DWORD size_in_bytes = 0; + + FreeImage_AcquireMemory(dst_stream, &dst_buffer, &size_in_bytes); + + // save the buffer in a file stream + FILE *stream = fopen(output, "wb"); + if(stream) { + fwrite(dst_buffer, sizeof(BYTE), size_in_bytes, stream); + fclose(stream); + } + + // close and free the memory stream + FreeImage_CloseMemory(dst_stream); + + return TRUE; + } + + if(buffer) { + free(buffer); + } + + return FALSE; +} + +// -------------------------------------------------------------------------- + +void testMultiPageMemory(const char *lpszPathName) { + BOOL bSuccess; + + printf("testMultiPageMemory ...\n"); + + // test FreeImage_LoadMultiBitmapFromMemory + testLoadMultiBitmapFromMemory(lpszPathName); + + // test FreeImage_SaveMultiBitmapToMemory + bSuccess = testSaveMultiBitmapToMemory("sample.tif", "mpage-mstream.tif", 0); + assert(bSuccess); + + // test FreeImage_LoadMultiBitmapFromMemory & FreeImage_SaveMultiBitmapToMemory + bSuccess = testMemoryStreamMultiPageOpenSave("sample.tif", "mpage-mstream-redirect.tif", 0, 0); + assert(bSuccess); + +} diff --git a/TestAPI/testMPageStream.cpp b/TestAPI/testMPageStream.cpp index 4be0e7d..ee65779 100644 --- a/TestAPI/testMPageStream.cpp +++ b/TestAPI/testMPageStream.cpp @@ -1,216 +1,216 @@ -// ========================================================== -// FreeImage 3 Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "TestSuite.h" - -// -------------------------------------------------------------------------- - -static unsigned DLL_CALLCONV -myReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { - return (unsigned)fread(buffer, size, count, (FILE *)handle); -} - -static unsigned DLL_CALLCONV -myWriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { - return (unsigned)fwrite(buffer, size, count, (FILE *)handle); -} - -static int DLL_CALLCONV -mySeekProc(fi_handle handle, long offset, int origin) { - return fseek((FILE *)handle, offset, origin); -} - -static long DLL_CALLCONV -myTellProc(fi_handle handle) { - return ftell((FILE *)handle); -} - -BOOL testStreamMultiPageOpen(const char *input, int flags) { - // initialize your own IO functions - - FreeImageIO io; - - io.read_proc = myReadProc; - io.write_proc = myWriteProc; - io.seek_proc = mySeekProc; - io.tell_proc = myTellProc; - - BOOL bSuccess = FALSE; - - // Open src stream in read-only mode - FILE *file = fopen(input, "r+b"); - if (file != NULL) { - // Open the multi-page file - FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromHandle(&io, (fi_handle)file); - FIMULTIBITMAP *src = FreeImage_OpenMultiBitmapFromHandle(fif, &io, (fi_handle)file, flags); - - if(src) { - // get the page count - int count = FreeImage_GetPageCount(src); - assert(count > 1); - - // delete page 0 (modifications are stored to the cache) - FreeImage_DeletePage(src, 0); - - // Close src file (nothing is done, the cache is cleared) - bSuccess = FreeImage_CloseMultiBitmap(src, 0); - assert(bSuccess); - } - - // Close the src stream - fclose(file); - - return bSuccess; - } - - return bSuccess; -} - -BOOL testStreamMultiPageSave(const char *input, const char *output, int input_flag, int output_flag) { - // initialize your own IO functions - - FreeImageIO io; - - io.read_proc = myReadProc; - io.write_proc = myWriteProc; - io.seek_proc = mySeekProc; - io.tell_proc = myTellProc; - - BOOL bCreateNew = FALSE; - BOOL bReadOnly = TRUE; - BOOL bMemoryCache = TRUE; - - // Open src file (read-only, use memory cache) - FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(input); - FIMULTIBITMAP *src = FreeImage_OpenMultiBitmap(fif, input, bCreateNew, bReadOnly, bMemoryCache, input_flag); - - if(src) { - // Open dst stream in read/write mode - FILE *file = fopen(output, "w+b"); - if (file != NULL) { - // Save the multi-page file to the stream - BOOL bSuccess = FreeImage_SaveMultiBitmapToHandle(fif, src, &io, (fi_handle)file, output_flag); - assert(bSuccess); - - // Close the dst stream - fclose(file); - - // Close src file - FreeImage_CloseMultiBitmap(src, 0); - - return TRUE; - } - - // Close src - FreeImage_CloseMultiBitmap(src, 0); - } - - return FALSE; -} - -BOOL testStreamMultiPageOpenSave(const char *input, const char *output, int input_flag, int output_flag) { - // initialize your own IO functions - - FreeImageIO io; - - io.read_proc = myReadProc; - io.write_proc = myWriteProc; - io.seek_proc = mySeekProc; - io.tell_proc = myTellProc; - - BOOL bSuccess = FALSE; - - // Open src stream in read-only mode - FILE *src_file = fopen(input, "r+b"); - assert(src_file); - if (src_file != NULL) { - // Open the multi-page file - FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromHandle(&io, (fi_handle)src_file); - FIMULTIBITMAP *src = FreeImage_OpenMultiBitmapFromHandle(fif, &io, (fi_handle)src_file, input_flag); - - if(src) { - // get the page count - int count = FreeImage_GetPageCount(src); - assert(count > 2); - - // Load the bitmap at position '2' - FIBITMAP *dib = FreeImage_LockPage(src, 2); - if(dib) { - FreeImage_Invert(dib); - // Unload the bitmap (apply change to src, modifications are stored to the cache) - FreeImage_UnlockPage(src, dib, TRUE); - } - - // delete page 0 (modifications are stored to the cache) - FreeImage_DeletePage(src, 0); - - // insert a new page at position '0' (modifications are stored to the cache) - FIBITMAP *page = createZonePlateImage(512, 512, 128); - FreeImage_InsertPage(src, 0, page); - FreeImage_Unload(page); - - // Open dst stream in read/write mode - FILE *dst_file = fopen(output, "w+b"); - assert(dst_file); - if (dst_file != NULL) { - // Save the multi-page file to the stream (modifications are applied) - BOOL bSuccess = FreeImage_SaveMultiBitmapToHandle(fif, src, &io, (fi_handle)dst_file, output_flag); - assert(bSuccess); - - // Close the dst stream - fclose(dst_file); - } - - // Close src file (nothing is done, the cache is cleared) - bSuccess = FreeImage_CloseMultiBitmap(src, 0); - assert(bSuccess); - } - - // Close the src stream - fclose(src_file); - - return bSuccess; - } - - return FALSE; -} - -// -------------------------------------------------------------------------- - -void testStreamMultiPage(const char *lpszPathName) { - BOOL bSuccess; - - printf("testStreamMultiPage ...\n"); - - // test multipage stream (opening) - bSuccess = testStreamMultiPageOpen(lpszPathName, 0); - assert(bSuccess); - - // test multipage stream (save as) - bSuccess = testStreamMultiPageSave(lpszPathName, "clone-stream.tif", 0, 0); - assert(bSuccess); - - // test multipage stream (open, modify, save as) - bSuccess = testStreamMultiPageOpenSave(lpszPathName, "redirect-stream.tif", 0, 0); - assert(bSuccess); - -} +// ========================================================== +// FreeImage 3 Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "TestSuite.h" + +// -------------------------------------------------------------------------- + +static unsigned DLL_CALLCONV +myReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { + return (unsigned)fread(buffer, size, count, (FILE *)handle); +} + +static unsigned DLL_CALLCONV +myWriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { + return (unsigned)fwrite(buffer, size, count, (FILE *)handle); +} + +static int DLL_CALLCONV +mySeekProc(fi_handle handle, long offset, int origin) { + return fseek((FILE *)handle, offset, origin); +} + +static long DLL_CALLCONV +myTellProc(fi_handle handle) { + return ftell((FILE *)handle); +} + +BOOL testStreamMultiPageOpen(const char *input, int flags) { + // initialize your own IO functions + + FreeImageIO io; + + io.read_proc = myReadProc; + io.write_proc = myWriteProc; + io.seek_proc = mySeekProc; + io.tell_proc = myTellProc; + + BOOL bSuccess = FALSE; + + // Open src stream in read-only mode + FILE *file = fopen(input, "r+b"); + if (file != NULL) { + // Open the multi-page file + FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromHandle(&io, (fi_handle)file); + FIMULTIBITMAP *src = FreeImage_OpenMultiBitmapFromHandle(fif, &io, (fi_handle)file, flags); + + if(src) { + // get the page count + int count = FreeImage_GetPageCount(src); + assert(count > 1); + + // delete page 0 (modifications are stored to the cache) + FreeImage_DeletePage(src, 0); + + // Close src file (nothing is done, the cache is cleared) + bSuccess = FreeImage_CloseMultiBitmap(src, 0); + assert(bSuccess); + } + + // Close the src stream + fclose(file); + + return bSuccess; + } + + return bSuccess; +} + +BOOL testStreamMultiPageSave(const char *input, const char *output, int input_flag, int output_flag) { + // initialize your own IO functions + + FreeImageIO io; + + io.read_proc = myReadProc; + io.write_proc = myWriteProc; + io.seek_proc = mySeekProc; + io.tell_proc = myTellProc; + + BOOL bCreateNew = FALSE; + BOOL bReadOnly = TRUE; + BOOL bMemoryCache = TRUE; + + // Open src file (read-only, use memory cache) + FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(input); + FIMULTIBITMAP *src = FreeImage_OpenMultiBitmap(fif, input, bCreateNew, bReadOnly, bMemoryCache, input_flag); + + if(src) { + // Open dst stream in read/write mode + FILE *file = fopen(output, "w+b"); + if (file != NULL) { + // Save the multi-page file to the stream + BOOL bSuccess = FreeImage_SaveMultiBitmapToHandle(fif, src, &io, (fi_handle)file, output_flag); + assert(bSuccess); + + // Close the dst stream + fclose(file); + + // Close src file + FreeImage_CloseMultiBitmap(src, 0); + + return TRUE; + } + + // Close src + FreeImage_CloseMultiBitmap(src, 0); + } + + return FALSE; +} + +BOOL testStreamMultiPageOpenSave(const char *input, const char *output, int input_flag, int output_flag) { + // initialize your own IO functions + + FreeImageIO io; + + io.read_proc = myReadProc; + io.write_proc = myWriteProc; + io.seek_proc = mySeekProc; + io.tell_proc = myTellProc; + + BOOL bSuccess = FALSE; + + // Open src stream in read-only mode + FILE *src_file = fopen(input, "r+b"); + assert(src_file); + if (src_file != NULL) { + // Open the multi-page file + FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromHandle(&io, (fi_handle)src_file); + FIMULTIBITMAP *src = FreeImage_OpenMultiBitmapFromHandle(fif, &io, (fi_handle)src_file, input_flag); + + if(src) { + // get the page count + int count = FreeImage_GetPageCount(src); + assert(count > 2); + + // Load the bitmap at position '2' + FIBITMAP *dib = FreeImage_LockPage(src, 2); + if(dib) { + FreeImage_Invert(dib); + // Unload the bitmap (apply change to src, modifications are stored to the cache) + FreeImage_UnlockPage(src, dib, TRUE); + } + + // delete page 0 (modifications are stored to the cache) + FreeImage_DeletePage(src, 0); + + // insert a new page at position '0' (modifications are stored to the cache) + FIBITMAP *page = createZonePlateImage(512, 512, 128); + FreeImage_InsertPage(src, 0, page); + FreeImage_Unload(page); + + // Open dst stream in read/write mode + FILE *dst_file = fopen(output, "w+b"); + assert(dst_file); + if (dst_file != NULL) { + // Save the multi-page file to the stream (modifications are applied) + BOOL bSuccess = FreeImage_SaveMultiBitmapToHandle(fif, src, &io, (fi_handle)dst_file, output_flag); + assert(bSuccess); + + // Close the dst stream + fclose(dst_file); + } + + // Close src file (nothing is done, the cache is cleared) + bSuccess = FreeImage_CloseMultiBitmap(src, 0); + assert(bSuccess); + } + + // Close the src stream + fclose(src_file); + + return bSuccess; + } + + return FALSE; +} + +// -------------------------------------------------------------------------- + +void testStreamMultiPage(const char *lpszPathName) { + BOOL bSuccess; + + printf("testStreamMultiPage ...\n"); + + // test multipage stream (opening) + bSuccess = testStreamMultiPageOpen(lpszPathName, 0); + assert(bSuccess); + + // test multipage stream (save as) + bSuccess = testStreamMultiPageSave(lpszPathName, "clone-stream.tif", 0, 0); + assert(bSuccess); + + // test multipage stream (open, modify, save as) + bSuccess = testStreamMultiPageOpenSave(lpszPathName, "redirect-stream.tif", 0, 0); + assert(bSuccess); + +} diff --git a/TestAPI/testMemIO.cpp b/TestAPI/testMemIO.cpp index 5a16576..6988dfc 100644 --- a/TestAPI/testMemIO.cpp +++ b/TestAPI/testMemIO.cpp @@ -1,147 +1,147 @@ -// ========================================================== -// FreeImage 3 Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "TestSuite.h" - -void testSaveMemIO(const char *lpszPathName) { - FIMEMORY *hmem = NULL; - - // load a regular file - FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(lpszPathName); - FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, 0); - - // open a memory handle - hmem = FreeImage_OpenMemory(); - - // save the file to memory - FreeImage_SaveToMemory(fif, dib, hmem, 0); - - // at this point, hmem contains the entire PNG data in memory. - // the amount of space used by the memory is equal to file_size - long file_size = FreeImage_TellMemory(hmem); - printf("File size : %ld\n", file_size); - - - // its easy load an image from memory as well - - // seek to the start of the memory stream - FreeImage_SeekMemory(hmem, 0L, SEEK_SET); - - // get the file type - FREE_IMAGE_FORMAT mem_fif = FreeImage_GetFileTypeFromMemory(hmem, 0); - - // load an image from the memory handle - FIBITMAP *check = FreeImage_LoadFromMemory(mem_fif, hmem, 0); - - // save as a regular file - FreeImage_Save(FIF_PNG, check, "dump.png", PNG_DEFAULT); - - // make sure to free the data since FreeImage_SaveToMemory - // will cause it to be malloc'd - FreeImage_CloseMemory(hmem); - - FreeImage_Unload(check); - FreeImage_Unload(dib); -} - - //you could also have image data in memory via some other method, and just set - //fmh.data to point to it, and set both fmh.datalen and fmh.filelen to the - //size of that data, then FreeImage_LoadFromMemory could load the image from that memory - -void testLoadMemIO(const char *lpszPathName) { - struct stat buf; - int result; - - // get data associated with lpszPathName - result = stat(lpszPathName, &buf); - if(result == 0) { - // allocate a memory buffer and load temporary data - BYTE *mem_buffer = (BYTE*)malloc(buf.st_size * sizeof(BYTE)); - if(mem_buffer) { - FILE *stream = fopen(lpszPathName, "rb"); - if(stream) { - fread(mem_buffer, sizeof(BYTE), buf.st_size, stream); - fclose(stream); - - // attach the binary data to a memory stream - FIMEMORY *hmem = FreeImage_OpenMemory(mem_buffer, buf.st_size); - - // get the file type - FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(hmem, 0); - - // load an image from the memory stream - FIBITMAP *check = FreeImage_LoadFromMemory(fif, hmem, PNG_DEFAULT); - - // save as a regular file - FreeImage_Save(FIF_PNG, check, "blob.png", PNG_DEFAULT); - FreeImage_Unload(check); - - // close the stream - FreeImage_CloseMemory(hmem); - - } - } - // user is responsible for freeing the data - free(mem_buffer); - } -} - -void testAcquireMemIO(const char *lpszPathName) { - FIMEMORY *hmem = NULL; - - // load a regular file - FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(lpszPathName); - FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, 0); - - // open and allocate a memory stream - hmem = FreeImage_OpenMemory(); - - // save the file to memory - FreeImage_SaveToMemory(FIF_PNG, dib, hmem, PNG_DEFAULT); - - FreeImage_Unload(dib); - - // get the buffer from the memory stream - BYTE *mem_buffer = NULL; - DWORD size_in_bytes = 0; - - FreeImage_AcquireMemory(hmem, &mem_buffer, &size_in_bytes); - - // save the buffer in a file stream - FILE *stream = fopen("buffer.png", "wb"); - if(stream) { - fwrite(mem_buffer, sizeof(BYTE), size_in_bytes, stream); - fclose(stream); - } - - // close and free the memory stream - FreeImage_CloseMemory(hmem); - -} - -void testMemIO(const char *lpszPathName) { - printf("testMemIO ...\n"); - testSaveMemIO(lpszPathName); - testLoadMemIO(lpszPathName); - testAcquireMemIO(lpszPathName); -} - +// ========================================================== +// FreeImage 3 Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "TestSuite.h" + +void testSaveMemIO(const char *lpszPathName) { + FIMEMORY *hmem = NULL; + + // load a regular file + FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(lpszPathName); + FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, 0); + + // open a memory handle + hmem = FreeImage_OpenMemory(); + + // save the file to memory + FreeImage_SaveToMemory(fif, dib, hmem, 0); + + // at this point, hmem contains the entire PNG data in memory. + // the amount of space used by the memory is equal to file_size + long file_size = FreeImage_TellMemory(hmem); + printf("File size : %ld\n", file_size); + + + // its easy load an image from memory as well + + // seek to the start of the memory stream + FreeImage_SeekMemory(hmem, 0L, SEEK_SET); + + // get the file type + FREE_IMAGE_FORMAT mem_fif = FreeImage_GetFileTypeFromMemory(hmem, 0); + + // load an image from the memory handle + FIBITMAP *check = FreeImage_LoadFromMemory(mem_fif, hmem, 0); + + // save as a regular file + FreeImage_Save(FIF_PNG, check, "dump.png", PNG_DEFAULT); + + // make sure to free the data since FreeImage_SaveToMemory + // will cause it to be malloc'd + FreeImage_CloseMemory(hmem); + + FreeImage_Unload(check); + FreeImage_Unload(dib); +} + + //you could also have image data in memory via some other method, and just set + //fmh.data to point to it, and set both fmh.datalen and fmh.filelen to the + //size of that data, then FreeImage_LoadFromMemory could load the image from that memory + +void testLoadMemIO(const char *lpszPathName) { + struct stat buf; + int result; + + // get data associated with lpszPathName + result = stat(lpszPathName, &buf); + if(result == 0) { + // allocate a memory buffer and load temporary data + BYTE *mem_buffer = (BYTE*)malloc(buf.st_size * sizeof(BYTE)); + if(mem_buffer) { + FILE *stream = fopen(lpszPathName, "rb"); + if(stream) { + fread(mem_buffer, sizeof(BYTE), buf.st_size, stream); + fclose(stream); + + // attach the binary data to a memory stream + FIMEMORY *hmem = FreeImage_OpenMemory(mem_buffer, buf.st_size); + + // get the file type + FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(hmem, 0); + + // load an image from the memory stream + FIBITMAP *check = FreeImage_LoadFromMemory(fif, hmem, PNG_DEFAULT); + + // save as a regular file + FreeImage_Save(FIF_PNG, check, "blob.png", PNG_DEFAULT); + FreeImage_Unload(check); + + // close the stream + FreeImage_CloseMemory(hmem); + + } + } + // user is responsible for freeing the data + free(mem_buffer); + } +} + +void testAcquireMemIO(const char *lpszPathName) { + FIMEMORY *hmem = NULL; + + // load a regular file + FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(lpszPathName); + FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, 0); + + // open and allocate a memory stream + hmem = FreeImage_OpenMemory(); + + // save the file to memory + FreeImage_SaveToMemory(FIF_PNG, dib, hmem, PNG_DEFAULT); + + FreeImage_Unload(dib); + + // get the buffer from the memory stream + BYTE *mem_buffer = NULL; + DWORD size_in_bytes = 0; + + FreeImage_AcquireMemory(hmem, &mem_buffer, &size_in_bytes); + + // save the buffer in a file stream + FILE *stream = fopen("buffer.png", "wb"); + if(stream) { + fwrite(mem_buffer, sizeof(BYTE), size_in_bytes, stream); + fclose(stream); + } + + // close and free the memory stream + FreeImage_CloseMemory(hmem); + +} + +void testMemIO(const char *lpszPathName) { + printf("testMemIO ...\n"); + testSaveMemIO(lpszPathName); + testLoadMemIO(lpszPathName); + testAcquireMemIO(lpszPathName); +} + diff --git a/TestAPI/testPlugins.cpp b/TestAPI/testPlugins.cpp index 119f90a..e320963 100644 --- a/TestAPI/testPlugins.cpp +++ b/TestAPI/testPlugins.cpp @@ -1,38 +1,38 @@ -// ========================================================== -// FreeImage 3 Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "TestSuite.h" - -// Show plugins -// ---------------------------------------------------------- -void showPlugins() { - // print version & copyright infos - - printf("FreeImage version: %s\n\n%s\n\n", FreeImage_GetVersion(), FreeImage_GetCopyrightMessage()); - - // print plugins info - - for (int j = FreeImage_GetFIFCount() - 1; j >= 0; --j) - printf("bitmap type %d (%s): %s (%s)\n", j, FreeImage_GetFormatFromFIF((FREE_IMAGE_FORMAT)j), FreeImage_GetFIFDescription((FREE_IMAGE_FORMAT)j), FreeImage_GetFIFExtensionList((FREE_IMAGE_FORMAT)j)); - printf("\n"); -} - +// ========================================================== +// FreeImage 3 Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "TestSuite.h" + +// Show plugins +// ---------------------------------------------------------- +void showPlugins() { + // print version & copyright infos + + printf("FreeImage version: %s\n\n%s\n\n", FreeImage_GetVersion(), FreeImage_GetCopyrightMessage()); + + // print plugins info + + for (int j = FreeImage_GetFIFCount() - 1; j >= 0; --j) + printf("bitmap type %d (%s): %s (%s)\n", j, FreeImage_GetFormatFromFIF((FREE_IMAGE_FORMAT)j), FreeImage_GetFIFDescription((FREE_IMAGE_FORMAT)j), FreeImage_GetFIFExtensionList((FREE_IMAGE_FORMAT)j)); + printf("\n"); +} + diff --git a/TestAPI/testThumbnail.cpp b/TestAPI/testThumbnail.cpp index 61e5c0e..e8e30ec 100644 --- a/TestAPI/testThumbnail.cpp +++ b/TestAPI/testThumbnail.cpp @@ -1,139 +1,139 @@ -// ========================================================== -// FreeImage 3 Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "TestSuite.h" - -/** -Test thumbnail loading -*/ -static BOOL testLoadThumbnail(const char *lpszPathName, int flags) { - FIBITMAP *dib = NULL; - - try { - FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(lpszPathName); - - dib = FreeImage_Load(fif, lpszPathName, flags); - if(!dib) throw(1); - - FIBITMAP *thumbnail = FreeImage_GetThumbnail(dib); - if(!thumbnail) throw(1); - - unsigned t_width = FreeImage_GetWidth(thumbnail); - unsigned t_height = FreeImage_GetHeight(thumbnail); - printf("... %s contains a thumbnail whose size is %dx%d\n", lpszPathName, t_width, t_height); - - FreeImage_Unload(dib); - - return TRUE; - } - catch(int) { - if(dib) FreeImage_Unload(dib); - } - - return FALSE; -} - -/** -Test thumbnail saving -*/ -static BOOL testSaveThumbnail(const char *lpszPathName, int flags) { - BOOL bResult = FALSE; - FIBITMAP *dib = NULL; - FIBITMAP *t_clone = NULL; - const char *lpszImagePathName = "exif_new_thumb.jpg"; - - try { - FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(lpszPathName); - - // load the dib - dib = FreeImage_Load(fif, lpszPathName, flags); - if(!dib) throw(1); - - // get a link to the attached thumbnail - FIBITMAP *thumbnail = FreeImage_GetThumbnail(dib); - if(!thumbnail) throw(1); - - // clone the thumbnail and modify it (e.g. convert to greyscale) - assert(FreeImage_GetBPP(thumbnail) == 24); - t_clone = FreeImage_ConvertTo8Bits(thumbnail); - if(!t_clone) throw(1); - - // replace the thumbnail - FreeImage_SetThumbnail(dib, t_clone); - // no longer needed - FreeImage_Unload(t_clone); - t_clone = NULL; - - // save as a new image - // be sure to delete the Exif segment as it can also contain a thumbnail - // this thumbnail will then be loaded instead of the one we store in the JFXX segment - fif = FIF_TIFF; - FreeImage_SetMetadata(FIMD_EXIF_RAW, dib, NULL, NULL); - bResult = FreeImage_Save(fif, dib, lpszImagePathName, 0); - assert(bResult); - - // no longer needed - FreeImage_Unload(dib); - - // reload the image and check its thumbnail - dib = FreeImage_Load(fif, lpszImagePathName, 0); - if(!dib) throw(1); - - // get a link to the attached thumbnail - FIBITMAP *new_thumbnail = FreeImage_GetThumbnail(dib); - if(!new_thumbnail) throw(1); - - // check that the thumbnail is greyscale - // note that with JPEG, we cannot compare pixels between new_thumbnail and t_clone - // because JPEG compression will modify the pixels - assert(FreeImage_GetBPP(new_thumbnail) == 8); - - FreeImage_Unload(dib); - - return TRUE; - } - catch(int) { - if(dib) FreeImage_Unload(dib); - if(t_clone) FreeImage_Unload(t_clone); - } - - return FALSE; -} - -/** -Thest thumbnail functions -*/ -void testThumbnail(const char *lpszPathName, int flags) { - BOOL bResult = FALSE; - - printf("testThumbnail ...\n"); - - // Thumbnail loading - bResult = testLoadThumbnail(lpszPathName, flags); - assert(bResult); - - // Thumbnail saving - bResult = testSaveThumbnail(lpszPathName, flags); - assert(bResult); - -} - +// ========================================================== +// FreeImage 3 Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "TestSuite.h" + +/** +Test thumbnail loading +*/ +static BOOL testLoadThumbnail(const char *lpszPathName, int flags) { + FIBITMAP *dib = NULL; + + try { + FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(lpszPathName); + + dib = FreeImage_Load(fif, lpszPathName, flags); + if(!dib) throw(1); + + FIBITMAP *thumbnail = FreeImage_GetThumbnail(dib); + if(!thumbnail) throw(1); + + unsigned t_width = FreeImage_GetWidth(thumbnail); + unsigned t_height = FreeImage_GetHeight(thumbnail); + printf("... %s contains a thumbnail whose size is %dx%d\n", lpszPathName, t_width, t_height); + + FreeImage_Unload(dib); + + return TRUE; + } + catch(int) { + if(dib) FreeImage_Unload(dib); + } + + return FALSE; +} + +/** +Test thumbnail saving +*/ +static BOOL testSaveThumbnail(const char *lpszPathName, int flags) { + BOOL bResult = FALSE; + FIBITMAP *dib = NULL; + FIBITMAP *t_clone = NULL; + const char *lpszImagePathName = "exif_new_thumb.jpg"; + + try { + FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(lpszPathName); + + // load the dib + dib = FreeImage_Load(fif, lpszPathName, flags); + if(!dib) throw(1); + + // get a link to the attached thumbnail + FIBITMAP *thumbnail = FreeImage_GetThumbnail(dib); + if(!thumbnail) throw(1); + + // clone the thumbnail and modify it (e.g. convert to greyscale) + assert(FreeImage_GetBPP(thumbnail) == 24); + t_clone = FreeImage_ConvertTo8Bits(thumbnail); + if(!t_clone) throw(1); + + // replace the thumbnail + FreeImage_SetThumbnail(dib, t_clone); + // no longer needed + FreeImage_Unload(t_clone); + t_clone = NULL; + + // save as a new image + // be sure to delete the Exif segment as it can also contain a thumbnail + // this thumbnail will then be loaded instead of the one we store in the JFXX segment + fif = FIF_TIFF; + FreeImage_SetMetadata(FIMD_EXIF_RAW, dib, NULL, NULL); + bResult = FreeImage_Save(fif, dib, lpszImagePathName, 0); + assert(bResult); + + // no longer needed + FreeImage_Unload(dib); + + // reload the image and check its thumbnail + dib = FreeImage_Load(fif, lpszImagePathName, 0); + if(!dib) throw(1); + + // get a link to the attached thumbnail + FIBITMAP *new_thumbnail = FreeImage_GetThumbnail(dib); + if(!new_thumbnail) throw(1); + + // check that the thumbnail is greyscale + // note that with JPEG, we cannot compare pixels between new_thumbnail and t_clone + // because JPEG compression will modify the pixels + assert(FreeImage_GetBPP(new_thumbnail) == 8); + + FreeImage_Unload(dib); + + return TRUE; + } + catch(int) { + if(dib) FreeImage_Unload(dib); + if(t_clone) FreeImage_Unload(t_clone); + } + + return FALSE; +} + +/** +Thest thumbnail functions +*/ +void testThumbnail(const char *lpszPathName, int flags) { + BOOL bResult = FALSE; + + printf("testThumbnail ...\n"); + + // Thumbnail loading + bResult = testLoadThumbnail(lpszPathName, flags); + assert(bResult); + + // Thumbnail saving + bResult = testSaveThumbnail(lpszPathName, flags); + assert(bResult); + +} + diff --git a/TestAPI/testTools.cpp b/TestAPI/testTools.cpp index b158de0..aa3b91d 100644 --- a/TestAPI/testTools.cpp +++ b/TestAPI/testTools.cpp @@ -1,82 +1,82 @@ -// ========================================================== -// FreeImage 3 Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "TestSuite.h" - - -// ---------------------------------------------------------- - -/** Create a Zone Plate test pattern. - - The circular zone plate has zero horizontal and vertical frequencies at the center. - Horizontal frequencies increase as you move horizontally, and vertical frequencies increase as you move vertically. - These patterns are useful to: -

      -
    • evaluate image compression -
    • evaluate filter properties -
    • evaluate the quality of resampling algorithms -
    • adjust gamma correction - at the proper gamma setting, the møires should be minimized -
    - Reference: - [1] Ken Turkowski, Open Source Repository. [Online] http://www.worldserver.com/turk/opensource/ -*/ -FIBITMAP* createZonePlateImage(unsigned width, unsigned height, int scale) { - const double PI = 3.1415926535898; - BYTE sinTab[256]; - - FIBITMAP *dst; - int i, j, x, y; - int cX, cY, d; - - // allocate a 8-bit dib - dst = FreeImage_Allocate(width, height, 8); - if(!dst) - return NULL; - - // build a greyscale palette - RGBQUAD *pal = FreeImage_GetPalette(dst); - for(i = 0; i < 256; i++) { - pal[i].rgbRed = (BYTE)i; - pal[i].rgbGreen = (BYTE)i; - pal[i].rgbBlue = (BYTE)i; - } - - // build the sinus table - for(i = 0; i < 256; i++) { - sinTab[i] = (BYTE)(127.5 * sin(PI * (i - 127.5) / 127.5) + 127.5); - } - - cX = width / 2; - cY = height / 2; - - // create a zone plate - for(i = height, y = -cY; i--; y++) { - BYTE *dst_bits = FreeImage_GetScanLine(dst, i); - for (j = width, x = -cX; j--; x++) { - d = ((x * x + y * y) * scale) >> 8; - dst_bits[j] = sinTab[d & 0xFF]; - } - } - - return dst; -} - +// ========================================================== +// FreeImage 3 Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "TestSuite.h" + + +// ---------------------------------------------------------- + +/** Create a Zone Plate test pattern. + + The circular zone plate has zero horizontal and vertical frequencies at the center. + Horizontal frequencies increase as you move horizontally, and vertical frequencies increase as you move vertically. + These patterns are useful to: +
      +
    • evaluate image compression +
    • evaluate filter properties +
    • evaluate the quality of resampling algorithms +
    • adjust gamma correction - at the proper gamma setting, the møires should be minimized +
    + Reference: + [1] Ken Turkowski, Open Source Repository. [Online] http://www.worldserver.com/turk/opensource/ +*/ +FIBITMAP* createZonePlateImage(unsigned width, unsigned height, int scale) { + const double PI = 3.1415926535898; + BYTE sinTab[256]; + + FIBITMAP *dst; + int i, j, x, y; + int cX, cY, d; + + // allocate a 8-bit dib + dst = FreeImage_Allocate(width, height, 8); + if(!dst) + return NULL; + + // build a greyscale palette + RGBQUAD *pal = FreeImage_GetPalette(dst); + for(i = 0; i < 256; i++) { + pal[i].rgbRed = (BYTE)i; + pal[i].rgbGreen = (BYTE)i; + pal[i].rgbBlue = (BYTE)i; + } + + // build the sinus table + for(i = 0; i < 256; i++) { + sinTab[i] = (BYTE)(127.5 * sin(PI * (i - 127.5) / 127.5) + 127.5); + } + + cX = width / 2; + cY = height / 2; + + // create a zone plate + for(i = height, y = -cY; i--; y++) { + BYTE *dst_bits = FreeImage_GetScanLine(dst, i); + for (j = width, x = -cX; j--; x++) { + d = ((x * x + y * y) * scale) >> 8; + dst_bits[j] = sinTab[d & 0xFF]; + } + } + + return dst; +} + diff --git a/Whatsnew.txt b/Whatsnew.txt index dbcbdc1..6185c6e 100644 --- a/Whatsnew.txt +++ b/Whatsnew.txt @@ -1,1172 +1,1172 @@ -What's New for FreeImage - -* : fixed -- : removed -! : changed -+ : added - -October 27th, 2012 - 3.15.4 -! FreeImage now uses LibPNG 1.5.13 -! FreeImage now uses LibRaw 0.14.7 -! FreeImage now uses ZLib 1.2.7 -! FreeImage now uses LibTIFF 4.0.3 -! FreeImage now uses OpenJPEG 1.5.1 -! FreeImage now uses OpenEXR 1.7.1 -+ [Herve Drolon] improved the speed of RAW files detection in FreeImage_GetFileType* functions -+ [Herve Drolon] added JPEG_GREYSCALE load flag to the JPEG plugin (force to load as 8-bit greyscale) -+ [Herve Drolon] added 64-bit RGBA to 24-bit conversion support in FreeImage_ConvertTo24Bits -+ [Carsten Klein] improved the speed of FreeImage_Rescale for FIT_BITMAP & UINT16, RGB[A]16 types -+ [Carsten Klein] improved the speed of FreeImage_ConvertToGreyscale -* [Carsten Klein] updated makefile for building FreeImage with MinGW -* [Herve Drolon] fixed BigTIFF signature validation in FreeImage_GetFileType* functions -* [Carsten Klein] fixed handling of RGB-565 16-bit images (needed for conversion from HBITMAP to FIBITMAP) -* [Herve Drolon] fixed loading of JPEG with invalid IPTC marker -* [Herve Drolon] changed default TIF RowsPerStrips to image height when saving as TIF G3 or TIF G4 (improved compression) -* [Herve Drolon] improved the memory behavior of the RAW plugin (do not allocate huge variables on the stack) -* [Herve Drolon] fixed FreeImage_AllocateT so that it returns NULL with images with a zero width and/or height -* [Herve Drolon] replaced FIUINT64/FIINT64 with standard types UINT64/INT64 -* [Rustam Abdullaev] fixed PNG plugin with saving of transparent monochrome images -* [Floris van den Berg] improved plugin registering when replacing an existing internal plugin with a new equivalent plugin -* [Herve Drolon] fixed a crash when calling FreeImage_GetColorType on a 32-bit RGBA images loaded with the FIF_LOAD_NOPIXELS flag -* [Herve Drolon] fixed FreeImage_SetTransparencyTable falsely setting a dib to 'transparent' when called with a count of 0 -* [Carsten Klein] fixed storing of RGB masks for 16-bit RGB standard images in order to be in a MSDN compatible way -* [Herve Drolon] added an error handling message inside HDR plugin when trying to save an unsupported format -* [Corey Taylor] fixed DDS plugin color channel swapping for RGB color order, when using FREEIMAGE_COLORORDER_RGB color order -* [Herve Drolon] fixed internal TagLib singleton initialization against double-checked locking so that it is multi-thread safe - -March 17th, 2012 - 3.15.3 -! FreeImage now uses LibPNG 1.5.9 -! FreeImage now uses LibTIFF 4.0.1 -+ [Herve Drolon] added new 64-bit data types FIINT64, FIUINT64 -+ [Herve Drolon] added new 64-bit metadata types to FREE_IMAGE_MDTYPE (FIDT_LONG8, FIDT_SLONG8, FIDT_IFD8) -+ [Herve Drolon] added support for 64-bit metadata types to FreeImage_TagToString -* [Herve Drolon] fixed a regression with Fax3/Fax4 TIFF images on 64-bit OS (introduced with FI 3.15.2) -* [Herve Drolon] fixed some gcc 4.4.6 warnings -* [Petr Pytelka] refactored FreeImage_InsertPage and FreeImage_AppendPage -* [Herve Drolon] fixed JP2/J2K plugins with saving of 32-bit dib with a fully opaque layer -* [Herve Drolon] fixed loading of CMYK JPEG when using JPEG_CMYK load flag (need to invert pixels) -* [Herve Drolon] fixed loading of CMYK PSD when using PSD_CMYK load flag - -February 20th, 2012 - 3.15.2 -! FreeImage now uses LibRaw 0.14.5 -! FreeImage now uses LibPNG 1.5.8 -! FreeImage now uses LibJPEG 8d -! FreeImage now uses ZLib 1.2.6 -! FreeImage now uses OpenJPEG 1.5.0 (released version) -! FreeImage now uses LibTIFF 4.0.0 -- [Herve Drolon] removed dependency on LibMNG 1.0.10 (MNG and JNG files are now handled internally) -+ [Herve Drolon] replaced the MNG plugin with a new MNG internal FreeImage plugin (with read support) -+ [Herve Drolon] added a new JNG internal FreeImage plugin (with read/write support) -+ [Christian Heimes] added write support to the TIFF plugin for EXIF_MAIN tags -+ [Herve Drolon] added new Exif maker note tags -+ [Herve Drolon] added TAG_COMPRESSION conversion to FreeImage_TagToString -* [Mylek Grey] enabled the use of multi-component transforms (MCT) in J2K and JP2 saving -* [Herve Drolon] refactored PluginICO in order to correctly support Windows Vista 256x256 icons -* [Herve Drolon] added minor speed improvements to FreeImage_Rescale -* [Herve Drolon] fixed dib allocation failing with very large images (i.e. more than 4GB) -* [Herve Drolon] fixed FreeImage_CloneTag behavior with ASCII data handling -* [Herve Drolon] improved JPEG plugin behavior with very big images -* [Herve Drolon] improved JPEG plugin behavior with C++ exceptions -* [Herve Drolon] fixed loading of palettized PNG with more that 256 palette entries -* [Herve Drolon] fixed a bug inside IFF plugin occuring when loading a 24-bit dib with a palette -* [Herve Drolon] fixed a bug with loading of PNG images containing a cHRM chunk (regression introduced by LibPNG 1.5.4 and fixed by LibPNG 1.5.5) -* [Herve Drolon] allowed loading of PNG with benign errors (such as images with too many IDATs) -* [Mihail Naydenov] fixed some incorrect MIME types returned by FreeImage_GetFIFMimeType -* [Herve Drolon] fixed loading of Exif with bad thumbnail data or with a bad first offset size - -July 25th, 2011 - 3.15.1 -! FreeImage now uses LibRaw 0.13.7 -! FreeImage now uses LibPNG 1.5.4 -! FreeImage now uses LibTIFF 3.9.5 -! FreeImage now uses OpenJPEG 1.5.0 (SVN patch 2011-07-23) -+ [Herve Drolon] added FreeImage_ConvertToRGB16 and updated FreeImage_ConvertToType -+ [Herve Drolon] added RAW_HALFSIZE flag to RAW plugin -* [Herve Drolon] fixed a memory leak in JPEG plugin occuring when loading some corrupted images -* [Eberhard Mattes] improved thread safety behavior inside internal TagLib class -* [Hew How Chee] fixed a bug in FreeImage_EnlargeCanvas when called with negative left and right parameters and bpp <= 4 -* [Herve Drolon] improved memory allocation checking in FreeImage_ConvertTo[Float/RGBF/UINT16] -* [Herve Drolon] allowed loading of TIF with missing bitspersample/samplesperpixel/photometric tags -* [Herve Drolon] fixed FreeImage_AllocateHeaderT against possible malloc overflow -* [Herve Drolon] fixed CUT plugin against heap corruption vulnerability -* [Herve Drolon] fixed BMP plugin for images with a truncated input data stream -* [Herve Drolon] improved PCX format detection in FreeImage_GetFileType* functions -* [Christian Heimes] fixed a TIFF G4 compression bug occuring with gcc-Version 4.1.2 20080704 (Red Hat 4.1.2-50) - -January 24th, 2011 - 3.15.0 -! FreeImage now uses LibRaw 0.13-Beta3 -! FreeImage now uses LibPNG 1.4.5 -! FreeImage now uses LibTIFF 3.9.4 (CVS patch 2011-01-03) -! FreeImage now uses LibJPEG 8c -! FreeImage now uses OpenJPEG 1.4.0 (SVN patch 2011-01-18) -! [Herve Drolon] FreeImage_CloneMetadata now clone resolution info returned by FreeImage_GetDotsPerMeter(X / Y) -+ [Herve Drolon] added loading support for "half float" format to TIF plugin -+ [Herve Drolon] FreeImage_IsTransparent is now independant of FREE_IMAGE_TYPE -+ [Herve Drolon] added FIT_UINT16 to FIT_RGBF conversion to FreeImage_ConvertToRGBF & FreeImage_ConvertToType -+ [Herve Drolon] added FreeImage_ConvertToUINT16 and updated FreeImage_ConvertToType -+ [Mihail Naydenov] added FreeImage_GetThumbnail / FreeImage_SetThumbnail -+ [Mihail Naydenov] added thumbnail support to Exif, JPEG, EXR, PSD, TGA, TIF formats -+ [Mihail Naydenov] added JPEG_BASELINE save flag to the JPEG plugin -+ [Herve Drolon] added new Exif-TIFF tags (PageName, PageNumber, XPosition, YPosition) and Exif WinXP tags -+ [Herve Drolon] added support for 256x256 icon size to PluginICO:Save -* [Domingo Stephan] fixed a compilation error in TARGA plugin when using a big endian OS (OS X 10.6) -* [Christian Heimes] fixed a compilation error with gcc 4.3.x and OpenEXR -* [Eric Fruhinsholz] fixed a crash in JPEG plugin when reading a JPEG with corrupted XMP data -* [Herve Drolon] improved FreeImage_MultigridPoissonSolver for images whose size is a power-of-two -* [Herve Drolon] fixed a crash in PSD plugin when loading a PSD with a CMYK embedded thumbnail -* [Herve Drolon] fixed loading of JPEG images with a not null but zero length IPTC segment (bad files produced by Picasa) -* [Carsten Klein] fixed a bug in FreeImage_ColorQuantizeEx when using FIQ_WUQUANT quantizer -* [Herve Drolon] added support for RGBA[16][F] to FreeImage_IsTransparent -* [Herve Drolon] fixed loading of resolution info in TIFF CMYK images (bug introduced with 3.14.0) -* [Tom May] fixed JPEG plugin crashing on some Exif files containing tags with an invalid tag length -* [Herve Drolon] fixed a crash when loading TIFF images with a TIFFTAG_TRANSFERFUNCTION Exif tag -* [Tom May] removed assertions in PSD plugin, causing crashes on some malformed images in debug mode -* [Mihail Naydenov] fixed a crash in TIFF plugin when reading an uncommon 24-bit palettized file -* [Carsten Klein] fixed a bug in FreeImage_EnlargeCanvas when using the function as a FreeImage_Copy function -* [Herve Drolon] fixed a bug in PluginBMP with loading of OS/2 2.x palettized BMP -* [luispedro] fixed a bug in PluginBMP when reading malformed 16-bit RGB-555 BMP - -August 12th, 2010 - 3.14.1 -+ [Mihail Naydenov] added support for FIF_LOAD_NOPIXELS flag to EXR plugin -+ [Herve Drolon] added support for FIF_LOAD_NOPIXELS flag to CUT, HDR, RAS, ICO, PNM, RAW, BMP, PFM, XPM plugins -* [Eberhard Mattes] fixed memory allocation checking in multipage API -* [Herve Drolon] (compiler options) removed Win32 OpenMP support introduced in 3.14.0 - -August 9th, 2010 - 3.14.0 -! FreeImage now uses OpenEXR 1.7.0 -! FreeImage now uses ZLib 1.2.5 -! FreeImage now uses LibPNG 1.4.3 -! FreeImage now uses LibJPEG 8b -! FreeImage now uses LibTIFF 3.9.4 (CVS patch 2010-07-13) -! FreeImage now uses LibRaw 0.10-Beta3 -! FreeImage now uses OpenJPEG 1.4.0 (SVN patch 2010-04-16) -! [Herve Drolon] FreeImage_AllocateT now builds a default greyscale palette for 8-bit images -! [Volodymyr Goncharov] FreeImage_LoadMultiBitmapFromMemory now supports read/write operations -! [Herve Drolon] FreeImage_OpenMultiBitmapFromHandle now supports read/write operations -! [Herve Drolon] greyscale conversions now use the Rec. 709 formula -! [Mihail Naydenov] saving RGBF images to TIFF no longer use LogLuv encoding (unless you use the TIFF_LOGLUV save flag) -+ [Herve Drolon] added FIT_FLOAT to FIT_RGBF conversion to FreeImage_ConvertToRGBF & FreeImage_ConvertToType -+ [Herve Drolon] added VS 2008 project files -+ [Herve Drolon] added FreeImage_ConvertToFloat -+ [Mihail Naydenov] added RLE saving to the Targa plugin (see flag TARGA_SAVE_RLE) -+ [Volodymyr Goncharov] added FreeImage_SaveMultiBitmapToHandle -+ [Herve Drolon] added FreeImage_SaveMultiBitmapToMemory -+ [Herve Drolon] added new Exif maker note tags -+ [Lucian Sabo] added JPEG_OPTIMIZE to PluginJPEG:Save -+ [Mihail Naydenov] improved support for Exif tag reading in TIFF plugin -+ [Mihail Naydenov] allowed dataWindow with minimal bounds different from zero in OpenEXR plugin -+ [Herve Drolon] added FIMD_EXIF_RAW metadata model -+ [Herve Drolon] JPEG plugin can load & save raw Exif data (see FIMD_EXIF_RAW) -+ [Herve Drolon] added FIF_LOAD_NOPIXELS load flag constant - used to load header & metadata only -+ [Herve Drolon] added FreeImage_HasPixels -+ [Herve Drolon] added FreeImage_FIFSupportsNoPixels -+ [Herve Drolon] added support for FIF_LOAD_NOPIXELS flag to JPEG, PNG, PCD, PCX plugins -+ [Mihail Naydenov] added support for FIF_LOAD_NOPIXELS flag to TGA, PSD, TIFF plugins -+ [Mihail Naydenov] added support for 16-bit image types to FreeImage_Invert -+ [Mihail Naydenov] improved PSD plugin (faster code, added support for CMYK and LAB loading) + added load flags PSD_CMYK & PSD_LAB -+ [Mihail Naydenov] improved TIFF plugin (CMYK 16-bit loading and saving / RGBAF saving) + added TIFF_LOGLUV save flag -* [Herve Drolon] fixed FreeImage_GetFileType behavior with ANI file formats -* [Herve Drolon] fixed loading of JNG with progressive-JPEG formats -* [Mihail Naydenov] fixed loading of TGA with a corrupted rle count -* [Herve Drolon] fixed conversion formula in FreeImage_PreMultiplyWithAlpha -* [Christoph Brill] removed the use of libmng_data.h private API in MNG Plugin -* [phe02sf] fixed handling of bad Exif-GPS data in a Nikon D5000 image -* [Atsuhiro Igarashi] fixed handling of last data block in PluginGIF::Save (sometimes it saves corrupted images) -* [Christian Heimes] fixed saving of G3 & G4 compressed TIFF with 1bpp on 64bit Linux -* [Herve Drolon] fixed long data type being 64-bit on Unix/Linux platforms (use LONG/DWORD instead of long/unsigned long) -* [Herve Drolon] fixed a memory leak in FreeImage_DeletePage -* [Herve Drolon] fixed the loading of RGBZ images in OpenEXR plugin -* [Lucian Sabo] improved conversion from 1-, 4-, 8-bpp transparent images to 32-bpp -* [Roy F.] fixed a bug in FreeImage_EnlargeCanvas (unable to crop an image on the right) -* [Herve Drolon] fixed the loading of Exif with unusual IFD offset value -* [Eberhard Mattes] fixed page numbering info when saving multipage TIFF -* [Herve Drolon] fixed PluginPICT causing an infinite loop on a malformed PICT image -* [Eberhard Mattes] improved memory allocation checking when using the new operator -* [Herve Drolon] (multipage internals) fixed a potential buffer overflow in ReplaceExtension -* [Eberhard Mattes] improved error checking in FreeImage_CloseMultiBitmap - -December 22, 2009 - 3.13.1 -! FreeImage now uses libTIFF 3.9.2 -! FreeImage now uses OpenJPEG 1.3.0 (SVN patch 2009-11-05) -! FreeImage now uses libPNG 1.2.41 -+ [Berend Engelbrecht] added loading of Exif orientation tag in TIFF plugin -+ [Herve Drolon] added decoding support for the old and outdated JPEG-in-TIFF 6.0 format in TIFF plugin -+ [Herve Drolon] added new 'non standard' Exif tags -+ [Herve Drolon] added new Exif makernote tags -* [Herve Drolon] fixed TIF plugin crashing on a malformed TIFF-JPEG compressed image -* [Herve Drolon] fixed MNG plugin crashing on some old mng images -* [Herve Drolon] fixed handling of 2-bit grayscale transparent PNG -* [Herve Drolon] fixed a bug with the compression rate of JP2 and J2K encoders -* [zestony] fixed TIF plugin with the '65535 bytes' pitch size limitation on saving -* [Herve Drolon] fixed handling of PSD files with a non zero file header reserved member -* [Lucian Sabo] PNG plugin now keep transparency when saving 1- or 4-bit transparent images - -September 28th, 2009 - 3.13.0 -! FreeImage now uses LibJPEG 7 -! FreeImage now uses LibRaw-Lite 0.7.2 -! FreeImage now uses libPNG 1.2.40 -! FreeImage now uses libTIFF 3.9.1 -! FreeImage_RotateClassic is deprecated (use FreeImage_Rotate instead) -+ [Herve Drolon] added support for all Photoshop supported color modes to PSD plugin -+ [Herve Drolon] added support for 32-bit to JNG/MNG plugin -+ [Amir Ebrahimi] added loading support for the PICT format -+ [Herve Drolon] added loading support for camera RAW formats (using LibRawLite wrapper for dcraw) -+ [Mihail Naydenov] added UNICODE functions FreeImage_JPEGTransformU and FreeImage_JPEGCropU -+ [Carsten Klein] added FreeImage_OpenMultiBitmapFromHandle -+ [Carsten Klein] added FreeImage_FillBackground -+ [Carsten Klein] added FreeImage_EnlargeCanvas -+ [Carsten Klein] added FreeImage_AllocateEx / FreeImage_AllocateExT -+ [Mihail Naydenov/Herve Drolon] added FreeImage_TmoReinhard05Ex -+ [Herve Drolon] added FIT_RGBA16 to FIT_RGBF conversion to FreeImage_ConvertToRGBF -+ [Herve Drolon] added FreeImage_Rotate (support for most image types, support background color) -* [Christian Heimes] fixed function prototypes to use a void argument when no argument exist -* [Herve Drolon] fixed RGB color ordering on Intel macs -* [Herve Drolon] FreeImage_RotateClassic now keep transparency when applied to 8-bit images -* [Herve Drolon] fixed handling of transparency info in FreeImage_Copy -* [Herve Drolon] fixed a normalization error in FreeImage_GetAdjustColorsLookupTable -* [Herve Drolon] fixed invalid Exif rotation in PluginJPEG for orientation cases 2 and 4 -* [Mihail Naydenov / Carsten Klein] fixed compilation issues with MinGW32 -* [Mihail Naydenov] improved the loading speed of all targa images -* [Herve Drolon] FreeImage_TagToString now handles the Exif UserComment tag - -April 14th, 2009 - 3.12.0 -! FreeImage now uses libPNG 1.2.35 -! FreeImage now uses libTIFF 3.9.0beta (CVS patch 2009-02-12) -! FreeImage now uses OpenJPEG 1.3.0 (SVN patch 2008-08-21) -! [Herve Drolon] FreeImage_CloneMetadata no longer clone the FIMD_ANIMATION metadata (this was causing problems when saving to GIF format) -+ [Herve Drolon] added full support for the PFM format -+ [Herve Drolon] added JPEG_EXIFROTATE load flag to the JPEG plugin -+ [Herve Drolon] added 16-bit RGB(A) and float RGB(A)F support to FreeImage_GetChannel / FreeImage_SetChannel -+ [Herve Drolon] added src FIT_RGBA16 to dst 32-bit FIT_BITMAP conversion to FreeImage_ConvertToType -* [Carsten Klein] FreeImage_Copy now copies transparency info, resolution info, ICC profile and metadata -* [Carsten Klein] check for negative top/left values in FreeImage_Paste -* [Christian Heimes] changed exceptions with a "catch(char *text)" to a "catch(const char *text)" to make GCC 4.1 happy -* [Deif Lou] fixed a bug in FreeImage_SetTransparentIndex -* [Thomas Maiwald] BMP plugin: on saving, fixed correct setting of bfSize BMP file header for palettized images -* [Timothy Lee] fixed handling of frame disposal in GIF_PLAYBACK mode (GIF plugin) -* [Herve Drolon] fixed handling of Exif Olympus Type 2 maker notes (not yet supported but now safely ignored) -* [Rich Geldreich] fixed DXT1 color endpoint precision problem in DDS plugin -* [Mihail Naydenov] improved loading speed of 24-bit targa images -* [Eugene Golushkov] improved big endian / little endian swapping functions -* [Carsten Klein/Jean-Philippe Goerke] improved FreeImage_SetMetadata / FreeImage_GetMetadata accessors -* [Christian Ruppert] improved Linux Makefiles -* [Eugene Golushkov] fixed PluginBMP alignment bug while saving 16 or 24bit BMP on big endian or Apple machines - -July 28th, 2008 - 3.11.0 -! FreeImage now uses libTIFF 3.9.0beta (CVS patch 2008-05-24) -! FreeImage now uses OpenJPEG 1.3.0 (SVN patch 2008-05-22) -! FreeImage now uses libMNG 1.0.10 -! FreeImage now uses libPNG 1.2.29 -+ [Yves Schmid] added 48-bit RGB to 32-bit conversion support in FreeImage_ConvertTo32Bits -+ [Aaron Shumate] added RGB16-to-BITMAP and All-to-RGBF conversion support in FreeImage_ConvertToType -+ [Benjamin English] added a new OpenGL sample to FreeImage/Examples -+ [Lucian Sabo] added new compression flags to the PNG plugin -+ [Lucian Sabo] added new compression flags to the JPEG plugin (chroma subsampling options) -+ [Noam Gat] added support for SGI grayscale + alpha pics to SGI plugin -+ [Herve Drolon] added FreeImage_CloneMetadata -+ [Herve Drolon] added loading support for Windows Vista icons in ICO Plugin -+ [Herve Drolon] added loading and saving support for RGBF images to the TIF plugin (using the LogLuv codec) -* [Will Bryant] fixed makefile for MacOSX Tiger and Leopard -* [Maria Gullickson] fixed a 'divide by 0' error in PNM plugin and FreeImage_Rescale function -* [Yves Schmid] fixed a bug with Exif metadata reading in TIFF images -* [Herve Drolon] fixed some possible 64-bit portability issues with pointer calculations -* [wangyn] fixed a bug with transparency handling of indexed images in PNG plugin -* [Martin Dyring-Andersen] fixed a bug with GIFinfo structure initialization in GIF plugin -* [Noam Gat] fixed a bug in SGI plugin: when the file reports as two-dimensional, the height factor does not get loaded -* [Herve Drolon] added error messages in FreeImage_Load(U) / FreeImage_Save(U) in case of bad filenames -* [Scott Smith/Herve Drolon] added missing IPTC tags and renamed some tag names to be compatible with ExifTool naming convention -* [Martin Dyring-Andersen] fixed a crash problem with images containing exif data emitted by Picassa -* [Herve Drolon] removed RGBA to RGB transparent conversion in EXR plugin -* [Glenn Pierce] improved the speed of FreeImage_FlipHorizontal -* [Carsten Klein] fixed 65535 pixels width/height limitation in FreeImage_Paste - -November 19th, 2007 - 3.10.0 -! FreeImage now uses libTIFF 3.9.0beta (CVS patch 2007-10-05) -! FreeImage now uses OpenJPEG 1.2.0 (SVN patch 2007-07-13) -! FreeImage now uses OpenEXR 1.6.1 -! FreeImage now uses libPNG 1.2.23 -! FreeImage now hides its internal functions and internal libraries when compiled with gcc -- [Herve Drolon] removed VS C+ 6.0 project files : this IDE is no longer supported because of OpenEXR -+ [Herve Drolon] added VS 2005 project files -+ [Herve Drolon] added full support for the OpenEXR format -+ [Herve Drolon] added full support for the JPEG-2000 format -+ [Herve Drolon] added FreeImage_TmoFattal02 tone mapping operator -+ [Ryan Rubley] added support for RGB vs BGR regardless of endian -+ [Herve Drolon] added FreeImage_MultigridPoissonSolver -+ [Carsten Klein] added FreeImage_PreMultiplyWithAlpha -+ [Carsten Klein] added __stdcall version of FreeImage_OutputMessage -+ [Carsten Klein] added new palette and color manipulation functions (see below) : - added FreeImage_SetTransparentIndex - added FreeImage_GetTransparentIndex - added FreeImage_GetAdjustColorsLookupTable - added FreeImage_AdjustColors - added FreeImage_ApplyColorMapping - added FreeImage_SwapColors - added FreeImage_ApplyPaletteIndexMapping - added FreeImage_SwapPaletteIndices -* [Herve Drolon] fixed a bug in TIFF plugin when reading 8-bit + 8-bit alpha images -* [Herve Drolon] fixed a bug in TIFF plugin when reading images with uncommon bitdepths -* [rodrigo] fixed FreeImage exception handling under gcc (added -fexceptions to gcc compiler flags) -* [Martin Dyring-Andersen] fixed GIF plugin crashing on some corrupted files -* [Herve Drolon] fixed a bug with RLE encoding for 8-bit BMP images -* [Herve Drolon] fixed GPS metadata being skipped when reading metadata in Exif images -* [Herve Drolon] fixed a bug when reading OS/2 BMP images with a negative height -* [Ryan Rubley] fixed a bug with loading of GIFs with large amounts of solid color areas -* [Ryan Rubley] fixed OS X compile error in BitmapAccess.cpp -* [Herve Drolon] fixed a bug in FreeImage_Paste when pasting non-standard image types -* [Herve Drolon] saving 1-bit TIF with the TIFF_CCITTFAX3 flag is now compliant with the TIFF Class F specification -* [Carsten Klein] fixed topdown parameter in FreeImage_ConvertFromRawBits and FreeImage_ConvertToRawBits being handled in reverse -* [Herve Drolon] fixed a bug when reading some RLE-4 encoded BMP data -* [Carsten Klein] conversion from 1-bit to 32-bit now keep possibly present transparency - -February 11th, 2007 - 3.9.3 -! FreeImage now uses libPNG 1.2.16 -! [Ryan Rubley/Ryan Davis] reworked the MacOSX makefile in order to fully support Universal Binary builds of FreeImage -! [Herve Drolon] makefiles are now generated from VS2003 project files instead of VS6 project files -! [Herve Drolon] changed JPEG load/save flag option values -+ [Herve Drolon] added support for RGBAF images to FreeImage_ConvertToRGBF -+ [Herve Drolon] FreeImage_Paste now works with any bitmap type -+ [Herve Drolon] added full support for 64-bit RGBA images to the PNG and TIFF plugins -+ [Jascha Wetzel] added JPEG downsampling feature to PluginJPEG:Load -* [Thomas Chmielewski] fixed a bug in FreeImage_Dither and Bayer dithering, added FID_BAYER16x16 -* [Raphael Gaquer] greatly improved the speed of the GIF encoder -* [Herve Drolon] fixed saving of metadata in the PNG plugin -* [rampelstinskin] fixed transparency table to alpha channel conversion for 4-bit images in FreeImage_ConvertTo32Bits -* [Scott Smith] added missing IPTC tag named "Country/PrimaryLocationCode" -* [Herve Drolon] changed #include by #include in FreeImage.h (needed by Solaris 9) -* [Pierre Arnaud] fixed the use of FreeImage in low memory condition by checking some returned values of the malloc function -* [Pierre Arnaud] fixed TagLib::getTagFieldName not being thread safe - -October 30th, 2006 - 3.9.2 -! FreeImage now uses libTIFF 3.8.2 (with patch 2006-10-13) -+ [Herve Drolon] added full support for 16-bit greyscale and 48-bit RGB to the PNM plugin -+ [Herve Drolon] added IPTC writing support to JPEG & TIFF plugins -+ [Herve Drolon] added new Exif maker note tags -+ [Herve Drolon] added FreeImage_JPEGCrop -+ [Thorsten Radde] added support for 8-bit palettized bitmaps in FreeImage_RotateClassic -+ [Matt Rice] added automatic call to FreeImage_Initialise / FreeImage_DeInitialise when using FreeImage as a .so -+ [Martin Dyring-Andersen] added FreeImage_LoadMultiBitmapFromMemory to the multi-page API -+ [Herve Drolon] added support for tiled TIFF images -* [Carsten Klein] fixed a bug in FreeImage_SetMetadata occuring when deleting a tag -* [Herve Drolon] fixed a bug in PNG plugin when reading Macromedia 'false' PNG files -* [Thorsten Radde] added resolution support to PluginPSD -* [Ryan Rubley] fixed a bug in PluginGIF occuring with interlaced GIF -* [Ryan Rubley] fixed a bug in the multipage cache mechanism (internal FreeImage_FindBlock function) -* [Thorsten Radde] fixed a stack corruption in TIFF plugin occuring when reading exif tags -* [checkered] fixed a bug in the multipage cache mechanism causing VS2005 to crash on multipage files -* [Herve Drolon] fixed a bug with transparency support of 1- and 4-bit images -* [Roar Flolo] fixed a bug in PSD plugin when reading non compressed RGB images (alpha channel initialization) -* [Nicolas Hatier] fixed a bug in PluginGIF when using the GIF_PLAYBACK flag -* [Herve Drolon] fixed a bug in TIFF plugin when saving 8-bit images using LZW with differenciation -* [Herve Drolon] fixed 64-bit compilation issue with LibPNG and assembler code - -July 16th, 2006 - 3.9.1 -* [Ryan Rubley] fixed a bug in PluginGIF plugin causing FreeImage to crash on malformed GIF files - -July 6th, 2006 - 3.9.0 -! FreeImage now uses libPNG 1.2.12 -! FreeImage now uses libTIFF 3.8.2 (with patch 2006-06-24) -! FreeImage_Allocate/FreeImage_Allocate now set the resolution to 72 dpi instead of 0 -+ [Herve Drolon/Petr Pytelka] added a raw FAX G3 format loader -+ [Herve Drolon] added support for most image types to FreeImage_Rescale -+ [Herve Drolon] added FreeImage_MakeThumbnail -+ [Herve Drolon] added support for 64-bit images to FreeImage_ConvertTo32Bits -+ [Herve Drolon] added support for Exif tags to TIF plugin (read only) -+ [Herve Drolon] added FreeImage_ReadMemory -+ [Herve Drolon] added FreeImage_WriteMemory -+ [Herve Drolon] added new Exif maker note tags -+ [Sherman Wilcox] added a SGI file format loader -+ [Herve Drolon] added support for separated images to PluginTIFF -+ [Herve Drolon] added support for progressive-JPEG saving to PluginJPEG -* [Carsten Klein] FreeImage_Dither and FreeImage_Threshold now work with palettized 8-bit dib -* [Christophe Petit] fixed a bug in FreeImage_GetFIFFromFilenameU occuring with files without extension -* [Leigh Brasington] fixed a bug in PluginGIF causing FreeImage not working on Win/98/ME -* [Herve Drolon] fixed a bug in PluginTIFF with writing of JPEG-in-TIFF files -* [Jojakim Stahl] fixed a bug occuring with 4-bit PCX files -* [Sandor Szalacsi] fixed a bug in FreeImage_SetBackgroundColor (bkgnd clearing) -* [Petr Pytelka] fixed PluginTIFF::_tiffSizeProc failing on some images -* [Sherman Wilcox] fixed a bug in DDS plugin when loading images whose size is not a multiple of 4 -* [Sherman Wilcox] fixed a memory leak in PluginDDS::LoadDXT_Helper -* [Sherman Wilcox] fixed DDS plugin bad behavior with invalid DDS files (such as files with zero length) -* [Floris van den Berg] fixed a memory leak in the MultiPage cache mechanism -* [Herve Drolon] replaced WIN32 #define by _WIN32 #define as this is needed by VS2005 -* [Herve Drolon] fixed a VS2005 error in FreeImage_DeletePage -* [Petr Supina] fixed a pow(long,long) function not being standard ANSI C/C++ -* [Petr Supina] fixed FreeImage_FindBlock function not being standard ANSI C/C++ -* [Olaf Stoyke] added support for 64-bit Linux OS -* [Craig Stark] fixed FreeImage support on Intel based Mac OS -* [Herve Drolon] fixed PluginTIFF failing on bad fax tiff images (bad images are now loaded 'as is') -* [Zack Simpson] fixed a bug occuring in rare situations with FreeImage_Aligned_Malloc - -September 5, 2005 - 3.8.0 -! FreeImage now uses libTIFF 3.7.3 -! FreeImage now uses ZLib 1.2.3 -+ [Herve Drolon] added support for 48-bit images to FreeImage_ConvertTo24Bits -+ [Herve Drolon] added FreeImage_ConvertToGreyscale -+ [Herve Drolon] added support for 16-bit greyscale images to FreeImage_ConvertTo8Bits -+ [Petr Pytelka] added UNICODE functions (see below) - added FreeImage_LoadU - added FreeImage_SaveU - added FreeImage_GetFIFFromFilenameU - added FreeImage_GetFileTypeU -+ [Herve Drolon] FreeImage_Copy now works with any bitmap type -+ [Herve Drolon] added support for 1-bit images to FreeImage_Paste -* [Ryan Rubley] fixed PluginGIF failing to link on some broken gcc versions -* [Karl-Heinz Bussian] fixed a bug in LookupX11Color/LookupSVGColor with handling of grey color names -* [Herve Drolon] FreeImage_Dither now uses FreeImage_ConvertToGreyscale and handles 4/8-bit palletized images -* [Herve Drolon] FreeImage_Threshold now uses FreeImage_ConvertToGreyscale and handles 4/8-bit palletized images -* [Craig Hockenberry] fixed PluginGIF::Save swapping the byte order for the height on big endian machines (e.g. PPC on Mac OS X.) -* [Herve Drolon] fixed a bug in JPEG plugin when reading Exif maker notes from images produced by Nikon Editor -* [Herve Drolon] fixed a bug in BMP plugin when reading some malformed RLE8 bmp -* [Herve Drolon] fixed a bug in RAS plugin when loading 8-bit palettized images with less than 256 colors -* [Herve Drolon] fixed a bug in FreeImage_Rescale with 16-,48-,64-bit images -* [Herve Drolon] fixed a bug in the ICC profiles API when loading profile-less CMYK TIFF -* [Herve Drolon] 4-bit PNG are now loaded as 4-bit and no longer converted to 8-bit -* [Greg Ng] fixed a bug in FreeImage_ConvertToRGBF (FIT_BITMAP -> FIT_RGBF conversion) - -May 7, 2005 - 3.7.0 -! FreeImage now uses libTIFF 3.7.2 -! [Ryan Rubley] improved FreeImage_OpenMultiBitmap -+ [Detlev Vendt] added FreeImage_ZLibGUnzip -+ [Herve Drolon] added new image data types FIT_RGB16, FIT_RGBA16, FIT_RGBF, FIT_RGBAF -+ [Herve Drolon] FreeImage_FlipHorizontal & FreeImage_FlipVertical now work with any bitmap type -+ [Herve Drolon] added conversions to float and double in FreeImage_ConvertToType -+ [Herve Drolon] added FreeImage_ConvertToRGBF -+ [Herve Drolon] added support for 16-, 48- and 96-bit images to FreeImage_Rescale -+ [Ryan Rubley] added FreeImage_ColorQuantizeEx -+ [Ryan Rubley] added FIMD_ANIMATION and FIDT_PALETTE -+ [Ryan Rubley] added brand new PluginGIF with full animation multipage and metadata support -+ [Herve Drolon] added support for FIC_MINISWHITE 8-bit images to FreeImage_Rescale -+ [Herve Drolon] added HDR (High Dynamic Range) format (loader & writer) -+ [Herve Drolon] added support for 48-bit images in TIFF plugin -+ [Herve Drolon] added support for 48-bit images in PNG plugin -+ [Herve Drolon] added tone mapping operators (see below) -+ added FreeImage_ToneMapping -+ added FreeImage_TmoDrago03 -+ added FreeImage_TmoReinhard05 -+ [Petr Pytelka] added FreeImage_JPEGTransform -* [Herve Drolon] allowed loading of corrupted JPEG with a premature end of file -* [Herve Drolon] fixed a memory leak with loading of exif JPEG images -* [Detlev Vendt] changed some 'pointer-to-int' casts to 'pointer-to-long' for 64bit machines -* [Ryan Rubley] fixed a memory leak in the multipage API -* [Ryan Rubley] updated VB6 wrapper generation for new functions -* [Herve Drolon] fixed incorrect behavior when reading JPEG comments containing special characters -* [Herve Drolon] fixed incorrect behavior when reading JPEG ICC profiles with a size greater than 64 KB -* [Herve Drolon] fixed a bug in TIFF plugin when loading malformed multipage TIFF -* [Herve Drolon] fixed PluginTIFF not being thread safe - -February 20, 2005 - 3.6.1 -* [Ryan Rubley] fixed a memory leak in the metadata API -* [luedi] improved the robustness of FIBITMAP allocations - -February 13, 2005 - 3.6.0 -! FreeImage now uses libMNG 1.0.9 -! [Herve Drolon] improved the speed of FreeImage_Rescale -! [Herve Drolon] improved FreeImage_RotateClassic (more compact code, a little faster) -! [Herve Drolon] improved the metadata API using tag accessors -+ [Detlev Vendt] added LZW support to PluginGIF:Save -+ [Herve Drolon] added VS.Net 2003 project files -+ [Herve Drolon] added VERSIONINFO resource to the DLL -+ [Herve Drolon] added support for CMYK JPEG on loading -+ [Petr Supina] added 16-bytes alignment to FIBITMAP palette and pixels starting address -+ [Petr Supina] added support for MMX/SSE2 code in LibJPEG (based on Mozilla/Firefox code) -+ [Herve Drolon] added TIFF_JPEG compression flag to the TIFF plugin -+ [Detlev Vendt] added FreeImage_ZLibGZip -+ [Detlev Vendt] added FreeImage_ZLibCRC32 -* [Detlev Vendt] fixed PluginPNG not being thread safe -* [Herve Drolon] fixed compiler warning C4018 occuring with VS.Net 2003 - -December 29, 2004 - 3.5.3 -! FreeImage now uses ZLib 1.2.2 -! FreeImage now uses libPNG 1.2.8 -! FreeImage now uses libTIFF 3.7.1 -! [Herve Drolon] improved FreeImage_RotateClassic -! [Detlev Vendt] improved FreeImage_Rescale (more compact code, preserving 8-bpp colors) -+ [Herve Drolon] added support for transparency saving in ICO plugin -+ [Herve Drolon] added support for 1-bit images to FreeImage_RotateClassic -+ [Herve Drolon] added FreeImage_SetDotsPerMeterX and FreeImage_SetDotsPerMeterY -* [Nan Feng] fixed memory leak in FreeImage_DeleteTag (internal stuff) -* [Nigel Stewart] added conditional #pragma with #ifdef _MSC_VER / #endif -* [Herve Drolon] fixed the '65536 lines' limit on loading in PNM plugin - -November 27th, 2004 - 3.5.2 -* [Herve Drolon] fixed a second bug in FreeImage_Clone function - -November 26th, 2004 - 3.5.1 -+ [Riley McNiff] added FreeImage_ConvertTo4Bits -* [Herve Drolon] fixed a buffer overrun with some ILBM images -* [Riley McNiff] fixed a potential problem when reading TIFF resolution info -* [Dimitar Atanasov] fixed a bug in FreeImage_Clone function -* [Dimitar Atanasov] fixed several bugs in TIFF plugin - -November 1st, 2004 - 3.5.0 -! FreeImage now uses libPNG 1.2.7 -! FreeImage now uses libTIFF 3.7.0 -! FreeImage now uses libMNG 1.0.8 -! [Herve Drolon] improved TIFF LZW compression using a predictor -! [Detlev Vendt] FreeImagesPlus: corrected references to FreeImage.h and FreeImage.lib -+ [Herve Drolon] added support for loading/saving of 8-bit transparent TIFF -+ [Riley McNiff] added support for 4-bit dib in FreeImage_Paste -+ [Herve Drolon] added support for memory IO streams (see below) -+ added FreeImage_OpenMemory -+ added FreeImage_CloseMemory -+ added FreeImage_LoadFromMemory -+ added FreeImage_SaveToMemory -+ added FreeImage_TellMemory -+ added FreeImage_SeekMemory -+ added FreeImage_AcquireMemory -+ added FreeImage_GetFileTypeFromMemory -+ [Petr Pytelka] added FreeImage_GetFIFMimeType to the plugins function list -+ [Herve Drolon] added ICC profile support to JPEG plugin -+ [Herve Drolon] added support for metadata (see below) -+ added FreeImage_SetMetadata -+ added FreeImage_GetMetadata -+ added FreeImage_GetMetadataCount -+ added FreeImage_TagToString -+ added FreeImage_FindFirstMetadata -+ added FreeImage_FindNextMetadata -+ added FreeImage_FindCloseMetadata -* [Riley McNiff] fixed a bug with FreeImage_SetPixelIndex and 4-bit images -* [Petr Pytelka] fixed returned value in FreeImage_CloseMultiBitmap -* [Petr Pytelka] fixed index of new page in FreeImage_InsertPage -* [Aaron Shumate] fixed a minor bug in PNG plugin -* [Aaron Shumate] fixed a bug in IFF plugin (odd-length chunks) -* [Rupert Hewitt] fixed FreeImage not compiling on National Instruments Cvi Ccompiler -* [Herve Drolon] fixed a bug in IFF plugin (ILBM data) -* [Fred Harju] added a Makefile for Solaris 9 -* [Roddy Pratt] fixed FreeImage not linking under Borland C++ Builder -* [Vadim Alexandrov] fixed a memory leak in the multipage API -* [Herve Drolon] fixed a bug with DDS plugin behaviour on Big Endian OS -* [Herve Drolon] fixed a bug with conversion of JPEG resolution info on saving - -July 8th, 2004 - 3.4.0 -! [Jim Keir] improved FreeImage_FlipVertical function -! [Herve Drolon] LZW compression is now enabled in FreeImage -+ [Karl-Heinz Bussian] added constants to FreeImage.h to get at compile time the library version -+ [Karl-Heinz Bussian] added color lookup functions for X11 and SVG -+ [Herve Drolon] added TIFF tags TIFF_CCITTFAX3, TIFF_CCITTFAX4 and TIFF_LZW -+ [Detlev Vendt] added support for CMYK TIFF files with alpha channel -+ [Detlev Vendt] added (re-introduction of) PluginGIF -* [Herve Drolon] fixed a bug with loading of FAX TIFF images (introduced with LibTIFF 3.6.1) -* [Herve Drolon] fixed a bug in Floyd-Steinberg dithering algorithm -* [Herve Drolon] fixed a bug in Targa plugin save function -* [Herve Drolon] fixed a bug in FreeImage_AdjustCurve function -* [Ryan Rubley] fixed a bug with FreeImage_Rescale's filters accuracy -* [Ryan Rubley] fixed a bug in NN quantizer -* [Herve Drolon] fixed a bug with TIFF files containing additional Photoshop alpha channels -* [James Rossfeld] fixed a memory leak with some PSD images -* [Herve Drolon] fixed a bug with saving of 32-bit non transparent PNG images -* [Alexandr Zamaraev] fixed FreeImage not compiling with mingw32 -* [Herve Drolon] fixed FreeImage not compiling with VC.NET (pow function needs casts) - -May 2, 2004 - 3.3.0 -! [Ryan Rubley] FreeImage has been ported to MacOSX and should also work on other big endian processors -+ [Ryan Rubley] rewrote XPM plugin (better load support) and added save support -+ [Ryan Rubley] added ICO_MAKEALPHA flag to ICO plugin -+ [Ryan Rubley] Set/GetPixelColor now works with 16-bit pixels (555 or 565) -+ [Herve Drolon] PNG plugin now supports loading and saving of unsigned 16-bit greyscale images -* [Herve Drolon] fixed a bug with loading of 8-bit and 16-bit PNG with a 8-bit alpha channel -* [Herve Drolon] fixed a bug in NN quantizer algorithm with handling of 4-byte boundary alignment. -* [Herve Drolon] fixed a bug in PluginIFF Validate function -* [Herve Drolon] fixed a minor design issue in FreeImage_GetFIFFromFormat -* [Brad Schick] fixed some compiler warnings with VC++ 7.1 -* [Herve Drolon] fixed a bug with saving of 8-bit palettized images to 24-bit JPEG (channel inversion) - -March 16, 2004 - 3.2.1 -! [Volker Gärtner] improved the DDS plugin -! [Herve Drolon] FreeImage_Rescale now works on 8-, 24- and 32-bit images -! [Herve Drolon] FreeImage_Copy now works on 1-, 4-, 8-, 16-, 24- and 32-bit images -* [Floris van den Berg] fixed a bug in the MultiPage cache mechanism -* [Herve Drolon] fixed a bug with loading/saving of 8-bit transparent tga images -* [Herve Drolon] fixed a bug with loading of 1-bit TIFF (introduced with LibTIFF 3.6.1) - -February 18, 2004 - 3.2.0 -! FreeImage now uses libTIFF 3.6.1 -+ [Herve Drolon] added FreeImage_HasBackgroundColor -+ [Herve Drolon] added FreeImage_GetBackgroundColor -+ [Herve Drolon] added FreeImage_SetBackgroundColor -+ [Herve Drolon] added FreeImage_Composite -+ [Herve Drolon] added ICC profile support to PNG plugin -+ [Herve Drolon] added background color support to PNG plugin -+ [Volker Gärtner] added support for DDS format (loader) -* [Steve Johnson] improved FreeImage_OpenMultiBitmap/FreeImage_CloseMultiBitmap -* [Steve Johnson] fixed a bug in FreeImage_InsertPage -* [Herve Drolon] fixed a bug with JPEG compressed TIFF (red/blue swapping) -* [Herve Drolon] fixed a bug in PluginTarga where 8-bit images were saved incorrectly - -January 26, 2004 - 3.1.0 -! FreeImage now uses ZLib 1.2.1 -+ [Herve Drolon] added support for integer, real and complex image types (see below) -+ added FREE_IMAGE_TYPE enum -+ added FreeImage_AllocateT -+ added FreeImage_GetImageType -+ added FreeImage_FIFSupportsExportType -+ added FreeImage_ConvertToStandardType -+ added FreeImage_ConvertToType -+ added load/save support of all image types to TIFF plugin -+ [Peter Lemmens] added a Validate function to TARGA plugin -+ [Herve Drolon] added FreeImage_GetPixelIndex / FreeImage_SetPixelIndex -+ [Herve Drolon] added FreeImage_GetPixelColor / FreeImage_SetPixelColor -+ [Herve Drolon] added FreeImage_GetComplexChannel / FreeImage_SetComplexChannel -* [Serge Ivanchenko] TIFF_DEFLATE compression is now enabled in TIFF plugin -* [Herve Drolon] fixed a bug in NeuQuant color reduction algorithm - -November 16, 2003 - 3.0.4 -* [Tobias Persson] fixed FreeImage_GetChannel not working with FICC_ALPHA channel -* [Detlev Vendt] fixed a minor bug with PNG plugin and PNG_IGNOREGAMMA flag -* [Detlev Vendt] fixed a memory leak in PNG plugin save routine -* [Detlev Vendt] fixed JPEG validation problem with .jpe files -* [Ryan Rubley] added Source/LibTIFF/tif_extension.c to LibTIFF (needed for MacOSX) -* [Herve Drolon] improved error handling in TIFF plugin -+ [Karl-Heinz Bussian] added FreeImage_IsLittleEndian -+ [Karl-Heinz Bussian] added JPEG save support for 8-bit miniswhite bitmaps (transparent conversion to minisblack) -+ [Karl-Heinz Bussian] FreeImage_GetColorType now recognizes 8-bit FIC_MINISWHITE images -! [Herve Drolon] FreeImage_Rescale now supports rescaling of 32-bit images with alpha channel -! [Herve Drolon] FreeImage_Invert now supports inversion of 32-bit images with alpha channel -! [Herve Drolon] FreeImage_AdjustCurve now supports working with FICC_ALPHA channel - -November 2, 2003 - 3.0.3 -* [Ryan Rubley] improved makefile for Linux -* [Ryan Rubley] fixed FreeImage not compiling under MacOSX -* [Detlev Vendt] fixed still present inconsistancy with 32bpp transparency handling -* [Herve Drolon] fixed incorrect loading of 4-bit greyscale images in TIFF plugin - -October 27, 2003 - 3.0.2 -! FreeImage now uses libMNG 1.0.6 -* [Herve Drolon] fixed a boolean test in PluginCUT returning always false -* [Herve Drolon] fixed a warning in PluginIFF generated with g++ -* [Linus Tan] fixed a bug in FreeImage_Copy -* [Herve Drolon] fixed FreeImage not compiling under Linux (thanks to Michal) - -October 20, 2003 - 3.0.1 - -! FreeImage now uses libTIFF 3.6.0 -* [Detlev Vendt] fixed incorrect definition of the FREE_IMAGE_FORMAT enum -* [Detlev Vendt] fixed a potential crash problem with Load / Save routines -* [Herve Drolon] fixed incorrect loading of 16-bit greyscale images in TIFF plugin -* [Dennis Lim] fixed a memory leak in Floyd & Steinberg dithering routine -* [Herve Drolon] fixed a bug in BMP loader (incorrect loading of RLE4 bmp) -* [Detlev Vendt] fixed some inconsistancy with 32bpp transparency handling -+ [David Boland] added a C# wrapper -// Linux compatibility issues -- [Michal Novotny] removed the round function in Utilities.h -! [Herve Drolon] replaced the round routine by the clamp routine in PluginPCD -+ [Herve Drolon] added _itoa version in Utilities.h -* [Michal Novotny] fixed untyped consts not accepted by g++ in PluginBMP - -September 8, 2003 - 3.0.0 -- [Herve Drolon] removed deprecated functions -- [Herve Drolon] removed deprecated flags (TARGA_LOAD_RGB555, ICO_*, except ICO_DEFAULT) -- [Herve Drolon] removed the FreeImage pointer table (internal stuff) -+ [Herve Drolon] added a C++ wrapper -+ [Herve Drolon] added the FreeImage Toolkit (see below) -+ added FreeImage_Rescale -+ added FreeImage_RotateClassic -+ added FreeImage_RotateEx -+ added FreeImage_FlipHorizontal -+ added FreeImage_FlipVertical -+ added FreeImage_Invert -+ added FreeImage_AdjustCurve -+ added FreeImage_AdjustGamma -+ added FreeImage_AdjustBrightness -+ added FreeImage_AdjustContrast -+ added FreeImage_GetHistogram -+ added FreeImage_GetChannel -+ added FreeImage_SetChannel -+ added FreeImage_Copy -+ added FreeImage_Paste -+ [Karl-Heinz Bussian] added XPM loader -+ [Karl-Heinz Bussian] added flags parameter to FreeImage_CloseMultiBitmap -+ [Karl-Heinz Bussian] added JPEG save support for 8-bit palettized bitmaps (transparent conversion to 24-bit) -+ [Herve Drolon] added interface to ZLib compression functions -+ [Herve Drolon] added ICO format to the multipage API (loader & writer) -+ [Herve Drolon] added a MIME type to all plugins -* [Karl-Heinz Bussian] fixed incorrect conversion from 1-bit FIC_MINISWHITE bitmaps to 8-bit -* [Herve Drolon] fixed a bug in FreeImage_CloseMultiBitmap -* [Herve Drolon] fixed a potential memory leak in conversion functions (8-, 24-, 32-bit) -* [Robert Walker] fixed incorrect conversion from 16-bit to 24-bit and 16-bit to 32-bit -* [blurble] fixed TIFF validate signature problem (3DS files were recognized as TIFF) -* [Kurt Jankowski-Tepe] fixed FreeImage not compiling on MinGW / LCC WIN32 -* [Jani Peltonen] fixed bug in PluginTARGA where 32-bit bitmaps are not always correctly flipped -* [Detlev Vendt] fixed a bug with TIFF (memory leak with ICC profiles) - -May 25, 2003 - 2.6.1 -+ [Detlev Vendt] added FIC_CMYK to FREE_IMAGE_COLOR_TYPE -+ [Detlev Vendt] added ICC profile support to the library (see below) -+ added FreeImage_GetICCProfile -+ added FreeImage_CreateICCProfile -+ added FreeImage_DestroyICCProfile -+ added FIICCPROFILE & FIICCPROFILE flags -+ added plugin function FreeImage_FIFSupportsICCProfiles -+ [Detlev Vendt] added ICC profile support for TIFF -+ [Herve Drolon] added XBM (X11 Bitmap Format) support : loading -* [Herve Drolon] fixed incorrect IFF file detection (thanks Floris) -* [Herve Drolon] fixed incorrect conversion from 1/4-bit greyscale bitmaps to 8-bit -* [Herve Drolon] fixed a bug in TIFF writer when saving 1,4,8 bit dib (introduced in 2.6.0, sorry) -* [Herve Drolon] fixed a palette problem in TIFF loader when loading 1-bit b & w images -* [Herve Drolon] improved FreeImage_Dither to handle any bitdepth - -May 5th, 2003 - 2.6.0 -! FreeImage now uses libPNG 1.2.5 -! FreeImage now uses libMNG 1.0.5 -! [Markus Loibl] ActiveX wrapper is now distributed in a separate release (since 2.5.5) -! [Herve Drolon] the function FreeImage_Free is now deprecated : use FreeImage_Unload instead -! [Herve Drolon] updated the generic samples and removed deprecated functions -+ [Detlev Vendt] added CMYK support to TIFF save function -+ [Detlev Vendt] added TIFF_SAVE_CMYK flag constant -+ [Detlev Vendt] added 32-bit support (with transparency handling) to TIFF plugin -+ [Herve Drolon] added FreeImage_Threshold -+ [Herve Drolon] added FreeImage_Dither -+ [Herve Drolon] added FREE_IMAGE_DITHER parameter to FreeImage_Dither -* [Herve Drolon] improved error handling in PluginMNG -* [Herve Drolon] improved TIFF flags handling in TIFF save function -* [Herve Drolon] fixed a potential crash-problem in FreeImage_OutputMessage (in case of a null message) -* [Detlev Vendt] fixed a bug with the deprecated FreeImage_GetBitsRowCol (trailling backslash behind the DEPRECATE macro) - -July 24th, 2002 - 2.5.5 -! FreeImage now uses libPNG 1.2.4 -! FreeImage now uses libMNG 1.0.4 -+ [Markus Loibl] added ActiveX wrapper - -June 22th, 2002 - 2.5.4 -* [Timothy Roughton] fixed FreeImage not compiling on LCC WIN32 -* [Markus Loibl] fixed PluginTIFF sometimes saving with wrong X/Y resolution -* fixed crashbug when loading some RLE4 BMPs -! FreeImage now uses LibPNG 1.2.3 -! [Markus Loibl] improved startup plugin locate handling code -! [Gerhard Gruber] made some changes so that FreeImage compiles on VC5 -+ [Markus Loibl] added flags TIFF_PACKBITS, TIFF_DEFLATE, TIFF_ADOBE_DEFLATE and TIFF_NONE - -May 21th, 2002 - 2.5.3 -* fixed wrong colors when loading 16-bit grayscale TIFF -* fixed crash-problem with FreeImageQt -* fixed PluginTIFF saving some bitmaps flipped vertically -* [Laurent Rocher] fixed bug in FreeImage_GetLockedPageNumbers -* [Laurent Rocher] fixed bug in FreeImage_UnlockPage -! FreeImage now uses libpng 1.2.2 -+ added TARGA save support -+ added BMP RLE8 save support - -March 30th, 2002 - 2.5.2 -* fixed bug in PluginTARGA where 32-bit bitmaps are not always correctly flipped -* fixed FreeImage_GetLockedPageNumber being mentioned in FreeImage.h -* fixed crash bug when handling read-only multipage bitmaps -- removed internal function FreeImage_GetExtraDataPointer -! FreeImage now uses zlib 1.1.4 -+ added function FreeImage_GetLockedPageNumbers - -March 2nd 2002 - 2.5.1 -* fixed pluginTIFF not being able to save 32-bit bitmaps -* fixed not being able to save PNM bitmaps through the LoadXXX wrappers -* fixed a webcam generated BMP image being loaded with wrong colors -! FI_ReadProc, FI_WriteProc, etc. do now carry the DLL_CALLCONV flag -! the function FreeImage_GetBitsRowCol is now deprecated -! FreeImage_SetTransparencyTable now taken an integer as count parameter -! FreeImage_IsTransparent now always returns true for 32-bit bitmaps -! PluginPNG::Save now ignores the result of FreeImage_IsTransparent -! PluginTIFF now converts all 32-bit bitmaps to 24-bit, until our patch - to fully support alpha in TIFF is applied in libtiff -+ added full multi-paging support -+ added octal and hexadecimal number support to FreeImage_OutputMessage - -January 3rd 2002 - 2.5.0 -* fixed bug in FreeImage_SaveJPEG -* fixed bug in FreeImage_LoadMNG -* fixed bug in FreeImage_LoadPNG -* fixed small Visual C++ 5.0 compiler issue in PluginMNG.cpp -* fixed FreeImage crashing on JPEG 6.0 encoded TIFFs -! FreeImage now uses libTIFF 3.5.7 -! FreeImage now uses libPNG 1.2.1 -! all the FreeImage_LoadXXX and FreeImage_SaveXXX functions are now deprecated -+ added Dr. Halo (*.cut) support -+ added printf-like format string support to SetOutputMessage -+ added basic multi-paging support: open, close, counting and grabbing -+ added deprecation manager -+ added FreeImage_Clone function - -October 3rd 2001 - 2.4.2 -* fixed missing BI_BITFIELDS support for 32-bit BMPs -* fixed bug in FreeImage_ConvertLine16_555_To16_565 and vice versa -* fixed bug in FreeImage_ConvertToRawBits -* fixed PluginTIFF behaving incorrectly on PHOTOMETRIC_MASK images -* fixed 16 bit TIFFs not loading correctly -* fixed incorrect handling of CCITTFAX3 and CCITTFAX4 TIFFs -* fixed JPEG encoded TIFFs not being supported -! [Yours Detlev] patched libTIFF to handle EXTRASAMPLE_UNSPECIFIED -! [Juergen Riecker] improved speed of PCX loading a lot -! rewrote parts of FreeImage to improve support for c -! the internal RGB555 and RGB565 macros now read BGR instead of RGB -! FreeImage now uses libMNG 1.0.3 -! FreeImage now uses libPNG 1.2.0 -! FreeImage_Save now opens files with the "w+b" flag -! renamed internal macro CalculateUsedColors to CalculateUsedPaletteEntries -! enabling/disabling plugins no longer has effect on FIFSupportsReading -! enabling/disabling plugins no longer has effect on FIFSupportsWriting -+ added flag PNG_IGNOREGAMMA -+ added function FreeImage_FIFSupportsExportBPP - -July 30th 2001 - 2.4.1 -* [Jan Nauta] fixed some plugin ids not being passed to plugins -* [Jan Nauta] fixed some functions being natively called instead of indirect -* [Jan Nauta] fixed BMPs with signature BA not being regognised -* [Remo Eichenberger] fixed memory leak in the plugin system -* fixed seek bug in PluginIFF's Validate -* fixed transparency issue in PluginPNG -* fixed uncaught exceptions in WUQuantizer and NNQuantizer -* fixed some problems with PluginTARGA -* fixed some problems with PluginICO -* fixed some problems with PluginBMP -! improved FreeImageQt's load function a little -! tell/seek control for validation is now handled inside the plugin framework - -July 22th 2001 - 2.4.0 -* (Yours Detlev) fixed memory leak in FreeImage_GetFIFFromFilename -* (Yours Detlev) fixed memory leak in the ICO plugin -* (Yours Detlev) fixed memory leak in the PNG plugin -* fixed potential NULL-pointer access bug in Plugin::AddNode -* fixed problems with linking the static lib -- removed LBM plugin. Its functionality is placed in the IFF plugin now -- removed FreeImage_GetFIFByIndex -! FreeImage now uses LibMNG 1.0.2 -! FreeImage_SetTransparent now only enables alpha when the bitmap is 8 or 32 bit -! FreeImage_SetTransparencyTable now only enables alpha when the bitmap is 8 bit -! FreeImage_LoadLBM now uses Mark Sibly's IFF plugin -! FreeImage_SaveBMP now converts to 24-bit when bpp is 32 and transparency is off -! FreeImage_SaveJPEG now converts to 24-bit when bpp is 32 and transparency is off -! FreeImage_SavePNM now converts to 24-bit when bpp is 32 and transparency is off -! FreeImage_SaveTIFF now converts to 24-bit when bpp is 32 and transparency is off -+ [Mark Sibly] added IFF (ILBM) support -+ added basic support for Photoshop files -+ added mime type support (FreeImage_GetFIFFromMime) -+ added functions FreeImage_SetPluginEnabled and FreeImage_IsPluginEnabled - Disabling plugins modifies the behaviour of the following functions: - * FreeImage_LoadFromHandle - * FreeImage_SaveToHandle - * FreeImage_FIFSupportsReading - * FreeImage_FIFSupportsWriting - * FreeImage_GetFIFFromFormat - * FreeImage_GetFIFFromFilename - * FreeImage_GetFIFFromMime - * FreeImage_Validate - -June 30th 2001 - 2.3.2 -* fixed missing "targa" extension in targa extension list -* fixed small memory leak in PluginList::AddNode -* fixed 32 bit PNG saving suddenly disappeared from the distro? -* fixed 'black line' bug in LoadTARGA -- removed project FreeImageM2 -- removed FreeImage_Combine -! FreeImage_RegisterLocalPlugin now receives a FI_InitProc as first parameter -! FreeImage_GetFIFFromFilename now also takes the format id into account -! cleanup up the code a little for PluginPCD and PluginPCX -+ added static lib project - -June 11th 2001 - 2.3.1 -* [Machiel ten Brinke] fixed the loading of some 'ancient' TARGAs -* [Rui Lopes] fixed some bugs in the external plugin registration -* fixed the plugin system crashing when the init function isn't called -- removed project FreeImagePy -- removed 32 to 24 bit conversion while saving PNG in FreeImageQt -! the scanline convert functions are now accessable in plugins -! FreeImage now uses an STL map to store the plugin list -! PluginSDK.h is now integrated into FreeImage.h -! FreeImage_Register now receives the boolean parameter 'load_local_plugins_only' -! FreeImage now uses LibPNG 1.0.12 -+ [Rui Lopes] added plugin for GIF reading/writing support -+ added function FreeImage_SetTransparencyCount -+ added support for 32 bit PNG saving -+ added FreeImage_RegisterLocalPlugin to allow plugins inside apps -+ added FreeImage_RegisterExternalPlugin to manually load DLLs -+ added plugin for JBIG reading/writing support - -May 4th 2001 - 2.3.0 -* [Martin Weber] fixed some small bugs in the TARGA and BMP plugins -* [Martin Weber] fixed tiny bug in new 16 bit conversions -* [Martin Weber] fixed load flag inconsistency in the TARGA plugin -* [Martin Weber] fixed plugin id / load reference inconsistency for PNM -* [Jan Nauta] fixed bug in conversion 16 -> 16 -* [Herve Drolon] fixed small bug in 4-bit PCX loader -- removed code that loads BMPs renamed to ICO in PluginICO -! the flag TARGA_LOAD_RGB555 is now obsolete -! the plugin list is now sorted internally -! ConvertTo32Bits now stores the transparency table as alpha mask -! FreeImage now uses LibMNG 1.0,1 -! FreeImage now uses LibPNG 1.0.11 -+ added external plugin support via DLLs -+ added function FreeImage_GetFIFByIndex -+ added internal function CalculateScanLine -+ added transparency support for high-color PNGs -+ added transparency support for high-color TIFFs -+ added functions FreeImage_SetTransparent and FreeImage_IsTransparent -+ added constant FIC_RGBALPHA to FREE_IMAGE_COLOR_TYPE - -April 5th 2001 - 2.2.0 -* [Remo Eichenberger] fixed small bug concerning DLLMain and static LIB generation -* fixed 1-bit bitmaps not properly loading in FreeImageQt -* fixed bug in conversion 16->16 -* FreeImage now uses LibPNG 1.0.10 -! [Martin Weber] improved loading of BMP files -! [Martin Weber] improved loading of TARGA files -! [Dave Larson] improved visual appearance after 16 conversions -! FreeImageQt now converts 32-bit bitmaps to 24-bit when saving PNGs and JPEGs -+ added functions FreeImage_Initialise and FreeImage_DeInitialise -+ added internal plugins -+ re-added combine/alphablend functions - -March 8th 2001 - 2.1.0 -* [Martin Hemming] fixed bug in 16-bit TARGA loading code -* fixed PNG's with alpha masks not loading correctly -! FreeImage is now dual-licensed: the FI-License and the GPL license -! FreeImage now uses LibPNG 1.0.9 -! FreeImage now uses LibTIFF 3.5.6 Beta -! FreeImage now uses LiBMNG 1.0.0 -! changed the ordering of the FREE_IMAGE_FORMAT table -! improved linux support -! improved test script -+ added transparency table support to SavePNG -+ added BI_BITFIELDS support to LoadBMP and SaveBMP -+ added reading support for OS/2 2.x BMPs -+ added support for MNG and JNG reading using LibMNG -+ added support for Deluxe Paint reading -+ added 'hot swap' support to the Core DLL -+ added 'hot swap' support to FreeImage Qt -+ added functions GetFIFFromFormat and GetFIFFromFilename -+ added functions FIFSupportsReading and FIFSupportsWriting -+ added function GetFIFRegExpr - -January 14th 2001 - 2.0.0 -* [Herve Drolon] fixed a bug in the conversion 4->8 -* [Herve Drolon] fixed a bug in metrics handling in SaveJPEG -* [Herve Drolon] fixed a bug in the return value of the function SaveTIFF -* fixed the presence of two WuQuantizer.cpp files in the distribution -* fixed bug where a BMP renamed to ICO isn't loaded -- removed FreeImage_ConvertToGreyScale. Use FreeImage_ConvertTo8Bits instead. -- removed the boolean parameters from all conversion routines -- removed page handling in LoadTIFF. A new range of functions will be added. -! The void pointers used in FreeImage are now typed -! LoadBMP now takes palettes in 24/32 bit images in respect -! All effects and MMX functions are now stored in a new library (FreeEffects) -! [Herve Drolon] fixed bug in FreeImage_GetColorType -! [Herve Drolon] improved PCX loader. It can now read 1, 4, 8 and 24-bit images -! [Manfred Tausch] improved FreeImage_Rotate -! [Luca Piergentili] fixed crash bug when saving some 1-bit TIFFs -! rewrote all bitdepth conversion routines making use of the new scanline converters -! rewrote bitdepth conversion in FreeImageQt (uses less memory) -! FreeImage is now compiled __stdcall -+ [Herve Drolon] added WBMP (Wireless Bitmap Format) support: loading and saving -+ [Herve Drolon] added 4, 16 and 32 bitdepth handling in GetColorType -+ [Herve Drolon] added handling of 8-bit greyscale bitmaps in SaveJPEG -+ [Herve Drolon] added NeuQuant color reduction algorithm to ColorQuantize -+ added DLL_CALLCONV (calling convention) flag -+ added bitmask support to all bitmaps -+ added a series of functions converting scanlines from one bitdepth to another -+ added functions ConvertFromRawBits and ConvertToRawBits -+ added project FreeImageM2: Magenta II MMT bindings for FreeImage -+ added basic foundation for linux support - -December 2th 2000 - 1.4.4 -* fixed small bug related to TIFFSetDirectory in FreeImage_LoadTIFF -* fixed FreeImage_Rotate sometimes clipping too much pixels -* fixed other small bug in FreeImage_Rotate -* fixed FreeImage_Clone not taking the FREEIMAGEHEADER in account -* fixed bug in FreeImageQt where 1-bit images are not correctly allocated -* fixed FreeImage_Crop not copying the palette -* fixed message function pointer crash bug -* fixed bug where the palette wasn't copied when saving in FreeImageQt -* fixed FreeImage_Clone not copying the transparency table -- removed FreeImage_WritePaletteEntry -! [Adam Gates] rewrote parts of FreeImage so that c compilers can handle it better -! FreeImageQt doesn't statically link with the FreeImage lib anymore -! FreeImageQt now uses atexit() to automatically unregister -! rewrote parts of FreeImage_LoadBMP to increase speed -+ [Markus Loibl] added metrics handling code to LoadBMP, LoadJPEG, LoadTIFF and LoadPCX -+ added metrics handling code to FreeImageQt -+ added functions FIQT_IsLoaded, FIQT_GetVersion and FIQT_GetCopyrightMessage -+ added conversion 1 -> 16 -+ added FreeImage_SaveJPEG and JPEG quality settings -+ added FreeImage_GetBitsRowCol -+ added function FIQT_SetOutputMessage to FreeImageQt -+ added FreeImage_GetFileTypeFromExtension and FIQT_GetFileTypeFromFormat -+ added project FreeImagePy: python bindings for FreeImage - -November 7th 2000 - 1.4.3 -* fixed FreeImage_SavePNG crash bug -* fixed slighly corrupt size filter in FreeImage_Combine -* fixed FreeImage_SaveTIFF not saving 4-bit images -* [Herve Drolon] fixed bug in FreeImage_LoadTIFF -* [Herve Drolon] fixed bug in FreeImage_GetColorType -- removed fclose from FreeImage_SavePNM (who put it there?) -! rewrote FreeImage_Rotate -! FreeImageQt now automatically detects which formats are supported by Qt and which not -! FreeImage_Allocate now returns a void pointer -! FreeImage_Unload is now called FreeImage_Free -+ added 16-bit 5-5-5 support to FreeImage_LoadBMP -+ added RLE_DELTA support to FreeImage_LoadBMP -+ added directory support to FreeImage_LoadTIFF -+ added functions dealing with transparency -+ added transparency support to 8-bit PNG's in Qt -+ added FREE_IMAGE_QUANTIZE parameter to FreeImage_ColorQuantize -+ added custom FREEIMAGEHEADER header prepended to internal bitmaps -+ added new documentation - -October 18th 2000 - 1.4.2 -* fixed FreeImage_SaveBMP storing an incorrect bfSize value in the BITMAPFILEHEADER -* fixed bug where JPEG and PNG wouldn't load in FreeImageQt -* fixed FreeImage_Mirror mirroring one pixel less than needed -! FreeImage_MaskedCombine24 is now called FreeImage_MaskedCombine24Ex -! FreeImage_MaskedCombine32 is now called FreeImage_MaskedCombine32Ex -+ added 16-bit bitmap support to FreeImage_Mirror -+ added 16-bit bitmap support to FreeImage_ConvertTo8Bits -+ added simple version of FreeImage_MaskedCombine24 -+ added simple version of FreeImage_MaskedCombine32 - -October 17th 2000 - 1.4.1 -* [Herve Drolon] fixed bug in FreeImage_ConvertTo8Bits -* fixed bug in conversion with 16 -> 24 and 16 -> 32 -- removed static library support -- removed all unnecessary files from LibTIFF, LibPNG, LibJPEG and ZLib -- removed all absolute seeks from the library -! FreeImageQt now makes use of the DLL distro -! rebuilt the entire directory structure -! improved handling of BMP -! renamed FreeImage_MaskedCombine to FreeImage_MaskedCombine32 -+ [Alexander Dymerets] added 24-bit masked alpha blending with a seperate alpha mask -+ added FreeImage_Rotate (known bug in degrees 76 to 106) -+ added 4-bit bitmap support to FreeImage_ConvertTo16Bits -+ added 8-bit bitmap support to FreeImage_ConvertTo16Bits -+ added 32-bit bitmap support to FreeImage_ConvertTo16Bits -+ added 32-bit bitmap support to FreeImage_Mirror -+ added 16-bit 5-5-5 support to FreeImage_ConvertTo24Bits -+ added 16-bit 5-5-5 support to FreeImage_ConvertTo32Bits - -October 2th 2000 - 1.4.0 -* [Jani Kajala] fixed bug in conversion with 4 -> 24 and 8 -> 32 -* [Jani Kajala] fixed bug in FreeImage_Flip -* [Jani Kajala] fixed minor bug in FreeImage_LoadBMP -- [Herve Drolon] removed PBMFlags, PGMFlags and PPMFlags -- [Herve Drolon] removed FI_LoadGeneric -- removed FreeImage_Win32.h -! [Herve Drolon] changed FI_GetFileType -! [Herve Drolon] replaced FI_LoadPBM, FI_LoadPGM and FI_LoadPPM with FI_LoadPNM -! [Herve Drolon] improved FreeImage_LoadPNG -! FreeImage_WritePaletteEntry is now exported -+ [Herve Drolon] added FreeImage_SavePNG -+ [Herve Drolon] added FreeImage_SavePNM and PNMFlags -+ [Herve Drolon] added XXXFlags parameter to save functions -+ [Herve Drolon] added FreeImage_LoadRAS and FIF_RAS -+ added FreeImage_GetFileTypeFromExt - -September 7th 2000 - 1.3.5 -+ added conversion 4 -> 8 to FI_ConvertTo8Bits -+ added simple version of FI_GetFileType -+ added project FreeImageQt; a port of the library to the TrollTech library - -August 31th 2000 - 1.3.4 -* fixed 'ice effect' bug in new 24 bit PCX code -* fixed some bugs with the conversion 16 -> 24 and 16 -> 32 -! FI_Blur now returns void -! A debug build of the library now produces FreeImaged.dll and FreeImaged.lib -! TARGA_LOAD_ARGB8888 is now called TARGA_LOAD_RGB888 -! Alpha channels are now automatically loaded unless TARGA_LOAD_RGB888 is specified -! cleaned up the code a lot -+ added 32-bit bitmap support to FreeImage_ConvertToGreyscale -+ added support for 32-bit bottom-left TARGA images -+ added internal functions FreeImage_WritePaletteEntry() and FreeImage_GetScanLine() -+ added FreeImage_Win32.h, containing Windows functions needed to create DIBs -+ added documentation through Doxygen - -July 30th 2000 - 1.3.3 -* [Jani Kajala] fixed some bugs with the conversion 4 -> 24 and 8 -> 24 -* [Jani Kajala] fixed some bugs with the conversion 4 -> 32 and 8 -> 32 -* fixed bug in FI_LoadPNM's ASCII number loader -! [Herve Drolon] improved FI_LoadPNG -! [Herve Drolon] changed FI_ConvertToGreyScale (added changeable macro for conversion) -! improved FI_ConvertTo24Bits -! improved FI_ConvertTo32Bits -! freeImage now uses LibPNG 1.0.8 -+ [Herve Drolon] added FI_ColorQuantize, based on Wu's color quantizer -+ added the conversion 1 -> 24 -+ added the conversion 1 -> 32 -+ added FI_ConvertTo8Bits -+ added FI_Invert (very useful for image processing) -+ added FI_GetColorType and 'enum FREE_IMAGE_COLOR_TYPE' - -June 30th 2000 - 1.3.2 -- removed color reduction functions from the project -! [Herve Drolon] Improved FI_LoadTIFF code -! renamed FI_ToGrayscale to FI_ConvertToGreyScale -! renamed FI_IncreaseColors to FI_ConvertTo24Bits -! LoadBMP now supports 32-bit bitmaps -! [Jani Kajala] Improved FI_LoadTARGA and FI_LoadPCX code -+ added FI_ConvertTo32Bits to convert a bitmap to 32-bit -+ added FI_MaskCombine to combine two 32-bit bitmaps using a alpha mask -+ added FI_AddAlphaMask to enrich a 32-bit bitmap with an alpha mask -+ added FI_SaveTIFF -+ added 16-bit bitmap (565) support to the ConvertToXXX functions. -+ added FI_ConvertTo16Bits (555 and 565) - -June 1th 2000 - 1.3.1 -- removed Standard Template Library (STL) code -* [Jani Kajala] fixed minor bug in FI_LoadTARGA -* [Jani Kajala] fixed some minor bugs in FI_LoadPCX -! streamlined FI_LoadJPEG a little -! FreeImage now uses LibPNG 1.0.6 -! FreeImage now uses LibTIFF 3.5.5 -! FreeImage now uses malloc and free instead of new and delete -+ introduced compiler flags to disable certain features in the DLL -+ added experimental nearest color reduction (FI_ReduceColorsNearestColor) - -April 13th 2000 - 1.3.0 -* fixed some 8 bit PCX files loading incorrectly -* fixed tiny bug in internally used CalculateUsedColors function -- removed FI_SaveXPM. Only BMP is supported now. -- removed Windows dependencies for easier porting -! optimized FI_LoadKOALA a little -! optimized FI_Combine using MMX technology -! FI_Combine now receives an 'unsigned integer' as alpha blend parameter -! FI_InCreaseColors and FI_ReduceColors don't dispose the old bitmap anymore -+ added PNM support (PGM, PPM and PBM; both binary and ascii) -+ [Alexander Dymerets] added FI_EnableMMX and FI_DisableMMX -+ added various effect functions (FI_Blur, FI_Brighten and FI_Crop) - -March 1st 2000 - 1.2.1 -* fixed some 24 bit PCX files loading incorrectly - -February 8th 2000 - 1.2.0 -* fixed last bitmap data block in JPEG files being truncated -* fixed 4/8 bit BMP's incorrectly loading when the palette is smaller than the bitcount predicts -- removed FI_Load. There is no reliable way to identify all image formats -- removed FI_SetJpegDecodeMode. - Mode selection is now done using the 'DataEnum data' parameter of FI_LoadJPEG -! read_proc/write_proc/tell_proc in FreeImageIO now are same as fread/fwrite/ftell -+ added a 'DataEnum data' parameter to all FI_LoadXXX functions. -+ added 16 bit TARGA support -+ added RLE support for TARGA images -+ added FI_GetDIBSize to get the size of a DIB in bytes -+ added Kodak PhotoCD support (Base, Base/4 and Base/16 encoding) -+ added KOALA support -+ added FI_GetFileType. Note: there is no reliable way to identify TARGA, ICO and PCD. Therefore they have been excluded -In KOALA files only the files converted by a C64 emulator can be identified. -+ added FI_Combine to combine two 24-bit bitmaps with (optional) alpha blending - -January 15th 2000 - 1.1.1 -! FI_Copy is now called FI_Clone -+ added FI_ToGrayscale to convert a color bitmap to grayscale -+ added 32 bit TARGA support -+ added FI_IncreaseColors to increase the bitmap bitdepth from 4/8 bit to 24 bit - -January 14th 2000 - 1.1.0 -* FI_MIRROR: fixed nibbles not being mirrored in 4 bit images -* FI_MIRROR: fixed bits not being mirrored in 1 bit images -* fixed improper loading of 1, 4 and 8 bit OS/2 BMP's -* fixed some inconsistensies in the calculation of lines and pitches -* fixed incorrectly loading of Huffman and FAX encoded TIFFs -* fixed LoadTGA accepting 16 bit TGA's and returning corrupt DIB's -- removed LZW support for TIFFs -! FreeImage now uses LibTIFF 3.5.4 -+ added ICO support -+ added overridable file I/O support in the form of FreeImageIO and fi_handle -+ added FI_Load for generic image loading -+ added FI_ReduceColors for color reduction -+ added FI_Copy to copy a bitmap in memory - -January 5th 2000 - 1.0.0 +What's New for FreeImage + +* : fixed +- : removed +! : changed ++ : added + +October 27th, 2012 - 3.15.4 +! FreeImage now uses LibPNG 1.5.13 +! FreeImage now uses LibRaw 0.14.7 +! FreeImage now uses ZLib 1.2.7 +! FreeImage now uses LibTIFF 4.0.3 +! FreeImage now uses OpenJPEG 1.5.1 +! FreeImage now uses OpenEXR 1.7.1 ++ [Herve Drolon] improved the speed of RAW files detection in FreeImage_GetFileType* functions ++ [Herve Drolon] added JPEG_GREYSCALE load flag to the JPEG plugin (force to load as 8-bit greyscale) ++ [Herve Drolon] added 64-bit RGBA to 24-bit conversion support in FreeImage_ConvertTo24Bits ++ [Carsten Klein] improved the speed of FreeImage_Rescale for FIT_BITMAP & UINT16, RGB[A]16 types ++ [Carsten Klein] improved the speed of FreeImage_ConvertToGreyscale +* [Carsten Klein] updated makefile for building FreeImage with MinGW +* [Herve Drolon] fixed BigTIFF signature validation in FreeImage_GetFileType* functions +* [Carsten Klein] fixed handling of RGB-565 16-bit images (needed for conversion from HBITMAP to FIBITMAP) +* [Herve Drolon] fixed loading of JPEG with invalid IPTC marker +* [Herve Drolon] changed default TIF RowsPerStrips to image height when saving as TIF G3 or TIF G4 (improved compression) +* [Herve Drolon] improved the memory behavior of the RAW plugin (do not allocate huge variables on the stack) +* [Herve Drolon] fixed FreeImage_AllocateT so that it returns NULL with images with a zero width and/or height +* [Herve Drolon] replaced FIUINT64/FIINT64 with standard types UINT64/INT64 +* [Rustam Abdullaev] fixed PNG plugin with saving of transparent monochrome images +* [Floris van den Berg] improved plugin registering when replacing an existing internal plugin with a new equivalent plugin +* [Herve Drolon] fixed a crash when calling FreeImage_GetColorType on a 32-bit RGBA images loaded with the FIF_LOAD_NOPIXELS flag +* [Herve Drolon] fixed FreeImage_SetTransparencyTable falsely setting a dib to 'transparent' when called with a count of 0 +* [Carsten Klein] fixed storing of RGB masks for 16-bit RGB standard images in order to be in a MSDN compatible way +* [Herve Drolon] added an error handling message inside HDR plugin when trying to save an unsupported format +* [Corey Taylor] fixed DDS plugin color channel swapping for RGB color order, when using FREEIMAGE_COLORORDER_RGB color order +* [Herve Drolon] fixed internal TagLib singleton initialization against double-checked locking so that it is multi-thread safe + +March 17th, 2012 - 3.15.3 +! FreeImage now uses LibPNG 1.5.9 +! FreeImage now uses LibTIFF 4.0.1 ++ [Herve Drolon] added new 64-bit data types FIINT64, FIUINT64 ++ [Herve Drolon] added new 64-bit metadata types to FREE_IMAGE_MDTYPE (FIDT_LONG8, FIDT_SLONG8, FIDT_IFD8) ++ [Herve Drolon] added support for 64-bit metadata types to FreeImage_TagToString +* [Herve Drolon] fixed a regression with Fax3/Fax4 TIFF images on 64-bit OS (introduced with FI 3.15.2) +* [Herve Drolon] fixed some gcc 4.4.6 warnings +* [Petr Pytelka] refactored FreeImage_InsertPage and FreeImage_AppendPage +* [Herve Drolon] fixed JP2/J2K plugins with saving of 32-bit dib with a fully opaque layer +* [Herve Drolon] fixed loading of CMYK JPEG when using JPEG_CMYK load flag (need to invert pixels) +* [Herve Drolon] fixed loading of CMYK PSD when using PSD_CMYK load flag + +February 20th, 2012 - 3.15.2 +! FreeImage now uses LibRaw 0.14.5 +! FreeImage now uses LibPNG 1.5.8 +! FreeImage now uses LibJPEG 8d +! FreeImage now uses ZLib 1.2.6 +! FreeImage now uses OpenJPEG 1.5.0 (released version) +! FreeImage now uses LibTIFF 4.0.0 +- [Herve Drolon] removed dependency on LibMNG 1.0.10 (MNG and JNG files are now handled internally) ++ [Herve Drolon] replaced the MNG plugin with a new MNG internal FreeImage plugin (with read support) ++ [Herve Drolon] added a new JNG internal FreeImage plugin (with read/write support) ++ [Christian Heimes] added write support to the TIFF plugin for EXIF_MAIN tags ++ [Herve Drolon] added new Exif maker note tags ++ [Herve Drolon] added TAG_COMPRESSION conversion to FreeImage_TagToString +* [Mylek Grey] enabled the use of multi-component transforms (MCT) in J2K and JP2 saving +* [Herve Drolon] refactored PluginICO in order to correctly support Windows Vista 256x256 icons +* [Herve Drolon] added minor speed improvements to FreeImage_Rescale +* [Herve Drolon] fixed dib allocation failing with very large images (i.e. more than 4GB) +* [Herve Drolon] fixed FreeImage_CloneTag behavior with ASCII data handling +* [Herve Drolon] improved JPEG plugin behavior with very big images +* [Herve Drolon] improved JPEG plugin behavior with C++ exceptions +* [Herve Drolon] fixed loading of palettized PNG with more that 256 palette entries +* [Herve Drolon] fixed a bug inside IFF plugin occuring when loading a 24-bit dib with a palette +* [Herve Drolon] fixed a bug with loading of PNG images containing a cHRM chunk (regression introduced by LibPNG 1.5.4 and fixed by LibPNG 1.5.5) +* [Herve Drolon] allowed loading of PNG with benign errors (such as images with too many IDATs) +* [Mihail Naydenov] fixed some incorrect MIME types returned by FreeImage_GetFIFMimeType +* [Herve Drolon] fixed loading of Exif with bad thumbnail data or with a bad first offset size + +July 25th, 2011 - 3.15.1 +! FreeImage now uses LibRaw 0.13.7 +! FreeImage now uses LibPNG 1.5.4 +! FreeImage now uses LibTIFF 3.9.5 +! FreeImage now uses OpenJPEG 1.5.0 (SVN patch 2011-07-23) ++ [Herve Drolon] added FreeImage_ConvertToRGB16 and updated FreeImage_ConvertToType ++ [Herve Drolon] added RAW_HALFSIZE flag to RAW plugin +* [Herve Drolon] fixed a memory leak in JPEG plugin occuring when loading some corrupted images +* [Eberhard Mattes] improved thread safety behavior inside internal TagLib class +* [Hew How Chee] fixed a bug in FreeImage_EnlargeCanvas when called with negative left and right parameters and bpp <= 4 +* [Herve Drolon] improved memory allocation checking in FreeImage_ConvertTo[Float/RGBF/UINT16] +* [Herve Drolon] allowed loading of TIF with missing bitspersample/samplesperpixel/photometric tags +* [Herve Drolon] fixed FreeImage_AllocateHeaderT against possible malloc overflow +* [Herve Drolon] fixed CUT plugin against heap corruption vulnerability +* [Herve Drolon] fixed BMP plugin for images with a truncated input data stream +* [Herve Drolon] improved PCX format detection in FreeImage_GetFileType* functions +* [Christian Heimes] fixed a TIFF G4 compression bug occuring with gcc-Version 4.1.2 20080704 (Red Hat 4.1.2-50) + +January 24th, 2011 - 3.15.0 +! FreeImage now uses LibRaw 0.13-Beta3 +! FreeImage now uses LibPNG 1.4.5 +! FreeImage now uses LibTIFF 3.9.4 (CVS patch 2011-01-03) +! FreeImage now uses LibJPEG 8c +! FreeImage now uses OpenJPEG 1.4.0 (SVN patch 2011-01-18) +! [Herve Drolon] FreeImage_CloneMetadata now clone resolution info returned by FreeImage_GetDotsPerMeter(X / Y) ++ [Herve Drolon] added loading support for "half float" format to TIF plugin ++ [Herve Drolon] FreeImage_IsTransparent is now independant of FREE_IMAGE_TYPE ++ [Herve Drolon] added FIT_UINT16 to FIT_RGBF conversion to FreeImage_ConvertToRGBF & FreeImage_ConvertToType ++ [Herve Drolon] added FreeImage_ConvertToUINT16 and updated FreeImage_ConvertToType ++ [Mihail Naydenov] added FreeImage_GetThumbnail / FreeImage_SetThumbnail ++ [Mihail Naydenov] added thumbnail support to Exif, JPEG, EXR, PSD, TGA, TIF formats ++ [Mihail Naydenov] added JPEG_BASELINE save flag to the JPEG plugin ++ [Herve Drolon] added new Exif-TIFF tags (PageName, PageNumber, XPosition, YPosition) and Exif WinXP tags ++ [Herve Drolon] added support for 256x256 icon size to PluginICO:Save +* [Domingo Stephan] fixed a compilation error in TARGA plugin when using a big endian OS (OS X 10.6) +* [Christian Heimes] fixed a compilation error with gcc 4.3.x and OpenEXR +* [Eric Fruhinsholz] fixed a crash in JPEG plugin when reading a JPEG with corrupted XMP data +* [Herve Drolon] improved FreeImage_MultigridPoissonSolver for images whose size is a power-of-two +* [Herve Drolon] fixed a crash in PSD plugin when loading a PSD with a CMYK embedded thumbnail +* [Herve Drolon] fixed loading of JPEG images with a not null but zero length IPTC segment (bad files produced by Picasa) +* [Carsten Klein] fixed a bug in FreeImage_ColorQuantizeEx when using FIQ_WUQUANT quantizer +* [Herve Drolon] added support for RGBA[16][F] to FreeImage_IsTransparent +* [Herve Drolon] fixed loading of resolution info in TIFF CMYK images (bug introduced with 3.14.0) +* [Tom May] fixed JPEG plugin crashing on some Exif files containing tags with an invalid tag length +* [Herve Drolon] fixed a crash when loading TIFF images with a TIFFTAG_TRANSFERFUNCTION Exif tag +* [Tom May] removed assertions in PSD plugin, causing crashes on some malformed images in debug mode +* [Mihail Naydenov] fixed a crash in TIFF plugin when reading an uncommon 24-bit palettized file +* [Carsten Klein] fixed a bug in FreeImage_EnlargeCanvas when using the function as a FreeImage_Copy function +* [Herve Drolon] fixed a bug in PluginBMP with loading of OS/2 2.x palettized BMP +* [luispedro] fixed a bug in PluginBMP when reading malformed 16-bit RGB-555 BMP + +August 12th, 2010 - 3.14.1 ++ [Mihail Naydenov] added support for FIF_LOAD_NOPIXELS flag to EXR plugin ++ [Herve Drolon] added support for FIF_LOAD_NOPIXELS flag to CUT, HDR, RAS, ICO, PNM, RAW, BMP, PFM, XPM plugins +* [Eberhard Mattes] fixed memory allocation checking in multipage API +* [Herve Drolon] (compiler options) removed Win32 OpenMP support introduced in 3.14.0 + +August 9th, 2010 - 3.14.0 +! FreeImage now uses OpenEXR 1.7.0 +! FreeImage now uses ZLib 1.2.5 +! FreeImage now uses LibPNG 1.4.3 +! FreeImage now uses LibJPEG 8b +! FreeImage now uses LibTIFF 3.9.4 (CVS patch 2010-07-13) +! FreeImage now uses LibRaw 0.10-Beta3 +! FreeImage now uses OpenJPEG 1.4.0 (SVN patch 2010-04-16) +! [Herve Drolon] FreeImage_AllocateT now builds a default greyscale palette for 8-bit images +! [Volodymyr Goncharov] FreeImage_LoadMultiBitmapFromMemory now supports read/write operations +! [Herve Drolon] FreeImage_OpenMultiBitmapFromHandle now supports read/write operations +! [Herve Drolon] greyscale conversions now use the Rec. 709 formula +! [Mihail Naydenov] saving RGBF images to TIFF no longer use LogLuv encoding (unless you use the TIFF_LOGLUV save flag) ++ [Herve Drolon] added FIT_FLOAT to FIT_RGBF conversion to FreeImage_ConvertToRGBF & FreeImage_ConvertToType ++ [Herve Drolon] added VS 2008 project files ++ [Herve Drolon] added FreeImage_ConvertToFloat ++ [Mihail Naydenov] added RLE saving to the Targa plugin (see flag TARGA_SAVE_RLE) ++ [Volodymyr Goncharov] added FreeImage_SaveMultiBitmapToHandle ++ [Herve Drolon] added FreeImage_SaveMultiBitmapToMemory ++ [Herve Drolon] added new Exif maker note tags ++ [Lucian Sabo] added JPEG_OPTIMIZE to PluginJPEG:Save ++ [Mihail Naydenov] improved support for Exif tag reading in TIFF plugin ++ [Mihail Naydenov] allowed dataWindow with minimal bounds different from zero in OpenEXR plugin ++ [Herve Drolon] added FIMD_EXIF_RAW metadata model ++ [Herve Drolon] JPEG plugin can load & save raw Exif data (see FIMD_EXIF_RAW) ++ [Herve Drolon] added FIF_LOAD_NOPIXELS load flag constant - used to load header & metadata only ++ [Herve Drolon] added FreeImage_HasPixels ++ [Herve Drolon] added FreeImage_FIFSupportsNoPixels ++ [Herve Drolon] added support for FIF_LOAD_NOPIXELS flag to JPEG, PNG, PCD, PCX plugins ++ [Mihail Naydenov] added support for FIF_LOAD_NOPIXELS flag to TGA, PSD, TIFF plugins ++ [Mihail Naydenov] added support for 16-bit image types to FreeImage_Invert ++ [Mihail Naydenov] improved PSD plugin (faster code, added support for CMYK and LAB loading) + added load flags PSD_CMYK & PSD_LAB ++ [Mihail Naydenov] improved TIFF plugin (CMYK 16-bit loading and saving / RGBAF saving) + added TIFF_LOGLUV save flag +* [Herve Drolon] fixed FreeImage_GetFileType behavior with ANI file formats +* [Herve Drolon] fixed loading of JNG with progressive-JPEG formats +* [Mihail Naydenov] fixed loading of TGA with a corrupted rle count +* [Herve Drolon] fixed conversion formula in FreeImage_PreMultiplyWithAlpha +* [Christoph Brill] removed the use of libmng_data.h private API in MNG Plugin +* [phe02sf] fixed handling of bad Exif-GPS data in a Nikon D5000 image +* [Atsuhiro Igarashi] fixed handling of last data block in PluginGIF::Save (sometimes it saves corrupted images) +* [Christian Heimes] fixed saving of G3 & G4 compressed TIFF with 1bpp on 64bit Linux +* [Herve Drolon] fixed long data type being 64-bit on Unix/Linux platforms (use LONG/DWORD instead of long/unsigned long) +* [Herve Drolon] fixed a memory leak in FreeImage_DeletePage +* [Herve Drolon] fixed the loading of RGBZ images in OpenEXR plugin +* [Lucian Sabo] improved conversion from 1-, 4-, 8-bpp transparent images to 32-bpp +* [Roy F.] fixed a bug in FreeImage_EnlargeCanvas (unable to crop an image on the right) +* [Herve Drolon] fixed the loading of Exif with unusual IFD offset value +* [Eberhard Mattes] fixed page numbering info when saving multipage TIFF +* [Herve Drolon] fixed PluginPICT causing an infinite loop on a malformed PICT image +* [Eberhard Mattes] improved memory allocation checking when using the new operator +* [Herve Drolon] (multipage internals) fixed a potential buffer overflow in ReplaceExtension +* [Eberhard Mattes] improved error checking in FreeImage_CloseMultiBitmap + +December 22, 2009 - 3.13.1 +! FreeImage now uses libTIFF 3.9.2 +! FreeImage now uses OpenJPEG 1.3.0 (SVN patch 2009-11-05) +! FreeImage now uses libPNG 1.2.41 ++ [Berend Engelbrecht] added loading of Exif orientation tag in TIFF plugin ++ [Herve Drolon] added decoding support for the old and outdated JPEG-in-TIFF 6.0 format in TIFF plugin ++ [Herve Drolon] added new 'non standard' Exif tags ++ [Herve Drolon] added new Exif makernote tags +* [Herve Drolon] fixed TIF plugin crashing on a malformed TIFF-JPEG compressed image +* [Herve Drolon] fixed MNG plugin crashing on some old mng images +* [Herve Drolon] fixed handling of 2-bit grayscale transparent PNG +* [Herve Drolon] fixed a bug with the compression rate of JP2 and J2K encoders +* [zestony] fixed TIF plugin with the '65535 bytes' pitch size limitation on saving +* [Herve Drolon] fixed handling of PSD files with a non zero file header reserved member +* [Lucian Sabo] PNG plugin now keep transparency when saving 1- or 4-bit transparent images + +September 28th, 2009 - 3.13.0 +! FreeImage now uses LibJPEG 7 +! FreeImage now uses LibRaw-Lite 0.7.2 +! FreeImage now uses libPNG 1.2.40 +! FreeImage now uses libTIFF 3.9.1 +! FreeImage_RotateClassic is deprecated (use FreeImage_Rotate instead) ++ [Herve Drolon] added support for all Photoshop supported color modes to PSD plugin ++ [Herve Drolon] added support for 32-bit to JNG/MNG plugin ++ [Amir Ebrahimi] added loading support for the PICT format ++ [Herve Drolon] added loading support for camera RAW formats (using LibRawLite wrapper for dcraw) ++ [Mihail Naydenov] added UNICODE functions FreeImage_JPEGTransformU and FreeImage_JPEGCropU ++ [Carsten Klein] added FreeImage_OpenMultiBitmapFromHandle ++ [Carsten Klein] added FreeImage_FillBackground ++ [Carsten Klein] added FreeImage_EnlargeCanvas ++ [Carsten Klein] added FreeImage_AllocateEx / FreeImage_AllocateExT ++ [Mihail Naydenov/Herve Drolon] added FreeImage_TmoReinhard05Ex ++ [Herve Drolon] added FIT_RGBA16 to FIT_RGBF conversion to FreeImage_ConvertToRGBF ++ [Herve Drolon] added FreeImage_Rotate (support for most image types, support background color) +* [Christian Heimes] fixed function prototypes to use a void argument when no argument exist +* [Herve Drolon] fixed RGB color ordering on Intel macs +* [Herve Drolon] FreeImage_RotateClassic now keep transparency when applied to 8-bit images +* [Herve Drolon] fixed handling of transparency info in FreeImage_Copy +* [Herve Drolon] fixed a normalization error in FreeImage_GetAdjustColorsLookupTable +* [Herve Drolon] fixed invalid Exif rotation in PluginJPEG for orientation cases 2 and 4 +* [Mihail Naydenov / Carsten Klein] fixed compilation issues with MinGW32 +* [Mihail Naydenov] improved the loading speed of all targa images +* [Herve Drolon] FreeImage_TagToString now handles the Exif UserComment tag + +April 14th, 2009 - 3.12.0 +! FreeImage now uses libPNG 1.2.35 +! FreeImage now uses libTIFF 3.9.0beta (CVS patch 2009-02-12) +! FreeImage now uses OpenJPEG 1.3.0 (SVN patch 2008-08-21) +! [Herve Drolon] FreeImage_CloneMetadata no longer clone the FIMD_ANIMATION metadata (this was causing problems when saving to GIF format) ++ [Herve Drolon] added full support for the PFM format ++ [Herve Drolon] added JPEG_EXIFROTATE load flag to the JPEG plugin ++ [Herve Drolon] added 16-bit RGB(A) and float RGB(A)F support to FreeImage_GetChannel / FreeImage_SetChannel ++ [Herve Drolon] added src FIT_RGBA16 to dst 32-bit FIT_BITMAP conversion to FreeImage_ConvertToType +* [Carsten Klein] FreeImage_Copy now copies transparency info, resolution info, ICC profile and metadata +* [Carsten Klein] check for negative top/left values in FreeImage_Paste +* [Christian Heimes] changed exceptions with a "catch(char *text)" to a "catch(const char *text)" to make GCC 4.1 happy +* [Deif Lou] fixed a bug in FreeImage_SetTransparentIndex +* [Thomas Maiwald] BMP plugin: on saving, fixed correct setting of bfSize BMP file header for palettized images +* [Timothy Lee] fixed handling of frame disposal in GIF_PLAYBACK mode (GIF plugin) +* [Herve Drolon] fixed handling of Exif Olympus Type 2 maker notes (not yet supported but now safely ignored) +* [Rich Geldreich] fixed DXT1 color endpoint precision problem in DDS plugin +* [Mihail Naydenov] improved loading speed of 24-bit targa images +* [Eugene Golushkov] improved big endian / little endian swapping functions +* [Carsten Klein/Jean-Philippe Goerke] improved FreeImage_SetMetadata / FreeImage_GetMetadata accessors +* [Christian Ruppert] improved Linux Makefiles +* [Eugene Golushkov] fixed PluginBMP alignment bug while saving 16 or 24bit BMP on big endian or Apple machines + +July 28th, 2008 - 3.11.0 +! FreeImage now uses libTIFF 3.9.0beta (CVS patch 2008-05-24) +! FreeImage now uses OpenJPEG 1.3.0 (SVN patch 2008-05-22) +! FreeImage now uses libMNG 1.0.10 +! FreeImage now uses libPNG 1.2.29 ++ [Yves Schmid] added 48-bit RGB to 32-bit conversion support in FreeImage_ConvertTo32Bits ++ [Aaron Shumate] added RGB16-to-BITMAP and All-to-RGBF conversion support in FreeImage_ConvertToType ++ [Benjamin English] added a new OpenGL sample to FreeImage/Examples ++ [Lucian Sabo] added new compression flags to the PNG plugin ++ [Lucian Sabo] added new compression flags to the JPEG plugin (chroma subsampling options) ++ [Noam Gat] added support for SGI grayscale + alpha pics to SGI plugin ++ [Herve Drolon] added FreeImage_CloneMetadata ++ [Herve Drolon] added loading support for Windows Vista icons in ICO Plugin ++ [Herve Drolon] added loading and saving support for RGBF images to the TIF plugin (using the LogLuv codec) +* [Will Bryant] fixed makefile for MacOSX Tiger and Leopard +* [Maria Gullickson] fixed a 'divide by 0' error in PNM plugin and FreeImage_Rescale function +* [Yves Schmid] fixed a bug with Exif metadata reading in TIFF images +* [Herve Drolon] fixed some possible 64-bit portability issues with pointer calculations +* [wangyn] fixed a bug with transparency handling of indexed images in PNG plugin +* [Martin Dyring-Andersen] fixed a bug with GIFinfo structure initialization in GIF plugin +* [Noam Gat] fixed a bug in SGI plugin: when the file reports as two-dimensional, the height factor does not get loaded +* [Herve Drolon] added error messages in FreeImage_Load(U) / FreeImage_Save(U) in case of bad filenames +* [Scott Smith/Herve Drolon] added missing IPTC tags and renamed some tag names to be compatible with ExifTool naming convention +* [Martin Dyring-Andersen] fixed a crash problem with images containing exif data emitted by Picassa +* [Herve Drolon] removed RGBA to RGB transparent conversion in EXR plugin +* [Glenn Pierce] improved the speed of FreeImage_FlipHorizontal +* [Carsten Klein] fixed 65535 pixels width/height limitation in FreeImage_Paste + +November 19th, 2007 - 3.10.0 +! FreeImage now uses libTIFF 3.9.0beta (CVS patch 2007-10-05) +! FreeImage now uses OpenJPEG 1.2.0 (SVN patch 2007-07-13) +! FreeImage now uses OpenEXR 1.6.1 +! FreeImage now uses libPNG 1.2.23 +! FreeImage now hides its internal functions and internal libraries when compiled with gcc +- [Herve Drolon] removed VS C+ 6.0 project files : this IDE is no longer supported because of OpenEXR ++ [Herve Drolon] added VS 2005 project files ++ [Herve Drolon] added full support for the OpenEXR format ++ [Herve Drolon] added full support for the JPEG-2000 format ++ [Herve Drolon] added FreeImage_TmoFattal02 tone mapping operator ++ [Ryan Rubley] added support for RGB vs BGR regardless of endian ++ [Herve Drolon] added FreeImage_MultigridPoissonSolver ++ [Carsten Klein] added FreeImage_PreMultiplyWithAlpha ++ [Carsten Klein] added __stdcall version of FreeImage_OutputMessage ++ [Carsten Klein] added new palette and color manipulation functions (see below) : + added FreeImage_SetTransparentIndex + added FreeImage_GetTransparentIndex + added FreeImage_GetAdjustColorsLookupTable + added FreeImage_AdjustColors + added FreeImage_ApplyColorMapping + added FreeImage_SwapColors + added FreeImage_ApplyPaletteIndexMapping + added FreeImage_SwapPaletteIndices +* [Herve Drolon] fixed a bug in TIFF plugin when reading 8-bit + 8-bit alpha images +* [Herve Drolon] fixed a bug in TIFF plugin when reading images with uncommon bitdepths +* [rodrigo] fixed FreeImage exception handling under gcc (added -fexceptions to gcc compiler flags) +* [Martin Dyring-Andersen] fixed GIF plugin crashing on some corrupted files +* [Herve Drolon] fixed a bug with RLE encoding for 8-bit BMP images +* [Herve Drolon] fixed GPS metadata being skipped when reading metadata in Exif images +* [Herve Drolon] fixed a bug when reading OS/2 BMP images with a negative height +* [Ryan Rubley] fixed a bug with loading of GIFs with large amounts of solid color areas +* [Ryan Rubley] fixed OS X compile error in BitmapAccess.cpp +* [Herve Drolon] fixed a bug in FreeImage_Paste when pasting non-standard image types +* [Herve Drolon] saving 1-bit TIF with the TIFF_CCITTFAX3 flag is now compliant with the TIFF Class F specification +* [Carsten Klein] fixed topdown parameter in FreeImage_ConvertFromRawBits and FreeImage_ConvertToRawBits being handled in reverse +* [Herve Drolon] fixed a bug when reading some RLE-4 encoded BMP data +* [Carsten Klein] conversion from 1-bit to 32-bit now keep possibly present transparency + +February 11th, 2007 - 3.9.3 +! FreeImage now uses libPNG 1.2.16 +! [Ryan Rubley/Ryan Davis] reworked the MacOSX makefile in order to fully support Universal Binary builds of FreeImage +! [Herve Drolon] makefiles are now generated from VS2003 project files instead of VS6 project files +! [Herve Drolon] changed JPEG load/save flag option values ++ [Herve Drolon] added support for RGBAF images to FreeImage_ConvertToRGBF ++ [Herve Drolon] FreeImage_Paste now works with any bitmap type ++ [Herve Drolon] added full support for 64-bit RGBA images to the PNG and TIFF plugins ++ [Jascha Wetzel] added JPEG downsampling feature to PluginJPEG:Load +* [Thomas Chmielewski] fixed a bug in FreeImage_Dither and Bayer dithering, added FID_BAYER16x16 +* [Raphael Gaquer] greatly improved the speed of the GIF encoder +* [Herve Drolon] fixed saving of metadata in the PNG plugin +* [rampelstinskin] fixed transparency table to alpha channel conversion for 4-bit images in FreeImage_ConvertTo32Bits +* [Scott Smith] added missing IPTC tag named "Country/PrimaryLocationCode" +* [Herve Drolon] changed #include by #include in FreeImage.h (needed by Solaris 9) +* [Pierre Arnaud] fixed the use of FreeImage in low memory condition by checking some returned values of the malloc function +* [Pierre Arnaud] fixed TagLib::getTagFieldName not being thread safe + +October 30th, 2006 - 3.9.2 +! FreeImage now uses libTIFF 3.8.2 (with patch 2006-10-13) ++ [Herve Drolon] added full support for 16-bit greyscale and 48-bit RGB to the PNM plugin ++ [Herve Drolon] added IPTC writing support to JPEG & TIFF plugins ++ [Herve Drolon] added new Exif maker note tags ++ [Herve Drolon] added FreeImage_JPEGCrop ++ [Thorsten Radde] added support for 8-bit palettized bitmaps in FreeImage_RotateClassic ++ [Matt Rice] added automatic call to FreeImage_Initialise / FreeImage_DeInitialise when using FreeImage as a .so ++ [Martin Dyring-Andersen] added FreeImage_LoadMultiBitmapFromMemory to the multi-page API ++ [Herve Drolon] added support for tiled TIFF images +* [Carsten Klein] fixed a bug in FreeImage_SetMetadata occuring when deleting a tag +* [Herve Drolon] fixed a bug in PNG plugin when reading Macromedia 'false' PNG files +* [Thorsten Radde] added resolution support to PluginPSD +* [Ryan Rubley] fixed a bug in PluginGIF occuring with interlaced GIF +* [Ryan Rubley] fixed a bug in the multipage cache mechanism (internal FreeImage_FindBlock function) +* [Thorsten Radde] fixed a stack corruption in TIFF plugin occuring when reading exif tags +* [checkered] fixed a bug in the multipage cache mechanism causing VS2005 to crash on multipage files +* [Herve Drolon] fixed a bug with transparency support of 1- and 4-bit images +* [Roar Flolo] fixed a bug in PSD plugin when reading non compressed RGB images (alpha channel initialization) +* [Nicolas Hatier] fixed a bug in PluginGIF when using the GIF_PLAYBACK flag +* [Herve Drolon] fixed a bug in TIFF plugin when saving 8-bit images using LZW with differenciation +* [Herve Drolon] fixed 64-bit compilation issue with LibPNG and assembler code + +July 16th, 2006 - 3.9.1 +* [Ryan Rubley] fixed a bug in PluginGIF plugin causing FreeImage to crash on malformed GIF files + +July 6th, 2006 - 3.9.0 +! FreeImage now uses libPNG 1.2.12 +! FreeImage now uses libTIFF 3.8.2 (with patch 2006-06-24) +! FreeImage_Allocate/FreeImage_Allocate now set the resolution to 72 dpi instead of 0 ++ [Herve Drolon/Petr Pytelka] added a raw FAX G3 format loader ++ [Herve Drolon] added support for most image types to FreeImage_Rescale ++ [Herve Drolon] added FreeImage_MakeThumbnail ++ [Herve Drolon] added support for 64-bit images to FreeImage_ConvertTo32Bits ++ [Herve Drolon] added support for Exif tags to TIF plugin (read only) ++ [Herve Drolon] added FreeImage_ReadMemory ++ [Herve Drolon] added FreeImage_WriteMemory ++ [Herve Drolon] added new Exif maker note tags ++ [Sherman Wilcox] added a SGI file format loader ++ [Herve Drolon] added support for separated images to PluginTIFF ++ [Herve Drolon] added support for progressive-JPEG saving to PluginJPEG +* [Carsten Klein] FreeImage_Dither and FreeImage_Threshold now work with palettized 8-bit dib +* [Christophe Petit] fixed a bug in FreeImage_GetFIFFromFilenameU occuring with files without extension +* [Leigh Brasington] fixed a bug in PluginGIF causing FreeImage not working on Win/98/ME +* [Herve Drolon] fixed a bug in PluginTIFF with writing of JPEG-in-TIFF files +* [Jojakim Stahl] fixed a bug occuring with 4-bit PCX files +* [Sandor Szalacsi] fixed a bug in FreeImage_SetBackgroundColor (bkgnd clearing) +* [Petr Pytelka] fixed PluginTIFF::_tiffSizeProc failing on some images +* [Sherman Wilcox] fixed a bug in DDS plugin when loading images whose size is not a multiple of 4 +* [Sherman Wilcox] fixed a memory leak in PluginDDS::LoadDXT_Helper +* [Sherman Wilcox] fixed DDS plugin bad behavior with invalid DDS files (such as files with zero length) +* [Floris van den Berg] fixed a memory leak in the MultiPage cache mechanism +* [Herve Drolon] replaced WIN32 #define by _WIN32 #define as this is needed by VS2005 +* [Herve Drolon] fixed a VS2005 error in FreeImage_DeletePage +* [Petr Supina] fixed a pow(long,long) function not being standard ANSI C/C++ +* [Petr Supina] fixed FreeImage_FindBlock function not being standard ANSI C/C++ +* [Olaf Stoyke] added support for 64-bit Linux OS +* [Craig Stark] fixed FreeImage support on Intel based Mac OS +* [Herve Drolon] fixed PluginTIFF failing on bad fax tiff images (bad images are now loaded 'as is') +* [Zack Simpson] fixed a bug occuring in rare situations with FreeImage_Aligned_Malloc + +September 5, 2005 - 3.8.0 +! FreeImage now uses libTIFF 3.7.3 +! FreeImage now uses ZLib 1.2.3 ++ [Herve Drolon] added support for 48-bit images to FreeImage_ConvertTo24Bits ++ [Herve Drolon] added FreeImage_ConvertToGreyscale ++ [Herve Drolon] added support for 16-bit greyscale images to FreeImage_ConvertTo8Bits ++ [Petr Pytelka] added UNICODE functions (see below) + added FreeImage_LoadU + added FreeImage_SaveU + added FreeImage_GetFIFFromFilenameU + added FreeImage_GetFileTypeU ++ [Herve Drolon] FreeImage_Copy now works with any bitmap type ++ [Herve Drolon] added support for 1-bit images to FreeImage_Paste +* [Ryan Rubley] fixed PluginGIF failing to link on some broken gcc versions +* [Karl-Heinz Bussian] fixed a bug in LookupX11Color/LookupSVGColor with handling of grey color names +* [Herve Drolon] FreeImage_Dither now uses FreeImage_ConvertToGreyscale and handles 4/8-bit palletized images +* [Herve Drolon] FreeImage_Threshold now uses FreeImage_ConvertToGreyscale and handles 4/8-bit palletized images +* [Craig Hockenberry] fixed PluginGIF::Save swapping the byte order for the height on big endian machines (e.g. PPC on Mac OS X.) +* [Herve Drolon] fixed a bug in JPEG plugin when reading Exif maker notes from images produced by Nikon Editor +* [Herve Drolon] fixed a bug in BMP plugin when reading some malformed RLE8 bmp +* [Herve Drolon] fixed a bug in RAS plugin when loading 8-bit palettized images with less than 256 colors +* [Herve Drolon] fixed a bug in FreeImage_Rescale with 16-,48-,64-bit images +* [Herve Drolon] fixed a bug in the ICC profiles API when loading profile-less CMYK TIFF +* [Herve Drolon] 4-bit PNG are now loaded as 4-bit and no longer converted to 8-bit +* [Greg Ng] fixed a bug in FreeImage_ConvertToRGBF (FIT_BITMAP -> FIT_RGBF conversion) + +May 7, 2005 - 3.7.0 +! FreeImage now uses libTIFF 3.7.2 +! [Ryan Rubley] improved FreeImage_OpenMultiBitmap ++ [Detlev Vendt] added FreeImage_ZLibGUnzip ++ [Herve Drolon] added new image data types FIT_RGB16, FIT_RGBA16, FIT_RGBF, FIT_RGBAF ++ [Herve Drolon] FreeImage_FlipHorizontal & FreeImage_FlipVertical now work with any bitmap type ++ [Herve Drolon] added conversions to float and double in FreeImage_ConvertToType ++ [Herve Drolon] added FreeImage_ConvertToRGBF ++ [Herve Drolon] added support for 16-, 48- and 96-bit images to FreeImage_Rescale ++ [Ryan Rubley] added FreeImage_ColorQuantizeEx ++ [Ryan Rubley] added FIMD_ANIMATION and FIDT_PALETTE ++ [Ryan Rubley] added brand new PluginGIF with full animation multipage and metadata support ++ [Herve Drolon] added support for FIC_MINISWHITE 8-bit images to FreeImage_Rescale ++ [Herve Drolon] added HDR (High Dynamic Range) format (loader & writer) ++ [Herve Drolon] added support for 48-bit images in TIFF plugin ++ [Herve Drolon] added support for 48-bit images in PNG plugin ++ [Herve Drolon] added tone mapping operators (see below) ++ added FreeImage_ToneMapping ++ added FreeImage_TmoDrago03 ++ added FreeImage_TmoReinhard05 ++ [Petr Pytelka] added FreeImage_JPEGTransform +* [Herve Drolon] allowed loading of corrupted JPEG with a premature end of file +* [Herve Drolon] fixed a memory leak with loading of exif JPEG images +* [Detlev Vendt] changed some 'pointer-to-int' casts to 'pointer-to-long' for 64bit machines +* [Ryan Rubley] fixed a memory leak in the multipage API +* [Ryan Rubley] updated VB6 wrapper generation for new functions +* [Herve Drolon] fixed incorrect behavior when reading JPEG comments containing special characters +* [Herve Drolon] fixed incorrect behavior when reading JPEG ICC profiles with a size greater than 64 KB +* [Herve Drolon] fixed a bug in TIFF plugin when loading malformed multipage TIFF +* [Herve Drolon] fixed PluginTIFF not being thread safe + +February 20, 2005 - 3.6.1 +* [Ryan Rubley] fixed a memory leak in the metadata API +* [luedi] improved the robustness of FIBITMAP allocations + +February 13, 2005 - 3.6.0 +! FreeImage now uses libMNG 1.0.9 +! [Herve Drolon] improved the speed of FreeImage_Rescale +! [Herve Drolon] improved FreeImage_RotateClassic (more compact code, a little faster) +! [Herve Drolon] improved the metadata API using tag accessors ++ [Detlev Vendt] added LZW support to PluginGIF:Save ++ [Herve Drolon] added VS.Net 2003 project files ++ [Herve Drolon] added VERSIONINFO resource to the DLL ++ [Herve Drolon] added support for CMYK JPEG on loading ++ [Petr Supina] added 16-bytes alignment to FIBITMAP palette and pixels starting address ++ [Petr Supina] added support for MMX/SSE2 code in LibJPEG (based on Mozilla/Firefox code) ++ [Herve Drolon] added TIFF_JPEG compression flag to the TIFF plugin ++ [Detlev Vendt] added FreeImage_ZLibGZip ++ [Detlev Vendt] added FreeImage_ZLibCRC32 +* [Detlev Vendt] fixed PluginPNG not being thread safe +* [Herve Drolon] fixed compiler warning C4018 occuring with VS.Net 2003 + +December 29, 2004 - 3.5.3 +! FreeImage now uses ZLib 1.2.2 +! FreeImage now uses libPNG 1.2.8 +! FreeImage now uses libTIFF 3.7.1 +! [Herve Drolon] improved FreeImage_RotateClassic +! [Detlev Vendt] improved FreeImage_Rescale (more compact code, preserving 8-bpp colors) ++ [Herve Drolon] added support for transparency saving in ICO plugin ++ [Herve Drolon] added support for 1-bit images to FreeImage_RotateClassic ++ [Herve Drolon] added FreeImage_SetDotsPerMeterX and FreeImage_SetDotsPerMeterY +* [Nan Feng] fixed memory leak in FreeImage_DeleteTag (internal stuff) +* [Nigel Stewart] added conditional #pragma with #ifdef _MSC_VER / #endif +* [Herve Drolon] fixed the '65536 lines' limit on loading in PNM plugin + +November 27th, 2004 - 3.5.2 +* [Herve Drolon] fixed a second bug in FreeImage_Clone function + +November 26th, 2004 - 3.5.1 ++ [Riley McNiff] added FreeImage_ConvertTo4Bits +* [Herve Drolon] fixed a buffer overrun with some ILBM images +* [Riley McNiff] fixed a potential problem when reading TIFF resolution info +* [Dimitar Atanasov] fixed a bug in FreeImage_Clone function +* [Dimitar Atanasov] fixed several bugs in TIFF plugin + +November 1st, 2004 - 3.5.0 +! FreeImage now uses libPNG 1.2.7 +! FreeImage now uses libTIFF 3.7.0 +! FreeImage now uses libMNG 1.0.8 +! [Herve Drolon] improved TIFF LZW compression using a predictor +! [Detlev Vendt] FreeImagesPlus: corrected references to FreeImage.h and FreeImage.lib ++ [Herve Drolon] added support for loading/saving of 8-bit transparent TIFF ++ [Riley McNiff] added support for 4-bit dib in FreeImage_Paste ++ [Herve Drolon] added support for memory IO streams (see below) ++ added FreeImage_OpenMemory ++ added FreeImage_CloseMemory ++ added FreeImage_LoadFromMemory ++ added FreeImage_SaveToMemory ++ added FreeImage_TellMemory ++ added FreeImage_SeekMemory ++ added FreeImage_AcquireMemory ++ added FreeImage_GetFileTypeFromMemory ++ [Petr Pytelka] added FreeImage_GetFIFMimeType to the plugins function list ++ [Herve Drolon] added ICC profile support to JPEG plugin ++ [Herve Drolon] added support for metadata (see below) ++ added FreeImage_SetMetadata ++ added FreeImage_GetMetadata ++ added FreeImage_GetMetadataCount ++ added FreeImage_TagToString ++ added FreeImage_FindFirstMetadata ++ added FreeImage_FindNextMetadata ++ added FreeImage_FindCloseMetadata +* [Riley McNiff] fixed a bug with FreeImage_SetPixelIndex and 4-bit images +* [Petr Pytelka] fixed returned value in FreeImage_CloseMultiBitmap +* [Petr Pytelka] fixed index of new page in FreeImage_InsertPage +* [Aaron Shumate] fixed a minor bug in PNG plugin +* [Aaron Shumate] fixed a bug in IFF plugin (odd-length chunks) +* [Rupert Hewitt] fixed FreeImage not compiling on National Instruments Cvi Ccompiler +* [Herve Drolon] fixed a bug in IFF plugin (ILBM data) +* [Fred Harju] added a Makefile for Solaris 9 +* [Roddy Pratt] fixed FreeImage not linking under Borland C++ Builder +* [Vadim Alexandrov] fixed a memory leak in the multipage API +* [Herve Drolon] fixed a bug with DDS plugin behaviour on Big Endian OS +* [Herve Drolon] fixed a bug with conversion of JPEG resolution info on saving + +July 8th, 2004 - 3.4.0 +! [Jim Keir] improved FreeImage_FlipVertical function +! [Herve Drolon] LZW compression is now enabled in FreeImage ++ [Karl-Heinz Bussian] added constants to FreeImage.h to get at compile time the library version ++ [Karl-Heinz Bussian] added color lookup functions for X11 and SVG ++ [Herve Drolon] added TIFF tags TIFF_CCITTFAX3, TIFF_CCITTFAX4 and TIFF_LZW ++ [Detlev Vendt] added support for CMYK TIFF files with alpha channel ++ [Detlev Vendt] added (re-introduction of) PluginGIF +* [Herve Drolon] fixed a bug with loading of FAX TIFF images (introduced with LibTIFF 3.6.1) +* [Herve Drolon] fixed a bug in Floyd-Steinberg dithering algorithm +* [Herve Drolon] fixed a bug in Targa plugin save function +* [Herve Drolon] fixed a bug in FreeImage_AdjustCurve function +* [Ryan Rubley] fixed a bug with FreeImage_Rescale's filters accuracy +* [Ryan Rubley] fixed a bug in NN quantizer +* [Herve Drolon] fixed a bug with TIFF files containing additional Photoshop alpha channels +* [James Rossfeld] fixed a memory leak with some PSD images +* [Herve Drolon] fixed a bug with saving of 32-bit non transparent PNG images +* [Alexandr Zamaraev] fixed FreeImage not compiling with mingw32 +* [Herve Drolon] fixed FreeImage not compiling with VC.NET (pow function needs casts) + +May 2, 2004 - 3.3.0 +! [Ryan Rubley] FreeImage has been ported to MacOSX and should also work on other big endian processors ++ [Ryan Rubley] rewrote XPM plugin (better load support) and added save support ++ [Ryan Rubley] added ICO_MAKEALPHA flag to ICO plugin ++ [Ryan Rubley] Set/GetPixelColor now works with 16-bit pixels (555 or 565) ++ [Herve Drolon] PNG plugin now supports loading and saving of unsigned 16-bit greyscale images +* [Herve Drolon] fixed a bug with loading of 8-bit and 16-bit PNG with a 8-bit alpha channel +* [Herve Drolon] fixed a bug in NN quantizer algorithm with handling of 4-byte boundary alignment. +* [Herve Drolon] fixed a bug in PluginIFF Validate function +* [Herve Drolon] fixed a minor design issue in FreeImage_GetFIFFromFormat +* [Brad Schick] fixed some compiler warnings with VC++ 7.1 +* [Herve Drolon] fixed a bug with saving of 8-bit palettized images to 24-bit JPEG (channel inversion) + +March 16, 2004 - 3.2.1 +! [Volker Gärtner] improved the DDS plugin +! [Herve Drolon] FreeImage_Rescale now works on 8-, 24- and 32-bit images +! [Herve Drolon] FreeImage_Copy now works on 1-, 4-, 8-, 16-, 24- and 32-bit images +* [Floris van den Berg] fixed a bug in the MultiPage cache mechanism +* [Herve Drolon] fixed a bug with loading/saving of 8-bit transparent tga images +* [Herve Drolon] fixed a bug with loading of 1-bit TIFF (introduced with LibTIFF 3.6.1) + +February 18, 2004 - 3.2.0 +! FreeImage now uses libTIFF 3.6.1 ++ [Herve Drolon] added FreeImage_HasBackgroundColor ++ [Herve Drolon] added FreeImage_GetBackgroundColor ++ [Herve Drolon] added FreeImage_SetBackgroundColor ++ [Herve Drolon] added FreeImage_Composite ++ [Herve Drolon] added ICC profile support to PNG plugin ++ [Herve Drolon] added background color support to PNG plugin ++ [Volker Gärtner] added support for DDS format (loader) +* [Steve Johnson] improved FreeImage_OpenMultiBitmap/FreeImage_CloseMultiBitmap +* [Steve Johnson] fixed a bug in FreeImage_InsertPage +* [Herve Drolon] fixed a bug with JPEG compressed TIFF (red/blue swapping) +* [Herve Drolon] fixed a bug in PluginTarga where 8-bit images were saved incorrectly + +January 26, 2004 - 3.1.0 +! FreeImage now uses ZLib 1.2.1 ++ [Herve Drolon] added support for integer, real and complex image types (see below) ++ added FREE_IMAGE_TYPE enum ++ added FreeImage_AllocateT ++ added FreeImage_GetImageType ++ added FreeImage_FIFSupportsExportType ++ added FreeImage_ConvertToStandardType ++ added FreeImage_ConvertToType ++ added load/save support of all image types to TIFF plugin ++ [Peter Lemmens] added a Validate function to TARGA plugin ++ [Herve Drolon] added FreeImage_GetPixelIndex / FreeImage_SetPixelIndex ++ [Herve Drolon] added FreeImage_GetPixelColor / FreeImage_SetPixelColor ++ [Herve Drolon] added FreeImage_GetComplexChannel / FreeImage_SetComplexChannel +* [Serge Ivanchenko] TIFF_DEFLATE compression is now enabled in TIFF plugin +* [Herve Drolon] fixed a bug in NeuQuant color reduction algorithm + +November 16, 2003 - 3.0.4 +* [Tobias Persson] fixed FreeImage_GetChannel not working with FICC_ALPHA channel +* [Detlev Vendt] fixed a minor bug with PNG plugin and PNG_IGNOREGAMMA flag +* [Detlev Vendt] fixed a memory leak in PNG plugin save routine +* [Detlev Vendt] fixed JPEG validation problem with .jpe files +* [Ryan Rubley] added Source/LibTIFF/tif_extension.c to LibTIFF (needed for MacOSX) +* [Herve Drolon] improved error handling in TIFF plugin ++ [Karl-Heinz Bussian] added FreeImage_IsLittleEndian ++ [Karl-Heinz Bussian] added JPEG save support for 8-bit miniswhite bitmaps (transparent conversion to minisblack) ++ [Karl-Heinz Bussian] FreeImage_GetColorType now recognizes 8-bit FIC_MINISWHITE images +! [Herve Drolon] FreeImage_Rescale now supports rescaling of 32-bit images with alpha channel +! [Herve Drolon] FreeImage_Invert now supports inversion of 32-bit images with alpha channel +! [Herve Drolon] FreeImage_AdjustCurve now supports working with FICC_ALPHA channel + +November 2, 2003 - 3.0.3 +* [Ryan Rubley] improved makefile for Linux +* [Ryan Rubley] fixed FreeImage not compiling under MacOSX +* [Detlev Vendt] fixed still present inconsistancy with 32bpp transparency handling +* [Herve Drolon] fixed incorrect loading of 4-bit greyscale images in TIFF plugin + +October 27, 2003 - 3.0.2 +! FreeImage now uses libMNG 1.0.6 +* [Herve Drolon] fixed a boolean test in PluginCUT returning always false +* [Herve Drolon] fixed a warning in PluginIFF generated with g++ +* [Linus Tan] fixed a bug in FreeImage_Copy +* [Herve Drolon] fixed FreeImage not compiling under Linux (thanks to Michal) + +October 20, 2003 - 3.0.1 + +! FreeImage now uses libTIFF 3.6.0 +* [Detlev Vendt] fixed incorrect definition of the FREE_IMAGE_FORMAT enum +* [Detlev Vendt] fixed a potential crash problem with Load / Save routines +* [Herve Drolon] fixed incorrect loading of 16-bit greyscale images in TIFF plugin +* [Dennis Lim] fixed a memory leak in Floyd & Steinberg dithering routine +* [Herve Drolon] fixed a bug in BMP loader (incorrect loading of RLE4 bmp) +* [Detlev Vendt] fixed some inconsistancy with 32bpp transparency handling ++ [David Boland] added a C# wrapper +// Linux compatibility issues +- [Michal Novotny] removed the round function in Utilities.h +! [Herve Drolon] replaced the round routine by the clamp routine in PluginPCD ++ [Herve Drolon] added _itoa version in Utilities.h +* [Michal Novotny] fixed untyped consts not accepted by g++ in PluginBMP + +September 8, 2003 - 3.0.0 +- [Herve Drolon] removed deprecated functions +- [Herve Drolon] removed deprecated flags (TARGA_LOAD_RGB555, ICO_*, except ICO_DEFAULT) +- [Herve Drolon] removed the FreeImage pointer table (internal stuff) ++ [Herve Drolon] added a C++ wrapper ++ [Herve Drolon] added the FreeImage Toolkit (see below) ++ added FreeImage_Rescale ++ added FreeImage_RotateClassic ++ added FreeImage_RotateEx ++ added FreeImage_FlipHorizontal ++ added FreeImage_FlipVertical ++ added FreeImage_Invert ++ added FreeImage_AdjustCurve ++ added FreeImage_AdjustGamma ++ added FreeImage_AdjustBrightness ++ added FreeImage_AdjustContrast ++ added FreeImage_GetHistogram ++ added FreeImage_GetChannel ++ added FreeImage_SetChannel ++ added FreeImage_Copy ++ added FreeImage_Paste ++ [Karl-Heinz Bussian] added XPM loader ++ [Karl-Heinz Bussian] added flags parameter to FreeImage_CloseMultiBitmap ++ [Karl-Heinz Bussian] added JPEG save support for 8-bit palettized bitmaps (transparent conversion to 24-bit) ++ [Herve Drolon] added interface to ZLib compression functions ++ [Herve Drolon] added ICO format to the multipage API (loader & writer) ++ [Herve Drolon] added a MIME type to all plugins +* [Karl-Heinz Bussian] fixed incorrect conversion from 1-bit FIC_MINISWHITE bitmaps to 8-bit +* [Herve Drolon] fixed a bug in FreeImage_CloseMultiBitmap +* [Herve Drolon] fixed a potential memory leak in conversion functions (8-, 24-, 32-bit) +* [Robert Walker] fixed incorrect conversion from 16-bit to 24-bit and 16-bit to 32-bit +* [blurble] fixed TIFF validate signature problem (3DS files were recognized as TIFF) +* [Kurt Jankowski-Tepe] fixed FreeImage not compiling on MinGW / LCC WIN32 +* [Jani Peltonen] fixed bug in PluginTARGA where 32-bit bitmaps are not always correctly flipped +* [Detlev Vendt] fixed a bug with TIFF (memory leak with ICC profiles) + +May 25, 2003 - 2.6.1 ++ [Detlev Vendt] added FIC_CMYK to FREE_IMAGE_COLOR_TYPE ++ [Detlev Vendt] added ICC profile support to the library (see below) ++ added FreeImage_GetICCProfile ++ added FreeImage_CreateICCProfile ++ added FreeImage_DestroyICCProfile ++ added FIICCPROFILE & FIICCPROFILE flags ++ added plugin function FreeImage_FIFSupportsICCProfiles ++ [Detlev Vendt] added ICC profile support for TIFF ++ [Herve Drolon] added XBM (X11 Bitmap Format) support : loading +* [Herve Drolon] fixed incorrect IFF file detection (thanks Floris) +* [Herve Drolon] fixed incorrect conversion from 1/4-bit greyscale bitmaps to 8-bit +* [Herve Drolon] fixed a bug in TIFF writer when saving 1,4,8 bit dib (introduced in 2.6.0, sorry) +* [Herve Drolon] fixed a palette problem in TIFF loader when loading 1-bit b & w images +* [Herve Drolon] improved FreeImage_Dither to handle any bitdepth + +May 5th, 2003 - 2.6.0 +! FreeImage now uses libPNG 1.2.5 +! FreeImage now uses libMNG 1.0.5 +! [Markus Loibl] ActiveX wrapper is now distributed in a separate release (since 2.5.5) +! [Herve Drolon] the function FreeImage_Free is now deprecated : use FreeImage_Unload instead +! [Herve Drolon] updated the generic samples and removed deprecated functions ++ [Detlev Vendt] added CMYK support to TIFF save function ++ [Detlev Vendt] added TIFF_SAVE_CMYK flag constant ++ [Detlev Vendt] added 32-bit support (with transparency handling) to TIFF plugin ++ [Herve Drolon] added FreeImage_Threshold ++ [Herve Drolon] added FreeImage_Dither ++ [Herve Drolon] added FREE_IMAGE_DITHER parameter to FreeImage_Dither +* [Herve Drolon] improved error handling in PluginMNG +* [Herve Drolon] improved TIFF flags handling in TIFF save function +* [Herve Drolon] fixed a potential crash-problem in FreeImage_OutputMessage (in case of a null message) +* [Detlev Vendt] fixed a bug with the deprecated FreeImage_GetBitsRowCol (trailling backslash behind the DEPRECATE macro) + +July 24th, 2002 - 2.5.5 +! FreeImage now uses libPNG 1.2.4 +! FreeImage now uses libMNG 1.0.4 ++ [Markus Loibl] added ActiveX wrapper + +June 22th, 2002 - 2.5.4 +* [Timothy Roughton] fixed FreeImage not compiling on LCC WIN32 +* [Markus Loibl] fixed PluginTIFF sometimes saving with wrong X/Y resolution +* fixed crashbug when loading some RLE4 BMPs +! FreeImage now uses LibPNG 1.2.3 +! [Markus Loibl] improved startup plugin locate handling code +! [Gerhard Gruber] made some changes so that FreeImage compiles on VC5 ++ [Markus Loibl] added flags TIFF_PACKBITS, TIFF_DEFLATE, TIFF_ADOBE_DEFLATE and TIFF_NONE + +May 21th, 2002 - 2.5.3 +* fixed wrong colors when loading 16-bit grayscale TIFF +* fixed crash-problem with FreeImageQt +* fixed PluginTIFF saving some bitmaps flipped vertically +* [Laurent Rocher] fixed bug in FreeImage_GetLockedPageNumbers +* [Laurent Rocher] fixed bug in FreeImage_UnlockPage +! FreeImage now uses libpng 1.2.2 ++ added TARGA save support ++ added BMP RLE8 save support + +March 30th, 2002 - 2.5.2 +* fixed bug in PluginTARGA where 32-bit bitmaps are not always correctly flipped +* fixed FreeImage_GetLockedPageNumber being mentioned in FreeImage.h +* fixed crash bug when handling read-only multipage bitmaps +- removed internal function FreeImage_GetExtraDataPointer +! FreeImage now uses zlib 1.1.4 ++ added function FreeImage_GetLockedPageNumbers + +March 2nd 2002 - 2.5.1 +* fixed pluginTIFF not being able to save 32-bit bitmaps +* fixed not being able to save PNM bitmaps through the LoadXXX wrappers +* fixed a webcam generated BMP image being loaded with wrong colors +! FI_ReadProc, FI_WriteProc, etc. do now carry the DLL_CALLCONV flag +! the function FreeImage_GetBitsRowCol is now deprecated +! FreeImage_SetTransparencyTable now taken an integer as count parameter +! FreeImage_IsTransparent now always returns true for 32-bit bitmaps +! PluginPNG::Save now ignores the result of FreeImage_IsTransparent +! PluginTIFF now converts all 32-bit bitmaps to 24-bit, until our patch + to fully support alpha in TIFF is applied in libtiff ++ added full multi-paging support ++ added octal and hexadecimal number support to FreeImage_OutputMessage + +January 3rd 2002 - 2.5.0 +* fixed bug in FreeImage_SaveJPEG +* fixed bug in FreeImage_LoadMNG +* fixed bug in FreeImage_LoadPNG +* fixed small Visual C++ 5.0 compiler issue in PluginMNG.cpp +* fixed FreeImage crashing on JPEG 6.0 encoded TIFFs +! FreeImage now uses libTIFF 3.5.7 +! FreeImage now uses libPNG 1.2.1 +! all the FreeImage_LoadXXX and FreeImage_SaveXXX functions are now deprecated ++ added Dr. Halo (*.cut) support ++ added printf-like format string support to SetOutputMessage ++ added basic multi-paging support: open, close, counting and grabbing ++ added deprecation manager ++ added FreeImage_Clone function + +October 3rd 2001 - 2.4.2 +* fixed missing BI_BITFIELDS support for 32-bit BMPs +* fixed bug in FreeImage_ConvertLine16_555_To16_565 and vice versa +* fixed bug in FreeImage_ConvertToRawBits +* fixed PluginTIFF behaving incorrectly on PHOTOMETRIC_MASK images +* fixed 16 bit TIFFs not loading correctly +* fixed incorrect handling of CCITTFAX3 and CCITTFAX4 TIFFs +* fixed JPEG encoded TIFFs not being supported +! [Yours Detlev] patched libTIFF to handle EXTRASAMPLE_UNSPECIFIED +! [Juergen Riecker] improved speed of PCX loading a lot +! rewrote parts of FreeImage to improve support for c +! the internal RGB555 and RGB565 macros now read BGR instead of RGB +! FreeImage now uses libMNG 1.0.3 +! FreeImage now uses libPNG 1.2.0 +! FreeImage_Save now opens files with the "w+b" flag +! renamed internal macro CalculateUsedColors to CalculateUsedPaletteEntries +! enabling/disabling plugins no longer has effect on FIFSupportsReading +! enabling/disabling plugins no longer has effect on FIFSupportsWriting ++ added flag PNG_IGNOREGAMMA ++ added function FreeImage_FIFSupportsExportBPP + +July 30th 2001 - 2.4.1 +* [Jan Nauta] fixed some plugin ids not being passed to plugins +* [Jan Nauta] fixed some functions being natively called instead of indirect +* [Jan Nauta] fixed BMPs with signature BA not being regognised +* [Remo Eichenberger] fixed memory leak in the plugin system +* fixed seek bug in PluginIFF's Validate +* fixed transparency issue in PluginPNG +* fixed uncaught exceptions in WUQuantizer and NNQuantizer +* fixed some problems with PluginTARGA +* fixed some problems with PluginICO +* fixed some problems with PluginBMP +! improved FreeImageQt's load function a little +! tell/seek control for validation is now handled inside the plugin framework + +July 22th 2001 - 2.4.0 +* (Yours Detlev) fixed memory leak in FreeImage_GetFIFFromFilename +* (Yours Detlev) fixed memory leak in the ICO plugin +* (Yours Detlev) fixed memory leak in the PNG plugin +* fixed potential NULL-pointer access bug in Plugin::AddNode +* fixed problems with linking the static lib +- removed LBM plugin. Its functionality is placed in the IFF plugin now +- removed FreeImage_GetFIFByIndex +! FreeImage now uses LibMNG 1.0.2 +! FreeImage_SetTransparent now only enables alpha when the bitmap is 8 or 32 bit +! FreeImage_SetTransparencyTable now only enables alpha when the bitmap is 8 bit +! FreeImage_LoadLBM now uses Mark Sibly's IFF plugin +! FreeImage_SaveBMP now converts to 24-bit when bpp is 32 and transparency is off +! FreeImage_SaveJPEG now converts to 24-bit when bpp is 32 and transparency is off +! FreeImage_SavePNM now converts to 24-bit when bpp is 32 and transparency is off +! FreeImage_SaveTIFF now converts to 24-bit when bpp is 32 and transparency is off ++ [Mark Sibly] added IFF (ILBM) support ++ added basic support for Photoshop files ++ added mime type support (FreeImage_GetFIFFromMime) ++ added functions FreeImage_SetPluginEnabled and FreeImage_IsPluginEnabled + Disabling plugins modifies the behaviour of the following functions: + * FreeImage_LoadFromHandle + * FreeImage_SaveToHandle + * FreeImage_FIFSupportsReading + * FreeImage_FIFSupportsWriting + * FreeImage_GetFIFFromFormat + * FreeImage_GetFIFFromFilename + * FreeImage_GetFIFFromMime + * FreeImage_Validate + +June 30th 2001 - 2.3.2 +* fixed missing "targa" extension in targa extension list +* fixed small memory leak in PluginList::AddNode +* fixed 32 bit PNG saving suddenly disappeared from the distro? +* fixed 'black line' bug in LoadTARGA +- removed project FreeImageM2 +- removed FreeImage_Combine +! FreeImage_RegisterLocalPlugin now receives a FI_InitProc as first parameter +! FreeImage_GetFIFFromFilename now also takes the format id into account +! cleanup up the code a little for PluginPCD and PluginPCX ++ added static lib project + +June 11th 2001 - 2.3.1 +* [Machiel ten Brinke] fixed the loading of some 'ancient' TARGAs +* [Rui Lopes] fixed some bugs in the external plugin registration +* fixed the plugin system crashing when the init function isn't called +- removed project FreeImagePy +- removed 32 to 24 bit conversion while saving PNG in FreeImageQt +! the scanline convert functions are now accessable in plugins +! FreeImage now uses an STL map to store the plugin list +! PluginSDK.h is now integrated into FreeImage.h +! FreeImage_Register now receives the boolean parameter 'load_local_plugins_only' +! FreeImage now uses LibPNG 1.0.12 ++ [Rui Lopes] added plugin for GIF reading/writing support ++ added function FreeImage_SetTransparencyCount ++ added support for 32 bit PNG saving ++ added FreeImage_RegisterLocalPlugin to allow plugins inside apps ++ added FreeImage_RegisterExternalPlugin to manually load DLLs ++ added plugin for JBIG reading/writing support + +May 4th 2001 - 2.3.0 +* [Martin Weber] fixed some small bugs in the TARGA and BMP plugins +* [Martin Weber] fixed tiny bug in new 16 bit conversions +* [Martin Weber] fixed load flag inconsistency in the TARGA plugin +* [Martin Weber] fixed plugin id / load reference inconsistency for PNM +* [Jan Nauta] fixed bug in conversion 16 -> 16 +* [Herve Drolon] fixed small bug in 4-bit PCX loader +- removed code that loads BMPs renamed to ICO in PluginICO +! the flag TARGA_LOAD_RGB555 is now obsolete +! the plugin list is now sorted internally +! ConvertTo32Bits now stores the transparency table as alpha mask +! FreeImage now uses LibMNG 1.0,1 +! FreeImage now uses LibPNG 1.0.11 ++ added external plugin support via DLLs ++ added function FreeImage_GetFIFByIndex ++ added internal function CalculateScanLine ++ added transparency support for high-color PNGs ++ added transparency support for high-color TIFFs ++ added functions FreeImage_SetTransparent and FreeImage_IsTransparent ++ added constant FIC_RGBALPHA to FREE_IMAGE_COLOR_TYPE + +April 5th 2001 - 2.2.0 +* [Remo Eichenberger] fixed small bug concerning DLLMain and static LIB generation +* fixed 1-bit bitmaps not properly loading in FreeImageQt +* fixed bug in conversion 16->16 +* FreeImage now uses LibPNG 1.0.10 +! [Martin Weber] improved loading of BMP files +! [Martin Weber] improved loading of TARGA files +! [Dave Larson] improved visual appearance after 16 conversions +! FreeImageQt now converts 32-bit bitmaps to 24-bit when saving PNGs and JPEGs ++ added functions FreeImage_Initialise and FreeImage_DeInitialise ++ added internal plugins ++ re-added combine/alphablend functions + +March 8th 2001 - 2.1.0 +* [Martin Hemming] fixed bug in 16-bit TARGA loading code +* fixed PNG's with alpha masks not loading correctly +! FreeImage is now dual-licensed: the FI-License and the GPL license +! FreeImage now uses LibPNG 1.0.9 +! FreeImage now uses LibTIFF 3.5.6 Beta +! FreeImage now uses LiBMNG 1.0.0 +! changed the ordering of the FREE_IMAGE_FORMAT table +! improved linux support +! improved test script ++ added transparency table support to SavePNG ++ added BI_BITFIELDS support to LoadBMP and SaveBMP ++ added reading support for OS/2 2.x BMPs ++ added support for MNG and JNG reading using LibMNG ++ added support for Deluxe Paint reading ++ added 'hot swap' support to the Core DLL ++ added 'hot swap' support to FreeImage Qt ++ added functions GetFIFFromFormat and GetFIFFromFilename ++ added functions FIFSupportsReading and FIFSupportsWriting ++ added function GetFIFRegExpr + +January 14th 2001 - 2.0.0 +* [Herve Drolon] fixed a bug in the conversion 4->8 +* [Herve Drolon] fixed a bug in metrics handling in SaveJPEG +* [Herve Drolon] fixed a bug in the return value of the function SaveTIFF +* fixed the presence of two WuQuantizer.cpp files in the distribution +* fixed bug where a BMP renamed to ICO isn't loaded +- removed FreeImage_ConvertToGreyScale. Use FreeImage_ConvertTo8Bits instead. +- removed the boolean parameters from all conversion routines +- removed page handling in LoadTIFF. A new range of functions will be added. +! The void pointers used in FreeImage are now typed +! LoadBMP now takes palettes in 24/32 bit images in respect +! All effects and MMX functions are now stored in a new library (FreeEffects) +! [Herve Drolon] fixed bug in FreeImage_GetColorType +! [Herve Drolon] improved PCX loader. It can now read 1, 4, 8 and 24-bit images +! [Manfred Tausch] improved FreeImage_Rotate +! [Luca Piergentili] fixed crash bug when saving some 1-bit TIFFs +! rewrote all bitdepth conversion routines making use of the new scanline converters +! rewrote bitdepth conversion in FreeImageQt (uses less memory) +! FreeImage is now compiled __stdcall ++ [Herve Drolon] added WBMP (Wireless Bitmap Format) support: loading and saving ++ [Herve Drolon] added 4, 16 and 32 bitdepth handling in GetColorType ++ [Herve Drolon] added handling of 8-bit greyscale bitmaps in SaveJPEG ++ [Herve Drolon] added NeuQuant color reduction algorithm to ColorQuantize ++ added DLL_CALLCONV (calling convention) flag ++ added bitmask support to all bitmaps ++ added a series of functions converting scanlines from one bitdepth to another ++ added functions ConvertFromRawBits and ConvertToRawBits ++ added project FreeImageM2: Magenta II MMT bindings for FreeImage ++ added basic foundation for linux support + +December 2th 2000 - 1.4.4 +* fixed small bug related to TIFFSetDirectory in FreeImage_LoadTIFF +* fixed FreeImage_Rotate sometimes clipping too much pixels +* fixed other small bug in FreeImage_Rotate +* fixed FreeImage_Clone not taking the FREEIMAGEHEADER in account +* fixed bug in FreeImageQt where 1-bit images are not correctly allocated +* fixed FreeImage_Crop not copying the palette +* fixed message function pointer crash bug +* fixed bug where the palette wasn't copied when saving in FreeImageQt +* fixed FreeImage_Clone not copying the transparency table +- removed FreeImage_WritePaletteEntry +! [Adam Gates] rewrote parts of FreeImage so that c compilers can handle it better +! FreeImageQt doesn't statically link with the FreeImage lib anymore +! FreeImageQt now uses atexit() to automatically unregister +! rewrote parts of FreeImage_LoadBMP to increase speed ++ [Markus Loibl] added metrics handling code to LoadBMP, LoadJPEG, LoadTIFF and LoadPCX ++ added metrics handling code to FreeImageQt ++ added functions FIQT_IsLoaded, FIQT_GetVersion and FIQT_GetCopyrightMessage ++ added conversion 1 -> 16 ++ added FreeImage_SaveJPEG and JPEG quality settings ++ added FreeImage_GetBitsRowCol ++ added function FIQT_SetOutputMessage to FreeImageQt ++ added FreeImage_GetFileTypeFromExtension and FIQT_GetFileTypeFromFormat ++ added project FreeImagePy: python bindings for FreeImage + +November 7th 2000 - 1.4.3 +* fixed FreeImage_SavePNG crash bug +* fixed slighly corrupt size filter in FreeImage_Combine +* fixed FreeImage_SaveTIFF not saving 4-bit images +* [Herve Drolon] fixed bug in FreeImage_LoadTIFF +* [Herve Drolon] fixed bug in FreeImage_GetColorType +- removed fclose from FreeImage_SavePNM (who put it there?) +! rewrote FreeImage_Rotate +! FreeImageQt now automatically detects which formats are supported by Qt and which not +! FreeImage_Allocate now returns a void pointer +! FreeImage_Unload is now called FreeImage_Free ++ added 16-bit 5-5-5 support to FreeImage_LoadBMP ++ added RLE_DELTA support to FreeImage_LoadBMP ++ added directory support to FreeImage_LoadTIFF ++ added functions dealing with transparency ++ added transparency support to 8-bit PNG's in Qt ++ added FREE_IMAGE_QUANTIZE parameter to FreeImage_ColorQuantize ++ added custom FREEIMAGEHEADER header prepended to internal bitmaps ++ added new documentation + +October 18th 2000 - 1.4.2 +* fixed FreeImage_SaveBMP storing an incorrect bfSize value in the BITMAPFILEHEADER +* fixed bug where JPEG and PNG wouldn't load in FreeImageQt +* fixed FreeImage_Mirror mirroring one pixel less than needed +! FreeImage_MaskedCombine24 is now called FreeImage_MaskedCombine24Ex +! FreeImage_MaskedCombine32 is now called FreeImage_MaskedCombine32Ex ++ added 16-bit bitmap support to FreeImage_Mirror ++ added 16-bit bitmap support to FreeImage_ConvertTo8Bits ++ added simple version of FreeImage_MaskedCombine24 ++ added simple version of FreeImage_MaskedCombine32 + +October 17th 2000 - 1.4.1 +* [Herve Drolon] fixed bug in FreeImage_ConvertTo8Bits +* fixed bug in conversion with 16 -> 24 and 16 -> 32 +- removed static library support +- removed all unnecessary files from LibTIFF, LibPNG, LibJPEG and ZLib +- removed all absolute seeks from the library +! FreeImageQt now makes use of the DLL distro +! rebuilt the entire directory structure +! improved handling of BMP +! renamed FreeImage_MaskedCombine to FreeImage_MaskedCombine32 ++ [Alexander Dymerets] added 24-bit masked alpha blending with a seperate alpha mask ++ added FreeImage_Rotate (known bug in degrees 76 to 106) ++ added 4-bit bitmap support to FreeImage_ConvertTo16Bits ++ added 8-bit bitmap support to FreeImage_ConvertTo16Bits ++ added 32-bit bitmap support to FreeImage_ConvertTo16Bits ++ added 32-bit bitmap support to FreeImage_Mirror ++ added 16-bit 5-5-5 support to FreeImage_ConvertTo24Bits ++ added 16-bit 5-5-5 support to FreeImage_ConvertTo32Bits + +October 2th 2000 - 1.4.0 +* [Jani Kajala] fixed bug in conversion with 4 -> 24 and 8 -> 32 +* [Jani Kajala] fixed bug in FreeImage_Flip +* [Jani Kajala] fixed minor bug in FreeImage_LoadBMP +- [Herve Drolon] removed PBMFlags, PGMFlags and PPMFlags +- [Herve Drolon] removed FI_LoadGeneric +- removed FreeImage_Win32.h +! [Herve Drolon] changed FI_GetFileType +! [Herve Drolon] replaced FI_LoadPBM, FI_LoadPGM and FI_LoadPPM with FI_LoadPNM +! [Herve Drolon] improved FreeImage_LoadPNG +! FreeImage_WritePaletteEntry is now exported ++ [Herve Drolon] added FreeImage_SavePNG ++ [Herve Drolon] added FreeImage_SavePNM and PNMFlags ++ [Herve Drolon] added XXXFlags parameter to save functions ++ [Herve Drolon] added FreeImage_LoadRAS and FIF_RAS ++ added FreeImage_GetFileTypeFromExt + +September 7th 2000 - 1.3.5 ++ added conversion 4 -> 8 to FI_ConvertTo8Bits ++ added simple version of FI_GetFileType ++ added project FreeImageQt; a port of the library to the TrollTech library + +August 31th 2000 - 1.3.4 +* fixed 'ice effect' bug in new 24 bit PCX code +* fixed some bugs with the conversion 16 -> 24 and 16 -> 32 +! FI_Blur now returns void +! A debug build of the library now produces FreeImaged.dll and FreeImaged.lib +! TARGA_LOAD_ARGB8888 is now called TARGA_LOAD_RGB888 +! Alpha channels are now automatically loaded unless TARGA_LOAD_RGB888 is specified +! cleaned up the code a lot ++ added 32-bit bitmap support to FreeImage_ConvertToGreyscale ++ added support for 32-bit bottom-left TARGA images ++ added internal functions FreeImage_WritePaletteEntry() and FreeImage_GetScanLine() ++ added FreeImage_Win32.h, containing Windows functions needed to create DIBs ++ added documentation through Doxygen + +July 30th 2000 - 1.3.3 +* [Jani Kajala] fixed some bugs with the conversion 4 -> 24 and 8 -> 24 +* [Jani Kajala] fixed some bugs with the conversion 4 -> 32 and 8 -> 32 +* fixed bug in FI_LoadPNM's ASCII number loader +! [Herve Drolon] improved FI_LoadPNG +! [Herve Drolon] changed FI_ConvertToGreyScale (added changeable macro for conversion) +! improved FI_ConvertTo24Bits +! improved FI_ConvertTo32Bits +! freeImage now uses LibPNG 1.0.8 ++ [Herve Drolon] added FI_ColorQuantize, based on Wu's color quantizer ++ added the conversion 1 -> 24 ++ added the conversion 1 -> 32 ++ added FI_ConvertTo8Bits ++ added FI_Invert (very useful for image processing) ++ added FI_GetColorType and 'enum FREE_IMAGE_COLOR_TYPE' + +June 30th 2000 - 1.3.2 +- removed color reduction functions from the project +! [Herve Drolon] Improved FI_LoadTIFF code +! renamed FI_ToGrayscale to FI_ConvertToGreyScale +! renamed FI_IncreaseColors to FI_ConvertTo24Bits +! LoadBMP now supports 32-bit bitmaps +! [Jani Kajala] Improved FI_LoadTARGA and FI_LoadPCX code ++ added FI_ConvertTo32Bits to convert a bitmap to 32-bit ++ added FI_MaskCombine to combine two 32-bit bitmaps using a alpha mask ++ added FI_AddAlphaMask to enrich a 32-bit bitmap with an alpha mask ++ added FI_SaveTIFF ++ added 16-bit bitmap (565) support to the ConvertToXXX functions. ++ added FI_ConvertTo16Bits (555 and 565) + +June 1th 2000 - 1.3.1 +- removed Standard Template Library (STL) code +* [Jani Kajala] fixed minor bug in FI_LoadTARGA +* [Jani Kajala] fixed some minor bugs in FI_LoadPCX +! streamlined FI_LoadJPEG a little +! FreeImage now uses LibPNG 1.0.6 +! FreeImage now uses LibTIFF 3.5.5 +! FreeImage now uses malloc and free instead of new and delete ++ introduced compiler flags to disable certain features in the DLL ++ added experimental nearest color reduction (FI_ReduceColorsNearestColor) + +April 13th 2000 - 1.3.0 +* fixed some 8 bit PCX files loading incorrectly +* fixed tiny bug in internally used CalculateUsedColors function +- removed FI_SaveXPM. Only BMP is supported now. +- removed Windows dependencies for easier porting +! optimized FI_LoadKOALA a little +! optimized FI_Combine using MMX technology +! FI_Combine now receives an 'unsigned integer' as alpha blend parameter +! FI_InCreaseColors and FI_ReduceColors don't dispose the old bitmap anymore ++ added PNM support (PGM, PPM and PBM; both binary and ascii) ++ [Alexander Dymerets] added FI_EnableMMX and FI_DisableMMX ++ added various effect functions (FI_Blur, FI_Brighten and FI_Crop) + +March 1st 2000 - 1.2.1 +* fixed some 24 bit PCX files loading incorrectly + +February 8th 2000 - 1.2.0 +* fixed last bitmap data block in JPEG files being truncated +* fixed 4/8 bit BMP's incorrectly loading when the palette is smaller than the bitcount predicts +- removed FI_Load. There is no reliable way to identify all image formats +- removed FI_SetJpegDecodeMode. + Mode selection is now done using the 'DataEnum data' parameter of FI_LoadJPEG +! read_proc/write_proc/tell_proc in FreeImageIO now are same as fread/fwrite/ftell ++ added a 'DataEnum data' parameter to all FI_LoadXXX functions. ++ added 16 bit TARGA support ++ added RLE support for TARGA images ++ added FI_GetDIBSize to get the size of a DIB in bytes ++ added Kodak PhotoCD support (Base, Base/4 and Base/16 encoding) ++ added KOALA support ++ added FI_GetFileType. Note: there is no reliable way to identify TARGA, ICO and PCD. Therefore they have been excluded +In KOALA files only the files converted by a C64 emulator can be identified. ++ added FI_Combine to combine two 24-bit bitmaps with (optional) alpha blending + +January 15th 2000 - 1.1.1 +! FI_Copy is now called FI_Clone ++ added FI_ToGrayscale to convert a color bitmap to grayscale ++ added 32 bit TARGA support ++ added FI_IncreaseColors to increase the bitmap bitdepth from 4/8 bit to 24 bit + +January 14th 2000 - 1.1.0 +* FI_MIRROR: fixed nibbles not being mirrored in 4 bit images +* FI_MIRROR: fixed bits not being mirrored in 1 bit images +* fixed improper loading of 1, 4 and 8 bit OS/2 BMP's +* fixed some inconsistensies in the calculation of lines and pitches +* fixed incorrectly loading of Huffman and FAX encoded TIFFs +* fixed LoadTGA accepting 16 bit TGA's and returning corrupt DIB's +- removed LZW support for TIFFs +! FreeImage now uses LibTIFF 3.5.4 ++ added ICO support ++ added overridable file I/O support in the form of FreeImageIO and fi_handle ++ added FI_Load for generic image loading ++ added FI_ReduceColors for color reduction ++ added FI_Copy to copy a bitmap in memory + +January 5th 2000 - 1.0.0 diff --git a/Wrapper/Delphi/WhatsNew_Delphi.txt b/Wrapper/Delphi/WhatsNew_Delphi.txt index a27d6a8..f2ffb29 100644 --- a/Wrapper/Delphi/WhatsNew_Delphi.txt +++ b/Wrapper/Delphi/WhatsNew_Delphi.txt @@ -1,109 +1,109 @@ -What's New for FreeImage Delphi Wrapper - -* : fixed -- : removed -! : changed -+ : added - -June 4, 2012 -+ [Lorenzo Monti] updated wrapper for FreeImage 3.15.3 - -March 4, 2011 -* [Jean-Marc Bottura] some bugfixes in FreeBitmap.pas -+ [Jean-Marc Bottura] added support for 64 bit compilers - -February 15, 2011 -+ [Lorenzo Monti] updated wrapper for FreeImage 3.15.0 - -January 4, 2011 -+ [Lorenzo Monti] updated ImagePreview demo to support latest Graphics32 components (1.9) and Delphi 2010 / XE - -November 12, 2010 -+ [Lorenzo Monti] updated wrapper for FreeImage 3.14.1 -+ [Lorenzo Monti] added Delphi XE support - -July 29, 2010 -+ [Lorenzo Monti] added Free Pascal / Lazarus 32 bit support - -July 14, 2010 -+ [Lorenzo Monti] updated wrapper for FreeImage 3.13.1 -* [Lorenzo Monti] fixed declaration of FreeImageIO functions (FI_ReadProc, FI_WriteProc, FI_SeekProc, FI_TellProc) -! [Lorenzo Monti] renamed structure PluginStruct to Plugin, according to FreeImage.h -* [Lorenzo Monti] fixed declaration of JPEG_CMYK constant -* [Lorenzo Monti] fixed declaration of type FreeImage_OutputMessageFunction -* [Lorenzo Monti] fixed declaration of FreeImage_OutputMessageProc -+ [Lorenzo Monti] added wrapper for FreeImage_OutputMessageProc for older Delphi compilers (<6) not supporting varargs -* [Lorenzo Monti] fixed declaration of FreeImage_LookupX11Color and FreeImage_LookupSVGColor -! [Lorenzo Monti] changed declaration of FreeImage_GetPixelIndex, FreeImage_GetPixelColor, FreeImage_SetPixelIndex, FreeImage_SetPixelColor -! [Lorenzo Monti] changed declaration of FreeImage_GetInfo -! [Lorenzo Monti] changed declaration of FreeImage_GetICCProfile, FreeImage_CreateICCProfile, FreeImage_DestroyICCProfile -* [Lorenzo Monti] fixed declaration of FreeImage_SetComplexChannel -+ [Lorenzo Monti] added Delphi 2010 support -+ [Lorenzo Monti] added Version.inc to determine compiler version -! [Lorenzo Monti] moved all "external" definitions to implementation section -! [Lorenzo Monti] changed FreeBitmap.pas, FreeUtils.pas and TargaImage.pas to reflect changes in the FreeImage.pas unit - -July 17, 2006 -+ [Hervé Drolon] added FIF_FAXG3 and FIF_SGI definitions, added FreeImage_MakeThumbnail definition. - -January 20, 2006 -! [Anatoliy Pulyaevskiy] updated WinBitmap demo -* [Anatoliy Pulyaevskiy] fixed TFreeBitmap.ConvertToStandartType renamed to TFreeBitmap.ConvertToStandardType -* [Anatoliy Pulyaevskiy] fixed using of SetFreeImageMarker (only for HDR dib) - -October 19, 2005 -+ [Anatoliy Pulyaevskiy] updated wrapper for FreeImage 3.8.0 -+ [Anatoliy Pulyaevskiy] added Delphi 5 support -+ [Anatoliy Pulyaevskiy] added TFreeBitmap.OnChanging event -! [Anatoliy Pulyaevskiy] changed declaration of TFreeBitmap.Assign method -+ [Anatoliy Pulyaevskiy] added TFreeBitmap.CanSave function -! [Anatoliy Pulyaevskiy] property TFreeBitmap.Dib now have read/write access -+ [Anatoliy Pulyaevskiy] added TFreeTag class incapsulating FreeImage FITAG type - -August 5, 2005 -* [kaare-nysite] fixed the prototype of FreeImage_ConvertFromRawBits - -June 21, 2005 -* [Maarten Veerman] fixed the prototype of FreeImage_OpenMultiBitmap - -February 17, 2005 - Version 1.3.0 -+ [Anatoliy Pulyaevskiy] updated the wrapper for FreeImage 3.6.0 -! [Anatoliy Pulyaevskiy] FreeImage.pas unit has been reworked - -January 14, 2005 - Version 1.2.1 -+ [Anatoliy Pulyaevskiy] updated the wrapper for FreeImage 3.5.3 -+ [Anatoliy Pulyaevskiy] added TFreeBitmap.SetHorizontalResolution and TFreeBitmap.SetVerticalResolution -+ [Anatoliy Pulyaevskiy] added TFreeBitmap.MakeThumbnail procedure ( an adapted version of function given by Enzo Costantini) -+ [Enzo Costantini] added FIU_GetFIFType utility function -+ [Enzo Costantini] added TFreeWinBitmap.CopyToBitmapH function -* [Anatoliy Pulyaevskiy] fixed TFreeBitmap.Rotate (fix from FreeImage CVS) -+ [Anatoliy Pulyaevskiy] added TFreeBitmap.ConvertToStandartType - -December 20, 2004 - Version 1.2.0 -+ [Anatoliy Pulyaevskiy] added MultiBitmap Demo -* [Anatoliy Pulyaevskiy] fixed TFreeMultiBitmap.LockPage due to error with Locking/Unlocking pages -+ [Anatoliy Pulyaevskiy] added TFreeBitmap.ConvertTo4Bits -* [Anatoliy Pulyaevskiy] TFreeBitmap.ConvertToGrayScale fixed converting bitmaps with FIC_MINISWHITE color type -* [Anatoliy Pulyaevskiy] fixed TFreeWinBitmap.DrawEx FDisplayDib deleting -+ [Anatoliy Pulyaevskiy] updated the wrapper for FreeImage 3.5.2 - -November 12, 2004 - Version 1.1.0 -+ [Anatoliy Pulyaevskiy] added TFreeBitmap.Assign(Source: PFIBITMAP) -- [Anatoliy Pulyaevskiy] removed TFreeBitmap.SetDib -! [Anatoliy Pulyaevskiy] TFreeBitmap.Dib property now read-only -* [Anatoliy Pulyaevskiy] TFreeMultiBitmap.UnlockPage implemented -* [Anatoliy Pulyaevskiy] fixed TFreeBitmap.Rescale not applies changes - -November 8, 2004 - Version 1.0.0 -+ [Anatoliy Pulyaevskiy] added Delphi version of FreeImagePlus -+ [Anatoliy Pulyaevskiy] updated the wrapper for FreeImage 3.5.0 - -January 7, 2004 -+ [Tommy] added TargaImage unit - -October 28, 2003 -+ [Peter Byström] updated the wrapper for FreeImage 3.0.2 - -August 9, 2003 -+ [Simon Beavis] added a wrapper for FreeImage 2.6.1 - +What's New for FreeImage Delphi Wrapper + +* : fixed +- : removed +! : changed ++ : added + +June 4, 2012 ++ [Lorenzo Monti] updated wrapper for FreeImage 3.15.3 + +March 4, 2011 +* [Jean-Marc Bottura] some bugfixes in FreeBitmap.pas ++ [Jean-Marc Bottura] added support for 64 bit compilers + +February 15, 2011 ++ [Lorenzo Monti] updated wrapper for FreeImage 3.15.0 + +January 4, 2011 ++ [Lorenzo Monti] updated ImagePreview demo to support latest Graphics32 components (1.9) and Delphi 2010 / XE + +November 12, 2010 ++ [Lorenzo Monti] updated wrapper for FreeImage 3.14.1 ++ [Lorenzo Monti] added Delphi XE support + +July 29, 2010 ++ [Lorenzo Monti] added Free Pascal / Lazarus 32 bit support + +July 14, 2010 ++ [Lorenzo Monti] updated wrapper for FreeImage 3.13.1 +* [Lorenzo Monti] fixed declaration of FreeImageIO functions (FI_ReadProc, FI_WriteProc, FI_SeekProc, FI_TellProc) +! [Lorenzo Monti] renamed structure PluginStruct to Plugin, according to FreeImage.h +* [Lorenzo Monti] fixed declaration of JPEG_CMYK constant +* [Lorenzo Monti] fixed declaration of type FreeImage_OutputMessageFunction +* [Lorenzo Monti] fixed declaration of FreeImage_OutputMessageProc ++ [Lorenzo Monti] added wrapper for FreeImage_OutputMessageProc for older Delphi compilers (<6) not supporting varargs +* [Lorenzo Monti] fixed declaration of FreeImage_LookupX11Color and FreeImage_LookupSVGColor +! [Lorenzo Monti] changed declaration of FreeImage_GetPixelIndex, FreeImage_GetPixelColor, FreeImage_SetPixelIndex, FreeImage_SetPixelColor +! [Lorenzo Monti] changed declaration of FreeImage_GetInfo +! [Lorenzo Monti] changed declaration of FreeImage_GetICCProfile, FreeImage_CreateICCProfile, FreeImage_DestroyICCProfile +* [Lorenzo Monti] fixed declaration of FreeImage_SetComplexChannel ++ [Lorenzo Monti] added Delphi 2010 support ++ [Lorenzo Monti] added Version.inc to determine compiler version +! [Lorenzo Monti] moved all "external" definitions to implementation section +! [Lorenzo Monti] changed FreeBitmap.pas, FreeUtils.pas and TargaImage.pas to reflect changes in the FreeImage.pas unit + +July 17, 2006 ++ [Hervé Drolon] added FIF_FAXG3 and FIF_SGI definitions, added FreeImage_MakeThumbnail definition. + +January 20, 2006 +! [Anatoliy Pulyaevskiy] updated WinBitmap demo +* [Anatoliy Pulyaevskiy] fixed TFreeBitmap.ConvertToStandartType renamed to TFreeBitmap.ConvertToStandardType +* [Anatoliy Pulyaevskiy] fixed using of SetFreeImageMarker (only for HDR dib) + +October 19, 2005 ++ [Anatoliy Pulyaevskiy] updated wrapper for FreeImage 3.8.0 ++ [Anatoliy Pulyaevskiy] added Delphi 5 support ++ [Anatoliy Pulyaevskiy] added TFreeBitmap.OnChanging event +! [Anatoliy Pulyaevskiy] changed declaration of TFreeBitmap.Assign method ++ [Anatoliy Pulyaevskiy] added TFreeBitmap.CanSave function +! [Anatoliy Pulyaevskiy] property TFreeBitmap.Dib now have read/write access ++ [Anatoliy Pulyaevskiy] added TFreeTag class incapsulating FreeImage FITAG type + +August 5, 2005 +* [kaare-nysite] fixed the prototype of FreeImage_ConvertFromRawBits + +June 21, 2005 +* [Maarten Veerman] fixed the prototype of FreeImage_OpenMultiBitmap + +February 17, 2005 - Version 1.3.0 ++ [Anatoliy Pulyaevskiy] updated the wrapper for FreeImage 3.6.0 +! [Anatoliy Pulyaevskiy] FreeImage.pas unit has been reworked + +January 14, 2005 - Version 1.2.1 ++ [Anatoliy Pulyaevskiy] updated the wrapper for FreeImage 3.5.3 ++ [Anatoliy Pulyaevskiy] added TFreeBitmap.SetHorizontalResolution and TFreeBitmap.SetVerticalResolution ++ [Anatoliy Pulyaevskiy] added TFreeBitmap.MakeThumbnail procedure ( an adapted version of function given by Enzo Costantini) ++ [Enzo Costantini] added FIU_GetFIFType utility function ++ [Enzo Costantini] added TFreeWinBitmap.CopyToBitmapH function +* [Anatoliy Pulyaevskiy] fixed TFreeBitmap.Rotate (fix from FreeImage CVS) ++ [Anatoliy Pulyaevskiy] added TFreeBitmap.ConvertToStandartType + +December 20, 2004 - Version 1.2.0 ++ [Anatoliy Pulyaevskiy] added MultiBitmap Demo +* [Anatoliy Pulyaevskiy] fixed TFreeMultiBitmap.LockPage due to error with Locking/Unlocking pages ++ [Anatoliy Pulyaevskiy] added TFreeBitmap.ConvertTo4Bits +* [Anatoliy Pulyaevskiy] TFreeBitmap.ConvertToGrayScale fixed converting bitmaps with FIC_MINISWHITE color type +* [Anatoliy Pulyaevskiy] fixed TFreeWinBitmap.DrawEx FDisplayDib deleting ++ [Anatoliy Pulyaevskiy] updated the wrapper for FreeImage 3.5.2 + +November 12, 2004 - Version 1.1.0 ++ [Anatoliy Pulyaevskiy] added TFreeBitmap.Assign(Source: PFIBITMAP) +- [Anatoliy Pulyaevskiy] removed TFreeBitmap.SetDib +! [Anatoliy Pulyaevskiy] TFreeBitmap.Dib property now read-only +* [Anatoliy Pulyaevskiy] TFreeMultiBitmap.UnlockPage implemented +* [Anatoliy Pulyaevskiy] fixed TFreeBitmap.Rescale not applies changes + +November 8, 2004 - Version 1.0.0 ++ [Anatoliy Pulyaevskiy] added Delphi version of FreeImagePlus ++ [Anatoliy Pulyaevskiy] updated the wrapper for FreeImage 3.5.0 + +January 7, 2004 ++ [Tommy] added TargaImage unit + +October 28, 2003 ++ [Peter Byström] updated the wrapper for FreeImage 3.0.2 + +August 9, 2003 ++ [Simon Beavis] added a wrapper for FreeImage 2.6.1 + diff --git a/Wrapper/Delphi/demo/ImagePreview/MainFrm.pas b/Wrapper/Delphi/demo/ImagePreview/MainFrm.pas index 1db403a..dd46b94 100644 --- a/Wrapper/Delphi/demo/ImagePreview/MainFrm.pas +++ b/Wrapper/Delphi/demo/ImagePreview/MainFrm.pas @@ -1,524 +1,524 @@ -unit MainFrm; - -interface - -uses - Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, - Dialogs, Menus, ExtCtrls, Math, GR32, GR32_Image, GR32_Transforms, - ExtDlgs; - -type - TMainForm = class(TForm) - PopupMenu: TPopupMenu; - ZoomInItem: TMenuItem; - ZoomOutItem: TMenuItem; - ActualSizeItem: TMenuItem; - ImgView32: TImgView32; - N1: TMenuItem; - AlphaView: TImgView32; - ShowAlphaItem: TMenuItem; - RotateClockwiseItem: TMenuItem; - RotateAntiClockwiseItem: TMenuItem; - N3: TMenuItem; - ShowWithAlphaItem: TMenuItem; - N4: TMenuItem; - FlipHorizontalItem: TMenuItem; - FilpVerticalItem: TMenuItem; - FilterTimer: TTimer; - OpenImageItem: TMenuItem; - N2: TMenuItem; - OpenDialog: TOpenDialog; - procedure FormCreate(Sender: TObject); - procedure FormDestroy(Sender: TObject); - procedure FormShow(Sender: TObject); - procedure ZoomInItemClick(Sender: TObject); - procedure ZoomOutItemClick(Sender: TObject); - procedure ActualSizeItemClick(Sender: TObject); - procedure ScrollBoxMouseWheel(Sender: TObject; Shift: TShiftState; - WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); - procedure FormKeyUp(Sender: TObject; var Key: Word; - Shift: TShiftState); - procedure ShowAlphaItemClick(Sender: TObject); - procedure RotateClockwiseItemClick(Sender: TObject); - procedure RotateAntiClockwiseItemClick(Sender: TObject); - procedure ShowWithAlphaItemClick(Sender: TObject); - procedure FlipHorizontalItemClick(Sender: TObject); - procedure FilpVerticalItemClick(Sender: TObject); - procedure FilterTimerTimer(Sender: TObject); - procedure ImgView32Scroll(Sender: TObject); - procedure OpenImageItemClick(Sender: TObject); - private - { Private declarations } - OrigWidth : integer; - OrigHeight : integer; - BPP : longword; - - procedure LoadImage( Name : string); - procedure RecalcWindowSize; - public - { Public declarations } - end; - -var - MainForm: TMainForm; - -implementation - -{$R *.dfm} - -uses FreeImage, GR32_Resamplers; - -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- -procedure TMainForm.FormCreate(Sender: TObject); -begin - AlphaView.Visible := False; - AlphaView.Align := alClient; -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.FormDestroy(Sender: TObject); -begin - // ... -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.FormShow(Sender: TObject); -var - Resampler: TKernelResampler; -begin - Resampler := TKernelResampler.Create(ImgView32.Bitmap); - Resampler.Kernel := TSplineKernel.Create; - if ParamCount = 1 then - LoadImage(ParamStr(1)); -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.LoadImage( Name : string); -var - dib : PFIBITMAP; - PBH : PBITMAPINFOHEADER; - PBI : PBITMAPINFO; - t : FREE_IMAGE_FORMAT; - Ext : string; - BM : TBitmap; - x, y : integer; - BP : PLONGWORD; - DC : HDC; -begin - try - t := FreeImage_GetFileType(PAnsiChar(AnsiString(Name)), 16); - - if t = FIF_UNKNOWN then - begin - // Check for types not supported by GetFileType - Ext := UpperCase(ExtractFileExt(Name)); - if (Ext = '.TGA') or(Ext = '.TARGA') then - t := FIF_TARGA - else if Ext = '.MNG' then - t := FIF_MNG - else if Ext = '.PCD' then - t := FIF_PCD - else if Ext = '.WBMP' then - t := FIF_WBMP - else if Ext = '.CUT' then - t := FIF_CUT - else - raise Exception.Create('The file "' + Name + '" cannot be displayed because SFM does not recognise the file type.'); - end; - - dib := FreeImage_Load(t, PAnsiChar(AnsiString(name)), 0); - if Dib = nil then - Close; - PBH := FreeImage_GetInfoHeader(dib); - PBI := FreeImage_GetInfo(dib); - - BPP := FreeImage_GetBPP(dib); - - ShowWithAlphaItem.Enabled := BPP = 32; - ShowAlphaItem.Enabled := BPP = 32; - - if BPP = 32 then - begin - ImgView32.Bitmap.SetSize(FreeImage_GetWidth(dib), FreeImage_GetHeight(dib)); - - BP := PLONGWORD(FreeImage_GetBits(dib)); - for y := ImgView32.Bitmap.Height - 1 downto 0 do - for x := 0 to ImgView32.Bitmap.Width - 1 do - begin - ImgView32.Bitmap.Pixel[x, y] := BP^; - inc(BP); - end; - end - else - begin - BM := TBitmap.Create; - - BM.Assign(nil); - DC := GetDC(Handle); - - BM.handle := CreateDIBitmap(DC, - PBH^, - CBM_INIT, - PChar(FreeImage_GetBits(dib)), - PBI^, - DIB_RGB_COLORS); - - ImgView32.Bitmap.Assign(BM); - AlphaView.Bitmap.Assign(BM); - - BM.Free; - ReleaseDC(Handle, DC); - end; - FreeImage_Unload(dib); - - OrigWidth := ImgView32.Bitmap.Width; - OrigHeight := ImgView32.Bitmap.Height; - - Caption := ExtractFileName( Name ) + ' (' + IntToStr(OrigWidth) + - ' x ' + IntToStr(OrigHeight) + ')'; - if BPP = 32 then - Caption := Caption + ' + Alpha'; - - AlphaView.Bitmap.SetSize(OrigWidth, OrigWidth); - - ImgView32.Hint := 'Name: ' + Name + #13 + - 'Width: ' + IntToStr(OrigWidth) + #13 + - 'Height: ' + IntToStr(OrigHeight) + #13 + - 'BPP: ' + IntToStr(BPP); - - RecalcWindowSize; - - Show; - except - on e:exception do - begin - Application.BringToFront; - MessageDlg(e.message, mtInformation, [mbOK], 0); - Close; - end; - end; -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.ZoomInItemClick(Sender: TObject); -begin - FilterTimer.Enabled := False; - if not (ImgView32.Bitmap.Resampler is TNearestResampler) then - TNearestResampler.Create(ImgView32.Bitmap); - FilterTimer.Enabled := True; - - ImgView32.Scale := ImgView32.Scale * 2.0; - RecalcWindowSize; -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.ZoomOutItemClick(Sender: TObject); -begin - FilterTimer.Enabled := False; - if not (ImgView32.Bitmap.Resampler is TNearestResampler) then - TNearestResampler.Create(ImgView32.Bitmap); - FilterTimer.Enabled := True; - - ImgView32.Scale := ImgView32.Scale / 2.0; - RecalcWindowSize; -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.ActualSizeItemClick(Sender: TObject); -begin - FilterTimer.Enabled := False; - if not (ImgView32.Bitmap.Resampler is TNearestResampler) then - TNearestResampler.Create(ImgView32.Bitmap); - FilterTimer.Enabled := True; - - ImgView32.Scale := 1.0; - - RecalcWindowSize; -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.RecalcWindowSize; -var - Rect : TRect; - CW, CH : integer; - WSH, WSW : integer; - TitleH : integer; - BorderY : integer; - BorderX : integer; -begin - CW := ImgView32.Bitmap.Width + GetSystemMetrics(SM_CXVSCROLL); - CH := ImgView32.Bitmap.Height + GetSystemMetrics(SM_CYVSCROLL); - - SystemParametersInfo( SPI_GETWORKAREA, 0, @Rect, 0); - - WSH := Rect.Bottom - Rect.Top; - WSW := Rect.Right - Rect.Left; - TitleH := GetSystemMetrics(SM_CYCAPTION); - BorderY := GetSystemMetrics(SM_CYSIZEFRAME) * 2; - BorderX := GetSystemMetrics(SM_CXSIZEFRAME) * 2; - - if (Top + CH + TitleH + BorderY > WSH) or (CH + TitleH + BorderY > WSH) then - begin - Top := Rect.Bottom - CH - BorderY; - if Top < 0 then - begin - Top := 0; - CH := WSH - TitleH - BorderY; - CW := CW + GetSystemMetrics(SM_CXVSCROLL); - - if CW + BorderX > WSW then - CH := CH - GetSystemMetrics(SM_CYVSCROLL); - end; - end; - - if (Left + CW + BorderX > WSW) or (CW + BorderX > WSW) then - begin - Left := Rect.Right - CW - BorderX; - if Left < 0 then - begin - Left := 0; - CW := WSW - BorderX; - CH := CH + GetSystemMetrics(SM_CYVSCROLL); - - if CH + TitleH + BorderY > WSH then - CW := CW + GetSystemMetrics(SM_CXVSCROLL); - end - end; - - ClientWidth := CW; - ClientHeight := CH; -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.ScrollBoxMouseWheel(Sender: TObject; - Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; - var Handled: Boolean); -begin - FilterTimer.Enabled := False; - if not (ImgView32.Bitmap.Resampler is TNearestResampler) then - TNearestResampler.Create(ImgView32.Bitmap); - FilterTimer.Enabled := True; - - if WheelDelta < 0 then - ImgView32.Scroll(0, 20) - else - ImgView32.Scroll(0, -20); - Handled := True; -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word; - Shift: TShiftState); -var - Amount : integer; -begin - FilterTimer.Enabled := False; - if not (ImgView32.Bitmap.Resampler is TNearestResampler) then - TNearestResampler.Create(ImgView32.Bitmap); - FilterTimer.Enabled := True; - - if ssShift in Shift then - Amount := 20 * 2 - else - Amount := 20; - - case Key of - VK_ESCAPE: - Close; - VK_UP: - ImgView32.Scroll(0, -Amount); - VK_DOWN: - ImgView32.Scroll(0, Amount); - VK_LEFT: - ImgView32.Scroll(-Amount, 0); - VK_RIGHT: - ImgView32.Scroll(Amount, 0); - VK_HOME: - ImgView32.ScrollToCenter(0, 0); - VK_END: - ImgView32.ScrollToCenter(ImgView32.Bitmap.Width, ImgView32.Bitmap.Height); - VK_NEXT: - ImgView32.Scroll(0, (Trunc(ImgView32.Bitmap.Height div 4))); - VK_PRIOR: - ImgView32.Scroll(0, -(Trunc(ImgView32.Bitmap.Height div 4))); - end; -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.ShowAlphaItemClick(Sender: TObject); -var - x, y : integer; - Col : TColor32; - Alpha : TColor; -begin - if ShowAlphaItem.Checked then - begin - AlphaView.Visible := False; - AlphaView.Bitmap.Delete; - end - else - begin - AlphaView.Bitmap.Width := ImgView32.Bitmap.Width; - AlphaView.Bitmap.Height := ImgView32.Bitmap.Height; - - for x := 0 to AlphaView.Bitmap.Width - 1 do - for y := 0 to AlphaView.Bitmap.Height - 1 do - begin - Col := ImgView32.Bitmap.Pixel[x, y]; - Alpha := Col shr 24; - AlphaView.Bitmap.Pixel[x, y] := Alpha + (Alpha shl 8) + (Alpha shl 16); - end; - AlphaView.Visible := True; - end; - ShowAlphaItem.Checked := not ShowAlphaItem.Checked; -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.RotateClockwiseItemClick(Sender: TObject); -var - x : integer; - y : integer; - DestX : integer; - DestY : integer; - C : TColor32; -begin - AlphaView.Bitmap.Assign(ImgView32.Bitmap); - - ImgView32.BeginUpdate; - ImgView32.Bitmap.Width := AlphaView.Bitmap.Height; - ImgView32.Bitmap.Height := AlphaView.Bitmap.Width; - - for x := 0 to AlphaView.Bitmap.Width - 1 do - for y := 0 to AlphaView.Bitmap.Height - 1 do - begin - C := AlphaView.Bitmap.Pixel[x, y]; - - DestX := (ImgView32.Bitmap.Width - 1) - Y; - DestY := X; - - ImgView32.Bitmap.Pixels[DestX, DestY] := C; - end; - - ImgView32.EndUpdate; - ImgView32.Refresh; -end; - -// ----------------------------------------------------------------------------- -procedure TMainForm.RotateAntiClockwiseItemClick(Sender: TObject); -var - x : integer; - y : integer; - DestX : integer; - DestY : integer; - C : TColor32; -begin - AlphaView.Bitmap.Assign(ImgView32.Bitmap); - - ImgView32.BeginUpdate; - ImgView32.Bitmap.Width := AlphaView.Bitmap.Height; - ImgView32.Bitmap.Height := AlphaView.Bitmap.Width; - - for x := 0 to AlphaView.Bitmap.Width - 1 do - for y := 0 to AlphaView.Bitmap.Height - 1 do - begin - C := AlphaView.Bitmap.Pixel[x, y]; - - DestX := Y; - DestY := (ImgView32.Bitmap.Height - 1) -X; - - ImgView32.Bitmap.Pixels[DestX, DestY] := C; - end; - - ImgView32.EndUpdate; - ImgView32.Refresh; -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.ShowWithAlphaItemClick(Sender: TObject); -begin - if ShowWithAlphaItem.Checked then - ImgView32.Bitmap.DrawMode := dmOpaque - else - ImgView32.Bitmap.DrawMode := dmBlend; - ShowWithAlphaItem.Checked := not ShowWithAlphaItem.Checked; -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.FlipHorizontalItemClick(Sender: TObject); -var - x : integer; - y : integer; - DestX : integer; - DestY : integer; - C : TColor32; -begin - AlphaView.Bitmap.Assign(ImgView32.Bitmap); - - ImgView32.BeginUpdate; - ImgView32.Bitmap.Width := AlphaView.Bitmap.Width; - ImgView32.Bitmap.Height := AlphaView.Bitmap.Height; - - for x := 0 to AlphaView.Bitmap.Width - 1 do - for y := 0 to AlphaView.Bitmap.Height - 1 do - begin - C := AlphaView.Bitmap.Pixel[x, y]; - - DestX := (ImgView32.Bitmap.Width - 1) -X; - DestY := Y; - - ImgView32.Bitmap.Pixels[DestX, DestY] := C; - end; - - ImgView32.EndUpdate; - ImgView32.Refresh; -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.FilpVerticalItemClick(Sender: TObject); -var - x : integer; - y : integer; - DestX : integer; - DestY : integer; - C : TColor32; -begin - AlphaView.Bitmap.Assign(ImgView32.Bitmap); - - ImgView32.BeginUpdate; - ImgView32.Bitmap.Width := AlphaView.Bitmap.Width; - ImgView32.Bitmap.Height := AlphaView.Bitmap.Height; - - for x := 0 to AlphaView.Bitmap.Width - 1 do - for y := 0 to AlphaView.Bitmap.Height - 1 do - begin - C := AlphaView.Bitmap.Pixel[x, y]; - - DestX := X; - DestY := (ImgView32.Bitmap.Height - 1) - Y; - - ImgView32.Bitmap.Pixels[DestX, DestY] := C; - end; - - ImgView32.EndUpdate; - ImgView32.Refresh; -end; - -// ----------------------------------------------------------------------------- -procedure TMainForm.FilterTimerTimer(Sender: TObject); -var - Resampler: TKernelResampler; -begin - FilterTimer.Enabled := False; - Resampler := TKernelResampler.Create(ImgView32.Bitmap); - Resampler.Kernel := TSplineKernel.Create; -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.ImgView32Scroll(Sender: TObject); -begin - FilterTimer.Enabled := False; - if not (ImgView32.Bitmap.Resampler is TNearestResampler) then - TNearestResampler.Create(ImgView32.Bitmap); - FilterTimer.Enabled := True; -end; -// ----------------------------------------------------------------------------- -procedure TMainForm.OpenImageItemClick(Sender: TObject); -begin - if OpenDialog.Execute then - begin - try - Screen.Cursor := crHourGlass; - LoadImage(OpenDialog.FileName); - finally - Screen.Cursor := crDefault; - end; - end; -end; - -end. +unit MainFrm; + +interface + +uses + Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, + Dialogs, Menus, ExtCtrls, Math, GR32, GR32_Image, GR32_Transforms, + ExtDlgs; + +type + TMainForm = class(TForm) + PopupMenu: TPopupMenu; + ZoomInItem: TMenuItem; + ZoomOutItem: TMenuItem; + ActualSizeItem: TMenuItem; + ImgView32: TImgView32; + N1: TMenuItem; + AlphaView: TImgView32; + ShowAlphaItem: TMenuItem; + RotateClockwiseItem: TMenuItem; + RotateAntiClockwiseItem: TMenuItem; + N3: TMenuItem; + ShowWithAlphaItem: TMenuItem; + N4: TMenuItem; + FlipHorizontalItem: TMenuItem; + FilpVerticalItem: TMenuItem; + FilterTimer: TTimer; + OpenImageItem: TMenuItem; + N2: TMenuItem; + OpenDialog: TOpenDialog; + procedure FormCreate(Sender: TObject); + procedure FormDestroy(Sender: TObject); + procedure FormShow(Sender: TObject); + procedure ZoomInItemClick(Sender: TObject); + procedure ZoomOutItemClick(Sender: TObject); + procedure ActualSizeItemClick(Sender: TObject); + procedure ScrollBoxMouseWheel(Sender: TObject; Shift: TShiftState; + WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); + procedure FormKeyUp(Sender: TObject; var Key: Word; + Shift: TShiftState); + procedure ShowAlphaItemClick(Sender: TObject); + procedure RotateClockwiseItemClick(Sender: TObject); + procedure RotateAntiClockwiseItemClick(Sender: TObject); + procedure ShowWithAlphaItemClick(Sender: TObject); + procedure FlipHorizontalItemClick(Sender: TObject); + procedure FilpVerticalItemClick(Sender: TObject); + procedure FilterTimerTimer(Sender: TObject); + procedure ImgView32Scroll(Sender: TObject); + procedure OpenImageItemClick(Sender: TObject); + private + { Private declarations } + OrigWidth : integer; + OrigHeight : integer; + BPP : longword; + + procedure LoadImage( Name : string); + procedure RecalcWindowSize; + public + { Public declarations } + end; + +var + MainForm: TMainForm; + +implementation + +{$R *.dfm} + +uses FreeImage, GR32_Resamplers; + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +procedure TMainForm.FormCreate(Sender: TObject); +begin + AlphaView.Visible := False; + AlphaView.Align := alClient; +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.FormDestroy(Sender: TObject); +begin + // ... +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.FormShow(Sender: TObject); +var + Resampler: TKernelResampler; +begin + Resampler := TKernelResampler.Create(ImgView32.Bitmap); + Resampler.Kernel := TSplineKernel.Create; + if ParamCount = 1 then + LoadImage(ParamStr(1)); +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.LoadImage( Name : string); +var + dib : PFIBITMAP; + PBH : PBITMAPINFOHEADER; + PBI : PBITMAPINFO; + t : FREE_IMAGE_FORMAT; + Ext : string; + BM : TBitmap; + x, y : integer; + BP : PLONGWORD; + DC : HDC; +begin + try + t := FreeImage_GetFileType(PAnsiChar(AnsiString(Name)), 16); + + if t = FIF_UNKNOWN then + begin + // Check for types not supported by GetFileType + Ext := UpperCase(ExtractFileExt(Name)); + if (Ext = '.TGA') or(Ext = '.TARGA') then + t := FIF_TARGA + else if Ext = '.MNG' then + t := FIF_MNG + else if Ext = '.PCD' then + t := FIF_PCD + else if Ext = '.WBMP' then + t := FIF_WBMP + else if Ext = '.CUT' then + t := FIF_CUT + else + raise Exception.Create('The file "' + Name + '" cannot be displayed because SFM does not recognise the file type.'); + end; + + dib := FreeImage_Load(t, PAnsiChar(AnsiString(name)), 0); + if Dib = nil then + Close; + PBH := FreeImage_GetInfoHeader(dib); + PBI := FreeImage_GetInfo(dib); + + BPP := FreeImage_GetBPP(dib); + + ShowWithAlphaItem.Enabled := BPP = 32; + ShowAlphaItem.Enabled := BPP = 32; + + if BPP = 32 then + begin + ImgView32.Bitmap.SetSize(FreeImage_GetWidth(dib), FreeImage_GetHeight(dib)); + + BP := PLONGWORD(FreeImage_GetBits(dib)); + for y := ImgView32.Bitmap.Height - 1 downto 0 do + for x := 0 to ImgView32.Bitmap.Width - 1 do + begin + ImgView32.Bitmap.Pixel[x, y] := BP^; + inc(BP); + end; + end + else + begin + BM := TBitmap.Create; + + BM.Assign(nil); + DC := GetDC(Handle); + + BM.handle := CreateDIBitmap(DC, + PBH^, + CBM_INIT, + PChar(FreeImage_GetBits(dib)), + PBI^, + DIB_RGB_COLORS); + + ImgView32.Bitmap.Assign(BM); + AlphaView.Bitmap.Assign(BM); + + BM.Free; + ReleaseDC(Handle, DC); + end; + FreeImage_Unload(dib); + + OrigWidth := ImgView32.Bitmap.Width; + OrigHeight := ImgView32.Bitmap.Height; + + Caption := ExtractFileName( Name ) + ' (' + IntToStr(OrigWidth) + + ' x ' + IntToStr(OrigHeight) + ')'; + if BPP = 32 then + Caption := Caption + ' + Alpha'; + + AlphaView.Bitmap.SetSize(OrigWidth, OrigWidth); + + ImgView32.Hint := 'Name: ' + Name + #13 + + 'Width: ' + IntToStr(OrigWidth) + #13 + + 'Height: ' + IntToStr(OrigHeight) + #13 + + 'BPP: ' + IntToStr(BPP); + + RecalcWindowSize; + + Show; + except + on e:exception do + begin + Application.BringToFront; + MessageDlg(e.message, mtInformation, [mbOK], 0); + Close; + end; + end; +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.ZoomInItemClick(Sender: TObject); +begin + FilterTimer.Enabled := False; + if not (ImgView32.Bitmap.Resampler is TNearestResampler) then + TNearestResampler.Create(ImgView32.Bitmap); + FilterTimer.Enabled := True; + + ImgView32.Scale := ImgView32.Scale * 2.0; + RecalcWindowSize; +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.ZoomOutItemClick(Sender: TObject); +begin + FilterTimer.Enabled := False; + if not (ImgView32.Bitmap.Resampler is TNearestResampler) then + TNearestResampler.Create(ImgView32.Bitmap); + FilterTimer.Enabled := True; + + ImgView32.Scale := ImgView32.Scale / 2.0; + RecalcWindowSize; +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.ActualSizeItemClick(Sender: TObject); +begin + FilterTimer.Enabled := False; + if not (ImgView32.Bitmap.Resampler is TNearestResampler) then + TNearestResampler.Create(ImgView32.Bitmap); + FilterTimer.Enabled := True; + + ImgView32.Scale := 1.0; + + RecalcWindowSize; +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.RecalcWindowSize; +var + Rect : TRect; + CW, CH : integer; + WSH, WSW : integer; + TitleH : integer; + BorderY : integer; + BorderX : integer; +begin + CW := ImgView32.Bitmap.Width + GetSystemMetrics(SM_CXVSCROLL); + CH := ImgView32.Bitmap.Height + GetSystemMetrics(SM_CYVSCROLL); + + SystemParametersInfo( SPI_GETWORKAREA, 0, @Rect, 0); + + WSH := Rect.Bottom - Rect.Top; + WSW := Rect.Right - Rect.Left; + TitleH := GetSystemMetrics(SM_CYCAPTION); + BorderY := GetSystemMetrics(SM_CYSIZEFRAME) * 2; + BorderX := GetSystemMetrics(SM_CXSIZEFRAME) * 2; + + if (Top + CH + TitleH + BorderY > WSH) or (CH + TitleH + BorderY > WSH) then + begin + Top := Rect.Bottom - CH - BorderY; + if Top < 0 then + begin + Top := 0; + CH := WSH - TitleH - BorderY; + CW := CW + GetSystemMetrics(SM_CXVSCROLL); + + if CW + BorderX > WSW then + CH := CH - GetSystemMetrics(SM_CYVSCROLL); + end; + end; + + if (Left + CW + BorderX > WSW) or (CW + BorderX > WSW) then + begin + Left := Rect.Right - CW - BorderX; + if Left < 0 then + begin + Left := 0; + CW := WSW - BorderX; + CH := CH + GetSystemMetrics(SM_CYVSCROLL); + + if CH + TitleH + BorderY > WSH then + CW := CW + GetSystemMetrics(SM_CXVSCROLL); + end + end; + + ClientWidth := CW; + ClientHeight := CH; +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.ScrollBoxMouseWheel(Sender: TObject; + Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; + var Handled: Boolean); +begin + FilterTimer.Enabled := False; + if not (ImgView32.Bitmap.Resampler is TNearestResampler) then + TNearestResampler.Create(ImgView32.Bitmap); + FilterTimer.Enabled := True; + + if WheelDelta < 0 then + ImgView32.Scroll(0, 20) + else + ImgView32.Scroll(0, -20); + Handled := True; +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word; + Shift: TShiftState); +var + Amount : integer; +begin + FilterTimer.Enabled := False; + if not (ImgView32.Bitmap.Resampler is TNearestResampler) then + TNearestResampler.Create(ImgView32.Bitmap); + FilterTimer.Enabled := True; + + if ssShift in Shift then + Amount := 20 * 2 + else + Amount := 20; + + case Key of + VK_ESCAPE: + Close; + VK_UP: + ImgView32.Scroll(0, -Amount); + VK_DOWN: + ImgView32.Scroll(0, Amount); + VK_LEFT: + ImgView32.Scroll(-Amount, 0); + VK_RIGHT: + ImgView32.Scroll(Amount, 0); + VK_HOME: + ImgView32.ScrollToCenter(0, 0); + VK_END: + ImgView32.ScrollToCenter(ImgView32.Bitmap.Width, ImgView32.Bitmap.Height); + VK_NEXT: + ImgView32.Scroll(0, (Trunc(ImgView32.Bitmap.Height div 4))); + VK_PRIOR: + ImgView32.Scroll(0, -(Trunc(ImgView32.Bitmap.Height div 4))); + end; +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.ShowAlphaItemClick(Sender: TObject); +var + x, y : integer; + Col : TColor32; + Alpha : TColor; +begin + if ShowAlphaItem.Checked then + begin + AlphaView.Visible := False; + AlphaView.Bitmap.Delete; + end + else + begin + AlphaView.Bitmap.Width := ImgView32.Bitmap.Width; + AlphaView.Bitmap.Height := ImgView32.Bitmap.Height; + + for x := 0 to AlphaView.Bitmap.Width - 1 do + for y := 0 to AlphaView.Bitmap.Height - 1 do + begin + Col := ImgView32.Bitmap.Pixel[x, y]; + Alpha := Col shr 24; + AlphaView.Bitmap.Pixel[x, y] := Alpha + (Alpha shl 8) + (Alpha shl 16); + end; + AlphaView.Visible := True; + end; + ShowAlphaItem.Checked := not ShowAlphaItem.Checked; +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.RotateClockwiseItemClick(Sender: TObject); +var + x : integer; + y : integer; + DestX : integer; + DestY : integer; + C : TColor32; +begin + AlphaView.Bitmap.Assign(ImgView32.Bitmap); + + ImgView32.BeginUpdate; + ImgView32.Bitmap.Width := AlphaView.Bitmap.Height; + ImgView32.Bitmap.Height := AlphaView.Bitmap.Width; + + for x := 0 to AlphaView.Bitmap.Width - 1 do + for y := 0 to AlphaView.Bitmap.Height - 1 do + begin + C := AlphaView.Bitmap.Pixel[x, y]; + + DestX := (ImgView32.Bitmap.Width - 1) - Y; + DestY := X; + + ImgView32.Bitmap.Pixels[DestX, DestY] := C; + end; + + ImgView32.EndUpdate; + ImgView32.Refresh; +end; + +// ----------------------------------------------------------------------------- +procedure TMainForm.RotateAntiClockwiseItemClick(Sender: TObject); +var + x : integer; + y : integer; + DestX : integer; + DestY : integer; + C : TColor32; +begin + AlphaView.Bitmap.Assign(ImgView32.Bitmap); + + ImgView32.BeginUpdate; + ImgView32.Bitmap.Width := AlphaView.Bitmap.Height; + ImgView32.Bitmap.Height := AlphaView.Bitmap.Width; + + for x := 0 to AlphaView.Bitmap.Width - 1 do + for y := 0 to AlphaView.Bitmap.Height - 1 do + begin + C := AlphaView.Bitmap.Pixel[x, y]; + + DestX := Y; + DestY := (ImgView32.Bitmap.Height - 1) -X; + + ImgView32.Bitmap.Pixels[DestX, DestY] := C; + end; + + ImgView32.EndUpdate; + ImgView32.Refresh; +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.ShowWithAlphaItemClick(Sender: TObject); +begin + if ShowWithAlphaItem.Checked then + ImgView32.Bitmap.DrawMode := dmOpaque + else + ImgView32.Bitmap.DrawMode := dmBlend; + ShowWithAlphaItem.Checked := not ShowWithAlphaItem.Checked; +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.FlipHorizontalItemClick(Sender: TObject); +var + x : integer; + y : integer; + DestX : integer; + DestY : integer; + C : TColor32; +begin + AlphaView.Bitmap.Assign(ImgView32.Bitmap); + + ImgView32.BeginUpdate; + ImgView32.Bitmap.Width := AlphaView.Bitmap.Width; + ImgView32.Bitmap.Height := AlphaView.Bitmap.Height; + + for x := 0 to AlphaView.Bitmap.Width - 1 do + for y := 0 to AlphaView.Bitmap.Height - 1 do + begin + C := AlphaView.Bitmap.Pixel[x, y]; + + DestX := (ImgView32.Bitmap.Width - 1) -X; + DestY := Y; + + ImgView32.Bitmap.Pixels[DestX, DestY] := C; + end; + + ImgView32.EndUpdate; + ImgView32.Refresh; +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.FilpVerticalItemClick(Sender: TObject); +var + x : integer; + y : integer; + DestX : integer; + DestY : integer; + C : TColor32; +begin + AlphaView.Bitmap.Assign(ImgView32.Bitmap); + + ImgView32.BeginUpdate; + ImgView32.Bitmap.Width := AlphaView.Bitmap.Width; + ImgView32.Bitmap.Height := AlphaView.Bitmap.Height; + + for x := 0 to AlphaView.Bitmap.Width - 1 do + for y := 0 to AlphaView.Bitmap.Height - 1 do + begin + C := AlphaView.Bitmap.Pixel[x, y]; + + DestX := X; + DestY := (ImgView32.Bitmap.Height - 1) - Y; + + ImgView32.Bitmap.Pixels[DestX, DestY] := C; + end; + + ImgView32.EndUpdate; + ImgView32.Refresh; +end; + +// ----------------------------------------------------------------------------- +procedure TMainForm.FilterTimerTimer(Sender: TObject); +var + Resampler: TKernelResampler; +begin + FilterTimer.Enabled := False; + Resampler := TKernelResampler.Create(ImgView32.Bitmap); + Resampler.Kernel := TSplineKernel.Create; +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.ImgView32Scroll(Sender: TObject); +begin + FilterTimer.Enabled := False; + if not (ImgView32.Bitmap.Resampler is TNearestResampler) then + TNearestResampler.Create(ImgView32.Bitmap); + FilterTimer.Enabled := True; +end; +// ----------------------------------------------------------------------------- +procedure TMainForm.OpenImageItemClick(Sender: TObject); +begin + if OpenDialog.Execute then + begin + try + Screen.Cursor := crHourGlass; + LoadImage(OpenDialog.FileName); + finally + Screen.Cursor := crDefault; + end; + end; +end; + +end. diff --git a/Wrapper/Delphi/demo/ImagePreview/Readme.txt b/Wrapper/Delphi/demo/ImagePreview/Readme.txt index f7f1a7d..bb10764 100644 --- a/Wrapper/Delphi/demo/ImagePreview/Readme.txt +++ b/Wrapper/Delphi/demo/ImagePreview/Readme.txt @@ -1,8 +1,8 @@ -This is a simple image viewing application that uses the FreeImage library to display images in many different formats. - -The app displays the image whose name is passed in as a command line argument. - - -To compile the app you will also need the Graphics32 library available from www.g32.org. It has been tested with version 1.5.1 of Graphics32. - -SJB. +This is a simple image viewing application that uses the FreeImage library to display images in many different formats. + +The app displays the image whose name is passed in as a command line argument. + + +To compile the app you will also need the Graphics32 library available from www.g32.org. It has been tested with version 1.5.1 of Graphics32. + +SJB. diff --git a/Wrapper/Delphi/demo/MultiBitmap/MultiBitmap.stat b/Wrapper/Delphi/demo/MultiBitmap/MultiBitmap.stat index 6e11772..0acf82a 100644 --- a/Wrapper/Delphi/demo/MultiBitmap/MultiBitmap.stat +++ b/Wrapper/Delphi/demo/MultiBitmap/MultiBitmap.stat @@ -1,10 +1,10 @@ -[Stats] -EditorSecs=82 -DesignerSecs=5 -InspectorSecs=1 -CompileSecs=850 -OtherSecs=5 -StartTime=20.12.2004 11:40:22 -RealKeys=0 -EffectiveKeys=0 -DebugSecs=19 +[Stats] +EditorSecs=82 +DesignerSecs=5 +InspectorSecs=1 +CompileSecs=850 +OtherSecs=5 +StartTime=20.12.2004 11:40:22 +RealKeys=0 +EffectiveKeys=0 +DebugSecs=19 diff --git a/Wrapper/Delphi/demo/MultiBitmap/mbMainForm.pas b/Wrapper/Delphi/demo/MultiBitmap/mbMainForm.pas index 07fd997..36c1fa0 100644 --- a/Wrapper/Delphi/demo/MultiBitmap/mbMainForm.pas +++ b/Wrapper/Delphi/demo/MultiBitmap/mbMainForm.pas @@ -1,150 +1,150 @@ -unit mbMainForm; - -interface - -uses - Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, - Dialogs, ComCtrls, ToolWin, StdCtrls, FreeBitmap; - -type - TMainForm = class(TForm) - ToolBar: TToolBar; - tbLoad: TToolButton; - ToolButton1: TToolButton; - tbClose: TToolButton; - ToolButton2: TToolButton; - cbPages: TComboBox; - Label1: TLabel; - OD: TOpenDialog; - procedure tbLoadClick(Sender: TObject); - procedure FormPaint(Sender: TObject); - procedure tbCloseClick(Sender: TObject); - procedure cbPagesChange(Sender: TObject); - procedure FormResize(Sender: TObject); - private - FMultiBitmap: TFreeMultiBitmap; - FPage: TFreeWinBitmap; - - procedure PageBitmapChangeHandler(Sender: TObject); - procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND; - public - constructor Create(AOwner: TComponent); override; - destructor Destroy; override; - - procedure OpenMultiBitmap(const FileName: string); - procedure CloseMultiBitmap; - procedure OpenPage(Number: Integer); - end; - -var - MainForm: TMainForm; - -implementation - -{$R *.dfm} - -{ TMainForm } - -procedure TMainForm.CloseMultiBitmap; -begin - if FPage.IsValid then - FMultiBitmap.UnlockPage(Fpage, False); - FMultiBitmap.Close; - cbPages.Clear; -end; - -constructor TMainForm.Create(AOwner: TComponent); -begin - inherited; - FMultiBitmap := TFreeMultiBitmap.Create; - FPage := TFreeWinBitmap.Create; - FPage.OnChange := PageBitmapChangeHandler; -end; - -destructor TMainForm.Destroy; -begin - if FMultiBitmap.IsValid then - CloseMultiBitmap; - FMultiBitmap.Free; - inherited; -end; - -procedure TMainForm.OpenMultiBitmap(const FileName: string); -var - I, Cnt: Integer; -begin - if FMultiBitmap.IsValid then CloseMultiBitmap; - - FMultiBitmap.Open(FileName, False, True); - - Cnt := FMultiBitmap.GetPageCount; - cbPages.OnChange := nil; - cbPages.Clear; - for I := 0 to Cnt - 1 do - cbPages.Items.Add(IntToStr(I)); - cbPages.OnChange := cbPagesChange; -end; - -procedure TMainForm.OpenPage(Number: Integer); -begin - if not FMultiBitmap.IsValid then Exit; - - if FPage.IsValid then - FMultiBitmap.UnlockPage(FPage, False); - - FMultiBitmap.LockPage(Number, FPage); -end; - -procedure TMainForm.PageBitmapChangeHandler(Sender: TObject); -begin - Invalidate; -end; - -procedure TMainForm.tbLoadClick(Sender: TObject); -begin - if OD.Execute then - begin - try - OpenMultiBitmap(OD.FileName); - except - raise Exception.CreateFmt('Can not load file %s', [OD.FileName]); - end; - end; -end; - -procedure TMainForm.WMEraseBkgnd(var Message: TWMEraseBkgnd); -begin - Message.Result := 1; -end; - -procedure TMainForm.FormPaint(Sender: TObject); -begin - if not FPage.IsValid then - begin - Canvas.Brush.Color := clBtnFace; - Canvas.FillRect(ClientRect); - end - else - FPage.Draw(Canvas.Handle, ClientRect); -end; - -procedure TMainForm.tbCloseClick(Sender: TObject); -begin - if FMultiBitmap.IsValid then - CloseMultiBitmap; -end; - -procedure TMainForm.cbPagesChange(Sender: TObject); -var - Page: Integer; -begin - Page := StrToInt(cbPages.Text); - OpenPage(Page); -end; - -procedure TMainForm.FormResize(Sender: TObject); -begin - Invalidate; -end; - -end. +unit mbMainForm; + +interface + +uses + Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, + Dialogs, ComCtrls, ToolWin, StdCtrls, FreeBitmap; + +type + TMainForm = class(TForm) + ToolBar: TToolBar; + tbLoad: TToolButton; + ToolButton1: TToolButton; + tbClose: TToolButton; + ToolButton2: TToolButton; + cbPages: TComboBox; + Label1: TLabel; + OD: TOpenDialog; + procedure tbLoadClick(Sender: TObject); + procedure FormPaint(Sender: TObject); + procedure tbCloseClick(Sender: TObject); + procedure cbPagesChange(Sender: TObject); + procedure FormResize(Sender: TObject); + private + FMultiBitmap: TFreeMultiBitmap; + FPage: TFreeWinBitmap; + + procedure PageBitmapChangeHandler(Sender: TObject); + procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND; + public + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + + procedure OpenMultiBitmap(const FileName: string); + procedure CloseMultiBitmap; + procedure OpenPage(Number: Integer); + end; + +var + MainForm: TMainForm; + +implementation + +{$R *.dfm} + +{ TMainForm } + +procedure TMainForm.CloseMultiBitmap; +begin + if FPage.IsValid then + FMultiBitmap.UnlockPage(Fpage, False); + FMultiBitmap.Close; + cbPages.Clear; +end; + +constructor TMainForm.Create(AOwner: TComponent); +begin + inherited; + FMultiBitmap := TFreeMultiBitmap.Create; + FPage := TFreeWinBitmap.Create; + FPage.OnChange := PageBitmapChangeHandler; +end; + +destructor TMainForm.Destroy; +begin + if FMultiBitmap.IsValid then + CloseMultiBitmap; + FMultiBitmap.Free; + inherited; +end; + +procedure TMainForm.OpenMultiBitmap(const FileName: string); +var + I, Cnt: Integer; +begin + if FMultiBitmap.IsValid then CloseMultiBitmap; + + FMultiBitmap.Open(FileName, False, True); + + Cnt := FMultiBitmap.GetPageCount; + cbPages.OnChange := nil; + cbPages.Clear; + for I := 0 to Cnt - 1 do + cbPages.Items.Add(IntToStr(I)); + cbPages.OnChange := cbPagesChange; +end; + +procedure TMainForm.OpenPage(Number: Integer); +begin + if not FMultiBitmap.IsValid then Exit; + + if FPage.IsValid then + FMultiBitmap.UnlockPage(FPage, False); + + FMultiBitmap.LockPage(Number, FPage); +end; + +procedure TMainForm.PageBitmapChangeHandler(Sender: TObject); +begin + Invalidate; +end; + +procedure TMainForm.tbLoadClick(Sender: TObject); +begin + if OD.Execute then + begin + try + OpenMultiBitmap(OD.FileName); + except + raise Exception.CreateFmt('Can not load file %s', [OD.FileName]); + end; + end; +end; + +procedure TMainForm.WMEraseBkgnd(var Message: TWMEraseBkgnd); +begin + Message.Result := 1; +end; + +procedure TMainForm.FormPaint(Sender: TObject); +begin + if not FPage.IsValid then + begin + Canvas.Brush.Color := clBtnFace; + Canvas.FillRect(ClientRect); + end + else + FPage.Draw(Canvas.Handle, ClientRect); +end; + +procedure TMainForm.tbCloseClick(Sender: TObject); +begin + if FMultiBitmap.IsValid then + CloseMultiBitmap; +end; + +procedure TMainForm.cbPagesChange(Sender: TObject); +var + Page: Integer; +begin + Page := StrToInt(cbPages.Text); + OpenPage(Page); +end; + +procedure TMainForm.FormResize(Sender: TObject); +begin + Invalidate; +end; + +end. diff --git a/Wrapper/Delphi/demo/TargaUnit/Readme.txt b/Wrapper/Delphi/demo/TargaUnit/Readme.txt index 280c6d2..de9ed24 100644 --- a/Wrapper/Delphi/demo/TargaUnit/Readme.txt +++ b/Wrapper/Delphi/demo/TargaUnit/Readme.txt @@ -1,22 +1,22 @@ -TargaImage.pas is a TGraphic descendant for Delphi. Installing it -will allow Delphi TImage and TDBImage components to read Targa files -just like BMP & WMF files with no coding on your part. - -It also adds the TGA file type to the Delphi Open/Save Picture dialog -boxes. - -To install this unit, place it in your one of your library folders -and make it available to all your Delphi projects by using -Component>Install Component from the Delphi menus. - -NOTE: any Delphi applications using this *must* have FreeImage.dll -installed in your application's folder, or somewhere in the path. - ------------------------ - -Tommy -Edinburgh, Scotland -LeTene@battlefieldeurope.org - - - +TargaImage.pas is a TGraphic descendant for Delphi. Installing it +will allow Delphi TImage and TDBImage components to read Targa files +just like BMP & WMF files with no coding on your part. + +It also adds the TGA file type to the Delphi Open/Save Picture dialog +boxes. + +To install this unit, place it in your one of your library folders +and make it available to all your Delphi projects by using +Component>Install Component from the Delphi menus. + +NOTE: any Delphi applications using this *must* have FreeImage.dll +installed in your application's folder, or somewhere in the path. + +----------------------- + +Tommy +Edinburgh, Scotland +LeTene@battlefieldeurope.org + + + diff --git a/Wrapper/Delphi/demo/TargaUnit/TargaImage.pas b/Wrapper/Delphi/demo/TargaUnit/TargaImage.pas index 3badc60..4a355c2 100644 --- a/Wrapper/Delphi/demo/TargaUnit/TargaImage.pas +++ b/Wrapper/Delphi/demo/TargaUnit/TargaImage.pas @@ -1,212 +1,212 @@ -unit TargaImage; - -// ========================================================== -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// -// ========================================================== - -interface - -uses - Windows, - Classes, - FreeImage, - Graphics, - Types; - -type - TTargaImage = class(TGraphic) - private - fImage: PFIBITMAP; - fWidth: Integer; - fHeight: Integer; - protected - procedure Draw(ACanvas: TCanvas; const ARect: TRect); override; - function GetEmpty: Boolean; override; - function GetHeight: Integer; override; - function GetWidth: Integer; override; - procedure SetHeight(Value: Integer); override; - procedure SetWidth(Value: Integer); override; - public - constructor Create; override; - destructor Destroy; override; - procedure Assign(Source: TPersistent); override; - procedure LoadFromClipboardFormat(AFormat: Word; AData: THandle; APalette: HPALETTE); override; - procedure LoadFromStream(Stream: TStream); override; - procedure SaveToClipboardFormat(var AFormat: Word; var AData: THandle; var APalette: HPALETTE); override; - procedure SaveToStream(Stream: TStream); override; - end; - - procedure Register; - -implementation - -{ Design-time registration } - -procedure Register; -begin - TPicture.RegisterFileFormat('tga', 'TARGA Files', TTargaImage); -end; - -{ IO functions } - -function FI_ReadProc(buffer : pointer; size : Cardinal; count : Cardinal; handle : fi_handle) : UInt; stdcall; -var - stream: TStream; - bytesToRead: Cardinal; -begin - stream := TStream(handle); - bytesToRead := size*count; - Result := stream.Read(buffer^, bytesToRead); -end; - -function FI_WriteProc(buffer : pointer; size, count : Cardinal; handle : fi_handle) : UInt; stdcall; -var - stream: TStream; - bytesToWrite: Cardinal; -begin - stream := TStream(handle); - bytesToWrite := size*count; - Result := stream.Write(buffer^, bytesToWrite); -end; - -function FI_SeekProc(handle : fi_handle; offset : longint; origin : integer) : Integer; stdcall; -begin - TStream(handle).Seek(offset, origin); - Result := 0; -end; - -function FI_TellProc(handle : fi_handle) : LongInt; stdcall; -begin - Result := TStream(handle).Position; -end; - -{ TTargaImage } - -constructor TTargaImage.Create; -begin - fImage := nil; - fWidth := 0; - fHeight := 0; - inherited; -end; - -destructor TTargaImage.Destroy; -begin - if Assigned(fImage) then - FreeImage_Unload(fImage); - inherited; -end; - -procedure TTargaImage.Assign(Source: TPersistent); -begin - if Source is TTargaImage then begin - fImage := FreeImage_Clone(TTargaImage(Source).fImage); - fWidth := FreeImage_GetWidth(fImage); - fHeight := FreeImage_GetHeight(fImage); - Changed(Self); - end else - inherited; -end; - -procedure TTargaImage.Draw(ACanvas: TCanvas; const ARect: TRect); -var - pbi: PBitmapInfo; -begin - if Assigned(fImage) then begin - pbi := FreeImage_GetInfo(fImage); - SetStretchBltMode(ACanvas.Handle, COLORONCOLOR); - StretchDIBits(ACanvas.Handle, ARect.left, ARect.top, - ARect.right-ARect.left, ARect.bottom-ARect.top, - 0, 0, fWidth, fHeight, - FreeImage_GetBits(fImage), pbi^, DIB_RGB_COLORS, SRCCOPY); - end; -end; - -function TTargaImage.GetEmpty: Boolean; -begin - Result := Assigned(fImage); -end; - -function TTargaImage.GetHeight: Integer; -begin - Result := fHeight; -end; - -function TTargaImage.GetWidth: Integer; -begin - Result := fWidth; -end; - -procedure TTargaImage.LoadFromClipboardFormat(AFormat: Word; AData: THandle; APalette: HPALETTE); -begin - if Assigned(fImage) then begin - end; -end; - -procedure TTargaImage.LoadFromStream(Stream: TStream); -var - io: FreeImageIO; -begin - with io do begin - read_proc := FI_ReadProc; - write_proc := FI_WriteProc; - seek_proc := FI_SeekProc; - tell_proc := FI_TellProc; - end; - fImage := FreeImage_LoadFromHandle(FIF_TARGA, @io, Stream); - if Assigned(fImage) then begin - fWidth := FreeImage_GetWidth(fImage); - fHeight := FreeImage_GetHeight(fImage); - end; -end; - -procedure TTargaImage.SaveToClipboardFormat(var AFormat: Word; var AData: THandle; var APalette: HPALETTE); -begin -end; - -procedure TTargaImage.SaveToStream(Stream: TStream); -var - io: FreeImageIO; -begin - with io do begin - read_proc := FI_ReadProc; - write_proc := FI_WriteProc; - seek_proc := FI_SeekProc; - tell_proc := FI_TellProc; - end; - FreeImage_SaveToHandle(FIF_TARGA, fImage, @io, Stream); -end; - -procedure TTargaImage.SetHeight(Value: Integer); -begin - if Assigned(fImage) then begin - fHeight := Value; - FreeImage_Rescale(fImage, fWidth, fHeight, FILTER_BICUBIC); - end; -end; - -procedure TTargaImage.SetWidth(Value: Integer); -begin - if Assigned(fImage) then begin - fWidth := Value; - FreeImage_Rescale(fImage, fWidth, fHeight, FILTER_BICUBIC); - end; -end; - -initialization - TPicture.RegisterFileFormat('tga', 'TARGA Files', TTargaImage); -end. +unit TargaImage; + +// ========================================================== +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// +// ========================================================== + +interface + +uses + Windows, + Classes, + FreeImage, + Graphics, + Types; + +type + TTargaImage = class(TGraphic) + private + fImage: PFIBITMAP; + fWidth: Integer; + fHeight: Integer; + protected + procedure Draw(ACanvas: TCanvas; const ARect: TRect); override; + function GetEmpty: Boolean; override; + function GetHeight: Integer; override; + function GetWidth: Integer; override; + procedure SetHeight(Value: Integer); override; + procedure SetWidth(Value: Integer); override; + public + constructor Create; override; + destructor Destroy; override; + procedure Assign(Source: TPersistent); override; + procedure LoadFromClipboardFormat(AFormat: Word; AData: THandle; APalette: HPALETTE); override; + procedure LoadFromStream(Stream: TStream); override; + procedure SaveToClipboardFormat(var AFormat: Word; var AData: THandle; var APalette: HPALETTE); override; + procedure SaveToStream(Stream: TStream); override; + end; + + procedure Register; + +implementation + +{ Design-time registration } + +procedure Register; +begin + TPicture.RegisterFileFormat('tga', 'TARGA Files', TTargaImage); +end; + +{ IO functions } + +function FI_ReadProc(buffer : pointer; size : Cardinal; count : Cardinal; handle : fi_handle) : UInt; stdcall; +var + stream: TStream; + bytesToRead: Cardinal; +begin + stream := TStream(handle); + bytesToRead := size*count; + Result := stream.Read(buffer^, bytesToRead); +end; + +function FI_WriteProc(buffer : pointer; size, count : Cardinal; handle : fi_handle) : UInt; stdcall; +var + stream: TStream; + bytesToWrite: Cardinal; +begin + stream := TStream(handle); + bytesToWrite := size*count; + Result := stream.Write(buffer^, bytesToWrite); +end; + +function FI_SeekProc(handle : fi_handle; offset : longint; origin : integer) : Integer; stdcall; +begin + TStream(handle).Seek(offset, origin); + Result := 0; +end; + +function FI_TellProc(handle : fi_handle) : LongInt; stdcall; +begin + Result := TStream(handle).Position; +end; + +{ TTargaImage } + +constructor TTargaImage.Create; +begin + fImage := nil; + fWidth := 0; + fHeight := 0; + inherited; +end; + +destructor TTargaImage.Destroy; +begin + if Assigned(fImage) then + FreeImage_Unload(fImage); + inherited; +end; + +procedure TTargaImage.Assign(Source: TPersistent); +begin + if Source is TTargaImage then begin + fImage := FreeImage_Clone(TTargaImage(Source).fImage); + fWidth := FreeImage_GetWidth(fImage); + fHeight := FreeImage_GetHeight(fImage); + Changed(Self); + end else + inherited; +end; + +procedure TTargaImage.Draw(ACanvas: TCanvas; const ARect: TRect); +var + pbi: PBitmapInfo; +begin + if Assigned(fImage) then begin + pbi := FreeImage_GetInfo(fImage); + SetStretchBltMode(ACanvas.Handle, COLORONCOLOR); + StretchDIBits(ACanvas.Handle, ARect.left, ARect.top, + ARect.right-ARect.left, ARect.bottom-ARect.top, + 0, 0, fWidth, fHeight, + FreeImage_GetBits(fImage), pbi^, DIB_RGB_COLORS, SRCCOPY); + end; +end; + +function TTargaImage.GetEmpty: Boolean; +begin + Result := Assigned(fImage); +end; + +function TTargaImage.GetHeight: Integer; +begin + Result := fHeight; +end; + +function TTargaImage.GetWidth: Integer; +begin + Result := fWidth; +end; + +procedure TTargaImage.LoadFromClipboardFormat(AFormat: Word; AData: THandle; APalette: HPALETTE); +begin + if Assigned(fImage) then begin + end; +end; + +procedure TTargaImage.LoadFromStream(Stream: TStream); +var + io: FreeImageIO; +begin + with io do begin + read_proc := FI_ReadProc; + write_proc := FI_WriteProc; + seek_proc := FI_SeekProc; + tell_proc := FI_TellProc; + end; + fImage := FreeImage_LoadFromHandle(FIF_TARGA, @io, Stream); + if Assigned(fImage) then begin + fWidth := FreeImage_GetWidth(fImage); + fHeight := FreeImage_GetHeight(fImage); + end; +end; + +procedure TTargaImage.SaveToClipboardFormat(var AFormat: Word; var AData: THandle; var APalette: HPALETTE); +begin +end; + +procedure TTargaImage.SaveToStream(Stream: TStream); +var + io: FreeImageIO; +begin + with io do begin + read_proc := FI_ReadProc; + write_proc := FI_WriteProc; + seek_proc := FI_SeekProc; + tell_proc := FI_TellProc; + end; + FreeImage_SaveToHandle(FIF_TARGA, fImage, @io, Stream); +end; + +procedure TTargaImage.SetHeight(Value: Integer); +begin + if Assigned(fImage) then begin + fHeight := Value; + FreeImage_Rescale(fImage, fWidth, fHeight, FILTER_BICUBIC); + end; +end; + +procedure TTargaImage.SetWidth(Value: Integer); +begin + if Assigned(fImage) then begin + fWidth := Value; + FreeImage_Rescale(fImage, fWidth, fHeight, FILTER_BICUBIC); + end; +end; + +initialization + TPicture.RegisterFileFormat('tga', 'TARGA Files', TTargaImage); +end. diff --git a/Wrapper/Delphi/demo/WinBitmap/MainForm.pas b/Wrapper/Delphi/demo/WinBitmap/MainForm.pas index 41b038b..5972081 100644 --- a/Wrapper/Delphi/demo/WinBitmap/MainForm.pas +++ b/Wrapper/Delphi/demo/WinBitmap/MainForm.pas @@ -1,227 +1,227 @@ -unit MainForm; - -interface - -uses - Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, - Dialogs, Menus, FreeBitmap, ComCtrls, ImgList, ToolWin; - -type - TfwbMainForm = class(TForm) - MainMenu: TMainMenu; - mnuFile: TMenuItem; - mnuFileOpen: TMenuItem; - mnuExit: TMenuItem; - OD: TOpenDialog; - StatusBar: TStatusBar; - mnuImage: TMenuItem; - mnuImageFlip: TMenuItem; - mnuFlipHorz: TMenuItem; - mnuFlipVert: TMenuItem; - mnuConvert: TMenuItem; - mnuTo8Bits: TMenuItem; - mnuTo16Bits555: TMenuItem; - mnuTo16Bits565: TMenuItem; - mnuTo24Bits: TMenuItem; - mnuTo32Bits: TMenuItem; - mnuDither: TMenuItem; - mnuQuantize: TMenuItem; - mnuGrayScale: TMenuItem; - mnuRotate: TMenuItem; - mnuClockwise: TMenuItem; - mnuAntiClockwise: TMenuItem; - mnuInvert: TMenuItem; - mnuClear: TMenuItem; - mnuTo4Bits: TMenuItem; - tbTools: TToolBar; - btnCopy: TToolButton; - ImageList1: TImageList; - ToolButton1: TToolButton; - btnPaste: TToolButton; - btnClear: TToolButton; - btnOpen: TToolButton; - ToolButton3: TToolButton; - ToolButton4: TToolButton; - procedure FormDestroy(Sender: TObject); - procedure FormPaint(Sender: TObject); - procedure FormCreate(Sender: TObject); - procedure mnuExitClick(Sender: TObject); - procedure mnuFileOpenClick(Sender: TObject); - procedure FormResize(Sender: TObject); - procedure mnuFlipHorzClick(Sender: TObject); - procedure btnCopyClick(Sender: TObject); - procedure btnClearClick(Sender: TObject); - procedure btnPasteClick(Sender: TObject); - private - FBitmap: TFreeWinBitmap; - procedure WMEraseBkgnd(var Message: TMessage); message WM_ERASEBKGND; - public - { Public declarations } - end; - -var - fwbMainForm: TfwbMainForm; - -implementation - -{$R *.dfm} - -uses - FreeUtils, FreeImage, Math; - -procedure TfwbMainForm.FormDestroy(Sender: TObject); -begin - if Assigned(FBitmap) then - FBitmap.Free; -end; - -procedure TfwbMainForm.FormPaint(Sender: TObject); -var - dx, dy, w, h: Integer; - r1, r2: Double; - R: TRect; -begin - if FBitmap.IsValid then // draw the bitmap - begin - // determine paint rect - r1 := FBitmap.GetWidth / FBitmap.GetHeight; - r2 := ClientWidth / ClientHeight; - if r1 > r2 then // fit by width - begin - w := ClientWidth; - h := Floor(w / r1); - dx := 0; - dy := (ClientHeight - h) div 2; - end - else // fit by height - begin - h := ClientHeight; - w := Floor(h * r1); - dy := 0; - dx := (ClientWidth - w) div 2; - end; - with ClientRect do - R := Bounds(Left + dx, Top + dy, w, h); - FBitmap.Draw(Canvas.Handle, R); - - // erase area around the image - Canvas.Brush.Color := Color; - if dx > 0 then - begin - with ClientRect do - R := Bounds(Left, Top, dx, ClientHeight); - Canvas.FillRect(R); - with ClientRect do - R := Bounds(Right - dx, Top, dx, ClientHeight); - Canvas.FillRect(R); - end else - if dy > 0 then - begin - with ClientRect do - R := Bounds(Left, Top, ClientWidth, dy); - Canvas.FillRect(R); - with ClientRect do - R := Bounds(Left, Bottom - dy, ClientWidth, dy); - Canvas.FillRect(R); - end - end - else // clear - begin - Canvas.Brush.Color := Color; - Canvas.FillRect(ClientRect); - end -end; - -procedure TfwbMainForm.FormCreate(Sender: TObject); -begin - FBitmap := TFreeWinBitmap.Create; - - mnuImage.Enabled := FBitmap.IsValid; - OD.Filter := FIU_GetAllFilters; -end; - -procedure TfwbMainForm.mnuExitClick(Sender: TObject); -begin - Close; -end; - -procedure TfwbMainForm.mnuFileOpenClick(Sender: TObject); -var - t: Cardinal; -begin - if OD.Execute then - begin - t := GetTickCount; - FBitmap.Load(OD.FileName); - t := GetTickCount - t; - mnuImage.Enabled := FBitmap.IsValid; - StatusBar.Panels[0].Text := 'Loaded in ' + IntToStr(t) + ' msec.'; - StatusBar.Panels[1].Text := Format('%dx%d', [FBitmap.GetWidth, FBitmap.GetHeight]); - Invalidate; - end; -end; - -procedure TfwbMainForm.FormResize(Sender: TObject); -begin - Invalidate -end; - -procedure TfwbMainForm.WMEraseBkgnd(var Message: TMessage); -begin - Message.Result := 1; -end; - -procedure TfwbMainForm.mnuFlipHorzClick(Sender: TObject); -begin - with FBitmap do - if Sender = mnuFlipHorz then - FLipHorizontal else - if Sender = mnuFlipVert then - FlipVertical else - if Sender = mnuTo4Bits then - ConvertTo4Bits else - if Sender = mnuTo8Bits then - ConvertTo8Bits else - if Sender = mnuTo16Bits555 then - ConvertTo16Bits555 else - if Sender = mnuTo16Bits565 then - ConvertTo16Bits565 else - if Sender = mnuTo24Bits then - ConvertTo24Bits else - if Sender = mnuTo32Bits then - ConvertTo32Bits else - if Sender = mnuDither then - Dither(FID_FS) else - if Sender = mnuQuantize then - ColorQuantize(FIQ_WUQUANT) else - if Sender = mnuGrayScale then - ConvertToGrayscale else - if Sender = mnuClockwise then - Rotate(-90) else - if Sender = mnuAntiClockwise then - Rotate(90) else - if Sender = mnuInvert then - Invert else - if Sender = mnuClear then - Clear; - Invalidate; -end; - -procedure TfwbMainForm.btnCopyClick(Sender: TObject); -begin - if FBitmap.IsValid then FBitmap.CopyToClipBoard(Handle); -end; - -procedure TfwbMainForm.btnClearClick(Sender: TObject); -begin - FBitmap.Clear; - Invalidate; -end; - -procedure TfwbMainForm.btnPasteClick(Sender: TObject); -begin - FBitmap.PasteFromClipBoard; - Invalidate; -end; - -end. +unit MainForm; + +interface + +uses + Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, + Dialogs, Menus, FreeBitmap, ComCtrls, ImgList, ToolWin; + +type + TfwbMainForm = class(TForm) + MainMenu: TMainMenu; + mnuFile: TMenuItem; + mnuFileOpen: TMenuItem; + mnuExit: TMenuItem; + OD: TOpenDialog; + StatusBar: TStatusBar; + mnuImage: TMenuItem; + mnuImageFlip: TMenuItem; + mnuFlipHorz: TMenuItem; + mnuFlipVert: TMenuItem; + mnuConvert: TMenuItem; + mnuTo8Bits: TMenuItem; + mnuTo16Bits555: TMenuItem; + mnuTo16Bits565: TMenuItem; + mnuTo24Bits: TMenuItem; + mnuTo32Bits: TMenuItem; + mnuDither: TMenuItem; + mnuQuantize: TMenuItem; + mnuGrayScale: TMenuItem; + mnuRotate: TMenuItem; + mnuClockwise: TMenuItem; + mnuAntiClockwise: TMenuItem; + mnuInvert: TMenuItem; + mnuClear: TMenuItem; + mnuTo4Bits: TMenuItem; + tbTools: TToolBar; + btnCopy: TToolButton; + ImageList1: TImageList; + ToolButton1: TToolButton; + btnPaste: TToolButton; + btnClear: TToolButton; + btnOpen: TToolButton; + ToolButton3: TToolButton; + ToolButton4: TToolButton; + procedure FormDestroy(Sender: TObject); + procedure FormPaint(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure mnuExitClick(Sender: TObject); + procedure mnuFileOpenClick(Sender: TObject); + procedure FormResize(Sender: TObject); + procedure mnuFlipHorzClick(Sender: TObject); + procedure btnCopyClick(Sender: TObject); + procedure btnClearClick(Sender: TObject); + procedure btnPasteClick(Sender: TObject); + private + FBitmap: TFreeWinBitmap; + procedure WMEraseBkgnd(var Message: TMessage); message WM_ERASEBKGND; + public + { Public declarations } + end; + +var + fwbMainForm: TfwbMainForm; + +implementation + +{$R *.dfm} + +uses + FreeUtils, FreeImage, Math; + +procedure TfwbMainForm.FormDestroy(Sender: TObject); +begin + if Assigned(FBitmap) then + FBitmap.Free; +end; + +procedure TfwbMainForm.FormPaint(Sender: TObject); +var + dx, dy, w, h: Integer; + r1, r2: Double; + R: TRect; +begin + if FBitmap.IsValid then // draw the bitmap + begin + // determine paint rect + r1 := FBitmap.GetWidth / FBitmap.GetHeight; + r2 := ClientWidth / ClientHeight; + if r1 > r2 then // fit by width + begin + w := ClientWidth; + h := Floor(w / r1); + dx := 0; + dy := (ClientHeight - h) div 2; + end + else // fit by height + begin + h := ClientHeight; + w := Floor(h * r1); + dy := 0; + dx := (ClientWidth - w) div 2; + end; + with ClientRect do + R := Bounds(Left + dx, Top + dy, w, h); + FBitmap.Draw(Canvas.Handle, R); + + // erase area around the image + Canvas.Brush.Color := Color; + if dx > 0 then + begin + with ClientRect do + R := Bounds(Left, Top, dx, ClientHeight); + Canvas.FillRect(R); + with ClientRect do + R := Bounds(Right - dx, Top, dx, ClientHeight); + Canvas.FillRect(R); + end else + if dy > 0 then + begin + with ClientRect do + R := Bounds(Left, Top, ClientWidth, dy); + Canvas.FillRect(R); + with ClientRect do + R := Bounds(Left, Bottom - dy, ClientWidth, dy); + Canvas.FillRect(R); + end + end + else // clear + begin + Canvas.Brush.Color := Color; + Canvas.FillRect(ClientRect); + end +end; + +procedure TfwbMainForm.FormCreate(Sender: TObject); +begin + FBitmap := TFreeWinBitmap.Create; + + mnuImage.Enabled := FBitmap.IsValid; + OD.Filter := FIU_GetAllFilters; +end; + +procedure TfwbMainForm.mnuExitClick(Sender: TObject); +begin + Close; +end; + +procedure TfwbMainForm.mnuFileOpenClick(Sender: TObject); +var + t: Cardinal; +begin + if OD.Execute then + begin + t := GetTickCount; + FBitmap.Load(OD.FileName); + t := GetTickCount - t; + mnuImage.Enabled := FBitmap.IsValid; + StatusBar.Panels[0].Text := 'Loaded in ' + IntToStr(t) + ' msec.'; + StatusBar.Panels[1].Text := Format('%dx%d', [FBitmap.GetWidth, FBitmap.GetHeight]); + Invalidate; + end; +end; + +procedure TfwbMainForm.FormResize(Sender: TObject); +begin + Invalidate +end; + +procedure TfwbMainForm.WMEraseBkgnd(var Message: TMessage); +begin + Message.Result := 1; +end; + +procedure TfwbMainForm.mnuFlipHorzClick(Sender: TObject); +begin + with FBitmap do + if Sender = mnuFlipHorz then + FLipHorizontal else + if Sender = mnuFlipVert then + FlipVertical else + if Sender = mnuTo4Bits then + ConvertTo4Bits else + if Sender = mnuTo8Bits then + ConvertTo8Bits else + if Sender = mnuTo16Bits555 then + ConvertTo16Bits555 else + if Sender = mnuTo16Bits565 then + ConvertTo16Bits565 else + if Sender = mnuTo24Bits then + ConvertTo24Bits else + if Sender = mnuTo32Bits then + ConvertTo32Bits else + if Sender = mnuDither then + Dither(FID_FS) else + if Sender = mnuQuantize then + ColorQuantize(FIQ_WUQUANT) else + if Sender = mnuGrayScale then + ConvertToGrayscale else + if Sender = mnuClockwise then + Rotate(-90) else + if Sender = mnuAntiClockwise then + Rotate(90) else + if Sender = mnuInvert then + Invert else + if Sender = mnuClear then + Clear; + Invalidate; +end; + +procedure TfwbMainForm.btnCopyClick(Sender: TObject); +begin + if FBitmap.IsValid then FBitmap.CopyToClipBoard(Handle); +end; + +procedure TfwbMainForm.btnClearClick(Sender: TObject); +begin + FBitmap.Clear; + Invalidate; +end; + +procedure TfwbMainForm.btnPasteClick(Sender: TObject); +begin + FBitmap.PasteFromClipBoard; + Invalidate; +end; + +end. diff --git a/Wrapper/Delphi/license.txt b/Wrapper/Delphi/license.txt index a930004..48215b6 100644 --- a/Wrapper/Delphi/license.txt +++ b/Wrapper/Delphi/license.txt @@ -1,3 +1,3 @@ -The contents of FreeImageDW package are subject to the FreeImage Public License Version 1.0 (the "License"); you may not use this package except in compliance with the License. You may obtain a copy of the License at http://home.wxs.nl/~flvdberg/freeimage-license.txt - +The contents of FreeImageDW package are subject to the FreeImage Public License Version 1.0 (the "License"); you may not use this package except in compliance with the License. You may obtain a copy of the License at http://home.wxs.nl/~flvdberg/freeimage-license.txt + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. \ No newline at end of file diff --git a/Wrapper/Delphi/src/FreeBitmap.pas b/Wrapper/Delphi/src/FreeBitmap.pas index ad74ebf..eac137f 100644 --- a/Wrapper/Delphi/src/FreeBitmap.pas +++ b/Wrapper/Delphi/src/FreeBitmap.pas @@ -1,2184 +1,2184 @@ -unit FreeBitmap; - -// ========================================================== -// -// Delphi wrapper for FreeImage 3 -// -// Design and implementation by -// - Anatoliy Pulyaevskiy (xvel84@rambler.ru) -// -// Contributors: -// - Enzo Costantini (enzocostantini@libero.it) -// - Lorenzo Monti (LM) lomo74@gmail.com -// -// Revision history -// When Who What -// ----------- ----- ----------------------------------------------------------- -// 2010-07-14 LM made RAD2010 compliant (unicode) -// 2011-03-04 JMB modifications to run on 64 bits (Windows and linux) : -// - FreeImage_RotateClassic : deprecated function, call to DeprecationManager in 64 bits crashes freeimage.dll -// ==> FreeImage_RotateClassic : replaced by FreeImage_Rotate -// modifications to run on linux : -// - exclude windows specific functions by compilation directives -// some corrections in : -// - TFreeBitmap.DoChanging -// - TFreeBitmap.IsGrayScale -// - TFreeWinBitmap.CopyFromBitmap -// - TFreeMultiBitmap.Open - -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// -// ========================================================== -// -// From begining all code of this file is based on C++ wrapper to -// FreeImage - FreeImagePlus. -// -// ========================================================== - -interface - -{$I 'Version.inc'} - -uses - SysUtils, Classes, -{$IFDEF MSWINDOWS} - Windows, -{$ENDIF} - FreeImage; - -type - { TFreeObject } - - TFreeObject = class(TObject) - public - function IsValid: Boolean; virtual; - end; - - { TFreeTag } - - TFreeTag = class(TFreeObject) - private - // fields - FTag: PFITAG; - - // getters & setters - function GetCount: Cardinal; - function GetDescription: AnsiString; - function GetID: Word; - function GetKey: AnsiString; - function GetLength: Cardinal; - function GetTagType: FREE_IMAGE_MDTYPE; - function GetValue: Pointer; - procedure SetCount(const Value: Cardinal); - procedure SetDescription(const Value: AnsiString); - procedure SetID(const Value: Word); - procedure SetKey(const Value: AnsiString); - procedure SetLength(const Value: Cardinal); - procedure SetTagType(const Value: FREE_IMAGE_MDTYPE); - procedure SetValue(const Value: Pointer); - public - // construction & destruction - constructor Create(ATag: PFITAG = nil); virtual; - destructor Destroy; override; - - // methods - function Clone: TFreeTag; - function IsValid: Boolean; override; - function ToString(Model: FREE_IMAGE_MDMODEL; Make: PAnsiChar = nil): AnsiString; reintroduce; - - // properties - property Key: AnsiString read GetKey write SetKey; - property Description: AnsiString read GetDescription write SetDescription; - property ID: Word read GetID write SetID; - property TagType: FREE_IMAGE_MDTYPE read GetTagType write SetTagType; - property Count: Cardinal read GetCount write SetCount; - property Length: Cardinal read GetLength write SetLength; - property Value: Pointer read GetValue write SetValue; - property Tag: PFITAG read FTag; - end; - - { forward declarations } - - TFreeBitmap = class; - TFreeMemoryIO = class; - - { TFreeBitmap } - - TFreeBitmapChangingEvent = procedure(Sender: TFreeBitmap; var OldDib, NewDib: PFIBITMAP; var Handled: Boolean) of object; - - TFreeBitmap = class(TFreeObject) - private - // fields - FDib: PFIBITMAP; - FOnChange: TNotifyEvent; - FOnChanging: TFreeBitmapChangingEvent; - - procedure SetDib(Value: PFIBITMAP); - protected - function DoChanging(var OldDib, NewDib: PFIBITMAP): Boolean; dynamic; - function Replace(NewDib: PFIBITMAP): Boolean; dynamic; - public - constructor Create(ImageType: FREE_IMAGE_TYPE = FIT_BITMAP; Width: Integer = 0; Height: Integer = 0; Bpp: Integer = 0); - destructor Destroy; override; - function SetSize(ImageType: FREE_IMAGE_TYPE; Width, Height, Bpp: Integer; RedMask: Cardinal = 0; GreenMask: Cardinal = 0; BlueMask: Cardinal = 0): Boolean; - procedure Change; dynamic; - procedure Assign(Source: TFreeBitmap); - function CopySubImage(Left, Top, Right, Bottom: Integer; Dest: TFreeBitmap): Boolean; - function PasteSubImage(Src: TFreeBitmap; Left, Top: Integer; Alpha: Integer = 256): Boolean; - procedure Clear; virtual; - function Load(const FileName: AnsiString; Flag: Integer = 0): Boolean; - function LoadU(const FileName: {$IFDEF DELPHI2010}string{$ELSE}WideString{$ENDIF}; Flag: Integer = 0): Boolean; - function LoadFromHandle(IO: PFreeImageIO; Handle: fi_handle; Flag: Integer = 0): Boolean; - function LoadFromMemory(MemIO: TFreeMemoryIO; Flag: Integer = 0): Boolean; - function LoadFromStream(Stream: TStream; Flag: Integer = 0): Boolean; - // save functions - function CanSave(fif: FREE_IMAGE_FORMAT): Boolean; - function Save(const FileName: AnsiString; Flag: Integer = 0): Boolean; - function SaveU(const FileName: {$IFDEF DELPHI2010}string{$ELSE}WideString{$ENDIF}; Flag: Integer = 0): Boolean; - function SaveToHandle(fif: FREE_IMAGE_FORMAT; IO: PFreeImageIO; Handle: fi_handle; Flag: Integer = 0): Boolean; - function SaveToMemory(fif: FREE_IMAGE_FORMAT; MemIO: TFreeMemoryIO; Flag: Integer = 0): Boolean; - function SaveToStream(fif: FREE_IMAGE_FORMAT; Stream: TStream; Flag: Integer = 0): Boolean; - // image information - function GetImageType: FREE_IMAGE_TYPE; - function GetWidth: Integer; - function GetHeight: Integer; - function GetScanWidth: Integer; - function IsValid: Boolean; override; - function GetInfo: PBitmapInfo; - function GetInfoHeader: PBitmapInfoHeader; - function GetImageSize: Cardinal; - function GetBitsPerPixel: Integer; - function GetLine: Integer; - function GetHorizontalResolution: Double; - function GetVerticalResolution: Double; - procedure SetHorizontalResolution(Value: Double); - procedure SetVerticalResolution(Value: Double); - // palette operations - function GetPalette: PRGBQUAD; - function GetPaletteSize: Integer; - function GetColorsUsed: Integer; - function GetColorType: FREE_IMAGE_COLOR_TYPE; - function IsGrayScale: Boolean; - // pixels access - function AccessPixels: PByte; - function GetScanLine(ScanLine: Integer): PByte; - function GetPixelIndex(X, Y: Cardinal; var Value: Byte): Boolean; - function GetPixelColor(X, Y: Cardinal; var Value: RGBQUAD): Boolean; - function SetPixelIndex(X, Y: Cardinal; var Value: Byte): Boolean; - function SetPixelColor(X, Y: Cardinal; var Value: RGBQUAD): Boolean; - // convertion - function ConvertToStandardType(ScaleLinear: Boolean): Boolean; - function ConvertToType(ImageType: FREE_IMAGE_TYPE; ScaleLinear: Boolean): Boolean; - function Threshold(T: Byte): Boolean; - function ConvertTo4Bits: Boolean; - function ConvertTo8Bits: Boolean; - function ConvertTo16Bits555: Boolean; - function ConvertTo16Bits565: Boolean; - function ConvertTo24Bits: Boolean; - function ConvertTo32Bits: Boolean; - function ConvertToGrayscale: Boolean; - function ColorQuantize(Algorithm: FREE_IMAGE_QUANTIZE): Boolean; - function Dither(Algorithm: FREE_IMAGE_DITHER): Boolean; - function ConvertToRGBF: Boolean; - function ToneMapping(TMO: FREE_IMAGE_TMO; FirstParam, SecondParam: Double): Boolean; - // transparency - function IsTransparent: Boolean; - function GetTransparencyCount: Cardinal; - function GetTransparencyTable: PByte; - procedure SetTransparencyTable(Table: PByte; Count: Integer); - function HasFileBkColor: Boolean; - function GetFileBkColor(var BkColor: RGBQUAD): Boolean; - function SetFileBkColor(BkColor: PRGBQuad): Boolean; - // channel processing routines - function GetChannel(Bitmap: TFreeBitmap; Channel: FREE_IMAGE_COLOR_CHANNEL): Boolean; - function SetChannel(Bitmap: TFreeBitmap; Channel: FREE_IMAGE_COLOR_CHANNEL): Boolean; - function SplitChannels(RedChannel, GreenChannel, BlueChannel: TFreeBitmap): Boolean; - function CombineChannels(Red, Green, Blue: TFreeBitmap): Boolean; - // rotation and flipping - function RotateEx(Angle, XShift, YShift, XOrigin, YOrigin: Double; UseMask: Boolean): Boolean; - function Rotate(Angle: Double): Boolean; - function FlipHorizontal: Boolean; - function FlipVertical: Boolean; - // color manipulation routines - function Invert: Boolean; - function AdjustCurve(Lut: PByte; Channel: FREE_IMAGE_COLOR_CHANNEL): Boolean; - function AdjustGamma(Gamma: Double): Boolean; - function AdjustBrightness(Percentage: Double): Boolean; - function AdjustContrast(Percentage: Double): Boolean; - function GetHistogram(Histo: PDWORD; Channel: FREE_IMAGE_COLOR_CHANNEL = FICC_BLACK): Boolean; - // upsampling / downsampling - procedure MakeThumbnail(const Width, Height: Integer; DestBitmap: TFreeBitmap); - function Rescale(NewWidth, NewHeight: Integer; Filter: FREE_IMAGE_FILTER; Dest: TFreeBitmap = nil): Boolean; - // metadata routines - function FindFirstMetadata(Model: FREE_IMAGE_MDMODEL; var Tag: TFreeTag): PFIMETADATA; - function FindNextMetadata(MDHandle: PFIMETADATA; var Tag: TFreeTag): Boolean; - procedure FindCloseMetadata(MDHandle: PFIMETADATA); - function SetMetadata(Model: FREE_IMAGE_MDMODEL; const Key: AnsiString; Tag: TFreeTag): Boolean; - function GetMetadata(Model: FREE_IMAGE_MDMODEL; const Key: AnsiString; var Tag: TFreeTag): Boolean; - function GetMetadataCount(Model: FREE_IMAGE_MDMODEL): Cardinal; - - // properties - property Dib: PFIBITMAP read FDib write SetDib; - property OnChange: TNotifyEvent read FOnChange write FOnChange; - property OnChanging: TFreeBitmapChangingEvent read FOnChanging write FOnChanging; - end; - - { TFreeWinBitmap } - - TFreeWinBitmap = class(TFreeBitmap) - private - FDeleteMe: Boolean; // True - need to delete FDisplayDib - FDisplayDib: PFIBITMAP; // Image that paints on DC - public - constructor Create(ImageType: FREE_IMAGE_TYPE = FIT_BITMAP; Width: Integer = 0; Height: Integer = 0; Bpp: Integer = 0); - destructor Destroy; override; - - procedure Clear; override; -{$IFDEF MSWINDOWS} - function CopyToHandle: THandle; - function CopyFromHandle(HMem: THandle): Boolean; - function CopyFromBitmap(HBmp: HBITMAP): Boolean; - function CopyToBitmapH: HBITMAP; - function CopyToClipBoard(NewOwner: HWND): Boolean; - function PasteFromClipBoard: Boolean; - function CaptureWindow(ApplicationWindow, SelectedWindow: HWND): Boolean; - - procedure Draw(DC: HDC; Rect: TRect); - procedure DrawEx(DC: HDC; Rect: TRect; UseFileBkg: Boolean = False; AppBkColor: PRGBQuad = nil; Bg: PFIBITMAP = nil); -{$ENDIF} - end; - - { TFreeMemoryIO } - - TFreeMemoryIO = class(TFreeObject) - private - FHMem: PFIMEMORY; - public - // construction and destruction - constructor Create(Data: PByte = nil; SizeInBytes: DWORD = 0); - destructor Destroy; override; - - function GetFileType: FREE_IMAGE_FORMAT; - function Read(fif: FREE_IMAGE_FORMAT; Flag: Integer = 0): PFIBITMAP; - function Write(fif: FREE_IMAGE_FORMAT; dib: PFIBITMAP; Flag: Integer = 0): Boolean; - function Tell: Longint; - function Seek(Offset: Longint; Origin: Word): Boolean; - function Acquire(var Data: PByte; var SizeInBytes: DWORD): Boolean; - // overriden methods - function IsValid: Boolean; override; - end; - - { TFreeMultiBitmap } - - TFreeMultiBitmap = class(TFreeObject) - private - FMPage: PFIMULTIBITMAP; - FMemoryCache: Boolean; - public - // constructor and destructor - constructor Create(KeepCacheInMemory: Boolean = False); - destructor Destroy; override; - - // methods - function Open(const FileName: AnsiString; CreateNew, ReadOnly: Boolean; Flags: Integer = 0): Boolean; - function Close(Flags: Integer = 0): Boolean; - function GetPageCount: Integer; - procedure AppendPage(Bitmap: TFreeBitmap); - procedure InsertPage(Page: Integer; Bitmap: TFreeBitmap); - procedure DeletePage(Page: Integer); - function MovePage(Target, Source: Integer): Boolean; - procedure LockPage(Page: Integer; DestBitmap: TFreeBitmap); - procedure UnlockPage(Bitmap: TFreeBitmap; Changed: Boolean); - function GetLockedPageNumbers(var Pages: Integer; var Count: Integer): Boolean; - // overriden methods - function IsValid: Boolean; override; - - // properties - // change of this property influences only on the next opening of a file - property MemoryCache: Boolean read FMemoryCache write FMemoryCache; - end; - -implementation - -const - ThumbSize = 150; - -// marker used for clipboard copy / paste - -procedure SetFreeImageMarker(bmih: PBitmapInfoHeader; dib: PFIBITMAP); -begin - // Windows constants goes from 0L to 5L - // Add $FF to avoid conflicts - bmih.biCompression := $FF + FreeImage_GetImageType(dib); -end; - -function GetFreeImageMarker(bmih: PBitmapInfoHeader): FREE_IMAGE_TYPE; -begin - Result := FREE_IMAGE_TYPE(bmih.biCompression - $FF); -end; - -{ TFreePersistent } - -function TFreeObject.IsValid: Boolean; -begin - Result := False -end; - -{ TFreeBitmap } - -function TFreeBitmap.AccessPixels: PByte; -begin - Result := FreeImage_GetBits(FDib) -end; - -function TFreeBitmap.AdjustBrightness(Percentage: Double): Boolean; -begin - if FDib <> nil then - begin - Result := FreeImage_AdjustBrightness(FDib, Percentage); - Change; - end - else - Result := False -end; - -function TFreeBitmap.AdjustContrast(Percentage: Double): Boolean; -begin - if FDib <> nil then - begin - Result := FreeImage_AdjustContrast(FDib, Percentage); - Change; - end - else - Result := False -end; - -function TFreeBitmap.AdjustCurve(Lut: PByte; - Channel: FREE_IMAGE_COLOR_CHANNEL): Boolean; -begin - if FDib <> nil then - begin - Result := FreeImage_AdjustCurve(FDib, Lut, Channel); - Change; - end - else - Result := False -end; - -function TFreeBitmap.AdjustGamma(Gamma: Double): Boolean; -begin - if FDib <> nil then - begin - Result := FreeImage_AdjustGamma(FDib, Gamma); - Change; - end - else - Result := False -end; - -procedure TFreeBitmap.Assign(Source: TFreeBitmap); -var - SourceBmp: TFreeBitmap; - Clone: PFIBITMAP; -begin - if Source = nil then - begin - Clear; - Exit; - end; - - if Source is TFreeBitmap then - begin - SourceBmp := TFreeBitmap(Source); - if SourceBmp <> Self then - begin - if SourceBmp.IsValid then - begin - Clone := FreeImage_Clone(SourceBmp.FDib); - Replace(Clone); - end - else - Clear; - end; - end; -end; - -function TFreeBitmap.CanSave(fif: FREE_IMAGE_FORMAT): Boolean; -var - ImageType: FREE_IMAGE_TYPE; - Bpp: Word; -begin - Result := False; - if not IsValid then Exit; - - if fif <> FIF_UNKNOWN then - begin - // check that the dib can be saved in this format - ImageType := FreeImage_GetImageType(FDib); - if ImageType = FIT_BITMAP then - begin - // standard bitmap type - Bpp := FreeImage_GetBPP(FDib); - Result := FreeImage_FIFSupportsWriting(fif) - and FreeImage_FIFSupportsExportBPP(fif, Bpp); - end - else // special bitmap type - Result := FreeImage_FIFSupportsExportType(fif, ImageType); - end; -end; - -procedure TFreeBitmap.Change; -begin - if Assigned(FOnChange) then FOnChange(Self) -end; - -procedure TFreeBitmap.Clear; -begin - if FDib <> nil then - begin - FreeImage_Unload(FDib); - FDib := nil; - Change; - end; -end; - -function TFreeBitmap.ColorQuantize( - Algorithm: FREE_IMAGE_QUANTIZE): Boolean; -var - dib8: PFIBITMAP; -begin - if FDib <> nil then - begin - dib8 := FreeImage_ColorQuantize(FDib, Algorithm); - Result := Replace(dib8); - end - else - Result := False; -end; - -function TFreeBitmap.CombineChannels(Red, Green, - Blue: TFreeBitmap): Boolean; -var - Width, Height: Integer; -begin - if FDib = nil then - begin - Width := Red.GetWidth; - Height := Red.GetHeight; - FDib := FreeImage_Allocate(Width, Height, 24, FI_RGBA_RED_MASK, - FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - end; - - if FDib <> nil then - begin - Result := FreeImage_SetChannel(FDib, Red.FDib, FICC_RED) and - FreeImage_SetChannel(FDib, Green.FDib, FICC_GREEN) and - FreeImage_SetChannel(FDib, Blue.FDib, FICC_BLUE); - - Change - end - else - Result := False; -end; - -function TFreeBitmap.ConvertTo16Bits555: Boolean; -var - dib16_555: PFIBITMAP; -begin - if FDib <> nil then - begin - dib16_555 := FreeImage_ConvertTo16Bits555(FDib); - Result := Replace(dib16_555); - end - else - Result := False -end; - -function TFreeBitmap.ConvertTo16Bits565: Boolean; -var - dib16_565: PFIBITMAP; -begin - if FDib <> nil then - begin - dib16_565 := FreeImage_ConvertTo16Bits565(FDib); - Result := Replace(dib16_565); - end - else - Result := False -end; - -function TFreeBitmap.ConvertTo24Bits: Boolean; -var - dibRGB: PFIBITMAP; -begin - if FDib <> nil then - begin - dibRGB := FreeImage_ConvertTo24Bits(FDib); - Result := Replace(dibRGB); - end - else - Result := False -end; - -function TFreeBitmap.ConvertTo32Bits: Boolean; -var - dib32: PFIBITMAP; -begin - if FDib <> nil then - begin - dib32 := FreeImage_ConvertTo32Bits(FDib); - Result := Replace(dib32); - end - else - Result := False -end; - -function TFreeBitmap.ConvertTo4Bits: Boolean; -var - dib4: PFIBITMAP; -begin - Result := False; - if IsValid then - begin - dib4 := FreeImage_ConvertTo4Bits(FDib); - Result := Replace(dib4); - end; -end; - -function TFreeBitmap.ConvertTo8Bits: Boolean; -var - dib8: PFIBITMAP; -begin - if FDib <> nil then - begin - dib8 := FreeImage_ConvertTo8Bits(FDib); - Result := Replace(dib8); - end - else - Result := False -end; - -function TFreeBitmap.ConvertToGrayscale: Boolean; -var - dib8: PFIBITMAP; -begin - Result := False; - - if IsValid then - begin - dib8 := FreeImage_ConvertToGreyscale(FDib); - Result := Replace(dib8); - end -end; - -function TFreeBitmap.ConvertToRGBF: Boolean; -var - ImageType: FREE_IMAGE_TYPE; - NewDib: PFIBITMAP; -begin - Result := False; - if not IsValid then Exit; - - ImageType := GetImageType; - - if (ImageType = FIT_BITMAP) then - begin - if GetBitsPerPixel < 24 then - if not ConvertTo24Bits then - Exit - end; - NewDib := FreeImage_ConvertToRGBF(FDib); - Result := Replace(NewDib); -end; - -function TFreeBitmap.ConvertToStandardType(ScaleLinear: Boolean): Boolean; -var - dibStandard: PFIBITMAP; -begin - if IsValid then - begin - dibStandard := FreeImage_ConvertToStandardType(FDib, ScaleLinear); - Result := Replace(dibStandard); - end - else - Result := False; -end; - -function TFreeBitmap.ConvertToType(ImageType: FREE_IMAGE_TYPE; - ScaleLinear: Boolean): Boolean; -var - dib: PFIBITMAP; -begin - if FDib <> nil then - begin - dib := FreeImage_ConvertToType(FDib, ImageType, ScaleLinear); - Result := Replace(dib) - end - else - Result := False -end; - -function TFreeBitmap.CopySubImage(Left, Top, Right, Bottom: Integer; - Dest: TFreeBitmap): Boolean; -begin - if FDib <> nil then - begin - Dest.FDib := FreeImage_Copy(FDib, Left, Top, Right, Bottom); - Result := Dest.IsValid; - end else - Result := False; -end; - -constructor TFreeBitmap.Create(ImageType: FREE_IMAGE_TYPE; Width, Height, - Bpp: Integer); -begin - inherited Create; - - FDib := nil; - if (Width > 0) and (Height > 0) and (Bpp > 0) then - SetSize(ImageType, Width, Height, Bpp); -end; - -destructor TFreeBitmap.Destroy; -begin - if FDib <> nil then - FreeImage_Unload(FDib); - inherited; -end; - -function TFreeBitmap.Dither(Algorithm: FREE_IMAGE_DITHER): Boolean; -var - dib: PFIBITMAP; -begin - if FDib <> nil then - begin - dib := FreeImage_Dither(FDib, Algorithm); - Result := Replace(dib); - end - else - Result := False; -end; - -function TFreeBitmap.DoChanging(var OldDib, NewDib: PFIBITMAP): Boolean; -begin - Result := False; - if (OldDib <> NewDib) and Assigned(FOnChanging) then - FOnChanging(Self, OldDib, NewDib, Result); -end; - -procedure TFreeBitmap.FindCloseMetadata(MDHandle: PFIMETADATA); -begin - FreeImage_FindCloseMetadata(MDHandle); -end; - -function TFreeBitmap.FindFirstMetadata(Model: FREE_IMAGE_MDMODEL; - var Tag: TFreeTag): PFIMETADATA; -begin - Result := FreeImage_FindFirstMetadata(Model, FDib, Tag.FTag); -end; - -function TFreeBitmap.FindNextMetadata(MDHandle: PFIMETADATA; - var Tag: TFreeTag): Boolean; -begin - Result := FreeImage_FindNextMetadata(MDHandle, Tag.FTag); -end; - -function TFreeBitmap.FlipHorizontal: Boolean; -begin - if FDib <> nil then - begin - Result := FreeImage_FlipHorizontal(FDib); - Change; - end - else - Result := False -end; - -function TFreeBitmap.FlipVertical: Boolean; -begin - if FDib <> nil then - begin - Result := FreeImage_FlipVertical(FDib); - Change; - end - else - Result := False -end; - -function TFreeBitmap.GetBitsPerPixel: Integer; -begin - Result := FreeImage_GetBPP(FDib) -end; - -function TFreeBitmap.GetChannel(Bitmap: TFreeBitmap; - Channel: FREE_IMAGE_COLOR_CHANNEL): Boolean; -begin - if FDib <> nil then - begin - Bitmap.Dib := FreeImage_GetChannel(FDib, Channel); - Result := Bitmap.IsValid; - end - else - Result := False -end; - -function TFreeBitmap.GetColorsUsed: Integer; -begin - Result := FreeImage_GetColorsUsed(FDib) -end; - -function TFreeBitmap.GetColorType: FREE_IMAGE_COLOR_TYPE; -begin - Result := FreeImage_GetColorType(FDib); -end; - -function TFreeBitmap.GetFileBkColor(var BkColor: RGBQUAD): Boolean; -begin - Result := FreeImage_GetBackgroundColor(FDib, BkColor); -end; - -function TFreeBitmap.GetHeight: Integer; -begin - Result := FreeImage_GetHeight(FDib) -end; - -function TFreeBitmap.GetHistogram(Histo: PDWORD; - Channel: FREE_IMAGE_COLOR_CHANNEL): Boolean; -begin - if FDib <> nil then - Result := FreeImage_GetHistogram(FDib, Histo, Channel) - else - Result := False -end; - -function TFreeBitmap.GetHorizontalResolution: Double; -begin - Result := FreeImage_GetDotsPerMeterX(FDib) / 100 -end; - -function TFreeBitmap.GetImageSize: Cardinal; -begin - Result := FreeImage_GetDIBSize(FDib); -end; - -function TFreeBitmap.GetImageType: FREE_IMAGE_TYPE; -begin - Result := FreeImage_GetImageType(FDib); -end; - -function TFreeBitmap.GetInfo: PBitmapInfo; -begin - Result := FreeImage_GetInfo(FDib); -end; - -function TFreeBitmap.GetInfoHeader: PBITMAPINFOHEADER; -begin - Result := FreeImage_GetInfoHeader(FDib) -end; - -function TFreeBitmap.GetLine: Integer; -begin - Result := FreeImage_GetLine(FDib) -end; - -function TFreeBitmap.GetMetadata(Model: FREE_IMAGE_MDMODEL; - const Key: AnsiString; var Tag: TFreeTag): Boolean; -begin - Result := FreeImage_GetMetadata(Model, FDib, PAnsiChar(Key), Tag.FTag); -end; - -function TFreeBitmap.GetMetadataCount(Model: FREE_IMAGE_MDMODEL): Cardinal; -begin - Result := FreeImage_GetMetadataCount(Model, FDib); -end; - -function TFreeBitmap.GetPalette: PRGBQUAD; -begin - Result := FreeImage_GetPalette(FDib) -end; - -function TFreeBitmap.GetPaletteSize: Integer; -begin - Result := FreeImage_GetColorsUsed(FDib) * SizeOf(RGBQUAD) -end; - -function TFreeBitmap.GetPixelColor(X, Y: Cardinal; - var Value: RGBQUAD): Boolean; -begin - Result := FreeImage_GetPixelColor(FDib, X, Y, Value); -end; - -function TFreeBitmap.GetPixelIndex(X, Y: Cardinal; - var Value: Byte): Boolean; -begin - Result := FreeImage_GetPixelIndex(FDib, X, Y, Value); -end; - -function TFreeBitmap.GetScanLine(ScanLine: Integer): PByte; -var - H: Integer; -begin - H := FreeImage_GetHeight(FDib); - if ScanLine < H then - Result := FreeImage_GetScanLine(FDib, ScanLine) - else - Result := nil; -end; - -function TFreeBitmap.GetScanWidth: Integer; -begin - Result := FreeImage_GetPitch(FDib) -end; - -function TFreeBitmap.GetTransparencyCount: Cardinal; -begin - Result := FreeImage_GetTransparencyCount(FDib) -end; - -function TFreeBitmap.GetTransparencyTable: PByte; -begin - Result := FreeImage_GetTransparencyTable(FDib) -end; - -function TFreeBitmap.GetVerticalResolution: Double; -begin - Result := FreeImage_GetDotsPerMeterY(Fdib) / 100 -end; - -function TFreeBitmap.GetWidth: Integer; -begin - Result := FreeImage_GetWidth(FDib) -end; - -function TFreeBitmap.HasFileBkColor: Boolean; -begin - Result := FreeImage_HasBackgroundColor(FDib) -end; - -function TFreeBitmap.Invert: Boolean; -begin - if FDib <> nil then - begin - Result := FreeImage_Invert(FDib); - Change; - end - else - Result := False -end; - -function TFreeBitmap.IsGrayScale: Boolean; -begin - Result := (FreeImage_GetBPP(FDib) = 8) -// modif JMB NOVAXEL -// FIC_PALETTE isn't enough to tell the bitmap is grayscale -// and (FreeImage_GetColorType(FDib) = FIC_PALETTE); - and ((FreeImage_GetColorType(FDib) = FIC_MINISBLACK) or - (FreeImage_GetColorType(FDib) = FIC_MINISWHITE)); -// end of modif JMB NOVAXEL -end; - -function TFreeBitmap.IsTransparent: Boolean; -begin - Result := FreeImage_IsTransparent(FDib); -end; - -function TFreeBitmap.IsValid: Boolean; -begin - Result := FDib <> nil -end; - -function TFreeBitmap.Load(const FileName: AnsiString; Flag: Integer): Boolean; -var - fif: FREE_IMAGE_FORMAT; -begin - - // check the file signature and get its format - fif := FreeImage_GetFileType(PAnsiChar(Filename), 0); - if fif = FIF_UNKNOWN then - // no signature? - // try to guess the file format from the file extention - fif := FreeImage_GetFIFFromFilename(PAnsiChar(FileName)); - - // check that the plugin has reading capabilities ... - if (fif <> FIF_UNKNOWN) and FreeImage_FIFSupportsReading(FIF) then - begin - // free the previous dib - if FDib <> nil then - FreeImage_Unload(dib); - - // load the file - FDib := FreeImage_Load(fif, PAnsiChar(FileName), Flag); - - Change; - Result := IsValid; - end else - Result := False; -end; - -function TFreeBitmap.LoadFromHandle(IO: PFreeImageIO; Handle: fi_handle; - Flag: Integer): Boolean; -var - fif: FREE_IMAGE_FORMAT; -begin - // check the file signature and get its format - fif := FreeImage_GetFileTypeFromHandle(IO, Handle, 16); - if (fif <> FIF_UNKNOWN) and FreeImage_FIFSupportsReading(fif) then - begin - // free the previous dib - if FDib <> nil then - FreeImage_Unload(FDib); - - // load the file - FDib := FreeImage_LoadFromHandle(fif, IO, Handle, Flag); - - Change; - Result := IsValid; - end else - Result := False; -end; - -function TFreeBitmap.LoadFromMemory(MemIO: TFreeMemoryIO; - Flag: Integer): Boolean; -var - fif: FREE_IMAGE_FORMAT; -begin - - // check the file signature and get its format - fif := MemIO.GetFileType; - if (fif <> FIF_UNKNOWN) and FreeImage_FIFSupportsReading(fif) then - begin - // free the previous dib - if FDib <> nil then - FreeImage_Unload(FDib); - - // load the file - FDib := MemIO.Read(fif, Flag); - - Result := IsValid; - Change; - end else - Result := False; -end; - -function TFreeBitmap.LoadFromStream(Stream: TStream; - Flag: Integer): Boolean; -var - MemIO: TFreeMemoryIO; - Data: PByte; - MemStream: TMemoryStream; - Size: Cardinal; -begin - Size := Stream.Size; - - MemStream := TMemoryStream.Create; - try - MemStream.CopyFrom(Stream, Size); - Data := MemStream.Memory; - - MemIO := TFreeMemoryIO.Create(Data, Size); - try - Result := LoadFromMemory(MemIO); - finally - MemIO.Free; - end; - finally - MemStream.Free; - end; -end; - -function TFreeBitmap.LoadU(const FileName: {$IFDEF DELPHI2010}string{$ELSE}WideString{$ENDIF}; - Flag: Integer): Boolean; -var - fif: FREE_IMAGE_FORMAT; -begin - - // check the file signature and get its format - fif := FreeImage_GetFileTypeU(PWideChar(Filename), 0); - if fif = FIF_UNKNOWN then - // no signature? - // try to guess the file format from the file extention - fif := FreeImage_GetFIFFromFilenameU(PWideChar(FileName)); - - // check that the plugin has reading capabilities ... - if (fif <> FIF_UNKNOWN) and FreeImage_FIFSupportsReading(FIF) then - begin - // free the previous dib - if FDib <> nil then - FreeImage_Unload(dib); - - // load the file - FDib := FreeImage_LoadU(fif, PWideChar(FileName), Flag); - - Change; - Result := IsValid; - end else - Result := False; -end; - -procedure TFreeBitmap.MakeThumbnail(const Width, Height: Integer; - DestBitmap: TFreeBitmap); -type - PRGB24 = ^TRGB24; - TRGB24 = packed record - B: Byte; - G: Byte; - R: Byte; - end; -var - x, y, ix, iy: integer; - x1, x2, x3: integer; - - xscale, yscale: single; - iRed, iGrn, iBlu, iRatio: Longword; - p, c1, c2, c3, c4, c5: TRGB24; - pt, pt1: PRGB24; - iSrc, iDst, s1: integer; - i, j, r, g, b, tmpY: integer; - - RowDest, RowSource, RowSourceStart: integer; - w, h: Integer; - dxmin, dymin: integer; - ny1, ny2, ny3: integer; - dx, dy: integer; - lutX, lutY: array of integer; - - SrcBmp, DestBmp: PFIBITMAP; -begin - if not IsValid then Exit; - - if (GetWidth <= ThumbSize) and (GetHeight <= ThumbSize) then - begin - DestBitmap.Assign(Self); - Exit; - end; - - w := Width; - h := Height; - - // prepare bitmaps - if GetBitsPerPixel <> 24 then - SrcBmp := FreeImage_ConvertTo24Bits(FDib) - else - SrcBmp := FDib; - DestBmp := FreeImage_Allocate(w, h, 24); - Assert(DestBmp <> nil, 'TFreeBitmap.MakeThumbnail error'); - -{ iDst := (w * 24 + 31) and not 31; - iDst := iDst div 8; //BytesPerScanline - iSrc := (GetWidth * 24 + 31) and not 31; - iSrc := iSrc div 8; -} - // BytesPerScanline - iDst := FreeImage_GetPitch(DestBmp); - iSrc := FreeImage_GetPitch(SrcBmp); - - xscale := 1 / (w / FreeImage_GetWidth(SrcBmp)); - yscale := 1 / (h / FreeImage_GetHeight(SrcBmp)); - - // X lookup table - SetLength(lutX, w); - x1 := 0; - x2 := trunc(xscale); - for x := 0 to w - 1 do - begin - lutX[x] := x2 - x1; - x1 := x2; - x2 := trunc((x + 2) * xscale); - end; - - // Y lookup table - SetLength(lutY, h); - x1 := 0; - x2 := trunc(yscale); - for x := 0 to h - 1 do - begin - lutY[x] := x2 - x1; - x1 := x2; - x2 := trunc((x + 2) * yscale); - end; - - Dec(w); - Dec(h); - RowDest := integer(FreeImage_GetScanLine(DestBmp, 0)); - RowSourceStart := integer(FreeImage_GetScanLine(SrcBmp, 0)); - RowSource := RowSourceStart; - - for y := 0 to h do - // resampling - begin - dy := lutY[y]; - x1 := 0; - x3 := 0; - for x := 0 to w do // loop through row - begin - dx:= lutX[x]; - iRed:= 0; - iGrn:= 0; - iBlu:= 0; - RowSource := RowSourceStart; - for iy := 1 to dy do - begin - pt := PRGB24(RowSource + x1); - for ix := 1 to dx do - begin - iRed := iRed + pt.R; - iGrn := iGrn + pt.G; - iBlu := iBlu + pt.B; - inc(pt); - end; - RowSource := RowSource + iSrc; - end; - iRatio := 65535 div (dx * dy); - pt1 := PRGB24(RowDest + x3); - pt1.R := (iRed * iRatio) shr 16; - pt1.G := (iGrn * iRatio) shr 16; - pt1.B := (iBlu * iRatio) shr 16; - x1 := x1 + 3 * dx; - inc(x3,3); - end; - RowDest := RowDest + iDst; - RowSourceStart := RowSource; - end; // resampling - - if FreeImage_GetHeight(DestBmp) >= 3 then - // Sharpening... - begin - s1 := integer(FreeImage_GetScanLine(DestBmp, 0)); - iDst := integer(FreeImage_GetScanLine(DestBmp, 1)) - s1; - ny1 := Integer(s1); - ny2 := ny1 + iDst; - ny3 := ny2 + iDst; - for y := 1 to FreeImage_GetHeight(DestBmp) - 2 do - begin - for x := 0 to FreeImage_GetWidth(DestBmp) - 3 do - begin - x1 := x * 3; - x2 := x1 + 3; - x3 := x1 + 6; - - c1 := pRGB24(ny1 + x1)^; - c2 := pRGB24(ny1 + x3)^; - c3 := pRGB24(ny2 + x2)^; - c4 := pRGB24(ny3 + x1)^; - c5 := pRGB24(ny3 + x3)^; - - r := (c1.R + c2.R + (c3.R * -12) + c4.R + c5.R) div -8; - g := (c1.G + c2.G + (c3.G * -12) + c4.G + c5.G) div -8; - b := (c1.B + c2.B + (c3.B * -12) + c4.B + c5.B) div -8; - - if r < 0 then r := 0 else if r > 255 then r := 255; - if g < 0 then g := 0 else if g > 255 then g := 255; - if b < 0 then b := 0 else if b > 255 then b := 255; - - pt1 := pRGB24(ny2 + x2); - pt1.R := r; - pt1.G := g; - pt1.B := b; - end; - inc(ny1, iDst); - inc(ny2, iDst); - inc(ny3, iDst); - end; - end; // sharpening - - if SrcBmp <> FDib then - FreeImage_Unload(SrcBmp); - DestBitmap.Replace(DestBmp); -end; - -function TFreeBitmap.PasteSubImage(Src: TFreeBitmap; Left, Top, - Alpha: Integer): Boolean; -begin - if FDib <> nil then - begin - Result := FreeImage_Paste(FDib, Src.Dib, Left, Top, Alpha); - Change; - end else - Result := False; -end; - -function TFreeBitmap.Replace(NewDib: PFIBITMAP): Boolean; -begin - Result := False; - if NewDib = nil then Exit; - - if not DoChanging(FDib, NewDib) and IsValid then - FreeImage_Unload(FDib); - - FDib := NewDib; - Result := True; - Change; -end; - -function TFreeBitmap.Rescale(NewWidth, NewHeight: Integer; - Filter: FREE_IMAGE_FILTER; Dest: TFreeBitmap): Boolean; -var - Bpp: Integer; - DstDib: PFIBITMAP; -begin - Result := False; - - if FDib <> nil then - begin - Bpp := FreeImage_GetBPP(FDib); - - if Bpp < 8 then - if not ConvertToGrayscale then Exit - else - if Bpp = 16 then - // convert to 24-bit - if not ConvertTo24Bits then Exit; - - // perform upsampling / downsampling - DstDib := FreeImage_Rescale(FDib, NewWidth, NewHeight, Filter); - if Dest = nil then - Result := Replace(DstDib) - else - Result := Dest.Replace(DstDib) - end -end; - -function TFreeBitmap.Rotate(Angle: Double): Boolean; -var - Bpp: Integer; - Rotated: PFIBITMAP; -begin - Result := False; - if IsValid then - begin - Bpp := FreeImage_GetBPP(FDib); - if Bpp in [1, 8, 24, 32] then - begin -// modif JMB : FreeImage_RotateClassic : deprecated function, call to DeprecationManager in 64 bits crash freeimage.dll - //Rotated := FreeImage_RotateClassic(FDib, Angle); - Rotated := FreeImage_Rotate(FDib, Angle, nil); -// end of modif JMB - //Rotated := FreeImage_Rotate(FDib, Angle); - Result := Replace(Rotated); - end - end; -end; - -function TFreeBitmap.RotateEx(Angle, XShift, YShift, XOrigin, - YOrigin: Double; UseMask: Boolean): Boolean; -var - Rotated: PFIBITMAP; -begin - Result := False; - if FDib <> nil then - begin - if FreeImage_GetBPP(FDib) >= 8 then - begin - Rotated := FreeImage_RotateEx(FDib, Angle, XShift, YShift, XOrigin, YOrigin, UseMask); - Result := Replace(Rotated); - end - end; -end; - -function TFreeBitmap.Save(const FileName: AnsiString; Flag: Integer): Boolean; -var - fif: FREE_IMAGE_FORMAT; -begin - Result := False; - - // try to guess the file format from the file extension - fif := FreeImage_GetFIFFromFilename(PAnsiChar(Filename)); - if CanSave(fif) then - Result := FreeImage_Save(fif, FDib, PAnsiChar(FileName), Flag); -end; - -function TFreeBitmap.SaveToHandle(fif: FREE_IMAGE_FORMAT; IO: PFreeImageIO; - Handle: fi_handle; Flag: Integer): Boolean; -begin - Result := False; - if CanSave(fif) then - Result := FreeImage_SaveToHandle(fif, FDib, IO, Handle, Flag) -end; - -function TFreeBitmap.SaveToMemory(fif: FREE_IMAGE_FORMAT; - MemIO: TFreeMemoryIO; Flag: Integer): Boolean; -begin - Result := False; - - if CanSave(fif) then - Result := MemIO.Write(fif, FDib, Flag) -end; - -function TFreeBitmap.SaveToStream(fif: FREE_IMAGE_FORMAT; Stream: TStream; - Flag: Integer): Boolean; -var - MemIO: TFreeMemoryIO; - Data: PByte; - Size: Cardinal; -begin - MemIO := TFreeMemoryIO.Create; - try - Result := SaveToMemory(fif, MemIO, Flag); - if Result then - begin - MemIO.Acquire(Data, Size); - Stream.WriteBuffer(Data^, Size); - end; - finally - MemIO.Free; - end; -end; - -function TFreeBitmap.SaveU(const FileName: {$IFDEF DELPHI2010}string{$ELSE}WideString{$ENDIF}; - Flag: Integer): Boolean; -var - fif: FREE_IMAGE_FORMAT; -begin - Result := False; - - // try to guess the file format from the file extension - fif := FreeImage_GetFIFFromFilenameU(PWideChar(Filename)); - if CanSave(fif) then - Result := FreeImage_SaveU(fif, FDib, PWideChar(FileName), Flag); -end; - -function TFreeBitmap.SetChannel(Bitmap: TFreeBitmap; - Channel: FREE_IMAGE_COLOR_CHANNEL): Boolean; -begin - if FDib <> nil then - begin - Result := FreeImage_SetChannel(FDib, Bitmap.FDib, Channel); - Change; - end - else - Result := False -end; - -procedure TFreeBitmap.SetDib(Value: PFIBITMAP); -begin - Replace(Value); -end; - -function TFreeBitmap.SetFileBkColor(BkColor: PRGBQuad): Boolean; -begin - Result := FreeImage_SetBackgroundColor(FDib, BkColor); - Change; -end; - -procedure TFreeBitmap.SetHorizontalResolution(Value: Double); -begin - if IsValid then - begin - FreeImage_SetDotsPerMeterX(FDib, Trunc(Value * 100 + 0.5)); - Change; - end; -end; - -function TFreeBitmap.SetMetadata(Model: FREE_IMAGE_MDMODEL; - const Key: AnsiString; Tag: TFreeTag): Boolean; -begin - Result := FreeImage_SetMetadata(Model, FDib, PAnsiChar(Key), Tag.Tag); -end; - -function TFreeBitmap.SetPixelColor(X, Y: Cardinal; - var Value: RGBQUAD): Boolean; -begin - Result := FreeImage_SetPixelColor(FDib, X, Y, Value); - Change; -end; - -function TFreeBitmap.SetPixelIndex(X, Y: Cardinal; var Value: Byte): Boolean; -begin - Result := FreeImage_SetPixelIndex(FDib, X, Y, Value); - Change; -end; - -function TFreeBitmap.SetSize(ImageType: FREE_IMAGE_TYPE; Width, Height, - Bpp: Integer; RedMask, GreenMask, BlueMask: Cardinal): Boolean; -var - Pal: PRGBQuad; - I: Cardinal; -begin - Result := False; - - if FDib <> nil then - FreeImage_Unload(FDib); - - FDib := FreeImage_Allocate(Width, Height, Bpp, RedMask, GreenMask, BlueMask); - if FDib = nil then Exit; - - if ImageType = FIT_BITMAP then - case Bpp of - 1, 4, 8: - begin - Pal := FreeImage_GetPalette(FDib); - for I := 0 to FreeImage_GetColorsUsed(FDib) - 1 do - begin - Pal.rgbBlue := I; - Pal.rgbGreen := I; - Pal.rgbRed := I; - Inc(Pal);//, SizeOf(RGBQUAD)); - end; - end; - end; - - Result := True; - Change; -end; - -procedure TFreeBitmap.SetTransparencyTable(Table: PByte; Count: Integer); -begin - FreeImage_SetTransparencyTable(FDib, Table, Count); - Change; -end; - -procedure TFreeBitmap.SetVerticalResolution(Value: Double); -begin - if IsValid then - begin - FreeImage_SetDotsPerMeterY(FDib, Trunc(Value * 100 + 0.5)); - Change; - end; -end; - -function TFreeBitmap.SplitChannels(RedChannel, GreenChannel, - BlueChannel: TFreeBitmap): Boolean; -begin - if FDib <> nil then - begin - RedChannel.FDib := FreeImage_GetChannel(FDib, FICC_RED); - GreenChannel.FDib := FreeImage_GetChannel(FDib, FICC_GREEN); - BlueChannel.FDib := FreeImage_GetChannel(FDib, FICC_BLUE); - Result := RedChannel.IsValid and GreenChannel.IsValid and BlueChannel.IsValid; - end - else - Result := False -end; - -function TFreeBitmap.Threshold(T: Byte): Boolean; -var - dib1: PFIBITMAP; -begin - if FDib <> nil then - begin - dib1 := FreeImage_Threshold(FDib, T); - Result := Replace(dib1); - end - else - Result := False -end; - -function TFreeBitmap.ToneMapping(TMO: FREE_IMAGE_TMO; FirstParam, - SecondParam: Double): Boolean; -var - NewDib: PFIBITMAP; -begin - Result := False; - if not IsValid then Exit; - - NewDib := FreeImage_ToneMapping(Fdib, TMO, FirstParam, SecondParam); - Result := Replace(NewDib); -end; - -{ TFreeWinBitmap } -{$IFDEF MSWINDOWS} -function TFreeWinBitmap.CaptureWindow(ApplicationWindow, - SelectedWindow: HWND): Boolean; -var - XScreen, YScreen, XShift, YShift, Width, Height: Integer; - R: TRect; - dstDC, srcDC, memDC: HDC; - BM, oldBM: HBITMAP; -begin - Result := False; - - // get window size - GetWindowRect(SelectedWindow, R); - - // check if the window is out of screen or maximized - XShift := 0; - YShift := 0; - XScreen := GetSystemMetrics(SM_CXSCREEN); - YScreen := GetSystemMetrics(SM_CYSCREEN); - if R.Right > XScreen then - R.Right := XScreen; - if R.Bottom > YScreen then - R.Bottom := YScreen; - if R.Left < 0 then - begin - XShift := -R.Left; - R.Left := 0; - end; - if R.Top < 0 then - begin - YShift := -R.Top; - R.Top := 0; - end; - - Width := R.Right - R.Left; - Height := R.Bottom - R.Top; - - if (Width <= 0) or (Height <= 0) then Exit; - - // hide the application window - ShowWindow(ApplicationWindow, SW_HIDE); - - // bring the window at the top most level - SetWindowPos(SelectedWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); - - // give enough time to refresh the window - Sleep(500); - - // prepare the DCs - dstDc := GetDC(0); - srcDC := GetWindowDC(SelectedWindow); //full window (GetDC(SelectedWindow) = clientarea) - memDC := CreateCompatibleDC(dstDC); - - // copy the screen to the bitmap - BM := CreateCompatibleBitmap(dstDC, Width, Height); - oldBM := HBITMAP(SelectObject(memDC, BM)); - BitBlt(memDC, 0, 0, Width, Height, srcDC, XShift, YShift, SRCCOPY); - - // redraw the application window - ShowWindow(ApplicationWindow, SW_SHOW); - - // restore the position - SetWindowPos(SelectedWindow, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); - SetWindowPos(ApplicationWindow, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); - - // convert the HBITMAP to FIBITMAP - CopyFromBitmap(BM); - - // free objects - DeleteObject(SelectObject(memDC, oldBM)); - DeleteObject(memDC); - - if GetBitsPerPixel = 32 then ConvertTo24Bits; - - Result := True; -end; -{$ENDIF} - -procedure TFreeWinBitmap.Clear; -begin - if FDeleteMe then FreeImage_Unload(FDisplayDib); - inherited; -end; - -{$IFDEF MSWINDOWS} -function TFreeWinBitmap.CopyFromBitmap(HBmp: HBITMAP): Boolean; -var - bm: BITMAP; - DC: HDC; - Success: Integer; -// modif NOVAXEL - nColors : integer; - bmih: PBitmapInfoHeader; -// end of modif NOVAXEL -begin - Result := False; - - if HBmp <> 0 then - begin - // get information about the bitmap - GetObject(HBmp, SizeOf(BITMAP), @bm); - - // create the image - SetSize(FIT_BITMAP, bm.bmWidth, bm.bmHeight, bm.bmBitsPixel); - -// modif NOVAXEL - // GetDIBits clears the biClrUsed and biClrImportant BITMAPINFO properties. - // So for the Palettized bitmaps, we need to save the count of colors and - // to restore it after the call to GetDIBits - nColors := GetColorsUsed; -// end of modif NOVAXEL - // create the device context for the bitmap - DC := GetDC(0); - - // copy the pixels - Success := GetDIBits(DC, // handle to DC - HBmp, // handle to Bitmap - 0, // first scan line - FreeImage_GetHeight(Dib), // number of scan lines to copy - FreeImage_GetBits(Dib), // array for bitmap bits - FreeImage_GetInfo(Dib)^, // bitmap data buffer - DIB_RGB_COLORS // RGB - ); - - ReleaseDC(0, DC); -// modif NOVAXEL - // as seen above, wr restore the properties which have been cleared by GetDIBits - bmih := GetInfoHeader; - bmih.biClrUsed := nColors; - bmih.biClrImportant := nColors; -// end of modif NOVAXEL - - if Success = 0 then - raise Exception.Create('Error: GetDIBits failed') - else - Result := True; - end; -end; - -function TFreeWinBitmap.CopyFromHandle(HMem: THandle): Boolean; -var - Data: PByte; - bmih: PBitmapInfoHeader; - Palette: PRGBQuad; - Bits: PByte; - BitFields: array [0..2] of DWORD; - MaskSize: Longint; - image_type: FREE_IMAGE_TYPE; -begin - Result := False; - Palette := nil; - BitFields[0] := 0; BitFields[1] := 0; BitFields[2] := 0; - - // get a pointer to the bitmap - Data := GlobalLock(HMem); - - // get a pointer to the bitmap header - bmih := PBitmapInfoHeader(Data); - - // get a pointer to the palette - if bmih.biBitCount < 16 then - begin - Palette := PRGBQUAD(bmih); - Inc(PByte(Palette), SizeOf(BITMAPINFOHEADER)); - end; - - // get a pointer to the pixels - Bits := PByte(bmih); - Inc(Bits, SizeOf(BITMAPINFOHEADER) + SizeOF(RGBQUAD) * bmih.biClrUsed); - - if bmih.biCompression = BI_BITFIELDS then - begin - // take into account the color masks that specify the red, green and blue - // components (16- and 32-bit) - MaskSize := 3 * SizeOf(DWORD); - CopyMemory(@BitFields[0], Bits, MaskSize); - Inc(Bits, MaskSize); - end; - - if Data <> nil then - begin - image_type := FIT_BITMAP; - - case GetFreeImageMarker(bmih) of - FIT_UINT16..FIT_RGBAF: image_type := GetFreeImageMarker(bmih); - end; - - // allocate a new FIBITMAP - if not SetSize(image_type, bmih.biWidth, bmih.biHeight, bmih.biBitCount, - BitFields[2], BitFields[1], BitFields[0]) then - begin - GlobalUnlock(HMem); - Exit; - end; - - // copy the bitmap header - CopyMemory(FreeImage_GetInfoHeader(Dib), bmih, SizeOf(BITMAPINFOHEADER)); - - // copy the palette - CopyMemory(FreeImage_GetPalette(Dib), Palette, bmih.biClrUsed * SizeOf(RGBQUAD)); - - // copy the bitmap - CopyMemory(FreeImage_GetBits(Dib), Bits, FreeImage_GetPitch(Dib) * FreeImage_GetHeight(Dib)); - - GlobalUnlock(HMem); - end; -end; - -function TFreeWinBitmap.CopyToBitmapH: HBITMAP; -var DC : HDC; -begin - Result:=0; - if IsValid then - begin - DC:=GetDC(0); - Result:=CreateDIBitmap(DC, - FreeImage_GetInfoHeader(Dib)^, - CBM_INIT, - PAnsiChar(FreeImage_GetBits(Dib)), - FreeImage_GetInfo(Dib)^, - DIB_RGB_COLORS); - ReleaseDC(0,DC); - end; -end; - -function TFreeWinBitmap.CopyToClipBoard(NewOwner: HWND): Boolean; -var - HDib: THandle; -begin - Result := False; - HDib := CopyToHandle; - - if OpenClipboard(NewOwner) and EmptyClipboard then - begin - if SetClipboardData(CF_DIB, HDib) = 0 then - begin - MessageBox(NewOwner, 'Unable to set clipboard data', 'FreeImage', MB_ICONERROR); - CloseClipboard; - Exit; - end; - end; - CloseClipboard; - Result := True; -end; - -function TFreeWinBitmap.CopyToHandle: THandle; -var - DibSize: Longint; - ADib, pdib: PByte; - bmih: PBITMAPINFOHEADER; - Pal: PRGBQuad; - Bits: PByte; -begin - Result := 0; - if IsValid then - begin - // get equivalent DIB size - DibSize := SizeOf(BITMAPINFOHEADER); - Inc(DibSize, FreeImage_GetColorsUsed(Dib) * SizeOf(RGBQUAD)); - Inc(DibSize, FreeImage_GetPitch(Dib) * FreeImage_GetHeight(Dib)); - - // allocate a DIB - Result := GlobalAlloc(GHND, DibSize); - ADib := GlobalLock(Result); - - pdib := ADib; - - // copy the BITMAPINFOHEADER - bmih := FreeImage_GetInfoHeader(Dib); - CopyMemory(pdib, bmih, SizeOf(BITMAPINFOHEADER)); - Inc(pdib, SizeOf(BITMAPINFOHEADER)); - if FreeImage_GetImageType(Dib) <> FIT_BITMAP then - SetFreeImageMarker(bmih, FDib); - - // copy the palette - Pal := FreeImage_GetPalette(Dib); - CopyMemory(pdib, Pal, FreeImage_GetColorsUsed(Dib) * SizeOf(RGBQUAD)); - Inc(pdib, FreeImage_GetColorsUsed(Dib) * SizeOf(RGBQUAD)); - - // copy the bitmap - Bits := FreeImage_GetBits(Dib); - CopyMemory(pdib, Bits, FreeImage_GetPitch(Dib) * FreeImage_GetHeight(Dib)); - - GlobalUnlock(Result); - end; -end; -{$ENDIF} - -constructor TFreeWinBitmap.Create(ImageType: FREE_IMAGE_TYPE; Width, - Height, Bpp: Integer); -begin - inherited Create(ImageType, Width, Height, Bpp); - - FDisplayDib := nil; - FDeleteMe := False; -end; - -destructor TFreeWinBitmap.Destroy; -begin - if FDeleteMe then - FreeImage_Unload(FDisplayDib); - inherited; -end; - -{$IFDEF MSWINDOWS} -procedure TFreeWinBitmap.Draw(DC: HDC; Rect: TRect); -begin - DrawEx(DC, Rect); -end; - -procedure TFreeWinBitmap.DrawEx(DC: HDC; Rect: TRect; UseFileBkg: Boolean; - AppBkColor: PRGBQuad; Bg: PFIBITMAP); -var - ImageType: FREE_IMAGE_TYPE; - HasBackground, Transparent: Boolean; - DibDouble: PFIBITMAP; -begin - if not IsValid then Exit; - - // convert to standard bitmap if needed - if FDeleteMe then - begin - FreeImage_Unload(FDisplayDib); - FDisplayDib := nil; - FDeleteMe := False; - end; - - ImageType := FreeImage_GetImageType(FDib); - if ImageType = FIT_BITMAP then - begin - HasBackground := FreeImage_HasBackgroundColor(Dib); - Transparent := FreeImage_IsTransparent(Dib); - - if not Transparent and not HasBackground then - // copy pointer - FDisplayDib := Dib - else - begin - // create the transparent / alpha blended image - FDisplayDib := FreeImage_Composite(Dib, UseFileBkg, AppBkColor, Bg); - // remember to delete FDisplayDib - FDeleteMe := True; - end - end - else - begin - // convert to standard dib for display - if ImageType <> FIT_COMPLEX then - FDisplayDib := FreeImage_ConvertToStandardType(Dib, True) - else - begin - // convert to type FIT_DOUBLE - DibDouble := FreeImage_GetComplexChannel(Dib, FICC_MAG); - FDisplayDib := FreeImage_ConvertToStandardType(DibDouble, True); - // free image of type FIT_DOUBLE - FreeImage_Unload(DibDouble); - end; - // remember to delete FDisplayDib - FDeleteMe := True; - end; - - // Draw the DIB - SetStretchBltMode(DC, COLORONCOLOR); - StretchDIBits(DC, Rect.Left, Rect.Top, - Rect.Right - Rect.Left, Rect.Bottom - Rect.Top, - 0, 0, FreeImage_GetWidth(FDisplayDib), FreeImage_GetHeight(FDisplayDib), - FreeImage_GetBits(FDisplayDib), FreeImage_GetInfo(FDisplayDib)^, DIB_RGB_COLORS, SRCCOPY); -end; - -function TFreeWinBitmap.PasteFromClipBoard: Boolean; -var - HDib: THandle; -begin - Result := False; - if not IsClipboardFormatAvailable(CF_DIB) then Exit; - - if OpenClipboard(0) then - begin - HDib := GetClipboardData(CF_DIB); - CopyFromHandle(HDib); - Result := True; - end; - CloseClipboard; -end; -{$ENDIF} - -{ TFreeMultiBitmap } - -procedure TFreeMultiBitmap.AppendPage(Bitmap: TFreeBitmap); -begin - if IsValid then - FreeImage_AppendPage(FMPage, Bitmap.FDib); -end; - -function TFreeMultiBitmap.Close(Flags: Integer): Boolean; -begin - Result := FreeImage_CloseMultiBitmap(FMPage, Flags); - FMPage := nil; -end; - -constructor TFreeMultiBitmap.Create(KeepCacheInMemory: Boolean); -begin - inherited Create; - FMemoryCache := KeepCacheInMemory; -end; - -procedure TFreeMultiBitmap.DeletePage(Page: Integer); -begin - if IsValid then - FreeImage_DeletePage(FMPage, Page); -end; - -destructor TFreeMultiBitmap.Destroy; -begin - if FMPage <> nil then Close; - inherited; -end; - -function TFreeMultiBitmap.GetLockedPageNumbers(var Pages, - Count: Integer): Boolean; -begin - Result := False; - if not IsValid then Exit; - Result := FreeImage_GetLockedPageNumbers(FMPage, Pages, Count) -end; - -function TFreeMultiBitmap.GetPageCount: Integer; -begin - Result := 0; - if IsValid then - Result := FreeImage_GetPageCount(FMPage) -end; - -procedure TFreeMultiBitmap.InsertPage(Page: Integer; Bitmap: TFreeBitmap); -begin - if IsValid then - FreeImage_InsertPage(FMPage, Page, Bitmap.FDib); -end; - -function TFreeMultiBitmap.IsValid: Boolean; -begin - Result := FMPage <> nil -end; - -procedure TFreeMultiBitmap.LockPage(Page: Integer; DestBitmap: TFreeBitmap); -begin - if not IsValid then Exit; - - if Assigned(DestBitmap) then - begin - DestBitmap.Replace(FreeImage_LockPage(FMPage, Page)); - end; -end; - -function TFreeMultiBitmap.MovePage(Target, Source: Integer): Boolean; -begin - Result := False; - if not IsValid then Exit; - Result := FreeImage_MovePage(FMPage, Target, Source); -end; - -function TFreeMultiBitmap.Open(const FileName: AnsiString; CreateNew, - ReadOnly: Boolean; Flags: Integer): Boolean; -var - fif: FREE_IMAGE_FORMAT; -begin - Result := False; - -// modif NOVAXEL -// In order to try to get the file format even if the extension is not standard, -// we check first the file signature - fif := FreeImage_GetFileType(PAnsiChar(Filename), 0); - if fif = FIF_UNKNOWN then - // no signature? -// end of modif NOVAXEL - // try to guess the file format from the filename - fif := FreeImage_GetFIFFromFilename(PAnsiChar(FileName)); - - // check for supported file types - if (fif <> FIF_UNKNOWN) and (not fif in [FIF_TIFF, FIF_ICO, FIF_GIF]) then - Exit; - - // open the stream - FMPage := FreeImage_OpenMultiBitmap(fif, PAnsiChar(FileName), CreateNew, ReadOnly, FMemoryCache, Flags); - - Result := FMPage <> nil; -end; - -procedure TFreeMultiBitmap.UnlockPage(Bitmap: TFreeBitmap; - Changed: Boolean); -begin - if IsValid then - begin - FreeImage_UnlockPage(FMPage, Bitmap.FDib, Changed); - // clear the image so that it becomes invalid. - // don't use Bitmap.Clear method because it calls FreeImage_Unload - // just clear the pointer - Bitmap.FDib := nil; - Bitmap.Change; - end; -end; - -{ TFreeMemoryIO } - -function TFreeMemoryIO.Acquire(var Data: PByte; - var SizeInBytes: DWORD): Boolean; -begin - Result := FreeImage_AcquireMemory(FHMem, Data, SizeInBytes); -end; - -constructor TFreeMemoryIO.Create(Data: PByte; SizeInBytes: DWORD); -begin - inherited Create; - FHMem := FreeImage_OpenMemory(Data, SizeInBytes); -end; - -destructor TFreeMemoryIO.Destroy; -begin - FreeImage_CloseMemory(FHMem); - inherited; -end; - -function TFreeMemoryIO.GetFileType: FREE_IMAGE_FORMAT; -begin - Result := FreeImage_GetFileTypeFromMemory(FHMem); -end; - -function TFreeMemoryIO.IsValid: Boolean; -begin - Result := FHMem <> nil -end; - -function TFreeMemoryIO.Read(fif: FREE_IMAGE_FORMAT; - Flag: Integer): PFIBITMAP; -begin - Result := FreeImage_LoadFromMemory(fif, FHMem, Flag) -end; - -function TFreeMemoryIO.Seek(Offset: Longint; Origin: Word): Boolean; -begin - Result := FreeImage_SeekMemory(FHMem, Offset, Origin) -end; - -function TFreeMemoryIO.Tell: Longint; -begin - Result := FreeImage_TellMemory(FHMem) -end; - -function TFreeMemoryIO.Write(fif: FREE_IMAGE_FORMAT; dib: PFIBITMAP; - Flag: Integer): Boolean; -begin - Result := FreeImage_SaveToMemory(fif, dib, FHMem, Flag) -end; - -{ TFreeTag } - -function TFreeTag.Clone: TFreeTag; -var - CloneTag: PFITAG; -begin - Result := nil; - if not IsValid then Exit; - - CloneTag := FreeImage_CloneTag(FTag); - Result := TFreeTag.Create(CloneTag); -end; - -constructor TFreeTag.Create(ATag: PFITAG); -begin - inherited Create; - - if ATag <> nil then - FTag := ATag - else - FTag := FreeImage_CreateTag; -end; - -destructor TFreeTag.Destroy; -begin - if IsValid then - FreeImage_DeleteTag(FTag); - - inherited; -end; - -function TFreeTag.GetCount: Cardinal; -begin - Result := 0; - if not IsValid then Exit; - - Result := FreeImage_GetTagCount(FTag); -end; - -function TFreeTag.GetDescription: AnsiString; -begin - Result := ''; - if not IsValid then Exit; - - Result := FreeImage_GetTagDescription(FTag); -end; - -function TFreeTag.GetID: Word; -begin - Result := 0; - if not IsValid then Exit; - - Result := FreeImage_GetTagID(FTag); -end; - -function TFreeTag.GetKey: AnsiString; -begin - Result := ''; - if not IsValid then Exit; - - Result := FreeImage_GetTagKey(FTag); -end; - -function TFreeTag.GetLength: Cardinal; -begin - Result := 0; - if not IsValid then Exit; - - Result := FreeImage_GetTagLength(FTag); -end; - -function TFreeTag.GetTagType: FREE_IMAGE_MDTYPE; -begin - Result := FIDT_NOTYPE; - if not IsValid then Exit; - - Result := FreeImage_GetTagType(FTag); -end; - -function TFreeTag.GetValue: Pointer; -begin - Result := nil; - if not IsValid then Exit; - - Result := FreeImage_GetTagValue(FTag); -end; - -function TFreeTag.IsValid: Boolean; -begin - Result := FTag <> nil; -end; - -procedure TFreeTag.SetCount(const Value: Cardinal); -begin - if IsValid then - FreeImage_SetTagCount(FTag, Value); -end; - -procedure TFreeTag.SetDescription(const Value: AnsiString); -begin - if IsValid then - FreeImage_SetTagDescription(FTag, PAnsiChar(Value)); -end; - -procedure TFreeTag.SetID(const Value: Word); -begin - if IsValid then - FreeImage_SetTagID(FTag, Value); -end; - -procedure TFreeTag.SetKey(const Value: AnsiString); -begin - if IsValid then - FreeImage_SetTagKey(FTag, PAnsiChar(Value)); -end; - -procedure TFreeTag.SetLength(const Value: Cardinal); -begin - if IsValid then - FreeImage_SetTagLength(FTag, Value); -end; - -procedure TFreeTag.SetTagType(const Value: FREE_IMAGE_MDTYPE); -begin - if IsValid then - FreeImage_SetTagType(FTag, Value); -end; - -procedure TFreeTag.SetValue(const Value: Pointer); -begin - if IsValid then - FreeImage_SetTagValue(FTag, Value); -end; - -function TFreeTag.ToString(Model: FREE_IMAGE_MDMODEL; Make: PAnsiChar): AnsiString; -begin - Result := FreeImage_TagToString(Model, FTag, Make); -end; - -end. +unit FreeBitmap; + +// ========================================================== +// +// Delphi wrapper for FreeImage 3 +// +// Design and implementation by +// - Anatoliy Pulyaevskiy (xvel84@rambler.ru) +// +// Contributors: +// - Enzo Costantini (enzocostantini@libero.it) +// - Lorenzo Monti (LM) lomo74@gmail.com +// +// Revision history +// When Who What +// ----------- ----- ----------------------------------------------------------- +// 2010-07-14 LM made RAD2010 compliant (unicode) +// 2011-03-04 JMB modifications to run on 64 bits (Windows and linux) : +// - FreeImage_RotateClassic : deprecated function, call to DeprecationManager in 64 bits crashes freeimage.dll +// ==> FreeImage_RotateClassic : replaced by FreeImage_Rotate +// modifications to run on linux : +// - exclude windows specific functions by compilation directives +// some corrections in : +// - TFreeBitmap.DoChanging +// - TFreeBitmap.IsGrayScale +// - TFreeWinBitmap.CopyFromBitmap +// - TFreeMultiBitmap.Open + +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// +// ========================================================== +// +// From begining all code of this file is based on C++ wrapper to +// FreeImage - FreeImagePlus. +// +// ========================================================== + +interface + +{$I 'Version.inc'} + +uses + SysUtils, Classes, +{$IFDEF MSWINDOWS} + Windows, +{$ENDIF} + FreeImage; + +type + { TFreeObject } + + TFreeObject = class(TObject) + public + function IsValid: Boolean; virtual; + end; + + { TFreeTag } + + TFreeTag = class(TFreeObject) + private + // fields + FTag: PFITAG; + + // getters & setters + function GetCount: Cardinal; + function GetDescription: AnsiString; + function GetID: Word; + function GetKey: AnsiString; + function GetLength: Cardinal; + function GetTagType: FREE_IMAGE_MDTYPE; + function GetValue: Pointer; + procedure SetCount(const Value: Cardinal); + procedure SetDescription(const Value: AnsiString); + procedure SetID(const Value: Word); + procedure SetKey(const Value: AnsiString); + procedure SetLength(const Value: Cardinal); + procedure SetTagType(const Value: FREE_IMAGE_MDTYPE); + procedure SetValue(const Value: Pointer); + public + // construction & destruction + constructor Create(ATag: PFITAG = nil); virtual; + destructor Destroy; override; + + // methods + function Clone: TFreeTag; + function IsValid: Boolean; override; + function ToString(Model: FREE_IMAGE_MDMODEL; Make: PAnsiChar = nil): AnsiString; reintroduce; + + // properties + property Key: AnsiString read GetKey write SetKey; + property Description: AnsiString read GetDescription write SetDescription; + property ID: Word read GetID write SetID; + property TagType: FREE_IMAGE_MDTYPE read GetTagType write SetTagType; + property Count: Cardinal read GetCount write SetCount; + property Length: Cardinal read GetLength write SetLength; + property Value: Pointer read GetValue write SetValue; + property Tag: PFITAG read FTag; + end; + + { forward declarations } + + TFreeBitmap = class; + TFreeMemoryIO = class; + + { TFreeBitmap } + + TFreeBitmapChangingEvent = procedure(Sender: TFreeBitmap; var OldDib, NewDib: PFIBITMAP; var Handled: Boolean) of object; + + TFreeBitmap = class(TFreeObject) + private + // fields + FDib: PFIBITMAP; + FOnChange: TNotifyEvent; + FOnChanging: TFreeBitmapChangingEvent; + + procedure SetDib(Value: PFIBITMAP); + protected + function DoChanging(var OldDib, NewDib: PFIBITMAP): Boolean; dynamic; + function Replace(NewDib: PFIBITMAP): Boolean; dynamic; + public + constructor Create(ImageType: FREE_IMAGE_TYPE = FIT_BITMAP; Width: Integer = 0; Height: Integer = 0; Bpp: Integer = 0); + destructor Destroy; override; + function SetSize(ImageType: FREE_IMAGE_TYPE; Width, Height, Bpp: Integer; RedMask: Cardinal = 0; GreenMask: Cardinal = 0; BlueMask: Cardinal = 0): Boolean; + procedure Change; dynamic; + procedure Assign(Source: TFreeBitmap); + function CopySubImage(Left, Top, Right, Bottom: Integer; Dest: TFreeBitmap): Boolean; + function PasteSubImage(Src: TFreeBitmap; Left, Top: Integer; Alpha: Integer = 256): Boolean; + procedure Clear; virtual; + function Load(const FileName: AnsiString; Flag: Integer = 0): Boolean; + function LoadU(const FileName: {$IFDEF DELPHI2010}string{$ELSE}WideString{$ENDIF}; Flag: Integer = 0): Boolean; + function LoadFromHandle(IO: PFreeImageIO; Handle: fi_handle; Flag: Integer = 0): Boolean; + function LoadFromMemory(MemIO: TFreeMemoryIO; Flag: Integer = 0): Boolean; + function LoadFromStream(Stream: TStream; Flag: Integer = 0): Boolean; + // save functions + function CanSave(fif: FREE_IMAGE_FORMAT): Boolean; + function Save(const FileName: AnsiString; Flag: Integer = 0): Boolean; + function SaveU(const FileName: {$IFDEF DELPHI2010}string{$ELSE}WideString{$ENDIF}; Flag: Integer = 0): Boolean; + function SaveToHandle(fif: FREE_IMAGE_FORMAT; IO: PFreeImageIO; Handle: fi_handle; Flag: Integer = 0): Boolean; + function SaveToMemory(fif: FREE_IMAGE_FORMAT; MemIO: TFreeMemoryIO; Flag: Integer = 0): Boolean; + function SaveToStream(fif: FREE_IMAGE_FORMAT; Stream: TStream; Flag: Integer = 0): Boolean; + // image information + function GetImageType: FREE_IMAGE_TYPE; + function GetWidth: Integer; + function GetHeight: Integer; + function GetScanWidth: Integer; + function IsValid: Boolean; override; + function GetInfo: PBitmapInfo; + function GetInfoHeader: PBitmapInfoHeader; + function GetImageSize: Cardinal; + function GetBitsPerPixel: Integer; + function GetLine: Integer; + function GetHorizontalResolution: Double; + function GetVerticalResolution: Double; + procedure SetHorizontalResolution(Value: Double); + procedure SetVerticalResolution(Value: Double); + // palette operations + function GetPalette: PRGBQUAD; + function GetPaletteSize: Integer; + function GetColorsUsed: Integer; + function GetColorType: FREE_IMAGE_COLOR_TYPE; + function IsGrayScale: Boolean; + // pixels access + function AccessPixels: PByte; + function GetScanLine(ScanLine: Integer): PByte; + function GetPixelIndex(X, Y: Cardinal; var Value: Byte): Boolean; + function GetPixelColor(X, Y: Cardinal; var Value: RGBQUAD): Boolean; + function SetPixelIndex(X, Y: Cardinal; var Value: Byte): Boolean; + function SetPixelColor(X, Y: Cardinal; var Value: RGBQUAD): Boolean; + // convertion + function ConvertToStandardType(ScaleLinear: Boolean): Boolean; + function ConvertToType(ImageType: FREE_IMAGE_TYPE; ScaleLinear: Boolean): Boolean; + function Threshold(T: Byte): Boolean; + function ConvertTo4Bits: Boolean; + function ConvertTo8Bits: Boolean; + function ConvertTo16Bits555: Boolean; + function ConvertTo16Bits565: Boolean; + function ConvertTo24Bits: Boolean; + function ConvertTo32Bits: Boolean; + function ConvertToGrayscale: Boolean; + function ColorQuantize(Algorithm: FREE_IMAGE_QUANTIZE): Boolean; + function Dither(Algorithm: FREE_IMAGE_DITHER): Boolean; + function ConvertToRGBF: Boolean; + function ToneMapping(TMO: FREE_IMAGE_TMO; FirstParam, SecondParam: Double): Boolean; + // transparency + function IsTransparent: Boolean; + function GetTransparencyCount: Cardinal; + function GetTransparencyTable: PByte; + procedure SetTransparencyTable(Table: PByte; Count: Integer); + function HasFileBkColor: Boolean; + function GetFileBkColor(var BkColor: RGBQUAD): Boolean; + function SetFileBkColor(BkColor: PRGBQuad): Boolean; + // channel processing routines + function GetChannel(Bitmap: TFreeBitmap; Channel: FREE_IMAGE_COLOR_CHANNEL): Boolean; + function SetChannel(Bitmap: TFreeBitmap; Channel: FREE_IMAGE_COLOR_CHANNEL): Boolean; + function SplitChannels(RedChannel, GreenChannel, BlueChannel: TFreeBitmap): Boolean; + function CombineChannels(Red, Green, Blue: TFreeBitmap): Boolean; + // rotation and flipping + function RotateEx(Angle, XShift, YShift, XOrigin, YOrigin: Double; UseMask: Boolean): Boolean; + function Rotate(Angle: Double): Boolean; + function FlipHorizontal: Boolean; + function FlipVertical: Boolean; + // color manipulation routines + function Invert: Boolean; + function AdjustCurve(Lut: PByte; Channel: FREE_IMAGE_COLOR_CHANNEL): Boolean; + function AdjustGamma(Gamma: Double): Boolean; + function AdjustBrightness(Percentage: Double): Boolean; + function AdjustContrast(Percentage: Double): Boolean; + function GetHistogram(Histo: PDWORD; Channel: FREE_IMAGE_COLOR_CHANNEL = FICC_BLACK): Boolean; + // upsampling / downsampling + procedure MakeThumbnail(const Width, Height: Integer; DestBitmap: TFreeBitmap); + function Rescale(NewWidth, NewHeight: Integer; Filter: FREE_IMAGE_FILTER; Dest: TFreeBitmap = nil): Boolean; + // metadata routines + function FindFirstMetadata(Model: FREE_IMAGE_MDMODEL; var Tag: TFreeTag): PFIMETADATA; + function FindNextMetadata(MDHandle: PFIMETADATA; var Tag: TFreeTag): Boolean; + procedure FindCloseMetadata(MDHandle: PFIMETADATA); + function SetMetadata(Model: FREE_IMAGE_MDMODEL; const Key: AnsiString; Tag: TFreeTag): Boolean; + function GetMetadata(Model: FREE_IMAGE_MDMODEL; const Key: AnsiString; var Tag: TFreeTag): Boolean; + function GetMetadataCount(Model: FREE_IMAGE_MDMODEL): Cardinal; + + // properties + property Dib: PFIBITMAP read FDib write SetDib; + property OnChange: TNotifyEvent read FOnChange write FOnChange; + property OnChanging: TFreeBitmapChangingEvent read FOnChanging write FOnChanging; + end; + + { TFreeWinBitmap } + + TFreeWinBitmap = class(TFreeBitmap) + private + FDeleteMe: Boolean; // True - need to delete FDisplayDib + FDisplayDib: PFIBITMAP; // Image that paints on DC + public + constructor Create(ImageType: FREE_IMAGE_TYPE = FIT_BITMAP; Width: Integer = 0; Height: Integer = 0; Bpp: Integer = 0); + destructor Destroy; override; + + procedure Clear; override; +{$IFDEF MSWINDOWS} + function CopyToHandle: THandle; + function CopyFromHandle(HMem: THandle): Boolean; + function CopyFromBitmap(HBmp: HBITMAP): Boolean; + function CopyToBitmapH: HBITMAP; + function CopyToClipBoard(NewOwner: HWND): Boolean; + function PasteFromClipBoard: Boolean; + function CaptureWindow(ApplicationWindow, SelectedWindow: HWND): Boolean; + + procedure Draw(DC: HDC; Rect: TRect); + procedure DrawEx(DC: HDC; Rect: TRect; UseFileBkg: Boolean = False; AppBkColor: PRGBQuad = nil; Bg: PFIBITMAP = nil); +{$ENDIF} + end; + + { TFreeMemoryIO } + + TFreeMemoryIO = class(TFreeObject) + private + FHMem: PFIMEMORY; + public + // construction and destruction + constructor Create(Data: PByte = nil; SizeInBytes: DWORD = 0); + destructor Destroy; override; + + function GetFileType: FREE_IMAGE_FORMAT; + function Read(fif: FREE_IMAGE_FORMAT; Flag: Integer = 0): PFIBITMAP; + function Write(fif: FREE_IMAGE_FORMAT; dib: PFIBITMAP; Flag: Integer = 0): Boolean; + function Tell: Longint; + function Seek(Offset: Longint; Origin: Word): Boolean; + function Acquire(var Data: PByte; var SizeInBytes: DWORD): Boolean; + // overriden methods + function IsValid: Boolean; override; + end; + + { TFreeMultiBitmap } + + TFreeMultiBitmap = class(TFreeObject) + private + FMPage: PFIMULTIBITMAP; + FMemoryCache: Boolean; + public + // constructor and destructor + constructor Create(KeepCacheInMemory: Boolean = False); + destructor Destroy; override; + + // methods + function Open(const FileName: AnsiString; CreateNew, ReadOnly: Boolean; Flags: Integer = 0): Boolean; + function Close(Flags: Integer = 0): Boolean; + function GetPageCount: Integer; + procedure AppendPage(Bitmap: TFreeBitmap); + procedure InsertPage(Page: Integer; Bitmap: TFreeBitmap); + procedure DeletePage(Page: Integer); + function MovePage(Target, Source: Integer): Boolean; + procedure LockPage(Page: Integer; DestBitmap: TFreeBitmap); + procedure UnlockPage(Bitmap: TFreeBitmap; Changed: Boolean); + function GetLockedPageNumbers(var Pages: Integer; var Count: Integer): Boolean; + // overriden methods + function IsValid: Boolean; override; + + // properties + // change of this property influences only on the next opening of a file + property MemoryCache: Boolean read FMemoryCache write FMemoryCache; + end; + +implementation + +const + ThumbSize = 150; + +// marker used for clipboard copy / paste + +procedure SetFreeImageMarker(bmih: PBitmapInfoHeader; dib: PFIBITMAP); +begin + // Windows constants goes from 0L to 5L + // Add $FF to avoid conflicts + bmih.biCompression := $FF + FreeImage_GetImageType(dib); +end; + +function GetFreeImageMarker(bmih: PBitmapInfoHeader): FREE_IMAGE_TYPE; +begin + Result := FREE_IMAGE_TYPE(bmih.biCompression - $FF); +end; + +{ TFreePersistent } + +function TFreeObject.IsValid: Boolean; +begin + Result := False +end; + +{ TFreeBitmap } + +function TFreeBitmap.AccessPixels: PByte; +begin + Result := FreeImage_GetBits(FDib) +end; + +function TFreeBitmap.AdjustBrightness(Percentage: Double): Boolean; +begin + if FDib <> nil then + begin + Result := FreeImage_AdjustBrightness(FDib, Percentage); + Change; + end + else + Result := False +end; + +function TFreeBitmap.AdjustContrast(Percentage: Double): Boolean; +begin + if FDib <> nil then + begin + Result := FreeImage_AdjustContrast(FDib, Percentage); + Change; + end + else + Result := False +end; + +function TFreeBitmap.AdjustCurve(Lut: PByte; + Channel: FREE_IMAGE_COLOR_CHANNEL): Boolean; +begin + if FDib <> nil then + begin + Result := FreeImage_AdjustCurve(FDib, Lut, Channel); + Change; + end + else + Result := False +end; + +function TFreeBitmap.AdjustGamma(Gamma: Double): Boolean; +begin + if FDib <> nil then + begin + Result := FreeImage_AdjustGamma(FDib, Gamma); + Change; + end + else + Result := False +end; + +procedure TFreeBitmap.Assign(Source: TFreeBitmap); +var + SourceBmp: TFreeBitmap; + Clone: PFIBITMAP; +begin + if Source = nil then + begin + Clear; + Exit; + end; + + if Source is TFreeBitmap then + begin + SourceBmp := TFreeBitmap(Source); + if SourceBmp <> Self then + begin + if SourceBmp.IsValid then + begin + Clone := FreeImage_Clone(SourceBmp.FDib); + Replace(Clone); + end + else + Clear; + end; + end; +end; + +function TFreeBitmap.CanSave(fif: FREE_IMAGE_FORMAT): Boolean; +var + ImageType: FREE_IMAGE_TYPE; + Bpp: Word; +begin + Result := False; + if not IsValid then Exit; + + if fif <> FIF_UNKNOWN then + begin + // check that the dib can be saved in this format + ImageType := FreeImage_GetImageType(FDib); + if ImageType = FIT_BITMAP then + begin + // standard bitmap type + Bpp := FreeImage_GetBPP(FDib); + Result := FreeImage_FIFSupportsWriting(fif) + and FreeImage_FIFSupportsExportBPP(fif, Bpp); + end + else // special bitmap type + Result := FreeImage_FIFSupportsExportType(fif, ImageType); + end; +end; + +procedure TFreeBitmap.Change; +begin + if Assigned(FOnChange) then FOnChange(Self) +end; + +procedure TFreeBitmap.Clear; +begin + if FDib <> nil then + begin + FreeImage_Unload(FDib); + FDib := nil; + Change; + end; +end; + +function TFreeBitmap.ColorQuantize( + Algorithm: FREE_IMAGE_QUANTIZE): Boolean; +var + dib8: PFIBITMAP; +begin + if FDib <> nil then + begin + dib8 := FreeImage_ColorQuantize(FDib, Algorithm); + Result := Replace(dib8); + end + else + Result := False; +end; + +function TFreeBitmap.CombineChannels(Red, Green, + Blue: TFreeBitmap): Boolean; +var + Width, Height: Integer; +begin + if FDib = nil then + begin + Width := Red.GetWidth; + Height := Red.GetHeight; + FDib := FreeImage_Allocate(Width, Height, 24, FI_RGBA_RED_MASK, + FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + end; + + if FDib <> nil then + begin + Result := FreeImage_SetChannel(FDib, Red.FDib, FICC_RED) and + FreeImage_SetChannel(FDib, Green.FDib, FICC_GREEN) and + FreeImage_SetChannel(FDib, Blue.FDib, FICC_BLUE); + + Change + end + else + Result := False; +end; + +function TFreeBitmap.ConvertTo16Bits555: Boolean; +var + dib16_555: PFIBITMAP; +begin + if FDib <> nil then + begin + dib16_555 := FreeImage_ConvertTo16Bits555(FDib); + Result := Replace(dib16_555); + end + else + Result := False +end; + +function TFreeBitmap.ConvertTo16Bits565: Boolean; +var + dib16_565: PFIBITMAP; +begin + if FDib <> nil then + begin + dib16_565 := FreeImage_ConvertTo16Bits565(FDib); + Result := Replace(dib16_565); + end + else + Result := False +end; + +function TFreeBitmap.ConvertTo24Bits: Boolean; +var + dibRGB: PFIBITMAP; +begin + if FDib <> nil then + begin + dibRGB := FreeImage_ConvertTo24Bits(FDib); + Result := Replace(dibRGB); + end + else + Result := False +end; + +function TFreeBitmap.ConvertTo32Bits: Boolean; +var + dib32: PFIBITMAP; +begin + if FDib <> nil then + begin + dib32 := FreeImage_ConvertTo32Bits(FDib); + Result := Replace(dib32); + end + else + Result := False +end; + +function TFreeBitmap.ConvertTo4Bits: Boolean; +var + dib4: PFIBITMAP; +begin + Result := False; + if IsValid then + begin + dib4 := FreeImage_ConvertTo4Bits(FDib); + Result := Replace(dib4); + end; +end; + +function TFreeBitmap.ConvertTo8Bits: Boolean; +var + dib8: PFIBITMAP; +begin + if FDib <> nil then + begin + dib8 := FreeImage_ConvertTo8Bits(FDib); + Result := Replace(dib8); + end + else + Result := False +end; + +function TFreeBitmap.ConvertToGrayscale: Boolean; +var + dib8: PFIBITMAP; +begin + Result := False; + + if IsValid then + begin + dib8 := FreeImage_ConvertToGreyscale(FDib); + Result := Replace(dib8); + end +end; + +function TFreeBitmap.ConvertToRGBF: Boolean; +var + ImageType: FREE_IMAGE_TYPE; + NewDib: PFIBITMAP; +begin + Result := False; + if not IsValid then Exit; + + ImageType := GetImageType; + + if (ImageType = FIT_BITMAP) then + begin + if GetBitsPerPixel < 24 then + if not ConvertTo24Bits then + Exit + end; + NewDib := FreeImage_ConvertToRGBF(FDib); + Result := Replace(NewDib); +end; + +function TFreeBitmap.ConvertToStandardType(ScaleLinear: Boolean): Boolean; +var + dibStandard: PFIBITMAP; +begin + if IsValid then + begin + dibStandard := FreeImage_ConvertToStandardType(FDib, ScaleLinear); + Result := Replace(dibStandard); + end + else + Result := False; +end; + +function TFreeBitmap.ConvertToType(ImageType: FREE_IMAGE_TYPE; + ScaleLinear: Boolean): Boolean; +var + dib: PFIBITMAP; +begin + if FDib <> nil then + begin + dib := FreeImage_ConvertToType(FDib, ImageType, ScaleLinear); + Result := Replace(dib) + end + else + Result := False +end; + +function TFreeBitmap.CopySubImage(Left, Top, Right, Bottom: Integer; + Dest: TFreeBitmap): Boolean; +begin + if FDib <> nil then + begin + Dest.FDib := FreeImage_Copy(FDib, Left, Top, Right, Bottom); + Result := Dest.IsValid; + end else + Result := False; +end; + +constructor TFreeBitmap.Create(ImageType: FREE_IMAGE_TYPE; Width, Height, + Bpp: Integer); +begin + inherited Create; + + FDib := nil; + if (Width > 0) and (Height > 0) and (Bpp > 0) then + SetSize(ImageType, Width, Height, Bpp); +end; + +destructor TFreeBitmap.Destroy; +begin + if FDib <> nil then + FreeImage_Unload(FDib); + inherited; +end; + +function TFreeBitmap.Dither(Algorithm: FREE_IMAGE_DITHER): Boolean; +var + dib: PFIBITMAP; +begin + if FDib <> nil then + begin + dib := FreeImage_Dither(FDib, Algorithm); + Result := Replace(dib); + end + else + Result := False; +end; + +function TFreeBitmap.DoChanging(var OldDib, NewDib: PFIBITMAP): Boolean; +begin + Result := False; + if (OldDib <> NewDib) and Assigned(FOnChanging) then + FOnChanging(Self, OldDib, NewDib, Result); +end; + +procedure TFreeBitmap.FindCloseMetadata(MDHandle: PFIMETADATA); +begin + FreeImage_FindCloseMetadata(MDHandle); +end; + +function TFreeBitmap.FindFirstMetadata(Model: FREE_IMAGE_MDMODEL; + var Tag: TFreeTag): PFIMETADATA; +begin + Result := FreeImage_FindFirstMetadata(Model, FDib, Tag.FTag); +end; + +function TFreeBitmap.FindNextMetadata(MDHandle: PFIMETADATA; + var Tag: TFreeTag): Boolean; +begin + Result := FreeImage_FindNextMetadata(MDHandle, Tag.FTag); +end; + +function TFreeBitmap.FlipHorizontal: Boolean; +begin + if FDib <> nil then + begin + Result := FreeImage_FlipHorizontal(FDib); + Change; + end + else + Result := False +end; + +function TFreeBitmap.FlipVertical: Boolean; +begin + if FDib <> nil then + begin + Result := FreeImage_FlipVertical(FDib); + Change; + end + else + Result := False +end; + +function TFreeBitmap.GetBitsPerPixel: Integer; +begin + Result := FreeImage_GetBPP(FDib) +end; + +function TFreeBitmap.GetChannel(Bitmap: TFreeBitmap; + Channel: FREE_IMAGE_COLOR_CHANNEL): Boolean; +begin + if FDib <> nil then + begin + Bitmap.Dib := FreeImage_GetChannel(FDib, Channel); + Result := Bitmap.IsValid; + end + else + Result := False +end; + +function TFreeBitmap.GetColorsUsed: Integer; +begin + Result := FreeImage_GetColorsUsed(FDib) +end; + +function TFreeBitmap.GetColorType: FREE_IMAGE_COLOR_TYPE; +begin + Result := FreeImage_GetColorType(FDib); +end; + +function TFreeBitmap.GetFileBkColor(var BkColor: RGBQUAD): Boolean; +begin + Result := FreeImage_GetBackgroundColor(FDib, BkColor); +end; + +function TFreeBitmap.GetHeight: Integer; +begin + Result := FreeImage_GetHeight(FDib) +end; + +function TFreeBitmap.GetHistogram(Histo: PDWORD; + Channel: FREE_IMAGE_COLOR_CHANNEL): Boolean; +begin + if FDib <> nil then + Result := FreeImage_GetHistogram(FDib, Histo, Channel) + else + Result := False +end; + +function TFreeBitmap.GetHorizontalResolution: Double; +begin + Result := FreeImage_GetDotsPerMeterX(FDib) / 100 +end; + +function TFreeBitmap.GetImageSize: Cardinal; +begin + Result := FreeImage_GetDIBSize(FDib); +end; + +function TFreeBitmap.GetImageType: FREE_IMAGE_TYPE; +begin + Result := FreeImage_GetImageType(FDib); +end; + +function TFreeBitmap.GetInfo: PBitmapInfo; +begin + Result := FreeImage_GetInfo(FDib); +end; + +function TFreeBitmap.GetInfoHeader: PBITMAPINFOHEADER; +begin + Result := FreeImage_GetInfoHeader(FDib) +end; + +function TFreeBitmap.GetLine: Integer; +begin + Result := FreeImage_GetLine(FDib) +end; + +function TFreeBitmap.GetMetadata(Model: FREE_IMAGE_MDMODEL; + const Key: AnsiString; var Tag: TFreeTag): Boolean; +begin + Result := FreeImage_GetMetadata(Model, FDib, PAnsiChar(Key), Tag.FTag); +end; + +function TFreeBitmap.GetMetadataCount(Model: FREE_IMAGE_MDMODEL): Cardinal; +begin + Result := FreeImage_GetMetadataCount(Model, FDib); +end; + +function TFreeBitmap.GetPalette: PRGBQUAD; +begin + Result := FreeImage_GetPalette(FDib) +end; + +function TFreeBitmap.GetPaletteSize: Integer; +begin + Result := FreeImage_GetColorsUsed(FDib) * SizeOf(RGBQUAD) +end; + +function TFreeBitmap.GetPixelColor(X, Y: Cardinal; + var Value: RGBQUAD): Boolean; +begin + Result := FreeImage_GetPixelColor(FDib, X, Y, Value); +end; + +function TFreeBitmap.GetPixelIndex(X, Y: Cardinal; + var Value: Byte): Boolean; +begin + Result := FreeImage_GetPixelIndex(FDib, X, Y, Value); +end; + +function TFreeBitmap.GetScanLine(ScanLine: Integer): PByte; +var + H: Integer; +begin + H := FreeImage_GetHeight(FDib); + if ScanLine < H then + Result := FreeImage_GetScanLine(FDib, ScanLine) + else + Result := nil; +end; + +function TFreeBitmap.GetScanWidth: Integer; +begin + Result := FreeImage_GetPitch(FDib) +end; + +function TFreeBitmap.GetTransparencyCount: Cardinal; +begin + Result := FreeImage_GetTransparencyCount(FDib) +end; + +function TFreeBitmap.GetTransparencyTable: PByte; +begin + Result := FreeImage_GetTransparencyTable(FDib) +end; + +function TFreeBitmap.GetVerticalResolution: Double; +begin + Result := FreeImage_GetDotsPerMeterY(Fdib) / 100 +end; + +function TFreeBitmap.GetWidth: Integer; +begin + Result := FreeImage_GetWidth(FDib) +end; + +function TFreeBitmap.HasFileBkColor: Boolean; +begin + Result := FreeImage_HasBackgroundColor(FDib) +end; + +function TFreeBitmap.Invert: Boolean; +begin + if FDib <> nil then + begin + Result := FreeImage_Invert(FDib); + Change; + end + else + Result := False +end; + +function TFreeBitmap.IsGrayScale: Boolean; +begin + Result := (FreeImage_GetBPP(FDib) = 8) +// modif JMB NOVAXEL +// FIC_PALETTE isn't enough to tell the bitmap is grayscale +// and (FreeImage_GetColorType(FDib) = FIC_PALETTE); + and ((FreeImage_GetColorType(FDib) = FIC_MINISBLACK) or + (FreeImage_GetColorType(FDib) = FIC_MINISWHITE)); +// end of modif JMB NOVAXEL +end; + +function TFreeBitmap.IsTransparent: Boolean; +begin + Result := FreeImage_IsTransparent(FDib); +end; + +function TFreeBitmap.IsValid: Boolean; +begin + Result := FDib <> nil +end; + +function TFreeBitmap.Load(const FileName: AnsiString; Flag: Integer): Boolean; +var + fif: FREE_IMAGE_FORMAT; +begin + + // check the file signature and get its format + fif := FreeImage_GetFileType(PAnsiChar(Filename), 0); + if fif = FIF_UNKNOWN then + // no signature? + // try to guess the file format from the file extention + fif := FreeImage_GetFIFFromFilename(PAnsiChar(FileName)); + + // check that the plugin has reading capabilities ... + if (fif <> FIF_UNKNOWN) and FreeImage_FIFSupportsReading(FIF) then + begin + // free the previous dib + if FDib <> nil then + FreeImage_Unload(dib); + + // load the file + FDib := FreeImage_Load(fif, PAnsiChar(FileName), Flag); + + Change; + Result := IsValid; + end else + Result := False; +end; + +function TFreeBitmap.LoadFromHandle(IO: PFreeImageIO; Handle: fi_handle; + Flag: Integer): Boolean; +var + fif: FREE_IMAGE_FORMAT; +begin + // check the file signature and get its format + fif := FreeImage_GetFileTypeFromHandle(IO, Handle, 16); + if (fif <> FIF_UNKNOWN) and FreeImage_FIFSupportsReading(fif) then + begin + // free the previous dib + if FDib <> nil then + FreeImage_Unload(FDib); + + // load the file + FDib := FreeImage_LoadFromHandle(fif, IO, Handle, Flag); + + Change; + Result := IsValid; + end else + Result := False; +end; + +function TFreeBitmap.LoadFromMemory(MemIO: TFreeMemoryIO; + Flag: Integer): Boolean; +var + fif: FREE_IMAGE_FORMAT; +begin + + // check the file signature and get its format + fif := MemIO.GetFileType; + if (fif <> FIF_UNKNOWN) and FreeImage_FIFSupportsReading(fif) then + begin + // free the previous dib + if FDib <> nil then + FreeImage_Unload(FDib); + + // load the file + FDib := MemIO.Read(fif, Flag); + + Result := IsValid; + Change; + end else + Result := False; +end; + +function TFreeBitmap.LoadFromStream(Stream: TStream; + Flag: Integer): Boolean; +var + MemIO: TFreeMemoryIO; + Data: PByte; + MemStream: TMemoryStream; + Size: Cardinal; +begin + Size := Stream.Size; + + MemStream := TMemoryStream.Create; + try + MemStream.CopyFrom(Stream, Size); + Data := MemStream.Memory; + + MemIO := TFreeMemoryIO.Create(Data, Size); + try + Result := LoadFromMemory(MemIO); + finally + MemIO.Free; + end; + finally + MemStream.Free; + end; +end; + +function TFreeBitmap.LoadU(const FileName: {$IFDEF DELPHI2010}string{$ELSE}WideString{$ENDIF}; + Flag: Integer): Boolean; +var + fif: FREE_IMAGE_FORMAT; +begin + + // check the file signature and get its format + fif := FreeImage_GetFileTypeU(PWideChar(Filename), 0); + if fif = FIF_UNKNOWN then + // no signature? + // try to guess the file format from the file extention + fif := FreeImage_GetFIFFromFilenameU(PWideChar(FileName)); + + // check that the plugin has reading capabilities ... + if (fif <> FIF_UNKNOWN) and FreeImage_FIFSupportsReading(FIF) then + begin + // free the previous dib + if FDib <> nil then + FreeImage_Unload(dib); + + // load the file + FDib := FreeImage_LoadU(fif, PWideChar(FileName), Flag); + + Change; + Result := IsValid; + end else + Result := False; +end; + +procedure TFreeBitmap.MakeThumbnail(const Width, Height: Integer; + DestBitmap: TFreeBitmap); +type + PRGB24 = ^TRGB24; + TRGB24 = packed record + B: Byte; + G: Byte; + R: Byte; + end; +var + x, y, ix, iy: integer; + x1, x2, x3: integer; + + xscale, yscale: single; + iRed, iGrn, iBlu, iRatio: Longword; + p, c1, c2, c3, c4, c5: TRGB24; + pt, pt1: PRGB24; + iSrc, iDst, s1: integer; + i, j, r, g, b, tmpY: integer; + + RowDest, RowSource, RowSourceStart: integer; + w, h: Integer; + dxmin, dymin: integer; + ny1, ny2, ny3: integer; + dx, dy: integer; + lutX, lutY: array of integer; + + SrcBmp, DestBmp: PFIBITMAP; +begin + if not IsValid then Exit; + + if (GetWidth <= ThumbSize) and (GetHeight <= ThumbSize) then + begin + DestBitmap.Assign(Self); + Exit; + end; + + w := Width; + h := Height; + + // prepare bitmaps + if GetBitsPerPixel <> 24 then + SrcBmp := FreeImage_ConvertTo24Bits(FDib) + else + SrcBmp := FDib; + DestBmp := FreeImage_Allocate(w, h, 24); + Assert(DestBmp <> nil, 'TFreeBitmap.MakeThumbnail error'); + +{ iDst := (w * 24 + 31) and not 31; + iDst := iDst div 8; //BytesPerScanline + iSrc := (GetWidth * 24 + 31) and not 31; + iSrc := iSrc div 8; +} + // BytesPerScanline + iDst := FreeImage_GetPitch(DestBmp); + iSrc := FreeImage_GetPitch(SrcBmp); + + xscale := 1 / (w / FreeImage_GetWidth(SrcBmp)); + yscale := 1 / (h / FreeImage_GetHeight(SrcBmp)); + + // X lookup table + SetLength(lutX, w); + x1 := 0; + x2 := trunc(xscale); + for x := 0 to w - 1 do + begin + lutX[x] := x2 - x1; + x1 := x2; + x2 := trunc((x + 2) * xscale); + end; + + // Y lookup table + SetLength(lutY, h); + x1 := 0; + x2 := trunc(yscale); + for x := 0 to h - 1 do + begin + lutY[x] := x2 - x1; + x1 := x2; + x2 := trunc((x + 2) * yscale); + end; + + Dec(w); + Dec(h); + RowDest := integer(FreeImage_GetScanLine(DestBmp, 0)); + RowSourceStart := integer(FreeImage_GetScanLine(SrcBmp, 0)); + RowSource := RowSourceStart; + + for y := 0 to h do + // resampling + begin + dy := lutY[y]; + x1 := 0; + x3 := 0; + for x := 0 to w do // loop through row + begin + dx:= lutX[x]; + iRed:= 0; + iGrn:= 0; + iBlu:= 0; + RowSource := RowSourceStart; + for iy := 1 to dy do + begin + pt := PRGB24(RowSource + x1); + for ix := 1 to dx do + begin + iRed := iRed + pt.R; + iGrn := iGrn + pt.G; + iBlu := iBlu + pt.B; + inc(pt); + end; + RowSource := RowSource + iSrc; + end; + iRatio := 65535 div (dx * dy); + pt1 := PRGB24(RowDest + x3); + pt1.R := (iRed * iRatio) shr 16; + pt1.G := (iGrn * iRatio) shr 16; + pt1.B := (iBlu * iRatio) shr 16; + x1 := x1 + 3 * dx; + inc(x3,3); + end; + RowDest := RowDest + iDst; + RowSourceStart := RowSource; + end; // resampling + + if FreeImage_GetHeight(DestBmp) >= 3 then + // Sharpening... + begin + s1 := integer(FreeImage_GetScanLine(DestBmp, 0)); + iDst := integer(FreeImage_GetScanLine(DestBmp, 1)) - s1; + ny1 := Integer(s1); + ny2 := ny1 + iDst; + ny3 := ny2 + iDst; + for y := 1 to FreeImage_GetHeight(DestBmp) - 2 do + begin + for x := 0 to FreeImage_GetWidth(DestBmp) - 3 do + begin + x1 := x * 3; + x2 := x1 + 3; + x3 := x1 + 6; + + c1 := pRGB24(ny1 + x1)^; + c2 := pRGB24(ny1 + x3)^; + c3 := pRGB24(ny2 + x2)^; + c4 := pRGB24(ny3 + x1)^; + c5 := pRGB24(ny3 + x3)^; + + r := (c1.R + c2.R + (c3.R * -12) + c4.R + c5.R) div -8; + g := (c1.G + c2.G + (c3.G * -12) + c4.G + c5.G) div -8; + b := (c1.B + c2.B + (c3.B * -12) + c4.B + c5.B) div -8; + + if r < 0 then r := 0 else if r > 255 then r := 255; + if g < 0 then g := 0 else if g > 255 then g := 255; + if b < 0 then b := 0 else if b > 255 then b := 255; + + pt1 := pRGB24(ny2 + x2); + pt1.R := r; + pt1.G := g; + pt1.B := b; + end; + inc(ny1, iDst); + inc(ny2, iDst); + inc(ny3, iDst); + end; + end; // sharpening + + if SrcBmp <> FDib then + FreeImage_Unload(SrcBmp); + DestBitmap.Replace(DestBmp); +end; + +function TFreeBitmap.PasteSubImage(Src: TFreeBitmap; Left, Top, + Alpha: Integer): Boolean; +begin + if FDib <> nil then + begin + Result := FreeImage_Paste(FDib, Src.Dib, Left, Top, Alpha); + Change; + end else + Result := False; +end; + +function TFreeBitmap.Replace(NewDib: PFIBITMAP): Boolean; +begin + Result := False; + if NewDib = nil then Exit; + + if not DoChanging(FDib, NewDib) and IsValid then + FreeImage_Unload(FDib); + + FDib := NewDib; + Result := True; + Change; +end; + +function TFreeBitmap.Rescale(NewWidth, NewHeight: Integer; + Filter: FREE_IMAGE_FILTER; Dest: TFreeBitmap): Boolean; +var + Bpp: Integer; + DstDib: PFIBITMAP; +begin + Result := False; + + if FDib <> nil then + begin + Bpp := FreeImage_GetBPP(FDib); + + if Bpp < 8 then + if not ConvertToGrayscale then Exit + else + if Bpp = 16 then + // convert to 24-bit + if not ConvertTo24Bits then Exit; + + // perform upsampling / downsampling + DstDib := FreeImage_Rescale(FDib, NewWidth, NewHeight, Filter); + if Dest = nil then + Result := Replace(DstDib) + else + Result := Dest.Replace(DstDib) + end +end; + +function TFreeBitmap.Rotate(Angle: Double): Boolean; +var + Bpp: Integer; + Rotated: PFIBITMAP; +begin + Result := False; + if IsValid then + begin + Bpp := FreeImage_GetBPP(FDib); + if Bpp in [1, 8, 24, 32] then + begin +// modif JMB : FreeImage_RotateClassic : deprecated function, call to DeprecationManager in 64 bits crash freeimage.dll + //Rotated := FreeImage_RotateClassic(FDib, Angle); + Rotated := FreeImage_Rotate(FDib, Angle, nil); +// end of modif JMB + //Rotated := FreeImage_Rotate(FDib, Angle); + Result := Replace(Rotated); + end + end; +end; + +function TFreeBitmap.RotateEx(Angle, XShift, YShift, XOrigin, + YOrigin: Double; UseMask: Boolean): Boolean; +var + Rotated: PFIBITMAP; +begin + Result := False; + if FDib <> nil then + begin + if FreeImage_GetBPP(FDib) >= 8 then + begin + Rotated := FreeImage_RotateEx(FDib, Angle, XShift, YShift, XOrigin, YOrigin, UseMask); + Result := Replace(Rotated); + end + end; +end; + +function TFreeBitmap.Save(const FileName: AnsiString; Flag: Integer): Boolean; +var + fif: FREE_IMAGE_FORMAT; +begin + Result := False; + + // try to guess the file format from the file extension + fif := FreeImage_GetFIFFromFilename(PAnsiChar(Filename)); + if CanSave(fif) then + Result := FreeImage_Save(fif, FDib, PAnsiChar(FileName), Flag); +end; + +function TFreeBitmap.SaveToHandle(fif: FREE_IMAGE_FORMAT; IO: PFreeImageIO; + Handle: fi_handle; Flag: Integer): Boolean; +begin + Result := False; + if CanSave(fif) then + Result := FreeImage_SaveToHandle(fif, FDib, IO, Handle, Flag) +end; + +function TFreeBitmap.SaveToMemory(fif: FREE_IMAGE_FORMAT; + MemIO: TFreeMemoryIO; Flag: Integer): Boolean; +begin + Result := False; + + if CanSave(fif) then + Result := MemIO.Write(fif, FDib, Flag) +end; + +function TFreeBitmap.SaveToStream(fif: FREE_IMAGE_FORMAT; Stream: TStream; + Flag: Integer): Boolean; +var + MemIO: TFreeMemoryIO; + Data: PByte; + Size: Cardinal; +begin + MemIO := TFreeMemoryIO.Create; + try + Result := SaveToMemory(fif, MemIO, Flag); + if Result then + begin + MemIO.Acquire(Data, Size); + Stream.WriteBuffer(Data^, Size); + end; + finally + MemIO.Free; + end; +end; + +function TFreeBitmap.SaveU(const FileName: {$IFDEF DELPHI2010}string{$ELSE}WideString{$ENDIF}; + Flag: Integer): Boolean; +var + fif: FREE_IMAGE_FORMAT; +begin + Result := False; + + // try to guess the file format from the file extension + fif := FreeImage_GetFIFFromFilenameU(PWideChar(Filename)); + if CanSave(fif) then + Result := FreeImage_SaveU(fif, FDib, PWideChar(FileName), Flag); +end; + +function TFreeBitmap.SetChannel(Bitmap: TFreeBitmap; + Channel: FREE_IMAGE_COLOR_CHANNEL): Boolean; +begin + if FDib <> nil then + begin + Result := FreeImage_SetChannel(FDib, Bitmap.FDib, Channel); + Change; + end + else + Result := False +end; + +procedure TFreeBitmap.SetDib(Value: PFIBITMAP); +begin + Replace(Value); +end; + +function TFreeBitmap.SetFileBkColor(BkColor: PRGBQuad): Boolean; +begin + Result := FreeImage_SetBackgroundColor(FDib, BkColor); + Change; +end; + +procedure TFreeBitmap.SetHorizontalResolution(Value: Double); +begin + if IsValid then + begin + FreeImage_SetDotsPerMeterX(FDib, Trunc(Value * 100 + 0.5)); + Change; + end; +end; + +function TFreeBitmap.SetMetadata(Model: FREE_IMAGE_MDMODEL; + const Key: AnsiString; Tag: TFreeTag): Boolean; +begin + Result := FreeImage_SetMetadata(Model, FDib, PAnsiChar(Key), Tag.Tag); +end; + +function TFreeBitmap.SetPixelColor(X, Y: Cardinal; + var Value: RGBQUAD): Boolean; +begin + Result := FreeImage_SetPixelColor(FDib, X, Y, Value); + Change; +end; + +function TFreeBitmap.SetPixelIndex(X, Y: Cardinal; var Value: Byte): Boolean; +begin + Result := FreeImage_SetPixelIndex(FDib, X, Y, Value); + Change; +end; + +function TFreeBitmap.SetSize(ImageType: FREE_IMAGE_TYPE; Width, Height, + Bpp: Integer; RedMask, GreenMask, BlueMask: Cardinal): Boolean; +var + Pal: PRGBQuad; + I: Cardinal; +begin + Result := False; + + if FDib <> nil then + FreeImage_Unload(FDib); + + FDib := FreeImage_Allocate(Width, Height, Bpp, RedMask, GreenMask, BlueMask); + if FDib = nil then Exit; + + if ImageType = FIT_BITMAP then + case Bpp of + 1, 4, 8: + begin + Pal := FreeImage_GetPalette(FDib); + for I := 0 to FreeImage_GetColorsUsed(FDib) - 1 do + begin + Pal.rgbBlue := I; + Pal.rgbGreen := I; + Pal.rgbRed := I; + Inc(Pal);//, SizeOf(RGBQUAD)); + end; + end; + end; + + Result := True; + Change; +end; + +procedure TFreeBitmap.SetTransparencyTable(Table: PByte; Count: Integer); +begin + FreeImage_SetTransparencyTable(FDib, Table, Count); + Change; +end; + +procedure TFreeBitmap.SetVerticalResolution(Value: Double); +begin + if IsValid then + begin + FreeImage_SetDotsPerMeterY(FDib, Trunc(Value * 100 + 0.5)); + Change; + end; +end; + +function TFreeBitmap.SplitChannels(RedChannel, GreenChannel, + BlueChannel: TFreeBitmap): Boolean; +begin + if FDib <> nil then + begin + RedChannel.FDib := FreeImage_GetChannel(FDib, FICC_RED); + GreenChannel.FDib := FreeImage_GetChannel(FDib, FICC_GREEN); + BlueChannel.FDib := FreeImage_GetChannel(FDib, FICC_BLUE); + Result := RedChannel.IsValid and GreenChannel.IsValid and BlueChannel.IsValid; + end + else + Result := False +end; + +function TFreeBitmap.Threshold(T: Byte): Boolean; +var + dib1: PFIBITMAP; +begin + if FDib <> nil then + begin + dib1 := FreeImage_Threshold(FDib, T); + Result := Replace(dib1); + end + else + Result := False +end; + +function TFreeBitmap.ToneMapping(TMO: FREE_IMAGE_TMO; FirstParam, + SecondParam: Double): Boolean; +var + NewDib: PFIBITMAP; +begin + Result := False; + if not IsValid then Exit; + + NewDib := FreeImage_ToneMapping(Fdib, TMO, FirstParam, SecondParam); + Result := Replace(NewDib); +end; + +{ TFreeWinBitmap } +{$IFDEF MSWINDOWS} +function TFreeWinBitmap.CaptureWindow(ApplicationWindow, + SelectedWindow: HWND): Boolean; +var + XScreen, YScreen, XShift, YShift, Width, Height: Integer; + R: TRect; + dstDC, srcDC, memDC: HDC; + BM, oldBM: HBITMAP; +begin + Result := False; + + // get window size + GetWindowRect(SelectedWindow, R); + + // check if the window is out of screen or maximized + XShift := 0; + YShift := 0; + XScreen := GetSystemMetrics(SM_CXSCREEN); + YScreen := GetSystemMetrics(SM_CYSCREEN); + if R.Right > XScreen then + R.Right := XScreen; + if R.Bottom > YScreen then + R.Bottom := YScreen; + if R.Left < 0 then + begin + XShift := -R.Left; + R.Left := 0; + end; + if R.Top < 0 then + begin + YShift := -R.Top; + R.Top := 0; + end; + + Width := R.Right - R.Left; + Height := R.Bottom - R.Top; + + if (Width <= 0) or (Height <= 0) then Exit; + + // hide the application window + ShowWindow(ApplicationWindow, SW_HIDE); + + // bring the window at the top most level + SetWindowPos(SelectedWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); + + // give enough time to refresh the window + Sleep(500); + + // prepare the DCs + dstDc := GetDC(0); + srcDC := GetWindowDC(SelectedWindow); //full window (GetDC(SelectedWindow) = clientarea) + memDC := CreateCompatibleDC(dstDC); + + // copy the screen to the bitmap + BM := CreateCompatibleBitmap(dstDC, Width, Height); + oldBM := HBITMAP(SelectObject(memDC, BM)); + BitBlt(memDC, 0, 0, Width, Height, srcDC, XShift, YShift, SRCCOPY); + + // redraw the application window + ShowWindow(ApplicationWindow, SW_SHOW); + + // restore the position + SetWindowPos(SelectedWindow, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); + SetWindowPos(ApplicationWindow, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); + + // convert the HBITMAP to FIBITMAP + CopyFromBitmap(BM); + + // free objects + DeleteObject(SelectObject(memDC, oldBM)); + DeleteObject(memDC); + + if GetBitsPerPixel = 32 then ConvertTo24Bits; + + Result := True; +end; +{$ENDIF} + +procedure TFreeWinBitmap.Clear; +begin + if FDeleteMe then FreeImage_Unload(FDisplayDib); + inherited; +end; + +{$IFDEF MSWINDOWS} +function TFreeWinBitmap.CopyFromBitmap(HBmp: HBITMAP): Boolean; +var + bm: BITMAP; + DC: HDC; + Success: Integer; +// modif NOVAXEL + nColors : integer; + bmih: PBitmapInfoHeader; +// end of modif NOVAXEL +begin + Result := False; + + if HBmp <> 0 then + begin + // get information about the bitmap + GetObject(HBmp, SizeOf(BITMAP), @bm); + + // create the image + SetSize(FIT_BITMAP, bm.bmWidth, bm.bmHeight, bm.bmBitsPixel); + +// modif NOVAXEL + // GetDIBits clears the biClrUsed and biClrImportant BITMAPINFO properties. + // So for the Palettized bitmaps, we need to save the count of colors and + // to restore it after the call to GetDIBits + nColors := GetColorsUsed; +// end of modif NOVAXEL + // create the device context for the bitmap + DC := GetDC(0); + + // copy the pixels + Success := GetDIBits(DC, // handle to DC + HBmp, // handle to Bitmap + 0, // first scan line + FreeImage_GetHeight(Dib), // number of scan lines to copy + FreeImage_GetBits(Dib), // array for bitmap bits + FreeImage_GetInfo(Dib)^, // bitmap data buffer + DIB_RGB_COLORS // RGB + ); + + ReleaseDC(0, DC); +// modif NOVAXEL + // as seen above, wr restore the properties which have been cleared by GetDIBits + bmih := GetInfoHeader; + bmih.biClrUsed := nColors; + bmih.biClrImportant := nColors; +// end of modif NOVAXEL + + if Success = 0 then + raise Exception.Create('Error: GetDIBits failed') + else + Result := True; + end; +end; + +function TFreeWinBitmap.CopyFromHandle(HMem: THandle): Boolean; +var + Data: PByte; + bmih: PBitmapInfoHeader; + Palette: PRGBQuad; + Bits: PByte; + BitFields: array [0..2] of DWORD; + MaskSize: Longint; + image_type: FREE_IMAGE_TYPE; +begin + Result := False; + Palette := nil; + BitFields[0] := 0; BitFields[1] := 0; BitFields[2] := 0; + + // get a pointer to the bitmap + Data := GlobalLock(HMem); + + // get a pointer to the bitmap header + bmih := PBitmapInfoHeader(Data); + + // get a pointer to the palette + if bmih.biBitCount < 16 then + begin + Palette := PRGBQUAD(bmih); + Inc(PByte(Palette), SizeOf(BITMAPINFOHEADER)); + end; + + // get a pointer to the pixels + Bits := PByte(bmih); + Inc(Bits, SizeOf(BITMAPINFOHEADER) + SizeOF(RGBQUAD) * bmih.biClrUsed); + + if bmih.biCompression = BI_BITFIELDS then + begin + // take into account the color masks that specify the red, green and blue + // components (16- and 32-bit) + MaskSize := 3 * SizeOf(DWORD); + CopyMemory(@BitFields[0], Bits, MaskSize); + Inc(Bits, MaskSize); + end; + + if Data <> nil then + begin + image_type := FIT_BITMAP; + + case GetFreeImageMarker(bmih) of + FIT_UINT16..FIT_RGBAF: image_type := GetFreeImageMarker(bmih); + end; + + // allocate a new FIBITMAP + if not SetSize(image_type, bmih.biWidth, bmih.biHeight, bmih.biBitCount, + BitFields[2], BitFields[1], BitFields[0]) then + begin + GlobalUnlock(HMem); + Exit; + end; + + // copy the bitmap header + CopyMemory(FreeImage_GetInfoHeader(Dib), bmih, SizeOf(BITMAPINFOHEADER)); + + // copy the palette + CopyMemory(FreeImage_GetPalette(Dib), Palette, bmih.biClrUsed * SizeOf(RGBQUAD)); + + // copy the bitmap + CopyMemory(FreeImage_GetBits(Dib), Bits, FreeImage_GetPitch(Dib) * FreeImage_GetHeight(Dib)); + + GlobalUnlock(HMem); + end; +end; + +function TFreeWinBitmap.CopyToBitmapH: HBITMAP; +var DC : HDC; +begin + Result:=0; + if IsValid then + begin + DC:=GetDC(0); + Result:=CreateDIBitmap(DC, + FreeImage_GetInfoHeader(Dib)^, + CBM_INIT, + PAnsiChar(FreeImage_GetBits(Dib)), + FreeImage_GetInfo(Dib)^, + DIB_RGB_COLORS); + ReleaseDC(0,DC); + end; +end; + +function TFreeWinBitmap.CopyToClipBoard(NewOwner: HWND): Boolean; +var + HDib: THandle; +begin + Result := False; + HDib := CopyToHandle; + + if OpenClipboard(NewOwner) and EmptyClipboard then + begin + if SetClipboardData(CF_DIB, HDib) = 0 then + begin + MessageBox(NewOwner, 'Unable to set clipboard data', 'FreeImage', MB_ICONERROR); + CloseClipboard; + Exit; + end; + end; + CloseClipboard; + Result := True; +end; + +function TFreeWinBitmap.CopyToHandle: THandle; +var + DibSize: Longint; + ADib, pdib: PByte; + bmih: PBITMAPINFOHEADER; + Pal: PRGBQuad; + Bits: PByte; +begin + Result := 0; + if IsValid then + begin + // get equivalent DIB size + DibSize := SizeOf(BITMAPINFOHEADER); + Inc(DibSize, FreeImage_GetColorsUsed(Dib) * SizeOf(RGBQUAD)); + Inc(DibSize, FreeImage_GetPitch(Dib) * FreeImage_GetHeight(Dib)); + + // allocate a DIB + Result := GlobalAlloc(GHND, DibSize); + ADib := GlobalLock(Result); + + pdib := ADib; + + // copy the BITMAPINFOHEADER + bmih := FreeImage_GetInfoHeader(Dib); + CopyMemory(pdib, bmih, SizeOf(BITMAPINFOHEADER)); + Inc(pdib, SizeOf(BITMAPINFOHEADER)); + if FreeImage_GetImageType(Dib) <> FIT_BITMAP then + SetFreeImageMarker(bmih, FDib); + + // copy the palette + Pal := FreeImage_GetPalette(Dib); + CopyMemory(pdib, Pal, FreeImage_GetColorsUsed(Dib) * SizeOf(RGBQUAD)); + Inc(pdib, FreeImage_GetColorsUsed(Dib) * SizeOf(RGBQUAD)); + + // copy the bitmap + Bits := FreeImage_GetBits(Dib); + CopyMemory(pdib, Bits, FreeImage_GetPitch(Dib) * FreeImage_GetHeight(Dib)); + + GlobalUnlock(Result); + end; +end; +{$ENDIF} + +constructor TFreeWinBitmap.Create(ImageType: FREE_IMAGE_TYPE; Width, + Height, Bpp: Integer); +begin + inherited Create(ImageType, Width, Height, Bpp); + + FDisplayDib := nil; + FDeleteMe := False; +end; + +destructor TFreeWinBitmap.Destroy; +begin + if FDeleteMe then + FreeImage_Unload(FDisplayDib); + inherited; +end; + +{$IFDEF MSWINDOWS} +procedure TFreeWinBitmap.Draw(DC: HDC; Rect: TRect); +begin + DrawEx(DC, Rect); +end; + +procedure TFreeWinBitmap.DrawEx(DC: HDC; Rect: TRect; UseFileBkg: Boolean; + AppBkColor: PRGBQuad; Bg: PFIBITMAP); +var + ImageType: FREE_IMAGE_TYPE; + HasBackground, Transparent: Boolean; + DibDouble: PFIBITMAP; +begin + if not IsValid then Exit; + + // convert to standard bitmap if needed + if FDeleteMe then + begin + FreeImage_Unload(FDisplayDib); + FDisplayDib := nil; + FDeleteMe := False; + end; + + ImageType := FreeImage_GetImageType(FDib); + if ImageType = FIT_BITMAP then + begin + HasBackground := FreeImage_HasBackgroundColor(Dib); + Transparent := FreeImage_IsTransparent(Dib); + + if not Transparent and not HasBackground then + // copy pointer + FDisplayDib := Dib + else + begin + // create the transparent / alpha blended image + FDisplayDib := FreeImage_Composite(Dib, UseFileBkg, AppBkColor, Bg); + // remember to delete FDisplayDib + FDeleteMe := True; + end + end + else + begin + // convert to standard dib for display + if ImageType <> FIT_COMPLEX then + FDisplayDib := FreeImage_ConvertToStandardType(Dib, True) + else + begin + // convert to type FIT_DOUBLE + DibDouble := FreeImage_GetComplexChannel(Dib, FICC_MAG); + FDisplayDib := FreeImage_ConvertToStandardType(DibDouble, True); + // free image of type FIT_DOUBLE + FreeImage_Unload(DibDouble); + end; + // remember to delete FDisplayDib + FDeleteMe := True; + end; + + // Draw the DIB + SetStretchBltMode(DC, COLORONCOLOR); + StretchDIBits(DC, Rect.Left, Rect.Top, + Rect.Right - Rect.Left, Rect.Bottom - Rect.Top, + 0, 0, FreeImage_GetWidth(FDisplayDib), FreeImage_GetHeight(FDisplayDib), + FreeImage_GetBits(FDisplayDib), FreeImage_GetInfo(FDisplayDib)^, DIB_RGB_COLORS, SRCCOPY); +end; + +function TFreeWinBitmap.PasteFromClipBoard: Boolean; +var + HDib: THandle; +begin + Result := False; + if not IsClipboardFormatAvailable(CF_DIB) then Exit; + + if OpenClipboard(0) then + begin + HDib := GetClipboardData(CF_DIB); + CopyFromHandle(HDib); + Result := True; + end; + CloseClipboard; +end; +{$ENDIF} + +{ TFreeMultiBitmap } + +procedure TFreeMultiBitmap.AppendPage(Bitmap: TFreeBitmap); +begin + if IsValid then + FreeImage_AppendPage(FMPage, Bitmap.FDib); +end; + +function TFreeMultiBitmap.Close(Flags: Integer): Boolean; +begin + Result := FreeImage_CloseMultiBitmap(FMPage, Flags); + FMPage := nil; +end; + +constructor TFreeMultiBitmap.Create(KeepCacheInMemory: Boolean); +begin + inherited Create; + FMemoryCache := KeepCacheInMemory; +end; + +procedure TFreeMultiBitmap.DeletePage(Page: Integer); +begin + if IsValid then + FreeImage_DeletePage(FMPage, Page); +end; + +destructor TFreeMultiBitmap.Destroy; +begin + if FMPage <> nil then Close; + inherited; +end; + +function TFreeMultiBitmap.GetLockedPageNumbers(var Pages, + Count: Integer): Boolean; +begin + Result := False; + if not IsValid then Exit; + Result := FreeImage_GetLockedPageNumbers(FMPage, Pages, Count) +end; + +function TFreeMultiBitmap.GetPageCount: Integer; +begin + Result := 0; + if IsValid then + Result := FreeImage_GetPageCount(FMPage) +end; + +procedure TFreeMultiBitmap.InsertPage(Page: Integer; Bitmap: TFreeBitmap); +begin + if IsValid then + FreeImage_InsertPage(FMPage, Page, Bitmap.FDib); +end; + +function TFreeMultiBitmap.IsValid: Boolean; +begin + Result := FMPage <> nil +end; + +procedure TFreeMultiBitmap.LockPage(Page: Integer; DestBitmap: TFreeBitmap); +begin + if not IsValid then Exit; + + if Assigned(DestBitmap) then + begin + DestBitmap.Replace(FreeImage_LockPage(FMPage, Page)); + end; +end; + +function TFreeMultiBitmap.MovePage(Target, Source: Integer): Boolean; +begin + Result := False; + if not IsValid then Exit; + Result := FreeImage_MovePage(FMPage, Target, Source); +end; + +function TFreeMultiBitmap.Open(const FileName: AnsiString; CreateNew, + ReadOnly: Boolean; Flags: Integer): Boolean; +var + fif: FREE_IMAGE_FORMAT; +begin + Result := False; + +// modif NOVAXEL +// In order to try to get the file format even if the extension is not standard, +// we check first the file signature + fif := FreeImage_GetFileType(PAnsiChar(Filename), 0); + if fif = FIF_UNKNOWN then + // no signature? +// end of modif NOVAXEL + // try to guess the file format from the filename + fif := FreeImage_GetFIFFromFilename(PAnsiChar(FileName)); + + // check for supported file types + if (fif <> FIF_UNKNOWN) and (not fif in [FIF_TIFF, FIF_ICO, FIF_GIF]) then + Exit; + + // open the stream + FMPage := FreeImage_OpenMultiBitmap(fif, PAnsiChar(FileName), CreateNew, ReadOnly, FMemoryCache, Flags); + + Result := FMPage <> nil; +end; + +procedure TFreeMultiBitmap.UnlockPage(Bitmap: TFreeBitmap; + Changed: Boolean); +begin + if IsValid then + begin + FreeImage_UnlockPage(FMPage, Bitmap.FDib, Changed); + // clear the image so that it becomes invalid. + // don't use Bitmap.Clear method because it calls FreeImage_Unload + // just clear the pointer + Bitmap.FDib := nil; + Bitmap.Change; + end; +end; + +{ TFreeMemoryIO } + +function TFreeMemoryIO.Acquire(var Data: PByte; + var SizeInBytes: DWORD): Boolean; +begin + Result := FreeImage_AcquireMemory(FHMem, Data, SizeInBytes); +end; + +constructor TFreeMemoryIO.Create(Data: PByte; SizeInBytes: DWORD); +begin + inherited Create; + FHMem := FreeImage_OpenMemory(Data, SizeInBytes); +end; + +destructor TFreeMemoryIO.Destroy; +begin + FreeImage_CloseMemory(FHMem); + inherited; +end; + +function TFreeMemoryIO.GetFileType: FREE_IMAGE_FORMAT; +begin + Result := FreeImage_GetFileTypeFromMemory(FHMem); +end; + +function TFreeMemoryIO.IsValid: Boolean; +begin + Result := FHMem <> nil +end; + +function TFreeMemoryIO.Read(fif: FREE_IMAGE_FORMAT; + Flag: Integer): PFIBITMAP; +begin + Result := FreeImage_LoadFromMemory(fif, FHMem, Flag) +end; + +function TFreeMemoryIO.Seek(Offset: Longint; Origin: Word): Boolean; +begin + Result := FreeImage_SeekMemory(FHMem, Offset, Origin) +end; + +function TFreeMemoryIO.Tell: Longint; +begin + Result := FreeImage_TellMemory(FHMem) +end; + +function TFreeMemoryIO.Write(fif: FREE_IMAGE_FORMAT; dib: PFIBITMAP; + Flag: Integer): Boolean; +begin + Result := FreeImage_SaveToMemory(fif, dib, FHMem, Flag) +end; + +{ TFreeTag } + +function TFreeTag.Clone: TFreeTag; +var + CloneTag: PFITAG; +begin + Result := nil; + if not IsValid then Exit; + + CloneTag := FreeImage_CloneTag(FTag); + Result := TFreeTag.Create(CloneTag); +end; + +constructor TFreeTag.Create(ATag: PFITAG); +begin + inherited Create; + + if ATag <> nil then + FTag := ATag + else + FTag := FreeImage_CreateTag; +end; + +destructor TFreeTag.Destroy; +begin + if IsValid then + FreeImage_DeleteTag(FTag); + + inherited; +end; + +function TFreeTag.GetCount: Cardinal; +begin + Result := 0; + if not IsValid then Exit; + + Result := FreeImage_GetTagCount(FTag); +end; + +function TFreeTag.GetDescription: AnsiString; +begin + Result := ''; + if not IsValid then Exit; + + Result := FreeImage_GetTagDescription(FTag); +end; + +function TFreeTag.GetID: Word; +begin + Result := 0; + if not IsValid then Exit; + + Result := FreeImage_GetTagID(FTag); +end; + +function TFreeTag.GetKey: AnsiString; +begin + Result := ''; + if not IsValid then Exit; + + Result := FreeImage_GetTagKey(FTag); +end; + +function TFreeTag.GetLength: Cardinal; +begin + Result := 0; + if not IsValid then Exit; + + Result := FreeImage_GetTagLength(FTag); +end; + +function TFreeTag.GetTagType: FREE_IMAGE_MDTYPE; +begin + Result := FIDT_NOTYPE; + if not IsValid then Exit; + + Result := FreeImage_GetTagType(FTag); +end; + +function TFreeTag.GetValue: Pointer; +begin + Result := nil; + if not IsValid then Exit; + + Result := FreeImage_GetTagValue(FTag); +end; + +function TFreeTag.IsValid: Boolean; +begin + Result := FTag <> nil; +end; + +procedure TFreeTag.SetCount(const Value: Cardinal); +begin + if IsValid then + FreeImage_SetTagCount(FTag, Value); +end; + +procedure TFreeTag.SetDescription(const Value: AnsiString); +begin + if IsValid then + FreeImage_SetTagDescription(FTag, PAnsiChar(Value)); +end; + +procedure TFreeTag.SetID(const Value: Word); +begin + if IsValid then + FreeImage_SetTagID(FTag, Value); +end; + +procedure TFreeTag.SetKey(const Value: AnsiString); +begin + if IsValid then + FreeImage_SetTagKey(FTag, PAnsiChar(Value)); +end; + +procedure TFreeTag.SetLength(const Value: Cardinal); +begin + if IsValid then + FreeImage_SetTagLength(FTag, Value); +end; + +procedure TFreeTag.SetTagType(const Value: FREE_IMAGE_MDTYPE); +begin + if IsValid then + FreeImage_SetTagType(FTag, Value); +end; + +procedure TFreeTag.SetValue(const Value: Pointer); +begin + if IsValid then + FreeImage_SetTagValue(FTag, Value); +end; + +function TFreeTag.ToString(Model: FREE_IMAGE_MDMODEL; Make: PAnsiChar): AnsiString; +begin + Result := FreeImage_TagToString(Model, FTag, Make); +end; + +end. diff --git a/Wrapper/Delphi/src/FreeImage.pas b/Wrapper/Delphi/src/FreeImage.pas index 0a844ea..d19952e 100644 --- a/Wrapper/Delphi/src/FreeImage.pas +++ b/Wrapper/Delphi/src/FreeImage.pas @@ -1,1461 +1,1461 @@ -unit FreeImage; - -// ========================================================== -// Delphi wrapper for FreeImage 3 -// -// Design and implementation by -// - Simon Beavis -// - Peter Byström -// - Anatoliy Pulyaevskiy (xvel84@rambler.ru) -// -// Contributors: -// - Lorenzo Monti (LM) lomo74@gmail.com -// -// Revision history -// When Who What -// ----------- ----- ----------------------------------------------------------- -// 2010-07-14 LM Fixed some C->Delphi translation errors, -// updated to 3.13.1, made RAD2010 compliant (unicode) -// 2010-07-29 LM Added Free Pascal / Lazarus 32 bit support -// 2010-11-12 LM Updated to 3.14.1 -// 2011-02-15 LM Updated to 3.15.0 -// 2011-03-04 JMB Modifications to compile on Free Pascal / Lazarus 64 bits (tested on Windows 7 and linux OpenSuse) : -// - in 64 bits, the names of the exported function are different : -// e.g. : _FreeImage_AcquireMemory@12 in 32 bits and FreeImage_AcquireMemory in 64 bits -// so the define WIN32 will allow to distinguish 32 and 64 bits in the calls to the freeimage library -// - in 64 bits, the Boolean type is not correctly converted to freeimage BOOL type (integer 32 bits) -// ==> replace Boolean with LongBool in the calls to the freeimage library -// - as linux sees the difference between uppercase and lowercase : -// ==> replace FreeImage_GetMetaData with FreeImage_GetMetadata in the call to the freeimage library -// 2012-06-04 LM Updated to 3.15.3 -// - -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -interface - -{$MINENUMSIZE 4} // Make sure enums are stored as an integer to be compatible with C/C++ - -{$I 'Version.inc'} - -{$IFDEF MSWINDOWS} -uses Windows; -{$ELSE} -type - LONG = LongInt; - DWORD = Cardinal; - - BITMAPINFOHEADER = record - biSize : DWORD; - biWidth : LONG; - biHeight : LONG; - biPlanes : WORD; - biBitCount : WORD; - biCompression : DWORD; - biSizeImage : DWORD; - biXPelsPerMeter : LONG; - biYPelsPerMeter : LONG; - biClrUsed : DWORD; - biClrImportant : DWORD; - end; - LPBITMAPINFOHEADER = ^BITMAPINFOHEADER; - TBITMAPINFOHEADER = BITMAPINFOHEADER; - PBITMAPINFOHEADER = ^BITMAPINFOHEADER; - - RGBQUAD = record - rgbBlue : BYTE; - rgbGreen : BYTE; - rgbRed : BYTE; - rgbReserved : BYTE; - end; - tagRGBQUAD = RGBQUAD; - TRGBQUAD = RGBQUAD; - PRGBQUAD = ^RGBQUAD; - - BITMAPINFO = record - bmiHeader : BITMAPINFOHEADER; - bmiColors : array[0..0] of RGBQUAD; - end; - LPBITMAPINFO = ^BITMAPINFO; - PBITMAPINFO = ^BITMAPINFO; - TBITMAPINFO = BITMAPINFO; -// modif JMB NOVAXEL - HBITMAP = type LongWord; - HWND = type LongWord; - HDC = type LongWord; -// end of modif JMB NOVAXEL -{$ENDIF} - -const - FIDLL = {$IFDEF MSWINDOWS}'FreeImage.dll';{$ENDIF} - {$IFDEF LINUX}'libfreeimage.so';{$ENDIF} - -const - // Version information - FREEIMAGE_MAJOR_VERSION = 3; - FREEIMAGE_MINOR_VERSION = 15; - FREEIMAGE_RELEASE_SERIAL = 3; - // This really only affects 24 and 32 bit formats, the rest are always RGB order. - FREEIMAGE_COLORORDER_BGR = 0; - FREEIMAGE_COLORORDER_RGB = 1; - FREEIMAGE_COLORORDER = FREEIMAGE_COLORORDER_BGR; - -// -------------------------------------------------------------------------- -// Bitmap types ------------------------------------------------------------- -// -------------------------------------------------------------------------- - -type - FIBITMAP = record - data: Pointer; - end; - PFIBITMAP = ^FIBITMAP; - - FIMULTIBITMAP = record - data: Pointer; - end; - PFIMULTIBITMAP = ^FIMULTIBITMAP; - -// -------------------------------------------------------------------------- -// Types used in the library (specific to FreeImage) ------------------------ -// -------------------------------------------------------------------------- - -type - {* 48-bit RGB } - tagFIRGB16 = packed record - red: WORD; - green: WORD; - blue: WORD; - end; - FIRGB16 = tagFIRGB16; - - {* 64-bit RGBA } - tagFIRGBA16 = packed record - red: WORD; - green: WORD; - blue: WORD; - alpha: WORD; - end; - FIRGBA16 = tagFIRGBA16; - - {* 96-bit RGB Float } - tagFIRGBF = packed record - red: Single; - green: Single; - blue: Single; - end; - FIRGBF = tagFIRGBF; - - {* 128-bit RGBA Float } - tagFIRGBAF = packed record - red: Single; - green: Single; - blue: Single; - alpha: Single; - end; - FIRGBAF = tagFIRGBAF; - - {* Data structure for COMPLEX type (complex number) } - tagFICOMPLEX = packed record - /// real part - r: Double; - /// imaginary part - i: Double; - end; - FICOMPLEX = tagFICOMPLEX; - -// -------------------------------------------------------------------------- -// Indexes for byte arrays, masks and shifts for treating pixels as words --- -// These coincide with the order of RGBQUAD and RGBTRIPLE ------------------- -// Little Endian (x86 / MS Windows, Linux) : BGR(A) order ------------------- -// -------------------------------------------------------------------------- - -const - FI_RGBA_RED = 2; - FI_RGBA_GREEN = 1; - FI_RGBA_BLUE = 0; - FI_RGBA_ALPHA = 3; - FI_RGBA_RED_MASK = $00FF0000; - FI_RGBA_GREEN_MASK = $0000FF00; - FI_RGBA_BLUE_MASK = $000000FF; - FI_RGBA_ALPHA_MASK = $FF000000; - FI_RGBA_RED_SHIFT = 16; - FI_RGBA_GREEN_SHIFT = 8; - FI_RGBA_BLUE_SHIFT = 0; - FI_RGBA_ALPHA_SHIFT = 24; - - FI_RGBA_RGB_MASK = FI_RGBA_RED_MASK or FI_RGBA_GREEN_MASK or FI_RGBA_BLUE_MASK; - -// -------------------------------------------------------------------------- -// The 16bit macros only include masks and shifts, -------------------------- -// since each color element is not byte aligned ----------------------------- -// -------------------------------------------------------------------------- - -const - FI16_555_RED_MASK = $7C00; - FI16_555_GREEN_MASK = $03E0; - FI16_555_BLUE_MASK = $001F; - FI16_555_RED_SHIFT = 10; - FI16_555_GREEN_SHIFT = 5; - FI16_555_BLUE_SHIFT = 0; - FI16_565_RED_MASK = $F800; - FI16_565_GREEN_MASK = $07E0; - FI16_565_BLUE_MASK = $001F; - FI16_565_RED_SHIFT = 11; - FI16_565_GREEN_SHIFT = 5; - FI16_565_BLUE_SHIFT = 0; - -// -------------------------------------------------------------------------- -// ICC profile support ------------------------------------------------------ -// -------------------------------------------------------------------------- - -const - FIICC_DEFAULT = $0; - FIICC_COLOR_IS_CMYK = $1; - -type - FIICCPROFILE = record - flags: WORD; // info flag - size: DWORD; // profile's size measured in bytes - data: Pointer; // points to a block of contiguous memory containing the profile - end; - PFIICCPROFILE = ^FIICCPROFILE; - -// -------------------------------------------------------------------------- -// Important enums ---------------------------------------------------------- -// -------------------------------------------------------------------------- - -type - FREE_IMAGE_FORMAT = type Integer; - FREE_IMAGE_TYPE = type Integer; - FREE_IMAGE_COLOR_TYPE = type Integer; - FREE_IMAGE_QUANTIZE = type Integer; - FREE_IMAGE_DITHER = type Integer; - FREE_IMAGE_FILTER = type Integer; - FREE_IMAGE_COLOR_CHANNEL = type Integer; - FREE_IMAGE_MDTYPE = type Integer; - FREE_IMAGE_MDMODEL = type Integer; - FREE_IMAGE_JPEG_OPERATION = type Integer; - FREE_IMAGE_TMO = type Integer; - -const - // I/O image format identifiers. - FIF_UNKNOWN = FREE_IMAGE_FORMAT(-1); - FIF_BMP = FREE_IMAGE_FORMAT(0); - FIF_ICO = FREE_IMAGE_FORMAT(1); - FIF_JPEG = FREE_IMAGE_FORMAT(2); - FIF_JNG = FREE_IMAGE_FORMAT(3); - FIF_KOALA = FREE_IMAGE_FORMAT(4); - FIF_LBM = FREE_IMAGE_FORMAT(5); - FIF_IFF = FIF_LBM; - FIF_MNG = FREE_IMAGE_FORMAT(6); - FIF_PBM = FREE_IMAGE_FORMAT(7); - FIF_PBMRAW = FREE_IMAGE_FORMAT(8); - FIF_PCD = FREE_IMAGE_FORMAT(9); - FIF_PCX = FREE_IMAGE_FORMAT(10); - FIF_PGM = FREE_IMAGE_FORMAT(11); - FIF_PGMRAW = FREE_IMAGE_FORMAT(12); - FIF_PNG = FREE_IMAGE_FORMAT(13); - FIF_PPM = FREE_IMAGE_FORMAT(14); - FIF_PPMRAW = FREE_IMAGE_FORMAT(15); - FIF_RAS = FREE_IMAGE_FORMAT(16); - FIF_TARGA = FREE_IMAGE_FORMAT(17); - FIF_TIFF = FREE_IMAGE_FORMAT(18); - FIF_WBMP = FREE_IMAGE_FORMAT(19); - FIF_PSD = FREE_IMAGE_FORMAT(20); - FIF_CUT = FREE_IMAGE_FORMAT(21); - FIF_XBM = FREE_IMAGE_FORMAT(22); - FIF_XPM = FREE_IMAGE_FORMAT(23); - FIF_DDS = FREE_IMAGE_FORMAT(24); - FIF_GIF = FREE_IMAGE_FORMAT(25); - FIF_HDR = FREE_IMAGE_FORMAT(26); - FIF_FAXG3 = FREE_IMAGE_FORMAT(27); - FIF_SGI = FREE_IMAGE_FORMAT(28); - FIF_EXR = FREE_IMAGE_FORMAT(29); - FIF_J2K = FREE_IMAGE_FORMAT(30); - FIF_JP2 = FREE_IMAGE_FORMAT(31); - FIF_PFM = FREE_IMAGE_FORMAT(32); - FIF_PICT = FREE_IMAGE_FORMAT(33); - FIF_RAW = FREE_IMAGE_FORMAT(34); - - // Image type used in FreeImage. - FIT_UNKNOWN = FREE_IMAGE_TYPE(0); // unknown type - FIT_BITMAP = FREE_IMAGE_TYPE(1); // standard image: 1-, 4-, 8-, 16-, 24-, 32-bit - FIT_UINT16 = FREE_IMAGE_TYPE(2); // array of unsigned short: unsigned 16-bit - FIT_INT16 = FREE_IMAGE_TYPE(3); // array of short: signed 16-bit - FIT_UINT32 = FREE_IMAGE_TYPE(4); // array of unsigned long: unsigned 32-bit - FIT_INT32 = FREE_IMAGE_TYPE(5); // array of long: signed 32-bit - FIT_FLOAT = FREE_IMAGE_TYPE(6); // array of float: 32-bit IEEE floating point - FIT_DOUBLE = FREE_IMAGE_TYPE(7); // array of double: 64-bit IEEE floating point - FIT_COMPLEX = FREE_IMAGE_TYPE(8); // array of FICOMPLEX: 2 x 64-bit IEEE floating point - FIT_RGB16 = FREE_IMAGE_TYPE(9); // 48-bit RGB image: 3 x 16-bit - FIT_RGBA16 = FREE_IMAGE_TYPE(10); // 64-bit RGBA image: 4 x 16-bit - FIT_RGBF = FREE_IMAGE_TYPE(11); // 96-bit RGB float image: 3 x 32-bit IEEE floating point - FIT_RGBAF = FREE_IMAGE_TYPE(12); // 128-bit RGBA float image: 4 x 32-bit IEEE floating point - - // Image color type used in FreeImage. - FIC_MINISWHITE = FREE_IMAGE_COLOR_TYPE(0); // min value is white - FIC_MINISBLACK = FREE_IMAGE_COLOR_TYPE(1); // min value is black - FIC_RGB = FREE_IMAGE_COLOR_TYPE(2); // RGB color model - FIC_PALETTE = FREE_IMAGE_COLOR_TYPE(3); // color map indexed - FIC_RGBALPHA = FREE_IMAGE_COLOR_TYPE(4); // RGB color model with alpha channel - FIC_CMYK = FREE_IMAGE_COLOR_TYPE(5); // CMYK color model - - // Color quantization algorithms. Constants used in FreeImage_ColorQuantize. - FIQ_WUQUANT = FREE_IMAGE_QUANTIZE(0); // Xiaolin Wu color quantization algorithm - FIQ_NNQUANT = FREE_IMAGE_QUANTIZE(1); // NeuQuant neural-net quantization algorithm by Anthony Dekker - - // Dithering algorithms. Constants used FreeImage_Dither. - FID_FS = FREE_IMAGE_DITHER(0); // Floyd & Steinberg error diffusion - FID_BAYER4x4 = FREE_IMAGE_DITHER(1); // Bayer ordered dispersed dot dithering (order 2 dithering matrix) - FID_BAYER8x8 = FREE_IMAGE_DITHER(2); // Bayer ordered dispersed dot dithering (order 3 dithering matrix) - FID_CLUSTER6x6 = FREE_IMAGE_DITHER(3); // Ordered clustered dot dithering (order 3 - 6x6 matrix) - FID_CLUSTER8x8 = FREE_IMAGE_DITHER(4); // Ordered clustered dot dithering (order 4 - 8x8 matrix) - FID_CLUSTER16x16 = FREE_IMAGE_DITHER(5); // Ordered clustered dot dithering (order 8 - 16x16 matrix) - FID_BAYER16x16 = FREE_IMAGE_DITHER(6); // Bayer ordered dispersed dot dithering (order 4 dithering matrix) - - // Lossless JPEG transformations Constants used in FreeImage_JPEGTransform - FIJPEG_OP_NONE = FREE_IMAGE_JPEG_OPERATION(0); // no transformation - FIJPEG_OP_FLIP_H = FREE_IMAGE_JPEG_OPERATION(1); // horizontal flip - FIJPEG_OP_FLIP_V = FREE_IMAGE_JPEG_OPERATION(2); // vertical flip - FIJPEG_OP_TRANSPOSE = FREE_IMAGE_JPEG_OPERATION(3); // transpose across UL-to-LR axis - FIJPEG_OP_TRANSVERSE = FREE_IMAGE_JPEG_OPERATION(4); // transpose across UR-to-LL axis - FIJPEG_OP_ROTATE_90 = FREE_IMAGE_JPEG_OPERATION(5); // 90-degree clockwise rotation - FIJPEG_OP_ROTATE_180 = FREE_IMAGE_JPEG_OPERATION(6); // 180-degree rotation - FIJPEG_OP_ROTATE_270 = FREE_IMAGE_JPEG_OPERATION(7); // 270-degree clockwise (or 90 ccw) - - // Tone mapping operators. Constants used in FreeImage_ToneMapping. - FITMO_DRAGO03 = FREE_IMAGE_TMO(0); // Adaptive logarithmic mapping (F. Drago, 2003) - FITMO_REINHARD05 = FREE_IMAGE_TMO(1); // Dynamic range reduction inspired by photoreceptor physiology (E. Reinhard, 2005) - FITMO_FATTAL02 = FREE_IMAGE_TMO(2); // Gradient domain high dynamic range compression (R. Fattal, 2002) - - // Upsampling / downsampling filters. Constants used in FreeImage_Rescale. - FILTER_BOX = FREE_IMAGE_FILTER(0); // Box, pulse, Fourier window, 1st order (constant) b-spline - FILTER_BICUBIC = FREE_IMAGE_FILTER(1); // Mitchell & Netravali's two-param cubic filter - FILTER_BILINEAR = FREE_IMAGE_FILTER(2); // Bilinear filter - FILTER_BSPLINE = FREE_IMAGE_FILTER(3); // 4th order (cubic) b-spline - FILTER_CATMULLROM = FREE_IMAGE_FILTER(4); // Catmull-Rom spline, Overhauser spline - FILTER_LANCZOS3 = FREE_IMAGE_FILTER(5); // Lanczos3 filter - - // Color channels. Constants used in color manipulation routines. - FICC_RGB = FREE_IMAGE_COLOR_CHANNEL(0); // Use red, green and blue channels - FICC_RED = FREE_IMAGE_COLOR_CHANNEL(1); // Use red channel - FICC_GREEN = FREE_IMAGE_COLOR_CHANNEL(2); // Use green channel - FICC_BLUE = FREE_IMAGE_COLOR_CHANNEL(3); // Use blue channel - FICC_ALPHA = FREE_IMAGE_COLOR_CHANNEL(4); // Use alpha channel - FICC_BLACK = FREE_IMAGE_COLOR_CHANNEL(5); // Use black channel - FICC_REAL = FREE_IMAGE_COLOR_CHANNEL(6); // Complex images: use real part - FICC_IMAG = FREE_IMAGE_COLOR_CHANNEL(7); // Complex images: use imaginary part - FICC_MAG = FREE_IMAGE_COLOR_CHANNEL(8); // Complex images: use magnitude - FICC_PHASE = FREE_IMAGE_COLOR_CHANNEL(9); // Complex images: use phase - - // Tag data type information (based on TIFF specifications) - FIDT_NOTYPE = FREE_IMAGE_MDTYPE(0); // placeholder - FIDT_BYTE = FREE_IMAGE_MDTYPE(1); // 8-bit unsigned integer - FIDT_ASCII = FREE_IMAGE_MDTYPE(2); // 8-bit bytes w/ last byte null - FIDT_SHORT = FREE_IMAGE_MDTYPE(3); // 16-bit unsigned integer - FIDT_LONG = FREE_IMAGE_MDTYPE(4); // 32-bit unsigned integer - FIDT_RATIONAL = FREE_IMAGE_MDTYPE(5); // 64-bit unsigned fraction - FIDT_SBYTE = FREE_IMAGE_MDTYPE(6); // 8-bit signed integer - FIDT_UNDEFINED = FREE_IMAGE_MDTYPE(7); // 8-bit untyped data - FIDT_SSHORT = FREE_IMAGE_MDTYPE(8); // 16-bit signed integer - FIDT_SLONG = FREE_IMAGE_MDTYPE(9); // 32-bit signed integer - FIDT_SRATIONAL = FREE_IMAGE_MDTYPE(10); // 64-bit signed fraction - FIDT_FLOAT = FREE_IMAGE_MDTYPE(11); // 32-bit IEEE floating point - FIDT_DOUBLE = FREE_IMAGE_MDTYPE(12); // 64-bit IEEE floating point - FIDT_IFD = FREE_IMAGE_MDTYPE(13); // 32-bit unsigned integer (offset) - FIDT_PALETTE = FREE_IMAGE_MDTYPE(14); // 32-bit RGBQUAD - FIDT_LONG8 = FREE_IMAGE_MDTYPE(16); // 64-bit unsigned integer - FIDT_SLONG8 = FREE_IMAGE_MDTYPE(17); // 64-bit signed integer - FIDT_IFD8 = FREE_IMAGE_MDTYPE(18); // 64-bit unsigned integer (offset) - - // Metadata models supported by FreeImage - FIMD_NODATA = FREE_IMAGE_MDMODEL(-1); - FIMD_COMMENTS = FREE_IMAGE_MDMODEL(0); // single comment or keywords - FIMD_EXIF_MAIN = FREE_IMAGE_MDMODEL(1); // Exif-TIFF metadata - FIMD_EXIF_EXIF = FREE_IMAGE_MDMODEL(2); // Exif-specific metadata - FIMD_EXIF_GPS = FREE_IMAGE_MDMODEL(3); // Exif GPS metadata - FIMD_EXIF_MAKERNOTE = FREE_IMAGE_MDMODEL(4); // Exif maker note metadata - FIMD_EXIF_INTEROP = FREE_IMAGE_MDMODEL(5); // Exif interoperability metadata - FIMD_IPTC = FREE_IMAGE_MDMODEL(6); // IPTC/NAA metadata - FIMD_XMP = FREE_IMAGE_MDMODEL(7); // Abobe XMP metadata - FIMD_GEOTIFF = FREE_IMAGE_MDMODEL(8); // GeoTIFF metadata (to be implemented) - FIMD_ANIMATION = FREE_IMAGE_MDMODEL(9); // Animation metadata - FIMD_CUSTOM = FREE_IMAGE_MDMODEL(10); // Used to attach other metadata types to a dib - FIMD_EXIF_RAW = FREE_IMAGE_MDMODEL(11); // Exif metadata as a raw buffer - -type - // Handle to a metadata model - FIMETADATA = record - data: Pointer; - end; - PFIMETADATA = ^FIMETADATA; - - // Handle to a metadata tag - FITAG = record - data: Pointer; - end; - PFITAG = ^FITAG; - -// -------------------------------------------------------------------------- -// File IO routines --------------------------------------------------------- -// -------------------------------------------------------------------------- - -type - fi_handle = Pointer; - - FI_ReadProc = function(buffer: Pointer; size, count: Cardinal; - handle: fi_handle): Cardinal; stdcall; - FI_WriteProc = function(buffer: Pointer; size, count: Cardinal; - handle: fi_handle): Cardinal; stdcall; - FI_SeekProc = function(handle: fi_handle; offset: LongInt; - origin: Integer): Integer; stdcall; - FI_TellProc = function(handle: fi_handle): LongInt; stdcall; - - FreeImageIO = packed record - read_proc : FI_ReadProc; // pointer to the function used to read data - write_proc: FI_WriteProc; // pointer to the function used to write data - seek_proc : FI_SeekProc; // pointer to the function used to seek - tell_proc : FI_TellProc; // pointer to the function used to aquire the current position - end; - PFreeImageIO = ^FreeImageIO; - - // Handle to a memory I/O stream - FIMEMORY = record - data: Pointer; - end; - PFIMEMORY = ^FIMEMORY; - -const - // constants used in FreeImage_Seek for Origin parameter - SEEK_SET = 0; - SEEK_CUR = 1; - SEEK_END = 2; - -type - // define portable types for 32-bit / 64-bit OS - FIINT64 = Int64; - FIUINT64 = UInt64; - -// -------------------------------------------------------------------------- -// Plugin routines ---------------------------------------------------------- -// -------------------------------------------------------------------------- - -type - PPlugin = ^Plugin; - - FI_FormatProc = function: PAnsiChar; stdcall; - FI_DescriptionProc = function: PAnsiChar; stdcall; - FI_ExtensionListProc = function: PAnsiChar; stdcall; - FI_RegExprProc = function: PAnsiChar; stdcall; - FI_OpenProc = function(io: PFreeImageIO; handle: fi_handle; - read: LongBool): Pointer; stdcall; - FI_CloseProc = procedure(io: PFreeImageIO; handle: fi_handle; - data: Pointer); stdcall; - FI_PageCountProc = function(io: PFreeImageIO; handle: fi_handle; - data: Pointer): Integer; stdcall; - FI_PageCapabilityProc = function(io: PFreeImageIO; handle: fi_handle; - data: Pointer): Integer; stdcall; - FI_LoadProc = function(io: PFreeImageIO; handle: fi_handle; page, flags: Integer; - data: Pointer): PFIBITMAP; stdcall; - FI_SaveProc = function(io: PFreeImageIO; dib: PFIBITMAP; handle: fi_handle; - page, flags: Integer; data: Pointer): LongBool; stdcall; - FI_ValidateProc = function(io: PFreeImageIO; handle: fi_handle): LongBool; stdcall; - FI_MimeProc = function: PAnsiChar; stdcall; - FI_SupportsExportBPPProc = function(bpp: integer): LongBool; stdcall; - FI_SupportsExportTypeProc = function(atype: FREE_IMAGE_TYPE): LongBool; stdcall; - FI_SupportsICCProfilesProc = function: LongBool; stdcall; - FI_SupportsNoPixelsProc = function: LongBool; stdcall; - - Plugin = record - format_proc: FI_FormatProc; - description_proc: FI_DescriptionProc; - extension_proc: FI_ExtensionListProc; - regexpr_proc: FI_RegExprProc; - open_proc: FI_OpenProc; - close_proc: FI_CloseProc; - pagecount_proc: FI_PageCountProc; - pagecapability_proc: FI_PageCapabilityProc; - load_proc: FI_LoadProc; - save_proc: FI_SaveProc; - validate_proc: FI_ValidateProc; - mime_proc: FI_MimeProc; - supports_export_bpp_proc: FI_SupportsExportBPPProc; - supports_export_type_proc: FI_SupportsExportTypeProc; - supports_icc_profiles_proc: FI_SupportsICCProfilesProc; - supports_no_pixels_proc: FI_SupportsNoPixelsProc; - end; - - FI_InitProc = procedure(aplugin: PPlugin; format_id: Integer); stdcall; - -// -------------------------------------------------------------------------- -// Load/Save flag constants ------------------------------------------------- -// -------------------------------------------------------------------------- - -const - FIF_LOAD_NOPIXELS = $8000; // loading: load the image header only (not supported by all plugins) - BMP_DEFAULT = 0; - BMP_SAVE_RLE = 1; - CUT_DEFAULT = 0; - DDS_DEFAULT = 0; - EXR_DEFAULT = 0; // save data as half with piz-based wavelet compression - EXR_FLOAT = $0001; // save data as float instead of as half (not recommended) - EXR_NONE = $0002; // save with no compression - EXR_ZIP = $0004; // save with zlib compression, in blocks of 16 scan lines - EXR_PIZ = $0008; // save with piz-based wavelet compression - EXR_PXR24 = $0010; // save with lossy 24-bit float compression - EXR_B44 = $0020; // save with lossy 44% float compression - goes to 22% when combined with EXR_LC - EXR_LC = $0040; // save images with one luminance and two chroma channels, rather than as RGB (lossy compression) - FAXG3_DEFAULT = 0; - GIF_DEFAULT = 0; - GIF_LOAD256 = 1; // Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color - GIF_PLAYBACK = 2; // 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading - HDR_DEFAULT = 0; - ICO_DEFAULT = 0; - ICO_MAKEALPHA = 1; // convert to 32bpp and create an alpha channel from the AND-mask when loading - IFF_DEFAULT = 0; - J2K_DEFAULT = 0; // save with a 16:1 rate - JP2_DEFAULT = 0; // save with a 16:1 rate - JPEG_DEFAULT = 0; - JPEG_FAST = 1; - JPEG_ACCURATE = 2; - JPEG_CMYK = $0004; // load separated CMYK "as is" (use | to combine with other flags) - JPEG_EXIFROTATE = $0008; // load and rotate according to Exif 'Orientation' tag if available - JPEG_QUALITYSUPERB = $0080; // save with superb quality (100:1) - JPEG_QUALITYGOOD = $0100; // save with good quality (75:1) - JPEG_QUALITYNORMAL = $0200; // save with normal quality (50:1) - JPEG_QUALITYAVERAGE = $0400; // save with average quality (25:1) - JPEG_QUALITYBAD = $0800; // save with bad quality (10:1) - JPEG_PROGRESSIVE = $2000; // save as a progressive-JPEG (use | to combine with other save flags) - JPEG_SUBSAMPLING_411 = $1000; // save with high 4x1 chroma subsampling (4:1:1) - JPEG_SUBSAMPLING_420 = $4000; // save with medium 2x2 medium chroma subsampling (4:2:0) - default value - JPEG_SUBSAMPLING_422 = $8000; // save with low 2x1 chroma subsampling (4:2:2) - JPEG_SUBSAMPLING_444 = $10000; // save with no chroma subsampling (4:4:4) - JPEG_OPTIMIZE = $20000; // on saving, compute optimal Huffman coding tables (can reduce a few percent of file size) - JPEG_BASELINE = $40000; // save basic JPEG, without metadata or any markers - KOALA_DEFAULT = 0; - LBM_DEFAULT = 0; - MNG_DEFAULT = 0; - PCD_DEFAULT = 0; - PCD_BASE = 1; // load the bitmap sized 768 x 512 - PCD_BASEDIV4 = 2; // load the bitmap sized 384 x 256 - PCD_BASEDIV16 = 3; // load the bitmap sized 192 x 128 - PCX_DEFAULT = 0; - PFM_DEFAULT = 0; - PICT_DEFAULT = 0; - PNG_DEFAULT = 0; - PNG_IGNOREGAMMA = 1; // avoid gamma correction - PNG_Z_BEST_SPEED = $0001; // save using ZLib level 1 compression flag (default value is 6) - PNG_Z_DEFAULT_COMPRESSION = $0006; // save using ZLib level 6 compression flag (default recommended value) - PNG_Z_BEST_COMPRESSION = $0009; // save using ZLib level 9 compression flag (default value is 6) - PNG_Z_NO_COMPRESSION = $0100; // save without ZLib compression - PNG_INTERLACED = $0200; // save using Adam7 interlacing (use | to combine with other save flags) - PNM_DEFAULT = 0; - PNM_SAVE_RAW = 0; // If set the writer saves in RAW format (i.e. P4, P5 or P6) - PNM_SAVE_ASCII = 1; // If set the writer saves in ASCII format (i.e. P1, P2 or P3) - PSD_DEFAULT = 0; - PSD_CMYK = 1; // reads tags for separated CMYK (default is conversion to RGB) - PSD_LAB = 2; // reads tags for CIELab (default is conversion to RGB) - RAS_DEFAULT = 0; - RAW_DEFAULT = 0; // load the file as linear RGB 48-bit - RAW_PREVIEW = 1; // try to load the embedded JPEG preview with included Exif Data or default to RGB 24-bit - RAW_DISPLAY = 2; // load the file as RGB 24-bit - RAW_HALFSIZE = 4; // output a half-size color image - SGI_DEFAULT = 0; - TARGA_DEFAULT = 0; - TARGA_LOAD_RGB888 = 1; // If set the loader converts RGB555 and ARGB8888 -> RGB888. - TARGA_SAVE_RLE = 2; // If set, the writer saves with RLE compression - TIFF_DEFAULT = 0; - TIFF_CMYK = $0001; // reads/stores tags for separated CMYK (use | to combine with compression flags) - TIFF_PACKBITS = $0100; // save using PACKBITS compression - TIFF_DEFLATE = $0200; // save using DEFLATE compression - TIFF_ADOBE_DEFLATE = $0400; // save using ADOBE DEFLATE compression - TIFF_NONE = $0800; // save without any compression - TIFF_CCITTFAX3 = $1000; // save using CCITT Group 3 fax encoding - TIFF_CCITTFAX4 = $2000; // save using CCITT Group 4 fax encoding - TIFF_LZW = $4000; // save using LZW compression - TIFF_JPEG = $8000; // save using JPEG compression - TIFF_LOGLUV = $10000; // save using LogLuv compression - WBMP_DEFAULT = 0; - XBM_DEFAULT = 0; - XPM_DEFAULT = 0; - -// -------------------------------------------------------------------------- -// Background filling options ----------------------------------------------- -// Constants used in FreeImage_FillBackground and FreeImage_EnlargeCanvas -// -------------------------------------------------------------------------- - -const - FI_COLOR_IS_RGB_COLOR = $00; // RGBQUAD color is a RGB color (contains no valid alpha channel) - FI_COLOR_IS_RGBA_COLOR = $01; // RGBQUAD color is a RGBA color (contains a valid alpha channel) - FI_COLOR_FIND_EQUAL_COLOR = $02; // For palettized images: lookup equal RGB color from palette - FI_COLOR_ALPHA_IS_INDEX = $04; // The color's rgbReserved member (alpha) contains the palette index to be used - FI_COLOR_PALETTE_SEARCH_MASK = FI_COLOR_FIND_EQUAL_COLOR or FI_COLOR_ALPHA_IS_INDEX; // No color lookup is performed - -// -------------------------------------------------------------------------- -// Init/Error routines ------------------------------------------------------ -// -------------------------------------------------------------------------- - -procedure FreeImage_Initialise(load_local_plugins_only: LongBool = False); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_Initialise@4'{$ENDIF}; -procedure FreeImage_DeInitialise; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_DeInitialise@0'{$ENDIF}; - -// -------------------------------------------------------------------------- -// Version routines --------------------------------------------------------- -// -------------------------------------------------------------------------- - -function FreeImage_GetVersion: PAnsiChar; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetVersion@0'{$ENDIF}; -function FreeImage_GetCopyrightMessage: PAnsiChar; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetCopyrightMessage@0'{$ENDIF}; - -// -------------------------------------------------------------------------- -// Message output functions ------------------------------------------------- -// -------------------------------------------------------------------------- - -type - FreeImage_OutputMessageFunction = procedure(fif: FREE_IMAGE_FORMAT; - msg: PAnsiChar); cdecl; - FreeImage_OutputMessageFunctionStdCall = procedure(fif: FREE_IMAGE_FORMAT; - msg: PAnsiChar); stdcall; - -procedure FreeImage_SetOutputMessageStdCall(omf: FreeImage_OutputMessageFunctionStdCall); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetOutputMessageStdCall@4'{$ENDIF}; -procedure FreeImage_SetOutputMessage(omf: FreeImage_OutputMessageFunction); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetOutputMessage@4'{$ENDIF}; -{$IFDEF DELPHI6} -//this is declared stdcall in the C header but it is actually cdecl. -//with varargs functions, clearing the stack is caller's responsibility -//(since the callee doesn't know how many parameters were passed). -//cdecl is the right convention here, not stdcall -procedure FreeImage_OutputMessageProc(fif: Integer; fmt: PAnsiChar); cdecl; varargs; - external FIDLL {$IFDEF WIN32}name 'FreeImage_OutputMessageProc'{$ENDIF}; -{$ELSE} -//older Delphi versions (<6) do not support varargs. -//we provide a wrapper that uses open arrays instead -procedure FreeImage_OutputMessageProc(fif: Integer; fmt: PAnsiChar; args: array of const); -{$ENDIF} - -// -------------------------------------------------------------------------- -// Allocate / Clone / Unload routines --------------------------------------- -// -------------------------------------------------------------------------- - -function FreeImage_Allocate(width, height, bpp: Integer; red_mask: Cardinal = 0; - green_mask: Cardinal = 0; blue_mask: Cardinal = 0): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_Allocate@24'{$ENDIF}; -function FreeImage_AllocateT(atype: FREE_IMAGE_TYPE; width, height: Integer; - bpp: Integer = 8; red_mask: Cardinal = 0; green_mask: Cardinal = 0; - blue_mask: Cardinal = 0): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_AllocateT@28'{$ENDIF}; -function FreeImage_Clone(dib: PFIBITMAP): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_Clone@4'{$ENDIF}; -procedure FreeImage_Unload(dib: PFIBITMAP); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_Unload@4'{$ENDIF}; - -// -------------------------------------------------------------------------- -// Header loading routines -// -------------------------------------------------------------------------- -function FreeImage_HasPixels(dib: PFIBITMAP): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_HasPixels@4'{$ENDIF}; - -// -------------------------------------------------------------------------- -// Load / Save routines ----------------------------------------------------- -// -------------------------------------------------------------------------- - -function FreeImage_Load(fif: FREE_IMAGE_FORMAT; filename: PAnsiChar; - flags: Integer = 0): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_Load@12'{$ENDIF}; -function FreeImage_LoadU(fif: FREE_IMAGE_FORMAT; filename: PWideChar; - flags: Integer = 0): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_LoadU@12'{$ENDIF}; -function FreeImage_LoadFromHandle(fif: FREE_IMAGE_FORMAT; io: PFreeImageIO; - handle: fi_handle; flags: Integer = 0): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_LoadFromHandle@16'{$ENDIF}; -function FreeImage_Save(fif: FREE_IMAGE_FORMAT; dib: PFIBITMAP; filename: PAnsiChar; - flags: Integer = 0): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_Save@16'{$ENDIF}; -function FreeImage_SaveU(fif: FREE_IMAGE_FORMAT; dib: PFIBITMAP; filename: PWideChar; - flags: Integer = 0): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SaveU@16'{$ENDIF}; -function FreeImage_SaveToHandle(fif: FREE_IMAGE_FORMAT; dib: PFIBITMAP; - io: PFreeImageIO; handle: fi_handle; flags: Integer = 0): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SaveToHandle@20'{$ENDIF}; - -// -------------------------------------------------------------------------- -// Memory I/O stream routines ----------------------------------------------- -// -------------------------------------------------------------------------- - -function FreeImage_OpenMemory(data: PByte = nil; size_in_bytes: DWORD = 0): PFIMEMORY; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_OpenMemory@8'{$ENDIF}; -procedure FreeImage_CloseMemory(stream: PFIMEMORY); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_CloseMemory@4'{$ENDIF}; -function FreeImage_LoadFromMemory(fif: FREE_IMAGE_FORMAT; stream: PFIMEMORY; - flags: Integer = 0): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_LoadFromMemory@12'{$ENDIF}; -function FreeImage_SaveToMemory(fif: FREE_IMAGE_FORMAT; dib: PFIBITMAP; - stream: PFIMEMORY; flags: Integer = 0): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SaveToMemory@16'{$ENDIF}; -function FreeImage_TellMemory(stream: PFIMEMORY): LongInt; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_TellMemory@4'{$ENDIF}; -function FreeImage_SeekMemory(stream: PFIMEMORY; offset: LongInt; - origin: Integer): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SeekMemory@12'{$ENDIF}; -function FreeImage_AcquireMemory(stream: PFIMEMORY; var data: PByte; - var size_in_bytes: DWORD): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_AcquireMemory@12'{$ENDIF}; -function FreeImage_ReadMemory(buffer: Pointer; size, count: Cardinal; - stream: PFIMEMORY): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ReadMemory@16'{$ENDIF}; -function FreeImage_WriteMemory(buffer: Pointer; size, count: Cardinal; - stream: PFIMEMORY): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_WriteMemory@16'{$ENDIF}; -function FreeImage_LoadMultiBitmapFromMemory(fif: FREE_IMAGE_FORMAT; stream: PFIMEMORY; - flags: Integer = 0): PFIMULTIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_LoadMultiBitmapFromMemory@12'{$ENDIF}; -function FreeImage_SaveMultiBitmapToMemory(fif: FREE_IMAGE_FORMAT; bitmap: PFIMULTIBITMAP; - stream: PFIMEMORY; flags: Integer): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SaveMultiBitmapToMemory@16'{$ENDIF}; - -// -------------------------------------------------------------------------- -// Plugin Interface --------------------------------------------------------- -// -------------------------------------------------------------------------- - -function FreeImage_RegisterLocalPlugin(proc_address: FI_InitProc; format: PAnsiChar = nil; - description: PAnsiChar = nil; extension: PAnsiChar = nil; - regexpr: PAnsiChar = nil): FREE_IMAGE_FORMAT; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_RegisterLocalPlugin@20'{$ENDIF}; -function FreeImage_RegisterExternalPlugin(path: PAnsiChar; format: PAnsiChar = nil; - description: PAnsiChar = nil; extension: PAnsiChar = nil; - regexpr: PAnsiChar = nil): FREE_IMAGE_FORMAT; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_RegisterExternalPlugin@20'{$ENDIF}; -function FreeImage_GetFIFCount: Integer; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFCount@0'{$ENDIF}; -procedure FreeImage_SetPluginEnabled(fif: FREE_IMAGE_FORMAT; enable: LongBool); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetPluginEnabled@8'{$ENDIF}; -function FreeImage_IsPluginEnabled(fif: FREE_IMAGE_FORMAT): Integer; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_IsPluginEnabled@4'{$ENDIF}; -function FreeImage_GetFIFFromFormat(format: PAnsiChar): FREE_IMAGE_FORMAT; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFFromFormat@4'{$ENDIF}; -function FreeImage_GetFIFFromMime(mime: PAnsiChar): FREE_IMAGE_FORMAT; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFFromMime@4'{$ENDIF}; -function FreeImage_GetFormatFromFIF(fif: FREE_IMAGE_FORMAT): PAnsiChar; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFormatFromFIF@4'{$ENDIF}; -function FreeImage_GetFIFExtensionList(fif: FREE_IMAGE_FORMAT): PAnsiChar; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFExtensionList@4'{$ENDIF}; -function FreeImage_GetFIFDescription(fif: FREE_IMAGE_FORMAT): PAnsiChar; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFDescription@4'{$ENDIF}; -function FreeImage_GetFIFRegExpr(fif: FREE_IMAGE_FORMAT): PAnsiChar; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFRegExpr@4'{$ENDIF}; -function FreeImage_GetFIFMimeType(fif: FREE_IMAGE_FORMAT): PAnsiChar; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFMimeType@4'{$ENDIF}; -function FreeImage_GetFIFFromFilename(filename: PAnsiChar): FREE_IMAGE_FORMAT; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFFromFilename@4'{$ENDIF}; -function FreeImage_GetFIFFromFilenameU(filename: PWideChar): FREE_IMAGE_FORMAT; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFFromFilenameU@4'{$ENDIF}; -function FreeImage_FIFSupportsReading(fif: FREE_IMAGE_FORMAT): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_FIFSupportsReading@4'{$ENDIF}; -function FreeImage_FIFSupportsWriting(fif: FREE_IMAGE_FORMAT): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_FIFSupportsWriting@4'{$ENDIF}; -function FreeImage_FIFSupportsExportBPP(fif: FREE_IMAGE_FORMAT; - bpp: Integer): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_FIFSupportsExportBPP@8'{$ENDIF}; -function FreeImage_FIFSupportsExportType(fif: FREE_IMAGE_FORMAT; - atype: FREE_IMAGE_TYPE): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_FIFSupportsExportType@8'{$ENDIF}; -function FreeImage_FIFSupportsICCProfiles(fif: FREE_IMAGE_FORMAT): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_FIFSupportsICCProfiles@4'{$ENDIF}; -function FreeImage_FIFSupportsNoPixels(fif: FREE_IMAGE_FORMAT): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_FIFSupportsNoPixels@4'{$ENDIF}; - -// -------------------------------------------------------------------------- -// Multipaging interface ---------------------------------------------------- -// -------------------------------------------------------------------------- - -function FreeImage_OpenMultiBitmap(fif: FREE_IMAGE_FORMAT; filename: PAnsiChar; - create_new, read_only: LongBool; keep_cache_in_memory: LongBool = False; - flags: Integer = 0): PFIMULTIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_OpenMultiBitmap@24'{$ENDIF}; -function FreeImage_OpenMultiBitmapFromHandle(fif: FREE_IMAGE_FORMAT; io: PFreeImageIO; - handle: fi_handle; flags: Integer = 0): PFIMULTIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_OpenMultiBitmapFromHandle@16'{$ENDIF}; -function FreeImage_SaveMultiBitmapToHandle(fif: FREE_IMAGE_FORMAT; bitmap: PFIMULTIBITMAP; - io: PFreeImageIO; handle: fi_handle; flags: Integer = 0): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SaveMultiBitmapToHandle@20'{$ENDIF}; -function FreeImage_CloseMultiBitmap(bitmap: PFIMULTIBITMAP; - flags: Integer = 0): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_CloseMultiBitmap@8'{$ENDIF}; -function FreeImage_GetPageCount(bitmap: PFIMULTIBITMAP): Integer; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetPageCount@4'{$ENDIF}; -procedure FreeImage_AppendPage(bitmap: PFIMULTIBITMAP; data: PFIBITMAP); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_AppendPage@8'{$ENDIF}; -procedure FreeImage_InsertPage(bitmap: PFIMULTIBITMAP; page: Integer; - data: PFIBITMAP); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_InsertPage@12'{$ENDIF}; -procedure FreeImage_DeletePage(bitmap: PFIMULTIBITMAP; page: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_DeletePage@8'{$ENDIF}; -function FreeImage_LockPage(bitmap: PFIMULTIBITMAP; page: Integer): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_LockPage@8'{$ENDIF}; -procedure FreeImage_UnlockPage(bitmap: PFIMULTIBITMAP; data: PFIBITMAP; - changed: LongBool); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_UnlockPage@12'{$ENDIF}; -function FreeImage_MovePage(bitmap: PFIMULTIBITMAP; target, source: Integer): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_MovePage@12'{$ENDIF}; -function FreeImage_GetLockedPageNumbers(bitmap: PFIMULTIBITMAP; var pages: Integer; - var count: Integer): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetLockedPageNumbers@12'{$ENDIF}; - -// -------------------------------------------------------------------------- -// Filetype request routines ------------------------------------------------ -// -------------------------------------------------------------------------- - -function FreeImage_GetFileType(filename: PAnsiChar; - size: Integer = 0): FREE_IMAGE_FORMAT; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFileType@8'{$ENDIF}; -function FreeImage_GetFileTypeU(filename: PWideChar; - size: Integer = 0): FREE_IMAGE_FORMAT; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFileTypeU@8'{$ENDIF}; -function FreeImage_GetFileTypeFromHandle(io: PFreeImageIO; handle: FI_Handle; - size: Integer = 0): FREE_IMAGE_FORMAT; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFileTypeFromHandle@12'{$ENDIF}; -function FreeImage_GetFileTypeFromMemory(stream: PFIMEMORY; - size: Integer = 0): FREE_IMAGE_FORMAT; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFileTypeFromMemory@8'{$ENDIF}; - -// -------------------------------------------------------------------------- -// ImageType request routine ------------------------------------------------ -// -------------------------------------------------------------------------- - -function FreeImage_GetImageType(dib: PFIBITMAP): FREE_IMAGE_TYPE; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetImageType@4'{$ENDIF}; - -// -------------------------------------------------------------------------- -// FreeImage helper routines ------------------------------------------------ -// -------------------------------------------------------------------------- - -function FreeImage_IsLittleEndian: LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_IsLittleEndian@0'{$ENDIF}; -function FreeImage_LookupX11Color(szColor: PAnsiChar; var nRed, nGreen, nBlue: Byte): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_LookupX11Color@16'{$ENDIF}; -function FreeImage_LookupSVGColor(szColor: PAnsiChar; var nRed, nGreen, nBlue: Byte): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_LookupSVGColor@16'{$ENDIF}; - -// -------------------------------------------------------------------------- -// Pixels access routines --------------------------------------------------- -// -------------------------------------------------------------------------- - -function FreeImage_GetBits(dib: PFIBITMAP): PByte; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetBits@4'{$ENDIF}; -function FreeImage_GetScanLine(dib: PFIBITMAP; scanline: Integer): PByte; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetScanLine@8'{$ENDIF}; - -function FreeImage_GetPixelIndex(dib: PFIBITMAP; x, y: Cardinal; var value: Byte): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetPixelIndex@16'{$ENDIF}; -function FreeImage_GetPixelColor(dib: PFIBITMAP; x, y: Cardinal; var value: RGBQUAD): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetPixelColor@16'{$ENDIF}; -function FreeImage_SetPixelIndex(dib: PFIBITMAP; x, y: Cardinal; var value: Byte): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetPixelIndex@16'{$ENDIF}; -function FreeImage_SetPixelColor(dib: PFIBITMAP; x, y: Cardinal; var value: RGBQUAD): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetPixelColor@16'{$ENDIF}; - -// -------------------------------------------------------------------------- -// DIB info routines -------------------------------------------------------- -// -------------------------------------------------------------------------- - -function FreeImage_GetColorsUsed(dib: PFIBITMAP): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetColorsUsed@4'{$ENDIF}; -function FreeImage_GetBPP(dib: PFIBITMAP): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetBPP@4'{$ENDIF}; -function FreeImage_GetWidth(dib: PFIBITMAP): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetWidth@4'{$ENDIF}; -function FreeImage_GetHeight(dib: PFIBITMAP): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetHeight@4'{$ENDIF}; -function FreeImage_GetLine(dib: PFIBITMAP): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetLine@4'{$ENDIF}; -function FreeImage_GetPitch(dib: PFIBITMAP): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetPitch@4'{$ENDIF}; -function FreeImage_GetDIBSize(dib: PFIBITMAP): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetDIBSize@4'{$ENDIF}; -function FreeImage_GetPalette(dib: PFIBITMAP): PRGBQuad; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetPalette@4'{$ENDIF}; - -function FreeImage_GetDotsPerMeterX(dib: PFIBITMAP): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetDotsPerMeterX@4'{$ENDIF}; -function FreeImage_GetDotsPerMeterY(dib: PFIBITMAP): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetDotsPerMeterY@4'{$ENDIF}; -procedure FreeImage_SetDotsPerMeterX(dib: PFIBITMAP; res: Cardinal); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetDotsPerMeterX@8'{$ENDIF}; -procedure FreeImage_SetDotsPerMeterY(dib: PFIBITMAP; res: Cardinal); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetDotsPerMeterY@8'{$ENDIF}; - -function FreeImage_GetInfoHeader(dib: PFIBITMAP): PBITMAPINFOHEADER; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetInfoHeader@4'{$ENDIF}; -function FreeImage_GetInfo(dib: PFIBITMAP): PBITMAPINFO; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetInfo@4'{$ENDIF}; -function FreeImage_GetColorType(dib: PFIBITMAP): FREE_IMAGE_COLOR_TYPE; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetColorType@4'{$ENDIF}; - -function FreeImage_GetRedMask(dib: PFIBITMAP): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetRedMask@4'{$ENDIF}; -function FreeImage_GetGreenMask(dib: PFIBITMAP): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetGreenMask@4'{$ENDIF}; -function FreeImage_GetBlueMask(dib: PFIBITMAP): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetBlueMask@4'{$ENDIF}; - -function FreeImage_GetTransparencyCount(dib: PFIBITMAP): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTransparencyCount@4'{$ENDIF}; -function FreeImage_GetTransparencyTable(dib: PFIBITMAP): PByte; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTransparencyTable@4'{$ENDIF}; -procedure FreeImage_SetTransparent(dib: PFIBITMAP; enabled: LongBool); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTransparent@8'{$ENDIF}; -procedure FreeImage_SetTransparencyTable(dib: PFIBITMAP; table: PByte; - count: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTransparencyTable@12'{$ENDIF}; -function FreeImage_IsTransparent(dib: PFIBITMAP): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_IsTransparent@4'{$ENDIF}; -procedure FreeImage_SetTransparentIndex(dib: PFIBITMAP; index: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTransparentIndex@8'{$ENDIF}; -function FreeImage_GetTransparentIndex(dib: PFIBITMAP): Integer; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTransparentIndex@4'{$ENDIF}; - -function FreeImage_HasBackgroundColor(dib: PFIBITMAP): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_HasBackgroundColor@4'{$ENDIF}; -function FreeImage_GetBackgroundColor(dib: PFIBITMAP; var bkcolor: RGBQUAD): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetBackgroundColor@8'{$ENDIF}; -function FreeImage_SetBackgroundColor(dib: PFIBITMAP; bkcolor: PRGBQuad): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetBackgroundColor@8'{$ENDIF}; - -function FreeImage_GetThumbnail(dib: PFIBITMAP): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetThumbnail@4'{$ENDIF}; -function FreeImage_SetThumbnail(dib, thumbnail: PFIBITMAP): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetThumbnail@8'{$ENDIF}; - -// -------------------------------------------------------------------------- -// ICC profile routines ----------------------------------------------------- -// -------------------------------------------------------------------------- - -function FreeImage_GetICCProfile(dib: PFIBITMAP): PFIICCPROFILE; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetICCProfile@4'{$ENDIF}; -function FreeImage_CreateICCProfile(dib: PFIBITMAP; data: Pointer; - size: LongInt): PFIICCPROFILE; stdcall; - external FIDLL {$IFDEF WIN32}name 'FreeImage_CreateICCProfile@12'{$ENDIF}; -procedure FreeImage_DestroyICCProfile(dib: PFIBITMAP); stdcall; - external FIDLL {$IFDEF WIN32}name 'FreeImage_DestroyICCProfile@4'{$ENDIF}; - -// -------------------------------------------------------------------------- -// Line conversion routines ------------------------------------------------- -// -------------------------------------------------------------------------- - -procedure FreeImage_ConvertLine1To4(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine1To4@12'{$ENDIF}; -procedure FreeImage_ConvertLine8To4(target, source: PByte; width_in_pixels: Integer; - palette: PRGBQuad); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine8To4@16'{$ENDIF}; -procedure FreeImage_ConvertLine16To4_555(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To4_555@12'{$ENDIF}; -procedure FreeImage_ConvertLine16To4_565(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To4_565@12'{$ENDIF}; -procedure FreeImage_ConvertLine24To4(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine24To4@12'{$ENDIF}; -procedure FreeImage_ConvertLine32To4(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine32To4@12'{$ENDIF}; - -procedure FreeImage_ConvertLine1To8(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine1To8@12'{$ENDIF}; -procedure FreeImage_ConvertLine4To8(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine4To8@12'{$ENDIF}; -procedure FreeImage_ConvertLine16To8_555(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To8_555@12'{$ENDIF}; -procedure FreeImage_ConvertLine16To8_565(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To8_565@12'{$ENDIF}; -procedure FreeImage_ConvertLine24To8(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine24To8@12'{$ENDIF}; -procedure FreeImage_ConvertLine32To8(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine32To8@12'{$ENDIF}; - -procedure FreeImage_ConvertLine1To16_555(target, source: PByte; width_in_pixels: Integer; - palette: PRGBQuad); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine1To16_555@16'{$ENDIF}; -procedure FreeImage_ConvertLine4To16_555(target, source: PByte; width_in_pixels: Integer; - palette: PRGBQuad); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine4To16_555@16'{$ENDIF}; -procedure FreeImage_ConvertLine8To16_555(target, source: PByte; width_in_pixels: Integer; - palette: PRGBQuad); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine8To16_555@16'{$ENDIF}; -procedure FreeImage_ConvertLine16_565_To16_555(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16_565_To16_555@12'{$ENDIF}; -procedure FreeImage_ConvertLine24To16_555(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine24To16_555@12'{$ENDIF}; -procedure FreeImage_ConvertLine32To16_555(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine32To16_555@12'{$ENDIF}; - -procedure FreeImage_ConvertLine1To16_565(target, source: PByte; width_in_pixels: Integer; - palette: PRGBQuad); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine1To16_565@16'{$ENDIF}; -procedure FreeImage_ConvertLine4To16_565(target, source: PByte; width_in_pixels: Integer; - palette: PRGBQuad); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine4To16_565@16'{$ENDIF}; -procedure FreeImage_ConvertLine8To16_565(target, source: PByte; width_in_pixels: Integer; - palette: PRGBQuad); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine8To16_565@16'{$ENDIF}; -procedure FreeImage_ConvertLine16_555_To16_565(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16_555_To16_565@12'{$ENDIF}; -procedure FreeImage_ConvertLine24To16_565(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine24To16_565@12'{$ENDIF}; -procedure FreeImage_ConvertLine32To16_565(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine32To16_565@12'{$ENDIF}; - -procedure FreeImage_ConvertLine1To24(target, source: PByte; width_in_pixels: Integer; - palette: PRGBQuad); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine1To24@16'{$ENDIF}; -procedure FreeImage_ConvertLine4To24(target, source: PByte; width_in_pixels: Integer; - palette: PRGBQuad); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine4To24@16'{$ENDIF}; -procedure FreeImage_ConvertLine8To24(target, source: PByte; width_in_pixels: Integer; - palette: PRGBQuad); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine8To24@16'{$ENDIF}; -procedure FreeImage_ConvertLine16To24_555(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To24_555@12'{$ENDIF}; -procedure FreeImage_ConvertLine16To24_565(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To24_565@12'{$ENDIF}; -procedure FreeImage_ConvertLine32To24(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine32To24@12'{$ENDIF}; - -procedure FreeImage_ConvertLine1To32(target, source: PByte; width_in_pixels: Integer; - palette: PRGBQuad); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine1To32@16'{$ENDIF}; -procedure FreeImage_ConvertLine4To32(target, source: PByte; width_in_pixels: Integer; - palette: PRGBQuad); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine4To32@16'{$ENDIF}; -procedure FreeImage_ConvertLine8To32(target, source: PByte; width_in_pixels: Integer; - palette: PRGBQuad); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine8To32@16'{$ENDIF}; -procedure FreeImage_ConvertLine16To32_555(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To32_555@12'{$ENDIF}; -procedure FreeImage_ConvertLine16To32_565(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To32_565@12'{$ENDIF}; -procedure FreeImage_ConvertLine24To32(target, source: PByte; width_in_pixels: Integer); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine24To32@12'{$ENDIF}; - -// -------------------------------------------------------------------------- -// Smart conversion routines ------------------------------------------------ -// -------------------------------------------------------------------------- - -function FreeImage_ConvertTo4Bits(dib: PFIBITMAP): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertTo4Bits@4'{$ENDIF}; -function FreeImage_ConvertTo8Bits(dib: PFIBITMAP): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertTo8Bits@4'{$ENDIF}; -function FreeImage_ConvertToGreyscale(dib: PFIBITMAP): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToGreyscale@4'{$ENDIF}; -function FreeImage_ConvertTo16Bits555(dib: PFIBITMAP): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertTo16Bits555@4'{$ENDIF}; -function FreeImage_ConvertTo16Bits565(dib: PFIBITMAP): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertTo16Bits565@4'{$ENDIF}; -function FreeImage_ConvertTo24Bits(dib: PFIBITMAP): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertTo24Bits@4'{$ENDIF}; -function FreeImage_ConvertTo32Bits(dib: PFIBITMAP): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertTo32Bits@4'{$ENDIF}; -function FreeImage_ColorQuantize(dib: PFIBITMAP; quantize: FREE_IMAGE_QUANTIZE): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ColorQuantize@8'{$ENDIF}; -function FreeImage_ColorQuantizeEx(dib: PFIBITMAP; quantize: FREE_IMAGE_QUANTIZE = FIQ_WUQUANT; - PaletteSize: Integer = 256; ReserveSize: Integer = 0; - ReservePalette: PRGBQuad = nil): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ColorQuantizeEx@20'{$ENDIF}; -function FreeImage_Threshold(dib: PFIBITMAP; T: Byte): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_Threshold@8'{$ENDIF}; -function FreeImage_Dither(dib: PFIBITMAP; algorithm: FREE_IMAGE_DITHER): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_Dither@8'{$ENDIF}; - -function FreeImage_ConvertFromRawBits(bits: PByte; width, height, pitch: Integer; - bpp, red_mask, green_mask, blue_mask: Cardinal; topdown: LongBool = False): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertFromRawBits@36'{$ENDIF}; -procedure FreeImage_ConvertToRawBits(bits: PByte; dib: PFIBITMAP; pitch: Integer; - bpp, red_mask, green_mask, blue_mask: Cardinal; topdown: LongBool = False); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToRawBits@32'{$ENDIF}; - -function FreeImage_ConvertToFloat(dib: PFIBITMAP): PFIBITMAP; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToFloat@4'{$ENDIF}; -function FreeImage_ConvertToRGBF(dib: PFIBITMAP): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToRGBF@4'{$ENDIF}; -function FreeImage_ConvertToUINT16(dib: PFIBITMAP): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToUINT16@4'{$ENDIF}; -function FreeImage_ConvertToRGB16(dib: PFIBITMAP): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToRGB16@4'{$ENDIF}; - -function FreeImage_ConvertToStandardType(src: PFIBITMAP; - scale_linear: LongBool = True): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToStandardType@8'{$ENDIF}; -function FreeImage_ConvertToType(src: PFIBITMAP; dst_type: FREE_IMAGE_TYPE; - scale_linear: LongBool = True): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToType@12'{$ENDIF}; - -// tone mapping operators -function FreeImage_ToneMapping(dib: PFIBITMAP; tmo: FREE_IMAGE_TMO; - first_param: Double = 0; second_param: Double = 0): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ToneMapping@24'{$ENDIF}; -function FreeImage_TmoDrago03(src: PFIBITMAP; gamma: Double = 2.2; - exposure: Double = 0): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_TmoDrago03@20'{$ENDIF}; -function FreeImage_TmoReinhard05(src: PFIBITMAP; intensity: Double = 0; - contrast: Double = 0): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_TmoReinhard05@20'{$ENDIF}; -function FreeImage_TmoReinhard05Ex(src: PFIBITMAP; intensity: Double = 0; - contrast: Double = 0; adaptation: Double = 1; color_correction: Double = 0): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_TmoReinhard05Ex@36'{$ENDIF}; - -function FreeImage_TmoFattal02(src: PFIBITMAP; color_saturation: Double = 0.5; - attenuation: Double = 0.85): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_TmoFattal02@20'{$ENDIF}; - -// -------------------------------------------------------------------------- -// ZLib interface ----------------------------------------------------------- -// -------------------------------------------------------------------------- - -function FreeImage_ZLibCompress(target: PByte; target_size: DWORD; source: PByte; source_size: DWORD): DWORD; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ZLibCompress@16'{$ENDIF}; -function FreeImage_ZLibUncompress(target: PByte; target_size: DWORD; source: PByte; source_size: DWORD): DWORD; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ZLibUncompress@16'{$ENDIF}; -function FreeImage_ZLibGZip(target: PByte; target_size: DWORD; source: PByte; source_size: DWORD): DWORD; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ZLibGZip@16'{$ENDIF}; -function FreeImage_ZLibGUnzip(target: PByte; target_size: DWORD; source: PByte; source_size: DWORD): DWORD; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ZLibGUnzip@16'{$ENDIF}; -function FreeImage_ZLibCRC32(crc: DWORD; source: PByte; source_size: DWORD): DWORD; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ZLibCRC32@12'{$ENDIF}; - -// -------------------------------------------------------------------------- -// Metadata routines -------------------------------------------------------- -// -------------------------------------------------------------------------- - -// tag creation / destruction -function FreeImage_CreateTag: PFITAG; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_CreateTag@0'{$ENDIF}; -procedure FreeImage_DeleteTag(tag: PFITAG); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_DeleteTag@4'{$ENDIF}; -function FreeImage_CloneTag(tag: PFITAG): PFITAG; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_CloneTag@4'{$ENDIF}; - -// tag getters and setters -function FreeImage_GetTagKey(tag: PFITAG): PAnsiChar; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTagKey@4'{$ENDIF}; -function FreeImage_GetTagDescription(tag: PFITAG): PAnsiChar; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTagDescription@4'{$ENDIF}; -function FreeImage_GetTagID(tag: PFITAG): Word; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTagID@4'{$ENDIF}; -function FreeImage_GetTagType(tag: PFITAG): FREE_IMAGE_MDTYPE; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTagType@4'{$ENDIF}; -function FreeImage_GetTagCount(tag: PFITAG): DWORD; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTagCount@4'{$ENDIF}; -function FreeImage_GetTagLength(tag: PFITAG): DWORD; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTagLength@4'{$ENDIF}; -function FreeImage_GetTagValue(tag: PFITAG): Pointer; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTagValue@4'{$ENDIF}; - -function FreeImage_SetTagKey(tag: PFITAG; key: PAnsiChar): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTagKey@8'{$ENDIF}; -function FreeImage_SetTagDescription(tag: PFITAG; description: PAnsiChar): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTagDescription@8'{$ENDIF}; -function FreeImage_SetTagID(tag: PFITAG; id: Word): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTagID@8'{$ENDIF}; -function FreeImage_SetTagType(tag: PFITAG; atype: FREE_IMAGE_MDTYPE): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTagType@8'{$ENDIF}; -function FreeImage_SetTagCount(tag: PFITAG; count: DWORD): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTagCount@8'{$ENDIF}; -function FreeImage_SetTagLength(tag: PFITAG; length: DWORD): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTagLength@8'{$ENDIF}; -function FreeImage_SetTagValue(tag: PFITAG; value: Pointer): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTagValue@8'{$ENDIF}; - -// iterator -function FreeImage_FindFirstMetadata(model: FREE_IMAGE_MDMODEL; dib: PFIBITMAP; - var tag: PFITAG): PFIMETADATA; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_FindFirstMetadata@12'{$ENDIF}; -function FreeImage_FindNextMetadata(mdhandle: PFIMETADATA; var tag: PFITAG): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_FindNextMetadata@8'{$ENDIF}; -procedure FreeImage_FindCloseMetadata(mdhandle: PFIMETADATA); stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_FindCloseMetadata@4'{$ENDIF}; - -// metadata setter and getter -function FreeImage_SetMetadata(model: FREE_IMAGE_MDMODEL; dib: PFIBITMAP; - key: PAnsiChar; tag: PFITAG): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetMetadata@16'{$ENDIF}; -function FreeImage_GetMetadata(model: FREE_IMAGE_MDMODEL; dib: PFIBITMAP; - key: PAnsiChar; var tag: PFITAG): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetMetadata@16'{$ENDIF}; - -// helpers -function FreeImage_GetMetadataCount(model: FREE_IMAGE_MDMODEL; dib: PFIBITMAP): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetMetadataCount@8'{$ENDIF}; -function FreeImage_CloneMetadata(dst, src: PFIBITMAP): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_CloneMetadata@8'{$ENDIF}; - -// tag to C string conversion -function FreeImage_TagToString(model: FREE_IMAGE_MDMODEL; tag: PFITAG; - Make: PAnsiChar = nil): PAnsiChar; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_TagToString@12'{$ENDIF}; - -// -------------------------------------------------------------------------- -// Image manipulation toolkit ----------------------------------------------- -// -------------------------------------------------------------------------- - -// rotation and flipping -// modif JMB : FreeImage_RotateClassic : deprecated function, call to DeprecationManager in 64 bits crashes freeimage.dll -//function FreeImage_RotateClassic(dib: PFIBITMAP; angle: Double): PFIBITMAP; stdcall; -// external FIDLL {$IFDEF WIN32}name '_FreeImage_RotateClassic@12'{$ENDIF}; -function FreeImage_Rotate(dib: PFIBITMAP; angle: Double; bkcolor: Pointer = nil): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_Rotate@16'{$ENDIF}; -function FreeImage_RotateEx(dib: PFIBITMAP; angle, x_shift, y_shift, x_origin, y_origin: Double; - use_mask: LongBool): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_RotateEx@48'{$ENDIF}; -function FreeImage_FlipHorizontal(dib: PFIBITMAP): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_FlipHorizontal@4'{$ENDIF}; -function FreeImage_FlipVertical(dib: PFIBITMAP): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_FlipVertical@4'{$ENDIF}; -function FreeImage_JPEGTransform(src_file, dst_file: PAnsiChar; operation: FREE_IMAGE_JPEG_OPERATION; - perfect: LongBool = False): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_JPEGTransform@16'{$ENDIF}; -function FreeImage_JPEGTransformU(src_file, dst_file: PWideChar; operation: FREE_IMAGE_JPEG_OPERATION; - perfect: LongBool = False): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_JPEGTransformU@16'{$ENDIF}; - -// upsampling / downsampling -function FreeImage_Rescale(dib: PFIBITMAP; dst_width, dst_height: Integer; filter: FREE_IMAGE_FILTER): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_Rescale@16'{$ENDIF}; -function FreeImage_MakeThumbnail(dib: PFIBITMAP; max_pixel_size: Integer; convert: LongBool = True): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_MakeThumbnail@12'{$ENDIF}; - -// color manipulation routines (point operations) -function FreeImage_AdjustCurve(dib: PFIBITMAP; LUT: PByte; - channel: FREE_IMAGE_COLOR_CHANNEL): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_AdjustCurve@12'{$ENDIF}; -function FreeImage_AdjustGamma(dib: PFIBITMAP; gamma: Double): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_AdjustGamma@12'{$ENDIF}; -function FreeImage_AdjustBrightness(dib: PFIBITMAP; percentage: Double): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_AdjustBrightness@12'{$ENDIF}; -function FreeImage_AdjustContrast(dib: PFIBITMAP; percentage: Double): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_AdjustContrast@12'{$ENDIF}; -function FreeImage_Invert(dib: PFIBITMAP): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_Invert@4'{$ENDIF}; -function FreeImage_GetHistogram(dib: PFIBITMAP; histo: PDWORD; - channel: FREE_IMAGE_COLOR_CHANNEL = FICC_BLACK): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetHistogram@12'{$ENDIF}; -function FreeImage_GetAdjustColorsLookupTable(LUT: PByte; brightness, contrast, gamma: Double; - invert: LongBool): Integer; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetAdjustColorsLookupTable@32'{$ENDIF}; -function FreeImage_AdjustColors(dib: PFIBITMAP; brightness, contrast, gamma: Double; - invert: LongBool = False): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_AdjustColors@32'{$ENDIF}; -function FreeImage_ApplyColorMapping(dib: PFIBITMAP; srccolors, dstcolors: PRGBQuad; - count: Cardinal; ignore_alpha, swap: LongBool): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ApplyColorMapping@24'{$ENDIF}; -function FreeImage_SwapColors(dib: PFIBITMAP; color_a, color_b: PRGBQuad; - ignore_alpha: LongBool): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SwapColors@16'{$ENDIF}; -function FreeImage_ApplyPaletteIndexMapping(dib: PFIBITMAP; srcindices, dstindices: PByte; - count: Cardinal; swap: LongBool): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_ApplyPaletteIndexMapping@20'{$ENDIF}; -function FreeImage_SwapPaletteIndices(dib: PFIBITMAP; index_a, index_b: PByte): Cardinal; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SwapPaletteIndices@12'{$ENDIF}; - -// channel processing routines -function FreeImage_GetChannel(dib: PFIBITMAP; channel: FREE_IMAGE_COLOR_CHANNEL): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetChannel@8'{$ENDIF}; -function FreeImage_SetChannel(dst, src: PFIBITMAP; channel: FREE_IMAGE_COLOR_CHANNEL): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetChannel@12'{$ENDIF}; -function FreeImage_GetComplexChannel(src: PFIBITMAP; channel: FREE_IMAGE_COLOR_CHANNEL): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_GetComplexChannel@8'{$ENDIF}; -function FreeImage_SetComplexChannel(dst, src: PFIBITMAP; channel: FREE_IMAGE_COLOR_CHANNEL): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_SetComplexChannel@12'{$ENDIF}; - -// copy / paste / composite routines - -function FreeImage_Copy(dib: PFIBITMAP; left, top, right, bottom: Integer): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_Copy@20'{$ENDIF}; -function FreeImage_Paste(dst, src: PFIBITMAP; left, top, alpha: Integer): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_Paste@20'{$ENDIF}; -function FreeImage_Composite(fg: PFIBITMAP; useFileBkg: LongBool = False; - appBkColor: PRGBQuad = nil; bg: PFIBITMAP = nil): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_Composite@16'{$ENDIF}; -function FreeImage_JPEGCrop(src_file, dst_file: PAnsiChar; - left, top, right, bottom: Integer): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_JPEGCrop@24'{$ENDIF}; -function FreeImage_JPEGCropU(src_file, dst_file: PWideChar; - left, top, right, bottom: Integer): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_JPEGCropU@24'{$ENDIF}; -function FreeImage_PreMultiplyWithAlpha(dib: PFIBITMAP): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_PreMultiplyWithAlpha@4'{$ENDIF}; - -// background filling routines -function FreeImage_FillBackground(dib: PFIBITMAP; color: Pointer; - options: Integer = 0): LongBool; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_FillBackground@12'{$ENDIF}; -function FreeImage_EnlargeCanvas(src: PFIBITMAP; left, top, right, bottom: Integer; - color: Pointer; options: Integer = 0): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_EnlargeCanvas@28'{$ENDIF}; -function FreeImage_AllocateEx(width, height, bpp: Integer; color: PRGBQuad; - options: Integer = 0; palette: PRGBQuad = nil; red_mask: Cardinal = 0; - green_mask: Cardinal = 0; blue_mask: Cardinal = 0): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_AllocateEx@36'{$ENDIF}; -function FreeImage_AllocateExT(atype: FREE_IMAGE_TYPE; width, height, bpp: Integer; - color: Pointer; options: Integer = 0; palette: PRGBQuad = nil; red_mask: Cardinal = 0; - green_mask: Cardinal = 0; blue_mask: Cardinal = 0): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_AllocateExT@40'{$ENDIF}; - -// miscellaneous algorithms -function FreeImage_MultigridPoissonSolver(Laplacian: PFIBITMAP; - ncycle: Integer = 3): PFIBITMAP; stdcall; - external FIDLL {$IFDEF WIN32}name '_FreeImage_MultigridPoissonSolver@8'{$ENDIF}; - - -implementation - -{$IFNDEF DELPHI6} -uses SysUtils; - -//we provide a wrapper since we haven't varargs in older versions of Delphi -procedure __FreeImage_OutputMessageProc; - external FIDLL name 'FreeImage_OutputMessageProc'; -procedure FreeImage_OutputMessageProc(fif: Integer; fmt: PAnsiChar; args: array of const); - function ArrayToBuffer(Args: array of const; - var Argv: Pointer; Buffer: Pointer; Size: Cardinal): Integer; - var - i: Integer; - temp: AnsiString; - parg: Pointer; - psrc, pbuf: PAnsiChar; - len: Cardinal; - begin - Result := High(Args) + 1; - if Result = 0 then - Exit; - //array of pointers to push on stack - GetMem(Argv, Result * SizeOf(Pointer)); - //pointer to current string in buffer - pbuf := Buffer; - //pointer to current arg - parg := Argv; - //for each const... - for i := 0 to Result - 1 do begin - case Args[i].VType of - vtInteger: begin - //integer - psrc := nil; - len := 0; - Integer(parg^) := Args[i].VInteger; - end; - vtString: begin - //short string - psrc := PAnsiChar(Cardinal(Args[i].VString) + SizeOf(Byte)); - len := PByte(Args[i].VString)^; - PAnsiChar(parg^) := pbuf; - end; - vtPChar: begin - //NULL terminated MBCS string - psrc := nil; - len := 0; - PAnsiChar(parg^) := Args[i].VPChar; - end; - vtPWideChar: begin - //NULL terminated Unicode string - temp := AnsiString(Args[i].VPWideChar); - psrc := PAnsiChar(temp); - len := Length(temp); - PAnsiChar(parg^) := pbuf; - end; - vtAnsiString: begin - //ANSI string - psrc := PAnsiChar(Args[i].VAnsiString); - len := StrLen(psrc); - PAnsiChar(parg^) := pbuf; - end; - vtWideString: begin - //Wide string (OLE) - temp := AnsiString(PWideChar(Args[i].VWideString)); - psrc := PAnsiChar(temp); - len := Length(temp); - PAnsiChar(parg^) := pbuf; - end; - else raise Exception.Create('Unsupported argument type'); - end; - if (psrc <> nil) and (len <> 0) then begin - //enough space to hold string? - if Size < (len + 1) then - raise Exception.Create('Buffer overflow'); - //copy string - Move(psrc^, pbuf^, len); - //NULL terminator - PAnsiChar(Cardinal(pbuf) + len)^ := #0; - //shift pointer... - Inc(pbuf, len + 1); - //...and decrease space left - Dec(Size, len + 1); - end; - Cardinal(parg) := Cardinal(parg) + SizeOf(Pointer); - end; - end; - - procedure DoVarargsCall(fif: Integer; fmt: PAnsiChar; Argv: Pointer; Argc: Integer); - { - fif -> EAX - fmt -> EDX - Argv -> ECX - Argc -> [EBP+$08] - } - asm - PUSH EAX //remember fif - PUSH ECX //make room for ESP backup - - MOV DWORD PTR [EBP-$08], ESP //backup stack pointer - - MOV EAX, DWORD PTR [EBP+$08] //store Argc - - TEST EAX, EAX //Argc <= 0? - JLE @Call - - @Loop: - PUSH DWORD PTR [ECX+EAX*$04-$04] //push Argv in right to left order - DEC EAX - JNZ @Loop - - @Call: - PUSH EDX //push fmt - PUSH DWORD PTR [EBP-$04] //push fif - CALL __FreeImage_OutputMessageProc - - MOV ESP, DWORD PTR [EBP-$08] //restore stack pointer - - POP ECX //clean stack - POP EAX - end; -var - Argc: Integer; - Argv: Pointer; - //buffer to hold strings - FreeImage allocates 512 bytes, we needn't more... - Buffer: array[1..512] of Byte; -begin - Argv := nil; - //build array of pointers from array of const - Argc := ArrayToBuffer(args, Argv, @Buffer, SizeOf(Buffer)); - try - //mimic cdecl call with varargs - DoVarargsCall(fif, fmt, Argv, Argc); - finally - //cleanup - FreeMem(Argv); - end; -end; -{$ENDIF} - -end. +unit FreeImage; + +// ========================================================== +// Delphi wrapper for FreeImage 3 +// +// Design and implementation by +// - Simon Beavis +// - Peter Byström +// - Anatoliy Pulyaevskiy (xvel84@rambler.ru) +// +// Contributors: +// - Lorenzo Monti (LM) lomo74@gmail.com +// +// Revision history +// When Who What +// ----------- ----- ----------------------------------------------------------- +// 2010-07-14 LM Fixed some C->Delphi translation errors, +// updated to 3.13.1, made RAD2010 compliant (unicode) +// 2010-07-29 LM Added Free Pascal / Lazarus 32 bit support +// 2010-11-12 LM Updated to 3.14.1 +// 2011-02-15 LM Updated to 3.15.0 +// 2011-03-04 JMB Modifications to compile on Free Pascal / Lazarus 64 bits (tested on Windows 7 and linux OpenSuse) : +// - in 64 bits, the names of the exported function are different : +// e.g. : _FreeImage_AcquireMemory@12 in 32 bits and FreeImage_AcquireMemory in 64 bits +// so the define WIN32 will allow to distinguish 32 and 64 bits in the calls to the freeimage library +// - in 64 bits, the Boolean type is not correctly converted to freeimage BOOL type (integer 32 bits) +// ==> replace Boolean with LongBool in the calls to the freeimage library +// - as linux sees the difference between uppercase and lowercase : +// ==> replace FreeImage_GetMetaData with FreeImage_GetMetadata in the call to the freeimage library +// 2012-06-04 LM Updated to 3.15.3 +// + +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +interface + +{$MINENUMSIZE 4} // Make sure enums are stored as an integer to be compatible with C/C++ + +{$I 'Version.inc'} + +{$IFDEF MSWINDOWS} +uses Windows; +{$ELSE} +type + LONG = LongInt; + DWORD = Cardinal; + + BITMAPINFOHEADER = record + biSize : DWORD; + biWidth : LONG; + biHeight : LONG; + biPlanes : WORD; + biBitCount : WORD; + biCompression : DWORD; + biSizeImage : DWORD; + biXPelsPerMeter : LONG; + biYPelsPerMeter : LONG; + biClrUsed : DWORD; + biClrImportant : DWORD; + end; + LPBITMAPINFOHEADER = ^BITMAPINFOHEADER; + TBITMAPINFOHEADER = BITMAPINFOHEADER; + PBITMAPINFOHEADER = ^BITMAPINFOHEADER; + + RGBQUAD = record + rgbBlue : BYTE; + rgbGreen : BYTE; + rgbRed : BYTE; + rgbReserved : BYTE; + end; + tagRGBQUAD = RGBQUAD; + TRGBQUAD = RGBQUAD; + PRGBQUAD = ^RGBQUAD; + + BITMAPINFO = record + bmiHeader : BITMAPINFOHEADER; + bmiColors : array[0..0] of RGBQUAD; + end; + LPBITMAPINFO = ^BITMAPINFO; + PBITMAPINFO = ^BITMAPINFO; + TBITMAPINFO = BITMAPINFO; +// modif JMB NOVAXEL + HBITMAP = type LongWord; + HWND = type LongWord; + HDC = type LongWord; +// end of modif JMB NOVAXEL +{$ENDIF} + +const + FIDLL = {$IFDEF MSWINDOWS}'FreeImage.dll';{$ENDIF} + {$IFDEF LINUX}'libfreeimage.so';{$ENDIF} + +const + // Version information + FREEIMAGE_MAJOR_VERSION = 3; + FREEIMAGE_MINOR_VERSION = 15; + FREEIMAGE_RELEASE_SERIAL = 3; + // This really only affects 24 and 32 bit formats, the rest are always RGB order. + FREEIMAGE_COLORORDER_BGR = 0; + FREEIMAGE_COLORORDER_RGB = 1; + FREEIMAGE_COLORORDER = FREEIMAGE_COLORORDER_BGR; + +// -------------------------------------------------------------------------- +// Bitmap types ------------------------------------------------------------- +// -------------------------------------------------------------------------- + +type + FIBITMAP = record + data: Pointer; + end; + PFIBITMAP = ^FIBITMAP; + + FIMULTIBITMAP = record + data: Pointer; + end; + PFIMULTIBITMAP = ^FIMULTIBITMAP; + +// -------------------------------------------------------------------------- +// Types used in the library (specific to FreeImage) ------------------------ +// -------------------------------------------------------------------------- + +type + {* 48-bit RGB } + tagFIRGB16 = packed record + red: WORD; + green: WORD; + blue: WORD; + end; + FIRGB16 = tagFIRGB16; + + {* 64-bit RGBA } + tagFIRGBA16 = packed record + red: WORD; + green: WORD; + blue: WORD; + alpha: WORD; + end; + FIRGBA16 = tagFIRGBA16; + + {* 96-bit RGB Float } + tagFIRGBF = packed record + red: Single; + green: Single; + blue: Single; + end; + FIRGBF = tagFIRGBF; + + {* 128-bit RGBA Float } + tagFIRGBAF = packed record + red: Single; + green: Single; + blue: Single; + alpha: Single; + end; + FIRGBAF = tagFIRGBAF; + + {* Data structure for COMPLEX type (complex number) } + tagFICOMPLEX = packed record + /// real part + r: Double; + /// imaginary part + i: Double; + end; + FICOMPLEX = tagFICOMPLEX; + +// -------------------------------------------------------------------------- +// Indexes for byte arrays, masks and shifts for treating pixels as words --- +// These coincide with the order of RGBQUAD and RGBTRIPLE ------------------- +// Little Endian (x86 / MS Windows, Linux) : BGR(A) order ------------------- +// -------------------------------------------------------------------------- + +const + FI_RGBA_RED = 2; + FI_RGBA_GREEN = 1; + FI_RGBA_BLUE = 0; + FI_RGBA_ALPHA = 3; + FI_RGBA_RED_MASK = $00FF0000; + FI_RGBA_GREEN_MASK = $0000FF00; + FI_RGBA_BLUE_MASK = $000000FF; + FI_RGBA_ALPHA_MASK = $FF000000; + FI_RGBA_RED_SHIFT = 16; + FI_RGBA_GREEN_SHIFT = 8; + FI_RGBA_BLUE_SHIFT = 0; + FI_RGBA_ALPHA_SHIFT = 24; + + FI_RGBA_RGB_MASK = FI_RGBA_RED_MASK or FI_RGBA_GREEN_MASK or FI_RGBA_BLUE_MASK; + +// -------------------------------------------------------------------------- +// The 16bit macros only include masks and shifts, -------------------------- +// since each color element is not byte aligned ----------------------------- +// -------------------------------------------------------------------------- + +const + FI16_555_RED_MASK = $7C00; + FI16_555_GREEN_MASK = $03E0; + FI16_555_BLUE_MASK = $001F; + FI16_555_RED_SHIFT = 10; + FI16_555_GREEN_SHIFT = 5; + FI16_555_BLUE_SHIFT = 0; + FI16_565_RED_MASK = $F800; + FI16_565_GREEN_MASK = $07E0; + FI16_565_BLUE_MASK = $001F; + FI16_565_RED_SHIFT = 11; + FI16_565_GREEN_SHIFT = 5; + FI16_565_BLUE_SHIFT = 0; + +// -------------------------------------------------------------------------- +// ICC profile support ------------------------------------------------------ +// -------------------------------------------------------------------------- + +const + FIICC_DEFAULT = $0; + FIICC_COLOR_IS_CMYK = $1; + +type + FIICCPROFILE = record + flags: WORD; // info flag + size: DWORD; // profile's size measured in bytes + data: Pointer; // points to a block of contiguous memory containing the profile + end; + PFIICCPROFILE = ^FIICCPROFILE; + +// -------------------------------------------------------------------------- +// Important enums ---------------------------------------------------------- +// -------------------------------------------------------------------------- + +type + FREE_IMAGE_FORMAT = type Integer; + FREE_IMAGE_TYPE = type Integer; + FREE_IMAGE_COLOR_TYPE = type Integer; + FREE_IMAGE_QUANTIZE = type Integer; + FREE_IMAGE_DITHER = type Integer; + FREE_IMAGE_FILTER = type Integer; + FREE_IMAGE_COLOR_CHANNEL = type Integer; + FREE_IMAGE_MDTYPE = type Integer; + FREE_IMAGE_MDMODEL = type Integer; + FREE_IMAGE_JPEG_OPERATION = type Integer; + FREE_IMAGE_TMO = type Integer; + +const + // I/O image format identifiers. + FIF_UNKNOWN = FREE_IMAGE_FORMAT(-1); + FIF_BMP = FREE_IMAGE_FORMAT(0); + FIF_ICO = FREE_IMAGE_FORMAT(1); + FIF_JPEG = FREE_IMAGE_FORMAT(2); + FIF_JNG = FREE_IMAGE_FORMAT(3); + FIF_KOALA = FREE_IMAGE_FORMAT(4); + FIF_LBM = FREE_IMAGE_FORMAT(5); + FIF_IFF = FIF_LBM; + FIF_MNG = FREE_IMAGE_FORMAT(6); + FIF_PBM = FREE_IMAGE_FORMAT(7); + FIF_PBMRAW = FREE_IMAGE_FORMAT(8); + FIF_PCD = FREE_IMAGE_FORMAT(9); + FIF_PCX = FREE_IMAGE_FORMAT(10); + FIF_PGM = FREE_IMAGE_FORMAT(11); + FIF_PGMRAW = FREE_IMAGE_FORMAT(12); + FIF_PNG = FREE_IMAGE_FORMAT(13); + FIF_PPM = FREE_IMAGE_FORMAT(14); + FIF_PPMRAW = FREE_IMAGE_FORMAT(15); + FIF_RAS = FREE_IMAGE_FORMAT(16); + FIF_TARGA = FREE_IMAGE_FORMAT(17); + FIF_TIFF = FREE_IMAGE_FORMAT(18); + FIF_WBMP = FREE_IMAGE_FORMAT(19); + FIF_PSD = FREE_IMAGE_FORMAT(20); + FIF_CUT = FREE_IMAGE_FORMAT(21); + FIF_XBM = FREE_IMAGE_FORMAT(22); + FIF_XPM = FREE_IMAGE_FORMAT(23); + FIF_DDS = FREE_IMAGE_FORMAT(24); + FIF_GIF = FREE_IMAGE_FORMAT(25); + FIF_HDR = FREE_IMAGE_FORMAT(26); + FIF_FAXG3 = FREE_IMAGE_FORMAT(27); + FIF_SGI = FREE_IMAGE_FORMAT(28); + FIF_EXR = FREE_IMAGE_FORMAT(29); + FIF_J2K = FREE_IMAGE_FORMAT(30); + FIF_JP2 = FREE_IMAGE_FORMAT(31); + FIF_PFM = FREE_IMAGE_FORMAT(32); + FIF_PICT = FREE_IMAGE_FORMAT(33); + FIF_RAW = FREE_IMAGE_FORMAT(34); + + // Image type used in FreeImage. + FIT_UNKNOWN = FREE_IMAGE_TYPE(0); // unknown type + FIT_BITMAP = FREE_IMAGE_TYPE(1); // standard image: 1-, 4-, 8-, 16-, 24-, 32-bit + FIT_UINT16 = FREE_IMAGE_TYPE(2); // array of unsigned short: unsigned 16-bit + FIT_INT16 = FREE_IMAGE_TYPE(3); // array of short: signed 16-bit + FIT_UINT32 = FREE_IMAGE_TYPE(4); // array of unsigned long: unsigned 32-bit + FIT_INT32 = FREE_IMAGE_TYPE(5); // array of long: signed 32-bit + FIT_FLOAT = FREE_IMAGE_TYPE(6); // array of float: 32-bit IEEE floating point + FIT_DOUBLE = FREE_IMAGE_TYPE(7); // array of double: 64-bit IEEE floating point + FIT_COMPLEX = FREE_IMAGE_TYPE(8); // array of FICOMPLEX: 2 x 64-bit IEEE floating point + FIT_RGB16 = FREE_IMAGE_TYPE(9); // 48-bit RGB image: 3 x 16-bit + FIT_RGBA16 = FREE_IMAGE_TYPE(10); // 64-bit RGBA image: 4 x 16-bit + FIT_RGBF = FREE_IMAGE_TYPE(11); // 96-bit RGB float image: 3 x 32-bit IEEE floating point + FIT_RGBAF = FREE_IMAGE_TYPE(12); // 128-bit RGBA float image: 4 x 32-bit IEEE floating point + + // Image color type used in FreeImage. + FIC_MINISWHITE = FREE_IMAGE_COLOR_TYPE(0); // min value is white + FIC_MINISBLACK = FREE_IMAGE_COLOR_TYPE(1); // min value is black + FIC_RGB = FREE_IMAGE_COLOR_TYPE(2); // RGB color model + FIC_PALETTE = FREE_IMAGE_COLOR_TYPE(3); // color map indexed + FIC_RGBALPHA = FREE_IMAGE_COLOR_TYPE(4); // RGB color model with alpha channel + FIC_CMYK = FREE_IMAGE_COLOR_TYPE(5); // CMYK color model + + // Color quantization algorithms. Constants used in FreeImage_ColorQuantize. + FIQ_WUQUANT = FREE_IMAGE_QUANTIZE(0); // Xiaolin Wu color quantization algorithm + FIQ_NNQUANT = FREE_IMAGE_QUANTIZE(1); // NeuQuant neural-net quantization algorithm by Anthony Dekker + + // Dithering algorithms. Constants used FreeImage_Dither. + FID_FS = FREE_IMAGE_DITHER(0); // Floyd & Steinberg error diffusion + FID_BAYER4x4 = FREE_IMAGE_DITHER(1); // Bayer ordered dispersed dot dithering (order 2 dithering matrix) + FID_BAYER8x8 = FREE_IMAGE_DITHER(2); // Bayer ordered dispersed dot dithering (order 3 dithering matrix) + FID_CLUSTER6x6 = FREE_IMAGE_DITHER(3); // Ordered clustered dot dithering (order 3 - 6x6 matrix) + FID_CLUSTER8x8 = FREE_IMAGE_DITHER(4); // Ordered clustered dot dithering (order 4 - 8x8 matrix) + FID_CLUSTER16x16 = FREE_IMAGE_DITHER(5); // Ordered clustered dot dithering (order 8 - 16x16 matrix) + FID_BAYER16x16 = FREE_IMAGE_DITHER(6); // Bayer ordered dispersed dot dithering (order 4 dithering matrix) + + // Lossless JPEG transformations Constants used in FreeImage_JPEGTransform + FIJPEG_OP_NONE = FREE_IMAGE_JPEG_OPERATION(0); // no transformation + FIJPEG_OP_FLIP_H = FREE_IMAGE_JPEG_OPERATION(1); // horizontal flip + FIJPEG_OP_FLIP_V = FREE_IMAGE_JPEG_OPERATION(2); // vertical flip + FIJPEG_OP_TRANSPOSE = FREE_IMAGE_JPEG_OPERATION(3); // transpose across UL-to-LR axis + FIJPEG_OP_TRANSVERSE = FREE_IMAGE_JPEG_OPERATION(4); // transpose across UR-to-LL axis + FIJPEG_OP_ROTATE_90 = FREE_IMAGE_JPEG_OPERATION(5); // 90-degree clockwise rotation + FIJPEG_OP_ROTATE_180 = FREE_IMAGE_JPEG_OPERATION(6); // 180-degree rotation + FIJPEG_OP_ROTATE_270 = FREE_IMAGE_JPEG_OPERATION(7); // 270-degree clockwise (or 90 ccw) + + // Tone mapping operators. Constants used in FreeImage_ToneMapping. + FITMO_DRAGO03 = FREE_IMAGE_TMO(0); // Adaptive logarithmic mapping (F. Drago, 2003) + FITMO_REINHARD05 = FREE_IMAGE_TMO(1); // Dynamic range reduction inspired by photoreceptor physiology (E. Reinhard, 2005) + FITMO_FATTAL02 = FREE_IMAGE_TMO(2); // Gradient domain high dynamic range compression (R. Fattal, 2002) + + // Upsampling / downsampling filters. Constants used in FreeImage_Rescale. + FILTER_BOX = FREE_IMAGE_FILTER(0); // Box, pulse, Fourier window, 1st order (constant) b-spline + FILTER_BICUBIC = FREE_IMAGE_FILTER(1); // Mitchell & Netravali's two-param cubic filter + FILTER_BILINEAR = FREE_IMAGE_FILTER(2); // Bilinear filter + FILTER_BSPLINE = FREE_IMAGE_FILTER(3); // 4th order (cubic) b-spline + FILTER_CATMULLROM = FREE_IMAGE_FILTER(4); // Catmull-Rom spline, Overhauser spline + FILTER_LANCZOS3 = FREE_IMAGE_FILTER(5); // Lanczos3 filter + + // Color channels. Constants used in color manipulation routines. + FICC_RGB = FREE_IMAGE_COLOR_CHANNEL(0); // Use red, green and blue channels + FICC_RED = FREE_IMAGE_COLOR_CHANNEL(1); // Use red channel + FICC_GREEN = FREE_IMAGE_COLOR_CHANNEL(2); // Use green channel + FICC_BLUE = FREE_IMAGE_COLOR_CHANNEL(3); // Use blue channel + FICC_ALPHA = FREE_IMAGE_COLOR_CHANNEL(4); // Use alpha channel + FICC_BLACK = FREE_IMAGE_COLOR_CHANNEL(5); // Use black channel + FICC_REAL = FREE_IMAGE_COLOR_CHANNEL(6); // Complex images: use real part + FICC_IMAG = FREE_IMAGE_COLOR_CHANNEL(7); // Complex images: use imaginary part + FICC_MAG = FREE_IMAGE_COLOR_CHANNEL(8); // Complex images: use magnitude + FICC_PHASE = FREE_IMAGE_COLOR_CHANNEL(9); // Complex images: use phase + + // Tag data type information (based on TIFF specifications) + FIDT_NOTYPE = FREE_IMAGE_MDTYPE(0); // placeholder + FIDT_BYTE = FREE_IMAGE_MDTYPE(1); // 8-bit unsigned integer + FIDT_ASCII = FREE_IMAGE_MDTYPE(2); // 8-bit bytes w/ last byte null + FIDT_SHORT = FREE_IMAGE_MDTYPE(3); // 16-bit unsigned integer + FIDT_LONG = FREE_IMAGE_MDTYPE(4); // 32-bit unsigned integer + FIDT_RATIONAL = FREE_IMAGE_MDTYPE(5); // 64-bit unsigned fraction + FIDT_SBYTE = FREE_IMAGE_MDTYPE(6); // 8-bit signed integer + FIDT_UNDEFINED = FREE_IMAGE_MDTYPE(7); // 8-bit untyped data + FIDT_SSHORT = FREE_IMAGE_MDTYPE(8); // 16-bit signed integer + FIDT_SLONG = FREE_IMAGE_MDTYPE(9); // 32-bit signed integer + FIDT_SRATIONAL = FREE_IMAGE_MDTYPE(10); // 64-bit signed fraction + FIDT_FLOAT = FREE_IMAGE_MDTYPE(11); // 32-bit IEEE floating point + FIDT_DOUBLE = FREE_IMAGE_MDTYPE(12); // 64-bit IEEE floating point + FIDT_IFD = FREE_IMAGE_MDTYPE(13); // 32-bit unsigned integer (offset) + FIDT_PALETTE = FREE_IMAGE_MDTYPE(14); // 32-bit RGBQUAD + FIDT_LONG8 = FREE_IMAGE_MDTYPE(16); // 64-bit unsigned integer + FIDT_SLONG8 = FREE_IMAGE_MDTYPE(17); // 64-bit signed integer + FIDT_IFD8 = FREE_IMAGE_MDTYPE(18); // 64-bit unsigned integer (offset) + + // Metadata models supported by FreeImage + FIMD_NODATA = FREE_IMAGE_MDMODEL(-1); + FIMD_COMMENTS = FREE_IMAGE_MDMODEL(0); // single comment or keywords + FIMD_EXIF_MAIN = FREE_IMAGE_MDMODEL(1); // Exif-TIFF metadata + FIMD_EXIF_EXIF = FREE_IMAGE_MDMODEL(2); // Exif-specific metadata + FIMD_EXIF_GPS = FREE_IMAGE_MDMODEL(3); // Exif GPS metadata + FIMD_EXIF_MAKERNOTE = FREE_IMAGE_MDMODEL(4); // Exif maker note metadata + FIMD_EXIF_INTEROP = FREE_IMAGE_MDMODEL(5); // Exif interoperability metadata + FIMD_IPTC = FREE_IMAGE_MDMODEL(6); // IPTC/NAA metadata + FIMD_XMP = FREE_IMAGE_MDMODEL(7); // Abobe XMP metadata + FIMD_GEOTIFF = FREE_IMAGE_MDMODEL(8); // GeoTIFF metadata (to be implemented) + FIMD_ANIMATION = FREE_IMAGE_MDMODEL(9); // Animation metadata + FIMD_CUSTOM = FREE_IMAGE_MDMODEL(10); // Used to attach other metadata types to a dib + FIMD_EXIF_RAW = FREE_IMAGE_MDMODEL(11); // Exif metadata as a raw buffer + +type + // Handle to a metadata model + FIMETADATA = record + data: Pointer; + end; + PFIMETADATA = ^FIMETADATA; + + // Handle to a metadata tag + FITAG = record + data: Pointer; + end; + PFITAG = ^FITAG; + +// -------------------------------------------------------------------------- +// File IO routines --------------------------------------------------------- +// -------------------------------------------------------------------------- + +type + fi_handle = Pointer; + + FI_ReadProc = function(buffer: Pointer; size, count: Cardinal; + handle: fi_handle): Cardinal; stdcall; + FI_WriteProc = function(buffer: Pointer; size, count: Cardinal; + handle: fi_handle): Cardinal; stdcall; + FI_SeekProc = function(handle: fi_handle; offset: LongInt; + origin: Integer): Integer; stdcall; + FI_TellProc = function(handle: fi_handle): LongInt; stdcall; + + FreeImageIO = packed record + read_proc : FI_ReadProc; // pointer to the function used to read data + write_proc: FI_WriteProc; // pointer to the function used to write data + seek_proc : FI_SeekProc; // pointer to the function used to seek + tell_proc : FI_TellProc; // pointer to the function used to aquire the current position + end; + PFreeImageIO = ^FreeImageIO; + + // Handle to a memory I/O stream + FIMEMORY = record + data: Pointer; + end; + PFIMEMORY = ^FIMEMORY; + +const + // constants used in FreeImage_Seek for Origin parameter + SEEK_SET = 0; + SEEK_CUR = 1; + SEEK_END = 2; + +type + // define portable types for 32-bit / 64-bit OS + FIINT64 = Int64; + FIUINT64 = UInt64; + +// -------------------------------------------------------------------------- +// Plugin routines ---------------------------------------------------------- +// -------------------------------------------------------------------------- + +type + PPlugin = ^Plugin; + + FI_FormatProc = function: PAnsiChar; stdcall; + FI_DescriptionProc = function: PAnsiChar; stdcall; + FI_ExtensionListProc = function: PAnsiChar; stdcall; + FI_RegExprProc = function: PAnsiChar; stdcall; + FI_OpenProc = function(io: PFreeImageIO; handle: fi_handle; + read: LongBool): Pointer; stdcall; + FI_CloseProc = procedure(io: PFreeImageIO; handle: fi_handle; + data: Pointer); stdcall; + FI_PageCountProc = function(io: PFreeImageIO; handle: fi_handle; + data: Pointer): Integer; stdcall; + FI_PageCapabilityProc = function(io: PFreeImageIO; handle: fi_handle; + data: Pointer): Integer; stdcall; + FI_LoadProc = function(io: PFreeImageIO; handle: fi_handle; page, flags: Integer; + data: Pointer): PFIBITMAP; stdcall; + FI_SaveProc = function(io: PFreeImageIO; dib: PFIBITMAP; handle: fi_handle; + page, flags: Integer; data: Pointer): LongBool; stdcall; + FI_ValidateProc = function(io: PFreeImageIO; handle: fi_handle): LongBool; stdcall; + FI_MimeProc = function: PAnsiChar; stdcall; + FI_SupportsExportBPPProc = function(bpp: integer): LongBool; stdcall; + FI_SupportsExportTypeProc = function(atype: FREE_IMAGE_TYPE): LongBool; stdcall; + FI_SupportsICCProfilesProc = function: LongBool; stdcall; + FI_SupportsNoPixelsProc = function: LongBool; stdcall; + + Plugin = record + format_proc: FI_FormatProc; + description_proc: FI_DescriptionProc; + extension_proc: FI_ExtensionListProc; + regexpr_proc: FI_RegExprProc; + open_proc: FI_OpenProc; + close_proc: FI_CloseProc; + pagecount_proc: FI_PageCountProc; + pagecapability_proc: FI_PageCapabilityProc; + load_proc: FI_LoadProc; + save_proc: FI_SaveProc; + validate_proc: FI_ValidateProc; + mime_proc: FI_MimeProc; + supports_export_bpp_proc: FI_SupportsExportBPPProc; + supports_export_type_proc: FI_SupportsExportTypeProc; + supports_icc_profiles_proc: FI_SupportsICCProfilesProc; + supports_no_pixels_proc: FI_SupportsNoPixelsProc; + end; + + FI_InitProc = procedure(aplugin: PPlugin; format_id: Integer); stdcall; + +// -------------------------------------------------------------------------- +// Load/Save flag constants ------------------------------------------------- +// -------------------------------------------------------------------------- + +const + FIF_LOAD_NOPIXELS = $8000; // loading: load the image header only (not supported by all plugins) + BMP_DEFAULT = 0; + BMP_SAVE_RLE = 1; + CUT_DEFAULT = 0; + DDS_DEFAULT = 0; + EXR_DEFAULT = 0; // save data as half with piz-based wavelet compression + EXR_FLOAT = $0001; // save data as float instead of as half (not recommended) + EXR_NONE = $0002; // save with no compression + EXR_ZIP = $0004; // save with zlib compression, in blocks of 16 scan lines + EXR_PIZ = $0008; // save with piz-based wavelet compression + EXR_PXR24 = $0010; // save with lossy 24-bit float compression + EXR_B44 = $0020; // save with lossy 44% float compression - goes to 22% when combined with EXR_LC + EXR_LC = $0040; // save images with one luminance and two chroma channels, rather than as RGB (lossy compression) + FAXG3_DEFAULT = 0; + GIF_DEFAULT = 0; + GIF_LOAD256 = 1; // Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color + GIF_PLAYBACK = 2; // 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading + HDR_DEFAULT = 0; + ICO_DEFAULT = 0; + ICO_MAKEALPHA = 1; // convert to 32bpp and create an alpha channel from the AND-mask when loading + IFF_DEFAULT = 0; + J2K_DEFAULT = 0; // save with a 16:1 rate + JP2_DEFAULT = 0; // save with a 16:1 rate + JPEG_DEFAULT = 0; + JPEG_FAST = 1; + JPEG_ACCURATE = 2; + JPEG_CMYK = $0004; // load separated CMYK "as is" (use | to combine with other flags) + JPEG_EXIFROTATE = $0008; // load and rotate according to Exif 'Orientation' tag if available + JPEG_QUALITYSUPERB = $0080; // save with superb quality (100:1) + JPEG_QUALITYGOOD = $0100; // save with good quality (75:1) + JPEG_QUALITYNORMAL = $0200; // save with normal quality (50:1) + JPEG_QUALITYAVERAGE = $0400; // save with average quality (25:1) + JPEG_QUALITYBAD = $0800; // save with bad quality (10:1) + JPEG_PROGRESSIVE = $2000; // save as a progressive-JPEG (use | to combine with other save flags) + JPEG_SUBSAMPLING_411 = $1000; // save with high 4x1 chroma subsampling (4:1:1) + JPEG_SUBSAMPLING_420 = $4000; // save with medium 2x2 medium chroma subsampling (4:2:0) - default value + JPEG_SUBSAMPLING_422 = $8000; // save with low 2x1 chroma subsampling (4:2:2) + JPEG_SUBSAMPLING_444 = $10000; // save with no chroma subsampling (4:4:4) + JPEG_OPTIMIZE = $20000; // on saving, compute optimal Huffman coding tables (can reduce a few percent of file size) + JPEG_BASELINE = $40000; // save basic JPEG, without metadata or any markers + KOALA_DEFAULT = 0; + LBM_DEFAULT = 0; + MNG_DEFAULT = 0; + PCD_DEFAULT = 0; + PCD_BASE = 1; // load the bitmap sized 768 x 512 + PCD_BASEDIV4 = 2; // load the bitmap sized 384 x 256 + PCD_BASEDIV16 = 3; // load the bitmap sized 192 x 128 + PCX_DEFAULT = 0; + PFM_DEFAULT = 0; + PICT_DEFAULT = 0; + PNG_DEFAULT = 0; + PNG_IGNOREGAMMA = 1; // avoid gamma correction + PNG_Z_BEST_SPEED = $0001; // save using ZLib level 1 compression flag (default value is 6) + PNG_Z_DEFAULT_COMPRESSION = $0006; // save using ZLib level 6 compression flag (default recommended value) + PNG_Z_BEST_COMPRESSION = $0009; // save using ZLib level 9 compression flag (default value is 6) + PNG_Z_NO_COMPRESSION = $0100; // save without ZLib compression + PNG_INTERLACED = $0200; // save using Adam7 interlacing (use | to combine with other save flags) + PNM_DEFAULT = 0; + PNM_SAVE_RAW = 0; // If set the writer saves in RAW format (i.e. P4, P5 or P6) + PNM_SAVE_ASCII = 1; // If set the writer saves in ASCII format (i.e. P1, P2 or P3) + PSD_DEFAULT = 0; + PSD_CMYK = 1; // reads tags for separated CMYK (default is conversion to RGB) + PSD_LAB = 2; // reads tags for CIELab (default is conversion to RGB) + RAS_DEFAULT = 0; + RAW_DEFAULT = 0; // load the file as linear RGB 48-bit + RAW_PREVIEW = 1; // try to load the embedded JPEG preview with included Exif Data or default to RGB 24-bit + RAW_DISPLAY = 2; // load the file as RGB 24-bit + RAW_HALFSIZE = 4; // output a half-size color image + SGI_DEFAULT = 0; + TARGA_DEFAULT = 0; + TARGA_LOAD_RGB888 = 1; // If set the loader converts RGB555 and ARGB8888 -> RGB888. + TARGA_SAVE_RLE = 2; // If set, the writer saves with RLE compression + TIFF_DEFAULT = 0; + TIFF_CMYK = $0001; // reads/stores tags for separated CMYK (use | to combine with compression flags) + TIFF_PACKBITS = $0100; // save using PACKBITS compression + TIFF_DEFLATE = $0200; // save using DEFLATE compression + TIFF_ADOBE_DEFLATE = $0400; // save using ADOBE DEFLATE compression + TIFF_NONE = $0800; // save without any compression + TIFF_CCITTFAX3 = $1000; // save using CCITT Group 3 fax encoding + TIFF_CCITTFAX4 = $2000; // save using CCITT Group 4 fax encoding + TIFF_LZW = $4000; // save using LZW compression + TIFF_JPEG = $8000; // save using JPEG compression + TIFF_LOGLUV = $10000; // save using LogLuv compression + WBMP_DEFAULT = 0; + XBM_DEFAULT = 0; + XPM_DEFAULT = 0; + +// -------------------------------------------------------------------------- +// Background filling options ----------------------------------------------- +// Constants used in FreeImage_FillBackground and FreeImage_EnlargeCanvas +// -------------------------------------------------------------------------- + +const + FI_COLOR_IS_RGB_COLOR = $00; // RGBQUAD color is a RGB color (contains no valid alpha channel) + FI_COLOR_IS_RGBA_COLOR = $01; // RGBQUAD color is a RGBA color (contains a valid alpha channel) + FI_COLOR_FIND_EQUAL_COLOR = $02; // For palettized images: lookup equal RGB color from palette + FI_COLOR_ALPHA_IS_INDEX = $04; // The color's rgbReserved member (alpha) contains the palette index to be used + FI_COLOR_PALETTE_SEARCH_MASK = FI_COLOR_FIND_EQUAL_COLOR or FI_COLOR_ALPHA_IS_INDEX; // No color lookup is performed + +// -------------------------------------------------------------------------- +// Init/Error routines ------------------------------------------------------ +// -------------------------------------------------------------------------- + +procedure FreeImage_Initialise(load_local_plugins_only: LongBool = False); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_Initialise@4'{$ENDIF}; +procedure FreeImage_DeInitialise; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_DeInitialise@0'{$ENDIF}; + +// -------------------------------------------------------------------------- +// Version routines --------------------------------------------------------- +// -------------------------------------------------------------------------- + +function FreeImage_GetVersion: PAnsiChar; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetVersion@0'{$ENDIF}; +function FreeImage_GetCopyrightMessage: PAnsiChar; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetCopyrightMessage@0'{$ENDIF}; + +// -------------------------------------------------------------------------- +// Message output functions ------------------------------------------------- +// -------------------------------------------------------------------------- + +type + FreeImage_OutputMessageFunction = procedure(fif: FREE_IMAGE_FORMAT; + msg: PAnsiChar); cdecl; + FreeImage_OutputMessageFunctionStdCall = procedure(fif: FREE_IMAGE_FORMAT; + msg: PAnsiChar); stdcall; + +procedure FreeImage_SetOutputMessageStdCall(omf: FreeImage_OutputMessageFunctionStdCall); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetOutputMessageStdCall@4'{$ENDIF}; +procedure FreeImage_SetOutputMessage(omf: FreeImage_OutputMessageFunction); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetOutputMessage@4'{$ENDIF}; +{$IFDEF DELPHI6} +//this is declared stdcall in the C header but it is actually cdecl. +//with varargs functions, clearing the stack is caller's responsibility +//(since the callee doesn't know how many parameters were passed). +//cdecl is the right convention here, not stdcall +procedure FreeImage_OutputMessageProc(fif: Integer; fmt: PAnsiChar); cdecl; varargs; + external FIDLL {$IFDEF WIN32}name 'FreeImage_OutputMessageProc'{$ENDIF}; +{$ELSE} +//older Delphi versions (<6) do not support varargs. +//we provide a wrapper that uses open arrays instead +procedure FreeImage_OutputMessageProc(fif: Integer; fmt: PAnsiChar; args: array of const); +{$ENDIF} + +// -------------------------------------------------------------------------- +// Allocate / Clone / Unload routines --------------------------------------- +// -------------------------------------------------------------------------- + +function FreeImage_Allocate(width, height, bpp: Integer; red_mask: Cardinal = 0; + green_mask: Cardinal = 0; blue_mask: Cardinal = 0): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_Allocate@24'{$ENDIF}; +function FreeImage_AllocateT(atype: FREE_IMAGE_TYPE; width, height: Integer; + bpp: Integer = 8; red_mask: Cardinal = 0; green_mask: Cardinal = 0; + blue_mask: Cardinal = 0): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_AllocateT@28'{$ENDIF}; +function FreeImage_Clone(dib: PFIBITMAP): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_Clone@4'{$ENDIF}; +procedure FreeImage_Unload(dib: PFIBITMAP); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_Unload@4'{$ENDIF}; + +// -------------------------------------------------------------------------- +// Header loading routines +// -------------------------------------------------------------------------- +function FreeImage_HasPixels(dib: PFIBITMAP): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_HasPixels@4'{$ENDIF}; + +// -------------------------------------------------------------------------- +// Load / Save routines ----------------------------------------------------- +// -------------------------------------------------------------------------- + +function FreeImage_Load(fif: FREE_IMAGE_FORMAT; filename: PAnsiChar; + flags: Integer = 0): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_Load@12'{$ENDIF}; +function FreeImage_LoadU(fif: FREE_IMAGE_FORMAT; filename: PWideChar; + flags: Integer = 0): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_LoadU@12'{$ENDIF}; +function FreeImage_LoadFromHandle(fif: FREE_IMAGE_FORMAT; io: PFreeImageIO; + handle: fi_handle; flags: Integer = 0): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_LoadFromHandle@16'{$ENDIF}; +function FreeImage_Save(fif: FREE_IMAGE_FORMAT; dib: PFIBITMAP; filename: PAnsiChar; + flags: Integer = 0): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_Save@16'{$ENDIF}; +function FreeImage_SaveU(fif: FREE_IMAGE_FORMAT; dib: PFIBITMAP; filename: PWideChar; + flags: Integer = 0): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SaveU@16'{$ENDIF}; +function FreeImage_SaveToHandle(fif: FREE_IMAGE_FORMAT; dib: PFIBITMAP; + io: PFreeImageIO; handle: fi_handle; flags: Integer = 0): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SaveToHandle@20'{$ENDIF}; + +// -------------------------------------------------------------------------- +// Memory I/O stream routines ----------------------------------------------- +// -------------------------------------------------------------------------- + +function FreeImage_OpenMemory(data: PByte = nil; size_in_bytes: DWORD = 0): PFIMEMORY; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_OpenMemory@8'{$ENDIF}; +procedure FreeImage_CloseMemory(stream: PFIMEMORY); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_CloseMemory@4'{$ENDIF}; +function FreeImage_LoadFromMemory(fif: FREE_IMAGE_FORMAT; stream: PFIMEMORY; + flags: Integer = 0): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_LoadFromMemory@12'{$ENDIF}; +function FreeImage_SaveToMemory(fif: FREE_IMAGE_FORMAT; dib: PFIBITMAP; + stream: PFIMEMORY; flags: Integer = 0): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SaveToMemory@16'{$ENDIF}; +function FreeImage_TellMemory(stream: PFIMEMORY): LongInt; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_TellMemory@4'{$ENDIF}; +function FreeImage_SeekMemory(stream: PFIMEMORY; offset: LongInt; + origin: Integer): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SeekMemory@12'{$ENDIF}; +function FreeImage_AcquireMemory(stream: PFIMEMORY; var data: PByte; + var size_in_bytes: DWORD): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_AcquireMemory@12'{$ENDIF}; +function FreeImage_ReadMemory(buffer: Pointer; size, count: Cardinal; + stream: PFIMEMORY): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ReadMemory@16'{$ENDIF}; +function FreeImage_WriteMemory(buffer: Pointer; size, count: Cardinal; + stream: PFIMEMORY): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_WriteMemory@16'{$ENDIF}; +function FreeImage_LoadMultiBitmapFromMemory(fif: FREE_IMAGE_FORMAT; stream: PFIMEMORY; + flags: Integer = 0): PFIMULTIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_LoadMultiBitmapFromMemory@12'{$ENDIF}; +function FreeImage_SaveMultiBitmapToMemory(fif: FREE_IMAGE_FORMAT; bitmap: PFIMULTIBITMAP; + stream: PFIMEMORY; flags: Integer): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SaveMultiBitmapToMemory@16'{$ENDIF}; + +// -------------------------------------------------------------------------- +// Plugin Interface --------------------------------------------------------- +// -------------------------------------------------------------------------- + +function FreeImage_RegisterLocalPlugin(proc_address: FI_InitProc; format: PAnsiChar = nil; + description: PAnsiChar = nil; extension: PAnsiChar = nil; + regexpr: PAnsiChar = nil): FREE_IMAGE_FORMAT; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_RegisterLocalPlugin@20'{$ENDIF}; +function FreeImage_RegisterExternalPlugin(path: PAnsiChar; format: PAnsiChar = nil; + description: PAnsiChar = nil; extension: PAnsiChar = nil; + regexpr: PAnsiChar = nil): FREE_IMAGE_FORMAT; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_RegisterExternalPlugin@20'{$ENDIF}; +function FreeImage_GetFIFCount: Integer; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFCount@0'{$ENDIF}; +procedure FreeImage_SetPluginEnabled(fif: FREE_IMAGE_FORMAT; enable: LongBool); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetPluginEnabled@8'{$ENDIF}; +function FreeImage_IsPluginEnabled(fif: FREE_IMAGE_FORMAT): Integer; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_IsPluginEnabled@4'{$ENDIF}; +function FreeImage_GetFIFFromFormat(format: PAnsiChar): FREE_IMAGE_FORMAT; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFFromFormat@4'{$ENDIF}; +function FreeImage_GetFIFFromMime(mime: PAnsiChar): FREE_IMAGE_FORMAT; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFFromMime@4'{$ENDIF}; +function FreeImage_GetFormatFromFIF(fif: FREE_IMAGE_FORMAT): PAnsiChar; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFormatFromFIF@4'{$ENDIF}; +function FreeImage_GetFIFExtensionList(fif: FREE_IMAGE_FORMAT): PAnsiChar; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFExtensionList@4'{$ENDIF}; +function FreeImage_GetFIFDescription(fif: FREE_IMAGE_FORMAT): PAnsiChar; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFDescription@4'{$ENDIF}; +function FreeImage_GetFIFRegExpr(fif: FREE_IMAGE_FORMAT): PAnsiChar; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFRegExpr@4'{$ENDIF}; +function FreeImage_GetFIFMimeType(fif: FREE_IMAGE_FORMAT): PAnsiChar; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFMimeType@4'{$ENDIF}; +function FreeImage_GetFIFFromFilename(filename: PAnsiChar): FREE_IMAGE_FORMAT; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFFromFilename@4'{$ENDIF}; +function FreeImage_GetFIFFromFilenameU(filename: PWideChar): FREE_IMAGE_FORMAT; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFIFFromFilenameU@4'{$ENDIF}; +function FreeImage_FIFSupportsReading(fif: FREE_IMAGE_FORMAT): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_FIFSupportsReading@4'{$ENDIF}; +function FreeImage_FIFSupportsWriting(fif: FREE_IMAGE_FORMAT): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_FIFSupportsWriting@4'{$ENDIF}; +function FreeImage_FIFSupportsExportBPP(fif: FREE_IMAGE_FORMAT; + bpp: Integer): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_FIFSupportsExportBPP@8'{$ENDIF}; +function FreeImage_FIFSupportsExportType(fif: FREE_IMAGE_FORMAT; + atype: FREE_IMAGE_TYPE): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_FIFSupportsExportType@8'{$ENDIF}; +function FreeImage_FIFSupportsICCProfiles(fif: FREE_IMAGE_FORMAT): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_FIFSupportsICCProfiles@4'{$ENDIF}; +function FreeImage_FIFSupportsNoPixels(fif: FREE_IMAGE_FORMAT): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_FIFSupportsNoPixels@4'{$ENDIF}; + +// -------------------------------------------------------------------------- +// Multipaging interface ---------------------------------------------------- +// -------------------------------------------------------------------------- + +function FreeImage_OpenMultiBitmap(fif: FREE_IMAGE_FORMAT; filename: PAnsiChar; + create_new, read_only: LongBool; keep_cache_in_memory: LongBool = False; + flags: Integer = 0): PFIMULTIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_OpenMultiBitmap@24'{$ENDIF}; +function FreeImage_OpenMultiBitmapFromHandle(fif: FREE_IMAGE_FORMAT; io: PFreeImageIO; + handle: fi_handle; flags: Integer = 0): PFIMULTIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_OpenMultiBitmapFromHandle@16'{$ENDIF}; +function FreeImage_SaveMultiBitmapToHandle(fif: FREE_IMAGE_FORMAT; bitmap: PFIMULTIBITMAP; + io: PFreeImageIO; handle: fi_handle; flags: Integer = 0): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SaveMultiBitmapToHandle@20'{$ENDIF}; +function FreeImage_CloseMultiBitmap(bitmap: PFIMULTIBITMAP; + flags: Integer = 0): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_CloseMultiBitmap@8'{$ENDIF}; +function FreeImage_GetPageCount(bitmap: PFIMULTIBITMAP): Integer; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetPageCount@4'{$ENDIF}; +procedure FreeImage_AppendPage(bitmap: PFIMULTIBITMAP; data: PFIBITMAP); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_AppendPage@8'{$ENDIF}; +procedure FreeImage_InsertPage(bitmap: PFIMULTIBITMAP; page: Integer; + data: PFIBITMAP); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_InsertPage@12'{$ENDIF}; +procedure FreeImage_DeletePage(bitmap: PFIMULTIBITMAP; page: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_DeletePage@8'{$ENDIF}; +function FreeImage_LockPage(bitmap: PFIMULTIBITMAP; page: Integer): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_LockPage@8'{$ENDIF}; +procedure FreeImage_UnlockPage(bitmap: PFIMULTIBITMAP; data: PFIBITMAP; + changed: LongBool); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_UnlockPage@12'{$ENDIF}; +function FreeImage_MovePage(bitmap: PFIMULTIBITMAP; target, source: Integer): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_MovePage@12'{$ENDIF}; +function FreeImage_GetLockedPageNumbers(bitmap: PFIMULTIBITMAP; var pages: Integer; + var count: Integer): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetLockedPageNumbers@12'{$ENDIF}; + +// -------------------------------------------------------------------------- +// Filetype request routines ------------------------------------------------ +// -------------------------------------------------------------------------- + +function FreeImage_GetFileType(filename: PAnsiChar; + size: Integer = 0): FREE_IMAGE_FORMAT; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFileType@8'{$ENDIF}; +function FreeImage_GetFileTypeU(filename: PWideChar; + size: Integer = 0): FREE_IMAGE_FORMAT; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFileTypeU@8'{$ENDIF}; +function FreeImage_GetFileTypeFromHandle(io: PFreeImageIO; handle: FI_Handle; + size: Integer = 0): FREE_IMAGE_FORMAT; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFileTypeFromHandle@12'{$ENDIF}; +function FreeImage_GetFileTypeFromMemory(stream: PFIMEMORY; + size: Integer = 0): FREE_IMAGE_FORMAT; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetFileTypeFromMemory@8'{$ENDIF}; + +// -------------------------------------------------------------------------- +// ImageType request routine ------------------------------------------------ +// -------------------------------------------------------------------------- + +function FreeImage_GetImageType(dib: PFIBITMAP): FREE_IMAGE_TYPE; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetImageType@4'{$ENDIF}; + +// -------------------------------------------------------------------------- +// FreeImage helper routines ------------------------------------------------ +// -------------------------------------------------------------------------- + +function FreeImage_IsLittleEndian: LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_IsLittleEndian@0'{$ENDIF}; +function FreeImage_LookupX11Color(szColor: PAnsiChar; var nRed, nGreen, nBlue: Byte): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_LookupX11Color@16'{$ENDIF}; +function FreeImage_LookupSVGColor(szColor: PAnsiChar; var nRed, nGreen, nBlue: Byte): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_LookupSVGColor@16'{$ENDIF}; + +// -------------------------------------------------------------------------- +// Pixels access routines --------------------------------------------------- +// -------------------------------------------------------------------------- + +function FreeImage_GetBits(dib: PFIBITMAP): PByte; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetBits@4'{$ENDIF}; +function FreeImage_GetScanLine(dib: PFIBITMAP; scanline: Integer): PByte; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetScanLine@8'{$ENDIF}; + +function FreeImage_GetPixelIndex(dib: PFIBITMAP; x, y: Cardinal; var value: Byte): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetPixelIndex@16'{$ENDIF}; +function FreeImage_GetPixelColor(dib: PFIBITMAP; x, y: Cardinal; var value: RGBQUAD): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetPixelColor@16'{$ENDIF}; +function FreeImage_SetPixelIndex(dib: PFIBITMAP; x, y: Cardinal; var value: Byte): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetPixelIndex@16'{$ENDIF}; +function FreeImage_SetPixelColor(dib: PFIBITMAP; x, y: Cardinal; var value: RGBQUAD): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetPixelColor@16'{$ENDIF}; + +// -------------------------------------------------------------------------- +// DIB info routines -------------------------------------------------------- +// -------------------------------------------------------------------------- + +function FreeImage_GetColorsUsed(dib: PFIBITMAP): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetColorsUsed@4'{$ENDIF}; +function FreeImage_GetBPP(dib: PFIBITMAP): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetBPP@4'{$ENDIF}; +function FreeImage_GetWidth(dib: PFIBITMAP): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetWidth@4'{$ENDIF}; +function FreeImage_GetHeight(dib: PFIBITMAP): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetHeight@4'{$ENDIF}; +function FreeImage_GetLine(dib: PFIBITMAP): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetLine@4'{$ENDIF}; +function FreeImage_GetPitch(dib: PFIBITMAP): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetPitch@4'{$ENDIF}; +function FreeImage_GetDIBSize(dib: PFIBITMAP): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetDIBSize@4'{$ENDIF}; +function FreeImage_GetPalette(dib: PFIBITMAP): PRGBQuad; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetPalette@4'{$ENDIF}; + +function FreeImage_GetDotsPerMeterX(dib: PFIBITMAP): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetDotsPerMeterX@4'{$ENDIF}; +function FreeImage_GetDotsPerMeterY(dib: PFIBITMAP): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetDotsPerMeterY@4'{$ENDIF}; +procedure FreeImage_SetDotsPerMeterX(dib: PFIBITMAP; res: Cardinal); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetDotsPerMeterX@8'{$ENDIF}; +procedure FreeImage_SetDotsPerMeterY(dib: PFIBITMAP; res: Cardinal); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetDotsPerMeterY@8'{$ENDIF}; + +function FreeImage_GetInfoHeader(dib: PFIBITMAP): PBITMAPINFOHEADER; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetInfoHeader@4'{$ENDIF}; +function FreeImage_GetInfo(dib: PFIBITMAP): PBITMAPINFO; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetInfo@4'{$ENDIF}; +function FreeImage_GetColorType(dib: PFIBITMAP): FREE_IMAGE_COLOR_TYPE; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetColorType@4'{$ENDIF}; + +function FreeImage_GetRedMask(dib: PFIBITMAP): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetRedMask@4'{$ENDIF}; +function FreeImage_GetGreenMask(dib: PFIBITMAP): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetGreenMask@4'{$ENDIF}; +function FreeImage_GetBlueMask(dib: PFIBITMAP): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetBlueMask@4'{$ENDIF}; + +function FreeImage_GetTransparencyCount(dib: PFIBITMAP): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTransparencyCount@4'{$ENDIF}; +function FreeImage_GetTransparencyTable(dib: PFIBITMAP): PByte; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTransparencyTable@4'{$ENDIF}; +procedure FreeImage_SetTransparent(dib: PFIBITMAP; enabled: LongBool); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTransparent@8'{$ENDIF}; +procedure FreeImage_SetTransparencyTable(dib: PFIBITMAP; table: PByte; + count: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTransparencyTable@12'{$ENDIF}; +function FreeImage_IsTransparent(dib: PFIBITMAP): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_IsTransparent@4'{$ENDIF}; +procedure FreeImage_SetTransparentIndex(dib: PFIBITMAP; index: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTransparentIndex@8'{$ENDIF}; +function FreeImage_GetTransparentIndex(dib: PFIBITMAP): Integer; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTransparentIndex@4'{$ENDIF}; + +function FreeImage_HasBackgroundColor(dib: PFIBITMAP): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_HasBackgroundColor@4'{$ENDIF}; +function FreeImage_GetBackgroundColor(dib: PFIBITMAP; var bkcolor: RGBQUAD): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetBackgroundColor@8'{$ENDIF}; +function FreeImage_SetBackgroundColor(dib: PFIBITMAP; bkcolor: PRGBQuad): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetBackgroundColor@8'{$ENDIF}; + +function FreeImage_GetThumbnail(dib: PFIBITMAP): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetThumbnail@4'{$ENDIF}; +function FreeImage_SetThumbnail(dib, thumbnail: PFIBITMAP): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetThumbnail@8'{$ENDIF}; + +// -------------------------------------------------------------------------- +// ICC profile routines ----------------------------------------------------- +// -------------------------------------------------------------------------- + +function FreeImage_GetICCProfile(dib: PFIBITMAP): PFIICCPROFILE; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetICCProfile@4'{$ENDIF}; +function FreeImage_CreateICCProfile(dib: PFIBITMAP; data: Pointer; + size: LongInt): PFIICCPROFILE; stdcall; + external FIDLL {$IFDEF WIN32}name 'FreeImage_CreateICCProfile@12'{$ENDIF}; +procedure FreeImage_DestroyICCProfile(dib: PFIBITMAP); stdcall; + external FIDLL {$IFDEF WIN32}name 'FreeImage_DestroyICCProfile@4'{$ENDIF}; + +// -------------------------------------------------------------------------- +// Line conversion routines ------------------------------------------------- +// -------------------------------------------------------------------------- + +procedure FreeImage_ConvertLine1To4(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine1To4@12'{$ENDIF}; +procedure FreeImage_ConvertLine8To4(target, source: PByte; width_in_pixels: Integer; + palette: PRGBQuad); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine8To4@16'{$ENDIF}; +procedure FreeImage_ConvertLine16To4_555(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To4_555@12'{$ENDIF}; +procedure FreeImage_ConvertLine16To4_565(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To4_565@12'{$ENDIF}; +procedure FreeImage_ConvertLine24To4(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine24To4@12'{$ENDIF}; +procedure FreeImage_ConvertLine32To4(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine32To4@12'{$ENDIF}; + +procedure FreeImage_ConvertLine1To8(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine1To8@12'{$ENDIF}; +procedure FreeImage_ConvertLine4To8(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine4To8@12'{$ENDIF}; +procedure FreeImage_ConvertLine16To8_555(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To8_555@12'{$ENDIF}; +procedure FreeImage_ConvertLine16To8_565(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To8_565@12'{$ENDIF}; +procedure FreeImage_ConvertLine24To8(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine24To8@12'{$ENDIF}; +procedure FreeImage_ConvertLine32To8(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine32To8@12'{$ENDIF}; + +procedure FreeImage_ConvertLine1To16_555(target, source: PByte; width_in_pixels: Integer; + palette: PRGBQuad); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine1To16_555@16'{$ENDIF}; +procedure FreeImage_ConvertLine4To16_555(target, source: PByte; width_in_pixels: Integer; + palette: PRGBQuad); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine4To16_555@16'{$ENDIF}; +procedure FreeImage_ConvertLine8To16_555(target, source: PByte; width_in_pixels: Integer; + palette: PRGBQuad); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine8To16_555@16'{$ENDIF}; +procedure FreeImage_ConvertLine16_565_To16_555(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16_565_To16_555@12'{$ENDIF}; +procedure FreeImage_ConvertLine24To16_555(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine24To16_555@12'{$ENDIF}; +procedure FreeImage_ConvertLine32To16_555(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine32To16_555@12'{$ENDIF}; + +procedure FreeImage_ConvertLine1To16_565(target, source: PByte; width_in_pixels: Integer; + palette: PRGBQuad); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine1To16_565@16'{$ENDIF}; +procedure FreeImage_ConvertLine4To16_565(target, source: PByte; width_in_pixels: Integer; + palette: PRGBQuad); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine4To16_565@16'{$ENDIF}; +procedure FreeImage_ConvertLine8To16_565(target, source: PByte; width_in_pixels: Integer; + palette: PRGBQuad); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine8To16_565@16'{$ENDIF}; +procedure FreeImage_ConvertLine16_555_To16_565(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16_555_To16_565@12'{$ENDIF}; +procedure FreeImage_ConvertLine24To16_565(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine24To16_565@12'{$ENDIF}; +procedure FreeImage_ConvertLine32To16_565(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine32To16_565@12'{$ENDIF}; + +procedure FreeImage_ConvertLine1To24(target, source: PByte; width_in_pixels: Integer; + palette: PRGBQuad); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine1To24@16'{$ENDIF}; +procedure FreeImage_ConvertLine4To24(target, source: PByte; width_in_pixels: Integer; + palette: PRGBQuad); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine4To24@16'{$ENDIF}; +procedure FreeImage_ConvertLine8To24(target, source: PByte; width_in_pixels: Integer; + palette: PRGBQuad); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine8To24@16'{$ENDIF}; +procedure FreeImage_ConvertLine16To24_555(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To24_555@12'{$ENDIF}; +procedure FreeImage_ConvertLine16To24_565(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To24_565@12'{$ENDIF}; +procedure FreeImage_ConvertLine32To24(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine32To24@12'{$ENDIF}; + +procedure FreeImage_ConvertLine1To32(target, source: PByte; width_in_pixels: Integer; + palette: PRGBQuad); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine1To32@16'{$ENDIF}; +procedure FreeImage_ConvertLine4To32(target, source: PByte; width_in_pixels: Integer; + palette: PRGBQuad); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine4To32@16'{$ENDIF}; +procedure FreeImage_ConvertLine8To32(target, source: PByte; width_in_pixels: Integer; + palette: PRGBQuad); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine8To32@16'{$ENDIF}; +procedure FreeImage_ConvertLine16To32_555(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To32_555@12'{$ENDIF}; +procedure FreeImage_ConvertLine16To32_565(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine16To32_565@12'{$ENDIF}; +procedure FreeImage_ConvertLine24To32(target, source: PByte; width_in_pixels: Integer); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertLine24To32@12'{$ENDIF}; + +// -------------------------------------------------------------------------- +// Smart conversion routines ------------------------------------------------ +// -------------------------------------------------------------------------- + +function FreeImage_ConvertTo4Bits(dib: PFIBITMAP): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertTo4Bits@4'{$ENDIF}; +function FreeImage_ConvertTo8Bits(dib: PFIBITMAP): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertTo8Bits@4'{$ENDIF}; +function FreeImage_ConvertToGreyscale(dib: PFIBITMAP): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToGreyscale@4'{$ENDIF}; +function FreeImage_ConvertTo16Bits555(dib: PFIBITMAP): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertTo16Bits555@4'{$ENDIF}; +function FreeImage_ConvertTo16Bits565(dib: PFIBITMAP): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertTo16Bits565@4'{$ENDIF}; +function FreeImage_ConvertTo24Bits(dib: PFIBITMAP): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertTo24Bits@4'{$ENDIF}; +function FreeImage_ConvertTo32Bits(dib: PFIBITMAP): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertTo32Bits@4'{$ENDIF}; +function FreeImage_ColorQuantize(dib: PFIBITMAP; quantize: FREE_IMAGE_QUANTIZE): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ColorQuantize@8'{$ENDIF}; +function FreeImage_ColorQuantizeEx(dib: PFIBITMAP; quantize: FREE_IMAGE_QUANTIZE = FIQ_WUQUANT; + PaletteSize: Integer = 256; ReserveSize: Integer = 0; + ReservePalette: PRGBQuad = nil): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ColorQuantizeEx@20'{$ENDIF}; +function FreeImage_Threshold(dib: PFIBITMAP; T: Byte): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_Threshold@8'{$ENDIF}; +function FreeImage_Dither(dib: PFIBITMAP; algorithm: FREE_IMAGE_DITHER): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_Dither@8'{$ENDIF}; + +function FreeImage_ConvertFromRawBits(bits: PByte; width, height, pitch: Integer; + bpp, red_mask, green_mask, blue_mask: Cardinal; topdown: LongBool = False): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertFromRawBits@36'{$ENDIF}; +procedure FreeImage_ConvertToRawBits(bits: PByte; dib: PFIBITMAP; pitch: Integer; + bpp, red_mask, green_mask, blue_mask: Cardinal; topdown: LongBool = False); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToRawBits@32'{$ENDIF}; + +function FreeImage_ConvertToFloat(dib: PFIBITMAP): PFIBITMAP; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToFloat@4'{$ENDIF}; +function FreeImage_ConvertToRGBF(dib: PFIBITMAP): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToRGBF@4'{$ENDIF}; +function FreeImage_ConvertToUINT16(dib: PFIBITMAP): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToUINT16@4'{$ENDIF}; +function FreeImage_ConvertToRGB16(dib: PFIBITMAP): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToRGB16@4'{$ENDIF}; + +function FreeImage_ConvertToStandardType(src: PFIBITMAP; + scale_linear: LongBool = True): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToStandardType@8'{$ENDIF}; +function FreeImage_ConvertToType(src: PFIBITMAP; dst_type: FREE_IMAGE_TYPE; + scale_linear: LongBool = True): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ConvertToType@12'{$ENDIF}; + +// tone mapping operators +function FreeImage_ToneMapping(dib: PFIBITMAP; tmo: FREE_IMAGE_TMO; + first_param: Double = 0; second_param: Double = 0): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ToneMapping@24'{$ENDIF}; +function FreeImage_TmoDrago03(src: PFIBITMAP; gamma: Double = 2.2; + exposure: Double = 0): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_TmoDrago03@20'{$ENDIF}; +function FreeImage_TmoReinhard05(src: PFIBITMAP; intensity: Double = 0; + contrast: Double = 0): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_TmoReinhard05@20'{$ENDIF}; +function FreeImage_TmoReinhard05Ex(src: PFIBITMAP; intensity: Double = 0; + contrast: Double = 0; adaptation: Double = 1; color_correction: Double = 0): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_TmoReinhard05Ex@36'{$ENDIF}; + +function FreeImage_TmoFattal02(src: PFIBITMAP; color_saturation: Double = 0.5; + attenuation: Double = 0.85): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_TmoFattal02@20'{$ENDIF}; + +// -------------------------------------------------------------------------- +// ZLib interface ----------------------------------------------------------- +// -------------------------------------------------------------------------- + +function FreeImage_ZLibCompress(target: PByte; target_size: DWORD; source: PByte; source_size: DWORD): DWORD; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ZLibCompress@16'{$ENDIF}; +function FreeImage_ZLibUncompress(target: PByte; target_size: DWORD; source: PByte; source_size: DWORD): DWORD; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ZLibUncompress@16'{$ENDIF}; +function FreeImage_ZLibGZip(target: PByte; target_size: DWORD; source: PByte; source_size: DWORD): DWORD; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ZLibGZip@16'{$ENDIF}; +function FreeImage_ZLibGUnzip(target: PByte; target_size: DWORD; source: PByte; source_size: DWORD): DWORD; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ZLibGUnzip@16'{$ENDIF}; +function FreeImage_ZLibCRC32(crc: DWORD; source: PByte; source_size: DWORD): DWORD; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ZLibCRC32@12'{$ENDIF}; + +// -------------------------------------------------------------------------- +// Metadata routines -------------------------------------------------------- +// -------------------------------------------------------------------------- + +// tag creation / destruction +function FreeImage_CreateTag: PFITAG; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_CreateTag@0'{$ENDIF}; +procedure FreeImage_DeleteTag(tag: PFITAG); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_DeleteTag@4'{$ENDIF}; +function FreeImage_CloneTag(tag: PFITAG): PFITAG; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_CloneTag@4'{$ENDIF}; + +// tag getters and setters +function FreeImage_GetTagKey(tag: PFITAG): PAnsiChar; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTagKey@4'{$ENDIF}; +function FreeImage_GetTagDescription(tag: PFITAG): PAnsiChar; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTagDescription@4'{$ENDIF}; +function FreeImage_GetTagID(tag: PFITAG): Word; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTagID@4'{$ENDIF}; +function FreeImage_GetTagType(tag: PFITAG): FREE_IMAGE_MDTYPE; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTagType@4'{$ENDIF}; +function FreeImage_GetTagCount(tag: PFITAG): DWORD; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTagCount@4'{$ENDIF}; +function FreeImage_GetTagLength(tag: PFITAG): DWORD; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTagLength@4'{$ENDIF}; +function FreeImage_GetTagValue(tag: PFITAG): Pointer; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetTagValue@4'{$ENDIF}; + +function FreeImage_SetTagKey(tag: PFITAG; key: PAnsiChar): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTagKey@8'{$ENDIF}; +function FreeImage_SetTagDescription(tag: PFITAG; description: PAnsiChar): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTagDescription@8'{$ENDIF}; +function FreeImage_SetTagID(tag: PFITAG; id: Word): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTagID@8'{$ENDIF}; +function FreeImage_SetTagType(tag: PFITAG; atype: FREE_IMAGE_MDTYPE): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTagType@8'{$ENDIF}; +function FreeImage_SetTagCount(tag: PFITAG; count: DWORD): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTagCount@8'{$ENDIF}; +function FreeImage_SetTagLength(tag: PFITAG; length: DWORD): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTagLength@8'{$ENDIF}; +function FreeImage_SetTagValue(tag: PFITAG; value: Pointer): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetTagValue@8'{$ENDIF}; + +// iterator +function FreeImage_FindFirstMetadata(model: FREE_IMAGE_MDMODEL; dib: PFIBITMAP; + var tag: PFITAG): PFIMETADATA; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_FindFirstMetadata@12'{$ENDIF}; +function FreeImage_FindNextMetadata(mdhandle: PFIMETADATA; var tag: PFITAG): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_FindNextMetadata@8'{$ENDIF}; +procedure FreeImage_FindCloseMetadata(mdhandle: PFIMETADATA); stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_FindCloseMetadata@4'{$ENDIF}; + +// metadata setter and getter +function FreeImage_SetMetadata(model: FREE_IMAGE_MDMODEL; dib: PFIBITMAP; + key: PAnsiChar; tag: PFITAG): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetMetadata@16'{$ENDIF}; +function FreeImage_GetMetadata(model: FREE_IMAGE_MDMODEL; dib: PFIBITMAP; + key: PAnsiChar; var tag: PFITAG): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetMetadata@16'{$ENDIF}; + +// helpers +function FreeImage_GetMetadataCount(model: FREE_IMAGE_MDMODEL; dib: PFIBITMAP): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetMetadataCount@8'{$ENDIF}; +function FreeImage_CloneMetadata(dst, src: PFIBITMAP): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_CloneMetadata@8'{$ENDIF}; + +// tag to C string conversion +function FreeImage_TagToString(model: FREE_IMAGE_MDMODEL; tag: PFITAG; + Make: PAnsiChar = nil): PAnsiChar; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_TagToString@12'{$ENDIF}; + +// -------------------------------------------------------------------------- +// Image manipulation toolkit ----------------------------------------------- +// -------------------------------------------------------------------------- + +// rotation and flipping +// modif JMB : FreeImage_RotateClassic : deprecated function, call to DeprecationManager in 64 bits crashes freeimage.dll +//function FreeImage_RotateClassic(dib: PFIBITMAP; angle: Double): PFIBITMAP; stdcall; +// external FIDLL {$IFDEF WIN32}name '_FreeImage_RotateClassic@12'{$ENDIF}; +function FreeImage_Rotate(dib: PFIBITMAP; angle: Double; bkcolor: Pointer = nil): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_Rotate@16'{$ENDIF}; +function FreeImage_RotateEx(dib: PFIBITMAP; angle, x_shift, y_shift, x_origin, y_origin: Double; + use_mask: LongBool): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_RotateEx@48'{$ENDIF}; +function FreeImage_FlipHorizontal(dib: PFIBITMAP): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_FlipHorizontal@4'{$ENDIF}; +function FreeImage_FlipVertical(dib: PFIBITMAP): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_FlipVertical@4'{$ENDIF}; +function FreeImage_JPEGTransform(src_file, dst_file: PAnsiChar; operation: FREE_IMAGE_JPEG_OPERATION; + perfect: LongBool = False): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_JPEGTransform@16'{$ENDIF}; +function FreeImage_JPEGTransformU(src_file, dst_file: PWideChar; operation: FREE_IMAGE_JPEG_OPERATION; + perfect: LongBool = False): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_JPEGTransformU@16'{$ENDIF}; + +// upsampling / downsampling +function FreeImage_Rescale(dib: PFIBITMAP; dst_width, dst_height: Integer; filter: FREE_IMAGE_FILTER): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_Rescale@16'{$ENDIF}; +function FreeImage_MakeThumbnail(dib: PFIBITMAP; max_pixel_size: Integer; convert: LongBool = True): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_MakeThumbnail@12'{$ENDIF}; + +// color manipulation routines (point operations) +function FreeImage_AdjustCurve(dib: PFIBITMAP; LUT: PByte; + channel: FREE_IMAGE_COLOR_CHANNEL): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_AdjustCurve@12'{$ENDIF}; +function FreeImage_AdjustGamma(dib: PFIBITMAP; gamma: Double): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_AdjustGamma@12'{$ENDIF}; +function FreeImage_AdjustBrightness(dib: PFIBITMAP; percentage: Double): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_AdjustBrightness@12'{$ENDIF}; +function FreeImage_AdjustContrast(dib: PFIBITMAP; percentage: Double): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_AdjustContrast@12'{$ENDIF}; +function FreeImage_Invert(dib: PFIBITMAP): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_Invert@4'{$ENDIF}; +function FreeImage_GetHistogram(dib: PFIBITMAP; histo: PDWORD; + channel: FREE_IMAGE_COLOR_CHANNEL = FICC_BLACK): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetHistogram@12'{$ENDIF}; +function FreeImage_GetAdjustColorsLookupTable(LUT: PByte; brightness, contrast, gamma: Double; + invert: LongBool): Integer; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetAdjustColorsLookupTable@32'{$ENDIF}; +function FreeImage_AdjustColors(dib: PFIBITMAP; brightness, contrast, gamma: Double; + invert: LongBool = False): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_AdjustColors@32'{$ENDIF}; +function FreeImage_ApplyColorMapping(dib: PFIBITMAP; srccolors, dstcolors: PRGBQuad; + count: Cardinal; ignore_alpha, swap: LongBool): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ApplyColorMapping@24'{$ENDIF}; +function FreeImage_SwapColors(dib: PFIBITMAP; color_a, color_b: PRGBQuad; + ignore_alpha: LongBool): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SwapColors@16'{$ENDIF}; +function FreeImage_ApplyPaletteIndexMapping(dib: PFIBITMAP; srcindices, dstindices: PByte; + count: Cardinal; swap: LongBool): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_ApplyPaletteIndexMapping@20'{$ENDIF}; +function FreeImage_SwapPaletteIndices(dib: PFIBITMAP; index_a, index_b: PByte): Cardinal; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SwapPaletteIndices@12'{$ENDIF}; + +// channel processing routines +function FreeImage_GetChannel(dib: PFIBITMAP; channel: FREE_IMAGE_COLOR_CHANNEL): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetChannel@8'{$ENDIF}; +function FreeImage_SetChannel(dst, src: PFIBITMAP; channel: FREE_IMAGE_COLOR_CHANNEL): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetChannel@12'{$ENDIF}; +function FreeImage_GetComplexChannel(src: PFIBITMAP; channel: FREE_IMAGE_COLOR_CHANNEL): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_GetComplexChannel@8'{$ENDIF}; +function FreeImage_SetComplexChannel(dst, src: PFIBITMAP; channel: FREE_IMAGE_COLOR_CHANNEL): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_SetComplexChannel@12'{$ENDIF}; + +// copy / paste / composite routines + +function FreeImage_Copy(dib: PFIBITMAP; left, top, right, bottom: Integer): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_Copy@20'{$ENDIF}; +function FreeImage_Paste(dst, src: PFIBITMAP; left, top, alpha: Integer): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_Paste@20'{$ENDIF}; +function FreeImage_Composite(fg: PFIBITMAP; useFileBkg: LongBool = False; + appBkColor: PRGBQuad = nil; bg: PFIBITMAP = nil): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_Composite@16'{$ENDIF}; +function FreeImage_JPEGCrop(src_file, dst_file: PAnsiChar; + left, top, right, bottom: Integer): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_JPEGCrop@24'{$ENDIF}; +function FreeImage_JPEGCropU(src_file, dst_file: PWideChar; + left, top, right, bottom: Integer): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_JPEGCropU@24'{$ENDIF}; +function FreeImage_PreMultiplyWithAlpha(dib: PFIBITMAP): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_PreMultiplyWithAlpha@4'{$ENDIF}; + +// background filling routines +function FreeImage_FillBackground(dib: PFIBITMAP; color: Pointer; + options: Integer = 0): LongBool; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_FillBackground@12'{$ENDIF}; +function FreeImage_EnlargeCanvas(src: PFIBITMAP; left, top, right, bottom: Integer; + color: Pointer; options: Integer = 0): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_EnlargeCanvas@28'{$ENDIF}; +function FreeImage_AllocateEx(width, height, bpp: Integer; color: PRGBQuad; + options: Integer = 0; palette: PRGBQuad = nil; red_mask: Cardinal = 0; + green_mask: Cardinal = 0; blue_mask: Cardinal = 0): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_AllocateEx@36'{$ENDIF}; +function FreeImage_AllocateExT(atype: FREE_IMAGE_TYPE; width, height, bpp: Integer; + color: Pointer; options: Integer = 0; palette: PRGBQuad = nil; red_mask: Cardinal = 0; + green_mask: Cardinal = 0; blue_mask: Cardinal = 0): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_AllocateExT@40'{$ENDIF}; + +// miscellaneous algorithms +function FreeImage_MultigridPoissonSolver(Laplacian: PFIBITMAP; + ncycle: Integer = 3): PFIBITMAP; stdcall; + external FIDLL {$IFDEF WIN32}name '_FreeImage_MultigridPoissonSolver@8'{$ENDIF}; + + +implementation + +{$IFNDEF DELPHI6} +uses SysUtils; + +//we provide a wrapper since we haven't varargs in older versions of Delphi +procedure __FreeImage_OutputMessageProc; + external FIDLL name 'FreeImage_OutputMessageProc'; +procedure FreeImage_OutputMessageProc(fif: Integer; fmt: PAnsiChar; args: array of const); + function ArrayToBuffer(Args: array of const; + var Argv: Pointer; Buffer: Pointer; Size: Cardinal): Integer; + var + i: Integer; + temp: AnsiString; + parg: Pointer; + psrc, pbuf: PAnsiChar; + len: Cardinal; + begin + Result := High(Args) + 1; + if Result = 0 then + Exit; + //array of pointers to push on stack + GetMem(Argv, Result * SizeOf(Pointer)); + //pointer to current string in buffer + pbuf := Buffer; + //pointer to current arg + parg := Argv; + //for each const... + for i := 0 to Result - 1 do begin + case Args[i].VType of + vtInteger: begin + //integer + psrc := nil; + len := 0; + Integer(parg^) := Args[i].VInteger; + end; + vtString: begin + //short string + psrc := PAnsiChar(Cardinal(Args[i].VString) + SizeOf(Byte)); + len := PByte(Args[i].VString)^; + PAnsiChar(parg^) := pbuf; + end; + vtPChar: begin + //NULL terminated MBCS string + psrc := nil; + len := 0; + PAnsiChar(parg^) := Args[i].VPChar; + end; + vtPWideChar: begin + //NULL terminated Unicode string + temp := AnsiString(Args[i].VPWideChar); + psrc := PAnsiChar(temp); + len := Length(temp); + PAnsiChar(parg^) := pbuf; + end; + vtAnsiString: begin + //ANSI string + psrc := PAnsiChar(Args[i].VAnsiString); + len := StrLen(psrc); + PAnsiChar(parg^) := pbuf; + end; + vtWideString: begin + //Wide string (OLE) + temp := AnsiString(PWideChar(Args[i].VWideString)); + psrc := PAnsiChar(temp); + len := Length(temp); + PAnsiChar(parg^) := pbuf; + end; + else raise Exception.Create('Unsupported argument type'); + end; + if (psrc <> nil) and (len <> 0) then begin + //enough space to hold string? + if Size < (len + 1) then + raise Exception.Create('Buffer overflow'); + //copy string + Move(psrc^, pbuf^, len); + //NULL terminator + PAnsiChar(Cardinal(pbuf) + len)^ := #0; + //shift pointer... + Inc(pbuf, len + 1); + //...and decrease space left + Dec(Size, len + 1); + end; + Cardinal(parg) := Cardinal(parg) + SizeOf(Pointer); + end; + end; + + procedure DoVarargsCall(fif: Integer; fmt: PAnsiChar; Argv: Pointer; Argc: Integer); + { + fif -> EAX + fmt -> EDX + Argv -> ECX + Argc -> [EBP+$08] + } + asm + PUSH EAX //remember fif + PUSH ECX //make room for ESP backup + + MOV DWORD PTR [EBP-$08], ESP //backup stack pointer + + MOV EAX, DWORD PTR [EBP+$08] //store Argc + + TEST EAX, EAX //Argc <= 0? + JLE @Call + + @Loop: + PUSH DWORD PTR [ECX+EAX*$04-$04] //push Argv in right to left order + DEC EAX + JNZ @Loop + + @Call: + PUSH EDX //push fmt + PUSH DWORD PTR [EBP-$04] //push fif + CALL __FreeImage_OutputMessageProc + + MOV ESP, DWORD PTR [EBP-$08] //restore stack pointer + + POP ECX //clean stack + POP EAX + end; +var + Argc: Integer; + Argv: Pointer; + //buffer to hold strings - FreeImage allocates 512 bytes, we needn't more... + Buffer: array[1..512] of Byte; +begin + Argv := nil; + //build array of pointers from array of const + Argc := ArrayToBuffer(args, Argv, @Buffer, SizeOf(Buffer)); + try + //mimic cdecl call with varargs + DoVarargsCall(fif, fmt, Argv, Argc); + finally + //cleanup + FreeMem(Argv); + end; +end; +{$ENDIF} + +end. diff --git a/Wrapper/Delphi/src/FreeUtils.pas b/Wrapper/Delphi/src/FreeUtils.pas index 9665dca..126ab64 100644 --- a/Wrapper/Delphi/src/FreeUtils.pas +++ b/Wrapper/Delphi/src/FreeUtils.pas @@ -1,186 +1,186 @@ -unit FreeUtils; - -// ========================================================== -// -// Delphi wrapper for FreeImage 3 -// -// Design and implementation by -// - Anatoliy Pulyaevskiy (xvel84@rambler.ru) -// -// Contributors: -// - Enzo Costantini (enzocostantini@libero.it) -// - Armindo (tech1.yxendis@wanadoo.fr) -// - Lorenzo Monti (LM) lomo74@gmail.com -// -// Revision history -// When Who What -// ----------- ----- ----------------------------------------------------------- -// 2010-07-14 LM made RAD2010 compliant (unicode) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// -// ========================================================== - -interface - -{$I 'Version.inc'} - -uses - {$IFDEF DELPHI2010}AnsiStrings,{$ENDIF} SysUtils, Classes, FreeImage; - -function FIU_GetFIFType(filename: AnsiString): FREE_IMAGE_FORMAT; - -// returns FIF (plugin) description string -function FIU_GetFIFDescription(fif: FREE_IMAGE_FORMAT): AnsiString; - -procedure FIU_GetAllDescriptions(var Descriptions: TStringList); - -// returns file extentions for FIF (e.g. '*.tif;*.tiff) -function FIU_GetFIFExtList(fif: FREE_IMAGE_FORMAT): AnsiString; - -// returns file extentions for all plugins -function FIU_GetFullExtList: AnsiString; - -// returns "Description + | + ExtList" for specified FIF -function FIU_GetFIFFilter(fif: FREE_IMAGE_FORMAT): AnsiString; - -// All supported formats + Full filter list for FIFs -function FIU_GetAllFilters: AnsiString; - -//Filter for OpenDialogs -function FIU_GetAllOpenFilters: AnsiString; - -//Filter for SaveDialogs -function FIU_GetAllSaveFilters: AnsiString; - -implementation - -const - FIF_START = FIF_UNKNOWN; - FIF_END = FIF_XPM; - -function FIU_GetFIFType(filename: AnsiString): FREE_IMAGE_FORMAT; -begin - Result := FreeImage_GetFileType(PAnsiChar(filename), 0); -end; - -function FIU_GetFIFDescription(fif: FREE_IMAGE_FORMAT): AnsiString; -begin - Result := FreeImage_GetFIFDescription(fif) -end; - -procedure FIU_GetAllDescriptions(var Descriptions: TStringList); -var - fif: FREE_IMAGE_FORMAT; -begin - Descriptions.Clear; - for fif := FIF_START to FIF_END do - Descriptions.Add(string(FreeImage_GetFIFDescription(fif)) + ' (' + - string(FIu_GetFIFExtList(fif)) + ')'); -end; - -function FIU_GetFIFExtList(fif: FREE_IMAGE_FORMAT): AnsiString; -var - ExtList: AnsiString; - I: Smallint; - C: AnsiChar; -begin - Result := '*.'; - ExtList := FreeImage_GetFIFExtensionList(fif); - for I := 1 to Length(ExtList) do - begin - C := ExtList[i]; - if C <> ',' then - Result := Result + C - else - Result := Result + ';*.'; - end -end; - -function FIU_GetFullExtList: AnsiString; -var - fif: FREE_IMAGE_FORMAT; -begin - Result := FIU_GetFIFExtList(FIF_START); - for fif := FIF_START to FIF_END do - Result := Result + ';' + FIU_GetFIFExtList(fif) -end; - -function FIU_GetFIFFilter(fif: FREE_IMAGE_FORMAT): AnsiString; -var - Text, ExtList: AnsiString; -begin - Result := ''; - if fif <> FIF_UNKNOWN then - begin - Text := {$IFDEF DELPHI2010}AnsiStrings.{$ENDIF}Trim(FreeImage_GetFIFDescription(fif)); - ExtList := FIU_GetFIFExtList(fif); - Result := Text + '(' + ExtList + ')' + '|' + ExtList - end -end; - -function FIU_GetAllFilters: AnsiString; -var - fif: FREE_IMAGE_FORMAT; -begin - Result := 'All supported formats|' + FIU_GetFullExtList; - for fif := FIF_START to FIF_END do - begin - Result := Result + '|' + FIU_GetFIFFilter(fif) - end; -end; - -function FIU_GetAllOpenFilters: AnsiString; -var - fif: FREE_IMAGE_FORMAT; -begin - Result := 'All supported formats|' + FIU_GetFullExtList; - for fif := FIF_START to FIF_END do - if FreeImage_FIFSupportsReading(fif) then - begin - Result := Result + '|' + FIU_GetFIFFilter(fif) - end; -end; - -function FIU_GetAllSaveFilters: AnsiString; -var - ExtList: AnsiString; - I: Smallint; - C: AnsiChar; - fif: FREE_IMAGE_FORMAT; - s: AnsiString; -begin - result := ''; - for fif := FIF_START to FIF_END do - if FreeImage_FIFSupportsWriting(fif) then - begin - ExtList := FreeImage_GetFIFExtensionList(fif); - s := ''; - for I := 1 to Length(ExtList) do - begin - C := ExtList[i]; - if C <> ',' then - S := S + C - else - begin - result := Result + FreeImage_GetFIFDescription(fif) + ' (' + UpperCase(s) + ')|*.' + s + '|'; - s := ''; - end; - end; - result := Result + FreeImage_GetFIFDescription(fif) + ' (' + UpperCase(s) + ')|*.' + s + '|'; - end; -end; - -end. +unit FreeUtils; + +// ========================================================== +// +// Delphi wrapper for FreeImage 3 +// +// Design and implementation by +// - Anatoliy Pulyaevskiy (xvel84@rambler.ru) +// +// Contributors: +// - Enzo Costantini (enzocostantini@libero.it) +// - Armindo (tech1.yxendis@wanadoo.fr) +// - Lorenzo Monti (LM) lomo74@gmail.com +// +// Revision history +// When Who What +// ----------- ----- ----------------------------------------------------------- +// 2010-07-14 LM made RAD2010 compliant (unicode) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// +// ========================================================== + +interface + +{$I 'Version.inc'} + +uses + {$IFDEF DELPHI2010}AnsiStrings,{$ENDIF} SysUtils, Classes, FreeImage; + +function FIU_GetFIFType(filename: AnsiString): FREE_IMAGE_FORMAT; + +// returns FIF (plugin) description string +function FIU_GetFIFDescription(fif: FREE_IMAGE_FORMAT): AnsiString; + +procedure FIU_GetAllDescriptions(var Descriptions: TStringList); + +// returns file extentions for FIF (e.g. '*.tif;*.tiff) +function FIU_GetFIFExtList(fif: FREE_IMAGE_FORMAT): AnsiString; + +// returns file extentions for all plugins +function FIU_GetFullExtList: AnsiString; + +// returns "Description + | + ExtList" for specified FIF +function FIU_GetFIFFilter(fif: FREE_IMAGE_FORMAT): AnsiString; + +// All supported formats + Full filter list for FIFs +function FIU_GetAllFilters: AnsiString; + +//Filter for OpenDialogs +function FIU_GetAllOpenFilters: AnsiString; + +//Filter for SaveDialogs +function FIU_GetAllSaveFilters: AnsiString; + +implementation + +const + FIF_START = FIF_UNKNOWN; + FIF_END = FIF_XPM; + +function FIU_GetFIFType(filename: AnsiString): FREE_IMAGE_FORMAT; +begin + Result := FreeImage_GetFileType(PAnsiChar(filename), 0); +end; + +function FIU_GetFIFDescription(fif: FREE_IMAGE_FORMAT): AnsiString; +begin + Result := FreeImage_GetFIFDescription(fif) +end; + +procedure FIU_GetAllDescriptions(var Descriptions: TStringList); +var + fif: FREE_IMAGE_FORMAT; +begin + Descriptions.Clear; + for fif := FIF_START to FIF_END do + Descriptions.Add(string(FreeImage_GetFIFDescription(fif)) + ' (' + + string(FIu_GetFIFExtList(fif)) + ')'); +end; + +function FIU_GetFIFExtList(fif: FREE_IMAGE_FORMAT): AnsiString; +var + ExtList: AnsiString; + I: Smallint; + C: AnsiChar; +begin + Result := '*.'; + ExtList := FreeImage_GetFIFExtensionList(fif); + for I := 1 to Length(ExtList) do + begin + C := ExtList[i]; + if C <> ',' then + Result := Result + C + else + Result := Result + ';*.'; + end +end; + +function FIU_GetFullExtList: AnsiString; +var + fif: FREE_IMAGE_FORMAT; +begin + Result := FIU_GetFIFExtList(FIF_START); + for fif := FIF_START to FIF_END do + Result := Result + ';' + FIU_GetFIFExtList(fif) +end; + +function FIU_GetFIFFilter(fif: FREE_IMAGE_FORMAT): AnsiString; +var + Text, ExtList: AnsiString; +begin + Result := ''; + if fif <> FIF_UNKNOWN then + begin + Text := {$IFDEF DELPHI2010}AnsiStrings.{$ENDIF}Trim(FreeImage_GetFIFDescription(fif)); + ExtList := FIU_GetFIFExtList(fif); + Result := Text + '(' + ExtList + ')' + '|' + ExtList + end +end; + +function FIU_GetAllFilters: AnsiString; +var + fif: FREE_IMAGE_FORMAT; +begin + Result := 'All supported formats|' + FIU_GetFullExtList; + for fif := FIF_START to FIF_END do + begin + Result := Result + '|' + FIU_GetFIFFilter(fif) + end; +end; + +function FIU_GetAllOpenFilters: AnsiString; +var + fif: FREE_IMAGE_FORMAT; +begin + Result := 'All supported formats|' + FIU_GetFullExtList; + for fif := FIF_START to FIF_END do + if FreeImage_FIFSupportsReading(fif) then + begin + Result := Result + '|' + FIU_GetFIFFilter(fif) + end; +end; + +function FIU_GetAllSaveFilters: AnsiString; +var + ExtList: AnsiString; + I: Smallint; + C: AnsiChar; + fif: FREE_IMAGE_FORMAT; + s: AnsiString; +begin + result := ''; + for fif := FIF_START to FIF_END do + if FreeImage_FIFSupportsWriting(fif) then + begin + ExtList := FreeImage_GetFIFExtensionList(fif); + s := ''; + for I := 1 to Length(ExtList) do + begin + C := ExtList[i]; + if C <> ',' then + S := S + C + else + begin + result := Result + FreeImage_GetFIFDescription(fif) + ' (' + UpperCase(s) + ')|*.' + s + '|'; + s := ''; + end; + end; + result := Result + FreeImage_GetFIFDescription(fif) + ' (' + UpperCase(s) + ')|*.' + s + '|'; + end; +end; + +end. diff --git a/Wrapper/Delphi/src/Version.inc b/Wrapper/Delphi/src/Version.inc index 03f009f..f3fb445 100644 --- a/Wrapper/Delphi/src/Version.inc +++ b/Wrapper/Delphi/src/Version.inc @@ -1,205 +1,205 @@ -// ========================================================== -// Delphi wrapper for FreeImage 3 -// -// Design and implementation by -// - Simon Beavis -// - Peter Byström -// - Anatoliy Pulyaevskiy (xvel84@rambler.ru) -// -// Contributors: -// - Lorenzo Monti (LM) lomo74@gmail.com -// -// Revision history -// When Who What -// ----------- ----- ----------------------------------------------------------- -// 2010-07-29 LM Added Free Pascal / Lazarus 32 bit support -// 2010-11-12 LM Added Delphi XE support -// 2011-03-04 JMB Added 64 bit compiler support -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -//some older Delphi version will define WIN32 but not MSWINDOWS -{$IFNDEF MSWINDOWS} - {$IFDEF WIN32} - {$DEFINE MSWINDOWS} - {$ENDIF} -{$ENDIF} - -//test for compiler -{$IFDEF FPC} - //Free pascal - {$IFNDEF CPU32} - //{$ERROR "64 bit platforms not tested yet. Remove this line if you feel brave."} - {$ENDIF} - {$IFNDEF ENDIAN_LITTLE} - {$ERROR "Big endian CPUs not tested yet. Remove this line if you feel brave."} - {$ENDIF} - {$DEFINE DELPHI1} - {$DEFINE DELPHI2} - {$DEFINE DELPHI3} - {$DEFINE DELPHI4} - {$DEFINE DELPHI5} - {$DEFINE DELPHI6} - {$DEFINE DELPHI7} -{$ELSE} - //Delphi - {$IFDEF VER80} - {$DEFINE DELPHI1} - {$ENDIF} - - {$IFDEF VER90} - {$DEFINE DELPHI1} - {$DEFINE DELPHI2} - {$ENDIF} - - {$IFDEF VER100} - {$DEFINE DELPHI1} - {$DEFINE DELPHI2} - {$DEFINE DELPHI3} - {$ENDIF} - - {$IFDEF VER120} - {$DEFINE DELPHI1} - {$DEFINE DELPHI2} - {$DEFINE DELPHI3} - {$DEFINE DELPHI4} - {$ENDIF} - - {$IFDEF VER130} - {$DEFINE DELPHI1} - {$DEFINE DELPHI2} - {$DEFINE DELPHI3} - {$DEFINE DELPHI4} - {$DEFINE DELPHI5} - {$ENDIF} - - {$IFDEF VER140} - {$DEFINE DELPHI1} - {$DEFINE DELPHI2} - {$DEFINE DELPHI3} - {$DEFINE DELPHI4} - {$DEFINE DELPHI5} - {$DEFINE DELPHI6} - {$ENDIF} - - {$IFDEF VER150} - {$DEFINE DELPHI1} - {$DEFINE DELPHI2} - {$DEFINE DELPHI3} - {$DEFINE DELPHI4} - {$DEFINE DELPHI5} - {$DEFINE DELPHI6} - {$DEFINE DELPHI7} - {$ENDIF} - - {$IFDEF VER160} - {$DEFINE DELPHI1} - {$DEFINE DELPHI2} - {$DEFINE DELPHI3} - {$DEFINE DELPHI4} - {$DEFINE DELPHI5} - {$DEFINE DELPHI6} - {$DEFINE DELPHI7} - {$DEFINE DELPHI8} - {$ENDIF} - - {$IFDEF VER170} - {$DEFINE DELPHI1} - {$DEFINE DELPHI2} - {$DEFINE DELPHI3} - {$DEFINE DELPHI4} - {$DEFINE DELPHI5} - {$DEFINE DELPHI6} - {$DEFINE DELPHI7} - {$DEFINE DELPHI8} - {$DEFINE DELPHI2005} - {$ENDIF} - - {$IFDEF VER180} - {$DEFINE DELPHI1} - {$DEFINE DELPHI2} - {$DEFINE DELPHI3} - {$DEFINE DELPHI4} - {$DEFINE DELPHI5} - {$DEFINE DELPHI6} - {$DEFINE DELPHI7} - {$DEFINE DELPHI8} - {$DEFINE DELPHI2005} - {$DEFINE DELPHI2006} - {$ENDIF} - - {$IFDEF VER185} - {$DEFINE DELPHI1} - {$DEFINE DELPHI2} - {$DEFINE DELPHI3} - {$DEFINE DELPHI4} - {$DEFINE DELPHI5} - {$DEFINE DELPHI6} - {$DEFINE DELPHI7} - {$DEFINE DELPHI8} - {$DEFINE DELPHI2005} - {$DEFINE DELPHI2006} - {$DEFINE DELPHI2007} - {$ENDIF} - - {$IFDEF VER200} - {$DEFINE DELPHI1} - {$DEFINE DELPHI2} - {$DEFINE DELPHI3} - {$DEFINE DELPHI4} - {$DEFINE DELPHI5} - {$DEFINE DELPHI6} - {$DEFINE DELPHI7} - {$DEFINE DELPHI8} - {$DEFINE DELPHI2005} - {$DEFINE DELPHI2006} - {$DEFINE DELPHI2007} - {$DEFINE DELPHI2009} - {$ENDIF} - - {$IFDEF VER210} - {$DEFINE DELPHI1} - {$DEFINE DELPHI2} - {$DEFINE DELPHI3} - {$DEFINE DELPHI4} - {$DEFINE DELPHI5} - {$DEFINE DELPHI6} - {$DEFINE DELPHI7} - {$DEFINE DELPHI8} - {$DEFINE DELPHI2005} - {$DEFINE DELPHI2006} - {$DEFINE DELPHI2007} - {$DEFINE DELPHI2009} - {$DEFINE DELPHI2010} - {$ENDIF} - - {$IFDEF VER220} - {$DEFINE DELPHI1} - {$DEFINE DELPHI2} - {$DEFINE DELPHI3} - {$DEFINE DELPHI4} - {$DEFINE DELPHI5} - {$DEFINE DELPHI6} - {$DEFINE DELPHI7} - {$DEFINE DELPHI8} - {$DEFINE DELPHI2005} - {$DEFINE DELPHI2006} - {$DEFINE DELPHI2007} - {$DEFINE DELPHI2009} - {$DEFINE DELPHI2010} - {$DEFINE DELPHIXE} - {$ENDIF} -{$ENDIF} +// ========================================================== +// Delphi wrapper for FreeImage 3 +// +// Design and implementation by +// - Simon Beavis +// - Peter Byström +// - Anatoliy Pulyaevskiy (xvel84@rambler.ru) +// +// Contributors: +// - Lorenzo Monti (LM) lomo74@gmail.com +// +// Revision history +// When Who What +// ----------- ----- ----------------------------------------------------------- +// 2010-07-29 LM Added Free Pascal / Lazarus 32 bit support +// 2010-11-12 LM Added Delphi XE support +// 2011-03-04 JMB Added 64 bit compiler support +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +//some older Delphi version will define WIN32 but not MSWINDOWS +{$IFNDEF MSWINDOWS} + {$IFDEF WIN32} + {$DEFINE MSWINDOWS} + {$ENDIF} +{$ENDIF} + +//test for compiler +{$IFDEF FPC} + //Free pascal + {$IFNDEF CPU32} + //{$ERROR "64 bit platforms not tested yet. Remove this line if you feel brave."} + {$ENDIF} + {$IFNDEF ENDIAN_LITTLE} + {$ERROR "Big endian CPUs not tested yet. Remove this line if you feel brave."} + {$ENDIF} + {$DEFINE DELPHI1} + {$DEFINE DELPHI2} + {$DEFINE DELPHI3} + {$DEFINE DELPHI4} + {$DEFINE DELPHI5} + {$DEFINE DELPHI6} + {$DEFINE DELPHI7} +{$ELSE} + //Delphi + {$IFDEF VER80} + {$DEFINE DELPHI1} + {$ENDIF} + + {$IFDEF VER90} + {$DEFINE DELPHI1} + {$DEFINE DELPHI2} + {$ENDIF} + + {$IFDEF VER100} + {$DEFINE DELPHI1} + {$DEFINE DELPHI2} + {$DEFINE DELPHI3} + {$ENDIF} + + {$IFDEF VER120} + {$DEFINE DELPHI1} + {$DEFINE DELPHI2} + {$DEFINE DELPHI3} + {$DEFINE DELPHI4} + {$ENDIF} + + {$IFDEF VER130} + {$DEFINE DELPHI1} + {$DEFINE DELPHI2} + {$DEFINE DELPHI3} + {$DEFINE DELPHI4} + {$DEFINE DELPHI5} + {$ENDIF} + + {$IFDEF VER140} + {$DEFINE DELPHI1} + {$DEFINE DELPHI2} + {$DEFINE DELPHI3} + {$DEFINE DELPHI4} + {$DEFINE DELPHI5} + {$DEFINE DELPHI6} + {$ENDIF} + + {$IFDEF VER150} + {$DEFINE DELPHI1} + {$DEFINE DELPHI2} + {$DEFINE DELPHI3} + {$DEFINE DELPHI4} + {$DEFINE DELPHI5} + {$DEFINE DELPHI6} + {$DEFINE DELPHI7} + {$ENDIF} + + {$IFDEF VER160} + {$DEFINE DELPHI1} + {$DEFINE DELPHI2} + {$DEFINE DELPHI3} + {$DEFINE DELPHI4} + {$DEFINE DELPHI5} + {$DEFINE DELPHI6} + {$DEFINE DELPHI7} + {$DEFINE DELPHI8} + {$ENDIF} + + {$IFDEF VER170} + {$DEFINE DELPHI1} + {$DEFINE DELPHI2} + {$DEFINE DELPHI3} + {$DEFINE DELPHI4} + {$DEFINE DELPHI5} + {$DEFINE DELPHI6} + {$DEFINE DELPHI7} + {$DEFINE DELPHI8} + {$DEFINE DELPHI2005} + {$ENDIF} + + {$IFDEF VER180} + {$DEFINE DELPHI1} + {$DEFINE DELPHI2} + {$DEFINE DELPHI3} + {$DEFINE DELPHI4} + {$DEFINE DELPHI5} + {$DEFINE DELPHI6} + {$DEFINE DELPHI7} + {$DEFINE DELPHI8} + {$DEFINE DELPHI2005} + {$DEFINE DELPHI2006} + {$ENDIF} + + {$IFDEF VER185} + {$DEFINE DELPHI1} + {$DEFINE DELPHI2} + {$DEFINE DELPHI3} + {$DEFINE DELPHI4} + {$DEFINE DELPHI5} + {$DEFINE DELPHI6} + {$DEFINE DELPHI7} + {$DEFINE DELPHI8} + {$DEFINE DELPHI2005} + {$DEFINE DELPHI2006} + {$DEFINE DELPHI2007} + {$ENDIF} + + {$IFDEF VER200} + {$DEFINE DELPHI1} + {$DEFINE DELPHI2} + {$DEFINE DELPHI3} + {$DEFINE DELPHI4} + {$DEFINE DELPHI5} + {$DEFINE DELPHI6} + {$DEFINE DELPHI7} + {$DEFINE DELPHI8} + {$DEFINE DELPHI2005} + {$DEFINE DELPHI2006} + {$DEFINE DELPHI2007} + {$DEFINE DELPHI2009} + {$ENDIF} + + {$IFDEF VER210} + {$DEFINE DELPHI1} + {$DEFINE DELPHI2} + {$DEFINE DELPHI3} + {$DEFINE DELPHI4} + {$DEFINE DELPHI5} + {$DEFINE DELPHI6} + {$DEFINE DELPHI7} + {$DEFINE DELPHI8} + {$DEFINE DELPHI2005} + {$DEFINE DELPHI2006} + {$DEFINE DELPHI2007} + {$DEFINE DELPHI2009} + {$DEFINE DELPHI2010} + {$ENDIF} + + {$IFDEF VER220} + {$DEFINE DELPHI1} + {$DEFINE DELPHI2} + {$DEFINE DELPHI3} + {$DEFINE DELPHI4} + {$DEFINE DELPHI5} + {$DEFINE DELPHI6} + {$DEFINE DELPHI7} + {$DEFINE DELPHI8} + {$DEFINE DELPHI2005} + {$DEFINE DELPHI2006} + {$DEFINE DELPHI2007} + {$DEFINE DELPHI2009} + {$DEFINE DELPHI2010} + {$DEFINE DELPHIXE} + {$ENDIF} +{$ENDIF} diff --git a/Wrapper/FreeImage.NET/cpp/FreeImageIO/AssemblyInfo.cpp b/Wrapper/FreeImage.NET/cpp/FreeImageIO/AssemblyInfo.cpp index 2c401db..e550a32 100644 --- a/Wrapper/FreeImage.NET/cpp/FreeImageIO/AssemblyInfo.cpp +++ b/Wrapper/FreeImage.NET/cpp/FreeImageIO/AssemblyInfo.cpp @@ -1,58 +1,58 @@ -#include "stdafx.h" - -using namespace System::Reflection; -using namespace System::Runtime::CompilerServices; - -// -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -// -[assembly:AssemblyTitleAttribute("")]; -[assembly:AssemblyDescriptionAttribute("")]; -[assembly:AssemblyConfigurationAttribute("")]; -[assembly:AssemblyCompanyAttribute("")]; -[assembly:AssemblyProductAttribute("")]; -[assembly:AssemblyCopyrightAttribute("")]; -[assembly:AssemblyTrademarkAttribute("")]; -[assembly:AssemblyCultureAttribute("")]; - -// -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the value or you can default the Revision and Build Numbers -// by using the '*' as shown below: - -[assembly:AssemblyVersionAttribute("1.0.*")]; - -// -// In order to sign your assembly you must specify a key to use. Refer to the -// Microsoft .NET Framework documentation for more information on assembly signing. -// -// Use the attributes below to control which key is used for signing. -// -// Notes: -// (*) If no key is specified, the assembly is not signed. -// (*) KeyName refers to a key that has been installed in the Crypto Service -// Provider (CSP) on your machine. KeyFile refers to a file which contains -// a key. -// (*) If the KeyFile and the KeyName values are both specified, the -// following processing occurs: -// (1) If the KeyName can be found in the CSP, that key is used. -// (2) If the KeyName does not exist and the KeyFile does exist, the key -// in the KeyFile is installed into the CSP and used. -// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. -// When specifying the KeyFile, the location of the KeyFile should be -// relative to the project directory. -// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework -// documentation for more information on this. -// -[assembly:AssemblyDelaySignAttribute(false)]; -[assembly:AssemblyKeyFileAttribute("")]; -[assembly:AssemblyKeyNameAttribute("")]; - +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("")]; +[assembly:AssemblyProductAttribute("")]; +[assembly:AssemblyCopyrightAttribute("")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project directory. +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly:AssemblyDelaySignAttribute(false)]; +[assembly:AssemblyKeyFileAttribute("")]; +[assembly:AssemblyKeyNameAttribute("")]; + diff --git a/Wrapper/FreeImage.NET/cpp/FreeImageIO/FreeImageIO.Net.cpp b/Wrapper/FreeImage.NET/cpp/FreeImageIO/FreeImageIO.Net.cpp index cbc88b7..c60ee8a 100644 --- a/Wrapper/FreeImage.NET/cpp/FreeImageIO/FreeImageIO.Net.cpp +++ b/Wrapper/FreeImage.NET/cpp/FreeImageIO/FreeImageIO.Net.cpp @@ -1,69 +1,69 @@ -// ========================================================== -// FreeImageIO.Net -// -// Design and implementation by -// - Marcos Pernambuco Motta (marcos.pernambuco@gmail.com) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "stdafx.h" -#include "FreeImageIO.Net.h" - - -extern "C" static unsigned __stdcall ReadProc (void *buffer, unsigned size, unsigned count, fi_handle handle) -{ - int total_read = 0; - struct UNMANAGED_HANDLER* puh = (struct UNMANAGED_HANDLER*)handle; - gcroot mbuffer = new unsigned char __gc[size]; - try - { - total_read = puh->_stream->Read(mbuffer,0,size); - Marshal::Copy(mbuffer,0,buffer,total_read); - } __finally { - mbuffer=NULL; - } - return (unsigned)total_read; -} - -extern "C" static unsigned __stdcall WriteProc (void *buffer, unsigned size, unsigned count, fi_handle handle) -{ - struct UNMANAGED_HANDLER* puh = (struct UNMANAGED_HANDLER*)handle; - gcroot mbuffer = new unsigned char __gc[size*count]; - try - { - - unsigned char __pin* pbuffer = &mbuffer[0]; - memcpy(pbuffer,buffer,size*count); - puh->_stream->Write(mbuffer,0,size); - } __finally { - mbuffer=NULL; - } - return count; -} - -extern "C" static int __stdcall SeekProc (fi_handle handle, long offset, int origin) -{ - struct UNMANAGED_HANDLER* puh = (struct UNMANAGED_HANDLER*)handle; - return (int)puh->_stream->Seek(offset,(SeekOrigin) origin); - -} - -extern "C" static long __stdcall TellProc(fi_handle handle) -{ - struct UNMANAGED_HANDLER* puh = (struct UNMANAGED_HANDLER*)handle; - return (long)puh->_stream->Position; -} - +// ========================================================== +// FreeImageIO.Net +// +// Design and implementation by +// - Marcos Pernambuco Motta (marcos.pernambuco@gmail.com) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "stdafx.h" +#include "FreeImageIO.Net.h" + + +extern "C" static unsigned __stdcall ReadProc (void *buffer, unsigned size, unsigned count, fi_handle handle) +{ + int total_read = 0; + struct UNMANAGED_HANDLER* puh = (struct UNMANAGED_HANDLER*)handle; + gcroot mbuffer = new unsigned char __gc[size]; + try + { + total_read = puh->_stream->Read(mbuffer,0,size); + Marshal::Copy(mbuffer,0,buffer,total_read); + } __finally { + mbuffer=NULL; + } + return (unsigned)total_read; +} + +extern "C" static unsigned __stdcall WriteProc (void *buffer, unsigned size, unsigned count, fi_handle handle) +{ + struct UNMANAGED_HANDLER* puh = (struct UNMANAGED_HANDLER*)handle; + gcroot mbuffer = new unsigned char __gc[size*count]; + try + { + + unsigned char __pin* pbuffer = &mbuffer[0]; + memcpy(pbuffer,buffer,size*count); + puh->_stream->Write(mbuffer,0,size); + } __finally { + mbuffer=NULL; + } + return count; +} + +extern "C" static int __stdcall SeekProc (fi_handle handle, long offset, int origin) +{ + struct UNMANAGED_HANDLER* puh = (struct UNMANAGED_HANDLER*)handle; + return (int)puh->_stream->Seek(offset,(SeekOrigin) origin); + +} + +extern "C" static long __stdcall TellProc(fi_handle handle) +{ + struct UNMANAGED_HANDLER* puh = (struct UNMANAGED_HANDLER*)handle; + return (long)puh->_stream->Position; +} + diff --git a/Wrapper/FreeImage.NET/cpp/FreeImageIO/ReadMe.txt b/Wrapper/FreeImage.NET/cpp/FreeImageIO/ReadMe.txt index 8412e57..f0d15f3 100644 --- a/Wrapper/FreeImage.NET/cpp/FreeImageIO/ReadMe.txt +++ b/Wrapper/FreeImage.NET/cpp/FreeImageIO/ReadMe.txt @@ -1,27 +1,27 @@ -======================================================================== -FreeImageIO.Net - -Author: Marcos Pernambuco Motta (marcos.pernambuco@gmail.com) -======================================================================== - -This library allows programs that use FreeImage.Net to save images to or -to load images from .Net Streams. - -The class FreeImageStream implements a FreeImageIO handler and routes -IO calls (read,write,tell and seek) to a wrapped System.IO.Stream. - -Example: - -using FreeImageAPI; -using FreeImageIODotNet; - -uint dib = FreeImageAPI.FreeImage.Allocate(width,height,32,0,0,0); - -// ... Image handling code goes here - -System.IO.FileStream stream = new System.IO.FileStream(@"c:\sample.png",System.IO.FileMode.Create); -FreeImageStream imageStream = new FreeImageStream(stream); -imageStream.SaveImage((int)FREE_IMAGE_FORMAT.FIF_PNG,dib,0); -stream.Close(); - -Compile with VS2003. +======================================================================== +FreeImageIO.Net + +Author: Marcos Pernambuco Motta (marcos.pernambuco@gmail.com) +======================================================================== + +This library allows programs that use FreeImage.Net to save images to or +to load images from .Net Streams. + +The class FreeImageStream implements a FreeImageIO handler and routes +IO calls (read,write,tell and seek) to a wrapped System.IO.Stream. + +Example: + +using FreeImageAPI; +using FreeImageIODotNet; + +uint dib = FreeImageAPI.FreeImage.Allocate(width,height,32,0,0,0); + +// ... Image handling code goes here + +System.IO.FileStream stream = new System.IO.FileStream(@"c:\sample.png",System.IO.FileMode.Create); +FreeImageStream imageStream = new FreeImageStream(stream); +imageStream.SaveImage((int)FREE_IMAGE_FORMAT.FIF_PNG,dib,0); +stream.Close(); + +Compile with VS2003. diff --git a/Wrapper/FreeImage.NET/cpp/FreeImageIO/Stdafx.cpp b/Wrapper/FreeImage.NET/cpp/FreeImageIO/Stdafx.cpp index 4f8b8cf..0260fa9 100644 --- a/Wrapper/FreeImage.NET/cpp/FreeImageIO/Stdafx.cpp +++ b/Wrapper/FreeImage.NET/cpp/FreeImageIO/Stdafx.cpp @@ -1,5 +1,5 @@ -// stdafx.cpp : source file that includes just the standard includes -// FreeImageIO.Net.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" +// stdafx.cpp : source file that includes just the standard includes +// FreeImageIO.Net.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" diff --git a/Wrapper/FreeImage.NET/cs/Bin/delete.me b/Wrapper/FreeImage.NET/cs/Bin/delete.me index ee53b98..81cd34c 100644 --- a/Wrapper/FreeImage.NET/cs/Bin/delete.me +++ b/Wrapper/FreeImage.NET/cs/Bin/delete.me @@ -1 +1 @@ -You may safely delete this file. +You may safely delete this file. diff --git a/Wrapper/FreeImage.NET/cs/Content.txt b/Wrapper/FreeImage.NET/cs/Content.txt index 9d17916..910206e 100644 --- a/Wrapper/FreeImage.NET/cs/Content.txt +++ b/Wrapper/FreeImage.NET/cs/Content.txt @@ -1,43 +1,43 @@ - -This file gives you a short description of the .NET wrapper's folders -and what's located in them. - - -"Doc" -Sandcastle Help File Builder project file for creating a Microsoft Help API -documentation (CHM file). -FreeImage.NET uses Eric Woodruff's Sandcastle Help File Builder GUI to -generate the API documentation. See http://www.codeplex.com/SHFB - -"Library" -Source code of the C# .NET wrapper. Builds the FreeImageNET.dll. - -"Samples" -Example projects showing how to use the wrapper. - -"SourceFileMerger" -Program to merge all the wrapper's source files into a single source file -for easy integration into your projects on source code basis. - -"UnitTest" -NUnit-based test project for the .NET wrapper. NUnit needs to be installed -for this project to work. - -"UnitTestData" (not in CVS) -Several images in each available color depth used by "UnitTest". - -"clear.bat" -Batch file to clear the whole project, removing all temporary files. - -"FreeImage.chm" (not in CVS) -The .NET wrapper's API documentation. Build with Microsoft's Sandcastle -project from C# source code documentation. - -"FreeImage.NET.nunit" -NUnit project file. NUnit needs to be installed for this project to work. - -"FreeImage.NET.sln" -The Microsoft Visual Studio 2005 solution file. - -"Whats_New.NET.txt" + +This file gives you a short description of the .NET wrapper's folders +and what's located in them. + + +"Doc" +Sandcastle Help File Builder project file for creating a Microsoft Help API +documentation (CHM file). +FreeImage.NET uses Eric Woodruff's Sandcastle Help File Builder GUI to +generate the API documentation. See http://www.codeplex.com/SHFB + +"Library" +Source code of the C# .NET wrapper. Builds the FreeImageNET.dll. + +"Samples" +Example projects showing how to use the wrapper. + +"SourceFileMerger" +Program to merge all the wrapper's source files into a single source file +for easy integration into your projects on source code basis. + +"UnitTest" +NUnit-based test project for the .NET wrapper. NUnit needs to be installed +for this project to work. + +"UnitTestData" (not in CVS) +Several images in each available color depth used by "UnitTest". + +"clear.bat" +Batch file to clear the whole project, removing all temporary files. + +"FreeImage.chm" (not in CVS) +The .NET wrapper's API documentation. Build with Microsoft's Sandcastle +project from C# source code documentation. + +"FreeImage.NET.nunit" +NUnit project file. NUnit needs to be installed for this project to work. + +"FreeImage.NET.sln" +The Microsoft Visual Studio 2005 solution file. + +"Whats_New.NET.txt" The changelog. \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Doc/SHFB.txt b/Wrapper/FreeImage.NET/cs/Doc/SHFB.txt index fae9b3f..90a2e38 100644 --- a/Wrapper/FreeImage.NET/cs/Doc/SHFB.txt +++ b/Wrapper/FreeImage.NET/cs/Doc/SHFB.txt @@ -1,9 +1,9 @@ -Eric Woodruff's Sandcastle Help File Builder 1.6.x.x (SHFB) is needed for FreeImage.NET wrapper -help file creation. It can be downloaded from http://www.codeplex.com/SHFB - -As of FreeImage.NET version 1.08, version 1.8.01 of Sandcastle Help File Builder is used by FreeImage.NET -and thus needed for FreeImage.NET wrapper help file creation. It can still be downloaded -from http://www.codeplex.com/SHFB - -Microsoft's Sandcaste is also needed for SHFB to run correctly. It can be downloaded from -http://www.microsoft.com/downloads/details.aspx?FamilyId=E82EA71D-DA89-42EE-A715-696E3A4873B2&displaylang=en +Eric Woodruff's Sandcastle Help File Builder 1.6.x.x (SHFB) is needed for FreeImage.NET wrapper +help file creation. It can be downloaded from http://www.codeplex.com/SHFB + +As of FreeImage.NET version 1.08, version 1.8.01 of Sandcastle Help File Builder is used by FreeImage.NET +and thus needed for FreeImage.NET wrapper help file creation. It can still be downloaded +from http://www.codeplex.com/SHFB + +Microsoft's Sandcaste is also needed for SHFB to run correctly. It can be downloaded from +http://www.microsoft.com/downloads/details.aspx?FamilyId=E82EA71D-DA89-42EE-A715-696E3A4873B2&displaylang=en diff --git a/Wrapper/FreeImage.NET/cs/FreeImage.NET.nunit b/Wrapper/FreeImage.NET/cs/FreeImage.NET.nunit index c1da949..ec2c4b2 100644 --- a/Wrapper/FreeImage.NET/cs/FreeImage.NET.nunit +++ b/Wrapper/FreeImage.NET/cs/FreeImage.NET.nunit @@ -1,9 +1,9 @@ - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImageBitmap.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImageBitmap.cs index f22d396..f00381a 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImageBitmap.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImageBitmap.cs @@ -1,4378 +1,4378 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.12 $ -// $Date: 2011/12/22 14:54:22 $ -// $Id: FreeImageBitmap.cs,v 1.12 2011/12/22 14:54:22 drolon Exp $ -// ========================================================== - -using System; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; -using System.IO.Compression; -using System.Runtime.InteropServices; -using System.Runtime.Serialization; -using System.Collections; -using System.Collections.Generic; -using FreeImageAPI.Metadata; -using System.Diagnostics; - -namespace FreeImageAPI -{ - /// - /// Encapsulates a FreeImage-bitmap. - /// - [Serializable, Guid("64a4c935-b757-499c-ab8c-6110316a9e51")] - public class FreeImageBitmap : MarshalByRefObject, ICloneable, IDisposable, IEnumerable, ISerializable - { - #region Fields - - /// - /// Indicates whether this instance is disposed. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool disposed; - - /// - /// Tab object. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private object tag; - - /// - /// Object used to syncronize lock methods. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private object lockObject = new object(); - - /// - /// Holds information used by SaveAdd() methods. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private SaveInformation saveInformation = new SaveInformation(); - - /// - /// The stream that this instance was loaded from or - /// null if it has been cloned or deserialized. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private Stream stream; - - /// - /// True if the stream must be disposed with this - /// instance. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool disposeStream; - - /// - /// The number of frames contained by a mutlipage bitmap. - /// Default value is 1 and only changed if needed. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private int frameCount = 1; - - /// - /// The index of the loaded frame. - /// Default value is 0 and only changed if needed. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private int frameIndex = 0; - - /// - /// Format of the sourceimage. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private FREE_IMAGE_FORMAT originalFormat = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - - /// - /// Handle to the encapsulated FreeImage-bitmap. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private FIBITMAP dib; - - private const string ErrorLoadingBitmap = "Unable to load bitmap."; - private const string ErrorLoadingFrame = "Unable to load frame."; - private const string ErrorCreatingBitmap = "Unable to create bitmap."; - private const string ErrorUnloadBitmap = "Unable to unload bitmap."; - - #endregion - - #region Constructors and Destructor - - /// - /// Initializes a new instance of the class. - /// - protected FreeImageBitmap() - { - } - - /// - /// Initializes a new instance of the class. - /// For internal use only. - /// - /// The operation failed. - internal protected FreeImageBitmap(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - this.dib = dib; - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image. - /// - /// The original to clone from. - /// The operation failed. - /// is a null reference. - public FreeImageBitmap(FreeImageBitmap original) - { - if (original == null) - { - throw new ArgumentNullException("original"); - } - original.EnsureNotDisposed(); - dib = FreeImage.Clone(original.dib); - if (dib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - originalFormat = original.originalFormat; - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image with the specified size. - /// - /// The original to clone from. - /// The Size structure that represent the - /// size of the new . - /// The operation failed. - /// is a null reference. - /// - /// or are less or equal zero. - /// - public FreeImageBitmap(FreeImageBitmap original, Size newSize) - : this(original, newSize.Width, newSize.Height) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image with the specified size. - /// - /// The original to clone from. - /// Width of the new . - /// Height of the new . - /// The operation failed. - /// is a null reference. - /// - /// or are less or equal zero. - public FreeImageBitmap(FreeImageBitmap original, int width, int height) - { - if (original == null) - { - throw new ArgumentNullException("original"); - } - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - original.EnsureNotDisposed(); - dib = FreeImage.Rescale(original.dib, width, height, FREE_IMAGE_FILTER.FILTER_BICUBIC); - if (dib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - originalFormat = original.originalFormat; - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image. - /// - /// The original to clone from. - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - public FreeImageBitmap(Image original) - : this(original as Bitmap) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image with the specified size. - /// - /// The original to clone from. - /// The Size structure that represent the - /// size of the new . - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - /// is a null reference. - /// - /// or are less or equal zero. - /// - public FreeImageBitmap(Image original, Size newSize) - : this(original as Bitmap, newSize.Width, newSize.Height) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image with the specified size. - /// - /// The original to clone from. - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - /// is a null reference. - /// - /// or are less or equal zero. - public FreeImageBitmap(Image original, int width, int height) - : this(original as Bitmap, width, height) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image. - /// - /// The original to clone from. - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// is a null reference. - /// The operation failed. - public FreeImageBitmap(Bitmap original) - { - if (original == null) - { - throw new ArgumentNullException("original"); - } - dib = FreeImage.CreateFromBitmap(original, true); - if (dib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - originalFormat = FreeImage.GetFormat(original.RawFormat); - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image with the specified size. - /// - /// The original to clone from. - /// The Size structure that represent the - /// size of the new . - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - /// is a null reference. - /// - /// or are less or equal zero. - /// - public FreeImageBitmap(Bitmap original, Size newSize) - : this(original, newSize.Width, newSize.Height) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image with the specified size. - /// - /// The original to clone from. - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - /// is a null reference. - /// - /// or are less or equal zero. - public FreeImageBitmap(Bitmap original, int width, int height) - { - if (original == null) - { - throw new ArgumentNullException("original"); - } - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - FIBITMAP temp = FreeImage.CreateFromBitmap(original, true); - if (temp.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - dib = FreeImage.Rescale(temp, width, height, FREE_IMAGE_FILTER.FILTER_BICUBIC); - FreeImage.Unload(temp); - if (dib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - originalFormat = FreeImage.GetFormat(original.RawFormat); - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class - /// bases on the specified stream. - /// - /// Stream to read from. - /// Ignored. - /// The operation failed. - /// is a null reference. - /// - /// You must keep the stream open for the lifetime of the . - /// - public FreeImageBitmap(Stream stream, bool useIcm) - : this(stream) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified stream. - /// - /// Stream to read from. - /// The operation failed. - /// is a null reference. - /// - /// You must keep the stream open for the lifetime of the . - /// - public FreeImageBitmap(Stream stream) - : this(stream, FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_LOAD_FLAGS.DEFAULT) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified stream in the specified format. - /// - /// Stream to read from. - /// Format of the image. - /// The operation failed. - /// is a null reference. - /// - /// You must keep the stream open for the lifetime of the . - /// - public FreeImageBitmap(Stream stream, FREE_IMAGE_FORMAT format) - : this(stream, format, FREE_IMAGE_LOAD_FLAGS.DEFAULT) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified stream with the specified loading flags. - /// - /// Stream to read from. - /// Flags to enable or disable plugin-features. - /// The operation failed. - /// is a null reference. - /// - /// You must keep the stream open for the lifetime of the . - /// - public FreeImageBitmap(Stream stream, FREE_IMAGE_LOAD_FLAGS flags) - : this(stream, FREE_IMAGE_FORMAT.FIF_UNKNOWN, flags) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified stream in the specified format - /// with the specified loading flags. - /// - /// Stream to read from. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// The operation failed. - /// is a null reference. - /// - /// You must keep the stream open for the lifetime of the . - /// - public FreeImageBitmap(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) - { - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - this.stream = stream; - disposeStream = false; - LoadFromStream(stream, format, flags); - } - - /// - /// Initializes a new instance of the class bases on the specified file. - /// - /// The complete name of the file to load. - /// The operation failed. - /// is a null reference. - /// does not exist. - public FreeImageBitmap(string filename) - : this(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT) - { - } - - /// - /// Initializes a new instance of the class bases on the specified file. - /// - /// The complete name of the file to load. - /// Ignored. - /// The operation failed. - /// is a null reference. - /// does not exist. - public FreeImageBitmap(string filename, bool useIcm) - : this(filename) - { - } - - /// - /// Initializes a new instance of the class bases on the specified file - /// with the specified loading flags. - /// - /// The complete name of the file to load. - /// Flags to enable or disable plugin-features. - /// The operation failed. - /// is a null reference. - /// does not exist. - public FreeImageBitmap(string filename, FREE_IMAGE_LOAD_FLAGS flags) - : this(filename, FREE_IMAGE_FORMAT.FIF_UNKNOWN, flags) - { - } - - /// - /// Initializes a new instance of the class bases on the specified file - /// in the specified format. - /// - /// The complete name of the file to load. - /// Format of the image. - /// The operation failed. - /// is a null reference. - /// does not exist. - public FreeImageBitmap(string filename, FREE_IMAGE_FORMAT format) - : this(filename, format, FREE_IMAGE_LOAD_FLAGS.DEFAULT) - { - } - - /// - /// Initializes a new instance of the class bases on the specified file - /// in the specified format with the specified loading flags. - /// - /// The complete name of the file to load. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// The operation failed. - /// is a null reference. - /// does not exist. - public FreeImageBitmap(string filename, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) - { - if (filename == null) - { - throw new ArgumentNullException("filename"); - } - if (!File.Exists(filename)) - { - throw new FileNotFoundException("filename"); - } - - saveInformation.filename = filename; - stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); - disposeStream = true; - LoadFromStream(stream, format, flags); - } - - /// - /// Initializes a new instance of the class - /// bases on the specified size. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// The operation failed. - public FreeImageBitmap(int width, int height) - { - dib = FreeImage.Allocate( - width, - height, - 24, - FreeImage.FI_RGBA_RED_MASK, - FreeImage.FI_RGBA_GREEN_MASK, - FreeImage.FI_RGBA_BLUE_MASK); - if (dib.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class bases on the specified resource. - /// - /// The class used to extract the resource. - /// The name of the resource. - /// The operation failed. - public FreeImageBitmap(Type type, string resource) - : this(type.Module.Assembly.GetManifestResourceStream(type, resource)) - { - } - - /// - /// Initializes a new instance of the class bases on the specified size - /// and with the resolution of the specified object. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// The Graphics object that specifies the resolution for the new . - /// The operation failed. - /// is a null reference. - public FreeImageBitmap(int width, int height, Graphics g) - : this(width, height) - { - FreeImage.SetResolutionX(dib, (uint)g.DpiX); - FreeImage.SetResolutionY(dib, (uint)g.DpiY); - } - - /// - /// Initializes a new instance of the class bases on the specified size and format. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// The PixelFormat enumeration for the new . - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - /// is invalid. - /// - /// or are less or equal zero. - public FreeImageBitmap(int width, int height, PixelFormat format) - { - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - uint bpp, redMask, greenMask, blueMask; - FREE_IMAGE_TYPE type; - if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask)) - { - throw new ArgumentException("format is invalid"); - } - dib = FreeImage.AllocateT(type, width, height, (int)bpp, redMask, greenMask, blueMask); - if (dib.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class bases on the specified size and type. - /// Only non standard bitmaps are supported. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// The type of the bitmap. - /// The operation failed. - /// - /// is FIT_BITMAP or FIT_UNKNOWN. - /// is invalid. - /// - /// or are less or equal zero. - public FreeImageBitmap(int width, int height, FREE_IMAGE_TYPE type) - { - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - if ((type == FREE_IMAGE_TYPE.FIT_BITMAP) || (type == FREE_IMAGE_TYPE.FIT_UNKNOWN)) - { - throw new ArgumentException("type is invalid."); - } - dib = FreeImage.AllocateT(type, width, height, 0, 0u, 0u, 0u); - if (dib.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class bases on the specified size, - /// pixel format and pixel data. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// Integer that specifies the byte offset between the beginning - /// of one scan line and the next. This is usually (but not necessarily) - /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) - /// multiplied by the width of the bitmap. The value passed to this parameter must - /// be a multiple of four.. - /// The PixelFormat enumeration for the new . - /// Pointer to an array of bytes that contains the pixel data. - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - /// is invalid. - /// - /// or are less or equal zero. - public FreeImageBitmap(int width, int height, int stride, PixelFormat format, IntPtr scan0) - { - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - uint bpp, redMask, greenMask, blueMask; - FREE_IMAGE_TYPE type; - bool topDown = (stride > 0); - stride = (stride > 0) ? stride : (stride * -1); - - if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask)) - { - throw new ArgumentException("format is invalid."); - } - - dib = FreeImage.ConvertFromRawBits( - scan0, type, width, height, stride, bpp, redMask, greenMask, blueMask, topDown); - - if (dib.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class bases on the specified size, - /// pixel format and pixel data. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// Integer that specifies the byte offset between the beginning - /// of one scan line and the next. This is usually (but not necessarily) - /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) - /// multiplied by the width of the bitmap. The value passed to this parameter must - /// be a multiple of four.. - /// The PixelFormat enumeration for the new . - /// Array of bytes containing the bitmap data. - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - /// is invalid. - /// - /// or are less or equal zero. - /// is null - public FreeImageBitmap(int width, int height, int stride, PixelFormat format, byte[] bits) - { - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - if (bits == null) - { - throw new ArgumentNullException("bits"); - } - uint bpp, redMask, greenMask, blueMask; - FREE_IMAGE_TYPE type; - bool topDown = (stride > 0); - stride = (stride > 0) ? stride : (stride * -1); - - if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask)) - { - throw new ArgumentException("format is invalid."); - } - - dib = FreeImage.ConvertFromRawBits( - bits, type, width, height, stride, bpp, redMask, greenMask, blueMask, topDown); - - if (dib.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class bases on the specified size, - /// pixel format and pixel data. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// Integer that specifies the byte offset between the beginning - /// of one scan line and the next. This is usually (but not necessarily) - /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) - /// multiplied by the width of the bitmap. The value passed to this parameter must - /// be a multiple of four.. - /// The color depth of the new - /// The type for the new . - /// Pointer to an array of bytes that contains the pixel data. - /// The operation failed. - /// is invalid. - /// - /// or are less or equal zero. - public FreeImageBitmap(int width, int height, int stride, int bpp, FREE_IMAGE_TYPE type, IntPtr scan0) - { - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - uint redMask, greenMask, blueMask; - bool topDown = (stride > 0); - stride = (stride > 0) ? stride : (stride * -1); - - if (!FreeImage.GetTypeParameters(type, bpp, out redMask, out greenMask, out blueMask)) - { - throw new ArgumentException("bpp and type are invalid or not supported."); - } - - dib = FreeImage.ConvertFromRawBits( - scan0, type, width, height, stride, (uint)bpp, redMask, greenMask, blueMask, topDown); - - if (dib.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class bases on the specified size, - /// pixel format and pixel data. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// Integer that specifies the byte offset between the beginning - /// of one scan line and the next. This is usually (but not necessarily) - /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) - /// multiplied by the width of the bitmap. The value passed to this parameter must - /// be a multiple of four.. - /// The color depth of the new - /// The type for the new . - /// Array of bytes containing the bitmap data. - /// The operation failed. - /// is invalid. - /// - /// or are less or equal zero. - /// is null - public FreeImageBitmap(int width, int height, int stride, int bpp, FREE_IMAGE_TYPE type, byte[] bits) - { - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - if (bits == null) - { - throw new ArgumentNullException("bits"); - } - uint redMask, greenMask, blueMask; - bool topDown = (stride > 0); - stride = (stride > 0) ? stride : (stride * -1); - - if (!FreeImage.GetTypeParameters(type, bpp, out redMask, out greenMask, out blueMask)) - { - throw new ArgumentException("bpp and type are invalid or not supported."); - } - - dib = FreeImage.ConvertFromRawBits( - bits, type, width, height, stride, (uint)bpp, redMask, greenMask, blueMask, topDown); - - if (dib.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class. - /// - /// The operation failed. - /// The operation failed. - public FreeImageBitmap(SerializationInfo info, StreamingContext context) - { - try - { - byte[] data = (byte[])info.GetValue("Bitmap Data", typeof(byte[])); - if ((data != null) && (data.Length > 0)) - { - MemoryStream memory = new MemoryStream(data); - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_TIFF; - dib = FreeImage.LoadFromStream(memory, ref format); - - if (dib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - - AddMemoryPressure(); - } - } - catch (Exception ex) - { - throw new SerializationException("Deserialization failed.", ex); - } - } - - /// - /// Frees all managed and unmanaged ressources. - /// - ~FreeImageBitmap() - { - Dispose(false); - } - - #endregion - - #region Operators - - /// - /// Converts a instance to a instance. - /// - /// A instance. - /// A new instance of initialized to . - /// - /// The explicit conversion from into Bitmap - /// allows to create an instance on the fly and use it as if - /// was a Bitmap. This way it can be directly used with a - /// PixtureBox for example without having to call any - /// conversion operations. - /// - public static explicit operator Bitmap(FreeImageBitmap value) - { - return value.ToBitmap(); - } - - /// - /// Converts a instance to a instance. - /// - /// A instance. - /// A new instance of initialized to . - /// - /// The explicit conversion from into - /// allows to create an instance on the fly to perform - /// image processing operations and converting it back. - /// - public static explicit operator FreeImageBitmap(Bitmap value) - { - return new FreeImageBitmap(value); - } - - /// - /// Determines whether two specified objects have the same value. - /// - /// A or a null reference (Nothing in Visual Basic). - /// A or a null reference (Nothing in Visual Basic). - /// - /// true if the value of left is the same as the value of right; otherwise, false. - /// - public static bool operator ==(FreeImageBitmap left, FreeImageBitmap right) - { - if (object.ReferenceEquals(left, right)) - { - return true; - } - else if (object.ReferenceEquals(left, null) || object.ReferenceEquals(right, null)) - { - return false; - } - else - { - left.EnsureNotDisposed(); - right.EnsureNotDisposed(); - return FreeImage.Compare(left.dib, right.dib, FREE_IMAGE_COMPARE_FLAGS.COMPLETE); - } - } - - /// - /// Determines whether two specified objects have different values. - /// - /// A or a null reference (Nothing in Visual Basic). - /// A or a null reference (Nothing in Visual Basic). - /// - /// true if the value of left is different from the value of right; otherwise, false. - /// - public static bool operator !=(FreeImageBitmap left, FreeImageBitmap right) - { - return (!(left == right)); - } - - #endregion - - #region Properties - - /// - /// Type of the bitmap. - /// - public FREE_IMAGE_TYPE ImageType - { - get - { - EnsureNotDisposed(); - return FreeImage.GetImageType(dib); - } - } - - /// - /// Number of palette entries. - /// - public int ColorsUsed - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetColorsUsed(dib); - } - } - - /// - /// The number of unique colors actually used by the bitmap. This might be different from - /// what ColorsUsed returns, which actually returns the palette size for palletised images. - /// Works for FIT_BITMAP type bitmaps only. - /// - public int UniqueColors - { - get - { - EnsureNotDisposed(); - return FreeImage.GetUniqueColors(dib); - } - } - - /// - /// The size of one pixel in the bitmap in bits. - /// - public int ColorDepth - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetBPP(dib); - } - } - - /// - /// Width of the bitmap in pixel units. - /// - public int Width - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetWidth(dib); - } - } - - /// - /// Height of the bitmap in pixel units. - /// - public int Height - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetHeight(dib); - } - } - - /// - /// Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary. - /// - public int Pitch - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetPitch(dib); - } - } - - /// - /// Size of the bitmap in memory. - /// - public int DataSize - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetDIBSize(dib); - } - } - - /// - /// Returns a structure that represents the palette of a FreeImage bitmap. - /// - /// is false. - public Palette Palette - { - get - { - EnsureNotDisposed(); - if (HasPalette) - { - return new Palette(dib); - } - throw new InvalidOperationException("This bitmap does not have a palette."); - } - } - - /// - /// Gets whether the bitmap is RGB 555. - /// - public bool IsRGB555 - { - get - { - EnsureNotDisposed(); - return FreeImage.IsRGB555(dib); - } - } - - /// - /// Gets whether the bitmap is RGB 565. - /// - public bool IsRGB565 - { - get - { - EnsureNotDisposed(); - return FreeImage.IsRGB565(dib); - } - } - - /// - /// Gets the horizontal resolution, in pixels per inch, of this . - /// - public float HorizontalResolution - { - get - { - EnsureNotDisposed(); - return (float)FreeImage.GetResolutionX(dib); - } - private set - { - EnsureNotDisposed(); - FreeImage.SetResolutionX(dib, (uint)value); - } - } - - /// - /// Gets the vertical resolution, in pixels per inch, of this . - /// - public float VerticalResolution - { - get - { - EnsureNotDisposed(); - return (float)FreeImage.GetResolutionY(dib); - } - private set - { - EnsureNotDisposed(); - FreeImage.SetResolutionY(dib, (uint)value); - } - } - - /// - /// Returns the structure of this . - /// - public BITMAPINFOHEADER InfoHeader - { - get - { - EnsureNotDisposed(); - return FreeImage.GetInfoHeaderEx(dib); - } - } - - /// - /// Returns the structure of a this . - /// - public BITMAPINFO Info - { - get - { - EnsureNotDisposed(); - return FreeImage.GetInfoEx(dib); - } - } - - /// - /// Investigates the color type of this - /// by reading the bitmaps pixel bits and analysing them. - /// - public FREE_IMAGE_COLOR_TYPE ColorType - { - get - { - EnsureNotDisposed(); - return FreeImage.GetColorType(dib); - } - } - - /// - /// Bit pattern describing the red color component of a pixel in this . - /// - public uint RedMask - { - get - { - EnsureNotDisposed(); - return FreeImage.GetRedMask(dib); - } - } - - /// - /// Bit pattern describing the green color component of a pixel in this . - /// - public uint GreenMask - { - get - { - EnsureNotDisposed(); - return FreeImage.GetGreenMask(dib); - } - } - - /// - /// Bit pattern describing the blue color component of a pixel in this . - /// - public uint BlueMask - { - get - { - EnsureNotDisposed(); - return FreeImage.GetBlueMask(dib); - } - } - - /// - /// Number of transparent colors in a palletised . - /// - public int TransparencyCount - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetTransparencyCount(dib); - } - } - - /// - /// Get or sets transparency table of this . - /// - public byte[] TransparencyTable - { - get - { - EnsureNotDisposed(); - return FreeImage.GetTransparencyTableEx(dib); - } - set - { - EnsureNotDisposed(); - FreeImage.SetTransparencyTable(dib, value); - } - } - - /// - /// Gets or sets whether this is transparent. - /// - public bool IsTransparent - { - get - { - EnsureNotDisposed(); - return FreeImage.IsTransparent(dib); - } - set - { - EnsureNotDisposed(); - FreeImage.SetTransparent(dib, value); - } - } - - /// - /// Gets whether this has a file background color. - /// - public bool HasBackgroundColor - { - get - { - EnsureNotDisposed(); - return FreeImage.HasBackgroundColor(dib); - } - } - - /// - /// Gets or sets the background color of this . - /// In case the value is null, the background color is removed. - /// - /// Get: There is no background color available. - /// Set: Setting background color failed. - public Color? BackgroundColor - { - get - { - EnsureNotDisposed(); - if (!FreeImage.HasBackgroundColor(dib)) - { - throw new InvalidOperationException("No background color available."); - } - RGBQUAD rgbq; - FreeImage.GetBackgroundColor(dib, out rgbq); - return rgbq.Color; - } - set - { - EnsureNotDisposed(); - if (!FreeImage.SetBackgroundColor(dib, (value.HasValue ? new RGBQUAD[] { value.Value } : null))) - { - throw new Exception("Setting background color failed."); - } - } - } - - /// - /// Pointer to the data-bits of this . - /// - public IntPtr Bits - { - get - { - EnsureNotDisposed(); - return FreeImage.GetBits(dib); - } - } - - /// - /// Width, in bytes, of this . - /// - public int Line - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetLine(dib); - } - } - - /// - /// Pointer to the scanline of the top most pixel row of this . - /// - public IntPtr Scan0 - { - get - { - EnsureNotDisposed(); - return FreeImage.GetScanLine(dib, (int)(FreeImage.GetHeight(dib) - 1)); - } - } - - /// - /// Width, in bytes, of this . - /// In case this is top down Stride will be positive, else negative. - /// - public int Stride - { - get - { - return -Line; - } - } - - /// - /// Gets attribute flags for the pixel data of this . - /// - public unsafe int Flags - { - get - { - EnsureNotDisposed(); - int result = 0; - byte alpha; - int cd = ColorDepth; - - if ((cd == 32) || (FreeImage.GetTransparencyCount(dib) != 0)) - { - result += (int)ImageFlags.HasAlpha; - } - - if (cd == 32) - { - uint width = FreeImage.GetWidth(dib); - uint height = FreeImage.GetHeight(dib); - for (int y = 0; y < height; y++) - { - RGBQUAD* scanline = (RGBQUAD*)FreeImage.GetScanLine(dib, y); - for (int x = 0; x < width; x++) - { - alpha = scanline[x].Color.A; - if (alpha != byte.MinValue && alpha != byte.MaxValue) - { - result += (int)ImageFlags.HasTranslucent; - y = (int)height; - break; - } - } - } - } - else if (FreeImage.GetTransparencyCount(dib) != 0) - { - byte[] transTable = FreeImage.GetTransparencyTableEx(dib); - for (int i = 0; i < transTable.Length; i++) - { - if (transTable[i] != byte.MinValue && transTable[i] != byte.MaxValue) - { - result += (int)ImageFlags.HasTranslucent; - break; - } - } - } - - if (FreeImage.GetICCProfileEx(dib).IsCMYK) - { - result += (int)ImageFlags.ColorSpaceCmyk; - } - else - { - result += (int)ImageFlags.ColorSpaceRgb; - } - - if (FreeImage.GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_MINISBLACK || - FreeImage.GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_MINISWHITE) - { - result += (int)ImageFlags.ColorSpaceGray; - } - - if (originalFormat == FREE_IMAGE_FORMAT.FIF_BMP || - originalFormat == FREE_IMAGE_FORMAT.FIF_FAXG3 || - originalFormat == FREE_IMAGE_FORMAT.FIF_ICO || - originalFormat == FREE_IMAGE_FORMAT.FIF_JPEG || - originalFormat == FREE_IMAGE_FORMAT.FIF_PCX || - originalFormat == FREE_IMAGE_FORMAT.FIF_PNG || - originalFormat == FREE_IMAGE_FORMAT.FIF_PSD || - originalFormat == FREE_IMAGE_FORMAT.FIF_TIFF) - { - result += (int)ImageFlags.HasRealDpi; - } - - return result; - } - } - - /// - /// Gets the width and height of this . - /// - public SizeF PhysicalDimension - { - get - { - EnsureNotDisposed(); - return new SizeF((float)FreeImage.GetWidth(dib), (float)FreeImage.GetHeight(dib)); - } - } - - /// - /// Gets the pixel format for this . - /// - public PixelFormat PixelFormat - { - get - { - EnsureNotDisposed(); - return FreeImage.GetPixelFormat(dib); - } - } - - /// - /// Gets IDs of the property items stored in this . - /// - public int[] PropertyIdList - { - get - { - EnsureNotDisposed(); - List list = new List(); - ImageMetadata metaData = new ImageMetadata(dib, true); - - foreach (MetadataModel metadataModel in metaData) - { - foreach (MetadataTag metadataTag in metadataModel) - { - list.Add(metadataTag.ID); - } - } - - return list.ToArray(); - } - } - - /// - /// Gets all the property items (pieces of metadata) stored in this . - /// - public PropertyItem[] PropertyItems - { - get - { - EnsureNotDisposed(); - List list = new List(); - ImageMetadata metaData = new ImageMetadata(dib, true); - - foreach (MetadataModel metadataModel in metaData) - { - foreach (MetadataTag metadataTag in metadataModel) - { - list.Add(metadataTag.GetPropertyItem()); - } - } - - return list.ToArray(); - } - } - - /// - /// Gets the format of this . - /// - public ImageFormat RawFormat - { - get - { - EnsureNotDisposed(); - Attribute guidAttribute = - Attribute.GetCustomAttribute( - typeof(FreeImageBitmap), typeof(System.Runtime.InteropServices.GuidAttribute) - ); - return (guidAttribute == null) ? - null : - new ImageFormat(new Guid(((GuidAttribute)guidAttribute).Value)); - } - } - - /// - /// Gets the width and height, in pixels, of this . - /// - public Size Size - { - get - { - EnsureNotDisposed(); - return new Size(Width, Height); - } - } - - /// - /// Gets or sets an object that provides additional data about the . - /// - public Object Tag - { - get - { - EnsureNotDisposed(); - return tag; - } - set - { - EnsureNotDisposed(); - tag = value; - } - } - - /// - /// Gets whether this has been disposed. - /// - public bool IsDisposed - { - get - { - return disposed; - } - } - - /// - /// Gets a new instance of a metadata representing class. - /// - public ImageMetadata Metadata - { - get - { - EnsureNotDisposed(); - return new ImageMetadata(dib, true); - } - } - - /// - /// Gets or sets the comment of this . - /// Supported formats are JPEG, PNG and GIF. - /// - public string Comment - { - get - { - EnsureNotDisposed(); - return FreeImage.GetImageComment(dib); - } - set - { - EnsureNotDisposed(); - FreeImage.SetImageComment(dib, value); - } - } - - /// - /// Returns whether this has a palette. - /// - public bool HasPalette - { - get - { - EnsureNotDisposed(); - return (FreeImage.GetPalette(dib) != IntPtr.Zero); - } - } - - /// - /// Gets or sets the entry used as transparent color in this . - /// Only works for 1-, 4- and 8-bpp. - /// - public int TransparentIndex - { - get - { - EnsureNotDisposed(); - return FreeImage.GetTransparentIndex(dib); - } - set - { - EnsureNotDisposed(); - FreeImage.SetTransparentIndex(dib, value); - } - } - - /// - /// Gets the number of frames in this . - /// - public int FrameCount - { - get - { - EnsureNotDisposed(); - return frameCount; - } - } - - /// - /// Gets the ICCProfile structure of this . - /// - public FIICCPROFILE ICCProfile - { - get - { - EnsureNotDisposed(); - return FreeImage.GetICCProfileEx(dib); - } - } - - /// - /// Gets the format of the original image in case - /// this was loaded from a file or stream. - /// - public FREE_IMAGE_FORMAT ImageFormat - { - get - { - EnsureNotDisposed(); - return originalFormat; - } - } - - /// - /// Gets the encapsulated FIBITMAP. - /// - internal FIBITMAP Dib - { - get { EnsureNotDisposed(); return dib; } - } - - #endregion - - #region Methods - - /// - /// Gets the bounds of this in the specified unit. - /// - /// One of the values indicating - /// the unit of measure for the bounding rectangle. - /// The that represents the bounds of this - /// , in the specified unit. - public RectangleF GetBounds(ref GraphicsUnit pageUnit) - { - EnsureNotDisposed(); - pageUnit = GraphicsUnit.Pixel; - return new RectangleF( - 0f, - 0f, - (float)FreeImage.GetWidth(dib), - (float)FreeImage.GetHeight(dib)); - } - - /// - /// Gets the specified property item from this . - /// - /// The ID of the property item to get. - /// The this method gets. - public PropertyItem GetPropertyItem(int propid) - { - EnsureNotDisposed(); - ImageMetadata metadata = new ImageMetadata(dib, true); - foreach (MetadataModel metadataModel in metadata) - { - foreach (MetadataTag tag in metadataModel) - { - if (tag.ID == propid) - { - return tag.GetPropertyItem(); - } - } - } - return null; - } - - /// - /// Returns a thumbnail for this . - /// - /// The width, in pixels, of the requested thumbnail image. - /// The height, in pixels, of the requested thumbnail image. - /// Ignored. - /// Ignored. - /// A that represents the thumbnail. - public FreeImageBitmap GetThumbnailImage(int thumbWidth, int thumbHeight, - Image.GetThumbnailImageAbort callback, IntPtr callBackData) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.Rescale( - dib, thumbWidth, thumbHeight, FREE_IMAGE_FILTER.FILTER_BICUBIC); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Returns a thumbnail for this , keeping aspect ratio. - /// defines the maximum width or height - /// of the thumbnail. - /// - /// Thumbnail square size. - /// When true HDR images are transperantly - /// converted to standard images. - /// The thumbnail in a new instance. - public FreeImageBitmap GetThumbnailImage(int maxPixelSize, bool convert) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.MakeThumbnail(dib, maxPixelSize, convert); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Converts this instance to a instance. - /// - /// A new instance of initialized this instance. - public Bitmap ToBitmap() - { - EnsureNotDisposed(); - return FreeImage.GetBitmap(dib, true); - } - - /// - /// Returns an instance of , representing the scanline - /// specified by of this . - /// Since FreeImage bitmaps are always bottum up aligned, keep in mind that scanline 0 is the - /// bottom-most line of the image. - /// - /// Number of the scanline to retrieve. - /// An instance of representing the - /// th scanline. - /// - /// List of return-types of T: - /// - /// Color Depth / TypeResult Type - /// 1 () - /// 4 () - /// 8 () - /// 16 () - /// 16 - 555 () - /// 16 - 565 () - /// 24 () - /// 32 () - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// FreeImageBitmap bitmap = new FreeImageBitmap(@"C:\Pictures\picture.bmp"); - /// if (bitmap.ColorDepth == 32) - /// { - /// Scanline<RGBQUAD> scanline = bitmap.GetScanline<RGBQUAD>(0); - /// foreach (RGBQUAD pixel in scanline) - /// { - /// Console.WriteLine(pixel); - /// } - /// } - /// - /// - /// - /// The bitmap's type or color depth are not supported. - /// - /// - /// is no valid value. - /// - public Scanline GetScanline(int scanline) where T : struct - { - EnsureNotDisposed(); - return new Scanline(dib, scanline); - } - - /// - /// Returns an instance of , representing the scanline - /// specified by of this . - /// Since FreeImage bitmaps are always bottum up aligned, keep in mind that scanline 0 is the - /// bottom-most line of the image. - /// - /// Number of the scanline to retrieve. - /// An instance of representing the - /// th scanline. - /// - /// List of return-types of T: - /// - /// Color Depth / TypeResult Type - /// 1 () - /// 4 () - /// 8 () - /// 16 () - /// 16 - 555 () - /// 16 - 565 () - /// 24 () - /// 32 () - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// FreeImageBitmap bitmap = new FreeImageBitmap(@"C:\Pictures\picture.bmp"); - /// if (bitmap.ColorDepth == 32) - /// { - /// Scanline<RGBQUAD> scanline = (Scanline<RGBQUAD>)bitmap.GetScanline(0); - /// foreach (RGBQUAD pixel in scanline) - /// { - /// Console.WriteLine(pixel); - /// } - /// } - /// - /// - /// - /// The type of the bitmap or color depth are not supported. - /// - /// - /// is no valid value. - /// - public object GetScanline(int scanline) - { - EnsureNotDisposed(); - object result = null; - int width = (int)FreeImage.GetWidth(dib); - - switch (FreeImage.GetImageType(dib)) - { - case FREE_IMAGE_TYPE.FIT_BITMAP: - - switch (FreeImage.GetBPP(dib)) - { - case 1u: result = new Scanline(dib, scanline, width); break; - case 4u: result = new Scanline(dib, scanline, width); break; - case 8u: result = new Scanline(dib, scanline, width); break; - case 16u: - if ((RedMask == FreeImage.FI16_555_RED_MASK) && - (GreenMask == FreeImage.FI16_555_GREEN_MASK) && - (BlueMask == FreeImage.FI16_555_BLUE_MASK)) - { - result = new Scanline(dib, scanline, width); - } - else if ((RedMask == FreeImage.FI16_565_RED_MASK) && - (GreenMask == FreeImage.FI16_565_GREEN_MASK) && - (BlueMask == FreeImage.FI16_565_BLUE_MASK)) - { - result = new Scanline(dib, scanline, width); - } - else - { - result = new Scanline(dib, scanline, width); - } - break; - case 24u: result = new Scanline(dib, scanline, width); break; - case 32u: result = new Scanline(dib, scanline, width); break; - default: throw new ArgumentException("Color depth is not supported."); - } - break; - - case FREE_IMAGE_TYPE.FIT_COMPLEX: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_DOUBLE: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_FLOAT: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_INT16: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_INT32: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_RGB16: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_RGBA16: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_RGBAF: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_RGBF: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_UINT16: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_UINT32: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_UNKNOWN: - default: throw new ArgumentException("Type is not supported."); - } - - return result; - } - - /// - /// Returns a pointer to the specified scanline. - /// Due to FreeImage bitmaps are bottum up, - /// scanline 0 is the most bottom line of the image. - /// - /// Number of the scanline. - /// Pointer to the scanline. - public IntPtr GetScanlinePointer(int scanline) - { - EnsureNotDisposed(); - return FreeImage.GetScanLine(dib, scanline); - } - - /// - /// Returns a list of structures, representing the scanlines of this . - /// Due to FreeImage bitmaps are bottum up, scanline 0 is the - /// bottom-most line of the image. - /// Each color depth has a different representing structure due to different memory layouts. - /// - /// - /// List of return-types of T: - /// - /// Color Depth / TypeResult Type of IEnmuerable<Scanline<T>> - /// 1 () - /// 4 () - /// 8 () - /// 16 () - /// 16 - 555 () - /// 16 - 565 () - /// 24 () - /// 32 () - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public IList GetScanlines() - { - EnsureNotDisposed(); - - int height = (int)FreeImage.GetHeight(dib); - IList list; - - switch (FreeImage.GetImageType(dib)) - { - case FREE_IMAGE_TYPE.FIT_BITMAP: - - switch (FreeImage.GetBPP(dib)) - { - case 1u: list = new List>(height); break; - case 4u: list = new List>(height); break; - case 8u: list = new List>(height); break; - case 16u: - if (FreeImage.IsRGB555(dib)) - { - list = new List>(height); - } - else if (FreeImage.IsRGB565(dib)) - { - list = new List>(height); - } - else - { - list = new List>(height); - } - break; - case 24u: list = new List>(height); break; - case 32u: list = new List>(height); break; - default: throw new ArgumentException("Color depth is not supported."); - } - break; - - case FREE_IMAGE_TYPE.FIT_COMPLEX: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_DOUBLE: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_FLOAT: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_INT16: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_INT32: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_RGB16: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_RGBA16: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_RGBAF: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_RGBF: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_UINT16: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_UINT32: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_UNKNOWN: - default: throw new ArgumentException("Type is not supported."); - } - - for (int i = 0; i < height; i++) - { - list.Add(GetScanline(i)); - } - - return list; - } - - /// - /// Removes the specified property item from this . - /// - /// The ID of the property item to remove. - public void RemovePropertyItem(int propid) - { - EnsureNotDisposed(); - ImageMetadata mdata = new ImageMetadata(dib, true); - foreach (MetadataModel model in mdata) - { - foreach (MetadataTag tag in model) - { - if (tag.ID == propid) - { - model.RemoveTag(tag.Key); - return; - } - } - } - } - - /// - /// This method rotates, flips, or rotates and flips this . - /// - /// A RotateFlipType member - /// that specifies the type of rotation and flip to apply to this . - public void RotateFlip(RotateFlipType rotateFlipType) - { - EnsureNotDisposed(); - - FIBITMAP newDib = new FIBITMAP(); - uint bpp = FreeImage.GetBPP(dib); - - switch (rotateFlipType) - { - case RotateFlipType.RotateNoneFlipX: - - FreeImage.FlipHorizontal(dib); - break; - - case RotateFlipType.RotateNoneFlipY: - - FreeImage.FlipVertical(dib); - break; - - case RotateFlipType.RotateNoneFlipXY: - - FreeImage.FlipHorizontal(dib); - FreeImage.FlipVertical(dib); - break; - - case RotateFlipType.Rotate90FlipNone: - - newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); - break; - - case RotateFlipType.Rotate90FlipX: - - newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); - FreeImage.FlipHorizontal(newDib); - break; - - case RotateFlipType.Rotate90FlipY: - - newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); - FreeImage.FlipVertical(newDib); - break; - - case RotateFlipType.Rotate90FlipXY: - - newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); - FreeImage.FlipHorizontal(newDib); - FreeImage.FlipVertical(newDib); - break; - - case RotateFlipType.Rotate180FlipXY: - newDib = FreeImage.Clone(dib); - break; - } - ReplaceDib(newDib); - } - - /// - /// Copies the metadata from another . - /// - /// The bitmap to read the metadata from. - /// - /// is a null reference. - /// - public void CloneMetadataFrom(FreeImageBitmap bitmap) - { - if (bitmap == null) - { - throw new ArgumentNullException("bitmap"); - } - EnsureNotDisposed(); - bitmap.EnsureNotDisposed(); - FreeImage.CloneMetadata(dib, bitmap.dib); - } - - /// - /// Copies the metadata from another using - /// the provided options. - /// - /// The bitmap to read the metadata from. - /// Specifies the way the metadata is copied. - /// - /// is a null reference. - /// - public void CloneMetadataFrom(FreeImageBitmap bitmap, FREE_IMAGE_METADATA_COPY flags) - { - if (bitmap == null) - { - throw new ArgumentNullException("bitmap"); - } - EnsureNotDisposed(); - bitmap.EnsureNotDisposed(); - FreeImage.CloneMetadataEx(bitmap.dib, dib, flags); - } - - /// - /// Saves this to the specified file. - /// - /// A string that contains the name of the file to which - /// to save this . - /// is null or empty. - /// Saving the image failed. - public void Save(string filename) - { - Save(filename, FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - /// - /// Saves this to the specified file in the specified format. - /// - /// A string that contains the name of the file to which - /// to save this . - /// An that specifies the format of the saved image. - /// is null or empty. - /// Saving the image failed. - public void Save(string filename, FREE_IMAGE_FORMAT format) - { - Save(filename, format, FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - /// - /// Saves this to the specified file in the specified format - /// using the specified saving flags. - /// - /// A string that contains the name of the file to which - /// to save this . - /// An that specifies the format of the saved image. - /// Flags to enable or disable plugin-features. - /// is null or empty. - /// Saving the image failed. - public void Save(string filename, FREE_IMAGE_FORMAT format, FREE_IMAGE_SAVE_FLAGS flags) - { - EnsureNotDisposed(); - if (string.IsNullOrEmpty(filename)) - { - throw new ArgumentException("filename"); - } - if (!FreeImage.SaveEx(dib, filename, format, flags)) - { - throw new Exception("Unable to save bitmap"); - } - - saveInformation.filename = filename; - saveInformation.format = format; - saveInformation.saveFlags = flags; - } - - /// - /// Saves this to the specified stream in the specified format. - /// - /// The stream where this will be saved. - /// An that specifies the format of the saved image. - /// is a null reference. - /// Saving the image failed. - public void Save(Stream stream, FREE_IMAGE_FORMAT format) - { - Save(stream, format, FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - /// - /// Saves this to the specified stream in the specified format - /// using the specified saving flags. - /// - /// The stream where this will be saved. - /// An that specifies the format of the saved image. - /// Flags to enable or disable plugin-features. - /// is a null reference. - /// Saving the image failed. - public void Save(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_SAVE_FLAGS flags) - { - EnsureNotDisposed(); - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - if (!FreeImage.SaveToStream(dib, stream, format, flags)) - { - throw new Exception("Unable to save bitmap"); - } - - saveInformation.filename = null; - } - - /// - /// Adds a frame to the file specified in a previous call to the - /// method. - /// - /// - /// This instance has not been saved to a file using Save(...) before. - public void SaveAdd() - { - SaveAdd(this); - } - - /// - /// Adds a frame to the file specified in a previous call to the method. - /// - /// The position at which the frame should be inserted. - /// - /// This instance has not yet been saved to a file using the Save(...) method. - /// is out of range. - public void SaveAdd(int insertPosition) - { - SaveAdd(this, insertPosition); - } - - /// - /// Adds a frame to the file specified in a previous call to the method. - /// - /// A that contains the frame to add. - /// - /// This instance has not yet been saved to a file using the Save(...) method. - public void SaveAdd(FreeImageBitmap bitmap) - { - if (saveInformation.filename == null) - { - throw new InvalidOperationException("This operation requires a previous call of Save()."); - } - - SaveAdd( - saveInformation.filename, - bitmap, - saveInformation.format, - saveInformation.loadFlags, - saveInformation.saveFlags); - } - - /// - /// Adds a frame to the file specified in a previous call to the method. - /// - /// A that contains the frame to add. - /// The position at which the frame should be inserted. - /// - /// This instance has not yet been saved to a file using the Save(...) method. - /// is out of range. - public void SaveAdd(FreeImageBitmap bitmap, int insertPosition) - { - if (saveInformation.filename == null) - { - throw new InvalidOperationException("This operation requires a previous call of Save()."); - } - - SaveAdd( - saveInformation.filename, - bitmap, - insertPosition, - saveInformation.format, - saveInformation.loadFlags, - saveInformation.saveFlags); - } - - /// - /// Adds a frame to the file specified. - /// - /// File to add this frame to. - /// is a null reference. - /// does not exist. - /// Saving the image has failed. - public void SaveAdd(string filename) - { - SaveAdd( - filename, - this, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - FREE_IMAGE_LOAD_FLAGS.DEFAULT, - FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - /// - /// Adds a frame to the file specified. - /// - /// File to add this frame to. - /// The position at which the frame should be inserted. - /// is a null reference. - /// does not exist. - /// Saving the image has failed. - /// is out of range. - public void SaveAdd(string filename, int insertPosition) - { - SaveAdd( - filename, - this, - insertPosition, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - FREE_IMAGE_LOAD_FLAGS.DEFAULT, - FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - /// - /// Adds a frame to the file specified using the specified parameters. - /// - /// File to add this frame to. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// Flags to enable or disable plugin-features. - /// is a null reference. - /// does not exist. - /// Saving the image has failed. - public void SaveAdd( - string filename, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_LOAD_FLAGS loadFlags, - FREE_IMAGE_SAVE_FLAGS saveFlags) - { - SaveAdd( - filename, - this, - format, - loadFlags, - saveFlags); - } - - /// - /// Adds a frame to the file specified using the specified parameters. - /// - /// File to add this frame to. - /// The position at which the frame should be inserted. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// Flags to enable or disable plugin-features. - /// is a null reference. - /// does not exist. - /// Saving the image has failed. - /// is out of range. - public void SaveAdd( - string filename, - int insertPosition, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_LOAD_FLAGS loadFlags, - FREE_IMAGE_SAVE_FLAGS saveFlags) - { - SaveAdd( - filename, - this, - insertPosition, - format, - loadFlags, - saveFlags); - } - - /// - /// Selects the frame specified by the index. - /// - /// The index of the active frame. - /// - /// is out of range. - /// The operation failed. - /// The source of the bitmap is not available. - /// - public void SelectActiveFrame(int frameIndex) - { - EnsureNotDisposed(); - if ((frameIndex < 0) || (frameIndex >= frameCount)) - { - throw new ArgumentOutOfRangeException("frameIndex"); - } - - if (frameIndex != this.frameIndex) - { - if (stream == null) - { - throw new InvalidOperationException("No source available."); - } - - FREE_IMAGE_FORMAT format = originalFormat; - FIMULTIBITMAP mdib = FreeImage.OpenMultiBitmapFromStream(stream, ref format, saveInformation.loadFlags); - if (mdib.IsNull) - throw new Exception(ErrorLoadingBitmap); - - try - { - if (frameIndex >= FreeImage.GetPageCount(mdib)) - { - throw new ArgumentOutOfRangeException("frameIndex"); - } - - FIBITMAP newDib = FreeImage.LockPage(mdib, frameIndex); - if (newDib.IsNull) - { - throw new Exception(ErrorLoadingFrame); - } - - try - { - FIBITMAP clone = FreeImage.Clone(newDib); - if (clone.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - ReplaceDib(clone); - } - finally - { - if (!newDib.IsNull) - { - FreeImage.UnlockPage(mdib, newDib, false); - } - } - } - finally - { - if (!FreeImage.CloseMultiBitmapEx(ref mdib)) - { - throw new Exception(ErrorUnloadBitmap); - } - } - - this.frameIndex = frameIndex; - } - } - - /// - /// Creates a GDI bitmap object from this . - /// - /// A handle to the GDI bitmap object that this method creates. - public IntPtr GetHbitmap() - { - EnsureNotDisposed(); - return FreeImage.GetHbitmap(dib, IntPtr.Zero, false); - } - - /// - /// Creates a GDI bitmap object from this . - /// - /// A structure that specifies the background color. - /// This parameter is ignored if the bitmap is totally opaque. - /// A handle to the GDI bitmap object that this method creates. - public IntPtr GetHbitmap(Color background) - { - EnsureNotDisposed(); - using (FreeImageBitmap temp = new FreeImageBitmap(this)) - { - temp.BackgroundColor = background; - return temp.GetHbitmap(); - } - } - - /// - /// Returns the handle to an icon. - /// - /// A Windows handle to an icon with the same image as this . - public IntPtr GetHicon() - { - EnsureNotDisposed(); - using (Bitmap bitmap = FreeImage.GetBitmap(dib, true)) - { - return bitmap.GetHicon(); - } - } - - /// - /// Creates a GDI bitmap object from this with the same - /// color depth as the primary device. - /// - /// A handle to the GDI bitmap object that this method creates. - public IntPtr GetHbitmapForDevice() - { - EnsureNotDisposed(); - return FreeImage.GetBitmapForDevice(dib, IntPtr.Zero, false); - } - - /// - /// Gets the of the specified pixel in this . - /// - /// The x-coordinate of the pixel to retrieve. - /// The y-coordinate of the pixel to retrieve. - /// A structure that represents the color of the specified pixel. - /// The operation failed. - /// The type of this bitmap is not supported. - public unsafe Color GetPixel(int x, int y) - { - EnsureNotDisposed(); - if (FreeImage.GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) - { - if (ColorDepth == 16 || ColorDepth == 24 || ColorDepth == 32) - { - RGBQUAD rgbq; - if (!FreeImage.GetPixelColor(dib, (uint)x, (uint)y, out rgbq)) - { - throw new Exception("FreeImage.GetPixelColor() failed"); - } - return rgbq.Color; - } - else if (ColorDepth == 1 || ColorDepth == 4 || ColorDepth == 8) - { - byte index; - if (!FreeImage.GetPixelIndex(dib, (uint)x, (uint)y, out index)) - { - throw new Exception("FreeImage.GetPixelIndex() failed"); - } - RGBQUAD* palette = (RGBQUAD*)FreeImage.GetPalette(dib); - return palette[index].Color; - } - } - throw new NotSupportedException("The type of the image is not supported"); - } - - /// - /// Makes the default transparent color transparent for this . - /// - public void MakeTransparent() - { - EnsureNotDisposed(); - MakeTransparent(Color.Transparent); - } - - /// - /// Makes the specified color transparent for this . - /// - /// The structure that represents - /// the color to make transparent. - /// - /// This method is not implemented. - public void MakeTransparent(Color transparentColor) - { - EnsureNotDisposed(); - throw new System.NotImplementedException(); - } - - /// - /// Sets the of the specified pixel in this . - /// - /// The x-coordinate of the pixel to set. - /// The y-coordinate of the pixel to set. - /// A structure that represents the color - /// to assign to the specified pixel. - /// The operation failed. - /// The type of this bitmap is not supported. - public unsafe void SetPixel(int x, int y, Color color) - { - EnsureNotDisposed(); - if (FreeImage.GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) - { - if (ColorDepth == 16 || ColorDepth == 24 || ColorDepth == 32) - { - RGBQUAD rgbq = color; - if (!FreeImage.SetPixelColor(dib, (uint)x, (uint)y, ref rgbq)) - { - throw new Exception("FreeImage.SetPixelColor() failed"); - } - return; - } - else if (ColorDepth == 1 || ColorDepth == 4 || ColorDepth == 8) - { - uint colorsUsed = FreeImage.GetColorsUsed(dib); - RGBQUAD* palette = (RGBQUAD*)FreeImage.GetPalette(dib); - for (int i = 0; i < colorsUsed; i++) - { - if (palette[i].Color == color) - { - byte index = (byte)i; - if (!FreeImage.SetPixelIndex(dib, (uint)x, (uint)y, ref index)) - { - throw new Exception("FreeImage.SetPixelIndex() failed"); - } - return; - } - } - throw new ArgumentOutOfRangeException("color"); - } - } - throw new NotSupportedException("The type of the image is not supported"); - } - - /// - /// Sets the resolution for this . - /// - /// The horizontal resolution, in dots per inch, of this . - /// The vertical resolution, in dots per inch, of this . - public void SetResolution(float xDpi, float yDpi) - { - EnsureNotDisposed(); - FreeImage.SetResolutionX(dib, (uint)xDpi); - FreeImage.SetResolutionY(dib, (uint)yDpi); - } - - /// - /// This function is not yet implemented. - /// - /// - /// This method is not implemented. - public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format) - { - throw new NotImplementedException(); - } - - /// - /// This function is not yet implemented. - /// - /// - /// This method is not implemented. - public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData) - { - throw new NotImplementedException(); - } - - /// - /// This function is not yet implemented. - /// - /// - /// This method is not implemented. - public void UnlockBits(BitmapData bitmapdata) - { - throw new NotImplementedException(); - } - - /// - /// Converts this into a different color depth. - /// The parameter specifies color depth, greyscale conversion - /// and palette reorder. - /// Adding the flag - /// will first perform a convesion to greyscale. This can be done with any target - /// color depth. - /// Adding the flag - /// will allow the algorithm to reorder the palette. This operation will not be performed to - /// non-greyscale images to prevent data loss by mistake. - /// - /// A bitfield containing information about the conversion - /// to perform. - /// Returns true on success, false on failure. - public bool ConvertColorDepth(FREE_IMAGE_COLOR_DEPTH bpp) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.ConvertColorDepth(dib, bpp, false)); - } - - /// - /// Converts this to - /// initializing a new instance. - /// In case source and destination type are the same, the operation fails. - /// An error message can be catched using the 'Message' event. - /// - /// Destination type. - /// True to scale linear, else false. - /// Returns true on success, false on failure. - public bool ConvertType(FREE_IMAGE_TYPE type, bool scaleLinear) - { - EnsureNotDisposed(); - return (ImageType == type) ? false : ReplaceDib(FreeImage.ConvertToType(dib, type, scaleLinear)); - } - - /// - /// Converts this to . - /// In case source and destination type are the same, the operation fails. - /// An error message can be catched using the 'Message' event. - /// - /// Destination type. - /// True to scale linear, else false. - /// The converted instance. - public FreeImageBitmap GetTypeConvertedInstance(FREE_IMAGE_TYPE type, bool scaleLinear) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - if (ImageType != type) - { - FIBITMAP newDib = FreeImage.ConvertToType(dib, type, scaleLinear); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - } - return result; - } - - /// - /// Converts this into a different color depth initializing - /// a new instance. - /// The parameter specifies color depth, greyscale conversion - /// and palette reorder. - /// Adding the flag will - /// first perform a convesion to greyscale. This can be done with any target color depth. - /// Adding the flag will - /// allow the algorithm to reorder the palette. This operation will not be performed to - /// non-greyscale images to prevent data loss by mistake. - /// - /// A bitfield containing information about the conversion - /// to perform. - /// The converted instance. - public FreeImageBitmap GetColorConvertedInstance(FREE_IMAGE_COLOR_DEPTH bpp) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.ConvertColorDepth(dib, bpp, false); - if (newDib == dib) - { - newDib = FreeImage.Clone(dib); - } - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Rescales this to the specified size using the - /// specified filter. - /// - /// The Size structure that represent the - /// size of the new . - /// Filter to use for resizing. - /// Returns true on success, false on failure. - public bool Rescale(Size newSize, FREE_IMAGE_FILTER filter) - { - return Rescale(newSize.Width, newSize.Height, filter); - } - - /// - /// Rescales this to the specified size using the - /// specified filter. - /// - /// Width of the new . - /// Height of the new . - /// Filter to use for resizing. - /// Returns true on success, false on failure. - public bool Rescale(int width, int height, FREE_IMAGE_FILTER filter) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.Rescale(dib, width, height, filter)); - } - - /// - /// Rescales this to the specified size using the - /// specified filter initializing a new instance. - /// - /// The Size structure that represent the - /// size of the new . - /// Filter to use for resizing. - /// The rescaled instance. - public FreeImageBitmap GetScaledInstance(Size newSize, FREE_IMAGE_FILTER filter) - { - return GetScaledInstance(newSize.Width, newSize.Height, filter); - } - - /// - /// Rescales this to the specified size using the - /// specified filter initializing a new instance. - /// - /// Width of the new . - /// Height of the new . - /// Filter to use for resizing. - /// The rescaled instance. - public FreeImageBitmap GetScaledInstance(int width, int height, FREE_IMAGE_FILTER filter) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.Rescale(dib, width, height, filter); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Enlarges or shrinks this selectively per side and fills - /// newly added areas with the specified background color. - /// See for further details. - /// - /// The type of the specified color. - /// The number of pixels, the image should be enlarged on its left side. - /// Negative values shrink the image on its left side. - /// The number of pixels, the image should be enlarged on its top side. - /// Negative values shrink the image on its top side. - /// The number of pixels, the image should be enlarged on its right side. - /// Negative values shrink the image on its right side. - /// The number of pixels, the image should be enlarged on its bottom side. - /// Negative values shrink the image on its bottom side. - /// The color, the enlarged sides of the image should be filled with. - /// true on success, false on failure. - public bool EnlargeCanvas(int left, int top, int right, int bottom, T? color) where T : struct - { - return EnlargeCanvas(left, top, right, bottom, color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT); - } - - /// - /// Enlarges or shrinks this selectively per side and fills - /// newly added areas with the specified background color. - /// See for further details. - /// - /// The type of the specified color. - /// The number of pixels, the image should be enlarged on its left side. - /// Negative values shrink the image on its left side. - /// The number of pixels, the image should be enlarged on its top side. - /// Negative values shrink the image on its top side. - /// The number of pixels, the image should be enlarged on its right side. - /// Negative values shrink the image on its right side. - /// The number of pixels, the image should be enlarged on its bottom side. - /// Negative values shrink the image on its bottom side. - /// The color, the enlarged sides of the image should be filled with. - /// Options that affect the color search process for palletized images. - /// true on success, false on failure. - public bool EnlargeCanvas(int left, int top, int right, int bottom, - T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.EnlargeCanvas(dib, left, top, right, bottom, color, options)); - } - - /// - /// Enlarges or shrinks this selectively per side and fills - /// newly added areas with the specified background color returning a new instance. - /// See for further details. - /// - /// The type of the specified color. - /// The number of pixels, the image should be enlarged on its left side. - /// Negative values shrink the image on its left side. - /// The number of pixels, the image should be enlarged on its top side. - /// Negative values shrink the image on its top side. - /// The number of pixels, the image should be enlarged on its right side. - /// Negative values shrink the image on its right side. - /// The number of pixels, the image should be enlarged on its bottom side. - /// Negative values shrink the image on its bottom side. - /// The color, the enlarged sides of the image should be filled with. - /// The enlarged instance. - public FreeImageBitmap GetEnlargedInstance(int left, int top, int right, int bottom, - T? color) where T : struct - { - return GetEnlargedInstance(left, top, right, bottom, color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT); - } - - /// - /// Enlarges or shrinks this selectively per side and fills - /// newly added areas with the specified background color returning a new instance. - /// See for further details. - /// - /// The type of the specified color. - /// The number of pixels, the image should be enlarged on its left side. - /// Negative values shrink the image on its left side. - /// The number of pixels, the image should be enlarged on its top side. - /// Negative values shrink the image on its top side. - /// The number of pixels, the image should be enlarged on its right side. - /// Negative values shrink the image on its right side. - /// The number of pixels, the image should be enlarged on its bottom side. - /// Negative values shrink the image on its bottom side. - /// The color, the enlarged sides of the image should be filled with. - /// Options that affect the color search process for palletized images. - /// The enlarged instance. - public FreeImageBitmap GetEnlargedInstance(int left, int top, int right, int bottom, - T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.EnlargeCanvas(dib, left, top, right, bottom, color, options); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Quantizes this from 24 bit to 8bit creating a new - /// palette with the specified using the specified - /// . - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// Returns true on success, false on failure. - public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize) - { - return Quantize(algorithm, paletteSize, 0, (RGBQUAD[])null); - } - - /// - /// Quantizes this from 24 bit to 8bit creating a new - /// palette with the specified using the specified - /// and the specified - /// palette up to the - /// specified length. - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// The provided palette. - /// Returns true on success, false on failure. - public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, Palette reservePalette) - { - return Quantize(algorithm, paletteSize, reservePalette.Length, reservePalette.Data); - } - - /// - /// Quantizes this from 24 bit to 8bit creating a new - /// palette with the specified using the specified - /// and the specified - /// palette up to the - /// specified length. - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// Size of the provided palette of ReservePalette. - /// The provided palette. - /// Returns true on success, false on failure. - public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, Palette reservePalette) - { - return Quantize(algorithm, paletteSize, reserveSize, reservePalette.Data); - } - - /// - /// Quantizes this from 24 bit to 8bit creating a new - /// palette with the specified using the specified - /// and the specified - /// palette up to the - /// specified length. - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// Size of the provided palette of ReservePalette. - /// The provided palette. - /// Returns true on success, false on failure. - public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, RGBQUAD[] reservePalette) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.ColorQuantizeEx(dib, algorithm, paletteSize, reserveSize, reservePalette)); - } - - /// - /// Quantizes this from 24 bit, using the specified - /// initializing a new 8 bit instance with the - /// specified . - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// The quantized instance. - public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize) - { - return GetQuantizedInstance(algorithm, paletteSize, 0, (RGBQUAD[])null); - } - - /// - /// Quantizes this from 24 bit, using the specified - /// and palette - /// initializing a new 8 bit instance with the specified . - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// The provided palette. - /// The quantized instance. - public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, Palette reservePalette) - { - return GetQuantizedInstance(algorithm, paletteSize, reservePalette.Length, reservePalette); - } - - /// - /// Quantizes this from 24 bit, using the specified - /// and up to - /// entries from palette initializing - /// a new 8 bit instance with the specified . - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// Size of the provided palette. - /// The provided palette. - /// The quantized instance. - public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, Palette reservePalette) - { - return GetQuantizedInstance(algorithm, paletteSize, reserveSize, reservePalette.Data); - } - - /// - /// Quantizes this from 24 bit, using the specified - /// and up to - /// entries from palette initializing - /// a new 8 bit instance with the specified . - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// Size of the provided palette. - /// The provided palette. - /// The quantized instance. - public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, RGBQUAD[] reservePalette) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.ColorQuantizeEx(dib, algorithm, paletteSize, reserveSize, reservePalette); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Converts a High Dynamic Range image to a 24-bit RGB image using a global - /// operator based on logarithmic compression of luminance values, imitating - /// the human response to light. - /// - /// A gamma correction that is applied after the tone mapping. - /// A value of 1 means no correction. - /// Scale factor allowing to adjust the brightness of the output image. - /// Returns true on success, false on failure. - public bool TmoDrago03(double gamma, double exposure) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.TmoDrago03(dib, gamma, exposure)); - } - - /// - /// Converts a High Dynamic Range image to a 24-bit RGB image using a global operator inspired - /// by photoreceptor physiology of the human visual system. - /// - /// Controls the overall image intensity in the range [-8, 8]. - /// Controls the overall image contrast in the range [0.3, 1.0[. - /// Returns true on success, false on failure. - public bool TmoReinhard05(double intensity, double contrast) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.TmoReinhard05(dib, intensity, contrast)); - } - - /// - /// Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and convert to 24-bit RGB. - /// - /// Color saturation (s parameter in the paper) in [0.4..0.6] - /// Atenuation factor (beta parameter in the paper) in [0.8..0.9] - /// Returns true on success, false on failure. - public bool TmoFattal02(double color_saturation, double attenuation) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.TmoFattal02(dib, color_saturation, attenuation)); - } - - /// - /// This method rotates a 1-, 4-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. - /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer - /// multiple of 90. - /// - /// The angle of rotation. - /// Returns true on success, false on failure. - public bool Rotate(double angle) - { - EnsureNotDisposed(); - bool result = false; - if (ColorDepth == 4) - { - result = ReplaceDib(FreeImage.Rotate4bit(dib, angle)); - } - else - { - result = ReplaceDib(FreeImage.Rotate(dib, angle)); - } - return result; - } - - /// - /// This method rotates a 1-, 4-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. - /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer - /// multiple of 90. - /// - /// The type of the color to use as background. - /// The angle of rotation. - /// The color used used to fill the bitmap's background. - /// Returns true on success, false on failure. - public bool Rotate(double angle, T? backgroundColor) where T : struct - { - EnsureNotDisposed(); - bool result = false; - if (ColorDepth == 4) - { - result = ReplaceDib(FreeImage.Rotate4bit(dib, angle)); - } - else - { - result = ReplaceDib(FreeImage.Rotate(dib, angle, backgroundColor)); - } - return result; - } - - /// - /// Rotates this by the specified angle initializing a new instance. - /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer - /// multiple of 90. - /// - /// The type of the color to use as background. - /// The angle of rotation. - /// The color used used to fill the bitmap's background. - /// The rotated instance. - public FreeImageBitmap GetRotatedInstance(double angle, T? backgroundColor) where T : struct - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib; - if (ColorDepth == 4) - { - newDib = FreeImage.Rotate4bit(dib, angle); - } - else - { - newDib = FreeImage.Rotate(dib, angle, backgroundColor); - } - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Rotates this by the specified angle initializing a new instance. - /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer - /// multiple of 90. - /// - /// The angle of rotation. - /// The rotated instance. - public FreeImageBitmap GetRotatedInstance(double angle) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib; - if (ColorDepth == 4) - { - newDib = FreeImage.Rotate4bit(dib, angle); - } - else - { - newDib = FreeImage.Rotate(dib, angle); - } - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// This method performs a rotation and / or translation of an 8-bit greyscale, - /// 24- or 32-bit image, using a 3rd order (cubic) B-Spline. - /// - /// The angle of rotation. - /// Horizontal image translation. - /// Vertical image translation. - /// Rotation center x-coordinate. - /// Rotation center y-coordinate. - /// When true the irrelevant part of the image is set to a black color, - /// otherwise, a mirroring technique is used to fill irrelevant pixels. - /// Returns true on success, false on failure. - public bool Rotate(double angle, double xShift, double yShift, - double xOrigin, double yOrigin, bool useMask) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.RotateEx(dib, angle, xShift, yShift, xOrigin, yOrigin, useMask)); - } - - /// - /// This method performs a rotation and / or translation of an 8-bit greyscale, - /// 24- or 32-bit image, using a 3rd order (cubic) B-Spline initializing a new instance. - /// - /// The angle of rotation. - /// Horizontal image translation. - /// Vertical image translation. - /// Rotation center x-coordinate. - /// Rotation center y-coordinate. - /// When true the irrelevant part of the image is set to a black color, - /// otherwise, a mirroring technique is used to fill irrelevant pixels. - /// The rotated instance. - public FreeImageBitmap GetRotatedInstance(double angle, double xShift, double yShift, - double xOrigin, double yOrigin, bool useMask) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.RotateEx( - dib, angle, xShift, yShift, xOrigin, yOrigin, useMask); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Perfoms an histogram transformation on a 8-, 24- or 32-bit image. - /// - /// The lookup table (LUT). - /// It's size is assumed to be 256 in length. - /// The color channel to be transformed. - /// Returns true on success, false on failure. - public bool AdjustCurve(byte[] lookUpTable, FREE_IMAGE_COLOR_CHANNEL channel) - { - EnsureNotDisposed(); - return FreeImage.AdjustCurve(dib, lookUpTable, channel); - } - - /// - /// Performs gamma correction on a 8-, 24- or 32-bit image. - /// - /// The parameter represents the gamma value to use (gamma > 0). - /// A value of 1.0 leaves the image alone, less than one darkens it, and greater than one lightens it. - /// Returns true on success, false on failure. - public bool AdjustGamma(double gamma) - { - EnsureNotDisposed(); - return FreeImage.AdjustGamma(dib, gamma); - } - - /// - /// Adjusts the brightness of a 8-, 24- or 32-bit image by a certain amount. - /// - /// A value 0 means no change, - /// less than 0 will make the image darker and greater than 0 will make the image brighter. - /// Returns true on success, false on failure. - public bool AdjustBrightness(double percentage) - { - EnsureNotDisposed(); - return FreeImage.AdjustBrightness(dib, percentage); - } - - /// - /// Adjusts the contrast of a 8-, 24- or 32-bit image by a certain amount. - /// - /// A value 0 means no change, - /// less than 0 will decrease the contrast and greater than 0 will increase the contrast of the image. - /// Returns true on success, false on failure. - public bool AdjustContrast(double percentage) - { - EnsureNotDisposed(); - return FreeImage.AdjustContrast(dib, percentage); - } - - /// - /// Inverts each pixel data. - /// - /// Returns true on success, false on failure. - public bool Invert() - { - EnsureNotDisposed(); - return FreeImage.Invert(dib); - } - - /// - /// Computes the image histogram. - /// - /// Channel to compute from. - /// Array of integers containing the histogram. - /// Returns true on success, false on failure. - public bool GetHistogram(FREE_IMAGE_COLOR_CHANNEL channel, out int[] histogram) - { - EnsureNotDisposed(); - histogram = new int[256]; - return FreeImage.GetHistogram(dib, histogram, channel); - } - - /// - /// Retrieves the red, green, blue or alpha channel of a 24- or 32-bit image. - /// - /// The color channel to extract. - /// The color channel in a new instance. - public FreeImageBitmap GetChannel(FREE_IMAGE_COLOR_CHANNEL channel) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.GetChannel(dib, channel); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Insert a 8-bit dib into a 24- or 32-bit image. - /// Both images must have to same width and height. - /// - /// The to insert. - /// The color channel to replace. - /// Returns true on success, false on failure. - public bool SetChannel(FreeImageBitmap bitmap, FREE_IMAGE_COLOR_CHANNEL channel) - { - EnsureNotDisposed(); - bitmap.EnsureNotDisposed(); - return FreeImage.SetChannel(dib, bitmap.dib, channel); - } - - /// - /// Retrieves the real part, imaginary part, magnitude or phase of a complex image. - /// - /// The color channel to extract. - /// The color channel in a new instance. - public FreeImageBitmap GetComplexChannel(FREE_IMAGE_COLOR_CHANNEL channel) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.GetComplexChannel(dib, channel); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Set the real or imaginary part of a complex image. - /// Both images must have to same width and height. - /// - /// The to insert. - /// The color channel to replace. - /// Returns true on success, false on failure. - public bool SetComplexChannel(FreeImageBitmap bitmap, FREE_IMAGE_COLOR_CHANNEL channel) - { - EnsureNotDisposed(); - bitmap.EnsureNotDisposed(); - return FreeImage.SetComplexChannel(dib, bitmap.dib, channel); - } - - /// - /// Copy a sub part of this . - /// - /// The subpart to copy. - /// The sub part in a new instance. - public FreeImageBitmap Copy(Rectangle rect) - { - EnsureNotDisposed(); - return Copy(rect.Left, rect.Top, rect.Right, rect.Bottom); - } - - /// - /// Copy a sub part of this . - /// - /// Specifies the left position of the cropped rectangle. - /// Specifies the top position of the cropped rectangle. - /// Specifies the right position of the cropped rectangle. - /// Specifies the bottom position of the cropped rectangle. - /// The sub part in a new instance. - public FreeImageBitmap Copy(int left, int top, int right, int bottom) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.Copy(dib, left, top, right, bottom); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Alpha blend or combine a sub part image with this . - /// The bit depth of must be greater than or equal to the bit depth this instance. - /// - /// The to paste into this instance. - /// Specifies the left position of the sub image. - /// Specifies the top position of the sub image. - /// alpha blend factor. - /// The source and destination images are alpha blended if alpha=0..255. - /// If alpha > 255, then the source image is combined to the destination image. - /// Returns true on success, false on failure. - public bool Paste(FreeImageBitmap bitmap, int left, int top, int alpha) - { - EnsureNotDisposed(); - bitmap.EnsureNotDisposed(); - return FreeImage.Paste(dib, bitmap.dib, left, top, alpha); - } - - /// - /// Alpha blend or combine a sub part image with tthis . - /// The bit depth of must be greater than or equal to the bit depth this instance. - /// - /// The to paste into this instance. - /// Specifies the position of the sub image. - /// alpha blend factor. - /// The source and destination images are alpha blended if alpha=0..255. - /// If alpha > 255, then the source image is combined to the destination image. - /// Returns true on success, false on failure. - public bool Paste(FreeImageBitmap bitmap, Point point, int alpha) - { - EnsureNotDisposed(); - return Paste(bitmap, point.X, point.Y, alpha); - } - - /// - /// This method composite a transparent foreground image against a single background color or - /// against a background image. - /// In case is false and - /// and - /// are null, a checkerboard will be used as background. - /// - /// When true the background of this instance is used - /// if it contains one. - /// Backgroundcolor used in case is false - /// and is not null. - /// Background used in case - /// is false and is a null reference. - /// Returns true on success, false on failure. - public bool Composite(bool useBitmapBackground, Color? applicationBackground, FreeImageBitmap bitmapBackGround) - { - EnsureNotDisposed(); - bitmapBackGround.EnsureNotDisposed(); - RGBQUAD? rgb = applicationBackground; - return ReplaceDib( - FreeImage.Composite( - dib, - useBitmapBackground, - rgb.HasValue ? new RGBQUAD[] { rgb.Value } : null, - bitmapBackGround.dib)); - } - - /// - /// Applies the alpha value of each pixel to its color components. - /// The aplha value stays unchanged. - /// Only works with 32-bits color depth. - /// - /// Returns true on success, false on failure. - public bool PreMultiplyWithAlpha() - { - EnsureNotDisposed(); - return FreeImage.PreMultiplyWithAlpha(dib); - } - - /// - /// Solves a Poisson equation, remap result pixels to [0..1] and returns the solution. - /// - /// Number of cycles in the multigrid algorithm (usually 2 or 3) - /// Returns true on success, false on failure. - public bool MultigridPoissonSolver(int ncycle) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.MultigridPoissonSolver(dib, ncycle)); - } - - /// - /// Adjusts an image's brightness, contrast and gamma as well as it may - /// optionally invert the image within a single operation. - /// - /// Percentage brightness value where -100 <= brightness <= 100. - /// A value of 0 means no change, less than 0 will make the image darker and greater - /// than 0 will make the image brighter. - /// Percentage contrast value where -100 <= contrast <= 100. - /// A value of 0 means no change, less than 0 will decrease the contrast - /// and greater than 0 will increase the contrast of the image. - /// Gamma value to be used for gamma correction. - /// A value of 1.0 leaves the image alone, less than one darkens it, - /// and greater than one lightens it. - /// This parameter must not be zero or smaller than zero. - /// If so, it will be ignored and no gamma correction will be performed on the image. - /// If set to true, the image will be inverted. - /// Returns true on success, false on failure. - public bool AdjustColors(double brightness, double contrast, double gamma, bool invert) - { - EnsureNotDisposed(); - return FreeImage.AdjustColors(dib, brightness, contrast, gamma, invert); - } - - /// - /// Applies color mapping for one or several colors on a 1-, 4- or 8-bit - /// palletized or a 16-, 24- or 32-bit high color image. - /// - /// Array of colors to be used as the mapping source. - /// Array of colors to be used as the mapping destination. - /// If true, 32-bit images and colors are treated as 24-bit. - /// If true, source and destination colors are swapped, that is, - /// each destination color is also mapped to the corresponding source color. - /// The total number of pixels changed. - /// - /// or is a null reference. - /// - /// - /// has a different length than . - /// - public uint ApplyColorMapping(RGBQUAD[] srccolors, RGBQUAD[] dstcolors, bool ignore_alpha, bool swap) - { - EnsureNotDisposed(); - if (srccolors == null) - { - throw new ArgumentNullException("srccolors"); - } - if (dstcolors == null) - { - throw new ArgumentNullException("dstcolors"); - } - if (srccolors.Length != dstcolors.Length) - { - throw new ArgumentException("srccolors and dstcolors must have the same length."); - } - return FreeImage.ApplyColorMapping(dib, srccolors, dstcolors, (uint)srccolors.Length, ignore_alpha, swap); - } - - /// - /// Swaps two specified colors on a 1-, 4- or 8-bit palletized - /// or a 16-, 24- or 32-bit high color image. - /// - /// One of the two colors to be swapped. - /// The other of the two colors to be swapped. - /// If true, 32-bit images and colors are treated as 24-bit. - /// The total number of pixels changed. - public uint SwapColors(RGBQUAD color_a, RGBQUAD color_b, bool ignore_alpha) - { - EnsureNotDisposed(); - return FreeImage.SwapColors(dib, ref color_a, ref color_b, ignore_alpha); - } - - /// - /// Applies palette index mapping for one or several indices - /// on a 1-, 4- or 8-bit palletized image. - /// - /// Array of palette indices to be used as the mapping source. - /// Array of palette indices to be used as the mapping destination. - /// The number of palette indices to be mapped. This is the size of both - /// srcindices and dstindices - /// If true, source and destination palette indices are swapped, that is, - /// each destination index is also mapped to the corresponding source index. - /// The total number of pixels changed. - /// - /// or is a null reference. - /// - /// - /// has a different length than . - /// - public uint ApplyPaletteIndexMapping(byte[] srcindices, byte[] dstindices, uint count, bool swap) - { - EnsureNotDisposed(); - if (srcindices == null) - { - throw new ArgumentNullException("srcindices"); - } - if (dstindices == null) - { - throw new ArgumentNullException("dstindices"); - } - if (srcindices.Length != dstindices.Length) - { - throw new ArgumentException("srcindices and dstindices must have the same length."); - } - return FreeImage.ApplyPaletteIndexMapping(dib, srcindices, dstindices, (uint)srcindices.Length, swap); - } - - /// - /// Swaps two specified palette indices on a 1-, 4- or 8-bit palletized image. - /// - /// One of the two palette indices to be swapped. - /// The other of the two palette indices to be swapped. - /// The total number of pixels changed. - public uint SwapPaletteIndices(byte index_a, byte index_b) - { - EnsureNotDisposed(); - return FreeImage.SwapPaletteIndices(dib, ref index_a, ref index_b); - } - - /// - /// Sets all pixels of this to the specified color. - /// See for further details. - /// - /// The type of the specified color. - /// The color to fill this with. - /// true on success, false on failure. - public bool FillBackground(T color) where T : struct - { - return FillBackground(color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT); - } - - /// - /// Sets all pixels of this to the specified color. - /// See for further details. - /// - /// The type of the specified color. - /// The color to fill this with. - /// Options that affect the color search process for palletized images. - /// true on success, false on failure. - public bool FillBackground(T color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct - { - EnsureNotDisposed(); - return FreeImage.FillBackground(dib, color, options); - } - - /// - /// Creates a new ICC-Profile. - /// - /// The data of the new ICC-Profile. - /// The new ICC-Profile of the bitmap. - /// is a null reference. - public FIICCPROFILE CreateICCProfile(byte[] data) - { - if (data == null) - { - throw new ArgumentNullException("data"); - } - return CreateICCProfile(data, data.Length); - } - - /// - /// Creates a new ICC-Profile. - /// - /// The data of the new ICC-Profile. - /// The number of bytes of to use. - /// The new ICC-Profile of the bitmap. - /// is null. - public FIICCPROFILE CreateICCProfile(byte[] data, int size) - { - EnsureNotDisposed(); - if (data == null) - { - throw new ArgumentNullException("data"); - } - return FreeImage.CreateICCProfileEx(dib, data, size); - } - - /// - /// Determines whether this and the specified instances are the same. - /// - /// The object to test. - /// true if this instance is the same - /// or if both are null references; otherwise, false. - public override bool Equals(object obj) - { - return ReferenceEquals(this, obj); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return dib.GetHashCode(); - } - - #endregion - - #region Static functions - - /// - /// Returns a value that indicates whether the pixel format for this contains alpha information. - /// - /// The to test. - /// true if pixfmt contains alpha information; otherwise, false. - public static bool IsAlphaPixelFormat(PixelFormat pixfmt) - { - return Bitmap.IsAlphaPixelFormat(pixfmt); - } - - /// - /// Returns a value that indicates whether the pixel format is 32 bits per pixel. - /// - /// The to test. - /// true if pixfmt is canonical; otherwise, false. - public static bool IsCanonicalPixelFormat(PixelFormat pixfmt) - { - return Bitmap.IsCanonicalPixelFormat(pixfmt); - } - - /// - /// Returns a value that indicates whether the pixel format is 64 bits per pixel. - /// - /// The enumeration to test. - /// true if pixfmt is extended; otherwise, false. - public static bool IsExtendedPixelFormat(PixelFormat pixfmt) - { - return Bitmap.IsExtendedPixelFormat(pixfmt); - } - - /// - /// Creates a from a Windows handle to an icon. - /// - /// A handle to an icon. - /// The that this method creates. - public static FreeImageBitmap FromHicon(IntPtr hicon) - { - using (Bitmap bitmap = Bitmap.FromHicon(hicon)) - { - return new FreeImageBitmap(bitmap); - } - } - - /// - /// Creates a from the specified Windows resource. - /// - /// A handle to an instance of the executable - /// file that contains the resource. - /// A string containing the name of the resource bitmap. - /// The that this method creates. - public static FreeImageBitmap FromResource(IntPtr hinstance, string bitmapName) - { - using (Bitmap bitmap = Bitmap.FromResource(hinstance, bitmapName)) - { - return new FreeImageBitmap(bitmap); - } - } - - /// - /// Creates a from the specified file. - /// - /// A string that contains the name of the file - /// from which to create the . - /// The this method creates. - public static FreeImageBitmap FromFile(string filename) - { - return new FreeImageBitmap(filename); - } - - /// - /// Creates a from the specified file - /// using embedded color management information in that file. - /// - /// A string that contains the - /// name of the file from which to create the . - /// Ignored. - /// The this method creates. - public static FreeImageBitmap FromFile(string filename, bool useEmbeddedColorManagement) - { - return new FreeImageBitmap(filename); - } - - /// - /// Creates a from a handle to a GDI bitmap. - /// - /// The GDI bitmap handle from which to create the . - /// The this method creates. - public static FreeImageBitmap FromHbitmap(IntPtr hbitmap) - { - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.CreateFromHbitmap(hbitmap, IntPtr.Zero); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Creates a from a handle to a GDI bitmap and a handle to a GDI palette. - /// - /// The GDI bitmap handle from which to create the . - /// Ignored. - /// The this method creates. - public static FreeImageBitmap FromHbitmap(IntPtr hbitmap, IntPtr hpalette) - { - return FromHbitmap(hbitmap); - } - - /// - /// Frees a bitmap handle. - /// - /// Handle to a bitmap. - /// true on success, false on failure. - public static bool FreeHbitmap(IntPtr hbitmap) - { - return FreeImage.FreeHbitmap(hbitmap); - } - - /// - /// Creates a from the specified data stream. - /// - /// A that contains the data for this . - /// The this method creates. - public static FreeImageBitmap FromStream(Stream stream) - { - return new FreeImageBitmap(stream); - } - - /// - /// Creates a from the specified data stream. - /// - /// A that contains the data for this . - /// Ignored. - /// The this method creates. - public static FreeImageBitmap FromStream(Stream stream, bool useEmbeddedColorManagement) - { - return new FreeImageBitmap(stream); - } - - /// - /// Creates a from the specified data stream. - /// - /// A that contains the data for this . - /// Ignored. - /// Ignored. - /// The this method creates. - public static FreeImageBitmap FromStream(Stream stream, bool useEmbeddedColorManagement, bool validateImageData) - { - return new FreeImageBitmap(stream); - } - - /// - /// Returns the color depth, in number of bits per pixel, - /// of the specified pixel format. - /// - /// The member that specifies - /// the format for which to find the size. - /// The color depth of the specified pixel format. - public static int GetPixelFormatSize(PixelFormat pixfmt) - { - return Bitmap.GetPixelFormatSize(pixfmt); - } - - /// - /// Performs a lossless rotation or flipping on a JPEG file. - /// - /// Source file. - /// Destination file; can be the source file; will be overwritten. - /// The operation to apply. - /// To avoid lossy transformation, you can set the perfect parameter to true. - /// Returns true on success, false on failure. - public static bool JPEGTransform(string source, string destination, FREE_IMAGE_JPEG_OPERATION operation, bool perfect) - { - return FreeImage.JPEGTransform(source, destination, operation, perfect); - } - - /// - /// Performs a lossless crop on a JPEG file. - /// - /// Source filename. - /// Destination filename. - /// Specifies the cropped rectangle. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// - /// does not exist. - /// - public static bool JPEGCrop(string source, string destination, Rectangle rect) - { - if (source == null) - { - throw new ArgumentNullException("source"); - } - if (!File.Exists(source)) - { - throw new FileNotFoundException("source"); - } - if (destination == null) - { - throw new ArgumentNullException("destination"); - } - return JPEGCrop(source, destination, rect.Left, rect.Top, rect.Right, rect.Bottom); - } - - /// - /// Performs a lossless crop on a JPEG file. - /// - /// Source filename. - /// Destination filename. - /// Specifies the left position of the cropped rectangle. - /// Specifies the top position of the cropped rectangle. - /// Specifies the right position of the cropped rectangle. - /// Specifies the bottom position of the cropped rectangle. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// - /// does not exist. - /// - public static bool JPEGCrop(string source, string destination, int left, int top, int right, int bottom) - { - if (source == null) - { - throw new ArgumentNullException("source"); - } - if (!File.Exists(source)) - { - throw new FileNotFoundException("source"); - } - if (destination == null) - { - throw new ArgumentNullException("destination"); - } - return FreeImage.JPEGCrop(source, destination, left, top, right, bottom); - } - - /// - /// Converts a X11 color name into a corresponding RGB value. - /// - /// Name of the color to convert. - /// Red component. - /// Green component. - /// Blue component. - /// Returns true on success, false on failure. - /// is null. - public static bool LookupX11Color(string color, out byte red, out byte green, out byte blue) - { - if (color == null) - { - throw new ArgumentNullException("color"); - } - return FreeImage.LookupX11Color(color, out red, out green, out blue); - } - - /// - /// Converts a SVG color name into a corresponding RGB value. - /// - /// Name of the color to convert. - /// Red component. - /// Green component. - /// Blue component. - /// Returns true on success, false on failure. - /// is null. - public static bool LookupSVGColor(string color, out byte red, out byte green, out byte blue) - { - if (color == null) - { - throw new ArgumentNullException("color"); - } - return FreeImage.LookupSVGColor(color, out red, out green, out blue); - } - - /// - /// Creates a lookup table to be used with AdjustCurve() which - /// may adjusts brightness and contrast, correct gamma and invert the image with a - /// single call to AdjustCurve(). - /// - /// Output lookup table to be used with AdjustCurve(). - /// The size of is assumed to be 256. - /// Percentage brightness value where -100 <= brightness <= 100. - /// A value of 0 means no change, less than 0 will make the image darker and greater - /// than 0 will make the image brighter. - /// Percentage contrast value where -100 <= contrast <= 100. - /// A value of 0 means no change, less than 0 will decrease the contrast - /// and greater than 0 will increase the contrast of the image. - /// Gamma value to be used for gamma correction. - /// A value of 1.0 leaves the image alone, less than one darkens it, - /// and greater than one lightens it. - /// If set to true, the image will be inverted. - /// The number of adjustments applied to the resulting lookup table - /// compared to a blind lookup table. - /// is null. - /// is not 256. - public static int GetAdjustColorsLookupTable(byte[] lookUpTable, double brightness, double contrast, double gamma, bool invert) - { - if (lookUpTable == null) - { - throw new ArgumentNullException("lookUpTable"); - } - if (lookUpTable.Length != 256) - { - throw new ArgumentException("lookUpTable"); - } - return FreeImage.GetAdjustColorsLookupTable(lookUpTable, brightness, contrast, gamma, invert); - } - - /// - /// Adds a specified frame to the file specified using the specified parameters. - /// Use this method to save selected frames from an to a multiple-frame image. - /// - /// File to add this frame to. - /// A that contains the frame to add. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// Flags to enable or disable plugin-features. - /// - /// or is null. - /// - /// does not exist. - /// Saving the image failed. - public static void SaveAdd( - string filename, - FreeImageBitmap bitmap, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_LOAD_FLAGS loadFlags, - FREE_IMAGE_SAVE_FLAGS saveFlags) - { - if (filename == null) - { - throw new ArgumentNullException("filename"); - } - if (!File.Exists(filename)) - { - throw new FileNotFoundException("filename"); - } - if (bitmap == null) - { - throw new ArgumentNullException("bitmap"); - } - bitmap.EnsureNotDisposed(); - - FIBITMAP dib = bitmap.dib; - if (dib.IsNull) - throw new ArgumentNullException("bitmap"); - - FIMULTIBITMAP mpBitmap = - FreeImage.OpenMultiBitmapEx(filename, ref format, loadFlags, false, false, true); - - if (mpBitmap.IsNull) - throw new Exception(ErrorLoadingBitmap); - - FreeImage.AppendPage(mpBitmap, bitmap.dib); - - if (!FreeImage.CloseMultiBitmap(mpBitmap, saveFlags)) - throw new Exception(ErrorUnloadBitmap); - } - - /// - /// Adds a specified frame to the file specified using the specified parameters. - /// Use this method to save selected frames from an image to a multiple-frame image. - /// - /// File to add this frame to. - /// A that contains the frame to add. - /// The position of the inserted frame. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// Flags to enable or disable plugin-features. - /// - /// or is null. - /// - /// does not exist. - /// Saving the image failed. - /// is out of range. - public static void SaveAdd( - string filename, - FreeImageBitmap bitmap, - int insertPosition, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_LOAD_FLAGS loadFlags, - FREE_IMAGE_SAVE_FLAGS saveFlags) - { - if (filename == null) - { - throw new ArgumentNullException("filename"); - } - if (!File.Exists(filename)) - { - throw new FileNotFoundException("filename"); - } - if (bitmap == null) - { - throw new ArgumentNullException("bitmap"); - } - if (insertPosition < 0) - { - throw new ArgumentOutOfRangeException("insertPosition"); - } - bitmap.EnsureNotDisposed(); - - FIBITMAP dib = bitmap.dib; - if (dib.IsNull) - throw new ArgumentNullException("bitmap"); - - FIMULTIBITMAP mpBitmap = - FreeImage.OpenMultiBitmapEx(filename, ref format, loadFlags, false, false, true); - - if (mpBitmap.IsNull) - throw new Exception(ErrorLoadingBitmap); - - int pageCount = FreeImage.GetPageCount(mpBitmap); - - if (insertPosition > pageCount) - throw new ArgumentOutOfRangeException("insertPosition"); - - if (insertPosition == pageCount) - FreeImage.AppendPage(mpBitmap, bitmap.dib); - else - FreeImage.InsertPage(mpBitmap, insertPosition, bitmap.dib); - - if (!FreeImage.CloseMultiBitmap(mpBitmap, saveFlags)) - throw new Exception(ErrorUnloadBitmap); - } - - /// - /// Returns a new instance of the class which - /// has no public accessible constructor. - /// - /// A new instace of . - public static PropertyItem CreateNewPropertyItem() - { - return FreeImage.CreatePropertyItem(); - } - - #endregion - - #region Helper functions - - /// - /// Throws an exception in case the instance has already been disposed. - /// - private void EnsureNotDisposed() - { - lock (lockObject) - { - if (!this.disposed) - { - return; - } - } - throw new ObjectDisposedException(ToString()); - } - - /// - /// Tries to replace the wrapped with a new one. - /// In case the new dib is null or the same as the already - /// wrapped one, nothing will be changed and the result will - /// be false. - /// Otherwise the wrapped will be unloaded and replaced. - /// - /// The new dib. - /// Returns true on success, false on failure. - private bool ReplaceDib(FIBITMAP newDib) - { - bool result = false; - if ((dib != newDib) && (!newDib.IsNull)) - { - UnloadDib(); - dib = newDib; - AddMemoryPressure(); - result = true; - } - return result; - } - - /// - /// Unloads currently wrapped or unlocks the locked page - /// in case it came from a multipaged bitmap. - /// - private void UnloadDib() - { - if (!dib.IsNull) - { - long size = FreeImage.GetDIBSize(dib); - FreeImage.UnloadEx(ref dib); - if (size > 0L) - GC.RemoveMemoryPressure(size); - } - } - - /// - /// Informs the runtime about unmanaged allocoted memory. - /// - private void AddMemoryPressure() - { - long dataSize; - if ((dataSize = DataSize) > 0L) - GC.AddMemoryPressure(dataSize); - } - - /// - /// Opens the stream and reads the number of available pages. - /// Then loads the first page to this instance. - /// - private void LoadFromStream(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) - { - FIMULTIBITMAP mdib = FreeImage.OpenMultiBitmapFromStream(stream, ref format, flags); - if (mdib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - try - { - frameCount = FreeImage.GetPageCount(mdib); - } - finally - { - if (!FreeImage.CloseMultiBitmapEx(ref mdib)) - { - throw new Exception(ErrorUnloadBitmap); - } - } - - dib = FreeImage.LoadFromStream(stream, flags, ref format); - if (dib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - - saveInformation.loadFlags = flags; - originalFormat = format; - AddMemoryPressure(); - } - - #endregion - - #region Interfaces - - /// - /// Helper class to store informations for . - /// - private sealed class SaveInformation : ICloneable - { - public string filename; - public FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - public FREE_IMAGE_LOAD_FLAGS loadFlags = FREE_IMAGE_LOAD_FLAGS.DEFAULT; - public FREE_IMAGE_SAVE_FLAGS saveFlags = FREE_IMAGE_SAVE_FLAGS.DEFAULT; - - public object Clone() - { - return base.MemberwiseClone(); - } - } - - /// - /// Creates a deep copy of this . - /// - /// A deep copy of this . - public object Clone() - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.Clone(dib); - if (!dib.IsNull) - { - result = new FreeImageBitmap(newDib); - result.saveInformation = (SaveInformation)saveInformation.Clone(); - result.tag = tag; - result.originalFormat = originalFormat; - } - return result; - } - - /// - /// Performs application-defined tasks associated with freeing, - /// releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Performs application-defined tasks associated with freeing, - /// releasing, or resetting unmanaged resources. - /// - /// If true managed ressources are released. - protected virtual void Dispose(bool disposing) - { - // Only clean up once - lock (lockObject) - { - if (disposed) - { - return; - } - disposed = true; - } - - // Clean up managed resources - if (disposing) - { - if (stream != null) - { - if (disposeStream) - { - stream.Dispose(); - } - stream = null; - } - } - - tag = null; - saveInformation = null; - - // Clean up unmanaged resources - UnloadDib(); - } - - /// - /// Retrieves an object that can iterate through the individual scanlines in this . - /// - /// An for the . - /// The bitmaps's type is not supported. - IEnumerator IEnumerable.GetEnumerator() - { - return GetScanlines().GetEnumerator(); - } - - void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) - { - EnsureNotDisposed(); - using (MemoryStream memory = new MemoryStream(DataSize)) - { - if (!FreeImage.SaveToStream(dib, memory, FREE_IMAGE_FORMAT.FIF_TIFF, FREE_IMAGE_SAVE_FLAGS.TIFF_LZW)) - { - throw new SerializationException(); - } - memory.Capacity = (int)memory.Length; - info.AddValue("Bitmap Data", memory.GetBuffer()); - } - } - - #endregion - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.12 $ +// $Date: 2011/12/22 14:54:22 $ +// $Id: FreeImageBitmap.cs,v 1.12 2011/12/22 14:54:22 drolon Exp $ +// ========================================================== + +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.IO.Compression; +using System.Runtime.InteropServices; +using System.Runtime.Serialization; +using System.Collections; +using System.Collections.Generic; +using FreeImageAPI.Metadata; +using System.Diagnostics; + +namespace FreeImageAPI +{ + /// + /// Encapsulates a FreeImage-bitmap. + /// + [Serializable, Guid("64a4c935-b757-499c-ab8c-6110316a9e51")] + public class FreeImageBitmap : MarshalByRefObject, ICloneable, IDisposable, IEnumerable, ISerializable + { + #region Fields + + /// + /// Indicates whether this instance is disposed. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool disposed; + + /// + /// Tab object. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private object tag; + + /// + /// Object used to syncronize lock methods. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private object lockObject = new object(); + + /// + /// Holds information used by SaveAdd() methods. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private SaveInformation saveInformation = new SaveInformation(); + + /// + /// The stream that this instance was loaded from or + /// null if it has been cloned or deserialized. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private Stream stream; + + /// + /// True if the stream must be disposed with this + /// instance. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool disposeStream; + + /// + /// The number of frames contained by a mutlipage bitmap. + /// Default value is 1 and only changed if needed. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private int frameCount = 1; + + /// + /// The index of the loaded frame. + /// Default value is 0 and only changed if needed. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private int frameIndex = 0; + + /// + /// Format of the sourceimage. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private FREE_IMAGE_FORMAT originalFormat = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + + /// + /// Handle to the encapsulated FreeImage-bitmap. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private FIBITMAP dib; + + private const string ErrorLoadingBitmap = "Unable to load bitmap."; + private const string ErrorLoadingFrame = "Unable to load frame."; + private const string ErrorCreatingBitmap = "Unable to create bitmap."; + private const string ErrorUnloadBitmap = "Unable to unload bitmap."; + + #endregion + + #region Constructors and Destructor + + /// + /// Initializes a new instance of the class. + /// + protected FreeImageBitmap() + { + } + + /// + /// Initializes a new instance of the class. + /// For internal use only. + /// + /// The operation failed. + internal protected FreeImageBitmap(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + this.dib = dib; + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image. + /// + /// The original to clone from. + /// The operation failed. + /// is a null reference. + public FreeImageBitmap(FreeImageBitmap original) + { + if (original == null) + { + throw new ArgumentNullException("original"); + } + original.EnsureNotDisposed(); + dib = FreeImage.Clone(original.dib); + if (dib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + originalFormat = original.originalFormat; + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image with the specified size. + /// + /// The original to clone from. + /// The Size structure that represent the + /// size of the new . + /// The operation failed. + /// is a null reference. + /// + /// or are less or equal zero. + /// + public FreeImageBitmap(FreeImageBitmap original, Size newSize) + : this(original, newSize.Width, newSize.Height) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image with the specified size. + /// + /// The original to clone from. + /// Width of the new . + /// Height of the new . + /// The operation failed. + /// is a null reference. + /// + /// or are less or equal zero. + public FreeImageBitmap(FreeImageBitmap original, int width, int height) + { + if (original == null) + { + throw new ArgumentNullException("original"); + } + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + original.EnsureNotDisposed(); + dib = FreeImage.Rescale(original.dib, width, height, FREE_IMAGE_FILTER.FILTER_BICUBIC); + if (dib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + originalFormat = original.originalFormat; + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image. + /// + /// The original to clone from. + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + public FreeImageBitmap(Image original) + : this(original as Bitmap) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image with the specified size. + /// + /// The original to clone from. + /// The Size structure that represent the + /// size of the new . + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + /// is a null reference. + /// + /// or are less or equal zero. + /// + public FreeImageBitmap(Image original, Size newSize) + : this(original as Bitmap, newSize.Width, newSize.Height) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image with the specified size. + /// + /// The original to clone from. + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + /// is a null reference. + /// + /// or are less or equal zero. + public FreeImageBitmap(Image original, int width, int height) + : this(original as Bitmap, width, height) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image. + /// + /// The original to clone from. + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// is a null reference. + /// The operation failed. + public FreeImageBitmap(Bitmap original) + { + if (original == null) + { + throw new ArgumentNullException("original"); + } + dib = FreeImage.CreateFromBitmap(original, true); + if (dib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + originalFormat = FreeImage.GetFormat(original.RawFormat); + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image with the specified size. + /// + /// The original to clone from. + /// The Size structure that represent the + /// size of the new . + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + /// is a null reference. + /// + /// or are less or equal zero. + /// + public FreeImageBitmap(Bitmap original, Size newSize) + : this(original, newSize.Width, newSize.Height) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image with the specified size. + /// + /// The original to clone from. + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + /// is a null reference. + /// + /// or are less or equal zero. + public FreeImageBitmap(Bitmap original, int width, int height) + { + if (original == null) + { + throw new ArgumentNullException("original"); + } + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + FIBITMAP temp = FreeImage.CreateFromBitmap(original, true); + if (temp.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + dib = FreeImage.Rescale(temp, width, height, FREE_IMAGE_FILTER.FILTER_BICUBIC); + FreeImage.Unload(temp); + if (dib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + originalFormat = FreeImage.GetFormat(original.RawFormat); + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class + /// bases on the specified stream. + /// + /// Stream to read from. + /// Ignored. + /// The operation failed. + /// is a null reference. + /// + /// You must keep the stream open for the lifetime of the . + /// + public FreeImageBitmap(Stream stream, bool useIcm) + : this(stream) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified stream. + /// + /// Stream to read from. + /// The operation failed. + /// is a null reference. + /// + /// You must keep the stream open for the lifetime of the . + /// + public FreeImageBitmap(Stream stream) + : this(stream, FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_LOAD_FLAGS.DEFAULT) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified stream in the specified format. + /// + /// Stream to read from. + /// Format of the image. + /// The operation failed. + /// is a null reference. + /// + /// You must keep the stream open for the lifetime of the . + /// + public FreeImageBitmap(Stream stream, FREE_IMAGE_FORMAT format) + : this(stream, format, FREE_IMAGE_LOAD_FLAGS.DEFAULT) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified stream with the specified loading flags. + /// + /// Stream to read from. + /// Flags to enable or disable plugin-features. + /// The operation failed. + /// is a null reference. + /// + /// You must keep the stream open for the lifetime of the . + /// + public FreeImageBitmap(Stream stream, FREE_IMAGE_LOAD_FLAGS flags) + : this(stream, FREE_IMAGE_FORMAT.FIF_UNKNOWN, flags) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified stream in the specified format + /// with the specified loading flags. + /// + /// Stream to read from. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// The operation failed. + /// is a null reference. + /// + /// You must keep the stream open for the lifetime of the . + /// + public FreeImageBitmap(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) + { + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + this.stream = stream; + disposeStream = false; + LoadFromStream(stream, format, flags); + } + + /// + /// Initializes a new instance of the class bases on the specified file. + /// + /// The complete name of the file to load. + /// The operation failed. + /// is a null reference. + /// does not exist. + public FreeImageBitmap(string filename) + : this(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT) + { + } + + /// + /// Initializes a new instance of the class bases on the specified file. + /// + /// The complete name of the file to load. + /// Ignored. + /// The operation failed. + /// is a null reference. + /// does not exist. + public FreeImageBitmap(string filename, bool useIcm) + : this(filename) + { + } + + /// + /// Initializes a new instance of the class bases on the specified file + /// with the specified loading flags. + /// + /// The complete name of the file to load. + /// Flags to enable or disable plugin-features. + /// The operation failed. + /// is a null reference. + /// does not exist. + public FreeImageBitmap(string filename, FREE_IMAGE_LOAD_FLAGS flags) + : this(filename, FREE_IMAGE_FORMAT.FIF_UNKNOWN, flags) + { + } + + /// + /// Initializes a new instance of the class bases on the specified file + /// in the specified format. + /// + /// The complete name of the file to load. + /// Format of the image. + /// The operation failed. + /// is a null reference. + /// does not exist. + public FreeImageBitmap(string filename, FREE_IMAGE_FORMAT format) + : this(filename, format, FREE_IMAGE_LOAD_FLAGS.DEFAULT) + { + } + + /// + /// Initializes a new instance of the class bases on the specified file + /// in the specified format with the specified loading flags. + /// + /// The complete name of the file to load. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// The operation failed. + /// is a null reference. + /// does not exist. + public FreeImageBitmap(string filename, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) + { + if (filename == null) + { + throw new ArgumentNullException("filename"); + } + if (!File.Exists(filename)) + { + throw new FileNotFoundException("filename"); + } + + saveInformation.filename = filename; + stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); + disposeStream = true; + LoadFromStream(stream, format, flags); + } + + /// + /// Initializes a new instance of the class + /// bases on the specified size. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// The operation failed. + public FreeImageBitmap(int width, int height) + { + dib = FreeImage.Allocate( + width, + height, + 24, + FreeImage.FI_RGBA_RED_MASK, + FreeImage.FI_RGBA_GREEN_MASK, + FreeImage.FI_RGBA_BLUE_MASK); + if (dib.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class bases on the specified resource. + /// + /// The class used to extract the resource. + /// The name of the resource. + /// The operation failed. + public FreeImageBitmap(Type type, string resource) + : this(type.Module.Assembly.GetManifestResourceStream(type, resource)) + { + } + + /// + /// Initializes a new instance of the class bases on the specified size + /// and with the resolution of the specified object. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// The Graphics object that specifies the resolution for the new . + /// The operation failed. + /// is a null reference. + public FreeImageBitmap(int width, int height, Graphics g) + : this(width, height) + { + FreeImage.SetResolutionX(dib, (uint)g.DpiX); + FreeImage.SetResolutionY(dib, (uint)g.DpiY); + } + + /// + /// Initializes a new instance of the class bases on the specified size and format. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// The PixelFormat enumeration for the new . + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + /// is invalid. + /// + /// or are less or equal zero. + public FreeImageBitmap(int width, int height, PixelFormat format) + { + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + uint bpp, redMask, greenMask, blueMask; + FREE_IMAGE_TYPE type; + if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask)) + { + throw new ArgumentException("format is invalid"); + } + dib = FreeImage.AllocateT(type, width, height, (int)bpp, redMask, greenMask, blueMask); + if (dib.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class bases on the specified size and type. + /// Only non standard bitmaps are supported. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// The type of the bitmap. + /// The operation failed. + /// + /// is FIT_BITMAP or FIT_UNKNOWN. + /// is invalid. + /// + /// or are less or equal zero. + public FreeImageBitmap(int width, int height, FREE_IMAGE_TYPE type) + { + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + if ((type == FREE_IMAGE_TYPE.FIT_BITMAP) || (type == FREE_IMAGE_TYPE.FIT_UNKNOWN)) + { + throw new ArgumentException("type is invalid."); + } + dib = FreeImage.AllocateT(type, width, height, 0, 0u, 0u, 0u); + if (dib.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class bases on the specified size, + /// pixel format and pixel data. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// Integer that specifies the byte offset between the beginning + /// of one scan line and the next. This is usually (but not necessarily) + /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) + /// multiplied by the width of the bitmap. The value passed to this parameter must + /// be a multiple of four.. + /// The PixelFormat enumeration for the new . + /// Pointer to an array of bytes that contains the pixel data. + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + /// is invalid. + /// + /// or are less or equal zero. + public FreeImageBitmap(int width, int height, int stride, PixelFormat format, IntPtr scan0) + { + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + uint bpp, redMask, greenMask, blueMask; + FREE_IMAGE_TYPE type; + bool topDown = (stride > 0); + stride = (stride > 0) ? stride : (stride * -1); + + if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask)) + { + throw new ArgumentException("format is invalid."); + } + + dib = FreeImage.ConvertFromRawBits( + scan0, type, width, height, stride, bpp, redMask, greenMask, blueMask, topDown); + + if (dib.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class bases on the specified size, + /// pixel format and pixel data. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// Integer that specifies the byte offset between the beginning + /// of one scan line and the next. This is usually (but not necessarily) + /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) + /// multiplied by the width of the bitmap. The value passed to this parameter must + /// be a multiple of four.. + /// The PixelFormat enumeration for the new . + /// Array of bytes containing the bitmap data. + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + /// is invalid. + /// + /// or are less or equal zero. + /// is null + public FreeImageBitmap(int width, int height, int stride, PixelFormat format, byte[] bits) + { + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + if (bits == null) + { + throw new ArgumentNullException("bits"); + } + uint bpp, redMask, greenMask, blueMask; + FREE_IMAGE_TYPE type; + bool topDown = (stride > 0); + stride = (stride > 0) ? stride : (stride * -1); + + if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask)) + { + throw new ArgumentException("format is invalid."); + } + + dib = FreeImage.ConvertFromRawBits( + bits, type, width, height, stride, bpp, redMask, greenMask, blueMask, topDown); + + if (dib.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class bases on the specified size, + /// pixel format and pixel data. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// Integer that specifies the byte offset between the beginning + /// of one scan line and the next. This is usually (but not necessarily) + /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) + /// multiplied by the width of the bitmap. The value passed to this parameter must + /// be a multiple of four.. + /// The color depth of the new + /// The type for the new . + /// Pointer to an array of bytes that contains the pixel data. + /// The operation failed. + /// is invalid. + /// + /// or are less or equal zero. + public FreeImageBitmap(int width, int height, int stride, int bpp, FREE_IMAGE_TYPE type, IntPtr scan0) + { + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + uint redMask, greenMask, blueMask; + bool topDown = (stride > 0); + stride = (stride > 0) ? stride : (stride * -1); + + if (!FreeImage.GetTypeParameters(type, bpp, out redMask, out greenMask, out blueMask)) + { + throw new ArgumentException("bpp and type are invalid or not supported."); + } + + dib = FreeImage.ConvertFromRawBits( + scan0, type, width, height, stride, (uint)bpp, redMask, greenMask, blueMask, topDown); + + if (dib.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class bases on the specified size, + /// pixel format and pixel data. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// Integer that specifies the byte offset between the beginning + /// of one scan line and the next. This is usually (but not necessarily) + /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) + /// multiplied by the width of the bitmap. The value passed to this parameter must + /// be a multiple of four.. + /// The color depth of the new + /// The type for the new . + /// Array of bytes containing the bitmap data. + /// The operation failed. + /// is invalid. + /// + /// or are less or equal zero. + /// is null + public FreeImageBitmap(int width, int height, int stride, int bpp, FREE_IMAGE_TYPE type, byte[] bits) + { + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + if (bits == null) + { + throw new ArgumentNullException("bits"); + } + uint redMask, greenMask, blueMask; + bool topDown = (stride > 0); + stride = (stride > 0) ? stride : (stride * -1); + + if (!FreeImage.GetTypeParameters(type, bpp, out redMask, out greenMask, out blueMask)) + { + throw new ArgumentException("bpp and type are invalid or not supported."); + } + + dib = FreeImage.ConvertFromRawBits( + bits, type, width, height, stride, (uint)bpp, redMask, greenMask, blueMask, topDown); + + if (dib.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class. + /// + /// The operation failed. + /// The operation failed. + public FreeImageBitmap(SerializationInfo info, StreamingContext context) + { + try + { + byte[] data = (byte[])info.GetValue("Bitmap Data", typeof(byte[])); + if ((data != null) && (data.Length > 0)) + { + MemoryStream memory = new MemoryStream(data); + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_TIFF; + dib = FreeImage.LoadFromStream(memory, ref format); + + if (dib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + + AddMemoryPressure(); + } + } + catch (Exception ex) + { + throw new SerializationException("Deserialization failed.", ex); + } + } + + /// + /// Frees all managed and unmanaged ressources. + /// + ~FreeImageBitmap() + { + Dispose(false); + } + + #endregion + + #region Operators + + /// + /// Converts a instance to a instance. + /// + /// A instance. + /// A new instance of initialized to . + /// + /// The explicit conversion from into Bitmap + /// allows to create an instance on the fly and use it as if + /// was a Bitmap. This way it can be directly used with a + /// PixtureBox for example without having to call any + /// conversion operations. + /// + public static explicit operator Bitmap(FreeImageBitmap value) + { + return value.ToBitmap(); + } + + /// + /// Converts a instance to a instance. + /// + /// A instance. + /// A new instance of initialized to . + /// + /// The explicit conversion from into + /// allows to create an instance on the fly to perform + /// image processing operations and converting it back. + /// + public static explicit operator FreeImageBitmap(Bitmap value) + { + return new FreeImageBitmap(value); + } + + /// + /// Determines whether two specified objects have the same value. + /// + /// A or a null reference (Nothing in Visual Basic). + /// A or a null reference (Nothing in Visual Basic). + /// + /// true if the value of left is the same as the value of right; otherwise, false. + /// + public static bool operator ==(FreeImageBitmap left, FreeImageBitmap right) + { + if (object.ReferenceEquals(left, right)) + { + return true; + } + else if (object.ReferenceEquals(left, null) || object.ReferenceEquals(right, null)) + { + return false; + } + else + { + left.EnsureNotDisposed(); + right.EnsureNotDisposed(); + return FreeImage.Compare(left.dib, right.dib, FREE_IMAGE_COMPARE_FLAGS.COMPLETE); + } + } + + /// + /// Determines whether two specified objects have different values. + /// + /// A or a null reference (Nothing in Visual Basic). + /// A or a null reference (Nothing in Visual Basic). + /// + /// true if the value of left is different from the value of right; otherwise, false. + /// + public static bool operator !=(FreeImageBitmap left, FreeImageBitmap right) + { + return (!(left == right)); + } + + #endregion + + #region Properties + + /// + /// Type of the bitmap. + /// + public FREE_IMAGE_TYPE ImageType + { + get + { + EnsureNotDisposed(); + return FreeImage.GetImageType(dib); + } + } + + /// + /// Number of palette entries. + /// + public int ColorsUsed + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetColorsUsed(dib); + } + } + + /// + /// The number of unique colors actually used by the bitmap. This might be different from + /// what ColorsUsed returns, which actually returns the palette size for palletised images. + /// Works for FIT_BITMAP type bitmaps only. + /// + public int UniqueColors + { + get + { + EnsureNotDisposed(); + return FreeImage.GetUniqueColors(dib); + } + } + + /// + /// The size of one pixel in the bitmap in bits. + /// + public int ColorDepth + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetBPP(dib); + } + } + + /// + /// Width of the bitmap in pixel units. + /// + public int Width + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetWidth(dib); + } + } + + /// + /// Height of the bitmap in pixel units. + /// + public int Height + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetHeight(dib); + } + } + + /// + /// Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary. + /// + public int Pitch + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetPitch(dib); + } + } + + /// + /// Size of the bitmap in memory. + /// + public int DataSize + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetDIBSize(dib); + } + } + + /// + /// Returns a structure that represents the palette of a FreeImage bitmap. + /// + /// is false. + public Palette Palette + { + get + { + EnsureNotDisposed(); + if (HasPalette) + { + return new Palette(dib); + } + throw new InvalidOperationException("This bitmap does not have a palette."); + } + } + + /// + /// Gets whether the bitmap is RGB 555. + /// + public bool IsRGB555 + { + get + { + EnsureNotDisposed(); + return FreeImage.IsRGB555(dib); + } + } + + /// + /// Gets whether the bitmap is RGB 565. + /// + public bool IsRGB565 + { + get + { + EnsureNotDisposed(); + return FreeImage.IsRGB565(dib); + } + } + + /// + /// Gets the horizontal resolution, in pixels per inch, of this . + /// + public float HorizontalResolution + { + get + { + EnsureNotDisposed(); + return (float)FreeImage.GetResolutionX(dib); + } + private set + { + EnsureNotDisposed(); + FreeImage.SetResolutionX(dib, (uint)value); + } + } + + /// + /// Gets the vertical resolution, in pixels per inch, of this . + /// + public float VerticalResolution + { + get + { + EnsureNotDisposed(); + return (float)FreeImage.GetResolutionY(dib); + } + private set + { + EnsureNotDisposed(); + FreeImage.SetResolutionY(dib, (uint)value); + } + } + + /// + /// Returns the structure of this . + /// + public BITMAPINFOHEADER InfoHeader + { + get + { + EnsureNotDisposed(); + return FreeImage.GetInfoHeaderEx(dib); + } + } + + /// + /// Returns the structure of a this . + /// + public BITMAPINFO Info + { + get + { + EnsureNotDisposed(); + return FreeImage.GetInfoEx(dib); + } + } + + /// + /// Investigates the color type of this + /// by reading the bitmaps pixel bits and analysing them. + /// + public FREE_IMAGE_COLOR_TYPE ColorType + { + get + { + EnsureNotDisposed(); + return FreeImage.GetColorType(dib); + } + } + + /// + /// Bit pattern describing the red color component of a pixel in this . + /// + public uint RedMask + { + get + { + EnsureNotDisposed(); + return FreeImage.GetRedMask(dib); + } + } + + /// + /// Bit pattern describing the green color component of a pixel in this . + /// + public uint GreenMask + { + get + { + EnsureNotDisposed(); + return FreeImage.GetGreenMask(dib); + } + } + + /// + /// Bit pattern describing the blue color component of a pixel in this . + /// + public uint BlueMask + { + get + { + EnsureNotDisposed(); + return FreeImage.GetBlueMask(dib); + } + } + + /// + /// Number of transparent colors in a palletised . + /// + public int TransparencyCount + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetTransparencyCount(dib); + } + } + + /// + /// Get or sets transparency table of this . + /// + public byte[] TransparencyTable + { + get + { + EnsureNotDisposed(); + return FreeImage.GetTransparencyTableEx(dib); + } + set + { + EnsureNotDisposed(); + FreeImage.SetTransparencyTable(dib, value); + } + } + + /// + /// Gets or sets whether this is transparent. + /// + public bool IsTransparent + { + get + { + EnsureNotDisposed(); + return FreeImage.IsTransparent(dib); + } + set + { + EnsureNotDisposed(); + FreeImage.SetTransparent(dib, value); + } + } + + /// + /// Gets whether this has a file background color. + /// + public bool HasBackgroundColor + { + get + { + EnsureNotDisposed(); + return FreeImage.HasBackgroundColor(dib); + } + } + + /// + /// Gets or sets the background color of this . + /// In case the value is null, the background color is removed. + /// + /// Get: There is no background color available. + /// Set: Setting background color failed. + public Color? BackgroundColor + { + get + { + EnsureNotDisposed(); + if (!FreeImage.HasBackgroundColor(dib)) + { + throw new InvalidOperationException("No background color available."); + } + RGBQUAD rgbq; + FreeImage.GetBackgroundColor(dib, out rgbq); + return rgbq.Color; + } + set + { + EnsureNotDisposed(); + if (!FreeImage.SetBackgroundColor(dib, (value.HasValue ? new RGBQUAD[] { value.Value } : null))) + { + throw new Exception("Setting background color failed."); + } + } + } + + /// + /// Pointer to the data-bits of this . + /// + public IntPtr Bits + { + get + { + EnsureNotDisposed(); + return FreeImage.GetBits(dib); + } + } + + /// + /// Width, in bytes, of this . + /// + public int Line + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetLine(dib); + } + } + + /// + /// Pointer to the scanline of the top most pixel row of this . + /// + public IntPtr Scan0 + { + get + { + EnsureNotDisposed(); + return FreeImage.GetScanLine(dib, (int)(FreeImage.GetHeight(dib) - 1)); + } + } + + /// + /// Width, in bytes, of this . + /// In case this is top down Stride will be positive, else negative. + /// + public int Stride + { + get + { + return -Line; + } + } + + /// + /// Gets attribute flags for the pixel data of this . + /// + public unsafe int Flags + { + get + { + EnsureNotDisposed(); + int result = 0; + byte alpha; + int cd = ColorDepth; + + if ((cd == 32) || (FreeImage.GetTransparencyCount(dib) != 0)) + { + result += (int)ImageFlags.HasAlpha; + } + + if (cd == 32) + { + uint width = FreeImage.GetWidth(dib); + uint height = FreeImage.GetHeight(dib); + for (int y = 0; y < height; y++) + { + RGBQUAD* scanline = (RGBQUAD*)FreeImage.GetScanLine(dib, y); + for (int x = 0; x < width; x++) + { + alpha = scanline[x].Color.A; + if (alpha != byte.MinValue && alpha != byte.MaxValue) + { + result += (int)ImageFlags.HasTranslucent; + y = (int)height; + break; + } + } + } + } + else if (FreeImage.GetTransparencyCount(dib) != 0) + { + byte[] transTable = FreeImage.GetTransparencyTableEx(dib); + for (int i = 0; i < transTable.Length; i++) + { + if (transTable[i] != byte.MinValue && transTable[i] != byte.MaxValue) + { + result += (int)ImageFlags.HasTranslucent; + break; + } + } + } + + if (FreeImage.GetICCProfileEx(dib).IsCMYK) + { + result += (int)ImageFlags.ColorSpaceCmyk; + } + else + { + result += (int)ImageFlags.ColorSpaceRgb; + } + + if (FreeImage.GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_MINISBLACK || + FreeImage.GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_MINISWHITE) + { + result += (int)ImageFlags.ColorSpaceGray; + } + + if (originalFormat == FREE_IMAGE_FORMAT.FIF_BMP || + originalFormat == FREE_IMAGE_FORMAT.FIF_FAXG3 || + originalFormat == FREE_IMAGE_FORMAT.FIF_ICO || + originalFormat == FREE_IMAGE_FORMAT.FIF_JPEG || + originalFormat == FREE_IMAGE_FORMAT.FIF_PCX || + originalFormat == FREE_IMAGE_FORMAT.FIF_PNG || + originalFormat == FREE_IMAGE_FORMAT.FIF_PSD || + originalFormat == FREE_IMAGE_FORMAT.FIF_TIFF) + { + result += (int)ImageFlags.HasRealDpi; + } + + return result; + } + } + + /// + /// Gets the width and height of this . + /// + public SizeF PhysicalDimension + { + get + { + EnsureNotDisposed(); + return new SizeF((float)FreeImage.GetWidth(dib), (float)FreeImage.GetHeight(dib)); + } + } + + /// + /// Gets the pixel format for this . + /// + public PixelFormat PixelFormat + { + get + { + EnsureNotDisposed(); + return FreeImage.GetPixelFormat(dib); + } + } + + /// + /// Gets IDs of the property items stored in this . + /// + public int[] PropertyIdList + { + get + { + EnsureNotDisposed(); + List list = new List(); + ImageMetadata metaData = new ImageMetadata(dib, true); + + foreach (MetadataModel metadataModel in metaData) + { + foreach (MetadataTag metadataTag in metadataModel) + { + list.Add(metadataTag.ID); + } + } + + return list.ToArray(); + } + } + + /// + /// Gets all the property items (pieces of metadata) stored in this . + /// + public PropertyItem[] PropertyItems + { + get + { + EnsureNotDisposed(); + List list = new List(); + ImageMetadata metaData = new ImageMetadata(dib, true); + + foreach (MetadataModel metadataModel in metaData) + { + foreach (MetadataTag metadataTag in metadataModel) + { + list.Add(metadataTag.GetPropertyItem()); + } + } + + return list.ToArray(); + } + } + + /// + /// Gets the format of this . + /// + public ImageFormat RawFormat + { + get + { + EnsureNotDisposed(); + Attribute guidAttribute = + Attribute.GetCustomAttribute( + typeof(FreeImageBitmap), typeof(System.Runtime.InteropServices.GuidAttribute) + ); + return (guidAttribute == null) ? + null : + new ImageFormat(new Guid(((GuidAttribute)guidAttribute).Value)); + } + } + + /// + /// Gets the width and height, in pixels, of this . + /// + public Size Size + { + get + { + EnsureNotDisposed(); + return new Size(Width, Height); + } + } + + /// + /// Gets or sets an object that provides additional data about the . + /// + public Object Tag + { + get + { + EnsureNotDisposed(); + return tag; + } + set + { + EnsureNotDisposed(); + tag = value; + } + } + + /// + /// Gets whether this has been disposed. + /// + public bool IsDisposed + { + get + { + return disposed; + } + } + + /// + /// Gets a new instance of a metadata representing class. + /// + public ImageMetadata Metadata + { + get + { + EnsureNotDisposed(); + return new ImageMetadata(dib, true); + } + } + + /// + /// Gets or sets the comment of this . + /// Supported formats are JPEG, PNG and GIF. + /// + public string Comment + { + get + { + EnsureNotDisposed(); + return FreeImage.GetImageComment(dib); + } + set + { + EnsureNotDisposed(); + FreeImage.SetImageComment(dib, value); + } + } + + /// + /// Returns whether this has a palette. + /// + public bool HasPalette + { + get + { + EnsureNotDisposed(); + return (FreeImage.GetPalette(dib) != IntPtr.Zero); + } + } + + /// + /// Gets or sets the entry used as transparent color in this . + /// Only works for 1-, 4- and 8-bpp. + /// + public int TransparentIndex + { + get + { + EnsureNotDisposed(); + return FreeImage.GetTransparentIndex(dib); + } + set + { + EnsureNotDisposed(); + FreeImage.SetTransparentIndex(dib, value); + } + } + + /// + /// Gets the number of frames in this . + /// + public int FrameCount + { + get + { + EnsureNotDisposed(); + return frameCount; + } + } + + /// + /// Gets the ICCProfile structure of this . + /// + public FIICCPROFILE ICCProfile + { + get + { + EnsureNotDisposed(); + return FreeImage.GetICCProfileEx(dib); + } + } + + /// + /// Gets the format of the original image in case + /// this was loaded from a file or stream. + /// + public FREE_IMAGE_FORMAT ImageFormat + { + get + { + EnsureNotDisposed(); + return originalFormat; + } + } + + /// + /// Gets the encapsulated FIBITMAP. + /// + internal FIBITMAP Dib + { + get { EnsureNotDisposed(); return dib; } + } + + #endregion + + #region Methods + + /// + /// Gets the bounds of this in the specified unit. + /// + /// One of the values indicating + /// the unit of measure for the bounding rectangle. + /// The that represents the bounds of this + /// , in the specified unit. + public RectangleF GetBounds(ref GraphicsUnit pageUnit) + { + EnsureNotDisposed(); + pageUnit = GraphicsUnit.Pixel; + return new RectangleF( + 0f, + 0f, + (float)FreeImage.GetWidth(dib), + (float)FreeImage.GetHeight(dib)); + } + + /// + /// Gets the specified property item from this . + /// + /// The ID of the property item to get. + /// The this method gets. + public PropertyItem GetPropertyItem(int propid) + { + EnsureNotDisposed(); + ImageMetadata metadata = new ImageMetadata(dib, true); + foreach (MetadataModel metadataModel in metadata) + { + foreach (MetadataTag tag in metadataModel) + { + if (tag.ID == propid) + { + return tag.GetPropertyItem(); + } + } + } + return null; + } + + /// + /// Returns a thumbnail for this . + /// + /// The width, in pixels, of the requested thumbnail image. + /// The height, in pixels, of the requested thumbnail image. + /// Ignored. + /// Ignored. + /// A that represents the thumbnail. + public FreeImageBitmap GetThumbnailImage(int thumbWidth, int thumbHeight, + Image.GetThumbnailImageAbort callback, IntPtr callBackData) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.Rescale( + dib, thumbWidth, thumbHeight, FREE_IMAGE_FILTER.FILTER_BICUBIC); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Returns a thumbnail for this , keeping aspect ratio. + /// defines the maximum width or height + /// of the thumbnail. + /// + /// Thumbnail square size. + /// When true HDR images are transperantly + /// converted to standard images. + /// The thumbnail in a new instance. + public FreeImageBitmap GetThumbnailImage(int maxPixelSize, bool convert) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.MakeThumbnail(dib, maxPixelSize, convert); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Converts this instance to a instance. + /// + /// A new instance of initialized this instance. + public Bitmap ToBitmap() + { + EnsureNotDisposed(); + return FreeImage.GetBitmap(dib, true); + } + + /// + /// Returns an instance of , representing the scanline + /// specified by of this . + /// Since FreeImage bitmaps are always bottum up aligned, keep in mind that scanline 0 is the + /// bottom-most line of the image. + /// + /// Number of the scanline to retrieve. + /// An instance of representing the + /// th scanline. + /// + /// List of return-types of T: + /// + /// Color Depth / TypeResult Type + /// 1 () + /// 4 () + /// 8 () + /// 16 () + /// 16 - 555 () + /// 16 - 565 () + /// 24 () + /// 32 () + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// FreeImageBitmap bitmap = new FreeImageBitmap(@"C:\Pictures\picture.bmp"); + /// if (bitmap.ColorDepth == 32) + /// { + /// Scanline<RGBQUAD> scanline = bitmap.GetScanline<RGBQUAD>(0); + /// foreach (RGBQUAD pixel in scanline) + /// { + /// Console.WriteLine(pixel); + /// } + /// } + /// + /// + /// + /// The bitmap's type or color depth are not supported. + /// + /// + /// is no valid value. + /// + public Scanline GetScanline(int scanline) where T : struct + { + EnsureNotDisposed(); + return new Scanline(dib, scanline); + } + + /// + /// Returns an instance of , representing the scanline + /// specified by of this . + /// Since FreeImage bitmaps are always bottum up aligned, keep in mind that scanline 0 is the + /// bottom-most line of the image. + /// + /// Number of the scanline to retrieve. + /// An instance of representing the + /// th scanline. + /// + /// List of return-types of T: + /// + /// Color Depth / TypeResult Type + /// 1 () + /// 4 () + /// 8 () + /// 16 () + /// 16 - 555 () + /// 16 - 565 () + /// 24 () + /// 32 () + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// FreeImageBitmap bitmap = new FreeImageBitmap(@"C:\Pictures\picture.bmp"); + /// if (bitmap.ColorDepth == 32) + /// { + /// Scanline<RGBQUAD> scanline = (Scanline<RGBQUAD>)bitmap.GetScanline(0); + /// foreach (RGBQUAD pixel in scanline) + /// { + /// Console.WriteLine(pixel); + /// } + /// } + /// + /// + /// + /// The type of the bitmap or color depth are not supported. + /// + /// + /// is no valid value. + /// + public object GetScanline(int scanline) + { + EnsureNotDisposed(); + object result = null; + int width = (int)FreeImage.GetWidth(dib); + + switch (FreeImage.GetImageType(dib)) + { + case FREE_IMAGE_TYPE.FIT_BITMAP: + + switch (FreeImage.GetBPP(dib)) + { + case 1u: result = new Scanline(dib, scanline, width); break; + case 4u: result = new Scanline(dib, scanline, width); break; + case 8u: result = new Scanline(dib, scanline, width); break; + case 16u: + if ((RedMask == FreeImage.FI16_555_RED_MASK) && + (GreenMask == FreeImage.FI16_555_GREEN_MASK) && + (BlueMask == FreeImage.FI16_555_BLUE_MASK)) + { + result = new Scanline(dib, scanline, width); + } + else if ((RedMask == FreeImage.FI16_565_RED_MASK) && + (GreenMask == FreeImage.FI16_565_GREEN_MASK) && + (BlueMask == FreeImage.FI16_565_BLUE_MASK)) + { + result = new Scanline(dib, scanline, width); + } + else + { + result = new Scanline(dib, scanline, width); + } + break; + case 24u: result = new Scanline(dib, scanline, width); break; + case 32u: result = new Scanline(dib, scanline, width); break; + default: throw new ArgumentException("Color depth is not supported."); + } + break; + + case FREE_IMAGE_TYPE.FIT_COMPLEX: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_DOUBLE: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_FLOAT: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_INT16: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_INT32: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_RGB16: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_RGBA16: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_RGBAF: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_RGBF: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_UINT16: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_UINT32: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_UNKNOWN: + default: throw new ArgumentException("Type is not supported."); + } + + return result; + } + + /// + /// Returns a pointer to the specified scanline. + /// Due to FreeImage bitmaps are bottum up, + /// scanline 0 is the most bottom line of the image. + /// + /// Number of the scanline. + /// Pointer to the scanline. + public IntPtr GetScanlinePointer(int scanline) + { + EnsureNotDisposed(); + return FreeImage.GetScanLine(dib, scanline); + } + + /// + /// Returns a list of structures, representing the scanlines of this . + /// Due to FreeImage bitmaps are bottum up, scanline 0 is the + /// bottom-most line of the image. + /// Each color depth has a different representing structure due to different memory layouts. + /// + /// + /// List of return-types of T: + /// + /// Color Depth / TypeResult Type of IEnmuerable<Scanline<T>> + /// 1 () + /// 4 () + /// 8 () + /// 16 () + /// 16 - 555 () + /// 16 - 565 () + /// 24 () + /// 32 () + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public IList GetScanlines() + { + EnsureNotDisposed(); + + int height = (int)FreeImage.GetHeight(dib); + IList list; + + switch (FreeImage.GetImageType(dib)) + { + case FREE_IMAGE_TYPE.FIT_BITMAP: + + switch (FreeImage.GetBPP(dib)) + { + case 1u: list = new List>(height); break; + case 4u: list = new List>(height); break; + case 8u: list = new List>(height); break; + case 16u: + if (FreeImage.IsRGB555(dib)) + { + list = new List>(height); + } + else if (FreeImage.IsRGB565(dib)) + { + list = new List>(height); + } + else + { + list = new List>(height); + } + break; + case 24u: list = new List>(height); break; + case 32u: list = new List>(height); break; + default: throw new ArgumentException("Color depth is not supported."); + } + break; + + case FREE_IMAGE_TYPE.FIT_COMPLEX: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_DOUBLE: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_FLOAT: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_INT16: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_INT32: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_RGB16: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_RGBA16: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_RGBAF: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_RGBF: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_UINT16: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_UINT32: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_UNKNOWN: + default: throw new ArgumentException("Type is not supported."); + } + + for (int i = 0; i < height; i++) + { + list.Add(GetScanline(i)); + } + + return list; + } + + /// + /// Removes the specified property item from this . + /// + /// The ID of the property item to remove. + public void RemovePropertyItem(int propid) + { + EnsureNotDisposed(); + ImageMetadata mdata = new ImageMetadata(dib, true); + foreach (MetadataModel model in mdata) + { + foreach (MetadataTag tag in model) + { + if (tag.ID == propid) + { + model.RemoveTag(tag.Key); + return; + } + } + } + } + + /// + /// This method rotates, flips, or rotates and flips this . + /// + /// A RotateFlipType member + /// that specifies the type of rotation and flip to apply to this . + public void RotateFlip(RotateFlipType rotateFlipType) + { + EnsureNotDisposed(); + + FIBITMAP newDib = new FIBITMAP(); + uint bpp = FreeImage.GetBPP(dib); + + switch (rotateFlipType) + { + case RotateFlipType.RotateNoneFlipX: + + FreeImage.FlipHorizontal(dib); + break; + + case RotateFlipType.RotateNoneFlipY: + + FreeImage.FlipVertical(dib); + break; + + case RotateFlipType.RotateNoneFlipXY: + + FreeImage.FlipHorizontal(dib); + FreeImage.FlipVertical(dib); + break; + + case RotateFlipType.Rotate90FlipNone: + + newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); + break; + + case RotateFlipType.Rotate90FlipX: + + newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); + FreeImage.FlipHorizontal(newDib); + break; + + case RotateFlipType.Rotate90FlipY: + + newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); + FreeImage.FlipVertical(newDib); + break; + + case RotateFlipType.Rotate90FlipXY: + + newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); + FreeImage.FlipHorizontal(newDib); + FreeImage.FlipVertical(newDib); + break; + + case RotateFlipType.Rotate180FlipXY: + newDib = FreeImage.Clone(dib); + break; + } + ReplaceDib(newDib); + } + + /// + /// Copies the metadata from another . + /// + /// The bitmap to read the metadata from. + /// + /// is a null reference. + /// + public void CloneMetadataFrom(FreeImageBitmap bitmap) + { + if (bitmap == null) + { + throw new ArgumentNullException("bitmap"); + } + EnsureNotDisposed(); + bitmap.EnsureNotDisposed(); + FreeImage.CloneMetadata(dib, bitmap.dib); + } + + /// + /// Copies the metadata from another using + /// the provided options. + /// + /// The bitmap to read the metadata from. + /// Specifies the way the metadata is copied. + /// + /// is a null reference. + /// + public void CloneMetadataFrom(FreeImageBitmap bitmap, FREE_IMAGE_METADATA_COPY flags) + { + if (bitmap == null) + { + throw new ArgumentNullException("bitmap"); + } + EnsureNotDisposed(); + bitmap.EnsureNotDisposed(); + FreeImage.CloneMetadataEx(bitmap.dib, dib, flags); + } + + /// + /// Saves this to the specified file. + /// + /// A string that contains the name of the file to which + /// to save this . + /// is null or empty. + /// Saving the image failed. + public void Save(string filename) + { + Save(filename, FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + /// + /// Saves this to the specified file in the specified format. + /// + /// A string that contains the name of the file to which + /// to save this . + /// An that specifies the format of the saved image. + /// is null or empty. + /// Saving the image failed. + public void Save(string filename, FREE_IMAGE_FORMAT format) + { + Save(filename, format, FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + /// + /// Saves this to the specified file in the specified format + /// using the specified saving flags. + /// + /// A string that contains the name of the file to which + /// to save this . + /// An that specifies the format of the saved image. + /// Flags to enable or disable plugin-features. + /// is null or empty. + /// Saving the image failed. + public void Save(string filename, FREE_IMAGE_FORMAT format, FREE_IMAGE_SAVE_FLAGS flags) + { + EnsureNotDisposed(); + if (string.IsNullOrEmpty(filename)) + { + throw new ArgumentException("filename"); + } + if (!FreeImage.SaveEx(dib, filename, format, flags)) + { + throw new Exception("Unable to save bitmap"); + } + + saveInformation.filename = filename; + saveInformation.format = format; + saveInformation.saveFlags = flags; + } + + /// + /// Saves this to the specified stream in the specified format. + /// + /// The stream where this will be saved. + /// An that specifies the format of the saved image. + /// is a null reference. + /// Saving the image failed. + public void Save(Stream stream, FREE_IMAGE_FORMAT format) + { + Save(stream, format, FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + /// + /// Saves this to the specified stream in the specified format + /// using the specified saving flags. + /// + /// The stream where this will be saved. + /// An that specifies the format of the saved image. + /// Flags to enable or disable plugin-features. + /// is a null reference. + /// Saving the image failed. + public void Save(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_SAVE_FLAGS flags) + { + EnsureNotDisposed(); + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + if (!FreeImage.SaveToStream(dib, stream, format, flags)) + { + throw new Exception("Unable to save bitmap"); + } + + saveInformation.filename = null; + } + + /// + /// Adds a frame to the file specified in a previous call to the + /// method. + /// + /// + /// This instance has not been saved to a file using Save(...) before. + public void SaveAdd() + { + SaveAdd(this); + } + + /// + /// Adds a frame to the file specified in a previous call to the method. + /// + /// The position at which the frame should be inserted. + /// + /// This instance has not yet been saved to a file using the Save(...) method. + /// is out of range. + public void SaveAdd(int insertPosition) + { + SaveAdd(this, insertPosition); + } + + /// + /// Adds a frame to the file specified in a previous call to the method. + /// + /// A that contains the frame to add. + /// + /// This instance has not yet been saved to a file using the Save(...) method. + public void SaveAdd(FreeImageBitmap bitmap) + { + if (saveInformation.filename == null) + { + throw new InvalidOperationException("This operation requires a previous call of Save()."); + } + + SaveAdd( + saveInformation.filename, + bitmap, + saveInformation.format, + saveInformation.loadFlags, + saveInformation.saveFlags); + } + + /// + /// Adds a frame to the file specified in a previous call to the method. + /// + /// A that contains the frame to add. + /// The position at which the frame should be inserted. + /// + /// This instance has not yet been saved to a file using the Save(...) method. + /// is out of range. + public void SaveAdd(FreeImageBitmap bitmap, int insertPosition) + { + if (saveInformation.filename == null) + { + throw new InvalidOperationException("This operation requires a previous call of Save()."); + } + + SaveAdd( + saveInformation.filename, + bitmap, + insertPosition, + saveInformation.format, + saveInformation.loadFlags, + saveInformation.saveFlags); + } + + /// + /// Adds a frame to the file specified. + /// + /// File to add this frame to. + /// is a null reference. + /// does not exist. + /// Saving the image has failed. + public void SaveAdd(string filename) + { + SaveAdd( + filename, + this, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + FREE_IMAGE_LOAD_FLAGS.DEFAULT, + FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + /// + /// Adds a frame to the file specified. + /// + /// File to add this frame to. + /// The position at which the frame should be inserted. + /// is a null reference. + /// does not exist. + /// Saving the image has failed. + /// is out of range. + public void SaveAdd(string filename, int insertPosition) + { + SaveAdd( + filename, + this, + insertPosition, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + FREE_IMAGE_LOAD_FLAGS.DEFAULT, + FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + /// + /// Adds a frame to the file specified using the specified parameters. + /// + /// File to add this frame to. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// Flags to enable or disable plugin-features. + /// is a null reference. + /// does not exist. + /// Saving the image has failed. + public void SaveAdd( + string filename, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_LOAD_FLAGS loadFlags, + FREE_IMAGE_SAVE_FLAGS saveFlags) + { + SaveAdd( + filename, + this, + format, + loadFlags, + saveFlags); + } + + /// + /// Adds a frame to the file specified using the specified parameters. + /// + /// File to add this frame to. + /// The position at which the frame should be inserted. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// Flags to enable or disable plugin-features. + /// is a null reference. + /// does not exist. + /// Saving the image has failed. + /// is out of range. + public void SaveAdd( + string filename, + int insertPosition, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_LOAD_FLAGS loadFlags, + FREE_IMAGE_SAVE_FLAGS saveFlags) + { + SaveAdd( + filename, + this, + insertPosition, + format, + loadFlags, + saveFlags); + } + + /// + /// Selects the frame specified by the index. + /// + /// The index of the active frame. + /// + /// is out of range. + /// The operation failed. + /// The source of the bitmap is not available. + /// + public void SelectActiveFrame(int frameIndex) + { + EnsureNotDisposed(); + if ((frameIndex < 0) || (frameIndex >= frameCount)) + { + throw new ArgumentOutOfRangeException("frameIndex"); + } + + if (frameIndex != this.frameIndex) + { + if (stream == null) + { + throw new InvalidOperationException("No source available."); + } + + FREE_IMAGE_FORMAT format = originalFormat; + FIMULTIBITMAP mdib = FreeImage.OpenMultiBitmapFromStream(stream, ref format, saveInformation.loadFlags); + if (mdib.IsNull) + throw new Exception(ErrorLoadingBitmap); + + try + { + if (frameIndex >= FreeImage.GetPageCount(mdib)) + { + throw new ArgumentOutOfRangeException("frameIndex"); + } + + FIBITMAP newDib = FreeImage.LockPage(mdib, frameIndex); + if (newDib.IsNull) + { + throw new Exception(ErrorLoadingFrame); + } + + try + { + FIBITMAP clone = FreeImage.Clone(newDib); + if (clone.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + ReplaceDib(clone); + } + finally + { + if (!newDib.IsNull) + { + FreeImage.UnlockPage(mdib, newDib, false); + } + } + } + finally + { + if (!FreeImage.CloseMultiBitmapEx(ref mdib)) + { + throw new Exception(ErrorUnloadBitmap); + } + } + + this.frameIndex = frameIndex; + } + } + + /// + /// Creates a GDI bitmap object from this . + /// + /// A handle to the GDI bitmap object that this method creates. + public IntPtr GetHbitmap() + { + EnsureNotDisposed(); + return FreeImage.GetHbitmap(dib, IntPtr.Zero, false); + } + + /// + /// Creates a GDI bitmap object from this . + /// + /// A structure that specifies the background color. + /// This parameter is ignored if the bitmap is totally opaque. + /// A handle to the GDI bitmap object that this method creates. + public IntPtr GetHbitmap(Color background) + { + EnsureNotDisposed(); + using (FreeImageBitmap temp = new FreeImageBitmap(this)) + { + temp.BackgroundColor = background; + return temp.GetHbitmap(); + } + } + + /// + /// Returns the handle to an icon. + /// + /// A Windows handle to an icon with the same image as this . + public IntPtr GetHicon() + { + EnsureNotDisposed(); + using (Bitmap bitmap = FreeImage.GetBitmap(dib, true)) + { + return bitmap.GetHicon(); + } + } + + /// + /// Creates a GDI bitmap object from this with the same + /// color depth as the primary device. + /// + /// A handle to the GDI bitmap object that this method creates. + public IntPtr GetHbitmapForDevice() + { + EnsureNotDisposed(); + return FreeImage.GetBitmapForDevice(dib, IntPtr.Zero, false); + } + + /// + /// Gets the of the specified pixel in this . + /// + /// The x-coordinate of the pixel to retrieve. + /// The y-coordinate of the pixel to retrieve. + /// A structure that represents the color of the specified pixel. + /// The operation failed. + /// The type of this bitmap is not supported. + public unsafe Color GetPixel(int x, int y) + { + EnsureNotDisposed(); + if (FreeImage.GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) + { + if (ColorDepth == 16 || ColorDepth == 24 || ColorDepth == 32) + { + RGBQUAD rgbq; + if (!FreeImage.GetPixelColor(dib, (uint)x, (uint)y, out rgbq)) + { + throw new Exception("FreeImage.GetPixelColor() failed"); + } + return rgbq.Color; + } + else if (ColorDepth == 1 || ColorDepth == 4 || ColorDepth == 8) + { + byte index; + if (!FreeImage.GetPixelIndex(dib, (uint)x, (uint)y, out index)) + { + throw new Exception("FreeImage.GetPixelIndex() failed"); + } + RGBQUAD* palette = (RGBQUAD*)FreeImage.GetPalette(dib); + return palette[index].Color; + } + } + throw new NotSupportedException("The type of the image is not supported"); + } + + /// + /// Makes the default transparent color transparent for this . + /// + public void MakeTransparent() + { + EnsureNotDisposed(); + MakeTransparent(Color.Transparent); + } + + /// + /// Makes the specified color transparent for this . + /// + /// The structure that represents + /// the color to make transparent. + /// + /// This method is not implemented. + public void MakeTransparent(Color transparentColor) + { + EnsureNotDisposed(); + throw new System.NotImplementedException(); + } + + /// + /// Sets the of the specified pixel in this . + /// + /// The x-coordinate of the pixel to set. + /// The y-coordinate of the pixel to set. + /// A structure that represents the color + /// to assign to the specified pixel. + /// The operation failed. + /// The type of this bitmap is not supported. + public unsafe void SetPixel(int x, int y, Color color) + { + EnsureNotDisposed(); + if (FreeImage.GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) + { + if (ColorDepth == 16 || ColorDepth == 24 || ColorDepth == 32) + { + RGBQUAD rgbq = color; + if (!FreeImage.SetPixelColor(dib, (uint)x, (uint)y, ref rgbq)) + { + throw new Exception("FreeImage.SetPixelColor() failed"); + } + return; + } + else if (ColorDepth == 1 || ColorDepth == 4 || ColorDepth == 8) + { + uint colorsUsed = FreeImage.GetColorsUsed(dib); + RGBQUAD* palette = (RGBQUAD*)FreeImage.GetPalette(dib); + for (int i = 0; i < colorsUsed; i++) + { + if (palette[i].Color == color) + { + byte index = (byte)i; + if (!FreeImage.SetPixelIndex(dib, (uint)x, (uint)y, ref index)) + { + throw new Exception("FreeImage.SetPixelIndex() failed"); + } + return; + } + } + throw new ArgumentOutOfRangeException("color"); + } + } + throw new NotSupportedException("The type of the image is not supported"); + } + + /// + /// Sets the resolution for this . + /// + /// The horizontal resolution, in dots per inch, of this . + /// The vertical resolution, in dots per inch, of this . + public void SetResolution(float xDpi, float yDpi) + { + EnsureNotDisposed(); + FreeImage.SetResolutionX(dib, (uint)xDpi); + FreeImage.SetResolutionY(dib, (uint)yDpi); + } + + /// + /// This function is not yet implemented. + /// + /// + /// This method is not implemented. + public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format) + { + throw new NotImplementedException(); + } + + /// + /// This function is not yet implemented. + /// + /// + /// This method is not implemented. + public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData) + { + throw new NotImplementedException(); + } + + /// + /// This function is not yet implemented. + /// + /// + /// This method is not implemented. + public void UnlockBits(BitmapData bitmapdata) + { + throw new NotImplementedException(); + } + + /// + /// Converts this into a different color depth. + /// The parameter specifies color depth, greyscale conversion + /// and palette reorder. + /// Adding the flag + /// will first perform a convesion to greyscale. This can be done with any target + /// color depth. + /// Adding the flag + /// will allow the algorithm to reorder the palette. This operation will not be performed to + /// non-greyscale images to prevent data loss by mistake. + /// + /// A bitfield containing information about the conversion + /// to perform. + /// Returns true on success, false on failure. + public bool ConvertColorDepth(FREE_IMAGE_COLOR_DEPTH bpp) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.ConvertColorDepth(dib, bpp, false)); + } + + /// + /// Converts this to + /// initializing a new instance. + /// In case source and destination type are the same, the operation fails. + /// An error message can be catched using the 'Message' event. + /// + /// Destination type. + /// True to scale linear, else false. + /// Returns true on success, false on failure. + public bool ConvertType(FREE_IMAGE_TYPE type, bool scaleLinear) + { + EnsureNotDisposed(); + return (ImageType == type) ? false : ReplaceDib(FreeImage.ConvertToType(dib, type, scaleLinear)); + } + + /// + /// Converts this to . + /// In case source and destination type are the same, the operation fails. + /// An error message can be catched using the 'Message' event. + /// + /// Destination type. + /// True to scale linear, else false. + /// The converted instance. + public FreeImageBitmap GetTypeConvertedInstance(FREE_IMAGE_TYPE type, bool scaleLinear) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + if (ImageType != type) + { + FIBITMAP newDib = FreeImage.ConvertToType(dib, type, scaleLinear); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + } + return result; + } + + /// + /// Converts this into a different color depth initializing + /// a new instance. + /// The parameter specifies color depth, greyscale conversion + /// and palette reorder. + /// Adding the flag will + /// first perform a convesion to greyscale. This can be done with any target color depth. + /// Adding the flag will + /// allow the algorithm to reorder the palette. This operation will not be performed to + /// non-greyscale images to prevent data loss by mistake. + /// + /// A bitfield containing information about the conversion + /// to perform. + /// The converted instance. + public FreeImageBitmap GetColorConvertedInstance(FREE_IMAGE_COLOR_DEPTH bpp) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.ConvertColorDepth(dib, bpp, false); + if (newDib == dib) + { + newDib = FreeImage.Clone(dib); + } + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Rescales this to the specified size using the + /// specified filter. + /// + /// The Size structure that represent the + /// size of the new . + /// Filter to use for resizing. + /// Returns true on success, false on failure. + public bool Rescale(Size newSize, FREE_IMAGE_FILTER filter) + { + return Rescale(newSize.Width, newSize.Height, filter); + } + + /// + /// Rescales this to the specified size using the + /// specified filter. + /// + /// Width of the new . + /// Height of the new . + /// Filter to use for resizing. + /// Returns true on success, false on failure. + public bool Rescale(int width, int height, FREE_IMAGE_FILTER filter) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.Rescale(dib, width, height, filter)); + } + + /// + /// Rescales this to the specified size using the + /// specified filter initializing a new instance. + /// + /// The Size structure that represent the + /// size of the new . + /// Filter to use for resizing. + /// The rescaled instance. + public FreeImageBitmap GetScaledInstance(Size newSize, FREE_IMAGE_FILTER filter) + { + return GetScaledInstance(newSize.Width, newSize.Height, filter); + } + + /// + /// Rescales this to the specified size using the + /// specified filter initializing a new instance. + /// + /// Width of the new . + /// Height of the new . + /// Filter to use for resizing. + /// The rescaled instance. + public FreeImageBitmap GetScaledInstance(int width, int height, FREE_IMAGE_FILTER filter) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.Rescale(dib, width, height, filter); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Enlarges or shrinks this selectively per side and fills + /// newly added areas with the specified background color. + /// See for further details. + /// + /// The type of the specified color. + /// The number of pixels, the image should be enlarged on its left side. + /// Negative values shrink the image on its left side. + /// The number of pixels, the image should be enlarged on its top side. + /// Negative values shrink the image on its top side. + /// The number of pixels, the image should be enlarged on its right side. + /// Negative values shrink the image on its right side. + /// The number of pixels, the image should be enlarged on its bottom side. + /// Negative values shrink the image on its bottom side. + /// The color, the enlarged sides of the image should be filled with. + /// true on success, false on failure. + public bool EnlargeCanvas(int left, int top, int right, int bottom, T? color) where T : struct + { + return EnlargeCanvas(left, top, right, bottom, color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT); + } + + /// + /// Enlarges or shrinks this selectively per side and fills + /// newly added areas with the specified background color. + /// See for further details. + /// + /// The type of the specified color. + /// The number of pixels, the image should be enlarged on its left side. + /// Negative values shrink the image on its left side. + /// The number of pixels, the image should be enlarged on its top side. + /// Negative values shrink the image on its top side. + /// The number of pixels, the image should be enlarged on its right side. + /// Negative values shrink the image on its right side. + /// The number of pixels, the image should be enlarged on its bottom side. + /// Negative values shrink the image on its bottom side. + /// The color, the enlarged sides of the image should be filled with. + /// Options that affect the color search process for palletized images. + /// true on success, false on failure. + public bool EnlargeCanvas(int left, int top, int right, int bottom, + T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.EnlargeCanvas(dib, left, top, right, bottom, color, options)); + } + + /// + /// Enlarges or shrinks this selectively per side and fills + /// newly added areas with the specified background color returning a new instance. + /// See for further details. + /// + /// The type of the specified color. + /// The number of pixels, the image should be enlarged on its left side. + /// Negative values shrink the image on its left side. + /// The number of pixels, the image should be enlarged on its top side. + /// Negative values shrink the image on its top side. + /// The number of pixels, the image should be enlarged on its right side. + /// Negative values shrink the image on its right side. + /// The number of pixels, the image should be enlarged on its bottom side. + /// Negative values shrink the image on its bottom side. + /// The color, the enlarged sides of the image should be filled with. + /// The enlarged instance. + public FreeImageBitmap GetEnlargedInstance(int left, int top, int right, int bottom, + T? color) where T : struct + { + return GetEnlargedInstance(left, top, right, bottom, color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT); + } + + /// + /// Enlarges or shrinks this selectively per side and fills + /// newly added areas with the specified background color returning a new instance. + /// See for further details. + /// + /// The type of the specified color. + /// The number of pixels, the image should be enlarged on its left side. + /// Negative values shrink the image on its left side. + /// The number of pixels, the image should be enlarged on its top side. + /// Negative values shrink the image on its top side. + /// The number of pixels, the image should be enlarged on its right side. + /// Negative values shrink the image on its right side. + /// The number of pixels, the image should be enlarged on its bottom side. + /// Negative values shrink the image on its bottom side. + /// The color, the enlarged sides of the image should be filled with. + /// Options that affect the color search process for palletized images. + /// The enlarged instance. + public FreeImageBitmap GetEnlargedInstance(int left, int top, int right, int bottom, + T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.EnlargeCanvas(dib, left, top, right, bottom, color, options); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Quantizes this from 24 bit to 8bit creating a new + /// palette with the specified using the specified + /// . + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// Returns true on success, false on failure. + public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize) + { + return Quantize(algorithm, paletteSize, 0, (RGBQUAD[])null); + } + + /// + /// Quantizes this from 24 bit to 8bit creating a new + /// palette with the specified using the specified + /// and the specified + /// palette up to the + /// specified length. + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// The provided palette. + /// Returns true on success, false on failure. + public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, Palette reservePalette) + { + return Quantize(algorithm, paletteSize, reservePalette.Length, reservePalette.Data); + } + + /// + /// Quantizes this from 24 bit to 8bit creating a new + /// palette with the specified using the specified + /// and the specified + /// palette up to the + /// specified length. + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// Size of the provided palette of ReservePalette. + /// The provided palette. + /// Returns true on success, false on failure. + public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, Palette reservePalette) + { + return Quantize(algorithm, paletteSize, reserveSize, reservePalette.Data); + } + + /// + /// Quantizes this from 24 bit to 8bit creating a new + /// palette with the specified using the specified + /// and the specified + /// palette up to the + /// specified length. + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// Size of the provided palette of ReservePalette. + /// The provided palette. + /// Returns true on success, false on failure. + public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, RGBQUAD[] reservePalette) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.ColorQuantizeEx(dib, algorithm, paletteSize, reserveSize, reservePalette)); + } + + /// + /// Quantizes this from 24 bit, using the specified + /// initializing a new 8 bit instance with the + /// specified . + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// The quantized instance. + public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize) + { + return GetQuantizedInstance(algorithm, paletteSize, 0, (RGBQUAD[])null); + } + + /// + /// Quantizes this from 24 bit, using the specified + /// and palette + /// initializing a new 8 bit instance with the specified . + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// The provided palette. + /// The quantized instance. + public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, Palette reservePalette) + { + return GetQuantizedInstance(algorithm, paletteSize, reservePalette.Length, reservePalette); + } + + /// + /// Quantizes this from 24 bit, using the specified + /// and up to + /// entries from palette initializing + /// a new 8 bit instance with the specified . + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// Size of the provided palette. + /// The provided palette. + /// The quantized instance. + public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, Palette reservePalette) + { + return GetQuantizedInstance(algorithm, paletteSize, reserveSize, reservePalette.Data); + } + + /// + /// Quantizes this from 24 bit, using the specified + /// and up to + /// entries from palette initializing + /// a new 8 bit instance with the specified . + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// Size of the provided palette. + /// The provided palette. + /// The quantized instance. + public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, RGBQUAD[] reservePalette) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.ColorQuantizeEx(dib, algorithm, paletteSize, reserveSize, reservePalette); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Converts a High Dynamic Range image to a 24-bit RGB image using a global + /// operator based on logarithmic compression of luminance values, imitating + /// the human response to light. + /// + /// A gamma correction that is applied after the tone mapping. + /// A value of 1 means no correction. + /// Scale factor allowing to adjust the brightness of the output image. + /// Returns true on success, false on failure. + public bool TmoDrago03(double gamma, double exposure) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.TmoDrago03(dib, gamma, exposure)); + } + + /// + /// Converts a High Dynamic Range image to a 24-bit RGB image using a global operator inspired + /// by photoreceptor physiology of the human visual system. + /// + /// Controls the overall image intensity in the range [-8, 8]. + /// Controls the overall image contrast in the range [0.3, 1.0[. + /// Returns true on success, false on failure. + public bool TmoReinhard05(double intensity, double contrast) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.TmoReinhard05(dib, intensity, contrast)); + } + + /// + /// Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and convert to 24-bit RGB. + /// + /// Color saturation (s parameter in the paper) in [0.4..0.6] + /// Atenuation factor (beta parameter in the paper) in [0.8..0.9] + /// Returns true on success, false on failure. + public bool TmoFattal02(double color_saturation, double attenuation) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.TmoFattal02(dib, color_saturation, attenuation)); + } + + /// + /// This method rotates a 1-, 4-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. + /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer + /// multiple of 90. + /// + /// The angle of rotation. + /// Returns true on success, false on failure. + public bool Rotate(double angle) + { + EnsureNotDisposed(); + bool result = false; + if (ColorDepth == 4) + { + result = ReplaceDib(FreeImage.Rotate4bit(dib, angle)); + } + else + { + result = ReplaceDib(FreeImage.Rotate(dib, angle)); + } + return result; + } + + /// + /// This method rotates a 1-, 4-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. + /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer + /// multiple of 90. + /// + /// The type of the color to use as background. + /// The angle of rotation. + /// The color used used to fill the bitmap's background. + /// Returns true on success, false on failure. + public bool Rotate(double angle, T? backgroundColor) where T : struct + { + EnsureNotDisposed(); + bool result = false; + if (ColorDepth == 4) + { + result = ReplaceDib(FreeImage.Rotate4bit(dib, angle)); + } + else + { + result = ReplaceDib(FreeImage.Rotate(dib, angle, backgroundColor)); + } + return result; + } + + /// + /// Rotates this by the specified angle initializing a new instance. + /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer + /// multiple of 90. + /// + /// The type of the color to use as background. + /// The angle of rotation. + /// The color used used to fill the bitmap's background. + /// The rotated instance. + public FreeImageBitmap GetRotatedInstance(double angle, T? backgroundColor) where T : struct + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib; + if (ColorDepth == 4) + { + newDib = FreeImage.Rotate4bit(dib, angle); + } + else + { + newDib = FreeImage.Rotate(dib, angle, backgroundColor); + } + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Rotates this by the specified angle initializing a new instance. + /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer + /// multiple of 90. + /// + /// The angle of rotation. + /// The rotated instance. + public FreeImageBitmap GetRotatedInstance(double angle) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib; + if (ColorDepth == 4) + { + newDib = FreeImage.Rotate4bit(dib, angle); + } + else + { + newDib = FreeImage.Rotate(dib, angle); + } + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// This method performs a rotation and / or translation of an 8-bit greyscale, + /// 24- or 32-bit image, using a 3rd order (cubic) B-Spline. + /// + /// The angle of rotation. + /// Horizontal image translation. + /// Vertical image translation. + /// Rotation center x-coordinate. + /// Rotation center y-coordinate. + /// When true the irrelevant part of the image is set to a black color, + /// otherwise, a mirroring technique is used to fill irrelevant pixels. + /// Returns true on success, false on failure. + public bool Rotate(double angle, double xShift, double yShift, + double xOrigin, double yOrigin, bool useMask) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.RotateEx(dib, angle, xShift, yShift, xOrigin, yOrigin, useMask)); + } + + /// + /// This method performs a rotation and / or translation of an 8-bit greyscale, + /// 24- or 32-bit image, using a 3rd order (cubic) B-Spline initializing a new instance. + /// + /// The angle of rotation. + /// Horizontal image translation. + /// Vertical image translation. + /// Rotation center x-coordinate. + /// Rotation center y-coordinate. + /// When true the irrelevant part of the image is set to a black color, + /// otherwise, a mirroring technique is used to fill irrelevant pixels. + /// The rotated instance. + public FreeImageBitmap GetRotatedInstance(double angle, double xShift, double yShift, + double xOrigin, double yOrigin, bool useMask) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.RotateEx( + dib, angle, xShift, yShift, xOrigin, yOrigin, useMask); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Perfoms an histogram transformation on a 8-, 24- or 32-bit image. + /// + /// The lookup table (LUT). + /// It's size is assumed to be 256 in length. + /// The color channel to be transformed. + /// Returns true on success, false on failure. + public bool AdjustCurve(byte[] lookUpTable, FREE_IMAGE_COLOR_CHANNEL channel) + { + EnsureNotDisposed(); + return FreeImage.AdjustCurve(dib, lookUpTable, channel); + } + + /// + /// Performs gamma correction on a 8-, 24- or 32-bit image. + /// + /// The parameter represents the gamma value to use (gamma > 0). + /// A value of 1.0 leaves the image alone, less than one darkens it, and greater than one lightens it. + /// Returns true on success, false on failure. + public bool AdjustGamma(double gamma) + { + EnsureNotDisposed(); + return FreeImage.AdjustGamma(dib, gamma); + } + + /// + /// Adjusts the brightness of a 8-, 24- or 32-bit image by a certain amount. + /// + /// A value 0 means no change, + /// less than 0 will make the image darker and greater than 0 will make the image brighter. + /// Returns true on success, false on failure. + public bool AdjustBrightness(double percentage) + { + EnsureNotDisposed(); + return FreeImage.AdjustBrightness(dib, percentage); + } + + /// + /// Adjusts the contrast of a 8-, 24- or 32-bit image by a certain amount. + /// + /// A value 0 means no change, + /// less than 0 will decrease the contrast and greater than 0 will increase the contrast of the image. + /// Returns true on success, false on failure. + public bool AdjustContrast(double percentage) + { + EnsureNotDisposed(); + return FreeImage.AdjustContrast(dib, percentage); + } + + /// + /// Inverts each pixel data. + /// + /// Returns true on success, false on failure. + public bool Invert() + { + EnsureNotDisposed(); + return FreeImage.Invert(dib); + } + + /// + /// Computes the image histogram. + /// + /// Channel to compute from. + /// Array of integers containing the histogram. + /// Returns true on success, false on failure. + public bool GetHistogram(FREE_IMAGE_COLOR_CHANNEL channel, out int[] histogram) + { + EnsureNotDisposed(); + histogram = new int[256]; + return FreeImage.GetHistogram(dib, histogram, channel); + } + + /// + /// Retrieves the red, green, blue or alpha channel of a 24- or 32-bit image. + /// + /// The color channel to extract. + /// The color channel in a new instance. + public FreeImageBitmap GetChannel(FREE_IMAGE_COLOR_CHANNEL channel) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.GetChannel(dib, channel); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Insert a 8-bit dib into a 24- or 32-bit image. + /// Both images must have to same width and height. + /// + /// The to insert. + /// The color channel to replace. + /// Returns true on success, false on failure. + public bool SetChannel(FreeImageBitmap bitmap, FREE_IMAGE_COLOR_CHANNEL channel) + { + EnsureNotDisposed(); + bitmap.EnsureNotDisposed(); + return FreeImage.SetChannel(dib, bitmap.dib, channel); + } + + /// + /// Retrieves the real part, imaginary part, magnitude or phase of a complex image. + /// + /// The color channel to extract. + /// The color channel in a new instance. + public FreeImageBitmap GetComplexChannel(FREE_IMAGE_COLOR_CHANNEL channel) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.GetComplexChannel(dib, channel); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Set the real or imaginary part of a complex image. + /// Both images must have to same width and height. + /// + /// The to insert. + /// The color channel to replace. + /// Returns true on success, false on failure. + public bool SetComplexChannel(FreeImageBitmap bitmap, FREE_IMAGE_COLOR_CHANNEL channel) + { + EnsureNotDisposed(); + bitmap.EnsureNotDisposed(); + return FreeImage.SetComplexChannel(dib, bitmap.dib, channel); + } + + /// + /// Copy a sub part of this . + /// + /// The subpart to copy. + /// The sub part in a new instance. + public FreeImageBitmap Copy(Rectangle rect) + { + EnsureNotDisposed(); + return Copy(rect.Left, rect.Top, rect.Right, rect.Bottom); + } + + /// + /// Copy a sub part of this . + /// + /// Specifies the left position of the cropped rectangle. + /// Specifies the top position of the cropped rectangle. + /// Specifies the right position of the cropped rectangle. + /// Specifies the bottom position of the cropped rectangle. + /// The sub part in a new instance. + public FreeImageBitmap Copy(int left, int top, int right, int bottom) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.Copy(dib, left, top, right, bottom); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Alpha blend or combine a sub part image with this . + /// The bit depth of must be greater than or equal to the bit depth this instance. + /// + /// The to paste into this instance. + /// Specifies the left position of the sub image. + /// Specifies the top position of the sub image. + /// alpha blend factor. + /// The source and destination images are alpha blended if alpha=0..255. + /// If alpha > 255, then the source image is combined to the destination image. + /// Returns true on success, false on failure. + public bool Paste(FreeImageBitmap bitmap, int left, int top, int alpha) + { + EnsureNotDisposed(); + bitmap.EnsureNotDisposed(); + return FreeImage.Paste(dib, bitmap.dib, left, top, alpha); + } + + /// + /// Alpha blend or combine a sub part image with tthis . + /// The bit depth of must be greater than or equal to the bit depth this instance. + /// + /// The to paste into this instance. + /// Specifies the position of the sub image. + /// alpha blend factor. + /// The source and destination images are alpha blended if alpha=0..255. + /// If alpha > 255, then the source image is combined to the destination image. + /// Returns true on success, false on failure. + public bool Paste(FreeImageBitmap bitmap, Point point, int alpha) + { + EnsureNotDisposed(); + return Paste(bitmap, point.X, point.Y, alpha); + } + + /// + /// This method composite a transparent foreground image against a single background color or + /// against a background image. + /// In case is false and + /// and + /// are null, a checkerboard will be used as background. + /// + /// When true the background of this instance is used + /// if it contains one. + /// Backgroundcolor used in case is false + /// and is not null. + /// Background used in case + /// is false and is a null reference. + /// Returns true on success, false on failure. + public bool Composite(bool useBitmapBackground, Color? applicationBackground, FreeImageBitmap bitmapBackGround) + { + EnsureNotDisposed(); + bitmapBackGround.EnsureNotDisposed(); + RGBQUAD? rgb = applicationBackground; + return ReplaceDib( + FreeImage.Composite( + dib, + useBitmapBackground, + rgb.HasValue ? new RGBQUAD[] { rgb.Value } : null, + bitmapBackGround.dib)); + } + + /// + /// Applies the alpha value of each pixel to its color components. + /// The aplha value stays unchanged. + /// Only works with 32-bits color depth. + /// + /// Returns true on success, false on failure. + public bool PreMultiplyWithAlpha() + { + EnsureNotDisposed(); + return FreeImage.PreMultiplyWithAlpha(dib); + } + + /// + /// Solves a Poisson equation, remap result pixels to [0..1] and returns the solution. + /// + /// Number of cycles in the multigrid algorithm (usually 2 or 3) + /// Returns true on success, false on failure. + public bool MultigridPoissonSolver(int ncycle) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.MultigridPoissonSolver(dib, ncycle)); + } + + /// + /// Adjusts an image's brightness, contrast and gamma as well as it may + /// optionally invert the image within a single operation. + /// + /// Percentage brightness value where -100 <= brightness <= 100. + /// A value of 0 means no change, less than 0 will make the image darker and greater + /// than 0 will make the image brighter. + /// Percentage contrast value where -100 <= contrast <= 100. + /// A value of 0 means no change, less than 0 will decrease the contrast + /// and greater than 0 will increase the contrast of the image. + /// Gamma value to be used for gamma correction. + /// A value of 1.0 leaves the image alone, less than one darkens it, + /// and greater than one lightens it. + /// This parameter must not be zero or smaller than zero. + /// If so, it will be ignored and no gamma correction will be performed on the image. + /// If set to true, the image will be inverted. + /// Returns true on success, false on failure. + public bool AdjustColors(double brightness, double contrast, double gamma, bool invert) + { + EnsureNotDisposed(); + return FreeImage.AdjustColors(dib, brightness, contrast, gamma, invert); + } + + /// + /// Applies color mapping for one or several colors on a 1-, 4- or 8-bit + /// palletized or a 16-, 24- or 32-bit high color image. + /// + /// Array of colors to be used as the mapping source. + /// Array of colors to be used as the mapping destination. + /// If true, 32-bit images and colors are treated as 24-bit. + /// If true, source and destination colors are swapped, that is, + /// each destination color is also mapped to the corresponding source color. + /// The total number of pixels changed. + /// + /// or is a null reference. + /// + /// + /// has a different length than . + /// + public uint ApplyColorMapping(RGBQUAD[] srccolors, RGBQUAD[] dstcolors, bool ignore_alpha, bool swap) + { + EnsureNotDisposed(); + if (srccolors == null) + { + throw new ArgumentNullException("srccolors"); + } + if (dstcolors == null) + { + throw new ArgumentNullException("dstcolors"); + } + if (srccolors.Length != dstcolors.Length) + { + throw new ArgumentException("srccolors and dstcolors must have the same length."); + } + return FreeImage.ApplyColorMapping(dib, srccolors, dstcolors, (uint)srccolors.Length, ignore_alpha, swap); + } + + /// + /// Swaps two specified colors on a 1-, 4- or 8-bit palletized + /// or a 16-, 24- or 32-bit high color image. + /// + /// One of the two colors to be swapped. + /// The other of the two colors to be swapped. + /// If true, 32-bit images and colors are treated as 24-bit. + /// The total number of pixels changed. + public uint SwapColors(RGBQUAD color_a, RGBQUAD color_b, bool ignore_alpha) + { + EnsureNotDisposed(); + return FreeImage.SwapColors(dib, ref color_a, ref color_b, ignore_alpha); + } + + /// + /// Applies palette index mapping for one or several indices + /// on a 1-, 4- or 8-bit palletized image. + /// + /// Array of palette indices to be used as the mapping source. + /// Array of palette indices to be used as the mapping destination. + /// The number of palette indices to be mapped. This is the size of both + /// srcindices and dstindices + /// If true, source and destination palette indices are swapped, that is, + /// each destination index is also mapped to the corresponding source index. + /// The total number of pixels changed. + /// + /// or is a null reference. + /// + /// + /// has a different length than . + /// + public uint ApplyPaletteIndexMapping(byte[] srcindices, byte[] dstindices, uint count, bool swap) + { + EnsureNotDisposed(); + if (srcindices == null) + { + throw new ArgumentNullException("srcindices"); + } + if (dstindices == null) + { + throw new ArgumentNullException("dstindices"); + } + if (srcindices.Length != dstindices.Length) + { + throw new ArgumentException("srcindices and dstindices must have the same length."); + } + return FreeImage.ApplyPaletteIndexMapping(dib, srcindices, dstindices, (uint)srcindices.Length, swap); + } + + /// + /// Swaps two specified palette indices on a 1-, 4- or 8-bit palletized image. + /// + /// One of the two palette indices to be swapped. + /// The other of the two palette indices to be swapped. + /// The total number of pixels changed. + public uint SwapPaletteIndices(byte index_a, byte index_b) + { + EnsureNotDisposed(); + return FreeImage.SwapPaletteIndices(dib, ref index_a, ref index_b); + } + + /// + /// Sets all pixels of this to the specified color. + /// See for further details. + /// + /// The type of the specified color. + /// The color to fill this with. + /// true on success, false on failure. + public bool FillBackground(T color) where T : struct + { + return FillBackground(color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT); + } + + /// + /// Sets all pixels of this to the specified color. + /// See for further details. + /// + /// The type of the specified color. + /// The color to fill this with. + /// Options that affect the color search process for palletized images. + /// true on success, false on failure. + public bool FillBackground(T color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct + { + EnsureNotDisposed(); + return FreeImage.FillBackground(dib, color, options); + } + + /// + /// Creates a new ICC-Profile. + /// + /// The data of the new ICC-Profile. + /// The new ICC-Profile of the bitmap. + /// is a null reference. + public FIICCPROFILE CreateICCProfile(byte[] data) + { + if (data == null) + { + throw new ArgumentNullException("data"); + } + return CreateICCProfile(data, data.Length); + } + + /// + /// Creates a new ICC-Profile. + /// + /// The data of the new ICC-Profile. + /// The number of bytes of to use. + /// The new ICC-Profile of the bitmap. + /// is null. + public FIICCPROFILE CreateICCProfile(byte[] data, int size) + { + EnsureNotDisposed(); + if (data == null) + { + throw new ArgumentNullException("data"); + } + return FreeImage.CreateICCProfileEx(dib, data, size); + } + + /// + /// Determines whether this and the specified instances are the same. + /// + /// The object to test. + /// true if this instance is the same + /// or if both are null references; otherwise, false. + public override bool Equals(object obj) + { + return ReferenceEquals(this, obj); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return dib.GetHashCode(); + } + + #endregion + + #region Static functions + + /// + /// Returns a value that indicates whether the pixel format for this contains alpha information. + /// + /// The to test. + /// true if pixfmt contains alpha information; otherwise, false. + public static bool IsAlphaPixelFormat(PixelFormat pixfmt) + { + return Bitmap.IsAlphaPixelFormat(pixfmt); + } + + /// + /// Returns a value that indicates whether the pixel format is 32 bits per pixel. + /// + /// The to test. + /// true if pixfmt is canonical; otherwise, false. + public static bool IsCanonicalPixelFormat(PixelFormat pixfmt) + { + return Bitmap.IsCanonicalPixelFormat(pixfmt); + } + + /// + /// Returns a value that indicates whether the pixel format is 64 bits per pixel. + /// + /// The enumeration to test. + /// true if pixfmt is extended; otherwise, false. + public static bool IsExtendedPixelFormat(PixelFormat pixfmt) + { + return Bitmap.IsExtendedPixelFormat(pixfmt); + } + + /// + /// Creates a from a Windows handle to an icon. + /// + /// A handle to an icon. + /// The that this method creates. + public static FreeImageBitmap FromHicon(IntPtr hicon) + { + using (Bitmap bitmap = Bitmap.FromHicon(hicon)) + { + return new FreeImageBitmap(bitmap); + } + } + + /// + /// Creates a from the specified Windows resource. + /// + /// A handle to an instance of the executable + /// file that contains the resource. + /// A string containing the name of the resource bitmap. + /// The that this method creates. + public static FreeImageBitmap FromResource(IntPtr hinstance, string bitmapName) + { + using (Bitmap bitmap = Bitmap.FromResource(hinstance, bitmapName)) + { + return new FreeImageBitmap(bitmap); + } + } + + /// + /// Creates a from the specified file. + /// + /// A string that contains the name of the file + /// from which to create the . + /// The this method creates. + public static FreeImageBitmap FromFile(string filename) + { + return new FreeImageBitmap(filename); + } + + /// + /// Creates a from the specified file + /// using embedded color management information in that file. + /// + /// A string that contains the + /// name of the file from which to create the . + /// Ignored. + /// The this method creates. + public static FreeImageBitmap FromFile(string filename, bool useEmbeddedColorManagement) + { + return new FreeImageBitmap(filename); + } + + /// + /// Creates a from a handle to a GDI bitmap. + /// + /// The GDI bitmap handle from which to create the . + /// The this method creates. + public static FreeImageBitmap FromHbitmap(IntPtr hbitmap) + { + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.CreateFromHbitmap(hbitmap, IntPtr.Zero); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Creates a from a handle to a GDI bitmap and a handle to a GDI palette. + /// + /// The GDI bitmap handle from which to create the . + /// Ignored. + /// The this method creates. + public static FreeImageBitmap FromHbitmap(IntPtr hbitmap, IntPtr hpalette) + { + return FromHbitmap(hbitmap); + } + + /// + /// Frees a bitmap handle. + /// + /// Handle to a bitmap. + /// true on success, false on failure. + public static bool FreeHbitmap(IntPtr hbitmap) + { + return FreeImage.FreeHbitmap(hbitmap); + } + + /// + /// Creates a from the specified data stream. + /// + /// A that contains the data for this . + /// The this method creates. + public static FreeImageBitmap FromStream(Stream stream) + { + return new FreeImageBitmap(stream); + } + + /// + /// Creates a from the specified data stream. + /// + /// A that contains the data for this . + /// Ignored. + /// The this method creates. + public static FreeImageBitmap FromStream(Stream stream, bool useEmbeddedColorManagement) + { + return new FreeImageBitmap(stream); + } + + /// + /// Creates a from the specified data stream. + /// + /// A that contains the data for this . + /// Ignored. + /// Ignored. + /// The this method creates. + public static FreeImageBitmap FromStream(Stream stream, bool useEmbeddedColorManagement, bool validateImageData) + { + return new FreeImageBitmap(stream); + } + + /// + /// Returns the color depth, in number of bits per pixel, + /// of the specified pixel format. + /// + /// The member that specifies + /// the format for which to find the size. + /// The color depth of the specified pixel format. + public static int GetPixelFormatSize(PixelFormat pixfmt) + { + return Bitmap.GetPixelFormatSize(pixfmt); + } + + /// + /// Performs a lossless rotation or flipping on a JPEG file. + /// + /// Source file. + /// Destination file; can be the source file; will be overwritten. + /// The operation to apply. + /// To avoid lossy transformation, you can set the perfect parameter to true. + /// Returns true on success, false on failure. + public static bool JPEGTransform(string source, string destination, FREE_IMAGE_JPEG_OPERATION operation, bool perfect) + { + return FreeImage.JPEGTransform(source, destination, operation, perfect); + } + + /// + /// Performs a lossless crop on a JPEG file. + /// + /// Source filename. + /// Destination filename. + /// Specifies the cropped rectangle. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// + /// does not exist. + /// + public static bool JPEGCrop(string source, string destination, Rectangle rect) + { + if (source == null) + { + throw new ArgumentNullException("source"); + } + if (!File.Exists(source)) + { + throw new FileNotFoundException("source"); + } + if (destination == null) + { + throw new ArgumentNullException("destination"); + } + return JPEGCrop(source, destination, rect.Left, rect.Top, rect.Right, rect.Bottom); + } + + /// + /// Performs a lossless crop on a JPEG file. + /// + /// Source filename. + /// Destination filename. + /// Specifies the left position of the cropped rectangle. + /// Specifies the top position of the cropped rectangle. + /// Specifies the right position of the cropped rectangle. + /// Specifies the bottom position of the cropped rectangle. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// + /// does not exist. + /// + public static bool JPEGCrop(string source, string destination, int left, int top, int right, int bottom) + { + if (source == null) + { + throw new ArgumentNullException("source"); + } + if (!File.Exists(source)) + { + throw new FileNotFoundException("source"); + } + if (destination == null) + { + throw new ArgumentNullException("destination"); + } + return FreeImage.JPEGCrop(source, destination, left, top, right, bottom); + } + + /// + /// Converts a X11 color name into a corresponding RGB value. + /// + /// Name of the color to convert. + /// Red component. + /// Green component. + /// Blue component. + /// Returns true on success, false on failure. + /// is null. + public static bool LookupX11Color(string color, out byte red, out byte green, out byte blue) + { + if (color == null) + { + throw new ArgumentNullException("color"); + } + return FreeImage.LookupX11Color(color, out red, out green, out blue); + } + + /// + /// Converts a SVG color name into a corresponding RGB value. + /// + /// Name of the color to convert. + /// Red component. + /// Green component. + /// Blue component. + /// Returns true on success, false on failure. + /// is null. + public static bool LookupSVGColor(string color, out byte red, out byte green, out byte blue) + { + if (color == null) + { + throw new ArgumentNullException("color"); + } + return FreeImage.LookupSVGColor(color, out red, out green, out blue); + } + + /// + /// Creates a lookup table to be used with AdjustCurve() which + /// may adjusts brightness and contrast, correct gamma and invert the image with a + /// single call to AdjustCurve(). + /// + /// Output lookup table to be used with AdjustCurve(). + /// The size of is assumed to be 256. + /// Percentage brightness value where -100 <= brightness <= 100. + /// A value of 0 means no change, less than 0 will make the image darker and greater + /// than 0 will make the image brighter. + /// Percentage contrast value where -100 <= contrast <= 100. + /// A value of 0 means no change, less than 0 will decrease the contrast + /// and greater than 0 will increase the contrast of the image. + /// Gamma value to be used for gamma correction. + /// A value of 1.0 leaves the image alone, less than one darkens it, + /// and greater than one lightens it. + /// If set to true, the image will be inverted. + /// The number of adjustments applied to the resulting lookup table + /// compared to a blind lookup table. + /// is null. + /// is not 256. + public static int GetAdjustColorsLookupTable(byte[] lookUpTable, double brightness, double contrast, double gamma, bool invert) + { + if (lookUpTable == null) + { + throw new ArgumentNullException("lookUpTable"); + } + if (lookUpTable.Length != 256) + { + throw new ArgumentException("lookUpTable"); + } + return FreeImage.GetAdjustColorsLookupTable(lookUpTable, brightness, contrast, gamma, invert); + } + + /// + /// Adds a specified frame to the file specified using the specified parameters. + /// Use this method to save selected frames from an to a multiple-frame image. + /// + /// File to add this frame to. + /// A that contains the frame to add. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// Flags to enable or disable plugin-features. + /// + /// or is null. + /// + /// does not exist. + /// Saving the image failed. + public static void SaveAdd( + string filename, + FreeImageBitmap bitmap, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_LOAD_FLAGS loadFlags, + FREE_IMAGE_SAVE_FLAGS saveFlags) + { + if (filename == null) + { + throw new ArgumentNullException("filename"); + } + if (!File.Exists(filename)) + { + throw new FileNotFoundException("filename"); + } + if (bitmap == null) + { + throw new ArgumentNullException("bitmap"); + } + bitmap.EnsureNotDisposed(); + + FIBITMAP dib = bitmap.dib; + if (dib.IsNull) + throw new ArgumentNullException("bitmap"); + + FIMULTIBITMAP mpBitmap = + FreeImage.OpenMultiBitmapEx(filename, ref format, loadFlags, false, false, true); + + if (mpBitmap.IsNull) + throw new Exception(ErrorLoadingBitmap); + + FreeImage.AppendPage(mpBitmap, bitmap.dib); + + if (!FreeImage.CloseMultiBitmap(mpBitmap, saveFlags)) + throw new Exception(ErrorUnloadBitmap); + } + + /// + /// Adds a specified frame to the file specified using the specified parameters. + /// Use this method to save selected frames from an image to a multiple-frame image. + /// + /// File to add this frame to. + /// A that contains the frame to add. + /// The position of the inserted frame. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// Flags to enable or disable plugin-features. + /// + /// or is null. + /// + /// does not exist. + /// Saving the image failed. + /// is out of range. + public static void SaveAdd( + string filename, + FreeImageBitmap bitmap, + int insertPosition, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_LOAD_FLAGS loadFlags, + FREE_IMAGE_SAVE_FLAGS saveFlags) + { + if (filename == null) + { + throw new ArgumentNullException("filename"); + } + if (!File.Exists(filename)) + { + throw new FileNotFoundException("filename"); + } + if (bitmap == null) + { + throw new ArgumentNullException("bitmap"); + } + if (insertPosition < 0) + { + throw new ArgumentOutOfRangeException("insertPosition"); + } + bitmap.EnsureNotDisposed(); + + FIBITMAP dib = bitmap.dib; + if (dib.IsNull) + throw new ArgumentNullException("bitmap"); + + FIMULTIBITMAP mpBitmap = + FreeImage.OpenMultiBitmapEx(filename, ref format, loadFlags, false, false, true); + + if (mpBitmap.IsNull) + throw new Exception(ErrorLoadingBitmap); + + int pageCount = FreeImage.GetPageCount(mpBitmap); + + if (insertPosition > pageCount) + throw new ArgumentOutOfRangeException("insertPosition"); + + if (insertPosition == pageCount) + FreeImage.AppendPage(mpBitmap, bitmap.dib); + else + FreeImage.InsertPage(mpBitmap, insertPosition, bitmap.dib); + + if (!FreeImage.CloseMultiBitmap(mpBitmap, saveFlags)) + throw new Exception(ErrorUnloadBitmap); + } + + /// + /// Returns a new instance of the class which + /// has no public accessible constructor. + /// + /// A new instace of . + public static PropertyItem CreateNewPropertyItem() + { + return FreeImage.CreatePropertyItem(); + } + + #endregion + + #region Helper functions + + /// + /// Throws an exception in case the instance has already been disposed. + /// + private void EnsureNotDisposed() + { + lock (lockObject) + { + if (!this.disposed) + { + return; + } + } + throw new ObjectDisposedException(ToString()); + } + + /// + /// Tries to replace the wrapped with a new one. + /// In case the new dib is null or the same as the already + /// wrapped one, nothing will be changed and the result will + /// be false. + /// Otherwise the wrapped will be unloaded and replaced. + /// + /// The new dib. + /// Returns true on success, false on failure. + private bool ReplaceDib(FIBITMAP newDib) + { + bool result = false; + if ((dib != newDib) && (!newDib.IsNull)) + { + UnloadDib(); + dib = newDib; + AddMemoryPressure(); + result = true; + } + return result; + } + + /// + /// Unloads currently wrapped or unlocks the locked page + /// in case it came from a multipaged bitmap. + /// + private void UnloadDib() + { + if (!dib.IsNull) + { + long size = FreeImage.GetDIBSize(dib); + FreeImage.UnloadEx(ref dib); + if (size > 0L) + GC.RemoveMemoryPressure(size); + } + } + + /// + /// Informs the runtime about unmanaged allocoted memory. + /// + private void AddMemoryPressure() + { + long dataSize; + if ((dataSize = DataSize) > 0L) + GC.AddMemoryPressure(dataSize); + } + + /// + /// Opens the stream and reads the number of available pages. + /// Then loads the first page to this instance. + /// + private void LoadFromStream(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) + { + FIMULTIBITMAP mdib = FreeImage.OpenMultiBitmapFromStream(stream, ref format, flags); + if (mdib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + try + { + frameCount = FreeImage.GetPageCount(mdib); + } + finally + { + if (!FreeImage.CloseMultiBitmapEx(ref mdib)) + { + throw new Exception(ErrorUnloadBitmap); + } + } + + dib = FreeImage.LoadFromStream(stream, flags, ref format); + if (dib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + + saveInformation.loadFlags = flags; + originalFormat = format; + AddMemoryPressure(); + } + + #endregion + + #region Interfaces + + /// + /// Helper class to store informations for . + /// + private sealed class SaveInformation : ICloneable + { + public string filename; + public FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + public FREE_IMAGE_LOAD_FLAGS loadFlags = FREE_IMAGE_LOAD_FLAGS.DEFAULT; + public FREE_IMAGE_SAVE_FLAGS saveFlags = FREE_IMAGE_SAVE_FLAGS.DEFAULT; + + public object Clone() + { + return base.MemberwiseClone(); + } + } + + /// + /// Creates a deep copy of this . + /// + /// A deep copy of this . + public object Clone() + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.Clone(dib); + if (!dib.IsNull) + { + result = new FreeImageBitmap(newDib); + result.saveInformation = (SaveInformation)saveInformation.Clone(); + result.tag = tag; + result.originalFormat = originalFormat; + } + return result; + } + + /// + /// Performs application-defined tasks associated with freeing, + /// releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Performs application-defined tasks associated with freeing, + /// releasing, or resetting unmanaged resources. + /// + /// If true managed ressources are released. + protected virtual void Dispose(bool disposing) + { + // Only clean up once + lock (lockObject) + { + if (disposed) + { + return; + } + disposed = true; + } + + // Clean up managed resources + if (disposing) + { + if (stream != null) + { + if (disposeStream) + { + stream.Dispose(); + } + stream = null; + } + } + + tag = null; + saveInformation = null; + + // Clean up unmanaged resources + UnloadDib(); + } + + /// + /// Retrieves an object that can iterate through the individual scanlines in this . + /// + /// An for the . + /// The bitmaps's type is not supported. + IEnumerator IEnumerable.GetEnumerator() + { + return GetScanlines().GetEnumerator(); + } + + void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) + { + EnsureNotDisposed(); + using (MemoryStream memory = new MemoryStream(DataSize)) + { + if (!FreeImage.SaveToStream(dib, memory, FREE_IMAGE_FORMAT.FIF_TIFF, FREE_IMAGE_SAVE_FLAGS.TIFF_LZW)) + { + throw new SerializationException(); + } + memory.Capacity = (int)memory.Length; + info.AddValue("Bitmap Data", memory.GetBuffer()); + } + } + + #endregion + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImageEngine.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImageEngine.cs index be287bc..584f87b 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImageEngine.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImageEngine.cs @@ -1,101 +1,101 @@ -using System; -using System.Runtime.InteropServices; -using System.Diagnostics; - -namespace FreeImageAPI -{ - /// - /// Class handling non-bitmap related functions. - /// - public static class FreeImageEngine - { - #region Callback - - // Callback delegate - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private static readonly OutputMessageFunction outputMessageFunction; - - static FreeImageEngine() - { - // Check if FreeImage.dll is present and cancel setting the callbackfuntion if not - if (!IsAvailable) - { - return; - } - // Create a delegate (function pointer) to 'OnMessage' - outputMessageFunction = new OutputMessageFunction(OnMessage); - // Set the callback - FreeImage.SetOutputMessage(outputMessageFunction); - } - - /// - /// Internal callback - /// - private static void OnMessage(FREE_IMAGE_FORMAT fif, string message) - { - // Get a local copy of the multicast-delegate - OutputMessageFunction m = Message; - - // Check the local copy instead of the static instance - // to prevent a second thread from setting the delegate - // to null, which would cause a nullreference exception - if (m != null) - { - // Invoke the multicast-delegate - m.Invoke(fif, message); - } - } - - /// - /// Gets a value indicating if the FreeImage DLL is available or not. - /// - public static bool IsAvailable - { - get - { - return FreeImage.IsAvailable(); - } - } - - /// - /// Internal errors in FreeImage generate a logstring that can be - /// captured by this event. - /// - public static event OutputMessageFunction Message; - - #endregion - - /// - /// Gets a string containing the current version of the library. - /// - public static string Version - { - get - { - return FreeImage.GetVersion(); - } - } - - /// - /// Gets a string containing a standard copyright message. - /// - public static string CopyrightMessage - { - get - { - return FreeImage.GetCopyrightMessage(); - } - } - - /// - /// Gets whether the platform is using Little Endian. - /// - public static bool IsLittleEndian - { - get - { - return FreeImage.IsLittleEndian(); - } - } - } +using System; +using System.Runtime.InteropServices; +using System.Diagnostics; + +namespace FreeImageAPI +{ + /// + /// Class handling non-bitmap related functions. + /// + public static class FreeImageEngine + { + #region Callback + + // Callback delegate + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private static readonly OutputMessageFunction outputMessageFunction; + + static FreeImageEngine() + { + // Check if FreeImage.dll is present and cancel setting the callbackfuntion if not + if (!IsAvailable) + { + return; + } + // Create a delegate (function pointer) to 'OnMessage' + outputMessageFunction = new OutputMessageFunction(OnMessage); + // Set the callback + FreeImage.SetOutputMessage(outputMessageFunction); + } + + /// + /// Internal callback + /// + private static void OnMessage(FREE_IMAGE_FORMAT fif, string message) + { + // Get a local copy of the multicast-delegate + OutputMessageFunction m = Message; + + // Check the local copy instead of the static instance + // to prevent a second thread from setting the delegate + // to null, which would cause a nullreference exception + if (m != null) + { + // Invoke the multicast-delegate + m.Invoke(fif, message); + } + } + + /// + /// Gets a value indicating if the FreeImage DLL is available or not. + /// + public static bool IsAvailable + { + get + { + return FreeImage.IsAvailable(); + } + } + + /// + /// Internal errors in FreeImage generate a logstring that can be + /// captured by this event. + /// + public static event OutputMessageFunction Message; + + #endregion + + /// + /// Gets a string containing the current version of the library. + /// + public static string Version + { + get + { + return FreeImage.GetVersion(); + } + } + + /// + /// Gets a string containing a standard copyright message. + /// + public static string CopyrightMessage + { + get + { + return FreeImage.GetCopyrightMessage(); + } + } + + /// + /// Gets whether the platform is using Little Endian. + /// + public static bool IsLittleEndian + { + get + { + return FreeImage.IsLittleEndian(); + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImagePlugin.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImagePlugin.cs index 399d492..3f02f60 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImagePlugin.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImagePlugin.cs @@ -1,202 +1,202 @@ -using System; -using System.Diagnostics; - -namespace FreeImageAPI.Plugins -{ - /// - /// Class representing a FreeImage format. - /// - public sealed class FreeImagePlugin - { - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private readonly FREE_IMAGE_FORMAT fif; - - /// - /// Initializes a new instance of this class. - /// - /// The FreeImage format to wrap. - internal FreeImagePlugin(FREE_IMAGE_FORMAT fif) - { - this.fif = fif; - } - - /// - /// Gets the format of this instance. - /// - public FREE_IMAGE_FORMAT FIFormat - { - get - { - return fif; - } - } - - /// - /// Gets or sets whether this plugin is enabled. - /// - public bool Enabled - { - get - { - return (FreeImage.IsPluginEnabled(fif) == 1); - } - set - { - FreeImage.SetPluginEnabled(fif, value); - } - } - - /// - /// Gets a string describing the format. - /// - public string Format - { - get - { - return FreeImage.GetFormatFromFIF(fif); - } - } - - /// - /// Gets a comma-delimited file extension list describing the bitmap formats - /// this plugin can read and/or write. - /// - public string ExtentsionList - { - get - { - return FreeImage.GetFIFExtensionList(fif); - } - } - - /// - /// Gets a descriptive string that describes the bitmap formats - /// this plugin can read and/or write. - /// - public string Description - { - get - { - return FreeImage.GetFIFDescription(fif); - } - } - - /// - /// Returns a regular expression string that can be used by - /// a regular expression engine to identify the bitmap. - /// FreeImageQt makes use of this function. - /// - public string RegExpr - { - get - { - return FreeImage.GetFIFRegExpr(fif); - } - } - - /// - /// Gets whether this plugin can load bitmaps. - /// - public bool SupportsReading - { - get - { - return FreeImage.FIFSupportsReading(fif); - } - } - - /// - /// Gets whether this plugin can save bitmaps. - /// - public bool SupportsWriting - { - get - { - return FreeImage.FIFSupportsWriting(fif); - } - } - - /// - /// Checks whether this plugin can save a bitmap in the desired data type. - /// - /// The desired image type. - /// True if this plugin can save bitmaps as the desired type, else false. - public bool SupportsExportType(FREE_IMAGE_TYPE type) - { - return FreeImage.FIFSupportsExportType(fif, type); - } - - /// - /// Checks whether this plugin can save bitmaps in the desired bit depth. - /// - /// The desired bit depth. - /// True if this plugin can save bitmaps in the desired bit depth, else false. - public bool SupportsExportBPP(int bpp) - { - return FreeImage.FIFSupportsExportBPP(fif, bpp); - } - - /// - /// Gets whether this plugin can load or save an ICC profile. - /// - public bool SupportsICCProfiles - { - get - { - return FreeImage.FIFSupportsICCProfiles(fif); - } - } - - /// - /// Checks whether an extension is valid for this format. - /// - /// The desired extension. - /// True if the extension is valid for this format, false otherwise. - public bool ValidExtension(string extension) - { - return FreeImage.IsExtensionValidForFIF(fif, extension); - } - - /// - /// Checks whether an extension is valid for this format. - /// - /// The desired extension. - /// The string comparison type. - /// True if the extension is valid for this format, false otherwise. - public bool ValidExtension(string extension, StringComparison comparisonType) - { - return FreeImage.IsExtensionValidForFIF(fif, extension, comparisonType); - } - - /// - /// Checks whether a filename is valid for this format. - /// - /// The desired filename. - /// True if the filename is valid for this format, false otherwise. - public bool ValidFilename(string filename) - { - return FreeImage.IsFilenameValidForFIF(fif, filename); - } - - /// - /// Checks whether a filename is valid for this format. - /// - /// The desired filename. - /// The string comparison type. - /// True if the filename is valid for this format, false otherwise. - public bool ValidFilename(string filename, StringComparison comparisonType) - { - return FreeImage.IsFilenameValidForFIF(fif, filename, comparisonType); - } - - /// - /// Gets a descriptive string that describes the bitmap formats - /// this plugin can read and/or write. - /// - /// A descriptive string that describes the bitmap formats. - public override string ToString() - { - return Description; - } - } -} +using System; +using System.Diagnostics; + +namespace FreeImageAPI.Plugins +{ + /// + /// Class representing a FreeImage format. + /// + public sealed class FreeImagePlugin + { + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private readonly FREE_IMAGE_FORMAT fif; + + /// + /// Initializes a new instance of this class. + /// + /// The FreeImage format to wrap. + internal FreeImagePlugin(FREE_IMAGE_FORMAT fif) + { + this.fif = fif; + } + + /// + /// Gets the format of this instance. + /// + public FREE_IMAGE_FORMAT FIFormat + { + get + { + return fif; + } + } + + /// + /// Gets or sets whether this plugin is enabled. + /// + public bool Enabled + { + get + { + return (FreeImage.IsPluginEnabled(fif) == 1); + } + set + { + FreeImage.SetPluginEnabled(fif, value); + } + } + + /// + /// Gets a string describing the format. + /// + public string Format + { + get + { + return FreeImage.GetFormatFromFIF(fif); + } + } + + /// + /// Gets a comma-delimited file extension list describing the bitmap formats + /// this plugin can read and/or write. + /// + public string ExtentsionList + { + get + { + return FreeImage.GetFIFExtensionList(fif); + } + } + + /// + /// Gets a descriptive string that describes the bitmap formats + /// this plugin can read and/or write. + /// + public string Description + { + get + { + return FreeImage.GetFIFDescription(fif); + } + } + + /// + /// Returns a regular expression string that can be used by + /// a regular expression engine to identify the bitmap. + /// FreeImageQt makes use of this function. + /// + public string RegExpr + { + get + { + return FreeImage.GetFIFRegExpr(fif); + } + } + + /// + /// Gets whether this plugin can load bitmaps. + /// + public bool SupportsReading + { + get + { + return FreeImage.FIFSupportsReading(fif); + } + } + + /// + /// Gets whether this plugin can save bitmaps. + /// + public bool SupportsWriting + { + get + { + return FreeImage.FIFSupportsWriting(fif); + } + } + + /// + /// Checks whether this plugin can save a bitmap in the desired data type. + /// + /// The desired image type. + /// True if this plugin can save bitmaps as the desired type, else false. + public bool SupportsExportType(FREE_IMAGE_TYPE type) + { + return FreeImage.FIFSupportsExportType(fif, type); + } + + /// + /// Checks whether this plugin can save bitmaps in the desired bit depth. + /// + /// The desired bit depth. + /// True if this plugin can save bitmaps in the desired bit depth, else false. + public bool SupportsExportBPP(int bpp) + { + return FreeImage.FIFSupportsExportBPP(fif, bpp); + } + + /// + /// Gets whether this plugin can load or save an ICC profile. + /// + public bool SupportsICCProfiles + { + get + { + return FreeImage.FIFSupportsICCProfiles(fif); + } + } + + /// + /// Checks whether an extension is valid for this format. + /// + /// The desired extension. + /// True if the extension is valid for this format, false otherwise. + public bool ValidExtension(string extension) + { + return FreeImage.IsExtensionValidForFIF(fif, extension); + } + + /// + /// Checks whether an extension is valid for this format. + /// + /// The desired extension. + /// The string comparison type. + /// True if the extension is valid for this format, false otherwise. + public bool ValidExtension(string extension, StringComparison comparisonType) + { + return FreeImage.IsExtensionValidForFIF(fif, extension, comparisonType); + } + + /// + /// Checks whether a filename is valid for this format. + /// + /// The desired filename. + /// True if the filename is valid for this format, false otherwise. + public bool ValidFilename(string filename) + { + return FreeImage.IsFilenameValidForFIF(fif, filename); + } + + /// + /// Checks whether a filename is valid for this format. + /// + /// The desired filename. + /// The string comparison type. + /// True if the filename is valid for this format, false otherwise. + public bool ValidFilename(string filename, StringComparison comparisonType) + { + return FreeImage.IsFilenameValidForFIF(fif, filename, comparisonType); + } + + /// + /// Gets a descriptive string that describes the bitmap formats + /// this plugin can read and/or write. + /// + /// A descriptive string that describes the bitmap formats. + public override string ToString() + { + return Description; + } + } +} diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImageStreamIO.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImageStreamIO.cs index fa0bfc7..2ef0087 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImageStreamIO.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/FreeImageStreamIO.cs @@ -1,167 +1,167 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.5 $ -// $Date: 2009/09/15 11:47:46 $ -// $Id: FreeImageStreamIO.cs,v 1.5 2009/09/15 11:47:46 cklein05 Exp $ -// ========================================================== - -using System; -using System.IO; -using System.Runtime.InteropServices; -using System.Diagnostics; - -namespace FreeImageAPI.IO -{ - /// - /// Internal class wrapping stream io functions. - /// - /// - /// FreeImage can read files from a disk or a network drive but also allows the user to - /// implement their own loading or saving functions to load them directly from an ftp or web - /// server for example. - /// - /// In .NET streams are a common way to handle data. The FreeImageStreamIO class handles - /// the loading and saving from and to streams. It implements the funtions FreeImage needs - /// to load data from an an arbitrary source. - /// - /// The class is for internal use only. - /// - internal static class FreeImageStreamIO - { - /// - /// structure that can be used to read from streams via - /// . - /// - public static readonly FreeImageIO io; - - /// - /// Initializes a new instances which can be used to - /// create a FreeImage compatible structure. - /// - static FreeImageStreamIO() - { - io.readProc = new ReadProc(streamRead); - io.writeProc = new WriteProc(streamWrite); - io.seekProc = new SeekProc(streamSeek); - io.tellProc = new TellProc(streamTell); - } - - /// - /// Reads the requested data from the stream and writes it to the given address. - /// - static unsafe uint streamRead(IntPtr buffer, uint size, uint count, fi_handle handle) - { - Stream stream = handle.GetObject() as Stream; - if ((stream == null) || (!stream.CanRead)) - { - return 0; - } - uint readCount = 0; - byte* ptr = (byte*)buffer; - byte[] bufferTemp = new byte[size]; - int read; - while (readCount < count) - { - read = stream.Read(bufferTemp, 0, (int)size); - if (read != (int)size) - { - stream.Seek(-read, SeekOrigin.Current); - break; - } - for (int i = 0; i < read; i++, ptr++) - { - *ptr = bufferTemp[i]; - } - readCount++; - } - return (uint)readCount; - } - - /// - /// Reads the given data and writes it into the stream. - /// - static unsafe uint streamWrite(IntPtr buffer, uint size, uint count, fi_handle handle) - { - Stream stream = handle.GetObject() as Stream; - if ((stream == null) || (!stream.CanWrite)) - { - return 0; - } - uint writeCount = 0; - byte[] bufferTemp = new byte[size]; - byte* ptr = (byte*)buffer; - while (writeCount < count) - { - for (int i = 0; i < size; i++, ptr++) - { - bufferTemp[i] = *ptr; - } - try - { - stream.Write(bufferTemp, 0, bufferTemp.Length); - } - catch - { - return writeCount; - } - writeCount++; - } - return writeCount; - } - - /// - /// Moves the streams position. - /// - static int streamSeek(fi_handle handle, int offset, SeekOrigin origin) - { - Stream stream = handle.GetObject() as Stream; - if (stream == null) - { - return 1; - } - stream.Seek((long)offset, origin); - return 0; - } - - /// - /// Returns the streams current position - /// - static int streamTell(fi_handle handle) - { - Stream stream = handle.GetObject() as Stream; - if (stream == null) - { - return -1; - } - return (int)stream.Position; - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.5 $ +// $Date: 2009/09/15 11:47:46 $ +// $Id: FreeImageStreamIO.cs,v 1.5 2009/09/15 11:47:46 cklein05 Exp $ +// ========================================================== + +using System; +using System.IO; +using System.Runtime.InteropServices; +using System.Diagnostics; + +namespace FreeImageAPI.IO +{ + /// + /// Internal class wrapping stream io functions. + /// + /// + /// FreeImage can read files from a disk or a network drive but also allows the user to + /// implement their own loading or saving functions to load them directly from an ftp or web + /// server for example. + /// + /// In .NET streams are a common way to handle data. The FreeImageStreamIO class handles + /// the loading and saving from and to streams. It implements the funtions FreeImage needs + /// to load data from an an arbitrary source. + /// + /// The class is for internal use only. + /// + internal static class FreeImageStreamIO + { + /// + /// structure that can be used to read from streams via + /// . + /// + public static readonly FreeImageIO io; + + /// + /// Initializes a new instances which can be used to + /// create a FreeImage compatible structure. + /// + static FreeImageStreamIO() + { + io.readProc = new ReadProc(streamRead); + io.writeProc = new WriteProc(streamWrite); + io.seekProc = new SeekProc(streamSeek); + io.tellProc = new TellProc(streamTell); + } + + /// + /// Reads the requested data from the stream and writes it to the given address. + /// + static unsafe uint streamRead(IntPtr buffer, uint size, uint count, fi_handle handle) + { + Stream stream = handle.GetObject() as Stream; + if ((stream == null) || (!stream.CanRead)) + { + return 0; + } + uint readCount = 0; + byte* ptr = (byte*)buffer; + byte[] bufferTemp = new byte[size]; + int read; + while (readCount < count) + { + read = stream.Read(bufferTemp, 0, (int)size); + if (read != (int)size) + { + stream.Seek(-read, SeekOrigin.Current); + break; + } + for (int i = 0; i < read; i++, ptr++) + { + *ptr = bufferTemp[i]; + } + readCount++; + } + return (uint)readCount; + } + + /// + /// Reads the given data and writes it into the stream. + /// + static unsafe uint streamWrite(IntPtr buffer, uint size, uint count, fi_handle handle) + { + Stream stream = handle.GetObject() as Stream; + if ((stream == null) || (!stream.CanWrite)) + { + return 0; + } + uint writeCount = 0; + byte[] bufferTemp = new byte[size]; + byte* ptr = (byte*)buffer; + while (writeCount < count) + { + for (int i = 0; i < size; i++, ptr++) + { + bufferTemp[i] = *ptr; + } + try + { + stream.Write(bufferTemp, 0, bufferTemp.Length); + } + catch + { + return writeCount; + } + writeCount++; + } + return writeCount; + } + + /// + /// Moves the streams position. + /// + static int streamSeek(fi_handle handle, int offset, SeekOrigin origin) + { + Stream stream = handle.GetObject() as Stream; + if (stream == null) + { + return 1; + } + stream.Seek((long)offset, origin); + return 0; + } + + /// + /// Returns the streams current position + /// + static int streamTell(fi_handle handle) + { + Stream stream = handle.GetObject() as Stream; + if (stream == null) + { + return -1; + } + return (int)stream.Position; + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/GifInformation.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/GifInformation.cs index 75af8ad..a2deb13 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/GifInformation.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/GifInformation.cs @@ -1,131 +1,131 @@ -using System; -using System.Diagnostics; -using System.Drawing; - -namespace FreeImageAPI.Metadata -{ - /// - /// Provides additional information specific for GIF files. This class cannot be inherited. - /// - public class GifInformation : MDM_ANIMATION - { - /// - /// Initializes a new instance of the class - /// with the specified . - /// - /// A reference to a instance. - public GifInformation(FreeImageBitmap bitmap) - : base(bitmap.Dib) - { - } - - /// - /// Gets or sets a value indicating whether this frame uses the - /// GIF image's global palette. If set to false, this - /// frame uses its local palette. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public bool? UseGlobalPalette - { - get - { - byte? useGlobalPalette = GetTagValue("NoLocalPalette"); - return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?); - } - set - { - byte? val = null; - if (value.HasValue) - { - val = (byte)(value.Value ? 1 : 0); - } - SetTagValue("NoLocalPalette", val); - } - } - - /// - /// Creates a global palette for the GIF image, intialized with all entries of the - /// current local palette. - /// The property will be set to true when - /// invoking this method. This effectively enables the newly created global palette. - /// - /// - /// The image does not have a palette. - /// - public void CreateGlobalPalette() - { - CreateGlobalPalette(new Palette(dib)); - } - - /// - /// Creates a global palette for the GIF image with the specified size, intialized - /// with the first entries of the current local palette. - /// The property will be set to true when - /// invoking this method. This effectively enables the newly created global palette. - /// - /// The size of the newly created global palette. - /// - /// is a null reference. - public void CreateGlobalPalette(int size) - { - CreateGlobalPalette(new Palette(dib), size); - } - - /// - /// Creates a global palette for the GIF image, intialized with the entries - /// of the specified palette. - /// The property will be set to true when - /// invoking this method. This effectively enables the newly created global palette. - /// - /// The palette that contains the initial values for - /// the newly created global palette. - /// - /// is a null reference. - public void CreateGlobalPalette(Palette palette) - { - if (palette == null) - { - throw new ArgumentNullException("palette"); - } - - GlobalPalette = palette; - UseGlobalPalette = true; - } - - /// - /// Creates a global palette for the GIF image with the specified size, intialized - /// with the first entries of the specified palette. - /// The property will be set to true when - /// invoking this method. This effectively enables the newly created global palette. - /// - /// The palette that contains the initial values for - /// the newly created global palette. - /// The size of the newly created global palette. - /// - /// is a null reference. - public void CreateGlobalPalette(Palette palette, int size) - { - if (palette == null) - { - throw new ArgumentNullException("palette"); - } - if (size <= 0) - { - throw new ArgumentOutOfRangeException("size"); - } - - Palette pal = new Palette(size); - pal.CopyFrom(palette); - GlobalPalette = palette; - UseGlobalPalette = true; - } - } +using System; +using System.Diagnostics; +using System.Drawing; + +namespace FreeImageAPI.Metadata +{ + /// + /// Provides additional information specific for GIF files. This class cannot be inherited. + /// + public class GifInformation : MDM_ANIMATION + { + /// + /// Initializes a new instance of the class + /// with the specified . + /// + /// A reference to a instance. + public GifInformation(FreeImageBitmap bitmap) + : base(bitmap.Dib) + { + } + + /// + /// Gets or sets a value indicating whether this frame uses the + /// GIF image's global palette. If set to false, this + /// frame uses its local palette. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public bool? UseGlobalPalette + { + get + { + byte? useGlobalPalette = GetTagValue("NoLocalPalette"); + return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?); + } + set + { + byte? val = null; + if (value.HasValue) + { + val = (byte)(value.Value ? 1 : 0); + } + SetTagValue("NoLocalPalette", val); + } + } + + /// + /// Creates a global palette for the GIF image, intialized with all entries of the + /// current local palette. + /// The property will be set to true when + /// invoking this method. This effectively enables the newly created global palette. + /// + /// + /// The image does not have a palette. + /// + public void CreateGlobalPalette() + { + CreateGlobalPalette(new Palette(dib)); + } + + /// + /// Creates a global palette for the GIF image with the specified size, intialized + /// with the first entries of the current local palette. + /// The property will be set to true when + /// invoking this method. This effectively enables the newly created global palette. + /// + /// The size of the newly created global palette. + /// + /// is a null reference. + public void CreateGlobalPalette(int size) + { + CreateGlobalPalette(new Palette(dib), size); + } + + /// + /// Creates a global palette for the GIF image, intialized with the entries + /// of the specified palette. + /// The property will be set to true when + /// invoking this method. This effectively enables the newly created global palette. + /// + /// The palette that contains the initial values for + /// the newly created global palette. + /// + /// is a null reference. + public void CreateGlobalPalette(Palette palette) + { + if (palette == null) + { + throw new ArgumentNullException("palette"); + } + + GlobalPalette = palette; + UseGlobalPalette = true; + } + + /// + /// Creates a global palette for the GIF image with the specified size, intialized + /// with the first entries of the specified palette. + /// The property will be set to true when + /// invoking this method. This effectively enables the newly created global palette. + /// + /// The palette that contains the initial values for + /// the newly created global palette. + /// The size of the newly created global palette. + /// + /// is a null reference. + public void CreateGlobalPalette(Palette palette, int size) + { + if (palette == null) + { + throw new ArgumentNullException("palette"); + } + if (size <= 0) + { + throw new ArgumentOutOfRangeException("size"); + } + + Palette pal = new Palette(size); + pal.CopyFrom(palette); + GlobalPalette = palette; + UseGlobalPalette = true; + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/ImageMetadata.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/ImageMetadata.cs index d0bb44b..e49f7e4 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/ImageMetadata.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/ImageMetadata.cs @@ -1,286 +1,286 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.7 $ -// $Date: 2009/02/27 16:34:59 $ -// $Id: ImageMetadata.cs,v 1.7 2009/02/27 16:34:59 cklein05 Exp $ -// ========================================================== - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; -using System.Diagnostics; - -namespace FreeImageAPI.Metadata -{ - /// - /// Class handling metadata of a FreeImage bitmap. - /// - public class ImageMetadata : IEnumerable, IComparable, IComparable - { - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private readonly List data; - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private readonly FIBITMAP dib; - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool hideEmptyModels; - - /// - /// Initializes a new instance based on the specified , - /// showing all known models. - /// - /// Handle to a FreeImage bitmap. - public ImageMetadata(FIBITMAP dib) : this(dib, false) { } - - /// - /// Initializes a new instance based on the specified , - /// showing or hiding empry models. - /// - /// Handle to a FreeImage bitmap. - /// When true, empty metadata models - /// will be hidden until a tag to this model is added. - public ImageMetadata(FIBITMAP dib, bool hideEmptyModels) - { - if (dib.IsNull) throw new ArgumentNullException("dib"); - data = new List(FreeImage.FREE_IMAGE_MDMODELS.Length); - this.dib = dib; - this.hideEmptyModels = hideEmptyModels; - - data.Add(new MDM_ANIMATION(dib)); - data.Add(new MDM_COMMENTS(dib)); - data.Add(new MDM_CUSTOM(dib)); - data.Add(new MDM_EXIF_EXIF(dib)); - data.Add(new MDM_EXIF_GPS(dib)); - data.Add(new MDM_INTEROP(dib)); - data.Add(new MDM_EXIF_MAIN(dib)); - data.Add(new MDM_MAKERNOTE(dib)); - data.Add(new MDM_GEOTIFF(dib)); - data.Add(new MDM_IPTC(dib)); - data.Add(new MDM_NODATA(dib)); - data.Add(new MDM_XMP(dib)); - } - - /// - /// Gets or sets the of the specified type. - /// In case the getter returns null the model is not contained - /// by the list. - /// null can be used calling the setter to destroy the model. - /// - /// Type of the model. - /// The object of the specified type. - public MetadataModel this[FREE_IMAGE_MDMODEL model] - { - get - { - for (int i = 0; i < data.Count; i++) - { - if (data[i].Model == model) - { - if (!data[i].Exists && hideEmptyModels) - { - return null; - } - return data[i]; - } - } - return null; - } - } - - /// - /// Gets or sets the at the specified index. - /// In case the getter returns null the model is not contained - /// by the list. - /// null can be used calling the setter to destroy the model. - /// - /// Index of the within - /// this instance. - /// The - /// object at the specified index. - public MetadataModel this[int index] - { - get - { - if (index < 0 || index >= data.Count) - { - throw new ArgumentOutOfRangeException("index"); - } - return (hideEmptyModels && !data[index].Exists) ? null : data[index]; - } - } - - /// - /// Returns a list of all visible - /// MetadataModels. - /// - public List List - { - get - { - if (hideEmptyModels) - { - List result = new List(); - for (int i = 0; i < data.Count; i++) - { - if (data[i].Exists) - { - result.Add(data[i]); - } - } - return result; - } - else - { - return data; - } - } - } - - /// - /// Adds new tag to the bitmap or updates its value in case it already exists. - /// will be used as key. - /// - /// The tag to add or update. - /// Returns true on success, false on failure. - /// - /// is null. - public bool AddTag(MetadataTag tag) - { - for (int i = 0; i < data.Count; i++) - { - if (tag.Model == data[i].Model) - { - return data[i].AddTag(tag); - } - } - return false; - } - - /// - /// Returns the number of visible - /// MetadataModels. - /// - public int Count - { - get - { - if (hideEmptyModels) - { - int count = 0; - for (int i = 0; i < data.Count; i++) - { - if (data[i].Exists) - { - count++; - } - } - return count; - } - else - { - return data.Count; - } - } - } - - /// - /// Gets or sets whether empty - /// MetadataModels are hidden. - /// - public bool HideEmptyModels - { - get - { - return hideEmptyModels; - } - set - { - hideEmptyModels = value; - } - } - - /// - /// Retrieves an object that can iterate through the individual - /// MetadataModels - /// in this . - /// - /// An for this . - public IEnumerator GetEnumerator() - { - if (hideEmptyModels) - { - List tempList = new List(data.Count); - for (int i = 0; i < data.Count; i++) - { - if (data[i].Exists) - { - tempList.Add(data[i]); - } - } - return tempList.GetEnumerator(); - } - else - { - return data.GetEnumerator(); - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is ImageMetadata)) - { - throw new ArgumentException("obj"); - } - return CompareTo((ImageMetadata)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(ImageMetadata other) - { - return this.dib.CompareTo(other.dib); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.7 $ +// $Date: 2009/02/27 16:34:59 $ +// $Id: ImageMetadata.cs,v 1.7 2009/02/27 16:34:59 cklein05 Exp $ +// ========================================================== + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using System.Diagnostics; + +namespace FreeImageAPI.Metadata +{ + /// + /// Class handling metadata of a FreeImage bitmap. + /// + public class ImageMetadata : IEnumerable, IComparable, IComparable + { + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private readonly List data; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private readonly FIBITMAP dib; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool hideEmptyModels; + + /// + /// Initializes a new instance based on the specified , + /// showing all known models. + /// + /// Handle to a FreeImage bitmap. + public ImageMetadata(FIBITMAP dib) : this(dib, false) { } + + /// + /// Initializes a new instance based on the specified , + /// showing or hiding empry models. + /// + /// Handle to a FreeImage bitmap. + /// When true, empty metadata models + /// will be hidden until a tag to this model is added. + public ImageMetadata(FIBITMAP dib, bool hideEmptyModels) + { + if (dib.IsNull) throw new ArgumentNullException("dib"); + data = new List(FreeImage.FREE_IMAGE_MDMODELS.Length); + this.dib = dib; + this.hideEmptyModels = hideEmptyModels; + + data.Add(new MDM_ANIMATION(dib)); + data.Add(new MDM_COMMENTS(dib)); + data.Add(new MDM_CUSTOM(dib)); + data.Add(new MDM_EXIF_EXIF(dib)); + data.Add(new MDM_EXIF_GPS(dib)); + data.Add(new MDM_INTEROP(dib)); + data.Add(new MDM_EXIF_MAIN(dib)); + data.Add(new MDM_MAKERNOTE(dib)); + data.Add(new MDM_GEOTIFF(dib)); + data.Add(new MDM_IPTC(dib)); + data.Add(new MDM_NODATA(dib)); + data.Add(new MDM_XMP(dib)); + } + + /// + /// Gets or sets the of the specified type. + /// In case the getter returns null the model is not contained + /// by the list. + /// null can be used calling the setter to destroy the model. + /// + /// Type of the model. + /// The object of the specified type. + public MetadataModel this[FREE_IMAGE_MDMODEL model] + { + get + { + for (int i = 0; i < data.Count; i++) + { + if (data[i].Model == model) + { + if (!data[i].Exists && hideEmptyModels) + { + return null; + } + return data[i]; + } + } + return null; + } + } + + /// + /// Gets or sets the at the specified index. + /// In case the getter returns null the model is not contained + /// by the list. + /// null can be used calling the setter to destroy the model. + /// + /// Index of the within + /// this instance. + /// The + /// object at the specified index. + public MetadataModel this[int index] + { + get + { + if (index < 0 || index >= data.Count) + { + throw new ArgumentOutOfRangeException("index"); + } + return (hideEmptyModels && !data[index].Exists) ? null : data[index]; + } + } + + /// + /// Returns a list of all visible + /// MetadataModels. + /// + public List List + { + get + { + if (hideEmptyModels) + { + List result = new List(); + for (int i = 0; i < data.Count; i++) + { + if (data[i].Exists) + { + result.Add(data[i]); + } + } + return result; + } + else + { + return data; + } + } + } + + /// + /// Adds new tag to the bitmap or updates its value in case it already exists. + /// will be used as key. + /// + /// The tag to add or update. + /// Returns true on success, false on failure. + /// + /// is null. + public bool AddTag(MetadataTag tag) + { + for (int i = 0; i < data.Count; i++) + { + if (tag.Model == data[i].Model) + { + return data[i].AddTag(tag); + } + } + return false; + } + + /// + /// Returns the number of visible + /// MetadataModels. + /// + public int Count + { + get + { + if (hideEmptyModels) + { + int count = 0; + for (int i = 0; i < data.Count; i++) + { + if (data[i].Exists) + { + count++; + } + } + return count; + } + else + { + return data.Count; + } + } + } + + /// + /// Gets or sets whether empty + /// MetadataModels are hidden. + /// + public bool HideEmptyModels + { + get + { + return hideEmptyModels; + } + set + { + hideEmptyModels = value; + } + } + + /// + /// Retrieves an object that can iterate through the individual + /// MetadataModels + /// in this . + /// + /// An for this . + public IEnumerator GetEnumerator() + { + if (hideEmptyModels) + { + List tempList = new List(data.Count); + for (int i = 0; i < data.Count; i++) + { + if (data[i].Exists) + { + tempList.Add(data[i]); + } + } + return tempList.GetEnumerator(); + } + else + { + return data.GetEnumerator(); + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is ImageMetadata)) + { + throw new ArgumentException("obj"); + } + return CompareTo((ImageMetadata)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(ImageMetadata other) + { + return this.dib.CompareTo(other.dib); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/LocalPlugin.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/LocalPlugin.cs index 4c6bbe8..a8d9278 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/LocalPlugin.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/LocalPlugin.cs @@ -1,466 +1,466 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.9 $ -// $Date: 2009/09/15 11:47:46 $ -// $Id: LocalPlugin.cs,v 1.9 2009/09/15 11:47:46 cklein05 Exp $ -// ========================================================== - -using System; -using System.IO; -using System.Runtime.InteropServices; -using FreeImageAPI.IO; -using System.Diagnostics; - -namespace FreeImageAPI.Plugins -{ - /// - /// Class representing own FreeImage-Plugins. - /// - /// - /// FreeImages itself is plugin based. Each supported format is integrated by a seperat plugin, - /// that handles loading, saving, descriptions, identifing ect. - /// And of course the user can create own plugins and use them in FreeImage. - /// To do that the above mentioned predefined methodes need to be implemented. - /// - /// The class below handles the creation of such a plugin. The class itself is abstract - /// as well as some core functions that need to be implemented. - /// The class can be used to enable or disable the plugin in FreeImage after regististration or - /// retrieve the formatid, assigned by FreeImage. - /// The class handles the callback functions, garbage collector and pointer operation to make - /// the implementation as user friendly as possible. - /// - /// How to: - /// There are two functions that need to be implemented: - /// and - /// . - /// is used by the constructor - /// of the abstract class. FreeImage wants a list of the implemented functions. Each function is - /// represented by a function pointer (a .NET ). In case a function - /// is not implemented FreeImage receives an empty delegate). To tell the constructor - /// which functions have been implemented the information is represented by a disjunction of - /// . - /// - /// For example: - /// return MethodFlags.LoadProc | MethodFlags.SaveProc; - /// - /// The above statement means that LoadProc and SaveProc have been implemented by the user. - /// Keep in mind, that each function has a standard implementation that has static return - /// values that may cause errors if listed in - /// without a real implementation. - /// - /// is used by some checks of FreeImage and - /// must be implemented. for example can be - /// implemented if the plugin supports reading, but it doesn't have to, the plugin could only - /// be used to save an already loaded bitmap in a special format. - /// - public abstract class LocalPlugin - { - /// - /// Struct containing function pointers. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private Plugin plugin; - - /// - /// Delegate for register callback by FreeImage. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private InitProc initProc; - - /// - /// The format id assiged to the plugin. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - - /// - /// When true the plugin was registered successfully else false. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected readonly bool registered = false; - - /// - /// A copy of the functions used to register. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected readonly MethodFlags implementedMethods; - - /// - /// MethodFlags defines values to fill a bitfield telling which - /// functions have been implemented by a plugin. - /// - [Flags] - protected enum MethodFlags - { - /// - /// No mothods implemented. - /// - None = 0x0, - - /// - /// DescriptionProc has been implemented. - /// - DescriptionProc = 0x1, - - /// - /// ExtensionListProc has been implemented. - /// - ExtensionListProc = 0x2, - - /// - /// RegExprProc has been implemented. - /// - RegExprProc = 0x4, - - /// - /// OpenProc has been implemented. - /// - OpenProc = 0x8, - - /// - /// CloseProc has been implemented. - /// - CloseProc = 0x10, - - /// - /// PageCountProc has been implemented. - /// - PageCountProc = 0x20, - - /// - /// PageCapabilityProc has been implemented. - /// - PageCapabilityProc = 0x40, - - /// - /// LoadProc has been implemented. - /// - LoadProc = 0x80, - - /// - /// SaveProc has been implemented. - /// - SaveProc = 0x100, - - /// - /// ValidateProc has been implemented. - /// - ValidateProc = 0x200, - - /// - /// MimeProc has been implemented. - /// - MimeProc = 0x400, - - /// - /// SupportsExportBPPProc has been implemented. - /// - SupportsExportBPPProc = 0x800, - - /// - /// SupportsExportTypeProc has been implemented. - /// - SupportsExportTypeProc = 0x1000, - - /// - /// SupportsICCProfilesProc has been implemented. - /// - SupportsICCProfilesProc = 0x2000 - } - - // Functions that must be implemented. - - /// - /// Function that returns a bitfield containing the - /// implemented methods. - /// - /// Bitfield of the implemented methods. - protected abstract MethodFlags GetImplementedMethods(); - - /// - /// Implementation of FormatProc - /// - /// A string containing the plugins format. - protected abstract string FormatProc(); - - // Functions that can be implemented. - - /// - /// Function that can be implemented. - /// - protected virtual string DescriptionProc() { return ""; } - /// - /// Function that can be implemented. - /// - protected virtual string ExtensionListProc() { return ""; } - /// - /// Function that can be implemented. - /// - protected virtual string RegExprProc() { return ""; } - /// - /// Function that can be implemented. - /// - protected virtual IntPtr OpenProc(ref FreeImageIO io, fi_handle handle, bool read) { return IntPtr.Zero; } - /// - /// Function that can be implemented. - /// - protected virtual void CloseProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { } - /// - /// Function that can be implemented. - /// - protected virtual int PageCountProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { return 0; } - /// - /// Function that can be implemented. - /// - protected virtual int PageCapabilityProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { return 0; } - /// - /// Function that can be implemented. - /// - protected virtual FIBITMAP LoadProc(ref FreeImageIO io, fi_handle handle, int page, int flags, IntPtr data) { return FIBITMAP.Zero; } - /// - /// Function that can be implemented. - /// - protected virtual bool SaveProc(ref FreeImageIO io, FIBITMAP dib, fi_handle handle, int page, int flags, IntPtr data) { return false; } - /// - /// Function that can be implemented. - /// - protected virtual bool ValidateProc(ref FreeImageIO io, fi_handle handle) { return false; } - /// - /// Function that can be implemented. - /// - protected virtual string MimeProc() { return ""; } - /// - /// Function that can be implemented. - /// - protected virtual bool SupportsExportBPPProc(int bpp) { return false; } - /// - /// Function that can be implemented. - /// - protected virtual bool SupportsExportTypeProc(FREE_IMAGE_TYPE type) { return false; } - /// - /// Function that can be implemented. - /// - protected virtual bool SupportsICCProfilesProc() { return false; } - - /// - /// The constructor automatically registeres the plugin in FreeImage. - /// To do this it prepares a FreeImage defined structure with function pointers - /// to the implemented functions or null if not implemented. - /// Before registing the functions they are pinned in memory so the garbage collector - /// can't move them around in memory after we passed there addresses to FreeImage. - /// - public LocalPlugin() - { - implementedMethods = GetImplementedMethods(); - - if ((implementedMethods & MethodFlags.DescriptionProc) != 0) - { - plugin.descriptionProc = new DescriptionProc(DescriptionProc); - } - if ((implementedMethods & MethodFlags.ExtensionListProc) != 0) - { - plugin.extensionListProc = new ExtensionListProc(ExtensionListProc); - } - if ((implementedMethods & MethodFlags.RegExprProc) != 0) - { - plugin.regExprProc = new RegExprProc(RegExprProc); - } - if ((implementedMethods & MethodFlags.OpenProc) != 0) - { - plugin.openProc = new OpenProc(OpenProc); - } - if ((implementedMethods & MethodFlags.CloseProc) != 0) - { - plugin.closeProc = new CloseProc(CloseProc); - } - if ((implementedMethods & MethodFlags.PageCountProc) != 0) - { - plugin.pageCountProc = new PageCountProc(PageCountProc); - } - if ((implementedMethods & MethodFlags.PageCapabilityProc) != 0) - { - plugin.pageCapabilityProc = new PageCapabilityProc(PageCapabilityProc); - } - if ((implementedMethods & MethodFlags.LoadProc) != 0) - { - plugin.loadProc = new LoadProc(LoadProc); - } - if ((implementedMethods & MethodFlags.SaveProc) != 0) - { - plugin.saveProc = new SaveProc(SaveProc); - } - if ((implementedMethods & MethodFlags.ValidateProc) != 0) - { - plugin.validateProc = new ValidateProc(ValidateProc); - } - if ((implementedMethods & MethodFlags.MimeProc) != 0) - { - plugin.mimeProc = new MimeProc(MimeProc); - } - if ((implementedMethods & MethodFlags.SupportsExportBPPProc) != 0) - { - plugin.supportsExportBPPProc = new SupportsExportBPPProc(SupportsExportBPPProc); - } - if ((implementedMethods & MethodFlags.SupportsExportTypeProc) != 0) - { - plugin.supportsExportTypeProc = new SupportsExportTypeProc(SupportsExportTypeProc); - } - if ((implementedMethods & MethodFlags.SupportsICCProfilesProc) != 0) - { - plugin.supportsICCProfilesProc = new SupportsICCProfilesProc(SupportsICCProfilesProc); - } - - // FormatProc is always implemented - plugin.formatProc = new FormatProc(FormatProc); - - // InitProc is the register call back. - initProc = new InitProc(RegisterProc); - - // Register the plugin. The result will be saved and can be accessed later. - registered = FreeImage.RegisterLocalPlugin(initProc, null, null, null, null) != FREE_IMAGE_FORMAT.FIF_UNKNOWN; - if (registered) - { - PluginRepository.RegisterLocalPlugin(this); - } - } - - private void RegisterProc(ref Plugin plugin, int format_id) - { - // Copy the function pointers - plugin = this.plugin; - // Retrieve the format if assigned to this plugin by FreeImage. - format = (FREE_IMAGE_FORMAT)format_id; - } - - /// - /// Gets or sets if the plugin is enabled. - /// - public bool Enabled - { - get - { - if (registered) - { - return (FreeImage.IsPluginEnabled(format) > 0); - } - else - { - throw new ObjectDisposedException("plugin not registered"); - } - } - set - { - if (registered) - { - FreeImage.SetPluginEnabled(format, value); - } - else - { - throw new ObjectDisposedException("plugin not registered"); - } - } - } - - /// - /// Gets if the plugin was registered successfully. - /// - public bool Registered - { - get { return registered; } - } - - /// - /// Gets the FreeImage assigned to this plugin. - /// - public FREE_IMAGE_FORMAT Format - { - get - { - return format; - } - } - - /// - /// Reads from an unmanaged stream. - /// - protected unsafe int Read(FreeImageIO io, fi_handle handle, uint size, uint count, ref byte[] buffer) - { - fixed (byte* ptr = buffer) - { - return (int)io.readProc(new IntPtr(ptr), size, count, handle); - } - } - - /// - /// Reads a single byte from an unmanaged stream. - /// - protected unsafe int ReadByte(FreeImageIO io, fi_handle handle) - { - byte buffer = 0; - return (int)io.readProc(new IntPtr(&buffer), 1, 1, handle) > 0 ? buffer : -1; - } - - /// - /// Writes to an unmanaged stream. - /// - protected unsafe int Write(FreeImageIO io, fi_handle handle, uint size, uint count, ref byte[] buffer) - { - fixed (byte* ptr = buffer) - { - return (int)io.writeProc(new IntPtr(ptr), size, count, handle); - } - } - - /// - /// Writes a single byte to an unmanaged stream. - /// - protected unsafe int WriteByte(FreeImageIO io, fi_handle handle, byte value) - { - return (int)io.writeProc(new IntPtr(&value), 1, 1, handle); - } - - /// - /// Seeks in an unmanaged stream. - /// - protected int Seek(FreeImageIO io, fi_handle handle, int offset, SeekOrigin origin) - { - return io.seekProc(handle, offset, origin); - } - - /// - /// Retrieves the position of an unmanaged stream. - /// - protected int Tell(FreeImageIO io, fi_handle handle) - { - return io.tellProc(handle); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.9 $ +// $Date: 2009/09/15 11:47:46 $ +// $Id: LocalPlugin.cs,v 1.9 2009/09/15 11:47:46 cklein05 Exp $ +// ========================================================== + +using System; +using System.IO; +using System.Runtime.InteropServices; +using FreeImageAPI.IO; +using System.Diagnostics; + +namespace FreeImageAPI.Plugins +{ + /// + /// Class representing own FreeImage-Plugins. + /// + /// + /// FreeImages itself is plugin based. Each supported format is integrated by a seperat plugin, + /// that handles loading, saving, descriptions, identifing ect. + /// And of course the user can create own plugins and use them in FreeImage. + /// To do that the above mentioned predefined methodes need to be implemented. + /// + /// The class below handles the creation of such a plugin. The class itself is abstract + /// as well as some core functions that need to be implemented. + /// The class can be used to enable or disable the plugin in FreeImage after regististration or + /// retrieve the formatid, assigned by FreeImage. + /// The class handles the callback functions, garbage collector and pointer operation to make + /// the implementation as user friendly as possible. + /// + /// How to: + /// There are two functions that need to be implemented: + /// and + /// . + /// is used by the constructor + /// of the abstract class. FreeImage wants a list of the implemented functions. Each function is + /// represented by a function pointer (a .NET ). In case a function + /// is not implemented FreeImage receives an empty delegate). To tell the constructor + /// which functions have been implemented the information is represented by a disjunction of + /// . + /// + /// For example: + /// return MethodFlags.LoadProc | MethodFlags.SaveProc; + /// + /// The above statement means that LoadProc and SaveProc have been implemented by the user. + /// Keep in mind, that each function has a standard implementation that has static return + /// values that may cause errors if listed in + /// without a real implementation. + /// + /// is used by some checks of FreeImage and + /// must be implemented. for example can be + /// implemented if the plugin supports reading, but it doesn't have to, the plugin could only + /// be used to save an already loaded bitmap in a special format. + /// + public abstract class LocalPlugin + { + /// + /// Struct containing function pointers. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private Plugin plugin; + + /// + /// Delegate for register callback by FreeImage. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private InitProc initProc; + + /// + /// The format id assiged to the plugin. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + + /// + /// When true the plugin was registered successfully else false. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected readonly bool registered = false; + + /// + /// A copy of the functions used to register. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected readonly MethodFlags implementedMethods; + + /// + /// MethodFlags defines values to fill a bitfield telling which + /// functions have been implemented by a plugin. + /// + [Flags] + protected enum MethodFlags + { + /// + /// No mothods implemented. + /// + None = 0x0, + + /// + /// DescriptionProc has been implemented. + /// + DescriptionProc = 0x1, + + /// + /// ExtensionListProc has been implemented. + /// + ExtensionListProc = 0x2, + + /// + /// RegExprProc has been implemented. + /// + RegExprProc = 0x4, + + /// + /// OpenProc has been implemented. + /// + OpenProc = 0x8, + + /// + /// CloseProc has been implemented. + /// + CloseProc = 0x10, + + /// + /// PageCountProc has been implemented. + /// + PageCountProc = 0x20, + + /// + /// PageCapabilityProc has been implemented. + /// + PageCapabilityProc = 0x40, + + /// + /// LoadProc has been implemented. + /// + LoadProc = 0x80, + + /// + /// SaveProc has been implemented. + /// + SaveProc = 0x100, + + /// + /// ValidateProc has been implemented. + /// + ValidateProc = 0x200, + + /// + /// MimeProc has been implemented. + /// + MimeProc = 0x400, + + /// + /// SupportsExportBPPProc has been implemented. + /// + SupportsExportBPPProc = 0x800, + + /// + /// SupportsExportTypeProc has been implemented. + /// + SupportsExportTypeProc = 0x1000, + + /// + /// SupportsICCProfilesProc has been implemented. + /// + SupportsICCProfilesProc = 0x2000 + } + + // Functions that must be implemented. + + /// + /// Function that returns a bitfield containing the + /// implemented methods. + /// + /// Bitfield of the implemented methods. + protected abstract MethodFlags GetImplementedMethods(); + + /// + /// Implementation of FormatProc + /// + /// A string containing the plugins format. + protected abstract string FormatProc(); + + // Functions that can be implemented. + + /// + /// Function that can be implemented. + /// + protected virtual string DescriptionProc() { return ""; } + /// + /// Function that can be implemented. + /// + protected virtual string ExtensionListProc() { return ""; } + /// + /// Function that can be implemented. + /// + protected virtual string RegExprProc() { return ""; } + /// + /// Function that can be implemented. + /// + protected virtual IntPtr OpenProc(ref FreeImageIO io, fi_handle handle, bool read) { return IntPtr.Zero; } + /// + /// Function that can be implemented. + /// + protected virtual void CloseProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { } + /// + /// Function that can be implemented. + /// + protected virtual int PageCountProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { return 0; } + /// + /// Function that can be implemented. + /// + protected virtual int PageCapabilityProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { return 0; } + /// + /// Function that can be implemented. + /// + protected virtual FIBITMAP LoadProc(ref FreeImageIO io, fi_handle handle, int page, int flags, IntPtr data) { return FIBITMAP.Zero; } + /// + /// Function that can be implemented. + /// + protected virtual bool SaveProc(ref FreeImageIO io, FIBITMAP dib, fi_handle handle, int page, int flags, IntPtr data) { return false; } + /// + /// Function that can be implemented. + /// + protected virtual bool ValidateProc(ref FreeImageIO io, fi_handle handle) { return false; } + /// + /// Function that can be implemented. + /// + protected virtual string MimeProc() { return ""; } + /// + /// Function that can be implemented. + /// + protected virtual bool SupportsExportBPPProc(int bpp) { return false; } + /// + /// Function that can be implemented. + /// + protected virtual bool SupportsExportTypeProc(FREE_IMAGE_TYPE type) { return false; } + /// + /// Function that can be implemented. + /// + protected virtual bool SupportsICCProfilesProc() { return false; } + + /// + /// The constructor automatically registeres the plugin in FreeImage. + /// To do this it prepares a FreeImage defined structure with function pointers + /// to the implemented functions or null if not implemented. + /// Before registing the functions they are pinned in memory so the garbage collector + /// can't move them around in memory after we passed there addresses to FreeImage. + /// + public LocalPlugin() + { + implementedMethods = GetImplementedMethods(); + + if ((implementedMethods & MethodFlags.DescriptionProc) != 0) + { + plugin.descriptionProc = new DescriptionProc(DescriptionProc); + } + if ((implementedMethods & MethodFlags.ExtensionListProc) != 0) + { + plugin.extensionListProc = new ExtensionListProc(ExtensionListProc); + } + if ((implementedMethods & MethodFlags.RegExprProc) != 0) + { + plugin.regExprProc = new RegExprProc(RegExprProc); + } + if ((implementedMethods & MethodFlags.OpenProc) != 0) + { + plugin.openProc = new OpenProc(OpenProc); + } + if ((implementedMethods & MethodFlags.CloseProc) != 0) + { + plugin.closeProc = new CloseProc(CloseProc); + } + if ((implementedMethods & MethodFlags.PageCountProc) != 0) + { + plugin.pageCountProc = new PageCountProc(PageCountProc); + } + if ((implementedMethods & MethodFlags.PageCapabilityProc) != 0) + { + plugin.pageCapabilityProc = new PageCapabilityProc(PageCapabilityProc); + } + if ((implementedMethods & MethodFlags.LoadProc) != 0) + { + plugin.loadProc = new LoadProc(LoadProc); + } + if ((implementedMethods & MethodFlags.SaveProc) != 0) + { + plugin.saveProc = new SaveProc(SaveProc); + } + if ((implementedMethods & MethodFlags.ValidateProc) != 0) + { + plugin.validateProc = new ValidateProc(ValidateProc); + } + if ((implementedMethods & MethodFlags.MimeProc) != 0) + { + plugin.mimeProc = new MimeProc(MimeProc); + } + if ((implementedMethods & MethodFlags.SupportsExportBPPProc) != 0) + { + plugin.supportsExportBPPProc = new SupportsExportBPPProc(SupportsExportBPPProc); + } + if ((implementedMethods & MethodFlags.SupportsExportTypeProc) != 0) + { + plugin.supportsExportTypeProc = new SupportsExportTypeProc(SupportsExportTypeProc); + } + if ((implementedMethods & MethodFlags.SupportsICCProfilesProc) != 0) + { + plugin.supportsICCProfilesProc = new SupportsICCProfilesProc(SupportsICCProfilesProc); + } + + // FormatProc is always implemented + plugin.formatProc = new FormatProc(FormatProc); + + // InitProc is the register call back. + initProc = new InitProc(RegisterProc); + + // Register the plugin. The result will be saved and can be accessed later. + registered = FreeImage.RegisterLocalPlugin(initProc, null, null, null, null) != FREE_IMAGE_FORMAT.FIF_UNKNOWN; + if (registered) + { + PluginRepository.RegisterLocalPlugin(this); + } + } + + private void RegisterProc(ref Plugin plugin, int format_id) + { + // Copy the function pointers + plugin = this.plugin; + // Retrieve the format if assigned to this plugin by FreeImage. + format = (FREE_IMAGE_FORMAT)format_id; + } + + /// + /// Gets or sets if the plugin is enabled. + /// + public bool Enabled + { + get + { + if (registered) + { + return (FreeImage.IsPluginEnabled(format) > 0); + } + else + { + throw new ObjectDisposedException("plugin not registered"); + } + } + set + { + if (registered) + { + FreeImage.SetPluginEnabled(format, value); + } + else + { + throw new ObjectDisposedException("plugin not registered"); + } + } + } + + /// + /// Gets if the plugin was registered successfully. + /// + public bool Registered + { + get { return registered; } + } + + /// + /// Gets the FreeImage assigned to this plugin. + /// + public FREE_IMAGE_FORMAT Format + { + get + { + return format; + } + } + + /// + /// Reads from an unmanaged stream. + /// + protected unsafe int Read(FreeImageIO io, fi_handle handle, uint size, uint count, ref byte[] buffer) + { + fixed (byte* ptr = buffer) + { + return (int)io.readProc(new IntPtr(ptr), size, count, handle); + } + } + + /// + /// Reads a single byte from an unmanaged stream. + /// + protected unsafe int ReadByte(FreeImageIO io, fi_handle handle) + { + byte buffer = 0; + return (int)io.readProc(new IntPtr(&buffer), 1, 1, handle) > 0 ? buffer : -1; + } + + /// + /// Writes to an unmanaged stream. + /// + protected unsafe int Write(FreeImageIO io, fi_handle handle, uint size, uint count, ref byte[] buffer) + { + fixed (byte* ptr = buffer) + { + return (int)io.writeProc(new IntPtr(ptr), size, count, handle); + } + } + + /// + /// Writes a single byte to an unmanaged stream. + /// + protected unsafe int WriteByte(FreeImageIO io, fi_handle handle, byte value) + { + return (int)io.writeProc(new IntPtr(&value), 1, 1, handle); + } + + /// + /// Seeks in an unmanaged stream. + /// + protected int Seek(FreeImageIO io, fi_handle handle, int offset, SeekOrigin origin) + { + return io.seekProc(handle, offset, origin); + } + + /// + /// Retrieves the position of an unmanaged stream. + /// + protected int Tell(FreeImageIO io, fi_handle handle) + { + return io.tellProc(handle); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/MemoryArray.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/MemoryArray.cs index a1ff887..33e2c0f 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/MemoryArray.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/MemoryArray.cs @@ -1,828 +1,828 @@ -using System; -using System.Runtime.InteropServices; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; - -namespace FreeImageAPI -{ - /// - /// Represents unmanaged memory, containing an array of a given structure. - /// - /// Structuretype represented by the instance. - /// - /// and can not be marshalled. - /// - /// Use instead of and - /// instead of . - /// - public unsafe class MemoryArray : IDisposable, ICloneable, ICollection, IEnumerable, IEquatable> where T : struct - { - /// - /// Baseaddress of the wrapped memory. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected byte* baseAddress; - - /// - /// Number of elements being wrapped. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected int length; - - /// - /// Size, in bytes, of each element. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private static readonly int size; - - /// - /// Array of T containing a single element. - /// The array is used as a workaround, because there are no pointer for generic types. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected T[] buffer; - - /// - /// Pointer to the element of buffer. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected byte* ptr; - - /// - /// Handle for pinning buffer. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected GCHandle handle; - - /// - /// Indicates whether the wrapped memory is handled like a bitfield. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected readonly bool isOneBit; - - /// - /// Indicates whther the wrapped memory is handles like 4-bit blocks. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected readonly bool isFourBit; - - /// - /// An object that can be used to synchronize access to the . - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected object syncRoot = null; - - static MemoryArray() - { - T[] dummy = new T[2]; - long marshalledSize = Marshal.SizeOf(typeof(T)); - long structureSize = - Marshal.UnsafeAddrOfPinnedArrayElement(dummy, 1).ToInt64() - - Marshal.UnsafeAddrOfPinnedArrayElement(dummy, 0).ToInt64(); - if (marshalledSize != structureSize) - { - throw new NotSupportedException( - "The desired type can not be handled, " + - "because its managed and unmanaged size in bytes are different."); - } - - size = (int)marshalledSize; - } - - /// - /// Initializes a new instance. - /// - protected MemoryArray() - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Address of the memory block. - /// Length of the array. - /// - /// is null. - /// - /// is less or equal zero. - /// - /// The type is not supported. - public MemoryArray(IntPtr baseAddress, int length) - : this(baseAddress.ToPointer(), length) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Address of the memory block. - /// Length of the array. - /// - /// is null. - /// - /// is less or equal zero. - /// - /// The type is not supported. - public MemoryArray(void* baseAddress, int length) - { - if (typeof(T) == typeof(FI1BIT)) - { - isOneBit = true; - } - else if (typeof(T) == typeof(FI4BIT)) - { - isFourBit = true; - } - - if (baseAddress == null) - { - throw new ArgumentNullException("baseAddress"); - } - if (length < 1) - { - throw new ArgumentOutOfRangeException("length"); - } - - this.baseAddress = (byte*)baseAddress; - this.length = (int)length; - - if (!isOneBit && !isFourBit) - { - // Create an array containing a single element. - // Due to the fact, that it's not possible to create pointers - // of generic types, an array is used to obtain the memory - // address of an element of T. - this.buffer = new T[1]; - // The array is pinned immediately to prevent the GC from - // moving it to a different position in memory. - this.handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - // The array and its content have beed pinned, so that its address - // can be safely requested and stored for the whole lifetime - // of the instace. - this.ptr = (byte*)handle.AddrOfPinnedObject(); - } - } - - /// - /// Frees the allocated . - /// - ~MemoryArray() - { - Dispose(false); - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(MemoryArray left, MemoryArray right) - { - if (object.ReferenceEquals(left, right)) - { - return true; - } - if (object.ReferenceEquals(right, null) || - object.ReferenceEquals(left, null) || - (left.length != right.length)) - { - return false; - } - if (left.baseAddress == right.baseAddress) - { - return true; - } - return FreeImage.CompareMemory(left.baseAddress, right.baseAddress, (uint)left.length); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(MemoryArray left, MemoryArray right) - { - return (!(left == right)); - } - - /// - /// Gets the value at the specified position. - /// - /// A 32-bit integer that represents the position - /// of the array element to get. - /// The value at the specified position. - /// - /// is outside the range of valid indexes - /// for the unmanaged array. - public T GetValue(int index) - { - if ((index >= this.length) || (index < 0)) - { - throw new ArgumentOutOfRangeException("index"); - } - - return GetValueInternal(index); - } - - private T GetValueInternal(int index) - { - EnsureNotDisposed(); - if (isOneBit) - { - return (T)(object)(FI1BIT)(((baseAddress[index / 8] & ((1 << (7 - (index % 8))))) == 0) ? 0 : 1); - } - else if (isFourBit) - { - return (T)(object)(FI4BIT)(((index % 2) == 0) ? (baseAddress[index / 2] >> 4) : (baseAddress[index / 2] & 0x0F)); - } - else - { - CopyMemory(ptr, baseAddress + (index * size), size); - return buffer[0]; - } - } - - /// - /// Sets a value to the element at the specified position. - /// - /// The new value for the specified element. - /// A 32-bit integer that represents the - /// position of the array element to set. - /// - /// is outside the range of valid indexes - /// for the unmanaged array. - public void SetValue(T value, int index) - { - if ((index >= this.length) || (index < 0)) - { - throw new ArgumentOutOfRangeException("index"); - } - SetValueInternal(value, index); - } - - private void SetValueInternal(T value, int index) - { - EnsureNotDisposed(); - if (isOneBit) - { - if ((FI1BIT)(object)value != 0) - { - baseAddress[index / 8] |= (byte)(1 << (7 - (index % 8))); - } - else - { - baseAddress[index / 8] &= (byte)(~(1 << (7 - (index % 8)))); - } - } - else if (isFourBit) - { - if ((index % 2) == 0) - { - baseAddress[index / 2] = (byte)((baseAddress[index / 2] & 0x0F) | ((FI4BIT)(object)value << 4)); - } - else - { - baseAddress[index / 2] = (byte)((baseAddress[index / 2] & 0xF0) | ((FI4BIT)(object)value & 0x0F)); - } - } - else - { - buffer[0] = value; - CopyMemory(baseAddress + (index * size), ptr, size); - } - } - - /// - /// Gets the values at the specified position and length. - /// - /// A 32-bit integer that represents the position - /// of the array elements to get. - /// A 32-bit integer that represents the length - /// of the array elements to get. - /// The values at the specified position and length. - /// - /// is outside the range of valid indexes - /// for the unmanaged array or is greater than the number of elements - /// from to the end of the unmanaged array. - public T[] GetValues(int index, int length) - { - EnsureNotDisposed(); - if ((index >= this.length) || (index < 0)) - { - throw new ArgumentOutOfRangeException("index"); - } - if (((index + length) > this.length) || (length < 1)) - { - throw new ArgumentOutOfRangeException("length"); - } - - T[] data = new T[length]; - if (isOneBit || isFourBit) - { - for (int i = 0; i < length; i++) - { - data[i] = GetValueInternal(i); - } - } - else - { - GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); - byte* dst = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(data, 0); - CopyMemory(dst, baseAddress + (size * index), size * length); - handle.Free(); - } - return data; - } - - /// - /// Sets the values at the specified position. - /// - /// An array containing the new values for the specified elements. - /// A 32-bit integer that represents the position - /// of the array elements to set. - /// - /// is a null reference (Nothing in Visual Basic). - /// - /// is outside the range of valid indexes - /// for the unmanaged array or is greater than the number of elements - /// from to the end of the array. - public void SetValues(T[] values, int index) - { - EnsureNotDisposed(); - if (values == null) - { - throw new ArgumentNullException("values"); - } - if ((index >= this.length) || (index < 0)) - { - throw new ArgumentOutOfRangeException("index"); - } - if ((index + values.Length) > this.length) - { - throw new ArgumentOutOfRangeException("values.Length"); - } - - if (isOneBit || isFourBit) - { - for (int i = 0; i != values.Length; ) - { - SetValueInternal(values[i++], index++); - } - } - else - { - GCHandle handle = GCHandle.Alloc(values, GCHandleType.Pinned); - byte* src = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(values, 0); - CopyMemory(baseAddress + (index * size), src, size * length); - handle.Free(); - } - } - - /// - /// Copies the entire array to a compatible one-dimensional , - /// starting at the specified index of the target array. - /// - /// The one-dimensional that is the destination - /// of the elements copied from . - /// The must have zero-based indexing. - /// The zero-based index in - /// at which copying begins. - public void CopyTo(Array array, int index) - { - EnsureNotDisposed(); - if (!(array is T[])) - { - throw new InvalidCastException("array"); - } - try - { - CopyTo((T[])array, 0, index, length); - } - catch (ArgumentOutOfRangeException ex) - { - throw new ArgumentException(ex.Message, ex); - } - } - - /// - /// Copies a range of elements from the unmanaged array starting at the specified - /// and pastes them to - /// starting at the specified . - /// The length and the indexes are specified as 32-bit integers. - /// - /// The array that receives the data. - /// A 32-bit integer that represents the index - /// in the unmanaged array at which copying begins. - /// A 32-bit integer that represents the index in - /// the destination array at which storing begins. - /// A 32-bit integer that represents the number of elements to copy. - /// - /// is a null reference (Nothing in Visual Basic). - /// - /// is outside the range of valid indexes - /// for the unmanaged array or is greater than the number of elements - /// from to the end of the unmanaged array - /// -or- - /// is outside the range of valid indexes - /// for the array or is greater than the number of elements - /// from to the end of the array. - /// - public void CopyTo(T[] array, int sourceIndex, int destinationIndex, int length) - { - EnsureNotDisposed(); - if (array == null) - { - throw new ArgumentNullException("array"); - } - if ((sourceIndex >= this.length) || (sourceIndex < 0)) - { - throw new ArgumentOutOfRangeException("sourceIndex"); - } - if ((destinationIndex >= array.Length) || (destinationIndex < 0)) - { - throw new ArgumentOutOfRangeException("destinationIndex"); - } - if ((sourceIndex + length > this.length) || - (destinationIndex + length > array.Length) || - (length < 1)) - { - throw new ArgumentOutOfRangeException("length"); - } - - if (isOneBit || isFourBit) - { - for (int i = 0; i != length; i++) - { - array[destinationIndex++] = GetValueInternal(sourceIndex++); - } - } - else - { - GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned); - byte* dst = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(array, destinationIndex); - CopyMemory(dst, baseAddress + (size * sourceIndex), size * length); - handle.Free(); - } - } - - /// - /// Copies a range of elements from the array starting at the specified - /// and pastes them to the unmanaged array - /// starting at the specified . - /// The length and the indexes are specified as 32-bit integers. - /// - /// The array that holds the data. - /// A 32-bit integer that represents the index - /// in the array at which copying begins. - /// A 32-bit integer that represents the index in - /// the unmanaged array at which storing begins. - /// A 32-bit integer that represents the number of elements to copy. - /// - /// is a null reference (Nothing in Visual Basic). - /// - /// is outside the range of valid indexes - /// for the array or is greater than the number of elements - /// from to the end of the array - /// -or- - /// is outside the range of valid indexes - /// for the unmanaged array or is greater than the number of elements - /// from to the end of the unmanaged array. - /// - public void CopyFrom(T[] array, int sourceIndex, int destinationIndex, int length) - { - EnsureNotDisposed(); - if (array == null) - { - throw new ArgumentNullException("array"); - } - if ((destinationIndex >= this.length) || (destinationIndex < 0)) - { - throw new ArgumentOutOfRangeException("destinationIndex"); - } - if ((sourceIndex >= array.Length) || (sourceIndex < 0)) - { - throw new ArgumentOutOfRangeException("sourceIndex"); - } - if ((destinationIndex + length > this.length) || - (sourceIndex + length > array.Length) || - (length < 1)) - { - throw new ArgumentOutOfRangeException("length"); - } - - if (isOneBit || isFourBit) - { - for (int i = 0; i != length; i++) - { - SetValueInternal(array[sourceIndex++], destinationIndex++); - } - } - else - { - GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned); - byte* src = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(array, sourceIndex); - CopyMemory(baseAddress + (size * destinationIndex), src, size * length); - handle.Free(); - } - } - - /// - /// Returns the represented block of memory as an array of . - /// - /// The represented block of memory. - public byte[] ToByteArray() - { - EnsureNotDisposed(); - byte[] result; - if (isOneBit) - { - result = new byte[(length + 7) / 8]; - } - else if (isFourBit) - { - result = new byte[(length + 3) / 4]; - } - else - { - result = new byte[size * length]; - } - fixed (byte* dst = result) - { - CopyMemory(dst, baseAddress, result.Length); - } - return result; - } - - /// - /// Gets or sets the value at the specified position in the array. - /// - /// A 32-bit integer that represents the position - /// of the array element to get. - /// The value at the specified position in the array. - /// - /// is outside the range of valid indexes - /// for the unmanaged array. - public T this[int index] - { - get - { - return GetValue(index); - } - set - { - SetValue(value, index); - } - } - - /// - /// Gets or sets the values of the unmanaged array. - /// - public T[] Data - { - get - { - return GetValues(0, length); - } - set - { - if (value == null) - { - throw new ArgumentNullException("value"); - } - if (value.Length != length) - { - throw new ArgumentOutOfRangeException("value.Lengt"); - } - SetValues(value, 0); - } - } - - /// - /// Gets the length of the unmanaged array. - /// - public int Length - { - get - { - EnsureNotDisposed(); - return length; - } - } - - /// - /// Gets the base address of the represented memory block. - /// - public IntPtr BaseAddress - { - get - { - EnsureNotDisposed(); - return new IntPtr(baseAddress); - } - } - - /// - /// Creates a shallow copy of the . - /// - /// A shallow copy of the . - public object Clone() - { - EnsureNotDisposed(); - return new MemoryArray(baseAddress, length); - } - - /// - /// Gets a 32-bit integer that represents the total number of elements - /// in the . - /// - public int Count - { - get { EnsureNotDisposed(); return length; } - } - - /// - /// Gets a value indicating whether access to the - /// is synchronized (thread safe). - /// - public bool IsSynchronized - { - get { EnsureNotDisposed(); return false; } - } - - /// - /// Gets an object that can be used to synchronize access to the . - /// - public object SyncRoot - { - get - { - EnsureNotDisposed(); - if (syncRoot == null) - { - System.Threading.Interlocked.CompareExchange(ref syncRoot, new object(), null); - } - return syncRoot; - } - } - - /// - /// Retrieves an object that can iterate through the individual - /// elements in this . - /// - /// An for the . - public IEnumerator GetEnumerator() - { - EnsureNotDisposed(); - T[] values = GetValues(0, length); - for (int i = 0; i != values.Length; i++) - { - yield return values[i]; - } - } - - /// - /// Retrieves an object that can iterate through the individual - /// elements in this . - /// - /// An for the . - IEnumerator IEnumerable.GetEnumerator() - { - EnsureNotDisposed(); - T[] values = GetValues(0, length); - for (int i = 0; i != values.Length; i++) - { - yield return values[i]; - } - } - - /// - /// Releases all ressources. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Releases allocated handles associated with this instance. - /// - /// true to release managed resources. - protected virtual void Dispose(bool disposing) - { - if (baseAddress != null) - { - if (handle.IsAllocated) - handle.Free(); - baseAddress = null; - buffer = null; - length = 0; - syncRoot = null; - } - } - - /// - /// Throws an if - /// this instance is disposed. - /// - protected virtual void EnsureNotDisposed() - { - if (baseAddress == null) - throw new ObjectDisposedException("This instance is disposed."); - } - - /// - /// Tests whether the specified structure is equivalent to this - /// structure. - /// - /// The structure to test. - /// true if is a - /// instance equivalent to this structure; otherwise, - /// false. - public override bool Equals(object obj) - { - EnsureNotDisposed(); - return ((obj is MemoryArray) && Equals((MemoryArray)obj)); - } - - /// - /// Tests whether the specified structure is equivalent to this - /// structure. - /// - /// The structure to test. - /// true if is equivalent to this - /// structure; otherwise, - /// false. - public bool Equals(MemoryArray other) - { - EnsureNotDisposed(); - return ((this.baseAddress == other.baseAddress) && (this.length == other.length)); - } - - /// - /// Serves as a hash function for a particular type. - /// - /// A hash code for the current . - public override int GetHashCode() - { - EnsureNotDisposed(); - return (int)baseAddress ^ length; - } - - /// - /// Copies a block of memory from one location to another. - /// - /// Pointer to the starting address of the copy destination. - /// Pointer to the starting address of the block of memory to be copied. - /// Size of the block of memory to copy, in bytes. - protected static unsafe void CopyMemory(byte* dest, byte* src, int len) - { - if (len >= 0x10) - { - do - { - *((int*)dest) = *((int*)src); - *((int*)(dest + 4)) = *((int*)(src + 4)); - *((int*)(dest + 8)) = *((int*)(src + 8)); - *((int*)(dest + 12)) = *((int*)(src + 12)); - dest += 0x10; - src += 0x10; - } - while ((len -= 0x10) >= 0x10); - } - if (len > 0) - { - if ((len & 8) != 0) - { - *((int*)dest) = *((int*)src); - *((int*)(dest + 4)) = *((int*)(src + 4)); - dest += 8; - src += 8; - } - if ((len & 4) != 0) - { - *((int*)dest) = *((int*)src); - dest += 4; - src += 4; - } - if ((len & 2) != 0) - { - *((short*)dest) = *((short*)src); - dest += 2; - src += 2; - } - if ((len & 1) != 0) - { - *dest = *src; - } - } - } - } +using System; +using System.Runtime.InteropServices; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; + +namespace FreeImageAPI +{ + /// + /// Represents unmanaged memory, containing an array of a given structure. + /// + /// Structuretype represented by the instance. + /// + /// and can not be marshalled. + /// + /// Use instead of and + /// instead of . + /// + public unsafe class MemoryArray : IDisposable, ICloneable, ICollection, IEnumerable, IEquatable> where T : struct + { + /// + /// Baseaddress of the wrapped memory. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected byte* baseAddress; + + /// + /// Number of elements being wrapped. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected int length; + + /// + /// Size, in bytes, of each element. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private static readonly int size; + + /// + /// Array of T containing a single element. + /// The array is used as a workaround, because there are no pointer for generic types. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected T[] buffer; + + /// + /// Pointer to the element of buffer. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected byte* ptr; + + /// + /// Handle for pinning buffer. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected GCHandle handle; + + /// + /// Indicates whether the wrapped memory is handled like a bitfield. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected readonly bool isOneBit; + + /// + /// Indicates whther the wrapped memory is handles like 4-bit blocks. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected readonly bool isFourBit; + + /// + /// An object that can be used to synchronize access to the . + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected object syncRoot = null; + + static MemoryArray() + { + T[] dummy = new T[2]; + long marshalledSize = Marshal.SizeOf(typeof(T)); + long structureSize = + Marshal.UnsafeAddrOfPinnedArrayElement(dummy, 1).ToInt64() - + Marshal.UnsafeAddrOfPinnedArrayElement(dummy, 0).ToInt64(); + if (marshalledSize != structureSize) + { + throw new NotSupportedException( + "The desired type can not be handled, " + + "because its managed and unmanaged size in bytes are different."); + } + + size = (int)marshalledSize; + } + + /// + /// Initializes a new instance. + /// + protected MemoryArray() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Address of the memory block. + /// Length of the array. + /// + /// is null. + /// + /// is less or equal zero. + /// + /// The type is not supported. + public MemoryArray(IntPtr baseAddress, int length) + : this(baseAddress.ToPointer(), length) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Address of the memory block. + /// Length of the array. + /// + /// is null. + /// + /// is less or equal zero. + /// + /// The type is not supported. + public MemoryArray(void* baseAddress, int length) + { + if (typeof(T) == typeof(FI1BIT)) + { + isOneBit = true; + } + else if (typeof(T) == typeof(FI4BIT)) + { + isFourBit = true; + } + + if (baseAddress == null) + { + throw new ArgumentNullException("baseAddress"); + } + if (length < 1) + { + throw new ArgumentOutOfRangeException("length"); + } + + this.baseAddress = (byte*)baseAddress; + this.length = (int)length; + + if (!isOneBit && !isFourBit) + { + // Create an array containing a single element. + // Due to the fact, that it's not possible to create pointers + // of generic types, an array is used to obtain the memory + // address of an element of T. + this.buffer = new T[1]; + // The array is pinned immediately to prevent the GC from + // moving it to a different position in memory. + this.handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + // The array and its content have beed pinned, so that its address + // can be safely requested and stored for the whole lifetime + // of the instace. + this.ptr = (byte*)handle.AddrOfPinnedObject(); + } + } + + /// + /// Frees the allocated . + /// + ~MemoryArray() + { + Dispose(false); + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(MemoryArray left, MemoryArray right) + { + if (object.ReferenceEquals(left, right)) + { + return true; + } + if (object.ReferenceEquals(right, null) || + object.ReferenceEquals(left, null) || + (left.length != right.length)) + { + return false; + } + if (left.baseAddress == right.baseAddress) + { + return true; + } + return FreeImage.CompareMemory(left.baseAddress, right.baseAddress, (uint)left.length); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(MemoryArray left, MemoryArray right) + { + return (!(left == right)); + } + + /// + /// Gets the value at the specified position. + /// + /// A 32-bit integer that represents the position + /// of the array element to get. + /// The value at the specified position. + /// + /// is outside the range of valid indexes + /// for the unmanaged array. + public T GetValue(int index) + { + if ((index >= this.length) || (index < 0)) + { + throw new ArgumentOutOfRangeException("index"); + } + + return GetValueInternal(index); + } + + private T GetValueInternal(int index) + { + EnsureNotDisposed(); + if (isOneBit) + { + return (T)(object)(FI1BIT)(((baseAddress[index / 8] & ((1 << (7 - (index % 8))))) == 0) ? 0 : 1); + } + else if (isFourBit) + { + return (T)(object)(FI4BIT)(((index % 2) == 0) ? (baseAddress[index / 2] >> 4) : (baseAddress[index / 2] & 0x0F)); + } + else + { + CopyMemory(ptr, baseAddress + (index * size), size); + return buffer[0]; + } + } + + /// + /// Sets a value to the element at the specified position. + /// + /// The new value for the specified element. + /// A 32-bit integer that represents the + /// position of the array element to set. + /// + /// is outside the range of valid indexes + /// for the unmanaged array. + public void SetValue(T value, int index) + { + if ((index >= this.length) || (index < 0)) + { + throw new ArgumentOutOfRangeException("index"); + } + SetValueInternal(value, index); + } + + private void SetValueInternal(T value, int index) + { + EnsureNotDisposed(); + if (isOneBit) + { + if ((FI1BIT)(object)value != 0) + { + baseAddress[index / 8] |= (byte)(1 << (7 - (index % 8))); + } + else + { + baseAddress[index / 8] &= (byte)(~(1 << (7 - (index % 8)))); + } + } + else if (isFourBit) + { + if ((index % 2) == 0) + { + baseAddress[index / 2] = (byte)((baseAddress[index / 2] & 0x0F) | ((FI4BIT)(object)value << 4)); + } + else + { + baseAddress[index / 2] = (byte)((baseAddress[index / 2] & 0xF0) | ((FI4BIT)(object)value & 0x0F)); + } + } + else + { + buffer[0] = value; + CopyMemory(baseAddress + (index * size), ptr, size); + } + } + + /// + /// Gets the values at the specified position and length. + /// + /// A 32-bit integer that represents the position + /// of the array elements to get. + /// A 32-bit integer that represents the length + /// of the array elements to get. + /// The values at the specified position and length. + /// + /// is outside the range of valid indexes + /// for the unmanaged array or is greater than the number of elements + /// from to the end of the unmanaged array. + public T[] GetValues(int index, int length) + { + EnsureNotDisposed(); + if ((index >= this.length) || (index < 0)) + { + throw new ArgumentOutOfRangeException("index"); + } + if (((index + length) > this.length) || (length < 1)) + { + throw new ArgumentOutOfRangeException("length"); + } + + T[] data = new T[length]; + if (isOneBit || isFourBit) + { + for (int i = 0; i < length; i++) + { + data[i] = GetValueInternal(i); + } + } + else + { + GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); + byte* dst = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(data, 0); + CopyMemory(dst, baseAddress + (size * index), size * length); + handle.Free(); + } + return data; + } + + /// + /// Sets the values at the specified position. + /// + /// An array containing the new values for the specified elements. + /// A 32-bit integer that represents the position + /// of the array elements to set. + /// + /// is a null reference (Nothing in Visual Basic). + /// + /// is outside the range of valid indexes + /// for the unmanaged array or is greater than the number of elements + /// from to the end of the array. + public void SetValues(T[] values, int index) + { + EnsureNotDisposed(); + if (values == null) + { + throw new ArgumentNullException("values"); + } + if ((index >= this.length) || (index < 0)) + { + throw new ArgumentOutOfRangeException("index"); + } + if ((index + values.Length) > this.length) + { + throw new ArgumentOutOfRangeException("values.Length"); + } + + if (isOneBit || isFourBit) + { + for (int i = 0; i != values.Length; ) + { + SetValueInternal(values[i++], index++); + } + } + else + { + GCHandle handle = GCHandle.Alloc(values, GCHandleType.Pinned); + byte* src = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(values, 0); + CopyMemory(baseAddress + (index * size), src, size * length); + handle.Free(); + } + } + + /// + /// Copies the entire array to a compatible one-dimensional , + /// starting at the specified index of the target array. + /// + /// The one-dimensional that is the destination + /// of the elements copied from . + /// The must have zero-based indexing. + /// The zero-based index in + /// at which copying begins. + public void CopyTo(Array array, int index) + { + EnsureNotDisposed(); + if (!(array is T[])) + { + throw new InvalidCastException("array"); + } + try + { + CopyTo((T[])array, 0, index, length); + } + catch (ArgumentOutOfRangeException ex) + { + throw new ArgumentException(ex.Message, ex); + } + } + + /// + /// Copies a range of elements from the unmanaged array starting at the specified + /// and pastes them to + /// starting at the specified . + /// The length and the indexes are specified as 32-bit integers. + /// + /// The array that receives the data. + /// A 32-bit integer that represents the index + /// in the unmanaged array at which copying begins. + /// A 32-bit integer that represents the index in + /// the destination array at which storing begins. + /// A 32-bit integer that represents the number of elements to copy. + /// + /// is a null reference (Nothing in Visual Basic). + /// + /// is outside the range of valid indexes + /// for the unmanaged array or is greater than the number of elements + /// from to the end of the unmanaged array + /// -or- + /// is outside the range of valid indexes + /// for the array or is greater than the number of elements + /// from to the end of the array. + /// + public void CopyTo(T[] array, int sourceIndex, int destinationIndex, int length) + { + EnsureNotDisposed(); + if (array == null) + { + throw new ArgumentNullException("array"); + } + if ((sourceIndex >= this.length) || (sourceIndex < 0)) + { + throw new ArgumentOutOfRangeException("sourceIndex"); + } + if ((destinationIndex >= array.Length) || (destinationIndex < 0)) + { + throw new ArgumentOutOfRangeException("destinationIndex"); + } + if ((sourceIndex + length > this.length) || + (destinationIndex + length > array.Length) || + (length < 1)) + { + throw new ArgumentOutOfRangeException("length"); + } + + if (isOneBit || isFourBit) + { + for (int i = 0; i != length; i++) + { + array[destinationIndex++] = GetValueInternal(sourceIndex++); + } + } + else + { + GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned); + byte* dst = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(array, destinationIndex); + CopyMemory(dst, baseAddress + (size * sourceIndex), size * length); + handle.Free(); + } + } + + /// + /// Copies a range of elements from the array starting at the specified + /// and pastes them to the unmanaged array + /// starting at the specified . + /// The length and the indexes are specified as 32-bit integers. + /// + /// The array that holds the data. + /// A 32-bit integer that represents the index + /// in the array at which copying begins. + /// A 32-bit integer that represents the index in + /// the unmanaged array at which storing begins. + /// A 32-bit integer that represents the number of elements to copy. + /// + /// is a null reference (Nothing in Visual Basic). + /// + /// is outside the range of valid indexes + /// for the array or is greater than the number of elements + /// from to the end of the array + /// -or- + /// is outside the range of valid indexes + /// for the unmanaged array or is greater than the number of elements + /// from to the end of the unmanaged array. + /// + public void CopyFrom(T[] array, int sourceIndex, int destinationIndex, int length) + { + EnsureNotDisposed(); + if (array == null) + { + throw new ArgumentNullException("array"); + } + if ((destinationIndex >= this.length) || (destinationIndex < 0)) + { + throw new ArgumentOutOfRangeException("destinationIndex"); + } + if ((sourceIndex >= array.Length) || (sourceIndex < 0)) + { + throw new ArgumentOutOfRangeException("sourceIndex"); + } + if ((destinationIndex + length > this.length) || + (sourceIndex + length > array.Length) || + (length < 1)) + { + throw new ArgumentOutOfRangeException("length"); + } + + if (isOneBit || isFourBit) + { + for (int i = 0; i != length; i++) + { + SetValueInternal(array[sourceIndex++], destinationIndex++); + } + } + else + { + GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned); + byte* src = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(array, sourceIndex); + CopyMemory(baseAddress + (size * destinationIndex), src, size * length); + handle.Free(); + } + } + + /// + /// Returns the represented block of memory as an array of . + /// + /// The represented block of memory. + public byte[] ToByteArray() + { + EnsureNotDisposed(); + byte[] result; + if (isOneBit) + { + result = new byte[(length + 7) / 8]; + } + else if (isFourBit) + { + result = new byte[(length + 3) / 4]; + } + else + { + result = new byte[size * length]; + } + fixed (byte* dst = result) + { + CopyMemory(dst, baseAddress, result.Length); + } + return result; + } + + /// + /// Gets or sets the value at the specified position in the array. + /// + /// A 32-bit integer that represents the position + /// of the array element to get. + /// The value at the specified position in the array. + /// + /// is outside the range of valid indexes + /// for the unmanaged array. + public T this[int index] + { + get + { + return GetValue(index); + } + set + { + SetValue(value, index); + } + } + + /// + /// Gets or sets the values of the unmanaged array. + /// + public T[] Data + { + get + { + return GetValues(0, length); + } + set + { + if (value == null) + { + throw new ArgumentNullException("value"); + } + if (value.Length != length) + { + throw new ArgumentOutOfRangeException("value.Lengt"); + } + SetValues(value, 0); + } + } + + /// + /// Gets the length of the unmanaged array. + /// + public int Length + { + get + { + EnsureNotDisposed(); + return length; + } + } + + /// + /// Gets the base address of the represented memory block. + /// + public IntPtr BaseAddress + { + get + { + EnsureNotDisposed(); + return new IntPtr(baseAddress); + } + } + + /// + /// Creates a shallow copy of the . + /// + /// A shallow copy of the . + public object Clone() + { + EnsureNotDisposed(); + return new MemoryArray(baseAddress, length); + } + + /// + /// Gets a 32-bit integer that represents the total number of elements + /// in the . + /// + public int Count + { + get { EnsureNotDisposed(); return length; } + } + + /// + /// Gets a value indicating whether access to the + /// is synchronized (thread safe). + /// + public bool IsSynchronized + { + get { EnsureNotDisposed(); return false; } + } + + /// + /// Gets an object that can be used to synchronize access to the . + /// + public object SyncRoot + { + get + { + EnsureNotDisposed(); + if (syncRoot == null) + { + System.Threading.Interlocked.CompareExchange(ref syncRoot, new object(), null); + } + return syncRoot; + } + } + + /// + /// Retrieves an object that can iterate through the individual + /// elements in this . + /// + /// An for the . + public IEnumerator GetEnumerator() + { + EnsureNotDisposed(); + T[] values = GetValues(0, length); + for (int i = 0; i != values.Length; i++) + { + yield return values[i]; + } + } + + /// + /// Retrieves an object that can iterate through the individual + /// elements in this . + /// + /// An for the . + IEnumerator IEnumerable.GetEnumerator() + { + EnsureNotDisposed(); + T[] values = GetValues(0, length); + for (int i = 0; i != values.Length; i++) + { + yield return values[i]; + } + } + + /// + /// Releases all ressources. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Releases allocated handles associated with this instance. + /// + /// true to release managed resources. + protected virtual void Dispose(bool disposing) + { + if (baseAddress != null) + { + if (handle.IsAllocated) + handle.Free(); + baseAddress = null; + buffer = null; + length = 0; + syncRoot = null; + } + } + + /// + /// Throws an if + /// this instance is disposed. + /// + protected virtual void EnsureNotDisposed() + { + if (baseAddress == null) + throw new ObjectDisposedException("This instance is disposed."); + } + + /// + /// Tests whether the specified structure is equivalent to this + /// structure. + /// + /// The structure to test. + /// true if is a + /// instance equivalent to this structure; otherwise, + /// false. + public override bool Equals(object obj) + { + EnsureNotDisposed(); + return ((obj is MemoryArray) && Equals((MemoryArray)obj)); + } + + /// + /// Tests whether the specified structure is equivalent to this + /// structure. + /// + /// The structure to test. + /// true if is equivalent to this + /// structure; otherwise, + /// false. + public bool Equals(MemoryArray other) + { + EnsureNotDisposed(); + return ((this.baseAddress == other.baseAddress) && (this.length == other.length)); + } + + /// + /// Serves as a hash function for a particular type. + /// + /// A hash code for the current . + public override int GetHashCode() + { + EnsureNotDisposed(); + return (int)baseAddress ^ length; + } + + /// + /// Copies a block of memory from one location to another. + /// + /// Pointer to the starting address of the copy destination. + /// Pointer to the starting address of the block of memory to be copied. + /// Size of the block of memory to copy, in bytes. + protected static unsafe void CopyMemory(byte* dest, byte* src, int len) + { + if (len >= 0x10) + { + do + { + *((int*)dest) = *((int*)src); + *((int*)(dest + 4)) = *((int*)(src + 4)); + *((int*)(dest + 8)) = *((int*)(src + 8)); + *((int*)(dest + 12)) = *((int*)(src + 12)); + dest += 0x10; + src += 0x10; + } + while ((len -= 0x10) >= 0x10); + } + if (len > 0) + { + if ((len & 8) != 0) + { + *((int*)dest) = *((int*)src); + *((int*)(dest + 4)) = *((int*)(src + 4)); + dest += 8; + src += 8; + } + if ((len & 4) != 0) + { + *((int*)dest) = *((int*)src); + dest += 4; + src += 4; + } + if ((len & 2) != 0) + { + *((short*)dest) = *((short*)src); + dest += 2; + src += 2; + } + if ((len & 1) != 0) + { + *dest = *src; + } + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/MetadataModel.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/MetadataModel.cs index c7ad248..5857db8 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/MetadataModel.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/MetadataModel.cs @@ -1,941 +1,941 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.8 $ -// $Date: 2009/02/27 16:34:31 $ -// $Id: MetadataModel.cs,v 1.8 2009/02/27 16:34:31 cklein05 Exp $ -// ========================================================== - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Text.RegularExpressions; -using System.Diagnostics; - -namespace FreeImageAPI.Metadata -{ - /// - /// Base class that represents a collection of all tags contained in a metadata model. - /// - /// - /// The MetedataModel class is an abstract base class, which is inherited by - /// several derived classes, one for each existing metadata model. - /// - public abstract class MetadataModel : IEnumerable - { - /// - /// Handle to the encapsulated FreeImage-bitmap. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected readonly FIBITMAP dib; - - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - /// - /// is null. - protected MetadataModel(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - this.dib = dib; - } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public abstract FREE_IMAGE_MDMODEL Model - { - get; - } - - /// - /// Adds new tag to the bitmap or updates its value in case it already exists. - /// will be used as key. - /// - /// The tag to add or update. - /// Returns true on success, false on failure. - /// - /// is null. - /// - /// The tags model differs from this instances model. - public bool AddTag(MetadataTag tag) - { - if (tag == null) - { - throw new ArgumentNullException("tag"); - } - if (tag.Model != Model) - { - throw new ArgumentException("tag.Model"); - } - return tag.AddToImage(dib); - } - - /// - /// Adds a list of tags to the bitmap or updates their values in case they already exist. - /// will be used as key. - /// - /// A list of tags to add or update. - /// Returns the number of successfully added tags. - /// - /// is null. - public int AddTag(IEnumerable list) - { - if (list == null) - { - throw new ArgumentNullException("list"); - } - int count = 0; - foreach (MetadataTag tag in list) - { - if (tag.Model == Model && tag.AddToImage(dib)) - { - count++; - } - } - return count; - } - - /// - /// Removes the specified tag from the bitmap. - /// - /// The key of the tag. - /// Returns true on success, false on failure. - /// - /// is null. - public bool RemoveTag(string key) - { - if (key == null) - { - throw new ArgumentNullException("key"); - } - return FreeImage.SetMetadata(Model, dib, key, FITAG.Zero); - } - - /// - /// Destroys the metadata model - /// which will remove all tags of this model from the bitmap. - /// - /// Returns true on success, false on failure. - public bool DestoryModel() - { - return FreeImage.SetMetadata(Model, dib, null, FITAG.Zero); - } - - /// - /// Returns the specified metadata tag. - /// - /// The key of the tag. - /// The metadata tag. - /// - /// is null. - public MetadataTag GetTag(string key) - { - if (key == null) - { - throw new ArgumentNullException("key"); - } - MetadataTag tag; - return FreeImage.GetMetadata(Model, dib, key, out tag) ? tag : null; - } - - /// - /// Returns whether the specified tag exists. - /// - /// The key of the tag. - /// True in case the tag exists, else false. - /// - /// is null. - public bool TagExists(string key) - { - if (key == null) - { - throw new ArgumentNullException("key"); - } - MetadataTag tag; - return FreeImage.GetMetadata(Model, dib, key, out tag); - } - - /// - /// Returns a list of all metadata tags this instance represents. - /// - public List List - { - get - { - List list = new List((int)FreeImage.GetMetadataCount(Model, dib)); - MetadataTag tag; - FIMETADATA mdHandle = FreeImage.FindFirstMetadata(Model, dib, out tag); - if (!mdHandle.IsNull) - { - do - { - list.Add(tag); - } - while (FreeImage.FindNextMetadata(mdHandle, out tag)); - FreeImage.FindCloseMetadata(mdHandle); - } - return list; - } - } - - /// - /// Returns the tag at the given index. - /// - /// Index of the tag to return. - /// The tag at the given index. - protected MetadataTag GetTagFromIndex(int index) - { - if (index >= Count || index < 0) - { - throw new ArgumentOutOfRangeException("index"); - } - MetadataTag tag; - int count = 0; - FIMETADATA mdHandle = FreeImage.FindFirstMetadata(Model, dib, out tag); - if (!mdHandle.IsNull) - { - try - { - do - { - if (count++ == index) - { - break; - } - } - while (FreeImage.FindNextMetadata(mdHandle, out tag)); - } - finally - { - FreeImage.FindCloseMetadata(mdHandle); - } - } - return tag; - } - - /// - /// Returns the metadata tag at the given index. This operation is slow when accessing all tags. - /// - /// Index of the tag. - /// The metadata tag. - /// - /// is greater or equal Count - /// or index is less than zero. - public MetadataTag this[int index] - { - get - { - return GetTagFromIndex(index); - } - } - - /// - /// Retrieves an object that can iterate through the individual MetadataTags in this MetadataModel. - /// - /// An for the - /// . - public IEnumerator GetEnumerator() - { - return List.GetEnumerator(); - } - - /// - /// Returns the number of metadata tags this instance represents. - /// - public int Count - { - get { return (int)FreeImage.GetMetadataCount(Model, dib); } - } - - /// - /// Returns whether this model exists in the bitmaps metadata structure. - /// - public bool Exists - { - get - { - return Count > 0; - } - } - - /// - /// Searches for a pattern in each metadata tag and returns the result as a list. - /// - /// The regular expression to use for the search. - /// A bitfield that controls which fields should be searched in. - /// A list containing all found metadata tags. - /// - /// is null. - /// - /// is empty. - public List RegexSearch(string searchPattern, MD_SEARCH_FLAGS flags) - { - if (searchPattern == null) - { - throw new ArgumentNullException("searchString"); - } - if (searchPattern.Length == 0) - { - throw new ArgumentException("searchString is empty"); - } - List result = new List(Count); - Regex regex = new Regex(searchPattern); - List list = List; - foreach (MetadataTag tag in list) - { - if (((flags & MD_SEARCH_FLAGS.KEY) > 0) && regex.Match(tag.Key).Success) - { - result.Add(tag); - continue; - } - if (((flags & MD_SEARCH_FLAGS.DESCRIPTION) > 0) && regex.Match(tag.Description).Success) - { - result.Add(tag); - continue; - } - if (((flags & MD_SEARCH_FLAGS.TOSTRING) > 0) && regex.Match(tag.ToString()).Success) - { - result.Add(tag); - continue; - } - } - result.Capacity = result.Count; - return result; - } - - /// - /// Returns the value of the specified tag. - /// - /// Type of the tag's data. - /// The key of the tag. - /// The value of the specified tag. - protected T? GetTagValue(string key) where T : struct - { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - MetadataTag tag = GetTag(key); - if (tag != null) - { - T[] value = tag.Value as T[]; - if ((value != null) && (value.Length != 0)) - { - return value[0]; - } - } - return null; - } - - /// - /// Returns an array containing the data of the specified tag. - /// - /// The type of the tag's data. - /// The key of the tag. - /// An array containing the data of the specified tag. - protected T[] GetTagArray(string key) where T : struct - { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - MetadataTag tag = GetTag(key); - return (tag == null) ? null : tag.Value as T[]; - } - - /// - /// Returns the string contained by the specified tag. - /// - /// The key of the tag. - /// The string contained by the specified tag. - protected string GetTagText(string key) - { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - MetadataTag tag = GetTag(key); - return (tag == null) ? null : tag.Value as string; - } - - /// - /// Returns an array containg the data of the specified tag - /// as unsigned 32bit integer. - /// - /// The key of the tag. - /// An array containg the data of the specified tag - /// as unsigned 32bit integer. - protected uint[] GetUInt32Array(string key) - { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - uint[] result = null; - MetadataTag tag = GetTag(key); - if (tag != null) - { - object value = tag.Value; - if (value != null) - { - if (value is ushort[]) - { - ushort[] array = (ushort[])value; - result = new uint[array.Length]; - for (int i = 0, j = array.Length; i < j; i++) - { - result[i] = (uint)array[i]; - } - } - else if (value is uint[]) - { - result = (uint[])value; - } - } - } - return result; - } - - /// - /// Returns the value of the tag as unsigned 32bit integer. - /// - /// The key of the tag. - /// The value of the tag as unsigned 32bit integer. - protected uint? GetUInt32Value(string key) - { - uint[] value = GetUInt32Array(key); - return value == null ? default(uint?) : value[0]; - } - - /// - /// Sets the value of the specified tag. - /// - /// The type of the tag's data. - /// The key of the tag. - /// The new value of the specified tag or null. - protected void SetTagValue(string key, T? value) where T : struct - { - SetTagValue(key, value.HasValue ? new T[] { value.Value } : null); - } - - /// - /// Sets the value of the specified tag. - /// - /// The key of the tag. - /// The new value of the specified tag or null. - protected void SetTagValue(string key, object value) - { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - if (value == null) - { - RemoveTag(key); - } - else - { - MetadataTag tag = GetTag(key); - if (tag == null) - { - tag = new MetadataTag(Model); - tag.Key = key; - tag.Value = value; - AddTag(tag); - } - else - { - tag.Value = value; - } - } - } - - /// - /// Sets the value of the specified tag as undefined. - /// - /// The key of the tag. - /// The new value of the specified tag or null. - protected void SetTagValueUndefined(string key, byte[] value) - { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - if (value == null) - { - RemoveTag(key); - } - else - { - MetadataTag tag = GetTag(key); - if (tag == null) - { - tag = new MetadataTag(Model); - tag.Key = key; - tag.SetValue(value, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED); - AddTag(tag); - } - else - { - tag.Value = value; - } - } - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The string containing the . - /// The equivalent for the - /// specified . - protected static DirectionReference? ToDirectionType(string s) - { - if (string.IsNullOrEmpty(s)) - return null; - switch (s[0]) - { - case 'T': - return DirectionReference.TrueDirection; - case 'M': - return DirectionReference.MagneticDirection; - default: - return DirectionReference.Undefined; - } - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The to convert. - /// The equivalent for the - /// specified . - protected static string ToString(DirectionReference? type) - { - if (type.HasValue) - { - switch (type.Value) - { - case DirectionReference.TrueDirection: - return "T"; - case DirectionReference.MagneticDirection: - return "M"; - default: - return "\0"; - } - } - return null; - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The string containing the . - /// The equivalent for the - /// specified . - protected static VelocityUnit? ToUnitType(string s) - { - if (string.IsNullOrEmpty(s)) - return null; - switch (s[0]) - { - case 'K': - return VelocityUnit.Kilometers; - case 'M': - return VelocityUnit.Miles; - case 'N': - return VelocityUnit.Knots; - default: - return VelocityUnit.Undefinied; - } - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The to convert. - /// The equivalent for the - /// specified . - protected static string ToString(VelocityUnit? type) - { - if (type.HasValue) - { - switch (type.Value) - { - case VelocityUnit.Kilometers: - return "K"; - case VelocityUnit.Miles: - return "M"; - case VelocityUnit.Knots: - return "N"; - default: - return "\0"; - } - } - return null; - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The string containing the . - /// The equivalent for the - /// specified . - protected static LongitudeType? ToLongitudeType(string s) - { - if (string.IsNullOrEmpty(s)) - return null; - switch (s[0]) - { - case 'E': - return LongitudeType.East; - case 'W': - return LongitudeType.West; - default: - return LongitudeType.Undefined; - } - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The to convert. - /// The equivalent for the - /// specified . - protected static string ToString(LongitudeType? type) - { - if (type.HasValue) - { - switch (type.Value) - { - case LongitudeType.East: - return "E"; - case LongitudeType.West: - return "W"; - default: - return "\0"; - } - } - return null; - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The string containing the . - /// The equivalent for the - /// specified . - protected static LatitudeType? ToLatitudeType(string s) - { - if (string.IsNullOrEmpty(s)) - return null; - switch (s[0]) - { - case 'N': - return LatitudeType.North; - case 'S': - return LatitudeType.South; - default: - return LatitudeType.Undefined; - } - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The to convert. - /// The equivalent for the - /// specified . - protected static string ToString(LatitudeType? type) - { - if (type.HasValue) - { - switch (type.Value) - { - case LatitudeType.North: - return "N"; - case LatitudeType.South: - return "S"; - default: - return "\0"; - } - } - return null; - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The string containing the . - /// The equivalent for the - /// specified . - protected static InteroperabilityMode? ToInteroperabilityType(string s) - { - if (string.IsNullOrEmpty(s)) - return null; - if (s.StartsWith("R98")) - return InteroperabilityMode.R98; - if (s.StartsWith("THM")) - return InteroperabilityMode.THM; - return InteroperabilityMode.Undefined; - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The to convert. - /// The equivalent for the - /// specified . - protected static string ToString(InteroperabilityMode? type) - { - if (type.HasValue) - { - switch (type.Value) - { - case InteroperabilityMode.R98: - return "R98"; - case InteroperabilityMode.THM: - return "THM"; - default: - return "\0\0\0"; - } - } - return null; - } - - /// - /// Specified different unit types. - /// - public enum VelocityUnit - { - /// - /// No or unknown type. - /// - Undefinied, - - /// - /// Kilometers per hour. - /// - Kilometers, - - /// - /// Miles per hour. - /// - Miles, - - /// - /// Knots. - /// - Knots, - } - - /// - /// Specifies different direction types. - /// - public enum DirectionReference - { - /// - /// No or unknown direction type. - /// - Undefined, - - /// - /// True direction. - /// - TrueDirection, - - /// - /// Magnatic direction. - /// - MagneticDirection, - } - - /// - /// Specifies the type of a latitude value. - /// - public enum LatitudeType - { - /// - /// No or unknown type. - /// - Undefined, - - /// - /// North. - /// - North, - - /// - /// South. - /// - South, - } - - /// - /// Specifies the type of a longitude value. - /// - public enum LongitudeType - { - /// - /// No or unknown type. - /// - Undefined, - - /// - /// East. - /// - East, - - /// - /// West. - /// - West, - } - - /// - /// Specifies different altitude types. - /// - public enum AltitudeType - { - /// - /// No or unknown type. - /// - Undefined, - - /// - /// East. - /// - AboveSeaLevel, - - /// - /// West. - /// - BelowSeaLevel, - } - - /// - /// Specifies interoperability types. - /// - public enum InteroperabilityMode - { - /// - /// No or unknown type. - /// - Undefined, - - /// - /// Indicates a file conforming to R98 file specification of Recommended - /// Exif Interoperability Rules (ExifR98) or to DCF basic file stipulated - /// by Design Rule for Camera File System. - /// - R98, - - /// - /// Indicates a file conforming to DCF thumbnail file stipulated by Design - /// rule for Camera File System. - /// - THM, - } - - /// - /// Specifies orientation of images. - /// - public enum ExifImageOrientation : ushort - { - /// - /// Undefinied orientation. - /// - Undefined, - - /// - /// TopLeft. - /// - TopLeft = 1, - - /// - /// TopRight. - /// - TopRight, - - /// - /// BottomRight. - /// - BottomRight, - - /// - /// BottomLeft. - /// - BottomLeft, - - /// - /// LeftTop. - /// - LeftTop, - - /// - /// RightTop. - /// - RightTop, - - /// - /// RightBottom. - /// - RightBottom, - - /// - /// LeftBottom. - /// - LeftBottom, - } - - /// - /// Converts the model of the MetadataModel object to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return Model.ToString(); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.8 $ +// $Date: 2009/02/27 16:34:31 $ +// $Id: MetadataModel.cs,v 1.8 2009/02/27 16:34:31 cklein05 Exp $ +// ========================================================== + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using System.Diagnostics; + +namespace FreeImageAPI.Metadata +{ + /// + /// Base class that represents a collection of all tags contained in a metadata model. + /// + /// + /// The MetedataModel class is an abstract base class, which is inherited by + /// several derived classes, one for each existing metadata model. + /// + public abstract class MetadataModel : IEnumerable + { + /// + /// Handle to the encapsulated FreeImage-bitmap. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected readonly FIBITMAP dib; + + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + /// + /// is null. + protected MetadataModel(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + this.dib = dib; + } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public abstract FREE_IMAGE_MDMODEL Model + { + get; + } + + /// + /// Adds new tag to the bitmap or updates its value in case it already exists. + /// will be used as key. + /// + /// The tag to add or update. + /// Returns true on success, false on failure. + /// + /// is null. + /// + /// The tags model differs from this instances model. + public bool AddTag(MetadataTag tag) + { + if (tag == null) + { + throw new ArgumentNullException("tag"); + } + if (tag.Model != Model) + { + throw new ArgumentException("tag.Model"); + } + return tag.AddToImage(dib); + } + + /// + /// Adds a list of tags to the bitmap or updates their values in case they already exist. + /// will be used as key. + /// + /// A list of tags to add or update. + /// Returns the number of successfully added tags. + /// + /// is null. + public int AddTag(IEnumerable list) + { + if (list == null) + { + throw new ArgumentNullException("list"); + } + int count = 0; + foreach (MetadataTag tag in list) + { + if (tag.Model == Model && tag.AddToImage(dib)) + { + count++; + } + } + return count; + } + + /// + /// Removes the specified tag from the bitmap. + /// + /// The key of the tag. + /// Returns true on success, false on failure. + /// + /// is null. + public bool RemoveTag(string key) + { + if (key == null) + { + throw new ArgumentNullException("key"); + } + return FreeImage.SetMetadata(Model, dib, key, FITAG.Zero); + } + + /// + /// Destroys the metadata model + /// which will remove all tags of this model from the bitmap. + /// + /// Returns true on success, false on failure. + public bool DestoryModel() + { + return FreeImage.SetMetadata(Model, dib, null, FITAG.Zero); + } + + /// + /// Returns the specified metadata tag. + /// + /// The key of the tag. + /// The metadata tag. + /// + /// is null. + public MetadataTag GetTag(string key) + { + if (key == null) + { + throw new ArgumentNullException("key"); + } + MetadataTag tag; + return FreeImage.GetMetadata(Model, dib, key, out tag) ? tag : null; + } + + /// + /// Returns whether the specified tag exists. + /// + /// The key of the tag. + /// True in case the tag exists, else false. + /// + /// is null. + public bool TagExists(string key) + { + if (key == null) + { + throw new ArgumentNullException("key"); + } + MetadataTag tag; + return FreeImage.GetMetadata(Model, dib, key, out tag); + } + + /// + /// Returns a list of all metadata tags this instance represents. + /// + public List List + { + get + { + List list = new List((int)FreeImage.GetMetadataCount(Model, dib)); + MetadataTag tag; + FIMETADATA mdHandle = FreeImage.FindFirstMetadata(Model, dib, out tag); + if (!mdHandle.IsNull) + { + do + { + list.Add(tag); + } + while (FreeImage.FindNextMetadata(mdHandle, out tag)); + FreeImage.FindCloseMetadata(mdHandle); + } + return list; + } + } + + /// + /// Returns the tag at the given index. + /// + /// Index of the tag to return. + /// The tag at the given index. + protected MetadataTag GetTagFromIndex(int index) + { + if (index >= Count || index < 0) + { + throw new ArgumentOutOfRangeException("index"); + } + MetadataTag tag; + int count = 0; + FIMETADATA mdHandle = FreeImage.FindFirstMetadata(Model, dib, out tag); + if (!mdHandle.IsNull) + { + try + { + do + { + if (count++ == index) + { + break; + } + } + while (FreeImage.FindNextMetadata(mdHandle, out tag)); + } + finally + { + FreeImage.FindCloseMetadata(mdHandle); + } + } + return tag; + } + + /// + /// Returns the metadata tag at the given index. This operation is slow when accessing all tags. + /// + /// Index of the tag. + /// The metadata tag. + /// + /// is greater or equal Count + /// or index is less than zero. + public MetadataTag this[int index] + { + get + { + return GetTagFromIndex(index); + } + } + + /// + /// Retrieves an object that can iterate through the individual MetadataTags in this MetadataModel. + /// + /// An for the + /// . + public IEnumerator GetEnumerator() + { + return List.GetEnumerator(); + } + + /// + /// Returns the number of metadata tags this instance represents. + /// + public int Count + { + get { return (int)FreeImage.GetMetadataCount(Model, dib); } + } + + /// + /// Returns whether this model exists in the bitmaps metadata structure. + /// + public bool Exists + { + get + { + return Count > 0; + } + } + + /// + /// Searches for a pattern in each metadata tag and returns the result as a list. + /// + /// The regular expression to use for the search. + /// A bitfield that controls which fields should be searched in. + /// A list containing all found metadata tags. + /// + /// is null. + /// + /// is empty. + public List RegexSearch(string searchPattern, MD_SEARCH_FLAGS flags) + { + if (searchPattern == null) + { + throw new ArgumentNullException("searchString"); + } + if (searchPattern.Length == 0) + { + throw new ArgumentException("searchString is empty"); + } + List result = new List(Count); + Regex regex = new Regex(searchPattern); + List list = List; + foreach (MetadataTag tag in list) + { + if (((flags & MD_SEARCH_FLAGS.KEY) > 0) && regex.Match(tag.Key).Success) + { + result.Add(tag); + continue; + } + if (((flags & MD_SEARCH_FLAGS.DESCRIPTION) > 0) && regex.Match(tag.Description).Success) + { + result.Add(tag); + continue; + } + if (((flags & MD_SEARCH_FLAGS.TOSTRING) > 0) && regex.Match(tag.ToString()).Success) + { + result.Add(tag); + continue; + } + } + result.Capacity = result.Count; + return result; + } + + /// + /// Returns the value of the specified tag. + /// + /// Type of the tag's data. + /// The key of the tag. + /// The value of the specified tag. + protected T? GetTagValue(string key) where T : struct + { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException("key"); + } + MetadataTag tag = GetTag(key); + if (tag != null) + { + T[] value = tag.Value as T[]; + if ((value != null) && (value.Length != 0)) + { + return value[0]; + } + } + return null; + } + + /// + /// Returns an array containing the data of the specified tag. + /// + /// The type of the tag's data. + /// The key of the tag. + /// An array containing the data of the specified tag. + protected T[] GetTagArray(string key) where T : struct + { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException("key"); + } + MetadataTag tag = GetTag(key); + return (tag == null) ? null : tag.Value as T[]; + } + + /// + /// Returns the string contained by the specified tag. + /// + /// The key of the tag. + /// The string contained by the specified tag. + protected string GetTagText(string key) + { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException("key"); + } + MetadataTag tag = GetTag(key); + return (tag == null) ? null : tag.Value as string; + } + + /// + /// Returns an array containg the data of the specified tag + /// as unsigned 32bit integer. + /// + /// The key of the tag. + /// An array containg the data of the specified tag + /// as unsigned 32bit integer. + protected uint[] GetUInt32Array(string key) + { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException("key"); + } + uint[] result = null; + MetadataTag tag = GetTag(key); + if (tag != null) + { + object value = tag.Value; + if (value != null) + { + if (value is ushort[]) + { + ushort[] array = (ushort[])value; + result = new uint[array.Length]; + for (int i = 0, j = array.Length; i < j; i++) + { + result[i] = (uint)array[i]; + } + } + else if (value is uint[]) + { + result = (uint[])value; + } + } + } + return result; + } + + /// + /// Returns the value of the tag as unsigned 32bit integer. + /// + /// The key of the tag. + /// The value of the tag as unsigned 32bit integer. + protected uint? GetUInt32Value(string key) + { + uint[] value = GetUInt32Array(key); + return value == null ? default(uint?) : value[0]; + } + + /// + /// Sets the value of the specified tag. + /// + /// The type of the tag's data. + /// The key of the tag. + /// The new value of the specified tag or null. + protected void SetTagValue(string key, T? value) where T : struct + { + SetTagValue(key, value.HasValue ? new T[] { value.Value } : null); + } + + /// + /// Sets the value of the specified tag. + /// + /// The key of the tag. + /// The new value of the specified tag or null. + protected void SetTagValue(string key, object value) + { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException("key"); + } + if (value == null) + { + RemoveTag(key); + } + else + { + MetadataTag tag = GetTag(key); + if (tag == null) + { + tag = new MetadataTag(Model); + tag.Key = key; + tag.Value = value; + AddTag(tag); + } + else + { + tag.Value = value; + } + } + } + + /// + /// Sets the value of the specified tag as undefined. + /// + /// The key of the tag. + /// The new value of the specified tag or null. + protected void SetTagValueUndefined(string key, byte[] value) + { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException("key"); + } + if (value == null) + { + RemoveTag(key); + } + else + { + MetadataTag tag = GetTag(key); + if (tag == null) + { + tag = new MetadataTag(Model); + tag.Key = key; + tag.SetValue(value, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED); + AddTag(tag); + } + else + { + tag.Value = value; + } + } + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The string containing the . + /// The equivalent for the + /// specified . + protected static DirectionReference? ToDirectionType(string s) + { + if (string.IsNullOrEmpty(s)) + return null; + switch (s[0]) + { + case 'T': + return DirectionReference.TrueDirection; + case 'M': + return DirectionReference.MagneticDirection; + default: + return DirectionReference.Undefined; + } + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The to convert. + /// The equivalent for the + /// specified . + protected static string ToString(DirectionReference? type) + { + if (type.HasValue) + { + switch (type.Value) + { + case DirectionReference.TrueDirection: + return "T"; + case DirectionReference.MagneticDirection: + return "M"; + default: + return "\0"; + } + } + return null; + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The string containing the . + /// The equivalent for the + /// specified . + protected static VelocityUnit? ToUnitType(string s) + { + if (string.IsNullOrEmpty(s)) + return null; + switch (s[0]) + { + case 'K': + return VelocityUnit.Kilometers; + case 'M': + return VelocityUnit.Miles; + case 'N': + return VelocityUnit.Knots; + default: + return VelocityUnit.Undefinied; + } + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The to convert. + /// The equivalent for the + /// specified . + protected static string ToString(VelocityUnit? type) + { + if (type.HasValue) + { + switch (type.Value) + { + case VelocityUnit.Kilometers: + return "K"; + case VelocityUnit.Miles: + return "M"; + case VelocityUnit.Knots: + return "N"; + default: + return "\0"; + } + } + return null; + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The string containing the . + /// The equivalent for the + /// specified . + protected static LongitudeType? ToLongitudeType(string s) + { + if (string.IsNullOrEmpty(s)) + return null; + switch (s[0]) + { + case 'E': + return LongitudeType.East; + case 'W': + return LongitudeType.West; + default: + return LongitudeType.Undefined; + } + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The to convert. + /// The equivalent for the + /// specified . + protected static string ToString(LongitudeType? type) + { + if (type.HasValue) + { + switch (type.Value) + { + case LongitudeType.East: + return "E"; + case LongitudeType.West: + return "W"; + default: + return "\0"; + } + } + return null; + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The string containing the . + /// The equivalent for the + /// specified . + protected static LatitudeType? ToLatitudeType(string s) + { + if (string.IsNullOrEmpty(s)) + return null; + switch (s[0]) + { + case 'N': + return LatitudeType.North; + case 'S': + return LatitudeType.South; + default: + return LatitudeType.Undefined; + } + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The to convert. + /// The equivalent for the + /// specified . + protected static string ToString(LatitudeType? type) + { + if (type.HasValue) + { + switch (type.Value) + { + case LatitudeType.North: + return "N"; + case LatitudeType.South: + return "S"; + default: + return "\0"; + } + } + return null; + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The string containing the . + /// The equivalent for the + /// specified . + protected static InteroperabilityMode? ToInteroperabilityType(string s) + { + if (string.IsNullOrEmpty(s)) + return null; + if (s.StartsWith("R98")) + return InteroperabilityMode.R98; + if (s.StartsWith("THM")) + return InteroperabilityMode.THM; + return InteroperabilityMode.Undefined; + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The to convert. + /// The equivalent for the + /// specified . + protected static string ToString(InteroperabilityMode? type) + { + if (type.HasValue) + { + switch (type.Value) + { + case InteroperabilityMode.R98: + return "R98"; + case InteroperabilityMode.THM: + return "THM"; + default: + return "\0\0\0"; + } + } + return null; + } + + /// + /// Specified different unit types. + /// + public enum VelocityUnit + { + /// + /// No or unknown type. + /// + Undefinied, + + /// + /// Kilometers per hour. + /// + Kilometers, + + /// + /// Miles per hour. + /// + Miles, + + /// + /// Knots. + /// + Knots, + } + + /// + /// Specifies different direction types. + /// + public enum DirectionReference + { + /// + /// No or unknown direction type. + /// + Undefined, + + /// + /// True direction. + /// + TrueDirection, + + /// + /// Magnatic direction. + /// + MagneticDirection, + } + + /// + /// Specifies the type of a latitude value. + /// + public enum LatitudeType + { + /// + /// No or unknown type. + /// + Undefined, + + /// + /// North. + /// + North, + + /// + /// South. + /// + South, + } + + /// + /// Specifies the type of a longitude value. + /// + public enum LongitudeType + { + /// + /// No or unknown type. + /// + Undefined, + + /// + /// East. + /// + East, + + /// + /// West. + /// + West, + } + + /// + /// Specifies different altitude types. + /// + public enum AltitudeType + { + /// + /// No or unknown type. + /// + Undefined, + + /// + /// East. + /// + AboveSeaLevel, + + /// + /// West. + /// + BelowSeaLevel, + } + + /// + /// Specifies interoperability types. + /// + public enum InteroperabilityMode + { + /// + /// No or unknown type. + /// + Undefined, + + /// + /// Indicates a file conforming to R98 file specification of Recommended + /// Exif Interoperability Rules (ExifR98) or to DCF basic file stipulated + /// by Design Rule for Camera File System. + /// + R98, + + /// + /// Indicates a file conforming to DCF thumbnail file stipulated by Design + /// rule for Camera File System. + /// + THM, + } + + /// + /// Specifies orientation of images. + /// + public enum ExifImageOrientation : ushort + { + /// + /// Undefinied orientation. + /// + Undefined, + + /// + /// TopLeft. + /// + TopLeft = 1, + + /// + /// TopRight. + /// + TopRight, + + /// + /// BottomRight. + /// + BottomRight, + + /// + /// BottomLeft. + /// + BottomLeft, + + /// + /// LeftTop. + /// + LeftTop, + + /// + /// RightTop. + /// + RightTop, + + /// + /// RightBottom. + /// + RightBottom, + + /// + /// LeftBottom. + /// + LeftBottom, + } + + /// + /// Converts the model of the MetadataModel object to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return Model.ToString(); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/MetadataModels.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/MetadataModels.cs index 4cd2835..dfa9f90 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/MetadataModels.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/MetadataModels.cs @@ -1,6724 +1,6724 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.6 $ -// $Date: 2009/09/15 11:49:24 $ -// $Id: MetadataModels.cs,v 1.6 2009/09/15 11:49:24 cklein05 Exp $ -// ========================================================== - -using System; -using System.Xml; -using System.IO; -using System.Text; - -namespace FreeImageAPI.Metadata -{ - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_ANIMATION : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_ANIMATION(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_ANIMATION; } - } - - /// - /// Gets or sets the width of the entire canvas area, that each page is displayed in. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? LogicalWidth - { - get - { - return GetTagValue("LogicalWidth"); - } - set - { - SetTagValue("LogicalWidth", value); - } - } - - /// - /// Gets or sets the height of the entire canvas area, that each page is displayed in. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? LogicalHeight - { - get - { - return GetTagValue("LogicalHeight"); - } - set - { - SetTagValue("LogicalHeight", value); - } - } - - /// - /// Gets or sets the global palette of the GIF image. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public Palette GlobalPalette - { - get - { - MetadataTag mdtag = GetTag("GlobalPalette"); - return (mdtag == null) ? null : new Palette(mdtag); - } - set - { - SetTagValue("GlobalPalette", (value != null) ? null : value.Data); - } - } - - /// - /// Gets or sets the number of replays for the animation. - /// Use 0 (zero) to specify an infinte number of replays. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? LoopCount - { - get - { - return GetTagValue("Loop"); - } - set - { - SetTagValue("Loop", value); - } - } - - /// - /// Gets or sets the horizontal offset within the logical canvas area, this frame is to be displayed at. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? FrameLeft - { - get - { - return GetTagValue("FrameLeft"); - } - set - { - SetTagValue("FrameLeft", value); - } - } - - /// - /// Gets or sets the vertical offset within the logical canvas area, this frame is to be displayed at. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? FrameTop - { - get - { - return GetTagValue("FrameTop"); - } - set - { - SetTagValue("FrameTop", value); - } - } - - /// - /// Gets or sets a flag to supress saving the dib's attached palette - /// (making it use the global palette). The local palette is the palette used by a page. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public bool? NoLocalPalette - { - get - { - byte? useGlobalPalette = GetTagValue("NoLocalPalette"); - return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?); - } - set - { - byte? val = null; - if (value.HasValue) - { - val = (byte)(value.Value ? 1 : 0); - } - SetTagValue("NoLocalPalette", val); - } - } - - /// - /// Gets or sets a value indicating whether the image is interlaced. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public bool? Interlaced - { - get - { - byte? useGlobalPalette = GetTagValue("Interlaced"); - return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?); - } - set - { - byte? val = null; - if (value.HasValue) - { - val = (byte)(value.Value ? 1 : 0); - } - SetTagValue("Interlaced", val); - } - } - - /// - /// Gets or sets the amout of time in milliseconds this frame is to be displayed. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? FrameTime - { - get - { - return GetTagValue("FrameTime"); - } - set - { - SetTagValue("FrameTime", value); - } - } - - /// - /// Gets or sets this frame's disposal method. Generally, this method defines, how to - /// remove or replace a frame when the next frame has to be drawn. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public DisposalMethodType? DisposalMethod - { - get - { - return GetTagValue("DisposalMethod"); - } - set - { - SetTagValue("DisposalMethod", value); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_COMMENTS : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_COMMENTS(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_COMMENTS; } - } - - /// - /// Gets or sets the comment of the image. - /// Supported formats are JPEG, PNG and GIF. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Comment - { - get - { - return GetTagText("Comment"); - } - set - { - SetTagValue("Comment", value); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_CUSTOM : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_CUSTOM(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_CUSTOM; } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_EXIF_EXIF : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_EXIF_EXIF(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF; } - } - - /// - /// Gets or sets the version of this standard supported. - /// Constant length or 4. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] ExifVersion - { - get - { - return GetTagArray("ExifVersion"); - } - set - { - FreeImage.Resize(ref value, 4); - SetTagValueUndefined("ExifVersion", value); - } - } - - /// - /// Gets or sets the Flashpix format version supported by a FPXR file. - /// Constant length or 4. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] FlashpixVersion - { - get - { - return GetTagArray("FlashpixVersion"); - } - set - { - FreeImage.Resize(ref value, 4); - SetTagValueUndefined("FlashpixVersion", value); - } - } - - /// - /// Gets or sets the color space information tag. - /// See remarks for further information. - /// - /// - /// The following values are defined: - /// - /// - /// ID - /// Description - /// - /// - /// 1 - /// sRGB (default) - /// - /// - /// 0xFFFF - /// uncalibrated - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? ColorSpace - { - get - { - return GetTagValue("ColorSpace"); - } - set - { - SetTagValue("ColorSpace", value); - } - } - - /// - /// Gets or sets the valid width of a compressed image. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? PixelXDimension - { - get - { - return GetUInt32Value("PixelXDimension"); - } - set - { - RemoveTag("PixelXDimension"); - if (value.HasValue) - { - SetTagValue("PixelXDimension", value.Value); - } - } - } - - /// - /// Gets or sets the valid height of a compressed image. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? PixelYDimension - { - get - { - return GetUInt32Value("PixelYDimension"); - } - set - { - RemoveTag("PixelYDimension"); - if (value.HasValue) - { - SetTagValue("PixelYDimension", value.Value); - } - } - } - - /// - /// Gets or sets components configuration. See remarks for further information. - /// Constant length of 4. - /// - /// - /// The channels of each component are arranged in order from the 1st component to the 4th. - /// For uncompressed data the data arrangement is given in the PhotometricInterpretation tag. - /// However, since PhotometricInterpretation can only express the order of Y,Cb and Cr, - /// this tag is provided for cases when compressed data uses components other than Y, Cb, - /// and Cr and to enable support of other sequences. - /// Default = 4 5 6 0 (if RGB uncompressed) - /// The following values are defined: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// does not exist - /// - /// - /// 1 - /// Y - /// - /// - /// 2 - /// Cb - /// - /// - /// 3 - /// Cr - /// - /// - /// 4 - /// R - /// - /// - /// 5 - /// R - /// - /// - /// 6 - /// R - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public byte[] ComponentsConfiguration - { - get - { - return GetTagArray("ComponentsConfiguration"); - } - set - { - FreeImage.Resize(ref value, 4); - SetTagValueUndefined("ComponentsConfiguration", value); - } - } - - /// - /// Gets or sets compression mode used for a compressed image is indicated - /// in unit bits per pixel. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? CompressedBitsPerPixel - { - get - { - return GetTagValue("CompressedBitsPerPixel"); - } - set - { - SetTagValue("CompressedBitsPerPixel", value); - } - } - - /// - /// Gets or sets a tag for manufacturers of Exif writers to record any desired information. - /// The contents are up to the manufacturer, but this tag should not be used for any other - /// than its intended purpose. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] MakerNote - { - get - { - return GetTagArray("FlashpixVersion"); - } - set - { - SetTagValueUndefined("FlashpixVersion", value); - } - } - - /// - /// Gets or sets a tag for Exif users to write keywords or comments on the image besides - /// those in ImageDescription, and without the character code limitations of the ImageDescription tag. - /// Minimum length of 8. See remarks for further information. - /// - /// - /// The character code used in the UserComment tag is identified based on an ID code in a fixed 8-byte - /// area at the start of the tag data area. The unused portion of the area is padded with NULL. - /// The ID code for the UserComment area may be a Defined code such as JIS or ASCII, or may be Undefined. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public byte[] UserComment - { - get - { - return GetTagArray("UserComment"); - } - set - { - FreeImage.Resize(ref value, 8, int.MaxValue); - SetTagValueUndefined("UserComment", value); - } - } - - /// - /// Gets or sets the name of an audio file related to the image data. - /// The format is 8.3. - /// Constant length of 12 - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string RelatedSoundFile - { - get - { - string text = GetTagText("RelatedSoundFile"); - if (!string.IsNullOrEmpty(text)) - { - text = text.Substring(0, text.Length - 1); - } - return text; - } - set - { - if (value != null) - { - FreeImage.Resize(ref value, 12); - value += '\0'; - } - SetTagValue("RelatedSoundFile", value); - } - } - - /// - /// Gets or sets the date and time when the original image data was generated. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public DateTime? DateTimeOriginal - { - get - { - DateTime? result = null; - string text = GetTagText("DateTimeOriginal"); - if (text != null) - { - try - { - result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null); - } - catch - { - } - } - return result; - } - set - { - string val = null; - if (value.HasValue) - { - try - { - val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0"); - } - catch - { - } - } - SetTagValue("DateTimeOriginal", val); - } - } - - /// - /// Gets or sets the date and time when the image was stored as digital data. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public DateTime? DateTimeDigitized - { - get - { - DateTime? result = null; - string text = GetTagText("DateTimeDigitized"); - if (text != null) - { - try - { - result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null); - } - catch - { - } - } - return result; - } - set - { - string val = null; - if (value.HasValue) - { - try - { - val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0"); - } - catch - { - } - } - SetTagValue("DateTimeDigitized", val); - } - } - - /// - /// Gets or sets a tag used to record fractions of seconds for the DateTime tag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SubsecTime - { - get - { - string text = GetTagText("SubsecTime"); - if (!string.IsNullOrEmpty(text)) - { - text = text.Substring(0, text.Length - 1); - } - return text; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("SubsecTime", value); - } - } - - /// - /// Gets or sets a tag used to record fractions of seconds for the DateTimeOriginal tag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SubsecTimeOriginal - { - get - { - string text = GetTagText("SubsecTimeOriginal"); - if (!string.IsNullOrEmpty(text)) - { - text = text.Substring(0, text.Length - 1); - } - return text; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("SubsecTimeOriginal", value); - } - } - - /// - /// Gets or sets a tag used to record fractions of seconds for the DateTimeDigitized tag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SubsecTimeDigitized - { - get - { - string text = GetTagText("SubsecTimeDigitized"); - if (!string.IsNullOrEmpty(text)) - { - text = text.Substring(0, text.Length - 1); - } - return text; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("SubsecTimeDigitized", value); - } - } - - /// - /// Gets or the exposure time, given in seconds (sec). - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? ExposureTime - { - get - { - return GetTagValue("ExposureTime"); - } - set - { - SetTagValue("ExposureTime", value); - } - } - - /// - /// Gets or the F number. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? FNumber - { - get - { - return GetTagValue("FNumber"); - } - set - { - SetTagValue("FNumber", value); - } - } - - /// - /// Gets or sets the class of the program used by the camera to set exposure when the - /// picture is taken. - /// See remarks for further information. - /// - /// - /// The following values are defined: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// not defined - /// - /// - /// 1 - /// manual - /// - /// - /// 2 - /// normal program - /// - /// - /// 3 - /// aperture priority - /// - /// - /// 4 - /// shutter priority - /// - /// - /// 5 - /// create program - /// - /// - /// 6 - /// action program - /// - /// - /// 7 - /// portrait mode - /// - /// - /// 8 - /// landscape mode - /// - /// - /// others - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? ExposureProgram - { - get - { - return GetTagValue("ExposureProgram"); - } - set - { - SetTagValue("ExposureProgram", value); - } - } - - /// - /// Gets or sets the spectral sensitivity of each channel of the camera used. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SpectralSensitivity - { - get - { - string text = GetTagText("SpectralSensitivity"); - if (!string.IsNullOrEmpty(text)) - { - text = text.Substring(0, text.Length - 1); - } - return text; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("SpectralSensitivity", value); - } - } - - /// - /// Gets or sets the the ISO Speed and ISO Latitude of the camera or input device as - /// specified in ISO 12232. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort[] ISOSpeedRatings - { - get - { - return GetTagArray("ISOSpeedRatings"); - } - set - { - SetTagValue("ISOSpeedRatings", value); - } - } - - /// - /// Gets or sets the Opto-Electric Conversion Function (OECF) specified in ISO 14524. - /// OECF is the relationship between the camera optical input and the image values. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] OECF - { - get - { - return GetTagArray("OECF"); - } - set - { - SetTagValueUndefined("OECF", value); - } - } - - /// - /// Gets or sets the shutter speed. The unit is the APEX (Additive System of Photographic Exposure). - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIRational? ShutterSpeedValue - { - get - { - return GetTagValue("ShutterSpeedValue"); - } - set - { - SetTagValue("ShutterSpeedValue", value); - } - } - - /// - /// Gets or sets the lens aperture. The unit is the APEX value. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? ApertureValue - { - get - { - return GetTagValue("ApertureValue"); - } - set - { - SetTagValue("ApertureValue", value); - } - } - - /// - /// Gets or sets the value of brightness. The unit is the APEX value. - /// Ordinarily it is given in the range of -99.99 to 99.99. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIRational? BrightnessValue - { - get - { - return GetTagValue("BrightnessValue"); - } - set - { - SetTagValue("BrightnessValue", value); - } - } - - /// - /// Gets or sets the exposure bias. The unit is the APEX value. - /// Ordinarily it is given in the range of –99.99 to 99.99. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIRational? ExposureBiasValue - { - get - { - return GetTagValue("ExposureBiasValue"); - } - set - { - SetTagValue("ExposureBiasValue", value); - } - } - - /// - /// Gets or sets the smallest F number of the lens. The unit is the APEX value. - /// Ordinarily it is given in the range of 00.00 to 99.99, - /// but it is not limited to this range. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? MaxApertureValue - { - get - { - return GetTagValue("MaxApertureValue"); - } - set - { - SetTagValue("MaxApertureValue", value); - } - } - - /// - /// Gets or sets distance to the subject, given in meters. - /// Note that if the numerator of the recorded value is FFFFFFFF, infinity shall be indicated; - /// and if the numerator is 0, distance unknown shall be indicated. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? SubjectDistance - { - get - { - return GetTagValue("SubjectDistance"); - } - set - { - SetTagValue("SubjectDistance", value); - } - } - - /// - /// Gets or sets the metering mode. See remarks for further information. - /// - /// - /// The following values are defined: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// unknown - /// - /// - /// 1 - /// average - /// - /// - /// 2 - /// center-weighted-average - /// - /// - /// 3 - /// spot - /// - /// - /// 4 - /// multi-spot - /// - /// - /// 5 - /// pattern - /// - /// - /// 6 - /// partial - /// - /// - /// other - /// reserved - /// - /// - /// 255 - /// other - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? MeteringMode - { - get - { - return GetTagValue("MeteringMode"); - } - set - { - SetTagValue("MeteringMode", value); - } - } - - /// - /// Gets or sets the kind of light source. - /// See remarks for further information. - /// - /// - /// The following values are defined: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// unknown - /// - /// - /// 1 - /// daylight - /// - /// - /// 2 - /// fluorescent - /// - /// - /// 3 - /// tungsten - /// - /// - /// 4 - /// flash - /// - /// - /// 9 - /// fine weather - /// - /// - /// 10 - /// cloudy weather - /// - /// - /// 11 - /// shade - /// - /// - /// 12 - /// daylight fluorecent (D 5700 - 7100K) - /// - /// - /// 13 - /// day white fluorescent (N 4600 - 5400K) - /// - /// - /// 14 - /// cool white fluorescent (W 3900 - 4500K) - /// - /// - /// 15 - /// white fluorescent (WW 3200 - 3700K) - /// - /// - /// 17 - /// standard light A - /// - /// - /// 18 - /// standard light B - /// - /// - /// 19 - /// standard light C - /// - /// - /// 20 - /// D55 - /// - /// - /// 21 - /// D65 - /// - /// - /// 22 - /// D75 - /// - /// - /// 23 - /// D50 - /// - /// - /// 24 - /// ISO studio tungsten - /// - /// - /// 255 - /// other light source - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? LightSource - { - get - { - return GetTagValue("LightSource"); - } - set - { - SetTagValue("LightSource", value); - } - } - - /// - /// Gets or sets a value indicating the status of flash when the image was shot. - /// Bit 0 indicates the flash firing status, bits 1 and 2 indicate the flash return - /// status, bits 3 and 4 indicate the flash mode, bit 5 indicates whether the flash - /// function is present, and bit 6 indicates "red eye" mode. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? Flash - { - get - { - return GetTagValue("Flash"); - } - set - { - SetTagValue("Flash", value); - } - } - - /// - /// Gets or sets a value indicating the location and area of the main subject in - /// the overall scene. Variable length between 2 and 4. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort[] SubjectArea - { - get - { - return GetTagArray("SubjectArea"); - } - set - { - FreeImage.Resize(ref value, 2, 4); - SetTagValue("SubjectArea", value); - } - } - - /// - /// Gets or sets the actual focal length of the lens, in mm. - /// Conversion is not made to the focal length of a 35 mm film camera. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? FocalLength - { - get - { - return GetTagValue("FocalLength"); - } - set - { - SetTagValue("FocalLength", value); - } - } - - /// - /// Gets or sets the strobe energy at the time the image is captured, - /// as measured in Beam Candle Power Seconds (BCPS). - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? FlashEnergy - { - get - { - return GetTagValue("FlashEnergy"); - } - set - { - SetTagValue("FlashEnergy", value); - } - } - - /// - /// Gets or sets the camera or input device spatial frequency table and SFR values - /// in the direction of image width, image height, and diagonal direction, - /// as specified in ISO 12233. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] SpatialFrequencyResponse - { - get - { - return GetTagArray("SpatialFrequencyResponse"); - } - set - { - SetTagValueUndefined("SpatialFrequencyResponse", value); - } - } - - /// - /// Gets or sets the number of pixels in the image width (X) direction per - /// FocalPlaneResolutionUnit on the camera focal plane. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? FocalPlaneXResolution - { - get - { - return GetTagValue("FocalPlaneXResolution"); - } - set - { - SetTagValue("FocalPlaneXResolution", value); - } - } - - /// - /// Gets or sets the number of pixels in the image height (Y) direction per - /// FocalPlaneResolutionUnit on the camera focal plane. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? FocalPlaneYResolution - { - get - { - return GetTagValue("FocalPlaneYResolution"); - } - set - { - SetTagValue("FocalPlaneYResolution", value); - } - } - - /// - /// Gets or sets the unit for measuring FocalPlaneXResolution and FocalPlaneYResolution. - /// This value is the same as the ResolutionUnit. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? FocalPlaneResolutionUnit - { - get - { - return GetTagValue("FocalPlaneResolutionUnit"); - } - set - { - SetTagValue("FocalPlaneResolutionUnit", value); - } - } - - /// - /// Gets or sets the location of the main subject in the scene. - /// The value of this tag represents the pixel at the center of the main subject - /// relative to the left edge, prior to rotation processing as per the Rotation tag. - /// The first value indicates the X column number and second indicates the Y row number. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? SubjectLocation - { - get - { - return GetTagValue("SubjectLocation"); - } - set - { - SetTagValue("SubjectLocation", value); - } - } - - /// - /// Gets or sets the exposure index selected on the camera or input device at the - /// time the image was captured. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? ExposureIndex - { - get - { - return GetTagValue("ExposureIndex"); - } - set - { - SetTagValue("ExposureIndex", value); - } - } - - /// - /// Gets or sets the image sensor type on the camera or input device. - /// See remarks for further information. - /// - /// - /// The following values are defined: - /// - /// - /// ID - /// Description - /// - /// - /// 1 - /// not defined - /// - /// - /// 2 - /// one-chip color area sensor - /// - /// - /// 3 - /// two-chip color area sensor - /// - /// - /// 4 - /// three-chip color area sensor - /// - /// - /// 5 - /// color sequential area sensor - /// - /// - /// 7 - /// trilinear sensor - /// - /// - /// 8 - /// color sequential linear sensor - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? SensingMethod - { - get - { - return GetTagValue("SensingMethod"); - } - set - { - SetTagValue("SensingMethod", value); - } - } - - /// - /// Gets or sets the image source. If a DSC recorded the image, this tag value of this - /// tag always be set to 3, indicating that the image was recorded on a DSC. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte? FileSource - { - get - { - return GetTagValue("FileSource"); - } - set - { - SetTagValueUndefined("FileSource", value.HasValue ? new byte[] { value.Value } : null); - } - } - - /// - /// Gets or sets the type of scene. If a DSC recorded the image, this tag value shall - /// always be set to 1, indicating that the image was directly photographed. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte? SceneType - { - get - { - return GetTagValue("SceneType"); - } - set - { - SetTagValueUndefined("SceneType", value.HasValue ? new byte[] { value.Value } : null); - } - } - - /// - /// Gets or sets the color filter array (CFA) geometric pattern of the image sensor - /// when a one-chip color area sensor is used. It does not apply to all sensing methods. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] CFAPattern - { - get - { - return GetTagArray("CFAPattern"); - } - set - { - SetTagValueUndefined("CFAPattern", value); - } - } - - /// - /// Gets or sets the use of special processing on image data, such as rendering geared to output. - /// When special processing is performed, the reader is expected to disable or minimize any - /// further processing. See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// normal process - /// - /// - /// 1 - /// custom process - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? CustomRendered - { - get - { - return GetTagValue("CustomRendered"); - } - set - { - SetTagValue("CustomRendered", value); - } - } - - /// - /// Gets or sets the exposure mode set when the image was shot. - /// In auto-bracketing mode, the camera shoots a series of frames of the same scene - /// at different exposure settings. See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// auto exposure - /// - /// - /// 1 - /// manual exposure - /// - /// - /// 2 - /// auto bracket - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? ExposureMode - { - get - { - return GetTagValue("ExposureMode"); - } - set - { - SetTagValue("ExposureMode", value); - } - } - - /// - /// Gets or sets the white balance mode set when the image was shot. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// auto white balance - /// - /// - /// 1 - /// manual white balance - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? WhiteBalance - { - get - { - return GetTagValue("WhiteBalance"); - } - set - { - SetTagValue("WhiteBalance", value); - } - } - - /// - /// Gets or sets the digital zoom ratio when the image was shot. - /// If the numerator of the recorded value is 0, this indicates that digital zoom was not used. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? DigitalZoomRatio - { - get - { - return GetTagValue("DigitalZoomRatio"); - } - set - { - SetTagValue("DigitalZoomRatio", value); - } - } - - /// - /// Gets or sets the equivalent focal length assuming a 35mm film camera, in mm. - /// A value of 0 means the focal length is unknown. Note that this tag differs - /// from the FocalLength tag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? FocalLengthIn35mmFilm - { - get - { - return GetTagValue("DigitalZoomRatio"); - } - set - { - SetTagValue("DigitalZoomRatio", value); - } - } - - /// - /// Gets or sets the type of scene that was shot. - /// It can also be used to record the mode in which the image was shot. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// standard - /// - /// - /// 1 - /// landscape - /// - /// - /// 2 - /// portrait - /// - /// - /// 3 - /// night scene - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? SceneCaptureType - { - get - { - return GetTagValue("SceneCaptureType"); - } - set - { - SetTagValue("SceneCaptureType", value); - } - } - - /// - /// Gets or sets the degree of overall image gain adjustment. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// none - /// - /// - /// 1 - /// low gain up - /// - /// - /// 2 - /// high gain up - /// - /// - /// 3 - /// low gain down - /// - /// - /// 4 - /// high gain down - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? GainControl - { - get - { - return GetTagValue("GainControl"); - } - set - { - SetTagValue("GainControl", value); - } - } - - /// - /// Gets or sets the direction of contrast processing applied by the camera - /// when the image was shot. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// normal - /// - /// - /// 1 - /// soft - /// - /// - /// 2 - /// hard - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? Contrast - { - get - { - return GetTagValue("Contrast"); - } - set - { - SetTagValue("Contrast", value); - } - } - - /// - /// Gets or sets the direction of saturation processing applied by the camera - /// when the image was shot. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// normal - /// - /// - /// 1 - /// low saturation - /// - /// - /// 2 - /// high saturation - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? Saturation - { - get - { - return GetTagValue("Saturation"); - } - set - { - SetTagValue("Saturation", value); - } - } - - /// - /// Gets or sets the direction of sharpness processing applied by the camera - /// when the image was shot. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// normal - /// - /// - /// 1 - /// soft - /// - /// - /// 2 - /// hard - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? Sharpness - { - get - { - return GetTagValue("Sharpness"); - } - set - { - SetTagValue("Sharpness", value); - } - } - - /// - /// Gets or sets information on the picture-taking conditions of a particular camera model. - /// The tag is used only to indicate the picture-taking conditions in the reader. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] DeviceSettingDescription - { - get - { - return GetTagArray("DeviceSettingDescription"); - } - set - { - SetTagValueUndefined("DeviceSettingDescription", value); - } - } - - /// - /// Gets or sets the distance to the subject. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// unknown - /// - /// - /// 1 - /// macro - /// - /// - /// 2 - /// close view - /// - /// - /// 3 - /// distant view - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? SubjectDistanceRange - { - get - { - return GetTagValue("SubjectDistanceRange"); - } - set - { - SetTagValue("SubjectDistanceRange", value); - } - } - - /// - /// Gets or sets an identifier assigned uniquely to each image. - /// It is recorded as an ASCII string equivalent to hexadecimal notation and 128-bit fixed length. - /// Constant length of 32. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ImageUniqueID - { - get - { - string text = GetTagText("ImageUniqueID"); - if (!string.IsNullOrEmpty(text)) - { - text = text.Substring(0, text.Length - 1); - } - return text; - } - set - { - if (value != null) - { - FreeImage.Resize(ref value, 32); - value += '\0'; - } - SetTagValue("ImageUniqueID", value); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_EXIF_GPS : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_EXIF_GPS(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_GPS; } - } - - /// - /// Gets or sets the GPS version ID. Constant length of 4. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] VersionID - { - get - { - return GetTagArray("GPSVersionID"); - } - set - { - FreeImage.Resize(ref value, 4); - SetTagValue("GPSVersionID", value); - } - } - - /// - /// Gets or sets a value indicating whether the - /// is north or south latitude. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public LatitudeType? LatitudeDirection - { - get - { - return ToLatitudeType(GetTagText("GPSLatitudeRef")); - } - set - { - SetTagValue("GPSLatitudeRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the latitude of the image. The latitude is expressed as three rational - /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public FIURational[] Latitude - { - get - { - return GetTagArray("GPSLatitude"); - } - set - { - FreeImage.Resize(ref value, 3); - SetTagValue("GPSLatitude", value); - } - } - - /// - /// Gets or sets a value indicating whether - /// is east or west longitude. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public LongitudeType? LongitudeDirection - { - get - { - return ToLongitudeType(GetTagText("GPSLongitudeRef")); - } - set - { - SetTagValue("GPSLongitudeRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the longitude of the image. The longitude is expressed as three rational - /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public FIURational[] Longitude - { - get - { - return GetTagArray("GPSLongitude"); - } - set - { - FreeImage.Resize(ref value, 3); - SetTagValue("GPSLongitude", value); - } - } - - /// - /// Gets a value indicating whether is sea level and the altitude - /// is above sea level. If the altitude is below sea level is - /// indicated as an absolute value. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public AltitudeType? AltitudeDirection - { - get - { - byte? flag = GetTagValue("GPSAltitudeRef"); - if (flag.HasValue) - { - switch (flag.Value) - { - case 0: - return AltitudeType.AboveSeaLevel; - case 1: - return AltitudeType.BelowSeaLevel; - default: - return AltitudeType.Undefined; - } - } - return null; - } - set - { - byte? val = null; - if (value.HasValue) - { - switch (value.Value) - { - case AltitudeType.AboveSeaLevel: - val = 0; - break; - - case AltitudeType.BelowSeaLevel: - val = 1; - break; - - default: - val = 2; - break; - } - } - SetTagValue("GPSAltitudeRef", val); - } - } - - /// - /// Gets or sets the altitude based on the reference in . - /// Altitude is expressed as one rational value. The reference unit is meters. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? Altitude - { - get - { - return GetTagValue("GPSAltitude"); - } - set - { - SetTagValue("GPSAltitude", value); - } - } - - /// - /// Gets or sets the sign of the . - /// - /// - /// This is a derived property. There is no metadata tag directly associated - /// with this property value. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public int? AltitudeSign - { - get - { - AltitudeType? seaLevel = AltitudeDirection; - if (seaLevel.HasValue) - { - return (seaLevel.Value == AltitudeType.BelowSeaLevel) ? -1 : 1; - } - return null; - } - set - { - if (value.HasValue) - { - AltitudeDirection = value.Value >= 0 ? AltitudeType.AboveSeaLevel : AltitudeType.BelowSeaLevel; - } - else - { - AltitudeDirection = null; - } - } - } - - /// - /// Gets or sets the signed altitude. - /// Altitude is expressed as one rational value. The reference unit is meters. - /// - /// - /// Altitude is too large to fit into a FIRational. - /// - /// - /// This is a derived property. There is no metadata tag directly associated - /// with this property value. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public FIRational? SignedAltitude - { - get - { - FIRational? result = null; - FIURational? altitude = Altitude; - if (altitude.HasValue) - { - int sign = AltitudeSign ?? 1; - if (((int)altitude.Value.Numerator < 0) || ((int)altitude.Value.Denominator < 0)) - throw new OverflowException(); - result = new FIRational((int)altitude.Value.Numerator * sign, (int)altitude.Value.Denominator); - } - return result; - } - set - { - FIURational? val = null; - if (value.HasValue) - { - if (value.Value < 0) - { - AltitudeSign = -1; - value = -value.Value; - } - else - { - AltitudeSign = 1; - } - val = new FIURational((uint)value.Value.Numerator, (uint)value.Value.Denominator); - } - Altitude = val; - } - } - - - /// - /// Gets or sets the time as UTC (Coordinated Universal Time). Constant length of 3. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public TimeSpan? TimeStamp - { - get - { - FIURational[] stamp = GetTagArray("GPSTimeStamp"); - if ((stamp == null) || stamp.Length != 3) - { - return null; - } - else - { - return new TimeSpan((int)stamp[0], (int)stamp[1], (int)stamp[2]); - } - } - set - { - FIURational[] stamp = null; - if (value.HasValue) - { - TimeSpan span = value.Value; - stamp = new FIURational[3]; - stamp[0] = span.Hours; - stamp[1] = span.Minutes; - stamp[2] = span.Seconds; - } - SetTagValue("GPSTimeStamp", stamp); - } - } - - /// - /// Gets or sets the GPS satellites used for measurements. This tag can be used to describe - /// the number of satellites, their ID number, angle of elevation, azimuth, SNR and other - /// information in ASCII notation. The format is not specified. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Satellites - { - get - { - string result = GetTagText("GPSSatellites"); - if (!string.IsNullOrEmpty(result)) - { - result = result.Substring(0, result.Length - 1); - } - return result; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("GPSTimeStamp", value); - } - } - - /// - /// Gets or sets a value indicating the status of the GPS receiver when the image was recorded. - /// true indicates measurement was in progress; - /// false indicates measurement was Interoperability. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public bool? Status - { - get - { - string text = GetTagText("GPSStatus"); - return string.IsNullOrEmpty(text) ? default(bool?) : text[0] == 'A'; - } - set - { - SetTagValue("GPSStatus", value.HasValue ? (value.Value ? "A\0" : "V\0") : null); - } - } - - /// - /// Gets or sets a value indicating the GPS measurement mode. - /// true indicates three-dimensional measurement; - /// false indicated two-dimensional measurement was in progress. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public bool? MeasureMode3D - { - get - { - string text = GetTagText("GPSMeasureMode"); - return string.IsNullOrEmpty(text) ? default(bool?) : text[0] == '3'; - } - set - { - SetTagValue("GPSMeasureMode", value.HasValue ? (value.Value ? "3\0" : "2\0") : null); - } - } - - /// - /// Gets or sets the GPS DOP (data degree of precision). An HDOP value is written during - /// two-dimensional measurement, and PDOP during three-dimensional measurement. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? DOP - { - get - { - return GetTagValue("GPSDOP"); - } - set - { - SetTagValue("GPSDOP", value); - } - } - - /// - /// Gets or sets the unit used to express the GPS receiver of movement. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public VelocityUnit? SpeedUnit - { - get - { - return ToUnitType(GetTagText("GPSSpeedRef")); - } - set - { - SetTagValue("GPSSpeedRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the speed of GPS receiver movement. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public FIURational? Speed - { - get - { - return GetTagValue("GPSSpeed"); - } - set - { - SetTagValue("GPSSpeed", value); - } - } - - /// - /// Gets or sets the reference for giving the direction of GPS receiver movement. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public DirectionReference? TrackDirectionReference - { - get - { - return ToDirectionType(GetTagText("GPSTrackRef")); - } - set - { - SetTagValue("GPSTrackRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the direction of GPS receiver movement. - /// The range of values is from 0.00 to 359.99. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public FIURational? Track - { - get - { - return GetTagValue("GPSTrack"); - } - set - { - SetTagValue("GPSTrack", value); - } - } - - /// - /// Gets or sets the reference for giving the direction of GPS receiver movement. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public DirectionReference? ImageDirectionReference - { - get - { - return ToDirectionType(GetTagText("GPSImgDirectionRef")); - } - set - { - SetTagValue("GPSImgDirectionRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the direction of the image when it was captured. - /// The range of values is from 0.00 to 359.99. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public FIURational? ImageDirection - { - get - { - return GetTagValue("GPSImgDirection"); - } - set - { - SetTagValue("GPSImgDirection", value); - } - } - - /// - /// Gets or sets the geodetic survey data used by the GPS receiver. If the survey data - /// is restricted to Japan, the value of this tag is 'TOKYO' or 'WGS-84'. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string MapDatum - { - get - { - string result = GetTagText("GPSMapDatum"); - if (!string.IsNullOrEmpty(result)) - { - result = result.Substring(0, result.Length - 1); - } - return result; - } - set - { - SetTagValue("GPSMapDatum", value + '\0'); - } - } - - /// - /// Gets or sets a value indicating whether the destination point - /// is north or south latitude. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public LatitudeType? DestinationLatitudeDirection - { - get - { - return ToLatitudeType(GetTagText("GPSDestLatitudeRef")); - } - set - { - SetTagValue("GPSDestLatitudeRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the latitude of the destination point. The latitude is expressed as three rational - /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public FIURational[] DestinationLatitude - { - get - { - return GetTagArray("GPSDestLatitude"); - } - set - { - FreeImage.Resize(ref value, 3); - SetTagValue("GPSDestLatitude", value); - } - } - - /// - /// Gets or sets a value indicating whether the destination point - /// is east or west longitude. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public LongitudeType? DestinationLongitudeDirection - { - get - { - return ToLongitudeType(GetTagText("GPSDestLongitudeRef")); - } - set - { - SetTagValue("GPSDestLongitudeRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the longitude of the destination point. The longitude is expressed as three rational - /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational[] DestinationLongitude - { - get - { - return GetTagArray("GPSDestLongitude"); - } - set - { - FreeImage.Resize(ref value, 3); - SetTagValue("GPSDestLongitude", value); - } - } - - /// - /// Gets or sets the reference used for giving the bearing to the destination point. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public DirectionReference? DestinationDirectionReference - { - get - { - return ToDirectionType(GetTagText("GPSDestBearingRef")); - } - set - { - SetTagValue("GPSDestBearingRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the bearing to the destination point. - /// The range of values is from 0.00 to 359.99. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public FIURational? DestinationBearing - { - get - { - return GetTagValue("GPSDestBearing"); - } - set - { - SetTagValue("GPSDestBearing", value); - } - } - - /// - /// Gets or sets the unit used to express the distance to the destination point. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public VelocityUnit? DestinationUnit - { - get - { - return ToUnitType(GetTagText("GPSDestDistanceRef")); - } - set - { - SetTagValue("GPSDestDistanceRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets a character string recording the name of the method used - /// for location finding. The first byte indicates the character code used, - /// and this is followed by the name of the method. Since the Type is not ASCII, - /// NULL termination is not necessary. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] ProcessingMethod - { - get - { - return GetTagArray("GPSProcessingMethod"); - } - set - { - SetTagValue("GPSProcessingMethod", value); - } - } - - /// - /// Gets or sets a character string recording the name of the GPS area. - /// The first byte indicates the character code used, and this is followed by - /// the name of the GPS area. Since the Type is not ASCII, NULL termination is - /// not necessary. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] AreaInformation - { - get - { - return GetTagArray("GPSAreaInformation"); - } - set - { - SetTagValue("GPSAreaInformation", value); - } - } - - /// - /// Gets or sets date and time information relative to UTC (Coordinated Universal Time). - /// - /// - /// This is a derived property. There is no metadata tag directly associated - /// with this property value. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public DateTime? DateTimeStamp - { - get - { - DateTime? date = DateStamp; - TimeSpan? time = TimeStamp; - if ((date == null) && (time == null)) - { - return null; - } - else - { - if (date == null) - { - date = DateTime.MinValue; - } - if (time == null) - { - time = TimeSpan.MinValue; - } - return date.Value.Add(time.Value); - } - } - set - { - if (value.HasValue) - { - DateStamp = value.Value.Date; - TimeStamp = value.Value.TimeOfDay; - } - else - { - DateStamp = null; - TimeStamp = null; - } - } - } - - /// - /// Gets or sets date information relative to UTC (Coordinated Universal Time). - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public DateTime? DateStamp - { - get - { - string stamp = GetTagText("GPSDateStamp"); - if (stamp != null) - { - try - { - return DateTime.ParseExact(stamp, "yyyy:MM:dd\0", null); - } - catch - { - } - } - return null; - } - set - { - string val = null; - if (value.HasValue) - { - try - { - val = value.Value.ToString("yyyy:MM:dd\0"); - } - catch - { - } - } - SetTagValue("GPSDateStamp", val); - } - } - - /// - /// Gets or sets a value indicating whether differential correction was applied to - /// the GPS receiver. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public bool? IsDifferential - { - get - { - ushort? value = GetTagValue("GPSDifferential"); - return value.HasValue ? (value != 0) : (default(bool?)); - } - set - { - SetTagValue("GPSDifferential", value.HasValue ? (object)(value.Value ? (ushort)1 : (ushort)0) : (null)); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_INTEROP : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_INTEROP(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_INTEROP; } - } - - /// - /// Gets or sets the identification of the Interoperability rule. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public InteroperabilityMode? Identification - { - get - { - return ToInteroperabilityType(GetTagText("InteroperabilityIndex")); - } - set - { - SetTagValue("InteroperabilityIndex", ToString(value) + '\0'); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - /// This class is obsolete. Use class instead. - /// - [Obsolete("To be removed in future releases. Use MDM_EXIF_MAIN instead.")] - public class MDM_MAIN : MDM_EXIF_MAIN - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_MAIN(FIBITMAP dib) : base(dib) { } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_EXIF_MAIN : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_EXIF_MAIN(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN; } - } - - /// - /// Gets or sets the number of columns of image data, equal to the number - /// of pixels per row. In JPEG compressed data a JPEG marker is used - /// instead of this tag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? ImageWidth - { - get - { - return GetUInt32Value("ImageWidth"); - } - set - { - RemoveTag("ImageWidth"); - if (value.HasValue) - { - SetTagValue("ImageWidth", value); - } - } - } - - /// - /// Gets or sets number of rows of image data. In JPEG compressed data a JPEG marker - /// is used instead of this tag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? ImageHeight - { - get - { - return GetUInt32Value("ImageLength"); - } - set - { - RemoveTag("ImageLength"); - if (value.HasValue) - { - SetTagValue("ImageLength", value); - } - } - } - - /// - /// Gets or sets number of bits per image component. In this standard - /// each component of the image is 8 bits, so the value for this tag is 8. - /// Constant length of 3. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort[] BitsPerSample - { - get - { - return GetTagArray("BitsPerSample"); - } - set - { - FreeImage.Resize(ref value, 3); - SetTagValue("BitsPerSample", value); - } - } - - /// - /// Gets or sets compression scheme used for the image data. When a primary image - /// is JPEG compressed, this designation is not necessary and is omitted. - /// When thumbnails use JPEG compression, this tag value is set to 6. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? Compression - { - get - { - return GetTagValue("Compression"); - } - set - { - SetTagValue("Compression", value); - } - } - - /// - /// Gets or sets pixel composition. In JPEG compressed data a JPEG marker is - /// used instead of this tag. See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 2 - /// RGB - /// - /// - /// 6 - /// YCbCr - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? PhotometricInterpretation - { - get - { - return GetTagValue("PhotometricInterpretation"); - } - set - { - SetTagValue("PhotometricInterpretation", value); - } - } - - /// - /// Gets or sets the image orientation viewed in terms of rows and columns. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ExifImageOrientation? Orientation - { - get - { - return (ExifImageOrientation?)GetTagValue("Orientation"); - } - set - { - SetTagValue("Orientation", (ushort?)value); - } - } - - /// - /// Gets or sets the number of components per pixel. Since this standard applies - /// to RGB and YCbCr images, the value set for this tag is 3. In JPEG compressed - /// data a JPEG marker is used instead of this tag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? SamplesPerPixel - { - get - { - return GetTagValue("SamplesPerPixel"); - } - set - { - SetTagValue("SamplesPerPixel", value); - } - } - - /// - /// Gets or sets a value that indicates whether pixel components are recorded in - /// chunky or planar format. In JPEG compressed files a JPEG marker is used instead - /// of this tag. If this field does not exist, the TIFF default of 1 (chunky) is assumed. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 1 - /// chunky format - /// - /// - /// 2 - /// planar format - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? PlanarConfiguration - { - get - { - return GetTagValue("PlanarConfiguration"); - } - set - { - SetTagValue("PlanarConfiguration", value); - } - } - - /// - /// Gets or sets the sampling ratio of chrominance components in relation to - /// the luminance component. In JPEG compressed dat a JPEG marker is used - /// instead of this tag. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// [2,1] - /// YCbCr4:2:2 - /// - /// - /// [2,2] - /// YCbCr4:2:0 - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort[] YCbCrSubSampling - { - get - { - return GetTagArray("YCbCrSubSampling"); - } - set - { - FreeImage.Resize(ref value, 2); - SetTagValue("YCbCrSubSampling", value); - } - } - - /// - /// Gets or sets position of chrominance components in relation to the luminance component. - /// See remarks for further information. - /// - /// - /// This field is designated only for JPEG compressed data or uncompressed YCbCr data. - /// The TIFF default is 1 (centered); but when Y:Cb:Cr = 4:2:2 it is recommended in - /// this standard that 2 (co-sited) be used to record data, in order to improve the - /// image quality when viewed on TV systems. - /// - /// When this field does not exist, the reader shall assume the TIFF default. - /// In the case of Y:Cb:Cr = 4:2:0, the TIFF default (centered) is recommended. - /// If the reader does not have the capability of supporting both kinds of YCbCrPositioning, - /// it shall follow the TIFF default regardless of the value in this field. - /// It is preferable that readers be able to support both centered and co-sited positioning. - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 1 - /// centered - /// - /// - /// 2 - /// co-sited - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? YCbCrPositioning - { - get - { - return GetTagValue("YCbCrPositioning"); - } - set - { - SetTagValue("YCbCrPositioning", value); - } - } - - /// - /// Gets or sets the number of pixels per - /// in the direction. When the image resolution is unknown, - /// 72 [dpi] is designated. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? XResolution - { - get - { - return GetTagValue("XResolution"); - } - set - { - SetTagValue("XResolution", value); - } - } - - /// - /// Gets or sets the number of pixels per - /// in the direction. When the image resolution is unknown, - /// 72 [dpi] is designated. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? YResolution - { - get - { - return GetTagValue("YResolution"); - } - set - { - SetTagValue("YResolution", value); - } - } - - /// - /// Gets or sets the unit for measuring and . - /// The same unit is used for both and . - /// If the image resolution in unknown, 2 (inches) is designated. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 2 - /// inches - /// - /// - /// 3 - /// YCbCr4:2:0 - /// - /// - /// other - /// centimeters - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? ResolutionUnit - { - get - { - return GetTagValue("ResolutionUnit"); - } - set - { - SetTagValue("ResolutionUnit", value); - } - } - - /// - /// Gets or sets the byte offset of that strip. - /// It is recommended that this be selected so the number of strip bytes - /// does not exceed 64 Kbytes. - /// With JPEG compressed data this designation is not needed and is omitted. - /// Constant length of * StripsPerImage. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - /// - public uint[] StripOffsets - { - get - { - return GetUInt32Array("StripOffsets"); - } - set - { - RemoveTag("StripOffsets"); - if (value != null) - { - SetTagValue("StripOffsets", value); - } - } - } - - /// - /// Gets or sets number of rows per strip. This is the number of rows in the image of - /// one strip when an image is divided into strips. With JPEG compressed data this - /// designation is not needed and is omitted. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public uint? RowsPerStrip - { - get - { - return GetUInt32Value("RowsPerStrip"); - } - set - { - RemoveTag("RowsPerStrip"); - if (value.HasValue) - { - SetTagValue("RowsPerStrip", value); - } - } - } - - /// - /// Gets or sets the total number of bytes in each strip. - /// With JPEG compressed data this designation is not needed and is omitted. - /// Constant length of * StripsPerImage. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint[] StripByteCounts - { - get - { - return GetUInt32Array("StripByteCounts"); - } - set - { - RemoveTag("StripByteCounts"); - if (value != null) - { - SetTagValue("StripByteCounts", value); - } - } - } - - /// - /// Gets or sets the offset to the start byte (SOI) of JPEG compressed thumbnail data. - /// This is not used for primary image JPEG data. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? JPEGInterchangeFormat - { - get - { - return GetTagValue("JPEGInterchangeFormat"); - } - set - { - SetTagValue("JPEGInterchangeFormat", value); - } - } - - /// - /// Gets or sets the number of bytes of JPEG compressed thumbnail data. - /// - /// - /// This is not used for primary image JPEG data. - /// JPEG thumbnails are not divided but are recorded as a continuous - /// JPEG bitstream from SOI to EOI. APPn and COM markers should not be recorded. - /// Compressed thumbnails shall be recorded in no more than 64 Kbytes, - /// including all other data to be recorded in APP1. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public uint? JPEGInterchangeFormatLength - { - get - { - return GetTagValue("JPEGInterchangeFormatLength"); - } - set - { - SetTagValue("JPEGInterchangeFormatLength", value); - } - } - - /// - /// Gets or sets a transfer function for the image, described in tabular style. - /// Constant length of 3 * 256. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort[] TransferFunction - { - get - { - return GetTagArray("TransferFunction"); - } - set - { - FreeImage.Resize(ref value, 3 * 256); - SetTagValue("TransferFunction", value); - } - } - - /// - /// Gets or sets the chromaticity of the white point of the image. - /// Constant length of 2. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational[] WhitePoint - { - get - { - return GetTagArray("WhitePoint"); - } - set - { - FreeImage.Resize(ref value, 2); - SetTagValue("WhitePoint", value); - } - } - - /// - /// Gets or sets the chromaticity of the three primary colors of the image. - /// Constant length of 6. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational[] PrimaryChromaticities - { - get - { - return GetTagArray("PrimaryChromaticities"); - } - set - { - FreeImage.Resize(ref value, 6); - SetTagValue("PrimaryChromaticities", value); - } - } - - /// - /// Gets or sets the matrix coefficients for transformation from RGB to YCbCr image data. - /// Constant length of 3. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational[] YCbCrCoefficients - { - get - { - return GetTagArray("YCbCrCoefficients"); - } - set - { - FreeImage.Resize(ref value, 3); - SetTagValue("PrimaryChromaticities", value); - } - } - - /// - /// Gets or sets the reference black point value and reference white point value. - /// Constant length of 6. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational[] ReferenceBlackWhite - { - get - { - return GetTagArray("ReferenceBlackWhite"); - } - set - { - FreeImage.Resize(ref value, 6); - SetTagValue("ReferenceBlackWhite", value); - } - } - - /// - /// Gets or sets the date and time of image creation. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public DateTime? DateTime - { - get - { - DateTime? result = null; - string text = GetTagText("DateTime"); - if (text != null) - { - try - { - result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null); - } - catch - { - } - } - return result; - } - set - { - string val = null; - if (value.HasValue) - { - try - { - val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0"); - } - catch - { - } - } - SetTagValue("DateTime", val); - } - } - - /// - /// Gets or sets a string giving the title of the image. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ImageDescription - { - get - { - string result = GetTagText("ImageDescription"); - if (!string.IsNullOrEmpty(result)) - { - result = result.Substring(0, result.Length - 1); - } - return result; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("ImageDescription", value); - } - } - - /// - /// Gets or sets the manufacturer of the recording equipment. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Make - { - get - { - string result = GetTagText("Make"); - if (!string.IsNullOrEmpty(result)) - { - result = result.Substring(0, result.Length - 1); - } - return result; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("Make", value); - } - } - - /// - /// Gets or sets the model name or model number of the equipment. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string EquipmentModel - { - get - { - string result = GetTagText("Model"); - if (!string.IsNullOrEmpty(result)) - { - result = result.Substring(0, result.Length - 1); - } - return result; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("Model", value); - } - } - - /// - /// Gets or sets the name and version of the software or firmware of the camera - /// or image input device used to generate the image. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Software - { - get - { - string result = GetTagText("Software"); - if (!string.IsNullOrEmpty(result)) - { - result = result.Substring(0, result.Length - 1); - } - return result; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("Software", value); - } - } - - /// - /// Gets or sets the name of the camera owner, photographer or image creator. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Artist - { - get - { - string result = GetTagText("Artist"); - if (!string.IsNullOrEmpty(result)) - { - result = result.Substring(0, result.Length - 1); - } - return result; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("Artist", value); - } - } - - /// - /// Gets or sets the photographer and editor copyrights. - /// Constant length of 1-2. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string[] Copyright - { - get - { - string[] result = null; - string text = GetTagText("Copyright"); - if (!string.IsNullOrEmpty(text)) - { - result = text.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); - } - return result; - } - set - { - string val = null; - if (value != null) - { - if (value.Length == 1) - { - if (value[0] != null) - { - val = value[0] + '\0'; - } - } - else if (value.Length == 2) - { - if ((value[0] != null) && (value[1] != null)) - { - val = value[0] + '\0' + value[1] + '\0'; - } - } - } - SetTagValue("Copyright", val); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_MAKERNOTE : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_MAKERNOTE(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_MAKERNOTE; } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_GEOTIFF : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_GEOTIFF(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_GEOTIFF; } - } - - /// - /// Gets or sets the value of the GeoTIFF GeoASCIIParamsTag. - /// - /// - /// The GeoASCIIParamsTag is used to store all of the valued - /// GeoKeys, referenced by the property. Since keys - /// defined in the GeoKeyDirectoryTag use offsets into this tag, any special - /// comments may be placed at the beginning of this tag. - /// For the most part, the only keys that are valued are - /// Citation keys, giving documentation and references for obscure - /// projections, datums, etc. - /// - /// Special handling is required for -valued keys. While it - /// is true that TIFF 6.0 permits multiple NULL-delimited strings within a single - /// ASCII tag, the secondary strings might not appear in the output of naive - /// tiffdump programs. For this reason, the NULL delimiter of each ASCII key - /// value shall be converted to a "|" (pipe) character before being installed - /// back into the holding tag, so that a dump of the tag - /// will look like this. - /// - /// AsciiTag="first_value|second_value|etc...last_value|" - /// - /// A baseline GeoTIFF-reader must check for and convert the final "|" pipe - /// character of a key back into a NULL before returning it to the client - /// software. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public string GeoASCIIParams - { - get - { - string text = GetTagText("GeoASCIIParams"); - if (!string.IsNullOrEmpty(text)) - { - text = text.Substring(0, text.Length - 1); - } - return text; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("GeoASCIIParams", value); - } - } - - /// - /// Gets or sets the value of the GeoTIFF GeoDoubleParamsTag. - /// - /// - /// The GeoDoubleParamsTag is used to store all of the valued - /// GeoKeys, referenced by the property. The meaning of - /// any value of this double array is determined from the GeoKeyDirectoryTag reference - /// pointing to it. values should first be converted to - /// and stored here. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public double[] GeoDoubleParams - { - get - { - return GetTagArray("GeoDoubleParams"); - } - set - { - SetTagValue("GeoDoubleParams", value); - } - } - - /// - /// Gets or sets the value of the GeoTIFF GeoKeyDirectoryTag. - /// - /// - /// The GeoKeyDirectoryTag may be used to store the GeoKey Directory, which defines and - /// references the GeoKeys. - /// - /// The tag is an array of unsigned values, which are primarily - /// grouped into blocks of 4. The first 4 values are special, and contain GeoKey directory - /// header information. The header values consist of the following information, in order: - /// - /// Header={KeyDirectoryVersion, KeyRevision, MinorRevision, NumberOfKeys} - /// - /// where - /// - /// KeyDirectoryVersion indicates the current version of Key implementation, and will - /// only change if this Tag's Key structure is changed. (Similar to the TIFFVersion (42)). - /// The current DirectoryVersion number is 1. This value will most likely never change, - /// and may be used to ensure that this is a valid Key-implementation. - /// - /// KeyRevision indicates what revision of Key-Sets are used. - /// - /// MinorRevision indicates what set of Key-Codes are used. The complete revision number - /// is denoted <KeyRevision>.<MinorRevision>. - /// - /// NumberOfKeys indicates how many Keys are defined by the rest of this Tag. - /// - /// This header is immediately followed by a collection of <NumberOfKeys> KeyEntry - /// sets, each of which is also 4- long. Each KeyEntry is modeled on the - /// TIFFEntry format of the TIFF directory header, and is of the form: - /// - /// KeyEntry = { KeyID, TIFFTagLocation, Count, Value_Offset } - /// - /// where - /// - /// KeyID gives the Key-ID value of the Key (identical in function to TIFF tag ID, - /// but completely independent of TIFF tag-space), - /// - /// TIFFTagLocation indicates which TIFF tag contains the value(s) of the Key: if - /// TIFFTagLocation is 0, then the value is , and is contained in the - /// Value_Offset entry. Otherwise, the type (format) of the value is implied by the - /// TIFF-Type of the tag containing the value. - /// - /// Count indicates the number of values in this key. - /// - /// Value_Offset Value_Offset indicates the index-offset into the TagArray indicated - /// by TIFFTagLocation, if it is nonzero. If TIFFTagLocation is 0 (zero) , then Value_Offset - /// contains the actual () value of the Key, and Count=1 is implied. - /// Note that the offset is not a byte-offset, but rather an index based on the natural data - /// type of the specified tag array. - /// - /// Following the KeyEntry definitions, the KeyDirectory tag may also contain additional - /// values. For example, if a key requires multiple values, they shall - /// be placed at the end of this tag, and the KeyEntry will set - /// TIFFTagLocation=GeoKeyDirectoryTag, with the Value_Offset pointing to the location of the - /// value(s). - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort[] GeoKeyDirectory - { - get - { - return GetTagArray("GeoKeyDirectory"); - } - set - { - SetTagValue("GeoKeyDirectory", value); - } - } - - /// - /// Gets or sets the value of the GeoTIFF ModelPixelScaleTag. - /// - /// - /// The ModelPixelScaleTag tag may be used to specify the size of raster pixel spacing - /// in the model space units, when the raster space can be embedded in the model space - /// coordinate system without rotation, and consists of the following 3 values: - /// - /// ModelPixelScaleTag = (ScaleX, ScaleY, ScaleZ) - /// - /// where ScaleX and ScaleY give the horizontal and vertical spacing of - /// raster pixels. The ScaleZ is primarily used to map the pixel value of a - /// digital elevation model into the correct Z-scale, and so for most other purposes - /// this value should be zero (since most model spaces are 2-D, with Z=0). - /// - /// A single tiepoint in the tag, together with this tag, - /// completely determine the relationship between raster and model space; thus they - /// comprise the two tags which Baseline GeoTIFF files most often will use to place a - /// raster image into a "standard position" in model space. - /// - /// Like the tag, this tag information is independent of the - /// XPosition, YPosition, Resolution and Orientation tags of the standard TIFF 6.0 spec. - /// However, simple reversals of orientation between raster and model space - /// (e.g. horizontal or vertical flips) may be indicated by reversal of sign in the - /// corresponding component of the ModelPixelScaleTag. GeoTIFF compliant readers must - /// honor this signreversal convention. - /// - /// This tag must not be used if the raster image requires rotation or shearing to place - /// it into the standard model space. In such cases the transformation shall be defined - /// with the more general . - /// - ///
    Naming differences - /// In the native FreeImage library and thus, in the FreeImage API documentation, this - /// property's key is named GeoPixelScale. Since the GeoTIFF specification - /// as well as Java's EXIFTIFFTagSet class call this tag - /// , this property was renamed accordingly. - /// However, when accessing this property's tag by its object, - /// the native FreeImage tag key GeoPixelScale must be used. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public double[] ModelPixelScale - { - get - { - return GetTagArray("GeoPixelScale"); - } - set - { - SetTagValue("GeoPixelScale", value); - } - } - - /// - /// Gets or sets the value of the GeoTIFF GeoTiePointsTag. - /// - /// - /// The GeoTiePointsTag stores raster -> model tiepoint pairs in the order - /// - /// ModelTiePoints = (...,I,J,K, X,Y,Z...), - /// - /// where (I,J,K) is the point at location (I,J) in raster space with - /// pixel-value K, and (X,Y,Z) is a vector in model space. In most cases - /// the model space is only two-dimensional, in which case both K and Z should be set - /// to zero; this third dimension is provided in anticipation of future support for 3D - /// digital elevation models and vertical coordinate systems. - /// - /// A raster image may be georeferenced simply by specifying its location, size and - /// orientation in the model coordinate space M. This may be done by specifying the - /// location of three of the four bounding corner points. However, tiepoints are only - /// to be considered exact at the points specified; thus defining such a set of - /// bounding tiepoints does not imply that the model space locations of the interior - /// of the image may be exactly computed by a linear interpolation of these tiepoints. - /// - /// However, since the relationship between the Raster space and the model space will - /// often be an exact, affine transformation, this relationship can be defined using - /// one set of tiepoints and the , described below, which - /// gives the vertical and horizontal raster grid cell size, specified in model units. - /// - /// If possible, the first tiepoint placed in this tag shall be the one establishing - /// the location of the point (0,0) in raster space. However, if this is not possible - /// (for example, if (0,0) is goes to a part of model space in which the projection is - /// ill-defined), then there is no particular order in which the tiepoints need be - /// listed. - /// - /// For orthorectification or mosaicking applications a large number of tiepoints may - /// be specified on a mesh over the raster image. However, the definition of associated - /// grid interpolation methods is not in the scope of the current GeoTIFF spec. - /// - ///
    Naming differences - /// In the native FreeImage library and thus, in the FreeImage API documentation, this - /// property's key is named GeoTiePoints. Since the GeoTIFF specification - /// as well as Java's EXIFTIFFTagSet class call this tag - /// , this property was renamed accordingly. - /// However, when accessing this property's tag by its object, - /// the native FreeImage tag key GeoTiePoints must be used. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public double[] ModelTiePoints - { - get - { - return GetTagArray("GeoTiePoints"); - } - set - { - SetTagValue("GeoTiePoints", value); - } - } - - /// - /// Gets or sets the value of the GeoTIFF ModelTransformationMatrixTag. - /// - /// - /// This tag may be used to specify the transformation matrix between the raster space - /// (and its dependent pixel-value space) and the (possibly 3D) model space. - /// - ///
    Naming differences - /// In the native FreeImage library and thus, in the FreeImage API documentation, this - /// property's key is named GeoTransformationMatrix. Since the GeoTIFF specification - /// as well as Java's EXIFTIFFTagSet class call this tag - /// , this property was renamed accordingly. - /// However, when accessing this property's tag by its object, - /// the native FreeImage tag key GeoTransformationMatrix must be used. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public double[] ModelTransformationMatrix - { - get - { - return GetTagArray("GeoTransformationMatrix"); - } - set - { - SetTagValue("GeoTransformationMatrix", value); - } - } - - /// - /// Gets or sets the value of the GeoTIFF IntergraphTransformationMatrixTag. - /// - /// - /// The IntergraphTransformationMatrixTag conflicts with an internal software implementation - /// at Intergraph, and so its use is no longer encouraged. A GeoTIFF reader should look first - /// for the new tag, and only if it is not found should it check for this older tag. If found, - /// it should only consider it to be contain valid GeoTIFF matrix information if the tag-count - /// is 16; the Intergraph version uses 17 values. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public double[] IntergraphTransformationMatrix - { - get - { - return GetTagArray("Intergraph TransformationMatrix"); - } - set - { - SetTagValue("Intergraph TransformationMatrix", value); - } - } - - /// - /// Gets or sets the value of the GeoTIFF JPLCartoIFDOffsetTag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? JPLCartoIFDOffset - { - get - { - return GetTagValue("JPL Carto IFD offset"); - } - set - { - SetTagValue("JPL Carto IFD offset", value); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_IPTC : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_IPTC(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_IPTC; } - } - - /// - /// Gets the Application Record Version. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public short? ApplicationRecordVersion - { - get - { - return GetTagValue("ApplicationRecordVersion"); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Object Type Reference. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ObjectTypeReference - { - get - { - return GetTagText("ObjectTypeReference"); - } - set - { - SetTagValue("ObjectTypeReference", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Object Attribute Reference. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ObjectAttributeReference - { - get - { - return GetTagText("ObjectAttributeReference"); - } - set - { - SetTagValue("ObjectAttributeReference", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Object Name. - /// This is also referred to as Title. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ObjectName - { - get - { - return GetTagText("ObjectName"); - } - set - { - SetTagValue("ObjectName", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Edit Status. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string EditStatus - { - get - { - return GetTagText("EditStatus"); - } - set - { - SetTagValue("EditStatus", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Editorial Update. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string EditorialUpdate - { - get - { - return GetTagText("EditorialUpdate"); - } - set - { - SetTagValue("EditorialUpdate", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Urgency. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Urgency - { - get - { - return GetTagText("Urgency"); - } - set - { - SetTagValue("Urgency", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Subject Reference. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SubjectReference - { - get - { - return GetTagText("SubjectReference"); - } - set - { - SetTagValue("SubjectReference", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Category. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Category - { - get - { - return GetTagText("Category"); - } - set - { - SetTagValue("Category", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Supplemental Categories. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SupplementalCategories - { - get - { - return GetTagText("SupplementalCategories"); - } - set - { - SetTagValue("SupplementalCategories", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Fixture Identifier. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string FixtureIdentifier - { - get - { - return GetTagText("FixtureIdentifier"); - } - set - { - SetTagValue("FixtureIdentifier", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Keywords. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Keywords - { - get - { - return GetTagText("Keywords"); - } - set - { - SetTagValue("Keywords", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Content Location Code. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ContentLocationCode - { - get - { - return GetTagText("ContentLocationCode"); - } - set - { - SetTagValue("ContentLocationCode", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Content Location Name. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ContentLocationName - { - get - { - return GetTagText("ContentLocationName"); - } - set - { - SetTagValue("ContentLocationName", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Release Date. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ReleaseDate - { - get - { - return GetTagText("ReleaseDate"); - } - set - { - SetTagValue("ReleaseDate", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Release Time. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ReleaseTime - { - get - { - return GetTagText("ReleaseTime"); - } - set - { - SetTagValue("ReleaseTime", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Expiration Date. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ExpirationDate - { - get - { - return GetTagText("ExpirationDate"); - } - set - { - SetTagValue("ExpirationDate", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Expiration Time. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ExpirationTime - { - get - { - return GetTagText("ExpirationTime"); - } - set - { - SetTagValue("ExpirationTime", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Special Instructions. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SpecialInstructions - { - get - { - return GetTagText("SpecialInstructions"); - } - set - { - SetTagValue("SpecialInstructions", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Action Advised. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ActionAdvised - { - get - { - return GetTagText("ActionAdvised"); - } - set - { - SetTagValue("ActionAdvised", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Reference Service. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ReferenceService - { - get - { - return GetTagText("ReferenceService"); - } - set - { - SetTagValue("ReferenceService", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Reference Date. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ReferenceDate - { - get - { - return GetTagText("ReferenceDate"); - } - set - { - SetTagValue("ReferenceDate", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Reference Number. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ReferenceNumber - { - get - { - return GetTagText("ReferenceNumber"); - } - set - { - SetTagValue("ReferenceNumber", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Date Created. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string DateCreated - { - get - { - return GetTagText("DateCreated"); - } - set - { - SetTagValue("DateCreated", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Time Created. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string TimeCreated - { - get - { - return GetTagText("TimeCreated"); - } - set - { - SetTagValue("TimeCreated", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Digital Creation Date. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string DigitalCreationDate - { - get - { - return GetTagText("DigitalCreationDate"); - } - set - { - SetTagValue("DigitalCreationDate", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Digital Creation Time. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string DigitalCreationTime - { - get - { - return GetTagText("DigitalCreationTime"); - } - set - { - SetTagValue("DigitalCreationTime", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Originating Program. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string OriginatingProgram - { - get - { - return GetTagText("OriginatingProgram"); - } - set - { - SetTagValue("OriginatingProgram", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Program Version. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ProgramVersion - { - get - { - return GetTagText("ProgramVersion"); - } - set - { - SetTagValue("ProgramVersion", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Object Cycle. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ObjectCycle - { - get - { - return GetTagText("ObjectCycle"); - } - set - { - SetTagValue("ObjectCycle", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag By Line. - /// This is the author's name. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ByLine - { - get - { - return GetTagText("By-line"); - } - set - { - SetTagValue("By-line", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag By Line Title. - /// This is the author's position. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ByLineTitle - { - get - { - return GetTagText("By-lineTitle"); - } - set - { - SetTagValue("By-lineTitle", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag City. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string City - { - get - { - return GetTagText("City"); - } - set - { - SetTagValue("City", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Sub Location. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SubLocation - { - get - { - return GetTagText("SubLocation"); - } - set - { - SetTagValue("SubLocation", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Province State. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ProvinceState - { - get - { - return GetTagText("ProvinceState"); - } - set - { - SetTagValue("ProvinceState", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Country Primary Location Code. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string CountryPrimaryLocationCode - { - get - { - return GetTagText("Country-PrimaryLocationCode"); - } - set - { - SetTagValue("Country-PrimaryLocationCode", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Country Primary Location Name. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string CountryPrimaryLocationName - { - get - { - return GetTagText("Country-PrimaryLocationName"); - } - set - { - SetTagValue("Country-PrimaryLocationName", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Original Transmission Reference. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string OriginalTransmissionReference - { - get - { - return GetTagText("OriginalTransmissionReference"); - } - set - { - SetTagValue("OriginalTransmissionReference", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Headline. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Headline - { - get - { - return GetTagText("Headline"); - } - set - { - SetTagValue("Headline", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Credit. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Credit - { - get - { - return GetTagText("Credit"); - } - set - { - SetTagValue("Credit", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Source. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Source - { - get - { - return GetTagText("Source"); - } - set - { - SetTagValue("Source", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Copyright Notice. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string CopyrightNotice - { - get - { - return GetTagText("CopyrightNotice"); - } - set - { - SetTagValue("CopyrightNotice", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Contact. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Contact - { - get - { - return GetTagText("Contact"); - } - set - { - SetTagValue("Contact", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Caption Abstract. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string CaptionAbstract - { - get - { - return GetTagText("CaptionAbstract"); - } - set - { - SetTagValue("CaptionAbstract", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Writer Editor. - /// This is also referred to as Caption Writer. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string WriterEditor - { - get - { - return GetTagText("WriterEditor"); - } - set - { - SetTagValue("WriterEditor", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Rasterized Caption. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string RasterizedCaption - { - get - { - return GetTagText("RasterizedCaption"); - } - set - { - SetTagValue("RasterizedCaption", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Image Type. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ImageType - { - get - { - return GetTagText("ImageType"); - } - set - { - SetTagValue("ImageType", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Image Orientation. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ImageOrientation - { - get - { - return GetTagText("ImageOrientation"); - } - set - { - SetTagValue("ImageOrientation", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Language Identifier. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string LanguageIdentifier - { - get - { - return GetTagText("LanguageIdentifier"); - } - set - { - SetTagValue("LanguageIdentifier", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Audio Type. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string AudioType - { - get - { - return GetTagText("AudioType"); - } - set - { - SetTagValue("AudioType", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Audio Sampling Rate. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string AudioSamplingRate - { - get - { - return GetTagText("AudioSamplingRate"); - } - set - { - SetTagValue("AudioSamplingRate", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Audio Sampling Resolution. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string AudioSamplingResolution - { - get - { - return GetTagText("AudioSamplingResolution"); - } - set - { - SetTagValue("AudioSamplingResolution", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Audio Duration. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string AudioDuration - { - get - { - return GetTagText("AudioDuration"); - } - set - { - SetTagValue("AudioDuration", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Audio Outcue. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string AudioOutcue - { - get - { - return GetTagText("AudioOutcue"); - } - set - { - SetTagValue("AudioOutcue", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Job I D. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string JobID - { - get - { - return GetTagText("JobID"); - } - set - { - SetTagValue("JobID", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Master Document I D. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string MasterDocumentID - { - get - { - return GetTagText("MasterDocumentID"); - } - set - { - SetTagValue("MasterDocumentID", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Short Document I D. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ShortDocumentID - { - get - { - return GetTagText("ShortDocumentID"); - } - set - { - SetTagValue("ShortDocumentID", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Unique Document I D. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string UniqueDocumentID - { - get - { - return GetTagText("UniqueDocumentID"); - } - set - { - SetTagValue("UniqueDocumentID", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Owner I D. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string OwnerID - { - get - { - return GetTagText("OwnerID"); - } - set - { - SetTagValue("OwnerID", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Object Preview File Format. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ObjectPreviewFileFormat - { - get - { - return GetTagText("ObjectPreviewFileFormat"); - } - set - { - SetTagValue("ObjectPreviewFileFormat", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Object Preview File Version. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ObjectPreviewFileVersion - { - get - { - return GetTagText("ObjectPreviewFileVersion"); - } - set - { - SetTagValue("ObjectPreviewFileVersion", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Object Preview Data. - /// This is also referred to as Audio Outcue. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ObjectPreviewData - { - get - { - return GetTagText("ObjectPreviewData"); - } - set - { - SetTagValue("ObjectPreviewData", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Prefs. - /// This is also referred to as photo-mechanic preferences. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Prefs - { - get - { - return GetTagText("Prefs"); - } - set - { - SetTagValue("Prefs", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Classify State. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ClassifyState - { - get - { - return GetTagText("ClassifyState"); - } - set - { - SetTagValue("ClassifyState", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Similarity Index. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SimilarityIndex - { - get - { - return GetTagText("SimilarityIndex"); - } - set - { - SetTagValue("SimilarityIndex", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Document Notes. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string DocumentNotes - { - get - { - return GetTagText("DocumentNotes"); - } - set - { - SetTagValue("DocumentNotes", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Document History. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string DocumentHistory - { - get - { - return GetTagText("DocumentHistory"); - } - set - { - SetTagValue("DocumentHistory", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Exif Camera Info. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ExifCameraInfo - { - get - { - return GetTagText("ExifCameraInfo"); - } - set - { - SetTagValue("ExifCameraInfo", value); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_NODATA : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_NODATA(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_NODATA; } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_XMP : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_XMP(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_XMP; } - } - - /// - /// Gets or sets the XMP XML content. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Xml - { - get - { - return GetTagText("XMLPacket"); - } - set - { - SetTagValue("XMLPacket", value); - } - } - - /// - /// Gets an initialized to read the XMP XML content. - /// Returns null, if the metadata tag XMLPacket is not present in - /// this model. - /// - public XmlReader XmlReader - { - get - { - string xmlString = Xml; - if (xmlString == null) - { - return null; - } - else - { - MemoryStream stream = new MemoryStream(); - StreamWriter writer = new StreamWriter(stream); - writer.Write(xmlString); - return XmlReader.Create(stream); - } - } - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.6 $ +// $Date: 2009/09/15 11:49:24 $ +// $Id: MetadataModels.cs,v 1.6 2009/09/15 11:49:24 cklein05 Exp $ +// ========================================================== + +using System; +using System.Xml; +using System.IO; +using System.Text; + +namespace FreeImageAPI.Metadata +{ + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_ANIMATION : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_ANIMATION(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_ANIMATION; } + } + + /// + /// Gets or sets the width of the entire canvas area, that each page is displayed in. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? LogicalWidth + { + get + { + return GetTagValue("LogicalWidth"); + } + set + { + SetTagValue("LogicalWidth", value); + } + } + + /// + /// Gets or sets the height of the entire canvas area, that each page is displayed in. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? LogicalHeight + { + get + { + return GetTagValue("LogicalHeight"); + } + set + { + SetTagValue("LogicalHeight", value); + } + } + + /// + /// Gets or sets the global palette of the GIF image. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public Palette GlobalPalette + { + get + { + MetadataTag mdtag = GetTag("GlobalPalette"); + return (mdtag == null) ? null : new Palette(mdtag); + } + set + { + SetTagValue("GlobalPalette", (value != null) ? null : value.Data); + } + } + + /// + /// Gets or sets the number of replays for the animation. + /// Use 0 (zero) to specify an infinte number of replays. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? LoopCount + { + get + { + return GetTagValue("Loop"); + } + set + { + SetTagValue("Loop", value); + } + } + + /// + /// Gets or sets the horizontal offset within the logical canvas area, this frame is to be displayed at. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? FrameLeft + { + get + { + return GetTagValue("FrameLeft"); + } + set + { + SetTagValue("FrameLeft", value); + } + } + + /// + /// Gets or sets the vertical offset within the logical canvas area, this frame is to be displayed at. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? FrameTop + { + get + { + return GetTagValue("FrameTop"); + } + set + { + SetTagValue("FrameTop", value); + } + } + + /// + /// Gets or sets a flag to supress saving the dib's attached palette + /// (making it use the global palette). The local palette is the palette used by a page. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public bool? NoLocalPalette + { + get + { + byte? useGlobalPalette = GetTagValue("NoLocalPalette"); + return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?); + } + set + { + byte? val = null; + if (value.HasValue) + { + val = (byte)(value.Value ? 1 : 0); + } + SetTagValue("NoLocalPalette", val); + } + } + + /// + /// Gets or sets a value indicating whether the image is interlaced. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public bool? Interlaced + { + get + { + byte? useGlobalPalette = GetTagValue("Interlaced"); + return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?); + } + set + { + byte? val = null; + if (value.HasValue) + { + val = (byte)(value.Value ? 1 : 0); + } + SetTagValue("Interlaced", val); + } + } + + /// + /// Gets or sets the amout of time in milliseconds this frame is to be displayed. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? FrameTime + { + get + { + return GetTagValue("FrameTime"); + } + set + { + SetTagValue("FrameTime", value); + } + } + + /// + /// Gets or sets this frame's disposal method. Generally, this method defines, how to + /// remove or replace a frame when the next frame has to be drawn. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public DisposalMethodType? DisposalMethod + { + get + { + return GetTagValue("DisposalMethod"); + } + set + { + SetTagValue("DisposalMethod", value); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_COMMENTS : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_COMMENTS(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_COMMENTS; } + } + + /// + /// Gets or sets the comment of the image. + /// Supported formats are JPEG, PNG and GIF. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Comment + { + get + { + return GetTagText("Comment"); + } + set + { + SetTagValue("Comment", value); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_CUSTOM : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_CUSTOM(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_CUSTOM; } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_EXIF_EXIF : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_EXIF_EXIF(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF; } + } + + /// + /// Gets or sets the version of this standard supported. + /// Constant length or 4. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] ExifVersion + { + get + { + return GetTagArray("ExifVersion"); + } + set + { + FreeImage.Resize(ref value, 4); + SetTagValueUndefined("ExifVersion", value); + } + } + + /// + /// Gets or sets the Flashpix format version supported by a FPXR file. + /// Constant length or 4. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] FlashpixVersion + { + get + { + return GetTagArray("FlashpixVersion"); + } + set + { + FreeImage.Resize(ref value, 4); + SetTagValueUndefined("FlashpixVersion", value); + } + } + + /// + /// Gets or sets the color space information tag. + /// See remarks for further information. + /// + /// + /// The following values are defined: + /// + /// + /// ID + /// Description + /// + /// + /// 1 + /// sRGB (default) + /// + /// + /// 0xFFFF + /// uncalibrated + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? ColorSpace + { + get + { + return GetTagValue("ColorSpace"); + } + set + { + SetTagValue("ColorSpace", value); + } + } + + /// + /// Gets or sets the valid width of a compressed image. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? PixelXDimension + { + get + { + return GetUInt32Value("PixelXDimension"); + } + set + { + RemoveTag("PixelXDimension"); + if (value.HasValue) + { + SetTagValue("PixelXDimension", value.Value); + } + } + } + + /// + /// Gets or sets the valid height of a compressed image. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? PixelYDimension + { + get + { + return GetUInt32Value("PixelYDimension"); + } + set + { + RemoveTag("PixelYDimension"); + if (value.HasValue) + { + SetTagValue("PixelYDimension", value.Value); + } + } + } + + /// + /// Gets or sets components configuration. See remarks for further information. + /// Constant length of 4. + /// + /// + /// The channels of each component are arranged in order from the 1st component to the 4th. + /// For uncompressed data the data arrangement is given in the PhotometricInterpretation tag. + /// However, since PhotometricInterpretation can only express the order of Y,Cb and Cr, + /// this tag is provided for cases when compressed data uses components other than Y, Cb, + /// and Cr and to enable support of other sequences. + /// Default = 4 5 6 0 (if RGB uncompressed) + /// The following values are defined: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// does not exist + /// + /// + /// 1 + /// Y + /// + /// + /// 2 + /// Cb + /// + /// + /// 3 + /// Cr + /// + /// + /// 4 + /// R + /// + /// + /// 5 + /// R + /// + /// + /// 6 + /// R + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public byte[] ComponentsConfiguration + { + get + { + return GetTagArray("ComponentsConfiguration"); + } + set + { + FreeImage.Resize(ref value, 4); + SetTagValueUndefined("ComponentsConfiguration", value); + } + } + + /// + /// Gets or sets compression mode used for a compressed image is indicated + /// in unit bits per pixel. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? CompressedBitsPerPixel + { + get + { + return GetTagValue("CompressedBitsPerPixel"); + } + set + { + SetTagValue("CompressedBitsPerPixel", value); + } + } + + /// + /// Gets or sets a tag for manufacturers of Exif writers to record any desired information. + /// The contents are up to the manufacturer, but this tag should not be used for any other + /// than its intended purpose. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] MakerNote + { + get + { + return GetTagArray("FlashpixVersion"); + } + set + { + SetTagValueUndefined("FlashpixVersion", value); + } + } + + /// + /// Gets or sets a tag for Exif users to write keywords or comments on the image besides + /// those in ImageDescription, and without the character code limitations of the ImageDescription tag. + /// Minimum length of 8. See remarks for further information. + /// + /// + /// The character code used in the UserComment tag is identified based on an ID code in a fixed 8-byte + /// area at the start of the tag data area. The unused portion of the area is padded with NULL. + /// The ID code for the UserComment area may be a Defined code such as JIS or ASCII, or may be Undefined. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public byte[] UserComment + { + get + { + return GetTagArray("UserComment"); + } + set + { + FreeImage.Resize(ref value, 8, int.MaxValue); + SetTagValueUndefined("UserComment", value); + } + } + + /// + /// Gets or sets the name of an audio file related to the image data. + /// The format is 8.3. + /// Constant length of 12 + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string RelatedSoundFile + { + get + { + string text = GetTagText("RelatedSoundFile"); + if (!string.IsNullOrEmpty(text)) + { + text = text.Substring(0, text.Length - 1); + } + return text; + } + set + { + if (value != null) + { + FreeImage.Resize(ref value, 12); + value += '\0'; + } + SetTagValue("RelatedSoundFile", value); + } + } + + /// + /// Gets or sets the date and time when the original image data was generated. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public DateTime? DateTimeOriginal + { + get + { + DateTime? result = null; + string text = GetTagText("DateTimeOriginal"); + if (text != null) + { + try + { + result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null); + } + catch + { + } + } + return result; + } + set + { + string val = null; + if (value.HasValue) + { + try + { + val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0"); + } + catch + { + } + } + SetTagValue("DateTimeOriginal", val); + } + } + + /// + /// Gets or sets the date and time when the image was stored as digital data. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public DateTime? DateTimeDigitized + { + get + { + DateTime? result = null; + string text = GetTagText("DateTimeDigitized"); + if (text != null) + { + try + { + result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null); + } + catch + { + } + } + return result; + } + set + { + string val = null; + if (value.HasValue) + { + try + { + val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0"); + } + catch + { + } + } + SetTagValue("DateTimeDigitized", val); + } + } + + /// + /// Gets or sets a tag used to record fractions of seconds for the DateTime tag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SubsecTime + { + get + { + string text = GetTagText("SubsecTime"); + if (!string.IsNullOrEmpty(text)) + { + text = text.Substring(0, text.Length - 1); + } + return text; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("SubsecTime", value); + } + } + + /// + /// Gets or sets a tag used to record fractions of seconds for the DateTimeOriginal tag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SubsecTimeOriginal + { + get + { + string text = GetTagText("SubsecTimeOriginal"); + if (!string.IsNullOrEmpty(text)) + { + text = text.Substring(0, text.Length - 1); + } + return text; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("SubsecTimeOriginal", value); + } + } + + /// + /// Gets or sets a tag used to record fractions of seconds for the DateTimeDigitized tag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SubsecTimeDigitized + { + get + { + string text = GetTagText("SubsecTimeDigitized"); + if (!string.IsNullOrEmpty(text)) + { + text = text.Substring(0, text.Length - 1); + } + return text; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("SubsecTimeDigitized", value); + } + } + + /// + /// Gets or the exposure time, given in seconds (sec). + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? ExposureTime + { + get + { + return GetTagValue("ExposureTime"); + } + set + { + SetTagValue("ExposureTime", value); + } + } + + /// + /// Gets or the F number. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? FNumber + { + get + { + return GetTagValue("FNumber"); + } + set + { + SetTagValue("FNumber", value); + } + } + + /// + /// Gets or sets the class of the program used by the camera to set exposure when the + /// picture is taken. + /// See remarks for further information. + /// + /// + /// The following values are defined: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// not defined + /// + /// + /// 1 + /// manual + /// + /// + /// 2 + /// normal program + /// + /// + /// 3 + /// aperture priority + /// + /// + /// 4 + /// shutter priority + /// + /// + /// 5 + /// create program + /// + /// + /// 6 + /// action program + /// + /// + /// 7 + /// portrait mode + /// + /// + /// 8 + /// landscape mode + /// + /// + /// others + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? ExposureProgram + { + get + { + return GetTagValue("ExposureProgram"); + } + set + { + SetTagValue("ExposureProgram", value); + } + } + + /// + /// Gets or sets the spectral sensitivity of each channel of the camera used. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SpectralSensitivity + { + get + { + string text = GetTagText("SpectralSensitivity"); + if (!string.IsNullOrEmpty(text)) + { + text = text.Substring(0, text.Length - 1); + } + return text; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("SpectralSensitivity", value); + } + } + + /// + /// Gets or sets the the ISO Speed and ISO Latitude of the camera or input device as + /// specified in ISO 12232. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort[] ISOSpeedRatings + { + get + { + return GetTagArray("ISOSpeedRatings"); + } + set + { + SetTagValue("ISOSpeedRatings", value); + } + } + + /// + /// Gets or sets the Opto-Electric Conversion Function (OECF) specified in ISO 14524. + /// OECF is the relationship between the camera optical input and the image values. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] OECF + { + get + { + return GetTagArray("OECF"); + } + set + { + SetTagValueUndefined("OECF", value); + } + } + + /// + /// Gets or sets the shutter speed. The unit is the APEX (Additive System of Photographic Exposure). + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIRational? ShutterSpeedValue + { + get + { + return GetTagValue("ShutterSpeedValue"); + } + set + { + SetTagValue("ShutterSpeedValue", value); + } + } + + /// + /// Gets or sets the lens aperture. The unit is the APEX value. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? ApertureValue + { + get + { + return GetTagValue("ApertureValue"); + } + set + { + SetTagValue("ApertureValue", value); + } + } + + /// + /// Gets or sets the value of brightness. The unit is the APEX value. + /// Ordinarily it is given in the range of -99.99 to 99.99. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIRational? BrightnessValue + { + get + { + return GetTagValue("BrightnessValue"); + } + set + { + SetTagValue("BrightnessValue", value); + } + } + + /// + /// Gets or sets the exposure bias. The unit is the APEX value. + /// Ordinarily it is given in the range of –99.99 to 99.99. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIRational? ExposureBiasValue + { + get + { + return GetTagValue("ExposureBiasValue"); + } + set + { + SetTagValue("ExposureBiasValue", value); + } + } + + /// + /// Gets or sets the smallest F number of the lens. The unit is the APEX value. + /// Ordinarily it is given in the range of 00.00 to 99.99, + /// but it is not limited to this range. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? MaxApertureValue + { + get + { + return GetTagValue("MaxApertureValue"); + } + set + { + SetTagValue("MaxApertureValue", value); + } + } + + /// + /// Gets or sets distance to the subject, given in meters. + /// Note that if the numerator of the recorded value is FFFFFFFF, infinity shall be indicated; + /// and if the numerator is 0, distance unknown shall be indicated. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? SubjectDistance + { + get + { + return GetTagValue("SubjectDistance"); + } + set + { + SetTagValue("SubjectDistance", value); + } + } + + /// + /// Gets or sets the metering mode. See remarks for further information. + /// + /// + /// The following values are defined: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// unknown + /// + /// + /// 1 + /// average + /// + /// + /// 2 + /// center-weighted-average + /// + /// + /// 3 + /// spot + /// + /// + /// 4 + /// multi-spot + /// + /// + /// 5 + /// pattern + /// + /// + /// 6 + /// partial + /// + /// + /// other + /// reserved + /// + /// + /// 255 + /// other + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? MeteringMode + { + get + { + return GetTagValue("MeteringMode"); + } + set + { + SetTagValue("MeteringMode", value); + } + } + + /// + /// Gets or sets the kind of light source. + /// See remarks for further information. + /// + /// + /// The following values are defined: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// unknown + /// + /// + /// 1 + /// daylight + /// + /// + /// 2 + /// fluorescent + /// + /// + /// 3 + /// tungsten + /// + /// + /// 4 + /// flash + /// + /// + /// 9 + /// fine weather + /// + /// + /// 10 + /// cloudy weather + /// + /// + /// 11 + /// shade + /// + /// + /// 12 + /// daylight fluorecent (D 5700 - 7100K) + /// + /// + /// 13 + /// day white fluorescent (N 4600 - 5400K) + /// + /// + /// 14 + /// cool white fluorescent (W 3900 - 4500K) + /// + /// + /// 15 + /// white fluorescent (WW 3200 - 3700K) + /// + /// + /// 17 + /// standard light A + /// + /// + /// 18 + /// standard light B + /// + /// + /// 19 + /// standard light C + /// + /// + /// 20 + /// D55 + /// + /// + /// 21 + /// D65 + /// + /// + /// 22 + /// D75 + /// + /// + /// 23 + /// D50 + /// + /// + /// 24 + /// ISO studio tungsten + /// + /// + /// 255 + /// other light source + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? LightSource + { + get + { + return GetTagValue("LightSource"); + } + set + { + SetTagValue("LightSource", value); + } + } + + /// + /// Gets or sets a value indicating the status of flash when the image was shot. + /// Bit 0 indicates the flash firing status, bits 1 and 2 indicate the flash return + /// status, bits 3 and 4 indicate the flash mode, bit 5 indicates whether the flash + /// function is present, and bit 6 indicates "red eye" mode. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? Flash + { + get + { + return GetTagValue("Flash"); + } + set + { + SetTagValue("Flash", value); + } + } + + /// + /// Gets or sets a value indicating the location and area of the main subject in + /// the overall scene. Variable length between 2 and 4. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort[] SubjectArea + { + get + { + return GetTagArray("SubjectArea"); + } + set + { + FreeImage.Resize(ref value, 2, 4); + SetTagValue("SubjectArea", value); + } + } + + /// + /// Gets or sets the actual focal length of the lens, in mm. + /// Conversion is not made to the focal length of a 35 mm film camera. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? FocalLength + { + get + { + return GetTagValue("FocalLength"); + } + set + { + SetTagValue("FocalLength", value); + } + } + + /// + /// Gets or sets the strobe energy at the time the image is captured, + /// as measured in Beam Candle Power Seconds (BCPS). + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? FlashEnergy + { + get + { + return GetTagValue("FlashEnergy"); + } + set + { + SetTagValue("FlashEnergy", value); + } + } + + /// + /// Gets or sets the camera or input device spatial frequency table and SFR values + /// in the direction of image width, image height, and diagonal direction, + /// as specified in ISO 12233. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] SpatialFrequencyResponse + { + get + { + return GetTagArray("SpatialFrequencyResponse"); + } + set + { + SetTagValueUndefined("SpatialFrequencyResponse", value); + } + } + + /// + /// Gets or sets the number of pixels in the image width (X) direction per + /// FocalPlaneResolutionUnit on the camera focal plane. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? FocalPlaneXResolution + { + get + { + return GetTagValue("FocalPlaneXResolution"); + } + set + { + SetTagValue("FocalPlaneXResolution", value); + } + } + + /// + /// Gets or sets the number of pixels in the image height (Y) direction per + /// FocalPlaneResolutionUnit on the camera focal plane. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? FocalPlaneYResolution + { + get + { + return GetTagValue("FocalPlaneYResolution"); + } + set + { + SetTagValue("FocalPlaneYResolution", value); + } + } + + /// + /// Gets or sets the unit for measuring FocalPlaneXResolution and FocalPlaneYResolution. + /// This value is the same as the ResolutionUnit. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? FocalPlaneResolutionUnit + { + get + { + return GetTagValue("FocalPlaneResolutionUnit"); + } + set + { + SetTagValue("FocalPlaneResolutionUnit", value); + } + } + + /// + /// Gets or sets the location of the main subject in the scene. + /// The value of this tag represents the pixel at the center of the main subject + /// relative to the left edge, prior to rotation processing as per the Rotation tag. + /// The first value indicates the X column number and second indicates the Y row number. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? SubjectLocation + { + get + { + return GetTagValue("SubjectLocation"); + } + set + { + SetTagValue("SubjectLocation", value); + } + } + + /// + /// Gets or sets the exposure index selected on the camera or input device at the + /// time the image was captured. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? ExposureIndex + { + get + { + return GetTagValue("ExposureIndex"); + } + set + { + SetTagValue("ExposureIndex", value); + } + } + + /// + /// Gets or sets the image sensor type on the camera or input device. + /// See remarks for further information. + /// + /// + /// The following values are defined: + /// + /// + /// ID + /// Description + /// + /// + /// 1 + /// not defined + /// + /// + /// 2 + /// one-chip color area sensor + /// + /// + /// 3 + /// two-chip color area sensor + /// + /// + /// 4 + /// three-chip color area sensor + /// + /// + /// 5 + /// color sequential area sensor + /// + /// + /// 7 + /// trilinear sensor + /// + /// + /// 8 + /// color sequential linear sensor + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? SensingMethod + { + get + { + return GetTagValue("SensingMethod"); + } + set + { + SetTagValue("SensingMethod", value); + } + } + + /// + /// Gets or sets the image source. If a DSC recorded the image, this tag value of this + /// tag always be set to 3, indicating that the image was recorded on a DSC. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte? FileSource + { + get + { + return GetTagValue("FileSource"); + } + set + { + SetTagValueUndefined("FileSource", value.HasValue ? new byte[] { value.Value } : null); + } + } + + /// + /// Gets or sets the type of scene. If a DSC recorded the image, this tag value shall + /// always be set to 1, indicating that the image was directly photographed. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte? SceneType + { + get + { + return GetTagValue("SceneType"); + } + set + { + SetTagValueUndefined("SceneType", value.HasValue ? new byte[] { value.Value } : null); + } + } + + /// + /// Gets or sets the color filter array (CFA) geometric pattern of the image sensor + /// when a one-chip color area sensor is used. It does not apply to all sensing methods. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] CFAPattern + { + get + { + return GetTagArray("CFAPattern"); + } + set + { + SetTagValueUndefined("CFAPattern", value); + } + } + + /// + /// Gets or sets the use of special processing on image data, such as rendering geared to output. + /// When special processing is performed, the reader is expected to disable or minimize any + /// further processing. See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// normal process + /// + /// + /// 1 + /// custom process + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? CustomRendered + { + get + { + return GetTagValue("CustomRendered"); + } + set + { + SetTagValue("CustomRendered", value); + } + } + + /// + /// Gets or sets the exposure mode set when the image was shot. + /// In auto-bracketing mode, the camera shoots a series of frames of the same scene + /// at different exposure settings. See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// auto exposure + /// + /// + /// 1 + /// manual exposure + /// + /// + /// 2 + /// auto bracket + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? ExposureMode + { + get + { + return GetTagValue("ExposureMode"); + } + set + { + SetTagValue("ExposureMode", value); + } + } + + /// + /// Gets or sets the white balance mode set when the image was shot. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// auto white balance + /// + /// + /// 1 + /// manual white balance + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? WhiteBalance + { + get + { + return GetTagValue("WhiteBalance"); + } + set + { + SetTagValue("WhiteBalance", value); + } + } + + /// + /// Gets or sets the digital zoom ratio when the image was shot. + /// If the numerator of the recorded value is 0, this indicates that digital zoom was not used. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? DigitalZoomRatio + { + get + { + return GetTagValue("DigitalZoomRatio"); + } + set + { + SetTagValue("DigitalZoomRatio", value); + } + } + + /// + /// Gets or sets the equivalent focal length assuming a 35mm film camera, in mm. + /// A value of 0 means the focal length is unknown. Note that this tag differs + /// from the FocalLength tag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? FocalLengthIn35mmFilm + { + get + { + return GetTagValue("DigitalZoomRatio"); + } + set + { + SetTagValue("DigitalZoomRatio", value); + } + } + + /// + /// Gets or sets the type of scene that was shot. + /// It can also be used to record the mode in which the image was shot. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// standard + /// + /// + /// 1 + /// landscape + /// + /// + /// 2 + /// portrait + /// + /// + /// 3 + /// night scene + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? SceneCaptureType + { + get + { + return GetTagValue("SceneCaptureType"); + } + set + { + SetTagValue("SceneCaptureType", value); + } + } + + /// + /// Gets or sets the degree of overall image gain adjustment. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// none + /// + /// + /// 1 + /// low gain up + /// + /// + /// 2 + /// high gain up + /// + /// + /// 3 + /// low gain down + /// + /// + /// 4 + /// high gain down + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? GainControl + { + get + { + return GetTagValue("GainControl"); + } + set + { + SetTagValue("GainControl", value); + } + } + + /// + /// Gets or sets the direction of contrast processing applied by the camera + /// when the image was shot. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// normal + /// + /// + /// 1 + /// soft + /// + /// + /// 2 + /// hard + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? Contrast + { + get + { + return GetTagValue("Contrast"); + } + set + { + SetTagValue("Contrast", value); + } + } + + /// + /// Gets or sets the direction of saturation processing applied by the camera + /// when the image was shot. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// normal + /// + /// + /// 1 + /// low saturation + /// + /// + /// 2 + /// high saturation + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? Saturation + { + get + { + return GetTagValue("Saturation"); + } + set + { + SetTagValue("Saturation", value); + } + } + + /// + /// Gets or sets the direction of sharpness processing applied by the camera + /// when the image was shot. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// normal + /// + /// + /// 1 + /// soft + /// + /// + /// 2 + /// hard + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? Sharpness + { + get + { + return GetTagValue("Sharpness"); + } + set + { + SetTagValue("Sharpness", value); + } + } + + /// + /// Gets or sets information on the picture-taking conditions of a particular camera model. + /// The tag is used only to indicate the picture-taking conditions in the reader. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] DeviceSettingDescription + { + get + { + return GetTagArray("DeviceSettingDescription"); + } + set + { + SetTagValueUndefined("DeviceSettingDescription", value); + } + } + + /// + /// Gets or sets the distance to the subject. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// unknown + /// + /// + /// 1 + /// macro + /// + /// + /// 2 + /// close view + /// + /// + /// 3 + /// distant view + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? SubjectDistanceRange + { + get + { + return GetTagValue("SubjectDistanceRange"); + } + set + { + SetTagValue("SubjectDistanceRange", value); + } + } + + /// + /// Gets or sets an identifier assigned uniquely to each image. + /// It is recorded as an ASCII string equivalent to hexadecimal notation and 128-bit fixed length. + /// Constant length of 32. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ImageUniqueID + { + get + { + string text = GetTagText("ImageUniqueID"); + if (!string.IsNullOrEmpty(text)) + { + text = text.Substring(0, text.Length - 1); + } + return text; + } + set + { + if (value != null) + { + FreeImage.Resize(ref value, 32); + value += '\0'; + } + SetTagValue("ImageUniqueID", value); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_EXIF_GPS : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_EXIF_GPS(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_GPS; } + } + + /// + /// Gets or sets the GPS version ID. Constant length of 4. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] VersionID + { + get + { + return GetTagArray("GPSVersionID"); + } + set + { + FreeImage.Resize(ref value, 4); + SetTagValue("GPSVersionID", value); + } + } + + /// + /// Gets or sets a value indicating whether the + /// is north or south latitude. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public LatitudeType? LatitudeDirection + { + get + { + return ToLatitudeType(GetTagText("GPSLatitudeRef")); + } + set + { + SetTagValue("GPSLatitudeRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the latitude of the image. The latitude is expressed as three rational + /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public FIURational[] Latitude + { + get + { + return GetTagArray("GPSLatitude"); + } + set + { + FreeImage.Resize(ref value, 3); + SetTagValue("GPSLatitude", value); + } + } + + /// + /// Gets or sets a value indicating whether + /// is east or west longitude. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public LongitudeType? LongitudeDirection + { + get + { + return ToLongitudeType(GetTagText("GPSLongitudeRef")); + } + set + { + SetTagValue("GPSLongitudeRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the longitude of the image. The longitude is expressed as three rational + /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public FIURational[] Longitude + { + get + { + return GetTagArray("GPSLongitude"); + } + set + { + FreeImage.Resize(ref value, 3); + SetTagValue("GPSLongitude", value); + } + } + + /// + /// Gets a value indicating whether is sea level and the altitude + /// is above sea level. If the altitude is below sea level is + /// indicated as an absolute value. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public AltitudeType? AltitudeDirection + { + get + { + byte? flag = GetTagValue("GPSAltitudeRef"); + if (flag.HasValue) + { + switch (flag.Value) + { + case 0: + return AltitudeType.AboveSeaLevel; + case 1: + return AltitudeType.BelowSeaLevel; + default: + return AltitudeType.Undefined; + } + } + return null; + } + set + { + byte? val = null; + if (value.HasValue) + { + switch (value.Value) + { + case AltitudeType.AboveSeaLevel: + val = 0; + break; + + case AltitudeType.BelowSeaLevel: + val = 1; + break; + + default: + val = 2; + break; + } + } + SetTagValue("GPSAltitudeRef", val); + } + } + + /// + /// Gets or sets the altitude based on the reference in . + /// Altitude is expressed as one rational value. The reference unit is meters. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? Altitude + { + get + { + return GetTagValue("GPSAltitude"); + } + set + { + SetTagValue("GPSAltitude", value); + } + } + + /// + /// Gets or sets the sign of the . + /// + /// + /// This is a derived property. There is no metadata tag directly associated + /// with this property value. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public int? AltitudeSign + { + get + { + AltitudeType? seaLevel = AltitudeDirection; + if (seaLevel.HasValue) + { + return (seaLevel.Value == AltitudeType.BelowSeaLevel) ? -1 : 1; + } + return null; + } + set + { + if (value.HasValue) + { + AltitudeDirection = value.Value >= 0 ? AltitudeType.AboveSeaLevel : AltitudeType.BelowSeaLevel; + } + else + { + AltitudeDirection = null; + } + } + } + + /// + /// Gets or sets the signed altitude. + /// Altitude is expressed as one rational value. The reference unit is meters. + /// + /// + /// Altitude is too large to fit into a FIRational. + /// + /// + /// This is a derived property. There is no metadata tag directly associated + /// with this property value. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public FIRational? SignedAltitude + { + get + { + FIRational? result = null; + FIURational? altitude = Altitude; + if (altitude.HasValue) + { + int sign = AltitudeSign ?? 1; + if (((int)altitude.Value.Numerator < 0) || ((int)altitude.Value.Denominator < 0)) + throw new OverflowException(); + result = new FIRational((int)altitude.Value.Numerator * sign, (int)altitude.Value.Denominator); + } + return result; + } + set + { + FIURational? val = null; + if (value.HasValue) + { + if (value.Value < 0) + { + AltitudeSign = -1; + value = -value.Value; + } + else + { + AltitudeSign = 1; + } + val = new FIURational((uint)value.Value.Numerator, (uint)value.Value.Denominator); + } + Altitude = val; + } + } + + + /// + /// Gets or sets the time as UTC (Coordinated Universal Time). Constant length of 3. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public TimeSpan? TimeStamp + { + get + { + FIURational[] stamp = GetTagArray("GPSTimeStamp"); + if ((stamp == null) || stamp.Length != 3) + { + return null; + } + else + { + return new TimeSpan((int)stamp[0], (int)stamp[1], (int)stamp[2]); + } + } + set + { + FIURational[] stamp = null; + if (value.HasValue) + { + TimeSpan span = value.Value; + stamp = new FIURational[3]; + stamp[0] = span.Hours; + stamp[1] = span.Minutes; + stamp[2] = span.Seconds; + } + SetTagValue("GPSTimeStamp", stamp); + } + } + + /// + /// Gets or sets the GPS satellites used for measurements. This tag can be used to describe + /// the number of satellites, their ID number, angle of elevation, azimuth, SNR and other + /// information in ASCII notation. The format is not specified. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Satellites + { + get + { + string result = GetTagText("GPSSatellites"); + if (!string.IsNullOrEmpty(result)) + { + result = result.Substring(0, result.Length - 1); + } + return result; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("GPSTimeStamp", value); + } + } + + /// + /// Gets or sets a value indicating the status of the GPS receiver when the image was recorded. + /// true indicates measurement was in progress; + /// false indicates measurement was Interoperability. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public bool? Status + { + get + { + string text = GetTagText("GPSStatus"); + return string.IsNullOrEmpty(text) ? default(bool?) : text[0] == 'A'; + } + set + { + SetTagValue("GPSStatus", value.HasValue ? (value.Value ? "A\0" : "V\0") : null); + } + } + + /// + /// Gets or sets a value indicating the GPS measurement mode. + /// true indicates three-dimensional measurement; + /// false indicated two-dimensional measurement was in progress. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public bool? MeasureMode3D + { + get + { + string text = GetTagText("GPSMeasureMode"); + return string.IsNullOrEmpty(text) ? default(bool?) : text[0] == '3'; + } + set + { + SetTagValue("GPSMeasureMode", value.HasValue ? (value.Value ? "3\0" : "2\0") : null); + } + } + + /// + /// Gets or sets the GPS DOP (data degree of precision). An HDOP value is written during + /// two-dimensional measurement, and PDOP during three-dimensional measurement. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? DOP + { + get + { + return GetTagValue("GPSDOP"); + } + set + { + SetTagValue("GPSDOP", value); + } + } + + /// + /// Gets or sets the unit used to express the GPS receiver of movement. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public VelocityUnit? SpeedUnit + { + get + { + return ToUnitType(GetTagText("GPSSpeedRef")); + } + set + { + SetTagValue("GPSSpeedRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the speed of GPS receiver movement. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public FIURational? Speed + { + get + { + return GetTagValue("GPSSpeed"); + } + set + { + SetTagValue("GPSSpeed", value); + } + } + + /// + /// Gets or sets the reference for giving the direction of GPS receiver movement. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public DirectionReference? TrackDirectionReference + { + get + { + return ToDirectionType(GetTagText("GPSTrackRef")); + } + set + { + SetTagValue("GPSTrackRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the direction of GPS receiver movement. + /// The range of values is from 0.00 to 359.99. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public FIURational? Track + { + get + { + return GetTagValue("GPSTrack"); + } + set + { + SetTagValue("GPSTrack", value); + } + } + + /// + /// Gets or sets the reference for giving the direction of GPS receiver movement. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public DirectionReference? ImageDirectionReference + { + get + { + return ToDirectionType(GetTagText("GPSImgDirectionRef")); + } + set + { + SetTagValue("GPSImgDirectionRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the direction of the image when it was captured. + /// The range of values is from 0.00 to 359.99. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public FIURational? ImageDirection + { + get + { + return GetTagValue("GPSImgDirection"); + } + set + { + SetTagValue("GPSImgDirection", value); + } + } + + /// + /// Gets or sets the geodetic survey data used by the GPS receiver. If the survey data + /// is restricted to Japan, the value of this tag is 'TOKYO' or 'WGS-84'. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string MapDatum + { + get + { + string result = GetTagText("GPSMapDatum"); + if (!string.IsNullOrEmpty(result)) + { + result = result.Substring(0, result.Length - 1); + } + return result; + } + set + { + SetTagValue("GPSMapDatum", value + '\0'); + } + } + + /// + /// Gets or sets a value indicating whether the destination point + /// is north or south latitude. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public LatitudeType? DestinationLatitudeDirection + { + get + { + return ToLatitudeType(GetTagText("GPSDestLatitudeRef")); + } + set + { + SetTagValue("GPSDestLatitudeRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the latitude of the destination point. The latitude is expressed as three rational + /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public FIURational[] DestinationLatitude + { + get + { + return GetTagArray("GPSDestLatitude"); + } + set + { + FreeImage.Resize(ref value, 3); + SetTagValue("GPSDestLatitude", value); + } + } + + /// + /// Gets or sets a value indicating whether the destination point + /// is east or west longitude. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public LongitudeType? DestinationLongitudeDirection + { + get + { + return ToLongitudeType(GetTagText("GPSDestLongitudeRef")); + } + set + { + SetTagValue("GPSDestLongitudeRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the longitude of the destination point. The longitude is expressed as three rational + /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational[] DestinationLongitude + { + get + { + return GetTagArray("GPSDestLongitude"); + } + set + { + FreeImage.Resize(ref value, 3); + SetTagValue("GPSDestLongitude", value); + } + } + + /// + /// Gets or sets the reference used for giving the bearing to the destination point. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public DirectionReference? DestinationDirectionReference + { + get + { + return ToDirectionType(GetTagText("GPSDestBearingRef")); + } + set + { + SetTagValue("GPSDestBearingRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the bearing to the destination point. + /// The range of values is from 0.00 to 359.99. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public FIURational? DestinationBearing + { + get + { + return GetTagValue("GPSDestBearing"); + } + set + { + SetTagValue("GPSDestBearing", value); + } + } + + /// + /// Gets or sets the unit used to express the distance to the destination point. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public VelocityUnit? DestinationUnit + { + get + { + return ToUnitType(GetTagText("GPSDestDistanceRef")); + } + set + { + SetTagValue("GPSDestDistanceRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets a character string recording the name of the method used + /// for location finding. The first byte indicates the character code used, + /// and this is followed by the name of the method. Since the Type is not ASCII, + /// NULL termination is not necessary. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] ProcessingMethod + { + get + { + return GetTagArray("GPSProcessingMethod"); + } + set + { + SetTagValue("GPSProcessingMethod", value); + } + } + + /// + /// Gets or sets a character string recording the name of the GPS area. + /// The first byte indicates the character code used, and this is followed by + /// the name of the GPS area. Since the Type is not ASCII, NULL termination is + /// not necessary. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] AreaInformation + { + get + { + return GetTagArray("GPSAreaInformation"); + } + set + { + SetTagValue("GPSAreaInformation", value); + } + } + + /// + /// Gets or sets date and time information relative to UTC (Coordinated Universal Time). + /// + /// + /// This is a derived property. There is no metadata tag directly associated + /// with this property value. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public DateTime? DateTimeStamp + { + get + { + DateTime? date = DateStamp; + TimeSpan? time = TimeStamp; + if ((date == null) && (time == null)) + { + return null; + } + else + { + if (date == null) + { + date = DateTime.MinValue; + } + if (time == null) + { + time = TimeSpan.MinValue; + } + return date.Value.Add(time.Value); + } + } + set + { + if (value.HasValue) + { + DateStamp = value.Value.Date; + TimeStamp = value.Value.TimeOfDay; + } + else + { + DateStamp = null; + TimeStamp = null; + } + } + } + + /// + /// Gets or sets date information relative to UTC (Coordinated Universal Time). + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public DateTime? DateStamp + { + get + { + string stamp = GetTagText("GPSDateStamp"); + if (stamp != null) + { + try + { + return DateTime.ParseExact(stamp, "yyyy:MM:dd\0", null); + } + catch + { + } + } + return null; + } + set + { + string val = null; + if (value.HasValue) + { + try + { + val = value.Value.ToString("yyyy:MM:dd\0"); + } + catch + { + } + } + SetTagValue("GPSDateStamp", val); + } + } + + /// + /// Gets or sets a value indicating whether differential correction was applied to + /// the GPS receiver. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public bool? IsDifferential + { + get + { + ushort? value = GetTagValue("GPSDifferential"); + return value.HasValue ? (value != 0) : (default(bool?)); + } + set + { + SetTagValue("GPSDifferential", value.HasValue ? (object)(value.Value ? (ushort)1 : (ushort)0) : (null)); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_INTEROP : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_INTEROP(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_INTEROP; } + } + + /// + /// Gets or sets the identification of the Interoperability rule. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public InteroperabilityMode? Identification + { + get + { + return ToInteroperabilityType(GetTagText("InteroperabilityIndex")); + } + set + { + SetTagValue("InteroperabilityIndex", ToString(value) + '\0'); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + /// This class is obsolete. Use class instead. + /// + [Obsolete("To be removed in future releases. Use MDM_EXIF_MAIN instead.")] + public class MDM_MAIN : MDM_EXIF_MAIN + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_MAIN(FIBITMAP dib) : base(dib) { } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_EXIF_MAIN : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_EXIF_MAIN(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN; } + } + + /// + /// Gets or sets the number of columns of image data, equal to the number + /// of pixels per row. In JPEG compressed data a JPEG marker is used + /// instead of this tag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? ImageWidth + { + get + { + return GetUInt32Value("ImageWidth"); + } + set + { + RemoveTag("ImageWidth"); + if (value.HasValue) + { + SetTagValue("ImageWidth", value); + } + } + } + + /// + /// Gets or sets number of rows of image data. In JPEG compressed data a JPEG marker + /// is used instead of this tag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? ImageHeight + { + get + { + return GetUInt32Value("ImageLength"); + } + set + { + RemoveTag("ImageLength"); + if (value.HasValue) + { + SetTagValue("ImageLength", value); + } + } + } + + /// + /// Gets or sets number of bits per image component. In this standard + /// each component of the image is 8 bits, so the value for this tag is 8. + /// Constant length of 3. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort[] BitsPerSample + { + get + { + return GetTagArray("BitsPerSample"); + } + set + { + FreeImage.Resize(ref value, 3); + SetTagValue("BitsPerSample", value); + } + } + + /// + /// Gets or sets compression scheme used for the image data. When a primary image + /// is JPEG compressed, this designation is not necessary and is omitted. + /// When thumbnails use JPEG compression, this tag value is set to 6. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? Compression + { + get + { + return GetTagValue("Compression"); + } + set + { + SetTagValue("Compression", value); + } + } + + /// + /// Gets or sets pixel composition. In JPEG compressed data a JPEG marker is + /// used instead of this tag. See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 2 + /// RGB + /// + /// + /// 6 + /// YCbCr + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? PhotometricInterpretation + { + get + { + return GetTagValue("PhotometricInterpretation"); + } + set + { + SetTagValue("PhotometricInterpretation", value); + } + } + + /// + /// Gets or sets the image orientation viewed in terms of rows and columns. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ExifImageOrientation? Orientation + { + get + { + return (ExifImageOrientation?)GetTagValue("Orientation"); + } + set + { + SetTagValue("Orientation", (ushort?)value); + } + } + + /// + /// Gets or sets the number of components per pixel. Since this standard applies + /// to RGB and YCbCr images, the value set for this tag is 3. In JPEG compressed + /// data a JPEG marker is used instead of this tag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? SamplesPerPixel + { + get + { + return GetTagValue("SamplesPerPixel"); + } + set + { + SetTagValue("SamplesPerPixel", value); + } + } + + /// + /// Gets or sets a value that indicates whether pixel components are recorded in + /// chunky or planar format. In JPEG compressed files a JPEG marker is used instead + /// of this tag. If this field does not exist, the TIFF default of 1 (chunky) is assumed. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 1 + /// chunky format + /// + /// + /// 2 + /// planar format + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? PlanarConfiguration + { + get + { + return GetTagValue("PlanarConfiguration"); + } + set + { + SetTagValue("PlanarConfiguration", value); + } + } + + /// + /// Gets or sets the sampling ratio of chrominance components in relation to + /// the luminance component. In JPEG compressed dat a JPEG marker is used + /// instead of this tag. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// [2,1] + /// YCbCr4:2:2 + /// + /// + /// [2,2] + /// YCbCr4:2:0 + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort[] YCbCrSubSampling + { + get + { + return GetTagArray("YCbCrSubSampling"); + } + set + { + FreeImage.Resize(ref value, 2); + SetTagValue("YCbCrSubSampling", value); + } + } + + /// + /// Gets or sets position of chrominance components in relation to the luminance component. + /// See remarks for further information. + /// + /// + /// This field is designated only for JPEG compressed data or uncompressed YCbCr data. + /// The TIFF default is 1 (centered); but when Y:Cb:Cr = 4:2:2 it is recommended in + /// this standard that 2 (co-sited) be used to record data, in order to improve the + /// image quality when viewed on TV systems. + /// + /// When this field does not exist, the reader shall assume the TIFF default. + /// In the case of Y:Cb:Cr = 4:2:0, the TIFF default (centered) is recommended. + /// If the reader does not have the capability of supporting both kinds of YCbCrPositioning, + /// it shall follow the TIFF default regardless of the value in this field. + /// It is preferable that readers be able to support both centered and co-sited positioning. + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 1 + /// centered + /// + /// + /// 2 + /// co-sited + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? YCbCrPositioning + { + get + { + return GetTagValue("YCbCrPositioning"); + } + set + { + SetTagValue("YCbCrPositioning", value); + } + } + + /// + /// Gets or sets the number of pixels per + /// in the direction. When the image resolution is unknown, + /// 72 [dpi] is designated. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? XResolution + { + get + { + return GetTagValue("XResolution"); + } + set + { + SetTagValue("XResolution", value); + } + } + + /// + /// Gets or sets the number of pixels per + /// in the direction. When the image resolution is unknown, + /// 72 [dpi] is designated. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? YResolution + { + get + { + return GetTagValue("YResolution"); + } + set + { + SetTagValue("YResolution", value); + } + } + + /// + /// Gets or sets the unit for measuring and . + /// The same unit is used for both and . + /// If the image resolution in unknown, 2 (inches) is designated. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 2 + /// inches + /// + /// + /// 3 + /// YCbCr4:2:0 + /// + /// + /// other + /// centimeters + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? ResolutionUnit + { + get + { + return GetTagValue("ResolutionUnit"); + } + set + { + SetTagValue("ResolutionUnit", value); + } + } + + /// + /// Gets or sets the byte offset of that strip. + /// It is recommended that this be selected so the number of strip bytes + /// does not exceed 64 Kbytes. + /// With JPEG compressed data this designation is not needed and is omitted. + /// Constant length of * StripsPerImage. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + /// + public uint[] StripOffsets + { + get + { + return GetUInt32Array("StripOffsets"); + } + set + { + RemoveTag("StripOffsets"); + if (value != null) + { + SetTagValue("StripOffsets", value); + } + } + } + + /// + /// Gets or sets number of rows per strip. This is the number of rows in the image of + /// one strip when an image is divided into strips. With JPEG compressed data this + /// designation is not needed and is omitted. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public uint? RowsPerStrip + { + get + { + return GetUInt32Value("RowsPerStrip"); + } + set + { + RemoveTag("RowsPerStrip"); + if (value.HasValue) + { + SetTagValue("RowsPerStrip", value); + } + } + } + + /// + /// Gets or sets the total number of bytes in each strip. + /// With JPEG compressed data this designation is not needed and is omitted. + /// Constant length of * StripsPerImage. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint[] StripByteCounts + { + get + { + return GetUInt32Array("StripByteCounts"); + } + set + { + RemoveTag("StripByteCounts"); + if (value != null) + { + SetTagValue("StripByteCounts", value); + } + } + } + + /// + /// Gets or sets the offset to the start byte (SOI) of JPEG compressed thumbnail data. + /// This is not used for primary image JPEG data. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? JPEGInterchangeFormat + { + get + { + return GetTagValue("JPEGInterchangeFormat"); + } + set + { + SetTagValue("JPEGInterchangeFormat", value); + } + } + + /// + /// Gets or sets the number of bytes of JPEG compressed thumbnail data. + /// + /// + /// This is not used for primary image JPEG data. + /// JPEG thumbnails are not divided but are recorded as a continuous + /// JPEG bitstream from SOI to EOI. APPn and COM markers should not be recorded. + /// Compressed thumbnails shall be recorded in no more than 64 Kbytes, + /// including all other data to be recorded in APP1. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public uint? JPEGInterchangeFormatLength + { + get + { + return GetTagValue("JPEGInterchangeFormatLength"); + } + set + { + SetTagValue("JPEGInterchangeFormatLength", value); + } + } + + /// + /// Gets or sets a transfer function for the image, described in tabular style. + /// Constant length of 3 * 256. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort[] TransferFunction + { + get + { + return GetTagArray("TransferFunction"); + } + set + { + FreeImage.Resize(ref value, 3 * 256); + SetTagValue("TransferFunction", value); + } + } + + /// + /// Gets or sets the chromaticity of the white point of the image. + /// Constant length of 2. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational[] WhitePoint + { + get + { + return GetTagArray("WhitePoint"); + } + set + { + FreeImage.Resize(ref value, 2); + SetTagValue("WhitePoint", value); + } + } + + /// + /// Gets or sets the chromaticity of the three primary colors of the image. + /// Constant length of 6. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational[] PrimaryChromaticities + { + get + { + return GetTagArray("PrimaryChromaticities"); + } + set + { + FreeImage.Resize(ref value, 6); + SetTagValue("PrimaryChromaticities", value); + } + } + + /// + /// Gets or sets the matrix coefficients for transformation from RGB to YCbCr image data. + /// Constant length of 3. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational[] YCbCrCoefficients + { + get + { + return GetTagArray("YCbCrCoefficients"); + } + set + { + FreeImage.Resize(ref value, 3); + SetTagValue("PrimaryChromaticities", value); + } + } + + /// + /// Gets or sets the reference black point value and reference white point value. + /// Constant length of 6. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational[] ReferenceBlackWhite + { + get + { + return GetTagArray("ReferenceBlackWhite"); + } + set + { + FreeImage.Resize(ref value, 6); + SetTagValue("ReferenceBlackWhite", value); + } + } + + /// + /// Gets or sets the date and time of image creation. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public DateTime? DateTime + { + get + { + DateTime? result = null; + string text = GetTagText("DateTime"); + if (text != null) + { + try + { + result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null); + } + catch + { + } + } + return result; + } + set + { + string val = null; + if (value.HasValue) + { + try + { + val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0"); + } + catch + { + } + } + SetTagValue("DateTime", val); + } + } + + /// + /// Gets or sets a string giving the title of the image. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ImageDescription + { + get + { + string result = GetTagText("ImageDescription"); + if (!string.IsNullOrEmpty(result)) + { + result = result.Substring(0, result.Length - 1); + } + return result; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("ImageDescription", value); + } + } + + /// + /// Gets or sets the manufacturer of the recording equipment. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Make + { + get + { + string result = GetTagText("Make"); + if (!string.IsNullOrEmpty(result)) + { + result = result.Substring(0, result.Length - 1); + } + return result; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("Make", value); + } + } + + /// + /// Gets or sets the model name or model number of the equipment. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string EquipmentModel + { + get + { + string result = GetTagText("Model"); + if (!string.IsNullOrEmpty(result)) + { + result = result.Substring(0, result.Length - 1); + } + return result; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("Model", value); + } + } + + /// + /// Gets or sets the name and version of the software or firmware of the camera + /// or image input device used to generate the image. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Software + { + get + { + string result = GetTagText("Software"); + if (!string.IsNullOrEmpty(result)) + { + result = result.Substring(0, result.Length - 1); + } + return result; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("Software", value); + } + } + + /// + /// Gets or sets the name of the camera owner, photographer or image creator. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Artist + { + get + { + string result = GetTagText("Artist"); + if (!string.IsNullOrEmpty(result)) + { + result = result.Substring(0, result.Length - 1); + } + return result; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("Artist", value); + } + } + + /// + /// Gets or sets the photographer and editor copyrights. + /// Constant length of 1-2. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string[] Copyright + { + get + { + string[] result = null; + string text = GetTagText("Copyright"); + if (!string.IsNullOrEmpty(text)) + { + result = text.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); + } + return result; + } + set + { + string val = null; + if (value != null) + { + if (value.Length == 1) + { + if (value[0] != null) + { + val = value[0] + '\0'; + } + } + else if (value.Length == 2) + { + if ((value[0] != null) && (value[1] != null)) + { + val = value[0] + '\0' + value[1] + '\0'; + } + } + } + SetTagValue("Copyright", val); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_MAKERNOTE : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_MAKERNOTE(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_MAKERNOTE; } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_GEOTIFF : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_GEOTIFF(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_GEOTIFF; } + } + + /// + /// Gets or sets the value of the GeoTIFF GeoASCIIParamsTag. + /// + /// + /// The GeoASCIIParamsTag is used to store all of the valued + /// GeoKeys, referenced by the property. Since keys + /// defined in the GeoKeyDirectoryTag use offsets into this tag, any special + /// comments may be placed at the beginning of this tag. + /// For the most part, the only keys that are valued are + /// Citation keys, giving documentation and references for obscure + /// projections, datums, etc. + /// + /// Special handling is required for -valued keys. While it + /// is true that TIFF 6.0 permits multiple NULL-delimited strings within a single + /// ASCII tag, the secondary strings might not appear in the output of naive + /// tiffdump programs. For this reason, the NULL delimiter of each ASCII key + /// value shall be converted to a "|" (pipe) character before being installed + /// back into the holding tag, so that a dump of the tag + /// will look like this. + /// + /// AsciiTag="first_value|second_value|etc...last_value|" + /// + /// A baseline GeoTIFF-reader must check for and convert the final "|" pipe + /// character of a key back into a NULL before returning it to the client + /// software. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public string GeoASCIIParams + { + get + { + string text = GetTagText("GeoASCIIParams"); + if (!string.IsNullOrEmpty(text)) + { + text = text.Substring(0, text.Length - 1); + } + return text; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("GeoASCIIParams", value); + } + } + + /// + /// Gets or sets the value of the GeoTIFF GeoDoubleParamsTag. + /// + /// + /// The GeoDoubleParamsTag is used to store all of the valued + /// GeoKeys, referenced by the property. The meaning of + /// any value of this double array is determined from the GeoKeyDirectoryTag reference + /// pointing to it. values should first be converted to + /// and stored here. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public double[] GeoDoubleParams + { + get + { + return GetTagArray("GeoDoubleParams"); + } + set + { + SetTagValue("GeoDoubleParams", value); + } + } + + /// + /// Gets or sets the value of the GeoTIFF GeoKeyDirectoryTag. + /// + /// + /// The GeoKeyDirectoryTag may be used to store the GeoKey Directory, which defines and + /// references the GeoKeys. + /// + /// The tag is an array of unsigned values, which are primarily + /// grouped into blocks of 4. The first 4 values are special, and contain GeoKey directory + /// header information. The header values consist of the following information, in order: + /// + /// Header={KeyDirectoryVersion, KeyRevision, MinorRevision, NumberOfKeys} + /// + /// where + /// + /// KeyDirectoryVersion indicates the current version of Key implementation, and will + /// only change if this Tag's Key structure is changed. (Similar to the TIFFVersion (42)). + /// The current DirectoryVersion number is 1. This value will most likely never change, + /// and may be used to ensure that this is a valid Key-implementation. + /// + /// KeyRevision indicates what revision of Key-Sets are used. + /// + /// MinorRevision indicates what set of Key-Codes are used. The complete revision number + /// is denoted <KeyRevision>.<MinorRevision>. + /// + /// NumberOfKeys indicates how many Keys are defined by the rest of this Tag. + /// + /// This header is immediately followed by a collection of <NumberOfKeys> KeyEntry + /// sets, each of which is also 4- long. Each KeyEntry is modeled on the + /// TIFFEntry format of the TIFF directory header, and is of the form: + /// + /// KeyEntry = { KeyID, TIFFTagLocation, Count, Value_Offset } + /// + /// where + /// + /// KeyID gives the Key-ID value of the Key (identical in function to TIFF tag ID, + /// but completely independent of TIFF tag-space), + /// + /// TIFFTagLocation indicates which TIFF tag contains the value(s) of the Key: if + /// TIFFTagLocation is 0, then the value is , and is contained in the + /// Value_Offset entry. Otherwise, the type (format) of the value is implied by the + /// TIFF-Type of the tag containing the value. + /// + /// Count indicates the number of values in this key. + /// + /// Value_Offset Value_Offset indicates the index-offset into the TagArray indicated + /// by TIFFTagLocation, if it is nonzero. If TIFFTagLocation is 0 (zero) , then Value_Offset + /// contains the actual () value of the Key, and Count=1 is implied. + /// Note that the offset is not a byte-offset, but rather an index based on the natural data + /// type of the specified tag array. + /// + /// Following the KeyEntry definitions, the KeyDirectory tag may also contain additional + /// values. For example, if a key requires multiple values, they shall + /// be placed at the end of this tag, and the KeyEntry will set + /// TIFFTagLocation=GeoKeyDirectoryTag, with the Value_Offset pointing to the location of the + /// value(s). + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort[] GeoKeyDirectory + { + get + { + return GetTagArray("GeoKeyDirectory"); + } + set + { + SetTagValue("GeoKeyDirectory", value); + } + } + + /// + /// Gets or sets the value of the GeoTIFF ModelPixelScaleTag. + /// + /// + /// The ModelPixelScaleTag tag may be used to specify the size of raster pixel spacing + /// in the model space units, when the raster space can be embedded in the model space + /// coordinate system without rotation, and consists of the following 3 values: + /// + /// ModelPixelScaleTag = (ScaleX, ScaleY, ScaleZ) + /// + /// where ScaleX and ScaleY give the horizontal and vertical spacing of + /// raster pixels. The ScaleZ is primarily used to map the pixel value of a + /// digital elevation model into the correct Z-scale, and so for most other purposes + /// this value should be zero (since most model spaces are 2-D, with Z=0). + /// + /// A single tiepoint in the tag, together with this tag, + /// completely determine the relationship between raster and model space; thus they + /// comprise the two tags which Baseline GeoTIFF files most often will use to place a + /// raster image into a "standard position" in model space. + /// + /// Like the tag, this tag information is independent of the + /// XPosition, YPosition, Resolution and Orientation tags of the standard TIFF 6.0 spec. + /// However, simple reversals of orientation between raster and model space + /// (e.g. horizontal or vertical flips) may be indicated by reversal of sign in the + /// corresponding component of the ModelPixelScaleTag. GeoTIFF compliant readers must + /// honor this signreversal convention. + /// + /// This tag must not be used if the raster image requires rotation or shearing to place + /// it into the standard model space. In such cases the transformation shall be defined + /// with the more general . + /// + ///
    Naming differences + /// In the native FreeImage library and thus, in the FreeImage API documentation, this + /// property's key is named GeoPixelScale. Since the GeoTIFF specification + /// as well as Java's EXIFTIFFTagSet class call this tag + /// , this property was renamed accordingly. + /// However, when accessing this property's tag by its object, + /// the native FreeImage tag key GeoPixelScale must be used. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public double[] ModelPixelScale + { + get + { + return GetTagArray("GeoPixelScale"); + } + set + { + SetTagValue("GeoPixelScale", value); + } + } + + /// + /// Gets or sets the value of the GeoTIFF GeoTiePointsTag. + /// + /// + /// The GeoTiePointsTag stores raster -> model tiepoint pairs in the order + /// + /// ModelTiePoints = (...,I,J,K, X,Y,Z...), + /// + /// where (I,J,K) is the point at location (I,J) in raster space with + /// pixel-value K, and (X,Y,Z) is a vector in model space. In most cases + /// the model space is only two-dimensional, in which case both K and Z should be set + /// to zero; this third dimension is provided in anticipation of future support for 3D + /// digital elevation models and vertical coordinate systems. + /// + /// A raster image may be georeferenced simply by specifying its location, size and + /// orientation in the model coordinate space M. This may be done by specifying the + /// location of three of the four bounding corner points. However, tiepoints are only + /// to be considered exact at the points specified; thus defining such a set of + /// bounding tiepoints does not imply that the model space locations of the interior + /// of the image may be exactly computed by a linear interpolation of these tiepoints. + /// + /// However, since the relationship between the Raster space and the model space will + /// often be an exact, affine transformation, this relationship can be defined using + /// one set of tiepoints and the , described below, which + /// gives the vertical and horizontal raster grid cell size, specified in model units. + /// + /// If possible, the first tiepoint placed in this tag shall be the one establishing + /// the location of the point (0,0) in raster space. However, if this is not possible + /// (for example, if (0,0) is goes to a part of model space in which the projection is + /// ill-defined), then there is no particular order in which the tiepoints need be + /// listed. + /// + /// For orthorectification or mosaicking applications a large number of tiepoints may + /// be specified on a mesh over the raster image. However, the definition of associated + /// grid interpolation methods is not in the scope of the current GeoTIFF spec. + /// + ///
    Naming differences + /// In the native FreeImage library and thus, in the FreeImage API documentation, this + /// property's key is named GeoTiePoints. Since the GeoTIFF specification + /// as well as Java's EXIFTIFFTagSet class call this tag + /// , this property was renamed accordingly. + /// However, when accessing this property's tag by its object, + /// the native FreeImage tag key GeoTiePoints must be used. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public double[] ModelTiePoints + { + get + { + return GetTagArray("GeoTiePoints"); + } + set + { + SetTagValue("GeoTiePoints", value); + } + } + + /// + /// Gets or sets the value of the GeoTIFF ModelTransformationMatrixTag. + /// + /// + /// This tag may be used to specify the transformation matrix between the raster space + /// (and its dependent pixel-value space) and the (possibly 3D) model space. + /// + ///
    Naming differences + /// In the native FreeImage library and thus, in the FreeImage API documentation, this + /// property's key is named GeoTransformationMatrix. Since the GeoTIFF specification + /// as well as Java's EXIFTIFFTagSet class call this tag + /// , this property was renamed accordingly. + /// However, when accessing this property's tag by its object, + /// the native FreeImage tag key GeoTransformationMatrix must be used. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public double[] ModelTransformationMatrix + { + get + { + return GetTagArray("GeoTransformationMatrix"); + } + set + { + SetTagValue("GeoTransformationMatrix", value); + } + } + + /// + /// Gets or sets the value of the GeoTIFF IntergraphTransformationMatrixTag. + /// + /// + /// The IntergraphTransformationMatrixTag conflicts with an internal software implementation + /// at Intergraph, and so its use is no longer encouraged. A GeoTIFF reader should look first + /// for the new tag, and only if it is not found should it check for this older tag. If found, + /// it should only consider it to be contain valid GeoTIFF matrix information if the tag-count + /// is 16; the Intergraph version uses 17 values. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public double[] IntergraphTransformationMatrix + { + get + { + return GetTagArray("Intergraph TransformationMatrix"); + } + set + { + SetTagValue("Intergraph TransformationMatrix", value); + } + } + + /// + /// Gets or sets the value of the GeoTIFF JPLCartoIFDOffsetTag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? JPLCartoIFDOffset + { + get + { + return GetTagValue("JPL Carto IFD offset"); + } + set + { + SetTagValue("JPL Carto IFD offset", value); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_IPTC : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_IPTC(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_IPTC; } + } + + /// + /// Gets the Application Record Version. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public short? ApplicationRecordVersion + { + get + { + return GetTagValue("ApplicationRecordVersion"); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Object Type Reference. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ObjectTypeReference + { + get + { + return GetTagText("ObjectTypeReference"); + } + set + { + SetTagValue("ObjectTypeReference", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Object Attribute Reference. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ObjectAttributeReference + { + get + { + return GetTagText("ObjectAttributeReference"); + } + set + { + SetTagValue("ObjectAttributeReference", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Object Name. + /// This is also referred to as Title. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ObjectName + { + get + { + return GetTagText("ObjectName"); + } + set + { + SetTagValue("ObjectName", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Edit Status. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string EditStatus + { + get + { + return GetTagText("EditStatus"); + } + set + { + SetTagValue("EditStatus", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Editorial Update. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string EditorialUpdate + { + get + { + return GetTagText("EditorialUpdate"); + } + set + { + SetTagValue("EditorialUpdate", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Urgency. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Urgency + { + get + { + return GetTagText("Urgency"); + } + set + { + SetTagValue("Urgency", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Subject Reference. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SubjectReference + { + get + { + return GetTagText("SubjectReference"); + } + set + { + SetTagValue("SubjectReference", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Category. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Category + { + get + { + return GetTagText("Category"); + } + set + { + SetTagValue("Category", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Supplemental Categories. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SupplementalCategories + { + get + { + return GetTagText("SupplementalCategories"); + } + set + { + SetTagValue("SupplementalCategories", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Fixture Identifier. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string FixtureIdentifier + { + get + { + return GetTagText("FixtureIdentifier"); + } + set + { + SetTagValue("FixtureIdentifier", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Keywords. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Keywords + { + get + { + return GetTagText("Keywords"); + } + set + { + SetTagValue("Keywords", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Content Location Code. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ContentLocationCode + { + get + { + return GetTagText("ContentLocationCode"); + } + set + { + SetTagValue("ContentLocationCode", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Content Location Name. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ContentLocationName + { + get + { + return GetTagText("ContentLocationName"); + } + set + { + SetTagValue("ContentLocationName", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Release Date. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ReleaseDate + { + get + { + return GetTagText("ReleaseDate"); + } + set + { + SetTagValue("ReleaseDate", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Release Time. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ReleaseTime + { + get + { + return GetTagText("ReleaseTime"); + } + set + { + SetTagValue("ReleaseTime", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Expiration Date. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ExpirationDate + { + get + { + return GetTagText("ExpirationDate"); + } + set + { + SetTagValue("ExpirationDate", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Expiration Time. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ExpirationTime + { + get + { + return GetTagText("ExpirationTime"); + } + set + { + SetTagValue("ExpirationTime", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Special Instructions. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SpecialInstructions + { + get + { + return GetTagText("SpecialInstructions"); + } + set + { + SetTagValue("SpecialInstructions", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Action Advised. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ActionAdvised + { + get + { + return GetTagText("ActionAdvised"); + } + set + { + SetTagValue("ActionAdvised", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Reference Service. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ReferenceService + { + get + { + return GetTagText("ReferenceService"); + } + set + { + SetTagValue("ReferenceService", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Reference Date. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ReferenceDate + { + get + { + return GetTagText("ReferenceDate"); + } + set + { + SetTagValue("ReferenceDate", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Reference Number. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ReferenceNumber + { + get + { + return GetTagText("ReferenceNumber"); + } + set + { + SetTagValue("ReferenceNumber", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Date Created. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string DateCreated + { + get + { + return GetTagText("DateCreated"); + } + set + { + SetTagValue("DateCreated", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Time Created. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string TimeCreated + { + get + { + return GetTagText("TimeCreated"); + } + set + { + SetTagValue("TimeCreated", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Digital Creation Date. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string DigitalCreationDate + { + get + { + return GetTagText("DigitalCreationDate"); + } + set + { + SetTagValue("DigitalCreationDate", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Digital Creation Time. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string DigitalCreationTime + { + get + { + return GetTagText("DigitalCreationTime"); + } + set + { + SetTagValue("DigitalCreationTime", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Originating Program. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string OriginatingProgram + { + get + { + return GetTagText("OriginatingProgram"); + } + set + { + SetTagValue("OriginatingProgram", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Program Version. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ProgramVersion + { + get + { + return GetTagText("ProgramVersion"); + } + set + { + SetTagValue("ProgramVersion", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Object Cycle. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ObjectCycle + { + get + { + return GetTagText("ObjectCycle"); + } + set + { + SetTagValue("ObjectCycle", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag By Line. + /// This is the author's name. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ByLine + { + get + { + return GetTagText("By-line"); + } + set + { + SetTagValue("By-line", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag By Line Title. + /// This is the author's position. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ByLineTitle + { + get + { + return GetTagText("By-lineTitle"); + } + set + { + SetTagValue("By-lineTitle", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag City. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string City + { + get + { + return GetTagText("City"); + } + set + { + SetTagValue("City", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Sub Location. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SubLocation + { + get + { + return GetTagText("SubLocation"); + } + set + { + SetTagValue("SubLocation", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Province State. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ProvinceState + { + get + { + return GetTagText("ProvinceState"); + } + set + { + SetTagValue("ProvinceState", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Country Primary Location Code. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string CountryPrimaryLocationCode + { + get + { + return GetTagText("Country-PrimaryLocationCode"); + } + set + { + SetTagValue("Country-PrimaryLocationCode", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Country Primary Location Name. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string CountryPrimaryLocationName + { + get + { + return GetTagText("Country-PrimaryLocationName"); + } + set + { + SetTagValue("Country-PrimaryLocationName", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Original Transmission Reference. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string OriginalTransmissionReference + { + get + { + return GetTagText("OriginalTransmissionReference"); + } + set + { + SetTagValue("OriginalTransmissionReference", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Headline. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Headline + { + get + { + return GetTagText("Headline"); + } + set + { + SetTagValue("Headline", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Credit. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Credit + { + get + { + return GetTagText("Credit"); + } + set + { + SetTagValue("Credit", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Source. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Source + { + get + { + return GetTagText("Source"); + } + set + { + SetTagValue("Source", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Copyright Notice. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string CopyrightNotice + { + get + { + return GetTagText("CopyrightNotice"); + } + set + { + SetTagValue("CopyrightNotice", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Contact. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Contact + { + get + { + return GetTagText("Contact"); + } + set + { + SetTagValue("Contact", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Caption Abstract. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string CaptionAbstract + { + get + { + return GetTagText("CaptionAbstract"); + } + set + { + SetTagValue("CaptionAbstract", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Writer Editor. + /// This is also referred to as Caption Writer. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string WriterEditor + { + get + { + return GetTagText("WriterEditor"); + } + set + { + SetTagValue("WriterEditor", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Rasterized Caption. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string RasterizedCaption + { + get + { + return GetTagText("RasterizedCaption"); + } + set + { + SetTagValue("RasterizedCaption", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Image Type. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ImageType + { + get + { + return GetTagText("ImageType"); + } + set + { + SetTagValue("ImageType", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Image Orientation. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ImageOrientation + { + get + { + return GetTagText("ImageOrientation"); + } + set + { + SetTagValue("ImageOrientation", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Language Identifier. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string LanguageIdentifier + { + get + { + return GetTagText("LanguageIdentifier"); + } + set + { + SetTagValue("LanguageIdentifier", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Audio Type. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string AudioType + { + get + { + return GetTagText("AudioType"); + } + set + { + SetTagValue("AudioType", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Audio Sampling Rate. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string AudioSamplingRate + { + get + { + return GetTagText("AudioSamplingRate"); + } + set + { + SetTagValue("AudioSamplingRate", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Audio Sampling Resolution. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string AudioSamplingResolution + { + get + { + return GetTagText("AudioSamplingResolution"); + } + set + { + SetTagValue("AudioSamplingResolution", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Audio Duration. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string AudioDuration + { + get + { + return GetTagText("AudioDuration"); + } + set + { + SetTagValue("AudioDuration", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Audio Outcue. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string AudioOutcue + { + get + { + return GetTagText("AudioOutcue"); + } + set + { + SetTagValue("AudioOutcue", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Job I D. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string JobID + { + get + { + return GetTagText("JobID"); + } + set + { + SetTagValue("JobID", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Master Document I D. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string MasterDocumentID + { + get + { + return GetTagText("MasterDocumentID"); + } + set + { + SetTagValue("MasterDocumentID", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Short Document I D. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ShortDocumentID + { + get + { + return GetTagText("ShortDocumentID"); + } + set + { + SetTagValue("ShortDocumentID", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Unique Document I D. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string UniqueDocumentID + { + get + { + return GetTagText("UniqueDocumentID"); + } + set + { + SetTagValue("UniqueDocumentID", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Owner I D. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string OwnerID + { + get + { + return GetTagText("OwnerID"); + } + set + { + SetTagValue("OwnerID", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Object Preview File Format. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ObjectPreviewFileFormat + { + get + { + return GetTagText("ObjectPreviewFileFormat"); + } + set + { + SetTagValue("ObjectPreviewFileFormat", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Object Preview File Version. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ObjectPreviewFileVersion + { + get + { + return GetTagText("ObjectPreviewFileVersion"); + } + set + { + SetTagValue("ObjectPreviewFileVersion", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Object Preview Data. + /// This is also referred to as Audio Outcue. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ObjectPreviewData + { + get + { + return GetTagText("ObjectPreviewData"); + } + set + { + SetTagValue("ObjectPreviewData", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Prefs. + /// This is also referred to as photo-mechanic preferences. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Prefs + { + get + { + return GetTagText("Prefs"); + } + set + { + SetTagValue("Prefs", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Classify State. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ClassifyState + { + get + { + return GetTagText("ClassifyState"); + } + set + { + SetTagValue("ClassifyState", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Similarity Index. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SimilarityIndex + { + get + { + return GetTagText("SimilarityIndex"); + } + set + { + SetTagValue("SimilarityIndex", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Document Notes. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string DocumentNotes + { + get + { + return GetTagText("DocumentNotes"); + } + set + { + SetTagValue("DocumentNotes", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Document History. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string DocumentHistory + { + get + { + return GetTagText("DocumentHistory"); + } + set + { + SetTagValue("DocumentHistory", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Exif Camera Info. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ExifCameraInfo + { + get + { + return GetTagText("ExifCameraInfo"); + } + set + { + SetTagValue("ExifCameraInfo", value); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_NODATA : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_NODATA(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_NODATA; } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_XMP : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_XMP(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_XMP; } + } + + /// + /// Gets or sets the XMP XML content. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Xml + { + get + { + return GetTagText("XMLPacket"); + } + set + { + SetTagValue("XMLPacket", value); + } + } + + /// + /// Gets an initialized to read the XMP XML content. + /// Returns null, if the metadata tag XMLPacket is not present in + /// this model. + /// + public XmlReader XmlReader + { + get + { + string xmlString = Xml; + if (xmlString == null) + { + return null; + } + else + { + MemoryStream stream = new MemoryStream(); + StreamWriter writer = new StreamWriter(stream); + writer.Write(xmlString); + return XmlReader.Create(stream); + } + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/MetadataTag.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/MetadataTag.cs index 8fa580d..5a811e0 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/MetadataTag.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/MetadataTag.cs @@ -1,757 +1,757 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.9 $ -// $Date: 2009/02/27 16:35:12 $ -// $Id: MetadataTag.cs,v 1.9 2009/02/27 16:35:12 cklein05 Exp $ -// ========================================================== - -using System; -using System.Text; -using System.Runtime.InteropServices; -using System.Collections.Generic; -using System.Diagnostics; - -namespace FreeImageAPI.Metadata -{ - /// - /// Manages metadata objects and operations. - /// - public sealed class MetadataTag : IComparable, IComparable, ICloneable, IEquatable, IDisposable - { - /// - /// The encapsulated FreeImage-tag. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - internal FITAG tag; - - /// - /// The metadata model of . - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private FREE_IMAGE_MDMODEL model; - - /// - /// Indicates whether this instance has already been disposed. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool disposed = false; - - /// - /// Indicates whether this instance was created by FreeImage or - /// by the user. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool selfCreated; - - /// - /// List linking metadata-model and Type. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private static readonly Dictionary idList; - - /// - /// List linking Type and metadata-model. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private static readonly Dictionary typeList; - - /// - /// Initializes a new instance of this class. - /// - private MetadataTag() - { - } - - /// - /// Initializes a new instance of this class. - /// - /// The new model the tag should be of. - public MetadataTag(FREE_IMAGE_MDMODEL model) - { - this.model = model; - tag = FreeImage.CreateTag(); - selfCreated = true; - - if (model == FREE_IMAGE_MDMODEL.FIMD_XMP) - { - Key = "XMLPacket"; - } - } - - /// - /// Initializes a new instance of this class. - /// - /// The to represent. - /// The bitmap was extracted from. - public MetadataTag(FITAG tag, FIBITMAP dib) - { - if (tag.IsNull) - { - throw new ArgumentNullException("tag"); - } - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - this.tag = tag; - model = GetModel(dib, tag); - selfCreated = false; - - if (model == FREE_IMAGE_MDMODEL.FIMD_XMP) - { - Key = "XMLPacket"; - } - } - - /// - /// Initializes a new instance of this class. - /// - /// The to represent. - /// The model of . - public MetadataTag(FITAG tag, FREE_IMAGE_MDMODEL model) - { - if (tag.IsNull) - { - throw new ArgumentNullException("tag"); - } - this.tag = tag; - this.model = model; - selfCreated = false; - - if (model == FREE_IMAGE_MDMODEL.FIMD_XMP) - { - Key = "XMLPacket"; - } - } - - static MetadataTag() - { - idList = new Dictionary(); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_BYTE, typeof(byte)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_SHORT, typeof(ushort)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_LONG, typeof(uint)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_RATIONAL, typeof(FIURational)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_SBYTE, typeof(sbyte)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_UNDEFINED, typeof(byte)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_SSHORT, typeof(short)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_SLONG, typeof(int)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_SRATIONAL, typeof(FIRational)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_FLOAT, typeof(float)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_DOUBLE, typeof(double)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_IFD, typeof(uint)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_PALETTE, typeof(RGBQUAD)); - - typeList = new Dictionary(); - typeList.Add(typeof(ushort), FREE_IMAGE_MDTYPE.FIDT_SHORT); - typeList.Add(typeof(ushort[]), FREE_IMAGE_MDTYPE.FIDT_SHORT); - typeList.Add(typeof(string), FREE_IMAGE_MDTYPE.FIDT_ASCII); - typeList.Add(typeof(uint), FREE_IMAGE_MDTYPE.FIDT_LONG); - typeList.Add(typeof(uint[]), FREE_IMAGE_MDTYPE.FIDT_LONG); - typeList.Add(typeof(FIURational), FREE_IMAGE_MDTYPE.FIDT_RATIONAL); - typeList.Add(typeof(FIURational[]), FREE_IMAGE_MDTYPE.FIDT_RATIONAL); - typeList.Add(typeof(sbyte), FREE_IMAGE_MDTYPE.FIDT_SBYTE); - typeList.Add(typeof(sbyte[]), FREE_IMAGE_MDTYPE.FIDT_SBYTE); - typeList.Add(typeof(byte), FREE_IMAGE_MDTYPE.FIDT_BYTE); - typeList.Add(typeof(byte[]), FREE_IMAGE_MDTYPE.FIDT_BYTE); - typeList.Add(typeof(short), FREE_IMAGE_MDTYPE.FIDT_SSHORT); - typeList.Add(typeof(short[]), FREE_IMAGE_MDTYPE.FIDT_SSHORT); - typeList.Add(typeof(int), FREE_IMAGE_MDTYPE.FIDT_SLONG); - typeList.Add(typeof(int[]), FREE_IMAGE_MDTYPE.FIDT_SLONG); - typeList.Add(typeof(FIRational), FREE_IMAGE_MDTYPE.FIDT_SRATIONAL); - typeList.Add(typeof(FIRational[]), FREE_IMAGE_MDTYPE.FIDT_SRATIONAL); - typeList.Add(typeof(float), FREE_IMAGE_MDTYPE.FIDT_FLOAT); - typeList.Add(typeof(float[]), FREE_IMAGE_MDTYPE.FIDT_FLOAT); - typeList.Add(typeof(double), FREE_IMAGE_MDTYPE.FIDT_DOUBLE); - typeList.Add(typeof(double[]), FREE_IMAGE_MDTYPE.FIDT_DOUBLE); - typeList.Add(typeof(RGBQUAD), FREE_IMAGE_MDTYPE.FIDT_PALETTE); - typeList.Add(typeof(RGBQUAD[]), FREE_IMAGE_MDTYPE.FIDT_PALETTE); - } - - /// - /// Releases all resources used by the instance. - /// - ~MetadataTag() - { - Dispose(); - } - - /// - /// Determines whether two specified objects have the same value. - /// - /// A or a null reference (Nothing in Visual Basic). - /// A or a null reference (Nothing in Visual Basic). - /// - /// true if the value of left is the same as the value of right; otherwise, false. - /// - public static bool operator ==(MetadataTag left, MetadataTag right) - { - // Check whether both are null - if ((object)left == (object)right) - { - return true; - } - else if ((object)left == null || (object)right == null) - { - return false; - } - left.CheckDisposed(); - right.CheckDisposed(); - // Check all properties - if ((left.Key != right.Key) || - (left.ID != right.ID) || - (left.Description != right.Description) || - (left.Count != right.Count) || - (left.Length != right.Length) || - (left.Model != right.Model) || - (left.Type != right.Type)) - { - return false; - } - if (left.Length == 0) - { - return true; - } - IntPtr ptr1 = FreeImage.GetTagValue(left.tag); - IntPtr ptr2 = FreeImage.GetTagValue(right.tag); - return FreeImage.CompareMemory(ptr1, ptr2, left.Length); - } - - /// - /// Determines whether two specified objects have different values. - /// - /// A or a null reference (Nothing in Visual Basic). - /// A or a null reference (Nothing in Visual Basic). - /// - /// true if the value of left is different from the value of right; otherwise, false. - /// - public static bool operator !=(MetadataTag left, MetadataTag right) - { - return !(left == right); - } - - /// - /// Extracts the value of a instance to a handle. - /// - /// A instance. - /// A new instance of initialized to . - public static implicit operator FITAG(MetadataTag value) - { - return value.tag; - } - - private static FREE_IMAGE_MDMODEL GetModel(FIBITMAP dib, FITAG tag) - { - FITAG value; - foreach (FREE_IMAGE_MDMODEL model in FreeImage.FREE_IMAGE_MDMODELS) - { - FIMETADATA mData = FreeImage.FindFirstMetadata(model, dib, out value); - if (mData.IsNull) - { - continue; - } - try - { - do - { - if (value == tag) - { - return model; - } - } - while (FreeImage.FindNextMetadata(mData, out value)); - } - finally - { - if (!mData.IsNull) - { - FreeImage.FindCloseMetadata(mData); - } - } - } - throw new ArgumentException("'tag' is no metadata object of 'dib'"); - } - - /// - /// Gets the model of the metadata. - /// - public FREE_IMAGE_MDMODEL Model - { - get { CheckDisposed(); return model; } - } - - /// - /// Gets or sets the key of the metadata. - /// - public string Key - { - get { CheckDisposed(); return FreeImage.GetTagKey(tag); } - set - { - CheckDisposed(); - if ((model != FREE_IMAGE_MDMODEL.FIMD_XMP) || (value == "XMLPacket")) - { - FreeImage.SetTagKey(tag, value); - } - } - } - - /// - /// Gets or sets the description of the metadata. - /// - public string Description - { - get { CheckDisposed(); return FreeImage.GetTagDescription(tag); } - set { CheckDisposed(); FreeImage.SetTagDescription(tag, value); } - } - - /// - /// Gets or sets the ID of the metadata. - /// - public ushort ID - { - get { CheckDisposed(); return FreeImage.GetTagID(tag); } - set { CheckDisposed(); FreeImage.SetTagID(tag, value); } - } - - /// - /// Gets the type of the metadata. - /// - public FREE_IMAGE_MDTYPE Type - { - get { CheckDisposed(); return FreeImage.GetTagType(tag); } - internal set { FreeImage.SetTagType(tag, value); } - } - - /// - /// Gets the number of elements the metadata object contains. - /// - public uint Count - { - get { CheckDisposed(); return FreeImage.GetTagCount(tag); } - private set { FreeImage.SetTagCount(tag, value); } - } - - /// - /// Gets the length of the value in bytes. - /// - public uint Length - { - get { CheckDisposed(); return FreeImage.GetTagLength(tag); } - private set { FreeImage.SetTagLength(tag, value); } - } - - private unsafe byte[] GetData() - { - uint length = Length; - byte[] value = new byte[length]; - byte* ptr = (byte*)FreeImage.GetTagValue(tag); - for (int i = 0; i < length; i++) - { - value[i] = ptr[i]; - } - return value; - } - - /// - /// Gets or sets the value of the metadata. - /// - public object Value - { - get - { - unsafe - { - CheckDisposed(); - int cnt = (int)Count; - - if (Type == FREE_IMAGE_MDTYPE.FIDT_ASCII) - { - byte* value = (byte*)FreeImage.GetTagValue(tag); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < cnt; i++) - { - sb.Append(Convert.ToChar(value[i])); - } - return sb.ToString(); - } - else if (Type == FREE_IMAGE_MDTYPE.FIDT_NOTYPE) - { - return null; - } - - Array array = Array.CreateInstance(idList[Type], Count); - void* src = (void*)FreeImage.GetTagValue(tag); - FreeImage.CopyMemory(array, src, Length); - return array; - } - } - set - { - SetValue(value); - } - } - - /// - /// Sets the value of the metadata. - /// In case value is of byte or byte[] is assumed. - /// In case value is of uint or uint[] is assumed. - /// - /// New data of the metadata. - /// True on success, false on failure. - /// - /// The data format is not supported. - /// - /// is null. - public bool SetValue(object value) - { - Type type = value.GetType(); - if (!typeList.ContainsKey(type)) - { - throw new NotSupportedException("The type of value is not supported"); - } - return SetValue(value, typeList[type]); - } - - /// - /// Sets the value of the metadata. - /// - /// New data of the metadata. - /// Type of the data. - /// True on success, false on failure. - /// - /// The data type is not supported. - /// - /// is null. - /// - /// and to not fit. - public bool SetValue(object value, FREE_IMAGE_MDTYPE type) - { - CheckDisposed(); - if ((!value.GetType().IsArray) && (!(value is string))) - { - Array array = Array.CreateInstance(value.GetType(), 1); - array.SetValue(value, 0); - return SetArrayValue(array, type); - } - return SetArrayValue(value, type); - } - - /// - /// Sets the value of this tag to the value of - /// using the given type. - /// - /// New value of the tag. - /// Data-type of the tag. - /// - /// - /// is a null reference. - /// - /// - /// is FIDT_ASCII and - /// is not String. - /// is not FIDT_ASCII and - /// is not Array. - /// - /// is FIDT_NOTYPE. - private unsafe bool SetArrayValue(object value, FREE_IMAGE_MDTYPE type) - { - if (value == null) - { - throw new ArgumentNullException("value"); - } - - byte[] data = null; - - if (type == FREE_IMAGE_MDTYPE.FIDT_ASCII) - { - string tempValue = value as string; - if (tempValue == null) - { - throw new ArgumentException("value"); - } - Type = type; - Length = Count = (uint)tempValue.Length; - data = new byte[Length]; - - for (int i = 0; i < tempValue.Length; i++) - { - data[i] = (byte)tempValue[i]; - } - } - else if (type == FREE_IMAGE_MDTYPE.FIDT_NOTYPE) - { - throw new NotSupportedException("type is not supported."); - } - else - { - Array array = value as Array; - if (array == null) - { - throw new ArgumentException("value"); - } - - if (array.Length != 0) - if (!CheckType(array.GetValue(0).GetType(), type)) - throw new ArgumentException("The type of value is incorrect."); - - Type = type; - Count = (uint)array.Length; - Length = (uint)(array.Length * Marshal.SizeOf(idList[type])); - data = new byte[Length]; - FreeImage.CopyMemory(data, array, Length); - } - - return FreeImage.SetTagValue(tag, data); - } - - private static bool CheckType(Type dataType, FREE_IMAGE_MDTYPE type) - { - if (dataType != null) - switch (type) - { - case FREE_IMAGE_MDTYPE.FIDT_ASCII: - return dataType == typeof(string); - case FREE_IMAGE_MDTYPE.FIDT_BYTE: - return dataType == typeof(byte); - case FREE_IMAGE_MDTYPE.FIDT_DOUBLE: - return dataType == typeof(double); - case FREE_IMAGE_MDTYPE.FIDT_FLOAT: - return dataType == typeof(float); - case FREE_IMAGE_MDTYPE.FIDT_IFD: - return dataType == typeof(uint); - case FREE_IMAGE_MDTYPE.FIDT_LONG: - return dataType == typeof(uint); - case FREE_IMAGE_MDTYPE.FIDT_NOTYPE: - return false; - case FREE_IMAGE_MDTYPE.FIDT_PALETTE: - return dataType == typeof(RGBQUAD); - case FREE_IMAGE_MDTYPE.FIDT_RATIONAL: - return dataType == typeof(FIURational); - case FREE_IMAGE_MDTYPE.FIDT_SBYTE: - return dataType == typeof(sbyte); - case FREE_IMAGE_MDTYPE.FIDT_SHORT: - return dataType == typeof(ushort); - case FREE_IMAGE_MDTYPE.FIDT_SLONG: - return dataType == typeof(int); - case FREE_IMAGE_MDTYPE.FIDT_SRATIONAL: - return dataType == typeof(FIRational); - case FREE_IMAGE_MDTYPE.FIDT_SSHORT: - return dataType == typeof(short); - case FREE_IMAGE_MDTYPE.FIDT_UNDEFINED: - return dataType == typeof(byte); - } - return false; - } - - /// - /// Add this metadata to an image. - /// - /// Handle to a FreeImage bitmap. - /// True on success, false on failure. - public bool AddToImage(FIBITMAP dib) - { - CheckDisposed(); - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - if (Key == null) - { - throw new ArgumentNullException("Key"); - } - if (!selfCreated) - { - tag = FreeImage.CloneTag(tag); - if (tag.IsNull) - { - throw new Exception("FreeImage.CloneTag() failed."); - } - selfCreated = true; - } - if (!FreeImage.SetMetadata(Model, dib, Key, tag)) - { - return false; - } - FREE_IMAGE_MDMODEL _model = Model; - string _key = Key; - selfCreated = false; - FreeImage.DeleteTag(tag); - return FreeImage.GetMetadata(_model, dib, _key, out tag); - } - - /// - /// Gets a .NET PropertyItem for this metadata tag. - /// - /// The .NET PropertyItem. - public unsafe System.Drawing.Imaging.PropertyItem GetPropertyItem() - { - System.Drawing.Imaging.PropertyItem item = FreeImage.CreatePropertyItem(); - item.Id = ID; - item.Len = (int)Length; - item.Type = (short)Type; - FreeImage.CopyMemory(item.Value = new byte[item.Len], FreeImage.GetTagValue(tag), item.Len); - return item; - } - - /// - /// Converts the value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - CheckDisposed(); - string fiString = FreeImage.TagToString(model, tag, 0); - - if (String.IsNullOrEmpty(fiString)) - { - return tag.ToString(); - } - else - { - return fiString; - } - } - - /// - /// Creates a deep copy of this . - /// - /// A deep copy of this . - public object Clone() - { - CheckDisposed(); - MetadataTag clone = new MetadataTag(); - clone.model = model; - clone.tag = FreeImage.CloneTag(tag); - clone.selfCreated = true; - return clone; - } - - /// - /// Tests whether the specified object is a instance - /// and is equivalent to this instance. - /// - /// The object to test. - /// true if is a instance - /// equivalent to this instance; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is MetadataTag) && (Equals((MetadataTag)obj))); - } - - /// - /// Tests whether the specified instance is equivalent to this instance. - /// - /// A instance to compare to this instance. - /// true if equivalent to this instance; - /// otherwise, false. - public bool Equals(MetadataTag other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return tag.GetHashCode(); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is MetadataTag)) - { - throw new ArgumentException("obj"); - } - return CompareTo((MetadataTag)obj); - } - - /// - /// Compares the current instance with another object of the same type. - /// - /// An object to compare with this instance. - /// A 32-bit signed integer that indicates the relative order of the objects being compared. - public int CompareTo(MetadataTag other) - { - CheckDisposed(); - other.CheckDisposed(); - return tag.CompareTo(other.tag); - } - - /// - /// Releases all resources used by the instance. - /// - public void Dispose() - { - if (!disposed) - { - disposed = true; - if (selfCreated) - { - FreeImage.DeleteTag(tag); - tag = FITAG.Zero; - } - } - } - - /// - /// Gets whether this instance has already been disposed. - /// - public bool Disposed - { - get { return disposed; } - } - - /// - /// Throwns an in case - /// this instance has already been disposed. - /// - private void CheckDisposed() - { - if (disposed) - { - throw new ObjectDisposedException("The object has already been disposed."); - } - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.9 $ +// $Date: 2009/02/27 16:35:12 $ +// $Id: MetadataTag.cs,v 1.9 2009/02/27 16:35:12 cklein05 Exp $ +// ========================================================== + +using System; +using System.Text; +using System.Runtime.InteropServices; +using System.Collections.Generic; +using System.Diagnostics; + +namespace FreeImageAPI.Metadata +{ + /// + /// Manages metadata objects and operations. + /// + public sealed class MetadataTag : IComparable, IComparable, ICloneable, IEquatable, IDisposable + { + /// + /// The encapsulated FreeImage-tag. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + internal FITAG tag; + + /// + /// The metadata model of . + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private FREE_IMAGE_MDMODEL model; + + /// + /// Indicates whether this instance has already been disposed. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool disposed = false; + + /// + /// Indicates whether this instance was created by FreeImage or + /// by the user. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool selfCreated; + + /// + /// List linking metadata-model and Type. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private static readonly Dictionary idList; + + /// + /// List linking Type and metadata-model. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private static readonly Dictionary typeList; + + /// + /// Initializes a new instance of this class. + /// + private MetadataTag() + { + } + + /// + /// Initializes a new instance of this class. + /// + /// The new model the tag should be of. + public MetadataTag(FREE_IMAGE_MDMODEL model) + { + this.model = model; + tag = FreeImage.CreateTag(); + selfCreated = true; + + if (model == FREE_IMAGE_MDMODEL.FIMD_XMP) + { + Key = "XMLPacket"; + } + } + + /// + /// Initializes a new instance of this class. + /// + /// The to represent. + /// The bitmap was extracted from. + public MetadataTag(FITAG tag, FIBITMAP dib) + { + if (tag.IsNull) + { + throw new ArgumentNullException("tag"); + } + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + this.tag = tag; + model = GetModel(dib, tag); + selfCreated = false; + + if (model == FREE_IMAGE_MDMODEL.FIMD_XMP) + { + Key = "XMLPacket"; + } + } + + /// + /// Initializes a new instance of this class. + /// + /// The to represent. + /// The model of . + public MetadataTag(FITAG tag, FREE_IMAGE_MDMODEL model) + { + if (tag.IsNull) + { + throw new ArgumentNullException("tag"); + } + this.tag = tag; + this.model = model; + selfCreated = false; + + if (model == FREE_IMAGE_MDMODEL.FIMD_XMP) + { + Key = "XMLPacket"; + } + } + + static MetadataTag() + { + idList = new Dictionary(); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_BYTE, typeof(byte)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_SHORT, typeof(ushort)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_LONG, typeof(uint)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_RATIONAL, typeof(FIURational)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_SBYTE, typeof(sbyte)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_UNDEFINED, typeof(byte)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_SSHORT, typeof(short)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_SLONG, typeof(int)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_SRATIONAL, typeof(FIRational)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_FLOAT, typeof(float)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_DOUBLE, typeof(double)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_IFD, typeof(uint)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_PALETTE, typeof(RGBQUAD)); + + typeList = new Dictionary(); + typeList.Add(typeof(ushort), FREE_IMAGE_MDTYPE.FIDT_SHORT); + typeList.Add(typeof(ushort[]), FREE_IMAGE_MDTYPE.FIDT_SHORT); + typeList.Add(typeof(string), FREE_IMAGE_MDTYPE.FIDT_ASCII); + typeList.Add(typeof(uint), FREE_IMAGE_MDTYPE.FIDT_LONG); + typeList.Add(typeof(uint[]), FREE_IMAGE_MDTYPE.FIDT_LONG); + typeList.Add(typeof(FIURational), FREE_IMAGE_MDTYPE.FIDT_RATIONAL); + typeList.Add(typeof(FIURational[]), FREE_IMAGE_MDTYPE.FIDT_RATIONAL); + typeList.Add(typeof(sbyte), FREE_IMAGE_MDTYPE.FIDT_SBYTE); + typeList.Add(typeof(sbyte[]), FREE_IMAGE_MDTYPE.FIDT_SBYTE); + typeList.Add(typeof(byte), FREE_IMAGE_MDTYPE.FIDT_BYTE); + typeList.Add(typeof(byte[]), FREE_IMAGE_MDTYPE.FIDT_BYTE); + typeList.Add(typeof(short), FREE_IMAGE_MDTYPE.FIDT_SSHORT); + typeList.Add(typeof(short[]), FREE_IMAGE_MDTYPE.FIDT_SSHORT); + typeList.Add(typeof(int), FREE_IMAGE_MDTYPE.FIDT_SLONG); + typeList.Add(typeof(int[]), FREE_IMAGE_MDTYPE.FIDT_SLONG); + typeList.Add(typeof(FIRational), FREE_IMAGE_MDTYPE.FIDT_SRATIONAL); + typeList.Add(typeof(FIRational[]), FREE_IMAGE_MDTYPE.FIDT_SRATIONAL); + typeList.Add(typeof(float), FREE_IMAGE_MDTYPE.FIDT_FLOAT); + typeList.Add(typeof(float[]), FREE_IMAGE_MDTYPE.FIDT_FLOAT); + typeList.Add(typeof(double), FREE_IMAGE_MDTYPE.FIDT_DOUBLE); + typeList.Add(typeof(double[]), FREE_IMAGE_MDTYPE.FIDT_DOUBLE); + typeList.Add(typeof(RGBQUAD), FREE_IMAGE_MDTYPE.FIDT_PALETTE); + typeList.Add(typeof(RGBQUAD[]), FREE_IMAGE_MDTYPE.FIDT_PALETTE); + } + + /// + /// Releases all resources used by the instance. + /// + ~MetadataTag() + { + Dispose(); + } + + /// + /// Determines whether two specified objects have the same value. + /// + /// A or a null reference (Nothing in Visual Basic). + /// A or a null reference (Nothing in Visual Basic). + /// + /// true if the value of left is the same as the value of right; otherwise, false. + /// + public static bool operator ==(MetadataTag left, MetadataTag right) + { + // Check whether both are null + if ((object)left == (object)right) + { + return true; + } + else if ((object)left == null || (object)right == null) + { + return false; + } + left.CheckDisposed(); + right.CheckDisposed(); + // Check all properties + if ((left.Key != right.Key) || + (left.ID != right.ID) || + (left.Description != right.Description) || + (left.Count != right.Count) || + (left.Length != right.Length) || + (left.Model != right.Model) || + (left.Type != right.Type)) + { + return false; + } + if (left.Length == 0) + { + return true; + } + IntPtr ptr1 = FreeImage.GetTagValue(left.tag); + IntPtr ptr2 = FreeImage.GetTagValue(right.tag); + return FreeImage.CompareMemory(ptr1, ptr2, left.Length); + } + + /// + /// Determines whether two specified objects have different values. + /// + /// A or a null reference (Nothing in Visual Basic). + /// A or a null reference (Nothing in Visual Basic). + /// + /// true if the value of left is different from the value of right; otherwise, false. + /// + public static bool operator !=(MetadataTag left, MetadataTag right) + { + return !(left == right); + } + + /// + /// Extracts the value of a instance to a handle. + /// + /// A instance. + /// A new instance of initialized to . + public static implicit operator FITAG(MetadataTag value) + { + return value.tag; + } + + private static FREE_IMAGE_MDMODEL GetModel(FIBITMAP dib, FITAG tag) + { + FITAG value; + foreach (FREE_IMAGE_MDMODEL model in FreeImage.FREE_IMAGE_MDMODELS) + { + FIMETADATA mData = FreeImage.FindFirstMetadata(model, dib, out value); + if (mData.IsNull) + { + continue; + } + try + { + do + { + if (value == tag) + { + return model; + } + } + while (FreeImage.FindNextMetadata(mData, out value)); + } + finally + { + if (!mData.IsNull) + { + FreeImage.FindCloseMetadata(mData); + } + } + } + throw new ArgumentException("'tag' is no metadata object of 'dib'"); + } + + /// + /// Gets the model of the metadata. + /// + public FREE_IMAGE_MDMODEL Model + { + get { CheckDisposed(); return model; } + } + + /// + /// Gets or sets the key of the metadata. + /// + public string Key + { + get { CheckDisposed(); return FreeImage.GetTagKey(tag); } + set + { + CheckDisposed(); + if ((model != FREE_IMAGE_MDMODEL.FIMD_XMP) || (value == "XMLPacket")) + { + FreeImage.SetTagKey(tag, value); + } + } + } + + /// + /// Gets or sets the description of the metadata. + /// + public string Description + { + get { CheckDisposed(); return FreeImage.GetTagDescription(tag); } + set { CheckDisposed(); FreeImage.SetTagDescription(tag, value); } + } + + /// + /// Gets or sets the ID of the metadata. + /// + public ushort ID + { + get { CheckDisposed(); return FreeImage.GetTagID(tag); } + set { CheckDisposed(); FreeImage.SetTagID(tag, value); } + } + + /// + /// Gets the type of the metadata. + /// + public FREE_IMAGE_MDTYPE Type + { + get { CheckDisposed(); return FreeImage.GetTagType(tag); } + internal set { FreeImage.SetTagType(tag, value); } + } + + /// + /// Gets the number of elements the metadata object contains. + /// + public uint Count + { + get { CheckDisposed(); return FreeImage.GetTagCount(tag); } + private set { FreeImage.SetTagCount(tag, value); } + } + + /// + /// Gets the length of the value in bytes. + /// + public uint Length + { + get { CheckDisposed(); return FreeImage.GetTagLength(tag); } + private set { FreeImage.SetTagLength(tag, value); } + } + + private unsafe byte[] GetData() + { + uint length = Length; + byte[] value = new byte[length]; + byte* ptr = (byte*)FreeImage.GetTagValue(tag); + for (int i = 0; i < length; i++) + { + value[i] = ptr[i]; + } + return value; + } + + /// + /// Gets or sets the value of the metadata. + /// + public object Value + { + get + { + unsafe + { + CheckDisposed(); + int cnt = (int)Count; + + if (Type == FREE_IMAGE_MDTYPE.FIDT_ASCII) + { + byte* value = (byte*)FreeImage.GetTagValue(tag); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < cnt; i++) + { + sb.Append(Convert.ToChar(value[i])); + } + return sb.ToString(); + } + else if (Type == FREE_IMAGE_MDTYPE.FIDT_NOTYPE) + { + return null; + } + + Array array = Array.CreateInstance(idList[Type], Count); + void* src = (void*)FreeImage.GetTagValue(tag); + FreeImage.CopyMemory(array, src, Length); + return array; + } + } + set + { + SetValue(value); + } + } + + /// + /// Sets the value of the metadata. + /// In case value is of byte or byte[] is assumed. + /// In case value is of uint or uint[] is assumed. + /// + /// New data of the metadata. + /// True on success, false on failure. + /// + /// The data format is not supported. + /// + /// is null. + public bool SetValue(object value) + { + Type type = value.GetType(); + if (!typeList.ContainsKey(type)) + { + throw new NotSupportedException("The type of value is not supported"); + } + return SetValue(value, typeList[type]); + } + + /// + /// Sets the value of the metadata. + /// + /// New data of the metadata. + /// Type of the data. + /// True on success, false on failure. + /// + /// The data type is not supported. + /// + /// is null. + /// + /// and to not fit. + public bool SetValue(object value, FREE_IMAGE_MDTYPE type) + { + CheckDisposed(); + if ((!value.GetType().IsArray) && (!(value is string))) + { + Array array = Array.CreateInstance(value.GetType(), 1); + array.SetValue(value, 0); + return SetArrayValue(array, type); + } + return SetArrayValue(value, type); + } + + /// + /// Sets the value of this tag to the value of + /// using the given type. + /// + /// New value of the tag. + /// Data-type of the tag. + /// + /// + /// is a null reference. + /// + /// + /// is FIDT_ASCII and + /// is not String. + /// is not FIDT_ASCII and + /// is not Array. + /// + /// is FIDT_NOTYPE. + private unsafe bool SetArrayValue(object value, FREE_IMAGE_MDTYPE type) + { + if (value == null) + { + throw new ArgumentNullException("value"); + } + + byte[] data = null; + + if (type == FREE_IMAGE_MDTYPE.FIDT_ASCII) + { + string tempValue = value as string; + if (tempValue == null) + { + throw new ArgumentException("value"); + } + Type = type; + Length = Count = (uint)tempValue.Length; + data = new byte[Length]; + + for (int i = 0; i < tempValue.Length; i++) + { + data[i] = (byte)tempValue[i]; + } + } + else if (type == FREE_IMAGE_MDTYPE.FIDT_NOTYPE) + { + throw new NotSupportedException("type is not supported."); + } + else + { + Array array = value as Array; + if (array == null) + { + throw new ArgumentException("value"); + } + + if (array.Length != 0) + if (!CheckType(array.GetValue(0).GetType(), type)) + throw new ArgumentException("The type of value is incorrect."); + + Type = type; + Count = (uint)array.Length; + Length = (uint)(array.Length * Marshal.SizeOf(idList[type])); + data = new byte[Length]; + FreeImage.CopyMemory(data, array, Length); + } + + return FreeImage.SetTagValue(tag, data); + } + + private static bool CheckType(Type dataType, FREE_IMAGE_MDTYPE type) + { + if (dataType != null) + switch (type) + { + case FREE_IMAGE_MDTYPE.FIDT_ASCII: + return dataType == typeof(string); + case FREE_IMAGE_MDTYPE.FIDT_BYTE: + return dataType == typeof(byte); + case FREE_IMAGE_MDTYPE.FIDT_DOUBLE: + return dataType == typeof(double); + case FREE_IMAGE_MDTYPE.FIDT_FLOAT: + return dataType == typeof(float); + case FREE_IMAGE_MDTYPE.FIDT_IFD: + return dataType == typeof(uint); + case FREE_IMAGE_MDTYPE.FIDT_LONG: + return dataType == typeof(uint); + case FREE_IMAGE_MDTYPE.FIDT_NOTYPE: + return false; + case FREE_IMAGE_MDTYPE.FIDT_PALETTE: + return dataType == typeof(RGBQUAD); + case FREE_IMAGE_MDTYPE.FIDT_RATIONAL: + return dataType == typeof(FIURational); + case FREE_IMAGE_MDTYPE.FIDT_SBYTE: + return dataType == typeof(sbyte); + case FREE_IMAGE_MDTYPE.FIDT_SHORT: + return dataType == typeof(ushort); + case FREE_IMAGE_MDTYPE.FIDT_SLONG: + return dataType == typeof(int); + case FREE_IMAGE_MDTYPE.FIDT_SRATIONAL: + return dataType == typeof(FIRational); + case FREE_IMAGE_MDTYPE.FIDT_SSHORT: + return dataType == typeof(short); + case FREE_IMAGE_MDTYPE.FIDT_UNDEFINED: + return dataType == typeof(byte); + } + return false; + } + + /// + /// Add this metadata to an image. + /// + /// Handle to a FreeImage bitmap. + /// True on success, false on failure. + public bool AddToImage(FIBITMAP dib) + { + CheckDisposed(); + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + if (Key == null) + { + throw new ArgumentNullException("Key"); + } + if (!selfCreated) + { + tag = FreeImage.CloneTag(tag); + if (tag.IsNull) + { + throw new Exception("FreeImage.CloneTag() failed."); + } + selfCreated = true; + } + if (!FreeImage.SetMetadata(Model, dib, Key, tag)) + { + return false; + } + FREE_IMAGE_MDMODEL _model = Model; + string _key = Key; + selfCreated = false; + FreeImage.DeleteTag(tag); + return FreeImage.GetMetadata(_model, dib, _key, out tag); + } + + /// + /// Gets a .NET PropertyItem for this metadata tag. + /// + /// The .NET PropertyItem. + public unsafe System.Drawing.Imaging.PropertyItem GetPropertyItem() + { + System.Drawing.Imaging.PropertyItem item = FreeImage.CreatePropertyItem(); + item.Id = ID; + item.Len = (int)Length; + item.Type = (short)Type; + FreeImage.CopyMemory(item.Value = new byte[item.Len], FreeImage.GetTagValue(tag), item.Len); + return item; + } + + /// + /// Converts the value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + CheckDisposed(); + string fiString = FreeImage.TagToString(model, tag, 0); + + if (String.IsNullOrEmpty(fiString)) + { + return tag.ToString(); + } + else + { + return fiString; + } + } + + /// + /// Creates a deep copy of this . + /// + /// A deep copy of this . + public object Clone() + { + CheckDisposed(); + MetadataTag clone = new MetadataTag(); + clone.model = model; + clone.tag = FreeImage.CloneTag(tag); + clone.selfCreated = true; + return clone; + } + + /// + /// Tests whether the specified object is a instance + /// and is equivalent to this instance. + /// + /// The object to test. + /// true if is a instance + /// equivalent to this instance; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is MetadataTag) && (Equals((MetadataTag)obj))); + } + + /// + /// Tests whether the specified instance is equivalent to this instance. + /// + /// A instance to compare to this instance. + /// true if equivalent to this instance; + /// otherwise, false. + public bool Equals(MetadataTag other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return tag.GetHashCode(); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is MetadataTag)) + { + throw new ArgumentException("obj"); + } + return CompareTo((MetadataTag)obj); + } + + /// + /// Compares the current instance with another object of the same type. + /// + /// An object to compare with this instance. + /// A 32-bit signed integer that indicates the relative order of the objects being compared. + public int CompareTo(MetadataTag other) + { + CheckDisposed(); + other.CheckDisposed(); + return tag.CompareTo(other.tag); + } + + /// + /// Releases all resources used by the instance. + /// + public void Dispose() + { + if (!disposed) + { + disposed = true; + if (selfCreated) + { + FreeImage.DeleteTag(tag); + tag = FITAG.Zero; + } + } + } + + /// + /// Gets whether this instance has already been disposed. + /// + public bool Disposed + { + get { return disposed; } + } + + /// + /// Throwns an in case + /// this instance has already been disposed. + /// + private void CheckDisposed() + { + if (disposed) + { + throw new ObjectDisposedException("The object has already been disposed."); + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/Palette.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/Palette.cs index c5cdfbe..58aa501 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/Palette.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/Palette.cs @@ -1,422 +1,422 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Drawing; -using System.IO; -using FreeImageAPI.Metadata; -using System.Runtime.InteropServices; -using System.Diagnostics; - -namespace FreeImageAPI -{ - /// - /// Provides methods for working with the standard bitmap palette. - /// - public sealed class Palette : MemoryArray - { - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private GCHandle paletteHandle; - - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private RGBQUAD[] array; - - /// - /// Initializes a new instance for the given FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// is null. - /// is not - /// -or- - /// has more than 8bpp. - public Palette(FIBITMAP dib) - : base(FreeImage.GetPalette(dib), (int)FreeImage.GetColorsUsed(dib)) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - if (FreeImage.GetImageType(dib) != FREE_IMAGE_TYPE.FIT_BITMAP) - { - throw new ArgumentException("dib"); - } - if (FreeImage.GetBPP(dib) > 8u) - { - throw new ArgumentException("dib"); - } - } - - /// - /// Initializes a new instance for the given FITAG that contains - /// a palette. - /// - /// The tag containing the palette. - /// is null. - /// is not - /// . - public Palette(FITAG tag) - : base(FreeImage.GetTagValue(tag), (int)FreeImage.GetTagCount(tag)) - { - if (FreeImage.GetTagType(tag) != FREE_IMAGE_MDTYPE.FIDT_PALETTE) - { - throw new ArgumentException("tag"); - } - } - - /// - /// Initializes a new instance for the given MetadataTag that contains - /// a palette. - /// - /// The tag containing the palette. - /// is null. - /// is not - /// . - public Palette(MetadataTag tag) - : base(FreeImage.GetTagValue(tag.tag), (int)tag.Count) - { - if (FreeImage.GetTagType(tag) != FREE_IMAGE_MDTYPE.FIDT_PALETTE) - { - throw new ArgumentException("tag"); - } - } - - /// - /// Initializes a new instance for the given array of that contains - /// a palette. - /// - /// A RGBQUAD array containing the palette data to initialize this instance. - public Palette(RGBQUAD[] palette) - { - unsafe - { - this.array = (RGBQUAD[])palette.Clone(); - this.paletteHandle = GCHandle.Alloc(array, GCHandleType.Pinned); - - base.baseAddress = (byte*)this.paletteHandle.AddrOfPinnedObject(); - base.length = (int)this.array.Length; - - // Create an array containing a single element. - // Due to the fact, that it's not possible to create pointers - // of generic types, an array is used to obtain the memory - // address of an element of T. - base.buffer = new RGBQUAD[1]; - // The array is pinned immediately to prevent the GC from - // moving it to a different position in memory. - base.handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - // The array and its content have beed pinned, so that its address - // can be safely requested and stored for the whole lifetime - // of the instace. - base.ptr = (byte*)base.handle.AddrOfPinnedObject(); - } - } - - /// - /// Initializes a new instance for the given array of that contains - /// a palette. - /// - /// A Color array containing the palette data to initialize this instance. - public Palette(Color[] palette) - : this(RGBQUAD.ToRGBQUAD(palette)) - { - } - - /// - /// Initializes a new instance with the specified size. - /// - /// The size of the palette. - public Palette(int size) - : this(new RGBQUAD[size]) - { - } - - /// - /// Gets or sets the palette through an array of . - /// - public RGBQUAD[] AsArray - { - get - { - return Data; - } - set - { - Data = value; - } - } - - /// - /// Get an array of that the block of memory represents. - /// This property is used for internal palette operations. - /// - internal unsafe Color[] ColorData - { - get - { - EnsureNotDisposed(); - Color[] data = new Color[length]; - for (int i = 0; i < length; i++) - { - data[i] = Color.FromArgb((int)(((uint*)baseAddress)[i] | 0xFF000000)); - } - return data; - } - } - - /// - /// Returns the palette as an array of . - /// - /// The palette as an array of . - public RGBQUAD[] ToArray() - { - return Data; - } - - /// - /// Creates a linear palette based on the provided . - /// - /// The used to colorize the palette. - /// - /// Only call this method on linear palettes. - /// - public void Colorize(Color color) - { - Colorize(color, 0.5d); - } - - /// - /// Creates a linear palette based on the provided . - /// - /// The used to colorize the palette. - /// The position of the color within the new palette. - /// 0 < < 1. - /// - /// Only call this method on linear palettes. - /// - public void Colorize(Color color, double splitSize) - { - Colorize(color, (int)(length * splitSize)); - } - - /// - /// Creates a linear palette based on the provided . - /// - /// The used to colorize the palette. - /// The position of the color within the new palette. - /// 0 < < . - /// - /// Only call this method on linear palettes. - /// - public void Colorize(Color color, int splitSize) - { - EnsureNotDisposed(); - if (splitSize < 1 || splitSize >= length) - { - throw new ArgumentOutOfRangeException("splitSize"); - } - - RGBQUAD[] pal = new RGBQUAD[length]; - - double red = color.R; - double green = color.G; - double blue = color.B; - - int i = 0; - double r, g, b; - - r = red / splitSize; - g = green / splitSize; - b = blue / splitSize; - - for (; i <= splitSize; i++) - { - pal[i].rgbRed = (byte)(i * r); - pal[i].rgbGreen = (byte)(i * g); - pal[i].rgbBlue = (byte)(i * b); - } - - r = (255 - red) / (length - splitSize); - g = (255 - green) / (length - splitSize); - b = (255 - blue) / (length - splitSize); - - for (; i < length; i++) - { - pal[i].rgbRed = (byte)(red + ((i - splitSize) * r)); - pal[i].rgbGreen = (byte)(green + ((i - splitSize) * g)); - pal[i].rgbBlue = (byte)(blue + ((i - splitSize) * b)); - } - - Data = pal; - } - - /// - /// Creates a linear grayscale palette. - /// - public void CreateGrayscalePalette() - { - Colorize(Color.White, length - 1); - } - - /// - /// Creates a linear grayscale palette. - /// - /// true to create an inverse grayscale palette. - public void CreateGrayscalePalette(bool inverse) - { - Colorize(Color.White, inverse ? 0 : length - 1); - } - - /// - /// Creates a linear palette with the specified . - /// - /// - /// A linear grayscale palette contains all shades of colors from - /// black to white. This method creates a similar palette with the white - /// color being replaced by the specified color. - /// - /// The used to create the palette. - /// true to create an inverse palette. - public void CreateGrayscalePalette(Color color, bool inverse) - { - Colorize(color, inverse ? 0 : length - 1); - } - - /// - /// Reverses the palette. - /// - public void Reverse() - { - EnsureNotDisposed(); - if (array != null) - { - Array.Reverse(array); - } - else - { - RGBQUAD[] localArray = Data; - Array.Reverse(localArray); - Data = localArray; - } - } - - /// - /// Copies the values from the specified to this instance. - /// - /// The palette to copy from. - /// - /// is a null reference. - public void CopyFrom(Palette palette) - { - EnsureNotDisposed(); - if (palette == null) - { - throw new ArgumentNullException("palette"); - } - CopyFrom(palette.Data, 0, 0, Math.Min(palette.Length, this.Length)); - } - - /// - /// Copies the values from the specified to this instance, - /// starting at the specified . - /// - /// The palette to copy from. - /// The position in this instance where the values - /// will be copied to. - /// - /// is a null reference. - /// - /// is outside the range of valid indexes. - public void CopyFrom(Palette palette, int offset) - { - EnsureNotDisposed(); - CopyFrom(palette.Data, 0, offset, Math.Min(palette.Length, this.Length - offset)); - } - - /// - /// Saves this to the specified file. - /// - /// - /// A string that contains the name of the file to which to save this . - /// - public void Save(string filename) - { - using (Stream stream = new FileStream(filename, FileMode.Create, FileAccess.Write)) - { - Save(stream); - } - } - - /// - /// Saves this to the specified stream. - /// - /// - /// The where the image will be saved. - /// - public void Save(Stream stream) - { - Save(new BinaryWriter(stream)); - } - - /// - /// Saves this using the specified writer. - /// - /// - /// The used to save the image. - /// - public void Save(BinaryWriter writer) - { - EnsureNotDisposed(); - writer.Write(ToByteArray()); - } - - /// - /// Loads a palette from the specified file. - /// - /// The name of the palette file. - public void Load(string filename) - { - using (Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read)) - { - Load(stream); - } - } - - /// - /// Loads a palette from the specified stream. - /// - /// The stream to load the palette from. - public void Load(Stream stream) - { - Load(new BinaryReader(stream)); - } - - /// - /// Loads a palette from the reader. - /// - /// The reader to load the palette from. - public void Load(BinaryReader reader) - { - EnsureNotDisposed(); - unsafe - { - int size = length * sizeof(RGBQUAD); - byte[] data = reader.ReadBytes(size); - fixed (byte* src = data) - { - CopyMemory(baseAddress, src, data.Length); - } - } - } - - /// - /// Releases allocated handles associated with this instance. - /// - /// true to release managed resources. - protected override void Dispose(bool disposing) - { - if (paletteHandle.IsAllocated) - paletteHandle.Free(); - array = null; - - base.Dispose(disposing); - } - } +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; +using System.IO; +using FreeImageAPI.Metadata; +using System.Runtime.InteropServices; +using System.Diagnostics; + +namespace FreeImageAPI +{ + /// + /// Provides methods for working with the standard bitmap palette. + /// + public sealed class Palette : MemoryArray + { + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private GCHandle paletteHandle; + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private RGBQUAD[] array; + + /// + /// Initializes a new instance for the given FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// is null. + /// is not + /// -or- + /// has more than 8bpp. + public Palette(FIBITMAP dib) + : base(FreeImage.GetPalette(dib), (int)FreeImage.GetColorsUsed(dib)) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + if (FreeImage.GetImageType(dib) != FREE_IMAGE_TYPE.FIT_BITMAP) + { + throw new ArgumentException("dib"); + } + if (FreeImage.GetBPP(dib) > 8u) + { + throw new ArgumentException("dib"); + } + } + + /// + /// Initializes a new instance for the given FITAG that contains + /// a palette. + /// + /// The tag containing the palette. + /// is null. + /// is not + /// . + public Palette(FITAG tag) + : base(FreeImage.GetTagValue(tag), (int)FreeImage.GetTagCount(tag)) + { + if (FreeImage.GetTagType(tag) != FREE_IMAGE_MDTYPE.FIDT_PALETTE) + { + throw new ArgumentException("tag"); + } + } + + /// + /// Initializes a new instance for the given MetadataTag that contains + /// a palette. + /// + /// The tag containing the palette. + /// is null. + /// is not + /// . + public Palette(MetadataTag tag) + : base(FreeImage.GetTagValue(tag.tag), (int)tag.Count) + { + if (FreeImage.GetTagType(tag) != FREE_IMAGE_MDTYPE.FIDT_PALETTE) + { + throw new ArgumentException("tag"); + } + } + + /// + /// Initializes a new instance for the given array of that contains + /// a palette. + /// + /// A RGBQUAD array containing the palette data to initialize this instance. + public Palette(RGBQUAD[] palette) + { + unsafe + { + this.array = (RGBQUAD[])palette.Clone(); + this.paletteHandle = GCHandle.Alloc(array, GCHandleType.Pinned); + + base.baseAddress = (byte*)this.paletteHandle.AddrOfPinnedObject(); + base.length = (int)this.array.Length; + + // Create an array containing a single element. + // Due to the fact, that it's not possible to create pointers + // of generic types, an array is used to obtain the memory + // address of an element of T. + base.buffer = new RGBQUAD[1]; + // The array is pinned immediately to prevent the GC from + // moving it to a different position in memory. + base.handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + // The array and its content have beed pinned, so that its address + // can be safely requested and stored for the whole lifetime + // of the instace. + base.ptr = (byte*)base.handle.AddrOfPinnedObject(); + } + } + + /// + /// Initializes a new instance for the given array of that contains + /// a palette. + /// + /// A Color array containing the palette data to initialize this instance. + public Palette(Color[] palette) + : this(RGBQUAD.ToRGBQUAD(palette)) + { + } + + /// + /// Initializes a new instance with the specified size. + /// + /// The size of the palette. + public Palette(int size) + : this(new RGBQUAD[size]) + { + } + + /// + /// Gets or sets the palette through an array of . + /// + public RGBQUAD[] AsArray + { + get + { + return Data; + } + set + { + Data = value; + } + } + + /// + /// Get an array of that the block of memory represents. + /// This property is used for internal palette operations. + /// + internal unsafe Color[] ColorData + { + get + { + EnsureNotDisposed(); + Color[] data = new Color[length]; + for (int i = 0; i < length; i++) + { + data[i] = Color.FromArgb((int)(((uint*)baseAddress)[i] | 0xFF000000)); + } + return data; + } + } + + /// + /// Returns the palette as an array of . + /// + /// The palette as an array of . + public RGBQUAD[] ToArray() + { + return Data; + } + + /// + /// Creates a linear palette based on the provided . + /// + /// The used to colorize the palette. + /// + /// Only call this method on linear palettes. + /// + public void Colorize(Color color) + { + Colorize(color, 0.5d); + } + + /// + /// Creates a linear palette based on the provided . + /// + /// The used to colorize the palette. + /// The position of the color within the new palette. + /// 0 < < 1. + /// + /// Only call this method on linear palettes. + /// + public void Colorize(Color color, double splitSize) + { + Colorize(color, (int)(length * splitSize)); + } + + /// + /// Creates a linear palette based on the provided . + /// + /// The used to colorize the palette. + /// The position of the color within the new palette. + /// 0 < < . + /// + /// Only call this method on linear palettes. + /// + public void Colorize(Color color, int splitSize) + { + EnsureNotDisposed(); + if (splitSize < 1 || splitSize >= length) + { + throw new ArgumentOutOfRangeException("splitSize"); + } + + RGBQUAD[] pal = new RGBQUAD[length]; + + double red = color.R; + double green = color.G; + double blue = color.B; + + int i = 0; + double r, g, b; + + r = red / splitSize; + g = green / splitSize; + b = blue / splitSize; + + for (; i <= splitSize; i++) + { + pal[i].rgbRed = (byte)(i * r); + pal[i].rgbGreen = (byte)(i * g); + pal[i].rgbBlue = (byte)(i * b); + } + + r = (255 - red) / (length - splitSize); + g = (255 - green) / (length - splitSize); + b = (255 - blue) / (length - splitSize); + + for (; i < length; i++) + { + pal[i].rgbRed = (byte)(red + ((i - splitSize) * r)); + pal[i].rgbGreen = (byte)(green + ((i - splitSize) * g)); + pal[i].rgbBlue = (byte)(blue + ((i - splitSize) * b)); + } + + Data = pal; + } + + /// + /// Creates a linear grayscale palette. + /// + public void CreateGrayscalePalette() + { + Colorize(Color.White, length - 1); + } + + /// + /// Creates a linear grayscale palette. + /// + /// true to create an inverse grayscale palette. + public void CreateGrayscalePalette(bool inverse) + { + Colorize(Color.White, inverse ? 0 : length - 1); + } + + /// + /// Creates a linear palette with the specified . + /// + /// + /// A linear grayscale palette contains all shades of colors from + /// black to white. This method creates a similar palette with the white + /// color being replaced by the specified color. + /// + /// The used to create the palette. + /// true to create an inverse palette. + public void CreateGrayscalePalette(Color color, bool inverse) + { + Colorize(color, inverse ? 0 : length - 1); + } + + /// + /// Reverses the palette. + /// + public void Reverse() + { + EnsureNotDisposed(); + if (array != null) + { + Array.Reverse(array); + } + else + { + RGBQUAD[] localArray = Data; + Array.Reverse(localArray); + Data = localArray; + } + } + + /// + /// Copies the values from the specified to this instance. + /// + /// The palette to copy from. + /// + /// is a null reference. + public void CopyFrom(Palette palette) + { + EnsureNotDisposed(); + if (palette == null) + { + throw new ArgumentNullException("palette"); + } + CopyFrom(palette.Data, 0, 0, Math.Min(palette.Length, this.Length)); + } + + /// + /// Copies the values from the specified to this instance, + /// starting at the specified . + /// + /// The palette to copy from. + /// The position in this instance where the values + /// will be copied to. + /// + /// is a null reference. + /// + /// is outside the range of valid indexes. + public void CopyFrom(Palette palette, int offset) + { + EnsureNotDisposed(); + CopyFrom(palette.Data, 0, offset, Math.Min(palette.Length, this.Length - offset)); + } + + /// + /// Saves this to the specified file. + /// + /// + /// A string that contains the name of the file to which to save this . + /// + public void Save(string filename) + { + using (Stream stream = new FileStream(filename, FileMode.Create, FileAccess.Write)) + { + Save(stream); + } + } + + /// + /// Saves this to the specified stream. + /// + /// + /// The where the image will be saved. + /// + public void Save(Stream stream) + { + Save(new BinaryWriter(stream)); + } + + /// + /// Saves this using the specified writer. + /// + /// + /// The used to save the image. + /// + public void Save(BinaryWriter writer) + { + EnsureNotDisposed(); + writer.Write(ToByteArray()); + } + + /// + /// Loads a palette from the specified file. + /// + /// The name of the palette file. + public void Load(string filename) + { + using (Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read)) + { + Load(stream); + } + } + + /// + /// Loads a palette from the specified stream. + /// + /// The stream to load the palette from. + public void Load(Stream stream) + { + Load(new BinaryReader(stream)); + } + + /// + /// Loads a palette from the reader. + /// + /// The reader to load the palette from. + public void Load(BinaryReader reader) + { + EnsureNotDisposed(); + unsafe + { + int size = length * sizeof(RGBQUAD); + byte[] data = reader.ReadBytes(size); + fixed (byte* src = data) + { + CopyMemory(baseAddress, src, data.Length); + } + } + } + + /// + /// Releases allocated handles associated with this instance. + /// + /// true to release managed resources. + protected override void Dispose(bool disposing) + { + if (paletteHandle.IsAllocated) + paletteHandle.Free(); + array = null; + + base.Dispose(disposing); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/PluginRepository.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/PluginRepository.cs index cc658a7..8b077dc 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/PluginRepository.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/PluginRepository.cs @@ -1,449 +1,449 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; - -namespace FreeImageAPI.Plugins -{ - /// - /// Class representing all registered in FreeImage. - /// - public static class PluginRepository - { - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private static readonly List plugins = null; - - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private static readonly List localPlugins = null; - - static PluginRepository() - { - plugins = new List(FreeImage.GetFIFCount()); - localPlugins = new List(0); - for (int i = 0; i < plugins.Capacity; i++) - { - plugins.Add(new FreeImagePlugin((FREE_IMAGE_FORMAT)i)); - } - } - - /// - /// Adds local plugin to this class. - /// - /// The registered plugin. - internal static void RegisterLocalPlugin(LocalPlugin localPlugin) - { - FreeImagePlugin plugin = new FreeImagePlugin(localPlugin.Format); - plugins.Add(plugin); - localPlugins.Add(plugin); - } - - /// - /// Returns an instance of , representing the given format. - /// - /// The representing format. - /// An instance of . - public static FreeImagePlugin Plugin(FREE_IMAGE_FORMAT fif) - { - return Plugin((int)fif); - } - - /// - /// Returns an instance of , - /// representing the format at the given index. - /// - /// The index of the representing format. - /// An instance of . - public static FreeImagePlugin Plugin(int index) - { - return (index >= 0) ? plugins[index] : null; - } - - /// - /// Returns an instance of . - /// is searched in: - /// Format, RegExpr, - /// ValidExtension and ValidFilename. - /// - /// The expression to search for. - /// An instance of . - public static FreeImagePlugin Plugin(string expression) - { - FreeImagePlugin result = null; - expression = expression.ToLower(); - - foreach (FreeImagePlugin plugin in plugins) - { - if (plugin.Format.ToLower().Contains(expression) || - plugin.RegExpr.ToLower().Contains(expression) || - plugin.ValidExtension(expression, StringComparison.CurrentCultureIgnoreCase) || - plugin.ValidFilename(expression, StringComparison.CurrentCultureIgnoreCase)) - { - result = plugin; - break; - } - } - - return result; - } - - /// - /// Returns an instance of for the given format. - /// - /// The format of the Plugin. - /// An instance of . - public static FreeImagePlugin PluginFromFormat(string format) - { - return Plugin(FreeImage.GetFIFFromFormat(format)); - } - - /// - /// Returns an instance of for the given filename. - /// - /// The valid filename for the plugin. - /// An instance of . - public static FreeImagePlugin PluginFromFilename(string filename) - { - return Plugin(FreeImage.GetFIFFromFilename(filename)); - } - - /// - /// Returns an instance of for the given mime. - /// - /// The valid mime for the plugin. - /// An instance of . - public static FreeImagePlugin PluginFromMime(string mime) - { - return Plugin(FreeImage.GetFIFFromMime(mime)); - } - - /// - /// Gets the number of registered plugins. - /// - public static int FIFCount - { - get - { - return FreeImage.GetFIFCount(); - } - } - - /// - /// Gets a readonly collection of all plugins. - /// - public static ReadOnlyCollection PluginList - { - get - { - return plugins.AsReadOnly(); - } - } - - /// - /// Gets a list of plugins that are only able to - /// read but not to write. - /// - public static List ReadOnlyPlugins - { - get - { - List list = new List(); - foreach (FreeImagePlugin p in plugins) - { - if (p.SupportsReading && !p.SupportsWriting) - { - list.Add(p); - } - } - return list; - } - } - - /// - /// Gets a list of plugins that are only able to - /// write but not to read. - /// - public static List WriteOnlyPlugins - { - get - { - List list = new List(); - foreach (FreeImagePlugin p in plugins) - { - if (!p.SupportsReading && p.SupportsWriting) - { - list.Add(p); - } - } - return list; - } - } - - /// - /// Gets a list of plugins that are not able to - /// read or write. - /// - public static List StupidPlugins - { - get - { - List list = new List(); - foreach (FreeImagePlugin p in plugins) - { - if (!p.SupportsReading && !p.SupportsWriting) - { - list.Add(p); - } - } - return list; - } - } - - /// - /// Gets a list of plugins that are able to read. - /// - public static List ReadablePlugins - { - get - { - List list = new List(); - foreach (FreeImagePlugin p in plugins) - { - if (p.SupportsReading) - { - list.Add(p); - } - } - return list; - } - } - - /// - /// Gets a list of plugins that are able to write. - /// - public static List WriteablePlugins - { - get - { - List list = new List(); - foreach (FreeImagePlugin p in plugins) - { - if (p.SupportsWriting) - { - list.Add(p); - } - } - return list; - } - } - - /// - /// Gets a list of local plugins. - /// - public static ReadOnlyCollection LocalPlugins - { - get - { - return localPlugins.AsReadOnly(); - } - } - - /// - /// Gets a list of built-in plugins. - /// - public static List BuiltInPlugins - { - get - { - List list = new List(); - foreach (FreeImagePlugin p in plugins) - { - if (!localPlugins.Contains(p)) - { - list.Add(p); - } - } - return list; - } - } - - /// - /// Windows or OS/2 Bitmap File (*.BMP) - /// - public static FreeImagePlugin BMP { get { return plugins[0]; } } - - /// - /// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE) - /// - public static FreeImagePlugin ICO { get { return plugins[1]; } } - - /// - /// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE) - /// - public static FreeImagePlugin JPEG { get { return plugins[2]; } } - - /// - /// JPEG Network Graphics (*.JNG) - /// - public static FreeImagePlugin JNG { get { return plugins[3]; } } - - /// - /// Commodore 64 Koala format (*.KOA) - /// - public static FreeImagePlugin KOALA { get { return plugins[4]; } } - - /// - /// Amiga IFF (*.IFF, *.LBM) - /// - public static FreeImagePlugin LBM { get { return plugins[5]; } } - - /// - /// Amiga IFF (*.IFF, *.LBM) - /// - public static FreeImagePlugin IFF { get { return plugins[5]; } } - - /// - /// Multiple Network Graphics (*.MNG) - /// - public static FreeImagePlugin MNG { get { return plugins[6]; } } - - /// - /// Portable Bitmap (ASCII) (*.PBM) - /// - public static FreeImagePlugin PBM { get { return plugins[7]; } } - - /// - /// Portable Bitmap (BINARY) (*.PBM) - /// - public static FreeImagePlugin PBMRAW { get { return plugins[8]; } } - - /// - /// Kodak PhotoCD (*.PCD) - /// - public static FreeImagePlugin PCD { get { return plugins[9]; } } - - /// - /// Zsoft Paintbrush PCX bitmap format (*.PCX) - /// - public static FreeImagePlugin PCX { get { return plugins[10]; } } - - /// - /// Portable Graymap (ASCII) (*.PGM) - /// - public static FreeImagePlugin PGM { get { return plugins[11]; } } - - /// - /// Portable Graymap (BINARY) (*.PGM) - /// - public static FreeImagePlugin PGMRAW { get { return plugins[12]; } } - - /// - /// Portable Network Graphics (*.PNG) - /// - public static FreeImagePlugin PNG { get { return plugins[13]; } } - - /// - /// Portable Pixelmap (ASCII) (*.PPM) - /// - public static FreeImagePlugin PPM { get { return plugins[14]; } } - - /// - /// Portable Pixelmap (BINARY) (*.PPM) - /// - public static FreeImagePlugin PPMRAW { get { return plugins[15]; } } - - /// - /// Sun Rasterfile (*.RAS) - /// - public static FreeImagePlugin RAS { get { return plugins[16]; } } - - /// - /// truevision Targa files (*.TGA, *.TARGA) - /// - public static FreeImagePlugin TARGA { get { return plugins[17]; } } - - /// - /// Tagged Image File Format (*.TIF, *.TIFF) - /// - public static FreeImagePlugin TIFF { get { return plugins[18]; } } - - /// - /// Wireless Bitmap (*.WBMP) - /// - public static FreeImagePlugin WBMP { get { return plugins[19]; } } - - /// - /// Adobe Photoshop (*.PSD) - /// - public static FreeImagePlugin PSD { get { return plugins[20]; } } - - /// - /// Dr. Halo (*.CUT) - /// - public static FreeImagePlugin CUT { get { return plugins[21]; } } - - /// - /// X11 Bitmap Format (*.XBM) - /// - public static FreeImagePlugin XBM { get { return plugins[22]; } } - - /// - /// X11 Pixmap Format (*.XPM) - /// - public static FreeImagePlugin XPM { get { return plugins[23]; } } - - /// - /// DirectDraw Surface (*.DDS) - /// - public static FreeImagePlugin DDS { get { return plugins[24]; } } - - /// - /// Graphics Interchange Format (*.GIF) - /// - public static FreeImagePlugin GIF { get { return plugins[25]; } } - - /// - /// High Dynamic Range (*.HDR) - /// - public static FreeImagePlugin HDR { get { return plugins[26]; } } - - /// - /// Raw Fax format CCITT G3 (*.G3) - /// - public static FreeImagePlugin FAXG3 { get { return plugins[27]; } } - - /// - /// Silicon Graphics SGI image format (*.SGI) - /// - public static FreeImagePlugin SGI { get { return plugins[28]; } } - - /// - /// OpenEXR format (*.EXR) - /// - public static FreeImagePlugin EXR { get { return plugins[29]; } } - - /// - /// JPEG-2000 format (*.J2K, *.J2C) - /// - public static FreeImagePlugin J2K { get { return plugins[30]; } } - - /// - /// JPEG-2000 format (*.JP2) - /// - public static FreeImagePlugin JP2 { get { return plugins[31]; } } - - /// - /// Portable FloatMap (*.PFM) - /// - public static FreeImagePlugin PFM { get { return plugins[32]; } } - - /// - /// Macintosh PICT (*.PICT) - /// - public static FreeImagePlugin PICT { get { return plugins[33]; } } - - /// - /// RAW camera image (*.*) - /// - public static FreeImagePlugin RAW { get { return plugins[34]; } } - } +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; + +namespace FreeImageAPI.Plugins +{ + /// + /// Class representing all registered in FreeImage. + /// + public static class PluginRepository + { + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private static readonly List plugins = null; + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private static readonly List localPlugins = null; + + static PluginRepository() + { + plugins = new List(FreeImage.GetFIFCount()); + localPlugins = new List(0); + for (int i = 0; i < plugins.Capacity; i++) + { + plugins.Add(new FreeImagePlugin((FREE_IMAGE_FORMAT)i)); + } + } + + /// + /// Adds local plugin to this class. + /// + /// The registered plugin. + internal static void RegisterLocalPlugin(LocalPlugin localPlugin) + { + FreeImagePlugin plugin = new FreeImagePlugin(localPlugin.Format); + plugins.Add(plugin); + localPlugins.Add(plugin); + } + + /// + /// Returns an instance of , representing the given format. + /// + /// The representing format. + /// An instance of . + public static FreeImagePlugin Plugin(FREE_IMAGE_FORMAT fif) + { + return Plugin((int)fif); + } + + /// + /// Returns an instance of , + /// representing the format at the given index. + /// + /// The index of the representing format. + /// An instance of . + public static FreeImagePlugin Plugin(int index) + { + return (index >= 0) ? plugins[index] : null; + } + + /// + /// Returns an instance of . + /// is searched in: + /// Format, RegExpr, + /// ValidExtension and ValidFilename. + /// + /// The expression to search for. + /// An instance of . + public static FreeImagePlugin Plugin(string expression) + { + FreeImagePlugin result = null; + expression = expression.ToLower(); + + foreach (FreeImagePlugin plugin in plugins) + { + if (plugin.Format.ToLower().Contains(expression) || + plugin.RegExpr.ToLower().Contains(expression) || + plugin.ValidExtension(expression, StringComparison.CurrentCultureIgnoreCase) || + plugin.ValidFilename(expression, StringComparison.CurrentCultureIgnoreCase)) + { + result = plugin; + break; + } + } + + return result; + } + + /// + /// Returns an instance of for the given format. + /// + /// The format of the Plugin. + /// An instance of . + public static FreeImagePlugin PluginFromFormat(string format) + { + return Plugin(FreeImage.GetFIFFromFormat(format)); + } + + /// + /// Returns an instance of for the given filename. + /// + /// The valid filename for the plugin. + /// An instance of . + public static FreeImagePlugin PluginFromFilename(string filename) + { + return Plugin(FreeImage.GetFIFFromFilename(filename)); + } + + /// + /// Returns an instance of for the given mime. + /// + /// The valid mime for the plugin. + /// An instance of . + public static FreeImagePlugin PluginFromMime(string mime) + { + return Plugin(FreeImage.GetFIFFromMime(mime)); + } + + /// + /// Gets the number of registered plugins. + /// + public static int FIFCount + { + get + { + return FreeImage.GetFIFCount(); + } + } + + /// + /// Gets a readonly collection of all plugins. + /// + public static ReadOnlyCollection PluginList + { + get + { + return plugins.AsReadOnly(); + } + } + + /// + /// Gets a list of plugins that are only able to + /// read but not to write. + /// + public static List ReadOnlyPlugins + { + get + { + List list = new List(); + foreach (FreeImagePlugin p in plugins) + { + if (p.SupportsReading && !p.SupportsWriting) + { + list.Add(p); + } + } + return list; + } + } + + /// + /// Gets a list of plugins that are only able to + /// write but not to read. + /// + public static List WriteOnlyPlugins + { + get + { + List list = new List(); + foreach (FreeImagePlugin p in plugins) + { + if (!p.SupportsReading && p.SupportsWriting) + { + list.Add(p); + } + } + return list; + } + } + + /// + /// Gets a list of plugins that are not able to + /// read or write. + /// + public static List StupidPlugins + { + get + { + List list = new List(); + foreach (FreeImagePlugin p in plugins) + { + if (!p.SupportsReading && !p.SupportsWriting) + { + list.Add(p); + } + } + return list; + } + } + + /// + /// Gets a list of plugins that are able to read. + /// + public static List ReadablePlugins + { + get + { + List list = new List(); + foreach (FreeImagePlugin p in plugins) + { + if (p.SupportsReading) + { + list.Add(p); + } + } + return list; + } + } + + /// + /// Gets a list of plugins that are able to write. + /// + public static List WriteablePlugins + { + get + { + List list = new List(); + foreach (FreeImagePlugin p in plugins) + { + if (p.SupportsWriting) + { + list.Add(p); + } + } + return list; + } + } + + /// + /// Gets a list of local plugins. + /// + public static ReadOnlyCollection LocalPlugins + { + get + { + return localPlugins.AsReadOnly(); + } + } + + /// + /// Gets a list of built-in plugins. + /// + public static List BuiltInPlugins + { + get + { + List list = new List(); + foreach (FreeImagePlugin p in plugins) + { + if (!localPlugins.Contains(p)) + { + list.Add(p); + } + } + return list; + } + } + + /// + /// Windows or OS/2 Bitmap File (*.BMP) + /// + public static FreeImagePlugin BMP { get { return plugins[0]; } } + + /// + /// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE) + /// + public static FreeImagePlugin ICO { get { return plugins[1]; } } + + /// + /// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE) + /// + public static FreeImagePlugin JPEG { get { return plugins[2]; } } + + /// + /// JPEG Network Graphics (*.JNG) + /// + public static FreeImagePlugin JNG { get { return plugins[3]; } } + + /// + /// Commodore 64 Koala format (*.KOA) + /// + public static FreeImagePlugin KOALA { get { return plugins[4]; } } + + /// + /// Amiga IFF (*.IFF, *.LBM) + /// + public static FreeImagePlugin LBM { get { return plugins[5]; } } + + /// + /// Amiga IFF (*.IFF, *.LBM) + /// + public static FreeImagePlugin IFF { get { return plugins[5]; } } + + /// + /// Multiple Network Graphics (*.MNG) + /// + public static FreeImagePlugin MNG { get { return plugins[6]; } } + + /// + /// Portable Bitmap (ASCII) (*.PBM) + /// + public static FreeImagePlugin PBM { get { return plugins[7]; } } + + /// + /// Portable Bitmap (BINARY) (*.PBM) + /// + public static FreeImagePlugin PBMRAW { get { return plugins[8]; } } + + /// + /// Kodak PhotoCD (*.PCD) + /// + public static FreeImagePlugin PCD { get { return plugins[9]; } } + + /// + /// Zsoft Paintbrush PCX bitmap format (*.PCX) + /// + public static FreeImagePlugin PCX { get { return plugins[10]; } } + + /// + /// Portable Graymap (ASCII) (*.PGM) + /// + public static FreeImagePlugin PGM { get { return plugins[11]; } } + + /// + /// Portable Graymap (BINARY) (*.PGM) + /// + public static FreeImagePlugin PGMRAW { get { return plugins[12]; } } + + /// + /// Portable Network Graphics (*.PNG) + /// + public static FreeImagePlugin PNG { get { return plugins[13]; } } + + /// + /// Portable Pixelmap (ASCII) (*.PPM) + /// + public static FreeImagePlugin PPM { get { return plugins[14]; } } + + /// + /// Portable Pixelmap (BINARY) (*.PPM) + /// + public static FreeImagePlugin PPMRAW { get { return plugins[15]; } } + + /// + /// Sun Rasterfile (*.RAS) + /// + public static FreeImagePlugin RAS { get { return plugins[16]; } } + + /// + /// truevision Targa files (*.TGA, *.TARGA) + /// + public static FreeImagePlugin TARGA { get { return plugins[17]; } } + + /// + /// Tagged Image File Format (*.TIF, *.TIFF) + /// + public static FreeImagePlugin TIFF { get { return plugins[18]; } } + + /// + /// Wireless Bitmap (*.WBMP) + /// + public static FreeImagePlugin WBMP { get { return plugins[19]; } } + + /// + /// Adobe Photoshop (*.PSD) + /// + public static FreeImagePlugin PSD { get { return plugins[20]; } } + + /// + /// Dr. Halo (*.CUT) + /// + public static FreeImagePlugin CUT { get { return plugins[21]; } } + + /// + /// X11 Bitmap Format (*.XBM) + /// + public static FreeImagePlugin XBM { get { return plugins[22]; } } + + /// + /// X11 Pixmap Format (*.XPM) + /// + public static FreeImagePlugin XPM { get { return plugins[23]; } } + + /// + /// DirectDraw Surface (*.DDS) + /// + public static FreeImagePlugin DDS { get { return plugins[24]; } } + + /// + /// Graphics Interchange Format (*.GIF) + /// + public static FreeImagePlugin GIF { get { return plugins[25]; } } + + /// + /// High Dynamic Range (*.HDR) + /// + public static FreeImagePlugin HDR { get { return plugins[26]; } } + + /// + /// Raw Fax format CCITT G3 (*.G3) + /// + public static FreeImagePlugin FAXG3 { get { return plugins[27]; } } + + /// + /// Silicon Graphics SGI image format (*.SGI) + /// + public static FreeImagePlugin SGI { get { return plugins[28]; } } + + /// + /// OpenEXR format (*.EXR) + /// + public static FreeImagePlugin EXR { get { return plugins[29]; } } + + /// + /// JPEG-2000 format (*.J2K, *.J2C) + /// + public static FreeImagePlugin J2K { get { return plugins[30]; } } + + /// + /// JPEG-2000 format (*.JP2) + /// + public static FreeImagePlugin JP2 { get { return plugins[31]; } } + + /// + /// Portable FloatMap (*.PFM) + /// + public static FreeImagePlugin PFM { get { return plugins[32]; } } + + /// + /// Macintosh PICT (*.PICT) + /// + public static FreeImagePlugin PICT { get { return plugins[33]; } } + + /// + /// RAW camera image (*.*) + /// + public static FreeImagePlugin RAW { get { return plugins[34]; } } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/Scanline.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/Scanline.cs index 6ad592d..fcbeac3 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/Scanline.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/Scanline.cs @@ -1,50 +1,50 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// Provides methods for working with generic bitmap scanlines. - /// - /// Type of the bitmaps' scanlines. - public sealed class Scanline : MemoryArray where T : struct - { - /// - /// Initializes a new instance based on the specified FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - public Scanline(FIBITMAP dib) - : this(dib, 0) - { - } - - /// - /// Initializes a new instance based on the specified FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Index of the zero based scanline. - public Scanline(FIBITMAP dib, int scanline) - : this(dib, scanline, (int)(typeof(T) == typeof(FI1BIT) ? - FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib) : - typeof(T) == typeof(FI4BIT) ? - FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib) / 4 : - (FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib)) / (Marshal.SizeOf(typeof(T)) * 8))) - { - } - - internal Scanline(FIBITMAP dib, int scanline, int length) - : base(FreeImage.GetScanLine(dib, scanline), length) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - if ((scanline < 0) || (scanline >= FreeImage.GetHeight(dib))) - { - throw new ArgumentOutOfRangeException("scanline"); - } - } - } +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// Provides methods for working with generic bitmap scanlines. + /// + /// Type of the bitmaps' scanlines. + public sealed class Scanline : MemoryArray where T : struct + { + /// + /// Initializes a new instance based on the specified FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + public Scanline(FIBITMAP dib) + : this(dib, 0) + { + } + + /// + /// Initializes a new instance based on the specified FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Index of the zero based scanline. + public Scanline(FIBITMAP dib, int scanline) + : this(dib, scanline, (int)(typeof(T) == typeof(FI1BIT) ? + FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib) : + typeof(T) == typeof(FI4BIT) ? + FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib) / 4 : + (FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib)) / (Marshal.SizeOf(typeof(T)) * 8))) + { + } + + internal Scanline(FIBITMAP dib, int scanline, int length) + : base(FreeImage.GetScanLine(dib, scanline), length) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + if ((scanline < 0) || (scanline >= FreeImage.GetHeight(dib))) + { + throw new ArgumentOutOfRangeException("scanline"); + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Classes/StreamWrapper.cs b/Wrapper/FreeImage.NET/cs/Library/Classes/StreamWrapper.cs index 2b8cba7..720156b 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Classes/StreamWrapper.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Classes/StreamWrapper.cs @@ -1,312 +1,312 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.6 $ -// $Date: 2009/02/23 12:28:56 $ -// $Id: StreamWrapper.cs,v 1.6 2009/02/23 12:28:56 cklein05 Exp $ -// ========================================================== - -using System; -using System.IO; -using System.Diagnostics; - -namespace FreeImageAPI.IO -{ - /// - /// Class wrapping streams, implementing a buffer for read data, - /// so that seek operations can be made. - /// - /// - /// FreeImage can load bitmaps from arbitrary sources. - /// .NET works with different streams like File- or NetConnection-strams. - /// NetConnection streams, which are used to load files from web servers, - /// for example cannot seek. - /// But FreeImage frequently uses the seek operation when loading bitmaps. - /// StreamWrapper wrapps a stream and makes it seekable by caching all read - /// data into an internal MemoryStream to jump back- and forward. - /// StreamWapper is for internal use and only for loading from streams. - /// - internal class StreamWrapper : Stream - { - /// - /// The stream to wrap - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private readonly Stream stream; - - /// - /// The caching stream - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private MemoryStream memoryStream = new MemoryStream(); - - /// - /// Indicates if the wrapped stream reached its end - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool eos = false; - - /// - /// Tells the wrapper to block readings or not - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool blocking = false; - - /// - /// Indicates if the wrapped stream is disposed or not - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool disposed = false; - - /// - /// Initializes a new instance based on the specified . - /// - /// The stream to wrap. - /// When true the wrapper always tries to read the requested - /// amount of data from the wrapped stream. - public StreamWrapper(Stream stream, bool blocking) - { - if (!stream.CanRead) - { - throw new ArgumentException("stream is not capable of reading."); - } - this.stream = stream; - this.blocking = blocking; - } - - /// - /// Releases all resources used by the instance. - /// - ~StreamWrapper() - { - Dispose(false); - } - - // The wrapper only accepts readable streams - public override bool CanRead - { - get { checkDisposed(); return true; } - } - - // We implement that feature - public override bool CanSeek - { - get { checkDisposed(); return true; } - } - - // The wrapper is readonly - public override bool CanWrite - { - get { checkDisposed(); return false; } - } - - // Just forward it - public override void Flush() - { - checkDisposed(); - stream.Flush(); - } - - // Calling this property will cause the wrapper to read the stream - // to its end and cache it completely. - public override long Length - { - get - { - checkDisposed(); - if (!eos) - { - Fill(); - } - return memoryStream.Length; - } - } - - // Gets or sets the current position - public override long Position - { - get - { - checkDisposed(); - return memoryStream.Position; - } - set - { - checkDisposed(); - Seek(value, SeekOrigin.Begin); - } - } - - // Implements the reading feature - public override int Read(byte[] buffer, int offset, int count) - { - checkDisposed(); - // total bytes read from memory-stream - int memoryBytes = 0; - // total bytes read from the original stream - int streamBytes = 0; - memoryBytes = memoryStream.Read(buffer, offset, count); - if ((count > memoryBytes) && (!eos)) - { - // read the rest from the original stream (can be 0 bytes) - do - { - int read = stream.Read( - buffer, - offset + memoryBytes + streamBytes, - count - memoryBytes - streamBytes); - streamBytes += read; - if (read == 0) - { - eos = true; - break; - } - if (!blocking) - { - break; - } - } while ((memoryBytes + streamBytes) < count); - // copy the bytes from the original stream into the memory stream - // if 0 bytes were read we write 0 so the memory-stream is not changed - memoryStream.Write(buffer, offset + memoryBytes, streamBytes); - } - return memoryBytes + streamBytes; - } - - // Implements the seeking feature - public override long Seek(long offset, SeekOrigin origin) - { - checkDisposed(); - long newPosition = 0L; - // get new position - switch (origin) - { - case SeekOrigin.Begin: - newPosition = offset; - break; - case SeekOrigin.Current: - newPosition = memoryStream.Position + offset; - break; - case SeekOrigin.End: - // to seek from the end have have to read to the end first - if (!eos) - { - Fill(); - } - newPosition = memoryStream.Length + offset; - break; - default: - throw new ArgumentOutOfRangeException("origin"); - } - // in case the new position is beyond the memory-streams end - // and the original streams end hasn't been reached - // the original stream is read until either the stream ends or - // enough bytes have been read - if ((newPosition > memoryStream.Length) && (!eos)) - { - memoryStream.Position = memoryStream.Length; - int bytesToRead = (int)(newPosition - memoryStream.Length); - byte[] buffer = new byte[1024]; - do - { - bytesToRead -= Read(buffer, 0, (bytesToRead >= buffer.Length) ? buffer.Length : bytesToRead); - } while ((bytesToRead > 0) && (!eos)); - } - memoryStream.Position = (newPosition <= memoryStream.Length) ? newPosition : memoryStream.Length; - return 0; - } - - // No write-support - public override void SetLength(long value) - { - throw new Exception("The method or operation is not implemented."); - } - - // No write-support - public override void Write(byte[] buffer, int offset, int count) - { - throw new Exception("The method or operation is not implemented."); - } - - public void Reset() - { - checkDisposed(); - Position = 0; - } - - // Reads the wrapped stream until its end. - private void Fill() - { - if (!eos) - { - memoryStream.Position = memoryStream.Length; - int bytesRead = 0; - byte[] buffer = new byte[1024]; - do - { - bytesRead = stream.Read(buffer, 0, buffer.Length); - memoryStream.Write(buffer, 0, bytesRead); - } while (bytesRead != 0); - eos = true; - } - } - - public new void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private new void Dispose(bool disposing) - { - if (!disposed) - { - disposed = true; - if (disposing) - { - if (memoryStream != null) - { - memoryStream.Dispose(); - } - } - } - } - - public bool Disposed - { - get { return disposed; } - } - - private void checkDisposed() - { - if (disposed) throw new ObjectDisposedException("StreamWrapper"); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.6 $ +// $Date: 2009/02/23 12:28:56 $ +// $Id: StreamWrapper.cs,v 1.6 2009/02/23 12:28:56 cklein05 Exp $ +// ========================================================== + +using System; +using System.IO; +using System.Diagnostics; + +namespace FreeImageAPI.IO +{ + /// + /// Class wrapping streams, implementing a buffer for read data, + /// so that seek operations can be made. + /// + /// + /// FreeImage can load bitmaps from arbitrary sources. + /// .NET works with different streams like File- or NetConnection-strams. + /// NetConnection streams, which are used to load files from web servers, + /// for example cannot seek. + /// But FreeImage frequently uses the seek operation when loading bitmaps. + /// StreamWrapper wrapps a stream and makes it seekable by caching all read + /// data into an internal MemoryStream to jump back- and forward. + /// StreamWapper is for internal use and only for loading from streams. + /// + internal class StreamWrapper : Stream + { + /// + /// The stream to wrap + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private readonly Stream stream; + + /// + /// The caching stream + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private MemoryStream memoryStream = new MemoryStream(); + + /// + /// Indicates if the wrapped stream reached its end + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool eos = false; + + /// + /// Tells the wrapper to block readings or not + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool blocking = false; + + /// + /// Indicates if the wrapped stream is disposed or not + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool disposed = false; + + /// + /// Initializes a new instance based on the specified . + /// + /// The stream to wrap. + /// When true the wrapper always tries to read the requested + /// amount of data from the wrapped stream. + public StreamWrapper(Stream stream, bool blocking) + { + if (!stream.CanRead) + { + throw new ArgumentException("stream is not capable of reading."); + } + this.stream = stream; + this.blocking = blocking; + } + + /// + /// Releases all resources used by the instance. + /// + ~StreamWrapper() + { + Dispose(false); + } + + // The wrapper only accepts readable streams + public override bool CanRead + { + get { checkDisposed(); return true; } + } + + // We implement that feature + public override bool CanSeek + { + get { checkDisposed(); return true; } + } + + // The wrapper is readonly + public override bool CanWrite + { + get { checkDisposed(); return false; } + } + + // Just forward it + public override void Flush() + { + checkDisposed(); + stream.Flush(); + } + + // Calling this property will cause the wrapper to read the stream + // to its end and cache it completely. + public override long Length + { + get + { + checkDisposed(); + if (!eos) + { + Fill(); + } + return memoryStream.Length; + } + } + + // Gets or sets the current position + public override long Position + { + get + { + checkDisposed(); + return memoryStream.Position; + } + set + { + checkDisposed(); + Seek(value, SeekOrigin.Begin); + } + } + + // Implements the reading feature + public override int Read(byte[] buffer, int offset, int count) + { + checkDisposed(); + // total bytes read from memory-stream + int memoryBytes = 0; + // total bytes read from the original stream + int streamBytes = 0; + memoryBytes = memoryStream.Read(buffer, offset, count); + if ((count > memoryBytes) && (!eos)) + { + // read the rest from the original stream (can be 0 bytes) + do + { + int read = stream.Read( + buffer, + offset + memoryBytes + streamBytes, + count - memoryBytes - streamBytes); + streamBytes += read; + if (read == 0) + { + eos = true; + break; + } + if (!blocking) + { + break; + } + } while ((memoryBytes + streamBytes) < count); + // copy the bytes from the original stream into the memory stream + // if 0 bytes were read we write 0 so the memory-stream is not changed + memoryStream.Write(buffer, offset + memoryBytes, streamBytes); + } + return memoryBytes + streamBytes; + } + + // Implements the seeking feature + public override long Seek(long offset, SeekOrigin origin) + { + checkDisposed(); + long newPosition = 0L; + // get new position + switch (origin) + { + case SeekOrigin.Begin: + newPosition = offset; + break; + case SeekOrigin.Current: + newPosition = memoryStream.Position + offset; + break; + case SeekOrigin.End: + // to seek from the end have have to read to the end first + if (!eos) + { + Fill(); + } + newPosition = memoryStream.Length + offset; + break; + default: + throw new ArgumentOutOfRangeException("origin"); + } + // in case the new position is beyond the memory-streams end + // and the original streams end hasn't been reached + // the original stream is read until either the stream ends or + // enough bytes have been read + if ((newPosition > memoryStream.Length) && (!eos)) + { + memoryStream.Position = memoryStream.Length; + int bytesToRead = (int)(newPosition - memoryStream.Length); + byte[] buffer = new byte[1024]; + do + { + bytesToRead -= Read(buffer, 0, (bytesToRead >= buffer.Length) ? buffer.Length : bytesToRead); + } while ((bytesToRead > 0) && (!eos)); + } + memoryStream.Position = (newPosition <= memoryStream.Length) ? newPosition : memoryStream.Length; + return 0; + } + + // No write-support + public override void SetLength(long value) + { + throw new Exception("The method or operation is not implemented."); + } + + // No write-support + public override void Write(byte[] buffer, int offset, int count) + { + throw new Exception("The method or operation is not implemented."); + } + + public void Reset() + { + checkDisposed(); + Position = 0; + } + + // Reads the wrapped stream until its end. + private void Fill() + { + if (!eos) + { + memoryStream.Position = memoryStream.Length; + int bytesRead = 0; + byte[] buffer = new byte[1024]; + do + { + bytesRead = stream.Read(buffer, 0, buffer.Length); + memoryStream.Write(buffer, 0, bytesRead); + } while (bytesRead != 0); + eos = true; + } + } + + public new void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private new void Dispose(bool disposing) + { + if (!disposed) + { + disposed = true; + if (disposing) + { + if (memoryStream != null) + { + memoryStream.Dispose(); + } + } + } + } + + public bool Disposed + { + get { return disposed; } + } + + private void checkDisposed() + { + if (disposed) throw new ObjectDisposedException("StreamWrapper"); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Delegates.cs b/Wrapper/FreeImage.NET/cs/Library/Delegates.cs index ff8847e..dda88f2 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Delegates.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Delegates.cs @@ -1,191 +1,191 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.4 $ -// $Date: 2009/09/15 11:39:10 $ -// $Id: Delegates.cs,v 1.4 2009/09/15 11:39:10 cklein05 Exp $ -// ========================================================== - -using System; -using System.IO; -using System.Runtime.InteropServices; -using FreeImageAPI.IO; - -namespace FreeImageAPI -{ - // Delegates used by the FreeImageIO structure - - /// - /// Delegate for capturing FreeImage error messages. - /// - /// The format of the image. - /// The errormessage. - // DLL_API is missing in the definition of the callbackfuntion. - [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = false)] - public delegate void OutputMessageFunction(FREE_IMAGE_FORMAT fif, string message); -} - -namespace FreeImageAPI.IO -{ - /// - /// Delegate to the C++ function fread. - /// - /// Pointer to read from. - /// Item size in bytes. - /// Maximum number of items to be read. - /// Handle/stream to read from. - /// Number of full items actually read, - /// which may be less than count if an error occurs or - /// if the end of the file is encountered before reaching count. - public delegate uint ReadProc(IntPtr buffer, uint size, uint count, fi_handle handle); - - /// - /// Delegate to the C++ function fwrite. - /// - /// Pointer to data to be written. - /// Item size in bytes. - /// Maximum number of items to be written. - /// Handle/stream to write to. - /// Number of full items actually written, - /// which may be less than count if an error occurs. - /// Also, if an error occurs, the file-position indicator cannot be determined. - public delegate uint WriteProc(IntPtr buffer, uint size, uint count, fi_handle handle); - - /// - /// Delegate to the C++ function fseek. - /// - /// Handle/stream to seek in. - /// Number of bytes from origin. - /// Initial position. - /// If successful 0 is returned; otherwise a nonzero value. - public delegate int SeekProc(fi_handle handle, int offset, SeekOrigin origin); - - /// - /// Delegate to the C++ function ftell. - /// - /// Handle/stream to retrieve its currents position from. - /// The current position. - public delegate int TellProc(fi_handle handle); - - // Delegates used by 'Plugin' structure -} - -namespace FreeImageAPI.Plugins -{ - /// - /// Delegate to a function that returns a string which describes - /// the plugins format. - /// - public delegate string FormatProc(); - - /// - /// Delegate to a function that returns a string which contains - /// a more detailed description. - /// - public delegate string DescriptionProc(); - - /// - /// Delegate to a function that returns a comma seperated list - /// of file extensions the plugin can read or write. - /// - public delegate string ExtensionListProc(); - - /// - /// Delegate to a function that returns a regular expression that - /// can be used to idientify whether a file can be handled by the plugin. - /// - public delegate string RegExprProc(); - - /// - /// Delegate to a function that opens a file. - /// - public delegate IntPtr OpenProc(ref FreeImageIO io, fi_handle handle, bool read); - - /// - /// Delegate to a function that closes a previosly opened file. - /// - public delegate void CloseProc(ref FreeImageIO io, fi_handle handle, IntPtr data); - - /// - /// Delegate to a function that returns the number of pages of a multipage - /// bitmap if the plugin is capable of handling multipage bitmaps. - /// - public delegate int PageCountProc(ref FreeImageIO io, fi_handle handle, IntPtr data); - - /// - /// UNKNOWN - /// - public delegate int PageCapabilityProc(ref FreeImageIO io, fi_handle handle, IntPtr data); - - /// - /// Delegate to a function that loads and decodes a bitmap into memory. - /// - public delegate FIBITMAP LoadProc(ref FreeImageIO io, fi_handle handle, int page, int flags, IntPtr data); - - /// - /// Delegate to a function that saves a bitmap. - /// - public delegate bool SaveProc(ref FreeImageIO io, FIBITMAP dib, fi_handle handle, int page, int flags, IntPtr data); - - /// - /// Delegate to a function that determines whether the source defined - /// by and is a valid image. - /// - public delegate bool ValidateProc(ref FreeImageIO io, fi_handle handle); - - /// - /// Delegate to a function that returns a string which contains - /// the plugin's mime type. - /// - public delegate string MimeProc(); - - /// - /// Delegate to a function that returns whether the plugin can handle the - /// specified color depth. - /// - public delegate bool SupportsExportBPPProc(int bpp); - - /// - /// Delegate to a function that returns whether the plugin can handle the - /// specified image type. - /// - public delegate bool SupportsExportTypeProc(FREE_IMAGE_TYPE type); - - /// - /// Delegate to a function that returns whether the plugin can handle - /// ICC-Profiles. - /// - public delegate bool SupportsICCProfilesProc(); - - /// - /// Callback function used by FreeImage to register plugins. - /// - public delegate void InitProc(ref Plugin plugin, int format_id); +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.4 $ +// $Date: 2009/09/15 11:39:10 $ +// $Id: Delegates.cs,v 1.4 2009/09/15 11:39:10 cklein05 Exp $ +// ========================================================== + +using System; +using System.IO; +using System.Runtime.InteropServices; +using FreeImageAPI.IO; + +namespace FreeImageAPI +{ + // Delegates used by the FreeImageIO structure + + /// + /// Delegate for capturing FreeImage error messages. + /// + /// The format of the image. + /// The errormessage. + // DLL_API is missing in the definition of the callbackfuntion. + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = false)] + public delegate void OutputMessageFunction(FREE_IMAGE_FORMAT fif, string message); +} + +namespace FreeImageAPI.IO +{ + /// + /// Delegate to the C++ function fread. + /// + /// Pointer to read from. + /// Item size in bytes. + /// Maximum number of items to be read. + /// Handle/stream to read from. + /// Number of full items actually read, + /// which may be less than count if an error occurs or + /// if the end of the file is encountered before reaching count. + public delegate uint ReadProc(IntPtr buffer, uint size, uint count, fi_handle handle); + + /// + /// Delegate to the C++ function fwrite. + /// + /// Pointer to data to be written. + /// Item size in bytes. + /// Maximum number of items to be written. + /// Handle/stream to write to. + /// Number of full items actually written, + /// which may be less than count if an error occurs. + /// Also, if an error occurs, the file-position indicator cannot be determined. + public delegate uint WriteProc(IntPtr buffer, uint size, uint count, fi_handle handle); + + /// + /// Delegate to the C++ function fseek. + /// + /// Handle/stream to seek in. + /// Number of bytes from origin. + /// Initial position. + /// If successful 0 is returned; otherwise a nonzero value. + public delegate int SeekProc(fi_handle handle, int offset, SeekOrigin origin); + + /// + /// Delegate to the C++ function ftell. + /// + /// Handle/stream to retrieve its currents position from. + /// The current position. + public delegate int TellProc(fi_handle handle); + + // Delegates used by 'Plugin' structure +} + +namespace FreeImageAPI.Plugins +{ + /// + /// Delegate to a function that returns a string which describes + /// the plugins format. + /// + public delegate string FormatProc(); + + /// + /// Delegate to a function that returns a string which contains + /// a more detailed description. + /// + public delegate string DescriptionProc(); + + /// + /// Delegate to a function that returns a comma seperated list + /// of file extensions the plugin can read or write. + /// + public delegate string ExtensionListProc(); + + /// + /// Delegate to a function that returns a regular expression that + /// can be used to idientify whether a file can be handled by the plugin. + /// + public delegate string RegExprProc(); + + /// + /// Delegate to a function that opens a file. + /// + public delegate IntPtr OpenProc(ref FreeImageIO io, fi_handle handle, bool read); + + /// + /// Delegate to a function that closes a previosly opened file. + /// + public delegate void CloseProc(ref FreeImageIO io, fi_handle handle, IntPtr data); + + /// + /// Delegate to a function that returns the number of pages of a multipage + /// bitmap if the plugin is capable of handling multipage bitmaps. + /// + public delegate int PageCountProc(ref FreeImageIO io, fi_handle handle, IntPtr data); + + /// + /// UNKNOWN + /// + public delegate int PageCapabilityProc(ref FreeImageIO io, fi_handle handle, IntPtr data); + + /// + /// Delegate to a function that loads and decodes a bitmap into memory. + /// + public delegate FIBITMAP LoadProc(ref FreeImageIO io, fi_handle handle, int page, int flags, IntPtr data); + + /// + /// Delegate to a function that saves a bitmap. + /// + public delegate bool SaveProc(ref FreeImageIO io, FIBITMAP dib, fi_handle handle, int page, int flags, IntPtr data); + + /// + /// Delegate to a function that determines whether the source defined + /// by and is a valid image. + /// + public delegate bool ValidateProc(ref FreeImageIO io, fi_handle handle); + + /// + /// Delegate to a function that returns a string which contains + /// the plugin's mime type. + /// + public delegate string MimeProc(); + + /// + /// Delegate to a function that returns whether the plugin can handle the + /// specified color depth. + /// + public delegate bool SupportsExportBPPProc(int bpp); + + /// + /// Delegate to a function that returns whether the plugin can handle the + /// specified image type. + /// + public delegate bool SupportsExportTypeProc(FREE_IMAGE_TYPE type); + + /// + /// Delegate to a function that returns whether the plugin can handle + /// ICC-Profiles. + /// + public delegate bool SupportsICCProfilesProc(); + + /// + /// Callback function used by FreeImage to register plugins. + /// + public delegate void InitProc(ref Plugin plugin, int format_id); } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/DisposalMethodType.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/DisposalMethodType.cs index ac2c1ee..ac2cd0c 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/DisposalMethodType.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/DisposalMethodType.cs @@ -1,33 +1,33 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace FreeImageAPI.Metadata -{ - /// - /// Specifies how a single frame will be handled after being displayed. - /// - public enum DisposalMethodType : byte - { - /// - /// Same behavior as but should not be used. - /// - Unspecified, - - /// - /// The image is left in place and will be overdrawn by the next image. - /// - Leave, - - /// - /// The area of the image will be blanked out by its background. - /// - Background, - - /// - /// Restores the the area of the image to the state it was before it - /// has been dawn. - /// - Previous, - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace FreeImageAPI.Metadata +{ + /// + /// Specifies how a single frame will be handled after being displayed. + /// + public enum DisposalMethodType : byte + { + /// + /// Same behavior as but should not be used. + /// + Unspecified, + + /// + /// The image is left in place and will be overdrawn by the next image. + /// + Leave, + + /// + /// The area of the image will be blanked out by its background. + /// + Background, + + /// + /// Restores the the area of the image to the state it was before it + /// has been dawn. + /// + Previous, + } +} diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_CHANNEL.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_CHANNEL.cs index 859b7d1..fbf2d39 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_CHANNEL.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_CHANNEL.cs @@ -1,84 +1,84 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:40 $ -// $Id: FREE_IMAGE_COLOR_CHANNEL.cs,v 1.1 2007/11/28 15:33:40 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Color channels. Constants used in color manipulation routines. - /// - public enum FREE_IMAGE_COLOR_CHANNEL - { - /// - /// Use red, green and blue channels - /// - FICC_RGB = 0, - /// - /// Use red channel - /// - FICC_RED = 1, - /// - /// Use green channel - /// - FICC_GREEN = 2, - /// - /// Use blue channel - /// - FICC_BLUE = 3, - /// - /// Use alpha channel - /// - FICC_ALPHA = 4, - /// - /// Use black channel - /// - FICC_BLACK = 5, - /// - /// Complex images: use real part - /// - FICC_REAL = 6, - /// - /// Complex images: use imaginary part - /// - FICC_IMAG = 7, - /// - /// Complex images: use magnitude - /// - FICC_MAG = 8, - /// - /// Complex images: use phase - /// - FICC_PHASE = 9 - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:40 $ +// $Id: FREE_IMAGE_COLOR_CHANNEL.cs,v 1.1 2007/11/28 15:33:40 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Color channels. Constants used in color manipulation routines. + /// + public enum FREE_IMAGE_COLOR_CHANNEL + { + /// + /// Use red, green and blue channels + /// + FICC_RGB = 0, + /// + /// Use red channel + /// + FICC_RED = 1, + /// + /// Use green channel + /// + FICC_GREEN = 2, + /// + /// Use blue channel + /// + FICC_BLUE = 3, + /// + /// Use alpha channel + /// + FICC_ALPHA = 4, + /// + /// Use black channel + /// + FICC_BLACK = 5, + /// + /// Complex images: use real part + /// + FICC_REAL = 6, + /// + /// Complex images: use imaginary part + /// + FICC_IMAG = 7, + /// + /// Complex images: use magnitude + /// + FICC_MAG = 8, + /// + /// Complex images: use phase + /// + FICC_PHASE = 9 + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_DEPTH.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_DEPTH.cs index 2479ce7..10ccd0c 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_DEPTH.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_DEPTH.cs @@ -1,105 +1,105 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:39 $ -// $Id: FREE_IMAGE_COLOR_DEPTH.cs,v 1.1 2007/11/28 15:33:39 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Enumeration used for color conversions. - /// FREE_IMAGE_COLOR_DEPTH contains several colors to convert to. - /// The default value 'FICD_AUTO'. - /// - [System.Flags] - public enum FREE_IMAGE_COLOR_DEPTH - { - /// - /// Unknown. - /// - FICD_UNKNOWN = 0, - /// - /// Auto selected by the used algorithm. - /// - FICD_AUTO = FICD_UNKNOWN, - /// - /// 1-bit. - /// - FICD_01_BPP = 1, - /// - /// 1-bit using dithering. - /// - FICD_01_BPP_DITHER = FICD_01_BPP, - /// - /// 1-bit using threshold. - /// - FICD_01_BPP_THRESHOLD = FICD_01_BPP | 2, - /// - /// 4-bit. - /// - FICD_04_BPP = 4, - /// - /// 8-bit. - /// - FICD_08_BPP = 8, - /// - /// 16-bit 555 (1 bit remains unused). - /// - FICD_16_BPP_555 = FICD_16_BPP | 2, - /// - /// 16-bit 565 (all bits are used). - /// - FICD_16_BPP = 16, - /// - /// 24-bit. - /// - FICD_24_BPP = 24, - /// - /// 32-bit. - /// - FICD_32_BPP = 32, - /// - /// Reorder palette (make it linear). Only affects 1-, 4- and 8-bit images. - /// The palette is only reordered in case the image is greyscale - /// (all palette entries have the same red, green and blue value). - /// - FICD_REORDER_PALETTE = 1024, - /// - /// Converts the image to greyscale. - /// - FICD_FORCE_GREYSCALE = 2048, - /// - /// Flag to mask out all non color depth flags. - /// - FICD_COLOR_MASK = FICD_01_BPP | FICD_04_BPP | FICD_08_BPP | FICD_16_BPP | FICD_24_BPP | FICD_32_BPP - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:39 $ +// $Id: FREE_IMAGE_COLOR_DEPTH.cs,v 1.1 2007/11/28 15:33:39 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Enumeration used for color conversions. + /// FREE_IMAGE_COLOR_DEPTH contains several colors to convert to. + /// The default value 'FICD_AUTO'. + /// + [System.Flags] + public enum FREE_IMAGE_COLOR_DEPTH + { + /// + /// Unknown. + /// + FICD_UNKNOWN = 0, + /// + /// Auto selected by the used algorithm. + /// + FICD_AUTO = FICD_UNKNOWN, + /// + /// 1-bit. + /// + FICD_01_BPP = 1, + /// + /// 1-bit using dithering. + /// + FICD_01_BPP_DITHER = FICD_01_BPP, + /// + /// 1-bit using threshold. + /// + FICD_01_BPP_THRESHOLD = FICD_01_BPP | 2, + /// + /// 4-bit. + /// + FICD_04_BPP = 4, + /// + /// 8-bit. + /// + FICD_08_BPP = 8, + /// + /// 16-bit 555 (1 bit remains unused). + /// + FICD_16_BPP_555 = FICD_16_BPP | 2, + /// + /// 16-bit 565 (all bits are used). + /// + FICD_16_BPP = 16, + /// + /// 24-bit. + /// + FICD_24_BPP = 24, + /// + /// 32-bit. + /// + FICD_32_BPP = 32, + /// + /// Reorder palette (make it linear). Only affects 1-, 4- and 8-bit images. + /// The palette is only reordered in case the image is greyscale + /// (all palette entries have the same red, green and blue value). + /// + FICD_REORDER_PALETTE = 1024, + /// + /// Converts the image to greyscale. + /// + FICD_FORCE_GREYSCALE = 2048, + /// + /// Flag to mask out all non color depth flags. + /// + FICD_COLOR_MASK = FICD_01_BPP | FICD_04_BPP | FICD_08_BPP | FICD_16_BPP | FICD_24_BPP | FICD_32_BPP + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_OPTIONS.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_OPTIONS.cs index 302f6bb..07f357e 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_OPTIONS.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_OPTIONS.cs @@ -1,68 +1,68 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2009/09/15 11:44:24 $ -// $Id: FREE_IMAGE_COLOR_OPTIONS.cs,v 1.1 2009/09/15 11:44:24 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Constants used in color filling routines. - /// - public enum FREE_IMAGE_COLOR_OPTIONS - { - /// - /// Default value. - /// - FICO_DEFAULT = 0x0, - /// - /// color is RGB color (contains no valid alpha channel). - /// - FICO_RGB = 0x0, - /// - /// color is RGBA color (contains a valid alpha channel). - /// - FICO_RGBA = 0x1, - /// - /// Lookup nearest RGB color from palette. - /// - FICO_NEAREST_COLOR = 0x0, - /// - /// Lookup equal RGB color from palette. - /// - FICO_EQUAL_COLOR = 0x2, - /// - /// contains the palette index to be used. - /// - FICO_ALPHA_IS_INDEX = 0x4, - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2009/09/15 11:44:24 $ +// $Id: FREE_IMAGE_COLOR_OPTIONS.cs,v 1.1 2009/09/15 11:44:24 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Constants used in color filling routines. + /// + public enum FREE_IMAGE_COLOR_OPTIONS + { + /// + /// Default value. + /// + FICO_DEFAULT = 0x0, + /// + /// color is RGB color (contains no valid alpha channel). + /// + FICO_RGB = 0x0, + /// + /// color is RGBA color (contains a valid alpha channel). + /// + FICO_RGBA = 0x1, + /// + /// Lookup nearest RGB color from palette. + /// + FICO_NEAREST_COLOR = 0x0, + /// + /// Lookup equal RGB color from palette. + /// + FICO_EQUAL_COLOR = 0x2, + /// + /// contains the palette index to be used. + /// + FICO_ALPHA_IS_INDEX = 0x4, + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_TYPE.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_TYPE.cs index f69c64d..3fbb5aa 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_TYPE.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COLOR_TYPE.cs @@ -1,68 +1,68 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:40 $ -// $Id: FREE_IMAGE_COLOR_TYPE.cs,v 1.1 2007/11/28 15:33:40 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Image color types used in FreeImage. - /// - public enum FREE_IMAGE_COLOR_TYPE - { - /// - /// min value is white - /// - FIC_MINISWHITE = 0, - /// - /// min value is black - /// - FIC_MINISBLACK = 1, - /// - /// RGB color model - /// - FIC_RGB = 2, - /// - /// color map indexed - /// - FIC_PALETTE = 3, - /// - /// RGB color model with alpha channel - /// - FIC_RGBALPHA = 4, - /// - /// CMYK color model - /// - FIC_CMYK = 5 - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:40 $ +// $Id: FREE_IMAGE_COLOR_TYPE.cs,v 1.1 2007/11/28 15:33:40 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Image color types used in FreeImage. + /// + public enum FREE_IMAGE_COLOR_TYPE + { + /// + /// min value is white + /// + FIC_MINISWHITE = 0, + /// + /// min value is black + /// + FIC_MINISBLACK = 1, + /// + /// RGB color model + /// + FIC_RGB = 2, + /// + /// color map indexed + /// + FIC_PALETTE = 3, + /// + /// RGB color model with alpha channel + /// + FIC_RGBALPHA = 4, + /// + /// CMYK color model + /// + FIC_CMYK = 5 + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COMPARE_FLAGS.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COMPARE_FLAGS.cs index 69b3035..047b003 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COMPARE_FLAGS.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_COMPARE_FLAGS.cs @@ -1,65 +1,65 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:40 $ -// $Id: FREE_IMAGE_COMPARE_FLAGS.cs,v 1.1 2007/11/28 15:33:40 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// List of combinable compare modes. - /// - [System.Flags] - public enum FREE_IMAGE_COMPARE_FLAGS - { - /// - /// Compare headers. - /// - HEADER = 0x1, - /// - /// Compare palettes. - /// - PALETTE = 0x2, - /// - /// Compare pixel data. - /// - DATA = 0x4, - /// - /// Compare meta data. - /// - METADATA = 0x8, - /// - /// Compare everything. - /// - COMPLETE = (HEADER | PALETTE | DATA | METADATA) - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:40 $ +// $Id: FREE_IMAGE_COMPARE_FLAGS.cs,v 1.1 2007/11/28 15:33:40 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// List of combinable compare modes. + /// + [System.Flags] + public enum FREE_IMAGE_COMPARE_FLAGS + { + /// + /// Compare headers. + /// + HEADER = 0x1, + /// + /// Compare palettes. + /// + PALETTE = 0x2, + /// + /// Compare pixel data. + /// + DATA = 0x4, + /// + /// Compare meta data. + /// + METADATA = 0x8, + /// + /// Compare everything. + /// + COMPLETE = (HEADER | PALETTE | DATA | METADATA) + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_DITHER.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_DITHER.cs index c1c87f8..5cf364c 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_DITHER.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_DITHER.cs @@ -1,73 +1,73 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:40 $ -// $Id: FREE_IMAGE_DITHER.cs,v 1.1 2007/11/28 15:33:40 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Dithering algorithms. - /// Constants used in FreeImage_Dither. - /// - public enum FREE_IMAGE_DITHER - { - /// - /// Floyd and Steinberg error diffusion - /// - FID_FS = 0, - /// - /// Bayer ordered dispersed dot dithering (order 2 dithering matrix) - /// - FID_BAYER4x4 = 1, - /// - /// Bayer ordered dispersed dot dithering (order 3 dithering matrix) - /// - FID_BAYER8x8 = 2, - /// - /// Ordered clustered dot dithering (order 3 - 6x6 matrix) - /// - FID_CLUSTER6x6 = 3, - /// - /// Ordered clustered dot dithering (order 4 - 8x8 matrix) - /// - FID_CLUSTER8x8 = 4, - /// - /// Ordered clustered dot dithering (order 8 - 16x16 matrix) - /// - FID_CLUSTER16x16 = 5, - /// - /// Bayer ordered dispersed dot dithering (order 4 dithering matrix) - /// - FID_BAYER16x16 = 6 - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:40 $ +// $Id: FREE_IMAGE_DITHER.cs,v 1.1 2007/11/28 15:33:40 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Dithering algorithms. + /// Constants used in FreeImage_Dither. + /// + public enum FREE_IMAGE_DITHER + { + /// + /// Floyd and Steinberg error diffusion + /// + FID_FS = 0, + /// + /// Bayer ordered dispersed dot dithering (order 2 dithering matrix) + /// + FID_BAYER4x4 = 1, + /// + /// Bayer ordered dispersed dot dithering (order 3 dithering matrix) + /// + FID_BAYER8x8 = 2, + /// + /// Ordered clustered dot dithering (order 3 - 6x6 matrix) + /// + FID_CLUSTER6x6 = 3, + /// + /// Ordered clustered dot dithering (order 4 - 8x8 matrix) + /// + FID_CLUSTER8x8 = 4, + /// + /// Ordered clustered dot dithering (order 8 - 16x16 matrix) + /// + FID_CLUSTER16x16 = 5, + /// + /// Bayer ordered dispersed dot dithering (order 4 dithering matrix) + /// + FID_BAYER16x16 = 6 + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_FILTER.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_FILTER.cs index 3d54566..6b283b1 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_FILTER.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_FILTER.cs @@ -1,68 +1,68 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:39 $ -// $Id: FREE_IMAGE_FILTER.cs,v 1.1 2007/11/28 15:33:39 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Upsampling / downsampling filters. Constants used in FreeImage_Rescale. - /// - public enum FREE_IMAGE_FILTER - { - /// - /// Box, pulse, Fourier window, 1st order (constant) b-spline - /// - FILTER_BOX = 0, - /// - /// Mitchell and Netravali's two-param cubic filter - /// - FILTER_BICUBIC = 1, - /// - /// Bilinear filter - /// - FILTER_BILINEAR = 2, - /// - /// 4th order (cubic) b-spline - /// - FILTER_BSPLINE = 3, - /// - /// Catmull-Rom spline, Overhauser spline - /// - FILTER_CATMULLROM = 4, - /// - /// Lanczos3 filter - /// - FILTER_LANCZOS3 = 5 - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:39 $ +// $Id: FREE_IMAGE_FILTER.cs,v 1.1 2007/11/28 15:33:39 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Upsampling / downsampling filters. Constants used in FreeImage_Rescale. + /// + public enum FREE_IMAGE_FILTER + { + /// + /// Box, pulse, Fourier window, 1st order (constant) b-spline + /// + FILTER_BOX = 0, + /// + /// Mitchell and Netravali's two-param cubic filter + /// + FILTER_BICUBIC = 1, + /// + /// Bilinear filter + /// + FILTER_BILINEAR = 2, + /// + /// 4th order (cubic) b-spline + /// + FILTER_BSPLINE = 3, + /// + /// Catmull-Rom spline, Overhauser spline + /// + FILTER_CATMULLROM = 4, + /// + /// Lanczos3 filter + /// + FILTER_LANCZOS3 = 5 + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_FORMAT.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_FORMAT.cs index e57fb0e..ecccf17 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_FORMAT.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_FORMAT.cs @@ -1,192 +1,192 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.2 $ -// $Date: 2009/09/15 11:44:42 $ -// $Id: FREE_IMAGE_FORMAT.cs,v 1.2 2009/09/15 11:44:42 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// I/O image format identifiers. - /// - public enum FREE_IMAGE_FORMAT - { - /// - /// Unknown format (returned value only, never use it as input value) - /// - FIF_UNKNOWN = -1, - /// - /// Windows or OS/2 Bitmap File (*.BMP) - /// - FIF_BMP = 0, - /// - /// Windows Icon (*.ICO) - /// - FIF_ICO = 1, - /// - /// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE) - /// - FIF_JPEG = 2, - /// - /// JPEG Network Graphics (*.JNG) - /// - FIF_JNG = 3, - /// - /// Commodore 64 Koala format (*.KOA) - /// - FIF_KOALA = 4, - /// - /// Amiga IFF (*.IFF, *.LBM) - /// - FIF_LBM = 5, - /// - /// Amiga IFF (*.IFF, *.LBM) - /// - FIF_IFF = 5, - /// - /// Multiple Network Graphics (*.MNG) - /// - FIF_MNG = 6, - /// - /// Portable Bitmap (ASCII) (*.PBM) - /// - FIF_PBM = 7, - /// - /// Portable Bitmap (BINARY) (*.PBM) - /// - FIF_PBMRAW = 8, - /// - /// Kodak PhotoCD (*.PCD) - /// - FIF_PCD = 9, - /// - /// Zsoft Paintbrush PCX bitmap format (*.PCX) - /// - FIF_PCX = 10, - /// - /// Portable Graymap (ASCII) (*.PGM) - /// - FIF_PGM = 11, - /// - /// Portable Graymap (BINARY) (*.PGM) - /// - FIF_PGMRAW = 12, - /// - /// Portable Network Graphics (*.PNG) - /// - FIF_PNG = 13, - /// - /// Portable Pixelmap (ASCII) (*.PPM) - /// - FIF_PPM = 14, - /// - /// Portable Pixelmap (BINARY) (*.PPM) - /// - FIF_PPMRAW = 15, - /// - /// Sun Rasterfile (*.RAS) - /// - FIF_RAS = 16, - /// - /// truevision Targa files (*.TGA, *.TARGA) - /// - FIF_TARGA = 17, - /// - /// Tagged Image File Format (*.TIF, *.TIFF) - /// - FIF_TIFF = 18, - /// - /// Wireless Bitmap (*.WBMP) - /// - FIF_WBMP = 19, - /// - /// Adobe Photoshop (*.PSD) - /// - FIF_PSD = 20, - /// - /// Dr. Halo (*.CUT) - /// - FIF_CUT = 21, - /// - /// X11 Bitmap Format (*.XBM) - /// - FIF_XBM = 22, - /// - /// X11 Pixmap Format (*.XPM) - /// - FIF_XPM = 23, - /// - /// DirectDraw Surface (*.DDS) - /// - FIF_DDS = 24, - /// - /// Graphics Interchange Format (*.GIF) - /// - FIF_GIF = 25, - /// - /// High Dynamic Range (*.HDR) - /// - FIF_HDR = 26, - /// - /// Raw Fax format CCITT G3 (*.G3) - /// - FIF_FAXG3 = 27, - /// - /// Silicon Graphics SGI image format (*.SGI) - /// - FIF_SGI = 28, - /// - /// OpenEXR format (*.EXR) - /// - FIF_EXR = 29, - /// - /// JPEG-2000 format (*.J2K, *.J2C) - /// - FIF_J2K = 30, - /// - /// JPEG-2000 format (*.JP2) - /// - FIF_JP2 = 31, - /// - /// Portable FloatMap (*.PFM) - /// - FIF_PFM = 32, - /// - /// Macintosh PICT (*.PICT) - /// - FIF_PICT = 33, - /// - /// RAW camera image (*.*) - /// - FIF_RAW = 34, - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.2 $ +// $Date: 2009/09/15 11:44:42 $ +// $Id: FREE_IMAGE_FORMAT.cs,v 1.2 2009/09/15 11:44:42 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// I/O image format identifiers. + /// + public enum FREE_IMAGE_FORMAT + { + /// + /// Unknown format (returned value only, never use it as input value) + /// + FIF_UNKNOWN = -1, + /// + /// Windows or OS/2 Bitmap File (*.BMP) + /// + FIF_BMP = 0, + /// + /// Windows Icon (*.ICO) + /// + FIF_ICO = 1, + /// + /// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE) + /// + FIF_JPEG = 2, + /// + /// JPEG Network Graphics (*.JNG) + /// + FIF_JNG = 3, + /// + /// Commodore 64 Koala format (*.KOA) + /// + FIF_KOALA = 4, + /// + /// Amiga IFF (*.IFF, *.LBM) + /// + FIF_LBM = 5, + /// + /// Amiga IFF (*.IFF, *.LBM) + /// + FIF_IFF = 5, + /// + /// Multiple Network Graphics (*.MNG) + /// + FIF_MNG = 6, + /// + /// Portable Bitmap (ASCII) (*.PBM) + /// + FIF_PBM = 7, + /// + /// Portable Bitmap (BINARY) (*.PBM) + /// + FIF_PBMRAW = 8, + /// + /// Kodak PhotoCD (*.PCD) + /// + FIF_PCD = 9, + /// + /// Zsoft Paintbrush PCX bitmap format (*.PCX) + /// + FIF_PCX = 10, + /// + /// Portable Graymap (ASCII) (*.PGM) + /// + FIF_PGM = 11, + /// + /// Portable Graymap (BINARY) (*.PGM) + /// + FIF_PGMRAW = 12, + /// + /// Portable Network Graphics (*.PNG) + /// + FIF_PNG = 13, + /// + /// Portable Pixelmap (ASCII) (*.PPM) + /// + FIF_PPM = 14, + /// + /// Portable Pixelmap (BINARY) (*.PPM) + /// + FIF_PPMRAW = 15, + /// + /// Sun Rasterfile (*.RAS) + /// + FIF_RAS = 16, + /// + /// truevision Targa files (*.TGA, *.TARGA) + /// + FIF_TARGA = 17, + /// + /// Tagged Image File Format (*.TIF, *.TIFF) + /// + FIF_TIFF = 18, + /// + /// Wireless Bitmap (*.WBMP) + /// + FIF_WBMP = 19, + /// + /// Adobe Photoshop (*.PSD) + /// + FIF_PSD = 20, + /// + /// Dr. Halo (*.CUT) + /// + FIF_CUT = 21, + /// + /// X11 Bitmap Format (*.XBM) + /// + FIF_XBM = 22, + /// + /// X11 Pixmap Format (*.XPM) + /// + FIF_XPM = 23, + /// + /// DirectDraw Surface (*.DDS) + /// + FIF_DDS = 24, + /// + /// Graphics Interchange Format (*.GIF) + /// + FIF_GIF = 25, + /// + /// High Dynamic Range (*.HDR) + /// + FIF_HDR = 26, + /// + /// Raw Fax format CCITT G3 (*.G3) + /// + FIF_FAXG3 = 27, + /// + /// Silicon Graphics SGI image format (*.SGI) + /// + FIF_SGI = 28, + /// + /// OpenEXR format (*.EXR) + /// + FIF_EXR = 29, + /// + /// JPEG-2000 format (*.J2K, *.J2C) + /// + FIF_J2K = 30, + /// + /// JPEG-2000 format (*.JP2) + /// + FIF_JP2 = 31, + /// + /// Portable FloatMap (*.PFM) + /// + FIF_PFM = 32, + /// + /// Macintosh PICT (*.PICT) + /// + FIF_PICT = 33, + /// + /// RAW camera image (*.*) + /// + FIF_RAW = 34, + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_JPEG_OPERATION.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_JPEG_OPERATION.cs index e76dc22..d493f55 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_JPEG_OPERATION.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_JPEG_OPERATION.cs @@ -1,76 +1,76 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:38 $ -// $Id: FREE_IMAGE_JPEG_OPERATION.cs,v 1.1 2007/11/28 15:33:38 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Lossless JPEG transformations constants used in FreeImage_JPEGTransform. - /// - public enum FREE_IMAGE_JPEG_OPERATION - { - /// - /// no transformation - /// - FIJPEG_OP_NONE = 0, - /// - /// horizontal flip - /// - FIJPEG_OP_FLIP_H = 1, - /// - /// vertical flip - /// - FIJPEG_OP_FLIP_V = 2, - /// - /// transpose across UL-to-LR axis - /// - FIJPEG_OP_TRANSPOSE = 3, - /// - /// transpose across UR-to-LL axis - /// - FIJPEG_OP_TRANSVERSE = 4, - /// - /// 90-degree clockwise rotation - /// - FIJPEG_OP_ROTATE_90 = 5, - /// - /// 180-degree rotation - /// - FIJPEG_OP_ROTATE_180 = 6, - /// - /// 270-degree clockwise (or 90 ccw) - /// - FIJPEG_OP_ROTATE_270 = 7 - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:38 $ +// $Id: FREE_IMAGE_JPEG_OPERATION.cs,v 1.1 2007/11/28 15:33:38 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Lossless JPEG transformations constants used in FreeImage_JPEGTransform. + /// + public enum FREE_IMAGE_JPEG_OPERATION + { + /// + /// no transformation + /// + FIJPEG_OP_NONE = 0, + /// + /// horizontal flip + /// + FIJPEG_OP_FLIP_H = 1, + /// + /// vertical flip + /// + FIJPEG_OP_FLIP_V = 2, + /// + /// transpose across UL-to-LR axis + /// + FIJPEG_OP_TRANSPOSE = 3, + /// + /// transpose across UR-to-LL axis + /// + FIJPEG_OP_TRANSVERSE = 4, + /// + /// 90-degree clockwise rotation + /// + FIJPEG_OP_ROTATE_90 = 5, + /// + /// 180-degree rotation + /// + FIJPEG_OP_ROTATE_180 = 6, + /// + /// 270-degree clockwise (or 90 ccw) + /// + FIJPEG_OP_ROTATE_270 = 7 + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_LOAD_FLAGS.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_LOAD_FLAGS.cs index 0f8c91b..5e2b4d4 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_LOAD_FLAGS.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_LOAD_FLAGS.cs @@ -1,111 +1,111 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.2 $ -// $Date: 2009/09/15 11:45:16 $ -// $Id: FREE_IMAGE_LOAD_FLAGS.cs,v 1.2 2009/09/15 11:45:16 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Flags used in load functions. - /// - [System.Flags] - public enum FREE_IMAGE_LOAD_FLAGS - { - /// - /// Default option for all types. - /// - DEFAULT = 0, - /// - /// Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color. - /// - GIF_LOAD256 = 1, - /// - /// 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading. - /// - GIF_PLAYBACK = 2, - /// - /// Convert to 32bpp and create an alpha channel from the AND-mask when loading. - /// - ICO_MAKEALPHA = 1, - /// - /// Load the file as fast as possible, sacrificing some quality. - /// - JPEG_FAST = 0x0001, - /// - /// Load the file with the best quality, sacrificing some speed. - /// - JPEG_ACCURATE = 0x0002, - /// - /// Load separated CMYK "as is" (use | to combine with other load flags). - /// - JPEG_CMYK = 0x0004, - /// - /// Load and rotate according to Exif 'Orientation' tag if available. - /// - JPEG_EXIFROTATE = 0x0008, - /// - /// Load the bitmap sized 768 x 512. - /// - PCD_BASE = 1, - /// - /// Load the bitmap sized 384 x 256. - /// - PCD_BASEDIV4 = 2, - /// - /// Load the bitmap sized 192 x 128. - /// - PCD_BASEDIV16 = 3, - /// - /// Avoid gamma correction. - /// - PNG_IGNOREGAMMA = 1, - /// - /// If set the loader converts RGB555 and ARGB8888 -> RGB888. - /// - TARGA_LOAD_RGB888 = 1, - /// - /// Reads tags for separated CMYK. - /// - TIFF_CMYK = 0x0001, - /// - /// Tries to load the JPEG preview image, embedded in - /// Exif Metadata or load the image as RGB 24-bit if no - /// preview image is available. - /// - RAW_PREVIEW = 0x1, - /// - /// Loads the image as RGB 24-bit. - /// - RAW_DISPLAY = 0x2, - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.2 $ +// $Date: 2009/09/15 11:45:16 $ +// $Id: FREE_IMAGE_LOAD_FLAGS.cs,v 1.2 2009/09/15 11:45:16 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Flags used in load functions. + /// + [System.Flags] + public enum FREE_IMAGE_LOAD_FLAGS + { + /// + /// Default option for all types. + /// + DEFAULT = 0, + /// + /// Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color. + /// + GIF_LOAD256 = 1, + /// + /// 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading. + /// + GIF_PLAYBACK = 2, + /// + /// Convert to 32bpp and create an alpha channel from the AND-mask when loading. + /// + ICO_MAKEALPHA = 1, + /// + /// Load the file as fast as possible, sacrificing some quality. + /// + JPEG_FAST = 0x0001, + /// + /// Load the file with the best quality, sacrificing some speed. + /// + JPEG_ACCURATE = 0x0002, + /// + /// Load separated CMYK "as is" (use | to combine with other load flags). + /// + JPEG_CMYK = 0x0004, + /// + /// Load and rotate according to Exif 'Orientation' tag if available. + /// + JPEG_EXIFROTATE = 0x0008, + /// + /// Load the bitmap sized 768 x 512. + /// + PCD_BASE = 1, + /// + /// Load the bitmap sized 384 x 256. + /// + PCD_BASEDIV4 = 2, + /// + /// Load the bitmap sized 192 x 128. + /// + PCD_BASEDIV16 = 3, + /// + /// Avoid gamma correction. + /// + PNG_IGNOREGAMMA = 1, + /// + /// If set the loader converts RGB555 and ARGB8888 -> RGB888. + /// + TARGA_LOAD_RGB888 = 1, + /// + /// Reads tags for separated CMYK. + /// + TIFF_CMYK = 0x0001, + /// + /// Tries to load the JPEG preview image, embedded in + /// Exif Metadata or load the image as RGB 24-bit if no + /// preview image is available. + /// + RAW_PREVIEW = 0x1, + /// + /// Loads the image as RGB 24-bit. + /// + RAW_DISPLAY = 0x2, + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_MDMODEL.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_MDMODEL.cs index 4fb4f66..99907aa 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_MDMODEL.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_MDMODEL.cs @@ -1,92 +1,92 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:39 $ -// $Id: FREE_IMAGE_MDMODEL.cs,v 1.1 2007/11/28 15:33:39 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Metadata models supported by FreeImage. - /// - public enum FREE_IMAGE_MDMODEL - { - /// - /// No data - /// - FIMD_NODATA = -1, - /// - /// single comment or keywords - /// - FIMD_COMMENTS = 0, - /// - /// Exif-TIFF metadata - /// - FIMD_EXIF_MAIN = 1, - /// - /// Exif-specific metadata - /// - FIMD_EXIF_EXIF = 2, - /// - /// Exif GPS metadata - /// - FIMD_EXIF_GPS = 3, - /// - /// Exif maker note metadata - /// - FIMD_EXIF_MAKERNOTE = 4, - /// - /// Exif interoperability metadata - /// - FIMD_EXIF_INTEROP = 5, - /// - /// IPTC/NAA metadata - /// - FIMD_IPTC = 6, - /// - /// Abobe XMP metadata - /// - FIMD_XMP = 7, - /// - /// GeoTIFF metadata - /// - FIMD_GEOTIFF = 8, - /// - /// Animation metadata - /// - FIMD_ANIMATION = 9, - /// - /// Used to attach other metadata types to a dib - /// - FIMD_CUSTOM = 10 - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:39 $ +// $Id: FREE_IMAGE_MDMODEL.cs,v 1.1 2007/11/28 15:33:39 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Metadata models supported by FreeImage. + /// + public enum FREE_IMAGE_MDMODEL + { + /// + /// No data + /// + FIMD_NODATA = -1, + /// + /// single comment or keywords + /// + FIMD_COMMENTS = 0, + /// + /// Exif-TIFF metadata + /// + FIMD_EXIF_MAIN = 1, + /// + /// Exif-specific metadata + /// + FIMD_EXIF_EXIF = 2, + /// + /// Exif GPS metadata + /// + FIMD_EXIF_GPS = 3, + /// + /// Exif maker note metadata + /// + FIMD_EXIF_MAKERNOTE = 4, + /// + /// Exif interoperability metadata + /// + FIMD_EXIF_INTEROP = 5, + /// + /// IPTC/NAA metadata + /// + FIMD_IPTC = 6, + /// + /// Abobe XMP metadata + /// + FIMD_XMP = 7, + /// + /// GeoTIFF metadata + /// + FIMD_GEOTIFF = 8, + /// + /// Animation metadata + /// + FIMD_ANIMATION = 9, + /// + /// Used to attach other metadata types to a dib + /// + FIMD_CUSTOM = 10 + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_MDTYPE.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_MDTYPE.cs index 60a0d11..6a3060b 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_MDTYPE.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_MDTYPE.cs @@ -1,105 +1,105 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:39 $ -// $Id: FREE_IMAGE_MDTYPE.cs,v 1.1 2007/11/28 15:33:39 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Tag data type information (based on TIFF specifications) - /// Note: RATIONALs are the ratio of two 32-bit integer values. - /// - public enum FREE_IMAGE_MDTYPE - { - /// - /// placeholder - /// - FIDT_NOTYPE = 0, - /// - /// 8-bit unsigned integer - /// - FIDT_BYTE = 1, - /// - /// 8-bit bytes w/ last byte null - /// - FIDT_ASCII = 2, - /// - /// 16-bit unsigned integer - /// - FIDT_SHORT = 3, - /// - /// 32-bit unsigned integer - /// - FIDT_LONG = 4, - /// - /// 64-bit unsigned fraction - /// - FIDT_RATIONAL = 5, - /// - /// 8-bit signed integer - /// - FIDT_SBYTE = 6, - /// - /// 8-bit untyped data - /// - FIDT_UNDEFINED = 7, - /// - /// 16-bit signed integer - /// - FIDT_SSHORT = 8, - /// - /// 32-bit signed integer - /// - FIDT_SLONG = 9, - /// - /// 64-bit signed fraction - /// - FIDT_SRATIONAL = 10, - /// - /// 32-bit IEEE floating point - /// - FIDT_FLOAT = 11, - /// - /// 64-bit IEEE floating point - /// - FIDT_DOUBLE = 12, - /// - /// 32-bit unsigned integer (offset) - /// - FIDT_IFD = 13, - /// - /// 32-bit RGBQUAD - /// - FIDT_PALETTE = 14 - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:39 $ +// $Id: FREE_IMAGE_MDTYPE.cs,v 1.1 2007/11/28 15:33:39 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Tag data type information (based on TIFF specifications) + /// Note: RATIONALs are the ratio of two 32-bit integer values. + /// + public enum FREE_IMAGE_MDTYPE + { + /// + /// placeholder + /// + FIDT_NOTYPE = 0, + /// + /// 8-bit unsigned integer + /// + FIDT_BYTE = 1, + /// + /// 8-bit bytes w/ last byte null + /// + FIDT_ASCII = 2, + /// + /// 16-bit unsigned integer + /// + FIDT_SHORT = 3, + /// + /// 32-bit unsigned integer + /// + FIDT_LONG = 4, + /// + /// 64-bit unsigned fraction + /// + FIDT_RATIONAL = 5, + /// + /// 8-bit signed integer + /// + FIDT_SBYTE = 6, + /// + /// 8-bit untyped data + /// + FIDT_UNDEFINED = 7, + /// + /// 16-bit signed integer + /// + FIDT_SSHORT = 8, + /// + /// 32-bit signed integer + /// + FIDT_SLONG = 9, + /// + /// 64-bit signed fraction + /// + FIDT_SRATIONAL = 10, + /// + /// 32-bit IEEE floating point + /// + FIDT_FLOAT = 11, + /// + /// 64-bit IEEE floating point + /// + FIDT_DOUBLE = 12, + /// + /// 32-bit unsigned integer (offset) + /// + FIDT_IFD = 13, + /// + /// 32-bit RGBQUAD + /// + FIDT_PALETTE = 14 + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_METADATA_COPY.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_METADATA_COPY.cs index f0d4a8c..d487ea0 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_METADATA_COPY.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_METADATA_COPY.cs @@ -1,56 +1,56 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:39 $ -// $Id: FREE_IMAGE_METADATA_COPY.cs,v 1.1 2007/11/28 15:33:39 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Flags for copying data from a bitmap to another. - /// - public enum FREE_IMAGE_METADATA_COPY - { - /// - /// Exisiting metadata will remain unchanged. - /// - KEEP_EXISITNG = 0x0, - /// - /// Existing metadata will be cleared. - /// - CLEAR_EXISTING = 0x1, - /// - /// Existing metadata will be overwritten. - /// - REPLACE_EXISTING = 0x2 - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:39 $ +// $Id: FREE_IMAGE_METADATA_COPY.cs,v 1.1 2007/11/28 15:33:39 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Flags for copying data from a bitmap to another. + /// + public enum FREE_IMAGE_METADATA_COPY + { + /// + /// Exisiting metadata will remain unchanged. + /// + KEEP_EXISITNG = 0x0, + /// + /// Existing metadata will be cleared. + /// + CLEAR_EXISTING = 0x1, + /// + /// Existing metadata will be overwritten. + /// + REPLACE_EXISTING = 0x2 + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_QUANTIZE.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_QUANTIZE.cs index 3aeace2..aa05d7f 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_QUANTIZE.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_QUANTIZE.cs @@ -1,53 +1,53 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:39 $ -// $Id: FREE_IMAGE_QUANTIZE.cs,v 1.1 2007/11/28 15:33:39 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Color quantization algorithms. - /// Constants used in FreeImage_ColorQuantize. - /// - public enum FREE_IMAGE_QUANTIZE - { - /// - /// Xiaolin Wu color quantization algorithm - /// - FIQ_WUQUANT = 0, - /// - /// NeuQuant neural-net quantization algorithm by Anthony Dekker - /// - FIQ_NNQUANT = 1 - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:39 $ +// $Id: FREE_IMAGE_QUANTIZE.cs,v 1.1 2007/11/28 15:33:39 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Color quantization algorithms. + /// Constants used in FreeImage_ColorQuantize. + /// + public enum FREE_IMAGE_QUANTIZE + { + /// + /// Xiaolin Wu color quantization algorithm + /// + FIQ_WUQUANT = 0, + /// + /// NeuQuant neural-net quantization algorithm by Anthony Dekker + /// + FIQ_NNQUANT = 1 + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_SAVE_FLAGS.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_SAVE_FLAGS.cs index ad1fc55..a6eb520 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_SAVE_FLAGS.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_SAVE_FLAGS.cs @@ -1,191 +1,191 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.3 $ -// $Date: 2011/12/22 14:53:28 $ -// $Id: FREE_IMAGE_SAVE_FLAGS.cs,v 1.3 2011/12/22 14:53:28 drolon Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Flags used in save functions. - /// - [System.Flags] - public enum FREE_IMAGE_SAVE_FLAGS - { - /// - /// Default option for all types. - /// - DEFAULT = 0, - /// - /// Save with run length encoding. - /// - BMP_SAVE_RLE = 1, - /// - /// Save data as float instead of as half (not recommended). - /// - EXR_FLOAT = 0x0001, - /// - /// Save with no compression. - /// - EXR_NONE = 0x0002, - /// - /// Save with zlib compression, in blocks of 16 scan lines. - /// - EXR_ZIP = 0x0004, - /// - /// Save with piz-based wavelet compression. - /// - EXR_PIZ = 0x0008, - /// - /// Save with lossy 24-bit float compression. - /// - EXR_PXR24 = 0x0010, - /// - /// Save with lossy 44% float compression - goes to 22% when combined with EXR_LC. - /// - EXR_B44 = 0x0020, - /// - /// Save images with one luminance and two chroma channels, rather than as RGB (lossy compression). - /// - EXR_LC = 0x0040, - /// - /// Save with superb quality (100:1). - /// - JPEG_QUALITYSUPERB = 0x80, - /// - /// Save with good quality (75:1). - /// - JPEG_QUALITYGOOD = 0x0100, - /// - /// Save with normal quality (50:1). - /// - JPEG_QUALITYNORMAL = 0x0200, - /// - /// Save with average quality (25:1). - /// - JPEG_QUALITYAVERAGE = 0x0400, - /// - /// Save with bad quality (10:1). - /// - JPEG_QUALITYBAD = 0x0800, - /// - /// Save as a progressive-JPEG (use | to combine with other save flags). - /// - JPEG_PROGRESSIVE = 0x2000, - /// - /// Save with high 4x1 chroma subsampling (4:1:1). - /// - JPEG_SUBSAMPLING_411 = 0x1000, - /// - /// Save with medium 2x2 medium chroma (4:2:0). - /// - JPEG_SUBSAMPLING_420 = 0x4000, - /// - /// Save with low 2x1 chroma subsampling (4:2:2). - /// - JPEG_SUBSAMPLING_422 = 0x8000, - /// - /// Save with no chroma subsampling (4:4:4). - /// - JPEG_SUBSAMPLING_444 = 0x10000, - /// - /// On saving, compute optimal Huffman coding tables (can reduce a few percent of file size). - /// - JPEG_OPTIMIZE = 0x20000, - /// - /// save basic JPEG, without metadata or any markers. - /// - JPEG_BASELINE = 0x40000, - /// - /// Save using ZLib level 1 compression flag - /// (default value is ). - /// - PNG_Z_BEST_SPEED = 0x0001, - /// - /// Save using ZLib level 6 compression flag (default recommended value). - /// - PNG_Z_DEFAULT_COMPRESSION = 0x0006, - /// - /// save using ZLib level 9 compression flag - /// (default value is ). - /// - PNG_Z_BEST_COMPRESSION = 0x0009, - /// - /// Save without ZLib compression. - /// - PNG_Z_NO_COMPRESSION = 0x0100, - /// - /// Save using Adam7 interlacing (use | to combine with other save flags). - /// - PNG_INTERLACED = 0x0200, - /// - /// If set the writer saves in ASCII format (i.e. P1, P2 or P3). - /// - PNM_SAVE_ASCII = 1, - /// - /// Stores tags for separated CMYK (use | to combine with compression flags). - /// - TIFF_CMYK = 0x0001, - /// - /// Save using PACKBITS compression. - /// - TIFF_PACKBITS = 0x0100, - /// - /// Save using DEFLATE compression (a.k.a. ZLIB compression). - /// - TIFF_DEFLATE = 0x0200, - /// - /// Save using ADOBE DEFLATE compression. - /// - TIFF_ADOBE_DEFLATE = 0x0400, - /// - /// Save without any compression. - /// - TIFF_NONE = 0x0800, - /// - /// Save using CCITT Group 3 fax encoding. - /// - TIFF_CCITTFAX3 = 0x1000, - /// - /// Save using CCITT Group 4 fax encoding. - /// - TIFF_CCITTFAX4 = 0x2000, - /// - /// Save using LZW compression. - /// - TIFF_LZW = 0x4000, - /// - /// Save using JPEG compression. - /// - TIFF_JPEG = 0x8000 - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.3 $ +// $Date: 2011/12/22 14:53:28 $ +// $Id: FREE_IMAGE_SAVE_FLAGS.cs,v 1.3 2011/12/22 14:53:28 drolon Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Flags used in save functions. + /// + [System.Flags] + public enum FREE_IMAGE_SAVE_FLAGS + { + /// + /// Default option for all types. + /// + DEFAULT = 0, + /// + /// Save with run length encoding. + /// + BMP_SAVE_RLE = 1, + /// + /// Save data as float instead of as half (not recommended). + /// + EXR_FLOAT = 0x0001, + /// + /// Save with no compression. + /// + EXR_NONE = 0x0002, + /// + /// Save with zlib compression, in blocks of 16 scan lines. + /// + EXR_ZIP = 0x0004, + /// + /// Save with piz-based wavelet compression. + /// + EXR_PIZ = 0x0008, + /// + /// Save with lossy 24-bit float compression. + /// + EXR_PXR24 = 0x0010, + /// + /// Save with lossy 44% float compression - goes to 22% when combined with EXR_LC. + /// + EXR_B44 = 0x0020, + /// + /// Save images with one luminance and two chroma channels, rather than as RGB (lossy compression). + /// + EXR_LC = 0x0040, + /// + /// Save with superb quality (100:1). + /// + JPEG_QUALITYSUPERB = 0x80, + /// + /// Save with good quality (75:1). + /// + JPEG_QUALITYGOOD = 0x0100, + /// + /// Save with normal quality (50:1). + /// + JPEG_QUALITYNORMAL = 0x0200, + /// + /// Save with average quality (25:1). + /// + JPEG_QUALITYAVERAGE = 0x0400, + /// + /// Save with bad quality (10:1). + /// + JPEG_QUALITYBAD = 0x0800, + /// + /// Save as a progressive-JPEG (use | to combine with other save flags). + /// + JPEG_PROGRESSIVE = 0x2000, + /// + /// Save with high 4x1 chroma subsampling (4:1:1). + /// + JPEG_SUBSAMPLING_411 = 0x1000, + /// + /// Save with medium 2x2 medium chroma (4:2:0). + /// + JPEG_SUBSAMPLING_420 = 0x4000, + /// + /// Save with low 2x1 chroma subsampling (4:2:2). + /// + JPEG_SUBSAMPLING_422 = 0x8000, + /// + /// Save with no chroma subsampling (4:4:4). + /// + JPEG_SUBSAMPLING_444 = 0x10000, + /// + /// On saving, compute optimal Huffman coding tables (can reduce a few percent of file size). + /// + JPEG_OPTIMIZE = 0x20000, + /// + /// save basic JPEG, without metadata or any markers. + /// + JPEG_BASELINE = 0x40000, + /// + /// Save using ZLib level 1 compression flag + /// (default value is ). + /// + PNG_Z_BEST_SPEED = 0x0001, + /// + /// Save using ZLib level 6 compression flag (default recommended value). + /// + PNG_Z_DEFAULT_COMPRESSION = 0x0006, + /// + /// save using ZLib level 9 compression flag + /// (default value is ). + /// + PNG_Z_BEST_COMPRESSION = 0x0009, + /// + /// Save without ZLib compression. + /// + PNG_Z_NO_COMPRESSION = 0x0100, + /// + /// Save using Adam7 interlacing (use | to combine with other save flags). + /// + PNG_INTERLACED = 0x0200, + /// + /// If set the writer saves in ASCII format (i.e. P1, P2 or P3). + /// + PNM_SAVE_ASCII = 1, + /// + /// Stores tags for separated CMYK (use | to combine with compression flags). + /// + TIFF_CMYK = 0x0001, + /// + /// Save using PACKBITS compression. + /// + TIFF_PACKBITS = 0x0100, + /// + /// Save using DEFLATE compression (a.k.a. ZLIB compression). + /// + TIFF_DEFLATE = 0x0200, + /// + /// Save using ADOBE DEFLATE compression. + /// + TIFF_ADOBE_DEFLATE = 0x0400, + /// + /// Save without any compression. + /// + TIFF_NONE = 0x0800, + /// + /// Save using CCITT Group 3 fax encoding. + /// + TIFF_CCITTFAX3 = 0x1000, + /// + /// Save using CCITT Group 4 fax encoding. + /// + TIFF_CCITTFAX4 = 0x2000, + /// + /// Save using LZW compression. + /// + TIFF_LZW = 0x4000, + /// + /// Save using JPEG compression. + /// + TIFF_JPEG = 0x8000 + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_TMO.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_TMO.cs index 5f3b9fd..36033e4 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_TMO.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_TMO.cs @@ -1,56 +1,56 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:39 $ -// $Id: FREE_IMAGE_TMO.cs,v 1.1 2007/11/28 15:33:39 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Tone mapping operators. Constants used in FreeImage_ToneMapping. - /// - public enum FREE_IMAGE_TMO - { - /// - /// Adaptive logarithmic mapping (F. Drago, 2003) - /// - FITMO_DRAGO03 = 0, - /// - /// Dynamic range reduction inspired by photoreceptor physiology (E. Reinhard, 2005) - /// - FITMO_REINHARD05 = 1, - /// - /// Gradient domain high dynamic range compression (R. Fattal, 2002) - /// - FITMO_FATTAL02 - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:39 $ +// $Id: FREE_IMAGE_TMO.cs,v 1.1 2007/11/28 15:33:39 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Tone mapping operators. Constants used in FreeImage_ToneMapping. + /// + public enum FREE_IMAGE_TMO + { + /// + /// Adaptive logarithmic mapping (F. Drago, 2003) + /// + FITMO_DRAGO03 = 0, + /// + /// Dynamic range reduction inspired by photoreceptor physiology (E. Reinhard, 2005) + /// + FITMO_REINHARD05 = 1, + /// + /// Gradient domain high dynamic range compression (R. Fattal, 2002) + /// + FITMO_FATTAL02 + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_TYPE.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_TYPE.cs index eeeb43e..a407bca 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_TYPE.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_TYPE.cs @@ -1,96 +1,96 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:40 $ -// $Id: FREE_IMAGE_TYPE.cs,v 1.1 2007/11/28 15:33:40 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Image types used in FreeImage. - /// - public enum FREE_IMAGE_TYPE - { - /// - /// unknown type - /// - FIT_UNKNOWN = 0, - /// - /// standard image : 1-, 4-, 8-, 16-, 24-, 32-bit - /// - FIT_BITMAP = 1, - /// - /// array of unsigned short : unsigned 16-bit - /// - FIT_UINT16 = 2, - /// - /// array of short : signed 16-bit - /// - FIT_INT16 = 3, - /// - /// array of unsigned long : unsigned 32-bit - /// - FIT_UINT32 = 4, - /// - /// array of long : signed 32-bit - /// - FIT_INT32 = 5, - /// - /// array of float : 32-bit IEEE floating point - /// - FIT_FLOAT = 6, - /// - /// array of double : 64-bit IEEE floating point - /// - FIT_DOUBLE = 7, - /// - /// array of FICOMPLEX : 2 x 64-bit IEEE floating point - /// - FIT_COMPLEX = 8, - /// - /// 48-bit RGB image : 3 x 16-bit - /// - FIT_RGB16 = 9, - /// - /// 64-bit RGBA image : 4 x 16-bit - /// - FIT_RGBA16 = 10, - /// - /// 96-bit RGB float image : 3 x 32-bit IEEE floating point - /// - FIT_RGBF = 11, - /// - /// 128-bit RGBA float image : 4 x 32-bit IEEE floating point - /// - FIT_RGBAF = 12 - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:40 $ +// $Id: FREE_IMAGE_TYPE.cs,v 1.1 2007/11/28 15:33:40 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Image types used in FreeImage. + /// + public enum FREE_IMAGE_TYPE + { + /// + /// unknown type + /// + FIT_UNKNOWN = 0, + /// + /// standard image : 1-, 4-, 8-, 16-, 24-, 32-bit + /// + FIT_BITMAP = 1, + /// + /// array of unsigned short : unsigned 16-bit + /// + FIT_UINT16 = 2, + /// + /// array of short : signed 16-bit + /// + FIT_INT16 = 3, + /// + /// array of unsigned long : unsigned 32-bit + /// + FIT_UINT32 = 4, + /// + /// array of long : signed 32-bit + /// + FIT_INT32 = 5, + /// + /// array of float : 32-bit IEEE floating point + /// + FIT_FLOAT = 6, + /// + /// array of double : 64-bit IEEE floating point + /// + FIT_DOUBLE = 7, + /// + /// array of FICOMPLEX : 2 x 64-bit IEEE floating point + /// + FIT_COMPLEX = 8, + /// + /// 48-bit RGB image : 3 x 16-bit + /// + FIT_RGB16 = 9, + /// + /// 64-bit RGBA image : 4 x 16-bit + /// + FIT_RGBA16 = 10, + /// + /// 96-bit RGB float image : 3 x 32-bit IEEE floating point + /// + FIT_RGBF = 11, + /// + /// 128-bit RGBA float image : 4 x 32-bit IEEE floating point + /// + FIT_RGBAF = 12 + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/ICC_FLAGS.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/ICC_FLAGS.cs index cf1f6cd..2e1cdee 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/ICC_FLAGS.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/ICC_FLAGS.cs @@ -1,53 +1,53 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:38 $ -// $Id: ICC_FLAGS.cs,v 1.1 2007/11/28 15:33:38 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// Flags for ICC profiles. - /// - [System.Flags] - public enum ICC_FLAGS : ushort - { - /// - /// Default value. - /// - FIICC_DEFAULT = 0x00, - /// - /// The color is CMYK. - /// - FIICC_COLOR_IS_CMYK = 0x01 - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:38 $ +// $Id: ICC_FLAGS.cs,v 1.1 2007/11/28 15:33:38 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// Flags for ICC profiles. + /// + [System.Flags] + public enum ICC_FLAGS : ushort + { + /// + /// Default value. + /// + FIICC_DEFAULT = 0x00, + /// + /// The color is CMYK. + /// + FIICC_COLOR_IS_CMYK = 0x01 + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Enumerations/MD_SEARCH_FLAGS.cs b/Wrapper/FreeImage.NET/cs/Library/Enumerations/MD_SEARCH_FLAGS.cs index aa91715..923f7e9 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Enumerations/MD_SEARCH_FLAGS.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Enumerations/MD_SEARCH_FLAGS.cs @@ -1,57 +1,57 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.1 $ -// $Date: 2007/11/28 15:33:40 $ -// $Id: MD_SEARCH_FLAGS.cs,v 1.1 2007/11/28 15:33:40 cklein05 Exp $ -// ========================================================== - -namespace FreeImageAPI -{ - /// - /// List different search modes. - /// - [System.Flags] - public enum MD_SEARCH_FLAGS - { - /// - /// The key of the metadata. - /// - KEY = 0x1, - /// - /// The description of the metadata - /// - DESCRIPTION = 0x2, - /// - /// The ToString value of the metadata - /// - TOSTRING = 0x4, - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.1 $ +// $Date: 2007/11/28 15:33:40 $ +// $Id: MD_SEARCH_FLAGS.cs,v 1.1 2007/11/28 15:33:40 cklein05 Exp $ +// ========================================================== + +namespace FreeImageAPI +{ + /// + /// List different search modes. + /// + [System.Flags] + public enum MD_SEARCH_FLAGS + { + /// + /// The key of the metadata. + /// + KEY = 0x1, + /// + /// The description of the metadata + /// + DESCRIPTION = 0x2, + /// + /// The ToString value of the metadata + /// + TOSTRING = 0x4, + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/FreeImageStaticImports.cs b/Wrapper/FreeImage.NET/cs/Library/FreeImageStaticImports.cs index 54c8f7f..35e675d 100644 --- a/Wrapper/FreeImage.NET/cs/Library/FreeImageStaticImports.cs +++ b/Wrapper/FreeImage.NET/cs/Library/FreeImageStaticImports.cs @@ -1,2369 +1,2369 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.9 $ -// $Date: 2009/09/15 11:41:37 $ -// $Id: FreeImageStaticImports.cs,v 1.9 2009/09/15 11:41:37 cklein05 Exp $ -// ========================================================== - -using System; -using System.Runtime.InteropServices; -using FreeImageAPI.Plugins; -using FreeImageAPI.IO; - -namespace FreeImageAPI -{ - public static partial class FreeImage - { - #region Constants - - /// - /// Filename of the FreeImage library. - /// - private const string FreeImageLibrary = "FreeImage"; - - /// - /// Number of bytes to shift left within a 4 byte block. - /// - public const int FI_RGBA_RED = 2; - - /// - /// Number of bytes to shift left within a 4 byte block. - /// - public const int FI_RGBA_GREEN = 1; - - /// - /// Number of bytes to shift left within a 4 byte block. - /// - public const int FI_RGBA_BLUE = 0; - - /// - /// Number of bytes to shift left within a 4 byte block. - /// - public const int FI_RGBA_ALPHA = 3; - - /// - /// Mask indicating the position of the given color. - /// - public const uint FI_RGBA_RED_MASK = 0x00FF0000; - - /// - /// Mask indicating the position of the given color. - /// - public const uint FI_RGBA_GREEN_MASK = 0x0000FF00; - - /// - /// Mask indicating the position of the given color. - /// - public const uint FI_RGBA_BLUE_MASK = 0x000000FF; - - /// - /// Mask indicating the position of the given color. - /// - public const uint FI_RGBA_ALPHA_MASK = 0xFF000000; - - /// - /// Number of bits to shift left within a 32 bit block. - /// - public const int FI_RGBA_RED_SHIFT = 16; - - /// - /// Number of bits to shift left within a 32 bit block. - /// - public const int FI_RGBA_GREEN_SHIFT = 8; - - /// - /// Number of bits to shift left within a 32 bit block. - /// - public const int FI_RGBA_BLUE_SHIFT = 0; - - /// - /// Number of bits to shift left within a 32 bit block. - /// - public const int FI_RGBA_ALPHA_SHIFT = 24; - - /// - /// Mask indicating the position of color components of a 32 bit color. - /// - public const uint FI_RGBA_RGB_MASK = (FI_RGBA_RED_MASK | FI_RGBA_GREEN_MASK | FI_RGBA_BLUE_MASK); - - /// - /// Mask indicating the position of the given color. - /// - public const int FI16_555_RED_MASK = 0x7C00; - - /// - /// Mask indicating the position of the given color. - /// - public const int FI16_555_GREEN_MASK = 0x03E0; - - /// - /// Mask indicating the position of the given color. - /// - public const int FI16_555_BLUE_MASK = 0x001F; - - /// - /// Number of bits to shift left within a 16 bit block. - /// - public const int FI16_555_RED_SHIFT = 10; - - /// - /// Number of bits to shift left within a 16 bit block. - /// - public const int FI16_555_GREEN_SHIFT = 5; - - /// - /// Number of bits to shift left within a 16 bit block. - /// - public const int FI16_555_BLUE_SHIFT = 0; - - /// - /// Mask indicating the position of the given color. - /// - public const int FI16_565_RED_MASK = 0xF800; - - /// - /// Mask indicating the position of the given color. - /// - public const int FI16_565_GREEN_MASK = 0x07E0; - - /// - /// Mask indicating the position of the given color. - /// - public const int FI16_565_BLUE_MASK = 0x001F; - - /// - /// Number of bits to shift left within a 16 bit block. - /// - public const int FI16_565_RED_SHIFT = 11; - - /// - /// Number of bits to shift left within a 16 bit block. - /// - public const int FI16_565_GREEN_SHIFT = 5; - - /// - /// Number of bits to shift left within a 16 bit block. - /// - public const int FI16_565_BLUE_SHIFT = 0; - - #endregion - - #region General functions - - /// - /// Initialises the library. - /// - /// - /// When the is true, FreeImage won't make use of external plugins. - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Initialise")] - private static extern void Initialise(bool load_local_plugins_only); - - /// - /// Deinitialises the library. - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeInitialise")] - private static extern void DeInitialise(); - - /// - /// Returns a string containing the current version of the library. - /// - /// The current version of the library. - public static unsafe string GetVersion() { return PtrToStr(GetVersion_()); } - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetVersion")] - private static unsafe extern byte* GetVersion_(); - - /// - /// Returns a string containing a standard copyright message. - /// - /// A standard copyright message. - public static unsafe string GetCopyrightMessage() { return PtrToStr(GetCopyrightMessage_()); } - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetCopyrightMessage")] - private static unsafe extern byte* GetCopyrightMessage_(); - - /// - /// Calls the set error message function in FreeImage. - /// - /// Format of the bitmaps. - /// The error message. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_OutputMessageProc")] - public static extern void OutputMessageProc(FREE_IMAGE_FORMAT fif, string message); - - /// - /// You use the function FreeImage_SetOutputMessage to capture the log string - /// so that you can show it to the user of the program. - /// The callback is implemented in the event of this class. - /// - /// The function is private because FreeImage can only have a single - /// callback function. To use the callback use the - /// event of this class. - /// Handler to the callback function. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetOutputMessage")] - internal static extern void SetOutputMessage(OutputMessageFunction omf); - - #endregion - - #region Bitmap management functions - - /// - /// Creates a new bitmap in memory. - /// - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new Bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap - /// Red part of the color layout. - /// eg: 0xFF0000 - /// Green part of the color layout. - /// eg: 0x00FF00 - /// Blue part of the color layout. - /// eg: 0x0000FF - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Allocate")] - public static extern FIBITMAP Allocate(int width, int height, int bpp, - uint red_mask, uint green_mask, uint blue_mask); - - /// - /// Creates a new bitmap in memory. - /// - /// Type of the image. - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new Bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap - /// Red part of the color layout. - /// eg: 0xFF0000 - /// Green part of the color layout. - /// eg: 0x00FF00 - /// Blue part of the color layout. - /// eg: 0x0000FF - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateT")] - public static extern FIBITMAP AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp, - uint red_mask, uint green_mask, uint blue_mask); - - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateEx")] - internal static extern FIBITMAP AllocateEx(int width, int height, int bpp, - IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, - uint red_mask, uint green_mask, uint blue_mask); - - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateExT")] - internal static extern FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp, - IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, - uint red_mask, uint green_mask, uint blue_mask); - - /// - /// Makes an exact reproduction of an existing bitmap, including metadata and attached profile if any. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Clone")] - public static extern FIBITMAP Clone(FIBITMAP dib); - - /// - /// Deletes a previously loaded FIBITMAP from memory. - /// - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Unload")] - public static extern void Unload(FIBITMAP dib); - - /// - /// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP. - /// - /// Type of the bitmap. - /// Name of the file to decode. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")] - public static extern FIBITMAP Load(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags); - - /// - /// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP. - /// The filename supports UNICODE. - /// - /// Type of the bitmap. - /// Name of the file to decode. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")] - private static extern FIBITMAP LoadU(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags); - - /// - /// Loads a bitmap from an arbitrary source. - /// - /// Type of the bitmap. - /// A FreeImageIO structure with functionpointers to handle the source. - /// A handle to the source. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadFromHandle")] - public static extern FIBITMAP LoadFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io, fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags); - - /// - /// Saves a previosly loaded FIBITMAP to a file. - /// - /// Type of the bitmap. - /// Handle to a FreeImage bitmap. - /// Name of the file to save to. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_SaveU")] - public static extern bool Save(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags); - - /// - /// Saves a previosly loaded FIBITMAP to a file. - /// The filename supports UNICODE. - /// - /// Type of the bitmap. - /// Handle to a FreeImage bitmap. - /// Name of the file to save to. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_SaveU")] - private static extern bool SaveU(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags); - - /// - /// Saves a bitmap to an arbitrary source. - /// - /// Type of the bitmap. - /// Handle to a FreeImage bitmap. - /// A FreeImageIO structure with functionpointers to handle the source. - /// A handle to the source. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SaveToHandle")] - public static extern bool SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP dib, ref FreeImageIO io, fi_handle handle, - FREE_IMAGE_SAVE_FLAGS flags); - - #endregion - - #region Memory I/O streams - - /// - /// Open a memory stream. - /// - /// Pointer to the data in memory. - /// Length of the data in byte. - /// Handle to a memory stream. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMemory")] - public static extern FIMEMORY OpenMemory(IntPtr data, uint size_in_bytes); - - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMemory")] - internal static extern FIMEMORY OpenMemoryEx(byte[] data, uint size_in_bytes); - - /// - /// Close and free a memory stream. - /// - /// Handle to a memory stream. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloseMemory")] - public static extern void CloseMemory(FIMEMORY stream); - - /// - /// Decodes a bitmap from a stream, allocates memory for it and returns it as a FIBITMAP. - /// - /// Type of the bitmap. - /// Handle to a memory stream. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadFromMemory")] - public static extern FIBITMAP LoadFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags); - - /// - /// Saves a previosly loaded FIBITMAP to a stream. - /// - /// Type of the bitmap. - /// Handle to a FreeImage bitmap. - /// Handle to a memory stream. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SaveToMemory")] - public static extern bool SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP dib, FIMEMORY stream, FREE_IMAGE_SAVE_FLAGS flags); - - /// - /// Gets the current position of a memory handle. - /// - /// Handle to a memory stream. - /// The current file position if successful, -1 otherwise. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TellMemory")] - public static extern int TellMemory(FIMEMORY stream); - - /// - /// Moves the memory handle to a specified location. - /// - /// Handle to a memory stream. - /// Number of bytes from origin. - /// Initial position. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SeekMemory")] - public static extern bool SeekMemory(FIMEMORY stream, int offset, System.IO.SeekOrigin origin); - - /// - /// Provides a direct buffer access to a memory stream. - /// - /// The target memory stream. - /// Pointer to the data in memory. - /// Size of the data in bytes. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AcquireMemory")] - public static extern bool AcquireMemory(FIMEMORY stream, ref IntPtr data, ref uint size_in_bytes); - - /// - /// Reads data from a memory stream. - /// - /// The buffer to store the data in. - /// Size in bytes of the items. - /// Number of items to read. - /// The stream to read from. - /// The memory pointer associated with stream is increased by the number of bytes actually read. - /// The number of full items actually read. - /// May be less than count on error or stream-end. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ReadMemory")] - public static extern uint ReadMemory(byte[] buffer, uint size, uint count, FIMEMORY stream); - - /// - /// Writes data to a memory stream. - /// - /// The buffer to read the data from. - /// Size in bytes of the items. - /// Number of items to write. - /// The stream to write to. - /// The memory pointer associated with stream is increased by the number of bytes actually written. - /// The number of full items actually written. - /// May be less than count on error or stream-end. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_WriteMemory")] - public static extern uint WriteMemory(byte[] buffer, uint size, uint count, FIMEMORY stream); - - /// - /// Open a multi-page bitmap from a memory stream. - /// - /// Type of the bitmap. - /// The stream to decode. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage multi-paged bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadMultiBitmapFromMemory")] - public static extern FIMULTIBITMAP LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags); - - #endregion - - #region Plugin functions - - /// - /// Registers a new plugin to be used in FreeImage. - /// - /// Pointer to the function that initialises the plugin. - /// A string describing the format of the plugin. - /// A string describing the plugin. - /// A string witha comma sperated list of extensions. f.e: "pl,pl2,pl4" - /// A regular expression used to identify the bitmap. - /// The format idientifier assigned by FreeImage. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_RegisterLocalPlugin")] - public static extern FREE_IMAGE_FORMAT RegisterLocalPlugin(InitProc proc_address, - string format, string description, string extension, string regexpr); - - /// - /// Registers a new plugin to be used in FreeImage. The plugin is residing in a DLL. - /// The Init function must be called “Init” and must use the stdcall calling convention. - /// - /// Complete path to the dll file hosting the plugin. - /// A string describing the format of the plugin. - /// A string describing the plugin. - /// A string witha comma sperated list of extensions. f.e: "pl,pl2,pl4" - /// A regular expression used to identify the bitmap. - /// The format idientifier assigned by FreeImage. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_RegisterExternalPlugin")] - public static extern FREE_IMAGE_FORMAT RegisterExternalPlugin(string path, - string format, string description, string extension, string regexpr); - - /// - /// Retrieves the number of FREE_IMAGE_FORMAT identifiers being currently registered. - /// - /// The number of registered formats. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFCount")] - public static extern int GetFIFCount(); - - /// - /// Enables or disables a plugin. - /// - /// The plugin to enable or disable. - /// True: enable the plugin. false: disable the plugin. - /// The previous state of the plugin. - /// 1 - enabled. 0 - disables. -1 plugin does not exist. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPluginEnabled")] - public static extern int SetPluginEnabled(FREE_IMAGE_FORMAT fif, bool enable); - - /// - /// Retrieves the state of a plugin. - /// - /// The plugin to check. - /// 1 - enabled. 0 - disables. -1 plugin does not exist. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsPluginEnabled")] - public static extern int IsPluginEnabled(FREE_IMAGE_FORMAT fif); - - /// - /// Returns a identifier from the format string that was used to register the FIF. - /// - /// The string that was used to register the plugin. - /// A identifier from the format. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetFIFFromFormat")] - public static extern FREE_IMAGE_FORMAT GetFIFFromFormat(string format); - - /// - /// Returns a identifier from a MIME content type string - /// (MIME stands for Multipurpose Internet Mail Extension). - /// - /// A MIME content type. - /// A identifier from the MIME. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetFIFFromMime")] - public static extern FREE_IMAGE_FORMAT GetFIFFromMime(string mime); - - /// - /// Returns the string that was used to register a plugin from the system assigned . - /// - /// The assigned . - /// The string that was used to register the plugin. - public static unsafe string GetFormatFromFIF(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFormatFromFIF_(fif)); } - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFormatFromFIF")] - private static unsafe extern byte* GetFormatFromFIF_(FREE_IMAGE_FORMAT fif); - - /// - /// Returns a comma-delimited file extension list describing the bitmap formats the given plugin can read and/or write. - /// - /// The desired . - /// A comma-delimited file extension list. - public static unsafe string GetFIFExtensionList(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFExtensionList_(fif)); } - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFExtensionList")] - private static unsafe extern byte* GetFIFExtensionList_(FREE_IMAGE_FORMAT fif); - - /// - /// Returns a descriptive string that describes the bitmap formats the given plugin can read and/or write. - /// - /// The desired . - /// A descriptive string that describes the bitmap formats. - public static unsafe string GetFIFDescription(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFDescription_(fif)); } - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFDescription")] - private static unsafe extern byte* GetFIFDescription_(FREE_IMAGE_FORMAT fif); - - /// - /// Returns a regular expression string that can be used by a regular expression engine to identify the bitmap. - /// FreeImageQt makes use of this function. - /// - /// The desired . - /// A regular expression string. - public static unsafe string GetFIFRegExpr(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFRegExpr_(fif)); } - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFRegExpr")] - private static unsafe extern byte* GetFIFRegExpr_(FREE_IMAGE_FORMAT fif); - - /// - /// Given a identifier, returns a MIME content type string (MIME stands for Multipurpose Internet Mail Extension). - /// - /// The desired . - /// A MIME content type string. - public static unsafe string GetFIFMimeType(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFMimeType_(fif)); } - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFMimeType")] - private static unsafe extern byte* GetFIFMimeType_(FREE_IMAGE_FORMAT fif); - - /// - /// This function takes a filename or a file-extension and returns the plugin that can - /// read/write files with that extension in the form of a identifier. - /// - /// The filename or -extension. - /// The of the plugin. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")] - public static extern FREE_IMAGE_FORMAT GetFIFFromFilename(string filename); - - /// - /// This function takes a filename or a file-extension and returns the plugin that can - /// read/write files with that extension in the form of a identifier. - /// Supports UNICODE filenames. - /// - /// The filename or -extension. - /// The of the plugin. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")] - private static extern FREE_IMAGE_FORMAT GetFIFFromFilenameU(string filename); - - /// - /// Checks if a plugin can load bitmaps. - /// - /// The of the plugin. - /// True if the plugin can load bitmaps, else false. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsReading")] - public static extern bool FIFSupportsReading(FREE_IMAGE_FORMAT fif); - - /// - /// Checks if a plugin can save bitmaps. - /// - /// The of the plugin. - /// True if the plugin can save bitmaps, else false. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsWriting")] - public static extern bool FIFSupportsWriting(FREE_IMAGE_FORMAT fif); - - /// - /// Checks if a plugin can save bitmaps in the desired bit depth. - /// - /// The of the plugin. - /// The desired bit depth. - /// True if the plugin can save bitmaps in the desired bit depth, else false. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsExportBPP")] - public static extern bool FIFSupportsExportBPP(FREE_IMAGE_FORMAT fif, int bpp); - - /// - /// Checks if a plugin can save a bitmap in the desired data type. - /// - /// The of the plugin. - /// The desired image type. - /// True if the plugin can save bitmaps as the desired type, else false. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsExportType")] - public static extern bool FIFSupportsExportType(FREE_IMAGE_FORMAT fif, FREE_IMAGE_TYPE type); - - /// - /// Checks if a plugin can load or save an ICC profile. - /// - /// The of the plugin. - /// True if the plugin can load or save an ICC profile, else false. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsICCProfiles")] - public static extern bool FIFSupportsICCProfiles(FREE_IMAGE_FORMAT fif); - - #endregion - - #region Multipage functions - - /// - /// Loads a FreeImage multi-paged bitmap. - /// Load flags can be provided by the flags parameter. - /// - /// Format of the image. - /// The complete name of the file to load. - /// When true a new bitmap is created. - /// When true the bitmap will be loaded read only. - /// When true performance is increased at the cost of memory. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage multi-paged bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMultiBitmap")] - public static extern FIMULTIBITMAP OpenMultiBitmap(FREE_IMAGE_FORMAT fif, string filename, bool create_new, - bool read_only, bool keep_cache_in_memory, FREE_IMAGE_LOAD_FLAGS flags); - - /// - /// Loads a FreeImage multi-pages bitmap from the specified handle - /// using the specified functions. - /// Load flags can be provided by the flags parameter. - /// - /// Format of the image. - /// IO functions used to read from the specified handle. - /// The handle to load the bitmap from. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage multi-paged bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMultiBitmapFromHandle")] - public static extern FIMULTIBITMAP OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io, - fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags); - - /// - /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, applies any changes made to it. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloseMultiBitmap")] - private static extern bool CloseMultiBitmap_(FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags); - - /// - /// Returns the number of pages currently available in the multi-paged bitmap. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Number of pages. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPageCount")] - public static extern int GetPageCount(FIMULTIBITMAP bitmap); - - /// - /// Appends a new page to the end of the bitmap. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AppendPage")] - public static extern void AppendPage(FIMULTIBITMAP bitmap, FIBITMAP data); - - /// - /// Inserts a new page before the given position in the bitmap. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Page has to be a number smaller than the current number of pages available in the bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_InsertPage")] - public static extern void InsertPage(FIMULTIBITMAP bitmap, int page, FIBITMAP data); - - /// - /// Deletes the page on the given position. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Number of the page to delete. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeletePage")] - public static extern void DeletePage(FIMULTIBITMAP bitmap, int page); - - /// - /// Locks a page in memory for editing. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Number of the page to lock. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LockPage")] - public static extern FIBITMAP LockPage(FIMULTIBITMAP bitmap, int page); - - /// - /// Unlocks a previously locked page and gives it back to the multi-page engine. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Handle to a FreeImage bitmap. - /// If true, the page is applied to the multi-page bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_UnlockPage")] - public static extern void UnlockPage(FIMULTIBITMAP bitmap, FIBITMAP data, bool changed); - - /// - /// Moves the source page to the position of the target page. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// New position of the page. - /// Old position of the page. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MovePage")] - public static extern bool MovePage(FIMULTIBITMAP bitmap, int target, int source); - - /// - /// Returns an array of page-numbers that are currently locked in memory. - /// When the pages parameter is null, the size of the array is returned in the count variable. - /// - /// - /// - /// int[] lockedPages = null; - /// int count = 0; - /// GetLockedPageNumbers(dib, lockedPages, ref count); - /// lockedPages = new int[count]; - /// GetLockedPageNumbers(dib, lockedPages, ref count); - /// - /// - /// Handle to a FreeImage multi-paged bitmap. - /// The list of locked pages in the multi-pages bitmap. - /// If set to null, count will contain the number of pages. - /// If is set to null count will contain the number of locked pages. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetLockedPageNumbers")] - public static extern bool GetLockedPageNumbers(FIMULTIBITMAP bitmap, int[] pages, ref int count); - - #endregion - - #region Filetype functions - - /// - /// Orders FreeImage to analyze the bitmap signature. - /// - /// Name of the file to analyze. - /// Reserved parameter - use 0. - /// Type of the bitmap. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")] - public static extern FREE_IMAGE_FORMAT GetFileType(string filename, int size); - - - /// - /// Orders FreeImage to analyze the bitmap signature. - /// Supports UNICODE filenames. - /// - /// Name of the file to analyze. - /// Reserved parameter - use 0. - /// Type of the bitmap. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")] - private static extern FREE_IMAGE_FORMAT GetFileTypeU(string filename, int size); - - /// - /// Uses the structure as described in the topic bitmap management functions - /// to identify a bitmap type. - /// - /// A structure with functionpointers to handle the source. - /// A handle to the source. - /// Size in bytes of the source. - /// Type of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromHandle")] - public static extern FREE_IMAGE_FORMAT GetFileTypeFromHandle(ref FreeImageIO io, fi_handle handle, int size); - - /// - /// Uses a memory handle to identify a bitmap type. - /// - /// Pointer to the stream. - /// Size in bytes of the source. - /// Type of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromMemory")] - public static extern FREE_IMAGE_FORMAT GetFileTypeFromMemory(FIMEMORY stream, int size); - - #endregion - - #region Helper functions - - /// - /// Returns whether the platform is using Little Endian. - /// - /// Returns true if the platform is using Litte Endian, else false. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsLittleEndian")] - public static extern bool IsLittleEndian(); - - /// - /// Converts a X11 color name into a corresponding RGB value. - /// - /// Name of the color to convert. - /// Red component. - /// Green component. - /// Blue component. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_LookupX11Color")] - public static extern bool LookupX11Color(string szColor, out byte nRed, out byte nGreen, out byte nBlue); - - /// - /// Converts a SVG color name into a corresponding RGB value. - /// - /// Name of the color to convert. - /// Red component. - /// Green component. - /// Blue component. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_LookupSVGColor")] - public static extern bool LookupSVGColor(string szColor, out byte nRed, out byte nGreen, out byte nBlue); - - #endregion - - #region Pixel access functions - - /// - /// Returns a pointer to the data-bits of the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Pointer to the data-bits. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBits")] - public static extern IntPtr GetBits(FIBITMAP dib); - - /// - /// Returns a pointer to the start of the given scanline in the bitmap's data-bits. - /// - /// Handle to a FreeImage bitmap. - /// Number of the scanline. - /// Pointer to the scanline. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetScanLine")] - public static extern IntPtr GetScanLine(FIBITMAP dib, int scanline); - - /// - /// Get the pixel index of a palettized image at position (x, y), including range check (slow access). - /// - /// Handle to a FreeImage bitmap. - /// Pixel position in horizontal direction. - /// Pixel position in vertical direction. - /// The pixel index. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPixelIndex")] - public static extern bool GetPixelIndex(FIBITMAP dib, uint x, uint y, out byte value); - - /// - /// Get the pixel color of a 16-, 24- or 32-bit image at position (x, y), including range check (slow access). - /// - /// Handle to a FreeImage bitmap. - /// Pixel position in horizontal direction. - /// Pixel position in vertical direction. - /// The pixel color. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPixelColor")] - public static extern bool GetPixelColor(FIBITMAP dib, uint x, uint y, out RGBQUAD value); - - /// - /// Set the pixel index of a palettized image at position (x, y), including range check (slow access). - /// - /// Handle to a FreeImage bitmap. - /// Pixel position in horizontal direction. - /// Pixel position in vertical direction. - /// The new pixel index. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPixelIndex")] - public static extern bool SetPixelIndex(FIBITMAP dib, uint x, uint y, ref byte value); - - /// - /// Set the pixel color of a 16-, 24- or 32-bit image at position (x, y), including range check (slow access). - /// - /// Handle to a FreeImage bitmap. - /// Pixel position in horizontal direction. - /// Pixel position in vertical direction. - /// The new pixel color. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPixelColor")] - public static extern bool SetPixelColor(FIBITMAP dib, uint x, uint y, ref RGBQUAD value); - - #endregion - - #region Bitmap information functions - - /// - /// Retrieves the type of the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Type of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetImageType")] - public static extern FREE_IMAGE_TYPE GetImageType(FIBITMAP dib); - - /// - /// Returns the number of colors used in a bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Palette-size for palletised bitmaps, and 0 for high-colour bitmaps. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetColorsUsed")] - public static extern uint GetColorsUsed(FIBITMAP dib); - - /// - /// Returns the size of one pixel in the bitmap in bits. - /// - /// Handle to a FreeImage bitmap. - /// Size of one pixel in the bitmap in bits. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBPP")] - public static extern uint GetBPP(FIBITMAP dib); - - /// - /// Returns the width of the bitmap in pixel units. - /// - /// Handle to a FreeImage bitmap. - /// With of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetWidth")] - public static extern uint GetWidth(FIBITMAP dib); - - /// - /// Returns the height of the bitmap in pixel units. - /// - /// Handle to a FreeImage bitmap. - /// Height of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetHeight")] - public static extern uint GetHeight(FIBITMAP dib); - - /// - /// Returns the width of the bitmap in bytes. - /// - /// Handle to a FreeImage bitmap. - /// With of the bitmap in bytes. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetLine")] - public static extern uint GetLine(FIBITMAP dib); - - /// - /// Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary, - /// also known as pitch or stride or scan width. - /// - /// Handle to a FreeImage bitmap. - /// With of the bitmap in bytes. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPitch")] - public static extern uint GetPitch(FIBITMAP dib); - - /// - /// Returns the size of the DIB-element of a FIBITMAP in memory. - /// - /// Handle to a FreeImage bitmap. - /// Size of the DIB-element - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDIBSize")] - public static extern uint GetDIBSize(FIBITMAP dib); - - /// - /// Returns a pointer to the bitmap's palette. - /// - /// Handle to a FreeImage bitmap. - /// Pointer to the bitmap's palette. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPalette")] - public static extern IntPtr GetPalette(FIBITMAP dib); - - /// - /// Returns the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The horizontal resolution, in pixels-per-meter. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDotsPerMeterX")] - public static extern uint GetDotsPerMeterX(FIBITMAP dib); - - /// - /// Returns the vertical resolution, in pixels-per-meter, of the target device for the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The vertical resolution, in pixels-per-meter. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDotsPerMeterY")] - public static extern uint GetDotsPerMeterY(FIBITMAP dib); - - /// - /// Set the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The new horizontal resolution. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetDotsPerMeterX")] - public static extern void SetDotsPerMeterX(FIBITMAP dib, uint res); - - /// - /// Set the vertical resolution, in pixels-per-meter, of the target device for the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The new vertical resolution. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetDotsPerMeterY")] - public static extern void SetDotsPerMeterY(FIBITMAP dib, uint res); - - /// - /// Returns a pointer to the of the DIB-element in a FIBITMAP. - /// - /// Handle to a FreeImage bitmap. - /// Poiter to the header of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetInfoHeader")] - public static extern IntPtr GetInfoHeader(FIBITMAP dib); - - /// - /// Alias for FreeImage_GetInfoHeader that returns a pointer to a - /// rather than to a . - /// - /// Handle to a FreeImage bitmap. - /// Pointer to the structure for the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetInfo")] - public static extern IntPtr GetInfo(FIBITMAP dib); - - /// - /// Investigates the color type of the bitmap by reading the bitmap's pixel bits and analysing them. - /// - /// Handle to a FreeImage bitmap. - /// The color type of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetColorType")] - public static extern FREE_IMAGE_COLOR_TYPE GetColorType(FIBITMAP dib); - - /// - /// Returns a bit pattern describing the red color component of a pixel in a FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The bit pattern for RED. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetRedMask")] - public static extern uint GetRedMask(FIBITMAP dib); - - /// - /// Returns a bit pattern describing the green color component of a pixel in a FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The bit pattern for green. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetGreenMask")] - public static extern uint GetGreenMask(FIBITMAP dib); - - /// - /// Returns a bit pattern describing the blue color component of a pixel in a FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The bit pattern for blue. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBlueMask")] - public static extern uint GetBlueMask(FIBITMAP dib); - - /// - /// Returns the number of transparent colors in a palletised bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The number of transparent colors in a palletised bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparencyCount")] - public static extern uint GetTransparencyCount(FIBITMAP dib); - - /// - /// Returns a pointer to the bitmap's transparency table. - /// - /// Handle to a FreeImage bitmap. - /// Pointer to the bitmap's transparency table. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparencyTable")] - public static extern IntPtr GetTransparencyTable(FIBITMAP dib); - - /// - /// Tells FreeImage if it should make use of the transparency table - /// or the alpha channel that may accompany a bitmap. - /// - /// Handle to a FreeImage bitmap. - /// True to enable the transparency, false to disable. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparent")] - public static extern void SetTransparent(FIBITMAP dib, bool enabled); - - /// - /// Set the bitmap's transparency table. Only affects palletised bitmaps. - /// - /// Handle to a FreeImage bitmap. - /// Pointer to the bitmap's new transparency table. - /// The number of transparent colors in the new transparency table. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparencyTable")] - internal static extern void SetTransparencyTable(FIBITMAP dib, byte[] table, int count); - - /// - /// Returns whether the transparency table is enabled. - /// - /// Handle to a FreeImage bitmap. - /// Returns true when the transparency table is enabled (1-, 4- or 8-bit images) - /// or when the input dib contains alpha values (32-bit images). Returns false otherwise. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsTransparent")] - public static extern bool IsTransparent(FIBITMAP dib); - - /// - /// Returns whether the bitmap has a file background color. - /// - /// Handle to a FreeImage bitmap. - /// Returns true when the image has a file background color, false otherwise. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_HasBackgroundColor")] - public static extern bool HasBackgroundColor(FIBITMAP dib); - - /// - /// Returns the file background color of an image. - /// For 8-bit images, the color index in the palette is returned in the - /// rgbReserved member of the bkcolor parameter. - /// - /// Handle to a FreeImage bitmap. - /// The background color. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBackgroundColor")] - public static extern bool GetBackgroundColor(FIBITMAP dib, out RGBQUAD bkcolor); - - /// - /// Set the file background color of an image. - /// When saving an image to PNG, this background color is transparently saved to the PNG file. - /// - /// Handle to a FreeImage bitmap. - /// The new background color. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetBackgroundColor")] - public static unsafe extern bool SetBackgroundColor(FIBITMAP dib, ref RGBQUAD bkcolor); - - /// - /// Set the file background color of an image. - /// When saving an image to PNG, this background color is transparently saved to the PNG file. - /// When the bkcolor parameter is null, the background color is removed from the image. - /// - /// This overloaded version of the function with an array parameter is provided to allow - /// passing null in the parameter. This is similar to the - /// original C/C++ function. Passing null as parameter will - /// unset the dib's previously set background color. - /// - /// - /// Handle to a FreeImage bitmap. - /// The new background color. - /// The first entry in the array is used. - /// Returns true on success, false on failure. - /// - /// - /// // create a RGBQUAD color - /// RGBQUAD color = new RGBQUAD(Color.Green); - /// - /// // set the dib's background color (using the other version of the function) - /// FreeImage.SetBackgroundColor(dib, ref color); - /// - /// // remove it again (this only works due to the array parameter RGBQUAD[]) - /// FreeImage.SetBackgroundColor(dib, null); - /// - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetBackgroundColor")] - public static unsafe extern bool SetBackgroundColor(FIBITMAP dib, RGBQUAD[] bkcolor); - - /// - /// Sets the index of the palette entry to be used as transparent color - /// for the image specified. Does nothing on high color images. - /// - /// Handle to a FreeImage bitmap. - /// The index of the palette entry to be set as transparent color. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparentIndex")] - public static extern void SetTransparentIndex(FIBITMAP dib, int index); - - /// - /// Returns the palette entry used as transparent color for the image specified. - /// Works for palletised images only and returns -1 for high color - /// images or if the image has no color set to be transparent. - /// - /// Handle to a FreeImage bitmap. - /// the index of the palette entry used as transparent color for - /// the image specified or -1 if there is no transparent color found - /// (e.g. the image is a high color image). - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparentIndex")] - public static extern int GetTransparentIndex(FIBITMAP dib); - - #endregion - - #region ICC profile functions - - /// - /// Retrieves the data of the bitmap. - /// This function can also be called safely, when the original format does not support profiles. - /// - /// Handle to a FreeImage bitmap. - /// The data of the bitmap. - public static FIICCPROFILE GetICCProfileEx(FIBITMAP dib) { unsafe { return *(FIICCPROFILE*)FreeImage.GetICCProfile(dib); } } - - /// - /// Retrieves a pointer to the data of the bitmap. - /// This function can also be called safely, when the original format does not support profiles. - /// - /// Handle to a FreeImage bitmap. - /// Pointer to the data of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetICCProfile")] - public static extern IntPtr GetICCProfile(FIBITMAP dib); - - /// - /// Creates a new block from ICC profile data previously read from a file - /// or built by a color management system. The profile data is attached to the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Pointer to the new data. - /// Size of the data. - /// Pointer to the created structure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CreateICCProfile")] - public static extern IntPtr CreateICCProfile(FIBITMAP dib, byte[] data, int size); - - /// - /// This function destroys an previously created by . - /// After this call the bitmap will contain no profile information. - /// This function should be called to ensure that a stored bitmap will not contain any profile information. - /// - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DestroyICCProfile")] - public static extern void DestroyICCProfile(FIBITMAP dib); - - #endregion - - #region Conversion functions - - /// - /// Converts a bitmap to 4 bits. - /// If the bitmap was a high-color bitmap (16, 24 or 32-bit) or if it was a - /// monochrome or greyscale bitmap (1 or 8-bit), the end result will be a - /// greyscale bitmap, otherwise (1-bit palletised bitmaps) it will be a palletised bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo4Bits")] - public static extern FIBITMAP ConvertTo4Bits(FIBITMAP dib); - - /// - /// Converts a bitmap to 8 bits. If the bitmap was a high-color bitmap (16, 24 or 32-bit) - /// or if it was a monochrome or greyscale bitmap (1 or 4-bit), the end result will be a - /// greyscale bitmap, otherwise (1 or 4-bit palletised bitmaps) it will be a palletised bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo8Bits")] - public static extern FIBITMAP ConvertTo8Bits(FIBITMAP dib); - - /// - /// Converts a bitmap to a 8-bit greyscale image with a linear ramp. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToGreyscale")] - public static extern FIBITMAP ConvertToGreyscale(FIBITMAP dib); - - /// - /// Converts a bitmap to 16 bits, where each pixel has a color pattern of - /// 5 bits red, 5 bits green and 5 bits blue. One bit in each pixel is unused. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo16Bits555")] - public static extern FIBITMAP ConvertTo16Bits555(FIBITMAP dib); - - /// - /// Converts a bitmap to 16 bits, where each pixel has a color pattern of - /// 5 bits red, 6 bits green and 5 bits blue. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo16Bits565")] - public static extern FIBITMAP ConvertTo16Bits565(FIBITMAP dib); - - /// - /// Converts a bitmap to 24 bits. A clone of the input bitmap is returned for 24-bit bitmaps. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo24Bits")] - public static extern FIBITMAP ConvertTo24Bits(FIBITMAP dib); - - /// - /// Converts a bitmap to 32 bits. A clone of the input bitmap is returned for 32-bit bitmaps. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo32Bits")] - public static extern FIBITMAP ConvertTo32Bits(FIBITMAP dib); - - /// - /// Quantizes a high-color 24-bit bitmap to an 8-bit palette color bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Specifies the color reduction algorithm to be used. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ColorQuantize")] - public static extern FIBITMAP ColorQuantize(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize); - - /// - /// ColorQuantizeEx is an extension to the method that - /// provides additional options used to quantize a 24-bit image to any - /// number of colors (up to 256), as well as quantize a 24-bit image using a - /// partial or full provided palette. - /// - /// Handle to a FreeImage bitmap. - /// Specifies the color reduction algorithm to be used. - /// Size of the desired output palette. - /// Size of the provided palette of ReservePalette. - /// The provided palette. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ColorQuantizeEx")] - public static extern FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, int ReserveSize, RGBQUAD[] ReservePalette); - - /// - /// Converts a bitmap to 1-bit monochrome bitmap using a threshold T between [0..255]. - /// The function first converts the bitmap to a 8-bit greyscale bitmap. - /// Then, any brightness level that is less than T is set to zero, otherwise to 1. - /// For 1-bit input bitmaps, the function clones the input bitmap and builds a monochrome palette. - /// - /// Handle to a FreeImage bitmap. - /// The threshold. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Threshold")] - public static extern FIBITMAP Threshold(FIBITMAP dib, byte t); - - /// - /// Converts a bitmap to 1-bit monochrome bitmap using a dithering algorithm. - /// For 1-bit input bitmaps, the function clones the input bitmap and builds a monochrome palette. - /// - /// Handle to a FreeImage bitmap. - /// The dithering algorithm to use. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Dither")] - public static extern FIBITMAP Dither(FIBITMAP dib, FREE_IMAGE_DITHER algorithm); - - /// - /// Converts a raw bitmap to a FreeImage bitmap. - /// - /// Pointer to the memory block containing the raw bitmap. - /// The width in pixels of the raw bitmap. - /// The height in pixels of the raw bitmap. - /// Defines the total width of a scanline in the raw bitmap, - /// including padding bytes. - /// The bit depth (bits per pixel) of the raw bitmap. - /// The bit mask describing the bits used to store a single - /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// If true, the raw bitmap is stored in top-down order (top-left pixel first) - /// and in bottom-up order (bottom-left pixel first) otherwise. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertFromRawBits")] - public static extern FIBITMAP ConvertFromRawBits(IntPtr bits, int width, int height, int pitch, - uint bpp, uint red_mask, uint green_mask, uint blue_mask, bool topdown); - - /// - /// Converts a raw bitmap to a FreeImage bitmap. - /// - /// Array of bytes containing the raw bitmap. - /// The width in pixels of the raw bitmap. - /// The height in pixels of the raw bitmap. - /// Defines the total width of a scanline in the raw bitmap, - /// including padding bytes. - /// The bit depth (bits per pixel) of the raw bitmap. - /// The bit mask describing the bits used to store a single - /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// If true, the raw bitmap is stored in top-down order (top-left pixel first) - /// and in bottom-up order (bottom-left pixel first) otherwise. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertFromRawBits")] - public static extern FIBITMAP ConvertFromRawBits(byte[] bits, int width, int height, int pitch, - uint bpp, uint red_mask, uint green_mask, uint blue_mask, bool topdown); - - /// - /// Converts a FreeImage bitmap to a raw bitmap, that is a raw piece of memory. - /// - /// Pointer to the memory block receiving the raw bitmap. - /// Handle to a FreeImage bitmap. - /// The desired total width in bytes of a scanline in the raw bitmap, - /// including any padding bytes. - /// The desired bit depth (bits per pixel) of the raw bitmap. - /// The desired bit mask describing the bits used to store a single - /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The desired bit mask describing the bits used to store a single - /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The desired bit mask describing the bits used to store a single - /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// If true, the raw bitmap will be stored in top-down order (top-left pixel first) - /// and in bottom-up order (bottom-left pixel first) otherwise. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRawBits")] - public static extern void ConvertToRawBits(IntPtr bits, FIBITMAP dib, int pitch, uint bpp, - uint red_mask, uint green_mask, uint blue_mask, bool topdown); - - /// - /// Converts a FreeImage bitmap to a raw bitmap, that is a raw piece of memory. - /// - /// Array of bytes receiving the raw bitmap. - /// Handle to a FreeImage bitmap. - /// The desired total width in bytes of a scanline in the raw bitmap, - /// including any padding bytes. - /// The desired bit depth (bits per pixel) of the raw bitmap. - /// The desired bit mask describing the bits used to store a single - /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The desired bit mask describing the bits used to store a single - /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The desired bit mask describing the bits used to store a single - /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// If true, the raw bitmap will be stored in top-down order (top-left pixel first) - /// and in bottom-up order (bottom-left pixel first) otherwise. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRawBits")] - public static extern void ConvertToRawBits(byte[] bits, FIBITMAP dib, int pitch, uint bpp, - uint red_mask, uint green_mask, uint blue_mask, bool topdown); - - /// - /// Converts a 24- or 32-bit RGB(A) standard image or a 48-bit RGB image to a FIT_RGBF type image. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRGBF")] - public static extern FIBITMAP ConvertToRGBF(FIBITMAP dib); - - /// - /// Converts a non standard image whose color type is FIC_MINISBLACK - /// to a standard 8-bit greyscale image. - /// - /// Handle to a FreeImage bitmap. - /// When true the conversion is done by scaling linearly - /// each pixel value from [min, max] to an integer value between [0..255], - /// where min and max are the minimum and maximum pixel values in the image. - /// When false the conversion is done by rounding each pixel value to an integer between [0..255]. - /// - /// Rounding is done using the following formula: - /// - /// dst_pixel = (BYTE) MIN(255, MAX(0, q)) where int q = int(src_pixel + 0.5); - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToStandardType")] - public static extern FIBITMAP ConvertToStandardType(FIBITMAP src, bool scale_linear); - - /// - /// Converts an image of any type to type dst_type. - /// - /// Handle to a FreeImage bitmap. - /// Destination type. - /// True to scale linear, else false. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToType")] - public static extern FIBITMAP ConvertToType(FIBITMAP src, FREE_IMAGE_TYPE dst_type, bool scale_linear); - - #endregion - - #region Tone mapping operators - - /// - /// Converts a High Dynamic Range image (48-bit RGB or 96-bit RGBF) to a 24-bit RGB image, suitable for display. - /// - /// Handle to a FreeImage bitmap. - /// The tone mapping operator to be used. - /// Parmeter depending on the used algorithm - /// Parmeter depending on the used algorithm - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ToneMapping")] - public static extern FIBITMAP ToneMapping(FIBITMAP dib, FREE_IMAGE_TMO tmo, double first_param, double second_param); - - /// - /// Converts a High Dynamic Range image to a 24-bit RGB image using a global - /// operator based on logarithmic compression of luminance values, imitating the human response to light. - /// - /// Handle to a FreeImage bitmap. - /// A gamma correction that is applied after the tone mapping. - /// A value of 1 means no correction. - /// Scale factor allowing to adjust the brightness of the output image. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoDrago03")] - public static extern FIBITMAP TmoDrago03(FIBITMAP src, double gamma, double exposure); - - /// - /// Converts a High Dynamic Range image to a 24-bit RGB image using a global operator inspired - /// by photoreceptor physiology of the human visual system. - /// - /// Handle to a FreeImage bitmap. - /// Controls the overall image intensity in the range [-8, 8]. - /// Controls the overall image contrast in the range [0.3, 1.0[. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoReinhard05")] - public static extern FIBITMAP TmoReinhard05(FIBITMAP src, double intensity, double contrast); - - /// - /// Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and convert to 24-bit RGB. - /// - /// Handle to a FreeImage bitmap. - /// Color saturation (s parameter in the paper) in [0.4..0.6] - /// Atenuation factor (beta parameter in the paper) in [0.8..0.9] - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoFattal02")] - public static extern FIBITMAP TmoFattal02(FIBITMAP src, double color_saturation, double attenuation); - - #endregion - - #region Compression functions - - /// - /// Compresses a source buffer into a target buffer, using the ZLib library. - /// - /// Pointer to the target buffer. - /// Size of the target buffer. - /// Must be at least 0.1% larger than source_size plus 12 bytes. - /// Pointer to the source buffer. - /// Size of the source buffer. - /// The actual size of the compressed buffer, or 0 if an error occurred. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibCompress")] - public static extern uint ZLibCompress(byte[] target, uint target_size, byte[] source, uint source_size); - - /// - /// Decompresses a source buffer into a target buffer, using the ZLib library. - /// - /// Pointer to the target buffer. - /// Size of the target buffer. - /// Must have been saved outlide of zlib. - /// Pointer to the source buffer. - /// Size of the source buffer. - /// The actual size of the uncompressed buffer, or 0 if an error occurred. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibUncompress")] - public static extern uint ZLibUncompress(byte[] target, uint target_size, byte[] source, uint source_size); - - /// - /// Compresses a source buffer into a target buffer, using the ZLib library. - /// - /// Pointer to the target buffer. - /// Size of the target buffer. - /// Must be at least 0.1% larger than source_size plus 24 bytes. - /// Pointer to the source buffer. - /// Size of the source buffer. - /// The actual size of the compressed buffer, or 0 if an error occurred. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibGZip")] - public static extern uint ZLibGZip(byte[] target, uint target_size, byte[] source, uint source_size); - - /// - /// Decompresses a source buffer into a target buffer, using the ZLib library. - /// - /// Pointer to the target buffer. - /// Size of the target buffer. - /// Must have been saved outlide of zlib. - /// Pointer to the source buffer. - /// Size of the source buffer. - /// The actual size of the uncompressed buffer, or 0 if an error occurred. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibGUnzip")] - public static extern uint ZLibGUnzip(byte[] target, uint target_size, byte[] source, uint source_size); - - /// - /// Generates a CRC32 checksum. - /// - /// The CRC32 checksum to begin with. - /// Pointer to the source buffer. - /// If the value is 0, the function returns the required initial value for the crc. - /// Size of the source buffer. - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibCRC32")] - public static extern uint ZLibCRC32(uint crc, byte[] source, uint source_size); - - #endregion - - #region Tag creation and destruction - - /// - /// Allocates a new object. - /// This object must be destroyed with a call to - /// when no longer in use. - /// - /// The new . - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CreateTag")] - public static extern FITAG CreateTag(); - - /// - /// Delete a previously allocated object. - /// - /// The to destroy. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeleteTag")] - public static extern void DeleteTag(FITAG tag); - - /// - /// Creates and returns a copy of a object. - /// - /// The to clone. - /// The new . - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloneTag")] - public static extern FITAG CloneTag(FITAG tag); - - #endregion - - #region Tag accessors - - /// - /// Returns the tag field name (unique inside a metadata model). - /// - /// The tag field. - /// The field name. - public static unsafe string GetTagKey(FITAG tag) { return PtrToStr(GetTagKey_(tag)); } - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetTagKey")] - private static unsafe extern byte* GetTagKey_(FITAG tag); - - /// - /// Returns the tag description. - /// - /// The tag field. - /// The description or NULL if unavailable. - public static unsafe string GetTagDescription(FITAG tag) { return PtrToStr(GetTagDescription_(tag)); } - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetTagDescription")] - private static unsafe extern byte* GetTagDescription_(FITAG tag); - - /// - /// Returns the tag ID. - /// - /// The tag field. - /// The ID or 0 if unavailable. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagID")] - public static extern ushort GetTagID(FITAG tag); - - /// - /// Returns the tag data type. - /// - /// The tag field. - /// The tag type. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagType")] - public static extern FREE_IMAGE_MDTYPE GetTagType(FITAG tag); - - /// - /// Returns the number of components in the tag (in tag type units). - /// - /// The tag field. - /// The number of components. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagCount")] - public static extern uint GetTagCount(FITAG tag); - - /// - /// Returns the length of the tag value in bytes. - /// - /// The tag field. - /// The length of the tag value. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagLength")] - public static extern uint GetTagLength(FITAG tag); - - /// - /// Returns the tag value. - /// It is up to the programmer to interpret the returned pointer correctly, - /// according to the results of GetTagType and GetTagCount. - /// - /// The tag field. - /// Pointer to the value. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagValue")] - public static extern IntPtr GetTagValue(FITAG tag); - - /// - /// Sets the tag field name. - /// - /// The tag field. - /// The new name. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetTagKey")] - public static extern bool SetTagKey(FITAG tag, string key); - - /// - /// Sets the tag description. - /// - /// The tag field. - /// The new description. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetTagDescription")] - public static extern bool SetTagDescription(FITAG tag, string description); - - /// - /// Sets the tag ID. - /// - /// The tag field. - /// The new ID. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagID")] - public static extern bool SetTagID(FITAG tag, ushort id); - - /// - /// Sets the tag data type. - /// - /// The tag field. - /// The new type. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagType")] - public static extern bool SetTagType(FITAG tag, FREE_IMAGE_MDTYPE type); - - /// - /// Sets the number of data in the tag. - /// - /// The tag field. - /// New number of data. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagCount")] - public static extern bool SetTagCount(FITAG tag, uint count); - - /// - /// Sets the length of the tag value in bytes. - /// - /// The tag field. - /// The new length. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagLength")] - public static extern bool SetTagLength(FITAG tag, uint length); - - /// - /// Sets the tag value. - /// - /// The tag field. - /// Pointer to the new value. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagValue")] - public static extern bool SetTagValue(FITAG tag, byte[] value); - - #endregion - - #region Metadata iterator - - /// - /// Provides information about the first instance of a tag that matches the metadata model. - /// - /// The model to match. - /// Handle to a FreeImage bitmap. - /// Tag that matches the metadata model. - /// Unique search handle that can be used to call FindNextMetadata or FindCloseMetadata. - /// Null if the metadata model does not exist. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindFirstMetadata")] - public static extern FIMETADATA FindFirstMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, out FITAG tag); - - /// - /// Find the next tag, if any, that matches the metadata model argument in a previous call - /// to FindFirstMetadata, and then alters the tag object contents accordingly. - /// - /// Unique search handle provided by FindFirstMetadata. - /// Tag that matches the metadata model. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindNextMetadata")] - public static extern bool FindNextMetadata(FIMETADATA mdhandle, out FITAG tag); - - /// - /// Closes the specified metadata search handle and releases associated resources. - /// - /// The handle to close. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindCloseMetadata")] - private static extern void FindCloseMetadata_(FIMETADATA mdhandle); - - #endregion - - #region Metadata setter and getter - - /// - /// Retrieve a metadata attached to a dib. - /// - /// The metadata model to look for. - /// Handle to a FreeImage bitmap. - /// The metadata field name. - /// A FITAG structure returned by the function. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetMetadata")] - public static extern bool GetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, string key, out FITAG tag); - - /// - /// Attach a new FreeImage tag to a dib. - /// - /// The metadata model used to store the tag. - /// Handle to a FreeImage bitmap. - /// The tag field name. - /// The FreeImage tag to be attached. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetMetadata")] - public static extern bool SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, string key, FITAG tag); - - #endregion - - #region Metadata helper functions - - /// - /// Returns the number of tags contained in the model metadata model attached to the input dib. - /// - /// The metadata model. - /// Handle to a FreeImage bitmap. - /// Number of tags contained in the metadata model. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetMetadataCount")] - public static extern uint GetMetadataCount(FREE_IMAGE_MDMODEL model, FIBITMAP dib); - - /// - /// Copies the metadata of FreeImage bitmap to another. - /// - /// The FreeImage bitmap to copy the metadata to. - /// The FreeImage bitmap to copy the metadata from. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloneMetadata")] - public static extern bool CloneMetadata(FIBITMAP dst, FIBITMAP src); - - /// - /// Converts a FreeImage tag structure to a string that represents the interpreted tag value. - /// The function is not thread safe. - /// - /// The metadata model. - /// The interpreted tag value. - /// Reserved. - /// The representing string. - public static unsafe string TagToString(FREE_IMAGE_MDMODEL model, FITAG tag, uint Make) { return PtrToStr(TagToString_(model, tag, Make)); } - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_TagToString")] - private static unsafe extern byte* TagToString_(FREE_IMAGE_MDMODEL model, FITAG tag, uint Make); - - #endregion - - #region Rotation and flipping - - /// - /// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. - /// 1-bit images rotation is limited to integer multiple of 90°. - /// null is returned for other values. - /// - /// Handle to a FreeImage bitmap. - /// The angle of rotation. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_RotateClassic")] - [Obsolete("RotateClassic is deprecated (use Rotate instead).")] - public static extern FIBITMAP RotateClassic(FIBITMAP dib, double angle); - - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Rotate")] - internal static extern FIBITMAP Rotate(FIBITMAP dib, double angle, IntPtr backgroundColor); - - /// - /// This function performs a rotation and / or translation of an 8-bit greyscale, - /// 24- or 32-bit image, using a 3rd order (cubic) B-Spline. - /// - /// Handle to a FreeImage bitmap. - /// The angle of rotation. - /// Horizontal image translation. - /// Vertical image translation. - /// Rotation center x-coordinate. - /// Rotation center y-coordinate. - /// When true the irrelevant part of the image is set to a black color, - /// otherwise, a mirroring technique is used to fill irrelevant pixels. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_RotateEx")] - public static extern FIBITMAP RotateEx(FIBITMAP dib, double angle, - double x_shift, double y_shift, double x_origin, double y_origin, bool use_mask); - - /// - /// Flip the input dib horizontally along the vertical axis. - /// - /// Handle to a FreeImage bitmap. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FlipHorizontal")] - public static extern bool FlipHorizontal(FIBITMAP dib); - - /// - /// Flip the input dib vertically along the horizontal axis. - /// - /// Handle to a FreeImage bitmap. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FlipVertical")] - public static extern bool FlipVertical(FIBITMAP dib); - - /// - /// Performs a lossless rotation or flipping on a JPEG file. - /// - /// Source file. - /// Destination file; can be the source file; will be overwritten. - /// The operation to apply. - /// To avoid lossy transformation, you can set the perfect parameter to true. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_JPEGTransformU")] - public static extern bool JPEGTransform(string src_file, string dst_file, - FREE_IMAGE_JPEG_OPERATION operation, bool perfect); - - #endregion - - #region Upsampling / downsampling - - /// - /// Performs resampling (or scaling, zooming) of a greyscale or RGB(A) image - /// to the desired destination width and height. - /// - /// Handle to a FreeImage bitmap. - /// Destination width. - /// Destination height. - /// The filter to apply. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Rescale")] - public static extern FIBITMAP Rescale(FIBITMAP dib, int dst_width, int dst_height, FREE_IMAGE_FILTER filter); - - /// - /// Creates a thumbnail from a greyscale or RGB(A) image, keeping aspect ratio. - /// - /// Handle to a FreeImage bitmap. - /// Thumbnail square size. - /// When true HDR images are transperantly converted to standard images. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MakeThumbnail")] - public static extern FIBITMAP MakeThumbnail(FIBITMAP dib, int max_pixel_size, bool convert); - - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_EnlargeCanvas")] - internal static extern FIBITMAP EnlargeCanvas(FIBITMAP dib, - int left, int top, int right, int bottom, IntPtr color, FREE_IMAGE_COLOR_OPTIONS options); - - #endregion - - #region Color manipulation - - /// - /// Perfoms an histogram transformation on a 8-, 24- or 32-bit image. - /// - /// Handle to a FreeImage bitmap. - /// The lookup table. - /// It's size is assumed to be 256 in length. - /// The color channel to be transformed. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustCurve")] - public static extern bool AdjustCurve(FIBITMAP dib, byte[] lookUpTable, FREE_IMAGE_COLOR_CHANNEL channel); - - /// - /// Performs gamma correction on a 8-, 24- or 32-bit image. - /// - /// Handle to a FreeImage bitmap. - /// The parameter represents the gamma value to use (gamma > 0). - /// A value of 1.0 leaves the image alone, less than one darkens it, and greater than one lightens it. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustGamma")] - public static extern bool AdjustGamma(FIBITMAP dib, double gamma); - - /// - /// Adjusts the brightness of a 8-, 24- or 32-bit image by a certain amount. - /// - /// Handle to a FreeImage bitmap. - /// A value 0 means no change, - /// less than 0 will make the image darker and greater than 0 will make the image brighter. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustBrightness")] - public static extern bool AdjustBrightness(FIBITMAP dib, double percentage); - - /// - /// Adjusts the contrast of a 8-, 24- or 32-bit image by a certain amount. - /// - /// Handle to a FreeImage bitmap. - /// A value 0 means no change, - /// less than 0 will decrease the contrast and greater than 0 will increase the contrast of the image. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustContrast")] - public static extern bool AdjustContrast(FIBITMAP dib, double percentage); - - /// - /// Inverts each pixel data. - /// - /// Handle to a FreeImage bitmap. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Invert")] - public static extern bool Invert(FIBITMAP dib); - - /// - /// Computes the image histogram. - /// - /// Handle to a FreeImage bitmap. - /// Array of integers with a size of 256. - /// Channel to compute from. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetHistogram")] - public static extern bool GetHistogram(FIBITMAP dib, int[] histo, FREE_IMAGE_COLOR_CHANNEL channel); - - #endregion - - #region Channel processing - - /// - /// Retrieves the red, green, blue or alpha channel of a 24- or 32-bit image. - /// - /// Handle to a FreeImage bitmap. - /// The color channel to extract. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetChannel")] - public static extern FIBITMAP GetChannel(FIBITMAP dib, FREE_IMAGE_COLOR_CHANNEL channel); - - /// - /// Insert a 8-bit dib into a 24- or 32-bit image. - /// Both images must have to same width and height. - /// - /// Handle to a FreeImage bitmap. - /// Handle to the bitmap to insert. - /// The color channel to replace. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetChannel")] - public static extern bool SetChannel(FIBITMAP dib, FIBITMAP dib8, FREE_IMAGE_COLOR_CHANNEL channel); - - /// - /// Retrieves the real part, imaginary part, magnitude or phase of a complex image. - /// - /// Handle to a FreeImage bitmap. - /// The color channel to extract. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetComplexChannel")] - public static extern FIBITMAP GetComplexChannel(FIBITMAP src, FREE_IMAGE_COLOR_CHANNEL channel); - - /// - /// Set the real or imaginary part of a complex image. - /// Both images must have to same width and height. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - /// The color channel to replace. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetComplexChannel")] - public static extern bool SetComplexChannel(FIBITMAP dst, FIBITMAP src, FREE_IMAGE_COLOR_CHANNEL channel); - - #endregion - - #region Copy / Paste / Composite routines - - /// - /// Copy a sub part of the current dib image. - /// - /// Handle to a FreeImage bitmap. - /// Specifies the left position of the cropped rectangle. - /// Specifies the top position of the cropped rectangle. - /// Specifies the right position of the cropped rectangle. - /// Specifies the bottom position of the cropped rectangle. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Copy")] - public static extern FIBITMAP Copy(FIBITMAP dib, int left, int top, int right, int bottom); - - /// - /// Alpha blend or combine a sub part image with the current dib image. - /// The bit depth of the dst bitmap must be greater than or equal to the bit depth of the src. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - /// Specifies the left position of the sub image. - /// Specifies the top position of the sub image. - /// alpha blend factor. - /// The source and destination images are alpha blended if alpha=0..255. - /// If alpha > 255, then the source image is combined to the destination image. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Paste")] - public static extern bool Paste(FIBITMAP dst, FIBITMAP src, int left, int top, int alpha); - - /// - /// This function composite a transparent foreground image against a single background color or - /// against a background image. - /// - /// Handle to a FreeImage bitmap. - /// When true the background of fg is used if it contains one. - /// The application background is used if useFileBkg is false. - /// Image used as background when useFileBkg is false or fg has no background - /// and appBkColor is null. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Composite")] - public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg, ref RGBQUAD appBkColor, FIBITMAP bg); - - /// - /// This function composite a transparent foreground image against a single background color or - /// against a background image. - /// - /// Handle to a FreeImage bitmap. - /// When true the background of fg is used if it contains one. - /// The application background is used if useFileBkg is false - /// and 'appBkColor' is not null. - /// Image used as background when useFileBkg is false or fg has no background - /// and appBkColor is null. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Composite")] - public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg, RGBQUAD[] appBkColor, FIBITMAP bg); - - /// - /// Performs a lossless crop on a JPEG file. - /// - /// Source filename. - /// Destination filename. - /// Specifies the left position of the cropped rectangle. - /// Specifies the top position of the cropped rectangle. - /// Specifies the right position of the cropped rectangle. - /// Specifies the bottom position of the cropped rectangle. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_JPEGCropU")] - public static extern bool JPEGCrop(string src_file, string dst_file, int left, int top, int right, int bottom); - - /// - /// Applies the alpha value of each pixel to its color components. - /// The aplha value stays unchanged. - /// Only works with 32-bits color depth. - /// - /// Handle to a FreeImage bitmap. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_PreMultiplyWithAlpha")] - public static extern bool PreMultiplyWithAlpha(FIBITMAP dib); - - #endregion - - #region Miscellaneous algorithms - - /// - /// Solves a Poisson equation, remap result pixels to [0..1] and returns the solution. - /// - /// Handle to a FreeImage bitmap. - /// Number of cycles in the multigrid algorithm (usually 2 or 3) - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MultigridPoissonSolver")] - public static extern FIBITMAP MultigridPoissonSolver(FIBITMAP Laplacian, int ncycle); - - #endregion - - #region Colors - - /// - /// Creates a lookup table to be used with which may adjusts brightness and - /// contrast, correct gamma and invert the image with a single call to . - /// - /// Output lookup table to be used with . - /// The size of 'lookUpTable' is assumed to be 256. - /// Percentage brightness value where -100 <= brightness <= 100. - /// A value of 0 means no change, less than 0 will make the image darker and greater - /// than 0 will make the image brighter. - /// Percentage contrast value where -100 <= contrast <= 100. - /// A value of 0 means no change, less than 0 will decrease the contrast - /// and greater than 0 will increase the contrast of the image. - /// Gamma value to be used for gamma correction. - /// A value of 1.0 leaves the image alone, less than one darkens it, - /// and greater than one lightens it. - /// If set to true, the image will be inverted. - /// The number of adjustments applied to the resulting lookup table - /// compared to a blind lookup table. - /// - /// This function creates a lookup table to be used with which may adjust - /// brightness and contrast, correct gamma and invert the image with a single call to - /// . If more than one of these image display properties need to be adjusted, - /// using a combined lookup table should be preferred over calling each adjustment function - /// separately. That's particularly true for huge images or if performance is an issue. Then, - /// the expensive process of iterating over all pixels of an image is performed only once and - /// not up to four times. - /// - /// Furthermore, the lookup table created does not depend on the order, in which each single - /// adjustment operation is performed. Due to rounding and byte casting issues, it actually - /// matters in which order individual adjustment operations are performed. Both of the following - /// snippets most likely produce different results: - /// - /// - /// // snippet 1: contrast, brightness - /// AdjustContrast(dib, 15.0); - /// AdjustBrightness(dib, 50.0); - /// - /// - /// - /// // snippet 2: brightness, contrast - /// AdjustBrightness(dib, 50.0); - /// AdjustContrast(dib, 15.0); - /// - /// - /// Better and even faster would be snippet 3: - /// - /// - /// // snippet 3: - /// byte[] lut = new byte[256]; - /// GetAdjustColorsLookupTable(lut, 50.0, 15.0, 1.0, false); - /// AdjustCurve(dib, lut, FREE_IMAGE_COLOR_CHANNEL.FICC_RGB); - /// - /// - /// This function is also used internally by , which does not return the - /// lookup table, but uses it to call on the passed image. - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetAdjustColorsLookupTable")] - public static extern int GetAdjustColorsLookupTable(byte[] lookUpTable, double brightness, double contrast, double gamma, bool invert); - - /// - /// Adjusts an image's brightness, contrast and gamma as well as it may - /// optionally invert the image within a single operation. - /// - /// Handle to a FreeImage bitmap. - /// Percentage brightness value where -100 <= brightness <= 100. - /// A value of 0 means no change, less than 0 will make the image darker and greater - /// than 0 will make the image brighter. - /// Percentage contrast value where -100 <= contrast <= 100. - /// A value of 0 means no change, less than 0 will decrease the contrast - /// and greater than 0 will increase the contrast of the image. - /// Gamma value to be used for gamma correction. - /// A value of 1.0 leaves the image alone, less than one darkens it, - /// and greater than one lightens it. - /// This parameter must not be zero or smaller than zero. - /// If so, it will be ignored and no gamma correction will be performed on the image. - /// If set to true, the image will be inverted. - /// Returns true on success, false on failure. - /// - /// This function adjusts an image's brightness, contrast and gamma as well as it - /// may optionally invert the image within a single operation. If more than one of - /// these image display properties need to be adjusted, using this function should - /// be preferred over calling each adjustment function separately. That's particularly - /// true for huge images or if performance is an issue. - /// - /// This function relies on , - /// which creates a single lookup table, that combines all adjustment operations requested. - /// - /// Furthermore, the lookup table created by does - /// not depend on the order, in which each single adjustment operation is performed. - /// Due to rounding and byte casting issues, it actually matters in which order individual - /// adjustment operations are performed. Both of the following snippets most likely produce - /// different results: - /// - /// - /// // snippet 1: contrast, brightness - /// AdjustContrast(dib, 15.0); - /// AdjustBrightness(dib, 50.0); - /// - /// - /// - /// // snippet 2: brightness, contrast - /// AdjustBrightness(dib, 50.0); - /// AdjustContrast(dib, 15.0); - /// - /// - /// Better and even faster would be snippet 3: - /// - /// - /// // snippet 3: - /// AdjustColors(dib, 50.0, 15.0, 1.0, false); - /// - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustColors")] - public static extern bool AdjustColors(FIBITMAP dib, double brightness, double contrast, double gamma, bool invert); - - /// - /// Applies color mapping for one or several colors on a 1-, 4- or 8-bit - /// palletized or a 16-, 24- or 32-bit high color image. - /// - /// Handle to a FreeImage bitmap. - /// Array of colors to be used as the mapping source. - /// Array of colors to be used as the mapping destination. - /// The number of colors to be mapped. This is the size of both - /// srccolors and dstcolors. - /// If true, 32-bit images and colors are treated as 24-bit. - /// If true, source and destination colors are swapped, that is, - /// each destination color is also mapped to the corresponding source color. - /// The total number of pixels changed. - /// - /// This function maps up to colors specified in - /// to these specified in . - /// Thereby, color srccolors[N], if found in the image, will be replaced by color - /// dstcolors[N]. If is true, additionally all colors - /// specified in are also mapped to these specified - /// in . For high color images, the actual image data will be - /// modified whereas, for palletized images only the palette will be changed. - /// - /// The function returns the number of pixels changed or zero, if no pixels were changed. - /// - /// Both arrays and are assumed - /// not to hold less than colors. - /// - /// For 16-bit images, all colors specified are transparently converted to their - /// proper 16-bit representation (either in RGB555 or RGB565 format, which is determined - /// by the image's red- green- and blue-mask). - /// - /// Note, that this behaviour is different from what does, - /// which modifies the actual image data on palletized images. - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ApplyColorMapping")] - public static extern uint ApplyColorMapping(FIBITMAP dib, RGBQUAD[] srccolors, RGBQUAD[] dstcolors, uint count, bool ignore_alpha, bool swap); - - /// - /// Swaps two specified colors on a 1-, 4- or 8-bit palletized - /// or a 16-, 24- or 32-bit high color image. - /// - /// Handle to a FreeImage bitmap. - /// One of the two colors to be swapped. - /// The other of the two colors to be swapped. - /// If true, 32-bit images and colors are treated as 24-bit. - /// The total number of pixels changed. - /// - /// This function swaps the two specified colors and - /// on a palletized or high color image. - /// For high color images, the actual image data will be modified whereas, for palletized - /// images only the palette will be changed. - /// - /// Note, that this behaviour is different from what does, - /// which modifies the actual image data on palletized images. - /// - /// This is just a thin wrapper for and resolves to: - /// - /// - /// return ApplyColorMapping(dib, color_a, color_b, 1, ignore_alpha, true); - /// - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SwapColors")] - public static extern uint SwapColors(FIBITMAP dib, ref RGBQUAD color_a, ref RGBQUAD color_b, bool ignore_alpha); - - /// - /// Applies palette index mapping for one or several indices - /// on a 1-, 4- or 8-bit palletized image. - /// - /// Handle to a FreeImage bitmap. - /// Array of palette indices to be used as the mapping source. - /// Array of palette indices to be used as the mapping destination. - /// The number of palette indices to be mapped. This is the size of both - /// srcindices and dstindices - /// If true, source and destination palette indices are swapped, that is, - /// each destination index is also mapped to the corresponding source index. - /// The total number of pixels changed. - /// - /// This function maps up to palette indices specified in - /// to these specified in . - /// Thereby, index srcindices[N], if present in the image, will be replaced by index - /// dstindices[N]. If is true, additionally all indices - /// specified in are also mapped to these specified in - /// . - /// - /// The function returns the number of pixels changed or zero, if no pixels were changed. - /// Both arrays and are assumed not to - /// hold less than indices. - /// - /// Note, that this behaviour is different from what does, which - /// modifies the actual image data on palletized images. - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ApplyPaletteIndexMapping")] - public static extern uint ApplyPaletteIndexMapping(FIBITMAP dib, byte[] srcindices, byte[] dstindices, uint count, bool swap); - - /// - /// Swaps two specified palette indices on a 1-, 4- or 8-bit palletized image. - /// - /// Handle to a FreeImage bitmap. - /// One of the two palette indices to be swapped. - /// The other of the two palette indices to be swapped. - /// The total number of pixels changed. - /// - /// This function swaps the two specified palette indices index_a and - /// index_b on a palletized image. Therefore, not the palette, but the - /// actual image data will be modified. - /// - /// Note, that this behaviour is different from what does on palletized images, - /// which only swaps the colors in the palette. - /// - /// This is just a thin wrapper for and resolves to: - /// - /// - /// return ApplyPaletteIndexMapping(dib, index_a, index_b, 1, true); - /// - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SwapPaletteIndices")] - public static extern uint SwapPaletteIndices(FIBITMAP dib, ref byte index_a, ref byte index_b); - - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FillBackground")] - internal static extern bool FillBackground(FIBITMAP dib, IntPtr color, FREE_IMAGE_COLOR_OPTIONS options); - - #endregion - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.9 $ +// $Date: 2009/09/15 11:41:37 $ +// $Id: FreeImageStaticImports.cs,v 1.9 2009/09/15 11:41:37 cklein05 Exp $ +// ========================================================== + +using System; +using System.Runtime.InteropServices; +using FreeImageAPI.Plugins; +using FreeImageAPI.IO; + +namespace FreeImageAPI +{ + public static partial class FreeImage + { + #region Constants + + /// + /// Filename of the FreeImage library. + /// + private const string FreeImageLibrary = "FreeImage"; + + /// + /// Number of bytes to shift left within a 4 byte block. + /// + public const int FI_RGBA_RED = 2; + + /// + /// Number of bytes to shift left within a 4 byte block. + /// + public const int FI_RGBA_GREEN = 1; + + /// + /// Number of bytes to shift left within a 4 byte block. + /// + public const int FI_RGBA_BLUE = 0; + + /// + /// Number of bytes to shift left within a 4 byte block. + /// + public const int FI_RGBA_ALPHA = 3; + + /// + /// Mask indicating the position of the given color. + /// + public const uint FI_RGBA_RED_MASK = 0x00FF0000; + + /// + /// Mask indicating the position of the given color. + /// + public const uint FI_RGBA_GREEN_MASK = 0x0000FF00; + + /// + /// Mask indicating the position of the given color. + /// + public const uint FI_RGBA_BLUE_MASK = 0x000000FF; + + /// + /// Mask indicating the position of the given color. + /// + public const uint FI_RGBA_ALPHA_MASK = 0xFF000000; + + /// + /// Number of bits to shift left within a 32 bit block. + /// + public const int FI_RGBA_RED_SHIFT = 16; + + /// + /// Number of bits to shift left within a 32 bit block. + /// + public const int FI_RGBA_GREEN_SHIFT = 8; + + /// + /// Number of bits to shift left within a 32 bit block. + /// + public const int FI_RGBA_BLUE_SHIFT = 0; + + /// + /// Number of bits to shift left within a 32 bit block. + /// + public const int FI_RGBA_ALPHA_SHIFT = 24; + + /// + /// Mask indicating the position of color components of a 32 bit color. + /// + public const uint FI_RGBA_RGB_MASK = (FI_RGBA_RED_MASK | FI_RGBA_GREEN_MASK | FI_RGBA_BLUE_MASK); + + /// + /// Mask indicating the position of the given color. + /// + public const int FI16_555_RED_MASK = 0x7C00; + + /// + /// Mask indicating the position of the given color. + /// + public const int FI16_555_GREEN_MASK = 0x03E0; + + /// + /// Mask indicating the position of the given color. + /// + public const int FI16_555_BLUE_MASK = 0x001F; + + /// + /// Number of bits to shift left within a 16 bit block. + /// + public const int FI16_555_RED_SHIFT = 10; + + /// + /// Number of bits to shift left within a 16 bit block. + /// + public const int FI16_555_GREEN_SHIFT = 5; + + /// + /// Number of bits to shift left within a 16 bit block. + /// + public const int FI16_555_BLUE_SHIFT = 0; + + /// + /// Mask indicating the position of the given color. + /// + public const int FI16_565_RED_MASK = 0xF800; + + /// + /// Mask indicating the position of the given color. + /// + public const int FI16_565_GREEN_MASK = 0x07E0; + + /// + /// Mask indicating the position of the given color. + /// + public const int FI16_565_BLUE_MASK = 0x001F; + + /// + /// Number of bits to shift left within a 16 bit block. + /// + public const int FI16_565_RED_SHIFT = 11; + + /// + /// Number of bits to shift left within a 16 bit block. + /// + public const int FI16_565_GREEN_SHIFT = 5; + + /// + /// Number of bits to shift left within a 16 bit block. + /// + public const int FI16_565_BLUE_SHIFT = 0; + + #endregion + + #region General functions + + /// + /// Initialises the library. + /// + /// + /// When the is true, FreeImage won't make use of external plugins. + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Initialise")] + private static extern void Initialise(bool load_local_plugins_only); + + /// + /// Deinitialises the library. + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeInitialise")] + private static extern void DeInitialise(); + + /// + /// Returns a string containing the current version of the library. + /// + /// The current version of the library. + public static unsafe string GetVersion() { return PtrToStr(GetVersion_()); } + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetVersion")] + private static unsafe extern byte* GetVersion_(); + + /// + /// Returns a string containing a standard copyright message. + /// + /// A standard copyright message. + public static unsafe string GetCopyrightMessage() { return PtrToStr(GetCopyrightMessage_()); } + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetCopyrightMessage")] + private static unsafe extern byte* GetCopyrightMessage_(); + + /// + /// Calls the set error message function in FreeImage. + /// + /// Format of the bitmaps. + /// The error message. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_OutputMessageProc")] + public static extern void OutputMessageProc(FREE_IMAGE_FORMAT fif, string message); + + /// + /// You use the function FreeImage_SetOutputMessage to capture the log string + /// so that you can show it to the user of the program. + /// The callback is implemented in the event of this class. + /// + /// The function is private because FreeImage can only have a single + /// callback function. To use the callback use the + /// event of this class. + /// Handler to the callback function. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetOutputMessage")] + internal static extern void SetOutputMessage(OutputMessageFunction omf); + + #endregion + + #region Bitmap management functions + + /// + /// Creates a new bitmap in memory. + /// + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new Bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap + /// Red part of the color layout. + /// eg: 0xFF0000 + /// Green part of the color layout. + /// eg: 0x00FF00 + /// Blue part of the color layout. + /// eg: 0x0000FF + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Allocate")] + public static extern FIBITMAP Allocate(int width, int height, int bpp, + uint red_mask, uint green_mask, uint blue_mask); + + /// + /// Creates a new bitmap in memory. + /// + /// Type of the image. + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new Bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap + /// Red part of the color layout. + /// eg: 0xFF0000 + /// Green part of the color layout. + /// eg: 0x00FF00 + /// Blue part of the color layout. + /// eg: 0x0000FF + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateT")] + public static extern FIBITMAP AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp, + uint red_mask, uint green_mask, uint blue_mask); + + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateEx")] + internal static extern FIBITMAP AllocateEx(int width, int height, int bpp, + IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, + uint red_mask, uint green_mask, uint blue_mask); + + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateExT")] + internal static extern FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp, + IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, + uint red_mask, uint green_mask, uint blue_mask); + + /// + /// Makes an exact reproduction of an existing bitmap, including metadata and attached profile if any. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Clone")] + public static extern FIBITMAP Clone(FIBITMAP dib); + + /// + /// Deletes a previously loaded FIBITMAP from memory. + /// + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Unload")] + public static extern void Unload(FIBITMAP dib); + + /// + /// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP. + /// + /// Type of the bitmap. + /// Name of the file to decode. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")] + public static extern FIBITMAP Load(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags); + + /// + /// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP. + /// The filename supports UNICODE. + /// + /// Type of the bitmap. + /// Name of the file to decode. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")] + private static extern FIBITMAP LoadU(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags); + + /// + /// Loads a bitmap from an arbitrary source. + /// + /// Type of the bitmap. + /// A FreeImageIO structure with functionpointers to handle the source. + /// A handle to the source. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadFromHandle")] + public static extern FIBITMAP LoadFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io, fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags); + + /// + /// Saves a previosly loaded FIBITMAP to a file. + /// + /// Type of the bitmap. + /// Handle to a FreeImage bitmap. + /// Name of the file to save to. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_SaveU")] + public static extern bool Save(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags); + + /// + /// Saves a previosly loaded FIBITMAP to a file. + /// The filename supports UNICODE. + /// + /// Type of the bitmap. + /// Handle to a FreeImage bitmap. + /// Name of the file to save to. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_SaveU")] + private static extern bool SaveU(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags); + + /// + /// Saves a bitmap to an arbitrary source. + /// + /// Type of the bitmap. + /// Handle to a FreeImage bitmap. + /// A FreeImageIO structure with functionpointers to handle the source. + /// A handle to the source. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SaveToHandle")] + public static extern bool SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP dib, ref FreeImageIO io, fi_handle handle, + FREE_IMAGE_SAVE_FLAGS flags); + + #endregion + + #region Memory I/O streams + + /// + /// Open a memory stream. + /// + /// Pointer to the data in memory. + /// Length of the data in byte. + /// Handle to a memory stream. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMemory")] + public static extern FIMEMORY OpenMemory(IntPtr data, uint size_in_bytes); + + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMemory")] + internal static extern FIMEMORY OpenMemoryEx(byte[] data, uint size_in_bytes); + + /// + /// Close and free a memory stream. + /// + /// Handle to a memory stream. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloseMemory")] + public static extern void CloseMemory(FIMEMORY stream); + + /// + /// Decodes a bitmap from a stream, allocates memory for it and returns it as a FIBITMAP. + /// + /// Type of the bitmap. + /// Handle to a memory stream. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadFromMemory")] + public static extern FIBITMAP LoadFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags); + + /// + /// Saves a previosly loaded FIBITMAP to a stream. + /// + /// Type of the bitmap. + /// Handle to a FreeImage bitmap. + /// Handle to a memory stream. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SaveToMemory")] + public static extern bool SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP dib, FIMEMORY stream, FREE_IMAGE_SAVE_FLAGS flags); + + /// + /// Gets the current position of a memory handle. + /// + /// Handle to a memory stream. + /// The current file position if successful, -1 otherwise. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TellMemory")] + public static extern int TellMemory(FIMEMORY stream); + + /// + /// Moves the memory handle to a specified location. + /// + /// Handle to a memory stream. + /// Number of bytes from origin. + /// Initial position. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SeekMemory")] + public static extern bool SeekMemory(FIMEMORY stream, int offset, System.IO.SeekOrigin origin); + + /// + /// Provides a direct buffer access to a memory stream. + /// + /// The target memory stream. + /// Pointer to the data in memory. + /// Size of the data in bytes. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AcquireMemory")] + public static extern bool AcquireMemory(FIMEMORY stream, ref IntPtr data, ref uint size_in_bytes); + + /// + /// Reads data from a memory stream. + /// + /// The buffer to store the data in. + /// Size in bytes of the items. + /// Number of items to read. + /// The stream to read from. + /// The memory pointer associated with stream is increased by the number of bytes actually read. + /// The number of full items actually read. + /// May be less than count on error or stream-end. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ReadMemory")] + public static extern uint ReadMemory(byte[] buffer, uint size, uint count, FIMEMORY stream); + + /// + /// Writes data to a memory stream. + /// + /// The buffer to read the data from. + /// Size in bytes of the items. + /// Number of items to write. + /// The stream to write to. + /// The memory pointer associated with stream is increased by the number of bytes actually written. + /// The number of full items actually written. + /// May be less than count on error or stream-end. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_WriteMemory")] + public static extern uint WriteMemory(byte[] buffer, uint size, uint count, FIMEMORY stream); + + /// + /// Open a multi-page bitmap from a memory stream. + /// + /// Type of the bitmap. + /// The stream to decode. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage multi-paged bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadMultiBitmapFromMemory")] + public static extern FIMULTIBITMAP LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags); + + #endregion + + #region Plugin functions + + /// + /// Registers a new plugin to be used in FreeImage. + /// + /// Pointer to the function that initialises the plugin. + /// A string describing the format of the plugin. + /// A string describing the plugin. + /// A string witha comma sperated list of extensions. f.e: "pl,pl2,pl4" + /// A regular expression used to identify the bitmap. + /// The format idientifier assigned by FreeImage. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_RegisterLocalPlugin")] + public static extern FREE_IMAGE_FORMAT RegisterLocalPlugin(InitProc proc_address, + string format, string description, string extension, string regexpr); + + /// + /// Registers a new plugin to be used in FreeImage. The plugin is residing in a DLL. + /// The Init function must be called “Init” and must use the stdcall calling convention. + /// + /// Complete path to the dll file hosting the plugin. + /// A string describing the format of the plugin. + /// A string describing the plugin. + /// A string witha comma sperated list of extensions. f.e: "pl,pl2,pl4" + /// A regular expression used to identify the bitmap. + /// The format idientifier assigned by FreeImage. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_RegisterExternalPlugin")] + public static extern FREE_IMAGE_FORMAT RegisterExternalPlugin(string path, + string format, string description, string extension, string regexpr); + + /// + /// Retrieves the number of FREE_IMAGE_FORMAT identifiers being currently registered. + /// + /// The number of registered formats. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFCount")] + public static extern int GetFIFCount(); + + /// + /// Enables or disables a plugin. + /// + /// The plugin to enable or disable. + /// True: enable the plugin. false: disable the plugin. + /// The previous state of the plugin. + /// 1 - enabled. 0 - disables. -1 plugin does not exist. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPluginEnabled")] + public static extern int SetPluginEnabled(FREE_IMAGE_FORMAT fif, bool enable); + + /// + /// Retrieves the state of a plugin. + /// + /// The plugin to check. + /// 1 - enabled. 0 - disables. -1 plugin does not exist. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsPluginEnabled")] + public static extern int IsPluginEnabled(FREE_IMAGE_FORMAT fif); + + /// + /// Returns a identifier from the format string that was used to register the FIF. + /// + /// The string that was used to register the plugin. + /// A identifier from the format. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetFIFFromFormat")] + public static extern FREE_IMAGE_FORMAT GetFIFFromFormat(string format); + + /// + /// Returns a identifier from a MIME content type string + /// (MIME stands for Multipurpose Internet Mail Extension). + /// + /// A MIME content type. + /// A identifier from the MIME. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetFIFFromMime")] + public static extern FREE_IMAGE_FORMAT GetFIFFromMime(string mime); + + /// + /// Returns the string that was used to register a plugin from the system assigned . + /// + /// The assigned . + /// The string that was used to register the plugin. + public static unsafe string GetFormatFromFIF(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFormatFromFIF_(fif)); } + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFormatFromFIF")] + private static unsafe extern byte* GetFormatFromFIF_(FREE_IMAGE_FORMAT fif); + + /// + /// Returns a comma-delimited file extension list describing the bitmap formats the given plugin can read and/or write. + /// + /// The desired . + /// A comma-delimited file extension list. + public static unsafe string GetFIFExtensionList(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFExtensionList_(fif)); } + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFExtensionList")] + private static unsafe extern byte* GetFIFExtensionList_(FREE_IMAGE_FORMAT fif); + + /// + /// Returns a descriptive string that describes the bitmap formats the given plugin can read and/or write. + /// + /// The desired . + /// A descriptive string that describes the bitmap formats. + public static unsafe string GetFIFDescription(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFDescription_(fif)); } + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFDescription")] + private static unsafe extern byte* GetFIFDescription_(FREE_IMAGE_FORMAT fif); + + /// + /// Returns a regular expression string that can be used by a regular expression engine to identify the bitmap. + /// FreeImageQt makes use of this function. + /// + /// The desired . + /// A regular expression string. + public static unsafe string GetFIFRegExpr(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFRegExpr_(fif)); } + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFRegExpr")] + private static unsafe extern byte* GetFIFRegExpr_(FREE_IMAGE_FORMAT fif); + + /// + /// Given a identifier, returns a MIME content type string (MIME stands for Multipurpose Internet Mail Extension). + /// + /// The desired . + /// A MIME content type string. + public static unsafe string GetFIFMimeType(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFMimeType_(fif)); } + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFMimeType")] + private static unsafe extern byte* GetFIFMimeType_(FREE_IMAGE_FORMAT fif); + + /// + /// This function takes a filename or a file-extension and returns the plugin that can + /// read/write files with that extension in the form of a identifier. + /// + /// The filename or -extension. + /// The of the plugin. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")] + public static extern FREE_IMAGE_FORMAT GetFIFFromFilename(string filename); + + /// + /// This function takes a filename or a file-extension and returns the plugin that can + /// read/write files with that extension in the form of a identifier. + /// Supports UNICODE filenames. + /// + /// The filename or -extension. + /// The of the plugin. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")] + private static extern FREE_IMAGE_FORMAT GetFIFFromFilenameU(string filename); + + /// + /// Checks if a plugin can load bitmaps. + /// + /// The of the plugin. + /// True if the plugin can load bitmaps, else false. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsReading")] + public static extern bool FIFSupportsReading(FREE_IMAGE_FORMAT fif); + + /// + /// Checks if a plugin can save bitmaps. + /// + /// The of the plugin. + /// True if the plugin can save bitmaps, else false. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsWriting")] + public static extern bool FIFSupportsWriting(FREE_IMAGE_FORMAT fif); + + /// + /// Checks if a plugin can save bitmaps in the desired bit depth. + /// + /// The of the plugin. + /// The desired bit depth. + /// True if the plugin can save bitmaps in the desired bit depth, else false. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsExportBPP")] + public static extern bool FIFSupportsExportBPP(FREE_IMAGE_FORMAT fif, int bpp); + + /// + /// Checks if a plugin can save a bitmap in the desired data type. + /// + /// The of the plugin. + /// The desired image type. + /// True if the plugin can save bitmaps as the desired type, else false. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsExportType")] + public static extern bool FIFSupportsExportType(FREE_IMAGE_FORMAT fif, FREE_IMAGE_TYPE type); + + /// + /// Checks if a plugin can load or save an ICC profile. + /// + /// The of the plugin. + /// True if the plugin can load or save an ICC profile, else false. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsICCProfiles")] + public static extern bool FIFSupportsICCProfiles(FREE_IMAGE_FORMAT fif); + + #endregion + + #region Multipage functions + + /// + /// Loads a FreeImage multi-paged bitmap. + /// Load flags can be provided by the flags parameter. + /// + /// Format of the image. + /// The complete name of the file to load. + /// When true a new bitmap is created. + /// When true the bitmap will be loaded read only. + /// When true performance is increased at the cost of memory. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage multi-paged bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMultiBitmap")] + public static extern FIMULTIBITMAP OpenMultiBitmap(FREE_IMAGE_FORMAT fif, string filename, bool create_new, + bool read_only, bool keep_cache_in_memory, FREE_IMAGE_LOAD_FLAGS flags); + + /// + /// Loads a FreeImage multi-pages bitmap from the specified handle + /// using the specified functions. + /// Load flags can be provided by the flags parameter. + /// + /// Format of the image. + /// IO functions used to read from the specified handle. + /// The handle to load the bitmap from. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage multi-paged bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMultiBitmapFromHandle")] + public static extern FIMULTIBITMAP OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io, + fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags); + + /// + /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, applies any changes made to it. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloseMultiBitmap")] + private static extern bool CloseMultiBitmap_(FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags); + + /// + /// Returns the number of pages currently available in the multi-paged bitmap. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Number of pages. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPageCount")] + public static extern int GetPageCount(FIMULTIBITMAP bitmap); + + /// + /// Appends a new page to the end of the bitmap. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AppendPage")] + public static extern void AppendPage(FIMULTIBITMAP bitmap, FIBITMAP data); + + /// + /// Inserts a new page before the given position in the bitmap. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Page has to be a number smaller than the current number of pages available in the bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_InsertPage")] + public static extern void InsertPage(FIMULTIBITMAP bitmap, int page, FIBITMAP data); + + /// + /// Deletes the page on the given position. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Number of the page to delete. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeletePage")] + public static extern void DeletePage(FIMULTIBITMAP bitmap, int page); + + /// + /// Locks a page in memory for editing. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Number of the page to lock. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LockPage")] + public static extern FIBITMAP LockPage(FIMULTIBITMAP bitmap, int page); + + /// + /// Unlocks a previously locked page and gives it back to the multi-page engine. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Handle to a FreeImage bitmap. + /// If true, the page is applied to the multi-page bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_UnlockPage")] + public static extern void UnlockPage(FIMULTIBITMAP bitmap, FIBITMAP data, bool changed); + + /// + /// Moves the source page to the position of the target page. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// New position of the page. + /// Old position of the page. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MovePage")] + public static extern bool MovePage(FIMULTIBITMAP bitmap, int target, int source); + + /// + /// Returns an array of page-numbers that are currently locked in memory. + /// When the pages parameter is null, the size of the array is returned in the count variable. + /// + /// + /// + /// int[] lockedPages = null; + /// int count = 0; + /// GetLockedPageNumbers(dib, lockedPages, ref count); + /// lockedPages = new int[count]; + /// GetLockedPageNumbers(dib, lockedPages, ref count); + /// + /// + /// Handle to a FreeImage multi-paged bitmap. + /// The list of locked pages in the multi-pages bitmap. + /// If set to null, count will contain the number of pages. + /// If is set to null count will contain the number of locked pages. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetLockedPageNumbers")] + public static extern bool GetLockedPageNumbers(FIMULTIBITMAP bitmap, int[] pages, ref int count); + + #endregion + + #region Filetype functions + + /// + /// Orders FreeImage to analyze the bitmap signature. + /// + /// Name of the file to analyze. + /// Reserved parameter - use 0. + /// Type of the bitmap. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")] + public static extern FREE_IMAGE_FORMAT GetFileType(string filename, int size); + + + /// + /// Orders FreeImage to analyze the bitmap signature. + /// Supports UNICODE filenames. + /// + /// Name of the file to analyze. + /// Reserved parameter - use 0. + /// Type of the bitmap. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")] + private static extern FREE_IMAGE_FORMAT GetFileTypeU(string filename, int size); + + /// + /// Uses the structure as described in the topic bitmap management functions + /// to identify a bitmap type. + /// + /// A structure with functionpointers to handle the source. + /// A handle to the source. + /// Size in bytes of the source. + /// Type of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromHandle")] + public static extern FREE_IMAGE_FORMAT GetFileTypeFromHandle(ref FreeImageIO io, fi_handle handle, int size); + + /// + /// Uses a memory handle to identify a bitmap type. + /// + /// Pointer to the stream. + /// Size in bytes of the source. + /// Type of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromMemory")] + public static extern FREE_IMAGE_FORMAT GetFileTypeFromMemory(FIMEMORY stream, int size); + + #endregion + + #region Helper functions + + /// + /// Returns whether the platform is using Little Endian. + /// + /// Returns true if the platform is using Litte Endian, else false. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsLittleEndian")] + public static extern bool IsLittleEndian(); + + /// + /// Converts a X11 color name into a corresponding RGB value. + /// + /// Name of the color to convert. + /// Red component. + /// Green component. + /// Blue component. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_LookupX11Color")] + public static extern bool LookupX11Color(string szColor, out byte nRed, out byte nGreen, out byte nBlue); + + /// + /// Converts a SVG color name into a corresponding RGB value. + /// + /// Name of the color to convert. + /// Red component. + /// Green component. + /// Blue component. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_LookupSVGColor")] + public static extern bool LookupSVGColor(string szColor, out byte nRed, out byte nGreen, out byte nBlue); + + #endregion + + #region Pixel access functions + + /// + /// Returns a pointer to the data-bits of the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Pointer to the data-bits. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBits")] + public static extern IntPtr GetBits(FIBITMAP dib); + + /// + /// Returns a pointer to the start of the given scanline in the bitmap's data-bits. + /// + /// Handle to a FreeImage bitmap. + /// Number of the scanline. + /// Pointer to the scanline. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetScanLine")] + public static extern IntPtr GetScanLine(FIBITMAP dib, int scanline); + + /// + /// Get the pixel index of a palettized image at position (x, y), including range check (slow access). + /// + /// Handle to a FreeImage bitmap. + /// Pixel position in horizontal direction. + /// Pixel position in vertical direction. + /// The pixel index. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPixelIndex")] + public static extern bool GetPixelIndex(FIBITMAP dib, uint x, uint y, out byte value); + + /// + /// Get the pixel color of a 16-, 24- or 32-bit image at position (x, y), including range check (slow access). + /// + /// Handle to a FreeImage bitmap. + /// Pixel position in horizontal direction. + /// Pixel position in vertical direction. + /// The pixel color. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPixelColor")] + public static extern bool GetPixelColor(FIBITMAP dib, uint x, uint y, out RGBQUAD value); + + /// + /// Set the pixel index of a palettized image at position (x, y), including range check (slow access). + /// + /// Handle to a FreeImage bitmap. + /// Pixel position in horizontal direction. + /// Pixel position in vertical direction. + /// The new pixel index. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPixelIndex")] + public static extern bool SetPixelIndex(FIBITMAP dib, uint x, uint y, ref byte value); + + /// + /// Set the pixel color of a 16-, 24- or 32-bit image at position (x, y), including range check (slow access). + /// + /// Handle to a FreeImage bitmap. + /// Pixel position in horizontal direction. + /// Pixel position in vertical direction. + /// The new pixel color. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPixelColor")] + public static extern bool SetPixelColor(FIBITMAP dib, uint x, uint y, ref RGBQUAD value); + + #endregion + + #region Bitmap information functions + + /// + /// Retrieves the type of the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Type of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetImageType")] + public static extern FREE_IMAGE_TYPE GetImageType(FIBITMAP dib); + + /// + /// Returns the number of colors used in a bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Palette-size for palletised bitmaps, and 0 for high-colour bitmaps. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetColorsUsed")] + public static extern uint GetColorsUsed(FIBITMAP dib); + + /// + /// Returns the size of one pixel in the bitmap in bits. + /// + /// Handle to a FreeImage bitmap. + /// Size of one pixel in the bitmap in bits. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBPP")] + public static extern uint GetBPP(FIBITMAP dib); + + /// + /// Returns the width of the bitmap in pixel units. + /// + /// Handle to a FreeImage bitmap. + /// With of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetWidth")] + public static extern uint GetWidth(FIBITMAP dib); + + /// + /// Returns the height of the bitmap in pixel units. + /// + /// Handle to a FreeImage bitmap. + /// Height of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetHeight")] + public static extern uint GetHeight(FIBITMAP dib); + + /// + /// Returns the width of the bitmap in bytes. + /// + /// Handle to a FreeImage bitmap. + /// With of the bitmap in bytes. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetLine")] + public static extern uint GetLine(FIBITMAP dib); + + /// + /// Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary, + /// also known as pitch or stride or scan width. + /// + /// Handle to a FreeImage bitmap. + /// With of the bitmap in bytes. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPitch")] + public static extern uint GetPitch(FIBITMAP dib); + + /// + /// Returns the size of the DIB-element of a FIBITMAP in memory. + /// + /// Handle to a FreeImage bitmap. + /// Size of the DIB-element + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDIBSize")] + public static extern uint GetDIBSize(FIBITMAP dib); + + /// + /// Returns a pointer to the bitmap's palette. + /// + /// Handle to a FreeImage bitmap. + /// Pointer to the bitmap's palette. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPalette")] + public static extern IntPtr GetPalette(FIBITMAP dib); + + /// + /// Returns the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The horizontal resolution, in pixels-per-meter. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDotsPerMeterX")] + public static extern uint GetDotsPerMeterX(FIBITMAP dib); + + /// + /// Returns the vertical resolution, in pixels-per-meter, of the target device for the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The vertical resolution, in pixels-per-meter. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDotsPerMeterY")] + public static extern uint GetDotsPerMeterY(FIBITMAP dib); + + /// + /// Set the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The new horizontal resolution. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetDotsPerMeterX")] + public static extern void SetDotsPerMeterX(FIBITMAP dib, uint res); + + /// + /// Set the vertical resolution, in pixels-per-meter, of the target device for the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The new vertical resolution. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetDotsPerMeterY")] + public static extern void SetDotsPerMeterY(FIBITMAP dib, uint res); + + /// + /// Returns a pointer to the of the DIB-element in a FIBITMAP. + /// + /// Handle to a FreeImage bitmap. + /// Poiter to the header of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetInfoHeader")] + public static extern IntPtr GetInfoHeader(FIBITMAP dib); + + /// + /// Alias for FreeImage_GetInfoHeader that returns a pointer to a + /// rather than to a . + /// + /// Handle to a FreeImage bitmap. + /// Pointer to the structure for the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetInfo")] + public static extern IntPtr GetInfo(FIBITMAP dib); + + /// + /// Investigates the color type of the bitmap by reading the bitmap's pixel bits and analysing them. + /// + /// Handle to a FreeImage bitmap. + /// The color type of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetColorType")] + public static extern FREE_IMAGE_COLOR_TYPE GetColorType(FIBITMAP dib); + + /// + /// Returns a bit pattern describing the red color component of a pixel in a FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The bit pattern for RED. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetRedMask")] + public static extern uint GetRedMask(FIBITMAP dib); + + /// + /// Returns a bit pattern describing the green color component of a pixel in a FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The bit pattern for green. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetGreenMask")] + public static extern uint GetGreenMask(FIBITMAP dib); + + /// + /// Returns a bit pattern describing the blue color component of a pixel in a FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The bit pattern for blue. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBlueMask")] + public static extern uint GetBlueMask(FIBITMAP dib); + + /// + /// Returns the number of transparent colors in a palletised bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The number of transparent colors in a palletised bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparencyCount")] + public static extern uint GetTransparencyCount(FIBITMAP dib); + + /// + /// Returns a pointer to the bitmap's transparency table. + /// + /// Handle to a FreeImage bitmap. + /// Pointer to the bitmap's transparency table. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparencyTable")] + public static extern IntPtr GetTransparencyTable(FIBITMAP dib); + + /// + /// Tells FreeImage if it should make use of the transparency table + /// or the alpha channel that may accompany a bitmap. + /// + /// Handle to a FreeImage bitmap. + /// True to enable the transparency, false to disable. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparent")] + public static extern void SetTransparent(FIBITMAP dib, bool enabled); + + /// + /// Set the bitmap's transparency table. Only affects palletised bitmaps. + /// + /// Handle to a FreeImage bitmap. + /// Pointer to the bitmap's new transparency table. + /// The number of transparent colors in the new transparency table. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparencyTable")] + internal static extern void SetTransparencyTable(FIBITMAP dib, byte[] table, int count); + + /// + /// Returns whether the transparency table is enabled. + /// + /// Handle to a FreeImage bitmap. + /// Returns true when the transparency table is enabled (1-, 4- or 8-bit images) + /// or when the input dib contains alpha values (32-bit images). Returns false otherwise. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsTransparent")] + public static extern bool IsTransparent(FIBITMAP dib); + + /// + /// Returns whether the bitmap has a file background color. + /// + /// Handle to a FreeImage bitmap. + /// Returns true when the image has a file background color, false otherwise. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_HasBackgroundColor")] + public static extern bool HasBackgroundColor(FIBITMAP dib); + + /// + /// Returns the file background color of an image. + /// For 8-bit images, the color index in the palette is returned in the + /// rgbReserved member of the bkcolor parameter. + /// + /// Handle to a FreeImage bitmap. + /// The background color. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBackgroundColor")] + public static extern bool GetBackgroundColor(FIBITMAP dib, out RGBQUAD bkcolor); + + /// + /// Set the file background color of an image. + /// When saving an image to PNG, this background color is transparently saved to the PNG file. + /// + /// Handle to a FreeImage bitmap. + /// The new background color. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetBackgroundColor")] + public static unsafe extern bool SetBackgroundColor(FIBITMAP dib, ref RGBQUAD bkcolor); + + /// + /// Set the file background color of an image. + /// When saving an image to PNG, this background color is transparently saved to the PNG file. + /// When the bkcolor parameter is null, the background color is removed from the image. + /// + /// This overloaded version of the function with an array parameter is provided to allow + /// passing null in the parameter. This is similar to the + /// original C/C++ function. Passing null as parameter will + /// unset the dib's previously set background color. + /// + /// + /// Handle to a FreeImage bitmap. + /// The new background color. + /// The first entry in the array is used. + /// Returns true on success, false on failure. + /// + /// + /// // create a RGBQUAD color + /// RGBQUAD color = new RGBQUAD(Color.Green); + /// + /// // set the dib's background color (using the other version of the function) + /// FreeImage.SetBackgroundColor(dib, ref color); + /// + /// // remove it again (this only works due to the array parameter RGBQUAD[]) + /// FreeImage.SetBackgroundColor(dib, null); + /// + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetBackgroundColor")] + public static unsafe extern bool SetBackgroundColor(FIBITMAP dib, RGBQUAD[] bkcolor); + + /// + /// Sets the index of the palette entry to be used as transparent color + /// for the image specified. Does nothing on high color images. + /// + /// Handle to a FreeImage bitmap. + /// The index of the palette entry to be set as transparent color. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparentIndex")] + public static extern void SetTransparentIndex(FIBITMAP dib, int index); + + /// + /// Returns the palette entry used as transparent color for the image specified. + /// Works for palletised images only and returns -1 for high color + /// images or if the image has no color set to be transparent. + /// + /// Handle to a FreeImage bitmap. + /// the index of the palette entry used as transparent color for + /// the image specified or -1 if there is no transparent color found + /// (e.g. the image is a high color image). + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparentIndex")] + public static extern int GetTransparentIndex(FIBITMAP dib); + + #endregion + + #region ICC profile functions + + /// + /// Retrieves the data of the bitmap. + /// This function can also be called safely, when the original format does not support profiles. + /// + /// Handle to a FreeImage bitmap. + /// The data of the bitmap. + public static FIICCPROFILE GetICCProfileEx(FIBITMAP dib) { unsafe { return *(FIICCPROFILE*)FreeImage.GetICCProfile(dib); } } + + /// + /// Retrieves a pointer to the data of the bitmap. + /// This function can also be called safely, when the original format does not support profiles. + /// + /// Handle to a FreeImage bitmap. + /// Pointer to the data of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetICCProfile")] + public static extern IntPtr GetICCProfile(FIBITMAP dib); + + /// + /// Creates a new block from ICC profile data previously read from a file + /// or built by a color management system. The profile data is attached to the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Pointer to the new data. + /// Size of the data. + /// Pointer to the created structure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CreateICCProfile")] + public static extern IntPtr CreateICCProfile(FIBITMAP dib, byte[] data, int size); + + /// + /// This function destroys an previously created by . + /// After this call the bitmap will contain no profile information. + /// This function should be called to ensure that a stored bitmap will not contain any profile information. + /// + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DestroyICCProfile")] + public static extern void DestroyICCProfile(FIBITMAP dib); + + #endregion + + #region Conversion functions + + /// + /// Converts a bitmap to 4 bits. + /// If the bitmap was a high-color bitmap (16, 24 or 32-bit) or if it was a + /// monochrome or greyscale bitmap (1 or 8-bit), the end result will be a + /// greyscale bitmap, otherwise (1-bit palletised bitmaps) it will be a palletised bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo4Bits")] + public static extern FIBITMAP ConvertTo4Bits(FIBITMAP dib); + + /// + /// Converts a bitmap to 8 bits. If the bitmap was a high-color bitmap (16, 24 or 32-bit) + /// or if it was a monochrome or greyscale bitmap (1 or 4-bit), the end result will be a + /// greyscale bitmap, otherwise (1 or 4-bit palletised bitmaps) it will be a palletised bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo8Bits")] + public static extern FIBITMAP ConvertTo8Bits(FIBITMAP dib); + + /// + /// Converts a bitmap to a 8-bit greyscale image with a linear ramp. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToGreyscale")] + public static extern FIBITMAP ConvertToGreyscale(FIBITMAP dib); + + /// + /// Converts a bitmap to 16 bits, where each pixel has a color pattern of + /// 5 bits red, 5 bits green and 5 bits blue. One bit in each pixel is unused. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo16Bits555")] + public static extern FIBITMAP ConvertTo16Bits555(FIBITMAP dib); + + /// + /// Converts a bitmap to 16 bits, where each pixel has a color pattern of + /// 5 bits red, 6 bits green and 5 bits blue. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo16Bits565")] + public static extern FIBITMAP ConvertTo16Bits565(FIBITMAP dib); + + /// + /// Converts a bitmap to 24 bits. A clone of the input bitmap is returned for 24-bit bitmaps. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo24Bits")] + public static extern FIBITMAP ConvertTo24Bits(FIBITMAP dib); + + /// + /// Converts a bitmap to 32 bits. A clone of the input bitmap is returned for 32-bit bitmaps. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo32Bits")] + public static extern FIBITMAP ConvertTo32Bits(FIBITMAP dib); + + /// + /// Quantizes a high-color 24-bit bitmap to an 8-bit palette color bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Specifies the color reduction algorithm to be used. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ColorQuantize")] + public static extern FIBITMAP ColorQuantize(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize); + + /// + /// ColorQuantizeEx is an extension to the method that + /// provides additional options used to quantize a 24-bit image to any + /// number of colors (up to 256), as well as quantize a 24-bit image using a + /// partial or full provided palette. + /// + /// Handle to a FreeImage bitmap. + /// Specifies the color reduction algorithm to be used. + /// Size of the desired output palette. + /// Size of the provided palette of ReservePalette. + /// The provided palette. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ColorQuantizeEx")] + public static extern FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, int ReserveSize, RGBQUAD[] ReservePalette); + + /// + /// Converts a bitmap to 1-bit monochrome bitmap using a threshold T between [0..255]. + /// The function first converts the bitmap to a 8-bit greyscale bitmap. + /// Then, any brightness level that is less than T is set to zero, otherwise to 1. + /// For 1-bit input bitmaps, the function clones the input bitmap and builds a monochrome palette. + /// + /// Handle to a FreeImage bitmap. + /// The threshold. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Threshold")] + public static extern FIBITMAP Threshold(FIBITMAP dib, byte t); + + /// + /// Converts a bitmap to 1-bit monochrome bitmap using a dithering algorithm. + /// For 1-bit input bitmaps, the function clones the input bitmap and builds a monochrome palette. + /// + /// Handle to a FreeImage bitmap. + /// The dithering algorithm to use. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Dither")] + public static extern FIBITMAP Dither(FIBITMAP dib, FREE_IMAGE_DITHER algorithm); + + /// + /// Converts a raw bitmap to a FreeImage bitmap. + /// + /// Pointer to the memory block containing the raw bitmap. + /// The width in pixels of the raw bitmap. + /// The height in pixels of the raw bitmap. + /// Defines the total width of a scanline in the raw bitmap, + /// including padding bytes. + /// The bit depth (bits per pixel) of the raw bitmap. + /// The bit mask describing the bits used to store a single + /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// If true, the raw bitmap is stored in top-down order (top-left pixel first) + /// and in bottom-up order (bottom-left pixel first) otherwise. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertFromRawBits")] + public static extern FIBITMAP ConvertFromRawBits(IntPtr bits, int width, int height, int pitch, + uint bpp, uint red_mask, uint green_mask, uint blue_mask, bool topdown); + + /// + /// Converts a raw bitmap to a FreeImage bitmap. + /// + /// Array of bytes containing the raw bitmap. + /// The width in pixels of the raw bitmap. + /// The height in pixels of the raw bitmap. + /// Defines the total width of a scanline in the raw bitmap, + /// including padding bytes. + /// The bit depth (bits per pixel) of the raw bitmap. + /// The bit mask describing the bits used to store a single + /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// If true, the raw bitmap is stored in top-down order (top-left pixel first) + /// and in bottom-up order (bottom-left pixel first) otherwise. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertFromRawBits")] + public static extern FIBITMAP ConvertFromRawBits(byte[] bits, int width, int height, int pitch, + uint bpp, uint red_mask, uint green_mask, uint blue_mask, bool topdown); + + /// + /// Converts a FreeImage bitmap to a raw bitmap, that is a raw piece of memory. + /// + /// Pointer to the memory block receiving the raw bitmap. + /// Handle to a FreeImage bitmap. + /// The desired total width in bytes of a scanline in the raw bitmap, + /// including any padding bytes. + /// The desired bit depth (bits per pixel) of the raw bitmap. + /// The desired bit mask describing the bits used to store a single + /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The desired bit mask describing the bits used to store a single + /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The desired bit mask describing the bits used to store a single + /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// If true, the raw bitmap will be stored in top-down order (top-left pixel first) + /// and in bottom-up order (bottom-left pixel first) otherwise. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRawBits")] + public static extern void ConvertToRawBits(IntPtr bits, FIBITMAP dib, int pitch, uint bpp, + uint red_mask, uint green_mask, uint blue_mask, bool topdown); + + /// + /// Converts a FreeImage bitmap to a raw bitmap, that is a raw piece of memory. + /// + /// Array of bytes receiving the raw bitmap. + /// Handle to a FreeImage bitmap. + /// The desired total width in bytes of a scanline in the raw bitmap, + /// including any padding bytes. + /// The desired bit depth (bits per pixel) of the raw bitmap. + /// The desired bit mask describing the bits used to store a single + /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The desired bit mask describing the bits used to store a single + /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The desired bit mask describing the bits used to store a single + /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// If true, the raw bitmap will be stored in top-down order (top-left pixel first) + /// and in bottom-up order (bottom-left pixel first) otherwise. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRawBits")] + public static extern void ConvertToRawBits(byte[] bits, FIBITMAP dib, int pitch, uint bpp, + uint red_mask, uint green_mask, uint blue_mask, bool topdown); + + /// + /// Converts a 24- or 32-bit RGB(A) standard image or a 48-bit RGB image to a FIT_RGBF type image. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRGBF")] + public static extern FIBITMAP ConvertToRGBF(FIBITMAP dib); + + /// + /// Converts a non standard image whose color type is FIC_MINISBLACK + /// to a standard 8-bit greyscale image. + /// + /// Handle to a FreeImage bitmap. + /// When true the conversion is done by scaling linearly + /// each pixel value from [min, max] to an integer value between [0..255], + /// where min and max are the minimum and maximum pixel values in the image. + /// When false the conversion is done by rounding each pixel value to an integer between [0..255]. + /// + /// Rounding is done using the following formula: + /// + /// dst_pixel = (BYTE) MIN(255, MAX(0, q)) where int q = int(src_pixel + 0.5); + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToStandardType")] + public static extern FIBITMAP ConvertToStandardType(FIBITMAP src, bool scale_linear); + + /// + /// Converts an image of any type to type dst_type. + /// + /// Handle to a FreeImage bitmap. + /// Destination type. + /// True to scale linear, else false. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToType")] + public static extern FIBITMAP ConvertToType(FIBITMAP src, FREE_IMAGE_TYPE dst_type, bool scale_linear); + + #endregion + + #region Tone mapping operators + + /// + /// Converts a High Dynamic Range image (48-bit RGB or 96-bit RGBF) to a 24-bit RGB image, suitable for display. + /// + /// Handle to a FreeImage bitmap. + /// The tone mapping operator to be used. + /// Parmeter depending on the used algorithm + /// Parmeter depending on the used algorithm + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ToneMapping")] + public static extern FIBITMAP ToneMapping(FIBITMAP dib, FREE_IMAGE_TMO tmo, double first_param, double second_param); + + /// + /// Converts a High Dynamic Range image to a 24-bit RGB image using a global + /// operator based on logarithmic compression of luminance values, imitating the human response to light. + /// + /// Handle to a FreeImage bitmap. + /// A gamma correction that is applied after the tone mapping. + /// A value of 1 means no correction. + /// Scale factor allowing to adjust the brightness of the output image. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoDrago03")] + public static extern FIBITMAP TmoDrago03(FIBITMAP src, double gamma, double exposure); + + /// + /// Converts a High Dynamic Range image to a 24-bit RGB image using a global operator inspired + /// by photoreceptor physiology of the human visual system. + /// + /// Handle to a FreeImage bitmap. + /// Controls the overall image intensity in the range [-8, 8]. + /// Controls the overall image contrast in the range [0.3, 1.0[. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoReinhard05")] + public static extern FIBITMAP TmoReinhard05(FIBITMAP src, double intensity, double contrast); + + /// + /// Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and convert to 24-bit RGB. + /// + /// Handle to a FreeImage bitmap. + /// Color saturation (s parameter in the paper) in [0.4..0.6] + /// Atenuation factor (beta parameter in the paper) in [0.8..0.9] + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoFattal02")] + public static extern FIBITMAP TmoFattal02(FIBITMAP src, double color_saturation, double attenuation); + + #endregion + + #region Compression functions + + /// + /// Compresses a source buffer into a target buffer, using the ZLib library. + /// + /// Pointer to the target buffer. + /// Size of the target buffer. + /// Must be at least 0.1% larger than source_size plus 12 bytes. + /// Pointer to the source buffer. + /// Size of the source buffer. + /// The actual size of the compressed buffer, or 0 if an error occurred. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibCompress")] + public static extern uint ZLibCompress(byte[] target, uint target_size, byte[] source, uint source_size); + + /// + /// Decompresses a source buffer into a target buffer, using the ZLib library. + /// + /// Pointer to the target buffer. + /// Size of the target buffer. + /// Must have been saved outlide of zlib. + /// Pointer to the source buffer. + /// Size of the source buffer. + /// The actual size of the uncompressed buffer, or 0 if an error occurred. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibUncompress")] + public static extern uint ZLibUncompress(byte[] target, uint target_size, byte[] source, uint source_size); + + /// + /// Compresses a source buffer into a target buffer, using the ZLib library. + /// + /// Pointer to the target buffer. + /// Size of the target buffer. + /// Must be at least 0.1% larger than source_size plus 24 bytes. + /// Pointer to the source buffer. + /// Size of the source buffer. + /// The actual size of the compressed buffer, or 0 if an error occurred. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibGZip")] + public static extern uint ZLibGZip(byte[] target, uint target_size, byte[] source, uint source_size); + + /// + /// Decompresses a source buffer into a target buffer, using the ZLib library. + /// + /// Pointer to the target buffer. + /// Size of the target buffer. + /// Must have been saved outlide of zlib. + /// Pointer to the source buffer. + /// Size of the source buffer. + /// The actual size of the uncompressed buffer, or 0 if an error occurred. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibGUnzip")] + public static extern uint ZLibGUnzip(byte[] target, uint target_size, byte[] source, uint source_size); + + /// + /// Generates a CRC32 checksum. + /// + /// The CRC32 checksum to begin with. + /// Pointer to the source buffer. + /// If the value is 0, the function returns the required initial value for the crc. + /// Size of the source buffer. + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibCRC32")] + public static extern uint ZLibCRC32(uint crc, byte[] source, uint source_size); + + #endregion + + #region Tag creation and destruction + + /// + /// Allocates a new object. + /// This object must be destroyed with a call to + /// when no longer in use. + /// + /// The new . + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CreateTag")] + public static extern FITAG CreateTag(); + + /// + /// Delete a previously allocated object. + /// + /// The to destroy. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeleteTag")] + public static extern void DeleteTag(FITAG tag); + + /// + /// Creates and returns a copy of a object. + /// + /// The to clone. + /// The new . + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloneTag")] + public static extern FITAG CloneTag(FITAG tag); + + #endregion + + #region Tag accessors + + /// + /// Returns the tag field name (unique inside a metadata model). + /// + /// The tag field. + /// The field name. + public static unsafe string GetTagKey(FITAG tag) { return PtrToStr(GetTagKey_(tag)); } + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetTagKey")] + private static unsafe extern byte* GetTagKey_(FITAG tag); + + /// + /// Returns the tag description. + /// + /// The tag field. + /// The description or NULL if unavailable. + public static unsafe string GetTagDescription(FITAG tag) { return PtrToStr(GetTagDescription_(tag)); } + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetTagDescription")] + private static unsafe extern byte* GetTagDescription_(FITAG tag); + + /// + /// Returns the tag ID. + /// + /// The tag field. + /// The ID or 0 if unavailable. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagID")] + public static extern ushort GetTagID(FITAG tag); + + /// + /// Returns the tag data type. + /// + /// The tag field. + /// The tag type. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagType")] + public static extern FREE_IMAGE_MDTYPE GetTagType(FITAG tag); + + /// + /// Returns the number of components in the tag (in tag type units). + /// + /// The tag field. + /// The number of components. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagCount")] + public static extern uint GetTagCount(FITAG tag); + + /// + /// Returns the length of the tag value in bytes. + /// + /// The tag field. + /// The length of the tag value. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagLength")] + public static extern uint GetTagLength(FITAG tag); + + /// + /// Returns the tag value. + /// It is up to the programmer to interpret the returned pointer correctly, + /// according to the results of GetTagType and GetTagCount. + /// + /// The tag field. + /// Pointer to the value. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagValue")] + public static extern IntPtr GetTagValue(FITAG tag); + + /// + /// Sets the tag field name. + /// + /// The tag field. + /// The new name. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetTagKey")] + public static extern bool SetTagKey(FITAG tag, string key); + + /// + /// Sets the tag description. + /// + /// The tag field. + /// The new description. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetTagDescription")] + public static extern bool SetTagDescription(FITAG tag, string description); + + /// + /// Sets the tag ID. + /// + /// The tag field. + /// The new ID. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagID")] + public static extern bool SetTagID(FITAG tag, ushort id); + + /// + /// Sets the tag data type. + /// + /// The tag field. + /// The new type. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagType")] + public static extern bool SetTagType(FITAG tag, FREE_IMAGE_MDTYPE type); + + /// + /// Sets the number of data in the tag. + /// + /// The tag field. + /// New number of data. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagCount")] + public static extern bool SetTagCount(FITAG tag, uint count); + + /// + /// Sets the length of the tag value in bytes. + /// + /// The tag field. + /// The new length. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagLength")] + public static extern bool SetTagLength(FITAG tag, uint length); + + /// + /// Sets the tag value. + /// + /// The tag field. + /// Pointer to the new value. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagValue")] + public static extern bool SetTagValue(FITAG tag, byte[] value); + + #endregion + + #region Metadata iterator + + /// + /// Provides information about the first instance of a tag that matches the metadata model. + /// + /// The model to match. + /// Handle to a FreeImage bitmap. + /// Tag that matches the metadata model. + /// Unique search handle that can be used to call FindNextMetadata or FindCloseMetadata. + /// Null if the metadata model does not exist. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindFirstMetadata")] + public static extern FIMETADATA FindFirstMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, out FITAG tag); + + /// + /// Find the next tag, if any, that matches the metadata model argument in a previous call + /// to FindFirstMetadata, and then alters the tag object contents accordingly. + /// + /// Unique search handle provided by FindFirstMetadata. + /// Tag that matches the metadata model. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindNextMetadata")] + public static extern bool FindNextMetadata(FIMETADATA mdhandle, out FITAG tag); + + /// + /// Closes the specified metadata search handle and releases associated resources. + /// + /// The handle to close. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindCloseMetadata")] + private static extern void FindCloseMetadata_(FIMETADATA mdhandle); + + #endregion + + #region Metadata setter and getter + + /// + /// Retrieve a metadata attached to a dib. + /// + /// The metadata model to look for. + /// Handle to a FreeImage bitmap. + /// The metadata field name. + /// A FITAG structure returned by the function. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetMetadata")] + public static extern bool GetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, string key, out FITAG tag); + + /// + /// Attach a new FreeImage tag to a dib. + /// + /// The metadata model used to store the tag. + /// Handle to a FreeImage bitmap. + /// The tag field name. + /// The FreeImage tag to be attached. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetMetadata")] + public static extern bool SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, string key, FITAG tag); + + #endregion + + #region Metadata helper functions + + /// + /// Returns the number of tags contained in the model metadata model attached to the input dib. + /// + /// The metadata model. + /// Handle to a FreeImage bitmap. + /// Number of tags contained in the metadata model. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetMetadataCount")] + public static extern uint GetMetadataCount(FREE_IMAGE_MDMODEL model, FIBITMAP dib); + + /// + /// Copies the metadata of FreeImage bitmap to another. + /// + /// The FreeImage bitmap to copy the metadata to. + /// The FreeImage bitmap to copy the metadata from. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloneMetadata")] + public static extern bool CloneMetadata(FIBITMAP dst, FIBITMAP src); + + /// + /// Converts a FreeImage tag structure to a string that represents the interpreted tag value. + /// The function is not thread safe. + /// + /// The metadata model. + /// The interpreted tag value. + /// Reserved. + /// The representing string. + public static unsafe string TagToString(FREE_IMAGE_MDMODEL model, FITAG tag, uint Make) { return PtrToStr(TagToString_(model, tag, Make)); } + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_TagToString")] + private static unsafe extern byte* TagToString_(FREE_IMAGE_MDMODEL model, FITAG tag, uint Make); + + #endregion + + #region Rotation and flipping + + /// + /// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. + /// 1-bit images rotation is limited to integer multiple of 90°. + /// null is returned for other values. + /// + /// Handle to a FreeImage bitmap. + /// The angle of rotation. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_RotateClassic")] + [Obsolete("RotateClassic is deprecated (use Rotate instead).")] + public static extern FIBITMAP RotateClassic(FIBITMAP dib, double angle); + + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Rotate")] + internal static extern FIBITMAP Rotate(FIBITMAP dib, double angle, IntPtr backgroundColor); + + /// + /// This function performs a rotation and / or translation of an 8-bit greyscale, + /// 24- or 32-bit image, using a 3rd order (cubic) B-Spline. + /// + /// Handle to a FreeImage bitmap. + /// The angle of rotation. + /// Horizontal image translation. + /// Vertical image translation. + /// Rotation center x-coordinate. + /// Rotation center y-coordinate. + /// When true the irrelevant part of the image is set to a black color, + /// otherwise, a mirroring technique is used to fill irrelevant pixels. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_RotateEx")] + public static extern FIBITMAP RotateEx(FIBITMAP dib, double angle, + double x_shift, double y_shift, double x_origin, double y_origin, bool use_mask); + + /// + /// Flip the input dib horizontally along the vertical axis. + /// + /// Handle to a FreeImage bitmap. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FlipHorizontal")] + public static extern bool FlipHorizontal(FIBITMAP dib); + + /// + /// Flip the input dib vertically along the horizontal axis. + /// + /// Handle to a FreeImage bitmap. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FlipVertical")] + public static extern bool FlipVertical(FIBITMAP dib); + + /// + /// Performs a lossless rotation or flipping on a JPEG file. + /// + /// Source file. + /// Destination file; can be the source file; will be overwritten. + /// The operation to apply. + /// To avoid lossy transformation, you can set the perfect parameter to true. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_JPEGTransformU")] + public static extern bool JPEGTransform(string src_file, string dst_file, + FREE_IMAGE_JPEG_OPERATION operation, bool perfect); + + #endregion + + #region Upsampling / downsampling + + /// + /// Performs resampling (or scaling, zooming) of a greyscale or RGB(A) image + /// to the desired destination width and height. + /// + /// Handle to a FreeImage bitmap. + /// Destination width. + /// Destination height. + /// The filter to apply. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Rescale")] + public static extern FIBITMAP Rescale(FIBITMAP dib, int dst_width, int dst_height, FREE_IMAGE_FILTER filter); + + /// + /// Creates a thumbnail from a greyscale or RGB(A) image, keeping aspect ratio. + /// + /// Handle to a FreeImage bitmap. + /// Thumbnail square size. + /// When true HDR images are transperantly converted to standard images. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MakeThumbnail")] + public static extern FIBITMAP MakeThumbnail(FIBITMAP dib, int max_pixel_size, bool convert); + + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_EnlargeCanvas")] + internal static extern FIBITMAP EnlargeCanvas(FIBITMAP dib, + int left, int top, int right, int bottom, IntPtr color, FREE_IMAGE_COLOR_OPTIONS options); + + #endregion + + #region Color manipulation + + /// + /// Perfoms an histogram transformation on a 8-, 24- or 32-bit image. + /// + /// Handle to a FreeImage bitmap. + /// The lookup table. + /// It's size is assumed to be 256 in length. + /// The color channel to be transformed. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustCurve")] + public static extern bool AdjustCurve(FIBITMAP dib, byte[] lookUpTable, FREE_IMAGE_COLOR_CHANNEL channel); + + /// + /// Performs gamma correction on a 8-, 24- or 32-bit image. + /// + /// Handle to a FreeImage bitmap. + /// The parameter represents the gamma value to use (gamma > 0). + /// A value of 1.0 leaves the image alone, less than one darkens it, and greater than one lightens it. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustGamma")] + public static extern bool AdjustGamma(FIBITMAP dib, double gamma); + + /// + /// Adjusts the brightness of a 8-, 24- or 32-bit image by a certain amount. + /// + /// Handle to a FreeImage bitmap. + /// A value 0 means no change, + /// less than 0 will make the image darker and greater than 0 will make the image brighter. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustBrightness")] + public static extern bool AdjustBrightness(FIBITMAP dib, double percentage); + + /// + /// Adjusts the contrast of a 8-, 24- or 32-bit image by a certain amount. + /// + /// Handle to a FreeImage bitmap. + /// A value 0 means no change, + /// less than 0 will decrease the contrast and greater than 0 will increase the contrast of the image. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustContrast")] + public static extern bool AdjustContrast(FIBITMAP dib, double percentage); + + /// + /// Inverts each pixel data. + /// + /// Handle to a FreeImage bitmap. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Invert")] + public static extern bool Invert(FIBITMAP dib); + + /// + /// Computes the image histogram. + /// + /// Handle to a FreeImage bitmap. + /// Array of integers with a size of 256. + /// Channel to compute from. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetHistogram")] + public static extern bool GetHistogram(FIBITMAP dib, int[] histo, FREE_IMAGE_COLOR_CHANNEL channel); + + #endregion + + #region Channel processing + + /// + /// Retrieves the red, green, blue or alpha channel of a 24- or 32-bit image. + /// + /// Handle to a FreeImage bitmap. + /// The color channel to extract. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetChannel")] + public static extern FIBITMAP GetChannel(FIBITMAP dib, FREE_IMAGE_COLOR_CHANNEL channel); + + /// + /// Insert a 8-bit dib into a 24- or 32-bit image. + /// Both images must have to same width and height. + /// + /// Handle to a FreeImage bitmap. + /// Handle to the bitmap to insert. + /// The color channel to replace. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetChannel")] + public static extern bool SetChannel(FIBITMAP dib, FIBITMAP dib8, FREE_IMAGE_COLOR_CHANNEL channel); + + /// + /// Retrieves the real part, imaginary part, magnitude or phase of a complex image. + /// + /// Handle to a FreeImage bitmap. + /// The color channel to extract. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetComplexChannel")] + public static extern FIBITMAP GetComplexChannel(FIBITMAP src, FREE_IMAGE_COLOR_CHANNEL channel); + + /// + /// Set the real or imaginary part of a complex image. + /// Both images must have to same width and height. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + /// The color channel to replace. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetComplexChannel")] + public static extern bool SetComplexChannel(FIBITMAP dst, FIBITMAP src, FREE_IMAGE_COLOR_CHANNEL channel); + + #endregion + + #region Copy / Paste / Composite routines + + /// + /// Copy a sub part of the current dib image. + /// + /// Handle to a FreeImage bitmap. + /// Specifies the left position of the cropped rectangle. + /// Specifies the top position of the cropped rectangle. + /// Specifies the right position of the cropped rectangle. + /// Specifies the bottom position of the cropped rectangle. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Copy")] + public static extern FIBITMAP Copy(FIBITMAP dib, int left, int top, int right, int bottom); + + /// + /// Alpha blend or combine a sub part image with the current dib image. + /// The bit depth of the dst bitmap must be greater than or equal to the bit depth of the src. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + /// Specifies the left position of the sub image. + /// Specifies the top position of the sub image. + /// alpha blend factor. + /// The source and destination images are alpha blended if alpha=0..255. + /// If alpha > 255, then the source image is combined to the destination image. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Paste")] + public static extern bool Paste(FIBITMAP dst, FIBITMAP src, int left, int top, int alpha); + + /// + /// This function composite a transparent foreground image against a single background color or + /// against a background image. + /// + /// Handle to a FreeImage bitmap. + /// When true the background of fg is used if it contains one. + /// The application background is used if useFileBkg is false. + /// Image used as background when useFileBkg is false or fg has no background + /// and appBkColor is null. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Composite")] + public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg, ref RGBQUAD appBkColor, FIBITMAP bg); + + /// + /// This function composite a transparent foreground image against a single background color or + /// against a background image. + /// + /// Handle to a FreeImage bitmap. + /// When true the background of fg is used if it contains one. + /// The application background is used if useFileBkg is false + /// and 'appBkColor' is not null. + /// Image used as background when useFileBkg is false or fg has no background + /// and appBkColor is null. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Composite")] + public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg, RGBQUAD[] appBkColor, FIBITMAP bg); + + /// + /// Performs a lossless crop on a JPEG file. + /// + /// Source filename. + /// Destination filename. + /// Specifies the left position of the cropped rectangle. + /// Specifies the top position of the cropped rectangle. + /// Specifies the right position of the cropped rectangle. + /// Specifies the bottom position of the cropped rectangle. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_JPEGCropU")] + public static extern bool JPEGCrop(string src_file, string dst_file, int left, int top, int right, int bottom); + + /// + /// Applies the alpha value of each pixel to its color components. + /// The aplha value stays unchanged. + /// Only works with 32-bits color depth. + /// + /// Handle to a FreeImage bitmap. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_PreMultiplyWithAlpha")] + public static extern bool PreMultiplyWithAlpha(FIBITMAP dib); + + #endregion + + #region Miscellaneous algorithms + + /// + /// Solves a Poisson equation, remap result pixels to [0..1] and returns the solution. + /// + /// Handle to a FreeImage bitmap. + /// Number of cycles in the multigrid algorithm (usually 2 or 3) + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MultigridPoissonSolver")] + public static extern FIBITMAP MultigridPoissonSolver(FIBITMAP Laplacian, int ncycle); + + #endregion + + #region Colors + + /// + /// Creates a lookup table to be used with which may adjusts brightness and + /// contrast, correct gamma and invert the image with a single call to . + /// + /// Output lookup table to be used with . + /// The size of 'lookUpTable' is assumed to be 256. + /// Percentage brightness value where -100 <= brightness <= 100. + /// A value of 0 means no change, less than 0 will make the image darker and greater + /// than 0 will make the image brighter. + /// Percentage contrast value where -100 <= contrast <= 100. + /// A value of 0 means no change, less than 0 will decrease the contrast + /// and greater than 0 will increase the contrast of the image. + /// Gamma value to be used for gamma correction. + /// A value of 1.0 leaves the image alone, less than one darkens it, + /// and greater than one lightens it. + /// If set to true, the image will be inverted. + /// The number of adjustments applied to the resulting lookup table + /// compared to a blind lookup table. + /// + /// This function creates a lookup table to be used with which may adjust + /// brightness and contrast, correct gamma and invert the image with a single call to + /// . If more than one of these image display properties need to be adjusted, + /// using a combined lookup table should be preferred over calling each adjustment function + /// separately. That's particularly true for huge images or if performance is an issue. Then, + /// the expensive process of iterating over all pixels of an image is performed only once and + /// not up to four times. + /// + /// Furthermore, the lookup table created does not depend on the order, in which each single + /// adjustment operation is performed. Due to rounding and byte casting issues, it actually + /// matters in which order individual adjustment operations are performed. Both of the following + /// snippets most likely produce different results: + /// + /// + /// // snippet 1: contrast, brightness + /// AdjustContrast(dib, 15.0); + /// AdjustBrightness(dib, 50.0); + /// + /// + /// + /// // snippet 2: brightness, contrast + /// AdjustBrightness(dib, 50.0); + /// AdjustContrast(dib, 15.0); + /// + /// + /// Better and even faster would be snippet 3: + /// + /// + /// // snippet 3: + /// byte[] lut = new byte[256]; + /// GetAdjustColorsLookupTable(lut, 50.0, 15.0, 1.0, false); + /// AdjustCurve(dib, lut, FREE_IMAGE_COLOR_CHANNEL.FICC_RGB); + /// + /// + /// This function is also used internally by , which does not return the + /// lookup table, but uses it to call on the passed image. + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetAdjustColorsLookupTable")] + public static extern int GetAdjustColorsLookupTable(byte[] lookUpTable, double brightness, double contrast, double gamma, bool invert); + + /// + /// Adjusts an image's brightness, contrast and gamma as well as it may + /// optionally invert the image within a single operation. + /// + /// Handle to a FreeImage bitmap. + /// Percentage brightness value where -100 <= brightness <= 100. + /// A value of 0 means no change, less than 0 will make the image darker and greater + /// than 0 will make the image brighter. + /// Percentage contrast value where -100 <= contrast <= 100. + /// A value of 0 means no change, less than 0 will decrease the contrast + /// and greater than 0 will increase the contrast of the image. + /// Gamma value to be used for gamma correction. + /// A value of 1.0 leaves the image alone, less than one darkens it, + /// and greater than one lightens it. + /// This parameter must not be zero or smaller than zero. + /// If so, it will be ignored and no gamma correction will be performed on the image. + /// If set to true, the image will be inverted. + /// Returns true on success, false on failure. + /// + /// This function adjusts an image's brightness, contrast and gamma as well as it + /// may optionally invert the image within a single operation. If more than one of + /// these image display properties need to be adjusted, using this function should + /// be preferred over calling each adjustment function separately. That's particularly + /// true for huge images or if performance is an issue. + /// + /// This function relies on , + /// which creates a single lookup table, that combines all adjustment operations requested. + /// + /// Furthermore, the lookup table created by does + /// not depend on the order, in which each single adjustment operation is performed. + /// Due to rounding and byte casting issues, it actually matters in which order individual + /// adjustment operations are performed. Both of the following snippets most likely produce + /// different results: + /// + /// + /// // snippet 1: contrast, brightness + /// AdjustContrast(dib, 15.0); + /// AdjustBrightness(dib, 50.0); + /// + /// + /// + /// // snippet 2: brightness, contrast + /// AdjustBrightness(dib, 50.0); + /// AdjustContrast(dib, 15.0); + /// + /// + /// Better and even faster would be snippet 3: + /// + /// + /// // snippet 3: + /// AdjustColors(dib, 50.0, 15.0, 1.0, false); + /// + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustColors")] + public static extern bool AdjustColors(FIBITMAP dib, double brightness, double contrast, double gamma, bool invert); + + /// + /// Applies color mapping for one or several colors on a 1-, 4- or 8-bit + /// palletized or a 16-, 24- or 32-bit high color image. + /// + /// Handle to a FreeImage bitmap. + /// Array of colors to be used as the mapping source. + /// Array of colors to be used as the mapping destination. + /// The number of colors to be mapped. This is the size of both + /// srccolors and dstcolors. + /// If true, 32-bit images and colors are treated as 24-bit. + /// If true, source and destination colors are swapped, that is, + /// each destination color is also mapped to the corresponding source color. + /// The total number of pixels changed. + /// + /// This function maps up to colors specified in + /// to these specified in . + /// Thereby, color srccolors[N], if found in the image, will be replaced by color + /// dstcolors[N]. If is true, additionally all colors + /// specified in are also mapped to these specified + /// in . For high color images, the actual image data will be + /// modified whereas, for palletized images only the palette will be changed. + /// + /// The function returns the number of pixels changed or zero, if no pixels were changed. + /// + /// Both arrays and are assumed + /// not to hold less than colors. + /// + /// For 16-bit images, all colors specified are transparently converted to their + /// proper 16-bit representation (either in RGB555 or RGB565 format, which is determined + /// by the image's red- green- and blue-mask). + /// + /// Note, that this behaviour is different from what does, + /// which modifies the actual image data on palletized images. + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ApplyColorMapping")] + public static extern uint ApplyColorMapping(FIBITMAP dib, RGBQUAD[] srccolors, RGBQUAD[] dstcolors, uint count, bool ignore_alpha, bool swap); + + /// + /// Swaps two specified colors on a 1-, 4- or 8-bit palletized + /// or a 16-, 24- or 32-bit high color image. + /// + /// Handle to a FreeImage bitmap. + /// One of the two colors to be swapped. + /// The other of the two colors to be swapped. + /// If true, 32-bit images and colors are treated as 24-bit. + /// The total number of pixels changed. + /// + /// This function swaps the two specified colors and + /// on a palletized or high color image. + /// For high color images, the actual image data will be modified whereas, for palletized + /// images only the palette will be changed. + /// + /// Note, that this behaviour is different from what does, + /// which modifies the actual image data on palletized images. + /// + /// This is just a thin wrapper for and resolves to: + /// + /// + /// return ApplyColorMapping(dib, color_a, color_b, 1, ignore_alpha, true); + /// + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SwapColors")] + public static extern uint SwapColors(FIBITMAP dib, ref RGBQUAD color_a, ref RGBQUAD color_b, bool ignore_alpha); + + /// + /// Applies palette index mapping for one or several indices + /// on a 1-, 4- or 8-bit palletized image. + /// + /// Handle to a FreeImage bitmap. + /// Array of palette indices to be used as the mapping source. + /// Array of palette indices to be used as the mapping destination. + /// The number of palette indices to be mapped. This is the size of both + /// srcindices and dstindices + /// If true, source and destination palette indices are swapped, that is, + /// each destination index is also mapped to the corresponding source index. + /// The total number of pixels changed. + /// + /// This function maps up to palette indices specified in + /// to these specified in . + /// Thereby, index srcindices[N], if present in the image, will be replaced by index + /// dstindices[N]. If is true, additionally all indices + /// specified in are also mapped to these specified in + /// . + /// + /// The function returns the number of pixels changed or zero, if no pixels were changed. + /// Both arrays and are assumed not to + /// hold less than indices. + /// + /// Note, that this behaviour is different from what does, which + /// modifies the actual image data on palletized images. + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ApplyPaletteIndexMapping")] + public static extern uint ApplyPaletteIndexMapping(FIBITMAP dib, byte[] srcindices, byte[] dstindices, uint count, bool swap); + + /// + /// Swaps two specified palette indices on a 1-, 4- or 8-bit palletized image. + /// + /// Handle to a FreeImage bitmap. + /// One of the two palette indices to be swapped. + /// The other of the two palette indices to be swapped. + /// The total number of pixels changed. + /// + /// This function swaps the two specified palette indices index_a and + /// index_b on a palletized image. Therefore, not the palette, but the + /// actual image data will be modified. + /// + /// Note, that this behaviour is different from what does on palletized images, + /// which only swaps the colors in the palette. + /// + /// This is just a thin wrapper for and resolves to: + /// + /// + /// return ApplyPaletteIndexMapping(dib, index_a, index_b, 1, true); + /// + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SwapPaletteIndices")] + public static extern uint SwapPaletteIndices(FIBITMAP dib, ref byte index_a, ref byte index_b); + + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FillBackground")] + internal static extern bool FillBackground(FIBITMAP dib, IntPtr color, FREE_IMAGE_COLOR_OPTIONS options); + + #endregion + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/FreeImageWrapper.cs b/Wrapper/FreeImage.NET/cs/Library/FreeImageWrapper.cs index 696d77a..d52dccb 100644 --- a/Wrapper/FreeImage.NET/cs/Library/FreeImageWrapper.cs +++ b/Wrapper/FreeImage.NET/cs/Library/FreeImageWrapper.cs @@ -1,5329 +1,5329 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.19 $ -// $Date: 2011/10/02 13:00:45 $ -// $Id: FreeImageWrapper.cs,v 1.19 2011/10/02 13:00:45 drolon Exp $ -// ========================================================== - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; -using FreeImageAPI.IO; -using FreeImageAPI.Metadata; - -namespace FreeImageAPI -{ - /// - /// Static class importing functions from the FreeImage library - /// and providing additional functions. - /// - public static partial class FreeImage - { - #region Constants - - /// - /// Array containing all 'FREE_IMAGE_MDMODEL's. - /// - public static readonly FREE_IMAGE_MDMODEL[] FREE_IMAGE_MDMODELS = - (FREE_IMAGE_MDMODEL[])Enum.GetValues(typeof(FREE_IMAGE_MDMODEL)); - - /// - /// Stores handles used to read from streams. - /// - private static Dictionary streamHandles = - new Dictionary(); - - /// - /// Version of the wrapper library. - /// - private static Version WrapperVersion; - - private const int DIB_RGB_COLORS = 0; - private const int DIB_PAL_COLORS = 1; - private const int CBM_INIT = 0x4; - - /// - /// An uncompressed format. - /// - public const int BI_RGB = 0; - - /// - /// A run-length encoded (RLE) format for bitmaps with 8 bpp. The compression format is a 2-byte - /// format consisting of a count byte followed by a byte containing a color index. - /// - public const int BI_RLE8 = 1; - - /// - /// An RLE format for bitmaps with 4 bpp. The compression format is a 2-byte format consisting - /// of a count byte followed by two word-length color indexes. - /// - public const int BI_RLE4 = 2; - - /// - /// Specifies that the bitmap is not compressed and that the color table consists of three - /// DWORD color masks that specify the red, green, and blue components, respectively, - /// of each pixel. This is valid when used with 16- and 32-bpp bitmaps. - /// - public const int BI_BITFIELDS = 3; - - /// - /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a JPEG image. - /// - public const int BI_JPEG = 4; - - /// - /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a PNG image. - /// - public const int BI_PNG = 5; - - #endregion - - #region General functions - - /// - /// Returns the internal version of this FreeImage .NET wrapper. - /// - /// The internal version of this FreeImage .NET wrapper. - public static Version GetWrapperVersion() - { - if (WrapperVersion == null) - { - try - { - object[] attributes = Assembly.GetAssembly(typeof(FreeImage)) - .GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false); - if ((attributes != null) && (attributes.Length != 0)) - { - AssemblyFileVersionAttribute attribute = - attributes[0] as AssemblyFileVersionAttribute; - if ((attribute != null) && (attribute.Version != null)) - { - return (WrapperVersion = new Version(attribute.Version)); - } - } - } - catch - { - - } - - WrapperVersion = new Version(); - } - - return WrapperVersion; - } - - /// - /// Returns the version of the native FreeImage library. - /// - /// The version of the native FreeImage library. - public static Version GetNativeVersion() - { - return new Version(GetVersion()); - } - - /// - /// Returns a value indicating if the FreeImage library is available or not. - /// See remarks for further details. - /// - /// false if the file is not available or out of date; - /// true, otherwise. - /// - /// The FreeImage.NET library is a wrapper for the native C++ library - /// (FreeImage.dll ... dont mix ist up with this library FreeImageNet.dll). - /// The native library must be either in the same folder as the program's - /// executable or in a folder contained in the envirent variable PATH - /// (for example %WINDIR%\System32). - /// Further more must both libraries, including the program itself, - /// be the same architecture (x86 or x64). - /// - public static bool IsAvailable() - { - try - { - // Call a static fast executing function - Version nativeVersion = new Version(GetVersion()); - Version wrapperVersion = GetWrapperVersion(); - // No exception thrown, the library seems to be present - return - (nativeVersion.Major > wrapperVersion.Major) || - ((nativeVersion.Major == wrapperVersion.Major) && (nativeVersion.Minor > wrapperVersion.Minor)) || - ((nativeVersion.Major == wrapperVersion.Major) && (nativeVersion.Minor == wrapperVersion.Minor) && (nativeVersion.Build >= wrapperVersion.Build)); - } - catch (DllNotFoundException) - { - return false; - } - catch (EntryPointNotFoundException) - { - return false; - } - catch (BadImageFormatException) - { - return false; - } - } - - #endregion - - #region Bitmap management functions - - /// - /// Creates a new bitmap in memory. - /// - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new Bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap - /// Handle to a FreeImage bitmap. - public static FIBITMAP Allocate(int width, int height, int bpp) - { - return Allocate(width, height, bpp, 0, 0, 0); - } - - /// - /// Creates a new bitmap in memory. - /// - /// Type of the image. - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new Bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap - /// Handle to a FreeImage bitmap. - public static FIBITMAP AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp) - { - return AllocateT(type, width, height, bpp, 0, 0, 0); - } - - /// - /// Allocates a new image of the specified width, height and bit depth and optionally - /// fills it with the specified color. See remarks for further details. - /// - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmaps. - /// The color to fill the bitmap with or null. - /// Options to enable or disable function-features. - /// The palette of the bitmap or null. - /// Handle to a FreeImage bitmap. - /// - /// This function is an extension to , which additionally supports - /// specifying a palette to be set for the newly create image, as well as specifying a - /// background color, the newly created image should initially be filled with. - /// - /// Basically, this function internally relies on function , followed by a - /// call to . This is why both parameters - /// and behave the same as it is - /// documented for function . - /// So, please refer to the documentation of to - /// learn more about parameters and . - /// - /// The palette specified through parameter is only copied to the - /// newly created image, if the desired bit depth is smaller than or equal to 8 bits per pixel. - /// In other words, the parameter is only taken into account for - /// palletized images. So, for an 8-bit image, the length is 256, for an 4-bit image it is 16 - /// and it is 2 for a 1-bit image. In other words, this function does not support partial palettes. - /// - /// However, specifying a palette is not necesarily needed, even for palletized images. This - /// function is capable of implicitly creating a palette, if is null. - /// If the specified background color is a greyscale value (red = green = blue) or if option - /// is specified, a greyscale palette - /// is created. For a 1-bit image, only if the specified background color is either black or white, - /// a monochrome palette, consisting of black and white only is created. In any case, the darker - /// colors are stored at the smaller palette indices. - /// - /// If the specified background color is not a greyscale value, or is neither black nor white - /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized - /// palette. For this operation, option - /// is implicit, so the specified is applied to the palette entry, - /// specified by the background color's field. - /// The image is then filled with this palette index. - /// - /// This function returns a newly created image as function does, if both - /// parameters and are null. - /// If only is null, the palette pointed to by - /// parameter is initially set for the new image, if a palletized - /// image of type is created. - /// However, in the latter case, this function returns an image, whose - /// pixels are all initialized with zeros so, the image will be filled with the color of the - /// first palette entry. - /// - public static FIBITMAP AllocateEx(int width, int height, int bpp, - RGBQUAD? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette) - { - return AllocateEx(width, height, bpp, color, options, palette, 0, 0, 0); - } - - /// - /// Allocates a new image of the specified width, height and bit depth and optionally - /// fills it with the specified color. See remarks for further details. - /// - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmaps. - /// The color to fill the bitmap with or null. - /// Options to enable or disable function-features. - /// The palette of the bitmap or null. - /// Red part of the color layout. - /// eg: 0xFF0000 - /// Green part of the color layout. - /// eg: 0x00FF00 - /// Blue part of the color layout. - /// eg: 0x0000FF - /// Handle to a FreeImage bitmap. - /// - /// This function is an extension to , which additionally supports - /// specifying a palette to be set for the newly create image, as well as specifying a - /// background color, the newly created image should initially be filled with. - /// - /// Basically, this function internally relies on function , followed by a - /// call to . This is why both parameters - /// and behave the same as it is - /// documented for function . - /// So, please refer to the documentation of to - /// learn more about parameters and . - /// - /// The palette specified through parameter is only copied to the - /// newly created image, if the desired bit depth is smaller than or equal to 8 bits per pixel. - /// In other words, the parameter is only taken into account for - /// palletized images. So, for an 8-bit image, the length is 256, for an 4-bit image it is 16 - /// and it is 2 for a 1-bit image. In other words, this function does not support partial palettes. - /// - /// However, specifying a palette is not necesarily needed, even for palletized images. This - /// function is capable of implicitly creating a palette, if is null. - /// If the specified background color is a greyscale value (red = green = blue) or if option - /// is specified, a greyscale palette - /// is created. For a 1-bit image, only if the specified background color is either black or white, - /// a monochrome palette, consisting of black and white only is created. In any case, the darker - /// colors are stored at the smaller palette indices. - /// - /// If the specified background color is not a greyscale value, or is neither black nor white - /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized - /// palette. For this operation, option - /// is implicit, so the specified is applied to the palette entry, - /// specified by the background color's field. - /// The image is then filled with this palette index. - /// - /// This function returns a newly created image as function does, if both - /// parameters and are null. - /// If only is null, the palette pointed to by - /// parameter is initially set for the new image, if a palletized - /// image of type is created. - /// However, in the latter case, this function returns an image, whose - /// pixels are all initialized with zeros so, the image will be filled with the color of the - /// first palette entry. - /// - public static FIBITMAP AllocateEx(int width, int height, int bpp, - RGBQUAD? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, - uint red_mask, uint green_mask, uint blue_mask) - { - if ((palette != null) && (bpp <= 8) && (palette.Length < (1 << bpp))) - return FIBITMAP.Zero; - - if (color.HasValue) - { - GCHandle handle = new GCHandle(); - try - { - RGBQUAD[] buffer = new RGBQUAD[] { color.Value }; - handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - return AllocateEx(width, height, bpp, handle.AddrOfPinnedObject(), - options, palette, red_mask, green_mask, blue_mask); - } - finally - { - if (handle.IsAllocated) - handle.Free(); - } - } - else - { - return AllocateEx(width, height, bpp, IntPtr.Zero, - options, palette, red_mask, green_mask, blue_mask); - } - } - - /// - /// Allocates a new image of the specified type, width, height and bit depth and optionally - /// fills it with the specified color. See remarks for further details. - /// - /// The type of the specified color. - /// Type of the image. - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap - /// The color to fill the bitmap with or null. - /// Options to enable or disable function-features. - /// The palette of the bitmap or null. - /// Handle to a FreeImage bitmap. - /// - /// This function is an extension to , which additionally supports - /// specifying a palette to be set for the newly create image, as well as specifying a - /// background color, the newly created image should initially be filled with. - /// - /// Basically, this function internally relies on function , followed by a - /// call to . This is why both parameters - /// and behave the same as it is - /// documented for function . So, please refer to the - /// documentation of to learn more about parameters color and options. - /// - /// The palette specified through parameter palette is only copied to the newly created - /// image, if its image type is and the desired bit - /// depth is smaller than or equal to 8 bits per pixel. In other words, the - /// palette is only taken into account for palletized images. However, if the preceding conditions - /// match and if is not null, the palette is assumed to be at - /// least as large as the size of a fully populated palette for the desired bit depth. - /// So, for an 8-bit image, this length is 256, for an 4-bit image it is 16 and it is - /// 2 for a 1-bit image. In other words, this function does not support partial palettes. - /// - /// However, specifying a palette is not necesarily needed, even for palletized images. This - /// function is capable of implicitly creating a palette, if is null. - /// If the specified background color is a greyscale value (red = green = blue) or if option - /// is specified, a greyscale palette - /// is created. For a 1-bit image, only if the specified background color is either black or white, - /// a monochrome palette, consisting of black and white only is created. In any case, the darker - /// colors are stored at the smaller palette indices. - /// - /// If the specified background color is not a greyscale value, or is neither black nor white - /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized - /// palette. For this operation, option - /// is implicit, so the specified color is applied to the palette entry, specified by the - /// background color's field. The image is then filled with - /// this palette index. - /// - /// This function returns a newly created image as function does, if both - /// parameters and are null. - /// If only is null, the palette pointed to by - /// parameter is initially set for the new image, if a palletized - /// image of type is created. - /// However, in the latter case, this function returns an image, whose - /// pixels are all initialized with zeros so, the image will be filled with the color of the - /// first palette entry. - /// - public static FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp, - T? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette) where T : struct - { - return AllocateExT(type, width, height, bpp, color, options, palette, 0, 0, 0); - } - - /// - /// Allocates a new image of the specified type, width, height and bit depth and optionally - /// fills it with the specified color. See remarks for further details. - /// - /// The type of the specified color. - /// Type of the image. - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap - /// The color to fill the bitmap with or null. - /// Options to enable or disable function-features. - /// The palette of the bitmap or null. - /// Red part of the color layout. - /// eg: 0xFF0000 - /// Green part of the color layout. - /// eg: 0x00FF00 - /// Blue part of the color layout. - /// eg: 0x0000FF - /// Handle to a FreeImage bitmap. - /// - /// This function is an extension to , which additionally supports - /// specifying a palette to be set for the newly create image, as well as specifying a - /// background color, the newly created image should initially be filled with. - /// - /// Basically, this function internally relies on function , followed by a - /// call to . This is why both parameters - /// and behave the same as it is - /// documented for function . So, please refer to the - /// documentation of to learn more about parameters color and options. - /// - /// The palette specified through parameter palette is only copied to the newly created - /// image, if its image type is and the desired bit - /// depth is smaller than or equal to 8 bits per pixel. In other words, the - /// palette is only taken into account for palletized images. However, if the preceding conditions - /// match and if is not null, the palette is assumed to be at - /// least as large as the size of a fully populated palette for the desired bit depth. - /// So, for an 8-bit image, this length is 256, for an 4-bit image it is 16 and it is - /// 2 for a 1-bit image. In other words, this function does not support partial palettes. - /// - /// However, specifying a palette is not necesarily needed, even for palletized images. This - /// function is capable of implicitly creating a palette, if is null. - /// If the specified background color is a greyscale value (red = green = blue) or if option - /// is specified, a greyscale palette - /// is created. For a 1-bit image, only if the specified background color is either black or white, - /// a monochrome palette, consisting of black and white only is created. In any case, the darker - /// colors are stored at the smaller palette indices. - /// - /// If the specified background color is not a greyscale value, or is neither black nor white - /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized - /// palette. For this operation, option - /// is implicit, so the specified color is applied to the palette entry, specified by the - /// background color's field. The image is then filled with - /// this palette index. - /// - /// This function returns a newly created image as function does, if both - /// parameters and are null. - /// If only is null, the palette pointed to by - /// parameter is initially set for the new image, if a palletized - /// image of type is created. - /// However, in the latter case, this function returns an image, whose - /// pixels are all initialized with zeros so, the image will be filled with the color of the - /// first palette entry. - /// - public static FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp, - T? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, - uint red_mask, uint green_mask, uint blue_mask) where T : struct - { - if ((palette != null) && (bpp <= 8) && (palette.Length < (1 << bpp))) - return FIBITMAP.Zero; - - if (color.HasValue) - { - if (!CheckColorType(type, color.Value)) - return FIBITMAP.Zero; - - GCHandle handle = new GCHandle(); - try - { - T[] buffer = new T[] { color.Value }; - handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - return AllocateExT(type, width, height, bpp, handle.AddrOfPinnedObject(), - options, palette, red_mask, green_mask, blue_mask); - } - finally - { - if (handle.IsAllocated) - handle.Free(); - } - } - else - { - return AllocateExT(type, width, height, bpp, IntPtr.Zero, - options, palette, red_mask, green_mask, blue_mask); - } - } - - /// - /// Converts a FreeImage bitmap to a .NET . - /// - /// Handle to a FreeImage bitmap. - /// The converted .NET . - /// Copying metadata has been disabled until a proper way - /// of reading and storing metadata in a .NET bitmap is found. - /// - /// is null. - /// - /// The image type of is not FIT_BITMAP. - public static Bitmap GetBitmap(FIBITMAP dib) - { - return GetBitmap(dib, true); - } - - /// - /// Converts a FreeImage bitmap to a .NET . - /// - /// Handle to a FreeImage bitmap. - /// When true existing metadata will be copied. - /// The converted .NET . - /// Copying metadata has been disabled until a proper way - /// of reading and storing metadata in a .NET bitmap is found. - /// - /// is null. - /// - /// The image type of is not FIT_BITMAP. - internal static Bitmap GetBitmap(FIBITMAP dib, bool copyMetadata) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - if (GetImageType(dib) != FREE_IMAGE_TYPE.FIT_BITMAP) - { - throw new ArgumentException("Only bitmaps with type of FIT_BITMAP can be converted."); - } - - PixelFormat format = GetPixelFormat(dib); - - if ((format == PixelFormat.Undefined) && (GetBPP(dib) == 16u)) - { - throw new ArgumentException("Only 16bit 555 and 565 are supported."); - } - - int height = (int)GetHeight(dib); - int width = (int)GetWidth(dib); - int pitch = (int)GetPitch(dib); - - Bitmap result = new Bitmap(width, height, format); - BitmapData data; - // Locking the complete bitmap in writeonly mode - data = result.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, format); - // Writing the bitmap data directly into the new created .NET bitmap. - ConvertToRawBits(data.Scan0, dib, pitch, GetBPP(dib), - GetRedMask(dib), GetGreenMask(dib), GetBlueMask(dib), true); - // Unlock the bitmap - result.UnlockBits(data); - // Apply the bitmap resolution - if((GetResolutionX(dib) > 0) && (GetResolutionY(dib) > 0)) - { - // SetResolution will throw an exception when zero values are given on input - result.SetResolution(GetResolutionX(dib), GetResolutionY(dib)); - } - // Check whether the bitmap has a palette - if (GetPalette(dib) != IntPtr.Zero) - { - // Get the bitmaps palette to apply changes - ColorPalette palette = result.Palette; - // Get the orgininal palette - Color[] colorPalette = new Palette(dib).ColorData; - // Get the maximum number of palette entries to copy - int entriesToCopy = Math.Min(colorPalette.Length, palette.Entries.Length); - - // Check whether the bitmap is transparent - if (IsTransparent(dib)) - { - byte[] transTable = GetTransparencyTableEx(dib); - int i = 0; - int maxEntriesWithTrans = Math.Min(entriesToCopy, transTable.Length); - // Copy palette entries and include transparency - for (; i < maxEntriesWithTrans; i++) - { - palette.Entries[i] = Color.FromArgb(transTable[i], colorPalette[i]); - } - // Copy palette entries and that have no transparancy - for (; i < entriesToCopy; i++) - { - palette.Entries[i] = Color.FromArgb(0xFF, colorPalette[i]); - } - } - else - { - for (int i = 0; i < entriesToCopy; i++) - { - palette.Entries[i] = colorPalette[i]; - } - } - - // Set the bitmaps palette - result.Palette = palette; - } - // Copy metadata - if (copyMetadata) - { - try - { - List list = new List(); - // Get a list of all types - FITAG tag; - FIMETADATA mData; - foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS) - { - // Get a unique search handle - mData = FindFirstMetadata(model, dib, out tag); - // Check if metadata exists for this type - if (mData.IsNull) continue; - do - { - PropertyItem propItem = CreatePropertyItem(); - propItem.Len = (int)GetTagLength(tag); - propItem.Id = (int)GetTagID(tag); - propItem.Type = (short)GetTagType(tag); - byte[] buffer = new byte[propItem.Len]; - - unsafe - { - byte* src = (byte*)GetTagValue(tag); - fixed (byte* dst = buffer) - { - CopyMemory(dst, src, (uint)propItem.Len); - } - } - - propItem.Value = buffer; - list.Add(propItem); - } - while (FindNextMetadata(mData, out tag)); - FindCloseMetadata(mData); - } - foreach (PropertyItem propItem in list) - { - result.SetPropertyItem(propItem); - } - } - catch - { - } - } - return result; - } - - /// - /// Converts an .NET into a FreeImage bitmap. - /// - /// The to convert. - /// Handle to a FreeImage bitmap. - /// Copying metadata has been disabled until a proper way - /// of reading and storing metadata in a .NET bitmap is found. - /// - /// is null. - /// - /// The bitmaps pixelformat is invalid. - public static FIBITMAP CreateFromBitmap(Bitmap bitmap) - { - return CreateFromBitmap(bitmap, false); - } - - /// - /// Converts an .NET into a FreeImage bitmap. - /// - /// The to convert. - /// When true existing metadata will be copied. - /// Handle to a FreeImage bitmap. - /// Copying metadata has been disabled until a proper way - /// of reading and storing metadata in a .NET bitmap is found. - /// - /// is null. - /// - /// The bitmaps pixelformat is invalid. - internal static FIBITMAP CreateFromBitmap(Bitmap bitmap, bool copyMetadata) - { - if (bitmap == null) - { - throw new ArgumentNullException("bitmap"); - } - uint bpp, red_mask, green_mask, blue_mask; - FREE_IMAGE_TYPE type; - if (!GetFormatParameters(bitmap.PixelFormat, out type, out bpp, out red_mask, out green_mask, out blue_mask)) - { - throw new ArgumentException("The bitmaps pixelformat is invalid."); - } - - // Locking the complete bitmap in readonly mode - BitmapData data = bitmap.LockBits( - new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat); - // Copying the bitmap data directly from the .NET bitmap - FIBITMAP result = ConvertFromRawBits( - data.Scan0, - type, - data.Width, - data.Height, - data.Stride, - bpp, - red_mask, - green_mask, - blue_mask, - true); - bitmap.UnlockBits(data); - // Handle palette - if (GetPalette(result) != IntPtr.Zero) - { - Palette palette = new Palette(result); - Color[] colors = bitmap.Palette.Entries; - // Only copy available palette entries - int entriesToCopy = Math.Min(palette.Length, colors.Length); - byte[] transTable = new byte[entriesToCopy]; - for (int i = 0; i < entriesToCopy; i++) - { - RGBQUAD color = (RGBQUAD)colors[i]; - color.rgbReserved = 0x00; - palette[i] = color; - transTable[i] = colors[i].A; - } - if ((bitmap.Flags & (int)ImageFlags.HasAlpha) != 0) - { - FreeImage.SetTransparencyTable(result, transTable); - } - } - // Handle meta data - // Disabled - //if (copyMetadata) - //{ - // foreach (PropertyItem propItem in bitmap.PropertyItems) - // { - // FITAG tag = CreateTag(); - // SetTagLength(tag, (uint)propItem.Len); - // SetTagID(tag, (ushort)propItem.Id); - // SetTagType(tag, (FREE_IMAGE_MDTYPE)propItem.Type); - // SetTagValue(tag, propItem.Value); - // SetMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, result, "", tag); - // } - //} - return result; - } - - /// - /// Converts a raw bitmap to a FreeImage bitmap. - /// - /// Array of bytes containing the raw bitmap. - /// The type of the raw bitmap. - /// The width in pixels of the raw bitmap. - /// The height in pixels of the raw bitmap. - /// Defines the total width of a scanline in the raw bitmap, - /// including padding bytes. - /// The bit depth (bits per pixel) of the raw bitmap. - /// The bit mask describing the bits used to store a single - /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// If true, the raw bitmap is stored in top-down order (top-left pixel first) - /// and in bottom-up order (bottom-left pixel first) otherwise. - /// Handle to a FreeImage bitmap. - public static unsafe FIBITMAP ConvertFromRawBits( - byte[] bits, - FREE_IMAGE_TYPE type, - int width, - int height, - int pitch, - uint bpp, - uint red_mask, - uint green_mask, - uint blue_mask, - bool topdown) - { - fixed (byte* ptr = bits) - { - return ConvertFromRawBits( - (IntPtr)ptr, - type, - width, - height, - pitch, - bpp, - red_mask, - green_mask, - blue_mask, - topdown); - } - } - - /// - /// Converts a raw bitmap to a FreeImage bitmap. - /// - /// Pointer to the memory block containing the raw bitmap. - /// The type of the raw bitmap. - /// The width in pixels of the raw bitmap. - /// The height in pixels of the raw bitmap. - /// Defines the total width of a scanline in the raw bitmap, - /// including padding bytes. - /// The bit depth (bits per pixel) of the raw bitmap. - /// The bit mask describing the bits used to store a single - /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// If true, the raw bitmap is stored in top-down order (top-left pixel first) - /// and in bottom-up order (bottom-left pixel first) otherwise. - /// Handle to a FreeImage bitmap. - public static unsafe FIBITMAP ConvertFromRawBits( - IntPtr bits, - FREE_IMAGE_TYPE type, - int width, - int height, - int pitch, - uint bpp, - uint red_mask, - uint green_mask, - uint blue_mask, - bool topdown) - { - byte* addr = (byte*)bits; - if ((addr == null) || (width <= 0) || (height <= 0)) - { - return FIBITMAP.Zero; - } - - FIBITMAP dib = AllocateT(type, width, height, (int)bpp, red_mask, green_mask, blue_mask); - if (dib != FIBITMAP.Zero) - { - if (topdown) - { - for (int i = height - 1; i >= 0; --i) - { - CopyMemory((byte*)GetScanLine(dib, i), addr, (int)GetLine(dib)); - addr += pitch; - } - } - else - { - for (int i = 0; i < height; ++i) - { - CopyMemory((byte*)GetScanLine(dib, i), addr, (int)GetLine(dib)); - addr += pitch; - } - } - } - return dib; - } - - /// - /// Saves a .NET to a file. - /// - /// The .NET to save. - /// Name of the file to save to. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// The bitmaps pixelformat is invalid. - public static bool SaveBitmap(Bitmap bitmap, string filename) - { - return SaveBitmap( - bitmap, - filename, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - /// - /// Saves a .NET to a file. - /// - /// The .NET to save. - /// Name of the file to save to. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// The bitmaps pixelformat is invalid. - public static bool SaveBitmap(Bitmap bitmap, string filename, FREE_IMAGE_SAVE_FLAGS flags) - { - return SaveBitmap( - bitmap, - filename, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - flags); - } - - /// - /// Saves a .NET to a file. - /// - /// The .NET to save. - /// Name of the file to save to. - /// Format of the bitmap. If the format should be taken from the - /// filename use . - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// The bitmaps pixelformat is invalid. - public static bool SaveBitmap( - Bitmap bitmap, - string filename, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_SAVE_FLAGS flags) - { - FIBITMAP dib = CreateFromBitmap(bitmap); - bool result = SaveEx(dib, filename, format, flags); - Unload(dib); - return result; - } - - /// - /// Loads a FreeImage bitmap. - /// The file will be loaded with default loading flags. - /// - /// The complete name of the file to load. - /// Handle to a FreeImage bitmap. - /// - /// does not exists. - public static FIBITMAP LoadEx(string filename) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return LoadEx(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); - } - - /// - /// Loads a FreeImage bitmap. - /// Load flags can be provided by the flags parameter. - /// - /// The complete name of the file to load. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage bitmap. - /// - /// does not exists. - public static FIBITMAP LoadEx(string filename, FREE_IMAGE_LOAD_FLAGS flags) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return LoadEx(filename, flags, ref format); - } - - /// - /// Loads a FreeImage bitmap. - /// In case the loading format is the files - /// real format is being analysed. If no plugin can read the file, format remains - /// and 0 is returned. - /// The file will be loaded with default loading flags. - /// - /// The complete name of the file to load. - /// Format of the image. If the format is unknown use - /// . - /// In case a suitable format was found by LoadEx it will be returned in format. - /// Handle to a FreeImage bitmap. - /// - /// does not exists. - public static FIBITMAP LoadEx(string filename, ref FREE_IMAGE_FORMAT format) - { - return LoadEx(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); - } - - /// - /// Loads a FreeImage bitmap. - /// In case the loading format is the files - /// real format is being analysed. If no plugin can read the file, format remains - /// and 0 is returned. - /// Load flags can be provided by the flags parameter. - /// - /// The complete name of the file to load. - /// Flags to enable or disable plugin-features. - /// Format of the image. If the format is unknown use - /// . - /// In case a suitable format was found by LoadEx it will be returned in format. - /// - /// Handle to a FreeImage bitmap. - /// - /// does not exists. - public static FIBITMAP LoadEx(string filename, FREE_IMAGE_LOAD_FLAGS flags, ref FREE_IMAGE_FORMAT format) - { - // check if file exists - if (!File.Exists(filename)) - { - throw new FileNotFoundException(filename + " could not be found."); - } - FIBITMAP dib = new FIBITMAP(); - if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) - { - // query all plugins to see if one can read the file - format = GetFileType(filename, 0); - } - // check if the plugin is capable of loading files - if (FIFSupportsReading(format)) - { - dib = Load(format, filename, flags); - } - return dib; - } - - /// - /// Loads a .NET from a file. - /// - /// Name of the file to be loaded. - /// Format of the image. If the format should be taken from the - /// filename use . - /// Flags to enable or disable plugin-features. - /// The loaded .NET . - /// - /// does not exists. - /// - /// The image type of the image is not . - public static Bitmap LoadBitmap(string filename, FREE_IMAGE_LOAD_FLAGS flags, ref FREE_IMAGE_FORMAT format) - { - FIBITMAP dib = LoadEx(filename, flags, ref format); - Bitmap result = GetBitmap(dib, true); - Unload(dib); - return result; - } - - /// - /// Deletes a previously loaded FreeImage bitmap from memory and resets the handle to 0. - /// - /// Handle to a FreeImage bitmap. - public static void UnloadEx(ref FIBITMAP dib) - { - if (!dib.IsNull) - { - Unload(dib); - dib.SetNull(); - } - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// The format is taken off the filename. - /// If no suitable format was found false will be returned. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified. - /// Returns true on success, false on failure. - /// - /// or is null. - public static bool SaveEx(FIBITMAP dib, string filename) - { - return SaveEx( - ref dib, - filename, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - FREE_IMAGE_SAVE_FLAGS.DEFAULT, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - false); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// In case the loading format is - /// the format is taken off the filename. - /// If no suitable format was found false will be returned. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified. - /// Format of the image. If the format should be taken from the - /// filename use . - /// Returns true on success, false on failure. - /// - /// or is null. - public static bool SaveEx( - FIBITMAP dib, - string filename, - FREE_IMAGE_FORMAT format) - { - return SaveEx( - ref dib, - filename, - format, - FREE_IMAGE_SAVE_FLAGS.DEFAULT, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - false); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// The format is taken off the filename. - /// If no suitable format was found false will be returned. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified. - /// When true the structure will be unloaded on success. - /// If the function failed and returned false, the bitmap was not unloaded. - /// Returns true on success, false on failure. - /// - /// or is null. - public static bool SaveEx( - ref FIBITMAP dib, - string filename, - bool unloadSource) - { - return SaveEx( - ref dib, - filename, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - FREE_IMAGE_SAVE_FLAGS.DEFAULT, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - unloadSource); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// The format is taken off the filename. - /// If no suitable format was found false will be returned. - /// Save flags can be provided by the flags parameter. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - /// - /// or is null. - public static bool SaveEx( - FIBITMAP dib, - string filename, - FREE_IMAGE_SAVE_FLAGS flags) - { - return SaveEx( - ref dib, - filename, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - flags, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - false); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// The format is taken off the filename. - /// If no suitable format was found false will be returned. - /// Save flags can be provided by the flags parameter. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified. - /// Flags to enable or disable plugin-features. - /// When true the structure will be unloaded on success. - /// If the function failed and returned false, the bitmap was not unloaded. - /// Returns true on success, false on failure. - /// - /// or is null. - public static bool SaveEx( - ref FIBITMAP dib, - string filename, - FREE_IMAGE_SAVE_FLAGS flags, - bool unloadSource) - { - return SaveEx( - ref dib, - filename, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - flags, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - unloadSource); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// In case the loading format is - /// the format is taken off the filename. - /// If no suitable format was found false will be returned. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified. - /// Format of the image. If the format should be taken from the - /// filename use . - /// When true the structure will be unloaded on success. - /// If the function failed and returned false, the bitmap was not unloaded. - /// Returns true on success, false on failure. - /// - /// or is null. - public static bool SaveEx( - ref FIBITMAP dib, - string filename, - FREE_IMAGE_FORMAT format, - bool unloadSource) - { - return SaveEx( - ref dib, - filename, - format, - FREE_IMAGE_SAVE_FLAGS.DEFAULT, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - unloadSource); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// In case the loading format is - /// the format is taken off the filename. - /// If no suitable format was found false will be returned. - /// Save flags can be provided by the flags parameter. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified. - /// Format of the image. If the format should be taken from the - /// filename use . - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - /// - /// or is null. - public static bool SaveEx( - FIBITMAP dib, - string filename, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_SAVE_FLAGS flags) - { - return SaveEx( - ref dib, - filename, - format, - flags, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - false); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// In case the loading format is - /// the format is taken off the filename. - /// If no suitable format was found false will be returned. - /// Save flags can be provided by the flags parameter. - /// The bitmaps color depth can be set by 'colorDepth'. - /// If set to a suitable color depth - /// will be taken if available. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified. - /// Format of the image. If the format should be taken from the - /// filename use . - /// Flags to enable or disable plugin-features. - /// The new color depth of the bitmap. - /// Set to if Save should take the - /// best suitable color depth. - /// If a color depth is selected that the provided format cannot write an - /// error-message will be thrown. - /// When true the structure will be unloaded on success. - /// If the function failed and returned false, the bitmap was not unloaded. - /// Returns true on success, false on failure. - /// - /// A direct color conversion failed. - /// - /// or is null. - public static bool SaveEx( - ref FIBITMAP dib, - string filename, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_SAVE_FLAGS flags, - FREE_IMAGE_COLOR_DEPTH colorDepth, - bool unloadSource) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - if (filename == null) - { - throw new ArgumentNullException("filename"); - } - bool result = false; - // Gets format from filename if the format is unknown - if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) - { - format = GetFIFFromFilename(filename); - } - if (format != FREE_IMAGE_FORMAT.FIF_UNKNOWN) - { - // Checks writing support - if (FIFSupportsWriting(format) && FIFSupportsExportType(format, GetImageType(dib))) - { - // Check valid filename and correct it if needed - if (!IsFilenameValidForFIF(format, filename)) - { - string extension = GetPrimaryExtensionFromFIF(format); - filename = Path.ChangeExtension(filename, extension); - } - - FIBITMAP dibToSave = PrepareBitmapColorDepth(dib, format, colorDepth); - try - { - result = Save(format, dibToSave, filename, flags); - } - finally - { - // Always unload a temporary created bitmap. - if (dibToSave != dib) - { - UnloadEx(ref dibToSave); - } - // On success unload the bitmap - if (result && unloadSource) - { - UnloadEx(ref dib); - } - } - } - } - return result; - } - - /// - /// Loads a FreeImage bitmap. - /// The stream must be set to the correct position before calling LoadFromStream. - /// - /// The stream to read from. - /// Handle to a FreeImage bitmap. - /// - /// is null. - /// - /// is not capable of reading. - public static FIBITMAP LoadFromStream(Stream stream) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return LoadFromStream(stream, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); - } - - /// - /// Loads a FreeImage bitmap. - /// The stream must be set to the correct position before calling LoadFromStream. - /// - /// The stream to read from. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage bitmap. - /// - /// is null. - /// - /// is not capable of reading. - public static FIBITMAP LoadFromStream(Stream stream, FREE_IMAGE_LOAD_FLAGS flags) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return LoadFromStream(stream, flags, ref format); - } - - /// - /// Loads a FreeImage bitmap. - /// In case the loading format is the - /// bitmaps real format is being analysed. - /// The stream must be set to the correct position before calling LoadFromStream. - /// - /// The stream to read from. - /// Format of the image. If the format is unknown use - /// . - /// In case a suitable format was found by LoadFromStream it will be returned in format. - /// Handle to a FreeImage bitmap. - /// - /// is null. - /// - /// is not capable of reading. - public static FIBITMAP LoadFromStream(Stream stream, ref FREE_IMAGE_FORMAT format) - { - return LoadFromStream(stream, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); - } - - /// - /// Loads a FreeImage bitmap. - /// In case the loading format is - /// the bitmaps real format is being analysed. - /// The stream must be set to the correct position before calling LoadFromStream. - /// - /// The stream to read from. - /// Flags to enable or disable plugin-features. - /// Format of the image. If the format is unknown use - /// . - /// In case a suitable format was found by LoadFromStream it will be returned in format. - /// Handle to a FreeImage bitmap. - /// - /// is null. - /// - /// is not capable of reading. - public static FIBITMAP LoadFromStream( - Stream stream, - FREE_IMAGE_LOAD_FLAGS flags, - ref FREE_IMAGE_FORMAT format) - { - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - if (!stream.CanRead) - { - throw new ArgumentException("stream is not capable of reading."); - } - // Wrap the source stream if it is unable to seek (which is required by FreeImage) - stream = (stream.CanSeek) ? stream : new StreamWrapper(stream, true); - - stream.Position = 0L; - if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) - { - // Get the format of the bitmap - format = GetFileTypeFromStream(stream); - // Restore the streams position - stream.Position = 0L; - } - if (!FIFSupportsReading(format)) - { - return FIBITMAP.Zero; - } - // Create a 'FreeImageIO' structure for calling 'LoadFromHandle' - // using the internal structure 'FreeImageStreamIO'. - FreeImageIO io = FreeImageStreamIO.io; - using (fi_handle handle = new fi_handle(stream)) - { - return LoadFromHandle(format, ref io, handle, flags); - } - } - - /// - /// Saves a previously loaded FreeImage bitmap to a stream. - /// The stream must be set to the correct position before calling SaveToStream. - /// - /// Handle to a FreeImage bitmap. - /// The stream to write to. - /// Format of the image. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// cannot write. - public static bool SaveToStream( - FIBITMAP dib, - Stream stream, - FREE_IMAGE_FORMAT format) - { - return SaveToStream( - ref dib, - stream, - format, - FREE_IMAGE_SAVE_FLAGS.DEFAULT, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - false); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a stream. - /// The stream must be set to the correct position before calling SaveToStream. - /// - /// Handle to a FreeImage bitmap. - /// The stream to write to. - /// Format of the image. - /// When true the structure will be unloaded on success. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// cannot write. - public static bool SaveToStream( - ref FIBITMAP dib, - Stream stream, - FREE_IMAGE_FORMAT format, - bool unloadSource) - { - return SaveToStream( - ref dib, - stream, - format, - FREE_IMAGE_SAVE_FLAGS.DEFAULT, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - unloadSource); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a stream. - /// The stream must be set to the correct position before calling SaveToStream. - /// - /// Handle to a FreeImage bitmap. - /// The stream to write to. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// cannot write. - public static bool SaveToStream( - FIBITMAP dib, - Stream stream, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_SAVE_FLAGS flags) - { - return SaveToStream( - ref dib, - stream, - format, - flags, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - false); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a stream. - /// The stream must be set to the correct position before calling SaveToStream. - /// - /// Handle to a FreeImage bitmap. - /// The stream to write to. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// When true the structure will be unloaded on success. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// cannot write. - public static bool SaveToStream( - ref FIBITMAP dib, - Stream stream, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_SAVE_FLAGS flags, - bool unloadSource) - { - return SaveToStream( - ref dib, stream, - format, - flags, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - unloadSource); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a stream. - /// The stream must be set to the correct position before calling SaveToStream. - /// - /// Handle to a FreeImage bitmap. - /// The stream to write to. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// The new color depth of the bitmap. - /// Set to if SaveToStream should - /// take the best suitable color depth. - /// If a color depth is selected that the provided format cannot write an - /// error-message will be thrown. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// cannot write. - public static bool SaveToStream( - FIBITMAP dib, - Stream stream, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_SAVE_FLAGS flags, - FREE_IMAGE_COLOR_DEPTH colorDepth) - { - return SaveToStream( - ref dib, - stream, - format, - flags, - colorDepth, - false); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a stream. - /// The stream must be set to the correct position before calling SaveToStream. - /// - /// Handle to a FreeImage bitmap. - /// The stream to write to. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// The new color depth of the bitmap. - /// Set to if SaveToStream should - /// take the best suitable color depth. - /// If a color depth is selected that the provided format cannot write an - /// error-message will be thrown. - /// When true the structure will be unloaded on success. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// cannot write. - public static bool SaveToStream( - ref FIBITMAP dib, - Stream stream, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_SAVE_FLAGS flags, - FREE_IMAGE_COLOR_DEPTH colorDepth, - bool unloadSource) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - if (!stream.CanWrite) - { - throw new ArgumentException("stream is not capable of writing."); - } - if ((!FIFSupportsWriting(format)) || (!FIFSupportsExportType(format, GetImageType(dib)))) - { - return false; - } - - FIBITMAP dibToSave = PrepareBitmapColorDepth(dib, format, colorDepth); - bool result = false; - - try - { - // Create a 'FreeImageIO' structure for calling 'SaveToHandle' - FreeImageIO io = FreeImageStreamIO.io; - - using (fi_handle handle = new fi_handle(stream)) - { - result = SaveToHandle(format, dibToSave, ref io, handle, flags); - } - } - finally - { - // Always unload a temporary created bitmap. - if (dibToSave != dib) - { - UnloadEx(ref dibToSave); - } - // On success unload the bitmap - if (result && unloadSource) - { - UnloadEx(ref dib); - } - } - - return result; - } - - #endregion - - #region Plugin functions - - /// - /// Checks if an extension is valid for a certain format. - /// - /// The desired format. - /// The desired extension. - /// True if the extension is valid for the given format, false otherwise. - /// - /// is null. - public static bool IsExtensionValidForFIF(FREE_IMAGE_FORMAT fif, string extension) - { - return IsExtensionValidForFIF(fif, extension, StringComparison.CurrentCultureIgnoreCase); - } - - /// - /// Checks if an extension is valid for a certain format. - /// - /// The desired format. - /// The desired extension. - /// The string comparison type. - /// True if the extension is valid for the given format, false otherwise. - /// - /// is null. - public static bool IsExtensionValidForFIF(FREE_IMAGE_FORMAT fif, string extension, StringComparison comparisonType) - { - if (extension == null) - { - throw new ArgumentNullException("extension"); - } - bool result = false; - // Split up the string and compare each with the given extension - string tempList = GetFIFExtensionList(fif); - if (tempList != null) - { - string[] extensionList = tempList.Split(','); - foreach (string ext in extensionList) - { - if (extension.Equals(ext, comparisonType)) - { - result = true; - break; - } - } - } - return result; - } - - /// - /// Checks if a filename is valid for a certain format. - /// - /// The desired format. - /// The desired filename. - /// True if the filename is valid for the given format, false otherwise. - /// - /// is null. - public static bool IsFilenameValidForFIF(FREE_IMAGE_FORMAT fif, string filename) - { - return IsFilenameValidForFIF(fif, filename, StringComparison.CurrentCultureIgnoreCase); - } - - /// - /// Checks if a filename is valid for a certain format. - /// - /// The desired format. - /// The desired filename. - /// The string comparison type. - /// True if the filename is valid for the given format, false otherwise. - /// - /// is null. - public static bool IsFilenameValidForFIF(FREE_IMAGE_FORMAT fif, string filename, StringComparison comparisonType) - { - if (filename == null) - { - throw new ArgumentNullException("filename"); - } - bool result = false; - // Extract the filenames extension if it exists - string extension = Path.GetExtension(filename); - if (extension.Length != 0) - { - extension = extension.Remove(0, 1); - result = IsExtensionValidForFIF(fif, extension, comparisonType); - } - return result; - } - - /// - /// This function returns the primary (main or most commonly used?) extension of a certain - /// image format (fif). This is done by returning the first of all possible extensions - /// returned by GetFIFExtensionList(). - /// That assumes, that the plugin returns the extensions in ordered form. - /// The image format to obtain the primary extension for. - /// The primary extension of the specified image format. - public static string GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT fif) - { - string result = null; - string extensions = GetFIFExtensionList(fif); - if (extensions != null) - { - int position = extensions.IndexOf(','); - if (position < 0) - { - result = extensions; - } - else - { - result = extensions.Substring(0, position); - } - } - return result; - } - - #endregion - - #region Multipage functions - - /// - /// Loads a FreeImage multi-paged bitmap. - /// - /// The complete name of the file to load. - /// Handle to a FreeImage multi-paged bitmap. - /// - /// does not exists while opening. - public static FIMULTIBITMAP OpenMultiBitmapEx(string filename) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return OpenMultiBitmapEx( - filename, - ref format, - FREE_IMAGE_LOAD_FLAGS.DEFAULT, - false, - false, - false); - } - - /// - /// Loads a FreeImage multi-paged bitmap. - /// - /// The complete name of the file to load. - /// When true performance is increased at the cost of memory. - /// Handle to a FreeImage multi-paged bitmap. - /// - /// does not exists while opening. - public static FIMULTIBITMAP OpenMultiBitmapEx(string filename, bool keep_cache_in_memory) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return OpenMultiBitmapEx( - filename, - ref format, - FREE_IMAGE_LOAD_FLAGS.DEFAULT, - false, - false, - keep_cache_in_memory); - } - - /// - /// Loads a FreeImage multi-paged bitmap. - /// - /// The complete name of the file to load. - /// When true the bitmap will be loaded read only. - /// When true performance is increased at the cost of memory. - /// Handle to a FreeImage multi-paged bitmap. - /// - /// does not exists while opening. - public static FIMULTIBITMAP OpenMultiBitmapEx( - string filename, - bool read_only, - bool keep_cache_in_memory) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return OpenMultiBitmapEx( - filename, - ref format, - FREE_IMAGE_LOAD_FLAGS.DEFAULT, - false, - read_only, - keep_cache_in_memory); - } - - /// - /// Loads a FreeImage multi-paged bitmap. - /// - /// The complete name of the file to load. - /// When true a new bitmap is created. - /// When true the bitmap will be loaded read only. - /// When true performance is increased at the cost of memory. - /// Handle to a FreeImage multi-paged bitmap. - /// - /// does not exists while opening. - public static FIMULTIBITMAP OpenMultiBitmapEx( - string filename, - bool create_new, - bool read_only, - bool keep_cache_in_memory) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return OpenMultiBitmapEx( - filename, - ref format, - FREE_IMAGE_LOAD_FLAGS.DEFAULT, - create_new, - read_only, - keep_cache_in_memory); - } - - /// - /// Loads a FreeImage multi-paged bitmap. - /// In case the loading format is the files real - /// format is being analysed. If no plugin can read the file, format remains - /// and 0 is returned. - /// - /// The complete name of the file to load. - /// Format of the image. If the format is unknown use - /// . - /// In case a suitable format was found by LoadEx it will be returned in format. - /// When true a new bitmap is created. - /// When true the bitmap will be loaded read only. - /// When true performance is increased at the cost of memory. - /// Handle to a FreeImage multi-paged bitmap. - /// - /// does not exists while opening. - public static FIMULTIBITMAP OpenMultiBitmapEx( - string filename, - ref FREE_IMAGE_FORMAT format, - bool create_new, - bool read_only, - bool keep_cache_in_memory) - { - return OpenMultiBitmapEx( - filename, - ref format, - FREE_IMAGE_LOAD_FLAGS.DEFAULT, - create_new, - read_only, - keep_cache_in_memory); - } - - /// - /// Loads a FreeImage multi-paged bitmap. - /// In case the loading format is the files - /// real format is being analysed. If no plugin can read the file, format remains - /// and 0 is returned. - /// Load flags can be provided by the flags parameter. - /// - /// The complete name of the file to load. - /// Format of the image. If the format is unknown use - /// . - /// In case a suitable format was found by LoadEx it will be returned in format. - /// Flags to enable or disable plugin-features. - /// When true a new bitmap is created. - /// When true the bitmap will be loaded read only. - /// When true performance is increased at the cost of memory. - /// Handle to a FreeImage multi-paged bitmap. - /// - /// does not exists while opening. - public static FIMULTIBITMAP OpenMultiBitmapEx( - string filename, - ref FREE_IMAGE_FORMAT format, - FREE_IMAGE_LOAD_FLAGS flags, - bool create_new, - bool read_only, - bool keep_cache_in_memory) - { - if (!File.Exists(filename) && !create_new) - { - throw new FileNotFoundException(filename + " could not be found."); - } - if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) - { - // Check if a plugin can read the data - format = GetFileType(filename, 0); - } - FIMULTIBITMAP dib = new FIMULTIBITMAP(); - if (FIFSupportsReading(format)) - { - dib = OpenMultiBitmap(format, filename, create_new, read_only, keep_cache_in_memory, flags); - } - return dib; - } - - /// - /// Loads a FreeImage multi-paged bitmap. - /// - /// The stream to load the bitmap from. - /// Handle to a FreeImage multi-paged bitmap. - public static FIMULTIBITMAP OpenMultiBitmapFromStream(Stream stream) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return OpenMultiBitmapFromStream(stream, ref format, FREE_IMAGE_LOAD_FLAGS.DEFAULT); - } - - /// - /// Loads a FreeImage multi-paged bitmap. - /// In case the loading format is the files - /// real format is being analysed. If no plugin can read the file, format remains - /// and 0 is returned. - /// Load flags can be provided by the flags parameter. - /// - /// The stream to load the bitmap from. - /// Format of the image. If the format is unknown use - /// . - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage multi-paged bitmap. - public static FIMULTIBITMAP OpenMultiBitmapFromStream(Stream stream, ref FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) - { - if (stream == null) - return FIMULTIBITMAP.Zero; - - if (!stream.CanSeek) - stream = new StreamWrapper(stream, true); - - FIMULTIBITMAP mdib = FIMULTIBITMAP.Zero; - FreeImageIO io = FreeImageStreamIO.io; - fi_handle handle = new fi_handle(stream); - - try - { - if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) - { - format = GetFileTypeFromHandle(ref io, handle, checked((int)stream.Length)); - } - - mdib = OpenMultiBitmapFromHandle(format, ref io, handle, flags); - - if (mdib.IsNull) - { - handle.Dispose(); - } - else - { - lock (streamHandles) - { - streamHandles.Add(mdib, handle); - } - } - - return mdib; - } - catch - { - if (!mdib.IsNull) - CloseMultiBitmap(mdib, FREE_IMAGE_SAVE_FLAGS.DEFAULT); - - if (handle != null) - handle.Dispose(); - - throw; - } - } - - /// - /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, applies any changes made to it. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - public static bool CloseMultiBitmap(FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags) - { - if (CloseMultiBitmap_(bitmap, flags)) - { - fi_handle handle; - lock (streamHandles) - { - if (streamHandles.TryGetValue(bitmap, out handle)) - { - streamHandles.Remove(bitmap); - handle.Dispose(); - } - } - return true; - } - return false; - } - - /// - /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, - /// applies any changes made to it. - /// On success the handle will be reset to null. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Returns true on success, false on failure. - public static bool CloseMultiBitmapEx(ref FIMULTIBITMAP bitmap) - { - return CloseMultiBitmapEx(ref bitmap, FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - /// - /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, - /// applies any changes made to it. - /// On success the handle will be reset to null. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - public static bool CloseMultiBitmapEx(ref FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags) - { - bool result = false; - if (!bitmap.IsNull) - { - if (CloseMultiBitmap(bitmap, flags)) - { - bitmap.SetNull(); - result = true; - } - } - return result; - } - - /// - /// Retrieves the number of pages that are locked in a multi-paged bitmap. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Number of locked pages. - /// - /// is null. - public static int GetLockedPageCount(FIMULTIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - int result = 0; - GetLockedPageNumbers(dib, null, ref result); - return result; - } - - /// - /// Retrieves a list locked pages of a multi-paged bitmap. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// List containing the indexes of the locked pages. - /// - /// is null. - public static int[] GetLockedPages(FIMULTIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - // Get the number of pages and create an array to save the information - int count = 0; - int[] result = null; - // Get count - if (GetLockedPageNumbers(dib, result, ref count)) - { - result = new int[count]; - // Fill array - if (!GetLockedPageNumbers(dib, result, ref count)) - { - result = null; - } - } - return result; - } - - /// - /// Loads a FreeImage multi-paged bitmap from a stream and returns the - /// FreeImage memory stream used as temporary buffer. - /// The bitmap can not be modified by calling - /// , - /// , - /// or - /// . - /// - /// The stream to read from. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// The temporary memory buffer used to load the bitmap. - /// Handle to a FreeImage multi-paged bitmap. - /// - /// is null. - /// - /// can not read. - public static FIMULTIBITMAP LoadMultiBitmapFromStream( - Stream stream, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_LOAD_FLAGS flags, - out FIMEMORY memory) - { - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - if (!stream.CanRead) - { - throw new ArgumentException("stream"); - } - const int blockSize = 1024; - int bytesRead; - byte[] buffer = new byte[blockSize]; - - stream = stream.CanSeek ? stream : new StreamWrapper(stream, true); - memory = OpenMemory(IntPtr.Zero, 0); - - do - { - bytesRead = stream.Read(buffer, 0, blockSize); - WriteMemory(buffer, (uint)blockSize, (uint)1, memory); - } - while (bytesRead == blockSize); - - return LoadMultiBitmapFromMemory(format, memory, flags); - } - - #endregion - - #region Filetype functions - - /// - /// Orders FreeImage to analyze the bitmap signature. - /// In case the stream is not seekable, the stream will have been used - /// and must be recreated for loading. - /// - /// Name of the stream to analyze. - /// Type of the bitmap. - /// - /// is null. - /// - /// can not read. - public static FREE_IMAGE_FORMAT GetFileTypeFromStream(Stream stream) - { - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - if (!stream.CanRead) - { - throw new ArgumentException("stream is not capable of reading."); - } - // Wrap the stream if it cannot seek - stream = (stream.CanSeek) ? stream : new StreamWrapper(stream, true); - // Create a 'FreeImageIO' structure for the stream - FreeImageIO io = FreeImageStreamIO.io; - using (fi_handle handle = new fi_handle(stream)) - { - return GetFileTypeFromHandle(ref io, handle, 0); - } - } - - #endregion - - #region Pixel access functions - - /// - /// Retrieves an hBitmap for a FreeImage bitmap. - /// Call FreeHbitmap(IntPtr) to free the handle. - /// - /// Handle to a FreeImage bitmap. - /// A reference device context. - /// Use IntPtr.Zero if no reference is available. - /// When true dib will be unloaded if the function succeeded. - /// The hBitmap for the FreeImage bitmap. - /// - /// is null. - public static unsafe IntPtr GetHbitmap(FIBITMAP dib, IntPtr hdc, bool unload) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - IntPtr hBitmap = IntPtr.Zero; - bool release = false; - IntPtr ppvBits = IntPtr.Zero; - // Check if we have destination - if (release = (hdc == IntPtr.Zero)) - { - // We don't so request dc - hdc = GetDC(IntPtr.Zero); - } - if (hdc != IntPtr.Zero) - { - // Get pointer to the infoheader of the bitmap - IntPtr info = GetInfo(dib); - // Create a bitmap in the dc - hBitmap = CreateDIBSection(hdc, info, DIB_RGB_COLORS, out ppvBits, IntPtr.Zero, 0); - if (hBitmap != IntPtr.Zero && ppvBits != IntPtr.Zero) - { - // Copy the data into the dc - CopyMemory(ppvBits, GetBits(dib), (GetHeight(dib) * GetPitch(dib))); - // Success: we unload the bitmap - if (unload) - { - Unload(dib); - } - } - // We have to release the dc - if (release) - { - ReleaseDC(IntPtr.Zero, hdc); - } - } - return hBitmap; - } - - /// - /// Returns an HBITMAP created by the CreateDIBitmap() function which in turn - /// has always the same color depth as the reference DC, which may be provided - /// through . The desktop DC will be used, - /// if IntPtr.Zero DC is specified. - /// Call to free the handle. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a device context. - /// When true the structure will be unloaded on success. - /// If the function failed and returned false, the bitmap was not unloaded. - /// If the function succeeds, the return value is a handle to the - /// compatible bitmap. If the function fails, the return value is . - /// - /// is null. - public static IntPtr GetBitmapForDevice(FIBITMAP dib, IntPtr hdc, bool unload) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - IntPtr hbitmap = IntPtr.Zero; - bool release = false; - if (release = (hdc == IntPtr.Zero)) - { - hdc = GetDC(IntPtr.Zero); - } - if (hdc != IntPtr.Zero) - { - hbitmap = CreateDIBitmap( - hdc, - GetInfoHeader(dib), - CBM_INIT, - GetBits(dib), - GetInfo(dib), - DIB_RGB_COLORS); - if (unload) - { - Unload(dib); - } - if (release) - { - ReleaseDC(IntPtr.Zero, hdc); - } - } - return hbitmap; - } - - /// - /// Creates a FreeImage DIB from a Device Context/Compatible Bitmap. - /// - /// Handle to the bitmap. - /// Handle to a device context. - /// Handle to a FreeImage bitmap. - /// - /// is null. - public unsafe static FIBITMAP CreateFromHbitmap(IntPtr hbitmap, IntPtr hdc) - { - if (hbitmap == IntPtr.Zero) - { - throw new ArgumentNullException("hbitmap"); - } - - FIBITMAP dib = new FIBITMAP(); - BITMAP bm; - uint colors; - bool release; - - if (GetObject(hbitmap, sizeof(BITMAP), (IntPtr)(&bm)) != 0) - { - dib = Allocate(bm.bmWidth, bm.bmHeight, bm.bmBitsPixel, 0, 0, 0); - if (!dib.IsNull) - { - colors = GetColorsUsed(dib); - if (release = (hdc == IntPtr.Zero)) - { - hdc = GetDC(IntPtr.Zero); - } - if (GetDIBits( - hdc, - hbitmap, - 0, - (uint)bm.bmHeight, - GetBits(dib), - GetInfo(dib), - DIB_RGB_COLORS) != 0) - { - if (colors != 0) - { - BITMAPINFOHEADER* bmih = (BITMAPINFOHEADER*)GetInfo(dib); - bmih[0].biClrImportant = bmih[0].biClrUsed = colors; - } - } - else - { - UnloadEx(ref dib); - } - if (release) - { - ReleaseDC(IntPtr.Zero, hdc); - } - } - } - - return dib; - } - - /// - /// Frees a bitmap handle. - /// - /// Handle to a bitmap. - /// True on success, false on failure. - public static bool FreeHbitmap(IntPtr hbitmap) - { - return DeleteObject(hbitmap); - } - - #endregion - - #region Bitmap information functions - - /// - /// Retrieves a DIB's resolution in X-direction measured in 'dots per inch' (DPI) and not in - /// 'dots per meter'. - /// - /// Handle to a FreeImage bitmap. - /// The resolution in 'dots per inch'. - /// - /// is null. - public static uint GetResolutionX(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - return (uint)(0.5d + 0.0254d * GetDotsPerMeterX(dib)); - } - - /// - /// Retrieves a DIB's resolution in Y-direction measured in 'dots per inch' (DPI) and not in - /// 'dots per meter'. - /// - /// Handle to a FreeImage bitmap. - /// The resolution in 'dots per inch'. - /// - /// is null. - public static uint GetResolutionY(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - return (uint)(0.5d + 0.0254d * GetDotsPerMeterY(dib)); - } - - /// - /// Sets a DIB's resolution in X-direction measured in 'dots per inch' (DPI) and not in - /// 'dots per meter'. - /// - /// Handle to a FreeImage bitmap. - /// The new resolution in 'dots per inch'. - /// - /// is null. - public static void SetResolutionX(FIBITMAP dib, uint res) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - SetDotsPerMeterX(dib, (uint)((double)res / 0.0254d + 0.5d)); - } - - /// - /// Sets a DIB's resolution in Y-direction measured in 'dots per inch' (DPI) and not in - /// 'dots per meter'. - /// - /// Handle to a FreeImage bitmap. - /// The new resolution in 'dots per inch'. - /// - /// is null. - public static void SetResolutionY(FIBITMAP dib, uint res) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - SetDotsPerMeterY(dib, (uint)((double)res / 0.0254d + 0.5d)); - } - - /// - /// Returns whether the image is a greyscale image or not. - /// The function scans all colors in the bitmaps palette for entries where - /// red, green and blue are not all the same (not a grey color). - /// Supports 1-, 4- and 8-bit bitmaps. - /// - /// Handle to a FreeImage bitmap. - /// True if the image is a greyscale image, else false. - /// - /// is null. - public static unsafe bool IsGreyscaleImage(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - bool result = true; - uint bpp = GetBPP(dib); - switch (bpp) - { - case 1: - case 4: - case 8: - RGBQUAD* palette = (RGBQUAD*)GetPalette(dib); - uint paletteLength = GetColorsUsed(dib); - for (int i = 0; i < paletteLength; i++) - { - if (palette[i].rgbRed != palette[i].rgbGreen || - palette[i].rgbRed != palette[i].rgbBlue) - { - result = false; - break; - } - } - break; - default: - result = false; - break; - } - return result; - } - - /// - /// Returns a structure that represents the palette of a FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// A structure representing the bitmaps palette. - /// - /// is null. - public static Palette GetPaletteEx(FIBITMAP dib) - { - return new Palette(dib); - } - - /// - /// Returns the structure of a FreeImage bitmap. - /// The structure is a copy, so changes will have no effect on - /// the bitmap itself. - /// - /// Handle to a FreeImage bitmap. - /// structure of the bitmap. - /// - /// is null. - public static unsafe BITMAPINFOHEADER GetInfoHeaderEx(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - return *(BITMAPINFOHEADER*)GetInfoHeader(dib); - } - - /// - /// Returns the structure of a FreeImage bitmap. - /// The structure is a copy, so changes will have no effect on - /// the bitmap itself. - /// - /// Handle to a FreeImage bitmap. - /// structure of the bitmap. - /// - /// is null. - public static BITMAPINFO GetInfoEx(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - BITMAPINFO result = new BITMAPINFO(); - result.bmiHeader = GetInfoHeaderEx(dib); - IntPtr ptr = GetPalette(dib); - if (ptr == IntPtr.Zero) - { - result.bmiColors = new RGBQUAD[0]; - } - else - { - result.bmiColors = new MemoryArray(ptr, (int)result.bmiHeader.biClrUsed).Data; - } - return result; - } - - /// - /// Returns the pixelformat of the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// of the bitmap. - /// - /// is null. - public static PixelFormat GetPixelFormat(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - - PixelFormat result = PixelFormat.Undefined; - - if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) - { - switch (GetBPP(dib)) - { - case 1: - result = PixelFormat.Format1bppIndexed; - break; - case 4: - result = PixelFormat.Format4bppIndexed; - break; - case 8: - result = PixelFormat.Format8bppIndexed; - break; - case 16: - if ((GetBlueMask(dib) == FI16_565_BLUE_MASK) && - (GetGreenMask(dib) == FI16_565_GREEN_MASK) && - (GetRedMask(dib) == FI16_565_RED_MASK)) - { - result = PixelFormat.Format16bppRgb565; - } - if ((GetBlueMask(dib) == FI16_555_BLUE_MASK) && - (GetGreenMask(dib) == FI16_555_GREEN_MASK) && - (GetRedMask(dib) == FI16_555_RED_MASK)) - { - result = PixelFormat.Format16bppRgb555; - } - break; - case 24: - result = PixelFormat.Format24bppRgb; - break; - case 32: - result = PixelFormat.Format32bppArgb; - break; - } - } - return result; - } - - /// - /// Retrieves all parameters needed to create a new FreeImage bitmap from - /// the format of a .NET . - /// - /// The - /// of the .NET . - /// Returns the type used for the new bitmap. - /// Returns the color depth for the new bitmap. - /// Returns the red_mask for the new bitmap. - /// Returns the green_mask for the new bitmap. - /// Returns the blue_mask for the new bitmap. - /// True in case a matching conversion exists; else false. - /// - public static bool GetFormatParameters( - PixelFormat format, - out FREE_IMAGE_TYPE type, - out uint bpp, - out uint red_mask, - out uint green_mask, - out uint blue_mask) - { - bool result = false; - type = FREE_IMAGE_TYPE.FIT_UNKNOWN; - bpp = 0; - red_mask = 0; - green_mask = 0; - blue_mask = 0; - switch (format) - { - case PixelFormat.Format1bppIndexed: - type = FREE_IMAGE_TYPE.FIT_BITMAP; - bpp = 1; - result = true; - break; - case PixelFormat.Format4bppIndexed: - type = FREE_IMAGE_TYPE.FIT_BITMAP; - bpp = 4; - result = true; - break; - case PixelFormat.Format8bppIndexed: - type = FREE_IMAGE_TYPE.FIT_BITMAP; - bpp = 8; - result = true; - break; - case PixelFormat.Format16bppRgb565: - type = FREE_IMAGE_TYPE.FIT_BITMAP; - bpp = 16; - red_mask = FI16_565_RED_MASK; - green_mask = FI16_565_GREEN_MASK; - blue_mask = FI16_565_BLUE_MASK; - result = true; - break; - case PixelFormat.Format16bppRgb555: - case PixelFormat.Format16bppArgb1555: - type = FREE_IMAGE_TYPE.FIT_BITMAP; - bpp = 16; - red_mask = FI16_555_RED_MASK; - green_mask = FI16_555_GREEN_MASK; - blue_mask = FI16_555_BLUE_MASK; - result = true; - break; - case PixelFormat.Format24bppRgb: - type = FREE_IMAGE_TYPE.FIT_BITMAP; - bpp = 24; - red_mask = FI_RGBA_RED_MASK; - green_mask = FI_RGBA_GREEN_MASK; - blue_mask = FI_RGBA_BLUE_MASK; - result = true; - break; - case PixelFormat.Format32bppRgb: - case PixelFormat.Format32bppArgb: - case PixelFormat.Format32bppPArgb: - type = FREE_IMAGE_TYPE.FIT_BITMAP; - bpp = 32; - red_mask = FI_RGBA_RED_MASK; - green_mask = FI_RGBA_GREEN_MASK; - blue_mask = FI_RGBA_BLUE_MASK; - result = true; - break; - case PixelFormat.Format16bppGrayScale: - type = FREE_IMAGE_TYPE.FIT_UINT16; - bpp = 16; - result = true; - break; - case PixelFormat.Format48bppRgb: - type = FREE_IMAGE_TYPE.FIT_RGB16; - bpp = 48; - result = true; - break; - case PixelFormat.Format64bppArgb: - case PixelFormat.Format64bppPArgb: - type = FREE_IMAGE_TYPE.FIT_RGBA16; - bpp = 64; - result = true; - break; - } - return result; - } - - /// - /// Returns the for the specified - /// . - /// - /// The - /// for which to return the corresponding . - /// The for the specified - /// - public static FREE_IMAGE_FORMAT GetFormat(ImageFormat imageFormat) - { - if (imageFormat != null) - { - if (imageFormat.Equals(ImageFormat.Bmp)) - return FREE_IMAGE_FORMAT.FIF_BMP; - if (imageFormat.Equals(ImageFormat.Gif)) - return FREE_IMAGE_FORMAT.FIF_GIF; - if (imageFormat.Equals(ImageFormat.Icon)) - return FREE_IMAGE_FORMAT.FIF_ICO; - if (imageFormat.Equals(ImageFormat.Jpeg)) - return FREE_IMAGE_FORMAT.FIF_JPEG; - if (imageFormat.Equals(ImageFormat.Png)) - return FREE_IMAGE_FORMAT.FIF_PNG; - if (imageFormat.Equals(ImageFormat.Tiff)) - return FREE_IMAGE_FORMAT.FIF_TIFF; - } - return FREE_IMAGE_FORMAT.FIF_UNKNOWN; - } - - /// - /// Retrieves all parameters needed to create a new FreeImage bitmap from - /// raw bits . - /// - /// The - /// of the data in memory. - /// The color depth for the data. - /// Returns the red_mask for the data. - /// Returns the green_mask for the data. - /// Returns the blue_mask for the data. - /// True in case a matching conversion exists; else false. - /// - public static bool GetTypeParameters( - FREE_IMAGE_TYPE type, - int bpp, - out uint red_mask, - out uint green_mask, - out uint blue_mask) - { - bool result = false; - red_mask = 0; - green_mask = 0; - blue_mask = 0; - switch (type) - { - case FREE_IMAGE_TYPE.FIT_BITMAP: - switch (bpp) - { - case 1: - case 4: - case 8: - result = true; - break; - case 16: - result = true; - red_mask = FI16_555_RED_MASK; - green_mask = FI16_555_GREEN_MASK; - blue_mask = FI16_555_BLUE_MASK; - break; - case 24: - case 32: - result = true; - red_mask = FI_RGBA_RED_MASK; - green_mask = FI_RGBA_GREEN_MASK; - blue_mask = FI_RGBA_BLUE_MASK; - break; - } - break; - case FREE_IMAGE_TYPE.FIT_UNKNOWN: - break; - default: - result = true; - break; - } - return result; - } - - /// - /// Compares two FreeImage bitmaps. - /// - /// The first bitmap to compare. - /// The second bitmap to compare. - /// Determines which components of the bitmaps will be compared. - /// True in case both bitmaps match the compare conditions, false otherwise. - public static bool Compare(FIBITMAP dib1, FIBITMAP dib2, FREE_IMAGE_COMPARE_FLAGS flags) - { - // Check whether one bitmap is null - if (dib1.IsNull ^ dib2.IsNull) - { - return false; - } - // Check whether both pointers are the same - if (dib1 == dib2) - { - return true; - } - if (((flags & FREE_IMAGE_COMPARE_FLAGS.HEADER) > 0) && (!CompareHeader(dib1, dib2))) - { - return false; - } - if (((flags & FREE_IMAGE_COMPARE_FLAGS.PALETTE) > 0) && (!ComparePalette(dib1, dib2))) - { - return false; - } - if (((flags & FREE_IMAGE_COMPARE_FLAGS.DATA) > 0) && (!CompareData(dib1, dib2))) - { - return false; - } - if (((flags & FREE_IMAGE_COMPARE_FLAGS.METADATA) > 0) && (!CompareMetadata(dib1, dib2))) - { - return false; - } - return true; - } - - private static unsafe bool CompareHeader(FIBITMAP dib1, FIBITMAP dib2) - { - IntPtr i1 = GetInfoHeader(dib1); - IntPtr i2 = GetInfoHeader(dib2); - return CompareMemory((void*)i1, (void*)i2, sizeof(BITMAPINFOHEADER)); - } - - private static unsafe bool ComparePalette(FIBITMAP dib1, FIBITMAP dib2) - { - IntPtr pal1 = GetPalette(dib1), pal2 = GetPalette(dib2); - bool hasPalette1 = pal1 != IntPtr.Zero; - bool hasPalette2 = pal2 != IntPtr.Zero; - if (hasPalette1 ^ hasPalette2) - { - return false; - } - if (!hasPalette1) - { - return true; - } - uint colors = GetColorsUsed(dib1); - if (colors != GetColorsUsed(dib2)) - { - return false; - } - return CompareMemory((void*)pal1, (void*)pal2, sizeof(RGBQUAD) * colors); - } - - private static unsafe bool CompareData(FIBITMAP dib1, FIBITMAP dib2) - { - uint width = GetWidth(dib1); - if (width != GetWidth(dib2)) - { - return false; - } - uint height = GetHeight(dib1); - if (height != GetHeight(dib2)) - { - return false; - } - uint bpp = GetBPP(dib1); - if (bpp != GetBPP(dib2)) - { - return false; - } - if (GetColorType(dib1) != GetColorType(dib2)) - { - return false; - } - FREE_IMAGE_TYPE type = GetImageType(dib1); - if (type != GetImageType(dib2)) - { - return false; - } - if (GetRedMask(dib1) != GetRedMask(dib2)) - { - return false; - } - if (GetGreenMask(dib1) != GetGreenMask(dib2)) - { - return false; - } - if (GetBlueMask(dib1) != GetBlueMask(dib2)) - { - return false; - } - - byte* ptr1, ptr2; - int fullBytes; - int shift; - uint line = GetLine(dib1); - - if (type == FREE_IMAGE_TYPE.FIT_BITMAP) - { - switch (bpp) - { - case 32: - for (int i = 0; i < height; i++) - { - ptr1 = (byte*)GetScanLine(dib1, i); - ptr2 = (byte*)GetScanLine(dib2, i); - if (!CompareMemory(ptr1, ptr2, line)) - { - return false; - } - } - break; - case 24: - for (int i = 0; i < height; i++) - { - ptr1 = (byte*)GetScanLine(dib1, i); - ptr2 = (byte*)GetScanLine(dib2, i); - if (!CompareMemory(ptr1, ptr2, line)) - { - return false; - } - } - break; - case 16: - short* sPtr1, sPtr2; - short mask = (short)(GetRedMask(dib1) | GetGreenMask(dib1) | GetBlueMask(dib1)); - if (mask == -1) - { - for (int i = 0; i < height; i++) - { - sPtr1 = (short*)GetScanLine(dib1, i); - sPtr2 = (short*)GetScanLine(dib2, i); - if (!CompareMemory(sPtr1, sPtr1, line)) - { - return false; - } - } - } - else - { - for (int i = 0; i < height; i++) - { - sPtr1 = (short*)GetScanLine(dib1, i); - sPtr2 = (short*)GetScanLine(dib2, i); - for (int x = 0; x < width; x++) - { - if ((sPtr1[x] & mask) != (sPtr2[x] & mask)) - { - return false; - } - } - } - } - break; - case 8: - for (int i = 0; i < height; i++) - { - ptr1 = (byte*)GetScanLine(dib1, i); - ptr2 = (byte*)GetScanLine(dib2, i); - if (!CompareMemory(ptr1, ptr2, line)) - { - return false; - } - } - break; - case 4: - fullBytes = (int)width / 2; - shift = (width % 2) == 0 ? 8 : 4; - for (int i = 0; i < height; i++) - { - ptr1 = (byte*)GetScanLine(dib1, i); - ptr2 = (byte*)GetScanLine(dib2, i); - if (fullBytes != 0) - { - if (!CompareMemory(ptr1, ptr2, fullBytes)) - { - return false; - } - ptr1 += fullBytes; - ptr2 += fullBytes; - } - if (shift != 8) - { - if ((ptr1[0] >> shift) != (ptr2[0] >> shift)) - { - return false; - } - } - } - break; - case 1: - fullBytes = (int)width / 8; - shift = 8 - ((int)width % 8); - for (int i = 0; i < height; i++) - { - ptr1 = (byte*)GetScanLine(dib1, i); - ptr2 = (byte*)GetScanLine(dib2, i); - if (fullBytes != 0) - { - if (!CompareMemory(ptr1, ptr2, fullBytes)) - { - return false; - } - ptr1 += fullBytes; - ptr2 += fullBytes; - } - if (shift != 8) - { - if ((ptr1[0] >> shift) != (ptr2[0] >> shift)) - { - return false; - } - } - } - break; - default: - throw new NotSupportedException("Only 1, 4, 8, 16, 24 and 32 bpp bitmaps are supported."); - } - } - else - { - for (int i = 0; i < height; i++) - { - ptr1 = (byte*)GetScanLine(dib1, i); - ptr2 = (byte*)GetScanLine(dib2, i); - if (!CompareMemory(ptr1, ptr2, line)) - { - return false; - } - } - } - return true; - } - - private static bool CompareMetadata(FIBITMAP dib1, FIBITMAP dib2) - { - MetadataTag tag1, tag2; - - foreach (FREE_IMAGE_MDMODEL metadataModel in FREE_IMAGE_MDMODELS) - { - if (GetMetadataCount(metadataModel, dib1) != - GetMetadataCount(metadataModel, dib2)) - { - return false; - } - if (GetMetadataCount(metadataModel, dib1) == 0) - { - continue; - } - - FIMETADATA mdHandle = FindFirstMetadata(metadataModel, dib1, out tag1); - if (mdHandle.IsNull) - { - continue; - } - do - { - if ((!GetMetadata(metadataModel, dib2, tag1.Key, out tag2)) || (tag1 != tag2)) - { - FindCloseMetadata(mdHandle); - return false; - } - } - while (FindNextMetadata(mdHandle, out tag1)); - FindCloseMetadata(mdHandle); - } - - return true; - } - - /// - /// Returns the FreeImage bitmap's transparency table. - /// The array is empty in case the bitmap has no transparency table. - /// - /// Handle to a FreeImage bitmap. - /// The FreeImage bitmap's transparency table. - /// - /// is null. - public static unsafe byte[] GetTransparencyTableEx(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - uint count = GetTransparencyCount(dib); - byte[] result = new byte[count]; - byte* ptr = (byte*)GetTransparencyTable(dib); - fixed (byte* dst = result) - { - CopyMemory(dst, ptr, count); - } - return result; - } - - /// - /// Set the FreeImage bitmap's transparency table. Only affects palletised bitmaps. - /// - /// Handle to a FreeImage bitmap. - /// The FreeImage bitmap's new transparency table. - /// - /// or is null. - public static void SetTransparencyTable(FIBITMAP dib, byte[] table) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - if (table == null) - { - throw new ArgumentNullException("table"); - } - SetTransparencyTable(dib, table, table.Length); - } - - /// - /// This function returns the number of unique colors actually used by the - /// specified 1-, 4-, 8-, 16-, 24- or 32-bit image. This might be different from - /// what function FreeImage_GetColorsUsed() returns, which actually returns the - /// palette size for palletised images. Works for - /// type images only. - /// - /// Handle to a FreeImage bitmap. - /// Returns the number of unique colors used by the image specified or - /// zero, if the image type cannot be handled. - /// - /// is null. - public static unsafe int GetUniqueColors(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - - int result = 0; - - if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) - { - BitArray bitArray; - int uniquePalEnts; - int hashcode; - byte[] lut; - int width = (int)GetWidth(dib); - int height = (int)GetHeight(dib); - - switch (GetBPP(dib)) - { - case 1: - - result = 1; - lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts); - if (uniquePalEnts == 1) - { - break; - } - - if ((*(byte*)GetScanLine(dib, 0) & 0x80) == 0) - { - for (int y = 0; y < height; y++) - { - byte* scanline = (byte*)GetScanLine(dib, y); - int mask = 0x80; - for (int x = 0; x < width; x++) - { - if ((scanline[x / 8] & mask) > 0) - { - return 2; - } - mask = (mask == 0x1) ? 0x80 : (mask >> 1); - } - } - } - else - { - for (int y = 0; y < height; y++) - { - byte* scanline = (byte*)GetScanLine(dib, y); - int mask = 0x80; - for (int x = 0; x < width; x++) - { - if ((scanline[x / 8] & mask) == 0) - { - return 2; - } - mask = (mask == 0x1) ? 0x80 : (mask >> 1); - } - } - } - break; - - case 4: - - bitArray = new BitArray(0x10); - lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts); - if (uniquePalEnts == 1) - { - result = 1; - break; - } - - for (int y = 0; (y < height) && (result < uniquePalEnts); y++) - { - byte* scanline = (byte*)GetScanLine(dib, y); - bool top = true; - for (int x = 0; (x < width) && (result < uniquePalEnts); x++) - { - if (top) - { - hashcode = lut[scanline[x / 2] >> 4]; - } - else - { - hashcode = lut[scanline[x / 2] & 0xF]; - } - top = !top; - if (!bitArray[hashcode]) - { - bitArray[hashcode] = true; - result++; - } - } - } - break; - - case 8: - - bitArray = new BitArray(0x100); - lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts); - if (uniquePalEnts == 1) - { - result = 1; - break; - } - - for (int y = 0; (y < height) && (result < uniquePalEnts); y++) - { - byte* scanline = (byte*)GetScanLine(dib, y); - for (int x = 0; (x < width) && (result < uniquePalEnts); x++) - { - hashcode = lut[scanline[x]]; - if (!bitArray[hashcode]) - { - bitArray[hashcode] = true; - result++; - } - } - } - break; - - case 16: - - bitArray = new BitArray(0x10000); - - for (int y = 0; y < height; y++) - { - short* scanline = (short*)GetScanLine(dib, y); - for (int x = 0; x < width; x++, scanline++) - { - hashcode = *scanline; - if (!bitArray[hashcode]) - { - bitArray[hashcode] = true; - result++; - } - } - } - break; - - case 24: - - bitArray = new BitArray(0x1000000); - - for (int y = 0; y < height; y++) - { - byte* scanline = (byte*)GetScanLine(dib, y); - for (int x = 0; x < width; x++, scanline += 3) - { - hashcode = *((int*)scanline) & 0x00FFFFFF; - if (!bitArray[hashcode]) - { - bitArray[hashcode] = true; - result++; - } - } - } - break; - - case 32: - - bitArray = new BitArray(0x1000000); - - for (int y = 0; y < height; y++) - { - int* scanline = (int*)GetScanLine(dib, y); - for (int x = 0; x < width; x++, scanline++) - { - hashcode = *scanline & 0x00FFFFFF; - if (!bitArray[hashcode]) - { - bitArray[hashcode] = true; - result++; - } - } - } - break; - } - } - return result; - } - - /// - /// Verifies whether the FreeImage bitmap is 16bit 555. - /// - /// The FreeImage bitmap to verify. - /// true if the bitmap is RGB16-555; otherwise false. - public static bool IsRGB555(FIBITMAP dib) - { - return ((GetRedMask(dib) == FI16_555_RED_MASK) && - (GetGreenMask(dib) == FI16_555_GREEN_MASK) && - (GetBlueMask(dib) == FI16_555_BLUE_MASK)); - } - - /// - /// Verifies whether the FreeImage bitmap is 16bit 565. - /// - /// The FreeImage bitmap to verify. - /// true if the bitmap is RGB16-565; otherwise false. - public static bool IsRGB565(FIBITMAP dib) - { - return ((GetRedMask(dib) == FI16_565_RED_MASK) && - (GetGreenMask(dib) == FI16_565_GREEN_MASK) && - (GetBlueMask(dib) == FI16_565_BLUE_MASK)); - } - - #endregion - - #region ICC profile functions - - /// - /// Creates a new ICC-Profile for a FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The data of the new ICC-Profile. - /// The new ICC-Profile of the bitmap. - /// - /// is null. - public static FIICCPROFILE CreateICCProfileEx(FIBITMAP dib, byte[] data) - { - return new FIICCPROFILE(dib, data); - } - - /// - /// Creates a new ICC-Profile for a FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The data of the new ICC-Profile. - /// The number of bytes of to use. - /// The new ICC-Profile of the FreeImage bitmap. - /// - /// is null. - public static FIICCPROFILE CreateICCProfileEx(FIBITMAP dib, byte[] data, int size) - { - return new FIICCPROFILE(dib, data, size); - } - - #endregion - - #region Conversion functions - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion) - { - return ConvertColorDepth( - dib, - conversion, - 128, - FREE_IMAGE_DITHER.FID_FS, - FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, - false); - } - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// When true the structure will be unloaded on success. - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - bool unloadSource) - { - return ConvertColorDepth( - dib, - conversion, - 128, - FREE_IMAGE_DITHER.FID_FS, - FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, - unloadSource); - } - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// Threshold value when converting with - /// . - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - byte threshold) - { - return ConvertColorDepth( - dib, - conversion, - threshold, - FREE_IMAGE_DITHER.FID_FS, - FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, - false); - } - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// Dither algorithm when converting - /// with . - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - FREE_IMAGE_DITHER ditherMethod) - { - return ConvertColorDepth( - dib, - conversion, - 128, - ditherMethod, - FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, - false); - } - - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// The quantization algorithm for conversion to 8-bit color depth. - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - FREE_IMAGE_QUANTIZE quantizationMethod) - { - return ConvertColorDepth( - dib, - conversion, - 128, - FREE_IMAGE_DITHER.FID_FS, - quantizationMethod, - false); - } - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// Threshold value when converting with - /// . - /// When true the structure will be unloaded on success. - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - byte threshold, - bool unloadSource) - { - return ConvertColorDepth( - dib, - conversion, - threshold, - FREE_IMAGE_DITHER.FID_FS, - FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, - unloadSource); - } - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// Dither algorithm when converting with - /// . - /// When true the structure will be unloaded on success. - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - FREE_IMAGE_DITHER ditherMethod, - bool unloadSource) - { - return ConvertColorDepth( - dib, - conversion, - 128, - ditherMethod, - FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, - unloadSource); - } - - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// The quantization algorithm for conversion to 8-bit color depth. - /// When true the structure will be unloaded on success. - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - FREE_IMAGE_QUANTIZE quantizationMethod, - bool unloadSource) - { - return ConvertColorDepth( - dib, - conversion, - 128, - FREE_IMAGE_DITHER.FID_FS, - quantizationMethod, - unloadSource); - } - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// Threshold value when converting with - /// . - /// Dither algorithm when converting with - /// . - /// The quantization algorithm for conversion to 8-bit color depth. - /// When true the structure will be unloaded on success. - /// Handle to a FreeImage bitmap. - /// - /// is null. - internal static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - byte threshold, - FREE_IMAGE_DITHER ditherMethod, - FREE_IMAGE_QUANTIZE quantizationMethod, - bool unloadSource) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - - FIBITMAP result = new FIBITMAP(); - FIBITMAP dibTemp = new FIBITMAP(); - uint bpp = GetBPP(dib); - bool reorderPalette = ((conversion & FREE_IMAGE_COLOR_DEPTH.FICD_REORDER_PALETTE) > 0); - bool forceGreyscale = ((conversion & FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE) > 0); - - if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) - { - switch (conversion & (FREE_IMAGE_COLOR_DEPTH)0xFF) - { - case FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_THRESHOLD: - - if (bpp != 1) - { - if (forceGreyscale) - { - result = Threshold(dib, threshold); - } - else - { - dibTemp = ConvertTo24Bits(dib); - result = ColorQuantizeEx(dibTemp, quantizationMethod, 2, null, 1); - Unload(dibTemp); - } - } - else - { - bool isGreyscale = IsGreyscaleImage(dib); - if ((forceGreyscale && (!isGreyscale)) || - (reorderPalette && isGreyscale)) - { - result = Threshold(dib, threshold); - } - } - break; - - case FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_DITHER: - - if (bpp != 1) - { - if (forceGreyscale) - { - result = Dither(dib, ditherMethod); - } - else - { - dibTemp = ConvertTo24Bits(dib); - result = ColorQuantizeEx(dibTemp, quantizationMethod, 2, null, 1); - Unload(dibTemp); - } - } - else - { - bool isGreyscale = IsGreyscaleImage(dib); - if ((forceGreyscale && (!isGreyscale)) || - (reorderPalette && isGreyscale)) - { - result = Dither(dib, ditherMethod); - } - } - break; - - case FREE_IMAGE_COLOR_DEPTH.FICD_04_BPP: - - if (bpp != 4) - { - // Special case when 1bpp and FIC_PALETTE - if (forceGreyscale || - ((bpp == 1) && (GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_PALETTE))) - { - dibTemp = ConvertToGreyscale(dib); - result = ConvertTo4Bits(dibTemp); - Unload(dibTemp); - } - else - { - dibTemp = ConvertTo24Bits(dib); - result = ColorQuantizeEx(dibTemp, quantizationMethod, 16, null, 4); - Unload(dibTemp); - } - } - else - { - bool isGreyscale = IsGreyscaleImage(dib); - if ((forceGreyscale && (!isGreyscale)) || - (reorderPalette && isGreyscale)) - { - dibTemp = ConvertToGreyscale(dib); - result = ConvertTo4Bits(dibTemp); - Unload(dibTemp); - } - } - - break; - - case FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP: - - if (bpp != 8) - { - if (forceGreyscale) - { - result = ConvertToGreyscale(dib); - } - else - { - dibTemp = ConvertTo24Bits(dib); - result = ColorQuantize(dibTemp, quantizationMethod); - Unload(dibTemp); - } - } - else - { - bool isGreyscale = IsGreyscaleImage(dib); - if ((forceGreyscale && (!isGreyscale)) || (reorderPalette && isGreyscale)) - { - result = ConvertToGreyscale(dib); - } - } - break; - - case FREE_IMAGE_COLOR_DEPTH.FICD_16_BPP_555: - - if (forceGreyscale) - { - dibTemp = ConvertToGreyscale(dib); - result = ConvertTo16Bits555(dibTemp); - Unload(dibTemp); - } - else if (bpp != 16 || GetRedMask(dib) != FI16_555_RED_MASK || GetGreenMask(dib) != FI16_555_GREEN_MASK || GetBlueMask(dib) != FI16_555_BLUE_MASK) - { - result = ConvertTo16Bits555(dib); - } - break; - - case FREE_IMAGE_COLOR_DEPTH.FICD_16_BPP: - - if (forceGreyscale) - { - dibTemp = ConvertToGreyscale(dib); - result = ConvertTo16Bits565(dibTemp); - Unload(dibTemp); - } - else if (bpp != 16 || GetRedMask(dib) != FI16_565_RED_MASK || GetGreenMask(dib) != FI16_565_GREEN_MASK || GetBlueMask(dib) != FI16_565_BLUE_MASK) - { - result = ConvertTo16Bits565(dib); - } - break; - - case FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP: - - if (forceGreyscale) - { - dibTemp = ConvertToGreyscale(dib); - result = ConvertTo24Bits(dibTemp); - Unload(dibTemp); - } - else if (bpp != 24) - { - result = ConvertTo24Bits(dib); - } - break; - - case FREE_IMAGE_COLOR_DEPTH.FICD_32_BPP: - - if (forceGreyscale) - { - dibTemp = ConvertToGreyscale(dib); - result = ConvertTo32Bits(dibTemp); - Unload(dibTemp); - } - else if (bpp != 32) - { - result = ConvertTo32Bits(dib); - } - break; - } - } - - if (result.IsNull) - { - return dib; - } - if (unloadSource) - { - Unload(dib); - } - - return result; - } - - /// - /// ColorQuantizeEx is an extension to the - /// method that provides additional options used to quantize a 24-bit image to any - /// number of colors (up to 256), as well as quantize a 24-bit image using a - /// provided palette. - /// - /// Handle to a FreeImage bitmap. - /// Specifies the color reduction algorithm to be used. - /// Size of the desired output palette. - /// The provided palette. - /// true to create a bitmap with the smallest possible - /// color depth for the specified . - /// Handle to a FreeImage bitmap. - public static FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, RGBQUAD[] ReservePalette, bool minColorDepth) - { - FIBITMAP result; - if (minColorDepth) - { - int bpp; - if (PaletteSize >= 256) - bpp = 8; - else if (PaletteSize > 2) - bpp = 4; - else - bpp = 1; - result = ColorQuantizeEx(dib, quantize, PaletteSize, ReservePalette, bpp); - } - else - { - result = ColorQuantizeEx(dib, quantize, PaletteSize, ReservePalette, 8); - } - return result; - } - - /// - /// ColorQuantizeEx is an extension to the - /// method that provides additional options used to quantize a 24-bit image to any - /// number of colors (up to 256), as well as quantize a 24-bit image using a - /// partial or full provided palette. - /// - /// Handle to a FreeImage bitmap. - /// Specifies the color reduction algorithm to be used. - /// Size of the desired output palette. - /// The provided palette. - /// The desired color depth of the created image. - /// Handle to a FreeImage bitmap. - public static FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, RGBQUAD[] ReservePalette, int bpp) - { - unsafe - { - FIBITMAP result = FIBITMAP.Zero; - FIBITMAP temp = FIBITMAP.Zero; - int reservedSize = (ReservePalette == null) ? 0 : ReservePalette.Length; - - if (bpp == 8) - { - result = ColorQuantizeEx(dib, quantize, PaletteSize, reservedSize, ReservePalette); - } - else if (bpp == 4) - { - temp = ColorQuantizeEx(dib, quantize, Math.Min(16, PaletteSize), reservedSize, ReservePalette); - if (!temp.IsNull) - { - result = Allocate((int)GetWidth(temp), (int)GetHeight(temp), 4, 0, 0, 0); - CloneMetadata(result, temp); - CopyMemory(GetPalette(result), GetPalette(temp), sizeof(RGBQUAD) * 16); - - for (int y = (int)GetHeight(temp) - 1; y >= 0; y--) - { - Scanline srcScanline = new Scanline(temp, y); - Scanline dstScanline = new Scanline(result, y); - - for (int x = (int)GetWidth(temp) - 1; x >= 0; x--) - { - dstScanline[x] = srcScanline[x]; - } - } - } - } - else if (bpp == 1) - { - temp = ColorQuantizeEx(dib, quantize, 2, reservedSize, ReservePalette); - if (!temp.IsNull) - { - result = Allocate((int)GetWidth(temp), (int)GetHeight(temp), 1, 0, 0, 0); - CloneMetadata(result, temp); - CopyMemory(GetPalette(result), GetPalette(temp), sizeof(RGBQUAD) * 2); - - for (int y = (int)GetHeight(temp) - 1; y >= 0; y--) - { - Scanline srcScanline = new Scanline(temp, y); - Scanline dstScanline = new Scanline(result, y); - - for (int x = (int)GetWidth(temp) - 1; x >= 0; x--) - { - dstScanline[x] = srcScanline[x]; - } - } - } - } - - UnloadEx(ref temp); - return result; - } - } - - #endregion - - #region Metadata - - /// - /// Copies metadata from one FreeImage bitmap to another. - /// - /// Source FreeImage bitmap containing the metadata. - /// FreeImage bitmap to copy the metadata to. - /// Flags to switch different copy modes. - /// Returns -1 on failure else the number of copied tags. - /// - /// or is null. - public static int CloneMetadataEx(FIBITMAP src, FIBITMAP dst, FREE_IMAGE_METADATA_COPY flags) - { - if (src.IsNull) - { - throw new ArgumentNullException("src"); - } - if (dst.IsNull) - { - throw new ArgumentNullException("dst"); - } - - FITAG tag = new FITAG(), tag2 = new FITAG(); - int copied = 0; - - // Clear all existing metadata - if ((flags & FREE_IMAGE_METADATA_COPY.CLEAR_EXISTING) > 0) - { - foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS) - { - if (!SetMetadata(model, dst, null, tag)) - { - return -1; - } - } - } - - bool keep = !((flags & FREE_IMAGE_METADATA_COPY.REPLACE_EXISTING) > 0); - - foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS) - { - FIMETADATA mData = FindFirstMetadata(model, src, out tag); - if (mData.IsNull) continue; - do - { - string key = GetTagKey(tag); - if (!(keep && GetMetadata(model, dst, key, out tag2))) - { - if (SetMetadata(model, dst, key, tag)) - { - copied++; - } - } - } - while (FindNextMetadata(mData, out tag)); - FindCloseMetadata(mData); - } - - return copied; - } - - /// - /// Returns the comment of a JPEG, PNG or GIF image. - /// - /// Handle to a FreeImage bitmap. - /// Comment of the FreeImage bitmp, or null in case no comment exists. - /// - /// is null. - public static string GetImageComment(FIBITMAP dib) - { - string result = null; - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - FITAG tag; - if (GetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", out tag)) - { - MetadataTag metadataTag = new MetadataTag(tag, FREE_IMAGE_MDMODEL.FIMD_COMMENTS); - result = metadataTag.Value as string; - } - return result; - } - - /// - /// Sets the comment of a JPEG, PNG or GIF image. - /// - /// Handle to a FreeImage bitmap. - /// New comment of the FreeImage bitmap. - /// Use null to remove the comment. - /// Returns true on success, false on failure. - /// - /// is null. - public static bool SetImageComment(FIBITMAP dib, string comment) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - bool result; - if (comment != null) - { - FITAG tag = CreateTag(); - MetadataTag metadataTag = new MetadataTag(tag, FREE_IMAGE_MDMODEL.FIMD_COMMENTS); - metadataTag.Value = comment; - result = SetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", tag); - DeleteTag(tag); - } - else - { - result = SetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", FITAG.Zero); - } - return result; - } - - /// - /// Retrieve a metadata attached to a FreeImage bitmap. - /// - /// The metadata model to look for. - /// Handle to a FreeImage bitmap. - /// The metadata field name. - /// A structure returned by the function. - /// Returns true on success, false on failure. - /// - /// is null. - public static bool GetMetadata( - FREE_IMAGE_MDMODEL model, - FIBITMAP dib, - string key, - out MetadataTag tag) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - - FITAG _tag; - bool result; - if (GetMetadata(model, dib, key, out _tag)) - { - tag = new MetadataTag(_tag, model); - result = true; - } - else - { - tag = null; - result = false; - } - return result; - } - - /// - /// Attach a new metadata tag to a FreeImage bitmap. - /// - /// The metadata model used to store the tag. - /// Handle to a FreeImage bitmap. - /// The tag field name. - /// The to be attached. - /// Returns true on success, false on failure. - /// - /// is null. - public static bool SetMetadata( - FREE_IMAGE_MDMODEL model, - FIBITMAP dib, - string key, - MetadataTag tag) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - return SetMetadata(model, dib, key, tag.tag); - } - - /// - /// Provides information about the first instance of a tag that matches the metadata model. - /// - /// The model to match. - /// Handle to a FreeImage bitmap. - /// Tag that matches the metadata model. - /// Unique search handle that can be used to call FindNextMetadata or FindCloseMetadata. - /// Null if the metadata model does not exist. - /// - /// is null. - public static FIMETADATA FindFirstMetadata( - FREE_IMAGE_MDMODEL model, - FIBITMAP dib, - out MetadataTag tag) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - FITAG _tag; - FIMETADATA result = FindFirstMetadata(model, dib, out _tag); - if (result.IsNull) - { - tag = null; - return result; - } - tag = new MetadataTag(_tag, model); - if (metaDataSearchHandler.ContainsKey(result)) - { - metaDataSearchHandler[result] = model; - } - else - { - metaDataSearchHandler.Add(result, model); - } - return result; - } - - /// - /// Find the next tag, if any, that matches the metadata model argument in a previous call - /// to FindFirstMetadata, and then alters the tag object contents accordingly. - /// - /// Unique search handle provided by FindFirstMetadata. - /// Tag that matches the metadata model. - /// Returns true on success, false on failure. - public static bool FindNextMetadata(FIMETADATA mdhandle, out MetadataTag tag) - { - FITAG _tag; - bool result; - if (FindNextMetadata(mdhandle, out _tag)) - { - tag = new MetadataTag(_tag, metaDataSearchHandler[mdhandle]); - result = true; - } - else - { - tag = null; - result = false; - } - return result; - } - - /// - /// Closes the specified metadata search handle and releases associated resources. - /// - /// The handle to close. - public static void FindCloseMetadata(FIMETADATA mdhandle) - { - if (metaDataSearchHandler.ContainsKey(mdhandle)) - { - metaDataSearchHandler.Remove(mdhandle); - } - FindCloseMetadata_(mdhandle); - } - - /// - /// This dictionary links FIMETADATA handles and FREE_IMAGE_MDMODEL models. - /// - private static Dictionary metaDataSearchHandler - = new Dictionary(1); - - #endregion - - #region Rotation and Flipping - - /// - /// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. - /// 1-bit images rotation is limited to integer multiple of 90°. - /// null is returned for other values. - /// - /// Handle to a FreeImage bitmap. - /// The angle of rotation. - /// Handle to a FreeImage bitmap. - public static FIBITMAP Rotate(FIBITMAP dib, double angle) - { - return Rotate(dib, angle, IntPtr.Zero); - } - - /// - /// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. - /// 1-bit images rotation is limited to integer multiple of 90°. - /// null is returned for other values. - /// - /// The type of the color to use as background. - /// Handle to a FreeImage bitmap. - /// The angle of rotation. - /// The color used used to fill the bitmap's background. - /// Handle to a FreeImage bitmap. - public static FIBITMAP Rotate(FIBITMAP dib, double angle, T? backgroundColor) where T : struct - { - if (backgroundColor.HasValue) - { - GCHandle handle = new GCHandle(); - try - { - T[] buffer = new T[] { backgroundColor.Value }; - handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - return Rotate(dib, angle, handle.AddrOfPinnedObject()); - } - finally - { - if (handle.IsAllocated) - handle.Free(); - } - } - else - { - return Rotate(dib, angle, IntPtr.Zero); - } - } - - /// - /// Rotates a 4-bit color FreeImage bitmap. - /// Allowed values for are 90, 180 and 270. - /// In case is 0 or 360 a clone is returned. - /// 0 is returned for other values or in case the rotation fails. - /// - /// Handle to a FreeImage bitmap. - /// The angle of rotation. - /// Handle to a FreeImage bitmap. - /// - /// This function is kind of temporary due to FreeImage's lack of - /// rotating 4-bit images. It's particularly used by 's - /// method RotateFlip. This function will be removed as soon as FreeImage - /// supports rotating 4-bit images. - /// - /// - /// is null. - public static unsafe FIBITMAP Rotate4bit(FIBITMAP dib, double angle) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - - FIBITMAP result = new FIBITMAP(); - int ang = (int)angle; - - if ((GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) && - (GetBPP(dib) == 4) && - ((ang % 90) == 0)) - { - int width, height, xOrg, yOrg; - Scanline[] src, dst; - width = (int)GetWidth(dib); - height = (int)GetHeight(dib); - byte index = 0; - switch (ang) - { - case 90: - result = Allocate(height, width, 4, 0, 0, 0); - if (result.IsNull) - { - break; - } - CopyPalette(dib, result); - src = Get04BitScanlines(dib); - dst = Get04BitScanlines(result); - for (int y = 0; y < width; y++) - { - yOrg = height - 1; - for (int x = 0; x < height; x++, yOrg--) - { - index = src[yOrg][y]; - dst[y][x] = index; - } - } - break; - case 180: - result = Allocate(width, height, 4, 0, 0, 0); - if (result.IsNull) - { - break; - } - CopyPalette(dib, result); - src = Get04BitScanlines(dib); - dst = Get04BitScanlines(result); - - yOrg = height - 1; - for (int y = 0; y < height; y++, yOrg--) - { - xOrg = width - 1; - for (int x = 0; x < width; x++, xOrg--) - { - index = src[yOrg][xOrg]; - dst[y][x] = index; - } - } - break; - case 270: - result = Allocate(height, width, 4, 0, 0, 0); - if (result.IsNull) - { - break; - } - CopyPalette(dib, result); - src = Get04BitScanlines(dib); - dst = Get04BitScanlines(result); - xOrg = width - 1; - for (int y = 0; y < width; y++, xOrg--) - { - for (int x = 0; x < height; x++) - { - index = src[x][xOrg]; - dst[y][x] = index; - } - } - break; - case 0: - case 360: - result = Clone(dib); - break; - } - } - return result; - } - - #endregion - - #region Upsampling / downsampling - - /// - /// Enlarges or shrinks the FreeImage bitmap selectively per side and fills newly added areas - /// with the specified background color. See remarks for further details. - /// - /// The type of the specified color. - /// Handle to a FreeImage bitmap. - /// The number of pixels, the image should be enlarged on its left side. - /// Negative values shrink the image on its left side. - /// The number of pixels, the image should be enlarged on its top side. - /// Negative values shrink the image on its top side. - /// The number of pixels, the image should be enlarged on its right side. - /// Negative values shrink the image on its right side. - /// The number of pixels, the image should be enlarged on its bottom side. - /// Negative values shrink the image on its bottom side. - /// The color, the enlarged sides of the image should be filled with. - /// Options that affect the color search process for palletized images. - /// Handle to a FreeImage bitmap. - /// - /// This function enlarges or shrinks an image selectively per side. - /// The main purpose of this function is to add borders to an image. - /// To add a border to any of the image's sides, a positive integer value must be passed in - /// any of the parameters , , - /// or . This value represents the border's - /// width in pixels. Newly created parts of the image (the border areas) are filled with the - /// specified . - /// Specifying a negative integer value for a certain side, will shrink or crop the image on - /// this side. Consequently, specifying zero for a certain side will not change the image's - /// extension on that side. - /// - /// So, calling this function with all parameters , , - /// and set to zero, is - /// effectively the same as calling function ; setting all parameters - /// , , and - /// to value equal to or smaller than zero, my easily be substituted - /// by a call to function . Both these cases produce a new image, which is - /// guaranteed not to be larger than the input image. Thus, since the specified - /// is not needed in these cases, - /// may be null. - /// - /// Both parameters and work according to - /// function . So, please refer to the documentation of - /// to learn more about parameters - /// and . For palletized images, the palette of the input image is - /// transparently copied to the newly created enlarged or shrunken image, so any color look-ups - /// are performed on this palette. - /// - /// - /// // create a white color
    - /// RGBQUAD c;
    - /// c.rgbRed = 0xFF;
    - /// c.rgbGreen = 0xFF;
    - /// c.rgbBlue = 0xFF;
    - /// c.rgbReserved = 0x00;
    - ///
    - /// // add a white, symmetric 10 pixel wide border to the image
    - /// dib2 = FreeImage_EnlargeCanvas(dib, 10, 10, 10, 10, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);
    - ///
    - /// // add white, 20 pixel wide stripes to the top and bottom side of the image
    - /// dib3 = FreeImage_EnlargeCanvas(dib, 0, 20, 0, 20, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);
    - ///
    - /// // add white, 30 pixel wide stripes to the right side of the image and
    - /// // cut off the 40 leftmost pixel columns
    - /// dib3 = FreeImage_EnlargeCanvas(dib, -40, 0, 30, 0, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);
    - ///
    - public static FIBITMAP EnlargeCanvas(FIBITMAP dib, int left, int top, int right, int bottom, - T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct - { - if (dib.IsNull) - return FIBITMAP.Zero; - - if (color.HasValue) - { - if (!CheckColorType(GetImageType(dib), color.Value)) - return FIBITMAP.Zero; - - GCHandle handle = new GCHandle(); - try - { - T[] buffer = new T[] { color.Value }; - handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - return EnlargeCanvas(dib, left, top, right, bottom, handle.AddrOfPinnedObject(), options); - } - finally - { - if (handle.IsAllocated) - handle.Free(); - } - } - else - { - return EnlargeCanvas(dib, left, top, right, bottom, IntPtr.Zero, options); - } - } - - #endregion - - #region Color - - /// - /// Sets all pixels of the specified image to the color provided through the - /// parameter. See remarks for further details. - /// - /// The type of the specified color. - /// Handle to a FreeImage bitmap. - /// The color to fill the bitmap with. See remarks for further details. - /// Options that affect the color search process for palletized images. - /// true on success, false on failure. - /// - /// This function sets all pixels of an image to the color provided through - /// the parameter. is used for standard type images. - /// For non standard type images the underlaying structure is used. - /// - /// So, must be of type , if the image to be filled is of type - /// and must be a structure if the - /// image is of type and so on. - /// - /// However, the fill color is always specified through a structure - /// for all images of type . - /// So, for 32- and 24-bit images, the red, green and blue members of the - /// structure are directly used for the image's red, green and blue channel respectively. - /// Although alpha transparent colors are - /// supported, the alpha channel of a 32-bit image never gets modified by this function. - /// A fill color with an alpha value smaller than 255 gets blended with the image's actual - /// background color, which is determined from the image's bottom-left pixel. - /// So, currently using alpha enabled colors, assumes the image to be unicolor before the - /// fill operation. However, the field is only taken into account, - /// if option has been specified. - /// - /// For 16-bit images, the red-, green- and blue components of the specified color are - /// transparently translated into either the 16-bit 555 or 565 representation. This depends - /// on the image's actual red- green- and blue masks. - /// - /// Special attention must be payed for palletized images. Generally, the RGB color specified - /// is looked up in the image's palette. The found palette index is then used to fill the image. - /// There are some option flags, that affect this lookup process: - /// - /// - /// Value - /// Meaning - /// - /// - /// - /// - /// Uses the color, that is nearest to the specified color. - /// This is the default behavior and should always find a - /// color in the palette. However, the visual result may - /// far from what was expected and mainly depends on the - /// image's palette. - /// - /// - /// - /// - /// - /// Searches the image's palette for the specified color - /// but only uses the returned palette index, if the specified - /// color exactly matches the palette entry. Of course, - /// depending on the image's actual palette entries, this - /// operation may fail. In this case, the function falls back - /// to option - /// and uses the RGBQUAD's rgbReserved member (or its low nibble for 4-bit images - /// or its least significant bit (LSB) for 1-bit images) as - /// the palette index used for the fill operation. - /// - /// - /// - /// - /// - /// Does not perform any color lookup from the palette, but - /// uses the RGBQUAD's alpha channel member rgbReserved as - /// the palette index to be used for the fill operation. - /// However, for 4-bit images, only the low nibble of the - /// rgbReserved member are used and for 1-bit images, only - /// the least significant bit (LSB) is used. - /// - /// - /// - /// - public static bool FillBackground(FIBITMAP dib, T color, FREE_IMAGE_COLOR_OPTIONS options) - where T : struct - { - if (dib.IsNull) - return false; - - if (!CheckColorType(GetImageType(dib), color)) - return false; - - GCHandle handle = new GCHandle(); - try - { - T[] buffer = new T[] { color }; - handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - return FillBackground(dib, handle.AddrOfPinnedObject(), options); - } - finally - { - if (handle.IsAllocated) - handle.Free(); - } - } - - #endregion - - #region Wrapper functions - - /// - /// Returns the next higher possible color depth. - /// - /// Color depth to increase. - /// The next higher color depth or 0 if there is no valid color depth. - internal static int GetNextColorDepth(int bpp) - { - int result = 0; - switch (bpp) - { - case 1: - result = 4; - break; - case 4: - result = 8; - break; - case 8: - result = 16; - break; - case 16: - result = 24; - break; - case 24: - result = 32; - break; - } - return result; - } - - /// - /// Returns the next lower possible color depth. - /// - /// Color depth to decrease. - /// The next lower color depth or 0 if there is no valid color depth. - internal static int GetPrevousColorDepth(int bpp) - { - int result = 0; - switch (bpp) - { - case 32: - result = 24; - break; - case 24: - result = 16; - break; - case 16: - result = 8; - break; - case 8: - result = 4; - break; - case 4: - result = 1; - break; - } - return result; - } - - /// - /// Reads a null-terminated c-string. - /// - /// Pointer to the first char of the string. - /// The converted string. - internal static unsafe string PtrToStr(byte* ptr) - { - string result = null; - if (ptr != null) - { - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - - while (*ptr != 0) - { - sb.Append((char)(*(ptr++))); - } - result = sb.ToString(); - } - return result; - } - - internal static unsafe byte[] CreateShrunkenPaletteLUT(FIBITMAP dib, out int uniqueColors) - { - byte[] result = null; - uniqueColors = 0; - - if ((!dib.IsNull) && (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) && (GetBPP(dib) <= 8)) - { - int size = (int)GetColorsUsed(dib); - List newPalette = new List(size); - List lut = new List(size); - RGBQUAD* palette = (RGBQUAD*)GetPalette(dib); - RGBQUAD color; - int index; - - for (int i = 0; i < size; i++) - { - color = palette[i]; - color.rgbReserved = 255; // ignore alpha - - index = newPalette.IndexOf(color); - if (index < 0) - { - newPalette.Add(color); - lut.Add((byte)(newPalette.Count - 1)); - } - else - { - lut.Add((byte)index); - } - } - result = lut.ToArray(); - uniqueColors = newPalette.Count; - } - return result; - } - - internal static PropertyItem CreatePropertyItem() - { - return (PropertyItem)Activator.CreateInstance(typeof(PropertyItem), true); - } - - private static unsafe void CopyPalette(FIBITMAP src, FIBITMAP dst) - { - RGBQUAD* orgPal = (RGBQUAD*)GetPalette(src); - RGBQUAD* newPal = (RGBQUAD*)GetPalette(dst); - uint size = (uint)(sizeof(RGBQUAD) * GetColorsUsed(src)); - CopyMemory(newPal, orgPal, size); - } - - private static unsafe Scanline[] Get04BitScanlines(FIBITMAP dib) - { - int height = (int)GetHeight(dib); - Scanline[] array = new Scanline[height]; - for (int i = 0; i < height; i++) - { - array[i] = new Scanline(dib, i); - } - return array; - } - - /// - /// Changes a bitmaps color depth. - /// Used by SaveEx and SaveToStream. - /// - private static FIBITMAP PrepareBitmapColorDepth(FIBITMAP dibToSave, FREE_IMAGE_FORMAT format, FREE_IMAGE_COLOR_DEPTH colorDepth) - { - FREE_IMAGE_TYPE type = GetImageType(dibToSave); - if (type == FREE_IMAGE_TYPE.FIT_BITMAP) - { - int bpp = (int)GetBPP(dibToSave); - int targetBpp = (int)(colorDepth & FREE_IMAGE_COLOR_DEPTH.FICD_COLOR_MASK); - - if (colorDepth != FREE_IMAGE_COLOR_DEPTH.FICD_AUTO) - { - // A fix colordepth was chosen - if (FIFSupportsExportBPP(format, targetBpp)) - { - dibToSave = ConvertColorDepth(dibToSave, colorDepth, false); - } - else - { - throw new ArgumentException("FreeImage\n\nFreeImage Library plugin " + - GetFormatFromFIF(format) + " is unable to write images with a color depth of " + - targetBpp + " bpp."); - } - } - else - { - // Auto selection was chosen - if (!FIFSupportsExportBPP(format, bpp)) - { - // The color depth is not supported - int bppUpper = bpp; - int bppLower = bpp; - // Check from the bitmaps current color depth in both directions - do - { - bppUpper = GetNextColorDepth(bppUpper); - if (FIFSupportsExportBPP(format, bppUpper)) - { - dibToSave = ConvertColorDepth(dibToSave, (FREE_IMAGE_COLOR_DEPTH)bppUpper, false); - break; - } - bppLower = GetPrevousColorDepth(bppLower); - if (FIFSupportsExportBPP(format, bppLower)) - { - dibToSave = ConvertColorDepth(dibToSave, (FREE_IMAGE_COLOR_DEPTH)bppLower, false); - break; - } - } while (!((bppLower == 0) && (bppUpper == 0))); - } - } - } - return dibToSave; - } - - /// - /// Compares blocks of memory. - /// - /// A pointer to a block of memory to compare. - /// A pointer to a block of memory to compare. - /// Specifies the number of bytes to be compared. - /// true, if all bytes compare as equal, false otherwise. - public static unsafe bool CompareMemory(void* buf1, void* buf2, uint length) - { - return (length == RtlCompareMemory(buf1, buf2, length)); - } - - /// - /// Compares blocks of memory. - /// - /// A pointer to a block of memory to compare. - /// A pointer to a block of memory to compare. - /// Specifies the number of bytes to be compared. - /// true, if all bytes compare as equal, false otherwise. - public static unsafe bool CompareMemory(void* buf1, void* buf2, long length) - { - return (length == RtlCompareMemory(buf1, buf2, checked((uint)length))); - } - - /// - /// Compares blocks of memory. - /// - /// A pointer to a block of memory to compare. - /// A pointer to a block of memory to compare. - /// Specifies the number of bytes to be compared. - /// true, if all bytes compare as equal, false otherwise. - public static unsafe bool CompareMemory(IntPtr buf1, IntPtr buf2, uint length) - { - return (length == RtlCompareMemory(buf1.ToPointer(), buf2.ToPointer(), length)); - } - - /// - /// Compares blocks of memory. - /// - /// A pointer to a block of memory to compare. - /// A pointer to a block of memory to compare. - /// Specifies the number of bytes to be compared. - /// true, if all bytes compare as equal, false otherwise. - public static unsafe bool CompareMemory(IntPtr buf1, IntPtr buf2, long length) - { - return (length == RtlCompareMemory(buf1.ToPointer(), buf2.ToPointer(), checked((uint)length))); - } - - /// - /// Moves a block of memory from one location to another. - /// - /// A pointer to the starting address of the move destination. - /// A pointer to the starting address of the block of memory to be moved. - /// The size of the block of memory to move, in bytes. - public static unsafe void MoveMemory(void* dst, void* src, long size) - { - MoveMemory(dst, src, checked((uint)size)); - } - - /// - /// Moves a block of memory from one location to another. - /// - /// A pointer to the starting address of the move destination. - /// A pointer to the starting address of the block of memory to be moved. - /// The size of the block of memory to move, in bytes. - public static unsafe void MoveMemory(IntPtr dst, IntPtr src, uint size) - { - MoveMemory(dst.ToPointer(), src.ToPointer(), size); - } - - /// - /// Moves a block of memory from one location to another. - /// - /// A pointer to the starting address of the move destination. - /// A pointer to the starting address of the block of memory to be moved. - /// The size of the block of memory to move, in bytes. - public static unsafe void MoveMemory(IntPtr dst, IntPtr src, long size) - { - MoveMemory(dst.ToPointer(), src.ToPointer(), checked((uint)size)); - } - - /// - /// Copies a block of memory from one location to another. - /// - /// A pointer to the starting address of the copied block's destination. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - /// - /// CopyMemory runs faster than . - /// However, if both blocks overlap the result is undefined. - /// - public static unsafe void CopyMemory(byte* dest, byte* src, int len) - { - if (len >= 0x10) - { - do - { - *((int*)dest) = *((int*)src); - *((int*)(dest + 4)) = *((int*)(src + 4)); - *((int*)(dest + 8)) = *((int*)(src + 8)); - *((int*)(dest + 12)) = *((int*)(src + 12)); - dest += 0x10; - src += 0x10; - } - while ((len -= 0x10) >= 0x10); - } - if (len > 0) - { - if ((len & 8) != 0) - { - *((int*)dest) = *((int*)src); - *((int*)(dest + 4)) = *((int*)(src + 4)); - dest += 8; - src += 8; - } - if ((len & 4) != 0) - { - *((int*)dest) = *((int*)src); - dest += 4; - src += 4; - } - if ((len & 2) != 0) - { - *((short*)dest) = *((short*)src); - dest += 2; - src += 2; - } - if ((len & 1) != 0) - { - *dest = *src; - } - } - } - - /// - /// Copies a block of memory from one location to another. - /// - /// A pointer to the starting address of the copied block's destination. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - /// - /// CopyMemory runs faster than . - /// However, if both blocks overlap the result is undefined. - /// - public static unsafe void CopyMemory(byte* dest, byte* src, long len) - { - CopyMemory(dest, src, checked((int)len)); - } - - /// - /// Copies a block of memory from one location to another. - /// - /// A pointer to the starting address of the copied block's destination. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - /// - /// CopyMemory runs faster than . - /// However, if both blocks overlap the result is undefined. - /// - public static unsafe void CopyMemory(void* dest, void* src, long len) - { - CopyMemory((byte*)dest, (byte*)src, checked((int)len)); - } - - /// - /// Copies a block of memory from one location to another. - /// - /// A pointer to the starting address of the copied block's destination. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - /// - /// CopyMemory runs faster than . - /// However, if both blocks overlap the result is undefined. - /// - public static unsafe void CopyMemory(void* dest, void* src, int len) - { - CopyMemory((byte*)dest, (byte*)src, len); - } - - /// - /// Copies a block of memory from one location to another. - /// - /// A pointer to the starting address of the copied block's destination. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - /// - /// CopyMemory runs faster than . - /// However, if both blocks overlap the result is undefined. - /// - public static unsafe void CopyMemory(IntPtr dest, IntPtr src, int len) - { - CopyMemory((byte*)dest, (byte*)src, len); - } - - /// - /// Copies a block of memory from one location to another. - /// - /// A pointer to the starting address of the copied block's destination. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - /// - /// CopyMemory runs faster than . - /// However, if both blocks overlap the result is undefined. - /// - public static unsafe void CopyMemory(IntPtr dest, IntPtr src, long len) - { - CopyMemory((byte*)dest, (byte*)src, checked((int)len)); - } - - /// - /// Copies a block of memory into an array. - /// - /// An array used as the destination of the copy process. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(Array dest, void* src, int len) - { - GCHandle handle = GCHandle.Alloc(dest, GCHandleType.Pinned); - try - { - CopyMemory((byte*)handle.AddrOfPinnedObject(), (byte*)src, len); - } - finally - { - handle.Free(); - } - } - - /// - /// Copies a block of memory into an array. - /// - /// An array used as the destination of the copy process. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(Array dest, void* src, long len) - { - CopyMemory(dest, (byte*)src, checked((int)len)); - } - - /// - /// Copies a block of memory into an array. - /// - /// An array used as the destination of the copy process. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(Array dest, IntPtr src, int len) - { - CopyMemory(dest, (byte*)src, len); - } - - /// - /// Copies a block of memory into an array. - /// - /// An array used as the destination of the copy process. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(Array dest, IntPtr src, long len) - { - CopyMemory(dest, (byte*)src, checked((int)len)); - } - - /// - /// Copies the content of an array to a memory location. - /// - /// A pointer to the starting address of the copied block's destination. - /// An array used as the source of the copy process. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(void* dest, Array src, int len) - { - GCHandle handle = GCHandle.Alloc(src, GCHandleType.Pinned); - try - { - CopyMemory((byte*)dest, (byte*)handle.AddrOfPinnedObject(), len); - } - finally - { - handle.Free(); - } - } - - /// - /// Copies the content of an array to a memory location. - /// - /// A pointer to the starting address of the copied block's destination. - /// An array used as the source of the copy process. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(void* dest, Array src, long len) - { - CopyMemory((byte*)dest, src, checked((int)len)); - } - - /// - /// Copies the content of an array to a memory location. - /// - /// A pointer to the starting address of the copied block's destination. - /// An array used as the source of the copy process. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(IntPtr dest, Array src, int len) - { - CopyMemory((byte*)dest, src, len); - } - - /// - /// Copies the content of an array to a memory location. - /// - /// A pointer to the starting address of the copied block's destination. - /// An array used as the source of the copy process. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(IntPtr dest, Array src, long len) - { - CopyMemory((byte*)dest, src, checked((int)len)); - } - - /// - /// Copies the content of one array into another array. - /// - /// An array used as the destination of the copy process. - /// An array used as the source of the copy process. - /// The size of the content to copy, in bytes. - public static unsafe void CopyMemory(Array dest, Array src, int len) - { - GCHandle dHandle = GCHandle.Alloc(dest, GCHandleType.Pinned); - try - { - GCHandle sHandle = GCHandle.Alloc(src, GCHandleType.Pinned); - try - { - CopyMemory((byte*)dHandle.AddrOfPinnedObject(), (byte*)sHandle.AddrOfPinnedObject(), len); - } - finally - { - sHandle.Free(); - } - } - finally - { - dHandle.Free(); - } - } - - /// - /// Copies the content of one array into another array. - /// - /// An array used as the destination of the copy process. - /// An array used as the source of the copy process. - /// The size of the content to copy, in bytes. - public static unsafe void CopyMemory(Array dest, Array src, long len) - { - CopyMemory(dest, src, checked((int)len)); - } - - internal static string ColorToString(Color color) - { - return string.Format( - System.Globalization.CultureInfo.CurrentCulture, - "{{Name={0}, ARGB=({1}, {2}, {3}, {4})}}", - new object[] { color.Name, color.A, color.R, color.G, color.B }); - } - - internal static void Resize(ref string str, int length) - { - if ((str != null) && (length >= 0) && (str.Length != length)) - { - char[] chars = str.ToCharArray(); - Array.Resize(ref chars, length); - str = new string(chars); - } - } - - internal static void Resize(ref string str, int min, int max) - { - if ((str != null) && (min >= 0) && (max >= 0) && (min <= max)) - { - if (str.Length < min) - { - char[] chars = str.ToCharArray(); - Array.Resize(ref chars, min); - str = new string(chars); - } - else if (str.Length > max) - { - char[] chars = str.ToCharArray(); - Array.Resize(ref chars, max); - str = new string(chars); - } - } - } - - internal static void Resize(ref T[] array, int length) - { - if ((array != null) && (length >= 0) && (array.Length != length)) - { - Array.Resize(ref array, length); - } - } - - internal static void Resize(ref T[] array, int min, int max) - { - if ((array != null) && (min >= 0) && (max >= 0) && (min <= max)) - { - if (array.Length < min) - { - Array.Resize(ref array, min); - } - else if (array.Length > max) - { - Array.Resize(ref array, max); - } - } - } - - internal static bool CheckColorType(FREE_IMAGE_TYPE imageType, T color) - { - Type type = typeof(T); - bool result; - switch (imageType) - { - case FREE_IMAGE_TYPE.FIT_BITMAP: - result = (type == typeof(RGBQUAD)); break; - case FREE_IMAGE_TYPE.FIT_COMPLEX: - result = (type == typeof(FICOMPLEX)); break; - case FREE_IMAGE_TYPE.FIT_DOUBLE: - result = (type == typeof(double)); break; - case FREE_IMAGE_TYPE.FIT_FLOAT: - result = (type == typeof(float)); break; - case FREE_IMAGE_TYPE.FIT_INT16: - result = (type == typeof(Int16)); break; - case FREE_IMAGE_TYPE.FIT_INT32: - result = (type == typeof(Int32)); break; - case FREE_IMAGE_TYPE.FIT_RGB16: - result = (type == typeof(FIRGB16)); break; - case FREE_IMAGE_TYPE.FIT_RGBA16: - result = (type == typeof(FIRGBA16)); break; - case FREE_IMAGE_TYPE.FIT_RGBAF: - result = (type == typeof(FIRGBAF)); break; - case FREE_IMAGE_TYPE.FIT_RGBF: - result = (type == typeof(FIRGBF)); break; - case FREE_IMAGE_TYPE.FIT_UINT16: - result = (type == typeof(UInt16)); break; - case FREE_IMAGE_TYPE.FIT_UINT32: - result = (type == typeof(UInt32)); break; - default: - result = false; break; - } - return result; - } - - #endregion - - #region Dll-Imports - - /// - /// Retrieves a handle to a display device context (DC) for the client area of a specified window - /// or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC. - /// - /// Handle to the window whose DC is to be retrieved. - /// If this value is IntPtr.Zero, GetDC retrieves the DC for the entire screen. - /// If the function succeeds, the return value is a handle to the DC for the specified window's client area. - /// If the function fails, the return value is NULL. - [DllImport("user32.dll")] - private static extern IntPtr GetDC(IntPtr hWnd); - - /// - /// Releases a device context (DC), freeing it for use by other applications. - /// The effect of the ReleaseDC function depends on the type of DC. It frees only common and window DCs. - /// It has no effect on class or private DCs. - /// - /// Handle to the window whose DC is to be released. - /// Handle to the DC to be released. - /// Returns true on success, false on failure. - [DllImport("user32.dll")] - private static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC); - - /// - /// Creates a DIB that applications can write to directly. - /// The function gives you a pointer to the location of the bitmap bit values. - /// You can supply a handle to a file-mapping object that the function will use to create the bitmap, - /// or you can let the system allocate the memory for the bitmap. - /// - /// Handle to a device context. - /// Pointer to a BITMAPINFO structure that specifies various attributes of the DIB, - /// including the bitmap dimensions and colors. - /// Specifies the type of data contained in the bmiColors array member of the BITMAPINFO structure - /// pointed to by pbmi (either logical palette indexes or literal RGB values). - /// Pointer to a variable that receives a pointer to the location of the DIB bit values. - /// Handle to a file-mapping object that the function will use to create the DIB. - /// This parameter can be NULL. - /// Specifies the offset from the beginning of the file-mapping object referenced by hSection - /// where storage for the bitmap bit values is to begin. This value is ignored if hSection is NULL. - /// If the function succeeds, the return value is a handle to the newly created DIB, - /// and *ppvBits points to the bitmap bit values. If the function fails, the return value is NULL, and *ppvBits is NULL. - [DllImport("gdi32.dll")] - private static extern IntPtr CreateDIBSection( - IntPtr hdc, - [In] IntPtr pbmi, - uint iUsage, - out IntPtr ppvBits, - IntPtr hSection, - uint dwOffset); - - /// - /// Deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object. - /// After the object is deleted, the specified handle is no longer valid. - /// - /// Handle to a logical pen, brush, font, bitmap, region, or palette. - /// Returns true on success, false on failure. - [DllImport("gdi32.dll")] - private static extern bool DeleteObject(IntPtr hObject); - - /// - /// Creates a compatible bitmap (DDB) from a DIB and, optionally, sets the bitmap bits. - /// - /// Handle to a device context. - /// Pointer to a bitmap information header structure. - /// Specifies how the system initializes the bitmap bits - (use 4). - /// Pointer to an array of bytes containing the initial bitmap data. - /// Pointer to a BITMAPINFO structure that describes the dimensions - /// and color format of the array pointed to by the lpbInit parameter. - /// Specifies whether the bmiColors member of the BITMAPINFO structure - /// was initialized - (use 0). - /// Handle to a DIB or null on failure. - [DllImport("gdi32.dll")] - private static extern IntPtr CreateDIBitmap( - IntPtr hdc, - IntPtr lpbmih, - uint fdwInit, - IntPtr lpbInit, - IntPtr lpbmi, - uint fuUsage); - - /// - /// Retrieves information for the specified graphics object. - /// - /// Handle to the graphics object of interest. - /// Specifies the number of bytes of information to - /// be written to the buffer. - /// Pointer to a buffer that receives the information - /// about the specified graphics object. - /// 0 on failure. - [DllImport("gdi32.dll")] - private static extern int GetObject(IntPtr hgdiobj, int cbBuffer, IntPtr lpvObject); - - /// - /// Retrieves the bits of the specified compatible bitmap and copies them into a buffer - /// as a DIB using the specified format. - /// - /// Handle to the device context. - /// Handle to the bitmap. This must be a compatible bitmap (DDB). - /// Specifies the first scan line to retrieve. - /// Specifies the number of scan lines to retrieve. - /// Pointer to a buffer to receive the bitmap data. - /// Pointer to a BITMAPINFO structure that specifies the desired - /// format for the DIB data. - /// Specifies the format of the bmiColors member of the - /// BITMAPINFO structure - (use 0). - /// 0 on failure. - [DllImport("gdi32.dll")] - private static extern unsafe int GetDIBits( - IntPtr hdc, - IntPtr hbmp, - uint uStartScan, - uint cScanLines, - IntPtr lpvBits, - IntPtr lpbmi, - uint uUsage); - - /// - /// Moves a block of memory from one location to another. - /// - /// Pointer to the starting address of the move destination. - /// Pointer to the starting address of the block of memory to be moved. - /// Size of the block of memory to move, in bytes. - [DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false)] - public static unsafe extern void MoveMemory(void* dst, void* src, uint size); - - /// - /// The RtlCompareMemory routine compares blocks of memory - /// and returns the number of bytes that are equivalent. - /// - /// A pointer to a block of memory to compare. - /// A pointer to a block of memory to compare. - /// Specifies the number of bytes to be compared. - /// RtlCompareMemory returns the number of bytes that compare as equal. - /// If all bytes compare as equal, the input Length is returned. - [DllImport("ntdll.dll", EntryPoint = "RtlCompareMemory", SetLastError = false)] - internal static unsafe extern uint RtlCompareMemory(void* buf1, void* buf2, uint count); - - #endregion - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.19 $ +// $Date: 2011/10/02 13:00:45 $ +// $Id: FreeImageWrapper.cs,v 1.19 2011/10/02 13:00:45 drolon Exp $ +// ========================================================== + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Reflection; +using System.Runtime.InteropServices; +using FreeImageAPI.IO; +using FreeImageAPI.Metadata; + +namespace FreeImageAPI +{ + /// + /// Static class importing functions from the FreeImage library + /// and providing additional functions. + /// + public static partial class FreeImage + { + #region Constants + + /// + /// Array containing all 'FREE_IMAGE_MDMODEL's. + /// + public static readonly FREE_IMAGE_MDMODEL[] FREE_IMAGE_MDMODELS = + (FREE_IMAGE_MDMODEL[])Enum.GetValues(typeof(FREE_IMAGE_MDMODEL)); + + /// + /// Stores handles used to read from streams. + /// + private static Dictionary streamHandles = + new Dictionary(); + + /// + /// Version of the wrapper library. + /// + private static Version WrapperVersion; + + private const int DIB_RGB_COLORS = 0; + private const int DIB_PAL_COLORS = 1; + private const int CBM_INIT = 0x4; + + /// + /// An uncompressed format. + /// + public const int BI_RGB = 0; + + /// + /// A run-length encoded (RLE) format for bitmaps with 8 bpp. The compression format is a 2-byte + /// format consisting of a count byte followed by a byte containing a color index. + /// + public const int BI_RLE8 = 1; + + /// + /// An RLE format for bitmaps with 4 bpp. The compression format is a 2-byte format consisting + /// of a count byte followed by two word-length color indexes. + /// + public const int BI_RLE4 = 2; + + /// + /// Specifies that the bitmap is not compressed and that the color table consists of three + /// DWORD color masks that specify the red, green, and blue components, respectively, + /// of each pixel. This is valid when used with 16- and 32-bpp bitmaps. + /// + public const int BI_BITFIELDS = 3; + + /// + /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a JPEG image. + /// + public const int BI_JPEG = 4; + + /// + /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a PNG image. + /// + public const int BI_PNG = 5; + + #endregion + + #region General functions + + /// + /// Returns the internal version of this FreeImage .NET wrapper. + /// + /// The internal version of this FreeImage .NET wrapper. + public static Version GetWrapperVersion() + { + if (WrapperVersion == null) + { + try + { + object[] attributes = Assembly.GetAssembly(typeof(FreeImage)) + .GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false); + if ((attributes != null) && (attributes.Length != 0)) + { + AssemblyFileVersionAttribute attribute = + attributes[0] as AssemblyFileVersionAttribute; + if ((attribute != null) && (attribute.Version != null)) + { + return (WrapperVersion = new Version(attribute.Version)); + } + } + } + catch + { + + } + + WrapperVersion = new Version(); + } + + return WrapperVersion; + } + + /// + /// Returns the version of the native FreeImage library. + /// + /// The version of the native FreeImage library. + public static Version GetNativeVersion() + { + return new Version(GetVersion()); + } + + /// + /// Returns a value indicating if the FreeImage library is available or not. + /// See remarks for further details. + /// + /// false if the file is not available or out of date; + /// true, otherwise. + /// + /// The FreeImage.NET library is a wrapper for the native C++ library + /// (FreeImage.dll ... dont mix ist up with this library FreeImageNet.dll). + /// The native library must be either in the same folder as the program's + /// executable or in a folder contained in the envirent variable PATH + /// (for example %WINDIR%\System32). + /// Further more must both libraries, including the program itself, + /// be the same architecture (x86 or x64). + /// + public static bool IsAvailable() + { + try + { + // Call a static fast executing function + Version nativeVersion = new Version(GetVersion()); + Version wrapperVersion = GetWrapperVersion(); + // No exception thrown, the library seems to be present + return + (nativeVersion.Major > wrapperVersion.Major) || + ((nativeVersion.Major == wrapperVersion.Major) && (nativeVersion.Minor > wrapperVersion.Minor)) || + ((nativeVersion.Major == wrapperVersion.Major) && (nativeVersion.Minor == wrapperVersion.Minor) && (nativeVersion.Build >= wrapperVersion.Build)); + } + catch (DllNotFoundException) + { + return false; + } + catch (EntryPointNotFoundException) + { + return false; + } + catch (BadImageFormatException) + { + return false; + } + } + + #endregion + + #region Bitmap management functions + + /// + /// Creates a new bitmap in memory. + /// + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new Bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap + /// Handle to a FreeImage bitmap. + public static FIBITMAP Allocate(int width, int height, int bpp) + { + return Allocate(width, height, bpp, 0, 0, 0); + } + + /// + /// Creates a new bitmap in memory. + /// + /// Type of the image. + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new Bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap + /// Handle to a FreeImage bitmap. + public static FIBITMAP AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp) + { + return AllocateT(type, width, height, bpp, 0, 0, 0); + } + + /// + /// Allocates a new image of the specified width, height and bit depth and optionally + /// fills it with the specified color. See remarks for further details. + /// + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmaps. + /// The color to fill the bitmap with or null. + /// Options to enable or disable function-features. + /// The palette of the bitmap or null. + /// Handle to a FreeImage bitmap. + /// + /// This function is an extension to , which additionally supports + /// specifying a palette to be set for the newly create image, as well as specifying a + /// background color, the newly created image should initially be filled with. + /// + /// Basically, this function internally relies on function , followed by a + /// call to . This is why both parameters + /// and behave the same as it is + /// documented for function . + /// So, please refer to the documentation of to + /// learn more about parameters and . + /// + /// The palette specified through parameter is only copied to the + /// newly created image, if the desired bit depth is smaller than or equal to 8 bits per pixel. + /// In other words, the parameter is only taken into account for + /// palletized images. So, for an 8-bit image, the length is 256, for an 4-bit image it is 16 + /// and it is 2 for a 1-bit image. In other words, this function does not support partial palettes. + /// + /// However, specifying a palette is not necesarily needed, even for palletized images. This + /// function is capable of implicitly creating a palette, if is null. + /// If the specified background color is a greyscale value (red = green = blue) or if option + /// is specified, a greyscale palette + /// is created. For a 1-bit image, only if the specified background color is either black or white, + /// a monochrome palette, consisting of black and white only is created. In any case, the darker + /// colors are stored at the smaller palette indices. + /// + /// If the specified background color is not a greyscale value, or is neither black nor white + /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized + /// palette. For this operation, option + /// is implicit, so the specified is applied to the palette entry, + /// specified by the background color's field. + /// The image is then filled with this palette index. + /// + /// This function returns a newly created image as function does, if both + /// parameters and are null. + /// If only is null, the palette pointed to by + /// parameter is initially set for the new image, if a palletized + /// image of type is created. + /// However, in the latter case, this function returns an image, whose + /// pixels are all initialized with zeros so, the image will be filled with the color of the + /// first palette entry. + /// + public static FIBITMAP AllocateEx(int width, int height, int bpp, + RGBQUAD? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette) + { + return AllocateEx(width, height, bpp, color, options, palette, 0, 0, 0); + } + + /// + /// Allocates a new image of the specified width, height and bit depth and optionally + /// fills it with the specified color. See remarks for further details. + /// + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmaps. + /// The color to fill the bitmap with or null. + /// Options to enable or disable function-features. + /// The palette of the bitmap or null. + /// Red part of the color layout. + /// eg: 0xFF0000 + /// Green part of the color layout. + /// eg: 0x00FF00 + /// Blue part of the color layout. + /// eg: 0x0000FF + /// Handle to a FreeImage bitmap. + /// + /// This function is an extension to , which additionally supports + /// specifying a palette to be set for the newly create image, as well as specifying a + /// background color, the newly created image should initially be filled with. + /// + /// Basically, this function internally relies on function , followed by a + /// call to . This is why both parameters + /// and behave the same as it is + /// documented for function . + /// So, please refer to the documentation of to + /// learn more about parameters and . + /// + /// The palette specified through parameter is only copied to the + /// newly created image, if the desired bit depth is smaller than or equal to 8 bits per pixel. + /// In other words, the parameter is only taken into account for + /// palletized images. So, for an 8-bit image, the length is 256, for an 4-bit image it is 16 + /// and it is 2 for a 1-bit image. In other words, this function does not support partial palettes. + /// + /// However, specifying a palette is not necesarily needed, even for palletized images. This + /// function is capable of implicitly creating a palette, if is null. + /// If the specified background color is a greyscale value (red = green = blue) or if option + /// is specified, a greyscale palette + /// is created. For a 1-bit image, only if the specified background color is either black or white, + /// a monochrome palette, consisting of black and white only is created. In any case, the darker + /// colors are stored at the smaller palette indices. + /// + /// If the specified background color is not a greyscale value, or is neither black nor white + /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized + /// palette. For this operation, option + /// is implicit, so the specified is applied to the palette entry, + /// specified by the background color's field. + /// The image is then filled with this palette index. + /// + /// This function returns a newly created image as function does, if both + /// parameters and are null. + /// If only is null, the palette pointed to by + /// parameter is initially set for the new image, if a palletized + /// image of type is created. + /// However, in the latter case, this function returns an image, whose + /// pixels are all initialized with zeros so, the image will be filled with the color of the + /// first palette entry. + /// + public static FIBITMAP AllocateEx(int width, int height, int bpp, + RGBQUAD? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, + uint red_mask, uint green_mask, uint blue_mask) + { + if ((palette != null) && (bpp <= 8) && (palette.Length < (1 << bpp))) + return FIBITMAP.Zero; + + if (color.HasValue) + { + GCHandle handle = new GCHandle(); + try + { + RGBQUAD[] buffer = new RGBQUAD[] { color.Value }; + handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + return AllocateEx(width, height, bpp, handle.AddrOfPinnedObject(), + options, palette, red_mask, green_mask, blue_mask); + } + finally + { + if (handle.IsAllocated) + handle.Free(); + } + } + else + { + return AllocateEx(width, height, bpp, IntPtr.Zero, + options, palette, red_mask, green_mask, blue_mask); + } + } + + /// + /// Allocates a new image of the specified type, width, height and bit depth and optionally + /// fills it with the specified color. See remarks for further details. + /// + /// The type of the specified color. + /// Type of the image. + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap + /// The color to fill the bitmap with or null. + /// Options to enable or disable function-features. + /// The palette of the bitmap or null. + /// Handle to a FreeImage bitmap. + /// + /// This function is an extension to , which additionally supports + /// specifying a palette to be set for the newly create image, as well as specifying a + /// background color, the newly created image should initially be filled with. + /// + /// Basically, this function internally relies on function , followed by a + /// call to . This is why both parameters + /// and behave the same as it is + /// documented for function . So, please refer to the + /// documentation of to learn more about parameters color and options. + /// + /// The palette specified through parameter palette is only copied to the newly created + /// image, if its image type is and the desired bit + /// depth is smaller than or equal to 8 bits per pixel. In other words, the + /// palette is only taken into account for palletized images. However, if the preceding conditions + /// match and if is not null, the palette is assumed to be at + /// least as large as the size of a fully populated palette for the desired bit depth. + /// So, for an 8-bit image, this length is 256, for an 4-bit image it is 16 and it is + /// 2 for a 1-bit image. In other words, this function does not support partial palettes. + /// + /// However, specifying a palette is not necesarily needed, even for palletized images. This + /// function is capable of implicitly creating a palette, if is null. + /// If the specified background color is a greyscale value (red = green = blue) or if option + /// is specified, a greyscale palette + /// is created. For a 1-bit image, only if the specified background color is either black or white, + /// a monochrome palette, consisting of black and white only is created. In any case, the darker + /// colors are stored at the smaller palette indices. + /// + /// If the specified background color is not a greyscale value, or is neither black nor white + /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized + /// palette. For this operation, option + /// is implicit, so the specified color is applied to the palette entry, specified by the + /// background color's field. The image is then filled with + /// this palette index. + /// + /// This function returns a newly created image as function does, if both + /// parameters and are null. + /// If only is null, the palette pointed to by + /// parameter is initially set for the new image, if a palletized + /// image of type is created. + /// However, in the latter case, this function returns an image, whose + /// pixels are all initialized with zeros so, the image will be filled with the color of the + /// first palette entry. + /// + public static FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp, + T? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette) where T : struct + { + return AllocateExT(type, width, height, bpp, color, options, palette, 0, 0, 0); + } + + /// + /// Allocates a new image of the specified type, width, height and bit depth and optionally + /// fills it with the specified color. See remarks for further details. + /// + /// The type of the specified color. + /// Type of the image. + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap + /// The color to fill the bitmap with or null. + /// Options to enable or disable function-features. + /// The palette of the bitmap or null. + /// Red part of the color layout. + /// eg: 0xFF0000 + /// Green part of the color layout. + /// eg: 0x00FF00 + /// Blue part of the color layout. + /// eg: 0x0000FF + /// Handle to a FreeImage bitmap. + /// + /// This function is an extension to , which additionally supports + /// specifying a palette to be set for the newly create image, as well as specifying a + /// background color, the newly created image should initially be filled with. + /// + /// Basically, this function internally relies on function , followed by a + /// call to . This is why both parameters + /// and behave the same as it is + /// documented for function . So, please refer to the + /// documentation of to learn more about parameters color and options. + /// + /// The palette specified through parameter palette is only copied to the newly created + /// image, if its image type is and the desired bit + /// depth is smaller than or equal to 8 bits per pixel. In other words, the + /// palette is only taken into account for palletized images. However, if the preceding conditions + /// match and if is not null, the palette is assumed to be at + /// least as large as the size of a fully populated palette for the desired bit depth. + /// So, for an 8-bit image, this length is 256, for an 4-bit image it is 16 and it is + /// 2 for a 1-bit image. In other words, this function does not support partial palettes. + /// + /// However, specifying a palette is not necesarily needed, even for palletized images. This + /// function is capable of implicitly creating a palette, if is null. + /// If the specified background color is a greyscale value (red = green = blue) or if option + /// is specified, a greyscale palette + /// is created. For a 1-bit image, only if the specified background color is either black or white, + /// a monochrome palette, consisting of black and white only is created. In any case, the darker + /// colors are stored at the smaller palette indices. + /// + /// If the specified background color is not a greyscale value, or is neither black nor white + /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized + /// palette. For this operation, option + /// is implicit, so the specified color is applied to the palette entry, specified by the + /// background color's field. The image is then filled with + /// this palette index. + /// + /// This function returns a newly created image as function does, if both + /// parameters and are null. + /// If only is null, the palette pointed to by + /// parameter is initially set for the new image, if a palletized + /// image of type is created. + /// However, in the latter case, this function returns an image, whose + /// pixels are all initialized with zeros so, the image will be filled with the color of the + /// first palette entry. + /// + public static FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp, + T? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, + uint red_mask, uint green_mask, uint blue_mask) where T : struct + { + if ((palette != null) && (bpp <= 8) && (palette.Length < (1 << bpp))) + return FIBITMAP.Zero; + + if (color.HasValue) + { + if (!CheckColorType(type, color.Value)) + return FIBITMAP.Zero; + + GCHandle handle = new GCHandle(); + try + { + T[] buffer = new T[] { color.Value }; + handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + return AllocateExT(type, width, height, bpp, handle.AddrOfPinnedObject(), + options, palette, red_mask, green_mask, blue_mask); + } + finally + { + if (handle.IsAllocated) + handle.Free(); + } + } + else + { + return AllocateExT(type, width, height, bpp, IntPtr.Zero, + options, palette, red_mask, green_mask, blue_mask); + } + } + + /// + /// Converts a FreeImage bitmap to a .NET . + /// + /// Handle to a FreeImage bitmap. + /// The converted .NET . + /// Copying metadata has been disabled until a proper way + /// of reading and storing metadata in a .NET bitmap is found. + /// + /// is null. + /// + /// The image type of is not FIT_BITMAP. + public static Bitmap GetBitmap(FIBITMAP dib) + { + return GetBitmap(dib, true); + } + + /// + /// Converts a FreeImage bitmap to a .NET . + /// + /// Handle to a FreeImage bitmap. + /// When true existing metadata will be copied. + /// The converted .NET . + /// Copying metadata has been disabled until a proper way + /// of reading and storing metadata in a .NET bitmap is found. + /// + /// is null. + /// + /// The image type of is not FIT_BITMAP. + internal static Bitmap GetBitmap(FIBITMAP dib, bool copyMetadata) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + if (GetImageType(dib) != FREE_IMAGE_TYPE.FIT_BITMAP) + { + throw new ArgumentException("Only bitmaps with type of FIT_BITMAP can be converted."); + } + + PixelFormat format = GetPixelFormat(dib); + + if ((format == PixelFormat.Undefined) && (GetBPP(dib) == 16u)) + { + throw new ArgumentException("Only 16bit 555 and 565 are supported."); + } + + int height = (int)GetHeight(dib); + int width = (int)GetWidth(dib); + int pitch = (int)GetPitch(dib); + + Bitmap result = new Bitmap(width, height, format); + BitmapData data; + // Locking the complete bitmap in writeonly mode + data = result.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, format); + // Writing the bitmap data directly into the new created .NET bitmap. + ConvertToRawBits(data.Scan0, dib, pitch, GetBPP(dib), + GetRedMask(dib), GetGreenMask(dib), GetBlueMask(dib), true); + // Unlock the bitmap + result.UnlockBits(data); + // Apply the bitmap resolution + if((GetResolutionX(dib) > 0) && (GetResolutionY(dib) > 0)) + { + // SetResolution will throw an exception when zero values are given on input + result.SetResolution(GetResolutionX(dib), GetResolutionY(dib)); + } + // Check whether the bitmap has a palette + if (GetPalette(dib) != IntPtr.Zero) + { + // Get the bitmaps palette to apply changes + ColorPalette palette = result.Palette; + // Get the orgininal palette + Color[] colorPalette = new Palette(dib).ColorData; + // Get the maximum number of palette entries to copy + int entriesToCopy = Math.Min(colorPalette.Length, palette.Entries.Length); + + // Check whether the bitmap is transparent + if (IsTransparent(dib)) + { + byte[] transTable = GetTransparencyTableEx(dib); + int i = 0; + int maxEntriesWithTrans = Math.Min(entriesToCopy, transTable.Length); + // Copy palette entries and include transparency + for (; i < maxEntriesWithTrans; i++) + { + palette.Entries[i] = Color.FromArgb(transTable[i], colorPalette[i]); + } + // Copy palette entries and that have no transparancy + for (; i < entriesToCopy; i++) + { + palette.Entries[i] = Color.FromArgb(0xFF, colorPalette[i]); + } + } + else + { + for (int i = 0; i < entriesToCopy; i++) + { + palette.Entries[i] = colorPalette[i]; + } + } + + // Set the bitmaps palette + result.Palette = palette; + } + // Copy metadata + if (copyMetadata) + { + try + { + List list = new List(); + // Get a list of all types + FITAG tag; + FIMETADATA mData; + foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS) + { + // Get a unique search handle + mData = FindFirstMetadata(model, dib, out tag); + // Check if metadata exists for this type + if (mData.IsNull) continue; + do + { + PropertyItem propItem = CreatePropertyItem(); + propItem.Len = (int)GetTagLength(tag); + propItem.Id = (int)GetTagID(tag); + propItem.Type = (short)GetTagType(tag); + byte[] buffer = new byte[propItem.Len]; + + unsafe + { + byte* src = (byte*)GetTagValue(tag); + fixed (byte* dst = buffer) + { + CopyMemory(dst, src, (uint)propItem.Len); + } + } + + propItem.Value = buffer; + list.Add(propItem); + } + while (FindNextMetadata(mData, out tag)); + FindCloseMetadata(mData); + } + foreach (PropertyItem propItem in list) + { + result.SetPropertyItem(propItem); + } + } + catch + { + } + } + return result; + } + + /// + /// Converts an .NET into a FreeImage bitmap. + /// + /// The to convert. + /// Handle to a FreeImage bitmap. + /// Copying metadata has been disabled until a proper way + /// of reading and storing metadata in a .NET bitmap is found. + /// + /// is null. + /// + /// The bitmaps pixelformat is invalid. + public static FIBITMAP CreateFromBitmap(Bitmap bitmap) + { + return CreateFromBitmap(bitmap, false); + } + + /// + /// Converts an .NET into a FreeImage bitmap. + /// + /// The to convert. + /// When true existing metadata will be copied. + /// Handle to a FreeImage bitmap. + /// Copying metadata has been disabled until a proper way + /// of reading and storing metadata in a .NET bitmap is found. + /// + /// is null. + /// + /// The bitmaps pixelformat is invalid. + internal static FIBITMAP CreateFromBitmap(Bitmap bitmap, bool copyMetadata) + { + if (bitmap == null) + { + throw new ArgumentNullException("bitmap"); + } + uint bpp, red_mask, green_mask, blue_mask; + FREE_IMAGE_TYPE type; + if (!GetFormatParameters(bitmap.PixelFormat, out type, out bpp, out red_mask, out green_mask, out blue_mask)) + { + throw new ArgumentException("The bitmaps pixelformat is invalid."); + } + + // Locking the complete bitmap in readonly mode + BitmapData data = bitmap.LockBits( + new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat); + // Copying the bitmap data directly from the .NET bitmap + FIBITMAP result = ConvertFromRawBits( + data.Scan0, + type, + data.Width, + data.Height, + data.Stride, + bpp, + red_mask, + green_mask, + blue_mask, + true); + bitmap.UnlockBits(data); + // Handle palette + if (GetPalette(result) != IntPtr.Zero) + { + Palette palette = new Palette(result); + Color[] colors = bitmap.Palette.Entries; + // Only copy available palette entries + int entriesToCopy = Math.Min(palette.Length, colors.Length); + byte[] transTable = new byte[entriesToCopy]; + for (int i = 0; i < entriesToCopy; i++) + { + RGBQUAD color = (RGBQUAD)colors[i]; + color.rgbReserved = 0x00; + palette[i] = color; + transTable[i] = colors[i].A; + } + if ((bitmap.Flags & (int)ImageFlags.HasAlpha) != 0) + { + FreeImage.SetTransparencyTable(result, transTable); + } + } + // Handle meta data + // Disabled + //if (copyMetadata) + //{ + // foreach (PropertyItem propItem in bitmap.PropertyItems) + // { + // FITAG tag = CreateTag(); + // SetTagLength(tag, (uint)propItem.Len); + // SetTagID(tag, (ushort)propItem.Id); + // SetTagType(tag, (FREE_IMAGE_MDTYPE)propItem.Type); + // SetTagValue(tag, propItem.Value); + // SetMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, result, "", tag); + // } + //} + return result; + } + + /// + /// Converts a raw bitmap to a FreeImage bitmap. + /// + /// Array of bytes containing the raw bitmap. + /// The type of the raw bitmap. + /// The width in pixels of the raw bitmap. + /// The height in pixels of the raw bitmap. + /// Defines the total width of a scanline in the raw bitmap, + /// including padding bytes. + /// The bit depth (bits per pixel) of the raw bitmap. + /// The bit mask describing the bits used to store a single + /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// If true, the raw bitmap is stored in top-down order (top-left pixel first) + /// and in bottom-up order (bottom-left pixel first) otherwise. + /// Handle to a FreeImage bitmap. + public static unsafe FIBITMAP ConvertFromRawBits( + byte[] bits, + FREE_IMAGE_TYPE type, + int width, + int height, + int pitch, + uint bpp, + uint red_mask, + uint green_mask, + uint blue_mask, + bool topdown) + { + fixed (byte* ptr = bits) + { + return ConvertFromRawBits( + (IntPtr)ptr, + type, + width, + height, + pitch, + bpp, + red_mask, + green_mask, + blue_mask, + topdown); + } + } + + /// + /// Converts a raw bitmap to a FreeImage bitmap. + /// + /// Pointer to the memory block containing the raw bitmap. + /// The type of the raw bitmap. + /// The width in pixels of the raw bitmap. + /// The height in pixels of the raw bitmap. + /// Defines the total width of a scanline in the raw bitmap, + /// including padding bytes. + /// The bit depth (bits per pixel) of the raw bitmap. + /// The bit mask describing the bits used to store a single + /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// If true, the raw bitmap is stored in top-down order (top-left pixel first) + /// and in bottom-up order (bottom-left pixel first) otherwise. + /// Handle to a FreeImage bitmap. + public static unsafe FIBITMAP ConvertFromRawBits( + IntPtr bits, + FREE_IMAGE_TYPE type, + int width, + int height, + int pitch, + uint bpp, + uint red_mask, + uint green_mask, + uint blue_mask, + bool topdown) + { + byte* addr = (byte*)bits; + if ((addr == null) || (width <= 0) || (height <= 0)) + { + return FIBITMAP.Zero; + } + + FIBITMAP dib = AllocateT(type, width, height, (int)bpp, red_mask, green_mask, blue_mask); + if (dib != FIBITMAP.Zero) + { + if (topdown) + { + for (int i = height - 1; i >= 0; --i) + { + CopyMemory((byte*)GetScanLine(dib, i), addr, (int)GetLine(dib)); + addr += pitch; + } + } + else + { + for (int i = 0; i < height; ++i) + { + CopyMemory((byte*)GetScanLine(dib, i), addr, (int)GetLine(dib)); + addr += pitch; + } + } + } + return dib; + } + + /// + /// Saves a .NET to a file. + /// + /// The .NET to save. + /// Name of the file to save to. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// The bitmaps pixelformat is invalid. + public static bool SaveBitmap(Bitmap bitmap, string filename) + { + return SaveBitmap( + bitmap, + filename, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + /// + /// Saves a .NET to a file. + /// + /// The .NET to save. + /// Name of the file to save to. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// The bitmaps pixelformat is invalid. + public static bool SaveBitmap(Bitmap bitmap, string filename, FREE_IMAGE_SAVE_FLAGS flags) + { + return SaveBitmap( + bitmap, + filename, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + flags); + } + + /// + /// Saves a .NET to a file. + /// + /// The .NET to save. + /// Name of the file to save to. + /// Format of the bitmap. If the format should be taken from the + /// filename use . + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// The bitmaps pixelformat is invalid. + public static bool SaveBitmap( + Bitmap bitmap, + string filename, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_SAVE_FLAGS flags) + { + FIBITMAP dib = CreateFromBitmap(bitmap); + bool result = SaveEx(dib, filename, format, flags); + Unload(dib); + return result; + } + + /// + /// Loads a FreeImage bitmap. + /// The file will be loaded with default loading flags. + /// + /// The complete name of the file to load. + /// Handle to a FreeImage bitmap. + /// + /// does not exists. + public static FIBITMAP LoadEx(string filename) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return LoadEx(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); + } + + /// + /// Loads a FreeImage bitmap. + /// Load flags can be provided by the flags parameter. + /// + /// The complete name of the file to load. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage bitmap. + /// + /// does not exists. + public static FIBITMAP LoadEx(string filename, FREE_IMAGE_LOAD_FLAGS flags) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return LoadEx(filename, flags, ref format); + } + + /// + /// Loads a FreeImage bitmap. + /// In case the loading format is the files + /// real format is being analysed. If no plugin can read the file, format remains + /// and 0 is returned. + /// The file will be loaded with default loading flags. + /// + /// The complete name of the file to load. + /// Format of the image. If the format is unknown use + /// . + /// In case a suitable format was found by LoadEx it will be returned in format. + /// Handle to a FreeImage bitmap. + /// + /// does not exists. + public static FIBITMAP LoadEx(string filename, ref FREE_IMAGE_FORMAT format) + { + return LoadEx(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); + } + + /// + /// Loads a FreeImage bitmap. + /// In case the loading format is the files + /// real format is being analysed. If no plugin can read the file, format remains + /// and 0 is returned. + /// Load flags can be provided by the flags parameter. + /// + /// The complete name of the file to load. + /// Flags to enable or disable plugin-features. + /// Format of the image. If the format is unknown use + /// . + /// In case a suitable format was found by LoadEx it will be returned in format. + /// + /// Handle to a FreeImage bitmap. + /// + /// does not exists. + public static FIBITMAP LoadEx(string filename, FREE_IMAGE_LOAD_FLAGS flags, ref FREE_IMAGE_FORMAT format) + { + // check if file exists + if (!File.Exists(filename)) + { + throw new FileNotFoundException(filename + " could not be found."); + } + FIBITMAP dib = new FIBITMAP(); + if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) + { + // query all plugins to see if one can read the file + format = GetFileType(filename, 0); + } + // check if the plugin is capable of loading files + if (FIFSupportsReading(format)) + { + dib = Load(format, filename, flags); + } + return dib; + } + + /// + /// Loads a .NET from a file. + /// + /// Name of the file to be loaded. + /// Format of the image. If the format should be taken from the + /// filename use . + /// Flags to enable or disable plugin-features. + /// The loaded .NET . + /// + /// does not exists. + /// + /// The image type of the image is not . + public static Bitmap LoadBitmap(string filename, FREE_IMAGE_LOAD_FLAGS flags, ref FREE_IMAGE_FORMAT format) + { + FIBITMAP dib = LoadEx(filename, flags, ref format); + Bitmap result = GetBitmap(dib, true); + Unload(dib); + return result; + } + + /// + /// Deletes a previously loaded FreeImage bitmap from memory and resets the handle to 0. + /// + /// Handle to a FreeImage bitmap. + public static void UnloadEx(ref FIBITMAP dib) + { + if (!dib.IsNull) + { + Unload(dib); + dib.SetNull(); + } + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// The format is taken off the filename. + /// If no suitable format was found false will be returned. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified. + /// Returns true on success, false on failure. + /// + /// or is null. + public static bool SaveEx(FIBITMAP dib, string filename) + { + return SaveEx( + ref dib, + filename, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + FREE_IMAGE_SAVE_FLAGS.DEFAULT, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + false); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// In case the loading format is + /// the format is taken off the filename. + /// If no suitable format was found false will be returned. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified. + /// Format of the image. If the format should be taken from the + /// filename use . + /// Returns true on success, false on failure. + /// + /// or is null. + public static bool SaveEx( + FIBITMAP dib, + string filename, + FREE_IMAGE_FORMAT format) + { + return SaveEx( + ref dib, + filename, + format, + FREE_IMAGE_SAVE_FLAGS.DEFAULT, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + false); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// The format is taken off the filename. + /// If no suitable format was found false will be returned. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified. + /// When true the structure will be unloaded on success. + /// If the function failed and returned false, the bitmap was not unloaded. + /// Returns true on success, false on failure. + /// + /// or is null. + public static bool SaveEx( + ref FIBITMAP dib, + string filename, + bool unloadSource) + { + return SaveEx( + ref dib, + filename, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + FREE_IMAGE_SAVE_FLAGS.DEFAULT, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + unloadSource); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// The format is taken off the filename. + /// If no suitable format was found false will be returned. + /// Save flags can be provided by the flags parameter. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + /// + /// or is null. + public static bool SaveEx( + FIBITMAP dib, + string filename, + FREE_IMAGE_SAVE_FLAGS flags) + { + return SaveEx( + ref dib, + filename, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + flags, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + false); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// The format is taken off the filename. + /// If no suitable format was found false will be returned. + /// Save flags can be provided by the flags parameter. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified. + /// Flags to enable or disable plugin-features. + /// When true the structure will be unloaded on success. + /// If the function failed and returned false, the bitmap was not unloaded. + /// Returns true on success, false on failure. + /// + /// or is null. + public static bool SaveEx( + ref FIBITMAP dib, + string filename, + FREE_IMAGE_SAVE_FLAGS flags, + bool unloadSource) + { + return SaveEx( + ref dib, + filename, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + flags, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + unloadSource); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// In case the loading format is + /// the format is taken off the filename. + /// If no suitable format was found false will be returned. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified. + /// Format of the image. If the format should be taken from the + /// filename use . + /// When true the structure will be unloaded on success. + /// If the function failed and returned false, the bitmap was not unloaded. + /// Returns true on success, false on failure. + /// + /// or is null. + public static bool SaveEx( + ref FIBITMAP dib, + string filename, + FREE_IMAGE_FORMAT format, + bool unloadSource) + { + return SaveEx( + ref dib, + filename, + format, + FREE_IMAGE_SAVE_FLAGS.DEFAULT, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + unloadSource); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// In case the loading format is + /// the format is taken off the filename. + /// If no suitable format was found false will be returned. + /// Save flags can be provided by the flags parameter. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified. + /// Format of the image. If the format should be taken from the + /// filename use . + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + /// + /// or is null. + public static bool SaveEx( + FIBITMAP dib, + string filename, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_SAVE_FLAGS flags) + { + return SaveEx( + ref dib, + filename, + format, + flags, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + false); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// In case the loading format is + /// the format is taken off the filename. + /// If no suitable format was found false will be returned. + /// Save flags can be provided by the flags parameter. + /// The bitmaps color depth can be set by 'colorDepth'. + /// If set to a suitable color depth + /// will be taken if available. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified. + /// Format of the image. If the format should be taken from the + /// filename use . + /// Flags to enable or disable plugin-features. + /// The new color depth of the bitmap. + /// Set to if Save should take the + /// best suitable color depth. + /// If a color depth is selected that the provided format cannot write an + /// error-message will be thrown. + /// When true the structure will be unloaded on success. + /// If the function failed and returned false, the bitmap was not unloaded. + /// Returns true on success, false on failure. + /// + /// A direct color conversion failed. + /// + /// or is null. + public static bool SaveEx( + ref FIBITMAP dib, + string filename, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_SAVE_FLAGS flags, + FREE_IMAGE_COLOR_DEPTH colorDepth, + bool unloadSource) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + if (filename == null) + { + throw new ArgumentNullException("filename"); + } + bool result = false; + // Gets format from filename if the format is unknown + if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) + { + format = GetFIFFromFilename(filename); + } + if (format != FREE_IMAGE_FORMAT.FIF_UNKNOWN) + { + // Checks writing support + if (FIFSupportsWriting(format) && FIFSupportsExportType(format, GetImageType(dib))) + { + // Check valid filename and correct it if needed + if (!IsFilenameValidForFIF(format, filename)) + { + string extension = GetPrimaryExtensionFromFIF(format); + filename = Path.ChangeExtension(filename, extension); + } + + FIBITMAP dibToSave = PrepareBitmapColorDepth(dib, format, colorDepth); + try + { + result = Save(format, dibToSave, filename, flags); + } + finally + { + // Always unload a temporary created bitmap. + if (dibToSave != dib) + { + UnloadEx(ref dibToSave); + } + // On success unload the bitmap + if (result && unloadSource) + { + UnloadEx(ref dib); + } + } + } + } + return result; + } + + /// + /// Loads a FreeImage bitmap. + /// The stream must be set to the correct position before calling LoadFromStream. + /// + /// The stream to read from. + /// Handle to a FreeImage bitmap. + /// + /// is null. + /// + /// is not capable of reading. + public static FIBITMAP LoadFromStream(Stream stream) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return LoadFromStream(stream, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); + } + + /// + /// Loads a FreeImage bitmap. + /// The stream must be set to the correct position before calling LoadFromStream. + /// + /// The stream to read from. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage bitmap. + /// + /// is null. + /// + /// is not capable of reading. + public static FIBITMAP LoadFromStream(Stream stream, FREE_IMAGE_LOAD_FLAGS flags) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return LoadFromStream(stream, flags, ref format); + } + + /// + /// Loads a FreeImage bitmap. + /// In case the loading format is the + /// bitmaps real format is being analysed. + /// The stream must be set to the correct position before calling LoadFromStream. + /// + /// The stream to read from. + /// Format of the image. If the format is unknown use + /// . + /// In case a suitable format was found by LoadFromStream it will be returned in format. + /// Handle to a FreeImage bitmap. + /// + /// is null. + /// + /// is not capable of reading. + public static FIBITMAP LoadFromStream(Stream stream, ref FREE_IMAGE_FORMAT format) + { + return LoadFromStream(stream, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); + } + + /// + /// Loads a FreeImage bitmap. + /// In case the loading format is + /// the bitmaps real format is being analysed. + /// The stream must be set to the correct position before calling LoadFromStream. + /// + /// The stream to read from. + /// Flags to enable or disable plugin-features. + /// Format of the image. If the format is unknown use + /// . + /// In case a suitable format was found by LoadFromStream it will be returned in format. + /// Handle to a FreeImage bitmap. + /// + /// is null. + /// + /// is not capable of reading. + public static FIBITMAP LoadFromStream( + Stream stream, + FREE_IMAGE_LOAD_FLAGS flags, + ref FREE_IMAGE_FORMAT format) + { + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + if (!stream.CanRead) + { + throw new ArgumentException("stream is not capable of reading."); + } + // Wrap the source stream if it is unable to seek (which is required by FreeImage) + stream = (stream.CanSeek) ? stream : new StreamWrapper(stream, true); + + stream.Position = 0L; + if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) + { + // Get the format of the bitmap + format = GetFileTypeFromStream(stream); + // Restore the streams position + stream.Position = 0L; + } + if (!FIFSupportsReading(format)) + { + return FIBITMAP.Zero; + } + // Create a 'FreeImageIO' structure for calling 'LoadFromHandle' + // using the internal structure 'FreeImageStreamIO'. + FreeImageIO io = FreeImageStreamIO.io; + using (fi_handle handle = new fi_handle(stream)) + { + return LoadFromHandle(format, ref io, handle, flags); + } + } + + /// + /// Saves a previously loaded FreeImage bitmap to a stream. + /// The stream must be set to the correct position before calling SaveToStream. + /// + /// Handle to a FreeImage bitmap. + /// The stream to write to. + /// Format of the image. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// cannot write. + public static bool SaveToStream( + FIBITMAP dib, + Stream stream, + FREE_IMAGE_FORMAT format) + { + return SaveToStream( + ref dib, + stream, + format, + FREE_IMAGE_SAVE_FLAGS.DEFAULT, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + false); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a stream. + /// The stream must be set to the correct position before calling SaveToStream. + /// + /// Handle to a FreeImage bitmap. + /// The stream to write to. + /// Format of the image. + /// When true the structure will be unloaded on success. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// cannot write. + public static bool SaveToStream( + ref FIBITMAP dib, + Stream stream, + FREE_IMAGE_FORMAT format, + bool unloadSource) + { + return SaveToStream( + ref dib, + stream, + format, + FREE_IMAGE_SAVE_FLAGS.DEFAULT, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + unloadSource); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a stream. + /// The stream must be set to the correct position before calling SaveToStream. + /// + /// Handle to a FreeImage bitmap. + /// The stream to write to. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// cannot write. + public static bool SaveToStream( + FIBITMAP dib, + Stream stream, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_SAVE_FLAGS flags) + { + return SaveToStream( + ref dib, + stream, + format, + flags, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + false); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a stream. + /// The stream must be set to the correct position before calling SaveToStream. + /// + /// Handle to a FreeImage bitmap. + /// The stream to write to. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// When true the structure will be unloaded on success. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// cannot write. + public static bool SaveToStream( + ref FIBITMAP dib, + Stream stream, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_SAVE_FLAGS flags, + bool unloadSource) + { + return SaveToStream( + ref dib, stream, + format, + flags, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + unloadSource); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a stream. + /// The stream must be set to the correct position before calling SaveToStream. + /// + /// Handle to a FreeImage bitmap. + /// The stream to write to. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// The new color depth of the bitmap. + /// Set to if SaveToStream should + /// take the best suitable color depth. + /// If a color depth is selected that the provided format cannot write an + /// error-message will be thrown. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// cannot write. + public static bool SaveToStream( + FIBITMAP dib, + Stream stream, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_SAVE_FLAGS flags, + FREE_IMAGE_COLOR_DEPTH colorDepth) + { + return SaveToStream( + ref dib, + stream, + format, + flags, + colorDepth, + false); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a stream. + /// The stream must be set to the correct position before calling SaveToStream. + /// + /// Handle to a FreeImage bitmap. + /// The stream to write to. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// The new color depth of the bitmap. + /// Set to if SaveToStream should + /// take the best suitable color depth. + /// If a color depth is selected that the provided format cannot write an + /// error-message will be thrown. + /// When true the structure will be unloaded on success. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// cannot write. + public static bool SaveToStream( + ref FIBITMAP dib, + Stream stream, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_SAVE_FLAGS flags, + FREE_IMAGE_COLOR_DEPTH colorDepth, + bool unloadSource) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + if (!stream.CanWrite) + { + throw new ArgumentException("stream is not capable of writing."); + } + if ((!FIFSupportsWriting(format)) || (!FIFSupportsExportType(format, GetImageType(dib)))) + { + return false; + } + + FIBITMAP dibToSave = PrepareBitmapColorDepth(dib, format, colorDepth); + bool result = false; + + try + { + // Create a 'FreeImageIO' structure for calling 'SaveToHandle' + FreeImageIO io = FreeImageStreamIO.io; + + using (fi_handle handle = new fi_handle(stream)) + { + result = SaveToHandle(format, dibToSave, ref io, handle, flags); + } + } + finally + { + // Always unload a temporary created bitmap. + if (dibToSave != dib) + { + UnloadEx(ref dibToSave); + } + // On success unload the bitmap + if (result && unloadSource) + { + UnloadEx(ref dib); + } + } + + return result; + } + + #endregion + + #region Plugin functions + + /// + /// Checks if an extension is valid for a certain format. + /// + /// The desired format. + /// The desired extension. + /// True if the extension is valid for the given format, false otherwise. + /// + /// is null. + public static bool IsExtensionValidForFIF(FREE_IMAGE_FORMAT fif, string extension) + { + return IsExtensionValidForFIF(fif, extension, StringComparison.CurrentCultureIgnoreCase); + } + + /// + /// Checks if an extension is valid for a certain format. + /// + /// The desired format. + /// The desired extension. + /// The string comparison type. + /// True if the extension is valid for the given format, false otherwise. + /// + /// is null. + public static bool IsExtensionValidForFIF(FREE_IMAGE_FORMAT fif, string extension, StringComparison comparisonType) + { + if (extension == null) + { + throw new ArgumentNullException("extension"); + } + bool result = false; + // Split up the string and compare each with the given extension + string tempList = GetFIFExtensionList(fif); + if (tempList != null) + { + string[] extensionList = tempList.Split(','); + foreach (string ext in extensionList) + { + if (extension.Equals(ext, comparisonType)) + { + result = true; + break; + } + } + } + return result; + } + + /// + /// Checks if a filename is valid for a certain format. + /// + /// The desired format. + /// The desired filename. + /// True if the filename is valid for the given format, false otherwise. + /// + /// is null. + public static bool IsFilenameValidForFIF(FREE_IMAGE_FORMAT fif, string filename) + { + return IsFilenameValidForFIF(fif, filename, StringComparison.CurrentCultureIgnoreCase); + } + + /// + /// Checks if a filename is valid for a certain format. + /// + /// The desired format. + /// The desired filename. + /// The string comparison type. + /// True if the filename is valid for the given format, false otherwise. + /// + /// is null. + public static bool IsFilenameValidForFIF(FREE_IMAGE_FORMAT fif, string filename, StringComparison comparisonType) + { + if (filename == null) + { + throw new ArgumentNullException("filename"); + } + bool result = false; + // Extract the filenames extension if it exists + string extension = Path.GetExtension(filename); + if (extension.Length != 0) + { + extension = extension.Remove(0, 1); + result = IsExtensionValidForFIF(fif, extension, comparisonType); + } + return result; + } + + /// + /// This function returns the primary (main or most commonly used?) extension of a certain + /// image format (fif). This is done by returning the first of all possible extensions + /// returned by GetFIFExtensionList(). + /// That assumes, that the plugin returns the extensions in ordered form. + /// The image format to obtain the primary extension for. + /// The primary extension of the specified image format. + public static string GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT fif) + { + string result = null; + string extensions = GetFIFExtensionList(fif); + if (extensions != null) + { + int position = extensions.IndexOf(','); + if (position < 0) + { + result = extensions; + } + else + { + result = extensions.Substring(0, position); + } + } + return result; + } + + #endregion + + #region Multipage functions + + /// + /// Loads a FreeImage multi-paged bitmap. + /// + /// The complete name of the file to load. + /// Handle to a FreeImage multi-paged bitmap. + /// + /// does not exists while opening. + public static FIMULTIBITMAP OpenMultiBitmapEx(string filename) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return OpenMultiBitmapEx( + filename, + ref format, + FREE_IMAGE_LOAD_FLAGS.DEFAULT, + false, + false, + false); + } + + /// + /// Loads a FreeImage multi-paged bitmap. + /// + /// The complete name of the file to load. + /// When true performance is increased at the cost of memory. + /// Handle to a FreeImage multi-paged bitmap. + /// + /// does not exists while opening. + public static FIMULTIBITMAP OpenMultiBitmapEx(string filename, bool keep_cache_in_memory) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return OpenMultiBitmapEx( + filename, + ref format, + FREE_IMAGE_LOAD_FLAGS.DEFAULT, + false, + false, + keep_cache_in_memory); + } + + /// + /// Loads a FreeImage multi-paged bitmap. + /// + /// The complete name of the file to load. + /// When true the bitmap will be loaded read only. + /// When true performance is increased at the cost of memory. + /// Handle to a FreeImage multi-paged bitmap. + /// + /// does not exists while opening. + public static FIMULTIBITMAP OpenMultiBitmapEx( + string filename, + bool read_only, + bool keep_cache_in_memory) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return OpenMultiBitmapEx( + filename, + ref format, + FREE_IMAGE_LOAD_FLAGS.DEFAULT, + false, + read_only, + keep_cache_in_memory); + } + + /// + /// Loads a FreeImage multi-paged bitmap. + /// + /// The complete name of the file to load. + /// When true a new bitmap is created. + /// When true the bitmap will be loaded read only. + /// When true performance is increased at the cost of memory. + /// Handle to a FreeImage multi-paged bitmap. + /// + /// does not exists while opening. + public static FIMULTIBITMAP OpenMultiBitmapEx( + string filename, + bool create_new, + bool read_only, + bool keep_cache_in_memory) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return OpenMultiBitmapEx( + filename, + ref format, + FREE_IMAGE_LOAD_FLAGS.DEFAULT, + create_new, + read_only, + keep_cache_in_memory); + } + + /// + /// Loads a FreeImage multi-paged bitmap. + /// In case the loading format is the files real + /// format is being analysed. If no plugin can read the file, format remains + /// and 0 is returned. + /// + /// The complete name of the file to load. + /// Format of the image. If the format is unknown use + /// . + /// In case a suitable format was found by LoadEx it will be returned in format. + /// When true a new bitmap is created. + /// When true the bitmap will be loaded read only. + /// When true performance is increased at the cost of memory. + /// Handle to a FreeImage multi-paged bitmap. + /// + /// does not exists while opening. + public static FIMULTIBITMAP OpenMultiBitmapEx( + string filename, + ref FREE_IMAGE_FORMAT format, + bool create_new, + bool read_only, + bool keep_cache_in_memory) + { + return OpenMultiBitmapEx( + filename, + ref format, + FREE_IMAGE_LOAD_FLAGS.DEFAULT, + create_new, + read_only, + keep_cache_in_memory); + } + + /// + /// Loads a FreeImage multi-paged bitmap. + /// In case the loading format is the files + /// real format is being analysed. If no plugin can read the file, format remains + /// and 0 is returned. + /// Load flags can be provided by the flags parameter. + /// + /// The complete name of the file to load. + /// Format of the image. If the format is unknown use + /// . + /// In case a suitable format was found by LoadEx it will be returned in format. + /// Flags to enable or disable plugin-features. + /// When true a new bitmap is created. + /// When true the bitmap will be loaded read only. + /// When true performance is increased at the cost of memory. + /// Handle to a FreeImage multi-paged bitmap. + /// + /// does not exists while opening. + public static FIMULTIBITMAP OpenMultiBitmapEx( + string filename, + ref FREE_IMAGE_FORMAT format, + FREE_IMAGE_LOAD_FLAGS flags, + bool create_new, + bool read_only, + bool keep_cache_in_memory) + { + if (!File.Exists(filename) && !create_new) + { + throw new FileNotFoundException(filename + " could not be found."); + } + if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) + { + // Check if a plugin can read the data + format = GetFileType(filename, 0); + } + FIMULTIBITMAP dib = new FIMULTIBITMAP(); + if (FIFSupportsReading(format)) + { + dib = OpenMultiBitmap(format, filename, create_new, read_only, keep_cache_in_memory, flags); + } + return dib; + } + + /// + /// Loads a FreeImage multi-paged bitmap. + /// + /// The stream to load the bitmap from. + /// Handle to a FreeImage multi-paged bitmap. + public static FIMULTIBITMAP OpenMultiBitmapFromStream(Stream stream) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return OpenMultiBitmapFromStream(stream, ref format, FREE_IMAGE_LOAD_FLAGS.DEFAULT); + } + + /// + /// Loads a FreeImage multi-paged bitmap. + /// In case the loading format is the files + /// real format is being analysed. If no plugin can read the file, format remains + /// and 0 is returned. + /// Load flags can be provided by the flags parameter. + /// + /// The stream to load the bitmap from. + /// Format of the image. If the format is unknown use + /// . + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage multi-paged bitmap. + public static FIMULTIBITMAP OpenMultiBitmapFromStream(Stream stream, ref FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) + { + if (stream == null) + return FIMULTIBITMAP.Zero; + + if (!stream.CanSeek) + stream = new StreamWrapper(stream, true); + + FIMULTIBITMAP mdib = FIMULTIBITMAP.Zero; + FreeImageIO io = FreeImageStreamIO.io; + fi_handle handle = new fi_handle(stream); + + try + { + if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) + { + format = GetFileTypeFromHandle(ref io, handle, checked((int)stream.Length)); + } + + mdib = OpenMultiBitmapFromHandle(format, ref io, handle, flags); + + if (mdib.IsNull) + { + handle.Dispose(); + } + else + { + lock (streamHandles) + { + streamHandles.Add(mdib, handle); + } + } + + return mdib; + } + catch + { + if (!mdib.IsNull) + CloseMultiBitmap(mdib, FREE_IMAGE_SAVE_FLAGS.DEFAULT); + + if (handle != null) + handle.Dispose(); + + throw; + } + } + + /// + /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, applies any changes made to it. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + public static bool CloseMultiBitmap(FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags) + { + if (CloseMultiBitmap_(bitmap, flags)) + { + fi_handle handle; + lock (streamHandles) + { + if (streamHandles.TryGetValue(bitmap, out handle)) + { + streamHandles.Remove(bitmap); + handle.Dispose(); + } + } + return true; + } + return false; + } + + /// + /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, + /// applies any changes made to it. + /// On success the handle will be reset to null. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Returns true on success, false on failure. + public static bool CloseMultiBitmapEx(ref FIMULTIBITMAP bitmap) + { + return CloseMultiBitmapEx(ref bitmap, FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + /// + /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, + /// applies any changes made to it. + /// On success the handle will be reset to null. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + public static bool CloseMultiBitmapEx(ref FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags) + { + bool result = false; + if (!bitmap.IsNull) + { + if (CloseMultiBitmap(bitmap, flags)) + { + bitmap.SetNull(); + result = true; + } + } + return result; + } + + /// + /// Retrieves the number of pages that are locked in a multi-paged bitmap. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Number of locked pages. + /// + /// is null. + public static int GetLockedPageCount(FIMULTIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + int result = 0; + GetLockedPageNumbers(dib, null, ref result); + return result; + } + + /// + /// Retrieves a list locked pages of a multi-paged bitmap. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// List containing the indexes of the locked pages. + /// + /// is null. + public static int[] GetLockedPages(FIMULTIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + // Get the number of pages and create an array to save the information + int count = 0; + int[] result = null; + // Get count + if (GetLockedPageNumbers(dib, result, ref count)) + { + result = new int[count]; + // Fill array + if (!GetLockedPageNumbers(dib, result, ref count)) + { + result = null; + } + } + return result; + } + + /// + /// Loads a FreeImage multi-paged bitmap from a stream and returns the + /// FreeImage memory stream used as temporary buffer. + /// The bitmap can not be modified by calling + /// , + /// , + /// or + /// . + /// + /// The stream to read from. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// The temporary memory buffer used to load the bitmap. + /// Handle to a FreeImage multi-paged bitmap. + /// + /// is null. + /// + /// can not read. + public static FIMULTIBITMAP LoadMultiBitmapFromStream( + Stream stream, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_LOAD_FLAGS flags, + out FIMEMORY memory) + { + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + if (!stream.CanRead) + { + throw new ArgumentException("stream"); + } + const int blockSize = 1024; + int bytesRead; + byte[] buffer = new byte[blockSize]; + + stream = stream.CanSeek ? stream : new StreamWrapper(stream, true); + memory = OpenMemory(IntPtr.Zero, 0); + + do + { + bytesRead = stream.Read(buffer, 0, blockSize); + WriteMemory(buffer, (uint)blockSize, (uint)1, memory); + } + while (bytesRead == blockSize); + + return LoadMultiBitmapFromMemory(format, memory, flags); + } + + #endregion + + #region Filetype functions + + /// + /// Orders FreeImage to analyze the bitmap signature. + /// In case the stream is not seekable, the stream will have been used + /// and must be recreated for loading. + /// + /// Name of the stream to analyze. + /// Type of the bitmap. + /// + /// is null. + /// + /// can not read. + public static FREE_IMAGE_FORMAT GetFileTypeFromStream(Stream stream) + { + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + if (!stream.CanRead) + { + throw new ArgumentException("stream is not capable of reading."); + } + // Wrap the stream if it cannot seek + stream = (stream.CanSeek) ? stream : new StreamWrapper(stream, true); + // Create a 'FreeImageIO' structure for the stream + FreeImageIO io = FreeImageStreamIO.io; + using (fi_handle handle = new fi_handle(stream)) + { + return GetFileTypeFromHandle(ref io, handle, 0); + } + } + + #endregion + + #region Pixel access functions + + /// + /// Retrieves an hBitmap for a FreeImage bitmap. + /// Call FreeHbitmap(IntPtr) to free the handle. + /// + /// Handle to a FreeImage bitmap. + /// A reference device context. + /// Use IntPtr.Zero if no reference is available. + /// When true dib will be unloaded if the function succeeded. + /// The hBitmap for the FreeImage bitmap. + /// + /// is null. + public static unsafe IntPtr GetHbitmap(FIBITMAP dib, IntPtr hdc, bool unload) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + IntPtr hBitmap = IntPtr.Zero; + bool release = false; + IntPtr ppvBits = IntPtr.Zero; + // Check if we have destination + if (release = (hdc == IntPtr.Zero)) + { + // We don't so request dc + hdc = GetDC(IntPtr.Zero); + } + if (hdc != IntPtr.Zero) + { + // Get pointer to the infoheader of the bitmap + IntPtr info = GetInfo(dib); + // Create a bitmap in the dc + hBitmap = CreateDIBSection(hdc, info, DIB_RGB_COLORS, out ppvBits, IntPtr.Zero, 0); + if (hBitmap != IntPtr.Zero && ppvBits != IntPtr.Zero) + { + // Copy the data into the dc + CopyMemory(ppvBits, GetBits(dib), (GetHeight(dib) * GetPitch(dib))); + // Success: we unload the bitmap + if (unload) + { + Unload(dib); + } + } + // We have to release the dc + if (release) + { + ReleaseDC(IntPtr.Zero, hdc); + } + } + return hBitmap; + } + + /// + /// Returns an HBITMAP created by the CreateDIBitmap() function which in turn + /// has always the same color depth as the reference DC, which may be provided + /// through . The desktop DC will be used, + /// if IntPtr.Zero DC is specified. + /// Call to free the handle. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a device context. + /// When true the structure will be unloaded on success. + /// If the function failed and returned false, the bitmap was not unloaded. + /// If the function succeeds, the return value is a handle to the + /// compatible bitmap. If the function fails, the return value is . + /// + /// is null. + public static IntPtr GetBitmapForDevice(FIBITMAP dib, IntPtr hdc, bool unload) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + IntPtr hbitmap = IntPtr.Zero; + bool release = false; + if (release = (hdc == IntPtr.Zero)) + { + hdc = GetDC(IntPtr.Zero); + } + if (hdc != IntPtr.Zero) + { + hbitmap = CreateDIBitmap( + hdc, + GetInfoHeader(dib), + CBM_INIT, + GetBits(dib), + GetInfo(dib), + DIB_RGB_COLORS); + if (unload) + { + Unload(dib); + } + if (release) + { + ReleaseDC(IntPtr.Zero, hdc); + } + } + return hbitmap; + } + + /// + /// Creates a FreeImage DIB from a Device Context/Compatible Bitmap. + /// + /// Handle to the bitmap. + /// Handle to a device context. + /// Handle to a FreeImage bitmap. + /// + /// is null. + public unsafe static FIBITMAP CreateFromHbitmap(IntPtr hbitmap, IntPtr hdc) + { + if (hbitmap == IntPtr.Zero) + { + throw new ArgumentNullException("hbitmap"); + } + + FIBITMAP dib = new FIBITMAP(); + BITMAP bm; + uint colors; + bool release; + + if (GetObject(hbitmap, sizeof(BITMAP), (IntPtr)(&bm)) != 0) + { + dib = Allocate(bm.bmWidth, bm.bmHeight, bm.bmBitsPixel, 0, 0, 0); + if (!dib.IsNull) + { + colors = GetColorsUsed(dib); + if (release = (hdc == IntPtr.Zero)) + { + hdc = GetDC(IntPtr.Zero); + } + if (GetDIBits( + hdc, + hbitmap, + 0, + (uint)bm.bmHeight, + GetBits(dib), + GetInfo(dib), + DIB_RGB_COLORS) != 0) + { + if (colors != 0) + { + BITMAPINFOHEADER* bmih = (BITMAPINFOHEADER*)GetInfo(dib); + bmih[0].biClrImportant = bmih[0].biClrUsed = colors; + } + } + else + { + UnloadEx(ref dib); + } + if (release) + { + ReleaseDC(IntPtr.Zero, hdc); + } + } + } + + return dib; + } + + /// + /// Frees a bitmap handle. + /// + /// Handle to a bitmap. + /// True on success, false on failure. + public static bool FreeHbitmap(IntPtr hbitmap) + { + return DeleteObject(hbitmap); + } + + #endregion + + #region Bitmap information functions + + /// + /// Retrieves a DIB's resolution in X-direction measured in 'dots per inch' (DPI) and not in + /// 'dots per meter'. + /// + /// Handle to a FreeImage bitmap. + /// The resolution in 'dots per inch'. + /// + /// is null. + public static uint GetResolutionX(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + return (uint)(0.5d + 0.0254d * GetDotsPerMeterX(dib)); + } + + /// + /// Retrieves a DIB's resolution in Y-direction measured in 'dots per inch' (DPI) and not in + /// 'dots per meter'. + /// + /// Handle to a FreeImage bitmap. + /// The resolution in 'dots per inch'. + /// + /// is null. + public static uint GetResolutionY(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + return (uint)(0.5d + 0.0254d * GetDotsPerMeterY(dib)); + } + + /// + /// Sets a DIB's resolution in X-direction measured in 'dots per inch' (DPI) and not in + /// 'dots per meter'. + /// + /// Handle to a FreeImage bitmap. + /// The new resolution in 'dots per inch'. + /// + /// is null. + public static void SetResolutionX(FIBITMAP dib, uint res) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + SetDotsPerMeterX(dib, (uint)((double)res / 0.0254d + 0.5d)); + } + + /// + /// Sets a DIB's resolution in Y-direction measured in 'dots per inch' (DPI) and not in + /// 'dots per meter'. + /// + /// Handle to a FreeImage bitmap. + /// The new resolution in 'dots per inch'. + /// + /// is null. + public static void SetResolutionY(FIBITMAP dib, uint res) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + SetDotsPerMeterY(dib, (uint)((double)res / 0.0254d + 0.5d)); + } + + /// + /// Returns whether the image is a greyscale image or not. + /// The function scans all colors in the bitmaps palette for entries where + /// red, green and blue are not all the same (not a grey color). + /// Supports 1-, 4- and 8-bit bitmaps. + /// + /// Handle to a FreeImage bitmap. + /// True if the image is a greyscale image, else false. + /// + /// is null. + public static unsafe bool IsGreyscaleImage(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + bool result = true; + uint bpp = GetBPP(dib); + switch (bpp) + { + case 1: + case 4: + case 8: + RGBQUAD* palette = (RGBQUAD*)GetPalette(dib); + uint paletteLength = GetColorsUsed(dib); + for (int i = 0; i < paletteLength; i++) + { + if (palette[i].rgbRed != palette[i].rgbGreen || + palette[i].rgbRed != palette[i].rgbBlue) + { + result = false; + break; + } + } + break; + default: + result = false; + break; + } + return result; + } + + /// + /// Returns a structure that represents the palette of a FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// A structure representing the bitmaps palette. + /// + /// is null. + public static Palette GetPaletteEx(FIBITMAP dib) + { + return new Palette(dib); + } + + /// + /// Returns the structure of a FreeImage bitmap. + /// The structure is a copy, so changes will have no effect on + /// the bitmap itself. + /// + /// Handle to a FreeImage bitmap. + /// structure of the bitmap. + /// + /// is null. + public static unsafe BITMAPINFOHEADER GetInfoHeaderEx(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + return *(BITMAPINFOHEADER*)GetInfoHeader(dib); + } + + /// + /// Returns the structure of a FreeImage bitmap. + /// The structure is a copy, so changes will have no effect on + /// the bitmap itself. + /// + /// Handle to a FreeImage bitmap. + /// structure of the bitmap. + /// + /// is null. + public static BITMAPINFO GetInfoEx(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + BITMAPINFO result = new BITMAPINFO(); + result.bmiHeader = GetInfoHeaderEx(dib); + IntPtr ptr = GetPalette(dib); + if (ptr == IntPtr.Zero) + { + result.bmiColors = new RGBQUAD[0]; + } + else + { + result.bmiColors = new MemoryArray(ptr, (int)result.bmiHeader.biClrUsed).Data; + } + return result; + } + + /// + /// Returns the pixelformat of the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// of the bitmap. + /// + /// is null. + public static PixelFormat GetPixelFormat(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + + PixelFormat result = PixelFormat.Undefined; + + if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) + { + switch (GetBPP(dib)) + { + case 1: + result = PixelFormat.Format1bppIndexed; + break; + case 4: + result = PixelFormat.Format4bppIndexed; + break; + case 8: + result = PixelFormat.Format8bppIndexed; + break; + case 16: + if ((GetBlueMask(dib) == FI16_565_BLUE_MASK) && + (GetGreenMask(dib) == FI16_565_GREEN_MASK) && + (GetRedMask(dib) == FI16_565_RED_MASK)) + { + result = PixelFormat.Format16bppRgb565; + } + if ((GetBlueMask(dib) == FI16_555_BLUE_MASK) && + (GetGreenMask(dib) == FI16_555_GREEN_MASK) && + (GetRedMask(dib) == FI16_555_RED_MASK)) + { + result = PixelFormat.Format16bppRgb555; + } + break; + case 24: + result = PixelFormat.Format24bppRgb; + break; + case 32: + result = PixelFormat.Format32bppArgb; + break; + } + } + return result; + } + + /// + /// Retrieves all parameters needed to create a new FreeImage bitmap from + /// the format of a .NET . + /// + /// The + /// of the .NET . + /// Returns the type used for the new bitmap. + /// Returns the color depth for the new bitmap. + /// Returns the red_mask for the new bitmap. + /// Returns the green_mask for the new bitmap. + /// Returns the blue_mask for the new bitmap. + /// True in case a matching conversion exists; else false. + /// + public static bool GetFormatParameters( + PixelFormat format, + out FREE_IMAGE_TYPE type, + out uint bpp, + out uint red_mask, + out uint green_mask, + out uint blue_mask) + { + bool result = false; + type = FREE_IMAGE_TYPE.FIT_UNKNOWN; + bpp = 0; + red_mask = 0; + green_mask = 0; + blue_mask = 0; + switch (format) + { + case PixelFormat.Format1bppIndexed: + type = FREE_IMAGE_TYPE.FIT_BITMAP; + bpp = 1; + result = true; + break; + case PixelFormat.Format4bppIndexed: + type = FREE_IMAGE_TYPE.FIT_BITMAP; + bpp = 4; + result = true; + break; + case PixelFormat.Format8bppIndexed: + type = FREE_IMAGE_TYPE.FIT_BITMAP; + bpp = 8; + result = true; + break; + case PixelFormat.Format16bppRgb565: + type = FREE_IMAGE_TYPE.FIT_BITMAP; + bpp = 16; + red_mask = FI16_565_RED_MASK; + green_mask = FI16_565_GREEN_MASK; + blue_mask = FI16_565_BLUE_MASK; + result = true; + break; + case PixelFormat.Format16bppRgb555: + case PixelFormat.Format16bppArgb1555: + type = FREE_IMAGE_TYPE.FIT_BITMAP; + bpp = 16; + red_mask = FI16_555_RED_MASK; + green_mask = FI16_555_GREEN_MASK; + blue_mask = FI16_555_BLUE_MASK; + result = true; + break; + case PixelFormat.Format24bppRgb: + type = FREE_IMAGE_TYPE.FIT_BITMAP; + bpp = 24; + red_mask = FI_RGBA_RED_MASK; + green_mask = FI_RGBA_GREEN_MASK; + blue_mask = FI_RGBA_BLUE_MASK; + result = true; + break; + case PixelFormat.Format32bppRgb: + case PixelFormat.Format32bppArgb: + case PixelFormat.Format32bppPArgb: + type = FREE_IMAGE_TYPE.FIT_BITMAP; + bpp = 32; + red_mask = FI_RGBA_RED_MASK; + green_mask = FI_RGBA_GREEN_MASK; + blue_mask = FI_RGBA_BLUE_MASK; + result = true; + break; + case PixelFormat.Format16bppGrayScale: + type = FREE_IMAGE_TYPE.FIT_UINT16; + bpp = 16; + result = true; + break; + case PixelFormat.Format48bppRgb: + type = FREE_IMAGE_TYPE.FIT_RGB16; + bpp = 48; + result = true; + break; + case PixelFormat.Format64bppArgb: + case PixelFormat.Format64bppPArgb: + type = FREE_IMAGE_TYPE.FIT_RGBA16; + bpp = 64; + result = true; + break; + } + return result; + } + + /// + /// Returns the for the specified + /// . + /// + /// The + /// for which to return the corresponding . + /// The for the specified + /// + public static FREE_IMAGE_FORMAT GetFormat(ImageFormat imageFormat) + { + if (imageFormat != null) + { + if (imageFormat.Equals(ImageFormat.Bmp)) + return FREE_IMAGE_FORMAT.FIF_BMP; + if (imageFormat.Equals(ImageFormat.Gif)) + return FREE_IMAGE_FORMAT.FIF_GIF; + if (imageFormat.Equals(ImageFormat.Icon)) + return FREE_IMAGE_FORMAT.FIF_ICO; + if (imageFormat.Equals(ImageFormat.Jpeg)) + return FREE_IMAGE_FORMAT.FIF_JPEG; + if (imageFormat.Equals(ImageFormat.Png)) + return FREE_IMAGE_FORMAT.FIF_PNG; + if (imageFormat.Equals(ImageFormat.Tiff)) + return FREE_IMAGE_FORMAT.FIF_TIFF; + } + return FREE_IMAGE_FORMAT.FIF_UNKNOWN; + } + + /// + /// Retrieves all parameters needed to create a new FreeImage bitmap from + /// raw bits . + /// + /// The + /// of the data in memory. + /// The color depth for the data. + /// Returns the red_mask for the data. + /// Returns the green_mask for the data. + /// Returns the blue_mask for the data. + /// True in case a matching conversion exists; else false. + /// + public static bool GetTypeParameters( + FREE_IMAGE_TYPE type, + int bpp, + out uint red_mask, + out uint green_mask, + out uint blue_mask) + { + bool result = false; + red_mask = 0; + green_mask = 0; + blue_mask = 0; + switch (type) + { + case FREE_IMAGE_TYPE.FIT_BITMAP: + switch (bpp) + { + case 1: + case 4: + case 8: + result = true; + break; + case 16: + result = true; + red_mask = FI16_555_RED_MASK; + green_mask = FI16_555_GREEN_MASK; + blue_mask = FI16_555_BLUE_MASK; + break; + case 24: + case 32: + result = true; + red_mask = FI_RGBA_RED_MASK; + green_mask = FI_RGBA_GREEN_MASK; + blue_mask = FI_RGBA_BLUE_MASK; + break; + } + break; + case FREE_IMAGE_TYPE.FIT_UNKNOWN: + break; + default: + result = true; + break; + } + return result; + } + + /// + /// Compares two FreeImage bitmaps. + /// + /// The first bitmap to compare. + /// The second bitmap to compare. + /// Determines which components of the bitmaps will be compared. + /// True in case both bitmaps match the compare conditions, false otherwise. + public static bool Compare(FIBITMAP dib1, FIBITMAP dib2, FREE_IMAGE_COMPARE_FLAGS flags) + { + // Check whether one bitmap is null + if (dib1.IsNull ^ dib2.IsNull) + { + return false; + } + // Check whether both pointers are the same + if (dib1 == dib2) + { + return true; + } + if (((flags & FREE_IMAGE_COMPARE_FLAGS.HEADER) > 0) && (!CompareHeader(dib1, dib2))) + { + return false; + } + if (((flags & FREE_IMAGE_COMPARE_FLAGS.PALETTE) > 0) && (!ComparePalette(dib1, dib2))) + { + return false; + } + if (((flags & FREE_IMAGE_COMPARE_FLAGS.DATA) > 0) && (!CompareData(dib1, dib2))) + { + return false; + } + if (((flags & FREE_IMAGE_COMPARE_FLAGS.METADATA) > 0) && (!CompareMetadata(dib1, dib2))) + { + return false; + } + return true; + } + + private static unsafe bool CompareHeader(FIBITMAP dib1, FIBITMAP dib2) + { + IntPtr i1 = GetInfoHeader(dib1); + IntPtr i2 = GetInfoHeader(dib2); + return CompareMemory((void*)i1, (void*)i2, sizeof(BITMAPINFOHEADER)); + } + + private static unsafe bool ComparePalette(FIBITMAP dib1, FIBITMAP dib2) + { + IntPtr pal1 = GetPalette(dib1), pal2 = GetPalette(dib2); + bool hasPalette1 = pal1 != IntPtr.Zero; + bool hasPalette2 = pal2 != IntPtr.Zero; + if (hasPalette1 ^ hasPalette2) + { + return false; + } + if (!hasPalette1) + { + return true; + } + uint colors = GetColorsUsed(dib1); + if (colors != GetColorsUsed(dib2)) + { + return false; + } + return CompareMemory((void*)pal1, (void*)pal2, sizeof(RGBQUAD) * colors); + } + + private static unsafe bool CompareData(FIBITMAP dib1, FIBITMAP dib2) + { + uint width = GetWidth(dib1); + if (width != GetWidth(dib2)) + { + return false; + } + uint height = GetHeight(dib1); + if (height != GetHeight(dib2)) + { + return false; + } + uint bpp = GetBPP(dib1); + if (bpp != GetBPP(dib2)) + { + return false; + } + if (GetColorType(dib1) != GetColorType(dib2)) + { + return false; + } + FREE_IMAGE_TYPE type = GetImageType(dib1); + if (type != GetImageType(dib2)) + { + return false; + } + if (GetRedMask(dib1) != GetRedMask(dib2)) + { + return false; + } + if (GetGreenMask(dib1) != GetGreenMask(dib2)) + { + return false; + } + if (GetBlueMask(dib1) != GetBlueMask(dib2)) + { + return false; + } + + byte* ptr1, ptr2; + int fullBytes; + int shift; + uint line = GetLine(dib1); + + if (type == FREE_IMAGE_TYPE.FIT_BITMAP) + { + switch (bpp) + { + case 32: + for (int i = 0; i < height; i++) + { + ptr1 = (byte*)GetScanLine(dib1, i); + ptr2 = (byte*)GetScanLine(dib2, i); + if (!CompareMemory(ptr1, ptr2, line)) + { + return false; + } + } + break; + case 24: + for (int i = 0; i < height; i++) + { + ptr1 = (byte*)GetScanLine(dib1, i); + ptr2 = (byte*)GetScanLine(dib2, i); + if (!CompareMemory(ptr1, ptr2, line)) + { + return false; + } + } + break; + case 16: + short* sPtr1, sPtr2; + short mask = (short)(GetRedMask(dib1) | GetGreenMask(dib1) | GetBlueMask(dib1)); + if (mask == -1) + { + for (int i = 0; i < height; i++) + { + sPtr1 = (short*)GetScanLine(dib1, i); + sPtr2 = (short*)GetScanLine(dib2, i); + if (!CompareMemory(sPtr1, sPtr1, line)) + { + return false; + } + } + } + else + { + for (int i = 0; i < height; i++) + { + sPtr1 = (short*)GetScanLine(dib1, i); + sPtr2 = (short*)GetScanLine(dib2, i); + for (int x = 0; x < width; x++) + { + if ((sPtr1[x] & mask) != (sPtr2[x] & mask)) + { + return false; + } + } + } + } + break; + case 8: + for (int i = 0; i < height; i++) + { + ptr1 = (byte*)GetScanLine(dib1, i); + ptr2 = (byte*)GetScanLine(dib2, i); + if (!CompareMemory(ptr1, ptr2, line)) + { + return false; + } + } + break; + case 4: + fullBytes = (int)width / 2; + shift = (width % 2) == 0 ? 8 : 4; + for (int i = 0; i < height; i++) + { + ptr1 = (byte*)GetScanLine(dib1, i); + ptr2 = (byte*)GetScanLine(dib2, i); + if (fullBytes != 0) + { + if (!CompareMemory(ptr1, ptr2, fullBytes)) + { + return false; + } + ptr1 += fullBytes; + ptr2 += fullBytes; + } + if (shift != 8) + { + if ((ptr1[0] >> shift) != (ptr2[0] >> shift)) + { + return false; + } + } + } + break; + case 1: + fullBytes = (int)width / 8; + shift = 8 - ((int)width % 8); + for (int i = 0; i < height; i++) + { + ptr1 = (byte*)GetScanLine(dib1, i); + ptr2 = (byte*)GetScanLine(dib2, i); + if (fullBytes != 0) + { + if (!CompareMemory(ptr1, ptr2, fullBytes)) + { + return false; + } + ptr1 += fullBytes; + ptr2 += fullBytes; + } + if (shift != 8) + { + if ((ptr1[0] >> shift) != (ptr2[0] >> shift)) + { + return false; + } + } + } + break; + default: + throw new NotSupportedException("Only 1, 4, 8, 16, 24 and 32 bpp bitmaps are supported."); + } + } + else + { + for (int i = 0; i < height; i++) + { + ptr1 = (byte*)GetScanLine(dib1, i); + ptr2 = (byte*)GetScanLine(dib2, i); + if (!CompareMemory(ptr1, ptr2, line)) + { + return false; + } + } + } + return true; + } + + private static bool CompareMetadata(FIBITMAP dib1, FIBITMAP dib2) + { + MetadataTag tag1, tag2; + + foreach (FREE_IMAGE_MDMODEL metadataModel in FREE_IMAGE_MDMODELS) + { + if (GetMetadataCount(metadataModel, dib1) != + GetMetadataCount(metadataModel, dib2)) + { + return false; + } + if (GetMetadataCount(metadataModel, dib1) == 0) + { + continue; + } + + FIMETADATA mdHandle = FindFirstMetadata(metadataModel, dib1, out tag1); + if (mdHandle.IsNull) + { + continue; + } + do + { + if ((!GetMetadata(metadataModel, dib2, tag1.Key, out tag2)) || (tag1 != tag2)) + { + FindCloseMetadata(mdHandle); + return false; + } + } + while (FindNextMetadata(mdHandle, out tag1)); + FindCloseMetadata(mdHandle); + } + + return true; + } + + /// + /// Returns the FreeImage bitmap's transparency table. + /// The array is empty in case the bitmap has no transparency table. + /// + /// Handle to a FreeImage bitmap. + /// The FreeImage bitmap's transparency table. + /// + /// is null. + public static unsafe byte[] GetTransparencyTableEx(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + uint count = GetTransparencyCount(dib); + byte[] result = new byte[count]; + byte* ptr = (byte*)GetTransparencyTable(dib); + fixed (byte* dst = result) + { + CopyMemory(dst, ptr, count); + } + return result; + } + + /// + /// Set the FreeImage bitmap's transparency table. Only affects palletised bitmaps. + /// + /// Handle to a FreeImage bitmap. + /// The FreeImage bitmap's new transparency table. + /// + /// or is null. + public static void SetTransparencyTable(FIBITMAP dib, byte[] table) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + if (table == null) + { + throw new ArgumentNullException("table"); + } + SetTransparencyTable(dib, table, table.Length); + } + + /// + /// This function returns the number of unique colors actually used by the + /// specified 1-, 4-, 8-, 16-, 24- or 32-bit image. This might be different from + /// what function FreeImage_GetColorsUsed() returns, which actually returns the + /// palette size for palletised images. Works for + /// type images only. + /// + /// Handle to a FreeImage bitmap. + /// Returns the number of unique colors used by the image specified or + /// zero, if the image type cannot be handled. + /// + /// is null. + public static unsafe int GetUniqueColors(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + + int result = 0; + + if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) + { + BitArray bitArray; + int uniquePalEnts; + int hashcode; + byte[] lut; + int width = (int)GetWidth(dib); + int height = (int)GetHeight(dib); + + switch (GetBPP(dib)) + { + case 1: + + result = 1; + lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts); + if (uniquePalEnts == 1) + { + break; + } + + if ((*(byte*)GetScanLine(dib, 0) & 0x80) == 0) + { + for (int y = 0; y < height; y++) + { + byte* scanline = (byte*)GetScanLine(dib, y); + int mask = 0x80; + for (int x = 0; x < width; x++) + { + if ((scanline[x / 8] & mask) > 0) + { + return 2; + } + mask = (mask == 0x1) ? 0x80 : (mask >> 1); + } + } + } + else + { + for (int y = 0; y < height; y++) + { + byte* scanline = (byte*)GetScanLine(dib, y); + int mask = 0x80; + for (int x = 0; x < width; x++) + { + if ((scanline[x / 8] & mask) == 0) + { + return 2; + } + mask = (mask == 0x1) ? 0x80 : (mask >> 1); + } + } + } + break; + + case 4: + + bitArray = new BitArray(0x10); + lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts); + if (uniquePalEnts == 1) + { + result = 1; + break; + } + + for (int y = 0; (y < height) && (result < uniquePalEnts); y++) + { + byte* scanline = (byte*)GetScanLine(dib, y); + bool top = true; + for (int x = 0; (x < width) && (result < uniquePalEnts); x++) + { + if (top) + { + hashcode = lut[scanline[x / 2] >> 4]; + } + else + { + hashcode = lut[scanline[x / 2] & 0xF]; + } + top = !top; + if (!bitArray[hashcode]) + { + bitArray[hashcode] = true; + result++; + } + } + } + break; + + case 8: + + bitArray = new BitArray(0x100); + lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts); + if (uniquePalEnts == 1) + { + result = 1; + break; + } + + for (int y = 0; (y < height) && (result < uniquePalEnts); y++) + { + byte* scanline = (byte*)GetScanLine(dib, y); + for (int x = 0; (x < width) && (result < uniquePalEnts); x++) + { + hashcode = lut[scanline[x]]; + if (!bitArray[hashcode]) + { + bitArray[hashcode] = true; + result++; + } + } + } + break; + + case 16: + + bitArray = new BitArray(0x10000); + + for (int y = 0; y < height; y++) + { + short* scanline = (short*)GetScanLine(dib, y); + for (int x = 0; x < width; x++, scanline++) + { + hashcode = *scanline; + if (!bitArray[hashcode]) + { + bitArray[hashcode] = true; + result++; + } + } + } + break; + + case 24: + + bitArray = new BitArray(0x1000000); + + for (int y = 0; y < height; y++) + { + byte* scanline = (byte*)GetScanLine(dib, y); + for (int x = 0; x < width; x++, scanline += 3) + { + hashcode = *((int*)scanline) & 0x00FFFFFF; + if (!bitArray[hashcode]) + { + bitArray[hashcode] = true; + result++; + } + } + } + break; + + case 32: + + bitArray = new BitArray(0x1000000); + + for (int y = 0; y < height; y++) + { + int* scanline = (int*)GetScanLine(dib, y); + for (int x = 0; x < width; x++, scanline++) + { + hashcode = *scanline & 0x00FFFFFF; + if (!bitArray[hashcode]) + { + bitArray[hashcode] = true; + result++; + } + } + } + break; + } + } + return result; + } + + /// + /// Verifies whether the FreeImage bitmap is 16bit 555. + /// + /// The FreeImage bitmap to verify. + /// true if the bitmap is RGB16-555; otherwise false. + public static bool IsRGB555(FIBITMAP dib) + { + return ((GetRedMask(dib) == FI16_555_RED_MASK) && + (GetGreenMask(dib) == FI16_555_GREEN_MASK) && + (GetBlueMask(dib) == FI16_555_BLUE_MASK)); + } + + /// + /// Verifies whether the FreeImage bitmap is 16bit 565. + /// + /// The FreeImage bitmap to verify. + /// true if the bitmap is RGB16-565; otherwise false. + public static bool IsRGB565(FIBITMAP dib) + { + return ((GetRedMask(dib) == FI16_565_RED_MASK) && + (GetGreenMask(dib) == FI16_565_GREEN_MASK) && + (GetBlueMask(dib) == FI16_565_BLUE_MASK)); + } + + #endregion + + #region ICC profile functions + + /// + /// Creates a new ICC-Profile for a FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The data of the new ICC-Profile. + /// The new ICC-Profile of the bitmap. + /// + /// is null. + public static FIICCPROFILE CreateICCProfileEx(FIBITMAP dib, byte[] data) + { + return new FIICCPROFILE(dib, data); + } + + /// + /// Creates a new ICC-Profile for a FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The data of the new ICC-Profile. + /// The number of bytes of to use. + /// The new ICC-Profile of the FreeImage bitmap. + /// + /// is null. + public static FIICCPROFILE CreateICCProfileEx(FIBITMAP dib, byte[] data, int size) + { + return new FIICCPROFILE(dib, data, size); + } + + #endregion + + #region Conversion functions + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion) + { + return ConvertColorDepth( + dib, + conversion, + 128, + FREE_IMAGE_DITHER.FID_FS, + FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, + false); + } + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// When true the structure will be unloaded on success. + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + bool unloadSource) + { + return ConvertColorDepth( + dib, + conversion, + 128, + FREE_IMAGE_DITHER.FID_FS, + FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, + unloadSource); + } + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// Threshold value when converting with + /// . + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + byte threshold) + { + return ConvertColorDepth( + dib, + conversion, + threshold, + FREE_IMAGE_DITHER.FID_FS, + FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, + false); + } + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// Dither algorithm when converting + /// with . + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + FREE_IMAGE_DITHER ditherMethod) + { + return ConvertColorDepth( + dib, + conversion, + 128, + ditherMethod, + FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, + false); + } + + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// The quantization algorithm for conversion to 8-bit color depth. + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + FREE_IMAGE_QUANTIZE quantizationMethod) + { + return ConvertColorDepth( + dib, + conversion, + 128, + FREE_IMAGE_DITHER.FID_FS, + quantizationMethod, + false); + } + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// Threshold value when converting with + /// . + /// When true the structure will be unloaded on success. + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + byte threshold, + bool unloadSource) + { + return ConvertColorDepth( + dib, + conversion, + threshold, + FREE_IMAGE_DITHER.FID_FS, + FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, + unloadSource); + } + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// Dither algorithm when converting with + /// . + /// When true the structure will be unloaded on success. + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + FREE_IMAGE_DITHER ditherMethod, + bool unloadSource) + { + return ConvertColorDepth( + dib, + conversion, + 128, + ditherMethod, + FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, + unloadSource); + } + + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// The quantization algorithm for conversion to 8-bit color depth. + /// When true the structure will be unloaded on success. + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + FREE_IMAGE_QUANTIZE quantizationMethod, + bool unloadSource) + { + return ConvertColorDepth( + dib, + conversion, + 128, + FREE_IMAGE_DITHER.FID_FS, + quantizationMethod, + unloadSource); + } + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// Threshold value when converting with + /// . + /// Dither algorithm when converting with + /// . + /// The quantization algorithm for conversion to 8-bit color depth. + /// When true the structure will be unloaded on success. + /// Handle to a FreeImage bitmap. + /// + /// is null. + internal static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + byte threshold, + FREE_IMAGE_DITHER ditherMethod, + FREE_IMAGE_QUANTIZE quantizationMethod, + bool unloadSource) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + + FIBITMAP result = new FIBITMAP(); + FIBITMAP dibTemp = new FIBITMAP(); + uint bpp = GetBPP(dib); + bool reorderPalette = ((conversion & FREE_IMAGE_COLOR_DEPTH.FICD_REORDER_PALETTE) > 0); + bool forceGreyscale = ((conversion & FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE) > 0); + + if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) + { + switch (conversion & (FREE_IMAGE_COLOR_DEPTH)0xFF) + { + case FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_THRESHOLD: + + if (bpp != 1) + { + if (forceGreyscale) + { + result = Threshold(dib, threshold); + } + else + { + dibTemp = ConvertTo24Bits(dib); + result = ColorQuantizeEx(dibTemp, quantizationMethod, 2, null, 1); + Unload(dibTemp); + } + } + else + { + bool isGreyscale = IsGreyscaleImage(dib); + if ((forceGreyscale && (!isGreyscale)) || + (reorderPalette && isGreyscale)) + { + result = Threshold(dib, threshold); + } + } + break; + + case FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_DITHER: + + if (bpp != 1) + { + if (forceGreyscale) + { + result = Dither(dib, ditherMethod); + } + else + { + dibTemp = ConvertTo24Bits(dib); + result = ColorQuantizeEx(dibTemp, quantizationMethod, 2, null, 1); + Unload(dibTemp); + } + } + else + { + bool isGreyscale = IsGreyscaleImage(dib); + if ((forceGreyscale && (!isGreyscale)) || + (reorderPalette && isGreyscale)) + { + result = Dither(dib, ditherMethod); + } + } + break; + + case FREE_IMAGE_COLOR_DEPTH.FICD_04_BPP: + + if (bpp != 4) + { + // Special case when 1bpp and FIC_PALETTE + if (forceGreyscale || + ((bpp == 1) && (GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_PALETTE))) + { + dibTemp = ConvertToGreyscale(dib); + result = ConvertTo4Bits(dibTemp); + Unload(dibTemp); + } + else + { + dibTemp = ConvertTo24Bits(dib); + result = ColorQuantizeEx(dibTemp, quantizationMethod, 16, null, 4); + Unload(dibTemp); + } + } + else + { + bool isGreyscale = IsGreyscaleImage(dib); + if ((forceGreyscale && (!isGreyscale)) || + (reorderPalette && isGreyscale)) + { + dibTemp = ConvertToGreyscale(dib); + result = ConvertTo4Bits(dibTemp); + Unload(dibTemp); + } + } + + break; + + case FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP: + + if (bpp != 8) + { + if (forceGreyscale) + { + result = ConvertToGreyscale(dib); + } + else + { + dibTemp = ConvertTo24Bits(dib); + result = ColorQuantize(dibTemp, quantizationMethod); + Unload(dibTemp); + } + } + else + { + bool isGreyscale = IsGreyscaleImage(dib); + if ((forceGreyscale && (!isGreyscale)) || (reorderPalette && isGreyscale)) + { + result = ConvertToGreyscale(dib); + } + } + break; + + case FREE_IMAGE_COLOR_DEPTH.FICD_16_BPP_555: + + if (forceGreyscale) + { + dibTemp = ConvertToGreyscale(dib); + result = ConvertTo16Bits555(dibTemp); + Unload(dibTemp); + } + else if (bpp != 16 || GetRedMask(dib) != FI16_555_RED_MASK || GetGreenMask(dib) != FI16_555_GREEN_MASK || GetBlueMask(dib) != FI16_555_BLUE_MASK) + { + result = ConvertTo16Bits555(dib); + } + break; + + case FREE_IMAGE_COLOR_DEPTH.FICD_16_BPP: + + if (forceGreyscale) + { + dibTemp = ConvertToGreyscale(dib); + result = ConvertTo16Bits565(dibTemp); + Unload(dibTemp); + } + else if (bpp != 16 || GetRedMask(dib) != FI16_565_RED_MASK || GetGreenMask(dib) != FI16_565_GREEN_MASK || GetBlueMask(dib) != FI16_565_BLUE_MASK) + { + result = ConvertTo16Bits565(dib); + } + break; + + case FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP: + + if (forceGreyscale) + { + dibTemp = ConvertToGreyscale(dib); + result = ConvertTo24Bits(dibTemp); + Unload(dibTemp); + } + else if (bpp != 24) + { + result = ConvertTo24Bits(dib); + } + break; + + case FREE_IMAGE_COLOR_DEPTH.FICD_32_BPP: + + if (forceGreyscale) + { + dibTemp = ConvertToGreyscale(dib); + result = ConvertTo32Bits(dibTemp); + Unload(dibTemp); + } + else if (bpp != 32) + { + result = ConvertTo32Bits(dib); + } + break; + } + } + + if (result.IsNull) + { + return dib; + } + if (unloadSource) + { + Unload(dib); + } + + return result; + } + + /// + /// ColorQuantizeEx is an extension to the + /// method that provides additional options used to quantize a 24-bit image to any + /// number of colors (up to 256), as well as quantize a 24-bit image using a + /// provided palette. + /// + /// Handle to a FreeImage bitmap. + /// Specifies the color reduction algorithm to be used. + /// Size of the desired output palette. + /// The provided palette. + /// true to create a bitmap with the smallest possible + /// color depth for the specified . + /// Handle to a FreeImage bitmap. + public static FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, RGBQUAD[] ReservePalette, bool minColorDepth) + { + FIBITMAP result; + if (minColorDepth) + { + int bpp; + if (PaletteSize >= 256) + bpp = 8; + else if (PaletteSize > 2) + bpp = 4; + else + bpp = 1; + result = ColorQuantizeEx(dib, quantize, PaletteSize, ReservePalette, bpp); + } + else + { + result = ColorQuantizeEx(dib, quantize, PaletteSize, ReservePalette, 8); + } + return result; + } + + /// + /// ColorQuantizeEx is an extension to the + /// method that provides additional options used to quantize a 24-bit image to any + /// number of colors (up to 256), as well as quantize a 24-bit image using a + /// partial or full provided palette. + /// + /// Handle to a FreeImage bitmap. + /// Specifies the color reduction algorithm to be used. + /// Size of the desired output palette. + /// The provided palette. + /// The desired color depth of the created image. + /// Handle to a FreeImage bitmap. + public static FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, RGBQUAD[] ReservePalette, int bpp) + { + unsafe + { + FIBITMAP result = FIBITMAP.Zero; + FIBITMAP temp = FIBITMAP.Zero; + int reservedSize = (ReservePalette == null) ? 0 : ReservePalette.Length; + + if (bpp == 8) + { + result = ColorQuantizeEx(dib, quantize, PaletteSize, reservedSize, ReservePalette); + } + else if (bpp == 4) + { + temp = ColorQuantizeEx(dib, quantize, Math.Min(16, PaletteSize), reservedSize, ReservePalette); + if (!temp.IsNull) + { + result = Allocate((int)GetWidth(temp), (int)GetHeight(temp), 4, 0, 0, 0); + CloneMetadata(result, temp); + CopyMemory(GetPalette(result), GetPalette(temp), sizeof(RGBQUAD) * 16); + + for (int y = (int)GetHeight(temp) - 1; y >= 0; y--) + { + Scanline srcScanline = new Scanline(temp, y); + Scanline dstScanline = new Scanline(result, y); + + for (int x = (int)GetWidth(temp) - 1; x >= 0; x--) + { + dstScanline[x] = srcScanline[x]; + } + } + } + } + else if (bpp == 1) + { + temp = ColorQuantizeEx(dib, quantize, 2, reservedSize, ReservePalette); + if (!temp.IsNull) + { + result = Allocate((int)GetWidth(temp), (int)GetHeight(temp), 1, 0, 0, 0); + CloneMetadata(result, temp); + CopyMemory(GetPalette(result), GetPalette(temp), sizeof(RGBQUAD) * 2); + + for (int y = (int)GetHeight(temp) - 1; y >= 0; y--) + { + Scanline srcScanline = new Scanline(temp, y); + Scanline dstScanline = new Scanline(result, y); + + for (int x = (int)GetWidth(temp) - 1; x >= 0; x--) + { + dstScanline[x] = srcScanline[x]; + } + } + } + } + + UnloadEx(ref temp); + return result; + } + } + + #endregion + + #region Metadata + + /// + /// Copies metadata from one FreeImage bitmap to another. + /// + /// Source FreeImage bitmap containing the metadata. + /// FreeImage bitmap to copy the metadata to. + /// Flags to switch different copy modes. + /// Returns -1 on failure else the number of copied tags. + /// + /// or is null. + public static int CloneMetadataEx(FIBITMAP src, FIBITMAP dst, FREE_IMAGE_METADATA_COPY flags) + { + if (src.IsNull) + { + throw new ArgumentNullException("src"); + } + if (dst.IsNull) + { + throw new ArgumentNullException("dst"); + } + + FITAG tag = new FITAG(), tag2 = new FITAG(); + int copied = 0; + + // Clear all existing metadata + if ((flags & FREE_IMAGE_METADATA_COPY.CLEAR_EXISTING) > 0) + { + foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS) + { + if (!SetMetadata(model, dst, null, tag)) + { + return -1; + } + } + } + + bool keep = !((flags & FREE_IMAGE_METADATA_COPY.REPLACE_EXISTING) > 0); + + foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS) + { + FIMETADATA mData = FindFirstMetadata(model, src, out tag); + if (mData.IsNull) continue; + do + { + string key = GetTagKey(tag); + if (!(keep && GetMetadata(model, dst, key, out tag2))) + { + if (SetMetadata(model, dst, key, tag)) + { + copied++; + } + } + } + while (FindNextMetadata(mData, out tag)); + FindCloseMetadata(mData); + } + + return copied; + } + + /// + /// Returns the comment of a JPEG, PNG or GIF image. + /// + /// Handle to a FreeImage bitmap. + /// Comment of the FreeImage bitmp, or null in case no comment exists. + /// + /// is null. + public static string GetImageComment(FIBITMAP dib) + { + string result = null; + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + FITAG tag; + if (GetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", out tag)) + { + MetadataTag metadataTag = new MetadataTag(tag, FREE_IMAGE_MDMODEL.FIMD_COMMENTS); + result = metadataTag.Value as string; + } + return result; + } + + /// + /// Sets the comment of a JPEG, PNG or GIF image. + /// + /// Handle to a FreeImage bitmap. + /// New comment of the FreeImage bitmap. + /// Use null to remove the comment. + /// Returns true on success, false on failure. + /// + /// is null. + public static bool SetImageComment(FIBITMAP dib, string comment) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + bool result; + if (comment != null) + { + FITAG tag = CreateTag(); + MetadataTag metadataTag = new MetadataTag(tag, FREE_IMAGE_MDMODEL.FIMD_COMMENTS); + metadataTag.Value = comment; + result = SetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", tag); + DeleteTag(tag); + } + else + { + result = SetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", FITAG.Zero); + } + return result; + } + + /// + /// Retrieve a metadata attached to a FreeImage bitmap. + /// + /// The metadata model to look for. + /// Handle to a FreeImage bitmap. + /// The metadata field name. + /// A structure returned by the function. + /// Returns true on success, false on failure. + /// + /// is null. + public static bool GetMetadata( + FREE_IMAGE_MDMODEL model, + FIBITMAP dib, + string key, + out MetadataTag tag) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + + FITAG _tag; + bool result; + if (GetMetadata(model, dib, key, out _tag)) + { + tag = new MetadataTag(_tag, model); + result = true; + } + else + { + tag = null; + result = false; + } + return result; + } + + /// + /// Attach a new metadata tag to a FreeImage bitmap. + /// + /// The metadata model used to store the tag. + /// Handle to a FreeImage bitmap. + /// The tag field name. + /// The to be attached. + /// Returns true on success, false on failure. + /// + /// is null. + public static bool SetMetadata( + FREE_IMAGE_MDMODEL model, + FIBITMAP dib, + string key, + MetadataTag tag) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + return SetMetadata(model, dib, key, tag.tag); + } + + /// + /// Provides information about the first instance of a tag that matches the metadata model. + /// + /// The model to match. + /// Handle to a FreeImage bitmap. + /// Tag that matches the metadata model. + /// Unique search handle that can be used to call FindNextMetadata or FindCloseMetadata. + /// Null if the metadata model does not exist. + /// + /// is null. + public static FIMETADATA FindFirstMetadata( + FREE_IMAGE_MDMODEL model, + FIBITMAP dib, + out MetadataTag tag) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + FITAG _tag; + FIMETADATA result = FindFirstMetadata(model, dib, out _tag); + if (result.IsNull) + { + tag = null; + return result; + } + tag = new MetadataTag(_tag, model); + if (metaDataSearchHandler.ContainsKey(result)) + { + metaDataSearchHandler[result] = model; + } + else + { + metaDataSearchHandler.Add(result, model); + } + return result; + } + + /// + /// Find the next tag, if any, that matches the metadata model argument in a previous call + /// to FindFirstMetadata, and then alters the tag object contents accordingly. + /// + /// Unique search handle provided by FindFirstMetadata. + /// Tag that matches the metadata model. + /// Returns true on success, false on failure. + public static bool FindNextMetadata(FIMETADATA mdhandle, out MetadataTag tag) + { + FITAG _tag; + bool result; + if (FindNextMetadata(mdhandle, out _tag)) + { + tag = new MetadataTag(_tag, metaDataSearchHandler[mdhandle]); + result = true; + } + else + { + tag = null; + result = false; + } + return result; + } + + /// + /// Closes the specified metadata search handle and releases associated resources. + /// + /// The handle to close. + public static void FindCloseMetadata(FIMETADATA mdhandle) + { + if (metaDataSearchHandler.ContainsKey(mdhandle)) + { + metaDataSearchHandler.Remove(mdhandle); + } + FindCloseMetadata_(mdhandle); + } + + /// + /// This dictionary links FIMETADATA handles and FREE_IMAGE_MDMODEL models. + /// + private static Dictionary metaDataSearchHandler + = new Dictionary(1); + + #endregion + + #region Rotation and Flipping + + /// + /// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. + /// 1-bit images rotation is limited to integer multiple of 90°. + /// null is returned for other values. + /// + /// Handle to a FreeImage bitmap. + /// The angle of rotation. + /// Handle to a FreeImage bitmap. + public static FIBITMAP Rotate(FIBITMAP dib, double angle) + { + return Rotate(dib, angle, IntPtr.Zero); + } + + /// + /// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. + /// 1-bit images rotation is limited to integer multiple of 90°. + /// null is returned for other values. + /// + /// The type of the color to use as background. + /// Handle to a FreeImage bitmap. + /// The angle of rotation. + /// The color used used to fill the bitmap's background. + /// Handle to a FreeImage bitmap. + public static FIBITMAP Rotate(FIBITMAP dib, double angle, T? backgroundColor) where T : struct + { + if (backgroundColor.HasValue) + { + GCHandle handle = new GCHandle(); + try + { + T[] buffer = new T[] { backgroundColor.Value }; + handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + return Rotate(dib, angle, handle.AddrOfPinnedObject()); + } + finally + { + if (handle.IsAllocated) + handle.Free(); + } + } + else + { + return Rotate(dib, angle, IntPtr.Zero); + } + } + + /// + /// Rotates a 4-bit color FreeImage bitmap. + /// Allowed values for are 90, 180 and 270. + /// In case is 0 or 360 a clone is returned. + /// 0 is returned for other values or in case the rotation fails. + /// + /// Handle to a FreeImage bitmap. + /// The angle of rotation. + /// Handle to a FreeImage bitmap. + /// + /// This function is kind of temporary due to FreeImage's lack of + /// rotating 4-bit images. It's particularly used by 's + /// method RotateFlip. This function will be removed as soon as FreeImage + /// supports rotating 4-bit images. + /// + /// + /// is null. + public static unsafe FIBITMAP Rotate4bit(FIBITMAP dib, double angle) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + + FIBITMAP result = new FIBITMAP(); + int ang = (int)angle; + + if ((GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) && + (GetBPP(dib) == 4) && + ((ang % 90) == 0)) + { + int width, height, xOrg, yOrg; + Scanline[] src, dst; + width = (int)GetWidth(dib); + height = (int)GetHeight(dib); + byte index = 0; + switch (ang) + { + case 90: + result = Allocate(height, width, 4, 0, 0, 0); + if (result.IsNull) + { + break; + } + CopyPalette(dib, result); + src = Get04BitScanlines(dib); + dst = Get04BitScanlines(result); + for (int y = 0; y < width; y++) + { + yOrg = height - 1; + for (int x = 0; x < height; x++, yOrg--) + { + index = src[yOrg][y]; + dst[y][x] = index; + } + } + break; + case 180: + result = Allocate(width, height, 4, 0, 0, 0); + if (result.IsNull) + { + break; + } + CopyPalette(dib, result); + src = Get04BitScanlines(dib); + dst = Get04BitScanlines(result); + + yOrg = height - 1; + for (int y = 0; y < height; y++, yOrg--) + { + xOrg = width - 1; + for (int x = 0; x < width; x++, xOrg--) + { + index = src[yOrg][xOrg]; + dst[y][x] = index; + } + } + break; + case 270: + result = Allocate(height, width, 4, 0, 0, 0); + if (result.IsNull) + { + break; + } + CopyPalette(dib, result); + src = Get04BitScanlines(dib); + dst = Get04BitScanlines(result); + xOrg = width - 1; + for (int y = 0; y < width; y++, xOrg--) + { + for (int x = 0; x < height; x++) + { + index = src[x][xOrg]; + dst[y][x] = index; + } + } + break; + case 0: + case 360: + result = Clone(dib); + break; + } + } + return result; + } + + #endregion + + #region Upsampling / downsampling + + /// + /// Enlarges or shrinks the FreeImage bitmap selectively per side and fills newly added areas + /// with the specified background color. See remarks for further details. + /// + /// The type of the specified color. + /// Handle to a FreeImage bitmap. + /// The number of pixels, the image should be enlarged on its left side. + /// Negative values shrink the image on its left side. + /// The number of pixels, the image should be enlarged on its top side. + /// Negative values shrink the image on its top side. + /// The number of pixels, the image should be enlarged on its right side. + /// Negative values shrink the image on its right side. + /// The number of pixels, the image should be enlarged on its bottom side. + /// Negative values shrink the image on its bottom side. + /// The color, the enlarged sides of the image should be filled with. + /// Options that affect the color search process for palletized images. + /// Handle to a FreeImage bitmap. + /// + /// This function enlarges or shrinks an image selectively per side. + /// The main purpose of this function is to add borders to an image. + /// To add a border to any of the image's sides, a positive integer value must be passed in + /// any of the parameters , , + /// or . This value represents the border's + /// width in pixels. Newly created parts of the image (the border areas) are filled with the + /// specified . + /// Specifying a negative integer value for a certain side, will shrink or crop the image on + /// this side. Consequently, specifying zero for a certain side will not change the image's + /// extension on that side. + /// + /// So, calling this function with all parameters , , + /// and set to zero, is + /// effectively the same as calling function ; setting all parameters + /// , , and + /// to value equal to or smaller than zero, my easily be substituted + /// by a call to function . Both these cases produce a new image, which is + /// guaranteed not to be larger than the input image. Thus, since the specified + /// is not needed in these cases, + /// may be null. + /// + /// Both parameters and work according to + /// function . So, please refer to the documentation of + /// to learn more about parameters + /// and . For palletized images, the palette of the input image is + /// transparently copied to the newly created enlarged or shrunken image, so any color look-ups + /// are performed on this palette. + /// + /// + /// // create a white color
    + /// RGBQUAD c;
    + /// c.rgbRed = 0xFF;
    + /// c.rgbGreen = 0xFF;
    + /// c.rgbBlue = 0xFF;
    + /// c.rgbReserved = 0x00;
    + ///
    + /// // add a white, symmetric 10 pixel wide border to the image
    + /// dib2 = FreeImage_EnlargeCanvas(dib, 10, 10, 10, 10, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);
    + ///
    + /// // add white, 20 pixel wide stripes to the top and bottom side of the image
    + /// dib3 = FreeImage_EnlargeCanvas(dib, 0, 20, 0, 20, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);
    + ///
    + /// // add white, 30 pixel wide stripes to the right side of the image and
    + /// // cut off the 40 leftmost pixel columns
    + /// dib3 = FreeImage_EnlargeCanvas(dib, -40, 0, 30, 0, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);
    + ///
    + public static FIBITMAP EnlargeCanvas(FIBITMAP dib, int left, int top, int right, int bottom, + T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct + { + if (dib.IsNull) + return FIBITMAP.Zero; + + if (color.HasValue) + { + if (!CheckColorType(GetImageType(dib), color.Value)) + return FIBITMAP.Zero; + + GCHandle handle = new GCHandle(); + try + { + T[] buffer = new T[] { color.Value }; + handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + return EnlargeCanvas(dib, left, top, right, bottom, handle.AddrOfPinnedObject(), options); + } + finally + { + if (handle.IsAllocated) + handle.Free(); + } + } + else + { + return EnlargeCanvas(dib, left, top, right, bottom, IntPtr.Zero, options); + } + } + + #endregion + + #region Color + + /// + /// Sets all pixels of the specified image to the color provided through the + /// parameter. See remarks for further details. + /// + /// The type of the specified color. + /// Handle to a FreeImage bitmap. + /// The color to fill the bitmap with. See remarks for further details. + /// Options that affect the color search process for palletized images. + /// true on success, false on failure. + /// + /// This function sets all pixels of an image to the color provided through + /// the parameter. is used for standard type images. + /// For non standard type images the underlaying structure is used. + /// + /// So, must be of type , if the image to be filled is of type + /// and must be a structure if the + /// image is of type and so on. + /// + /// However, the fill color is always specified through a structure + /// for all images of type . + /// So, for 32- and 24-bit images, the red, green and blue members of the + /// structure are directly used for the image's red, green and blue channel respectively. + /// Although alpha transparent colors are + /// supported, the alpha channel of a 32-bit image never gets modified by this function. + /// A fill color with an alpha value smaller than 255 gets blended with the image's actual + /// background color, which is determined from the image's bottom-left pixel. + /// So, currently using alpha enabled colors, assumes the image to be unicolor before the + /// fill operation. However, the field is only taken into account, + /// if option has been specified. + /// + /// For 16-bit images, the red-, green- and blue components of the specified color are + /// transparently translated into either the 16-bit 555 or 565 representation. This depends + /// on the image's actual red- green- and blue masks. + /// + /// Special attention must be payed for palletized images. Generally, the RGB color specified + /// is looked up in the image's palette. The found palette index is then used to fill the image. + /// There are some option flags, that affect this lookup process: + /// + /// + /// Value + /// Meaning + /// + /// + /// + /// + /// Uses the color, that is nearest to the specified color. + /// This is the default behavior and should always find a + /// color in the palette. However, the visual result may + /// far from what was expected and mainly depends on the + /// image's palette. + /// + /// + /// + /// + /// + /// Searches the image's palette for the specified color + /// but only uses the returned palette index, if the specified + /// color exactly matches the palette entry. Of course, + /// depending on the image's actual palette entries, this + /// operation may fail. In this case, the function falls back + /// to option + /// and uses the RGBQUAD's rgbReserved member (or its low nibble for 4-bit images + /// or its least significant bit (LSB) for 1-bit images) as + /// the palette index used for the fill operation. + /// + /// + /// + /// + /// + /// Does not perform any color lookup from the palette, but + /// uses the RGBQUAD's alpha channel member rgbReserved as + /// the palette index to be used for the fill operation. + /// However, for 4-bit images, only the low nibble of the + /// rgbReserved member are used and for 1-bit images, only + /// the least significant bit (LSB) is used. + /// + /// + /// + /// + public static bool FillBackground(FIBITMAP dib, T color, FREE_IMAGE_COLOR_OPTIONS options) + where T : struct + { + if (dib.IsNull) + return false; + + if (!CheckColorType(GetImageType(dib), color)) + return false; + + GCHandle handle = new GCHandle(); + try + { + T[] buffer = new T[] { color }; + handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + return FillBackground(dib, handle.AddrOfPinnedObject(), options); + } + finally + { + if (handle.IsAllocated) + handle.Free(); + } + } + + #endregion + + #region Wrapper functions + + /// + /// Returns the next higher possible color depth. + /// + /// Color depth to increase. + /// The next higher color depth or 0 if there is no valid color depth. + internal static int GetNextColorDepth(int bpp) + { + int result = 0; + switch (bpp) + { + case 1: + result = 4; + break; + case 4: + result = 8; + break; + case 8: + result = 16; + break; + case 16: + result = 24; + break; + case 24: + result = 32; + break; + } + return result; + } + + /// + /// Returns the next lower possible color depth. + /// + /// Color depth to decrease. + /// The next lower color depth or 0 if there is no valid color depth. + internal static int GetPrevousColorDepth(int bpp) + { + int result = 0; + switch (bpp) + { + case 32: + result = 24; + break; + case 24: + result = 16; + break; + case 16: + result = 8; + break; + case 8: + result = 4; + break; + case 4: + result = 1; + break; + } + return result; + } + + /// + /// Reads a null-terminated c-string. + /// + /// Pointer to the first char of the string. + /// The converted string. + internal static unsafe string PtrToStr(byte* ptr) + { + string result = null; + if (ptr != null) + { + System.Text.StringBuilder sb = new System.Text.StringBuilder(); + + while (*ptr != 0) + { + sb.Append((char)(*(ptr++))); + } + result = sb.ToString(); + } + return result; + } + + internal static unsafe byte[] CreateShrunkenPaletteLUT(FIBITMAP dib, out int uniqueColors) + { + byte[] result = null; + uniqueColors = 0; + + if ((!dib.IsNull) && (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) && (GetBPP(dib) <= 8)) + { + int size = (int)GetColorsUsed(dib); + List newPalette = new List(size); + List lut = new List(size); + RGBQUAD* palette = (RGBQUAD*)GetPalette(dib); + RGBQUAD color; + int index; + + for (int i = 0; i < size; i++) + { + color = palette[i]; + color.rgbReserved = 255; // ignore alpha + + index = newPalette.IndexOf(color); + if (index < 0) + { + newPalette.Add(color); + lut.Add((byte)(newPalette.Count - 1)); + } + else + { + lut.Add((byte)index); + } + } + result = lut.ToArray(); + uniqueColors = newPalette.Count; + } + return result; + } + + internal static PropertyItem CreatePropertyItem() + { + return (PropertyItem)Activator.CreateInstance(typeof(PropertyItem), true); + } + + private static unsafe void CopyPalette(FIBITMAP src, FIBITMAP dst) + { + RGBQUAD* orgPal = (RGBQUAD*)GetPalette(src); + RGBQUAD* newPal = (RGBQUAD*)GetPalette(dst); + uint size = (uint)(sizeof(RGBQUAD) * GetColorsUsed(src)); + CopyMemory(newPal, orgPal, size); + } + + private static unsafe Scanline[] Get04BitScanlines(FIBITMAP dib) + { + int height = (int)GetHeight(dib); + Scanline[] array = new Scanline[height]; + for (int i = 0; i < height; i++) + { + array[i] = new Scanline(dib, i); + } + return array; + } + + /// + /// Changes a bitmaps color depth. + /// Used by SaveEx and SaveToStream. + /// + private static FIBITMAP PrepareBitmapColorDepth(FIBITMAP dibToSave, FREE_IMAGE_FORMAT format, FREE_IMAGE_COLOR_DEPTH colorDepth) + { + FREE_IMAGE_TYPE type = GetImageType(dibToSave); + if (type == FREE_IMAGE_TYPE.FIT_BITMAP) + { + int bpp = (int)GetBPP(dibToSave); + int targetBpp = (int)(colorDepth & FREE_IMAGE_COLOR_DEPTH.FICD_COLOR_MASK); + + if (colorDepth != FREE_IMAGE_COLOR_DEPTH.FICD_AUTO) + { + // A fix colordepth was chosen + if (FIFSupportsExportBPP(format, targetBpp)) + { + dibToSave = ConvertColorDepth(dibToSave, colorDepth, false); + } + else + { + throw new ArgumentException("FreeImage\n\nFreeImage Library plugin " + + GetFormatFromFIF(format) + " is unable to write images with a color depth of " + + targetBpp + " bpp."); + } + } + else + { + // Auto selection was chosen + if (!FIFSupportsExportBPP(format, bpp)) + { + // The color depth is not supported + int bppUpper = bpp; + int bppLower = bpp; + // Check from the bitmaps current color depth in both directions + do + { + bppUpper = GetNextColorDepth(bppUpper); + if (FIFSupportsExportBPP(format, bppUpper)) + { + dibToSave = ConvertColorDepth(dibToSave, (FREE_IMAGE_COLOR_DEPTH)bppUpper, false); + break; + } + bppLower = GetPrevousColorDepth(bppLower); + if (FIFSupportsExportBPP(format, bppLower)) + { + dibToSave = ConvertColorDepth(dibToSave, (FREE_IMAGE_COLOR_DEPTH)bppLower, false); + break; + } + } while (!((bppLower == 0) && (bppUpper == 0))); + } + } + } + return dibToSave; + } + + /// + /// Compares blocks of memory. + /// + /// A pointer to a block of memory to compare. + /// A pointer to a block of memory to compare. + /// Specifies the number of bytes to be compared. + /// true, if all bytes compare as equal, false otherwise. + public static unsafe bool CompareMemory(void* buf1, void* buf2, uint length) + { + return (length == RtlCompareMemory(buf1, buf2, length)); + } + + /// + /// Compares blocks of memory. + /// + /// A pointer to a block of memory to compare. + /// A pointer to a block of memory to compare. + /// Specifies the number of bytes to be compared. + /// true, if all bytes compare as equal, false otherwise. + public static unsafe bool CompareMemory(void* buf1, void* buf2, long length) + { + return (length == RtlCompareMemory(buf1, buf2, checked((uint)length))); + } + + /// + /// Compares blocks of memory. + /// + /// A pointer to a block of memory to compare. + /// A pointer to a block of memory to compare. + /// Specifies the number of bytes to be compared. + /// true, if all bytes compare as equal, false otherwise. + public static unsafe bool CompareMemory(IntPtr buf1, IntPtr buf2, uint length) + { + return (length == RtlCompareMemory(buf1.ToPointer(), buf2.ToPointer(), length)); + } + + /// + /// Compares blocks of memory. + /// + /// A pointer to a block of memory to compare. + /// A pointer to a block of memory to compare. + /// Specifies the number of bytes to be compared. + /// true, if all bytes compare as equal, false otherwise. + public static unsafe bool CompareMemory(IntPtr buf1, IntPtr buf2, long length) + { + return (length == RtlCompareMemory(buf1.ToPointer(), buf2.ToPointer(), checked((uint)length))); + } + + /// + /// Moves a block of memory from one location to another. + /// + /// A pointer to the starting address of the move destination. + /// A pointer to the starting address of the block of memory to be moved. + /// The size of the block of memory to move, in bytes. + public static unsafe void MoveMemory(void* dst, void* src, long size) + { + MoveMemory(dst, src, checked((uint)size)); + } + + /// + /// Moves a block of memory from one location to another. + /// + /// A pointer to the starting address of the move destination. + /// A pointer to the starting address of the block of memory to be moved. + /// The size of the block of memory to move, in bytes. + public static unsafe void MoveMemory(IntPtr dst, IntPtr src, uint size) + { + MoveMemory(dst.ToPointer(), src.ToPointer(), size); + } + + /// + /// Moves a block of memory from one location to another. + /// + /// A pointer to the starting address of the move destination. + /// A pointer to the starting address of the block of memory to be moved. + /// The size of the block of memory to move, in bytes. + public static unsafe void MoveMemory(IntPtr dst, IntPtr src, long size) + { + MoveMemory(dst.ToPointer(), src.ToPointer(), checked((uint)size)); + } + + /// + /// Copies a block of memory from one location to another. + /// + /// A pointer to the starting address of the copied block's destination. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + /// + /// CopyMemory runs faster than . + /// However, if both blocks overlap the result is undefined. + /// + public static unsafe void CopyMemory(byte* dest, byte* src, int len) + { + if (len >= 0x10) + { + do + { + *((int*)dest) = *((int*)src); + *((int*)(dest + 4)) = *((int*)(src + 4)); + *((int*)(dest + 8)) = *((int*)(src + 8)); + *((int*)(dest + 12)) = *((int*)(src + 12)); + dest += 0x10; + src += 0x10; + } + while ((len -= 0x10) >= 0x10); + } + if (len > 0) + { + if ((len & 8) != 0) + { + *((int*)dest) = *((int*)src); + *((int*)(dest + 4)) = *((int*)(src + 4)); + dest += 8; + src += 8; + } + if ((len & 4) != 0) + { + *((int*)dest) = *((int*)src); + dest += 4; + src += 4; + } + if ((len & 2) != 0) + { + *((short*)dest) = *((short*)src); + dest += 2; + src += 2; + } + if ((len & 1) != 0) + { + *dest = *src; + } + } + } + + /// + /// Copies a block of memory from one location to another. + /// + /// A pointer to the starting address of the copied block's destination. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + /// + /// CopyMemory runs faster than . + /// However, if both blocks overlap the result is undefined. + /// + public static unsafe void CopyMemory(byte* dest, byte* src, long len) + { + CopyMemory(dest, src, checked((int)len)); + } + + /// + /// Copies a block of memory from one location to another. + /// + /// A pointer to the starting address of the copied block's destination. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + /// + /// CopyMemory runs faster than . + /// However, if both blocks overlap the result is undefined. + /// + public static unsafe void CopyMemory(void* dest, void* src, long len) + { + CopyMemory((byte*)dest, (byte*)src, checked((int)len)); + } + + /// + /// Copies a block of memory from one location to another. + /// + /// A pointer to the starting address of the copied block's destination. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + /// + /// CopyMemory runs faster than . + /// However, if both blocks overlap the result is undefined. + /// + public static unsafe void CopyMemory(void* dest, void* src, int len) + { + CopyMemory((byte*)dest, (byte*)src, len); + } + + /// + /// Copies a block of memory from one location to another. + /// + /// A pointer to the starting address of the copied block's destination. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + /// + /// CopyMemory runs faster than . + /// However, if both blocks overlap the result is undefined. + /// + public static unsafe void CopyMemory(IntPtr dest, IntPtr src, int len) + { + CopyMemory((byte*)dest, (byte*)src, len); + } + + /// + /// Copies a block of memory from one location to another. + /// + /// A pointer to the starting address of the copied block's destination. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + /// + /// CopyMemory runs faster than . + /// However, if both blocks overlap the result is undefined. + /// + public static unsafe void CopyMemory(IntPtr dest, IntPtr src, long len) + { + CopyMemory((byte*)dest, (byte*)src, checked((int)len)); + } + + /// + /// Copies a block of memory into an array. + /// + /// An array used as the destination of the copy process. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(Array dest, void* src, int len) + { + GCHandle handle = GCHandle.Alloc(dest, GCHandleType.Pinned); + try + { + CopyMemory((byte*)handle.AddrOfPinnedObject(), (byte*)src, len); + } + finally + { + handle.Free(); + } + } + + /// + /// Copies a block of memory into an array. + /// + /// An array used as the destination of the copy process. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(Array dest, void* src, long len) + { + CopyMemory(dest, (byte*)src, checked((int)len)); + } + + /// + /// Copies a block of memory into an array. + /// + /// An array used as the destination of the copy process. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(Array dest, IntPtr src, int len) + { + CopyMemory(dest, (byte*)src, len); + } + + /// + /// Copies a block of memory into an array. + /// + /// An array used as the destination of the copy process. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(Array dest, IntPtr src, long len) + { + CopyMemory(dest, (byte*)src, checked((int)len)); + } + + /// + /// Copies the content of an array to a memory location. + /// + /// A pointer to the starting address of the copied block's destination. + /// An array used as the source of the copy process. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(void* dest, Array src, int len) + { + GCHandle handle = GCHandle.Alloc(src, GCHandleType.Pinned); + try + { + CopyMemory((byte*)dest, (byte*)handle.AddrOfPinnedObject(), len); + } + finally + { + handle.Free(); + } + } + + /// + /// Copies the content of an array to a memory location. + /// + /// A pointer to the starting address of the copied block's destination. + /// An array used as the source of the copy process. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(void* dest, Array src, long len) + { + CopyMemory((byte*)dest, src, checked((int)len)); + } + + /// + /// Copies the content of an array to a memory location. + /// + /// A pointer to the starting address of the copied block's destination. + /// An array used as the source of the copy process. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(IntPtr dest, Array src, int len) + { + CopyMemory((byte*)dest, src, len); + } + + /// + /// Copies the content of an array to a memory location. + /// + /// A pointer to the starting address of the copied block's destination. + /// An array used as the source of the copy process. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(IntPtr dest, Array src, long len) + { + CopyMemory((byte*)dest, src, checked((int)len)); + } + + /// + /// Copies the content of one array into another array. + /// + /// An array used as the destination of the copy process. + /// An array used as the source of the copy process. + /// The size of the content to copy, in bytes. + public static unsafe void CopyMemory(Array dest, Array src, int len) + { + GCHandle dHandle = GCHandle.Alloc(dest, GCHandleType.Pinned); + try + { + GCHandle sHandle = GCHandle.Alloc(src, GCHandleType.Pinned); + try + { + CopyMemory((byte*)dHandle.AddrOfPinnedObject(), (byte*)sHandle.AddrOfPinnedObject(), len); + } + finally + { + sHandle.Free(); + } + } + finally + { + dHandle.Free(); + } + } + + /// + /// Copies the content of one array into another array. + /// + /// An array used as the destination of the copy process. + /// An array used as the source of the copy process. + /// The size of the content to copy, in bytes. + public static unsafe void CopyMemory(Array dest, Array src, long len) + { + CopyMemory(dest, src, checked((int)len)); + } + + internal static string ColorToString(Color color) + { + return string.Format( + System.Globalization.CultureInfo.CurrentCulture, + "{{Name={0}, ARGB=({1}, {2}, {3}, {4})}}", + new object[] { color.Name, color.A, color.R, color.G, color.B }); + } + + internal static void Resize(ref string str, int length) + { + if ((str != null) && (length >= 0) && (str.Length != length)) + { + char[] chars = str.ToCharArray(); + Array.Resize(ref chars, length); + str = new string(chars); + } + } + + internal static void Resize(ref string str, int min, int max) + { + if ((str != null) && (min >= 0) && (max >= 0) && (min <= max)) + { + if (str.Length < min) + { + char[] chars = str.ToCharArray(); + Array.Resize(ref chars, min); + str = new string(chars); + } + else if (str.Length > max) + { + char[] chars = str.ToCharArray(); + Array.Resize(ref chars, max); + str = new string(chars); + } + } + } + + internal static void Resize(ref T[] array, int length) + { + if ((array != null) && (length >= 0) && (array.Length != length)) + { + Array.Resize(ref array, length); + } + } + + internal static void Resize(ref T[] array, int min, int max) + { + if ((array != null) && (min >= 0) && (max >= 0) && (min <= max)) + { + if (array.Length < min) + { + Array.Resize(ref array, min); + } + else if (array.Length > max) + { + Array.Resize(ref array, max); + } + } + } + + internal static bool CheckColorType(FREE_IMAGE_TYPE imageType, T color) + { + Type type = typeof(T); + bool result; + switch (imageType) + { + case FREE_IMAGE_TYPE.FIT_BITMAP: + result = (type == typeof(RGBQUAD)); break; + case FREE_IMAGE_TYPE.FIT_COMPLEX: + result = (type == typeof(FICOMPLEX)); break; + case FREE_IMAGE_TYPE.FIT_DOUBLE: + result = (type == typeof(double)); break; + case FREE_IMAGE_TYPE.FIT_FLOAT: + result = (type == typeof(float)); break; + case FREE_IMAGE_TYPE.FIT_INT16: + result = (type == typeof(Int16)); break; + case FREE_IMAGE_TYPE.FIT_INT32: + result = (type == typeof(Int32)); break; + case FREE_IMAGE_TYPE.FIT_RGB16: + result = (type == typeof(FIRGB16)); break; + case FREE_IMAGE_TYPE.FIT_RGBA16: + result = (type == typeof(FIRGBA16)); break; + case FREE_IMAGE_TYPE.FIT_RGBAF: + result = (type == typeof(FIRGBAF)); break; + case FREE_IMAGE_TYPE.FIT_RGBF: + result = (type == typeof(FIRGBF)); break; + case FREE_IMAGE_TYPE.FIT_UINT16: + result = (type == typeof(UInt16)); break; + case FREE_IMAGE_TYPE.FIT_UINT32: + result = (type == typeof(UInt32)); break; + default: + result = false; break; + } + return result; + } + + #endregion + + #region Dll-Imports + + /// + /// Retrieves a handle to a display device context (DC) for the client area of a specified window + /// or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC. + /// + /// Handle to the window whose DC is to be retrieved. + /// If this value is IntPtr.Zero, GetDC retrieves the DC for the entire screen. + /// If the function succeeds, the return value is a handle to the DC for the specified window's client area. + /// If the function fails, the return value is NULL. + [DllImport("user32.dll")] + private static extern IntPtr GetDC(IntPtr hWnd); + + /// + /// Releases a device context (DC), freeing it for use by other applications. + /// The effect of the ReleaseDC function depends on the type of DC. It frees only common and window DCs. + /// It has no effect on class or private DCs. + /// + /// Handle to the window whose DC is to be released. + /// Handle to the DC to be released. + /// Returns true on success, false on failure. + [DllImport("user32.dll")] + private static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC); + + /// + /// Creates a DIB that applications can write to directly. + /// The function gives you a pointer to the location of the bitmap bit values. + /// You can supply a handle to a file-mapping object that the function will use to create the bitmap, + /// or you can let the system allocate the memory for the bitmap. + /// + /// Handle to a device context. + /// Pointer to a BITMAPINFO structure that specifies various attributes of the DIB, + /// including the bitmap dimensions and colors. + /// Specifies the type of data contained in the bmiColors array member of the BITMAPINFO structure + /// pointed to by pbmi (either logical palette indexes or literal RGB values). + /// Pointer to a variable that receives a pointer to the location of the DIB bit values. + /// Handle to a file-mapping object that the function will use to create the DIB. + /// This parameter can be NULL. + /// Specifies the offset from the beginning of the file-mapping object referenced by hSection + /// where storage for the bitmap bit values is to begin. This value is ignored if hSection is NULL. + /// If the function succeeds, the return value is a handle to the newly created DIB, + /// and *ppvBits points to the bitmap bit values. If the function fails, the return value is NULL, and *ppvBits is NULL. + [DllImport("gdi32.dll")] + private static extern IntPtr CreateDIBSection( + IntPtr hdc, + [In] IntPtr pbmi, + uint iUsage, + out IntPtr ppvBits, + IntPtr hSection, + uint dwOffset); + + /// + /// Deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object. + /// After the object is deleted, the specified handle is no longer valid. + /// + /// Handle to a logical pen, brush, font, bitmap, region, or palette. + /// Returns true on success, false on failure. + [DllImport("gdi32.dll")] + private static extern bool DeleteObject(IntPtr hObject); + + /// + /// Creates a compatible bitmap (DDB) from a DIB and, optionally, sets the bitmap bits. + /// + /// Handle to a device context. + /// Pointer to a bitmap information header structure. + /// Specifies how the system initializes the bitmap bits - (use 4). + /// Pointer to an array of bytes containing the initial bitmap data. + /// Pointer to a BITMAPINFO structure that describes the dimensions + /// and color format of the array pointed to by the lpbInit parameter. + /// Specifies whether the bmiColors member of the BITMAPINFO structure + /// was initialized - (use 0). + /// Handle to a DIB or null on failure. + [DllImport("gdi32.dll")] + private static extern IntPtr CreateDIBitmap( + IntPtr hdc, + IntPtr lpbmih, + uint fdwInit, + IntPtr lpbInit, + IntPtr lpbmi, + uint fuUsage); + + /// + /// Retrieves information for the specified graphics object. + /// + /// Handle to the graphics object of interest. + /// Specifies the number of bytes of information to + /// be written to the buffer. + /// Pointer to a buffer that receives the information + /// about the specified graphics object. + /// 0 on failure. + [DllImport("gdi32.dll")] + private static extern int GetObject(IntPtr hgdiobj, int cbBuffer, IntPtr lpvObject); + + /// + /// Retrieves the bits of the specified compatible bitmap and copies them into a buffer + /// as a DIB using the specified format. + /// + /// Handle to the device context. + /// Handle to the bitmap. This must be a compatible bitmap (DDB). + /// Specifies the first scan line to retrieve. + /// Specifies the number of scan lines to retrieve. + /// Pointer to a buffer to receive the bitmap data. + /// Pointer to a BITMAPINFO structure that specifies the desired + /// format for the DIB data. + /// Specifies the format of the bmiColors member of the + /// BITMAPINFO structure - (use 0). + /// 0 on failure. + [DllImport("gdi32.dll")] + private static extern unsafe int GetDIBits( + IntPtr hdc, + IntPtr hbmp, + uint uStartScan, + uint cScanLines, + IntPtr lpvBits, + IntPtr lpbmi, + uint uUsage); + + /// + /// Moves a block of memory from one location to another. + /// + /// Pointer to the starting address of the move destination. + /// Pointer to the starting address of the block of memory to be moved. + /// Size of the block of memory to move, in bytes. + [DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false)] + public static unsafe extern void MoveMemory(void* dst, void* src, uint size); + + /// + /// The RtlCompareMemory routine compares blocks of memory + /// and returns the number of bytes that are equivalent. + /// + /// A pointer to a block of memory to compare. + /// A pointer to a block of memory to compare. + /// Specifies the number of bytes to be compared. + /// RtlCompareMemory returns the number of bytes that compare as equal. + /// If all bytes compare as equal, the input Length is returned. + [DllImport("ntdll.dll", EntryPoint = "RtlCompareMemory", SetLastError = false)] + internal static unsafe extern uint RtlCompareMemory(void* buf1, void* buf2, uint count); + + #endregion + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Properties/AssemblyInfo.cs b/Wrapper/FreeImage.NET/cs/Library/Properties/AssemblyInfo.cs index f6f8b84..55c10a8 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Properties/AssemblyInfo.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Properties/AssemblyInfo.cs @@ -1,21 +1,21 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Resources; -// -[assembly: AssemblyTitle("FreeImage.NET")] -[assembly: AssemblyDescription(".NET wrapper for the FreeImage 3.15.1 Library")] -[assembly: AssemblyConfiguration("All")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("FreeImage.NET Wrapper")] -[assembly: AssemblyCopyright("Copyright 2003-2011, FreeImage, DataGis")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: AssemblyVersion("3.15.1.0")] -[assembly: AssemblyDelaySign(false)] -[assembly: AssemblyKeyFile("")] -[assembly: AssemblyFileVersionAttribute("3.15.1.0")] -[assembly: ComVisibleAttribute(false)] -[assembly: NeutralResourcesLanguageAttribute("")] -[assembly: GuidAttribute("64a4c935-b757-499c-ab8c-6110316a9e51")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Resources; +// +[assembly: AssemblyTitle("FreeImage.NET")] +[assembly: AssemblyDescription(".NET wrapper for the FreeImage 3.15.1 Library")] +[assembly: AssemblyConfiguration("All")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FreeImage.NET Wrapper")] +[assembly: AssemblyCopyright("Copyright 2003-2011, FreeImage, DataGis")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: AssemblyVersion("3.15.1.0")] +[assembly: AssemblyDelaySign(false)] +[assembly: AssemblyKeyFile("")] +[assembly: AssemblyFileVersionAttribute("3.15.1.0")] +[assembly: ComVisibleAttribute(false)] +[assembly: NeutralResourcesLanguageAttribute("")] +[assembly: GuidAttribute("64a4c935-b757-499c-ab8c-6110316a9e51")] // \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/BITMAP.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/BITMAP.cs index a4347c0..e64d33e 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/BITMAP.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/BITMAP.cs @@ -1,104 +1,104 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.2 $ -// $Date: 2008/06/16 15:15:36 $ -// $Id: BITMAP.cs,v 1.2 2008/06/16 15:15:36 cklein05 Exp $ -// ========================================================== - -using System; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The BITMAP structure defines the type, width, height, color format, and bit values of a bitmap. - /// - /// - /// The bitmap formats currently used are monochrome and color. The monochrome bitmap uses a one-bit, - /// one-plane format. Each scan is a multiple of 32 bits. - /// - /// Scans are organized as follows for a monochrome bitmap of height n: - /// - /// - /// Scan 0 - /// Scan 1 - /// . - /// . - /// . - /// Scan n-2 - /// Scan n-1 - /// - /// - /// The pixels on a monochrome device are either black or white. If the corresponding bit in the - /// bitmap is 1, the pixel is set to the foreground color; if the corresponding bit in the bitmap - /// is zero, the pixel is set to the background color. - /// - /// All devices that have the RC_BITBLT device capability support bitmaps. For more information, - /// see GetDeviceCaps. - /// - /// Each device has a unique color format. To transfer a bitmap from one device to another, - /// use the GetDIBits and SetDIBits functions. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct BITMAP - { - /// - /// Specifies the bitmap type. This member must be zero. - /// - public int bmType; - /// - /// Specifies the width, in pixels, of the bitmap. The width must be greater than zero. - /// - public int bmWidth; - /// - /// Specifies the height, in pixels, of the bitmap. The height must be greater than zero. - /// - public int bmHeight; - /// - /// Specifies the number of bytes in each scan line. This value must be divisible by 2, - /// because the system assumes that the bit values of a bitmap form an array that is word aligned. - /// - public int bmWidthBytes; - /// - /// Specifies the count of color planes. - /// - public ushort bmPlanes; - /// - /// Specifies the number of bits required to indicate the color of a pixel. - /// - public ushort bmBitsPixel; - /// - /// Pointer to the location of the bit values for the bitmap. - /// The bmBits member must be a long pointer to an array of character (1-byte) values. - /// - public IntPtr bmBits; - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.2 $ +// $Date: 2008/06/16 15:15:36 $ +// $Id: BITMAP.cs,v 1.2 2008/06/16 15:15:36 cklein05 Exp $ +// ========================================================== + +using System; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The BITMAP structure defines the type, width, height, color format, and bit values of a bitmap. + /// + /// + /// The bitmap formats currently used are monochrome and color. The monochrome bitmap uses a one-bit, + /// one-plane format. Each scan is a multiple of 32 bits. + /// + /// Scans are organized as follows for a monochrome bitmap of height n: + /// + /// + /// Scan 0 + /// Scan 1 + /// . + /// . + /// . + /// Scan n-2 + /// Scan n-1 + /// + /// + /// The pixels on a monochrome device are either black or white. If the corresponding bit in the + /// bitmap is 1, the pixel is set to the foreground color; if the corresponding bit in the bitmap + /// is zero, the pixel is set to the background color. + /// + /// All devices that have the RC_BITBLT device capability support bitmaps. For more information, + /// see GetDeviceCaps. + /// + /// Each device has a unique color format. To transfer a bitmap from one device to another, + /// use the GetDIBits and SetDIBits functions. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct BITMAP + { + /// + /// Specifies the bitmap type. This member must be zero. + /// + public int bmType; + /// + /// Specifies the width, in pixels, of the bitmap. The width must be greater than zero. + /// + public int bmWidth; + /// + /// Specifies the height, in pixels, of the bitmap. The height must be greater than zero. + /// + public int bmHeight; + /// + /// Specifies the number of bytes in each scan line. This value must be divisible by 2, + /// because the system assumes that the bit values of a bitmap form an array that is word aligned. + /// + public int bmWidthBytes; + /// + /// Specifies the count of color planes. + /// + public ushort bmPlanes; + /// + /// Specifies the number of bits required to indicate the color of a pixel. + /// + public ushort bmBitsPixel; + /// + /// Pointer to the location of the bit values for the bitmap. + /// The bmBits member must be a long pointer to an array of character (1-byte) values. + /// + public IntPtr bmBits; + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/BITMAPINFO.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/BITMAPINFO.cs index 5b0a9f0..8e1da37 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/BITMAPINFO.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/BITMAPINFO.cs @@ -1,203 +1,203 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.3 $ -// $Date: 2008/06/16 15:16:07 $ -// $Id: BITMAPINFO.cs,v 1.3 2008/06/16 15:16:07 cklein05 Exp $ -// ========================================================== - -using System; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The BITMAPINFO structure defines the dimensions and color information for a DIB. - /// - /// - /// A DIB consists of two distinct parts: a BITMAPINFO structure describing the dimensions - /// and colors of the bitmap, and an array of bytes defining the pixels of the bitmap. The bits in - /// the array are packed together, but each scan line must be padded with zeroes to end on a - /// LONG data-type boundary. If the height of the bitmap is positive, the bitmap is a - /// bottom-up DIB and its origin is the lower-left corner. If the height is negative, the bitmap is - /// a top-down DIB and its origin is the upper left corner. - /// - /// A bitmap is packed when the bitmap array immediately follows the BITMAPINFO header. - /// Packed bitmaps are referenced by a single pointer. For packed bitmaps, the biClrUsed - /// member must be set to an even number when using the DIB_PAL_COLORS mode so that the DIB bitmap - /// array starts on a DWORD boundary. - /// - /// Note The bmiColors member should not contain palette indexes if the bitmap is to - /// be stored in a file or transferred to another application. - /// - /// Unless the application has exclusive use and control of the bitmap, the bitmap color table - /// should contain explicit RGB values. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct BITMAPINFO : IEquatable - { - /// - /// Specifies a structure that contains information - /// about the dimensions of color format. - /// - public BITMAPINFOHEADER bmiHeader; - /// - /// The bmiColors member contains one of the following: - /// - /// - /// - /// - /// An array of . The elements of the array that make up the - /// color table. - /// - /// - /// - /// - /// - /// An array of 16-bit unsigned integers that specifies indexes into the currently realized - /// logical palette. This use of bmiColors is allowed for functions that use DIBs. - /// When bmiColors elements contain indexes to a realized logical palette, they must - /// also call the following bitmap functions: - /// - /// - /// - /// - /// CreateDIBitmap - /// - /// CreateDIBPatternBrush - /// - /// CreateDIBSection - /// - /// The iUsage parameter of CreateDIBSection must be set to DIB_PAL_COLORS. - /// - /// The number of entries in the array depends on the values of the biBitCount and - /// biClrUsed members of the structure. - /// - /// The colors in the bmiColors table appear in order of importance. For more information, - /// see the Remarks section. - /// - public RGBQUAD[] bmiColors; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(BITMAPINFO left, BITMAPINFO right) - { - if (left.bmiHeader != right.bmiHeader) - { - return false; - } - if ((left.bmiColors == null) && (right.bmiColors == null)) - { - return true; - } - if ((left.bmiColors == null) || (right.bmiColors == null)) - { - return false; - } - if (left.bmiColors.Length != right.bmiColors.Length) - { - return false; - } - for (int i = 0; i < left.bmiColors.Length; i++) - { - if (left.bmiColors[i] != right.bmiColors[i]) - { - return false; - } - } - return true; - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(BITMAPINFO left, BITMAPINFO right) - { - return !(left == right); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(BITMAPINFO other) - { - return (this == other); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is BITMAPINFO) && (this == ((BITMAPINFO)obj))); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - int hash = bmiHeader.GetHashCode(); - if (bmiColors != null) - { - for (int c = 0; c < bmiColors.Length; c++) - { - hash ^= bmiColors[c].GetHashCode(); - hash <<= 1; - } - hash <<= 1; - } - else - { - hash >>= 1; - } - return hash; - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.3 $ +// $Date: 2008/06/16 15:16:07 $ +// $Id: BITMAPINFO.cs,v 1.3 2008/06/16 15:16:07 cklein05 Exp $ +// ========================================================== + +using System; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The BITMAPINFO structure defines the dimensions and color information for a DIB. + /// + /// + /// A DIB consists of two distinct parts: a BITMAPINFO structure describing the dimensions + /// and colors of the bitmap, and an array of bytes defining the pixels of the bitmap. The bits in + /// the array are packed together, but each scan line must be padded with zeroes to end on a + /// LONG data-type boundary. If the height of the bitmap is positive, the bitmap is a + /// bottom-up DIB and its origin is the lower-left corner. If the height is negative, the bitmap is + /// a top-down DIB and its origin is the upper left corner. + /// + /// A bitmap is packed when the bitmap array immediately follows the BITMAPINFO header. + /// Packed bitmaps are referenced by a single pointer. For packed bitmaps, the biClrUsed + /// member must be set to an even number when using the DIB_PAL_COLORS mode so that the DIB bitmap + /// array starts on a DWORD boundary. + /// + /// Note The bmiColors member should not contain palette indexes if the bitmap is to + /// be stored in a file or transferred to another application. + /// + /// Unless the application has exclusive use and control of the bitmap, the bitmap color table + /// should contain explicit RGB values. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct BITMAPINFO : IEquatable + { + /// + /// Specifies a structure that contains information + /// about the dimensions of color format. + /// + public BITMAPINFOHEADER bmiHeader; + /// + /// The bmiColors member contains one of the following: + /// + /// + /// + /// + /// An array of . The elements of the array that make up the + /// color table. + /// + /// + /// + /// + /// + /// An array of 16-bit unsigned integers that specifies indexes into the currently realized + /// logical palette. This use of bmiColors is allowed for functions that use DIBs. + /// When bmiColors elements contain indexes to a realized logical palette, they must + /// also call the following bitmap functions: + /// + /// + /// + /// + /// CreateDIBitmap + /// + /// CreateDIBPatternBrush + /// + /// CreateDIBSection + /// + /// The iUsage parameter of CreateDIBSection must be set to DIB_PAL_COLORS. + /// + /// The number of entries in the array depends on the values of the biBitCount and + /// biClrUsed members of the structure. + /// + /// The colors in the bmiColors table appear in order of importance. For more information, + /// see the Remarks section. + /// + public RGBQUAD[] bmiColors; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(BITMAPINFO left, BITMAPINFO right) + { + if (left.bmiHeader != right.bmiHeader) + { + return false; + } + if ((left.bmiColors == null) && (right.bmiColors == null)) + { + return true; + } + if ((left.bmiColors == null) || (right.bmiColors == null)) + { + return false; + } + if (left.bmiColors.Length != right.bmiColors.Length) + { + return false; + } + for (int i = 0; i < left.bmiColors.Length; i++) + { + if (left.bmiColors[i] != right.bmiColors[i]) + { + return false; + } + } + return true; + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(BITMAPINFO left, BITMAPINFO right) + { + return !(left == right); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(BITMAPINFO other) + { + return (this == other); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is BITMAPINFO) && (this == ((BITMAPINFO)obj))); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + int hash = bmiHeader.GetHashCode(); + if (bmiColors != null) + { + for (int c = 0; c < bmiColors.Length; c++) + { + hash ^= bmiColors[c].GetHashCode(); + hash <<= 1; + } + hash <<= 1; + } + else + { + hash >>= 1; + } + return hash; + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/BITMAPINFOHEADER.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/BITMAPINFOHEADER.cs index 007870b..61a80b5 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/BITMAPINFOHEADER.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/BITMAPINFOHEADER.cs @@ -1,352 +1,352 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.4 $ -// $Date: 2008/06/16 15:17:37 $ -// $Id: BITMAPINFOHEADER.cs,v 1.4 2008/06/16 15:17:37 cklein05 Exp $ -// ========================================================== - -using System; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// This structure contains information about the dimensions and color format - /// of a device-independent bitmap (DIB). - /// - /// - /// The structure combines the - /// BITMAPINFOHEADER structure and a color table to provide a complete - /// definition of the dimensions and colors of a DIB. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct BITMAPINFOHEADER : IEquatable - { - /// - /// Specifies the size of the structure, in bytes. - /// - public uint biSize; - /// - /// Specifies the width of the bitmap, in pixels. - /// - /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, - /// the biWidth member specifies the width of the decompressed JPEG or PNG image file, - /// respectively. - /// - public int biWidth; - /// - /// Specifies the height of the bitmap, in pixels. If biHeight is positive, the bitmap - /// is a bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, - /// the bitmap is a top-down DIB and its origin is the upper-left corner. - /// - /// If biHeight is negative, indicating a top-down DIB, biCompression must be - /// either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed. - /// - /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, - /// the biHeight member specifies the height of the decompressed JPEG or PNG image file, - /// respectively. - /// - public int biHeight; - /// - /// Specifies the number of planes for the target device. This value must be set to 1. - /// - public ushort biPlanes; - /// - /// Specifies the number of bits per pixel.The biBitCount member of the BITMAPINFOHEADER - /// structure determines the number of bits that define each pixel and the maximum number of - /// colors in the bitmap. This member must be one of the following values. - /// - /// - /// - /// - /// Value - /// Meaning - /// - /// - /// - /// 0 - /// - /// Windows 98/Me, Windows 2000/XP: The number of bits-per-pixel is specified - /// or is implied by the JPEG or PNG format. - /// - /// - /// - /// - /// 1 - /// - /// The bitmap is monochrome, and the bmiColors member of - /// contains two entries. Each bit in the bitmap array represents a pixel. If the bit is clear, - /// the pixel is displayed with the color of the first entry in the bmiColors table; if the bit - /// is set, the pixel has the color of the second entry in the table. - /// - /// - /// - /// - /// 4 - /// - /// The bitmap has a maximum of 16 colors, and the bmiColors member of BITMAPINFO - /// contains up to 16 entries. Each pixel in the bitmap is represented by a 4-bit index into the - /// color table. For example, if the first byte in the bitmap is 0x1F, the byte represents two - /// pixels. The first pixel contains the color in the second table entry, and the second pixel - /// contains the color in the sixteenth table entry. - /// - /// - /// - /// 8 - /// - /// The bitmap has a maximum of 256 colors, and the bmiColors member of BITMAPINFO - /// contains up to 256 entries. In this case, each byte in the array represents a single pixel. - /// - /// - /// - /// - /// 16 - /// - /// The bitmap has a maximum of 2^16 colors. If the biCompression member of the - /// BITMAPINFOHEADER is BI_RGB, the bmiColors member of BITMAPINFO is NULL. - /// Each WORD in the bitmap array represents a single pixel. The relative intensities - /// of red, green, and blue are represented with five bits for each color component. - /// The value for blue is in the least significant five bits, followed by five bits each for - /// green and red. The most significant bit is not used. The bmiColors color table is used - /// for optimizing colors used on palette-based devices, and must contain the number of entries - /// specified by the biClrUsed member of the BITMAPINFOHEADER. - /// - /// If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, the - /// bmiColors member contains three DWORD color masks that specify the red, green, - /// and blue components, respectively, of each pixel. Each WORD in the bitmap array represents - /// a single pixel. - /// - /// Windows NT/Windows 2000/XP: When the biCompression member is BI_BITFIELDS, - /// bits set in each DWORD mask must be contiguous and should not overlap the bits - /// of another mask. All the bits in the pixel do not have to be used. - /// - /// Windows 95/98/Me: When the biCompression member is BI_BITFIELDS, the system - /// supports only the following 16bpp color masks: A 5-5-5 16-bit image, where the blue mask is - /// 0x001F, the green mask is 0x03E0, and the red mask is 0x7C00; and a 5-6-5 16-bit image, - /// where the blue mask is 0x001F, the green mask is 0x07E0, and the red mask is 0xF800. - /// - /// - /// - /// - /// 24 - /// - /// The bitmap has a maximum of 2^24 colors, and the bmiColors member of BITMAPINFO - /// is NULL. Each 3-byte triplet in the bitmap array represents the relative intensities of blue, - /// green, and red, respectively, for a pixel. The bmiColors color table is used for - /// optimizing colors used on palette-based devices, and must contain the number of entries - /// specified by the biClrUsed member of the BITMAPINFOHEADER. - /// - /// - /// - /// - /// 32 - /// - /// The bitmap has a maximum of 2^32 colors. If the biCompression member of the - /// BITMAPINFOHEADER is BI_RGB, the bmiColors member of BITMAPINFO is NULL. - /// Each DWORD in the bitmap array represents the relative intensities of blue, green, and red, - /// respectively, for a pixel. The high byte in each DWORD is not used. The bmiColors - /// color table is used for optimizing colors used on palette-based devices, and must contain the - /// number of entries specified by the biClrUsed member of the BITMAPINFOHEADER. - /// - /// If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, - /// the bmiColors member contains three DWORD color masks that specify the red, green, - /// and blue components, respectively, of each pixel. Each DWORD in the bitmap array represents - /// a single pixel. - /// - /// Windows NT/ 2000: When the biCompression member is BI_BITFIELDS, bits set in each - /// DWORD mask must be contiguous and should not overlap the bits of another mask. All the - /// bits in the pixel do not need to be used. - /// - /// Windows 95/98/Me: When the biCompression member is BI_BITFIELDS, the system - /// supports only the following 32-bpp color mask: The blue mask is 0x000000FF, the green mask is - /// 0x0000FF00, and the red mask is 0x00FF0000. - /// - /// - /// - /// - public ushort biBitCount; - /// - /// Specifies the type of compression for a compressed bottom-up bitmap (top-down DIBs cannot be - /// compressed). - /// - /// - /// Value - /// Meaning - /// - /// - /// - /// BI_RGB - /// An uncompressed format. - /// - /// - /// - /// BI_RLE8 - /// A run-length encoded (RLE) format for bitmaps with 8 bpp. The compression format - /// is a 2-byte format consisting of a count byte followed by a byte containing a color index. - /// - /// - /// - /// - /// BI_RLE4 - /// An RLE format for bitmaps with 4 bpp. The compression format is a 2-byte format - /// consisting of a count byte followed by two word-length color indexes. - /// - /// - /// - /// BI_BITFIELDS - /// Specifies that the bitmap is not compressed and that the color table consists - /// of three DWORD color masks that specify the red, green, and blue components, respectively, - /// of each pixel. This is valid when used with 16- and 32-bpp bitmaps. - /// - /// - /// - /// BI_JPEG - /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a JPEG image. - /// - /// - /// - /// - /// BI_PNG - /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a PNG image. - /// - /// - /// - /// - /// - public uint biCompression; - /// - /// Specifies the size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps. - /// - /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, - /// biSizeImage indicates the size of the JPEG or PNG image buffer, respectively. - /// - public uint biSizeImage; - /// - /// Specifies the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. - /// An application can use this value to select a bitmap from a resource group that best matches - /// the characteristics of the current device. - /// - public int biXPelsPerMeter; - /// - /// Specifies the vertical resolution, in pixels-per-meter, of the target device for the bitmap. - /// - public int biYPelsPerMeter; - /// - /// Specifies the number of color indexes in the color table that are actually used by the bitmap. - /// If this value is zero, the bitmap uses the maximum number of colors corresponding to the value - /// of the biBitCount member for the compression mode specified by biCompression. - /// - /// If iClrUsed is nonzero and the biBitCount member is less than 16, the biClrUsed - /// member specifies the actual number of colors the graphics engine or device driver accesses. - /// If biBitCount is 16 or greater, the biClrUsed member specifies the size of the color - /// table used to optimize performance of the system color palettes. If biBitCount equals 16 or 32, - /// the optimal color palette starts immediately following the three DWORD masks. - /// - /// When the bitmap array immediately follows the structure, it is a packed bitmap. - /// Packed bitmaps are referenced by a single pointer. Packed bitmaps require that the - /// biClrUsed member must be either zero or the actual size of the color table. - /// - public uint biClrUsed; - /// - /// Specifies the number of color indexes that are required for displaying the bitmap. If this value - /// is zero, all colors are required. - /// - public uint biClrImportant; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(BITMAPINFOHEADER left, BITMAPINFOHEADER right) - { - return ((left.biSize == right.biSize) && - (left.biWidth == right.biWidth) && - (left.biHeight == right.biHeight) && - (left.biPlanes == right.biPlanes) && - (left.biBitCount == right.biBitCount) && - (left.biCompression == right.biCompression) && - (left.biSizeImage == right.biSizeImage) && - (left.biXPelsPerMeter == right.biXPelsPerMeter) && - (left.biYPelsPerMeter == right.biYPelsPerMeter) && - (left.biClrUsed == right.biClrUsed) && - (left.biClrImportant == right.biClrImportant)); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(BITMAPINFOHEADER left, BITMAPINFOHEADER right) - { - return !(left == right); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(BITMAPINFOHEADER other) - { - return (this == other); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is BITMAPINFOHEADER) && (this == (BITMAPINFOHEADER)obj)); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.4 $ +// $Date: 2008/06/16 15:17:37 $ +// $Id: BITMAPINFOHEADER.cs,v 1.4 2008/06/16 15:17:37 cklein05 Exp $ +// ========================================================== + +using System; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// This structure contains information about the dimensions and color format + /// of a device-independent bitmap (DIB). + /// + /// + /// The structure combines the + /// BITMAPINFOHEADER structure and a color table to provide a complete + /// definition of the dimensions and colors of a DIB. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct BITMAPINFOHEADER : IEquatable + { + /// + /// Specifies the size of the structure, in bytes. + /// + public uint biSize; + /// + /// Specifies the width of the bitmap, in pixels. + /// + /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, + /// the biWidth member specifies the width of the decompressed JPEG or PNG image file, + /// respectively. + /// + public int biWidth; + /// + /// Specifies the height of the bitmap, in pixels. If biHeight is positive, the bitmap + /// is a bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, + /// the bitmap is a top-down DIB and its origin is the upper-left corner. + /// + /// If biHeight is negative, indicating a top-down DIB, biCompression must be + /// either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed. + /// + /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, + /// the biHeight member specifies the height of the decompressed JPEG or PNG image file, + /// respectively. + /// + public int biHeight; + /// + /// Specifies the number of planes for the target device. This value must be set to 1. + /// + public ushort biPlanes; + /// + /// Specifies the number of bits per pixel.The biBitCount member of the BITMAPINFOHEADER + /// structure determines the number of bits that define each pixel and the maximum number of + /// colors in the bitmap. This member must be one of the following values. + /// + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// + /// 0 + /// + /// Windows 98/Me, Windows 2000/XP: The number of bits-per-pixel is specified + /// or is implied by the JPEG or PNG format. + /// + /// + /// + /// + /// 1 + /// + /// The bitmap is monochrome, and the bmiColors member of + /// contains two entries. Each bit in the bitmap array represents a pixel. If the bit is clear, + /// the pixel is displayed with the color of the first entry in the bmiColors table; if the bit + /// is set, the pixel has the color of the second entry in the table. + /// + /// + /// + /// + /// 4 + /// + /// The bitmap has a maximum of 16 colors, and the bmiColors member of BITMAPINFO + /// contains up to 16 entries. Each pixel in the bitmap is represented by a 4-bit index into the + /// color table. For example, if the first byte in the bitmap is 0x1F, the byte represents two + /// pixels. The first pixel contains the color in the second table entry, and the second pixel + /// contains the color in the sixteenth table entry. + /// + /// + /// + /// 8 + /// + /// The bitmap has a maximum of 256 colors, and the bmiColors member of BITMAPINFO + /// contains up to 256 entries. In this case, each byte in the array represents a single pixel. + /// + /// + /// + /// + /// 16 + /// + /// The bitmap has a maximum of 2^16 colors. If the biCompression member of the + /// BITMAPINFOHEADER is BI_RGB, the bmiColors member of BITMAPINFO is NULL. + /// Each WORD in the bitmap array represents a single pixel. The relative intensities + /// of red, green, and blue are represented with five bits for each color component. + /// The value for blue is in the least significant five bits, followed by five bits each for + /// green and red. The most significant bit is not used. The bmiColors color table is used + /// for optimizing colors used on palette-based devices, and must contain the number of entries + /// specified by the biClrUsed member of the BITMAPINFOHEADER. + /// + /// If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, the + /// bmiColors member contains three DWORD color masks that specify the red, green, + /// and blue components, respectively, of each pixel. Each WORD in the bitmap array represents + /// a single pixel. + /// + /// Windows NT/Windows 2000/XP: When the biCompression member is BI_BITFIELDS, + /// bits set in each DWORD mask must be contiguous and should not overlap the bits + /// of another mask. All the bits in the pixel do not have to be used. + /// + /// Windows 95/98/Me: When the biCompression member is BI_BITFIELDS, the system + /// supports only the following 16bpp color masks: A 5-5-5 16-bit image, where the blue mask is + /// 0x001F, the green mask is 0x03E0, and the red mask is 0x7C00; and a 5-6-5 16-bit image, + /// where the blue mask is 0x001F, the green mask is 0x07E0, and the red mask is 0xF800. + /// + /// + /// + /// + /// 24 + /// + /// The bitmap has a maximum of 2^24 colors, and the bmiColors member of BITMAPINFO + /// is NULL. Each 3-byte triplet in the bitmap array represents the relative intensities of blue, + /// green, and red, respectively, for a pixel. The bmiColors color table is used for + /// optimizing colors used on palette-based devices, and must contain the number of entries + /// specified by the biClrUsed member of the BITMAPINFOHEADER. + /// + /// + /// + /// + /// 32 + /// + /// The bitmap has a maximum of 2^32 colors. If the biCompression member of the + /// BITMAPINFOHEADER is BI_RGB, the bmiColors member of BITMAPINFO is NULL. + /// Each DWORD in the bitmap array represents the relative intensities of blue, green, and red, + /// respectively, for a pixel. The high byte in each DWORD is not used. The bmiColors + /// color table is used for optimizing colors used on palette-based devices, and must contain the + /// number of entries specified by the biClrUsed member of the BITMAPINFOHEADER. + /// + /// If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, + /// the bmiColors member contains three DWORD color masks that specify the red, green, + /// and blue components, respectively, of each pixel. Each DWORD in the bitmap array represents + /// a single pixel. + /// + /// Windows NT/ 2000: When the biCompression member is BI_BITFIELDS, bits set in each + /// DWORD mask must be contiguous and should not overlap the bits of another mask. All the + /// bits in the pixel do not need to be used. + /// + /// Windows 95/98/Me: When the biCompression member is BI_BITFIELDS, the system + /// supports only the following 32-bpp color mask: The blue mask is 0x000000FF, the green mask is + /// 0x0000FF00, and the red mask is 0x00FF0000. + /// + /// + /// + /// + public ushort biBitCount; + /// + /// Specifies the type of compression for a compressed bottom-up bitmap (top-down DIBs cannot be + /// compressed). + /// + /// + /// Value + /// Meaning + /// + /// + /// + /// BI_RGB + /// An uncompressed format. + /// + /// + /// + /// BI_RLE8 + /// A run-length encoded (RLE) format for bitmaps with 8 bpp. The compression format + /// is a 2-byte format consisting of a count byte followed by a byte containing a color index. + /// + /// + /// + /// + /// BI_RLE4 + /// An RLE format for bitmaps with 4 bpp. The compression format is a 2-byte format + /// consisting of a count byte followed by two word-length color indexes. + /// + /// + /// + /// BI_BITFIELDS + /// Specifies that the bitmap is not compressed and that the color table consists + /// of three DWORD color masks that specify the red, green, and blue components, respectively, + /// of each pixel. This is valid when used with 16- and 32-bpp bitmaps. + /// + /// + /// + /// BI_JPEG + /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a JPEG image. + /// + /// + /// + /// + /// BI_PNG + /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a PNG image. + /// + /// + /// + /// + /// + public uint biCompression; + /// + /// Specifies the size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps. + /// + /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, + /// biSizeImage indicates the size of the JPEG or PNG image buffer, respectively. + /// + public uint biSizeImage; + /// + /// Specifies the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. + /// An application can use this value to select a bitmap from a resource group that best matches + /// the characteristics of the current device. + /// + public int biXPelsPerMeter; + /// + /// Specifies the vertical resolution, in pixels-per-meter, of the target device for the bitmap. + /// + public int biYPelsPerMeter; + /// + /// Specifies the number of color indexes in the color table that are actually used by the bitmap. + /// If this value is zero, the bitmap uses the maximum number of colors corresponding to the value + /// of the biBitCount member for the compression mode specified by biCompression. + /// + /// If iClrUsed is nonzero and the biBitCount member is less than 16, the biClrUsed + /// member specifies the actual number of colors the graphics engine or device driver accesses. + /// If biBitCount is 16 or greater, the biClrUsed member specifies the size of the color + /// table used to optimize performance of the system color palettes. If biBitCount equals 16 or 32, + /// the optimal color palette starts immediately following the three DWORD masks. + /// + /// When the bitmap array immediately follows the structure, it is a packed bitmap. + /// Packed bitmaps are referenced by a single pointer. Packed bitmaps require that the + /// biClrUsed member must be either zero or the actual size of the color table. + /// + public uint biClrUsed; + /// + /// Specifies the number of color indexes that are required for displaying the bitmap. If this value + /// is zero, all colors are required. + /// + public uint biClrImportant; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(BITMAPINFOHEADER left, BITMAPINFOHEADER right) + { + return ((left.biSize == right.biSize) && + (left.biWidth == right.biWidth) && + (left.biHeight == right.biHeight) && + (left.biPlanes == right.biPlanes) && + (left.biBitCount == right.biBitCount) && + (left.biCompression == right.biCompression) && + (left.biSizeImage == right.biSizeImage) && + (left.biXPelsPerMeter == right.biXPelsPerMeter) && + (left.biYPelsPerMeter == right.biYPelsPerMeter) && + (left.biClrUsed == right.biClrUsed) && + (left.biClrImportant == right.biClrImportant)); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(BITMAPINFOHEADER left, BITMAPINFOHEADER right) + { + return !(left == right); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(BITMAPINFOHEADER other) + { + return (this == other); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is BITMAPINFOHEADER) && (this == (BITMAPINFOHEADER)obj)); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FI16RGB555.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FI16RGB555.cs index 83adb5a..e4c189d 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FI16RGB555.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FI16RGB555.cs @@ -1,277 +1,277 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.3 $ -// $Date: 2009/02/20 07:41:08 $ -// $Id: FI16RGB555.cs,v 1.3 2009/02/20 07:41:08 cklein05 Exp $ -// ========================================================== - -using System; -using System.Drawing; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The FI16RGB555 structure describes a color consisting of relative - /// intensities of red, green, blue and alpha value. Each single color - /// component consumes 5 bits and so, takes values in the range from 0 to 31. - /// - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the FI16RGB555 structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the FI16RGB555 structure and my be used in all situations which require - /// an FI16RGB555 type. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// FI16RGB555 structure and the structure. - /// - /// FI16RGB555 fi16rgb; - /// // Initialize the structure using a native .NET Color structure. - /// fi16rgb = new FI16RGB555(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// fi16rgb = Color.DarkSeaGreen; - /// // Convert the FI16RGB555 instance into a native .NET Color - /// // using its implicit operator. - /// Color color = fi16rgb; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = fi16rgb.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FI16RGB555 : IComparable, IComparable, IEquatable - { - /// - /// The value of the color. - /// - private ushort value; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public FI16RGB555(Color color) - { - value = (ushort)( - (((color.R * 31) / 255) << FreeImage.FI16_555_RED_SHIFT) + - (((color.G * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT) + - (((color.B * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT)); - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FI16RGB555 left, FI16RGB555 right) - { - return (left.value == right.value); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FI16RGB555 left, FI16RGB555 right) - { - return (!(left == right)); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FI16RGB555(Color value) - { - return new FI16RGB555(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(FI16RGB555 value) - { - return value.Color; - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb( - ((value & FreeImage.FI16_555_RED_MASK) >> FreeImage.FI16_555_RED_SHIFT) * 255 / 31, - ((value & FreeImage.FI16_555_GREEN_MASK) >> FreeImage.FI16_555_GREEN_SHIFT) * 255 / 31, - ((value & FreeImage.FI16_555_BLUE_MASK) >> FreeImage.FI16_555_BLUE_SHIFT) * 255 / 31); - } - set - { - this.value = (ushort)( - (((value.R * 31) / 255) << FreeImage.FI16_555_RED_SHIFT) + - (((value.G * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT) + - (((value.B * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT)); - } - } - - /// - /// Gets or sets the red color component. - /// - public byte Red - { - get - { - return (byte)(((value & FreeImage.FI16_555_RED_MASK) >> FreeImage.FI16_555_RED_SHIFT) * 255 / 31); - } - set - { - this.value = (ushort)((this.value & (~FreeImage.FI16_555_RED_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_RED_SHIFT)); - } - } - - /// - /// Gets or sets the green color component. - /// - public byte Green - { - get - { - return (byte)(((value & FreeImage.FI16_555_GREEN_MASK) >> FreeImage.FI16_555_GREEN_SHIFT) * 255 / 31); - } - set - { - this.value = (ushort)((this.value & (~FreeImage.FI16_555_GREEN_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT)); - } - } - - /// - /// Gets or sets the blue color component. - /// - public byte Blue - { - get - { - return (byte)(((value & FreeImage.FI16_555_BLUE_MASK) >> FreeImage.FI16_555_BLUE_SHIFT) * 255 / 31); - } - set - { - this.value = (ushort)((this.value & (~FreeImage.FI16_555_BLUE_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT)); - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FI16RGB555)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FI16RGB555)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FI16RGB555 other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return base.Equals(obj); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FI16RGB555 other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.3 $ +// $Date: 2009/02/20 07:41:08 $ +// $Id: FI16RGB555.cs,v 1.3 2009/02/20 07:41:08 cklein05 Exp $ +// ========================================================== + +using System; +using System.Drawing; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The FI16RGB555 structure describes a color consisting of relative + /// intensities of red, green, blue and alpha value. Each single color + /// component consumes 5 bits and so, takes values in the range from 0 to 31. + /// + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the FI16RGB555 structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the FI16RGB555 structure and my be used in all situations which require + /// an FI16RGB555 type. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// FI16RGB555 structure and the structure. + /// + /// FI16RGB555 fi16rgb; + /// // Initialize the structure using a native .NET Color structure. + /// fi16rgb = new FI16RGB555(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// fi16rgb = Color.DarkSeaGreen; + /// // Convert the FI16RGB555 instance into a native .NET Color + /// // using its implicit operator. + /// Color color = fi16rgb; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = fi16rgb.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FI16RGB555 : IComparable, IComparable, IEquatable + { + /// + /// The value of the color. + /// + private ushort value; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public FI16RGB555(Color color) + { + value = (ushort)( + (((color.R * 31) / 255) << FreeImage.FI16_555_RED_SHIFT) + + (((color.G * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT) + + (((color.B * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT)); + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FI16RGB555 left, FI16RGB555 right) + { + return (left.value == right.value); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FI16RGB555 left, FI16RGB555 right) + { + return (!(left == right)); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FI16RGB555(Color value) + { + return new FI16RGB555(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(FI16RGB555 value) + { + return value.Color; + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb( + ((value & FreeImage.FI16_555_RED_MASK) >> FreeImage.FI16_555_RED_SHIFT) * 255 / 31, + ((value & FreeImage.FI16_555_GREEN_MASK) >> FreeImage.FI16_555_GREEN_SHIFT) * 255 / 31, + ((value & FreeImage.FI16_555_BLUE_MASK) >> FreeImage.FI16_555_BLUE_SHIFT) * 255 / 31); + } + set + { + this.value = (ushort)( + (((value.R * 31) / 255) << FreeImage.FI16_555_RED_SHIFT) + + (((value.G * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT) + + (((value.B * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT)); + } + } + + /// + /// Gets or sets the red color component. + /// + public byte Red + { + get + { + return (byte)(((value & FreeImage.FI16_555_RED_MASK) >> FreeImage.FI16_555_RED_SHIFT) * 255 / 31); + } + set + { + this.value = (ushort)((this.value & (~FreeImage.FI16_555_RED_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_RED_SHIFT)); + } + } + + /// + /// Gets or sets the green color component. + /// + public byte Green + { + get + { + return (byte)(((value & FreeImage.FI16_555_GREEN_MASK) >> FreeImage.FI16_555_GREEN_SHIFT) * 255 / 31); + } + set + { + this.value = (ushort)((this.value & (~FreeImage.FI16_555_GREEN_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT)); + } + } + + /// + /// Gets or sets the blue color component. + /// + public byte Blue + { + get + { + return (byte)(((value & FreeImage.FI16_555_BLUE_MASK) >> FreeImage.FI16_555_BLUE_SHIFT) * 255 / 31); + } + set + { + this.value = (ushort)((this.value & (~FreeImage.FI16_555_BLUE_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT)); + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FI16RGB555)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FI16RGB555)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FI16RGB555 other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return base.Equals(obj); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FI16RGB555 other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FI16RGB565.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FI16RGB565.cs index 26e59c3..8c1ca59 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FI16RGB565.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FI16RGB565.cs @@ -1,277 +1,277 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.3 $ -// $Date: 2009/02/20 07:41:08 $ -// $Id: FI16RGB565.cs,v 1.3 2009/02/20 07:41:08 cklein05 Exp $ -// ========================================================== - -using System; -using System.Drawing; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The FI16RGB565 structure describes a color consisting of relative - /// intensities of red, green, blue and alpha value. Each single color - /// component consumes 5 bits and so, takes values in the range from 0 to 31. - /// - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the FI16RGB565 structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the FI16RGB565 structure and my be used in all situations which require - /// an FI16RGB565 type. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// FI16RGB565 structure and the structure. - /// - /// FI16RGB565 fi16rgb; - /// // Initialize the structure using a native .NET Color structure. - /// fi16rgb = new FI16RGB565(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// fi16rgb = Color.DarkSeaGreen; - /// // Convert the FI16RGB565 instance into a native .NET Color - /// // using its implicit operator. - /// Color color = fi16rgb; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = fi16rgb.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FI16RGB565 : IComparable, IComparable, IEquatable - { - /// - /// The value of the color. - /// - private ushort value; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public FI16RGB565(Color color) - { - value = (ushort)( - (((color.R * 31) / 255) << FreeImage.FI16_565_RED_SHIFT) + - (((color.G * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT) + - (((color.B * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT)); - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FI16RGB565 left, FI16RGB565 right) - { - return (left.value == right.value); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FI16RGB565 left, FI16RGB565 right) - { - return (!(left == right)); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FI16RGB565(Color value) - { - return new FI16RGB565(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(FI16RGB565 value) - { - return value.Color; - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb( - ((value & FreeImage.FI16_565_RED_MASK) >> FreeImage.FI16_565_RED_SHIFT) * 255 / 31, - ((value & FreeImage.FI16_565_GREEN_MASK) >> FreeImage.FI16_565_GREEN_SHIFT) * 255 / 63, - ((value & FreeImage.FI16_565_BLUE_MASK) >> FreeImage.FI16_565_BLUE_SHIFT) * 255 / 31); - } - set - { - this.value = (ushort)( - (((value.R * 31) / 255) << FreeImage.FI16_565_RED_SHIFT) + - (((value.G * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT) + - (((value.B * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT)); - } - } - - /// - /// Gets or sets the red color component. - /// - public byte Red - { - get - { - return (byte)(((value & FreeImage.FI16_565_RED_MASK) >> FreeImage.FI16_565_RED_SHIFT) * 255 / 31); - } - set - { - this.value = (ushort)((this.value & (~FreeImage.FI16_565_RED_MASK)) | (((value * 31) / 255) << FreeImage.FI16_565_RED_SHIFT)); - } - } - - /// - /// Gets or sets the green color component. - /// - public byte Green - { - get - { - return (byte)(((value & FreeImage.FI16_565_GREEN_MASK) >> FreeImage.FI16_565_GREEN_SHIFT) * 255 / 63); - } - set - { - this.value = (ushort)((this.value & (~FreeImage.FI16_565_GREEN_MASK)) | (((value * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT)); - } - } - - /// - /// Gets or sets the blue color component. - /// - public byte Blue - { - get - { - return (byte)(((value & FreeImage.FI16_565_BLUE_MASK) >> FreeImage.FI16_565_BLUE_SHIFT) * 255 / 31); - } - set - { - this.value = (ushort)((this.value & (~FreeImage.FI16_565_BLUE_MASK)) | (((value * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT)); - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FI16RGB565)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FI16RGB565)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FI16RGB565 other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return base.Equals(obj); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FI16RGB565 other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.3 $ +// $Date: 2009/02/20 07:41:08 $ +// $Id: FI16RGB565.cs,v 1.3 2009/02/20 07:41:08 cklein05 Exp $ +// ========================================================== + +using System; +using System.Drawing; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The FI16RGB565 structure describes a color consisting of relative + /// intensities of red, green, blue and alpha value. Each single color + /// component consumes 5 bits and so, takes values in the range from 0 to 31. + /// + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the FI16RGB565 structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the FI16RGB565 structure and my be used in all situations which require + /// an FI16RGB565 type. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// FI16RGB565 structure and the structure. + /// + /// FI16RGB565 fi16rgb; + /// // Initialize the structure using a native .NET Color structure. + /// fi16rgb = new FI16RGB565(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// fi16rgb = Color.DarkSeaGreen; + /// // Convert the FI16RGB565 instance into a native .NET Color + /// // using its implicit operator. + /// Color color = fi16rgb; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = fi16rgb.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FI16RGB565 : IComparable, IComparable, IEquatable + { + /// + /// The value of the color. + /// + private ushort value; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public FI16RGB565(Color color) + { + value = (ushort)( + (((color.R * 31) / 255) << FreeImage.FI16_565_RED_SHIFT) + + (((color.G * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT) + + (((color.B * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT)); + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FI16RGB565 left, FI16RGB565 right) + { + return (left.value == right.value); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FI16RGB565 left, FI16RGB565 right) + { + return (!(left == right)); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FI16RGB565(Color value) + { + return new FI16RGB565(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(FI16RGB565 value) + { + return value.Color; + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb( + ((value & FreeImage.FI16_565_RED_MASK) >> FreeImage.FI16_565_RED_SHIFT) * 255 / 31, + ((value & FreeImage.FI16_565_GREEN_MASK) >> FreeImage.FI16_565_GREEN_SHIFT) * 255 / 63, + ((value & FreeImage.FI16_565_BLUE_MASK) >> FreeImage.FI16_565_BLUE_SHIFT) * 255 / 31); + } + set + { + this.value = (ushort)( + (((value.R * 31) / 255) << FreeImage.FI16_565_RED_SHIFT) + + (((value.G * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT) + + (((value.B * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT)); + } + } + + /// + /// Gets or sets the red color component. + /// + public byte Red + { + get + { + return (byte)(((value & FreeImage.FI16_565_RED_MASK) >> FreeImage.FI16_565_RED_SHIFT) * 255 / 31); + } + set + { + this.value = (ushort)((this.value & (~FreeImage.FI16_565_RED_MASK)) | (((value * 31) / 255) << FreeImage.FI16_565_RED_SHIFT)); + } + } + + /// + /// Gets or sets the green color component. + /// + public byte Green + { + get + { + return (byte)(((value & FreeImage.FI16_565_GREEN_MASK) >> FreeImage.FI16_565_GREEN_SHIFT) * 255 / 63); + } + set + { + this.value = (ushort)((this.value & (~FreeImage.FI16_565_GREEN_MASK)) | (((value * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT)); + } + } + + /// + /// Gets or sets the blue color component. + /// + public byte Blue + { + get + { + return (byte)(((value & FreeImage.FI16_565_BLUE_MASK) >> FreeImage.FI16_565_BLUE_SHIFT) * 255 / 31); + } + set + { + this.value = (ushort)((this.value & (~FreeImage.FI16_565_BLUE_MASK)) | (((value * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT)); + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FI16RGB565)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FI16RGB565)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FI16RGB565 other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return base.Equals(obj); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FI16RGB565 other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FI1BIT.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FI1BIT.cs index 5712466..0ac49a3 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FI1BIT.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FI1BIT.cs @@ -1,70 +1,70 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Diagnostics; - -namespace FreeImageAPI -{ - /// - /// The FI1BIT structure represents a single bit. - /// It's value can be 0 or 1. - /// - [DebuggerDisplay("{value}"), - Serializable] - public struct FI1BIT - { - /// - /// Represents the largest possible value of . This field is constant. - /// - public const byte MaxValue = 0x01; - - /// - /// Represents the smallest possible value of . This field is constant. - /// - public const byte MinValue = 0x00; - - /// - /// The value of the structure. - /// - private byte value; - - /// - /// Initializes a new instance based on the specified value. - /// - /// The value to initialize with. - private FI1BIT(byte value) - { - this.value = (byte)(value & MaxValue); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator byte(FI1BIT value) - { - return value.value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FI1BIT(byte value) - { - return new FI1BIT(value); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return value.ToString(); - } - } -} +using System; +using System.Collections.Generic; +using System.Text; +using System.Diagnostics; + +namespace FreeImageAPI +{ + /// + /// The FI1BIT structure represents a single bit. + /// It's value can be 0 or 1. + /// + [DebuggerDisplay("{value}"), + Serializable] + public struct FI1BIT + { + /// + /// Represents the largest possible value of . This field is constant. + /// + public const byte MaxValue = 0x01; + + /// + /// Represents the smallest possible value of . This field is constant. + /// + public const byte MinValue = 0x00; + + /// + /// The value of the structure. + /// + private byte value; + + /// + /// Initializes a new instance based on the specified value. + /// + /// The value to initialize with. + private FI1BIT(byte value) + { + this.value = (byte)(value & MaxValue); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator byte(FI1BIT value) + { + return value.value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FI1BIT(byte value) + { + return new FI1BIT(value); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return value.ToString(); + } + } +} diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FI4BIT.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FI4BIT.cs index a047a80..0188c6d 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FI4BIT.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FI4BIT.cs @@ -1,70 +1,70 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Diagnostics; - -namespace FreeImageAPI -{ - /// - /// The FI4BIT structure represents the half of a . - /// It's valuerange is between 0 and 15. - /// - [DebuggerDisplay("{value}"), - Serializable] - public struct FI4BIT - { - /// - /// Represents the largest possible value of . This field is constant. - /// - public const byte MaxValue = 0x0F; - - /// - /// Represents the smallest possible value of . This field is constant. - /// - public const byte MinValue = 0x00; - - /// - /// The value of the structure. - /// - private byte value; - - /// - /// Initializes a new instance based on the specified value. - /// - /// The value to initialize with. - private FI4BIT(byte value) - { - this.value = (byte)(value & MaxValue); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator byte(FI4BIT value) - { - return value.value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FI4BIT(byte value) - { - return new FI4BIT(value); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return value.ToString(); - } - } +using System; +using System.Collections.Generic; +using System.Text; +using System.Diagnostics; + +namespace FreeImageAPI +{ + /// + /// The FI4BIT structure represents the half of a . + /// It's valuerange is between 0 and 15. + /// + [DebuggerDisplay("{value}"), + Serializable] + public struct FI4BIT + { + /// + /// Represents the largest possible value of . This field is constant. + /// + public const byte MaxValue = 0x0F; + + /// + /// Represents the smallest possible value of . This field is constant. + /// + public const byte MinValue = 0x00; + + /// + /// The value of the structure. + /// + private byte value; + + /// + /// Initializes a new instance based on the specified value. + /// + /// The value to initialize with. + private FI4BIT(byte value) + { + this.value = (byte)(value & MaxValue); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator byte(FI4BIT value) + { + return value.value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FI4BIT(byte value) + { + return new FI4BIT(value); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return value.ToString(); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FIBITMAP.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FIBITMAP.cs index 4403817..d12a586 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FIBITMAP.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FIBITMAP.cs @@ -1,175 +1,175 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.5 $ -// $Date: 2009/02/20 07:41:08 $ -// $Id: FIBITMAP.cs,v 1.5 2009/02/20 07:41:08 cklein05 Exp $ -// ========================================================== - -using System; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The FIBITMAP structure is a handle to a FreeImage bimtap. - /// - /// - /// The handle represented by a FIBITBAP structure provides - /// access to either a singlepage bitmap or exactly one page of - /// a multipage bitmap. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIBITMAP : IComparable, IComparable, IEquatable - { - private IntPtr data; - - /// - /// A read-only field that represents a handle that has been initialized to zero. - /// - public static readonly FIBITMAP Zero; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIBITMAP left, FIBITMAP right) - { - return (left.data == right.data); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIBITMAP left, FIBITMAP right) - { - return (left.data != right.data); - } - - /// - /// Gets whether the handle is a null or not. - /// - /// true if this handle is a null; - /// otherwise, false. - public bool IsNull - { - get - { - return (data == IntPtr.Zero); - } - } - - /// - /// Sets the handle to null. - /// - public void SetNull() - { - data = IntPtr.Zero; - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return data.ToString(); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return data.GetHashCode(); - } - - /// - /// Determines whether the specified is equal to the current . - /// - /// The to compare with the current . - /// true if the specified is equal to the current ; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIBITMAP) && (this == ((FIBITMAP)obj))); - } - - /// - /// Indicates whether the current object is equal to another object of the same type. - /// - /// An object to compare with this object. - /// true if the current object is equal to the other parameter; otherwise, false. - public bool Equals(FIBITMAP other) - { - return (this == other); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIBITMAP)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIBITMAP)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIBITMAP other) - { - return this.data.ToInt64().CompareTo(other.data.ToInt64()); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.5 $ +// $Date: 2009/02/20 07:41:08 $ +// $Id: FIBITMAP.cs,v 1.5 2009/02/20 07:41:08 cklein05 Exp $ +// ========================================================== + +using System; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The FIBITMAP structure is a handle to a FreeImage bimtap. + /// + /// + /// The handle represented by a FIBITBAP structure provides + /// access to either a singlepage bitmap or exactly one page of + /// a multipage bitmap. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIBITMAP : IComparable, IComparable, IEquatable + { + private IntPtr data; + + /// + /// A read-only field that represents a handle that has been initialized to zero. + /// + public static readonly FIBITMAP Zero; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIBITMAP left, FIBITMAP right) + { + return (left.data == right.data); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIBITMAP left, FIBITMAP right) + { + return (left.data != right.data); + } + + /// + /// Gets whether the handle is a null or not. + /// + /// true if this handle is a null; + /// otherwise, false. + public bool IsNull + { + get + { + return (data == IntPtr.Zero); + } + } + + /// + /// Sets the handle to null. + /// + public void SetNull() + { + data = IntPtr.Zero; + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return data.ToString(); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return data.GetHashCode(); + } + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current ; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIBITMAP) && (this == ((FIBITMAP)obj))); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// An object to compare with this object. + /// true if the current object is equal to the other parameter; otherwise, false. + public bool Equals(FIBITMAP other) + { + return (this == other); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIBITMAP)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIBITMAP)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIBITMAP other) + { + return this.data.ToInt64().CompareTo(other.data.ToInt64()); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FICOMPLEX.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FICOMPLEX.cs index c3ea716..39e97fe 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FICOMPLEX.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FICOMPLEX.cs @@ -1,146 +1,146 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.4 $ -// $Date: 2009/02/20 07:41:08 $ -// $Id: FICOMPLEX.cs,v 1.4 2009/02/20 07:41:08 cklein05 Exp $ -// ========================================================== - -using System; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The FICOMPLEX structure describes a color consisting of a real and an imaginary part. - /// Each part is using 4 bytes of data. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FICOMPLEX : IComparable, IComparable, IEquatable - { - /// - /// Real part of the color. - /// - public double real; - - /// - /// Imaginary part of the color. - /// - public double imag; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FICOMPLEX left, FICOMPLEX right) - { - return ((left.real == right.real) && (left.imag == right.imag)); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FICOMPLEX left, FICOMPLEX right) - { - return ((left.real != right.real) || (left.imag == right.imag)); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FICOMPLEX)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FICOMPLEX)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FICOMPLEX other) - { - return base.GetHashCode(); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FICOMPLEX) && (this == ((FICOMPLEX)obj))); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FICOMPLEX other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.4 $ +// $Date: 2009/02/20 07:41:08 $ +// $Id: FICOMPLEX.cs,v 1.4 2009/02/20 07:41:08 cklein05 Exp $ +// ========================================================== + +using System; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The FICOMPLEX structure describes a color consisting of a real and an imaginary part. + /// Each part is using 4 bytes of data. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FICOMPLEX : IComparable, IComparable, IEquatable + { + /// + /// Real part of the color. + /// + public double real; + + /// + /// Imaginary part of the color. + /// + public double imag; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FICOMPLEX left, FICOMPLEX right) + { + return ((left.real == right.real) && (left.imag == right.imag)); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FICOMPLEX left, FICOMPLEX right) + { + return ((left.real != right.real) || (left.imag == right.imag)); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FICOMPLEX)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FICOMPLEX)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FICOMPLEX other) + { + return base.GetHashCode(); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FICOMPLEX) && (this == ((FICOMPLEX)obj))); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FICOMPLEX other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FIICCPROFILE.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FIICCPROFILE.cs index 04f6b64..6afdf76 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FIICCPROFILE.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FIICCPROFILE.cs @@ -1,133 +1,133 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.5 $ -// $Date: 2008/11/05 13:19:06 $ -// $Id: FIICCPROFILE.cs,v 1.5 2008/11/05 13:19:06 cklein05 Exp $ -// ========================================================== - -using System; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// This Structure contains ICC-Profile data. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIICCPROFILE - { - private ICC_FLAGS flags; - private uint size; - private IntPtr data; - - /// - /// Creates a new ICC-Profile for . - /// - /// Handle to a FreeImage bitmap. - /// The ICC-Profile data. - /// - /// is null. - public FIICCPROFILE(FIBITMAP dib, byte[] data) - : this(dib, data, (int)data.Length) - { - } - - /// - /// Creates a new ICC-Profile for . - /// - /// Handle to a FreeImage bitmap. - /// The ICC-Profile data. - /// Number of bytes to use from data. - /// - /// is null. - public unsafe FIICCPROFILE(FIBITMAP dib, byte[] data, int size) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - FIICCPROFILE prof; - size = Math.Min(size, (int)data.Length); - prof = *(FIICCPROFILE*)FreeImage.CreateICCProfile(dib, data, size); - this.flags = prof.flags; - this.size = prof.size; - this.data = prof.data; - } - - /// - /// Info flag of the profile. - /// - public ICC_FLAGS Flags - { - get { return flags; } - } - - /// - /// Profile's size measured in bytes. - /// - public uint Size - { - get { return size; } - } - - /// - /// Points to a block of contiguous memory containing the profile. - /// - public IntPtr DataPointer - { - get { return data; } - } - - /// - /// Copy of the ICC-Profiles data. - /// - public unsafe byte[] Data - { - get - { - byte[] result; - FreeImage.CopyMemory(result = new byte[size], data.ToPointer(), size); - return result; - } - } - - /// - /// Indicates whether the profile is CMYK. - /// - public bool IsCMYK - { - get - { - return ((flags & ICC_FLAGS.FIICC_COLOR_IS_CMYK) != 0); - } - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.5 $ +// $Date: 2008/11/05 13:19:06 $ +// $Id: FIICCPROFILE.cs,v 1.5 2008/11/05 13:19:06 cklein05 Exp $ +// ========================================================== + +using System; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// This Structure contains ICC-Profile data. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIICCPROFILE + { + private ICC_FLAGS flags; + private uint size; + private IntPtr data; + + /// + /// Creates a new ICC-Profile for . + /// + /// Handle to a FreeImage bitmap. + /// The ICC-Profile data. + /// + /// is null. + public FIICCPROFILE(FIBITMAP dib, byte[] data) + : this(dib, data, (int)data.Length) + { + } + + /// + /// Creates a new ICC-Profile for . + /// + /// Handle to a FreeImage bitmap. + /// The ICC-Profile data. + /// Number of bytes to use from data. + /// + /// is null. + public unsafe FIICCPROFILE(FIBITMAP dib, byte[] data, int size) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + FIICCPROFILE prof; + size = Math.Min(size, (int)data.Length); + prof = *(FIICCPROFILE*)FreeImage.CreateICCProfile(dib, data, size); + this.flags = prof.flags; + this.size = prof.size; + this.data = prof.data; + } + + /// + /// Info flag of the profile. + /// + public ICC_FLAGS Flags + { + get { return flags; } + } + + /// + /// Profile's size measured in bytes. + /// + public uint Size + { + get { return size; } + } + + /// + /// Points to a block of contiguous memory containing the profile. + /// + public IntPtr DataPointer + { + get { return data; } + } + + /// + /// Copy of the ICC-Profiles data. + /// + public unsafe byte[] Data + { + get + { + byte[] result; + FreeImage.CopyMemory(result = new byte[size], data.ToPointer(), size); + return result; + } + } + + /// + /// Indicates whether the profile is CMYK. + /// + public bool IsCMYK + { + get + { + return ((flags & ICC_FLAGS.FIICC_COLOR_IS_CMYK) != 0); + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FIMEMORY.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FIMEMORY.cs index e190975..89a3015 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FIMEMORY.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FIMEMORY.cs @@ -1,170 +1,170 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.5 $ -// $Date: 2009/02/20 07:41:08 $ -// $Id: FIMEMORY.cs,v 1.5 2009/02/20 07:41:08 cklein05 Exp $ -// ========================================================== - -using System; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The FIMEMORY structure is a handle to an opened memory stream. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIMEMORY : IComparable, IComparable, IEquatable - { - private IntPtr data; - - /// - /// A read-only field that represents a handle that has been initialized to zero. - /// - public static readonly FIMEMORY Zero; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIMEMORY left, FIMEMORY right) - { - return (left.data == right.data); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIMEMORY left, FIMEMORY right) - { - return (left.data != right.data); - } - - /// - /// Gets whether the pointer is a null pointer or not. - /// - /// true if this is a null pointer; - /// otherwise, false. - public bool IsNull - { - get - { - return (data == IntPtr.Zero); - } - } - - /// - /// Sets the handle to null. - /// - public void SetNull() - { - data = IntPtr.Zero; - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return data.ToString(); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return data.GetHashCode(); - } - - /// - /// Determines whether the specified is equal to the current . - /// - /// The to compare with the current . - /// true if the specified is equal to the current ; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIMEMORY) && (this == ((FIMEMORY)obj))); - } - - /// - /// Indicates whether the current object is equal to another object of the same type. - /// - /// An object to compare with this object. - /// true if the current object is equal to the other parameter; otherwise, false. - public bool Equals(FIMEMORY other) - { - return (this == other); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIMEMORY)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIMEMORY)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIMEMORY other) - { - return this.data.ToInt64().CompareTo(other.data.ToInt64()); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.5 $ +// $Date: 2009/02/20 07:41:08 $ +// $Id: FIMEMORY.cs,v 1.5 2009/02/20 07:41:08 cklein05 Exp $ +// ========================================================== + +using System; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The FIMEMORY structure is a handle to an opened memory stream. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIMEMORY : IComparable, IComparable, IEquatable + { + private IntPtr data; + + /// + /// A read-only field that represents a handle that has been initialized to zero. + /// + public static readonly FIMEMORY Zero; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIMEMORY left, FIMEMORY right) + { + return (left.data == right.data); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIMEMORY left, FIMEMORY right) + { + return (left.data != right.data); + } + + /// + /// Gets whether the pointer is a null pointer or not. + /// + /// true if this is a null pointer; + /// otherwise, false. + public bool IsNull + { + get + { + return (data == IntPtr.Zero); + } + } + + /// + /// Sets the handle to null. + /// + public void SetNull() + { + data = IntPtr.Zero; + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return data.ToString(); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return data.GetHashCode(); + } + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current ; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIMEMORY) && (this == ((FIMEMORY)obj))); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// An object to compare with this object. + /// true if the current object is equal to the other parameter; otherwise, false. + public bool Equals(FIMEMORY other) + { + return (this == other); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIMEMORY)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIMEMORY)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIMEMORY other) + { + return this.data.ToInt64().CompareTo(other.data.ToInt64()); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FIMETADATA.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FIMETADATA.cs index 0fee77e..de1ea66 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FIMETADATA.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FIMETADATA.cs @@ -1,178 +1,178 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.5 $ -// $Date: 2009/02/20 07:41:08 $ -// $Id: FIMETADATA.cs,v 1.5 2009/02/20 07:41:08 cklein05 Exp $ -// ========================================================== - -using System; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The FIMETADATA structure is an unique search handle for metadata search operations. - /// - /// - /// The FIMETADATA structure is usually returned by the - /// - /// function and then used on subsequent calls to - /// . - /// When the FIMETADATA handle is no longer used, it needs to be freed by the - /// function. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIMETADATA : IComparable, IComparable, IEquatable - { - private IntPtr data; - - /// - /// A read-only field that represents a handle that has been initialized to zero. - /// - public static readonly FIMETADATA Zero; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIMETADATA left, FIMETADATA right) - { - return (left.data == right.data); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIMETADATA left, FIMETADATA right) - { - return (left.data != right.data); - } - - /// - /// Gets whether the pointer is a null pointer or not. - /// - /// true if this is a null pointer; - /// otherwise, false. - public bool IsNull - { - get - { - return (data == IntPtr.Zero); - } - } - - /// - /// Sets the handle to null. - /// - public void SetNull() - { - data = IntPtr.Zero; - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return data.ToString(); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return data.GetHashCode(); - } - - /// - /// Determines whether the specified is equal to the current . - /// - /// The to compare with the current . - /// true if the specified is equal to the current ; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIMETADATA) && (this == ((FIMETADATA)obj))); - } - - /// - /// Indicates whether the current object is equal to another object of the same type. - /// - /// An object to compare with this object. - /// true if the current object is equal to the other parameter; otherwise, false. - public bool Equals(FIMETADATA other) - { - return (this == other); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIMETADATA)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIMETADATA)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIMETADATA other) - { - return this.data.ToInt64().CompareTo(other.data.ToInt64()); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.5 $ +// $Date: 2009/02/20 07:41:08 $ +// $Id: FIMETADATA.cs,v 1.5 2009/02/20 07:41:08 cklein05 Exp $ +// ========================================================== + +using System; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The FIMETADATA structure is an unique search handle for metadata search operations. + /// + /// + /// The FIMETADATA structure is usually returned by the + /// + /// function and then used on subsequent calls to + /// . + /// When the FIMETADATA handle is no longer used, it needs to be freed by the + /// function. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIMETADATA : IComparable, IComparable, IEquatable + { + private IntPtr data; + + /// + /// A read-only field that represents a handle that has been initialized to zero. + /// + public static readonly FIMETADATA Zero; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIMETADATA left, FIMETADATA right) + { + return (left.data == right.data); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIMETADATA left, FIMETADATA right) + { + return (left.data != right.data); + } + + /// + /// Gets whether the pointer is a null pointer or not. + /// + /// true if this is a null pointer; + /// otherwise, false. + public bool IsNull + { + get + { + return (data == IntPtr.Zero); + } + } + + /// + /// Sets the handle to null. + /// + public void SetNull() + { + data = IntPtr.Zero; + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return data.ToString(); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return data.GetHashCode(); + } + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current ; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIMETADATA) && (this == ((FIMETADATA)obj))); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// An object to compare with this object. + /// true if the current object is equal to the other parameter; otherwise, false. + public bool Equals(FIMETADATA other) + { + return (this == other); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIMETADATA)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIMETADATA)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIMETADATA other) + { + return this.data.ToInt64().CompareTo(other.data.ToInt64()); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FIMULTIBITMAP.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FIMULTIBITMAP.cs index 931b911..896a067 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FIMULTIBITMAP.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FIMULTIBITMAP.cs @@ -1,170 +1,170 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.5 $ -// $Date: 2009/02/20 07:41:08 $ -// $Id: FIMULTIBITMAP.cs,v 1.5 2009/02/20 07:41:08 cklein05 Exp $ -// ========================================================== - -using System; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The FIMULTIBITMAP structure is a handle to a FreeImage multipaged bimtap. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIMULTIBITMAP : IComparable, IComparable, IEquatable - { - private IntPtr data; - - /// - /// A read-only field that represents a handle that has been initialized to zero. - /// - public static readonly FIMULTIBITMAP Zero; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIMULTIBITMAP left, FIMULTIBITMAP right) - { - return (left.data == right.data); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIMULTIBITMAP left, FIMULTIBITMAP right) - { - return (left.data != right.data); - } - - /// - /// Gets whether the handle is a null or not. - /// - /// true if this handle is a null; - /// otherwise, false. - public bool IsNull - { - get - { - return (data == IntPtr.Zero); - } - } - - /// - /// Sets the handle to null. - /// - public void SetNull() - { - data = IntPtr.Zero; - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return data.ToString(); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return data.GetHashCode(); - } - - /// - /// Determines whether the specified is equal to the current . - /// - /// The to compare with the current . - /// true if the specified is equal to the current ; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIMULTIBITMAP) && (this == ((FIMULTIBITMAP)obj))); - } - - /// - /// Indicates whether the current object is equal to another object of the same type. - /// - /// An object to compare with this object. - /// true if the current object is equal to the other parameter; otherwise, false. - public bool Equals(FIMULTIBITMAP other) - { - return (this == other); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIMULTIBITMAP)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIMULTIBITMAP)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIMULTIBITMAP other) - { - return this.data.ToInt64().CompareTo(other.data.ToInt64()); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.5 $ +// $Date: 2009/02/20 07:41:08 $ +// $Id: FIMULTIBITMAP.cs,v 1.5 2009/02/20 07:41:08 cklein05 Exp $ +// ========================================================== + +using System; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The FIMULTIBITMAP structure is a handle to a FreeImage multipaged bimtap. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIMULTIBITMAP : IComparable, IComparable, IEquatable + { + private IntPtr data; + + /// + /// A read-only field that represents a handle that has been initialized to zero. + /// + public static readonly FIMULTIBITMAP Zero; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIMULTIBITMAP left, FIMULTIBITMAP right) + { + return (left.data == right.data); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIMULTIBITMAP left, FIMULTIBITMAP right) + { + return (left.data != right.data); + } + + /// + /// Gets whether the handle is a null or not. + /// + /// true if this handle is a null; + /// otherwise, false. + public bool IsNull + { + get + { + return (data == IntPtr.Zero); + } + } + + /// + /// Sets the handle to null. + /// + public void SetNull() + { + data = IntPtr.Zero; + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return data.ToString(); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return data.GetHashCode(); + } + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current ; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIMULTIBITMAP) && (this == ((FIMULTIBITMAP)obj))); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// An object to compare with this object. + /// true if the current object is equal to the other parameter; otherwise, false. + public bool Equals(FIMULTIBITMAP other) + { + return (this == other); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIMULTIBITMAP)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIMULTIBITMAP)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIMULTIBITMAP other) + { + return this.data.ToInt64().CompareTo(other.data.ToInt64()); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGB16.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGB16.cs index fbdf816..58e8aa9 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGB16.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGB16.cs @@ -1,267 +1,267 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.3 $ -// $Date: 2009/02/20 07:41:08 $ -// $Id: FIRGB16.cs,v 1.3 2009/02/20 07:41:08 cklein05 Exp $ -// ========================================================== - -using System; -using System.Drawing; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The FIRGB16 structure describes a color consisting of relative - /// intensities of red, green, blue and alpha value. Each single color - /// component consumes 16 bits and so, takes values in the range from 0 to 65535. - /// - /// - /// - /// The FIRGB16 structure provides access to an underlying FreeImage FIRGB16 - /// structure. To determine the red, green or blue component of a color, - /// use the red, green or blue fields, respectively. - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the FIRGB16 structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the FIRGB16 structure and my be used in all situations which require - /// an FIRGB16 type. - /// - /// - /// Each color component red, green or blue of FIRGB16 is translated into - /// it's corresponding color component R, G or B of - /// by right shifting 8 bits and shifting left 8 bits for the reverse conversion. - /// When converting from into FIRGB16, the - /// color's alpha value is ignored and assumed to be 255 when converting from - /// FIRGB16 into , creating a fully - /// opaque color. - /// - /// - /// Conversion from System.Drawing.Color to FIRGB16 - /// - /// FIRGB16.component = Color.component << 8 - /// - /// Conversion from FIRGB16 to System.Drawing.Color - /// - /// Color.component = FIRGB16.component >> 8 - /// - /// The same conversion is also applied when the - /// property or the constructor - /// is invoked. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// FIRGB16 structure and the structure. - /// - /// FIRGB16 firgb16; - /// // Initialize the structure using a native .NET Color structure. - /// firgb16 = new FIRGBA16(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// firgb16 = Color.DarkSeaGreen; - /// // Convert the FIRGB16 instance into a native .NET Color - /// // using its implicit operator. - /// Color color = firgb16; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = firgb16.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIRGB16 : IComparable, IComparable, IEquatable - { - /// - /// The red color component. - /// - public ushort red; - - /// - /// The green color component. - /// - public ushort green; - - /// - /// The blue color component. - /// - public ushort blue; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public FIRGB16(Color color) - { - red = (ushort)(color.R << 8); - green = (ushort)(color.G << 8); - blue = (ushort)(color.B << 8); - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIRGB16 left, FIRGB16 right) - { - return - ((left.blue == right.blue) && - (left.green == right.green) && - (left.red == right.red)); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIRGB16 left, FIRGB16 right) - { - return !(left == right); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIRGB16(Color value) - { - return new FIRGB16(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(FIRGB16 value) - { - return value.Color; - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb((red >> 8), (green >> 8), (blue >> 8)); - } - set - { - red = (ushort)(value.R << 8); - green = (ushort)(value.G << 8); - blue = (ushort)(value.B << 8); - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIRGB16)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIRGB16)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIRGB16 other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIRGB16) && (this == ((FIRGB16)obj))); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FIRGB16 other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.3 $ +// $Date: 2009/02/20 07:41:08 $ +// $Id: FIRGB16.cs,v 1.3 2009/02/20 07:41:08 cklein05 Exp $ +// ========================================================== + +using System; +using System.Drawing; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The FIRGB16 structure describes a color consisting of relative + /// intensities of red, green, blue and alpha value. Each single color + /// component consumes 16 bits and so, takes values in the range from 0 to 65535. + /// + /// + /// + /// The FIRGB16 structure provides access to an underlying FreeImage FIRGB16 + /// structure. To determine the red, green or blue component of a color, + /// use the red, green or blue fields, respectively. + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the FIRGB16 structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the FIRGB16 structure and my be used in all situations which require + /// an FIRGB16 type. + /// + /// + /// Each color component red, green or blue of FIRGB16 is translated into + /// it's corresponding color component R, G or B of + /// by right shifting 8 bits and shifting left 8 bits for the reverse conversion. + /// When converting from into FIRGB16, the + /// color's alpha value is ignored and assumed to be 255 when converting from + /// FIRGB16 into , creating a fully + /// opaque color. + /// + /// + /// Conversion from System.Drawing.Color to FIRGB16 + /// + /// FIRGB16.component = Color.component << 8 + /// + /// Conversion from FIRGB16 to System.Drawing.Color + /// + /// Color.component = FIRGB16.component >> 8 + /// + /// The same conversion is also applied when the + /// property or the constructor + /// is invoked. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// FIRGB16 structure and the structure. + /// + /// FIRGB16 firgb16; + /// // Initialize the structure using a native .NET Color structure. + /// firgb16 = new FIRGBA16(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// firgb16 = Color.DarkSeaGreen; + /// // Convert the FIRGB16 instance into a native .NET Color + /// // using its implicit operator. + /// Color color = firgb16; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = firgb16.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIRGB16 : IComparable, IComparable, IEquatable + { + /// + /// The red color component. + /// + public ushort red; + + /// + /// The green color component. + /// + public ushort green; + + /// + /// The blue color component. + /// + public ushort blue; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public FIRGB16(Color color) + { + red = (ushort)(color.R << 8); + green = (ushort)(color.G << 8); + blue = (ushort)(color.B << 8); + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIRGB16 left, FIRGB16 right) + { + return + ((left.blue == right.blue) && + (left.green == right.green) && + (left.red == right.red)); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIRGB16 left, FIRGB16 right) + { + return !(left == right); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIRGB16(Color value) + { + return new FIRGB16(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(FIRGB16 value) + { + return value.Color; + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb((red >> 8), (green >> 8), (blue >> 8)); + } + set + { + red = (ushort)(value.R << 8); + green = (ushort)(value.G << 8); + blue = (ushort)(value.B << 8); + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIRGB16)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIRGB16)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIRGB16 other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIRGB16) && (this == ((FIRGB16)obj))); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FIRGB16 other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGBA16.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGBA16.cs index d63698d..5f0b3d8 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGBA16.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGBA16.cs @@ -1,271 +1,271 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.3 $ -// $Date: 2009/02/20 07:41:08 $ -// $Id: FIRGBA16.cs,v 1.3 2009/02/20 07:41:08 cklein05 Exp $ -// ========================================================== - -using System; -using System.Drawing; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The FIRGBA16 structure describes a color consisting of relative - /// intensities of red, green, blue and alpha value. Each single color - /// component consumes 16 bits and so, takes values in the range from 0 to 65535. - /// - /// - /// - /// The FIRGBA16 structure provides access to an underlying FreeImage FIRGBA16 - /// structure. To determine the alpha, red, green or blue component of a color, - /// use the alpha, red, green or blue fields, respectively. - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the FIRGBA16 structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the FIRGBA16 structure and my be used in all situations which require - /// an FIRGBA16 type. - /// - /// - /// Each color component alpha, red, green or blue of FIRGBA16 - /// is translated into it's corresponding color component A, R, G or B of - /// by an 8 bit right shift and vice versa. - /// - /// - /// Conversion from System.Drawing.Color to FIRGBA16 - /// - /// FIRGBA16.component = Color.component << 8 - /// - /// Conversion from FIRGBA16 to System.Drawing.Color - /// - /// Color.component = FIRGBA16.component >> 8 - /// - /// The same conversion is also applied when the - /// property or the constructor - /// is invoked. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// FIRGBA16 structure and the structure. - /// - /// FIRGBA16 firgba16; - /// // Initialize the structure using a native .NET Color structure. - /// firgba16 = new FIRGBA16(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// firgba16 = Color.DarkSeaGreen; - /// // Convert the FIRGBA16 instance into a native .NET Color - /// // using its implicit operator. - /// Color color = firgba16; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = firgba16.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIRGBA16 : IComparable, IComparable, IEquatable - { - /// - /// The red color component. - /// - public ushort red; - - /// - /// The green color component. - /// - public ushort green; - - /// - /// The blue color component. - /// - public ushort blue; - - /// - /// The alpha color component. - /// - public ushort alpha; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public FIRGBA16(Color color) - { - red = (ushort)(color.R << 8); - green = (ushort)(color.G << 8); - blue = (ushort)(color.B << 8); - alpha = (ushort)(color.A << 8); - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIRGBA16 left, FIRGBA16 right) - { - return - ((left.alpha == right.alpha) && - (left.blue == right.blue) && - (left.green == right.green) && - (left.red == right.red)); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIRGBA16 left, FIRGBA16 right) - { - return !(left == right); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIRGBA16(Color value) - { - return new FIRGBA16(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(FIRGBA16 value) - { - return value.Color; - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb((alpha >> 8), (red >> 8), (green >> 8), (blue >> 8)); - } - set - { - red = (ushort)(value.R << 8); - green = (ushort)(value.G << 8); - blue = (ushort)(value.B << 8); - alpha = (ushort)(value.A << 8); - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIRGBA16)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIRGBA16)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIRGBA16 other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIRGBA16) && (this == ((FIRGBA16)obj))); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FIRGBA16 other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.3 $ +// $Date: 2009/02/20 07:41:08 $ +// $Id: FIRGBA16.cs,v 1.3 2009/02/20 07:41:08 cklein05 Exp $ +// ========================================================== + +using System; +using System.Drawing; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The FIRGBA16 structure describes a color consisting of relative + /// intensities of red, green, blue and alpha value. Each single color + /// component consumes 16 bits and so, takes values in the range from 0 to 65535. + /// + /// + /// + /// The FIRGBA16 structure provides access to an underlying FreeImage FIRGBA16 + /// structure. To determine the alpha, red, green or blue component of a color, + /// use the alpha, red, green or blue fields, respectively. + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the FIRGBA16 structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the FIRGBA16 structure and my be used in all situations which require + /// an FIRGBA16 type. + /// + /// + /// Each color component alpha, red, green or blue of FIRGBA16 + /// is translated into it's corresponding color component A, R, G or B of + /// by an 8 bit right shift and vice versa. + /// + /// + /// Conversion from System.Drawing.Color to FIRGBA16 + /// + /// FIRGBA16.component = Color.component << 8 + /// + /// Conversion from FIRGBA16 to System.Drawing.Color + /// + /// Color.component = FIRGBA16.component >> 8 + /// + /// The same conversion is also applied when the + /// property or the constructor + /// is invoked. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// FIRGBA16 structure and the structure. + /// + /// FIRGBA16 firgba16; + /// // Initialize the structure using a native .NET Color structure. + /// firgba16 = new FIRGBA16(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// firgba16 = Color.DarkSeaGreen; + /// // Convert the FIRGBA16 instance into a native .NET Color + /// // using its implicit operator. + /// Color color = firgba16; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = firgba16.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIRGBA16 : IComparable, IComparable, IEquatable + { + /// + /// The red color component. + /// + public ushort red; + + /// + /// The green color component. + /// + public ushort green; + + /// + /// The blue color component. + /// + public ushort blue; + + /// + /// The alpha color component. + /// + public ushort alpha; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public FIRGBA16(Color color) + { + red = (ushort)(color.R << 8); + green = (ushort)(color.G << 8); + blue = (ushort)(color.B << 8); + alpha = (ushort)(color.A << 8); + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIRGBA16 left, FIRGBA16 right) + { + return + ((left.alpha == right.alpha) && + (left.blue == right.blue) && + (left.green == right.green) && + (left.red == right.red)); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIRGBA16 left, FIRGBA16 right) + { + return !(left == right); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIRGBA16(Color value) + { + return new FIRGBA16(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(FIRGBA16 value) + { + return value.Color; + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb((alpha >> 8), (red >> 8), (green >> 8), (blue >> 8)); + } + set + { + red = (ushort)(value.R << 8); + green = (ushort)(value.G << 8); + blue = (ushort)(value.B << 8); + alpha = (ushort)(value.A << 8); + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIRGBA16)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIRGBA16)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIRGBA16 other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIRGBA16) && (this == ((FIRGBA16)obj))); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FIRGBA16 other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGBAF.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGBAF.cs index aa515a0..b79bad9 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGBAF.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGBAF.cs @@ -1,276 +1,276 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.3 $ -// $Date: 2009/02/20 07:41:08 $ -// $Id: FIRGBAF.cs,v 1.3 2009/02/20 07:41:08 cklein05 Exp $ -// ========================================================== - -using System; -using System.Drawing; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The FIRGBAF structure describes a color consisting of relative - /// intensities of red, green, blue and alpha value. Each single color - /// component consumes 32 bits and takes values in the range from 0 to 1. - /// - /// - /// - /// The FIRGBAF structure provides access to an underlying FreeImage FIRGBAF - /// structure. To determine the alpha, red, green or blue component of a color, - /// use the alpha, red, green or blue fields, respectively. - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the FIRGBAF structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the FIRGBAF structure and my be used in all situations which require - /// an FIRGBAF type. - /// - /// - /// Each color component alpha, red, green or blue of FIRGBAF is translated - /// into it's corresponding color component A, R, G or B of - /// by linearly mapping the values of one range - /// into the other range and vice versa. - /// - /// - /// Conversion from System.Drawing.Color to FIRGBAF - /// - /// FIRGBAF.component = (float)Color.component / 255f - /// - /// Conversion from FIRGBAF to System.Drawing.Color - /// - /// Color.component = (int)(FIRGBAF.component * 255f) - /// - /// The same conversion is also applied when the - /// property or the constructor - /// is invoked. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// FIRGBAF structure and the structure. - /// - /// FIRGBAF firgbaf; - /// // Initialize the structure using a native .NET Color structure. - /// firgbaf = new FIRGBAF(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// firgbaf = Color.DarkSeaGreen; - /// // Convert the FIRGBAF instance into a native .NET Color - /// // using its implicit operator. - /// Color color = firgbaf; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = firgbaf.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIRGBAF : IComparable, IComparable, IEquatable - { - /// - /// The red color component. - /// - public float red; - - /// - /// The green color component. - /// - public float green; - - /// - /// The blue color component. - /// - public float blue; - - /// - /// The alpha color component. - /// - public float alpha; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public FIRGBAF(Color color) - { - red = (float)color.R / 255f; - green = (float)color.G / 255f; - blue = (float)color.B / 255f; - alpha = (float)color.A / 255f; - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIRGBAF left, FIRGBAF right) - { - return - ((left.alpha == right.alpha) && - (left.blue == right.blue) && - (left.green == right.green) && - (left.red == right.red)); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIRGBAF left, FIRGBAF right) - { - return !(left == right); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIRGBAF(Color value) - { - return new FIRGBAF(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(FIRGBAF value) - { - return value.Color; - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb( - (int)(alpha * 255f), - (int)(red * 255f), - (int)(green * 255f), - (int)(blue * 255f)); - } - set - { - red = (float)value.R / 255f; - green = (float)value.G / 255f; - blue = (float)value.B / 255f; - alpha = (float)value.A / 255f; - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIRGBAF)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIRGBAF)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIRGBAF other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIRGBAF) && (this == ((FIRGBAF)obj))); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FIRGBAF other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.3 $ +// $Date: 2009/02/20 07:41:08 $ +// $Id: FIRGBAF.cs,v 1.3 2009/02/20 07:41:08 cklein05 Exp $ +// ========================================================== + +using System; +using System.Drawing; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The FIRGBAF structure describes a color consisting of relative + /// intensities of red, green, blue and alpha value. Each single color + /// component consumes 32 bits and takes values in the range from 0 to 1. + /// + /// + /// + /// The FIRGBAF structure provides access to an underlying FreeImage FIRGBAF + /// structure. To determine the alpha, red, green or blue component of a color, + /// use the alpha, red, green or blue fields, respectively. + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the FIRGBAF structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the FIRGBAF structure and my be used in all situations which require + /// an FIRGBAF type. + /// + /// + /// Each color component alpha, red, green or blue of FIRGBAF is translated + /// into it's corresponding color component A, R, G or B of + /// by linearly mapping the values of one range + /// into the other range and vice versa. + /// + /// + /// Conversion from System.Drawing.Color to FIRGBAF + /// + /// FIRGBAF.component = (float)Color.component / 255f + /// + /// Conversion from FIRGBAF to System.Drawing.Color + /// + /// Color.component = (int)(FIRGBAF.component * 255f) + /// + /// The same conversion is also applied when the + /// property or the constructor + /// is invoked. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// FIRGBAF structure and the structure. + /// + /// FIRGBAF firgbaf; + /// // Initialize the structure using a native .NET Color structure. + /// firgbaf = new FIRGBAF(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// firgbaf = Color.DarkSeaGreen; + /// // Convert the FIRGBAF instance into a native .NET Color + /// // using its implicit operator. + /// Color color = firgbaf; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = firgbaf.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIRGBAF : IComparable, IComparable, IEquatable + { + /// + /// The red color component. + /// + public float red; + + /// + /// The green color component. + /// + public float green; + + /// + /// The blue color component. + /// + public float blue; + + /// + /// The alpha color component. + /// + public float alpha; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public FIRGBAF(Color color) + { + red = (float)color.R / 255f; + green = (float)color.G / 255f; + blue = (float)color.B / 255f; + alpha = (float)color.A / 255f; + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIRGBAF left, FIRGBAF right) + { + return + ((left.alpha == right.alpha) && + (left.blue == right.blue) && + (left.green == right.green) && + (left.red == right.red)); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIRGBAF left, FIRGBAF right) + { + return !(left == right); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIRGBAF(Color value) + { + return new FIRGBAF(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(FIRGBAF value) + { + return value.Color; + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb( + (int)(alpha * 255f), + (int)(red * 255f), + (int)(green * 255f), + (int)(blue * 255f)); + } + set + { + red = (float)value.R / 255f; + green = (float)value.G / 255f; + blue = (float)value.B / 255f; + alpha = (float)value.A / 255f; + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIRGBAF)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIRGBAF)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIRGBAF other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIRGBAF) && (this == ((FIRGBAF)obj))); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FIRGBAF other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGBF.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGBF.cs index 0fce242..e106669 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGBF.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FIRGBF.cs @@ -1,272 +1,272 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.3 $ -// $Date: 2009/02/20 07:41:08 $ -// $Id: FIRGBF.cs,v 1.3 2009/02/20 07:41:08 cklein05 Exp $ -// ========================================================== - -using System; -using System.Drawing; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The FIRGBF structure describes a color consisting of relative - /// intensities of red, green, blue and alpha value. Each single color - /// component consumes 32 bits and takes values in the range from 0 to 1. - /// - /// - /// - /// The FIRGBF structure provides access to an underlying FreeImage FIRGBF - /// structure. To determine the red, green or blue component of a color, use the - /// red, green or blue fields, respectively. - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the FIRGBF structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the FIRGBF structure and my be used in all situations which require - /// an FIRGBF type. - /// - /// - /// Each color component alpha, red, green or blue of FIRGBF is translated - /// into it's corresponding color component A, R, G or B of - /// by linearly mapping the values of one range - /// into the other range and vice versa. - /// When converting from into FIRGBF, the - /// color's alpha value is ignored and assumed to be 255 when converting from - /// FIRGBF into , creating a fully - /// opaque color. - /// - /// - /// Conversion from System.Drawing.Color to FIRGBF - /// - /// FIRGBF.component = (float)Color.component / 255f - /// - /// Conversion from FIRGBF to System.Drawing.Color - /// - /// Color.component = (int)(FIRGBF.component * 255f) - /// - /// The same conversion is also applied when the - /// property or the constructor - /// is invoked. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// FIRGBF structure and the structure. - /// - /// FIRGBF firgbf; - /// // Initialize the structure using a native .NET Color structure. - /// firgbf = new FIRGBF(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// firgbf = Color.DarkSeaGreen; - /// // Convert the FIRGBF instance into a native .NET Color - /// // using its implicit operator. - /// Color color = firgbf; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = firgbf.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIRGBF : IComparable, IComparable, IEquatable - { - /// - /// The red color component. - /// - public float red; - - /// - /// The green color component. - /// - public float green; - - /// - /// The blue color component. - /// - public float blue; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public FIRGBF(Color color) - { - red = (float)color.R / 255f; - green = (float)color.G / 255f; - blue = (float)color.B / 255f; - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIRGBF left, FIRGBF right) - { - return - ((left.blue == right.blue) && - (left.green == right.green) && - (left.red == right.red)); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIRGBF left, FIRGBF right) - { - return !(left == right); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIRGBF(Color value) - { - return new FIRGBF(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(FIRGBF value) - { - return value.Color; - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb( - (int)(red * 255f), - (int)(green * 255f), - (int)(blue * 255f)); - } - set - { - red = (float)value.R / 255f; - green = (float)value.G / 255f; - blue = (float)value.B / 255f; - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIRGBF)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIRGBF)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIRGBF other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIRGBF) && (this == ((FIRGBF)obj))); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FIRGBF other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.3 $ +// $Date: 2009/02/20 07:41:08 $ +// $Id: FIRGBF.cs,v 1.3 2009/02/20 07:41:08 cklein05 Exp $ +// ========================================================== + +using System; +using System.Drawing; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The FIRGBF structure describes a color consisting of relative + /// intensities of red, green, blue and alpha value. Each single color + /// component consumes 32 bits and takes values in the range from 0 to 1. + /// + /// + /// + /// The FIRGBF structure provides access to an underlying FreeImage FIRGBF + /// structure. To determine the red, green or blue component of a color, use the + /// red, green or blue fields, respectively. + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the FIRGBF structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the FIRGBF structure and my be used in all situations which require + /// an FIRGBF type. + /// + /// + /// Each color component alpha, red, green or blue of FIRGBF is translated + /// into it's corresponding color component A, R, G or B of + /// by linearly mapping the values of one range + /// into the other range and vice versa. + /// When converting from into FIRGBF, the + /// color's alpha value is ignored and assumed to be 255 when converting from + /// FIRGBF into , creating a fully + /// opaque color. + /// + /// + /// Conversion from System.Drawing.Color to FIRGBF + /// + /// FIRGBF.component = (float)Color.component / 255f + /// + /// Conversion from FIRGBF to System.Drawing.Color + /// + /// Color.component = (int)(FIRGBF.component * 255f) + /// + /// The same conversion is also applied when the + /// property or the constructor + /// is invoked. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// FIRGBF structure and the structure. + /// + /// FIRGBF firgbf; + /// // Initialize the structure using a native .NET Color structure. + /// firgbf = new FIRGBF(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// firgbf = Color.DarkSeaGreen; + /// // Convert the FIRGBF instance into a native .NET Color + /// // using its implicit operator. + /// Color color = firgbf; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = firgbf.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIRGBF : IComparable, IComparable, IEquatable + { + /// + /// The red color component. + /// + public float red; + + /// + /// The green color component. + /// + public float green; + + /// + /// The blue color component. + /// + public float blue; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public FIRGBF(Color color) + { + red = (float)color.R / 255f; + green = (float)color.G / 255f; + blue = (float)color.B / 255f; + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIRGBF left, FIRGBF right) + { + return + ((left.blue == right.blue) && + (left.green == right.green) && + (left.red == right.red)); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIRGBF left, FIRGBF right) + { + return !(left == right); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIRGBF(Color value) + { + return new FIRGBF(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(FIRGBF value) + { + return value.Color; + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb( + (int)(red * 255f), + (int)(green * 255f), + (int)(blue * 255f)); + } + set + { + red = (float)value.R / 255f; + green = (float)value.G / 255f; + blue = (float)value.B / 255f; + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIRGBF)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIRGBF)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIRGBF other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIRGBF) && (this == ((FIRGBF)obj))); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FIRGBF other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FIRational.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FIRational.cs index 4788a0b..06280b4 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FIRational.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FIRational.cs @@ -1,1011 +1,1011 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.5 $ -// $Date: 2009/02/27 16:36:23 $ -// $Id: FIRational.cs,v 1.5 2009/02/27 16:36:23 cklein05 Exp $ -// ========================================================== - -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Diagnostics; - -namespace FreeImageAPI -{ - /// - /// The FIRational structure represents a fraction via two - /// instances which are interpreted as numerator and denominator. - /// - /// - /// The structure tries to approximate the value of - /// when creating a new instance by using a better algorithm than FreeImage does. - /// - /// The structure implements the following operators: - /// +, -, ++, --, ==, != , >, >==, <, <== and ~ (which switches nominator and denomiator). - /// - /// The structure can be converted into all .NET standard types either implicit or - /// explicit. - /// - [Serializable, StructLayout(LayoutKind.Sequential), ComVisible(true)] - public struct FIRational : IConvertible, IComparable, IFormattable, IComparable, IEquatable - { - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private int numerator; - - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private int denominator; - - /// - /// Represents the largest possible value of . This field is constant. - /// - public static readonly FIRational MaxValue = new FIRational(Int32.MaxValue, 1); - - /// - /// Represents the smallest possible value of . This field is constant. - /// - public static readonly FIRational MinValue = new FIRational(Int32.MinValue, 1); - - /// - /// Represents the smallest positive value greater than zero. This field is constant. - /// - public static readonly FIRational Epsilon = new FIRational(1, Int32.MaxValue); - - /// - /// Initializes a new instance based on the specified parameters. - /// - /// The numerator. - /// The denominator. - public FIRational(int n, int d) - { - numerator = n; - denominator = d; - Normalize(); - } - - /// - /// Initializes a new instance based on the specified parameters. - /// - /// The tag to read the data from. - public unsafe FIRational(FITAG tag) - { - switch (FreeImage.GetTagType(tag)) - { - case FREE_IMAGE_MDTYPE.FIDT_SRATIONAL: - int* value = (int*)FreeImage.GetTagValue(tag); - numerator = (int)value[0]; - denominator = (int)value[1]; - Normalize(); - return; - default: - throw new ArgumentException("tag"); - } - } - - /// - /// Initializes a new instance based on the specified parameters. - /// - /// The value to convert into a fraction. - /// - /// cannot be converted into a fraction - /// represented by two integer values. - public FIRational(decimal value) - { - try - { - int sign = value < 0 ? -1 : 1; - value = Math.Abs(value); - try - { - int[] contFract = CreateContinuedFraction(value); - CreateFraction(contFract, out numerator, out denominator); - Normalize(); - } - catch - { - numerator = 0; - denominator = 1; - } - if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) - { - int maxDen = (Int32.MaxValue / (int)value) - 2; - maxDen = maxDen < 10000 ? maxDen : 10000; - ApproximateFraction(value, maxDen, out numerator, out denominator); - Normalize(); - if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) - { - throw new OverflowException("Unable to convert value into a fraction"); - } - } - numerator *= sign; - Normalize(); - } - catch (Exception ex) - { - throw new OverflowException("Unable to calculate fraction.", ex); - } - } - - /// - /// The numerator of the fraction. - /// - public int Numerator - { - get { return numerator; } - } - - /// - /// The denominator of the fraction. - /// - public int Denominator - { - get { return denominator; } - } - - /// - /// Returns the truncated value of the fraction. - /// - /// - public int Truncate() - { - return denominator > 0 ? (int)(numerator / denominator) : 0; - } - - /// - /// Returns whether the fraction is representing an integer value. - /// - public bool IsInteger - { - get - { - return (denominator == 1 || - (denominator != 0 && (numerator % denominator == 0)) || - (denominator == 0 && numerator == 0)); - } - } - - /// - /// Calculated the greatest common divisor of 'a' and 'b'. - /// - private static long Gcd(long a, long b) - { - a = Math.Abs(a); - b = Math.Abs(b); - long r; - while (b > 0) - { - r = a % b; - a = b; - b = r; - } - return a; - } - - /// - /// Calculated the smallest common multiple of 'a' and 'b'. - /// - private static long Scm(int n, int m) - { - return Math.Abs((long)n * (long)m) / Gcd(n, m); - } - - /// - /// Normalizes the fraction. - /// - private void Normalize() - { - if (denominator == 0) - { - numerator = 0; - denominator = 1; - return; - } - - if (numerator != 1 && denominator != 1) - { - int common = (int)Gcd(numerator, denominator); - if (common != 1 && common != 0) - { - numerator /= common; - denominator /= common; - } - } - - if (denominator < 0) - { - numerator *= -1; - denominator *= -1; - } - } - - /// - /// Normalizes a fraction. - /// - private static void Normalize(ref long numerator, ref long denominator) - { - if (denominator == 0) - { - numerator = 0; - denominator = 1; - } - else if (numerator != 1 && denominator != 1) - { - long common = Gcd(numerator, denominator); - if (common != 1) - { - numerator /= common; - denominator /= common; - } - } - if (denominator < 0) - { - numerator *= -1; - denominator *= -1; - } - } - - /// - /// Returns the digits after the point. - /// - private static int GetDigits(decimal value) - { - int result = 0; - value -= decimal.Truncate(value); - while (value != 0) - { - value *= 10; - value -= decimal.Truncate(value); - result++; - } - return result; - } - - /// - /// Creates a continued fraction of a decimal value. - /// - private static int[] CreateContinuedFraction(decimal value) - { - int precision = GetDigits(value); - decimal epsilon = 0.0000001m; - List list = new List(); - value = Math.Abs(value); - - byte b = 0; - - list.Add((int)value); - value -= ((int)value); - - while (value != 0m) - { - if (++b == byte.MaxValue || value < epsilon) - { - break; - } - value = 1m / value; - if (Math.Abs((Math.Round(value, precision - 1) - value)) < epsilon) - { - value = Math.Round(value, precision - 1); - } - list.Add((int)value); - value -= ((int)value); - } - return list.ToArray(); - } - - /// - /// Creates a fraction from a continued fraction. - /// - private static void CreateFraction(int[] continuedFraction, out int numerator, out int denominator) - { - numerator = 1; - denominator = 0; - int temp; - - for (int i = continuedFraction.Length - 1; i > -1; i--) - { - temp = numerator; - numerator = continuedFraction[i] * numerator + denominator; - denominator = temp; - } - } - - /// - /// Tries 'brute force' to approximate with a fraction. - /// - private static void ApproximateFraction(decimal value, int maxDen, out int num, out int den) - { - num = 0; - den = 0; - decimal bestDifference = 1m; - decimal currentDifference = -1m; - int digits = GetDigits(value); - - if (digits <= 9) - { - int mul = 1; - for (int i = 1; i <= digits; i++) - { - mul *= 10; - } - if (mul <= maxDen) - { - num = (int)(value * mul); - den = mul; - return; - } - } - - for (int i = 1; i <= maxDen; i++) - { - int numerator = (int)Math.Floor(value * (decimal)i + 0.5m); - currentDifference = Math.Abs(value - (decimal)numerator / (decimal)i); - if (currentDifference < bestDifference) - { - num = numerator; - den = i; - bestDifference = currentDifference; - } - } - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return ((IConvertible)this).ToDouble(null).ToString(); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIRational) && (this == ((FIRational)obj))); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - #region Operators - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator +(FIRational r1) - { - return r1; - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator -(FIRational r1) - { - r1.numerator *= -1; - return r1; - } - - /// - /// Returns the reciprocal value of this instance. - /// - public static FIRational operator ~(FIRational r1) - { - int temp = r1.denominator; - r1.denominator = r1.numerator; - r1.numerator = temp; - r1.Normalize(); - return r1; - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator ++(FIRational r1) - { - checked - { - r1.numerator += r1.denominator; - } - return r1; - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator --(FIRational r1) - { - checked - { - r1.numerator -= r1.denominator; - } - return r1; - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator +(FIRational r1, FIRational r2) - { - long numerator = 0; - long denominator = Scm(r1.denominator, r2.denominator); - numerator = (r1.numerator * (denominator / r1.denominator)) + (r2.numerator * (denominator / r2.denominator)); - Normalize(ref numerator, ref denominator); - checked - { - return new FIRational((int)numerator, (int)denominator); - } - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator -(FIRational r1, FIRational r2) - { - return r1 + (-r2); - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator *(FIRational r1, FIRational r2) - { - long numerator = r1.numerator * r2.numerator; - long denominator = r1.denominator * r2.denominator; - Normalize(ref numerator, ref denominator); - checked - { - return new FIRational((int)numerator, (int)denominator); - } - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator /(FIRational r1, FIRational r2) - { - int temp = r2.denominator; - r2.denominator = r2.numerator; - r2.numerator = temp; - return r1 * r2; - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator %(FIRational r1, FIRational r2) - { - r2.Normalize(); - if (Math.Abs(r2.numerator) < r2.denominator) - return new FIRational(0, 0); - int div = (int)(r1 / r2); - return r1 - (r2 * div); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator ==(FIRational r1, FIRational r2) - { - r1.Normalize(); - r2.Normalize(); - return (r1.numerator == r2.numerator) && (r1.denominator == r2.denominator); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator !=(FIRational r1, FIRational r2) - { - return !(r1 == r2); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator >(FIRational r1, FIRational r2) - { - long denominator = Scm(r1.denominator, r2.denominator); - return (r1.numerator * (denominator / r1.denominator)) > (r2.numerator * (denominator / r2.denominator)); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator <(FIRational r1, FIRational r2) - { - long denominator = Scm(r1.denominator, r2.denominator); - return (r1.numerator * (denominator / r1.denominator)) < (r2.numerator * (denominator / r2.denominator)); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator >=(FIRational r1, FIRational r2) - { - long denominator = Scm(r1.denominator, r2.denominator); - return (r1.numerator * (denominator / r1.denominator)) >= (r2.numerator * (denominator / r2.denominator)); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator <=(FIRational r1, FIRational r2) - { - long denominator = Scm(r1.denominator, r2.denominator); - return (r1.numerator * (denominator / r1.denominator)) <= (r2.numerator * (denominator / r2.denominator)); - } - - #endregion - - #region Conversions - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator bool(FIRational value) - { - return (value.numerator != 0); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator byte(FIRational value) - { - return (byte)(double)value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator char(FIRational value) - { - return (char)(double)value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator decimal(FIRational value) - { - return value.denominator == 0 ? 0m : (decimal)value.numerator / (decimal)value.denominator; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator double(FIRational value) - { - return value.denominator == 0 ? 0d : (double)value.numerator / (double)value.denominator; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator short(FIRational value) - { - return (short)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator int(FIRational value) - { - return (int)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator long(FIRational value) - { - return (byte)(double)value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator float(FIRational value) - { - return value.denominator == 0 ? 0f : (float)value.numerator / (float)value.denominator; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator sbyte(FIRational value) - { - return (sbyte)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator ushort(FIRational value) - { - return (ushort)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator uint(FIRational value) - { - return (uint)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator ulong(FIRational value) - { - return (ulong)(double)value; - } - - // - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIRational(bool value) - { - return new FIRational(value ? 1 : 0, 1); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIRational(byte value) - { - return new FIRational(value, 1); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIRational(char value) - { - return new FIRational(value, 1); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIRational(decimal value) - { - return new FIRational(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIRational(double value) - { - return new FIRational((decimal)value); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator FIRational(short value) - { - return new FIRational(value, 1); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator FIRational(int value) - { - return new FIRational(value, 1); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static explicit operator FIRational(long value) - { - return new FIRational((int)value, 1); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIRational(sbyte value) - { - return new FIRational(value, 1); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIRational(float value) - { - return new FIRational((decimal)value); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator FIRational(ushort value) - { - return new FIRational(value, 1); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static explicit operator FIRational(uint value) - { - return new FIRational((int)value, 1); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static explicit operator FIRational(ulong value) - { - return new FIRational((int)value, 1); - } - - #endregion - - #region IConvertible Member - - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Double; - } - - bool IConvertible.ToBoolean(IFormatProvider provider) - { - return (bool)this; - } - - byte IConvertible.ToByte(IFormatProvider provider) - { - return (byte)this; - } - - char IConvertible.ToChar(IFormatProvider provider) - { - return (char)this; - } - - DateTime IConvertible.ToDateTime(IFormatProvider provider) - { - return Convert.ToDateTime(((IConvertible)this).ToDouble(provider)); - } - - decimal IConvertible.ToDecimal(IFormatProvider provider) - { - return this; - } - - double IConvertible.ToDouble(IFormatProvider provider) - { - return this; - } - - short IConvertible.ToInt16(IFormatProvider provider) - { - return (short)this; - } - - int IConvertible.ToInt32(IFormatProvider provider) - { - return (int)this; - } - - long IConvertible.ToInt64(IFormatProvider provider) - { - return (long)this; - } - - sbyte IConvertible.ToSByte(IFormatProvider provider) - { - return (sbyte)this; - } - - float IConvertible.ToSingle(IFormatProvider provider) - { - return this; - } - - string IConvertible.ToString(IFormatProvider provider) - { - return ToString(((double)this).ToString(), provider); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider provider) - { - return Convert.ChangeType(((IConvertible)this).ToDouble(provider), conversionType, provider); - } - - ushort IConvertible.ToUInt16(IFormatProvider provider) - { - return (ushort)this; - } - - uint IConvertible.ToUInt32(IFormatProvider provider) - { - return (uint)this; - } - - ulong IConvertible.ToUInt64(IFormatProvider provider) - { - return (ulong)this; - } - - #endregion - - #region IComparable Member - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIRational)) - { - throw new ArgumentException(); - } - return CompareTo((FIRational)obj); - } - - #endregion - - #region IFormattable Member - - /// - /// Formats the value of the current instance using the specified format. - /// - /// The String specifying the format to use. - /// The IFormatProvider to use to format the value. - /// A String containing the value of the current instance in the specified format. - public string ToString(string format, IFormatProvider formatProvider) - { - if (format == null) - { - format = ""; - } - return String.Format(formatProvider, format, ((IConvertible)this).ToDouble(formatProvider)); - } - - #endregion - - #region IEquatable Member - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FIRational other) - { - return (this == other); - } - - #endregion - - #region IComparable Member - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIRational other) - { - FIRational difference = this - other; - difference.Normalize(); - if (difference.numerator > 0) return 1; - if (difference.numerator < 0) return -1; - else return 0; - } - - #endregion - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.5 $ +// $Date: 2009/02/27 16:36:23 $ +// $Id: FIRational.cs,v 1.5 2009/02/27 16:36:23 cklein05 Exp $ +// ========================================================== + +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Diagnostics; + +namespace FreeImageAPI +{ + /// + /// The FIRational structure represents a fraction via two + /// instances which are interpreted as numerator and denominator. + /// + /// + /// The structure tries to approximate the value of + /// when creating a new instance by using a better algorithm than FreeImage does. + /// + /// The structure implements the following operators: + /// +, -, ++, --, ==, != , >, >==, <, <== and ~ (which switches nominator and denomiator). + /// + /// The structure can be converted into all .NET standard types either implicit or + /// explicit. + /// + [Serializable, StructLayout(LayoutKind.Sequential), ComVisible(true)] + public struct FIRational : IConvertible, IComparable, IFormattable, IComparable, IEquatable + { + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private int numerator; + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private int denominator; + + /// + /// Represents the largest possible value of . This field is constant. + /// + public static readonly FIRational MaxValue = new FIRational(Int32.MaxValue, 1); + + /// + /// Represents the smallest possible value of . This field is constant. + /// + public static readonly FIRational MinValue = new FIRational(Int32.MinValue, 1); + + /// + /// Represents the smallest positive value greater than zero. This field is constant. + /// + public static readonly FIRational Epsilon = new FIRational(1, Int32.MaxValue); + + /// + /// Initializes a new instance based on the specified parameters. + /// + /// The numerator. + /// The denominator. + public FIRational(int n, int d) + { + numerator = n; + denominator = d; + Normalize(); + } + + /// + /// Initializes a new instance based on the specified parameters. + /// + /// The tag to read the data from. + public unsafe FIRational(FITAG tag) + { + switch (FreeImage.GetTagType(tag)) + { + case FREE_IMAGE_MDTYPE.FIDT_SRATIONAL: + int* value = (int*)FreeImage.GetTagValue(tag); + numerator = (int)value[0]; + denominator = (int)value[1]; + Normalize(); + return; + default: + throw new ArgumentException("tag"); + } + } + + /// + /// Initializes a new instance based on the specified parameters. + /// + /// The value to convert into a fraction. + /// + /// cannot be converted into a fraction + /// represented by two integer values. + public FIRational(decimal value) + { + try + { + int sign = value < 0 ? -1 : 1; + value = Math.Abs(value); + try + { + int[] contFract = CreateContinuedFraction(value); + CreateFraction(contFract, out numerator, out denominator); + Normalize(); + } + catch + { + numerator = 0; + denominator = 1; + } + if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) + { + int maxDen = (Int32.MaxValue / (int)value) - 2; + maxDen = maxDen < 10000 ? maxDen : 10000; + ApproximateFraction(value, maxDen, out numerator, out denominator); + Normalize(); + if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) + { + throw new OverflowException("Unable to convert value into a fraction"); + } + } + numerator *= sign; + Normalize(); + } + catch (Exception ex) + { + throw new OverflowException("Unable to calculate fraction.", ex); + } + } + + /// + /// The numerator of the fraction. + /// + public int Numerator + { + get { return numerator; } + } + + /// + /// The denominator of the fraction. + /// + public int Denominator + { + get { return denominator; } + } + + /// + /// Returns the truncated value of the fraction. + /// + /// + public int Truncate() + { + return denominator > 0 ? (int)(numerator / denominator) : 0; + } + + /// + /// Returns whether the fraction is representing an integer value. + /// + public bool IsInteger + { + get + { + return (denominator == 1 || + (denominator != 0 && (numerator % denominator == 0)) || + (denominator == 0 && numerator == 0)); + } + } + + /// + /// Calculated the greatest common divisor of 'a' and 'b'. + /// + private static long Gcd(long a, long b) + { + a = Math.Abs(a); + b = Math.Abs(b); + long r; + while (b > 0) + { + r = a % b; + a = b; + b = r; + } + return a; + } + + /// + /// Calculated the smallest common multiple of 'a' and 'b'. + /// + private static long Scm(int n, int m) + { + return Math.Abs((long)n * (long)m) / Gcd(n, m); + } + + /// + /// Normalizes the fraction. + /// + private void Normalize() + { + if (denominator == 0) + { + numerator = 0; + denominator = 1; + return; + } + + if (numerator != 1 && denominator != 1) + { + int common = (int)Gcd(numerator, denominator); + if (common != 1 && common != 0) + { + numerator /= common; + denominator /= common; + } + } + + if (denominator < 0) + { + numerator *= -1; + denominator *= -1; + } + } + + /// + /// Normalizes a fraction. + /// + private static void Normalize(ref long numerator, ref long denominator) + { + if (denominator == 0) + { + numerator = 0; + denominator = 1; + } + else if (numerator != 1 && denominator != 1) + { + long common = Gcd(numerator, denominator); + if (common != 1) + { + numerator /= common; + denominator /= common; + } + } + if (denominator < 0) + { + numerator *= -1; + denominator *= -1; + } + } + + /// + /// Returns the digits after the point. + /// + private static int GetDigits(decimal value) + { + int result = 0; + value -= decimal.Truncate(value); + while (value != 0) + { + value *= 10; + value -= decimal.Truncate(value); + result++; + } + return result; + } + + /// + /// Creates a continued fraction of a decimal value. + /// + private static int[] CreateContinuedFraction(decimal value) + { + int precision = GetDigits(value); + decimal epsilon = 0.0000001m; + List list = new List(); + value = Math.Abs(value); + + byte b = 0; + + list.Add((int)value); + value -= ((int)value); + + while (value != 0m) + { + if (++b == byte.MaxValue || value < epsilon) + { + break; + } + value = 1m / value; + if (Math.Abs((Math.Round(value, precision - 1) - value)) < epsilon) + { + value = Math.Round(value, precision - 1); + } + list.Add((int)value); + value -= ((int)value); + } + return list.ToArray(); + } + + /// + /// Creates a fraction from a continued fraction. + /// + private static void CreateFraction(int[] continuedFraction, out int numerator, out int denominator) + { + numerator = 1; + denominator = 0; + int temp; + + for (int i = continuedFraction.Length - 1; i > -1; i--) + { + temp = numerator; + numerator = continuedFraction[i] * numerator + denominator; + denominator = temp; + } + } + + /// + /// Tries 'brute force' to approximate with a fraction. + /// + private static void ApproximateFraction(decimal value, int maxDen, out int num, out int den) + { + num = 0; + den = 0; + decimal bestDifference = 1m; + decimal currentDifference = -1m; + int digits = GetDigits(value); + + if (digits <= 9) + { + int mul = 1; + for (int i = 1; i <= digits; i++) + { + mul *= 10; + } + if (mul <= maxDen) + { + num = (int)(value * mul); + den = mul; + return; + } + } + + for (int i = 1; i <= maxDen; i++) + { + int numerator = (int)Math.Floor(value * (decimal)i + 0.5m); + currentDifference = Math.Abs(value - (decimal)numerator / (decimal)i); + if (currentDifference < bestDifference) + { + num = numerator; + den = i; + bestDifference = currentDifference; + } + } + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return ((IConvertible)this).ToDouble(null).ToString(); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIRational) && (this == ((FIRational)obj))); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + #region Operators + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator +(FIRational r1) + { + return r1; + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator -(FIRational r1) + { + r1.numerator *= -1; + return r1; + } + + /// + /// Returns the reciprocal value of this instance. + /// + public static FIRational operator ~(FIRational r1) + { + int temp = r1.denominator; + r1.denominator = r1.numerator; + r1.numerator = temp; + r1.Normalize(); + return r1; + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator ++(FIRational r1) + { + checked + { + r1.numerator += r1.denominator; + } + return r1; + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator --(FIRational r1) + { + checked + { + r1.numerator -= r1.denominator; + } + return r1; + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator +(FIRational r1, FIRational r2) + { + long numerator = 0; + long denominator = Scm(r1.denominator, r2.denominator); + numerator = (r1.numerator * (denominator / r1.denominator)) + (r2.numerator * (denominator / r2.denominator)); + Normalize(ref numerator, ref denominator); + checked + { + return new FIRational((int)numerator, (int)denominator); + } + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator -(FIRational r1, FIRational r2) + { + return r1 + (-r2); + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator *(FIRational r1, FIRational r2) + { + long numerator = r1.numerator * r2.numerator; + long denominator = r1.denominator * r2.denominator; + Normalize(ref numerator, ref denominator); + checked + { + return new FIRational((int)numerator, (int)denominator); + } + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator /(FIRational r1, FIRational r2) + { + int temp = r2.denominator; + r2.denominator = r2.numerator; + r2.numerator = temp; + return r1 * r2; + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator %(FIRational r1, FIRational r2) + { + r2.Normalize(); + if (Math.Abs(r2.numerator) < r2.denominator) + return new FIRational(0, 0); + int div = (int)(r1 / r2); + return r1 - (r2 * div); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator ==(FIRational r1, FIRational r2) + { + r1.Normalize(); + r2.Normalize(); + return (r1.numerator == r2.numerator) && (r1.denominator == r2.denominator); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator !=(FIRational r1, FIRational r2) + { + return !(r1 == r2); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator >(FIRational r1, FIRational r2) + { + long denominator = Scm(r1.denominator, r2.denominator); + return (r1.numerator * (denominator / r1.denominator)) > (r2.numerator * (denominator / r2.denominator)); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator <(FIRational r1, FIRational r2) + { + long denominator = Scm(r1.denominator, r2.denominator); + return (r1.numerator * (denominator / r1.denominator)) < (r2.numerator * (denominator / r2.denominator)); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator >=(FIRational r1, FIRational r2) + { + long denominator = Scm(r1.denominator, r2.denominator); + return (r1.numerator * (denominator / r1.denominator)) >= (r2.numerator * (denominator / r2.denominator)); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator <=(FIRational r1, FIRational r2) + { + long denominator = Scm(r1.denominator, r2.denominator); + return (r1.numerator * (denominator / r1.denominator)) <= (r2.numerator * (denominator / r2.denominator)); + } + + #endregion + + #region Conversions + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator bool(FIRational value) + { + return (value.numerator != 0); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator byte(FIRational value) + { + return (byte)(double)value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator char(FIRational value) + { + return (char)(double)value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator decimal(FIRational value) + { + return value.denominator == 0 ? 0m : (decimal)value.numerator / (decimal)value.denominator; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator double(FIRational value) + { + return value.denominator == 0 ? 0d : (double)value.numerator / (double)value.denominator; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator short(FIRational value) + { + return (short)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator int(FIRational value) + { + return (int)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator long(FIRational value) + { + return (byte)(double)value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator float(FIRational value) + { + return value.denominator == 0 ? 0f : (float)value.numerator / (float)value.denominator; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator sbyte(FIRational value) + { + return (sbyte)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator ushort(FIRational value) + { + return (ushort)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator uint(FIRational value) + { + return (uint)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator ulong(FIRational value) + { + return (ulong)(double)value; + } + + // + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIRational(bool value) + { + return new FIRational(value ? 1 : 0, 1); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIRational(byte value) + { + return new FIRational(value, 1); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIRational(char value) + { + return new FIRational(value, 1); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIRational(decimal value) + { + return new FIRational(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIRational(double value) + { + return new FIRational((decimal)value); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator FIRational(short value) + { + return new FIRational(value, 1); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator FIRational(int value) + { + return new FIRational(value, 1); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static explicit operator FIRational(long value) + { + return new FIRational((int)value, 1); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIRational(sbyte value) + { + return new FIRational(value, 1); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIRational(float value) + { + return new FIRational((decimal)value); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator FIRational(ushort value) + { + return new FIRational(value, 1); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static explicit operator FIRational(uint value) + { + return new FIRational((int)value, 1); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static explicit operator FIRational(ulong value) + { + return new FIRational((int)value, 1); + } + + #endregion + + #region IConvertible Member + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Double; + } + + bool IConvertible.ToBoolean(IFormatProvider provider) + { + return (bool)this; + } + + byte IConvertible.ToByte(IFormatProvider provider) + { + return (byte)this; + } + + char IConvertible.ToChar(IFormatProvider provider) + { + return (char)this; + } + + DateTime IConvertible.ToDateTime(IFormatProvider provider) + { + return Convert.ToDateTime(((IConvertible)this).ToDouble(provider)); + } + + decimal IConvertible.ToDecimal(IFormatProvider provider) + { + return this; + } + + double IConvertible.ToDouble(IFormatProvider provider) + { + return this; + } + + short IConvertible.ToInt16(IFormatProvider provider) + { + return (short)this; + } + + int IConvertible.ToInt32(IFormatProvider provider) + { + return (int)this; + } + + long IConvertible.ToInt64(IFormatProvider provider) + { + return (long)this; + } + + sbyte IConvertible.ToSByte(IFormatProvider provider) + { + return (sbyte)this; + } + + float IConvertible.ToSingle(IFormatProvider provider) + { + return this; + } + + string IConvertible.ToString(IFormatProvider provider) + { + return ToString(((double)this).ToString(), provider); + } + + object IConvertible.ToType(Type conversionType, IFormatProvider provider) + { + return Convert.ChangeType(((IConvertible)this).ToDouble(provider), conversionType, provider); + } + + ushort IConvertible.ToUInt16(IFormatProvider provider) + { + return (ushort)this; + } + + uint IConvertible.ToUInt32(IFormatProvider provider) + { + return (uint)this; + } + + ulong IConvertible.ToUInt64(IFormatProvider provider) + { + return (ulong)this; + } + + #endregion + + #region IComparable Member + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIRational)) + { + throw new ArgumentException(); + } + return CompareTo((FIRational)obj); + } + + #endregion + + #region IFormattable Member + + /// + /// Formats the value of the current instance using the specified format. + /// + /// The String specifying the format to use. + /// The IFormatProvider to use to format the value. + /// A String containing the value of the current instance in the specified format. + public string ToString(string format, IFormatProvider formatProvider) + { + if (format == null) + { + format = ""; + } + return String.Format(formatProvider, format, ((IConvertible)this).ToDouble(formatProvider)); + } + + #endregion + + #region IEquatable Member + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FIRational other) + { + return (this == other); + } + + #endregion + + #region IComparable Member + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIRational other) + { + FIRational difference = this - other; + difference.Normalize(); + if (difference.numerator > 0) return 1; + if (difference.numerator < 0) return -1; + else return 0; + } + + #endregion + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FITAG.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FITAG.cs index a439bb9..e82a1aa 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FITAG.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FITAG.cs @@ -1,170 +1,170 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.5 $ -// $Date: 2009/02/20 07:41:08 $ -// $Id: FITAG.cs,v 1.5 2009/02/20 07:41:08 cklein05 Exp $ -// ========================================================== - -using System; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The FITAG structure is a handle to a FreeImage metadata tag. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FITAG : IComparable, IComparable, IEquatable - { - private IntPtr data; - - /// - /// A read-only field that represents a handle that has been initialized to zero. - /// - public static readonly FITAG Zero; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FITAG left, FITAG right) - { - return (left.data == right.data); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FITAG left, FITAG right) - { - return (left.data != right.data); - } - - /// - /// Gets whether the pointer is a null pointer or not. - /// - /// true if this is a null pointer; - /// otherwise, false. - public bool IsNull - { - get - { - return (data == IntPtr.Zero); - } - } - - /// - /// Sets the handle to null. - /// - public void SetNull() - { - data = IntPtr.Zero; - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return data.ToString(); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return data.GetHashCode(); - } - - /// - /// Determines whether the specified is equal to the current . - /// - /// The to compare with the current . - /// true if the specified is equal to the current ; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FITAG) && (this == ((FITAG)obj))); - } - - /// - /// Indicates whether the current object is equal to another object of the same type. - /// - /// An object to compare with this object. - /// true if the current object is equal to the other parameter; otherwise, false. - public bool Equals(FITAG other) - { - return (this == other); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FITAG)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FITAG)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FITAG other) - { - return this.data.ToInt64().CompareTo(other.data.ToInt64()); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.5 $ +// $Date: 2009/02/20 07:41:08 $ +// $Id: FITAG.cs,v 1.5 2009/02/20 07:41:08 cklein05 Exp $ +// ========================================================== + +using System; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The FITAG structure is a handle to a FreeImage metadata tag. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FITAG : IComparable, IComparable, IEquatable + { + private IntPtr data; + + /// + /// A read-only field that represents a handle that has been initialized to zero. + /// + public static readonly FITAG Zero; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FITAG left, FITAG right) + { + return (left.data == right.data); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FITAG left, FITAG right) + { + return (left.data != right.data); + } + + /// + /// Gets whether the pointer is a null pointer or not. + /// + /// true if this is a null pointer; + /// otherwise, false. + public bool IsNull + { + get + { + return (data == IntPtr.Zero); + } + } + + /// + /// Sets the handle to null. + /// + public void SetNull() + { + data = IntPtr.Zero; + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return data.ToString(); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return data.GetHashCode(); + } + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current ; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FITAG) && (this == ((FITAG)obj))); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// An object to compare with this object. + /// true if the current object is equal to the other parameter; otherwise, false. + public bool Equals(FITAG other) + { + return (this == other); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FITAG)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FITAG)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FITAG other) + { + return this.data.ToInt64().CompareTo(other.data.ToInt64()); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FIURational.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FIURational.cs index 4c2f24d..9c04983 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FIURational.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FIURational.cs @@ -1,1010 +1,1010 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.5 $ -// $Date: 2009/02/27 16:36:23 $ -// $Id: FIURational.cs,v 1.5 2009/02/27 16:36:23 cklein05 Exp $ -// ========================================================== - -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Diagnostics; - -namespace FreeImageAPI -{ - /// - /// The FIURational structure represents a fraction via two - /// instances which are interpreted as numerator and denominator. - /// - /// - /// The structure tries to approximate the value of - /// when creating a new instance by using a better algorithm than FreeImage does. - /// - /// The structure implements the following operators: - /// +, ++, --, ==, != , >, >==, <, <== and ~ (which switches nominator and denomiator). - /// - /// The structure can be converted into all .NET standard types either implicit or - /// explicit. - /// - [Serializable, StructLayout(LayoutKind.Sequential), ComVisible(true)] - public struct FIURational : IConvertible, IComparable, IFormattable, IComparable, IEquatable - { - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private uint numerator; - - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private uint denominator; - - /// - /// Represents the largest possible value of . This field is constant. - /// - public static readonly FIURational MaxValue = new FIURational(UInt32.MaxValue, 1u); - - /// - /// Represents the smallest possible value of . This field is constant. - /// - public static readonly FIURational MinValue = new FIURational(0u, 1u); - - /// - /// Represents the smallest positive value greater than zero. This field is constant. - /// - public static readonly FIURational Epsilon = new FIURational(1u, UInt32.MaxValue); - - /// - /// Initializes a new instance based on the specified parameters. - /// - /// The numerator. - /// The denominator. - public FIURational(uint n, uint d) - { - numerator = n; - denominator = d; - Normalize(); - } - - /// - /// Initializes a new instance based on the specified parameters. - /// - /// The tag to read the data from. - public unsafe FIURational(FITAG tag) - { - switch (FreeImage.GetTagType(tag)) - { - case FREE_IMAGE_MDTYPE.FIDT_RATIONAL: - uint* pvalue = (uint*)FreeImage.GetTagValue(tag); - numerator = pvalue[0]; - denominator = pvalue[1]; - Normalize(); - return; - default: - throw new ArgumentException("tag"); - } - } - - /// - ///Initializes a new instance based on the specified parameters. - /// - /// The value to convert into a fraction. - /// - /// cannot be converted into a fraction - /// represented by two unsigned integer values. - public FIURational(decimal value) - { - try - { - if (value < 0) - { - throw new OverflowException("value"); - } - try - { - int[] contFract = CreateContinuedFraction(value); - CreateFraction(contFract, out numerator, out denominator); - Normalize(); - } - catch - { - numerator = 0; - denominator = 1; - } - if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) - { - int maxDen = (Int32.MaxValue / (int)value) - 2; - maxDen = maxDen < 10000 ? maxDen : 10000; - ApproximateFraction(value, maxDen, out numerator, out denominator); - Normalize(); - if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) - { - throw new OverflowException("Unable to convert value into a fraction"); - } - } - Normalize(); - } - catch (Exception ex) - { - throw new OverflowException("Unable to calculate fraction.", ex); - } - } - - /// - /// The numerator of the fraction. - /// - public uint Numerator - { - get { return numerator; } - } - - /// - /// The denominator of the fraction. - /// - public uint Denominator - { - get { return denominator; } - } - - /// - /// Returns the truncated value of the fraction. - /// - /// - public int Truncate() - { - return denominator > 0 ? (int)(numerator / denominator) : 0; - } - - /// - /// Returns whether the fraction is representing an integer value. - /// - public bool IsInteger - { - get - { - return (denominator == 1 || - (denominator != 0 && (numerator % denominator == 0)) || - (denominator == 0 && numerator == 0)); - } - } - - /// - /// Calculated the greatest common divisor of 'a' and 'b'. - /// - private static ulong Gcd(ulong a, ulong b) - { - ulong r; - while (b > 0) - { - r = a % b; - a = b; - b = r; - } - return a; - } - - /// - /// Calculated the smallest common multiple of 'a' and 'b'. - /// - private static ulong Scm(uint n, uint m) - { - return (ulong)n * (ulong)m / Gcd(n, m); - } - - /// - /// Normalizes the fraction. - /// - private void Normalize() - { - if (denominator == 0) - { - numerator = 0; - denominator = 1; - return; - } - - if (numerator != 1 && denominator != 1) - { - uint common = (uint)Gcd(numerator, denominator); - if (common != 1 && common != 0) - { - numerator /= common; - denominator /= common; - } - } - } - - /// - /// Normalizes a fraction. - /// - private static void Normalize(ref ulong numerator, ref ulong denominator) - { - if (denominator == 0) - { - numerator = 0; - denominator = 1; - } - else if (numerator != 1 && denominator != 1) - { - ulong common = Gcd(numerator, denominator); - if (common != 1) - { - numerator /= common; - denominator /= common; - } - } - } - - /// - /// Returns the digits after the point. - /// - private static int GetDigits(decimal value) - { - int result = 0; - value -= decimal.Truncate(value); - while (value != 0) - { - value *= 10; - value -= decimal.Truncate(value); - result++; - } - return result; - } - - /// - /// Creates a continued fraction of a decimal value. - /// - private static int[] CreateContinuedFraction(decimal value) - { - int precision = GetDigits(value); - decimal epsilon = 0.0000001m; - List list = new List(); - value = Math.Abs(value); - - byte b = 0; - - list.Add((int)value); - value -= ((int)value); - - while (value != 0m) - { - if (++b == byte.MaxValue || value < epsilon) - { - break; - } - value = 1m / value; - if (Math.Abs((Math.Round(value, precision - 1) - value)) < epsilon) - { - value = Math.Round(value, precision - 1); - } - list.Add((int)value); - value -= ((int)value); - } - return list.ToArray(); - } - - /// - /// Creates a fraction from a continued fraction. - /// - private static void CreateFraction(int[] continuedFraction, out uint numerator, out uint denominator) - { - numerator = 1; - denominator = 0; - uint temp; - - for (int i = continuedFraction.Length - 1; i > -1; i--) - { - temp = numerator; - numerator = (uint)(continuedFraction[i] * numerator + denominator); - denominator = temp; - } - } - - /// - /// Tries 'brute force' to approximate with a fraction. - /// - private static void ApproximateFraction(decimal value, int maxDen, out uint num, out uint den) - { - num = 0; - den = 0; - decimal bestDifference = 1m; - decimal currentDifference = -1m; - int digits = GetDigits(value); - - if (digits <= 9) - { - uint mul = 1; - for (int i = 1; i <= digits; i++) - { - mul *= 10; - } - if (mul <= maxDen) - { - num = (uint)(value * mul); - den = mul; - return; - } - } - - for (uint u = 1; u <= maxDen; u++) - { - uint numerator = (uint)Math.Floor(value * (decimal)u + 0.5m); - currentDifference = Math.Abs(value - (decimal)numerator / (decimal)u); - if (currentDifference < bestDifference) - { - num = numerator; - den = u; - bestDifference = currentDifference; - } - } - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return ((IConvertible)this).ToDouble(null).ToString(); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIURational) && (this == ((FIURational)obj))); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - #region Operators - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator +(FIURational value) - { - return value; - } - - /// - /// Returns the reciprocal value of this instance. - /// - public static FIURational operator ~(FIURational value) - { - uint temp = value.denominator; - value.denominator = value.numerator; - value.numerator = temp; - value.Normalize(); - return value; - } - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator ++(FIURational value) - { - checked - { - value.numerator += value.denominator; - } - return value; - } - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator --(FIURational value) - { - checked - { - value.numerator -= value.denominator; - } - return value; - } - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator +(FIURational left, FIURational right) - { - ulong numerator = 0; - ulong denominator = Scm(left.denominator, right.denominator); - numerator = (left.numerator * (denominator / left.denominator)) + - (right.numerator * (denominator / right.denominator)); - Normalize(ref numerator, ref denominator); - checked - { - return new FIURational((uint)numerator, (uint)denominator); - } - } - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator -(FIURational left, FIURational right) - { - checked - { - if (left.denominator != right.denominator) - { - uint denom = left.denominator; - left.numerator *= right.denominator; - left.denominator *= right.denominator; - right.numerator *= denom; - right.denominator *= denom; - } - left.numerator -= right.numerator; - left.Normalize(); - return left; - } - } - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator *(FIURational left, FIURational r2) - { - ulong numerator = left.numerator * r2.numerator; - ulong denominator = left.denominator * r2.denominator; - Normalize(ref numerator, ref denominator); - checked - { - return new FIURational((uint)numerator, (uint)denominator); - } - } - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator /(FIURational left, FIURational right) - { - uint temp = right.denominator; - right.denominator = right.numerator; - right.numerator = temp; - return left * right; - } - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator %(FIURational left, FIURational right) - { - right.Normalize(); - if (Math.Abs(right.numerator) < right.denominator) - return new FIURational(0, 0); - int div = (int)(left / right); - return left - (right * div); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator ==(FIURational left, FIURational right) - { - left.Normalize(); - right.Normalize(); - return (left.numerator == right.numerator) && (left.denominator == right.denominator); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator !=(FIURational left, FIURational right) - { - left.Normalize(); - right.Normalize(); - return (left.numerator != right.numerator) || (left.denominator != right.denominator); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator >(FIURational left, FIURational right) - { - ulong denominator = Scm(left.denominator, right.denominator); - return (left.numerator * (denominator / left.denominator)) > - (right.numerator * (denominator / right.denominator)); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator <(FIURational left, FIURational right) - { - ulong denominator = Scm(left.denominator, right.denominator); - return (left.numerator * (denominator / left.denominator)) < - (right.numerator * (denominator / right.denominator)); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator >=(FIURational left, FIURational right) - { - ulong denominator = Scm(left.denominator, right.denominator); - return (left.numerator * (denominator / left.denominator)) >= - (right.numerator * (denominator / right.denominator)); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator <=(FIURational left, FIURational right) - { - ulong denominator = Scm(left.denominator, right.denominator); - return (left.numerator * (denominator / left.denominator)) <= - (right.numerator * (denominator / right.denominator)); - } - - #endregion - - #region Conversions - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator bool(FIURational value) - { - return (value.numerator != 0); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator byte(FIURational value) - { - return (byte)(double)value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator char(FIURational value) - { - return (char)(double)value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator decimal(FIURational value) - { - return value.denominator == 0 ? 0m : (decimal)value.numerator / (decimal)value.denominator; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator double(FIURational value) - { - return value.denominator == 0 ? 0d : (double)value.numerator / (double)value.denominator; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator short(FIURational value) - { - return (short)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator int(FIURational value) - { - return (int)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator long(FIURational value) - { - return (byte)(double)value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator float(FIURational value) - { - return value.denominator == 0 ? 0f : (float)value.numerator / (float)value.denominator; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator sbyte(FIURational value) - { - return (sbyte)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator ushort(FIURational value) - { - return (ushort)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator uint(FIURational value) - { - return (uint)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator ulong(FIURational value) - { - return (ulong)(double)value; - } - - // - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIURational(bool value) - { - return new FIURational(value ? 1u : 0u, 1u); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIURational(byte value) - { - return new FIURational(value, 1); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIURational(char value) - { - return new FIURational(value, 1); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIURational(decimal value) - { - return new FIURational(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIURational(double value) - { - return new FIURational((decimal)value); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator FIURational(short value) - { - return new FIURational((uint)value, 1u); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator FIURational(int value) - { - return new FIURational((uint)value, 1u); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static explicit operator FIURational(long value) - { - return new FIURational((uint)value, 1u); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIURational(sbyte value) - { - return new FIURational((uint)value, 1u); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIURational(float value) - { - return new FIURational((decimal)value); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator FIURational(ushort value) - { - return new FIURational(value, 1); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static explicit operator FIURational(uint value) - { - return new FIURational(value, 1u); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static explicit operator FIURational(ulong value) - { - return new FIURational((uint)value, 1u); - } - - #endregion - - #region IConvertible Member - - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Double; - } - - bool IConvertible.ToBoolean(IFormatProvider provider) - { - return (bool)this; - } - - byte IConvertible.ToByte(IFormatProvider provider) - { - return (byte)this; - } - - char IConvertible.ToChar(IFormatProvider provider) - { - return (char)this; - } - - DateTime IConvertible.ToDateTime(IFormatProvider provider) - { - return Convert.ToDateTime(((IConvertible)this).ToDouble(provider)); - } - - decimal IConvertible.ToDecimal(IFormatProvider provider) - { - return this; - } - - double IConvertible.ToDouble(IFormatProvider provider) - { - return this; - } - - short IConvertible.ToInt16(IFormatProvider provider) - { - return (short)this; - } - - int IConvertible.ToInt32(IFormatProvider provider) - { - return (int)this; - } - - long IConvertible.ToInt64(IFormatProvider provider) - { - return (long)this; - } - - sbyte IConvertible.ToSByte(IFormatProvider provider) - { - return (sbyte)this; - } - - float IConvertible.ToSingle(IFormatProvider provider) - { - return this; - } - - string IConvertible.ToString(IFormatProvider provider) - { - return ToString(((double)this).ToString(), provider); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider provider) - { - return Convert.ChangeType(((IConvertible)this).ToDouble(provider), conversionType, provider); - } - - ushort IConvertible.ToUInt16(IFormatProvider provider) - { - return (ushort)this; - } - - uint IConvertible.ToUInt32(IFormatProvider provider) - { - return (uint)this; - } - - ulong IConvertible.ToUInt64(IFormatProvider provider) - { - return (ulong)this; - } - - #endregion - - #region IComparable Member - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIURational)) - { - throw new ArgumentException(); - } - return CompareTo((FIURational)obj); - } - - #endregion - - #region IFormattable Member - - /// - /// Formats the value of the current instance using the specified format. - /// - /// The String specifying the format to use. - /// The IFormatProvider to use to format the value. - /// A String containing the value of the current instance in the specified format. - public string ToString(string format, IFormatProvider formatProvider) - { - if (format == null) - { - format = ""; - } - return String.Format(formatProvider, format, ((IConvertible)this).ToDouble(formatProvider)); - } - - #endregion - - #region IEquatable Member - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FIURational other) - { - return (this == other); - } - - #endregion - - #region IComparable Member - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIURational other) - { - FIURational difference = this - other; - difference.Normalize(); - if (difference.numerator > 0) return 1; - if (difference.numerator < 0) return -1; - else return 0; - } - - #endregion - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.5 $ +// $Date: 2009/02/27 16:36:23 $ +// $Id: FIURational.cs,v 1.5 2009/02/27 16:36:23 cklein05 Exp $ +// ========================================================== + +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Diagnostics; + +namespace FreeImageAPI +{ + /// + /// The FIURational structure represents a fraction via two + /// instances which are interpreted as numerator and denominator. + /// + /// + /// The structure tries to approximate the value of + /// when creating a new instance by using a better algorithm than FreeImage does. + /// + /// The structure implements the following operators: + /// +, ++, --, ==, != , >, >==, <, <== and ~ (which switches nominator and denomiator). + /// + /// The structure can be converted into all .NET standard types either implicit or + /// explicit. + /// + [Serializable, StructLayout(LayoutKind.Sequential), ComVisible(true)] + public struct FIURational : IConvertible, IComparable, IFormattable, IComparable, IEquatable + { + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private uint numerator; + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private uint denominator; + + /// + /// Represents the largest possible value of . This field is constant. + /// + public static readonly FIURational MaxValue = new FIURational(UInt32.MaxValue, 1u); + + /// + /// Represents the smallest possible value of . This field is constant. + /// + public static readonly FIURational MinValue = new FIURational(0u, 1u); + + /// + /// Represents the smallest positive value greater than zero. This field is constant. + /// + public static readonly FIURational Epsilon = new FIURational(1u, UInt32.MaxValue); + + /// + /// Initializes a new instance based on the specified parameters. + /// + /// The numerator. + /// The denominator. + public FIURational(uint n, uint d) + { + numerator = n; + denominator = d; + Normalize(); + } + + /// + /// Initializes a new instance based on the specified parameters. + /// + /// The tag to read the data from. + public unsafe FIURational(FITAG tag) + { + switch (FreeImage.GetTagType(tag)) + { + case FREE_IMAGE_MDTYPE.FIDT_RATIONAL: + uint* pvalue = (uint*)FreeImage.GetTagValue(tag); + numerator = pvalue[0]; + denominator = pvalue[1]; + Normalize(); + return; + default: + throw new ArgumentException("tag"); + } + } + + /// + ///Initializes a new instance based on the specified parameters. + /// + /// The value to convert into a fraction. + /// + /// cannot be converted into a fraction + /// represented by two unsigned integer values. + public FIURational(decimal value) + { + try + { + if (value < 0) + { + throw new OverflowException("value"); + } + try + { + int[] contFract = CreateContinuedFraction(value); + CreateFraction(contFract, out numerator, out denominator); + Normalize(); + } + catch + { + numerator = 0; + denominator = 1; + } + if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) + { + int maxDen = (Int32.MaxValue / (int)value) - 2; + maxDen = maxDen < 10000 ? maxDen : 10000; + ApproximateFraction(value, maxDen, out numerator, out denominator); + Normalize(); + if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) + { + throw new OverflowException("Unable to convert value into a fraction"); + } + } + Normalize(); + } + catch (Exception ex) + { + throw new OverflowException("Unable to calculate fraction.", ex); + } + } + + /// + /// The numerator of the fraction. + /// + public uint Numerator + { + get { return numerator; } + } + + /// + /// The denominator of the fraction. + /// + public uint Denominator + { + get { return denominator; } + } + + /// + /// Returns the truncated value of the fraction. + /// + /// + public int Truncate() + { + return denominator > 0 ? (int)(numerator / denominator) : 0; + } + + /// + /// Returns whether the fraction is representing an integer value. + /// + public bool IsInteger + { + get + { + return (denominator == 1 || + (denominator != 0 && (numerator % denominator == 0)) || + (denominator == 0 && numerator == 0)); + } + } + + /// + /// Calculated the greatest common divisor of 'a' and 'b'. + /// + private static ulong Gcd(ulong a, ulong b) + { + ulong r; + while (b > 0) + { + r = a % b; + a = b; + b = r; + } + return a; + } + + /// + /// Calculated the smallest common multiple of 'a' and 'b'. + /// + private static ulong Scm(uint n, uint m) + { + return (ulong)n * (ulong)m / Gcd(n, m); + } + + /// + /// Normalizes the fraction. + /// + private void Normalize() + { + if (denominator == 0) + { + numerator = 0; + denominator = 1; + return; + } + + if (numerator != 1 && denominator != 1) + { + uint common = (uint)Gcd(numerator, denominator); + if (common != 1 && common != 0) + { + numerator /= common; + denominator /= common; + } + } + } + + /// + /// Normalizes a fraction. + /// + private static void Normalize(ref ulong numerator, ref ulong denominator) + { + if (denominator == 0) + { + numerator = 0; + denominator = 1; + } + else if (numerator != 1 && denominator != 1) + { + ulong common = Gcd(numerator, denominator); + if (common != 1) + { + numerator /= common; + denominator /= common; + } + } + } + + /// + /// Returns the digits after the point. + /// + private static int GetDigits(decimal value) + { + int result = 0; + value -= decimal.Truncate(value); + while (value != 0) + { + value *= 10; + value -= decimal.Truncate(value); + result++; + } + return result; + } + + /// + /// Creates a continued fraction of a decimal value. + /// + private static int[] CreateContinuedFraction(decimal value) + { + int precision = GetDigits(value); + decimal epsilon = 0.0000001m; + List list = new List(); + value = Math.Abs(value); + + byte b = 0; + + list.Add((int)value); + value -= ((int)value); + + while (value != 0m) + { + if (++b == byte.MaxValue || value < epsilon) + { + break; + } + value = 1m / value; + if (Math.Abs((Math.Round(value, precision - 1) - value)) < epsilon) + { + value = Math.Round(value, precision - 1); + } + list.Add((int)value); + value -= ((int)value); + } + return list.ToArray(); + } + + /// + /// Creates a fraction from a continued fraction. + /// + private static void CreateFraction(int[] continuedFraction, out uint numerator, out uint denominator) + { + numerator = 1; + denominator = 0; + uint temp; + + for (int i = continuedFraction.Length - 1; i > -1; i--) + { + temp = numerator; + numerator = (uint)(continuedFraction[i] * numerator + denominator); + denominator = temp; + } + } + + /// + /// Tries 'brute force' to approximate with a fraction. + /// + private static void ApproximateFraction(decimal value, int maxDen, out uint num, out uint den) + { + num = 0; + den = 0; + decimal bestDifference = 1m; + decimal currentDifference = -1m; + int digits = GetDigits(value); + + if (digits <= 9) + { + uint mul = 1; + for (int i = 1; i <= digits; i++) + { + mul *= 10; + } + if (mul <= maxDen) + { + num = (uint)(value * mul); + den = mul; + return; + } + } + + for (uint u = 1; u <= maxDen; u++) + { + uint numerator = (uint)Math.Floor(value * (decimal)u + 0.5m); + currentDifference = Math.Abs(value - (decimal)numerator / (decimal)u); + if (currentDifference < bestDifference) + { + num = numerator; + den = u; + bestDifference = currentDifference; + } + } + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return ((IConvertible)this).ToDouble(null).ToString(); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIURational) && (this == ((FIURational)obj))); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + #region Operators + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator +(FIURational value) + { + return value; + } + + /// + /// Returns the reciprocal value of this instance. + /// + public static FIURational operator ~(FIURational value) + { + uint temp = value.denominator; + value.denominator = value.numerator; + value.numerator = temp; + value.Normalize(); + return value; + } + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator ++(FIURational value) + { + checked + { + value.numerator += value.denominator; + } + return value; + } + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator --(FIURational value) + { + checked + { + value.numerator -= value.denominator; + } + return value; + } + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator +(FIURational left, FIURational right) + { + ulong numerator = 0; + ulong denominator = Scm(left.denominator, right.denominator); + numerator = (left.numerator * (denominator / left.denominator)) + + (right.numerator * (denominator / right.denominator)); + Normalize(ref numerator, ref denominator); + checked + { + return new FIURational((uint)numerator, (uint)denominator); + } + } + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator -(FIURational left, FIURational right) + { + checked + { + if (left.denominator != right.denominator) + { + uint denom = left.denominator; + left.numerator *= right.denominator; + left.denominator *= right.denominator; + right.numerator *= denom; + right.denominator *= denom; + } + left.numerator -= right.numerator; + left.Normalize(); + return left; + } + } + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator *(FIURational left, FIURational r2) + { + ulong numerator = left.numerator * r2.numerator; + ulong denominator = left.denominator * r2.denominator; + Normalize(ref numerator, ref denominator); + checked + { + return new FIURational((uint)numerator, (uint)denominator); + } + } + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator /(FIURational left, FIURational right) + { + uint temp = right.denominator; + right.denominator = right.numerator; + right.numerator = temp; + return left * right; + } + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator %(FIURational left, FIURational right) + { + right.Normalize(); + if (Math.Abs(right.numerator) < right.denominator) + return new FIURational(0, 0); + int div = (int)(left / right); + return left - (right * div); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator ==(FIURational left, FIURational right) + { + left.Normalize(); + right.Normalize(); + return (left.numerator == right.numerator) && (left.denominator == right.denominator); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator !=(FIURational left, FIURational right) + { + left.Normalize(); + right.Normalize(); + return (left.numerator != right.numerator) || (left.denominator != right.denominator); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator >(FIURational left, FIURational right) + { + ulong denominator = Scm(left.denominator, right.denominator); + return (left.numerator * (denominator / left.denominator)) > + (right.numerator * (denominator / right.denominator)); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator <(FIURational left, FIURational right) + { + ulong denominator = Scm(left.denominator, right.denominator); + return (left.numerator * (denominator / left.denominator)) < + (right.numerator * (denominator / right.denominator)); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator >=(FIURational left, FIURational right) + { + ulong denominator = Scm(left.denominator, right.denominator); + return (left.numerator * (denominator / left.denominator)) >= + (right.numerator * (denominator / right.denominator)); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator <=(FIURational left, FIURational right) + { + ulong denominator = Scm(left.denominator, right.denominator); + return (left.numerator * (denominator / left.denominator)) <= + (right.numerator * (denominator / right.denominator)); + } + + #endregion + + #region Conversions + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator bool(FIURational value) + { + return (value.numerator != 0); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator byte(FIURational value) + { + return (byte)(double)value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator char(FIURational value) + { + return (char)(double)value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator decimal(FIURational value) + { + return value.denominator == 0 ? 0m : (decimal)value.numerator / (decimal)value.denominator; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator double(FIURational value) + { + return value.denominator == 0 ? 0d : (double)value.numerator / (double)value.denominator; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator short(FIURational value) + { + return (short)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator int(FIURational value) + { + return (int)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator long(FIURational value) + { + return (byte)(double)value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator float(FIURational value) + { + return value.denominator == 0 ? 0f : (float)value.numerator / (float)value.denominator; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator sbyte(FIURational value) + { + return (sbyte)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator ushort(FIURational value) + { + return (ushort)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator uint(FIURational value) + { + return (uint)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator ulong(FIURational value) + { + return (ulong)(double)value; + } + + // + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIURational(bool value) + { + return new FIURational(value ? 1u : 0u, 1u); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIURational(byte value) + { + return new FIURational(value, 1); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIURational(char value) + { + return new FIURational(value, 1); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIURational(decimal value) + { + return new FIURational(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIURational(double value) + { + return new FIURational((decimal)value); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator FIURational(short value) + { + return new FIURational((uint)value, 1u); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator FIURational(int value) + { + return new FIURational((uint)value, 1u); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static explicit operator FIURational(long value) + { + return new FIURational((uint)value, 1u); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIURational(sbyte value) + { + return new FIURational((uint)value, 1u); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIURational(float value) + { + return new FIURational((decimal)value); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator FIURational(ushort value) + { + return new FIURational(value, 1); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static explicit operator FIURational(uint value) + { + return new FIURational(value, 1u); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static explicit operator FIURational(ulong value) + { + return new FIURational((uint)value, 1u); + } + + #endregion + + #region IConvertible Member + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Double; + } + + bool IConvertible.ToBoolean(IFormatProvider provider) + { + return (bool)this; + } + + byte IConvertible.ToByte(IFormatProvider provider) + { + return (byte)this; + } + + char IConvertible.ToChar(IFormatProvider provider) + { + return (char)this; + } + + DateTime IConvertible.ToDateTime(IFormatProvider provider) + { + return Convert.ToDateTime(((IConvertible)this).ToDouble(provider)); + } + + decimal IConvertible.ToDecimal(IFormatProvider provider) + { + return this; + } + + double IConvertible.ToDouble(IFormatProvider provider) + { + return this; + } + + short IConvertible.ToInt16(IFormatProvider provider) + { + return (short)this; + } + + int IConvertible.ToInt32(IFormatProvider provider) + { + return (int)this; + } + + long IConvertible.ToInt64(IFormatProvider provider) + { + return (long)this; + } + + sbyte IConvertible.ToSByte(IFormatProvider provider) + { + return (sbyte)this; + } + + float IConvertible.ToSingle(IFormatProvider provider) + { + return this; + } + + string IConvertible.ToString(IFormatProvider provider) + { + return ToString(((double)this).ToString(), provider); + } + + object IConvertible.ToType(Type conversionType, IFormatProvider provider) + { + return Convert.ChangeType(((IConvertible)this).ToDouble(provider), conversionType, provider); + } + + ushort IConvertible.ToUInt16(IFormatProvider provider) + { + return (ushort)this; + } + + uint IConvertible.ToUInt32(IFormatProvider provider) + { + return (uint)this; + } + + ulong IConvertible.ToUInt64(IFormatProvider provider) + { + return (ulong)this; + } + + #endregion + + #region IComparable Member + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIURational)) + { + throw new ArgumentException(); + } + return CompareTo((FIURational)obj); + } + + #endregion + + #region IFormattable Member + + /// + /// Formats the value of the current instance using the specified format. + /// + /// The String specifying the format to use. + /// The IFormatProvider to use to format the value. + /// A String containing the value of the current instance in the specified format. + public string ToString(string format, IFormatProvider formatProvider) + { + if (format == null) + { + format = ""; + } + return String.Format(formatProvider, format, ((IConvertible)this).ToDouble(formatProvider)); + } + + #endregion + + #region IEquatable Member + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FIURational other) + { + return (this == other); + } + + #endregion + + #region IComparable Member + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIURational other) + { + FIURational difference = this - other; + difference.Normalize(); + if (difference.numerator > 0) return 1; + if (difference.numerator < 0) return -1; + else return 0; + } + + #endregion + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/FreeImageIO.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/FreeImageIO.cs index af464d0..d42575e 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/FreeImageIO.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/FreeImageIO.cs @@ -1,66 +1,66 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.3 $ -// $Date: 2008/06/17 13:49:23 $ -// $Id: FreeImageIO.cs,v 1.3 2008/06/17 13:49:23 cklein05 Exp $ -// ========================================================== - -using System.Runtime.InteropServices; - -namespace FreeImageAPI.IO -{ - /// - /// Structure for implementing access to custom handles. - /// - [StructLayout(LayoutKind.Sequential)] - public struct FreeImageIO - { - /// - /// Delegate to the C++ function fread. - /// - public ReadProc readProc; - - /// - /// Delegate to the C++ function fwrite. - /// - public WriteProc writeProc; - - /// - /// Delegate to the C++ function fseek. - /// - public SeekProc seekProc; - - /// - /// Delegate to the C++ function ftell. - /// - public TellProc tellProc; - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.3 $ +// $Date: 2008/06/17 13:49:23 $ +// $Id: FreeImageIO.cs,v 1.3 2008/06/17 13:49:23 cklein05 Exp $ +// ========================================================== + +using System.Runtime.InteropServices; + +namespace FreeImageAPI.IO +{ + /// + /// Structure for implementing access to custom handles. + /// + [StructLayout(LayoutKind.Sequential)] + public struct FreeImageIO + { + /// + /// Delegate to the C++ function fread. + /// + public ReadProc readProc; + + /// + /// Delegate to the C++ function fwrite. + /// + public WriteProc writeProc; + + /// + /// Delegate to the C++ function fseek. + /// + public SeekProc seekProc; + + /// + /// Delegate to the C++ function ftell. + /// + public TellProc tellProc; + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/Plugin.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/Plugin.cs index 0148c45..8de1666 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/Plugin.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/Plugin.cs @@ -1,132 +1,132 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.3 $ -// $Date: 2008/06/17 13:48:22 $ -// $Id: Plugin.cs,v 1.3 2008/06/17 13:48:22 cklein05 Exp $ -// ========================================================== - -using System; -using System.Runtime.InteropServices; -using FreeImageAPI.Plugins; - -namespace FreeImageAPI.Plugins -{ - /// - /// The structure contains functionpointers that make up a FreeImage plugin. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct Plugin - { - /// - /// Delegate to a function that returns a string which describes - /// the plugins format. - /// - public FormatProc formatProc; - - /// - /// Delegate to a function that returns a string which contains - /// a more detailed description. - /// - public DescriptionProc descriptionProc; - - /// - /// Delegate to a function that returns a comma seperated list - /// of file extensions the plugin can read or write. - /// - public ExtensionListProc extensionListProc; - - /// - /// Delegate to a function that returns a regular expression that - /// can be used to idientify whether a file can be handled by the plugin. - /// - public RegExprProc regExprProc; - - /// - /// Delegate to a function that opens a file. - /// - public OpenProc openProc; - - /// - /// Delegate to a function that closes a previosly opened file. - /// - public CloseProc closeProc; - - /// - /// Delegate to a function that returns the number of pages of a multipage - /// bitmap if the plugin is capable of handling multipage bitmaps. - /// - public PageCountProc pageCountProc; - - /// - /// UNKNOWN - /// - public PageCapabilityProc pageCapabilityProc; - - /// - /// Delegate to a function that loads and decodes a bitmap into memory. - /// - public LoadProc loadProc; - - /// - /// Delegate to a function that saves a bitmap. - /// - public SaveProc saveProc; - - /// - /// Delegate to a function that determines whether the source is a valid image. - /// - public ValidateProc validateProc; - - /// - /// Delegate to a function that returns a string which contains - /// the plugin's mime type. - /// - public MimeProc mimeProc; - - /// - /// Delegate to a function that returns whether the plugin can handle the - /// specified color depth. - /// - public SupportsExportBPPProc supportsExportBPPProc; - - /// - /// Delegate to a function that returns whether the plugin can handle the - /// specified image type. - /// - public SupportsExportTypeProc supportsExportTypeProc; - - /// - /// Delegate to a function that returns whether the plugin can handle - /// ICC-Profiles. - /// - public SupportsICCProfilesProc supportsICCProfilesProc; - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.3 $ +// $Date: 2008/06/17 13:48:22 $ +// $Id: Plugin.cs,v 1.3 2008/06/17 13:48:22 cklein05 Exp $ +// ========================================================== + +using System; +using System.Runtime.InteropServices; +using FreeImageAPI.Plugins; + +namespace FreeImageAPI.Plugins +{ + /// + /// The structure contains functionpointers that make up a FreeImage plugin. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct Plugin + { + /// + /// Delegate to a function that returns a string which describes + /// the plugins format. + /// + public FormatProc formatProc; + + /// + /// Delegate to a function that returns a string which contains + /// a more detailed description. + /// + public DescriptionProc descriptionProc; + + /// + /// Delegate to a function that returns a comma seperated list + /// of file extensions the plugin can read or write. + /// + public ExtensionListProc extensionListProc; + + /// + /// Delegate to a function that returns a regular expression that + /// can be used to idientify whether a file can be handled by the plugin. + /// + public RegExprProc regExprProc; + + /// + /// Delegate to a function that opens a file. + /// + public OpenProc openProc; + + /// + /// Delegate to a function that closes a previosly opened file. + /// + public CloseProc closeProc; + + /// + /// Delegate to a function that returns the number of pages of a multipage + /// bitmap if the plugin is capable of handling multipage bitmaps. + /// + public PageCountProc pageCountProc; + + /// + /// UNKNOWN + /// + public PageCapabilityProc pageCapabilityProc; + + /// + /// Delegate to a function that loads and decodes a bitmap into memory. + /// + public LoadProc loadProc; + + /// + /// Delegate to a function that saves a bitmap. + /// + public SaveProc saveProc; + + /// + /// Delegate to a function that determines whether the source is a valid image. + /// + public ValidateProc validateProc; + + /// + /// Delegate to a function that returns a string which contains + /// the plugin's mime type. + /// + public MimeProc mimeProc; + + /// + /// Delegate to a function that returns whether the plugin can handle the + /// specified color depth. + /// + public SupportsExportBPPProc supportsExportBPPProc; + + /// + /// Delegate to a function that returns whether the plugin can handle the + /// specified image type. + /// + public SupportsExportTypeProc supportsExportTypeProc; + + /// + /// Delegate to a function that returns whether the plugin can handle + /// ICC-Profiles. + /// + public SupportsICCProfilesProc supportsICCProfilesProc; + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/RGBQUAD.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/RGBQUAD.cs index fce303e..a9f2287 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/RGBQUAD.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/RGBQUAD.cs @@ -1,342 +1,342 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.4 $ -// $Date: 2009/02/20 07:40:53 $ -// $Id: RGBQUAD.cs,v 1.4 2009/02/20 07:40:53 cklein05 Exp $ -// ========================================================== - -using System; -using System.Drawing; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The RGBQUAD structure describes a color consisting of relative - /// intensities of red, green, blue and alpha value. Each single color - /// component consumes 8 bits and so, takes values in the range from 0 to 255. - /// - /// - /// - /// The RGBQUAD structure provides access to an underlying Win32 RGBQUAD - /// structure. To determine the alpha, red, green or blue component of a color, - /// use the rgbReserved, rgbRed, rgbGreen or rgbBlue fields, respectively. - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the RGBQUAD structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the RGBQUAD structure and my be used in all situations which require - /// an RGBQUAD type. - /// - /// - /// Each color component rgbReserved, rgbRed, rgbGreen or rgbBlue of RGBQUAD - /// is translated into it's corresponding color component A, R, G or B of - /// by an one-to-one manner and vice versa. - /// - /// - /// Conversion from System.Drawing.Color to RGBQUAD - /// - /// RGBQUAD.component = Color.component - /// - /// Conversion from RGBQUAD to System.Drawing.Color - /// - /// Color.component = RGBQUAD.component - /// - /// The same conversion is also applied when the - /// property or the constructor - /// is invoked. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// RGBQUAD structure and the structure. - /// - /// RGBQUAD rgbq; - /// // Initialize the structure using a native .NET Color structure. - /// rgbq = new RGBQUAD(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// rgbq = Color.DarkSeaGreen; - /// // Convert the RGBQUAD instance into a native .NET Color - /// // using its implicit operator. - /// Color color = rgbq; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = rgbq.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Explicit)] - public struct RGBQUAD : IComparable, IComparable, IEquatable - { - /// - /// The blue color component. - /// - [FieldOffset(0)] - public byte rgbBlue; - - /// - /// The green color component. - /// - [FieldOffset(1)] - public byte rgbGreen; - - /// - /// The red color component. - /// - [FieldOffset(2)] - public byte rgbRed; - - /// - /// The alpha color component. - /// - [FieldOffset(3)] - public byte rgbReserved; - - /// - /// The color's value. - /// - [FieldOffset(0)] - public uint uintValue; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public RGBQUAD(Color color) - { - uintValue = 0u; - rgbBlue = color.B; - rgbGreen = color.G; - rgbRed = color.R; - rgbReserved = color.A; - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(RGBQUAD left, RGBQUAD right) - { - return (left.uintValue == right.uintValue); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(RGBQUAD left, RGBQUAD right) - { - return (left.uintValue != right.uintValue); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator RGBQUAD(Color value) - { - return new RGBQUAD(value); - } - - /// - /// Converts the value of a structure to a Color structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(RGBQUAD value) - { - return value.Color; - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator RGBQUAD(uint value) - { - RGBQUAD result = new RGBQUAD(); - result.uintValue = value; - return result; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator uint(RGBQUAD value) - { - return value.uintValue; - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb( - rgbReserved, - rgbRed, - rgbGreen, - rgbBlue); - } - set - { - rgbRed = value.R; - rgbGreen = value.G; - rgbBlue = value.B; - rgbReserved = value.A; - } - } - - /// - /// Converts an array of into an array of - /// . - /// - /// The array to convert. - /// An array of . - public static RGBQUAD[] ToRGBQUAD(Color[] array) - { - if (array == null) - return null; - - RGBQUAD[] result = new RGBQUAD[array.Length]; - for (int i = 0; i < array.Length; i++) - { - result[i] = array[i]; - } - return result; - } - - /// - /// Converts an array of into an array of - /// . - /// - /// The array to convert. - /// An array of . - public static Color[] ToColor(RGBQUAD[] array) - { - if (array == null) - return null; - - Color[] result = new Color[array.Length]; - for (int i = 0; i < array.Length; i++) - { - result[i] = array[i].Color; - } - return result; - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is RGBQUAD)) - { - throw new ArgumentException("obj"); - } - return CompareTo((RGBQUAD)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(RGBQUAD other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is RGBQUAD) && (this == ((RGBQUAD)obj))); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(RGBQUAD other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.4 $ +// $Date: 2009/02/20 07:40:53 $ +// $Id: RGBQUAD.cs,v 1.4 2009/02/20 07:40:53 cklein05 Exp $ +// ========================================================== + +using System; +using System.Drawing; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The RGBQUAD structure describes a color consisting of relative + /// intensities of red, green, blue and alpha value. Each single color + /// component consumes 8 bits and so, takes values in the range from 0 to 255. + /// + /// + /// + /// The RGBQUAD structure provides access to an underlying Win32 RGBQUAD + /// structure. To determine the alpha, red, green or blue component of a color, + /// use the rgbReserved, rgbRed, rgbGreen or rgbBlue fields, respectively. + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the RGBQUAD structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the RGBQUAD structure and my be used in all situations which require + /// an RGBQUAD type. + /// + /// + /// Each color component rgbReserved, rgbRed, rgbGreen or rgbBlue of RGBQUAD + /// is translated into it's corresponding color component A, R, G or B of + /// by an one-to-one manner and vice versa. + /// + /// + /// Conversion from System.Drawing.Color to RGBQUAD + /// + /// RGBQUAD.component = Color.component + /// + /// Conversion from RGBQUAD to System.Drawing.Color + /// + /// Color.component = RGBQUAD.component + /// + /// The same conversion is also applied when the + /// property or the constructor + /// is invoked. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// RGBQUAD structure and the structure. + /// + /// RGBQUAD rgbq; + /// // Initialize the structure using a native .NET Color structure. + /// rgbq = new RGBQUAD(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// rgbq = Color.DarkSeaGreen; + /// // Convert the RGBQUAD instance into a native .NET Color + /// // using its implicit operator. + /// Color color = rgbq; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = rgbq.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Explicit)] + public struct RGBQUAD : IComparable, IComparable, IEquatable + { + /// + /// The blue color component. + /// + [FieldOffset(0)] + public byte rgbBlue; + + /// + /// The green color component. + /// + [FieldOffset(1)] + public byte rgbGreen; + + /// + /// The red color component. + /// + [FieldOffset(2)] + public byte rgbRed; + + /// + /// The alpha color component. + /// + [FieldOffset(3)] + public byte rgbReserved; + + /// + /// The color's value. + /// + [FieldOffset(0)] + public uint uintValue; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public RGBQUAD(Color color) + { + uintValue = 0u; + rgbBlue = color.B; + rgbGreen = color.G; + rgbRed = color.R; + rgbReserved = color.A; + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(RGBQUAD left, RGBQUAD right) + { + return (left.uintValue == right.uintValue); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(RGBQUAD left, RGBQUAD right) + { + return (left.uintValue != right.uintValue); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator RGBQUAD(Color value) + { + return new RGBQUAD(value); + } + + /// + /// Converts the value of a structure to a Color structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(RGBQUAD value) + { + return value.Color; + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator RGBQUAD(uint value) + { + RGBQUAD result = new RGBQUAD(); + result.uintValue = value; + return result; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator uint(RGBQUAD value) + { + return value.uintValue; + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb( + rgbReserved, + rgbRed, + rgbGreen, + rgbBlue); + } + set + { + rgbRed = value.R; + rgbGreen = value.G; + rgbBlue = value.B; + rgbReserved = value.A; + } + } + + /// + /// Converts an array of into an array of + /// . + /// + /// The array to convert. + /// An array of . + public static RGBQUAD[] ToRGBQUAD(Color[] array) + { + if (array == null) + return null; + + RGBQUAD[] result = new RGBQUAD[array.Length]; + for (int i = 0; i < array.Length; i++) + { + result[i] = array[i]; + } + return result; + } + + /// + /// Converts an array of into an array of + /// . + /// + /// The array to convert. + /// An array of . + public static Color[] ToColor(RGBQUAD[] array) + { + if (array == null) + return null; + + Color[] result = new Color[array.Length]; + for (int i = 0; i < array.Length; i++) + { + result[i] = array[i].Color; + } + return result; + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is RGBQUAD)) + { + throw new ArgumentException("obj"); + } + return CompareTo((RGBQUAD)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(RGBQUAD other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is RGBQUAD) && (this == ((RGBQUAD)obj))); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(RGBQUAD other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/RGBTRIPLE.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/RGBTRIPLE.cs index feddcbf..01c5a9d 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/RGBTRIPLE.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/RGBTRIPLE.cs @@ -1,295 +1,295 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.3 $ -// $Date: 2009/02/20 07:41:08 $ -// $Id: RGBTRIPLE.cs,v 1.3 2009/02/20 07:41:08 cklein05 Exp $ -// ========================================================== - -using System; -using System.Drawing; -using System.Runtime.InteropServices; - -namespace FreeImageAPI -{ - /// - /// The RGBTRIPLE structure describes a color consisting of relative - /// intensities of red, green and blue value. Each single color component - /// consumes 8 bits and so, takes values in the range from 0 to 255. - /// - /// - /// - /// The RGBTRIPLE structure provides access to an underlying Win32 RGBTRIPLE - /// structure. To determine the red, green or blue component of a color, use the - /// rgbtRed, rgbtGreen or rgbtBlue fields, respectively. - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the RGBTRIPLE structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the RGBTRIPLE structure and my be used in all situations which require - /// an RGBTRIPLE type. - /// - /// - /// Each of the color components rgbtRed, rgbtGreen or rgbtBlue of RGBTRIPLE is - /// translated into it's corresponding color component R, G or B of - /// by an one-to-one manner and vice versa. - /// When converting from into RGBTRIPLE, the - /// color's alpha value is ignored and assumed to be 255 when converting from - /// RGBTRIPLE into , creating a fully - /// opaque color. - /// - /// - /// Conversion from System.Drawing.Color to RGBTRIPLE - /// - /// RGBTRIPLE.component = Color.component - /// - /// Conversion from RGBTRIPLE to System.Drawing.Color - /// - /// Color.component = RGBTRIPLE.component - /// - /// The same conversion is also applied when the - /// property or the constructor - /// is invoked. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// RGBTRIPLE structure and the structure. - /// - /// RGBTRIPLE rgbt; - /// // Initialize the structure using a native .NET Color structure. - /// rgbt = new RGBTRIPLE(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// rgbt = Color.DarkSeaGreen; - /// // Convert the RGBTRIPLE instance into a native .NET Color - /// // using its implicit operator. - /// Color color = rgbt; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = rgbt.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct RGBTRIPLE : IComparable, IComparable, IEquatable - { - /// - /// The blue color component. - /// - public byte rgbtBlue; - - /// - /// The green color component. - /// - public byte rgbtGreen; - - /// - /// The red color component. - /// - public byte rgbtRed; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public RGBTRIPLE(Color color) - { - rgbtBlue = color.B; - rgbtGreen = color.G; - rgbtRed = color.R; - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(RGBTRIPLE left, RGBTRIPLE right) - { - return - left.rgbtBlue == right.rgbtBlue && - left.rgbtGreen == right.rgbtGreen && - left.rgbtRed == right.rgbtRed; - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(RGBTRIPLE left, RGBTRIPLE right) - { - return !(left == right); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator RGBTRIPLE(Color value) - { - return new RGBTRIPLE(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(RGBTRIPLE value) - { - return value.Color; - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator RGBTRIPLE(uint value) - { - RGBTRIPLE result = new RGBTRIPLE(); - result.rgbtBlue = (byte)(value & 0xFF); - result.rgbtGreen = (byte)((value >> 8) & 0xFF); - result.rgbtRed = (byte)((value >> 16) & 0xFF); - return result; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator uint(RGBTRIPLE value) - { - return (uint)((value.rgbtRed << 16) | (value.rgbtGreen << 8) | (value.rgbtBlue)); - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb( - rgbtRed, - rgbtGreen, - rgbtBlue); - } - set - { - rgbtBlue = value.B; - rgbtGreen = value.G; - rgbtRed = value.R; - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is RGBTRIPLE)) - { - throw new ArgumentException("obj"); - } - return CompareTo((RGBTRIPLE)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(RGBTRIPLE other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is RGBTRIPLE) && (this == ((RGBTRIPLE)obj))); - } - - /// - /// Tests whether the specified structure is equivalent to this - /// structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(RGBTRIPLE other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.3 $ +// $Date: 2009/02/20 07:41:08 $ +// $Id: RGBTRIPLE.cs,v 1.3 2009/02/20 07:41:08 cklein05 Exp $ +// ========================================================== + +using System; +using System.Drawing; +using System.Runtime.InteropServices; + +namespace FreeImageAPI +{ + /// + /// The RGBTRIPLE structure describes a color consisting of relative + /// intensities of red, green and blue value. Each single color component + /// consumes 8 bits and so, takes values in the range from 0 to 255. + /// + /// + /// + /// The RGBTRIPLE structure provides access to an underlying Win32 RGBTRIPLE + /// structure. To determine the red, green or blue component of a color, use the + /// rgbtRed, rgbtGreen or rgbtBlue fields, respectively. + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the RGBTRIPLE structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the RGBTRIPLE structure and my be used in all situations which require + /// an RGBTRIPLE type. + /// + /// + /// Each of the color components rgbtRed, rgbtGreen or rgbtBlue of RGBTRIPLE is + /// translated into it's corresponding color component R, G or B of + /// by an one-to-one manner and vice versa. + /// When converting from into RGBTRIPLE, the + /// color's alpha value is ignored and assumed to be 255 when converting from + /// RGBTRIPLE into , creating a fully + /// opaque color. + /// + /// + /// Conversion from System.Drawing.Color to RGBTRIPLE + /// + /// RGBTRIPLE.component = Color.component + /// + /// Conversion from RGBTRIPLE to System.Drawing.Color + /// + /// Color.component = RGBTRIPLE.component + /// + /// The same conversion is also applied when the + /// property or the constructor + /// is invoked. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// RGBTRIPLE structure and the structure. + /// + /// RGBTRIPLE rgbt; + /// // Initialize the structure using a native .NET Color structure. + /// rgbt = new RGBTRIPLE(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// rgbt = Color.DarkSeaGreen; + /// // Convert the RGBTRIPLE instance into a native .NET Color + /// // using its implicit operator. + /// Color color = rgbt; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = rgbt.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct RGBTRIPLE : IComparable, IComparable, IEquatable + { + /// + /// The blue color component. + /// + public byte rgbtBlue; + + /// + /// The green color component. + /// + public byte rgbtGreen; + + /// + /// The red color component. + /// + public byte rgbtRed; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public RGBTRIPLE(Color color) + { + rgbtBlue = color.B; + rgbtGreen = color.G; + rgbtRed = color.R; + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(RGBTRIPLE left, RGBTRIPLE right) + { + return + left.rgbtBlue == right.rgbtBlue && + left.rgbtGreen == right.rgbtGreen && + left.rgbtRed == right.rgbtRed; + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(RGBTRIPLE left, RGBTRIPLE right) + { + return !(left == right); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator RGBTRIPLE(Color value) + { + return new RGBTRIPLE(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(RGBTRIPLE value) + { + return value.Color; + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator RGBTRIPLE(uint value) + { + RGBTRIPLE result = new RGBTRIPLE(); + result.rgbtBlue = (byte)(value & 0xFF); + result.rgbtGreen = (byte)((value >> 8) & 0xFF); + result.rgbtRed = (byte)((value >> 16) & 0xFF); + return result; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator uint(RGBTRIPLE value) + { + return (uint)((value.rgbtRed << 16) | (value.rgbtGreen << 8) | (value.rgbtBlue)); + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb( + rgbtRed, + rgbtGreen, + rgbtBlue); + } + set + { + rgbtBlue = value.B; + rgbtGreen = value.G; + rgbtRed = value.R; + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is RGBTRIPLE)) + { + throw new ArgumentException("obj"); + } + return CompareTo((RGBTRIPLE)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(RGBTRIPLE other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is RGBTRIPLE) && (this == ((RGBTRIPLE)obj))); + } + + /// + /// Tests whether the specified structure is equivalent to this + /// structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(RGBTRIPLE other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Library/Structs/fi_handle.cs b/Wrapper/FreeImage.NET/cs/Library/Structs/fi_handle.cs index 7547d78..d2d1188 100644 --- a/Wrapper/FreeImage.NET/cs/Library/Structs/fi_handle.cs +++ b/Wrapper/FreeImage.NET/cs/Library/Structs/fi_handle.cs @@ -1,256 +1,256 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// CVS -// $Revision: 1.7 $ -// $Date: 2009/02/20 07:41:08 $ -// $Id: fi_handle.cs,v 1.7 2009/02/20 07:41:08 cklein05 Exp $ -// ========================================================== - -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; - -namespace FreeImageAPI.IO -{ - /// - /// Wrapper for a custom handle. - /// - /// - /// The fi_handle of FreeImage in C++ is a simple pointer, but in .NET - /// it's not that simple. This wrapper uses fi_handle in two different ways. - /// - /// We implement a new plugin and FreeImage gives us a handle (pointer) that - /// we can simply pass through to the given functions in a 'FreeImageIO' - /// structure. - /// But when we want to use LoadFromhandle or SaveToHandle we need - /// a fi_handle (that we receive again in our own functions). - /// This handle is for example a stream (see LoadFromStream / SaveToStream) - /// that we want to work with. To know which stream a read/write is meant for - /// we could use a hash value that the wrapper itself handles or we can - /// go the unmanaged way of using a handle. - /// Therefor we use a to receive a unique pointer that we can - /// convert back into a .NET object. - /// When the fi_handle instance is no longer needed the instance must be disposed - /// by the creater manually! It is recommended to use the using statement to - /// be sure the instance is always disposed: - /// - /// - /// using (fi_handle handle = new fi_handle(object)) - /// { - /// callSomeFunctions(handle); - /// } - /// - /// - /// What does that mean? - /// If we get a fi_handle from unmanaged code we get a pointer to unmanaged - /// memory that we do not have to care about, and just pass ist back to FreeImage. - /// If we have to create a handle our own we use the standard constructur - /// that fills the with an pointer that represents the given object. - /// With calling the is used to retrieve the original - /// object we passed through the constructor. - /// - /// This way we can implement a fi_handle that works with managed an unmanaged - /// code. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct fi_handle : IComparable, IComparable, IEquatable, IDisposable - { - /// - /// The handle to wrap. - /// - public IntPtr handle; - - /// - /// Initializes a new instance wrapping a managed object. - /// - /// The object to wrap. - /// - /// is null. - public fi_handle(object obj) - { - if (obj == null) - { - throw new ArgumentNullException("obj"); - } - GCHandle gch = GCHandle.Alloc(obj, GCHandleType.Normal); - handle = GCHandle.ToIntPtr(gch); - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(fi_handle left, fi_handle right) - { - return (left.handle == right.handle); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(fi_handle left, fi_handle right) - { - return (left.handle != right.handle); - } - - /// - /// Gets whether the pointer is a null pointer. - /// - public bool IsNull - { - get - { - return (handle == IntPtr.Zero); - } - } - - /// - /// Returns the object assigned to the handle in case this instance - /// was created by managed code. - /// - /// assigned to this handle or null on failure. - internal object GetObject() - { - object result = null; - if (handle != IntPtr.Zero) - { - try - { - result = GCHandle.FromIntPtr(handle).Target; - } - catch - { - } - } - return result; - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return handle.ToString(); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return handle.GetHashCode(); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is fi_handle) && (this == ((fi_handle)obj))); - } - - /// - /// Indicates whether the current object is equal to another object of the same type. - /// - /// An object to compare with this object. - /// True if the current object is equal to the other parameter; otherwise, false. - public bool Equals(fi_handle other) - { - return (this == other); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is fi_handle)) - { - throw new ArgumentException("obj"); - } - return CompareTo((fi_handle)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(fi_handle other) - { - return handle.ToInt64().CompareTo(other.handle.ToInt64()); - } - - /// - /// Releases all resources used by the instance. - /// - public void Dispose() - { - if (this.handle != IntPtr.Zero) - { - try - { - GCHandle.FromIntPtr(handle).Free(); - } - catch - { - } - finally - { - this.handle = IntPtr.Zero; - } - } - } - } +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// CVS +// $Revision: 1.7 $ +// $Date: 2009/02/20 07:41:08 $ +// $Id: fi_handle.cs,v 1.7 2009/02/20 07:41:08 cklein05 Exp $ +// ========================================================== + +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; + +namespace FreeImageAPI.IO +{ + /// + /// Wrapper for a custom handle. + /// + /// + /// The fi_handle of FreeImage in C++ is a simple pointer, but in .NET + /// it's not that simple. This wrapper uses fi_handle in two different ways. + /// + /// We implement a new plugin and FreeImage gives us a handle (pointer) that + /// we can simply pass through to the given functions in a 'FreeImageIO' + /// structure. + /// But when we want to use LoadFromhandle or SaveToHandle we need + /// a fi_handle (that we receive again in our own functions). + /// This handle is for example a stream (see LoadFromStream / SaveToStream) + /// that we want to work with. To know which stream a read/write is meant for + /// we could use a hash value that the wrapper itself handles or we can + /// go the unmanaged way of using a handle. + /// Therefor we use a to receive a unique pointer that we can + /// convert back into a .NET object. + /// When the fi_handle instance is no longer needed the instance must be disposed + /// by the creater manually! It is recommended to use the using statement to + /// be sure the instance is always disposed: + /// + /// + /// using (fi_handle handle = new fi_handle(object)) + /// { + /// callSomeFunctions(handle); + /// } + /// + /// + /// What does that mean? + /// If we get a fi_handle from unmanaged code we get a pointer to unmanaged + /// memory that we do not have to care about, and just pass ist back to FreeImage. + /// If we have to create a handle our own we use the standard constructur + /// that fills the with an pointer that represents the given object. + /// With calling the is used to retrieve the original + /// object we passed through the constructor. + /// + /// This way we can implement a fi_handle that works with managed an unmanaged + /// code. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct fi_handle : IComparable, IComparable, IEquatable, IDisposable + { + /// + /// The handle to wrap. + /// + public IntPtr handle; + + /// + /// Initializes a new instance wrapping a managed object. + /// + /// The object to wrap. + /// + /// is null. + public fi_handle(object obj) + { + if (obj == null) + { + throw new ArgumentNullException("obj"); + } + GCHandle gch = GCHandle.Alloc(obj, GCHandleType.Normal); + handle = GCHandle.ToIntPtr(gch); + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(fi_handle left, fi_handle right) + { + return (left.handle == right.handle); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(fi_handle left, fi_handle right) + { + return (left.handle != right.handle); + } + + /// + /// Gets whether the pointer is a null pointer. + /// + public bool IsNull + { + get + { + return (handle == IntPtr.Zero); + } + } + + /// + /// Returns the object assigned to the handle in case this instance + /// was created by managed code. + /// + /// assigned to this handle or null on failure. + internal object GetObject() + { + object result = null; + if (handle != IntPtr.Zero) + { + try + { + result = GCHandle.FromIntPtr(handle).Target; + } + catch + { + } + } + return result; + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return handle.ToString(); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return handle.GetHashCode(); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is fi_handle) && (this == ((fi_handle)obj))); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// An object to compare with this object. + /// True if the current object is equal to the other parameter; otherwise, false. + public bool Equals(fi_handle other) + { + return (this == other); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is fi_handle)) + { + throw new ArgumentException("obj"); + } + return CompareTo((fi_handle)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(fi_handle other) + { + return handle.ToInt64().CompareTo(other.handle.ToInt64()); + } + + /// + /// Releases all resources used by the instance. + /// + public void Dispose() + { + if (this.handle != IntPtr.Zero) + { + try + { + GCHandle.FromIntPtr(handle).Free(); + } + catch + { + } + finally + { + this.handle = IntPtr.Zero; + } + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 01 - Loading and saving/Program.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 01 - Loading and saving/Program.cs index 4ca025f..5b3a6b0 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 01 - Loading and saving/Program.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 01 - Loading and saving/Program.cs @@ -1,179 +1,179 @@ -using System; -using System.IO; -using FreeImageAPI; -using System.Collections.Generic; -using System.Runtime.Serialization.Formatters.Binary; -using System.Drawing; -using System.Drawing.Imaging; -using System.Runtime.InteropServices; - -namespace Sample01 -{ - class Program - { - static void Main(string[] args) - { - // Check if FreeImage.dll is available (can be in %path%). - if (!FreeImage.IsAvailable()) - { - Console.WriteLine("FreeImage.dll seems to be missing. Aborting."); - return; - } - - Sample sample = new Sample(); - // This example shows the basic loading and saving operations offered by FreeImage. - sample.Example01(); - - // This example shows a more comfortable way offered by the .NET Wrapper. - sample.Example02(); - - // This example shows the FreeImage-Errormessage-Callback - sample.Example03(); - } - } - - public class Sample - { - const string fileName = @"Sample.jpg"; - const string outFileName = @"Sample.tif"; - FIBITMAP dib = new FIBITMAP(); - string message = null; - - public void Example01() - { - if (!File.Exists(fileName)) - { - Console.WriteLine(fileName + " does not exist. Aborting."); - return; - } - - // Try to unload the bitmap handle (in case it is not null). - // Always assert that a handle (like dib) is unloaded before it is reused, because - // on unmanaged side there is no garbage collector that will clean up unreferenced - // objects. - // The following code will produce a memory leak (in case the bitmap is loaded - // successfully) because the handle to the first bitmap is lost: - // dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, fileName, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); - // dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, fileName, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); - if (!dib.IsNull) - FreeImage.Unload(dib); - - // Loading a sample bitmap. In this case it's a .jpg file. 'Load' requires the file - // format or the loading process will fail. An additional flag (the default value is - // 'DEFAULT') can be set to enable special loading options. - dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, fileName, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); - - // Check if the handle is null which means the bitmap could not be loaded. - if (dib.IsNull) - { - Console.WriteLine("Loading bitmap failed. Aborting."); - // Check whether there was an error message. - return; - } - - // Try flipping the bitmap. - if (!FreeImage.FlipHorizontal(dib)) - { - Console.WriteLine("Unable to flip bitmap."); - // Check whether there was an error message. - } - - // Store the bitmap back to disk. Again the desired format is needed. In this case the format is 'TIFF'. - // An output filename has to be chosen (which will be overwritten without a warning). - // A flag can be provided to enable pluginfunctions (compression is this case). - FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, dib, outFileName, FREE_IMAGE_SAVE_FLAGS.TIFF_DEFLATE); - - // The bitmap was saved to disk but is still allocated in memory, so the handle has to be freed. - if (!dib.IsNull) - FreeImage.Unload(dib); - - // Make sure to set the handle to null so that it is clear that the handle is not pointing to a bitmap. - dib.SetNull(); - } - - public void Example02() - { - // 'UnloadEx' is a comfortable way of unloading a bitmap. The coder can call 'UnloadEx' even - // when the handle is pointing to null (in this case nothing will happen). In case the handle - // is valid (valid means that it is NOT pointing to null) the bitmap will be unloaded and the - // handle will be set to null manually. - FreeImage.UnloadEx(ref dib); - - // 'LoadEx' is a comfortable way of loading a bitmap. 'LoadEx' tries to find out the format of - // the file and will use this to load it. It will use DEFAULT loading values. - dib = FreeImage.LoadEx(fileName); - - // Check if the handle is null which means the bitmap could not be loaded. - if (dib.IsNull) - { - Console.WriteLine("Loading bitmap failed. Aborting."); - return; - } - - // 'SaveEx' (like 'LoadEx') will try to save the bitmap with default values. - // Before saving the bitmap, 'SaveEx' checks whether the extension is valid for the file type - // and if the plugin can use the colordepth of the bitmap. If not it will automatically convert - // the bitmap into the next best colordepth and save it. - if (!FreeImage.SaveEx(ref dib, @"Sample.gif", false)) - { - Console.WriteLine("Saving bitmap failed."); - } - - // The handle is still valid. - if (!FreeImage.SaveEx( - ref dib, - @"Sample", // No extension was selected so let 'SaveEx' decide. - FREE_IMAGE_FORMAT.FIF_PNG, // A format is needed this time. - FREE_IMAGE_SAVE_FLAGS.DEFAULT, // PNG has no options so use default. - FREE_IMAGE_COLOR_DEPTH.FICD_04_BPP, // 4bpp as result color depth. - true)) // We're done so unload - { - // SaveEx will not unload the bitmap in case saving failed. - // This way possible operations done to the bitmaps aren't lost. - FreeImage.UnloadEx(ref dib); - } - } - - public void Example03() - { - // Safely unload to prevent memory leak. - FreeImage.UnloadEx(ref dib); - - // Load the example bitmap. - dib = FreeImage.LoadEx(fileName); - - // Check whether loading succeeded. - if (dib.IsNull) - { - return; - } - - // Add this class to the callback event. - FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); - - // Try to save the bitmap as a gif - if (!FreeImage.Save(FREE_IMAGE_FORMAT.FIF_GIF, dib, @"Sample_fail.gif", FREE_IMAGE_SAVE_FLAGS.DEFAULT)) - { - // Saving failed - // Check whether there was an error callback - if (message != null) - { - // Print the message and delete it. - Console.WriteLine("Error message recieved: {0}", message); - message = null; - } - } - - // Unload bitmap. - FreeImage.UnloadEx(ref dib); - - // Remove this class from the callback event. - FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); - } - - void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) - { - this.message = message; - } - } +using System; +using System.IO; +using FreeImageAPI; +using System.Collections.Generic; +using System.Runtime.Serialization.Formatters.Binary; +using System.Drawing; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; + +namespace Sample01 +{ + class Program + { + static void Main(string[] args) + { + // Check if FreeImage.dll is available (can be in %path%). + if (!FreeImage.IsAvailable()) + { + Console.WriteLine("FreeImage.dll seems to be missing. Aborting."); + return; + } + + Sample sample = new Sample(); + // This example shows the basic loading and saving operations offered by FreeImage. + sample.Example01(); + + // This example shows a more comfortable way offered by the .NET Wrapper. + sample.Example02(); + + // This example shows the FreeImage-Errormessage-Callback + sample.Example03(); + } + } + + public class Sample + { + const string fileName = @"Sample.jpg"; + const string outFileName = @"Sample.tif"; + FIBITMAP dib = new FIBITMAP(); + string message = null; + + public void Example01() + { + if (!File.Exists(fileName)) + { + Console.WriteLine(fileName + " does not exist. Aborting."); + return; + } + + // Try to unload the bitmap handle (in case it is not null). + // Always assert that a handle (like dib) is unloaded before it is reused, because + // on unmanaged side there is no garbage collector that will clean up unreferenced + // objects. + // The following code will produce a memory leak (in case the bitmap is loaded + // successfully) because the handle to the first bitmap is lost: + // dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, fileName, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); + // dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, fileName, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); + if (!dib.IsNull) + FreeImage.Unload(dib); + + // Loading a sample bitmap. In this case it's a .jpg file. 'Load' requires the file + // format or the loading process will fail. An additional flag (the default value is + // 'DEFAULT') can be set to enable special loading options. + dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, fileName, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); + + // Check if the handle is null which means the bitmap could not be loaded. + if (dib.IsNull) + { + Console.WriteLine("Loading bitmap failed. Aborting."); + // Check whether there was an error message. + return; + } + + // Try flipping the bitmap. + if (!FreeImage.FlipHorizontal(dib)) + { + Console.WriteLine("Unable to flip bitmap."); + // Check whether there was an error message. + } + + // Store the bitmap back to disk. Again the desired format is needed. In this case the format is 'TIFF'. + // An output filename has to be chosen (which will be overwritten without a warning). + // A flag can be provided to enable pluginfunctions (compression is this case). + FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, dib, outFileName, FREE_IMAGE_SAVE_FLAGS.TIFF_DEFLATE); + + // The bitmap was saved to disk but is still allocated in memory, so the handle has to be freed. + if (!dib.IsNull) + FreeImage.Unload(dib); + + // Make sure to set the handle to null so that it is clear that the handle is not pointing to a bitmap. + dib.SetNull(); + } + + public void Example02() + { + // 'UnloadEx' is a comfortable way of unloading a bitmap. The coder can call 'UnloadEx' even + // when the handle is pointing to null (in this case nothing will happen). In case the handle + // is valid (valid means that it is NOT pointing to null) the bitmap will be unloaded and the + // handle will be set to null manually. + FreeImage.UnloadEx(ref dib); + + // 'LoadEx' is a comfortable way of loading a bitmap. 'LoadEx' tries to find out the format of + // the file and will use this to load it. It will use DEFAULT loading values. + dib = FreeImage.LoadEx(fileName); + + // Check if the handle is null which means the bitmap could not be loaded. + if (dib.IsNull) + { + Console.WriteLine("Loading bitmap failed. Aborting."); + return; + } + + // 'SaveEx' (like 'LoadEx') will try to save the bitmap with default values. + // Before saving the bitmap, 'SaveEx' checks whether the extension is valid for the file type + // and if the plugin can use the colordepth of the bitmap. If not it will automatically convert + // the bitmap into the next best colordepth and save it. + if (!FreeImage.SaveEx(ref dib, @"Sample.gif", false)) + { + Console.WriteLine("Saving bitmap failed."); + } + + // The handle is still valid. + if (!FreeImage.SaveEx( + ref dib, + @"Sample", // No extension was selected so let 'SaveEx' decide. + FREE_IMAGE_FORMAT.FIF_PNG, // A format is needed this time. + FREE_IMAGE_SAVE_FLAGS.DEFAULT, // PNG has no options so use default. + FREE_IMAGE_COLOR_DEPTH.FICD_04_BPP, // 4bpp as result color depth. + true)) // We're done so unload + { + // SaveEx will not unload the bitmap in case saving failed. + // This way possible operations done to the bitmaps aren't lost. + FreeImage.UnloadEx(ref dib); + } + } + + public void Example03() + { + // Safely unload to prevent memory leak. + FreeImage.UnloadEx(ref dib); + + // Load the example bitmap. + dib = FreeImage.LoadEx(fileName); + + // Check whether loading succeeded. + if (dib.IsNull) + { + return; + } + + // Add this class to the callback event. + FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); + + // Try to save the bitmap as a gif + if (!FreeImage.Save(FREE_IMAGE_FORMAT.FIF_GIF, dib, @"Sample_fail.gif", FREE_IMAGE_SAVE_FLAGS.DEFAULT)) + { + // Saving failed + // Check whether there was an error callback + if (message != null) + { + // Print the message and delete it. + Console.WriteLine("Error message recieved: {0}", message); + message = null; + } + } + + // Unload bitmap. + FreeImage.UnloadEx(ref dib); + + // Remove this class from the callback event. + FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); + } + + void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) + { + this.message = message; + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 01 - Loading and saving/Properties/AssemblyInfo.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 01 - Loading and saving/Properties/AssemblyInfo.cs index 0a5e51f..68bdc62 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 01 - Loading and saving/Properties/AssemblyInfo.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 01 - Loading and saving/Properties/AssemblyInfo.cs @@ -1,16 +1,16 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("ac0569fe-c021-4f40-bfe9-275baf0fd21a")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: Guid("ac0569fe-c021-4f40-bfe9-275baf0fd21a")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 02 - Multipaged bitmaps/Program.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 02 - Multipaged bitmaps/Program.cs index 306cce0..dccc2d8 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 02 - Multipaged bitmaps/Program.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 02 - Multipaged bitmaps/Program.cs @@ -1,140 +1,140 @@ -using System; -using System.IO; -using FreeImageAPI; - -namespace Sample02 -{ - class Program - { - static void Main(string[] args) - { - // Check if FreeImage.dll is available (can be in %path%). - if (!FreeImage.IsAvailable()) - { - Console.WriteLine("FreeImage.dll seems to be missing. Aborting."); - return; - } - - Sample sample = new Sample(); - sample.Example(); - } - } - - public class Sample - { - const string fileName = @"multipaged.tif"; - FIMULTIBITMAP dib = new FIMULTIBITMAP(); - Random rand = new Random(); - - public void Example() - { - if (!File.Exists(fileName)) - { - Console.WriteLine("File not found. Aborting."); - return; - } - - // Load the multipaged bitmap. - // 'OpenMultiBitmapEx' tries to find the correct file format, loads the bitmap - // with default options, with write support and does not use caching. - dib = FreeImage.OpenMultiBitmapEx(fileName); - - // Check whether loading succeeded. - if (dib.IsNull) - { - Console.WriteLine("File could not be loaded. Aborting."); - return; - } - - // Get the number of bitmaps the multipaged bitmap contains. - int count = FreeImage.GetPageCount(dib); - - // Multipaged bitmaps consist of multiple single FIBITMAPs - FIBITMAP page = new FIBITMAP(); - - // There are bitmaps we can work with. - if (count > 0) - { - // Lock a random bitmap to work with. - page = FreeImage.LockPage(dib, rand.Next(0, count)); - } - - // Check whether locking succeeded. - if (page.IsNull) - { - // Locking failed. Unload the bitmap and return. - FreeImage.CloseMultiBitmapEx(ref dib); - return; - } - - // Get a list of locked pages. This can be usefull to check whether a page has already been locked. - int[] lockedPages = FreeImage.GetLockedPages(dib); - - // Lets modify the page. - if (FreeImage.AdjustGamma(page, 2d)) - { - Console.WriteLine("Successfully changed gamma of page {0}.", lockedPages[0]); - } - else - { - Console.WriteLine("Failed to adjust gamma ..."); - } - - // Print out the list of locked pages - foreach (int i in lockedPages) - Console.WriteLine("Page {0} is locked.", i); - - // Use 'UnlockPage' instead of 'Unload' to free the page. Set the third parameter to 'true' - // so that FreeImage can store the changed page within the multipaged bitmap. - FreeImage.UnlockPage(dib, page, true); - - // Retieve the list again to see whether unlocking succeeded. - lockedPages = FreeImage.GetLockedPages(dib); - - // No output should be produced here. - foreach (int i in lockedPages) - Console.WriteLine("Page {0} is still locked.", i); - - // If there are more than one page we can swap them - if (count > 1) - { - if (!FreeImage.MovePage(dib, 1, 0)) - { - Console.WriteLine("Swapping pages failed."); - } - } - - if (count > 2) - { - // Lock page 2 - page = FreeImage.LockPage(dib, 2); - if (!page.IsNull) - { - // Clone the page for later appending - FIBITMAP temp = FreeImage.Clone(page); - - // Unlock the page again - FreeImage.UnlockPage(dib, page, false); - - // Delete the page form the multipaged bitmap - FreeImage.DeletePage(dib, 2); - - // Append the clone again - FreeImage.AppendPage(dib, temp); - - // Check whether the number of pages is still the same - Console.WriteLine("Pages before: {0}. Pages after: {1}", count, FreeImage.GetPageCount(dib)); - - // Unload clone to prevent memory leak - FreeImage.UnloadEx(ref temp); - } - } - - // We are done and close the multipaged bitmap. - if (!FreeImage.CloseMultiBitmapEx(ref dib)) - { - Console.WriteLine("Closing bitmap failed!"); - } - } - } -} +using System; +using System.IO; +using FreeImageAPI; + +namespace Sample02 +{ + class Program + { + static void Main(string[] args) + { + // Check if FreeImage.dll is available (can be in %path%). + if (!FreeImage.IsAvailable()) + { + Console.WriteLine("FreeImage.dll seems to be missing. Aborting."); + return; + } + + Sample sample = new Sample(); + sample.Example(); + } + } + + public class Sample + { + const string fileName = @"multipaged.tif"; + FIMULTIBITMAP dib = new FIMULTIBITMAP(); + Random rand = new Random(); + + public void Example() + { + if (!File.Exists(fileName)) + { + Console.WriteLine("File not found. Aborting."); + return; + } + + // Load the multipaged bitmap. + // 'OpenMultiBitmapEx' tries to find the correct file format, loads the bitmap + // with default options, with write support and does not use caching. + dib = FreeImage.OpenMultiBitmapEx(fileName); + + // Check whether loading succeeded. + if (dib.IsNull) + { + Console.WriteLine("File could not be loaded. Aborting."); + return; + } + + // Get the number of bitmaps the multipaged bitmap contains. + int count = FreeImage.GetPageCount(dib); + + // Multipaged bitmaps consist of multiple single FIBITMAPs + FIBITMAP page = new FIBITMAP(); + + // There are bitmaps we can work with. + if (count > 0) + { + // Lock a random bitmap to work with. + page = FreeImage.LockPage(dib, rand.Next(0, count)); + } + + // Check whether locking succeeded. + if (page.IsNull) + { + // Locking failed. Unload the bitmap and return. + FreeImage.CloseMultiBitmapEx(ref dib); + return; + } + + // Get a list of locked pages. This can be usefull to check whether a page has already been locked. + int[] lockedPages = FreeImage.GetLockedPages(dib); + + // Lets modify the page. + if (FreeImage.AdjustGamma(page, 2d)) + { + Console.WriteLine("Successfully changed gamma of page {0}.", lockedPages[0]); + } + else + { + Console.WriteLine("Failed to adjust gamma ..."); + } + + // Print out the list of locked pages + foreach (int i in lockedPages) + Console.WriteLine("Page {0} is locked.", i); + + // Use 'UnlockPage' instead of 'Unload' to free the page. Set the third parameter to 'true' + // so that FreeImage can store the changed page within the multipaged bitmap. + FreeImage.UnlockPage(dib, page, true); + + // Retieve the list again to see whether unlocking succeeded. + lockedPages = FreeImage.GetLockedPages(dib); + + // No output should be produced here. + foreach (int i in lockedPages) + Console.WriteLine("Page {0} is still locked.", i); + + // If there are more than one page we can swap them + if (count > 1) + { + if (!FreeImage.MovePage(dib, 1, 0)) + { + Console.WriteLine("Swapping pages failed."); + } + } + + if (count > 2) + { + // Lock page 2 + page = FreeImage.LockPage(dib, 2); + if (!page.IsNull) + { + // Clone the page for later appending + FIBITMAP temp = FreeImage.Clone(page); + + // Unlock the page again + FreeImage.UnlockPage(dib, page, false); + + // Delete the page form the multipaged bitmap + FreeImage.DeletePage(dib, 2); + + // Append the clone again + FreeImage.AppendPage(dib, temp); + + // Check whether the number of pages is still the same + Console.WriteLine("Pages before: {0}. Pages after: {1}", count, FreeImage.GetPageCount(dib)); + + // Unload clone to prevent memory leak + FreeImage.UnloadEx(ref temp); + } + } + + // We are done and close the multipaged bitmap. + if (!FreeImage.CloseMultiBitmapEx(ref dib)) + { + Console.WriteLine("Closing bitmap failed!"); + } + } + } +} diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 02 - Multipaged bitmaps/Properties/AssemblyInfo.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 02 - Multipaged bitmaps/Properties/AssemblyInfo.cs index fc97675..f31990f 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 02 - Multipaged bitmaps/Properties/AssemblyInfo.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 02 - Multipaged bitmaps/Properties/AssemblyInfo.cs @@ -1,16 +1,16 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("35960522-c01a-40d2-a86b-37b9839b131c")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: Guid("35960522-c01a-40d2-a86b-37b9839b131c")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 03 - Allocating/Program.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 03 - Allocating/Program.cs index 50d3cde..b7e9524 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 03 - Allocating/Program.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 03 - Allocating/Program.cs @@ -1,74 +1,74 @@ -using System; -using System.IO; -using FreeImageAPI; - -namespace Sample03 -{ - class Program - { - static void Main(string[] args) - { - // Check if FreeImage.dll is available (can be in %path%). - if (!FreeImage.IsAvailable()) - { - Console.WriteLine("FreeImage.dll seems to be missing. Aborting."); - return; - } - - // Add this class to the message event - FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); - - Sample sample = new Sample(); - sample.Example(); - - // Remove this class from the message event - FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); - } - - static void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) - { - Console.WriteLine("Error for {0}: {1}", fif.ToString(), message); - } - } - - public class Sample - { - FIBITMAP dib = new FIBITMAP(); - - public void Example() - { - // Allocating a new bitmap with 99x99 pixels, 16-bit color depth and an allocation of 5 bits for each color. - dib = FreeImage.Allocate(99, 99, 16, FreeImage.FI16_555_RED_MASK, FreeImage.FI16_555_GREEN_MASK, FreeImage.FI16_555_BLUE_MASK); - - // Saving bitmap. - if (!FreeImage.SaveEx(ref dib, "example01.bmp", true)) - { - Console.WriteLine("Saving 'example.bmp' failed."); - FreeImage.UnloadEx(ref dib); - } - - // Allocation a new bitmap with 71x33 pixels, 4-bit color depth. Bitmaps below 16-bit have paletts. - // Each pixel references an index within the palette wich contains the true color. - // Therefor no bit-masks are needed and can be set to 0. - dib = FreeImage.Allocate(71, 33, 4, 0, 0, 0); - - // Saving bitmap. - if (!FreeImage.SaveEx(ref dib, "example02.tif", true)) - { - Console.WriteLine("Saving 'example02.tif' failed."); - FreeImage.UnloadEx(ref dib); - } - - // Allocation a new bitmap. This time 'AllocateT' is used because 'Allocate' can only create standard bitmaps. - // In this case a RGBF bitmap is created. Red, green and blue are represented by a float-value so no bit-masks are needed. - dib = FreeImage.AllocateT(FREE_IMAGE_TYPE.FIT_RGBF, 50, 75, 9, 0, 0, 0); - - // Saving bitmap. - if (!FreeImage.SaveEx(ref dib, "example03.hdr", true)) - { - Console.WriteLine("Saving 'example03.hdr' failed."); - FreeImage.UnloadEx(ref dib); - } - } - } -} +using System; +using System.IO; +using FreeImageAPI; + +namespace Sample03 +{ + class Program + { + static void Main(string[] args) + { + // Check if FreeImage.dll is available (can be in %path%). + if (!FreeImage.IsAvailable()) + { + Console.WriteLine("FreeImage.dll seems to be missing. Aborting."); + return; + } + + // Add this class to the message event + FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); + + Sample sample = new Sample(); + sample.Example(); + + // Remove this class from the message event + FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); + } + + static void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) + { + Console.WriteLine("Error for {0}: {1}", fif.ToString(), message); + } + } + + public class Sample + { + FIBITMAP dib = new FIBITMAP(); + + public void Example() + { + // Allocating a new bitmap with 99x99 pixels, 16-bit color depth and an allocation of 5 bits for each color. + dib = FreeImage.Allocate(99, 99, 16, FreeImage.FI16_555_RED_MASK, FreeImage.FI16_555_GREEN_MASK, FreeImage.FI16_555_BLUE_MASK); + + // Saving bitmap. + if (!FreeImage.SaveEx(ref dib, "example01.bmp", true)) + { + Console.WriteLine("Saving 'example.bmp' failed."); + FreeImage.UnloadEx(ref dib); + } + + // Allocation a new bitmap with 71x33 pixels, 4-bit color depth. Bitmaps below 16-bit have paletts. + // Each pixel references an index within the palette wich contains the true color. + // Therefor no bit-masks are needed and can be set to 0. + dib = FreeImage.Allocate(71, 33, 4, 0, 0, 0); + + // Saving bitmap. + if (!FreeImage.SaveEx(ref dib, "example02.tif", true)) + { + Console.WriteLine("Saving 'example02.tif' failed."); + FreeImage.UnloadEx(ref dib); + } + + // Allocation a new bitmap. This time 'AllocateT' is used because 'Allocate' can only create standard bitmaps. + // In this case a RGBF bitmap is created. Red, green and blue are represented by a float-value so no bit-masks are needed. + dib = FreeImage.AllocateT(FREE_IMAGE_TYPE.FIT_RGBF, 50, 75, 9, 0, 0, 0); + + // Saving bitmap. + if (!FreeImage.SaveEx(ref dib, "example03.hdr", true)) + { + Console.WriteLine("Saving 'example03.hdr' failed."); + FreeImage.UnloadEx(ref dib); + } + } + } +} diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 03 - Allocating/Properties/AssemblyInfo.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 03 - Allocating/Properties/AssemblyInfo.cs index 96b32c1..889eee8 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 03 - Allocating/Properties/AssemblyInfo.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 03 - Allocating/Properties/AssemblyInfo.cs @@ -1,16 +1,16 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("7139f1dc-3312-4c76-aeb3-891f869409b3")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: Guid("7139f1dc-3312-4c76-aeb3-891f869409b3")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 04 - Getting bitmap informations/MainForm.Designer.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 04 - Getting bitmap informations/MainForm.Designer.cs index 9ddcf38..ed75d0a 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 04 - Getting bitmap informations/MainForm.Designer.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 04 - Getting bitmap informations/MainForm.Designer.cs @@ -1,205 +1,205 @@ -namespace Sample04 -{ - partial class MainForm - { - /// - /// Erforderliche Designervariable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Verwendete Ressourcen bereinigen. - /// - /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Vom Windows Form-Designer generierter Code - - /// - /// Erforderliche Methode für die Designerunterstützung. - /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. - /// - private void InitializeComponent() - { - this.ofd = new System.Windows.Forms.OpenFileDialog(); - this.bOpenFile = new System.Windows.Forms.Button(); - this.lWidth = new System.Windows.Forms.Label(); - this.lHeight = new System.Windows.Forms.Label(); - this.lBPP = new System.Windows.Forms.Label(); - this.lRedMask = new System.Windows.Forms.Label(); - this.lGreenMask = new System.Windows.Forms.Label(); - this.lBlueMask = new System.Windows.Forms.Label(); - this.lImageType = new System.Windows.Forms.Label(); - this.lDPIY = new System.Windows.Forms.Label(); - this.lDPIX = new System.Windows.Forms.Label(); - this.lFormat = new System.Windows.Forms.Label(); - this.lHeader = new System.Windows.Forms.Label(); - this.SuspendLayout(); - // - // ofd - // - this.ofd.Filter = "All files (*.*)|*.*"; - // - // bOpenFile - // - this.bOpenFile.Location = new System.Drawing.Point(12, 358); - this.bOpenFile.Name = "bOpenFile"; - this.bOpenFile.Size = new System.Drawing.Size(75, 23); - this.bOpenFile.TabIndex = 4; - this.bOpenFile.Text = "Open file"; - this.bOpenFile.UseVisualStyleBackColor = true; - this.bOpenFile.Click += new System.EventHandler(this.bOpenFile_Click); - // - // lWidth - // - this.lWidth.AutoSize = true; - this.lWidth.Location = new System.Drawing.Point(9, 51); - this.lWidth.Name = "lWidth"; - this.lWidth.Size = new System.Drawing.Size(46, 16); - this.lWidth.TabIndex = 0; - this.lWidth.Text = "Width:"; - // - // lHeight - // - this.lHeight.AutoSize = true; - this.lHeight.Location = new System.Drawing.Point(9, 76); - this.lHeight.Name = "lHeight"; - this.lHeight.Size = new System.Drawing.Size(53, 16); - this.lHeight.TabIndex = 1; - this.lHeight.Text = "Height: "; - // - // lBPP - // - this.lBPP.AutoSize = true; - this.lBPP.Location = new System.Drawing.Point(9, 101); - this.lBPP.Name = "lBPP"; - this.lBPP.Size = new System.Drawing.Size(80, 16); - this.lBPP.TabIndex = 2; - this.lBPP.Text = "Color Depth:"; - // - // lRedMask - // - this.lRedMask.AutoSize = true; - this.lRedMask.Location = new System.Drawing.Point(9, 129); - this.lRedMask.Name = "lRedMask"; - this.lRedMask.Size = new System.Drawing.Size(68, 16); - this.lRedMask.TabIndex = 3; - this.lRedMask.Text = "Red Mask:"; - // - // lGreenMask - // - this.lGreenMask.AutoSize = true; - this.lGreenMask.Location = new System.Drawing.Point(9, 188); - this.lGreenMask.Name = "lGreenMask"; - this.lGreenMask.Size = new System.Drawing.Size(80, 16); - this.lGreenMask.TabIndex = 5; - this.lGreenMask.Text = "Green Mask:"; - // - // lBlueMask - // - this.lBlueMask.AutoSize = true; - this.lBlueMask.Location = new System.Drawing.Point(9, 158); - this.lBlueMask.Name = "lBlueMask"; - this.lBlueMask.Size = new System.Drawing.Size(70, 16); - this.lBlueMask.TabIndex = 6; - this.lBlueMask.Text = "Blue Mask:"; - // - // lImageType - // - this.lImageType.AutoSize = true; - this.lImageType.Location = new System.Drawing.Point(9, 215); - this.lImageType.Name = "lImageType"; - this.lImageType.Size = new System.Drawing.Size(81, 16); - this.lImageType.TabIndex = 7; - this.lImageType.Text = "Image Type:"; - // - // lDPIY - // - this.lDPIY.AutoSize = true; - this.lDPIY.Location = new System.Drawing.Point(9, 244); - this.lDPIY.Name = "lDPIY"; - this.lDPIY.Size = new System.Drawing.Size(43, 16); - this.lDPIY.TabIndex = 8; - this.lDPIY.Text = "DPI Y:"; - // - // lDPIX - // - this.lDPIX.AutoSize = true; - this.lDPIX.Location = new System.Drawing.Point(9, 273); - this.lDPIX.Name = "lDPIX"; - this.lDPIX.Size = new System.Drawing.Size(44, 16); - this.lDPIX.TabIndex = 9; - this.lDPIX.Text = "DPI X:"; - // - // lFormat - // - this.lFormat.AutoSize = true; - this.lFormat.Location = new System.Drawing.Point(9, 302); - this.lFormat.Name = "lFormat"; - this.lFormat.Size = new System.Drawing.Size(78, 16); - this.lFormat.TabIndex = 10; - this.lFormat.Text = "File Format:"; - // - // lHeader - // - this.lHeader.AutoSize = true; - this.lHeader.Location = new System.Drawing.Point(117, 19); - this.lHeader.Name = "lHeader"; - this.lHeader.Size = new System.Drawing.Size(162, 16); - this.lHeader.TabIndex = 11; - this.lHeader.Text = "Bitmap-Information Viewer"; - // - // MainForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(400, 393); - this.Controls.Add(this.lHeader); - this.Controls.Add(this.lFormat); - this.Controls.Add(this.lDPIX); - this.Controls.Add(this.lDPIY); - this.Controls.Add(this.lImageType); - this.Controls.Add(this.lBlueMask); - this.Controls.Add(this.lGreenMask); - this.Controls.Add(this.bOpenFile); - this.Controls.Add(this.lRedMask); - this.Controls.Add(this.lBPP); - this.Controls.Add(this.lHeight); - this.Controls.Add(this.lWidth); - this.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "MainForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Sample04"; - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.OpenFileDialog ofd; - private System.Windows.Forms.Button bOpenFile; - private System.Windows.Forms.Label lWidth; - private System.Windows.Forms.Label lHeight; - private System.Windows.Forms.Label lBPP; - private System.Windows.Forms.Label lRedMask; - private System.Windows.Forms.Label lGreenMask; - private System.Windows.Forms.Label lBlueMask; - private System.Windows.Forms.Label lImageType; - private System.Windows.Forms.Label lDPIY; - private System.Windows.Forms.Label lDPIX; - private System.Windows.Forms.Label lFormat; - private System.Windows.Forms.Label lHeader; - } +namespace Sample04 +{ + partial class MainForm + { + /// + /// Erforderliche Designervariable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Verwendete Ressourcen bereinigen. + /// + /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Windows Form-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() + { + this.ofd = new System.Windows.Forms.OpenFileDialog(); + this.bOpenFile = new System.Windows.Forms.Button(); + this.lWidth = new System.Windows.Forms.Label(); + this.lHeight = new System.Windows.Forms.Label(); + this.lBPP = new System.Windows.Forms.Label(); + this.lRedMask = new System.Windows.Forms.Label(); + this.lGreenMask = new System.Windows.Forms.Label(); + this.lBlueMask = new System.Windows.Forms.Label(); + this.lImageType = new System.Windows.Forms.Label(); + this.lDPIY = new System.Windows.Forms.Label(); + this.lDPIX = new System.Windows.Forms.Label(); + this.lFormat = new System.Windows.Forms.Label(); + this.lHeader = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // ofd + // + this.ofd.Filter = "All files (*.*)|*.*"; + // + // bOpenFile + // + this.bOpenFile.Location = new System.Drawing.Point(12, 358); + this.bOpenFile.Name = "bOpenFile"; + this.bOpenFile.Size = new System.Drawing.Size(75, 23); + this.bOpenFile.TabIndex = 4; + this.bOpenFile.Text = "Open file"; + this.bOpenFile.UseVisualStyleBackColor = true; + this.bOpenFile.Click += new System.EventHandler(this.bOpenFile_Click); + // + // lWidth + // + this.lWidth.AutoSize = true; + this.lWidth.Location = new System.Drawing.Point(9, 51); + this.lWidth.Name = "lWidth"; + this.lWidth.Size = new System.Drawing.Size(46, 16); + this.lWidth.TabIndex = 0; + this.lWidth.Text = "Width:"; + // + // lHeight + // + this.lHeight.AutoSize = true; + this.lHeight.Location = new System.Drawing.Point(9, 76); + this.lHeight.Name = "lHeight"; + this.lHeight.Size = new System.Drawing.Size(53, 16); + this.lHeight.TabIndex = 1; + this.lHeight.Text = "Height: "; + // + // lBPP + // + this.lBPP.AutoSize = true; + this.lBPP.Location = new System.Drawing.Point(9, 101); + this.lBPP.Name = "lBPP"; + this.lBPP.Size = new System.Drawing.Size(80, 16); + this.lBPP.TabIndex = 2; + this.lBPP.Text = "Color Depth:"; + // + // lRedMask + // + this.lRedMask.AutoSize = true; + this.lRedMask.Location = new System.Drawing.Point(9, 129); + this.lRedMask.Name = "lRedMask"; + this.lRedMask.Size = new System.Drawing.Size(68, 16); + this.lRedMask.TabIndex = 3; + this.lRedMask.Text = "Red Mask:"; + // + // lGreenMask + // + this.lGreenMask.AutoSize = true; + this.lGreenMask.Location = new System.Drawing.Point(9, 188); + this.lGreenMask.Name = "lGreenMask"; + this.lGreenMask.Size = new System.Drawing.Size(80, 16); + this.lGreenMask.TabIndex = 5; + this.lGreenMask.Text = "Green Mask:"; + // + // lBlueMask + // + this.lBlueMask.AutoSize = true; + this.lBlueMask.Location = new System.Drawing.Point(9, 158); + this.lBlueMask.Name = "lBlueMask"; + this.lBlueMask.Size = new System.Drawing.Size(70, 16); + this.lBlueMask.TabIndex = 6; + this.lBlueMask.Text = "Blue Mask:"; + // + // lImageType + // + this.lImageType.AutoSize = true; + this.lImageType.Location = new System.Drawing.Point(9, 215); + this.lImageType.Name = "lImageType"; + this.lImageType.Size = new System.Drawing.Size(81, 16); + this.lImageType.TabIndex = 7; + this.lImageType.Text = "Image Type:"; + // + // lDPIY + // + this.lDPIY.AutoSize = true; + this.lDPIY.Location = new System.Drawing.Point(9, 244); + this.lDPIY.Name = "lDPIY"; + this.lDPIY.Size = new System.Drawing.Size(43, 16); + this.lDPIY.TabIndex = 8; + this.lDPIY.Text = "DPI Y:"; + // + // lDPIX + // + this.lDPIX.AutoSize = true; + this.lDPIX.Location = new System.Drawing.Point(9, 273); + this.lDPIX.Name = "lDPIX"; + this.lDPIX.Size = new System.Drawing.Size(44, 16); + this.lDPIX.TabIndex = 9; + this.lDPIX.Text = "DPI X:"; + // + // lFormat + // + this.lFormat.AutoSize = true; + this.lFormat.Location = new System.Drawing.Point(9, 302); + this.lFormat.Name = "lFormat"; + this.lFormat.Size = new System.Drawing.Size(78, 16); + this.lFormat.TabIndex = 10; + this.lFormat.Text = "File Format:"; + // + // lHeader + // + this.lHeader.AutoSize = true; + this.lHeader.Location = new System.Drawing.Point(117, 19); + this.lHeader.Name = "lHeader"; + this.lHeader.Size = new System.Drawing.Size(162, 16); + this.lHeader.TabIndex = 11; + this.lHeader.Text = "Bitmap-Information Viewer"; + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(400, 393); + this.Controls.Add(this.lHeader); + this.Controls.Add(this.lFormat); + this.Controls.Add(this.lDPIX); + this.Controls.Add(this.lDPIY); + this.Controls.Add(this.lImageType); + this.Controls.Add(this.lBlueMask); + this.Controls.Add(this.lGreenMask); + this.Controls.Add(this.bOpenFile); + this.Controls.Add(this.lRedMask); + this.Controls.Add(this.lBPP); + this.Controls.Add(this.lHeight); + this.Controls.Add(this.lWidth); + this.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "MainForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Sample04"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.OpenFileDialog ofd; + private System.Windows.Forms.Button bOpenFile; + private System.Windows.Forms.Label lWidth; + private System.Windows.Forms.Label lHeight; + private System.Windows.Forms.Label lBPP; + private System.Windows.Forms.Label lRedMask; + private System.Windows.Forms.Label lGreenMask; + private System.Windows.Forms.Label lBlueMask; + private System.Windows.Forms.Label lImageType; + private System.Windows.Forms.Label lDPIY; + private System.Windows.Forms.Label lDPIX; + private System.Windows.Forms.Label lFormat; + private System.Windows.Forms.Label lHeader; + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 04 - Getting bitmap informations/MainForm.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 04 - Getting bitmap informations/MainForm.cs index 21e7342..dff68f3 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 04 - Getting bitmap informations/MainForm.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 04 - Getting bitmap informations/MainForm.cs @@ -1,120 +1,120 @@ -using System; -using System.Windows.Forms; -using FreeImageAPI; - -namespace Sample04 -{ - public partial class MainForm : Form - { - string message = null; - - [STAThread] - static void Main() - { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); - } - - public MainForm() - { - InitializeComponent(); - FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); - } - - ~MainForm() - { - FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); - } - - void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) - { - if (this.message == null) - { - this.message = message; - } - else - { - this.message += "\n" + message; - } - } - - private void bOpenFile_Click(object sender, EventArgs e) - { - // Resetting filename - ofd.FileName = ""; - - // Was a file selected - if (ofd.ShowDialog() == DialogResult.OK) - { - // Format is stored in 'format' on successfull load. - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - - // Try loading the file - FIBITMAP dib = FreeImage.LoadEx(ofd.FileName, ref format); - - try - { - // Error handling - if (dib.IsNull) - { - // Chech whether FreeImage generated an error messe - if (message != null) - { - MessageBox.Show("File could not be loaded!\nError:{0}", message); - } - else - { - MessageBox.Show("File could not be loaded!", message); - } - return; - } - - // Read width - lWidth.Text = String.Format("Width: {0}", FreeImage.GetWidth(dib)); - - // Read height - lHeight.Text = String.Format("Height: {0}", FreeImage.GetHeight(dib)); - - // Read color depth - lBPP.Text = String.Format("Color Depth: {0}", FreeImage.GetBPP(dib)); - - // Read red bitmask (16 - 32 bpp) - lRedMask.Text = String.Format("Red Mask: 0x{0:X8}", FreeImage.GetRedMask(dib)); - - // Read green bitmask (16 - 32 bpp) - lBlueMask.Text = String.Format("Green Mask: 0x{0:X8}", FreeImage.GetGreenMask(dib)); - - // Read blue bitmask (16 - 32 bpp) - lGreenMask.Text = String.Format("Blue Mask: 0x{0:X8}", FreeImage.GetBlueMask(dib)); - - // Read image type (FI_BITMAP, FIT_RGB16, FIT_COMPLEX ect) - lImageType.Text = String.Format("Image Type: {0}", FreeImage.GetImageType(dib)); - - // Read x-axis dpi - lDPIX.Text = String.Format("DPI X: {0}", FreeImage.GetResolutionX(dib)); - - // Read y-axis dpi - lDPIY.Text = String.Format("DPI Y: {0}", FreeImage.GetResolutionY(dib)); - - // Read file format - lFormat.Text = String.Format("File Format: {0}", FreeImage.GetFormatFromFIF(format)); - } - catch - { - } - - // Always unload bitmap - FreeImage.UnloadEx(ref dib); - - // Reset the error massage buffer - message = null; - } - // No file was selected - else - { - MessageBox.Show("No file loaded.", "Error"); - } - } - } +using System; +using System.Windows.Forms; +using FreeImageAPI; + +namespace Sample04 +{ + public partial class MainForm : Form + { + string message = null; + + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + + public MainForm() + { + InitializeComponent(); + FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); + } + + ~MainForm() + { + FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); + } + + void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) + { + if (this.message == null) + { + this.message = message; + } + else + { + this.message += "\n" + message; + } + } + + private void bOpenFile_Click(object sender, EventArgs e) + { + // Resetting filename + ofd.FileName = ""; + + // Was a file selected + if (ofd.ShowDialog() == DialogResult.OK) + { + // Format is stored in 'format' on successfull load. + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + + // Try loading the file + FIBITMAP dib = FreeImage.LoadEx(ofd.FileName, ref format); + + try + { + // Error handling + if (dib.IsNull) + { + // Chech whether FreeImage generated an error messe + if (message != null) + { + MessageBox.Show("File could not be loaded!\nError:{0}", message); + } + else + { + MessageBox.Show("File could not be loaded!", message); + } + return; + } + + // Read width + lWidth.Text = String.Format("Width: {0}", FreeImage.GetWidth(dib)); + + // Read height + lHeight.Text = String.Format("Height: {0}", FreeImage.GetHeight(dib)); + + // Read color depth + lBPP.Text = String.Format("Color Depth: {0}", FreeImage.GetBPP(dib)); + + // Read red bitmask (16 - 32 bpp) + lRedMask.Text = String.Format("Red Mask: 0x{0:X8}", FreeImage.GetRedMask(dib)); + + // Read green bitmask (16 - 32 bpp) + lBlueMask.Text = String.Format("Green Mask: 0x{0:X8}", FreeImage.GetGreenMask(dib)); + + // Read blue bitmask (16 - 32 bpp) + lGreenMask.Text = String.Format("Blue Mask: 0x{0:X8}", FreeImage.GetBlueMask(dib)); + + // Read image type (FI_BITMAP, FIT_RGB16, FIT_COMPLEX ect) + lImageType.Text = String.Format("Image Type: {0}", FreeImage.GetImageType(dib)); + + // Read x-axis dpi + lDPIX.Text = String.Format("DPI X: {0}", FreeImage.GetResolutionX(dib)); + + // Read y-axis dpi + lDPIY.Text = String.Format("DPI Y: {0}", FreeImage.GetResolutionY(dib)); + + // Read file format + lFormat.Text = String.Format("File Format: {0}", FreeImage.GetFormatFromFIF(format)); + } + catch + { + } + + // Always unload bitmap + FreeImage.UnloadEx(ref dib); + + // Reset the error massage buffer + message = null; + } + // No file was selected + else + { + MessageBox.Show("No file loaded.", "Error"); + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 04 - Getting bitmap informations/Properties/AssemblyInfo.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 04 - Getting bitmap informations/Properties/AssemblyInfo.cs index eafebc8..443c1d7 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 04 - Getting bitmap informations/Properties/AssemblyInfo.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 04 - Getting bitmap informations/Properties/AssemblyInfo.cs @@ -1,16 +1,16 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("7c8fdc9a-a8f9-4996-99c8-9df47513edeb")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: Guid("7c8fdc9a-a8f9-4996-99c8-9df47513edeb")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 05 - Working with pixels/Program.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 05 - Working with pixels/Program.cs index de6819f..40f878f 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 05 - Working with pixels/Program.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 05 - Working with pixels/Program.cs @@ -1,213 +1,213 @@ -using System; -using FreeImageAPI; -using System.Drawing; - -namespace Sample05 -{ - class Program - { - static void Main(string[] args) - { - // Check if FreeImage.dll is available (can be in %path%). - if (!FreeImage.IsAvailable()) - { - Console.WriteLine("FreeImage.dll seems to be missing. Aborting."); - return; - } - - Sample sample = new Sample(); - - // The example will flip the bitmap by manually accessing the - // bitmaps scanlines and swapping them - sample.Example01(); - - // The example will access each pixel of the bitmap manually - // and change its color intensity to 3/4 of the original value - // which will have a darker bitmap as result. - sample.Example02(); - - // The example will access and swap the bitmaps palette from - // 'FIC_MINISBLACK' to 'FIC_MINISWHITE'. Then it will swap each pixels - // palette index so that each pixel is assigned to the its old value - // so that the bitmaps "pixeldata" stays the same. - sample.Example03(); - } - } - - public class Sample - { - FIBITMAP dib = new FIBITMAP(); - - public void Example01() - { - // Load sample file - dib = FreeImage.LoadEx("Sample.jpg", FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); - - // Check whether loading succeeded - if (dib.IsNull) - { - Console.WriteLine("Sample.jpg could not be loaded. Aborting."); - return; - } - - // Check whether the bitmap has 24 bpp color depth to ensure - // using RGBTRIPPLE is correct. - if (FreeImage.GetBPP(dib) != 24) - { - Console.WriteLine("Sample.jpg is no 24 bpp bitmap. Aborting."); - FreeImage.UnloadEx(ref dib); - return; - } - - // Store height of the bitmap - int height = (int)FreeImage.GetHeight(dib); - - // Iterate over half of the bitmaps scanlines and swap - // line[1] with line[height], line[2] with line[height-1] etc which will - // flip the image. - for (int i = 0; i < (height / 2); i++) - { - // Get scanline from the bottom part of the bitmap - Scanline scanlineBottom = new Scanline(dib, i); - - // Get scanline from the top part of the bitmap - Scanline scanlineTop = new Scanline(dib, height - 1 - i); - - // Get arrays of RGBTRIPPLEs that contain the bitmaps real pixel data - // of the two scanlines. - RGBTRIPLE[] rgbtBottom = scanlineBottom.Data; - RGBTRIPLE[] rgbtTop = scanlineTop.Data; - - // Restore the scanline across to switch the bitmaps lines. - scanlineBottom.Data = rgbtTop; - scanlineTop.Data = rgbtBottom; - } - - // Store the bitmap to disk - if (!FreeImage.SaveEx(ref dib, "SampleOut01.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD, true)) - { - Console.WriteLine("Error while saving 'SampleOut01.jpg'"); - FreeImage.UnloadEx(ref dib); - } - } - - public void Example02() - { - dib = FreeImage.LoadEx("Sample.jpg", FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); - - // Check whether loading succeeded - if (dib.IsNull) - { - Console.WriteLine("Sample.jpg could not be loaded. Aborting."); - return; - } - - // Check whether the bitmap has 24 bpp color depth to ensure - // using RGBTRIPPLE is correct. - if (FreeImage.GetBPP(dib) != 24) - { - Console.WriteLine("Sample.jpg is no 24 bpp bitmap. Aborting."); - FreeImage.UnloadEx(ref dib); - return; - } - - // Iterate over all scanlines - for (int i = 0; i < FreeImage.GetHeight(dib); i++) - { - // Get scanline - Scanline scanline = new Scanline(dib, i); - - // Get pixeldata from scanline - RGBTRIPLE[] rgbt = scanline.Data; - - // Iterate over each pixel reducing the colors intensity to 3/4 which - // will darken the bitmap. - for (int j = 0; j < rgbt.Length; j++) - { - rgbt[j].rgbtBlue = (byte)((int)rgbt[j].rgbtBlue * 3 / 4); - rgbt[j].rgbtGreen = (byte)((int)rgbt[j].rgbtGreen * 3 / 4); - rgbt[j].rgbtRed = (byte)((int)rgbt[j].rgbtRed * 3 / 4); - - // In case no direct access to the data is implemented - // the following way is equivalent: - // - // Color color = rgbt[j].color; - // rgbt[j].color = Color.FromArgb(color.R * 3 / 4, color.G * 3 / 4, color.B * 3 / 4); - } - - // Write the darkened scanline back to memory - scanline.Data = rgbt; - } - - // Store the bitmap to disk - if (!FreeImage.SaveEx(ref dib, "SampleOut02.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD, true)) - { - Console.WriteLine("Error while saving 'SampleOut02.jpg'"); - FreeImage.UnloadEx(ref dib); - } - } - - public void Example03() - { - dib = FreeImage.LoadEx("Sample.tif"); - - // Check whether loading succeeded - if (dib.IsNull) - { - Console.WriteLine("Sample.tif could not be loaded. Aborting."); - return; - } - - // Check whether the bitmap has 4 bpp color depth to ensure - // using FI4B is correct. - if (FreeImage.GetBPP(dib) != 4) - { - Console.WriteLine("Sample.tif is no 4 bpp bitmap. Aborting."); - FreeImage.UnloadEx(ref dib); - return; - } - - // Get the bitmaps palette - Palette palette = FreeImage.GetPaletteEx(dib); - - int size = (int)palette.Length; - - // Check whether the palette has a color (is valid) - if (size == 0) - { - Console.WriteLine("Sample.tif has no valid palette. Aborting."); - FreeImage.UnloadEx(ref dib); - return; - } - - // Swapping the palette - for (int i = 0; i < size / 2; i++) - { - RGBQUAD temp = palette[i]; - palette[i] = palette[size - 1 - i]; - palette[size - 1 - i] = temp; - } - - // Iterate over each scanline - for (int i = 0; i < FreeImage.GetHeight(dib); i++) - { - // Get scanline - Scanline scanline = new Scanline(dib, i); - - // Iterate over all pixels swapping the palette index - // so that the color will stay the same - for (int j = 0; j < scanline.Length; j++) - { - scanline[j] = (byte)(size - 1 - scanline[j]); - } - } - - // Save the bitmap to disk - if (!FreeImage.SaveEx(ref dib, "SampleOut03.tif", FREE_IMAGE_SAVE_FLAGS.TIFF_LZW, true)) - { - Console.WriteLine("Error while saving 'SampleOut03.tif'"); - FreeImage.UnloadEx(ref dib); - } - } - } +using System; +using FreeImageAPI; +using System.Drawing; + +namespace Sample05 +{ + class Program + { + static void Main(string[] args) + { + // Check if FreeImage.dll is available (can be in %path%). + if (!FreeImage.IsAvailable()) + { + Console.WriteLine("FreeImage.dll seems to be missing. Aborting."); + return; + } + + Sample sample = new Sample(); + + // The example will flip the bitmap by manually accessing the + // bitmaps scanlines and swapping them + sample.Example01(); + + // The example will access each pixel of the bitmap manually + // and change its color intensity to 3/4 of the original value + // which will have a darker bitmap as result. + sample.Example02(); + + // The example will access and swap the bitmaps palette from + // 'FIC_MINISBLACK' to 'FIC_MINISWHITE'. Then it will swap each pixels + // palette index so that each pixel is assigned to the its old value + // so that the bitmaps "pixeldata" stays the same. + sample.Example03(); + } + } + + public class Sample + { + FIBITMAP dib = new FIBITMAP(); + + public void Example01() + { + // Load sample file + dib = FreeImage.LoadEx("Sample.jpg", FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); + + // Check whether loading succeeded + if (dib.IsNull) + { + Console.WriteLine("Sample.jpg could not be loaded. Aborting."); + return; + } + + // Check whether the bitmap has 24 bpp color depth to ensure + // using RGBTRIPPLE is correct. + if (FreeImage.GetBPP(dib) != 24) + { + Console.WriteLine("Sample.jpg is no 24 bpp bitmap. Aborting."); + FreeImage.UnloadEx(ref dib); + return; + } + + // Store height of the bitmap + int height = (int)FreeImage.GetHeight(dib); + + // Iterate over half of the bitmaps scanlines and swap + // line[1] with line[height], line[2] with line[height-1] etc which will + // flip the image. + for (int i = 0; i < (height / 2); i++) + { + // Get scanline from the bottom part of the bitmap + Scanline scanlineBottom = new Scanline(dib, i); + + // Get scanline from the top part of the bitmap + Scanline scanlineTop = new Scanline(dib, height - 1 - i); + + // Get arrays of RGBTRIPPLEs that contain the bitmaps real pixel data + // of the two scanlines. + RGBTRIPLE[] rgbtBottom = scanlineBottom.Data; + RGBTRIPLE[] rgbtTop = scanlineTop.Data; + + // Restore the scanline across to switch the bitmaps lines. + scanlineBottom.Data = rgbtTop; + scanlineTop.Data = rgbtBottom; + } + + // Store the bitmap to disk + if (!FreeImage.SaveEx(ref dib, "SampleOut01.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD, true)) + { + Console.WriteLine("Error while saving 'SampleOut01.jpg'"); + FreeImage.UnloadEx(ref dib); + } + } + + public void Example02() + { + dib = FreeImage.LoadEx("Sample.jpg", FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); + + // Check whether loading succeeded + if (dib.IsNull) + { + Console.WriteLine("Sample.jpg could not be loaded. Aborting."); + return; + } + + // Check whether the bitmap has 24 bpp color depth to ensure + // using RGBTRIPPLE is correct. + if (FreeImage.GetBPP(dib) != 24) + { + Console.WriteLine("Sample.jpg is no 24 bpp bitmap. Aborting."); + FreeImage.UnloadEx(ref dib); + return; + } + + // Iterate over all scanlines + for (int i = 0; i < FreeImage.GetHeight(dib); i++) + { + // Get scanline + Scanline scanline = new Scanline(dib, i); + + // Get pixeldata from scanline + RGBTRIPLE[] rgbt = scanline.Data; + + // Iterate over each pixel reducing the colors intensity to 3/4 which + // will darken the bitmap. + for (int j = 0; j < rgbt.Length; j++) + { + rgbt[j].rgbtBlue = (byte)((int)rgbt[j].rgbtBlue * 3 / 4); + rgbt[j].rgbtGreen = (byte)((int)rgbt[j].rgbtGreen * 3 / 4); + rgbt[j].rgbtRed = (byte)((int)rgbt[j].rgbtRed * 3 / 4); + + // In case no direct access to the data is implemented + // the following way is equivalent: + // + // Color color = rgbt[j].color; + // rgbt[j].color = Color.FromArgb(color.R * 3 / 4, color.G * 3 / 4, color.B * 3 / 4); + } + + // Write the darkened scanline back to memory + scanline.Data = rgbt; + } + + // Store the bitmap to disk + if (!FreeImage.SaveEx(ref dib, "SampleOut02.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD, true)) + { + Console.WriteLine("Error while saving 'SampleOut02.jpg'"); + FreeImage.UnloadEx(ref dib); + } + } + + public void Example03() + { + dib = FreeImage.LoadEx("Sample.tif"); + + // Check whether loading succeeded + if (dib.IsNull) + { + Console.WriteLine("Sample.tif could not be loaded. Aborting."); + return; + } + + // Check whether the bitmap has 4 bpp color depth to ensure + // using FI4B is correct. + if (FreeImage.GetBPP(dib) != 4) + { + Console.WriteLine("Sample.tif is no 4 bpp bitmap. Aborting."); + FreeImage.UnloadEx(ref dib); + return; + } + + // Get the bitmaps palette + Palette palette = FreeImage.GetPaletteEx(dib); + + int size = (int)palette.Length; + + // Check whether the palette has a color (is valid) + if (size == 0) + { + Console.WriteLine("Sample.tif has no valid palette. Aborting."); + FreeImage.UnloadEx(ref dib); + return; + } + + // Swapping the palette + for (int i = 0; i < size / 2; i++) + { + RGBQUAD temp = palette[i]; + palette[i] = palette[size - 1 - i]; + palette[size - 1 - i] = temp; + } + + // Iterate over each scanline + for (int i = 0; i < FreeImage.GetHeight(dib); i++) + { + // Get scanline + Scanline scanline = new Scanline(dib, i); + + // Iterate over all pixels swapping the palette index + // so that the color will stay the same + for (int j = 0; j < scanline.Length; j++) + { + scanline[j] = (byte)(size - 1 - scanline[j]); + } + } + + // Save the bitmap to disk + if (!FreeImage.SaveEx(ref dib, "SampleOut03.tif", FREE_IMAGE_SAVE_FLAGS.TIFF_LZW, true)) + { + Console.WriteLine("Error while saving 'SampleOut03.tif'"); + FreeImage.UnloadEx(ref dib); + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 05 - Working with pixels/Properties/AssemblyInfo.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 05 - Working with pixels/Properties/AssemblyInfo.cs index 7dd2e1a..c656ffa 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 05 - Working with pixels/Properties/AssemblyInfo.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 05 - Working with pixels/Properties/AssemblyInfo.cs @@ -1,16 +1,16 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("fd43331d-5ea4-40f8-86d5-8f820d606912")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: Guid("fd43331d-5ea4-40f8-86d5-8f820d606912")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 06 - Converting/MainForm.Designer.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 06 - Converting/MainForm.Designer.cs index fd131e6..af9a594 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 06 - Converting/MainForm.Designer.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 06 - Converting/MainForm.Designer.cs @@ -1,120 +1,120 @@ -namespace Sample06 -{ - partial class MainForm - { - /// - /// Erforderliche Designervariable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Verwendete Ressourcen bereinigen. - /// - /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Vom Windows Form-Designer generierter Code - - /// - /// Erforderliche Methode für die Designerunterstützung. - /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. - /// - private void InitializeComponent() - { - this.picBox = new System.Windows.Forms.PictureBox(); - this.bExample01 = new System.Windows.Forms.Button(); - this.bOriginal = new System.Windows.Forms.Button(); - this.bExample02 = new System.Windows.Forms.Button(); - this.bExample03 = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.picBox)).BeginInit(); - this.SuspendLayout(); - // - // picBox - // - this.picBox.BackColor = System.Drawing.Color.White; - this.picBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.picBox.Location = new System.Drawing.Point(12, 12); - this.picBox.Name = "picBox"; - this.picBox.Size = new System.Drawing.Size(747, 465); - this.picBox.TabIndex = 0; - this.picBox.TabStop = false; - // - // bExample01 - // - this.bExample01.Location = new System.Drawing.Point(93, 483); - this.bExample01.Name = "bExample01"; - this.bExample01.Size = new System.Drawing.Size(88, 23); - this.bExample01.TabIndex = 1; - this.bExample01.Text = "Example 01"; - this.bExample01.UseVisualStyleBackColor = true; - this.bExample01.Click += new System.EventHandler(this.bExample01_Click); - // - // bOriginal - // - this.bOriginal.Location = new System.Drawing.Point(12, 483); - this.bOriginal.Name = "bOriginal"; - this.bOriginal.Size = new System.Drawing.Size(75, 23); - this.bOriginal.TabIndex = 2; - this.bOriginal.Text = "Original"; - this.bOriginal.UseVisualStyleBackColor = true; - this.bOriginal.Click += new System.EventHandler(this.bOriginal_Click); - // - // bExample02 - // - this.bExample02.Location = new System.Drawing.Point(187, 483); - this.bExample02.Name = "bExample02"; - this.bExample02.Size = new System.Drawing.Size(88, 23); - this.bExample02.TabIndex = 3; - this.bExample02.Text = "Example 02"; - this.bExample02.UseVisualStyleBackColor = true; - this.bExample02.Click += new System.EventHandler(this.bExample02_Click); - // - // bExample03 - // - this.bExample03.Location = new System.Drawing.Point(281, 483); - this.bExample03.Name = "bExample03"; - this.bExample03.Size = new System.Drawing.Size(88, 23); - this.bExample03.TabIndex = 4; - this.bExample03.Text = "Example 03"; - this.bExample03.UseVisualStyleBackColor = true; - this.bExample03.Click += new System.EventHandler(this.bExample03_Click); - // - // MainForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(771, 518); - this.Controls.Add(this.bExample03); - this.Controls.Add(this.bExample02); - this.Controls.Add(this.bOriginal); - this.Controls.Add(this.bExample01); - this.Controls.Add(this.picBox); - this.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "MainForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Sample06"; - ((System.ComponentModel.ISupportInitialize)(this.picBox)).EndInit(); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.PictureBox picBox; - private System.Windows.Forms.Button bExample01; - private System.Windows.Forms.Button bOriginal; - private System.Windows.Forms.Button bExample02; - private System.Windows.Forms.Button bExample03; - } +namespace Sample06 +{ + partial class MainForm + { + /// + /// Erforderliche Designervariable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Verwendete Ressourcen bereinigen. + /// + /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Windows Form-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() + { + this.picBox = new System.Windows.Forms.PictureBox(); + this.bExample01 = new System.Windows.Forms.Button(); + this.bOriginal = new System.Windows.Forms.Button(); + this.bExample02 = new System.Windows.Forms.Button(); + this.bExample03 = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.picBox)).BeginInit(); + this.SuspendLayout(); + // + // picBox + // + this.picBox.BackColor = System.Drawing.Color.White; + this.picBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.picBox.Location = new System.Drawing.Point(12, 12); + this.picBox.Name = "picBox"; + this.picBox.Size = new System.Drawing.Size(747, 465); + this.picBox.TabIndex = 0; + this.picBox.TabStop = false; + // + // bExample01 + // + this.bExample01.Location = new System.Drawing.Point(93, 483); + this.bExample01.Name = "bExample01"; + this.bExample01.Size = new System.Drawing.Size(88, 23); + this.bExample01.TabIndex = 1; + this.bExample01.Text = "Example 01"; + this.bExample01.UseVisualStyleBackColor = true; + this.bExample01.Click += new System.EventHandler(this.bExample01_Click); + // + // bOriginal + // + this.bOriginal.Location = new System.Drawing.Point(12, 483); + this.bOriginal.Name = "bOriginal"; + this.bOriginal.Size = new System.Drawing.Size(75, 23); + this.bOriginal.TabIndex = 2; + this.bOriginal.Text = "Original"; + this.bOriginal.UseVisualStyleBackColor = true; + this.bOriginal.Click += new System.EventHandler(this.bOriginal_Click); + // + // bExample02 + // + this.bExample02.Location = new System.Drawing.Point(187, 483); + this.bExample02.Name = "bExample02"; + this.bExample02.Size = new System.Drawing.Size(88, 23); + this.bExample02.TabIndex = 3; + this.bExample02.Text = "Example 02"; + this.bExample02.UseVisualStyleBackColor = true; + this.bExample02.Click += new System.EventHandler(this.bExample02_Click); + // + // bExample03 + // + this.bExample03.Location = new System.Drawing.Point(281, 483); + this.bExample03.Name = "bExample03"; + this.bExample03.Size = new System.Drawing.Size(88, 23); + this.bExample03.TabIndex = 4; + this.bExample03.Text = "Example 03"; + this.bExample03.UseVisualStyleBackColor = true; + this.bExample03.Click += new System.EventHandler(this.bExample03_Click); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(771, 518); + this.Controls.Add(this.bExample03); + this.Controls.Add(this.bExample02); + this.Controls.Add(this.bOriginal); + this.Controls.Add(this.bExample01); + this.Controls.Add(this.picBox); + this.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "MainForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Sample06"; + ((System.ComponentModel.ISupportInitialize)(this.picBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.PictureBox picBox; + private System.Windows.Forms.Button bExample01; + private System.Windows.Forms.Button bOriginal; + private System.Windows.Forms.Button bExample02; + private System.Windows.Forms.Button bExample03; + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 06 - Converting/MainForm.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 06 - Converting/MainForm.cs index 125b9c3..b7409bb 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 06 - Converting/MainForm.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 06 - Converting/MainForm.cs @@ -1,177 +1,177 @@ -using System; -using System.Drawing; -using System.Windows.Forms; -using FreeImageAPI; -using System.Drawing.Imaging; - -namespace Sample06 -{ - public partial class MainForm : Form - { - [STAThread] - static void Main() - { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); - } - - public MainForm() - { - InitializeComponent(); - } - - private void bExample01_Click(object sender, EventArgs e) - { - // Load bitmap - FIBITMAP dib = FreeImage.LoadEx("Sample.jpg"); - - // Check success - if (dib.IsNull) - { - MessageBox.Show("Could not load Sample.jpg", "Error"); - return; - } - - // Check whether bitmap is 24-bit - if (FreeImage.GetBPP(dib) != 24) - { - MessageBox.Show("Sample.jpg is not 24-bit.", "Error"); - FreeImage.UnloadEx(ref dib); - return; - } - - // Convert the 24-bit bitmap to 8-bit and forcing the result will be greyscale - dib = FreeImage.ConvertColorDepth(dib, FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP | FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE, true); - - if (FreeImage.GetBPP(dib) == 8) - { - // Convert the FreeImage-Bitmap into a .NET bitmap - Bitmap bitmap = FreeImage.GetBitmap(dib); - - // Dispose the bitmap of the pictureBox - if (picBox.Image != null) - { - picBox.Image.Dispose(); - } - - // Assign the bitmap to the picturebox - picBox.Image = bitmap; - } - - // Unload source bitmap - FreeImage.UnloadEx(ref dib); - } - - private void bOriginal_Click(object sender, EventArgs e) - { - // Load bitmap - FIBITMAP dib = FreeImage.LoadEx("Sample.jpg"); - - // Check success - if (dib.IsNull) - { - MessageBox.Show("Could not load Sample.jpg", "Error"); - return; - } - - // Convert the FreeImage-Bitmap into a .NET bitmap - Bitmap bitmap = FreeImage.GetBitmap(dib); - - // Check success - if (bitmap != null) - { - // Dispose old bitmap - if (picBox.Image != null) - { - picBox.Image.Dispose(); - } - - // Assign new bitmap - picBox.Image = bitmap; - } - - // Unload bitmap - FreeImage.UnloadEx(ref dib); - } - - private void bExample02_Click(object sender, EventArgs e) - { - FIBITMAP dib = FreeImage.LoadEx("Sample.jpg"); - - // Check success - if (dib.IsNull) - { - MessageBox.Show("Could not load Sample.jpg", "Error"); - return; - } - - // Convert bitmap to 8 bit - dib = FreeImage.ConvertColorDepth(dib, FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP, true); - - // Check whether conversion succeeded - if (FreeImage.GetBPP(dib) != 8) - { - MessageBox.Show("Converting Sample.jpg to 8-bit failed.", "Error"); - FreeImage.UnloadEx(ref dib); - return; - } - - // Convert the FreeImage-Bitmap into a .NET bitmap - Bitmap bitmap = FreeImage.GetBitmap(dib); - - // Dispose old bitmap - if (picBox.Image != null) - { - picBox.Image.Dispose(); - } - - // Assign new bitmap - picBox.Image = bitmap; - - // Unload bitmap - FreeImage.UnloadEx(ref dib); - } - - private void bExample03_Click(object sender, EventArgs e) - { - // Load bitmap - Bitmap bitmap = (Bitmap)Bitmap.FromFile("Sample.jpg"); - - // Convert the .NET bitmap into a FreeImage-Bitmap - FIBITMAP dib = FreeImage.CreateFromBitmap(bitmap); - - // Unload bitmap - bitmap.Dispose(); - - // Rescale the bitmap - FIBITMAP temp = FreeImage.Rescale(dib, 300, 300, FREE_IMAGE_FILTER.FILTER_BICUBIC); - - // Unload bitmap - FreeImage.UnloadEx(ref dib); - - Random rand = new Random(); - - // Rotate the bitmap - dib = FreeImage.Rotate(temp, rand.NextDouble() * 360d); - - // Unload bitmap - FreeImage.UnloadEx(ref temp); - - // Convert the FreeImage-Bitmap into a .NET bitmap - bitmap = FreeImage.GetBitmap(dib); - - // Unload bitmap - FreeImage.UnloadEx(ref dib); - - // Unload bitmap - if (picBox.Image != null) - { - picBox.Image.Dispose(); - } - - // Assign new bitmap - picBox.Image = bitmap; - } - } +using System; +using System.Drawing; +using System.Windows.Forms; +using FreeImageAPI; +using System.Drawing.Imaging; + +namespace Sample06 +{ + public partial class MainForm : Form + { + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + + public MainForm() + { + InitializeComponent(); + } + + private void bExample01_Click(object sender, EventArgs e) + { + // Load bitmap + FIBITMAP dib = FreeImage.LoadEx("Sample.jpg"); + + // Check success + if (dib.IsNull) + { + MessageBox.Show("Could not load Sample.jpg", "Error"); + return; + } + + // Check whether bitmap is 24-bit + if (FreeImage.GetBPP(dib) != 24) + { + MessageBox.Show("Sample.jpg is not 24-bit.", "Error"); + FreeImage.UnloadEx(ref dib); + return; + } + + // Convert the 24-bit bitmap to 8-bit and forcing the result will be greyscale + dib = FreeImage.ConvertColorDepth(dib, FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP | FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE, true); + + if (FreeImage.GetBPP(dib) == 8) + { + // Convert the FreeImage-Bitmap into a .NET bitmap + Bitmap bitmap = FreeImage.GetBitmap(dib); + + // Dispose the bitmap of the pictureBox + if (picBox.Image != null) + { + picBox.Image.Dispose(); + } + + // Assign the bitmap to the picturebox + picBox.Image = bitmap; + } + + // Unload source bitmap + FreeImage.UnloadEx(ref dib); + } + + private void bOriginal_Click(object sender, EventArgs e) + { + // Load bitmap + FIBITMAP dib = FreeImage.LoadEx("Sample.jpg"); + + // Check success + if (dib.IsNull) + { + MessageBox.Show("Could not load Sample.jpg", "Error"); + return; + } + + // Convert the FreeImage-Bitmap into a .NET bitmap + Bitmap bitmap = FreeImage.GetBitmap(dib); + + // Check success + if (bitmap != null) + { + // Dispose old bitmap + if (picBox.Image != null) + { + picBox.Image.Dispose(); + } + + // Assign new bitmap + picBox.Image = bitmap; + } + + // Unload bitmap + FreeImage.UnloadEx(ref dib); + } + + private void bExample02_Click(object sender, EventArgs e) + { + FIBITMAP dib = FreeImage.LoadEx("Sample.jpg"); + + // Check success + if (dib.IsNull) + { + MessageBox.Show("Could not load Sample.jpg", "Error"); + return; + } + + // Convert bitmap to 8 bit + dib = FreeImage.ConvertColorDepth(dib, FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP, true); + + // Check whether conversion succeeded + if (FreeImage.GetBPP(dib) != 8) + { + MessageBox.Show("Converting Sample.jpg to 8-bit failed.", "Error"); + FreeImage.UnloadEx(ref dib); + return; + } + + // Convert the FreeImage-Bitmap into a .NET bitmap + Bitmap bitmap = FreeImage.GetBitmap(dib); + + // Dispose old bitmap + if (picBox.Image != null) + { + picBox.Image.Dispose(); + } + + // Assign new bitmap + picBox.Image = bitmap; + + // Unload bitmap + FreeImage.UnloadEx(ref dib); + } + + private void bExample03_Click(object sender, EventArgs e) + { + // Load bitmap + Bitmap bitmap = (Bitmap)Bitmap.FromFile("Sample.jpg"); + + // Convert the .NET bitmap into a FreeImage-Bitmap + FIBITMAP dib = FreeImage.CreateFromBitmap(bitmap); + + // Unload bitmap + bitmap.Dispose(); + + // Rescale the bitmap + FIBITMAP temp = FreeImage.Rescale(dib, 300, 300, FREE_IMAGE_FILTER.FILTER_BICUBIC); + + // Unload bitmap + FreeImage.UnloadEx(ref dib); + + Random rand = new Random(); + + // Rotate the bitmap + dib = FreeImage.Rotate(temp, rand.NextDouble() * 360d); + + // Unload bitmap + FreeImage.UnloadEx(ref temp); + + // Convert the FreeImage-Bitmap into a .NET bitmap + bitmap = FreeImage.GetBitmap(dib); + + // Unload bitmap + FreeImage.UnloadEx(ref dib); + + // Unload bitmap + if (picBox.Image != null) + { + picBox.Image.Dispose(); + } + + // Assign new bitmap + picBox.Image = bitmap; + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 06 - Converting/Properties/AssemblyInfo.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 06 - Converting/Properties/AssemblyInfo.cs index 18e8904..ff947dc 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 06 - Converting/Properties/AssemblyInfo.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 06 - Converting/Properties/AssemblyInfo.cs @@ -1,16 +1,16 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("69a8cbdd-43da-49e3-8d0b-2680c4ca2851")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: Guid("69a8cbdd-43da-49e3-8d0b-2680c4ca2851")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 07 - ICC Profiles/Program.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 07 - ICC Profiles/Program.cs index 1b1732f..b03d1f2 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 07 - ICC Profiles/Program.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 07 - ICC Profiles/Program.cs @@ -1,73 +1,73 @@ -using System; -using System.Collections.Generic; -using FreeImageAPI; - -namespace Sample07 -{ - class Program - { - static void Main(string[] args) - { - // Check if FreeImage.dll is available (can be in %path%). - if (!FreeImage.IsAvailable()) - { - Console.WriteLine("FreeImage.dll seems to be missing. Aborting."); - return; - } - - Sample sample = new Sample(); - // This example shows how to work with ICC-Profiles. - sample.Example(); - } - } - - public class Sample - { - public void Example() - { - // Load the sample bitmap. - FIBITMAP dib = FreeImage.LoadEx("Sample.jpg"); - - // Check success - if (dib.IsNull) - { - Console.WriteLine("Sample.jpg could not be loaded. Aborting."); - return; - } - - // Get the bitmaps ICC-Profile. - FIICCPROFILE icc = FreeImage.GetICCProfileEx(dib); - - // Print the profiles address. - Console.WriteLine("The profiles memory-address is : 0x{0}", icc.DataPointer.ToString("X")); - - // Print the profiles size - Console.WriteLine("The profiles size is : {0} bytes", icc.Size); - - // Create data for a new profile. - byte[] data = new byte[256]; - for (int i = 0; i < data.Length; i++) - data[i] = (byte)i; - - // Create the new profile - icc = new FIICCPROFILE(dib, data); - - Console.WriteLine("The profiles memory-address is : 0x{0}", icc.DataPointer.ToString("X")); - Console.WriteLine("The profiles size is : {0} bytes", icc.Size); - - // Create the new profile but only use the first 64 bytes - icc = new FIICCPROFILE(dib, data, 64); - - Console.WriteLine("The profiles memory-address is : 0x{0}", icc.DataPointer.ToString("X")); - Console.WriteLine("The profiles size is : {0} bytes", icc.Size); - - // CreateICCProfileEx(...) does the same as above - icc = FreeImage.CreateICCProfileEx(dib, data, 16); - - Console.WriteLine("The profiles memory-address is : 0x{0}", icc.DataPointer.ToString("X")); - Console.WriteLine("The profiles size is : {0} bytes", icc.Size); - - FreeImage.UnloadEx(ref dib); - } - } -} +using System; +using System.Collections.Generic; +using FreeImageAPI; + +namespace Sample07 +{ + class Program + { + static void Main(string[] args) + { + // Check if FreeImage.dll is available (can be in %path%). + if (!FreeImage.IsAvailable()) + { + Console.WriteLine("FreeImage.dll seems to be missing. Aborting."); + return; + } + + Sample sample = new Sample(); + // This example shows how to work with ICC-Profiles. + sample.Example(); + } + } + + public class Sample + { + public void Example() + { + // Load the sample bitmap. + FIBITMAP dib = FreeImage.LoadEx("Sample.jpg"); + + // Check success + if (dib.IsNull) + { + Console.WriteLine("Sample.jpg could not be loaded. Aborting."); + return; + } + + // Get the bitmaps ICC-Profile. + FIICCPROFILE icc = FreeImage.GetICCProfileEx(dib); + + // Print the profiles address. + Console.WriteLine("The profiles memory-address is : 0x{0}", icc.DataPointer.ToString("X")); + + // Print the profiles size + Console.WriteLine("The profiles size is : {0} bytes", icc.Size); + + // Create data for a new profile. + byte[] data = new byte[256]; + for (int i = 0; i < data.Length; i++) + data[i] = (byte)i; + + // Create the new profile + icc = new FIICCPROFILE(dib, data); + + Console.WriteLine("The profiles memory-address is : 0x{0}", icc.DataPointer.ToString("X")); + Console.WriteLine("The profiles size is : {0} bytes", icc.Size); + + // Create the new profile but only use the first 64 bytes + icc = new FIICCPROFILE(dib, data, 64); + + Console.WriteLine("The profiles memory-address is : 0x{0}", icc.DataPointer.ToString("X")); + Console.WriteLine("The profiles size is : {0} bytes", icc.Size); + + // CreateICCProfileEx(...) does the same as above + icc = FreeImage.CreateICCProfileEx(dib, data, 16); + + Console.WriteLine("The profiles memory-address is : 0x{0}", icc.DataPointer.ToString("X")); + Console.WriteLine("The profiles size is : {0} bytes", icc.Size); + + FreeImage.UnloadEx(ref dib); + } + } +} diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 07 - ICC Profiles/Properties/AssemblyInfo.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 07 - ICC Profiles/Properties/AssemblyInfo.cs index d7f3a03..d1997ae 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 07 - ICC Profiles/Properties/AssemblyInfo.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 07 - ICC Profiles/Properties/AssemblyInfo.cs @@ -1,16 +1,16 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("c9991d1d-684a-4736-b088-369a216b35b6")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: Guid("c9991d1d-684a-4736-b088-369a216b35b6")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/Properties/AssemblyInfo.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/Properties/AssemblyInfo.cs index 2db8f57..b8845e4 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/Properties/AssemblyInfo.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/Properties/AssemblyInfo.cs @@ -1,16 +1,16 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("dc891ffc-ab5c-451f-97da-2c0d5d90edcc")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: Guid("dc891ffc-ab5c-451f-97da-2c0d5d90edcc")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/SampleForm.Designer.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/SampleForm.Designer.cs index 4eafbae..fa4eb4a 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/SampleForm.Designer.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/SampleForm.Designer.cs @@ -1,119 +1,119 @@ -namespace Sample08 -{ - partial class SampleForm - { - /// - /// Erforderliche Designervariable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Verwendete Ressourcen bereinigen. - /// - /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Vom Windows Form-Designer generierter Code - - /// - /// Erforderliche Methode für die Designerunterstützung. - /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. - /// - private void InitializeComponent() - { - this.pictureBox = new System.Windows.Forms.PictureBox(); - this.bLoad = new System.Windows.Forms.Button(); - this.SaveToSer = new System.Windows.Forms.Button(); - this.LoadSerBitmap = new System.Windows.Forms.Button(); - this.bClearBitmap = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); - this.SuspendLayout(); - // - // pictureBox - // - this.pictureBox.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.pictureBox.Location = new System.Drawing.Point(12, 12); - this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(600, 400); - this.pictureBox.TabIndex = 0; - this.pictureBox.TabStop = false; - // - // bLoad - // - this.bLoad.Location = new System.Drawing.Point(12, 418); - this.bLoad.Name = "bLoad"; - this.bLoad.Size = new System.Drawing.Size(98, 23); - this.bLoad.TabIndex = 1; - this.bLoad.Text = "Load any bitmap"; - this.bLoad.UseVisualStyleBackColor = true; - this.bLoad.Click += new System.EventHandler(this.bLoad_Click); - // - // SaveToSer - // - this.SaveToSer.Location = new System.Drawing.Point(324, 418); - this.SaveToSer.Name = "SaveToSer"; - this.SaveToSer.Size = new System.Drawing.Size(98, 23); - this.SaveToSer.TabIndex = 2; - this.SaveToSer.Text = "Save as .ser"; - this.SaveToSer.UseVisualStyleBackColor = true; - this.SaveToSer.Click += new System.EventHandler(this.SaveToSer_Click); - // - // LoadSerBitmap - // - this.LoadSerBitmap.Location = new System.Drawing.Point(220, 418); - this.LoadSerBitmap.Name = "LoadSerBitmap"; - this.LoadSerBitmap.Size = new System.Drawing.Size(98, 23); - this.LoadSerBitmap.TabIndex = 3; - this.LoadSerBitmap.Text = "Load .ser bitmap"; - this.LoadSerBitmap.UseVisualStyleBackColor = true; - this.LoadSerBitmap.Click += new System.EventHandler(this.LoadSerBitmap_Click); - // - // bClearBitmap - // - this.bClearBitmap.Location = new System.Drawing.Point(116, 418); - this.bClearBitmap.Name = "bClearBitmap"; - this.bClearBitmap.Size = new System.Drawing.Size(98, 23); - this.bClearBitmap.TabIndex = 4; - this.bClearBitmap.Text = "Clear screen"; - this.bClearBitmap.UseVisualStyleBackColor = true; - this.bClearBitmap.Click += new System.EventHandler(this.bClearBitmap_Click); - // - // SampleForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(627, 448); - this.Controls.Add(this.bClearBitmap); - this.Controls.Add(this.LoadSerBitmap); - this.Controls.Add(this.SaveToSer); - this.Controls.Add(this.bLoad); - this.Controls.Add(this.pictureBox); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "SampleForm"; - this.ShowIcon = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Sample 08"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.PictureBox pictureBox; - private System.Windows.Forms.Button bLoad; - private System.Windows.Forms.Button SaveToSer; - private System.Windows.Forms.Button LoadSerBitmap; - private System.Windows.Forms.Button bClearBitmap; - } -} - +namespace Sample08 +{ + partial class SampleForm + { + /// + /// Erforderliche Designervariable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Verwendete Ressourcen bereinigen. + /// + /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Windows Form-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() + { + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.bLoad = new System.Windows.Forms.Button(); + this.SaveToSer = new System.Windows.Forms.Button(); + this.LoadSerBitmap = new System.Windows.Forms.Button(); + this.bClearBitmap = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // pictureBox + // + this.pictureBox.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.pictureBox.Location = new System.Drawing.Point(12, 12); + this.pictureBox.Name = "pictureBox"; + this.pictureBox.Size = new System.Drawing.Size(600, 400); + this.pictureBox.TabIndex = 0; + this.pictureBox.TabStop = false; + // + // bLoad + // + this.bLoad.Location = new System.Drawing.Point(12, 418); + this.bLoad.Name = "bLoad"; + this.bLoad.Size = new System.Drawing.Size(98, 23); + this.bLoad.TabIndex = 1; + this.bLoad.Text = "Load any bitmap"; + this.bLoad.UseVisualStyleBackColor = true; + this.bLoad.Click += new System.EventHandler(this.bLoad_Click); + // + // SaveToSer + // + this.SaveToSer.Location = new System.Drawing.Point(324, 418); + this.SaveToSer.Name = "SaveToSer"; + this.SaveToSer.Size = new System.Drawing.Size(98, 23); + this.SaveToSer.TabIndex = 2; + this.SaveToSer.Text = "Save as .ser"; + this.SaveToSer.UseVisualStyleBackColor = true; + this.SaveToSer.Click += new System.EventHandler(this.SaveToSer_Click); + // + // LoadSerBitmap + // + this.LoadSerBitmap.Location = new System.Drawing.Point(220, 418); + this.LoadSerBitmap.Name = "LoadSerBitmap"; + this.LoadSerBitmap.Size = new System.Drawing.Size(98, 23); + this.LoadSerBitmap.TabIndex = 3; + this.LoadSerBitmap.Text = "Load .ser bitmap"; + this.LoadSerBitmap.UseVisualStyleBackColor = true; + this.LoadSerBitmap.Click += new System.EventHandler(this.LoadSerBitmap_Click); + // + // bClearBitmap + // + this.bClearBitmap.Location = new System.Drawing.Point(116, 418); + this.bClearBitmap.Name = "bClearBitmap"; + this.bClearBitmap.Size = new System.Drawing.Size(98, 23); + this.bClearBitmap.TabIndex = 4; + this.bClearBitmap.Text = "Clear screen"; + this.bClearBitmap.UseVisualStyleBackColor = true; + this.bClearBitmap.Click += new System.EventHandler(this.bClearBitmap_Click); + // + // SampleForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(627, 448); + this.Controls.Add(this.bClearBitmap); + this.Controls.Add(this.LoadSerBitmap); + this.Controls.Add(this.SaveToSer); + this.Controls.Add(this.bLoad); + this.Controls.Add(this.pictureBox); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "SampleForm"; + this.ShowIcon = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Sample 08"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.PictureBox pictureBox; + private System.Windows.Forms.Button bLoad; + private System.Windows.Forms.Button SaveToSer; + private System.Windows.Forms.Button LoadSerBitmap; + private System.Windows.Forms.Button bClearBitmap; + } +} + diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/SampleForm.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/SampleForm.cs index 2551f0e..87b83ed 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/SampleForm.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/SampleForm.cs @@ -1,217 +1,217 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; -using System.Text; -using System.Windows.Forms; -using FreeImageAPI; -using System.Runtime.InteropServices; -using System.Security.Permissions; - -namespace Sample08 -{ - public partial class SampleForm : Form - { - SerializationPlugin serialPlugin; - - [STAThread] - static void Main() - { - // Check if FreeImage is available - if (!FreeImage.IsAvailable()) - { - throw new Exception("FreeImage is not available!"); - } - - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new SampleForm()); - } - - public SampleForm() - { - InitializeComponent(); - FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); - - // Creating a new instance of the plugin will register it automatically. - serialPlugin = new SerializationPlugin(); - } - - void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) - { - // Show the message - MessageBox.Show(String.Format("Format: {0}\nMessage: {1}", fif, message), "FreeImage Message"); - } - - private void bLoad_Click(object sender, EventArgs e) - { - // Create a new dialog instance - OpenFileDialog ofd = new OpenFileDialog(); - try - { - // Apply settings - ofd.CheckPathExists = true; - ofd.CheckFileExists = true; - ofd.RestoreDirectory = true; - ofd.Filter = "All files (*.*)|*.*"; - - // Get filename - if (ofd.ShowDialog(this) == DialogResult.OK) - { - Bitmap bitmap = null; - try - { - // Try loading the selected file - // a ser-file will create an exception - bitmap = (Bitmap)Bitmap.FromFile(ofd.FileName); - } - catch - { - MessageBox.Show("Unable to load bitmap from file.", "Error"); - return; - } - - // Unload old bitmap - if (pictureBox.Image != null) - { - pictureBox.Image.Dispose(); - } - - // Set new bitmap - pictureBox.Image = bitmap; - MessageBox.Show("Bitmap loaded successfully", "Success"); - } - else - { - MessageBox.Show("Action aborted."); - } - } - finally - { - // Unload dialog - ofd.Dispose(); - } - } - - private void LoadSerBitmap_Click(object sender, EventArgs e) - { - // Creat a new dialog - OpenFileDialog ofd = new OpenFileDialog(); - - FIBITMAP dib = new FIBITMAP(); - try - { - // Apply settings - ofd.CheckPathExists = true; - ofd.CheckFileExists = true; - ofd.RestoreDirectory = true; - ofd.Filter = "Serialized bitmap (*.ser)|*.ser"; - - // Get filename - if (ofd.ShowDialog() == DialogResult.OK) - { - // Try loading the file forcing the new format - dib = FreeImage.Load(serialPlugin.Format, ofd.FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT); - if (dib.IsNull) - { - MessageBox.Show("Loading bitmap failed", "Error"); - return; - } - - // Convert the loaded bitmap into a .NET bitmap - Bitmap bitmap = FreeImage.GetBitmap(dib); - if (bitmap == null) - { - MessageBox.Show("Converting bitmap failed.", "Error"); - return; - } - - // Unload the picturebox - if (pictureBox.Image != null) - { - pictureBox.Image.Dispose(); - } - - // Apply the loaded bitmap - pictureBox.Image = bitmap; - MessageBox.Show("Bitmap loaded successfully", "Success"); - } - else - { - MessageBox.Show("Action aborted."); - } - } - finally - { - // Unload bitmap - FreeImage.UnloadEx(ref dib); - - // Unload dialog - ofd.Dispose(); - } - } - - private void SaveToSer_Click(object sender, EventArgs e) - { - // Create a new dialog - SaveFileDialog sfd = new SaveFileDialog(); - - FIBITMAP dib = new FIBITMAP(); - try - { - // Check if the picture box contains a bitmap that can be saved. - if (pictureBox.Image == null) - { - MessageBox.Show("No bitmap loaded.", "Error"); - return; - } - - // Convert the picture-boxes bitmap into a FreeImage bitmap. - dib = FreeImage.CreateFromBitmap((Bitmap)pictureBox.Image); - if (dib.IsNull) - { - MessageBox.Show("Unable to convert bitmap to FIBITMAP.", "Error"); - return; - } - - // Apply settings - sfd.Filter = "Serialized bitmap (*.ser)|*.ser"; - sfd.FileName = "Bitmap.ser"; - sfd.OverwritePrompt = true; - sfd.RestoreDirectory = true; - - // Get filename - if (sfd.ShowDialog() == DialogResult.OK) - { - // Save bitmap in the new format - if (FreeImage.SaveEx(dib, sfd.FileName, serialPlugin.Format)) - MessageBox.Show("Bitmap saved successfully.", "Success"); - else - MessageBox.Show("Saving bitmap failed.", "Failure"); - } - else - { - MessageBox.Show("Action aborted."); - } - } - finally - { - // Unload bitmap - FreeImage.UnloadEx(ref dib); - - // Unload dialog - sfd.Dispose(); - } - } - - private void bClearBitmap_Click(object sender, EventArgs e) - { - // Unload the picture-box - if (pictureBox.Image != null) - { - pictureBox.Image.Dispose(); - pictureBox.Image = null; - } - } - } +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using FreeImageAPI; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +namespace Sample08 +{ + public partial class SampleForm : Form + { + SerializationPlugin serialPlugin; + + [STAThread] + static void Main() + { + // Check if FreeImage is available + if (!FreeImage.IsAvailable()) + { + throw new Exception("FreeImage is not available!"); + } + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new SampleForm()); + } + + public SampleForm() + { + InitializeComponent(); + FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); + + // Creating a new instance of the plugin will register it automatically. + serialPlugin = new SerializationPlugin(); + } + + void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) + { + // Show the message + MessageBox.Show(String.Format("Format: {0}\nMessage: {1}", fif, message), "FreeImage Message"); + } + + private void bLoad_Click(object sender, EventArgs e) + { + // Create a new dialog instance + OpenFileDialog ofd = new OpenFileDialog(); + try + { + // Apply settings + ofd.CheckPathExists = true; + ofd.CheckFileExists = true; + ofd.RestoreDirectory = true; + ofd.Filter = "All files (*.*)|*.*"; + + // Get filename + if (ofd.ShowDialog(this) == DialogResult.OK) + { + Bitmap bitmap = null; + try + { + // Try loading the selected file + // a ser-file will create an exception + bitmap = (Bitmap)Bitmap.FromFile(ofd.FileName); + } + catch + { + MessageBox.Show("Unable to load bitmap from file.", "Error"); + return; + } + + // Unload old bitmap + if (pictureBox.Image != null) + { + pictureBox.Image.Dispose(); + } + + // Set new bitmap + pictureBox.Image = bitmap; + MessageBox.Show("Bitmap loaded successfully", "Success"); + } + else + { + MessageBox.Show("Action aborted."); + } + } + finally + { + // Unload dialog + ofd.Dispose(); + } + } + + private void LoadSerBitmap_Click(object sender, EventArgs e) + { + // Creat a new dialog + OpenFileDialog ofd = new OpenFileDialog(); + + FIBITMAP dib = new FIBITMAP(); + try + { + // Apply settings + ofd.CheckPathExists = true; + ofd.CheckFileExists = true; + ofd.RestoreDirectory = true; + ofd.Filter = "Serialized bitmap (*.ser)|*.ser"; + + // Get filename + if (ofd.ShowDialog() == DialogResult.OK) + { + // Try loading the file forcing the new format + dib = FreeImage.Load(serialPlugin.Format, ofd.FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT); + if (dib.IsNull) + { + MessageBox.Show("Loading bitmap failed", "Error"); + return; + } + + // Convert the loaded bitmap into a .NET bitmap + Bitmap bitmap = FreeImage.GetBitmap(dib); + if (bitmap == null) + { + MessageBox.Show("Converting bitmap failed.", "Error"); + return; + } + + // Unload the picturebox + if (pictureBox.Image != null) + { + pictureBox.Image.Dispose(); + } + + // Apply the loaded bitmap + pictureBox.Image = bitmap; + MessageBox.Show("Bitmap loaded successfully", "Success"); + } + else + { + MessageBox.Show("Action aborted."); + } + } + finally + { + // Unload bitmap + FreeImage.UnloadEx(ref dib); + + // Unload dialog + ofd.Dispose(); + } + } + + private void SaveToSer_Click(object sender, EventArgs e) + { + // Create a new dialog + SaveFileDialog sfd = new SaveFileDialog(); + + FIBITMAP dib = new FIBITMAP(); + try + { + // Check if the picture box contains a bitmap that can be saved. + if (pictureBox.Image == null) + { + MessageBox.Show("No bitmap loaded.", "Error"); + return; + } + + // Convert the picture-boxes bitmap into a FreeImage bitmap. + dib = FreeImage.CreateFromBitmap((Bitmap)pictureBox.Image); + if (dib.IsNull) + { + MessageBox.Show("Unable to convert bitmap to FIBITMAP.", "Error"); + return; + } + + // Apply settings + sfd.Filter = "Serialized bitmap (*.ser)|*.ser"; + sfd.FileName = "Bitmap.ser"; + sfd.OverwritePrompt = true; + sfd.RestoreDirectory = true; + + // Get filename + if (sfd.ShowDialog() == DialogResult.OK) + { + // Save bitmap in the new format + if (FreeImage.SaveEx(dib, sfd.FileName, serialPlugin.Format)) + MessageBox.Show("Bitmap saved successfully.", "Success"); + else + MessageBox.Show("Saving bitmap failed.", "Failure"); + } + else + { + MessageBox.Show("Action aborted."); + } + } + finally + { + // Unload bitmap + FreeImage.UnloadEx(ref dib); + + // Unload dialog + sfd.Dispose(); + } + } + + private void bClearBitmap_Click(object sender, EventArgs e) + { + // Unload the picture-box + if (pictureBox.Image != null) + { + pictureBox.Image.Dispose(); + pictureBox.Image = null; + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/SerializationPlugin.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/SerializationPlugin.cs index 96043e0..a8ef7d5 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/SerializationPlugin.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 08 - Creating a plugin/SerializationPlugin.cs @@ -1,222 +1,222 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Runtime.InteropServices; -using System.Runtime.Serialization.Formatters.Binary; -using System.IO; -using System.IO.Compression; -using FreeImageAPI; -using FreeImageAPI.IO; -using FreeImageAPI.Plugins; - -namespace Sample08 -{ - public sealed class SerializationPlugin : LocalPlugin - { - // Header for the file - private byte[] header = new byte[] { 0xff, 0x12, 0x0f, 0xff, 0x01, 0x00 }; - - // Structure that will store all bitmap data. - [Serializable] - private struct SerialDib - { - public uint width; - public uint height; - public int pitch; - public uint bpp; - public uint red_mask; - public uint green_mask; - public uint blue_mask; - public byte[] data; - } - - // Implementation of 'GetImplementedMethods()' - // All implemented methods are listed. - protected override LocalPlugin.MethodFlags GetImplementedMethods() - { - return - MethodFlags.DescriptionProc | - MethodFlags.SupportsExportBPPProc | - MethodFlags.SupportsExportTypeProc | - MethodFlags.SupportsICCProfilesProc | - MethodFlags.LoadProc | - MethodFlags.SaveProc | - MethodFlags.ValidateProc | - MethodFlags.ExtensionListProc; - } - - // Returns a format string. - protected override string FormatProc() - { - return "Serialization"; - } - - // Returns a more specific description - protected override string DescriptionProc() - { - return "Serializes bitmaps for .NET"; - } - - // Returns whether a color depth is supported. - protected override bool SupportsExportBPPProc(int bpp) - { - return ((bpp == 1) || - (bpp == 4) || - (bpp == 8) || - (bpp == 16) || - (bpp == 24) || - (bpp == 32)); - } - - // This plugin can only export standard bitmaps - protected override bool SupportsExportTypeProc(FREE_IMAGE_TYPE type) - { - return (type == FREE_IMAGE_TYPE.FIT_BITMAP); - } - - // This plugin does not support icc profiles - protected override bool SupportsICCProfilesProc() - { - return false; - } - - // The function reads the first bytes of the file and compares it - // with the predefined header. - protected override bool ValidateProc(ref FreeImageIO io, fi_handle handle) - { - for (int i = 0; i < header.Length; i++) - if (ReadByte(io, handle) != header[i]) - return false; - return true; - } - - // Loading function - protected override FIBITMAP LoadProc(ref FreeImageIO io, fi_handle handle, int page, int flags, IntPtr data) - { - // Check if the data has the correct format - if (!ValidateProc(ref io, handle)) - { - // Create a free-image message - FreeImage.OutputMessageProc(format, "Invalid format."); - // return 0 (operation failed) - return FIBITMAP.Zero; - } - - SerialDib sdib; - int read = 0; - System.IO.MemoryStream stream = new System.IO.MemoryStream(); - byte[] buffer = new byte[1024]; - - do - { - // Use the helper function 'Read' to read from the source - read = Read(io, handle, 1, 1024, ref buffer); - - // Store the data in a temporary buffer - stream.Write(buffer, 0, read); - } - while (read != 0); - - // Set the memory stream back to the beginning. - stream.Position = 0; - - // Unzip the stream - GZipStream zipStream = new GZipStream(stream, CompressionMode.Decompress); - - // Create a serializer - BinaryFormatter formatter = new BinaryFormatter(); - - // Deserialize the stream - sdib = (SerialDib)formatter.Deserialize(zipStream); - - // Unload the stream - zipStream.Dispose(); - - // Use 'ConvertFromRawBits and the deserialized struct to recreate the bitmap - // In this case the marshaller is used to create the needed IntPtr to the data - // array. - FIBITMAP dib = FreeImage.ConvertFromRawBits( - Marshal.UnsafeAddrOfPinnedArrayElement(sdib.data, 0), - (int)sdib.width, (int)sdib.height, sdib.pitch, sdib.bpp, - sdib.red_mask, sdib.green_mask, sdib.blue_mask, - false); - - // Unload the temporary stream - stream.Dispose(); - - // Return the created bitmap - return dib; - } - - // Saving function - protected override bool SaveProc(ref FreeImageIO io, FIBITMAP dib, fi_handle handle, int page, int flags, IntPtr data) - { - SerialDib sdib; - uint size = FreeImage.GetDIBSize(dib); - - // Store all data needed to recreate the bitmap - sdib.width = FreeImage.GetWidth(dib); - sdib.height = FreeImage.GetHeight(dib); - sdib.pitch = (int)FreeImage.GetPitch(dib); - sdib.bpp = FreeImage.GetBPP(dib); - sdib.red_mask = FreeImage.GetRedMask(dib); - sdib.green_mask = FreeImage.GetGreenMask(dib); - sdib.blue_mask = FreeImage.GetBlueMask(dib); - sdib.data = new byte[size]; - - // Copy the bitmaps data into the structures byte-array - // The marshaller is used to create an IntPtr for using - // 'ConvertToRawBits'. - FreeImage.ConvertToRawBits(Marshal.UnsafeAddrOfPinnedArrayElement(sdib.data, 0), - dib, sdib.pitch, sdib.bpp, - sdib.red_mask, sdib.green_mask, sdib.blue_mask, - false); - - // Use the healper function to write the header to the destination - if (Write(io, handle, (uint)header.Length, 1, ref header) != 1) - return false; - - // Create a serializer - BinaryFormatter formatter = new BinaryFormatter(); - - // Create a temporary stream - MemoryStream stream = new MemoryStream(); - - // Create a compression stream - GZipStream zipStream = new GZipStream(stream, CompressionMode.Compress); - - // Serialize the structure into the compression stream - formatter.Serialize(zipStream, sdib); - - // Unload the compression stream - zipStream.Dispose(); - - // Get the result data - byte[] buffer = stream.GetBuffer(); - - // Use the healper function 'Write' to write the data to the destination - if (Write(io, handle, 1, (uint)buffer.Length, ref buffer) != buffer.Length) - { - // Unload the temporary stream - stream.Dispose(); - return false; - } - - // Unload the temporary stream - stream.Dispose(); - return true; - } - - // Return a list of supported file extensions (comma seperated) - protected override string ExtensionListProc() - { - return "ser"; - } - - // Implementation of 'ToString()' - public override string ToString() - { - return DescriptionProc(); - } - } -} +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; +using System.Runtime.Serialization.Formatters.Binary; +using System.IO; +using System.IO.Compression; +using FreeImageAPI; +using FreeImageAPI.IO; +using FreeImageAPI.Plugins; + +namespace Sample08 +{ + public sealed class SerializationPlugin : LocalPlugin + { + // Header for the file + private byte[] header = new byte[] { 0xff, 0x12, 0x0f, 0xff, 0x01, 0x00 }; + + // Structure that will store all bitmap data. + [Serializable] + private struct SerialDib + { + public uint width; + public uint height; + public int pitch; + public uint bpp; + public uint red_mask; + public uint green_mask; + public uint blue_mask; + public byte[] data; + } + + // Implementation of 'GetImplementedMethods()' + // All implemented methods are listed. + protected override LocalPlugin.MethodFlags GetImplementedMethods() + { + return + MethodFlags.DescriptionProc | + MethodFlags.SupportsExportBPPProc | + MethodFlags.SupportsExportTypeProc | + MethodFlags.SupportsICCProfilesProc | + MethodFlags.LoadProc | + MethodFlags.SaveProc | + MethodFlags.ValidateProc | + MethodFlags.ExtensionListProc; + } + + // Returns a format string. + protected override string FormatProc() + { + return "Serialization"; + } + + // Returns a more specific description + protected override string DescriptionProc() + { + return "Serializes bitmaps for .NET"; + } + + // Returns whether a color depth is supported. + protected override bool SupportsExportBPPProc(int bpp) + { + return ((bpp == 1) || + (bpp == 4) || + (bpp == 8) || + (bpp == 16) || + (bpp == 24) || + (bpp == 32)); + } + + // This plugin can only export standard bitmaps + protected override bool SupportsExportTypeProc(FREE_IMAGE_TYPE type) + { + return (type == FREE_IMAGE_TYPE.FIT_BITMAP); + } + + // This plugin does not support icc profiles + protected override bool SupportsICCProfilesProc() + { + return false; + } + + // The function reads the first bytes of the file and compares it + // with the predefined header. + protected override bool ValidateProc(ref FreeImageIO io, fi_handle handle) + { + for (int i = 0; i < header.Length; i++) + if (ReadByte(io, handle) != header[i]) + return false; + return true; + } + + // Loading function + protected override FIBITMAP LoadProc(ref FreeImageIO io, fi_handle handle, int page, int flags, IntPtr data) + { + // Check if the data has the correct format + if (!ValidateProc(ref io, handle)) + { + // Create a free-image message + FreeImage.OutputMessageProc(format, "Invalid format."); + // return 0 (operation failed) + return FIBITMAP.Zero; + } + + SerialDib sdib; + int read = 0; + System.IO.MemoryStream stream = new System.IO.MemoryStream(); + byte[] buffer = new byte[1024]; + + do + { + // Use the helper function 'Read' to read from the source + read = Read(io, handle, 1, 1024, ref buffer); + + // Store the data in a temporary buffer + stream.Write(buffer, 0, read); + } + while (read != 0); + + // Set the memory stream back to the beginning. + stream.Position = 0; + + // Unzip the stream + GZipStream zipStream = new GZipStream(stream, CompressionMode.Decompress); + + // Create a serializer + BinaryFormatter formatter = new BinaryFormatter(); + + // Deserialize the stream + sdib = (SerialDib)formatter.Deserialize(zipStream); + + // Unload the stream + zipStream.Dispose(); + + // Use 'ConvertFromRawBits and the deserialized struct to recreate the bitmap + // In this case the marshaller is used to create the needed IntPtr to the data + // array. + FIBITMAP dib = FreeImage.ConvertFromRawBits( + Marshal.UnsafeAddrOfPinnedArrayElement(sdib.data, 0), + (int)sdib.width, (int)sdib.height, sdib.pitch, sdib.bpp, + sdib.red_mask, sdib.green_mask, sdib.blue_mask, + false); + + // Unload the temporary stream + stream.Dispose(); + + // Return the created bitmap + return dib; + } + + // Saving function + protected override bool SaveProc(ref FreeImageIO io, FIBITMAP dib, fi_handle handle, int page, int flags, IntPtr data) + { + SerialDib sdib; + uint size = FreeImage.GetDIBSize(dib); + + // Store all data needed to recreate the bitmap + sdib.width = FreeImage.GetWidth(dib); + sdib.height = FreeImage.GetHeight(dib); + sdib.pitch = (int)FreeImage.GetPitch(dib); + sdib.bpp = FreeImage.GetBPP(dib); + sdib.red_mask = FreeImage.GetRedMask(dib); + sdib.green_mask = FreeImage.GetGreenMask(dib); + sdib.blue_mask = FreeImage.GetBlueMask(dib); + sdib.data = new byte[size]; + + // Copy the bitmaps data into the structures byte-array + // The marshaller is used to create an IntPtr for using + // 'ConvertToRawBits'. + FreeImage.ConvertToRawBits(Marshal.UnsafeAddrOfPinnedArrayElement(sdib.data, 0), + dib, sdib.pitch, sdib.bpp, + sdib.red_mask, sdib.green_mask, sdib.blue_mask, + false); + + // Use the healper function to write the header to the destination + if (Write(io, handle, (uint)header.Length, 1, ref header) != 1) + return false; + + // Create a serializer + BinaryFormatter formatter = new BinaryFormatter(); + + // Create a temporary stream + MemoryStream stream = new MemoryStream(); + + // Create a compression stream + GZipStream zipStream = new GZipStream(stream, CompressionMode.Compress); + + // Serialize the structure into the compression stream + formatter.Serialize(zipStream, sdib); + + // Unload the compression stream + zipStream.Dispose(); + + // Get the result data + byte[] buffer = stream.GetBuffer(); + + // Use the healper function 'Write' to write the data to the destination + if (Write(io, handle, 1, (uint)buffer.Length, ref buffer) != buffer.Length) + { + // Unload the temporary stream + stream.Dispose(); + return false; + } + + // Unload the temporary stream + stream.Dispose(); + return true; + } + + // Return a list of supported file extensions (comma seperated) + protected override string ExtensionListProc() + { + return "ser"; + } + + // Implementation of 'ToString()' + public override string ToString() + { + return DescriptionProc(); + } + } +} diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 09 - Working with streams/Properties/AssemblyInfo.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 09 - Working with streams/Properties/AssemblyInfo.cs index 62165f0..84c3352 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 09 - Working with streams/Properties/AssemblyInfo.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 09 - Working with streams/Properties/AssemblyInfo.cs @@ -1,16 +1,16 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("7f29fbaa-d2b3-4011-b34f-5a109bc282af")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: Guid("7f29fbaa-d2b3-4011-b34f-5a109bc282af")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 09 - Working with streams/SampleForm.Designer.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 09 - Working with streams/SampleForm.Designer.cs index cf4489d..1992092 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 09 - Working with streams/SampleForm.Designer.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 09 - Working with streams/SampleForm.Designer.cs @@ -1,115 +1,115 @@ -namespace Sample09 -{ - partial class SampleForm - { - /// - /// Erforderliche Designervariable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Verwendete Ressourcen bereinigen. - /// - /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Vom Windows Form-Designer generierter Code - - /// - /// Erforderliche Methode für die Designerunterstützung. - /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. - /// - private void InitializeComponent() - { - this.picBox = new System.Windows.Forms.PictureBox(); - this.tbURL = new System.Windows.Forms.TextBox(); - this.lUrl = new System.Windows.Forms.Label(); - this.bLoadUrl = new System.Windows.Forms.Button(); - this.bSave = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.picBox)).BeginInit(); - this.SuspendLayout(); - // - // picBox - // - this.picBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.picBox.Location = new System.Drawing.Point(12, 12); - this.picBox.Name = "picBox"; - this.picBox.Size = new System.Drawing.Size(536, 299); - this.picBox.TabIndex = 0; - this.picBox.TabStop = false; - // - // tbURL - // - this.tbURL.Location = new System.Drawing.Point(155, 317); - this.tbURL.Name = "tbURL"; - this.tbURL.Size = new System.Drawing.Size(393, 20); - this.tbURL.TabIndex = 1; - this.tbURL.Text = "http://freeimage.sourceforge.net/images/logo.jpg"; - // - // lUrl - // - this.lUrl.AutoSize = true; - this.lUrl.Location = new System.Drawing.Point(9, 320); - this.lUrl.Name = "lUrl"; - this.lUrl.Size = new System.Drawing.Size(137, 13); - this.lUrl.TabIndex = 2; - this.lUrl.Text = "Enter the URL of an Image:"; - // - // bLoadUrl - // - this.bLoadUrl.Location = new System.Drawing.Point(12, 344); - this.bLoadUrl.Name = "bLoadUrl"; - this.bLoadUrl.Size = new System.Drawing.Size(75, 23); - this.bLoadUrl.TabIndex = 3; - this.bLoadUrl.Text = "Load URL"; - this.bLoadUrl.UseVisualStyleBackColor = true; - this.bLoadUrl.Click += new System.EventHandler(this.bLoadUrl_Click); - // - // bSave - // - this.bSave.Location = new System.Drawing.Point(93, 344); - this.bSave.Name = "bSave"; - this.bSave.Size = new System.Drawing.Size(75, 23); - this.bSave.TabIndex = 4; - this.bSave.Text = "Save to disk"; - this.bSave.UseVisualStyleBackColor = true; - this.bSave.Click += new System.EventHandler(this.bSave_Click); - // - // SampleForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(560, 379); - this.Controls.Add(this.bSave); - this.Controls.Add(this.bLoadUrl); - this.Controls.Add(this.lUrl); - this.Controls.Add(this.tbURL); - this.Controls.Add(this.picBox); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "SampleForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Sample09"; - ((System.ComponentModel.ISupportInitialize)(this.picBox)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.PictureBox picBox; - private System.Windows.Forms.TextBox tbURL; - private System.Windows.Forms.Label lUrl; - private System.Windows.Forms.Button bLoadUrl; - private System.Windows.Forms.Button bSave; - } +namespace Sample09 +{ + partial class SampleForm + { + /// + /// Erforderliche Designervariable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Verwendete Ressourcen bereinigen. + /// + /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Windows Form-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() + { + this.picBox = new System.Windows.Forms.PictureBox(); + this.tbURL = new System.Windows.Forms.TextBox(); + this.lUrl = new System.Windows.Forms.Label(); + this.bLoadUrl = new System.Windows.Forms.Button(); + this.bSave = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.picBox)).BeginInit(); + this.SuspendLayout(); + // + // picBox + // + this.picBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.picBox.Location = new System.Drawing.Point(12, 12); + this.picBox.Name = "picBox"; + this.picBox.Size = new System.Drawing.Size(536, 299); + this.picBox.TabIndex = 0; + this.picBox.TabStop = false; + // + // tbURL + // + this.tbURL.Location = new System.Drawing.Point(155, 317); + this.tbURL.Name = "tbURL"; + this.tbURL.Size = new System.Drawing.Size(393, 20); + this.tbURL.TabIndex = 1; + this.tbURL.Text = "http://freeimage.sourceforge.net/images/logo.jpg"; + // + // lUrl + // + this.lUrl.AutoSize = true; + this.lUrl.Location = new System.Drawing.Point(9, 320); + this.lUrl.Name = "lUrl"; + this.lUrl.Size = new System.Drawing.Size(137, 13); + this.lUrl.TabIndex = 2; + this.lUrl.Text = "Enter the URL of an Image:"; + // + // bLoadUrl + // + this.bLoadUrl.Location = new System.Drawing.Point(12, 344); + this.bLoadUrl.Name = "bLoadUrl"; + this.bLoadUrl.Size = new System.Drawing.Size(75, 23); + this.bLoadUrl.TabIndex = 3; + this.bLoadUrl.Text = "Load URL"; + this.bLoadUrl.UseVisualStyleBackColor = true; + this.bLoadUrl.Click += new System.EventHandler(this.bLoadUrl_Click); + // + // bSave + // + this.bSave.Location = new System.Drawing.Point(93, 344); + this.bSave.Name = "bSave"; + this.bSave.Size = new System.Drawing.Size(75, 23); + this.bSave.TabIndex = 4; + this.bSave.Text = "Save to disk"; + this.bSave.UseVisualStyleBackColor = true; + this.bSave.Click += new System.EventHandler(this.bSave_Click); + // + // SampleForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(560, 379); + this.Controls.Add(this.bSave); + this.Controls.Add(this.bLoadUrl); + this.Controls.Add(this.lUrl); + this.Controls.Add(this.tbURL); + this.Controls.Add(this.picBox); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "SampleForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Sample09"; + ((System.ComponentModel.ISupportInitialize)(this.picBox)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.PictureBox picBox; + private System.Windows.Forms.TextBox tbURL; + private System.Windows.Forms.Label lUrl; + private System.Windows.Forms.Button bLoadUrl; + private System.Windows.Forms.Button bSave; + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 09 - Working with streams/SampleForm.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 09 - Working with streams/SampleForm.cs index 72af7cf..2440394 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 09 - Working with streams/SampleForm.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 09 - Working with streams/SampleForm.cs @@ -1,147 +1,147 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; -using FreeImageAPI; -using System.Net; -using System.IO; - -namespace Sample09 -{ - public partial class SampleForm : Form - { - [STAThread] - static void Main() - { - // Check if FreeImage is available - if (!FreeImage.IsAvailable()) - { - throw new Exception("FreeImage is not available!"); - } - - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new SampleForm()); - } - - public SampleForm() - { - InitializeComponent(); - } - - private void bLoadUrl_Click(object sender, EventArgs e) - { - // Verify url - if (String.IsNullOrEmpty(tbURL.Text)) - { - MessageBox.Show("Please enter a valid URL.", "Error"); - return; - } - FIBITMAP dib = new FIBITMAP(); - Stream sourceStream = null; - try - { - // Build a stream to read from - WebRequest request = (WebRequest)HttpWebRequest.Create(tbURL.Text); - WebResponse response = request.GetResponse(); - sourceStream = response.GetResponseStream(); - if (sourceStream == null) - { - throw new Exception(); - } - // Load the image from stream - dib = FreeImage.LoadFromStream(sourceStream); - // Check success - if (dib.IsNull) - { - throw new Exception(); - } - // Convert the bitmap into a .NET bitmap - Bitmap bitmap = FreeImage.GetBitmap(dib); - if (bitmap == null) - { - throw new Exception(); - } - // Show the bitmap - if (picBox.Image != null) - { - picBox.Image.Dispose(); - } - picBox.Image = bitmap; - } - catch - { - // Error handling - MessageBox.Show("Error loading URL.", "Error"); - } - finally - { - // Clean up memory - FreeImage.UnloadEx(ref dib); - if (sourceStream != null) sourceStream.Dispose(); - } - } - - private void bSave_Click(object sender, EventArgs e) - { - // Check if there is a loaded bitmap - if (picBox.Image == null) - { - MessageBox.Show("No image loaded.", "Error"); - return; - } - SaveFileDialog sfd = null; - FileStream fStream = null; - FIBITMAP dib = new FIBITMAP(); - try - { - sfd = new SaveFileDialog(); - sfd.CreatePrompt = false; - sfd.FileName = ""; - sfd.Filter = "TIF (*tif)|*.tif"; - sfd.OverwritePrompt = true; - sfd.RestoreDirectory = true; - if (sfd.ShowDialog() == DialogResult.OK) - { - // Convert the .NET bitmap into a FreeImage-Bitmap - dib = FreeImage.CreateFromBitmap((Bitmap)picBox.Image); - if (dib.IsNull) - { - throw new Exception(); - } - // Create a filestream to write to - fStream = new FileStream(sfd.FileName, FileMode.Create); - if (!FreeImage.SaveToStream( - ref dib, - fStream, - FREE_IMAGE_FORMAT.FIF_TIFF, - FREE_IMAGE_SAVE_FLAGS.TIFF_LZW, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - false)) - { - throw new Exception(); - } - MessageBox.Show("Image saved successfully.", "Success"); - } - else - { - MessageBox.Show("Operation aborted.", "Aborted"); - } - } - catch - { - MessageBox.Show("Error saving image.", "Error"); - } - finally - { - // Clean up - if (sfd != null) sfd.Dispose(); - if (fStream != null) fStream.Dispose(); - FreeImage.UnloadEx(ref dib); - } - } - } +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using FreeImageAPI; +using System.Net; +using System.IO; + +namespace Sample09 +{ + public partial class SampleForm : Form + { + [STAThread] + static void Main() + { + // Check if FreeImage is available + if (!FreeImage.IsAvailable()) + { + throw new Exception("FreeImage is not available!"); + } + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new SampleForm()); + } + + public SampleForm() + { + InitializeComponent(); + } + + private void bLoadUrl_Click(object sender, EventArgs e) + { + // Verify url + if (String.IsNullOrEmpty(tbURL.Text)) + { + MessageBox.Show("Please enter a valid URL.", "Error"); + return; + } + FIBITMAP dib = new FIBITMAP(); + Stream sourceStream = null; + try + { + // Build a stream to read from + WebRequest request = (WebRequest)HttpWebRequest.Create(tbURL.Text); + WebResponse response = request.GetResponse(); + sourceStream = response.GetResponseStream(); + if (sourceStream == null) + { + throw new Exception(); + } + // Load the image from stream + dib = FreeImage.LoadFromStream(sourceStream); + // Check success + if (dib.IsNull) + { + throw new Exception(); + } + // Convert the bitmap into a .NET bitmap + Bitmap bitmap = FreeImage.GetBitmap(dib); + if (bitmap == null) + { + throw new Exception(); + } + // Show the bitmap + if (picBox.Image != null) + { + picBox.Image.Dispose(); + } + picBox.Image = bitmap; + } + catch + { + // Error handling + MessageBox.Show("Error loading URL.", "Error"); + } + finally + { + // Clean up memory + FreeImage.UnloadEx(ref dib); + if (sourceStream != null) sourceStream.Dispose(); + } + } + + private void bSave_Click(object sender, EventArgs e) + { + // Check if there is a loaded bitmap + if (picBox.Image == null) + { + MessageBox.Show("No image loaded.", "Error"); + return; + } + SaveFileDialog sfd = null; + FileStream fStream = null; + FIBITMAP dib = new FIBITMAP(); + try + { + sfd = new SaveFileDialog(); + sfd.CreatePrompt = false; + sfd.FileName = ""; + sfd.Filter = "TIF (*tif)|*.tif"; + sfd.OverwritePrompt = true; + sfd.RestoreDirectory = true; + if (sfd.ShowDialog() == DialogResult.OK) + { + // Convert the .NET bitmap into a FreeImage-Bitmap + dib = FreeImage.CreateFromBitmap((Bitmap)picBox.Image); + if (dib.IsNull) + { + throw new Exception(); + } + // Create a filestream to write to + fStream = new FileStream(sfd.FileName, FileMode.Create); + if (!FreeImage.SaveToStream( + ref dib, + fStream, + FREE_IMAGE_FORMAT.FIF_TIFF, + FREE_IMAGE_SAVE_FLAGS.TIFF_LZW, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + false)) + { + throw new Exception(); + } + MessageBox.Show("Image saved successfully.", "Success"); + } + else + { + MessageBox.Show("Operation aborted.", "Aborted"); + } + } + catch + { + MessageBox.Show("Error saving image.", "Error"); + } + finally + { + // Clean up + if (sfd != null) sfd.Dispose(); + if (fStream != null) fStream.Dispose(); + FreeImage.UnloadEx(ref dib); + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 10 - Metadata/MainForm.Designer.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 10 - Metadata/MainForm.Designer.cs index b552724..acbeda0 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 10 - Metadata/MainForm.Designer.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 10 - Metadata/MainForm.Designer.cs @@ -1,87 +1,87 @@ -namespace Sample10 -{ - partial class MainForm - { - /// - /// Erforderliche Designervariable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Verwendete Ressourcen bereinigen. - /// - /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Vom Windows Form-Designer generierter Code - - /// - /// Erforderliche Methode für die Designerunterstützung. - /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. - /// - private void InitializeComponent() - { - this.bLoad = new System.Windows.Forms.Button(); - this.bQuit = new System.Windows.Forms.Button(); - this.tvMetadata = new System.Windows.Forms.TreeView(); - this.SuspendLayout(); - // - // bLoad - // - this.bLoad.Location = new System.Drawing.Point(12, 336); - this.bLoad.Name = "bLoad"; - this.bLoad.Size = new System.Drawing.Size(75, 23); - this.bLoad.TabIndex = 0; - this.bLoad.Text = "Load Image"; - this.bLoad.UseVisualStyleBackColor = true; - this.bLoad.Click += new System.EventHandler(this.bLoad_Click); - // - // bQuit - // - this.bQuit.Location = new System.Drawing.Point(328, 336); - this.bQuit.Name = "bQuit"; - this.bQuit.Size = new System.Drawing.Size(75, 23); - this.bQuit.TabIndex = 1; - this.bQuit.Text = "Quit"; - this.bQuit.UseVisualStyleBackColor = true; - this.bQuit.Click += new System.EventHandler(this.bQuit_Click); - // - // tvMetadata - // - this.tvMetadata.Location = new System.Drawing.Point(12, 12); - this.tvMetadata.Name = "tvMetadata"; - this.tvMetadata.Size = new System.Drawing.Size(389, 318); - this.tvMetadata.TabIndex = 2; - // - // MainForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(415, 371); - this.Controls.Add(this.tvMetadata); - this.Controls.Add(this.bQuit); - this.Controls.Add(this.bLoad); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "MainForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "MainForm"; - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.Button bLoad; - private System.Windows.Forms.Button bQuit; - private System.Windows.Forms.TreeView tvMetadata; - } +namespace Sample10 +{ + partial class MainForm + { + /// + /// Erforderliche Designervariable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Verwendete Ressourcen bereinigen. + /// + /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Windows Form-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() + { + this.bLoad = new System.Windows.Forms.Button(); + this.bQuit = new System.Windows.Forms.Button(); + this.tvMetadata = new System.Windows.Forms.TreeView(); + this.SuspendLayout(); + // + // bLoad + // + this.bLoad.Location = new System.Drawing.Point(12, 336); + this.bLoad.Name = "bLoad"; + this.bLoad.Size = new System.Drawing.Size(75, 23); + this.bLoad.TabIndex = 0; + this.bLoad.Text = "Load Image"; + this.bLoad.UseVisualStyleBackColor = true; + this.bLoad.Click += new System.EventHandler(this.bLoad_Click); + // + // bQuit + // + this.bQuit.Location = new System.Drawing.Point(328, 336); + this.bQuit.Name = "bQuit"; + this.bQuit.Size = new System.Drawing.Size(75, 23); + this.bQuit.TabIndex = 1; + this.bQuit.Text = "Quit"; + this.bQuit.UseVisualStyleBackColor = true; + this.bQuit.Click += new System.EventHandler(this.bQuit_Click); + // + // tvMetadata + // + this.tvMetadata.Location = new System.Drawing.Point(12, 12); + this.tvMetadata.Name = "tvMetadata"; + this.tvMetadata.Size = new System.Drawing.Size(389, 318); + this.tvMetadata.TabIndex = 2; + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(415, 371); + this.Controls.Add(this.tvMetadata); + this.Controls.Add(this.bQuit); + this.Controls.Add(this.bLoad); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "MainForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "MainForm"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button bLoad; + private System.Windows.Forms.Button bQuit; + private System.Windows.Forms.TreeView tvMetadata; + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 10 - Metadata/MainForm.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 10 - Metadata/MainForm.cs index 7ce6021..d97f2ea 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 10 - Metadata/MainForm.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 10 - Metadata/MainForm.cs @@ -1,105 +1,105 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Windows.Forms; -using FreeImageAPI; -using FreeImageAPI.Metadata; - -namespace Sample10 -{ - public partial class MainForm : Form - { - [STAThread] - static void Main() - { - // Check if FreeImage.dll is available - if (!FreeImage.IsAvailable()) - { - MessageBox.Show("FreeImage is not available. Aborting.", "Error"); - } - - // Add this class to the FreeImage-Message-Callback - FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); - - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); - } - - static void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) - { - // Display the data - MessageBox.Show( - String.Format("FreeImage-Message:\n{1}\nFormat:{0}", fif.ToString(), message), - "FreeImage-Message"); - } - - public MainForm() - { - InitializeComponent(); - } - - private void bQuit_Click(object sender, EventArgs e) - { - Application.Exit(); - } - - private void bLoad_Click(object sender, EventArgs e) - { - // Create variables - OpenFileDialog ofd = new OpenFileDialog(); - FIBITMAP dib = new FIBITMAP(); - try - { - // Apply settings - ofd.CheckFileExists = true; - ofd.CheckPathExists = true; - ofd.FileName = ""; - ofd.Filter = "All files (*.*)|*.*"; - ofd.Multiselect = false; - ofd.RestoreDirectory = true; - // Get image filename - if (ofd.ShowDialog() == DialogResult.OK) - { - // Load the image - dib = FreeImage.LoadEx(ofd.FileName); - // Check if image was loaded successfully - if (dib.IsNull) throw new Exception("Failed to load image."); - // Clear the treeview - tvMetadata.Nodes.Clear(); - // Create a wrapper for all metadata the image contains - ImageMetadata iMetadata = new ImageMetadata(dib); - // Get each metadata model - foreach (MetadataModel metadataModel in iMetadata) - { - // Create a new node for each model - TreeNode modelNode = tvMetadata.Nodes.Add(metadataModel.ToString()); - - // Get each metadata tag and create a subnode for it - foreach (MetadataTag metadataTag in metadataModel) - { - modelNode.Nodes.Add(metadataTag.Key + ": " + metadataTag.ToString()); - } - } - } - else - { - MessageBox.Show("Operation aborted.", "Aborted"); - } - } - // Display error message - catch (Exception ex) - { - while (ex.InnerException != null) - ex = ex.InnerException; - MessageBox.Show(ex.ToString(), "Exception caught"); - } - // Clean up - finally - { - ofd.Dispose(); - FreeImage.UnloadEx(ref dib); - } - } - } +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; +using FreeImageAPI; +using FreeImageAPI.Metadata; + +namespace Sample10 +{ + public partial class MainForm : Form + { + [STAThread] + static void Main() + { + // Check if FreeImage.dll is available + if (!FreeImage.IsAvailable()) + { + MessageBox.Show("FreeImage is not available. Aborting.", "Error"); + } + + // Add this class to the FreeImage-Message-Callback + FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + + static void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) + { + // Display the data + MessageBox.Show( + String.Format("FreeImage-Message:\n{1}\nFormat:{0}", fif.ToString(), message), + "FreeImage-Message"); + } + + public MainForm() + { + InitializeComponent(); + } + + private void bQuit_Click(object sender, EventArgs e) + { + Application.Exit(); + } + + private void bLoad_Click(object sender, EventArgs e) + { + // Create variables + OpenFileDialog ofd = new OpenFileDialog(); + FIBITMAP dib = new FIBITMAP(); + try + { + // Apply settings + ofd.CheckFileExists = true; + ofd.CheckPathExists = true; + ofd.FileName = ""; + ofd.Filter = "All files (*.*)|*.*"; + ofd.Multiselect = false; + ofd.RestoreDirectory = true; + // Get image filename + if (ofd.ShowDialog() == DialogResult.OK) + { + // Load the image + dib = FreeImage.LoadEx(ofd.FileName); + // Check if image was loaded successfully + if (dib.IsNull) throw new Exception("Failed to load image."); + // Clear the treeview + tvMetadata.Nodes.Clear(); + // Create a wrapper for all metadata the image contains + ImageMetadata iMetadata = new ImageMetadata(dib); + // Get each metadata model + foreach (MetadataModel metadataModel in iMetadata) + { + // Create a new node for each model + TreeNode modelNode = tvMetadata.Nodes.Add(metadataModel.ToString()); + + // Get each metadata tag and create a subnode for it + foreach (MetadataTag metadataTag in metadataModel) + { + modelNode.Nodes.Add(metadataTag.Key + ": " + metadataTag.ToString()); + } + } + } + else + { + MessageBox.Show("Operation aborted.", "Aborted"); + } + } + // Display error message + catch (Exception ex) + { + while (ex.InnerException != null) + ex = ex.InnerException; + MessageBox.Show(ex.ToString(), "Exception caught"); + } + // Clean up + finally + { + ofd.Dispose(); + FreeImage.UnloadEx(ref dib); + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 10 - Metadata/Properties/AssemblyInfo.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 10 - Metadata/Properties/AssemblyInfo.cs index 67c1d7a..b258d97 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 10 - Metadata/Properties/AssemblyInfo.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 10 - Metadata/Properties/AssemblyInfo.cs @@ -1,16 +1,16 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("e8da4fa8-cc15-4b0e-8c57-d55ceb771559")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: Guid("e8da4fa8-cc15-4b0e-8c57-d55ceb771559")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MainForm.Designer.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MainForm.Designer.cs index 9f2ffe2..52473fa 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MainForm.Designer.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MainForm.Designer.cs @@ -1,382 +1,382 @@ -namespace Sample11 -{ - partial class MainForm - { - /// - /// Erforderliche Designervariable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Verwendete Ressourcen bereinigen. - /// - /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Vom Windows Form-Designer generierter Code - - /// - /// Erforderliche Methode für die Designerunterstützung. - /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. - /// - private void InitializeComponent() - { - this.pictureBox = new System.Windows.Forms.PictureBox(); - this.bLoadImage = new System.Windows.Forms.Button(); - this.bSaveImage = new System.Windows.Forms.Button(); - this.ofd = new System.Windows.Forms.OpenFileDialog(); - this.sfd = new System.Windows.Forms.SaveFileDialog(); - this.lWidth = new System.Windows.Forms.Label(); - this.lHeight = new System.Windows.Forms.Label(); - this.lBpp = new System.Windows.Forms.Label(); - this.lMetadataCount = new System.Windows.Forms.Label(); - this.bGreyscale = new System.Windows.Forms.Button(); - this.cbSelectFrame = new System.Windows.Forms.ComboBox(); - this.lComment = new System.Windows.Forms.Label(); - this.bAdjustGamma = new System.Windows.Forms.Button(); - this.vGamma = new System.Windows.Forms.NumericUpDown(); - this.bRedChannelOnly = new System.Windows.Forms.Button(); - this.bBlueChannel = new System.Windows.Forms.Button(); - this.bGreenChannel = new System.Windows.Forms.Button(); - this.bAllChannels = new System.Windows.Forms.Button(); - this.lSelectFrame = new System.Windows.Forms.Label(); - this.lImageFormat = new System.Windows.Forms.Label(); - this.bRotate = new System.Windows.Forms.Button(); - this.vRotate = new System.Windows.Forms.TrackBar(); - this.lRotate = new System.Windows.Forms.Label(); - this.lColors = new System.Windows.Forms.Label(); - this.nShowMetadata = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.vGamma)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.vRotate)).BeginInit(); - this.SuspendLayout(); - // - // pictureBox - // - this.pictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.pictureBox.Location = new System.Drawing.Point(14, 15); - this.pictureBox.Margin = new System.Windows.Forms.Padding(4); - this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(542, 395); - this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; - this.pictureBox.TabIndex = 0; - this.pictureBox.TabStop = false; - // - // bLoadImage - // - this.bLoadImage.Location = new System.Drawing.Point(564, 15); - this.bLoadImage.Margin = new System.Windows.Forms.Padding(4); - this.bLoadImage.Name = "bLoadImage"; - this.bLoadImage.Size = new System.Drawing.Size(125, 28); - this.bLoadImage.TabIndex = 1; - this.bLoadImage.Text = "Load image"; - this.bLoadImage.UseVisualStyleBackColor = true; - this.bLoadImage.Click += new System.EventHandler(this.bLoadImage_Click); - // - // bSaveImage - // - this.bSaveImage.Location = new System.Drawing.Point(564, 51); - this.bSaveImage.Margin = new System.Windows.Forms.Padding(4); - this.bSaveImage.Name = "bSaveImage"; - this.bSaveImage.Size = new System.Drawing.Size(125, 28); - this.bSaveImage.TabIndex = 2; - this.bSaveImage.Text = "Save image"; - this.bSaveImage.UseVisualStyleBackColor = true; - this.bSaveImage.Click += new System.EventHandler(this.bSaveImage_Click); - // - // ofd - // - this.ofd.AddExtension = false; - this.ofd.AutoUpgradeEnabled = false; - this.ofd.Filter = "All files|*.*"; - this.ofd.RestoreDirectory = true; - this.ofd.SupportMultiDottedExtensions = true; - // - // sfd - // - this.sfd.AddExtension = false; - this.sfd.Filter = "All files|*.*"; - this.sfd.RestoreDirectory = true; - this.sfd.SupportMultiDottedExtensions = true; - // - // lWidth - // - this.lWidth.AutoSize = true; - this.lWidth.Location = new System.Drawing.Point(563, 350); - this.lWidth.Name = "lWidth"; - this.lWidth.Size = new System.Drawing.Size(57, 16); - this.lWidth.TabIndex = 6; - this.lWidth.Text = "Width: 0"; - // - // lHeight - // - this.lHeight.AutoSize = true; - this.lHeight.Location = new System.Drawing.Point(649, 350); - this.lHeight.Name = "lHeight"; - this.lHeight.Size = new System.Drawing.Size(60, 16); - this.lHeight.TabIndex = 7; - this.lHeight.Text = "Height: 0"; - // - // lBpp - // - this.lBpp.AutoSize = true; - this.lBpp.Location = new System.Drawing.Point(740, 350); - this.lBpp.Name = "lBpp"; - this.lBpp.Size = new System.Drawing.Size(45, 16); - this.lBpp.TabIndex = 8; - this.lBpp.Text = "Bpp: 0"; - // - // lMetadataCount - // - this.lMetadataCount.AutoSize = true; - this.lMetadataCount.Location = new System.Drawing.Point(809, 350); - this.lMetadataCount.Name = "lMetadataCount"; - this.lMetadataCount.Size = new System.Drawing.Size(77, 16); - this.lMetadataCount.TabIndex = 9; - this.lMetadataCount.Text = "Metadata: 0"; - // - // bGreyscale - // - this.bGreyscale.Location = new System.Drawing.Point(564, 121); - this.bGreyscale.Name = "bGreyscale"; - this.bGreyscale.Size = new System.Drawing.Size(125, 28); - this.bGreyscale.TabIndex = 10; - this.bGreyscale.Text = "Conv to greyscale"; - this.bGreyscale.UseVisualStyleBackColor = true; - this.bGreyscale.Click += new System.EventHandler(this.bGreyscale_Click); - // - // cbSelectFrame - // - this.cbSelectFrame.FormattingEnabled = true; - this.cbSelectFrame.Location = new System.Drawing.Point(695, 156); - this.cbSelectFrame.Name = "cbSelectFrame"; - this.cbSelectFrame.Size = new System.Drawing.Size(121, 24); - this.cbSelectFrame.TabIndex = 11; - this.cbSelectFrame.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); - // - // lComment - // - this.lComment.AutoSize = true; - this.lComment.Location = new System.Drawing.Point(563, 373); - this.lComment.Name = "lComment"; - this.lComment.Size = new System.Drawing.Size(107, 16); - this.lComment.TabIndex = 12; - this.lComment.Text = "Image-comment:"; - // - // bAdjustGamma - // - this.bAdjustGamma.Location = new System.Drawing.Point(564, 185); - this.bAdjustGamma.Name = "bAdjustGamma"; - this.bAdjustGamma.Size = new System.Drawing.Size(125, 28); - this.bAdjustGamma.TabIndex = 13; - this.bAdjustGamma.Text = "Adjust gamma"; - this.bAdjustGamma.UseVisualStyleBackColor = true; - this.bAdjustGamma.Click += new System.EventHandler(this.bAdjustGamma_Click); - // - // vGamma - // - this.vGamma.DecimalPlaces = 2; - this.vGamma.Increment = new decimal(new int[] { - 0, - 0, - 0, - 0}); - this.vGamma.Location = new System.Drawing.Point(695, 189); - this.vGamma.Maximum = new decimal(new int[] { - 2, - 0, - 0, - 0}); - this.vGamma.Name = "vGamma"; - this.vGamma.Size = new System.Drawing.Size(121, 23); - this.vGamma.TabIndex = 14; - // - // bRedChannelOnly - // - this.bRedChannelOnly.Location = new System.Drawing.Point(564, 219); - this.bRedChannelOnly.Name = "bRedChannelOnly"; - this.bRedChannelOnly.Size = new System.Drawing.Size(125, 28); - this.bRedChannelOnly.TabIndex = 15; - this.bRedChannelOnly.Text = "Red channel"; - this.bRedChannelOnly.UseVisualStyleBackColor = true; - this.bRedChannelOnly.Click += new System.EventHandler(this.bRedChannelOnly_Click); - // - // bBlueChannel - // - this.bBlueChannel.Location = new System.Drawing.Point(564, 287); - this.bBlueChannel.Name = "bBlueChannel"; - this.bBlueChannel.Size = new System.Drawing.Size(125, 28); - this.bBlueChannel.TabIndex = 16; - this.bBlueChannel.Text = "Blue channel"; - this.bBlueChannel.UseVisualStyleBackColor = true; - this.bBlueChannel.Click += new System.EventHandler(this.bBlueChannel_Click); - // - // bGreenChannel - // - this.bGreenChannel.Location = new System.Drawing.Point(564, 253); - this.bGreenChannel.Name = "bGreenChannel"; - this.bGreenChannel.Size = new System.Drawing.Size(125, 28); - this.bGreenChannel.TabIndex = 17; - this.bGreenChannel.Text = "Green channel"; - this.bGreenChannel.UseVisualStyleBackColor = true; - this.bGreenChannel.Click += new System.EventHandler(this.bGreenChannel_Click); - // - // bAllChannels - // - this.bAllChannels.Location = new System.Drawing.Point(563, 321); - this.bAllChannels.Name = "bAllChannels"; - this.bAllChannels.Size = new System.Drawing.Size(126, 28); - this.bAllChannels.TabIndex = 18; - this.bAllChannels.Text = "All channels"; - this.bAllChannels.UseVisualStyleBackColor = true; - this.bAllChannels.Click += new System.EventHandler(this.bAllChannels_Click); - // - // lSelectFrame - // - this.lSelectFrame.AutoSize = true; - this.lSelectFrame.Location = new System.Drawing.Point(563, 159); - this.lSelectFrame.Name = "lSelectFrame"; - this.lSelectFrame.Size = new System.Drawing.Size(86, 16); - this.lSelectFrame.TabIndex = 19; - this.lSelectFrame.Text = "Select frame:"; - // - // lImageFormat - // - this.lImageFormat.AutoSize = true; - this.lImageFormat.Location = new System.Drawing.Point(563, 395); - this.lImageFormat.Name = "lImageFormat"; - this.lImageFormat.Size = new System.Drawing.Size(92, 16); - this.lImageFormat.TabIndex = 20; - this.lImageFormat.Text = "Image-format:"; - // - // bRotate - // - this.bRotate.Location = new System.Drawing.Point(564, 86); - this.bRotate.Name = "bRotate"; - this.bRotate.Size = new System.Drawing.Size(125, 28); - this.bRotate.TabIndex = 21; - this.bRotate.Text = "Rotate"; - this.bRotate.UseVisualStyleBackColor = true; - this.bRotate.Click += new System.EventHandler(this.bRotate_Click); - // - // vRotate - // - this.vRotate.Location = new System.Drawing.Point(695, 80); - this.vRotate.Maximum = 360; - this.vRotate.Name = "vRotate"; - this.vRotate.Size = new System.Drawing.Size(170, 45); - this.vRotate.TabIndex = 22; - this.vRotate.TickFrequency = 10; - this.vRotate.TickStyle = System.Windows.Forms.TickStyle.Both; - this.vRotate.Scroll += new System.EventHandler(this.vRotate_Scroll); - // - // lRotate - // - this.lRotate.AutoSize = true; - this.lRotate.Location = new System.Drawing.Point(871, 92); - this.lRotate.Name = "lRotate"; - this.lRotate.Size = new System.Drawing.Size(15, 16); - this.lRotate.TabIndex = 23; - this.lRotate.Text = "0"; - // - // lColors - // - this.lColors.AutoSize = true; - this.lColors.Location = new System.Drawing.Point(740, 394); - this.lColors.Name = "lColors"; - this.lColors.Size = new System.Drawing.Size(60, 16); - this.lColors.TabIndex = 24; - this.lColors.Text = "Colors: 0"; - // - // nShowMetadata - // - this.nShowMetadata.Location = new System.Drawing.Point(696, 15); - this.nShowMetadata.Name = "nShowMetadata"; - this.nShowMetadata.Size = new System.Drawing.Size(125, 28); - this.nShowMetadata.TabIndex = 25; - this.nShowMetadata.Text = "Show metadata"; - this.nShowMetadata.UseVisualStyleBackColor = true; - this.nShowMetadata.Click += new System.EventHandler(this.nShowMetadata_Click); - // - // MainForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(908, 423); - this.Controls.Add(this.nShowMetadata); - this.Controls.Add(this.lColors); - this.Controls.Add(this.lRotate); - this.Controls.Add(this.vRotate); - this.Controls.Add(this.bRotate); - this.Controls.Add(this.lImageFormat); - this.Controls.Add(this.lSelectFrame); - this.Controls.Add(this.bAllChannels); - this.Controls.Add(this.bGreenChannel); - this.Controls.Add(this.bBlueChannel); - this.Controls.Add(this.bRedChannelOnly); - this.Controls.Add(this.vGamma); - this.Controls.Add(this.bAdjustGamma); - this.Controls.Add(this.lComment); - this.Controls.Add(this.cbSelectFrame); - this.Controls.Add(this.bGreyscale); - this.Controls.Add(this.lMetadataCount); - this.Controls.Add(this.lBpp); - this.Controls.Add(this.lHeight); - this.Controls.Add(this.lWidth); - this.Controls.Add(this.bSaveImage); - this.Controls.Add(this.bLoadImage); - this.Controls.Add(this.pictureBox); - this.DoubleBuffered = true; - this.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.Margin = new System.Windows.Forms.Padding(4); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "MainForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Sample 11"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.vGamma)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.vRotate)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.PictureBox pictureBox; - private System.Windows.Forms.Button bLoadImage; - private System.Windows.Forms.Button bSaveImage; - private System.Windows.Forms.OpenFileDialog ofd; - private System.Windows.Forms.SaveFileDialog sfd; - private System.Windows.Forms.Label lWidth; - private System.Windows.Forms.Label lHeight; - private System.Windows.Forms.Label lBpp; - private System.Windows.Forms.Label lMetadataCount; - private System.Windows.Forms.Button bGreyscale; - private System.Windows.Forms.ComboBox cbSelectFrame; - private System.Windows.Forms.Label lComment; - private System.Windows.Forms.Button bAdjustGamma; - private System.Windows.Forms.NumericUpDown vGamma; - private System.Windows.Forms.Button bRedChannelOnly; - private System.Windows.Forms.Button bBlueChannel; - private System.Windows.Forms.Button bGreenChannel; - private System.Windows.Forms.Button bAllChannels; - private System.Windows.Forms.Label lSelectFrame; - private System.Windows.Forms.Label lImageFormat; - private System.Windows.Forms.Button bRotate; - private System.Windows.Forms.TrackBar vRotate; - private System.Windows.Forms.Label lRotate; - private System.Windows.Forms.Label lColors; - private System.Windows.Forms.Button nShowMetadata; - } -} - +namespace Sample11 +{ + partial class MainForm + { + /// + /// Erforderliche Designervariable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Verwendete Ressourcen bereinigen. + /// + /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Windows Form-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() + { + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.bLoadImage = new System.Windows.Forms.Button(); + this.bSaveImage = new System.Windows.Forms.Button(); + this.ofd = new System.Windows.Forms.OpenFileDialog(); + this.sfd = new System.Windows.Forms.SaveFileDialog(); + this.lWidth = new System.Windows.Forms.Label(); + this.lHeight = new System.Windows.Forms.Label(); + this.lBpp = new System.Windows.Forms.Label(); + this.lMetadataCount = new System.Windows.Forms.Label(); + this.bGreyscale = new System.Windows.Forms.Button(); + this.cbSelectFrame = new System.Windows.Forms.ComboBox(); + this.lComment = new System.Windows.Forms.Label(); + this.bAdjustGamma = new System.Windows.Forms.Button(); + this.vGamma = new System.Windows.Forms.NumericUpDown(); + this.bRedChannelOnly = new System.Windows.Forms.Button(); + this.bBlueChannel = new System.Windows.Forms.Button(); + this.bGreenChannel = new System.Windows.Forms.Button(); + this.bAllChannels = new System.Windows.Forms.Button(); + this.lSelectFrame = new System.Windows.Forms.Label(); + this.lImageFormat = new System.Windows.Forms.Label(); + this.bRotate = new System.Windows.Forms.Button(); + this.vRotate = new System.Windows.Forms.TrackBar(); + this.lRotate = new System.Windows.Forms.Label(); + this.lColors = new System.Windows.Forms.Label(); + this.nShowMetadata = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.vGamma)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.vRotate)).BeginInit(); + this.SuspendLayout(); + // + // pictureBox + // + this.pictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.pictureBox.Location = new System.Drawing.Point(14, 15); + this.pictureBox.Margin = new System.Windows.Forms.Padding(4); + this.pictureBox.Name = "pictureBox"; + this.pictureBox.Size = new System.Drawing.Size(542, 395); + this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.pictureBox.TabIndex = 0; + this.pictureBox.TabStop = false; + // + // bLoadImage + // + this.bLoadImage.Location = new System.Drawing.Point(564, 15); + this.bLoadImage.Margin = new System.Windows.Forms.Padding(4); + this.bLoadImage.Name = "bLoadImage"; + this.bLoadImage.Size = new System.Drawing.Size(125, 28); + this.bLoadImage.TabIndex = 1; + this.bLoadImage.Text = "Load image"; + this.bLoadImage.UseVisualStyleBackColor = true; + this.bLoadImage.Click += new System.EventHandler(this.bLoadImage_Click); + // + // bSaveImage + // + this.bSaveImage.Location = new System.Drawing.Point(564, 51); + this.bSaveImage.Margin = new System.Windows.Forms.Padding(4); + this.bSaveImage.Name = "bSaveImage"; + this.bSaveImage.Size = new System.Drawing.Size(125, 28); + this.bSaveImage.TabIndex = 2; + this.bSaveImage.Text = "Save image"; + this.bSaveImage.UseVisualStyleBackColor = true; + this.bSaveImage.Click += new System.EventHandler(this.bSaveImage_Click); + // + // ofd + // + this.ofd.AddExtension = false; + this.ofd.AutoUpgradeEnabled = false; + this.ofd.Filter = "All files|*.*"; + this.ofd.RestoreDirectory = true; + this.ofd.SupportMultiDottedExtensions = true; + // + // sfd + // + this.sfd.AddExtension = false; + this.sfd.Filter = "All files|*.*"; + this.sfd.RestoreDirectory = true; + this.sfd.SupportMultiDottedExtensions = true; + // + // lWidth + // + this.lWidth.AutoSize = true; + this.lWidth.Location = new System.Drawing.Point(563, 350); + this.lWidth.Name = "lWidth"; + this.lWidth.Size = new System.Drawing.Size(57, 16); + this.lWidth.TabIndex = 6; + this.lWidth.Text = "Width: 0"; + // + // lHeight + // + this.lHeight.AutoSize = true; + this.lHeight.Location = new System.Drawing.Point(649, 350); + this.lHeight.Name = "lHeight"; + this.lHeight.Size = new System.Drawing.Size(60, 16); + this.lHeight.TabIndex = 7; + this.lHeight.Text = "Height: 0"; + // + // lBpp + // + this.lBpp.AutoSize = true; + this.lBpp.Location = new System.Drawing.Point(740, 350); + this.lBpp.Name = "lBpp"; + this.lBpp.Size = new System.Drawing.Size(45, 16); + this.lBpp.TabIndex = 8; + this.lBpp.Text = "Bpp: 0"; + // + // lMetadataCount + // + this.lMetadataCount.AutoSize = true; + this.lMetadataCount.Location = new System.Drawing.Point(809, 350); + this.lMetadataCount.Name = "lMetadataCount"; + this.lMetadataCount.Size = new System.Drawing.Size(77, 16); + this.lMetadataCount.TabIndex = 9; + this.lMetadataCount.Text = "Metadata: 0"; + // + // bGreyscale + // + this.bGreyscale.Location = new System.Drawing.Point(564, 121); + this.bGreyscale.Name = "bGreyscale"; + this.bGreyscale.Size = new System.Drawing.Size(125, 28); + this.bGreyscale.TabIndex = 10; + this.bGreyscale.Text = "Conv to greyscale"; + this.bGreyscale.UseVisualStyleBackColor = true; + this.bGreyscale.Click += new System.EventHandler(this.bGreyscale_Click); + // + // cbSelectFrame + // + this.cbSelectFrame.FormattingEnabled = true; + this.cbSelectFrame.Location = new System.Drawing.Point(695, 156); + this.cbSelectFrame.Name = "cbSelectFrame"; + this.cbSelectFrame.Size = new System.Drawing.Size(121, 24); + this.cbSelectFrame.TabIndex = 11; + this.cbSelectFrame.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); + // + // lComment + // + this.lComment.AutoSize = true; + this.lComment.Location = new System.Drawing.Point(563, 373); + this.lComment.Name = "lComment"; + this.lComment.Size = new System.Drawing.Size(107, 16); + this.lComment.TabIndex = 12; + this.lComment.Text = "Image-comment:"; + // + // bAdjustGamma + // + this.bAdjustGamma.Location = new System.Drawing.Point(564, 185); + this.bAdjustGamma.Name = "bAdjustGamma"; + this.bAdjustGamma.Size = new System.Drawing.Size(125, 28); + this.bAdjustGamma.TabIndex = 13; + this.bAdjustGamma.Text = "Adjust gamma"; + this.bAdjustGamma.UseVisualStyleBackColor = true; + this.bAdjustGamma.Click += new System.EventHandler(this.bAdjustGamma_Click); + // + // vGamma + // + this.vGamma.DecimalPlaces = 2; + this.vGamma.Increment = new decimal(new int[] { + 0, + 0, + 0, + 0}); + this.vGamma.Location = new System.Drawing.Point(695, 189); + this.vGamma.Maximum = new decimal(new int[] { + 2, + 0, + 0, + 0}); + this.vGamma.Name = "vGamma"; + this.vGamma.Size = new System.Drawing.Size(121, 23); + this.vGamma.TabIndex = 14; + // + // bRedChannelOnly + // + this.bRedChannelOnly.Location = new System.Drawing.Point(564, 219); + this.bRedChannelOnly.Name = "bRedChannelOnly"; + this.bRedChannelOnly.Size = new System.Drawing.Size(125, 28); + this.bRedChannelOnly.TabIndex = 15; + this.bRedChannelOnly.Text = "Red channel"; + this.bRedChannelOnly.UseVisualStyleBackColor = true; + this.bRedChannelOnly.Click += new System.EventHandler(this.bRedChannelOnly_Click); + // + // bBlueChannel + // + this.bBlueChannel.Location = new System.Drawing.Point(564, 287); + this.bBlueChannel.Name = "bBlueChannel"; + this.bBlueChannel.Size = new System.Drawing.Size(125, 28); + this.bBlueChannel.TabIndex = 16; + this.bBlueChannel.Text = "Blue channel"; + this.bBlueChannel.UseVisualStyleBackColor = true; + this.bBlueChannel.Click += new System.EventHandler(this.bBlueChannel_Click); + // + // bGreenChannel + // + this.bGreenChannel.Location = new System.Drawing.Point(564, 253); + this.bGreenChannel.Name = "bGreenChannel"; + this.bGreenChannel.Size = new System.Drawing.Size(125, 28); + this.bGreenChannel.TabIndex = 17; + this.bGreenChannel.Text = "Green channel"; + this.bGreenChannel.UseVisualStyleBackColor = true; + this.bGreenChannel.Click += new System.EventHandler(this.bGreenChannel_Click); + // + // bAllChannels + // + this.bAllChannels.Location = new System.Drawing.Point(563, 321); + this.bAllChannels.Name = "bAllChannels"; + this.bAllChannels.Size = new System.Drawing.Size(126, 28); + this.bAllChannels.TabIndex = 18; + this.bAllChannels.Text = "All channels"; + this.bAllChannels.UseVisualStyleBackColor = true; + this.bAllChannels.Click += new System.EventHandler(this.bAllChannels_Click); + // + // lSelectFrame + // + this.lSelectFrame.AutoSize = true; + this.lSelectFrame.Location = new System.Drawing.Point(563, 159); + this.lSelectFrame.Name = "lSelectFrame"; + this.lSelectFrame.Size = new System.Drawing.Size(86, 16); + this.lSelectFrame.TabIndex = 19; + this.lSelectFrame.Text = "Select frame:"; + // + // lImageFormat + // + this.lImageFormat.AutoSize = true; + this.lImageFormat.Location = new System.Drawing.Point(563, 395); + this.lImageFormat.Name = "lImageFormat"; + this.lImageFormat.Size = new System.Drawing.Size(92, 16); + this.lImageFormat.TabIndex = 20; + this.lImageFormat.Text = "Image-format:"; + // + // bRotate + // + this.bRotate.Location = new System.Drawing.Point(564, 86); + this.bRotate.Name = "bRotate"; + this.bRotate.Size = new System.Drawing.Size(125, 28); + this.bRotate.TabIndex = 21; + this.bRotate.Text = "Rotate"; + this.bRotate.UseVisualStyleBackColor = true; + this.bRotate.Click += new System.EventHandler(this.bRotate_Click); + // + // vRotate + // + this.vRotate.Location = new System.Drawing.Point(695, 80); + this.vRotate.Maximum = 360; + this.vRotate.Name = "vRotate"; + this.vRotate.Size = new System.Drawing.Size(170, 45); + this.vRotate.TabIndex = 22; + this.vRotate.TickFrequency = 10; + this.vRotate.TickStyle = System.Windows.Forms.TickStyle.Both; + this.vRotate.Scroll += new System.EventHandler(this.vRotate_Scroll); + // + // lRotate + // + this.lRotate.AutoSize = true; + this.lRotate.Location = new System.Drawing.Point(871, 92); + this.lRotate.Name = "lRotate"; + this.lRotate.Size = new System.Drawing.Size(15, 16); + this.lRotate.TabIndex = 23; + this.lRotate.Text = "0"; + // + // lColors + // + this.lColors.AutoSize = true; + this.lColors.Location = new System.Drawing.Point(740, 394); + this.lColors.Name = "lColors"; + this.lColors.Size = new System.Drawing.Size(60, 16); + this.lColors.TabIndex = 24; + this.lColors.Text = "Colors: 0"; + // + // nShowMetadata + // + this.nShowMetadata.Location = new System.Drawing.Point(696, 15); + this.nShowMetadata.Name = "nShowMetadata"; + this.nShowMetadata.Size = new System.Drawing.Size(125, 28); + this.nShowMetadata.TabIndex = 25; + this.nShowMetadata.Text = "Show metadata"; + this.nShowMetadata.UseVisualStyleBackColor = true; + this.nShowMetadata.Click += new System.EventHandler(this.nShowMetadata_Click); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(908, 423); + this.Controls.Add(this.nShowMetadata); + this.Controls.Add(this.lColors); + this.Controls.Add(this.lRotate); + this.Controls.Add(this.vRotate); + this.Controls.Add(this.bRotate); + this.Controls.Add(this.lImageFormat); + this.Controls.Add(this.lSelectFrame); + this.Controls.Add(this.bAllChannels); + this.Controls.Add(this.bGreenChannel); + this.Controls.Add(this.bBlueChannel); + this.Controls.Add(this.bRedChannelOnly); + this.Controls.Add(this.vGamma); + this.Controls.Add(this.bAdjustGamma); + this.Controls.Add(this.lComment); + this.Controls.Add(this.cbSelectFrame); + this.Controls.Add(this.bGreyscale); + this.Controls.Add(this.lMetadataCount); + this.Controls.Add(this.lBpp); + this.Controls.Add(this.lHeight); + this.Controls.Add(this.lWidth); + this.Controls.Add(this.bSaveImage); + this.Controls.Add(this.bLoadImage); + this.Controls.Add(this.pictureBox); + this.DoubleBuffered = true; + this.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Margin = new System.Windows.Forms.Padding(4); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "MainForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Sample 11"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.vGamma)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.vRotate)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.PictureBox pictureBox; + private System.Windows.Forms.Button bLoadImage; + private System.Windows.Forms.Button bSaveImage; + private System.Windows.Forms.OpenFileDialog ofd; + private System.Windows.Forms.SaveFileDialog sfd; + private System.Windows.Forms.Label lWidth; + private System.Windows.Forms.Label lHeight; + private System.Windows.Forms.Label lBpp; + private System.Windows.Forms.Label lMetadataCount; + private System.Windows.Forms.Button bGreyscale; + private System.Windows.Forms.ComboBox cbSelectFrame; + private System.Windows.Forms.Label lComment; + private System.Windows.Forms.Button bAdjustGamma; + private System.Windows.Forms.NumericUpDown vGamma; + private System.Windows.Forms.Button bRedChannelOnly; + private System.Windows.Forms.Button bBlueChannel; + private System.Windows.Forms.Button bGreenChannel; + private System.Windows.Forms.Button bAllChannels; + private System.Windows.Forms.Label lSelectFrame; + private System.Windows.Forms.Label lImageFormat; + private System.Windows.Forms.Button bRotate; + private System.Windows.Forms.TrackBar vRotate; + private System.Windows.Forms.Label lRotate; + private System.Windows.Forms.Label lColors; + private System.Windows.Forms.Button nShowMetadata; + } +} + diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MainForm.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MainForm.cs index 68a4702..0cb9973 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MainForm.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MainForm.cs @@ -1,412 +1,412 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; -using System.Windows.Forms; -using FreeImageAPI; -using FreeImageAPI.Metadata; -using FreeImageAPI.Plugins; - -namespace Sample11 -{ - public partial class MainForm : Form - { - public MainForm() - { - InitializeComponent(); - } - - [STAThread] - static void Main() - { - // Capture messages generated by FreeImage - FreeImageEngine.Message += new OutputMessageFunction(FreeImageEngine_Message); - - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); - } - - static void FreeImageEngine_Message(FREE_IMAGE_FORMAT fif, string message) - { - // Display the message - // FreeImage continues code executing when all - // addes subscribers of 'Message' finished returned. - MessageBox.Show(message, "FreeImage-Message", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - - // The FreeImageBitmap this sample will work with. - FreeImageBitmap bitmap = null; - - // Replaces the current bitmap with the given one. - private void ReplaceBitmap(FreeImageBitmap newBitmap) - { - // Checks whether the bitmap is usable - if (newBitmap == null || newBitmap.IsDisposed) - { - MessageBox.Show( - "Unexpected error.", - "Error", - MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - - // Check whether the image type of the new bitmap is 'FIT_BITMAP'. - // If not convert to 'FIT_BITMAP'. - if (newBitmap.ImageType != FREE_IMAGE_TYPE.FIT_BITMAP) - { - if (!newBitmap.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true)) - { - MessageBox.Show( - "Error converting bitmap to standard type.", - "Error", - MessageBoxButtons.OK, - MessageBoxIcon.Error); - return; - } - } - - // Dispose the old bitmap only in case it exists and - // the old instance is another than the new one. - if ((bitmap != null) && !object.ReferenceEquals(bitmap, newBitmap)) - { - bitmap.Dispose(); - } - // Dispose the picturebox's bitmap in case it exists. - if (pictureBox.Image != null) - { - pictureBox.Image.Dispose(); - } - - // Set the new bitmap. - pictureBox.Image = (Bitmap)(bitmap = newBitmap); - - // Update gui. - UpdateBitmapInformations(); - UpdateFrameSelection(); - } - - // Get bitmap properties and display them in the gui. - private void UpdateBitmapInformations() - { - if (Bitmap) - { - // Get width - lWidth.Text = String.Format("Width: {0}", bitmap.Width); - // Get Height - lHeight.Text = String.Format("Height: {0}", bitmap.Height); - // Get color depth - lBpp.Text = String.Format("Bpp: {0}", bitmap.ColorDepth); - // Get number of metadata - ImageMetadata mData = bitmap.Metadata; - mData.HideEmptyModels = true; - int mCnt = 0; - foreach (MetadataModel model in mData.List) - { - mCnt += model.Count; - } - lMetadataCount.Text = String.Format("Metadata: {0}", mCnt); - // Get image comment - lComment.Text = String.Format("Image-comment: {0}", bitmap.Comment != null ? bitmap.Comment : String.Empty); - // Get the number of real colors in the image - lColors.Text = String.Format("Colors: {0}", bitmap.UniqueColors); - } - else - { - // Reset all values - lWidth.Text = String.Format("Width: {0}", 0); - lHeight.Text = String.Format("Height: {0}", 0); - lBpp.Text = String.Format("Bpp: {0}", 0); - lMetadataCount.Text = String.Format("Metadata: {0}", 0); - lComment.Text = String.Format("Image-comment: {0}", String.Empty); - lColors.Text = String.Format("Colors: {0}", 0); - } - } - - // Update combobox for frame selection. - private void UpdateFrameSelection() - { - cbSelectFrame.Items.Clear(); - if (Bitmap) - { - // Get number of frames in the bitmap - if (bitmap.FrameCount > 1) - { - // Add an entry for each frame to the combobox - for (int i = 0; i < bitmap.FrameCount; i++) - { - cbSelectFrame.Items.Add(String.Format("Frame {0}", i + 1)); - } - } - } - } - - // Returns true in case the variable 'bitmap' - // is set and not disposed. - private bool Bitmap - { - get { return ((bitmap != null) && (!bitmap.IsDisposed)); } - } - - private void bLoadImage_Click(object sender, EventArgs e) - { - if (ofd.ShowDialog() == DialogResult.OK) - { - try - { - // Load the file using autodetection - FreeImageBitmap fib = new FreeImageBitmap(ofd.FileName); - // Rescale the image so that it fits the picturebox - // Get the plugin that was used to load the bitmap - FreeImagePlugin plug = PluginRepository.Plugin(fib.ImageFormat); - lImageFormat.Text = String.Format("Image-format: {0}", plug.Format); - // Replace the existing bitmap with the new one - ReplaceBitmap(fib); - } - catch - { - } - } - } - - private void bSaveImage_Click(object sender, EventArgs e) - { - if (pictureBox.Image != null) - { - try - { - if (sfd.ShowDialog() == DialogResult.OK) - { - // Save the bitmap using autodetection - using (FreeImageBitmap temp = new FreeImageBitmap(pictureBox.Image)) - { - temp.Save(sfd.FileName); - } - } - } - catch - { - } - } - } - - private void bRotate_Click(object sender, EventArgs e) - { - if (Bitmap) - { - // Create a temporary rescaled bitmap - using (FreeImageBitmap temp = bitmap.GetScaledInstance( - pictureBox.DisplayRectangle.Width, pictureBox.DisplayRectangle.Height, - FREE_IMAGE_FILTER.FILTER_CATMULLROM)) - { - if (temp != null) - { - // Rotate the bitmap - temp.Rotate((double)vRotate.Value); - if (pictureBox.Image != null) - { - pictureBox.Image.Dispose(); - } - // Display the result - pictureBox.Image = (Bitmap)temp; - } - } - } - } - - private void bGreyscale_Click(object sender, EventArgs e) - { - if (Bitmap) - { - // Convert the bitmap to 8bpp and greyscale - ReplaceBitmap(bitmap.GetColorConvertedInstance( - FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP | - FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE)); - } - } - - private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) - { - ComboBox cb = sender as ComboBox; - if ((cb != null) && (cb.Items.Count > 0)) - { - if (Bitmap) - { - try - { - // Switch the selected frame - bitmap.SelectActiveFrame(cb.SelectedIndex); - ReplaceBitmap(bitmap); - } - catch (ArgumentOutOfRangeException) - { - MessageBox.Show("Error changing frame.", "Error"); - } - } - } - } - - private void bAdjustGamma_Click(object sender, EventArgs e) - { - if (Bitmap) - { - // Adjust the gamma value - bitmap.AdjustGamma((double)vGamma.Value); - ReplaceBitmap(bitmap); - } - } - - private void bRedChannelOnly_Click(object sender, EventArgs e) - { - // Mask out green and blue - SetColorChannels(0xFF, 0x00, 0x00); - } - - private void bGreenChannel_Click(object sender, EventArgs e) - { - // Mask out red and blue - SetColorChannels(0x00, 0xFF, 0x00); - } - - private void bBlueChannel_Click(object sender, EventArgs e) - { - // Mask out red and green - SetColorChannels(0x00, 0x00, 0xFF); - } - - private void bAllChannels_Click(object sender, EventArgs e) - { - if (Bitmap) - { - // Restore the bitmap using the original - ReplaceBitmap(bitmap); - } - } - - private void SetColorChannels(int redmask, int greenmask, int bluemask) - { - if (Bitmap) - { - // Create a temporary clone. - using (FreeImageBitmap bitmap = (FreeImageBitmap)this.bitmap.Clone()) - { - if (bitmap != null) - { - // Check whether the bitmap has a palette - if (bitmap.HasPalette) - { - // Use the Palette class to handle the bitmap's - // palette. A palette always consist of RGBQUADs. - Palette palette = bitmap.Palette; - // Apply the new values for all three color components. - for (int i = 0; i < palette.Length; i++) - { - RGBQUAD rgbq = palette[i]; - - rgbq.rgbRed = (byte)(rgbq.rgbRed & redmask); - rgbq.rgbGreen = (byte)(rgbq.rgbGreen & greenmask); - rgbq.rgbBlue = (byte)(rgbq.rgbBlue & bluemask); - - palette[i] = rgbq; - } - } - // In case the bitmap has no palette it must have a color depth - // of 16, 24 or 32. Each color depth needs a different wrapping - // structure for the bitmaps data. These structures can be accessed - // by using the foreach clause. - else if (bitmap.ColorDepth == 16) - { - // Iterate over each scanline - // For 16bpp use either Scanline or Scanline - if (bitmap.IsRGB555) - { - foreach (Scanline scanline in bitmap) - { - for (int x = 0; x < scanline.Length; x++) - { - FI16RGB555 pixel = scanline[x]; - pixel.Red = (byte)(pixel.Red & redmask); - pixel.Green = (byte)(pixel.Green & greenmask); - pixel.Blue = (byte)(pixel.Blue & bluemask); - scanline[x] = pixel; - } - } - } - else if (bitmap.IsRGB565) - { - foreach (Scanline scanline in bitmap) - { - for (int x = 0; x < scanline.Length; x++) - { - FI16RGB565 pixel = scanline[x]; - pixel.Red = (byte)(pixel.Red & redmask); - pixel.Green = (byte)(pixel.Green & greenmask); - pixel.Blue = (byte)(pixel.Blue & bluemask); - scanline[x] = pixel; - } - } - } - } - else if (bitmap.ColorDepth == 24) - { - // Iterate over each scanline - // For 24bpp Scanline must be used - foreach (Scanline scanline in bitmap) - { - for (int x = 0; x < scanline.Length; x++) - { - RGBTRIPLE pixel = scanline[x]; - pixel.rgbtRed = (byte)(pixel.rgbtRed & redmask); - pixel.rgbtGreen = (byte)(pixel.rgbtGreen & greenmask); - pixel.rgbtBlue = (byte)(pixel.rgbtBlue & bluemask); - scanline[x] = pixel; - } - } - } - else if (bitmap.ColorDepth == 32) - { - // Iterate over each scanline - // For 32bpp Scanline must be used - foreach (Scanline scanline in bitmap) - { - for (int x = 0; x < scanline.Length; x++) - { - RGBQUAD pixel = scanline[x]; - pixel.rgbRed = (byte)(pixel.rgbRed & redmask); - pixel.rgbGreen = (byte)(pixel.rgbGreen & greenmask); - pixel.rgbBlue = (byte)(pixel.rgbBlue & bluemask); - scanline[x] = pixel; - } - } - } - // Dispose only the picturebox's bitmap - if (pictureBox.Image != null) - { - pictureBox.Image.Dispose(); - } - pictureBox.Image = (Bitmap)bitmap; - } - } - } - } - - private void vRotate_Scroll(object sender, EventArgs e) - { - TrackBar bar = sender as TrackBar; - if (bar != null) - { - lRotate.Text = bar.Value.ToString(); - } - } - - private void nShowMetadata_Click(object sender, EventArgs e) - { - if (Bitmap) - { - MetaDataFrame mFrame = new MetaDataFrame(); - mFrame.Tag = bitmap.Metadata; - mFrame.ShowDialog(this); - } - } - } +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Windows.Forms; +using FreeImageAPI; +using FreeImageAPI.Metadata; +using FreeImageAPI.Plugins; + +namespace Sample11 +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + } + + [STAThread] + static void Main() + { + // Capture messages generated by FreeImage + FreeImageEngine.Message += new OutputMessageFunction(FreeImageEngine_Message); + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + + static void FreeImageEngine_Message(FREE_IMAGE_FORMAT fif, string message) + { + // Display the message + // FreeImage continues code executing when all + // addes subscribers of 'Message' finished returned. + MessageBox.Show(message, "FreeImage-Message", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + // The FreeImageBitmap this sample will work with. + FreeImageBitmap bitmap = null; + + // Replaces the current bitmap with the given one. + private void ReplaceBitmap(FreeImageBitmap newBitmap) + { + // Checks whether the bitmap is usable + if (newBitmap == null || newBitmap.IsDisposed) + { + MessageBox.Show( + "Unexpected error.", + "Error", + MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + // Check whether the image type of the new bitmap is 'FIT_BITMAP'. + // If not convert to 'FIT_BITMAP'. + if (newBitmap.ImageType != FREE_IMAGE_TYPE.FIT_BITMAP) + { + if (!newBitmap.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true)) + { + MessageBox.Show( + "Error converting bitmap to standard type.", + "Error", + MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + } + + // Dispose the old bitmap only in case it exists and + // the old instance is another than the new one. + if ((bitmap != null) && !object.ReferenceEquals(bitmap, newBitmap)) + { + bitmap.Dispose(); + } + // Dispose the picturebox's bitmap in case it exists. + if (pictureBox.Image != null) + { + pictureBox.Image.Dispose(); + } + + // Set the new bitmap. + pictureBox.Image = (Bitmap)(bitmap = newBitmap); + + // Update gui. + UpdateBitmapInformations(); + UpdateFrameSelection(); + } + + // Get bitmap properties and display them in the gui. + private void UpdateBitmapInformations() + { + if (Bitmap) + { + // Get width + lWidth.Text = String.Format("Width: {0}", bitmap.Width); + // Get Height + lHeight.Text = String.Format("Height: {0}", bitmap.Height); + // Get color depth + lBpp.Text = String.Format("Bpp: {0}", bitmap.ColorDepth); + // Get number of metadata + ImageMetadata mData = bitmap.Metadata; + mData.HideEmptyModels = true; + int mCnt = 0; + foreach (MetadataModel model in mData.List) + { + mCnt += model.Count; + } + lMetadataCount.Text = String.Format("Metadata: {0}", mCnt); + // Get image comment + lComment.Text = String.Format("Image-comment: {0}", bitmap.Comment != null ? bitmap.Comment : String.Empty); + // Get the number of real colors in the image + lColors.Text = String.Format("Colors: {0}", bitmap.UniqueColors); + } + else + { + // Reset all values + lWidth.Text = String.Format("Width: {0}", 0); + lHeight.Text = String.Format("Height: {0}", 0); + lBpp.Text = String.Format("Bpp: {0}", 0); + lMetadataCount.Text = String.Format("Metadata: {0}", 0); + lComment.Text = String.Format("Image-comment: {0}", String.Empty); + lColors.Text = String.Format("Colors: {0}", 0); + } + } + + // Update combobox for frame selection. + private void UpdateFrameSelection() + { + cbSelectFrame.Items.Clear(); + if (Bitmap) + { + // Get number of frames in the bitmap + if (bitmap.FrameCount > 1) + { + // Add an entry for each frame to the combobox + for (int i = 0; i < bitmap.FrameCount; i++) + { + cbSelectFrame.Items.Add(String.Format("Frame {0}", i + 1)); + } + } + } + } + + // Returns true in case the variable 'bitmap' + // is set and not disposed. + private bool Bitmap + { + get { return ((bitmap != null) && (!bitmap.IsDisposed)); } + } + + private void bLoadImage_Click(object sender, EventArgs e) + { + if (ofd.ShowDialog() == DialogResult.OK) + { + try + { + // Load the file using autodetection + FreeImageBitmap fib = new FreeImageBitmap(ofd.FileName); + // Rescale the image so that it fits the picturebox + // Get the plugin that was used to load the bitmap + FreeImagePlugin plug = PluginRepository.Plugin(fib.ImageFormat); + lImageFormat.Text = String.Format("Image-format: {0}", plug.Format); + // Replace the existing bitmap with the new one + ReplaceBitmap(fib); + } + catch + { + } + } + } + + private void bSaveImage_Click(object sender, EventArgs e) + { + if (pictureBox.Image != null) + { + try + { + if (sfd.ShowDialog() == DialogResult.OK) + { + // Save the bitmap using autodetection + using (FreeImageBitmap temp = new FreeImageBitmap(pictureBox.Image)) + { + temp.Save(sfd.FileName); + } + } + } + catch + { + } + } + } + + private void bRotate_Click(object sender, EventArgs e) + { + if (Bitmap) + { + // Create a temporary rescaled bitmap + using (FreeImageBitmap temp = bitmap.GetScaledInstance( + pictureBox.DisplayRectangle.Width, pictureBox.DisplayRectangle.Height, + FREE_IMAGE_FILTER.FILTER_CATMULLROM)) + { + if (temp != null) + { + // Rotate the bitmap + temp.Rotate((double)vRotate.Value); + if (pictureBox.Image != null) + { + pictureBox.Image.Dispose(); + } + // Display the result + pictureBox.Image = (Bitmap)temp; + } + } + } + } + + private void bGreyscale_Click(object sender, EventArgs e) + { + if (Bitmap) + { + // Convert the bitmap to 8bpp and greyscale + ReplaceBitmap(bitmap.GetColorConvertedInstance( + FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP | + FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE)); + } + } + + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) + { + ComboBox cb = sender as ComboBox; + if ((cb != null) && (cb.Items.Count > 0)) + { + if (Bitmap) + { + try + { + // Switch the selected frame + bitmap.SelectActiveFrame(cb.SelectedIndex); + ReplaceBitmap(bitmap); + } + catch (ArgumentOutOfRangeException) + { + MessageBox.Show("Error changing frame.", "Error"); + } + } + } + } + + private void bAdjustGamma_Click(object sender, EventArgs e) + { + if (Bitmap) + { + // Adjust the gamma value + bitmap.AdjustGamma((double)vGamma.Value); + ReplaceBitmap(bitmap); + } + } + + private void bRedChannelOnly_Click(object sender, EventArgs e) + { + // Mask out green and blue + SetColorChannels(0xFF, 0x00, 0x00); + } + + private void bGreenChannel_Click(object sender, EventArgs e) + { + // Mask out red and blue + SetColorChannels(0x00, 0xFF, 0x00); + } + + private void bBlueChannel_Click(object sender, EventArgs e) + { + // Mask out red and green + SetColorChannels(0x00, 0x00, 0xFF); + } + + private void bAllChannels_Click(object sender, EventArgs e) + { + if (Bitmap) + { + // Restore the bitmap using the original + ReplaceBitmap(bitmap); + } + } + + private void SetColorChannels(int redmask, int greenmask, int bluemask) + { + if (Bitmap) + { + // Create a temporary clone. + using (FreeImageBitmap bitmap = (FreeImageBitmap)this.bitmap.Clone()) + { + if (bitmap != null) + { + // Check whether the bitmap has a palette + if (bitmap.HasPalette) + { + // Use the Palette class to handle the bitmap's + // palette. A palette always consist of RGBQUADs. + Palette palette = bitmap.Palette; + // Apply the new values for all three color components. + for (int i = 0; i < palette.Length; i++) + { + RGBQUAD rgbq = palette[i]; + + rgbq.rgbRed = (byte)(rgbq.rgbRed & redmask); + rgbq.rgbGreen = (byte)(rgbq.rgbGreen & greenmask); + rgbq.rgbBlue = (byte)(rgbq.rgbBlue & bluemask); + + palette[i] = rgbq; + } + } + // In case the bitmap has no palette it must have a color depth + // of 16, 24 or 32. Each color depth needs a different wrapping + // structure for the bitmaps data. These structures can be accessed + // by using the foreach clause. + else if (bitmap.ColorDepth == 16) + { + // Iterate over each scanline + // For 16bpp use either Scanline or Scanline + if (bitmap.IsRGB555) + { + foreach (Scanline scanline in bitmap) + { + for (int x = 0; x < scanline.Length; x++) + { + FI16RGB555 pixel = scanline[x]; + pixel.Red = (byte)(pixel.Red & redmask); + pixel.Green = (byte)(pixel.Green & greenmask); + pixel.Blue = (byte)(pixel.Blue & bluemask); + scanline[x] = pixel; + } + } + } + else if (bitmap.IsRGB565) + { + foreach (Scanline scanline in bitmap) + { + for (int x = 0; x < scanline.Length; x++) + { + FI16RGB565 pixel = scanline[x]; + pixel.Red = (byte)(pixel.Red & redmask); + pixel.Green = (byte)(pixel.Green & greenmask); + pixel.Blue = (byte)(pixel.Blue & bluemask); + scanline[x] = pixel; + } + } + } + } + else if (bitmap.ColorDepth == 24) + { + // Iterate over each scanline + // For 24bpp Scanline must be used + foreach (Scanline scanline in bitmap) + { + for (int x = 0; x < scanline.Length; x++) + { + RGBTRIPLE pixel = scanline[x]; + pixel.rgbtRed = (byte)(pixel.rgbtRed & redmask); + pixel.rgbtGreen = (byte)(pixel.rgbtGreen & greenmask); + pixel.rgbtBlue = (byte)(pixel.rgbtBlue & bluemask); + scanline[x] = pixel; + } + } + } + else if (bitmap.ColorDepth == 32) + { + // Iterate over each scanline + // For 32bpp Scanline must be used + foreach (Scanline scanline in bitmap) + { + for (int x = 0; x < scanline.Length; x++) + { + RGBQUAD pixel = scanline[x]; + pixel.rgbRed = (byte)(pixel.rgbRed & redmask); + pixel.rgbGreen = (byte)(pixel.rgbGreen & greenmask); + pixel.rgbBlue = (byte)(pixel.rgbBlue & bluemask); + scanline[x] = pixel; + } + } + } + // Dispose only the picturebox's bitmap + if (pictureBox.Image != null) + { + pictureBox.Image.Dispose(); + } + pictureBox.Image = (Bitmap)bitmap; + } + } + } + } + + private void vRotate_Scroll(object sender, EventArgs e) + { + TrackBar bar = sender as TrackBar; + if (bar != null) + { + lRotate.Text = bar.Value.ToString(); + } + } + + private void nShowMetadata_Click(object sender, EventArgs e) + { + if (Bitmap) + { + MetaDataFrame mFrame = new MetaDataFrame(); + mFrame.Tag = bitmap.Metadata; + mFrame.ShowDialog(this); + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MetaDataFrame.Designer.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MetaDataFrame.Designer.cs index 12c1031..6c723e4 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MetaDataFrame.Designer.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MetaDataFrame.Designer.cs @@ -1,63 +1,63 @@ -namespace Sample11 -{ - partial class MetaDataFrame - { - /// - /// Erforderliche Designervariable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Verwendete Ressourcen bereinigen. - /// - /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Vom Windows Form-Designer generierter Code - - /// - /// Erforderliche Methode für die Designerunterstützung. - /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. - /// - private void InitializeComponent() - { - this.tvMetadata = new System.Windows.Forms.TreeView(); - this.SuspendLayout(); - // - // tvMetadata - // - this.tvMetadata.Location = new System.Drawing.Point(12, 12); - this.tvMetadata.Name = "tvMetadata"; - this.tvMetadata.Size = new System.Drawing.Size(389, 318); - this.tvMetadata.TabIndex = 3; - // - // MetaDataFrame - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(417, 349); - this.Controls.Add(this.tvMetadata); - this.DoubleBuffered = true; - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "MetaDataFrame"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Metadata"; - this.Load += new System.EventHandler(this.MetaDataFrame_Load); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.TreeView tvMetadata; - } +namespace Sample11 +{ + partial class MetaDataFrame + { + /// + /// Erforderliche Designervariable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Verwendete Ressourcen bereinigen. + /// + /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Windows Form-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() + { + this.tvMetadata = new System.Windows.Forms.TreeView(); + this.SuspendLayout(); + // + // tvMetadata + // + this.tvMetadata.Location = new System.Drawing.Point(12, 12); + this.tvMetadata.Name = "tvMetadata"; + this.tvMetadata.Size = new System.Drawing.Size(389, 318); + this.tvMetadata.TabIndex = 3; + // + // MetaDataFrame + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(417, 349); + this.Controls.Add(this.tvMetadata); + this.DoubleBuffered = true; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "MetaDataFrame"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Metadata"; + this.Load += new System.EventHandler(this.MetaDataFrame_Load); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TreeView tvMetadata; + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MetaDataFrame.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MetaDataFrame.cs index 77e670b..57ba257 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MetaDataFrame.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/MetaDataFrame.cs @@ -1,49 +1,49 @@ -using System; -using System.ComponentModel; -using System.Windows.Forms; -using FreeImageAPI; -using FreeImageAPI.Metadata; - -namespace Sample11 -{ - public partial class MetaDataFrame : Form - { - public MetaDataFrame() - { - InitializeComponent(); - } - - private void MetaDataFrame_Load(object sender, EventArgs e) - { - ImageMetadata iMetadata = this.Tag as ImageMetadata; - if (iMetadata != null) - { - bool backup = iMetadata.HideEmptyModels; - iMetadata.HideEmptyModels = false; - try - { - // Get each metadata model - foreach (MetadataModel metadataModel in iMetadata) - { - // Create a new node for each model - TreeNode modelNode = tvMetadata.Nodes.Add(metadataModel.ToString()); - - // Get each metadata tag and create a subnode for it - foreach (MetadataTag metadataTag in metadataModel) - { - modelNode.Nodes.Add(metadataTag.Key + ": " + metadataTag.ToString()); - } - } - } - // Display error message - catch (Exception ex) - { - while (ex.InnerException != null) - ex = ex.InnerException; - MessageBox.Show(ex.ToString(), "Exception caught"); - } - iMetadata.HideEmptyModels = backup; - } - } - } +using System; +using System.ComponentModel; +using System.Windows.Forms; +using FreeImageAPI; +using FreeImageAPI.Metadata; + +namespace Sample11 +{ + public partial class MetaDataFrame : Form + { + public MetaDataFrame() + { + InitializeComponent(); + } + + private void MetaDataFrame_Load(object sender, EventArgs e) + { + ImageMetadata iMetadata = this.Tag as ImageMetadata; + if (iMetadata != null) + { + bool backup = iMetadata.HideEmptyModels; + iMetadata.HideEmptyModels = false; + try + { + // Get each metadata model + foreach (MetadataModel metadataModel in iMetadata) + { + // Create a new node for each model + TreeNode modelNode = tvMetadata.Nodes.Add(metadataModel.ToString()); + + // Get each metadata tag and create a subnode for it + foreach (MetadataTag metadataTag in metadataModel) + { + modelNode.Nodes.Add(metadataTag.Key + ": " + metadataTag.ToString()); + } + } + } + // Display error message + catch (Exception ex) + { + while (ex.InnerException != null) + ex = ex.InnerException; + MessageBox.Show(ex.ToString(), "Exception caught"); + } + iMetadata.HideEmptyModels = backup; + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/Properties/AssemblyInfo.cs b/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/Properties/AssemblyInfo.cs index ce7c549..9866fee 100644 --- a/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/Properties/AssemblyInfo.cs +++ b/Wrapper/FreeImage.NET/cs/Samples/Sample 11 - Using the FreeImageBitmap class/Properties/AssemblyInfo.cs @@ -1,16 +1,16 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("219019e1-9a57-46c7-b9d7-3928a9277fd6")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: Guid("219019e1-9a57-46c7-b9d7-3928a9277fd6")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wrapper/FreeImage.NET/cs/SourceFileMerger/FreeImage.cs.template b/Wrapper/FreeImage.NET/cs/SourceFileMerger/FreeImage.cs.template index f02974d..9670741 100644 --- a/Wrapper/FreeImage.NET/cs/SourceFileMerger/FreeImage.cs.template +++ b/Wrapper/FreeImage.NET/cs/SourceFileMerger/FreeImage.cs.template @@ -1,219 +1,219 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// To build the project without VS use the following commandline: -// "csc.exe /out:FreeImageNET.dll /target:library /doc:FreeImageNET.XML /debug- /o /unsafe+ /filealign:512 FreeImage.cs" -// ========================================================== - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; -using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Serialization; -using System.Text; -using System.Text.RegularExpressions; -using System.Xml; -using FreeImageAPI; -using FreeImageAPI.IO; -using FreeImageAPI.Metadata; -using FreeImageAPI.Plugins; - -///////////////////////////////////////////////////// -// // -// FreeImage.h import // -// // -///////////////////////////////////////////////////// - - #region Structs - -#include "Structs\BITMAP.cs" - -#include "Structs\BITMAPINFOHEADER.cs" - -#include "Structs\BITMAPINFO.cs" - -#include "Structs\FIBITMAP.cs" - -#include "Structs\FIMULTIBITMAP.cs" - -#include "Structs\FIMEMORY.cs" - -#include "Structs\FIMETADATA.cs" - -#include "Structs\FITAG.cs" - -#include "Structs\FreeImageIO.cs" - -#include "Structs\RGBQUAD.cs" - -#include "Structs\RGBTRIPLE.cs" - -#include "Structs\FIRGBA16.cs" - -#include "Structs\FIRGB16.cs" - -#include "Structs\FIRGBAF.cs" - -#include "Structs\FIRGBF.cs" - -#include "Structs\FICOMPLEX.cs" - -#include "Structs\FIICCPROFILE.cs" - -#include "Structs\Plugin.cs" - - #endregion - - #region Enums - -#include "Enumerations\DisposalMethodType.cs" - -#include "Enumerations\FREE_IMAGE_FORMAT.cs" - -#include "Enumerations\FREE_IMAGE_TYPE.cs" - -#include "Enumerations\FREE_IMAGE_COLOR_OPTIONS.cs" - -#include "Enumerations\FREE_IMAGE_COLOR_TYPE.cs" - -#include "Enumerations\FREE_IMAGE_QUANTIZE.cs" - -#include "Enumerations\FREE_IMAGE_DITHER.cs" - -#include "Enumerations\FREE_IMAGE_JPEG_OPERATION.cs" - -#include "Enumerations\FREE_IMAGE_TMO.cs" - -#include "Enumerations\FREE_IMAGE_FILTER.cs" - -#include "Enumerations\FREE_IMAGE_COLOR_CHANNEL.cs" - -#include "Enumerations\FREE_IMAGE_MDTYPE.cs" - -#include "Enumerations\FREE_IMAGE_MDMODEL.cs" - -#include "Enumerations\FREE_IMAGE_LOAD_FLAGS.cs" - -#include "Enumerations\FREE_IMAGE_SAVE_FLAGS.cs" - -#include "Enumerations\ICC_FLAGS.cs" - - #endregion - - #region Delegates - -#include "Delegates.cs" - - #endregion - -#include "FreeImageStaticImports.cs" - -///////////////////////////////////////////////////// -// // -// Wrapper functions // -// // -///////////////////////////////////////////////////// - - #region Structs - -#include "Structs\fi_handle.cs" - -#include "Structs\FI1BIT.cs" - -#include "Structs\FI4BIT.cs" - -#include "Structs\FI16RGB555.cs" - -#include "Structs\FI16RGB565.cs" - -#include "Structs\FIRational.cs" - -#include "Structs\FIURational.cs" - - #endregion - - #region Classes - -#include "Classes\FreeImageBitmap.cs" - -#include "Classes\FreeImageEngine.cs" - -#include "Classes\FreeImagePlugin.cs" - -#include "Classes\FreeImageStreamIO.cs" - -#include "Classes\GifInformation.cs" - -#include "Classes\ImageMetadata.cs" - -#include "Classes\LocalPlugin.cs" - -#include "Classes\MemoryArray.cs" - -#include "Classes\MetadataModel.cs" - - #region Metadata Models - - #include "Classes\MetadataModels.cs" - - #endregion - -#include "Classes\MetadataTag.cs" - -#include "Classes\Palette.cs" - -#include "Classes\PluginRepository.cs" - -#include "Classes\Scanline.cs" - -#include "Classes\StreamWrapper.cs" - - #endregion - - #region Enums - -#include "Enumerations\FREE_IMAGE_COLOR_DEPTH.cs" - -#include "Enumerations\FREE_IMAGE_COMPARE_FLAGS.cs" - -#include "Enumerations\FREE_IMAGE_METADATA_COPY.cs" - -#include "Enumerations\MD_SEARCH_FLAGS.cs" - - #endregion - +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// To build the project without VS use the following commandline: +// "csc.exe /out:FreeImageNET.dll /target:library /doc:FreeImageNET.XML /debug- /o /unsafe+ /filealign:512 FreeImage.cs" +// ========================================================== + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using System.Xml; +using FreeImageAPI; +using FreeImageAPI.IO; +using FreeImageAPI.Metadata; +using FreeImageAPI.Plugins; + +///////////////////////////////////////////////////// +// // +// FreeImage.h import // +// // +///////////////////////////////////////////////////// + + #region Structs + +#include "Structs\BITMAP.cs" + +#include "Structs\BITMAPINFOHEADER.cs" + +#include "Structs\BITMAPINFO.cs" + +#include "Structs\FIBITMAP.cs" + +#include "Structs\FIMULTIBITMAP.cs" + +#include "Structs\FIMEMORY.cs" + +#include "Structs\FIMETADATA.cs" + +#include "Structs\FITAG.cs" + +#include "Structs\FreeImageIO.cs" + +#include "Structs\RGBQUAD.cs" + +#include "Structs\RGBTRIPLE.cs" + +#include "Structs\FIRGBA16.cs" + +#include "Structs\FIRGB16.cs" + +#include "Structs\FIRGBAF.cs" + +#include "Structs\FIRGBF.cs" + +#include "Structs\FICOMPLEX.cs" + +#include "Structs\FIICCPROFILE.cs" + +#include "Structs\Plugin.cs" + + #endregion + + #region Enums + +#include "Enumerations\DisposalMethodType.cs" + +#include "Enumerations\FREE_IMAGE_FORMAT.cs" + +#include "Enumerations\FREE_IMAGE_TYPE.cs" + +#include "Enumerations\FREE_IMAGE_COLOR_OPTIONS.cs" + +#include "Enumerations\FREE_IMAGE_COLOR_TYPE.cs" + +#include "Enumerations\FREE_IMAGE_QUANTIZE.cs" + +#include "Enumerations\FREE_IMAGE_DITHER.cs" + +#include "Enumerations\FREE_IMAGE_JPEG_OPERATION.cs" + +#include "Enumerations\FREE_IMAGE_TMO.cs" + +#include "Enumerations\FREE_IMAGE_FILTER.cs" + +#include "Enumerations\FREE_IMAGE_COLOR_CHANNEL.cs" + +#include "Enumerations\FREE_IMAGE_MDTYPE.cs" + +#include "Enumerations\FREE_IMAGE_MDMODEL.cs" + +#include "Enumerations\FREE_IMAGE_LOAD_FLAGS.cs" + +#include "Enumerations\FREE_IMAGE_SAVE_FLAGS.cs" + +#include "Enumerations\ICC_FLAGS.cs" + + #endregion + + #region Delegates + +#include "Delegates.cs" + + #endregion + +#include "FreeImageStaticImports.cs" + +///////////////////////////////////////////////////// +// // +// Wrapper functions // +// // +///////////////////////////////////////////////////// + + #region Structs + +#include "Structs\fi_handle.cs" + +#include "Structs\FI1BIT.cs" + +#include "Structs\FI4BIT.cs" + +#include "Structs\FI16RGB555.cs" + +#include "Structs\FI16RGB565.cs" + +#include "Structs\FIRational.cs" + +#include "Structs\FIURational.cs" + + #endregion + + #region Classes + +#include "Classes\FreeImageBitmap.cs" + +#include "Classes\FreeImageEngine.cs" + +#include "Classes\FreeImagePlugin.cs" + +#include "Classes\FreeImageStreamIO.cs" + +#include "Classes\GifInformation.cs" + +#include "Classes\ImageMetadata.cs" + +#include "Classes\LocalPlugin.cs" + +#include "Classes\MemoryArray.cs" + +#include "Classes\MetadataModel.cs" + + #region Metadata Models + + #include "Classes\MetadataModels.cs" + + #endregion + +#include "Classes\MetadataTag.cs" + +#include "Classes\Palette.cs" + +#include "Classes\PluginRepository.cs" + +#include "Classes\Scanline.cs" + +#include "Classes\StreamWrapper.cs" + + #endregion + + #region Enums + +#include "Enumerations\FREE_IMAGE_COLOR_DEPTH.cs" + +#include "Enumerations\FREE_IMAGE_COMPARE_FLAGS.cs" + +#include "Enumerations\FREE_IMAGE_METADATA_COPY.cs" + +#include "Enumerations\MD_SEARCH_FLAGS.cs" + + #endregion + #include "FreeImageWrapper.cs" \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/SourceFileMerger/Program.cs b/Wrapper/FreeImage.NET/cs/SourceFileMerger/Program.cs index dd7ce7e..7daa066 100644 --- a/Wrapper/FreeImage.NET/cs/SourceFileMerger/Program.cs +++ b/Wrapper/FreeImage.NET/cs/SourceFileMerger/Program.cs @@ -1,122 +1,122 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.IO; -using System.Text.RegularExpressions; - -namespace FreeImageNET_SFM -{ - class Program - { - static private Regex searchPattern = new Regex("#include[ \\t]*\"(.*)\"", RegexOptions.Compiled); - static private FileStream fStream = null; - static private TextWriter textOut = null; - private const string baseFolder = @"..\..\..\Library\"; - private const string templateName = @"FreeImage.cs.template"; - - static int Main(string[] args) - { - try - { - if (!File.Exists(templateName)) - { - Console.WriteLine(templateName + " not found."); return 1; - } - - try - { - fStream = new FileStream(@"FreeImage.cs", FileMode.Create); - } - catch - { - Console.WriteLine("Unable to create output file."); return 2; - } - - textOut = new StreamWriter(fStream); - - string[] content = File.ReadAllLines(templateName); - - for (int lineNumber = 0; lineNumber < content.Length; lineNumber++) - { - string line = content[lineNumber].Trim(); - Match match = searchPattern.Match(line); - - if (match.Success && match.Groups.Count == 2 && match.Groups[1].Value != null) - { - if (!File.Exists(baseFolder + match.Groups[1].Value)) - { - throw new FileNotFoundException(baseFolder + match.Groups[1].Value + " does not exist."); - } - - ParseFile(baseFolder + match.Groups[1].Value); - } - else - { - textOut.WriteLine(content[lineNumber]); - } - } - - return 0; - } - catch (Exception ex) - { - Console.WriteLine(ex.ToString()); - //Console.WriteLine("Error while parsing."); - return 3; - } - finally - { - if (textOut != null) - { - textOut.Flush(); - textOut.Close(); - } - } - } - - private static void ParseFile(string fileName) - { - int lineNumber = 0; - string line; - Match match; - string[] content = File.ReadAllLines(fileName); - - if (fileName.Contains("AssemblyInfo.cs")) - { - while (content[lineNumber].Trim().StartsWith("using") && lineNumber < content.Length) - { - lineNumber++; - } - lineNumber++; - } - else - { - while (!(content[lineNumber].Trim().StartsWith("namespace")) && lineNumber < content.Length) - { - lineNumber++; - } - //lineNumber += 2; - } - - for (; lineNumber < content.Length; lineNumber++) - { - line = content[lineNumber].Trim(); - match = searchPattern.Match(line); - - if (match.Success && match.Groups.Count == 2 && match.Groups[1].Value != null) - { - if (!File.Exists(baseFolder + match.Groups[1].Value)) - { - throw new FileNotFoundException(baseFolder + match.Groups[1].Value + " does not exist."); - } - - ParseFile(baseFolder + match.Groups[1].Value); - } - else - { - textOut.WriteLine(content[lineNumber]); - } - } - } - } +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using System.Text.RegularExpressions; + +namespace FreeImageNET_SFM +{ + class Program + { + static private Regex searchPattern = new Regex("#include[ \\t]*\"(.*)\"", RegexOptions.Compiled); + static private FileStream fStream = null; + static private TextWriter textOut = null; + private const string baseFolder = @"..\..\..\Library\"; + private const string templateName = @"FreeImage.cs.template"; + + static int Main(string[] args) + { + try + { + if (!File.Exists(templateName)) + { + Console.WriteLine(templateName + " not found."); return 1; + } + + try + { + fStream = new FileStream(@"FreeImage.cs", FileMode.Create); + } + catch + { + Console.WriteLine("Unable to create output file."); return 2; + } + + textOut = new StreamWriter(fStream); + + string[] content = File.ReadAllLines(templateName); + + for (int lineNumber = 0; lineNumber < content.Length; lineNumber++) + { + string line = content[lineNumber].Trim(); + Match match = searchPattern.Match(line); + + if (match.Success && match.Groups.Count == 2 && match.Groups[1].Value != null) + { + if (!File.Exists(baseFolder + match.Groups[1].Value)) + { + throw new FileNotFoundException(baseFolder + match.Groups[1].Value + " does not exist."); + } + + ParseFile(baseFolder + match.Groups[1].Value); + } + else + { + textOut.WriteLine(content[lineNumber]); + } + } + + return 0; + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + //Console.WriteLine("Error while parsing."); + return 3; + } + finally + { + if (textOut != null) + { + textOut.Flush(); + textOut.Close(); + } + } + } + + private static void ParseFile(string fileName) + { + int lineNumber = 0; + string line; + Match match; + string[] content = File.ReadAllLines(fileName); + + if (fileName.Contains("AssemblyInfo.cs")) + { + while (content[lineNumber].Trim().StartsWith("using") && lineNumber < content.Length) + { + lineNumber++; + } + lineNumber++; + } + else + { + while (!(content[lineNumber].Trim().StartsWith("namespace")) && lineNumber < content.Length) + { + lineNumber++; + } + //lineNumber += 2; + } + + for (; lineNumber < content.Length; lineNumber++) + { + line = content[lineNumber].Trim(); + match = searchPattern.Match(line); + + if (match.Success && match.Groups.Count == 2 && match.Groups[1].Value != null) + { + if (!File.Exists(baseFolder + match.Groups[1].Value)) + { + throw new FileNotFoundException(baseFolder + match.Groups[1].Value + " does not exist."); + } + + ParseFile(baseFolder + match.Groups[1].Value); + } + else + { + textOut.WriteLine(content[lineNumber]); + } + } + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/SourceFileMerger/Properties/AssemblyInfo.cs b/Wrapper/FreeImage.NET/cs/SourceFileMerger/Properties/AssemblyInfo.cs index 1634d6f..e52c979 100644 --- a/Wrapper/FreeImage.NET/cs/SourceFileMerger/Properties/AssemblyInfo.cs +++ b/Wrapper/FreeImage.NET/cs/SourceFileMerger/Properties/AssemblyInfo.cs @@ -1,16 +1,16 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("4fcae9f3-1b12-4137-9c5b-047124da37e9")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: Guid("4fcae9f3-1b12-4137-9c5b-047124da37e9")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wrapper/FreeImage.NET/cs/UnitTest/FreeImage.cs b/Wrapper/FreeImage.NET/cs/UnitTest/FreeImage.cs index 46cb386..c9b93cf 100644 --- a/Wrapper/FreeImage.NET/cs/UnitTest/FreeImage.cs +++ b/Wrapper/FreeImage.NET/cs/UnitTest/FreeImage.cs @@ -1,30584 +1,30584 @@ -// ========================================================== -// FreeImage 3 .NET wrapper -// Original FreeImage 3 functions and .NET compatible derived functions -// -// Design and implementation by -// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) -// - Carsten Klein (cklein05@users.sourceforge.net) -// -// Contributors: -// - David Boland (davidboland@vodafone.ie) -// -// Main reference : MSDN Knowlede Base -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -// ========================================================== -// To build the project without VS use the following commandline: -// "csc.exe /out:FreeImageNET.dll /target:library /doc:FreeImageNET.XML /debug- /o /unsafe+ /filealign:512 FreeImage.cs" -// ========================================================== - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; -using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Runtime.Serialization; -using System.Text; -using System.Text.RegularExpressions; -using System.Xml; -using FreeImageAPI; -using FreeImageAPI.IO; -using FreeImageAPI.Metadata; -using FreeImageAPI.Plugins; - -///////////////////////////////////////////////////// -// // -// FreeImage.h import // -// // -///////////////////////////////////////////////////// - - #region Structs - -namespace FreeImageAPI -{ - /// - /// The BITMAP structure defines the type, width, height, color format, and bit values of a bitmap. - /// - /// - /// The bitmap formats currently used are monochrome and color. The monochrome bitmap uses a one-bit, - /// one-plane format. Each scan is a multiple of 32 bits. - /// - /// Scans are organized as follows for a monochrome bitmap of height n: - /// - /// - /// Scan 0 - /// Scan 1 - /// . - /// . - /// . - /// Scan n-2 - /// Scan n-1 - /// - /// - /// The pixels on a monochrome device are either black or white. If the corresponding bit in the - /// bitmap is 1, the pixel is set to the foreground color; if the corresponding bit in the bitmap - /// is zero, the pixel is set to the background color. - /// - /// All devices that have the RC_BITBLT device capability support bitmaps. For more information, - /// see GetDeviceCaps. - /// - /// Each device has a unique color format. To transfer a bitmap from one device to another, - /// use the GetDIBits and SetDIBits functions. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct BITMAP - { - /// - /// Specifies the bitmap type. This member must be zero. - /// - public int bmType; - /// - /// Specifies the width, in pixels, of the bitmap. The width must be greater than zero. - /// - public int bmWidth; - /// - /// Specifies the height, in pixels, of the bitmap. The height must be greater than zero. - /// - public int bmHeight; - /// - /// Specifies the number of bytes in each scan line. This value must be divisible by 2, - /// because the system assumes that the bit values of a bitmap form an array that is word aligned. - /// - public int bmWidthBytes; - /// - /// Specifies the count of color planes. - /// - public ushort bmPlanes; - /// - /// Specifies the number of bits required to indicate the color of a pixel. - /// - public ushort bmBitsPixel; - /// - /// Pointer to the location of the bit values for the bitmap. - /// The bmBits member must be a long pointer to an array of character (1-byte) values. - /// - public IntPtr bmBits; - } -} - -namespace FreeImageAPI -{ - /// - /// This structure contains information about the dimensions and color format - /// of a device-independent bitmap (DIB). - /// - /// - /// The structure combines the - /// BITMAPINFOHEADER structure and a color table to provide a complete - /// definition of the dimensions and colors of a DIB. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct BITMAPINFOHEADER : IEquatable - { - /// - /// Specifies the size of the structure, in bytes. - /// - public uint biSize; - /// - /// Specifies the width of the bitmap, in pixels. - /// - /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, - /// the biWidth member specifies the width of the decompressed JPEG or PNG image file, - /// respectively. - /// - public int biWidth; - /// - /// Specifies the height of the bitmap, in pixels. If biHeight is positive, the bitmap - /// is a bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, - /// the bitmap is a top-down DIB and its origin is the upper-left corner. - /// - /// If biHeight is negative, indicating a top-down DIB, biCompression must be - /// either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed. - /// - /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, - /// the biHeight member specifies the height of the decompressed JPEG or PNG image file, - /// respectively. - /// - public int biHeight; - /// - /// Specifies the number of planes for the target device. This value must be set to 1. - /// - public ushort biPlanes; - /// - /// Specifies the number of bits per pixel.The biBitCount member of the BITMAPINFOHEADER - /// structure determines the number of bits that define each pixel and the maximum number of - /// colors in the bitmap. This member must be one of the following values. - /// - /// - /// - /// - /// Value - /// Meaning - /// - /// - /// - /// 0 - /// - /// Windows 98/Me, Windows 2000/XP: The number of bits-per-pixel is specified - /// or is implied by the JPEG or PNG format. - /// - /// - /// - /// - /// 1 - /// - /// The bitmap is monochrome, and the bmiColors member of - /// contains two entries. Each bit in the bitmap array represents a pixel. If the bit is clear, - /// the pixel is displayed with the color of the first entry in the bmiColors table; if the bit - /// is set, the pixel has the color of the second entry in the table. - /// - /// - /// - /// - /// 4 - /// - /// The bitmap has a maximum of 16 colors, and the bmiColors member of BITMAPINFO - /// contains up to 16 entries. Each pixel in the bitmap is represented by a 4-bit index into the - /// color table. For example, if the first byte in the bitmap is 0x1F, the byte represents two - /// pixels. The first pixel contains the color in the second table entry, and the second pixel - /// contains the color in the sixteenth table entry. - /// - /// - /// - /// 8 - /// - /// The bitmap has a maximum of 256 colors, and the bmiColors member of BITMAPINFO - /// contains up to 256 entries. In this case, each byte in the array represents a single pixel. - /// - /// - /// - /// - /// 16 - /// - /// The bitmap has a maximum of 2^16 colors. If the biCompression member of the - /// BITMAPINFOHEADER is BI_RGB, the bmiColors member of BITMAPINFO is NULL. - /// Each WORD in the bitmap array represents a single pixel. The relative intensities - /// of red, green, and blue are represented with five bits for each color component. - /// The value for blue is in the least significant five bits, followed by five bits each for - /// green and red. The most significant bit is not used. The bmiColors color table is used - /// for optimizing colors used on palette-based devices, and must contain the number of entries - /// specified by the biClrUsed member of the BITMAPINFOHEADER. - /// - /// If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, the - /// bmiColors member contains three DWORD color masks that specify the red, green, - /// and blue components, respectively, of each pixel. Each WORD in the bitmap array represents - /// a single pixel. - /// - /// Windows NT/Windows 2000/XP: When the biCompression member is BI_BITFIELDS, - /// bits set in each DWORD mask must be contiguous and should not overlap the bits - /// of another mask. All the bits in the pixel do not have to be used. - /// - /// Windows 95/98/Me: When the biCompression member is BI_BITFIELDS, the system - /// supports only the following 16bpp color masks: A 5-5-5 16-bit image, where the blue mask is - /// 0x001F, the green mask is 0x03E0, and the red mask is 0x7C00; and a 5-6-5 16-bit image, - /// where the blue mask is 0x001F, the green mask is 0x07E0, and the red mask is 0xF800. - /// - /// - /// - /// - /// 24 - /// - /// The bitmap has a maximum of 2^24 colors, and the bmiColors member of BITMAPINFO - /// is NULL. Each 3-byte triplet in the bitmap array represents the relative intensities of blue, - /// green, and red, respectively, for a pixel. The bmiColors color table is used for - /// optimizing colors used on palette-based devices, and must contain the number of entries - /// specified by the biClrUsed member of the BITMAPINFOHEADER. - /// - /// - /// - /// - /// 32 - /// - /// The bitmap has a maximum of 2^32 colors. If the biCompression member of the - /// BITMAPINFOHEADER is BI_RGB, the bmiColors member of BITMAPINFO is NULL. - /// Each DWORD in the bitmap array represents the relative intensities of blue, green, and red, - /// respectively, for a pixel. The high byte in each DWORD is not used. The bmiColors - /// color table is used for optimizing colors used on palette-based devices, and must contain the - /// number of entries specified by the biClrUsed member of the BITMAPINFOHEADER. - /// - /// If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, - /// the bmiColors member contains three DWORD color masks that specify the red, green, - /// and blue components, respectively, of each pixel. Each DWORD in the bitmap array represents - /// a single pixel. - /// - /// Windows NT/ 2000: When the biCompression member is BI_BITFIELDS, bits set in each - /// DWORD mask must be contiguous and should not overlap the bits of another mask. All the - /// bits in the pixel do not need to be used. - /// - /// Windows 95/98/Me: When the biCompression member is BI_BITFIELDS, the system - /// supports only the following 32-bpp color mask: The blue mask is 0x000000FF, the green mask is - /// 0x0000FF00, and the red mask is 0x00FF0000. - /// - /// - /// - /// - public ushort biBitCount; - /// - /// Specifies the type of compression for a compressed bottom-up bitmap (top-down DIBs cannot be - /// compressed). - /// - /// - /// Value - /// Meaning - /// - /// - /// - /// BI_RGB - /// An uncompressed format. - /// - /// - /// - /// BI_RLE8 - /// A run-length encoded (RLE) format for bitmaps with 8 bpp. The compression format - /// is a 2-byte format consisting of a count byte followed by a byte containing a color index. - /// - /// - /// - /// - /// BI_RLE4 - /// An RLE format for bitmaps with 4 bpp. The compression format is a 2-byte format - /// consisting of a count byte followed by two word-length color indexes. - /// - /// - /// - /// BI_BITFIELDS - /// Specifies that the bitmap is not compressed and that the color table consists - /// of three DWORD color masks that specify the red, green, and blue components, respectively, - /// of each pixel. This is valid when used with 16- and 32-bpp bitmaps. - /// - /// - /// - /// BI_JPEG - /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a JPEG image. - /// - /// - /// - /// - /// BI_PNG - /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a PNG image. - /// - /// - /// - /// - /// - public uint biCompression; - /// - /// Specifies the size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps. - /// - /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, - /// biSizeImage indicates the size of the JPEG or PNG image buffer, respectively. - /// - public uint biSizeImage; - /// - /// Specifies the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. - /// An application can use this value to select a bitmap from a resource group that best matches - /// the characteristics of the current device. - /// - public int biXPelsPerMeter; - /// - /// Specifies the vertical resolution, in pixels-per-meter, of the target device for the bitmap. - /// - public int biYPelsPerMeter; - /// - /// Specifies the number of color indexes in the color table that are actually used by the bitmap. - /// If this value is zero, the bitmap uses the maximum number of colors corresponding to the value - /// of the biBitCount member for the compression mode specified by biCompression. - /// - /// If iClrUsed is nonzero and the biBitCount member is less than 16, the biClrUsed - /// member specifies the actual number of colors the graphics engine or device driver accesses. - /// If biBitCount is 16 or greater, the biClrUsed member specifies the size of the color - /// table used to optimize performance of the system color palettes. If biBitCount equals 16 or 32, - /// the optimal color palette starts immediately following the three DWORD masks. - /// - /// When the bitmap array immediately follows the structure, it is a packed bitmap. - /// Packed bitmaps are referenced by a single pointer. Packed bitmaps require that the - /// biClrUsed member must be either zero or the actual size of the color table. - /// - public uint biClrUsed; - /// - /// Specifies the number of color indexes that are required for displaying the bitmap. If this value - /// is zero, all colors are required. - /// - public uint biClrImportant; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(BITMAPINFOHEADER left, BITMAPINFOHEADER right) - { - return ((left.biSize == right.biSize) && - (left.biWidth == right.biWidth) && - (left.biHeight == right.biHeight) && - (left.biPlanes == right.biPlanes) && - (left.biBitCount == right.biBitCount) && - (left.biCompression == right.biCompression) && - (left.biSizeImage == right.biSizeImage) && - (left.biXPelsPerMeter == right.biXPelsPerMeter) && - (left.biYPelsPerMeter == right.biYPelsPerMeter) && - (left.biClrUsed == right.biClrUsed) && - (left.biClrImportant == right.biClrImportant)); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(BITMAPINFOHEADER left, BITMAPINFOHEADER right) - { - return !(left == right); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(BITMAPINFOHEADER other) - { - return (this == other); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is BITMAPINFOHEADER) && (this == (BITMAPINFOHEADER)obj)); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The BITMAPINFO structure defines the dimensions and color information for a DIB. - /// - /// - /// A DIB consists of two distinct parts: a BITMAPINFO structure describing the dimensions - /// and colors of the bitmap, and an array of bytes defining the pixels of the bitmap. The bits in - /// the array are packed together, but each scan line must be padded with zeroes to end on a - /// LONG data-type boundary. If the height of the bitmap is positive, the bitmap is a - /// bottom-up DIB and its origin is the lower-left corner. If the height is negative, the bitmap is - /// a top-down DIB and its origin is the upper left corner. - /// - /// A bitmap is packed when the bitmap array immediately follows the BITMAPINFO header. - /// Packed bitmaps are referenced by a single pointer. For packed bitmaps, the biClrUsed - /// member must be set to an even number when using the DIB_PAL_COLORS mode so that the DIB bitmap - /// array starts on a DWORD boundary. - /// - /// Note The bmiColors member should not contain palette indexes if the bitmap is to - /// be stored in a file or transferred to another application. - /// - /// Unless the application has exclusive use and control of the bitmap, the bitmap color table - /// should contain explicit RGB values. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct BITMAPINFO : IEquatable - { - /// - /// Specifies a structure that contains information - /// about the dimensions of color format. - /// - public BITMAPINFOHEADER bmiHeader; - /// - /// The bmiColors member contains one of the following: - /// - /// - /// - /// - /// An array of . The elements of the array that make up the - /// color table. - /// - /// - /// - /// - /// - /// An array of 16-bit unsigned integers that specifies indexes into the currently realized - /// logical palette. This use of bmiColors is allowed for functions that use DIBs. - /// When bmiColors elements contain indexes to a realized logical palette, they must - /// also call the following bitmap functions: - /// - /// - /// - /// - /// CreateDIBitmap - /// - /// CreateDIBPatternBrush - /// - /// CreateDIBSection - /// - /// The iUsage parameter of CreateDIBSection must be set to DIB_PAL_COLORS. - /// - /// The number of entries in the array depends on the values of the biBitCount and - /// biClrUsed members of the structure. - /// - /// The colors in the bmiColors table appear in order of importance. For more information, - /// see the Remarks section. - /// - public RGBQUAD[] bmiColors; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(BITMAPINFO left, BITMAPINFO right) - { - if (left.bmiHeader != right.bmiHeader) - { - return false; - } - if ((left.bmiColors == null) && (right.bmiColors == null)) - { - return true; - } - if ((left.bmiColors == null) || (right.bmiColors == null)) - { - return false; - } - if (left.bmiColors.Length != right.bmiColors.Length) - { - return false; - } - for (int i = 0; i < left.bmiColors.Length; i++) - { - if (left.bmiColors[i] != right.bmiColors[i]) - { - return false; - } - } - return true; - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(BITMAPINFO left, BITMAPINFO right) - { - return !(left == right); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(BITMAPINFO other) - { - return (this == other); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is BITMAPINFO) && (this == ((BITMAPINFO)obj))); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - int hash = bmiHeader.GetHashCode(); - if (bmiColors != null) - { - for (int c = 0; c < bmiColors.Length; c++) - { - hash ^= bmiColors[c].GetHashCode(); - hash <<= 1; - } - hash <<= 1; - } - else - { - hash >>= 1; - } - return hash; - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FIBITMAP structure is a handle to a FreeImage bimtap. - /// - /// - /// The handle represented by a FIBITBAP structure provides - /// access to either a singlepage bitmap or exactly one page of - /// a multipage bitmap. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIBITMAP : IComparable, IComparable, IEquatable - { - private IntPtr data; - - /// - /// A read-only field that represents a handle that has been initialized to zero. - /// - public static readonly FIBITMAP Zero; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIBITMAP left, FIBITMAP right) - { - return (left.data == right.data); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIBITMAP left, FIBITMAP right) - { - return (left.data != right.data); - } - - /// - /// Gets whether the handle is a null or not. - /// - /// true if this handle is a null; - /// otherwise, false. - public bool IsNull - { - get - { - return (data == IntPtr.Zero); - } - } - - /// - /// Sets the handle to null. - /// - public void SetNull() - { - data = IntPtr.Zero; - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return data.ToString(); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return data.GetHashCode(); - } - - /// - /// Determines whether the specified is equal to the current . - /// - /// The to compare with the current . - /// true if the specified is equal to the current ; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIBITMAP) && (this == ((FIBITMAP)obj))); - } - - /// - /// Indicates whether the current object is equal to another object of the same type. - /// - /// An object to compare with this object. - /// true if the current object is equal to the other parameter; otherwise, false. - public bool Equals(FIBITMAP other) - { - return (this == other); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIBITMAP)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIBITMAP)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIBITMAP other) - { - return this.data.ToInt64().CompareTo(other.data.ToInt64()); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FIMULTIBITMAP structure is a handle to a FreeImage multipaged bimtap. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIMULTIBITMAP : IComparable, IComparable, IEquatable - { - private IntPtr data; - - /// - /// A read-only field that represents a handle that has been initialized to zero. - /// - public static readonly FIMULTIBITMAP Zero; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIMULTIBITMAP left, FIMULTIBITMAP right) - { - return (left.data == right.data); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIMULTIBITMAP left, FIMULTIBITMAP right) - { - return (left.data != right.data); - } - - /// - /// Gets whether the handle is a null or not. - /// - /// true if this handle is a null; - /// otherwise, false. - public bool IsNull - { - get - { - return (data == IntPtr.Zero); - } - } - - /// - /// Sets the handle to null. - /// - public void SetNull() - { - data = IntPtr.Zero; - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return data.ToString(); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return data.GetHashCode(); - } - - /// - /// Determines whether the specified is equal to the current . - /// - /// The to compare with the current . - /// true if the specified is equal to the current ; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIMULTIBITMAP) && (this == ((FIMULTIBITMAP)obj))); - } - - /// - /// Indicates whether the current object is equal to another object of the same type. - /// - /// An object to compare with this object. - /// true if the current object is equal to the other parameter; otherwise, false. - public bool Equals(FIMULTIBITMAP other) - { - return (this == other); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIMULTIBITMAP)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIMULTIBITMAP)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIMULTIBITMAP other) - { - return this.data.ToInt64().CompareTo(other.data.ToInt64()); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FIMEMORY structure is a handle to an opened memory stream. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIMEMORY : IComparable, IComparable, IEquatable - { - private IntPtr data; - - /// - /// A read-only field that represents a handle that has been initialized to zero. - /// - public static readonly FIMEMORY Zero; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIMEMORY left, FIMEMORY right) - { - return (left.data == right.data); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIMEMORY left, FIMEMORY right) - { - return (left.data != right.data); - } - - /// - /// Gets whether the pointer is a null pointer or not. - /// - /// true if this is a null pointer; - /// otherwise, false. - public bool IsNull - { - get - { - return (data == IntPtr.Zero); - } - } - - /// - /// Sets the handle to null. - /// - public void SetNull() - { - data = IntPtr.Zero; - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return data.ToString(); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return data.GetHashCode(); - } - - /// - /// Determines whether the specified is equal to the current . - /// - /// The to compare with the current . - /// true if the specified is equal to the current ; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIMEMORY) && (this == ((FIMEMORY)obj))); - } - - /// - /// Indicates whether the current object is equal to another object of the same type. - /// - /// An object to compare with this object. - /// true if the current object is equal to the other parameter; otherwise, false. - public bool Equals(FIMEMORY other) - { - return (this == other); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIMEMORY)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIMEMORY)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIMEMORY other) - { - return this.data.ToInt64().CompareTo(other.data.ToInt64()); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FIMETADATA structure is an unique search handle for metadata search operations. - /// - /// - /// The FIMETADATA structure is usually returned by the - /// - /// function and then used on subsequent calls to - /// . - /// When the FIMETADATA handle is no longer used, it needs to be freed by the - /// function. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIMETADATA : IComparable, IComparable, IEquatable - { - private IntPtr data; - - /// - /// A read-only field that represents a handle that has been initialized to zero. - /// - public static readonly FIMETADATA Zero; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIMETADATA left, FIMETADATA right) - { - return (left.data == right.data); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIMETADATA left, FIMETADATA right) - { - return (left.data != right.data); - } - - /// - /// Gets whether the pointer is a null pointer or not. - /// - /// true if this is a null pointer; - /// otherwise, false. - public bool IsNull - { - get - { - return (data == IntPtr.Zero); - } - } - - /// - /// Sets the handle to null. - /// - public void SetNull() - { - data = IntPtr.Zero; - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return data.ToString(); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return data.GetHashCode(); - } - - /// - /// Determines whether the specified is equal to the current . - /// - /// The to compare with the current . - /// true if the specified is equal to the current ; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIMETADATA) && (this == ((FIMETADATA)obj))); - } - - /// - /// Indicates whether the current object is equal to another object of the same type. - /// - /// An object to compare with this object. - /// true if the current object is equal to the other parameter; otherwise, false. - public bool Equals(FIMETADATA other) - { - return (this == other); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIMETADATA)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIMETADATA)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIMETADATA other) - { - return this.data.ToInt64().CompareTo(other.data.ToInt64()); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FITAG structure is a handle to a FreeImage metadata tag. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FITAG : IComparable, IComparable, IEquatable - { - private IntPtr data; - - /// - /// A read-only field that represents a handle that has been initialized to zero. - /// - public static readonly FITAG Zero; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FITAG left, FITAG right) - { - return (left.data == right.data); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FITAG left, FITAG right) - { - return (left.data != right.data); - } - - /// - /// Gets whether the pointer is a null pointer or not. - /// - /// true if this is a null pointer; - /// otherwise, false. - public bool IsNull - { - get - { - return (data == IntPtr.Zero); - } - } - - /// - /// Sets the handle to null. - /// - public void SetNull() - { - data = IntPtr.Zero; - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return data.ToString(); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return data.GetHashCode(); - } - - /// - /// Determines whether the specified is equal to the current . - /// - /// The to compare with the current . - /// true if the specified is equal to the current ; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FITAG) && (this == ((FITAG)obj))); - } - - /// - /// Indicates whether the current object is equal to another object of the same type. - /// - /// An object to compare with this object. - /// true if the current object is equal to the other parameter; otherwise, false. - public bool Equals(FITAG other) - { - return (this == other); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FITAG)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FITAG)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FITAG other) - { - return this.data.ToInt64().CompareTo(other.data.ToInt64()); - } - } -} - -namespace FreeImageAPI.IO -{ - /// - /// Structure for implementing access to custom handles. - /// - [StructLayout(LayoutKind.Sequential)] - public struct FreeImageIO - { - /// - /// Delegate to the C++ function fread. - /// - public ReadProc readProc; - - /// - /// Delegate to the C++ function fwrite. - /// - public WriteProc writeProc; - - /// - /// Delegate to the C++ function fseek. - /// - public SeekProc seekProc; - - /// - /// Delegate to the C++ function ftell. - /// - public TellProc tellProc; - } -} - -namespace FreeImageAPI -{ - /// - /// The RGBQUAD structure describes a color consisting of relative - /// intensities of red, green, blue and alpha value. Each single color - /// component consumes 8 bits and so, takes values in the range from 0 to 255. - /// - /// - /// - /// The RGBQUAD structure provides access to an underlying Win32 RGBQUAD - /// structure. To determine the alpha, red, green or blue component of a color, - /// use the rgbReserved, rgbRed, rgbGreen or rgbBlue fields, respectively. - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the RGBQUAD structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the RGBQUAD structure and my be used in all situations which require - /// an RGBQUAD type. - /// - /// - /// Each color component rgbReserved, rgbRed, rgbGreen or rgbBlue of RGBQUAD - /// is translated into it's corresponding color component A, R, G or B of - /// by an one-to-one manner and vice versa. - /// - /// - /// Conversion from System.Drawing.Color to RGBQUAD - /// - /// RGBQUAD.component = Color.component - /// - /// Conversion from RGBQUAD to System.Drawing.Color - /// - /// Color.component = RGBQUAD.component - /// - /// The same conversion is also applied when the - /// property or the constructor - /// is invoked. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// RGBQUAD structure and the structure. - /// - /// RGBQUAD rgbq; - /// // Initialize the structure using a native .NET Color structure. - /// rgbq = new RGBQUAD(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// rgbq = Color.DarkSeaGreen; - /// // Convert the RGBQUAD instance into a native .NET Color - /// // using its implicit operator. - /// Color color = rgbq; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = rgbq.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Explicit)] - public struct RGBQUAD : IComparable, IComparable, IEquatable - { - /// - /// The blue color component. - /// - [FieldOffset(0)] - public byte rgbBlue; - - /// - /// The green color component. - /// - [FieldOffset(1)] - public byte rgbGreen; - - /// - /// The red color component. - /// - [FieldOffset(2)] - public byte rgbRed; - - /// - /// The alpha color component. - /// - [FieldOffset(3)] - public byte rgbReserved; - - /// - /// The color's value. - /// - [FieldOffset(0)] - public uint uintValue; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public RGBQUAD(Color color) - { - uintValue = 0u; - rgbBlue = color.B; - rgbGreen = color.G; - rgbRed = color.R; - rgbReserved = color.A; - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(RGBQUAD left, RGBQUAD right) - { - return (left.uintValue == right.uintValue); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(RGBQUAD left, RGBQUAD right) - { - return (left.uintValue != right.uintValue); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator RGBQUAD(Color value) - { - return new RGBQUAD(value); - } - - /// - /// Converts the value of a structure to a Color structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(RGBQUAD value) - { - return value.Color; - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator RGBQUAD(uint value) - { - RGBQUAD result = new RGBQUAD(); - result.uintValue = value; - return result; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator uint(RGBQUAD value) - { - return value.uintValue; - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb( - rgbReserved, - rgbRed, - rgbGreen, - rgbBlue); - } - set - { - rgbRed = value.R; - rgbGreen = value.G; - rgbBlue = value.B; - rgbReserved = value.A; - } - } - - /// - /// Converts an array of into an array of - /// . - /// - /// The array to convert. - /// An array of . - public static RGBQUAD[] ToRGBQUAD(Color[] array) - { - if (array == null) - return null; - - RGBQUAD[] result = new RGBQUAD[array.Length]; - for (int i = 0; i < array.Length; i++) - { - result[i] = array[i]; - } - return result; - } - - /// - /// Converts an array of into an array of - /// . - /// - /// The array to convert. - /// An array of . - public static Color[] ToColor(RGBQUAD[] array) - { - if (array == null) - return null; - - Color[] result = new Color[array.Length]; - for (int i = 0; i < array.Length; i++) - { - result[i] = array[i].Color; - } - return result; - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is RGBQUAD)) - { - throw new ArgumentException("obj"); - } - return CompareTo((RGBQUAD)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(RGBQUAD other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is RGBQUAD) && (this == ((RGBQUAD)obj))); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(RGBQUAD other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The RGBTRIPLE structure describes a color consisting of relative - /// intensities of red, green and blue value. Each single color component - /// consumes 8 bits and so, takes values in the range from 0 to 255. - /// - /// - /// - /// The RGBTRIPLE structure provides access to an underlying Win32 RGBTRIPLE - /// structure. To determine the red, green or blue component of a color, use the - /// rgbtRed, rgbtGreen or rgbtBlue fields, respectively. - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the RGBTRIPLE structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the RGBTRIPLE structure and my be used in all situations which require - /// an RGBTRIPLE type. - /// - /// - /// Each of the color components rgbtRed, rgbtGreen or rgbtBlue of RGBTRIPLE is - /// translated into it's corresponding color component R, G or B of - /// by an one-to-one manner and vice versa. - /// When converting from into RGBTRIPLE, the - /// color's alpha value is ignored and assumed to be 255 when converting from - /// RGBTRIPLE into , creating a fully - /// opaque color. - /// - /// - /// Conversion from System.Drawing.Color to RGBTRIPLE - /// - /// RGBTRIPLE.component = Color.component - /// - /// Conversion from RGBTRIPLE to System.Drawing.Color - /// - /// Color.component = RGBTRIPLE.component - /// - /// The same conversion is also applied when the - /// property or the constructor - /// is invoked. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// RGBTRIPLE structure and the structure. - /// - /// RGBTRIPLE rgbt; - /// // Initialize the structure using a native .NET Color structure. - /// rgbt = new RGBTRIPLE(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// rgbt = Color.DarkSeaGreen; - /// // Convert the RGBTRIPLE instance into a native .NET Color - /// // using its implicit operator. - /// Color color = rgbt; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = rgbt.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct RGBTRIPLE : IComparable, IComparable, IEquatable - { - /// - /// The blue color component. - /// - public byte rgbtBlue; - - /// - /// The green color component. - /// - public byte rgbtGreen; - - /// - /// The red color component. - /// - public byte rgbtRed; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public RGBTRIPLE(Color color) - { - rgbtBlue = color.B; - rgbtGreen = color.G; - rgbtRed = color.R; - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(RGBTRIPLE left, RGBTRIPLE right) - { - return - left.rgbtBlue == right.rgbtBlue && - left.rgbtGreen == right.rgbtGreen && - left.rgbtRed == right.rgbtRed; - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(RGBTRIPLE left, RGBTRIPLE right) - { - return !(left == right); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator RGBTRIPLE(Color value) - { - return new RGBTRIPLE(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(RGBTRIPLE value) - { - return value.Color; - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator RGBTRIPLE(uint value) - { - RGBTRIPLE result = new RGBTRIPLE(); - result.rgbtBlue = (byte)(value & 0xFF); - result.rgbtGreen = (byte)((value >> 8) & 0xFF); - result.rgbtRed = (byte)((value >> 16) & 0xFF); - return result; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator uint(RGBTRIPLE value) - { - return (uint)((value.rgbtRed << 16) | (value.rgbtGreen << 8) | (value.rgbtBlue)); - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb( - rgbtRed, - rgbtGreen, - rgbtBlue); - } - set - { - rgbtBlue = value.B; - rgbtGreen = value.G; - rgbtRed = value.R; - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is RGBTRIPLE)) - { - throw new ArgumentException("obj"); - } - return CompareTo((RGBTRIPLE)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(RGBTRIPLE other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is RGBTRIPLE) && (this == ((RGBTRIPLE)obj))); - } - - /// - /// Tests whether the specified structure is equivalent to this - /// structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(RGBTRIPLE other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FIRGBA16 structure describes a color consisting of relative - /// intensities of red, green, blue and alpha value. Each single color - /// component consumes 16 bits and so, takes values in the range from 0 to 65535. - /// - /// - /// - /// The FIRGBA16 structure provides access to an underlying FreeImage FIRGBA16 - /// structure. To determine the alpha, red, green or blue component of a color, - /// use the alpha, red, green or blue fields, respectively. - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the FIRGBA16 structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the FIRGBA16 structure and my be used in all situations which require - /// an FIRGBA16 type. - /// - /// - /// Each color component alpha, red, green or blue of FIRGBA16 - /// is translated into it's corresponding color component A, R, G or B of - /// by an 8 bit right shift and vice versa. - /// - /// - /// Conversion from System.Drawing.Color to FIRGBA16 - /// - /// FIRGBA16.component = Color.component << 8 - /// - /// Conversion from FIRGBA16 to System.Drawing.Color - /// - /// Color.component = FIRGBA16.component >> 8 - /// - /// The same conversion is also applied when the - /// property or the constructor - /// is invoked. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// FIRGBA16 structure and the structure. - /// - /// FIRGBA16 firgba16; - /// // Initialize the structure using a native .NET Color structure. - /// firgba16 = new FIRGBA16(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// firgba16 = Color.DarkSeaGreen; - /// // Convert the FIRGBA16 instance into a native .NET Color - /// // using its implicit operator. - /// Color color = firgba16; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = firgba16.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIRGBA16 : IComparable, IComparable, IEquatable - { - /// - /// The red color component. - /// - public ushort red; - - /// - /// The green color component. - /// - public ushort green; - - /// - /// The blue color component. - /// - public ushort blue; - - /// - /// The alpha color component. - /// - public ushort alpha; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public FIRGBA16(Color color) - { - red = (ushort)(color.R << 8); - green = (ushort)(color.G << 8); - blue = (ushort)(color.B << 8); - alpha = (ushort)(color.A << 8); - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIRGBA16 left, FIRGBA16 right) - { - return - ((left.alpha == right.alpha) && - (left.blue == right.blue) && - (left.green == right.green) && - (left.red == right.red)); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIRGBA16 left, FIRGBA16 right) - { - return !(left == right); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIRGBA16(Color value) - { - return new FIRGBA16(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(FIRGBA16 value) - { - return value.Color; - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb((alpha >> 8), (red >> 8), (green >> 8), (blue >> 8)); - } - set - { - red = (ushort)(value.R << 8); - green = (ushort)(value.G << 8); - blue = (ushort)(value.B << 8); - alpha = (ushort)(value.A << 8); - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIRGBA16)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIRGBA16)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIRGBA16 other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIRGBA16) && (this == ((FIRGBA16)obj))); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FIRGBA16 other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FIRGB16 structure describes a color consisting of relative - /// intensities of red, green, blue and alpha value. Each single color - /// component consumes 16 bits and so, takes values in the range from 0 to 65535. - /// - /// - /// - /// The FIRGB16 structure provides access to an underlying FreeImage FIRGB16 - /// structure. To determine the red, green or blue component of a color, - /// use the red, green or blue fields, respectively. - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the FIRGB16 structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the FIRGB16 structure and my be used in all situations which require - /// an FIRGB16 type. - /// - /// - /// Each color component red, green or blue of FIRGB16 is translated into - /// it's corresponding color component R, G or B of - /// by right shifting 8 bits and shifting left 8 bits for the reverse conversion. - /// When converting from into FIRGB16, the - /// color's alpha value is ignored and assumed to be 255 when converting from - /// FIRGB16 into , creating a fully - /// opaque color. - /// - /// - /// Conversion from System.Drawing.Color to FIRGB16 - /// - /// FIRGB16.component = Color.component << 8 - /// - /// Conversion from FIRGB16 to System.Drawing.Color - /// - /// Color.component = FIRGB16.component >> 8 - /// - /// The same conversion is also applied when the - /// property or the constructor - /// is invoked. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// FIRGB16 structure and the structure. - /// - /// FIRGB16 firgb16; - /// // Initialize the structure using a native .NET Color structure. - /// firgb16 = new FIRGBA16(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// firgb16 = Color.DarkSeaGreen; - /// // Convert the FIRGB16 instance into a native .NET Color - /// // using its implicit operator. - /// Color color = firgb16; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = firgb16.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIRGB16 : IComparable, IComparable, IEquatable - { - /// - /// The red color component. - /// - public ushort red; - - /// - /// The green color component. - /// - public ushort green; - - /// - /// The blue color component. - /// - public ushort blue; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public FIRGB16(Color color) - { - red = (ushort)(color.R << 8); - green = (ushort)(color.G << 8); - blue = (ushort)(color.B << 8); - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIRGB16 left, FIRGB16 right) - { - return - ((left.blue == right.blue) && - (left.green == right.green) && - (left.red == right.red)); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIRGB16 left, FIRGB16 right) - { - return !(left == right); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIRGB16(Color value) - { - return new FIRGB16(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(FIRGB16 value) - { - return value.Color; - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb((red >> 8), (green >> 8), (blue >> 8)); - } - set - { - red = (ushort)(value.R << 8); - green = (ushort)(value.G << 8); - blue = (ushort)(value.B << 8); - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIRGB16)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIRGB16)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIRGB16 other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIRGB16) && (this == ((FIRGB16)obj))); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FIRGB16 other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FIRGBAF structure describes a color consisting of relative - /// intensities of red, green, blue and alpha value. Each single color - /// component consumes 32 bits and takes values in the range from 0 to 1. - /// - /// - /// - /// The FIRGBAF structure provides access to an underlying FreeImage FIRGBAF - /// structure. To determine the alpha, red, green or blue component of a color, - /// use the alpha, red, green or blue fields, respectively. - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the FIRGBAF structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the FIRGBAF structure and my be used in all situations which require - /// an FIRGBAF type. - /// - /// - /// Each color component alpha, red, green or blue of FIRGBAF is translated - /// into it's corresponding color component A, R, G or B of - /// by linearly mapping the values of one range - /// into the other range and vice versa. - /// - /// - /// Conversion from System.Drawing.Color to FIRGBAF - /// - /// FIRGBAF.component = (float)Color.component / 255f - /// - /// Conversion from FIRGBAF to System.Drawing.Color - /// - /// Color.component = (int)(FIRGBAF.component * 255f) - /// - /// The same conversion is also applied when the - /// property or the constructor - /// is invoked. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// FIRGBAF structure and the structure. - /// - /// FIRGBAF firgbaf; - /// // Initialize the structure using a native .NET Color structure. - /// firgbaf = new FIRGBAF(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// firgbaf = Color.DarkSeaGreen; - /// // Convert the FIRGBAF instance into a native .NET Color - /// // using its implicit operator. - /// Color color = firgbaf; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = firgbaf.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIRGBAF : IComparable, IComparable, IEquatable - { - /// - /// The red color component. - /// - public float red; - - /// - /// The green color component. - /// - public float green; - - /// - /// The blue color component. - /// - public float blue; - - /// - /// The alpha color component. - /// - public float alpha; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public FIRGBAF(Color color) - { - red = (float)color.R / 255f; - green = (float)color.G / 255f; - blue = (float)color.B / 255f; - alpha = (float)color.A / 255f; - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIRGBAF left, FIRGBAF right) - { - return - ((left.alpha == right.alpha) && - (left.blue == right.blue) && - (left.green == right.green) && - (left.red == right.red)); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIRGBAF left, FIRGBAF right) - { - return !(left == right); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIRGBAF(Color value) - { - return new FIRGBAF(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(FIRGBAF value) - { - return value.Color; - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb( - (int)(alpha * 255f), - (int)(red * 255f), - (int)(green * 255f), - (int)(blue * 255f)); - } - set - { - red = (float)value.R / 255f; - green = (float)value.G / 255f; - blue = (float)value.B / 255f; - alpha = (float)value.A / 255f; - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIRGBAF)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIRGBAF)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIRGBAF other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIRGBAF) && (this == ((FIRGBAF)obj))); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FIRGBAF other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FIRGBF structure describes a color consisting of relative - /// intensities of red, green, blue and alpha value. Each single color - /// component consumes 32 bits and takes values in the range from 0 to 1. - /// - /// - /// - /// The FIRGBF structure provides access to an underlying FreeImage FIRGBF - /// structure. To determine the red, green or blue component of a color, use the - /// red, green or blue fields, respectively. - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the FIRGBF structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the FIRGBF structure and my be used in all situations which require - /// an FIRGBF type. - /// - /// - /// Each color component alpha, red, green or blue of FIRGBF is translated - /// into it's corresponding color component A, R, G or B of - /// by linearly mapping the values of one range - /// into the other range and vice versa. - /// When converting from into FIRGBF, the - /// color's alpha value is ignored and assumed to be 255 when converting from - /// FIRGBF into , creating a fully - /// opaque color. - /// - /// - /// Conversion from System.Drawing.Color to FIRGBF - /// - /// FIRGBF.component = (float)Color.component / 255f - /// - /// Conversion from FIRGBF to System.Drawing.Color - /// - /// Color.component = (int)(FIRGBF.component * 255f) - /// - /// The same conversion is also applied when the - /// property or the constructor - /// is invoked. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// FIRGBF structure and the structure. - /// - /// FIRGBF firgbf; - /// // Initialize the structure using a native .NET Color structure. - /// firgbf = new FIRGBF(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// firgbf = Color.DarkSeaGreen; - /// // Convert the FIRGBF instance into a native .NET Color - /// // using its implicit operator. - /// Color color = firgbf; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = firgbf.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIRGBF : IComparable, IComparable, IEquatable - { - /// - /// The red color component. - /// - public float red; - - /// - /// The green color component. - /// - public float green; - - /// - /// The blue color component. - /// - public float blue; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public FIRGBF(Color color) - { - red = (float)color.R / 255f; - green = (float)color.G / 255f; - blue = (float)color.B / 255f; - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FIRGBF left, FIRGBF right) - { - return - ((left.blue == right.blue) && - (left.green == right.green) && - (left.red == right.red)); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FIRGBF left, FIRGBF right) - { - return !(left == right); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIRGBF(Color value) - { - return new FIRGBF(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(FIRGBF value) - { - return value.Color; - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb( - (int)(red * 255f), - (int)(green * 255f), - (int)(blue * 255f)); - } - set - { - red = (float)value.R / 255f; - green = (float)value.G / 255f; - blue = (float)value.B / 255f; - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIRGBF)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FIRGBF)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIRGBF other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIRGBF) && (this == ((FIRGBF)obj))); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FIRGBF other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FICOMPLEX structure describes a color consisting of a real and an imaginary part. - /// Each part is using 4 bytes of data. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FICOMPLEX : IComparable, IComparable, IEquatable - { - /// - /// Real part of the color. - /// - public double real; - - /// - /// Imaginary part of the color. - /// - public double imag; - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FICOMPLEX left, FICOMPLEX right) - { - return ((left.real == right.real) && (left.imag == right.imag)); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FICOMPLEX left, FICOMPLEX right) - { - return ((left.real != right.real) || (left.imag == right.imag)); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FICOMPLEX)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FICOMPLEX)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FICOMPLEX other) - { - return base.GetHashCode(); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FICOMPLEX) && (this == ((FICOMPLEX)obj))); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FICOMPLEX other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - } -} - -namespace FreeImageAPI -{ - /// - /// This Structure contains ICC-Profile data. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FIICCPROFILE - { - private ICC_FLAGS flags; - private uint size; - private IntPtr data; - - /// - /// Creates a new ICC-Profile for . - /// - /// Handle to a FreeImage bitmap. - /// The ICC-Profile data. - /// - /// is null. - public FIICCPROFILE(FIBITMAP dib, byte[] data) - : this(dib, data, (int)data.Length) - { - } - - /// - /// Creates a new ICC-Profile for . - /// - /// Handle to a FreeImage bitmap. - /// The ICC-Profile data. - /// Number of bytes to use from data. - /// - /// is null. - public unsafe FIICCPROFILE(FIBITMAP dib, byte[] data, int size) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - FIICCPROFILE prof; - size = Math.Min(size, (int)data.Length); - prof = *(FIICCPROFILE*)FreeImage.CreateICCProfile(dib, data, size); - this.flags = prof.flags; - this.size = prof.size; - this.data = prof.data; - } - - /// - /// Info flag of the profile. - /// - public ICC_FLAGS Flags - { - get { return flags; } - } - - /// - /// Profile's size measured in bytes. - /// - public uint Size - { - get { return size; } - } - - /// - /// Points to a block of contiguous memory containing the profile. - /// - public IntPtr DataPointer - { - get { return data; } - } - - /// - /// Copy of the ICC-Profiles data. - /// - public unsafe byte[] Data - { - get - { - byte[] result; - FreeImage.CopyMemory(result = new byte[size], data.ToPointer(), size); - return result; - } - } - - /// - /// Indicates whether the profile is CMYK. - /// - public bool IsCMYK - { - get - { - return ((flags & ICC_FLAGS.FIICC_COLOR_IS_CMYK) != 0); - } - } - } -} - -namespace FreeImageAPI.Plugins -{ - /// - /// The structure contains functionpointers that make up a FreeImage plugin. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct Plugin - { - /// - /// Delegate to a function that returns a string which describes - /// the plugins format. - /// - public FormatProc formatProc; - - /// - /// Delegate to a function that returns a string which contains - /// a more detailed description. - /// - public DescriptionProc descriptionProc; - - /// - /// Delegate to a function that returns a comma seperated list - /// of file extensions the plugin can read or write. - /// - public ExtensionListProc extensionListProc; - - /// - /// Delegate to a function that returns a regular expression that - /// can be used to idientify whether a file can be handled by the plugin. - /// - public RegExprProc regExprProc; - - /// - /// Delegate to a function that opens a file. - /// - public OpenProc openProc; - - /// - /// Delegate to a function that closes a previosly opened file. - /// - public CloseProc closeProc; - - /// - /// Delegate to a function that returns the number of pages of a multipage - /// bitmap if the plugin is capable of handling multipage bitmaps. - /// - public PageCountProc pageCountProc; - - /// - /// UNKNOWN - /// - public PageCapabilityProc pageCapabilityProc; - - /// - /// Delegate to a function that loads and decodes a bitmap into memory. - /// - public LoadProc loadProc; - - /// - /// Delegate to a function that saves a bitmap. - /// - public SaveProc saveProc; - - /// - /// Delegate to a function that determines whether the source is a valid image. - /// - public ValidateProc validateProc; - - /// - /// Delegate to a function that returns a string which contains - /// the plugin's mime type. - /// - public MimeProc mimeProc; - - /// - /// Delegate to a function that returns whether the plugin can handle the - /// specified color depth. - /// - public SupportsExportBPPProc supportsExportBPPProc; - - /// - /// Delegate to a function that returns whether the plugin can handle the - /// specified image type. - /// - public SupportsExportTypeProc supportsExportTypeProc; - - /// - /// Delegate to a function that returns whether the plugin can handle - /// ICC-Profiles. - /// - public SupportsICCProfilesProc supportsICCProfilesProc; - } -} - - #endregion - - #region Enums - -namespace FreeImageAPI.Metadata -{ - /// - /// Specifies how a single frame will be handled after being displayed. - /// - public enum DisposalMethodType : byte - { - /// - /// Same behavior as but should not be used. - /// - Unspecified, - - /// - /// The image is left in place and will be overdrawn by the next image. - /// - Leave, - - /// - /// The area of the image will be blanked out by its background. - /// - Background, - - /// - /// Restores the the area of the image to the state it was before it - /// has been dawn. - /// - Previous, - } -} - -namespace FreeImageAPI -{ - /// - /// I/O image format identifiers. - /// - public enum FREE_IMAGE_FORMAT - { - /// - /// Unknown format (returned value only, never use it as input value) - /// - FIF_UNKNOWN = -1, - /// - /// Windows or OS/2 Bitmap File (*.BMP) - /// - FIF_BMP = 0, - /// - /// Windows Icon (*.ICO) - /// - FIF_ICO = 1, - /// - /// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE) - /// - FIF_JPEG = 2, - /// - /// JPEG Network Graphics (*.JNG) - /// - FIF_JNG = 3, - /// - /// Commodore 64 Koala format (*.KOA) - /// - FIF_KOALA = 4, - /// - /// Amiga IFF (*.IFF, *.LBM) - /// - FIF_LBM = 5, - /// - /// Amiga IFF (*.IFF, *.LBM) - /// - FIF_IFF = 5, - /// - /// Multiple Network Graphics (*.MNG) - /// - FIF_MNG = 6, - /// - /// Portable Bitmap (ASCII) (*.PBM) - /// - FIF_PBM = 7, - /// - /// Portable Bitmap (BINARY) (*.PBM) - /// - FIF_PBMRAW = 8, - /// - /// Kodak PhotoCD (*.PCD) - /// - FIF_PCD = 9, - /// - /// Zsoft Paintbrush PCX bitmap format (*.PCX) - /// - FIF_PCX = 10, - /// - /// Portable Graymap (ASCII) (*.PGM) - /// - FIF_PGM = 11, - /// - /// Portable Graymap (BINARY) (*.PGM) - /// - FIF_PGMRAW = 12, - /// - /// Portable Network Graphics (*.PNG) - /// - FIF_PNG = 13, - /// - /// Portable Pixelmap (ASCII) (*.PPM) - /// - FIF_PPM = 14, - /// - /// Portable Pixelmap (BINARY) (*.PPM) - /// - FIF_PPMRAW = 15, - /// - /// Sun Rasterfile (*.RAS) - /// - FIF_RAS = 16, - /// - /// truevision Targa files (*.TGA, *.TARGA) - /// - FIF_TARGA = 17, - /// - /// Tagged Image File Format (*.TIF, *.TIFF) - /// - FIF_TIFF = 18, - /// - /// Wireless Bitmap (*.WBMP) - /// - FIF_WBMP = 19, - /// - /// Adobe Photoshop (*.PSD) - /// - FIF_PSD = 20, - /// - /// Dr. Halo (*.CUT) - /// - FIF_CUT = 21, - /// - /// X11 Bitmap Format (*.XBM) - /// - FIF_XBM = 22, - /// - /// X11 Pixmap Format (*.XPM) - /// - FIF_XPM = 23, - /// - /// DirectDraw Surface (*.DDS) - /// - FIF_DDS = 24, - /// - /// Graphics Interchange Format (*.GIF) - /// - FIF_GIF = 25, - /// - /// High Dynamic Range (*.HDR) - /// - FIF_HDR = 26, - /// - /// Raw Fax format CCITT G3 (*.G3) - /// - FIF_FAXG3 = 27, - /// - /// Silicon Graphics SGI image format (*.SGI) - /// - FIF_SGI = 28, - /// - /// OpenEXR format (*.EXR) - /// - FIF_EXR = 29, - /// - /// JPEG-2000 format (*.J2K, *.J2C) - /// - FIF_J2K = 30, - /// - /// JPEG-2000 format (*.JP2) - /// - FIF_JP2 = 31, - /// - /// Portable FloatMap (*.PFM) - /// - FIF_PFM = 32, - /// - /// Macintosh PICT (*.PICT) - /// - FIF_PICT = 33, - /// - /// RAW camera image (*.*) - /// - FIF_RAW = 34, - } -} - -namespace FreeImageAPI -{ - /// - /// Image types used in FreeImage. - /// - public enum FREE_IMAGE_TYPE - { - /// - /// unknown type - /// - FIT_UNKNOWN = 0, - /// - /// standard image : 1-, 4-, 8-, 16-, 24-, 32-bit - /// - FIT_BITMAP = 1, - /// - /// array of unsigned short : unsigned 16-bit - /// - FIT_UINT16 = 2, - /// - /// array of short : signed 16-bit - /// - FIT_INT16 = 3, - /// - /// array of unsigned long : unsigned 32-bit - /// - FIT_UINT32 = 4, - /// - /// array of long : signed 32-bit - /// - FIT_INT32 = 5, - /// - /// array of float : 32-bit IEEE floating point - /// - FIT_FLOAT = 6, - /// - /// array of double : 64-bit IEEE floating point - /// - FIT_DOUBLE = 7, - /// - /// array of FICOMPLEX : 2 x 64-bit IEEE floating point - /// - FIT_COMPLEX = 8, - /// - /// 48-bit RGB image : 3 x 16-bit - /// - FIT_RGB16 = 9, - /// - /// 64-bit RGBA image : 4 x 16-bit - /// - FIT_RGBA16 = 10, - /// - /// 96-bit RGB float image : 3 x 32-bit IEEE floating point - /// - FIT_RGBF = 11, - /// - /// 128-bit RGBA float image : 4 x 32-bit IEEE floating point - /// - FIT_RGBAF = 12 - } -} - -namespace FreeImageAPI -{ - /// - /// Constants used in color filling routines. - /// - public enum FREE_IMAGE_COLOR_OPTIONS - { - /// - /// Default value. - /// - FICO_DEFAULT = 0x0, - /// - /// color is RGB color (contains no valid alpha channel). - /// - FICO_RGB = 0x0, - /// - /// color is RGBA color (contains a valid alpha channel). - /// - FICO_RGBA = 0x1, - /// - /// Lookup nearest RGB color from palette. - /// - FICO_NEAREST_COLOR = 0x0, - /// - /// Lookup equal RGB color from palette. - /// - FICO_EQUAL_COLOR = 0x2, - /// - /// contains the palette index to be used. - /// - FICO_ALPHA_IS_INDEX = 0x4, - } -} - -namespace FreeImageAPI -{ - /// - /// Image color types used in FreeImage. - /// - public enum FREE_IMAGE_COLOR_TYPE - { - /// - /// min value is white - /// - FIC_MINISWHITE = 0, - /// - /// min value is black - /// - FIC_MINISBLACK = 1, - /// - /// RGB color model - /// - FIC_RGB = 2, - /// - /// color map indexed - /// - FIC_PALETTE = 3, - /// - /// RGB color model with alpha channel - /// - FIC_RGBALPHA = 4, - /// - /// CMYK color model - /// - FIC_CMYK = 5 - } -} - -namespace FreeImageAPI -{ - /// - /// Color quantization algorithms. - /// Constants used in FreeImage_ColorQuantize. - /// - public enum FREE_IMAGE_QUANTIZE - { - /// - /// Xiaolin Wu color quantization algorithm - /// - FIQ_WUQUANT = 0, - /// - /// NeuQuant neural-net quantization algorithm by Anthony Dekker - /// - FIQ_NNQUANT = 1 - } -} - -namespace FreeImageAPI -{ - /// - /// Dithering algorithms. - /// Constants used in FreeImage_Dither. - /// - public enum FREE_IMAGE_DITHER - { - /// - /// Floyd and Steinberg error diffusion - /// - FID_FS = 0, - /// - /// Bayer ordered dispersed dot dithering (order 2 dithering matrix) - /// - FID_BAYER4x4 = 1, - /// - /// Bayer ordered dispersed dot dithering (order 3 dithering matrix) - /// - FID_BAYER8x8 = 2, - /// - /// Ordered clustered dot dithering (order 3 - 6x6 matrix) - /// - FID_CLUSTER6x6 = 3, - /// - /// Ordered clustered dot dithering (order 4 - 8x8 matrix) - /// - FID_CLUSTER8x8 = 4, - /// - /// Ordered clustered dot dithering (order 8 - 16x16 matrix) - /// - FID_CLUSTER16x16 = 5, - /// - /// Bayer ordered dispersed dot dithering (order 4 dithering matrix) - /// - FID_BAYER16x16 = 6 - } -} - -namespace FreeImageAPI -{ - /// - /// Lossless JPEG transformations constants used in FreeImage_JPEGTransform. - /// - public enum FREE_IMAGE_JPEG_OPERATION - { - /// - /// no transformation - /// - FIJPEG_OP_NONE = 0, - /// - /// horizontal flip - /// - FIJPEG_OP_FLIP_H = 1, - /// - /// vertical flip - /// - FIJPEG_OP_FLIP_V = 2, - /// - /// transpose across UL-to-LR axis - /// - FIJPEG_OP_TRANSPOSE = 3, - /// - /// transpose across UR-to-LL axis - /// - FIJPEG_OP_TRANSVERSE = 4, - /// - /// 90-degree clockwise rotation - /// - FIJPEG_OP_ROTATE_90 = 5, - /// - /// 180-degree rotation - /// - FIJPEG_OP_ROTATE_180 = 6, - /// - /// 270-degree clockwise (or 90 ccw) - /// - FIJPEG_OP_ROTATE_270 = 7 - } -} - -namespace FreeImageAPI -{ - /// - /// Tone mapping operators. Constants used in FreeImage_ToneMapping. - /// - public enum FREE_IMAGE_TMO - { - /// - /// Adaptive logarithmic mapping (F. Drago, 2003) - /// - FITMO_DRAGO03 = 0, - /// - /// Dynamic range reduction inspired by photoreceptor physiology (E. Reinhard, 2005) - /// - FITMO_REINHARD05 = 1, - /// - /// Gradient domain high dynamic range compression (R. Fattal, 2002) - /// - FITMO_FATTAL02 - } -} - -namespace FreeImageAPI -{ - /// - /// Upsampling / downsampling filters. Constants used in FreeImage_Rescale. - /// - public enum FREE_IMAGE_FILTER - { - /// - /// Box, pulse, Fourier window, 1st order (constant) b-spline - /// - FILTER_BOX = 0, - /// - /// Mitchell and Netravali's two-param cubic filter - /// - FILTER_BICUBIC = 1, - /// - /// Bilinear filter - /// - FILTER_BILINEAR = 2, - /// - /// 4th order (cubic) b-spline - /// - FILTER_BSPLINE = 3, - /// - /// Catmull-Rom spline, Overhauser spline - /// - FILTER_CATMULLROM = 4, - /// - /// Lanczos3 filter - /// - FILTER_LANCZOS3 = 5 - } -} - -namespace FreeImageAPI -{ - /// - /// Color channels. Constants used in color manipulation routines. - /// - public enum FREE_IMAGE_COLOR_CHANNEL - { - /// - /// Use red, green and blue channels - /// - FICC_RGB = 0, - /// - /// Use red channel - /// - FICC_RED = 1, - /// - /// Use green channel - /// - FICC_GREEN = 2, - /// - /// Use blue channel - /// - FICC_BLUE = 3, - /// - /// Use alpha channel - /// - FICC_ALPHA = 4, - /// - /// Use black channel - /// - FICC_BLACK = 5, - /// - /// Complex images: use real part - /// - FICC_REAL = 6, - /// - /// Complex images: use imaginary part - /// - FICC_IMAG = 7, - /// - /// Complex images: use magnitude - /// - FICC_MAG = 8, - /// - /// Complex images: use phase - /// - FICC_PHASE = 9 - } -} - -namespace FreeImageAPI -{ - /// - /// Tag data type information (based on TIFF specifications) - /// Note: RATIONALs are the ratio of two 32-bit integer values. - /// - public enum FREE_IMAGE_MDTYPE - { - /// - /// placeholder - /// - FIDT_NOTYPE = 0, - /// - /// 8-bit unsigned integer - /// - FIDT_BYTE = 1, - /// - /// 8-bit bytes w/ last byte null - /// - FIDT_ASCII = 2, - /// - /// 16-bit unsigned integer - /// - FIDT_SHORT = 3, - /// - /// 32-bit unsigned integer - /// - FIDT_LONG = 4, - /// - /// 64-bit unsigned fraction - /// - FIDT_RATIONAL = 5, - /// - /// 8-bit signed integer - /// - FIDT_SBYTE = 6, - /// - /// 8-bit untyped data - /// - FIDT_UNDEFINED = 7, - /// - /// 16-bit signed integer - /// - FIDT_SSHORT = 8, - /// - /// 32-bit signed integer - /// - FIDT_SLONG = 9, - /// - /// 64-bit signed fraction - /// - FIDT_SRATIONAL = 10, - /// - /// 32-bit IEEE floating point - /// - FIDT_FLOAT = 11, - /// - /// 64-bit IEEE floating point - /// - FIDT_DOUBLE = 12, - /// - /// 32-bit unsigned integer (offset) - /// - FIDT_IFD = 13, - /// - /// 32-bit RGBQUAD - /// - FIDT_PALETTE = 14 - } -} - -namespace FreeImageAPI -{ - /// - /// Metadata models supported by FreeImage. - /// - public enum FREE_IMAGE_MDMODEL - { - /// - /// No data - /// - FIMD_NODATA = -1, - /// - /// single comment or keywords - /// - FIMD_COMMENTS = 0, - /// - /// Exif-TIFF metadata - /// - FIMD_EXIF_MAIN = 1, - /// - /// Exif-specific metadata - /// - FIMD_EXIF_EXIF = 2, - /// - /// Exif GPS metadata - /// - FIMD_EXIF_GPS = 3, - /// - /// Exif maker note metadata - /// - FIMD_EXIF_MAKERNOTE = 4, - /// - /// Exif interoperability metadata - /// - FIMD_EXIF_INTEROP = 5, - /// - /// IPTC/NAA metadata - /// - FIMD_IPTC = 6, - /// - /// Abobe XMP metadata - /// - FIMD_XMP = 7, - /// - /// GeoTIFF metadata - /// - FIMD_GEOTIFF = 8, - /// - /// Animation metadata - /// - FIMD_ANIMATION = 9, - /// - /// Used to attach other metadata types to a dib - /// - FIMD_CUSTOM = 10 - } -} - -namespace FreeImageAPI -{ - /// - /// Flags used in load functions. - /// - [System.Flags] - public enum FREE_IMAGE_LOAD_FLAGS - { - /// - /// Default option for all types. - /// - DEFAULT = 0, - /// - /// Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color. - /// - GIF_LOAD256 = 1, - /// - /// 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading. - /// - GIF_PLAYBACK = 2, - /// - /// Convert to 32bpp and create an alpha channel from the AND-mask when loading. - /// - ICO_MAKEALPHA = 1, - /// - /// Load the file as fast as possible, sacrificing some quality. - /// - JPEG_FAST = 0x0001, - /// - /// Load the file with the best quality, sacrificing some speed. - /// - JPEG_ACCURATE = 0x0002, - /// - /// Load separated CMYK "as is" (use | to combine with other load flags). - /// - JPEG_CMYK = 0x0004, - /// - /// Load and rotate according to Exif 'Orientation' tag if available. - /// - JPEG_EXIFROTATE = 0x0008, - /// - /// Load the bitmap sized 768 x 512. - /// - PCD_BASE = 1, - /// - /// Load the bitmap sized 384 x 256. - /// - PCD_BASEDIV4 = 2, - /// - /// Load the bitmap sized 192 x 128. - /// - PCD_BASEDIV16 = 3, - /// - /// Avoid gamma correction. - /// - PNG_IGNOREGAMMA = 1, - /// - /// If set the loader converts RGB555 and ARGB8888 -> RGB888. - /// - TARGA_LOAD_RGB888 = 1, - /// - /// Reads tags for separated CMYK. - /// - TIFF_CMYK = 0x0001, - /// - /// Tries to load the JPEG preview image, embedded in - /// Exif Metadata or load the image as RGB 24-bit if no - /// preview image is available. - /// - RAW_PREVIEW = 0x1, - /// - /// Loads the image as RGB 24-bit. - /// - RAW_DISPLAY = 0x2, - } -} - -namespace FreeImageAPI -{ - /// - /// Flags used in save functions. - /// - [System.Flags] - public enum FREE_IMAGE_SAVE_FLAGS - { - /// - /// Default option for all types. - /// - DEFAULT = 0, - /// - /// Save with run length encoding. - /// - BMP_SAVE_RLE = 1, - /// - /// Save data as float instead of as half (not recommended). - /// - EXR_FLOAT = 0x0001, - /// - /// Save with no compression. - /// - EXR_NONE = 0x0002, - /// - /// Save with zlib compression, in blocks of 16 scan lines. - /// - EXR_ZIP = 0x0004, - /// - /// Save with piz-based wavelet compression. - /// - EXR_PIZ = 0x0008, - /// - /// Save with lossy 24-bit float compression. - /// - EXR_PXR24 = 0x0010, - /// - /// Save with lossy 44% float compression - goes to 22% when combined with EXR_LC. - /// - EXR_B44 = 0x0020, - /// - /// Save images with one luminance and two chroma channels, rather than as RGB (lossy compression). - /// - EXR_LC = 0x0040, - /// - /// Save with superb quality (100:1). - /// - JPEG_QUALITYSUPERB = 0x80, - /// - /// Save with good quality (75:1). - /// - JPEG_QUALITYGOOD = 0x0100, - /// - /// Save with normal quality (50:1). - /// - JPEG_QUALITYNORMAL = 0x0200, - /// - /// Save with average quality (25:1). - /// - JPEG_QUALITYAVERAGE = 0x0400, - /// - /// Save with bad quality (10:1). - /// - JPEG_QUALITYBAD = 0x0800, - /// - /// Save as a progressive-JPEG (use | to combine with other save flags). - /// - JPEG_PROGRESSIVE = 0x2000, - /// - /// Save with high 4x1 chroma subsampling (4:1:1). - /// - JPEG_SUBSAMPLING_411 = 0x1000, - /// - /// Save with medium 2x2 medium chroma (4:2:0). - /// - JPEG_SUBSAMPLING_420 = 0x4000, - /// - /// Save with low 2x1 chroma subsampling (4:2:2). - /// - JPEG_SUBSAMPLING_422 = 0x8000, - /// - /// Save with no chroma subsampling (4:4:4). - /// - JPEG_SUBSAMPLING_444 = 0x10000, - /// - /// Save using ZLib level 1 compression flag - /// (default value is ). - /// - PNG_Z_BEST_SPEED = 0x0001, - /// - /// Save using ZLib level 6 compression flag (default recommended value). - /// - PNG_Z_DEFAULT_COMPRESSION = 0x0006, - /// - /// save using ZLib level 9 compression flag - /// (default value is ). - /// - PNG_Z_BEST_COMPRESSION = 0x0009, - /// - /// Save without ZLib compression. - /// - PNG_Z_NO_COMPRESSION = 0x0100, - /// - /// Save using Adam7 interlacing (use | to combine with other save flags). - /// - PNG_INTERLACED = 0x0200, - /// - /// If set the writer saves in ASCII format (i.e. P1, P2 or P3). - /// - PNM_SAVE_ASCII = 1, - /// - /// Stores tags for separated CMYK (use | to combine with compression flags). - /// - TIFF_CMYK = 0x0001, - /// - /// Save using PACKBITS compression. - /// - TIFF_PACKBITS = 0x0100, - /// - /// Save using DEFLATE compression (a.k.a. ZLIB compression). - /// - TIFF_DEFLATE = 0x0200, - /// - /// Save using ADOBE DEFLATE compression. - /// - TIFF_ADOBE_DEFLATE = 0x0400, - /// - /// Save without any compression. - /// - TIFF_NONE = 0x0800, - /// - /// Save using CCITT Group 3 fax encoding. - /// - TIFF_CCITTFAX3 = 0x1000, - /// - /// Save using CCITT Group 4 fax encoding. - /// - TIFF_CCITTFAX4 = 0x2000, - /// - /// Save using LZW compression. - /// - TIFF_LZW = 0x4000, - /// - /// Save using JPEG compression. - /// - TIFF_JPEG = 0x8000 - } -} - -namespace FreeImageAPI -{ - /// - /// Flags for ICC profiles. - /// - [System.Flags] - public enum ICC_FLAGS : ushort - { - /// - /// Default value. - /// - FIICC_DEFAULT = 0x00, - /// - /// The color is CMYK. - /// - FIICC_COLOR_IS_CMYK = 0x01 - } -} - - #endregion - - #region Delegates - -namespace FreeImageAPI -{ - // Delegates used by the FreeImageIO structure - - /// - /// Delegate for capturing FreeImage error messages. - /// - /// The format of the image. - /// The errormessage. - // DLL_API is missing in the definition of the callbackfuntion. - [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = false)] - public delegate void OutputMessageFunction(FREE_IMAGE_FORMAT fif, string message); -} - -namespace FreeImageAPI.IO -{ - /// - /// Delegate to the C++ function fread. - /// - /// Pointer to read from. - /// Item size in bytes. - /// Maximum number of items to be read. - /// Handle/stream to read from. - /// Number of full items actually read, - /// which may be less than count if an error occurs or - /// if the end of the file is encountered before reaching count. - public delegate uint ReadProc(IntPtr buffer, uint size, uint count, fi_handle handle); - - /// - /// Delegate to the C++ function fwrite. - /// - /// Pointer to data to be written. - /// Item size in bytes. - /// Maximum number of items to be written. - /// Handle/stream to write to. - /// Number of full items actually written, - /// which may be less than count if an error occurs. - /// Also, if an error occurs, the file-position indicator cannot be determined. - public delegate uint WriteProc(IntPtr buffer, uint size, uint count, fi_handle handle); - - /// - /// Delegate to the C++ function fseek. - /// - /// Handle/stream to seek in. - /// Number of bytes from origin. - /// Initial position. - /// If successful 0 is returned; otherwise a nonzero value. - public delegate int SeekProc(fi_handle handle, int offset, SeekOrigin origin); - - /// - /// Delegate to the C++ function ftell. - /// - /// Handle/stream to retrieve its currents position from. - /// The current position. - public delegate int TellProc(fi_handle handle); - - // Delegates used by 'Plugin' structure -} - -namespace FreeImageAPI.Plugins -{ - /// - /// Delegate to a function that returns a string which describes - /// the plugins format. - /// - public delegate string FormatProc(); - - /// - /// Delegate to a function that returns a string which contains - /// a more detailed description. - /// - public delegate string DescriptionProc(); - - /// - /// Delegate to a function that returns a comma seperated list - /// of file extensions the plugin can read or write. - /// - public delegate string ExtensionListProc(); - - /// - /// Delegate to a function that returns a regular expression that - /// can be used to idientify whether a file can be handled by the plugin. - /// - public delegate string RegExprProc(); - - /// - /// Delegate to a function that opens a file. - /// - public delegate IntPtr OpenProc(ref FreeImageIO io, fi_handle handle, bool read); - - /// - /// Delegate to a function that closes a previosly opened file. - /// - public delegate void CloseProc(ref FreeImageIO io, fi_handle handle, IntPtr data); - - /// - /// Delegate to a function that returns the number of pages of a multipage - /// bitmap if the plugin is capable of handling multipage bitmaps. - /// - public delegate int PageCountProc(ref FreeImageIO io, fi_handle handle, IntPtr data); - - /// - /// UNKNOWN - /// - public delegate int PageCapabilityProc(ref FreeImageIO io, fi_handle handle, IntPtr data); - - /// - /// Delegate to a function that loads and decodes a bitmap into memory. - /// - public delegate FIBITMAP LoadProc(ref FreeImageIO io, fi_handle handle, int page, int flags, IntPtr data); - - /// - /// Delegate to a function that saves a bitmap. - /// - public delegate bool SaveProc(ref FreeImageIO io, FIBITMAP dib, fi_handle handle, int page, int flags, IntPtr data); - - /// - /// Delegate to a function that determines whether the source defined - /// by and is a valid image. - /// - public delegate bool ValidateProc(ref FreeImageIO io, fi_handle handle); - - /// - /// Delegate to a function that returns a string which contains - /// the plugin's mime type. - /// - public delegate string MimeProc(); - - /// - /// Delegate to a function that returns whether the plugin can handle the - /// specified color depth. - /// - public delegate bool SupportsExportBPPProc(int bpp); - - /// - /// Delegate to a function that returns whether the plugin can handle the - /// specified image type. - /// - public delegate bool SupportsExportTypeProc(FREE_IMAGE_TYPE type); - - /// - /// Delegate to a function that returns whether the plugin can handle - /// ICC-Profiles. - /// - public delegate bool SupportsICCProfilesProc(); - - /// - /// Callback function used by FreeImage to register plugins. - /// - public delegate void InitProc(ref Plugin plugin, int format_id); -} - - #endregion - -namespace FreeImageAPI -{ - public static partial class FreeImage - { - #region Constants - - /// - /// Filename of the FreeImage library. - /// - private const string FreeImageLibrary = "FreeImage"; - - /// - /// Number of bytes to shift left within a 4 byte block. - /// - public const int FI_RGBA_RED = 2; - - /// - /// Number of bytes to shift left within a 4 byte block. - /// - public const int FI_RGBA_GREEN = 1; - - /// - /// Number of bytes to shift left within a 4 byte block. - /// - public const int FI_RGBA_BLUE = 0; - - /// - /// Number of bytes to shift left within a 4 byte block. - /// - public const int FI_RGBA_ALPHA = 3; - - /// - /// Mask indicating the position of the given color. - /// - public const uint FI_RGBA_RED_MASK = 0x00FF0000; - - /// - /// Mask indicating the position of the given color. - /// - public const uint FI_RGBA_GREEN_MASK = 0x0000FF00; - - /// - /// Mask indicating the position of the given color. - /// - public const uint FI_RGBA_BLUE_MASK = 0x000000FF; - - /// - /// Mask indicating the position of the given color. - /// - public const uint FI_RGBA_ALPHA_MASK = 0xFF000000; - - /// - /// Number of bits to shift left within a 32 bit block. - /// - public const int FI_RGBA_RED_SHIFT = 16; - - /// - /// Number of bits to shift left within a 32 bit block. - /// - public const int FI_RGBA_GREEN_SHIFT = 8; - - /// - /// Number of bits to shift left within a 32 bit block. - /// - public const int FI_RGBA_BLUE_SHIFT = 0; - - /// - /// Number of bits to shift left within a 32 bit block. - /// - public const int FI_RGBA_ALPHA_SHIFT = 24; - - /// - /// Mask indicating the position of color components of a 32 bit color. - /// - public const uint FI_RGBA_RGB_MASK = (FI_RGBA_RED_MASK | FI_RGBA_GREEN_MASK | FI_RGBA_BLUE_MASK); - - /// - /// Mask indicating the position of the given color. - /// - public const int FI16_555_RED_MASK = 0x7C00; - - /// - /// Mask indicating the position of the given color. - /// - public const int FI16_555_GREEN_MASK = 0x03E0; - - /// - /// Mask indicating the position of the given color. - /// - public const int FI16_555_BLUE_MASK = 0x001F; - - /// - /// Number of bits to shift left within a 16 bit block. - /// - public const int FI16_555_RED_SHIFT = 10; - - /// - /// Number of bits to shift left within a 16 bit block. - /// - public const int FI16_555_GREEN_SHIFT = 5; - - /// - /// Number of bits to shift left within a 16 bit block. - /// - public const int FI16_555_BLUE_SHIFT = 0; - - /// - /// Mask indicating the position of the given color. - /// - public const int FI16_565_RED_MASK = 0xF800; - - /// - /// Mask indicating the position of the given color. - /// - public const int FI16_565_GREEN_MASK = 0x07E0; - - /// - /// Mask indicating the position of the given color. - /// - public const int FI16_565_BLUE_MASK = 0x001F; - - /// - /// Number of bits to shift left within a 16 bit block. - /// - public const int FI16_565_RED_SHIFT = 11; - - /// - /// Number of bits to shift left within a 16 bit block. - /// - public const int FI16_565_GREEN_SHIFT = 5; - - /// - /// Number of bits to shift left within a 16 bit block. - /// - public const int FI16_565_BLUE_SHIFT = 0; - - #endregion - - #region General functions - - /// - /// Initialises the library. - /// - /// - /// When the is true, FreeImage won't make use of external plugins. - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Initialise")] - private static extern void Initialise(bool load_local_plugins_only); - - /// - /// Deinitialises the library. - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeInitialise")] - private static extern void DeInitialise(); - - /// - /// Returns a string containing the current version of the library. - /// - /// The current version of the library. - public static unsafe string GetVersion() { return PtrToStr(GetVersion_()); } - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetVersion")] - private static unsafe extern byte* GetVersion_(); - - /// - /// Returns a string containing a standard copyright message. - /// - /// A standard copyright message. - public static unsafe string GetCopyrightMessage() { return PtrToStr(GetCopyrightMessage_()); } - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetCopyrightMessage")] - private static unsafe extern byte* GetCopyrightMessage_(); - - /// - /// Calls the set error message function in FreeImage. - /// - /// Format of the bitmaps. - /// The error message. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_OutputMessageProc")] - public static extern void OutputMessageProc(FREE_IMAGE_FORMAT fif, string message); - - /// - /// You use the function FreeImage_SetOutputMessage to capture the log string - /// so that you can show it to the user of the program. - /// The callback is implemented in the event of this class. - /// - /// The function is private because FreeImage can only have a single - /// callback function. To use the callback use the - /// event of this class. - /// Handler to the callback function. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetOutputMessage")] - internal static extern void SetOutputMessage(OutputMessageFunction omf); - - #endregion - - #region Bitmap management functions - - /// - /// Creates a new bitmap in memory. - /// - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new Bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap - /// Red part of the color layout. - /// eg: 0xFF0000 - /// Green part of the color layout. - /// eg: 0x00FF00 - /// Blue part of the color layout. - /// eg: 0x0000FF - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Allocate")] - public static extern FIBITMAP Allocate(int width, int height, int bpp, - uint red_mask, uint green_mask, uint blue_mask); - - /// - /// Creates a new bitmap in memory. - /// - /// Type of the image. - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new Bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap - /// Red part of the color layout. - /// eg: 0xFF0000 - /// Green part of the color layout. - /// eg: 0x00FF00 - /// Blue part of the color layout. - /// eg: 0x0000FF - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateT")] - public static extern FIBITMAP AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp, - uint red_mask, uint green_mask, uint blue_mask); - - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateEx")] - internal static extern FIBITMAP AllocateEx(int width, int height, int bpp, - IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, - uint red_mask, uint green_mask, uint blue_mask); - - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateExT")] - internal static extern FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp, - IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, - uint red_mask, uint green_mask, uint blue_mask); - - /// - /// Makes an exact reproduction of an existing bitmap, including metadata and attached profile if any. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Clone")] - public static extern FIBITMAP Clone(FIBITMAP dib); - - /// - /// Deletes a previously loaded FIBITMAP from memory. - /// - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Unload")] - public static extern void Unload(FIBITMAP dib); - - /// - /// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP. - /// - /// Type of the bitmap. - /// Name of the file to decode. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")] - public static extern FIBITMAP Load(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags); - - /// - /// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP. - /// The filename supports UNICODE. - /// - /// Type of the bitmap. - /// Name of the file to decode. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")] - private static extern FIBITMAP LoadU(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags); - - /// - /// Loads a bitmap from an arbitrary source. - /// - /// Type of the bitmap. - /// A FreeImageIO structure with functionpointers to handle the source. - /// A handle to the source. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadFromHandle")] - public static extern FIBITMAP LoadFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io, fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags); - - /// - /// Saves a previosly loaded FIBITMAP to a file. - /// - /// Type of the bitmap. - /// Handle to a FreeImage bitmap. - /// Name of the file to save to. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_SaveU")] - public static extern bool Save(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags); - - /// - /// Saves a previosly loaded FIBITMAP to a file. - /// The filename supports UNICODE. - /// - /// Type of the bitmap. - /// Handle to a FreeImage bitmap. - /// Name of the file to save to. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_SaveU")] - private static extern bool SaveU(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags); - - /// - /// Saves a bitmap to an arbitrary source. - /// - /// Type of the bitmap. - /// Handle to a FreeImage bitmap. - /// A FreeImageIO structure with functionpointers to handle the source. - /// A handle to the source. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SaveToHandle")] - public static extern bool SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP dib, ref FreeImageIO io, fi_handle handle, - FREE_IMAGE_SAVE_FLAGS flags); - - #endregion - - #region Memory I/O streams - - /// - /// Open a memory stream. - /// - /// Pointer to the data in memory. - /// Length of the data in byte. - /// Handle to a memory stream. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMemory")] - public static extern FIMEMORY OpenMemory(IntPtr data, uint size_in_bytes); - - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMemory")] - internal static extern FIMEMORY OpenMemoryEx(byte[] data, uint size_in_bytes); - - /// - /// Close and free a memory stream. - /// - /// Handle to a memory stream. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloseMemory")] - public static extern void CloseMemory(FIMEMORY stream); - - /// - /// Decodes a bitmap from a stream, allocates memory for it and returns it as a FIBITMAP. - /// - /// Type of the bitmap. - /// Handle to a memory stream. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadFromMemory")] - public static extern FIBITMAP LoadFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags); - - /// - /// Saves a previosly loaded FIBITMAP to a stream. - /// - /// Type of the bitmap. - /// Handle to a FreeImage bitmap. - /// Handle to a memory stream. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SaveToMemory")] - public static extern bool SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP dib, FIMEMORY stream, FREE_IMAGE_SAVE_FLAGS flags); - - /// - /// Gets the current position of a memory handle. - /// - /// Handle to a memory stream. - /// The current file position if successful, -1 otherwise. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TellMemory")] - public static extern int TellMemory(FIMEMORY stream); - - /// - /// Moves the memory handle to a specified location. - /// - /// Handle to a memory stream. - /// Number of bytes from origin. - /// Initial position. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SeekMemory")] - public static extern bool SeekMemory(FIMEMORY stream, int offset, System.IO.SeekOrigin origin); - - /// - /// Provides a direct buffer access to a memory stream. - /// - /// The target memory stream. - /// Pointer to the data in memory. - /// Size of the data in bytes. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AcquireMemory")] - public static extern bool AcquireMemory(FIMEMORY stream, ref IntPtr data, ref uint size_in_bytes); - - /// - /// Reads data from a memory stream. - /// - /// The buffer to store the data in. - /// Size in bytes of the items. - /// Number of items to read. - /// The stream to read from. - /// The memory pointer associated with stream is increased by the number of bytes actually read. - /// The number of full items actually read. - /// May be less than count on error or stream-end. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ReadMemory")] - public static extern uint ReadMemory(byte[] buffer, uint size, uint count, FIMEMORY stream); - - /// - /// Writes data to a memory stream. - /// - /// The buffer to read the data from. - /// Size in bytes of the items. - /// Number of items to write. - /// The stream to write to. - /// The memory pointer associated with stream is increased by the number of bytes actually written. - /// The number of full items actually written. - /// May be less than count on error or stream-end. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_WriteMemory")] - public static extern uint WriteMemory(byte[] buffer, uint size, uint count, FIMEMORY stream); - - /// - /// Open a multi-page bitmap from a memory stream. - /// - /// Type of the bitmap. - /// The stream to decode. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage multi-paged bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadMultiBitmapFromMemory")] - public static extern FIMULTIBITMAP LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags); - - #endregion - - #region Plugin functions - - /// - /// Registers a new plugin to be used in FreeImage. - /// - /// Pointer to the function that initialises the plugin. - /// A string describing the format of the plugin. - /// A string describing the plugin. - /// A string witha comma sperated list of extensions. f.e: "pl,pl2,pl4" - /// A regular expression used to identify the bitmap. - /// The format idientifier assigned by FreeImage. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_RegisterLocalPlugin")] - public static extern FREE_IMAGE_FORMAT RegisterLocalPlugin(InitProc proc_address, - string format, string description, string extension, string regexpr); - - /// - /// Registers a new plugin to be used in FreeImage. The plugin is residing in a DLL. - /// The Init function must be called �Init� and must use the stdcall calling convention. - /// - /// Complete path to the dll file hosting the plugin. - /// A string describing the format of the plugin. - /// A string describing the plugin. - /// A string witha comma sperated list of extensions. f.e: "pl,pl2,pl4" - /// A regular expression used to identify the bitmap. - /// The format idientifier assigned by FreeImage. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_RegisterExternalPlugin")] - public static extern FREE_IMAGE_FORMAT RegisterExternalPlugin(string path, - string format, string description, string extension, string regexpr); - - /// - /// Retrieves the number of FREE_IMAGE_FORMAT identifiers being currently registered. - /// - /// The number of registered formats. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFCount")] - public static extern int GetFIFCount(); - - /// - /// Enables or disables a plugin. - /// - /// The plugin to enable or disable. - /// True: enable the plugin. false: disable the plugin. - /// The previous state of the plugin. - /// 1 - enabled. 0 - disables. -1 plugin does not exist. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPluginEnabled")] - public static extern int SetPluginEnabled(FREE_IMAGE_FORMAT fif, bool enable); - - /// - /// Retrieves the state of a plugin. - /// - /// The plugin to check. - /// 1 - enabled. 0 - disables. -1 plugin does not exist. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsPluginEnabled")] - public static extern int IsPluginEnabled(FREE_IMAGE_FORMAT fif); - - /// - /// Returns a identifier from the format string that was used to register the FIF. - /// - /// The string that was used to register the plugin. - /// A identifier from the format. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetFIFFromFormat")] - public static extern FREE_IMAGE_FORMAT GetFIFFromFormat(string format); - - /// - /// Returns a identifier from a MIME content type string - /// (MIME stands for Multipurpose Internet Mail Extension). - /// - /// A MIME content type. - /// A identifier from the MIME. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetFIFFromMime")] - public static extern FREE_IMAGE_FORMAT GetFIFFromMime(string mime); - - /// - /// Returns the string that was used to register a plugin from the system assigned . - /// - /// The assigned . - /// The string that was used to register the plugin. - public static unsafe string GetFormatFromFIF(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFormatFromFIF_(fif)); } - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFormatFromFIF")] - private static unsafe extern byte* GetFormatFromFIF_(FREE_IMAGE_FORMAT fif); - - /// - /// Returns a comma-delimited file extension list describing the bitmap formats the given plugin can read and/or write. - /// - /// The desired . - /// A comma-delimited file extension list. - public static unsafe string GetFIFExtensionList(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFExtensionList_(fif)); } - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFExtensionList")] - private static unsafe extern byte* GetFIFExtensionList_(FREE_IMAGE_FORMAT fif); - - /// - /// Returns a descriptive string that describes the bitmap formats the given plugin can read and/or write. - /// - /// The desired . - /// A descriptive string that describes the bitmap formats. - public static unsafe string GetFIFDescription(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFDescription_(fif)); } - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFDescription")] - private static unsafe extern byte* GetFIFDescription_(FREE_IMAGE_FORMAT fif); - - /// - /// Returns a regular expression string that can be used by a regular expression engine to identify the bitmap. - /// FreeImageQt makes use of this function. - /// - /// The desired . - /// A regular expression string. - public static unsafe string GetFIFRegExpr(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFRegExpr_(fif)); } - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFRegExpr")] - private static unsafe extern byte* GetFIFRegExpr_(FREE_IMAGE_FORMAT fif); - - /// - /// Given a identifier, returns a MIME content type string (MIME stands for Multipurpose Internet Mail Extension). - /// - /// The desired . - /// A MIME content type string. - public static unsafe string GetFIFMimeType(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFMimeType_(fif)); } - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFMimeType")] - private static unsafe extern byte* GetFIFMimeType_(FREE_IMAGE_FORMAT fif); - - /// - /// This function takes a filename or a file-extension and returns the plugin that can - /// read/write files with that extension in the form of a identifier. - /// - /// The filename or -extension. - /// The of the plugin. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")] - public static extern FREE_IMAGE_FORMAT GetFIFFromFilename(string filename); - - /// - /// This function takes a filename or a file-extension and returns the plugin that can - /// read/write files with that extension in the form of a identifier. - /// Supports UNICODE filenames. - /// - /// The filename or -extension. - /// The of the plugin. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")] - private static extern FREE_IMAGE_FORMAT GetFIFFromFilenameU(string filename); - - /// - /// Checks if a plugin can load bitmaps. - /// - /// The of the plugin. - /// True if the plugin can load bitmaps, else false. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsReading")] - public static extern bool FIFSupportsReading(FREE_IMAGE_FORMAT fif); - - /// - /// Checks if a plugin can save bitmaps. - /// - /// The of the plugin. - /// True if the plugin can save bitmaps, else false. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsWriting")] - public static extern bool FIFSupportsWriting(FREE_IMAGE_FORMAT fif); - - /// - /// Checks if a plugin can save bitmaps in the desired bit depth. - /// - /// The of the plugin. - /// The desired bit depth. - /// True if the plugin can save bitmaps in the desired bit depth, else false. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsExportBPP")] - public static extern bool FIFSupportsExportBPP(FREE_IMAGE_FORMAT fif, int bpp); - - /// - /// Checks if a plugin can save a bitmap in the desired data type. - /// - /// The of the plugin. - /// The desired image type. - /// True if the plugin can save bitmaps as the desired type, else false. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsExportType")] - public static extern bool FIFSupportsExportType(FREE_IMAGE_FORMAT fif, FREE_IMAGE_TYPE type); - - /// - /// Checks if a plugin can load or save an ICC profile. - /// - /// The of the plugin. - /// True if the plugin can load or save an ICC profile, else false. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsICCProfiles")] - public static extern bool FIFSupportsICCProfiles(FREE_IMAGE_FORMAT fif); - - #endregion - - #region Multipage functions - - /// - /// Loads a FreeImage multi-paged bitmap. - /// Load flags can be provided by the flags parameter. - /// - /// Format of the image. - /// The complete name of the file to load. - /// When true a new bitmap is created. - /// When true the bitmap will be loaded read only. - /// When true performance is increased at the cost of memory. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage multi-paged bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMultiBitmap")] - public static extern FIMULTIBITMAP OpenMultiBitmap(FREE_IMAGE_FORMAT fif, string filename, bool create_new, - bool read_only, bool keep_cache_in_memory, FREE_IMAGE_LOAD_FLAGS flags); - - /// - /// Loads a FreeImage multi-pages bitmap from the specified handle - /// using the specified functions. - /// Load flags can be provided by the flags parameter. - /// - /// Format of the image. - /// IO functions used to read from the specified handle. - /// The handle to load the bitmap from. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage multi-paged bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMultiBitmapFromHandle")] - public static extern FIMULTIBITMAP OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io, - fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags); - - /// - /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, applies any changes made to it. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloseMultiBitmap")] - private static extern bool CloseMultiBitmap_(FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags); - - /// - /// Returns the number of pages currently available in the multi-paged bitmap. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Number of pages. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPageCount")] - public static extern int GetPageCount(FIMULTIBITMAP bitmap); - - /// - /// Appends a new page to the end of the bitmap. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AppendPage")] - public static extern void AppendPage(FIMULTIBITMAP bitmap, FIBITMAP data); - - /// - /// Inserts a new page before the given position in the bitmap. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Page has to be a number smaller than the current number of pages available in the bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_InsertPage")] - public static extern void InsertPage(FIMULTIBITMAP bitmap, int page, FIBITMAP data); - - /// - /// Deletes the page on the given position. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Number of the page to delete. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeletePage")] - public static extern void DeletePage(FIMULTIBITMAP bitmap, int page); - - /// - /// Locks a page in memory for editing. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Number of the page to lock. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LockPage")] - public static extern FIBITMAP LockPage(FIMULTIBITMAP bitmap, int page); - - /// - /// Unlocks a previously locked page and gives it back to the multi-page engine. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Handle to a FreeImage bitmap. - /// If true, the page is applied to the multi-page bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_UnlockPage")] - public static extern void UnlockPage(FIMULTIBITMAP bitmap, FIBITMAP data, bool changed); - - /// - /// Moves the source page to the position of the target page. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// New position of the page. - /// Old position of the page. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MovePage")] - public static extern bool MovePage(FIMULTIBITMAP bitmap, int target, int source); - - /// - /// Returns an array of page-numbers that are currently locked in memory. - /// When the pages parameter is null, the size of the array is returned in the count variable. - /// - /// - /// - /// int[] lockedPages = null; - /// int count = 0; - /// GetLockedPageNumbers(dib, lockedPages, ref count); - /// lockedPages = new int[count]; - /// GetLockedPageNumbers(dib, lockedPages, ref count); - /// - /// - /// Handle to a FreeImage multi-paged bitmap. - /// The list of locked pages in the multi-pages bitmap. - /// If set to null, count will contain the number of pages. - /// If is set to null count will contain the number of locked pages. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetLockedPageNumbers")] - public static extern bool GetLockedPageNumbers(FIMULTIBITMAP bitmap, int[] pages, ref int count); - - #endregion - - #region Filetype functions - - /// - /// Orders FreeImage to analyze the bitmap signature. - /// - /// Name of the file to analyze. - /// Reserved parameter - use 0. - /// Type of the bitmap. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")] - public static extern FREE_IMAGE_FORMAT GetFileType(string filename, int size); - - - /// - /// Orders FreeImage to analyze the bitmap signature. - /// Supports UNICODE filenames. - /// - /// Name of the file to analyze. - /// Reserved parameter - use 0. - /// Type of the bitmap. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")] - private static extern FREE_IMAGE_FORMAT GetFileTypeU(string filename, int size); - - /// - /// Uses the structure as described in the topic bitmap management functions - /// to identify a bitmap type. - /// - /// A structure with functionpointers to handle the source. - /// A handle to the source. - /// Size in bytes of the source. - /// Type of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromHandle")] - public static extern FREE_IMAGE_FORMAT GetFileTypeFromHandle(ref FreeImageIO io, fi_handle handle, int size); - - /// - /// Uses a memory handle to identify a bitmap type. - /// - /// Pointer to the stream. - /// Size in bytes of the source. - /// Type of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromMemory")] - public static extern FREE_IMAGE_FORMAT GetFileTypeFromMemory(FIMEMORY stream, int size); - - #endregion - - #region Helper functions - - /// - /// Returns whether the platform is using Little Endian. - /// - /// Returns true if the platform is using Litte Endian, else false. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsLittleEndian")] - public static extern bool IsLittleEndian(); - - /// - /// Converts a X11 color name into a corresponding RGB value. - /// - /// Name of the color to convert. - /// Red component. - /// Green component. - /// Blue component. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_LookupX11Color")] - public static extern bool LookupX11Color(string szColor, out byte nRed, out byte nGreen, out byte nBlue); - - /// - /// Converts a SVG color name into a corresponding RGB value. - /// - /// Name of the color to convert. - /// Red component. - /// Green component. - /// Blue component. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_LookupSVGColor")] - public static extern bool LookupSVGColor(string szColor, out byte nRed, out byte nGreen, out byte nBlue); - - #endregion - - #region Pixel access functions - - /// - /// Returns a pointer to the data-bits of the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Pointer to the data-bits. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBits")] - public static extern IntPtr GetBits(FIBITMAP dib); - - /// - /// Returns a pointer to the start of the given scanline in the bitmap's data-bits. - /// - /// Handle to a FreeImage bitmap. - /// Number of the scanline. - /// Pointer to the scanline. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetScanLine")] - public static extern IntPtr GetScanLine(FIBITMAP dib, int scanline); - - /// - /// Get the pixel index of a palettized image at position (x, y), including range check (slow access). - /// - /// Handle to a FreeImage bitmap. - /// Pixel position in horizontal direction. - /// Pixel position in vertical direction. - /// The pixel index. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPixelIndex")] - public static extern bool GetPixelIndex(FIBITMAP dib, uint x, uint y, out byte value); - - /// - /// Get the pixel color of a 16-, 24- or 32-bit image at position (x, y), including range check (slow access). - /// - /// Handle to a FreeImage bitmap. - /// Pixel position in horizontal direction. - /// Pixel position in vertical direction. - /// The pixel color. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPixelColor")] - public static extern bool GetPixelColor(FIBITMAP dib, uint x, uint y, out RGBQUAD value); - - /// - /// Set the pixel index of a palettized image at position (x, y), including range check (slow access). - /// - /// Handle to a FreeImage bitmap. - /// Pixel position in horizontal direction. - /// Pixel position in vertical direction. - /// The new pixel index. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPixelIndex")] - public static extern bool SetPixelIndex(FIBITMAP dib, uint x, uint y, ref byte value); - - /// - /// Set the pixel color of a 16-, 24- or 32-bit image at position (x, y), including range check (slow access). - /// - /// Handle to a FreeImage bitmap. - /// Pixel position in horizontal direction. - /// Pixel position in vertical direction. - /// The new pixel color. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPixelColor")] - public static extern bool SetPixelColor(FIBITMAP dib, uint x, uint y, ref RGBQUAD value); - - #endregion - - #region Bitmap information functions - - /// - /// Retrieves the type of the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Type of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetImageType")] - public static extern FREE_IMAGE_TYPE GetImageType(FIBITMAP dib); - - /// - /// Returns the number of colors used in a bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Palette-size for palletised bitmaps, and 0 for high-colour bitmaps. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetColorsUsed")] - public static extern uint GetColorsUsed(FIBITMAP dib); - - /// - /// Returns the size of one pixel in the bitmap in bits. - /// - /// Handle to a FreeImage bitmap. - /// Size of one pixel in the bitmap in bits. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBPP")] - public static extern uint GetBPP(FIBITMAP dib); - - /// - /// Returns the width of the bitmap in pixel units. - /// - /// Handle to a FreeImage bitmap. - /// With of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetWidth")] - public static extern uint GetWidth(FIBITMAP dib); - - /// - /// Returns the height of the bitmap in pixel units. - /// - /// Handle to a FreeImage bitmap. - /// Height of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetHeight")] - public static extern uint GetHeight(FIBITMAP dib); - - /// - /// Returns the width of the bitmap in bytes. - /// - /// Handle to a FreeImage bitmap. - /// With of the bitmap in bytes. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetLine")] - public static extern uint GetLine(FIBITMAP dib); - - /// - /// Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary, - /// also known as pitch or stride or scan width. - /// - /// Handle to a FreeImage bitmap. - /// With of the bitmap in bytes. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPitch")] - public static extern uint GetPitch(FIBITMAP dib); - - /// - /// Returns the size of the DIB-element of a FIBITMAP in memory. - /// - /// Handle to a FreeImage bitmap. - /// Size of the DIB-element - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDIBSize")] - public static extern uint GetDIBSize(FIBITMAP dib); - - /// - /// Returns a pointer to the bitmap's palette. - /// - /// Handle to a FreeImage bitmap. - /// Pointer to the bitmap's palette. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPalette")] - public static extern IntPtr GetPalette(FIBITMAP dib); - - /// - /// Returns the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The horizontal resolution, in pixels-per-meter. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDotsPerMeterX")] - public static extern uint GetDotsPerMeterX(FIBITMAP dib); - - /// - /// Returns the vertical resolution, in pixels-per-meter, of the target device for the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The vertical resolution, in pixels-per-meter. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDotsPerMeterY")] - public static extern uint GetDotsPerMeterY(FIBITMAP dib); - - /// - /// Set the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The new horizontal resolution. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetDotsPerMeterX")] - public static extern void SetDotsPerMeterX(FIBITMAP dib, uint res); - - /// - /// Set the vertical resolution, in pixels-per-meter, of the target device for the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The new vertical resolution. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetDotsPerMeterY")] - public static extern void SetDotsPerMeterY(FIBITMAP dib, uint res); - - /// - /// Returns a pointer to the of the DIB-element in a FIBITMAP. - /// - /// Handle to a FreeImage bitmap. - /// Poiter to the header of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetInfoHeader")] - public static extern IntPtr GetInfoHeader(FIBITMAP dib); - - /// - /// Alias for FreeImage_GetInfoHeader that returns a pointer to a - /// rather than to a . - /// - /// Handle to a FreeImage bitmap. - /// Pointer to the structure for the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetInfo")] - public static extern IntPtr GetInfo(FIBITMAP dib); - - /// - /// Investigates the color type of the bitmap by reading the bitmap's pixel bits and analysing them. - /// - /// Handle to a FreeImage bitmap. - /// The color type of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetColorType")] - public static extern FREE_IMAGE_COLOR_TYPE GetColorType(FIBITMAP dib); - - /// - /// Returns a bit pattern describing the red color component of a pixel in a FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The bit pattern for RED. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetRedMask")] - public static extern uint GetRedMask(FIBITMAP dib); - - /// - /// Returns a bit pattern describing the green color component of a pixel in a FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The bit pattern for green. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetGreenMask")] - public static extern uint GetGreenMask(FIBITMAP dib); - - /// - /// Returns a bit pattern describing the blue color component of a pixel in a FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The bit pattern for blue. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBlueMask")] - public static extern uint GetBlueMask(FIBITMAP dib); - - /// - /// Returns the number of transparent colors in a palletised bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The number of transparent colors in a palletised bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparencyCount")] - public static extern uint GetTransparencyCount(FIBITMAP dib); - - /// - /// Returns a pointer to the bitmap's transparency table. - /// - /// Handle to a FreeImage bitmap. - /// Pointer to the bitmap's transparency table. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparencyTable")] - public static extern IntPtr GetTransparencyTable(FIBITMAP dib); - - /// - /// Tells FreeImage if it should make use of the transparency table - /// or the alpha channel that may accompany a bitmap. - /// - /// Handle to a FreeImage bitmap. - /// True to enable the transparency, false to disable. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparent")] - public static extern void SetTransparent(FIBITMAP dib, bool enabled); - - /// - /// Set the bitmap's transparency table. Only affects palletised bitmaps. - /// - /// Handle to a FreeImage bitmap. - /// Pointer to the bitmap's new transparency table. - /// The number of transparent colors in the new transparency table. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparencyTable")] - internal static extern void SetTransparencyTable(FIBITMAP dib, byte[] table, int count); - - /// - /// Returns whether the transparency table is enabled. - /// - /// Handle to a FreeImage bitmap. - /// Returns true when the transparency table is enabled (1-, 4- or 8-bit images) - /// or when the input dib contains alpha values (32-bit images). Returns false otherwise. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsTransparent")] - public static extern bool IsTransparent(FIBITMAP dib); - - /// - /// Returns whether the bitmap has a file background color. - /// - /// Handle to a FreeImage bitmap. - /// Returns true when the image has a file background color, false otherwise. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_HasBackgroundColor")] - public static extern bool HasBackgroundColor(FIBITMAP dib); - - /// - /// Returns the file background color of an image. - /// For 8-bit images, the color index in the palette is returned in the - /// rgbReserved member of the bkcolor parameter. - /// - /// Handle to a FreeImage bitmap. - /// The background color. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBackgroundColor")] - public static extern bool GetBackgroundColor(FIBITMAP dib, out RGBQUAD bkcolor); - - /// - /// Set the file background color of an image. - /// When saving an image to PNG, this background color is transparently saved to the PNG file. - /// - /// Handle to a FreeImage bitmap. - /// The new background color. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetBackgroundColor")] - public static unsafe extern bool SetBackgroundColor(FIBITMAP dib, ref RGBQUAD bkcolor); - - /// - /// Set the file background color of an image. - /// When saving an image to PNG, this background color is transparently saved to the PNG file. - /// When the bkcolor parameter is null, the background color is removed from the image. - /// - /// This overloaded version of the function with an array parameter is provided to allow - /// passing null in the parameter. This is similar to the - /// original C/C++ function. Passing null as parameter will - /// unset the dib's previously set background color. - /// - /// - /// Handle to a FreeImage bitmap. - /// The new background color. - /// The first entry in the array is used. - /// Returns true on success, false on failure. - /// - /// - /// // create a RGBQUAD color - /// RGBQUAD color = new RGBQUAD(Color.Green); - /// - /// // set the dib's background color (using the other version of the function) - /// FreeImage.SetBackgroundColor(dib, ref color); - /// - /// // remove it again (this only works due to the array parameter RGBQUAD[]) - /// FreeImage.SetBackgroundColor(dib, null); - /// - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetBackgroundColor")] - public static unsafe extern bool SetBackgroundColor(FIBITMAP dib, RGBQUAD[] bkcolor); - - /// - /// Sets the index of the palette entry to be used as transparent color - /// for the image specified. Does nothing on high color images. - /// - /// Handle to a FreeImage bitmap. - /// The index of the palette entry to be set as transparent color. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparentIndex")] - public static extern void SetTransparentIndex(FIBITMAP dib, int index); - - /// - /// Returns the palette entry used as transparent color for the image specified. - /// Works for palletised images only and returns -1 for high color - /// images or if the image has no color set to be transparent. - /// - /// Handle to a FreeImage bitmap. - /// the index of the palette entry used as transparent color for - /// the image specified or -1 if there is no transparent color found - /// (e.g. the image is a high color image). - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparentIndex")] - public static extern int GetTransparentIndex(FIBITMAP dib); - - #endregion - - #region ICC profile functions - - /// - /// Retrieves the data of the bitmap. - /// This function can also be called safely, when the original format does not support profiles. - /// - /// Handle to a FreeImage bitmap. - /// The data of the bitmap. - public static FIICCPROFILE GetICCProfileEx(FIBITMAP dib) { unsafe { return *(FIICCPROFILE*)FreeImage.GetICCProfile(dib); } } - - /// - /// Retrieves a pointer to the data of the bitmap. - /// This function can also be called safely, when the original format does not support profiles. - /// - /// Handle to a FreeImage bitmap. - /// Pointer to the data of the bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetICCProfile")] - public static extern IntPtr GetICCProfile(FIBITMAP dib); - - /// - /// Creates a new block from ICC profile data previously read from a file - /// or built by a color management system. The profile data is attached to the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Pointer to the new data. - /// Size of the data. - /// Pointer to the created structure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CreateICCProfile")] - public static extern IntPtr CreateICCProfile(FIBITMAP dib, byte[] data, int size); - - /// - /// This function destroys an previously created by . - /// After this call the bitmap will contain no profile information. - /// This function should be called to ensure that a stored bitmap will not contain any profile information. - /// - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DestroyICCProfile")] - public static extern void DestroyICCProfile(FIBITMAP dib); - - #endregion - - #region Conversion functions - - /// - /// Converts a bitmap to 4 bits. - /// If the bitmap was a high-color bitmap (16, 24 or 32-bit) or if it was a - /// monochrome or greyscale bitmap (1 or 8-bit), the end result will be a - /// greyscale bitmap, otherwise (1-bit palletised bitmaps) it will be a palletised bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo4Bits")] - public static extern FIBITMAP ConvertTo4Bits(FIBITMAP dib); - - /// - /// Converts a bitmap to 8 bits. If the bitmap was a high-color bitmap (16, 24 or 32-bit) - /// or if it was a monochrome or greyscale bitmap (1 or 4-bit), the end result will be a - /// greyscale bitmap, otherwise (1 or 4-bit palletised bitmaps) it will be a palletised bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo8Bits")] - public static extern FIBITMAP ConvertTo8Bits(FIBITMAP dib); - - /// - /// Converts a bitmap to a 8-bit greyscale image with a linear ramp. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToGreyscale")] - public static extern FIBITMAP ConvertToGreyscale(FIBITMAP dib); - - /// - /// Converts a bitmap to 16 bits, where each pixel has a color pattern of - /// 5 bits red, 5 bits green and 5 bits blue. One bit in each pixel is unused. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo16Bits555")] - public static extern FIBITMAP ConvertTo16Bits555(FIBITMAP dib); - - /// - /// Converts a bitmap to 16 bits, where each pixel has a color pattern of - /// 5 bits red, 6 bits green and 5 bits blue. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo16Bits565")] - public static extern FIBITMAP ConvertTo16Bits565(FIBITMAP dib); - - /// - /// Converts a bitmap to 24 bits. A clone of the input bitmap is returned for 24-bit bitmaps. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo24Bits")] - public static extern FIBITMAP ConvertTo24Bits(FIBITMAP dib); - - /// - /// Converts a bitmap to 32 bits. A clone of the input bitmap is returned for 32-bit bitmaps. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo32Bits")] - public static extern FIBITMAP ConvertTo32Bits(FIBITMAP dib); - - /// - /// Quantizes a high-color 24-bit bitmap to an 8-bit palette color bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Specifies the color reduction algorithm to be used. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ColorQuantize")] - public static extern FIBITMAP ColorQuantize(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize); - - /// - /// ColorQuantizeEx is an extension to the method that - /// provides additional options used to quantize a 24-bit image to any - /// number of colors (up to 256), as well as quantize a 24-bit image using a - /// partial or full provided palette. - /// - /// Handle to a FreeImage bitmap. - /// Specifies the color reduction algorithm to be used. - /// Size of the desired output palette. - /// Size of the provided palette of ReservePalette. - /// The provided palette. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ColorQuantizeEx")] - public static extern FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, int ReserveSize, RGBQUAD[] ReservePalette); - - /// - /// Converts a bitmap to 1-bit monochrome bitmap using a threshold T between [0..255]. - /// The function first converts the bitmap to a 8-bit greyscale bitmap. - /// Then, any brightness level that is less than T is set to zero, otherwise to 1. - /// For 1-bit input bitmaps, the function clones the input bitmap and builds a monochrome palette. - /// - /// Handle to a FreeImage bitmap. - /// The threshold. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Threshold")] - public static extern FIBITMAP Threshold(FIBITMAP dib, byte t); - - /// - /// Converts a bitmap to 1-bit monochrome bitmap using a dithering algorithm. - /// For 1-bit input bitmaps, the function clones the input bitmap and builds a monochrome palette. - /// - /// Handle to a FreeImage bitmap. - /// The dithering algorithm to use. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Dither")] - public static extern FIBITMAP Dither(FIBITMAP dib, FREE_IMAGE_DITHER algorithm); - - /// - /// Converts a raw bitmap to a FreeImage bitmap. - /// - /// Pointer to the memory block containing the raw bitmap. - /// The width in pixels of the raw bitmap. - /// The height in pixels of the raw bitmap. - /// Defines the total width of a scanline in the raw bitmap, - /// including padding bytes. - /// The bit depth (bits per pixel) of the raw bitmap. - /// The bit mask describing the bits used to store a single - /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// If true, the raw bitmap is stored in top-down order (top-left pixel first) - /// and in bottom-up order (bottom-left pixel first) otherwise. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertFromRawBits")] - public static extern FIBITMAP ConvertFromRawBits(IntPtr bits, int width, int height, int pitch, - uint bpp, uint red_mask, uint green_mask, uint blue_mask, bool topdown); - - /// - /// Converts a raw bitmap to a FreeImage bitmap. - /// - /// Array of bytes containing the raw bitmap. - /// The width in pixels of the raw bitmap. - /// The height in pixels of the raw bitmap. - /// Defines the total width of a scanline in the raw bitmap, - /// including padding bytes. - /// The bit depth (bits per pixel) of the raw bitmap. - /// The bit mask describing the bits used to store a single - /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// If true, the raw bitmap is stored in top-down order (top-left pixel first) - /// and in bottom-up order (bottom-left pixel first) otherwise. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertFromRawBits")] - public static extern FIBITMAP ConvertFromRawBits(byte[] bits, int width, int height, int pitch, - uint bpp, uint red_mask, uint green_mask, uint blue_mask, bool topdown); - - /// - /// Converts a FreeImage bitmap to a raw bitmap, that is a raw piece of memory. - /// - /// Pointer to the memory block receiving the raw bitmap. - /// Handle to a FreeImage bitmap. - /// The desired total width in bytes of a scanline in the raw bitmap, - /// including any padding bytes. - /// The desired bit depth (bits per pixel) of the raw bitmap. - /// The desired bit mask describing the bits used to store a single - /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The desired bit mask describing the bits used to store a single - /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The desired bit mask describing the bits used to store a single - /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// If true, the raw bitmap will be stored in top-down order (top-left pixel first) - /// and in bottom-up order (bottom-left pixel first) otherwise. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRawBits")] - public static extern void ConvertToRawBits(IntPtr bits, FIBITMAP dib, int pitch, uint bpp, - uint red_mask, uint green_mask, uint blue_mask, bool topdown); - - /// - /// Converts a FreeImage bitmap to a raw bitmap, that is a raw piece of memory. - /// - /// Array of bytes receiving the raw bitmap. - /// Handle to a FreeImage bitmap. - /// The desired total width in bytes of a scanline in the raw bitmap, - /// including any padding bytes. - /// The desired bit depth (bits per pixel) of the raw bitmap. - /// The desired bit mask describing the bits used to store a single - /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The desired bit mask describing the bits used to store a single - /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The desired bit mask describing the bits used to store a single - /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// If true, the raw bitmap will be stored in top-down order (top-left pixel first) - /// and in bottom-up order (bottom-left pixel first) otherwise. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRawBits")] - public static extern void ConvertToRawBits(byte[] bits, FIBITMAP dib, int pitch, uint bpp, - uint red_mask, uint green_mask, uint blue_mask, bool topdown); - - /// - /// Converts a 24- or 32-bit RGB(A) standard image or a 48-bit RGB image to a FIT_RGBF type image. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRGBF")] - public static extern FIBITMAP ConvertToRGBF(FIBITMAP dib); - - /// - /// Converts a non standard image whose color type is FIC_MINISBLACK - /// to a standard 8-bit greyscale image. - /// - /// Handle to a FreeImage bitmap. - /// When true the conversion is done by scaling linearly - /// each pixel value from [min, max] to an integer value between [0..255], - /// where min and max are the minimum and maximum pixel values in the image. - /// When false the conversion is done by rounding each pixel value to an integer between [0..255]. - /// - /// Rounding is done using the following formula: - /// - /// dst_pixel = (BYTE) MIN(255, MAX(0, q)) where int q = int(src_pixel + 0.5); - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToStandardType")] - public static extern FIBITMAP ConvertToStandardType(FIBITMAP src, bool scale_linear); - - /// - /// Converts an image of any type to type dst_type. - /// - /// Handle to a FreeImage bitmap. - /// Destination type. - /// True to scale linear, else false. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToType")] - public static extern FIBITMAP ConvertToType(FIBITMAP src, FREE_IMAGE_TYPE dst_type, bool scale_linear); - - #endregion - - #region Tone mapping operators - - /// - /// Converts a High Dynamic Range image (48-bit RGB or 96-bit RGBF) to a 24-bit RGB image, suitable for display. - /// - /// Handle to a FreeImage bitmap. - /// The tone mapping operator to be used. - /// Parmeter depending on the used algorithm - /// Parmeter depending on the used algorithm - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ToneMapping")] - public static extern FIBITMAP ToneMapping(FIBITMAP dib, FREE_IMAGE_TMO tmo, double first_param, double second_param); - - /// - /// Converts a High Dynamic Range image to a 24-bit RGB image using a global - /// operator based on logarithmic compression of luminance values, imitating the human response to light. - /// - /// Handle to a FreeImage bitmap. - /// A gamma correction that is applied after the tone mapping. - /// A value of 1 means no correction. - /// Scale factor allowing to adjust the brightness of the output image. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoDrago03")] - public static extern FIBITMAP TmoDrago03(FIBITMAP src, double gamma, double exposure); - - /// - /// Converts a High Dynamic Range image to a 24-bit RGB image using a global operator inspired - /// by photoreceptor physiology of the human visual system. - /// - /// Handle to a FreeImage bitmap. - /// Controls the overall image intensity in the range [-8, 8]. - /// Controls the overall image contrast in the range [0.3, 1.0[. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoReinhard05")] - public static extern FIBITMAP TmoReinhard05(FIBITMAP src, double intensity, double contrast); - - /// - /// Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and convert to 24-bit RGB. - /// - /// Handle to a FreeImage bitmap. - /// Color saturation (s parameter in the paper) in [0.4..0.6] - /// Atenuation factor (beta parameter in the paper) in [0.8..0.9] - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoFattal02")] - public static extern FIBITMAP TmoFattal02(FIBITMAP src, double color_saturation, double attenuation); - - #endregion - - #region Compression functions - - /// - /// Compresses a source buffer into a target buffer, using the ZLib library. - /// - /// Pointer to the target buffer. - /// Size of the target buffer. - /// Must be at least 0.1% larger than source_size plus 12 bytes. - /// Pointer to the source buffer. - /// Size of the source buffer. - /// The actual size of the compressed buffer, or 0 if an error occurred. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibCompress")] - public static extern uint ZLibCompress(byte[] target, uint target_size, byte[] source, uint source_size); - - /// - /// Decompresses a source buffer into a target buffer, using the ZLib library. - /// - /// Pointer to the target buffer. - /// Size of the target buffer. - /// Must have been saved outlide of zlib. - /// Pointer to the source buffer. - /// Size of the source buffer. - /// The actual size of the uncompressed buffer, or 0 if an error occurred. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibUncompress")] - public static extern uint ZLibUncompress(byte[] target, uint target_size, byte[] source, uint source_size); - - /// - /// Compresses a source buffer into a target buffer, using the ZLib library. - /// - /// Pointer to the target buffer. - /// Size of the target buffer. - /// Must be at least 0.1% larger than source_size plus 24 bytes. - /// Pointer to the source buffer. - /// Size of the source buffer. - /// The actual size of the compressed buffer, or 0 if an error occurred. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibGZip")] - public static extern uint ZLibGZip(byte[] target, uint target_size, byte[] source, uint source_size); - - /// - /// Decompresses a source buffer into a target buffer, using the ZLib library. - /// - /// Pointer to the target buffer. - /// Size of the target buffer. - /// Must have been saved outlide of zlib. - /// Pointer to the source buffer. - /// Size of the source buffer. - /// The actual size of the uncompressed buffer, or 0 if an error occurred. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibGUnzip")] - public static extern uint ZLibGUnzip(byte[] target, uint target_size, byte[] source, uint source_size); - - /// - /// Generates a CRC32 checksum. - /// - /// The CRC32 checksum to begin with. - /// Pointer to the source buffer. - /// If the value is 0, the function returns the required initial value for the crc. - /// Size of the source buffer. - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibCRC32")] - public static extern uint ZLibCRC32(uint crc, byte[] source, uint source_size); - - #endregion - - #region Tag creation and destruction - - /// - /// Allocates a new object. - /// This object must be destroyed with a call to - /// when no longer in use. - /// - /// The new . - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CreateTag")] - public static extern FITAG CreateTag(); - - /// - /// Delete a previously allocated object. - /// - /// The to destroy. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeleteTag")] - public static extern void DeleteTag(FITAG tag); - - /// - /// Creates and returns a copy of a object. - /// - /// The to clone. - /// The new . - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloneTag")] - public static extern FITAG CloneTag(FITAG tag); - - #endregion - - #region Tag accessors - - /// - /// Returns the tag field name (unique inside a metadata model). - /// - /// The tag field. - /// The field name. - public static unsafe string GetTagKey(FITAG tag) { return PtrToStr(GetTagKey_(tag)); } - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetTagKey")] - private static unsafe extern byte* GetTagKey_(FITAG tag); - - /// - /// Returns the tag description. - /// - /// The tag field. - /// The description or NULL if unavailable. - public static unsafe string GetTagDescription(FITAG tag) { return PtrToStr(GetTagDescription_(tag)); } - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetTagDescription")] - private static unsafe extern byte* GetTagDescription_(FITAG tag); - - /// - /// Returns the tag ID. - /// - /// The tag field. - /// The ID or 0 if unavailable. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagID")] - public static extern ushort GetTagID(FITAG tag); - - /// - /// Returns the tag data type. - /// - /// The tag field. - /// The tag type. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagType")] - public static extern FREE_IMAGE_MDTYPE GetTagType(FITAG tag); - - /// - /// Returns the number of components in the tag (in tag type units). - /// - /// The tag field. - /// The number of components. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagCount")] - public static extern uint GetTagCount(FITAG tag); - - /// - /// Returns the length of the tag value in bytes. - /// - /// The tag field. - /// The length of the tag value. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagLength")] - public static extern uint GetTagLength(FITAG tag); - - /// - /// Returns the tag value. - /// It is up to the programmer to interpret the returned pointer correctly, - /// according to the results of GetTagType and GetTagCount. - /// - /// The tag field. - /// Pointer to the value. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagValue")] - public static extern IntPtr GetTagValue(FITAG tag); - - /// - /// Sets the tag field name. - /// - /// The tag field. - /// The new name. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetTagKey")] - public static extern bool SetTagKey(FITAG tag, string key); - - /// - /// Sets the tag description. - /// - /// The tag field. - /// The new description. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetTagDescription")] - public static extern bool SetTagDescription(FITAG tag, string description); - - /// - /// Sets the tag ID. - /// - /// The tag field. - /// The new ID. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagID")] - public static extern bool SetTagID(FITAG tag, ushort id); - - /// - /// Sets the tag data type. - /// - /// The tag field. - /// The new type. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagType")] - public static extern bool SetTagType(FITAG tag, FREE_IMAGE_MDTYPE type); - - /// - /// Sets the number of data in the tag. - /// - /// The tag field. - /// New number of data. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagCount")] - public static extern bool SetTagCount(FITAG tag, uint count); - - /// - /// Sets the length of the tag value in bytes. - /// - /// The tag field. - /// The new length. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagLength")] - public static extern bool SetTagLength(FITAG tag, uint length); - - /// - /// Sets the tag value. - /// - /// The tag field. - /// Pointer to the new value. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagValue")] - public static extern bool SetTagValue(FITAG tag, byte[] value); - - #endregion - - #region Metadata iterator - - /// - /// Provides information about the first instance of a tag that matches the metadata model. - /// - /// The model to match. - /// Handle to a FreeImage bitmap. - /// Tag that matches the metadata model. - /// Unique search handle that can be used to call FindNextMetadata or FindCloseMetadata. - /// Null if the metadata model does not exist. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindFirstMetadata")] - public static extern FIMETADATA FindFirstMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, out FITAG tag); - - /// - /// Find the next tag, if any, that matches the metadata model argument in a previous call - /// to FindFirstMetadata, and then alters the tag object contents accordingly. - /// - /// Unique search handle provided by FindFirstMetadata. - /// Tag that matches the metadata model. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindNextMetadata")] - public static extern bool FindNextMetadata(FIMETADATA mdhandle, out FITAG tag); - - /// - /// Closes the specified metadata search handle and releases associated resources. - /// - /// The handle to close. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindCloseMetadata")] - private static extern void FindCloseMetadata_(FIMETADATA mdhandle); - - #endregion - - #region Metadata setter and getter - - /// - /// Retrieve a metadata attached to a dib. - /// - /// The metadata model to look for. - /// Handle to a FreeImage bitmap. - /// The metadata field name. - /// A FITAG structure returned by the function. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetMetadata")] - public static extern bool GetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, string key, out FITAG tag); - - /// - /// Attach a new FreeImage tag to a dib. - /// - /// The metadata model used to store the tag. - /// Handle to a FreeImage bitmap. - /// The tag field name. - /// The FreeImage tag to be attached. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetMetadata")] - public static extern bool SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, string key, FITAG tag); - - #endregion - - #region Metadata helper functions - - /// - /// Returns the number of tags contained in the model metadata model attached to the input dib. - /// - /// The metadata model. - /// Handle to a FreeImage bitmap. - /// Number of tags contained in the metadata model. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetMetadataCount")] - public static extern uint GetMetadataCount(FREE_IMAGE_MDMODEL model, FIBITMAP dib); - - /// - /// Copies the metadata of FreeImage bitmap to another. - /// - /// The FreeImage bitmap to copy the metadata to. - /// The FreeImage bitmap to copy the metadata from. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloneMetadata")] - public static extern bool CloneMetadata(FIBITMAP dst, FIBITMAP src); - - /// - /// Converts a FreeImage tag structure to a string that represents the interpreted tag value. - /// The function is not thread safe. - /// - /// The metadata model. - /// The interpreted tag value. - /// Reserved. - /// The representing string. - public static unsafe string TagToString(FREE_IMAGE_MDMODEL model, FITAG tag, uint Make) { return PtrToStr(TagToString_(model, tag, Make)); } - [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_TagToString")] - private static unsafe extern byte* TagToString_(FREE_IMAGE_MDMODEL model, FITAG tag, uint Make); - - #endregion - - #region Rotation and flipping - - /// - /// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. - /// 1-bit images rotation is limited to integer multiple of 90�. - /// null is returned for other values. - /// - /// Handle to a FreeImage bitmap. - /// The angle of rotation. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_RotateClassic")] - [Obsolete("RotateClassic is deprecated (use Rotate instead).")] - public static extern FIBITMAP RotateClassic(FIBITMAP dib, double angle); - - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Rotate")] - internal static extern FIBITMAP Rotate(FIBITMAP dib, double angle, IntPtr backgroundColor); - - /// - /// This function performs a rotation and / or translation of an 8-bit greyscale, - /// 24- or 32-bit image, using a 3rd order (cubic) B-Spline. - /// - /// Handle to a FreeImage bitmap. - /// The angle of rotation. - /// Horizontal image translation. - /// Vertical image translation. - /// Rotation center x-coordinate. - /// Rotation center y-coordinate. - /// When true the irrelevant part of the image is set to a black color, - /// otherwise, a mirroring technique is used to fill irrelevant pixels. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_RotateEx")] - public static extern FIBITMAP RotateEx(FIBITMAP dib, double angle, - double x_shift, double y_shift, double x_origin, double y_origin, bool use_mask); - - /// - /// Flip the input dib horizontally along the vertical axis. - /// - /// Handle to a FreeImage bitmap. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FlipHorizontal")] - public static extern bool FlipHorizontal(FIBITMAP dib); - - /// - /// Flip the input dib vertically along the horizontal axis. - /// - /// Handle to a FreeImage bitmap. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FlipVertical")] - public static extern bool FlipVertical(FIBITMAP dib); - - /// - /// Performs a lossless rotation or flipping on a JPEG file. - /// - /// Source file. - /// Destination file; can be the source file; will be overwritten. - /// The operation to apply. - /// To avoid lossy transformation, you can set the perfect parameter to true. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_JPEGTransformU")] - public static extern bool JPEGTransform(string src_file, string dst_file, - FREE_IMAGE_JPEG_OPERATION operation, bool perfect); - - #endregion - - #region Upsampling / downsampling - - /// - /// Performs resampling (or scaling, zooming) of a greyscale or RGB(A) image - /// to the desired destination width and height. - /// - /// Handle to a FreeImage bitmap. - /// Destination width. - /// Destination height. - /// The filter to apply. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Rescale")] - public static extern FIBITMAP Rescale(FIBITMAP dib, int dst_width, int dst_height, FREE_IMAGE_FILTER filter); - - /// - /// Creates a thumbnail from a greyscale or RGB(A) image, keeping aspect ratio. - /// - /// Handle to a FreeImage bitmap. - /// Thumbnail square size. - /// When true HDR images are transperantly converted to standard images. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MakeThumbnail")] - public static extern FIBITMAP MakeThumbnail(FIBITMAP dib, int max_pixel_size, bool convert); - - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_EnlargeCanvas")] - internal static extern FIBITMAP EnlargeCanvas(FIBITMAP dib, - int left, int top, int right, int bottom, IntPtr color, FREE_IMAGE_COLOR_OPTIONS options); - - #endregion - - #region Color manipulation - - /// - /// Perfoms an histogram transformation on a 8-, 24- or 32-bit image. - /// - /// Handle to a FreeImage bitmap. - /// The lookup table. - /// It's size is assumed to be 256 in length. - /// The color channel to be transformed. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustCurve")] - public static extern bool AdjustCurve(FIBITMAP dib, byte[] lookUpTable, FREE_IMAGE_COLOR_CHANNEL channel); - - /// - /// Performs gamma correction on a 8-, 24- or 32-bit image. - /// - /// Handle to a FreeImage bitmap. - /// The parameter represents the gamma value to use (gamma > 0). - /// A value of 1.0 leaves the image alone, less than one darkens it, and greater than one lightens it. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustGamma")] - public static extern bool AdjustGamma(FIBITMAP dib, double gamma); - - /// - /// Adjusts the brightness of a 8-, 24- or 32-bit image by a certain amount. - /// - /// Handle to a FreeImage bitmap. - /// A value 0 means no change, - /// less than 0 will make the image darker and greater than 0 will make the image brighter. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustBrightness")] - public static extern bool AdjustBrightness(FIBITMAP dib, double percentage); - - /// - /// Adjusts the contrast of a 8-, 24- or 32-bit image by a certain amount. - /// - /// Handle to a FreeImage bitmap. - /// A value 0 means no change, - /// less than 0 will decrease the contrast and greater than 0 will increase the contrast of the image. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustContrast")] - public static extern bool AdjustContrast(FIBITMAP dib, double percentage); - - /// - /// Inverts each pixel data. - /// - /// Handle to a FreeImage bitmap. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Invert")] - public static extern bool Invert(FIBITMAP dib); - - /// - /// Computes the image histogram. - /// - /// Handle to a FreeImage bitmap. - /// Array of integers with a size of 256. - /// Channel to compute from. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetHistogram")] - public static extern bool GetHistogram(FIBITMAP dib, int[] histo, FREE_IMAGE_COLOR_CHANNEL channel); - - #endregion - - #region Channel processing - - /// - /// Retrieves the red, green, blue or alpha channel of a 24- or 32-bit image. - /// - /// Handle to a FreeImage bitmap. - /// The color channel to extract. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetChannel")] - public static extern FIBITMAP GetChannel(FIBITMAP dib, FREE_IMAGE_COLOR_CHANNEL channel); - - /// - /// Insert a 8-bit dib into a 24- or 32-bit image. - /// Both images must have to same width and height. - /// - /// Handle to a FreeImage bitmap. - /// Handle to the bitmap to insert. - /// The color channel to replace. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetChannel")] - public static extern bool SetChannel(FIBITMAP dib, FIBITMAP dib8, FREE_IMAGE_COLOR_CHANNEL channel); - - /// - /// Retrieves the real part, imaginary part, magnitude or phase of a complex image. - /// - /// Handle to a FreeImage bitmap. - /// The color channel to extract. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetComplexChannel")] - public static extern FIBITMAP GetComplexChannel(FIBITMAP src, FREE_IMAGE_COLOR_CHANNEL channel); - - /// - /// Set the real or imaginary part of a complex image. - /// Both images must have to same width and height. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - /// The color channel to replace. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetComplexChannel")] - public static extern bool SetComplexChannel(FIBITMAP dst, FIBITMAP src, FREE_IMAGE_COLOR_CHANNEL channel); - - #endregion - - #region Copy / Paste / Composite routines - - /// - /// Copy a sub part of the current dib image. - /// - /// Handle to a FreeImage bitmap. - /// Specifies the left position of the cropped rectangle. - /// Specifies the top position of the cropped rectangle. - /// Specifies the right position of the cropped rectangle. - /// Specifies the bottom position of the cropped rectangle. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Copy")] - public static extern FIBITMAP Copy(FIBITMAP dib, int left, int top, int right, int bottom); - - /// - /// Alpha blend or combine a sub part image with the current dib image. - /// The bit depth of the dst bitmap must be greater than or equal to the bit depth of the src. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a FreeImage bitmap. - /// Specifies the left position of the sub image. - /// Specifies the top position of the sub image. - /// alpha blend factor. - /// The source and destination images are alpha blended if alpha=0..255. - /// If alpha > 255, then the source image is combined to the destination image. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Paste")] - public static extern bool Paste(FIBITMAP dst, FIBITMAP src, int left, int top, int alpha); - - /// - /// This function composite a transparent foreground image against a single background color or - /// against a background image. - /// - /// Handle to a FreeImage bitmap. - /// When true the background of fg is used if it contains one. - /// The application background is used if useFileBkg is false. - /// Image used as background when useFileBkg is false or fg has no background - /// and appBkColor is null. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Composite")] - public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg, ref RGBQUAD appBkColor, FIBITMAP bg); - - /// - /// This function composite a transparent foreground image against a single background color or - /// against a background image. - /// - /// Handle to a FreeImage bitmap. - /// When true the background of fg is used if it contains one. - /// The application background is used if useFileBkg is false - /// and 'appBkColor' is not null. - /// Image used as background when useFileBkg is false or fg has no background - /// and appBkColor is null. - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Composite")] - public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg, RGBQUAD[] appBkColor, FIBITMAP bg); - - /// - /// Performs a lossless crop on a JPEG file. - /// - /// Source filename. - /// Destination filename. - /// Specifies the left position of the cropped rectangle. - /// Specifies the top position of the cropped rectangle. - /// Specifies the right position of the cropped rectangle. - /// Specifies the bottom position of the cropped rectangle. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_JPEGCropU")] - public static extern bool JPEGCrop(string src_file, string dst_file, int left, int top, int right, int bottom); - - /// - /// Applies the alpha value of each pixel to its color components. - /// The aplha value stays unchanged. - /// Only works with 32-bits color depth. - /// - /// Handle to a FreeImage bitmap. - /// Returns true on success, false on failure. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_PreMultiplyWithAlpha")] - public static extern bool PreMultiplyWithAlpha(FIBITMAP dib); - - #endregion - - #region Miscellaneous algorithms - - /// - /// Solves a Poisson equation, remap result pixels to [0..1] and returns the solution. - /// - /// Handle to a FreeImage bitmap. - /// Number of cycles in the multigrid algorithm (usually 2 or 3) - /// Handle to a FreeImage bitmap. - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MultigridPoissonSolver")] - public static extern FIBITMAP MultigridPoissonSolver(FIBITMAP Laplacian, int ncycle); - - #endregion - - #region Colors - - /// - /// Creates a lookup table to be used with which may adjusts brightness and - /// contrast, correct gamma and invert the image with a single call to . - /// - /// Output lookup table to be used with . - /// The size of 'lookUpTable' is assumed to be 256. - /// Percentage brightness value where -100 <= brightness <= 100. - /// A value of 0 means no change, less than 0 will make the image darker and greater - /// than 0 will make the image brighter. - /// Percentage contrast value where -100 <= contrast <= 100. - /// A value of 0 means no change, less than 0 will decrease the contrast - /// and greater than 0 will increase the contrast of the image. - /// Gamma value to be used for gamma correction. - /// A value of 1.0 leaves the image alone, less than one darkens it, - /// and greater than one lightens it. - /// If set to true, the image will be inverted. - /// The number of adjustments applied to the resulting lookup table - /// compared to a blind lookup table. - /// - /// This function creates a lookup table to be used with which may adjust - /// brightness and contrast, correct gamma and invert the image with a single call to - /// . If more than one of these image display properties need to be adjusted, - /// using a combined lookup table should be preferred over calling each adjustment function - /// separately. That's particularly true for huge images or if performance is an issue. Then, - /// the expensive process of iterating over all pixels of an image is performed only once and - /// not up to four times. - /// - /// Furthermore, the lookup table created does not depend on the order, in which each single - /// adjustment operation is performed. Due to rounding and byte casting issues, it actually - /// matters in which order individual adjustment operations are performed. Both of the following - /// snippets most likely produce different results: - /// - /// - /// // snippet 1: contrast, brightness - /// AdjustContrast(dib, 15.0); - /// AdjustBrightness(dib, 50.0); - /// - /// - /// - /// // snippet 2: brightness, contrast - /// AdjustBrightness(dib, 50.0); - /// AdjustContrast(dib, 15.0); - /// - /// - /// Better and even faster would be snippet 3: - /// - /// - /// // snippet 3: - /// byte[] lut = new byte[256]; - /// GetAdjustColorsLookupTable(lut, 50.0, 15.0, 1.0, false); - /// AdjustCurve(dib, lut, FREE_IMAGE_COLOR_CHANNEL.FICC_RGB); - /// - /// - /// This function is also used internally by , which does not return the - /// lookup table, but uses it to call on the passed image. - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetAdjustColorsLookupTable")] - public static extern int GetAdjustColorsLookupTable(byte[] lookUpTable, double brightness, double contrast, double gamma, bool invert); - - /// - /// Adjusts an image's brightness, contrast and gamma as well as it may - /// optionally invert the image within a single operation. - /// - /// Handle to a FreeImage bitmap. - /// Percentage brightness value where -100 <= brightness <= 100. - /// A value of 0 means no change, less than 0 will make the image darker and greater - /// than 0 will make the image brighter. - /// Percentage contrast value where -100 <= contrast <= 100. - /// A value of 0 means no change, less than 0 will decrease the contrast - /// and greater than 0 will increase the contrast of the image. - /// Gamma value to be used for gamma correction. - /// A value of 1.0 leaves the image alone, less than one darkens it, - /// and greater than one lightens it. - /// This parameter must not be zero or smaller than zero. - /// If so, it will be ignored and no gamma correction will be performed on the image. - /// If set to true, the image will be inverted. - /// Returns true on success, false on failure. - /// - /// This function adjusts an image's brightness, contrast and gamma as well as it - /// may optionally invert the image within a single operation. If more than one of - /// these image display properties need to be adjusted, using this function should - /// be preferred over calling each adjustment function separately. That's particularly - /// true for huge images or if performance is an issue. - /// - /// This function relies on , - /// which creates a single lookup table, that combines all adjustment operations requested. - /// - /// Furthermore, the lookup table created by does - /// not depend on the order, in which each single adjustment operation is performed. - /// Due to rounding and byte casting issues, it actually matters in which order individual - /// adjustment operations are performed. Both of the following snippets most likely produce - /// different results: - /// - /// - /// // snippet 1: contrast, brightness - /// AdjustContrast(dib, 15.0); - /// AdjustBrightness(dib, 50.0); - /// - /// - /// - /// // snippet 2: brightness, contrast - /// AdjustBrightness(dib, 50.0); - /// AdjustContrast(dib, 15.0); - /// - /// - /// Better and even faster would be snippet 3: - /// - /// - /// // snippet 3: - /// AdjustColors(dib, 50.0, 15.0, 1.0, false); - /// - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustColors")] - public static extern bool AdjustColors(FIBITMAP dib, double brightness, double contrast, double gamma, bool invert); - - /// - /// Applies color mapping for one or several colors on a 1-, 4- or 8-bit - /// palletized or a 16-, 24- or 32-bit high color image. - /// - /// Handle to a FreeImage bitmap. - /// Array of colors to be used as the mapping source. - /// Array of colors to be used as the mapping destination. - /// The number of colors to be mapped. This is the size of both - /// srccolors and dstcolors. - /// If true, 32-bit images and colors are treated as 24-bit. - /// If true, source and destination colors are swapped, that is, - /// each destination color is also mapped to the corresponding source color. - /// The total number of pixels changed. - /// - /// This function maps up to colors specified in - /// to these specified in . - /// Thereby, color srccolors[N], if found in the image, will be replaced by color - /// dstcolors[N]. If is true, additionally all colors - /// specified in are also mapped to these specified - /// in . For high color images, the actual image data will be - /// modified whereas, for palletized images only the palette will be changed. - /// - /// The function returns the number of pixels changed or zero, if no pixels were changed. - /// - /// Both arrays and are assumed - /// not to hold less than colors. - /// - /// For 16-bit images, all colors specified are transparently converted to their - /// proper 16-bit representation (either in RGB555 or RGB565 format, which is determined - /// by the image's red- green- and blue-mask). - /// - /// Note, that this behaviour is different from what does, - /// which modifies the actual image data on palletized images. - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ApplyColorMapping")] - public static extern uint ApplyColorMapping(FIBITMAP dib, RGBQUAD[] srccolors, RGBQUAD[] dstcolors, uint count, bool ignore_alpha, bool swap); - - /// - /// Swaps two specified colors on a 1-, 4- or 8-bit palletized - /// or a 16-, 24- or 32-bit high color image. - /// - /// Handle to a FreeImage bitmap. - /// One of the two colors to be swapped. - /// The other of the two colors to be swapped. - /// If true, 32-bit images and colors are treated as 24-bit. - /// The total number of pixels changed. - /// - /// This function swaps the two specified colors and - /// on a palletized or high color image. - /// For high color images, the actual image data will be modified whereas, for palletized - /// images only the palette will be changed. - /// - /// Note, that this behaviour is different from what does, - /// which modifies the actual image data on palletized images. - /// - /// This is just a thin wrapper for and resolves to: - /// - /// - /// return ApplyColorMapping(dib, color_a, color_b, 1, ignore_alpha, true); - /// - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SwapColors")] - public static extern uint SwapColors(FIBITMAP dib, ref RGBQUAD color_a, ref RGBQUAD color_b, bool ignore_alpha); - - /// - /// Applies palette index mapping for one or several indices - /// on a 1-, 4- or 8-bit palletized image. - /// - /// Handle to a FreeImage bitmap. - /// Array of palette indices to be used as the mapping source. - /// Array of palette indices to be used as the mapping destination. - /// The number of palette indices to be mapped. This is the size of both - /// srcindices and dstindices - /// If true, source and destination palette indices are swapped, that is, - /// each destination index is also mapped to the corresponding source index. - /// The total number of pixels changed. - /// - /// This function maps up to palette indices specified in - /// to these specified in . - /// Thereby, index srcindices[N], if present in the image, will be replaced by index - /// dstindices[N]. If is true, additionally all indices - /// specified in are also mapped to these specified in - /// . - /// - /// The function returns the number of pixels changed or zero, if no pixels were changed. - /// Both arrays and are assumed not to - /// hold less than indices. - /// - /// Note, that this behaviour is different from what does, which - /// modifies the actual image data on palletized images. - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ApplyPaletteIndexMapping")] - public static extern uint ApplyPaletteIndexMapping(FIBITMAP dib, byte[] srcindices, byte[] dstindices, uint count, bool swap); - - /// - /// Swaps two specified palette indices on a 1-, 4- or 8-bit palletized image. - /// - /// Handle to a FreeImage bitmap. - /// One of the two palette indices to be swapped. - /// The other of the two palette indices to be swapped. - /// The total number of pixels changed. - /// - /// This function swaps the two specified palette indices index_a and - /// index_b on a palletized image. Therefore, not the palette, but the - /// actual image data will be modified. - /// - /// Note, that this behaviour is different from what does on palletized images, - /// which only swaps the colors in the palette. - /// - /// This is just a thin wrapper for and resolves to: - /// - /// - /// return ApplyPaletteIndexMapping(dib, index_a, index_b, 1, true); - /// - /// - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SwapPaletteIndices")] - public static extern uint SwapPaletteIndices(FIBITMAP dib, ref byte index_a, ref byte index_b); - - [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FillBackground")] - internal static extern bool FillBackground(FIBITMAP dib, IntPtr color, FREE_IMAGE_COLOR_OPTIONS options); - - #endregion - } -} - -///////////////////////////////////////////////////// -// // -// Wrapper functions // -// // -///////////////////////////////////////////////////// - - #region Structs - -namespace FreeImageAPI.IO -{ - /// - /// Wrapper for a custom handle. - /// - /// - /// The fi_handle of FreeImage in C++ is a simple pointer, but in .NET - /// it's not that simple. This wrapper uses fi_handle in two different ways. - /// - /// We implement a new plugin and FreeImage gives us a handle (pointer) that - /// we can simply pass through to the given functions in a 'FreeImageIO' - /// structure. - /// But when we want to use LoadFromhandle or SaveToHandle we need - /// a fi_handle (that we receive again in our own functions). - /// This handle is for example a stream (see LoadFromStream / SaveToStream) - /// that we want to work with. To know which stream a read/write is meant for - /// we could use a hash value that the wrapper itself handles or we can - /// go the unmanaged way of using a handle. - /// Therefor we use a to receive a unique pointer that we can - /// convert back into a .NET object. - /// When the fi_handle instance is no longer needed the instance must be disposed - /// by the creater manually! It is recommended to use the using statement to - /// be sure the instance is always disposed: - /// - /// - /// using (fi_handle handle = new fi_handle(object)) - /// { - /// callSomeFunctions(handle); - /// } - /// - /// - /// What does that mean? - /// If we get a fi_handle from unmanaged code we get a pointer to unmanaged - /// memory that we do not have to care about, and just pass ist back to FreeImage. - /// If we have to create a handle our own we use the standard constructur - /// that fills the with an pointer that represents the given object. - /// With calling the is used to retrieve the original - /// object we passed through the constructor. - /// - /// This way we can implement a fi_handle that works with managed an unmanaged - /// code. - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct fi_handle : IComparable, IComparable, IEquatable, IDisposable - { - /// - /// The handle to wrap. - /// - public IntPtr handle; - - /// - /// Initializes a new instance wrapping a managed object. - /// - /// The object to wrap. - /// - /// is null. - public fi_handle(object obj) - { - if (obj == null) - { - throw new ArgumentNullException("obj"); - } - GCHandle gch = GCHandle.Alloc(obj, GCHandleType.Normal); - handle = GCHandle.ToIntPtr(gch); - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(fi_handle left, fi_handle right) - { - return (left.handle == right.handle); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(fi_handle left, fi_handle right) - { - return (left.handle != right.handle); - } - - /// - /// Gets whether the pointer is a null pointer. - /// - public bool IsNull - { - get - { - return (handle == IntPtr.Zero); - } - } - - /// - /// Returns the object assigned to the handle in case this instance - /// was created by managed code. - /// - /// assigned to this handle or null on failure. - internal object GetObject() - { - object result = null; - if (handle != IntPtr.Zero) - { - try - { - result = GCHandle.FromIntPtr(handle).Target; - } - catch - { - } - } - return result; - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return handle.ToString(); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return handle.GetHashCode(); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is fi_handle) && (this == ((fi_handle)obj))); - } - - /// - /// Indicates whether the current object is equal to another object of the same type. - /// - /// An object to compare with this object. - /// True if the current object is equal to the other parameter; otherwise, false. - public bool Equals(fi_handle other) - { - return (this == other); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is fi_handle)) - { - throw new ArgumentException("obj"); - } - return CompareTo((fi_handle)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(fi_handle other) - { - return handle.ToInt64().CompareTo(other.handle.ToInt64()); - } - - /// - /// Releases all resources used by the instance. - /// - public void Dispose() - { - if (this.handle != IntPtr.Zero) - { - try - { - GCHandle.FromIntPtr(handle).Free(); - } - catch - { - } - finally - { - this.handle = IntPtr.Zero; - } - } - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FI1BIT structure represents a single bit. - /// It's value can be 0 or 1. - /// - [DebuggerDisplay("{value}"), - Serializable] - public struct FI1BIT - { - /// - /// Represents the largest possible value of . This field is constant. - /// - public const byte MaxValue = 0x01; - - /// - /// Represents the smallest possible value of . This field is constant. - /// - public const byte MinValue = 0x00; - - /// - /// The value of the structure. - /// - private byte value; - - /// - /// Initializes a new instance based on the specified value. - /// - /// The value to initialize with. - private FI1BIT(byte value) - { - this.value = (byte)(value & MaxValue); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator byte(FI1BIT value) - { - return value.value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FI1BIT(byte value) - { - return new FI1BIT(value); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return value.ToString(); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FI4BIT structure represents the half of a . - /// It's valuerange is between 0 and 15. - /// - [DebuggerDisplay("{value}"), - Serializable] - public struct FI4BIT - { - /// - /// Represents the largest possible value of . This field is constant. - /// - public const byte MaxValue = 0x0F; - - /// - /// Represents the smallest possible value of . This field is constant. - /// - public const byte MinValue = 0x00; - - /// - /// The value of the structure. - /// - private byte value; - - /// - /// Initializes a new instance based on the specified value. - /// - /// The value to initialize with. - private FI4BIT(byte value) - { - this.value = (byte)(value & MaxValue); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator byte(FI4BIT value) - { - return value.value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FI4BIT(byte value) - { - return new FI4BIT(value); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return value.ToString(); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FI16RGB555 structure describes a color consisting of relative - /// intensities of red, green, blue and alpha value. Each single color - /// component consumes 5 bits and so, takes values in the range from 0 to 31. - /// - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the FI16RGB555 structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the FI16RGB555 structure and my be used in all situations which require - /// an FI16RGB555 type. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// FI16RGB555 structure and the structure. - /// - /// FI16RGB555 fi16rgb; - /// // Initialize the structure using a native .NET Color structure. - /// fi16rgb = new FI16RGB555(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// fi16rgb = Color.DarkSeaGreen; - /// // Convert the FI16RGB555 instance into a native .NET Color - /// // using its implicit operator. - /// Color color = fi16rgb; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = fi16rgb.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FI16RGB555 : IComparable, IComparable, IEquatable - { - /// - /// The value of the color. - /// - private ushort value; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public FI16RGB555(Color color) - { - value = (ushort)( - (((color.R * 31) / 255) << FreeImage.FI16_555_RED_SHIFT) + - (((color.G * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT) + - (((color.B * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT)); - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FI16RGB555 left, FI16RGB555 right) - { - return (left.value == right.value); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FI16RGB555 left, FI16RGB555 right) - { - return (!(left == right)); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FI16RGB555(Color value) - { - return new FI16RGB555(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(FI16RGB555 value) - { - return value.Color; - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb( - ((value & FreeImage.FI16_555_RED_MASK) >> FreeImage.FI16_555_RED_SHIFT) * 255 / 31, - ((value & FreeImage.FI16_555_GREEN_MASK) >> FreeImage.FI16_555_GREEN_SHIFT) * 255 / 31, - ((value & FreeImage.FI16_555_BLUE_MASK) >> FreeImage.FI16_555_BLUE_SHIFT) * 255 / 31); - } - set - { - this.value = (ushort)( - (((value.R * 31) / 255) << FreeImage.FI16_555_RED_SHIFT) + - (((value.G * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT) + - (((value.B * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT)); - } - } - - /// - /// Gets or sets the red color component. - /// - public byte Red - { - get - { - return (byte)(((value & FreeImage.FI16_555_RED_MASK) >> FreeImage.FI16_555_RED_SHIFT) * 255 / 31); - } - set - { - this.value = (ushort)((this.value & (~FreeImage.FI16_555_RED_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_RED_SHIFT)); - } - } - - /// - /// Gets or sets the green color component. - /// - public byte Green - { - get - { - return (byte)(((value & FreeImage.FI16_555_GREEN_MASK) >> FreeImage.FI16_555_GREEN_SHIFT) * 255 / 31); - } - set - { - this.value = (ushort)((this.value & (~FreeImage.FI16_555_GREEN_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT)); - } - } - - /// - /// Gets or sets the blue color component. - /// - public byte Blue - { - get - { - return (byte)(((value & FreeImage.FI16_555_BLUE_MASK) >> FreeImage.FI16_555_BLUE_SHIFT) * 255 / 31); - } - set - { - this.value = (ushort)((this.value & (~FreeImage.FI16_555_BLUE_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT)); - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FI16RGB555)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FI16RGB555)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FI16RGB555 other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return base.Equals(obj); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FI16RGB555 other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FI16RGB565 structure describes a color consisting of relative - /// intensities of red, green, blue and alpha value. Each single color - /// component consumes 5 bits and so, takes values in the range from 0 to 31. - /// - /// - /// For easy integration of the underlying structure into the .NET framework, - /// the FI16RGB565 structure implements implicit conversion operators to - /// convert the represented color to and from the - /// type. This makes the type a real replacement - /// for the FI16RGB565 structure and my be used in all situations which require - /// an FI16RGB565 type. - /// - /// - /// - /// The following code example demonstrates the various conversions between the - /// FI16RGB565 structure and the structure. - /// - /// FI16RGB565 fi16rgb; - /// // Initialize the structure using a native .NET Color structure. - /// fi16rgb = new FI16RGB565(Color.Indigo); - /// // Initialize the structure using the implicit operator. - /// fi16rgb = Color.DarkSeaGreen; - /// // Convert the FI16RGB565 instance into a native .NET Color - /// // using its implicit operator. - /// Color color = fi16rgb; - /// // Using the structure's Color property for converting it - /// // into a native .NET Color. - /// Color another = fi16rgb.Color; - /// - /// - [Serializable, StructLayout(LayoutKind.Sequential)] - public struct FI16RGB565 : IComparable, IComparable, IEquatable - { - /// - /// The value of the color. - /// - private ushort value; - - /// - /// Initializes a new instance based on the specified . - /// - /// to initialize with. - public FI16RGB565(Color color) - { - value = (ushort)( - (((color.R * 31) / 255) << FreeImage.FI16_565_RED_SHIFT) + - (((color.G * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT) + - (((color.B * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT)); - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(FI16RGB565 left, FI16RGB565 right) - { - return (left.value == right.value); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(FI16RGB565 left, FI16RGB565 right) - { - return (!(left == right)); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FI16RGB565(Color value) - { - return new FI16RGB565(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator Color(FI16RGB565 value) - { - return value.Color; - } - - /// - /// Gets or sets the of the structure. - /// - public Color Color - { - get - { - return Color.FromArgb( - ((value & FreeImage.FI16_565_RED_MASK) >> FreeImage.FI16_565_RED_SHIFT) * 255 / 31, - ((value & FreeImage.FI16_565_GREEN_MASK) >> FreeImage.FI16_565_GREEN_SHIFT) * 255 / 63, - ((value & FreeImage.FI16_565_BLUE_MASK) >> FreeImage.FI16_565_BLUE_SHIFT) * 255 / 31); - } - set - { - this.value = (ushort)( - (((value.R * 31) / 255) << FreeImage.FI16_565_RED_SHIFT) + - (((value.G * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT) + - (((value.B * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT)); - } - } - - /// - /// Gets or sets the red color component. - /// - public byte Red - { - get - { - return (byte)(((value & FreeImage.FI16_565_RED_MASK) >> FreeImage.FI16_565_RED_SHIFT) * 255 / 31); - } - set - { - this.value = (ushort)((this.value & (~FreeImage.FI16_565_RED_MASK)) | (((value * 31) / 255) << FreeImage.FI16_565_RED_SHIFT)); - } - } - - /// - /// Gets or sets the green color component. - /// - public byte Green - { - get - { - return (byte)(((value & FreeImage.FI16_565_GREEN_MASK) >> FreeImage.FI16_565_GREEN_SHIFT) * 255 / 63); - } - set - { - this.value = (ushort)((this.value & (~FreeImage.FI16_565_GREEN_MASK)) | (((value * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT)); - } - } - - /// - /// Gets or sets the blue color component. - /// - public byte Blue - { - get - { - return (byte)(((value & FreeImage.FI16_565_BLUE_MASK) >> FreeImage.FI16_565_BLUE_SHIFT) * 255 / 31); - } - set - { - this.value = (ushort)((this.value & (~FreeImage.FI16_565_BLUE_MASK)) | (((value * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT)); - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FI16RGB565)) - { - throw new ArgumentException("obj"); - } - return CompareTo((FI16RGB565)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FI16RGB565 other) - { - return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return base.Equals(obj); - } - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FI16RGB565 other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return FreeImage.ColorToString(Color); - } - } -} - -namespace FreeImageAPI -{ - /// - /// The FIRational structure represents a fraction via two - /// instances which are interpreted as numerator and denominator. - /// - /// - /// The structure tries to approximate the value of - /// when creating a new instance by using a better algorithm than FreeImage does. - /// - /// The structure implements the following operators: - /// +, -, ++, --, ==, != , >, >==, <, <== and ~ (which switches nominator and denomiator). - /// - /// The structure can be converted into all .NET standard types either implicit or - /// explicit. - /// - [Serializable, StructLayout(LayoutKind.Sequential), ComVisible(true)] - public struct FIRational : IConvertible, IComparable, IFormattable, IComparable, IEquatable - { - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private int numerator; - - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private int denominator; - - /// - /// Represents the largest possible value of . This field is constant. - /// - public static readonly FIRational MaxValue = new FIRational(Int32.MaxValue, 1); - - /// - /// Represents the smallest possible value of . This field is constant. - /// - public static readonly FIRational MinValue = new FIRational(Int32.MinValue, 1); - - /// - /// Represents the smallest positive value greater than zero. This field is constant. - /// - public static readonly FIRational Epsilon = new FIRational(1, Int32.MaxValue); - - /// - /// Initializes a new instance based on the specified parameters. - /// - /// The numerator. - /// The denominator. - public FIRational(int n, int d) - { - numerator = n; - denominator = d; - Normalize(); - } - - /// - /// Initializes a new instance based on the specified parameters. - /// - /// The tag to read the data from. - public unsafe FIRational(FITAG tag) - { - switch (FreeImage.GetTagType(tag)) - { - case FREE_IMAGE_MDTYPE.FIDT_SRATIONAL: - int* value = (int*)FreeImage.GetTagValue(tag); - numerator = (int)value[0]; - denominator = (int)value[1]; - Normalize(); - return; - default: - throw new ArgumentException("tag"); - } - } - - /// - /// Initializes a new instance based on the specified parameters. - /// - /// The value to convert into a fraction. - /// - /// cannot be converted into a fraction - /// represented by two integer values. - public FIRational(decimal value) - { - try - { - int sign = value < 0 ? -1 : 1; - value = Math.Abs(value); - try - { - int[] contFract = CreateContinuedFraction(value); - CreateFraction(contFract, out numerator, out denominator); - Normalize(); - } - catch - { - numerator = 0; - denominator = 1; - } - if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) - { - int maxDen = (Int32.MaxValue / (int)value) - 2; - maxDen = maxDen < 10000 ? maxDen : 10000; - ApproximateFraction(value, maxDen, out numerator, out denominator); - Normalize(); - if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) - { - throw new OverflowException("Unable to convert value into a fraction"); - } - } - numerator *= sign; - Normalize(); - } - catch (Exception ex) - { - throw new OverflowException("Unable to calculate fraction.", ex); - } - } - - /// - /// The numerator of the fraction. - /// - public int Numerator - { - get { return numerator; } - } - - /// - /// The denominator of the fraction. - /// - public int Denominator - { - get { return denominator; } - } - - /// - /// Returns the truncated value of the fraction. - /// - /// - public int Truncate() - { - return denominator > 0 ? (int)(numerator / denominator) : 0; - } - - /// - /// Returns whether the fraction is representing an integer value. - /// - public bool IsInteger - { - get - { - return (denominator == 1 || - (denominator != 0 && (numerator % denominator == 0)) || - (denominator == 0 && numerator == 0)); - } - } - - /// - /// Calculated the greatest common divisor of 'a' and 'b'. - /// - private static long Gcd(long a, long b) - { - a = Math.Abs(a); - b = Math.Abs(b); - long r; - while (b > 0) - { - r = a % b; - a = b; - b = r; - } - return a; - } - - /// - /// Calculated the smallest common multiple of 'a' and 'b'. - /// - private static long Scm(int n, int m) - { - return Math.Abs((long)n * (long)m) / Gcd(n, m); - } - - /// - /// Normalizes the fraction. - /// - private void Normalize() - { - if (denominator == 0) - { - numerator = 0; - denominator = 1; - return; - } - - if (numerator != 1 && denominator != 1) - { - int common = (int)Gcd(numerator, denominator); - if (common != 1 && common != 0) - { - numerator /= common; - denominator /= common; - } - } - - if (denominator < 0) - { - numerator *= -1; - denominator *= -1; - } - } - - /// - /// Normalizes a fraction. - /// - private static void Normalize(ref long numerator, ref long denominator) - { - if (denominator == 0) - { - numerator = 0; - denominator = 1; - } - else if (numerator != 1 && denominator != 1) - { - long common = Gcd(numerator, denominator); - if (common != 1) - { - numerator /= common; - denominator /= common; - } - } - if (denominator < 0) - { - numerator *= -1; - denominator *= -1; - } - } - - /// - /// Returns the digits after the point. - /// - private static int GetDigits(decimal value) - { - int result = 0; - value -= decimal.Truncate(value); - while (value != 0) - { - value *= 10; - value -= decimal.Truncate(value); - result++; - } - return result; - } - - /// - /// Creates a continued fraction of a decimal value. - /// - private static int[] CreateContinuedFraction(decimal value) - { - int precision = GetDigits(value); - decimal epsilon = 0.0000001m; - List list = new List(); - value = Math.Abs(value); - - byte b = 0; - - list.Add((int)value); - value -= ((int)value); - - while (value != 0m) - { - if (++b == byte.MaxValue || value < epsilon) - { - break; - } - value = 1m / value; - if (Math.Abs((Math.Round(value, precision - 1) - value)) < epsilon) - { - value = Math.Round(value, precision - 1); - } - list.Add((int)value); - value -= ((int)value); - } - return list.ToArray(); - } - - /// - /// Creates a fraction from a continued fraction. - /// - private static void CreateFraction(int[] continuedFraction, out int numerator, out int denominator) - { - numerator = 1; - denominator = 0; - int temp; - - for (int i = continuedFraction.Length - 1; i > -1; i--) - { - temp = numerator; - numerator = continuedFraction[i] * numerator + denominator; - denominator = temp; - } - } - - /// - /// Tries 'brute force' to approximate with a fraction. - /// - private static void ApproximateFraction(decimal value, int maxDen, out int num, out int den) - { - num = 0; - den = 0; - decimal bestDifference = 1m; - decimal currentDifference = -1m; - int digits = GetDigits(value); - - if (digits <= 9) - { - int mul = 1; - for (int i = 1; i <= digits; i++) - { - mul *= 10; - } - if (mul <= maxDen) - { - num = (int)(value * mul); - den = mul; - return; - } - } - - for (int i = 1; i <= maxDen; i++) - { - int numerator = (int)Math.Floor(value * (decimal)i + 0.5m); - currentDifference = Math.Abs(value - (decimal)numerator / (decimal)i); - if (currentDifference < bestDifference) - { - num = numerator; - den = i; - bestDifference = currentDifference; - } - } - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return ((IConvertible)this).ToDouble(null).ToString(); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIRational) && (this == ((FIRational)obj))); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - #region Operators - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator +(FIRational r1) - { - return r1; - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator -(FIRational r1) - { - r1.numerator *= -1; - return r1; - } - - /// - /// Returns the reciprocal value of this instance. - /// - public static FIRational operator ~(FIRational r1) - { - int temp = r1.denominator; - r1.denominator = r1.numerator; - r1.numerator = temp; - r1.Normalize(); - return r1; - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator ++(FIRational r1) - { - checked - { - r1.numerator += r1.denominator; - } - return r1; - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator --(FIRational r1) - { - checked - { - r1.numerator -= r1.denominator; - } - return r1; - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator +(FIRational r1, FIRational r2) - { - long numerator = 0; - long denominator = Scm(r1.denominator, r2.denominator); - numerator = (r1.numerator * (denominator / r1.denominator)) + (r2.numerator * (denominator / r2.denominator)); - Normalize(ref numerator, ref denominator); - checked - { - return new FIRational((int)numerator, (int)denominator); - } - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator -(FIRational r1, FIRational r2) - { - return r1 + (-r2); - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator *(FIRational r1, FIRational r2) - { - long numerator = r1.numerator * r2.numerator; - long denominator = r1.denominator * r2.denominator; - Normalize(ref numerator, ref denominator); - checked - { - return new FIRational((int)numerator, (int)denominator); - } - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator /(FIRational r1, FIRational r2) - { - int temp = r2.denominator; - r2.denominator = r2.numerator; - r2.numerator = temp; - return r1 * r2; - } - - /// - /// Standard implementation of the operator. - /// - public static FIRational operator %(FIRational r1, FIRational r2) - { - r2.Normalize(); - if (Math.Abs(r2.numerator) < r2.denominator) - return new FIRational(0, 0); - int div = (int)(r1 / r2); - return r1 - (r2 * div); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator ==(FIRational r1, FIRational r2) - { - r1.Normalize(); - r2.Normalize(); - return (r1.numerator == r2.numerator) && (r1.denominator == r2.denominator); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator !=(FIRational r1, FIRational r2) - { - return !(r1 == r2); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator >(FIRational r1, FIRational r2) - { - long denominator = Scm(r1.denominator, r2.denominator); - return (r1.numerator * (denominator / r1.denominator)) > (r2.numerator * (denominator / r2.denominator)); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator <(FIRational r1, FIRational r2) - { - long denominator = Scm(r1.denominator, r2.denominator); - return (r1.numerator * (denominator / r1.denominator)) < (r2.numerator * (denominator / r2.denominator)); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator >=(FIRational r1, FIRational r2) - { - long denominator = Scm(r1.denominator, r2.denominator); - return (r1.numerator * (denominator / r1.denominator)) >= (r2.numerator * (denominator / r2.denominator)); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator <=(FIRational r1, FIRational r2) - { - long denominator = Scm(r1.denominator, r2.denominator); - return (r1.numerator * (denominator / r1.denominator)) <= (r2.numerator * (denominator / r2.denominator)); - } - - #endregion - - #region Conversions - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator bool(FIRational value) - { - return (value.numerator != 0); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator byte(FIRational value) - { - return (byte)(double)value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator char(FIRational value) - { - return (char)(double)value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator decimal(FIRational value) - { - return value.denominator == 0 ? 0m : (decimal)value.numerator / (decimal)value.denominator; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator double(FIRational value) - { - return value.denominator == 0 ? 0d : (double)value.numerator / (double)value.denominator; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator short(FIRational value) - { - return (short)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator int(FIRational value) - { - return (int)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator long(FIRational value) - { - return (byte)(double)value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator float(FIRational value) - { - return value.denominator == 0 ? 0f : (float)value.numerator / (float)value.denominator; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator sbyte(FIRational value) - { - return (sbyte)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator ushort(FIRational value) - { - return (ushort)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator uint(FIRational value) - { - return (uint)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator ulong(FIRational value) - { - return (ulong)(double)value; - } - - // - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIRational(bool value) - { - return new FIRational(value ? 1 : 0, 1); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIRational(byte value) - { - return new FIRational(value, 1); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIRational(char value) - { - return new FIRational(value, 1); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIRational(decimal value) - { - return new FIRational(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIRational(double value) - { - return new FIRational((decimal)value); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator FIRational(short value) - { - return new FIRational(value, 1); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator FIRational(int value) - { - return new FIRational(value, 1); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static explicit operator FIRational(long value) - { - return new FIRational((int)value, 1); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIRational(sbyte value) - { - return new FIRational(value, 1); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIRational(float value) - { - return new FIRational((decimal)value); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator FIRational(ushort value) - { - return new FIRational(value, 1); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static explicit operator FIRational(uint value) - { - return new FIRational((int)value, 1); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static explicit operator FIRational(ulong value) - { - return new FIRational((int)value, 1); - } - - #endregion - - #region IConvertible Member - - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Double; - } - - bool IConvertible.ToBoolean(IFormatProvider provider) - { - return (bool)this; - } - - byte IConvertible.ToByte(IFormatProvider provider) - { - return (byte)this; - } - - char IConvertible.ToChar(IFormatProvider provider) - { - return (char)this; - } - - DateTime IConvertible.ToDateTime(IFormatProvider provider) - { - return Convert.ToDateTime(((IConvertible)this).ToDouble(provider)); - } - - decimal IConvertible.ToDecimal(IFormatProvider provider) - { - return this; - } - - double IConvertible.ToDouble(IFormatProvider provider) - { - return this; - } - - short IConvertible.ToInt16(IFormatProvider provider) - { - return (short)this; - } - - int IConvertible.ToInt32(IFormatProvider provider) - { - return (int)this; - } - - long IConvertible.ToInt64(IFormatProvider provider) - { - return (long)this; - } - - sbyte IConvertible.ToSByte(IFormatProvider provider) - { - return (sbyte)this; - } - - float IConvertible.ToSingle(IFormatProvider provider) - { - return this; - } - - string IConvertible.ToString(IFormatProvider provider) - { - return ToString(((double)this).ToString(), provider); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider provider) - { - return Convert.ChangeType(((IConvertible)this).ToDouble(provider), conversionType, provider); - } - - ushort IConvertible.ToUInt16(IFormatProvider provider) - { - return (ushort)this; - } - - uint IConvertible.ToUInt32(IFormatProvider provider) - { - return (uint)this; - } - - ulong IConvertible.ToUInt64(IFormatProvider provider) - { - return (ulong)this; - } - - #endregion - - #region IComparable Member - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIRational)) - { - throw new ArgumentException(); - } - return CompareTo((FIRational)obj); - } - - #endregion - - #region IFormattable Member - - /// - /// Formats the value of the current instance using the specified format. - /// - /// The String specifying the format to use. - /// The IFormatProvider to use to format the value. - /// A String containing the value of the current instance in the specified format. - public string ToString(string format, IFormatProvider formatProvider) - { - if (format == null) - { - format = ""; - } - return String.Format(formatProvider, format, ((IConvertible)this).ToDouble(formatProvider)); - } - - #endregion - - #region IEquatable Member - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FIRational other) - { - return (this == other); - } - - #endregion - - #region IComparable Member - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIRational other) - { - FIRational difference = this - other; - difference.Normalize(); - if (difference.numerator > 0) return 1; - if (difference.numerator < 0) return -1; - else return 0; - } - - #endregion - } -} - -namespace FreeImageAPI -{ - /// - /// The FIURational structure represents a fraction via two - /// instances which are interpreted as numerator and denominator. - /// - /// - /// The structure tries to approximate the value of - /// when creating a new instance by using a better algorithm than FreeImage does. - /// - /// The structure implements the following operators: - /// +, ++, --, ==, != , >, >==, <, <== and ~ (which switches nominator and denomiator). - /// - /// The structure can be converted into all .NET standard types either implicit or - /// explicit. - /// - [Serializable, StructLayout(LayoutKind.Sequential), ComVisible(true)] - public struct FIURational : IConvertible, IComparable, IFormattable, IComparable, IEquatable - { - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private uint numerator; - - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private uint denominator; - - /// - /// Represents the largest possible value of . This field is constant. - /// - public static readonly FIURational MaxValue = new FIURational(UInt32.MaxValue, 1u); - - /// - /// Represents the smallest possible value of . This field is constant. - /// - public static readonly FIURational MinValue = new FIURational(0u, 1u); - - /// - /// Represents the smallest positive value greater than zero. This field is constant. - /// - public static readonly FIURational Epsilon = new FIURational(1u, UInt32.MaxValue); - - /// - /// Initializes a new instance based on the specified parameters. - /// - /// The numerator. - /// The denominator. - public FIURational(uint n, uint d) - { - numerator = n; - denominator = d; - Normalize(); - } - - /// - /// Initializes a new instance based on the specified parameters. - /// - /// The tag to read the data from. - public unsafe FIURational(FITAG tag) - { - switch (FreeImage.GetTagType(tag)) - { - case FREE_IMAGE_MDTYPE.FIDT_RATIONAL: - uint* pvalue = (uint*)FreeImage.GetTagValue(tag); - numerator = pvalue[0]; - denominator = pvalue[1]; - Normalize(); - return; - default: - throw new ArgumentException("tag"); - } - } - - /// - ///Initializes a new instance based on the specified parameters. - /// - /// The value to convert into a fraction. - /// - /// cannot be converted into a fraction - /// represented by two unsigned integer values. - public FIURational(decimal value) - { - try - { - if (value < 0) - { - throw new OverflowException("value"); - } - try - { - int[] contFract = CreateContinuedFraction(value); - CreateFraction(contFract, out numerator, out denominator); - Normalize(); - } - catch - { - numerator = 0; - denominator = 1; - } - if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) - { - int maxDen = (Int32.MaxValue / (int)value) - 2; - maxDen = maxDen < 10000 ? maxDen : 10000; - ApproximateFraction(value, maxDen, out numerator, out denominator); - Normalize(); - if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) - { - throw new OverflowException("Unable to convert value into a fraction"); - } - } - Normalize(); - } - catch (Exception ex) - { - throw new OverflowException("Unable to calculate fraction.", ex); - } - } - - /// - /// The numerator of the fraction. - /// - public uint Numerator - { - get { return numerator; } - } - - /// - /// The denominator of the fraction. - /// - public uint Denominator - { - get { return denominator; } - } - - /// - /// Returns the truncated value of the fraction. - /// - /// - public int Truncate() - { - return denominator > 0 ? (int)(numerator / denominator) : 0; - } - - /// - /// Returns whether the fraction is representing an integer value. - /// - public bool IsInteger - { - get - { - return (denominator == 1 || - (denominator != 0 && (numerator % denominator == 0)) || - (denominator == 0 && numerator == 0)); - } - } - - /// - /// Calculated the greatest common divisor of 'a' and 'b'. - /// - private static ulong Gcd(ulong a, ulong b) - { - ulong r; - while (b > 0) - { - r = a % b; - a = b; - b = r; - } - return a; - } - - /// - /// Calculated the smallest common multiple of 'a' and 'b'. - /// - private static ulong Scm(uint n, uint m) - { - return (ulong)n * (ulong)m / Gcd(n, m); - } - - /// - /// Normalizes the fraction. - /// - private void Normalize() - { - if (denominator == 0) - { - numerator = 0; - denominator = 1; - return; - } - - if (numerator != 1 && denominator != 1) - { - uint common = (uint)Gcd(numerator, denominator); - if (common != 1 && common != 0) - { - numerator /= common; - denominator /= common; - } - } - } - - /// - /// Normalizes a fraction. - /// - private static void Normalize(ref ulong numerator, ref ulong denominator) - { - if (denominator == 0) - { - numerator = 0; - denominator = 1; - } - else if (numerator != 1 && denominator != 1) - { - ulong common = Gcd(numerator, denominator); - if (common != 1) - { - numerator /= common; - denominator /= common; - } - } - } - - /// - /// Returns the digits after the point. - /// - private static int GetDigits(decimal value) - { - int result = 0; - value -= decimal.Truncate(value); - while (value != 0) - { - value *= 10; - value -= decimal.Truncate(value); - result++; - } - return result; - } - - /// - /// Creates a continued fraction of a decimal value. - /// - private static int[] CreateContinuedFraction(decimal value) - { - int precision = GetDigits(value); - decimal epsilon = 0.0000001m; - List list = new List(); - value = Math.Abs(value); - - byte b = 0; - - list.Add((int)value); - value -= ((int)value); - - while (value != 0m) - { - if (++b == byte.MaxValue || value < epsilon) - { - break; - } - value = 1m / value; - if (Math.Abs((Math.Round(value, precision - 1) - value)) < epsilon) - { - value = Math.Round(value, precision - 1); - } - list.Add((int)value); - value -= ((int)value); - } - return list.ToArray(); - } - - /// - /// Creates a fraction from a continued fraction. - /// - private static void CreateFraction(int[] continuedFraction, out uint numerator, out uint denominator) - { - numerator = 1; - denominator = 0; - uint temp; - - for (int i = continuedFraction.Length - 1; i > -1; i--) - { - temp = numerator; - numerator = (uint)(continuedFraction[i] * numerator + denominator); - denominator = temp; - } - } - - /// - /// Tries 'brute force' to approximate with a fraction. - /// - private static void ApproximateFraction(decimal value, int maxDen, out uint num, out uint den) - { - num = 0; - den = 0; - decimal bestDifference = 1m; - decimal currentDifference = -1m; - int digits = GetDigits(value); - - if (digits <= 9) - { - uint mul = 1; - for (int i = 1; i <= digits; i++) - { - mul *= 10; - } - if (mul <= maxDen) - { - num = (uint)(value * mul); - den = mul; - return; - } - } - - for (uint u = 1; u <= maxDen; u++) - { - uint numerator = (uint)Math.Floor(value * (decimal)u + 0.5m); - currentDifference = Math.Abs(value - (decimal)numerator / (decimal)u); - if (currentDifference < bestDifference) - { - num = numerator; - den = u; - bestDifference = currentDifference; - } - } - } - - /// - /// Converts the numeric value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return ((IConvertible)this).ToDouble(null).ToString(); - } - - /// - /// Tests whether the specified object is a structure - /// and is equivalent to this structure. - /// - /// The object to test. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is FIURational) && (this == ((FIURational)obj))); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return base.GetHashCode(); - } - - #region Operators - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator +(FIURational value) - { - return value; - } - - /// - /// Returns the reciprocal value of this instance. - /// - public static FIURational operator ~(FIURational value) - { - uint temp = value.denominator; - value.denominator = value.numerator; - value.numerator = temp; - value.Normalize(); - return value; - } - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator ++(FIURational value) - { - checked - { - value.numerator += value.denominator; - } - return value; - } - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator --(FIURational value) - { - checked - { - value.numerator -= value.denominator; - } - return value; - } - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator +(FIURational left, FIURational right) - { - ulong numerator = 0; - ulong denominator = Scm(left.denominator, right.denominator); - numerator = (left.numerator * (denominator / left.denominator)) + - (right.numerator * (denominator / right.denominator)); - Normalize(ref numerator, ref denominator); - checked - { - return new FIURational((uint)numerator, (uint)denominator); - } - } - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator -(FIURational left, FIURational right) - { - checked - { - if (left.denominator != right.denominator) - { - uint denom = left.denominator; - left.numerator *= right.denominator; - left.denominator *= right.denominator; - right.numerator *= denom; - right.denominator *= denom; - } - left.numerator -= right.numerator; - left.Normalize(); - return left; - } - } - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator *(FIURational left, FIURational r2) - { - ulong numerator = left.numerator * r2.numerator; - ulong denominator = left.denominator * r2.denominator; - Normalize(ref numerator, ref denominator); - checked - { - return new FIURational((uint)numerator, (uint)denominator); - } - } - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator /(FIURational left, FIURational right) - { - uint temp = right.denominator; - right.denominator = right.numerator; - right.numerator = temp; - return left * right; - } - - /// - /// Standard implementation of the operator. - /// - public static FIURational operator %(FIURational left, FIURational right) - { - right.Normalize(); - if (Math.Abs(right.numerator) < right.denominator) - return new FIURational(0, 0); - int div = (int)(left / right); - return left - (right * div); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator ==(FIURational left, FIURational right) - { - left.Normalize(); - right.Normalize(); - return (left.numerator == right.numerator) && (left.denominator == right.denominator); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator !=(FIURational left, FIURational right) - { - left.Normalize(); - right.Normalize(); - return (left.numerator != right.numerator) || (left.denominator != right.denominator); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator >(FIURational left, FIURational right) - { - ulong denominator = Scm(left.denominator, right.denominator); - return (left.numerator * (denominator / left.denominator)) > - (right.numerator * (denominator / right.denominator)); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator <(FIURational left, FIURational right) - { - ulong denominator = Scm(left.denominator, right.denominator); - return (left.numerator * (denominator / left.denominator)) < - (right.numerator * (denominator / right.denominator)); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator >=(FIURational left, FIURational right) - { - ulong denominator = Scm(left.denominator, right.denominator); - return (left.numerator * (denominator / left.denominator)) >= - (right.numerator * (denominator / right.denominator)); - } - - /// - /// Standard implementation of the operator. - /// - public static bool operator <=(FIURational left, FIURational right) - { - ulong denominator = Scm(left.denominator, right.denominator); - return (left.numerator * (denominator / left.denominator)) <= - (right.numerator * (denominator / right.denominator)); - } - - #endregion - - #region Conversions - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator bool(FIURational value) - { - return (value.numerator != 0); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator byte(FIURational value) - { - return (byte)(double)value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator char(FIURational value) - { - return (char)(double)value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator decimal(FIURational value) - { - return value.denominator == 0 ? 0m : (decimal)value.numerator / (decimal)value.denominator; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator double(FIURational value) - { - return value.denominator == 0 ? 0d : (double)value.numerator / (double)value.denominator; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator short(FIURational value) - { - return (short)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator int(FIURational value) - { - return (int)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator long(FIURational value) - { - return (byte)(double)value; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator float(FIURational value) - { - return value.denominator == 0 ? 0f : (float)value.numerator / (float)value.denominator; - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator sbyte(FIURational value) - { - return (sbyte)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator ushort(FIURational value) - { - return (ushort)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator uint(FIURational value) - { - return (uint)(double)value; - } - - /// - /// Converts the value of a structure to an structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator ulong(FIURational value) - { - return (ulong)(double)value; - } - - // - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIURational(bool value) - { - return new FIURational(value ? 1u : 0u, 1u); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIURational(byte value) - { - return new FIURational(value, 1); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIURational(char value) - { - return new FIURational(value, 1); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIURational(decimal value) - { - return new FIURational(value); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIURational(double value) - { - return new FIURational((decimal)value); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator FIURational(short value) - { - return new FIURational((uint)value, 1u); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator FIURational(int value) - { - return new FIURational((uint)value, 1u); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static explicit operator FIURational(long value) - { - return new FIURational((uint)value, 1u); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static implicit operator FIURational(sbyte value) - { - return new FIURational((uint)value, 1u); - } - - /// - /// Converts the value of a structure to a structure. - /// - /// A structure. - /// A new instance of initialized to . - public static explicit operator FIURational(float value) - { - return new FIURational((decimal)value); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static implicit operator FIURational(ushort value) - { - return new FIURational(value, 1); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static explicit operator FIURational(uint value) - { - return new FIURational(value, 1u); - } - - /// - /// Converts the value of an structure to a structure. - /// - /// An structure. - /// A new instance of initialized to . - public static explicit operator FIURational(ulong value) - { - return new FIURational((uint)value, 1u); - } - - #endregion - - #region IConvertible Member - - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Double; - } - - bool IConvertible.ToBoolean(IFormatProvider provider) - { - return (bool)this; - } - - byte IConvertible.ToByte(IFormatProvider provider) - { - return (byte)this; - } - - char IConvertible.ToChar(IFormatProvider provider) - { - return (char)this; - } - - DateTime IConvertible.ToDateTime(IFormatProvider provider) - { - return Convert.ToDateTime(((IConvertible)this).ToDouble(provider)); - } - - decimal IConvertible.ToDecimal(IFormatProvider provider) - { - return this; - } - - double IConvertible.ToDouble(IFormatProvider provider) - { - return this; - } - - short IConvertible.ToInt16(IFormatProvider provider) - { - return (short)this; - } - - int IConvertible.ToInt32(IFormatProvider provider) - { - return (int)this; - } - - long IConvertible.ToInt64(IFormatProvider provider) - { - return (long)this; - } - - sbyte IConvertible.ToSByte(IFormatProvider provider) - { - return (sbyte)this; - } - - float IConvertible.ToSingle(IFormatProvider provider) - { - return this; - } - - string IConvertible.ToString(IFormatProvider provider) - { - return ToString(((double)this).ToString(), provider); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider provider) - { - return Convert.ChangeType(((IConvertible)this).ToDouble(provider), conversionType, provider); - } - - ushort IConvertible.ToUInt16(IFormatProvider provider) - { - return (ushort)this; - } - - uint IConvertible.ToUInt32(IFormatProvider provider) - { - return (uint)this; - } - - ulong IConvertible.ToUInt64(IFormatProvider provider) - { - return (ulong)this; - } - - #endregion - - #region IComparable Member - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is FIURational)) - { - throw new ArgumentException(); - } - return CompareTo((FIURational)obj); - } - - #endregion - - #region IFormattable Member - - /// - /// Formats the value of the current instance using the specified format. - /// - /// The String specifying the format to use. - /// The IFormatProvider to use to format the value. - /// A String containing the value of the current instance in the specified format. - public string ToString(string format, IFormatProvider formatProvider) - { - if (format == null) - { - format = ""; - } - return String.Format(formatProvider, format, ((IConvertible)this).ToDouble(formatProvider)); - } - - #endregion - - #region IEquatable Member - - /// - /// Tests whether the specified structure is equivalent to this structure. - /// - /// A structure to compare to this instance. - /// true if is a structure - /// equivalent to this structure; otherwise, false. - public bool Equals(FIURational other) - { - return (this == other); - } - - #endregion - - #region IComparable Member - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(FIURational other) - { - FIURational difference = this - other; - difference.Normalize(); - if (difference.numerator > 0) return 1; - if (difference.numerator < 0) return -1; - else return 0; - } - - #endregion - } -} - - #endregion - - #region Classes - -namespace FreeImageAPI -{ - /// - /// Encapsulates a FreeImage-bitmap. - /// - [Serializable, Guid("64a4c935-b757-499c-ab8c-6110316a9e51")] - public class FreeImageBitmap : MarshalByRefObject, ICloneable, IDisposable, IEnumerable, ISerializable - { - #region Fields - - /// - /// Indicates whether this instance is disposed. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool disposed; - - /// - /// Tab object. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private object tag; - - /// - /// Object used to syncronize lock methods. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private object lockObject = new object(); - - /// - /// Holds information used by SaveAdd() methods. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private SaveInformation saveInformation = new SaveInformation(); - - /// - /// The stream that this instance was loaded from or - /// null if it has been cloned or deserialized. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private Stream stream; - - /// - /// True if the stream must be disposed with this - /// instance. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool disposeStream; - - /// - /// The number of frames contained by a mutlipage bitmap. - /// Default value is 1 and only changed if needed. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private int frameCount = 1; - - /// - /// The index of the loaded frame. - /// Default value is 0 and only changed if needed. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private int frameIndex = 0; - - /// - /// Format of the sourceimage. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private FREE_IMAGE_FORMAT originalFormat = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - - /// - /// Handle to the encapsulated FreeImage-bitmap. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private FIBITMAP dib; - - private const string ErrorLoadingBitmap = "Unable to load bitmap."; - private const string ErrorLoadingFrame = "Unable to load frame."; - private const string ErrorCreatingBitmap = "Unable to create bitmap."; - private const string ErrorUnloadBitmap = "Unable to unload bitmap."; - - #endregion - - #region Constructors and Destructor - - /// - /// Initializes a new instance of the class. - /// - protected FreeImageBitmap() - { - } - - /// - /// Initializes a new instance of the class. - /// For internal use only. - /// - /// The operation failed. - internal protected FreeImageBitmap(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - this.dib = dib; - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image. - /// - /// The original to clone from. - /// The operation failed. - /// is a null reference. - public FreeImageBitmap(FreeImageBitmap original) - { - if (original == null) - { - throw new ArgumentNullException("original"); - } - original.EnsureNotDisposed(); - dib = FreeImage.Clone(original.dib); - if (dib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - originalFormat = original.originalFormat; - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image with the specified size. - /// - /// The original to clone from. - /// The Size structure that represent the - /// size of the new . - /// The operation failed. - /// is a null reference. - /// - /// or are less or equal zero. - /// - public FreeImageBitmap(FreeImageBitmap original, Size newSize) - : this(original, newSize.Width, newSize.Height) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image with the specified size. - /// - /// The original to clone from. - /// Width of the new . - /// Height of the new . - /// The operation failed. - /// is a null reference. - /// - /// or are less or equal zero. - public FreeImageBitmap(FreeImageBitmap original, int width, int height) - { - if (original == null) - { - throw new ArgumentNullException("original"); - } - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - original.EnsureNotDisposed(); - dib = FreeImage.Rescale(original.dib, width, height, FREE_IMAGE_FILTER.FILTER_BICUBIC); - if (dib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - originalFormat = original.originalFormat; - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image. - /// - /// The original to clone from. - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - public FreeImageBitmap(Image original) - : this(original as Bitmap) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image with the specified size. - /// - /// The original to clone from. - /// The Size structure that represent the - /// size of the new . - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - /// is a null reference. - /// - /// or are less or equal zero. - /// - public FreeImageBitmap(Image original, Size newSize) - : this(original as Bitmap, newSize.Width, newSize.Height) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image with the specified size. - /// - /// The original to clone from. - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - /// is a null reference. - /// - /// or are less or equal zero. - public FreeImageBitmap(Image original, int width, int height) - : this(original as Bitmap, width, height) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image. - /// - /// The original to clone from. - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// is a null reference. - /// The operation failed. - public FreeImageBitmap(Bitmap original) - { - if (original == null) - { - throw new ArgumentNullException("original"); - } - dib = FreeImage.CreateFromBitmap(original, true); - if (dib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - originalFormat = FreeImage.GetFormat(original.RawFormat); - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image with the specified size. - /// - /// The original to clone from. - /// The Size structure that represent the - /// size of the new . - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - /// is a null reference. - /// - /// or are less or equal zero. - /// - public FreeImageBitmap(Bitmap original, Size newSize) - : this(original, newSize.Width, newSize.Height) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified image with the specified size. - /// - /// The original to clone from. - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - /// is a null reference. - /// - /// or are less or equal zero. - public FreeImageBitmap(Bitmap original, int width, int height) - { - if (original == null) - { - throw new ArgumentNullException("original"); - } - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - FIBITMAP temp = FreeImage.CreateFromBitmap(original, true); - if (temp.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - dib = FreeImage.Rescale(temp, width, height, FREE_IMAGE_FILTER.FILTER_BICUBIC); - FreeImage.Unload(temp); - if (dib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - originalFormat = FreeImage.GetFormat(original.RawFormat); - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class - /// bases on the specified stream. - /// - /// Stream to read from. - /// Ignored. - /// The operation failed. - /// is a null reference. - /// - /// You must keep the stream open for the lifetime of the . - /// - public FreeImageBitmap(Stream stream, bool useIcm) - : this(stream) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified stream. - /// - /// Stream to read from. - /// The operation failed. - /// is a null reference. - /// - /// You must keep the stream open for the lifetime of the . - /// - public FreeImageBitmap(Stream stream) - : this(stream, FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_LOAD_FLAGS.DEFAULT) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified stream in the specified format. - /// - /// Stream to read from. - /// Format of the image. - /// The operation failed. - /// is a null reference. - /// - /// You must keep the stream open for the lifetime of the . - /// - public FreeImageBitmap(Stream stream, FREE_IMAGE_FORMAT format) - : this(stream, format, FREE_IMAGE_LOAD_FLAGS.DEFAULT) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified stream with the specified loading flags. - /// - /// Stream to read from. - /// Flags to enable or disable plugin-features. - /// The operation failed. - /// is a null reference. - /// - /// You must keep the stream open for the lifetime of the . - /// - public FreeImageBitmap(Stream stream, FREE_IMAGE_LOAD_FLAGS flags) - : this(stream, FREE_IMAGE_FORMAT.FIF_UNKNOWN, flags) - { - } - - /// - /// Initializes a new instance of the class - /// bases on the specified stream in the specified format - /// with the specified loading flags. - /// - /// Stream to read from. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// The operation failed. - /// is a null reference. - /// - /// You must keep the stream open for the lifetime of the . - /// - public FreeImageBitmap(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) - { - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - this.stream = stream; - disposeStream = false; - LoadFromStream(stream, format, flags); - } - - /// - /// Initializes a new instance of the class bases on the specified file. - /// - /// The complete name of the file to load. - /// The operation failed. - /// is a null reference. - /// does not exist. - public FreeImageBitmap(string filename) - : this(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT) - { - } - - /// - /// Initializes a new instance of the class bases on the specified file. - /// - /// The complete name of the file to load. - /// Ignored. - /// The operation failed. - /// is a null reference. - /// does not exist. - public FreeImageBitmap(string filename, bool useIcm) - : this(filename) - { - } - - /// - /// Initializes a new instance of the class bases on the specified file - /// with the specified loading flags. - /// - /// The complete name of the file to load. - /// Flags to enable or disable plugin-features. - /// The operation failed. - /// is a null reference. - /// does not exist. - public FreeImageBitmap(string filename, FREE_IMAGE_LOAD_FLAGS flags) - : this(filename, FREE_IMAGE_FORMAT.FIF_UNKNOWN, flags) - { - } - - /// - /// Initializes a new instance of the class bases on the specified file - /// in the specified format. - /// - /// The complete name of the file to load. - /// Format of the image. - /// The operation failed. - /// is a null reference. - /// does not exist. - public FreeImageBitmap(string filename, FREE_IMAGE_FORMAT format) - : this(filename, format, FREE_IMAGE_LOAD_FLAGS.DEFAULT) - { - } - - /// - /// Initializes a new instance of the class bases on the specified file - /// in the specified format with the specified loading flags. - /// - /// The complete name of the file to load. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// The operation failed. - /// is a null reference. - /// does not exist. - public FreeImageBitmap(string filename, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) - { - if (filename == null) - { - throw new ArgumentNullException("filename"); - } - if (!File.Exists(filename)) - { - throw new FileNotFoundException("filename"); - } - - saveInformation.filename = filename; - stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); - disposeStream = true; - LoadFromStream(stream, format, flags); - } - - /// - /// Initializes a new instance of the class - /// bases on the specified size. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// The operation failed. - public FreeImageBitmap(int width, int height) - { - dib = FreeImage.Allocate( - width, - height, - 24, - FreeImage.FI_RGBA_RED_MASK, - FreeImage.FI_RGBA_GREEN_MASK, - FreeImage.FI_RGBA_BLUE_MASK); - if (dib.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class bases on the specified resource. - /// - /// The class used to extract the resource. - /// The name of the resource. - /// The operation failed. - public FreeImageBitmap(Type type, string resource) - : this(type.Module.Assembly.GetManifestResourceStream(type, resource)) - { - } - - /// - /// Initializes a new instance of the class bases on the specified size - /// and with the resolution of the specified object. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// The Graphics object that specifies the resolution for the new . - /// The operation failed. - /// is a null reference. - public FreeImageBitmap(int width, int height, Graphics g) - : this(width, height) - { - FreeImage.SetResolutionX(dib, (uint)g.DpiX); - FreeImage.SetResolutionY(dib, (uint)g.DpiY); - } - - /// - /// Initializes a new instance of the class bases on the specified size and format. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// The PixelFormat enumeration for the new . - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - /// is invalid. - /// - /// or are less or equal zero. - public FreeImageBitmap(int width, int height, PixelFormat format) - { - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - uint bpp, redMask, greenMask, blueMask; - FREE_IMAGE_TYPE type; - if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask)) - { - throw new ArgumentException("format is invalid"); - } - dib = FreeImage.AllocateT(type, width, height, (int)bpp, redMask, greenMask, blueMask); - if (dib.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class bases on the specified size and type. - /// Only non standard bitmaps are supported. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// The type of the bitmap. - /// The operation failed. - /// - /// is FIT_BITMAP or FIT_UNKNOWN. - /// is invalid. - /// - /// or are less or equal zero. - public FreeImageBitmap(int width, int height, FREE_IMAGE_TYPE type) - { - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - if ((type == FREE_IMAGE_TYPE.FIT_BITMAP) || (type == FREE_IMAGE_TYPE.FIT_UNKNOWN)) - { - throw new ArgumentException("type is invalid."); - } - dib = FreeImage.AllocateT(type, width, height, 0, 0u, 0u, 0u); - if (dib.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class bases on the specified size, - /// pixel format and pixel data. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// Integer that specifies the byte offset between the beginning - /// of one scan line and the next. This is usually (but not necessarily) - /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) - /// multiplied by the width of the bitmap. The value passed to this parameter must - /// be a multiple of four.. - /// The PixelFormat enumeration for the new . - /// Pointer to an array of bytes that contains the pixel data. - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - /// is invalid. - /// - /// or are less or equal zero. - public FreeImageBitmap(int width, int height, int stride, PixelFormat format, IntPtr scan0) - { - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - uint bpp, redMask, greenMask, blueMask; - FREE_IMAGE_TYPE type; - bool topDown = (stride > 0); - stride = (stride > 0) ? stride : (stride * -1); - - if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask)) - { - throw new ArgumentException("format is invalid."); - } - - dib = FreeImage.ConvertFromRawBits( - scan0, type, width, height, stride, bpp, redMask, greenMask, blueMask, topDown); - - if (dib.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class bases on the specified size, - /// pixel format and pixel data. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// Integer that specifies the byte offset between the beginning - /// of one scan line and the next. This is usually (but not necessarily) - /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) - /// multiplied by the width of the bitmap. The value passed to this parameter must - /// be a multiple of four.. - /// The PixelFormat enumeration for the new . - /// Array of bytes containing the bitmap data. - /// - /// Although this constructor supports creating images in both formats - /// - /// and , bitmaps - /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA - /// images respectively. Currently, there is no support for automatic premultiplying images in - /// . - /// - /// The operation failed. - /// is invalid. - /// - /// or are less or equal zero. - /// is null - public FreeImageBitmap(int width, int height, int stride, PixelFormat format, byte[] bits) - { - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - if (bits == null) - { - throw new ArgumentNullException("bits"); - } - uint bpp, redMask, greenMask, blueMask; - FREE_IMAGE_TYPE type; - bool topDown = (stride > 0); - stride = (stride > 0) ? stride : (stride * -1); - - if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask)) - { - throw new ArgumentException("format is invalid."); - } - - dib = FreeImage.ConvertFromRawBits( - bits, type, width, height, stride, bpp, redMask, greenMask, blueMask, topDown); - - if (dib.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class bases on the specified size, - /// pixel format and pixel data. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// Integer that specifies the byte offset between the beginning - /// of one scan line and the next. This is usually (but not necessarily) - /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) - /// multiplied by the width of the bitmap. The value passed to this parameter must - /// be a multiple of four.. - /// The color depth of the new - /// The type for the new . - /// Pointer to an array of bytes that contains the pixel data. - /// The operation failed. - /// is invalid. - /// - /// or are less or equal zero. - public FreeImageBitmap(int width, int height, int stride, int bpp, FREE_IMAGE_TYPE type, IntPtr scan0) - { - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - uint redMask, greenMask, blueMask; - bool topDown = (stride > 0); - stride = (stride > 0) ? stride : (stride * -1); - - if (!FreeImage.GetTypeParameters(type, bpp, out redMask, out greenMask, out blueMask)) - { - throw new ArgumentException("bpp and type are invalid or not supported."); - } - - dib = FreeImage.ConvertFromRawBits( - scan0, type, width, height, stride, (uint)bpp, redMask, greenMask, blueMask, topDown); - - if (dib.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class bases on the specified size, - /// pixel format and pixel data. - /// - /// The width, in pixels, of the new . - /// The height, in pixels, of the new . - /// Integer that specifies the byte offset between the beginning - /// of one scan line and the next. This is usually (but not necessarily) - /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) - /// multiplied by the width of the bitmap. The value passed to this parameter must - /// be a multiple of four.. - /// The color depth of the new - /// The type for the new . - /// Array of bytes containing the bitmap data. - /// The operation failed. - /// is invalid. - /// - /// or are less or equal zero. - /// is null - public FreeImageBitmap(int width, int height, int stride, int bpp, FREE_IMAGE_TYPE type, byte[] bits) - { - if (width <= 0) - { - throw new ArgumentOutOfRangeException("width"); - } - if (height <= 0) - { - throw new ArgumentOutOfRangeException("height"); - } - if (bits == null) - { - throw new ArgumentNullException("bits"); - } - uint redMask, greenMask, blueMask; - bool topDown = (stride > 0); - stride = (stride > 0) ? stride : (stride * -1); - - if (!FreeImage.GetTypeParameters(type, bpp, out redMask, out greenMask, out blueMask)) - { - throw new ArgumentException("bpp and type are invalid or not supported."); - } - - dib = FreeImage.ConvertFromRawBits( - bits, type, width, height, stride, (uint)bpp, redMask, greenMask, blueMask, topDown); - - if (dib.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - AddMemoryPressure(); - } - - /// - /// Initializes a new instance of the class. - /// - /// The operation failed. - /// The operation failed. - public FreeImageBitmap(SerializationInfo info, StreamingContext context) - { - try - { - byte[] data = (byte[])info.GetValue("Bitmap Data", typeof(byte[])); - if ((data != null) && (data.Length > 0)) - { - MemoryStream memory = new MemoryStream(data); - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_TIFF; - dib = FreeImage.LoadFromStream(memory, ref format); - - if (dib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - - AddMemoryPressure(); - } - } - catch (Exception ex) - { - throw new SerializationException("Deserialization failed.", ex); - } - } - - /// - /// Frees all managed and unmanaged ressources. - /// - ~FreeImageBitmap() - { - Dispose(false); - } - - #endregion - - #region Operators - - /// - /// Converts a instance to a instance. - /// - /// A instance. - /// A new instance of initialized to . - /// - /// The explicit conversion from into Bitmap - /// allows to create an instance on the fly and use it as if - /// was a Bitmap. This way it can be directly used with a - /// PixtureBox for example without having to call any - /// conversion operations. - /// - public static explicit operator Bitmap(FreeImageBitmap value) - { - return value.ToBitmap(); - } - - /// - /// Converts a instance to a instance. - /// - /// A instance. - /// A new instance of initialized to . - /// - /// The explicit conversion from into - /// allows to create an instance on the fly to perform - /// image processing operations and converting it back. - /// - public static explicit operator FreeImageBitmap(Bitmap value) - { - return new FreeImageBitmap(value); - } - - /// - /// Determines whether two specified objects have the same value. - /// - /// A or a null reference (Nothing in Visual Basic). - /// A or a null reference (Nothing in Visual Basic). - /// - /// true if the value of left is the same as the value of right; otherwise, false. - /// - public static bool operator ==(FreeImageBitmap left, FreeImageBitmap right) - { - if (object.ReferenceEquals(left, right)) - { - return true; - } - else if (object.ReferenceEquals(left, null) || object.ReferenceEquals(right, null)) - { - return false; - } - else - { - left.EnsureNotDisposed(); - right.EnsureNotDisposed(); - return FreeImage.Compare(left.dib, right.dib, FREE_IMAGE_COMPARE_FLAGS.COMPLETE); - } - } - - /// - /// Determines whether two specified objects have different values. - /// - /// A or a null reference (Nothing in Visual Basic). - /// A or a null reference (Nothing in Visual Basic). - /// - /// true if the value of left is different from the value of right; otherwise, false. - /// - public static bool operator !=(FreeImageBitmap left, FreeImageBitmap right) - { - return (!(left == right)); - } - - #endregion - - #region Properties - - /// - /// Type of the bitmap. - /// - public FREE_IMAGE_TYPE ImageType - { - get - { - EnsureNotDisposed(); - return FreeImage.GetImageType(dib); - } - } - - /// - /// Number of palette entries. - /// - public int ColorsUsed - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetColorsUsed(dib); - } - } - - /// - /// The number of unique colors actually used by the bitmap. This might be different from - /// what ColorsUsed returns, which actually returns the palette size for palletised images. - /// Works for FIT_BITMAP type bitmaps only. - /// - public int UniqueColors - { - get - { - EnsureNotDisposed(); - return FreeImage.GetUniqueColors(dib); - } - } - - /// - /// The size of one pixel in the bitmap in bits. - /// - public int ColorDepth - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetBPP(dib); - } - } - - /// - /// Width of the bitmap in pixel units. - /// - public int Width - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetWidth(dib); - } - } - - /// - /// Height of the bitmap in pixel units. - /// - public int Height - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetHeight(dib); - } - } - - /// - /// Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary. - /// - public int Pitch - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetPitch(dib); - } - } - - /// - /// Size of the bitmap in memory. - /// - public int DataSize - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetDIBSize(dib); - } - } - - /// - /// Returns a structure that represents the palette of a FreeImage bitmap. - /// - /// is false. - public Palette Palette - { - get - { - EnsureNotDisposed(); - if (HasPalette) - { - return new Palette(dib); - } - throw new InvalidOperationException("This bitmap does not have a palette."); - } - } - - /// - /// Gets whether the bitmap is RGB 555. - /// - public bool IsRGB555 - { - get - { - EnsureNotDisposed(); - return FreeImage.IsRGB555(dib); - } - } - - /// - /// Gets whether the bitmap is RGB 565. - /// - public bool IsRGB565 - { - get - { - EnsureNotDisposed(); - return FreeImage.IsRGB565(dib); - } - } - - /// - /// Gets the horizontal resolution, in pixels per inch, of this . - /// - public float HorizontalResolution - { - get - { - EnsureNotDisposed(); - return (float)FreeImage.GetResolutionX(dib); - } - private set - { - EnsureNotDisposed(); - FreeImage.SetResolutionX(dib, (uint)value); - } - } - - /// - /// Gets the vertical resolution, in pixels per inch, of this . - /// - public float VerticalResolution - { - get - { - EnsureNotDisposed(); - return (float)FreeImage.GetResolutionY(dib); - } - private set - { - EnsureNotDisposed(); - FreeImage.SetResolutionY(dib, (uint)value); - } - } - - /// - /// Returns the structure of this . - /// - public BITMAPINFOHEADER InfoHeader - { - get - { - EnsureNotDisposed(); - return FreeImage.GetInfoHeaderEx(dib); - } - } - - /// - /// Returns the structure of a this . - /// - public BITMAPINFO Info - { - get - { - EnsureNotDisposed(); - return FreeImage.GetInfoEx(dib); - } - } - - /// - /// Investigates the color type of this - /// by reading the bitmaps pixel bits and analysing them. - /// - public FREE_IMAGE_COLOR_TYPE ColorType - { - get - { - EnsureNotDisposed(); - return FreeImage.GetColorType(dib); - } - } - - /// - /// Bit pattern describing the red color component of a pixel in this . - /// - public uint RedMask - { - get - { - EnsureNotDisposed(); - return FreeImage.GetRedMask(dib); - } - } - - /// - /// Bit pattern describing the green color component of a pixel in this . - /// - public uint GreenMask - { - get - { - EnsureNotDisposed(); - return FreeImage.GetGreenMask(dib); - } - } - - /// - /// Bit pattern describing the blue color component of a pixel in this . - /// - public uint BlueMask - { - get - { - EnsureNotDisposed(); - return FreeImage.GetBlueMask(dib); - } - } - - /// - /// Number of transparent colors in a palletised . - /// - public int TransparencyCount - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetTransparencyCount(dib); - } - } - - /// - /// Get or sets transparency table of this . - /// - public byte[] TransparencyTable - { - get - { - EnsureNotDisposed(); - return FreeImage.GetTransparencyTableEx(dib); - } - set - { - EnsureNotDisposed(); - FreeImage.SetTransparencyTable(dib, value); - } - } - - /// - /// Gets or sets whether this is transparent. - /// - public bool IsTransparent - { - get - { - EnsureNotDisposed(); - return FreeImage.IsTransparent(dib); - } - set - { - EnsureNotDisposed(); - FreeImage.SetTransparent(dib, value); - } - } - - /// - /// Gets whether this has a file background color. - /// - public bool HasBackgroundColor - { - get - { - EnsureNotDisposed(); - return FreeImage.HasBackgroundColor(dib); - } - } - - /// - /// Gets or sets the background color of this . - /// In case the value is null, the background color is removed. - /// - /// Get: There is no background color available. - /// Set: Setting background color failed. - public Color? BackgroundColor - { - get - { - EnsureNotDisposed(); - if (!FreeImage.HasBackgroundColor(dib)) - { - throw new InvalidOperationException("No background color available."); - } - RGBQUAD rgbq; - FreeImage.GetBackgroundColor(dib, out rgbq); - return rgbq.Color; - } - set - { - EnsureNotDisposed(); - if (!FreeImage.SetBackgroundColor(dib, (value.HasValue ? new RGBQUAD[] { value.Value } : null))) - { - throw new Exception("Setting background color failed."); - } - } - } - - /// - /// Pointer to the data-bits of this . - /// - public IntPtr Bits - { - get - { - EnsureNotDisposed(); - return FreeImage.GetBits(dib); - } - } - - /// - /// Width, in bytes, of this . - /// - public int Line - { - get - { - EnsureNotDisposed(); - return (int)FreeImage.GetLine(dib); - } - } - - /// - /// Pointer to the scanline of the top most pixel row of this . - /// - public IntPtr Scan0 - { - get - { - EnsureNotDisposed(); - return FreeImage.GetScanLine(dib, (int)(FreeImage.GetHeight(dib) - 1)); - } - } - - /// - /// Width, in bytes, of this . - /// In case this is top down Stride will be positive, else negative. - /// - public int Stride - { - get - { - return -Line; - } - } - - /// - /// Gets attribute flags for the pixel data of this . - /// - public unsafe int Flags - { - get - { - EnsureNotDisposed(); - int result = 0; - byte alpha; - int cd = ColorDepth; - - if ((cd == 32) || (FreeImage.GetTransparencyCount(dib) != 0)) - { - result += (int)ImageFlags.HasAlpha; - } - - if (cd == 32) - { - uint width = FreeImage.GetWidth(dib); - uint height = FreeImage.GetHeight(dib); - for (int y = 0; y < height; y++) - { - RGBQUAD* scanline = (RGBQUAD*)FreeImage.GetScanLine(dib, y); - for (int x = 0; x < width; x++) - { - alpha = scanline[x].Color.A; - if (alpha != byte.MinValue && alpha != byte.MaxValue) - { - result += (int)ImageFlags.HasTranslucent; - y = (int)height; - break; - } - } - } - } - else if (FreeImage.GetTransparencyCount(dib) != 0) - { - byte[] transTable = FreeImage.GetTransparencyTableEx(dib); - for (int i = 0; i < transTable.Length; i++) - { - if (transTable[i] != byte.MinValue && transTable[i] != byte.MaxValue) - { - result += (int)ImageFlags.HasTranslucent; - break; - } - } - } - - if (FreeImage.GetICCProfileEx(dib).IsCMYK) - { - result += (int)ImageFlags.ColorSpaceCmyk; - } - else - { - result += (int)ImageFlags.ColorSpaceRgb; - } - - if (FreeImage.GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_MINISBLACK || - FreeImage.GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_MINISWHITE) - { - result += (int)ImageFlags.ColorSpaceGray; - } - - if (originalFormat == FREE_IMAGE_FORMAT.FIF_BMP || - originalFormat == FREE_IMAGE_FORMAT.FIF_FAXG3 || - originalFormat == FREE_IMAGE_FORMAT.FIF_ICO || - originalFormat == FREE_IMAGE_FORMAT.FIF_JPEG || - originalFormat == FREE_IMAGE_FORMAT.FIF_PCX || - originalFormat == FREE_IMAGE_FORMAT.FIF_PNG || - originalFormat == FREE_IMAGE_FORMAT.FIF_PSD || - originalFormat == FREE_IMAGE_FORMAT.FIF_TIFF) - { - result += (int)ImageFlags.HasRealDpi; - } - - return result; - } - } - - /// - /// Gets the width and height of this . - /// - public SizeF PhysicalDimension - { - get - { - EnsureNotDisposed(); - return new SizeF((float)FreeImage.GetWidth(dib), (float)FreeImage.GetHeight(dib)); - } - } - - /// - /// Gets the pixel format for this . - /// - public PixelFormat PixelFormat - { - get - { - EnsureNotDisposed(); - return FreeImage.GetPixelFormat(dib); - } - } - - /// - /// Gets IDs of the property items stored in this . - /// - public int[] PropertyIdList - { - get - { - EnsureNotDisposed(); - List list = new List(); - ImageMetadata metaData = new ImageMetadata(dib, true); - - foreach (MetadataModel metadataModel in metaData) - { - foreach (MetadataTag metadataTag in metadataModel) - { - list.Add(metadataTag.ID); - } - } - - return list.ToArray(); - } - } - - /// - /// Gets all the property items (pieces of metadata) stored in this . - /// - public PropertyItem[] PropertyItems - { - get - { - EnsureNotDisposed(); - List list = new List(); - ImageMetadata metaData = new ImageMetadata(dib, true); - - foreach (MetadataModel metadataModel in metaData) - { - foreach (MetadataTag metadataTag in metadataModel) - { - list.Add(metadataTag.GetPropertyItem()); - } - } - - return list.ToArray(); - } - } - - /// - /// Gets the format of this . - /// - public ImageFormat RawFormat - { - get - { - EnsureNotDisposed(); - Attribute guidAttribute = - Attribute.GetCustomAttribute( - typeof(FreeImageBitmap), typeof(System.Runtime.InteropServices.GuidAttribute) - ); - return (guidAttribute == null) ? - null : - new ImageFormat(new Guid(((GuidAttribute)guidAttribute).Value)); - } - } - - /// - /// Gets the width and height, in pixels, of this . - /// - public Size Size - { - get - { - EnsureNotDisposed(); - return new Size(Width, Height); - } - } - - /// - /// Gets or sets an object that provides additional data about the . - /// - public Object Tag - { - get - { - EnsureNotDisposed(); - return tag; - } - set - { - EnsureNotDisposed(); - tag = value; - } - } - - /// - /// Gets whether this has been disposed. - /// - public bool IsDisposed - { - get - { - return disposed; - } - } - - /// - /// Gets a new instance of a metadata representing class. - /// - public ImageMetadata Metadata - { - get - { - EnsureNotDisposed(); - return new ImageMetadata(dib, true); - } - } - - /// - /// Gets or sets the comment of this . - /// Supported formats are JPEG, PNG and GIF. - /// - public string Comment - { - get - { - EnsureNotDisposed(); - return FreeImage.GetImageComment(dib); - } - set - { - EnsureNotDisposed(); - FreeImage.SetImageComment(dib, value); - } - } - - /// - /// Returns whether this has a palette. - /// - public bool HasPalette - { - get - { - EnsureNotDisposed(); - return (FreeImage.GetPalette(dib) != IntPtr.Zero); - } - } - - /// - /// Gets or sets the entry used as transparent color in this . - /// Only works for 1-, 4- and 8-bpp. - /// - public int TransparentIndex - { - get - { - EnsureNotDisposed(); - return FreeImage.GetTransparentIndex(dib); - } - set - { - EnsureNotDisposed(); - FreeImage.SetTransparentIndex(dib, value); - } - } - - /// - /// Gets the number of frames in this . - /// - public int FrameCount - { - get - { - EnsureNotDisposed(); - return frameCount; - } - } - - /// - /// Gets the ICCProfile structure of this . - /// - public FIICCPROFILE ICCProfile - { - get - { - EnsureNotDisposed(); - return FreeImage.GetICCProfileEx(dib); - } - } - - /// - /// Gets the format of the original image in case - /// this was loaded from a file or stream. - /// - public FREE_IMAGE_FORMAT ImageFormat - { - get - { - EnsureNotDisposed(); - return originalFormat; - } - } - - /// - /// Gets the encapsulated FIBITMAP. - /// - internal FIBITMAP Dib - { - get { EnsureNotDisposed(); return dib; } - } - - #endregion - - #region Methods - - /// - /// Gets the bounds of this in the specified unit. - /// - /// One of the values indicating - /// the unit of measure for the bounding rectangle. - /// The that represents the bounds of this - /// , in the specified unit. - public RectangleF GetBounds(ref GraphicsUnit pageUnit) - { - EnsureNotDisposed(); - pageUnit = GraphicsUnit.Pixel; - return new RectangleF( - 0f, - 0f, - (float)FreeImage.GetWidth(dib), - (float)FreeImage.GetHeight(dib)); - } - - /// - /// Gets the specified property item from this . - /// - /// The ID of the property item to get. - /// The this method gets. - public PropertyItem GetPropertyItem(int propid) - { - EnsureNotDisposed(); - ImageMetadata metadata = new ImageMetadata(dib, true); - foreach (MetadataModel metadataModel in metadata) - { - foreach (MetadataTag tag in metadataModel) - { - if (tag.ID == propid) - { - return tag.GetPropertyItem(); - } - } - } - return null; - } - - /// - /// Returns a thumbnail for this . - /// - /// The width, in pixels, of the requested thumbnail image. - /// The height, in pixels, of the requested thumbnail image. - /// Ignored. - /// Ignored. - /// A that represents the thumbnail. - public FreeImageBitmap GetThumbnailImage(int thumbWidth, int thumbHeight, - Image.GetThumbnailImageAbort callback, IntPtr callBackData) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.Rescale( - dib, thumbWidth, thumbHeight, FREE_IMAGE_FILTER.FILTER_BICUBIC); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Returns a thumbnail for this , keeping aspect ratio. - /// defines the maximum width or height - /// of the thumbnail. - /// - /// Thumbnail square size. - /// When true HDR images are transperantly - /// converted to standard images. - /// The thumbnail in a new instance. - public FreeImageBitmap GetThumbnailImage(int maxPixelSize, bool convert) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.MakeThumbnail(dib, maxPixelSize, convert); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Converts this instance to a instance. - /// - /// A new instance of initialized this instance. - public Bitmap ToBitmap() - { - EnsureNotDisposed(); - return FreeImage.GetBitmap(dib, true); - } - - /// - /// Returns an instance of , representing the scanline - /// specified by of this . - /// Since FreeImage bitmaps are always bottum up aligned, keep in mind that scanline 0 is the - /// bottom-most line of the image. - /// - /// Number of the scanline to retrieve. - /// An instance of representing the - /// th scanline. - /// - /// List of return-types of T: - /// - /// Color Depth / TypeResult Type - /// 1 () - /// 4 () - /// 8 () - /// 16 () - /// 16 - 555 () - /// 16 - 565 () - /// 24 () - /// 32 () - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// FreeImageBitmap bitmap = new FreeImageBitmap(@"C:\Pictures\picture.bmp"); - /// if (bitmap.ColorDepth == 32) - /// { - /// Scanline<RGBQUAD> scanline = bitmap.GetScanline<RGBQUAD>(0); - /// foreach (RGBQUAD pixel in scanline) - /// { - /// Console.WriteLine(pixel); - /// } - /// } - /// - /// - /// - /// The bitmap's type or color depth are not supported. - /// - /// - /// is no valid value. - /// - public Scanline GetScanline(int scanline) where T : struct - { - EnsureNotDisposed(); - return new Scanline(dib, scanline); - } - - /// - /// Returns an instance of , representing the scanline - /// specified by of this . - /// Since FreeImage bitmaps are always bottum up aligned, keep in mind that scanline 0 is the - /// bottom-most line of the image. - /// - /// Number of the scanline to retrieve. - /// An instance of representing the - /// th scanline. - /// - /// List of return-types of T: - /// - /// Color Depth / TypeResult Type - /// 1 () - /// 4 () - /// 8 () - /// 16 () - /// 16 - 555 () - /// 16 - 565 () - /// 24 () - /// 32 () - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// FreeImageBitmap bitmap = new FreeImageBitmap(@"C:\Pictures\picture.bmp"); - /// if (bitmap.ColorDepth == 32) - /// { - /// Scanline<RGBQUAD> scanline = (Scanline<RGBQUAD>)bitmap.GetScanline(0); - /// foreach (RGBQUAD pixel in scanline) - /// { - /// Console.WriteLine(pixel); - /// } - /// } - /// - /// - /// - /// The type of the bitmap or color depth are not supported. - /// - /// - /// is no valid value. - /// - public object GetScanline(int scanline) - { - EnsureNotDisposed(); - object result = null; - int width = (int)FreeImage.GetWidth(dib); - - switch (FreeImage.GetImageType(dib)) - { - case FREE_IMAGE_TYPE.FIT_BITMAP: - - switch (FreeImage.GetBPP(dib)) - { - case 1u: result = new Scanline(dib, scanline, width); break; - case 4u: result = new Scanline(dib, scanline, width); break; - case 8u: result = new Scanline(dib, scanline, width); break; - case 16u: - if ((RedMask == FreeImage.FI16_555_RED_MASK) && - (GreenMask == FreeImage.FI16_555_GREEN_MASK) && - (BlueMask == FreeImage.FI16_555_BLUE_MASK)) - { - result = new Scanline(dib, scanline, width); - } - else if ((RedMask == FreeImage.FI16_565_RED_MASK) && - (GreenMask == FreeImage.FI16_565_GREEN_MASK) && - (BlueMask == FreeImage.FI16_565_BLUE_MASK)) - { - result = new Scanline(dib, scanline, width); - } - else - { - result = new Scanline(dib, scanline, width); - } - break; - case 24u: result = new Scanline(dib, scanline, width); break; - case 32u: result = new Scanline(dib, scanline, width); break; - default: throw new ArgumentException("Color depth is not supported."); - } - break; - - case FREE_IMAGE_TYPE.FIT_COMPLEX: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_DOUBLE: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_FLOAT: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_INT16: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_INT32: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_RGB16: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_RGBA16: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_RGBAF: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_RGBF: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_UINT16: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_UINT32: result = new Scanline(dib, scanline, width); break; - case FREE_IMAGE_TYPE.FIT_UNKNOWN: - default: throw new ArgumentException("Type is not supported."); - } - - return result; - } - - /// - /// Returns a pointer to the specified scanline. - /// Due to FreeImage bitmaps are bottum up, - /// scanline 0 is the most bottom line of the image. - /// - /// Number of the scanline. - /// Pointer to the scanline. - public IntPtr GetScanlinePointer(int scanline) - { - EnsureNotDisposed(); - return FreeImage.GetScanLine(dib, scanline); - } - - /// - /// Returns a list of structures, representing the scanlines of this . - /// Due to FreeImage bitmaps are bottum up, scanline 0 is the - /// bottom-most line of the image. - /// Each color depth has a different representing structure due to different memory layouts. - /// - /// - /// List of return-types of T: - /// - /// Color Depth / TypeResult Type of IEnmuerable<Scanline<T>> - /// 1 () - /// 4 () - /// 8 () - /// 16 () - /// 16 - 555 () - /// 16 - 565 () - /// 24 () - /// 32 () - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public IList GetScanlines() - { - EnsureNotDisposed(); - - int height = (int)FreeImage.GetHeight(dib); - IList list; - - switch (FreeImage.GetImageType(dib)) - { - case FREE_IMAGE_TYPE.FIT_BITMAP: - - switch (FreeImage.GetBPP(dib)) - { - case 1u: list = new List>(height); break; - case 4u: list = new List>(height); break; - case 8u: list = new List>(height); break; - case 16u: - if (FreeImage.IsRGB555(dib)) - { - list = new List>(height); - } - else if (FreeImage.IsRGB565(dib)) - { - list = new List>(height); - } - else - { - list = new List>(height); - } - break; - case 24u: list = new List>(height); break; - case 32u: list = new List>(height); break; - default: throw new ArgumentException("Color depth is not supported."); - } - break; - - case FREE_IMAGE_TYPE.FIT_COMPLEX: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_DOUBLE: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_FLOAT: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_INT16: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_INT32: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_RGB16: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_RGBA16: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_RGBAF: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_RGBF: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_UINT16: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_UINT32: list = new List>(height); break; - case FREE_IMAGE_TYPE.FIT_UNKNOWN: - default: throw new ArgumentException("Type is not supported."); - } - - for (int i = 0; i < height; i++) - { - list.Add(GetScanline(i)); - } - - return list; - } - - /// - /// Removes the specified property item from this . - /// - /// The ID of the property item to remove. - public void RemovePropertyItem(int propid) - { - EnsureNotDisposed(); - ImageMetadata mdata = new ImageMetadata(dib, true); - foreach (MetadataModel model in mdata) - { - foreach (MetadataTag tag in model) - { - if (tag.ID == propid) - { - model.RemoveTag(tag.Key); - return; - } - } - } - } - - /// - /// This method rotates, flips, or rotates and flips this . - /// - /// A RotateFlipType member - /// that specifies the type of rotation and flip to apply to this . - public void RotateFlip(RotateFlipType rotateFlipType) - { - EnsureNotDisposed(); - - FIBITMAP newDib = new FIBITMAP(); - uint bpp = FreeImage.GetBPP(dib); - - switch (rotateFlipType) - { - case RotateFlipType.RotateNoneFlipX: - - FreeImage.FlipHorizontal(dib); - break; - - case RotateFlipType.RotateNoneFlipY: - - FreeImage.FlipVertical(dib); - break; - - case RotateFlipType.RotateNoneFlipXY: - - FreeImage.FlipHorizontal(dib); - FreeImage.FlipVertical(dib); - break; - - case RotateFlipType.Rotate90FlipNone: - - newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); - break; - - case RotateFlipType.Rotate90FlipX: - - newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); - FreeImage.FlipHorizontal(newDib); - break; - - case RotateFlipType.Rotate90FlipY: - - newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); - FreeImage.FlipVertical(newDib); - break; - - case RotateFlipType.Rotate90FlipXY: - - newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); - FreeImage.FlipHorizontal(newDib); - FreeImage.FlipVertical(newDib); - break; - - case RotateFlipType.Rotate180FlipXY: - newDib = FreeImage.Clone(dib); - break; - } - ReplaceDib(newDib); - } - - /// - /// Copies the metadata from another . - /// - /// The bitmap to read the metadata from. - /// - /// is a null reference. - /// - public void CloneMetadataFrom(FreeImageBitmap bitmap) - { - if (bitmap == null) - { - throw new ArgumentNullException("bitmap"); - } - EnsureNotDisposed(); - bitmap.EnsureNotDisposed(); - FreeImage.CloneMetadata(dib, bitmap.dib); - } - - /// - /// Copies the metadata from another using - /// the provided options. - /// - /// The bitmap to read the metadata from. - /// Specifies the way the metadata is copied. - /// - /// is a null reference. - /// - public void CloneMetadataFrom(FreeImageBitmap bitmap, FREE_IMAGE_METADATA_COPY flags) - { - if (bitmap == null) - { - throw new ArgumentNullException("bitmap"); - } - EnsureNotDisposed(); - bitmap.EnsureNotDisposed(); - FreeImage.CloneMetadataEx(bitmap.dib, dib, flags); - } - - /// - /// Saves this to the specified file. - /// - /// A string that contains the name of the file to which - /// to save this . - /// is null or empty. - /// Saving the image failed. - public void Save(string filename) - { - Save(filename, FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - /// - /// Saves this to the specified file in the specified format. - /// - /// A string that contains the name of the file to which - /// to save this . - /// An that specifies the format of the saved image. - /// is null or empty. - /// Saving the image failed. - public void Save(string filename, FREE_IMAGE_FORMAT format) - { - Save(filename, format, FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - /// - /// Saves this to the specified file in the specified format - /// using the specified saving flags. - /// - /// A string that contains the name of the file to which - /// to save this . - /// An that specifies the format of the saved image. - /// Flags to enable or disable plugin-features. - /// is null or empty. - /// Saving the image failed. - public void Save(string filename, FREE_IMAGE_FORMAT format, FREE_IMAGE_SAVE_FLAGS flags) - { - EnsureNotDisposed(); - if (string.IsNullOrEmpty(filename)) - { - throw new ArgumentException("filename"); - } - if (!FreeImage.SaveEx(dib, filename, format, flags)) - { - throw new Exception("Unable to save bitmap"); - } - - saveInformation.filename = filename; - saveInformation.format = format; - saveInformation.saveFlags = flags; - } - - /// - /// Saves this to the specified stream in the specified format. - /// - /// The stream where this will be saved. - /// An that specifies the format of the saved image. - /// is a null reference. - /// Saving the image failed. - public void Save(Stream stream, FREE_IMAGE_FORMAT format) - { - Save(stream, format, FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - /// - /// Saves this to the specified stream in the specified format - /// using the specified saving flags. - /// - /// The stream where this will be saved. - /// An that specifies the format of the saved image. - /// Flags to enable or disable plugin-features. - /// is a null reference. - /// Saving the image failed. - public void Save(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_SAVE_FLAGS flags) - { - EnsureNotDisposed(); - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - if (!FreeImage.SaveToStream(dib, stream, format, flags)) - { - throw new Exception("Unable to save bitmap"); - } - - saveInformation.filename = null; - } - - /// - /// Adds a frame to the file specified in a previous call to the - /// method. - /// - /// - /// This instance has not been saved to a file using Save(...) before. - public void SaveAdd() - { - SaveAdd(this); - } - - /// - /// Adds a frame to the file specified in a previous call to the method. - /// - /// The position at which the frame should be inserted. - /// - /// This instance has not yet been saved to a file using the Save(...) method. - /// is out of range. - public void SaveAdd(int insertPosition) - { - SaveAdd(this, insertPosition); - } - - /// - /// Adds a frame to the file specified in a previous call to the method. - /// - /// A that contains the frame to add. - /// - /// This instance has not yet been saved to a file using the Save(...) method. - public void SaveAdd(FreeImageBitmap bitmap) - { - if (saveInformation.filename == null) - { - throw new InvalidOperationException("This operation requires a previous call of Save()."); - } - - SaveAdd( - saveInformation.filename, - bitmap, - saveInformation.format, - saveInformation.loadFlags, - saveInformation.saveFlags); - } - - /// - /// Adds a frame to the file specified in a previous call to the method. - /// - /// A that contains the frame to add. - /// The position at which the frame should be inserted. - /// - /// This instance has not yet been saved to a file using the Save(...) method. - /// is out of range. - public void SaveAdd(FreeImageBitmap bitmap, int insertPosition) - { - if (saveInformation.filename == null) - { - throw new InvalidOperationException("This operation requires a previous call of Save()."); - } - - SaveAdd( - saveInformation.filename, - bitmap, - insertPosition, - saveInformation.format, - saveInformation.loadFlags, - saveInformation.saveFlags); - } - - /// - /// Adds a frame to the file specified. - /// - /// File to add this frame to. - /// is a null reference. - /// does not exist. - /// Saving the image has failed. - public void SaveAdd(string filename) - { - SaveAdd( - filename, - this, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - FREE_IMAGE_LOAD_FLAGS.DEFAULT, - FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - /// - /// Adds a frame to the file specified. - /// - /// File to add this frame to. - /// The position at which the frame should be inserted. - /// is a null reference. - /// does not exist. - /// Saving the image has failed. - /// is out of range. - public void SaveAdd(string filename, int insertPosition) - { - SaveAdd( - filename, - this, - insertPosition, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - FREE_IMAGE_LOAD_FLAGS.DEFAULT, - FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - /// - /// Adds a frame to the file specified using the specified parameters. - /// - /// File to add this frame to. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// Flags to enable or disable plugin-features. - /// is a null reference. - /// does not exist. - /// Saving the image has failed. - public void SaveAdd( - string filename, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_LOAD_FLAGS loadFlags, - FREE_IMAGE_SAVE_FLAGS saveFlags) - { - SaveAdd( - filename, - this, - format, - loadFlags, - saveFlags); - } - - /// - /// Adds a frame to the file specified using the specified parameters. - /// - /// File to add this frame to. - /// The position at which the frame should be inserted. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// Flags to enable or disable plugin-features. - /// is a null reference. - /// does not exist. - /// Saving the image has failed. - /// is out of range. - public void SaveAdd( - string filename, - int insertPosition, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_LOAD_FLAGS loadFlags, - FREE_IMAGE_SAVE_FLAGS saveFlags) - { - SaveAdd( - filename, - this, - insertPosition, - format, - loadFlags, - saveFlags); - } - - /// - /// Selects the frame specified by the index. - /// - /// The index of the active frame. - /// - /// is out of range. - /// The operation failed. - /// The source of the bitmap is not available. - /// - public void SelectActiveFrame(int frameIndex) - { - EnsureNotDisposed(); - if ((frameIndex < 0) || (frameIndex >= frameCount)) - { - throw new ArgumentOutOfRangeException("frameIndex"); - } - - if (frameIndex != this.frameIndex) - { - if (stream == null) - { - throw new InvalidOperationException("No source available."); - } - - FREE_IMAGE_FORMAT format = originalFormat; - FIMULTIBITMAP mdib = FreeImage.OpenMultiBitmapFromStream(stream, ref format, saveInformation.loadFlags); - if (mdib.IsNull) - throw new Exception(ErrorLoadingBitmap); - - try - { - if (frameIndex >= FreeImage.GetPageCount(mdib)) - { - throw new ArgumentOutOfRangeException("frameIndex"); - } - - FIBITMAP newDib = FreeImage.LockPage(mdib, frameIndex); - if (newDib.IsNull) - { - throw new Exception(ErrorLoadingFrame); - } - - try - { - FIBITMAP clone = FreeImage.Clone(newDib); - if (clone.IsNull) - { - throw new Exception(ErrorCreatingBitmap); - } - ReplaceDib(clone); - } - finally - { - if (!newDib.IsNull) - { - FreeImage.UnlockPage(mdib, newDib, false); - } - } - } - finally - { - if (!FreeImage.CloseMultiBitmapEx(ref mdib)) - { - throw new Exception(ErrorUnloadBitmap); - } - } - - this.frameIndex = frameIndex; - } - } - - /// - /// Creates a GDI bitmap object from this . - /// - /// A handle to the GDI bitmap object that this method creates. - public IntPtr GetHbitmap() - { - EnsureNotDisposed(); - return FreeImage.GetHbitmap(dib, IntPtr.Zero, false); - } - - /// - /// Creates a GDI bitmap object from this . - /// - /// A structure that specifies the background color. - /// This parameter is ignored if the bitmap is totally opaque. - /// A handle to the GDI bitmap object that this method creates. - public IntPtr GetHbitmap(Color background) - { - EnsureNotDisposed(); - using (FreeImageBitmap temp = new FreeImageBitmap(this)) - { - temp.BackgroundColor = background; - return temp.GetHbitmap(); - } - } - - /// - /// Returns the handle to an icon. - /// - /// A Windows handle to an icon with the same image as this . - public IntPtr GetHicon() - { - EnsureNotDisposed(); - using (Bitmap bitmap = FreeImage.GetBitmap(dib, true)) - { - return bitmap.GetHicon(); - } - } - - /// - /// Creates a GDI bitmap object from this with the same - /// color depth as the primary device. - /// - /// A handle to the GDI bitmap object that this method creates. - public IntPtr GetHbitmapForDevice() - { - EnsureNotDisposed(); - return FreeImage.GetBitmapForDevice(dib, IntPtr.Zero, false); - } - - /// - /// Gets the of the specified pixel in this . - /// - /// The x-coordinate of the pixel to retrieve. - /// The y-coordinate of the pixel to retrieve. - /// A structure that represents the color of the specified pixel. - /// The operation failed. - /// The type of this bitmap is not supported. - public unsafe Color GetPixel(int x, int y) - { - EnsureNotDisposed(); - if (FreeImage.GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) - { - if (ColorDepth == 16 || ColorDepth == 24 || ColorDepth == 32) - { - RGBQUAD rgbq; - if (!FreeImage.GetPixelColor(dib, (uint)x, (uint)y, out rgbq)) - { - throw new Exception("FreeImage.GetPixelColor() failed"); - } - return rgbq.Color; - } - else if (ColorDepth == 1 || ColorDepth == 4 || ColorDepth == 8) - { - byte index; - if (!FreeImage.GetPixelIndex(dib, (uint)x, (uint)y, out index)) - { - throw new Exception("FreeImage.GetPixelIndex() failed"); - } - RGBQUAD* palette = (RGBQUAD*)FreeImage.GetPalette(dib); - return palette[index].Color; - } - } - throw new NotSupportedException("The type of the image is not supported"); - } - - /// - /// Makes the default transparent color transparent for this . - /// - public void MakeTransparent() - { - EnsureNotDisposed(); - MakeTransparent(Color.Transparent); - } - - /// - /// Makes the specified color transparent for this . - /// - /// The structure that represents - /// the color to make transparent. - /// - /// This method is not implemented. - public void MakeTransparent(Color transparentColor) - { - EnsureNotDisposed(); - throw new System.NotImplementedException(); - } - - /// - /// Sets the of the specified pixel in this . - /// - /// The x-coordinate of the pixel to set. - /// The y-coordinate of the pixel to set. - /// A structure that represents the color - /// to assign to the specified pixel. - /// The operation failed. - /// The type of this bitmap is not supported. - public unsafe void SetPixel(int x, int y, Color color) - { - EnsureNotDisposed(); - if (FreeImage.GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) - { - if (ColorDepth == 16 || ColorDepth == 24 || ColorDepth == 32) - { - RGBQUAD rgbq = color; - if (!FreeImage.SetPixelColor(dib, (uint)x, (uint)y, ref rgbq)) - { - throw new Exception("FreeImage.SetPixelColor() failed"); - } - return; - } - else if (ColorDepth == 1 || ColorDepth == 4 || ColorDepth == 8) - { - uint colorsUsed = FreeImage.GetColorsUsed(dib); - RGBQUAD* palette = (RGBQUAD*)FreeImage.GetPalette(dib); - for (int i = 0; i < colorsUsed; i++) - { - if (palette[i].Color == color) - { - byte index = (byte)i; - if (!FreeImage.SetPixelIndex(dib, (uint)x, (uint)y, ref index)) - { - throw new Exception("FreeImage.SetPixelIndex() failed"); - } - return; - } - } - throw new ArgumentOutOfRangeException("color"); - } - } - throw new NotSupportedException("The type of the image is not supported"); - } - - /// - /// Sets the resolution for this . - /// - /// The horizontal resolution, in dots per inch, of this . - /// The vertical resolution, in dots per inch, of this . - public void SetResolution(float xDpi, float yDpi) - { - EnsureNotDisposed(); - FreeImage.SetResolutionX(dib, (uint)xDpi); - FreeImage.SetResolutionY(dib, (uint)yDpi); - } - - /// - /// This function is not yet implemented. - /// - /// - /// This method is not implemented. - public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format) - { - throw new NotImplementedException(); - } - - /// - /// This function is not yet implemented. - /// - /// - /// This method is not implemented. - public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData) - { - throw new NotImplementedException(); - } - - /// - /// This function is not yet implemented. - /// - /// - /// This method is not implemented. - public void UnlockBits(BitmapData bitmapdata) - { - throw new NotImplementedException(); - } - - /// - /// Converts this into a different color depth. - /// The parameter specifies color depth, greyscale conversion - /// and palette reorder. - /// Adding the flag - /// will first perform a convesion to greyscale. This can be done with any target - /// color depth. - /// Adding the flag - /// will allow the algorithm to reorder the palette. This operation will not be performed to - /// non-greyscale images to prevent data loss by mistake. - /// - /// A bitfield containing information about the conversion - /// to perform. - /// Returns true on success, false on failure. - public bool ConvertColorDepth(FREE_IMAGE_COLOR_DEPTH bpp) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.ConvertColorDepth(dib, bpp, false)); - } - - /// - /// Converts this to - /// initializing a new instance. - /// In case source and destination type are the same, the operation fails. - /// An error message can be catched using the 'Message' event. - /// - /// Destination type. - /// True to scale linear, else false. - /// Returns true on success, false on failure. - public bool ConvertType(FREE_IMAGE_TYPE type, bool scaleLinear) - { - EnsureNotDisposed(); - return (ImageType == type) ? false : ReplaceDib(FreeImage.ConvertToType(dib, type, scaleLinear)); - } - - /// - /// Converts this to . - /// In case source and destination type are the same, the operation fails. - /// An error message can be catched using the 'Message' event. - /// - /// Destination type. - /// True to scale linear, else false. - /// The converted instance. - public FreeImageBitmap GetTypeConvertedInstance(FREE_IMAGE_TYPE type, bool scaleLinear) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - if (ImageType != type) - { - FIBITMAP newDib = FreeImage.ConvertToType(dib, type, scaleLinear); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - } - return result; - } - - /// - /// Converts this into a different color depth initializing - /// a new instance. - /// The parameter specifies color depth, greyscale conversion - /// and palette reorder. - /// Adding the flag will - /// first perform a convesion to greyscale. This can be done with any target color depth. - /// Adding the flag will - /// allow the algorithm to reorder the palette. This operation will not be performed to - /// non-greyscale images to prevent data loss by mistake. - /// - /// A bitfield containing information about the conversion - /// to perform. - /// The converted instance. - public FreeImageBitmap GetColorConvertedInstance(FREE_IMAGE_COLOR_DEPTH bpp) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.ConvertColorDepth(dib, bpp, false); - if (newDib == dib) - { - newDib = FreeImage.Clone(dib); - } - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Rescales this to the specified size using the - /// specified filter. - /// - /// The Size structure that represent the - /// size of the new . - /// Filter to use for resizing. - /// Returns true on success, false on failure. - public bool Rescale(Size newSize, FREE_IMAGE_FILTER filter) - { - return Rescale(newSize.Width, newSize.Height, filter); - } - - /// - /// Rescales this to the specified size using the - /// specified filter. - /// - /// Width of the new . - /// Height of the new . - /// Filter to use for resizing. - /// Returns true on success, false on failure. - public bool Rescale(int width, int height, FREE_IMAGE_FILTER filter) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.Rescale(dib, width, height, filter)); - } - - /// - /// Rescales this to the specified size using the - /// specified filter initializing a new instance. - /// - /// The Size structure that represent the - /// size of the new . - /// Filter to use for resizing. - /// The rescaled instance. - public FreeImageBitmap GetScaledInstance(Size newSize, FREE_IMAGE_FILTER filter) - { - return GetScaledInstance(newSize.Width, newSize.Height, filter); - } - - /// - /// Rescales this to the specified size using the - /// specified filter initializing a new instance. - /// - /// Width of the new . - /// Height of the new . - /// Filter to use for resizing. - /// The rescaled instance. - public FreeImageBitmap GetScaledInstance(int width, int height, FREE_IMAGE_FILTER filter) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.Rescale(dib, width, height, filter); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Enlarges or shrinks this selectively per side and fills - /// newly added areas with the specified background color. - /// See for further details. - /// - /// The type of the specified color. - /// The number of pixels, the image should be enlarged on its left side. - /// Negative values shrink the image on its left side. - /// The number of pixels, the image should be enlarged on its top side. - /// Negative values shrink the image on its top side. - /// The number of pixels, the image should be enlarged on its right side. - /// Negative values shrink the image on its right side. - /// The number of pixels, the image should be enlarged on its bottom side. - /// Negative values shrink the image on its bottom side. - /// The color, the enlarged sides of the image should be filled with. - /// true on success, false on failure. - public bool EnlargeCanvas(int left, int top, int right, int bottom, T? color) where T : struct - { - return EnlargeCanvas(left, top, right, bottom, color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT); - } - - /// - /// Enlarges or shrinks this selectively per side and fills - /// newly added areas with the specified background color. - /// See for further details. - /// - /// The type of the specified color. - /// The number of pixels, the image should be enlarged on its left side. - /// Negative values shrink the image on its left side. - /// The number of pixels, the image should be enlarged on its top side. - /// Negative values shrink the image on its top side. - /// The number of pixels, the image should be enlarged on its right side. - /// Negative values shrink the image on its right side. - /// The number of pixels, the image should be enlarged on its bottom side. - /// Negative values shrink the image on its bottom side. - /// The color, the enlarged sides of the image should be filled with. - /// Options that affect the color search process for palletized images. - /// true on success, false on failure. - public bool EnlargeCanvas(int left, int top, int right, int bottom, - T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.EnlargeCanvas(dib, left, top, right, bottom, color, options)); - } - - /// - /// Enlarges or shrinks this selectively per side and fills - /// newly added areas with the specified background color returning a new instance. - /// See for further details. - /// - /// The type of the specified color. - /// The number of pixels, the image should be enlarged on its left side. - /// Negative values shrink the image on its left side. - /// The number of pixels, the image should be enlarged on its top side. - /// Negative values shrink the image on its top side. - /// The number of pixels, the image should be enlarged on its right side. - /// Negative values shrink the image on its right side. - /// The number of pixels, the image should be enlarged on its bottom side. - /// Negative values shrink the image on its bottom side. - /// The color, the enlarged sides of the image should be filled with. - /// The enlarged instance. - public FreeImageBitmap GetEnlargedInstance(int left, int top, int right, int bottom, - T? color) where T : struct - { - return GetEnlargedInstance(left, top, right, bottom, color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT); - } - - /// - /// Enlarges or shrinks this selectively per side and fills - /// newly added areas with the specified background color returning a new instance. - /// See for further details. - /// - /// The type of the specified color. - /// The number of pixels, the image should be enlarged on its left side. - /// Negative values shrink the image on its left side. - /// The number of pixels, the image should be enlarged on its top side. - /// Negative values shrink the image on its top side. - /// The number of pixels, the image should be enlarged on its right side. - /// Negative values shrink the image on its right side. - /// The number of pixels, the image should be enlarged on its bottom side. - /// Negative values shrink the image on its bottom side. - /// The color, the enlarged sides of the image should be filled with. - /// Options that affect the color search process for palletized images. - /// The enlarged instance. - public FreeImageBitmap GetEnlargedInstance(int left, int top, int right, int bottom, - T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.EnlargeCanvas(dib, left, top, right, bottom, color, options); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Quantizes this from 24 bit to 8bit creating a new - /// palette with the specified using the specified - /// . - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// Returns true on success, false on failure. - public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize) - { - return Quantize(algorithm, paletteSize, 0, (RGBQUAD[])null); - } - - /// - /// Quantizes this from 24 bit to 8bit creating a new - /// palette with the specified using the specified - /// and the specified - /// palette up to the - /// specified length. - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// The provided palette. - /// Returns true on success, false on failure. - public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, Palette reservePalette) - { - return Quantize(algorithm, paletteSize, reservePalette.Length, reservePalette.Data); - } - - /// - /// Quantizes this from 24 bit to 8bit creating a new - /// palette with the specified using the specified - /// and the specified - /// palette up to the - /// specified length. - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// Size of the provided palette of ReservePalette. - /// The provided palette. - /// Returns true on success, false on failure. - public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, Palette reservePalette) - { - return Quantize(algorithm, paletteSize, reserveSize, reservePalette.Data); - } - - /// - /// Quantizes this from 24 bit to 8bit creating a new - /// palette with the specified using the specified - /// and the specified - /// palette up to the - /// specified length. - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// Size of the provided palette of ReservePalette. - /// The provided palette. - /// Returns true on success, false on failure. - public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, RGBQUAD[] reservePalette) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.ColorQuantizeEx(dib, algorithm, paletteSize, reserveSize, reservePalette)); - } - - /// - /// Quantizes this from 24 bit, using the specified - /// initializing a new 8 bit instance with the - /// specified . - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// The quantized instance. - public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize) - { - return GetQuantizedInstance(algorithm, paletteSize, 0, (RGBQUAD[])null); - } - - /// - /// Quantizes this from 24 bit, using the specified - /// and palette - /// initializing a new 8 bit instance with the specified . - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// The provided palette. - /// The quantized instance. - public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, Palette reservePalette) - { - return GetQuantizedInstance(algorithm, paletteSize, reservePalette.Length, reservePalette); - } - - /// - /// Quantizes this from 24 bit, using the specified - /// and up to - /// entries from palette initializing - /// a new 8 bit instance with the specified . - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// Size of the provided palette. - /// The provided palette. - /// The quantized instance. - public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, Palette reservePalette) - { - return GetQuantizedInstance(algorithm, paletteSize, reserveSize, reservePalette.Data); - } - - /// - /// Quantizes this from 24 bit, using the specified - /// and up to - /// entries from palette initializing - /// a new 8 bit instance with the specified . - /// - /// The color reduction algorithm to be used. - /// Size of the desired output palette. - /// Size of the provided palette. - /// The provided palette. - /// The quantized instance. - public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, RGBQUAD[] reservePalette) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.ColorQuantizeEx(dib, algorithm, paletteSize, reserveSize, reservePalette); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Converts a High Dynamic Range image to a 24-bit RGB image using a global - /// operator based on logarithmic compression of luminance values, imitating - /// the human response to light. - /// - /// A gamma correction that is applied after the tone mapping. - /// A value of 1 means no correction. - /// Scale factor allowing to adjust the brightness of the output image. - /// Returns true on success, false on failure. - public bool TmoDrago03(double gamma, double exposure) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.TmoDrago03(dib, gamma, exposure)); - } - - /// - /// Converts a High Dynamic Range image to a 24-bit RGB image using a global operator inspired - /// by photoreceptor physiology of the human visual system. - /// - /// Controls the overall image intensity in the range [-8, 8]. - /// Controls the overall image contrast in the range [0.3, 1.0[. - /// Returns true on success, false on failure. - public bool TmoReinhard05(double intensity, double contrast) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.TmoReinhard05(dib, intensity, contrast)); - } - - /// - /// Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and convert to 24-bit RGB. - /// - /// Color saturation (s parameter in the paper) in [0.4..0.6] - /// Atenuation factor (beta parameter in the paper) in [0.8..0.9] - /// Returns true on success, false on failure. - public bool TmoFattal02(double color_saturation, double attenuation) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.TmoFattal02(dib, color_saturation, attenuation)); - } - - /// - /// This method rotates a 1-, 4-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. - /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer - /// multiple of 90. - /// - /// The angle of rotation. - /// Returns true on success, false on failure. - public bool Rotate(double angle) - { - EnsureNotDisposed(); - bool result = false; - if (ColorDepth == 4) - { - result = ReplaceDib(FreeImage.Rotate4bit(dib, angle)); - } - else - { - result = ReplaceDib(FreeImage.Rotate(dib, angle)); - } - return result; - } - - /// - /// This method rotates a 1-, 4-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. - /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer - /// multiple of 90. - /// - /// The type of the color to use as background. - /// The angle of rotation. - /// The color used used to fill the bitmap's background. - /// Returns true on success, false on failure. - public bool Rotate(double angle, T? backgroundColor) where T : struct - { - EnsureNotDisposed(); - bool result = false; - if (ColorDepth == 4) - { - result = ReplaceDib(FreeImage.Rotate4bit(dib, angle)); - } - else - { - result = ReplaceDib(FreeImage.Rotate(dib, angle, backgroundColor)); - } - return result; - } - - /// - /// Rotates this by the specified angle initializing a new instance. - /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer - /// multiple of 90. - /// - /// The type of the color to use as background. - /// The angle of rotation. - /// The color used used to fill the bitmap's background. - /// The rotated instance. - public FreeImageBitmap GetRotatedInstance(double angle, T? backgroundColor) where T : struct - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib; - if (ColorDepth == 4) - { - newDib = FreeImage.Rotate4bit(dib, angle); - } - else - { - newDib = FreeImage.Rotate(dib, angle, backgroundColor); - } - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Rotates this by the specified angle initializing a new instance. - /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer - /// multiple of 90. - /// - /// The angle of rotation. - /// The rotated instance. - public FreeImageBitmap GetRotatedInstance(double angle) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib; - if (ColorDepth == 4) - { - newDib = FreeImage.Rotate4bit(dib, angle); - } - else - { - newDib = FreeImage.Rotate(dib, angle); - } - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// This method performs a rotation and / or translation of an 8-bit greyscale, - /// 24- or 32-bit image, using a 3rd order (cubic) B-Spline. - /// - /// The angle of rotation. - /// Horizontal image translation. - /// Vertical image translation. - /// Rotation center x-coordinate. - /// Rotation center y-coordinate. - /// When true the irrelevant part of the image is set to a black color, - /// otherwise, a mirroring technique is used to fill irrelevant pixels. - /// Returns true on success, false on failure. - public bool Rotate(double angle, double xShift, double yShift, - double xOrigin, double yOrigin, bool useMask) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.RotateEx(dib, angle, xShift, yShift, xOrigin, yOrigin, useMask)); - } - - /// - /// This method performs a rotation and / or translation of an 8-bit greyscale, - /// 24- or 32-bit image, using a 3rd order (cubic) B-Spline initializing a new instance. - /// - /// The angle of rotation. - /// Horizontal image translation. - /// Vertical image translation. - /// Rotation center x-coordinate. - /// Rotation center y-coordinate. - /// When true the irrelevant part of the image is set to a black color, - /// otherwise, a mirroring technique is used to fill irrelevant pixels. - /// The rotated instance. - public FreeImageBitmap GetRotatedInstance(double angle, double xShift, double yShift, - double xOrigin, double yOrigin, bool useMask) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.RotateEx( - dib, angle, xShift, yShift, xOrigin, yOrigin, useMask); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Perfoms an histogram transformation on a 8-, 24- or 32-bit image. - /// - /// The lookup table (LUT). - /// It's size is assumed to be 256 in length. - /// The color channel to be transformed. - /// Returns true on success, false on failure. - public bool AdjustCurve(byte[] lookUpTable, FREE_IMAGE_COLOR_CHANNEL channel) - { - EnsureNotDisposed(); - return FreeImage.AdjustCurve(dib, lookUpTable, channel); - } - - /// - /// Performs gamma correction on a 8-, 24- or 32-bit image. - /// - /// The parameter represents the gamma value to use (gamma > 0). - /// A value of 1.0 leaves the image alone, less than one darkens it, and greater than one lightens it. - /// Returns true on success, false on failure. - public bool AdjustGamma(double gamma) - { - EnsureNotDisposed(); - return FreeImage.AdjustGamma(dib, gamma); - } - - /// - /// Adjusts the brightness of a 8-, 24- or 32-bit image by a certain amount. - /// - /// A value 0 means no change, - /// less than 0 will make the image darker and greater than 0 will make the image brighter. - /// Returns true on success, false on failure. - public bool AdjustBrightness(double percentage) - { - EnsureNotDisposed(); - return FreeImage.AdjustBrightness(dib, percentage); - } - - /// - /// Adjusts the contrast of a 8-, 24- or 32-bit image by a certain amount. - /// - /// A value 0 means no change, - /// less than 0 will decrease the contrast and greater than 0 will increase the contrast of the image. - /// Returns true on success, false on failure. - public bool AdjustContrast(double percentage) - { - EnsureNotDisposed(); - return FreeImage.AdjustContrast(dib, percentage); - } - - /// - /// Inverts each pixel data. - /// - /// Returns true on success, false on failure. - public bool Invert() - { - EnsureNotDisposed(); - return FreeImage.Invert(dib); - } - - /// - /// Computes the image histogram. - /// - /// Channel to compute from. - /// Array of integers containing the histogram. - /// Returns true on success, false on failure. - public bool GetHistogram(FREE_IMAGE_COLOR_CHANNEL channel, out int[] histogram) - { - EnsureNotDisposed(); - histogram = new int[256]; - return FreeImage.GetHistogram(dib, histogram, channel); - } - - /// - /// Retrieves the red, green, blue or alpha channel of a 24- or 32-bit image. - /// - /// The color channel to extract. - /// The color channel in a new instance. - public FreeImageBitmap GetChannel(FREE_IMAGE_COLOR_CHANNEL channel) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.GetChannel(dib, channel); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Insert a 8-bit dib into a 24- or 32-bit image. - /// Both images must have to same width and height. - /// - /// The to insert. - /// The color channel to replace. - /// Returns true on success, false on failure. - public bool SetChannel(FreeImageBitmap bitmap, FREE_IMAGE_COLOR_CHANNEL channel) - { - EnsureNotDisposed(); - bitmap.EnsureNotDisposed(); - return FreeImage.SetChannel(dib, bitmap.dib, channel); - } - - /// - /// Retrieves the real part, imaginary part, magnitude or phase of a complex image. - /// - /// The color channel to extract. - /// The color channel in a new instance. - public FreeImageBitmap GetComplexChannel(FREE_IMAGE_COLOR_CHANNEL channel) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.GetComplexChannel(dib, channel); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Set the real or imaginary part of a complex image. - /// Both images must have to same width and height. - /// - /// The to insert. - /// The color channel to replace. - /// Returns true on success, false on failure. - public bool SetComplexChannel(FreeImageBitmap bitmap, FREE_IMAGE_COLOR_CHANNEL channel) - { - EnsureNotDisposed(); - bitmap.EnsureNotDisposed(); - return FreeImage.SetComplexChannel(dib, bitmap.dib, channel); - } - - /// - /// Copy a sub part of this . - /// - /// The subpart to copy. - /// The sub part in a new instance. - public FreeImageBitmap Copy(Rectangle rect) - { - EnsureNotDisposed(); - return Copy(rect.Left, rect.Top, rect.Right, rect.Bottom); - } - - /// - /// Copy a sub part of this . - /// - /// Specifies the left position of the cropped rectangle. - /// Specifies the top position of the cropped rectangle. - /// Specifies the right position of the cropped rectangle. - /// Specifies the bottom position of the cropped rectangle. - /// The sub part in a new instance. - public FreeImageBitmap Copy(int left, int top, int right, int bottom) - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.Copy(dib, left, top, right, bottom); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Alpha blend or combine a sub part image with this . - /// The bit depth of must be greater than or equal to the bit depth this instance. - /// - /// The to paste into this instance. - /// Specifies the left position of the sub image. - /// Specifies the top position of the sub image. - /// alpha blend factor. - /// The source and destination images are alpha blended if alpha=0..255. - /// If alpha > 255, then the source image is combined to the destination image. - /// Returns true on success, false on failure. - public bool Paste(FreeImageBitmap bitmap, int left, int top, int alpha) - { - EnsureNotDisposed(); - bitmap.EnsureNotDisposed(); - return FreeImage.Paste(dib, bitmap.dib, left, top, alpha); - } - - /// - /// Alpha blend or combine a sub part image with tthis . - /// The bit depth of must be greater than or equal to the bit depth this instance. - /// - /// The to paste into this instance. - /// Specifies the position of the sub image. - /// alpha blend factor. - /// The source and destination images are alpha blended if alpha=0..255. - /// If alpha > 255, then the source image is combined to the destination image. - /// Returns true on success, false on failure. - public bool Paste(FreeImageBitmap bitmap, Point point, int alpha) - { - EnsureNotDisposed(); - return Paste(bitmap, point.X, point.Y, alpha); - } - - /// - /// This method composite a transparent foreground image against a single background color or - /// against a background image. - /// In case is false and - /// and - /// are null, a checkerboard will be used as background. - /// - /// When true the background of this instance is used - /// if it contains one. - /// Backgroundcolor used in case is false - /// and is not null. - /// Background used in case - /// is false and is a null reference. - /// Returns true on success, false on failure. - public bool Composite(bool useBitmapBackground, Color? applicationBackground, FreeImageBitmap bitmapBackGround) - { - EnsureNotDisposed(); - bitmapBackGround.EnsureNotDisposed(); - RGBQUAD? rgb = applicationBackground; - return ReplaceDib( - FreeImage.Composite( - dib, - useBitmapBackground, - rgb.HasValue ? new RGBQUAD[] { rgb.Value } : null, - bitmapBackGround.dib)); - } - - /// - /// Applies the alpha value of each pixel to its color components. - /// The aplha value stays unchanged. - /// Only works with 32-bits color depth. - /// - /// Returns true on success, false on failure. - public bool PreMultiplyWithAlpha() - { - EnsureNotDisposed(); - return FreeImage.PreMultiplyWithAlpha(dib); - } - - /// - /// Solves a Poisson equation, remap result pixels to [0..1] and returns the solution. - /// - /// Number of cycles in the multigrid algorithm (usually 2 or 3) - /// Returns true on success, false on failure. - public bool MultigridPoissonSolver(int ncycle) - { - EnsureNotDisposed(); - return ReplaceDib(FreeImage.MultigridPoissonSolver(dib, ncycle)); - } - - /// - /// Adjusts an image's brightness, contrast and gamma as well as it may - /// optionally invert the image within a single operation. - /// - /// Percentage brightness value where -100 <= brightness <= 100. - /// A value of 0 means no change, less than 0 will make the image darker and greater - /// than 0 will make the image brighter. - /// Percentage contrast value where -100 <= contrast <= 100. - /// A value of 0 means no change, less than 0 will decrease the contrast - /// and greater than 0 will increase the contrast of the image. - /// Gamma value to be used for gamma correction. - /// A value of 1.0 leaves the image alone, less than one darkens it, - /// and greater than one lightens it. - /// This parameter must not be zero or smaller than zero. - /// If so, it will be ignored and no gamma correction will be performed on the image. - /// If set to true, the image will be inverted. - /// Returns true on success, false on failure. - public bool AdjustColors(double brightness, double contrast, double gamma, bool invert) - { - EnsureNotDisposed(); - return FreeImage.AdjustColors(dib, brightness, contrast, gamma, invert); - } - - /// - /// Applies color mapping for one or several colors on a 1-, 4- or 8-bit - /// palletized or a 16-, 24- or 32-bit high color image. - /// - /// Array of colors to be used as the mapping source. - /// Array of colors to be used as the mapping destination. - /// If true, 32-bit images and colors are treated as 24-bit. - /// If true, source and destination colors are swapped, that is, - /// each destination color is also mapped to the corresponding source color. - /// The total number of pixels changed. - /// - /// or is a null reference. - /// - /// - /// has a different length than . - /// - public uint ApplyColorMapping(RGBQUAD[] srccolors, RGBQUAD[] dstcolors, bool ignore_alpha, bool swap) - { - EnsureNotDisposed(); - if (srccolors == null) - { - throw new ArgumentNullException("srccolors"); - } - if (dstcolors == null) - { - throw new ArgumentNullException("dstcolors"); - } - if (srccolors.Length != dstcolors.Length) - { - throw new ArgumentException("srccolors and dstcolors must have the same length."); - } - return FreeImage.ApplyColorMapping(dib, srccolors, dstcolors, (uint)srccolors.Length, ignore_alpha, swap); - } - - /// - /// Swaps two specified colors on a 1-, 4- or 8-bit palletized - /// or a 16-, 24- or 32-bit high color image. - /// - /// One of the two colors to be swapped. - /// The other of the two colors to be swapped. - /// If true, 32-bit images and colors are treated as 24-bit. - /// The total number of pixels changed. - public uint SwapColors(RGBQUAD color_a, RGBQUAD color_b, bool ignore_alpha) - { - EnsureNotDisposed(); - return FreeImage.SwapColors(dib, ref color_a, ref color_b, ignore_alpha); - } - - /// - /// Applies palette index mapping for one or several indices - /// on a 1-, 4- or 8-bit palletized image. - /// - /// Array of palette indices to be used as the mapping source. - /// Array of palette indices to be used as the mapping destination. - /// The number of palette indices to be mapped. This is the size of both - /// srcindices and dstindices - /// If true, source and destination palette indices are swapped, that is, - /// each destination index is also mapped to the corresponding source index. - /// The total number of pixels changed. - /// - /// or is a null reference. - /// - /// - /// has a different length than . - /// - public uint ApplyPaletteIndexMapping(byte[] srcindices, byte[] dstindices, uint count, bool swap) - { - EnsureNotDisposed(); - if (srcindices == null) - { - throw new ArgumentNullException("srcindices"); - } - if (dstindices == null) - { - throw new ArgumentNullException("dstindices"); - } - if (srcindices.Length != dstindices.Length) - { - throw new ArgumentException("srcindices and dstindices must have the same length."); - } - return FreeImage.ApplyPaletteIndexMapping(dib, srcindices, dstindices, (uint)srcindices.Length, swap); - } - - /// - /// Swaps two specified palette indices on a 1-, 4- or 8-bit palletized image. - /// - /// One of the two palette indices to be swapped. - /// The other of the two palette indices to be swapped. - /// The total number of pixels changed. - public uint SwapPaletteIndices(byte index_a, byte index_b) - { - EnsureNotDisposed(); - return FreeImage.SwapPaletteIndices(dib, ref index_a, ref index_b); - } - - /// - /// Sets all pixels of this to the specified color. - /// See for further details. - /// - /// The type of the specified color. - /// The color to fill this with. - /// true on success, false on failure. - public bool FillBackground(T color) where T : struct - { - return FillBackground(color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT); - } - - /// - /// Sets all pixels of this to the specified color. - /// See for further details. - /// - /// The type of the specified color. - /// The color to fill this with. - /// Options that affect the color search process for palletized images. - /// true on success, false on failure. - public bool FillBackground(T color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct - { - EnsureNotDisposed(); - return FreeImage.FillBackground(dib, color, options); - } - - /// - /// Creates a new ICC-Profile. - /// - /// The data of the new ICC-Profile. - /// The new ICC-Profile of the bitmap. - /// is a null reference. - public FIICCPROFILE CreateICCProfile(byte[] data) - { - if (data == null) - { - throw new ArgumentNullException("data"); - } - return CreateICCProfile(data, data.Length); - } - - /// - /// Creates a new ICC-Profile. - /// - /// The data of the new ICC-Profile. - /// The number of bytes of to use. - /// The new ICC-Profile of the bitmap. - /// is null. - public FIICCPROFILE CreateICCProfile(byte[] data, int size) - { - EnsureNotDisposed(); - if (data == null) - { - throw new ArgumentNullException("data"); - } - return FreeImage.CreateICCProfileEx(dib, data, size); - } - - /// - /// Determines whether this and the specified instances are the same. - /// - /// The object to test. - /// true if this instance is the same - /// or if both are null references; otherwise, false. - public override bool Equals(object obj) - { - return ReferenceEquals(this, obj); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return dib.GetHashCode(); - } - - #endregion - - #region Static functions - - /// - /// Returns a value that indicates whether the pixel format for this contains alpha information. - /// - /// The to test. - /// true if pixfmt contains alpha information; otherwise, false. - public static bool IsAlphaPixelFormat(PixelFormat pixfmt) - { - return Bitmap.IsAlphaPixelFormat(pixfmt); - } - - /// - /// Returns a value that indicates whether the pixel format is 32 bits per pixel. - /// - /// The to test. - /// true if pixfmt is canonical; otherwise, false. - public static bool IsCanonicalPixelFormat(PixelFormat pixfmt) - { - return Bitmap.IsCanonicalPixelFormat(pixfmt); - } - - /// - /// Returns a value that indicates whether the pixel format is 64 bits per pixel. - /// - /// The enumeration to test. - /// true if pixfmt is extended; otherwise, false. - public static bool IsExtendedPixelFormat(PixelFormat pixfmt) - { - return Bitmap.IsExtendedPixelFormat(pixfmt); - } - - /// - /// Creates a from a Windows handle to an icon. - /// - /// A handle to an icon. - /// The that this method creates. - public static FreeImageBitmap FromHicon(IntPtr hicon) - { - using (Bitmap bitmap = Bitmap.FromHicon(hicon)) - { - return new FreeImageBitmap(bitmap); - } - } - - /// - /// Creates a from the specified Windows resource. - /// - /// A handle to an instance of the executable - /// file that contains the resource. - /// A string containing the name of the resource bitmap. - /// The that this method creates. - public static FreeImageBitmap FromResource(IntPtr hinstance, string bitmapName) - { - using (Bitmap bitmap = Bitmap.FromResource(hinstance, bitmapName)) - { - return new FreeImageBitmap(bitmap); - } - } - - /// - /// Creates a from the specified file. - /// - /// A string that contains the name of the file - /// from which to create the . - /// The this method creates. - public static FreeImageBitmap FromFile(string filename) - { - return new FreeImageBitmap(filename); - } - - /// - /// Creates a from the specified file - /// using embedded color management information in that file. - /// - /// A string that contains the - /// name of the file from which to create the . - /// Ignored. - /// The this method creates. - public static FreeImageBitmap FromFile(string filename, bool useEmbeddedColorManagement) - { - return new FreeImageBitmap(filename); - } - - /// - /// Creates a from a handle to a GDI bitmap. - /// - /// The GDI bitmap handle from which to create the . - /// The this method creates. - public static FreeImageBitmap FromHbitmap(IntPtr hbitmap) - { - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.CreateFromHbitmap(hbitmap, IntPtr.Zero); - if (!newDib.IsNull) - { - result = new FreeImageBitmap(newDib); - } - return result; - } - - /// - /// Creates a from a handle to a GDI bitmap and a handle to a GDI palette. - /// - /// The GDI bitmap handle from which to create the . - /// Ignored. - /// The this method creates. - public static FreeImageBitmap FromHbitmap(IntPtr hbitmap, IntPtr hpalette) - { - return FromHbitmap(hbitmap); - } - - /// - /// Frees a bitmap handle. - /// - /// Handle to a bitmap. - /// true on success, false on failure. - public static bool FreeHbitmap(IntPtr hbitmap) - { - return FreeImage.FreeHbitmap(hbitmap); - } - - /// - /// Creates a from the specified data stream. - /// - /// A that contains the data for this . - /// The this method creates. - public static FreeImageBitmap FromStream(Stream stream) - { - return new FreeImageBitmap(stream); - } - - /// - /// Creates a from the specified data stream. - /// - /// A that contains the data for this . - /// Ignored. - /// The this method creates. - public static FreeImageBitmap FromStream(Stream stream, bool useEmbeddedColorManagement) - { - return new FreeImageBitmap(stream); - } - - /// - /// Creates a from the specified data stream. - /// - /// A that contains the data for this . - /// Ignored. - /// Ignored. - /// The this method creates. - public static FreeImageBitmap FromStream(Stream stream, bool useEmbeddedColorManagement, bool validateImageData) - { - return new FreeImageBitmap(stream); - } - - /// - /// Returns the color depth, in number of bits per pixel, - /// of the specified pixel format. - /// - /// The member that specifies - /// the format for which to find the size. - /// The color depth of the specified pixel format. - public static int GetPixelFormatSize(PixelFormat pixfmt) - { - return Bitmap.GetPixelFormatSize(pixfmt); - } - - /// - /// Performs a lossless rotation or flipping on a JPEG file. - /// - /// Source file. - /// Destination file; can be the source file; will be overwritten. - /// The operation to apply. - /// To avoid lossy transformation, you can set the perfect parameter to true. - /// Returns true on success, false on failure. - public static bool JPEGTransform(string source, string destination, FREE_IMAGE_JPEG_OPERATION operation, bool perfect) - { - return FreeImage.JPEGTransform(source, destination, operation, perfect); - } - - /// - /// Performs a lossless crop on a JPEG file. - /// - /// Source filename. - /// Destination filename. - /// Specifies the cropped rectangle. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// - /// does not exist. - /// - public static bool JPEGCrop(string source, string destination, Rectangle rect) - { - if (source == null) - { - throw new ArgumentNullException("source"); - } - if (!File.Exists(source)) - { - throw new FileNotFoundException("source"); - } - if (destination == null) - { - throw new ArgumentNullException("destination"); - } - return JPEGCrop(source, destination, rect.Left, rect.Top, rect.Right, rect.Bottom); - } - - /// - /// Performs a lossless crop on a JPEG file. - /// - /// Source filename. - /// Destination filename. - /// Specifies the left position of the cropped rectangle. - /// Specifies the top position of the cropped rectangle. - /// Specifies the right position of the cropped rectangle. - /// Specifies the bottom position of the cropped rectangle. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// - /// does not exist. - /// - public static bool JPEGCrop(string source, string destination, int left, int top, int right, int bottom) - { - if (source == null) - { - throw new ArgumentNullException("source"); - } - if (!File.Exists(source)) - { - throw new FileNotFoundException("source"); - } - if (destination == null) - { - throw new ArgumentNullException("destination"); - } - return FreeImage.JPEGCrop(source, destination, left, top, right, bottom); - } - - /// - /// Converts a X11 color name into a corresponding RGB value. - /// - /// Name of the color to convert. - /// Red component. - /// Green component. - /// Blue component. - /// Returns true on success, false on failure. - /// is null. - public static bool LookupX11Color(string color, out byte red, out byte green, out byte blue) - { - if (color == null) - { - throw new ArgumentNullException("color"); - } - return FreeImage.LookupX11Color(color, out red, out green, out blue); - } - - /// - /// Converts a SVG color name into a corresponding RGB value. - /// - /// Name of the color to convert. - /// Red component. - /// Green component. - /// Blue component. - /// Returns true on success, false on failure. - /// is null. - public static bool LookupSVGColor(string color, out byte red, out byte green, out byte blue) - { - if (color == null) - { - throw new ArgumentNullException("color"); - } - return FreeImage.LookupSVGColor(color, out red, out green, out blue); - } - - /// - /// Creates a lookup table to be used with AdjustCurve() which - /// may adjusts brightness and contrast, correct gamma and invert the image with a - /// single call to AdjustCurve(). - /// - /// Output lookup table to be used with AdjustCurve(). - /// The size of is assumed to be 256. - /// Percentage brightness value where -100 <= brightness <= 100. - /// A value of 0 means no change, less than 0 will make the image darker and greater - /// than 0 will make the image brighter. - /// Percentage contrast value where -100 <= contrast <= 100. - /// A value of 0 means no change, less than 0 will decrease the contrast - /// and greater than 0 will increase the contrast of the image. - /// Gamma value to be used for gamma correction. - /// A value of 1.0 leaves the image alone, less than one darkens it, - /// and greater than one lightens it. - /// If set to true, the image will be inverted. - /// The number of adjustments applied to the resulting lookup table - /// compared to a blind lookup table. - /// is null. - /// is not 256. - public static int GetAdjustColorsLookupTable(byte[] lookUpTable, double brightness, double contrast, double gamma, bool invert) - { - if (lookUpTable == null) - { - throw new ArgumentNullException("lookUpTable"); - } - if (lookUpTable.Length != 256) - { - throw new ArgumentException("lookUpTable"); - } - return FreeImage.GetAdjustColorsLookupTable(lookUpTable, brightness, contrast, gamma, invert); - } - - /// - /// Adds a specified frame to the file specified using the specified parameters. - /// Use this method to save selected frames from an to a multiple-frame image. - /// - /// File to add this frame to. - /// A that contains the frame to add. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// Flags to enable or disable plugin-features. - /// - /// or is null. - /// - /// does not exist. - /// Saving the image failed. - public static void SaveAdd( - string filename, - FreeImageBitmap bitmap, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_LOAD_FLAGS loadFlags, - FREE_IMAGE_SAVE_FLAGS saveFlags) - { - if (filename == null) - { - throw new ArgumentNullException("filename"); - } - if (!File.Exists(filename)) - { - throw new FileNotFoundException("filename"); - } - if (bitmap == null) - { - throw new ArgumentNullException("bitmap"); - } - bitmap.EnsureNotDisposed(); - - FIBITMAP dib = bitmap.dib; - if (dib.IsNull) - throw new ArgumentNullException("bitmap"); - - FIMULTIBITMAP mpBitmap = - FreeImage.OpenMultiBitmapEx(filename, ref format, loadFlags, false, false, true); - - if (mpBitmap.IsNull) - throw new Exception(ErrorLoadingBitmap); - - FreeImage.AppendPage(mpBitmap, bitmap.dib); - - if (!FreeImage.CloseMultiBitmap(mpBitmap, saveFlags)) - throw new Exception(ErrorUnloadBitmap); - } - - /// - /// Adds a specified frame to the file specified using the specified parameters. - /// Use this method to save selected frames from an image to a multiple-frame image. - /// - /// File to add this frame to. - /// A that contains the frame to add. - /// The position of the inserted frame. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// Flags to enable or disable plugin-features. - /// - /// or is null. - /// - /// does not exist. - /// Saving the image failed. - /// is out of range. - public static void SaveAdd( - string filename, - FreeImageBitmap bitmap, - int insertPosition, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_LOAD_FLAGS loadFlags, - FREE_IMAGE_SAVE_FLAGS saveFlags) - { - if (filename == null) - { - throw new ArgumentNullException("filename"); - } - if (!File.Exists(filename)) - { - throw new FileNotFoundException("filename"); - } - if (bitmap == null) - { - throw new ArgumentNullException("bitmap"); - } - if (insertPosition < 0) - { - throw new ArgumentOutOfRangeException("insertPosition"); - } - bitmap.EnsureNotDisposed(); - - FIBITMAP dib = bitmap.dib; - if (dib.IsNull) - throw new ArgumentNullException("bitmap"); - - FIMULTIBITMAP mpBitmap = - FreeImage.OpenMultiBitmapEx(filename, ref format, loadFlags, false, false, true); - - if (mpBitmap.IsNull) - throw new Exception(ErrorLoadingBitmap); - - int pageCount = FreeImage.GetPageCount(mpBitmap); - - if (insertPosition > pageCount) - throw new ArgumentOutOfRangeException("insertPosition"); - - if (insertPosition == pageCount) - FreeImage.AppendPage(mpBitmap, bitmap.dib); - else - FreeImage.InsertPage(mpBitmap, insertPosition, bitmap.dib); - - if (!FreeImage.CloseMultiBitmap(mpBitmap, saveFlags)) - throw new Exception(ErrorUnloadBitmap); - } - - /// - /// Returns a new instance of the class which - /// has no public accessible constructor. - /// - /// A new instace of . - public static PropertyItem CreateNewPropertyItem() - { - return FreeImage.CreatePropertyItem(); - } - - #endregion - - #region Helper functions - - /// - /// Throws an exception in case the instance has already been disposed. - /// - private void EnsureNotDisposed() - { - lock (lockObject) - { - if (!this.disposed) - { - return; - } - } - throw new ObjectDisposedException(ToString()); - } - - /// - /// Tries to replace the wrapped with a new one. - /// In case the new dib is null or the same as the already - /// wrapped one, nothing will be changed and the result will - /// be false. - /// Otherwise the wrapped will be unloaded and replaced. - /// - /// The new dib. - /// Returns true on success, false on failure. - private bool ReplaceDib(FIBITMAP newDib) - { - bool result = false; - if ((dib != newDib) && (!newDib.IsNull)) - { - UnloadDib(); - dib = newDib; - AddMemoryPressure(); - result = true; - } - return result; - } - - /// - /// Unloads currently wrapped or unlocks the locked page - /// in case it came from a multipaged bitmap. - /// - private void UnloadDib() - { - if (!dib.IsNull) - { - long size = FreeImage.GetDIBSize(dib); - FreeImage.UnloadEx(ref dib); - if (size > 0L) - GC.RemoveMemoryPressure(size); - } - } - - /// - /// Informs the runtime about unmanaged allocoted memory. - /// - private void AddMemoryPressure() - { - long dataSize; - if ((dataSize = DataSize) > 0L) - GC.AddMemoryPressure(dataSize); - } - - /// - /// Opens the stream and reads the number of available pages. - /// Then loads the first page to this instance. - /// - private void LoadFromStream(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) - { - FIMULTIBITMAP mdib = FreeImage.OpenMultiBitmapFromStream(stream, ref format, flags); - if (mdib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - try - { - frameCount = FreeImage.GetPageCount(mdib); - } - finally - { - if (!FreeImage.CloseMultiBitmapEx(ref mdib)) - { - throw new Exception(ErrorUnloadBitmap); - } - } - - dib = FreeImage.LoadFromStream(stream, flags, ref format); - if (dib.IsNull) - { - throw new Exception(ErrorLoadingBitmap); - } - - saveInformation.loadFlags = flags; - originalFormat = format; - AddMemoryPressure(); - } - - #endregion - - #region Interfaces - - /// - /// Helper class to store informations for . - /// - private sealed class SaveInformation : ICloneable - { - public string filename; - public FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - public FREE_IMAGE_LOAD_FLAGS loadFlags = FREE_IMAGE_LOAD_FLAGS.DEFAULT; - public FREE_IMAGE_SAVE_FLAGS saveFlags = FREE_IMAGE_SAVE_FLAGS.DEFAULT; - - public object Clone() - { - return base.MemberwiseClone(); - } - } - - /// - /// Creates a deep copy of this . - /// - /// A deep copy of this . - public object Clone() - { - EnsureNotDisposed(); - FreeImageBitmap result = null; - FIBITMAP newDib = FreeImage.Clone(dib); - if (!dib.IsNull) - { - result = new FreeImageBitmap(newDib); - result.saveInformation = (SaveInformation)saveInformation.Clone(); - result.tag = tag; - result.originalFormat = originalFormat; - } - return result; - } - - /// - /// Performs application-defined tasks associated with freeing, - /// releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Performs application-defined tasks associated with freeing, - /// releasing, or resetting unmanaged resources. - /// - /// If true managed ressources are released. - protected virtual void Dispose(bool disposing) - { - // Only clean up once - lock (lockObject) - { - if (disposed) - { - return; - } - disposed = true; - } - - // Clean up managed resources - if (disposing) - { - if (stream != null) - { - if (disposeStream) - { - stream.Dispose(); - } - stream = null; - } - } - - tag = null; - saveInformation = null; - - // Clean up unmanaged resources - UnloadDib(); - } - - /// - /// Retrieves an object that can iterate through the individual scanlines in this . - /// - /// An for the . - /// The bitmaps's type is not supported. - IEnumerator IEnumerable.GetEnumerator() - { - return GetScanlines().GetEnumerator(); - } - - void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) - { - EnsureNotDisposed(); - using (MemoryStream memory = new MemoryStream(DataSize)) - { - if (!FreeImage.SaveToStream(dib, memory, FREE_IMAGE_FORMAT.FIF_TIFF, FREE_IMAGE_SAVE_FLAGS.TIFF_LZW)) - { - throw new SerializationException(); - } - memory.Capacity = (int)memory.Length; - info.AddValue("Bitmap Data", memory.GetBuffer()); - } - } - - #endregion - } -} - -namespace FreeImageAPI -{ - /// - /// Class handling non-bitmap related functions. - /// - public static class FreeImageEngine - { - #region Callback - - // Callback delegate - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private static readonly OutputMessageFunction outputMessageFunction; - - static FreeImageEngine() - { - // Check if FreeImage.dll is present and cancel setting the callbackfuntion if not - if (!IsAvailable) - { - return; - } - // Create a delegate (function pointer) to 'OnMessage' - outputMessageFunction = new OutputMessageFunction(OnMessage); - // Set the callback - FreeImage.SetOutputMessage(outputMessageFunction); - } - - /// - /// Internal callback - /// - private static void OnMessage(FREE_IMAGE_FORMAT fif, string message) - { - // Get a local copy of the multicast-delegate - OutputMessageFunction m = Message; - - // Check the local copy instead of the static instance - // to prevent a second thread from setting the delegate - // to null, which would cause a nullreference exception - if (m != null) - { - // Invoke the multicast-delegate - m.Invoke(fif, message); - } - } - - /// - /// Gets a value indicating if the FreeImage DLL is available or not. - /// - public static bool IsAvailable - { - get - { - return FreeImage.IsAvailable(); - } - } - - /// - /// Internal errors in FreeImage generate a logstring that can be - /// captured by this event. - /// - public static event OutputMessageFunction Message; - - #endregion - - /// - /// Gets a string containing the current version of the library. - /// - public static string Version - { - get - { - return FreeImage.GetVersion(); - } - } - - /// - /// Gets a string containing a standard copyright message. - /// - public static string CopyrightMessage - { - get - { - return FreeImage.GetCopyrightMessage(); - } - } - - /// - /// Gets whether the platform is using Little Endian. - /// - public static bool IsLittleEndian - { - get - { - return FreeImage.IsLittleEndian(); - } - } - } -} - -namespace FreeImageAPI.Plugins -{ - /// - /// Class representing a FreeImage format. - /// - public sealed class FreeImagePlugin - { - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private readonly FREE_IMAGE_FORMAT fif; - - /// - /// Initializes a new instance of this class. - /// - /// The FreeImage format to wrap. - internal FreeImagePlugin(FREE_IMAGE_FORMAT fif) - { - this.fif = fif; - } - - /// - /// Gets the format of this instance. - /// - public FREE_IMAGE_FORMAT FIFormat - { - get - { - return fif; - } - } - - /// - /// Gets or sets whether this plugin is enabled. - /// - public bool Enabled - { - get - { - return (FreeImage.IsPluginEnabled(fif) == 1); - } - set - { - FreeImage.SetPluginEnabled(fif, value); - } - } - - /// - /// Gets a string describing the format. - /// - public string Format - { - get - { - return FreeImage.GetFormatFromFIF(fif); - } - } - - /// - /// Gets a comma-delimited file extension list describing the bitmap formats - /// this plugin can read and/or write. - /// - public string ExtentsionList - { - get - { - return FreeImage.GetFIFExtensionList(fif); - } - } - - /// - /// Gets a descriptive string that describes the bitmap formats - /// this plugin can read and/or write. - /// - public string Description - { - get - { - return FreeImage.GetFIFDescription(fif); - } - } - - /// - /// Returns a regular expression string that can be used by - /// a regular expression engine to identify the bitmap. - /// FreeImageQt makes use of this function. - /// - public string RegExpr - { - get - { - return FreeImage.GetFIFRegExpr(fif); - } - } - - /// - /// Gets whether this plugin can load bitmaps. - /// - public bool SupportsReading - { - get - { - return FreeImage.FIFSupportsReading(fif); - } - } - - /// - /// Gets whether this plugin can save bitmaps. - /// - public bool SupportsWriting - { - get - { - return FreeImage.FIFSupportsWriting(fif); - } - } - - /// - /// Checks whether this plugin can save a bitmap in the desired data type. - /// - /// The desired image type. - /// True if this plugin can save bitmaps as the desired type, else false. - public bool SupportsExportType(FREE_IMAGE_TYPE type) - { - return FreeImage.FIFSupportsExportType(fif, type); - } - - /// - /// Checks whether this plugin can save bitmaps in the desired bit depth. - /// - /// The desired bit depth. - /// True if this plugin can save bitmaps in the desired bit depth, else false. - public bool SupportsExportBPP(int bpp) - { - return FreeImage.FIFSupportsExportBPP(fif, bpp); - } - - /// - /// Gets whether this plugin can load or save an ICC profile. - /// - public bool SupportsICCProfiles - { - get - { - return FreeImage.FIFSupportsICCProfiles(fif); - } - } - - /// - /// Checks whether an extension is valid for this format. - /// - /// The desired extension. - /// True if the extension is valid for this format, false otherwise. - public bool ValidExtension(string extension) - { - return FreeImage.IsExtensionValidForFIF(fif, extension); - } - - /// - /// Checks whether an extension is valid for this format. - /// - /// The desired extension. - /// The string comparison type. - /// True if the extension is valid for this format, false otherwise. - public bool ValidExtension(string extension, StringComparison comparisonType) - { - return FreeImage.IsExtensionValidForFIF(fif, extension, comparisonType); - } - - /// - /// Checks whether a filename is valid for this format. - /// - /// The desired filename. - /// True if the filename is valid for this format, false otherwise. - public bool ValidFilename(string filename) - { - return FreeImage.IsFilenameValidForFIF(fif, filename); - } - - /// - /// Checks whether a filename is valid for this format. - /// - /// The desired filename. - /// The string comparison type. - /// True if the filename is valid for this format, false otherwise. - public bool ValidFilename(string filename, StringComparison comparisonType) - { - return FreeImage.IsFilenameValidForFIF(fif, filename, comparisonType); - } - - /// - /// Gets a descriptive string that describes the bitmap formats - /// this plugin can read and/or write. - /// - /// A descriptive string that describes the bitmap formats. - public override string ToString() - { - return Description; - } - } -} - -namespace FreeImageAPI.IO -{ - /// - /// Internal class wrapping stream io functions. - /// - /// - /// FreeImage can read files from a disk or a network drive but also allows the user to - /// implement their own loading or saving functions to load them directly from an ftp or web - /// server for example. - /// - /// In .NET streams are a common way to handle data. The FreeImageStreamIO class handles - /// the loading and saving from and to streams. It implements the funtions FreeImage needs - /// to load data from an an arbitrary source. - /// - /// The class is for internal use only. - /// - internal static class FreeImageStreamIO - { - /// - /// structure that can be used to read from streams via - /// . - /// - public static readonly FreeImageIO io; - - /// - /// Initializes a new instances which can be used to - /// create a FreeImage compatible structure. - /// - static FreeImageStreamIO() - { - io.readProc = new ReadProc(streamRead); - io.writeProc = new WriteProc(streamWrite); - io.seekProc = new SeekProc(streamSeek); - io.tellProc = new TellProc(streamTell); - } - - /// - /// Reads the requested data from the stream and writes it to the given address. - /// - static unsafe uint streamRead(IntPtr buffer, uint size, uint count, fi_handle handle) - { - Stream stream = handle.GetObject() as Stream; - if ((stream == null) || (!stream.CanRead)) - { - return 0; - } - uint readCount = 0; - byte* ptr = (byte*)buffer; - byte[] bufferTemp = new byte[size]; - int read; - while (readCount < count) - { - read = stream.Read(bufferTemp, 0, (int)size); - if (read != (int)size) - { - stream.Seek(-read, SeekOrigin.Current); - break; - } - for (int i = 0; i < read; i++, ptr++) - { - *ptr = bufferTemp[i]; - } - readCount++; - } - return (uint)readCount; - } - - /// - /// Reads the given data and writes it into the stream. - /// - static unsafe uint streamWrite(IntPtr buffer, uint size, uint count, fi_handle handle) - { - Stream stream = handle.GetObject() as Stream; - if ((stream == null) || (!stream.CanWrite)) - { - return 0; - } - uint writeCount = 0; - byte[] bufferTemp = new byte[size]; - byte* ptr = (byte*)buffer; - while (writeCount < count) - { - for (int i = 0; i < size; i++, ptr++) - { - bufferTemp[i] = *ptr; - } - try - { - stream.Write(bufferTemp, 0, bufferTemp.Length); - } - catch - { - return writeCount; - } - writeCount++; - } - return writeCount; - } - - /// - /// Moves the streams position. - /// - static int streamSeek(fi_handle handle, int offset, SeekOrigin origin) - { - Stream stream = handle.GetObject() as Stream; - if (stream == null) - { - return 1; - } - stream.Seek((long)offset, origin); - return 0; - } - - /// - /// Returns the streams current position - /// - static int streamTell(fi_handle handle) - { - Stream stream = handle.GetObject() as Stream; - if (stream == null) - { - return -1; - } - return (int)stream.Position; - } - } -} - -namespace FreeImageAPI.Metadata -{ - /// - /// Provides additional information specific for GIF files. This class cannot be inherited. - /// - public class GifInformation : MDM_ANIMATION - { - /// - /// Initializes a new instance of the class - /// with the specified . - /// - /// A reference to a instance. - public GifInformation(FreeImageBitmap bitmap) - : base(bitmap.Dib) - { - } - - /// - /// Gets or sets a value indicating whether this frame uses the - /// GIF image's global palette. If set to false, this - /// frame uses its local palette. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public bool? UseGlobalPalette - { - get - { - byte? useGlobalPalette = GetTagValue("NoLocalPalette"); - return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?); - } - set - { - byte? val = null; - if (value.HasValue) - { - val = (byte)(value.Value ? 1 : 0); - } - SetTagValue("NoLocalPalette", val); - } - } - - /// - /// Creates a global palette for the GIF image, intialized with all entries of the - /// current local palette. - /// The property will be set to true when - /// invoking this method. This effectively enables the newly created global palette. - /// - /// - /// The image does not have a palette. - /// - public void CreateGlobalPalette() - { - CreateGlobalPalette(new Palette(dib)); - } - - /// - /// Creates a global palette for the GIF image with the specified size, intialized - /// with the first entries of the current local palette. - /// The property will be set to true when - /// invoking this method. This effectively enables the newly created global palette. - /// - /// The size of the newly created global palette. - /// - /// is a null reference. - public void CreateGlobalPalette(int size) - { - CreateGlobalPalette(new Palette(dib), size); - } - - /// - /// Creates a global palette for the GIF image, intialized with the entries - /// of the specified palette. - /// The property will be set to true when - /// invoking this method. This effectively enables the newly created global palette. - /// - /// The palette that contains the initial values for - /// the newly created global palette. - /// - /// is a null reference. - public void CreateGlobalPalette(Palette palette) - { - if (palette == null) - { - throw new ArgumentNullException("palette"); - } - - GlobalPalette = palette; - UseGlobalPalette = true; - } - - /// - /// Creates a global palette for the GIF image with the specified size, intialized - /// with the first entries of the specified palette. - /// The property will be set to true when - /// invoking this method. This effectively enables the newly created global palette. - /// - /// The palette that contains the initial values for - /// the newly created global palette. - /// The size of the newly created global palette. - /// - /// is a null reference. - public void CreateGlobalPalette(Palette palette, int size) - { - if (palette == null) - { - throw new ArgumentNullException("palette"); - } - if (size <= 0) - { - throw new ArgumentOutOfRangeException("size"); - } - - Palette pal = new Palette(size); - pal.CopyFrom(palette); - GlobalPalette = palette; - UseGlobalPalette = true; - } - } -} - -namespace FreeImageAPI.Metadata -{ - /// - /// Class handling metadata of a FreeImage bitmap. - /// - public class ImageMetadata : IEnumerable, IComparable, IComparable - { - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private readonly List data; - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private readonly FIBITMAP dib; - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool hideEmptyModels; - - /// - /// Initializes a new instance based on the specified , - /// showing all known models. - /// - /// Handle to a FreeImage bitmap. - public ImageMetadata(FIBITMAP dib) : this(dib, false) { } - - /// - /// Initializes a new instance based on the specified , - /// showing or hiding empry models. - /// - /// Handle to a FreeImage bitmap. - /// When true, empty metadata models - /// will be hidden until a tag to this model is added. - public ImageMetadata(FIBITMAP dib, bool hideEmptyModels) - { - if (dib.IsNull) throw new ArgumentNullException("dib"); - data = new List(FreeImage.FREE_IMAGE_MDMODELS.Length); - this.dib = dib; - this.hideEmptyModels = hideEmptyModels; - - data.Add(new MDM_ANIMATION(dib)); - data.Add(new MDM_COMMENTS(dib)); - data.Add(new MDM_CUSTOM(dib)); - data.Add(new MDM_EXIF_EXIF(dib)); - data.Add(new MDM_EXIF_GPS(dib)); - data.Add(new MDM_INTEROP(dib)); - data.Add(new MDM_EXIF_MAIN(dib)); - data.Add(new MDM_MAKERNOTE(dib)); - data.Add(new MDM_GEOTIFF(dib)); - data.Add(new MDM_IPTC(dib)); - data.Add(new MDM_NODATA(dib)); - data.Add(new MDM_XMP(dib)); - } - - /// - /// Gets or sets the of the specified type. - /// In case the getter returns null the model is not contained - /// by the list. - /// null can be used calling the setter to destroy the model. - /// - /// Type of the model. - /// The object of the specified type. - public MetadataModel this[FREE_IMAGE_MDMODEL model] - { - get - { - for (int i = 0; i < data.Count; i++) - { - if (data[i].Model == model) - { - if (!data[i].Exists && hideEmptyModels) - { - return null; - } - return data[i]; - } - } - return null; - } - } - - /// - /// Gets or sets the at the specified index. - /// In case the getter returns null the model is not contained - /// by the list. - /// null can be used calling the setter to destroy the model. - /// - /// Index of the within - /// this instance. - /// The - /// object at the specified index. - public MetadataModel this[int index] - { - get - { - if (index < 0 || index >= data.Count) - { - throw new ArgumentOutOfRangeException("index"); - } - return (hideEmptyModels && !data[index].Exists) ? null : data[index]; - } - } - - /// - /// Returns a list of all visible - /// MetadataModels. - /// - public List List - { - get - { - if (hideEmptyModels) - { - List result = new List(); - for (int i = 0; i < data.Count; i++) - { - if (data[i].Exists) - { - result.Add(data[i]); - } - } - return result; - } - else - { - return data; - } - } - } - - /// - /// Adds new tag to the bitmap or updates its value in case it already exists. - /// will be used as key. - /// - /// The tag to add or update. - /// Returns true on success, false on failure. - /// - /// is null. - public bool AddTag(MetadataTag tag) - { - for (int i = 0; i < data.Count; i++) - { - if (tag.Model == data[i].Model) - { - return data[i].AddTag(tag); - } - } - return false; - } - - /// - /// Returns the number of visible - /// MetadataModels. - /// - public int Count - { - get - { - if (hideEmptyModels) - { - int count = 0; - for (int i = 0; i < data.Count; i++) - { - if (data[i].Exists) - { - count++; - } - } - return count; - } - else - { - return data.Count; - } - } - } - - /// - /// Gets or sets whether empty - /// MetadataModels are hidden. - /// - public bool HideEmptyModels - { - get - { - return hideEmptyModels; - } - set - { - hideEmptyModels = value; - } - } - - /// - /// Retrieves an object that can iterate through the individual - /// MetadataModels - /// in this . - /// - /// An for this . - public IEnumerator GetEnumerator() - { - if (hideEmptyModels) - { - List tempList = new List(data.Count); - for (int i = 0; i < data.Count; i++) - { - if (data[i].Exists) - { - tempList.Add(data[i]); - } - } - return tempList.GetEnumerator(); - } - else - { - return data.GetEnumerator(); - } - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is ImageMetadata)) - { - throw new ArgumentException("obj"); - } - return CompareTo((ImageMetadata)obj); - } - - /// - /// Compares this instance with a specified object. - /// - /// A to compare. - /// A signed number indicating the relative values of this instance - /// and . - public int CompareTo(ImageMetadata other) - { - return this.dib.CompareTo(other.dib); - } - } -} - -namespace FreeImageAPI.Plugins -{ - /// - /// Class representing own FreeImage-Plugins. - /// - /// - /// FreeImages itself is plugin based. Each supported format is integrated by a seperat plugin, - /// that handles loading, saving, descriptions, identifing ect. - /// And of course the user can create own plugins and use them in FreeImage. - /// To do that the above mentioned predefined methodes need to be implemented. - /// - /// The class below handles the creation of such a plugin. The class itself is abstract - /// as well as some core functions that need to be implemented. - /// The class can be used to enable or disable the plugin in FreeImage after regististration or - /// retrieve the formatid, assigned by FreeImage. - /// The class handles the callback functions, garbage collector and pointer operation to make - /// the implementation as user friendly as possible. - /// - /// How to: - /// There are two functions that need to be implemented: - /// and - /// . - /// is used by the constructor - /// of the abstract class. FreeImage wants a list of the implemented functions. Each function is - /// represented by a function pointer (a .NET ). In case a function - /// is not implemented FreeImage receives an empty delegate). To tell the constructor - /// which functions have been implemented the information is represented by a disjunction of - /// . - /// - /// For example: - /// return MethodFlags.LoadProc | MethodFlags.SaveProc; - /// - /// The above statement means that LoadProc and SaveProc have been implemented by the user. - /// Keep in mind, that each function has a standard implementation that has static return - /// values that may cause errors if listed in - /// without a real implementation. - /// - /// is used by some checks of FreeImage and - /// must be implemented. for example can be - /// implemented if the plugin supports reading, but it doesn't have to, the plugin could only - /// be used to save an already loaded bitmap in a special format. - /// - public abstract class LocalPlugin - { - /// - /// Struct containing function pointers. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private Plugin plugin; - - /// - /// Delegate for register callback by FreeImage. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private InitProc initProc; - - /// - /// The format id assiged to the plugin. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - - /// - /// When true the plugin was registered successfully else false. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected readonly bool registered = false; - - /// - /// A copy of the functions used to register. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected readonly MethodFlags implementedMethods; - - /// - /// MethodFlags defines values to fill a bitfield telling which - /// functions have been implemented by a plugin. - /// - [Flags] - protected enum MethodFlags - { - /// - /// No mothods implemented. - /// - None = 0x0, - - /// - /// DescriptionProc has been implemented. - /// - DescriptionProc = 0x1, - - /// - /// ExtensionListProc has been implemented. - /// - ExtensionListProc = 0x2, - - /// - /// RegExprProc has been implemented. - /// - RegExprProc = 0x4, - - /// - /// OpenProc has been implemented. - /// - OpenProc = 0x8, - - /// - /// CloseProc has been implemented. - /// - CloseProc = 0x10, - - /// - /// PageCountProc has been implemented. - /// - PageCountProc = 0x20, - - /// - /// PageCapabilityProc has been implemented. - /// - PageCapabilityProc = 0x40, - - /// - /// LoadProc has been implemented. - /// - LoadProc = 0x80, - - /// - /// SaveProc has been implemented. - /// - SaveProc = 0x100, - - /// - /// ValidateProc has been implemented. - /// - ValidateProc = 0x200, - - /// - /// MimeProc has been implemented. - /// - MimeProc = 0x400, - - /// - /// SupportsExportBPPProc has been implemented. - /// - SupportsExportBPPProc = 0x800, - - /// - /// SupportsExportTypeProc has been implemented. - /// - SupportsExportTypeProc = 0x1000, - - /// - /// SupportsICCProfilesProc has been implemented. - /// - SupportsICCProfilesProc = 0x2000 - } - - // Functions that must be implemented. - - /// - /// Function that returns a bitfield containing the - /// implemented methods. - /// - /// Bitfield of the implemented methods. - protected abstract MethodFlags GetImplementedMethods(); - - /// - /// Implementation of FormatProc - /// - /// A string containing the plugins format. - protected abstract string FormatProc(); - - // Functions that can be implemented. - - /// - /// Function that can be implemented. - /// - protected virtual string DescriptionProc() { return ""; } - /// - /// Function that can be implemented. - /// - protected virtual string ExtensionListProc() { return ""; } - /// - /// Function that can be implemented. - /// - protected virtual string RegExprProc() { return ""; } - /// - /// Function that can be implemented. - /// - protected virtual IntPtr OpenProc(ref FreeImageIO io, fi_handle handle, bool read) { return IntPtr.Zero; } - /// - /// Function that can be implemented. - /// - protected virtual void CloseProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { } - /// - /// Function that can be implemented. - /// - protected virtual int PageCountProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { return 0; } - /// - /// Function that can be implemented. - /// - protected virtual int PageCapabilityProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { return 0; } - /// - /// Function that can be implemented. - /// - protected virtual FIBITMAP LoadProc(ref FreeImageIO io, fi_handle handle, int page, int flags, IntPtr data) { return FIBITMAP.Zero; } - /// - /// Function that can be implemented. - /// - protected virtual bool SaveProc(ref FreeImageIO io, FIBITMAP dib, fi_handle handle, int page, int flags, IntPtr data) { return false; } - /// - /// Function that can be implemented. - /// - protected virtual bool ValidateProc(ref FreeImageIO io, fi_handle handle) { return false; } - /// - /// Function that can be implemented. - /// - protected virtual string MimeProc() { return ""; } - /// - /// Function that can be implemented. - /// - protected virtual bool SupportsExportBPPProc(int bpp) { return false; } - /// - /// Function that can be implemented. - /// - protected virtual bool SupportsExportTypeProc(FREE_IMAGE_TYPE type) { return false; } - /// - /// Function that can be implemented. - /// - protected virtual bool SupportsICCProfilesProc() { return false; } - - /// - /// The constructor automatically registeres the plugin in FreeImage. - /// To do this it prepares a FreeImage defined structure with function pointers - /// to the implemented functions or null if not implemented. - /// Before registing the functions they are pinned in memory so the garbage collector - /// can't move them around in memory after we passed there addresses to FreeImage. - /// - public LocalPlugin() - { - implementedMethods = GetImplementedMethods(); - - if ((implementedMethods & MethodFlags.DescriptionProc) != 0) - { - plugin.descriptionProc = new DescriptionProc(DescriptionProc); - } - if ((implementedMethods & MethodFlags.ExtensionListProc) != 0) - { - plugin.extensionListProc = new ExtensionListProc(ExtensionListProc); - } - if ((implementedMethods & MethodFlags.RegExprProc) != 0) - { - plugin.regExprProc = new RegExprProc(RegExprProc); - } - if ((implementedMethods & MethodFlags.OpenProc) != 0) - { - plugin.openProc = new OpenProc(OpenProc); - } - if ((implementedMethods & MethodFlags.CloseProc) != 0) - { - plugin.closeProc = new CloseProc(CloseProc); - } - if ((implementedMethods & MethodFlags.PageCountProc) != 0) - { - plugin.pageCountProc = new PageCountProc(PageCountProc); - } - if ((implementedMethods & MethodFlags.PageCapabilityProc) != 0) - { - plugin.pageCapabilityProc = new PageCapabilityProc(PageCapabilityProc); - } - if ((implementedMethods & MethodFlags.LoadProc) != 0) - { - plugin.loadProc = new LoadProc(LoadProc); - } - if ((implementedMethods & MethodFlags.SaveProc) != 0) - { - plugin.saveProc = new SaveProc(SaveProc); - } - if ((implementedMethods & MethodFlags.ValidateProc) != 0) - { - plugin.validateProc = new ValidateProc(ValidateProc); - } - if ((implementedMethods & MethodFlags.MimeProc) != 0) - { - plugin.mimeProc = new MimeProc(MimeProc); - } - if ((implementedMethods & MethodFlags.SupportsExportBPPProc) != 0) - { - plugin.supportsExportBPPProc = new SupportsExportBPPProc(SupportsExportBPPProc); - } - if ((implementedMethods & MethodFlags.SupportsExportTypeProc) != 0) - { - plugin.supportsExportTypeProc = new SupportsExportTypeProc(SupportsExportTypeProc); - } - if ((implementedMethods & MethodFlags.SupportsICCProfilesProc) != 0) - { - plugin.supportsICCProfilesProc = new SupportsICCProfilesProc(SupportsICCProfilesProc); - } - - // FormatProc is always implemented - plugin.formatProc = new FormatProc(FormatProc); - - // InitProc is the register call back. - initProc = new InitProc(RegisterProc); - - // Register the plugin. The result will be saved and can be accessed later. - registered = FreeImage.RegisterLocalPlugin(initProc, null, null, null, null) != FREE_IMAGE_FORMAT.FIF_UNKNOWN; - if (registered) - { - PluginRepository.RegisterLocalPlugin(this); - } - } - - private void RegisterProc(ref Plugin plugin, int format_id) - { - // Copy the function pointers - plugin = this.plugin; - // Retrieve the format if assigned to this plugin by FreeImage. - format = (FREE_IMAGE_FORMAT)format_id; - } - - /// - /// Gets or sets if the plugin is enabled. - /// - public bool Enabled - { - get - { - if (registered) - { - return (FreeImage.IsPluginEnabled(format) > 0); - } - else - { - throw new ObjectDisposedException("plugin not registered"); - } - } - set - { - if (registered) - { - FreeImage.SetPluginEnabled(format, value); - } - else - { - throw new ObjectDisposedException("plugin not registered"); - } - } - } - - /// - /// Gets if the plugin was registered successfully. - /// - public bool Registered - { - get { return registered; } - } - - /// - /// Gets the FreeImage assigned to this plugin. - /// - public FREE_IMAGE_FORMAT Format - { - get - { - return format; - } - } - - /// - /// Reads from an unmanaged stream. - /// - protected unsafe int Read(FreeImageIO io, fi_handle handle, uint size, uint count, ref byte[] buffer) - { - fixed (byte* ptr = buffer) - { - return (int)io.readProc(new IntPtr(ptr), size, count, handle); - } - } - - /// - /// Reads a single byte from an unmanaged stream. - /// - protected unsafe int ReadByte(FreeImageIO io, fi_handle handle) - { - byte buffer = 0; - return (int)io.readProc(new IntPtr(&buffer), 1, 1, handle) > 0 ? buffer : -1; - } - - /// - /// Writes to an unmanaged stream. - /// - protected unsafe int Write(FreeImageIO io, fi_handle handle, uint size, uint count, ref byte[] buffer) - { - fixed (byte* ptr = buffer) - { - return (int)io.writeProc(new IntPtr(ptr), size, count, handle); - } - } - - /// - /// Writes a single byte to an unmanaged stream. - /// - protected unsafe int WriteByte(FreeImageIO io, fi_handle handle, byte value) - { - return (int)io.writeProc(new IntPtr(&value), 1, 1, handle); - } - - /// - /// Seeks in an unmanaged stream. - /// - protected int Seek(FreeImageIO io, fi_handle handle, int offset, SeekOrigin origin) - { - return io.seekProc(handle, offset, origin); - } - - /// - /// Retrieves the position of an unmanaged stream. - /// - protected int Tell(FreeImageIO io, fi_handle handle) - { - return io.tellProc(handle); - } - } -} - -namespace FreeImageAPI -{ - /// - /// Represents unmanaged memory, containing an array of a given structure. - /// - /// Structuretype represented by the instance. - /// - /// and can not be marshalled. - /// - /// Use instead of and - /// instead of . - /// - public unsafe class MemoryArray : IDisposable, ICloneable, ICollection, IEnumerable, IEquatable> where T : struct - { - /// - /// Baseaddress of the wrapped memory. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected byte* baseAddress; - - /// - /// Number of elements being wrapped. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected int length; - - /// - /// Size, in bytes, of each element. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private static readonly int size; - - /// - /// Array of T containing a single element. - /// The array is used as a workaround, because there are no pointer for generic types. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected T[] buffer; - - /// - /// Pointer to the element of buffer. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected byte* ptr; - - /// - /// Handle for pinning buffer. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected GCHandle handle; - - /// - /// Indicates whether the wrapped memory is handled like a bitfield. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected readonly bool isOneBit; - - /// - /// Indicates whther the wrapped memory is handles like 4-bit blocks. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected readonly bool isFourBit; - - /// - /// An object that can be used to synchronize access to the . - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected object syncRoot = null; - - static MemoryArray() - { - T[] dummy = new T[2]; - long marshalledSize = Marshal.SizeOf(typeof(T)); - long structureSize = - Marshal.UnsafeAddrOfPinnedArrayElement(dummy, 1).ToInt64() - - Marshal.UnsafeAddrOfPinnedArrayElement(dummy, 0).ToInt64(); - if (marshalledSize != structureSize) - { - throw new NotSupportedException( - "The desired type can not be handled, " + - "because its managed and unmanaged size in bytes are different."); - } - - size = (int)marshalledSize; - } - - /// - /// Initializes a new instance. - /// - protected MemoryArray() - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Address of the memory block. - /// Length of the array. - /// - /// is null. - /// - /// is less or equal zero. - /// - /// The type is not supported. - public MemoryArray(IntPtr baseAddress, int length) - : this(baseAddress.ToPointer(), length) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Address of the memory block. - /// Length of the array. - /// - /// is null. - /// - /// is less or equal zero. - /// - /// The type is not supported. - public MemoryArray(void* baseAddress, int length) - { - if (typeof(T) == typeof(FI1BIT)) - { - isOneBit = true; - } - else if (typeof(T) == typeof(FI4BIT)) - { - isFourBit = true; - } - - if (baseAddress == null) - { - throw new ArgumentNullException("baseAddress"); - } - if (length < 1) - { - throw new ArgumentOutOfRangeException("length"); - } - - this.baseAddress = (byte*)baseAddress; - this.length = (int)length; - - if (!isOneBit && !isFourBit) - { - // Create an array containing a single element. - // Due to the fact, that it's not possible to create pointers - // of generic types, an array is used to obtain the memory - // address of an element of T. - this.buffer = new T[1]; - // The array is pinned immediately to prevent the GC from - // moving it to a different position in memory. - this.handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - // The array and its content have beed pinned, so that its address - // can be safely requested and stored for the whole lifetime - // of the instace. - this.ptr = (byte*)handle.AddrOfPinnedObject(); - } - } - - /// - /// Frees the allocated . - /// - ~MemoryArray() - { - Dispose(false); - } - - /// - /// Tests whether two specified structures are equivalent. - /// - /// The that is to the left of the equality operator. - /// The that is to the right of the equality operator. - /// - /// true if the two structures are equal; otherwise, false. - /// - public static bool operator ==(MemoryArray left, MemoryArray right) - { - if (object.ReferenceEquals(left, right)) - { - return true; - } - if (object.ReferenceEquals(right, null) || - object.ReferenceEquals(left, null) || - (left.length != right.length)) - { - return false; - } - if (left.baseAddress == right.baseAddress) - { - return true; - } - return FreeImage.CompareMemory(left.baseAddress, right.baseAddress, (uint)left.length); - } - - /// - /// Tests whether two specified structures are different. - /// - /// The that is to the left of the inequality operator. - /// The that is to the right of the inequality operator. - /// - /// true if the two structures are different; otherwise, false. - /// - public static bool operator !=(MemoryArray left, MemoryArray right) - { - return (!(left == right)); - } - - /// - /// Gets the value at the specified position. - /// - /// A 32-bit integer that represents the position - /// of the array element to get. - /// The value at the specified position. - /// - /// is outside the range of valid indexes - /// for the unmanaged array. - public T GetValue(int index) - { - if ((index >= this.length) || (index < 0)) - { - throw new ArgumentOutOfRangeException("index"); - } - - return GetValueInternal(index); - } - - private T GetValueInternal(int index) - { - EnsureNotDisposed(); - if (isOneBit) - { - return (T)(object)(FI1BIT)(((baseAddress[index / 8] & ((1 << (7 - (index % 8))))) == 0) ? 0 : 1); - } - else if (isFourBit) - { - return (T)(object)(FI4BIT)(((index % 2) == 0) ? (baseAddress[index / 2] >> 4) : (baseAddress[index / 2] & 0x0F)); - } - else - { - CopyMemory(ptr, baseAddress + (index * size), size); - return buffer[0]; - } - } - - /// - /// Sets a value to the element at the specified position. - /// - /// The new value for the specified element. - /// A 32-bit integer that represents the - /// position of the array element to set. - /// - /// is outside the range of valid indexes - /// for the unmanaged array. - public void SetValue(T value, int index) - { - if ((index >= this.length) || (index < 0)) - { - throw new ArgumentOutOfRangeException("index"); - } - SetValueInternal(value, index); - } - - private void SetValueInternal(T value, int index) - { - EnsureNotDisposed(); - if (isOneBit) - { - if ((FI1BIT)(object)value != 0) - { - baseAddress[index / 8] |= (byte)(1 << (7 - (index % 8))); - } - else - { - baseAddress[index / 8] &= (byte)(~(1 << (7 - (index % 8)))); - } - } - else if (isFourBit) - { - if ((index % 2) == 0) - { - baseAddress[index / 2] = (byte)((baseAddress[index / 2] & 0x0F) | ((FI4BIT)(object)value << 4)); - } - else - { - baseAddress[index / 2] = (byte)((baseAddress[index / 2] & 0xF0) | ((FI4BIT)(object)value & 0x0F)); - } - } - else - { - buffer[0] = value; - CopyMemory(baseAddress + (index * size), ptr, size); - } - } - - /// - /// Gets the values at the specified position and length. - /// - /// A 32-bit integer that represents the position - /// of the array elements to get. - /// A 32-bit integer that represents the length - /// of the array elements to get. - /// The values at the specified position and length. - /// - /// is outside the range of valid indexes - /// for the unmanaged array or is greater than the number of elements - /// from to the end of the unmanaged array. - public T[] GetValues(int index, int length) - { - EnsureNotDisposed(); - if ((index >= this.length) || (index < 0)) - { - throw new ArgumentOutOfRangeException("index"); - } - if (((index + length) > this.length) || (length < 1)) - { - throw new ArgumentOutOfRangeException("length"); - } - - T[] data = new T[length]; - if (isOneBit || isFourBit) - { - for (int i = 0; i < length; i++) - { - data[i] = GetValueInternal(i); - } - } - else - { - GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); - byte* dst = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(data, 0); - CopyMemory(dst, baseAddress + (size * index), size * length); - handle.Free(); - } - return data; - } - - /// - /// Sets the values at the specified position. - /// - /// An array containing the new values for the specified elements. - /// A 32-bit integer that represents the position - /// of the array elements to set. - /// - /// is a null reference (Nothing in Visual Basic). - /// - /// is outside the range of valid indexes - /// for the unmanaged array or is greater than the number of elements - /// from to the end of the array. - public void SetValues(T[] values, int index) - { - EnsureNotDisposed(); - if (values == null) - { - throw new ArgumentNullException("values"); - } - if ((index >= this.length) || (index < 0)) - { - throw new ArgumentOutOfRangeException("index"); - } - if ((index + values.Length) > this.length) - { - throw new ArgumentOutOfRangeException("values.Length"); - } - - if (isOneBit || isFourBit) - { - for (int i = 0; i != values.Length; ) - { - SetValueInternal(values[i++], index++); - } - } - else - { - GCHandle handle = GCHandle.Alloc(values, GCHandleType.Pinned); - byte* src = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(values, 0); - CopyMemory(baseAddress + (index * size), src, size * length); - handle.Free(); - } - } - - /// - /// Copies the entire array to a compatible one-dimensional , - /// starting at the specified index of the target array. - /// - /// The one-dimensional that is the destination - /// of the elements copied from . - /// The must have zero-based indexing. - /// The zero-based index in - /// at which copying begins. - public void CopyTo(Array array, int index) - { - EnsureNotDisposed(); - if (!(array is T[])) - { - throw new InvalidCastException("array"); - } - try - { - CopyTo((T[])array, 0, index, length); - } - catch (ArgumentOutOfRangeException ex) - { - throw new ArgumentException(ex.Message, ex); - } - } - - /// - /// Copies a range of elements from the unmanaged array starting at the specified - /// and pastes them to - /// starting at the specified . - /// The length and the indexes are specified as 32-bit integers. - /// - /// The array that receives the data. - /// A 32-bit integer that represents the index - /// in the unmanaged array at which copying begins. - /// A 32-bit integer that represents the index in - /// the destination array at which storing begins. - /// A 32-bit integer that represents the number of elements to copy. - /// - /// is a null reference (Nothing in Visual Basic). - /// - /// is outside the range of valid indexes - /// for the unmanaged array or is greater than the number of elements - /// from to the end of the unmanaged array - /// -or- - /// is outside the range of valid indexes - /// for the array or is greater than the number of elements - /// from to the end of the array. - /// - public void CopyTo(T[] array, int sourceIndex, int destinationIndex, int length) - { - EnsureNotDisposed(); - if (array == null) - { - throw new ArgumentNullException("array"); - } - if ((sourceIndex >= this.length) || (sourceIndex < 0)) - { - throw new ArgumentOutOfRangeException("sourceIndex"); - } - if ((destinationIndex >= array.Length) || (destinationIndex < 0)) - { - throw new ArgumentOutOfRangeException("destinationIndex"); - } - if ((sourceIndex + length > this.length) || - (destinationIndex + length > array.Length) || - (length < 1)) - { - throw new ArgumentOutOfRangeException("length"); - } - - if (isOneBit || isFourBit) - { - for (int i = 0; i != length; i++) - { - array[destinationIndex++] = GetValueInternal(sourceIndex++); - } - } - else - { - GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned); - byte* dst = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(array, destinationIndex); - CopyMemory(dst, baseAddress + (size * sourceIndex), size * length); - handle.Free(); - } - } - - /// - /// Copies a range of elements from the array starting at the specified - /// and pastes them to the unmanaged array - /// starting at the specified . - /// The length and the indexes are specified as 32-bit integers. - /// - /// The array that holds the data. - /// A 32-bit integer that represents the index - /// in the array at which copying begins. - /// A 32-bit integer that represents the index in - /// the unmanaged array at which storing begins. - /// A 32-bit integer that represents the number of elements to copy. - /// - /// is a null reference (Nothing in Visual Basic). - /// - /// is outside the range of valid indexes - /// for the array or is greater than the number of elements - /// from to the end of the array - /// -or- - /// is outside the range of valid indexes - /// for the unmanaged array or is greater than the number of elements - /// from to the end of the unmanaged array. - /// - public void CopyFrom(T[] array, int sourceIndex, int destinationIndex, int length) - { - EnsureNotDisposed(); - if (array == null) - { - throw new ArgumentNullException("array"); - } - if ((destinationIndex >= this.length) || (destinationIndex < 0)) - { - throw new ArgumentOutOfRangeException("destinationIndex"); - } - if ((sourceIndex >= array.Length) || (sourceIndex < 0)) - { - throw new ArgumentOutOfRangeException("sourceIndex"); - } - if ((destinationIndex + length > this.length) || - (sourceIndex + length > array.Length) || - (length < 1)) - { - throw new ArgumentOutOfRangeException("length"); - } - - if (isOneBit || isFourBit) - { - for (int i = 0; i != length; i++) - { - SetValueInternal(array[sourceIndex++], destinationIndex++); - } - } - else - { - GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned); - byte* src = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(array, sourceIndex); - CopyMemory(baseAddress + (size * destinationIndex), src, size * length); - handle.Free(); - } - } - - /// - /// Returns the represented block of memory as an array of . - /// - /// The represented block of memory. - public byte[] ToByteArray() - { - EnsureNotDisposed(); - byte[] result; - if (isOneBit) - { - result = new byte[(length + 7) / 8]; - } - else if (isFourBit) - { - result = new byte[(length + 3) / 4]; - } - else - { - result = new byte[size * length]; - } - fixed (byte* dst = result) - { - CopyMemory(dst, baseAddress, result.Length); - } - return result; - } - - /// - /// Gets or sets the value at the specified position in the array. - /// - /// A 32-bit integer that represents the position - /// of the array element to get. - /// The value at the specified position in the array. - /// - /// is outside the range of valid indexes - /// for the unmanaged array. - public T this[int index] - { - get - { - return GetValue(index); - } - set - { - SetValue(value, index); - } - } - - /// - /// Gets or sets the values of the unmanaged array. - /// - public T[] Data - { - get - { - return GetValues(0, length); - } - set - { - if (value == null) - { - throw new ArgumentNullException("value"); - } - if (value.Length != length) - { - throw new ArgumentOutOfRangeException("value.Lengt"); - } - SetValues(value, 0); - } - } - - /// - /// Gets the length of the unmanaged array. - /// - public int Length - { - get - { - EnsureNotDisposed(); - return length; - } - } - - /// - /// Gets the base address of the represented memory block. - /// - public IntPtr BaseAddress - { - get - { - EnsureNotDisposed(); - return new IntPtr(baseAddress); - } - } - - /// - /// Creates a shallow copy of the . - /// - /// A shallow copy of the . - public object Clone() - { - EnsureNotDisposed(); - return new MemoryArray(baseAddress, length); - } - - /// - /// Gets a 32-bit integer that represents the total number of elements - /// in the . - /// - public int Count - { - get { EnsureNotDisposed(); return length; } - } - - /// - /// Gets a value indicating whether access to the - /// is synchronized (thread safe). - /// - public bool IsSynchronized - { - get { EnsureNotDisposed(); return false; } - } - - /// - /// Gets an object that can be used to synchronize access to the . - /// - public object SyncRoot - { - get - { - EnsureNotDisposed(); - if (syncRoot == null) - { - System.Threading.Interlocked.CompareExchange(ref syncRoot, new object(), null); - } - return syncRoot; - } - } - - /// - /// Retrieves an object that can iterate through the individual - /// elements in this . - /// - /// An for the . - public IEnumerator GetEnumerator() - { - EnsureNotDisposed(); - T[] values = GetValues(0, length); - for (int i = 0; i != values.Length; i++) - { - yield return values[i]; - } - } - - /// - /// Retrieves an object that can iterate through the individual - /// elements in this . - /// - /// An for the . - IEnumerator IEnumerable.GetEnumerator() - { - EnsureNotDisposed(); - T[] values = GetValues(0, length); - for (int i = 0; i != values.Length; i++) - { - yield return values[i]; - } - } - - /// - /// Releases all ressources. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Releases allocated handles associated with this instance. - /// - /// true to release managed resources. - protected virtual void Dispose(bool disposing) - { - if (baseAddress != null) - { - if (handle.IsAllocated) - handle.Free(); - baseAddress = null; - buffer = null; - length = 0; - syncRoot = null; - } - } - - /// - /// Throws an if - /// this instance is disposed. - /// - protected virtual void EnsureNotDisposed() - { - if (baseAddress == null) - throw new ObjectDisposedException("This instance is disposed."); - } - - /// - /// Tests whether the specified structure is equivalent to this - /// structure. - /// - /// The structure to test. - /// true if is a - /// instance equivalent to this structure; otherwise, - /// false. - public override bool Equals(object obj) - { - EnsureNotDisposed(); - return ((obj is MemoryArray) && Equals((MemoryArray)obj)); - } - - /// - /// Tests whether the specified structure is equivalent to this - /// structure. - /// - /// The structure to test. - /// true if is equivalent to this - /// structure; otherwise, - /// false. - public bool Equals(MemoryArray other) - { - EnsureNotDisposed(); - return ((this.baseAddress == other.baseAddress) && (this.length == other.length)); - } - - /// - /// Serves as a hash function for a particular type. - /// - /// A hash code for the current . - public override int GetHashCode() - { - EnsureNotDisposed(); - return (int)baseAddress ^ length; - } - - /// - /// Copies a block of memory from one location to another. - /// - /// Pointer to the starting address of the copy destination. - /// Pointer to the starting address of the block of memory to be copied. - /// Size of the block of memory to copy, in bytes. - protected static unsafe void CopyMemory(byte* dest, byte* src, int len) - { - if (len >= 0x10) - { - do - { - *((int*)dest) = *((int*)src); - *((int*)(dest + 4)) = *((int*)(src + 4)); - *((int*)(dest + 8)) = *((int*)(src + 8)); - *((int*)(dest + 12)) = *((int*)(src + 12)); - dest += 0x10; - src += 0x10; - } - while ((len -= 0x10) >= 0x10); - } - if (len > 0) - { - if ((len & 8) != 0) - { - *((int*)dest) = *((int*)src); - *((int*)(dest + 4)) = *((int*)(src + 4)); - dest += 8; - src += 8; - } - if ((len & 4) != 0) - { - *((int*)dest) = *((int*)src); - dest += 4; - src += 4; - } - if ((len & 2) != 0) - { - *((short*)dest) = *((short*)src); - dest += 2; - src += 2; - } - if ((len & 1) != 0) - { - *dest = *src; - } - } - } - } -} - -namespace FreeImageAPI.Metadata -{ - /// - /// Base class that represents a collection of all tags contained in a metadata model. - /// - /// - /// The MetedataModel class is an abstract base class, which is inherited by - /// several derived classes, one for each existing metadata model. - /// - public abstract class MetadataModel : IEnumerable - { - /// - /// Handle to the encapsulated FreeImage-bitmap. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected readonly FIBITMAP dib; - - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - /// - /// is null. - protected MetadataModel(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - this.dib = dib; - } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public abstract FREE_IMAGE_MDMODEL Model - { - get; - } - - /// - /// Adds new tag to the bitmap or updates its value in case it already exists. - /// will be used as key. - /// - /// The tag to add or update. - /// Returns true on success, false on failure. - /// - /// is null. - /// - /// The tags model differs from this instances model. - public bool AddTag(MetadataTag tag) - { - if (tag == null) - { - throw new ArgumentNullException("tag"); - } - if (tag.Model != Model) - { - throw new ArgumentException("tag.Model"); - } - return tag.AddToImage(dib); - } - - /// - /// Adds a list of tags to the bitmap or updates their values in case they already exist. - /// will be used as key. - /// - /// A list of tags to add or update. - /// Returns the number of successfully added tags. - /// - /// is null. - public int AddTag(IEnumerable list) - { - if (list == null) - { - throw new ArgumentNullException("list"); - } - int count = 0; - foreach (MetadataTag tag in list) - { - if (tag.Model == Model && tag.AddToImage(dib)) - { - count++; - } - } - return count; - } - - /// - /// Removes the specified tag from the bitmap. - /// - /// The key of the tag. - /// Returns true on success, false on failure. - /// - /// is null. - public bool RemoveTag(string key) - { - if (key == null) - { - throw new ArgumentNullException("key"); - } - return FreeImage.SetMetadata(Model, dib, key, FITAG.Zero); - } - - /// - /// Destroys the metadata model - /// which will remove all tags of this model from the bitmap. - /// - /// Returns true on success, false on failure. - public bool DestoryModel() - { - return FreeImage.SetMetadata(Model, dib, null, FITAG.Zero); - } - - /// - /// Returns the specified metadata tag. - /// - /// The key of the tag. - /// The metadata tag. - /// - /// is null. - public MetadataTag GetTag(string key) - { - if (key == null) - { - throw new ArgumentNullException("key"); - } - MetadataTag tag; - return FreeImage.GetMetadata(Model, dib, key, out tag) ? tag : null; - } - - /// - /// Returns whether the specified tag exists. - /// - /// The key of the tag. - /// True in case the tag exists, else false. - /// - /// is null. - public bool TagExists(string key) - { - if (key == null) - { - throw new ArgumentNullException("key"); - } - MetadataTag tag; - return FreeImage.GetMetadata(Model, dib, key, out tag); - } - - /// - /// Returns a list of all metadata tags this instance represents. - /// - public List List - { - get - { - List list = new List((int)FreeImage.GetMetadataCount(Model, dib)); - MetadataTag tag; - FIMETADATA mdHandle = FreeImage.FindFirstMetadata(Model, dib, out tag); - if (!mdHandle.IsNull) - { - do - { - list.Add(tag); - } - while (FreeImage.FindNextMetadata(mdHandle, out tag)); - FreeImage.FindCloseMetadata(mdHandle); - } - return list; - } - } - - /// - /// Returns the tag at the given index. - /// - /// Index of the tag to return. - /// The tag at the given index. - protected MetadataTag GetTagFromIndex(int index) - { - if (index >= Count || index < 0) - { - throw new ArgumentOutOfRangeException("index"); - } - MetadataTag tag; - int count = 0; - FIMETADATA mdHandle = FreeImage.FindFirstMetadata(Model, dib, out tag); - if (!mdHandle.IsNull) - { - try - { - do - { - if (count++ == index) - { - break; - } - } - while (FreeImage.FindNextMetadata(mdHandle, out tag)); - } - finally - { - FreeImage.FindCloseMetadata(mdHandle); - } - } - return tag; - } - - /// - /// Returns the metadata tag at the given index. This operation is slow when accessing all tags. - /// - /// Index of the tag. - /// The metadata tag. - /// - /// is greater or equal Count - /// or index is less than zero. - public MetadataTag this[int index] - { - get - { - return GetTagFromIndex(index); - } - } - - /// - /// Retrieves an object that can iterate through the individual MetadataTags in this MetadataModel. - /// - /// An for the - /// . - public IEnumerator GetEnumerator() - { - return List.GetEnumerator(); - } - - /// - /// Returns the number of metadata tags this instance represents. - /// - public int Count - { - get { return (int)FreeImage.GetMetadataCount(Model, dib); } - } - - /// - /// Returns whether this model exists in the bitmaps metadata structure. - /// - public bool Exists - { - get - { - return Count > 0; - } - } - - /// - /// Searches for a pattern in each metadata tag and returns the result as a list. - /// - /// The regular expression to use for the search. - /// A bitfield that controls which fields should be searched in. - /// A list containing all found metadata tags. - /// - /// is null. - /// - /// is empty. - public List RegexSearch(string searchPattern, MD_SEARCH_FLAGS flags) - { - if (searchPattern == null) - { - throw new ArgumentNullException("searchString"); - } - if (searchPattern.Length == 0) - { - throw new ArgumentException("searchString is empty"); - } - List result = new List(Count); - Regex regex = new Regex(searchPattern); - List list = List; - foreach (MetadataTag tag in list) - { - if (((flags & MD_SEARCH_FLAGS.KEY) > 0) && regex.Match(tag.Key).Success) - { - result.Add(tag); - continue; - } - if (((flags & MD_SEARCH_FLAGS.DESCRIPTION) > 0) && regex.Match(tag.Description).Success) - { - result.Add(tag); - continue; - } - if (((flags & MD_SEARCH_FLAGS.TOSTRING) > 0) && regex.Match(tag.ToString()).Success) - { - result.Add(tag); - continue; - } - } - result.Capacity = result.Count; - return result; - } - - /// - /// Returns the value of the specified tag. - /// - /// Type of the tag's data. - /// The key of the tag. - /// The value of the specified tag. - protected T? GetTagValue(string key) where T : struct - { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - MetadataTag tag = GetTag(key); - if (tag != null) - { - T[] value = tag.Value as T[]; - if ((value != null) && (value.Length != 0)) - { - return value[0]; - } - } - return null; - } - - /// - /// Returns an array containing the data of the specified tag. - /// - /// The type of the tag's data. - /// The key of the tag. - /// An array containing the data of the specified tag. - protected T[] GetTagArray(string key) where T : struct - { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - MetadataTag tag = GetTag(key); - return (tag == null) ? null : tag.Value as T[]; - } - - /// - /// Returns the string contained by the specified tag. - /// - /// The key of the tag. - /// The string contained by the specified tag. - protected string GetTagText(string key) - { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - MetadataTag tag = GetTag(key); - return (tag == null) ? null : tag.Value as string; - } - - /// - /// Returns an array containg the data of the specified tag - /// as unsigned 32bit integer. - /// - /// The key of the tag. - /// An array containg the data of the specified tag - /// as unsigned 32bit integer. - protected uint[] GetUInt32Array(string key) - { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - uint[] result = null; - MetadataTag tag = GetTag(key); - if (tag != null) - { - object value = tag.Value; - if (value != null) - { - if (value is ushort[]) - { - ushort[] array = (ushort[])value; - result = new uint[array.Length]; - for (int i = 0, j = array.Length; i < j; i++) - { - result[i] = (uint)array[i]; - } - } - else if (value is uint[]) - { - result = (uint[])value; - } - } - } - return result; - } - - /// - /// Returns the value of the tag as unsigned 32bit integer. - /// - /// The key of the tag. - /// The value of the tag as unsigned 32bit integer. - protected uint? GetUInt32Value(string key) - { - uint[] value = GetUInt32Array(key); - return value == null ? default(uint?) : value[0]; - } - - /// - /// Sets the value of the specified tag. - /// - /// The type of the tag's data. - /// The key of the tag. - /// The new value of the specified tag or null. - protected void SetTagValue(string key, T? value) where T : struct - { - SetTagValue(key, value.HasValue ? new T[] { value.Value } : null); - } - - /// - /// Sets the value of the specified tag. - /// - /// The key of the tag. - /// The new value of the specified tag or null. - protected void SetTagValue(string key, object value) - { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - if (value == null) - { - RemoveTag(key); - } - else - { - MetadataTag tag = GetTag(key); - if (tag == null) - { - tag = new MetadataTag(Model); - tag.Key = key; - tag.Value = value; - AddTag(tag); - } - else - { - tag.Value = value; - } - } - } - - /// - /// Sets the value of the specified tag as undefined. - /// - /// The key of the tag. - /// The new value of the specified tag or null. - protected void SetTagValueUndefined(string key, byte[] value) - { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } - if (value == null) - { - RemoveTag(key); - } - else - { - MetadataTag tag = GetTag(key); - if (tag == null) - { - tag = new MetadataTag(Model); - tag.Key = key; - tag.SetValue(value, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED); - AddTag(tag); - } - else - { - tag.Value = value; - } - } - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The string containing the . - /// The equivalent for the - /// specified . - protected static DirectionReference? ToDirectionType(string s) - { - if (string.IsNullOrEmpty(s)) - return null; - switch (s[0]) - { - case 'T': - return DirectionReference.TrueDirection; - case 'M': - return DirectionReference.MagneticDirection; - default: - return DirectionReference.Undefined; - } - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The to convert. - /// The equivalent for the - /// specified . - protected static string ToString(DirectionReference? type) - { - if (type.HasValue) - { - switch (type.Value) - { - case DirectionReference.TrueDirection: - return "T"; - case DirectionReference.MagneticDirection: - return "M"; - default: - return "\0"; - } - } - return null; - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The string containing the . - /// The equivalent for the - /// specified . - protected static VelocityUnit? ToUnitType(string s) - { - if (string.IsNullOrEmpty(s)) - return null; - switch (s[0]) - { - case 'K': - return VelocityUnit.Kilometers; - case 'M': - return VelocityUnit.Miles; - case 'N': - return VelocityUnit.Knots; - default: - return VelocityUnit.Undefinied; - } - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The to convert. - /// The equivalent for the - /// specified . - protected static string ToString(VelocityUnit? type) - { - if (type.HasValue) - { - switch (type.Value) - { - case VelocityUnit.Kilometers: - return "K"; - case VelocityUnit.Miles: - return "M"; - case VelocityUnit.Knots: - return "N"; - default: - return "\0"; - } - } - return null; - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The string containing the . - /// The equivalent for the - /// specified . - protected static LongitudeType? ToLongitudeType(string s) - { - if (string.IsNullOrEmpty(s)) - return null; - switch (s[0]) - { - case 'E': - return LongitudeType.East; - case 'W': - return LongitudeType.West; - default: - return LongitudeType.Undefined; - } - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The to convert. - /// The equivalent for the - /// specified . - protected static string ToString(LongitudeType? type) - { - if (type.HasValue) - { - switch (type.Value) - { - case LongitudeType.East: - return "E"; - case LongitudeType.West: - return "W"; - default: - return "\0"; - } - } - return null; - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The string containing the . - /// The equivalent for the - /// specified . - protected static LatitudeType? ToLatitudeType(string s) - { - if (string.IsNullOrEmpty(s)) - return null; - switch (s[0]) - { - case 'N': - return LatitudeType.North; - case 'S': - return LatitudeType.South; - default: - return LatitudeType.Undefined; - } - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The to convert. - /// The equivalent for the - /// specified . - protected static string ToString(LatitudeType? type) - { - if (type.HasValue) - { - switch (type.Value) - { - case LatitudeType.North: - return "N"; - case LatitudeType.South: - return "S"; - default: - return "\0"; - } - } - return null; - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The string containing the . - /// The equivalent for the - /// specified . - protected static InteroperabilityMode? ToInteroperabilityType(string s) - { - if (string.IsNullOrEmpty(s)) - return null; - if (s.StartsWith("R98")) - return InteroperabilityMode.R98; - if (s.StartsWith("THM")) - return InteroperabilityMode.THM; - return InteroperabilityMode.Undefined; - } - - /// - /// Returns the equivalent for the - /// specified . - /// - /// The to convert. - /// The equivalent for the - /// specified . - protected static string ToString(InteroperabilityMode? type) - { - if (type.HasValue) - { - switch (type.Value) - { - case InteroperabilityMode.R98: - return "R98"; - case InteroperabilityMode.THM: - return "THM"; - default: - return "\0\0\0"; - } - } - return null; - } - - /// - /// Specified different unit types. - /// - public enum VelocityUnit - { - /// - /// No or unknown type. - /// - Undefinied, - - /// - /// Kilometers per hour. - /// - Kilometers, - - /// - /// Miles per hour. - /// - Miles, - - /// - /// Knots. - /// - Knots, - } - - /// - /// Specifies different direction types. - /// - public enum DirectionReference - { - /// - /// No or unknown direction type. - /// - Undefined, - - /// - /// True direction. - /// - TrueDirection, - - /// - /// Magnatic direction. - /// - MagneticDirection, - } - - /// - /// Specifies the type of a latitude value. - /// - public enum LatitudeType - { - /// - /// No or unknown type. - /// - Undefined, - - /// - /// North. - /// - North, - - /// - /// South. - /// - South, - } - - /// - /// Specifies the type of a longitude value. - /// - public enum LongitudeType - { - /// - /// No or unknown type. - /// - Undefined, - - /// - /// East. - /// - East, - - /// - /// West. - /// - West, - } - - /// - /// Specifies different altitude types. - /// - public enum AltitudeType - { - /// - /// No or unknown type. - /// - Undefined, - - /// - /// East. - /// - AboveSeaLevel, - - /// - /// West. - /// - BelowSeaLevel, - } - - /// - /// Specifies interoperability types. - /// - public enum InteroperabilityMode - { - /// - /// No or unknown type. - /// - Undefined, - - /// - /// Indicates a file conforming to R98 file specification of Recommended - /// Exif Interoperability Rules (ExifR98) or to DCF basic file stipulated - /// by Design Rule for Camera File System. - /// - R98, - - /// - /// Indicates a file conforming to DCF thumbnail file stipulated by Design - /// rule for Camera File System. - /// - THM, - } - - /// - /// Specifies orientation of images. - /// - public enum ExifImageOrientation : ushort - { - /// - /// Undefinied orientation. - /// - Undefined, - - /// - /// TopLeft. - /// - TopLeft = 1, - - /// - /// TopRight. - /// - TopRight, - - /// - /// BottomRight. - /// - BottomRight, - - /// - /// BottomLeft. - /// - BottomLeft, - - /// - /// LeftTop. - /// - LeftTop, - - /// - /// RightTop. - /// - RightTop, - - /// - /// RightBottom. - /// - RightBottom, - - /// - /// LeftBottom. - /// - LeftBottom, - } - - /// - /// Converts the model of the MetadataModel object to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - return Model.ToString(); - } - } -} - - #region Metadata Models - -namespace FreeImageAPI.Metadata -{ - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_ANIMATION : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_ANIMATION(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_ANIMATION; } - } - - /// - /// Gets or sets the width of the entire canvas area, that each page is displayed in. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? LogicalWidth - { - get - { - return GetTagValue("LogicalWidth"); - } - set - { - SetTagValue("LogicalWidth", value); - } - } - - /// - /// Gets or sets the height of the entire canvas area, that each page is displayed in. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? LogicalHeight - { - get - { - return GetTagValue("LogicalHeight"); - } - set - { - SetTagValue("LogicalHeight", value); - } - } - - /// - /// Gets or sets the global palette of the GIF image. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public Palette GlobalPalette - { - get - { - MetadataTag mdtag = GetTag("GlobalPalette"); - return (mdtag == null) ? null : new Palette(mdtag); - } - set - { - SetTagValue("GlobalPalette", (value != null) ? null : value.Data); - } - } - - /// - /// Gets or sets the number of replays for the animation. - /// Use 0 (zero) to specify an infinte number of replays. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? LoopCount - { - get - { - return GetTagValue("Loop"); - } - set - { - SetTagValue("Loop", value); - } - } - - /// - /// Gets or sets the horizontal offset within the logical canvas area, this frame is to be displayed at. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? FrameLeft - { - get - { - return GetTagValue("FrameLeft"); - } - set - { - SetTagValue("FrameLeft", value); - } - } - - /// - /// Gets or sets the vertical offset within the logical canvas area, this frame is to be displayed at. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? FrameTop - { - get - { - return GetTagValue("FrameTop"); - } - set - { - SetTagValue("FrameTop", value); - } - } - - /// - /// Gets or sets a flag to supress saving the dib's attached palette - /// (making it use the global palette). The local palette is the palette used by a page. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public bool? NoLocalPalette - { - get - { - byte? useGlobalPalette = GetTagValue("NoLocalPalette"); - return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?); - } - set - { - byte? val = null; - if (value.HasValue) - { - val = (byte)(value.Value ? 1 : 0); - } - SetTagValue("NoLocalPalette", val); - } - } - - /// - /// Gets or sets a value indicating whether the image is interlaced. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public bool? Interlaced - { - get - { - byte? useGlobalPalette = GetTagValue("Interlaced"); - return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?); - } - set - { - byte? val = null; - if (value.HasValue) - { - val = (byte)(value.Value ? 1 : 0); - } - SetTagValue("Interlaced", val); - } - } - - /// - /// Gets or sets the amout of time in milliseconds this frame is to be displayed. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? FrameTime - { - get - { - return GetTagValue("FrameTime"); - } - set - { - SetTagValue("FrameTime", value); - } - } - - /// - /// Gets or sets this frame's disposal method. Generally, this method defines, how to - /// remove or replace a frame when the next frame has to be drawn. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public DisposalMethodType? DisposalMethod - { - get - { - return GetTagValue("DisposalMethod"); - } - set - { - SetTagValue("DisposalMethod", value); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_COMMENTS : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_COMMENTS(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_COMMENTS; } - } - - /// - /// Gets or sets the comment of the image. - /// Supported formats are JPEG, PNG and GIF. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Comment - { - get - { - return GetTagText("Comment"); - } - set - { - SetTagValue("Comment", value); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_CUSTOM : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_CUSTOM(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_CUSTOM; } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_EXIF_EXIF : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_EXIF_EXIF(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF; } - } - - /// - /// Gets or sets the version of this standard supported. - /// Constant length or 4. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] ExifVersion - { - get - { - return GetTagArray("ExifVersion"); - } - set - { - FreeImage.Resize(ref value, 4); - SetTagValueUndefined("ExifVersion", value); - } - } - - /// - /// Gets or sets the Flashpix format version supported by a FPXR file. - /// Constant length or 4. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] FlashpixVersion - { - get - { - return GetTagArray("FlashpixVersion"); - } - set - { - FreeImage.Resize(ref value, 4); - SetTagValueUndefined("FlashpixVersion", value); - } - } - - /// - /// Gets or sets the color space information tag. - /// See remarks for further information. - /// - /// - /// The following values are defined: - /// - /// - /// ID - /// Description - /// - /// - /// 1 - /// sRGB (default) - /// - /// - /// 0xFFFF - /// uncalibrated - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? ColorSpace - { - get - { - return GetTagValue("ColorSpace"); - } - set - { - SetTagValue("ColorSpace", value); - } - } - - /// - /// Gets or sets the valid width of a compressed image. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? PixelXDimension - { - get - { - return GetUInt32Value("PixelXDimension"); - } - set - { - RemoveTag("PixelXDimension"); - if (value.HasValue) - { - SetTagValue("PixelXDimension", value.Value); - } - } - } - - /// - /// Gets or sets the valid height of a compressed image. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? PixelYDimension - { - get - { - return GetUInt32Value("PixelYDimension"); - } - set - { - RemoveTag("PixelYDimension"); - if (value.HasValue) - { - SetTagValue("PixelYDimension", value.Value); - } - } - } - - /// - /// Gets or sets components configuration. See remarks for further information. - /// Constant length of 4. - /// - /// - /// The channels of each component are arranged in order from the 1st component to the 4th. - /// For uncompressed data the data arrangement is given in the PhotometricInterpretation tag. - /// However, since PhotometricInterpretation can only express the order of Y,Cb and Cr, - /// this tag is provided for cases when compressed data uses components other than Y, Cb, - /// and Cr and to enable support of other sequences. - /// Default = 4 5 6 0 (if RGB uncompressed) - /// The following values are defined: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// does not exist - /// - /// - /// 1 - /// Y - /// - /// - /// 2 - /// Cb - /// - /// - /// 3 - /// Cr - /// - /// - /// 4 - /// R - /// - /// - /// 5 - /// R - /// - /// - /// 6 - /// R - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public byte[] ComponentsConfiguration - { - get - { - return GetTagArray("ComponentsConfiguration"); - } - set - { - FreeImage.Resize(ref value, 4); - SetTagValueUndefined("ComponentsConfiguration", value); - } - } - - /// - /// Gets or sets compression mode used for a compressed image is indicated - /// in unit bits per pixel. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? CompressedBitsPerPixel - { - get - { - return GetTagValue("CompressedBitsPerPixel"); - } - set - { - SetTagValue("CompressedBitsPerPixel", value); - } - } - - /// - /// Gets or sets a tag for manufacturers of Exif writers to record any desired information. - /// The contents are up to the manufacturer, but this tag should not be used for any other - /// than its intended purpose. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] MakerNote - { - get - { - return GetTagArray("FlashpixVersion"); - } - set - { - SetTagValueUndefined("FlashpixVersion", value); - } - } - - /// - /// Gets or sets a tag for Exif users to write keywords or comments on the image besides - /// those in ImageDescription, and without the character code limitations of the ImageDescription tag. - /// Minimum length of 8. See remarks for further information. - /// - /// - /// The character code used in the UserComment tag is identified based on an ID code in a fixed 8-byte - /// area at the start of the tag data area. The unused portion of the area is padded with NULL. - /// The ID code for the UserComment area may be a Defined code such as JIS or ASCII, or may be Undefined. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public byte[] UserComment - { - get - { - return GetTagArray("UserComment"); - } - set - { - FreeImage.Resize(ref value, 8, int.MaxValue); - SetTagValueUndefined("UserComment", value); - } - } - - /// - /// Gets or sets the name of an audio file related to the image data. - /// The format is 8.3. - /// Constant length of 12 - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string RelatedSoundFile - { - get - { - string text = GetTagText("RelatedSoundFile"); - if (!string.IsNullOrEmpty(text)) - { - text = text.Substring(0, text.Length - 1); - } - return text; - } - set - { - if (value != null) - { - FreeImage.Resize(ref value, 12); - value += '\0'; - } - SetTagValue("RelatedSoundFile", value); - } - } - - /// - /// Gets or sets the date and time when the original image data was generated. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public DateTime? DateTimeOriginal - { - get - { - DateTime? result = null; - string text = GetTagText("DateTimeOriginal"); - if (text != null) - { - try - { - result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null); - } - catch - { - } - } - return result; - } - set - { - string val = null; - if (value.HasValue) - { - try - { - val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0"); - } - catch - { - } - } - SetTagValue("DateTimeOriginal", val); - } - } - - /// - /// Gets or sets the date and time when the image was stored as digital data. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public DateTime? DateTimeDigitized - { - get - { - DateTime? result = null; - string text = GetTagText("DateTimeDigitized"); - if (text != null) - { - try - { - result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null); - } - catch - { - } - } - return result; - } - set - { - string val = null; - if (value.HasValue) - { - try - { - val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0"); - } - catch - { - } - } - SetTagValue("DateTimeDigitized", val); - } - } - - /// - /// Gets or sets a tag used to record fractions of seconds for the DateTime tag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SubsecTime - { - get - { - string text = GetTagText("SubsecTime"); - if (!string.IsNullOrEmpty(text)) - { - text = text.Substring(0, text.Length - 1); - } - return text; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("SubsecTime", value); - } - } - - /// - /// Gets or sets a tag used to record fractions of seconds for the DateTimeOriginal tag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SubsecTimeOriginal - { - get - { - string text = GetTagText("SubsecTimeOriginal"); - if (!string.IsNullOrEmpty(text)) - { - text = text.Substring(0, text.Length - 1); - } - return text; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("SubsecTimeOriginal", value); - } - } - - /// - /// Gets or sets a tag used to record fractions of seconds for the DateTimeDigitized tag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SubsecTimeDigitized - { - get - { - string text = GetTagText("SubsecTimeDigitized"); - if (!string.IsNullOrEmpty(text)) - { - text = text.Substring(0, text.Length - 1); - } - return text; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("SubsecTimeDigitized", value); - } - } - - /// - /// Gets or the exposure time, given in seconds (sec). - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? ExposureTime - { - get - { - return GetTagValue("ExposureTime"); - } - set - { - SetTagValue("ExposureTime", value); - } - } - - /// - /// Gets or the F number. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? FNumber - { - get - { - return GetTagValue("FNumber"); - } - set - { - SetTagValue("FNumber", value); - } - } - - /// - /// Gets or sets the class of the program used by the camera to set exposure when the - /// picture is taken. - /// See remarks for further information. - /// - /// - /// The following values are defined: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// not defined - /// - /// - /// 1 - /// manual - /// - /// - /// 2 - /// normal program - /// - /// - /// 3 - /// aperture priority - /// - /// - /// 4 - /// shutter priority - /// - /// - /// 5 - /// create program - /// - /// - /// 6 - /// action program - /// - /// - /// 7 - /// portrait mode - /// - /// - /// 8 - /// landscape mode - /// - /// - /// others - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? ExposureProgram - { - get - { - return GetTagValue("ExposureProgram"); - } - set - { - SetTagValue("ExposureProgram", value); - } - } - - /// - /// Gets or sets the spectral sensitivity of each channel of the camera used. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SpectralSensitivity - { - get - { - string text = GetTagText("SpectralSensitivity"); - if (!string.IsNullOrEmpty(text)) - { - text = text.Substring(0, text.Length - 1); - } - return text; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("SpectralSensitivity", value); - } - } - - /// - /// Gets or sets the the ISO Speed and ISO Latitude of the camera or input device as - /// specified in ISO 12232. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort[] ISOSpeedRatings - { - get - { - return GetTagArray("ISOSpeedRatings"); - } - set - { - SetTagValue("ISOSpeedRatings", value); - } - } - - /// - /// Gets or sets the Opto-Electric Conversion Function (OECF) specified in ISO 14524. - /// OECF is the relationship between the camera optical input and the image values. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] OECF - { - get - { - return GetTagArray("OECF"); - } - set - { - SetTagValueUndefined("OECF", value); - } - } - - /// - /// Gets or sets the shutter speed. The unit is the APEX (Additive System of Photographic Exposure). - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIRational? ShutterSpeedValue - { - get - { - return GetTagValue("ShutterSpeedValue"); - } - set - { - SetTagValue("ShutterSpeedValue", value); - } - } - - /// - /// Gets or sets the lens aperture. The unit is the APEX value. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? ApertureValue - { - get - { - return GetTagValue("ApertureValue"); - } - set - { - SetTagValue("ApertureValue", value); - } - } - - /// - /// Gets or sets the value of brightness. The unit is the APEX value. - /// Ordinarily it is given in the range of -99.99 to 99.99. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIRational? BrightnessValue - { - get - { - return GetTagValue("BrightnessValue"); - } - set - { - SetTagValue("BrightnessValue", value); - } - } - - /// - /// Gets or sets the exposure bias. The unit is the APEX value. - /// Ordinarily it is given in the range of �99.99 to 99.99. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIRational? ExposureBiasValue - { - get - { - return GetTagValue("ExposureBiasValue"); - } - set - { - SetTagValue("ExposureBiasValue", value); - } - } - - /// - /// Gets or sets the smallest F number of the lens. The unit is the APEX value. - /// Ordinarily it is given in the range of 00.00 to 99.99, - /// but it is not limited to this range. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? MaxApertureValue - { - get - { - return GetTagValue("MaxApertureValue"); - } - set - { - SetTagValue("MaxApertureValue", value); - } - } - - /// - /// Gets or sets distance to the subject, given in meters. - /// Note that if the numerator of the recorded value is FFFFFFFF, infinity shall be indicated; - /// and if the numerator is 0, distance unknown shall be indicated. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? SubjectDistance - { - get - { - return GetTagValue("SubjectDistance"); - } - set - { - SetTagValue("SubjectDistance", value); - } - } - - /// - /// Gets or sets the metering mode. See remarks for further information. - /// - /// - /// The following values are defined: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// unknown - /// - /// - /// 1 - /// average - /// - /// - /// 2 - /// center-weighted-average - /// - /// - /// 3 - /// spot - /// - /// - /// 4 - /// multi-spot - /// - /// - /// 5 - /// pattern - /// - /// - /// 6 - /// partial - /// - /// - /// other - /// reserved - /// - /// - /// 255 - /// other - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? MeteringMode - { - get - { - return GetTagValue("MeteringMode"); - } - set - { - SetTagValue("MeteringMode", value); - } - } - - /// - /// Gets or sets the kind of light source. - /// See remarks for further information. - /// - /// - /// The following values are defined: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// unknown - /// - /// - /// 1 - /// daylight - /// - /// - /// 2 - /// fluorescent - /// - /// - /// 3 - /// tungsten - /// - /// - /// 4 - /// flash - /// - /// - /// 9 - /// fine weather - /// - /// - /// 10 - /// cloudy weather - /// - /// - /// 11 - /// shade - /// - /// - /// 12 - /// daylight fluorecent (D 5700 - 7100K) - /// - /// - /// 13 - /// day white fluorescent (N 4600 - 5400K) - /// - /// - /// 14 - /// cool white fluorescent (W 3900 - 4500K) - /// - /// - /// 15 - /// white fluorescent (WW 3200 - 3700K) - /// - /// - /// 17 - /// standard light A - /// - /// - /// 18 - /// standard light B - /// - /// - /// 19 - /// standard light C - /// - /// - /// 20 - /// D55 - /// - /// - /// 21 - /// D65 - /// - /// - /// 22 - /// D75 - /// - /// - /// 23 - /// D50 - /// - /// - /// 24 - /// ISO studio tungsten - /// - /// - /// 255 - /// other light source - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? LightSource - { - get - { - return GetTagValue("LightSource"); - } - set - { - SetTagValue("LightSource", value); - } - } - - /// - /// Gets or sets a value indicating the status of flash when the image was shot. - /// Bit 0 indicates the flash firing status, bits 1 and 2 indicate the flash return - /// status, bits 3 and 4 indicate the flash mode, bit 5 indicates whether the flash - /// function is present, and bit 6 indicates "red eye" mode. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? Flash - { - get - { - return GetTagValue("Flash"); - } - set - { - SetTagValue("Flash", value); - } - } - - /// - /// Gets or sets a value indicating the location and area of the main subject in - /// the overall scene. Variable length between 2 and 4. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort[] SubjectArea - { - get - { - return GetTagArray("SubjectArea"); - } - set - { - FreeImage.Resize(ref value, 2, 4); - SetTagValue("SubjectArea", value); - } - } - - /// - /// Gets or sets the actual focal length of the lens, in mm. - /// Conversion is not made to the focal length of a 35 mm film camera. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? FocalLength - { - get - { - return GetTagValue("FocalLength"); - } - set - { - SetTagValue("FocalLength", value); - } - } - - /// - /// Gets or sets the strobe energy at the time the image is captured, - /// as measured in Beam Candle Power Seconds (BCPS). - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? FlashEnergy - { - get - { - return GetTagValue("FlashEnergy"); - } - set - { - SetTagValue("FlashEnergy", value); - } - } - - /// - /// Gets or sets the camera or input device spatial frequency table and SFR values - /// in the direction of image width, image height, and diagonal direction, - /// as specified in ISO 12233. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] SpatialFrequencyResponse - { - get - { - return GetTagArray("SpatialFrequencyResponse"); - } - set - { - SetTagValueUndefined("SpatialFrequencyResponse", value); - } - } - - /// - /// Gets or sets the number of pixels in the image width (X) direction per - /// FocalPlaneResolutionUnit on the camera focal plane. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? FocalPlaneXResolution - { - get - { - return GetTagValue("FocalPlaneXResolution"); - } - set - { - SetTagValue("FocalPlaneXResolution", value); - } - } - - /// - /// Gets or sets the number of pixels in the image height (Y) direction per - /// FocalPlaneResolutionUnit on the camera focal plane. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? FocalPlaneYResolution - { - get - { - return GetTagValue("FocalPlaneYResolution"); - } - set - { - SetTagValue("FocalPlaneYResolution", value); - } - } - - /// - /// Gets or sets the unit for measuring FocalPlaneXResolution and FocalPlaneYResolution. - /// This value is the same as the ResolutionUnit. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? FocalPlaneResolutionUnit - { - get - { - return GetTagValue("FocalPlaneResolutionUnit"); - } - set - { - SetTagValue("FocalPlaneResolutionUnit", value); - } - } - - /// - /// Gets or sets the location of the main subject in the scene. - /// The value of this tag represents the pixel at the center of the main subject - /// relative to the left edge, prior to rotation processing as per the Rotation tag. - /// The first value indicates the X column number and second indicates the Y row number. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? SubjectLocation - { - get - { - return GetTagValue("SubjectLocation"); - } - set - { - SetTagValue("SubjectLocation", value); - } - } - - /// - /// Gets or sets the exposure index selected on the camera or input device at the - /// time the image was captured. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? ExposureIndex - { - get - { - return GetTagValue("ExposureIndex"); - } - set - { - SetTagValue("ExposureIndex", value); - } - } - - /// - /// Gets or sets the image sensor type on the camera or input device. - /// See remarks for further information. - /// - /// - /// The following values are defined: - /// - /// - /// ID - /// Description - /// - /// - /// 1 - /// not defined - /// - /// - /// 2 - /// one-chip color area sensor - /// - /// - /// 3 - /// two-chip color area sensor - /// - /// - /// 4 - /// three-chip color area sensor - /// - /// - /// 5 - /// color sequential area sensor - /// - /// - /// 7 - /// trilinear sensor - /// - /// - /// 8 - /// color sequential linear sensor - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? SensingMethod - { - get - { - return GetTagValue("SensingMethod"); - } - set - { - SetTagValue("SensingMethod", value); - } - } - - /// - /// Gets or sets the image source. If a DSC recorded the image, this tag value of this - /// tag always be set to 3, indicating that the image was recorded on a DSC. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte? FileSource - { - get - { - return GetTagValue("FileSource"); - } - set - { - SetTagValueUndefined("FileSource", value.HasValue ? new byte[] { value.Value } : null); - } - } - - /// - /// Gets or sets the type of scene. If a DSC recorded the image, this tag value shall - /// always be set to 1, indicating that the image was directly photographed. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte? SceneType - { - get - { - return GetTagValue("SceneType"); - } - set - { - SetTagValueUndefined("SceneType", value.HasValue ? new byte[] { value.Value } : null); - } - } - - /// - /// Gets or sets the color filter array (CFA) geometric pattern of the image sensor - /// when a one-chip color area sensor is used. It does not apply to all sensing methods. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] CFAPattern - { - get - { - return GetTagArray("CFAPattern"); - } - set - { - SetTagValueUndefined("CFAPattern", value); - } - } - - /// - /// Gets or sets the use of special processing on image data, such as rendering geared to output. - /// When special processing is performed, the reader is expected to disable or minimize any - /// further processing. See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// normal process - /// - /// - /// 1 - /// custom process - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? CustomRendered - { - get - { - return GetTagValue("CustomRendered"); - } - set - { - SetTagValue("CustomRendered", value); - } - } - - /// - /// Gets or sets the exposure mode set when the image was shot. - /// In auto-bracketing mode, the camera shoots a series of frames of the same scene - /// at different exposure settings. See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// auto exposure - /// - /// - /// 1 - /// manual exposure - /// - /// - /// 2 - /// auto bracket - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? ExposureMode - { - get - { - return GetTagValue("ExposureMode"); - } - set - { - SetTagValue("ExposureMode", value); - } - } - - /// - /// Gets or sets the white balance mode set when the image was shot. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// auto white balance - /// - /// - /// 1 - /// manual white balance - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? WhiteBalance - { - get - { - return GetTagValue("WhiteBalance"); - } - set - { - SetTagValue("WhiteBalance", value); - } - } - - /// - /// Gets or sets the digital zoom ratio when the image was shot. - /// If the numerator of the recorded value is 0, this indicates that digital zoom was not used. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? DigitalZoomRatio - { - get - { - return GetTagValue("DigitalZoomRatio"); - } - set - { - SetTagValue("DigitalZoomRatio", value); - } - } - - /// - /// Gets or sets the equivalent focal length assuming a 35mm film camera, in mm. - /// A value of 0 means the focal length is unknown. Note that this tag differs - /// from the FocalLength tag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? FocalLengthIn35mmFilm - { - get - { - return GetTagValue("DigitalZoomRatio"); - } - set - { - SetTagValue("DigitalZoomRatio", value); - } - } - - /// - /// Gets or sets the type of scene that was shot. - /// It can also be used to record the mode in which the image was shot. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// standard - /// - /// - /// 1 - /// landscape - /// - /// - /// 2 - /// portrait - /// - /// - /// 3 - /// night scene - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? SceneCaptureType - { - get - { - return GetTagValue("SceneCaptureType"); - } - set - { - SetTagValue("SceneCaptureType", value); - } - } - - /// - /// Gets or sets the degree of overall image gain adjustment. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// none - /// - /// - /// 1 - /// low gain up - /// - /// - /// 2 - /// high gain up - /// - /// - /// 3 - /// low gain down - /// - /// - /// 4 - /// high gain down - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? GainControl - { - get - { - return GetTagValue("GainControl"); - } - set - { - SetTagValue("GainControl", value); - } - } - - /// - /// Gets or sets the direction of contrast processing applied by the camera - /// when the image was shot. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// normal - /// - /// - /// 1 - /// soft - /// - /// - /// 2 - /// hard - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? Contrast - { - get - { - return GetTagValue("Contrast"); - } - set - { - SetTagValue("Contrast", value); - } - } - - /// - /// Gets or sets the direction of saturation processing applied by the camera - /// when the image was shot. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// normal - /// - /// - /// 1 - /// low saturation - /// - /// - /// 2 - /// high saturation - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? Saturation - { - get - { - return GetTagValue("Saturation"); - } - set - { - SetTagValue("Saturation", value); - } - } - - /// - /// Gets or sets the direction of sharpness processing applied by the camera - /// when the image was shot. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// normal - /// - /// - /// 1 - /// soft - /// - /// - /// 2 - /// hard - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? Sharpness - { - get - { - return GetTagValue("Sharpness"); - } - set - { - SetTagValue("Sharpness", value); - } - } - - /// - /// Gets or sets information on the picture-taking conditions of a particular camera model. - /// The tag is used only to indicate the picture-taking conditions in the reader. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] DeviceSettingDescription - { - get - { - return GetTagArray("DeviceSettingDescription"); - } - set - { - SetTagValueUndefined("DeviceSettingDescription", value); - } - } - - /// - /// Gets or sets the distance to the subject. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 0 - /// unknown - /// - /// - /// 1 - /// macro - /// - /// - /// 2 - /// close view - /// - /// - /// 3 - /// distant view - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? SubjectDistanceRange - { - get - { - return GetTagValue("SubjectDistanceRange"); - } - set - { - SetTagValue("SubjectDistanceRange", value); - } - } - - /// - /// Gets or sets an identifier assigned uniquely to each image. - /// It is recorded as an ASCII string equivalent to hexadecimal notation and 128-bit fixed length. - /// Constant length of 32. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ImageUniqueID - { - get - { - string text = GetTagText("ImageUniqueID"); - if (!string.IsNullOrEmpty(text)) - { - text = text.Substring(0, text.Length - 1); - } - return text; - } - set - { - if (value != null) - { - FreeImage.Resize(ref value, 32); - value += '\0'; - } - SetTagValue("ImageUniqueID", value); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_EXIF_GPS : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_EXIF_GPS(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_GPS; } - } - - /// - /// Gets or sets the GPS version ID. Constant length of 4. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] VersionID - { - get - { - return GetTagArray("GPSVersionID"); - } - set - { - FreeImage.Resize(ref value, 4); - SetTagValue("GPSVersionID", value); - } - } - - /// - /// Gets or sets a value indicating whether the - /// is north or south latitude. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public LatitudeType? LatitudeDirection - { - get - { - return ToLatitudeType(GetTagText("GPSLatitudeRef")); - } - set - { - SetTagValue("GPSLatitudeRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the latitude of the image. The latitude is expressed as three rational - /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public FIURational[] Latitude - { - get - { - return GetTagArray("GPSLatitude"); - } - set - { - FreeImage.Resize(ref value, 3); - SetTagValue("GPSLatitude", value); - } - } - - /// - /// Gets or sets a value indicating whether - /// is east or west longitude. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public LongitudeType? LongitudeDirection - { - get - { - return ToLongitudeType(GetTagText("GPSLongitudeRef")); - } - set - { - SetTagValue("GPSLongitudeRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the longitude of the image. The longitude is expressed as three rational - /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public FIURational[] Longitude - { - get - { - return GetTagArray("GPSLongitude"); - } - set - { - FreeImage.Resize(ref value, 3); - SetTagValue("GPSLongitude", value); - } - } - - /// - /// Gets a value indicating whether is sea level and the altitude - /// is above sea level. If the altitude is below sea level is - /// indicated as an absolute value. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public AltitudeType? AltitudeDirection - { - get - { - byte? flag = GetTagValue("GPSAltitudeRef"); - if (flag.HasValue) - { - switch (flag.Value) - { - case 0: - return AltitudeType.AboveSeaLevel; - case 1: - return AltitudeType.BelowSeaLevel; - default: - return AltitudeType.Undefined; - } - } - return null; - } - set - { - byte? val = null; - if (value.HasValue) - { - switch (value.Value) - { - case AltitudeType.AboveSeaLevel: - val = 0; - break; - - case AltitudeType.BelowSeaLevel: - val = 1; - break; - - default: - val = 2; - break; - } - } - SetTagValue("GPSAltitudeRef", val); - } - } - - /// - /// Gets or sets the altitude based on the reference in . - /// Altitude is expressed as one rational value. The reference unit is meters. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? Altitude - { - get - { - return GetTagValue("GPSAltitude"); - } - set - { - SetTagValue("GPSAltitude", value); - } - } - - /// - /// Gets or sets the sign of the . - /// - /// - /// This is a derived property. There is no metadata tag directly associated - /// with this property value. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public int? AltitudeSign - { - get - { - AltitudeType? seaLevel = AltitudeDirection; - if (seaLevel.HasValue) - { - return (seaLevel.Value == AltitudeType.BelowSeaLevel) ? -1 : 1; - } - return null; - } - set - { - if (value.HasValue) - { - AltitudeDirection = value.Value >= 0 ? AltitudeType.AboveSeaLevel : AltitudeType.BelowSeaLevel; - } - else - { - AltitudeDirection = null; - } - } - } - - /// - /// Gets or sets the signed altitude. - /// Altitude is expressed as one rational value. The reference unit is meters. - /// - /// - /// Altitude is too large to fit into a FIRational. - /// - /// - /// This is a derived property. There is no metadata tag directly associated - /// with this property value. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public FIRational? SignedAltitude - { - get - { - FIRational? result = null; - FIURational? altitude = Altitude; - if (altitude.HasValue) - { - int sign = AltitudeSign ?? 1; - if (((int)altitude.Value.Numerator < 0) || ((int)altitude.Value.Denominator < 0)) - throw new OverflowException(); - result = new FIRational((int)altitude.Value.Numerator * sign, (int)altitude.Value.Denominator); - } - return result; - } - set - { - FIURational? val = null; - if (value.HasValue) - { - if (value.Value < 0) - { - AltitudeSign = -1; - value = -value.Value; - } - else - { - AltitudeSign = 1; - } - val = new FIURational((uint)value.Value.Numerator, (uint)value.Value.Denominator); - } - Altitude = val; - } - } - - - /// - /// Gets or sets the time as UTC (Coordinated Universal Time). Constant length of 3. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public TimeSpan? TimeStamp - { - get - { - FIURational[] stamp = GetTagArray("GPSTimeStamp"); - if ((stamp == null) || stamp.Length != 3) - { - return null; - } - else - { - return new TimeSpan((int)stamp[0], (int)stamp[1], (int)stamp[2]); - } - } - set - { - FIURational[] stamp = null; - if (value.HasValue) - { - TimeSpan span = value.Value; - stamp = new FIURational[3]; - stamp[0] = span.Hours; - stamp[1] = span.Minutes; - stamp[2] = span.Seconds; - } - SetTagValue("GPSTimeStamp", stamp); - } - } - - /// - /// Gets or sets the GPS satellites used for measurements. This tag can be used to describe - /// the number of satellites, their ID number, angle of elevation, azimuth, SNR and other - /// information in ASCII notation. The format is not specified. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Satellites - { - get - { - string result = GetTagText("GPSSatellites"); - if (!string.IsNullOrEmpty(result)) - { - result = result.Substring(0, result.Length - 1); - } - return result; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("GPSTimeStamp", value); - } - } - - /// - /// Gets or sets a value indicating the status of the GPS receiver when the image was recorded. - /// true indicates measurement was in progress; - /// false indicates measurement was Interoperability. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public bool? Status - { - get - { - string text = GetTagText("GPSStatus"); - return string.IsNullOrEmpty(text) ? default(bool?) : text[0] == 'A'; - } - set - { - SetTagValue("GPSStatus", value.HasValue ? (value.Value ? "A\0" : "V\0") : null); - } - } - - /// - /// Gets or sets a value indicating the GPS measurement mode. - /// true indicates three-dimensional measurement; - /// false indicated two-dimensional measurement was in progress. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public bool? MeasureMode3D - { - get - { - string text = GetTagText("GPSMeasureMode"); - return string.IsNullOrEmpty(text) ? default(bool?) : text[0] == '3'; - } - set - { - SetTagValue("GPSMeasureMode", value.HasValue ? (value.Value ? "3\0" : "2\0") : null); - } - } - - /// - /// Gets or sets the GPS DOP (data degree of precision). An HDOP value is written during - /// two-dimensional measurement, and PDOP during three-dimensional measurement. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? DOP - { - get - { - return GetTagValue("GPSDOP"); - } - set - { - SetTagValue("GPSDOP", value); - } - } - - /// - /// Gets or sets the unit used to express the GPS receiver of movement. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public VelocityUnit? SpeedUnit - { - get - { - return ToUnitType(GetTagText("GPSSpeedRef")); - } - set - { - SetTagValue("GPSSpeedRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the speed of GPS receiver movement. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public FIURational? Speed - { - get - { - return GetTagValue("GPSSpeed"); - } - set - { - SetTagValue("GPSSpeed", value); - } - } - - /// - /// Gets or sets the reference for giving the direction of GPS receiver movement. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public DirectionReference? TrackDirectionReference - { - get - { - return ToDirectionType(GetTagText("GPSTrackRef")); - } - set - { - SetTagValue("GPSTrackRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the direction of GPS receiver movement. - /// The range of values is from 0.00 to 359.99. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public FIURational? Track - { - get - { - return GetTagValue("GPSTrack"); - } - set - { - SetTagValue("GPSTrack", value); - } - } - - /// - /// Gets or sets the reference for giving the direction of GPS receiver movement. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public DirectionReference? ImageDirectionReference - { - get - { - return ToDirectionType(GetTagText("GPSImgDirectionRef")); - } - set - { - SetTagValue("GPSImgDirectionRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the direction of the image when it was captured. - /// The range of values is from 0.00 to 359.99. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public FIURational? ImageDirection - { - get - { - return GetTagValue("GPSImgDirection"); - } - set - { - SetTagValue("GPSImgDirection", value); - } - } - - /// - /// Gets or sets the geodetic survey data used by the GPS receiver. If the survey data - /// is restricted to Japan, the value of this tag is 'TOKYO' or 'WGS-84'. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string MapDatum - { - get - { - string result = GetTagText("GPSMapDatum"); - if (!string.IsNullOrEmpty(result)) - { - result = result.Substring(0, result.Length - 1); - } - return result; - } - set - { - SetTagValue("GPSMapDatum", value + '\0'); - } - } - - /// - /// Gets or sets a value indicating whether the destination point - /// is north or south latitude. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public LatitudeType? DestinationLatitudeDirection - { - get - { - return ToLatitudeType(GetTagText("GPSDestLatitudeRef")); - } - set - { - SetTagValue("GPSDestLatitudeRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the latitude of the destination point. The latitude is expressed as three rational - /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public FIURational[] DestinationLatitude - { - get - { - return GetTagArray("GPSDestLatitude"); - } - set - { - FreeImage.Resize(ref value, 3); - SetTagValue("GPSDestLatitude", value); - } - } - - /// - /// Gets or sets a value indicating whether the destination point - /// is east or west longitude. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public LongitudeType? DestinationLongitudeDirection - { - get - { - return ToLongitudeType(GetTagText("GPSDestLongitudeRef")); - } - set - { - SetTagValue("GPSDestLongitudeRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the longitude of the destination point. The longitude is expressed as three rational - /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational[] DestinationLongitude - { - get - { - return GetTagArray("GPSDestLongitude"); - } - set - { - FreeImage.Resize(ref value, 3); - SetTagValue("GPSDestLongitude", value); - } - } - - /// - /// Gets or sets the reference used for giving the bearing to the destination point. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public DirectionReference? DestinationDirectionReference - { - get - { - return ToDirectionType(GetTagText("GPSDestBearingRef")); - } - set - { - SetTagValue("GPSDestBearingRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets the bearing to the destination point. - /// The range of values is from 0.00 to 359.99. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public FIURational? DestinationBearing - { - get - { - return GetTagValue("GPSDestBearing"); - } - set - { - SetTagValue("GPSDestBearing", value); - } - } - - /// - /// Gets or sets the unit used to express the distance to the destination point. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public VelocityUnit? DestinationUnit - { - get - { - return ToUnitType(GetTagText("GPSDestDistanceRef")); - } - set - { - SetTagValue("GPSDestDistanceRef", ToString(value) + '\0'); - } - } - - /// - /// Gets or sets a character string recording the name of the method used - /// for location finding. The first byte indicates the character code used, - /// and this is followed by the name of the method. Since the Type is not ASCII, - /// NULL termination is not necessary. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] ProcessingMethod - { - get - { - return GetTagArray("GPSProcessingMethod"); - } - set - { - SetTagValue("GPSProcessingMethod", value); - } - } - - /// - /// Gets or sets a character string recording the name of the GPS area. - /// The first byte indicates the character code used, and this is followed by - /// the name of the GPS area. Since the Type is not ASCII, NULL termination is - /// not necessary. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public byte[] AreaInformation - { - get - { - return GetTagArray("GPSAreaInformation"); - } - set - { - SetTagValue("GPSAreaInformation", value); - } - } - - /// - /// Gets or sets date and time information relative to UTC (Coordinated Universal Time). - /// - /// - /// This is a derived property. There is no metadata tag directly associated - /// with this property value. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public DateTime? DateTimeStamp - { - get - { - DateTime? date = DateStamp; - TimeSpan? time = TimeStamp; - if ((date == null) && (time == null)) - { - return null; - } - else - { - if (date == null) - { - date = DateTime.MinValue; - } - if (time == null) - { - time = TimeSpan.MinValue; - } - return date.Value.Add(time.Value); - } - } - set - { - if (value.HasValue) - { - DateStamp = value.Value.Date; - TimeStamp = value.Value.TimeOfDay; - } - else - { - DateStamp = null; - TimeStamp = null; - } - } - } - - /// - /// Gets or sets date information relative to UTC (Coordinated Universal Time). - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public DateTime? DateStamp - { - get - { - string stamp = GetTagText("GPSDateStamp"); - if (stamp != null) - { - try - { - return DateTime.ParseExact(stamp, "yyyy:MM:dd\0", null); - } - catch - { - } - } - return null; - } - set - { - string val = null; - if (value.HasValue) - { - try - { - val = value.Value.ToString("yyyy:MM:dd\0"); - } - catch - { - } - } - SetTagValue("GPSDateStamp", val); - } - } - - /// - /// Gets or sets a value indicating whether differential correction was applied to - /// the GPS receiver. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public bool? IsDifferential - { - get - { - ushort? value = GetTagValue("GPSDifferential"); - return value.HasValue ? (value != 0) : (default(bool?)); - } - set - { - SetTagValue("GPSDifferential", value.HasValue ? (object)(value.Value ? (ushort)1 : (ushort)0) : (null)); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_INTEROP : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_INTEROP(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_INTEROP; } - } - - /// - /// Gets or sets the identification of the Interoperability rule. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public InteroperabilityMode? Identification - { - get - { - return ToInteroperabilityType(GetTagText("InteroperabilityIndex")); - } - set - { - SetTagValue("InteroperabilityIndex", ToString(value) + '\0'); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - /// This class is obsolete. Use class instead. - /// - [Obsolete("To be removed in future releases. Use MDM_EXIF_MAIN instead.")] - public class MDM_MAIN : MDM_EXIF_MAIN - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_MAIN(FIBITMAP dib) : base(dib) { } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_EXIF_MAIN : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_EXIF_MAIN(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN; } - } - - /// - /// Gets or sets the number of columns of image data, equal to the number - /// of pixels per row. In JPEG compressed data a JPEG marker is used - /// instead of this tag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? ImageWidth - { - get - { - return GetUInt32Value("ImageWidth"); - } - set - { - RemoveTag("ImageWidth"); - if (value.HasValue) - { - SetTagValue("ImageWidth", value); - } - } - } - - /// - /// Gets or sets number of rows of image data. In JPEG compressed data a JPEG marker - /// is used instead of this tag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? ImageHeight - { - get - { - return GetUInt32Value("ImageLength"); - } - set - { - RemoveTag("ImageLength"); - if (value.HasValue) - { - SetTagValue("ImageLength", value); - } - } - } - - /// - /// Gets or sets number of bits per image component. In this standard - /// each component of the image is 8 bits, so the value for this tag is 8. - /// Constant length of 3. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort[] BitsPerSample - { - get - { - return GetTagArray("BitsPerSample"); - } - set - { - FreeImage.Resize(ref value, 3); - SetTagValue("BitsPerSample", value); - } - } - - /// - /// Gets or sets compression scheme used for the image data. When a primary image - /// is JPEG compressed, this designation is not necessary and is omitted. - /// When thumbnails use JPEG compression, this tag value is set to 6. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? Compression - { - get - { - return GetTagValue("Compression"); - } - set - { - SetTagValue("Compression", value); - } - } - - /// - /// Gets or sets pixel composition. In JPEG compressed data a JPEG marker is - /// used instead of this tag. See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 2 - /// RGB - /// - /// - /// 6 - /// YCbCr - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? PhotometricInterpretation - { - get - { - return GetTagValue("PhotometricInterpretation"); - } - set - { - SetTagValue("PhotometricInterpretation", value); - } - } - - /// - /// Gets or sets the image orientation viewed in terms of rows and columns. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ExifImageOrientation? Orientation - { - get - { - return (ExifImageOrientation?)GetTagValue("Orientation"); - } - set - { - SetTagValue("Orientation", (ushort?)value); - } - } - - /// - /// Gets or sets the number of components per pixel. Since this standard applies - /// to RGB and YCbCr images, the value set for this tag is 3. In JPEG compressed - /// data a JPEG marker is used instead of this tag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort? SamplesPerPixel - { - get - { - return GetTagValue("SamplesPerPixel"); - } - set - { - SetTagValue("SamplesPerPixel", value); - } - } - - /// - /// Gets or sets a value that indicates whether pixel components are recorded in - /// chunky or planar format. In JPEG compressed files a JPEG marker is used instead - /// of this tag. If this field does not exist, the TIFF default of 1 (chunky) is assumed. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 1 - /// chunky format - /// - /// - /// 2 - /// planar format - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? PlanarConfiguration - { - get - { - return GetTagValue("PlanarConfiguration"); - } - set - { - SetTagValue("PlanarConfiguration", value); - } - } - - /// - /// Gets or sets the sampling ratio of chrominance components in relation to - /// the luminance component. In JPEG compressed dat a JPEG marker is used - /// instead of this tag. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// [2,1] - /// YCbCr4:2:2 - /// - /// - /// [2,2] - /// YCbCr4:2:0 - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort[] YCbCrSubSampling - { - get - { - return GetTagArray("YCbCrSubSampling"); - } - set - { - FreeImage.Resize(ref value, 2); - SetTagValue("YCbCrSubSampling", value); - } - } - - /// - /// Gets or sets position of chrominance components in relation to the luminance component. - /// See remarks for further information. - /// - /// - /// This field is designated only for JPEG compressed data or uncompressed YCbCr data. - /// The TIFF default is 1 (centered); but when Y:Cb:Cr = 4:2:2 it is recommended in - /// this standard that 2 (co-sited) be used to record data, in order to improve the - /// image quality when viewed on TV systems. - /// - /// When this field does not exist, the reader shall assume the TIFF default. - /// In the case of Y:Cb:Cr = 4:2:0, the TIFF default (centered) is recommended. - /// If the reader does not have the capability of supporting both kinds of YCbCrPositioning, - /// it shall follow the TIFF default regardless of the value in this field. - /// It is preferable that readers be able to support both centered and co-sited positioning. - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 1 - /// centered - /// - /// - /// 2 - /// co-sited - /// - /// - /// other - /// reserved - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? YCbCrPositioning - { - get - { - return GetTagValue("YCbCrPositioning"); - } - set - { - SetTagValue("YCbCrPositioning", value); - } - } - - /// - /// Gets or sets the number of pixels per - /// in the direction. When the image resolution is unknown, - /// 72 [dpi] is designated. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? XResolution - { - get - { - return GetTagValue("XResolution"); - } - set - { - SetTagValue("XResolution", value); - } - } - - /// - /// Gets or sets the number of pixels per - /// in the direction. When the image resolution is unknown, - /// 72 [dpi] is designated. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational? YResolution - { - get - { - return GetTagValue("YResolution"); - } - set - { - SetTagValue("YResolution", value); - } - } - - /// - /// Gets or sets the unit for measuring and . - /// The same unit is used for both and . - /// If the image resolution in unknown, 2 (inches) is designated. - /// See remarks for further information. - /// - /// - /// The following values are definied: - /// - /// - /// ID - /// Description - /// - /// - /// 2 - /// inches - /// - /// - /// 3 - /// YCbCr4:2:0 - /// - /// - /// other - /// centimeters - /// - /// - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort? ResolutionUnit - { - get - { - return GetTagValue("ResolutionUnit"); - } - set - { - SetTagValue("ResolutionUnit", value); - } - } - - /// - /// Gets or sets the byte offset of that strip. - /// It is recommended that this be selected so the number of strip bytes - /// does not exceed 64 Kbytes. - /// With JPEG compressed data this designation is not needed and is omitted. - /// Constant length of * StripsPerImage. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - /// - public uint[] StripOffsets - { - get - { - return GetUInt32Array("StripOffsets"); - } - set - { - RemoveTag("StripOffsets"); - if (value != null) - { - SetTagValue("StripOffsets", value); - } - } - } - - /// - /// Gets or sets number of rows per strip. This is the number of rows in the image of - /// one strip when an image is divided into strips. With JPEG compressed data this - /// designation is not needed and is omitted. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - /// - public uint? RowsPerStrip - { - get - { - return GetUInt32Value("RowsPerStrip"); - } - set - { - RemoveTag("RowsPerStrip"); - if (value.HasValue) - { - SetTagValue("RowsPerStrip", value); - } - } - } - - /// - /// Gets or sets the total number of bytes in each strip. - /// With JPEG compressed data this designation is not needed and is omitted. - /// Constant length of * StripsPerImage. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint[] StripByteCounts - { - get - { - return GetUInt32Array("StripByteCounts"); - } - set - { - RemoveTag("StripByteCounts"); - if (value != null) - { - SetTagValue("StripByteCounts", value); - } - } - } - - /// - /// Gets or sets the offset to the start byte (SOI) of JPEG compressed thumbnail data. - /// This is not used for primary image JPEG data. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? JPEGInterchangeFormat - { - get - { - return GetTagValue("JPEGInterchangeFormat"); - } - set - { - SetTagValue("JPEGInterchangeFormat", value); - } - } - - /// - /// Gets or sets the number of bytes of JPEG compressed thumbnail data. - /// - /// - /// This is not used for primary image JPEG data. - /// JPEG thumbnails are not divided but are recorded as a continuous - /// JPEG bitstream from SOI to EOI. APPn and COM markers should not be recorded. - /// Compressed thumbnails shall be recorded in no more than 64 Kbytes, - /// including all other data to be recorded in APP1. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public uint? JPEGInterchangeFormatLength - { - get - { - return GetTagValue("JPEGInterchangeFormatLength"); - } - set - { - SetTagValue("JPEGInterchangeFormatLength", value); - } - } - - /// - /// Gets or sets a transfer function for the image, described in tabular style. - /// Constant length of 3 * 256. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public ushort[] TransferFunction - { - get - { - return GetTagArray("TransferFunction"); - } - set - { - FreeImage.Resize(ref value, 3 * 256); - SetTagValue("TransferFunction", value); - } - } - - /// - /// Gets or sets the chromaticity of the white point of the image. - /// Constant length of 2. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational[] WhitePoint - { - get - { - return GetTagArray("WhitePoint"); - } - set - { - FreeImage.Resize(ref value, 2); - SetTagValue("WhitePoint", value); - } - } - - /// - /// Gets or sets the chromaticity of the three primary colors of the image. - /// Constant length of 6. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational[] PrimaryChromaticities - { - get - { - return GetTagArray("PrimaryChromaticities"); - } - set - { - FreeImage.Resize(ref value, 6); - SetTagValue("PrimaryChromaticities", value); - } - } - - /// - /// Gets or sets the matrix coefficients for transformation from RGB to YCbCr image data. - /// Constant length of 3. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational[] YCbCrCoefficients - { - get - { - return GetTagArray("YCbCrCoefficients"); - } - set - { - FreeImage.Resize(ref value, 3); - SetTagValue("PrimaryChromaticities", value); - } - } - - /// - /// Gets or sets the reference black point value and reference white point value. - /// Constant length of 6. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public FIURational[] ReferenceBlackWhite - { - get - { - return GetTagArray("ReferenceBlackWhite"); - } - set - { - FreeImage.Resize(ref value, 6); - SetTagValue("ReferenceBlackWhite", value); - } - } - - /// - /// Gets or sets the date and time of image creation. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public DateTime? DateTime - { - get - { - DateTime? result = null; - string text = GetTagText("DateTime"); - if (text != null) - { - try - { - result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null); - } - catch - { - } - } - return result; - } - set - { - string val = null; - if (value.HasValue) - { - try - { - val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0"); - } - catch - { - } - } - SetTagValue("DateTime", val); - } - } - - /// - /// Gets or sets a string giving the title of the image. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ImageDescription - { - get - { - string result = GetTagText("ImageDescription"); - if (!string.IsNullOrEmpty(result)) - { - result = result.Substring(0, result.Length - 1); - } - return result; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("ImageDescription", value); - } - } - - /// - /// Gets or sets the manufacturer of the recording equipment. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Make - { - get - { - string result = GetTagText("Make"); - if (!string.IsNullOrEmpty(result)) - { - result = result.Substring(0, result.Length - 1); - } - return result; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("Make", value); - } - } - - /// - /// Gets or sets the model name or model number of the equipment. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string EquipmentModel - { - get - { - string result = GetTagText("Model"); - if (!string.IsNullOrEmpty(result)) - { - result = result.Substring(0, result.Length - 1); - } - return result; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("Model", value); - } - } - - /// - /// Gets or sets the name and version of the software or firmware of the camera - /// or image input device used to generate the image. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Software - { - get - { - string result = GetTagText("Software"); - if (!string.IsNullOrEmpty(result)) - { - result = result.Substring(0, result.Length - 1); - } - return result; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("Software", value); - } - } - - /// - /// Gets or sets the name of the camera owner, photographer or image creator. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Artist - { - get - { - string result = GetTagText("Artist"); - if (!string.IsNullOrEmpty(result)) - { - result = result.Substring(0, result.Length - 1); - } - return result; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("Artist", value); - } - } - - /// - /// Gets or sets the photographer and editor copyrights. - /// Constant length of 1-2. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string[] Copyright - { - get - { - string[] result = null; - string text = GetTagText("Copyright"); - if (!string.IsNullOrEmpty(text)) - { - result = text.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); - } - return result; - } - set - { - string val = null; - if (value != null) - { - if (value.Length == 1) - { - if (value[0] != null) - { - val = value[0] + '\0'; - } - } - else if (value.Length == 2) - { - if ((value[0] != null) && (value[1] != null)) - { - val = value[0] + '\0' + value[1] + '\0'; - } - } - } - SetTagValue("Copyright", val); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_MAKERNOTE : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_MAKERNOTE(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_MAKERNOTE; } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_GEOTIFF : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_GEOTIFF(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_GEOTIFF; } - } - - /// - /// Gets or sets the value of the GeoTIFF GeoASCIIParamsTag. - /// - /// - /// The GeoASCIIParamsTag is used to store all of the valued - /// GeoKeys, referenced by the property. Since keys - /// defined in the GeoKeyDirectoryTag use offsets into this tag, any special - /// comments may be placed at the beginning of this tag. - /// For the most part, the only keys that are valued are - /// Citation keys, giving documentation and references for obscure - /// projections, datums, etc. - /// - /// Special handling is required for -valued keys. While it - /// is true that TIFF 6.0 permits multiple NULL-delimited strings within a single - /// ASCII tag, the secondary strings might not appear in the output of naive - /// tiffdump programs. For this reason, the NULL delimiter of each ASCII key - /// value shall be converted to a "|" (pipe) character before being installed - /// back into the holding tag, so that a dump of the tag - /// will look like this. - /// - /// AsciiTag="first_value|second_value|etc...last_value|" - /// - /// A baseline GeoTIFF-reader must check for and convert the final "|" pipe - /// character of a key back into a NULL before returning it to the client - /// software. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public string GeoASCIIParams - { - get - { - string text = GetTagText("GeoASCIIParams"); - if (!string.IsNullOrEmpty(text)) - { - text = text.Substring(0, text.Length - 1); - } - return text; - } - set - { - if (value != null) - { - value += '\0'; - } - SetTagValue("GeoASCIIParams", value); - } - } - - /// - /// Gets or sets the value of the GeoTIFF GeoDoubleParamsTag. - /// - /// - /// The GeoDoubleParamsTag is used to store all of the valued - /// GeoKeys, referenced by the property. The meaning of - /// any value of this double array is determined from the GeoKeyDirectoryTag reference - /// pointing to it. values should first be converted to - /// and stored here. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public double[] GeoDoubleParams - { - get - { - return GetTagArray("GeoDoubleParams"); - } - set - { - SetTagValue("GeoDoubleParams", value); - } - } - - /// - /// Gets or sets the value of the GeoTIFF GeoKeyDirectoryTag. - /// - /// - /// The GeoKeyDirectoryTag may be used to store the GeoKey Directory, which defines and - /// references the GeoKeys. - /// - /// The tag is an array of unsigned values, which are primarily - /// grouped into blocks of 4. The first 4 values are special, and contain GeoKey directory - /// header information. The header values consist of the following information, in order: - /// - /// Header={KeyDirectoryVersion, KeyRevision, MinorRevision, NumberOfKeys} - /// - /// where - /// - /// KeyDirectoryVersion indicates the current version of Key implementation, and will - /// only change if this Tag's Key structure is changed. (Similar to the TIFFVersion (42)). - /// The current DirectoryVersion number is 1. This value will most likely never change, - /// and may be used to ensure that this is a valid Key-implementation. - /// - /// KeyRevision indicates what revision of Key-Sets are used. - /// - /// MinorRevision indicates what set of Key-Codes are used. The complete revision number - /// is denoted <KeyRevision>.<MinorRevision>. - /// - /// NumberOfKeys indicates how many Keys are defined by the rest of this Tag. - /// - /// This header is immediately followed by a collection of <NumberOfKeys> KeyEntry - /// sets, each of which is also 4- long. Each KeyEntry is modeled on the - /// TIFFEntry format of the TIFF directory header, and is of the form: - /// - /// KeyEntry = { KeyID, TIFFTagLocation, Count, Value_Offset } - /// - /// where - /// - /// KeyID gives the Key-ID value of the Key (identical in function to TIFF tag ID, - /// but completely independent of TIFF tag-space), - /// - /// TIFFTagLocation indicates which TIFF tag contains the value(s) of the Key: if - /// TIFFTagLocation is 0, then the value is , and is contained in the - /// Value_Offset entry. Otherwise, the type (format) of the value is implied by the - /// TIFF-Type of the tag containing the value. - /// - /// Count indicates the number of values in this key. - /// - /// Value_Offset Value_Offset indicates the index-offset into the TagArray indicated - /// by TIFFTagLocation, if it is nonzero. If TIFFTagLocation is 0 (zero) , then Value_Offset - /// contains the actual () value of the Key, and Count=1 is implied. - /// Note that the offset is not a byte-offset, but rather an index based on the natural data - /// type of the specified tag array. - /// - /// Following the KeyEntry definitions, the KeyDirectory tag may also contain additional - /// values. For example, if a key requires multiple values, they shall - /// be placed at the end of this tag, and the KeyEntry will set - /// TIFFTagLocation=GeoKeyDirectoryTag, with the Value_Offset pointing to the location of the - /// value(s). - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public ushort[] GeoKeyDirectory - { - get - { - return GetTagArray("GeoKeyDirectory"); - } - set - { - SetTagValue("GeoKeyDirectory", value); - } - } - - /// - /// Gets or sets the value of the GeoTIFF ModelPixelScaleTag. - /// - /// - /// The ModelPixelScaleTag tag may be used to specify the size of raster pixel spacing - /// in the model space units, when the raster space can be embedded in the model space - /// coordinate system without rotation, and consists of the following 3 values: - /// - /// ModelPixelScaleTag = (ScaleX, ScaleY, ScaleZ) - /// - /// where ScaleX and ScaleY give the horizontal and vertical spacing of - /// raster pixels. The ScaleZ is primarily used to map the pixel value of a - /// digital elevation model into the correct Z-scale, and so for most other purposes - /// this value should be zero (since most model spaces are 2-D, with Z=0). - /// - /// A single tiepoint in the tag, together with this tag, - /// completely determine the relationship between raster and model space; thus they - /// comprise the two tags which Baseline GeoTIFF files most often will use to place a - /// raster image into a "standard position" in model space. - /// - /// Like the tag, this tag information is independent of the - /// XPosition, YPosition, Resolution and Orientation tags of the standard TIFF 6.0 spec. - /// However, simple reversals of orientation between raster and model space - /// (e.g. horizontal or vertical flips) may be indicated by reversal of sign in the - /// corresponding component of the ModelPixelScaleTag. GeoTIFF compliant readers must - /// honor this signreversal convention. - /// - /// This tag must not be used if the raster image requires rotation or shearing to place - /// it into the standard model space. In such cases the transformation shall be defined - /// with the more general . - /// - ///
    Naming differences - /// In the native FreeImage library and thus, in the FreeImage API documentation, this - /// property's key is named GeoPixelScale. Since the GeoTIFF specification - /// as well as Java's EXIFTIFFTagSet class call this tag - /// , this property was renamed accordingly. - /// However, when accessing this property's tag by its object, - /// the native FreeImage tag key GeoPixelScale must be used. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public double[] ModelPixelScale - { - get - { - return GetTagArray("GeoPixelScale"); - } - set - { - SetTagValue("GeoPixelScale", value); - } - } - - /// - /// Gets or sets the value of the GeoTIFF GeoTiePointsTag. - /// - /// - /// The GeoTiePointsTag stores raster -> model tiepoint pairs in the order - /// - /// ModelTiePoints = (...,I,J,K, X,Y,Z...), - /// - /// where (I,J,K) is the point at location (I,J) in raster space with - /// pixel-value K, and (X,Y,Z) is a vector in model space. In most cases - /// the model space is only two-dimensional, in which case both K and Z should be set - /// to zero; this third dimension is provided in anticipation of future support for 3D - /// digital elevation models and vertical coordinate systems. - /// - /// A raster image may be georeferenced simply by specifying its location, size and - /// orientation in the model coordinate space M. This may be done by specifying the - /// location of three of the four bounding corner points. However, tiepoints are only - /// to be considered exact at the points specified; thus defining such a set of - /// bounding tiepoints does not imply that the model space locations of the interior - /// of the image may be exactly computed by a linear interpolation of these tiepoints. - /// - /// However, since the relationship between the Raster space and the model space will - /// often be an exact, affine transformation, this relationship can be defined using - /// one set of tiepoints and the , described below, which - /// gives the vertical and horizontal raster grid cell size, specified in model units. - /// - /// If possible, the first tiepoint placed in this tag shall be the one establishing - /// the location of the point (0,0) in raster space. However, if this is not possible - /// (for example, if (0,0) is goes to a part of model space in which the projection is - /// ill-defined), then there is no particular order in which the tiepoints need be - /// listed. - /// - /// For orthorectification or mosaicking applications a large number of tiepoints may - /// be specified on a mesh over the raster image. However, the definition of associated - /// grid interpolation methods is not in the scope of the current GeoTIFF spec. - /// - ///
    Naming differences - /// In the native FreeImage library and thus, in the FreeImage API documentation, this - /// property's key is named GeoTiePoints. Since the GeoTIFF specification - /// as well as Java's EXIFTIFFTagSet class call this tag - /// , this property was renamed accordingly. - /// However, when accessing this property's tag by its object, - /// the native FreeImage tag key GeoTiePoints must be used. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public double[] ModelTiePoints - { - get - { - return GetTagArray("GeoTiePoints"); - } - set - { - SetTagValue("GeoTiePoints", value); - } - } - - /// - /// Gets or sets the value of the GeoTIFF ModelTransformationMatrixTag. - /// - /// - /// This tag may be used to specify the transformation matrix between the raster space - /// (and its dependent pixel-value space) and the (possibly 3D) model space. - /// - ///
    Naming differences - /// In the native FreeImage library and thus, in the FreeImage API documentation, this - /// property's key is named GeoTransformationMatrix. Since the GeoTIFF specification - /// as well as Java's EXIFTIFFTagSet class call this tag - /// , this property was renamed accordingly. - /// However, when accessing this property's tag by its object, - /// the native FreeImage tag key GeoTransformationMatrix must be used. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public double[] ModelTransformationMatrix - { - get - { - return GetTagArray("GeoTransformationMatrix"); - } - set - { - SetTagValue("GeoTransformationMatrix", value); - } - } - - /// - /// Gets or sets the value of the GeoTIFF IntergraphTransformationMatrixTag. - /// - /// - /// The IntergraphTransformationMatrixTag conflicts with an internal software implementation - /// at Intergraph, and so its use is no longer encouraged. A GeoTIFF reader should look first - /// for the new tag, and only if it is not found should it check for this older tag. If found, - /// it should only consider it to be contain valid GeoTIFF matrix information if the tag-count - /// is 16; the Intergraph version uses 17 values. - /// - ///
    Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - ///
    - public double[] IntergraphTransformationMatrix - { - get - { - return GetTagArray("Intergraph TransformationMatrix"); - } - set - { - SetTagValue("Intergraph TransformationMatrix", value); - } - } - - /// - /// Gets or sets the value of the GeoTIFF JPLCartoIFDOffsetTag. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public uint? JPLCartoIFDOffset - { - get - { - return GetTagValue("JPL Carto IFD offset"); - } - set - { - SetTagValue("JPL Carto IFD offset", value); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_IPTC : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_IPTC(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_IPTC; } - } - - /// - /// Gets the Application Record Version. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public short? ApplicationRecordVersion - { - get - { - return GetTagValue("ApplicationRecordVersion"); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Object Type Reference. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ObjectTypeReference - { - get - { - return GetTagText("ObjectTypeReference"); - } - set - { - SetTagValue("ObjectTypeReference", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Object Attribute Reference. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ObjectAttributeReference - { - get - { - return GetTagText("ObjectAttributeReference"); - } - set - { - SetTagValue("ObjectAttributeReference", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Object Name. - /// This is also referred to as Title. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ObjectName - { - get - { - return GetTagText("ObjectName"); - } - set - { - SetTagValue("ObjectName", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Edit Status. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string EditStatus - { - get - { - return GetTagText("EditStatus"); - } - set - { - SetTagValue("EditStatus", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Editorial Update. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string EditorialUpdate - { - get - { - return GetTagText("EditorialUpdate"); - } - set - { - SetTagValue("EditorialUpdate", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Urgency. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Urgency - { - get - { - return GetTagText("Urgency"); - } - set - { - SetTagValue("Urgency", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Subject Reference. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SubjectReference - { - get - { - return GetTagText("SubjectReference"); - } - set - { - SetTagValue("SubjectReference", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Category. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Category - { - get - { - return GetTagText("Category"); - } - set - { - SetTagValue("Category", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Supplemental Categories. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SupplementalCategories - { - get - { - return GetTagText("SupplementalCategories"); - } - set - { - SetTagValue("SupplementalCategories", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Fixture Identifier. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string FixtureIdentifier - { - get - { - return GetTagText("FixtureIdentifier"); - } - set - { - SetTagValue("FixtureIdentifier", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Keywords. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Keywords - { - get - { - return GetTagText("Keywords"); - } - set - { - SetTagValue("Keywords", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Content Location Code. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ContentLocationCode - { - get - { - return GetTagText("ContentLocationCode"); - } - set - { - SetTagValue("ContentLocationCode", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Content Location Name. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ContentLocationName - { - get - { - return GetTagText("ContentLocationName"); - } - set - { - SetTagValue("ContentLocationName", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Release Date. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ReleaseDate - { - get - { - return GetTagText("ReleaseDate"); - } - set - { - SetTagValue("ReleaseDate", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Release Time. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ReleaseTime - { - get - { - return GetTagText("ReleaseTime"); - } - set - { - SetTagValue("ReleaseTime", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Expiration Date. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ExpirationDate - { - get - { - return GetTagText("ExpirationDate"); - } - set - { - SetTagValue("ExpirationDate", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Expiration Time. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ExpirationTime - { - get - { - return GetTagText("ExpirationTime"); - } - set - { - SetTagValue("ExpirationTime", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Special Instructions. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SpecialInstructions - { - get - { - return GetTagText("SpecialInstructions"); - } - set - { - SetTagValue("SpecialInstructions", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Action Advised. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ActionAdvised - { - get - { - return GetTagText("ActionAdvised"); - } - set - { - SetTagValue("ActionAdvised", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Reference Service. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ReferenceService - { - get - { - return GetTagText("ReferenceService"); - } - set - { - SetTagValue("ReferenceService", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Reference Date. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ReferenceDate - { - get - { - return GetTagText("ReferenceDate"); - } - set - { - SetTagValue("ReferenceDate", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Reference Number. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ReferenceNumber - { - get - { - return GetTagText("ReferenceNumber"); - } - set - { - SetTagValue("ReferenceNumber", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Date Created. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string DateCreated - { - get - { - return GetTagText("DateCreated"); - } - set - { - SetTagValue("DateCreated", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Time Created. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string TimeCreated - { - get - { - return GetTagText("TimeCreated"); - } - set - { - SetTagValue("TimeCreated", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Digital Creation Date. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string DigitalCreationDate - { - get - { - return GetTagText("DigitalCreationDate"); - } - set - { - SetTagValue("DigitalCreationDate", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Digital Creation Time. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string DigitalCreationTime - { - get - { - return GetTagText("DigitalCreationTime"); - } - set - { - SetTagValue("DigitalCreationTime", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Originating Program. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string OriginatingProgram - { - get - { - return GetTagText("OriginatingProgram"); - } - set - { - SetTagValue("OriginatingProgram", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Program Version. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ProgramVersion - { - get - { - return GetTagText("ProgramVersion"); - } - set - { - SetTagValue("ProgramVersion", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Object Cycle. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ObjectCycle - { - get - { - return GetTagText("ObjectCycle"); - } - set - { - SetTagValue("ObjectCycle", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag By Line. - /// This is the author's name. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ByLine - { - get - { - return GetTagText("By-line"); - } - set - { - SetTagValue("By-line", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag By Line Title. - /// This is the author's position. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ByLineTitle - { - get - { - return GetTagText("By-lineTitle"); - } - set - { - SetTagValue("By-lineTitle", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag City. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string City - { - get - { - return GetTagText("City"); - } - set - { - SetTagValue("City", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Sub Location. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SubLocation - { - get - { - return GetTagText("SubLocation"); - } - set - { - SetTagValue("SubLocation", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Province State. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ProvinceState - { - get - { - return GetTagText("ProvinceState"); - } - set - { - SetTagValue("ProvinceState", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Country Primary Location Code. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string CountryPrimaryLocationCode - { - get - { - return GetTagText("Country-PrimaryLocationCode"); - } - set - { - SetTagValue("Country-PrimaryLocationCode", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Country Primary Location Name. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string CountryPrimaryLocationName - { - get - { - return GetTagText("Country-PrimaryLocationName"); - } - set - { - SetTagValue("Country-PrimaryLocationName", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Original Transmission Reference. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string OriginalTransmissionReference - { - get - { - return GetTagText("OriginalTransmissionReference"); - } - set - { - SetTagValue("OriginalTransmissionReference", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Headline. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Headline - { - get - { - return GetTagText("Headline"); - } - set - { - SetTagValue("Headline", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Credit. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Credit - { - get - { - return GetTagText("Credit"); - } - set - { - SetTagValue("Credit", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Source. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Source - { - get - { - return GetTagText("Source"); - } - set - { - SetTagValue("Source", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Copyright Notice. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string CopyrightNotice - { - get - { - return GetTagText("CopyrightNotice"); - } - set - { - SetTagValue("CopyrightNotice", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Contact. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Contact - { - get - { - return GetTagText("Contact"); - } - set - { - SetTagValue("Contact", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Caption Abstract. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string CaptionAbstract - { - get - { - return GetTagText("CaptionAbstract"); - } - set - { - SetTagValue("CaptionAbstract", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Writer Editor. - /// This is also referred to as Caption Writer. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string WriterEditor - { - get - { - return GetTagText("WriterEditor"); - } - set - { - SetTagValue("WriterEditor", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Rasterized Caption. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string RasterizedCaption - { - get - { - return GetTagText("RasterizedCaption"); - } - set - { - SetTagValue("RasterizedCaption", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Image Type. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ImageType - { - get - { - return GetTagText("ImageType"); - } - set - { - SetTagValue("ImageType", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Image Orientation. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ImageOrientation - { - get - { - return GetTagText("ImageOrientation"); - } - set - { - SetTagValue("ImageOrientation", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Language Identifier. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string LanguageIdentifier - { - get - { - return GetTagText("LanguageIdentifier"); - } - set - { - SetTagValue("LanguageIdentifier", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Audio Type. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string AudioType - { - get - { - return GetTagText("AudioType"); - } - set - { - SetTagValue("AudioType", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Audio Sampling Rate. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string AudioSamplingRate - { - get - { - return GetTagText("AudioSamplingRate"); - } - set - { - SetTagValue("AudioSamplingRate", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Audio Sampling Resolution. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string AudioSamplingResolution - { - get - { - return GetTagText("AudioSamplingResolution"); - } - set - { - SetTagValue("AudioSamplingResolution", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Audio Duration. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string AudioDuration - { - get - { - return GetTagText("AudioDuration"); - } - set - { - SetTagValue("AudioDuration", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Audio Outcue. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string AudioOutcue - { - get - { - return GetTagText("AudioOutcue"); - } - set - { - SetTagValue("AudioOutcue", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Job I D. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string JobID - { - get - { - return GetTagText("JobID"); - } - set - { - SetTagValue("JobID", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Master Document I D. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string MasterDocumentID - { - get - { - return GetTagText("MasterDocumentID"); - } - set - { - SetTagValue("MasterDocumentID", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Short Document I D. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ShortDocumentID - { - get - { - return GetTagText("ShortDocumentID"); - } - set - { - SetTagValue("ShortDocumentID", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Unique Document I D. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string UniqueDocumentID - { - get - { - return GetTagText("UniqueDocumentID"); - } - set - { - SetTagValue("UniqueDocumentID", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Owner I D. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string OwnerID - { - get - { - return GetTagText("OwnerID"); - } - set - { - SetTagValue("OwnerID", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Object Preview File Format. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ObjectPreviewFileFormat - { - get - { - return GetTagText("ObjectPreviewFileFormat"); - } - set - { - SetTagValue("ObjectPreviewFileFormat", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Object Preview File Version. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ObjectPreviewFileVersion - { - get - { - return GetTagText("ObjectPreviewFileVersion"); - } - set - { - SetTagValue("ObjectPreviewFileVersion", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Object Preview Data. - /// This is also referred to as Audio Outcue. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ObjectPreviewData - { - get - { - return GetTagText("ObjectPreviewData"); - } - set - { - SetTagValue("ObjectPreviewData", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Prefs. - /// This is also referred to as photo-mechanic preferences. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Prefs - { - get - { - return GetTagText("Prefs"); - } - set - { - SetTagValue("Prefs", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Classify State. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ClassifyState - { - get - { - return GetTagText("ClassifyState"); - } - set - { - SetTagValue("ClassifyState", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Similarity Index. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string SimilarityIndex - { - get - { - return GetTagText("SimilarityIndex"); - } - set - { - SetTagValue("SimilarityIndex", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Document Notes. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string DocumentNotes - { - get - { - return GetTagText("DocumentNotes"); - } - set - { - SetTagValue("DocumentNotes", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Document History. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string DocumentHistory - { - get - { - return GetTagText("DocumentHistory"); - } - set - { - SetTagValue("DocumentHistory", value); - } - } - - /// - /// Gets or sets the value of the IPTC/NAA tag Exif Camera Info. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string ExifCameraInfo - { - get - { - return GetTagText("ExifCameraInfo"); - } - set - { - SetTagValue("ExifCameraInfo", value); - } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_NODATA : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_NODATA(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_NODATA; } - } - } - - /// - /// Represents a collection of all tags contained in the metadata model - /// . - /// - public class MDM_XMP : MetadataModel - { - /// - /// Initializes a new instance of this class. - /// - /// Handle to a FreeImage bitmap. - public MDM_XMP(FIBITMAP dib) : base(dib) { } - - /// - /// Retrieves the datamodel that this instance represents. - /// - public override FREE_IMAGE_MDMODEL Model - { - get { return FREE_IMAGE_MDMODEL.FIMD_XMP; } - } - - /// - /// Gets or sets the XMP XML content. - /// - /// - /// Handling of null values - /// A null value indicates, that the corresponding metadata tag is not - /// present in the metadata model. - /// Setting this property's value to a non-null reference creates the - /// metadata tag if necessary. - /// Setting this property's value to a null reference deletes the - /// metadata tag from the metadata model. - /// - public string Xml - { - get - { - return GetTagText("XMLPacket"); - } - set - { - SetTagValue("XMLPacket", value); - } - } - - /// - /// Gets an initialized to read the XMP XML content. - /// Returns null, if the metadata tag XMLPacket is not present in - /// this model. - /// - public XmlReader XmlReader - { - get - { - string xmlString = Xml; - if (xmlString == null) - { - return null; - } - else - { - MemoryStream stream = new MemoryStream(); - StreamWriter writer = new StreamWriter(stream); - writer.Write(xmlString); - return XmlReader.Create(stream); - } - } - } - } -} - - #endregion - -namespace FreeImageAPI.Metadata -{ - /// - /// Manages metadata objects and operations. - /// - public sealed class MetadataTag : IComparable, IComparable, ICloneable, IEquatable, IDisposable - { - /// - /// The encapsulated FreeImage-tag. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - internal FITAG tag; - - /// - /// The metadata model of . - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private FREE_IMAGE_MDMODEL model; - - /// - /// Indicates whether this instance has already been disposed. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool disposed = false; - - /// - /// Indicates whether this instance was created by FreeImage or - /// by the user. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool selfCreated; - - /// - /// List linking metadata-model and Type. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private static readonly Dictionary idList; - - /// - /// List linking Type and metadata-model. - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private static readonly Dictionary typeList; - - /// - /// Initializes a new instance of this class. - /// - private MetadataTag() - { - } - - /// - /// Initializes a new instance of this class. - /// - /// The new model the tag should be of. - public MetadataTag(FREE_IMAGE_MDMODEL model) - { - this.model = model; - tag = FreeImage.CreateTag(); - selfCreated = true; - - if (model == FREE_IMAGE_MDMODEL.FIMD_XMP) - { - Key = "XMLPacket"; - } - } - - /// - /// Initializes a new instance of this class. - /// - /// The to represent. - /// The bitmap was extracted from. - public MetadataTag(FITAG tag, FIBITMAP dib) - { - if (tag.IsNull) - { - throw new ArgumentNullException("tag"); - } - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - this.tag = tag; - model = GetModel(dib, tag); - selfCreated = false; - - if (model == FREE_IMAGE_MDMODEL.FIMD_XMP) - { - Key = "XMLPacket"; - } - } - - /// - /// Initializes a new instance of this class. - /// - /// The to represent. - /// The model of . - public MetadataTag(FITAG tag, FREE_IMAGE_MDMODEL model) - { - if (tag.IsNull) - { - throw new ArgumentNullException("tag"); - } - this.tag = tag; - this.model = model; - selfCreated = false; - - if (model == FREE_IMAGE_MDMODEL.FIMD_XMP) - { - Key = "XMLPacket"; - } - } - - static MetadataTag() - { - idList = new Dictionary(); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_BYTE, typeof(byte)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_SHORT, typeof(ushort)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_LONG, typeof(uint)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_RATIONAL, typeof(FIURational)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_SBYTE, typeof(sbyte)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_UNDEFINED, typeof(byte)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_SSHORT, typeof(short)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_SLONG, typeof(int)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_SRATIONAL, typeof(FIRational)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_FLOAT, typeof(float)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_DOUBLE, typeof(double)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_IFD, typeof(uint)); - idList.Add(FREE_IMAGE_MDTYPE.FIDT_PALETTE, typeof(RGBQUAD)); - - typeList = new Dictionary(); - typeList.Add(typeof(ushort), FREE_IMAGE_MDTYPE.FIDT_SHORT); - typeList.Add(typeof(ushort[]), FREE_IMAGE_MDTYPE.FIDT_SHORT); - typeList.Add(typeof(string), FREE_IMAGE_MDTYPE.FIDT_ASCII); - typeList.Add(typeof(uint), FREE_IMAGE_MDTYPE.FIDT_LONG); - typeList.Add(typeof(uint[]), FREE_IMAGE_MDTYPE.FIDT_LONG); - typeList.Add(typeof(FIURational), FREE_IMAGE_MDTYPE.FIDT_RATIONAL); - typeList.Add(typeof(FIURational[]), FREE_IMAGE_MDTYPE.FIDT_RATIONAL); - typeList.Add(typeof(sbyte), FREE_IMAGE_MDTYPE.FIDT_SBYTE); - typeList.Add(typeof(sbyte[]), FREE_IMAGE_MDTYPE.FIDT_SBYTE); - typeList.Add(typeof(byte), FREE_IMAGE_MDTYPE.FIDT_BYTE); - typeList.Add(typeof(byte[]), FREE_IMAGE_MDTYPE.FIDT_BYTE); - typeList.Add(typeof(short), FREE_IMAGE_MDTYPE.FIDT_SSHORT); - typeList.Add(typeof(short[]), FREE_IMAGE_MDTYPE.FIDT_SSHORT); - typeList.Add(typeof(int), FREE_IMAGE_MDTYPE.FIDT_SLONG); - typeList.Add(typeof(int[]), FREE_IMAGE_MDTYPE.FIDT_SLONG); - typeList.Add(typeof(FIRational), FREE_IMAGE_MDTYPE.FIDT_SRATIONAL); - typeList.Add(typeof(FIRational[]), FREE_IMAGE_MDTYPE.FIDT_SRATIONAL); - typeList.Add(typeof(float), FREE_IMAGE_MDTYPE.FIDT_FLOAT); - typeList.Add(typeof(float[]), FREE_IMAGE_MDTYPE.FIDT_FLOAT); - typeList.Add(typeof(double), FREE_IMAGE_MDTYPE.FIDT_DOUBLE); - typeList.Add(typeof(double[]), FREE_IMAGE_MDTYPE.FIDT_DOUBLE); - typeList.Add(typeof(RGBQUAD), FREE_IMAGE_MDTYPE.FIDT_PALETTE); - typeList.Add(typeof(RGBQUAD[]), FREE_IMAGE_MDTYPE.FIDT_PALETTE); - } - - /// - /// Releases all resources used by the instance. - /// - ~MetadataTag() - { - Dispose(); - } - - /// - /// Determines whether two specified objects have the same value. - /// - /// A or a null reference (Nothing in Visual Basic). - /// A or a null reference (Nothing in Visual Basic). - /// - /// true if the value of left is the same as the value of right; otherwise, false. - /// - public static bool operator ==(MetadataTag left, MetadataTag right) - { - // Check whether both are null - if ((object)left == (object)right) - { - return true; - } - else if ((object)left == null || (object)right == null) - { - return false; - } - left.CheckDisposed(); - right.CheckDisposed(); - // Check all properties - if ((left.Key != right.Key) || - (left.ID != right.ID) || - (left.Description != right.Description) || - (left.Count != right.Count) || - (left.Length != right.Length) || - (left.Model != right.Model) || - (left.Type != right.Type)) - { - return false; - } - if (left.Length == 0) - { - return true; - } - IntPtr ptr1 = FreeImage.GetTagValue(left.tag); - IntPtr ptr2 = FreeImage.GetTagValue(right.tag); - return FreeImage.CompareMemory(ptr1, ptr2, left.Length); - } - - /// - /// Determines whether two specified objects have different values. - /// - /// A or a null reference (Nothing in Visual Basic). - /// A or a null reference (Nothing in Visual Basic). - /// - /// true if the value of left is different from the value of right; otherwise, false. - /// - public static bool operator !=(MetadataTag left, MetadataTag right) - { - return !(left == right); - } - - /// - /// Extracts the value of a instance to a handle. - /// - /// A instance. - /// A new instance of initialized to . - public static implicit operator FITAG(MetadataTag value) - { - return value.tag; - } - - private static FREE_IMAGE_MDMODEL GetModel(FIBITMAP dib, FITAG tag) - { - FITAG value; - foreach (FREE_IMAGE_MDMODEL model in FreeImage.FREE_IMAGE_MDMODELS) - { - FIMETADATA mData = FreeImage.FindFirstMetadata(model, dib, out value); - if (mData.IsNull) - { - continue; - } - try - { - do - { - if (value == tag) - { - return model; - } - } - while (FreeImage.FindNextMetadata(mData, out value)); - } - finally - { - if (!mData.IsNull) - { - FreeImage.FindCloseMetadata(mData); - } - } - } - throw new ArgumentException("'tag' is no metadata object of 'dib'"); - } - - /// - /// Gets the model of the metadata. - /// - public FREE_IMAGE_MDMODEL Model - { - get { CheckDisposed(); return model; } - } - - /// - /// Gets or sets the key of the metadata. - /// - public string Key - { - get { CheckDisposed(); return FreeImage.GetTagKey(tag); } - set - { - CheckDisposed(); - if ((model != FREE_IMAGE_MDMODEL.FIMD_XMP) || (value == "XMLPacket")) - { - FreeImage.SetTagKey(tag, value); - } - } - } - - /// - /// Gets or sets the description of the metadata. - /// - public string Description - { - get { CheckDisposed(); return FreeImage.GetTagDescription(tag); } - set { CheckDisposed(); FreeImage.SetTagDescription(tag, value); } - } - - /// - /// Gets or sets the ID of the metadata. - /// - public ushort ID - { - get { CheckDisposed(); return FreeImage.GetTagID(tag); } - set { CheckDisposed(); FreeImage.SetTagID(tag, value); } - } - - /// - /// Gets the type of the metadata. - /// - public FREE_IMAGE_MDTYPE Type - { - get { CheckDisposed(); return FreeImage.GetTagType(tag); } - internal set { FreeImage.SetTagType(tag, value); } - } - - /// - /// Gets the number of elements the metadata object contains. - /// - public uint Count - { - get { CheckDisposed(); return FreeImage.GetTagCount(tag); } - private set { FreeImage.SetTagCount(tag, value); } - } - - /// - /// Gets the length of the value in bytes. - /// - public uint Length - { - get { CheckDisposed(); return FreeImage.GetTagLength(tag); } - private set { FreeImage.SetTagLength(tag, value); } - } - - private unsafe byte[] GetData() - { - uint length = Length; - byte[] value = new byte[length]; - byte* ptr = (byte*)FreeImage.GetTagValue(tag); - for (int i = 0; i < length; i++) - { - value[i] = ptr[i]; - } - return value; - } - - /// - /// Gets or sets the value of the metadata. - /// - public object Value - { - get - { - unsafe - { - CheckDisposed(); - int cnt = (int)Count; - - if (Type == FREE_IMAGE_MDTYPE.FIDT_ASCII) - { - byte* value = (byte*)FreeImage.GetTagValue(tag); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < cnt; i++) - { - sb.Append(Convert.ToChar(value[i])); - } - return sb.ToString(); - } - else if (Type == FREE_IMAGE_MDTYPE.FIDT_NOTYPE) - { - return null; - } - - Array array = Array.CreateInstance(idList[Type], Count); - void* src = (void*)FreeImage.GetTagValue(tag); - FreeImage.CopyMemory(array, src, Length); - return array; - } - } - set - { - SetValue(value); - } - } - - /// - /// Sets the value of the metadata. - /// In case value is of byte or byte[] is assumed. - /// In case value is of uint or uint[] is assumed. - /// - /// New data of the metadata. - /// True on success, false on failure. - /// - /// The data format is not supported. - /// - /// is null. - public bool SetValue(object value) - { - Type type = value.GetType(); - if (!typeList.ContainsKey(type)) - { - throw new NotSupportedException("The type of value is not supported"); - } - return SetValue(value, typeList[type]); - } - - /// - /// Sets the value of the metadata. - /// - /// New data of the metadata. - /// Type of the data. - /// True on success, false on failure. - /// - /// The data type is not supported. - /// - /// is null. - /// - /// and to not fit. - public bool SetValue(object value, FREE_IMAGE_MDTYPE type) - { - CheckDisposed(); - if ((!value.GetType().IsArray) && (!(value is string))) - { - Array array = Array.CreateInstance(value.GetType(), 1); - array.SetValue(value, 0); - return SetArrayValue(array, type); - } - return SetArrayValue(value, type); - } - - /// - /// Sets the value of this tag to the value of - /// using the given type. - /// - /// New value of the tag. - /// Data-type of the tag. - /// - /// - /// is a null reference. - /// - /// - /// is FIDT_ASCII and - /// is not String. - /// is not FIDT_ASCII and - /// is not Array. - /// - /// is FIDT_NOTYPE. - private unsafe bool SetArrayValue(object value, FREE_IMAGE_MDTYPE type) - { - if (value == null) - { - throw new ArgumentNullException("value"); - } - - byte[] data = null; - - if (type == FREE_IMAGE_MDTYPE.FIDT_ASCII) - { - string tempValue = value as string; - if (tempValue == null) - { - throw new ArgumentException("value"); - } - Type = type; - Length = Count = (uint)tempValue.Length; - data = new byte[Length]; - - for (int i = 0; i < tempValue.Length; i++) - { - data[i] = (byte)tempValue[i]; - } - } - else if (type == FREE_IMAGE_MDTYPE.FIDT_NOTYPE) - { - throw new NotSupportedException("type is not supported."); - } - else - { - Array array = value as Array; - if (array == null) - { - throw new ArgumentException("value"); - } - - if (array.Length != 0) - if (!CheckType(array.GetValue(0).GetType(), type)) - throw new ArgumentException("The type of value is incorrect."); - - Type = type; - Count = (uint)array.Length; - Length = (uint)(array.Length * Marshal.SizeOf(idList[type])); - data = new byte[Length]; - FreeImage.CopyMemory(data, array, Length); - } - - return FreeImage.SetTagValue(tag, data); - } - - private static bool CheckType(Type dataType, FREE_IMAGE_MDTYPE type) - { - if (dataType != null) - switch (type) - { - case FREE_IMAGE_MDTYPE.FIDT_ASCII: - return dataType == typeof(string); - case FREE_IMAGE_MDTYPE.FIDT_BYTE: - return dataType == typeof(byte); - case FREE_IMAGE_MDTYPE.FIDT_DOUBLE: - return dataType == typeof(double); - case FREE_IMAGE_MDTYPE.FIDT_FLOAT: - return dataType == typeof(float); - case FREE_IMAGE_MDTYPE.FIDT_IFD: - return dataType == typeof(uint); - case FREE_IMAGE_MDTYPE.FIDT_LONG: - return dataType == typeof(uint); - case FREE_IMAGE_MDTYPE.FIDT_NOTYPE: - return false; - case FREE_IMAGE_MDTYPE.FIDT_PALETTE: - return dataType == typeof(RGBQUAD); - case FREE_IMAGE_MDTYPE.FIDT_RATIONAL: - return dataType == typeof(FIURational); - case FREE_IMAGE_MDTYPE.FIDT_SBYTE: - return dataType == typeof(sbyte); - case FREE_IMAGE_MDTYPE.FIDT_SHORT: - return dataType == typeof(ushort); - case FREE_IMAGE_MDTYPE.FIDT_SLONG: - return dataType == typeof(int); - case FREE_IMAGE_MDTYPE.FIDT_SRATIONAL: - return dataType == typeof(FIRational); - case FREE_IMAGE_MDTYPE.FIDT_SSHORT: - return dataType == typeof(short); - case FREE_IMAGE_MDTYPE.FIDT_UNDEFINED: - return dataType == typeof(byte); - } - return false; - } - - /// - /// Add this metadata to an image. - /// - /// Handle to a FreeImage bitmap. - /// True on success, false on failure. - public bool AddToImage(FIBITMAP dib) - { - CheckDisposed(); - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - if (Key == null) - { - throw new ArgumentNullException("Key"); - } - if (!selfCreated) - { - tag = FreeImage.CloneTag(tag); - if (tag.IsNull) - { - throw new Exception("FreeImage.CloneTag() failed."); - } - selfCreated = true; - } - if (!FreeImage.SetMetadata(Model, dib, Key, tag)) - { - return false; - } - FREE_IMAGE_MDMODEL _model = Model; - string _key = Key; - selfCreated = false; - FreeImage.DeleteTag(tag); - return FreeImage.GetMetadata(_model, dib, _key, out tag); - } - - /// - /// Gets a .NET PropertyItem for this metadata tag. - /// - /// The .NET PropertyItem. - public unsafe System.Drawing.Imaging.PropertyItem GetPropertyItem() - { - System.Drawing.Imaging.PropertyItem item = FreeImage.CreatePropertyItem(); - item.Id = ID; - item.Len = (int)Length; - item.Type = (short)Type; - FreeImage.CopyMemory(item.Value = new byte[item.Len], FreeImage.GetTagValue(tag), item.Len); - return item; - } - - /// - /// Converts the value of the object - /// to its equivalent string representation. - /// - /// The string representation of the value of this instance. - public override string ToString() - { - CheckDisposed(); - string fiString = FreeImage.TagToString(model, tag, 0); - - if (String.IsNullOrEmpty(fiString)) - { - return tag.ToString(); - } - else - { - return fiString; - } - } - - /// - /// Creates a deep copy of this . - /// - /// A deep copy of this . - public object Clone() - { - CheckDisposed(); - MetadataTag clone = new MetadataTag(); - clone.model = model; - clone.tag = FreeImage.CloneTag(tag); - clone.selfCreated = true; - return clone; - } - - /// - /// Tests whether the specified object is a instance - /// and is equivalent to this instance. - /// - /// The object to test. - /// true if is a instance - /// equivalent to this instance; otherwise, false. - public override bool Equals(object obj) - { - return ((obj is MetadataTag) && (Equals((MetadataTag)obj))); - } - - /// - /// Tests whether the specified instance is equivalent to this instance. - /// - /// A instance to compare to this instance. - /// true if equivalent to this instance; - /// otherwise, false. - public bool Equals(MetadataTag other) - { - return (this == other); - } - - /// - /// Returns a hash code for this structure. - /// - /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - return tag.GetHashCode(); - } - - /// - /// Compares this instance with a specified . - /// - /// An object to compare with this instance. - /// A 32-bit signed integer indicating the lexical relationship between the two comparands. - /// is not a . - public int CompareTo(object obj) - { - if (obj == null) - { - return 1; - } - if (!(obj is MetadataTag)) - { - throw new ArgumentException("obj"); - } - return CompareTo((MetadataTag)obj); - } - - /// - /// Compares the current instance with another object of the same type. - /// - /// An object to compare with this instance. - /// A 32-bit signed integer that indicates the relative order of the objects being compared. - public int CompareTo(MetadataTag other) - { - CheckDisposed(); - other.CheckDisposed(); - return tag.CompareTo(other.tag); - } - - /// - /// Releases all resources used by the instance. - /// - public void Dispose() - { - if (!disposed) - { - disposed = true; - if (selfCreated) - { - FreeImage.DeleteTag(tag); - tag = FITAG.Zero; - } - } - } - - /// - /// Gets whether this instance has already been disposed. - /// - public bool Disposed - { - get { return disposed; } - } - - /// - /// Throwns an in case - /// this instance has already been disposed. - /// - private void CheckDisposed() - { - if (disposed) - { - throw new ObjectDisposedException("The object has already been disposed."); - } - } - } -} - -namespace FreeImageAPI -{ - /// - /// Provides methods for working with the standard bitmap palette. - /// - public sealed class Palette : MemoryArray - { - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private GCHandle paletteHandle; - - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private RGBQUAD[] array; - - /// - /// Initializes a new instance for the given FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// is null. - /// is not - /// -or- - /// has more than 8bpp. - public Palette(FIBITMAP dib) - : base(FreeImage.GetPalette(dib), (int)FreeImage.GetColorsUsed(dib)) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - if (FreeImage.GetImageType(dib) != FREE_IMAGE_TYPE.FIT_BITMAP) - { - throw new ArgumentException("dib"); - } - if (FreeImage.GetBPP(dib) > 8u) - { - throw new ArgumentException("dib"); - } - } - - /// - /// Initializes a new instance for the given FITAG that contains - /// a palette. - /// - /// The tag containing the palette. - /// is null. - /// is not - /// . - public Palette(FITAG tag) - : base(FreeImage.GetTagValue(tag), (int)FreeImage.GetTagCount(tag)) - { - if (FreeImage.GetTagType(tag) != FREE_IMAGE_MDTYPE.FIDT_PALETTE) - { - throw new ArgumentException("tag"); - } - } - - /// - /// Initializes a new instance for the given MetadataTag that contains - /// a palette. - /// - /// The tag containing the palette. - /// is null. - /// is not - /// . - public Palette(MetadataTag tag) - : base(FreeImage.GetTagValue(tag.tag), (int)tag.Count) - { - if (FreeImage.GetTagType(tag) != FREE_IMAGE_MDTYPE.FIDT_PALETTE) - { - throw new ArgumentException("tag"); - } - } - - /// - /// Initializes a new instance for the given array of that contains - /// a palette. - /// - /// A RGBQUAD array containing the palette data to initialize this instance. - public Palette(RGBQUAD[] palette) - { - unsafe - { - this.array = (RGBQUAD[])palette.Clone(); - this.paletteHandle = GCHandle.Alloc(array, GCHandleType.Pinned); - - base.baseAddress = (byte*)this.paletteHandle.AddrOfPinnedObject(); - base.length = (int)this.array.Length; - - // Create an array containing a single element. - // Due to the fact, that it's not possible to create pointers - // of generic types, an array is used to obtain the memory - // address of an element of T. - base.buffer = new RGBQUAD[1]; - // The array is pinned immediately to prevent the GC from - // moving it to a different position in memory. - base.handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - // The array and its content have beed pinned, so that its address - // can be safely requested and stored for the whole lifetime - // of the instace. - base.ptr = (byte*)base.handle.AddrOfPinnedObject(); - } - } - - /// - /// Initializes a new instance for the given array of that contains - /// a palette. - /// - /// A Color array containing the palette data to initialize this instance. - public Palette(Color[] palette) - : this(RGBQUAD.ToRGBQUAD(palette)) - { - } - - /// - /// Initializes a new instance with the specified size. - /// - /// The size of the palette. - public Palette(int size) - : this(new RGBQUAD[size]) - { - } - - /// - /// Gets or sets the palette through an array of . - /// - public RGBQUAD[] AsArray - { - get - { - return Data; - } - set - { - Data = value; - } - } - - /// - /// Get an array of that the block of memory represents. - /// This property is used for internal palette operations. - /// - internal unsafe Color[] ColorData - { - get - { - EnsureNotDisposed(); - Color[] data = new Color[length]; - for (int i = 0; i < length; i++) - { - data[i] = Color.FromArgb((int)(((uint*)baseAddress)[i] | 0xFF000000)); - } - return data; - } - } - - /// - /// Returns the palette as an array of . - /// - /// The palette as an array of . - public RGBQUAD[] ToArray() - { - return Data; - } - - /// - /// Creates a linear palette based on the provided . - /// - /// The used to colorize the palette. - /// - /// Only call this method on linear palettes. - /// - public void Colorize(Color color) - { - Colorize(color, 0.5d); - } - - /// - /// Creates a linear palette based on the provided . - /// - /// The used to colorize the palette. - /// The position of the color within the new palette. - /// 0 < < 1. - /// - /// Only call this method on linear palettes. - /// - public void Colorize(Color color, double splitSize) - { - Colorize(color, (int)(length * splitSize)); - } - - /// - /// Creates a linear palette based on the provided . - /// - /// The used to colorize the palette. - /// The position of the color within the new palette. - /// 0 < < . - /// - /// Only call this method on linear palettes. - /// - public void Colorize(Color color, int splitSize) - { - EnsureNotDisposed(); - if (splitSize < 1 || splitSize >= length) - { - throw new ArgumentOutOfRangeException("splitSize"); - } - - RGBQUAD[] pal = new RGBQUAD[length]; - - double red = color.R; - double green = color.G; - double blue = color.B; - - int i = 0; - double r, g, b; - - r = red / splitSize; - g = green / splitSize; - b = blue / splitSize; - - for (; i <= splitSize; i++) - { - pal[i].rgbRed = (byte)(i * r); - pal[i].rgbGreen = (byte)(i * g); - pal[i].rgbBlue = (byte)(i * b); - } - - r = (255 - red) / (length - splitSize); - g = (255 - green) / (length - splitSize); - b = (255 - blue) / (length - splitSize); - - for (; i < length; i++) - { - pal[i].rgbRed = (byte)(red + ((i - splitSize) * r)); - pal[i].rgbGreen = (byte)(green + ((i - splitSize) * g)); - pal[i].rgbBlue = (byte)(blue + ((i - splitSize) * b)); - } - - Data = pal; - } - - /// - /// Creates a linear grayscale palette. - /// - public void CreateGrayscalePalette() - { - Colorize(Color.White, length - 1); - } - - /// - /// Creates a linear grayscale palette. - /// - /// true to create an inverse grayscale palette. - public void CreateGrayscalePalette(bool inverse) - { - Colorize(Color.White, inverse ? 0 : length - 1); - } - - /// - /// Creates a linear palette with the specified . - /// - /// - /// A linear grayscale palette contains all shades of colors from - /// black to white. This method creates a similar palette with the white - /// color being replaced by the specified color. - /// - /// The used to create the palette. - /// true to create an inverse palette. - public void CreateGrayscalePalette(Color color, bool inverse) - { - Colorize(color, inverse ? 0 : length - 1); - } - - /// - /// Reverses the palette. - /// - public void Reverse() - { - EnsureNotDisposed(); - if (array != null) - { - Array.Reverse(array); - } - else - { - RGBQUAD[] localArray = Data; - Array.Reverse(localArray); - Data = localArray; - } - } - - /// - /// Copies the values from the specified to this instance. - /// - /// The palette to copy from. - /// - /// is a null reference. - public void CopyFrom(Palette palette) - { - EnsureNotDisposed(); - if (palette == null) - { - throw new ArgumentNullException("palette"); - } - CopyFrom(palette.Data, 0, 0, Math.Min(palette.Length, this.Length)); - } - - /// - /// Copies the values from the specified to this instance, - /// starting at the specified . - /// - /// The palette to copy from. - /// The position in this instance where the values - /// will be copied to. - /// - /// is a null reference. - /// - /// is outside the range of valid indexes. - public void CopyFrom(Palette palette, int offset) - { - EnsureNotDisposed(); - CopyFrom(palette.Data, 0, offset, Math.Min(palette.Length, this.Length - offset)); - } - - /// - /// Saves this to the specified file. - /// - /// - /// A string that contains the name of the file to which to save this . - /// - public void Save(string filename) - { - using (Stream stream = new FileStream(filename, FileMode.Create, FileAccess.Write)) - { - Save(stream); - } - } - - /// - /// Saves this to the specified stream. - /// - /// - /// The where the image will be saved. - /// - public void Save(Stream stream) - { - Save(new BinaryWriter(stream)); - } - - /// - /// Saves this using the specified writer. - /// - /// - /// The used to save the image. - /// - public void Save(BinaryWriter writer) - { - EnsureNotDisposed(); - writer.Write(ToByteArray()); - } - - /// - /// Loads a palette from the specified file. - /// - /// The name of the palette file. - public void Load(string filename) - { - using (Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read)) - { - Load(stream); - } - } - - /// - /// Loads a palette from the specified stream. - /// - /// The stream to load the palette from. - public void Load(Stream stream) - { - Load(new BinaryReader(stream)); - } - - /// - /// Loads a palette from the reader. - /// - /// The reader to load the palette from. - public void Load(BinaryReader reader) - { - EnsureNotDisposed(); - unsafe - { - int size = length * sizeof(RGBQUAD); - byte[] data = reader.ReadBytes(size); - fixed (byte* src = data) - { - CopyMemory(baseAddress, src, data.Length); - } - } - } - - /// - /// Releases allocated handles associated with this instance. - /// - /// true to release managed resources. - protected override void Dispose(bool disposing) - { - if (paletteHandle.IsAllocated) - paletteHandle.Free(); - array = null; - - base.Dispose(disposing); - } - } -} - -namespace FreeImageAPI.Plugins -{ - /// - /// Class representing all registered in FreeImage. - /// - public static class PluginRepository - { - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private static readonly List plugins = null; - - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private static readonly List localPlugins = null; - - static PluginRepository() - { - plugins = new List(FreeImage.GetFIFCount()); - localPlugins = new List(0); - for (int i = 0; i < plugins.Capacity; i++) - { - plugins.Add(new FreeImagePlugin((FREE_IMAGE_FORMAT)i)); - } - } - - /// - /// Adds local plugin to this class. - /// - /// The registered plugin. - internal static void RegisterLocalPlugin(LocalPlugin localPlugin) - { - FreeImagePlugin plugin = new FreeImagePlugin(localPlugin.Format); - plugins.Add(plugin); - localPlugins.Add(plugin); - } - - /// - /// Returns an instance of , representing the given format. - /// - /// The representing format. - /// An instance of . - public static FreeImagePlugin Plugin(FREE_IMAGE_FORMAT fif) - { - return Plugin((int)fif); - } - - /// - /// Returns an instance of , - /// representing the format at the given index. - /// - /// The index of the representing format. - /// An instance of . - public static FreeImagePlugin Plugin(int index) - { - return (index >= 0) ? plugins[index] : null; - } - - /// - /// Returns an instance of . - /// is searched in: - /// Format, RegExpr, - /// ValidExtension and ValidFilename. - /// - /// The expression to search for. - /// An instance of . - public static FreeImagePlugin Plugin(string expression) - { - FreeImagePlugin result = null; - expression = expression.ToLower(); - - foreach (FreeImagePlugin plugin in plugins) - { - if (plugin.Format.ToLower().Contains(expression) || - plugin.RegExpr.ToLower().Contains(expression) || - plugin.ValidExtension(expression, StringComparison.CurrentCultureIgnoreCase) || - plugin.ValidFilename(expression, StringComparison.CurrentCultureIgnoreCase)) - { - result = plugin; - break; - } - } - - return result; - } - - /// - /// Returns an instance of for the given format. - /// - /// The format of the Plugin. - /// An instance of . - public static FreeImagePlugin PluginFromFormat(string format) - { - return Plugin(FreeImage.GetFIFFromFormat(format)); - } - - /// - /// Returns an instance of for the given filename. - /// - /// The valid filename for the plugin. - /// An instance of . - public static FreeImagePlugin PluginFromFilename(string filename) - { - return Plugin(FreeImage.GetFIFFromFilename(filename)); - } - - /// - /// Returns an instance of for the given mime. - /// - /// The valid mime for the plugin. - /// An instance of . - public static FreeImagePlugin PluginFromMime(string mime) - { - return Plugin(FreeImage.GetFIFFromMime(mime)); - } - - /// - /// Gets the number of registered plugins. - /// - public static int FIFCount - { - get - { - return FreeImage.GetFIFCount(); - } - } - - /// - /// Gets a readonly collection of all plugins. - /// - public static ReadOnlyCollection PluginList - { - get - { - return plugins.AsReadOnly(); - } - } - - /// - /// Gets a list of plugins that are only able to - /// read but not to write. - /// - public static List ReadOnlyPlugins - { - get - { - List list = new List(); - foreach (FreeImagePlugin p in plugins) - { - if (p.SupportsReading && !p.SupportsWriting) - { - list.Add(p); - } - } - return list; - } - } - - /// - /// Gets a list of plugins that are only able to - /// write but not to read. - /// - public static List WriteOnlyPlugins - { - get - { - List list = new List(); - foreach (FreeImagePlugin p in plugins) - { - if (!p.SupportsReading && p.SupportsWriting) - { - list.Add(p); - } - } - return list; - } - } - - /// - /// Gets a list of plugins that are not able to - /// read or write. - /// - public static List StupidPlugins - { - get - { - List list = new List(); - foreach (FreeImagePlugin p in plugins) - { - if (!p.SupportsReading && !p.SupportsWriting) - { - list.Add(p); - } - } - return list; - } - } - - /// - /// Gets a list of plugins that are able to read. - /// - public static List ReadablePlugins - { - get - { - List list = new List(); - foreach (FreeImagePlugin p in plugins) - { - if (p.SupportsReading) - { - list.Add(p); - } - } - return list; - } - } - - /// - /// Gets a list of plugins that are able to write. - /// - public static List WriteablePlugins - { - get - { - List list = new List(); - foreach (FreeImagePlugin p in plugins) - { - if (p.SupportsWriting) - { - list.Add(p); - } - } - return list; - } - } - - /// - /// Gets a list of local plugins. - /// - public static ReadOnlyCollection LocalPlugins - { - get - { - return localPlugins.AsReadOnly(); - } - } - - /// - /// Gets a list of built-in plugins. - /// - public static List BuiltInPlugins - { - get - { - List list = new List(); - foreach (FreeImagePlugin p in plugins) - { - if (!localPlugins.Contains(p)) - { - list.Add(p); - } - } - return list; - } - } - - /// - /// Windows or OS/2 Bitmap File (*.BMP) - /// - public static FreeImagePlugin BMP { get { return plugins[0]; } } - - /// - /// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE) - /// - public static FreeImagePlugin ICO { get { return plugins[1]; } } - - /// - /// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE) - /// - public static FreeImagePlugin JPEG { get { return plugins[2]; } } - - /// - /// JPEG Network Graphics (*.JNG) - /// - public static FreeImagePlugin JNG { get { return plugins[3]; } } - - /// - /// Commodore 64 Koala format (*.KOA) - /// - public static FreeImagePlugin KOALA { get { return plugins[4]; } } - - /// - /// Amiga IFF (*.IFF, *.LBM) - /// - public static FreeImagePlugin LBM { get { return plugins[5]; } } - - /// - /// Amiga IFF (*.IFF, *.LBM) - /// - public static FreeImagePlugin IFF { get { return plugins[5]; } } - - /// - /// Multiple Network Graphics (*.MNG) - /// - public static FreeImagePlugin MNG { get { return plugins[6]; } } - - /// - /// Portable Bitmap (ASCII) (*.PBM) - /// - public static FreeImagePlugin PBM { get { return plugins[7]; } } - - /// - /// Portable Bitmap (BINARY) (*.PBM) - /// - public static FreeImagePlugin PBMRAW { get { return plugins[8]; } } - - /// - /// Kodak PhotoCD (*.PCD) - /// - public static FreeImagePlugin PCD { get { return plugins[9]; } } - - /// - /// Zsoft Paintbrush PCX bitmap format (*.PCX) - /// - public static FreeImagePlugin PCX { get { return plugins[10]; } } - - /// - /// Portable Graymap (ASCII) (*.PGM) - /// - public static FreeImagePlugin PGM { get { return plugins[11]; } } - - /// - /// Portable Graymap (BINARY) (*.PGM) - /// - public static FreeImagePlugin PGMRAW { get { return plugins[12]; } } - - /// - /// Portable Network Graphics (*.PNG) - /// - public static FreeImagePlugin PNG { get { return plugins[13]; } } - - /// - /// Portable Pixelmap (ASCII) (*.PPM) - /// - public static FreeImagePlugin PPM { get { return plugins[14]; } } - - /// - /// Portable Pixelmap (BINARY) (*.PPM) - /// - public static FreeImagePlugin PPMRAW { get { return plugins[15]; } } - - /// - /// Sun Rasterfile (*.RAS) - /// - public static FreeImagePlugin RAS { get { return plugins[16]; } } - - /// - /// truevision Targa files (*.TGA, *.TARGA) - /// - public static FreeImagePlugin TARGA { get { return plugins[17]; } } - - /// - /// Tagged Image File Format (*.TIF, *.TIFF) - /// - public static FreeImagePlugin TIFF { get { return plugins[18]; } } - - /// - /// Wireless Bitmap (*.WBMP) - /// - public static FreeImagePlugin WBMP { get { return plugins[19]; } } - - /// - /// Adobe Photoshop (*.PSD) - /// - public static FreeImagePlugin PSD { get { return plugins[20]; } } - - /// - /// Dr. Halo (*.CUT) - /// - public static FreeImagePlugin CUT { get { return plugins[21]; } } - - /// - /// X11 Bitmap Format (*.XBM) - /// - public static FreeImagePlugin XBM { get { return plugins[22]; } } - - /// - /// X11 Pixmap Format (*.XPM) - /// - public static FreeImagePlugin XPM { get { return plugins[23]; } } - - /// - /// DirectDraw Surface (*.DDS) - /// - public static FreeImagePlugin DDS { get { return plugins[24]; } } - - /// - /// Graphics Interchange Format (*.GIF) - /// - public static FreeImagePlugin GIF { get { return plugins[25]; } } - - /// - /// High Dynamic Range (*.HDR) - /// - public static FreeImagePlugin HDR { get { return plugins[26]; } } - - /// - /// Raw Fax format CCITT G3 (*.G3) - /// - public static FreeImagePlugin FAXG3 { get { return plugins[27]; } } - - /// - /// Silicon Graphics SGI image format (*.SGI) - /// - public static FreeImagePlugin SGI { get { return plugins[28]; } } - - /// - /// OpenEXR format (*.EXR) - /// - public static FreeImagePlugin EXR { get { return plugins[29]; } } - - /// - /// JPEG-2000 format (*.J2K, *.J2C) - /// - public static FreeImagePlugin J2K { get { return plugins[30]; } } - - /// - /// JPEG-2000 format (*.JP2) - /// - public static FreeImagePlugin JP2 { get { return plugins[31]; } } - - /// - /// Portable FloatMap (*.PFM) - /// - public static FreeImagePlugin PFM { get { return plugins[32]; } } - - /// - /// Macintosh PICT (*.PICT) - /// - public static FreeImagePlugin PICT { get { return plugins[33]; } } - - /// - /// RAW camera image (*.*) - /// - public static FreeImagePlugin RAW { get { return plugins[34]; } } - } -} - -namespace FreeImageAPI -{ - /// - /// Provides methods for working with generic bitmap scanlines. - /// - /// Type of the bitmaps' scanlines. - public sealed class Scanline : MemoryArray where T : struct - { - /// - /// Initializes a new instance based on the specified FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - public Scanline(FIBITMAP dib) - : this(dib, 0) - { - } - - /// - /// Initializes a new instance based on the specified FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// Index of the zero based scanline. - public Scanline(FIBITMAP dib, int scanline) - : this(dib, scanline, (int)(typeof(T) == typeof(FI1BIT) ? - FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib) : - typeof(T) == typeof(FI4BIT) ? - FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib) / 4 : - (FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib)) / (Marshal.SizeOf(typeof(T)) * 8))) - { - } - - internal Scanline(FIBITMAP dib, int scanline, int length) - : base(FreeImage.GetScanLine(dib, scanline), length) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - if ((scanline < 0) || (scanline >= FreeImage.GetHeight(dib))) - { - throw new ArgumentOutOfRangeException("scanline"); - } - } - } -} - -namespace FreeImageAPI.IO -{ - /// - /// Class wrapping streams, implementing a buffer for read data, - /// so that seek operations can be made. - /// - /// - /// FreeImage can load bitmaps from arbitrary sources. - /// .NET works with different streams like File- or NetConnection-strams. - /// NetConnection streams, which are used to load files from web servers, - /// for example cannot seek. - /// But FreeImage frequently uses the seek operation when loading bitmaps. - /// StreamWrapper wrapps a stream and makes it seekable by caching all read - /// data into an internal MemoryStream to jump back- and forward. - /// StreamWapper is for internal use and only for loading from streams. - /// - internal class StreamWrapper : Stream - { - /// - /// The stream to wrap - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private readonly Stream stream; - - /// - /// The caching stream - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private MemoryStream memoryStream = new MemoryStream(); - - /// - /// Indicates if the wrapped stream reached its end - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool eos = false; - - /// - /// Tells the wrapper to block readings or not - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool blocking = false; - - /// - /// Indicates if the wrapped stream is disposed or not - /// - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private bool disposed = false; - - /// - /// Initializes a new instance based on the specified . - /// - /// The stream to wrap. - /// When true the wrapper always tries to read the requested - /// amount of data from the wrapped stream. - public StreamWrapper(Stream stream, bool blocking) - { - if (!stream.CanRead) - { - throw new ArgumentException("stream is not capable of reading."); - } - this.stream = stream; - this.blocking = blocking; - } - - /// - /// Releases all resources used by the instance. - /// - ~StreamWrapper() - { - Dispose(false); - } - - // The wrapper only accepts readable streams - public override bool CanRead - { - get { checkDisposed(); return true; } - } - - // We implement that feature - public override bool CanSeek - { - get { checkDisposed(); return true; } - } - - // The wrapper is readonly - public override bool CanWrite - { - get { checkDisposed(); return false; } - } - - // Just forward it - public override void Flush() - { - checkDisposed(); - stream.Flush(); - } - - // Calling this property will cause the wrapper to read the stream - // to its end and cache it completely. - public override long Length - { - get - { - checkDisposed(); - if (!eos) - { - Fill(); - } - return memoryStream.Length; - } - } - - // Gets or sets the current position - public override long Position - { - get - { - checkDisposed(); - return memoryStream.Position; - } - set - { - checkDisposed(); - Seek(value, SeekOrigin.Begin); - } - } - - // Implements the reading feature - public override int Read(byte[] buffer, int offset, int count) - { - checkDisposed(); - // total bytes read from memory-stream - int memoryBytes = 0; - // total bytes read from the original stream - int streamBytes = 0; - memoryBytes = memoryStream.Read(buffer, offset, count); - if ((count > memoryBytes) && (!eos)) - { - // read the rest from the original stream (can be 0 bytes) - do - { - int read = stream.Read( - buffer, - offset + memoryBytes + streamBytes, - count - memoryBytes - streamBytes); - streamBytes += read; - if (read == 0) - { - eos = true; - break; - } - if (!blocking) - { - break; - } - } while ((memoryBytes + streamBytes) < count); - // copy the bytes from the original stream into the memory stream - // if 0 bytes were read we write 0 so the memory-stream is not changed - memoryStream.Write(buffer, offset + memoryBytes, streamBytes); - } - return memoryBytes + streamBytes; - } - - // Implements the seeking feature - public override long Seek(long offset, SeekOrigin origin) - { - checkDisposed(); - long newPosition = 0L; - // get new position - switch (origin) - { - case SeekOrigin.Begin: - newPosition = offset; - break; - case SeekOrigin.Current: - newPosition = memoryStream.Position + offset; - break; - case SeekOrigin.End: - // to seek from the end have have to read to the end first - if (!eos) - { - Fill(); - } - newPosition = memoryStream.Length + offset; - break; - default: - throw new ArgumentOutOfRangeException("origin"); - } - // in case the new position is beyond the memory-streams end - // and the original streams end hasn't been reached - // the original stream is read until either the stream ends or - // enough bytes have been read - if ((newPosition > memoryStream.Length) && (!eos)) - { - memoryStream.Position = memoryStream.Length; - int bytesToRead = (int)(newPosition - memoryStream.Length); - byte[] buffer = new byte[1024]; - do - { - bytesToRead -= Read(buffer, 0, (bytesToRead >= buffer.Length) ? buffer.Length : bytesToRead); - } while ((bytesToRead > 0) && (!eos)); - } - memoryStream.Position = (newPosition <= memoryStream.Length) ? newPosition : memoryStream.Length; - return 0; - } - - // No write-support - public override void SetLength(long value) - { - throw new Exception("The method or operation is not implemented."); - } - - // No write-support - public override void Write(byte[] buffer, int offset, int count) - { - throw new Exception("The method or operation is not implemented."); - } - - public void Reset() - { - checkDisposed(); - Position = 0; - } - - // Reads the wrapped stream until its end. - private void Fill() - { - if (!eos) - { - memoryStream.Position = memoryStream.Length; - int bytesRead = 0; - byte[] buffer = new byte[1024]; - do - { - bytesRead = stream.Read(buffer, 0, buffer.Length); - memoryStream.Write(buffer, 0, bytesRead); - } while (bytesRead != 0); - eos = true; - } - } - - public new void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private new void Dispose(bool disposing) - { - if (!disposed) - { - disposed = true; - if (disposing) - { - if (memoryStream != null) - { - memoryStream.Dispose(); - } - } - } - } - - public bool Disposed - { - get { return disposed; } - } - - private void checkDisposed() - { - if (disposed) throw new ObjectDisposedException("StreamWrapper"); - } - } -} - - #endregion - - #region Enums - -namespace FreeImageAPI -{ - /// - /// Enumeration used for color conversions. - /// FREE_IMAGE_COLOR_DEPTH contains several colors to convert to. - /// The default value 'FICD_AUTO'. - /// - [System.Flags] - public enum FREE_IMAGE_COLOR_DEPTH - { - /// - /// Unknown. - /// - FICD_UNKNOWN = 0, - /// - /// Auto selected by the used algorithm. - /// - FICD_AUTO = FICD_UNKNOWN, - /// - /// 1-bit. - /// - FICD_01_BPP = 1, - /// - /// 1-bit using dithering. - /// - FICD_01_BPP_DITHER = FICD_01_BPP, - /// - /// 1-bit using threshold. - /// - FICD_01_BPP_THRESHOLD = FICD_01_BPP | 2, - /// - /// 4-bit. - /// - FICD_04_BPP = 4, - /// - /// 8-bit. - /// - FICD_08_BPP = 8, - /// - /// 16-bit 555 (1 bit remains unused). - /// - FICD_16_BPP_555 = FICD_16_BPP | 2, - /// - /// 16-bit 565 (all bits are used). - /// - FICD_16_BPP = 16, - /// - /// 24-bit. - /// - FICD_24_BPP = 24, - /// - /// 32-bit. - /// - FICD_32_BPP = 32, - /// - /// Reorder palette (make it linear). Only affects 1-, 4- and 8-bit images. - /// The palette is only reordered in case the image is greyscale - /// (all palette entries have the same red, green and blue value). - /// - FICD_REORDER_PALETTE = 1024, - /// - /// Converts the image to greyscale. - /// - FICD_FORCE_GREYSCALE = 2048, - /// - /// Flag to mask out all non color depth flags. - /// - FICD_COLOR_MASK = FICD_01_BPP | FICD_04_BPP | FICD_08_BPP | FICD_16_BPP | FICD_24_BPP | FICD_32_BPP - } -} - -namespace FreeImageAPI -{ - /// - /// List of combinable compare modes. - /// - [System.Flags] - public enum FREE_IMAGE_COMPARE_FLAGS - { - /// - /// Compare headers. - /// - HEADER = 0x1, - /// - /// Compare palettes. - /// - PALETTE = 0x2, - /// - /// Compare pixel data. - /// - DATA = 0x4, - /// - /// Compare meta data. - /// - METADATA = 0x8, - /// - /// Compare everything. - /// - COMPLETE = (HEADER | PALETTE | DATA | METADATA) - } -} - -namespace FreeImageAPI -{ - /// - /// Flags for copying data from a bitmap to another. - /// - public enum FREE_IMAGE_METADATA_COPY - { - /// - /// Exisiting metadata will remain unchanged. - /// - KEEP_EXISITNG = 0x0, - /// - /// Existing metadata will be cleared. - /// - CLEAR_EXISTING = 0x1, - /// - /// Existing metadata will be overwritten. - /// - REPLACE_EXISTING = 0x2 - } -} - -namespace FreeImageAPI -{ - /// - /// List different search modes. - /// - [System.Flags] - public enum MD_SEARCH_FLAGS - { - /// - /// The key of the metadata. - /// - KEY = 0x1, - /// - /// The description of the metadata - /// - DESCRIPTION = 0x2, - /// - /// The ToString value of the metadata - /// - TOSTRING = 0x4, - } -} - - #endregion - -namespace FreeImageAPI -{ - /// - /// Static class importing functions from the FreeImage library - /// and providing additional functions. - /// - public static partial class FreeImage - { - #region Constants - - /// - /// Array containing all 'FREE_IMAGE_MDMODEL's. - /// - public static readonly FREE_IMAGE_MDMODEL[] FREE_IMAGE_MDMODELS = - (FREE_IMAGE_MDMODEL[])Enum.GetValues(typeof(FREE_IMAGE_MDMODEL)); - - /// - /// Stores handles used to read from streams. - /// - private static Dictionary streamHandles = - new Dictionary(); - - /// - /// Version of the wrapper library. - /// - private static Version WrapperVersion; - - private const int DIB_RGB_COLORS = 0; - private const int DIB_PAL_COLORS = 1; - private const int CBM_INIT = 0x4; - - /// - /// An uncompressed format. - /// - public const int BI_RGB = 0; - - /// - /// A run-length encoded (RLE) format for bitmaps with 8 bpp. The compression format is a 2-byte - /// format consisting of a count byte followed by a byte containing a color index. - /// - public const int BI_RLE8 = 1; - - /// - /// An RLE format for bitmaps with 4 bpp. The compression format is a 2-byte format consisting - /// of a count byte followed by two word-length color indexes. - /// - public const int BI_RLE4 = 2; - - /// - /// Specifies that the bitmap is not compressed and that the color table consists of three - /// DWORD color masks that specify the red, green, and blue components, respectively, - /// of each pixel. This is valid when used with 16- and 32-bpp bitmaps. - /// - public const int BI_BITFIELDS = 3; - - /// - /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a JPEG image. - /// - public const int BI_JPEG = 4; - - /// - /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a PNG image. - /// - public const int BI_PNG = 5; - - #endregion - - #region General functions - - /// - /// Returns the internal version of this FreeImage .NET wrapper. - /// - /// The internal version of this FreeImage .NET wrapper. - public static Version GetWrapperVersion() - { - if (WrapperVersion == null) - { - try - { - object[] attributes = Assembly.GetAssembly(typeof(FreeImage)) - .GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false); - if ((attributes != null) && (attributes.Length != 0)) - { - AssemblyFileVersionAttribute attribute = - attributes[0] as AssemblyFileVersionAttribute; - if ((attribute != null) && (attribute.Version != null)) - { - return (WrapperVersion = new Version(attribute.Version)); - } - } - } - catch - { - - } - - WrapperVersion = new Version(); - } - - return WrapperVersion; - } - - /// - /// Returns the version of the native FreeImage library. - /// - /// The version of the native FreeImage library. - public static Version GetNativeVersion() - { - return new Version(GetVersion()); - } - - /// - /// Returns a value indicating if the FreeImage library is available or not. - /// See remarks for further details. - /// - /// false if the file is not available or out of date; - /// true, otherwise. - /// - /// The FreeImage.NET library is a wrapper for the native C++ library - /// (FreeImage.dll ... dont mix ist up with this library FreeImageNet.dll). - /// The native library must be either in the same folder as the program's - /// executable or in a folder contained in the envirent variable PATH - /// (for example %WINDIR%\System32). - /// Further more must both libraries, including the program itself, - /// be the same architecture (x86 or x64). - /// - public static bool IsAvailable() - { - try - { - // Call a static fast executing function - Version nativeVersion = new Version(GetVersion()); - Version wrapperVersion = GetWrapperVersion(); - // No exception thrown, the library seems to be present - return - (nativeVersion.Major >= wrapperVersion.Major) && - (nativeVersion.Minor >= wrapperVersion.Minor) && - (nativeVersion.Build >= wrapperVersion.Build); - } - catch (DllNotFoundException) - { - return false; - } - catch (EntryPointNotFoundException) - { - return false; - } - catch (BadImageFormatException) - { - return false; - } - } - - #endregion - - #region Bitmap management functions - - /// - /// Creates a new bitmap in memory. - /// - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new Bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap - /// Handle to a FreeImage bitmap. - public static FIBITMAP Allocate(int width, int height, int bpp) - { - return Allocate(width, height, bpp, 0, 0, 0); - } - - /// - /// Creates a new bitmap in memory. - /// - /// Type of the image. - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new Bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap - /// Handle to a FreeImage bitmap. - public static FIBITMAP AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp) - { - return AllocateT(type, width, height, bpp, 0, 0, 0); - } - - /// - /// Allocates a new image of the specified width, height and bit depth and optionally - /// fills it with the specified color. See remarks for further details. - /// - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmaps. - /// The color to fill the bitmap with or null. - /// Options to enable or disable function-features. - /// The palette of the bitmap or null. - /// Handle to a FreeImage bitmap. - /// - /// This function is an extension to , which additionally supports - /// specifying a palette to be set for the newly create image, as well as specifying a - /// background color, the newly created image should initially be filled with. - /// - /// Basically, this function internally relies on function , followed by a - /// call to . This is why both parameters - /// and behave the same as it is - /// documented for function . - /// So, please refer to the documentation of to - /// learn more about parameters and . - /// - /// The palette specified through parameter is only copied to the - /// newly created image, if the desired bit depth is smaller than or equal to 8 bits per pixel. - /// In other words, the parameter is only taken into account for - /// palletized images. So, for an 8-bit image, the length is 256, for an 4-bit image it is 16 - /// and it is 2 for a 1-bit image. In other words, this function does not support partial palettes. - /// - /// However, specifying a palette is not necesarily needed, even for palletized images. This - /// function is capable of implicitly creating a palette, if is null. - /// If the specified background color is a greyscale value (red = green = blue) or if option - /// is specified, a greyscale palette - /// is created. For a 1-bit image, only if the specified background color is either black or white, - /// a monochrome palette, consisting of black and white only is created. In any case, the darker - /// colors are stored at the smaller palette indices. - /// - /// If the specified background color is not a greyscale value, or is neither black nor white - /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized - /// palette. For this operation, option - /// is implicit, so the specified is applied to the palette entry, - /// specified by the background color's field. - /// The image is then filled with this palette index. - /// - /// This function returns a newly created image as function does, if both - /// parameters and are null. - /// If only is null, the palette pointed to by - /// parameter is initially set for the new image, if a palletized - /// image of type is created. - /// However, in the latter case, this function returns an image, whose - /// pixels are all initialized with zeros so, the image will be filled with the color of the - /// first palette entry. - /// - public static FIBITMAP AllocateEx(int width, int height, int bpp, - RGBQUAD? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette) - { - return AllocateEx(width, height, bpp, color, options, palette, 0, 0, 0); - } - - /// - /// Allocates a new image of the specified width, height and bit depth and optionally - /// fills it with the specified color. See remarks for further details. - /// - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmaps. - /// The color to fill the bitmap with or null. - /// Options to enable or disable function-features. - /// The palette of the bitmap or null. - /// Red part of the color layout. - /// eg: 0xFF0000 - /// Green part of the color layout. - /// eg: 0x00FF00 - /// Blue part of the color layout. - /// eg: 0x0000FF - /// Handle to a FreeImage bitmap. - /// - /// This function is an extension to , which additionally supports - /// specifying a palette to be set for the newly create image, as well as specifying a - /// background color, the newly created image should initially be filled with. - /// - /// Basically, this function internally relies on function , followed by a - /// call to . This is why both parameters - /// and behave the same as it is - /// documented for function . - /// So, please refer to the documentation of to - /// learn more about parameters and . - /// - /// The palette specified through parameter is only copied to the - /// newly created image, if the desired bit depth is smaller than or equal to 8 bits per pixel. - /// In other words, the parameter is only taken into account for - /// palletized images. So, for an 8-bit image, the length is 256, for an 4-bit image it is 16 - /// and it is 2 for a 1-bit image. In other words, this function does not support partial palettes. - /// - /// However, specifying a palette is not necesarily needed, even for palletized images. This - /// function is capable of implicitly creating a palette, if is null. - /// If the specified background color is a greyscale value (red = green = blue) or if option - /// is specified, a greyscale palette - /// is created. For a 1-bit image, only if the specified background color is either black or white, - /// a monochrome palette, consisting of black and white only is created. In any case, the darker - /// colors are stored at the smaller palette indices. - /// - /// If the specified background color is not a greyscale value, or is neither black nor white - /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized - /// palette. For this operation, option - /// is implicit, so the specified is applied to the palette entry, - /// specified by the background color's field. - /// The image is then filled with this palette index. - /// - /// This function returns a newly created image as function does, if both - /// parameters and are null. - /// If only is null, the palette pointed to by - /// parameter is initially set for the new image, if a palletized - /// image of type is created. - /// However, in the latter case, this function returns an image, whose - /// pixels are all initialized with zeros so, the image will be filled with the color of the - /// first palette entry. - /// - public static FIBITMAP AllocateEx(int width, int height, int bpp, - RGBQUAD? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, - uint red_mask, uint green_mask, uint blue_mask) - { - if ((palette != null) && (bpp <= 8) && (palette.Length < (1 << bpp))) - return FIBITMAP.Zero; - - if (color.HasValue) - { - GCHandle handle = new GCHandle(); - try - { - RGBQUAD[] buffer = new RGBQUAD[] { color.Value }; - handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - return AllocateEx(width, height, bpp, handle.AddrOfPinnedObject(), - options, palette, red_mask, green_mask, blue_mask); - } - finally - { - if (handle.IsAllocated) - handle.Free(); - } - } - else - { - return AllocateEx(width, height, bpp, IntPtr.Zero, - options, palette, red_mask, green_mask, blue_mask); - } - } - - /// - /// Allocates a new image of the specified type, width, height and bit depth and optionally - /// fills it with the specified color. See remarks for further details. - /// - /// The type of the specified color. - /// Type of the image. - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap - /// The color to fill the bitmap with or null. - /// Options to enable or disable function-features. - /// The palette of the bitmap or null. - /// Handle to a FreeImage bitmap. - /// - /// This function is an extension to , which additionally supports - /// specifying a palette to be set for the newly create image, as well as specifying a - /// background color, the newly created image should initially be filled with. - /// - /// Basically, this function internally relies on function , followed by a - /// call to . This is why both parameters - /// and behave the same as it is - /// documented for function . So, please refer to the - /// documentation of to learn more about parameters color and options. - /// - /// The palette specified through parameter palette is only copied to the newly created - /// image, if its image type is and the desired bit - /// depth is smaller than or equal to 8 bits per pixel. In other words, the - /// palette is only taken into account for palletized images. However, if the preceding conditions - /// match and if is not null, the palette is assumed to be at - /// least as large as the size of a fully populated palette for the desired bit depth. - /// So, for an 8-bit image, this length is 256, for an 4-bit image it is 16 and it is - /// 2 for a 1-bit image. In other words, this function does not support partial palettes. - /// - /// However, specifying a palette is not necesarily needed, even for palletized images. This - /// function is capable of implicitly creating a palette, if is null. - /// If the specified background color is a greyscale value (red = green = blue) or if option - /// is specified, a greyscale palette - /// is created. For a 1-bit image, only if the specified background color is either black or white, - /// a monochrome palette, consisting of black and white only is created. In any case, the darker - /// colors are stored at the smaller palette indices. - /// - /// If the specified background color is not a greyscale value, or is neither black nor white - /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized - /// palette. For this operation, option - /// is implicit, so the specified color is applied to the palette entry, specified by the - /// background color's field. The image is then filled with - /// this palette index. - /// - /// This function returns a newly created image as function does, if both - /// parameters and are null. - /// If only is null, the palette pointed to by - /// parameter is initially set for the new image, if a palletized - /// image of type is created. - /// However, in the latter case, this function returns an image, whose - /// pixels are all initialized with zeros so, the image will be filled with the color of the - /// first palette entry. - /// - public static FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp, - T? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette) where T : struct - { - return AllocateExT(type, width, height, bpp, color, options, palette, 0, 0, 0); - } - - /// - /// Allocates a new image of the specified type, width, height and bit depth and optionally - /// fills it with the specified color. See remarks for further details. - /// - /// The type of the specified color. - /// Type of the image. - /// Width of the new bitmap. - /// Height of the new bitmap. - /// Bit depth of the new bitmap. - /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap - /// The color to fill the bitmap with or null. - /// Options to enable or disable function-features. - /// The palette of the bitmap or null. - /// Red part of the color layout. - /// eg: 0xFF0000 - /// Green part of the color layout. - /// eg: 0x00FF00 - /// Blue part of the color layout. - /// eg: 0x0000FF - /// Handle to a FreeImage bitmap. - /// - /// This function is an extension to , which additionally supports - /// specifying a palette to be set for the newly create image, as well as specifying a - /// background color, the newly created image should initially be filled with. - /// - /// Basically, this function internally relies on function , followed by a - /// call to . This is why both parameters - /// and behave the same as it is - /// documented for function . So, please refer to the - /// documentation of to learn more about parameters color and options. - /// - /// The palette specified through parameter palette is only copied to the newly created - /// image, if its image type is and the desired bit - /// depth is smaller than or equal to 8 bits per pixel. In other words, the - /// palette is only taken into account for palletized images. However, if the preceding conditions - /// match and if is not null, the palette is assumed to be at - /// least as large as the size of a fully populated palette for the desired bit depth. - /// So, for an 8-bit image, this length is 256, for an 4-bit image it is 16 and it is - /// 2 for a 1-bit image. In other words, this function does not support partial palettes. - /// - /// However, specifying a palette is not necesarily needed, even for palletized images. This - /// function is capable of implicitly creating a palette, if is null. - /// If the specified background color is a greyscale value (red = green = blue) or if option - /// is specified, a greyscale palette - /// is created. For a 1-bit image, only if the specified background color is either black or white, - /// a monochrome palette, consisting of black and white only is created. In any case, the darker - /// colors are stored at the smaller palette indices. - /// - /// If the specified background color is not a greyscale value, or is neither black nor white - /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized - /// palette. For this operation, option - /// is implicit, so the specified color is applied to the palette entry, specified by the - /// background color's field. The image is then filled with - /// this palette index. - /// - /// This function returns a newly created image as function does, if both - /// parameters and are null. - /// If only is null, the palette pointed to by - /// parameter is initially set for the new image, if a palletized - /// image of type is created. - /// However, in the latter case, this function returns an image, whose - /// pixels are all initialized with zeros so, the image will be filled with the color of the - /// first palette entry. - /// - public static FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp, - T? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, - uint red_mask, uint green_mask, uint blue_mask) where T : struct - { - if ((palette != null) && (bpp <= 8) && (palette.Length < (1 << bpp))) - return FIBITMAP.Zero; - - if (!CheckColorType(type, color)) - return FIBITMAP.Zero; - - if (color.HasValue) - { - GCHandle handle = new GCHandle(); - try - { - T[] buffer = new T[] { color.Value }; - handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - return AllocateExT(type, width, height, bpp, handle.AddrOfPinnedObject(), - options, palette, red_mask, green_mask, blue_mask); - } - finally - { - if (handle.IsAllocated) - handle.Free(); - } - } - else - { - return AllocateExT(type, width, height, bpp, IntPtr.Zero, - options, palette, red_mask, green_mask, blue_mask); - } - } - - /// - /// Converts a FreeImage bitmap to a .NET . - /// - /// Handle to a FreeImage bitmap. - /// The converted .NET . - /// Copying metadata has been disabled until a proper way - /// of reading and storing metadata in a .NET bitmap is found. - /// - /// is null. - /// - /// The image type of is not FIT_BITMAP. - public static Bitmap GetBitmap(FIBITMAP dib) - { - return GetBitmap(dib, true); - } - - /// - /// Converts a FreeImage bitmap to a .NET . - /// - /// Handle to a FreeImage bitmap. - /// When true existing metadata will be copied. - /// The converted .NET . - /// Copying metadata has been disabled until a proper way - /// of reading and storing metadata in a .NET bitmap is found. - /// - /// is null. - /// - /// The image type of is not FIT_BITMAP. - internal static Bitmap GetBitmap(FIBITMAP dib, bool copyMetadata) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - if (GetImageType(dib) != FREE_IMAGE_TYPE.FIT_BITMAP) - { - throw new ArgumentException("Only bitmaps with type of FIT_BITMAP can be converted."); - } - - PixelFormat format = GetPixelFormat(dib); - - if ((format == PixelFormat.Undefined) && (GetBPP(dib) == 16u)) - { - throw new ArgumentException("Only 16bit 555 and 565 are supported."); - } - - int height = (int)GetHeight(dib); - int width = (int)GetWidth(dib); - int pitch = (int)GetPitch(dib); - - Bitmap result = new Bitmap(width, height, format); - BitmapData data; - // Locking the complete bitmap in writeonly mode - data = result.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, format); - // Writing the bitmap data directly into the new created .NET bitmap. - ConvertToRawBits(data.Scan0, dib, pitch, GetBPP(dib), - GetRedMask(dib), GetGreenMask(dib), GetBlueMask(dib), true); - // Unlock the bitmap - result.UnlockBits(data); - // Apply the bitmaps resolution - result.SetResolution(GetResolutionX(dib), GetResolutionY(dib)); - // Check whether the bitmap has a palette - if (GetPalette(dib) != IntPtr.Zero) - { - // Get the bitmaps palette to apply changes - ColorPalette palette = result.Palette; - // Get the orgininal palette - Color[] colorPalette = new Palette(dib).ColorData; - // Get the maximum number of palette entries to copy - int entriesToCopy = Math.Min(colorPalette.Length, palette.Entries.Length); - - // Check whether the bitmap is transparent - if (IsTransparent(dib)) - { - byte[] transTable = GetTransparencyTableEx(dib); - int i = 0; - int maxEntriesWithTrans = Math.Min(entriesToCopy, transTable.Length); - // Copy palette entries and include transparency - for (; i < maxEntriesWithTrans; i++) - { - palette.Entries[i] = Color.FromArgb(transTable[i], colorPalette[i]); - } - // Copy palette entries and that have no transparancy - for (; i < entriesToCopy; i++) - { - palette.Entries[i] = Color.FromArgb(0xFF, colorPalette[i]); - } - } - else - { - for (int i = 0; i < entriesToCopy; i++) - { - palette.Entries[i] = colorPalette[i]; - } - } - - // Set the bitmaps palette - result.Palette = palette; - } - // Copy metadata - if (copyMetadata) - { - try - { - List list = new List(); - // Get a list of all types - FITAG tag; - FIMETADATA mData; - foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS) - { - // Get a unique search handle - mData = FindFirstMetadata(model, dib, out tag); - // Check if metadata exists for this type - if (mData.IsNull) continue; - do - { - PropertyItem propItem = CreatePropertyItem(); - propItem.Len = (int)GetTagLength(tag); - propItem.Id = (int)GetTagID(tag); - propItem.Type = (short)GetTagType(tag); - byte[] buffer = new byte[propItem.Len]; - - unsafe - { - byte* src = (byte*)GetTagValue(tag); - fixed (byte* dst = buffer) - { - CopyMemory(dst, src, (uint)propItem.Len); - } - } - - propItem.Value = buffer; - list.Add(propItem); - } - while (FindNextMetadata(mData, out tag)); - FindCloseMetadata(mData); - } - foreach (PropertyItem propItem in list) - { - result.SetPropertyItem(propItem); - } - } - catch - { - } - } - return result; - } - - /// - /// Converts an .NET into a FreeImage bitmap. - /// - /// The to convert. - /// Handle to a FreeImage bitmap. - /// Copying metadata has been disabled until a proper way - /// of reading and storing metadata in a .NET bitmap is found. - /// - /// is null. - /// - /// The bitmaps pixelformat is invalid. - public static FIBITMAP CreateFromBitmap(Bitmap bitmap) - { - return CreateFromBitmap(bitmap, false); - } - - /// - /// Converts an .NET into a FreeImage bitmap. - /// - /// The to convert. - /// When true existing metadata will be copied. - /// Handle to a FreeImage bitmap. - /// Copying metadata has been disabled until a proper way - /// of reading and storing metadata in a .NET bitmap is found. - /// - /// is null. - /// - /// The bitmaps pixelformat is invalid. - internal static FIBITMAP CreateFromBitmap(Bitmap bitmap, bool copyMetadata) - { - if (bitmap == null) - { - throw new ArgumentNullException("bitmap"); - } - uint bpp, red_mask, green_mask, blue_mask; - FREE_IMAGE_TYPE type; - if (!GetFormatParameters(bitmap.PixelFormat, out type, out bpp, out red_mask, out green_mask, out blue_mask)) - { - throw new ArgumentException("The bitmaps pixelformat is invalid."); - } - - // Locking the complete bitmap in readonly mode - BitmapData data = bitmap.LockBits( - new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat); - // Copying the bitmap data directly from the .NET bitmap - FIBITMAP result = ConvertFromRawBits( - data.Scan0, - type, - data.Width, - data.Height, - data.Stride, - bpp, - red_mask, - green_mask, - blue_mask, - true); - bitmap.UnlockBits(data); - // Handle palette - if (GetPalette(result) != IntPtr.Zero) - { - Palette palette = new Palette(result); - Color[] colors = bitmap.Palette.Entries; - // Only copy available palette entries - int entriesToCopy = Math.Min(palette.Length, colors.Length); - byte[] transTable = new byte[entriesToCopy]; - for (int i = 0; i < entriesToCopy; i++) - { - RGBQUAD color = (RGBQUAD)colors[i]; - color.rgbReserved = 0x00; - palette[i] = color; - transTable[i] = colors[i].A; - } - if ((bitmap.Flags & (int)ImageFlags.HasAlpha) != 0) - { - FreeImage.SetTransparencyTable(result, transTable); - } - } - // Handle meta data - // Disabled - //if (copyMetadata) - //{ - // foreach (PropertyItem propItem in bitmap.PropertyItems) - // { - // FITAG tag = CreateTag(); - // SetTagLength(tag, (uint)propItem.Len); - // SetTagID(tag, (ushort)propItem.Id); - // SetTagType(tag, (FREE_IMAGE_MDTYPE)propItem.Type); - // SetTagValue(tag, propItem.Value); - // SetMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, result, "", tag); - // } - //} - return result; - } - - /// - /// Converts a raw bitmap to a FreeImage bitmap. - /// - /// Array of bytes containing the raw bitmap. - /// The type of the raw bitmap. - /// The width in pixels of the raw bitmap. - /// The height in pixels of the raw bitmap. - /// Defines the total width of a scanline in the raw bitmap, - /// including padding bytes. - /// The bit depth (bits per pixel) of the raw bitmap. - /// The bit mask describing the bits used to store a single - /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// If true, the raw bitmap is stored in top-down order (top-left pixel first) - /// and in bottom-up order (bottom-left pixel first) otherwise. - /// Handle to a FreeImage bitmap. - public static unsafe FIBITMAP ConvertFromRawBits( - byte[] bits, - FREE_IMAGE_TYPE type, - int width, - int height, - int pitch, - uint bpp, - uint red_mask, - uint green_mask, - uint blue_mask, - bool topdown) - { - fixed (byte* ptr = bits) - { - return ConvertFromRawBits( - (IntPtr)ptr, - type, - width, - height, - pitch, - bpp, - red_mask, - green_mask, - blue_mask, - topdown); - } - } - - /// - /// Converts a raw bitmap to a FreeImage bitmap. - /// - /// Pointer to the memory block containing the raw bitmap. - /// The type of the raw bitmap. - /// The width in pixels of the raw bitmap. - /// The height in pixels of the raw bitmap. - /// Defines the total width of a scanline in the raw bitmap, - /// including padding bytes. - /// The bit depth (bits per pixel) of the raw bitmap. - /// The bit mask describing the bits used to store a single - /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// The bit mask describing the bits used to store a single - /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. - /// If true, the raw bitmap is stored in top-down order (top-left pixel first) - /// and in bottom-up order (bottom-left pixel first) otherwise. - /// Handle to a FreeImage bitmap. - public static unsafe FIBITMAP ConvertFromRawBits( - IntPtr bits, - FREE_IMAGE_TYPE type, - int width, - int height, - int pitch, - uint bpp, - uint red_mask, - uint green_mask, - uint blue_mask, - bool topdown) - { - byte* addr = (byte*)bits; - if ((addr == null) || (width <= 0) || (height <= 0)) - { - return FIBITMAP.Zero; - } - - FIBITMAP dib = AllocateT(type, width, height, (int)bpp, red_mask, green_mask, blue_mask); - if (dib != FIBITMAP.Zero) - { - if (topdown) - { - for (int i = height - 1; i >= 0; --i) - { - CopyMemory((byte*)GetScanLine(dib, i), addr, (int)GetLine(dib)); - addr += pitch; - } - } - else - { - for (int i = 0; i < height; ++i) - { - CopyMemory((byte*)GetScanLine(dib, i), addr, (int)GetLine(dib)); - addr += pitch; - } - } - } - return dib; - } - - /// - /// Saves a .NET to a file. - /// - /// The .NET to save. - /// Name of the file to save to. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// The bitmaps pixelformat is invalid. - public static bool SaveBitmap(Bitmap bitmap, string filename) - { - return SaveBitmap( - bitmap, - filename, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - /// - /// Saves a .NET to a file. - /// - /// The .NET to save. - /// Name of the file to save to. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// The bitmaps pixelformat is invalid. - public static bool SaveBitmap(Bitmap bitmap, string filename, FREE_IMAGE_SAVE_FLAGS flags) - { - return SaveBitmap( - bitmap, - filename, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - flags); - } - - /// - /// Saves a .NET to a file. - /// - /// The .NET to save. - /// Name of the file to save to. - /// Format of the bitmap. If the format should be taken from the - /// filename use . - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// The bitmaps pixelformat is invalid. - public static bool SaveBitmap( - Bitmap bitmap, - string filename, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_SAVE_FLAGS flags) - { - FIBITMAP dib = CreateFromBitmap(bitmap); - bool result = SaveEx(dib, filename, format, flags); - Unload(dib); - return result; - } - - /// - /// Loads a FreeImage bitmap. - /// The file will be loaded with default loading flags. - /// - /// The complete name of the file to load. - /// Handle to a FreeImage bitmap. - /// - /// does not exists. - public static FIBITMAP LoadEx(string filename) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return LoadEx(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); - } - - /// - /// Loads a FreeImage bitmap. - /// Load flags can be provided by the flags parameter. - /// - /// The complete name of the file to load. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage bitmap. - /// - /// does not exists. - public static FIBITMAP LoadEx(string filename, FREE_IMAGE_LOAD_FLAGS flags) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return LoadEx(filename, flags, ref format); - } - - /// - /// Loads a FreeImage bitmap. - /// In case the loading format is the files - /// real format is being analysed. If no plugin can read the file, format remains - /// and 0 is returned. - /// The file will be loaded with default loading flags. - /// - /// The complete name of the file to load. - /// Format of the image. If the format is unknown use - /// . - /// In case a suitable format was found by LoadEx it will be returned in format. - /// Handle to a FreeImage bitmap. - /// - /// does not exists. - public static FIBITMAP LoadEx(string filename, ref FREE_IMAGE_FORMAT format) - { - return LoadEx(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); - } - - /// - /// Loads a FreeImage bitmap. - /// In case the loading format is the files - /// real format is being analysed. If no plugin can read the file, format remains - /// and 0 is returned. - /// Load flags can be provided by the flags parameter. - /// - /// The complete name of the file to load. - /// Flags to enable or disable plugin-features. - /// Format of the image. If the format is unknown use - /// . - /// In case a suitable format was found by LoadEx it will be returned in format. - /// - /// Handle to a FreeImage bitmap. - /// - /// does not exists. - public static FIBITMAP LoadEx(string filename, FREE_IMAGE_LOAD_FLAGS flags, ref FREE_IMAGE_FORMAT format) - { - // check if file exists - if (!File.Exists(filename)) - { - throw new FileNotFoundException(filename + " could not be found."); - } - FIBITMAP dib = new FIBITMAP(); - if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) - { - // query all plugins to see if one can read the file - format = GetFileType(filename, 0); - } - // check if the plugin is capable of loading files - if (FIFSupportsReading(format)) - { - dib = Load(format, filename, flags); - } - return dib; - } - - /// - /// Loads a .NET from a file. - /// - /// Name of the file to be loaded. - /// Format of the image. If the format should be taken from the - /// filename use . - /// Flags to enable or disable plugin-features. - /// The loaded .NET . - /// - /// does not exists. - /// - /// The image type of the image is not . - public static Bitmap LoadBitmap(string filename, FREE_IMAGE_LOAD_FLAGS flags, ref FREE_IMAGE_FORMAT format) - { - FIBITMAP dib = LoadEx(filename, flags, ref format); - Bitmap result = GetBitmap(dib, true); - Unload(dib); - return result; - } - - /// - /// Deletes a previously loaded FreeImage bitmap from memory and resets the handle to 0. - /// - /// Handle to a FreeImage bitmap. - public static void UnloadEx(ref FIBITMAP dib) - { - if (!dib.IsNull) - { - Unload(dib); - dib.SetNull(); - } - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// The format is taken off the filename. - /// If no suitable format was found false will be returned. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified. - /// Returns true on success, false on failure. - /// - /// or is null. - public static bool SaveEx(FIBITMAP dib, string filename) - { - return SaveEx( - ref dib, - filename, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - FREE_IMAGE_SAVE_FLAGS.DEFAULT, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - false); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// In case the loading format is - /// the format is taken off the filename. - /// If no suitable format was found false will be returned. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified. - /// Format of the image. If the format should be taken from the - /// filename use . - /// Returns true on success, false on failure. - /// - /// or is null. - public static bool SaveEx( - FIBITMAP dib, - string filename, - FREE_IMAGE_FORMAT format) - { - return SaveEx( - ref dib, - filename, - format, - FREE_IMAGE_SAVE_FLAGS.DEFAULT, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - false); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// The format is taken off the filename. - /// If no suitable format was found false will be returned. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified. - /// When true the structure will be unloaded on success. - /// If the function failed and returned false, the bitmap was not unloaded. - /// Returns true on success, false on failure. - /// - /// or is null. - public static bool SaveEx( - ref FIBITMAP dib, - string filename, - bool unloadSource) - { - return SaveEx( - ref dib, - filename, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - FREE_IMAGE_SAVE_FLAGS.DEFAULT, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - unloadSource); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// The format is taken off the filename. - /// If no suitable format was found false will be returned. - /// Save flags can be provided by the flags parameter. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - /// - /// or is null. - public static bool SaveEx( - FIBITMAP dib, - string filename, - FREE_IMAGE_SAVE_FLAGS flags) - { - return SaveEx( - ref dib, - filename, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - flags, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - false); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// The format is taken off the filename. - /// If no suitable format was found false will be returned. - /// Save flags can be provided by the flags parameter. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified. - /// Flags to enable or disable plugin-features. - /// When true the structure will be unloaded on success. - /// If the function failed and returned false, the bitmap was not unloaded. - /// Returns true on success, false on failure. - /// - /// or is null. - public static bool SaveEx( - ref FIBITMAP dib, - string filename, - FREE_IMAGE_SAVE_FLAGS flags, - bool unloadSource) - { - return SaveEx( - ref dib, - filename, - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - flags, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - unloadSource); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// In case the loading format is - /// the format is taken off the filename. - /// If no suitable format was found false will be returned. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified. - /// Format of the image. If the format should be taken from the - /// filename use . - /// When true the structure will be unloaded on success. - /// If the function failed and returned false, the bitmap was not unloaded. - /// Returns true on success, false on failure. - /// - /// or is null. - public static bool SaveEx( - ref FIBITMAP dib, - string filename, - FREE_IMAGE_FORMAT format, - bool unloadSource) - { - return SaveEx( - ref dib, - filename, - format, - FREE_IMAGE_SAVE_FLAGS.DEFAULT, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - unloadSource); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// In case the loading format is - /// the format is taken off the filename. - /// If no suitable format was found false will be returned. - /// Save flags can be provided by the flags parameter. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified. - /// Format of the image. If the format should be taken from the - /// filename use . - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - /// - /// or is null. - public static bool SaveEx( - FIBITMAP dib, - string filename, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_SAVE_FLAGS flags) - { - return SaveEx( - ref dib, - filename, - format, - flags, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - false); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a file. - /// In case the loading format is - /// the format is taken off the filename. - /// If no suitable format was found false will be returned. - /// Save flags can be provided by the flags parameter. - /// The bitmaps color depth can be set by 'colorDepth'. - /// If set to a suitable color depth - /// will be taken if available. - /// - /// Handle to a FreeImage bitmap. - /// The complete name of the file to save to. - /// The extension will be corrected if it is no valid extension for the - /// selected format or if no extension was specified. - /// Format of the image. If the format should be taken from the - /// filename use . - /// Flags to enable or disable plugin-features. - /// The new color depth of the bitmap. - /// Set to if Save should take the - /// best suitable color depth. - /// If a color depth is selected that the provided format cannot write an - /// error-message will be thrown. - /// When true the structure will be unloaded on success. - /// If the function failed and returned false, the bitmap was not unloaded. - /// Returns true on success, false on failure. - /// - /// A direct color conversion failed. - /// - /// or is null. - public static bool SaveEx( - ref FIBITMAP dib, - string filename, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_SAVE_FLAGS flags, - FREE_IMAGE_COLOR_DEPTH colorDepth, - bool unloadSource) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - if (filename == null) - { - throw new ArgumentNullException("filename"); - } - bool result = false; - // Gets format from filename if the format is unknown - if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) - { - format = GetFIFFromFilename(filename); - } - if (format != FREE_IMAGE_FORMAT.FIF_UNKNOWN) - { - // Checks writing support - if (FIFSupportsWriting(format) && FIFSupportsExportType(format, GetImageType(dib))) - { - // Check valid filename and correct it if needed - if (!IsFilenameValidForFIF(format, filename)) - { - string extension = GetPrimaryExtensionFromFIF(format); - filename = Path.ChangeExtension(filename, extension); - } - - FIBITMAP dibToSave = PrepareBitmapColorDepth(dib, format, colorDepth); - try - { - result = Save(format, dibToSave, filename, flags); - } - finally - { - // Always unload a temporary created bitmap. - if (dibToSave != dib) - { - UnloadEx(ref dibToSave); - } - // On success unload the bitmap - if (result && unloadSource) - { - UnloadEx(ref dib); - } - } - } - } - return result; - } - - /// - /// Loads a FreeImage bitmap. - /// The stream must be set to the correct position before calling LoadFromStream. - /// - /// The stream to read from. - /// Handle to a FreeImage bitmap. - /// - /// is null. - /// - /// is not capable of reading. - public static FIBITMAP LoadFromStream(Stream stream) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return LoadFromStream(stream, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); - } - - /// - /// Loads a FreeImage bitmap. - /// The stream must be set to the correct position before calling LoadFromStream. - /// - /// The stream to read from. - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage bitmap. - /// - /// is null. - /// - /// is not capable of reading. - public static FIBITMAP LoadFromStream(Stream stream, FREE_IMAGE_LOAD_FLAGS flags) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return LoadFromStream(stream, flags, ref format); - } - - /// - /// Loads a FreeImage bitmap. - /// In case the loading format is the - /// bitmaps real format is being analysed. - /// The stream must be set to the correct position before calling LoadFromStream. - /// - /// The stream to read from. - /// Format of the image. If the format is unknown use - /// . - /// In case a suitable format was found by LoadFromStream it will be returned in format. - /// Handle to a FreeImage bitmap. - /// - /// is null. - /// - /// is not capable of reading. - public static FIBITMAP LoadFromStream(Stream stream, ref FREE_IMAGE_FORMAT format) - { - return LoadFromStream(stream, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); - } - - /// - /// Loads a FreeImage bitmap. - /// In case the loading format is - /// the bitmaps real format is being analysed. - /// The stream must be set to the correct position before calling LoadFromStream. - /// - /// The stream to read from. - /// Flags to enable or disable plugin-features. - /// Format of the image. If the format is unknown use - /// . - /// In case a suitable format was found by LoadFromStream it will be returned in format. - /// Handle to a FreeImage bitmap. - /// - /// is null. - /// - /// is not capable of reading. - public static FIBITMAP LoadFromStream( - Stream stream, - FREE_IMAGE_LOAD_FLAGS flags, - ref FREE_IMAGE_FORMAT format) - { - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - if (!stream.CanRead) - { - throw new ArgumentException("stream is not capable of reading."); - } - // Wrap the source stream if it is unable to seek (which is required by FreeImage) - stream = (stream.CanSeek) ? stream : new StreamWrapper(stream, true); - - stream.Position = 0L; - if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) - { - // Get the format of the bitmap - format = GetFileTypeFromStream(stream); - // Restore the streams position - stream.Position = 0L; - } - if (!FIFSupportsReading(format)) - { - return FIBITMAP.Zero; - } - // Create a 'FreeImageIO' structure for calling 'LoadFromHandle' - // using the internal structure 'FreeImageStreamIO'. - FreeImageIO io = FreeImageStreamIO.io; - using (fi_handle handle = new fi_handle(stream)) - { - return LoadFromHandle(format, ref io, handle, flags); - } - } - - /// - /// Saves a previously loaded FreeImage bitmap to a stream. - /// The stream must be set to the correct position before calling SaveToStream. - /// - /// Handle to a FreeImage bitmap. - /// The stream to write to. - /// Format of the image. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// cannot write. - public static bool SaveToStream( - FIBITMAP dib, - Stream stream, - FREE_IMAGE_FORMAT format) - { - return SaveToStream( - ref dib, - stream, - format, - FREE_IMAGE_SAVE_FLAGS.DEFAULT, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - false); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a stream. - /// The stream must be set to the correct position before calling SaveToStream. - /// - /// Handle to a FreeImage bitmap. - /// The stream to write to. - /// Format of the image. - /// When true the structure will be unloaded on success. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// cannot write. - public static bool SaveToStream( - ref FIBITMAP dib, - Stream stream, - FREE_IMAGE_FORMAT format, - bool unloadSource) - { - return SaveToStream( - ref dib, - stream, - format, - FREE_IMAGE_SAVE_FLAGS.DEFAULT, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - unloadSource); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a stream. - /// The stream must be set to the correct position before calling SaveToStream. - /// - /// Handle to a FreeImage bitmap. - /// The stream to write to. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// cannot write. - public static bool SaveToStream( - FIBITMAP dib, - Stream stream, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_SAVE_FLAGS flags) - { - return SaveToStream( - ref dib, - stream, - format, - flags, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - false); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a stream. - /// The stream must be set to the correct position before calling SaveToStream. - /// - /// Handle to a FreeImage bitmap. - /// The stream to write to. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// When true the structure will be unloaded on success. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// cannot write. - public static bool SaveToStream( - ref FIBITMAP dib, - Stream stream, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_SAVE_FLAGS flags, - bool unloadSource) - { - return SaveToStream( - ref dib, stream, - format, - flags, - FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, - unloadSource); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a stream. - /// The stream must be set to the correct position before calling SaveToStream. - /// - /// Handle to a FreeImage bitmap. - /// The stream to write to. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// The new color depth of the bitmap. - /// Set to if SaveToStream should - /// take the best suitable color depth. - /// If a color depth is selected that the provided format cannot write an - /// error-message will be thrown. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// cannot write. - public static bool SaveToStream( - FIBITMAP dib, - Stream stream, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_SAVE_FLAGS flags, - FREE_IMAGE_COLOR_DEPTH colorDepth) - { - return SaveToStream( - ref dib, - stream, - format, - flags, - colorDepth, - false); - } - - /// - /// Saves a previously loaded FreeImage bitmap to a stream. - /// The stream must be set to the correct position before calling SaveToStream. - /// - /// Handle to a FreeImage bitmap. - /// The stream to write to. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// The new color depth of the bitmap. - /// Set to if SaveToStream should - /// take the best suitable color depth. - /// If a color depth is selected that the provided format cannot write an - /// error-message will be thrown. - /// When true the structure will be unloaded on success. - /// Returns true on success, false on failure. - /// - /// or is null. - /// - /// cannot write. - public static bool SaveToStream( - ref FIBITMAP dib, - Stream stream, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_SAVE_FLAGS flags, - FREE_IMAGE_COLOR_DEPTH colorDepth, - bool unloadSource) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - if (!stream.CanWrite) - { - throw new ArgumentException("stream is not capable of writing."); - } - if ((!FIFSupportsWriting(format)) || (!FIFSupportsExportType(format, GetImageType(dib)))) - { - return false; - } - - FIBITMAP dibToSave = PrepareBitmapColorDepth(dib, format, colorDepth); - bool result = false; - - try - { - // Create a 'FreeImageIO' structure for calling 'SaveToHandle' - FreeImageIO io = FreeImageStreamIO.io; - - using (fi_handle handle = new fi_handle(stream)) - { - result = SaveToHandle(format, dibToSave, ref io, handle, flags); - } - } - finally - { - // Always unload a temporary created bitmap. - if (dibToSave != dib) - { - UnloadEx(ref dibToSave); - } - // On success unload the bitmap - if (result && unloadSource) - { - UnloadEx(ref dib); - } - } - - return result; - } - - #endregion - - #region Plugin functions - - /// - /// Checks if an extension is valid for a certain format. - /// - /// The desired format. - /// The desired extension. - /// True if the extension is valid for the given format, false otherwise. - /// - /// is null. - public static bool IsExtensionValidForFIF(FREE_IMAGE_FORMAT fif, string extension) - { - return IsExtensionValidForFIF(fif, extension, StringComparison.CurrentCultureIgnoreCase); - } - - /// - /// Checks if an extension is valid for a certain format. - /// - /// The desired format. - /// The desired extension. - /// The string comparison type. - /// True if the extension is valid for the given format, false otherwise. - /// - /// is null. - public static bool IsExtensionValidForFIF(FREE_IMAGE_FORMAT fif, string extension, StringComparison comparisonType) - { - if (extension == null) - { - throw new ArgumentNullException("extension"); - } - bool result = false; - // Split up the string and compare each with the given extension - string tempList = GetFIFExtensionList(fif); - if (tempList != null) - { - string[] extensionList = tempList.Split(','); - foreach (string ext in extensionList) - { - if (extension.Equals(ext, comparisonType)) - { - result = true; - break; - } - } - } - return result; - } - - /// - /// Checks if a filename is valid for a certain format. - /// - /// The desired format. - /// The desired filename. - /// True if the filename is valid for the given format, false otherwise. - /// - /// is null. - public static bool IsFilenameValidForFIF(FREE_IMAGE_FORMAT fif, string filename) - { - return IsFilenameValidForFIF(fif, filename, StringComparison.CurrentCultureIgnoreCase); - } - - /// - /// Checks if a filename is valid for a certain format. - /// - /// The desired format. - /// The desired filename. - /// The string comparison type. - /// True if the filename is valid for the given format, false otherwise. - /// - /// is null. - public static bool IsFilenameValidForFIF(FREE_IMAGE_FORMAT fif, string filename, StringComparison comparisonType) - { - if (filename == null) - { - throw new ArgumentNullException("filename"); - } - bool result = false; - // Extract the filenames extension if it exists - string extension = Path.GetExtension(filename); - if (extension.Length != 0) - { - extension = extension.Remove(0, 1); - result = IsExtensionValidForFIF(fif, extension, comparisonType); - } - return result; - } - - /// - /// This function returns the primary (main or most commonly used?) extension of a certain - /// image format (fif). This is done by returning the first of all possible extensions - /// returned by GetFIFExtensionList(). - /// That assumes, that the plugin returns the extensions in ordered form. - /// The image format to obtain the primary extension for. - /// The primary extension of the specified image format. - public static string GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT fif) - { - string result = null; - string extensions = GetFIFExtensionList(fif); - if (extensions != null) - { - int position = extensions.IndexOf(','); - if (position < 0) - { - result = extensions; - } - else - { - result = extensions.Substring(0, position); - } - } - return result; - } - - #endregion - - #region Multipage functions - - /// - /// Loads a FreeImage multi-paged bitmap. - /// - /// The complete name of the file to load. - /// Handle to a FreeImage multi-paged bitmap. - /// - /// does not exists while opening. - public static FIMULTIBITMAP OpenMultiBitmapEx(string filename) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return OpenMultiBitmapEx( - filename, - ref format, - FREE_IMAGE_LOAD_FLAGS.DEFAULT, - false, - false, - false); - } - - /// - /// Loads a FreeImage multi-paged bitmap. - /// - /// The complete name of the file to load. - /// When true performance is increased at the cost of memory. - /// Handle to a FreeImage multi-paged bitmap. - /// - /// does not exists while opening. - public static FIMULTIBITMAP OpenMultiBitmapEx(string filename, bool keep_cache_in_memory) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return OpenMultiBitmapEx( - filename, - ref format, - FREE_IMAGE_LOAD_FLAGS.DEFAULT, - false, - false, - keep_cache_in_memory); - } - - /// - /// Loads a FreeImage multi-paged bitmap. - /// - /// The complete name of the file to load. - /// When true the bitmap will be loaded read only. - /// When true performance is increased at the cost of memory. - /// Handle to a FreeImage multi-paged bitmap. - /// - /// does not exists while opening. - public static FIMULTIBITMAP OpenMultiBitmapEx( - string filename, - bool read_only, - bool keep_cache_in_memory) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return OpenMultiBitmapEx( - filename, - ref format, - FREE_IMAGE_LOAD_FLAGS.DEFAULT, - false, - read_only, - keep_cache_in_memory); - } - - /// - /// Loads a FreeImage multi-paged bitmap. - /// - /// The complete name of the file to load. - /// When true a new bitmap is created. - /// When true the bitmap will be loaded read only. - /// When true performance is increased at the cost of memory. - /// Handle to a FreeImage multi-paged bitmap. - /// - /// does not exists while opening. - public static FIMULTIBITMAP OpenMultiBitmapEx( - string filename, - bool create_new, - bool read_only, - bool keep_cache_in_memory) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return OpenMultiBitmapEx( - filename, - ref format, - FREE_IMAGE_LOAD_FLAGS.DEFAULT, - create_new, - read_only, - keep_cache_in_memory); - } - - /// - /// Loads a FreeImage multi-paged bitmap. - /// In case the loading format is the files real - /// format is being analysed. If no plugin can read the file, format remains - /// and 0 is returned. - /// - /// The complete name of the file to load. - /// Format of the image. If the format is unknown use - /// . - /// In case a suitable format was found by LoadEx it will be returned in format. - /// When true a new bitmap is created. - /// When true the bitmap will be loaded read only. - /// When true performance is increased at the cost of memory. - /// Handle to a FreeImage multi-paged bitmap. - /// - /// does not exists while opening. - public static FIMULTIBITMAP OpenMultiBitmapEx( - string filename, - ref FREE_IMAGE_FORMAT format, - bool create_new, - bool read_only, - bool keep_cache_in_memory) - { - return OpenMultiBitmapEx( - filename, - ref format, - FREE_IMAGE_LOAD_FLAGS.DEFAULT, - create_new, - read_only, - keep_cache_in_memory); - } - - /// - /// Loads a FreeImage multi-paged bitmap. - /// In case the loading format is the files - /// real format is being analysed. If no plugin can read the file, format remains - /// and 0 is returned. - /// Load flags can be provided by the flags parameter. - /// - /// The complete name of the file to load. - /// Format of the image. If the format is unknown use - /// . - /// In case a suitable format was found by LoadEx it will be returned in format. - /// Flags to enable or disable plugin-features. - /// When true a new bitmap is created. - /// When true the bitmap will be loaded read only. - /// When true performance is increased at the cost of memory. - /// Handle to a FreeImage multi-paged bitmap. - /// - /// does not exists while opening. - public static FIMULTIBITMAP OpenMultiBitmapEx( - string filename, - ref FREE_IMAGE_FORMAT format, - FREE_IMAGE_LOAD_FLAGS flags, - bool create_new, - bool read_only, - bool keep_cache_in_memory) - { - if (!File.Exists(filename) && !create_new) - { - throw new FileNotFoundException(filename + " could not be found."); - } - if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) - { - // Check if a plugin can read the data - format = GetFileType(filename, 0); - } - FIMULTIBITMAP dib = new FIMULTIBITMAP(); - if (FIFSupportsReading(format)) - { - dib = OpenMultiBitmap(format, filename, create_new, read_only, keep_cache_in_memory, flags); - } - return dib; - } - - /// - /// Loads a FreeImage multi-paged bitmap. - /// - /// The stream to load the bitmap from. - /// Handle to a FreeImage multi-paged bitmap. - public static FIMULTIBITMAP OpenMultiBitmapFromStream(Stream stream) - { - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - return OpenMultiBitmapFromStream(stream, ref format, FREE_IMAGE_LOAD_FLAGS.DEFAULT); - } - - /// - /// Loads a FreeImage multi-paged bitmap. - /// In case the loading format is the files - /// real format is being analysed. If no plugin can read the file, format remains - /// and 0 is returned. - /// Load flags can be provided by the flags parameter. - /// - /// The stream to load the bitmap from. - /// Format of the image. If the format is unknown use - /// . - /// Flags to enable or disable plugin-features. - /// Handle to a FreeImage multi-paged bitmap. - public static FIMULTIBITMAP OpenMultiBitmapFromStream(Stream stream, ref FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) - { - if (stream == null) - return FIMULTIBITMAP.Zero; - - if (!stream.CanSeek) - stream = new StreamWrapper(stream, true); - - FIMULTIBITMAP mdib = FIMULTIBITMAP.Zero; - FreeImageIO io = FreeImageStreamIO.io; - fi_handle handle = new fi_handle(stream); - - try - { - if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) - { - format = GetFileTypeFromHandle(ref io, handle, checked((int)stream.Length)); - } - - mdib = OpenMultiBitmapFromHandle(format, ref io, handle, flags); - - if (mdib.IsNull) - { - handle.Dispose(); - } - else - { - lock (streamHandles) - { - streamHandles.Add(mdib, handle); - } - } - - return mdib; - } - catch - { - if (!mdib.IsNull) - CloseMultiBitmap(mdib, FREE_IMAGE_SAVE_FLAGS.DEFAULT); - - if (handle != null) - handle.Dispose(); - - throw; - } - } - - /// - /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, applies any changes made to it. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - public static bool CloseMultiBitmap(FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags) - { - if (CloseMultiBitmap_(bitmap, flags)) - { - fi_handle handle; - lock (streamHandles) - { - if (streamHandles.TryGetValue(bitmap, out handle)) - { - streamHandles.Remove(bitmap); - handle.Dispose(); - } - } - return true; - } - return false; - } - - /// - /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, - /// applies any changes made to it. - /// On success the handle will be reset to null. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Returns true on success, false on failure. - public static bool CloseMultiBitmapEx(ref FIMULTIBITMAP bitmap) - { - return CloseMultiBitmapEx(ref bitmap, FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - /// - /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, - /// applies any changes made to it. - /// On success the handle will be reset to null. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Flags to enable or disable plugin-features. - /// Returns true on success, false on failure. - public static bool CloseMultiBitmapEx(ref FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags) - { - bool result = false; - if (!bitmap.IsNull) - { - if (CloseMultiBitmap(bitmap, flags)) - { - bitmap.SetNull(); - result = true; - } - } - return result; - } - - /// - /// Retrieves the number of pages that are locked in a multi-paged bitmap. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// Number of locked pages. - /// - /// is null. - public static int GetLockedPageCount(FIMULTIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - int result = 0; - GetLockedPageNumbers(dib, null, ref result); - return result; - } - - /// - /// Retrieves a list locked pages of a multi-paged bitmap. - /// - /// Handle to a FreeImage multi-paged bitmap. - /// List containing the indexes of the locked pages. - /// - /// is null. - public static int[] GetLockedPages(FIMULTIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - // Get the number of pages and create an array to save the information - int count = 0; - int[] result = null; - // Get count - if (GetLockedPageNumbers(dib, result, ref count)) - { - result = new int[count]; - // Fill array - if (!GetLockedPageNumbers(dib, result, ref count)) - { - result = null; - } - } - return result; - } - - /// - /// Loads a FreeImage multi-paged bitmap from a stream and returns the - /// FreeImage memory stream used as temporary buffer. - /// The bitmap can not be modified by calling - /// , - /// , - /// or - /// . - /// - /// The stream to read from. - /// Format of the image. - /// Flags to enable or disable plugin-features. - /// The temporary memory buffer used to load the bitmap. - /// Handle to a FreeImage multi-paged bitmap. - /// - /// is null. - /// - /// can not read. - public static FIMULTIBITMAP LoadMultiBitmapFromStream( - Stream stream, - FREE_IMAGE_FORMAT format, - FREE_IMAGE_LOAD_FLAGS flags, - out FIMEMORY memory) - { - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - if (!stream.CanRead) - { - throw new ArgumentException("stream"); - } - const int blockSize = 1024; - int bytesRead; - byte[] buffer = new byte[blockSize]; - - stream = stream.CanSeek ? stream : new StreamWrapper(stream, true); - memory = OpenMemory(IntPtr.Zero, 0); - - do - { - bytesRead = stream.Read(buffer, 0, blockSize); - WriteMemory(buffer, (uint)blockSize, (uint)1, memory); - } - while (bytesRead == blockSize); - - return LoadMultiBitmapFromMemory(format, memory, flags); - } - - #endregion - - #region Filetype functions - - /// - /// Orders FreeImage to analyze the bitmap signature. - /// In case the stream is not seekable, the stream will have been used - /// and must be recreated for loading. - /// - /// Name of the stream to analyze. - /// Type of the bitmap. - /// - /// is null. - /// - /// can not read. - public static FREE_IMAGE_FORMAT GetFileTypeFromStream(Stream stream) - { - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - if (!stream.CanRead) - { - throw new ArgumentException("stream is not capable of reading."); - } - // Wrap the stream if it cannot seek - stream = (stream.CanSeek) ? stream : new StreamWrapper(stream, true); - // Create a 'FreeImageIO' structure for the stream - FreeImageIO io = FreeImageStreamIO.io; - using (fi_handle handle = new fi_handle(stream)) - { - return GetFileTypeFromHandle(ref io, handle, 0); - } - } - - #endregion - - #region Pixel access functions - - /// - /// Retrieves an hBitmap for a FreeImage bitmap. - /// Call FreeHbitmap(IntPtr) to free the handle. - /// - /// Handle to a FreeImage bitmap. - /// A reference device context. - /// Use IntPtr.Zero if no reference is available. - /// When true dib will be unloaded if the function succeeded. - /// The hBitmap for the FreeImage bitmap. - /// - /// is null. - public static unsafe IntPtr GetHbitmap(FIBITMAP dib, IntPtr hdc, bool unload) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - IntPtr hBitmap = IntPtr.Zero; - bool release = false; - IntPtr ppvBits = IntPtr.Zero; - // Check if we have destination - if (release = (hdc == IntPtr.Zero)) - { - // We don't so request dc - hdc = GetDC(IntPtr.Zero); - } - if (hdc != IntPtr.Zero) - { - // Get pointer to the infoheader of the bitmap - IntPtr info = GetInfo(dib); - // Create a bitmap in the dc - hBitmap = CreateDIBSection(hdc, info, DIB_RGB_COLORS, out ppvBits, IntPtr.Zero, 0); - if (hBitmap != IntPtr.Zero && ppvBits != IntPtr.Zero) - { - // Copy the data into the dc - CopyMemory(ppvBits, GetBits(dib), (GetHeight(dib) * GetPitch(dib))); - // Success: we unload the bitmap - if (unload) - { - Unload(dib); - } - } - // We have to release the dc - if (release) - { - ReleaseDC(IntPtr.Zero, hdc); - } - } - return hBitmap; - } - - /// - /// Returns an HBITMAP created by the CreateDIBitmap() function which in turn - /// has always the same color depth as the reference DC, which may be provided - /// through . The desktop DC will be used, - /// if IntPtr.Zero DC is specified. - /// Call to free the handle. - /// - /// Handle to a FreeImage bitmap. - /// Handle to a device context. - /// When true the structure will be unloaded on success. - /// If the function failed and returned false, the bitmap was not unloaded. - /// If the function succeeds, the return value is a handle to the - /// compatible bitmap. If the function fails, the return value is . - /// - /// is null. - public static IntPtr GetBitmapForDevice(FIBITMAP dib, IntPtr hdc, bool unload) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - IntPtr hbitmap = IntPtr.Zero; - bool release = false; - if (release = (hdc == IntPtr.Zero)) - { - hdc = GetDC(IntPtr.Zero); - } - if (hdc != IntPtr.Zero) - { - hbitmap = CreateDIBitmap( - hdc, - GetInfoHeader(dib), - CBM_INIT, - GetBits(dib), - GetInfo(dib), - DIB_RGB_COLORS); - if (unload) - { - Unload(dib); - } - if (release) - { - ReleaseDC(IntPtr.Zero, hdc); - } - } - return hbitmap; - } - - /// - /// Creates a FreeImage DIB from a Device Context/Compatible Bitmap. - /// - /// Handle to the bitmap. - /// Handle to a device context. - /// Handle to a FreeImage bitmap. - /// - /// is null. - public unsafe static FIBITMAP CreateFromHbitmap(IntPtr hbitmap, IntPtr hdc) - { - if (hbitmap == IntPtr.Zero) - { - throw new ArgumentNullException("hbitmap"); - } - - FIBITMAP dib = new FIBITMAP(); - BITMAP bm; - uint colors; - bool release; - - if (GetObject(hbitmap, sizeof(BITMAP), (IntPtr)(&bm)) != 0) - { - dib = Allocate(bm.bmWidth, bm.bmHeight, bm.bmBitsPixel, 0, 0, 0); - if (!dib.IsNull) - { - colors = GetColorsUsed(dib); - if (release = (hdc == IntPtr.Zero)) - { - hdc = GetDC(IntPtr.Zero); - } - if (GetDIBits( - hdc, - hbitmap, - 0, - (uint)bm.bmHeight, - GetBits(dib), - GetInfo(dib), - DIB_RGB_COLORS) != 0) - { - if (colors != 0) - { - BITMAPINFOHEADER* bmih = (BITMAPINFOHEADER*)GetInfo(dib); - bmih[0].biClrImportant = bmih[0].biClrUsed = colors; - } - } - else - { - UnloadEx(ref dib); - } - if (release) - { - ReleaseDC(IntPtr.Zero, hdc); - } - } - } - - return dib; - } - - /// - /// Frees a bitmap handle. - /// - /// Handle to a bitmap. - /// True on success, false on failure. - public static bool FreeHbitmap(IntPtr hbitmap) - { - return DeleteObject(hbitmap); - } - - #endregion - - #region Bitmap information functions - - /// - /// Retrieves a DIB's resolution in X-direction measured in 'dots per inch' (DPI) and not in - /// 'dots per meter'. - /// - /// Handle to a FreeImage bitmap. - /// The resolution in 'dots per inch'. - /// - /// is null. - public static uint GetResolutionX(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - return (uint)(0.5d + 0.0254d * GetDotsPerMeterX(dib)); - } - - /// - /// Retrieves a DIB's resolution in Y-direction measured in 'dots per inch' (DPI) and not in - /// 'dots per meter'. - /// - /// Handle to a FreeImage bitmap. - /// The resolution in 'dots per inch'. - /// - /// is null. - public static uint GetResolutionY(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - return (uint)(0.5d + 0.0254d * GetDotsPerMeterY(dib)); - } - - /// - /// Sets a DIB's resolution in X-direction measured in 'dots per inch' (DPI) and not in - /// 'dots per meter'. - /// - /// Handle to a FreeImage bitmap. - /// The new resolution in 'dots per inch'. - /// - /// is null. - public static void SetResolutionX(FIBITMAP dib, uint res) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - SetDotsPerMeterX(dib, (uint)((double)res / 0.0254d + 0.5d)); - } - - /// - /// Sets a DIB's resolution in Y-direction measured in 'dots per inch' (DPI) and not in - /// 'dots per meter'. - /// - /// Handle to a FreeImage bitmap. - /// The new resolution in 'dots per inch'. - /// - /// is null. - public static void SetResolutionY(FIBITMAP dib, uint res) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - SetDotsPerMeterY(dib, (uint)((double)res / 0.0254d + 0.5d)); - } - - /// - /// Returns whether the image is a greyscale image or not. - /// The function scans all colors in the bitmaps palette for entries where - /// red, green and blue are not all the same (not a grey color). - /// Supports 1-, 4- and 8-bit bitmaps. - /// - /// Handle to a FreeImage bitmap. - /// True if the image is a greyscale image, else false. - /// - /// is null. - public static unsafe bool IsGreyscaleImage(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - bool result = true; - uint bpp = GetBPP(dib); - switch (bpp) - { - case 1: - case 4: - case 8: - RGBQUAD* palette = (RGBQUAD*)GetPalette(dib); - uint paletteLength = GetColorsUsed(dib); - for (int i = 0; i < paletteLength; i++) - { - if (palette[i].rgbRed != palette[i].rgbGreen || - palette[i].rgbRed != palette[i].rgbBlue) - { - result = false; - break; - } - } - break; - default: - result = false; - break; - } - return result; - } - - /// - /// Returns a structure that represents the palette of a FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// A structure representing the bitmaps palette. - /// - /// is null. - public static Palette GetPaletteEx(FIBITMAP dib) - { - return new Palette(dib); - } - - /// - /// Returns the structure of a FreeImage bitmap. - /// The structure is a copy, so changes will have no effect on - /// the bitmap itself. - /// - /// Handle to a FreeImage bitmap. - /// structure of the bitmap. - /// - /// is null. - public static unsafe BITMAPINFOHEADER GetInfoHeaderEx(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - return *(BITMAPINFOHEADER*)GetInfoHeader(dib); - } - - /// - /// Returns the structure of a FreeImage bitmap. - /// The structure is a copy, so changes will have no effect on - /// the bitmap itself. - /// - /// Handle to a FreeImage bitmap. - /// structure of the bitmap. - /// - /// is null. - public static BITMAPINFO GetInfoEx(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - BITMAPINFO result = new BITMAPINFO(); - result.bmiHeader = GetInfoHeaderEx(dib); - IntPtr ptr = GetPalette(dib); - if (ptr == IntPtr.Zero) - { - result.bmiColors = new RGBQUAD[0]; - } - else - { - result.bmiColors = new MemoryArray(ptr, (int)result.bmiHeader.biClrUsed).Data; - } - return result; - } - - /// - /// Returns the pixelformat of the bitmap. - /// - /// Handle to a FreeImage bitmap. - /// of the bitmap. - /// - /// is null. - public static PixelFormat GetPixelFormat(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - - PixelFormat result = PixelFormat.Undefined; - - if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) - { - switch (GetBPP(dib)) - { - case 1: - result = PixelFormat.Format1bppIndexed; - break; - case 4: - result = PixelFormat.Format4bppIndexed; - break; - case 8: - result = PixelFormat.Format8bppIndexed; - break; - case 16: - if ((GetBlueMask(dib) == FI16_565_BLUE_MASK) && - (GetGreenMask(dib) == FI16_565_GREEN_MASK) && - (GetRedMask(dib) == FI16_565_RED_MASK)) - { - result = PixelFormat.Format16bppRgb565; - } - if ((GetBlueMask(dib) == FI16_555_BLUE_MASK) && - (GetGreenMask(dib) == FI16_555_GREEN_MASK) && - (GetRedMask(dib) == FI16_555_RED_MASK)) - { - result = PixelFormat.Format16bppRgb555; - } - break; - case 24: - result = PixelFormat.Format24bppRgb; - break; - case 32: - result = PixelFormat.Format32bppArgb; - break; - } - } - return result; - } - - /// - /// Retrieves all parameters needed to create a new FreeImage bitmap from - /// the format of a .NET . - /// - /// The - /// of the .NET . - /// Returns the type used for the new bitmap. - /// Returns the color depth for the new bitmap. - /// Returns the red_mask for the new bitmap. - /// Returns the green_mask for the new bitmap. - /// Returns the blue_mask for the new bitmap. - /// True in case a matching conversion exists; else false. - /// - public static bool GetFormatParameters( - PixelFormat format, - out FREE_IMAGE_TYPE type, - out uint bpp, - out uint red_mask, - out uint green_mask, - out uint blue_mask) - { - bool result = false; - type = FREE_IMAGE_TYPE.FIT_UNKNOWN; - bpp = 0; - red_mask = 0; - green_mask = 0; - blue_mask = 0; - switch (format) - { - case PixelFormat.Format1bppIndexed: - type = FREE_IMAGE_TYPE.FIT_BITMAP; - bpp = 1; - result = true; - break; - case PixelFormat.Format4bppIndexed: - type = FREE_IMAGE_TYPE.FIT_BITMAP; - bpp = 4; - result = true; - break; - case PixelFormat.Format8bppIndexed: - type = FREE_IMAGE_TYPE.FIT_BITMAP; - bpp = 8; - result = true; - break; - case PixelFormat.Format16bppRgb565: - type = FREE_IMAGE_TYPE.FIT_BITMAP; - bpp = 16; - red_mask = FI16_565_RED_MASK; - green_mask = FI16_565_GREEN_MASK; - blue_mask = FI16_565_BLUE_MASK; - result = true; - break; - case PixelFormat.Format16bppRgb555: - case PixelFormat.Format16bppArgb1555: - type = FREE_IMAGE_TYPE.FIT_BITMAP; - bpp = 16; - red_mask = FI16_555_RED_MASK; - green_mask = FI16_555_GREEN_MASK; - blue_mask = FI16_555_BLUE_MASK; - result = true; - break; - case PixelFormat.Format24bppRgb: - type = FREE_IMAGE_TYPE.FIT_BITMAP; - bpp = 24; - red_mask = FI_RGBA_RED_MASK; - green_mask = FI_RGBA_GREEN_MASK; - blue_mask = FI_RGBA_BLUE_MASK; - result = true; - break; - case PixelFormat.Format32bppRgb: - case PixelFormat.Format32bppArgb: - case PixelFormat.Format32bppPArgb: - type = FREE_IMAGE_TYPE.FIT_BITMAP; - bpp = 32; - red_mask = FI_RGBA_RED_MASK; - green_mask = FI_RGBA_GREEN_MASK; - blue_mask = FI_RGBA_BLUE_MASK; - result = true; - break; - case PixelFormat.Format16bppGrayScale: - type = FREE_IMAGE_TYPE.FIT_UINT16; - bpp = 16; - result = true; - break; - case PixelFormat.Format48bppRgb: - type = FREE_IMAGE_TYPE.FIT_RGB16; - bpp = 48; - result = true; - break; - case PixelFormat.Format64bppArgb: - case PixelFormat.Format64bppPArgb: - type = FREE_IMAGE_TYPE.FIT_RGBA16; - bpp = 64; - result = true; - break; - } - return result; - } - - /// - /// Returns the for the specified - /// . - /// - /// The - /// for which to return the corresponding . - /// The for the specified - /// - public static FREE_IMAGE_FORMAT GetFormat(ImageFormat imageFormat) - { - if (imageFormat != null) - { - if (imageFormat.Equals(ImageFormat.Bmp)) - return FREE_IMAGE_FORMAT.FIF_BMP; - if (imageFormat.Equals(ImageFormat.Gif)) - return FREE_IMAGE_FORMAT.FIF_GIF; - if (imageFormat.Equals(ImageFormat.Icon)) - return FREE_IMAGE_FORMAT.FIF_ICO; - if (imageFormat.Equals(ImageFormat.Jpeg)) - return FREE_IMAGE_FORMAT.FIF_JPEG; - if (imageFormat.Equals(ImageFormat.Png)) - return FREE_IMAGE_FORMAT.FIF_PNG; - if (imageFormat.Equals(ImageFormat.Tiff)) - return FREE_IMAGE_FORMAT.FIF_TIFF; - } - return FREE_IMAGE_FORMAT.FIF_UNKNOWN; - } - - /// - /// Retrieves all parameters needed to create a new FreeImage bitmap from - /// raw bits . - /// - /// The - /// of the data in memory. - /// The color depth for the data. - /// Returns the red_mask for the data. - /// Returns the green_mask for the data. - /// Returns the blue_mask for the data. - /// True in case a matching conversion exists; else false. - /// - public static bool GetTypeParameters( - FREE_IMAGE_TYPE type, - int bpp, - out uint red_mask, - out uint green_mask, - out uint blue_mask) - { - bool result = false; - red_mask = 0; - green_mask = 0; - blue_mask = 0; - switch (type) - { - case FREE_IMAGE_TYPE.FIT_BITMAP: - switch (bpp) - { - case 1: - case 4: - case 8: - result = true; - break; - case 16: - result = true; - red_mask = FI16_555_RED_MASK; - green_mask = FI16_555_GREEN_MASK; - blue_mask = FI16_555_BLUE_MASK; - break; - case 24: - case 32: - result = true; - red_mask = FI_RGBA_RED_MASK; - green_mask = FI_RGBA_GREEN_MASK; - blue_mask = FI_RGBA_BLUE_MASK; - break; - } - break; - case FREE_IMAGE_TYPE.FIT_UNKNOWN: - break; - default: - result = true; - break; - } - return result; - } - - /// - /// Compares two FreeImage bitmaps. - /// - /// The first bitmap to compare. - /// The second bitmap to compare. - /// Determines which components of the bitmaps will be compared. - /// True in case both bitmaps match the compare conditions, false otherwise. - public static bool Compare(FIBITMAP dib1, FIBITMAP dib2, FREE_IMAGE_COMPARE_FLAGS flags) - { - // Check whether one bitmap is null - if (dib1.IsNull ^ dib2.IsNull) - { - return false; - } - // Check whether both pointers are the same - if (dib1 == dib2) - { - return true; - } - if (((flags & FREE_IMAGE_COMPARE_FLAGS.HEADER) > 0) && (!CompareHeader(dib1, dib2))) - { - return false; - } - if (((flags & FREE_IMAGE_COMPARE_FLAGS.PALETTE) > 0) && (!ComparePalette(dib1, dib2))) - { - return false; - } - if (((flags & FREE_IMAGE_COMPARE_FLAGS.DATA) > 0) && (!CompareData(dib1, dib2))) - { - return false; - } - if (((flags & FREE_IMAGE_COMPARE_FLAGS.METADATA) > 0) && (!CompareMetadata(dib1, dib2))) - { - return false; - } - return true; - } - - private static unsafe bool CompareHeader(FIBITMAP dib1, FIBITMAP dib2) - { - IntPtr i1 = GetInfoHeader(dib1); - IntPtr i2 = GetInfoHeader(dib2); - return CompareMemory((void*)i1, (void*)i2, sizeof(BITMAPINFOHEADER)); - } - - private static unsafe bool ComparePalette(FIBITMAP dib1, FIBITMAP dib2) - { - IntPtr pal1 = GetPalette(dib1), pal2 = GetPalette(dib2); - bool hasPalette1 = pal1 != IntPtr.Zero; - bool hasPalette2 = pal2 != IntPtr.Zero; - if (hasPalette1 ^ hasPalette2) - { - return false; - } - if (!hasPalette1) - { - return true; - } - uint colors = GetColorsUsed(dib1); - if (colors != GetColorsUsed(dib2)) - { - return false; - } - return CompareMemory((void*)pal1, (void*)pal2, sizeof(RGBQUAD) * colors); - } - - private static unsafe bool CompareData(FIBITMAP dib1, FIBITMAP dib2) - { - uint width = GetWidth(dib1); - if (width != GetWidth(dib2)) - { - return false; - } - uint height = GetHeight(dib1); - if (height != GetHeight(dib2)) - { - return false; - } - uint bpp = GetBPP(dib1); - if (bpp != GetBPP(dib2)) - { - return false; - } - if (GetColorType(dib1) != GetColorType(dib2)) - { - return false; - } - FREE_IMAGE_TYPE type = GetImageType(dib1); - if (type != GetImageType(dib2)) - { - return false; - } - if (GetRedMask(dib1) != GetRedMask(dib2)) - { - return false; - } - if (GetGreenMask(dib1) != GetGreenMask(dib2)) - { - return false; - } - if (GetBlueMask(dib1) != GetBlueMask(dib2)) - { - return false; - } - - byte* ptr1, ptr2; - int fullBytes; - int shift; - uint line = GetLine(dib1); - - if (type == FREE_IMAGE_TYPE.FIT_BITMAP) - { - switch (bpp) - { - case 32: - for (int i = 0; i < height; i++) - { - ptr1 = (byte*)GetScanLine(dib1, i); - ptr2 = (byte*)GetScanLine(dib2, i); - if (!CompareMemory(ptr1, ptr2, line)) - { - return false; - } - } - break; - case 24: - for (int i = 0; i < height; i++) - { - ptr1 = (byte*)GetScanLine(dib1, i); - ptr2 = (byte*)GetScanLine(dib2, i); - if (!CompareMemory(ptr1, ptr2, line)) - { - return false; - } - } - break; - case 16: - short* sPtr1, sPtr2; - short mask = (short)(GetRedMask(dib1) | GetGreenMask(dib1) | GetBlueMask(dib1)); - if (mask == -1) - { - for (int i = 0; i < height; i++) - { - sPtr1 = (short*)GetScanLine(dib1, i); - sPtr2 = (short*)GetScanLine(dib2, i); - if (!CompareMemory(sPtr1, sPtr1, line)) - { - return false; - } - } - } - else - { - for (int i = 0; i < height; i++) - { - sPtr1 = (short*)GetScanLine(dib1, i); - sPtr2 = (short*)GetScanLine(dib2, i); - for (int x = 0; x < width; x++) - { - if ((sPtr1[x] & mask) != (sPtr2[x] & mask)) - { - return false; - } - } - } - } - break; - case 8: - for (int i = 0; i < height; i++) - { - ptr1 = (byte*)GetScanLine(dib1, i); - ptr2 = (byte*)GetScanLine(dib2, i); - if (!CompareMemory(ptr1, ptr2, line)) - { - return false; - } - } - break; - case 4: - fullBytes = (int)width / 2; - shift = (width % 2) == 0 ? 8 : 4; - for (int i = 0; i < height; i++) - { - ptr1 = (byte*)GetScanLine(dib1, i); - ptr2 = (byte*)GetScanLine(dib2, i); - if (fullBytes != 0) - { - if (!CompareMemory(ptr1, ptr2, fullBytes)) - { - return false; - } - ptr1 += fullBytes; - ptr2 += fullBytes; - } - if (shift != 8) - { - if ((ptr1[0] >> shift) != (ptr2[0] >> shift)) - { - return false; - } - } - } - break; - case 1: - fullBytes = (int)width / 8; - shift = 8 - ((int)width % 8); - for (int i = 0; i < height; i++) - { - ptr1 = (byte*)GetScanLine(dib1, i); - ptr2 = (byte*)GetScanLine(dib2, i); - if (fullBytes != 0) - { - if (!CompareMemory(ptr1, ptr2, fullBytes)) - { - return false; - } - ptr1 += fullBytes; - ptr2 += fullBytes; - } - if (shift != 8) - { - if ((ptr1[0] >> shift) != (ptr2[0] >> shift)) - { - return false; - } - } - } - break; - default: - throw new NotSupportedException("Only 1, 4, 8, 16, 24 and 32 bpp bitmaps are supported."); - } - } - else - { - for (int i = 0; i < height; i++) - { - ptr1 = (byte*)GetScanLine(dib1, i); - ptr2 = (byte*)GetScanLine(dib2, i); - if (!CompareMemory(ptr1, ptr2, line)) - { - return false; - } - } - } - return true; - } - - private static bool CompareMetadata(FIBITMAP dib1, FIBITMAP dib2) - { - MetadataTag tag1, tag2; - - foreach (FREE_IMAGE_MDMODEL metadataModel in FREE_IMAGE_MDMODELS) - { - if (GetMetadataCount(metadataModel, dib1) != - GetMetadataCount(metadataModel, dib2)) - { - return false; - } - if (GetMetadataCount(metadataModel, dib1) == 0) - { - continue; - } - - FIMETADATA mdHandle = FindFirstMetadata(metadataModel, dib1, out tag1); - if (mdHandle.IsNull) - { - continue; - } - do - { - if ((!GetMetadata(metadataModel, dib2, tag1.Key, out tag2)) || (tag1 != tag2)) - { - FindCloseMetadata(mdHandle); - return false; - } - } - while (FindNextMetadata(mdHandle, out tag1)); - FindCloseMetadata(mdHandle); - } - - return true; - } - - /// - /// Returns the FreeImage bitmap's transparency table. - /// The array is empty in case the bitmap has no transparency table. - /// - /// Handle to a FreeImage bitmap. - /// The FreeImage bitmap's transparency table. - /// - /// is null. - public static unsafe byte[] GetTransparencyTableEx(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - uint count = GetTransparencyCount(dib); - byte[] result = new byte[count]; - byte* ptr = (byte*)GetTransparencyTable(dib); - fixed (byte* dst = result) - { - CopyMemory(dst, ptr, count); - } - return result; - } - - /// - /// Set the FreeImage bitmap's transparency table. Only affects palletised bitmaps. - /// - /// Handle to a FreeImage bitmap. - /// The FreeImage bitmap's new transparency table. - /// - /// or is null. - public static void SetTransparencyTable(FIBITMAP dib, byte[] table) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - if (table == null) - { - throw new ArgumentNullException("table"); - } - SetTransparencyTable(dib, table, table.Length); - } - - /// - /// This function returns the number of unique colors actually used by the - /// specified 1-, 4-, 8-, 16-, 24- or 32-bit image. This might be different from - /// what function FreeImage_GetColorsUsed() returns, which actually returns the - /// palette size for palletised images. Works for - /// type images only. - /// - /// Handle to a FreeImage bitmap. - /// Returns the number of unique colors used by the image specified or - /// zero, if the image type cannot be handled. - /// - /// is null. - public static unsafe int GetUniqueColors(FIBITMAP dib) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - - int result = 0; - - if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) - { - BitArray bitArray; - int uniquePalEnts; - int hashcode; - byte[] lut; - int width = (int)GetWidth(dib); - int height = (int)GetHeight(dib); - - switch (GetBPP(dib)) - { - case 1: - - result = 1; - lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts); - if (uniquePalEnts == 1) - { - break; - } - - if ((*(byte*)GetScanLine(dib, 0) & 0x80) == 0) - { - for (int y = 0; y < height; y++) - { - byte* scanline = (byte*)GetScanLine(dib, y); - int mask = 0x80; - for (int x = 0; x < width; x++) - { - if ((scanline[x / 8] & mask) > 0) - { - return 2; - } - mask = (mask == 0x1) ? 0x80 : (mask >> 1); - } - } - } - else - { - for (int y = 0; y < height; y++) - { - byte* scanline = (byte*)GetScanLine(dib, y); - int mask = 0x80; - for (int x = 0; x < width; x++) - { - if ((scanline[x / 8] & mask) == 0) - { - return 2; - } - mask = (mask == 0x1) ? 0x80 : (mask >> 1); - } - } - } - break; - - case 4: - - bitArray = new BitArray(0x10); - lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts); - if (uniquePalEnts == 1) - { - result = 1; - break; - } - - for (int y = 0; (y < height) && (result < uniquePalEnts); y++) - { - byte* scanline = (byte*)GetScanLine(dib, y); - bool top = true; - for (int x = 0; (x < width) && (result < uniquePalEnts); x++) - { - if (top) - { - hashcode = lut[scanline[x / 2] >> 4]; - } - else - { - hashcode = lut[scanline[x / 2] & 0xF]; - } - top = !top; - if (!bitArray[hashcode]) - { - bitArray[hashcode] = true; - result++; - } - } - } - break; - - case 8: - - bitArray = new BitArray(0x100); - lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts); - if (uniquePalEnts == 1) - { - result = 1; - break; - } - - for (int y = 0; (y < height) && (result < uniquePalEnts); y++) - { - byte* scanline = (byte*)GetScanLine(dib, y); - for (int x = 0; (x < width) && (result < uniquePalEnts); x++) - { - hashcode = lut[scanline[x]]; - if (!bitArray[hashcode]) - { - bitArray[hashcode] = true; - result++; - } - } - } - break; - - case 16: - - bitArray = new BitArray(0x10000); - - for (int y = 0; y < height; y++) - { - short* scanline = (short*)GetScanLine(dib, y); - for (int x = 0; x < width; x++, scanline++) - { - hashcode = *scanline; - if (!bitArray[hashcode]) - { - bitArray[hashcode] = true; - result++; - } - } - } - break; - - case 24: - - bitArray = new BitArray(0x1000000); - - for (int y = 0; y < height; y++) - { - byte* scanline = (byte*)GetScanLine(dib, y); - for (int x = 0; x < width; x++, scanline += 3) - { - hashcode = *((int*)scanline) & 0x00FFFFFF; - if (!bitArray[hashcode]) - { - bitArray[hashcode] = true; - result++; - } - } - } - break; - - case 32: - - bitArray = new BitArray(0x1000000); - - for (int y = 0; y < height; y++) - { - int* scanline = (int*)GetScanLine(dib, y); - for (int x = 0; x < width; x++, scanline++) - { - hashcode = *scanline & 0x00FFFFFF; - if (!bitArray[hashcode]) - { - bitArray[hashcode] = true; - result++; - } - } - } - break; - } - } - return result; - } - - /// - /// Verifies whether the FreeImage bitmap is 16bit 555. - /// - /// The FreeImage bitmap to verify. - /// true if the bitmap is RGB16-555; otherwise false. - public static bool IsRGB555(FIBITMAP dib) - { - return ((GetRedMask(dib) == FI16_555_RED_MASK) && - (GetGreenMask(dib) == FI16_555_GREEN_MASK) && - (GetBlueMask(dib) == FI16_555_BLUE_MASK)); - } - - /// - /// Verifies whether the FreeImage bitmap is 16bit 565. - /// - /// The FreeImage bitmap to verify. - /// true if the bitmap is RGB16-565; otherwise false. - public static bool IsRGB565(FIBITMAP dib) - { - return ((GetRedMask(dib) == FI16_565_RED_MASK) && - (GetGreenMask(dib) == FI16_565_GREEN_MASK) && - (GetBlueMask(dib) == FI16_565_BLUE_MASK)); - } - - #endregion - - #region ICC profile functions - - /// - /// Creates a new ICC-Profile for a FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The data of the new ICC-Profile. - /// The new ICC-Profile of the bitmap. - /// - /// is null. - public static FIICCPROFILE CreateICCProfileEx(FIBITMAP dib, byte[] data) - { - return new FIICCPROFILE(dib, data); - } - - /// - /// Creates a new ICC-Profile for a FreeImage bitmap. - /// - /// Handle to a FreeImage bitmap. - /// The data of the new ICC-Profile. - /// The number of bytes of to use. - /// The new ICC-Profile of the FreeImage bitmap. - /// - /// is null. - public static FIICCPROFILE CreateICCProfileEx(FIBITMAP dib, byte[] data, int size) - { - return new FIICCPROFILE(dib, data, size); - } - - #endregion - - #region Conversion functions - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion) - { - return ConvertColorDepth( - dib, - conversion, - 128, - FREE_IMAGE_DITHER.FID_FS, - FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, - false); - } - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// When true the structure will be unloaded on success. - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - bool unloadSource) - { - return ConvertColorDepth( - dib, - conversion, - 128, - FREE_IMAGE_DITHER.FID_FS, - FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, - unloadSource); - } - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// Threshold value when converting with - /// . - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - byte threshold) - { - return ConvertColorDepth( - dib, - conversion, - threshold, - FREE_IMAGE_DITHER.FID_FS, - FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, - false); - } - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// Dither algorithm when converting - /// with . - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - FREE_IMAGE_DITHER ditherMethod) - { - return ConvertColorDepth( - dib, - conversion, - 128, - ditherMethod, - FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, - false); - } - - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// The quantization algorithm for conversion to 8-bit color depth. - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - FREE_IMAGE_QUANTIZE quantizationMethod) - { - return ConvertColorDepth( - dib, - conversion, - 128, - FREE_IMAGE_DITHER.FID_FS, - quantizationMethod, - false); - } - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// Threshold value when converting with - /// . - /// When true the structure will be unloaded on success. - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - byte threshold, - bool unloadSource) - { - return ConvertColorDepth( - dib, - conversion, - threshold, - FREE_IMAGE_DITHER.FID_FS, - FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, - unloadSource); - } - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// Dither algorithm when converting with - /// . - /// When true the structure will be unloaded on success. - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - FREE_IMAGE_DITHER ditherMethod, - bool unloadSource) - { - return ConvertColorDepth( - dib, - conversion, - 128, - ditherMethod, - FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, - unloadSource); - } - - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// The quantization algorithm for conversion to 8-bit color depth. - /// When true the structure will be unloaded on success. - /// Handle to a FreeImage bitmap. - /// - /// is null. - public static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - FREE_IMAGE_QUANTIZE quantizationMethod, - bool unloadSource) - { - return ConvertColorDepth( - dib, - conversion, - 128, - FREE_IMAGE_DITHER.FID_FS, - quantizationMethod, - unloadSource); - } - - /// - /// Converts a FreeImage bitmap from one color depth to another. - /// If the conversion fails the original FreeImage bitmap is returned. - /// - /// Handle to a FreeImage bitmap. - /// The desired output format. - /// Threshold value when converting with - /// . - /// Dither algorithm when converting with - /// . - /// The quantization algorithm for conversion to 8-bit color depth. - /// When true the structure will be unloaded on success. - /// Handle to a FreeImage bitmap. - /// - /// is null. - internal static FIBITMAP ConvertColorDepth( - FIBITMAP dib, - FREE_IMAGE_COLOR_DEPTH conversion, - byte threshold, - FREE_IMAGE_DITHER ditherMethod, - FREE_IMAGE_QUANTIZE quantizationMethod, - bool unloadSource) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - - FIBITMAP result = new FIBITMAP(); - FIBITMAP dibTemp = new FIBITMAP(); - uint bpp = GetBPP(dib); - bool reorderPalette = ((conversion & FREE_IMAGE_COLOR_DEPTH.FICD_REORDER_PALETTE) > 0); - bool forceGreyscale = ((conversion & FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE) > 0); - - if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) - { - switch (conversion & (FREE_IMAGE_COLOR_DEPTH)0xFF) - { - case FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_THRESHOLD: - - if (bpp != 1) - { - if (forceGreyscale) - { - result = Threshold(dib, threshold); - } - else - { - dibTemp = ConvertTo24Bits(dib); - result = ColorQuantizeEx(dibTemp, quantizationMethod, 2, null, 1); - Unload(dibTemp); - } - } - else - { - bool isGreyscale = IsGreyscaleImage(dib); - if ((forceGreyscale && (!isGreyscale)) || - (reorderPalette && isGreyscale)) - { - result = Threshold(dib, threshold); - } - } - break; - - case FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_DITHER: - - if (bpp != 1) - { - if (forceGreyscale) - { - result = Dither(dib, ditherMethod); - } - else - { - dibTemp = ConvertTo24Bits(dib); - result = ColorQuantizeEx(dibTemp, quantizationMethod, 2, null, 1); - Unload(dibTemp); - } - } - else - { - bool isGreyscale = IsGreyscaleImage(dib); - if ((forceGreyscale && (!isGreyscale)) || - (reorderPalette && isGreyscale)) - { - result = Dither(dib, ditherMethod); - } - } - break; - - case FREE_IMAGE_COLOR_DEPTH.FICD_04_BPP: - - if (bpp != 4) - { - // Special case when 1bpp and FIC_PALETTE - if (forceGreyscale || - ((bpp == 1) && (GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_PALETTE))) - { - dibTemp = ConvertToGreyscale(dib); - result = ConvertTo4Bits(dibTemp); - Unload(dibTemp); - } - else - { - dibTemp = ConvertTo24Bits(dib); - result = ColorQuantizeEx(dibTemp, quantizationMethod, 16, null, 4); - Unload(dibTemp); - } - } - else - { - bool isGreyscale = IsGreyscaleImage(dib); - if ((forceGreyscale && (!isGreyscale)) || - (reorderPalette && isGreyscale)) - { - dibTemp = ConvertToGreyscale(dib); - result = ConvertTo4Bits(dibTemp); - Unload(dibTemp); - } - } - - break; - - case FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP: - - if (bpp != 8) - { - if (forceGreyscale) - { - result = ConvertToGreyscale(dib); - } - else - { - dibTemp = ConvertTo24Bits(dib); - result = ColorQuantize(dibTemp, quantizationMethod); - Unload(dibTemp); - } - } - else - { - bool isGreyscale = IsGreyscaleImage(dib); - if ((forceGreyscale && (!isGreyscale)) || (reorderPalette && isGreyscale)) - { - result = ConvertToGreyscale(dib); - } - } - break; - - case FREE_IMAGE_COLOR_DEPTH.FICD_16_BPP_555: - - if (forceGreyscale) - { - dibTemp = ConvertToGreyscale(dib); - result = ConvertTo16Bits555(dibTemp); - Unload(dibTemp); - } - else if (bpp != 16 || GetRedMask(dib) != FI16_555_RED_MASK || GetGreenMask(dib) != FI16_555_GREEN_MASK || GetBlueMask(dib) != FI16_555_BLUE_MASK) - { - result = ConvertTo16Bits555(dib); - } - break; - - case FREE_IMAGE_COLOR_DEPTH.FICD_16_BPP: - - if (forceGreyscale) - { - dibTemp = ConvertToGreyscale(dib); - result = ConvertTo16Bits565(dibTemp); - Unload(dibTemp); - } - else if (bpp != 16 || GetRedMask(dib) != FI16_565_RED_MASK || GetGreenMask(dib) != FI16_565_GREEN_MASK || GetBlueMask(dib) != FI16_565_BLUE_MASK) - { - result = ConvertTo16Bits565(dib); - } - break; - - case FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP: - - if (forceGreyscale) - { - dibTemp = ConvertToGreyscale(dib); - result = ConvertTo24Bits(dibTemp); - Unload(dibTemp); - } - else if (bpp != 24) - { - result = ConvertTo24Bits(dib); - } - break; - - case FREE_IMAGE_COLOR_DEPTH.FICD_32_BPP: - - if (forceGreyscale) - { - dibTemp = ConvertToGreyscale(dib); - result = ConvertTo32Bits(dibTemp); - Unload(dibTemp); - } - else if (bpp != 32) - { - result = ConvertTo32Bits(dib); - } - break; - } - } - - if (result.IsNull) - { - return dib; - } - if (unloadSource) - { - Unload(dib); - } - - return result; - } - - /// - /// ColorQuantizeEx is an extension to the - /// method that provides additional options used to quantize a 24-bit image to any - /// number of colors (up to 256), as well as quantize a 24-bit image using a - /// provided palette. - /// - /// Handle to a FreeImage bitmap. - /// Specifies the color reduction algorithm to be used. - /// Size of the desired output palette. - /// The provided palette. - /// true to create a bitmap with the smallest possible - /// color depth for the specified . - /// Handle to a FreeImage bitmap. - public static FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, RGBQUAD[] ReservePalette, bool minColorDepth) - { - FIBITMAP result; - if (minColorDepth) - { - int bpp; - if (PaletteSize >= 256) - bpp = 8; - else if (PaletteSize > 2) - bpp = 4; - else - bpp = 1; - result = ColorQuantizeEx(dib, quantize, PaletteSize, ReservePalette, bpp); - } - else - { - result = ColorQuantizeEx(dib, quantize, PaletteSize, ReservePalette, 8); - } - return result; - } - - /// - /// ColorQuantizeEx is an extension to the - /// method that provides additional options used to quantize a 24-bit image to any - /// number of colors (up to 256), as well as quantize a 24-bit image using a - /// partial or full provided palette. - /// - /// Handle to a FreeImage bitmap. - /// Specifies the color reduction algorithm to be used. - /// Size of the desired output palette. - /// The provided palette. - /// The desired color depth of the created image. - /// Handle to a FreeImage bitmap. - public static FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, RGBQUAD[] ReservePalette, int bpp) - { - unsafe - { - FIBITMAP result = FIBITMAP.Zero; - FIBITMAP temp = FIBITMAP.Zero; - int reservedSize = (ReservePalette == null) ? 0 : ReservePalette.Length; - - if (bpp == 8) - { - result = ColorQuantizeEx(dib, quantize, PaletteSize, reservedSize, ReservePalette); - } - else if (bpp == 4) - { - temp = ColorQuantizeEx(dib, quantize, Math.Min(16, PaletteSize), reservedSize, ReservePalette); - if (!temp.IsNull) - { - result = Allocate((int)GetWidth(temp), (int)GetHeight(temp), 4, 0, 0, 0); - CloneMetadata(result, temp); - CopyMemory(GetPalette(result), GetPalette(temp), sizeof(RGBQUAD) * 16); - - for (int y = (int)GetHeight(temp) - 1; y >= 0; y--) - { - Scanline srcScanline = new Scanline(temp, y); - Scanline dstScanline = new Scanline(result, y); - - for (int x = (int)GetWidth(temp) - 1; x >= 0; x--) - { - dstScanline[x] = srcScanline[x]; - } - } - } - } - else if (bpp == 1) - { - temp = ColorQuantizeEx(dib, quantize, 2, reservedSize, ReservePalette); - if (!temp.IsNull) - { - result = Allocate((int)GetWidth(temp), (int)GetHeight(temp), 1, 0, 0, 0); - CloneMetadata(result, temp); - CopyMemory(GetPalette(result), GetPalette(temp), sizeof(RGBQUAD) * 2); - - for (int y = (int)GetHeight(temp) - 1; y >= 0; y--) - { - Scanline srcScanline = new Scanline(temp, y); - Scanline dstScanline = new Scanline(result, y); - - for (int x = (int)GetWidth(temp) - 1; x >= 0; x--) - { - dstScanline[x] = srcScanline[x]; - } - } - } - } - - UnloadEx(ref temp); - return result; - } - } - - #endregion - - #region Metadata - - /// - /// Copies metadata from one FreeImage bitmap to another. - /// - /// Source FreeImage bitmap containing the metadata. - /// FreeImage bitmap to copy the metadata to. - /// Flags to switch different copy modes. - /// Returns -1 on failure else the number of copied tags. - /// - /// or is null. - public static int CloneMetadataEx(FIBITMAP src, FIBITMAP dst, FREE_IMAGE_METADATA_COPY flags) - { - if (src.IsNull) - { - throw new ArgumentNullException("src"); - } - if (dst.IsNull) - { - throw new ArgumentNullException("dst"); - } - - FITAG tag = new FITAG(), tag2 = new FITAG(); - int copied = 0; - - // Clear all existing metadata - if ((flags & FREE_IMAGE_METADATA_COPY.CLEAR_EXISTING) > 0) - { - foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS) - { - if (!SetMetadata(model, dst, null, tag)) - { - return -1; - } - } - } - - bool keep = !((flags & FREE_IMAGE_METADATA_COPY.REPLACE_EXISTING) > 0); - - foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS) - { - FIMETADATA mData = FindFirstMetadata(model, src, out tag); - if (mData.IsNull) continue; - do - { - string key = GetTagKey(tag); - if (!(keep && GetMetadata(model, dst, key, out tag2))) - { - if (SetMetadata(model, dst, key, tag)) - { - copied++; - } - } - } - while (FindNextMetadata(mData, out tag)); - FindCloseMetadata(mData); - } - - return copied; - } - - /// - /// Returns the comment of a JPEG, PNG or GIF image. - /// - /// Handle to a FreeImage bitmap. - /// Comment of the FreeImage bitmp, or null in case no comment exists. - /// - /// is null. - public static string GetImageComment(FIBITMAP dib) - { - string result = null; - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - FITAG tag; - if (GetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", out tag)) - { - MetadataTag metadataTag = new MetadataTag(tag, FREE_IMAGE_MDMODEL.FIMD_COMMENTS); - result = metadataTag.Value as string; - } - return result; - } - - /// - /// Sets the comment of a JPEG, PNG or GIF image. - /// - /// Handle to a FreeImage bitmap. - /// New comment of the FreeImage bitmap. - /// Use null to remove the comment. - /// Returns true on success, false on failure. - /// - /// is null. - public static bool SetImageComment(FIBITMAP dib, string comment) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - bool result; - if (comment != null) - { - FITAG tag = CreateTag(); - MetadataTag metadataTag = new MetadataTag(tag, FREE_IMAGE_MDMODEL.FIMD_COMMENTS); - metadataTag.Value = comment; - result = SetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", tag); - DeleteTag(tag); - } - else - { - result = SetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", FITAG.Zero); - } - return result; - } - - /// - /// Retrieve a metadata attached to a FreeImage bitmap. - /// - /// The metadata model to look for. - /// Handle to a FreeImage bitmap. - /// The metadata field name. - /// A structure returned by the function. - /// Returns true on success, false on failure. - /// - /// is null. - public static bool GetMetadata( - FREE_IMAGE_MDMODEL model, - FIBITMAP dib, - string key, - out MetadataTag tag) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - - FITAG _tag; - bool result; - if (GetMetadata(model, dib, key, out _tag)) - { - tag = new MetadataTag(_tag, model); - result = true; - } - else - { - tag = null; - result = false; - } - return result; - } - - /// - /// Attach a new metadata tag to a FreeImage bitmap. - /// - /// The metadata model used to store the tag. - /// Handle to a FreeImage bitmap. - /// The tag field name. - /// The to be attached. - /// Returns true on success, false on failure. - /// - /// is null. - public static bool SetMetadata( - FREE_IMAGE_MDMODEL model, - FIBITMAP dib, - string key, - MetadataTag tag) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - return SetMetadata(model, dib, key, tag.tag); - } - - /// - /// Provides information about the first instance of a tag that matches the metadata model. - /// - /// The model to match. - /// Handle to a FreeImage bitmap. - /// Tag that matches the metadata model. - /// Unique search handle that can be used to call FindNextMetadata or FindCloseMetadata. - /// Null if the metadata model does not exist. - /// - /// is null. - public static FIMETADATA FindFirstMetadata( - FREE_IMAGE_MDMODEL model, - FIBITMAP dib, - out MetadataTag tag) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - FITAG _tag; - FIMETADATA result = FindFirstMetadata(model, dib, out _tag); - if (result.IsNull) - { - tag = null; - return result; - } - tag = new MetadataTag(_tag, model); - if (metaDataSearchHandler.ContainsKey(result)) - { - metaDataSearchHandler[result] = model; - } - else - { - metaDataSearchHandler.Add(result, model); - } - return result; - } - - /// - /// Find the next tag, if any, that matches the metadata model argument in a previous call - /// to FindFirstMetadata, and then alters the tag object contents accordingly. - /// - /// Unique search handle provided by FindFirstMetadata. - /// Tag that matches the metadata model. - /// Returns true on success, false on failure. - public static bool FindNextMetadata(FIMETADATA mdhandle, out MetadataTag tag) - { - FITAG _tag; - bool result; - if (FindNextMetadata(mdhandle, out _tag)) - { - tag = new MetadataTag(_tag, metaDataSearchHandler[mdhandle]); - result = true; - } - else - { - tag = null; - result = false; - } - return result; - } - - /// - /// Closes the specified metadata search handle and releases associated resources. - /// - /// The handle to close. - public static void FindCloseMetadata(FIMETADATA mdhandle) - { - if (metaDataSearchHandler.ContainsKey(mdhandle)) - { - metaDataSearchHandler.Remove(mdhandle); - } - FindCloseMetadata_(mdhandle); - } - - /// - /// This dictionary links FIMETADATA handles and FREE_IMAGE_MDMODEL models. - /// - private static Dictionary metaDataSearchHandler - = new Dictionary(1); - - #endregion - - #region Rotation and Flipping - - /// - /// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. - /// 1-bit images rotation is limited to integer multiple of 90�. - /// null is returned for other values. - /// - /// Handle to a FreeImage bitmap. - /// The angle of rotation. - /// Handle to a FreeImage bitmap. - public static FIBITMAP Rotate(FIBITMAP dib, double angle) - { - return Rotate(dib, angle, IntPtr.Zero); - } - - /// - /// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. - /// 1-bit images rotation is limited to integer multiple of 90�. - /// null is returned for other values. - /// - /// The type of the color to use as background. - /// Handle to a FreeImage bitmap. - /// The angle of rotation. - /// The color used used to fill the bitmap's background. - /// Handle to a FreeImage bitmap. - public static FIBITMAP Rotate(FIBITMAP dib, double angle, T? backgroundColor) where T : struct - { - if (backgroundColor.HasValue) - { - GCHandle handle = new GCHandle(); - try - { - T[] buffer = new T[] { backgroundColor.Value }; - handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - return Rotate(dib, angle, handle.AddrOfPinnedObject()); - } - finally - { - if (handle.IsAllocated) - handle.Free(); - } - } - else - { - return Rotate(dib, angle, IntPtr.Zero); - } - } - - /// - /// Rotates a 4-bit color FreeImage bitmap. - /// Allowed values for are 90, 180 and 270. - /// In case is 0 or 360 a clone is returned. - /// 0 is returned for other values or in case the rotation fails. - /// - /// Handle to a FreeImage bitmap. - /// The angle of rotation. - /// Handle to a FreeImage bitmap. - /// - /// This function is kind of temporary due to FreeImage's lack of - /// rotating 4-bit images. It's particularly used by 's - /// method RotateFlip. This function will be removed as soon as FreeImage - /// supports rotating 4-bit images. - /// - /// - /// is null. - public static unsafe FIBITMAP Rotate4bit(FIBITMAP dib, double angle) - { - if (dib.IsNull) - { - throw new ArgumentNullException("dib"); - } - - FIBITMAP result = new FIBITMAP(); - int ang = (int)angle; - - if ((GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) && - (GetBPP(dib) == 4) && - ((ang % 90) == 0)) - { - int width, height, xOrg, yOrg; - Scanline[] src, dst; - width = (int)GetWidth(dib); - height = (int)GetHeight(dib); - byte index = 0; - switch (ang) - { - case 90: - result = Allocate(height, width, 4, 0, 0, 0); - if (result.IsNull) - { - break; - } - CopyPalette(dib, result); - src = Get04BitScanlines(dib); - dst = Get04BitScanlines(result); - for (int y = 0; y < width; y++) - { - yOrg = height - 1; - for (int x = 0; x < height; x++, yOrg--) - { - index = src[yOrg][y]; - dst[y][x] = index; - } - } - break; - case 180: - result = Allocate(width, height, 4, 0, 0, 0); - if (result.IsNull) - { - break; - } - CopyPalette(dib, result); - src = Get04BitScanlines(dib); - dst = Get04BitScanlines(result); - - yOrg = height - 1; - for (int y = 0; y < height; y++, yOrg--) - { - xOrg = width - 1; - for (int x = 0; x < width; x++, xOrg--) - { - index = src[yOrg][xOrg]; - dst[y][x] = index; - } - } - break; - case 270: - result = Allocate(height, width, 4, 0, 0, 0); - if (result.IsNull) - { - break; - } - CopyPalette(dib, result); - src = Get04BitScanlines(dib); - dst = Get04BitScanlines(result); - xOrg = width - 1; - for (int y = 0; y < width; y++, xOrg--) - { - for (int x = 0; x < height; x++) - { - index = src[x][xOrg]; - dst[y][x] = index; - } - } - break; - case 0: - case 360: - result = Clone(dib); - break; - } - } - return result; - } - - #endregion - - #region Upsampling / downsampling - - /// - /// Enlarges or shrinks the FreeImage bitmap selectively per side and fills newly added areas - /// with the specified background color. See remarks for further details. - /// - /// The type of the specified color. - /// Handle to a FreeImage bitmap. - /// The number of pixels, the image should be enlarged on its left side. - /// Negative values shrink the image on its left side. - /// The number of pixels, the image should be enlarged on its top side. - /// Negative values shrink the image on its top side. - /// The number of pixels, the image should be enlarged on its right side. - /// Negative values shrink the image on its right side. - /// The number of pixels, the image should be enlarged on its bottom side. - /// Negative values shrink the image on its bottom side. - /// The color, the enlarged sides of the image should be filled with. - /// Options that affect the color search process for palletized images. - /// Handle to a FreeImage bitmap. - /// - /// This function enlarges or shrinks an image selectively per side. - /// The main purpose of this function is to add borders to an image. - /// To add a border to any of the image's sides, a positive integer value must be passed in - /// any of the parameters , , - /// or . This value represents the border's - /// width in pixels. Newly created parts of the image (the border areas) are filled with the - /// specified . - /// Specifying a negative integer value for a certain side, will shrink or crop the image on - /// this side. Consequently, specifying zero for a certain side will not change the image's - /// extension on that side. - /// - /// So, calling this function with all parameters , , - /// and set to zero, is - /// effectively the same as calling function ; setting all parameters - /// , , and - /// to value equal to or smaller than zero, my easily be substituted - /// by a call to function . Both these cases produce a new image, which is - /// guaranteed not to be larger than the input image. Thus, since the specified - /// is not needed in these cases, - /// may be null. - /// - /// Both parameters and work according to - /// function . So, please refer to the documentation of - /// to learn more about parameters - /// and . For palletized images, the palette of the input image is - /// transparently copied to the newly created enlarged or shrunken image, so any color look-ups - /// are performed on this palette. - /// - /// - /// // create a white color
    - /// RGBQUAD c;
    - /// c.rgbRed = 0xFF;
    - /// c.rgbGreen = 0xFF;
    - /// c.rgbBlue = 0xFF;
    - /// c.rgbReserved = 0x00;
    - ///
    - /// // add a white, symmetric 10 pixel wide border to the image
    - /// dib2 = FreeImage_EnlargeCanvas(dib, 10, 10, 10, 10, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);
    - ///
    - /// // add white, 20 pixel wide stripes to the top and bottom side of the image
    - /// dib3 = FreeImage_EnlargeCanvas(dib, 0, 20, 0, 20, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);
    - ///
    - /// // add white, 30 pixel wide stripes to the right side of the image and
    - /// // cut off the 40 leftmost pixel columns
    - /// dib3 = FreeImage_EnlargeCanvas(dib, -40, 0, 30, 0, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);
    - ///
    - public static FIBITMAP EnlargeCanvas(FIBITMAP dib, int left, int top, int right, int bottom, - T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct - { - if (dib.IsNull) - return FIBITMAP.Zero; - - if (!CheckColorType(GetImageType(dib), color)) - return FIBITMAP.Zero; - - if (color.HasValue) - { - GCHandle handle = new GCHandle(); - try - { - T[] buffer = new T[] { color.Value }; - handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - return EnlargeCanvas(dib, left, top, right, bottom, handle.AddrOfPinnedObject(), options); - } - finally - { - if (handle.IsAllocated) - handle.Free(); - } - } - else - { - return EnlargeCanvas(dib, left, top, right, bottom, IntPtr.Zero, options); - } - } - - #endregion - - #region Color - - /// - /// Sets all pixels of the specified image to the color provided through the - /// parameter. See remarks for further details. - /// - /// The type of the specified color. - /// Handle to a FreeImage bitmap. - /// The color to fill the bitmap with. See remarks for further details. - /// Options that affect the color search process for palletized images. - /// true on success, false on failure. - /// - /// This function sets all pixels of an image to the color provided through - /// the parameter. is used for standard type images. - /// For non standard type images the underlaying structure is used. - /// - /// So, must be of type , if the image to be filled is of type - /// and must be a structure if the - /// image is of type and so on. - /// - /// However, the fill color is always specified through a structure - /// for all images of type . - /// So, for 32- and 24-bit images, the red, green and blue members of the - /// structure are directly used for the image's red, green and blue channel respectively. - /// Although alpha transparent colors are - /// supported, the alpha channel of a 32-bit image never gets modified by this function. - /// A fill color with an alpha value smaller than 255 gets blended with the image's actual - /// background color, which is determined from the image's bottom-left pixel. - /// So, currently using alpha enabled colors, assumes the image to be unicolor before the - /// fill operation. However, the field is only taken into account, - /// if option has been specified. - /// - /// For 16-bit images, the red-, green- and blue components of the specified color are - /// transparently translated into either the 16-bit 555 or 565 representation. This depends - /// on the image's actual red- green- and blue masks. - /// - /// Special attention must be payed for palletized images. Generally, the RGB color specified - /// is looked up in the image's palette. The found palette index is then used to fill the image. - /// There are some option flags, that affect this lookup process: - /// - /// - /// Value - /// Meaning - /// - /// - /// - /// - /// Uses the color, that is nearest to the specified color. - /// This is the default behavior and should always find a - /// color in the palette. However, the visual result may - /// far from what was expected and mainly depends on the - /// image's palette. - /// - /// - /// - /// - /// - /// Searches the image's palette for the specified color - /// but only uses the returned palette index, if the specified - /// color exactly matches the palette entry. Of course, - /// depending on the image's actual palette entries, this - /// operation may fail. In this case, the function falls back - /// to option - /// and uses the RGBQUAD's rgbReserved member (or its low nibble for 4-bit images - /// or its least significant bit (LSB) for 1-bit images) as - /// the palette index used for the fill operation. - /// - /// - /// - /// - /// - /// Does not perform any color lookup from the palette, but - /// uses the RGBQUAD's alpha channel member rgbReserved as - /// the palette index to be used for the fill operation. - /// However, for 4-bit images, only the low nibble of the - /// rgbReserved member are used and for 1-bit images, only - /// the least significant bit (LSB) is used. - /// - /// - /// - /// - public static bool FillBackground(FIBITMAP dib, T color, FREE_IMAGE_COLOR_OPTIONS options) - where T : struct - { - if (dib.IsNull) - return false; - - if (!CheckColorType(GetImageType(dib), color)) - return false; - - GCHandle handle = new GCHandle(); - try - { - T[] buffer = new T[] { color }; - handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); - return FillBackground(dib, handle.AddrOfPinnedObject(), options); - } - finally - { - if (handle.IsAllocated) - handle.Free(); - } - } - - #endregion - - #region Wrapper functions - - /// - /// Returns the next higher possible color depth. - /// - /// Color depth to increase. - /// The next higher color depth or 0 if there is no valid color depth. - internal static int GetNextColorDepth(int bpp) - { - int result = 0; - switch (bpp) - { - case 1: - result = 4; - break; - case 4: - result = 8; - break; - case 8: - result = 16; - break; - case 16: - result = 24; - break; - case 24: - result = 32; - break; - } - return result; - } - - /// - /// Returns the next lower possible color depth. - /// - /// Color depth to decrease. - /// The next lower color depth or 0 if there is no valid color depth. - internal static int GetPrevousColorDepth(int bpp) - { - int result = 0; - switch (bpp) - { - case 32: - result = 24; - break; - case 24: - result = 16; - break; - case 16: - result = 8; - break; - case 8: - result = 4; - break; - case 4: - result = 1; - break; - } - return result; - } - - /// - /// Reads a null-terminated c-string. - /// - /// Pointer to the first char of the string. - /// The converted string. - internal static unsafe string PtrToStr(byte* ptr) - { - string result = null; - if (ptr != null) - { - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - - while (*ptr != 0) - { - sb.Append((char)(*(ptr++))); - } - result = sb.ToString(); - } - return result; - } - - internal static unsafe byte[] CreateShrunkenPaletteLUT(FIBITMAP dib, out int uniqueColors) - { - byte[] result = null; - uniqueColors = 0; - - if ((!dib.IsNull) && (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) && (GetBPP(dib) <= 8)) - { - int size = (int)GetColorsUsed(dib); - List newPalette = new List(size); - List lut = new List(size); - RGBQUAD* palette = (RGBQUAD*)GetPalette(dib); - RGBQUAD color; - int index; - - for (int i = 0; i < size; i++) - { - color = palette[i]; - color.rgbReserved = 255; // ignore alpha - - index = newPalette.IndexOf(color); - if (index < 0) - { - newPalette.Add(color); - lut.Add((byte)(newPalette.Count - 1)); - } - else - { - lut.Add((byte)index); - } - } - result = lut.ToArray(); - uniqueColors = newPalette.Count; - } - return result; - } - - internal static PropertyItem CreatePropertyItem() - { - return (PropertyItem)Activator.CreateInstance(typeof(PropertyItem), true); - } - - private static unsafe void CopyPalette(FIBITMAP src, FIBITMAP dst) - { - RGBQUAD* orgPal = (RGBQUAD*)GetPalette(src); - RGBQUAD* newPal = (RGBQUAD*)GetPalette(dst); - uint size = (uint)(sizeof(RGBQUAD) * GetColorsUsed(src)); - CopyMemory(newPal, orgPal, size); - } - - private static unsafe Scanline[] Get04BitScanlines(FIBITMAP dib) - { - int height = (int)GetHeight(dib); - Scanline[] array = new Scanline[height]; - for (int i = 0; i < height; i++) - { - array[i] = new Scanline(dib, i); - } - return array; - } - - /// - /// Changes a bitmaps color depth. - /// Used by SaveEx and SaveToStream. - /// - private static FIBITMAP PrepareBitmapColorDepth(FIBITMAP dibToSave, FREE_IMAGE_FORMAT format, FREE_IMAGE_COLOR_DEPTH colorDepth) - { - FREE_IMAGE_TYPE type = GetImageType(dibToSave); - if (type == FREE_IMAGE_TYPE.FIT_BITMAP) - { - int bpp = (int)GetBPP(dibToSave); - int targetBpp = (int)(colorDepth & FREE_IMAGE_COLOR_DEPTH.FICD_COLOR_MASK); - - if (colorDepth != FREE_IMAGE_COLOR_DEPTH.FICD_AUTO) - { - // A fix colordepth was chosen - if (FIFSupportsExportBPP(format, targetBpp)) - { - dibToSave = ConvertColorDepth(dibToSave, colorDepth, false); - } - else - { - throw new ArgumentException("FreeImage\n\nFreeImage Library plugin " + - GetFormatFromFIF(format) + " is unable to write images with a color depth of " + - targetBpp + " bpp."); - } - } - else - { - // Auto selection was chosen - if (!FIFSupportsExportBPP(format, bpp)) - { - // The color depth is not supported - int bppUpper = bpp; - int bppLower = bpp; - // Check from the bitmaps current color depth in both directions - do - { - bppUpper = GetNextColorDepth(bppUpper); - if (FIFSupportsExportBPP(format, bppUpper)) - { - dibToSave = ConvertColorDepth(dibToSave, (FREE_IMAGE_COLOR_DEPTH)bppUpper, false); - break; - } - bppLower = GetPrevousColorDepth(bppLower); - if (FIFSupportsExportBPP(format, bppLower)) - { - dibToSave = ConvertColorDepth(dibToSave, (FREE_IMAGE_COLOR_DEPTH)bppLower, false); - break; - } - } while (!((bppLower == 0) && (bppUpper == 0))); - } - } - } - return dibToSave; - } - - /// - /// Compares blocks of memory. - /// - /// A pointer to a block of memory to compare. - /// A pointer to a block of memory to compare. - /// Specifies the number of bytes to be compared. - /// true, if all bytes compare as equal, false otherwise. - public static unsafe bool CompareMemory(void* buf1, void* buf2, uint length) - { - return (length == RtlCompareMemory(buf1, buf2, length)); - } - - /// - /// Compares blocks of memory. - /// - /// A pointer to a block of memory to compare. - /// A pointer to a block of memory to compare. - /// Specifies the number of bytes to be compared. - /// true, if all bytes compare as equal, false otherwise. - public static unsafe bool CompareMemory(void* buf1, void* buf2, long length) - { - return (length == RtlCompareMemory(buf1, buf2, checked((uint)length))); - } - - /// - /// Compares blocks of memory. - /// - /// A pointer to a block of memory to compare. - /// A pointer to a block of memory to compare. - /// Specifies the number of bytes to be compared. - /// true, if all bytes compare as equal, false otherwise. - public static unsafe bool CompareMemory(IntPtr buf1, IntPtr buf2, uint length) - { - return (length == RtlCompareMemory(buf1.ToPointer(), buf2.ToPointer(), length)); - } - - /// - /// Compares blocks of memory. - /// - /// A pointer to a block of memory to compare. - /// A pointer to a block of memory to compare. - /// Specifies the number of bytes to be compared. - /// true, if all bytes compare as equal, false otherwise. - public static unsafe bool CompareMemory(IntPtr buf1, IntPtr buf2, long length) - { - return (length == RtlCompareMemory(buf1.ToPointer(), buf2.ToPointer(), checked((uint)length))); - } - - /// - /// Moves a block of memory from one location to another. - /// - /// A pointer to the starting address of the move destination. - /// A pointer to the starting address of the block of memory to be moved. - /// The size of the block of memory to move, in bytes. - public static unsafe void MoveMemory(void* dst, void* src, long size) - { - MoveMemory(dst, src, checked((uint)size)); - } - - /// - /// Moves a block of memory from one location to another. - /// - /// A pointer to the starting address of the move destination. - /// A pointer to the starting address of the block of memory to be moved. - /// The size of the block of memory to move, in bytes. - public static unsafe void MoveMemory(IntPtr dst, IntPtr src, uint size) - { - MoveMemory(dst.ToPointer(), src.ToPointer(), size); - } - - /// - /// Moves a block of memory from one location to another. - /// - /// A pointer to the starting address of the move destination. - /// A pointer to the starting address of the block of memory to be moved. - /// The size of the block of memory to move, in bytes. - public static unsafe void MoveMemory(IntPtr dst, IntPtr src, long size) - { - MoveMemory(dst.ToPointer(), src.ToPointer(), checked((uint)size)); - } - - /// - /// Copies a block of memory from one location to another. - /// - /// A pointer to the starting address of the copied block's destination. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - /// - /// CopyMemory runs faster than . - /// However, if both blocks overlap the result is undefined. - /// - public static unsafe void CopyMemory(byte* dest, byte* src, int len) - { - if (len >= 0x10) - { - do - { - *((int*)dest) = *((int*)src); - *((int*)(dest + 4)) = *((int*)(src + 4)); - *((int*)(dest + 8)) = *((int*)(src + 8)); - *((int*)(dest + 12)) = *((int*)(src + 12)); - dest += 0x10; - src += 0x10; - } - while ((len -= 0x10) >= 0x10); - } - if (len > 0) - { - if ((len & 8) != 0) - { - *((int*)dest) = *((int*)src); - *((int*)(dest + 4)) = *((int*)(src + 4)); - dest += 8; - src += 8; - } - if ((len & 4) != 0) - { - *((int*)dest) = *((int*)src); - dest += 4; - src += 4; - } - if ((len & 2) != 0) - { - *((short*)dest) = *((short*)src); - dest += 2; - src += 2; - } - if ((len & 1) != 0) - { - *dest = *src; - } - } - } - - /// - /// Copies a block of memory from one location to another. - /// - /// A pointer to the starting address of the copied block's destination. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - /// - /// CopyMemory runs faster than . - /// However, if both blocks overlap the result is undefined. - /// - public static unsafe void CopyMemory(byte* dest, byte* src, long len) - { - CopyMemory(dest, src, checked((int)len)); - } - - /// - /// Copies a block of memory from one location to another. - /// - /// A pointer to the starting address of the copied block's destination. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - /// - /// CopyMemory runs faster than . - /// However, if both blocks overlap the result is undefined. - /// - public static unsafe void CopyMemory(void* dest, void* src, long len) - { - CopyMemory((byte*)dest, (byte*)src, checked((int)len)); - } - - /// - /// Copies a block of memory from one location to another. - /// - /// A pointer to the starting address of the copied block's destination. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - /// - /// CopyMemory runs faster than . - /// However, if both blocks overlap the result is undefined. - /// - public static unsafe void CopyMemory(void* dest, void* src, int len) - { - CopyMemory((byte*)dest, (byte*)src, len); - } - - /// - /// Copies a block of memory from one location to another. - /// - /// A pointer to the starting address of the copied block's destination. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - /// - /// CopyMemory runs faster than . - /// However, if both blocks overlap the result is undefined. - /// - public static unsafe void CopyMemory(IntPtr dest, IntPtr src, int len) - { - CopyMemory((byte*)dest, (byte*)src, len); - } - - /// - /// Copies a block of memory from one location to another. - /// - /// A pointer to the starting address of the copied block's destination. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - /// - /// CopyMemory runs faster than . - /// However, if both blocks overlap the result is undefined. - /// - public static unsafe void CopyMemory(IntPtr dest, IntPtr src, long len) - { - CopyMemory((byte*)dest, (byte*)src, checked((int)len)); - } - - /// - /// Copies a block of memory into an array. - /// - /// An array used as the destination of the copy process. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(Array dest, void* src, int len) - { - GCHandle handle = GCHandle.Alloc(dest, GCHandleType.Pinned); - try - { - CopyMemory((byte*)handle.AddrOfPinnedObject(), (byte*)src, len); - } - finally - { - handle.Free(); - } - } - - /// - /// Copies a block of memory into an array. - /// - /// An array used as the destination of the copy process. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(Array dest, void* src, long len) - { - CopyMemory(dest, (byte*)src, checked((int)len)); - } - - /// - /// Copies a block of memory into an array. - /// - /// An array used as the destination of the copy process. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(Array dest, IntPtr src, int len) - { - CopyMemory(dest, (byte*)src, len); - } - - /// - /// Copies a block of memory into an array. - /// - /// An array used as the destination of the copy process. - /// A pointer to the starting address of the block of memory to copy. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(Array dest, IntPtr src, long len) - { - CopyMemory(dest, (byte*)src, checked((int)len)); - } - - /// - /// Copies the content of an array to a memory location. - /// - /// A pointer to the starting address of the copied block's destination. - /// An array used as the source of the copy process. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(void* dest, Array src, int len) - { - GCHandle handle = GCHandle.Alloc(src, GCHandleType.Pinned); - try - { - CopyMemory((byte*)dest, (byte*)handle.AddrOfPinnedObject(), len); - } - finally - { - handle.Free(); - } - } - - /// - /// Copies the content of an array to a memory location. - /// - /// A pointer to the starting address of the copied block's destination. - /// An array used as the source of the copy process. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(void* dest, Array src, long len) - { - CopyMemory((byte*)dest, src, checked((int)len)); - } - - /// - /// Copies the content of an array to a memory location. - /// - /// A pointer to the starting address of the copied block's destination. - /// An array used as the source of the copy process. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(IntPtr dest, Array src, int len) - { - CopyMemory((byte*)dest, src, len); - } - - /// - /// Copies the content of an array to a memory location. - /// - /// A pointer to the starting address of the copied block's destination. - /// An array used as the source of the copy process. - /// The size of the block of memory to copy, in bytes. - public static unsafe void CopyMemory(IntPtr dest, Array src, long len) - { - CopyMemory((byte*)dest, src, checked((int)len)); - } - - /// - /// Copies the content of one array into another array. - /// - /// An array used as the destination of the copy process. - /// An array used as the source of the copy process. - /// The size of the content to copy, in bytes. - public static unsafe void CopyMemory(Array dest, Array src, int len) - { - GCHandle dHandle = GCHandle.Alloc(dest, GCHandleType.Pinned); - try - { - GCHandle sHandle = GCHandle.Alloc(src, GCHandleType.Pinned); - try - { - CopyMemory((byte*)dHandle.AddrOfPinnedObject(), (byte*)sHandle.AddrOfPinnedObject(), len); - } - finally - { - sHandle.Free(); - } - } - finally - { - dHandle.Free(); - } - } - - /// - /// Copies the content of one array into another array. - /// - /// An array used as the destination of the copy process. - /// An array used as the source of the copy process. - /// The size of the content to copy, in bytes. - public static unsafe void CopyMemory(Array dest, Array src, long len) - { - CopyMemory(dest, src, checked((int)len)); - } - - internal static string ColorToString(Color color) - { - return string.Format( - System.Globalization.CultureInfo.CurrentCulture, - "{{Name={0}, ARGB=({1}, {2}, {3}, {4})}}", - new object[] { color.Name, color.A, color.R, color.G, color.B }); - } - - internal static void Resize(ref string str, int length) - { - if ((str != null) && (length >= 0) && (str.Length != length)) - { - char[] chars = str.ToCharArray(); - Array.Resize(ref chars, length); - str = new string(chars); - } - } - - internal static void Resize(ref string str, int min, int max) - { - if ((str != null) && (min >= 0) && (max >= 0) && (min <= max)) - { - if (str.Length < min) - { - char[] chars = str.ToCharArray(); - Array.Resize(ref chars, min); - str = new string(chars); - } - else if (str.Length > max) - { - char[] chars = str.ToCharArray(); - Array.Resize(ref chars, max); - str = new string(chars); - } - } - } - - internal static void Resize(ref T[] array, int length) - { - if ((array != null) && (length >= 0) && (array.Length != length)) - { - Array.Resize(ref array, length); - } - } - - internal static void Resize(ref T[] array, int min, int max) - { - if ((array != null) && (min >= 0) && (max >= 0) && (min <= max)) - { - if (array.Length < min) - { - Array.Resize(ref array, min); - } - else if (array.Length > max) - { - Array.Resize(ref array, max); - } - } - } - - internal static bool CheckColorType(FREE_IMAGE_TYPE imageType, T color) - { - Type type = typeof(T); - bool result; - switch (imageType) - { - case FREE_IMAGE_TYPE.FIT_BITMAP: - result = (type == typeof(RGBQUAD)); break; - case FREE_IMAGE_TYPE.FIT_COMPLEX: - result = (type == typeof(FICOMPLEX)); break; - case FREE_IMAGE_TYPE.FIT_DOUBLE: - result = (type == typeof(double)); break; - case FREE_IMAGE_TYPE.FIT_FLOAT: - result = (type == typeof(float)); break; - case FREE_IMAGE_TYPE.FIT_INT16: - result = (type == typeof(Int16)); break; - case FREE_IMAGE_TYPE.FIT_INT32: - result = (type == typeof(Int32)); break; - case FREE_IMAGE_TYPE.FIT_RGB16: - result = (type == typeof(FIRGB16)); break; - case FREE_IMAGE_TYPE.FIT_RGBA16: - result = (type == typeof(FIRGBA16)); break; - case FREE_IMAGE_TYPE.FIT_RGBAF: - result = (type == typeof(FIRGBAF)); break; - case FREE_IMAGE_TYPE.FIT_RGBF: - result = (type == typeof(FIRGBF)); break; - case FREE_IMAGE_TYPE.FIT_UINT16: - result = (type == typeof(UInt16)); break; - case FREE_IMAGE_TYPE.FIT_UINT32: - result = (type == typeof(UInt32)); break; - default: - result = false; break; - } - return result; - } - - #endregion - - #region Dll-Imports - - /// - /// Retrieves a handle to a display device context (DC) for the client area of a specified window - /// or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC. - /// - /// Handle to the window whose DC is to be retrieved. - /// If this value is IntPtr.Zero, GetDC retrieves the DC for the entire screen. - /// If the function succeeds, the return value is a handle to the DC for the specified window's client area. - /// If the function fails, the return value is NULL. - [DllImport("user32.dll")] - private static extern IntPtr GetDC(IntPtr hWnd); - - /// - /// Releases a device context (DC), freeing it for use by other applications. - /// The effect of the ReleaseDC function depends on the type of DC. It frees only common and window DCs. - /// It has no effect on class or private DCs. - /// - /// Handle to the window whose DC is to be released. - /// Handle to the DC to be released. - /// Returns true on success, false on failure. - [DllImport("user32.dll")] - private static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC); - - /// - /// Creates a DIB that applications can write to directly. - /// The function gives you a pointer to the location of the bitmap bit values. - /// You can supply a handle to a file-mapping object that the function will use to create the bitmap, - /// or you can let the system allocate the memory for the bitmap. - /// - /// Handle to a device context. - /// Pointer to a BITMAPINFO structure that specifies various attributes of the DIB, - /// including the bitmap dimensions and colors. - /// Specifies the type of data contained in the bmiColors array member of the BITMAPINFO structure - /// pointed to by pbmi (either logical palette indexes or literal RGB values). - /// Pointer to a variable that receives a pointer to the location of the DIB bit values. - /// Handle to a file-mapping object that the function will use to create the DIB. - /// This parameter can be NULL. - /// Specifies the offset from the beginning of the file-mapping object referenced by hSection - /// where storage for the bitmap bit values is to begin. This value is ignored if hSection is NULL. - /// If the function succeeds, the return value is a handle to the newly created DIB, - /// and *ppvBits points to the bitmap bit values. If the function fails, the return value is NULL, and *ppvBits is NULL. - [DllImport("gdi32.dll")] - private static extern IntPtr CreateDIBSection( - IntPtr hdc, - [In] IntPtr pbmi, - uint iUsage, - out IntPtr ppvBits, - IntPtr hSection, - uint dwOffset); - - /// - /// Deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object. - /// After the object is deleted, the specified handle is no longer valid. - /// - /// Handle to a logical pen, brush, font, bitmap, region, or palette. - /// Returns true on success, false on failure. - [DllImport("gdi32.dll")] - private static extern bool DeleteObject(IntPtr hObject); - - /// - /// Creates a compatible bitmap (DDB) from a DIB and, optionally, sets the bitmap bits. - /// - /// Handle to a device context. - /// Pointer to a bitmap information header structure. - /// Specifies how the system initializes the bitmap bits - (use 4). - /// Pointer to an array of bytes containing the initial bitmap data. - /// Pointer to a BITMAPINFO structure that describes the dimensions - /// and color format of the array pointed to by the lpbInit parameter. - /// Specifies whether the bmiColors member of the BITMAPINFO structure - /// was initialized - (use 0). - /// Handle to a DIB or null on failure. - [DllImport("gdi32.dll")] - private static extern IntPtr CreateDIBitmap( - IntPtr hdc, - IntPtr lpbmih, - uint fdwInit, - IntPtr lpbInit, - IntPtr lpbmi, - uint fuUsage); - - /// - /// Retrieves information for the specified graphics object. - /// - /// Handle to the graphics object of interest. - /// Specifies the number of bytes of information to - /// be written to the buffer. - /// Pointer to a buffer that receives the information - /// about the specified graphics object. - /// 0 on failure. - [DllImport("gdi32.dll")] - private static extern int GetObject(IntPtr hgdiobj, int cbBuffer, IntPtr lpvObject); - - /// - /// Retrieves the bits of the specified compatible bitmap and copies them into a buffer - /// as a DIB using the specified format. - /// - /// Handle to the device context. - /// Handle to the bitmap. This must be a compatible bitmap (DDB). - /// Specifies the first scan line to retrieve. - /// Specifies the number of scan lines to retrieve. - /// Pointer to a buffer to receive the bitmap data. - /// Pointer to a BITMAPINFO structure that specifies the desired - /// format for the DIB data. - /// Specifies the format of the bmiColors member of the - /// BITMAPINFO structure - (use 0). - /// 0 on failure. - [DllImport("gdi32.dll")] - private static extern unsafe int GetDIBits( - IntPtr hdc, - IntPtr hbmp, - uint uStartScan, - uint cScanLines, - IntPtr lpvBits, - IntPtr lpbmi, - uint uUsage); - - /// - /// Moves a block of memory from one location to another. - /// - /// Pointer to the starting address of the move destination. - /// Pointer to the starting address of the block of memory to be moved. - /// Size of the block of memory to move, in bytes. - [DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false)] - public static unsafe extern void MoveMemory(void* dst, void* src, uint size); - - /// - /// The RtlCompareMemory routine compares blocks of memory - /// and returns the number of bytes that are equivalent. - /// - /// A pointer to a block of memory to compare. - /// A pointer to a block of memory to compare. - /// Specifies the number of bytes to be compared. - /// RtlCompareMemory returns the number of bytes that compare as equal. - /// If all bytes compare as equal, the input Length is returned. - [DllImport("ntdll.dll", EntryPoint = "RtlCompareMemory", SetLastError = false)] - internal static unsafe extern uint RtlCompareMemory(void* buf1, void* buf2, uint count); - - #endregion - } -} +// ========================================================== +// FreeImage 3 .NET wrapper +// Original FreeImage 3 functions and .NET compatible derived functions +// +// Design and implementation by +// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) +// - Carsten Klein (cklein05@users.sourceforge.net) +// +// Contributors: +// - David Boland (davidboland@vodafone.ie) +// +// Main reference : MSDN Knowlede Base +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +// ========================================================== +// To build the project without VS use the following commandline: +// "csc.exe /out:FreeImageNET.dll /target:library /doc:FreeImageNET.XML /debug- /o /unsafe+ /filealign:512 FreeImage.cs" +// ========================================================== + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using System.Xml; +using FreeImageAPI; +using FreeImageAPI.IO; +using FreeImageAPI.Metadata; +using FreeImageAPI.Plugins; + +///////////////////////////////////////////////////// +// // +// FreeImage.h import // +// // +///////////////////////////////////////////////////// + + #region Structs + +namespace FreeImageAPI +{ + /// + /// The BITMAP structure defines the type, width, height, color format, and bit values of a bitmap. + /// + /// + /// The bitmap formats currently used are monochrome and color. The monochrome bitmap uses a one-bit, + /// one-plane format. Each scan is a multiple of 32 bits. + /// + /// Scans are organized as follows for a monochrome bitmap of height n: + /// + /// + /// Scan 0 + /// Scan 1 + /// . + /// . + /// . + /// Scan n-2 + /// Scan n-1 + /// + /// + /// The pixels on a monochrome device are either black or white. If the corresponding bit in the + /// bitmap is 1, the pixel is set to the foreground color; if the corresponding bit in the bitmap + /// is zero, the pixel is set to the background color. + /// + /// All devices that have the RC_BITBLT device capability support bitmaps. For more information, + /// see GetDeviceCaps. + /// + /// Each device has a unique color format. To transfer a bitmap from one device to another, + /// use the GetDIBits and SetDIBits functions. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct BITMAP + { + /// + /// Specifies the bitmap type. This member must be zero. + /// + public int bmType; + /// + /// Specifies the width, in pixels, of the bitmap. The width must be greater than zero. + /// + public int bmWidth; + /// + /// Specifies the height, in pixels, of the bitmap. The height must be greater than zero. + /// + public int bmHeight; + /// + /// Specifies the number of bytes in each scan line. This value must be divisible by 2, + /// because the system assumes that the bit values of a bitmap form an array that is word aligned. + /// + public int bmWidthBytes; + /// + /// Specifies the count of color planes. + /// + public ushort bmPlanes; + /// + /// Specifies the number of bits required to indicate the color of a pixel. + /// + public ushort bmBitsPixel; + /// + /// Pointer to the location of the bit values for the bitmap. + /// The bmBits member must be a long pointer to an array of character (1-byte) values. + /// + public IntPtr bmBits; + } +} + +namespace FreeImageAPI +{ + /// + /// This structure contains information about the dimensions and color format + /// of a device-independent bitmap (DIB). + /// + /// + /// The structure combines the + /// BITMAPINFOHEADER structure and a color table to provide a complete + /// definition of the dimensions and colors of a DIB. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct BITMAPINFOHEADER : IEquatable + { + /// + /// Specifies the size of the structure, in bytes. + /// + public uint biSize; + /// + /// Specifies the width of the bitmap, in pixels. + /// + /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, + /// the biWidth member specifies the width of the decompressed JPEG or PNG image file, + /// respectively. + /// + public int biWidth; + /// + /// Specifies the height of the bitmap, in pixels. If biHeight is positive, the bitmap + /// is a bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, + /// the bitmap is a top-down DIB and its origin is the upper-left corner. + /// + /// If biHeight is negative, indicating a top-down DIB, biCompression must be + /// either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed. + /// + /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, + /// the biHeight member specifies the height of the decompressed JPEG or PNG image file, + /// respectively. + /// + public int biHeight; + /// + /// Specifies the number of planes for the target device. This value must be set to 1. + /// + public ushort biPlanes; + /// + /// Specifies the number of bits per pixel.The biBitCount member of the BITMAPINFOHEADER + /// structure determines the number of bits that define each pixel and the maximum number of + /// colors in the bitmap. This member must be one of the following values. + /// + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// + /// 0 + /// + /// Windows 98/Me, Windows 2000/XP: The number of bits-per-pixel is specified + /// or is implied by the JPEG or PNG format. + /// + /// + /// + /// + /// 1 + /// + /// The bitmap is monochrome, and the bmiColors member of + /// contains two entries. Each bit in the bitmap array represents a pixel. If the bit is clear, + /// the pixel is displayed with the color of the first entry in the bmiColors table; if the bit + /// is set, the pixel has the color of the second entry in the table. + /// + /// + /// + /// + /// 4 + /// + /// The bitmap has a maximum of 16 colors, and the bmiColors member of BITMAPINFO + /// contains up to 16 entries. Each pixel in the bitmap is represented by a 4-bit index into the + /// color table. For example, if the first byte in the bitmap is 0x1F, the byte represents two + /// pixels. The first pixel contains the color in the second table entry, and the second pixel + /// contains the color in the sixteenth table entry. + /// + /// + /// + /// 8 + /// + /// The bitmap has a maximum of 256 colors, and the bmiColors member of BITMAPINFO + /// contains up to 256 entries. In this case, each byte in the array represents a single pixel. + /// + /// + /// + /// + /// 16 + /// + /// The bitmap has a maximum of 2^16 colors. If the biCompression member of the + /// BITMAPINFOHEADER is BI_RGB, the bmiColors member of BITMAPINFO is NULL. + /// Each WORD in the bitmap array represents a single pixel. The relative intensities + /// of red, green, and blue are represented with five bits for each color component. + /// The value for blue is in the least significant five bits, followed by five bits each for + /// green and red. The most significant bit is not used. The bmiColors color table is used + /// for optimizing colors used on palette-based devices, and must contain the number of entries + /// specified by the biClrUsed member of the BITMAPINFOHEADER. + /// + /// If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, the + /// bmiColors member contains three DWORD color masks that specify the red, green, + /// and blue components, respectively, of each pixel. Each WORD in the bitmap array represents + /// a single pixel. + /// + /// Windows NT/Windows 2000/XP: When the biCompression member is BI_BITFIELDS, + /// bits set in each DWORD mask must be contiguous and should not overlap the bits + /// of another mask. All the bits in the pixel do not have to be used. + /// + /// Windows 95/98/Me: When the biCompression member is BI_BITFIELDS, the system + /// supports only the following 16bpp color masks: A 5-5-5 16-bit image, where the blue mask is + /// 0x001F, the green mask is 0x03E0, and the red mask is 0x7C00; and a 5-6-5 16-bit image, + /// where the blue mask is 0x001F, the green mask is 0x07E0, and the red mask is 0xF800. + /// + /// + /// + /// + /// 24 + /// + /// The bitmap has a maximum of 2^24 colors, and the bmiColors member of BITMAPINFO + /// is NULL. Each 3-byte triplet in the bitmap array represents the relative intensities of blue, + /// green, and red, respectively, for a pixel. The bmiColors color table is used for + /// optimizing colors used on palette-based devices, and must contain the number of entries + /// specified by the biClrUsed member of the BITMAPINFOHEADER. + /// + /// + /// + /// + /// 32 + /// + /// The bitmap has a maximum of 2^32 colors. If the biCompression member of the + /// BITMAPINFOHEADER is BI_RGB, the bmiColors member of BITMAPINFO is NULL. + /// Each DWORD in the bitmap array represents the relative intensities of blue, green, and red, + /// respectively, for a pixel. The high byte in each DWORD is not used. The bmiColors + /// color table is used for optimizing colors used on palette-based devices, and must contain the + /// number of entries specified by the biClrUsed member of the BITMAPINFOHEADER. + /// + /// If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, + /// the bmiColors member contains three DWORD color masks that specify the red, green, + /// and blue components, respectively, of each pixel. Each DWORD in the bitmap array represents + /// a single pixel. + /// + /// Windows NT/ 2000: When the biCompression member is BI_BITFIELDS, bits set in each + /// DWORD mask must be contiguous and should not overlap the bits of another mask. All the + /// bits in the pixel do not need to be used. + /// + /// Windows 95/98/Me: When the biCompression member is BI_BITFIELDS, the system + /// supports only the following 32-bpp color mask: The blue mask is 0x000000FF, the green mask is + /// 0x0000FF00, and the red mask is 0x00FF0000. + /// + /// + /// + /// + public ushort biBitCount; + /// + /// Specifies the type of compression for a compressed bottom-up bitmap (top-down DIBs cannot be + /// compressed). + /// + /// + /// Value + /// Meaning + /// + /// + /// + /// BI_RGB + /// An uncompressed format. + /// + /// + /// + /// BI_RLE8 + /// A run-length encoded (RLE) format for bitmaps with 8 bpp. The compression format + /// is a 2-byte format consisting of a count byte followed by a byte containing a color index. + /// + /// + /// + /// + /// BI_RLE4 + /// An RLE format for bitmaps with 4 bpp. The compression format is a 2-byte format + /// consisting of a count byte followed by two word-length color indexes. + /// + /// + /// + /// BI_BITFIELDS + /// Specifies that the bitmap is not compressed and that the color table consists + /// of three DWORD color masks that specify the red, green, and blue components, respectively, + /// of each pixel. This is valid when used with 16- and 32-bpp bitmaps. + /// + /// + /// + /// BI_JPEG + /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a JPEG image. + /// + /// + /// + /// + /// BI_PNG + /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a PNG image. + /// + /// + /// + /// + /// + public uint biCompression; + /// + /// Specifies the size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps. + /// + /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, + /// biSizeImage indicates the size of the JPEG or PNG image buffer, respectively. + /// + public uint biSizeImage; + /// + /// Specifies the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. + /// An application can use this value to select a bitmap from a resource group that best matches + /// the characteristics of the current device. + /// + public int biXPelsPerMeter; + /// + /// Specifies the vertical resolution, in pixels-per-meter, of the target device for the bitmap. + /// + public int biYPelsPerMeter; + /// + /// Specifies the number of color indexes in the color table that are actually used by the bitmap. + /// If this value is zero, the bitmap uses the maximum number of colors corresponding to the value + /// of the biBitCount member for the compression mode specified by biCompression. + /// + /// If iClrUsed is nonzero and the biBitCount member is less than 16, the biClrUsed + /// member specifies the actual number of colors the graphics engine or device driver accesses. + /// If biBitCount is 16 or greater, the biClrUsed member specifies the size of the color + /// table used to optimize performance of the system color palettes. If biBitCount equals 16 or 32, + /// the optimal color palette starts immediately following the three DWORD masks. + /// + /// When the bitmap array immediately follows the structure, it is a packed bitmap. + /// Packed bitmaps are referenced by a single pointer. Packed bitmaps require that the + /// biClrUsed member must be either zero or the actual size of the color table. + /// + public uint biClrUsed; + /// + /// Specifies the number of color indexes that are required for displaying the bitmap. If this value + /// is zero, all colors are required. + /// + public uint biClrImportant; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(BITMAPINFOHEADER left, BITMAPINFOHEADER right) + { + return ((left.biSize == right.biSize) && + (left.biWidth == right.biWidth) && + (left.biHeight == right.biHeight) && + (left.biPlanes == right.biPlanes) && + (left.biBitCount == right.biBitCount) && + (left.biCompression == right.biCompression) && + (left.biSizeImage == right.biSizeImage) && + (left.biXPelsPerMeter == right.biXPelsPerMeter) && + (left.biYPelsPerMeter == right.biYPelsPerMeter) && + (left.biClrUsed == right.biClrUsed) && + (left.biClrImportant == right.biClrImportant)); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(BITMAPINFOHEADER left, BITMAPINFOHEADER right) + { + return !(left == right); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(BITMAPINFOHEADER other) + { + return (this == other); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is BITMAPINFOHEADER) && (this == (BITMAPINFOHEADER)obj)); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The BITMAPINFO structure defines the dimensions and color information for a DIB. + /// + /// + /// A DIB consists of two distinct parts: a BITMAPINFO structure describing the dimensions + /// and colors of the bitmap, and an array of bytes defining the pixels of the bitmap. The bits in + /// the array are packed together, but each scan line must be padded with zeroes to end on a + /// LONG data-type boundary. If the height of the bitmap is positive, the bitmap is a + /// bottom-up DIB and its origin is the lower-left corner. If the height is negative, the bitmap is + /// a top-down DIB and its origin is the upper left corner. + /// + /// A bitmap is packed when the bitmap array immediately follows the BITMAPINFO header. + /// Packed bitmaps are referenced by a single pointer. For packed bitmaps, the biClrUsed + /// member must be set to an even number when using the DIB_PAL_COLORS mode so that the DIB bitmap + /// array starts on a DWORD boundary. + /// + /// Note The bmiColors member should not contain palette indexes if the bitmap is to + /// be stored in a file or transferred to another application. + /// + /// Unless the application has exclusive use and control of the bitmap, the bitmap color table + /// should contain explicit RGB values. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct BITMAPINFO : IEquatable + { + /// + /// Specifies a structure that contains information + /// about the dimensions of color format. + /// + public BITMAPINFOHEADER bmiHeader; + /// + /// The bmiColors member contains one of the following: + /// + /// + /// + /// + /// An array of . The elements of the array that make up the + /// color table. + /// + /// + /// + /// + /// + /// An array of 16-bit unsigned integers that specifies indexes into the currently realized + /// logical palette. This use of bmiColors is allowed for functions that use DIBs. + /// When bmiColors elements contain indexes to a realized logical palette, they must + /// also call the following bitmap functions: + /// + /// + /// + /// + /// CreateDIBitmap + /// + /// CreateDIBPatternBrush + /// + /// CreateDIBSection + /// + /// The iUsage parameter of CreateDIBSection must be set to DIB_PAL_COLORS. + /// + /// The number of entries in the array depends on the values of the biBitCount and + /// biClrUsed members of the structure. + /// + /// The colors in the bmiColors table appear in order of importance. For more information, + /// see the Remarks section. + /// + public RGBQUAD[] bmiColors; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(BITMAPINFO left, BITMAPINFO right) + { + if (left.bmiHeader != right.bmiHeader) + { + return false; + } + if ((left.bmiColors == null) && (right.bmiColors == null)) + { + return true; + } + if ((left.bmiColors == null) || (right.bmiColors == null)) + { + return false; + } + if (left.bmiColors.Length != right.bmiColors.Length) + { + return false; + } + for (int i = 0; i < left.bmiColors.Length; i++) + { + if (left.bmiColors[i] != right.bmiColors[i]) + { + return false; + } + } + return true; + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(BITMAPINFO left, BITMAPINFO right) + { + return !(left == right); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(BITMAPINFO other) + { + return (this == other); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is BITMAPINFO) && (this == ((BITMAPINFO)obj))); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + int hash = bmiHeader.GetHashCode(); + if (bmiColors != null) + { + for (int c = 0; c < bmiColors.Length; c++) + { + hash ^= bmiColors[c].GetHashCode(); + hash <<= 1; + } + hash <<= 1; + } + else + { + hash >>= 1; + } + return hash; + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FIBITMAP structure is a handle to a FreeImage bimtap. + /// + /// + /// The handle represented by a FIBITBAP structure provides + /// access to either a singlepage bitmap or exactly one page of + /// a multipage bitmap. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIBITMAP : IComparable, IComparable, IEquatable + { + private IntPtr data; + + /// + /// A read-only field that represents a handle that has been initialized to zero. + /// + public static readonly FIBITMAP Zero; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIBITMAP left, FIBITMAP right) + { + return (left.data == right.data); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIBITMAP left, FIBITMAP right) + { + return (left.data != right.data); + } + + /// + /// Gets whether the handle is a null or not. + /// + /// true if this handle is a null; + /// otherwise, false. + public bool IsNull + { + get + { + return (data == IntPtr.Zero); + } + } + + /// + /// Sets the handle to null. + /// + public void SetNull() + { + data = IntPtr.Zero; + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return data.ToString(); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return data.GetHashCode(); + } + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current ; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIBITMAP) && (this == ((FIBITMAP)obj))); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// An object to compare with this object. + /// true if the current object is equal to the other parameter; otherwise, false. + public bool Equals(FIBITMAP other) + { + return (this == other); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIBITMAP)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIBITMAP)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIBITMAP other) + { + return this.data.ToInt64().CompareTo(other.data.ToInt64()); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FIMULTIBITMAP structure is a handle to a FreeImage multipaged bimtap. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIMULTIBITMAP : IComparable, IComparable, IEquatable + { + private IntPtr data; + + /// + /// A read-only field that represents a handle that has been initialized to zero. + /// + public static readonly FIMULTIBITMAP Zero; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIMULTIBITMAP left, FIMULTIBITMAP right) + { + return (left.data == right.data); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIMULTIBITMAP left, FIMULTIBITMAP right) + { + return (left.data != right.data); + } + + /// + /// Gets whether the handle is a null or not. + /// + /// true if this handle is a null; + /// otherwise, false. + public bool IsNull + { + get + { + return (data == IntPtr.Zero); + } + } + + /// + /// Sets the handle to null. + /// + public void SetNull() + { + data = IntPtr.Zero; + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return data.ToString(); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return data.GetHashCode(); + } + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current ; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIMULTIBITMAP) && (this == ((FIMULTIBITMAP)obj))); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// An object to compare with this object. + /// true if the current object is equal to the other parameter; otherwise, false. + public bool Equals(FIMULTIBITMAP other) + { + return (this == other); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIMULTIBITMAP)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIMULTIBITMAP)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIMULTIBITMAP other) + { + return this.data.ToInt64().CompareTo(other.data.ToInt64()); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FIMEMORY structure is a handle to an opened memory stream. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIMEMORY : IComparable, IComparable, IEquatable + { + private IntPtr data; + + /// + /// A read-only field that represents a handle that has been initialized to zero. + /// + public static readonly FIMEMORY Zero; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIMEMORY left, FIMEMORY right) + { + return (left.data == right.data); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIMEMORY left, FIMEMORY right) + { + return (left.data != right.data); + } + + /// + /// Gets whether the pointer is a null pointer or not. + /// + /// true if this is a null pointer; + /// otherwise, false. + public bool IsNull + { + get + { + return (data == IntPtr.Zero); + } + } + + /// + /// Sets the handle to null. + /// + public void SetNull() + { + data = IntPtr.Zero; + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return data.ToString(); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return data.GetHashCode(); + } + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current ; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIMEMORY) && (this == ((FIMEMORY)obj))); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// An object to compare with this object. + /// true if the current object is equal to the other parameter; otherwise, false. + public bool Equals(FIMEMORY other) + { + return (this == other); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIMEMORY)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIMEMORY)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIMEMORY other) + { + return this.data.ToInt64().CompareTo(other.data.ToInt64()); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FIMETADATA structure is an unique search handle for metadata search operations. + /// + /// + /// The FIMETADATA structure is usually returned by the + /// + /// function and then used on subsequent calls to + /// . + /// When the FIMETADATA handle is no longer used, it needs to be freed by the + /// function. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIMETADATA : IComparable, IComparable, IEquatable + { + private IntPtr data; + + /// + /// A read-only field that represents a handle that has been initialized to zero. + /// + public static readonly FIMETADATA Zero; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIMETADATA left, FIMETADATA right) + { + return (left.data == right.data); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIMETADATA left, FIMETADATA right) + { + return (left.data != right.data); + } + + /// + /// Gets whether the pointer is a null pointer or not. + /// + /// true if this is a null pointer; + /// otherwise, false. + public bool IsNull + { + get + { + return (data == IntPtr.Zero); + } + } + + /// + /// Sets the handle to null. + /// + public void SetNull() + { + data = IntPtr.Zero; + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return data.ToString(); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return data.GetHashCode(); + } + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current ; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIMETADATA) && (this == ((FIMETADATA)obj))); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// An object to compare with this object. + /// true if the current object is equal to the other parameter; otherwise, false. + public bool Equals(FIMETADATA other) + { + return (this == other); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIMETADATA)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIMETADATA)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIMETADATA other) + { + return this.data.ToInt64().CompareTo(other.data.ToInt64()); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FITAG structure is a handle to a FreeImage metadata tag. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FITAG : IComparable, IComparable, IEquatable + { + private IntPtr data; + + /// + /// A read-only field that represents a handle that has been initialized to zero. + /// + public static readonly FITAG Zero; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FITAG left, FITAG right) + { + return (left.data == right.data); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FITAG left, FITAG right) + { + return (left.data != right.data); + } + + /// + /// Gets whether the pointer is a null pointer or not. + /// + /// true if this is a null pointer; + /// otherwise, false. + public bool IsNull + { + get + { + return (data == IntPtr.Zero); + } + } + + /// + /// Sets the handle to null. + /// + public void SetNull() + { + data = IntPtr.Zero; + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return data.ToString(); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return data.GetHashCode(); + } + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current ; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FITAG) && (this == ((FITAG)obj))); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// An object to compare with this object. + /// true if the current object is equal to the other parameter; otherwise, false. + public bool Equals(FITAG other) + { + return (this == other); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FITAG)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FITAG)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FITAG other) + { + return this.data.ToInt64().CompareTo(other.data.ToInt64()); + } + } +} + +namespace FreeImageAPI.IO +{ + /// + /// Structure for implementing access to custom handles. + /// + [StructLayout(LayoutKind.Sequential)] + public struct FreeImageIO + { + /// + /// Delegate to the C++ function fread. + /// + public ReadProc readProc; + + /// + /// Delegate to the C++ function fwrite. + /// + public WriteProc writeProc; + + /// + /// Delegate to the C++ function fseek. + /// + public SeekProc seekProc; + + /// + /// Delegate to the C++ function ftell. + /// + public TellProc tellProc; + } +} + +namespace FreeImageAPI +{ + /// + /// The RGBQUAD structure describes a color consisting of relative + /// intensities of red, green, blue and alpha value. Each single color + /// component consumes 8 bits and so, takes values in the range from 0 to 255. + /// + /// + /// + /// The RGBQUAD structure provides access to an underlying Win32 RGBQUAD + /// structure. To determine the alpha, red, green or blue component of a color, + /// use the rgbReserved, rgbRed, rgbGreen or rgbBlue fields, respectively. + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the RGBQUAD structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the RGBQUAD structure and my be used in all situations which require + /// an RGBQUAD type. + /// + /// + /// Each color component rgbReserved, rgbRed, rgbGreen or rgbBlue of RGBQUAD + /// is translated into it's corresponding color component A, R, G or B of + /// by an one-to-one manner and vice versa. + /// + /// + /// Conversion from System.Drawing.Color to RGBQUAD + /// + /// RGBQUAD.component = Color.component + /// + /// Conversion from RGBQUAD to System.Drawing.Color + /// + /// Color.component = RGBQUAD.component + /// + /// The same conversion is also applied when the + /// property or the constructor + /// is invoked. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// RGBQUAD structure and the structure. + /// + /// RGBQUAD rgbq; + /// // Initialize the structure using a native .NET Color structure. + /// rgbq = new RGBQUAD(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// rgbq = Color.DarkSeaGreen; + /// // Convert the RGBQUAD instance into a native .NET Color + /// // using its implicit operator. + /// Color color = rgbq; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = rgbq.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Explicit)] + public struct RGBQUAD : IComparable, IComparable, IEquatable + { + /// + /// The blue color component. + /// + [FieldOffset(0)] + public byte rgbBlue; + + /// + /// The green color component. + /// + [FieldOffset(1)] + public byte rgbGreen; + + /// + /// The red color component. + /// + [FieldOffset(2)] + public byte rgbRed; + + /// + /// The alpha color component. + /// + [FieldOffset(3)] + public byte rgbReserved; + + /// + /// The color's value. + /// + [FieldOffset(0)] + public uint uintValue; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public RGBQUAD(Color color) + { + uintValue = 0u; + rgbBlue = color.B; + rgbGreen = color.G; + rgbRed = color.R; + rgbReserved = color.A; + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(RGBQUAD left, RGBQUAD right) + { + return (left.uintValue == right.uintValue); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(RGBQUAD left, RGBQUAD right) + { + return (left.uintValue != right.uintValue); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator RGBQUAD(Color value) + { + return new RGBQUAD(value); + } + + /// + /// Converts the value of a structure to a Color structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(RGBQUAD value) + { + return value.Color; + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator RGBQUAD(uint value) + { + RGBQUAD result = new RGBQUAD(); + result.uintValue = value; + return result; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator uint(RGBQUAD value) + { + return value.uintValue; + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb( + rgbReserved, + rgbRed, + rgbGreen, + rgbBlue); + } + set + { + rgbRed = value.R; + rgbGreen = value.G; + rgbBlue = value.B; + rgbReserved = value.A; + } + } + + /// + /// Converts an array of into an array of + /// . + /// + /// The array to convert. + /// An array of . + public static RGBQUAD[] ToRGBQUAD(Color[] array) + { + if (array == null) + return null; + + RGBQUAD[] result = new RGBQUAD[array.Length]; + for (int i = 0; i < array.Length; i++) + { + result[i] = array[i]; + } + return result; + } + + /// + /// Converts an array of into an array of + /// . + /// + /// The array to convert. + /// An array of . + public static Color[] ToColor(RGBQUAD[] array) + { + if (array == null) + return null; + + Color[] result = new Color[array.Length]; + for (int i = 0; i < array.Length; i++) + { + result[i] = array[i].Color; + } + return result; + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is RGBQUAD)) + { + throw new ArgumentException("obj"); + } + return CompareTo((RGBQUAD)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(RGBQUAD other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is RGBQUAD) && (this == ((RGBQUAD)obj))); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(RGBQUAD other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The RGBTRIPLE structure describes a color consisting of relative + /// intensities of red, green and blue value. Each single color component + /// consumes 8 bits and so, takes values in the range from 0 to 255. + /// + /// + /// + /// The RGBTRIPLE structure provides access to an underlying Win32 RGBTRIPLE + /// structure. To determine the red, green or blue component of a color, use the + /// rgbtRed, rgbtGreen or rgbtBlue fields, respectively. + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the RGBTRIPLE structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the RGBTRIPLE structure and my be used in all situations which require + /// an RGBTRIPLE type. + /// + /// + /// Each of the color components rgbtRed, rgbtGreen or rgbtBlue of RGBTRIPLE is + /// translated into it's corresponding color component R, G or B of + /// by an one-to-one manner and vice versa. + /// When converting from into RGBTRIPLE, the + /// color's alpha value is ignored and assumed to be 255 when converting from + /// RGBTRIPLE into , creating a fully + /// opaque color. + /// + /// + /// Conversion from System.Drawing.Color to RGBTRIPLE + /// + /// RGBTRIPLE.component = Color.component + /// + /// Conversion from RGBTRIPLE to System.Drawing.Color + /// + /// Color.component = RGBTRIPLE.component + /// + /// The same conversion is also applied when the + /// property or the constructor + /// is invoked. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// RGBTRIPLE structure and the structure. + /// + /// RGBTRIPLE rgbt; + /// // Initialize the structure using a native .NET Color structure. + /// rgbt = new RGBTRIPLE(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// rgbt = Color.DarkSeaGreen; + /// // Convert the RGBTRIPLE instance into a native .NET Color + /// // using its implicit operator. + /// Color color = rgbt; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = rgbt.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct RGBTRIPLE : IComparable, IComparable, IEquatable + { + /// + /// The blue color component. + /// + public byte rgbtBlue; + + /// + /// The green color component. + /// + public byte rgbtGreen; + + /// + /// The red color component. + /// + public byte rgbtRed; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public RGBTRIPLE(Color color) + { + rgbtBlue = color.B; + rgbtGreen = color.G; + rgbtRed = color.R; + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(RGBTRIPLE left, RGBTRIPLE right) + { + return + left.rgbtBlue == right.rgbtBlue && + left.rgbtGreen == right.rgbtGreen && + left.rgbtRed == right.rgbtRed; + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(RGBTRIPLE left, RGBTRIPLE right) + { + return !(left == right); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator RGBTRIPLE(Color value) + { + return new RGBTRIPLE(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(RGBTRIPLE value) + { + return value.Color; + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator RGBTRIPLE(uint value) + { + RGBTRIPLE result = new RGBTRIPLE(); + result.rgbtBlue = (byte)(value & 0xFF); + result.rgbtGreen = (byte)((value >> 8) & 0xFF); + result.rgbtRed = (byte)((value >> 16) & 0xFF); + return result; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator uint(RGBTRIPLE value) + { + return (uint)((value.rgbtRed << 16) | (value.rgbtGreen << 8) | (value.rgbtBlue)); + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb( + rgbtRed, + rgbtGreen, + rgbtBlue); + } + set + { + rgbtBlue = value.B; + rgbtGreen = value.G; + rgbtRed = value.R; + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is RGBTRIPLE)) + { + throw new ArgumentException("obj"); + } + return CompareTo((RGBTRIPLE)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(RGBTRIPLE other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is RGBTRIPLE) && (this == ((RGBTRIPLE)obj))); + } + + /// + /// Tests whether the specified structure is equivalent to this + /// structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(RGBTRIPLE other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FIRGBA16 structure describes a color consisting of relative + /// intensities of red, green, blue and alpha value. Each single color + /// component consumes 16 bits and so, takes values in the range from 0 to 65535. + /// + /// + /// + /// The FIRGBA16 structure provides access to an underlying FreeImage FIRGBA16 + /// structure. To determine the alpha, red, green or blue component of a color, + /// use the alpha, red, green or blue fields, respectively. + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the FIRGBA16 structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the FIRGBA16 structure and my be used in all situations which require + /// an FIRGBA16 type. + /// + /// + /// Each color component alpha, red, green or blue of FIRGBA16 + /// is translated into it's corresponding color component A, R, G or B of + /// by an 8 bit right shift and vice versa. + /// + /// + /// Conversion from System.Drawing.Color to FIRGBA16 + /// + /// FIRGBA16.component = Color.component << 8 + /// + /// Conversion from FIRGBA16 to System.Drawing.Color + /// + /// Color.component = FIRGBA16.component >> 8 + /// + /// The same conversion is also applied when the + /// property or the constructor + /// is invoked. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// FIRGBA16 structure and the structure. + /// + /// FIRGBA16 firgba16; + /// // Initialize the structure using a native .NET Color structure. + /// firgba16 = new FIRGBA16(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// firgba16 = Color.DarkSeaGreen; + /// // Convert the FIRGBA16 instance into a native .NET Color + /// // using its implicit operator. + /// Color color = firgba16; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = firgba16.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIRGBA16 : IComparable, IComparable, IEquatable + { + /// + /// The red color component. + /// + public ushort red; + + /// + /// The green color component. + /// + public ushort green; + + /// + /// The blue color component. + /// + public ushort blue; + + /// + /// The alpha color component. + /// + public ushort alpha; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public FIRGBA16(Color color) + { + red = (ushort)(color.R << 8); + green = (ushort)(color.G << 8); + blue = (ushort)(color.B << 8); + alpha = (ushort)(color.A << 8); + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIRGBA16 left, FIRGBA16 right) + { + return + ((left.alpha == right.alpha) && + (left.blue == right.blue) && + (left.green == right.green) && + (left.red == right.red)); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIRGBA16 left, FIRGBA16 right) + { + return !(left == right); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIRGBA16(Color value) + { + return new FIRGBA16(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(FIRGBA16 value) + { + return value.Color; + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb((alpha >> 8), (red >> 8), (green >> 8), (blue >> 8)); + } + set + { + red = (ushort)(value.R << 8); + green = (ushort)(value.G << 8); + blue = (ushort)(value.B << 8); + alpha = (ushort)(value.A << 8); + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIRGBA16)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIRGBA16)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIRGBA16 other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIRGBA16) && (this == ((FIRGBA16)obj))); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FIRGBA16 other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FIRGB16 structure describes a color consisting of relative + /// intensities of red, green, blue and alpha value. Each single color + /// component consumes 16 bits and so, takes values in the range from 0 to 65535. + /// + /// + /// + /// The FIRGB16 structure provides access to an underlying FreeImage FIRGB16 + /// structure. To determine the red, green or blue component of a color, + /// use the red, green or blue fields, respectively. + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the FIRGB16 structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the FIRGB16 structure and my be used in all situations which require + /// an FIRGB16 type. + /// + /// + /// Each color component red, green or blue of FIRGB16 is translated into + /// it's corresponding color component R, G or B of + /// by right shifting 8 bits and shifting left 8 bits for the reverse conversion. + /// When converting from into FIRGB16, the + /// color's alpha value is ignored and assumed to be 255 when converting from + /// FIRGB16 into , creating a fully + /// opaque color. + /// + /// + /// Conversion from System.Drawing.Color to FIRGB16 + /// + /// FIRGB16.component = Color.component << 8 + /// + /// Conversion from FIRGB16 to System.Drawing.Color + /// + /// Color.component = FIRGB16.component >> 8 + /// + /// The same conversion is also applied when the + /// property or the constructor + /// is invoked. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// FIRGB16 structure and the structure. + /// + /// FIRGB16 firgb16; + /// // Initialize the structure using a native .NET Color structure. + /// firgb16 = new FIRGBA16(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// firgb16 = Color.DarkSeaGreen; + /// // Convert the FIRGB16 instance into a native .NET Color + /// // using its implicit operator. + /// Color color = firgb16; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = firgb16.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIRGB16 : IComparable, IComparable, IEquatable + { + /// + /// The red color component. + /// + public ushort red; + + /// + /// The green color component. + /// + public ushort green; + + /// + /// The blue color component. + /// + public ushort blue; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public FIRGB16(Color color) + { + red = (ushort)(color.R << 8); + green = (ushort)(color.G << 8); + blue = (ushort)(color.B << 8); + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIRGB16 left, FIRGB16 right) + { + return + ((left.blue == right.blue) && + (left.green == right.green) && + (left.red == right.red)); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIRGB16 left, FIRGB16 right) + { + return !(left == right); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIRGB16(Color value) + { + return new FIRGB16(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(FIRGB16 value) + { + return value.Color; + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb((red >> 8), (green >> 8), (blue >> 8)); + } + set + { + red = (ushort)(value.R << 8); + green = (ushort)(value.G << 8); + blue = (ushort)(value.B << 8); + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIRGB16)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIRGB16)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIRGB16 other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIRGB16) && (this == ((FIRGB16)obj))); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FIRGB16 other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FIRGBAF structure describes a color consisting of relative + /// intensities of red, green, blue and alpha value. Each single color + /// component consumes 32 bits and takes values in the range from 0 to 1. + /// + /// + /// + /// The FIRGBAF structure provides access to an underlying FreeImage FIRGBAF + /// structure. To determine the alpha, red, green or blue component of a color, + /// use the alpha, red, green or blue fields, respectively. + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the FIRGBAF structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the FIRGBAF structure and my be used in all situations which require + /// an FIRGBAF type. + /// + /// + /// Each color component alpha, red, green or blue of FIRGBAF is translated + /// into it's corresponding color component A, R, G or B of + /// by linearly mapping the values of one range + /// into the other range and vice versa. + /// + /// + /// Conversion from System.Drawing.Color to FIRGBAF + /// + /// FIRGBAF.component = (float)Color.component / 255f + /// + /// Conversion from FIRGBAF to System.Drawing.Color + /// + /// Color.component = (int)(FIRGBAF.component * 255f) + /// + /// The same conversion is also applied when the + /// property or the constructor + /// is invoked. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// FIRGBAF structure and the structure. + /// + /// FIRGBAF firgbaf; + /// // Initialize the structure using a native .NET Color structure. + /// firgbaf = new FIRGBAF(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// firgbaf = Color.DarkSeaGreen; + /// // Convert the FIRGBAF instance into a native .NET Color + /// // using its implicit operator. + /// Color color = firgbaf; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = firgbaf.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIRGBAF : IComparable, IComparable, IEquatable + { + /// + /// The red color component. + /// + public float red; + + /// + /// The green color component. + /// + public float green; + + /// + /// The blue color component. + /// + public float blue; + + /// + /// The alpha color component. + /// + public float alpha; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public FIRGBAF(Color color) + { + red = (float)color.R / 255f; + green = (float)color.G / 255f; + blue = (float)color.B / 255f; + alpha = (float)color.A / 255f; + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIRGBAF left, FIRGBAF right) + { + return + ((left.alpha == right.alpha) && + (left.blue == right.blue) && + (left.green == right.green) && + (left.red == right.red)); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIRGBAF left, FIRGBAF right) + { + return !(left == right); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIRGBAF(Color value) + { + return new FIRGBAF(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(FIRGBAF value) + { + return value.Color; + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb( + (int)(alpha * 255f), + (int)(red * 255f), + (int)(green * 255f), + (int)(blue * 255f)); + } + set + { + red = (float)value.R / 255f; + green = (float)value.G / 255f; + blue = (float)value.B / 255f; + alpha = (float)value.A / 255f; + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIRGBAF)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIRGBAF)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIRGBAF other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIRGBAF) && (this == ((FIRGBAF)obj))); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FIRGBAF other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FIRGBF structure describes a color consisting of relative + /// intensities of red, green, blue and alpha value. Each single color + /// component consumes 32 bits and takes values in the range from 0 to 1. + /// + /// + /// + /// The FIRGBF structure provides access to an underlying FreeImage FIRGBF + /// structure. To determine the red, green or blue component of a color, use the + /// red, green or blue fields, respectively. + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the FIRGBF structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the FIRGBF structure and my be used in all situations which require + /// an FIRGBF type. + /// + /// + /// Each color component alpha, red, green or blue of FIRGBF is translated + /// into it's corresponding color component A, R, G or B of + /// by linearly mapping the values of one range + /// into the other range and vice versa. + /// When converting from into FIRGBF, the + /// color's alpha value is ignored and assumed to be 255 when converting from + /// FIRGBF into , creating a fully + /// opaque color. + /// + /// + /// Conversion from System.Drawing.Color to FIRGBF + /// + /// FIRGBF.component = (float)Color.component / 255f + /// + /// Conversion from FIRGBF to System.Drawing.Color + /// + /// Color.component = (int)(FIRGBF.component * 255f) + /// + /// The same conversion is also applied when the + /// property or the constructor + /// is invoked. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// FIRGBF structure and the structure. + /// + /// FIRGBF firgbf; + /// // Initialize the structure using a native .NET Color structure. + /// firgbf = new FIRGBF(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// firgbf = Color.DarkSeaGreen; + /// // Convert the FIRGBF instance into a native .NET Color + /// // using its implicit operator. + /// Color color = firgbf; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = firgbf.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIRGBF : IComparable, IComparable, IEquatable + { + /// + /// The red color component. + /// + public float red; + + /// + /// The green color component. + /// + public float green; + + /// + /// The blue color component. + /// + public float blue; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public FIRGBF(Color color) + { + red = (float)color.R / 255f; + green = (float)color.G / 255f; + blue = (float)color.B / 255f; + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FIRGBF left, FIRGBF right) + { + return + ((left.blue == right.blue) && + (left.green == right.green) && + (left.red == right.red)); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FIRGBF left, FIRGBF right) + { + return !(left == right); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIRGBF(Color value) + { + return new FIRGBF(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(FIRGBF value) + { + return value.Color; + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb( + (int)(red * 255f), + (int)(green * 255f), + (int)(blue * 255f)); + } + set + { + red = (float)value.R / 255f; + green = (float)value.G / 255f; + blue = (float)value.B / 255f; + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIRGBF)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FIRGBF)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIRGBF other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIRGBF) && (this == ((FIRGBF)obj))); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FIRGBF other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FICOMPLEX structure describes a color consisting of a real and an imaginary part. + /// Each part is using 4 bytes of data. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FICOMPLEX : IComparable, IComparable, IEquatable + { + /// + /// Real part of the color. + /// + public double real; + + /// + /// Imaginary part of the color. + /// + public double imag; + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FICOMPLEX left, FICOMPLEX right) + { + return ((left.real == right.real) && (left.imag == right.imag)); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FICOMPLEX left, FICOMPLEX right) + { + return ((left.real != right.real) || (left.imag == right.imag)); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FICOMPLEX)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FICOMPLEX)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FICOMPLEX other) + { + return base.GetHashCode(); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FICOMPLEX) && (this == ((FICOMPLEX)obj))); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FICOMPLEX other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + } +} + +namespace FreeImageAPI +{ + /// + /// This Structure contains ICC-Profile data. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FIICCPROFILE + { + private ICC_FLAGS flags; + private uint size; + private IntPtr data; + + /// + /// Creates a new ICC-Profile for . + /// + /// Handle to a FreeImage bitmap. + /// The ICC-Profile data. + /// + /// is null. + public FIICCPROFILE(FIBITMAP dib, byte[] data) + : this(dib, data, (int)data.Length) + { + } + + /// + /// Creates a new ICC-Profile for . + /// + /// Handle to a FreeImage bitmap. + /// The ICC-Profile data. + /// Number of bytes to use from data. + /// + /// is null. + public unsafe FIICCPROFILE(FIBITMAP dib, byte[] data, int size) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + FIICCPROFILE prof; + size = Math.Min(size, (int)data.Length); + prof = *(FIICCPROFILE*)FreeImage.CreateICCProfile(dib, data, size); + this.flags = prof.flags; + this.size = prof.size; + this.data = prof.data; + } + + /// + /// Info flag of the profile. + /// + public ICC_FLAGS Flags + { + get { return flags; } + } + + /// + /// Profile's size measured in bytes. + /// + public uint Size + { + get { return size; } + } + + /// + /// Points to a block of contiguous memory containing the profile. + /// + public IntPtr DataPointer + { + get { return data; } + } + + /// + /// Copy of the ICC-Profiles data. + /// + public unsafe byte[] Data + { + get + { + byte[] result; + FreeImage.CopyMemory(result = new byte[size], data.ToPointer(), size); + return result; + } + } + + /// + /// Indicates whether the profile is CMYK. + /// + public bool IsCMYK + { + get + { + return ((flags & ICC_FLAGS.FIICC_COLOR_IS_CMYK) != 0); + } + } + } +} + +namespace FreeImageAPI.Plugins +{ + /// + /// The structure contains functionpointers that make up a FreeImage plugin. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct Plugin + { + /// + /// Delegate to a function that returns a string which describes + /// the plugins format. + /// + public FormatProc formatProc; + + /// + /// Delegate to a function that returns a string which contains + /// a more detailed description. + /// + public DescriptionProc descriptionProc; + + /// + /// Delegate to a function that returns a comma seperated list + /// of file extensions the plugin can read or write. + /// + public ExtensionListProc extensionListProc; + + /// + /// Delegate to a function that returns a regular expression that + /// can be used to idientify whether a file can be handled by the plugin. + /// + public RegExprProc regExprProc; + + /// + /// Delegate to a function that opens a file. + /// + public OpenProc openProc; + + /// + /// Delegate to a function that closes a previosly opened file. + /// + public CloseProc closeProc; + + /// + /// Delegate to a function that returns the number of pages of a multipage + /// bitmap if the plugin is capable of handling multipage bitmaps. + /// + public PageCountProc pageCountProc; + + /// + /// UNKNOWN + /// + public PageCapabilityProc pageCapabilityProc; + + /// + /// Delegate to a function that loads and decodes a bitmap into memory. + /// + public LoadProc loadProc; + + /// + /// Delegate to a function that saves a bitmap. + /// + public SaveProc saveProc; + + /// + /// Delegate to a function that determines whether the source is a valid image. + /// + public ValidateProc validateProc; + + /// + /// Delegate to a function that returns a string which contains + /// the plugin's mime type. + /// + public MimeProc mimeProc; + + /// + /// Delegate to a function that returns whether the plugin can handle the + /// specified color depth. + /// + public SupportsExportBPPProc supportsExportBPPProc; + + /// + /// Delegate to a function that returns whether the plugin can handle the + /// specified image type. + /// + public SupportsExportTypeProc supportsExportTypeProc; + + /// + /// Delegate to a function that returns whether the plugin can handle + /// ICC-Profiles. + /// + public SupportsICCProfilesProc supportsICCProfilesProc; + } +} + + #endregion + + #region Enums + +namespace FreeImageAPI.Metadata +{ + /// + /// Specifies how a single frame will be handled after being displayed. + /// + public enum DisposalMethodType : byte + { + /// + /// Same behavior as but should not be used. + /// + Unspecified, + + /// + /// The image is left in place and will be overdrawn by the next image. + /// + Leave, + + /// + /// The area of the image will be blanked out by its background. + /// + Background, + + /// + /// Restores the the area of the image to the state it was before it + /// has been dawn. + /// + Previous, + } +} + +namespace FreeImageAPI +{ + /// + /// I/O image format identifiers. + /// + public enum FREE_IMAGE_FORMAT + { + /// + /// Unknown format (returned value only, never use it as input value) + /// + FIF_UNKNOWN = -1, + /// + /// Windows or OS/2 Bitmap File (*.BMP) + /// + FIF_BMP = 0, + /// + /// Windows Icon (*.ICO) + /// + FIF_ICO = 1, + /// + /// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE) + /// + FIF_JPEG = 2, + /// + /// JPEG Network Graphics (*.JNG) + /// + FIF_JNG = 3, + /// + /// Commodore 64 Koala format (*.KOA) + /// + FIF_KOALA = 4, + /// + /// Amiga IFF (*.IFF, *.LBM) + /// + FIF_LBM = 5, + /// + /// Amiga IFF (*.IFF, *.LBM) + /// + FIF_IFF = 5, + /// + /// Multiple Network Graphics (*.MNG) + /// + FIF_MNG = 6, + /// + /// Portable Bitmap (ASCII) (*.PBM) + /// + FIF_PBM = 7, + /// + /// Portable Bitmap (BINARY) (*.PBM) + /// + FIF_PBMRAW = 8, + /// + /// Kodak PhotoCD (*.PCD) + /// + FIF_PCD = 9, + /// + /// Zsoft Paintbrush PCX bitmap format (*.PCX) + /// + FIF_PCX = 10, + /// + /// Portable Graymap (ASCII) (*.PGM) + /// + FIF_PGM = 11, + /// + /// Portable Graymap (BINARY) (*.PGM) + /// + FIF_PGMRAW = 12, + /// + /// Portable Network Graphics (*.PNG) + /// + FIF_PNG = 13, + /// + /// Portable Pixelmap (ASCII) (*.PPM) + /// + FIF_PPM = 14, + /// + /// Portable Pixelmap (BINARY) (*.PPM) + /// + FIF_PPMRAW = 15, + /// + /// Sun Rasterfile (*.RAS) + /// + FIF_RAS = 16, + /// + /// truevision Targa files (*.TGA, *.TARGA) + /// + FIF_TARGA = 17, + /// + /// Tagged Image File Format (*.TIF, *.TIFF) + /// + FIF_TIFF = 18, + /// + /// Wireless Bitmap (*.WBMP) + /// + FIF_WBMP = 19, + /// + /// Adobe Photoshop (*.PSD) + /// + FIF_PSD = 20, + /// + /// Dr. Halo (*.CUT) + /// + FIF_CUT = 21, + /// + /// X11 Bitmap Format (*.XBM) + /// + FIF_XBM = 22, + /// + /// X11 Pixmap Format (*.XPM) + /// + FIF_XPM = 23, + /// + /// DirectDraw Surface (*.DDS) + /// + FIF_DDS = 24, + /// + /// Graphics Interchange Format (*.GIF) + /// + FIF_GIF = 25, + /// + /// High Dynamic Range (*.HDR) + /// + FIF_HDR = 26, + /// + /// Raw Fax format CCITT G3 (*.G3) + /// + FIF_FAXG3 = 27, + /// + /// Silicon Graphics SGI image format (*.SGI) + /// + FIF_SGI = 28, + /// + /// OpenEXR format (*.EXR) + /// + FIF_EXR = 29, + /// + /// JPEG-2000 format (*.J2K, *.J2C) + /// + FIF_J2K = 30, + /// + /// JPEG-2000 format (*.JP2) + /// + FIF_JP2 = 31, + /// + /// Portable FloatMap (*.PFM) + /// + FIF_PFM = 32, + /// + /// Macintosh PICT (*.PICT) + /// + FIF_PICT = 33, + /// + /// RAW camera image (*.*) + /// + FIF_RAW = 34, + } +} + +namespace FreeImageAPI +{ + /// + /// Image types used in FreeImage. + /// + public enum FREE_IMAGE_TYPE + { + /// + /// unknown type + /// + FIT_UNKNOWN = 0, + /// + /// standard image : 1-, 4-, 8-, 16-, 24-, 32-bit + /// + FIT_BITMAP = 1, + /// + /// array of unsigned short : unsigned 16-bit + /// + FIT_UINT16 = 2, + /// + /// array of short : signed 16-bit + /// + FIT_INT16 = 3, + /// + /// array of unsigned long : unsigned 32-bit + /// + FIT_UINT32 = 4, + /// + /// array of long : signed 32-bit + /// + FIT_INT32 = 5, + /// + /// array of float : 32-bit IEEE floating point + /// + FIT_FLOAT = 6, + /// + /// array of double : 64-bit IEEE floating point + /// + FIT_DOUBLE = 7, + /// + /// array of FICOMPLEX : 2 x 64-bit IEEE floating point + /// + FIT_COMPLEX = 8, + /// + /// 48-bit RGB image : 3 x 16-bit + /// + FIT_RGB16 = 9, + /// + /// 64-bit RGBA image : 4 x 16-bit + /// + FIT_RGBA16 = 10, + /// + /// 96-bit RGB float image : 3 x 32-bit IEEE floating point + /// + FIT_RGBF = 11, + /// + /// 128-bit RGBA float image : 4 x 32-bit IEEE floating point + /// + FIT_RGBAF = 12 + } +} + +namespace FreeImageAPI +{ + /// + /// Constants used in color filling routines. + /// + public enum FREE_IMAGE_COLOR_OPTIONS + { + /// + /// Default value. + /// + FICO_DEFAULT = 0x0, + /// + /// color is RGB color (contains no valid alpha channel). + /// + FICO_RGB = 0x0, + /// + /// color is RGBA color (contains a valid alpha channel). + /// + FICO_RGBA = 0x1, + /// + /// Lookup nearest RGB color from palette. + /// + FICO_NEAREST_COLOR = 0x0, + /// + /// Lookup equal RGB color from palette. + /// + FICO_EQUAL_COLOR = 0x2, + /// + /// contains the palette index to be used. + /// + FICO_ALPHA_IS_INDEX = 0x4, + } +} + +namespace FreeImageAPI +{ + /// + /// Image color types used in FreeImage. + /// + public enum FREE_IMAGE_COLOR_TYPE + { + /// + /// min value is white + /// + FIC_MINISWHITE = 0, + /// + /// min value is black + /// + FIC_MINISBLACK = 1, + /// + /// RGB color model + /// + FIC_RGB = 2, + /// + /// color map indexed + /// + FIC_PALETTE = 3, + /// + /// RGB color model with alpha channel + /// + FIC_RGBALPHA = 4, + /// + /// CMYK color model + /// + FIC_CMYK = 5 + } +} + +namespace FreeImageAPI +{ + /// + /// Color quantization algorithms. + /// Constants used in FreeImage_ColorQuantize. + /// + public enum FREE_IMAGE_QUANTIZE + { + /// + /// Xiaolin Wu color quantization algorithm + /// + FIQ_WUQUANT = 0, + /// + /// NeuQuant neural-net quantization algorithm by Anthony Dekker + /// + FIQ_NNQUANT = 1 + } +} + +namespace FreeImageAPI +{ + /// + /// Dithering algorithms. + /// Constants used in FreeImage_Dither. + /// + public enum FREE_IMAGE_DITHER + { + /// + /// Floyd and Steinberg error diffusion + /// + FID_FS = 0, + /// + /// Bayer ordered dispersed dot dithering (order 2 dithering matrix) + /// + FID_BAYER4x4 = 1, + /// + /// Bayer ordered dispersed dot dithering (order 3 dithering matrix) + /// + FID_BAYER8x8 = 2, + /// + /// Ordered clustered dot dithering (order 3 - 6x6 matrix) + /// + FID_CLUSTER6x6 = 3, + /// + /// Ordered clustered dot dithering (order 4 - 8x8 matrix) + /// + FID_CLUSTER8x8 = 4, + /// + /// Ordered clustered dot dithering (order 8 - 16x16 matrix) + /// + FID_CLUSTER16x16 = 5, + /// + /// Bayer ordered dispersed dot dithering (order 4 dithering matrix) + /// + FID_BAYER16x16 = 6 + } +} + +namespace FreeImageAPI +{ + /// + /// Lossless JPEG transformations constants used in FreeImage_JPEGTransform. + /// + public enum FREE_IMAGE_JPEG_OPERATION + { + /// + /// no transformation + /// + FIJPEG_OP_NONE = 0, + /// + /// horizontal flip + /// + FIJPEG_OP_FLIP_H = 1, + /// + /// vertical flip + /// + FIJPEG_OP_FLIP_V = 2, + /// + /// transpose across UL-to-LR axis + /// + FIJPEG_OP_TRANSPOSE = 3, + /// + /// transpose across UR-to-LL axis + /// + FIJPEG_OP_TRANSVERSE = 4, + /// + /// 90-degree clockwise rotation + /// + FIJPEG_OP_ROTATE_90 = 5, + /// + /// 180-degree rotation + /// + FIJPEG_OP_ROTATE_180 = 6, + /// + /// 270-degree clockwise (or 90 ccw) + /// + FIJPEG_OP_ROTATE_270 = 7 + } +} + +namespace FreeImageAPI +{ + /// + /// Tone mapping operators. Constants used in FreeImage_ToneMapping. + /// + public enum FREE_IMAGE_TMO + { + /// + /// Adaptive logarithmic mapping (F. Drago, 2003) + /// + FITMO_DRAGO03 = 0, + /// + /// Dynamic range reduction inspired by photoreceptor physiology (E. Reinhard, 2005) + /// + FITMO_REINHARD05 = 1, + /// + /// Gradient domain high dynamic range compression (R. Fattal, 2002) + /// + FITMO_FATTAL02 + } +} + +namespace FreeImageAPI +{ + /// + /// Upsampling / downsampling filters. Constants used in FreeImage_Rescale. + /// + public enum FREE_IMAGE_FILTER + { + /// + /// Box, pulse, Fourier window, 1st order (constant) b-spline + /// + FILTER_BOX = 0, + /// + /// Mitchell and Netravali's two-param cubic filter + /// + FILTER_BICUBIC = 1, + /// + /// Bilinear filter + /// + FILTER_BILINEAR = 2, + /// + /// 4th order (cubic) b-spline + /// + FILTER_BSPLINE = 3, + /// + /// Catmull-Rom spline, Overhauser spline + /// + FILTER_CATMULLROM = 4, + /// + /// Lanczos3 filter + /// + FILTER_LANCZOS3 = 5 + } +} + +namespace FreeImageAPI +{ + /// + /// Color channels. Constants used in color manipulation routines. + /// + public enum FREE_IMAGE_COLOR_CHANNEL + { + /// + /// Use red, green and blue channels + /// + FICC_RGB = 0, + /// + /// Use red channel + /// + FICC_RED = 1, + /// + /// Use green channel + /// + FICC_GREEN = 2, + /// + /// Use blue channel + /// + FICC_BLUE = 3, + /// + /// Use alpha channel + /// + FICC_ALPHA = 4, + /// + /// Use black channel + /// + FICC_BLACK = 5, + /// + /// Complex images: use real part + /// + FICC_REAL = 6, + /// + /// Complex images: use imaginary part + /// + FICC_IMAG = 7, + /// + /// Complex images: use magnitude + /// + FICC_MAG = 8, + /// + /// Complex images: use phase + /// + FICC_PHASE = 9 + } +} + +namespace FreeImageAPI +{ + /// + /// Tag data type information (based on TIFF specifications) + /// Note: RATIONALs are the ratio of two 32-bit integer values. + /// + public enum FREE_IMAGE_MDTYPE + { + /// + /// placeholder + /// + FIDT_NOTYPE = 0, + /// + /// 8-bit unsigned integer + /// + FIDT_BYTE = 1, + /// + /// 8-bit bytes w/ last byte null + /// + FIDT_ASCII = 2, + /// + /// 16-bit unsigned integer + /// + FIDT_SHORT = 3, + /// + /// 32-bit unsigned integer + /// + FIDT_LONG = 4, + /// + /// 64-bit unsigned fraction + /// + FIDT_RATIONAL = 5, + /// + /// 8-bit signed integer + /// + FIDT_SBYTE = 6, + /// + /// 8-bit untyped data + /// + FIDT_UNDEFINED = 7, + /// + /// 16-bit signed integer + /// + FIDT_SSHORT = 8, + /// + /// 32-bit signed integer + /// + FIDT_SLONG = 9, + /// + /// 64-bit signed fraction + /// + FIDT_SRATIONAL = 10, + /// + /// 32-bit IEEE floating point + /// + FIDT_FLOAT = 11, + /// + /// 64-bit IEEE floating point + /// + FIDT_DOUBLE = 12, + /// + /// 32-bit unsigned integer (offset) + /// + FIDT_IFD = 13, + /// + /// 32-bit RGBQUAD + /// + FIDT_PALETTE = 14 + } +} + +namespace FreeImageAPI +{ + /// + /// Metadata models supported by FreeImage. + /// + public enum FREE_IMAGE_MDMODEL + { + /// + /// No data + /// + FIMD_NODATA = -1, + /// + /// single comment or keywords + /// + FIMD_COMMENTS = 0, + /// + /// Exif-TIFF metadata + /// + FIMD_EXIF_MAIN = 1, + /// + /// Exif-specific metadata + /// + FIMD_EXIF_EXIF = 2, + /// + /// Exif GPS metadata + /// + FIMD_EXIF_GPS = 3, + /// + /// Exif maker note metadata + /// + FIMD_EXIF_MAKERNOTE = 4, + /// + /// Exif interoperability metadata + /// + FIMD_EXIF_INTEROP = 5, + /// + /// IPTC/NAA metadata + /// + FIMD_IPTC = 6, + /// + /// Abobe XMP metadata + /// + FIMD_XMP = 7, + /// + /// GeoTIFF metadata + /// + FIMD_GEOTIFF = 8, + /// + /// Animation metadata + /// + FIMD_ANIMATION = 9, + /// + /// Used to attach other metadata types to a dib + /// + FIMD_CUSTOM = 10 + } +} + +namespace FreeImageAPI +{ + /// + /// Flags used in load functions. + /// + [System.Flags] + public enum FREE_IMAGE_LOAD_FLAGS + { + /// + /// Default option for all types. + /// + DEFAULT = 0, + /// + /// Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color. + /// + GIF_LOAD256 = 1, + /// + /// 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading. + /// + GIF_PLAYBACK = 2, + /// + /// Convert to 32bpp and create an alpha channel from the AND-mask when loading. + /// + ICO_MAKEALPHA = 1, + /// + /// Load the file as fast as possible, sacrificing some quality. + /// + JPEG_FAST = 0x0001, + /// + /// Load the file with the best quality, sacrificing some speed. + /// + JPEG_ACCURATE = 0x0002, + /// + /// Load separated CMYK "as is" (use | to combine with other load flags). + /// + JPEG_CMYK = 0x0004, + /// + /// Load and rotate according to Exif 'Orientation' tag if available. + /// + JPEG_EXIFROTATE = 0x0008, + /// + /// Load the bitmap sized 768 x 512. + /// + PCD_BASE = 1, + /// + /// Load the bitmap sized 384 x 256. + /// + PCD_BASEDIV4 = 2, + /// + /// Load the bitmap sized 192 x 128. + /// + PCD_BASEDIV16 = 3, + /// + /// Avoid gamma correction. + /// + PNG_IGNOREGAMMA = 1, + /// + /// If set the loader converts RGB555 and ARGB8888 -> RGB888. + /// + TARGA_LOAD_RGB888 = 1, + /// + /// Reads tags for separated CMYK. + /// + TIFF_CMYK = 0x0001, + /// + /// Tries to load the JPEG preview image, embedded in + /// Exif Metadata or load the image as RGB 24-bit if no + /// preview image is available. + /// + RAW_PREVIEW = 0x1, + /// + /// Loads the image as RGB 24-bit. + /// + RAW_DISPLAY = 0x2, + } +} + +namespace FreeImageAPI +{ + /// + /// Flags used in save functions. + /// + [System.Flags] + public enum FREE_IMAGE_SAVE_FLAGS + { + /// + /// Default option for all types. + /// + DEFAULT = 0, + /// + /// Save with run length encoding. + /// + BMP_SAVE_RLE = 1, + /// + /// Save data as float instead of as half (not recommended). + /// + EXR_FLOAT = 0x0001, + /// + /// Save with no compression. + /// + EXR_NONE = 0x0002, + /// + /// Save with zlib compression, in blocks of 16 scan lines. + /// + EXR_ZIP = 0x0004, + /// + /// Save with piz-based wavelet compression. + /// + EXR_PIZ = 0x0008, + /// + /// Save with lossy 24-bit float compression. + /// + EXR_PXR24 = 0x0010, + /// + /// Save with lossy 44% float compression - goes to 22% when combined with EXR_LC. + /// + EXR_B44 = 0x0020, + /// + /// Save images with one luminance and two chroma channels, rather than as RGB (lossy compression). + /// + EXR_LC = 0x0040, + /// + /// Save with superb quality (100:1). + /// + JPEG_QUALITYSUPERB = 0x80, + /// + /// Save with good quality (75:1). + /// + JPEG_QUALITYGOOD = 0x0100, + /// + /// Save with normal quality (50:1). + /// + JPEG_QUALITYNORMAL = 0x0200, + /// + /// Save with average quality (25:1). + /// + JPEG_QUALITYAVERAGE = 0x0400, + /// + /// Save with bad quality (10:1). + /// + JPEG_QUALITYBAD = 0x0800, + /// + /// Save as a progressive-JPEG (use | to combine with other save flags). + /// + JPEG_PROGRESSIVE = 0x2000, + /// + /// Save with high 4x1 chroma subsampling (4:1:1). + /// + JPEG_SUBSAMPLING_411 = 0x1000, + /// + /// Save with medium 2x2 medium chroma (4:2:0). + /// + JPEG_SUBSAMPLING_420 = 0x4000, + /// + /// Save with low 2x1 chroma subsampling (4:2:2). + /// + JPEG_SUBSAMPLING_422 = 0x8000, + /// + /// Save with no chroma subsampling (4:4:4). + /// + JPEG_SUBSAMPLING_444 = 0x10000, + /// + /// Save using ZLib level 1 compression flag + /// (default value is ). + /// + PNG_Z_BEST_SPEED = 0x0001, + /// + /// Save using ZLib level 6 compression flag (default recommended value). + /// + PNG_Z_DEFAULT_COMPRESSION = 0x0006, + /// + /// save using ZLib level 9 compression flag + /// (default value is ). + /// + PNG_Z_BEST_COMPRESSION = 0x0009, + /// + /// Save without ZLib compression. + /// + PNG_Z_NO_COMPRESSION = 0x0100, + /// + /// Save using Adam7 interlacing (use | to combine with other save flags). + /// + PNG_INTERLACED = 0x0200, + /// + /// If set the writer saves in ASCII format (i.e. P1, P2 or P3). + /// + PNM_SAVE_ASCII = 1, + /// + /// Stores tags for separated CMYK (use | to combine with compression flags). + /// + TIFF_CMYK = 0x0001, + /// + /// Save using PACKBITS compression. + /// + TIFF_PACKBITS = 0x0100, + /// + /// Save using DEFLATE compression (a.k.a. ZLIB compression). + /// + TIFF_DEFLATE = 0x0200, + /// + /// Save using ADOBE DEFLATE compression. + /// + TIFF_ADOBE_DEFLATE = 0x0400, + /// + /// Save without any compression. + /// + TIFF_NONE = 0x0800, + /// + /// Save using CCITT Group 3 fax encoding. + /// + TIFF_CCITTFAX3 = 0x1000, + /// + /// Save using CCITT Group 4 fax encoding. + /// + TIFF_CCITTFAX4 = 0x2000, + /// + /// Save using LZW compression. + /// + TIFF_LZW = 0x4000, + /// + /// Save using JPEG compression. + /// + TIFF_JPEG = 0x8000 + } +} + +namespace FreeImageAPI +{ + /// + /// Flags for ICC profiles. + /// + [System.Flags] + public enum ICC_FLAGS : ushort + { + /// + /// Default value. + /// + FIICC_DEFAULT = 0x00, + /// + /// The color is CMYK. + /// + FIICC_COLOR_IS_CMYK = 0x01 + } +} + + #endregion + + #region Delegates + +namespace FreeImageAPI +{ + // Delegates used by the FreeImageIO structure + + /// + /// Delegate for capturing FreeImage error messages. + /// + /// The format of the image. + /// The errormessage. + // DLL_API is missing in the definition of the callbackfuntion. + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = false)] + public delegate void OutputMessageFunction(FREE_IMAGE_FORMAT fif, string message); +} + +namespace FreeImageAPI.IO +{ + /// + /// Delegate to the C++ function fread. + /// + /// Pointer to read from. + /// Item size in bytes. + /// Maximum number of items to be read. + /// Handle/stream to read from. + /// Number of full items actually read, + /// which may be less than count if an error occurs or + /// if the end of the file is encountered before reaching count. + public delegate uint ReadProc(IntPtr buffer, uint size, uint count, fi_handle handle); + + /// + /// Delegate to the C++ function fwrite. + /// + /// Pointer to data to be written. + /// Item size in bytes. + /// Maximum number of items to be written. + /// Handle/stream to write to. + /// Number of full items actually written, + /// which may be less than count if an error occurs. + /// Also, if an error occurs, the file-position indicator cannot be determined. + public delegate uint WriteProc(IntPtr buffer, uint size, uint count, fi_handle handle); + + /// + /// Delegate to the C++ function fseek. + /// + /// Handle/stream to seek in. + /// Number of bytes from origin. + /// Initial position. + /// If successful 0 is returned; otherwise a nonzero value. + public delegate int SeekProc(fi_handle handle, int offset, SeekOrigin origin); + + /// + /// Delegate to the C++ function ftell. + /// + /// Handle/stream to retrieve its currents position from. + /// The current position. + public delegate int TellProc(fi_handle handle); + + // Delegates used by 'Plugin' structure +} + +namespace FreeImageAPI.Plugins +{ + /// + /// Delegate to a function that returns a string which describes + /// the plugins format. + /// + public delegate string FormatProc(); + + /// + /// Delegate to a function that returns a string which contains + /// a more detailed description. + /// + public delegate string DescriptionProc(); + + /// + /// Delegate to a function that returns a comma seperated list + /// of file extensions the plugin can read or write. + /// + public delegate string ExtensionListProc(); + + /// + /// Delegate to a function that returns a regular expression that + /// can be used to idientify whether a file can be handled by the plugin. + /// + public delegate string RegExprProc(); + + /// + /// Delegate to a function that opens a file. + /// + public delegate IntPtr OpenProc(ref FreeImageIO io, fi_handle handle, bool read); + + /// + /// Delegate to a function that closes a previosly opened file. + /// + public delegate void CloseProc(ref FreeImageIO io, fi_handle handle, IntPtr data); + + /// + /// Delegate to a function that returns the number of pages of a multipage + /// bitmap if the plugin is capable of handling multipage bitmaps. + /// + public delegate int PageCountProc(ref FreeImageIO io, fi_handle handle, IntPtr data); + + /// + /// UNKNOWN + /// + public delegate int PageCapabilityProc(ref FreeImageIO io, fi_handle handle, IntPtr data); + + /// + /// Delegate to a function that loads and decodes a bitmap into memory. + /// + public delegate FIBITMAP LoadProc(ref FreeImageIO io, fi_handle handle, int page, int flags, IntPtr data); + + /// + /// Delegate to a function that saves a bitmap. + /// + public delegate bool SaveProc(ref FreeImageIO io, FIBITMAP dib, fi_handle handle, int page, int flags, IntPtr data); + + /// + /// Delegate to a function that determines whether the source defined + /// by and is a valid image. + /// + public delegate bool ValidateProc(ref FreeImageIO io, fi_handle handle); + + /// + /// Delegate to a function that returns a string which contains + /// the plugin's mime type. + /// + public delegate string MimeProc(); + + /// + /// Delegate to a function that returns whether the plugin can handle the + /// specified color depth. + /// + public delegate bool SupportsExportBPPProc(int bpp); + + /// + /// Delegate to a function that returns whether the plugin can handle the + /// specified image type. + /// + public delegate bool SupportsExportTypeProc(FREE_IMAGE_TYPE type); + + /// + /// Delegate to a function that returns whether the plugin can handle + /// ICC-Profiles. + /// + public delegate bool SupportsICCProfilesProc(); + + /// + /// Callback function used by FreeImage to register plugins. + /// + public delegate void InitProc(ref Plugin plugin, int format_id); +} + + #endregion + +namespace FreeImageAPI +{ + public static partial class FreeImage + { + #region Constants + + /// + /// Filename of the FreeImage library. + /// + private const string FreeImageLibrary = "FreeImage"; + + /// + /// Number of bytes to shift left within a 4 byte block. + /// + public const int FI_RGBA_RED = 2; + + /// + /// Number of bytes to shift left within a 4 byte block. + /// + public const int FI_RGBA_GREEN = 1; + + /// + /// Number of bytes to shift left within a 4 byte block. + /// + public const int FI_RGBA_BLUE = 0; + + /// + /// Number of bytes to shift left within a 4 byte block. + /// + public const int FI_RGBA_ALPHA = 3; + + /// + /// Mask indicating the position of the given color. + /// + public const uint FI_RGBA_RED_MASK = 0x00FF0000; + + /// + /// Mask indicating the position of the given color. + /// + public const uint FI_RGBA_GREEN_MASK = 0x0000FF00; + + /// + /// Mask indicating the position of the given color. + /// + public const uint FI_RGBA_BLUE_MASK = 0x000000FF; + + /// + /// Mask indicating the position of the given color. + /// + public const uint FI_RGBA_ALPHA_MASK = 0xFF000000; + + /// + /// Number of bits to shift left within a 32 bit block. + /// + public const int FI_RGBA_RED_SHIFT = 16; + + /// + /// Number of bits to shift left within a 32 bit block. + /// + public const int FI_RGBA_GREEN_SHIFT = 8; + + /// + /// Number of bits to shift left within a 32 bit block. + /// + public const int FI_RGBA_BLUE_SHIFT = 0; + + /// + /// Number of bits to shift left within a 32 bit block. + /// + public const int FI_RGBA_ALPHA_SHIFT = 24; + + /// + /// Mask indicating the position of color components of a 32 bit color. + /// + public const uint FI_RGBA_RGB_MASK = (FI_RGBA_RED_MASK | FI_RGBA_GREEN_MASK | FI_RGBA_BLUE_MASK); + + /// + /// Mask indicating the position of the given color. + /// + public const int FI16_555_RED_MASK = 0x7C00; + + /// + /// Mask indicating the position of the given color. + /// + public const int FI16_555_GREEN_MASK = 0x03E0; + + /// + /// Mask indicating the position of the given color. + /// + public const int FI16_555_BLUE_MASK = 0x001F; + + /// + /// Number of bits to shift left within a 16 bit block. + /// + public const int FI16_555_RED_SHIFT = 10; + + /// + /// Number of bits to shift left within a 16 bit block. + /// + public const int FI16_555_GREEN_SHIFT = 5; + + /// + /// Number of bits to shift left within a 16 bit block. + /// + public const int FI16_555_BLUE_SHIFT = 0; + + /// + /// Mask indicating the position of the given color. + /// + public const int FI16_565_RED_MASK = 0xF800; + + /// + /// Mask indicating the position of the given color. + /// + public const int FI16_565_GREEN_MASK = 0x07E0; + + /// + /// Mask indicating the position of the given color. + /// + public const int FI16_565_BLUE_MASK = 0x001F; + + /// + /// Number of bits to shift left within a 16 bit block. + /// + public const int FI16_565_RED_SHIFT = 11; + + /// + /// Number of bits to shift left within a 16 bit block. + /// + public const int FI16_565_GREEN_SHIFT = 5; + + /// + /// Number of bits to shift left within a 16 bit block. + /// + public const int FI16_565_BLUE_SHIFT = 0; + + #endregion + + #region General functions + + /// + /// Initialises the library. + /// + /// + /// When the is true, FreeImage won't make use of external plugins. + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Initialise")] + private static extern void Initialise(bool load_local_plugins_only); + + /// + /// Deinitialises the library. + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeInitialise")] + private static extern void DeInitialise(); + + /// + /// Returns a string containing the current version of the library. + /// + /// The current version of the library. + public static unsafe string GetVersion() { return PtrToStr(GetVersion_()); } + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetVersion")] + private static unsafe extern byte* GetVersion_(); + + /// + /// Returns a string containing a standard copyright message. + /// + /// A standard copyright message. + public static unsafe string GetCopyrightMessage() { return PtrToStr(GetCopyrightMessage_()); } + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetCopyrightMessage")] + private static unsafe extern byte* GetCopyrightMessage_(); + + /// + /// Calls the set error message function in FreeImage. + /// + /// Format of the bitmaps. + /// The error message. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_OutputMessageProc")] + public static extern void OutputMessageProc(FREE_IMAGE_FORMAT fif, string message); + + /// + /// You use the function FreeImage_SetOutputMessage to capture the log string + /// so that you can show it to the user of the program. + /// The callback is implemented in the event of this class. + /// + /// The function is private because FreeImage can only have a single + /// callback function. To use the callback use the + /// event of this class. + /// Handler to the callback function. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetOutputMessage")] + internal static extern void SetOutputMessage(OutputMessageFunction omf); + + #endregion + + #region Bitmap management functions + + /// + /// Creates a new bitmap in memory. + /// + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new Bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap + /// Red part of the color layout. + /// eg: 0xFF0000 + /// Green part of the color layout. + /// eg: 0x00FF00 + /// Blue part of the color layout. + /// eg: 0x0000FF + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Allocate")] + public static extern FIBITMAP Allocate(int width, int height, int bpp, + uint red_mask, uint green_mask, uint blue_mask); + + /// + /// Creates a new bitmap in memory. + /// + /// Type of the image. + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new Bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap + /// Red part of the color layout. + /// eg: 0xFF0000 + /// Green part of the color layout. + /// eg: 0x00FF00 + /// Blue part of the color layout. + /// eg: 0x0000FF + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateT")] + public static extern FIBITMAP AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp, + uint red_mask, uint green_mask, uint blue_mask); + + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateEx")] + internal static extern FIBITMAP AllocateEx(int width, int height, int bpp, + IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, + uint red_mask, uint green_mask, uint blue_mask); + + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateExT")] + internal static extern FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp, + IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, + uint red_mask, uint green_mask, uint blue_mask); + + /// + /// Makes an exact reproduction of an existing bitmap, including metadata and attached profile if any. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Clone")] + public static extern FIBITMAP Clone(FIBITMAP dib); + + /// + /// Deletes a previously loaded FIBITMAP from memory. + /// + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Unload")] + public static extern void Unload(FIBITMAP dib); + + /// + /// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP. + /// + /// Type of the bitmap. + /// Name of the file to decode. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")] + public static extern FIBITMAP Load(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags); + + /// + /// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP. + /// The filename supports UNICODE. + /// + /// Type of the bitmap. + /// Name of the file to decode. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")] + private static extern FIBITMAP LoadU(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags); + + /// + /// Loads a bitmap from an arbitrary source. + /// + /// Type of the bitmap. + /// A FreeImageIO structure with functionpointers to handle the source. + /// A handle to the source. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadFromHandle")] + public static extern FIBITMAP LoadFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io, fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags); + + /// + /// Saves a previosly loaded FIBITMAP to a file. + /// + /// Type of the bitmap. + /// Handle to a FreeImage bitmap. + /// Name of the file to save to. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_SaveU")] + public static extern bool Save(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags); + + /// + /// Saves a previosly loaded FIBITMAP to a file. + /// The filename supports UNICODE. + /// + /// Type of the bitmap. + /// Handle to a FreeImage bitmap. + /// Name of the file to save to. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_SaveU")] + private static extern bool SaveU(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags); + + /// + /// Saves a bitmap to an arbitrary source. + /// + /// Type of the bitmap. + /// Handle to a FreeImage bitmap. + /// A FreeImageIO structure with functionpointers to handle the source. + /// A handle to the source. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SaveToHandle")] + public static extern bool SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP dib, ref FreeImageIO io, fi_handle handle, + FREE_IMAGE_SAVE_FLAGS flags); + + #endregion + + #region Memory I/O streams + + /// + /// Open a memory stream. + /// + /// Pointer to the data in memory. + /// Length of the data in byte. + /// Handle to a memory stream. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMemory")] + public static extern FIMEMORY OpenMemory(IntPtr data, uint size_in_bytes); + + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMemory")] + internal static extern FIMEMORY OpenMemoryEx(byte[] data, uint size_in_bytes); + + /// + /// Close and free a memory stream. + /// + /// Handle to a memory stream. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloseMemory")] + public static extern void CloseMemory(FIMEMORY stream); + + /// + /// Decodes a bitmap from a stream, allocates memory for it and returns it as a FIBITMAP. + /// + /// Type of the bitmap. + /// Handle to a memory stream. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadFromMemory")] + public static extern FIBITMAP LoadFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags); + + /// + /// Saves a previosly loaded FIBITMAP to a stream. + /// + /// Type of the bitmap. + /// Handle to a FreeImage bitmap. + /// Handle to a memory stream. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SaveToMemory")] + public static extern bool SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP dib, FIMEMORY stream, FREE_IMAGE_SAVE_FLAGS flags); + + /// + /// Gets the current position of a memory handle. + /// + /// Handle to a memory stream. + /// The current file position if successful, -1 otherwise. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TellMemory")] + public static extern int TellMemory(FIMEMORY stream); + + /// + /// Moves the memory handle to a specified location. + /// + /// Handle to a memory stream. + /// Number of bytes from origin. + /// Initial position. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SeekMemory")] + public static extern bool SeekMemory(FIMEMORY stream, int offset, System.IO.SeekOrigin origin); + + /// + /// Provides a direct buffer access to a memory stream. + /// + /// The target memory stream. + /// Pointer to the data in memory. + /// Size of the data in bytes. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AcquireMemory")] + public static extern bool AcquireMemory(FIMEMORY stream, ref IntPtr data, ref uint size_in_bytes); + + /// + /// Reads data from a memory stream. + /// + /// The buffer to store the data in. + /// Size in bytes of the items. + /// Number of items to read. + /// The stream to read from. + /// The memory pointer associated with stream is increased by the number of bytes actually read. + /// The number of full items actually read. + /// May be less than count on error or stream-end. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ReadMemory")] + public static extern uint ReadMemory(byte[] buffer, uint size, uint count, FIMEMORY stream); + + /// + /// Writes data to a memory stream. + /// + /// The buffer to read the data from. + /// Size in bytes of the items. + /// Number of items to write. + /// The stream to write to. + /// The memory pointer associated with stream is increased by the number of bytes actually written. + /// The number of full items actually written. + /// May be less than count on error or stream-end. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_WriteMemory")] + public static extern uint WriteMemory(byte[] buffer, uint size, uint count, FIMEMORY stream); + + /// + /// Open a multi-page bitmap from a memory stream. + /// + /// Type of the bitmap. + /// The stream to decode. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage multi-paged bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadMultiBitmapFromMemory")] + public static extern FIMULTIBITMAP LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags); + + #endregion + + #region Plugin functions + + /// + /// Registers a new plugin to be used in FreeImage. + /// + /// Pointer to the function that initialises the plugin. + /// A string describing the format of the plugin. + /// A string describing the plugin. + /// A string witha comma sperated list of extensions. f.e: "pl,pl2,pl4" + /// A regular expression used to identify the bitmap. + /// The format idientifier assigned by FreeImage. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_RegisterLocalPlugin")] + public static extern FREE_IMAGE_FORMAT RegisterLocalPlugin(InitProc proc_address, + string format, string description, string extension, string regexpr); + + /// + /// Registers a new plugin to be used in FreeImage. The plugin is residing in a DLL. + /// The Init function must be called �Init� and must use the stdcall calling convention. + /// + /// Complete path to the dll file hosting the plugin. + /// A string describing the format of the plugin. + /// A string describing the plugin. + /// A string witha comma sperated list of extensions. f.e: "pl,pl2,pl4" + /// A regular expression used to identify the bitmap. + /// The format idientifier assigned by FreeImage. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_RegisterExternalPlugin")] + public static extern FREE_IMAGE_FORMAT RegisterExternalPlugin(string path, + string format, string description, string extension, string regexpr); + + /// + /// Retrieves the number of FREE_IMAGE_FORMAT identifiers being currently registered. + /// + /// The number of registered formats. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFCount")] + public static extern int GetFIFCount(); + + /// + /// Enables or disables a plugin. + /// + /// The plugin to enable or disable. + /// True: enable the plugin. false: disable the plugin. + /// The previous state of the plugin. + /// 1 - enabled. 0 - disables. -1 plugin does not exist. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPluginEnabled")] + public static extern int SetPluginEnabled(FREE_IMAGE_FORMAT fif, bool enable); + + /// + /// Retrieves the state of a plugin. + /// + /// The plugin to check. + /// 1 - enabled. 0 - disables. -1 plugin does not exist. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsPluginEnabled")] + public static extern int IsPluginEnabled(FREE_IMAGE_FORMAT fif); + + /// + /// Returns a identifier from the format string that was used to register the FIF. + /// + /// The string that was used to register the plugin. + /// A identifier from the format. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetFIFFromFormat")] + public static extern FREE_IMAGE_FORMAT GetFIFFromFormat(string format); + + /// + /// Returns a identifier from a MIME content type string + /// (MIME stands for Multipurpose Internet Mail Extension). + /// + /// A MIME content type. + /// A identifier from the MIME. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetFIFFromMime")] + public static extern FREE_IMAGE_FORMAT GetFIFFromMime(string mime); + + /// + /// Returns the string that was used to register a plugin from the system assigned . + /// + /// The assigned . + /// The string that was used to register the plugin. + public static unsafe string GetFormatFromFIF(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFormatFromFIF_(fif)); } + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFormatFromFIF")] + private static unsafe extern byte* GetFormatFromFIF_(FREE_IMAGE_FORMAT fif); + + /// + /// Returns a comma-delimited file extension list describing the bitmap formats the given plugin can read and/or write. + /// + /// The desired . + /// A comma-delimited file extension list. + public static unsafe string GetFIFExtensionList(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFExtensionList_(fif)); } + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFExtensionList")] + private static unsafe extern byte* GetFIFExtensionList_(FREE_IMAGE_FORMAT fif); + + /// + /// Returns a descriptive string that describes the bitmap formats the given plugin can read and/or write. + /// + /// The desired . + /// A descriptive string that describes the bitmap formats. + public static unsafe string GetFIFDescription(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFDescription_(fif)); } + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFDescription")] + private static unsafe extern byte* GetFIFDescription_(FREE_IMAGE_FORMAT fif); + + /// + /// Returns a regular expression string that can be used by a regular expression engine to identify the bitmap. + /// FreeImageQt makes use of this function. + /// + /// The desired . + /// A regular expression string. + public static unsafe string GetFIFRegExpr(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFRegExpr_(fif)); } + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFRegExpr")] + private static unsafe extern byte* GetFIFRegExpr_(FREE_IMAGE_FORMAT fif); + + /// + /// Given a identifier, returns a MIME content type string (MIME stands for Multipurpose Internet Mail Extension). + /// + /// The desired . + /// A MIME content type string. + public static unsafe string GetFIFMimeType(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFMimeType_(fif)); } + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFMimeType")] + private static unsafe extern byte* GetFIFMimeType_(FREE_IMAGE_FORMAT fif); + + /// + /// This function takes a filename or a file-extension and returns the plugin that can + /// read/write files with that extension in the form of a identifier. + /// + /// The filename or -extension. + /// The of the plugin. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")] + public static extern FREE_IMAGE_FORMAT GetFIFFromFilename(string filename); + + /// + /// This function takes a filename or a file-extension and returns the plugin that can + /// read/write files with that extension in the form of a identifier. + /// Supports UNICODE filenames. + /// + /// The filename or -extension. + /// The of the plugin. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")] + private static extern FREE_IMAGE_FORMAT GetFIFFromFilenameU(string filename); + + /// + /// Checks if a plugin can load bitmaps. + /// + /// The of the plugin. + /// True if the plugin can load bitmaps, else false. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsReading")] + public static extern bool FIFSupportsReading(FREE_IMAGE_FORMAT fif); + + /// + /// Checks if a plugin can save bitmaps. + /// + /// The of the plugin. + /// True if the plugin can save bitmaps, else false. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsWriting")] + public static extern bool FIFSupportsWriting(FREE_IMAGE_FORMAT fif); + + /// + /// Checks if a plugin can save bitmaps in the desired bit depth. + /// + /// The of the plugin. + /// The desired bit depth. + /// True if the plugin can save bitmaps in the desired bit depth, else false. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsExportBPP")] + public static extern bool FIFSupportsExportBPP(FREE_IMAGE_FORMAT fif, int bpp); + + /// + /// Checks if a plugin can save a bitmap in the desired data type. + /// + /// The of the plugin. + /// The desired image type. + /// True if the plugin can save bitmaps as the desired type, else false. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsExportType")] + public static extern bool FIFSupportsExportType(FREE_IMAGE_FORMAT fif, FREE_IMAGE_TYPE type); + + /// + /// Checks if a plugin can load or save an ICC profile. + /// + /// The of the plugin. + /// True if the plugin can load or save an ICC profile, else false. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsICCProfiles")] + public static extern bool FIFSupportsICCProfiles(FREE_IMAGE_FORMAT fif); + + #endregion + + #region Multipage functions + + /// + /// Loads a FreeImage multi-paged bitmap. + /// Load flags can be provided by the flags parameter. + /// + /// Format of the image. + /// The complete name of the file to load. + /// When true a new bitmap is created. + /// When true the bitmap will be loaded read only. + /// When true performance is increased at the cost of memory. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage multi-paged bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMultiBitmap")] + public static extern FIMULTIBITMAP OpenMultiBitmap(FREE_IMAGE_FORMAT fif, string filename, bool create_new, + bool read_only, bool keep_cache_in_memory, FREE_IMAGE_LOAD_FLAGS flags); + + /// + /// Loads a FreeImage multi-pages bitmap from the specified handle + /// using the specified functions. + /// Load flags can be provided by the flags parameter. + /// + /// Format of the image. + /// IO functions used to read from the specified handle. + /// The handle to load the bitmap from. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage multi-paged bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMultiBitmapFromHandle")] + public static extern FIMULTIBITMAP OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io, + fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags); + + /// + /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, applies any changes made to it. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloseMultiBitmap")] + private static extern bool CloseMultiBitmap_(FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags); + + /// + /// Returns the number of pages currently available in the multi-paged bitmap. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Number of pages. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPageCount")] + public static extern int GetPageCount(FIMULTIBITMAP bitmap); + + /// + /// Appends a new page to the end of the bitmap. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AppendPage")] + public static extern void AppendPage(FIMULTIBITMAP bitmap, FIBITMAP data); + + /// + /// Inserts a new page before the given position in the bitmap. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Page has to be a number smaller than the current number of pages available in the bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_InsertPage")] + public static extern void InsertPage(FIMULTIBITMAP bitmap, int page, FIBITMAP data); + + /// + /// Deletes the page on the given position. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Number of the page to delete. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeletePage")] + public static extern void DeletePage(FIMULTIBITMAP bitmap, int page); + + /// + /// Locks a page in memory for editing. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Number of the page to lock. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LockPage")] + public static extern FIBITMAP LockPage(FIMULTIBITMAP bitmap, int page); + + /// + /// Unlocks a previously locked page and gives it back to the multi-page engine. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Handle to a FreeImage bitmap. + /// If true, the page is applied to the multi-page bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_UnlockPage")] + public static extern void UnlockPage(FIMULTIBITMAP bitmap, FIBITMAP data, bool changed); + + /// + /// Moves the source page to the position of the target page. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// New position of the page. + /// Old position of the page. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MovePage")] + public static extern bool MovePage(FIMULTIBITMAP bitmap, int target, int source); + + /// + /// Returns an array of page-numbers that are currently locked in memory. + /// When the pages parameter is null, the size of the array is returned in the count variable. + /// + /// + /// + /// int[] lockedPages = null; + /// int count = 0; + /// GetLockedPageNumbers(dib, lockedPages, ref count); + /// lockedPages = new int[count]; + /// GetLockedPageNumbers(dib, lockedPages, ref count); + /// + /// + /// Handle to a FreeImage multi-paged bitmap. + /// The list of locked pages in the multi-pages bitmap. + /// If set to null, count will contain the number of pages. + /// If is set to null count will contain the number of locked pages. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetLockedPageNumbers")] + public static extern bool GetLockedPageNumbers(FIMULTIBITMAP bitmap, int[] pages, ref int count); + + #endregion + + #region Filetype functions + + /// + /// Orders FreeImage to analyze the bitmap signature. + /// + /// Name of the file to analyze. + /// Reserved parameter - use 0. + /// Type of the bitmap. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")] + public static extern FREE_IMAGE_FORMAT GetFileType(string filename, int size); + + + /// + /// Orders FreeImage to analyze the bitmap signature. + /// Supports UNICODE filenames. + /// + /// Name of the file to analyze. + /// Reserved parameter - use 0. + /// Type of the bitmap. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")] + private static extern FREE_IMAGE_FORMAT GetFileTypeU(string filename, int size); + + /// + /// Uses the structure as described in the topic bitmap management functions + /// to identify a bitmap type. + /// + /// A structure with functionpointers to handle the source. + /// A handle to the source. + /// Size in bytes of the source. + /// Type of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromHandle")] + public static extern FREE_IMAGE_FORMAT GetFileTypeFromHandle(ref FreeImageIO io, fi_handle handle, int size); + + /// + /// Uses a memory handle to identify a bitmap type. + /// + /// Pointer to the stream. + /// Size in bytes of the source. + /// Type of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromMemory")] + public static extern FREE_IMAGE_FORMAT GetFileTypeFromMemory(FIMEMORY stream, int size); + + #endregion + + #region Helper functions + + /// + /// Returns whether the platform is using Little Endian. + /// + /// Returns true if the platform is using Litte Endian, else false. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsLittleEndian")] + public static extern bool IsLittleEndian(); + + /// + /// Converts a X11 color name into a corresponding RGB value. + /// + /// Name of the color to convert. + /// Red component. + /// Green component. + /// Blue component. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_LookupX11Color")] + public static extern bool LookupX11Color(string szColor, out byte nRed, out byte nGreen, out byte nBlue); + + /// + /// Converts a SVG color name into a corresponding RGB value. + /// + /// Name of the color to convert. + /// Red component. + /// Green component. + /// Blue component. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_LookupSVGColor")] + public static extern bool LookupSVGColor(string szColor, out byte nRed, out byte nGreen, out byte nBlue); + + #endregion + + #region Pixel access functions + + /// + /// Returns a pointer to the data-bits of the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Pointer to the data-bits. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBits")] + public static extern IntPtr GetBits(FIBITMAP dib); + + /// + /// Returns a pointer to the start of the given scanline in the bitmap's data-bits. + /// + /// Handle to a FreeImage bitmap. + /// Number of the scanline. + /// Pointer to the scanline. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetScanLine")] + public static extern IntPtr GetScanLine(FIBITMAP dib, int scanline); + + /// + /// Get the pixel index of a palettized image at position (x, y), including range check (slow access). + /// + /// Handle to a FreeImage bitmap. + /// Pixel position in horizontal direction. + /// Pixel position in vertical direction. + /// The pixel index. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPixelIndex")] + public static extern bool GetPixelIndex(FIBITMAP dib, uint x, uint y, out byte value); + + /// + /// Get the pixel color of a 16-, 24- or 32-bit image at position (x, y), including range check (slow access). + /// + /// Handle to a FreeImage bitmap. + /// Pixel position in horizontal direction. + /// Pixel position in vertical direction. + /// The pixel color. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPixelColor")] + public static extern bool GetPixelColor(FIBITMAP dib, uint x, uint y, out RGBQUAD value); + + /// + /// Set the pixel index of a palettized image at position (x, y), including range check (slow access). + /// + /// Handle to a FreeImage bitmap. + /// Pixel position in horizontal direction. + /// Pixel position in vertical direction. + /// The new pixel index. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPixelIndex")] + public static extern bool SetPixelIndex(FIBITMAP dib, uint x, uint y, ref byte value); + + /// + /// Set the pixel color of a 16-, 24- or 32-bit image at position (x, y), including range check (slow access). + /// + /// Handle to a FreeImage bitmap. + /// Pixel position in horizontal direction. + /// Pixel position in vertical direction. + /// The new pixel color. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPixelColor")] + public static extern bool SetPixelColor(FIBITMAP dib, uint x, uint y, ref RGBQUAD value); + + #endregion + + #region Bitmap information functions + + /// + /// Retrieves the type of the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Type of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetImageType")] + public static extern FREE_IMAGE_TYPE GetImageType(FIBITMAP dib); + + /// + /// Returns the number of colors used in a bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Palette-size for palletised bitmaps, and 0 for high-colour bitmaps. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetColorsUsed")] + public static extern uint GetColorsUsed(FIBITMAP dib); + + /// + /// Returns the size of one pixel in the bitmap in bits. + /// + /// Handle to a FreeImage bitmap. + /// Size of one pixel in the bitmap in bits. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBPP")] + public static extern uint GetBPP(FIBITMAP dib); + + /// + /// Returns the width of the bitmap in pixel units. + /// + /// Handle to a FreeImage bitmap. + /// With of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetWidth")] + public static extern uint GetWidth(FIBITMAP dib); + + /// + /// Returns the height of the bitmap in pixel units. + /// + /// Handle to a FreeImage bitmap. + /// Height of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetHeight")] + public static extern uint GetHeight(FIBITMAP dib); + + /// + /// Returns the width of the bitmap in bytes. + /// + /// Handle to a FreeImage bitmap. + /// With of the bitmap in bytes. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetLine")] + public static extern uint GetLine(FIBITMAP dib); + + /// + /// Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary, + /// also known as pitch or stride or scan width. + /// + /// Handle to a FreeImage bitmap. + /// With of the bitmap in bytes. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPitch")] + public static extern uint GetPitch(FIBITMAP dib); + + /// + /// Returns the size of the DIB-element of a FIBITMAP in memory. + /// + /// Handle to a FreeImage bitmap. + /// Size of the DIB-element + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDIBSize")] + public static extern uint GetDIBSize(FIBITMAP dib); + + /// + /// Returns a pointer to the bitmap's palette. + /// + /// Handle to a FreeImage bitmap. + /// Pointer to the bitmap's palette. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPalette")] + public static extern IntPtr GetPalette(FIBITMAP dib); + + /// + /// Returns the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The horizontal resolution, in pixels-per-meter. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDotsPerMeterX")] + public static extern uint GetDotsPerMeterX(FIBITMAP dib); + + /// + /// Returns the vertical resolution, in pixels-per-meter, of the target device for the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The vertical resolution, in pixels-per-meter. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDotsPerMeterY")] + public static extern uint GetDotsPerMeterY(FIBITMAP dib); + + /// + /// Set the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The new horizontal resolution. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetDotsPerMeterX")] + public static extern void SetDotsPerMeterX(FIBITMAP dib, uint res); + + /// + /// Set the vertical resolution, in pixels-per-meter, of the target device for the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The new vertical resolution. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetDotsPerMeterY")] + public static extern void SetDotsPerMeterY(FIBITMAP dib, uint res); + + /// + /// Returns a pointer to the of the DIB-element in a FIBITMAP. + /// + /// Handle to a FreeImage bitmap. + /// Poiter to the header of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetInfoHeader")] + public static extern IntPtr GetInfoHeader(FIBITMAP dib); + + /// + /// Alias for FreeImage_GetInfoHeader that returns a pointer to a + /// rather than to a . + /// + /// Handle to a FreeImage bitmap. + /// Pointer to the structure for the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetInfo")] + public static extern IntPtr GetInfo(FIBITMAP dib); + + /// + /// Investigates the color type of the bitmap by reading the bitmap's pixel bits and analysing them. + /// + /// Handle to a FreeImage bitmap. + /// The color type of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetColorType")] + public static extern FREE_IMAGE_COLOR_TYPE GetColorType(FIBITMAP dib); + + /// + /// Returns a bit pattern describing the red color component of a pixel in a FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The bit pattern for RED. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetRedMask")] + public static extern uint GetRedMask(FIBITMAP dib); + + /// + /// Returns a bit pattern describing the green color component of a pixel in a FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The bit pattern for green. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetGreenMask")] + public static extern uint GetGreenMask(FIBITMAP dib); + + /// + /// Returns a bit pattern describing the blue color component of a pixel in a FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The bit pattern for blue. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBlueMask")] + public static extern uint GetBlueMask(FIBITMAP dib); + + /// + /// Returns the number of transparent colors in a palletised bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The number of transparent colors in a palletised bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparencyCount")] + public static extern uint GetTransparencyCount(FIBITMAP dib); + + /// + /// Returns a pointer to the bitmap's transparency table. + /// + /// Handle to a FreeImage bitmap. + /// Pointer to the bitmap's transparency table. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparencyTable")] + public static extern IntPtr GetTransparencyTable(FIBITMAP dib); + + /// + /// Tells FreeImage if it should make use of the transparency table + /// or the alpha channel that may accompany a bitmap. + /// + /// Handle to a FreeImage bitmap. + /// True to enable the transparency, false to disable. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparent")] + public static extern void SetTransparent(FIBITMAP dib, bool enabled); + + /// + /// Set the bitmap's transparency table. Only affects palletised bitmaps. + /// + /// Handle to a FreeImage bitmap. + /// Pointer to the bitmap's new transparency table. + /// The number of transparent colors in the new transparency table. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparencyTable")] + internal static extern void SetTransparencyTable(FIBITMAP dib, byte[] table, int count); + + /// + /// Returns whether the transparency table is enabled. + /// + /// Handle to a FreeImage bitmap. + /// Returns true when the transparency table is enabled (1-, 4- or 8-bit images) + /// or when the input dib contains alpha values (32-bit images). Returns false otherwise. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsTransparent")] + public static extern bool IsTransparent(FIBITMAP dib); + + /// + /// Returns whether the bitmap has a file background color. + /// + /// Handle to a FreeImage bitmap. + /// Returns true when the image has a file background color, false otherwise. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_HasBackgroundColor")] + public static extern bool HasBackgroundColor(FIBITMAP dib); + + /// + /// Returns the file background color of an image. + /// For 8-bit images, the color index in the palette is returned in the + /// rgbReserved member of the bkcolor parameter. + /// + /// Handle to a FreeImage bitmap. + /// The background color. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBackgroundColor")] + public static extern bool GetBackgroundColor(FIBITMAP dib, out RGBQUAD bkcolor); + + /// + /// Set the file background color of an image. + /// When saving an image to PNG, this background color is transparently saved to the PNG file. + /// + /// Handle to a FreeImage bitmap. + /// The new background color. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetBackgroundColor")] + public static unsafe extern bool SetBackgroundColor(FIBITMAP dib, ref RGBQUAD bkcolor); + + /// + /// Set the file background color of an image. + /// When saving an image to PNG, this background color is transparently saved to the PNG file. + /// When the bkcolor parameter is null, the background color is removed from the image. + /// + /// This overloaded version of the function with an array parameter is provided to allow + /// passing null in the parameter. This is similar to the + /// original C/C++ function. Passing null as parameter will + /// unset the dib's previously set background color. + /// + /// + /// Handle to a FreeImage bitmap. + /// The new background color. + /// The first entry in the array is used. + /// Returns true on success, false on failure. + /// + /// + /// // create a RGBQUAD color + /// RGBQUAD color = new RGBQUAD(Color.Green); + /// + /// // set the dib's background color (using the other version of the function) + /// FreeImage.SetBackgroundColor(dib, ref color); + /// + /// // remove it again (this only works due to the array parameter RGBQUAD[]) + /// FreeImage.SetBackgroundColor(dib, null); + /// + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetBackgroundColor")] + public static unsafe extern bool SetBackgroundColor(FIBITMAP dib, RGBQUAD[] bkcolor); + + /// + /// Sets the index of the palette entry to be used as transparent color + /// for the image specified. Does nothing on high color images. + /// + /// Handle to a FreeImage bitmap. + /// The index of the palette entry to be set as transparent color. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparentIndex")] + public static extern void SetTransparentIndex(FIBITMAP dib, int index); + + /// + /// Returns the palette entry used as transparent color for the image specified. + /// Works for palletised images only and returns -1 for high color + /// images or if the image has no color set to be transparent. + /// + /// Handle to a FreeImage bitmap. + /// the index of the palette entry used as transparent color for + /// the image specified or -1 if there is no transparent color found + /// (e.g. the image is a high color image). + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparentIndex")] + public static extern int GetTransparentIndex(FIBITMAP dib); + + #endregion + + #region ICC profile functions + + /// + /// Retrieves the data of the bitmap. + /// This function can also be called safely, when the original format does not support profiles. + /// + /// Handle to a FreeImage bitmap. + /// The data of the bitmap. + public static FIICCPROFILE GetICCProfileEx(FIBITMAP dib) { unsafe { return *(FIICCPROFILE*)FreeImage.GetICCProfile(dib); } } + + /// + /// Retrieves a pointer to the data of the bitmap. + /// This function can also be called safely, when the original format does not support profiles. + /// + /// Handle to a FreeImage bitmap. + /// Pointer to the data of the bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetICCProfile")] + public static extern IntPtr GetICCProfile(FIBITMAP dib); + + /// + /// Creates a new block from ICC profile data previously read from a file + /// or built by a color management system. The profile data is attached to the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Pointer to the new data. + /// Size of the data. + /// Pointer to the created structure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CreateICCProfile")] + public static extern IntPtr CreateICCProfile(FIBITMAP dib, byte[] data, int size); + + /// + /// This function destroys an previously created by . + /// After this call the bitmap will contain no profile information. + /// This function should be called to ensure that a stored bitmap will not contain any profile information. + /// + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DestroyICCProfile")] + public static extern void DestroyICCProfile(FIBITMAP dib); + + #endregion + + #region Conversion functions + + /// + /// Converts a bitmap to 4 bits. + /// If the bitmap was a high-color bitmap (16, 24 or 32-bit) or if it was a + /// monochrome or greyscale bitmap (1 or 8-bit), the end result will be a + /// greyscale bitmap, otherwise (1-bit palletised bitmaps) it will be a palletised bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo4Bits")] + public static extern FIBITMAP ConvertTo4Bits(FIBITMAP dib); + + /// + /// Converts a bitmap to 8 bits. If the bitmap was a high-color bitmap (16, 24 or 32-bit) + /// or if it was a monochrome or greyscale bitmap (1 or 4-bit), the end result will be a + /// greyscale bitmap, otherwise (1 or 4-bit palletised bitmaps) it will be a palletised bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo8Bits")] + public static extern FIBITMAP ConvertTo8Bits(FIBITMAP dib); + + /// + /// Converts a bitmap to a 8-bit greyscale image with a linear ramp. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToGreyscale")] + public static extern FIBITMAP ConvertToGreyscale(FIBITMAP dib); + + /// + /// Converts a bitmap to 16 bits, where each pixel has a color pattern of + /// 5 bits red, 5 bits green and 5 bits blue. One bit in each pixel is unused. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo16Bits555")] + public static extern FIBITMAP ConvertTo16Bits555(FIBITMAP dib); + + /// + /// Converts a bitmap to 16 bits, where each pixel has a color pattern of + /// 5 bits red, 6 bits green and 5 bits blue. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo16Bits565")] + public static extern FIBITMAP ConvertTo16Bits565(FIBITMAP dib); + + /// + /// Converts a bitmap to 24 bits. A clone of the input bitmap is returned for 24-bit bitmaps. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo24Bits")] + public static extern FIBITMAP ConvertTo24Bits(FIBITMAP dib); + + /// + /// Converts a bitmap to 32 bits. A clone of the input bitmap is returned for 32-bit bitmaps. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo32Bits")] + public static extern FIBITMAP ConvertTo32Bits(FIBITMAP dib); + + /// + /// Quantizes a high-color 24-bit bitmap to an 8-bit palette color bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Specifies the color reduction algorithm to be used. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ColorQuantize")] + public static extern FIBITMAP ColorQuantize(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize); + + /// + /// ColorQuantizeEx is an extension to the method that + /// provides additional options used to quantize a 24-bit image to any + /// number of colors (up to 256), as well as quantize a 24-bit image using a + /// partial or full provided palette. + /// + /// Handle to a FreeImage bitmap. + /// Specifies the color reduction algorithm to be used. + /// Size of the desired output palette. + /// Size of the provided palette of ReservePalette. + /// The provided palette. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ColorQuantizeEx")] + public static extern FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, int ReserveSize, RGBQUAD[] ReservePalette); + + /// + /// Converts a bitmap to 1-bit monochrome bitmap using a threshold T between [0..255]. + /// The function first converts the bitmap to a 8-bit greyscale bitmap. + /// Then, any brightness level that is less than T is set to zero, otherwise to 1. + /// For 1-bit input bitmaps, the function clones the input bitmap and builds a monochrome palette. + /// + /// Handle to a FreeImage bitmap. + /// The threshold. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Threshold")] + public static extern FIBITMAP Threshold(FIBITMAP dib, byte t); + + /// + /// Converts a bitmap to 1-bit monochrome bitmap using a dithering algorithm. + /// For 1-bit input bitmaps, the function clones the input bitmap and builds a monochrome palette. + /// + /// Handle to a FreeImage bitmap. + /// The dithering algorithm to use. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Dither")] + public static extern FIBITMAP Dither(FIBITMAP dib, FREE_IMAGE_DITHER algorithm); + + /// + /// Converts a raw bitmap to a FreeImage bitmap. + /// + /// Pointer to the memory block containing the raw bitmap. + /// The width in pixels of the raw bitmap. + /// The height in pixels of the raw bitmap. + /// Defines the total width of a scanline in the raw bitmap, + /// including padding bytes. + /// The bit depth (bits per pixel) of the raw bitmap. + /// The bit mask describing the bits used to store a single + /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// If true, the raw bitmap is stored in top-down order (top-left pixel first) + /// and in bottom-up order (bottom-left pixel first) otherwise. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertFromRawBits")] + public static extern FIBITMAP ConvertFromRawBits(IntPtr bits, int width, int height, int pitch, + uint bpp, uint red_mask, uint green_mask, uint blue_mask, bool topdown); + + /// + /// Converts a raw bitmap to a FreeImage bitmap. + /// + /// Array of bytes containing the raw bitmap. + /// The width in pixels of the raw bitmap. + /// The height in pixels of the raw bitmap. + /// Defines the total width of a scanline in the raw bitmap, + /// including padding bytes. + /// The bit depth (bits per pixel) of the raw bitmap. + /// The bit mask describing the bits used to store a single + /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// If true, the raw bitmap is stored in top-down order (top-left pixel first) + /// and in bottom-up order (bottom-left pixel first) otherwise. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertFromRawBits")] + public static extern FIBITMAP ConvertFromRawBits(byte[] bits, int width, int height, int pitch, + uint bpp, uint red_mask, uint green_mask, uint blue_mask, bool topdown); + + /// + /// Converts a FreeImage bitmap to a raw bitmap, that is a raw piece of memory. + /// + /// Pointer to the memory block receiving the raw bitmap. + /// Handle to a FreeImage bitmap. + /// The desired total width in bytes of a scanline in the raw bitmap, + /// including any padding bytes. + /// The desired bit depth (bits per pixel) of the raw bitmap. + /// The desired bit mask describing the bits used to store a single + /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The desired bit mask describing the bits used to store a single + /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The desired bit mask describing the bits used to store a single + /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// If true, the raw bitmap will be stored in top-down order (top-left pixel first) + /// and in bottom-up order (bottom-left pixel first) otherwise. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRawBits")] + public static extern void ConvertToRawBits(IntPtr bits, FIBITMAP dib, int pitch, uint bpp, + uint red_mask, uint green_mask, uint blue_mask, bool topdown); + + /// + /// Converts a FreeImage bitmap to a raw bitmap, that is a raw piece of memory. + /// + /// Array of bytes receiving the raw bitmap. + /// Handle to a FreeImage bitmap. + /// The desired total width in bytes of a scanline in the raw bitmap, + /// including any padding bytes. + /// The desired bit depth (bits per pixel) of the raw bitmap. + /// The desired bit mask describing the bits used to store a single + /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The desired bit mask describing the bits used to store a single + /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The desired bit mask describing the bits used to store a single + /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// If true, the raw bitmap will be stored in top-down order (top-left pixel first) + /// and in bottom-up order (bottom-left pixel first) otherwise. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRawBits")] + public static extern void ConvertToRawBits(byte[] bits, FIBITMAP dib, int pitch, uint bpp, + uint red_mask, uint green_mask, uint blue_mask, bool topdown); + + /// + /// Converts a 24- or 32-bit RGB(A) standard image or a 48-bit RGB image to a FIT_RGBF type image. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRGBF")] + public static extern FIBITMAP ConvertToRGBF(FIBITMAP dib); + + /// + /// Converts a non standard image whose color type is FIC_MINISBLACK + /// to a standard 8-bit greyscale image. + /// + /// Handle to a FreeImage bitmap. + /// When true the conversion is done by scaling linearly + /// each pixel value from [min, max] to an integer value between [0..255], + /// where min and max are the minimum and maximum pixel values in the image. + /// When false the conversion is done by rounding each pixel value to an integer between [0..255]. + /// + /// Rounding is done using the following formula: + /// + /// dst_pixel = (BYTE) MIN(255, MAX(0, q)) where int q = int(src_pixel + 0.5); + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToStandardType")] + public static extern FIBITMAP ConvertToStandardType(FIBITMAP src, bool scale_linear); + + /// + /// Converts an image of any type to type dst_type. + /// + /// Handle to a FreeImage bitmap. + /// Destination type. + /// True to scale linear, else false. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToType")] + public static extern FIBITMAP ConvertToType(FIBITMAP src, FREE_IMAGE_TYPE dst_type, bool scale_linear); + + #endregion + + #region Tone mapping operators + + /// + /// Converts a High Dynamic Range image (48-bit RGB or 96-bit RGBF) to a 24-bit RGB image, suitable for display. + /// + /// Handle to a FreeImage bitmap. + /// The tone mapping operator to be used. + /// Parmeter depending on the used algorithm + /// Parmeter depending on the used algorithm + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ToneMapping")] + public static extern FIBITMAP ToneMapping(FIBITMAP dib, FREE_IMAGE_TMO tmo, double first_param, double second_param); + + /// + /// Converts a High Dynamic Range image to a 24-bit RGB image using a global + /// operator based on logarithmic compression of luminance values, imitating the human response to light. + /// + /// Handle to a FreeImage bitmap. + /// A gamma correction that is applied after the tone mapping. + /// A value of 1 means no correction. + /// Scale factor allowing to adjust the brightness of the output image. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoDrago03")] + public static extern FIBITMAP TmoDrago03(FIBITMAP src, double gamma, double exposure); + + /// + /// Converts a High Dynamic Range image to a 24-bit RGB image using a global operator inspired + /// by photoreceptor physiology of the human visual system. + /// + /// Handle to a FreeImage bitmap. + /// Controls the overall image intensity in the range [-8, 8]. + /// Controls the overall image contrast in the range [0.3, 1.0[. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoReinhard05")] + public static extern FIBITMAP TmoReinhard05(FIBITMAP src, double intensity, double contrast); + + /// + /// Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and convert to 24-bit RGB. + /// + /// Handle to a FreeImage bitmap. + /// Color saturation (s parameter in the paper) in [0.4..0.6] + /// Atenuation factor (beta parameter in the paper) in [0.8..0.9] + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoFattal02")] + public static extern FIBITMAP TmoFattal02(FIBITMAP src, double color_saturation, double attenuation); + + #endregion + + #region Compression functions + + /// + /// Compresses a source buffer into a target buffer, using the ZLib library. + /// + /// Pointer to the target buffer. + /// Size of the target buffer. + /// Must be at least 0.1% larger than source_size plus 12 bytes. + /// Pointer to the source buffer. + /// Size of the source buffer. + /// The actual size of the compressed buffer, or 0 if an error occurred. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibCompress")] + public static extern uint ZLibCompress(byte[] target, uint target_size, byte[] source, uint source_size); + + /// + /// Decompresses a source buffer into a target buffer, using the ZLib library. + /// + /// Pointer to the target buffer. + /// Size of the target buffer. + /// Must have been saved outlide of zlib. + /// Pointer to the source buffer. + /// Size of the source buffer. + /// The actual size of the uncompressed buffer, or 0 if an error occurred. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibUncompress")] + public static extern uint ZLibUncompress(byte[] target, uint target_size, byte[] source, uint source_size); + + /// + /// Compresses a source buffer into a target buffer, using the ZLib library. + /// + /// Pointer to the target buffer. + /// Size of the target buffer. + /// Must be at least 0.1% larger than source_size plus 24 bytes. + /// Pointer to the source buffer. + /// Size of the source buffer. + /// The actual size of the compressed buffer, or 0 if an error occurred. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibGZip")] + public static extern uint ZLibGZip(byte[] target, uint target_size, byte[] source, uint source_size); + + /// + /// Decompresses a source buffer into a target buffer, using the ZLib library. + /// + /// Pointer to the target buffer. + /// Size of the target buffer. + /// Must have been saved outlide of zlib. + /// Pointer to the source buffer. + /// Size of the source buffer. + /// The actual size of the uncompressed buffer, or 0 if an error occurred. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibGUnzip")] + public static extern uint ZLibGUnzip(byte[] target, uint target_size, byte[] source, uint source_size); + + /// + /// Generates a CRC32 checksum. + /// + /// The CRC32 checksum to begin with. + /// Pointer to the source buffer. + /// If the value is 0, the function returns the required initial value for the crc. + /// Size of the source buffer. + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibCRC32")] + public static extern uint ZLibCRC32(uint crc, byte[] source, uint source_size); + + #endregion + + #region Tag creation and destruction + + /// + /// Allocates a new object. + /// This object must be destroyed with a call to + /// when no longer in use. + /// + /// The new . + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CreateTag")] + public static extern FITAG CreateTag(); + + /// + /// Delete a previously allocated object. + /// + /// The to destroy. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeleteTag")] + public static extern void DeleteTag(FITAG tag); + + /// + /// Creates and returns a copy of a object. + /// + /// The to clone. + /// The new . + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloneTag")] + public static extern FITAG CloneTag(FITAG tag); + + #endregion + + #region Tag accessors + + /// + /// Returns the tag field name (unique inside a metadata model). + /// + /// The tag field. + /// The field name. + public static unsafe string GetTagKey(FITAG tag) { return PtrToStr(GetTagKey_(tag)); } + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetTagKey")] + private static unsafe extern byte* GetTagKey_(FITAG tag); + + /// + /// Returns the tag description. + /// + /// The tag field. + /// The description or NULL if unavailable. + public static unsafe string GetTagDescription(FITAG tag) { return PtrToStr(GetTagDescription_(tag)); } + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetTagDescription")] + private static unsafe extern byte* GetTagDescription_(FITAG tag); + + /// + /// Returns the tag ID. + /// + /// The tag field. + /// The ID or 0 if unavailable. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagID")] + public static extern ushort GetTagID(FITAG tag); + + /// + /// Returns the tag data type. + /// + /// The tag field. + /// The tag type. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagType")] + public static extern FREE_IMAGE_MDTYPE GetTagType(FITAG tag); + + /// + /// Returns the number of components in the tag (in tag type units). + /// + /// The tag field. + /// The number of components. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagCount")] + public static extern uint GetTagCount(FITAG tag); + + /// + /// Returns the length of the tag value in bytes. + /// + /// The tag field. + /// The length of the tag value. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagLength")] + public static extern uint GetTagLength(FITAG tag); + + /// + /// Returns the tag value. + /// It is up to the programmer to interpret the returned pointer correctly, + /// according to the results of GetTagType and GetTagCount. + /// + /// The tag field. + /// Pointer to the value. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagValue")] + public static extern IntPtr GetTagValue(FITAG tag); + + /// + /// Sets the tag field name. + /// + /// The tag field. + /// The new name. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetTagKey")] + public static extern bool SetTagKey(FITAG tag, string key); + + /// + /// Sets the tag description. + /// + /// The tag field. + /// The new description. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetTagDescription")] + public static extern bool SetTagDescription(FITAG tag, string description); + + /// + /// Sets the tag ID. + /// + /// The tag field. + /// The new ID. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagID")] + public static extern bool SetTagID(FITAG tag, ushort id); + + /// + /// Sets the tag data type. + /// + /// The tag field. + /// The new type. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagType")] + public static extern bool SetTagType(FITAG tag, FREE_IMAGE_MDTYPE type); + + /// + /// Sets the number of data in the tag. + /// + /// The tag field. + /// New number of data. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagCount")] + public static extern bool SetTagCount(FITAG tag, uint count); + + /// + /// Sets the length of the tag value in bytes. + /// + /// The tag field. + /// The new length. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagLength")] + public static extern bool SetTagLength(FITAG tag, uint length); + + /// + /// Sets the tag value. + /// + /// The tag field. + /// Pointer to the new value. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagValue")] + public static extern bool SetTagValue(FITAG tag, byte[] value); + + #endregion + + #region Metadata iterator + + /// + /// Provides information about the first instance of a tag that matches the metadata model. + /// + /// The model to match. + /// Handle to a FreeImage bitmap. + /// Tag that matches the metadata model. + /// Unique search handle that can be used to call FindNextMetadata or FindCloseMetadata. + /// Null if the metadata model does not exist. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindFirstMetadata")] + public static extern FIMETADATA FindFirstMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, out FITAG tag); + + /// + /// Find the next tag, if any, that matches the metadata model argument in a previous call + /// to FindFirstMetadata, and then alters the tag object contents accordingly. + /// + /// Unique search handle provided by FindFirstMetadata. + /// Tag that matches the metadata model. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindNextMetadata")] + public static extern bool FindNextMetadata(FIMETADATA mdhandle, out FITAG tag); + + /// + /// Closes the specified metadata search handle and releases associated resources. + /// + /// The handle to close. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindCloseMetadata")] + private static extern void FindCloseMetadata_(FIMETADATA mdhandle); + + #endregion + + #region Metadata setter and getter + + /// + /// Retrieve a metadata attached to a dib. + /// + /// The metadata model to look for. + /// Handle to a FreeImage bitmap. + /// The metadata field name. + /// A FITAG structure returned by the function. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetMetadata")] + public static extern bool GetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, string key, out FITAG tag); + + /// + /// Attach a new FreeImage tag to a dib. + /// + /// The metadata model used to store the tag. + /// Handle to a FreeImage bitmap. + /// The tag field name. + /// The FreeImage tag to be attached. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetMetadata")] + public static extern bool SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, string key, FITAG tag); + + #endregion + + #region Metadata helper functions + + /// + /// Returns the number of tags contained in the model metadata model attached to the input dib. + /// + /// The metadata model. + /// Handle to a FreeImage bitmap. + /// Number of tags contained in the metadata model. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetMetadataCount")] + public static extern uint GetMetadataCount(FREE_IMAGE_MDMODEL model, FIBITMAP dib); + + /// + /// Copies the metadata of FreeImage bitmap to another. + /// + /// The FreeImage bitmap to copy the metadata to. + /// The FreeImage bitmap to copy the metadata from. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloneMetadata")] + public static extern bool CloneMetadata(FIBITMAP dst, FIBITMAP src); + + /// + /// Converts a FreeImage tag structure to a string that represents the interpreted tag value. + /// The function is not thread safe. + /// + /// The metadata model. + /// The interpreted tag value. + /// Reserved. + /// The representing string. + public static unsafe string TagToString(FREE_IMAGE_MDMODEL model, FITAG tag, uint Make) { return PtrToStr(TagToString_(model, tag, Make)); } + [DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_TagToString")] + private static unsafe extern byte* TagToString_(FREE_IMAGE_MDMODEL model, FITAG tag, uint Make); + + #endregion + + #region Rotation and flipping + + /// + /// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. + /// 1-bit images rotation is limited to integer multiple of 90�. + /// null is returned for other values. + /// + /// Handle to a FreeImage bitmap. + /// The angle of rotation. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_RotateClassic")] + [Obsolete("RotateClassic is deprecated (use Rotate instead).")] + public static extern FIBITMAP RotateClassic(FIBITMAP dib, double angle); + + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Rotate")] + internal static extern FIBITMAP Rotate(FIBITMAP dib, double angle, IntPtr backgroundColor); + + /// + /// This function performs a rotation and / or translation of an 8-bit greyscale, + /// 24- or 32-bit image, using a 3rd order (cubic) B-Spline. + /// + /// Handle to a FreeImage bitmap. + /// The angle of rotation. + /// Horizontal image translation. + /// Vertical image translation. + /// Rotation center x-coordinate. + /// Rotation center y-coordinate. + /// When true the irrelevant part of the image is set to a black color, + /// otherwise, a mirroring technique is used to fill irrelevant pixels. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_RotateEx")] + public static extern FIBITMAP RotateEx(FIBITMAP dib, double angle, + double x_shift, double y_shift, double x_origin, double y_origin, bool use_mask); + + /// + /// Flip the input dib horizontally along the vertical axis. + /// + /// Handle to a FreeImage bitmap. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FlipHorizontal")] + public static extern bool FlipHorizontal(FIBITMAP dib); + + /// + /// Flip the input dib vertically along the horizontal axis. + /// + /// Handle to a FreeImage bitmap. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FlipVertical")] + public static extern bool FlipVertical(FIBITMAP dib); + + /// + /// Performs a lossless rotation or flipping on a JPEG file. + /// + /// Source file. + /// Destination file; can be the source file; will be overwritten. + /// The operation to apply. + /// To avoid lossy transformation, you can set the perfect parameter to true. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_JPEGTransformU")] + public static extern bool JPEGTransform(string src_file, string dst_file, + FREE_IMAGE_JPEG_OPERATION operation, bool perfect); + + #endregion + + #region Upsampling / downsampling + + /// + /// Performs resampling (or scaling, zooming) of a greyscale or RGB(A) image + /// to the desired destination width and height. + /// + /// Handle to a FreeImage bitmap. + /// Destination width. + /// Destination height. + /// The filter to apply. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Rescale")] + public static extern FIBITMAP Rescale(FIBITMAP dib, int dst_width, int dst_height, FREE_IMAGE_FILTER filter); + + /// + /// Creates a thumbnail from a greyscale or RGB(A) image, keeping aspect ratio. + /// + /// Handle to a FreeImage bitmap. + /// Thumbnail square size. + /// When true HDR images are transperantly converted to standard images. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MakeThumbnail")] + public static extern FIBITMAP MakeThumbnail(FIBITMAP dib, int max_pixel_size, bool convert); + + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_EnlargeCanvas")] + internal static extern FIBITMAP EnlargeCanvas(FIBITMAP dib, + int left, int top, int right, int bottom, IntPtr color, FREE_IMAGE_COLOR_OPTIONS options); + + #endregion + + #region Color manipulation + + /// + /// Perfoms an histogram transformation on a 8-, 24- or 32-bit image. + /// + /// Handle to a FreeImage bitmap. + /// The lookup table. + /// It's size is assumed to be 256 in length. + /// The color channel to be transformed. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustCurve")] + public static extern bool AdjustCurve(FIBITMAP dib, byte[] lookUpTable, FREE_IMAGE_COLOR_CHANNEL channel); + + /// + /// Performs gamma correction on a 8-, 24- or 32-bit image. + /// + /// Handle to a FreeImage bitmap. + /// The parameter represents the gamma value to use (gamma > 0). + /// A value of 1.0 leaves the image alone, less than one darkens it, and greater than one lightens it. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustGamma")] + public static extern bool AdjustGamma(FIBITMAP dib, double gamma); + + /// + /// Adjusts the brightness of a 8-, 24- or 32-bit image by a certain amount. + /// + /// Handle to a FreeImage bitmap. + /// A value 0 means no change, + /// less than 0 will make the image darker and greater than 0 will make the image brighter. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustBrightness")] + public static extern bool AdjustBrightness(FIBITMAP dib, double percentage); + + /// + /// Adjusts the contrast of a 8-, 24- or 32-bit image by a certain amount. + /// + /// Handle to a FreeImage bitmap. + /// A value 0 means no change, + /// less than 0 will decrease the contrast and greater than 0 will increase the contrast of the image. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustContrast")] + public static extern bool AdjustContrast(FIBITMAP dib, double percentage); + + /// + /// Inverts each pixel data. + /// + /// Handle to a FreeImage bitmap. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Invert")] + public static extern bool Invert(FIBITMAP dib); + + /// + /// Computes the image histogram. + /// + /// Handle to a FreeImage bitmap. + /// Array of integers with a size of 256. + /// Channel to compute from. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetHistogram")] + public static extern bool GetHistogram(FIBITMAP dib, int[] histo, FREE_IMAGE_COLOR_CHANNEL channel); + + #endregion + + #region Channel processing + + /// + /// Retrieves the red, green, blue or alpha channel of a 24- or 32-bit image. + /// + /// Handle to a FreeImage bitmap. + /// The color channel to extract. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetChannel")] + public static extern FIBITMAP GetChannel(FIBITMAP dib, FREE_IMAGE_COLOR_CHANNEL channel); + + /// + /// Insert a 8-bit dib into a 24- or 32-bit image. + /// Both images must have to same width and height. + /// + /// Handle to a FreeImage bitmap. + /// Handle to the bitmap to insert. + /// The color channel to replace. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetChannel")] + public static extern bool SetChannel(FIBITMAP dib, FIBITMAP dib8, FREE_IMAGE_COLOR_CHANNEL channel); + + /// + /// Retrieves the real part, imaginary part, magnitude or phase of a complex image. + /// + /// Handle to a FreeImage bitmap. + /// The color channel to extract. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetComplexChannel")] + public static extern FIBITMAP GetComplexChannel(FIBITMAP src, FREE_IMAGE_COLOR_CHANNEL channel); + + /// + /// Set the real or imaginary part of a complex image. + /// Both images must have to same width and height. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + /// The color channel to replace. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetComplexChannel")] + public static extern bool SetComplexChannel(FIBITMAP dst, FIBITMAP src, FREE_IMAGE_COLOR_CHANNEL channel); + + #endregion + + #region Copy / Paste / Composite routines + + /// + /// Copy a sub part of the current dib image. + /// + /// Handle to a FreeImage bitmap. + /// Specifies the left position of the cropped rectangle. + /// Specifies the top position of the cropped rectangle. + /// Specifies the right position of the cropped rectangle. + /// Specifies the bottom position of the cropped rectangle. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Copy")] + public static extern FIBITMAP Copy(FIBITMAP dib, int left, int top, int right, int bottom); + + /// + /// Alpha blend or combine a sub part image with the current dib image. + /// The bit depth of the dst bitmap must be greater than or equal to the bit depth of the src. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a FreeImage bitmap. + /// Specifies the left position of the sub image. + /// Specifies the top position of the sub image. + /// alpha blend factor. + /// The source and destination images are alpha blended if alpha=0..255. + /// If alpha > 255, then the source image is combined to the destination image. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Paste")] + public static extern bool Paste(FIBITMAP dst, FIBITMAP src, int left, int top, int alpha); + + /// + /// This function composite a transparent foreground image against a single background color or + /// against a background image. + /// + /// Handle to a FreeImage bitmap. + /// When true the background of fg is used if it contains one. + /// The application background is used if useFileBkg is false. + /// Image used as background when useFileBkg is false or fg has no background + /// and appBkColor is null. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Composite")] + public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg, ref RGBQUAD appBkColor, FIBITMAP bg); + + /// + /// This function composite a transparent foreground image against a single background color or + /// against a background image. + /// + /// Handle to a FreeImage bitmap. + /// When true the background of fg is used if it contains one. + /// The application background is used if useFileBkg is false + /// and 'appBkColor' is not null. + /// Image used as background when useFileBkg is false or fg has no background + /// and appBkColor is null. + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Composite")] + public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg, RGBQUAD[] appBkColor, FIBITMAP bg); + + /// + /// Performs a lossless crop on a JPEG file. + /// + /// Source filename. + /// Destination filename. + /// Specifies the left position of the cropped rectangle. + /// Specifies the top position of the cropped rectangle. + /// Specifies the right position of the cropped rectangle. + /// Specifies the bottom position of the cropped rectangle. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_JPEGCropU")] + public static extern bool JPEGCrop(string src_file, string dst_file, int left, int top, int right, int bottom); + + /// + /// Applies the alpha value of each pixel to its color components. + /// The aplha value stays unchanged. + /// Only works with 32-bits color depth. + /// + /// Handle to a FreeImage bitmap. + /// Returns true on success, false on failure. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_PreMultiplyWithAlpha")] + public static extern bool PreMultiplyWithAlpha(FIBITMAP dib); + + #endregion + + #region Miscellaneous algorithms + + /// + /// Solves a Poisson equation, remap result pixels to [0..1] and returns the solution. + /// + /// Handle to a FreeImage bitmap. + /// Number of cycles in the multigrid algorithm (usually 2 or 3) + /// Handle to a FreeImage bitmap. + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MultigridPoissonSolver")] + public static extern FIBITMAP MultigridPoissonSolver(FIBITMAP Laplacian, int ncycle); + + #endregion + + #region Colors + + /// + /// Creates a lookup table to be used with which may adjusts brightness and + /// contrast, correct gamma and invert the image with a single call to . + /// + /// Output lookup table to be used with . + /// The size of 'lookUpTable' is assumed to be 256. + /// Percentage brightness value where -100 <= brightness <= 100. + /// A value of 0 means no change, less than 0 will make the image darker and greater + /// than 0 will make the image brighter. + /// Percentage contrast value where -100 <= contrast <= 100. + /// A value of 0 means no change, less than 0 will decrease the contrast + /// and greater than 0 will increase the contrast of the image. + /// Gamma value to be used for gamma correction. + /// A value of 1.0 leaves the image alone, less than one darkens it, + /// and greater than one lightens it. + /// If set to true, the image will be inverted. + /// The number of adjustments applied to the resulting lookup table + /// compared to a blind lookup table. + /// + /// This function creates a lookup table to be used with which may adjust + /// brightness and contrast, correct gamma and invert the image with a single call to + /// . If more than one of these image display properties need to be adjusted, + /// using a combined lookup table should be preferred over calling each adjustment function + /// separately. That's particularly true for huge images or if performance is an issue. Then, + /// the expensive process of iterating over all pixels of an image is performed only once and + /// not up to four times. + /// + /// Furthermore, the lookup table created does not depend on the order, in which each single + /// adjustment operation is performed. Due to rounding and byte casting issues, it actually + /// matters in which order individual adjustment operations are performed. Both of the following + /// snippets most likely produce different results: + /// + /// + /// // snippet 1: contrast, brightness + /// AdjustContrast(dib, 15.0); + /// AdjustBrightness(dib, 50.0); + /// + /// + /// + /// // snippet 2: brightness, contrast + /// AdjustBrightness(dib, 50.0); + /// AdjustContrast(dib, 15.0); + /// + /// + /// Better and even faster would be snippet 3: + /// + /// + /// // snippet 3: + /// byte[] lut = new byte[256]; + /// GetAdjustColorsLookupTable(lut, 50.0, 15.0, 1.0, false); + /// AdjustCurve(dib, lut, FREE_IMAGE_COLOR_CHANNEL.FICC_RGB); + /// + /// + /// This function is also used internally by , which does not return the + /// lookup table, but uses it to call on the passed image. + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetAdjustColorsLookupTable")] + public static extern int GetAdjustColorsLookupTable(byte[] lookUpTable, double brightness, double contrast, double gamma, bool invert); + + /// + /// Adjusts an image's brightness, contrast and gamma as well as it may + /// optionally invert the image within a single operation. + /// + /// Handle to a FreeImage bitmap. + /// Percentage brightness value where -100 <= brightness <= 100. + /// A value of 0 means no change, less than 0 will make the image darker and greater + /// than 0 will make the image brighter. + /// Percentage contrast value where -100 <= contrast <= 100. + /// A value of 0 means no change, less than 0 will decrease the contrast + /// and greater than 0 will increase the contrast of the image. + /// Gamma value to be used for gamma correction. + /// A value of 1.0 leaves the image alone, less than one darkens it, + /// and greater than one lightens it. + /// This parameter must not be zero or smaller than zero. + /// If so, it will be ignored and no gamma correction will be performed on the image. + /// If set to true, the image will be inverted. + /// Returns true on success, false on failure. + /// + /// This function adjusts an image's brightness, contrast and gamma as well as it + /// may optionally invert the image within a single operation. If more than one of + /// these image display properties need to be adjusted, using this function should + /// be preferred over calling each adjustment function separately. That's particularly + /// true for huge images or if performance is an issue. + /// + /// This function relies on , + /// which creates a single lookup table, that combines all adjustment operations requested. + /// + /// Furthermore, the lookup table created by does + /// not depend on the order, in which each single adjustment operation is performed. + /// Due to rounding and byte casting issues, it actually matters in which order individual + /// adjustment operations are performed. Both of the following snippets most likely produce + /// different results: + /// + /// + /// // snippet 1: contrast, brightness + /// AdjustContrast(dib, 15.0); + /// AdjustBrightness(dib, 50.0); + /// + /// + /// + /// // snippet 2: brightness, contrast + /// AdjustBrightness(dib, 50.0); + /// AdjustContrast(dib, 15.0); + /// + /// + /// Better and even faster would be snippet 3: + /// + /// + /// // snippet 3: + /// AdjustColors(dib, 50.0, 15.0, 1.0, false); + /// + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustColors")] + public static extern bool AdjustColors(FIBITMAP dib, double brightness, double contrast, double gamma, bool invert); + + /// + /// Applies color mapping for one or several colors on a 1-, 4- or 8-bit + /// palletized or a 16-, 24- or 32-bit high color image. + /// + /// Handle to a FreeImage bitmap. + /// Array of colors to be used as the mapping source. + /// Array of colors to be used as the mapping destination. + /// The number of colors to be mapped. This is the size of both + /// srccolors and dstcolors. + /// If true, 32-bit images and colors are treated as 24-bit. + /// If true, source and destination colors are swapped, that is, + /// each destination color is also mapped to the corresponding source color. + /// The total number of pixels changed. + /// + /// This function maps up to colors specified in + /// to these specified in . + /// Thereby, color srccolors[N], if found in the image, will be replaced by color + /// dstcolors[N]. If is true, additionally all colors + /// specified in are also mapped to these specified + /// in . For high color images, the actual image data will be + /// modified whereas, for palletized images only the palette will be changed. + /// + /// The function returns the number of pixels changed or zero, if no pixels were changed. + /// + /// Both arrays and are assumed + /// not to hold less than colors. + /// + /// For 16-bit images, all colors specified are transparently converted to their + /// proper 16-bit representation (either in RGB555 or RGB565 format, which is determined + /// by the image's red- green- and blue-mask). + /// + /// Note, that this behaviour is different from what does, + /// which modifies the actual image data on palletized images. + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ApplyColorMapping")] + public static extern uint ApplyColorMapping(FIBITMAP dib, RGBQUAD[] srccolors, RGBQUAD[] dstcolors, uint count, bool ignore_alpha, bool swap); + + /// + /// Swaps two specified colors on a 1-, 4- or 8-bit palletized + /// or a 16-, 24- or 32-bit high color image. + /// + /// Handle to a FreeImage bitmap. + /// One of the two colors to be swapped. + /// The other of the two colors to be swapped. + /// If true, 32-bit images and colors are treated as 24-bit. + /// The total number of pixels changed. + /// + /// This function swaps the two specified colors and + /// on a palletized or high color image. + /// For high color images, the actual image data will be modified whereas, for palletized + /// images only the palette will be changed. + /// + /// Note, that this behaviour is different from what does, + /// which modifies the actual image data on palletized images. + /// + /// This is just a thin wrapper for and resolves to: + /// + /// + /// return ApplyColorMapping(dib, color_a, color_b, 1, ignore_alpha, true); + /// + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SwapColors")] + public static extern uint SwapColors(FIBITMAP dib, ref RGBQUAD color_a, ref RGBQUAD color_b, bool ignore_alpha); + + /// + /// Applies palette index mapping for one or several indices + /// on a 1-, 4- or 8-bit palletized image. + /// + /// Handle to a FreeImage bitmap. + /// Array of palette indices to be used as the mapping source. + /// Array of palette indices to be used as the mapping destination. + /// The number of palette indices to be mapped. This is the size of both + /// srcindices and dstindices + /// If true, source and destination palette indices are swapped, that is, + /// each destination index is also mapped to the corresponding source index. + /// The total number of pixels changed. + /// + /// This function maps up to palette indices specified in + /// to these specified in . + /// Thereby, index srcindices[N], if present in the image, will be replaced by index + /// dstindices[N]. If is true, additionally all indices + /// specified in are also mapped to these specified in + /// . + /// + /// The function returns the number of pixels changed or zero, if no pixels were changed. + /// Both arrays and are assumed not to + /// hold less than indices. + /// + /// Note, that this behaviour is different from what does, which + /// modifies the actual image data on palletized images. + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ApplyPaletteIndexMapping")] + public static extern uint ApplyPaletteIndexMapping(FIBITMAP dib, byte[] srcindices, byte[] dstindices, uint count, bool swap); + + /// + /// Swaps two specified palette indices on a 1-, 4- or 8-bit palletized image. + /// + /// Handle to a FreeImage bitmap. + /// One of the two palette indices to be swapped. + /// The other of the two palette indices to be swapped. + /// The total number of pixels changed. + /// + /// This function swaps the two specified palette indices index_a and + /// index_b on a palletized image. Therefore, not the palette, but the + /// actual image data will be modified. + /// + /// Note, that this behaviour is different from what does on palletized images, + /// which only swaps the colors in the palette. + /// + /// This is just a thin wrapper for and resolves to: + /// + /// + /// return ApplyPaletteIndexMapping(dib, index_a, index_b, 1, true); + /// + /// + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SwapPaletteIndices")] + public static extern uint SwapPaletteIndices(FIBITMAP dib, ref byte index_a, ref byte index_b); + + [DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FillBackground")] + internal static extern bool FillBackground(FIBITMAP dib, IntPtr color, FREE_IMAGE_COLOR_OPTIONS options); + + #endregion + } +} + +///////////////////////////////////////////////////// +// // +// Wrapper functions // +// // +///////////////////////////////////////////////////// + + #region Structs + +namespace FreeImageAPI.IO +{ + /// + /// Wrapper for a custom handle. + /// + /// + /// The fi_handle of FreeImage in C++ is a simple pointer, but in .NET + /// it's not that simple. This wrapper uses fi_handle in two different ways. + /// + /// We implement a new plugin and FreeImage gives us a handle (pointer) that + /// we can simply pass through to the given functions in a 'FreeImageIO' + /// structure. + /// But when we want to use LoadFromhandle or SaveToHandle we need + /// a fi_handle (that we receive again in our own functions). + /// This handle is for example a stream (see LoadFromStream / SaveToStream) + /// that we want to work with. To know which stream a read/write is meant for + /// we could use a hash value that the wrapper itself handles or we can + /// go the unmanaged way of using a handle. + /// Therefor we use a to receive a unique pointer that we can + /// convert back into a .NET object. + /// When the fi_handle instance is no longer needed the instance must be disposed + /// by the creater manually! It is recommended to use the using statement to + /// be sure the instance is always disposed: + /// + /// + /// using (fi_handle handle = new fi_handle(object)) + /// { + /// callSomeFunctions(handle); + /// } + /// + /// + /// What does that mean? + /// If we get a fi_handle from unmanaged code we get a pointer to unmanaged + /// memory that we do not have to care about, and just pass ist back to FreeImage. + /// If we have to create a handle our own we use the standard constructur + /// that fills the with an pointer that represents the given object. + /// With calling the is used to retrieve the original + /// object we passed through the constructor. + /// + /// This way we can implement a fi_handle that works with managed an unmanaged + /// code. + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct fi_handle : IComparable, IComparable, IEquatable, IDisposable + { + /// + /// The handle to wrap. + /// + public IntPtr handle; + + /// + /// Initializes a new instance wrapping a managed object. + /// + /// The object to wrap. + /// + /// is null. + public fi_handle(object obj) + { + if (obj == null) + { + throw new ArgumentNullException("obj"); + } + GCHandle gch = GCHandle.Alloc(obj, GCHandleType.Normal); + handle = GCHandle.ToIntPtr(gch); + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(fi_handle left, fi_handle right) + { + return (left.handle == right.handle); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(fi_handle left, fi_handle right) + { + return (left.handle != right.handle); + } + + /// + /// Gets whether the pointer is a null pointer. + /// + public bool IsNull + { + get + { + return (handle == IntPtr.Zero); + } + } + + /// + /// Returns the object assigned to the handle in case this instance + /// was created by managed code. + /// + /// assigned to this handle or null on failure. + internal object GetObject() + { + object result = null; + if (handle != IntPtr.Zero) + { + try + { + result = GCHandle.FromIntPtr(handle).Target; + } + catch + { + } + } + return result; + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return handle.ToString(); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return handle.GetHashCode(); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is fi_handle) && (this == ((fi_handle)obj))); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// An object to compare with this object. + /// True if the current object is equal to the other parameter; otherwise, false. + public bool Equals(fi_handle other) + { + return (this == other); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is fi_handle)) + { + throw new ArgumentException("obj"); + } + return CompareTo((fi_handle)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(fi_handle other) + { + return handle.ToInt64().CompareTo(other.handle.ToInt64()); + } + + /// + /// Releases all resources used by the instance. + /// + public void Dispose() + { + if (this.handle != IntPtr.Zero) + { + try + { + GCHandle.FromIntPtr(handle).Free(); + } + catch + { + } + finally + { + this.handle = IntPtr.Zero; + } + } + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FI1BIT structure represents a single bit. + /// It's value can be 0 or 1. + /// + [DebuggerDisplay("{value}"), + Serializable] + public struct FI1BIT + { + /// + /// Represents the largest possible value of . This field is constant. + /// + public const byte MaxValue = 0x01; + + /// + /// Represents the smallest possible value of . This field is constant. + /// + public const byte MinValue = 0x00; + + /// + /// The value of the structure. + /// + private byte value; + + /// + /// Initializes a new instance based on the specified value. + /// + /// The value to initialize with. + private FI1BIT(byte value) + { + this.value = (byte)(value & MaxValue); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator byte(FI1BIT value) + { + return value.value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FI1BIT(byte value) + { + return new FI1BIT(value); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return value.ToString(); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FI4BIT structure represents the half of a . + /// It's valuerange is between 0 and 15. + /// + [DebuggerDisplay("{value}"), + Serializable] + public struct FI4BIT + { + /// + /// Represents the largest possible value of . This field is constant. + /// + public const byte MaxValue = 0x0F; + + /// + /// Represents the smallest possible value of . This field is constant. + /// + public const byte MinValue = 0x00; + + /// + /// The value of the structure. + /// + private byte value; + + /// + /// Initializes a new instance based on the specified value. + /// + /// The value to initialize with. + private FI4BIT(byte value) + { + this.value = (byte)(value & MaxValue); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator byte(FI4BIT value) + { + return value.value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FI4BIT(byte value) + { + return new FI4BIT(value); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return value.ToString(); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FI16RGB555 structure describes a color consisting of relative + /// intensities of red, green, blue and alpha value. Each single color + /// component consumes 5 bits and so, takes values in the range from 0 to 31. + /// + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the FI16RGB555 structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the FI16RGB555 structure and my be used in all situations which require + /// an FI16RGB555 type. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// FI16RGB555 structure and the structure. + /// + /// FI16RGB555 fi16rgb; + /// // Initialize the structure using a native .NET Color structure. + /// fi16rgb = new FI16RGB555(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// fi16rgb = Color.DarkSeaGreen; + /// // Convert the FI16RGB555 instance into a native .NET Color + /// // using its implicit operator. + /// Color color = fi16rgb; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = fi16rgb.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FI16RGB555 : IComparable, IComparable, IEquatable + { + /// + /// The value of the color. + /// + private ushort value; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public FI16RGB555(Color color) + { + value = (ushort)( + (((color.R * 31) / 255) << FreeImage.FI16_555_RED_SHIFT) + + (((color.G * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT) + + (((color.B * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT)); + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FI16RGB555 left, FI16RGB555 right) + { + return (left.value == right.value); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FI16RGB555 left, FI16RGB555 right) + { + return (!(left == right)); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FI16RGB555(Color value) + { + return new FI16RGB555(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(FI16RGB555 value) + { + return value.Color; + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb( + ((value & FreeImage.FI16_555_RED_MASK) >> FreeImage.FI16_555_RED_SHIFT) * 255 / 31, + ((value & FreeImage.FI16_555_GREEN_MASK) >> FreeImage.FI16_555_GREEN_SHIFT) * 255 / 31, + ((value & FreeImage.FI16_555_BLUE_MASK) >> FreeImage.FI16_555_BLUE_SHIFT) * 255 / 31); + } + set + { + this.value = (ushort)( + (((value.R * 31) / 255) << FreeImage.FI16_555_RED_SHIFT) + + (((value.G * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT) + + (((value.B * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT)); + } + } + + /// + /// Gets or sets the red color component. + /// + public byte Red + { + get + { + return (byte)(((value & FreeImage.FI16_555_RED_MASK) >> FreeImage.FI16_555_RED_SHIFT) * 255 / 31); + } + set + { + this.value = (ushort)((this.value & (~FreeImage.FI16_555_RED_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_RED_SHIFT)); + } + } + + /// + /// Gets or sets the green color component. + /// + public byte Green + { + get + { + return (byte)(((value & FreeImage.FI16_555_GREEN_MASK) >> FreeImage.FI16_555_GREEN_SHIFT) * 255 / 31); + } + set + { + this.value = (ushort)((this.value & (~FreeImage.FI16_555_GREEN_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT)); + } + } + + /// + /// Gets or sets the blue color component. + /// + public byte Blue + { + get + { + return (byte)(((value & FreeImage.FI16_555_BLUE_MASK) >> FreeImage.FI16_555_BLUE_SHIFT) * 255 / 31); + } + set + { + this.value = (ushort)((this.value & (~FreeImage.FI16_555_BLUE_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT)); + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FI16RGB555)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FI16RGB555)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FI16RGB555 other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return base.Equals(obj); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FI16RGB555 other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FI16RGB565 structure describes a color consisting of relative + /// intensities of red, green, blue and alpha value. Each single color + /// component consumes 5 bits and so, takes values in the range from 0 to 31. + /// + /// + /// For easy integration of the underlying structure into the .NET framework, + /// the FI16RGB565 structure implements implicit conversion operators to + /// convert the represented color to and from the + /// type. This makes the type a real replacement + /// for the FI16RGB565 structure and my be used in all situations which require + /// an FI16RGB565 type. + /// + /// + /// + /// The following code example demonstrates the various conversions between the + /// FI16RGB565 structure and the structure. + /// + /// FI16RGB565 fi16rgb; + /// // Initialize the structure using a native .NET Color structure. + /// fi16rgb = new FI16RGB565(Color.Indigo); + /// // Initialize the structure using the implicit operator. + /// fi16rgb = Color.DarkSeaGreen; + /// // Convert the FI16RGB565 instance into a native .NET Color + /// // using its implicit operator. + /// Color color = fi16rgb; + /// // Using the structure's Color property for converting it + /// // into a native .NET Color. + /// Color another = fi16rgb.Color; + /// + /// + [Serializable, StructLayout(LayoutKind.Sequential)] + public struct FI16RGB565 : IComparable, IComparable, IEquatable + { + /// + /// The value of the color. + /// + private ushort value; + + /// + /// Initializes a new instance based on the specified . + /// + /// to initialize with. + public FI16RGB565(Color color) + { + value = (ushort)( + (((color.R * 31) / 255) << FreeImage.FI16_565_RED_SHIFT) + + (((color.G * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT) + + (((color.B * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT)); + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(FI16RGB565 left, FI16RGB565 right) + { + return (left.value == right.value); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(FI16RGB565 left, FI16RGB565 right) + { + return (!(left == right)); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FI16RGB565(Color value) + { + return new FI16RGB565(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator Color(FI16RGB565 value) + { + return value.Color; + } + + /// + /// Gets or sets the of the structure. + /// + public Color Color + { + get + { + return Color.FromArgb( + ((value & FreeImage.FI16_565_RED_MASK) >> FreeImage.FI16_565_RED_SHIFT) * 255 / 31, + ((value & FreeImage.FI16_565_GREEN_MASK) >> FreeImage.FI16_565_GREEN_SHIFT) * 255 / 63, + ((value & FreeImage.FI16_565_BLUE_MASK) >> FreeImage.FI16_565_BLUE_SHIFT) * 255 / 31); + } + set + { + this.value = (ushort)( + (((value.R * 31) / 255) << FreeImage.FI16_565_RED_SHIFT) + + (((value.G * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT) + + (((value.B * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT)); + } + } + + /// + /// Gets or sets the red color component. + /// + public byte Red + { + get + { + return (byte)(((value & FreeImage.FI16_565_RED_MASK) >> FreeImage.FI16_565_RED_SHIFT) * 255 / 31); + } + set + { + this.value = (ushort)((this.value & (~FreeImage.FI16_565_RED_MASK)) | (((value * 31) / 255) << FreeImage.FI16_565_RED_SHIFT)); + } + } + + /// + /// Gets or sets the green color component. + /// + public byte Green + { + get + { + return (byte)(((value & FreeImage.FI16_565_GREEN_MASK) >> FreeImage.FI16_565_GREEN_SHIFT) * 255 / 63); + } + set + { + this.value = (ushort)((this.value & (~FreeImage.FI16_565_GREEN_MASK)) | (((value * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT)); + } + } + + /// + /// Gets or sets the blue color component. + /// + public byte Blue + { + get + { + return (byte)(((value & FreeImage.FI16_565_BLUE_MASK) >> FreeImage.FI16_565_BLUE_SHIFT) * 255 / 31); + } + set + { + this.value = (ushort)((this.value & (~FreeImage.FI16_565_BLUE_MASK)) | (((value * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT)); + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FI16RGB565)) + { + throw new ArgumentException("obj"); + } + return CompareTo((FI16RGB565)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FI16RGB565 other) + { + return this.Color.ToArgb().CompareTo(other.Color.ToArgb()); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return base.Equals(obj); + } + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FI16RGB565 other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return FreeImage.ColorToString(Color); + } + } +} + +namespace FreeImageAPI +{ + /// + /// The FIRational structure represents a fraction via two + /// instances which are interpreted as numerator and denominator. + /// + /// + /// The structure tries to approximate the value of + /// when creating a new instance by using a better algorithm than FreeImage does. + /// + /// The structure implements the following operators: + /// +, -, ++, --, ==, != , >, >==, <, <== and ~ (which switches nominator and denomiator). + /// + /// The structure can be converted into all .NET standard types either implicit or + /// explicit. + /// + [Serializable, StructLayout(LayoutKind.Sequential), ComVisible(true)] + public struct FIRational : IConvertible, IComparable, IFormattable, IComparable, IEquatable + { + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private int numerator; + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private int denominator; + + /// + /// Represents the largest possible value of . This field is constant. + /// + public static readonly FIRational MaxValue = new FIRational(Int32.MaxValue, 1); + + /// + /// Represents the smallest possible value of . This field is constant. + /// + public static readonly FIRational MinValue = new FIRational(Int32.MinValue, 1); + + /// + /// Represents the smallest positive value greater than zero. This field is constant. + /// + public static readonly FIRational Epsilon = new FIRational(1, Int32.MaxValue); + + /// + /// Initializes a new instance based on the specified parameters. + /// + /// The numerator. + /// The denominator. + public FIRational(int n, int d) + { + numerator = n; + denominator = d; + Normalize(); + } + + /// + /// Initializes a new instance based on the specified parameters. + /// + /// The tag to read the data from. + public unsafe FIRational(FITAG tag) + { + switch (FreeImage.GetTagType(tag)) + { + case FREE_IMAGE_MDTYPE.FIDT_SRATIONAL: + int* value = (int*)FreeImage.GetTagValue(tag); + numerator = (int)value[0]; + denominator = (int)value[1]; + Normalize(); + return; + default: + throw new ArgumentException("tag"); + } + } + + /// + /// Initializes a new instance based on the specified parameters. + /// + /// The value to convert into a fraction. + /// + /// cannot be converted into a fraction + /// represented by two integer values. + public FIRational(decimal value) + { + try + { + int sign = value < 0 ? -1 : 1; + value = Math.Abs(value); + try + { + int[] contFract = CreateContinuedFraction(value); + CreateFraction(contFract, out numerator, out denominator); + Normalize(); + } + catch + { + numerator = 0; + denominator = 1; + } + if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) + { + int maxDen = (Int32.MaxValue / (int)value) - 2; + maxDen = maxDen < 10000 ? maxDen : 10000; + ApproximateFraction(value, maxDen, out numerator, out denominator); + Normalize(); + if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) + { + throw new OverflowException("Unable to convert value into a fraction"); + } + } + numerator *= sign; + Normalize(); + } + catch (Exception ex) + { + throw new OverflowException("Unable to calculate fraction.", ex); + } + } + + /// + /// The numerator of the fraction. + /// + public int Numerator + { + get { return numerator; } + } + + /// + /// The denominator of the fraction. + /// + public int Denominator + { + get { return denominator; } + } + + /// + /// Returns the truncated value of the fraction. + /// + /// + public int Truncate() + { + return denominator > 0 ? (int)(numerator / denominator) : 0; + } + + /// + /// Returns whether the fraction is representing an integer value. + /// + public bool IsInteger + { + get + { + return (denominator == 1 || + (denominator != 0 && (numerator % denominator == 0)) || + (denominator == 0 && numerator == 0)); + } + } + + /// + /// Calculated the greatest common divisor of 'a' and 'b'. + /// + private static long Gcd(long a, long b) + { + a = Math.Abs(a); + b = Math.Abs(b); + long r; + while (b > 0) + { + r = a % b; + a = b; + b = r; + } + return a; + } + + /// + /// Calculated the smallest common multiple of 'a' and 'b'. + /// + private static long Scm(int n, int m) + { + return Math.Abs((long)n * (long)m) / Gcd(n, m); + } + + /// + /// Normalizes the fraction. + /// + private void Normalize() + { + if (denominator == 0) + { + numerator = 0; + denominator = 1; + return; + } + + if (numerator != 1 && denominator != 1) + { + int common = (int)Gcd(numerator, denominator); + if (common != 1 && common != 0) + { + numerator /= common; + denominator /= common; + } + } + + if (denominator < 0) + { + numerator *= -1; + denominator *= -1; + } + } + + /// + /// Normalizes a fraction. + /// + private static void Normalize(ref long numerator, ref long denominator) + { + if (denominator == 0) + { + numerator = 0; + denominator = 1; + } + else if (numerator != 1 && denominator != 1) + { + long common = Gcd(numerator, denominator); + if (common != 1) + { + numerator /= common; + denominator /= common; + } + } + if (denominator < 0) + { + numerator *= -1; + denominator *= -1; + } + } + + /// + /// Returns the digits after the point. + /// + private static int GetDigits(decimal value) + { + int result = 0; + value -= decimal.Truncate(value); + while (value != 0) + { + value *= 10; + value -= decimal.Truncate(value); + result++; + } + return result; + } + + /// + /// Creates a continued fraction of a decimal value. + /// + private static int[] CreateContinuedFraction(decimal value) + { + int precision = GetDigits(value); + decimal epsilon = 0.0000001m; + List list = new List(); + value = Math.Abs(value); + + byte b = 0; + + list.Add((int)value); + value -= ((int)value); + + while (value != 0m) + { + if (++b == byte.MaxValue || value < epsilon) + { + break; + } + value = 1m / value; + if (Math.Abs((Math.Round(value, precision - 1) - value)) < epsilon) + { + value = Math.Round(value, precision - 1); + } + list.Add((int)value); + value -= ((int)value); + } + return list.ToArray(); + } + + /// + /// Creates a fraction from a continued fraction. + /// + private static void CreateFraction(int[] continuedFraction, out int numerator, out int denominator) + { + numerator = 1; + denominator = 0; + int temp; + + for (int i = continuedFraction.Length - 1; i > -1; i--) + { + temp = numerator; + numerator = continuedFraction[i] * numerator + denominator; + denominator = temp; + } + } + + /// + /// Tries 'brute force' to approximate with a fraction. + /// + private static void ApproximateFraction(decimal value, int maxDen, out int num, out int den) + { + num = 0; + den = 0; + decimal bestDifference = 1m; + decimal currentDifference = -1m; + int digits = GetDigits(value); + + if (digits <= 9) + { + int mul = 1; + for (int i = 1; i <= digits; i++) + { + mul *= 10; + } + if (mul <= maxDen) + { + num = (int)(value * mul); + den = mul; + return; + } + } + + for (int i = 1; i <= maxDen; i++) + { + int numerator = (int)Math.Floor(value * (decimal)i + 0.5m); + currentDifference = Math.Abs(value - (decimal)numerator / (decimal)i); + if (currentDifference < bestDifference) + { + num = numerator; + den = i; + bestDifference = currentDifference; + } + } + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return ((IConvertible)this).ToDouble(null).ToString(); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIRational) && (this == ((FIRational)obj))); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + #region Operators + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator +(FIRational r1) + { + return r1; + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator -(FIRational r1) + { + r1.numerator *= -1; + return r1; + } + + /// + /// Returns the reciprocal value of this instance. + /// + public static FIRational operator ~(FIRational r1) + { + int temp = r1.denominator; + r1.denominator = r1.numerator; + r1.numerator = temp; + r1.Normalize(); + return r1; + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator ++(FIRational r1) + { + checked + { + r1.numerator += r1.denominator; + } + return r1; + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator --(FIRational r1) + { + checked + { + r1.numerator -= r1.denominator; + } + return r1; + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator +(FIRational r1, FIRational r2) + { + long numerator = 0; + long denominator = Scm(r1.denominator, r2.denominator); + numerator = (r1.numerator * (denominator / r1.denominator)) + (r2.numerator * (denominator / r2.denominator)); + Normalize(ref numerator, ref denominator); + checked + { + return new FIRational((int)numerator, (int)denominator); + } + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator -(FIRational r1, FIRational r2) + { + return r1 + (-r2); + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator *(FIRational r1, FIRational r2) + { + long numerator = r1.numerator * r2.numerator; + long denominator = r1.denominator * r2.denominator; + Normalize(ref numerator, ref denominator); + checked + { + return new FIRational((int)numerator, (int)denominator); + } + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator /(FIRational r1, FIRational r2) + { + int temp = r2.denominator; + r2.denominator = r2.numerator; + r2.numerator = temp; + return r1 * r2; + } + + /// + /// Standard implementation of the operator. + /// + public static FIRational operator %(FIRational r1, FIRational r2) + { + r2.Normalize(); + if (Math.Abs(r2.numerator) < r2.denominator) + return new FIRational(0, 0); + int div = (int)(r1 / r2); + return r1 - (r2 * div); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator ==(FIRational r1, FIRational r2) + { + r1.Normalize(); + r2.Normalize(); + return (r1.numerator == r2.numerator) && (r1.denominator == r2.denominator); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator !=(FIRational r1, FIRational r2) + { + return !(r1 == r2); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator >(FIRational r1, FIRational r2) + { + long denominator = Scm(r1.denominator, r2.denominator); + return (r1.numerator * (denominator / r1.denominator)) > (r2.numerator * (denominator / r2.denominator)); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator <(FIRational r1, FIRational r2) + { + long denominator = Scm(r1.denominator, r2.denominator); + return (r1.numerator * (denominator / r1.denominator)) < (r2.numerator * (denominator / r2.denominator)); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator >=(FIRational r1, FIRational r2) + { + long denominator = Scm(r1.denominator, r2.denominator); + return (r1.numerator * (denominator / r1.denominator)) >= (r2.numerator * (denominator / r2.denominator)); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator <=(FIRational r1, FIRational r2) + { + long denominator = Scm(r1.denominator, r2.denominator); + return (r1.numerator * (denominator / r1.denominator)) <= (r2.numerator * (denominator / r2.denominator)); + } + + #endregion + + #region Conversions + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator bool(FIRational value) + { + return (value.numerator != 0); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator byte(FIRational value) + { + return (byte)(double)value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator char(FIRational value) + { + return (char)(double)value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator decimal(FIRational value) + { + return value.denominator == 0 ? 0m : (decimal)value.numerator / (decimal)value.denominator; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator double(FIRational value) + { + return value.denominator == 0 ? 0d : (double)value.numerator / (double)value.denominator; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator short(FIRational value) + { + return (short)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator int(FIRational value) + { + return (int)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator long(FIRational value) + { + return (byte)(double)value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator float(FIRational value) + { + return value.denominator == 0 ? 0f : (float)value.numerator / (float)value.denominator; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator sbyte(FIRational value) + { + return (sbyte)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator ushort(FIRational value) + { + return (ushort)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator uint(FIRational value) + { + return (uint)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator ulong(FIRational value) + { + return (ulong)(double)value; + } + + // + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIRational(bool value) + { + return new FIRational(value ? 1 : 0, 1); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIRational(byte value) + { + return new FIRational(value, 1); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIRational(char value) + { + return new FIRational(value, 1); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIRational(decimal value) + { + return new FIRational(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIRational(double value) + { + return new FIRational((decimal)value); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator FIRational(short value) + { + return new FIRational(value, 1); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator FIRational(int value) + { + return new FIRational(value, 1); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static explicit operator FIRational(long value) + { + return new FIRational((int)value, 1); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIRational(sbyte value) + { + return new FIRational(value, 1); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIRational(float value) + { + return new FIRational((decimal)value); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator FIRational(ushort value) + { + return new FIRational(value, 1); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static explicit operator FIRational(uint value) + { + return new FIRational((int)value, 1); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static explicit operator FIRational(ulong value) + { + return new FIRational((int)value, 1); + } + + #endregion + + #region IConvertible Member + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Double; + } + + bool IConvertible.ToBoolean(IFormatProvider provider) + { + return (bool)this; + } + + byte IConvertible.ToByte(IFormatProvider provider) + { + return (byte)this; + } + + char IConvertible.ToChar(IFormatProvider provider) + { + return (char)this; + } + + DateTime IConvertible.ToDateTime(IFormatProvider provider) + { + return Convert.ToDateTime(((IConvertible)this).ToDouble(provider)); + } + + decimal IConvertible.ToDecimal(IFormatProvider provider) + { + return this; + } + + double IConvertible.ToDouble(IFormatProvider provider) + { + return this; + } + + short IConvertible.ToInt16(IFormatProvider provider) + { + return (short)this; + } + + int IConvertible.ToInt32(IFormatProvider provider) + { + return (int)this; + } + + long IConvertible.ToInt64(IFormatProvider provider) + { + return (long)this; + } + + sbyte IConvertible.ToSByte(IFormatProvider provider) + { + return (sbyte)this; + } + + float IConvertible.ToSingle(IFormatProvider provider) + { + return this; + } + + string IConvertible.ToString(IFormatProvider provider) + { + return ToString(((double)this).ToString(), provider); + } + + object IConvertible.ToType(Type conversionType, IFormatProvider provider) + { + return Convert.ChangeType(((IConvertible)this).ToDouble(provider), conversionType, provider); + } + + ushort IConvertible.ToUInt16(IFormatProvider provider) + { + return (ushort)this; + } + + uint IConvertible.ToUInt32(IFormatProvider provider) + { + return (uint)this; + } + + ulong IConvertible.ToUInt64(IFormatProvider provider) + { + return (ulong)this; + } + + #endregion + + #region IComparable Member + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIRational)) + { + throw new ArgumentException(); + } + return CompareTo((FIRational)obj); + } + + #endregion + + #region IFormattable Member + + /// + /// Formats the value of the current instance using the specified format. + /// + /// The String specifying the format to use. + /// The IFormatProvider to use to format the value. + /// A String containing the value of the current instance in the specified format. + public string ToString(string format, IFormatProvider formatProvider) + { + if (format == null) + { + format = ""; + } + return String.Format(formatProvider, format, ((IConvertible)this).ToDouble(formatProvider)); + } + + #endregion + + #region IEquatable Member + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FIRational other) + { + return (this == other); + } + + #endregion + + #region IComparable Member + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIRational other) + { + FIRational difference = this - other; + difference.Normalize(); + if (difference.numerator > 0) return 1; + if (difference.numerator < 0) return -1; + else return 0; + } + + #endregion + } +} + +namespace FreeImageAPI +{ + /// + /// The FIURational structure represents a fraction via two + /// instances which are interpreted as numerator and denominator. + /// + /// + /// The structure tries to approximate the value of + /// when creating a new instance by using a better algorithm than FreeImage does. + /// + /// The structure implements the following operators: + /// +, ++, --, ==, != , >, >==, <, <== and ~ (which switches nominator and denomiator). + /// + /// The structure can be converted into all .NET standard types either implicit or + /// explicit. + /// + [Serializable, StructLayout(LayoutKind.Sequential), ComVisible(true)] + public struct FIURational : IConvertible, IComparable, IFormattable, IComparable, IEquatable + { + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private uint numerator; + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private uint denominator; + + /// + /// Represents the largest possible value of . This field is constant. + /// + public static readonly FIURational MaxValue = new FIURational(UInt32.MaxValue, 1u); + + /// + /// Represents the smallest possible value of . This field is constant. + /// + public static readonly FIURational MinValue = new FIURational(0u, 1u); + + /// + /// Represents the smallest positive value greater than zero. This field is constant. + /// + public static readonly FIURational Epsilon = new FIURational(1u, UInt32.MaxValue); + + /// + /// Initializes a new instance based on the specified parameters. + /// + /// The numerator. + /// The denominator. + public FIURational(uint n, uint d) + { + numerator = n; + denominator = d; + Normalize(); + } + + /// + /// Initializes a new instance based on the specified parameters. + /// + /// The tag to read the data from. + public unsafe FIURational(FITAG tag) + { + switch (FreeImage.GetTagType(tag)) + { + case FREE_IMAGE_MDTYPE.FIDT_RATIONAL: + uint* pvalue = (uint*)FreeImage.GetTagValue(tag); + numerator = pvalue[0]; + denominator = pvalue[1]; + Normalize(); + return; + default: + throw new ArgumentException("tag"); + } + } + + /// + ///Initializes a new instance based on the specified parameters. + /// + /// The value to convert into a fraction. + /// + /// cannot be converted into a fraction + /// represented by two unsigned integer values. + public FIURational(decimal value) + { + try + { + if (value < 0) + { + throw new OverflowException("value"); + } + try + { + int[] contFract = CreateContinuedFraction(value); + CreateFraction(contFract, out numerator, out denominator); + Normalize(); + } + catch + { + numerator = 0; + denominator = 1; + } + if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) + { + int maxDen = (Int32.MaxValue / (int)value) - 2; + maxDen = maxDen < 10000 ? maxDen : 10000; + ApproximateFraction(value, maxDen, out numerator, out denominator); + Normalize(); + if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m) + { + throw new OverflowException("Unable to convert value into a fraction"); + } + } + Normalize(); + } + catch (Exception ex) + { + throw new OverflowException("Unable to calculate fraction.", ex); + } + } + + /// + /// The numerator of the fraction. + /// + public uint Numerator + { + get { return numerator; } + } + + /// + /// The denominator of the fraction. + /// + public uint Denominator + { + get { return denominator; } + } + + /// + /// Returns the truncated value of the fraction. + /// + /// + public int Truncate() + { + return denominator > 0 ? (int)(numerator / denominator) : 0; + } + + /// + /// Returns whether the fraction is representing an integer value. + /// + public bool IsInteger + { + get + { + return (denominator == 1 || + (denominator != 0 && (numerator % denominator == 0)) || + (denominator == 0 && numerator == 0)); + } + } + + /// + /// Calculated the greatest common divisor of 'a' and 'b'. + /// + private static ulong Gcd(ulong a, ulong b) + { + ulong r; + while (b > 0) + { + r = a % b; + a = b; + b = r; + } + return a; + } + + /// + /// Calculated the smallest common multiple of 'a' and 'b'. + /// + private static ulong Scm(uint n, uint m) + { + return (ulong)n * (ulong)m / Gcd(n, m); + } + + /// + /// Normalizes the fraction. + /// + private void Normalize() + { + if (denominator == 0) + { + numerator = 0; + denominator = 1; + return; + } + + if (numerator != 1 && denominator != 1) + { + uint common = (uint)Gcd(numerator, denominator); + if (common != 1 && common != 0) + { + numerator /= common; + denominator /= common; + } + } + } + + /// + /// Normalizes a fraction. + /// + private static void Normalize(ref ulong numerator, ref ulong denominator) + { + if (denominator == 0) + { + numerator = 0; + denominator = 1; + } + else if (numerator != 1 && denominator != 1) + { + ulong common = Gcd(numerator, denominator); + if (common != 1) + { + numerator /= common; + denominator /= common; + } + } + } + + /// + /// Returns the digits after the point. + /// + private static int GetDigits(decimal value) + { + int result = 0; + value -= decimal.Truncate(value); + while (value != 0) + { + value *= 10; + value -= decimal.Truncate(value); + result++; + } + return result; + } + + /// + /// Creates a continued fraction of a decimal value. + /// + private static int[] CreateContinuedFraction(decimal value) + { + int precision = GetDigits(value); + decimal epsilon = 0.0000001m; + List list = new List(); + value = Math.Abs(value); + + byte b = 0; + + list.Add((int)value); + value -= ((int)value); + + while (value != 0m) + { + if (++b == byte.MaxValue || value < epsilon) + { + break; + } + value = 1m / value; + if (Math.Abs((Math.Round(value, precision - 1) - value)) < epsilon) + { + value = Math.Round(value, precision - 1); + } + list.Add((int)value); + value -= ((int)value); + } + return list.ToArray(); + } + + /// + /// Creates a fraction from a continued fraction. + /// + private static void CreateFraction(int[] continuedFraction, out uint numerator, out uint denominator) + { + numerator = 1; + denominator = 0; + uint temp; + + for (int i = continuedFraction.Length - 1; i > -1; i--) + { + temp = numerator; + numerator = (uint)(continuedFraction[i] * numerator + denominator); + denominator = temp; + } + } + + /// + /// Tries 'brute force' to approximate with a fraction. + /// + private static void ApproximateFraction(decimal value, int maxDen, out uint num, out uint den) + { + num = 0; + den = 0; + decimal bestDifference = 1m; + decimal currentDifference = -1m; + int digits = GetDigits(value); + + if (digits <= 9) + { + uint mul = 1; + for (int i = 1; i <= digits; i++) + { + mul *= 10; + } + if (mul <= maxDen) + { + num = (uint)(value * mul); + den = mul; + return; + } + } + + for (uint u = 1; u <= maxDen; u++) + { + uint numerator = (uint)Math.Floor(value * (decimal)u + 0.5m); + currentDifference = Math.Abs(value - (decimal)numerator / (decimal)u); + if (currentDifference < bestDifference) + { + num = numerator; + den = u; + bestDifference = currentDifference; + } + } + } + + /// + /// Converts the numeric value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return ((IConvertible)this).ToDouble(null).ToString(); + } + + /// + /// Tests whether the specified object is a structure + /// and is equivalent to this structure. + /// + /// The object to test. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is FIURational) && (this == ((FIURational)obj))); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return base.GetHashCode(); + } + + #region Operators + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator +(FIURational value) + { + return value; + } + + /// + /// Returns the reciprocal value of this instance. + /// + public static FIURational operator ~(FIURational value) + { + uint temp = value.denominator; + value.denominator = value.numerator; + value.numerator = temp; + value.Normalize(); + return value; + } + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator ++(FIURational value) + { + checked + { + value.numerator += value.denominator; + } + return value; + } + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator --(FIURational value) + { + checked + { + value.numerator -= value.denominator; + } + return value; + } + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator +(FIURational left, FIURational right) + { + ulong numerator = 0; + ulong denominator = Scm(left.denominator, right.denominator); + numerator = (left.numerator * (denominator / left.denominator)) + + (right.numerator * (denominator / right.denominator)); + Normalize(ref numerator, ref denominator); + checked + { + return new FIURational((uint)numerator, (uint)denominator); + } + } + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator -(FIURational left, FIURational right) + { + checked + { + if (left.denominator != right.denominator) + { + uint denom = left.denominator; + left.numerator *= right.denominator; + left.denominator *= right.denominator; + right.numerator *= denom; + right.denominator *= denom; + } + left.numerator -= right.numerator; + left.Normalize(); + return left; + } + } + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator *(FIURational left, FIURational r2) + { + ulong numerator = left.numerator * r2.numerator; + ulong denominator = left.denominator * r2.denominator; + Normalize(ref numerator, ref denominator); + checked + { + return new FIURational((uint)numerator, (uint)denominator); + } + } + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator /(FIURational left, FIURational right) + { + uint temp = right.denominator; + right.denominator = right.numerator; + right.numerator = temp; + return left * right; + } + + /// + /// Standard implementation of the operator. + /// + public static FIURational operator %(FIURational left, FIURational right) + { + right.Normalize(); + if (Math.Abs(right.numerator) < right.denominator) + return new FIURational(0, 0); + int div = (int)(left / right); + return left - (right * div); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator ==(FIURational left, FIURational right) + { + left.Normalize(); + right.Normalize(); + return (left.numerator == right.numerator) && (left.denominator == right.denominator); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator !=(FIURational left, FIURational right) + { + left.Normalize(); + right.Normalize(); + return (left.numerator != right.numerator) || (left.denominator != right.denominator); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator >(FIURational left, FIURational right) + { + ulong denominator = Scm(left.denominator, right.denominator); + return (left.numerator * (denominator / left.denominator)) > + (right.numerator * (denominator / right.denominator)); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator <(FIURational left, FIURational right) + { + ulong denominator = Scm(left.denominator, right.denominator); + return (left.numerator * (denominator / left.denominator)) < + (right.numerator * (denominator / right.denominator)); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator >=(FIURational left, FIURational right) + { + ulong denominator = Scm(left.denominator, right.denominator); + return (left.numerator * (denominator / left.denominator)) >= + (right.numerator * (denominator / right.denominator)); + } + + /// + /// Standard implementation of the operator. + /// + public static bool operator <=(FIURational left, FIURational right) + { + ulong denominator = Scm(left.denominator, right.denominator); + return (left.numerator * (denominator / left.denominator)) <= + (right.numerator * (denominator / right.denominator)); + } + + #endregion + + #region Conversions + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator bool(FIURational value) + { + return (value.numerator != 0); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator byte(FIURational value) + { + return (byte)(double)value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator char(FIURational value) + { + return (char)(double)value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator decimal(FIURational value) + { + return value.denominator == 0 ? 0m : (decimal)value.numerator / (decimal)value.denominator; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator double(FIURational value) + { + return value.denominator == 0 ? 0d : (double)value.numerator / (double)value.denominator; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator short(FIURational value) + { + return (short)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator int(FIURational value) + { + return (int)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator long(FIURational value) + { + return (byte)(double)value; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator float(FIURational value) + { + return value.denominator == 0 ? 0f : (float)value.numerator / (float)value.denominator; + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator sbyte(FIURational value) + { + return (sbyte)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator ushort(FIURational value) + { + return (ushort)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator uint(FIURational value) + { + return (uint)(double)value; + } + + /// + /// Converts the value of a structure to an structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator ulong(FIURational value) + { + return (ulong)(double)value; + } + + // + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIURational(bool value) + { + return new FIURational(value ? 1u : 0u, 1u); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIURational(byte value) + { + return new FIURational(value, 1); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIURational(char value) + { + return new FIURational(value, 1); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIURational(decimal value) + { + return new FIURational(value); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIURational(double value) + { + return new FIURational((decimal)value); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator FIURational(short value) + { + return new FIURational((uint)value, 1u); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator FIURational(int value) + { + return new FIURational((uint)value, 1u); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static explicit operator FIURational(long value) + { + return new FIURational((uint)value, 1u); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static implicit operator FIURational(sbyte value) + { + return new FIURational((uint)value, 1u); + } + + /// + /// Converts the value of a structure to a structure. + /// + /// A structure. + /// A new instance of initialized to . + public static explicit operator FIURational(float value) + { + return new FIURational((decimal)value); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static implicit operator FIURational(ushort value) + { + return new FIURational(value, 1); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static explicit operator FIURational(uint value) + { + return new FIURational(value, 1u); + } + + /// + /// Converts the value of an structure to a structure. + /// + /// An structure. + /// A new instance of initialized to . + public static explicit operator FIURational(ulong value) + { + return new FIURational((uint)value, 1u); + } + + #endregion + + #region IConvertible Member + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Double; + } + + bool IConvertible.ToBoolean(IFormatProvider provider) + { + return (bool)this; + } + + byte IConvertible.ToByte(IFormatProvider provider) + { + return (byte)this; + } + + char IConvertible.ToChar(IFormatProvider provider) + { + return (char)this; + } + + DateTime IConvertible.ToDateTime(IFormatProvider provider) + { + return Convert.ToDateTime(((IConvertible)this).ToDouble(provider)); + } + + decimal IConvertible.ToDecimal(IFormatProvider provider) + { + return this; + } + + double IConvertible.ToDouble(IFormatProvider provider) + { + return this; + } + + short IConvertible.ToInt16(IFormatProvider provider) + { + return (short)this; + } + + int IConvertible.ToInt32(IFormatProvider provider) + { + return (int)this; + } + + long IConvertible.ToInt64(IFormatProvider provider) + { + return (long)this; + } + + sbyte IConvertible.ToSByte(IFormatProvider provider) + { + return (sbyte)this; + } + + float IConvertible.ToSingle(IFormatProvider provider) + { + return this; + } + + string IConvertible.ToString(IFormatProvider provider) + { + return ToString(((double)this).ToString(), provider); + } + + object IConvertible.ToType(Type conversionType, IFormatProvider provider) + { + return Convert.ChangeType(((IConvertible)this).ToDouble(provider), conversionType, provider); + } + + ushort IConvertible.ToUInt16(IFormatProvider provider) + { + return (ushort)this; + } + + uint IConvertible.ToUInt32(IFormatProvider provider) + { + return (uint)this; + } + + ulong IConvertible.ToUInt64(IFormatProvider provider) + { + return (ulong)this; + } + + #endregion + + #region IComparable Member + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is FIURational)) + { + throw new ArgumentException(); + } + return CompareTo((FIURational)obj); + } + + #endregion + + #region IFormattable Member + + /// + /// Formats the value of the current instance using the specified format. + /// + /// The String specifying the format to use. + /// The IFormatProvider to use to format the value. + /// A String containing the value of the current instance in the specified format. + public string ToString(string format, IFormatProvider formatProvider) + { + if (format == null) + { + format = ""; + } + return String.Format(formatProvider, format, ((IConvertible)this).ToDouble(formatProvider)); + } + + #endregion + + #region IEquatable Member + + /// + /// Tests whether the specified structure is equivalent to this structure. + /// + /// A structure to compare to this instance. + /// true if is a structure + /// equivalent to this structure; otherwise, false. + public bool Equals(FIURational other) + { + return (this == other); + } + + #endregion + + #region IComparable Member + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(FIURational other) + { + FIURational difference = this - other; + difference.Normalize(); + if (difference.numerator > 0) return 1; + if (difference.numerator < 0) return -1; + else return 0; + } + + #endregion + } +} + + #endregion + + #region Classes + +namespace FreeImageAPI +{ + /// + /// Encapsulates a FreeImage-bitmap. + /// + [Serializable, Guid("64a4c935-b757-499c-ab8c-6110316a9e51")] + public class FreeImageBitmap : MarshalByRefObject, ICloneable, IDisposable, IEnumerable, ISerializable + { + #region Fields + + /// + /// Indicates whether this instance is disposed. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool disposed; + + /// + /// Tab object. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private object tag; + + /// + /// Object used to syncronize lock methods. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private object lockObject = new object(); + + /// + /// Holds information used by SaveAdd() methods. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private SaveInformation saveInformation = new SaveInformation(); + + /// + /// The stream that this instance was loaded from or + /// null if it has been cloned or deserialized. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private Stream stream; + + /// + /// True if the stream must be disposed with this + /// instance. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool disposeStream; + + /// + /// The number of frames contained by a mutlipage bitmap. + /// Default value is 1 and only changed if needed. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private int frameCount = 1; + + /// + /// The index of the loaded frame. + /// Default value is 0 and only changed if needed. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private int frameIndex = 0; + + /// + /// Format of the sourceimage. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private FREE_IMAGE_FORMAT originalFormat = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + + /// + /// Handle to the encapsulated FreeImage-bitmap. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private FIBITMAP dib; + + private const string ErrorLoadingBitmap = "Unable to load bitmap."; + private const string ErrorLoadingFrame = "Unable to load frame."; + private const string ErrorCreatingBitmap = "Unable to create bitmap."; + private const string ErrorUnloadBitmap = "Unable to unload bitmap."; + + #endregion + + #region Constructors and Destructor + + /// + /// Initializes a new instance of the class. + /// + protected FreeImageBitmap() + { + } + + /// + /// Initializes a new instance of the class. + /// For internal use only. + /// + /// The operation failed. + internal protected FreeImageBitmap(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + this.dib = dib; + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image. + /// + /// The original to clone from. + /// The operation failed. + /// is a null reference. + public FreeImageBitmap(FreeImageBitmap original) + { + if (original == null) + { + throw new ArgumentNullException("original"); + } + original.EnsureNotDisposed(); + dib = FreeImage.Clone(original.dib); + if (dib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + originalFormat = original.originalFormat; + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image with the specified size. + /// + /// The original to clone from. + /// The Size structure that represent the + /// size of the new . + /// The operation failed. + /// is a null reference. + /// + /// or are less or equal zero. + /// + public FreeImageBitmap(FreeImageBitmap original, Size newSize) + : this(original, newSize.Width, newSize.Height) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image with the specified size. + /// + /// The original to clone from. + /// Width of the new . + /// Height of the new . + /// The operation failed. + /// is a null reference. + /// + /// or are less or equal zero. + public FreeImageBitmap(FreeImageBitmap original, int width, int height) + { + if (original == null) + { + throw new ArgumentNullException("original"); + } + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + original.EnsureNotDisposed(); + dib = FreeImage.Rescale(original.dib, width, height, FREE_IMAGE_FILTER.FILTER_BICUBIC); + if (dib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + originalFormat = original.originalFormat; + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image. + /// + /// The original to clone from. + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + public FreeImageBitmap(Image original) + : this(original as Bitmap) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image with the specified size. + /// + /// The original to clone from. + /// The Size structure that represent the + /// size of the new . + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + /// is a null reference. + /// + /// or are less or equal zero. + /// + public FreeImageBitmap(Image original, Size newSize) + : this(original as Bitmap, newSize.Width, newSize.Height) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image with the specified size. + /// + /// The original to clone from. + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + /// is a null reference. + /// + /// or are less or equal zero. + public FreeImageBitmap(Image original, int width, int height) + : this(original as Bitmap, width, height) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image. + /// + /// The original to clone from. + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// is a null reference. + /// The operation failed. + public FreeImageBitmap(Bitmap original) + { + if (original == null) + { + throw new ArgumentNullException("original"); + } + dib = FreeImage.CreateFromBitmap(original, true); + if (dib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + originalFormat = FreeImage.GetFormat(original.RawFormat); + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image with the specified size. + /// + /// The original to clone from. + /// The Size structure that represent the + /// size of the new . + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + /// is a null reference. + /// + /// or are less or equal zero. + /// + public FreeImageBitmap(Bitmap original, Size newSize) + : this(original, newSize.Width, newSize.Height) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified image with the specified size. + /// + /// The original to clone from. + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + /// is a null reference. + /// + /// or are less or equal zero. + public FreeImageBitmap(Bitmap original, int width, int height) + { + if (original == null) + { + throw new ArgumentNullException("original"); + } + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + FIBITMAP temp = FreeImage.CreateFromBitmap(original, true); + if (temp.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + dib = FreeImage.Rescale(temp, width, height, FREE_IMAGE_FILTER.FILTER_BICUBIC); + FreeImage.Unload(temp); + if (dib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + originalFormat = FreeImage.GetFormat(original.RawFormat); + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class + /// bases on the specified stream. + /// + /// Stream to read from. + /// Ignored. + /// The operation failed. + /// is a null reference. + /// + /// You must keep the stream open for the lifetime of the . + /// + public FreeImageBitmap(Stream stream, bool useIcm) + : this(stream) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified stream. + /// + /// Stream to read from. + /// The operation failed. + /// is a null reference. + /// + /// You must keep the stream open for the lifetime of the . + /// + public FreeImageBitmap(Stream stream) + : this(stream, FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_LOAD_FLAGS.DEFAULT) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified stream in the specified format. + /// + /// Stream to read from. + /// Format of the image. + /// The operation failed. + /// is a null reference. + /// + /// You must keep the stream open for the lifetime of the . + /// + public FreeImageBitmap(Stream stream, FREE_IMAGE_FORMAT format) + : this(stream, format, FREE_IMAGE_LOAD_FLAGS.DEFAULT) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified stream with the specified loading flags. + /// + /// Stream to read from. + /// Flags to enable or disable plugin-features. + /// The operation failed. + /// is a null reference. + /// + /// You must keep the stream open for the lifetime of the . + /// + public FreeImageBitmap(Stream stream, FREE_IMAGE_LOAD_FLAGS flags) + : this(stream, FREE_IMAGE_FORMAT.FIF_UNKNOWN, flags) + { + } + + /// + /// Initializes a new instance of the class + /// bases on the specified stream in the specified format + /// with the specified loading flags. + /// + /// Stream to read from. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// The operation failed. + /// is a null reference. + /// + /// You must keep the stream open for the lifetime of the . + /// + public FreeImageBitmap(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) + { + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + this.stream = stream; + disposeStream = false; + LoadFromStream(stream, format, flags); + } + + /// + /// Initializes a new instance of the class bases on the specified file. + /// + /// The complete name of the file to load. + /// The operation failed. + /// is a null reference. + /// does not exist. + public FreeImageBitmap(string filename) + : this(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT) + { + } + + /// + /// Initializes a new instance of the class bases on the specified file. + /// + /// The complete name of the file to load. + /// Ignored. + /// The operation failed. + /// is a null reference. + /// does not exist. + public FreeImageBitmap(string filename, bool useIcm) + : this(filename) + { + } + + /// + /// Initializes a new instance of the class bases on the specified file + /// with the specified loading flags. + /// + /// The complete name of the file to load. + /// Flags to enable or disable plugin-features. + /// The operation failed. + /// is a null reference. + /// does not exist. + public FreeImageBitmap(string filename, FREE_IMAGE_LOAD_FLAGS flags) + : this(filename, FREE_IMAGE_FORMAT.FIF_UNKNOWN, flags) + { + } + + /// + /// Initializes a new instance of the class bases on the specified file + /// in the specified format. + /// + /// The complete name of the file to load. + /// Format of the image. + /// The operation failed. + /// is a null reference. + /// does not exist. + public FreeImageBitmap(string filename, FREE_IMAGE_FORMAT format) + : this(filename, format, FREE_IMAGE_LOAD_FLAGS.DEFAULT) + { + } + + /// + /// Initializes a new instance of the class bases on the specified file + /// in the specified format with the specified loading flags. + /// + /// The complete name of the file to load. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// The operation failed. + /// is a null reference. + /// does not exist. + public FreeImageBitmap(string filename, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) + { + if (filename == null) + { + throw new ArgumentNullException("filename"); + } + if (!File.Exists(filename)) + { + throw new FileNotFoundException("filename"); + } + + saveInformation.filename = filename; + stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); + disposeStream = true; + LoadFromStream(stream, format, flags); + } + + /// + /// Initializes a new instance of the class + /// bases on the specified size. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// The operation failed. + public FreeImageBitmap(int width, int height) + { + dib = FreeImage.Allocate( + width, + height, + 24, + FreeImage.FI_RGBA_RED_MASK, + FreeImage.FI_RGBA_GREEN_MASK, + FreeImage.FI_RGBA_BLUE_MASK); + if (dib.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class bases on the specified resource. + /// + /// The class used to extract the resource. + /// The name of the resource. + /// The operation failed. + public FreeImageBitmap(Type type, string resource) + : this(type.Module.Assembly.GetManifestResourceStream(type, resource)) + { + } + + /// + /// Initializes a new instance of the class bases on the specified size + /// and with the resolution of the specified object. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// The Graphics object that specifies the resolution for the new . + /// The operation failed. + /// is a null reference. + public FreeImageBitmap(int width, int height, Graphics g) + : this(width, height) + { + FreeImage.SetResolutionX(dib, (uint)g.DpiX); + FreeImage.SetResolutionY(dib, (uint)g.DpiY); + } + + /// + /// Initializes a new instance of the class bases on the specified size and format. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// The PixelFormat enumeration for the new . + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + /// is invalid. + /// + /// or are less or equal zero. + public FreeImageBitmap(int width, int height, PixelFormat format) + { + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + uint bpp, redMask, greenMask, blueMask; + FREE_IMAGE_TYPE type; + if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask)) + { + throw new ArgumentException("format is invalid"); + } + dib = FreeImage.AllocateT(type, width, height, (int)bpp, redMask, greenMask, blueMask); + if (dib.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class bases on the specified size and type. + /// Only non standard bitmaps are supported. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// The type of the bitmap. + /// The operation failed. + /// + /// is FIT_BITMAP or FIT_UNKNOWN. + /// is invalid. + /// + /// or are less or equal zero. + public FreeImageBitmap(int width, int height, FREE_IMAGE_TYPE type) + { + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + if ((type == FREE_IMAGE_TYPE.FIT_BITMAP) || (type == FREE_IMAGE_TYPE.FIT_UNKNOWN)) + { + throw new ArgumentException("type is invalid."); + } + dib = FreeImage.AllocateT(type, width, height, 0, 0u, 0u, 0u); + if (dib.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class bases on the specified size, + /// pixel format and pixel data. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// Integer that specifies the byte offset between the beginning + /// of one scan line and the next. This is usually (but not necessarily) + /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) + /// multiplied by the width of the bitmap. The value passed to this parameter must + /// be a multiple of four.. + /// The PixelFormat enumeration for the new . + /// Pointer to an array of bytes that contains the pixel data. + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + /// is invalid. + /// + /// or are less or equal zero. + public FreeImageBitmap(int width, int height, int stride, PixelFormat format, IntPtr scan0) + { + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + uint bpp, redMask, greenMask, blueMask; + FREE_IMAGE_TYPE type; + bool topDown = (stride > 0); + stride = (stride > 0) ? stride : (stride * -1); + + if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask)) + { + throw new ArgumentException("format is invalid."); + } + + dib = FreeImage.ConvertFromRawBits( + scan0, type, width, height, stride, bpp, redMask, greenMask, blueMask, topDown); + + if (dib.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class bases on the specified size, + /// pixel format and pixel data. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// Integer that specifies the byte offset between the beginning + /// of one scan line and the next. This is usually (but not necessarily) + /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) + /// multiplied by the width of the bitmap. The value passed to this parameter must + /// be a multiple of four.. + /// The PixelFormat enumeration for the new . + /// Array of bytes containing the bitmap data. + /// + /// Although this constructor supports creating images in both formats + /// + /// and , bitmaps + /// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA + /// images respectively. Currently, there is no support for automatic premultiplying images in + /// . + /// + /// The operation failed. + /// is invalid. + /// + /// or are less or equal zero. + /// is null + public FreeImageBitmap(int width, int height, int stride, PixelFormat format, byte[] bits) + { + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + if (bits == null) + { + throw new ArgumentNullException("bits"); + } + uint bpp, redMask, greenMask, blueMask; + FREE_IMAGE_TYPE type; + bool topDown = (stride > 0); + stride = (stride > 0) ? stride : (stride * -1); + + if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask)) + { + throw new ArgumentException("format is invalid."); + } + + dib = FreeImage.ConvertFromRawBits( + bits, type, width, height, stride, bpp, redMask, greenMask, blueMask, topDown); + + if (dib.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class bases on the specified size, + /// pixel format and pixel data. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// Integer that specifies the byte offset between the beginning + /// of one scan line and the next. This is usually (but not necessarily) + /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) + /// multiplied by the width of the bitmap. The value passed to this parameter must + /// be a multiple of four.. + /// The color depth of the new + /// The type for the new . + /// Pointer to an array of bytes that contains the pixel data. + /// The operation failed. + /// is invalid. + /// + /// or are less or equal zero. + public FreeImageBitmap(int width, int height, int stride, int bpp, FREE_IMAGE_TYPE type, IntPtr scan0) + { + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + uint redMask, greenMask, blueMask; + bool topDown = (stride > 0); + stride = (stride > 0) ? stride : (stride * -1); + + if (!FreeImage.GetTypeParameters(type, bpp, out redMask, out greenMask, out blueMask)) + { + throw new ArgumentException("bpp and type are invalid or not supported."); + } + + dib = FreeImage.ConvertFromRawBits( + scan0, type, width, height, stride, (uint)bpp, redMask, greenMask, blueMask, topDown); + + if (dib.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class bases on the specified size, + /// pixel format and pixel data. + /// + /// The width, in pixels, of the new . + /// The height, in pixels, of the new . + /// Integer that specifies the byte offset between the beginning + /// of one scan line and the next. This is usually (but not necessarily) + /// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) + /// multiplied by the width of the bitmap. The value passed to this parameter must + /// be a multiple of four.. + /// The color depth of the new + /// The type for the new . + /// Array of bytes containing the bitmap data. + /// The operation failed. + /// is invalid. + /// + /// or are less or equal zero. + /// is null + public FreeImageBitmap(int width, int height, int stride, int bpp, FREE_IMAGE_TYPE type, byte[] bits) + { + if (width <= 0) + { + throw new ArgumentOutOfRangeException("width"); + } + if (height <= 0) + { + throw new ArgumentOutOfRangeException("height"); + } + if (bits == null) + { + throw new ArgumentNullException("bits"); + } + uint redMask, greenMask, blueMask; + bool topDown = (stride > 0); + stride = (stride > 0) ? stride : (stride * -1); + + if (!FreeImage.GetTypeParameters(type, bpp, out redMask, out greenMask, out blueMask)) + { + throw new ArgumentException("bpp and type are invalid or not supported."); + } + + dib = FreeImage.ConvertFromRawBits( + bits, type, width, height, stride, (uint)bpp, redMask, greenMask, blueMask, topDown); + + if (dib.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + AddMemoryPressure(); + } + + /// + /// Initializes a new instance of the class. + /// + /// The operation failed. + /// The operation failed. + public FreeImageBitmap(SerializationInfo info, StreamingContext context) + { + try + { + byte[] data = (byte[])info.GetValue("Bitmap Data", typeof(byte[])); + if ((data != null) && (data.Length > 0)) + { + MemoryStream memory = new MemoryStream(data); + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_TIFF; + dib = FreeImage.LoadFromStream(memory, ref format); + + if (dib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + + AddMemoryPressure(); + } + } + catch (Exception ex) + { + throw new SerializationException("Deserialization failed.", ex); + } + } + + /// + /// Frees all managed and unmanaged ressources. + /// + ~FreeImageBitmap() + { + Dispose(false); + } + + #endregion + + #region Operators + + /// + /// Converts a instance to a instance. + /// + /// A instance. + /// A new instance of initialized to . + /// + /// The explicit conversion from into Bitmap + /// allows to create an instance on the fly and use it as if + /// was a Bitmap. This way it can be directly used with a + /// PixtureBox for example without having to call any + /// conversion operations. + /// + public static explicit operator Bitmap(FreeImageBitmap value) + { + return value.ToBitmap(); + } + + /// + /// Converts a instance to a instance. + /// + /// A instance. + /// A new instance of initialized to . + /// + /// The explicit conversion from into + /// allows to create an instance on the fly to perform + /// image processing operations and converting it back. + /// + public static explicit operator FreeImageBitmap(Bitmap value) + { + return new FreeImageBitmap(value); + } + + /// + /// Determines whether two specified objects have the same value. + /// + /// A or a null reference (Nothing in Visual Basic). + /// A or a null reference (Nothing in Visual Basic). + /// + /// true if the value of left is the same as the value of right; otherwise, false. + /// + public static bool operator ==(FreeImageBitmap left, FreeImageBitmap right) + { + if (object.ReferenceEquals(left, right)) + { + return true; + } + else if (object.ReferenceEquals(left, null) || object.ReferenceEquals(right, null)) + { + return false; + } + else + { + left.EnsureNotDisposed(); + right.EnsureNotDisposed(); + return FreeImage.Compare(left.dib, right.dib, FREE_IMAGE_COMPARE_FLAGS.COMPLETE); + } + } + + /// + /// Determines whether two specified objects have different values. + /// + /// A or a null reference (Nothing in Visual Basic). + /// A or a null reference (Nothing in Visual Basic). + /// + /// true if the value of left is different from the value of right; otherwise, false. + /// + public static bool operator !=(FreeImageBitmap left, FreeImageBitmap right) + { + return (!(left == right)); + } + + #endregion + + #region Properties + + /// + /// Type of the bitmap. + /// + public FREE_IMAGE_TYPE ImageType + { + get + { + EnsureNotDisposed(); + return FreeImage.GetImageType(dib); + } + } + + /// + /// Number of palette entries. + /// + public int ColorsUsed + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetColorsUsed(dib); + } + } + + /// + /// The number of unique colors actually used by the bitmap. This might be different from + /// what ColorsUsed returns, which actually returns the palette size for palletised images. + /// Works for FIT_BITMAP type bitmaps only. + /// + public int UniqueColors + { + get + { + EnsureNotDisposed(); + return FreeImage.GetUniqueColors(dib); + } + } + + /// + /// The size of one pixel in the bitmap in bits. + /// + public int ColorDepth + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetBPP(dib); + } + } + + /// + /// Width of the bitmap in pixel units. + /// + public int Width + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetWidth(dib); + } + } + + /// + /// Height of the bitmap in pixel units. + /// + public int Height + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetHeight(dib); + } + } + + /// + /// Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary. + /// + public int Pitch + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetPitch(dib); + } + } + + /// + /// Size of the bitmap in memory. + /// + public int DataSize + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetDIBSize(dib); + } + } + + /// + /// Returns a structure that represents the palette of a FreeImage bitmap. + /// + /// is false. + public Palette Palette + { + get + { + EnsureNotDisposed(); + if (HasPalette) + { + return new Palette(dib); + } + throw new InvalidOperationException("This bitmap does not have a palette."); + } + } + + /// + /// Gets whether the bitmap is RGB 555. + /// + public bool IsRGB555 + { + get + { + EnsureNotDisposed(); + return FreeImage.IsRGB555(dib); + } + } + + /// + /// Gets whether the bitmap is RGB 565. + /// + public bool IsRGB565 + { + get + { + EnsureNotDisposed(); + return FreeImage.IsRGB565(dib); + } + } + + /// + /// Gets the horizontal resolution, in pixels per inch, of this . + /// + public float HorizontalResolution + { + get + { + EnsureNotDisposed(); + return (float)FreeImage.GetResolutionX(dib); + } + private set + { + EnsureNotDisposed(); + FreeImage.SetResolutionX(dib, (uint)value); + } + } + + /// + /// Gets the vertical resolution, in pixels per inch, of this . + /// + public float VerticalResolution + { + get + { + EnsureNotDisposed(); + return (float)FreeImage.GetResolutionY(dib); + } + private set + { + EnsureNotDisposed(); + FreeImage.SetResolutionY(dib, (uint)value); + } + } + + /// + /// Returns the structure of this . + /// + public BITMAPINFOHEADER InfoHeader + { + get + { + EnsureNotDisposed(); + return FreeImage.GetInfoHeaderEx(dib); + } + } + + /// + /// Returns the structure of a this . + /// + public BITMAPINFO Info + { + get + { + EnsureNotDisposed(); + return FreeImage.GetInfoEx(dib); + } + } + + /// + /// Investigates the color type of this + /// by reading the bitmaps pixel bits and analysing them. + /// + public FREE_IMAGE_COLOR_TYPE ColorType + { + get + { + EnsureNotDisposed(); + return FreeImage.GetColorType(dib); + } + } + + /// + /// Bit pattern describing the red color component of a pixel in this . + /// + public uint RedMask + { + get + { + EnsureNotDisposed(); + return FreeImage.GetRedMask(dib); + } + } + + /// + /// Bit pattern describing the green color component of a pixel in this . + /// + public uint GreenMask + { + get + { + EnsureNotDisposed(); + return FreeImage.GetGreenMask(dib); + } + } + + /// + /// Bit pattern describing the blue color component of a pixel in this . + /// + public uint BlueMask + { + get + { + EnsureNotDisposed(); + return FreeImage.GetBlueMask(dib); + } + } + + /// + /// Number of transparent colors in a palletised . + /// + public int TransparencyCount + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetTransparencyCount(dib); + } + } + + /// + /// Get or sets transparency table of this . + /// + public byte[] TransparencyTable + { + get + { + EnsureNotDisposed(); + return FreeImage.GetTransparencyTableEx(dib); + } + set + { + EnsureNotDisposed(); + FreeImage.SetTransparencyTable(dib, value); + } + } + + /// + /// Gets or sets whether this is transparent. + /// + public bool IsTransparent + { + get + { + EnsureNotDisposed(); + return FreeImage.IsTransparent(dib); + } + set + { + EnsureNotDisposed(); + FreeImage.SetTransparent(dib, value); + } + } + + /// + /// Gets whether this has a file background color. + /// + public bool HasBackgroundColor + { + get + { + EnsureNotDisposed(); + return FreeImage.HasBackgroundColor(dib); + } + } + + /// + /// Gets or sets the background color of this . + /// In case the value is null, the background color is removed. + /// + /// Get: There is no background color available. + /// Set: Setting background color failed. + public Color? BackgroundColor + { + get + { + EnsureNotDisposed(); + if (!FreeImage.HasBackgroundColor(dib)) + { + throw new InvalidOperationException("No background color available."); + } + RGBQUAD rgbq; + FreeImage.GetBackgroundColor(dib, out rgbq); + return rgbq.Color; + } + set + { + EnsureNotDisposed(); + if (!FreeImage.SetBackgroundColor(dib, (value.HasValue ? new RGBQUAD[] { value.Value } : null))) + { + throw new Exception("Setting background color failed."); + } + } + } + + /// + /// Pointer to the data-bits of this . + /// + public IntPtr Bits + { + get + { + EnsureNotDisposed(); + return FreeImage.GetBits(dib); + } + } + + /// + /// Width, in bytes, of this . + /// + public int Line + { + get + { + EnsureNotDisposed(); + return (int)FreeImage.GetLine(dib); + } + } + + /// + /// Pointer to the scanline of the top most pixel row of this . + /// + public IntPtr Scan0 + { + get + { + EnsureNotDisposed(); + return FreeImage.GetScanLine(dib, (int)(FreeImage.GetHeight(dib) - 1)); + } + } + + /// + /// Width, in bytes, of this . + /// In case this is top down Stride will be positive, else negative. + /// + public int Stride + { + get + { + return -Line; + } + } + + /// + /// Gets attribute flags for the pixel data of this . + /// + public unsafe int Flags + { + get + { + EnsureNotDisposed(); + int result = 0; + byte alpha; + int cd = ColorDepth; + + if ((cd == 32) || (FreeImage.GetTransparencyCount(dib) != 0)) + { + result += (int)ImageFlags.HasAlpha; + } + + if (cd == 32) + { + uint width = FreeImage.GetWidth(dib); + uint height = FreeImage.GetHeight(dib); + for (int y = 0; y < height; y++) + { + RGBQUAD* scanline = (RGBQUAD*)FreeImage.GetScanLine(dib, y); + for (int x = 0; x < width; x++) + { + alpha = scanline[x].Color.A; + if (alpha != byte.MinValue && alpha != byte.MaxValue) + { + result += (int)ImageFlags.HasTranslucent; + y = (int)height; + break; + } + } + } + } + else if (FreeImage.GetTransparencyCount(dib) != 0) + { + byte[] transTable = FreeImage.GetTransparencyTableEx(dib); + for (int i = 0; i < transTable.Length; i++) + { + if (transTable[i] != byte.MinValue && transTable[i] != byte.MaxValue) + { + result += (int)ImageFlags.HasTranslucent; + break; + } + } + } + + if (FreeImage.GetICCProfileEx(dib).IsCMYK) + { + result += (int)ImageFlags.ColorSpaceCmyk; + } + else + { + result += (int)ImageFlags.ColorSpaceRgb; + } + + if (FreeImage.GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_MINISBLACK || + FreeImage.GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_MINISWHITE) + { + result += (int)ImageFlags.ColorSpaceGray; + } + + if (originalFormat == FREE_IMAGE_FORMAT.FIF_BMP || + originalFormat == FREE_IMAGE_FORMAT.FIF_FAXG3 || + originalFormat == FREE_IMAGE_FORMAT.FIF_ICO || + originalFormat == FREE_IMAGE_FORMAT.FIF_JPEG || + originalFormat == FREE_IMAGE_FORMAT.FIF_PCX || + originalFormat == FREE_IMAGE_FORMAT.FIF_PNG || + originalFormat == FREE_IMAGE_FORMAT.FIF_PSD || + originalFormat == FREE_IMAGE_FORMAT.FIF_TIFF) + { + result += (int)ImageFlags.HasRealDpi; + } + + return result; + } + } + + /// + /// Gets the width and height of this . + /// + public SizeF PhysicalDimension + { + get + { + EnsureNotDisposed(); + return new SizeF((float)FreeImage.GetWidth(dib), (float)FreeImage.GetHeight(dib)); + } + } + + /// + /// Gets the pixel format for this . + /// + public PixelFormat PixelFormat + { + get + { + EnsureNotDisposed(); + return FreeImage.GetPixelFormat(dib); + } + } + + /// + /// Gets IDs of the property items stored in this . + /// + public int[] PropertyIdList + { + get + { + EnsureNotDisposed(); + List list = new List(); + ImageMetadata metaData = new ImageMetadata(dib, true); + + foreach (MetadataModel metadataModel in metaData) + { + foreach (MetadataTag metadataTag in metadataModel) + { + list.Add(metadataTag.ID); + } + } + + return list.ToArray(); + } + } + + /// + /// Gets all the property items (pieces of metadata) stored in this . + /// + public PropertyItem[] PropertyItems + { + get + { + EnsureNotDisposed(); + List list = new List(); + ImageMetadata metaData = new ImageMetadata(dib, true); + + foreach (MetadataModel metadataModel in metaData) + { + foreach (MetadataTag metadataTag in metadataModel) + { + list.Add(metadataTag.GetPropertyItem()); + } + } + + return list.ToArray(); + } + } + + /// + /// Gets the format of this . + /// + public ImageFormat RawFormat + { + get + { + EnsureNotDisposed(); + Attribute guidAttribute = + Attribute.GetCustomAttribute( + typeof(FreeImageBitmap), typeof(System.Runtime.InteropServices.GuidAttribute) + ); + return (guidAttribute == null) ? + null : + new ImageFormat(new Guid(((GuidAttribute)guidAttribute).Value)); + } + } + + /// + /// Gets the width and height, in pixels, of this . + /// + public Size Size + { + get + { + EnsureNotDisposed(); + return new Size(Width, Height); + } + } + + /// + /// Gets or sets an object that provides additional data about the . + /// + public Object Tag + { + get + { + EnsureNotDisposed(); + return tag; + } + set + { + EnsureNotDisposed(); + tag = value; + } + } + + /// + /// Gets whether this has been disposed. + /// + public bool IsDisposed + { + get + { + return disposed; + } + } + + /// + /// Gets a new instance of a metadata representing class. + /// + public ImageMetadata Metadata + { + get + { + EnsureNotDisposed(); + return new ImageMetadata(dib, true); + } + } + + /// + /// Gets or sets the comment of this . + /// Supported formats are JPEG, PNG and GIF. + /// + public string Comment + { + get + { + EnsureNotDisposed(); + return FreeImage.GetImageComment(dib); + } + set + { + EnsureNotDisposed(); + FreeImage.SetImageComment(dib, value); + } + } + + /// + /// Returns whether this has a palette. + /// + public bool HasPalette + { + get + { + EnsureNotDisposed(); + return (FreeImage.GetPalette(dib) != IntPtr.Zero); + } + } + + /// + /// Gets or sets the entry used as transparent color in this . + /// Only works for 1-, 4- and 8-bpp. + /// + public int TransparentIndex + { + get + { + EnsureNotDisposed(); + return FreeImage.GetTransparentIndex(dib); + } + set + { + EnsureNotDisposed(); + FreeImage.SetTransparentIndex(dib, value); + } + } + + /// + /// Gets the number of frames in this . + /// + public int FrameCount + { + get + { + EnsureNotDisposed(); + return frameCount; + } + } + + /// + /// Gets the ICCProfile structure of this . + /// + public FIICCPROFILE ICCProfile + { + get + { + EnsureNotDisposed(); + return FreeImage.GetICCProfileEx(dib); + } + } + + /// + /// Gets the format of the original image in case + /// this was loaded from a file or stream. + /// + public FREE_IMAGE_FORMAT ImageFormat + { + get + { + EnsureNotDisposed(); + return originalFormat; + } + } + + /// + /// Gets the encapsulated FIBITMAP. + /// + internal FIBITMAP Dib + { + get { EnsureNotDisposed(); return dib; } + } + + #endregion + + #region Methods + + /// + /// Gets the bounds of this in the specified unit. + /// + /// One of the values indicating + /// the unit of measure for the bounding rectangle. + /// The that represents the bounds of this + /// , in the specified unit. + public RectangleF GetBounds(ref GraphicsUnit pageUnit) + { + EnsureNotDisposed(); + pageUnit = GraphicsUnit.Pixel; + return new RectangleF( + 0f, + 0f, + (float)FreeImage.GetWidth(dib), + (float)FreeImage.GetHeight(dib)); + } + + /// + /// Gets the specified property item from this . + /// + /// The ID of the property item to get. + /// The this method gets. + public PropertyItem GetPropertyItem(int propid) + { + EnsureNotDisposed(); + ImageMetadata metadata = new ImageMetadata(dib, true); + foreach (MetadataModel metadataModel in metadata) + { + foreach (MetadataTag tag in metadataModel) + { + if (tag.ID == propid) + { + return tag.GetPropertyItem(); + } + } + } + return null; + } + + /// + /// Returns a thumbnail for this . + /// + /// The width, in pixels, of the requested thumbnail image. + /// The height, in pixels, of the requested thumbnail image. + /// Ignored. + /// Ignored. + /// A that represents the thumbnail. + public FreeImageBitmap GetThumbnailImage(int thumbWidth, int thumbHeight, + Image.GetThumbnailImageAbort callback, IntPtr callBackData) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.Rescale( + dib, thumbWidth, thumbHeight, FREE_IMAGE_FILTER.FILTER_BICUBIC); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Returns a thumbnail for this , keeping aspect ratio. + /// defines the maximum width or height + /// of the thumbnail. + /// + /// Thumbnail square size. + /// When true HDR images are transperantly + /// converted to standard images. + /// The thumbnail in a new instance. + public FreeImageBitmap GetThumbnailImage(int maxPixelSize, bool convert) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.MakeThumbnail(dib, maxPixelSize, convert); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Converts this instance to a instance. + /// + /// A new instance of initialized this instance. + public Bitmap ToBitmap() + { + EnsureNotDisposed(); + return FreeImage.GetBitmap(dib, true); + } + + /// + /// Returns an instance of , representing the scanline + /// specified by of this . + /// Since FreeImage bitmaps are always bottum up aligned, keep in mind that scanline 0 is the + /// bottom-most line of the image. + /// + /// Number of the scanline to retrieve. + /// An instance of representing the + /// th scanline. + /// + /// List of return-types of T: + /// + /// Color Depth / TypeResult Type + /// 1 () + /// 4 () + /// 8 () + /// 16 () + /// 16 - 555 () + /// 16 - 565 () + /// 24 () + /// 32 () + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// FreeImageBitmap bitmap = new FreeImageBitmap(@"C:\Pictures\picture.bmp"); + /// if (bitmap.ColorDepth == 32) + /// { + /// Scanline<RGBQUAD> scanline = bitmap.GetScanline<RGBQUAD>(0); + /// foreach (RGBQUAD pixel in scanline) + /// { + /// Console.WriteLine(pixel); + /// } + /// } + /// + /// + /// + /// The bitmap's type or color depth are not supported. + /// + /// + /// is no valid value. + /// + public Scanline GetScanline(int scanline) where T : struct + { + EnsureNotDisposed(); + return new Scanline(dib, scanline); + } + + /// + /// Returns an instance of , representing the scanline + /// specified by of this . + /// Since FreeImage bitmaps are always bottum up aligned, keep in mind that scanline 0 is the + /// bottom-most line of the image. + /// + /// Number of the scanline to retrieve. + /// An instance of representing the + /// th scanline. + /// + /// List of return-types of T: + /// + /// Color Depth / TypeResult Type + /// 1 () + /// 4 () + /// 8 () + /// 16 () + /// 16 - 555 () + /// 16 - 565 () + /// 24 () + /// 32 () + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// FreeImageBitmap bitmap = new FreeImageBitmap(@"C:\Pictures\picture.bmp"); + /// if (bitmap.ColorDepth == 32) + /// { + /// Scanline<RGBQUAD> scanline = (Scanline<RGBQUAD>)bitmap.GetScanline(0); + /// foreach (RGBQUAD pixel in scanline) + /// { + /// Console.WriteLine(pixel); + /// } + /// } + /// + /// + /// + /// The type of the bitmap or color depth are not supported. + /// + /// + /// is no valid value. + /// + public object GetScanline(int scanline) + { + EnsureNotDisposed(); + object result = null; + int width = (int)FreeImage.GetWidth(dib); + + switch (FreeImage.GetImageType(dib)) + { + case FREE_IMAGE_TYPE.FIT_BITMAP: + + switch (FreeImage.GetBPP(dib)) + { + case 1u: result = new Scanline(dib, scanline, width); break; + case 4u: result = new Scanline(dib, scanline, width); break; + case 8u: result = new Scanline(dib, scanline, width); break; + case 16u: + if ((RedMask == FreeImage.FI16_555_RED_MASK) && + (GreenMask == FreeImage.FI16_555_GREEN_MASK) && + (BlueMask == FreeImage.FI16_555_BLUE_MASK)) + { + result = new Scanline(dib, scanline, width); + } + else if ((RedMask == FreeImage.FI16_565_RED_MASK) && + (GreenMask == FreeImage.FI16_565_GREEN_MASK) && + (BlueMask == FreeImage.FI16_565_BLUE_MASK)) + { + result = new Scanline(dib, scanline, width); + } + else + { + result = new Scanline(dib, scanline, width); + } + break; + case 24u: result = new Scanline(dib, scanline, width); break; + case 32u: result = new Scanline(dib, scanline, width); break; + default: throw new ArgumentException("Color depth is not supported."); + } + break; + + case FREE_IMAGE_TYPE.FIT_COMPLEX: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_DOUBLE: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_FLOAT: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_INT16: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_INT32: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_RGB16: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_RGBA16: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_RGBAF: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_RGBF: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_UINT16: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_UINT32: result = new Scanline(dib, scanline, width); break; + case FREE_IMAGE_TYPE.FIT_UNKNOWN: + default: throw new ArgumentException("Type is not supported."); + } + + return result; + } + + /// + /// Returns a pointer to the specified scanline. + /// Due to FreeImage bitmaps are bottum up, + /// scanline 0 is the most bottom line of the image. + /// + /// Number of the scanline. + /// Pointer to the scanline. + public IntPtr GetScanlinePointer(int scanline) + { + EnsureNotDisposed(); + return FreeImage.GetScanLine(dib, scanline); + } + + /// + /// Returns a list of structures, representing the scanlines of this . + /// Due to FreeImage bitmaps are bottum up, scanline 0 is the + /// bottom-most line of the image. + /// Each color depth has a different representing structure due to different memory layouts. + /// + /// + /// List of return-types of T: + /// + /// Color Depth / TypeResult Type of IEnmuerable<Scanline<T>> + /// 1 () + /// 4 () + /// 8 () + /// 16 () + /// 16 - 555 () + /// 16 - 565 () + /// 24 () + /// 32 () + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public IList GetScanlines() + { + EnsureNotDisposed(); + + int height = (int)FreeImage.GetHeight(dib); + IList list; + + switch (FreeImage.GetImageType(dib)) + { + case FREE_IMAGE_TYPE.FIT_BITMAP: + + switch (FreeImage.GetBPP(dib)) + { + case 1u: list = new List>(height); break; + case 4u: list = new List>(height); break; + case 8u: list = new List>(height); break; + case 16u: + if (FreeImage.IsRGB555(dib)) + { + list = new List>(height); + } + else if (FreeImage.IsRGB565(dib)) + { + list = new List>(height); + } + else + { + list = new List>(height); + } + break; + case 24u: list = new List>(height); break; + case 32u: list = new List>(height); break; + default: throw new ArgumentException("Color depth is not supported."); + } + break; + + case FREE_IMAGE_TYPE.FIT_COMPLEX: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_DOUBLE: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_FLOAT: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_INT16: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_INT32: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_RGB16: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_RGBA16: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_RGBAF: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_RGBF: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_UINT16: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_UINT32: list = new List>(height); break; + case FREE_IMAGE_TYPE.FIT_UNKNOWN: + default: throw new ArgumentException("Type is not supported."); + } + + for (int i = 0; i < height; i++) + { + list.Add(GetScanline(i)); + } + + return list; + } + + /// + /// Removes the specified property item from this . + /// + /// The ID of the property item to remove. + public void RemovePropertyItem(int propid) + { + EnsureNotDisposed(); + ImageMetadata mdata = new ImageMetadata(dib, true); + foreach (MetadataModel model in mdata) + { + foreach (MetadataTag tag in model) + { + if (tag.ID == propid) + { + model.RemoveTag(tag.Key); + return; + } + } + } + } + + /// + /// This method rotates, flips, or rotates and flips this . + /// + /// A RotateFlipType member + /// that specifies the type of rotation and flip to apply to this . + public void RotateFlip(RotateFlipType rotateFlipType) + { + EnsureNotDisposed(); + + FIBITMAP newDib = new FIBITMAP(); + uint bpp = FreeImage.GetBPP(dib); + + switch (rotateFlipType) + { + case RotateFlipType.RotateNoneFlipX: + + FreeImage.FlipHorizontal(dib); + break; + + case RotateFlipType.RotateNoneFlipY: + + FreeImage.FlipVertical(dib); + break; + + case RotateFlipType.RotateNoneFlipXY: + + FreeImage.FlipHorizontal(dib); + FreeImage.FlipVertical(dib); + break; + + case RotateFlipType.Rotate90FlipNone: + + newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); + break; + + case RotateFlipType.Rotate90FlipX: + + newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); + FreeImage.FlipHorizontal(newDib); + break; + + case RotateFlipType.Rotate90FlipY: + + newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); + FreeImage.FlipVertical(newDib); + break; + + case RotateFlipType.Rotate90FlipXY: + + newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d); + FreeImage.FlipHorizontal(newDib); + FreeImage.FlipVertical(newDib); + break; + + case RotateFlipType.Rotate180FlipXY: + newDib = FreeImage.Clone(dib); + break; + } + ReplaceDib(newDib); + } + + /// + /// Copies the metadata from another . + /// + /// The bitmap to read the metadata from. + /// + /// is a null reference. + /// + public void CloneMetadataFrom(FreeImageBitmap bitmap) + { + if (bitmap == null) + { + throw new ArgumentNullException("bitmap"); + } + EnsureNotDisposed(); + bitmap.EnsureNotDisposed(); + FreeImage.CloneMetadata(dib, bitmap.dib); + } + + /// + /// Copies the metadata from another using + /// the provided options. + /// + /// The bitmap to read the metadata from. + /// Specifies the way the metadata is copied. + /// + /// is a null reference. + /// + public void CloneMetadataFrom(FreeImageBitmap bitmap, FREE_IMAGE_METADATA_COPY flags) + { + if (bitmap == null) + { + throw new ArgumentNullException("bitmap"); + } + EnsureNotDisposed(); + bitmap.EnsureNotDisposed(); + FreeImage.CloneMetadataEx(bitmap.dib, dib, flags); + } + + /// + /// Saves this to the specified file. + /// + /// A string that contains the name of the file to which + /// to save this . + /// is null or empty. + /// Saving the image failed. + public void Save(string filename) + { + Save(filename, FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + /// + /// Saves this to the specified file in the specified format. + /// + /// A string that contains the name of the file to which + /// to save this . + /// An that specifies the format of the saved image. + /// is null or empty. + /// Saving the image failed. + public void Save(string filename, FREE_IMAGE_FORMAT format) + { + Save(filename, format, FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + /// + /// Saves this to the specified file in the specified format + /// using the specified saving flags. + /// + /// A string that contains the name of the file to which + /// to save this . + /// An that specifies the format of the saved image. + /// Flags to enable or disable plugin-features. + /// is null or empty. + /// Saving the image failed. + public void Save(string filename, FREE_IMAGE_FORMAT format, FREE_IMAGE_SAVE_FLAGS flags) + { + EnsureNotDisposed(); + if (string.IsNullOrEmpty(filename)) + { + throw new ArgumentException("filename"); + } + if (!FreeImage.SaveEx(dib, filename, format, flags)) + { + throw new Exception("Unable to save bitmap"); + } + + saveInformation.filename = filename; + saveInformation.format = format; + saveInformation.saveFlags = flags; + } + + /// + /// Saves this to the specified stream in the specified format. + /// + /// The stream where this will be saved. + /// An that specifies the format of the saved image. + /// is a null reference. + /// Saving the image failed. + public void Save(Stream stream, FREE_IMAGE_FORMAT format) + { + Save(stream, format, FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + /// + /// Saves this to the specified stream in the specified format + /// using the specified saving flags. + /// + /// The stream where this will be saved. + /// An that specifies the format of the saved image. + /// Flags to enable or disable plugin-features. + /// is a null reference. + /// Saving the image failed. + public void Save(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_SAVE_FLAGS flags) + { + EnsureNotDisposed(); + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + if (!FreeImage.SaveToStream(dib, stream, format, flags)) + { + throw new Exception("Unable to save bitmap"); + } + + saveInformation.filename = null; + } + + /// + /// Adds a frame to the file specified in a previous call to the + /// method. + /// + /// + /// This instance has not been saved to a file using Save(...) before. + public void SaveAdd() + { + SaveAdd(this); + } + + /// + /// Adds a frame to the file specified in a previous call to the method. + /// + /// The position at which the frame should be inserted. + /// + /// This instance has not yet been saved to a file using the Save(...) method. + /// is out of range. + public void SaveAdd(int insertPosition) + { + SaveAdd(this, insertPosition); + } + + /// + /// Adds a frame to the file specified in a previous call to the method. + /// + /// A that contains the frame to add. + /// + /// This instance has not yet been saved to a file using the Save(...) method. + public void SaveAdd(FreeImageBitmap bitmap) + { + if (saveInformation.filename == null) + { + throw new InvalidOperationException("This operation requires a previous call of Save()."); + } + + SaveAdd( + saveInformation.filename, + bitmap, + saveInformation.format, + saveInformation.loadFlags, + saveInformation.saveFlags); + } + + /// + /// Adds a frame to the file specified in a previous call to the method. + /// + /// A that contains the frame to add. + /// The position at which the frame should be inserted. + /// + /// This instance has not yet been saved to a file using the Save(...) method. + /// is out of range. + public void SaveAdd(FreeImageBitmap bitmap, int insertPosition) + { + if (saveInformation.filename == null) + { + throw new InvalidOperationException("This operation requires a previous call of Save()."); + } + + SaveAdd( + saveInformation.filename, + bitmap, + insertPosition, + saveInformation.format, + saveInformation.loadFlags, + saveInformation.saveFlags); + } + + /// + /// Adds a frame to the file specified. + /// + /// File to add this frame to. + /// is a null reference. + /// does not exist. + /// Saving the image has failed. + public void SaveAdd(string filename) + { + SaveAdd( + filename, + this, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + FREE_IMAGE_LOAD_FLAGS.DEFAULT, + FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + /// + /// Adds a frame to the file specified. + /// + /// File to add this frame to. + /// The position at which the frame should be inserted. + /// is a null reference. + /// does not exist. + /// Saving the image has failed. + /// is out of range. + public void SaveAdd(string filename, int insertPosition) + { + SaveAdd( + filename, + this, + insertPosition, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + FREE_IMAGE_LOAD_FLAGS.DEFAULT, + FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + /// + /// Adds a frame to the file specified using the specified parameters. + /// + /// File to add this frame to. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// Flags to enable or disable plugin-features. + /// is a null reference. + /// does not exist. + /// Saving the image has failed. + public void SaveAdd( + string filename, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_LOAD_FLAGS loadFlags, + FREE_IMAGE_SAVE_FLAGS saveFlags) + { + SaveAdd( + filename, + this, + format, + loadFlags, + saveFlags); + } + + /// + /// Adds a frame to the file specified using the specified parameters. + /// + /// File to add this frame to. + /// The position at which the frame should be inserted. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// Flags to enable or disable plugin-features. + /// is a null reference. + /// does not exist. + /// Saving the image has failed. + /// is out of range. + public void SaveAdd( + string filename, + int insertPosition, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_LOAD_FLAGS loadFlags, + FREE_IMAGE_SAVE_FLAGS saveFlags) + { + SaveAdd( + filename, + this, + insertPosition, + format, + loadFlags, + saveFlags); + } + + /// + /// Selects the frame specified by the index. + /// + /// The index of the active frame. + /// + /// is out of range. + /// The operation failed. + /// The source of the bitmap is not available. + /// + public void SelectActiveFrame(int frameIndex) + { + EnsureNotDisposed(); + if ((frameIndex < 0) || (frameIndex >= frameCount)) + { + throw new ArgumentOutOfRangeException("frameIndex"); + } + + if (frameIndex != this.frameIndex) + { + if (stream == null) + { + throw new InvalidOperationException("No source available."); + } + + FREE_IMAGE_FORMAT format = originalFormat; + FIMULTIBITMAP mdib = FreeImage.OpenMultiBitmapFromStream(stream, ref format, saveInformation.loadFlags); + if (mdib.IsNull) + throw new Exception(ErrorLoadingBitmap); + + try + { + if (frameIndex >= FreeImage.GetPageCount(mdib)) + { + throw new ArgumentOutOfRangeException("frameIndex"); + } + + FIBITMAP newDib = FreeImage.LockPage(mdib, frameIndex); + if (newDib.IsNull) + { + throw new Exception(ErrorLoadingFrame); + } + + try + { + FIBITMAP clone = FreeImage.Clone(newDib); + if (clone.IsNull) + { + throw new Exception(ErrorCreatingBitmap); + } + ReplaceDib(clone); + } + finally + { + if (!newDib.IsNull) + { + FreeImage.UnlockPage(mdib, newDib, false); + } + } + } + finally + { + if (!FreeImage.CloseMultiBitmapEx(ref mdib)) + { + throw new Exception(ErrorUnloadBitmap); + } + } + + this.frameIndex = frameIndex; + } + } + + /// + /// Creates a GDI bitmap object from this . + /// + /// A handle to the GDI bitmap object that this method creates. + public IntPtr GetHbitmap() + { + EnsureNotDisposed(); + return FreeImage.GetHbitmap(dib, IntPtr.Zero, false); + } + + /// + /// Creates a GDI bitmap object from this . + /// + /// A structure that specifies the background color. + /// This parameter is ignored if the bitmap is totally opaque. + /// A handle to the GDI bitmap object that this method creates. + public IntPtr GetHbitmap(Color background) + { + EnsureNotDisposed(); + using (FreeImageBitmap temp = new FreeImageBitmap(this)) + { + temp.BackgroundColor = background; + return temp.GetHbitmap(); + } + } + + /// + /// Returns the handle to an icon. + /// + /// A Windows handle to an icon with the same image as this . + public IntPtr GetHicon() + { + EnsureNotDisposed(); + using (Bitmap bitmap = FreeImage.GetBitmap(dib, true)) + { + return bitmap.GetHicon(); + } + } + + /// + /// Creates a GDI bitmap object from this with the same + /// color depth as the primary device. + /// + /// A handle to the GDI bitmap object that this method creates. + public IntPtr GetHbitmapForDevice() + { + EnsureNotDisposed(); + return FreeImage.GetBitmapForDevice(dib, IntPtr.Zero, false); + } + + /// + /// Gets the of the specified pixel in this . + /// + /// The x-coordinate of the pixel to retrieve. + /// The y-coordinate of the pixel to retrieve. + /// A structure that represents the color of the specified pixel. + /// The operation failed. + /// The type of this bitmap is not supported. + public unsafe Color GetPixel(int x, int y) + { + EnsureNotDisposed(); + if (FreeImage.GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) + { + if (ColorDepth == 16 || ColorDepth == 24 || ColorDepth == 32) + { + RGBQUAD rgbq; + if (!FreeImage.GetPixelColor(dib, (uint)x, (uint)y, out rgbq)) + { + throw new Exception("FreeImage.GetPixelColor() failed"); + } + return rgbq.Color; + } + else if (ColorDepth == 1 || ColorDepth == 4 || ColorDepth == 8) + { + byte index; + if (!FreeImage.GetPixelIndex(dib, (uint)x, (uint)y, out index)) + { + throw new Exception("FreeImage.GetPixelIndex() failed"); + } + RGBQUAD* palette = (RGBQUAD*)FreeImage.GetPalette(dib); + return palette[index].Color; + } + } + throw new NotSupportedException("The type of the image is not supported"); + } + + /// + /// Makes the default transparent color transparent for this . + /// + public void MakeTransparent() + { + EnsureNotDisposed(); + MakeTransparent(Color.Transparent); + } + + /// + /// Makes the specified color transparent for this . + /// + /// The structure that represents + /// the color to make transparent. + /// + /// This method is not implemented. + public void MakeTransparent(Color transparentColor) + { + EnsureNotDisposed(); + throw new System.NotImplementedException(); + } + + /// + /// Sets the of the specified pixel in this . + /// + /// The x-coordinate of the pixel to set. + /// The y-coordinate of the pixel to set. + /// A structure that represents the color + /// to assign to the specified pixel. + /// The operation failed. + /// The type of this bitmap is not supported. + public unsafe void SetPixel(int x, int y, Color color) + { + EnsureNotDisposed(); + if (FreeImage.GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) + { + if (ColorDepth == 16 || ColorDepth == 24 || ColorDepth == 32) + { + RGBQUAD rgbq = color; + if (!FreeImage.SetPixelColor(dib, (uint)x, (uint)y, ref rgbq)) + { + throw new Exception("FreeImage.SetPixelColor() failed"); + } + return; + } + else if (ColorDepth == 1 || ColorDepth == 4 || ColorDepth == 8) + { + uint colorsUsed = FreeImage.GetColorsUsed(dib); + RGBQUAD* palette = (RGBQUAD*)FreeImage.GetPalette(dib); + for (int i = 0; i < colorsUsed; i++) + { + if (palette[i].Color == color) + { + byte index = (byte)i; + if (!FreeImage.SetPixelIndex(dib, (uint)x, (uint)y, ref index)) + { + throw new Exception("FreeImage.SetPixelIndex() failed"); + } + return; + } + } + throw new ArgumentOutOfRangeException("color"); + } + } + throw new NotSupportedException("The type of the image is not supported"); + } + + /// + /// Sets the resolution for this . + /// + /// The horizontal resolution, in dots per inch, of this . + /// The vertical resolution, in dots per inch, of this . + public void SetResolution(float xDpi, float yDpi) + { + EnsureNotDisposed(); + FreeImage.SetResolutionX(dib, (uint)xDpi); + FreeImage.SetResolutionY(dib, (uint)yDpi); + } + + /// + /// This function is not yet implemented. + /// + /// + /// This method is not implemented. + public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format) + { + throw new NotImplementedException(); + } + + /// + /// This function is not yet implemented. + /// + /// + /// This method is not implemented. + public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData) + { + throw new NotImplementedException(); + } + + /// + /// This function is not yet implemented. + /// + /// + /// This method is not implemented. + public void UnlockBits(BitmapData bitmapdata) + { + throw new NotImplementedException(); + } + + /// + /// Converts this into a different color depth. + /// The parameter specifies color depth, greyscale conversion + /// and palette reorder. + /// Adding the flag + /// will first perform a convesion to greyscale. This can be done with any target + /// color depth. + /// Adding the flag + /// will allow the algorithm to reorder the palette. This operation will not be performed to + /// non-greyscale images to prevent data loss by mistake. + /// + /// A bitfield containing information about the conversion + /// to perform. + /// Returns true on success, false on failure. + public bool ConvertColorDepth(FREE_IMAGE_COLOR_DEPTH bpp) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.ConvertColorDepth(dib, bpp, false)); + } + + /// + /// Converts this to + /// initializing a new instance. + /// In case source and destination type are the same, the operation fails. + /// An error message can be catched using the 'Message' event. + /// + /// Destination type. + /// True to scale linear, else false. + /// Returns true on success, false on failure. + public bool ConvertType(FREE_IMAGE_TYPE type, bool scaleLinear) + { + EnsureNotDisposed(); + return (ImageType == type) ? false : ReplaceDib(FreeImage.ConvertToType(dib, type, scaleLinear)); + } + + /// + /// Converts this to . + /// In case source and destination type are the same, the operation fails. + /// An error message can be catched using the 'Message' event. + /// + /// Destination type. + /// True to scale linear, else false. + /// The converted instance. + public FreeImageBitmap GetTypeConvertedInstance(FREE_IMAGE_TYPE type, bool scaleLinear) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + if (ImageType != type) + { + FIBITMAP newDib = FreeImage.ConvertToType(dib, type, scaleLinear); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + } + return result; + } + + /// + /// Converts this into a different color depth initializing + /// a new instance. + /// The parameter specifies color depth, greyscale conversion + /// and palette reorder. + /// Adding the flag will + /// first perform a convesion to greyscale. This can be done with any target color depth. + /// Adding the flag will + /// allow the algorithm to reorder the palette. This operation will not be performed to + /// non-greyscale images to prevent data loss by mistake. + /// + /// A bitfield containing information about the conversion + /// to perform. + /// The converted instance. + public FreeImageBitmap GetColorConvertedInstance(FREE_IMAGE_COLOR_DEPTH bpp) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.ConvertColorDepth(dib, bpp, false); + if (newDib == dib) + { + newDib = FreeImage.Clone(dib); + } + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Rescales this to the specified size using the + /// specified filter. + /// + /// The Size structure that represent the + /// size of the new . + /// Filter to use for resizing. + /// Returns true on success, false on failure. + public bool Rescale(Size newSize, FREE_IMAGE_FILTER filter) + { + return Rescale(newSize.Width, newSize.Height, filter); + } + + /// + /// Rescales this to the specified size using the + /// specified filter. + /// + /// Width of the new . + /// Height of the new . + /// Filter to use for resizing. + /// Returns true on success, false on failure. + public bool Rescale(int width, int height, FREE_IMAGE_FILTER filter) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.Rescale(dib, width, height, filter)); + } + + /// + /// Rescales this to the specified size using the + /// specified filter initializing a new instance. + /// + /// The Size structure that represent the + /// size of the new . + /// Filter to use for resizing. + /// The rescaled instance. + public FreeImageBitmap GetScaledInstance(Size newSize, FREE_IMAGE_FILTER filter) + { + return GetScaledInstance(newSize.Width, newSize.Height, filter); + } + + /// + /// Rescales this to the specified size using the + /// specified filter initializing a new instance. + /// + /// Width of the new . + /// Height of the new . + /// Filter to use for resizing. + /// The rescaled instance. + public FreeImageBitmap GetScaledInstance(int width, int height, FREE_IMAGE_FILTER filter) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.Rescale(dib, width, height, filter); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Enlarges or shrinks this selectively per side and fills + /// newly added areas with the specified background color. + /// See for further details. + /// + /// The type of the specified color. + /// The number of pixels, the image should be enlarged on its left side. + /// Negative values shrink the image on its left side. + /// The number of pixels, the image should be enlarged on its top side. + /// Negative values shrink the image on its top side. + /// The number of pixels, the image should be enlarged on its right side. + /// Negative values shrink the image on its right side. + /// The number of pixels, the image should be enlarged on its bottom side. + /// Negative values shrink the image on its bottom side. + /// The color, the enlarged sides of the image should be filled with. + /// true on success, false on failure. + public bool EnlargeCanvas(int left, int top, int right, int bottom, T? color) where T : struct + { + return EnlargeCanvas(left, top, right, bottom, color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT); + } + + /// + /// Enlarges or shrinks this selectively per side and fills + /// newly added areas with the specified background color. + /// See for further details. + /// + /// The type of the specified color. + /// The number of pixels, the image should be enlarged on its left side. + /// Negative values shrink the image on its left side. + /// The number of pixels, the image should be enlarged on its top side. + /// Negative values shrink the image on its top side. + /// The number of pixels, the image should be enlarged on its right side. + /// Negative values shrink the image on its right side. + /// The number of pixels, the image should be enlarged on its bottom side. + /// Negative values shrink the image on its bottom side. + /// The color, the enlarged sides of the image should be filled with. + /// Options that affect the color search process for palletized images. + /// true on success, false on failure. + public bool EnlargeCanvas(int left, int top, int right, int bottom, + T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.EnlargeCanvas(dib, left, top, right, bottom, color, options)); + } + + /// + /// Enlarges or shrinks this selectively per side and fills + /// newly added areas with the specified background color returning a new instance. + /// See for further details. + /// + /// The type of the specified color. + /// The number of pixels, the image should be enlarged on its left side. + /// Negative values shrink the image on its left side. + /// The number of pixels, the image should be enlarged on its top side. + /// Negative values shrink the image on its top side. + /// The number of pixels, the image should be enlarged on its right side. + /// Negative values shrink the image on its right side. + /// The number of pixels, the image should be enlarged on its bottom side. + /// Negative values shrink the image on its bottom side. + /// The color, the enlarged sides of the image should be filled with. + /// The enlarged instance. + public FreeImageBitmap GetEnlargedInstance(int left, int top, int right, int bottom, + T? color) where T : struct + { + return GetEnlargedInstance(left, top, right, bottom, color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT); + } + + /// + /// Enlarges or shrinks this selectively per side and fills + /// newly added areas with the specified background color returning a new instance. + /// See for further details. + /// + /// The type of the specified color. + /// The number of pixels, the image should be enlarged on its left side. + /// Negative values shrink the image on its left side. + /// The number of pixels, the image should be enlarged on its top side. + /// Negative values shrink the image on its top side. + /// The number of pixels, the image should be enlarged on its right side. + /// Negative values shrink the image on its right side. + /// The number of pixels, the image should be enlarged on its bottom side. + /// Negative values shrink the image on its bottom side. + /// The color, the enlarged sides of the image should be filled with. + /// Options that affect the color search process for palletized images. + /// The enlarged instance. + public FreeImageBitmap GetEnlargedInstance(int left, int top, int right, int bottom, + T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.EnlargeCanvas(dib, left, top, right, bottom, color, options); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Quantizes this from 24 bit to 8bit creating a new + /// palette with the specified using the specified + /// . + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// Returns true on success, false on failure. + public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize) + { + return Quantize(algorithm, paletteSize, 0, (RGBQUAD[])null); + } + + /// + /// Quantizes this from 24 bit to 8bit creating a new + /// palette with the specified using the specified + /// and the specified + /// palette up to the + /// specified length. + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// The provided palette. + /// Returns true on success, false on failure. + public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, Palette reservePalette) + { + return Quantize(algorithm, paletteSize, reservePalette.Length, reservePalette.Data); + } + + /// + /// Quantizes this from 24 bit to 8bit creating a new + /// palette with the specified using the specified + /// and the specified + /// palette up to the + /// specified length. + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// Size of the provided palette of ReservePalette. + /// The provided palette. + /// Returns true on success, false on failure. + public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, Palette reservePalette) + { + return Quantize(algorithm, paletteSize, reserveSize, reservePalette.Data); + } + + /// + /// Quantizes this from 24 bit to 8bit creating a new + /// palette with the specified using the specified + /// and the specified + /// palette up to the + /// specified length. + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// Size of the provided palette of ReservePalette. + /// The provided palette. + /// Returns true on success, false on failure. + public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, RGBQUAD[] reservePalette) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.ColorQuantizeEx(dib, algorithm, paletteSize, reserveSize, reservePalette)); + } + + /// + /// Quantizes this from 24 bit, using the specified + /// initializing a new 8 bit instance with the + /// specified . + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// The quantized instance. + public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize) + { + return GetQuantizedInstance(algorithm, paletteSize, 0, (RGBQUAD[])null); + } + + /// + /// Quantizes this from 24 bit, using the specified + /// and palette + /// initializing a new 8 bit instance with the specified . + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// The provided palette. + /// The quantized instance. + public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, Palette reservePalette) + { + return GetQuantizedInstance(algorithm, paletteSize, reservePalette.Length, reservePalette); + } + + /// + /// Quantizes this from 24 bit, using the specified + /// and up to + /// entries from palette initializing + /// a new 8 bit instance with the specified . + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// Size of the provided palette. + /// The provided palette. + /// The quantized instance. + public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, Palette reservePalette) + { + return GetQuantizedInstance(algorithm, paletteSize, reserveSize, reservePalette.Data); + } + + /// + /// Quantizes this from 24 bit, using the specified + /// and up to + /// entries from palette initializing + /// a new 8 bit instance with the specified . + /// + /// The color reduction algorithm to be used. + /// Size of the desired output palette. + /// Size of the provided palette. + /// The provided palette. + /// The quantized instance. + public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, RGBQUAD[] reservePalette) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.ColorQuantizeEx(dib, algorithm, paletteSize, reserveSize, reservePalette); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Converts a High Dynamic Range image to a 24-bit RGB image using a global + /// operator based on logarithmic compression of luminance values, imitating + /// the human response to light. + /// + /// A gamma correction that is applied after the tone mapping. + /// A value of 1 means no correction. + /// Scale factor allowing to adjust the brightness of the output image. + /// Returns true on success, false on failure. + public bool TmoDrago03(double gamma, double exposure) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.TmoDrago03(dib, gamma, exposure)); + } + + /// + /// Converts a High Dynamic Range image to a 24-bit RGB image using a global operator inspired + /// by photoreceptor physiology of the human visual system. + /// + /// Controls the overall image intensity in the range [-8, 8]. + /// Controls the overall image contrast in the range [0.3, 1.0[. + /// Returns true on success, false on failure. + public bool TmoReinhard05(double intensity, double contrast) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.TmoReinhard05(dib, intensity, contrast)); + } + + /// + /// Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and convert to 24-bit RGB. + /// + /// Color saturation (s parameter in the paper) in [0.4..0.6] + /// Atenuation factor (beta parameter in the paper) in [0.8..0.9] + /// Returns true on success, false on failure. + public bool TmoFattal02(double color_saturation, double attenuation) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.TmoFattal02(dib, color_saturation, attenuation)); + } + + /// + /// This method rotates a 1-, 4-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. + /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer + /// multiple of 90. + /// + /// The angle of rotation. + /// Returns true on success, false on failure. + public bool Rotate(double angle) + { + EnsureNotDisposed(); + bool result = false; + if (ColorDepth == 4) + { + result = ReplaceDib(FreeImage.Rotate4bit(dib, angle)); + } + else + { + result = ReplaceDib(FreeImage.Rotate(dib, angle)); + } + return result; + } + + /// + /// This method rotates a 1-, 4-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. + /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer + /// multiple of 90. + /// + /// The type of the color to use as background. + /// The angle of rotation. + /// The color used used to fill the bitmap's background. + /// Returns true on success, false on failure. + public bool Rotate(double angle, T? backgroundColor) where T : struct + { + EnsureNotDisposed(); + bool result = false; + if (ColorDepth == 4) + { + result = ReplaceDib(FreeImage.Rotate4bit(dib, angle)); + } + else + { + result = ReplaceDib(FreeImage.Rotate(dib, angle, backgroundColor)); + } + return result; + } + + /// + /// Rotates this by the specified angle initializing a new instance. + /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer + /// multiple of 90. + /// + /// The type of the color to use as background. + /// The angle of rotation. + /// The color used used to fill the bitmap's background. + /// The rotated instance. + public FreeImageBitmap GetRotatedInstance(double angle, T? backgroundColor) where T : struct + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib; + if (ColorDepth == 4) + { + newDib = FreeImage.Rotate4bit(dib, angle); + } + else + { + newDib = FreeImage.Rotate(dib, angle, backgroundColor); + } + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Rotates this by the specified angle initializing a new instance. + /// For 1- and 4-bit images, rotation is limited to angles whose value is an integer + /// multiple of 90. + /// + /// The angle of rotation. + /// The rotated instance. + public FreeImageBitmap GetRotatedInstance(double angle) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib; + if (ColorDepth == 4) + { + newDib = FreeImage.Rotate4bit(dib, angle); + } + else + { + newDib = FreeImage.Rotate(dib, angle); + } + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// This method performs a rotation and / or translation of an 8-bit greyscale, + /// 24- or 32-bit image, using a 3rd order (cubic) B-Spline. + /// + /// The angle of rotation. + /// Horizontal image translation. + /// Vertical image translation. + /// Rotation center x-coordinate. + /// Rotation center y-coordinate. + /// When true the irrelevant part of the image is set to a black color, + /// otherwise, a mirroring technique is used to fill irrelevant pixels. + /// Returns true on success, false on failure. + public bool Rotate(double angle, double xShift, double yShift, + double xOrigin, double yOrigin, bool useMask) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.RotateEx(dib, angle, xShift, yShift, xOrigin, yOrigin, useMask)); + } + + /// + /// This method performs a rotation and / or translation of an 8-bit greyscale, + /// 24- or 32-bit image, using a 3rd order (cubic) B-Spline initializing a new instance. + /// + /// The angle of rotation. + /// Horizontal image translation. + /// Vertical image translation. + /// Rotation center x-coordinate. + /// Rotation center y-coordinate. + /// When true the irrelevant part of the image is set to a black color, + /// otherwise, a mirroring technique is used to fill irrelevant pixels. + /// The rotated instance. + public FreeImageBitmap GetRotatedInstance(double angle, double xShift, double yShift, + double xOrigin, double yOrigin, bool useMask) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.RotateEx( + dib, angle, xShift, yShift, xOrigin, yOrigin, useMask); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Perfoms an histogram transformation on a 8-, 24- or 32-bit image. + /// + /// The lookup table (LUT). + /// It's size is assumed to be 256 in length. + /// The color channel to be transformed. + /// Returns true on success, false on failure. + public bool AdjustCurve(byte[] lookUpTable, FREE_IMAGE_COLOR_CHANNEL channel) + { + EnsureNotDisposed(); + return FreeImage.AdjustCurve(dib, lookUpTable, channel); + } + + /// + /// Performs gamma correction on a 8-, 24- or 32-bit image. + /// + /// The parameter represents the gamma value to use (gamma > 0). + /// A value of 1.0 leaves the image alone, less than one darkens it, and greater than one lightens it. + /// Returns true on success, false on failure. + public bool AdjustGamma(double gamma) + { + EnsureNotDisposed(); + return FreeImage.AdjustGamma(dib, gamma); + } + + /// + /// Adjusts the brightness of a 8-, 24- or 32-bit image by a certain amount. + /// + /// A value 0 means no change, + /// less than 0 will make the image darker and greater than 0 will make the image brighter. + /// Returns true on success, false on failure. + public bool AdjustBrightness(double percentage) + { + EnsureNotDisposed(); + return FreeImage.AdjustBrightness(dib, percentage); + } + + /// + /// Adjusts the contrast of a 8-, 24- or 32-bit image by a certain amount. + /// + /// A value 0 means no change, + /// less than 0 will decrease the contrast and greater than 0 will increase the contrast of the image. + /// Returns true on success, false on failure. + public bool AdjustContrast(double percentage) + { + EnsureNotDisposed(); + return FreeImage.AdjustContrast(dib, percentage); + } + + /// + /// Inverts each pixel data. + /// + /// Returns true on success, false on failure. + public bool Invert() + { + EnsureNotDisposed(); + return FreeImage.Invert(dib); + } + + /// + /// Computes the image histogram. + /// + /// Channel to compute from. + /// Array of integers containing the histogram. + /// Returns true on success, false on failure. + public bool GetHistogram(FREE_IMAGE_COLOR_CHANNEL channel, out int[] histogram) + { + EnsureNotDisposed(); + histogram = new int[256]; + return FreeImage.GetHistogram(dib, histogram, channel); + } + + /// + /// Retrieves the red, green, blue or alpha channel of a 24- or 32-bit image. + /// + /// The color channel to extract. + /// The color channel in a new instance. + public FreeImageBitmap GetChannel(FREE_IMAGE_COLOR_CHANNEL channel) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.GetChannel(dib, channel); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Insert a 8-bit dib into a 24- or 32-bit image. + /// Both images must have to same width and height. + /// + /// The to insert. + /// The color channel to replace. + /// Returns true on success, false on failure. + public bool SetChannel(FreeImageBitmap bitmap, FREE_IMAGE_COLOR_CHANNEL channel) + { + EnsureNotDisposed(); + bitmap.EnsureNotDisposed(); + return FreeImage.SetChannel(dib, bitmap.dib, channel); + } + + /// + /// Retrieves the real part, imaginary part, magnitude or phase of a complex image. + /// + /// The color channel to extract. + /// The color channel in a new instance. + public FreeImageBitmap GetComplexChannel(FREE_IMAGE_COLOR_CHANNEL channel) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.GetComplexChannel(dib, channel); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Set the real or imaginary part of a complex image. + /// Both images must have to same width and height. + /// + /// The to insert. + /// The color channel to replace. + /// Returns true on success, false on failure. + public bool SetComplexChannel(FreeImageBitmap bitmap, FREE_IMAGE_COLOR_CHANNEL channel) + { + EnsureNotDisposed(); + bitmap.EnsureNotDisposed(); + return FreeImage.SetComplexChannel(dib, bitmap.dib, channel); + } + + /// + /// Copy a sub part of this . + /// + /// The subpart to copy. + /// The sub part in a new instance. + public FreeImageBitmap Copy(Rectangle rect) + { + EnsureNotDisposed(); + return Copy(rect.Left, rect.Top, rect.Right, rect.Bottom); + } + + /// + /// Copy a sub part of this . + /// + /// Specifies the left position of the cropped rectangle. + /// Specifies the top position of the cropped rectangle. + /// Specifies the right position of the cropped rectangle. + /// Specifies the bottom position of the cropped rectangle. + /// The sub part in a new instance. + public FreeImageBitmap Copy(int left, int top, int right, int bottom) + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.Copy(dib, left, top, right, bottom); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Alpha blend or combine a sub part image with this . + /// The bit depth of must be greater than or equal to the bit depth this instance. + /// + /// The to paste into this instance. + /// Specifies the left position of the sub image. + /// Specifies the top position of the sub image. + /// alpha blend factor. + /// The source and destination images are alpha blended if alpha=0..255. + /// If alpha > 255, then the source image is combined to the destination image. + /// Returns true on success, false on failure. + public bool Paste(FreeImageBitmap bitmap, int left, int top, int alpha) + { + EnsureNotDisposed(); + bitmap.EnsureNotDisposed(); + return FreeImage.Paste(dib, bitmap.dib, left, top, alpha); + } + + /// + /// Alpha blend or combine a sub part image with tthis . + /// The bit depth of must be greater than or equal to the bit depth this instance. + /// + /// The to paste into this instance. + /// Specifies the position of the sub image. + /// alpha blend factor. + /// The source and destination images are alpha blended if alpha=0..255. + /// If alpha > 255, then the source image is combined to the destination image. + /// Returns true on success, false on failure. + public bool Paste(FreeImageBitmap bitmap, Point point, int alpha) + { + EnsureNotDisposed(); + return Paste(bitmap, point.X, point.Y, alpha); + } + + /// + /// This method composite a transparent foreground image against a single background color or + /// against a background image. + /// In case is false and + /// and + /// are null, a checkerboard will be used as background. + /// + /// When true the background of this instance is used + /// if it contains one. + /// Backgroundcolor used in case is false + /// and is not null. + /// Background used in case + /// is false and is a null reference. + /// Returns true on success, false on failure. + public bool Composite(bool useBitmapBackground, Color? applicationBackground, FreeImageBitmap bitmapBackGround) + { + EnsureNotDisposed(); + bitmapBackGround.EnsureNotDisposed(); + RGBQUAD? rgb = applicationBackground; + return ReplaceDib( + FreeImage.Composite( + dib, + useBitmapBackground, + rgb.HasValue ? new RGBQUAD[] { rgb.Value } : null, + bitmapBackGround.dib)); + } + + /// + /// Applies the alpha value of each pixel to its color components. + /// The aplha value stays unchanged. + /// Only works with 32-bits color depth. + /// + /// Returns true on success, false on failure. + public bool PreMultiplyWithAlpha() + { + EnsureNotDisposed(); + return FreeImage.PreMultiplyWithAlpha(dib); + } + + /// + /// Solves a Poisson equation, remap result pixels to [0..1] and returns the solution. + /// + /// Number of cycles in the multigrid algorithm (usually 2 or 3) + /// Returns true on success, false on failure. + public bool MultigridPoissonSolver(int ncycle) + { + EnsureNotDisposed(); + return ReplaceDib(FreeImage.MultigridPoissonSolver(dib, ncycle)); + } + + /// + /// Adjusts an image's brightness, contrast and gamma as well as it may + /// optionally invert the image within a single operation. + /// + /// Percentage brightness value where -100 <= brightness <= 100. + /// A value of 0 means no change, less than 0 will make the image darker and greater + /// than 0 will make the image brighter. + /// Percentage contrast value where -100 <= contrast <= 100. + /// A value of 0 means no change, less than 0 will decrease the contrast + /// and greater than 0 will increase the contrast of the image. + /// Gamma value to be used for gamma correction. + /// A value of 1.0 leaves the image alone, less than one darkens it, + /// and greater than one lightens it. + /// This parameter must not be zero or smaller than zero. + /// If so, it will be ignored and no gamma correction will be performed on the image. + /// If set to true, the image will be inverted. + /// Returns true on success, false on failure. + public bool AdjustColors(double brightness, double contrast, double gamma, bool invert) + { + EnsureNotDisposed(); + return FreeImage.AdjustColors(dib, brightness, contrast, gamma, invert); + } + + /// + /// Applies color mapping for one or several colors on a 1-, 4- or 8-bit + /// palletized or a 16-, 24- or 32-bit high color image. + /// + /// Array of colors to be used as the mapping source. + /// Array of colors to be used as the mapping destination. + /// If true, 32-bit images and colors are treated as 24-bit. + /// If true, source and destination colors are swapped, that is, + /// each destination color is also mapped to the corresponding source color. + /// The total number of pixels changed. + /// + /// or is a null reference. + /// + /// + /// has a different length than . + /// + public uint ApplyColorMapping(RGBQUAD[] srccolors, RGBQUAD[] dstcolors, bool ignore_alpha, bool swap) + { + EnsureNotDisposed(); + if (srccolors == null) + { + throw new ArgumentNullException("srccolors"); + } + if (dstcolors == null) + { + throw new ArgumentNullException("dstcolors"); + } + if (srccolors.Length != dstcolors.Length) + { + throw new ArgumentException("srccolors and dstcolors must have the same length."); + } + return FreeImage.ApplyColorMapping(dib, srccolors, dstcolors, (uint)srccolors.Length, ignore_alpha, swap); + } + + /// + /// Swaps two specified colors on a 1-, 4- or 8-bit palletized + /// or a 16-, 24- or 32-bit high color image. + /// + /// One of the two colors to be swapped. + /// The other of the two colors to be swapped. + /// If true, 32-bit images and colors are treated as 24-bit. + /// The total number of pixels changed. + public uint SwapColors(RGBQUAD color_a, RGBQUAD color_b, bool ignore_alpha) + { + EnsureNotDisposed(); + return FreeImage.SwapColors(dib, ref color_a, ref color_b, ignore_alpha); + } + + /// + /// Applies palette index mapping for one or several indices + /// on a 1-, 4- or 8-bit palletized image. + /// + /// Array of palette indices to be used as the mapping source. + /// Array of palette indices to be used as the mapping destination. + /// The number of palette indices to be mapped. This is the size of both + /// srcindices and dstindices + /// If true, source and destination palette indices are swapped, that is, + /// each destination index is also mapped to the corresponding source index. + /// The total number of pixels changed. + /// + /// or is a null reference. + /// + /// + /// has a different length than . + /// + public uint ApplyPaletteIndexMapping(byte[] srcindices, byte[] dstindices, uint count, bool swap) + { + EnsureNotDisposed(); + if (srcindices == null) + { + throw new ArgumentNullException("srcindices"); + } + if (dstindices == null) + { + throw new ArgumentNullException("dstindices"); + } + if (srcindices.Length != dstindices.Length) + { + throw new ArgumentException("srcindices and dstindices must have the same length."); + } + return FreeImage.ApplyPaletteIndexMapping(dib, srcindices, dstindices, (uint)srcindices.Length, swap); + } + + /// + /// Swaps two specified palette indices on a 1-, 4- or 8-bit palletized image. + /// + /// One of the two palette indices to be swapped. + /// The other of the two palette indices to be swapped. + /// The total number of pixels changed. + public uint SwapPaletteIndices(byte index_a, byte index_b) + { + EnsureNotDisposed(); + return FreeImage.SwapPaletteIndices(dib, ref index_a, ref index_b); + } + + /// + /// Sets all pixels of this to the specified color. + /// See for further details. + /// + /// The type of the specified color. + /// The color to fill this with. + /// true on success, false on failure. + public bool FillBackground(T color) where T : struct + { + return FillBackground(color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT); + } + + /// + /// Sets all pixels of this to the specified color. + /// See for further details. + /// + /// The type of the specified color. + /// The color to fill this with. + /// Options that affect the color search process for palletized images. + /// true on success, false on failure. + public bool FillBackground(T color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct + { + EnsureNotDisposed(); + return FreeImage.FillBackground(dib, color, options); + } + + /// + /// Creates a new ICC-Profile. + /// + /// The data of the new ICC-Profile. + /// The new ICC-Profile of the bitmap. + /// is a null reference. + public FIICCPROFILE CreateICCProfile(byte[] data) + { + if (data == null) + { + throw new ArgumentNullException("data"); + } + return CreateICCProfile(data, data.Length); + } + + /// + /// Creates a new ICC-Profile. + /// + /// The data of the new ICC-Profile. + /// The number of bytes of to use. + /// The new ICC-Profile of the bitmap. + /// is null. + public FIICCPROFILE CreateICCProfile(byte[] data, int size) + { + EnsureNotDisposed(); + if (data == null) + { + throw new ArgumentNullException("data"); + } + return FreeImage.CreateICCProfileEx(dib, data, size); + } + + /// + /// Determines whether this and the specified instances are the same. + /// + /// The object to test. + /// true if this instance is the same + /// or if both are null references; otherwise, false. + public override bool Equals(object obj) + { + return ReferenceEquals(this, obj); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return dib.GetHashCode(); + } + + #endregion + + #region Static functions + + /// + /// Returns a value that indicates whether the pixel format for this contains alpha information. + /// + /// The to test. + /// true if pixfmt contains alpha information; otherwise, false. + public static bool IsAlphaPixelFormat(PixelFormat pixfmt) + { + return Bitmap.IsAlphaPixelFormat(pixfmt); + } + + /// + /// Returns a value that indicates whether the pixel format is 32 bits per pixel. + /// + /// The to test. + /// true if pixfmt is canonical; otherwise, false. + public static bool IsCanonicalPixelFormat(PixelFormat pixfmt) + { + return Bitmap.IsCanonicalPixelFormat(pixfmt); + } + + /// + /// Returns a value that indicates whether the pixel format is 64 bits per pixel. + /// + /// The enumeration to test. + /// true if pixfmt is extended; otherwise, false. + public static bool IsExtendedPixelFormat(PixelFormat pixfmt) + { + return Bitmap.IsExtendedPixelFormat(pixfmt); + } + + /// + /// Creates a from a Windows handle to an icon. + /// + /// A handle to an icon. + /// The that this method creates. + public static FreeImageBitmap FromHicon(IntPtr hicon) + { + using (Bitmap bitmap = Bitmap.FromHicon(hicon)) + { + return new FreeImageBitmap(bitmap); + } + } + + /// + /// Creates a from the specified Windows resource. + /// + /// A handle to an instance of the executable + /// file that contains the resource. + /// A string containing the name of the resource bitmap. + /// The that this method creates. + public static FreeImageBitmap FromResource(IntPtr hinstance, string bitmapName) + { + using (Bitmap bitmap = Bitmap.FromResource(hinstance, bitmapName)) + { + return new FreeImageBitmap(bitmap); + } + } + + /// + /// Creates a from the specified file. + /// + /// A string that contains the name of the file + /// from which to create the . + /// The this method creates. + public static FreeImageBitmap FromFile(string filename) + { + return new FreeImageBitmap(filename); + } + + /// + /// Creates a from the specified file + /// using embedded color management information in that file. + /// + /// A string that contains the + /// name of the file from which to create the . + /// Ignored. + /// The this method creates. + public static FreeImageBitmap FromFile(string filename, bool useEmbeddedColorManagement) + { + return new FreeImageBitmap(filename); + } + + /// + /// Creates a from a handle to a GDI bitmap. + /// + /// The GDI bitmap handle from which to create the . + /// The this method creates. + public static FreeImageBitmap FromHbitmap(IntPtr hbitmap) + { + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.CreateFromHbitmap(hbitmap, IntPtr.Zero); + if (!newDib.IsNull) + { + result = new FreeImageBitmap(newDib); + } + return result; + } + + /// + /// Creates a from a handle to a GDI bitmap and a handle to a GDI palette. + /// + /// The GDI bitmap handle from which to create the . + /// Ignored. + /// The this method creates. + public static FreeImageBitmap FromHbitmap(IntPtr hbitmap, IntPtr hpalette) + { + return FromHbitmap(hbitmap); + } + + /// + /// Frees a bitmap handle. + /// + /// Handle to a bitmap. + /// true on success, false on failure. + public static bool FreeHbitmap(IntPtr hbitmap) + { + return FreeImage.FreeHbitmap(hbitmap); + } + + /// + /// Creates a from the specified data stream. + /// + /// A that contains the data for this . + /// The this method creates. + public static FreeImageBitmap FromStream(Stream stream) + { + return new FreeImageBitmap(stream); + } + + /// + /// Creates a from the specified data stream. + /// + /// A that contains the data for this . + /// Ignored. + /// The this method creates. + public static FreeImageBitmap FromStream(Stream stream, bool useEmbeddedColorManagement) + { + return new FreeImageBitmap(stream); + } + + /// + /// Creates a from the specified data stream. + /// + /// A that contains the data for this . + /// Ignored. + /// Ignored. + /// The this method creates. + public static FreeImageBitmap FromStream(Stream stream, bool useEmbeddedColorManagement, bool validateImageData) + { + return new FreeImageBitmap(stream); + } + + /// + /// Returns the color depth, in number of bits per pixel, + /// of the specified pixel format. + /// + /// The member that specifies + /// the format for which to find the size. + /// The color depth of the specified pixel format. + public static int GetPixelFormatSize(PixelFormat pixfmt) + { + return Bitmap.GetPixelFormatSize(pixfmt); + } + + /// + /// Performs a lossless rotation or flipping on a JPEG file. + /// + /// Source file. + /// Destination file; can be the source file; will be overwritten. + /// The operation to apply. + /// To avoid lossy transformation, you can set the perfect parameter to true. + /// Returns true on success, false on failure. + public static bool JPEGTransform(string source, string destination, FREE_IMAGE_JPEG_OPERATION operation, bool perfect) + { + return FreeImage.JPEGTransform(source, destination, operation, perfect); + } + + /// + /// Performs a lossless crop on a JPEG file. + /// + /// Source filename. + /// Destination filename. + /// Specifies the cropped rectangle. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// + /// does not exist. + /// + public static bool JPEGCrop(string source, string destination, Rectangle rect) + { + if (source == null) + { + throw new ArgumentNullException("source"); + } + if (!File.Exists(source)) + { + throw new FileNotFoundException("source"); + } + if (destination == null) + { + throw new ArgumentNullException("destination"); + } + return JPEGCrop(source, destination, rect.Left, rect.Top, rect.Right, rect.Bottom); + } + + /// + /// Performs a lossless crop on a JPEG file. + /// + /// Source filename. + /// Destination filename. + /// Specifies the left position of the cropped rectangle. + /// Specifies the top position of the cropped rectangle. + /// Specifies the right position of the cropped rectangle. + /// Specifies the bottom position of the cropped rectangle. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// + /// does not exist. + /// + public static bool JPEGCrop(string source, string destination, int left, int top, int right, int bottom) + { + if (source == null) + { + throw new ArgumentNullException("source"); + } + if (!File.Exists(source)) + { + throw new FileNotFoundException("source"); + } + if (destination == null) + { + throw new ArgumentNullException("destination"); + } + return FreeImage.JPEGCrop(source, destination, left, top, right, bottom); + } + + /// + /// Converts a X11 color name into a corresponding RGB value. + /// + /// Name of the color to convert. + /// Red component. + /// Green component. + /// Blue component. + /// Returns true on success, false on failure. + /// is null. + public static bool LookupX11Color(string color, out byte red, out byte green, out byte blue) + { + if (color == null) + { + throw new ArgumentNullException("color"); + } + return FreeImage.LookupX11Color(color, out red, out green, out blue); + } + + /// + /// Converts a SVG color name into a corresponding RGB value. + /// + /// Name of the color to convert. + /// Red component. + /// Green component. + /// Blue component. + /// Returns true on success, false on failure. + /// is null. + public static bool LookupSVGColor(string color, out byte red, out byte green, out byte blue) + { + if (color == null) + { + throw new ArgumentNullException("color"); + } + return FreeImage.LookupSVGColor(color, out red, out green, out blue); + } + + /// + /// Creates a lookup table to be used with AdjustCurve() which + /// may adjusts brightness and contrast, correct gamma and invert the image with a + /// single call to AdjustCurve(). + /// + /// Output lookup table to be used with AdjustCurve(). + /// The size of is assumed to be 256. + /// Percentage brightness value where -100 <= brightness <= 100. + /// A value of 0 means no change, less than 0 will make the image darker and greater + /// than 0 will make the image brighter. + /// Percentage contrast value where -100 <= contrast <= 100. + /// A value of 0 means no change, less than 0 will decrease the contrast + /// and greater than 0 will increase the contrast of the image. + /// Gamma value to be used for gamma correction. + /// A value of 1.0 leaves the image alone, less than one darkens it, + /// and greater than one lightens it. + /// If set to true, the image will be inverted. + /// The number of adjustments applied to the resulting lookup table + /// compared to a blind lookup table. + /// is null. + /// is not 256. + public static int GetAdjustColorsLookupTable(byte[] lookUpTable, double brightness, double contrast, double gamma, bool invert) + { + if (lookUpTable == null) + { + throw new ArgumentNullException("lookUpTable"); + } + if (lookUpTable.Length != 256) + { + throw new ArgumentException("lookUpTable"); + } + return FreeImage.GetAdjustColorsLookupTable(lookUpTable, brightness, contrast, gamma, invert); + } + + /// + /// Adds a specified frame to the file specified using the specified parameters. + /// Use this method to save selected frames from an to a multiple-frame image. + /// + /// File to add this frame to. + /// A that contains the frame to add. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// Flags to enable or disable plugin-features. + /// + /// or is null. + /// + /// does not exist. + /// Saving the image failed. + public static void SaveAdd( + string filename, + FreeImageBitmap bitmap, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_LOAD_FLAGS loadFlags, + FREE_IMAGE_SAVE_FLAGS saveFlags) + { + if (filename == null) + { + throw new ArgumentNullException("filename"); + } + if (!File.Exists(filename)) + { + throw new FileNotFoundException("filename"); + } + if (bitmap == null) + { + throw new ArgumentNullException("bitmap"); + } + bitmap.EnsureNotDisposed(); + + FIBITMAP dib = bitmap.dib; + if (dib.IsNull) + throw new ArgumentNullException("bitmap"); + + FIMULTIBITMAP mpBitmap = + FreeImage.OpenMultiBitmapEx(filename, ref format, loadFlags, false, false, true); + + if (mpBitmap.IsNull) + throw new Exception(ErrorLoadingBitmap); + + FreeImage.AppendPage(mpBitmap, bitmap.dib); + + if (!FreeImage.CloseMultiBitmap(mpBitmap, saveFlags)) + throw new Exception(ErrorUnloadBitmap); + } + + /// + /// Adds a specified frame to the file specified using the specified parameters. + /// Use this method to save selected frames from an image to a multiple-frame image. + /// + /// File to add this frame to. + /// A that contains the frame to add. + /// The position of the inserted frame. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// Flags to enable or disable plugin-features. + /// + /// or is null. + /// + /// does not exist. + /// Saving the image failed. + /// is out of range. + public static void SaveAdd( + string filename, + FreeImageBitmap bitmap, + int insertPosition, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_LOAD_FLAGS loadFlags, + FREE_IMAGE_SAVE_FLAGS saveFlags) + { + if (filename == null) + { + throw new ArgumentNullException("filename"); + } + if (!File.Exists(filename)) + { + throw new FileNotFoundException("filename"); + } + if (bitmap == null) + { + throw new ArgumentNullException("bitmap"); + } + if (insertPosition < 0) + { + throw new ArgumentOutOfRangeException("insertPosition"); + } + bitmap.EnsureNotDisposed(); + + FIBITMAP dib = bitmap.dib; + if (dib.IsNull) + throw new ArgumentNullException("bitmap"); + + FIMULTIBITMAP mpBitmap = + FreeImage.OpenMultiBitmapEx(filename, ref format, loadFlags, false, false, true); + + if (mpBitmap.IsNull) + throw new Exception(ErrorLoadingBitmap); + + int pageCount = FreeImage.GetPageCount(mpBitmap); + + if (insertPosition > pageCount) + throw new ArgumentOutOfRangeException("insertPosition"); + + if (insertPosition == pageCount) + FreeImage.AppendPage(mpBitmap, bitmap.dib); + else + FreeImage.InsertPage(mpBitmap, insertPosition, bitmap.dib); + + if (!FreeImage.CloseMultiBitmap(mpBitmap, saveFlags)) + throw new Exception(ErrorUnloadBitmap); + } + + /// + /// Returns a new instance of the class which + /// has no public accessible constructor. + /// + /// A new instace of . + public static PropertyItem CreateNewPropertyItem() + { + return FreeImage.CreatePropertyItem(); + } + + #endregion + + #region Helper functions + + /// + /// Throws an exception in case the instance has already been disposed. + /// + private void EnsureNotDisposed() + { + lock (lockObject) + { + if (!this.disposed) + { + return; + } + } + throw new ObjectDisposedException(ToString()); + } + + /// + /// Tries to replace the wrapped with a new one. + /// In case the new dib is null or the same as the already + /// wrapped one, nothing will be changed and the result will + /// be false. + /// Otherwise the wrapped will be unloaded and replaced. + /// + /// The new dib. + /// Returns true on success, false on failure. + private bool ReplaceDib(FIBITMAP newDib) + { + bool result = false; + if ((dib != newDib) && (!newDib.IsNull)) + { + UnloadDib(); + dib = newDib; + AddMemoryPressure(); + result = true; + } + return result; + } + + /// + /// Unloads currently wrapped or unlocks the locked page + /// in case it came from a multipaged bitmap. + /// + private void UnloadDib() + { + if (!dib.IsNull) + { + long size = FreeImage.GetDIBSize(dib); + FreeImage.UnloadEx(ref dib); + if (size > 0L) + GC.RemoveMemoryPressure(size); + } + } + + /// + /// Informs the runtime about unmanaged allocoted memory. + /// + private void AddMemoryPressure() + { + long dataSize; + if ((dataSize = DataSize) > 0L) + GC.AddMemoryPressure(dataSize); + } + + /// + /// Opens the stream and reads the number of available pages. + /// Then loads the first page to this instance. + /// + private void LoadFromStream(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) + { + FIMULTIBITMAP mdib = FreeImage.OpenMultiBitmapFromStream(stream, ref format, flags); + if (mdib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + try + { + frameCount = FreeImage.GetPageCount(mdib); + } + finally + { + if (!FreeImage.CloseMultiBitmapEx(ref mdib)) + { + throw new Exception(ErrorUnloadBitmap); + } + } + + dib = FreeImage.LoadFromStream(stream, flags, ref format); + if (dib.IsNull) + { + throw new Exception(ErrorLoadingBitmap); + } + + saveInformation.loadFlags = flags; + originalFormat = format; + AddMemoryPressure(); + } + + #endregion + + #region Interfaces + + /// + /// Helper class to store informations for . + /// + private sealed class SaveInformation : ICloneable + { + public string filename; + public FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + public FREE_IMAGE_LOAD_FLAGS loadFlags = FREE_IMAGE_LOAD_FLAGS.DEFAULT; + public FREE_IMAGE_SAVE_FLAGS saveFlags = FREE_IMAGE_SAVE_FLAGS.DEFAULT; + + public object Clone() + { + return base.MemberwiseClone(); + } + } + + /// + /// Creates a deep copy of this . + /// + /// A deep copy of this . + public object Clone() + { + EnsureNotDisposed(); + FreeImageBitmap result = null; + FIBITMAP newDib = FreeImage.Clone(dib); + if (!dib.IsNull) + { + result = new FreeImageBitmap(newDib); + result.saveInformation = (SaveInformation)saveInformation.Clone(); + result.tag = tag; + result.originalFormat = originalFormat; + } + return result; + } + + /// + /// Performs application-defined tasks associated with freeing, + /// releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Performs application-defined tasks associated with freeing, + /// releasing, or resetting unmanaged resources. + /// + /// If true managed ressources are released. + protected virtual void Dispose(bool disposing) + { + // Only clean up once + lock (lockObject) + { + if (disposed) + { + return; + } + disposed = true; + } + + // Clean up managed resources + if (disposing) + { + if (stream != null) + { + if (disposeStream) + { + stream.Dispose(); + } + stream = null; + } + } + + tag = null; + saveInformation = null; + + // Clean up unmanaged resources + UnloadDib(); + } + + /// + /// Retrieves an object that can iterate through the individual scanlines in this . + /// + /// An for the . + /// The bitmaps's type is not supported. + IEnumerator IEnumerable.GetEnumerator() + { + return GetScanlines().GetEnumerator(); + } + + void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) + { + EnsureNotDisposed(); + using (MemoryStream memory = new MemoryStream(DataSize)) + { + if (!FreeImage.SaveToStream(dib, memory, FREE_IMAGE_FORMAT.FIF_TIFF, FREE_IMAGE_SAVE_FLAGS.TIFF_LZW)) + { + throw new SerializationException(); + } + memory.Capacity = (int)memory.Length; + info.AddValue("Bitmap Data", memory.GetBuffer()); + } + } + + #endregion + } +} + +namespace FreeImageAPI +{ + /// + /// Class handling non-bitmap related functions. + /// + public static class FreeImageEngine + { + #region Callback + + // Callback delegate + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private static readonly OutputMessageFunction outputMessageFunction; + + static FreeImageEngine() + { + // Check if FreeImage.dll is present and cancel setting the callbackfuntion if not + if (!IsAvailable) + { + return; + } + // Create a delegate (function pointer) to 'OnMessage' + outputMessageFunction = new OutputMessageFunction(OnMessage); + // Set the callback + FreeImage.SetOutputMessage(outputMessageFunction); + } + + /// + /// Internal callback + /// + private static void OnMessage(FREE_IMAGE_FORMAT fif, string message) + { + // Get a local copy of the multicast-delegate + OutputMessageFunction m = Message; + + // Check the local copy instead of the static instance + // to prevent a second thread from setting the delegate + // to null, which would cause a nullreference exception + if (m != null) + { + // Invoke the multicast-delegate + m.Invoke(fif, message); + } + } + + /// + /// Gets a value indicating if the FreeImage DLL is available or not. + /// + public static bool IsAvailable + { + get + { + return FreeImage.IsAvailable(); + } + } + + /// + /// Internal errors in FreeImage generate a logstring that can be + /// captured by this event. + /// + public static event OutputMessageFunction Message; + + #endregion + + /// + /// Gets a string containing the current version of the library. + /// + public static string Version + { + get + { + return FreeImage.GetVersion(); + } + } + + /// + /// Gets a string containing a standard copyright message. + /// + public static string CopyrightMessage + { + get + { + return FreeImage.GetCopyrightMessage(); + } + } + + /// + /// Gets whether the platform is using Little Endian. + /// + public static bool IsLittleEndian + { + get + { + return FreeImage.IsLittleEndian(); + } + } + } +} + +namespace FreeImageAPI.Plugins +{ + /// + /// Class representing a FreeImage format. + /// + public sealed class FreeImagePlugin + { + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private readonly FREE_IMAGE_FORMAT fif; + + /// + /// Initializes a new instance of this class. + /// + /// The FreeImage format to wrap. + internal FreeImagePlugin(FREE_IMAGE_FORMAT fif) + { + this.fif = fif; + } + + /// + /// Gets the format of this instance. + /// + public FREE_IMAGE_FORMAT FIFormat + { + get + { + return fif; + } + } + + /// + /// Gets or sets whether this plugin is enabled. + /// + public bool Enabled + { + get + { + return (FreeImage.IsPluginEnabled(fif) == 1); + } + set + { + FreeImage.SetPluginEnabled(fif, value); + } + } + + /// + /// Gets a string describing the format. + /// + public string Format + { + get + { + return FreeImage.GetFormatFromFIF(fif); + } + } + + /// + /// Gets a comma-delimited file extension list describing the bitmap formats + /// this plugin can read and/or write. + /// + public string ExtentsionList + { + get + { + return FreeImage.GetFIFExtensionList(fif); + } + } + + /// + /// Gets a descriptive string that describes the bitmap formats + /// this plugin can read and/or write. + /// + public string Description + { + get + { + return FreeImage.GetFIFDescription(fif); + } + } + + /// + /// Returns a regular expression string that can be used by + /// a regular expression engine to identify the bitmap. + /// FreeImageQt makes use of this function. + /// + public string RegExpr + { + get + { + return FreeImage.GetFIFRegExpr(fif); + } + } + + /// + /// Gets whether this plugin can load bitmaps. + /// + public bool SupportsReading + { + get + { + return FreeImage.FIFSupportsReading(fif); + } + } + + /// + /// Gets whether this plugin can save bitmaps. + /// + public bool SupportsWriting + { + get + { + return FreeImage.FIFSupportsWriting(fif); + } + } + + /// + /// Checks whether this plugin can save a bitmap in the desired data type. + /// + /// The desired image type. + /// True if this plugin can save bitmaps as the desired type, else false. + public bool SupportsExportType(FREE_IMAGE_TYPE type) + { + return FreeImage.FIFSupportsExportType(fif, type); + } + + /// + /// Checks whether this plugin can save bitmaps in the desired bit depth. + /// + /// The desired bit depth. + /// True if this plugin can save bitmaps in the desired bit depth, else false. + public bool SupportsExportBPP(int bpp) + { + return FreeImage.FIFSupportsExportBPP(fif, bpp); + } + + /// + /// Gets whether this plugin can load or save an ICC profile. + /// + public bool SupportsICCProfiles + { + get + { + return FreeImage.FIFSupportsICCProfiles(fif); + } + } + + /// + /// Checks whether an extension is valid for this format. + /// + /// The desired extension. + /// True if the extension is valid for this format, false otherwise. + public bool ValidExtension(string extension) + { + return FreeImage.IsExtensionValidForFIF(fif, extension); + } + + /// + /// Checks whether an extension is valid for this format. + /// + /// The desired extension. + /// The string comparison type. + /// True if the extension is valid for this format, false otherwise. + public bool ValidExtension(string extension, StringComparison comparisonType) + { + return FreeImage.IsExtensionValidForFIF(fif, extension, comparisonType); + } + + /// + /// Checks whether a filename is valid for this format. + /// + /// The desired filename. + /// True if the filename is valid for this format, false otherwise. + public bool ValidFilename(string filename) + { + return FreeImage.IsFilenameValidForFIF(fif, filename); + } + + /// + /// Checks whether a filename is valid for this format. + /// + /// The desired filename. + /// The string comparison type. + /// True if the filename is valid for this format, false otherwise. + public bool ValidFilename(string filename, StringComparison comparisonType) + { + return FreeImage.IsFilenameValidForFIF(fif, filename, comparisonType); + } + + /// + /// Gets a descriptive string that describes the bitmap formats + /// this plugin can read and/or write. + /// + /// A descriptive string that describes the bitmap formats. + public override string ToString() + { + return Description; + } + } +} + +namespace FreeImageAPI.IO +{ + /// + /// Internal class wrapping stream io functions. + /// + /// + /// FreeImage can read files from a disk or a network drive but also allows the user to + /// implement their own loading or saving functions to load them directly from an ftp or web + /// server for example. + /// + /// In .NET streams are a common way to handle data. The FreeImageStreamIO class handles + /// the loading and saving from and to streams. It implements the funtions FreeImage needs + /// to load data from an an arbitrary source. + /// + /// The class is for internal use only. + /// + internal static class FreeImageStreamIO + { + /// + /// structure that can be used to read from streams via + /// . + /// + public static readonly FreeImageIO io; + + /// + /// Initializes a new instances which can be used to + /// create a FreeImage compatible structure. + /// + static FreeImageStreamIO() + { + io.readProc = new ReadProc(streamRead); + io.writeProc = new WriteProc(streamWrite); + io.seekProc = new SeekProc(streamSeek); + io.tellProc = new TellProc(streamTell); + } + + /// + /// Reads the requested data from the stream and writes it to the given address. + /// + static unsafe uint streamRead(IntPtr buffer, uint size, uint count, fi_handle handle) + { + Stream stream = handle.GetObject() as Stream; + if ((stream == null) || (!stream.CanRead)) + { + return 0; + } + uint readCount = 0; + byte* ptr = (byte*)buffer; + byte[] bufferTemp = new byte[size]; + int read; + while (readCount < count) + { + read = stream.Read(bufferTemp, 0, (int)size); + if (read != (int)size) + { + stream.Seek(-read, SeekOrigin.Current); + break; + } + for (int i = 0; i < read; i++, ptr++) + { + *ptr = bufferTemp[i]; + } + readCount++; + } + return (uint)readCount; + } + + /// + /// Reads the given data and writes it into the stream. + /// + static unsafe uint streamWrite(IntPtr buffer, uint size, uint count, fi_handle handle) + { + Stream stream = handle.GetObject() as Stream; + if ((stream == null) || (!stream.CanWrite)) + { + return 0; + } + uint writeCount = 0; + byte[] bufferTemp = new byte[size]; + byte* ptr = (byte*)buffer; + while (writeCount < count) + { + for (int i = 0; i < size; i++, ptr++) + { + bufferTemp[i] = *ptr; + } + try + { + stream.Write(bufferTemp, 0, bufferTemp.Length); + } + catch + { + return writeCount; + } + writeCount++; + } + return writeCount; + } + + /// + /// Moves the streams position. + /// + static int streamSeek(fi_handle handle, int offset, SeekOrigin origin) + { + Stream stream = handle.GetObject() as Stream; + if (stream == null) + { + return 1; + } + stream.Seek((long)offset, origin); + return 0; + } + + /// + /// Returns the streams current position + /// + static int streamTell(fi_handle handle) + { + Stream stream = handle.GetObject() as Stream; + if (stream == null) + { + return -1; + } + return (int)stream.Position; + } + } +} + +namespace FreeImageAPI.Metadata +{ + /// + /// Provides additional information specific for GIF files. This class cannot be inherited. + /// + public class GifInformation : MDM_ANIMATION + { + /// + /// Initializes a new instance of the class + /// with the specified . + /// + /// A reference to a instance. + public GifInformation(FreeImageBitmap bitmap) + : base(bitmap.Dib) + { + } + + /// + /// Gets or sets a value indicating whether this frame uses the + /// GIF image's global palette. If set to false, this + /// frame uses its local palette. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public bool? UseGlobalPalette + { + get + { + byte? useGlobalPalette = GetTagValue("NoLocalPalette"); + return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?); + } + set + { + byte? val = null; + if (value.HasValue) + { + val = (byte)(value.Value ? 1 : 0); + } + SetTagValue("NoLocalPalette", val); + } + } + + /// + /// Creates a global palette for the GIF image, intialized with all entries of the + /// current local palette. + /// The property will be set to true when + /// invoking this method. This effectively enables the newly created global palette. + /// + /// + /// The image does not have a palette. + /// + public void CreateGlobalPalette() + { + CreateGlobalPalette(new Palette(dib)); + } + + /// + /// Creates a global palette for the GIF image with the specified size, intialized + /// with the first entries of the current local palette. + /// The property will be set to true when + /// invoking this method. This effectively enables the newly created global palette. + /// + /// The size of the newly created global palette. + /// + /// is a null reference. + public void CreateGlobalPalette(int size) + { + CreateGlobalPalette(new Palette(dib), size); + } + + /// + /// Creates a global palette for the GIF image, intialized with the entries + /// of the specified palette. + /// The property will be set to true when + /// invoking this method. This effectively enables the newly created global palette. + /// + /// The palette that contains the initial values for + /// the newly created global palette. + /// + /// is a null reference. + public void CreateGlobalPalette(Palette palette) + { + if (palette == null) + { + throw new ArgumentNullException("palette"); + } + + GlobalPalette = palette; + UseGlobalPalette = true; + } + + /// + /// Creates a global palette for the GIF image with the specified size, intialized + /// with the first entries of the specified palette. + /// The property will be set to true when + /// invoking this method. This effectively enables the newly created global palette. + /// + /// The palette that contains the initial values for + /// the newly created global palette. + /// The size of the newly created global palette. + /// + /// is a null reference. + public void CreateGlobalPalette(Palette palette, int size) + { + if (palette == null) + { + throw new ArgumentNullException("palette"); + } + if (size <= 0) + { + throw new ArgumentOutOfRangeException("size"); + } + + Palette pal = new Palette(size); + pal.CopyFrom(palette); + GlobalPalette = palette; + UseGlobalPalette = true; + } + } +} + +namespace FreeImageAPI.Metadata +{ + /// + /// Class handling metadata of a FreeImage bitmap. + /// + public class ImageMetadata : IEnumerable, IComparable, IComparable + { + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private readonly List data; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private readonly FIBITMAP dib; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool hideEmptyModels; + + /// + /// Initializes a new instance based on the specified , + /// showing all known models. + /// + /// Handle to a FreeImage bitmap. + public ImageMetadata(FIBITMAP dib) : this(dib, false) { } + + /// + /// Initializes a new instance based on the specified , + /// showing or hiding empry models. + /// + /// Handle to a FreeImage bitmap. + /// When true, empty metadata models + /// will be hidden until a tag to this model is added. + public ImageMetadata(FIBITMAP dib, bool hideEmptyModels) + { + if (dib.IsNull) throw new ArgumentNullException("dib"); + data = new List(FreeImage.FREE_IMAGE_MDMODELS.Length); + this.dib = dib; + this.hideEmptyModels = hideEmptyModels; + + data.Add(new MDM_ANIMATION(dib)); + data.Add(new MDM_COMMENTS(dib)); + data.Add(new MDM_CUSTOM(dib)); + data.Add(new MDM_EXIF_EXIF(dib)); + data.Add(new MDM_EXIF_GPS(dib)); + data.Add(new MDM_INTEROP(dib)); + data.Add(new MDM_EXIF_MAIN(dib)); + data.Add(new MDM_MAKERNOTE(dib)); + data.Add(new MDM_GEOTIFF(dib)); + data.Add(new MDM_IPTC(dib)); + data.Add(new MDM_NODATA(dib)); + data.Add(new MDM_XMP(dib)); + } + + /// + /// Gets or sets the of the specified type. + /// In case the getter returns null the model is not contained + /// by the list. + /// null can be used calling the setter to destroy the model. + /// + /// Type of the model. + /// The object of the specified type. + public MetadataModel this[FREE_IMAGE_MDMODEL model] + { + get + { + for (int i = 0; i < data.Count; i++) + { + if (data[i].Model == model) + { + if (!data[i].Exists && hideEmptyModels) + { + return null; + } + return data[i]; + } + } + return null; + } + } + + /// + /// Gets or sets the at the specified index. + /// In case the getter returns null the model is not contained + /// by the list. + /// null can be used calling the setter to destroy the model. + /// + /// Index of the within + /// this instance. + /// The + /// object at the specified index. + public MetadataModel this[int index] + { + get + { + if (index < 0 || index >= data.Count) + { + throw new ArgumentOutOfRangeException("index"); + } + return (hideEmptyModels && !data[index].Exists) ? null : data[index]; + } + } + + /// + /// Returns a list of all visible + /// MetadataModels. + /// + public List List + { + get + { + if (hideEmptyModels) + { + List result = new List(); + for (int i = 0; i < data.Count; i++) + { + if (data[i].Exists) + { + result.Add(data[i]); + } + } + return result; + } + else + { + return data; + } + } + } + + /// + /// Adds new tag to the bitmap or updates its value in case it already exists. + /// will be used as key. + /// + /// The tag to add or update. + /// Returns true on success, false on failure. + /// + /// is null. + public bool AddTag(MetadataTag tag) + { + for (int i = 0; i < data.Count; i++) + { + if (tag.Model == data[i].Model) + { + return data[i].AddTag(tag); + } + } + return false; + } + + /// + /// Returns the number of visible + /// MetadataModels. + /// + public int Count + { + get + { + if (hideEmptyModels) + { + int count = 0; + for (int i = 0; i < data.Count; i++) + { + if (data[i].Exists) + { + count++; + } + } + return count; + } + else + { + return data.Count; + } + } + } + + /// + /// Gets or sets whether empty + /// MetadataModels are hidden. + /// + public bool HideEmptyModels + { + get + { + return hideEmptyModels; + } + set + { + hideEmptyModels = value; + } + } + + /// + /// Retrieves an object that can iterate through the individual + /// MetadataModels + /// in this . + /// + /// An for this . + public IEnumerator GetEnumerator() + { + if (hideEmptyModels) + { + List tempList = new List(data.Count); + for (int i = 0; i < data.Count; i++) + { + if (data[i].Exists) + { + tempList.Add(data[i]); + } + } + return tempList.GetEnumerator(); + } + else + { + return data.GetEnumerator(); + } + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is ImageMetadata)) + { + throw new ArgumentException("obj"); + } + return CompareTo((ImageMetadata)obj); + } + + /// + /// Compares this instance with a specified object. + /// + /// A to compare. + /// A signed number indicating the relative values of this instance + /// and . + public int CompareTo(ImageMetadata other) + { + return this.dib.CompareTo(other.dib); + } + } +} + +namespace FreeImageAPI.Plugins +{ + /// + /// Class representing own FreeImage-Plugins. + /// + /// + /// FreeImages itself is plugin based. Each supported format is integrated by a seperat plugin, + /// that handles loading, saving, descriptions, identifing ect. + /// And of course the user can create own plugins and use them in FreeImage. + /// To do that the above mentioned predefined methodes need to be implemented. + /// + /// The class below handles the creation of such a plugin. The class itself is abstract + /// as well as some core functions that need to be implemented. + /// The class can be used to enable or disable the plugin in FreeImage after regististration or + /// retrieve the formatid, assigned by FreeImage. + /// The class handles the callback functions, garbage collector and pointer operation to make + /// the implementation as user friendly as possible. + /// + /// How to: + /// There are two functions that need to be implemented: + /// and + /// . + /// is used by the constructor + /// of the abstract class. FreeImage wants a list of the implemented functions. Each function is + /// represented by a function pointer (a .NET ). In case a function + /// is not implemented FreeImage receives an empty delegate). To tell the constructor + /// which functions have been implemented the information is represented by a disjunction of + /// . + /// + /// For example: + /// return MethodFlags.LoadProc | MethodFlags.SaveProc; + /// + /// The above statement means that LoadProc and SaveProc have been implemented by the user. + /// Keep in mind, that each function has a standard implementation that has static return + /// values that may cause errors if listed in + /// without a real implementation. + /// + /// is used by some checks of FreeImage and + /// must be implemented. for example can be + /// implemented if the plugin supports reading, but it doesn't have to, the plugin could only + /// be used to save an already loaded bitmap in a special format. + /// + public abstract class LocalPlugin + { + /// + /// Struct containing function pointers. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private Plugin plugin; + + /// + /// Delegate for register callback by FreeImage. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private InitProc initProc; + + /// + /// The format id assiged to the plugin. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + + /// + /// When true the plugin was registered successfully else false. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected readonly bool registered = false; + + /// + /// A copy of the functions used to register. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected readonly MethodFlags implementedMethods; + + /// + /// MethodFlags defines values to fill a bitfield telling which + /// functions have been implemented by a plugin. + /// + [Flags] + protected enum MethodFlags + { + /// + /// No mothods implemented. + /// + None = 0x0, + + /// + /// DescriptionProc has been implemented. + /// + DescriptionProc = 0x1, + + /// + /// ExtensionListProc has been implemented. + /// + ExtensionListProc = 0x2, + + /// + /// RegExprProc has been implemented. + /// + RegExprProc = 0x4, + + /// + /// OpenProc has been implemented. + /// + OpenProc = 0x8, + + /// + /// CloseProc has been implemented. + /// + CloseProc = 0x10, + + /// + /// PageCountProc has been implemented. + /// + PageCountProc = 0x20, + + /// + /// PageCapabilityProc has been implemented. + /// + PageCapabilityProc = 0x40, + + /// + /// LoadProc has been implemented. + /// + LoadProc = 0x80, + + /// + /// SaveProc has been implemented. + /// + SaveProc = 0x100, + + /// + /// ValidateProc has been implemented. + /// + ValidateProc = 0x200, + + /// + /// MimeProc has been implemented. + /// + MimeProc = 0x400, + + /// + /// SupportsExportBPPProc has been implemented. + /// + SupportsExportBPPProc = 0x800, + + /// + /// SupportsExportTypeProc has been implemented. + /// + SupportsExportTypeProc = 0x1000, + + /// + /// SupportsICCProfilesProc has been implemented. + /// + SupportsICCProfilesProc = 0x2000 + } + + // Functions that must be implemented. + + /// + /// Function that returns a bitfield containing the + /// implemented methods. + /// + /// Bitfield of the implemented methods. + protected abstract MethodFlags GetImplementedMethods(); + + /// + /// Implementation of FormatProc + /// + /// A string containing the plugins format. + protected abstract string FormatProc(); + + // Functions that can be implemented. + + /// + /// Function that can be implemented. + /// + protected virtual string DescriptionProc() { return ""; } + /// + /// Function that can be implemented. + /// + protected virtual string ExtensionListProc() { return ""; } + /// + /// Function that can be implemented. + /// + protected virtual string RegExprProc() { return ""; } + /// + /// Function that can be implemented. + /// + protected virtual IntPtr OpenProc(ref FreeImageIO io, fi_handle handle, bool read) { return IntPtr.Zero; } + /// + /// Function that can be implemented. + /// + protected virtual void CloseProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { } + /// + /// Function that can be implemented. + /// + protected virtual int PageCountProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { return 0; } + /// + /// Function that can be implemented. + /// + protected virtual int PageCapabilityProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { return 0; } + /// + /// Function that can be implemented. + /// + protected virtual FIBITMAP LoadProc(ref FreeImageIO io, fi_handle handle, int page, int flags, IntPtr data) { return FIBITMAP.Zero; } + /// + /// Function that can be implemented. + /// + protected virtual bool SaveProc(ref FreeImageIO io, FIBITMAP dib, fi_handle handle, int page, int flags, IntPtr data) { return false; } + /// + /// Function that can be implemented. + /// + protected virtual bool ValidateProc(ref FreeImageIO io, fi_handle handle) { return false; } + /// + /// Function that can be implemented. + /// + protected virtual string MimeProc() { return ""; } + /// + /// Function that can be implemented. + /// + protected virtual bool SupportsExportBPPProc(int bpp) { return false; } + /// + /// Function that can be implemented. + /// + protected virtual bool SupportsExportTypeProc(FREE_IMAGE_TYPE type) { return false; } + /// + /// Function that can be implemented. + /// + protected virtual bool SupportsICCProfilesProc() { return false; } + + /// + /// The constructor automatically registeres the plugin in FreeImage. + /// To do this it prepares a FreeImage defined structure with function pointers + /// to the implemented functions or null if not implemented. + /// Before registing the functions they are pinned in memory so the garbage collector + /// can't move them around in memory after we passed there addresses to FreeImage. + /// + public LocalPlugin() + { + implementedMethods = GetImplementedMethods(); + + if ((implementedMethods & MethodFlags.DescriptionProc) != 0) + { + plugin.descriptionProc = new DescriptionProc(DescriptionProc); + } + if ((implementedMethods & MethodFlags.ExtensionListProc) != 0) + { + plugin.extensionListProc = new ExtensionListProc(ExtensionListProc); + } + if ((implementedMethods & MethodFlags.RegExprProc) != 0) + { + plugin.regExprProc = new RegExprProc(RegExprProc); + } + if ((implementedMethods & MethodFlags.OpenProc) != 0) + { + plugin.openProc = new OpenProc(OpenProc); + } + if ((implementedMethods & MethodFlags.CloseProc) != 0) + { + plugin.closeProc = new CloseProc(CloseProc); + } + if ((implementedMethods & MethodFlags.PageCountProc) != 0) + { + plugin.pageCountProc = new PageCountProc(PageCountProc); + } + if ((implementedMethods & MethodFlags.PageCapabilityProc) != 0) + { + plugin.pageCapabilityProc = new PageCapabilityProc(PageCapabilityProc); + } + if ((implementedMethods & MethodFlags.LoadProc) != 0) + { + plugin.loadProc = new LoadProc(LoadProc); + } + if ((implementedMethods & MethodFlags.SaveProc) != 0) + { + plugin.saveProc = new SaveProc(SaveProc); + } + if ((implementedMethods & MethodFlags.ValidateProc) != 0) + { + plugin.validateProc = new ValidateProc(ValidateProc); + } + if ((implementedMethods & MethodFlags.MimeProc) != 0) + { + plugin.mimeProc = new MimeProc(MimeProc); + } + if ((implementedMethods & MethodFlags.SupportsExportBPPProc) != 0) + { + plugin.supportsExportBPPProc = new SupportsExportBPPProc(SupportsExportBPPProc); + } + if ((implementedMethods & MethodFlags.SupportsExportTypeProc) != 0) + { + plugin.supportsExportTypeProc = new SupportsExportTypeProc(SupportsExportTypeProc); + } + if ((implementedMethods & MethodFlags.SupportsICCProfilesProc) != 0) + { + plugin.supportsICCProfilesProc = new SupportsICCProfilesProc(SupportsICCProfilesProc); + } + + // FormatProc is always implemented + plugin.formatProc = new FormatProc(FormatProc); + + // InitProc is the register call back. + initProc = new InitProc(RegisterProc); + + // Register the plugin. The result will be saved and can be accessed later. + registered = FreeImage.RegisterLocalPlugin(initProc, null, null, null, null) != FREE_IMAGE_FORMAT.FIF_UNKNOWN; + if (registered) + { + PluginRepository.RegisterLocalPlugin(this); + } + } + + private void RegisterProc(ref Plugin plugin, int format_id) + { + // Copy the function pointers + plugin = this.plugin; + // Retrieve the format if assigned to this plugin by FreeImage. + format = (FREE_IMAGE_FORMAT)format_id; + } + + /// + /// Gets or sets if the plugin is enabled. + /// + public bool Enabled + { + get + { + if (registered) + { + return (FreeImage.IsPluginEnabled(format) > 0); + } + else + { + throw new ObjectDisposedException("plugin not registered"); + } + } + set + { + if (registered) + { + FreeImage.SetPluginEnabled(format, value); + } + else + { + throw new ObjectDisposedException("plugin not registered"); + } + } + } + + /// + /// Gets if the plugin was registered successfully. + /// + public bool Registered + { + get { return registered; } + } + + /// + /// Gets the FreeImage assigned to this plugin. + /// + public FREE_IMAGE_FORMAT Format + { + get + { + return format; + } + } + + /// + /// Reads from an unmanaged stream. + /// + protected unsafe int Read(FreeImageIO io, fi_handle handle, uint size, uint count, ref byte[] buffer) + { + fixed (byte* ptr = buffer) + { + return (int)io.readProc(new IntPtr(ptr), size, count, handle); + } + } + + /// + /// Reads a single byte from an unmanaged stream. + /// + protected unsafe int ReadByte(FreeImageIO io, fi_handle handle) + { + byte buffer = 0; + return (int)io.readProc(new IntPtr(&buffer), 1, 1, handle) > 0 ? buffer : -1; + } + + /// + /// Writes to an unmanaged stream. + /// + protected unsafe int Write(FreeImageIO io, fi_handle handle, uint size, uint count, ref byte[] buffer) + { + fixed (byte* ptr = buffer) + { + return (int)io.writeProc(new IntPtr(ptr), size, count, handle); + } + } + + /// + /// Writes a single byte to an unmanaged stream. + /// + protected unsafe int WriteByte(FreeImageIO io, fi_handle handle, byte value) + { + return (int)io.writeProc(new IntPtr(&value), 1, 1, handle); + } + + /// + /// Seeks in an unmanaged stream. + /// + protected int Seek(FreeImageIO io, fi_handle handle, int offset, SeekOrigin origin) + { + return io.seekProc(handle, offset, origin); + } + + /// + /// Retrieves the position of an unmanaged stream. + /// + protected int Tell(FreeImageIO io, fi_handle handle) + { + return io.tellProc(handle); + } + } +} + +namespace FreeImageAPI +{ + /// + /// Represents unmanaged memory, containing an array of a given structure. + /// + /// Structuretype represented by the instance. + /// + /// and can not be marshalled. + /// + /// Use instead of and + /// instead of . + /// + public unsafe class MemoryArray : IDisposable, ICloneable, ICollection, IEnumerable, IEquatable> where T : struct + { + /// + /// Baseaddress of the wrapped memory. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected byte* baseAddress; + + /// + /// Number of elements being wrapped. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected int length; + + /// + /// Size, in bytes, of each element. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private static readonly int size; + + /// + /// Array of T containing a single element. + /// The array is used as a workaround, because there are no pointer for generic types. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected T[] buffer; + + /// + /// Pointer to the element of buffer. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected byte* ptr; + + /// + /// Handle for pinning buffer. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected GCHandle handle; + + /// + /// Indicates whether the wrapped memory is handled like a bitfield. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected readonly bool isOneBit; + + /// + /// Indicates whther the wrapped memory is handles like 4-bit blocks. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected readonly bool isFourBit; + + /// + /// An object that can be used to synchronize access to the . + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected object syncRoot = null; + + static MemoryArray() + { + T[] dummy = new T[2]; + long marshalledSize = Marshal.SizeOf(typeof(T)); + long structureSize = + Marshal.UnsafeAddrOfPinnedArrayElement(dummy, 1).ToInt64() - + Marshal.UnsafeAddrOfPinnedArrayElement(dummy, 0).ToInt64(); + if (marshalledSize != structureSize) + { + throw new NotSupportedException( + "The desired type can not be handled, " + + "because its managed and unmanaged size in bytes are different."); + } + + size = (int)marshalledSize; + } + + /// + /// Initializes a new instance. + /// + protected MemoryArray() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Address of the memory block. + /// Length of the array. + /// + /// is null. + /// + /// is less or equal zero. + /// + /// The type is not supported. + public MemoryArray(IntPtr baseAddress, int length) + : this(baseAddress.ToPointer(), length) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Address of the memory block. + /// Length of the array. + /// + /// is null. + /// + /// is less or equal zero. + /// + /// The type is not supported. + public MemoryArray(void* baseAddress, int length) + { + if (typeof(T) == typeof(FI1BIT)) + { + isOneBit = true; + } + else if (typeof(T) == typeof(FI4BIT)) + { + isFourBit = true; + } + + if (baseAddress == null) + { + throw new ArgumentNullException("baseAddress"); + } + if (length < 1) + { + throw new ArgumentOutOfRangeException("length"); + } + + this.baseAddress = (byte*)baseAddress; + this.length = (int)length; + + if (!isOneBit && !isFourBit) + { + // Create an array containing a single element. + // Due to the fact, that it's not possible to create pointers + // of generic types, an array is used to obtain the memory + // address of an element of T. + this.buffer = new T[1]; + // The array is pinned immediately to prevent the GC from + // moving it to a different position in memory. + this.handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + // The array and its content have beed pinned, so that its address + // can be safely requested and stored for the whole lifetime + // of the instace. + this.ptr = (byte*)handle.AddrOfPinnedObject(); + } + } + + /// + /// Frees the allocated . + /// + ~MemoryArray() + { + Dispose(false); + } + + /// + /// Tests whether two specified structures are equivalent. + /// + /// The that is to the left of the equality operator. + /// The that is to the right of the equality operator. + /// + /// true if the two structures are equal; otherwise, false. + /// + public static bool operator ==(MemoryArray left, MemoryArray right) + { + if (object.ReferenceEquals(left, right)) + { + return true; + } + if (object.ReferenceEquals(right, null) || + object.ReferenceEquals(left, null) || + (left.length != right.length)) + { + return false; + } + if (left.baseAddress == right.baseAddress) + { + return true; + } + return FreeImage.CompareMemory(left.baseAddress, right.baseAddress, (uint)left.length); + } + + /// + /// Tests whether two specified structures are different. + /// + /// The that is to the left of the inequality operator. + /// The that is to the right of the inequality operator. + /// + /// true if the two structures are different; otherwise, false. + /// + public static bool operator !=(MemoryArray left, MemoryArray right) + { + return (!(left == right)); + } + + /// + /// Gets the value at the specified position. + /// + /// A 32-bit integer that represents the position + /// of the array element to get. + /// The value at the specified position. + /// + /// is outside the range of valid indexes + /// for the unmanaged array. + public T GetValue(int index) + { + if ((index >= this.length) || (index < 0)) + { + throw new ArgumentOutOfRangeException("index"); + } + + return GetValueInternal(index); + } + + private T GetValueInternal(int index) + { + EnsureNotDisposed(); + if (isOneBit) + { + return (T)(object)(FI1BIT)(((baseAddress[index / 8] & ((1 << (7 - (index % 8))))) == 0) ? 0 : 1); + } + else if (isFourBit) + { + return (T)(object)(FI4BIT)(((index % 2) == 0) ? (baseAddress[index / 2] >> 4) : (baseAddress[index / 2] & 0x0F)); + } + else + { + CopyMemory(ptr, baseAddress + (index * size), size); + return buffer[0]; + } + } + + /// + /// Sets a value to the element at the specified position. + /// + /// The new value for the specified element. + /// A 32-bit integer that represents the + /// position of the array element to set. + /// + /// is outside the range of valid indexes + /// for the unmanaged array. + public void SetValue(T value, int index) + { + if ((index >= this.length) || (index < 0)) + { + throw new ArgumentOutOfRangeException("index"); + } + SetValueInternal(value, index); + } + + private void SetValueInternal(T value, int index) + { + EnsureNotDisposed(); + if (isOneBit) + { + if ((FI1BIT)(object)value != 0) + { + baseAddress[index / 8] |= (byte)(1 << (7 - (index % 8))); + } + else + { + baseAddress[index / 8] &= (byte)(~(1 << (7 - (index % 8)))); + } + } + else if (isFourBit) + { + if ((index % 2) == 0) + { + baseAddress[index / 2] = (byte)((baseAddress[index / 2] & 0x0F) | ((FI4BIT)(object)value << 4)); + } + else + { + baseAddress[index / 2] = (byte)((baseAddress[index / 2] & 0xF0) | ((FI4BIT)(object)value & 0x0F)); + } + } + else + { + buffer[0] = value; + CopyMemory(baseAddress + (index * size), ptr, size); + } + } + + /// + /// Gets the values at the specified position and length. + /// + /// A 32-bit integer that represents the position + /// of the array elements to get. + /// A 32-bit integer that represents the length + /// of the array elements to get. + /// The values at the specified position and length. + /// + /// is outside the range of valid indexes + /// for the unmanaged array or is greater than the number of elements + /// from to the end of the unmanaged array. + public T[] GetValues(int index, int length) + { + EnsureNotDisposed(); + if ((index >= this.length) || (index < 0)) + { + throw new ArgumentOutOfRangeException("index"); + } + if (((index + length) > this.length) || (length < 1)) + { + throw new ArgumentOutOfRangeException("length"); + } + + T[] data = new T[length]; + if (isOneBit || isFourBit) + { + for (int i = 0; i < length; i++) + { + data[i] = GetValueInternal(i); + } + } + else + { + GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); + byte* dst = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(data, 0); + CopyMemory(dst, baseAddress + (size * index), size * length); + handle.Free(); + } + return data; + } + + /// + /// Sets the values at the specified position. + /// + /// An array containing the new values for the specified elements. + /// A 32-bit integer that represents the position + /// of the array elements to set. + /// + /// is a null reference (Nothing in Visual Basic). + /// + /// is outside the range of valid indexes + /// for the unmanaged array or is greater than the number of elements + /// from to the end of the array. + public void SetValues(T[] values, int index) + { + EnsureNotDisposed(); + if (values == null) + { + throw new ArgumentNullException("values"); + } + if ((index >= this.length) || (index < 0)) + { + throw new ArgumentOutOfRangeException("index"); + } + if ((index + values.Length) > this.length) + { + throw new ArgumentOutOfRangeException("values.Length"); + } + + if (isOneBit || isFourBit) + { + for (int i = 0; i != values.Length; ) + { + SetValueInternal(values[i++], index++); + } + } + else + { + GCHandle handle = GCHandle.Alloc(values, GCHandleType.Pinned); + byte* src = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(values, 0); + CopyMemory(baseAddress + (index * size), src, size * length); + handle.Free(); + } + } + + /// + /// Copies the entire array to a compatible one-dimensional , + /// starting at the specified index of the target array. + /// + /// The one-dimensional that is the destination + /// of the elements copied from . + /// The must have zero-based indexing. + /// The zero-based index in + /// at which copying begins. + public void CopyTo(Array array, int index) + { + EnsureNotDisposed(); + if (!(array is T[])) + { + throw new InvalidCastException("array"); + } + try + { + CopyTo((T[])array, 0, index, length); + } + catch (ArgumentOutOfRangeException ex) + { + throw new ArgumentException(ex.Message, ex); + } + } + + /// + /// Copies a range of elements from the unmanaged array starting at the specified + /// and pastes them to + /// starting at the specified . + /// The length and the indexes are specified as 32-bit integers. + /// + /// The array that receives the data. + /// A 32-bit integer that represents the index + /// in the unmanaged array at which copying begins. + /// A 32-bit integer that represents the index in + /// the destination array at which storing begins. + /// A 32-bit integer that represents the number of elements to copy. + /// + /// is a null reference (Nothing in Visual Basic). + /// + /// is outside the range of valid indexes + /// for the unmanaged array or is greater than the number of elements + /// from to the end of the unmanaged array + /// -or- + /// is outside the range of valid indexes + /// for the array or is greater than the number of elements + /// from to the end of the array. + /// + public void CopyTo(T[] array, int sourceIndex, int destinationIndex, int length) + { + EnsureNotDisposed(); + if (array == null) + { + throw new ArgumentNullException("array"); + } + if ((sourceIndex >= this.length) || (sourceIndex < 0)) + { + throw new ArgumentOutOfRangeException("sourceIndex"); + } + if ((destinationIndex >= array.Length) || (destinationIndex < 0)) + { + throw new ArgumentOutOfRangeException("destinationIndex"); + } + if ((sourceIndex + length > this.length) || + (destinationIndex + length > array.Length) || + (length < 1)) + { + throw new ArgumentOutOfRangeException("length"); + } + + if (isOneBit || isFourBit) + { + for (int i = 0; i != length; i++) + { + array[destinationIndex++] = GetValueInternal(sourceIndex++); + } + } + else + { + GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned); + byte* dst = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(array, destinationIndex); + CopyMemory(dst, baseAddress + (size * sourceIndex), size * length); + handle.Free(); + } + } + + /// + /// Copies a range of elements from the array starting at the specified + /// and pastes them to the unmanaged array + /// starting at the specified . + /// The length and the indexes are specified as 32-bit integers. + /// + /// The array that holds the data. + /// A 32-bit integer that represents the index + /// in the array at which copying begins. + /// A 32-bit integer that represents the index in + /// the unmanaged array at which storing begins. + /// A 32-bit integer that represents the number of elements to copy. + /// + /// is a null reference (Nothing in Visual Basic). + /// + /// is outside the range of valid indexes + /// for the array or is greater than the number of elements + /// from to the end of the array + /// -or- + /// is outside the range of valid indexes + /// for the unmanaged array or is greater than the number of elements + /// from to the end of the unmanaged array. + /// + public void CopyFrom(T[] array, int sourceIndex, int destinationIndex, int length) + { + EnsureNotDisposed(); + if (array == null) + { + throw new ArgumentNullException("array"); + } + if ((destinationIndex >= this.length) || (destinationIndex < 0)) + { + throw new ArgumentOutOfRangeException("destinationIndex"); + } + if ((sourceIndex >= array.Length) || (sourceIndex < 0)) + { + throw new ArgumentOutOfRangeException("sourceIndex"); + } + if ((destinationIndex + length > this.length) || + (sourceIndex + length > array.Length) || + (length < 1)) + { + throw new ArgumentOutOfRangeException("length"); + } + + if (isOneBit || isFourBit) + { + for (int i = 0; i != length; i++) + { + SetValueInternal(array[sourceIndex++], destinationIndex++); + } + } + else + { + GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned); + byte* src = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(array, sourceIndex); + CopyMemory(baseAddress + (size * destinationIndex), src, size * length); + handle.Free(); + } + } + + /// + /// Returns the represented block of memory as an array of . + /// + /// The represented block of memory. + public byte[] ToByteArray() + { + EnsureNotDisposed(); + byte[] result; + if (isOneBit) + { + result = new byte[(length + 7) / 8]; + } + else if (isFourBit) + { + result = new byte[(length + 3) / 4]; + } + else + { + result = new byte[size * length]; + } + fixed (byte* dst = result) + { + CopyMemory(dst, baseAddress, result.Length); + } + return result; + } + + /// + /// Gets or sets the value at the specified position in the array. + /// + /// A 32-bit integer that represents the position + /// of the array element to get. + /// The value at the specified position in the array. + /// + /// is outside the range of valid indexes + /// for the unmanaged array. + public T this[int index] + { + get + { + return GetValue(index); + } + set + { + SetValue(value, index); + } + } + + /// + /// Gets or sets the values of the unmanaged array. + /// + public T[] Data + { + get + { + return GetValues(0, length); + } + set + { + if (value == null) + { + throw new ArgumentNullException("value"); + } + if (value.Length != length) + { + throw new ArgumentOutOfRangeException("value.Lengt"); + } + SetValues(value, 0); + } + } + + /// + /// Gets the length of the unmanaged array. + /// + public int Length + { + get + { + EnsureNotDisposed(); + return length; + } + } + + /// + /// Gets the base address of the represented memory block. + /// + public IntPtr BaseAddress + { + get + { + EnsureNotDisposed(); + return new IntPtr(baseAddress); + } + } + + /// + /// Creates a shallow copy of the . + /// + /// A shallow copy of the . + public object Clone() + { + EnsureNotDisposed(); + return new MemoryArray(baseAddress, length); + } + + /// + /// Gets a 32-bit integer that represents the total number of elements + /// in the . + /// + public int Count + { + get { EnsureNotDisposed(); return length; } + } + + /// + /// Gets a value indicating whether access to the + /// is synchronized (thread safe). + /// + public bool IsSynchronized + { + get { EnsureNotDisposed(); return false; } + } + + /// + /// Gets an object that can be used to synchronize access to the . + /// + public object SyncRoot + { + get + { + EnsureNotDisposed(); + if (syncRoot == null) + { + System.Threading.Interlocked.CompareExchange(ref syncRoot, new object(), null); + } + return syncRoot; + } + } + + /// + /// Retrieves an object that can iterate through the individual + /// elements in this . + /// + /// An for the . + public IEnumerator GetEnumerator() + { + EnsureNotDisposed(); + T[] values = GetValues(0, length); + for (int i = 0; i != values.Length; i++) + { + yield return values[i]; + } + } + + /// + /// Retrieves an object that can iterate through the individual + /// elements in this . + /// + /// An for the . + IEnumerator IEnumerable.GetEnumerator() + { + EnsureNotDisposed(); + T[] values = GetValues(0, length); + for (int i = 0; i != values.Length; i++) + { + yield return values[i]; + } + } + + /// + /// Releases all ressources. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Releases allocated handles associated with this instance. + /// + /// true to release managed resources. + protected virtual void Dispose(bool disposing) + { + if (baseAddress != null) + { + if (handle.IsAllocated) + handle.Free(); + baseAddress = null; + buffer = null; + length = 0; + syncRoot = null; + } + } + + /// + /// Throws an if + /// this instance is disposed. + /// + protected virtual void EnsureNotDisposed() + { + if (baseAddress == null) + throw new ObjectDisposedException("This instance is disposed."); + } + + /// + /// Tests whether the specified structure is equivalent to this + /// structure. + /// + /// The structure to test. + /// true if is a + /// instance equivalent to this structure; otherwise, + /// false. + public override bool Equals(object obj) + { + EnsureNotDisposed(); + return ((obj is MemoryArray) && Equals((MemoryArray)obj)); + } + + /// + /// Tests whether the specified structure is equivalent to this + /// structure. + /// + /// The structure to test. + /// true if is equivalent to this + /// structure; otherwise, + /// false. + public bool Equals(MemoryArray other) + { + EnsureNotDisposed(); + return ((this.baseAddress == other.baseAddress) && (this.length == other.length)); + } + + /// + /// Serves as a hash function for a particular type. + /// + /// A hash code for the current . + public override int GetHashCode() + { + EnsureNotDisposed(); + return (int)baseAddress ^ length; + } + + /// + /// Copies a block of memory from one location to another. + /// + /// Pointer to the starting address of the copy destination. + /// Pointer to the starting address of the block of memory to be copied. + /// Size of the block of memory to copy, in bytes. + protected static unsafe void CopyMemory(byte* dest, byte* src, int len) + { + if (len >= 0x10) + { + do + { + *((int*)dest) = *((int*)src); + *((int*)(dest + 4)) = *((int*)(src + 4)); + *((int*)(dest + 8)) = *((int*)(src + 8)); + *((int*)(dest + 12)) = *((int*)(src + 12)); + dest += 0x10; + src += 0x10; + } + while ((len -= 0x10) >= 0x10); + } + if (len > 0) + { + if ((len & 8) != 0) + { + *((int*)dest) = *((int*)src); + *((int*)(dest + 4)) = *((int*)(src + 4)); + dest += 8; + src += 8; + } + if ((len & 4) != 0) + { + *((int*)dest) = *((int*)src); + dest += 4; + src += 4; + } + if ((len & 2) != 0) + { + *((short*)dest) = *((short*)src); + dest += 2; + src += 2; + } + if ((len & 1) != 0) + { + *dest = *src; + } + } + } + } +} + +namespace FreeImageAPI.Metadata +{ + /// + /// Base class that represents a collection of all tags contained in a metadata model. + /// + /// + /// The MetedataModel class is an abstract base class, which is inherited by + /// several derived classes, one for each existing metadata model. + /// + public abstract class MetadataModel : IEnumerable + { + /// + /// Handle to the encapsulated FreeImage-bitmap. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected readonly FIBITMAP dib; + + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + /// + /// is null. + protected MetadataModel(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + this.dib = dib; + } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public abstract FREE_IMAGE_MDMODEL Model + { + get; + } + + /// + /// Adds new tag to the bitmap or updates its value in case it already exists. + /// will be used as key. + /// + /// The tag to add or update. + /// Returns true on success, false on failure. + /// + /// is null. + /// + /// The tags model differs from this instances model. + public bool AddTag(MetadataTag tag) + { + if (tag == null) + { + throw new ArgumentNullException("tag"); + } + if (tag.Model != Model) + { + throw new ArgumentException("tag.Model"); + } + return tag.AddToImage(dib); + } + + /// + /// Adds a list of tags to the bitmap or updates their values in case they already exist. + /// will be used as key. + /// + /// A list of tags to add or update. + /// Returns the number of successfully added tags. + /// + /// is null. + public int AddTag(IEnumerable list) + { + if (list == null) + { + throw new ArgumentNullException("list"); + } + int count = 0; + foreach (MetadataTag tag in list) + { + if (tag.Model == Model && tag.AddToImage(dib)) + { + count++; + } + } + return count; + } + + /// + /// Removes the specified tag from the bitmap. + /// + /// The key of the tag. + /// Returns true on success, false on failure. + /// + /// is null. + public bool RemoveTag(string key) + { + if (key == null) + { + throw new ArgumentNullException("key"); + } + return FreeImage.SetMetadata(Model, dib, key, FITAG.Zero); + } + + /// + /// Destroys the metadata model + /// which will remove all tags of this model from the bitmap. + /// + /// Returns true on success, false on failure. + public bool DestoryModel() + { + return FreeImage.SetMetadata(Model, dib, null, FITAG.Zero); + } + + /// + /// Returns the specified metadata tag. + /// + /// The key of the tag. + /// The metadata tag. + /// + /// is null. + public MetadataTag GetTag(string key) + { + if (key == null) + { + throw new ArgumentNullException("key"); + } + MetadataTag tag; + return FreeImage.GetMetadata(Model, dib, key, out tag) ? tag : null; + } + + /// + /// Returns whether the specified tag exists. + /// + /// The key of the tag. + /// True in case the tag exists, else false. + /// + /// is null. + public bool TagExists(string key) + { + if (key == null) + { + throw new ArgumentNullException("key"); + } + MetadataTag tag; + return FreeImage.GetMetadata(Model, dib, key, out tag); + } + + /// + /// Returns a list of all metadata tags this instance represents. + /// + public List List + { + get + { + List list = new List((int)FreeImage.GetMetadataCount(Model, dib)); + MetadataTag tag; + FIMETADATA mdHandle = FreeImage.FindFirstMetadata(Model, dib, out tag); + if (!mdHandle.IsNull) + { + do + { + list.Add(tag); + } + while (FreeImage.FindNextMetadata(mdHandle, out tag)); + FreeImage.FindCloseMetadata(mdHandle); + } + return list; + } + } + + /// + /// Returns the tag at the given index. + /// + /// Index of the tag to return. + /// The tag at the given index. + protected MetadataTag GetTagFromIndex(int index) + { + if (index >= Count || index < 0) + { + throw new ArgumentOutOfRangeException("index"); + } + MetadataTag tag; + int count = 0; + FIMETADATA mdHandle = FreeImage.FindFirstMetadata(Model, dib, out tag); + if (!mdHandle.IsNull) + { + try + { + do + { + if (count++ == index) + { + break; + } + } + while (FreeImage.FindNextMetadata(mdHandle, out tag)); + } + finally + { + FreeImage.FindCloseMetadata(mdHandle); + } + } + return tag; + } + + /// + /// Returns the metadata tag at the given index. This operation is slow when accessing all tags. + /// + /// Index of the tag. + /// The metadata tag. + /// + /// is greater or equal Count + /// or index is less than zero. + public MetadataTag this[int index] + { + get + { + return GetTagFromIndex(index); + } + } + + /// + /// Retrieves an object that can iterate through the individual MetadataTags in this MetadataModel. + /// + /// An for the + /// . + public IEnumerator GetEnumerator() + { + return List.GetEnumerator(); + } + + /// + /// Returns the number of metadata tags this instance represents. + /// + public int Count + { + get { return (int)FreeImage.GetMetadataCount(Model, dib); } + } + + /// + /// Returns whether this model exists in the bitmaps metadata structure. + /// + public bool Exists + { + get + { + return Count > 0; + } + } + + /// + /// Searches for a pattern in each metadata tag and returns the result as a list. + /// + /// The regular expression to use for the search. + /// A bitfield that controls which fields should be searched in. + /// A list containing all found metadata tags. + /// + /// is null. + /// + /// is empty. + public List RegexSearch(string searchPattern, MD_SEARCH_FLAGS flags) + { + if (searchPattern == null) + { + throw new ArgumentNullException("searchString"); + } + if (searchPattern.Length == 0) + { + throw new ArgumentException("searchString is empty"); + } + List result = new List(Count); + Regex regex = new Regex(searchPattern); + List list = List; + foreach (MetadataTag tag in list) + { + if (((flags & MD_SEARCH_FLAGS.KEY) > 0) && regex.Match(tag.Key).Success) + { + result.Add(tag); + continue; + } + if (((flags & MD_SEARCH_FLAGS.DESCRIPTION) > 0) && regex.Match(tag.Description).Success) + { + result.Add(tag); + continue; + } + if (((flags & MD_SEARCH_FLAGS.TOSTRING) > 0) && regex.Match(tag.ToString()).Success) + { + result.Add(tag); + continue; + } + } + result.Capacity = result.Count; + return result; + } + + /// + /// Returns the value of the specified tag. + /// + /// Type of the tag's data. + /// The key of the tag. + /// The value of the specified tag. + protected T? GetTagValue(string key) where T : struct + { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException("key"); + } + MetadataTag tag = GetTag(key); + if (tag != null) + { + T[] value = tag.Value as T[]; + if ((value != null) && (value.Length != 0)) + { + return value[0]; + } + } + return null; + } + + /// + /// Returns an array containing the data of the specified tag. + /// + /// The type of the tag's data. + /// The key of the tag. + /// An array containing the data of the specified tag. + protected T[] GetTagArray(string key) where T : struct + { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException("key"); + } + MetadataTag tag = GetTag(key); + return (tag == null) ? null : tag.Value as T[]; + } + + /// + /// Returns the string contained by the specified tag. + /// + /// The key of the tag. + /// The string contained by the specified tag. + protected string GetTagText(string key) + { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException("key"); + } + MetadataTag tag = GetTag(key); + return (tag == null) ? null : tag.Value as string; + } + + /// + /// Returns an array containg the data of the specified tag + /// as unsigned 32bit integer. + /// + /// The key of the tag. + /// An array containg the data of the specified tag + /// as unsigned 32bit integer. + protected uint[] GetUInt32Array(string key) + { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException("key"); + } + uint[] result = null; + MetadataTag tag = GetTag(key); + if (tag != null) + { + object value = tag.Value; + if (value != null) + { + if (value is ushort[]) + { + ushort[] array = (ushort[])value; + result = new uint[array.Length]; + for (int i = 0, j = array.Length; i < j; i++) + { + result[i] = (uint)array[i]; + } + } + else if (value is uint[]) + { + result = (uint[])value; + } + } + } + return result; + } + + /// + /// Returns the value of the tag as unsigned 32bit integer. + /// + /// The key of the tag. + /// The value of the tag as unsigned 32bit integer. + protected uint? GetUInt32Value(string key) + { + uint[] value = GetUInt32Array(key); + return value == null ? default(uint?) : value[0]; + } + + /// + /// Sets the value of the specified tag. + /// + /// The type of the tag's data. + /// The key of the tag. + /// The new value of the specified tag or null. + protected void SetTagValue(string key, T? value) where T : struct + { + SetTagValue(key, value.HasValue ? new T[] { value.Value } : null); + } + + /// + /// Sets the value of the specified tag. + /// + /// The key of the tag. + /// The new value of the specified tag or null. + protected void SetTagValue(string key, object value) + { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException("key"); + } + if (value == null) + { + RemoveTag(key); + } + else + { + MetadataTag tag = GetTag(key); + if (tag == null) + { + tag = new MetadataTag(Model); + tag.Key = key; + tag.Value = value; + AddTag(tag); + } + else + { + tag.Value = value; + } + } + } + + /// + /// Sets the value of the specified tag as undefined. + /// + /// The key of the tag. + /// The new value of the specified tag or null. + protected void SetTagValueUndefined(string key, byte[] value) + { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException("key"); + } + if (value == null) + { + RemoveTag(key); + } + else + { + MetadataTag tag = GetTag(key); + if (tag == null) + { + tag = new MetadataTag(Model); + tag.Key = key; + tag.SetValue(value, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED); + AddTag(tag); + } + else + { + tag.Value = value; + } + } + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The string containing the . + /// The equivalent for the + /// specified . + protected static DirectionReference? ToDirectionType(string s) + { + if (string.IsNullOrEmpty(s)) + return null; + switch (s[0]) + { + case 'T': + return DirectionReference.TrueDirection; + case 'M': + return DirectionReference.MagneticDirection; + default: + return DirectionReference.Undefined; + } + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The to convert. + /// The equivalent for the + /// specified . + protected static string ToString(DirectionReference? type) + { + if (type.HasValue) + { + switch (type.Value) + { + case DirectionReference.TrueDirection: + return "T"; + case DirectionReference.MagneticDirection: + return "M"; + default: + return "\0"; + } + } + return null; + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The string containing the . + /// The equivalent for the + /// specified . + protected static VelocityUnit? ToUnitType(string s) + { + if (string.IsNullOrEmpty(s)) + return null; + switch (s[0]) + { + case 'K': + return VelocityUnit.Kilometers; + case 'M': + return VelocityUnit.Miles; + case 'N': + return VelocityUnit.Knots; + default: + return VelocityUnit.Undefinied; + } + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The to convert. + /// The equivalent for the + /// specified . + protected static string ToString(VelocityUnit? type) + { + if (type.HasValue) + { + switch (type.Value) + { + case VelocityUnit.Kilometers: + return "K"; + case VelocityUnit.Miles: + return "M"; + case VelocityUnit.Knots: + return "N"; + default: + return "\0"; + } + } + return null; + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The string containing the . + /// The equivalent for the + /// specified . + protected static LongitudeType? ToLongitudeType(string s) + { + if (string.IsNullOrEmpty(s)) + return null; + switch (s[0]) + { + case 'E': + return LongitudeType.East; + case 'W': + return LongitudeType.West; + default: + return LongitudeType.Undefined; + } + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The to convert. + /// The equivalent for the + /// specified . + protected static string ToString(LongitudeType? type) + { + if (type.HasValue) + { + switch (type.Value) + { + case LongitudeType.East: + return "E"; + case LongitudeType.West: + return "W"; + default: + return "\0"; + } + } + return null; + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The string containing the . + /// The equivalent for the + /// specified . + protected static LatitudeType? ToLatitudeType(string s) + { + if (string.IsNullOrEmpty(s)) + return null; + switch (s[0]) + { + case 'N': + return LatitudeType.North; + case 'S': + return LatitudeType.South; + default: + return LatitudeType.Undefined; + } + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The to convert. + /// The equivalent for the + /// specified . + protected static string ToString(LatitudeType? type) + { + if (type.HasValue) + { + switch (type.Value) + { + case LatitudeType.North: + return "N"; + case LatitudeType.South: + return "S"; + default: + return "\0"; + } + } + return null; + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The string containing the . + /// The equivalent for the + /// specified . + protected static InteroperabilityMode? ToInteroperabilityType(string s) + { + if (string.IsNullOrEmpty(s)) + return null; + if (s.StartsWith("R98")) + return InteroperabilityMode.R98; + if (s.StartsWith("THM")) + return InteroperabilityMode.THM; + return InteroperabilityMode.Undefined; + } + + /// + /// Returns the equivalent for the + /// specified . + /// + /// The to convert. + /// The equivalent for the + /// specified . + protected static string ToString(InteroperabilityMode? type) + { + if (type.HasValue) + { + switch (type.Value) + { + case InteroperabilityMode.R98: + return "R98"; + case InteroperabilityMode.THM: + return "THM"; + default: + return "\0\0\0"; + } + } + return null; + } + + /// + /// Specified different unit types. + /// + public enum VelocityUnit + { + /// + /// No or unknown type. + /// + Undefinied, + + /// + /// Kilometers per hour. + /// + Kilometers, + + /// + /// Miles per hour. + /// + Miles, + + /// + /// Knots. + /// + Knots, + } + + /// + /// Specifies different direction types. + /// + public enum DirectionReference + { + /// + /// No or unknown direction type. + /// + Undefined, + + /// + /// True direction. + /// + TrueDirection, + + /// + /// Magnatic direction. + /// + MagneticDirection, + } + + /// + /// Specifies the type of a latitude value. + /// + public enum LatitudeType + { + /// + /// No or unknown type. + /// + Undefined, + + /// + /// North. + /// + North, + + /// + /// South. + /// + South, + } + + /// + /// Specifies the type of a longitude value. + /// + public enum LongitudeType + { + /// + /// No or unknown type. + /// + Undefined, + + /// + /// East. + /// + East, + + /// + /// West. + /// + West, + } + + /// + /// Specifies different altitude types. + /// + public enum AltitudeType + { + /// + /// No or unknown type. + /// + Undefined, + + /// + /// East. + /// + AboveSeaLevel, + + /// + /// West. + /// + BelowSeaLevel, + } + + /// + /// Specifies interoperability types. + /// + public enum InteroperabilityMode + { + /// + /// No or unknown type. + /// + Undefined, + + /// + /// Indicates a file conforming to R98 file specification of Recommended + /// Exif Interoperability Rules (ExifR98) or to DCF basic file stipulated + /// by Design Rule for Camera File System. + /// + R98, + + /// + /// Indicates a file conforming to DCF thumbnail file stipulated by Design + /// rule for Camera File System. + /// + THM, + } + + /// + /// Specifies orientation of images. + /// + public enum ExifImageOrientation : ushort + { + /// + /// Undefinied orientation. + /// + Undefined, + + /// + /// TopLeft. + /// + TopLeft = 1, + + /// + /// TopRight. + /// + TopRight, + + /// + /// BottomRight. + /// + BottomRight, + + /// + /// BottomLeft. + /// + BottomLeft, + + /// + /// LeftTop. + /// + LeftTop, + + /// + /// RightTop. + /// + RightTop, + + /// + /// RightBottom. + /// + RightBottom, + + /// + /// LeftBottom. + /// + LeftBottom, + } + + /// + /// Converts the model of the MetadataModel object to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + return Model.ToString(); + } + } +} + + #region Metadata Models + +namespace FreeImageAPI.Metadata +{ + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_ANIMATION : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_ANIMATION(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_ANIMATION; } + } + + /// + /// Gets or sets the width of the entire canvas area, that each page is displayed in. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? LogicalWidth + { + get + { + return GetTagValue("LogicalWidth"); + } + set + { + SetTagValue("LogicalWidth", value); + } + } + + /// + /// Gets or sets the height of the entire canvas area, that each page is displayed in. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? LogicalHeight + { + get + { + return GetTagValue("LogicalHeight"); + } + set + { + SetTagValue("LogicalHeight", value); + } + } + + /// + /// Gets or sets the global palette of the GIF image. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public Palette GlobalPalette + { + get + { + MetadataTag mdtag = GetTag("GlobalPalette"); + return (mdtag == null) ? null : new Palette(mdtag); + } + set + { + SetTagValue("GlobalPalette", (value != null) ? null : value.Data); + } + } + + /// + /// Gets or sets the number of replays for the animation. + /// Use 0 (zero) to specify an infinte number of replays. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? LoopCount + { + get + { + return GetTagValue("Loop"); + } + set + { + SetTagValue("Loop", value); + } + } + + /// + /// Gets or sets the horizontal offset within the logical canvas area, this frame is to be displayed at. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? FrameLeft + { + get + { + return GetTagValue("FrameLeft"); + } + set + { + SetTagValue("FrameLeft", value); + } + } + + /// + /// Gets or sets the vertical offset within the logical canvas area, this frame is to be displayed at. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? FrameTop + { + get + { + return GetTagValue("FrameTop"); + } + set + { + SetTagValue("FrameTop", value); + } + } + + /// + /// Gets or sets a flag to supress saving the dib's attached palette + /// (making it use the global palette). The local palette is the palette used by a page. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public bool? NoLocalPalette + { + get + { + byte? useGlobalPalette = GetTagValue("NoLocalPalette"); + return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?); + } + set + { + byte? val = null; + if (value.HasValue) + { + val = (byte)(value.Value ? 1 : 0); + } + SetTagValue("NoLocalPalette", val); + } + } + + /// + /// Gets or sets a value indicating whether the image is interlaced. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public bool? Interlaced + { + get + { + byte? useGlobalPalette = GetTagValue("Interlaced"); + return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?); + } + set + { + byte? val = null; + if (value.HasValue) + { + val = (byte)(value.Value ? 1 : 0); + } + SetTagValue("Interlaced", val); + } + } + + /// + /// Gets or sets the amout of time in milliseconds this frame is to be displayed. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? FrameTime + { + get + { + return GetTagValue("FrameTime"); + } + set + { + SetTagValue("FrameTime", value); + } + } + + /// + /// Gets or sets this frame's disposal method. Generally, this method defines, how to + /// remove or replace a frame when the next frame has to be drawn. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public DisposalMethodType? DisposalMethod + { + get + { + return GetTagValue("DisposalMethod"); + } + set + { + SetTagValue("DisposalMethod", value); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_COMMENTS : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_COMMENTS(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_COMMENTS; } + } + + /// + /// Gets or sets the comment of the image. + /// Supported formats are JPEG, PNG and GIF. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Comment + { + get + { + return GetTagText("Comment"); + } + set + { + SetTagValue("Comment", value); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_CUSTOM : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_CUSTOM(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_CUSTOM; } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_EXIF_EXIF : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_EXIF_EXIF(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF; } + } + + /// + /// Gets or sets the version of this standard supported. + /// Constant length or 4. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] ExifVersion + { + get + { + return GetTagArray("ExifVersion"); + } + set + { + FreeImage.Resize(ref value, 4); + SetTagValueUndefined("ExifVersion", value); + } + } + + /// + /// Gets or sets the Flashpix format version supported by a FPXR file. + /// Constant length or 4. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] FlashpixVersion + { + get + { + return GetTagArray("FlashpixVersion"); + } + set + { + FreeImage.Resize(ref value, 4); + SetTagValueUndefined("FlashpixVersion", value); + } + } + + /// + /// Gets or sets the color space information tag. + /// See remarks for further information. + /// + /// + /// The following values are defined: + /// + /// + /// ID + /// Description + /// + /// + /// 1 + /// sRGB (default) + /// + /// + /// 0xFFFF + /// uncalibrated + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? ColorSpace + { + get + { + return GetTagValue("ColorSpace"); + } + set + { + SetTagValue("ColorSpace", value); + } + } + + /// + /// Gets or sets the valid width of a compressed image. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? PixelXDimension + { + get + { + return GetUInt32Value("PixelXDimension"); + } + set + { + RemoveTag("PixelXDimension"); + if (value.HasValue) + { + SetTagValue("PixelXDimension", value.Value); + } + } + } + + /// + /// Gets or sets the valid height of a compressed image. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? PixelYDimension + { + get + { + return GetUInt32Value("PixelYDimension"); + } + set + { + RemoveTag("PixelYDimension"); + if (value.HasValue) + { + SetTagValue("PixelYDimension", value.Value); + } + } + } + + /// + /// Gets or sets components configuration. See remarks for further information. + /// Constant length of 4. + /// + /// + /// The channels of each component are arranged in order from the 1st component to the 4th. + /// For uncompressed data the data arrangement is given in the PhotometricInterpretation tag. + /// However, since PhotometricInterpretation can only express the order of Y,Cb and Cr, + /// this tag is provided for cases when compressed data uses components other than Y, Cb, + /// and Cr and to enable support of other sequences. + /// Default = 4 5 6 0 (if RGB uncompressed) + /// The following values are defined: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// does not exist + /// + /// + /// 1 + /// Y + /// + /// + /// 2 + /// Cb + /// + /// + /// 3 + /// Cr + /// + /// + /// 4 + /// R + /// + /// + /// 5 + /// R + /// + /// + /// 6 + /// R + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public byte[] ComponentsConfiguration + { + get + { + return GetTagArray("ComponentsConfiguration"); + } + set + { + FreeImage.Resize(ref value, 4); + SetTagValueUndefined("ComponentsConfiguration", value); + } + } + + /// + /// Gets or sets compression mode used for a compressed image is indicated + /// in unit bits per pixel. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? CompressedBitsPerPixel + { + get + { + return GetTagValue("CompressedBitsPerPixel"); + } + set + { + SetTagValue("CompressedBitsPerPixel", value); + } + } + + /// + /// Gets or sets a tag for manufacturers of Exif writers to record any desired information. + /// The contents are up to the manufacturer, but this tag should not be used for any other + /// than its intended purpose. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] MakerNote + { + get + { + return GetTagArray("FlashpixVersion"); + } + set + { + SetTagValueUndefined("FlashpixVersion", value); + } + } + + /// + /// Gets or sets a tag for Exif users to write keywords or comments on the image besides + /// those in ImageDescription, and without the character code limitations of the ImageDescription tag. + /// Minimum length of 8. See remarks for further information. + /// + /// + /// The character code used in the UserComment tag is identified based on an ID code in a fixed 8-byte + /// area at the start of the tag data area. The unused portion of the area is padded with NULL. + /// The ID code for the UserComment area may be a Defined code such as JIS or ASCII, or may be Undefined. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public byte[] UserComment + { + get + { + return GetTagArray("UserComment"); + } + set + { + FreeImage.Resize(ref value, 8, int.MaxValue); + SetTagValueUndefined("UserComment", value); + } + } + + /// + /// Gets or sets the name of an audio file related to the image data. + /// The format is 8.3. + /// Constant length of 12 + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string RelatedSoundFile + { + get + { + string text = GetTagText("RelatedSoundFile"); + if (!string.IsNullOrEmpty(text)) + { + text = text.Substring(0, text.Length - 1); + } + return text; + } + set + { + if (value != null) + { + FreeImage.Resize(ref value, 12); + value += '\0'; + } + SetTagValue("RelatedSoundFile", value); + } + } + + /// + /// Gets or sets the date and time when the original image data was generated. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public DateTime? DateTimeOriginal + { + get + { + DateTime? result = null; + string text = GetTagText("DateTimeOriginal"); + if (text != null) + { + try + { + result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null); + } + catch + { + } + } + return result; + } + set + { + string val = null; + if (value.HasValue) + { + try + { + val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0"); + } + catch + { + } + } + SetTagValue("DateTimeOriginal", val); + } + } + + /// + /// Gets or sets the date and time when the image was stored as digital data. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public DateTime? DateTimeDigitized + { + get + { + DateTime? result = null; + string text = GetTagText("DateTimeDigitized"); + if (text != null) + { + try + { + result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null); + } + catch + { + } + } + return result; + } + set + { + string val = null; + if (value.HasValue) + { + try + { + val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0"); + } + catch + { + } + } + SetTagValue("DateTimeDigitized", val); + } + } + + /// + /// Gets or sets a tag used to record fractions of seconds for the DateTime tag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SubsecTime + { + get + { + string text = GetTagText("SubsecTime"); + if (!string.IsNullOrEmpty(text)) + { + text = text.Substring(0, text.Length - 1); + } + return text; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("SubsecTime", value); + } + } + + /// + /// Gets or sets a tag used to record fractions of seconds for the DateTimeOriginal tag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SubsecTimeOriginal + { + get + { + string text = GetTagText("SubsecTimeOriginal"); + if (!string.IsNullOrEmpty(text)) + { + text = text.Substring(0, text.Length - 1); + } + return text; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("SubsecTimeOriginal", value); + } + } + + /// + /// Gets or sets a tag used to record fractions of seconds for the DateTimeDigitized tag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SubsecTimeDigitized + { + get + { + string text = GetTagText("SubsecTimeDigitized"); + if (!string.IsNullOrEmpty(text)) + { + text = text.Substring(0, text.Length - 1); + } + return text; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("SubsecTimeDigitized", value); + } + } + + /// + /// Gets or the exposure time, given in seconds (sec). + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? ExposureTime + { + get + { + return GetTagValue("ExposureTime"); + } + set + { + SetTagValue("ExposureTime", value); + } + } + + /// + /// Gets or the F number. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? FNumber + { + get + { + return GetTagValue("FNumber"); + } + set + { + SetTagValue("FNumber", value); + } + } + + /// + /// Gets or sets the class of the program used by the camera to set exposure when the + /// picture is taken. + /// See remarks for further information. + /// + /// + /// The following values are defined: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// not defined + /// + /// + /// 1 + /// manual + /// + /// + /// 2 + /// normal program + /// + /// + /// 3 + /// aperture priority + /// + /// + /// 4 + /// shutter priority + /// + /// + /// 5 + /// create program + /// + /// + /// 6 + /// action program + /// + /// + /// 7 + /// portrait mode + /// + /// + /// 8 + /// landscape mode + /// + /// + /// others + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? ExposureProgram + { + get + { + return GetTagValue("ExposureProgram"); + } + set + { + SetTagValue("ExposureProgram", value); + } + } + + /// + /// Gets or sets the spectral sensitivity of each channel of the camera used. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SpectralSensitivity + { + get + { + string text = GetTagText("SpectralSensitivity"); + if (!string.IsNullOrEmpty(text)) + { + text = text.Substring(0, text.Length - 1); + } + return text; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("SpectralSensitivity", value); + } + } + + /// + /// Gets or sets the the ISO Speed and ISO Latitude of the camera or input device as + /// specified in ISO 12232. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort[] ISOSpeedRatings + { + get + { + return GetTagArray("ISOSpeedRatings"); + } + set + { + SetTagValue("ISOSpeedRatings", value); + } + } + + /// + /// Gets or sets the Opto-Electric Conversion Function (OECF) specified in ISO 14524. + /// OECF is the relationship between the camera optical input and the image values. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] OECF + { + get + { + return GetTagArray("OECF"); + } + set + { + SetTagValueUndefined("OECF", value); + } + } + + /// + /// Gets or sets the shutter speed. The unit is the APEX (Additive System of Photographic Exposure). + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIRational? ShutterSpeedValue + { + get + { + return GetTagValue("ShutterSpeedValue"); + } + set + { + SetTagValue("ShutterSpeedValue", value); + } + } + + /// + /// Gets or sets the lens aperture. The unit is the APEX value. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? ApertureValue + { + get + { + return GetTagValue("ApertureValue"); + } + set + { + SetTagValue("ApertureValue", value); + } + } + + /// + /// Gets or sets the value of brightness. The unit is the APEX value. + /// Ordinarily it is given in the range of -99.99 to 99.99. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIRational? BrightnessValue + { + get + { + return GetTagValue("BrightnessValue"); + } + set + { + SetTagValue("BrightnessValue", value); + } + } + + /// + /// Gets or sets the exposure bias. The unit is the APEX value. + /// Ordinarily it is given in the range of �99.99 to 99.99. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIRational? ExposureBiasValue + { + get + { + return GetTagValue("ExposureBiasValue"); + } + set + { + SetTagValue("ExposureBiasValue", value); + } + } + + /// + /// Gets or sets the smallest F number of the lens. The unit is the APEX value. + /// Ordinarily it is given in the range of 00.00 to 99.99, + /// but it is not limited to this range. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? MaxApertureValue + { + get + { + return GetTagValue("MaxApertureValue"); + } + set + { + SetTagValue("MaxApertureValue", value); + } + } + + /// + /// Gets or sets distance to the subject, given in meters. + /// Note that if the numerator of the recorded value is FFFFFFFF, infinity shall be indicated; + /// and if the numerator is 0, distance unknown shall be indicated. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? SubjectDistance + { + get + { + return GetTagValue("SubjectDistance"); + } + set + { + SetTagValue("SubjectDistance", value); + } + } + + /// + /// Gets or sets the metering mode. See remarks for further information. + /// + /// + /// The following values are defined: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// unknown + /// + /// + /// 1 + /// average + /// + /// + /// 2 + /// center-weighted-average + /// + /// + /// 3 + /// spot + /// + /// + /// 4 + /// multi-spot + /// + /// + /// 5 + /// pattern + /// + /// + /// 6 + /// partial + /// + /// + /// other + /// reserved + /// + /// + /// 255 + /// other + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? MeteringMode + { + get + { + return GetTagValue("MeteringMode"); + } + set + { + SetTagValue("MeteringMode", value); + } + } + + /// + /// Gets or sets the kind of light source. + /// See remarks for further information. + /// + /// + /// The following values are defined: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// unknown + /// + /// + /// 1 + /// daylight + /// + /// + /// 2 + /// fluorescent + /// + /// + /// 3 + /// tungsten + /// + /// + /// 4 + /// flash + /// + /// + /// 9 + /// fine weather + /// + /// + /// 10 + /// cloudy weather + /// + /// + /// 11 + /// shade + /// + /// + /// 12 + /// daylight fluorecent (D 5700 - 7100K) + /// + /// + /// 13 + /// day white fluorescent (N 4600 - 5400K) + /// + /// + /// 14 + /// cool white fluorescent (W 3900 - 4500K) + /// + /// + /// 15 + /// white fluorescent (WW 3200 - 3700K) + /// + /// + /// 17 + /// standard light A + /// + /// + /// 18 + /// standard light B + /// + /// + /// 19 + /// standard light C + /// + /// + /// 20 + /// D55 + /// + /// + /// 21 + /// D65 + /// + /// + /// 22 + /// D75 + /// + /// + /// 23 + /// D50 + /// + /// + /// 24 + /// ISO studio tungsten + /// + /// + /// 255 + /// other light source + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? LightSource + { + get + { + return GetTagValue("LightSource"); + } + set + { + SetTagValue("LightSource", value); + } + } + + /// + /// Gets or sets a value indicating the status of flash when the image was shot. + /// Bit 0 indicates the flash firing status, bits 1 and 2 indicate the flash return + /// status, bits 3 and 4 indicate the flash mode, bit 5 indicates whether the flash + /// function is present, and bit 6 indicates "red eye" mode. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? Flash + { + get + { + return GetTagValue("Flash"); + } + set + { + SetTagValue("Flash", value); + } + } + + /// + /// Gets or sets a value indicating the location and area of the main subject in + /// the overall scene. Variable length between 2 and 4. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort[] SubjectArea + { + get + { + return GetTagArray("SubjectArea"); + } + set + { + FreeImage.Resize(ref value, 2, 4); + SetTagValue("SubjectArea", value); + } + } + + /// + /// Gets or sets the actual focal length of the lens, in mm. + /// Conversion is not made to the focal length of a 35 mm film camera. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? FocalLength + { + get + { + return GetTagValue("FocalLength"); + } + set + { + SetTagValue("FocalLength", value); + } + } + + /// + /// Gets or sets the strobe energy at the time the image is captured, + /// as measured in Beam Candle Power Seconds (BCPS). + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? FlashEnergy + { + get + { + return GetTagValue("FlashEnergy"); + } + set + { + SetTagValue("FlashEnergy", value); + } + } + + /// + /// Gets or sets the camera or input device spatial frequency table and SFR values + /// in the direction of image width, image height, and diagonal direction, + /// as specified in ISO 12233. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] SpatialFrequencyResponse + { + get + { + return GetTagArray("SpatialFrequencyResponse"); + } + set + { + SetTagValueUndefined("SpatialFrequencyResponse", value); + } + } + + /// + /// Gets or sets the number of pixels in the image width (X) direction per + /// FocalPlaneResolutionUnit on the camera focal plane. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? FocalPlaneXResolution + { + get + { + return GetTagValue("FocalPlaneXResolution"); + } + set + { + SetTagValue("FocalPlaneXResolution", value); + } + } + + /// + /// Gets or sets the number of pixels in the image height (Y) direction per + /// FocalPlaneResolutionUnit on the camera focal plane. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? FocalPlaneYResolution + { + get + { + return GetTagValue("FocalPlaneYResolution"); + } + set + { + SetTagValue("FocalPlaneYResolution", value); + } + } + + /// + /// Gets or sets the unit for measuring FocalPlaneXResolution and FocalPlaneYResolution. + /// This value is the same as the ResolutionUnit. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? FocalPlaneResolutionUnit + { + get + { + return GetTagValue("FocalPlaneResolutionUnit"); + } + set + { + SetTagValue("FocalPlaneResolutionUnit", value); + } + } + + /// + /// Gets or sets the location of the main subject in the scene. + /// The value of this tag represents the pixel at the center of the main subject + /// relative to the left edge, prior to rotation processing as per the Rotation tag. + /// The first value indicates the X column number and second indicates the Y row number. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? SubjectLocation + { + get + { + return GetTagValue("SubjectLocation"); + } + set + { + SetTagValue("SubjectLocation", value); + } + } + + /// + /// Gets or sets the exposure index selected on the camera or input device at the + /// time the image was captured. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? ExposureIndex + { + get + { + return GetTagValue("ExposureIndex"); + } + set + { + SetTagValue("ExposureIndex", value); + } + } + + /// + /// Gets or sets the image sensor type on the camera or input device. + /// See remarks for further information. + /// + /// + /// The following values are defined: + /// + /// + /// ID + /// Description + /// + /// + /// 1 + /// not defined + /// + /// + /// 2 + /// one-chip color area sensor + /// + /// + /// 3 + /// two-chip color area sensor + /// + /// + /// 4 + /// three-chip color area sensor + /// + /// + /// 5 + /// color sequential area sensor + /// + /// + /// 7 + /// trilinear sensor + /// + /// + /// 8 + /// color sequential linear sensor + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? SensingMethod + { + get + { + return GetTagValue("SensingMethod"); + } + set + { + SetTagValue("SensingMethod", value); + } + } + + /// + /// Gets or sets the image source. If a DSC recorded the image, this tag value of this + /// tag always be set to 3, indicating that the image was recorded on a DSC. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte? FileSource + { + get + { + return GetTagValue("FileSource"); + } + set + { + SetTagValueUndefined("FileSource", value.HasValue ? new byte[] { value.Value } : null); + } + } + + /// + /// Gets or sets the type of scene. If a DSC recorded the image, this tag value shall + /// always be set to 1, indicating that the image was directly photographed. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte? SceneType + { + get + { + return GetTagValue("SceneType"); + } + set + { + SetTagValueUndefined("SceneType", value.HasValue ? new byte[] { value.Value } : null); + } + } + + /// + /// Gets or sets the color filter array (CFA) geometric pattern of the image sensor + /// when a one-chip color area sensor is used. It does not apply to all sensing methods. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] CFAPattern + { + get + { + return GetTagArray("CFAPattern"); + } + set + { + SetTagValueUndefined("CFAPattern", value); + } + } + + /// + /// Gets or sets the use of special processing on image data, such as rendering geared to output. + /// When special processing is performed, the reader is expected to disable or minimize any + /// further processing. See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// normal process + /// + /// + /// 1 + /// custom process + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? CustomRendered + { + get + { + return GetTagValue("CustomRendered"); + } + set + { + SetTagValue("CustomRendered", value); + } + } + + /// + /// Gets or sets the exposure mode set when the image was shot. + /// In auto-bracketing mode, the camera shoots a series of frames of the same scene + /// at different exposure settings. See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// auto exposure + /// + /// + /// 1 + /// manual exposure + /// + /// + /// 2 + /// auto bracket + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? ExposureMode + { + get + { + return GetTagValue("ExposureMode"); + } + set + { + SetTagValue("ExposureMode", value); + } + } + + /// + /// Gets or sets the white balance mode set when the image was shot. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// auto white balance + /// + /// + /// 1 + /// manual white balance + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? WhiteBalance + { + get + { + return GetTagValue("WhiteBalance"); + } + set + { + SetTagValue("WhiteBalance", value); + } + } + + /// + /// Gets or sets the digital zoom ratio when the image was shot. + /// If the numerator of the recorded value is 0, this indicates that digital zoom was not used. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? DigitalZoomRatio + { + get + { + return GetTagValue("DigitalZoomRatio"); + } + set + { + SetTagValue("DigitalZoomRatio", value); + } + } + + /// + /// Gets or sets the equivalent focal length assuming a 35mm film camera, in mm. + /// A value of 0 means the focal length is unknown. Note that this tag differs + /// from the FocalLength tag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? FocalLengthIn35mmFilm + { + get + { + return GetTagValue("DigitalZoomRatio"); + } + set + { + SetTagValue("DigitalZoomRatio", value); + } + } + + /// + /// Gets or sets the type of scene that was shot. + /// It can also be used to record the mode in which the image was shot. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// standard + /// + /// + /// 1 + /// landscape + /// + /// + /// 2 + /// portrait + /// + /// + /// 3 + /// night scene + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? SceneCaptureType + { + get + { + return GetTagValue("SceneCaptureType"); + } + set + { + SetTagValue("SceneCaptureType", value); + } + } + + /// + /// Gets or sets the degree of overall image gain adjustment. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// none + /// + /// + /// 1 + /// low gain up + /// + /// + /// 2 + /// high gain up + /// + /// + /// 3 + /// low gain down + /// + /// + /// 4 + /// high gain down + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? GainControl + { + get + { + return GetTagValue("GainControl"); + } + set + { + SetTagValue("GainControl", value); + } + } + + /// + /// Gets or sets the direction of contrast processing applied by the camera + /// when the image was shot. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// normal + /// + /// + /// 1 + /// soft + /// + /// + /// 2 + /// hard + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? Contrast + { + get + { + return GetTagValue("Contrast"); + } + set + { + SetTagValue("Contrast", value); + } + } + + /// + /// Gets or sets the direction of saturation processing applied by the camera + /// when the image was shot. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// normal + /// + /// + /// 1 + /// low saturation + /// + /// + /// 2 + /// high saturation + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? Saturation + { + get + { + return GetTagValue("Saturation"); + } + set + { + SetTagValue("Saturation", value); + } + } + + /// + /// Gets or sets the direction of sharpness processing applied by the camera + /// when the image was shot. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// normal + /// + /// + /// 1 + /// soft + /// + /// + /// 2 + /// hard + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? Sharpness + { + get + { + return GetTagValue("Sharpness"); + } + set + { + SetTagValue("Sharpness", value); + } + } + + /// + /// Gets or sets information on the picture-taking conditions of a particular camera model. + /// The tag is used only to indicate the picture-taking conditions in the reader. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] DeviceSettingDescription + { + get + { + return GetTagArray("DeviceSettingDescription"); + } + set + { + SetTagValueUndefined("DeviceSettingDescription", value); + } + } + + /// + /// Gets or sets the distance to the subject. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 0 + /// unknown + /// + /// + /// 1 + /// macro + /// + /// + /// 2 + /// close view + /// + /// + /// 3 + /// distant view + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? SubjectDistanceRange + { + get + { + return GetTagValue("SubjectDistanceRange"); + } + set + { + SetTagValue("SubjectDistanceRange", value); + } + } + + /// + /// Gets or sets an identifier assigned uniquely to each image. + /// It is recorded as an ASCII string equivalent to hexadecimal notation and 128-bit fixed length. + /// Constant length of 32. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ImageUniqueID + { + get + { + string text = GetTagText("ImageUniqueID"); + if (!string.IsNullOrEmpty(text)) + { + text = text.Substring(0, text.Length - 1); + } + return text; + } + set + { + if (value != null) + { + FreeImage.Resize(ref value, 32); + value += '\0'; + } + SetTagValue("ImageUniqueID", value); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_EXIF_GPS : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_EXIF_GPS(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_GPS; } + } + + /// + /// Gets or sets the GPS version ID. Constant length of 4. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] VersionID + { + get + { + return GetTagArray("GPSVersionID"); + } + set + { + FreeImage.Resize(ref value, 4); + SetTagValue("GPSVersionID", value); + } + } + + /// + /// Gets or sets a value indicating whether the + /// is north or south latitude. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public LatitudeType? LatitudeDirection + { + get + { + return ToLatitudeType(GetTagText("GPSLatitudeRef")); + } + set + { + SetTagValue("GPSLatitudeRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the latitude of the image. The latitude is expressed as three rational + /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public FIURational[] Latitude + { + get + { + return GetTagArray("GPSLatitude"); + } + set + { + FreeImage.Resize(ref value, 3); + SetTagValue("GPSLatitude", value); + } + } + + /// + /// Gets or sets a value indicating whether + /// is east or west longitude. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public LongitudeType? LongitudeDirection + { + get + { + return ToLongitudeType(GetTagText("GPSLongitudeRef")); + } + set + { + SetTagValue("GPSLongitudeRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the longitude of the image. The longitude is expressed as three rational + /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public FIURational[] Longitude + { + get + { + return GetTagArray("GPSLongitude"); + } + set + { + FreeImage.Resize(ref value, 3); + SetTagValue("GPSLongitude", value); + } + } + + /// + /// Gets a value indicating whether is sea level and the altitude + /// is above sea level. If the altitude is below sea level is + /// indicated as an absolute value. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public AltitudeType? AltitudeDirection + { + get + { + byte? flag = GetTagValue("GPSAltitudeRef"); + if (flag.HasValue) + { + switch (flag.Value) + { + case 0: + return AltitudeType.AboveSeaLevel; + case 1: + return AltitudeType.BelowSeaLevel; + default: + return AltitudeType.Undefined; + } + } + return null; + } + set + { + byte? val = null; + if (value.HasValue) + { + switch (value.Value) + { + case AltitudeType.AboveSeaLevel: + val = 0; + break; + + case AltitudeType.BelowSeaLevel: + val = 1; + break; + + default: + val = 2; + break; + } + } + SetTagValue("GPSAltitudeRef", val); + } + } + + /// + /// Gets or sets the altitude based on the reference in . + /// Altitude is expressed as one rational value. The reference unit is meters. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? Altitude + { + get + { + return GetTagValue("GPSAltitude"); + } + set + { + SetTagValue("GPSAltitude", value); + } + } + + /// + /// Gets or sets the sign of the . + /// + /// + /// This is a derived property. There is no metadata tag directly associated + /// with this property value. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public int? AltitudeSign + { + get + { + AltitudeType? seaLevel = AltitudeDirection; + if (seaLevel.HasValue) + { + return (seaLevel.Value == AltitudeType.BelowSeaLevel) ? -1 : 1; + } + return null; + } + set + { + if (value.HasValue) + { + AltitudeDirection = value.Value >= 0 ? AltitudeType.AboveSeaLevel : AltitudeType.BelowSeaLevel; + } + else + { + AltitudeDirection = null; + } + } + } + + /// + /// Gets or sets the signed altitude. + /// Altitude is expressed as one rational value. The reference unit is meters. + /// + /// + /// Altitude is too large to fit into a FIRational. + /// + /// + /// This is a derived property. There is no metadata tag directly associated + /// with this property value. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public FIRational? SignedAltitude + { + get + { + FIRational? result = null; + FIURational? altitude = Altitude; + if (altitude.HasValue) + { + int sign = AltitudeSign ?? 1; + if (((int)altitude.Value.Numerator < 0) || ((int)altitude.Value.Denominator < 0)) + throw new OverflowException(); + result = new FIRational((int)altitude.Value.Numerator * sign, (int)altitude.Value.Denominator); + } + return result; + } + set + { + FIURational? val = null; + if (value.HasValue) + { + if (value.Value < 0) + { + AltitudeSign = -1; + value = -value.Value; + } + else + { + AltitudeSign = 1; + } + val = new FIURational((uint)value.Value.Numerator, (uint)value.Value.Denominator); + } + Altitude = val; + } + } + + + /// + /// Gets or sets the time as UTC (Coordinated Universal Time). Constant length of 3. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public TimeSpan? TimeStamp + { + get + { + FIURational[] stamp = GetTagArray("GPSTimeStamp"); + if ((stamp == null) || stamp.Length != 3) + { + return null; + } + else + { + return new TimeSpan((int)stamp[0], (int)stamp[1], (int)stamp[2]); + } + } + set + { + FIURational[] stamp = null; + if (value.HasValue) + { + TimeSpan span = value.Value; + stamp = new FIURational[3]; + stamp[0] = span.Hours; + stamp[1] = span.Minutes; + stamp[2] = span.Seconds; + } + SetTagValue("GPSTimeStamp", stamp); + } + } + + /// + /// Gets or sets the GPS satellites used for measurements. This tag can be used to describe + /// the number of satellites, their ID number, angle of elevation, azimuth, SNR and other + /// information in ASCII notation. The format is not specified. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Satellites + { + get + { + string result = GetTagText("GPSSatellites"); + if (!string.IsNullOrEmpty(result)) + { + result = result.Substring(0, result.Length - 1); + } + return result; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("GPSTimeStamp", value); + } + } + + /// + /// Gets or sets a value indicating the status of the GPS receiver when the image was recorded. + /// true indicates measurement was in progress; + /// false indicates measurement was Interoperability. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public bool? Status + { + get + { + string text = GetTagText("GPSStatus"); + return string.IsNullOrEmpty(text) ? default(bool?) : text[0] == 'A'; + } + set + { + SetTagValue("GPSStatus", value.HasValue ? (value.Value ? "A\0" : "V\0") : null); + } + } + + /// + /// Gets or sets a value indicating the GPS measurement mode. + /// true indicates three-dimensional measurement; + /// false indicated two-dimensional measurement was in progress. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public bool? MeasureMode3D + { + get + { + string text = GetTagText("GPSMeasureMode"); + return string.IsNullOrEmpty(text) ? default(bool?) : text[0] == '3'; + } + set + { + SetTagValue("GPSMeasureMode", value.HasValue ? (value.Value ? "3\0" : "2\0") : null); + } + } + + /// + /// Gets or sets the GPS DOP (data degree of precision). An HDOP value is written during + /// two-dimensional measurement, and PDOP during three-dimensional measurement. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? DOP + { + get + { + return GetTagValue("GPSDOP"); + } + set + { + SetTagValue("GPSDOP", value); + } + } + + /// + /// Gets or sets the unit used to express the GPS receiver of movement. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public VelocityUnit? SpeedUnit + { + get + { + return ToUnitType(GetTagText("GPSSpeedRef")); + } + set + { + SetTagValue("GPSSpeedRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the speed of GPS receiver movement. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public FIURational? Speed + { + get + { + return GetTagValue("GPSSpeed"); + } + set + { + SetTagValue("GPSSpeed", value); + } + } + + /// + /// Gets or sets the reference for giving the direction of GPS receiver movement. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public DirectionReference? TrackDirectionReference + { + get + { + return ToDirectionType(GetTagText("GPSTrackRef")); + } + set + { + SetTagValue("GPSTrackRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the direction of GPS receiver movement. + /// The range of values is from 0.00 to 359.99. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public FIURational? Track + { + get + { + return GetTagValue("GPSTrack"); + } + set + { + SetTagValue("GPSTrack", value); + } + } + + /// + /// Gets or sets the reference for giving the direction of GPS receiver movement. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public DirectionReference? ImageDirectionReference + { + get + { + return ToDirectionType(GetTagText("GPSImgDirectionRef")); + } + set + { + SetTagValue("GPSImgDirectionRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the direction of the image when it was captured. + /// The range of values is from 0.00 to 359.99. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public FIURational? ImageDirection + { + get + { + return GetTagValue("GPSImgDirection"); + } + set + { + SetTagValue("GPSImgDirection", value); + } + } + + /// + /// Gets or sets the geodetic survey data used by the GPS receiver. If the survey data + /// is restricted to Japan, the value of this tag is 'TOKYO' or 'WGS-84'. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string MapDatum + { + get + { + string result = GetTagText("GPSMapDatum"); + if (!string.IsNullOrEmpty(result)) + { + result = result.Substring(0, result.Length - 1); + } + return result; + } + set + { + SetTagValue("GPSMapDatum", value + '\0'); + } + } + + /// + /// Gets or sets a value indicating whether the destination point + /// is north or south latitude. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public LatitudeType? DestinationLatitudeDirection + { + get + { + return ToLatitudeType(GetTagText("GPSDestLatitudeRef")); + } + set + { + SetTagValue("GPSDestLatitudeRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the latitude of the destination point. The latitude is expressed as three rational + /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public FIURational[] DestinationLatitude + { + get + { + return GetTagArray("GPSDestLatitude"); + } + set + { + FreeImage.Resize(ref value, 3); + SetTagValue("GPSDestLatitude", value); + } + } + + /// + /// Gets or sets a value indicating whether the destination point + /// is east or west longitude. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public LongitudeType? DestinationLongitudeDirection + { + get + { + return ToLongitudeType(GetTagText("GPSDestLongitudeRef")); + } + set + { + SetTagValue("GPSDestLongitudeRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the longitude of the destination point. The longitude is expressed as three rational + /// values giving the degrees, minutes, and seconds, respectively. Constant length of 3. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational[] DestinationLongitude + { + get + { + return GetTagArray("GPSDestLongitude"); + } + set + { + FreeImage.Resize(ref value, 3); + SetTagValue("GPSDestLongitude", value); + } + } + + /// + /// Gets or sets the reference used for giving the bearing to the destination point. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public DirectionReference? DestinationDirectionReference + { + get + { + return ToDirectionType(GetTagText("GPSDestBearingRef")); + } + set + { + SetTagValue("GPSDestBearingRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets the bearing to the destination point. + /// The range of values is from 0.00 to 359.99. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public FIURational? DestinationBearing + { + get + { + return GetTagValue("GPSDestBearing"); + } + set + { + SetTagValue("GPSDestBearing", value); + } + } + + /// + /// Gets or sets the unit used to express the distance to the destination point. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public VelocityUnit? DestinationUnit + { + get + { + return ToUnitType(GetTagText("GPSDestDistanceRef")); + } + set + { + SetTagValue("GPSDestDistanceRef", ToString(value) + '\0'); + } + } + + /// + /// Gets or sets a character string recording the name of the method used + /// for location finding. The first byte indicates the character code used, + /// and this is followed by the name of the method. Since the Type is not ASCII, + /// NULL termination is not necessary. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] ProcessingMethod + { + get + { + return GetTagArray("GPSProcessingMethod"); + } + set + { + SetTagValue("GPSProcessingMethod", value); + } + } + + /// + /// Gets or sets a character string recording the name of the GPS area. + /// The first byte indicates the character code used, and this is followed by + /// the name of the GPS area. Since the Type is not ASCII, NULL termination is + /// not necessary. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public byte[] AreaInformation + { + get + { + return GetTagArray("GPSAreaInformation"); + } + set + { + SetTagValue("GPSAreaInformation", value); + } + } + + /// + /// Gets or sets date and time information relative to UTC (Coordinated Universal Time). + /// + /// + /// This is a derived property. There is no metadata tag directly associated + /// with this property value. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public DateTime? DateTimeStamp + { + get + { + DateTime? date = DateStamp; + TimeSpan? time = TimeStamp; + if ((date == null) && (time == null)) + { + return null; + } + else + { + if (date == null) + { + date = DateTime.MinValue; + } + if (time == null) + { + time = TimeSpan.MinValue; + } + return date.Value.Add(time.Value); + } + } + set + { + if (value.HasValue) + { + DateStamp = value.Value.Date; + TimeStamp = value.Value.TimeOfDay; + } + else + { + DateStamp = null; + TimeStamp = null; + } + } + } + + /// + /// Gets or sets date information relative to UTC (Coordinated Universal Time). + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public DateTime? DateStamp + { + get + { + string stamp = GetTagText("GPSDateStamp"); + if (stamp != null) + { + try + { + return DateTime.ParseExact(stamp, "yyyy:MM:dd\0", null); + } + catch + { + } + } + return null; + } + set + { + string val = null; + if (value.HasValue) + { + try + { + val = value.Value.ToString("yyyy:MM:dd\0"); + } + catch + { + } + } + SetTagValue("GPSDateStamp", val); + } + } + + /// + /// Gets or sets a value indicating whether differential correction was applied to + /// the GPS receiver. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public bool? IsDifferential + { + get + { + ushort? value = GetTagValue("GPSDifferential"); + return value.HasValue ? (value != 0) : (default(bool?)); + } + set + { + SetTagValue("GPSDifferential", value.HasValue ? (object)(value.Value ? (ushort)1 : (ushort)0) : (null)); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_INTEROP : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_INTEROP(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_INTEROP; } + } + + /// + /// Gets or sets the identification of the Interoperability rule. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public InteroperabilityMode? Identification + { + get + { + return ToInteroperabilityType(GetTagText("InteroperabilityIndex")); + } + set + { + SetTagValue("InteroperabilityIndex", ToString(value) + '\0'); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + /// This class is obsolete. Use class instead. + /// + [Obsolete("To be removed in future releases. Use MDM_EXIF_MAIN instead.")] + public class MDM_MAIN : MDM_EXIF_MAIN + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_MAIN(FIBITMAP dib) : base(dib) { } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_EXIF_MAIN : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_EXIF_MAIN(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN; } + } + + /// + /// Gets or sets the number of columns of image data, equal to the number + /// of pixels per row. In JPEG compressed data a JPEG marker is used + /// instead of this tag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? ImageWidth + { + get + { + return GetUInt32Value("ImageWidth"); + } + set + { + RemoveTag("ImageWidth"); + if (value.HasValue) + { + SetTagValue("ImageWidth", value); + } + } + } + + /// + /// Gets or sets number of rows of image data. In JPEG compressed data a JPEG marker + /// is used instead of this tag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? ImageHeight + { + get + { + return GetUInt32Value("ImageLength"); + } + set + { + RemoveTag("ImageLength"); + if (value.HasValue) + { + SetTagValue("ImageLength", value); + } + } + } + + /// + /// Gets or sets number of bits per image component. In this standard + /// each component of the image is 8 bits, so the value for this tag is 8. + /// Constant length of 3. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort[] BitsPerSample + { + get + { + return GetTagArray("BitsPerSample"); + } + set + { + FreeImage.Resize(ref value, 3); + SetTagValue("BitsPerSample", value); + } + } + + /// + /// Gets or sets compression scheme used for the image data. When a primary image + /// is JPEG compressed, this designation is not necessary and is omitted. + /// When thumbnails use JPEG compression, this tag value is set to 6. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? Compression + { + get + { + return GetTagValue("Compression"); + } + set + { + SetTagValue("Compression", value); + } + } + + /// + /// Gets or sets pixel composition. In JPEG compressed data a JPEG marker is + /// used instead of this tag. See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 2 + /// RGB + /// + /// + /// 6 + /// YCbCr + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? PhotometricInterpretation + { + get + { + return GetTagValue("PhotometricInterpretation"); + } + set + { + SetTagValue("PhotometricInterpretation", value); + } + } + + /// + /// Gets or sets the image orientation viewed in terms of rows and columns. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ExifImageOrientation? Orientation + { + get + { + return (ExifImageOrientation?)GetTagValue("Orientation"); + } + set + { + SetTagValue("Orientation", (ushort?)value); + } + } + + /// + /// Gets or sets the number of components per pixel. Since this standard applies + /// to RGB and YCbCr images, the value set for this tag is 3. In JPEG compressed + /// data a JPEG marker is used instead of this tag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort? SamplesPerPixel + { + get + { + return GetTagValue("SamplesPerPixel"); + } + set + { + SetTagValue("SamplesPerPixel", value); + } + } + + /// + /// Gets or sets a value that indicates whether pixel components are recorded in + /// chunky or planar format. In JPEG compressed files a JPEG marker is used instead + /// of this tag. If this field does not exist, the TIFF default of 1 (chunky) is assumed. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 1 + /// chunky format + /// + /// + /// 2 + /// planar format + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? PlanarConfiguration + { + get + { + return GetTagValue("PlanarConfiguration"); + } + set + { + SetTagValue("PlanarConfiguration", value); + } + } + + /// + /// Gets or sets the sampling ratio of chrominance components in relation to + /// the luminance component. In JPEG compressed dat a JPEG marker is used + /// instead of this tag. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// [2,1] + /// YCbCr4:2:2 + /// + /// + /// [2,2] + /// YCbCr4:2:0 + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort[] YCbCrSubSampling + { + get + { + return GetTagArray("YCbCrSubSampling"); + } + set + { + FreeImage.Resize(ref value, 2); + SetTagValue("YCbCrSubSampling", value); + } + } + + /// + /// Gets or sets position of chrominance components in relation to the luminance component. + /// See remarks for further information. + /// + /// + /// This field is designated only for JPEG compressed data or uncompressed YCbCr data. + /// The TIFF default is 1 (centered); but when Y:Cb:Cr = 4:2:2 it is recommended in + /// this standard that 2 (co-sited) be used to record data, in order to improve the + /// image quality when viewed on TV systems. + /// + /// When this field does not exist, the reader shall assume the TIFF default. + /// In the case of Y:Cb:Cr = 4:2:0, the TIFF default (centered) is recommended. + /// If the reader does not have the capability of supporting both kinds of YCbCrPositioning, + /// it shall follow the TIFF default regardless of the value in this field. + /// It is preferable that readers be able to support both centered and co-sited positioning. + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 1 + /// centered + /// + /// + /// 2 + /// co-sited + /// + /// + /// other + /// reserved + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? YCbCrPositioning + { + get + { + return GetTagValue("YCbCrPositioning"); + } + set + { + SetTagValue("YCbCrPositioning", value); + } + } + + /// + /// Gets or sets the number of pixels per + /// in the direction. When the image resolution is unknown, + /// 72 [dpi] is designated. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? XResolution + { + get + { + return GetTagValue("XResolution"); + } + set + { + SetTagValue("XResolution", value); + } + } + + /// + /// Gets or sets the number of pixels per + /// in the direction. When the image resolution is unknown, + /// 72 [dpi] is designated. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational? YResolution + { + get + { + return GetTagValue("YResolution"); + } + set + { + SetTagValue("YResolution", value); + } + } + + /// + /// Gets or sets the unit for measuring and . + /// The same unit is used for both and . + /// If the image resolution in unknown, 2 (inches) is designated. + /// See remarks for further information. + /// + /// + /// The following values are definied: + /// + /// + /// ID + /// Description + /// + /// + /// 2 + /// inches + /// + /// + /// 3 + /// YCbCr4:2:0 + /// + /// + /// other + /// centimeters + /// + /// + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort? ResolutionUnit + { + get + { + return GetTagValue("ResolutionUnit"); + } + set + { + SetTagValue("ResolutionUnit", value); + } + } + + /// + /// Gets or sets the byte offset of that strip. + /// It is recommended that this be selected so the number of strip bytes + /// does not exceed 64 Kbytes. + /// With JPEG compressed data this designation is not needed and is omitted. + /// Constant length of * StripsPerImage. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + /// + public uint[] StripOffsets + { + get + { + return GetUInt32Array("StripOffsets"); + } + set + { + RemoveTag("StripOffsets"); + if (value != null) + { + SetTagValue("StripOffsets", value); + } + } + } + + /// + /// Gets or sets number of rows per strip. This is the number of rows in the image of + /// one strip when an image is divided into strips. With JPEG compressed data this + /// designation is not needed and is omitted. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + /// + public uint? RowsPerStrip + { + get + { + return GetUInt32Value("RowsPerStrip"); + } + set + { + RemoveTag("RowsPerStrip"); + if (value.HasValue) + { + SetTagValue("RowsPerStrip", value); + } + } + } + + /// + /// Gets or sets the total number of bytes in each strip. + /// With JPEG compressed data this designation is not needed and is omitted. + /// Constant length of * StripsPerImage. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint[] StripByteCounts + { + get + { + return GetUInt32Array("StripByteCounts"); + } + set + { + RemoveTag("StripByteCounts"); + if (value != null) + { + SetTagValue("StripByteCounts", value); + } + } + } + + /// + /// Gets or sets the offset to the start byte (SOI) of JPEG compressed thumbnail data. + /// This is not used for primary image JPEG data. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? JPEGInterchangeFormat + { + get + { + return GetTagValue("JPEGInterchangeFormat"); + } + set + { + SetTagValue("JPEGInterchangeFormat", value); + } + } + + /// + /// Gets or sets the number of bytes of JPEG compressed thumbnail data. + /// + /// + /// This is not used for primary image JPEG data. + /// JPEG thumbnails are not divided but are recorded as a continuous + /// JPEG bitstream from SOI to EOI. APPn and COM markers should not be recorded. + /// Compressed thumbnails shall be recorded in no more than 64 Kbytes, + /// including all other data to be recorded in APP1. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public uint? JPEGInterchangeFormatLength + { + get + { + return GetTagValue("JPEGInterchangeFormatLength"); + } + set + { + SetTagValue("JPEGInterchangeFormatLength", value); + } + } + + /// + /// Gets or sets a transfer function for the image, described in tabular style. + /// Constant length of 3 * 256. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public ushort[] TransferFunction + { + get + { + return GetTagArray("TransferFunction"); + } + set + { + FreeImage.Resize(ref value, 3 * 256); + SetTagValue("TransferFunction", value); + } + } + + /// + /// Gets or sets the chromaticity of the white point of the image. + /// Constant length of 2. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational[] WhitePoint + { + get + { + return GetTagArray("WhitePoint"); + } + set + { + FreeImage.Resize(ref value, 2); + SetTagValue("WhitePoint", value); + } + } + + /// + /// Gets or sets the chromaticity of the three primary colors of the image. + /// Constant length of 6. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational[] PrimaryChromaticities + { + get + { + return GetTagArray("PrimaryChromaticities"); + } + set + { + FreeImage.Resize(ref value, 6); + SetTagValue("PrimaryChromaticities", value); + } + } + + /// + /// Gets or sets the matrix coefficients for transformation from RGB to YCbCr image data. + /// Constant length of 3. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational[] YCbCrCoefficients + { + get + { + return GetTagArray("YCbCrCoefficients"); + } + set + { + FreeImage.Resize(ref value, 3); + SetTagValue("PrimaryChromaticities", value); + } + } + + /// + /// Gets or sets the reference black point value and reference white point value. + /// Constant length of 6. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public FIURational[] ReferenceBlackWhite + { + get + { + return GetTagArray("ReferenceBlackWhite"); + } + set + { + FreeImage.Resize(ref value, 6); + SetTagValue("ReferenceBlackWhite", value); + } + } + + /// + /// Gets or sets the date and time of image creation. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public DateTime? DateTime + { + get + { + DateTime? result = null; + string text = GetTagText("DateTime"); + if (text != null) + { + try + { + result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null); + } + catch + { + } + } + return result; + } + set + { + string val = null; + if (value.HasValue) + { + try + { + val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0"); + } + catch + { + } + } + SetTagValue("DateTime", val); + } + } + + /// + /// Gets or sets a string giving the title of the image. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ImageDescription + { + get + { + string result = GetTagText("ImageDescription"); + if (!string.IsNullOrEmpty(result)) + { + result = result.Substring(0, result.Length - 1); + } + return result; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("ImageDescription", value); + } + } + + /// + /// Gets or sets the manufacturer of the recording equipment. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Make + { + get + { + string result = GetTagText("Make"); + if (!string.IsNullOrEmpty(result)) + { + result = result.Substring(0, result.Length - 1); + } + return result; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("Make", value); + } + } + + /// + /// Gets or sets the model name or model number of the equipment. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string EquipmentModel + { + get + { + string result = GetTagText("Model"); + if (!string.IsNullOrEmpty(result)) + { + result = result.Substring(0, result.Length - 1); + } + return result; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("Model", value); + } + } + + /// + /// Gets or sets the name and version of the software or firmware of the camera + /// or image input device used to generate the image. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Software + { + get + { + string result = GetTagText("Software"); + if (!string.IsNullOrEmpty(result)) + { + result = result.Substring(0, result.Length - 1); + } + return result; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("Software", value); + } + } + + /// + /// Gets or sets the name of the camera owner, photographer or image creator. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Artist + { + get + { + string result = GetTagText("Artist"); + if (!string.IsNullOrEmpty(result)) + { + result = result.Substring(0, result.Length - 1); + } + return result; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("Artist", value); + } + } + + /// + /// Gets or sets the photographer and editor copyrights. + /// Constant length of 1-2. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string[] Copyright + { + get + { + string[] result = null; + string text = GetTagText("Copyright"); + if (!string.IsNullOrEmpty(text)) + { + result = text.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); + } + return result; + } + set + { + string val = null; + if (value != null) + { + if (value.Length == 1) + { + if (value[0] != null) + { + val = value[0] + '\0'; + } + } + else if (value.Length == 2) + { + if ((value[0] != null) && (value[1] != null)) + { + val = value[0] + '\0' + value[1] + '\0'; + } + } + } + SetTagValue("Copyright", val); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_MAKERNOTE : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_MAKERNOTE(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_MAKERNOTE; } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_GEOTIFF : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_GEOTIFF(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_GEOTIFF; } + } + + /// + /// Gets or sets the value of the GeoTIFF GeoASCIIParamsTag. + /// + /// + /// The GeoASCIIParamsTag is used to store all of the valued + /// GeoKeys, referenced by the property. Since keys + /// defined in the GeoKeyDirectoryTag use offsets into this tag, any special + /// comments may be placed at the beginning of this tag. + /// For the most part, the only keys that are valued are + /// Citation keys, giving documentation and references for obscure + /// projections, datums, etc. + /// + /// Special handling is required for -valued keys. While it + /// is true that TIFF 6.0 permits multiple NULL-delimited strings within a single + /// ASCII tag, the secondary strings might not appear in the output of naive + /// tiffdump programs. For this reason, the NULL delimiter of each ASCII key + /// value shall be converted to a "|" (pipe) character before being installed + /// back into the holding tag, so that a dump of the tag + /// will look like this. + /// + /// AsciiTag="first_value|second_value|etc...last_value|" + /// + /// A baseline GeoTIFF-reader must check for and convert the final "|" pipe + /// character of a key back into a NULL before returning it to the client + /// software. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public string GeoASCIIParams + { + get + { + string text = GetTagText("GeoASCIIParams"); + if (!string.IsNullOrEmpty(text)) + { + text = text.Substring(0, text.Length - 1); + } + return text; + } + set + { + if (value != null) + { + value += '\0'; + } + SetTagValue("GeoASCIIParams", value); + } + } + + /// + /// Gets or sets the value of the GeoTIFF GeoDoubleParamsTag. + /// + /// + /// The GeoDoubleParamsTag is used to store all of the valued + /// GeoKeys, referenced by the property. The meaning of + /// any value of this double array is determined from the GeoKeyDirectoryTag reference + /// pointing to it. values should first be converted to + /// and stored here. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public double[] GeoDoubleParams + { + get + { + return GetTagArray("GeoDoubleParams"); + } + set + { + SetTagValue("GeoDoubleParams", value); + } + } + + /// + /// Gets or sets the value of the GeoTIFF GeoKeyDirectoryTag. + /// + /// + /// The GeoKeyDirectoryTag may be used to store the GeoKey Directory, which defines and + /// references the GeoKeys. + /// + /// The tag is an array of unsigned values, which are primarily + /// grouped into blocks of 4. The first 4 values are special, and contain GeoKey directory + /// header information. The header values consist of the following information, in order: + /// + /// Header={KeyDirectoryVersion, KeyRevision, MinorRevision, NumberOfKeys} + /// + /// where + /// + /// KeyDirectoryVersion indicates the current version of Key implementation, and will + /// only change if this Tag's Key structure is changed. (Similar to the TIFFVersion (42)). + /// The current DirectoryVersion number is 1. This value will most likely never change, + /// and may be used to ensure that this is a valid Key-implementation. + /// + /// KeyRevision indicates what revision of Key-Sets are used. + /// + /// MinorRevision indicates what set of Key-Codes are used. The complete revision number + /// is denoted <KeyRevision>.<MinorRevision>. + /// + /// NumberOfKeys indicates how many Keys are defined by the rest of this Tag. + /// + /// This header is immediately followed by a collection of <NumberOfKeys> KeyEntry + /// sets, each of which is also 4- long. Each KeyEntry is modeled on the + /// TIFFEntry format of the TIFF directory header, and is of the form: + /// + /// KeyEntry = { KeyID, TIFFTagLocation, Count, Value_Offset } + /// + /// where + /// + /// KeyID gives the Key-ID value of the Key (identical in function to TIFF tag ID, + /// but completely independent of TIFF tag-space), + /// + /// TIFFTagLocation indicates which TIFF tag contains the value(s) of the Key: if + /// TIFFTagLocation is 0, then the value is , and is contained in the + /// Value_Offset entry. Otherwise, the type (format) of the value is implied by the + /// TIFF-Type of the tag containing the value. + /// + /// Count indicates the number of values in this key. + /// + /// Value_Offset Value_Offset indicates the index-offset into the TagArray indicated + /// by TIFFTagLocation, if it is nonzero. If TIFFTagLocation is 0 (zero) , then Value_Offset + /// contains the actual () value of the Key, and Count=1 is implied. + /// Note that the offset is not a byte-offset, but rather an index based on the natural data + /// type of the specified tag array. + /// + /// Following the KeyEntry definitions, the KeyDirectory tag may also contain additional + /// values. For example, if a key requires multiple values, they shall + /// be placed at the end of this tag, and the KeyEntry will set + /// TIFFTagLocation=GeoKeyDirectoryTag, with the Value_Offset pointing to the location of the + /// value(s). + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public ushort[] GeoKeyDirectory + { + get + { + return GetTagArray("GeoKeyDirectory"); + } + set + { + SetTagValue("GeoKeyDirectory", value); + } + } + + /// + /// Gets or sets the value of the GeoTIFF ModelPixelScaleTag. + /// + /// + /// The ModelPixelScaleTag tag may be used to specify the size of raster pixel spacing + /// in the model space units, when the raster space can be embedded in the model space + /// coordinate system without rotation, and consists of the following 3 values: + /// + /// ModelPixelScaleTag = (ScaleX, ScaleY, ScaleZ) + /// + /// where ScaleX and ScaleY give the horizontal and vertical spacing of + /// raster pixels. The ScaleZ is primarily used to map the pixel value of a + /// digital elevation model into the correct Z-scale, and so for most other purposes + /// this value should be zero (since most model spaces are 2-D, with Z=0). + /// + /// A single tiepoint in the tag, together with this tag, + /// completely determine the relationship between raster and model space; thus they + /// comprise the two tags which Baseline GeoTIFF files most often will use to place a + /// raster image into a "standard position" in model space. + /// + /// Like the tag, this tag information is independent of the + /// XPosition, YPosition, Resolution and Orientation tags of the standard TIFF 6.0 spec. + /// However, simple reversals of orientation between raster and model space + /// (e.g. horizontal or vertical flips) may be indicated by reversal of sign in the + /// corresponding component of the ModelPixelScaleTag. GeoTIFF compliant readers must + /// honor this signreversal convention. + /// + /// This tag must not be used if the raster image requires rotation or shearing to place + /// it into the standard model space. In such cases the transformation shall be defined + /// with the more general . + /// + ///
    Naming differences + /// In the native FreeImage library and thus, in the FreeImage API documentation, this + /// property's key is named GeoPixelScale. Since the GeoTIFF specification + /// as well as Java's EXIFTIFFTagSet class call this tag + /// , this property was renamed accordingly. + /// However, when accessing this property's tag by its object, + /// the native FreeImage tag key GeoPixelScale must be used. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public double[] ModelPixelScale + { + get + { + return GetTagArray("GeoPixelScale"); + } + set + { + SetTagValue("GeoPixelScale", value); + } + } + + /// + /// Gets or sets the value of the GeoTIFF GeoTiePointsTag. + /// + /// + /// The GeoTiePointsTag stores raster -> model tiepoint pairs in the order + /// + /// ModelTiePoints = (...,I,J,K, X,Y,Z...), + /// + /// where (I,J,K) is the point at location (I,J) in raster space with + /// pixel-value K, and (X,Y,Z) is a vector in model space. In most cases + /// the model space is only two-dimensional, in which case both K and Z should be set + /// to zero; this third dimension is provided in anticipation of future support for 3D + /// digital elevation models and vertical coordinate systems. + /// + /// A raster image may be georeferenced simply by specifying its location, size and + /// orientation in the model coordinate space M. This may be done by specifying the + /// location of three of the four bounding corner points. However, tiepoints are only + /// to be considered exact at the points specified; thus defining such a set of + /// bounding tiepoints does not imply that the model space locations of the interior + /// of the image may be exactly computed by a linear interpolation of these tiepoints. + /// + /// However, since the relationship between the Raster space and the model space will + /// often be an exact, affine transformation, this relationship can be defined using + /// one set of tiepoints and the , described below, which + /// gives the vertical and horizontal raster grid cell size, specified in model units. + /// + /// If possible, the first tiepoint placed in this tag shall be the one establishing + /// the location of the point (0,0) in raster space. However, if this is not possible + /// (for example, if (0,0) is goes to a part of model space in which the projection is + /// ill-defined), then there is no particular order in which the tiepoints need be + /// listed. + /// + /// For orthorectification or mosaicking applications a large number of tiepoints may + /// be specified on a mesh over the raster image. However, the definition of associated + /// grid interpolation methods is not in the scope of the current GeoTIFF spec. + /// + ///
    Naming differences + /// In the native FreeImage library and thus, in the FreeImage API documentation, this + /// property's key is named GeoTiePoints. Since the GeoTIFF specification + /// as well as Java's EXIFTIFFTagSet class call this tag + /// , this property was renamed accordingly. + /// However, when accessing this property's tag by its object, + /// the native FreeImage tag key GeoTiePoints must be used. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public double[] ModelTiePoints + { + get + { + return GetTagArray("GeoTiePoints"); + } + set + { + SetTagValue("GeoTiePoints", value); + } + } + + /// + /// Gets or sets the value of the GeoTIFF ModelTransformationMatrixTag. + /// + /// + /// This tag may be used to specify the transformation matrix between the raster space + /// (and its dependent pixel-value space) and the (possibly 3D) model space. + /// + ///
    Naming differences + /// In the native FreeImage library and thus, in the FreeImage API documentation, this + /// property's key is named GeoTransformationMatrix. Since the GeoTIFF specification + /// as well as Java's EXIFTIFFTagSet class call this tag + /// , this property was renamed accordingly. + /// However, when accessing this property's tag by its object, + /// the native FreeImage tag key GeoTransformationMatrix must be used. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public double[] ModelTransformationMatrix + { + get + { + return GetTagArray("GeoTransformationMatrix"); + } + set + { + SetTagValue("GeoTransformationMatrix", value); + } + } + + /// + /// Gets or sets the value of the GeoTIFF IntergraphTransformationMatrixTag. + /// + /// + /// The IntergraphTransformationMatrixTag conflicts with an internal software implementation + /// at Intergraph, and so its use is no longer encouraged. A GeoTIFF reader should look first + /// for the new tag, and only if it is not found should it check for this older tag. If found, + /// it should only consider it to be contain valid GeoTIFF matrix information if the tag-count + /// is 16; the Intergraph version uses 17 values. + /// + ///
    Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + ///
    + public double[] IntergraphTransformationMatrix + { + get + { + return GetTagArray("Intergraph TransformationMatrix"); + } + set + { + SetTagValue("Intergraph TransformationMatrix", value); + } + } + + /// + /// Gets or sets the value of the GeoTIFF JPLCartoIFDOffsetTag. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public uint? JPLCartoIFDOffset + { + get + { + return GetTagValue("JPL Carto IFD offset"); + } + set + { + SetTagValue("JPL Carto IFD offset", value); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_IPTC : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_IPTC(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_IPTC; } + } + + /// + /// Gets the Application Record Version. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public short? ApplicationRecordVersion + { + get + { + return GetTagValue("ApplicationRecordVersion"); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Object Type Reference. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ObjectTypeReference + { + get + { + return GetTagText("ObjectTypeReference"); + } + set + { + SetTagValue("ObjectTypeReference", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Object Attribute Reference. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ObjectAttributeReference + { + get + { + return GetTagText("ObjectAttributeReference"); + } + set + { + SetTagValue("ObjectAttributeReference", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Object Name. + /// This is also referred to as Title. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ObjectName + { + get + { + return GetTagText("ObjectName"); + } + set + { + SetTagValue("ObjectName", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Edit Status. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string EditStatus + { + get + { + return GetTagText("EditStatus"); + } + set + { + SetTagValue("EditStatus", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Editorial Update. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string EditorialUpdate + { + get + { + return GetTagText("EditorialUpdate"); + } + set + { + SetTagValue("EditorialUpdate", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Urgency. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Urgency + { + get + { + return GetTagText("Urgency"); + } + set + { + SetTagValue("Urgency", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Subject Reference. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SubjectReference + { + get + { + return GetTagText("SubjectReference"); + } + set + { + SetTagValue("SubjectReference", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Category. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Category + { + get + { + return GetTagText("Category"); + } + set + { + SetTagValue("Category", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Supplemental Categories. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SupplementalCategories + { + get + { + return GetTagText("SupplementalCategories"); + } + set + { + SetTagValue("SupplementalCategories", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Fixture Identifier. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string FixtureIdentifier + { + get + { + return GetTagText("FixtureIdentifier"); + } + set + { + SetTagValue("FixtureIdentifier", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Keywords. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Keywords + { + get + { + return GetTagText("Keywords"); + } + set + { + SetTagValue("Keywords", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Content Location Code. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ContentLocationCode + { + get + { + return GetTagText("ContentLocationCode"); + } + set + { + SetTagValue("ContentLocationCode", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Content Location Name. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ContentLocationName + { + get + { + return GetTagText("ContentLocationName"); + } + set + { + SetTagValue("ContentLocationName", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Release Date. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ReleaseDate + { + get + { + return GetTagText("ReleaseDate"); + } + set + { + SetTagValue("ReleaseDate", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Release Time. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ReleaseTime + { + get + { + return GetTagText("ReleaseTime"); + } + set + { + SetTagValue("ReleaseTime", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Expiration Date. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ExpirationDate + { + get + { + return GetTagText("ExpirationDate"); + } + set + { + SetTagValue("ExpirationDate", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Expiration Time. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ExpirationTime + { + get + { + return GetTagText("ExpirationTime"); + } + set + { + SetTagValue("ExpirationTime", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Special Instructions. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SpecialInstructions + { + get + { + return GetTagText("SpecialInstructions"); + } + set + { + SetTagValue("SpecialInstructions", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Action Advised. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ActionAdvised + { + get + { + return GetTagText("ActionAdvised"); + } + set + { + SetTagValue("ActionAdvised", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Reference Service. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ReferenceService + { + get + { + return GetTagText("ReferenceService"); + } + set + { + SetTagValue("ReferenceService", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Reference Date. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ReferenceDate + { + get + { + return GetTagText("ReferenceDate"); + } + set + { + SetTagValue("ReferenceDate", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Reference Number. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ReferenceNumber + { + get + { + return GetTagText("ReferenceNumber"); + } + set + { + SetTagValue("ReferenceNumber", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Date Created. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string DateCreated + { + get + { + return GetTagText("DateCreated"); + } + set + { + SetTagValue("DateCreated", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Time Created. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string TimeCreated + { + get + { + return GetTagText("TimeCreated"); + } + set + { + SetTagValue("TimeCreated", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Digital Creation Date. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string DigitalCreationDate + { + get + { + return GetTagText("DigitalCreationDate"); + } + set + { + SetTagValue("DigitalCreationDate", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Digital Creation Time. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string DigitalCreationTime + { + get + { + return GetTagText("DigitalCreationTime"); + } + set + { + SetTagValue("DigitalCreationTime", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Originating Program. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string OriginatingProgram + { + get + { + return GetTagText("OriginatingProgram"); + } + set + { + SetTagValue("OriginatingProgram", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Program Version. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ProgramVersion + { + get + { + return GetTagText("ProgramVersion"); + } + set + { + SetTagValue("ProgramVersion", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Object Cycle. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ObjectCycle + { + get + { + return GetTagText("ObjectCycle"); + } + set + { + SetTagValue("ObjectCycle", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag By Line. + /// This is the author's name. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ByLine + { + get + { + return GetTagText("By-line"); + } + set + { + SetTagValue("By-line", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag By Line Title. + /// This is the author's position. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ByLineTitle + { + get + { + return GetTagText("By-lineTitle"); + } + set + { + SetTagValue("By-lineTitle", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag City. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string City + { + get + { + return GetTagText("City"); + } + set + { + SetTagValue("City", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Sub Location. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SubLocation + { + get + { + return GetTagText("SubLocation"); + } + set + { + SetTagValue("SubLocation", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Province State. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ProvinceState + { + get + { + return GetTagText("ProvinceState"); + } + set + { + SetTagValue("ProvinceState", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Country Primary Location Code. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string CountryPrimaryLocationCode + { + get + { + return GetTagText("Country-PrimaryLocationCode"); + } + set + { + SetTagValue("Country-PrimaryLocationCode", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Country Primary Location Name. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string CountryPrimaryLocationName + { + get + { + return GetTagText("Country-PrimaryLocationName"); + } + set + { + SetTagValue("Country-PrimaryLocationName", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Original Transmission Reference. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string OriginalTransmissionReference + { + get + { + return GetTagText("OriginalTransmissionReference"); + } + set + { + SetTagValue("OriginalTransmissionReference", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Headline. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Headline + { + get + { + return GetTagText("Headline"); + } + set + { + SetTagValue("Headline", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Credit. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Credit + { + get + { + return GetTagText("Credit"); + } + set + { + SetTagValue("Credit", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Source. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Source + { + get + { + return GetTagText("Source"); + } + set + { + SetTagValue("Source", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Copyright Notice. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string CopyrightNotice + { + get + { + return GetTagText("CopyrightNotice"); + } + set + { + SetTagValue("CopyrightNotice", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Contact. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Contact + { + get + { + return GetTagText("Contact"); + } + set + { + SetTagValue("Contact", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Caption Abstract. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string CaptionAbstract + { + get + { + return GetTagText("CaptionAbstract"); + } + set + { + SetTagValue("CaptionAbstract", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Writer Editor. + /// This is also referred to as Caption Writer. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string WriterEditor + { + get + { + return GetTagText("WriterEditor"); + } + set + { + SetTagValue("WriterEditor", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Rasterized Caption. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string RasterizedCaption + { + get + { + return GetTagText("RasterizedCaption"); + } + set + { + SetTagValue("RasterizedCaption", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Image Type. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ImageType + { + get + { + return GetTagText("ImageType"); + } + set + { + SetTagValue("ImageType", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Image Orientation. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ImageOrientation + { + get + { + return GetTagText("ImageOrientation"); + } + set + { + SetTagValue("ImageOrientation", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Language Identifier. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string LanguageIdentifier + { + get + { + return GetTagText("LanguageIdentifier"); + } + set + { + SetTagValue("LanguageIdentifier", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Audio Type. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string AudioType + { + get + { + return GetTagText("AudioType"); + } + set + { + SetTagValue("AudioType", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Audio Sampling Rate. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string AudioSamplingRate + { + get + { + return GetTagText("AudioSamplingRate"); + } + set + { + SetTagValue("AudioSamplingRate", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Audio Sampling Resolution. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string AudioSamplingResolution + { + get + { + return GetTagText("AudioSamplingResolution"); + } + set + { + SetTagValue("AudioSamplingResolution", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Audio Duration. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string AudioDuration + { + get + { + return GetTagText("AudioDuration"); + } + set + { + SetTagValue("AudioDuration", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Audio Outcue. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string AudioOutcue + { + get + { + return GetTagText("AudioOutcue"); + } + set + { + SetTagValue("AudioOutcue", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Job I D. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string JobID + { + get + { + return GetTagText("JobID"); + } + set + { + SetTagValue("JobID", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Master Document I D. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string MasterDocumentID + { + get + { + return GetTagText("MasterDocumentID"); + } + set + { + SetTagValue("MasterDocumentID", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Short Document I D. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ShortDocumentID + { + get + { + return GetTagText("ShortDocumentID"); + } + set + { + SetTagValue("ShortDocumentID", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Unique Document I D. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string UniqueDocumentID + { + get + { + return GetTagText("UniqueDocumentID"); + } + set + { + SetTagValue("UniqueDocumentID", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Owner I D. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string OwnerID + { + get + { + return GetTagText("OwnerID"); + } + set + { + SetTagValue("OwnerID", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Object Preview File Format. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ObjectPreviewFileFormat + { + get + { + return GetTagText("ObjectPreviewFileFormat"); + } + set + { + SetTagValue("ObjectPreviewFileFormat", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Object Preview File Version. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ObjectPreviewFileVersion + { + get + { + return GetTagText("ObjectPreviewFileVersion"); + } + set + { + SetTagValue("ObjectPreviewFileVersion", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Object Preview Data. + /// This is also referred to as Audio Outcue. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ObjectPreviewData + { + get + { + return GetTagText("ObjectPreviewData"); + } + set + { + SetTagValue("ObjectPreviewData", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Prefs. + /// This is also referred to as photo-mechanic preferences. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Prefs + { + get + { + return GetTagText("Prefs"); + } + set + { + SetTagValue("Prefs", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Classify State. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ClassifyState + { + get + { + return GetTagText("ClassifyState"); + } + set + { + SetTagValue("ClassifyState", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Similarity Index. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string SimilarityIndex + { + get + { + return GetTagText("SimilarityIndex"); + } + set + { + SetTagValue("SimilarityIndex", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Document Notes. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string DocumentNotes + { + get + { + return GetTagText("DocumentNotes"); + } + set + { + SetTagValue("DocumentNotes", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Document History. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string DocumentHistory + { + get + { + return GetTagText("DocumentHistory"); + } + set + { + SetTagValue("DocumentHistory", value); + } + } + + /// + /// Gets or sets the value of the IPTC/NAA tag Exif Camera Info. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string ExifCameraInfo + { + get + { + return GetTagText("ExifCameraInfo"); + } + set + { + SetTagValue("ExifCameraInfo", value); + } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_NODATA : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_NODATA(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_NODATA; } + } + } + + /// + /// Represents a collection of all tags contained in the metadata model + /// . + /// + public class MDM_XMP : MetadataModel + { + /// + /// Initializes a new instance of this class. + /// + /// Handle to a FreeImage bitmap. + public MDM_XMP(FIBITMAP dib) : base(dib) { } + + /// + /// Retrieves the datamodel that this instance represents. + /// + public override FREE_IMAGE_MDMODEL Model + { + get { return FREE_IMAGE_MDMODEL.FIMD_XMP; } + } + + /// + /// Gets or sets the XMP XML content. + /// + /// + /// Handling of null values + /// A null value indicates, that the corresponding metadata tag is not + /// present in the metadata model. + /// Setting this property's value to a non-null reference creates the + /// metadata tag if necessary. + /// Setting this property's value to a null reference deletes the + /// metadata tag from the metadata model. + /// + public string Xml + { + get + { + return GetTagText("XMLPacket"); + } + set + { + SetTagValue("XMLPacket", value); + } + } + + /// + /// Gets an initialized to read the XMP XML content. + /// Returns null, if the metadata tag XMLPacket is not present in + /// this model. + /// + public XmlReader XmlReader + { + get + { + string xmlString = Xml; + if (xmlString == null) + { + return null; + } + else + { + MemoryStream stream = new MemoryStream(); + StreamWriter writer = new StreamWriter(stream); + writer.Write(xmlString); + return XmlReader.Create(stream); + } + } + } + } +} + + #endregion + +namespace FreeImageAPI.Metadata +{ + /// + /// Manages metadata objects and operations. + /// + public sealed class MetadataTag : IComparable, IComparable, ICloneable, IEquatable, IDisposable + { + /// + /// The encapsulated FreeImage-tag. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + internal FITAG tag; + + /// + /// The metadata model of . + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private FREE_IMAGE_MDMODEL model; + + /// + /// Indicates whether this instance has already been disposed. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool disposed = false; + + /// + /// Indicates whether this instance was created by FreeImage or + /// by the user. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool selfCreated; + + /// + /// List linking metadata-model and Type. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private static readonly Dictionary idList; + + /// + /// List linking Type and metadata-model. + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private static readonly Dictionary typeList; + + /// + /// Initializes a new instance of this class. + /// + private MetadataTag() + { + } + + /// + /// Initializes a new instance of this class. + /// + /// The new model the tag should be of. + public MetadataTag(FREE_IMAGE_MDMODEL model) + { + this.model = model; + tag = FreeImage.CreateTag(); + selfCreated = true; + + if (model == FREE_IMAGE_MDMODEL.FIMD_XMP) + { + Key = "XMLPacket"; + } + } + + /// + /// Initializes a new instance of this class. + /// + /// The to represent. + /// The bitmap was extracted from. + public MetadataTag(FITAG tag, FIBITMAP dib) + { + if (tag.IsNull) + { + throw new ArgumentNullException("tag"); + } + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + this.tag = tag; + model = GetModel(dib, tag); + selfCreated = false; + + if (model == FREE_IMAGE_MDMODEL.FIMD_XMP) + { + Key = "XMLPacket"; + } + } + + /// + /// Initializes a new instance of this class. + /// + /// The to represent. + /// The model of . + public MetadataTag(FITAG tag, FREE_IMAGE_MDMODEL model) + { + if (tag.IsNull) + { + throw new ArgumentNullException("tag"); + } + this.tag = tag; + this.model = model; + selfCreated = false; + + if (model == FREE_IMAGE_MDMODEL.FIMD_XMP) + { + Key = "XMLPacket"; + } + } + + static MetadataTag() + { + idList = new Dictionary(); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_BYTE, typeof(byte)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_SHORT, typeof(ushort)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_LONG, typeof(uint)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_RATIONAL, typeof(FIURational)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_SBYTE, typeof(sbyte)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_UNDEFINED, typeof(byte)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_SSHORT, typeof(short)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_SLONG, typeof(int)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_SRATIONAL, typeof(FIRational)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_FLOAT, typeof(float)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_DOUBLE, typeof(double)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_IFD, typeof(uint)); + idList.Add(FREE_IMAGE_MDTYPE.FIDT_PALETTE, typeof(RGBQUAD)); + + typeList = new Dictionary(); + typeList.Add(typeof(ushort), FREE_IMAGE_MDTYPE.FIDT_SHORT); + typeList.Add(typeof(ushort[]), FREE_IMAGE_MDTYPE.FIDT_SHORT); + typeList.Add(typeof(string), FREE_IMAGE_MDTYPE.FIDT_ASCII); + typeList.Add(typeof(uint), FREE_IMAGE_MDTYPE.FIDT_LONG); + typeList.Add(typeof(uint[]), FREE_IMAGE_MDTYPE.FIDT_LONG); + typeList.Add(typeof(FIURational), FREE_IMAGE_MDTYPE.FIDT_RATIONAL); + typeList.Add(typeof(FIURational[]), FREE_IMAGE_MDTYPE.FIDT_RATIONAL); + typeList.Add(typeof(sbyte), FREE_IMAGE_MDTYPE.FIDT_SBYTE); + typeList.Add(typeof(sbyte[]), FREE_IMAGE_MDTYPE.FIDT_SBYTE); + typeList.Add(typeof(byte), FREE_IMAGE_MDTYPE.FIDT_BYTE); + typeList.Add(typeof(byte[]), FREE_IMAGE_MDTYPE.FIDT_BYTE); + typeList.Add(typeof(short), FREE_IMAGE_MDTYPE.FIDT_SSHORT); + typeList.Add(typeof(short[]), FREE_IMAGE_MDTYPE.FIDT_SSHORT); + typeList.Add(typeof(int), FREE_IMAGE_MDTYPE.FIDT_SLONG); + typeList.Add(typeof(int[]), FREE_IMAGE_MDTYPE.FIDT_SLONG); + typeList.Add(typeof(FIRational), FREE_IMAGE_MDTYPE.FIDT_SRATIONAL); + typeList.Add(typeof(FIRational[]), FREE_IMAGE_MDTYPE.FIDT_SRATIONAL); + typeList.Add(typeof(float), FREE_IMAGE_MDTYPE.FIDT_FLOAT); + typeList.Add(typeof(float[]), FREE_IMAGE_MDTYPE.FIDT_FLOAT); + typeList.Add(typeof(double), FREE_IMAGE_MDTYPE.FIDT_DOUBLE); + typeList.Add(typeof(double[]), FREE_IMAGE_MDTYPE.FIDT_DOUBLE); + typeList.Add(typeof(RGBQUAD), FREE_IMAGE_MDTYPE.FIDT_PALETTE); + typeList.Add(typeof(RGBQUAD[]), FREE_IMAGE_MDTYPE.FIDT_PALETTE); + } + + /// + /// Releases all resources used by the instance. + /// + ~MetadataTag() + { + Dispose(); + } + + /// + /// Determines whether two specified objects have the same value. + /// + /// A or a null reference (Nothing in Visual Basic). + /// A or a null reference (Nothing in Visual Basic). + /// + /// true if the value of left is the same as the value of right; otherwise, false. + /// + public static bool operator ==(MetadataTag left, MetadataTag right) + { + // Check whether both are null + if ((object)left == (object)right) + { + return true; + } + else if ((object)left == null || (object)right == null) + { + return false; + } + left.CheckDisposed(); + right.CheckDisposed(); + // Check all properties + if ((left.Key != right.Key) || + (left.ID != right.ID) || + (left.Description != right.Description) || + (left.Count != right.Count) || + (left.Length != right.Length) || + (left.Model != right.Model) || + (left.Type != right.Type)) + { + return false; + } + if (left.Length == 0) + { + return true; + } + IntPtr ptr1 = FreeImage.GetTagValue(left.tag); + IntPtr ptr2 = FreeImage.GetTagValue(right.tag); + return FreeImage.CompareMemory(ptr1, ptr2, left.Length); + } + + /// + /// Determines whether two specified objects have different values. + /// + /// A or a null reference (Nothing in Visual Basic). + /// A or a null reference (Nothing in Visual Basic). + /// + /// true if the value of left is different from the value of right; otherwise, false. + /// + public static bool operator !=(MetadataTag left, MetadataTag right) + { + return !(left == right); + } + + /// + /// Extracts the value of a instance to a handle. + /// + /// A instance. + /// A new instance of initialized to . + public static implicit operator FITAG(MetadataTag value) + { + return value.tag; + } + + private static FREE_IMAGE_MDMODEL GetModel(FIBITMAP dib, FITAG tag) + { + FITAG value; + foreach (FREE_IMAGE_MDMODEL model in FreeImage.FREE_IMAGE_MDMODELS) + { + FIMETADATA mData = FreeImage.FindFirstMetadata(model, dib, out value); + if (mData.IsNull) + { + continue; + } + try + { + do + { + if (value == tag) + { + return model; + } + } + while (FreeImage.FindNextMetadata(mData, out value)); + } + finally + { + if (!mData.IsNull) + { + FreeImage.FindCloseMetadata(mData); + } + } + } + throw new ArgumentException("'tag' is no metadata object of 'dib'"); + } + + /// + /// Gets the model of the metadata. + /// + public FREE_IMAGE_MDMODEL Model + { + get { CheckDisposed(); return model; } + } + + /// + /// Gets or sets the key of the metadata. + /// + public string Key + { + get { CheckDisposed(); return FreeImage.GetTagKey(tag); } + set + { + CheckDisposed(); + if ((model != FREE_IMAGE_MDMODEL.FIMD_XMP) || (value == "XMLPacket")) + { + FreeImage.SetTagKey(tag, value); + } + } + } + + /// + /// Gets or sets the description of the metadata. + /// + public string Description + { + get { CheckDisposed(); return FreeImage.GetTagDescription(tag); } + set { CheckDisposed(); FreeImage.SetTagDescription(tag, value); } + } + + /// + /// Gets or sets the ID of the metadata. + /// + public ushort ID + { + get { CheckDisposed(); return FreeImage.GetTagID(tag); } + set { CheckDisposed(); FreeImage.SetTagID(tag, value); } + } + + /// + /// Gets the type of the metadata. + /// + public FREE_IMAGE_MDTYPE Type + { + get { CheckDisposed(); return FreeImage.GetTagType(tag); } + internal set { FreeImage.SetTagType(tag, value); } + } + + /// + /// Gets the number of elements the metadata object contains. + /// + public uint Count + { + get { CheckDisposed(); return FreeImage.GetTagCount(tag); } + private set { FreeImage.SetTagCount(tag, value); } + } + + /// + /// Gets the length of the value in bytes. + /// + public uint Length + { + get { CheckDisposed(); return FreeImage.GetTagLength(tag); } + private set { FreeImage.SetTagLength(tag, value); } + } + + private unsafe byte[] GetData() + { + uint length = Length; + byte[] value = new byte[length]; + byte* ptr = (byte*)FreeImage.GetTagValue(tag); + for (int i = 0; i < length; i++) + { + value[i] = ptr[i]; + } + return value; + } + + /// + /// Gets or sets the value of the metadata. + /// + public object Value + { + get + { + unsafe + { + CheckDisposed(); + int cnt = (int)Count; + + if (Type == FREE_IMAGE_MDTYPE.FIDT_ASCII) + { + byte* value = (byte*)FreeImage.GetTagValue(tag); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < cnt; i++) + { + sb.Append(Convert.ToChar(value[i])); + } + return sb.ToString(); + } + else if (Type == FREE_IMAGE_MDTYPE.FIDT_NOTYPE) + { + return null; + } + + Array array = Array.CreateInstance(idList[Type], Count); + void* src = (void*)FreeImage.GetTagValue(tag); + FreeImage.CopyMemory(array, src, Length); + return array; + } + } + set + { + SetValue(value); + } + } + + /// + /// Sets the value of the metadata. + /// In case value is of byte or byte[] is assumed. + /// In case value is of uint or uint[] is assumed. + /// + /// New data of the metadata. + /// True on success, false on failure. + /// + /// The data format is not supported. + /// + /// is null. + public bool SetValue(object value) + { + Type type = value.GetType(); + if (!typeList.ContainsKey(type)) + { + throw new NotSupportedException("The type of value is not supported"); + } + return SetValue(value, typeList[type]); + } + + /// + /// Sets the value of the metadata. + /// + /// New data of the metadata. + /// Type of the data. + /// True on success, false on failure. + /// + /// The data type is not supported. + /// + /// is null. + /// + /// and to not fit. + public bool SetValue(object value, FREE_IMAGE_MDTYPE type) + { + CheckDisposed(); + if ((!value.GetType().IsArray) && (!(value is string))) + { + Array array = Array.CreateInstance(value.GetType(), 1); + array.SetValue(value, 0); + return SetArrayValue(array, type); + } + return SetArrayValue(value, type); + } + + /// + /// Sets the value of this tag to the value of + /// using the given type. + /// + /// New value of the tag. + /// Data-type of the tag. + /// + /// + /// is a null reference. + /// + /// + /// is FIDT_ASCII and + /// is not String. + /// is not FIDT_ASCII and + /// is not Array. + /// + /// is FIDT_NOTYPE. + private unsafe bool SetArrayValue(object value, FREE_IMAGE_MDTYPE type) + { + if (value == null) + { + throw new ArgumentNullException("value"); + } + + byte[] data = null; + + if (type == FREE_IMAGE_MDTYPE.FIDT_ASCII) + { + string tempValue = value as string; + if (tempValue == null) + { + throw new ArgumentException("value"); + } + Type = type; + Length = Count = (uint)tempValue.Length; + data = new byte[Length]; + + for (int i = 0; i < tempValue.Length; i++) + { + data[i] = (byte)tempValue[i]; + } + } + else if (type == FREE_IMAGE_MDTYPE.FIDT_NOTYPE) + { + throw new NotSupportedException("type is not supported."); + } + else + { + Array array = value as Array; + if (array == null) + { + throw new ArgumentException("value"); + } + + if (array.Length != 0) + if (!CheckType(array.GetValue(0).GetType(), type)) + throw new ArgumentException("The type of value is incorrect."); + + Type = type; + Count = (uint)array.Length; + Length = (uint)(array.Length * Marshal.SizeOf(idList[type])); + data = new byte[Length]; + FreeImage.CopyMemory(data, array, Length); + } + + return FreeImage.SetTagValue(tag, data); + } + + private static bool CheckType(Type dataType, FREE_IMAGE_MDTYPE type) + { + if (dataType != null) + switch (type) + { + case FREE_IMAGE_MDTYPE.FIDT_ASCII: + return dataType == typeof(string); + case FREE_IMAGE_MDTYPE.FIDT_BYTE: + return dataType == typeof(byte); + case FREE_IMAGE_MDTYPE.FIDT_DOUBLE: + return dataType == typeof(double); + case FREE_IMAGE_MDTYPE.FIDT_FLOAT: + return dataType == typeof(float); + case FREE_IMAGE_MDTYPE.FIDT_IFD: + return dataType == typeof(uint); + case FREE_IMAGE_MDTYPE.FIDT_LONG: + return dataType == typeof(uint); + case FREE_IMAGE_MDTYPE.FIDT_NOTYPE: + return false; + case FREE_IMAGE_MDTYPE.FIDT_PALETTE: + return dataType == typeof(RGBQUAD); + case FREE_IMAGE_MDTYPE.FIDT_RATIONAL: + return dataType == typeof(FIURational); + case FREE_IMAGE_MDTYPE.FIDT_SBYTE: + return dataType == typeof(sbyte); + case FREE_IMAGE_MDTYPE.FIDT_SHORT: + return dataType == typeof(ushort); + case FREE_IMAGE_MDTYPE.FIDT_SLONG: + return dataType == typeof(int); + case FREE_IMAGE_MDTYPE.FIDT_SRATIONAL: + return dataType == typeof(FIRational); + case FREE_IMAGE_MDTYPE.FIDT_SSHORT: + return dataType == typeof(short); + case FREE_IMAGE_MDTYPE.FIDT_UNDEFINED: + return dataType == typeof(byte); + } + return false; + } + + /// + /// Add this metadata to an image. + /// + /// Handle to a FreeImage bitmap. + /// True on success, false on failure. + public bool AddToImage(FIBITMAP dib) + { + CheckDisposed(); + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + if (Key == null) + { + throw new ArgumentNullException("Key"); + } + if (!selfCreated) + { + tag = FreeImage.CloneTag(tag); + if (tag.IsNull) + { + throw new Exception("FreeImage.CloneTag() failed."); + } + selfCreated = true; + } + if (!FreeImage.SetMetadata(Model, dib, Key, tag)) + { + return false; + } + FREE_IMAGE_MDMODEL _model = Model; + string _key = Key; + selfCreated = false; + FreeImage.DeleteTag(tag); + return FreeImage.GetMetadata(_model, dib, _key, out tag); + } + + /// + /// Gets a .NET PropertyItem for this metadata tag. + /// + /// The .NET PropertyItem. + public unsafe System.Drawing.Imaging.PropertyItem GetPropertyItem() + { + System.Drawing.Imaging.PropertyItem item = FreeImage.CreatePropertyItem(); + item.Id = ID; + item.Len = (int)Length; + item.Type = (short)Type; + FreeImage.CopyMemory(item.Value = new byte[item.Len], FreeImage.GetTagValue(tag), item.Len); + return item; + } + + /// + /// Converts the value of the object + /// to its equivalent string representation. + /// + /// The string representation of the value of this instance. + public override string ToString() + { + CheckDisposed(); + string fiString = FreeImage.TagToString(model, tag, 0); + + if (String.IsNullOrEmpty(fiString)) + { + return tag.ToString(); + } + else + { + return fiString; + } + } + + /// + /// Creates a deep copy of this . + /// + /// A deep copy of this . + public object Clone() + { + CheckDisposed(); + MetadataTag clone = new MetadataTag(); + clone.model = model; + clone.tag = FreeImage.CloneTag(tag); + clone.selfCreated = true; + return clone; + } + + /// + /// Tests whether the specified object is a instance + /// and is equivalent to this instance. + /// + /// The object to test. + /// true if is a instance + /// equivalent to this instance; otherwise, false. + public override bool Equals(object obj) + { + return ((obj is MetadataTag) && (Equals((MetadataTag)obj))); + } + + /// + /// Tests whether the specified instance is equivalent to this instance. + /// + /// A instance to compare to this instance. + /// true if equivalent to this instance; + /// otherwise, false. + public bool Equals(MetadataTag other) + { + return (this == other); + } + + /// + /// Returns a hash code for this structure. + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + return tag.GetHashCode(); + } + + /// + /// Compares this instance with a specified . + /// + /// An object to compare with this instance. + /// A 32-bit signed integer indicating the lexical relationship between the two comparands. + /// is not a . + public int CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is MetadataTag)) + { + throw new ArgumentException("obj"); + } + return CompareTo((MetadataTag)obj); + } + + /// + /// Compares the current instance with another object of the same type. + /// + /// An object to compare with this instance. + /// A 32-bit signed integer that indicates the relative order of the objects being compared. + public int CompareTo(MetadataTag other) + { + CheckDisposed(); + other.CheckDisposed(); + return tag.CompareTo(other.tag); + } + + /// + /// Releases all resources used by the instance. + /// + public void Dispose() + { + if (!disposed) + { + disposed = true; + if (selfCreated) + { + FreeImage.DeleteTag(tag); + tag = FITAG.Zero; + } + } + } + + /// + /// Gets whether this instance has already been disposed. + /// + public bool Disposed + { + get { return disposed; } + } + + /// + /// Throwns an in case + /// this instance has already been disposed. + /// + private void CheckDisposed() + { + if (disposed) + { + throw new ObjectDisposedException("The object has already been disposed."); + } + } + } +} + +namespace FreeImageAPI +{ + /// + /// Provides methods for working with the standard bitmap palette. + /// + public sealed class Palette : MemoryArray + { + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private GCHandle paletteHandle; + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private RGBQUAD[] array; + + /// + /// Initializes a new instance for the given FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// is null. + /// is not + /// -or- + /// has more than 8bpp. + public Palette(FIBITMAP dib) + : base(FreeImage.GetPalette(dib), (int)FreeImage.GetColorsUsed(dib)) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + if (FreeImage.GetImageType(dib) != FREE_IMAGE_TYPE.FIT_BITMAP) + { + throw new ArgumentException("dib"); + } + if (FreeImage.GetBPP(dib) > 8u) + { + throw new ArgumentException("dib"); + } + } + + /// + /// Initializes a new instance for the given FITAG that contains + /// a palette. + /// + /// The tag containing the palette. + /// is null. + /// is not + /// . + public Palette(FITAG tag) + : base(FreeImage.GetTagValue(tag), (int)FreeImage.GetTagCount(tag)) + { + if (FreeImage.GetTagType(tag) != FREE_IMAGE_MDTYPE.FIDT_PALETTE) + { + throw new ArgumentException("tag"); + } + } + + /// + /// Initializes a new instance for the given MetadataTag that contains + /// a palette. + /// + /// The tag containing the palette. + /// is null. + /// is not + /// . + public Palette(MetadataTag tag) + : base(FreeImage.GetTagValue(tag.tag), (int)tag.Count) + { + if (FreeImage.GetTagType(tag) != FREE_IMAGE_MDTYPE.FIDT_PALETTE) + { + throw new ArgumentException("tag"); + } + } + + /// + /// Initializes a new instance for the given array of that contains + /// a palette. + /// + /// A RGBQUAD array containing the palette data to initialize this instance. + public Palette(RGBQUAD[] palette) + { + unsafe + { + this.array = (RGBQUAD[])palette.Clone(); + this.paletteHandle = GCHandle.Alloc(array, GCHandleType.Pinned); + + base.baseAddress = (byte*)this.paletteHandle.AddrOfPinnedObject(); + base.length = (int)this.array.Length; + + // Create an array containing a single element. + // Due to the fact, that it's not possible to create pointers + // of generic types, an array is used to obtain the memory + // address of an element of T. + base.buffer = new RGBQUAD[1]; + // The array is pinned immediately to prevent the GC from + // moving it to a different position in memory. + base.handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + // The array and its content have beed pinned, so that its address + // can be safely requested and stored for the whole lifetime + // of the instace. + base.ptr = (byte*)base.handle.AddrOfPinnedObject(); + } + } + + /// + /// Initializes a new instance for the given array of that contains + /// a palette. + /// + /// A Color array containing the palette data to initialize this instance. + public Palette(Color[] palette) + : this(RGBQUAD.ToRGBQUAD(palette)) + { + } + + /// + /// Initializes a new instance with the specified size. + /// + /// The size of the palette. + public Palette(int size) + : this(new RGBQUAD[size]) + { + } + + /// + /// Gets or sets the palette through an array of . + /// + public RGBQUAD[] AsArray + { + get + { + return Data; + } + set + { + Data = value; + } + } + + /// + /// Get an array of that the block of memory represents. + /// This property is used for internal palette operations. + /// + internal unsafe Color[] ColorData + { + get + { + EnsureNotDisposed(); + Color[] data = new Color[length]; + for (int i = 0; i < length; i++) + { + data[i] = Color.FromArgb((int)(((uint*)baseAddress)[i] | 0xFF000000)); + } + return data; + } + } + + /// + /// Returns the palette as an array of . + /// + /// The palette as an array of . + public RGBQUAD[] ToArray() + { + return Data; + } + + /// + /// Creates a linear palette based on the provided . + /// + /// The used to colorize the palette. + /// + /// Only call this method on linear palettes. + /// + public void Colorize(Color color) + { + Colorize(color, 0.5d); + } + + /// + /// Creates a linear palette based on the provided . + /// + /// The used to colorize the palette. + /// The position of the color within the new palette. + /// 0 < < 1. + /// + /// Only call this method on linear palettes. + /// + public void Colorize(Color color, double splitSize) + { + Colorize(color, (int)(length * splitSize)); + } + + /// + /// Creates a linear palette based on the provided . + /// + /// The used to colorize the palette. + /// The position of the color within the new palette. + /// 0 < < . + /// + /// Only call this method on linear palettes. + /// + public void Colorize(Color color, int splitSize) + { + EnsureNotDisposed(); + if (splitSize < 1 || splitSize >= length) + { + throw new ArgumentOutOfRangeException("splitSize"); + } + + RGBQUAD[] pal = new RGBQUAD[length]; + + double red = color.R; + double green = color.G; + double blue = color.B; + + int i = 0; + double r, g, b; + + r = red / splitSize; + g = green / splitSize; + b = blue / splitSize; + + for (; i <= splitSize; i++) + { + pal[i].rgbRed = (byte)(i * r); + pal[i].rgbGreen = (byte)(i * g); + pal[i].rgbBlue = (byte)(i * b); + } + + r = (255 - red) / (length - splitSize); + g = (255 - green) / (length - splitSize); + b = (255 - blue) / (length - splitSize); + + for (; i < length; i++) + { + pal[i].rgbRed = (byte)(red + ((i - splitSize) * r)); + pal[i].rgbGreen = (byte)(green + ((i - splitSize) * g)); + pal[i].rgbBlue = (byte)(blue + ((i - splitSize) * b)); + } + + Data = pal; + } + + /// + /// Creates a linear grayscale palette. + /// + public void CreateGrayscalePalette() + { + Colorize(Color.White, length - 1); + } + + /// + /// Creates a linear grayscale palette. + /// + /// true to create an inverse grayscale palette. + public void CreateGrayscalePalette(bool inverse) + { + Colorize(Color.White, inverse ? 0 : length - 1); + } + + /// + /// Creates a linear palette with the specified . + /// + /// + /// A linear grayscale palette contains all shades of colors from + /// black to white. This method creates a similar palette with the white + /// color being replaced by the specified color. + /// + /// The used to create the palette. + /// true to create an inverse palette. + public void CreateGrayscalePalette(Color color, bool inverse) + { + Colorize(color, inverse ? 0 : length - 1); + } + + /// + /// Reverses the palette. + /// + public void Reverse() + { + EnsureNotDisposed(); + if (array != null) + { + Array.Reverse(array); + } + else + { + RGBQUAD[] localArray = Data; + Array.Reverse(localArray); + Data = localArray; + } + } + + /// + /// Copies the values from the specified to this instance. + /// + /// The palette to copy from. + /// + /// is a null reference. + public void CopyFrom(Palette palette) + { + EnsureNotDisposed(); + if (palette == null) + { + throw new ArgumentNullException("palette"); + } + CopyFrom(palette.Data, 0, 0, Math.Min(palette.Length, this.Length)); + } + + /// + /// Copies the values from the specified to this instance, + /// starting at the specified . + /// + /// The palette to copy from. + /// The position in this instance where the values + /// will be copied to. + /// + /// is a null reference. + /// + /// is outside the range of valid indexes. + public void CopyFrom(Palette palette, int offset) + { + EnsureNotDisposed(); + CopyFrom(palette.Data, 0, offset, Math.Min(palette.Length, this.Length - offset)); + } + + /// + /// Saves this to the specified file. + /// + /// + /// A string that contains the name of the file to which to save this . + /// + public void Save(string filename) + { + using (Stream stream = new FileStream(filename, FileMode.Create, FileAccess.Write)) + { + Save(stream); + } + } + + /// + /// Saves this to the specified stream. + /// + /// + /// The where the image will be saved. + /// + public void Save(Stream stream) + { + Save(new BinaryWriter(stream)); + } + + /// + /// Saves this using the specified writer. + /// + /// + /// The used to save the image. + /// + public void Save(BinaryWriter writer) + { + EnsureNotDisposed(); + writer.Write(ToByteArray()); + } + + /// + /// Loads a palette from the specified file. + /// + /// The name of the palette file. + public void Load(string filename) + { + using (Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read)) + { + Load(stream); + } + } + + /// + /// Loads a palette from the specified stream. + /// + /// The stream to load the palette from. + public void Load(Stream stream) + { + Load(new BinaryReader(stream)); + } + + /// + /// Loads a palette from the reader. + /// + /// The reader to load the palette from. + public void Load(BinaryReader reader) + { + EnsureNotDisposed(); + unsafe + { + int size = length * sizeof(RGBQUAD); + byte[] data = reader.ReadBytes(size); + fixed (byte* src = data) + { + CopyMemory(baseAddress, src, data.Length); + } + } + } + + /// + /// Releases allocated handles associated with this instance. + /// + /// true to release managed resources. + protected override void Dispose(bool disposing) + { + if (paletteHandle.IsAllocated) + paletteHandle.Free(); + array = null; + + base.Dispose(disposing); + } + } +} + +namespace FreeImageAPI.Plugins +{ + /// + /// Class representing all registered in FreeImage. + /// + public static class PluginRepository + { + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private static readonly List plugins = null; + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private static readonly List localPlugins = null; + + static PluginRepository() + { + plugins = new List(FreeImage.GetFIFCount()); + localPlugins = new List(0); + for (int i = 0; i < plugins.Capacity; i++) + { + plugins.Add(new FreeImagePlugin((FREE_IMAGE_FORMAT)i)); + } + } + + /// + /// Adds local plugin to this class. + /// + /// The registered plugin. + internal static void RegisterLocalPlugin(LocalPlugin localPlugin) + { + FreeImagePlugin plugin = new FreeImagePlugin(localPlugin.Format); + plugins.Add(plugin); + localPlugins.Add(plugin); + } + + /// + /// Returns an instance of , representing the given format. + /// + /// The representing format. + /// An instance of . + public static FreeImagePlugin Plugin(FREE_IMAGE_FORMAT fif) + { + return Plugin((int)fif); + } + + /// + /// Returns an instance of , + /// representing the format at the given index. + /// + /// The index of the representing format. + /// An instance of . + public static FreeImagePlugin Plugin(int index) + { + return (index >= 0) ? plugins[index] : null; + } + + /// + /// Returns an instance of . + /// is searched in: + /// Format, RegExpr, + /// ValidExtension and ValidFilename. + /// + /// The expression to search for. + /// An instance of . + public static FreeImagePlugin Plugin(string expression) + { + FreeImagePlugin result = null; + expression = expression.ToLower(); + + foreach (FreeImagePlugin plugin in plugins) + { + if (plugin.Format.ToLower().Contains(expression) || + plugin.RegExpr.ToLower().Contains(expression) || + plugin.ValidExtension(expression, StringComparison.CurrentCultureIgnoreCase) || + plugin.ValidFilename(expression, StringComparison.CurrentCultureIgnoreCase)) + { + result = plugin; + break; + } + } + + return result; + } + + /// + /// Returns an instance of for the given format. + /// + /// The format of the Plugin. + /// An instance of . + public static FreeImagePlugin PluginFromFormat(string format) + { + return Plugin(FreeImage.GetFIFFromFormat(format)); + } + + /// + /// Returns an instance of for the given filename. + /// + /// The valid filename for the plugin. + /// An instance of . + public static FreeImagePlugin PluginFromFilename(string filename) + { + return Plugin(FreeImage.GetFIFFromFilename(filename)); + } + + /// + /// Returns an instance of for the given mime. + /// + /// The valid mime for the plugin. + /// An instance of . + public static FreeImagePlugin PluginFromMime(string mime) + { + return Plugin(FreeImage.GetFIFFromMime(mime)); + } + + /// + /// Gets the number of registered plugins. + /// + public static int FIFCount + { + get + { + return FreeImage.GetFIFCount(); + } + } + + /// + /// Gets a readonly collection of all plugins. + /// + public static ReadOnlyCollection PluginList + { + get + { + return plugins.AsReadOnly(); + } + } + + /// + /// Gets a list of plugins that are only able to + /// read but not to write. + /// + public static List ReadOnlyPlugins + { + get + { + List list = new List(); + foreach (FreeImagePlugin p in plugins) + { + if (p.SupportsReading && !p.SupportsWriting) + { + list.Add(p); + } + } + return list; + } + } + + /// + /// Gets a list of plugins that are only able to + /// write but not to read. + /// + public static List WriteOnlyPlugins + { + get + { + List list = new List(); + foreach (FreeImagePlugin p in plugins) + { + if (!p.SupportsReading && p.SupportsWriting) + { + list.Add(p); + } + } + return list; + } + } + + /// + /// Gets a list of plugins that are not able to + /// read or write. + /// + public static List StupidPlugins + { + get + { + List list = new List(); + foreach (FreeImagePlugin p in plugins) + { + if (!p.SupportsReading && !p.SupportsWriting) + { + list.Add(p); + } + } + return list; + } + } + + /// + /// Gets a list of plugins that are able to read. + /// + public static List ReadablePlugins + { + get + { + List list = new List(); + foreach (FreeImagePlugin p in plugins) + { + if (p.SupportsReading) + { + list.Add(p); + } + } + return list; + } + } + + /// + /// Gets a list of plugins that are able to write. + /// + public static List WriteablePlugins + { + get + { + List list = new List(); + foreach (FreeImagePlugin p in plugins) + { + if (p.SupportsWriting) + { + list.Add(p); + } + } + return list; + } + } + + /// + /// Gets a list of local plugins. + /// + public static ReadOnlyCollection LocalPlugins + { + get + { + return localPlugins.AsReadOnly(); + } + } + + /// + /// Gets a list of built-in plugins. + /// + public static List BuiltInPlugins + { + get + { + List list = new List(); + foreach (FreeImagePlugin p in plugins) + { + if (!localPlugins.Contains(p)) + { + list.Add(p); + } + } + return list; + } + } + + /// + /// Windows or OS/2 Bitmap File (*.BMP) + /// + public static FreeImagePlugin BMP { get { return plugins[0]; } } + + /// + /// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE) + /// + public static FreeImagePlugin ICO { get { return plugins[1]; } } + + /// + /// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE) + /// + public static FreeImagePlugin JPEG { get { return plugins[2]; } } + + /// + /// JPEG Network Graphics (*.JNG) + /// + public static FreeImagePlugin JNG { get { return plugins[3]; } } + + /// + /// Commodore 64 Koala format (*.KOA) + /// + public static FreeImagePlugin KOALA { get { return plugins[4]; } } + + /// + /// Amiga IFF (*.IFF, *.LBM) + /// + public static FreeImagePlugin LBM { get { return plugins[5]; } } + + /// + /// Amiga IFF (*.IFF, *.LBM) + /// + public static FreeImagePlugin IFF { get { return plugins[5]; } } + + /// + /// Multiple Network Graphics (*.MNG) + /// + public static FreeImagePlugin MNG { get { return plugins[6]; } } + + /// + /// Portable Bitmap (ASCII) (*.PBM) + /// + public static FreeImagePlugin PBM { get { return plugins[7]; } } + + /// + /// Portable Bitmap (BINARY) (*.PBM) + /// + public static FreeImagePlugin PBMRAW { get { return plugins[8]; } } + + /// + /// Kodak PhotoCD (*.PCD) + /// + public static FreeImagePlugin PCD { get { return plugins[9]; } } + + /// + /// Zsoft Paintbrush PCX bitmap format (*.PCX) + /// + public static FreeImagePlugin PCX { get { return plugins[10]; } } + + /// + /// Portable Graymap (ASCII) (*.PGM) + /// + public static FreeImagePlugin PGM { get { return plugins[11]; } } + + /// + /// Portable Graymap (BINARY) (*.PGM) + /// + public static FreeImagePlugin PGMRAW { get { return plugins[12]; } } + + /// + /// Portable Network Graphics (*.PNG) + /// + public static FreeImagePlugin PNG { get { return plugins[13]; } } + + /// + /// Portable Pixelmap (ASCII) (*.PPM) + /// + public static FreeImagePlugin PPM { get { return plugins[14]; } } + + /// + /// Portable Pixelmap (BINARY) (*.PPM) + /// + public static FreeImagePlugin PPMRAW { get { return plugins[15]; } } + + /// + /// Sun Rasterfile (*.RAS) + /// + public static FreeImagePlugin RAS { get { return plugins[16]; } } + + /// + /// truevision Targa files (*.TGA, *.TARGA) + /// + public static FreeImagePlugin TARGA { get { return plugins[17]; } } + + /// + /// Tagged Image File Format (*.TIF, *.TIFF) + /// + public static FreeImagePlugin TIFF { get { return plugins[18]; } } + + /// + /// Wireless Bitmap (*.WBMP) + /// + public static FreeImagePlugin WBMP { get { return plugins[19]; } } + + /// + /// Adobe Photoshop (*.PSD) + /// + public static FreeImagePlugin PSD { get { return plugins[20]; } } + + /// + /// Dr. Halo (*.CUT) + /// + public static FreeImagePlugin CUT { get { return plugins[21]; } } + + /// + /// X11 Bitmap Format (*.XBM) + /// + public static FreeImagePlugin XBM { get { return plugins[22]; } } + + /// + /// X11 Pixmap Format (*.XPM) + /// + public static FreeImagePlugin XPM { get { return plugins[23]; } } + + /// + /// DirectDraw Surface (*.DDS) + /// + public static FreeImagePlugin DDS { get { return plugins[24]; } } + + /// + /// Graphics Interchange Format (*.GIF) + /// + public static FreeImagePlugin GIF { get { return plugins[25]; } } + + /// + /// High Dynamic Range (*.HDR) + /// + public static FreeImagePlugin HDR { get { return plugins[26]; } } + + /// + /// Raw Fax format CCITT G3 (*.G3) + /// + public static FreeImagePlugin FAXG3 { get { return plugins[27]; } } + + /// + /// Silicon Graphics SGI image format (*.SGI) + /// + public static FreeImagePlugin SGI { get { return plugins[28]; } } + + /// + /// OpenEXR format (*.EXR) + /// + public static FreeImagePlugin EXR { get { return plugins[29]; } } + + /// + /// JPEG-2000 format (*.J2K, *.J2C) + /// + public static FreeImagePlugin J2K { get { return plugins[30]; } } + + /// + /// JPEG-2000 format (*.JP2) + /// + public static FreeImagePlugin JP2 { get { return plugins[31]; } } + + /// + /// Portable FloatMap (*.PFM) + /// + public static FreeImagePlugin PFM { get { return plugins[32]; } } + + /// + /// Macintosh PICT (*.PICT) + /// + public static FreeImagePlugin PICT { get { return plugins[33]; } } + + /// + /// RAW camera image (*.*) + /// + public static FreeImagePlugin RAW { get { return plugins[34]; } } + } +} + +namespace FreeImageAPI +{ + /// + /// Provides methods for working with generic bitmap scanlines. + /// + /// Type of the bitmaps' scanlines. + public sealed class Scanline : MemoryArray where T : struct + { + /// + /// Initializes a new instance based on the specified FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + public Scanline(FIBITMAP dib) + : this(dib, 0) + { + } + + /// + /// Initializes a new instance based on the specified FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// Index of the zero based scanline. + public Scanline(FIBITMAP dib, int scanline) + : this(dib, scanline, (int)(typeof(T) == typeof(FI1BIT) ? + FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib) : + typeof(T) == typeof(FI4BIT) ? + FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib) / 4 : + (FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib)) / (Marshal.SizeOf(typeof(T)) * 8))) + { + } + + internal Scanline(FIBITMAP dib, int scanline, int length) + : base(FreeImage.GetScanLine(dib, scanline), length) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + if ((scanline < 0) || (scanline >= FreeImage.GetHeight(dib))) + { + throw new ArgumentOutOfRangeException("scanline"); + } + } + } +} + +namespace FreeImageAPI.IO +{ + /// + /// Class wrapping streams, implementing a buffer for read data, + /// so that seek operations can be made. + /// + /// + /// FreeImage can load bitmaps from arbitrary sources. + /// .NET works with different streams like File- or NetConnection-strams. + /// NetConnection streams, which are used to load files from web servers, + /// for example cannot seek. + /// But FreeImage frequently uses the seek operation when loading bitmaps. + /// StreamWrapper wrapps a stream and makes it seekable by caching all read + /// data into an internal MemoryStream to jump back- and forward. + /// StreamWapper is for internal use and only for loading from streams. + /// + internal class StreamWrapper : Stream + { + /// + /// The stream to wrap + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private readonly Stream stream; + + /// + /// The caching stream + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private MemoryStream memoryStream = new MemoryStream(); + + /// + /// Indicates if the wrapped stream reached its end + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool eos = false; + + /// + /// Tells the wrapper to block readings or not + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool blocking = false; + + /// + /// Indicates if the wrapped stream is disposed or not + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool disposed = false; + + /// + /// Initializes a new instance based on the specified . + /// + /// The stream to wrap. + /// When true the wrapper always tries to read the requested + /// amount of data from the wrapped stream. + public StreamWrapper(Stream stream, bool blocking) + { + if (!stream.CanRead) + { + throw new ArgumentException("stream is not capable of reading."); + } + this.stream = stream; + this.blocking = blocking; + } + + /// + /// Releases all resources used by the instance. + /// + ~StreamWrapper() + { + Dispose(false); + } + + // The wrapper only accepts readable streams + public override bool CanRead + { + get { checkDisposed(); return true; } + } + + // We implement that feature + public override bool CanSeek + { + get { checkDisposed(); return true; } + } + + // The wrapper is readonly + public override bool CanWrite + { + get { checkDisposed(); return false; } + } + + // Just forward it + public override void Flush() + { + checkDisposed(); + stream.Flush(); + } + + // Calling this property will cause the wrapper to read the stream + // to its end and cache it completely. + public override long Length + { + get + { + checkDisposed(); + if (!eos) + { + Fill(); + } + return memoryStream.Length; + } + } + + // Gets or sets the current position + public override long Position + { + get + { + checkDisposed(); + return memoryStream.Position; + } + set + { + checkDisposed(); + Seek(value, SeekOrigin.Begin); + } + } + + // Implements the reading feature + public override int Read(byte[] buffer, int offset, int count) + { + checkDisposed(); + // total bytes read from memory-stream + int memoryBytes = 0; + // total bytes read from the original stream + int streamBytes = 0; + memoryBytes = memoryStream.Read(buffer, offset, count); + if ((count > memoryBytes) && (!eos)) + { + // read the rest from the original stream (can be 0 bytes) + do + { + int read = stream.Read( + buffer, + offset + memoryBytes + streamBytes, + count - memoryBytes - streamBytes); + streamBytes += read; + if (read == 0) + { + eos = true; + break; + } + if (!blocking) + { + break; + } + } while ((memoryBytes + streamBytes) < count); + // copy the bytes from the original stream into the memory stream + // if 0 bytes were read we write 0 so the memory-stream is not changed + memoryStream.Write(buffer, offset + memoryBytes, streamBytes); + } + return memoryBytes + streamBytes; + } + + // Implements the seeking feature + public override long Seek(long offset, SeekOrigin origin) + { + checkDisposed(); + long newPosition = 0L; + // get new position + switch (origin) + { + case SeekOrigin.Begin: + newPosition = offset; + break; + case SeekOrigin.Current: + newPosition = memoryStream.Position + offset; + break; + case SeekOrigin.End: + // to seek from the end have have to read to the end first + if (!eos) + { + Fill(); + } + newPosition = memoryStream.Length + offset; + break; + default: + throw new ArgumentOutOfRangeException("origin"); + } + // in case the new position is beyond the memory-streams end + // and the original streams end hasn't been reached + // the original stream is read until either the stream ends or + // enough bytes have been read + if ((newPosition > memoryStream.Length) && (!eos)) + { + memoryStream.Position = memoryStream.Length; + int bytesToRead = (int)(newPosition - memoryStream.Length); + byte[] buffer = new byte[1024]; + do + { + bytesToRead -= Read(buffer, 0, (bytesToRead >= buffer.Length) ? buffer.Length : bytesToRead); + } while ((bytesToRead > 0) && (!eos)); + } + memoryStream.Position = (newPosition <= memoryStream.Length) ? newPosition : memoryStream.Length; + return 0; + } + + // No write-support + public override void SetLength(long value) + { + throw new Exception("The method or operation is not implemented."); + } + + // No write-support + public override void Write(byte[] buffer, int offset, int count) + { + throw new Exception("The method or operation is not implemented."); + } + + public void Reset() + { + checkDisposed(); + Position = 0; + } + + // Reads the wrapped stream until its end. + private void Fill() + { + if (!eos) + { + memoryStream.Position = memoryStream.Length; + int bytesRead = 0; + byte[] buffer = new byte[1024]; + do + { + bytesRead = stream.Read(buffer, 0, buffer.Length); + memoryStream.Write(buffer, 0, bytesRead); + } while (bytesRead != 0); + eos = true; + } + } + + public new void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private new void Dispose(bool disposing) + { + if (!disposed) + { + disposed = true; + if (disposing) + { + if (memoryStream != null) + { + memoryStream.Dispose(); + } + } + } + } + + public bool Disposed + { + get { return disposed; } + } + + private void checkDisposed() + { + if (disposed) throw new ObjectDisposedException("StreamWrapper"); + } + } +} + + #endregion + + #region Enums + +namespace FreeImageAPI +{ + /// + /// Enumeration used for color conversions. + /// FREE_IMAGE_COLOR_DEPTH contains several colors to convert to. + /// The default value 'FICD_AUTO'. + /// + [System.Flags] + public enum FREE_IMAGE_COLOR_DEPTH + { + /// + /// Unknown. + /// + FICD_UNKNOWN = 0, + /// + /// Auto selected by the used algorithm. + /// + FICD_AUTO = FICD_UNKNOWN, + /// + /// 1-bit. + /// + FICD_01_BPP = 1, + /// + /// 1-bit using dithering. + /// + FICD_01_BPP_DITHER = FICD_01_BPP, + /// + /// 1-bit using threshold. + /// + FICD_01_BPP_THRESHOLD = FICD_01_BPP | 2, + /// + /// 4-bit. + /// + FICD_04_BPP = 4, + /// + /// 8-bit. + /// + FICD_08_BPP = 8, + /// + /// 16-bit 555 (1 bit remains unused). + /// + FICD_16_BPP_555 = FICD_16_BPP | 2, + /// + /// 16-bit 565 (all bits are used). + /// + FICD_16_BPP = 16, + /// + /// 24-bit. + /// + FICD_24_BPP = 24, + /// + /// 32-bit. + /// + FICD_32_BPP = 32, + /// + /// Reorder palette (make it linear). Only affects 1-, 4- and 8-bit images. + /// The palette is only reordered in case the image is greyscale + /// (all palette entries have the same red, green and blue value). + /// + FICD_REORDER_PALETTE = 1024, + /// + /// Converts the image to greyscale. + /// + FICD_FORCE_GREYSCALE = 2048, + /// + /// Flag to mask out all non color depth flags. + /// + FICD_COLOR_MASK = FICD_01_BPP | FICD_04_BPP | FICD_08_BPP | FICD_16_BPP | FICD_24_BPP | FICD_32_BPP + } +} + +namespace FreeImageAPI +{ + /// + /// List of combinable compare modes. + /// + [System.Flags] + public enum FREE_IMAGE_COMPARE_FLAGS + { + /// + /// Compare headers. + /// + HEADER = 0x1, + /// + /// Compare palettes. + /// + PALETTE = 0x2, + /// + /// Compare pixel data. + /// + DATA = 0x4, + /// + /// Compare meta data. + /// + METADATA = 0x8, + /// + /// Compare everything. + /// + COMPLETE = (HEADER | PALETTE | DATA | METADATA) + } +} + +namespace FreeImageAPI +{ + /// + /// Flags for copying data from a bitmap to another. + /// + public enum FREE_IMAGE_METADATA_COPY + { + /// + /// Exisiting metadata will remain unchanged. + /// + KEEP_EXISITNG = 0x0, + /// + /// Existing metadata will be cleared. + /// + CLEAR_EXISTING = 0x1, + /// + /// Existing metadata will be overwritten. + /// + REPLACE_EXISTING = 0x2 + } +} + +namespace FreeImageAPI +{ + /// + /// List different search modes. + /// + [System.Flags] + public enum MD_SEARCH_FLAGS + { + /// + /// The key of the metadata. + /// + KEY = 0x1, + /// + /// The description of the metadata + /// + DESCRIPTION = 0x2, + /// + /// The ToString value of the metadata + /// + TOSTRING = 0x4, + } +} + + #endregion + +namespace FreeImageAPI +{ + /// + /// Static class importing functions from the FreeImage library + /// and providing additional functions. + /// + public static partial class FreeImage + { + #region Constants + + /// + /// Array containing all 'FREE_IMAGE_MDMODEL's. + /// + public static readonly FREE_IMAGE_MDMODEL[] FREE_IMAGE_MDMODELS = + (FREE_IMAGE_MDMODEL[])Enum.GetValues(typeof(FREE_IMAGE_MDMODEL)); + + /// + /// Stores handles used to read from streams. + /// + private static Dictionary streamHandles = + new Dictionary(); + + /// + /// Version of the wrapper library. + /// + private static Version WrapperVersion; + + private const int DIB_RGB_COLORS = 0; + private const int DIB_PAL_COLORS = 1; + private const int CBM_INIT = 0x4; + + /// + /// An uncompressed format. + /// + public const int BI_RGB = 0; + + /// + /// A run-length encoded (RLE) format for bitmaps with 8 bpp. The compression format is a 2-byte + /// format consisting of a count byte followed by a byte containing a color index. + /// + public const int BI_RLE8 = 1; + + /// + /// An RLE format for bitmaps with 4 bpp. The compression format is a 2-byte format consisting + /// of a count byte followed by two word-length color indexes. + /// + public const int BI_RLE4 = 2; + + /// + /// Specifies that the bitmap is not compressed and that the color table consists of three + /// DWORD color masks that specify the red, green, and blue components, respectively, + /// of each pixel. This is valid when used with 16- and 32-bpp bitmaps. + /// + public const int BI_BITFIELDS = 3; + + /// + /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a JPEG image. + /// + public const int BI_JPEG = 4; + + /// + /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a PNG image. + /// + public const int BI_PNG = 5; + + #endregion + + #region General functions + + /// + /// Returns the internal version of this FreeImage .NET wrapper. + /// + /// The internal version of this FreeImage .NET wrapper. + public static Version GetWrapperVersion() + { + if (WrapperVersion == null) + { + try + { + object[] attributes = Assembly.GetAssembly(typeof(FreeImage)) + .GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false); + if ((attributes != null) && (attributes.Length != 0)) + { + AssemblyFileVersionAttribute attribute = + attributes[0] as AssemblyFileVersionAttribute; + if ((attribute != null) && (attribute.Version != null)) + { + return (WrapperVersion = new Version(attribute.Version)); + } + } + } + catch + { + + } + + WrapperVersion = new Version(); + } + + return WrapperVersion; + } + + /// + /// Returns the version of the native FreeImage library. + /// + /// The version of the native FreeImage library. + public static Version GetNativeVersion() + { + return new Version(GetVersion()); + } + + /// + /// Returns a value indicating if the FreeImage library is available or not. + /// See remarks for further details. + /// + /// false if the file is not available or out of date; + /// true, otherwise. + /// + /// The FreeImage.NET library is a wrapper for the native C++ library + /// (FreeImage.dll ... dont mix ist up with this library FreeImageNet.dll). + /// The native library must be either in the same folder as the program's + /// executable or in a folder contained in the envirent variable PATH + /// (for example %WINDIR%\System32). + /// Further more must both libraries, including the program itself, + /// be the same architecture (x86 or x64). + /// + public static bool IsAvailable() + { + try + { + // Call a static fast executing function + Version nativeVersion = new Version(GetVersion()); + Version wrapperVersion = GetWrapperVersion(); + // No exception thrown, the library seems to be present + return + (nativeVersion.Major >= wrapperVersion.Major) && + (nativeVersion.Minor >= wrapperVersion.Minor) && + (nativeVersion.Build >= wrapperVersion.Build); + } + catch (DllNotFoundException) + { + return false; + } + catch (EntryPointNotFoundException) + { + return false; + } + catch (BadImageFormatException) + { + return false; + } + } + + #endregion + + #region Bitmap management functions + + /// + /// Creates a new bitmap in memory. + /// + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new Bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap + /// Handle to a FreeImage bitmap. + public static FIBITMAP Allocate(int width, int height, int bpp) + { + return Allocate(width, height, bpp, 0, 0, 0); + } + + /// + /// Creates a new bitmap in memory. + /// + /// Type of the image. + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new Bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap + /// Handle to a FreeImage bitmap. + public static FIBITMAP AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp) + { + return AllocateT(type, width, height, bpp, 0, 0, 0); + } + + /// + /// Allocates a new image of the specified width, height and bit depth and optionally + /// fills it with the specified color. See remarks for further details. + /// + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmaps. + /// The color to fill the bitmap with or null. + /// Options to enable or disable function-features. + /// The palette of the bitmap or null. + /// Handle to a FreeImage bitmap. + /// + /// This function is an extension to , which additionally supports + /// specifying a palette to be set for the newly create image, as well as specifying a + /// background color, the newly created image should initially be filled with. + /// + /// Basically, this function internally relies on function , followed by a + /// call to . This is why both parameters + /// and behave the same as it is + /// documented for function . + /// So, please refer to the documentation of to + /// learn more about parameters and . + /// + /// The palette specified through parameter is only copied to the + /// newly created image, if the desired bit depth is smaller than or equal to 8 bits per pixel. + /// In other words, the parameter is only taken into account for + /// palletized images. So, for an 8-bit image, the length is 256, for an 4-bit image it is 16 + /// and it is 2 for a 1-bit image. In other words, this function does not support partial palettes. + /// + /// However, specifying a palette is not necesarily needed, even for palletized images. This + /// function is capable of implicitly creating a palette, if is null. + /// If the specified background color is a greyscale value (red = green = blue) or if option + /// is specified, a greyscale palette + /// is created. For a 1-bit image, only if the specified background color is either black or white, + /// a monochrome palette, consisting of black and white only is created. In any case, the darker + /// colors are stored at the smaller palette indices. + /// + /// If the specified background color is not a greyscale value, or is neither black nor white + /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized + /// palette. For this operation, option + /// is implicit, so the specified is applied to the palette entry, + /// specified by the background color's field. + /// The image is then filled with this palette index. + /// + /// This function returns a newly created image as function does, if both + /// parameters and are null. + /// If only is null, the palette pointed to by + /// parameter is initially set for the new image, if a palletized + /// image of type is created. + /// However, in the latter case, this function returns an image, whose + /// pixels are all initialized with zeros so, the image will be filled with the color of the + /// first palette entry. + /// + public static FIBITMAP AllocateEx(int width, int height, int bpp, + RGBQUAD? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette) + { + return AllocateEx(width, height, bpp, color, options, palette, 0, 0, 0); + } + + /// + /// Allocates a new image of the specified width, height and bit depth and optionally + /// fills it with the specified color. See remarks for further details. + /// + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmaps. + /// The color to fill the bitmap with or null. + /// Options to enable or disable function-features. + /// The palette of the bitmap or null. + /// Red part of the color layout. + /// eg: 0xFF0000 + /// Green part of the color layout. + /// eg: 0x00FF00 + /// Blue part of the color layout. + /// eg: 0x0000FF + /// Handle to a FreeImage bitmap. + /// + /// This function is an extension to , which additionally supports + /// specifying a palette to be set for the newly create image, as well as specifying a + /// background color, the newly created image should initially be filled with. + /// + /// Basically, this function internally relies on function , followed by a + /// call to . This is why both parameters + /// and behave the same as it is + /// documented for function . + /// So, please refer to the documentation of to + /// learn more about parameters and . + /// + /// The palette specified through parameter is only copied to the + /// newly created image, if the desired bit depth is smaller than or equal to 8 bits per pixel. + /// In other words, the parameter is only taken into account for + /// palletized images. So, for an 8-bit image, the length is 256, for an 4-bit image it is 16 + /// and it is 2 for a 1-bit image. In other words, this function does not support partial palettes. + /// + /// However, specifying a palette is not necesarily needed, even for palletized images. This + /// function is capable of implicitly creating a palette, if is null. + /// If the specified background color is a greyscale value (red = green = blue) or if option + /// is specified, a greyscale palette + /// is created. For a 1-bit image, only if the specified background color is either black or white, + /// a monochrome palette, consisting of black and white only is created. In any case, the darker + /// colors are stored at the smaller palette indices. + /// + /// If the specified background color is not a greyscale value, or is neither black nor white + /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized + /// palette. For this operation, option + /// is implicit, so the specified is applied to the palette entry, + /// specified by the background color's field. + /// The image is then filled with this palette index. + /// + /// This function returns a newly created image as function does, if both + /// parameters and are null. + /// If only is null, the palette pointed to by + /// parameter is initially set for the new image, if a palletized + /// image of type is created. + /// However, in the latter case, this function returns an image, whose + /// pixels are all initialized with zeros so, the image will be filled with the color of the + /// first palette entry. + /// + public static FIBITMAP AllocateEx(int width, int height, int bpp, + RGBQUAD? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, + uint red_mask, uint green_mask, uint blue_mask) + { + if ((palette != null) && (bpp <= 8) && (palette.Length < (1 << bpp))) + return FIBITMAP.Zero; + + if (color.HasValue) + { + GCHandle handle = new GCHandle(); + try + { + RGBQUAD[] buffer = new RGBQUAD[] { color.Value }; + handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + return AllocateEx(width, height, bpp, handle.AddrOfPinnedObject(), + options, palette, red_mask, green_mask, blue_mask); + } + finally + { + if (handle.IsAllocated) + handle.Free(); + } + } + else + { + return AllocateEx(width, height, bpp, IntPtr.Zero, + options, palette, red_mask, green_mask, blue_mask); + } + } + + /// + /// Allocates a new image of the specified type, width, height and bit depth and optionally + /// fills it with the specified color. See remarks for further details. + /// + /// The type of the specified color. + /// Type of the image. + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap + /// The color to fill the bitmap with or null. + /// Options to enable or disable function-features. + /// The palette of the bitmap or null. + /// Handle to a FreeImage bitmap. + /// + /// This function is an extension to , which additionally supports + /// specifying a palette to be set for the newly create image, as well as specifying a + /// background color, the newly created image should initially be filled with. + /// + /// Basically, this function internally relies on function , followed by a + /// call to . This is why both parameters + /// and behave the same as it is + /// documented for function . So, please refer to the + /// documentation of to learn more about parameters color and options. + /// + /// The palette specified through parameter palette is only copied to the newly created + /// image, if its image type is and the desired bit + /// depth is smaller than or equal to 8 bits per pixel. In other words, the + /// palette is only taken into account for palletized images. However, if the preceding conditions + /// match and if is not null, the palette is assumed to be at + /// least as large as the size of a fully populated palette for the desired bit depth. + /// So, for an 8-bit image, this length is 256, for an 4-bit image it is 16 and it is + /// 2 for a 1-bit image. In other words, this function does not support partial palettes. + /// + /// However, specifying a palette is not necesarily needed, even for palletized images. This + /// function is capable of implicitly creating a palette, if is null. + /// If the specified background color is a greyscale value (red = green = blue) or if option + /// is specified, a greyscale palette + /// is created. For a 1-bit image, only if the specified background color is either black or white, + /// a monochrome palette, consisting of black and white only is created. In any case, the darker + /// colors are stored at the smaller palette indices. + /// + /// If the specified background color is not a greyscale value, or is neither black nor white + /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized + /// palette. For this operation, option + /// is implicit, so the specified color is applied to the palette entry, specified by the + /// background color's field. The image is then filled with + /// this palette index. + /// + /// This function returns a newly created image as function does, if both + /// parameters and are null. + /// If only is null, the palette pointed to by + /// parameter is initially set for the new image, if a palletized + /// image of type is created. + /// However, in the latter case, this function returns an image, whose + /// pixels are all initialized with zeros so, the image will be filled with the color of the + /// first palette entry. + /// + public static FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp, + T? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette) where T : struct + { + return AllocateExT(type, width, height, bpp, color, options, palette, 0, 0, 0); + } + + /// + /// Allocates a new image of the specified type, width, height and bit depth and optionally + /// fills it with the specified color. See remarks for further details. + /// + /// The type of the specified color. + /// Type of the image. + /// Width of the new bitmap. + /// Height of the new bitmap. + /// Bit depth of the new bitmap. + /// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap + /// The color to fill the bitmap with or null. + /// Options to enable or disable function-features. + /// The palette of the bitmap or null. + /// Red part of the color layout. + /// eg: 0xFF0000 + /// Green part of the color layout. + /// eg: 0x00FF00 + /// Blue part of the color layout. + /// eg: 0x0000FF + /// Handle to a FreeImage bitmap. + /// + /// This function is an extension to , which additionally supports + /// specifying a palette to be set for the newly create image, as well as specifying a + /// background color, the newly created image should initially be filled with. + /// + /// Basically, this function internally relies on function , followed by a + /// call to . This is why both parameters + /// and behave the same as it is + /// documented for function . So, please refer to the + /// documentation of to learn more about parameters color and options. + /// + /// The palette specified through parameter palette is only copied to the newly created + /// image, if its image type is and the desired bit + /// depth is smaller than or equal to 8 bits per pixel. In other words, the + /// palette is only taken into account for palletized images. However, if the preceding conditions + /// match and if is not null, the palette is assumed to be at + /// least as large as the size of a fully populated palette for the desired bit depth. + /// So, for an 8-bit image, this length is 256, for an 4-bit image it is 16 and it is + /// 2 for a 1-bit image. In other words, this function does not support partial palettes. + /// + /// However, specifying a palette is not necesarily needed, even for palletized images. This + /// function is capable of implicitly creating a palette, if is null. + /// If the specified background color is a greyscale value (red = green = blue) or if option + /// is specified, a greyscale palette + /// is created. For a 1-bit image, only if the specified background color is either black or white, + /// a monochrome palette, consisting of black and white only is created. In any case, the darker + /// colors are stored at the smaller palette indices. + /// + /// If the specified background color is not a greyscale value, or is neither black nor white + /// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized + /// palette. For this operation, option + /// is implicit, so the specified color is applied to the palette entry, specified by the + /// background color's field. The image is then filled with + /// this palette index. + /// + /// This function returns a newly created image as function does, if both + /// parameters and are null. + /// If only is null, the palette pointed to by + /// parameter is initially set for the new image, if a palletized + /// image of type is created. + /// However, in the latter case, this function returns an image, whose + /// pixels are all initialized with zeros so, the image will be filled with the color of the + /// first palette entry. + /// + public static FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp, + T? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette, + uint red_mask, uint green_mask, uint blue_mask) where T : struct + { + if ((palette != null) && (bpp <= 8) && (palette.Length < (1 << bpp))) + return FIBITMAP.Zero; + + if (!CheckColorType(type, color)) + return FIBITMAP.Zero; + + if (color.HasValue) + { + GCHandle handle = new GCHandle(); + try + { + T[] buffer = new T[] { color.Value }; + handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + return AllocateExT(type, width, height, bpp, handle.AddrOfPinnedObject(), + options, palette, red_mask, green_mask, blue_mask); + } + finally + { + if (handle.IsAllocated) + handle.Free(); + } + } + else + { + return AllocateExT(type, width, height, bpp, IntPtr.Zero, + options, palette, red_mask, green_mask, blue_mask); + } + } + + /// + /// Converts a FreeImage bitmap to a .NET . + /// + /// Handle to a FreeImage bitmap. + /// The converted .NET . + /// Copying metadata has been disabled until a proper way + /// of reading and storing metadata in a .NET bitmap is found. + /// + /// is null. + /// + /// The image type of is not FIT_BITMAP. + public static Bitmap GetBitmap(FIBITMAP dib) + { + return GetBitmap(dib, true); + } + + /// + /// Converts a FreeImage bitmap to a .NET . + /// + /// Handle to a FreeImage bitmap. + /// When true existing metadata will be copied. + /// The converted .NET . + /// Copying metadata has been disabled until a proper way + /// of reading and storing metadata in a .NET bitmap is found. + /// + /// is null. + /// + /// The image type of is not FIT_BITMAP. + internal static Bitmap GetBitmap(FIBITMAP dib, bool copyMetadata) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + if (GetImageType(dib) != FREE_IMAGE_TYPE.FIT_BITMAP) + { + throw new ArgumentException("Only bitmaps with type of FIT_BITMAP can be converted."); + } + + PixelFormat format = GetPixelFormat(dib); + + if ((format == PixelFormat.Undefined) && (GetBPP(dib) == 16u)) + { + throw new ArgumentException("Only 16bit 555 and 565 are supported."); + } + + int height = (int)GetHeight(dib); + int width = (int)GetWidth(dib); + int pitch = (int)GetPitch(dib); + + Bitmap result = new Bitmap(width, height, format); + BitmapData data; + // Locking the complete bitmap in writeonly mode + data = result.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, format); + // Writing the bitmap data directly into the new created .NET bitmap. + ConvertToRawBits(data.Scan0, dib, pitch, GetBPP(dib), + GetRedMask(dib), GetGreenMask(dib), GetBlueMask(dib), true); + // Unlock the bitmap + result.UnlockBits(data); + // Apply the bitmaps resolution + result.SetResolution(GetResolutionX(dib), GetResolutionY(dib)); + // Check whether the bitmap has a palette + if (GetPalette(dib) != IntPtr.Zero) + { + // Get the bitmaps palette to apply changes + ColorPalette palette = result.Palette; + // Get the orgininal palette + Color[] colorPalette = new Palette(dib).ColorData; + // Get the maximum number of palette entries to copy + int entriesToCopy = Math.Min(colorPalette.Length, palette.Entries.Length); + + // Check whether the bitmap is transparent + if (IsTransparent(dib)) + { + byte[] transTable = GetTransparencyTableEx(dib); + int i = 0; + int maxEntriesWithTrans = Math.Min(entriesToCopy, transTable.Length); + // Copy palette entries and include transparency + for (; i < maxEntriesWithTrans; i++) + { + palette.Entries[i] = Color.FromArgb(transTable[i], colorPalette[i]); + } + // Copy palette entries and that have no transparancy + for (; i < entriesToCopy; i++) + { + palette.Entries[i] = Color.FromArgb(0xFF, colorPalette[i]); + } + } + else + { + for (int i = 0; i < entriesToCopy; i++) + { + palette.Entries[i] = colorPalette[i]; + } + } + + // Set the bitmaps palette + result.Palette = palette; + } + // Copy metadata + if (copyMetadata) + { + try + { + List list = new List(); + // Get a list of all types + FITAG tag; + FIMETADATA mData; + foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS) + { + // Get a unique search handle + mData = FindFirstMetadata(model, dib, out tag); + // Check if metadata exists for this type + if (mData.IsNull) continue; + do + { + PropertyItem propItem = CreatePropertyItem(); + propItem.Len = (int)GetTagLength(tag); + propItem.Id = (int)GetTagID(tag); + propItem.Type = (short)GetTagType(tag); + byte[] buffer = new byte[propItem.Len]; + + unsafe + { + byte* src = (byte*)GetTagValue(tag); + fixed (byte* dst = buffer) + { + CopyMemory(dst, src, (uint)propItem.Len); + } + } + + propItem.Value = buffer; + list.Add(propItem); + } + while (FindNextMetadata(mData, out tag)); + FindCloseMetadata(mData); + } + foreach (PropertyItem propItem in list) + { + result.SetPropertyItem(propItem); + } + } + catch + { + } + } + return result; + } + + /// + /// Converts an .NET into a FreeImage bitmap. + /// + /// The to convert. + /// Handle to a FreeImage bitmap. + /// Copying metadata has been disabled until a proper way + /// of reading and storing metadata in a .NET bitmap is found. + /// + /// is null. + /// + /// The bitmaps pixelformat is invalid. + public static FIBITMAP CreateFromBitmap(Bitmap bitmap) + { + return CreateFromBitmap(bitmap, false); + } + + /// + /// Converts an .NET into a FreeImage bitmap. + /// + /// The to convert. + /// When true existing metadata will be copied. + /// Handle to a FreeImage bitmap. + /// Copying metadata has been disabled until a proper way + /// of reading and storing metadata in a .NET bitmap is found. + /// + /// is null. + /// + /// The bitmaps pixelformat is invalid. + internal static FIBITMAP CreateFromBitmap(Bitmap bitmap, bool copyMetadata) + { + if (bitmap == null) + { + throw new ArgumentNullException("bitmap"); + } + uint bpp, red_mask, green_mask, blue_mask; + FREE_IMAGE_TYPE type; + if (!GetFormatParameters(bitmap.PixelFormat, out type, out bpp, out red_mask, out green_mask, out blue_mask)) + { + throw new ArgumentException("The bitmaps pixelformat is invalid."); + } + + // Locking the complete bitmap in readonly mode + BitmapData data = bitmap.LockBits( + new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat); + // Copying the bitmap data directly from the .NET bitmap + FIBITMAP result = ConvertFromRawBits( + data.Scan0, + type, + data.Width, + data.Height, + data.Stride, + bpp, + red_mask, + green_mask, + blue_mask, + true); + bitmap.UnlockBits(data); + // Handle palette + if (GetPalette(result) != IntPtr.Zero) + { + Palette palette = new Palette(result); + Color[] colors = bitmap.Palette.Entries; + // Only copy available palette entries + int entriesToCopy = Math.Min(palette.Length, colors.Length); + byte[] transTable = new byte[entriesToCopy]; + for (int i = 0; i < entriesToCopy; i++) + { + RGBQUAD color = (RGBQUAD)colors[i]; + color.rgbReserved = 0x00; + palette[i] = color; + transTable[i] = colors[i].A; + } + if ((bitmap.Flags & (int)ImageFlags.HasAlpha) != 0) + { + FreeImage.SetTransparencyTable(result, transTable); + } + } + // Handle meta data + // Disabled + //if (copyMetadata) + //{ + // foreach (PropertyItem propItem in bitmap.PropertyItems) + // { + // FITAG tag = CreateTag(); + // SetTagLength(tag, (uint)propItem.Len); + // SetTagID(tag, (ushort)propItem.Id); + // SetTagType(tag, (FREE_IMAGE_MDTYPE)propItem.Type); + // SetTagValue(tag, propItem.Value); + // SetMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, result, "", tag); + // } + //} + return result; + } + + /// + /// Converts a raw bitmap to a FreeImage bitmap. + /// + /// Array of bytes containing the raw bitmap. + /// The type of the raw bitmap. + /// The width in pixels of the raw bitmap. + /// The height in pixels of the raw bitmap. + /// Defines the total width of a scanline in the raw bitmap, + /// including padding bytes. + /// The bit depth (bits per pixel) of the raw bitmap. + /// The bit mask describing the bits used to store a single + /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// If true, the raw bitmap is stored in top-down order (top-left pixel first) + /// and in bottom-up order (bottom-left pixel first) otherwise. + /// Handle to a FreeImage bitmap. + public static unsafe FIBITMAP ConvertFromRawBits( + byte[] bits, + FREE_IMAGE_TYPE type, + int width, + int height, + int pitch, + uint bpp, + uint red_mask, + uint green_mask, + uint blue_mask, + bool topdown) + { + fixed (byte* ptr = bits) + { + return ConvertFromRawBits( + (IntPtr)ptr, + type, + width, + height, + pitch, + bpp, + red_mask, + green_mask, + blue_mask, + topdown); + } + } + + /// + /// Converts a raw bitmap to a FreeImage bitmap. + /// + /// Pointer to the memory block containing the raw bitmap. + /// The type of the raw bitmap. + /// The width in pixels of the raw bitmap. + /// The height in pixels of the raw bitmap. + /// Defines the total width of a scanline in the raw bitmap, + /// including padding bytes. + /// The bit depth (bits per pixel) of the raw bitmap. + /// The bit mask describing the bits used to store a single + /// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// The bit mask describing the bits used to store a single + /// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps. + /// If true, the raw bitmap is stored in top-down order (top-left pixel first) + /// and in bottom-up order (bottom-left pixel first) otherwise. + /// Handle to a FreeImage bitmap. + public static unsafe FIBITMAP ConvertFromRawBits( + IntPtr bits, + FREE_IMAGE_TYPE type, + int width, + int height, + int pitch, + uint bpp, + uint red_mask, + uint green_mask, + uint blue_mask, + bool topdown) + { + byte* addr = (byte*)bits; + if ((addr == null) || (width <= 0) || (height <= 0)) + { + return FIBITMAP.Zero; + } + + FIBITMAP dib = AllocateT(type, width, height, (int)bpp, red_mask, green_mask, blue_mask); + if (dib != FIBITMAP.Zero) + { + if (topdown) + { + for (int i = height - 1; i >= 0; --i) + { + CopyMemory((byte*)GetScanLine(dib, i), addr, (int)GetLine(dib)); + addr += pitch; + } + } + else + { + for (int i = 0; i < height; ++i) + { + CopyMemory((byte*)GetScanLine(dib, i), addr, (int)GetLine(dib)); + addr += pitch; + } + } + } + return dib; + } + + /// + /// Saves a .NET to a file. + /// + /// The .NET to save. + /// Name of the file to save to. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// The bitmaps pixelformat is invalid. + public static bool SaveBitmap(Bitmap bitmap, string filename) + { + return SaveBitmap( + bitmap, + filename, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + /// + /// Saves a .NET to a file. + /// + /// The .NET to save. + /// Name of the file to save to. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// The bitmaps pixelformat is invalid. + public static bool SaveBitmap(Bitmap bitmap, string filename, FREE_IMAGE_SAVE_FLAGS flags) + { + return SaveBitmap( + bitmap, + filename, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + flags); + } + + /// + /// Saves a .NET to a file. + /// + /// The .NET to save. + /// Name of the file to save to. + /// Format of the bitmap. If the format should be taken from the + /// filename use . + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// The bitmaps pixelformat is invalid. + public static bool SaveBitmap( + Bitmap bitmap, + string filename, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_SAVE_FLAGS flags) + { + FIBITMAP dib = CreateFromBitmap(bitmap); + bool result = SaveEx(dib, filename, format, flags); + Unload(dib); + return result; + } + + /// + /// Loads a FreeImage bitmap. + /// The file will be loaded with default loading flags. + /// + /// The complete name of the file to load. + /// Handle to a FreeImage bitmap. + /// + /// does not exists. + public static FIBITMAP LoadEx(string filename) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return LoadEx(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); + } + + /// + /// Loads a FreeImage bitmap. + /// Load flags can be provided by the flags parameter. + /// + /// The complete name of the file to load. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage bitmap. + /// + /// does not exists. + public static FIBITMAP LoadEx(string filename, FREE_IMAGE_LOAD_FLAGS flags) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return LoadEx(filename, flags, ref format); + } + + /// + /// Loads a FreeImage bitmap. + /// In case the loading format is the files + /// real format is being analysed. If no plugin can read the file, format remains + /// and 0 is returned. + /// The file will be loaded with default loading flags. + /// + /// The complete name of the file to load. + /// Format of the image. If the format is unknown use + /// . + /// In case a suitable format was found by LoadEx it will be returned in format. + /// Handle to a FreeImage bitmap. + /// + /// does not exists. + public static FIBITMAP LoadEx(string filename, ref FREE_IMAGE_FORMAT format) + { + return LoadEx(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); + } + + /// + /// Loads a FreeImage bitmap. + /// In case the loading format is the files + /// real format is being analysed. If no plugin can read the file, format remains + /// and 0 is returned. + /// Load flags can be provided by the flags parameter. + /// + /// The complete name of the file to load. + /// Flags to enable or disable plugin-features. + /// Format of the image. If the format is unknown use + /// . + /// In case a suitable format was found by LoadEx it will be returned in format. + /// + /// Handle to a FreeImage bitmap. + /// + /// does not exists. + public static FIBITMAP LoadEx(string filename, FREE_IMAGE_LOAD_FLAGS flags, ref FREE_IMAGE_FORMAT format) + { + // check if file exists + if (!File.Exists(filename)) + { + throw new FileNotFoundException(filename + " could not be found."); + } + FIBITMAP dib = new FIBITMAP(); + if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) + { + // query all plugins to see if one can read the file + format = GetFileType(filename, 0); + } + // check if the plugin is capable of loading files + if (FIFSupportsReading(format)) + { + dib = Load(format, filename, flags); + } + return dib; + } + + /// + /// Loads a .NET from a file. + /// + /// Name of the file to be loaded. + /// Format of the image. If the format should be taken from the + /// filename use . + /// Flags to enable or disable plugin-features. + /// The loaded .NET . + /// + /// does not exists. + /// + /// The image type of the image is not . + public static Bitmap LoadBitmap(string filename, FREE_IMAGE_LOAD_FLAGS flags, ref FREE_IMAGE_FORMAT format) + { + FIBITMAP dib = LoadEx(filename, flags, ref format); + Bitmap result = GetBitmap(dib, true); + Unload(dib); + return result; + } + + /// + /// Deletes a previously loaded FreeImage bitmap from memory and resets the handle to 0. + /// + /// Handle to a FreeImage bitmap. + public static void UnloadEx(ref FIBITMAP dib) + { + if (!dib.IsNull) + { + Unload(dib); + dib.SetNull(); + } + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// The format is taken off the filename. + /// If no suitable format was found false will be returned. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified. + /// Returns true on success, false on failure. + /// + /// or is null. + public static bool SaveEx(FIBITMAP dib, string filename) + { + return SaveEx( + ref dib, + filename, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + FREE_IMAGE_SAVE_FLAGS.DEFAULT, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + false); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// In case the loading format is + /// the format is taken off the filename. + /// If no suitable format was found false will be returned. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified. + /// Format of the image. If the format should be taken from the + /// filename use . + /// Returns true on success, false on failure. + /// + /// or is null. + public static bool SaveEx( + FIBITMAP dib, + string filename, + FREE_IMAGE_FORMAT format) + { + return SaveEx( + ref dib, + filename, + format, + FREE_IMAGE_SAVE_FLAGS.DEFAULT, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + false); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// The format is taken off the filename. + /// If no suitable format was found false will be returned. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified. + /// When true the structure will be unloaded on success. + /// If the function failed and returned false, the bitmap was not unloaded. + /// Returns true on success, false on failure. + /// + /// or is null. + public static bool SaveEx( + ref FIBITMAP dib, + string filename, + bool unloadSource) + { + return SaveEx( + ref dib, + filename, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + FREE_IMAGE_SAVE_FLAGS.DEFAULT, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + unloadSource); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// The format is taken off the filename. + /// If no suitable format was found false will be returned. + /// Save flags can be provided by the flags parameter. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + /// + /// or is null. + public static bool SaveEx( + FIBITMAP dib, + string filename, + FREE_IMAGE_SAVE_FLAGS flags) + { + return SaveEx( + ref dib, + filename, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + flags, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + false); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// The format is taken off the filename. + /// If no suitable format was found false will be returned. + /// Save flags can be provided by the flags parameter. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified. + /// Flags to enable or disable plugin-features. + /// When true the structure will be unloaded on success. + /// If the function failed and returned false, the bitmap was not unloaded. + /// Returns true on success, false on failure. + /// + /// or is null. + public static bool SaveEx( + ref FIBITMAP dib, + string filename, + FREE_IMAGE_SAVE_FLAGS flags, + bool unloadSource) + { + return SaveEx( + ref dib, + filename, + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + flags, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + unloadSource); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// In case the loading format is + /// the format is taken off the filename. + /// If no suitable format was found false will be returned. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified. + /// Format of the image. If the format should be taken from the + /// filename use . + /// When true the structure will be unloaded on success. + /// If the function failed and returned false, the bitmap was not unloaded. + /// Returns true on success, false on failure. + /// + /// or is null. + public static bool SaveEx( + ref FIBITMAP dib, + string filename, + FREE_IMAGE_FORMAT format, + bool unloadSource) + { + return SaveEx( + ref dib, + filename, + format, + FREE_IMAGE_SAVE_FLAGS.DEFAULT, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + unloadSource); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// In case the loading format is + /// the format is taken off the filename. + /// If no suitable format was found false will be returned. + /// Save flags can be provided by the flags parameter. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified. + /// Format of the image. If the format should be taken from the + /// filename use . + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + /// + /// or is null. + public static bool SaveEx( + FIBITMAP dib, + string filename, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_SAVE_FLAGS flags) + { + return SaveEx( + ref dib, + filename, + format, + flags, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + false); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a file. + /// In case the loading format is + /// the format is taken off the filename. + /// If no suitable format was found false will be returned. + /// Save flags can be provided by the flags parameter. + /// The bitmaps color depth can be set by 'colorDepth'. + /// If set to a suitable color depth + /// will be taken if available. + /// + /// Handle to a FreeImage bitmap. + /// The complete name of the file to save to. + /// The extension will be corrected if it is no valid extension for the + /// selected format or if no extension was specified. + /// Format of the image. If the format should be taken from the + /// filename use . + /// Flags to enable or disable plugin-features. + /// The new color depth of the bitmap. + /// Set to if Save should take the + /// best suitable color depth. + /// If a color depth is selected that the provided format cannot write an + /// error-message will be thrown. + /// When true the structure will be unloaded on success. + /// If the function failed and returned false, the bitmap was not unloaded. + /// Returns true on success, false on failure. + /// + /// A direct color conversion failed. + /// + /// or is null. + public static bool SaveEx( + ref FIBITMAP dib, + string filename, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_SAVE_FLAGS flags, + FREE_IMAGE_COLOR_DEPTH colorDepth, + bool unloadSource) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + if (filename == null) + { + throw new ArgumentNullException("filename"); + } + bool result = false; + // Gets format from filename if the format is unknown + if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) + { + format = GetFIFFromFilename(filename); + } + if (format != FREE_IMAGE_FORMAT.FIF_UNKNOWN) + { + // Checks writing support + if (FIFSupportsWriting(format) && FIFSupportsExportType(format, GetImageType(dib))) + { + // Check valid filename and correct it if needed + if (!IsFilenameValidForFIF(format, filename)) + { + string extension = GetPrimaryExtensionFromFIF(format); + filename = Path.ChangeExtension(filename, extension); + } + + FIBITMAP dibToSave = PrepareBitmapColorDepth(dib, format, colorDepth); + try + { + result = Save(format, dibToSave, filename, flags); + } + finally + { + // Always unload a temporary created bitmap. + if (dibToSave != dib) + { + UnloadEx(ref dibToSave); + } + // On success unload the bitmap + if (result && unloadSource) + { + UnloadEx(ref dib); + } + } + } + } + return result; + } + + /// + /// Loads a FreeImage bitmap. + /// The stream must be set to the correct position before calling LoadFromStream. + /// + /// The stream to read from. + /// Handle to a FreeImage bitmap. + /// + /// is null. + /// + /// is not capable of reading. + public static FIBITMAP LoadFromStream(Stream stream) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return LoadFromStream(stream, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); + } + + /// + /// Loads a FreeImage bitmap. + /// The stream must be set to the correct position before calling LoadFromStream. + /// + /// The stream to read from. + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage bitmap. + /// + /// is null. + /// + /// is not capable of reading. + public static FIBITMAP LoadFromStream(Stream stream, FREE_IMAGE_LOAD_FLAGS flags) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return LoadFromStream(stream, flags, ref format); + } + + /// + /// Loads a FreeImage bitmap. + /// In case the loading format is the + /// bitmaps real format is being analysed. + /// The stream must be set to the correct position before calling LoadFromStream. + /// + /// The stream to read from. + /// Format of the image. If the format is unknown use + /// . + /// In case a suitable format was found by LoadFromStream it will be returned in format. + /// Handle to a FreeImage bitmap. + /// + /// is null. + /// + /// is not capable of reading. + public static FIBITMAP LoadFromStream(Stream stream, ref FREE_IMAGE_FORMAT format) + { + return LoadFromStream(stream, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); + } + + /// + /// Loads a FreeImage bitmap. + /// In case the loading format is + /// the bitmaps real format is being analysed. + /// The stream must be set to the correct position before calling LoadFromStream. + /// + /// The stream to read from. + /// Flags to enable or disable plugin-features. + /// Format of the image. If the format is unknown use + /// . + /// In case a suitable format was found by LoadFromStream it will be returned in format. + /// Handle to a FreeImage bitmap. + /// + /// is null. + /// + /// is not capable of reading. + public static FIBITMAP LoadFromStream( + Stream stream, + FREE_IMAGE_LOAD_FLAGS flags, + ref FREE_IMAGE_FORMAT format) + { + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + if (!stream.CanRead) + { + throw new ArgumentException("stream is not capable of reading."); + } + // Wrap the source stream if it is unable to seek (which is required by FreeImage) + stream = (stream.CanSeek) ? stream : new StreamWrapper(stream, true); + + stream.Position = 0L; + if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) + { + // Get the format of the bitmap + format = GetFileTypeFromStream(stream); + // Restore the streams position + stream.Position = 0L; + } + if (!FIFSupportsReading(format)) + { + return FIBITMAP.Zero; + } + // Create a 'FreeImageIO' structure for calling 'LoadFromHandle' + // using the internal structure 'FreeImageStreamIO'. + FreeImageIO io = FreeImageStreamIO.io; + using (fi_handle handle = new fi_handle(stream)) + { + return LoadFromHandle(format, ref io, handle, flags); + } + } + + /// + /// Saves a previously loaded FreeImage bitmap to a stream. + /// The stream must be set to the correct position before calling SaveToStream. + /// + /// Handle to a FreeImage bitmap. + /// The stream to write to. + /// Format of the image. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// cannot write. + public static bool SaveToStream( + FIBITMAP dib, + Stream stream, + FREE_IMAGE_FORMAT format) + { + return SaveToStream( + ref dib, + stream, + format, + FREE_IMAGE_SAVE_FLAGS.DEFAULT, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + false); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a stream. + /// The stream must be set to the correct position before calling SaveToStream. + /// + /// Handle to a FreeImage bitmap. + /// The stream to write to. + /// Format of the image. + /// When true the structure will be unloaded on success. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// cannot write. + public static bool SaveToStream( + ref FIBITMAP dib, + Stream stream, + FREE_IMAGE_FORMAT format, + bool unloadSource) + { + return SaveToStream( + ref dib, + stream, + format, + FREE_IMAGE_SAVE_FLAGS.DEFAULT, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + unloadSource); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a stream. + /// The stream must be set to the correct position before calling SaveToStream. + /// + /// Handle to a FreeImage bitmap. + /// The stream to write to. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// cannot write. + public static bool SaveToStream( + FIBITMAP dib, + Stream stream, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_SAVE_FLAGS flags) + { + return SaveToStream( + ref dib, + stream, + format, + flags, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + false); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a stream. + /// The stream must be set to the correct position before calling SaveToStream. + /// + /// Handle to a FreeImage bitmap. + /// The stream to write to. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// When true the structure will be unloaded on success. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// cannot write. + public static bool SaveToStream( + ref FIBITMAP dib, + Stream stream, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_SAVE_FLAGS flags, + bool unloadSource) + { + return SaveToStream( + ref dib, stream, + format, + flags, + FREE_IMAGE_COLOR_DEPTH.FICD_AUTO, + unloadSource); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a stream. + /// The stream must be set to the correct position before calling SaveToStream. + /// + /// Handle to a FreeImage bitmap. + /// The stream to write to. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// The new color depth of the bitmap. + /// Set to if SaveToStream should + /// take the best suitable color depth. + /// If a color depth is selected that the provided format cannot write an + /// error-message will be thrown. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// cannot write. + public static bool SaveToStream( + FIBITMAP dib, + Stream stream, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_SAVE_FLAGS flags, + FREE_IMAGE_COLOR_DEPTH colorDepth) + { + return SaveToStream( + ref dib, + stream, + format, + flags, + colorDepth, + false); + } + + /// + /// Saves a previously loaded FreeImage bitmap to a stream. + /// The stream must be set to the correct position before calling SaveToStream. + /// + /// Handle to a FreeImage bitmap. + /// The stream to write to. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// The new color depth of the bitmap. + /// Set to if SaveToStream should + /// take the best suitable color depth. + /// If a color depth is selected that the provided format cannot write an + /// error-message will be thrown. + /// When true the structure will be unloaded on success. + /// Returns true on success, false on failure. + /// + /// or is null. + /// + /// cannot write. + public static bool SaveToStream( + ref FIBITMAP dib, + Stream stream, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_SAVE_FLAGS flags, + FREE_IMAGE_COLOR_DEPTH colorDepth, + bool unloadSource) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + if (!stream.CanWrite) + { + throw new ArgumentException("stream is not capable of writing."); + } + if ((!FIFSupportsWriting(format)) || (!FIFSupportsExportType(format, GetImageType(dib)))) + { + return false; + } + + FIBITMAP dibToSave = PrepareBitmapColorDepth(dib, format, colorDepth); + bool result = false; + + try + { + // Create a 'FreeImageIO' structure for calling 'SaveToHandle' + FreeImageIO io = FreeImageStreamIO.io; + + using (fi_handle handle = new fi_handle(stream)) + { + result = SaveToHandle(format, dibToSave, ref io, handle, flags); + } + } + finally + { + // Always unload a temporary created bitmap. + if (dibToSave != dib) + { + UnloadEx(ref dibToSave); + } + // On success unload the bitmap + if (result && unloadSource) + { + UnloadEx(ref dib); + } + } + + return result; + } + + #endregion + + #region Plugin functions + + /// + /// Checks if an extension is valid for a certain format. + /// + /// The desired format. + /// The desired extension. + /// True if the extension is valid for the given format, false otherwise. + /// + /// is null. + public static bool IsExtensionValidForFIF(FREE_IMAGE_FORMAT fif, string extension) + { + return IsExtensionValidForFIF(fif, extension, StringComparison.CurrentCultureIgnoreCase); + } + + /// + /// Checks if an extension is valid for a certain format. + /// + /// The desired format. + /// The desired extension. + /// The string comparison type. + /// True if the extension is valid for the given format, false otherwise. + /// + /// is null. + public static bool IsExtensionValidForFIF(FREE_IMAGE_FORMAT fif, string extension, StringComparison comparisonType) + { + if (extension == null) + { + throw new ArgumentNullException("extension"); + } + bool result = false; + // Split up the string and compare each with the given extension + string tempList = GetFIFExtensionList(fif); + if (tempList != null) + { + string[] extensionList = tempList.Split(','); + foreach (string ext in extensionList) + { + if (extension.Equals(ext, comparisonType)) + { + result = true; + break; + } + } + } + return result; + } + + /// + /// Checks if a filename is valid for a certain format. + /// + /// The desired format. + /// The desired filename. + /// True if the filename is valid for the given format, false otherwise. + /// + /// is null. + public static bool IsFilenameValidForFIF(FREE_IMAGE_FORMAT fif, string filename) + { + return IsFilenameValidForFIF(fif, filename, StringComparison.CurrentCultureIgnoreCase); + } + + /// + /// Checks if a filename is valid for a certain format. + /// + /// The desired format. + /// The desired filename. + /// The string comparison type. + /// True if the filename is valid for the given format, false otherwise. + /// + /// is null. + public static bool IsFilenameValidForFIF(FREE_IMAGE_FORMAT fif, string filename, StringComparison comparisonType) + { + if (filename == null) + { + throw new ArgumentNullException("filename"); + } + bool result = false; + // Extract the filenames extension if it exists + string extension = Path.GetExtension(filename); + if (extension.Length != 0) + { + extension = extension.Remove(0, 1); + result = IsExtensionValidForFIF(fif, extension, comparisonType); + } + return result; + } + + /// + /// This function returns the primary (main or most commonly used?) extension of a certain + /// image format (fif). This is done by returning the first of all possible extensions + /// returned by GetFIFExtensionList(). + /// That assumes, that the plugin returns the extensions in ordered form. + /// The image format to obtain the primary extension for. + /// The primary extension of the specified image format. + public static string GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT fif) + { + string result = null; + string extensions = GetFIFExtensionList(fif); + if (extensions != null) + { + int position = extensions.IndexOf(','); + if (position < 0) + { + result = extensions; + } + else + { + result = extensions.Substring(0, position); + } + } + return result; + } + + #endregion + + #region Multipage functions + + /// + /// Loads a FreeImage multi-paged bitmap. + /// + /// The complete name of the file to load. + /// Handle to a FreeImage multi-paged bitmap. + /// + /// does not exists while opening. + public static FIMULTIBITMAP OpenMultiBitmapEx(string filename) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return OpenMultiBitmapEx( + filename, + ref format, + FREE_IMAGE_LOAD_FLAGS.DEFAULT, + false, + false, + false); + } + + /// + /// Loads a FreeImage multi-paged bitmap. + /// + /// The complete name of the file to load. + /// When true performance is increased at the cost of memory. + /// Handle to a FreeImage multi-paged bitmap. + /// + /// does not exists while opening. + public static FIMULTIBITMAP OpenMultiBitmapEx(string filename, bool keep_cache_in_memory) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return OpenMultiBitmapEx( + filename, + ref format, + FREE_IMAGE_LOAD_FLAGS.DEFAULT, + false, + false, + keep_cache_in_memory); + } + + /// + /// Loads a FreeImage multi-paged bitmap. + /// + /// The complete name of the file to load. + /// When true the bitmap will be loaded read only. + /// When true performance is increased at the cost of memory. + /// Handle to a FreeImage multi-paged bitmap. + /// + /// does not exists while opening. + public static FIMULTIBITMAP OpenMultiBitmapEx( + string filename, + bool read_only, + bool keep_cache_in_memory) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return OpenMultiBitmapEx( + filename, + ref format, + FREE_IMAGE_LOAD_FLAGS.DEFAULT, + false, + read_only, + keep_cache_in_memory); + } + + /// + /// Loads a FreeImage multi-paged bitmap. + /// + /// The complete name of the file to load. + /// When true a new bitmap is created. + /// When true the bitmap will be loaded read only. + /// When true performance is increased at the cost of memory. + /// Handle to a FreeImage multi-paged bitmap. + /// + /// does not exists while opening. + public static FIMULTIBITMAP OpenMultiBitmapEx( + string filename, + bool create_new, + bool read_only, + bool keep_cache_in_memory) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return OpenMultiBitmapEx( + filename, + ref format, + FREE_IMAGE_LOAD_FLAGS.DEFAULT, + create_new, + read_only, + keep_cache_in_memory); + } + + /// + /// Loads a FreeImage multi-paged bitmap. + /// In case the loading format is the files real + /// format is being analysed. If no plugin can read the file, format remains + /// and 0 is returned. + /// + /// The complete name of the file to load. + /// Format of the image. If the format is unknown use + /// . + /// In case a suitable format was found by LoadEx it will be returned in format. + /// When true a new bitmap is created. + /// When true the bitmap will be loaded read only. + /// When true performance is increased at the cost of memory. + /// Handle to a FreeImage multi-paged bitmap. + /// + /// does not exists while opening. + public static FIMULTIBITMAP OpenMultiBitmapEx( + string filename, + ref FREE_IMAGE_FORMAT format, + bool create_new, + bool read_only, + bool keep_cache_in_memory) + { + return OpenMultiBitmapEx( + filename, + ref format, + FREE_IMAGE_LOAD_FLAGS.DEFAULT, + create_new, + read_only, + keep_cache_in_memory); + } + + /// + /// Loads a FreeImage multi-paged bitmap. + /// In case the loading format is the files + /// real format is being analysed. If no plugin can read the file, format remains + /// and 0 is returned. + /// Load flags can be provided by the flags parameter. + /// + /// The complete name of the file to load. + /// Format of the image. If the format is unknown use + /// . + /// In case a suitable format was found by LoadEx it will be returned in format. + /// Flags to enable or disable plugin-features. + /// When true a new bitmap is created. + /// When true the bitmap will be loaded read only. + /// When true performance is increased at the cost of memory. + /// Handle to a FreeImage multi-paged bitmap. + /// + /// does not exists while opening. + public static FIMULTIBITMAP OpenMultiBitmapEx( + string filename, + ref FREE_IMAGE_FORMAT format, + FREE_IMAGE_LOAD_FLAGS flags, + bool create_new, + bool read_only, + bool keep_cache_in_memory) + { + if (!File.Exists(filename) && !create_new) + { + throw new FileNotFoundException(filename + " could not be found."); + } + if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) + { + // Check if a plugin can read the data + format = GetFileType(filename, 0); + } + FIMULTIBITMAP dib = new FIMULTIBITMAP(); + if (FIFSupportsReading(format)) + { + dib = OpenMultiBitmap(format, filename, create_new, read_only, keep_cache_in_memory, flags); + } + return dib; + } + + /// + /// Loads a FreeImage multi-paged bitmap. + /// + /// The stream to load the bitmap from. + /// Handle to a FreeImage multi-paged bitmap. + public static FIMULTIBITMAP OpenMultiBitmapFromStream(Stream stream) + { + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + return OpenMultiBitmapFromStream(stream, ref format, FREE_IMAGE_LOAD_FLAGS.DEFAULT); + } + + /// + /// Loads a FreeImage multi-paged bitmap. + /// In case the loading format is the files + /// real format is being analysed. If no plugin can read the file, format remains + /// and 0 is returned. + /// Load flags can be provided by the flags parameter. + /// + /// The stream to load the bitmap from. + /// Format of the image. If the format is unknown use + /// . + /// Flags to enable or disable plugin-features. + /// Handle to a FreeImage multi-paged bitmap. + public static FIMULTIBITMAP OpenMultiBitmapFromStream(Stream stream, ref FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags) + { + if (stream == null) + return FIMULTIBITMAP.Zero; + + if (!stream.CanSeek) + stream = new StreamWrapper(stream, true); + + FIMULTIBITMAP mdib = FIMULTIBITMAP.Zero; + FreeImageIO io = FreeImageStreamIO.io; + fi_handle handle = new fi_handle(stream); + + try + { + if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) + { + format = GetFileTypeFromHandle(ref io, handle, checked((int)stream.Length)); + } + + mdib = OpenMultiBitmapFromHandle(format, ref io, handle, flags); + + if (mdib.IsNull) + { + handle.Dispose(); + } + else + { + lock (streamHandles) + { + streamHandles.Add(mdib, handle); + } + } + + return mdib; + } + catch + { + if (!mdib.IsNull) + CloseMultiBitmap(mdib, FREE_IMAGE_SAVE_FLAGS.DEFAULT); + + if (handle != null) + handle.Dispose(); + + throw; + } + } + + /// + /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, applies any changes made to it. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + public static bool CloseMultiBitmap(FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags) + { + if (CloseMultiBitmap_(bitmap, flags)) + { + fi_handle handle; + lock (streamHandles) + { + if (streamHandles.TryGetValue(bitmap, out handle)) + { + streamHandles.Remove(bitmap); + handle.Dispose(); + } + } + return true; + } + return false; + } + + /// + /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, + /// applies any changes made to it. + /// On success the handle will be reset to null. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Returns true on success, false on failure. + public static bool CloseMultiBitmapEx(ref FIMULTIBITMAP bitmap) + { + return CloseMultiBitmapEx(ref bitmap, FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + /// + /// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, + /// applies any changes made to it. + /// On success the handle will be reset to null. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Flags to enable or disable plugin-features. + /// Returns true on success, false on failure. + public static bool CloseMultiBitmapEx(ref FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags) + { + bool result = false; + if (!bitmap.IsNull) + { + if (CloseMultiBitmap(bitmap, flags)) + { + bitmap.SetNull(); + result = true; + } + } + return result; + } + + /// + /// Retrieves the number of pages that are locked in a multi-paged bitmap. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// Number of locked pages. + /// + /// is null. + public static int GetLockedPageCount(FIMULTIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + int result = 0; + GetLockedPageNumbers(dib, null, ref result); + return result; + } + + /// + /// Retrieves a list locked pages of a multi-paged bitmap. + /// + /// Handle to a FreeImage multi-paged bitmap. + /// List containing the indexes of the locked pages. + /// + /// is null. + public static int[] GetLockedPages(FIMULTIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + // Get the number of pages and create an array to save the information + int count = 0; + int[] result = null; + // Get count + if (GetLockedPageNumbers(dib, result, ref count)) + { + result = new int[count]; + // Fill array + if (!GetLockedPageNumbers(dib, result, ref count)) + { + result = null; + } + } + return result; + } + + /// + /// Loads a FreeImage multi-paged bitmap from a stream and returns the + /// FreeImage memory stream used as temporary buffer. + /// The bitmap can not be modified by calling + /// , + /// , + /// or + /// . + /// + /// The stream to read from. + /// Format of the image. + /// Flags to enable or disable plugin-features. + /// The temporary memory buffer used to load the bitmap. + /// Handle to a FreeImage multi-paged bitmap. + /// + /// is null. + /// + /// can not read. + public static FIMULTIBITMAP LoadMultiBitmapFromStream( + Stream stream, + FREE_IMAGE_FORMAT format, + FREE_IMAGE_LOAD_FLAGS flags, + out FIMEMORY memory) + { + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + if (!stream.CanRead) + { + throw new ArgumentException("stream"); + } + const int blockSize = 1024; + int bytesRead; + byte[] buffer = new byte[blockSize]; + + stream = stream.CanSeek ? stream : new StreamWrapper(stream, true); + memory = OpenMemory(IntPtr.Zero, 0); + + do + { + bytesRead = stream.Read(buffer, 0, blockSize); + WriteMemory(buffer, (uint)blockSize, (uint)1, memory); + } + while (bytesRead == blockSize); + + return LoadMultiBitmapFromMemory(format, memory, flags); + } + + #endregion + + #region Filetype functions + + /// + /// Orders FreeImage to analyze the bitmap signature. + /// In case the stream is not seekable, the stream will have been used + /// and must be recreated for loading. + /// + /// Name of the stream to analyze. + /// Type of the bitmap. + /// + /// is null. + /// + /// can not read. + public static FREE_IMAGE_FORMAT GetFileTypeFromStream(Stream stream) + { + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + if (!stream.CanRead) + { + throw new ArgumentException("stream is not capable of reading."); + } + // Wrap the stream if it cannot seek + stream = (stream.CanSeek) ? stream : new StreamWrapper(stream, true); + // Create a 'FreeImageIO' structure for the stream + FreeImageIO io = FreeImageStreamIO.io; + using (fi_handle handle = new fi_handle(stream)) + { + return GetFileTypeFromHandle(ref io, handle, 0); + } + } + + #endregion + + #region Pixel access functions + + /// + /// Retrieves an hBitmap for a FreeImage bitmap. + /// Call FreeHbitmap(IntPtr) to free the handle. + /// + /// Handle to a FreeImage bitmap. + /// A reference device context. + /// Use IntPtr.Zero if no reference is available. + /// When true dib will be unloaded if the function succeeded. + /// The hBitmap for the FreeImage bitmap. + /// + /// is null. + public static unsafe IntPtr GetHbitmap(FIBITMAP dib, IntPtr hdc, bool unload) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + IntPtr hBitmap = IntPtr.Zero; + bool release = false; + IntPtr ppvBits = IntPtr.Zero; + // Check if we have destination + if (release = (hdc == IntPtr.Zero)) + { + // We don't so request dc + hdc = GetDC(IntPtr.Zero); + } + if (hdc != IntPtr.Zero) + { + // Get pointer to the infoheader of the bitmap + IntPtr info = GetInfo(dib); + // Create a bitmap in the dc + hBitmap = CreateDIBSection(hdc, info, DIB_RGB_COLORS, out ppvBits, IntPtr.Zero, 0); + if (hBitmap != IntPtr.Zero && ppvBits != IntPtr.Zero) + { + // Copy the data into the dc + CopyMemory(ppvBits, GetBits(dib), (GetHeight(dib) * GetPitch(dib))); + // Success: we unload the bitmap + if (unload) + { + Unload(dib); + } + } + // We have to release the dc + if (release) + { + ReleaseDC(IntPtr.Zero, hdc); + } + } + return hBitmap; + } + + /// + /// Returns an HBITMAP created by the CreateDIBitmap() function which in turn + /// has always the same color depth as the reference DC, which may be provided + /// through . The desktop DC will be used, + /// if IntPtr.Zero DC is specified. + /// Call to free the handle. + /// + /// Handle to a FreeImage bitmap. + /// Handle to a device context. + /// When true the structure will be unloaded on success. + /// If the function failed and returned false, the bitmap was not unloaded. + /// If the function succeeds, the return value is a handle to the + /// compatible bitmap. If the function fails, the return value is . + /// + /// is null. + public static IntPtr GetBitmapForDevice(FIBITMAP dib, IntPtr hdc, bool unload) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + IntPtr hbitmap = IntPtr.Zero; + bool release = false; + if (release = (hdc == IntPtr.Zero)) + { + hdc = GetDC(IntPtr.Zero); + } + if (hdc != IntPtr.Zero) + { + hbitmap = CreateDIBitmap( + hdc, + GetInfoHeader(dib), + CBM_INIT, + GetBits(dib), + GetInfo(dib), + DIB_RGB_COLORS); + if (unload) + { + Unload(dib); + } + if (release) + { + ReleaseDC(IntPtr.Zero, hdc); + } + } + return hbitmap; + } + + /// + /// Creates a FreeImage DIB from a Device Context/Compatible Bitmap. + /// + /// Handle to the bitmap. + /// Handle to a device context. + /// Handle to a FreeImage bitmap. + /// + /// is null. + public unsafe static FIBITMAP CreateFromHbitmap(IntPtr hbitmap, IntPtr hdc) + { + if (hbitmap == IntPtr.Zero) + { + throw new ArgumentNullException("hbitmap"); + } + + FIBITMAP dib = new FIBITMAP(); + BITMAP bm; + uint colors; + bool release; + + if (GetObject(hbitmap, sizeof(BITMAP), (IntPtr)(&bm)) != 0) + { + dib = Allocate(bm.bmWidth, bm.bmHeight, bm.bmBitsPixel, 0, 0, 0); + if (!dib.IsNull) + { + colors = GetColorsUsed(dib); + if (release = (hdc == IntPtr.Zero)) + { + hdc = GetDC(IntPtr.Zero); + } + if (GetDIBits( + hdc, + hbitmap, + 0, + (uint)bm.bmHeight, + GetBits(dib), + GetInfo(dib), + DIB_RGB_COLORS) != 0) + { + if (colors != 0) + { + BITMAPINFOHEADER* bmih = (BITMAPINFOHEADER*)GetInfo(dib); + bmih[0].biClrImportant = bmih[0].biClrUsed = colors; + } + } + else + { + UnloadEx(ref dib); + } + if (release) + { + ReleaseDC(IntPtr.Zero, hdc); + } + } + } + + return dib; + } + + /// + /// Frees a bitmap handle. + /// + /// Handle to a bitmap. + /// True on success, false on failure. + public static bool FreeHbitmap(IntPtr hbitmap) + { + return DeleteObject(hbitmap); + } + + #endregion + + #region Bitmap information functions + + /// + /// Retrieves a DIB's resolution in X-direction measured in 'dots per inch' (DPI) and not in + /// 'dots per meter'. + /// + /// Handle to a FreeImage bitmap. + /// The resolution in 'dots per inch'. + /// + /// is null. + public static uint GetResolutionX(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + return (uint)(0.5d + 0.0254d * GetDotsPerMeterX(dib)); + } + + /// + /// Retrieves a DIB's resolution in Y-direction measured in 'dots per inch' (DPI) and not in + /// 'dots per meter'. + /// + /// Handle to a FreeImage bitmap. + /// The resolution in 'dots per inch'. + /// + /// is null. + public static uint GetResolutionY(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + return (uint)(0.5d + 0.0254d * GetDotsPerMeterY(dib)); + } + + /// + /// Sets a DIB's resolution in X-direction measured in 'dots per inch' (DPI) and not in + /// 'dots per meter'. + /// + /// Handle to a FreeImage bitmap. + /// The new resolution in 'dots per inch'. + /// + /// is null. + public static void SetResolutionX(FIBITMAP dib, uint res) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + SetDotsPerMeterX(dib, (uint)((double)res / 0.0254d + 0.5d)); + } + + /// + /// Sets a DIB's resolution in Y-direction measured in 'dots per inch' (DPI) and not in + /// 'dots per meter'. + /// + /// Handle to a FreeImage bitmap. + /// The new resolution in 'dots per inch'. + /// + /// is null. + public static void SetResolutionY(FIBITMAP dib, uint res) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + SetDotsPerMeterY(dib, (uint)((double)res / 0.0254d + 0.5d)); + } + + /// + /// Returns whether the image is a greyscale image or not. + /// The function scans all colors in the bitmaps palette for entries where + /// red, green and blue are not all the same (not a grey color). + /// Supports 1-, 4- and 8-bit bitmaps. + /// + /// Handle to a FreeImage bitmap. + /// True if the image is a greyscale image, else false. + /// + /// is null. + public static unsafe bool IsGreyscaleImage(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + bool result = true; + uint bpp = GetBPP(dib); + switch (bpp) + { + case 1: + case 4: + case 8: + RGBQUAD* palette = (RGBQUAD*)GetPalette(dib); + uint paletteLength = GetColorsUsed(dib); + for (int i = 0; i < paletteLength; i++) + { + if (palette[i].rgbRed != palette[i].rgbGreen || + palette[i].rgbRed != palette[i].rgbBlue) + { + result = false; + break; + } + } + break; + default: + result = false; + break; + } + return result; + } + + /// + /// Returns a structure that represents the palette of a FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// A structure representing the bitmaps palette. + /// + /// is null. + public static Palette GetPaletteEx(FIBITMAP dib) + { + return new Palette(dib); + } + + /// + /// Returns the structure of a FreeImage bitmap. + /// The structure is a copy, so changes will have no effect on + /// the bitmap itself. + /// + /// Handle to a FreeImage bitmap. + /// structure of the bitmap. + /// + /// is null. + public static unsafe BITMAPINFOHEADER GetInfoHeaderEx(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + return *(BITMAPINFOHEADER*)GetInfoHeader(dib); + } + + /// + /// Returns the structure of a FreeImage bitmap. + /// The structure is a copy, so changes will have no effect on + /// the bitmap itself. + /// + /// Handle to a FreeImage bitmap. + /// structure of the bitmap. + /// + /// is null. + public static BITMAPINFO GetInfoEx(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + BITMAPINFO result = new BITMAPINFO(); + result.bmiHeader = GetInfoHeaderEx(dib); + IntPtr ptr = GetPalette(dib); + if (ptr == IntPtr.Zero) + { + result.bmiColors = new RGBQUAD[0]; + } + else + { + result.bmiColors = new MemoryArray(ptr, (int)result.bmiHeader.biClrUsed).Data; + } + return result; + } + + /// + /// Returns the pixelformat of the bitmap. + /// + /// Handle to a FreeImage bitmap. + /// of the bitmap. + /// + /// is null. + public static PixelFormat GetPixelFormat(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + + PixelFormat result = PixelFormat.Undefined; + + if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) + { + switch (GetBPP(dib)) + { + case 1: + result = PixelFormat.Format1bppIndexed; + break; + case 4: + result = PixelFormat.Format4bppIndexed; + break; + case 8: + result = PixelFormat.Format8bppIndexed; + break; + case 16: + if ((GetBlueMask(dib) == FI16_565_BLUE_MASK) && + (GetGreenMask(dib) == FI16_565_GREEN_MASK) && + (GetRedMask(dib) == FI16_565_RED_MASK)) + { + result = PixelFormat.Format16bppRgb565; + } + if ((GetBlueMask(dib) == FI16_555_BLUE_MASK) && + (GetGreenMask(dib) == FI16_555_GREEN_MASK) && + (GetRedMask(dib) == FI16_555_RED_MASK)) + { + result = PixelFormat.Format16bppRgb555; + } + break; + case 24: + result = PixelFormat.Format24bppRgb; + break; + case 32: + result = PixelFormat.Format32bppArgb; + break; + } + } + return result; + } + + /// + /// Retrieves all parameters needed to create a new FreeImage bitmap from + /// the format of a .NET . + /// + /// The + /// of the .NET . + /// Returns the type used for the new bitmap. + /// Returns the color depth for the new bitmap. + /// Returns the red_mask for the new bitmap. + /// Returns the green_mask for the new bitmap. + /// Returns the blue_mask for the new bitmap. + /// True in case a matching conversion exists; else false. + /// + public static bool GetFormatParameters( + PixelFormat format, + out FREE_IMAGE_TYPE type, + out uint bpp, + out uint red_mask, + out uint green_mask, + out uint blue_mask) + { + bool result = false; + type = FREE_IMAGE_TYPE.FIT_UNKNOWN; + bpp = 0; + red_mask = 0; + green_mask = 0; + blue_mask = 0; + switch (format) + { + case PixelFormat.Format1bppIndexed: + type = FREE_IMAGE_TYPE.FIT_BITMAP; + bpp = 1; + result = true; + break; + case PixelFormat.Format4bppIndexed: + type = FREE_IMAGE_TYPE.FIT_BITMAP; + bpp = 4; + result = true; + break; + case PixelFormat.Format8bppIndexed: + type = FREE_IMAGE_TYPE.FIT_BITMAP; + bpp = 8; + result = true; + break; + case PixelFormat.Format16bppRgb565: + type = FREE_IMAGE_TYPE.FIT_BITMAP; + bpp = 16; + red_mask = FI16_565_RED_MASK; + green_mask = FI16_565_GREEN_MASK; + blue_mask = FI16_565_BLUE_MASK; + result = true; + break; + case PixelFormat.Format16bppRgb555: + case PixelFormat.Format16bppArgb1555: + type = FREE_IMAGE_TYPE.FIT_BITMAP; + bpp = 16; + red_mask = FI16_555_RED_MASK; + green_mask = FI16_555_GREEN_MASK; + blue_mask = FI16_555_BLUE_MASK; + result = true; + break; + case PixelFormat.Format24bppRgb: + type = FREE_IMAGE_TYPE.FIT_BITMAP; + bpp = 24; + red_mask = FI_RGBA_RED_MASK; + green_mask = FI_RGBA_GREEN_MASK; + blue_mask = FI_RGBA_BLUE_MASK; + result = true; + break; + case PixelFormat.Format32bppRgb: + case PixelFormat.Format32bppArgb: + case PixelFormat.Format32bppPArgb: + type = FREE_IMAGE_TYPE.FIT_BITMAP; + bpp = 32; + red_mask = FI_RGBA_RED_MASK; + green_mask = FI_RGBA_GREEN_MASK; + blue_mask = FI_RGBA_BLUE_MASK; + result = true; + break; + case PixelFormat.Format16bppGrayScale: + type = FREE_IMAGE_TYPE.FIT_UINT16; + bpp = 16; + result = true; + break; + case PixelFormat.Format48bppRgb: + type = FREE_IMAGE_TYPE.FIT_RGB16; + bpp = 48; + result = true; + break; + case PixelFormat.Format64bppArgb: + case PixelFormat.Format64bppPArgb: + type = FREE_IMAGE_TYPE.FIT_RGBA16; + bpp = 64; + result = true; + break; + } + return result; + } + + /// + /// Returns the for the specified + /// . + /// + /// The + /// for which to return the corresponding . + /// The for the specified + /// + public static FREE_IMAGE_FORMAT GetFormat(ImageFormat imageFormat) + { + if (imageFormat != null) + { + if (imageFormat.Equals(ImageFormat.Bmp)) + return FREE_IMAGE_FORMAT.FIF_BMP; + if (imageFormat.Equals(ImageFormat.Gif)) + return FREE_IMAGE_FORMAT.FIF_GIF; + if (imageFormat.Equals(ImageFormat.Icon)) + return FREE_IMAGE_FORMAT.FIF_ICO; + if (imageFormat.Equals(ImageFormat.Jpeg)) + return FREE_IMAGE_FORMAT.FIF_JPEG; + if (imageFormat.Equals(ImageFormat.Png)) + return FREE_IMAGE_FORMAT.FIF_PNG; + if (imageFormat.Equals(ImageFormat.Tiff)) + return FREE_IMAGE_FORMAT.FIF_TIFF; + } + return FREE_IMAGE_FORMAT.FIF_UNKNOWN; + } + + /// + /// Retrieves all parameters needed to create a new FreeImage bitmap from + /// raw bits . + /// + /// The + /// of the data in memory. + /// The color depth for the data. + /// Returns the red_mask for the data. + /// Returns the green_mask for the data. + /// Returns the blue_mask for the data. + /// True in case a matching conversion exists; else false. + /// + public static bool GetTypeParameters( + FREE_IMAGE_TYPE type, + int bpp, + out uint red_mask, + out uint green_mask, + out uint blue_mask) + { + bool result = false; + red_mask = 0; + green_mask = 0; + blue_mask = 0; + switch (type) + { + case FREE_IMAGE_TYPE.FIT_BITMAP: + switch (bpp) + { + case 1: + case 4: + case 8: + result = true; + break; + case 16: + result = true; + red_mask = FI16_555_RED_MASK; + green_mask = FI16_555_GREEN_MASK; + blue_mask = FI16_555_BLUE_MASK; + break; + case 24: + case 32: + result = true; + red_mask = FI_RGBA_RED_MASK; + green_mask = FI_RGBA_GREEN_MASK; + blue_mask = FI_RGBA_BLUE_MASK; + break; + } + break; + case FREE_IMAGE_TYPE.FIT_UNKNOWN: + break; + default: + result = true; + break; + } + return result; + } + + /// + /// Compares two FreeImage bitmaps. + /// + /// The first bitmap to compare. + /// The second bitmap to compare. + /// Determines which components of the bitmaps will be compared. + /// True in case both bitmaps match the compare conditions, false otherwise. + public static bool Compare(FIBITMAP dib1, FIBITMAP dib2, FREE_IMAGE_COMPARE_FLAGS flags) + { + // Check whether one bitmap is null + if (dib1.IsNull ^ dib2.IsNull) + { + return false; + } + // Check whether both pointers are the same + if (dib1 == dib2) + { + return true; + } + if (((flags & FREE_IMAGE_COMPARE_FLAGS.HEADER) > 0) && (!CompareHeader(dib1, dib2))) + { + return false; + } + if (((flags & FREE_IMAGE_COMPARE_FLAGS.PALETTE) > 0) && (!ComparePalette(dib1, dib2))) + { + return false; + } + if (((flags & FREE_IMAGE_COMPARE_FLAGS.DATA) > 0) && (!CompareData(dib1, dib2))) + { + return false; + } + if (((flags & FREE_IMAGE_COMPARE_FLAGS.METADATA) > 0) && (!CompareMetadata(dib1, dib2))) + { + return false; + } + return true; + } + + private static unsafe bool CompareHeader(FIBITMAP dib1, FIBITMAP dib2) + { + IntPtr i1 = GetInfoHeader(dib1); + IntPtr i2 = GetInfoHeader(dib2); + return CompareMemory((void*)i1, (void*)i2, sizeof(BITMAPINFOHEADER)); + } + + private static unsafe bool ComparePalette(FIBITMAP dib1, FIBITMAP dib2) + { + IntPtr pal1 = GetPalette(dib1), pal2 = GetPalette(dib2); + bool hasPalette1 = pal1 != IntPtr.Zero; + bool hasPalette2 = pal2 != IntPtr.Zero; + if (hasPalette1 ^ hasPalette2) + { + return false; + } + if (!hasPalette1) + { + return true; + } + uint colors = GetColorsUsed(dib1); + if (colors != GetColorsUsed(dib2)) + { + return false; + } + return CompareMemory((void*)pal1, (void*)pal2, sizeof(RGBQUAD) * colors); + } + + private static unsafe bool CompareData(FIBITMAP dib1, FIBITMAP dib2) + { + uint width = GetWidth(dib1); + if (width != GetWidth(dib2)) + { + return false; + } + uint height = GetHeight(dib1); + if (height != GetHeight(dib2)) + { + return false; + } + uint bpp = GetBPP(dib1); + if (bpp != GetBPP(dib2)) + { + return false; + } + if (GetColorType(dib1) != GetColorType(dib2)) + { + return false; + } + FREE_IMAGE_TYPE type = GetImageType(dib1); + if (type != GetImageType(dib2)) + { + return false; + } + if (GetRedMask(dib1) != GetRedMask(dib2)) + { + return false; + } + if (GetGreenMask(dib1) != GetGreenMask(dib2)) + { + return false; + } + if (GetBlueMask(dib1) != GetBlueMask(dib2)) + { + return false; + } + + byte* ptr1, ptr2; + int fullBytes; + int shift; + uint line = GetLine(dib1); + + if (type == FREE_IMAGE_TYPE.FIT_BITMAP) + { + switch (bpp) + { + case 32: + for (int i = 0; i < height; i++) + { + ptr1 = (byte*)GetScanLine(dib1, i); + ptr2 = (byte*)GetScanLine(dib2, i); + if (!CompareMemory(ptr1, ptr2, line)) + { + return false; + } + } + break; + case 24: + for (int i = 0; i < height; i++) + { + ptr1 = (byte*)GetScanLine(dib1, i); + ptr2 = (byte*)GetScanLine(dib2, i); + if (!CompareMemory(ptr1, ptr2, line)) + { + return false; + } + } + break; + case 16: + short* sPtr1, sPtr2; + short mask = (short)(GetRedMask(dib1) | GetGreenMask(dib1) | GetBlueMask(dib1)); + if (mask == -1) + { + for (int i = 0; i < height; i++) + { + sPtr1 = (short*)GetScanLine(dib1, i); + sPtr2 = (short*)GetScanLine(dib2, i); + if (!CompareMemory(sPtr1, sPtr1, line)) + { + return false; + } + } + } + else + { + for (int i = 0; i < height; i++) + { + sPtr1 = (short*)GetScanLine(dib1, i); + sPtr2 = (short*)GetScanLine(dib2, i); + for (int x = 0; x < width; x++) + { + if ((sPtr1[x] & mask) != (sPtr2[x] & mask)) + { + return false; + } + } + } + } + break; + case 8: + for (int i = 0; i < height; i++) + { + ptr1 = (byte*)GetScanLine(dib1, i); + ptr2 = (byte*)GetScanLine(dib2, i); + if (!CompareMemory(ptr1, ptr2, line)) + { + return false; + } + } + break; + case 4: + fullBytes = (int)width / 2; + shift = (width % 2) == 0 ? 8 : 4; + for (int i = 0; i < height; i++) + { + ptr1 = (byte*)GetScanLine(dib1, i); + ptr2 = (byte*)GetScanLine(dib2, i); + if (fullBytes != 0) + { + if (!CompareMemory(ptr1, ptr2, fullBytes)) + { + return false; + } + ptr1 += fullBytes; + ptr2 += fullBytes; + } + if (shift != 8) + { + if ((ptr1[0] >> shift) != (ptr2[0] >> shift)) + { + return false; + } + } + } + break; + case 1: + fullBytes = (int)width / 8; + shift = 8 - ((int)width % 8); + for (int i = 0; i < height; i++) + { + ptr1 = (byte*)GetScanLine(dib1, i); + ptr2 = (byte*)GetScanLine(dib2, i); + if (fullBytes != 0) + { + if (!CompareMemory(ptr1, ptr2, fullBytes)) + { + return false; + } + ptr1 += fullBytes; + ptr2 += fullBytes; + } + if (shift != 8) + { + if ((ptr1[0] >> shift) != (ptr2[0] >> shift)) + { + return false; + } + } + } + break; + default: + throw new NotSupportedException("Only 1, 4, 8, 16, 24 and 32 bpp bitmaps are supported."); + } + } + else + { + for (int i = 0; i < height; i++) + { + ptr1 = (byte*)GetScanLine(dib1, i); + ptr2 = (byte*)GetScanLine(dib2, i); + if (!CompareMemory(ptr1, ptr2, line)) + { + return false; + } + } + } + return true; + } + + private static bool CompareMetadata(FIBITMAP dib1, FIBITMAP dib2) + { + MetadataTag tag1, tag2; + + foreach (FREE_IMAGE_MDMODEL metadataModel in FREE_IMAGE_MDMODELS) + { + if (GetMetadataCount(metadataModel, dib1) != + GetMetadataCount(metadataModel, dib2)) + { + return false; + } + if (GetMetadataCount(metadataModel, dib1) == 0) + { + continue; + } + + FIMETADATA mdHandle = FindFirstMetadata(metadataModel, dib1, out tag1); + if (mdHandle.IsNull) + { + continue; + } + do + { + if ((!GetMetadata(metadataModel, dib2, tag1.Key, out tag2)) || (tag1 != tag2)) + { + FindCloseMetadata(mdHandle); + return false; + } + } + while (FindNextMetadata(mdHandle, out tag1)); + FindCloseMetadata(mdHandle); + } + + return true; + } + + /// + /// Returns the FreeImage bitmap's transparency table. + /// The array is empty in case the bitmap has no transparency table. + /// + /// Handle to a FreeImage bitmap. + /// The FreeImage bitmap's transparency table. + /// + /// is null. + public static unsafe byte[] GetTransparencyTableEx(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + uint count = GetTransparencyCount(dib); + byte[] result = new byte[count]; + byte* ptr = (byte*)GetTransparencyTable(dib); + fixed (byte* dst = result) + { + CopyMemory(dst, ptr, count); + } + return result; + } + + /// + /// Set the FreeImage bitmap's transparency table. Only affects palletised bitmaps. + /// + /// Handle to a FreeImage bitmap. + /// The FreeImage bitmap's new transparency table. + /// + /// or is null. + public static void SetTransparencyTable(FIBITMAP dib, byte[] table) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + if (table == null) + { + throw new ArgumentNullException("table"); + } + SetTransparencyTable(dib, table, table.Length); + } + + /// + /// This function returns the number of unique colors actually used by the + /// specified 1-, 4-, 8-, 16-, 24- or 32-bit image. This might be different from + /// what function FreeImage_GetColorsUsed() returns, which actually returns the + /// palette size for palletised images. Works for + /// type images only. + /// + /// Handle to a FreeImage bitmap. + /// Returns the number of unique colors used by the image specified or + /// zero, if the image type cannot be handled. + /// + /// is null. + public static unsafe int GetUniqueColors(FIBITMAP dib) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + + int result = 0; + + if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) + { + BitArray bitArray; + int uniquePalEnts; + int hashcode; + byte[] lut; + int width = (int)GetWidth(dib); + int height = (int)GetHeight(dib); + + switch (GetBPP(dib)) + { + case 1: + + result = 1; + lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts); + if (uniquePalEnts == 1) + { + break; + } + + if ((*(byte*)GetScanLine(dib, 0) & 0x80) == 0) + { + for (int y = 0; y < height; y++) + { + byte* scanline = (byte*)GetScanLine(dib, y); + int mask = 0x80; + for (int x = 0; x < width; x++) + { + if ((scanline[x / 8] & mask) > 0) + { + return 2; + } + mask = (mask == 0x1) ? 0x80 : (mask >> 1); + } + } + } + else + { + for (int y = 0; y < height; y++) + { + byte* scanline = (byte*)GetScanLine(dib, y); + int mask = 0x80; + for (int x = 0; x < width; x++) + { + if ((scanline[x / 8] & mask) == 0) + { + return 2; + } + mask = (mask == 0x1) ? 0x80 : (mask >> 1); + } + } + } + break; + + case 4: + + bitArray = new BitArray(0x10); + lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts); + if (uniquePalEnts == 1) + { + result = 1; + break; + } + + for (int y = 0; (y < height) && (result < uniquePalEnts); y++) + { + byte* scanline = (byte*)GetScanLine(dib, y); + bool top = true; + for (int x = 0; (x < width) && (result < uniquePalEnts); x++) + { + if (top) + { + hashcode = lut[scanline[x / 2] >> 4]; + } + else + { + hashcode = lut[scanline[x / 2] & 0xF]; + } + top = !top; + if (!bitArray[hashcode]) + { + bitArray[hashcode] = true; + result++; + } + } + } + break; + + case 8: + + bitArray = new BitArray(0x100); + lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts); + if (uniquePalEnts == 1) + { + result = 1; + break; + } + + for (int y = 0; (y < height) && (result < uniquePalEnts); y++) + { + byte* scanline = (byte*)GetScanLine(dib, y); + for (int x = 0; (x < width) && (result < uniquePalEnts); x++) + { + hashcode = lut[scanline[x]]; + if (!bitArray[hashcode]) + { + bitArray[hashcode] = true; + result++; + } + } + } + break; + + case 16: + + bitArray = new BitArray(0x10000); + + for (int y = 0; y < height; y++) + { + short* scanline = (short*)GetScanLine(dib, y); + for (int x = 0; x < width; x++, scanline++) + { + hashcode = *scanline; + if (!bitArray[hashcode]) + { + bitArray[hashcode] = true; + result++; + } + } + } + break; + + case 24: + + bitArray = new BitArray(0x1000000); + + for (int y = 0; y < height; y++) + { + byte* scanline = (byte*)GetScanLine(dib, y); + for (int x = 0; x < width; x++, scanline += 3) + { + hashcode = *((int*)scanline) & 0x00FFFFFF; + if (!bitArray[hashcode]) + { + bitArray[hashcode] = true; + result++; + } + } + } + break; + + case 32: + + bitArray = new BitArray(0x1000000); + + for (int y = 0; y < height; y++) + { + int* scanline = (int*)GetScanLine(dib, y); + for (int x = 0; x < width; x++, scanline++) + { + hashcode = *scanline & 0x00FFFFFF; + if (!bitArray[hashcode]) + { + bitArray[hashcode] = true; + result++; + } + } + } + break; + } + } + return result; + } + + /// + /// Verifies whether the FreeImage bitmap is 16bit 555. + /// + /// The FreeImage bitmap to verify. + /// true if the bitmap is RGB16-555; otherwise false. + public static bool IsRGB555(FIBITMAP dib) + { + return ((GetRedMask(dib) == FI16_555_RED_MASK) && + (GetGreenMask(dib) == FI16_555_GREEN_MASK) && + (GetBlueMask(dib) == FI16_555_BLUE_MASK)); + } + + /// + /// Verifies whether the FreeImage bitmap is 16bit 565. + /// + /// The FreeImage bitmap to verify. + /// true if the bitmap is RGB16-565; otherwise false. + public static bool IsRGB565(FIBITMAP dib) + { + return ((GetRedMask(dib) == FI16_565_RED_MASK) && + (GetGreenMask(dib) == FI16_565_GREEN_MASK) && + (GetBlueMask(dib) == FI16_565_BLUE_MASK)); + } + + #endregion + + #region ICC profile functions + + /// + /// Creates a new ICC-Profile for a FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The data of the new ICC-Profile. + /// The new ICC-Profile of the bitmap. + /// + /// is null. + public static FIICCPROFILE CreateICCProfileEx(FIBITMAP dib, byte[] data) + { + return new FIICCPROFILE(dib, data); + } + + /// + /// Creates a new ICC-Profile for a FreeImage bitmap. + /// + /// Handle to a FreeImage bitmap. + /// The data of the new ICC-Profile. + /// The number of bytes of to use. + /// The new ICC-Profile of the FreeImage bitmap. + /// + /// is null. + public static FIICCPROFILE CreateICCProfileEx(FIBITMAP dib, byte[] data, int size) + { + return new FIICCPROFILE(dib, data, size); + } + + #endregion + + #region Conversion functions + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion) + { + return ConvertColorDepth( + dib, + conversion, + 128, + FREE_IMAGE_DITHER.FID_FS, + FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, + false); + } + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// When true the structure will be unloaded on success. + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + bool unloadSource) + { + return ConvertColorDepth( + dib, + conversion, + 128, + FREE_IMAGE_DITHER.FID_FS, + FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, + unloadSource); + } + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// Threshold value when converting with + /// . + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + byte threshold) + { + return ConvertColorDepth( + dib, + conversion, + threshold, + FREE_IMAGE_DITHER.FID_FS, + FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, + false); + } + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// Dither algorithm when converting + /// with . + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + FREE_IMAGE_DITHER ditherMethod) + { + return ConvertColorDepth( + dib, + conversion, + 128, + ditherMethod, + FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, + false); + } + + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// The quantization algorithm for conversion to 8-bit color depth. + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + FREE_IMAGE_QUANTIZE quantizationMethod) + { + return ConvertColorDepth( + dib, + conversion, + 128, + FREE_IMAGE_DITHER.FID_FS, + quantizationMethod, + false); + } + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// Threshold value when converting with + /// . + /// When true the structure will be unloaded on success. + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + byte threshold, + bool unloadSource) + { + return ConvertColorDepth( + dib, + conversion, + threshold, + FREE_IMAGE_DITHER.FID_FS, + FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, + unloadSource); + } + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// Dither algorithm when converting with + /// . + /// When true the structure will be unloaded on success. + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + FREE_IMAGE_DITHER ditherMethod, + bool unloadSource) + { + return ConvertColorDepth( + dib, + conversion, + 128, + ditherMethod, + FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, + unloadSource); + } + + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// The quantization algorithm for conversion to 8-bit color depth. + /// When true the structure will be unloaded on success. + /// Handle to a FreeImage bitmap. + /// + /// is null. + public static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + FREE_IMAGE_QUANTIZE quantizationMethod, + bool unloadSource) + { + return ConvertColorDepth( + dib, + conversion, + 128, + FREE_IMAGE_DITHER.FID_FS, + quantizationMethod, + unloadSource); + } + + /// + /// Converts a FreeImage bitmap from one color depth to another. + /// If the conversion fails the original FreeImage bitmap is returned. + /// + /// Handle to a FreeImage bitmap. + /// The desired output format. + /// Threshold value when converting with + /// . + /// Dither algorithm when converting with + /// . + /// The quantization algorithm for conversion to 8-bit color depth. + /// When true the structure will be unloaded on success. + /// Handle to a FreeImage bitmap. + /// + /// is null. + internal static FIBITMAP ConvertColorDepth( + FIBITMAP dib, + FREE_IMAGE_COLOR_DEPTH conversion, + byte threshold, + FREE_IMAGE_DITHER ditherMethod, + FREE_IMAGE_QUANTIZE quantizationMethod, + bool unloadSource) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + + FIBITMAP result = new FIBITMAP(); + FIBITMAP dibTemp = new FIBITMAP(); + uint bpp = GetBPP(dib); + bool reorderPalette = ((conversion & FREE_IMAGE_COLOR_DEPTH.FICD_REORDER_PALETTE) > 0); + bool forceGreyscale = ((conversion & FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE) > 0); + + if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) + { + switch (conversion & (FREE_IMAGE_COLOR_DEPTH)0xFF) + { + case FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_THRESHOLD: + + if (bpp != 1) + { + if (forceGreyscale) + { + result = Threshold(dib, threshold); + } + else + { + dibTemp = ConvertTo24Bits(dib); + result = ColorQuantizeEx(dibTemp, quantizationMethod, 2, null, 1); + Unload(dibTemp); + } + } + else + { + bool isGreyscale = IsGreyscaleImage(dib); + if ((forceGreyscale && (!isGreyscale)) || + (reorderPalette && isGreyscale)) + { + result = Threshold(dib, threshold); + } + } + break; + + case FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_DITHER: + + if (bpp != 1) + { + if (forceGreyscale) + { + result = Dither(dib, ditherMethod); + } + else + { + dibTemp = ConvertTo24Bits(dib); + result = ColorQuantizeEx(dibTemp, quantizationMethod, 2, null, 1); + Unload(dibTemp); + } + } + else + { + bool isGreyscale = IsGreyscaleImage(dib); + if ((forceGreyscale && (!isGreyscale)) || + (reorderPalette && isGreyscale)) + { + result = Dither(dib, ditherMethod); + } + } + break; + + case FREE_IMAGE_COLOR_DEPTH.FICD_04_BPP: + + if (bpp != 4) + { + // Special case when 1bpp and FIC_PALETTE + if (forceGreyscale || + ((bpp == 1) && (GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_PALETTE))) + { + dibTemp = ConvertToGreyscale(dib); + result = ConvertTo4Bits(dibTemp); + Unload(dibTemp); + } + else + { + dibTemp = ConvertTo24Bits(dib); + result = ColorQuantizeEx(dibTemp, quantizationMethod, 16, null, 4); + Unload(dibTemp); + } + } + else + { + bool isGreyscale = IsGreyscaleImage(dib); + if ((forceGreyscale && (!isGreyscale)) || + (reorderPalette && isGreyscale)) + { + dibTemp = ConvertToGreyscale(dib); + result = ConvertTo4Bits(dibTemp); + Unload(dibTemp); + } + } + + break; + + case FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP: + + if (bpp != 8) + { + if (forceGreyscale) + { + result = ConvertToGreyscale(dib); + } + else + { + dibTemp = ConvertTo24Bits(dib); + result = ColorQuantize(dibTemp, quantizationMethod); + Unload(dibTemp); + } + } + else + { + bool isGreyscale = IsGreyscaleImage(dib); + if ((forceGreyscale && (!isGreyscale)) || (reorderPalette && isGreyscale)) + { + result = ConvertToGreyscale(dib); + } + } + break; + + case FREE_IMAGE_COLOR_DEPTH.FICD_16_BPP_555: + + if (forceGreyscale) + { + dibTemp = ConvertToGreyscale(dib); + result = ConvertTo16Bits555(dibTemp); + Unload(dibTemp); + } + else if (bpp != 16 || GetRedMask(dib) != FI16_555_RED_MASK || GetGreenMask(dib) != FI16_555_GREEN_MASK || GetBlueMask(dib) != FI16_555_BLUE_MASK) + { + result = ConvertTo16Bits555(dib); + } + break; + + case FREE_IMAGE_COLOR_DEPTH.FICD_16_BPP: + + if (forceGreyscale) + { + dibTemp = ConvertToGreyscale(dib); + result = ConvertTo16Bits565(dibTemp); + Unload(dibTemp); + } + else if (bpp != 16 || GetRedMask(dib) != FI16_565_RED_MASK || GetGreenMask(dib) != FI16_565_GREEN_MASK || GetBlueMask(dib) != FI16_565_BLUE_MASK) + { + result = ConvertTo16Bits565(dib); + } + break; + + case FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP: + + if (forceGreyscale) + { + dibTemp = ConvertToGreyscale(dib); + result = ConvertTo24Bits(dibTemp); + Unload(dibTemp); + } + else if (bpp != 24) + { + result = ConvertTo24Bits(dib); + } + break; + + case FREE_IMAGE_COLOR_DEPTH.FICD_32_BPP: + + if (forceGreyscale) + { + dibTemp = ConvertToGreyscale(dib); + result = ConvertTo32Bits(dibTemp); + Unload(dibTemp); + } + else if (bpp != 32) + { + result = ConvertTo32Bits(dib); + } + break; + } + } + + if (result.IsNull) + { + return dib; + } + if (unloadSource) + { + Unload(dib); + } + + return result; + } + + /// + /// ColorQuantizeEx is an extension to the + /// method that provides additional options used to quantize a 24-bit image to any + /// number of colors (up to 256), as well as quantize a 24-bit image using a + /// provided palette. + /// + /// Handle to a FreeImage bitmap. + /// Specifies the color reduction algorithm to be used. + /// Size of the desired output palette. + /// The provided palette. + /// true to create a bitmap with the smallest possible + /// color depth for the specified . + /// Handle to a FreeImage bitmap. + public static FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, RGBQUAD[] ReservePalette, bool minColorDepth) + { + FIBITMAP result; + if (minColorDepth) + { + int bpp; + if (PaletteSize >= 256) + bpp = 8; + else if (PaletteSize > 2) + bpp = 4; + else + bpp = 1; + result = ColorQuantizeEx(dib, quantize, PaletteSize, ReservePalette, bpp); + } + else + { + result = ColorQuantizeEx(dib, quantize, PaletteSize, ReservePalette, 8); + } + return result; + } + + /// + /// ColorQuantizeEx is an extension to the + /// method that provides additional options used to quantize a 24-bit image to any + /// number of colors (up to 256), as well as quantize a 24-bit image using a + /// partial or full provided palette. + /// + /// Handle to a FreeImage bitmap. + /// Specifies the color reduction algorithm to be used. + /// Size of the desired output palette. + /// The provided palette. + /// The desired color depth of the created image. + /// Handle to a FreeImage bitmap. + public static FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, RGBQUAD[] ReservePalette, int bpp) + { + unsafe + { + FIBITMAP result = FIBITMAP.Zero; + FIBITMAP temp = FIBITMAP.Zero; + int reservedSize = (ReservePalette == null) ? 0 : ReservePalette.Length; + + if (bpp == 8) + { + result = ColorQuantizeEx(dib, quantize, PaletteSize, reservedSize, ReservePalette); + } + else if (bpp == 4) + { + temp = ColorQuantizeEx(dib, quantize, Math.Min(16, PaletteSize), reservedSize, ReservePalette); + if (!temp.IsNull) + { + result = Allocate((int)GetWidth(temp), (int)GetHeight(temp), 4, 0, 0, 0); + CloneMetadata(result, temp); + CopyMemory(GetPalette(result), GetPalette(temp), sizeof(RGBQUAD) * 16); + + for (int y = (int)GetHeight(temp) - 1; y >= 0; y--) + { + Scanline srcScanline = new Scanline(temp, y); + Scanline dstScanline = new Scanline(result, y); + + for (int x = (int)GetWidth(temp) - 1; x >= 0; x--) + { + dstScanline[x] = srcScanline[x]; + } + } + } + } + else if (bpp == 1) + { + temp = ColorQuantizeEx(dib, quantize, 2, reservedSize, ReservePalette); + if (!temp.IsNull) + { + result = Allocate((int)GetWidth(temp), (int)GetHeight(temp), 1, 0, 0, 0); + CloneMetadata(result, temp); + CopyMemory(GetPalette(result), GetPalette(temp), sizeof(RGBQUAD) * 2); + + for (int y = (int)GetHeight(temp) - 1; y >= 0; y--) + { + Scanline srcScanline = new Scanline(temp, y); + Scanline dstScanline = new Scanline(result, y); + + for (int x = (int)GetWidth(temp) - 1; x >= 0; x--) + { + dstScanline[x] = srcScanline[x]; + } + } + } + } + + UnloadEx(ref temp); + return result; + } + } + + #endregion + + #region Metadata + + /// + /// Copies metadata from one FreeImage bitmap to another. + /// + /// Source FreeImage bitmap containing the metadata. + /// FreeImage bitmap to copy the metadata to. + /// Flags to switch different copy modes. + /// Returns -1 on failure else the number of copied tags. + /// + /// or is null. + public static int CloneMetadataEx(FIBITMAP src, FIBITMAP dst, FREE_IMAGE_METADATA_COPY flags) + { + if (src.IsNull) + { + throw new ArgumentNullException("src"); + } + if (dst.IsNull) + { + throw new ArgumentNullException("dst"); + } + + FITAG tag = new FITAG(), tag2 = new FITAG(); + int copied = 0; + + // Clear all existing metadata + if ((flags & FREE_IMAGE_METADATA_COPY.CLEAR_EXISTING) > 0) + { + foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS) + { + if (!SetMetadata(model, dst, null, tag)) + { + return -1; + } + } + } + + bool keep = !((flags & FREE_IMAGE_METADATA_COPY.REPLACE_EXISTING) > 0); + + foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS) + { + FIMETADATA mData = FindFirstMetadata(model, src, out tag); + if (mData.IsNull) continue; + do + { + string key = GetTagKey(tag); + if (!(keep && GetMetadata(model, dst, key, out tag2))) + { + if (SetMetadata(model, dst, key, tag)) + { + copied++; + } + } + } + while (FindNextMetadata(mData, out tag)); + FindCloseMetadata(mData); + } + + return copied; + } + + /// + /// Returns the comment of a JPEG, PNG or GIF image. + /// + /// Handle to a FreeImage bitmap. + /// Comment of the FreeImage bitmp, or null in case no comment exists. + /// + /// is null. + public static string GetImageComment(FIBITMAP dib) + { + string result = null; + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + FITAG tag; + if (GetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", out tag)) + { + MetadataTag metadataTag = new MetadataTag(tag, FREE_IMAGE_MDMODEL.FIMD_COMMENTS); + result = metadataTag.Value as string; + } + return result; + } + + /// + /// Sets the comment of a JPEG, PNG or GIF image. + /// + /// Handle to a FreeImage bitmap. + /// New comment of the FreeImage bitmap. + /// Use null to remove the comment. + /// Returns true on success, false on failure. + /// + /// is null. + public static bool SetImageComment(FIBITMAP dib, string comment) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + bool result; + if (comment != null) + { + FITAG tag = CreateTag(); + MetadataTag metadataTag = new MetadataTag(tag, FREE_IMAGE_MDMODEL.FIMD_COMMENTS); + metadataTag.Value = comment; + result = SetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", tag); + DeleteTag(tag); + } + else + { + result = SetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", FITAG.Zero); + } + return result; + } + + /// + /// Retrieve a metadata attached to a FreeImage bitmap. + /// + /// The metadata model to look for. + /// Handle to a FreeImage bitmap. + /// The metadata field name. + /// A structure returned by the function. + /// Returns true on success, false on failure. + /// + /// is null. + public static bool GetMetadata( + FREE_IMAGE_MDMODEL model, + FIBITMAP dib, + string key, + out MetadataTag tag) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + + FITAG _tag; + bool result; + if (GetMetadata(model, dib, key, out _tag)) + { + tag = new MetadataTag(_tag, model); + result = true; + } + else + { + tag = null; + result = false; + } + return result; + } + + /// + /// Attach a new metadata tag to a FreeImage bitmap. + /// + /// The metadata model used to store the tag. + /// Handle to a FreeImage bitmap. + /// The tag field name. + /// The to be attached. + /// Returns true on success, false on failure. + /// + /// is null. + public static bool SetMetadata( + FREE_IMAGE_MDMODEL model, + FIBITMAP dib, + string key, + MetadataTag tag) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + return SetMetadata(model, dib, key, tag.tag); + } + + /// + /// Provides information about the first instance of a tag that matches the metadata model. + /// + /// The model to match. + /// Handle to a FreeImage bitmap. + /// Tag that matches the metadata model. + /// Unique search handle that can be used to call FindNextMetadata or FindCloseMetadata. + /// Null if the metadata model does not exist. + /// + /// is null. + public static FIMETADATA FindFirstMetadata( + FREE_IMAGE_MDMODEL model, + FIBITMAP dib, + out MetadataTag tag) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + FITAG _tag; + FIMETADATA result = FindFirstMetadata(model, dib, out _tag); + if (result.IsNull) + { + tag = null; + return result; + } + tag = new MetadataTag(_tag, model); + if (metaDataSearchHandler.ContainsKey(result)) + { + metaDataSearchHandler[result] = model; + } + else + { + metaDataSearchHandler.Add(result, model); + } + return result; + } + + /// + /// Find the next tag, if any, that matches the metadata model argument in a previous call + /// to FindFirstMetadata, and then alters the tag object contents accordingly. + /// + /// Unique search handle provided by FindFirstMetadata. + /// Tag that matches the metadata model. + /// Returns true on success, false on failure. + public static bool FindNextMetadata(FIMETADATA mdhandle, out MetadataTag tag) + { + FITAG _tag; + bool result; + if (FindNextMetadata(mdhandle, out _tag)) + { + tag = new MetadataTag(_tag, metaDataSearchHandler[mdhandle]); + result = true; + } + else + { + tag = null; + result = false; + } + return result; + } + + /// + /// Closes the specified metadata search handle and releases associated resources. + /// + /// The handle to close. + public static void FindCloseMetadata(FIMETADATA mdhandle) + { + if (metaDataSearchHandler.ContainsKey(mdhandle)) + { + metaDataSearchHandler.Remove(mdhandle); + } + FindCloseMetadata_(mdhandle); + } + + /// + /// This dictionary links FIMETADATA handles and FREE_IMAGE_MDMODEL models. + /// + private static Dictionary metaDataSearchHandler + = new Dictionary(1); + + #endregion + + #region Rotation and Flipping + + /// + /// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. + /// 1-bit images rotation is limited to integer multiple of 90�. + /// null is returned for other values. + /// + /// Handle to a FreeImage bitmap. + /// The angle of rotation. + /// Handle to a FreeImage bitmap. + public static FIBITMAP Rotate(FIBITMAP dib, double angle) + { + return Rotate(dib, angle, IntPtr.Zero); + } + + /// + /// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears. + /// 1-bit images rotation is limited to integer multiple of 90�. + /// null is returned for other values. + /// + /// The type of the color to use as background. + /// Handle to a FreeImage bitmap. + /// The angle of rotation. + /// The color used used to fill the bitmap's background. + /// Handle to a FreeImage bitmap. + public static FIBITMAP Rotate(FIBITMAP dib, double angle, T? backgroundColor) where T : struct + { + if (backgroundColor.HasValue) + { + GCHandle handle = new GCHandle(); + try + { + T[] buffer = new T[] { backgroundColor.Value }; + handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + return Rotate(dib, angle, handle.AddrOfPinnedObject()); + } + finally + { + if (handle.IsAllocated) + handle.Free(); + } + } + else + { + return Rotate(dib, angle, IntPtr.Zero); + } + } + + /// + /// Rotates a 4-bit color FreeImage bitmap. + /// Allowed values for are 90, 180 and 270. + /// In case is 0 or 360 a clone is returned. + /// 0 is returned for other values or in case the rotation fails. + /// + /// Handle to a FreeImage bitmap. + /// The angle of rotation. + /// Handle to a FreeImage bitmap. + /// + /// This function is kind of temporary due to FreeImage's lack of + /// rotating 4-bit images. It's particularly used by 's + /// method RotateFlip. This function will be removed as soon as FreeImage + /// supports rotating 4-bit images. + /// + /// + /// is null. + public static unsafe FIBITMAP Rotate4bit(FIBITMAP dib, double angle) + { + if (dib.IsNull) + { + throw new ArgumentNullException("dib"); + } + + FIBITMAP result = new FIBITMAP(); + int ang = (int)angle; + + if ((GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) && + (GetBPP(dib) == 4) && + ((ang % 90) == 0)) + { + int width, height, xOrg, yOrg; + Scanline[] src, dst; + width = (int)GetWidth(dib); + height = (int)GetHeight(dib); + byte index = 0; + switch (ang) + { + case 90: + result = Allocate(height, width, 4, 0, 0, 0); + if (result.IsNull) + { + break; + } + CopyPalette(dib, result); + src = Get04BitScanlines(dib); + dst = Get04BitScanlines(result); + for (int y = 0; y < width; y++) + { + yOrg = height - 1; + for (int x = 0; x < height; x++, yOrg--) + { + index = src[yOrg][y]; + dst[y][x] = index; + } + } + break; + case 180: + result = Allocate(width, height, 4, 0, 0, 0); + if (result.IsNull) + { + break; + } + CopyPalette(dib, result); + src = Get04BitScanlines(dib); + dst = Get04BitScanlines(result); + + yOrg = height - 1; + for (int y = 0; y < height; y++, yOrg--) + { + xOrg = width - 1; + for (int x = 0; x < width; x++, xOrg--) + { + index = src[yOrg][xOrg]; + dst[y][x] = index; + } + } + break; + case 270: + result = Allocate(height, width, 4, 0, 0, 0); + if (result.IsNull) + { + break; + } + CopyPalette(dib, result); + src = Get04BitScanlines(dib); + dst = Get04BitScanlines(result); + xOrg = width - 1; + for (int y = 0; y < width; y++, xOrg--) + { + for (int x = 0; x < height; x++) + { + index = src[x][xOrg]; + dst[y][x] = index; + } + } + break; + case 0: + case 360: + result = Clone(dib); + break; + } + } + return result; + } + + #endregion + + #region Upsampling / downsampling + + /// + /// Enlarges or shrinks the FreeImage bitmap selectively per side and fills newly added areas + /// with the specified background color. See remarks for further details. + /// + /// The type of the specified color. + /// Handle to a FreeImage bitmap. + /// The number of pixels, the image should be enlarged on its left side. + /// Negative values shrink the image on its left side. + /// The number of pixels, the image should be enlarged on its top side. + /// Negative values shrink the image on its top side. + /// The number of pixels, the image should be enlarged on its right side. + /// Negative values shrink the image on its right side. + /// The number of pixels, the image should be enlarged on its bottom side. + /// Negative values shrink the image on its bottom side. + /// The color, the enlarged sides of the image should be filled with. + /// Options that affect the color search process for palletized images. + /// Handle to a FreeImage bitmap. + /// + /// This function enlarges or shrinks an image selectively per side. + /// The main purpose of this function is to add borders to an image. + /// To add a border to any of the image's sides, a positive integer value must be passed in + /// any of the parameters , , + /// or . This value represents the border's + /// width in pixels. Newly created parts of the image (the border areas) are filled with the + /// specified . + /// Specifying a negative integer value for a certain side, will shrink or crop the image on + /// this side. Consequently, specifying zero for a certain side will not change the image's + /// extension on that side. + /// + /// So, calling this function with all parameters , , + /// and set to zero, is + /// effectively the same as calling function ; setting all parameters + /// , , and + /// to value equal to or smaller than zero, my easily be substituted + /// by a call to function . Both these cases produce a new image, which is + /// guaranteed not to be larger than the input image. Thus, since the specified + /// is not needed in these cases, + /// may be null. + /// + /// Both parameters and work according to + /// function . So, please refer to the documentation of + /// to learn more about parameters + /// and . For palletized images, the palette of the input image is + /// transparently copied to the newly created enlarged or shrunken image, so any color look-ups + /// are performed on this palette. + /// + /// + /// // create a white color
    + /// RGBQUAD c;
    + /// c.rgbRed = 0xFF;
    + /// c.rgbGreen = 0xFF;
    + /// c.rgbBlue = 0xFF;
    + /// c.rgbReserved = 0x00;
    + ///
    + /// // add a white, symmetric 10 pixel wide border to the image
    + /// dib2 = FreeImage_EnlargeCanvas(dib, 10, 10, 10, 10, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);
    + ///
    + /// // add white, 20 pixel wide stripes to the top and bottom side of the image
    + /// dib3 = FreeImage_EnlargeCanvas(dib, 0, 20, 0, 20, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);
    + ///
    + /// // add white, 30 pixel wide stripes to the right side of the image and
    + /// // cut off the 40 leftmost pixel columns
    + /// dib3 = FreeImage_EnlargeCanvas(dib, -40, 0, 30, 0, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);
    + ///
    + public static FIBITMAP EnlargeCanvas(FIBITMAP dib, int left, int top, int right, int bottom, + T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct + { + if (dib.IsNull) + return FIBITMAP.Zero; + + if (!CheckColorType(GetImageType(dib), color)) + return FIBITMAP.Zero; + + if (color.HasValue) + { + GCHandle handle = new GCHandle(); + try + { + T[] buffer = new T[] { color.Value }; + handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + return EnlargeCanvas(dib, left, top, right, bottom, handle.AddrOfPinnedObject(), options); + } + finally + { + if (handle.IsAllocated) + handle.Free(); + } + } + else + { + return EnlargeCanvas(dib, left, top, right, bottom, IntPtr.Zero, options); + } + } + + #endregion + + #region Color + + /// + /// Sets all pixels of the specified image to the color provided through the + /// parameter. See remarks for further details. + /// + /// The type of the specified color. + /// Handle to a FreeImage bitmap. + /// The color to fill the bitmap with. See remarks for further details. + /// Options that affect the color search process for palletized images. + /// true on success, false on failure. + /// + /// This function sets all pixels of an image to the color provided through + /// the parameter. is used for standard type images. + /// For non standard type images the underlaying structure is used. + /// + /// So, must be of type , if the image to be filled is of type + /// and must be a structure if the + /// image is of type and so on. + /// + /// However, the fill color is always specified through a structure + /// for all images of type . + /// So, for 32- and 24-bit images, the red, green and blue members of the + /// structure are directly used for the image's red, green and blue channel respectively. + /// Although alpha transparent colors are + /// supported, the alpha channel of a 32-bit image never gets modified by this function. + /// A fill color with an alpha value smaller than 255 gets blended with the image's actual + /// background color, which is determined from the image's bottom-left pixel. + /// So, currently using alpha enabled colors, assumes the image to be unicolor before the + /// fill operation. However, the field is only taken into account, + /// if option has been specified. + /// + /// For 16-bit images, the red-, green- and blue components of the specified color are + /// transparently translated into either the 16-bit 555 or 565 representation. This depends + /// on the image's actual red- green- and blue masks. + /// + /// Special attention must be payed for palletized images. Generally, the RGB color specified + /// is looked up in the image's palette. The found palette index is then used to fill the image. + /// There are some option flags, that affect this lookup process: + /// + /// + /// Value + /// Meaning + /// + /// + /// + /// + /// Uses the color, that is nearest to the specified color. + /// This is the default behavior and should always find a + /// color in the palette. However, the visual result may + /// far from what was expected and mainly depends on the + /// image's palette. + /// + /// + /// + /// + /// + /// Searches the image's palette for the specified color + /// but only uses the returned palette index, if the specified + /// color exactly matches the palette entry. Of course, + /// depending on the image's actual palette entries, this + /// operation may fail. In this case, the function falls back + /// to option + /// and uses the RGBQUAD's rgbReserved member (or its low nibble for 4-bit images + /// or its least significant bit (LSB) for 1-bit images) as + /// the palette index used for the fill operation. + /// + /// + /// + /// + /// + /// Does not perform any color lookup from the palette, but + /// uses the RGBQUAD's alpha channel member rgbReserved as + /// the palette index to be used for the fill operation. + /// However, for 4-bit images, only the low nibble of the + /// rgbReserved member are used and for 1-bit images, only + /// the least significant bit (LSB) is used. + /// + /// + /// + /// + public static bool FillBackground(FIBITMAP dib, T color, FREE_IMAGE_COLOR_OPTIONS options) + where T : struct + { + if (dib.IsNull) + return false; + + if (!CheckColorType(GetImageType(dib), color)) + return false; + + GCHandle handle = new GCHandle(); + try + { + T[] buffer = new T[] { color }; + handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + return FillBackground(dib, handle.AddrOfPinnedObject(), options); + } + finally + { + if (handle.IsAllocated) + handle.Free(); + } + } + + #endregion + + #region Wrapper functions + + /// + /// Returns the next higher possible color depth. + /// + /// Color depth to increase. + /// The next higher color depth or 0 if there is no valid color depth. + internal static int GetNextColorDepth(int bpp) + { + int result = 0; + switch (bpp) + { + case 1: + result = 4; + break; + case 4: + result = 8; + break; + case 8: + result = 16; + break; + case 16: + result = 24; + break; + case 24: + result = 32; + break; + } + return result; + } + + /// + /// Returns the next lower possible color depth. + /// + /// Color depth to decrease. + /// The next lower color depth or 0 if there is no valid color depth. + internal static int GetPrevousColorDepth(int bpp) + { + int result = 0; + switch (bpp) + { + case 32: + result = 24; + break; + case 24: + result = 16; + break; + case 16: + result = 8; + break; + case 8: + result = 4; + break; + case 4: + result = 1; + break; + } + return result; + } + + /// + /// Reads a null-terminated c-string. + /// + /// Pointer to the first char of the string. + /// The converted string. + internal static unsafe string PtrToStr(byte* ptr) + { + string result = null; + if (ptr != null) + { + System.Text.StringBuilder sb = new System.Text.StringBuilder(); + + while (*ptr != 0) + { + sb.Append((char)(*(ptr++))); + } + result = sb.ToString(); + } + return result; + } + + internal static unsafe byte[] CreateShrunkenPaletteLUT(FIBITMAP dib, out int uniqueColors) + { + byte[] result = null; + uniqueColors = 0; + + if ((!dib.IsNull) && (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) && (GetBPP(dib) <= 8)) + { + int size = (int)GetColorsUsed(dib); + List newPalette = new List(size); + List lut = new List(size); + RGBQUAD* palette = (RGBQUAD*)GetPalette(dib); + RGBQUAD color; + int index; + + for (int i = 0; i < size; i++) + { + color = palette[i]; + color.rgbReserved = 255; // ignore alpha + + index = newPalette.IndexOf(color); + if (index < 0) + { + newPalette.Add(color); + lut.Add((byte)(newPalette.Count - 1)); + } + else + { + lut.Add((byte)index); + } + } + result = lut.ToArray(); + uniqueColors = newPalette.Count; + } + return result; + } + + internal static PropertyItem CreatePropertyItem() + { + return (PropertyItem)Activator.CreateInstance(typeof(PropertyItem), true); + } + + private static unsafe void CopyPalette(FIBITMAP src, FIBITMAP dst) + { + RGBQUAD* orgPal = (RGBQUAD*)GetPalette(src); + RGBQUAD* newPal = (RGBQUAD*)GetPalette(dst); + uint size = (uint)(sizeof(RGBQUAD) * GetColorsUsed(src)); + CopyMemory(newPal, orgPal, size); + } + + private static unsafe Scanline[] Get04BitScanlines(FIBITMAP dib) + { + int height = (int)GetHeight(dib); + Scanline[] array = new Scanline[height]; + for (int i = 0; i < height; i++) + { + array[i] = new Scanline(dib, i); + } + return array; + } + + /// + /// Changes a bitmaps color depth. + /// Used by SaveEx and SaveToStream. + /// + private static FIBITMAP PrepareBitmapColorDepth(FIBITMAP dibToSave, FREE_IMAGE_FORMAT format, FREE_IMAGE_COLOR_DEPTH colorDepth) + { + FREE_IMAGE_TYPE type = GetImageType(dibToSave); + if (type == FREE_IMAGE_TYPE.FIT_BITMAP) + { + int bpp = (int)GetBPP(dibToSave); + int targetBpp = (int)(colorDepth & FREE_IMAGE_COLOR_DEPTH.FICD_COLOR_MASK); + + if (colorDepth != FREE_IMAGE_COLOR_DEPTH.FICD_AUTO) + { + // A fix colordepth was chosen + if (FIFSupportsExportBPP(format, targetBpp)) + { + dibToSave = ConvertColorDepth(dibToSave, colorDepth, false); + } + else + { + throw new ArgumentException("FreeImage\n\nFreeImage Library plugin " + + GetFormatFromFIF(format) + " is unable to write images with a color depth of " + + targetBpp + " bpp."); + } + } + else + { + // Auto selection was chosen + if (!FIFSupportsExportBPP(format, bpp)) + { + // The color depth is not supported + int bppUpper = bpp; + int bppLower = bpp; + // Check from the bitmaps current color depth in both directions + do + { + bppUpper = GetNextColorDepth(bppUpper); + if (FIFSupportsExportBPP(format, bppUpper)) + { + dibToSave = ConvertColorDepth(dibToSave, (FREE_IMAGE_COLOR_DEPTH)bppUpper, false); + break; + } + bppLower = GetPrevousColorDepth(bppLower); + if (FIFSupportsExportBPP(format, bppLower)) + { + dibToSave = ConvertColorDepth(dibToSave, (FREE_IMAGE_COLOR_DEPTH)bppLower, false); + break; + } + } while (!((bppLower == 0) && (bppUpper == 0))); + } + } + } + return dibToSave; + } + + /// + /// Compares blocks of memory. + /// + /// A pointer to a block of memory to compare. + /// A pointer to a block of memory to compare. + /// Specifies the number of bytes to be compared. + /// true, if all bytes compare as equal, false otherwise. + public static unsafe bool CompareMemory(void* buf1, void* buf2, uint length) + { + return (length == RtlCompareMemory(buf1, buf2, length)); + } + + /// + /// Compares blocks of memory. + /// + /// A pointer to a block of memory to compare. + /// A pointer to a block of memory to compare. + /// Specifies the number of bytes to be compared. + /// true, if all bytes compare as equal, false otherwise. + public static unsafe bool CompareMemory(void* buf1, void* buf2, long length) + { + return (length == RtlCompareMemory(buf1, buf2, checked((uint)length))); + } + + /// + /// Compares blocks of memory. + /// + /// A pointer to a block of memory to compare. + /// A pointer to a block of memory to compare. + /// Specifies the number of bytes to be compared. + /// true, if all bytes compare as equal, false otherwise. + public static unsafe bool CompareMemory(IntPtr buf1, IntPtr buf2, uint length) + { + return (length == RtlCompareMemory(buf1.ToPointer(), buf2.ToPointer(), length)); + } + + /// + /// Compares blocks of memory. + /// + /// A pointer to a block of memory to compare. + /// A pointer to a block of memory to compare. + /// Specifies the number of bytes to be compared. + /// true, if all bytes compare as equal, false otherwise. + public static unsafe bool CompareMemory(IntPtr buf1, IntPtr buf2, long length) + { + return (length == RtlCompareMemory(buf1.ToPointer(), buf2.ToPointer(), checked((uint)length))); + } + + /// + /// Moves a block of memory from one location to another. + /// + /// A pointer to the starting address of the move destination. + /// A pointer to the starting address of the block of memory to be moved. + /// The size of the block of memory to move, in bytes. + public static unsafe void MoveMemory(void* dst, void* src, long size) + { + MoveMemory(dst, src, checked((uint)size)); + } + + /// + /// Moves a block of memory from one location to another. + /// + /// A pointer to the starting address of the move destination. + /// A pointer to the starting address of the block of memory to be moved. + /// The size of the block of memory to move, in bytes. + public static unsafe void MoveMemory(IntPtr dst, IntPtr src, uint size) + { + MoveMemory(dst.ToPointer(), src.ToPointer(), size); + } + + /// + /// Moves a block of memory from one location to another. + /// + /// A pointer to the starting address of the move destination. + /// A pointer to the starting address of the block of memory to be moved. + /// The size of the block of memory to move, in bytes. + public static unsafe void MoveMemory(IntPtr dst, IntPtr src, long size) + { + MoveMemory(dst.ToPointer(), src.ToPointer(), checked((uint)size)); + } + + /// + /// Copies a block of memory from one location to another. + /// + /// A pointer to the starting address of the copied block's destination. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + /// + /// CopyMemory runs faster than . + /// However, if both blocks overlap the result is undefined. + /// + public static unsafe void CopyMemory(byte* dest, byte* src, int len) + { + if (len >= 0x10) + { + do + { + *((int*)dest) = *((int*)src); + *((int*)(dest + 4)) = *((int*)(src + 4)); + *((int*)(dest + 8)) = *((int*)(src + 8)); + *((int*)(dest + 12)) = *((int*)(src + 12)); + dest += 0x10; + src += 0x10; + } + while ((len -= 0x10) >= 0x10); + } + if (len > 0) + { + if ((len & 8) != 0) + { + *((int*)dest) = *((int*)src); + *((int*)(dest + 4)) = *((int*)(src + 4)); + dest += 8; + src += 8; + } + if ((len & 4) != 0) + { + *((int*)dest) = *((int*)src); + dest += 4; + src += 4; + } + if ((len & 2) != 0) + { + *((short*)dest) = *((short*)src); + dest += 2; + src += 2; + } + if ((len & 1) != 0) + { + *dest = *src; + } + } + } + + /// + /// Copies a block of memory from one location to another. + /// + /// A pointer to the starting address of the copied block's destination. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + /// + /// CopyMemory runs faster than . + /// However, if both blocks overlap the result is undefined. + /// + public static unsafe void CopyMemory(byte* dest, byte* src, long len) + { + CopyMemory(dest, src, checked((int)len)); + } + + /// + /// Copies a block of memory from one location to another. + /// + /// A pointer to the starting address of the copied block's destination. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + /// + /// CopyMemory runs faster than . + /// However, if both blocks overlap the result is undefined. + /// + public static unsafe void CopyMemory(void* dest, void* src, long len) + { + CopyMemory((byte*)dest, (byte*)src, checked((int)len)); + } + + /// + /// Copies a block of memory from one location to another. + /// + /// A pointer to the starting address of the copied block's destination. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + /// + /// CopyMemory runs faster than . + /// However, if both blocks overlap the result is undefined. + /// + public static unsafe void CopyMemory(void* dest, void* src, int len) + { + CopyMemory((byte*)dest, (byte*)src, len); + } + + /// + /// Copies a block of memory from one location to another. + /// + /// A pointer to the starting address of the copied block's destination. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + /// + /// CopyMemory runs faster than . + /// However, if both blocks overlap the result is undefined. + /// + public static unsafe void CopyMemory(IntPtr dest, IntPtr src, int len) + { + CopyMemory((byte*)dest, (byte*)src, len); + } + + /// + /// Copies a block of memory from one location to another. + /// + /// A pointer to the starting address of the copied block's destination. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + /// + /// CopyMemory runs faster than . + /// However, if both blocks overlap the result is undefined. + /// + public static unsafe void CopyMemory(IntPtr dest, IntPtr src, long len) + { + CopyMemory((byte*)dest, (byte*)src, checked((int)len)); + } + + /// + /// Copies a block of memory into an array. + /// + /// An array used as the destination of the copy process. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(Array dest, void* src, int len) + { + GCHandle handle = GCHandle.Alloc(dest, GCHandleType.Pinned); + try + { + CopyMemory((byte*)handle.AddrOfPinnedObject(), (byte*)src, len); + } + finally + { + handle.Free(); + } + } + + /// + /// Copies a block of memory into an array. + /// + /// An array used as the destination of the copy process. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(Array dest, void* src, long len) + { + CopyMemory(dest, (byte*)src, checked((int)len)); + } + + /// + /// Copies a block of memory into an array. + /// + /// An array used as the destination of the copy process. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(Array dest, IntPtr src, int len) + { + CopyMemory(dest, (byte*)src, len); + } + + /// + /// Copies a block of memory into an array. + /// + /// An array used as the destination of the copy process. + /// A pointer to the starting address of the block of memory to copy. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(Array dest, IntPtr src, long len) + { + CopyMemory(dest, (byte*)src, checked((int)len)); + } + + /// + /// Copies the content of an array to a memory location. + /// + /// A pointer to the starting address of the copied block's destination. + /// An array used as the source of the copy process. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(void* dest, Array src, int len) + { + GCHandle handle = GCHandle.Alloc(src, GCHandleType.Pinned); + try + { + CopyMemory((byte*)dest, (byte*)handle.AddrOfPinnedObject(), len); + } + finally + { + handle.Free(); + } + } + + /// + /// Copies the content of an array to a memory location. + /// + /// A pointer to the starting address of the copied block's destination. + /// An array used as the source of the copy process. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(void* dest, Array src, long len) + { + CopyMemory((byte*)dest, src, checked((int)len)); + } + + /// + /// Copies the content of an array to a memory location. + /// + /// A pointer to the starting address of the copied block's destination. + /// An array used as the source of the copy process. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(IntPtr dest, Array src, int len) + { + CopyMemory((byte*)dest, src, len); + } + + /// + /// Copies the content of an array to a memory location. + /// + /// A pointer to the starting address of the copied block's destination. + /// An array used as the source of the copy process. + /// The size of the block of memory to copy, in bytes. + public static unsafe void CopyMemory(IntPtr dest, Array src, long len) + { + CopyMemory((byte*)dest, src, checked((int)len)); + } + + /// + /// Copies the content of one array into another array. + /// + /// An array used as the destination of the copy process. + /// An array used as the source of the copy process. + /// The size of the content to copy, in bytes. + public static unsafe void CopyMemory(Array dest, Array src, int len) + { + GCHandle dHandle = GCHandle.Alloc(dest, GCHandleType.Pinned); + try + { + GCHandle sHandle = GCHandle.Alloc(src, GCHandleType.Pinned); + try + { + CopyMemory((byte*)dHandle.AddrOfPinnedObject(), (byte*)sHandle.AddrOfPinnedObject(), len); + } + finally + { + sHandle.Free(); + } + } + finally + { + dHandle.Free(); + } + } + + /// + /// Copies the content of one array into another array. + /// + /// An array used as the destination of the copy process. + /// An array used as the source of the copy process. + /// The size of the content to copy, in bytes. + public static unsafe void CopyMemory(Array dest, Array src, long len) + { + CopyMemory(dest, src, checked((int)len)); + } + + internal static string ColorToString(Color color) + { + return string.Format( + System.Globalization.CultureInfo.CurrentCulture, + "{{Name={0}, ARGB=({1}, {2}, {3}, {4})}}", + new object[] { color.Name, color.A, color.R, color.G, color.B }); + } + + internal static void Resize(ref string str, int length) + { + if ((str != null) && (length >= 0) && (str.Length != length)) + { + char[] chars = str.ToCharArray(); + Array.Resize(ref chars, length); + str = new string(chars); + } + } + + internal static void Resize(ref string str, int min, int max) + { + if ((str != null) && (min >= 0) && (max >= 0) && (min <= max)) + { + if (str.Length < min) + { + char[] chars = str.ToCharArray(); + Array.Resize(ref chars, min); + str = new string(chars); + } + else if (str.Length > max) + { + char[] chars = str.ToCharArray(); + Array.Resize(ref chars, max); + str = new string(chars); + } + } + } + + internal static void Resize(ref T[] array, int length) + { + if ((array != null) && (length >= 0) && (array.Length != length)) + { + Array.Resize(ref array, length); + } + } + + internal static void Resize(ref T[] array, int min, int max) + { + if ((array != null) && (min >= 0) && (max >= 0) && (min <= max)) + { + if (array.Length < min) + { + Array.Resize(ref array, min); + } + else if (array.Length > max) + { + Array.Resize(ref array, max); + } + } + } + + internal static bool CheckColorType(FREE_IMAGE_TYPE imageType, T color) + { + Type type = typeof(T); + bool result; + switch (imageType) + { + case FREE_IMAGE_TYPE.FIT_BITMAP: + result = (type == typeof(RGBQUAD)); break; + case FREE_IMAGE_TYPE.FIT_COMPLEX: + result = (type == typeof(FICOMPLEX)); break; + case FREE_IMAGE_TYPE.FIT_DOUBLE: + result = (type == typeof(double)); break; + case FREE_IMAGE_TYPE.FIT_FLOAT: + result = (type == typeof(float)); break; + case FREE_IMAGE_TYPE.FIT_INT16: + result = (type == typeof(Int16)); break; + case FREE_IMAGE_TYPE.FIT_INT32: + result = (type == typeof(Int32)); break; + case FREE_IMAGE_TYPE.FIT_RGB16: + result = (type == typeof(FIRGB16)); break; + case FREE_IMAGE_TYPE.FIT_RGBA16: + result = (type == typeof(FIRGBA16)); break; + case FREE_IMAGE_TYPE.FIT_RGBAF: + result = (type == typeof(FIRGBAF)); break; + case FREE_IMAGE_TYPE.FIT_RGBF: + result = (type == typeof(FIRGBF)); break; + case FREE_IMAGE_TYPE.FIT_UINT16: + result = (type == typeof(UInt16)); break; + case FREE_IMAGE_TYPE.FIT_UINT32: + result = (type == typeof(UInt32)); break; + default: + result = false; break; + } + return result; + } + + #endregion + + #region Dll-Imports + + /// + /// Retrieves a handle to a display device context (DC) for the client area of a specified window + /// or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC. + /// + /// Handle to the window whose DC is to be retrieved. + /// If this value is IntPtr.Zero, GetDC retrieves the DC for the entire screen. + /// If the function succeeds, the return value is a handle to the DC for the specified window's client area. + /// If the function fails, the return value is NULL. + [DllImport("user32.dll")] + private static extern IntPtr GetDC(IntPtr hWnd); + + /// + /// Releases a device context (DC), freeing it for use by other applications. + /// The effect of the ReleaseDC function depends on the type of DC. It frees only common and window DCs. + /// It has no effect on class or private DCs. + /// + /// Handle to the window whose DC is to be released. + /// Handle to the DC to be released. + /// Returns true on success, false on failure. + [DllImport("user32.dll")] + private static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC); + + /// + /// Creates a DIB that applications can write to directly. + /// The function gives you a pointer to the location of the bitmap bit values. + /// You can supply a handle to a file-mapping object that the function will use to create the bitmap, + /// or you can let the system allocate the memory for the bitmap. + /// + /// Handle to a device context. + /// Pointer to a BITMAPINFO structure that specifies various attributes of the DIB, + /// including the bitmap dimensions and colors. + /// Specifies the type of data contained in the bmiColors array member of the BITMAPINFO structure + /// pointed to by pbmi (either logical palette indexes or literal RGB values). + /// Pointer to a variable that receives a pointer to the location of the DIB bit values. + /// Handle to a file-mapping object that the function will use to create the DIB. + /// This parameter can be NULL. + /// Specifies the offset from the beginning of the file-mapping object referenced by hSection + /// where storage for the bitmap bit values is to begin. This value is ignored if hSection is NULL. + /// If the function succeeds, the return value is a handle to the newly created DIB, + /// and *ppvBits points to the bitmap bit values. If the function fails, the return value is NULL, and *ppvBits is NULL. + [DllImport("gdi32.dll")] + private static extern IntPtr CreateDIBSection( + IntPtr hdc, + [In] IntPtr pbmi, + uint iUsage, + out IntPtr ppvBits, + IntPtr hSection, + uint dwOffset); + + /// + /// Deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object. + /// After the object is deleted, the specified handle is no longer valid. + /// + /// Handle to a logical pen, brush, font, bitmap, region, or palette. + /// Returns true on success, false on failure. + [DllImport("gdi32.dll")] + private static extern bool DeleteObject(IntPtr hObject); + + /// + /// Creates a compatible bitmap (DDB) from a DIB and, optionally, sets the bitmap bits. + /// + /// Handle to a device context. + /// Pointer to a bitmap information header structure. + /// Specifies how the system initializes the bitmap bits - (use 4). + /// Pointer to an array of bytes containing the initial bitmap data. + /// Pointer to a BITMAPINFO structure that describes the dimensions + /// and color format of the array pointed to by the lpbInit parameter. + /// Specifies whether the bmiColors member of the BITMAPINFO structure + /// was initialized - (use 0). + /// Handle to a DIB or null on failure. + [DllImport("gdi32.dll")] + private static extern IntPtr CreateDIBitmap( + IntPtr hdc, + IntPtr lpbmih, + uint fdwInit, + IntPtr lpbInit, + IntPtr lpbmi, + uint fuUsage); + + /// + /// Retrieves information for the specified graphics object. + /// + /// Handle to the graphics object of interest. + /// Specifies the number of bytes of information to + /// be written to the buffer. + /// Pointer to a buffer that receives the information + /// about the specified graphics object. + /// 0 on failure. + [DllImport("gdi32.dll")] + private static extern int GetObject(IntPtr hgdiobj, int cbBuffer, IntPtr lpvObject); + + /// + /// Retrieves the bits of the specified compatible bitmap and copies them into a buffer + /// as a DIB using the specified format. + /// + /// Handle to the device context. + /// Handle to the bitmap. This must be a compatible bitmap (DDB). + /// Specifies the first scan line to retrieve. + /// Specifies the number of scan lines to retrieve. + /// Pointer to a buffer to receive the bitmap data. + /// Pointer to a BITMAPINFO structure that specifies the desired + /// format for the DIB data. + /// Specifies the format of the bmiColors member of the + /// BITMAPINFO structure - (use 0). + /// 0 on failure. + [DllImport("gdi32.dll")] + private static extern unsafe int GetDIBits( + IntPtr hdc, + IntPtr hbmp, + uint uStartScan, + uint cScanLines, + IntPtr lpvBits, + IntPtr lpbmi, + uint uUsage); + + /// + /// Moves a block of memory from one location to another. + /// + /// Pointer to the starting address of the move destination. + /// Pointer to the starting address of the block of memory to be moved. + /// Size of the block of memory to move, in bytes. + [DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false)] + public static unsafe extern void MoveMemory(void* dst, void* src, uint size); + + /// + /// The RtlCompareMemory routine compares blocks of memory + /// and returns the number of bytes that are equivalent. + /// + /// A pointer to a block of memory to compare. + /// A pointer to a block of memory to compare. + /// Specifies the number of bytes to be compared. + /// RtlCompareMemory returns the number of bytes that compare as equal. + /// If all bytes compare as equal, the input Length is returned. + [DllImport("ntdll.dll", EntryPoint = "RtlCompareMemory", SetLastError = false)] + internal static unsafe extern uint RtlCompareMemory(void* buf1, void* buf2, uint count); + + #endregion + } +} diff --git a/Wrapper/FreeImage.NET/cs/UnitTest/ImageManager.cs b/Wrapper/FreeImage.NET/cs/UnitTest/ImageManager.cs index 83f4be4..b554473 100644 --- a/Wrapper/FreeImage.NET/cs/UnitTest/ImageManager.cs +++ b/Wrapper/FreeImage.NET/cs/UnitTest/ImageManager.cs @@ -1,156 +1,156 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.IO; - -namespace FreeImageNETUnitTest -{ - internal enum ImageType : byte - { - Even, - Odd, - JPEG, - Metadata, - Multipaged - } - - internal enum ImageColorType : byte - { - Type_01_Dither, - Type_01_Threshold, - Type_04, - Type_04_Greyscale_MinIsBlack, - Type_04_Greyscale_Unordered, - Type_08, - Type_08_Greyscale_MinIsBlack, - Type_08_Greyscale_Unordered, - Type_16_555, - Type_16_565, - Type_24, - Type_32, - } - - internal class ImageManager - { - public readonly string baseDirectory = null; - - public ImageManager() - : this(new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.Parent.FullName + @"\UnitTestData\Images\") - { - } - - public ImageManager(string baseDirectory) - { - if (!Directory.Exists(baseDirectory)) - throw new DirectoryNotFoundException(); - this.baseDirectory = baseDirectory; - } - - public string GetBitmapPath(ImageType type, ImageColorType colorType) - { - string filename = null; - - switch (type) - { - case ImageType.Even: - switch (colorType) - { - case ImageColorType.Type_01_Dither: - filename = baseDirectory + @"Even\Image_01_dither.tif"; - break; - case ImageColorType.Type_01_Threshold: - filename = baseDirectory + @"Even\Image_01_threshold.tif"; - break; - case ImageColorType.Type_04: - filename = baseDirectory + @"Even\Image_04.tif"; - break; - case ImageColorType.Type_04_Greyscale_MinIsBlack: - filename = baseDirectory + @"Even\Image_04_gs_minisblack.tif"; - break; - case ImageColorType.Type_04_Greyscale_Unordered: - filename = baseDirectory + @"Even\Image_04_gs_unordered.tif"; - break; - case ImageColorType.Type_08: - filename = baseDirectory + @"Even\Image_08.tif"; - break; - case ImageColorType.Type_08_Greyscale_MinIsBlack: - filename = baseDirectory + @"Even\Image_08_gs_minisblack.tif"; - break; - case ImageColorType.Type_08_Greyscale_Unordered: - filename = baseDirectory + @"Even\Image_08_gs_unordered.tif"; - break; - case ImageColorType.Type_16_555: - filename = baseDirectory + @"Even\Image_16_555.bmp"; - break; - case ImageColorType.Type_16_565: - filename = baseDirectory + @"Even\Image_16_565.bmp"; - break; - case ImageColorType.Type_24: - filename = baseDirectory + @"Even\Image_24.tif"; - break; - case ImageColorType.Type_32: - filename = baseDirectory + @"Even\Image_32.tif"; - break; - } - break; - case ImageType.Odd: - switch (colorType) - { - case ImageColorType.Type_01_Dither: - filename = baseDirectory + @"Odd\Image_01_dither.tif"; - break; - case ImageColorType.Type_01_Threshold: - filename = baseDirectory + @"Odd\Image_01_threshold.tif"; - break; - case ImageColorType.Type_04: - filename = baseDirectory + @"Odd\Image_04.tif"; - break; - case ImageColorType.Type_04_Greyscale_MinIsBlack: - filename = baseDirectory + @"Odd\Image_04_gs_minisblack.tif"; - break; - case ImageColorType.Type_04_Greyscale_Unordered: - filename = baseDirectory + @"Odd\Image_04_gs_unordered.tif"; - break; - case ImageColorType.Type_08: - filename = baseDirectory + @"Odd\Image_08.tif"; - break; - case ImageColorType.Type_08_Greyscale_MinIsBlack: - filename = baseDirectory + @"Odd\Image_08_gs_minisblack.tif"; - break; - case ImageColorType.Type_08_Greyscale_Unordered: - filename = baseDirectory + @"Odd\Image_08_gs_unordered.tif"; - break; - case ImageColorType.Type_16_555: - filename = baseDirectory + @"Odd\Image_16_555.bmp"; - break; - case ImageColorType.Type_16_565: - filename = baseDirectory + @"Odd\Image_16_565.bmp"; - break; - case ImageColorType.Type_24: - filename = baseDirectory + @"Odd\Image_24.tif"; - break; - } - break; - case ImageType.JPEG: - filename = baseDirectory + @"JPEG\Image.jpg"; - break; - case ImageType.Metadata: - filename = baseDirectory + @"Metadata\exif.jpg"; - break; - case ImageType.Multipaged: - filename = baseDirectory + @"Multipaged\Image.tif"; - break; - } - return filename; - } - - public FreeImageAPI.FIBITMAP GetBitmap(ImageType type, ImageColorType colorType) - { - FreeImageAPI.FIBITMAP result = new FreeImageAPI.FIBITMAP(); - string filename = GetBitmapPath(type, colorType); - if (!String.IsNullOrEmpty(filename) && File.Exists(filename)) - result = FreeImageAPI.FreeImage.LoadEx(filename); - return result; - } - } +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace FreeImageNETUnitTest +{ + internal enum ImageType : byte + { + Even, + Odd, + JPEG, + Metadata, + Multipaged + } + + internal enum ImageColorType : byte + { + Type_01_Dither, + Type_01_Threshold, + Type_04, + Type_04_Greyscale_MinIsBlack, + Type_04_Greyscale_Unordered, + Type_08, + Type_08_Greyscale_MinIsBlack, + Type_08_Greyscale_Unordered, + Type_16_555, + Type_16_565, + Type_24, + Type_32, + } + + internal class ImageManager + { + public readonly string baseDirectory = null; + + public ImageManager() + : this(new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.Parent.FullName + @"\UnitTestData\Images\") + { + } + + public ImageManager(string baseDirectory) + { + if (!Directory.Exists(baseDirectory)) + throw new DirectoryNotFoundException(); + this.baseDirectory = baseDirectory; + } + + public string GetBitmapPath(ImageType type, ImageColorType colorType) + { + string filename = null; + + switch (type) + { + case ImageType.Even: + switch (colorType) + { + case ImageColorType.Type_01_Dither: + filename = baseDirectory + @"Even\Image_01_dither.tif"; + break; + case ImageColorType.Type_01_Threshold: + filename = baseDirectory + @"Even\Image_01_threshold.tif"; + break; + case ImageColorType.Type_04: + filename = baseDirectory + @"Even\Image_04.tif"; + break; + case ImageColorType.Type_04_Greyscale_MinIsBlack: + filename = baseDirectory + @"Even\Image_04_gs_minisblack.tif"; + break; + case ImageColorType.Type_04_Greyscale_Unordered: + filename = baseDirectory + @"Even\Image_04_gs_unordered.tif"; + break; + case ImageColorType.Type_08: + filename = baseDirectory + @"Even\Image_08.tif"; + break; + case ImageColorType.Type_08_Greyscale_MinIsBlack: + filename = baseDirectory + @"Even\Image_08_gs_minisblack.tif"; + break; + case ImageColorType.Type_08_Greyscale_Unordered: + filename = baseDirectory + @"Even\Image_08_gs_unordered.tif"; + break; + case ImageColorType.Type_16_555: + filename = baseDirectory + @"Even\Image_16_555.bmp"; + break; + case ImageColorType.Type_16_565: + filename = baseDirectory + @"Even\Image_16_565.bmp"; + break; + case ImageColorType.Type_24: + filename = baseDirectory + @"Even\Image_24.tif"; + break; + case ImageColorType.Type_32: + filename = baseDirectory + @"Even\Image_32.tif"; + break; + } + break; + case ImageType.Odd: + switch (colorType) + { + case ImageColorType.Type_01_Dither: + filename = baseDirectory + @"Odd\Image_01_dither.tif"; + break; + case ImageColorType.Type_01_Threshold: + filename = baseDirectory + @"Odd\Image_01_threshold.tif"; + break; + case ImageColorType.Type_04: + filename = baseDirectory + @"Odd\Image_04.tif"; + break; + case ImageColorType.Type_04_Greyscale_MinIsBlack: + filename = baseDirectory + @"Odd\Image_04_gs_minisblack.tif"; + break; + case ImageColorType.Type_04_Greyscale_Unordered: + filename = baseDirectory + @"Odd\Image_04_gs_unordered.tif"; + break; + case ImageColorType.Type_08: + filename = baseDirectory + @"Odd\Image_08.tif"; + break; + case ImageColorType.Type_08_Greyscale_MinIsBlack: + filename = baseDirectory + @"Odd\Image_08_gs_minisblack.tif"; + break; + case ImageColorType.Type_08_Greyscale_Unordered: + filename = baseDirectory + @"Odd\Image_08_gs_unordered.tif"; + break; + case ImageColorType.Type_16_555: + filename = baseDirectory + @"Odd\Image_16_555.bmp"; + break; + case ImageColorType.Type_16_565: + filename = baseDirectory + @"Odd\Image_16_565.bmp"; + break; + case ImageColorType.Type_24: + filename = baseDirectory + @"Odd\Image_24.tif"; + break; + } + break; + case ImageType.JPEG: + filename = baseDirectory + @"JPEG\Image.jpg"; + break; + case ImageType.Metadata: + filename = baseDirectory + @"Metadata\exif.jpg"; + break; + case ImageType.Multipaged: + filename = baseDirectory + @"Multipaged\Image.tif"; + break; + } + return filename; + } + + public FreeImageAPI.FIBITMAP GetBitmap(ImageType type, ImageColorType colorType) + { + FreeImageAPI.FIBITMAP result = new FreeImageAPI.FIBITMAP(); + string filename = GetBitmapPath(type, colorType); + if (!String.IsNullOrEmpty(filename) && File.Exists(filename)) + result = FreeImageAPI.FreeImage.LoadEx(filename); + return result; + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/UnitTest/NUnit.txt b/Wrapper/FreeImage.NET/cs/UnitTest/NUnit.txt index ce0d58e..cca3df5 100644 --- a/Wrapper/FreeImage.NET/cs/UnitTest/NUnit.txt +++ b/Wrapper/FreeImage.NET/cs/UnitTest/NUnit.txt @@ -1,14 +1,14 @@ -NUnit 2.x is needed for FreeImage .NET wrapper unit tests. It can be -downloaded from http://www.nunit.org/ - -After installing NUnit, double click on the NUnit project file -FreeImage.NET.nunit located in the FreeImage .NET wrapper Source folder -to load the project. - -The FreeImage .NET wrapper unit test project UnitTest.csproj, located -under Source\UnitTest, must be compiled in 'Debug' mode prior to opening -the NUnit project. - -The FreeImage .NET wrapper unit test project UnitTest.csproj currently -relies on the FreeImage .NET wrapper single source file, created by the +NUnit 2.x is needed for FreeImage .NET wrapper unit tests. It can be +downloaded from http://www.nunit.org/ + +After installing NUnit, double click on the NUnit project file +FreeImage.NET.nunit located in the FreeImage .NET wrapper Source folder +to load the project. + +The FreeImage .NET wrapper unit test project UnitTest.csproj, located +under Source\UnitTest, must be compiled in 'Debug' mode prior to opening +the NUnit project. + +The FreeImage .NET wrapper unit test project UnitTest.csproj currently +relies on the FreeImage .NET wrapper single source file, created by the Source File Merger, located in the Source\SourceFileMerger folder. \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/UnitTest/Properties/AssemblyInfo.cs b/Wrapper/FreeImage.NET/cs/UnitTest/Properties/AssemblyInfo.cs index 2d0f3fb..1f2bec8 100644 --- a/Wrapper/FreeImage.NET/cs/UnitTest/Properties/AssemblyInfo.cs +++ b/Wrapper/FreeImage.NET/cs/UnitTest/Properties/AssemblyInfo.cs @@ -1,16 +1,16 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("FreeImageAPI.Properties")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("DataGis")] -[assembly: AssemblyProduct("FreeImageAPI.Properties")] -[assembly: AssemblyCopyright("Copyright © DataGis 2007")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("51678252-9a4b-492d-96c9-37ebe08d1f29")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("FreeImageAPI.Properties")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("DataGis")] +[assembly: AssemblyProduct("FreeImageAPI.Properties")] +[assembly: AssemblyCopyright("Copyright © DataGis 2007")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: Guid("51678252-9a4b-492d-96c9-37ebe08d1f29")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wrapper/FreeImage.NET/cs/UnitTest/UnitTest.cs b/Wrapper/FreeImage.NET/cs/UnitTest/UnitTest.cs index 98fad61..6794e34 100644 --- a/Wrapper/FreeImage.NET/cs/UnitTest/UnitTest.cs +++ b/Wrapper/FreeImage.NET/cs/UnitTest/UnitTest.cs @@ -1,5555 +1,5555 @@ -using System; -using System.Drawing; -using System.Collections.Generic; -using System.Text; -using System.Runtime.InteropServices; -using System.IO; -using System.Drawing.Imaging; -using System.Net; -using FreeImageNETUnitTest; -using System.Reflection; -using System.Threading; -using System.Runtime.Serialization.Formatters.Binary; -using System.Collections; -using FreeImageAPI; -using FreeImageAPI.IO; -using FreeImageAPI.Metadata; -using FreeImageAPI.Plugins; -using NUnit.Framework; - -namespace FreeImageNETUnitTest -{ - [TestFixture] - public class ImportedFunctionsTest - { - ImageManager iManager = new ImageManager(); - FIBITMAP dib; - string freeImageCallback = null; - - [TestFixtureSetUp] - public void Init() - { - FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); - } - - [TestFixtureTearDown] - public void DeInit() - { - FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); - } - - [SetUp] - public void InitEachTime() - { - } - - [TearDown] - public void DeInitEachTime() - { - } - - void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) - { - freeImageCallback = message; - } - - [Test] - public void FreeImage_GetVersion() - { - string version = FreeImage.GetVersion(); - Assert.IsNotEmpty(version); - } - - [Test] - public void FreeImage_GetCopyrightMessage() - { - string copyright = FreeImage.GetCopyrightMessage(); - Assert.IsNotEmpty(copyright); - } - - [Test] - public void FreeImage_OutputMessageProc_SetOutputMessage() - { - Assert.IsNull(freeImageCallback); - FreeImage.SetOutputMessage(new OutputMessageFunction(FreeImage_Message)); - FreeImage.OutputMessageProc(FREE_IMAGE_FORMAT.FIF_UNKNOWN, "unit test"); - FreeImage.SetOutputMessage(null); - Assert.IsNotNull(freeImageCallback); - freeImageCallback = null; - } - - [Test] - public void FreeImage_Allocate() - { - dib = FreeImage.Allocate( - 133, - 77, - 8, - FreeImage.FI_RGBA_RED_MASK, - FreeImage.FI_RGBA_GREEN_MASK, - FreeImage.FI_RGBA_BLUE_MASK); - - Assert.That(!dib.IsNull); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_AllocateT() - { - dib = FreeImage.AllocateT(FREE_IMAGE_TYPE.FIT_RGBA16, 31, 555, 64, 0, 0, 0); - - Assert.That(!dib.IsNull); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_Clone() - { - dib = FreeImage.Allocate(1, 1, 32, 0, 0, 0); - Assert.That(!dib.IsNull); - - FIBITMAP temp = FreeImage.Clone(dib); - Assert.AreNotEqual(0, temp); - - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_Load() - { - Assert.That(dib.IsNull); - dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, iManager.baseDirectory + @"JPEG\Image.jpg", FREE_IMAGE_LOAD_FLAGS.DEFAULT); - Assert.That(!dib.IsNull); - FreeImage.UnloadEx(ref dib); - Assert.That(dib.IsNull); - } - - [Test] - public void FreeImage_Unload() - { - Assert.That(dib.IsNull); - dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, iManager.baseDirectory + @"JPEG\Image.jpg", FREE_IMAGE_LOAD_FLAGS.DEFAULT); - Assert.IsNotNull(dib); - FreeImage.Unload(dib); - dib.SetNull(); - } - - [Test] - public void FreeImage_LoadFromHandle() - { - byte[] data = File.ReadAllBytes(iManager.GetBitmapPath(ImageType.Even, ImageColorType.Type_16_555)); - MemoryStream mStream = new MemoryStream(data); - FreeImageIO io = FreeImageStreamIO.io; - - using (fi_handle handle = new fi_handle(mStream)) - { - dib = FreeImage.LoadFromHandle(FREE_IMAGE_FORMAT.FIF_BMP, ref io, handle, FREE_IMAGE_LOAD_FLAGS.DEFAULT); - Assert.That(!dib.IsNull); - - FreeImage.UnloadEx(ref dib); - } - } - - [Test] - public void FreeImage_Save() - { - string filename = @"test.bmp"; - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08); - Assert.That(!dib.IsNull); - - Assert.IsTrue(FreeImage.Save(FREE_IMAGE_FORMAT.FIF_BMP, dib, filename, FREE_IMAGE_SAVE_FLAGS.DEFAULT)); - Assert.IsTrue(File.Exists(filename)); - File.Delete(filename); - Assert.IsFalse(File.Exists(filename)); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SaveToHandle() - { - FreeImageIO io = new FreeImageIO(); - FreeImage.SaveToHandle(FREE_IMAGE_FORMAT.FIF_BMP, dib, ref io, new fi_handle(), FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - [Test] - public void FreeImage_Memory() - { - dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); - Assert.That(!dib.IsNull); - FIMEMORY mem = FreeImage.OpenMemory(IntPtr.Zero, 0); - Assert.AreNotEqual(0, mem); - FreeImage.SaveToMemory(FREE_IMAGE_FORMAT.FIF_TIFF, dib, mem, FREE_IMAGE_SAVE_FLAGS.DEFAULT); - Assert.AreNotEqual(0, FreeImage.TellMemory(mem)); - Assert.IsTrue(FreeImage.SeekMemory(mem, 0, System.IO.SeekOrigin.Begin)); - - FIBITMAP temp = FreeImage.LoadFromMemory(FREE_IMAGE_FORMAT.FIF_TIFF, mem, FREE_IMAGE_LOAD_FLAGS.DEFAULT); - Assert.AreNotEqual(0, temp); - FreeImage.UnloadEx(ref temp); - - uint size = 0; - byte[] ptr = new byte[1]; - IntPtr buffer = IntPtr.Zero; - Assert.IsTrue(FreeImage.AcquireMemory(mem, ref buffer, ref size)); - Assert.AreNotEqual(IntPtr.Zero, ptr); - Assert.AreNotEqual(0, size); - - Assert.AreEqual(1, FreeImage.WriteMemory(ptr, 1, 1, mem)); - FreeImage.SeekMemory(mem, 1, System.IO.SeekOrigin.Begin); - Assert.AreEqual(1, FreeImage.TellMemory(mem)); - Assert.AreEqual(2, FreeImage.ReadMemory(ptr, 1, 2, mem)); - FreeImage.CloseMemory(mem); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_RegisterLocalPlugin() - { - InitProc proc = null; - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.RegisterLocalPlugin(proc, "", "", "", "")); - } - - [Test] - public void FreeImage_RegisterExternalPlugin() - { - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.RegisterExternalPlugin("", "", "", "", "")); - } - - [Test] - public void FreeImage_GetFIFCount() - { - Assert.AreNotEqual(0, FreeImage.GetFIFCount()); - } - - [Test] - public void FreeImage_SetPluginEnabled_IsPluginEnabled() - { - FreeImage.SetPluginEnabled(FREE_IMAGE_FORMAT.FIF_PNG, false); - Assert.AreEqual(0, FreeImage.IsPluginEnabled(FREE_IMAGE_FORMAT.FIF_PNG)); - FreeImage.SetPluginEnabled(FREE_IMAGE_FORMAT.FIF_PNG, true); - Assert.AreEqual(1, FreeImage.IsPluginEnabled(FREE_IMAGE_FORMAT.FIF_PNG)); - } - - [Test] - public void FreeImage_GetFIFFromFormat() - { - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFIFFromFormat("")); - Assert.AreNotEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFIFFromFormat("TIFF")); - } - - [Test] - public void FreeImage_GetFIFFromMime() - { - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFIFFromMime("")); - Assert.AreNotEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFIFFromMime("image/jpeg")); - } - - [Test] - public void FreeImage_GetFormatFromFIF() - { - Assert.IsNotEmpty(FreeImage.GetFormatFromFIF(FREE_IMAGE_FORMAT.FIF_JNG)); - } - - [Test] - public void FreeImage_GetFIFExtensionList() - { - Assert.IsNotEmpty(FreeImage.GetFIFExtensionList(FREE_IMAGE_FORMAT.FIF_PGM)); - } - - [Test] - public void FreeImage_GetFIFDescription() - { - Assert.IsNotEmpty(FreeImage.GetFIFDescription(FREE_IMAGE_FORMAT.FIF_PBM)); - } - - [Test] - public void FreeImage_GetFIFRegExpr() - { - Assert.IsNotEmpty(FreeImage.GetFIFRegExpr(FREE_IMAGE_FORMAT.FIF_JPEG)); - } - - [Test] - public void FreeImage_GetFIFMimeType() - { - Assert.IsNotEmpty(FreeImage.GetFIFMimeType(FREE_IMAGE_FORMAT.FIF_ICO)); - } - - [Test] - public void FreeImage_GetFIFFromFilename() - { - Assert.AreNotEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFIFFromFilename("test.bmp")); - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFIFFromFilename("test.000")); - } - - [Test] - public void FreeImage_FIFSupportsReading() - { - Assert.IsTrue(FreeImage.FIFSupportsReading(FREE_IMAGE_FORMAT.FIF_TIFF)); - } - - [Test] - public void FreeImage_FIFSupportsWriting() - { - Assert.IsTrue(FreeImage.FIFSupportsWriting(FREE_IMAGE_FORMAT.FIF_GIF)); - } - - [Test] - public void FreeImage_FIFSupportsExportBPP() - { - Assert.IsTrue(FreeImage.FIFSupportsExportBPP(FREE_IMAGE_FORMAT.FIF_BMP, 32)); - Assert.IsFalse(FreeImage.FIFSupportsExportBPP(FREE_IMAGE_FORMAT.FIF_GIF, 32)); - } - - [Test] - public void FreeImage_FIFSupportsExportType() - { - Assert.IsTrue(FreeImage.FIFSupportsExportType(FREE_IMAGE_FORMAT.FIF_BMP, FREE_IMAGE_TYPE.FIT_BITMAP)); - Assert.IsFalse(FreeImage.FIFSupportsExportType(FREE_IMAGE_FORMAT.FIF_BMP, FREE_IMAGE_TYPE.FIT_COMPLEX)); - } - - [Test] - public void FreeImage_FIFSupportsICCProfiles() - { - Assert.IsTrue(FreeImage.FIFSupportsICCProfiles(FREE_IMAGE_FORMAT.FIF_JPEG)); - Assert.IsFalse(FreeImage.FIFSupportsICCProfiles(FREE_IMAGE_FORMAT.FIF_BMP)); - } - - [Test] - public void FreeImage_MultiBitmap() - { - FIBITMAP temp; - FIMULTIBITMAP mdib = FreeImage.OpenMultiBitmap( - FREE_IMAGE_FORMAT.FIF_TIFF, - @"test.tif", - true, - false, - true, - FREE_IMAGE_LOAD_FLAGS.DEFAULT); - Assert.AreNotEqual(0, mdib); - Assert.AreEqual(0, FreeImage.GetPageCount(mdib)); - dib = FreeImage.Allocate(10, 10, 8, 0, 0, 0); - FreeImage.AppendPage(mdib, dib); - Assert.AreEqual(1, FreeImage.GetPageCount(mdib)); - FreeImage.AppendPage(mdib, dib); - Assert.AreEqual(2, FreeImage.GetPageCount(mdib)); - FreeImage.AppendPage(mdib, dib); - Assert.AreEqual(3, FreeImage.GetPageCount(mdib)); - FreeImage.CloseMultiBitmapEx(ref mdib); - FreeImage.UnloadEx(ref dib); - mdib.SetNull(); - mdib = FreeImage.OpenMultiBitmap(FREE_IMAGE_FORMAT.FIF_TIFF, @"test.tif", false, false, true, FREE_IMAGE_LOAD_FLAGS.DEFAULT); - Assert.AreNotEqual(0, mdib); - Assert.AreEqual(3, FreeImage.GetPageCount(mdib)); - dib = FreeImage.LockPage(mdib, 1); - temp = FreeImage.LockPage(mdib, 2); - - int[] pages = null; - int count = 0; - FreeImage.GetLockedPageNumbers(mdib, pages, ref count); - Assert.AreEqual(2, count); - pages = new int[count]; - FreeImage.GetLockedPageNumbers(mdib, pages, ref count); - Assert.AreEqual(2, pages.Length); - FreeImage.UnlockPage(mdib, dib, false); - FreeImage.UnlockPage(mdib, temp, true); - dib.SetNull(); - Assert.IsTrue(FreeImage.MovePage(mdib, 0, 1)); - FreeImage.CloseMultiBitmapEx(ref mdib); - Assert.IsTrue(System.IO.File.Exists("test.tif")); - System.IO.File.Delete("test.tif"); - } - - [Test] - public void FreeImage_GetFileType() - { - Assert.AreNotEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFileType(iManager.GetBitmapPath(ImageType.Even, ImageColorType.Type_08_Greyscale_Unordered), 0)); - } - - [Test] - public void FreeImage_GetFileTypeFromHandle() - { - FreeImageIO io = FreeImageStreamIO.io; - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFileTypeFromHandle(ref io, new fi_handle(), 0)); - } - - [Test] - public void FreeImage_GetFileTypeFromMemory() - { - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFileTypeFromMemory(new FIMEMORY(), 0)); - } - - [Test] - public void FreeImage_IsLittleEndian() - { - Assert.IsTrue(FreeImage.IsLittleEndian()); - } - - [Test] - public void FreeImage_LookupX11Color() - { - byte red, green, blue; - FreeImage.LookupX11Color("lawngreen", out red, out green, out blue); - Assert.AreEqual(124, red); - Assert.AreEqual(252, green); - Assert.AreEqual(0, blue); - } - - [Test] - public void FreeImage_LookupSVGColor() - { - byte red, green, blue; - FreeImage.LookupX11Color("orchid", out red, out green, out blue); - Assert.AreEqual(218, red); - Assert.AreEqual(112, green); - Assert.AreEqual(214, blue); - } - - [Test] - public void FreeImage_GetBits() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_01_Threshold); - Assert.That(!dib.IsNull); - Assert.AreNotEqual(IntPtr.Zero, FreeImage.GetBits(dib)); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetScanLine() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04_Greyscale_MinIsBlack); - Assert.That(!dib.IsNull); - Assert.AreNotEqual(IntPtr.Zero, FreeImage.GetScanLine(dib, 0)); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetPixelIndex_SetPixelIndex() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_04_Greyscale_Unordered); - Assert.That(!dib.IsNull); - byte index_old, index_new; - Assert.IsTrue(FreeImage.GetPixelIndex(dib, 31, 10, out index_old)); - index_new = index_old == byte.MaxValue ? (byte)0 : (byte)(index_old + 1); - Assert.IsTrue(FreeImage.SetPixelIndex(dib, 31, 10, ref index_new)); - Assert.IsTrue(FreeImage.GetPixelIndex(dib, 31, 10, out index_old)); - Assert.AreEqual(index_new, index_old); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetPixelColor_SetPixelColor() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.That(!dib.IsNull); - RGBQUAD value_old, value_new; - Assert.IsTrue(FreeImage.GetPixelColor(dib, 77, 61, out value_old)); - value_new = (value_old == (RGBQUAD)Color.White) ? Color.Black : Color.White; - Assert.IsTrue(FreeImage.SetPixelColor(dib, 77, 61, ref value_new)); - Assert.IsTrue(FreeImage.GetPixelColor(dib, 77, 61, out value_old)); - Assert.AreEqual(value_new, value_old); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_Bitmap_information_functions() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_08_Greyscale_MinIsBlack); - Assert.That(!dib.IsNull); - Assert.AreEqual(FREE_IMAGE_TYPE.FIT_BITMAP, FreeImage.GetImageType(dib)); - Assert.AreNotEqual(0, FreeImage.GetColorsUsed(dib)); - Assert.AreEqual(8, FreeImage.GetBPP(dib)); - Assert.AreNotEqual(0, FreeImage.GetWidth(dib)); - Assert.AreNotEqual(0, FreeImage.GetHeight(dib)); - Assert.AreNotEqual(0, FreeImage.GetLine(dib)); - Assert.AreNotEqual(0, FreeImage.GetPitch(dib)); - Assert.AreNotEqual(0, FreeImage.GetDIBSize(dib)); - Assert.AreNotEqual(IntPtr.Zero, FreeImage.GetPalette(dib)); - FreeImage.SetDotsPerMeterX(dib, 1234); - FreeImage.SetDotsPerMeterY(dib, 4321); - Assert.AreEqual(1234, FreeImage.GetDotsPerMeterX(dib)); - Assert.AreEqual(4321, FreeImage.GetDotsPerMeterY(dib)); - Assert.AreNotEqual(IntPtr.Zero, FreeImage.GetInfoHeader(dib)); - Assert.AreNotEqual(IntPtr.Zero, FreeImage.GetInfo(dib)); - Assert.AreEqual(FREE_IMAGE_COLOR_TYPE.FIC_MINISBLACK, FreeImage.GetColorType(dib)); - Assert.AreEqual(0, FreeImage.GetRedMask(dib)); - Assert.AreEqual(0, FreeImage.GetGreenMask(dib)); - Assert.AreEqual(0, FreeImage.GetBlueMask(dib)); - Assert.AreEqual(0, FreeImage.GetTransparencyCount(dib)); - Assert.AreNotEqual(IntPtr.Zero, FreeImage.GetTransparencyTable(dib)); - FreeImage.SetTransparent(dib, false); - FreeImage.SetTransparencyTable(dib, new byte[] { }); - Assert.IsTrue(FreeImage.IsTransparent(dib)); - Assert.IsFalse(FreeImage.HasBackgroundColor(dib)); - RGBQUAD rgb = Color.Teal; - Assert.IsTrue(FreeImage.SetBackgroundColor(dib, ref rgb)); - Assert.IsTrue(FreeImage.GetBackgroundColor(dib, out rgb)); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetICCProfile() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - new FIICCPROFILE(dib, new byte[] { 0xFF, 0xAA, 0x00, 0x33 }); - FIICCPROFILE p = FreeImage.GetICCProfileEx(dib); - Assert.AreEqual(4, p.Size); - Assert.AreEqual(0xAA, p.Data[1]); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_CreateICCProfile() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - byte[] data = new byte[256]; - Assert.AreNotEqual(IntPtr.Zero, FreeImage.CreateICCProfile(dib, data, 256)); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_DestroyICCProfile() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - FreeImage.DestroyICCProfile(dib); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ConvertTo4Bits() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.That(!dib.IsNull); - FIBITMAP temp = FreeImage.ConvertTo4Bits(dib); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(4, FreeImage.GetBPP(temp)); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ConvertTo8Bits() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.That(!dib.IsNull); - FIBITMAP temp = FreeImage.ConvertTo8Bits(dib); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(8, FreeImage.GetBPP(temp)); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ConvertToGreyscale() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.That(!dib.IsNull); - FIBITMAP temp = FreeImage.ConvertToGreyscale(dib); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(8, FreeImage.GetBPP(temp)); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ConvertTo16Bits555() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.That(!dib.IsNull); - FIBITMAP temp = FreeImage.ConvertTo16Bits555(dib); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(16, FreeImage.GetBPP(temp)); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ConvertTo16Bits565() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.That(!dib.IsNull); - FIBITMAP temp = FreeImage.ConvertTo16Bits565(dib); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(16, FreeImage.GetBPP(temp)); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ConvertTo24Bits() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.That(!dib.IsNull); - FIBITMAP temp = FreeImage.ConvertTo24Bits(dib); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(24, FreeImage.GetBPP(temp)); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ConvertTo32Bits() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - FIBITMAP temp = FreeImage.ConvertTo32Bits(dib); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(32, FreeImage.GetBPP(temp)); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ColorQuantize() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - FIBITMAP temp = FreeImage.ColorQuantize(dib, FREE_IMAGE_QUANTIZE.FIQ_WUQUANT); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(8, FreeImage.GetBPP(temp)); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ColorQuantizeEx() - { - FIBITMAP paletteDib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08); - Assert.IsFalse(paletteDib.IsNull); - Palette palette = FreeImage.GetPaletteEx(paletteDib); - RGBQUAD[] table = palette.Data; - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - FIBITMAP temp = FreeImage.ColorQuantizeEx(dib, FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, (int)palette.Length, (int)palette.Length, table); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(8, FreeImage.GetBPP(temp)); - - FreeImage.UnloadEx(ref paletteDib); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_Threshold() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.That(!dib.IsNull); - FIBITMAP temp = FreeImage.Threshold(dib, 128); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(1, FreeImage.GetBPP(temp)); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_Dither() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.That(!dib.IsNull); - FIBITMAP temp = FreeImage.Dither(dib, FREE_IMAGE_DITHER.FID_FS); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(1, FreeImage.GetBPP(temp)); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_RawBits() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.That(!dib.IsNull); - IntPtr buffer = Marshal.AllocHGlobal((int)FreeImage.GetDIBSize(dib)); - FreeImage.ConvertToRawBits( - buffer, - dib, - (int)FreeImage.GetPitch(dib), - FreeImage.GetBPP(dib), - FreeImage.GetRedMask(dib), - FreeImage.GetGreenMask(dib), - FreeImage.GetBlueMask(dib), - true); - FIBITMAP temp = FreeImage.ConvertFromRawBits( - buffer, - (int)FreeImage.GetWidth(dib), - (int)FreeImage.GetHeight(dib), - (int)FreeImage.GetPitch(dib), - FreeImage.GetBPP(dib), - FreeImage.GetRedMask(dib), - FreeImage.GetGreenMask(dib), - FreeImage.GetBlueMask(dib), - true); - - Assert.AreNotEqual(0, temp); - - Marshal.FreeHGlobal(buffer); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ConvertToRGBF() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.That(!dib.IsNull); - FIBITMAP temp = FreeImage.ConvertToRGBF(dib); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(FREE_IMAGE_TYPE.FIT_RGBF, FreeImage.GetImageType(temp)); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ConvertToStandardType() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04_Greyscale_MinIsBlack); - Assert.That(!dib.IsNull); - FIBITMAP temp = FreeImage.ConvertToStandardType(dib, true); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(FREE_IMAGE_COLOR_TYPE.FIC_PALETTE, FreeImage.GetColorType(temp)); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ConvertToType() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_Unordered); - Assert.That(!dib.IsNull); - FIBITMAP temp = FreeImage.ConvertToType(dib, FREE_IMAGE_TYPE.FIT_UINT32, true); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(FREE_IMAGE_TYPE.FIT_UINT32, FreeImage.GetImageType(temp)); - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ToneMapping() - { - FIBITMAP temp; - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - FIBITMAP rgbf = FreeImage.ConvertToRGBF(dib); - Assert.AreNotEqual(0, rgbf); - Assert.AreEqual(FREE_IMAGE_TYPE.FIT_RGBF, FreeImage.GetImageType(rgbf)); - Assert.AreEqual(96, FreeImage.GetBPP(rgbf)); - - temp = FreeImage.ToneMapping(rgbf, FREE_IMAGE_TMO.FITMO_REINHARD05, 1f, 1.1f); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(24, FreeImage.GetBPP(temp)); - FreeImage.UnloadEx(ref temp); - - FreeImage.UnloadEx(ref rgbf); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_TmoDrago03() - { - FIBITMAP temp; - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - FIBITMAP rgbf = FreeImage.ConvertToRGBF(dib); - Assert.AreNotEqual(0, rgbf); - Assert.AreEqual(FREE_IMAGE_TYPE.FIT_RGBF, FreeImage.GetImageType(rgbf)); - Assert.AreEqual(96, FreeImage.GetBPP(rgbf)); - - temp = FreeImage.TmoDrago03(rgbf, 1f, 1.2f); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(24, FreeImage.GetBPP(temp)); - FreeImage.UnloadEx(ref temp); - - FreeImage.UnloadEx(ref rgbf); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_TmoReinhard05() - { - FIBITMAP temp; - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - FIBITMAP rgbf = FreeImage.ConvertToRGBF(dib); - Assert.AreNotEqual(0, rgbf); - Assert.AreEqual(FREE_IMAGE_TYPE.FIT_RGBF, FreeImage.GetImageType(rgbf)); - Assert.AreEqual(96, FreeImage.GetBPP(rgbf)); - - temp = FreeImage.TmoReinhard05(rgbf, 0f, 0.25f); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(24, FreeImage.GetBPP(temp)); - FreeImage.UnloadEx(ref temp); - - FreeImage.UnloadEx(ref rgbf); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_TmoFattal02() - { - FIBITMAP temp; - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - FIBITMAP rgbf = FreeImage.ConvertToRGBF(dib); - Assert.AreNotEqual(0, rgbf); - Assert.AreEqual(FREE_IMAGE_TYPE.FIT_RGBF, FreeImage.GetImageType(rgbf)); - Assert.AreEqual(96, FreeImage.GetBPP(rgbf)); - - temp = FreeImage.TmoFattal02(rgbf, 1f, 0.79f); - Assert.AreNotEqual(0, temp); - Assert.AreEqual(24, FreeImage.GetBPP(temp)); - FreeImage.UnloadEx(ref temp); - - FreeImage.UnloadEx(ref rgbf); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ZLibCompress_ZLibUncompress() - { - Random rand = new Random(DateTime.Now.Millisecond); - byte[] source = new byte[10240]; - byte[] compressed = new byte[(int)(10355f * 1.01 + 12f)]; - byte[] uncompressed = new byte[10240]; - rand.NextBytes(source); - Assert.AreNotEqual(0, FreeImage.ZLibCompress(compressed, (uint)compressed.Length, source, (uint)source.Length)); - Assert.AreNotEqual(0, FreeImage.ZLibUncompress(uncompressed, (uint)source.Length, compressed, (uint)compressed.Length)); - for (int i = 0; i < source.Length; i++) - if (source[i] != uncompressed[i]) - Assert.Fail(); - } - - [Test] - public void FreeImage_ZLibGZip_ZLibGUnzip() - { - Random rand = new Random(DateTime.Now.Millisecond); - byte[] source = new byte[10240]; - byte[] compressed = new byte[(int)(10355f * 1.01 + 24f)]; - byte[] uncompressed = new byte[10240]; - rand.NextBytes(source); - Assert.AreNotEqual(0, FreeImage.ZLibGZip(compressed, (uint)compressed.Length, source, (uint)source.Length)); - Assert.AreNotEqual(0, FreeImage.ZLibGUnzip(uncompressed, (uint)source.Length, compressed, (uint)compressed.Length)); - for (int i = 0; i < source.Length; i++) - if (source[i] != uncompressed[i]) - Assert.Fail(); - } - - [Test] - public void FreeImage_ZLibCRC32() - { - byte[] buffer = new byte[0]; - Assert.AreEqual(0xFEBCA008, FreeImage.ZLibCRC32(0xFEBCA008, buffer, 0)); - } - - [Test] - public void FreeImage_CreateTag() - { - FITAG tag = FreeImage.CreateTag(); - Assert.AreNotEqual(0, tag); - FITAG tag_clone = FreeImage.CloneTag(tag); - Assert.AreNotEqual(0, tag_clone); - FreeImage.DeleteTag(tag); - FreeImage.DeleteTag(tag_clone); - } - - [Test] - public void FreeImage_Tag_accessors() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - Assert.IsTrue(FreeImage.FindNextMetadata(mData, out tag)); - Assert.AreNotEqual(0, tag); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetTagKey() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - FreeImage.GetTagKey(tag); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetTagDescription() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - FreeImage.GetTagDescription(tag); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetTagID() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - FreeImage.GetTagID(tag); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetTagType() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - FreeImage.GetTagType(tag); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetTagCount() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - FreeImage.GetTagCount(tag); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetTagLength() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - FreeImage.GetTagLength(tag); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetTagValue() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - FreeImage.GetTagValue(tag); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetTagKey() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - FreeImage.SetTagKey(tag, ""); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetTagDescription() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - FreeImage.SetTagDescription(tag, ""); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetTagID() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - FreeImage.SetTagID(tag, 44); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetTagType() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - FreeImage.SetTagType(tag, FREE_IMAGE_MDTYPE.FIDT_ASCII); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetTagCount() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - FreeImage.SetTagCount(tag, 3); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetTagLength() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - FreeImage.SetTagLength(tag, 6); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetTagValue() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - int length = (int)FreeImage.GetTagLength(tag); - FREE_IMAGE_MDTYPE type = FreeImage.GetTagType(tag); - int count = (int)FreeImage.GetTagCount(tag); - - byte[] buffer = new byte[length * count]; - - FreeImage.SetTagValue(tag, buffer); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetMetadataCount() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - Assert.AreNotEqual(0, FreeImage.GetMetadataCount(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib)); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_TagToString() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - - FITAG tag; - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); - Assert.AreNotEqual(0, mData); - Assert.AreNotEqual(0, tag); - - Assert.IsNotEmpty(FreeImage.TagToString(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, tag, 0)); - - FreeImage.FindCloseMetadata(mData); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_RotateClassic() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - FIBITMAP temp = FreeImage.RotateClassic(dib, 45d); - Assert.AreNotEqual(0, temp); - - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_RotateEx() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - FIBITMAP temp = FreeImage.RotateEx(dib, 261d, 0d, 33d, 51d, 9d, true); - Assert.AreNotEqual(0, temp); - - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_FlipHorizontal() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - Assert.IsTrue(FreeImage.FlipHorizontal(dib)); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_FlipVertical() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - Assert.IsTrue(FreeImage.FlipVertical(dib)); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_JPEGTransform() - { - string filename = iManager.GetBitmapPath(ImageType.JPEG, ImageColorType.Type_24); - string filenameOut = filename + ".out.jpg"; - Assert.IsTrue(File.Exists(filename)); - - Assert.IsTrue(FreeImage.JPEGTransform(filename, filenameOut, FREE_IMAGE_JPEG_OPERATION.FIJPEG_OP_FLIP_V, false)); - Assert.IsTrue(File.Exists(filenameOut)); - - FIBITMAP temp = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, filenameOut, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); - Assert.AreNotEqual(0, temp); - - File.Delete(filenameOut); - Assert.IsFalse(File.Exists(filenameOut)); - - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_Rescale() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_16_555); - Assert.That(!dib.IsNull); - - FIBITMAP temp = FreeImage.Rescale(dib, 100, 100, FREE_IMAGE_FILTER.FILTER_BICUBIC); - Assert.AreNotEqual(0, temp); - - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_MakeThumbnail() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_16_555); - Assert.That(!dib.IsNull); - - FIBITMAP temp = FreeImage.MakeThumbnail(dib, 50, false); - Assert.AreNotEqual(0, temp); - - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_AdjustCurve() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - byte[] lut = new byte[256]; - Assert.IsTrue(FreeImage.AdjustCurve(dib, lut, FREE_IMAGE_COLOR_CHANNEL.FICC_GREEN)); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_AdjustGamma() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - Assert.IsTrue(FreeImage.AdjustGamma(dib, 1.3d)); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_AdjustBrightness() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - Assert.IsTrue(FreeImage.AdjustBrightness(dib, 1.3d)); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_AdjustContrast() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - Assert.IsTrue(FreeImage.AdjustContrast(dib, 1.3d)); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_Invert() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_16_555); - Assert.That(!dib.IsNull); - - Assert.IsTrue(FreeImage.Invert(dib)); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetHistogram() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - int[] histo = new int[256]; - Assert.IsTrue(FreeImage.GetHistogram(dib, histo, FREE_IMAGE_COLOR_CHANNEL.FICC_RED)); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetChannel() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - FIBITMAP temp = FreeImage.GetChannel(dib, FREE_IMAGE_COLOR_CHANNEL.FICC_GREEN); - Assert.AreNotEqual(0, temp); - - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetChannel() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.That(!dib.IsNull); - FIBITMAP dib8 = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_MinIsBlack); - Assert.AreNotEqual(0, dib8); - Assert.AreEqual(FreeImage.GetWidth(dib), FreeImage.GetWidth(dib8)); - Assert.AreEqual(FreeImage.GetHeight(dib), FreeImage.GetHeight(dib8)); - - Assert.IsTrue(FreeImage.SetChannel(dib, dib8, FREE_IMAGE_COLOR_CHANNEL.FICC_BLUE)); - - FreeImage.UnloadEx(ref dib8); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetComplexChannel() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08); - Assert.That(!dib.IsNull); - - FIBITMAP temp = FreeImage.ConvertToType(dib, FREE_IMAGE_TYPE.FIT_COMPLEX, true); - Assert.AreNotEqual(0, temp); - - FIBITMAP temp2 = FreeImage.GetComplexChannel(temp, FREE_IMAGE_COLOR_CHANNEL.FICC_IMAG); - Assert.AreNotEqual(0, temp2); - - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref temp2); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetComplexChannel() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_Unordered); - Assert.That(!dib.IsNull); - - FIBITMAP temp = FreeImage.ConvertToType(dib, FREE_IMAGE_TYPE.FIT_COMPLEX, true); - Assert.AreNotEqual(0, temp); - - FIBITMAP temp2 = FreeImage.GetComplexChannel(temp, FREE_IMAGE_COLOR_CHANNEL.FICC_IMAG); - Assert.AreNotEqual(0, temp2); - - Assert.IsTrue(FreeImage.SetComplexChannel(temp, temp2, FREE_IMAGE_COLOR_CHANNEL.FICC_IMAG)); - - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref temp2); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_Copy() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_MinIsBlack); - Assert.That(!dib.IsNull); - - FIBITMAP temp = FreeImage.Copy(dib, 5, 9, 44, 2); - Assert.AreNotEqual(0, temp); - - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_Paste() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_MinIsBlack); - Assert.That(!dib.IsNull); - - FIBITMAP temp = FreeImage.Allocate(3, 3, 8, 0, 0, 0); - Assert.IsTrue(FreeImage.Paste(dib, temp, 31, 3, 256)); - - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_Composite() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_MinIsBlack); - Assert.That(!dib.IsNull); - RGBQUAD rgbq = new RGBQUAD(); - - FIBITMAP temp = FreeImage.Composite(dib, false, ref rgbq, new FIBITMAP()); - Assert.AreNotEqual(0, temp); - - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_JPEGCrop() - { - string filename = iManager.GetBitmapPath(ImageType.JPEG, ImageColorType.Type_01_Dither); - Assert.IsTrue(File.Exists(filename)); - string filenameOut = filename + ".out.jpg"; - - Assert.IsTrue(FreeImage.JPEGCrop(filename, filenameOut, 3, 2, 1, 5)); - Assert.IsTrue(File.Exists(filenameOut)); - - FIBITMAP temp = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, filenameOut, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); - Assert.AreNotEqual(0, temp); - - File.Delete(filenameOut); - Assert.IsFalse(File.Exists(filenameOut)); - - FreeImage.UnloadEx(ref temp); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_PreMultiplyWithAlpha() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.IsFalse(dib.IsNull); - - Assert.IsTrue(FreeImage.PreMultiplyWithAlpha(dib)); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_MultigridPoissonSolver() - { - dib = FreeImage.AllocateT(FREE_IMAGE_TYPE.FIT_FLOAT, 10, 10, 32, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - - FIBITMAP dib2 = FreeImage.MultigridPoissonSolver(dib, 2); - - FreeImage.UnloadEx(ref dib); - FreeImage.UnloadEx(ref dib2); - } - - [Test] - public void FreeImage_GetAdjustColorsLookupTable() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); - Assert.IsFalse(dib.IsNull); - - byte[] lut = new byte[256]; - FreeImage.GetAdjustColorsLookupTable(lut, 55d, 0d, 2.1d, false); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_AdjustColors() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.IsFalse(dib.IsNull); - - Assert.IsTrue(FreeImage.AdjustColors(dib, -4d, 22d, 1.1d, false)); - - FreeImage.UnloadEx(ref dib); - } - - [Ignore] - public void FreeImage_ApplyColorMapping() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - FreeImage_ApplyColorMapping2(dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - FreeImage_ApplyColorMapping2(dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - FreeImage_ApplyColorMapping2(dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - FreeImage_ApplyColorMapping2(dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - FreeImage_ApplyColorMapping2(dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - FreeImage_ApplyColorMapping2(dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - FreeImage_ApplyColorMapping2(dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - FreeImage_ApplyColorMapping2(dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - FreeImage_ApplyColorMapping2(dib); - } - - private void FreeImage_ApplyColorMapping2(FIBITMAP dib) - { - Assert.IsFalse(dib.IsNull); - - Scanline rgbqa = new Scanline(dib, 0); - - RGBQUAD[] src = new RGBQUAD[1]; - RGBQUAD[] dst = new RGBQUAD[1]; - src[0] = rgbqa[0]; - dst[0].Color = src[0].Color == Color.White ? Color.Thistle : Color.White; - - uint count = FreeImage.ApplyColorMapping(dib, src, dst, 1, true, false); // Memory - Assert.That(count > 0); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SwapColors() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_08); - Assert.IsFalse(dib.IsNull); - - RGBQUAD src = new RGBQUAD(Color.FromArgb(93, 119, 170)); - RGBQUAD dst = new RGBQUAD(Color.FromArgb(90, 130, 148)); - - uint count = FreeImage.SwapColors(dib, ref src, ref dst, true); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ApplyPaletteIndexMapping() - { - // alle farbtiefen - - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_04); - Assert.IsFalse(dib.IsNull); - - byte[] src = { 0, 3, 1 }; - byte[] dst = { 3, 1, 0 }; - - uint count = FreeImage.ApplyPaletteIndexMapping(dib, src, dst, 3, false); - Assert.That(count > 0); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SwapPaletteIndices() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_04); - Assert.IsFalse(dib.IsNull); - - byte src = 0; - byte dst = 3; - - uint count = FreeImage.SwapPaletteIndices(dib, ref src, ref dst); - Assert.That(count > 0); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetTransparentIndex() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04); - Assert.IsFalse(dib.IsNull); - - FreeImage.SetTransparentIndex(dib, 0); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetTransparentIndex() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04); - Assert.IsFalse(dib.IsNull); - - int i = FreeImage.GetTransparentIndex(dib); - - FreeImage.UnloadEx(ref dib); - } - } - - [TestFixture] - public class ImportedStructsTest - { - ImageManager iManager = new ImageManager(); - FIBITMAP dib = new FIBITMAP(); - string freeImageCallback = null; - - [TestFixtureSetUp] - public void Init() - { - FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); - } - - [TestFixtureTearDown] - public void DeInit() - { - FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); - } - - [SetUp] - public void InitEachTime() - { - } - - [TearDown] - public void DeInitEachTime() - { - } - - void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) - { - freeImageCallback = message; - } - - public bool EqualColors(Color color1, Color color2) - { - if (color1.A != color2.A) return false; - if (color1.R != color2.R) return false; - if (color1.G != color2.G) return false; - if (color1.B != color2.B) return false; - return true; - } - - [Test] - public void RGBQUAD() - { - RGBQUAD rgbq = new RGBQUAD(); - Assert.AreEqual(0, rgbq.rgbBlue); - Assert.AreEqual(0, rgbq.rgbGreen); - Assert.AreEqual(0, rgbq.rgbRed); - Assert.AreEqual(0, rgbq.rgbReserved); - - rgbq = new RGBQUAD(Color.Chartreuse); - Assert.That(EqualColors(Color.Chartreuse, rgbq.Color)); - - rgbq = new RGBQUAD(Color.FromArgb(133, 83, 95, 173)); - Assert.AreEqual(173, rgbq.rgbBlue); - Assert.AreEqual(95, rgbq.rgbGreen); - Assert.AreEqual(83, rgbq.rgbRed); - Assert.AreEqual(133, rgbq.rgbReserved); - - rgbq.Color = Color.Crimson; - Assert.That(EqualColors(Color.Crimson, rgbq.Color)); - - rgbq.Color = Color.MidnightBlue; - Assert.That(EqualColors(Color.MidnightBlue, rgbq.Color)); - - rgbq.Color = Color.White; - Assert.AreEqual(255, rgbq.rgbBlue); - Assert.AreEqual(255, rgbq.rgbGreen); - Assert.AreEqual(255, rgbq.rgbRed); - Assert.AreEqual(255, rgbq.rgbReserved); - - rgbq.Color = Color.Black; - Assert.AreEqual(0, rgbq.rgbBlue); - Assert.AreEqual(0, rgbq.rgbGreen); - Assert.AreEqual(0, rgbq.rgbRed); - Assert.AreEqual(255, rgbq.rgbReserved); - - rgbq = Color.DarkGoldenrod; - Color color = rgbq; - Assert.That(EqualColors(Color.DarkGoldenrod, color)); - } - - [Test] - public void RGBTRIPLE() - { - RGBTRIPLE rgbt = new RGBTRIPLE(); - Assert.AreEqual(0, rgbt.rgbtBlue); - Assert.AreEqual(0, rgbt.rgbtGreen); - Assert.AreEqual(0, rgbt.rgbtRed); - - rgbt = new RGBTRIPLE(Color.Chartreuse); - Assert.That(EqualColors(Color.Chartreuse, rgbt.Color)); - - rgbt = new RGBTRIPLE(Color.FromArgb(133, 83, 95, 173)); - Assert.AreEqual(173, rgbt.rgbtBlue); - Assert.AreEqual(95, rgbt.rgbtGreen); - Assert.AreEqual(83, rgbt.rgbtRed); - - rgbt.Color = Color.Crimson; - Assert.That(EqualColors(Color.Crimson, rgbt.Color)); - - rgbt.Color = Color.MidnightBlue; - Assert.That(EqualColors(Color.MidnightBlue, rgbt.Color)); - - rgbt.Color = Color.White; - Assert.AreEqual(255, rgbt.rgbtBlue); - Assert.AreEqual(255, rgbt.rgbtGreen); - Assert.AreEqual(255, rgbt.rgbtRed); - - rgbt.Color = Color.Black; - Assert.AreEqual(0, rgbt.rgbtBlue); - Assert.AreEqual(0, rgbt.rgbtGreen); - Assert.AreEqual(0, rgbt.rgbtRed); - - rgbt = Color.DarkGoldenrod; - Color color = rgbt; - Assert.That(EqualColors(Color.DarkGoldenrod, color)); - } - - [Test] - public void FIRGB16() - { - FIRGB16 rgb = new FIRGB16(); - Assert.AreEqual(0 * 256, rgb.blue); - Assert.AreEqual(0 * 256, rgb.green); - Assert.AreEqual(0 * 256, rgb.red); - - rgb = new FIRGB16(Color.Chartreuse); - Assert.That(EqualColors(Color.Chartreuse, rgb.Color)); - - rgb = new FIRGB16(Color.FromArgb(133, 83, 95, 173)); - Assert.AreEqual(173 * 256, rgb.blue); - Assert.AreEqual(95 * 256, rgb.green); - Assert.AreEqual(83 * 256, rgb.red); - - rgb.Color = Color.Crimson; - Assert.That(EqualColors(Color.Crimson, rgb.Color)); - - rgb.Color = Color.MidnightBlue; - Assert.That(EqualColors(Color.MidnightBlue, rgb.Color)); - - rgb.Color = Color.White; - Assert.AreEqual(255 * 256, rgb.blue); - Assert.AreEqual(255 * 256, rgb.green); - Assert.AreEqual(255 * 256, rgb.red); - - rgb.Color = Color.Black; - Assert.AreEqual(0 * 256, rgb.blue); - Assert.AreEqual(0 * 256, rgb.green); - Assert.AreEqual(0 * 256, rgb.red); - - rgb = Color.DarkGoldenrod; - Color color = rgb; - Assert.That(EqualColors(Color.DarkGoldenrod, color)); - } - - [Test] - public void FIRGBA16() - { - FIRGBA16 rgb = new FIRGBA16(); - Assert.AreEqual(0 * 256, rgb.blue); - Assert.AreEqual(0 * 256, rgb.green); - Assert.AreEqual(0 * 256, rgb.red); - Assert.AreEqual(0 * 256, rgb.alpha); - - rgb = new FIRGBA16(Color.Chartreuse); - Assert.That(EqualColors(Color.Chartreuse, rgb.Color)); - - rgb = new FIRGBA16(Color.FromArgb(133, 83, 95, 173)); - Assert.AreEqual(173 * 256, rgb.blue); - Assert.AreEqual(95 * 256, rgb.green); - Assert.AreEqual(83 * 256, rgb.red); - Assert.AreEqual(133 * 256, rgb.alpha); - - rgb.Color = Color.Crimson; - Assert.That(EqualColors(Color.Crimson, rgb.Color)); - - rgb.Color = Color.MidnightBlue; - Assert.That(EqualColors(Color.MidnightBlue, rgb.Color)); - - rgb.Color = Color.White; - Assert.AreEqual(255 * 256, rgb.blue); - Assert.AreEqual(255 * 256, rgb.green); - Assert.AreEqual(255 * 256, rgb.red); - Assert.AreEqual(255 * 256, rgb.alpha); - - rgb.Color = Color.Black; - Assert.AreEqual(0 * 256, rgb.blue); - Assert.AreEqual(0 * 256, rgb.green); - Assert.AreEqual(0 * 256, rgb.red); - Assert.AreEqual(255 * 256, rgb.alpha); - - rgb = Color.DarkGoldenrod; - Color color = rgb; - Assert.That(EqualColors(Color.DarkGoldenrod, color)); - } - - [Test] - public void FIRGBF() - { - FIRGBF rgb = new FIRGBF(); - Assert.AreEqual(0 / 255f, rgb.blue); - Assert.AreEqual(0 / 255f, rgb.green); - Assert.AreEqual(0 / 255f, rgb.red); - - rgb = new FIRGBF(Color.Chartreuse); - Assert.That(EqualColors(Color.Chartreuse, rgb.Color)); - - rgb = new FIRGBF(Color.FromArgb(133, 83, 95, 173)); - Assert.AreEqual(173 / 255f, rgb.blue); - Assert.AreEqual(95 / 255f, rgb.green); - Assert.AreEqual(83 / 255f, rgb.red); - - rgb.Color = Color.Crimson; - Assert.That(EqualColors(Color.Crimson, rgb.Color)); - - rgb.Color = Color.MidnightBlue; - Assert.That(EqualColors(Color.MidnightBlue, rgb.Color)); - - rgb.Color = Color.White; - Assert.AreEqual(255 / 255f, rgb.blue); - Assert.AreEqual(255 / 255f, rgb.green); - Assert.AreEqual(255 / 255f, rgb.red); - - rgb.Color = Color.Black; - Assert.AreEqual(0 / 255f, rgb.blue); - Assert.AreEqual(0 / 255f, rgb.green); - Assert.AreEqual(0 / 255f, rgb.red); - - rgb = Color.DarkGoldenrod; - Color color = rgb; - Assert.That(EqualColors(Color.DarkGoldenrod, color)); - } - - [Test] - public void FIRGBAF() - { - FIRGBAF rgb = new FIRGBAF(); - Assert.AreEqual(0 / 255f, rgb.blue); - Assert.AreEqual(0 / 255f, rgb.green); - Assert.AreEqual(0 / 255f, rgb.red); - Assert.AreEqual(0 / 255f, rgb.alpha); - - rgb = new FIRGBAF(Color.Chartreuse); - Assert.That(EqualColors(Color.Chartreuse, rgb.Color)); - - rgb = new FIRGBAF(Color.FromArgb(133, 83, 95, 173)); - Assert.AreEqual(173 / 255f, rgb.blue); - Assert.AreEqual(95 / 255f, rgb.green); - Assert.AreEqual(83 / 255f, rgb.red); - Assert.AreEqual(133 / 255f, rgb.alpha); - - rgb.Color = Color.Crimson; - Assert.That(EqualColors(Color.Crimson, rgb.Color)); - - rgb.Color = Color.MidnightBlue; - Assert.That(EqualColors(Color.MidnightBlue, rgb.Color)); - - rgb.Color = Color.White; - Assert.AreEqual(255 / 255f, rgb.blue); - Assert.AreEqual(255 / 255f, rgb.green); - Assert.AreEqual(255 / 255f, rgb.red); - Assert.AreEqual(255 / 255f, rgb.alpha); - - rgb.Color = Color.Black; - Assert.AreEqual(0 / 255f, rgb.blue); - Assert.AreEqual(0 / 255f, rgb.green); - Assert.AreEqual(0 / 255f, rgb.red); - Assert.AreEqual(255 / 255f, rgb.alpha); - - rgb = Color.DarkGoldenrod; - Color color = rgb; - Assert.That(EqualColors(Color.DarkGoldenrod, color)); - } - - [Ignore] - public void FICOMPLEX() - { - } - - [Test] - public void FIBITMAP() - { - FIBITMAP var = new FIBITMAP(); - Assert.IsTrue(var.IsNull); - } - - [Test] - public void fi_handle() - { - fi_handle var = new fi_handle(); - Assert.IsTrue(var.IsNull); - - string test = "hello word!"; - using (var = new fi_handle(test)) - { - Assert.IsFalse(var.IsNull); - - object obj = var.GetObject(); - Assert.That(obj is string); - Assert.AreSame(obj, test); - } - } - - [Test] - public void FIICCPROFILE() - { - Random rand = new Random(DateTime.Now.Millisecond); - FIICCPROFILE var = new FIICCPROFILE(); - Assert.AreEqual(0, var.Data.Length); - Assert.AreEqual(IntPtr.Zero, var.DataPointer); - Assert.AreEqual(0, var.Size); - - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - byte[] data = new byte[512]; - rand.NextBytes(data); - - var = FreeImage.GetICCProfileEx(dib); - Assert.AreEqual(0, var.Size); - - var = new FIICCPROFILE(dib, data, 256); - Assert.AreEqual(256, var.Data.Length); - Assert.AreNotEqual(IntPtr.Zero, var.DataPointer); - Assert.AreEqual(256, var.Size); - byte[] dataComp = var.Data; - for (int i = 0; i < data.Length && i < dataComp.Length; i++) - if (data[i] != dataComp[i]) - Assert.Fail(); - - FreeImage.DestroyICCProfile(dib); - var = FreeImage.GetICCProfileEx(dib); - Assert.AreEqual(0, var.Size); - - var = new FIICCPROFILE(dib, data); - Assert.AreEqual(512, var.Data.Length); - Assert.AreNotEqual(IntPtr.Zero, var.DataPointer); - Assert.AreEqual(512, var.Size); - dataComp = var.Data; - for (int i = 0; i < data.Length && i < dataComp.Length; i++) - if (data[i] != dataComp[i]) - Assert.Fail(); - - var = FreeImage.GetICCProfileEx(dib); - Assert.AreEqual(512, var.Data.Length); - Assert.AreNotEqual(IntPtr.Zero, var.DataPointer); - Assert.AreEqual(512, var.Size); - - FreeImage.DestroyICCProfile(dib); - var = FreeImage.GetICCProfileEx(dib); - Assert.AreEqual(0, var.Size); - - FreeImage.UnloadEx(ref dib); - } - } - - [TestFixture] - public class WrapperStructsTest - { - ImageManager iManager = new ImageManager(); - FIBITMAP dib = new FIBITMAP(); - string freeImageCallback = null; - - [TestFixtureSetUp] - public void Init() - { - FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); - } - - [TestFixtureTearDown] - public void DeInit() - { - FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); - } - - [SetUp] - public void InitEachTime() - { - } - - [TearDown] - public void DeInitEachTime() - { - } - - void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) - { - freeImageCallback = message; - } - - public bool EqualColors(Color color1, Color color2) - { - if (color1.A != color2.A) return false; - if (color1.R != color2.R) return false; - if (color1.G != color2.G) return false; - if (color1.B != color2.B) return false; - return true; - } - - [Test] - public void FIRational() - { - FIRational rational1 = new FIRational(); - FIRational rational2 = new FIRational(); - FIRational rational3 = new FIRational(); - - // - // Constructors - // - - Assert.That(rational1.Numerator == 0); - Assert.That(rational1.Denominator == 0); - - rational1 = new FIRational(412, 33); - Assert.That(rational1.Numerator == 412); - Assert.That(rational1.Denominator == 33); - - rational2 = new FIRational(rational1); - Assert.That(rational2.Numerator == 412); - Assert.That(rational2.Denominator == 33); - - rational3 = new FIRational(5.75m); - Assert.That(rational3.Numerator == 23); - Assert.That(rational3.Denominator == 4); - - // - // == != - // - - rational1 = new FIRational(421, 51); - rational2 = rational1; - Assert.That(rational1 == rational2); - Assert.That(!(rational1 != rational2)); - - rational2 = new FIRational(1, 7); - Assert.That(rational1 != rational2); - Assert.That(!(rational1 == rational2)); - - // - // > >= < <= - // - - rational1 = new FIRational(51, 4); - rational2 = new FIRational(27, 9); - Assert.That(rational1 != rational2); - Assert.That(rational1 > rational2); - Assert.That(rational1 >= rational2); - - rational1 = new FIRational(-412, 4); - Assert.That(rational1 != rational2); - Assert.That(rational1 < rational2); - Assert.That(rational1 <= rational2); - - // - // + / - - // - - rational1 = new FIRational(41, 3); - rational2 = new FIRational(612, 412); - rational3 = rational1 - rational2; - Assert.That((rational3 + rational2) == rational1); - - rational1 = new FIRational(-7852, 63); - rational2 = new FIRational(666111, -7654); - rational3 = rational1 - rational2; - Assert.That((rational3 + rational2) == rational1); - - rational1 = new FIRational(-513, 88); - rational2 = new FIRational(413, 5); - rational3 = rational1 - rational2; - Assert.That((rational3 + rational2) == rational1); - - rational1 = new FIRational(-513, 88); - rational2 = new FIRational(413, 5); - rational3 = rational1 - rational2; - Assert.That((rational3 + rational2) == rational1); - - rational1 = new FIRational(7531, 23144); - rational2 = new FIRational(-412, 78777); - rational3 = rational1 - rational2; - Assert.That((rational3 + rational2) == rational1); - - rational1 = new FIRational(513, -42123); - rational2 = new FIRational(-42, 77); - rational3 = rational1 - rational2; - Assert.That((rational3 + rational2) == rational1); - - rational1 = new FIRational(44, 11); - rational1 = -rational1; - Assert.That(rational1.Numerator == -4 && rational1.Denominator == 1); - - // - // % - // - - rational1 = new FIRational(23, 8); - rational2 = new FIRational(77, 777); - Assert.That((rational1 % rational2) == 0); - - rational2 = -rational2; - Assert.That((rational1 % rational2) == 0); - - rational2 = new FIRational(7, 4); - rational3 = new FIRational(9, 8); - Assert.That((rational1 % rational2) == rational3); - - rational2 = -rational2; - Assert.That((rational1 % rational2) == rational3); - - // - // ~ - // - - rational1 = new FIRational(41, 77); - rational1 = ~rational1; - Assert.That(rational1.Numerator == 77 && rational1.Denominator == 41); - - // - // - - // - - rational1 = new FIRational(52, 4); - rational1 = -rational1; - Assert.That(rational1 < 0); - - // - // ++ -- - // - - rational1 = new FIRational(5, 3); - rational1++; - rational2 = new FIRational(8, 3); - Assert.That(rational1 == rational2); - - rational1 = new FIRational(41, -43); - rational1++; - Assert.That(rational1 > 0.0f); - - rational1--; - Assert.That(rational1 == new FIRational(41, -43)); - - rational1 = new FIRational(8134, 312); - Assert.That(rational1 != 26); - - // - // Direct assigns - // - - rational1 = (FIRational)0.75m; - Assert.That(rational1.Numerator == 3 && rational1.Denominator == 4); - rational1 = (FIRational)0.33; - Assert.That(rational1.Numerator == 33 && rational1.Denominator == 100); - rational1 = (FIRational)62.975m; - Assert.That(((decimal)rational1.Numerator / (decimal)rational1.Denominator) == 62.975m); - rational1 = (FIRational)(-73.0975m); - Assert.That(((decimal)rational1.Numerator / (decimal)rational1.Denominator) == -73.0975m); - rational1 = (FIRational)(7m / 9m); - Assert.That(rational1.Numerator == 7 && rational1.Denominator == 9); - rational1 = (FIRational)(-15m / 9m); - Assert.That(rational1.Numerator == -5 && rational1.Denominator == 3); - rational1 = (FIRational)(0.7777m); - Assert.That(rational1.Denominator != 9); - - // - // Properties - // - - rational1 = new FIRational(515, 5); - Assert.That(rational1.IsInteger); - - rational1 = new FIRational(876, 77); - Assert.That(rational1.Truncate() == (876 / 77)); - - // - // Special cases - // - - rational1 = new FIRational(0, 10000); - Assert.That(rational1 == 0m); - - rational1 = new FIRational(10000, 0); - Assert.That(rational1 == 0f); - - rational1 = new FIRational(0, 0); - Assert.That(rational1 == 0d); - - rational1 = new FIRational(-1, 0); - Assert.That(rational1 == 0); - - rational1 = new FIRational(0, -1); - Assert.That(rational1 == 0); - } - - [Ignore] - public void StreamWrapper() - { - string url = @"http://freeimage.sourceforge.net/images/logo.jpg"; - - // - // Non blocking - // - - HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); - Assert.IsNotNull(req); - - req.Timeout = 1000; - HttpWebResponse resp; - try - { - resp = (HttpWebResponse)req.GetResponse(); - } - catch - { - return; - } - Assert.IsNotNull(resp); - - Stream stream = resp.GetResponseStream(); - Assert.IsNotNull(stream); - - StreamWrapper wrapper = new StreamWrapper(stream, false); - Assert.IsNotNull(wrapper); - Assert.IsTrue(wrapper.CanRead && wrapper.CanSeek && !wrapper.CanWrite); - - byte[] buffer = new byte[1024 * 100]; - int read; - int count = 0; - - do - { - read = wrapper.Read(buffer, count, buffer.Length - count); - count += read; - } while (read != 0); - - Assert.AreEqual(7972, count); - Assert.AreEqual(7972, wrapper.Length); - - wrapper.Position = 0; - Assert.AreEqual(0, wrapper.Position); - - byte[] test = new byte[buffer.Length]; - int countTest = 0; - - do - { - read = wrapper.Read(test, countTest, test.Length - countTest); - countTest += read; - } while (read != 0); - - Assert.AreEqual(count, countTest); - - for (int i = 0; i < countTest; i++) - if (buffer[i] != test[i]) - Assert.Fail(); - - resp.Close(); - wrapper.Dispose(); - stream.Dispose(); - - // - // Blocking - // - - req = (HttpWebRequest)HttpWebRequest.Create(url); - Assert.IsNotNull(req); - - resp = (HttpWebResponse)req.GetResponse(); - Assert.IsNotNull(resp); - - stream = resp.GetResponseStream(); - Assert.IsNotNull(stream); - - wrapper = new StreamWrapper(stream, true); - Assert.IsNotNull(wrapper); - Assert.IsTrue(wrapper.CanRead && wrapper.CanSeek && !wrapper.CanWrite); - - buffer = new byte[1024 * 100]; - count = 0; - - count = wrapper.Read(buffer, 0, buffer.Length); - Assert.AreEqual(7972, count); - - resp.Close(); - stream.Dispose(); - wrapper.Dispose(); - - // - // Position & Read byte - // - - buffer = new byte[] { 0x00, 0x01, 0x02, 0xFF, 0xFE, 0xFD }; - stream = new MemoryStream(buffer); - wrapper = new StreamWrapper(stream, false); - - Assert.That(0x00 == wrapper.ReadByte()); - Assert.That(0x01 == wrapper.ReadByte()); - Assert.That(0x02 == wrapper.ReadByte()); - Assert.That(0xFF == wrapper.ReadByte()); - Assert.That(0xFE == wrapper.ReadByte()); - Assert.That(0xFD == wrapper.ReadByte()); - Assert.That(-1 == wrapper.ReadByte()); - - Assert.That(wrapper.Length == buffer.Length); - - wrapper.Seek(0, SeekOrigin.Begin); - Assert.That(0x00 == wrapper.ReadByte()); - wrapper.Seek(3, SeekOrigin.Begin); - Assert.That(0xFF == wrapper.ReadByte()); - wrapper.Seek(0, SeekOrigin.End); - Assert.That(-1 == wrapper.ReadByte()); - wrapper.Seek(-2, SeekOrigin.End); - Assert.That(0xFE == wrapper.ReadByte()); - wrapper.Seek(0, SeekOrigin.Begin); - Assert.That(0x00 == wrapper.ReadByte()); - wrapper.Seek(2, SeekOrigin.Current); - Assert.That(0xFF == wrapper.ReadByte()); - wrapper.Seek(1, SeekOrigin.Current); - Assert.That(0xFD == wrapper.ReadByte()); - Assert.That(wrapper.Position != 0); - wrapper.Reset(); - Assert.That(wrapper.Position == 0); - - wrapper.Dispose(); - stream.Position = 0; - wrapper = new StreamWrapper(stream, false); - - wrapper.Seek(10, SeekOrigin.Begin); - Assert.That(wrapper.Position == buffer.Length); - - wrapper.Dispose(); - stream.Dispose(); - } - - [Ignore] - public void LocalPlugin() - { - } - - [Test] - public void FreeImageStreamIO() - { - Random rand = new Random(); - byte[] bBuffer = new byte[256]; - IntPtr buffer = Marshal.AllocHGlobal(256); - - MemoryStream stream = new MemoryStream(); - Assert.IsNotNull(stream); - using (fi_handle handle = new fi_handle(stream)) - { - - FreeImageIO io = FreeImageAPI.IO.FreeImageStreamIO.io; - Assert.IsNotNull(io.readProc); - Assert.IsNotNull(io.writeProc); - Assert.IsNotNull(io.seekProc); - Assert.IsNotNull(io.tellProc); - - // - // Procs - // - - rand.NextBytes(bBuffer); - - stream.Write(bBuffer, 0, bBuffer.Length); - Assert.That(io.tellProc(handle) == stream.Position); - Assert.That(io.seekProc(handle, 0, SeekOrigin.Begin) == 0); - Assert.That(io.tellProc(handle) == 0); - Assert.That(io.tellProc(handle) == stream.Position); - - // Read one block - Assert.That(io.readProc(buffer, (uint)bBuffer.Length, 1, handle) == 1); - for (int i = 0; i < bBuffer.Length; i++) - Assert.That(Marshal.ReadByte(buffer, i) == bBuffer[i]); - - Assert.That(io.tellProc(handle) == stream.Position); - Assert.That(io.seekProc(handle, 0, SeekOrigin.Begin) == 0); - Assert.That(io.tellProc(handle) == stream.Position); - - // Read 1 byte block - Assert.That(io.readProc(buffer, 1, (uint)bBuffer.Length, handle) == bBuffer.Length); - for (int i = 0; i < bBuffer.Length; i++) - Assert.That(Marshal.ReadByte(buffer, i) == bBuffer[i]); - - Assert.That(io.tellProc(handle) == stream.Position); - Assert.That(io.seekProc(handle, 0, SeekOrigin.Begin) == 0); - Assert.That(io.tellProc(handle) == stream.Position); - - rand.NextBytes(bBuffer); - for (int i = 0; i < bBuffer.Length; i++) - Marshal.WriteByte(buffer, i, bBuffer[i]); - - // Write one block - - Assert.That(io.writeProc(buffer, (uint)bBuffer.Length, 1, handle) == 1); - for (int i = 0; i < bBuffer.Length; i++) - Assert.That(Marshal.ReadByte(buffer, i) == bBuffer[i]); - Assert.That(io.tellProc(handle) == stream.Position); - - Assert.That(io.seekProc(handle, 0, SeekOrigin.Begin) == 0); - Assert.That(io.tellProc(handle) == 0); - - // write 1 byte block - - Assert.That(io.writeProc(buffer, 1, (uint)bBuffer.Length, handle) == bBuffer.Length); - for (int i = 0; i < bBuffer.Length; i++) - Assert.That(Marshal.ReadByte(buffer, i) == bBuffer[i]); - Assert.That(io.tellProc(handle) == stream.Position); - - // Seek and tell - - Assert.That(io.seekProc(handle, 0, SeekOrigin.Begin) == 0); - Assert.That(io.tellProc(handle) == 0); - - Assert.That(io.seekProc(handle, 127, SeekOrigin.Current) == 0); - Assert.That(io.tellProc(handle) == 127); - - Assert.That(io.seekProc(handle, 0, SeekOrigin.End) == 0); - Assert.That(io.tellProc(handle) == 256); - - Marshal.FreeHGlobal(buffer); - stream.Dispose(); - } - } - - [Test] - public void MetadataTag() - { - FITAG tag; - MetadataTag metaTag; - - Random rand = new Random(); - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.IsFalse(dib.IsNull); - - Assert.That(FreeImage.GetMetadataCount(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib) > 0); - - FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib, out tag); - Assert.IsFalse(tag.IsNull); - Assert.IsFalse(mData.IsNull); - - // - // Constructors - // - - metaTag = new MetadataTag(tag, dib); - Assert.That(metaTag.Model == FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN); - - metaTag = new MetadataTag(tag, FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN); - Assert.That(metaTag.Model == FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN); - - // - // Properties - // - - metaTag.ID = ushort.MinValue; - Assert.That(metaTag.ID == ushort.MinValue); - - metaTag.ID = ushort.MaxValue; - Assert.That(metaTag.ID == ushort.MaxValue); - - metaTag.ID = ushort.MaxValue / 2; - Assert.That(metaTag.ID == ushort.MaxValue / 2); - - metaTag.Description = ""; - Assert.That(metaTag.Description == ""); - - metaTag.Description = "A"; - Assert.That(metaTag.Description == "A"); - - metaTag.Description = "ABCDEFG"; - Assert.That(metaTag.Description == "ABCDEFG"); - - metaTag.Key = ""; - Assert.That(metaTag.Key == ""); - - metaTag.Key = "A"; - Assert.That(metaTag.Key == "A"); - - metaTag.Key = "ABCDEFG"; - Assert.That(metaTag.Key == "ABCDEFG"); - - // - // SetValue - // - - try - { - metaTag.SetValue(null, FREE_IMAGE_MDTYPE.FIDT_ASCII); - Assert.Fail(); - } - catch - { - } - - // - // FREE_IMAGE_MDTYPE.FIDT_ASCII - // - - string testString = ""; - - Assert.IsTrue(metaTag.SetValue(testString, FREE_IMAGE_MDTYPE.FIDT_ASCII)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((string)metaTag.Value).Length == 0); - - testString = "X"; - - Assert.IsTrue(metaTag.SetValue(testString, FREE_IMAGE_MDTYPE.FIDT_ASCII)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((string)metaTag.Value).Length == testString.Length); - Assert.That(((string)metaTag.Value) == testString); - - testString = "TEST-STRING"; - - Assert.IsTrue(metaTag.SetValue(testString, FREE_IMAGE_MDTYPE.FIDT_ASCII)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((string)metaTag.Value).Length == testString.Length); - Assert.That(((string)metaTag.Value) == testString); - - // - // FREE_IMAGE_MDTYPE.FIDT_BYTE - // - - byte testByte; - byte[] testByteArray; - - Assert.IsTrue(metaTag.SetValue(byte.MinValue, FREE_IMAGE_MDTYPE.FIDT_BYTE)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((byte[])metaTag.Value).Length == 1); - Assert.That(((byte[])metaTag.Value)[0] == byte.MinValue); - - Assert.IsTrue(metaTag.SetValue(byte.MaxValue, FREE_IMAGE_MDTYPE.FIDT_BYTE)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((byte[])metaTag.Value).Length == 1); - Assert.That(((byte[])metaTag.Value)[0] == byte.MaxValue); - - for (int i = 0; i < 10; i++) - { - testByte = (byte)rand.Next(byte.MinValue, byte.MaxValue); - testByteArray = new byte[rand.Next(0, 31)]; - - for (int j = 0; j < testByteArray.Length; j++) - testByteArray[j] = (byte)rand.Next(); - - Assert.IsTrue(metaTag.SetValue(testByte, FREE_IMAGE_MDTYPE.FIDT_BYTE)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((byte[])metaTag.Value).Length == 1); - Assert.That(metaTag.Count == 1); - Assert.That(metaTag.Length == 1); - Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_BYTE); - Assert.That(((byte[])metaTag.Value)[0] == testByte); - - Assert.IsTrue(metaTag.SetValue(testByteArray, FREE_IMAGE_MDTYPE.FIDT_BYTE)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((byte[])metaTag.Value).Length == testByteArray.Length); - Assert.That(metaTag.Count == testByteArray.Length); - Assert.That(metaTag.Length == testByteArray.Length * 1); - - byte[] value = (byte[])metaTag.Value; - - for (int j = 0; j < value.Length; j++) - Assert.That(testByteArray[j] == value[j]); - } - - // - // FREE_IMAGE_MDTYPE.FIDT_DOUBLE - // - - double testDouble; - double[] testDoubleArray; - - Assert.IsTrue(metaTag.SetValue(double.MinValue, FREE_IMAGE_MDTYPE.FIDT_DOUBLE)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((double[])metaTag.Value).Length == 1); - Assert.That(((double[])metaTag.Value)[0] == double.MinValue); - - Assert.IsTrue(metaTag.SetValue(double.MaxValue, FREE_IMAGE_MDTYPE.FIDT_DOUBLE)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((double[])metaTag.Value).Length == 1); - Assert.That(((double[])metaTag.Value)[0] == double.MaxValue); - - for (int i = 0; i < 10; i++) - { - testDouble = (double)rand.NextDouble(); - testDoubleArray = new double[rand.Next(0, 31)]; - - for (int j = 0; j < testDoubleArray.Length; j++) - testDoubleArray[j] = rand.NextDouble(); - - Assert.IsTrue(metaTag.SetValue(testDouble, FREE_IMAGE_MDTYPE.FIDT_DOUBLE)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((double[])metaTag.Value).Length == 1); - Assert.That(metaTag.Count == 1); - Assert.That(metaTag.Length == 8); - Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_DOUBLE); - Assert.That(((double[])metaTag.Value)[0] == testDouble); - - Assert.IsTrue(metaTag.SetValue(testDoubleArray, FREE_IMAGE_MDTYPE.FIDT_DOUBLE)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((double[])metaTag.Value).Length == testDoubleArray.Length); - Assert.That(metaTag.Count == testDoubleArray.Length); - Assert.That(metaTag.Length == testDoubleArray.Length * 8); - - double[] value = (double[])metaTag.Value; - - for (int j = 0; j < value.Length; j++) - Assert.That(testDoubleArray[j] == value[j]); - } - - // - // FREE_IMAGE_MDTYPE.FIDT_FLOAT - // - - float testfloat; - float[] testFloatArray; - - Assert.IsTrue(metaTag.SetValue(float.MinValue, FREE_IMAGE_MDTYPE.FIDT_FLOAT)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((float[])metaTag.Value).Length == 1); - Assert.That(((float[])metaTag.Value)[0] == float.MinValue); - - Assert.IsTrue(metaTag.SetValue(float.MaxValue, FREE_IMAGE_MDTYPE.FIDT_FLOAT)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((float[])metaTag.Value).Length == 1); - Assert.That(((float[])metaTag.Value)[0] == float.MaxValue); - - for (int i = 0; i < 10; i++) - { - testfloat = (float)rand.NextDouble(); - testFloatArray = new float[rand.Next(0, 31)]; - - for (int j = 0; j < testFloatArray.Length; j++) - testFloatArray[j] = (float)rand.NextDouble(); - - Assert.IsTrue(metaTag.SetValue(testfloat, FREE_IMAGE_MDTYPE.FIDT_FLOAT)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((float[])metaTag.Value).Length == 1); - Assert.That(metaTag.Count == 1); - Assert.That(metaTag.Length == 4); - Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_FLOAT); - Assert.That(((float[])metaTag.Value)[0] == testfloat); - - Assert.IsTrue(metaTag.SetValue(testFloatArray, FREE_IMAGE_MDTYPE.FIDT_FLOAT)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((float[])metaTag.Value).Length == testFloatArray.Length); - Assert.That(metaTag.Count == testFloatArray.Length); - Assert.That(metaTag.Length == testFloatArray.Length * 4); - - float[] value = (float[])metaTag.Value; - - for (int j = 0; j < value.Length; j++) - Assert.That(testFloatArray[j] == value[j]); - } - - // - // FREE_IMAGE_MDTYPE.FIDT_IFD - // - - uint testUint; - uint[] testUintArray; - - Assert.IsTrue(metaTag.SetValue(uint.MinValue, FREE_IMAGE_MDTYPE.FIDT_IFD)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((uint[])metaTag.Value).Length == 1); - Assert.That(((uint[])metaTag.Value)[0] == uint.MinValue); - - Assert.IsTrue(metaTag.SetValue(uint.MaxValue, FREE_IMAGE_MDTYPE.FIDT_IFD)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((uint[])metaTag.Value).Length == 1); - Assert.That(((uint[])metaTag.Value)[0] == uint.MaxValue); - - for (int i = 0; i < 10; i++) - { - testUint = (uint)rand.NextDouble(); - testUintArray = new uint[rand.Next(0, 31)]; - - for (int j = 0; j < testUintArray.Length; j++) - testUintArray[j] = (uint)rand.Next(); - - Assert.IsTrue(metaTag.SetValue(testUint, FREE_IMAGE_MDTYPE.FIDT_IFD)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((uint[])metaTag.Value).Length == 1); - Assert.That(metaTag.Count == 1); - Assert.That(metaTag.Length == 4); - Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_IFD); - Assert.That(((uint[])metaTag.Value)[0] == testUint); - - Assert.IsTrue(metaTag.SetValue(testUintArray, FREE_IMAGE_MDTYPE.FIDT_IFD)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((uint[])metaTag.Value).Length == testUintArray.Length); - Assert.That(metaTag.Count == testUintArray.Length); - Assert.That(metaTag.Length == testUintArray.Length * 4); - - uint[] value = (uint[])metaTag.Value; - - for (int j = 0; j < value.Length; j++) - Assert.That(testUintArray[j] == value[j]); - } - - // - // FREE_IMAGE_MDTYPE.FIDT_LONG - // - - Assert.IsTrue(metaTag.SetValue(uint.MinValue, FREE_IMAGE_MDTYPE.FIDT_LONG)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((uint[])metaTag.Value).Length == 1); - Assert.That(((uint[])metaTag.Value)[0] == uint.MinValue); - - Assert.IsTrue(metaTag.SetValue(uint.MaxValue, FREE_IMAGE_MDTYPE.FIDT_LONG)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((uint[])metaTag.Value).Length == 1); - Assert.That(((uint[])metaTag.Value)[0] == uint.MaxValue); - - for (int i = 0; i < 10; i++) - { - testUint = (uint)rand.NextDouble(); - testUintArray = new uint[rand.Next(0, 31)]; - - for (int j = 0; j < testUintArray.Length; j++) - testUintArray[j] = (uint)rand.Next(); - - Assert.IsTrue(metaTag.SetValue(testUint, FREE_IMAGE_MDTYPE.FIDT_LONG)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((uint[])metaTag.Value).Length == 1); - Assert.That(metaTag.Count == 1); - Assert.That(metaTag.Length == 4); - Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_LONG); - Assert.That(((uint[])metaTag.Value)[0] == testUint); - - Assert.IsTrue(metaTag.SetValue(testUintArray, FREE_IMAGE_MDTYPE.FIDT_LONG)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((uint[])metaTag.Value).Length == testUintArray.Length); - Assert.That(metaTag.Count == testUintArray.Length); - Assert.That(metaTag.Length == testUintArray.Length * 4); - - uint[] value = (uint[])metaTag.Value; - - for (int j = 0; j < value.Length; j++) - Assert.That(testUintArray[j] == value[j]); - } - - // - // FREE_IMAGE_MDTYPE.FIDT_NOTYPE - // - - try - { - metaTag.SetValue(new object(), FREE_IMAGE_MDTYPE.FIDT_NOTYPE); - Assert.Fail(); - } - catch (NotSupportedException) - { - } - - // - // FREE_IMAGE_MDTYPE.FIDT_PALETTE - // - - RGBQUAD testRGBQUAD; - RGBQUAD[] testRGBQUADArray; - - for (int i = 0; i < 10; i++) - { - testRGBQUAD = new RGBQUAD(Color.FromArgb(rand.Next())); - testRGBQUADArray = new RGBQUAD[rand.Next(0, 31)]; - - for (int j = 0; j < testRGBQUADArray.Length; j++) - testRGBQUADArray[j] = new RGBQUAD(Color.FromArgb(rand.Next())); - - Assert.IsTrue(metaTag.SetValue(testRGBQUAD, FREE_IMAGE_MDTYPE.FIDT_PALETTE)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((RGBQUAD[])metaTag.Value).Length == 1); - Assert.That(metaTag.Count == 1); - Assert.That(metaTag.Length == 4); - Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_PALETTE); - Assert.That(((RGBQUAD[])metaTag.Value)[0] == testRGBQUAD); - - Assert.IsTrue(metaTag.SetValue(testRGBQUADArray, FREE_IMAGE_MDTYPE.FIDT_PALETTE)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((RGBQUAD[])metaTag.Value).Length == testRGBQUADArray.Length); - Assert.That(metaTag.Count == testRGBQUADArray.Length); - Assert.That(metaTag.Length == testRGBQUADArray.Length * 4); - - RGBQUAD[] value = (RGBQUAD[])metaTag.Value; - - for (int j = 0; j < value.Length; j++) - Assert.That(testRGBQUADArray[j] == value[j]); - } - - // - // FREE_IMAGE_MDTYPE.FIDT_RATIONAL - // - - FIURational testFIURational; - FIURational[] testFIURationalArray; - - for (int i = 0; i < 10; i++) - { - testFIURational = new FIURational((uint)rand.Next(), (uint)rand.Next()); - testFIURationalArray = new FIURational[rand.Next(0, 31)]; - - for (int j = 0; j < testFIURationalArray.Length; j++) - testFIURationalArray[j] = new FIURational((uint)rand.Next(), (uint)rand.Next()); - - Assert.IsTrue(metaTag.SetValue(testFIURational, FREE_IMAGE_MDTYPE.FIDT_RATIONAL)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((FIURational[])metaTag.Value).Length == 1); - Assert.That(metaTag.Count == 1); - Assert.That(metaTag.Length == 8); - Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_RATIONAL); - Assert.That(((FIURational[])metaTag.Value)[0] == testFIURational); - - Assert.IsTrue(metaTag.SetValue(testFIURationalArray, FREE_IMAGE_MDTYPE.FIDT_RATIONAL)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((FIURational[])metaTag.Value).Length == testFIURationalArray.Length); - Assert.That(metaTag.Count == testFIURationalArray.Length); - Assert.That(metaTag.Length == testFIURationalArray.Length * 8); - - FIURational[] value = (FIURational[])metaTag.Value; - - for (int j = 0; j < value.Length; j++) - Assert.That(testFIURationalArray[j] == value[j]); - } - - // - // FREE_IMAGE_MDTYPE.FIDT_SBYTE - // - - sbyte testSByte; - sbyte[] testSByteArray; - - Assert.IsTrue(metaTag.SetValue(sbyte.MinValue, FREE_IMAGE_MDTYPE.FIDT_SBYTE)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((sbyte[])metaTag.Value).Length == 1); - Assert.That(((sbyte[])metaTag.Value)[0] == sbyte.MinValue); - - Assert.IsTrue(metaTag.SetValue(sbyte.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SBYTE)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((sbyte[])metaTag.Value).Length == 1); - Assert.That(((sbyte[])metaTag.Value)[0] == sbyte.MaxValue); - - for (int i = 0; i < 10; i++) - { - testSByte = (sbyte)rand.Next(sbyte.MinValue, sbyte.MaxValue); - testSByteArray = new sbyte[rand.Next(0, 31)]; - - for (int j = 0; j < testSByteArray.Length; j++) - testSByteArray[j] = (sbyte)rand.Next(); - - Assert.IsTrue(metaTag.SetValue(testSByte, FREE_IMAGE_MDTYPE.FIDT_SBYTE)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((sbyte[])metaTag.Value).Length == 1); - Assert.That(metaTag.Count == 1); - Assert.That(metaTag.Length == 1); - Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SBYTE); - Assert.That(((sbyte[])metaTag.Value)[0] == testSByte); - - Assert.IsTrue(metaTag.SetValue(testSByteArray, FREE_IMAGE_MDTYPE.FIDT_SBYTE)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((sbyte[])metaTag.Value).Length == testSByteArray.Length); - Assert.That(metaTag.Count == testSByteArray.Length); - Assert.That(metaTag.Length == testSByteArray.Length * 1); - - sbyte[] value = (sbyte[])metaTag.Value; - - for (int j = 0; j < value.Length; j++) - Assert.That(testSByteArray[j] == value[j]); - } - - // - // FREE_IMAGE_MDTYPE.FIDT_SHORT - // - - ushort testUShort; - ushort[] testUShortArray; - - Assert.IsTrue(metaTag.SetValue(ushort.MinValue, FREE_IMAGE_MDTYPE.FIDT_SHORT)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((ushort[])metaTag.Value).Length == 1); - Assert.That(((ushort[])metaTag.Value)[0] == ushort.MinValue); - - Assert.IsTrue(metaTag.SetValue(ushort.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SHORT)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((ushort[])metaTag.Value).Length == 1); - Assert.That(((ushort[])metaTag.Value)[0] == ushort.MaxValue); - - for (int i = 0; i < 10; i++) - { - testUShort = (ushort)rand.Next(ushort.MinValue, sbyte.MaxValue); - testUShortArray = new ushort[rand.Next(0, 31)]; - - for (int j = 0; j < testUShortArray.Length; j++) - testUShortArray[j] = (ushort)rand.Next(); - - Assert.IsTrue(metaTag.SetValue(testUShort, FREE_IMAGE_MDTYPE.FIDT_SHORT)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((ushort[])metaTag.Value).Length == 1); - Assert.That(metaTag.Count == 1); - Assert.That(metaTag.Length == 2); - Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SHORT); - Assert.That(((ushort[])metaTag.Value)[0] == testUShort); - - Assert.IsTrue(metaTag.SetValue(testUShortArray, FREE_IMAGE_MDTYPE.FIDT_SHORT)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((ushort[])metaTag.Value).Length == testUShortArray.Length); - Assert.That(metaTag.Count == testUShortArray.Length); - Assert.That(metaTag.Length == testUShortArray.Length * 2); - - ushort[] value = (ushort[])metaTag.Value; - - for (int j = 0; j < value.Length; j++) - Assert.That(testUShortArray[j] == value[j]); - } - - // - // FREE_IMAGE_MDTYPE.FIDT_SLONG - // - - int testInt; - int[] testIntArray; - - Assert.IsTrue(metaTag.SetValue(int.MinValue, FREE_IMAGE_MDTYPE.FIDT_SLONG)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((int[])metaTag.Value).Length == 1); - Assert.That(((int[])metaTag.Value)[0] == int.MinValue); - - Assert.IsTrue(metaTag.SetValue(int.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SLONG)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((int[])metaTag.Value).Length == 1); - Assert.That(((int[])metaTag.Value)[0] == int.MaxValue); - - for (int i = 0; i < 10; i++) - { - testInt = (int)rand.NextDouble(); - testIntArray = new int[rand.Next(0, 31)]; - - for (int j = 0; j < testIntArray.Length; j++) - testIntArray[j] = rand.Next(); - - Assert.IsTrue(metaTag.SetValue(testInt, FREE_IMAGE_MDTYPE.FIDT_SLONG)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((int[])metaTag.Value).Length == 1); - Assert.That(metaTag.Count == 1); - Assert.That(metaTag.Length == 4); - Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SLONG); - Assert.That(((int[])metaTag.Value)[0] == testInt); - - Assert.IsTrue(metaTag.SetValue(testIntArray, FREE_IMAGE_MDTYPE.FIDT_SLONG)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((int[])metaTag.Value).Length == testIntArray.Length); - Assert.That(metaTag.Count == testIntArray.Length); - Assert.That(metaTag.Length == testIntArray.Length * 4); - - int[] value = (int[])metaTag.Value; - - for (int j = 0; j < value.Length; j++) - Assert.That(testIntArray[j] == value[j]); - } - - // - // FREE_IMAGE_MDTYPE.FIDT_SRATIONAL - // - - FIRational testFIRational; - FIRational[] testFIRationalArray; - - for (int i = 0; i < 10; i++) - { - testFIRational = new FIRational(rand.Next(), rand.Next()); - testFIRationalArray = new FIRational[rand.Next(0, 31)]; - - for (int j = 0; j < testFIRationalArray.Length; j++) - testFIRationalArray[j] = new FIRational(rand.Next(), rand.Next()); - - Assert.IsTrue(metaTag.SetValue(testFIRational, FREE_IMAGE_MDTYPE.FIDT_SRATIONAL)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((FIRational[])metaTag.Value).Length == 1); - Assert.That(metaTag.Count == 1); - Assert.That(metaTag.Length == 8); - Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SRATIONAL); - Assert.That(((FIRational[])metaTag.Value)[0] == testFIRational); - - Assert.IsTrue(metaTag.SetValue(testFIRationalArray, FREE_IMAGE_MDTYPE.FIDT_SRATIONAL)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((FIRational[])metaTag.Value).Length == testFIRationalArray.Length); - Assert.That(metaTag.Count == testFIRationalArray.Length); - Assert.That(metaTag.Length == testFIRationalArray.Length * 8); - - FIRational[] value = (FIRational[])metaTag.Value; - - for (int j = 0; j < value.Length; j++) - Assert.That(testFIRationalArray[j] == value[j]); - } - - // - // FREE_IMAGE_MDTYPE.FIDT_SSHORT - // - - short testShort; - short[] testShortArray; - - Assert.IsTrue(metaTag.SetValue(short.MinValue, FREE_IMAGE_MDTYPE.FIDT_SSHORT)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((short[])metaTag.Value).Length == 1); - Assert.That(((short[])metaTag.Value)[0] == short.MinValue); - - Assert.IsTrue(metaTag.SetValue(short.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SSHORT)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((short[])metaTag.Value).Length == 1); - Assert.That(((short[])metaTag.Value)[0] == short.MaxValue); - - for (int i = 0; i < 10; i++) - { - testShort = (short)rand.Next(short.MinValue, short.MaxValue); - testShortArray = new short[rand.Next(0, 31)]; - - for (int j = 0; j < testShortArray.Length; j++) - testShortArray[j] = (short)rand.Next(); - - Assert.IsTrue(metaTag.SetValue(testShort, FREE_IMAGE_MDTYPE.FIDT_SSHORT)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((short[])metaTag.Value).Length == 1); - Assert.That(metaTag.Count == 1); - Assert.That(metaTag.Length == 2); - Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SSHORT); - Assert.That(((short[])metaTag.Value)[0] == testShort); - - Assert.IsTrue(metaTag.SetValue(testShortArray, FREE_IMAGE_MDTYPE.FIDT_SSHORT)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((short[])metaTag.Value).Length == testShortArray.Length); - Assert.That(metaTag.Count == testShortArray.Length); - Assert.That(metaTag.Length == testShortArray.Length * 2); - - short[] value = (short[])metaTag.Value; - - for (int j = 0; j < value.Length; j++) - Assert.That(testShortArray[j] == value[j]); - } - - // - // FREE_IMAGE_MDTYPE.FIDT_UNDEFINED - // - - Assert.IsTrue(metaTag.SetValue(byte.MinValue, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((byte[])metaTag.Value).Length == 1); - Assert.That(((byte[])metaTag.Value)[0] == byte.MinValue); - - Assert.IsTrue(metaTag.SetValue(byte.MaxValue, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((byte[])metaTag.Value).Length == 1); - Assert.That(((byte[])metaTag.Value)[0] == byte.MaxValue); - - for (int i = 0; i < 10; i++) - { - testByte = (byte)rand.Next(byte.MinValue, byte.MaxValue); - testByteArray = new byte[rand.Next(0, 31)]; - - for (int j = 0; j < testByteArray.Length; j++) - testByteArray[j] = (byte)rand.Next(); - - Assert.IsTrue(metaTag.SetValue(testByte, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((byte[])metaTag.Value).Length == 1); - Assert.That(metaTag.Count == 1); - Assert.That(metaTag.Length == 1); - Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_UNDEFINED); - Assert.That(((byte[])metaTag.Value)[0] == testByte); - - Assert.IsTrue(metaTag.SetValue(testByteArray, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED)); - Assert.IsNotNull(metaTag.Value); - Assert.That(((byte[])metaTag.Value).Length == testByteArray.Length); - Assert.That(metaTag.Count == testByteArray.Length); - Assert.That(metaTag.Length == testByteArray.Length * 1); - - byte[] value = (byte[])metaTag.Value; - - for (int j = 0; j < value.Length; j++) - Assert.That(testByteArray[j] == value[j]); - } - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void MetadataModel() - { - MetadataTag tag; - dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - - MetadataModel model = new MDM_GEOTIFF(dib); - Assert.AreEqual(0, model.Count); - Assert.IsFalse(model.Exists); - Assert.IsEmpty(model.List); - Assert.AreEqual(model.Model, FREE_IMAGE_MDMODEL.FIMD_GEOTIFF); - Assert.IsTrue(model.DestoryModel()); - foreach (MetadataTag m in model) Assert.Fail(); - - tag = new MetadataTag(FREE_IMAGE_MDMODEL.FIMD_GEOTIFF); - tag.Key = "KEY"; - tag.Value = 54321f; - Assert.IsTrue(model.AddTag(tag)); - - Assert.AreEqual(1, model.Count); - Assert.IsTrue(model.Exists); - Assert.IsNotEmpty(model.List); - Assert.AreEqual(model.Model, FREE_IMAGE_MDMODEL.FIMD_GEOTIFF); - - Assert.IsTrue(model.DestoryModel()); - Assert.AreEqual(0, model.Count); - Assert.IsFalse(model.Exists); - Assert.IsEmpty(model.List); - Assert.AreEqual(model.Model, FREE_IMAGE_MDMODEL.FIMD_GEOTIFF); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void ImageMetadata() - { - ImageMetadata metadata; - List modelList; - MetadataTag tag = new MetadataTag(FREE_IMAGE_MDMODEL.FIMD_COMMENTS); - tag.Key = "KEY"; - tag.ID = 11; - tag.Value = new double[] { 0d, 41d, -523d, -0.41d }; - - dib = FreeImage.Allocate(1, 1, 1, 1, 0, 0); - Assert.IsFalse(dib.IsNull); - - metadata = new ImageMetadata(dib, true); - Assert.AreEqual(0, metadata.Count); - Assert.IsTrue(metadata.HideEmptyModels); - Assert.IsEmpty(metadata.List); - - metadata = new ImageMetadata(dib, false); - Assert.AreEqual(FreeImage.FREE_IMAGE_MDMODELS.Length, metadata.Count); - Assert.IsFalse(metadata.HideEmptyModels); - Assert.IsNotEmpty(metadata.List); - - metadata.HideEmptyModels = true; - metadata.AddTag(tag); - - Assert.AreEqual(1, metadata.Count); - Assert.IsNotEmpty(metadata.List); - - modelList = metadata.List; - Assert.AreEqual(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, modelList[0].Model); - - System.Collections.IEnumerator enumerator = metadata.GetEnumerator(); - Assert.IsTrue(enumerator.MoveNext()); - Assert.IsNotNull((MetadataModel)enumerator.Current); - Assert.IsFalse(enumerator.MoveNext()); - - FreeImage.UnloadEx(ref dib); - } - } - - [TestFixture] - public class WrapperFunctionsTest - { - ImageManager iManager = new ImageManager(); - FIBITMAP dib = new FIBITMAP(); - string freeImageCallback = null; - - [TestFixtureSetUp] - public void Init() - { - FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); - } - - [TestFixtureTearDown] - public void DeInit() - { - FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); - } - - [SetUp] - public void InitEachTime() - { - } - - [TearDown] - public void DeInitEachTime() - { - } - - void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) - { - freeImageCallback = message; - } - - public bool EqualColors(Color color1, Color color2) - { - if (color1.A != color2.A) return false; - if (color1.R != color2.R) return false; - if (color1.G != color2.G) return false; - if (color1.B != color2.B) return false; - return true; - } - - // - // Tests - // - - [Test] - public void FreeImage_GetWrapperVersion() - { - //Assert.That(FreeImage.GetWrapperVersion() == - // String.Format("{0}.{1}.{2}", - // FreeImage.FREEIMAGE_MAJOR_VERSION, - // FreeImage.FREEIMAGE_MINOR_VERSION, - // FreeImage.FREEIMAGE_RELEASE_SERIAL)); - } - - [Test] - public void FreeImage_IsAvailable() - { - Assert.IsTrue(FreeImage.IsAvailable()); - } - - [Test] - public void FreeImage_GetBitmap() - { - Bitmap bitmap = null; - - try - { - bitmap = FreeImage.GetBitmap(new FIBITMAP()); - } - catch - { - } - Assert.IsNull(bitmap); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - - bitmap = FreeImage.GetBitmap(dib); - Assert.IsNotNull(bitmap); - Assert.AreEqual((int)FreeImage.GetHeight(dib), bitmap.Height); - Assert.AreEqual((int)FreeImage.GetWidth(dib), bitmap.Width); - - bitmap.Dispose(); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_CreateFromBitmap() - { - Bitmap bitmap = (Bitmap)Bitmap.FromFile(iManager.GetBitmapPath(ImageType.Odd, ImageColorType.Type_24)); - Assert.IsNotNull(bitmap); - - dib = FreeImage.CreateFromBitmap(bitmap); - Assert.That(!dib.IsNull); - - Assert.AreEqual((int)FreeImage.GetHeight(dib), bitmap.Height); - Assert.AreEqual((int)FreeImage.GetWidth(dib), bitmap.Width); - - bitmap.Dispose(); - FreeImage.UnloadEx(ref dib); - - try - { - dib = FreeImage.CreateFromBitmap(null); - Assert.Fail(); - } - catch - { - } - } - - [Test] - public void FreeImage_SaveBitmap() - { - Bitmap bitmap = (Bitmap)Bitmap.FromFile(iManager.GetBitmapPath(ImageType.Odd, ImageColorType.Type_24)); - Assert.IsNotNull(bitmap); - - Assert.IsTrue(FreeImage.SaveBitmap(bitmap, @"test.png", FREE_IMAGE_FORMAT.FIF_PNG, FREE_IMAGE_SAVE_FLAGS.DEFAULT)); - bitmap.Dispose(); - - Assert.IsTrue(File.Exists(@"test.png")); - - dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PNG, @"test.png", FREE_IMAGE_LOAD_FLAGS.DEFAULT); - Assert.That(!dib.IsNull); - - FreeImage.UnloadEx(ref dib); - - File.Delete(@"test.png"); - Assert.IsFalse(File.Exists(@"test.png")); - bitmap.Dispose(); - } - - [Test] - public void FreeImage_LoadEx() - { - dib = FreeImage.LoadEx(iManager.GetBitmapPath(ImageType.Odd, ImageColorType.Type_16_555)); - Assert.That(!dib.IsNull); - FreeImage.UnloadEx(ref dib); - - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_TIFF; - - dib = FreeImage.LoadEx(iManager.GetBitmapPath(ImageType.Odd, ImageColorType.Type_16_565), ref format); - Assert.That(dib.IsNull); - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_TIFF, format); - FreeImage.UnloadEx(ref dib); - - format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - dib = FreeImage.LoadEx(iManager.GetBitmapPath(ImageType.JPEG, ImageColorType.Type_16_565), - FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); - Assert.That(!dib.IsNull); - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_JPEG, format); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_UnloadEx() - { - Assert.That(dib.IsNull); - FreeImage.UnloadEx(ref dib); - Assert.That(dib.IsNull); - - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_16_555); - Assert.That(!dib.IsNull); - - FreeImage.UnloadEx(ref dib); - Assert.That(dib.IsNull); - } - - [Test] - public void FreeImage_SaveEx() - { - FREE_IMAGE_FORMAT format; - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08); - Assert.That(!dib.IsNull); - - Assert.IsTrue(FreeImage.SaveEx(dib, @"test.png")); - Assert.IsTrue(File.Exists(@"test.png")); - format = FreeImage.GetFileType(@"test.png", 0); - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_PNG, format); - File.Delete(@"test.png"); - Assert.IsFalse(File.Exists(@"test.png")); - - Assert.IsTrue(FreeImage.SaveEx(ref dib, @"test.tiff", FREE_IMAGE_SAVE_FLAGS.DEFAULT, false)); - Assert.IsTrue(File.Exists(@"test.tiff")); - format = FreeImage.GetFileType(@"test.tiff", 0); - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_TIFF, format); - File.Delete(@"test.tiff"); - Assert.IsFalse(File.Exists(@"test.tiff")); - - Assert.IsTrue(FreeImage.SaveEx( - ref dib, - @"test.gif", - FREE_IMAGE_FORMAT.FIF_UNKNOWN, - FREE_IMAGE_SAVE_FLAGS.DEFAULT, - FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP, - false)); - - Assert.IsTrue(File.Exists(@"test.gif")); - format = FreeImage.GetFileType(@"test.gif", 0); - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_GIF, format); - File.Delete(@"test.gif"); - Assert.IsFalse(File.Exists(@"test.gif")); - - Assert.IsFalse(FreeImage.SaveEx(dib, @"")); - Assert.IsFalse(FreeImage.SaveEx(dib, @"test.test")); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_LoadFromStream() - { - FREE_IMAGE_FORMAT format; - FileStream fStream; - - fStream = new FileStream(iManager.GetBitmapPath(ImageType.Odd, ImageColorType.Type_16_565), FileMode.Open); - Assert.IsNotNull(fStream); - - dib = FreeImage.LoadFromStream(fStream); - Assert.That(!dib.IsNull); - Assert.That(FreeImage.GetBPP(dib) == 16); - Assert.That(FreeImage.GetGreenMask(dib) == FreeImage.FI16_565_GREEN_MASK); - - FreeImage.UnloadEx(ref dib); - fStream.Close(); - - fStream = new FileStream(iManager.GetBitmapPath(ImageType.Metadata, ImageColorType.Type_01_Dither), FileMode.Open); - Assert.IsNotNull(fStream); - - format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - dib = FreeImage.LoadFromStream(fStream, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); - Assert.That(!dib.IsNull); - Assert.That(FreeImage.GetBPP(dib) == 24); - Assert.That(format == FREE_IMAGE_FORMAT.FIF_JPEG); - FreeImage.UnloadEx(ref dib); - fStream.Close(); - - fStream = new FileStream(iManager.GetBitmapPath(ImageType.Even, ImageColorType.Type_32), FileMode.Open); - format = FREE_IMAGE_FORMAT.FIF_TIFF; - dib = FreeImage.LoadFromStream(fStream, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); - Assert.That(!dib.IsNull); - Assert.That(FreeImage.GetBPP(dib) == 32); - Assert.That(format == FREE_IMAGE_FORMAT.FIF_TIFF); - - FreeImage.UnloadEx(ref dib); - - Assert.That(dib.IsNull); - dib = FreeImage.LoadFromStream(new MemoryStream(new byte[] { })); - Assert.That(dib.IsNull); - - format = FREE_IMAGE_FORMAT.FIF_BMP; - fStream.Position = 0; - dib = FreeImage.LoadFromStream(fStream, ref format); - Assert.That(dib.IsNull); - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_BMP, format); - - fStream.Close(); - } - - [Test] - public void FreeImage_SaveToStream() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_08_Greyscale_MinIsBlack); - Assert.That(!dib.IsNull); - - Stream stream = new FileStream(@"out_stream.bmp", FileMode.Create); - Assert.IsNotNull(stream); - - Assert.IsTrue(FreeImage.SaveEx(ref dib, @"out_file.bmp", FREE_IMAGE_FORMAT.FIF_BMP, false)); - Assert.IsTrue(FreeImage.SaveToStream(dib, stream, FREE_IMAGE_FORMAT.FIF_BMP)); - stream.Flush(); - stream.Dispose(); - - Assert.IsTrue(File.Exists(@"out_stream.bmp")); - Assert.IsTrue(File.Exists(@"out_file.bmp")); - byte[] buffer1 = File.ReadAllBytes(@"out_stream.bmp"); - byte[] buffer2 = File.ReadAllBytes(@"out_file.bmp"); - Assert.AreEqual(buffer1.Length, buffer2.Length); - for (int i = 0; i < buffer1.Length; i++) - if (buffer1[i] != buffer2[i]) - Assert.Fail(); - - File.Delete(@"out_stream.bmp"); - File.Delete(@"out_file.bmp"); - Assert.IsFalse(File.Exists(@"out_stream.bmp")); - Assert.IsFalse(File.Exists(@"out_file.bmp")); - - stream = new MemoryStream(); - Assert.IsFalse(FreeImage.SaveToStream(dib, stream, FREE_IMAGE_FORMAT.FIF_FAXG3)); - stream.Dispose(); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_IsExtensionValidForFIF() - { - Assert.IsTrue(FreeImage.IsExtensionValidForFIF(FREE_IMAGE_FORMAT.FIF_BMP, "bmp", StringComparison.CurrentCultureIgnoreCase)); - Assert.IsTrue(FreeImage.IsExtensionValidForFIF(FREE_IMAGE_FORMAT.FIF_BMP, "BMP", StringComparison.CurrentCultureIgnoreCase)); - Assert.IsFalse(FreeImage.IsExtensionValidForFIF(FREE_IMAGE_FORMAT.FIF_BMP, "DUMMY", StringComparison.CurrentCultureIgnoreCase)); - Assert.IsTrue(FreeImage.IsExtensionValidForFIF(FREE_IMAGE_FORMAT.FIF_PCX, "pcx", StringComparison.CurrentCultureIgnoreCase)); - Assert.IsTrue(FreeImage.IsExtensionValidForFIF(FREE_IMAGE_FORMAT.FIF_TIFF, "tif", StringComparison.CurrentCultureIgnoreCase)); - Assert.IsTrue(FreeImage.IsExtensionValidForFIF(FREE_IMAGE_FORMAT.FIF_TIFF, "TIFF", StringComparison.CurrentCultureIgnoreCase)); - Assert.IsFalse(FreeImage.IsExtensionValidForFIF(FREE_IMAGE_FORMAT.FIF_ICO, "ICO", StringComparison.CurrentCulture)); - } - - [Test] - public void FreeImage_IsFilenameValidForFIF() - { - Assert.IsTrue(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_JPEG, "file.jpg")); - Assert.IsTrue(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_JPEG, "file.jpeg")); - Assert.IsFalse(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_JPEG, "file.bmp")); - Assert.IsTrue(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_GIF, "file.gif")); - Assert.IsTrue(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_GIF, "file.GIF")); - Assert.IsTrue(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_GIF, "file.GIF", StringComparison.CurrentCultureIgnoreCase)); - Assert.IsFalse(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_GIF, "file.txt")); - Assert.IsFalse(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_UNKNOWN, "file.jpg")); - Assert.IsFalse(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_UNKNOWN, "file.bmp")); - Assert.IsFalse(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_UNKNOWN, "file.tif")); - } - - [Test] - public void FreeImage_GetPrimaryExtensionFromFIF() - { - Assert.AreEqual("gif", FreeImage.GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT.FIF_GIF)); - Assert.AreEqual("tif", FreeImage.GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT.FIF_TIFF)); - Assert.AreNotEqual("tiff", FreeImage.GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT.FIF_TIFF)); - Assert.AreEqual("psd", FreeImage.GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT.FIF_PSD)); - Assert.AreEqual("iff", FreeImage.GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT.FIF_IFF)); - Assert.IsNull(FreeImage.GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT.FIF_UNKNOWN)); - } - - [Test] - public void FreeImage_OpenMultiBitmapEx() - { - FIMULTIBITMAP dib = FreeImage.OpenMultiBitmapEx(iManager.GetBitmapPath(ImageType.Multipaged, ImageColorType.Type_01_Dither)); - Assert.IsFalse(dib.IsNull); - Assert.AreEqual(4, FreeImage.GetPageCount(dib)); - FreeImage.CloseMultiBitmap(dib, FREE_IMAGE_SAVE_FLAGS.DEFAULT); - - FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - dib = FreeImage.OpenMultiBitmapEx( - iManager.GetBitmapPath(ImageType.Multipaged, ImageColorType.Type_04), ref format, FREE_IMAGE_LOAD_FLAGS.DEFAULT, - false, true, true); - Assert.IsFalse(dib.IsNull); - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_TIFF, format); - FreeImage.CloseMultiBitmap(dib, FREE_IMAGE_SAVE_FLAGS.DEFAULT); - } - - [Test] - public void FreeImage_GetLockedPageCount() - { - FIMULTIBITMAP dib = FreeImage.OpenMultiBitmapEx(iManager.GetBitmapPath(ImageType.Multipaged, ImageColorType.Type_01_Dither)); - FIBITMAP page1, page2, page3; - Assert.IsFalse(dib.IsNull); - Assert.AreEqual(4, FreeImage.GetPageCount(dib)); - Assert.AreEqual(0, FreeImage.GetLockedPageCount(dib)); - - page1 = FreeImage.LockPage(dib, 0); - Assert.AreEqual(1, FreeImage.GetLockedPageCount(dib)); - - page2 = FreeImage.LockPage(dib, 1); - Assert.AreEqual(2, FreeImage.GetLockedPageCount(dib)); - - page3 = FreeImage.LockPage(dib, 2); - Assert.AreEqual(3, FreeImage.GetLockedPageCount(dib)); - - FreeImage.UnlockPage(dib, page3, true); - Assert.AreEqual(2, FreeImage.GetLockedPageCount(dib)); - - FreeImage.UnlockPage(dib, page2, true); - Assert.AreEqual(1, FreeImage.GetLockedPageCount(dib)); - - FreeImage.UnlockPage(dib, page1, true); - Assert.AreEqual(0, FreeImage.GetLockedPageCount(dib)); - - FreeImage.CloseMultiBitmapEx(ref dib); - } - - [Test] - public void FreeImage_GetLockedPages() - { - FIMULTIBITMAP dib = FreeImage.OpenMultiBitmapEx(iManager.GetBitmapPath(ImageType.Multipaged, ImageColorType.Type_01_Dither)); - FIBITMAP page1, page2, page3; - int[] lockedList; - Assert.IsFalse(dib.IsNull); - Assert.AreEqual(4, FreeImage.GetPageCount(dib)); - Assert.AreEqual(0, FreeImage.GetLockedPageCount(dib)); - - page1 = FreeImage.LockPage(dib, 0); - Assert.AreEqual(1, FreeImage.GetLockedPageCount(dib)); - lockedList = FreeImage.GetLockedPages(dib); - Assert.Contains(0, lockedList); - - page2 = FreeImage.LockPage(dib, 1); - Assert.AreEqual(2, FreeImage.GetLockedPageCount(dib)); - lockedList = FreeImage.GetLockedPages(dib); - Assert.Contains(0, lockedList); - Assert.Contains(1, lockedList); - - page3 = FreeImage.LockPage(dib, 3); - Assert.AreEqual(3, FreeImage.GetLockedPageCount(dib)); - lockedList = FreeImage.GetLockedPages(dib); - Assert.Contains(0, lockedList); - Assert.Contains(1, lockedList); - Assert.Contains(3, lockedList); - - FreeImage.UnlockPage(dib, page2, true); - Assert.AreEqual(2, FreeImage.GetLockedPageCount(dib)); - lockedList = FreeImage.GetLockedPages(dib); - Assert.Contains(0, lockedList); - Assert.Contains(3, lockedList); - - FreeImage.UnlockPage(dib, page1, true); - Assert.AreEqual(1, FreeImage.GetLockedPageCount(dib)); - lockedList = FreeImage.GetLockedPages(dib); - Assert.Contains(3, lockedList); - - FreeImage.UnlockPage(dib, page3, true); - Assert.AreEqual(0, FreeImage.GetLockedPageCount(dib)); - lockedList = FreeImage.GetLockedPages(dib); - Assert.AreEqual(0, lockedList.Length); - - FreeImage.CloseMultiBitmapEx(ref dib); - } - - [Test] - public void FreeImage_GetFileTypeFromStream() - { - FileStream fStream = new FileStream(iManager.GetBitmapPath(ImageType.JPEG, ImageColorType.Type_01_Dither), FileMode.Open); - Assert.IsNotNull(fStream); - - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_JPEG, FreeImage.GetFileTypeFromStream(fStream)); - fStream.Dispose(); - - fStream = new FileStream(iManager.GetBitmapPath(ImageType.Odd, ImageColorType.Type_16_565), FileMode.Open); - Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_BMP, FreeImage.GetFileTypeFromStream(fStream)); - fStream.Close(); - } - - [Test] - public void FreeImage_GetHbitmap() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); - Assert.IsFalse(dib.IsNull); - - IntPtr hBitmap = FreeImage.GetHbitmap(dib, IntPtr.Zero, false); - Bitmap bitmap = Bitmap.FromHbitmap(hBitmap); - Assert.IsNotNull(bitmap); - Assert.AreEqual(FreeImage.GetWidth(dib), bitmap.Width); - Assert.AreEqual(FreeImage.GetHeight(dib), bitmap.Height); - - bitmap.Dispose(); - FreeImage.FreeHbitmap(hBitmap); - FreeImage.UnloadEx(ref dib); - - try - { - hBitmap = FreeImage.GetHbitmap(dib, IntPtr.Zero, false); - Assert.Fail(); - } - catch - { - } - } - - [Test] - public void FreeImage_GetResolutionX() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); - Assert.IsFalse(dib.IsNull); - - Assert.AreEqual(72, FreeImage.GetResolutionX(dib)); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetResolutionY() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); - Assert.IsFalse(dib.IsNull); - - Assert.AreEqual(72, FreeImage.GetResolutionY(dib)); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetResolutionX() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); - Assert.IsFalse(dib.IsNull); - - Assert.AreEqual(72, FreeImage.GetResolutionX(dib)); - - FreeImage.SetResolutionX(dib, 12u); - Assert.AreEqual(12, FreeImage.GetResolutionX(dib)); - - FreeImage.SetResolutionX(dib, 1u); - Assert.AreEqual(1, FreeImage.GetResolutionX(dib)); - - FreeImage.SetResolutionX(dib, 66u); - Assert.AreEqual(66, FreeImage.GetResolutionX(dib)); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetResolutionY() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); - Assert.IsFalse(dib.IsNull); - - Assert.AreEqual(72, FreeImage.GetResolutionY(dib)); - - FreeImage.SetResolutionY(dib, 12u); - Assert.AreEqual(12, FreeImage.GetResolutionY(dib)); - - FreeImage.SetResolutionY(dib, 1u); - Assert.AreEqual(1, FreeImage.GetResolutionY(dib)); - - FreeImage.SetResolutionY(dib, 66u); - Assert.AreEqual(66, FreeImage.GetResolutionY(dib)); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_IsGreyscaleImage() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.IsFalse(FreeImage.IsGreyscaleImage(dib)); - FreeImage.UnloadEx(ref dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04_Greyscale_Unordered); - Assert.IsTrue(FreeImage.IsGreyscaleImage(dib)); - FreeImage.UnloadEx(ref dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04_Greyscale_MinIsBlack); - Assert.IsTrue(FreeImage.IsGreyscaleImage(dib)); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetPaletteEx() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Palette palette = null; - - try - { - palette = FreeImage.GetPaletteEx(dib); - Assert.Fail(); - } - catch - { - } - FreeImage.UnloadEx(ref dib); - - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_08_Greyscale_MinIsBlack); - try - { - palette = FreeImage.GetPaletteEx(dib); - } - catch - { - Assert.Fail(); - } - Assert.AreEqual(256, palette.Length); - for (int index = 0; index < 256; index++) - { - Assert.AreEqual(index, palette[index].rgbRed); - Assert.AreEqual(index, palette[index].rgbGreen); - Assert.AreEqual(index, palette[index].rgbBlue); - } - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetInfoHeaderEx() - { - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04); - Assert.IsFalse(dib.IsNull); - - BITMAPINFOHEADER iHeader = FreeImage.GetInfoHeaderEx(dib); - Assert.AreEqual(4, iHeader.biBitCount); - Assert.AreEqual(FreeImage.GetWidth(dib), iHeader.biWidth); - Assert.AreEqual(FreeImage.GetHeight(dib), iHeader.biHeight); - FreeImage.UnloadEx(ref dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_01_Dither); - Assert.IsFalse(dib.IsNull); - - iHeader = FreeImage.GetInfoHeaderEx(dib); - Assert.AreEqual(1, iHeader.biBitCount); - Assert.AreEqual(FreeImage.GetWidth(dib), iHeader.biWidth); - Assert.AreEqual(FreeImage.GetHeight(dib), iHeader.biHeight); - FreeImage.UnloadEx(ref dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.IsFalse(dib.IsNull); - - iHeader = FreeImage.GetInfoHeaderEx(dib); - Assert.AreEqual(24, iHeader.biBitCount); - Assert.AreEqual(FreeImage.GetWidth(dib), iHeader.biWidth); - Assert.AreEqual(FreeImage.GetHeight(dib), iHeader.biHeight); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetInfoEx() - { - BITMAPINFO info; - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_01_Dither); - Assert.That(!dib.IsNull); - info = FreeImage.GetInfoEx(dib); - Assert.AreEqual(FreeImage.GetBPP(dib), info.bmiHeader.biBitCount); - Assert.AreEqual(FreeImage.GetWidth(dib), info.bmiHeader.biWidth); - Assert.AreEqual(FreeImage.GetHeight(dib), info.bmiHeader.biHeight); - FreeImage.UnloadEx(ref dib); - - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_04_Greyscale_MinIsBlack); - Assert.That(!dib.IsNull); - info = FreeImage.GetInfoEx(dib); - Assert.AreEqual(FreeImage.GetBPP(dib), info.bmiHeader.biBitCount); - Assert.AreEqual(FreeImage.GetWidth(dib), info.bmiHeader.biWidth); - Assert.AreEqual(FreeImage.GetHeight(dib), info.bmiHeader.biHeight); - FreeImage.UnloadEx(ref dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_Unordered); - Assert.That(!dib.IsNull); - info = FreeImage.GetInfoEx(dib); - Assert.AreEqual(FreeImage.GetBPP(dib), info.bmiHeader.biBitCount); - Assert.AreEqual(FreeImage.GetWidth(dib), info.bmiHeader.biWidth); - Assert.AreEqual(FreeImage.GetHeight(dib), info.bmiHeader.biHeight); - FreeImage.UnloadEx(ref dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_16_555); - Assert.That(!dib.IsNull); - info = FreeImage.GetInfoEx(dib); - Assert.AreEqual(FreeImage.GetBPP(dib), info.bmiHeader.biBitCount); - Assert.AreEqual(FreeImage.GetWidth(dib), info.bmiHeader.biWidth); - Assert.AreEqual(FreeImage.GetHeight(dib), info.bmiHeader.biHeight); - FreeImage.UnloadEx(ref dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_16_565); - Assert.That(!dib.IsNull); - info = FreeImage.GetInfoEx(dib); - Assert.AreEqual(FreeImage.GetBPP(dib), info.bmiHeader.biBitCount); - Assert.AreEqual(FreeImage.GetWidth(dib), info.bmiHeader.biWidth); - Assert.AreEqual(FreeImage.GetHeight(dib), info.bmiHeader.biHeight); - FreeImage.UnloadEx(ref dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); - Assert.That(!dib.IsNull); - info = FreeImage.GetInfoEx(dib); - Assert.AreEqual(FreeImage.GetBPP(dib), info.bmiHeader.biBitCount); - Assert.AreEqual(FreeImage.GetWidth(dib), info.bmiHeader.biWidth); - Assert.AreEqual(FreeImage.GetHeight(dib), info.bmiHeader.biHeight); - FreeImage.UnloadEx(ref dib); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.That(!dib.IsNull); - info = FreeImage.GetInfoEx(dib); - Assert.AreEqual(FreeImage.GetBPP(dib), info.bmiHeader.biBitCount); - Assert.AreEqual(FreeImage.GetWidth(dib), info.bmiHeader.biWidth); - Assert.AreEqual(FreeImage.GetHeight(dib), info.bmiHeader.biHeight); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetPixelFormat() - { - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_01_Threshold); - Assert.IsFalse(dib.IsNull); - - Assert.AreEqual(PixelFormat.Format1bppIndexed, FreeImage.GetPixelFormat(dib)); - FreeImage.UnloadEx(ref dib); - - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_04_Greyscale_Unordered); - Assert.IsFalse(dib.IsNull); - - Assert.AreEqual(PixelFormat.Format4bppIndexed, FreeImage.GetPixelFormat(dib)); - FreeImage.UnloadEx(ref dib); - - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_16_555); - Assert.IsFalse(dib.IsNull); - - Assert.AreEqual(PixelFormat.Format16bppRgb555, FreeImage.GetPixelFormat(dib)); - FreeImage.UnloadEx(ref dib); - - dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_16_565); - Assert.IsFalse(dib.IsNull); - - Assert.AreEqual(PixelFormat.Format16bppRgb565, FreeImage.GetPixelFormat(dib)); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetFormatParameters() - { - uint bpp, red, green, blue; - FREE_IMAGE_TYPE type; - - Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format16bppArgb1555, out type, out bpp, out red, out green, out blue)); - Assert.AreEqual(16, bpp); - Assert.AreEqual(red, FreeImage.FI16_555_RED_MASK); - Assert.AreEqual(green, FreeImage.FI16_555_GREEN_MASK); - Assert.AreEqual(blue, FreeImage.FI16_555_BLUE_MASK); - Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); - - Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format16bppGrayScale, out type, out bpp, out red, out green, out blue)); - Assert.AreEqual(16, bpp); - Assert.AreEqual(red, 0); - Assert.AreEqual(green, 0); - Assert.AreEqual(blue, 0); - Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_UINT16); - - Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format16bppRgb555, out type, out bpp, out red, out green, out blue)); - Assert.AreEqual(16, bpp); - Assert.AreEqual(red, FreeImage.FI16_555_RED_MASK); - Assert.AreEqual(green, FreeImage.FI16_555_GREEN_MASK); - Assert.AreEqual(blue, FreeImage.FI16_555_BLUE_MASK); - Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); - - Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format16bppRgb565, out type, out bpp, out red, out green, out blue)); - Assert.AreEqual(16, bpp); - Assert.AreEqual(red, FreeImage.FI16_565_RED_MASK); - Assert.AreEqual(green, FreeImage.FI16_565_GREEN_MASK); - Assert.AreEqual(blue, FreeImage.FI16_565_BLUE_MASK); - Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); - - Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format1bppIndexed, out type, out bpp, out red, out green, out blue)); - Assert.AreEqual(1, bpp); - Assert.AreEqual(red, 0); - Assert.AreEqual(green, 0); - Assert.AreEqual(blue, 0); - Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); - - Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format24bppRgb, out type, out bpp, out red, out green, out blue)); - Assert.AreEqual(24, bpp); - Assert.AreEqual(red, FreeImage.FI_RGBA_RED_MASK); - Assert.AreEqual(green, FreeImage.FI_RGBA_GREEN_MASK); - Assert.AreEqual(blue, FreeImage.FI_RGBA_BLUE_MASK); - Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); - - Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format32bppArgb, out type, out bpp, out red, out green, out blue)); - Assert.AreEqual(32, bpp); - Assert.AreEqual(red, FreeImage.FI_RGBA_RED_MASK); - Assert.AreEqual(green, FreeImage.FI_RGBA_GREEN_MASK); - Assert.AreEqual(blue, FreeImage.FI_RGBA_BLUE_MASK); - Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); - - Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format32bppPArgb, out type, out bpp, out red, out green, out blue)); - Assert.AreEqual(32, bpp); - Assert.AreEqual(red, FreeImage.FI_RGBA_RED_MASK); - Assert.AreEqual(green, FreeImage.FI_RGBA_GREEN_MASK); - Assert.AreEqual(blue, FreeImage.FI_RGBA_BLUE_MASK); - Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); - - Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format32bppRgb, out type, out bpp, out red, out green, out blue)); - Assert.AreEqual(32, bpp); - Assert.AreEqual(red, FreeImage.FI_RGBA_RED_MASK); - Assert.AreEqual(green, FreeImage.FI_RGBA_GREEN_MASK); - Assert.AreEqual(blue, FreeImage.FI_RGBA_BLUE_MASK); - Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); - - Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format48bppRgb, out type, out bpp, out red, out green, out blue)); - Assert.AreEqual(48, bpp); - Assert.AreEqual(red, 0); - Assert.AreEqual(green, 0); - Assert.AreEqual(blue, 0); - Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_RGB16); - - Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format4bppIndexed, out type, out bpp, out red, out green, out blue)); - Assert.AreEqual(4, bpp); - Assert.AreEqual(red, 0); - Assert.AreEqual(green, 0); - Assert.AreEqual(blue, 0); - Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); - - Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format64bppArgb, out type, out bpp, out red, out green, out blue)); - Assert.AreEqual(64, bpp); - Assert.AreEqual(red, 0); - Assert.AreEqual(green, 0); - Assert.AreEqual(blue, 0); - Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_RGBA16); - - Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format64bppPArgb, out type, out bpp, out red, out green, out blue)); - Assert.AreEqual(64, bpp); - Assert.AreEqual(red, 0); - Assert.AreEqual(green, 0); - Assert.AreEqual(blue, 0); - Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_RGBA16); - - Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format8bppIndexed, out type, out bpp, out red, out green, out blue)); - Assert.AreEqual(8, bpp); - Assert.AreEqual(red, 0); - Assert.AreEqual(green, 0); - Assert.AreEqual(blue, 0); - Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); - } - - [Test] - public void FreeImage_Compare() - { - FIBITMAP dib2; - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_01_Dither); - Assert.IsFalse(dib.IsNull); - dib2 = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_01_Threshold); - Assert.IsFalse(dib2.IsNull); - - Assert.IsFalse(FreeImage.Compare(dib, dib2, FREE_IMAGE_COMPARE_FLAGS.COMPLETE)); - Assert.IsTrue(FreeImage.Compare(dib, dib2, FREE_IMAGE_COMPARE_FLAGS.HEADER)); - - FreeImage.UnloadEx(ref dib); - FreeImage.UnloadEx(ref dib2); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04_Greyscale_MinIsBlack); - dib2 = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04_Greyscale_Unordered); - - Assert.IsFalse(FreeImage.Compare(dib, dib2, FREE_IMAGE_COMPARE_FLAGS.COMPLETE)); - - FreeImage.UnloadEx(ref dib); - FreeImage.UnloadEx(ref dib2); - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - dib2 = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); - Assert.IsTrue(FreeImage.Compare(dib, dib2, FREE_IMAGE_COMPARE_FLAGS.COMPLETE)); - - FreeImage.UnloadEx(ref dib); - FreeImage.UnloadEx(ref dib2); - - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.IsFalse(dib.IsNull); - dib2 = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.IsFalse(dib2.IsNull); - - Assert.IsTrue(FreeImage.Compare(dib, dib2, FREE_IMAGE_COMPARE_FLAGS.COMPLETE)); - - FreeImage.UnloadEx(ref dib); - FreeImage.UnloadEx(ref dib2); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_16_555); - Assert.IsFalse(dib.IsNull); - dib2 = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_16_555); - Assert.IsFalse(dib2.IsNull); - - Assert.IsTrue(FreeImage.Compare(dib, dib2, FREE_IMAGE_COMPARE_FLAGS.COMPLETE)); - - FreeImage.UnloadEx(ref dib); - FreeImage.UnloadEx(ref dib2); - - dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_16_565); - Assert.IsFalse(dib.IsNull); - dib2 = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_16_565); - Assert.IsFalse(dib2.IsNull); - - Assert.IsTrue(FreeImage.Compare(dib, dib2, FREE_IMAGE_COMPARE_FLAGS.COMPLETE)); - - FreeImage.UnloadEx(ref dib); - FreeImage.UnloadEx(ref dib2); - } - - [Test] - public void FreeImage_CreateICCProfileEx() - { - FIICCPROFILE prof; - byte[] data = new byte[173]; - Random rand = new Random(DateTime.Now.Millisecond); - dib = FreeImage.AllocateT(FREE_IMAGE_TYPE.FIT_BITMAP, 1, 1, 1, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - - prof = FreeImage.GetICCProfileEx(dib); - Assert.That(prof.DataPointer == IntPtr.Zero); - - rand.NextBytes(data); - prof = FreeImage.CreateICCProfileEx(dib, data); - Assert.That(prof.Size == data.Length); - for (int i = 0; i < data.Length; i++) - if (prof.Data[i] != data[i]) - Assert.Fail(); - - FreeImage.DestroyICCProfile(dib); - prof = FreeImage.GetICCProfileEx(dib); - Assert.That(prof.DataPointer == IntPtr.Zero); - - FreeImage.CreateICCProfileEx(dib, new byte[0], 0); - prof = FreeImage.GetICCProfileEx(dib); - Assert.That(prof.DataPointer == IntPtr.Zero); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_ConvertColorDepth() - { - int bpp = 1; - FIBITMAP dib2; - - dib = FreeImage.AllocateT(FREE_IMAGE_TYPE.FIT_BITMAP, 80, 80, 1, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - - do - { - dib2 = FreeImage.ConvertColorDepth(dib, (FREE_IMAGE_COLOR_DEPTH)bpp); - Assert.IsFalse(dib2.IsNull); - Assert.AreEqual(bpp, FreeImage.GetBPP(dib2)); - if (dib != dib2) - FreeImage.UnloadEx(ref dib2); - } while (0 != (bpp = FreeImage.GetNextColorDepth(bpp))); - - FreeImage.UnloadEx(ref dib); - - dib = FreeImage.AllocateT(FREE_IMAGE_TYPE.FIT_BITMAP, 80, 80, 32, - FreeImage.FI_RGBA_RED_MASK, FreeImage.FI_RGBA_GREEN_MASK, FreeImage.FI_RGBA_BLUE_MASK); - Assert.IsFalse(dib.IsNull); - bpp = 32; - - do - { - dib2 = FreeImage.ConvertColorDepth(dib, (FREE_IMAGE_COLOR_DEPTH)bpp); - Assert.IsFalse(dib2.IsNull); - Assert.AreEqual(bpp, FreeImage.GetBPP(dib2)); - if (dib != dib2) - FreeImage.UnloadEx(ref dib2); - } while (0 != (bpp = FreeImage.GetPrevousColorDepth(bpp))); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetNextColorDepth() - { - Assert.AreEqual(0, FreeImage.GetNextColorDepth(5)); - Assert.AreEqual(0, FreeImage.GetNextColorDepth(0)); - Assert.AreEqual(4, FreeImage.GetNextColorDepth(1)); - Assert.AreEqual(8, FreeImage.GetNextColorDepth(4)); - Assert.AreEqual(16, FreeImage.GetNextColorDepth(8)); - Assert.AreEqual(24, FreeImage.GetNextColorDepth(16)); - Assert.AreEqual(32, FreeImage.GetNextColorDepth(24)); - Assert.AreEqual(0, FreeImage.GetNextColorDepth(32)); - } - - [Test] - public void FreeImage_GetPrevousColorDepth() - { - Assert.AreEqual(0, FreeImage.GetNextColorDepth(5)); - Assert.AreEqual(0, FreeImage.GetNextColorDepth(0)); - Assert.AreEqual(4, FreeImage.GetNextColorDepth(1)); - Assert.AreEqual(8, FreeImage.GetNextColorDepth(4)); - Assert.AreEqual(16, FreeImage.GetNextColorDepth(8)); - Assert.AreEqual(24, FreeImage.GetNextColorDepth(16)); - Assert.AreEqual(32, FreeImage.GetNextColorDepth(24)); - Assert.AreEqual(0, FreeImage.GetNextColorDepth(32)); - } - - [Test] - public unsafe void FreeImage_PtrToStr() - { - string testString; - string resString; - IntPtr buffer; - int index; - - testString = "Test string"; - buffer = Marshal.AllocHGlobal(testString.Length + 1); - - for (index = 0; index < testString.Length; index++) - { - Marshal.WriteByte(buffer, index, (byte)testString[index]); - } - Marshal.WriteByte(buffer, index, (byte)0); - - resString = FreeImage.PtrToStr((byte*)buffer); - Assert.That(resString == testString); - - Marshal.FreeHGlobal(buffer); - - testString = @"äöü?=§%/!)§(%&)(§"; - buffer = Marshal.AllocHGlobal(testString.Length + 1); - - for (index = 0; index < testString.Length; index++) - { - Marshal.WriteByte(buffer, index, (byte)testString[index]); - } - Marshal.WriteByte(buffer, index, (byte)0); - - resString = FreeImage.PtrToStr((byte*)buffer); - Assert.That(resString == testString); - - Marshal.FreeHGlobal(buffer); - } - - [Test] - public void FreeImage_CopyMetadata() - { - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.IsFalse(dib.IsNull); - int mdCount = 0; - - FIBITMAP dib2 = FreeImage.Allocate(1, 1, 1, 0, 0, 0); - Assert.IsFalse(dib2.IsNull); - - FREE_IMAGE_MDMODEL[] modelList = (FREE_IMAGE_MDMODEL[])Enum.GetValues(typeof(FREE_IMAGE_MDMODEL)); - FITAG tag, tag2; - FIMETADATA mdHandle; - - foreach (FREE_IMAGE_MDMODEL model in modelList) - { - mdHandle = FreeImage.FindFirstMetadata(model, dib2, out tag); - Assert.IsTrue(mdHandle.IsNull); - mdCount += (int)FreeImage.GetMetadataCount(model, dib); - } - - Assert.AreEqual(mdCount, FreeImage.CloneMetadataEx(dib, dib2, FREE_IMAGE_METADATA_COPY.CLEAR_EXISTING)); - - foreach (FREE_IMAGE_MDMODEL model in modelList) - { - mdHandle = FreeImage.FindFirstMetadata(model, dib, out tag); - if (!mdHandle.IsNull) - { - do - { - Assert.IsTrue(FreeImage.GetMetadata(model, dib2, FreeImage.GetTagKey(tag), out tag2)); - Assert.That(FreeImage.GetTagCount(tag) == FreeImage.GetTagCount(tag2)); - Assert.That(FreeImage.GetTagDescription(tag) == FreeImage.GetTagDescription(tag2)); - Assert.That(FreeImage.GetTagID(tag) == FreeImage.GetTagID(tag2)); - Assert.That(FreeImage.GetTagKey(tag) == FreeImage.GetTagKey(tag2)); - Assert.That(FreeImage.GetTagLength(tag) == FreeImage.GetTagLength(tag2)); - Assert.That(FreeImage.GetTagType(tag) == FreeImage.GetTagType(tag2)); - } - while (FreeImage.FindNextMetadata(mdHandle, out tag)); - FreeImage.FindCloseMetadata(mdHandle); - } - } - - Assert.AreEqual(0, FreeImage.CloneMetadataEx(dib, dib2, FREE_IMAGE_METADATA_COPY.KEEP_EXISITNG)); - - foreach (FREE_IMAGE_MDMODEL model in modelList) - { - mdHandle = FreeImage.FindFirstMetadata(model, dib, out tag); - if (!mdHandle.IsNull) - { - do - { - Assert.IsTrue(FreeImage.GetMetadata(model, dib2, FreeImage.GetTagKey(tag), out tag2)); - Assert.AreEqual(FreeImage.GetTagCount(tag), FreeImage.GetTagCount(tag2)); - Assert.AreEqual(FreeImage.GetTagDescription(tag), FreeImage.GetTagDescription(tag2)); - Assert.AreEqual(FreeImage.GetTagID(tag), FreeImage.GetTagID(tag2)); - Assert.AreEqual(FreeImage.GetTagKey(tag), FreeImage.GetTagKey(tag2)); - Assert.AreEqual(FreeImage.GetTagLength(tag), FreeImage.GetTagLength(tag2)); - Assert.AreEqual(FreeImage.GetTagType(tag), FreeImage.GetTagType(tag2)); - } - while (FreeImage.FindNextMetadata(mdHandle, out tag)); - FreeImage.FindCloseMetadata(mdHandle); - } - } - - const string newTagDescription = "NEW_TAG_DESCRIPTION"; - - Assert.IsTrue(FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib, "Copyright", out tag)); - Assert.IsTrue(FreeImage.SetTagDescription(tag, newTagDescription)); - Assert.AreEqual(mdCount, FreeImage.CloneMetadataEx(dib, dib2, FREE_IMAGE_METADATA_COPY.REPLACE_EXISTING)); - Assert.IsTrue(FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib2, "Copyright", out tag2)); - Assert.AreEqual(newTagDescription, FreeImage.GetTagDescription(tag2)); - - FreeImage.UnloadEx(ref dib2); - FreeImage.UnloadEx(ref dib); - - dib2 = FreeImage.Allocate(1, 1, 1, 0, 0, 0); - dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); - - Assert.AreEqual(0, FreeImage.CloneMetadataEx(dib, dib2, FREE_IMAGE_METADATA_COPY.CLEAR_EXISTING)); - - FreeImage.UnloadEx(ref dib2); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetImageComment() - { - dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - const string comment = "C O M M E N T"; - - Assert.IsNull(FreeImage.GetImageComment(dib)); - Assert.IsTrue(FreeImage.SetImageComment(dib, comment)); - Assert.AreEqual(comment, FreeImage.GetImageComment(dib)); - Assert.IsTrue(FreeImage.SetImageComment(dib, null)); - Assert.IsNull(FreeImage.GetImageComment(dib)); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetImageComment() - { - dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - const string comment = "C O M M E N T"; - - Assert.IsNull(FreeImage.GetImageComment(dib)); - Assert.IsTrue(FreeImage.SetImageComment(dib, comment)); - Assert.AreEqual(comment, FreeImage.GetImageComment(dib)); - Assert.IsTrue(FreeImage.SetImageComment(dib, null)); - Assert.IsNull(FreeImage.GetImageComment(dib)); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetMetadata() - { - MetadataTag tag; - - dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); - Assert.IsFalse(dib.IsNull); - - Assert.IsFalse(FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib, "~~~~~", out tag)); - Assert.IsNull(tag); - - Assert.IsTrue(FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib, "Artist", out tag)); - Assert.IsFalse(tag.tag.IsNull); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetMetadata() - { - MetadataTag tag; - Random rand = new Random(); - - dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - - ushort value = (ushort)rand.Next(); - - tag = new MetadataTag(FREE_IMAGE_MDMODEL.FIMD_CUSTOM); - tag.ID = value; - - Assert.IsTrue(FreeImage.SetMetadata(FREE_IMAGE_MDMODEL.FIMD_CUSTOM, dib, "~~~~~", tag)); - Assert.IsTrue(FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_CUSTOM, dib, "~~~~~", out tag)); - Assert.AreEqual(value, tag.ID); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_FindFirstMetadata() - { - MetadataTag tag; - FIMETADATA mdHandle; - dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - - FREE_IMAGE_MDMODEL[] models = (FREE_IMAGE_MDMODEL[])Enum.GetValues(typeof(FREE_IMAGE_MDMODEL)); - foreach (FREE_IMAGE_MDMODEL model in models) - { - mdHandle = FreeImage.FindFirstMetadata(model, dib, out tag); - Assert.IsTrue(mdHandle.IsNull); - } - - tag = new MetadataTag(FREE_IMAGE_MDMODEL.FIMD_COMMENTS); - tag.Key = "KEY"; - tag.Value = 12345; - tag.AddToImage(dib); - - mdHandle = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, out tag); - Assert.IsFalse(mdHandle.IsNull); - - FreeImage.FindCloseMetadata(mdHandle); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_FindNextMetadata() - { - MetadataTag tag; - FIMETADATA mdHandle; - dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - - FREE_IMAGE_MDMODEL[] models = (FREE_IMAGE_MDMODEL[])Enum.GetValues(typeof(FREE_IMAGE_MDMODEL)); - foreach (FREE_IMAGE_MDMODEL model in models) - { - mdHandle = FreeImage.FindFirstMetadata(model, dib, out tag); - Assert.IsTrue(mdHandle.IsNull); - } - - tag = new MetadataTag(FREE_IMAGE_MDMODEL.FIMD_COMMENTS); - tag.Key = "KEY1"; - tag.Value = 12345; - tag.AddToImage(dib); - - tag = new MetadataTag(FREE_IMAGE_MDMODEL.FIMD_COMMENTS); - tag.Key = "KEY2"; - tag.Value = 54321; - tag.AddToImage(dib); - - mdHandle = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, out tag); - Assert.IsFalse(mdHandle.IsNull); - - Assert.IsTrue(FreeImage.FindNextMetadata(mdHandle, out tag)); - Assert.IsFalse(FreeImage.FindNextMetadata(mdHandle, out tag)); - - FreeImage.FindCloseMetadata(mdHandle); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_SetGetTransparencyTableEx() - { - dib = FreeImage.Allocate(10, 10, 6, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - - byte[] transTable = FreeImage.GetTransparencyTableEx(dib); - Assert.That(transTable.Length == 0); - - Random rand = new Random(); - transTable = new byte[rand.Next(0, 255)]; - int length = transTable.Length; - - for (int i = 0; i < transTable.Length; i++) - transTable[i] = (byte)i; - - FreeImage.SetTransparencyTable(dib, transTable); - transTable = null; - transTable = FreeImage.GetTransparencyTableEx(dib); - Assert.That(transTable.Length == length); - for (int i = 0; i < transTable.Length; i++) - Assert.That(transTable[i] == i); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_GetUniqueColors() - { - Palette palette; - - // - // 1bpp - // - - dib = FreeImage.Allocate(10, 1, 1, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - - palette = new Palette(dib); - palette[0] = Color.FromArgb(43, 255, 255, 255); - palette[1] = Color.FromArgb(222, 0, 0, 0); - - Scanline sl1bit = new Scanline(dib, 0); - for (int x = 0; x < sl1bit.Length; x++) - { - sl1bit[x] = 0; - } - - Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); - - sl1bit[5] = 1; - Assert.AreEqual(2, FreeImage.GetUniqueColors(dib)); - - palette[1] = Color.FromArgb(222, 255, 255, 255); - Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); - - sl1bit[5] = 0; - Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); - - FreeImage.UnloadEx(ref dib); - - // - // 4bpp - // - - dib = FreeImage.Allocate(10, 1, 4, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - - palette = new Palette(dib); - palette[0] = new RGBQUAD(Color.FromArgb(43, 255, 255, 255)); - palette[1] = new RGBQUAD(Color.FromArgb(222, 51, 2, 211)); - palette[2] = new RGBQUAD(Color.FromArgb(29, 25, 31, 52)); - palette[3] = new RGBQUAD(Color.FromArgb(173, 142, 61, 178)); - palette[4] = new RGBQUAD(Color.FromArgb(143, 41, 67, 199)); - palette[5] = new RGBQUAD(Color.FromArgb(2, 0, 2, 221)); - - Scanline sl4bit = new Scanline(dib, 0); - - for (int x = 0; x < sl4bit.Length; x++) - { - sl4bit[x] = 0; - } - - Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); - - sl4bit[1] = 1; - Assert.AreEqual(2, FreeImage.GetUniqueColors(dib)); - - sl4bit[2] = 1; - Assert.AreEqual(2, FreeImage.GetUniqueColors(dib)); - - sl4bit[3] = 2; - Assert.AreEqual(3, FreeImage.GetUniqueColors(dib)); - - sl4bit[4] = 3; - Assert.AreEqual(4, FreeImage.GetUniqueColors(dib)); - - sl4bit[5] = 4; - Assert.AreEqual(5, FreeImage.GetUniqueColors(dib)); - - sl4bit[6] = 5; - Assert.AreEqual(6, FreeImage.GetUniqueColors(dib)); - - sl4bit[7] = 6; - Assert.AreEqual(7, FreeImage.GetUniqueColors(dib)); - - sl4bit[8] = 7; - Assert.AreEqual(7, FreeImage.GetUniqueColors(dib)); - - sl4bit[9] = 7; - Assert.AreEqual(7, FreeImage.GetUniqueColors(dib)); - - FreeImage.UnloadEx(ref dib); - - // - // 8bpp - // - - dib = FreeImage.Allocate(10, 1, 8, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - - palette = new Palette(dib); - palette[0] = new RGBQUAD(Color.FromArgb(43, 255, 255, 255)); - palette[1] = new RGBQUAD(Color.FromArgb(222, 51, 2, 211)); - palette[2] = new RGBQUAD(Color.FromArgb(29, 25, 31, 52)); - palette[3] = new RGBQUAD(Color.FromArgb(173, 142, 61, 178)); - palette[4] = new RGBQUAD(Color.FromArgb(143, 41, 67, 199)); - palette[5] = new RGBQUAD(Color.FromArgb(2, 0, 2, 221)); - - Scanline sl8bit = new Scanline(dib, 0); - - for (int x = 0; x < sl8bit.Length; x++) - { - sl8bit[x] = 0; - } - - Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); - - sl8bit[1] = 1; - Assert.AreEqual(2, FreeImage.GetUniqueColors(dib)); - - sl8bit[2] = 2; - Assert.AreEqual(3, FreeImage.GetUniqueColors(dib)); - - sl8bit[3] = 3; - Assert.AreEqual(4, FreeImage.GetUniqueColors(dib)); - - sl8bit[4] = 4; - Assert.AreEqual(5, FreeImage.GetUniqueColors(dib)); - - sl8bit[5] = 6; - Assert.AreEqual(6, FreeImage.GetUniqueColors(dib)); - - sl8bit[5] = 7; - Assert.AreEqual(6, FreeImage.GetUniqueColors(dib)); - - sl8bit[5] = 8; - Assert.AreEqual(6, FreeImage.GetUniqueColors(dib)); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_CreateShrunkenPaletteLUT() - { - Random rand = new Random(); - dib = FreeImage.Allocate(1, 1, 8, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - - Palette palette = new Palette(dib); - byte[] lut; - int colors; - - for (int x = 0; x < palette.Length; x++) - { - palette[x] = 0xFF000000; - } - - lut = FreeImage.CreateShrunkenPaletteLUT(dib, out colors); - Assert.AreEqual(1, colors); - - for (int x = 0; x < palette.Length; x++) - { - Assert.AreEqual(0, lut[x]); - } - - palette[1] = 0x00000001; - lut = FreeImage.CreateShrunkenPaletteLUT(dib, out colors); - Assert.AreEqual(2, colors); - - Assert.AreEqual(0, lut[0]); - Assert.AreEqual(1, lut[1]); - - for (int x = 2; x < palette.Length; x++) - { - Assert.AreEqual(0, lut[x]); - } - - for (int x = 0; x < palette.Length; x++) - { - palette[x] = (uint)x; - } - - lut = FreeImage.CreateShrunkenPaletteLUT(dib, out colors); - Assert.AreEqual(256, colors); - - for (int x = 0; x < palette.Length; x++) - { - Assert.AreEqual(x, lut[x]); - } - - uint[] testColors = new uint[] { 0xFF4F387C, 0xFF749178, 0xFF84D51A, 0xFF746B71, 0x74718163, 0x91648106 }; - palette[0] = testColors[0]; - palette[1] = testColors[1]; - palette[2] = testColors[2]; - palette[3] = testColors[3]; - palette[4] = testColors[4]; - palette[5] = testColors[5]; - - for (int x = testColors.Length; x < palette.Length; x++) - { - palette[x] = testColors[rand.Next(0, testColors.Length - 1)]; - } - - lut = FreeImage.CreateShrunkenPaletteLUT(dib, out colors); - Assert.AreEqual(testColors.Length, colors); - - FreeImage.UnloadEx(ref dib); - } - - [Test] - public void FreeImage_Rotate4bit() - { - Palette orgPal, rotPal; - FIBITMAP rotated; - byte index; - dib = FreeImage.Allocate(2, 3, 4, 0, 0, 0); - Assert.IsFalse(dib.IsNull); - - index = 1; if (!FreeImage.SetPixelIndex(dib, 0, 0, ref index)) throw new Exception(); - index = 2; if (!FreeImage.SetPixelIndex(dib, 1, 0, ref index)) throw new Exception(); - index = 3; if (!FreeImage.SetPixelIndex(dib, 0, 1, ref index)) throw new Exception(); - index = 4; if (!FreeImage.SetPixelIndex(dib, 1, 1, ref index)) throw new Exception(); - index = 5; if (!FreeImage.SetPixelIndex(dib, 0, 2, ref index)) throw new Exception(); - index = 6; if (!FreeImage.SetPixelIndex(dib, 1, 2, ref index)) throw new Exception(); - - // - // 90 deg - // - - rotated = FreeImage.Rotate4bit(dib, 90d); - Assert.IsFalse(rotated.IsNull); - Assert.AreEqual(3, FreeImage.GetWidth(rotated)); - Assert.AreEqual(2, FreeImage.GetHeight(rotated)); - Assert.AreEqual(FREE_IMAGE_TYPE.FIT_BITMAP, FreeImage.GetImageType(rotated)); - Assert.AreEqual(4, FreeImage.GetBPP(rotated)); - orgPal = new Palette(dib); - rotPal = new Palette(rotated); - Assert.IsNotNull(orgPal); - Assert.IsNotNull(rotPal); - Assert.AreEqual(orgPal.Length, rotPal.Length); - for (int i = 0; i < orgPal.Length; i++) - { - Assert.AreEqual(orgPal[i], rotPal[i]); - } - - FreeImage.GetPixelIndex(rotated, 0, 0, out index); - Assert.AreEqual(5, index); - FreeImage.GetPixelIndex(rotated, 1, 0, out index); - Assert.AreEqual(3, index); - FreeImage.GetPixelIndex(rotated, 2, 0, out index); - Assert.AreEqual(1, index); - FreeImage.GetPixelIndex(rotated, 0, 1, out index); - Assert.AreEqual(6, index); - FreeImage.GetPixelIndex(rotated, 1, 1, out index); - Assert.AreEqual(4, index); - FreeImage.GetPixelIndex(rotated, 2, 1, out index); - Assert.AreEqual(2, index); - FreeImage.UnloadEx(ref rotated); - - // - // 180 deg - // - - rotated = FreeImage.Rotate4bit(dib, 180d); - Assert.IsFalse(rotated.IsNull); - Assert.AreEqual(FreeImage.GetWidth(dib), FreeImage.GetWidth(rotated)); - Assert.AreEqual(FreeImage.GetHeight(dib), FreeImage.GetHeight(rotated)); - Assert.AreEqual(FREE_IMAGE_TYPE.FIT_BITMAP, FreeImage.GetImageType(rotated)); - Assert.AreEqual(4, FreeImage.GetBPP(rotated)); - orgPal = new Palette(dib); - rotPal = new Palette(rotated); - Assert.IsNotNull(orgPal); - Assert.IsNotNull(rotPal); - Assert.AreEqual(orgPal.Length, rotPal.Length); - for (int i = 0; i < orgPal.Length; i++) - { - Assert.AreEqual(orgPal[i], rotPal[i]); - } - - FreeImage.GetPixelIndex(rotated, 0, 0, out index); - Assert.AreEqual(6, index); - FreeImage.GetPixelIndex(rotated, 1, 0, out index); - Assert.AreEqual(5, index); - FreeImage.GetPixelIndex(rotated, 0, 1, out index); - Assert.AreEqual(4, index); - FreeImage.GetPixelIndex(rotated, 1, 1, out index); - Assert.AreEqual(3, index); - FreeImage.GetPixelIndex(rotated, 0, 2, out index); - Assert.AreEqual(2, index); - FreeImage.GetPixelIndex(rotated, 1, 2, out index); - Assert.AreEqual(1, index); - FreeImage.UnloadEx(ref rotated); - - // - // 270 deg - // - - rotated = FreeImage.Rotate4bit(dib, 270d); - Assert.IsFalse(rotated.IsNull); - Assert.AreEqual(3, FreeImage.GetWidth(rotated)); - Assert.AreEqual(2, FreeImage.GetHeight(rotated)); - Assert.AreEqual(FREE_IMAGE_TYPE.FIT_BITMAP, FreeImage.GetImageType(rotated)); - Assert.AreEqual(4, FreeImage.GetBPP(rotated)); - orgPal = new Palette(dib); - rotPal = new Palette(rotated); - Assert.IsNotNull(orgPal); - Assert.IsNotNull(rotPal); - Assert.AreEqual(orgPal.Length, rotPal.Length); - for (int i = 0; i < orgPal.Length; i++) - { - Assert.AreEqual(orgPal[i], rotPal[i]); - } - - FreeImage.GetPixelIndex(rotated, 0, 0, out index); - Assert.AreEqual(2, index); - FreeImage.GetPixelIndex(rotated, 1, 0, out index); - Assert.AreEqual(4, index); - FreeImage.GetPixelIndex(rotated, 2, 0, out index); - Assert.AreEqual(6, index); - FreeImage.GetPixelIndex(rotated, 0, 1, out index); - Assert.AreEqual(1, index); - FreeImage.GetPixelIndex(rotated, 1, 1, out index); - Assert.AreEqual(3, index); - FreeImage.GetPixelIndex(rotated, 2, 1, out index); - Assert.AreEqual(5, index); - FreeImage.UnloadEx(ref rotated); - - FreeImage.UnloadEx(ref dib); - } - } - - [TestFixture] - public class FreeImageBitmapTest - { - ImageManager iManager = new ImageManager(); - FIBITMAP dib = new FIBITMAP(); - string freeImageCallback = null; - - [TestFixtureSetUp] - public void Init() - { - FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); - } - - [TestFixtureTearDown] - public void DeInit() - { - FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); - } - - [SetUp] - public void InitEachTime() - { - } - - [TearDown] - public void DeInitEachTime() - { - } - - void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) - { - freeImageCallback = message; - } - - [Test] - public void FreeImageBitmapConstructors() - { - Image bitmap; - FreeImageBitmap fib, fib2; - Stream stream; - Graphics g; - string filename = iManager.GetBitmapPath(ImageType.Odd, ImageColorType.Type_24); - Assert.IsNotNull(filename); - Assert.IsTrue(File.Exists(filename)); - - bitmap = new Bitmap(filename); - Assert.IsNotNull(bitmap); - - fib = new FreeImageBitmap(bitmap); - Assert.AreEqual(bitmap.Width, fib.Width); - Assert.AreEqual(bitmap.Height, fib.Height); - fib.Dispose(); - fib.Dispose(); - - fib = new FreeImageBitmap(bitmap, new Size(100, 100)); - Assert.AreEqual(100, fib.Width); - Assert.AreEqual(100, fib.Height); - fib.Dispose(); - bitmap.Dispose(); - - fib = new FreeImageBitmap(filename); - fib.Dispose(); - - fib = new FreeImageBitmap(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT); - fib.Dispose(); - - fib = new FreeImageBitmap(filename, FREE_IMAGE_FORMAT.FIF_UNKNOWN); - fib.Dispose(); - - fib = new FreeImageBitmap(filename, FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_LOAD_FLAGS.DEFAULT); - fib.Dispose(); - - stream = new FileStream(filename, FileMode.Open); - Assert.IsNotNull(stream); - - fib = new FreeImageBitmap(stream); - fib.Dispose(); - stream.Seek(0, SeekOrigin.Begin); - - fib = new FreeImageBitmap(stream, FREE_IMAGE_FORMAT.FIF_UNKNOWN); - fib.Dispose(); - stream.Seek(0, SeekOrigin.Begin); - - fib = new FreeImageBitmap(stream, FREE_IMAGE_LOAD_FLAGS.DEFAULT); - fib.Dispose(); - stream.Seek(0, SeekOrigin.Begin); - - fib = new FreeImageBitmap(stream, FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_LOAD_FLAGS.DEFAULT); - fib.Dispose(); - stream.Dispose(); - - fib = new FreeImageBitmap(100, 100); - Assert.AreEqual(24, fib.ColorDepth); - Assert.AreEqual(100, fib.Width); - Assert.AreEqual(100, fib.Height); - fib.Dispose(); - - using (bitmap = new Bitmap(filename)) - { - Assert.IsNotNull(bitmap); - using (g = Graphics.FromImage(bitmap)) - { - Assert.IsNotNull(g); - fib = new FreeImageBitmap(100, 100, g); - } - } - fib.Dispose(); - - fib = new FreeImageBitmap(100, 100, PixelFormat.Format1bppIndexed); - Assert.AreEqual(PixelFormat.Format1bppIndexed, fib.PixelFormat); - Assert.AreEqual(100, fib.Width); - Assert.AreEqual(100, fib.Height); - fib.Dispose(); - - fib = new FreeImageBitmap(100, 100, PixelFormat.Format4bppIndexed); - Assert.AreEqual(PixelFormat.Format4bppIndexed, fib.PixelFormat); - Assert.AreEqual(100, fib.Width); - Assert.AreEqual(100, fib.Height); - fib.Dispose(); - - fib = new FreeImageBitmap(100, 100, PixelFormat.Format8bppIndexed); - Assert.AreEqual(PixelFormat.Format8bppIndexed, fib.PixelFormat); - Assert.AreEqual(100, fib.Width); - Assert.AreEqual(100, fib.Height); - fib.Dispose(); - - fib = new FreeImageBitmap(100, 100, PixelFormat.Format16bppRgb555); - Assert.AreEqual(PixelFormat.Format16bppRgb555, fib.PixelFormat); - Assert.AreEqual(100, fib.Width); - Assert.AreEqual(100, fib.Height); - fib.Dispose(); - - fib = new FreeImageBitmap(100, 100, PixelFormat.Format16bppRgb565); - Assert.AreEqual(PixelFormat.Format16bppRgb565, fib.PixelFormat); - Assert.AreEqual(100, fib.Width); - Assert.AreEqual(100, fib.Height); - fib.Dispose(); - - fib = new FreeImageBitmap(100, 100, PixelFormat.Format24bppRgb); - Assert.AreEqual(PixelFormat.Format24bppRgb, fib.PixelFormat); - Assert.AreEqual(100, fib.Width); - Assert.AreEqual(100, fib.Height); - fib.Dispose(); - - fib = new FreeImageBitmap(100, 100, PixelFormat.Format32bppArgb); - Assert.AreEqual(PixelFormat.Format32bppArgb, fib.PixelFormat); - Assert.AreEqual(100, fib.Width); - Assert.AreEqual(100, fib.Height); - - stream = new MemoryStream(); - BinaryFormatter formatter = new BinaryFormatter(); - - formatter.Serialize(stream, fib); - Assert.Greater(stream.Length, 0); - stream.Position = 0; - - fib2 = formatter.Deserialize(stream) as FreeImageBitmap; - stream.Dispose(); - fib.Dispose(); - fib2.Dispose(); - - fib = new FreeImageBitmap(filename); - fib2 = new FreeImageBitmap(fib); - fib2.Dispose(); - - fib2 = new FreeImageBitmap(fib, new Size(31, 22)); - Assert.AreEqual(31, fib2.Width); - Assert.AreEqual(22, fib2.Height); - fib2.Dispose(); - fib.Dispose(); - - dib = FreeImage.Allocate(1000, 800, 24, 0xFF0000, 0xFF00, 0xFF); - Assert.IsFalse(dib.IsNull); - - fib = new FreeImageBitmap(1000, 800, -(int)FreeImage.GetPitch(dib), FreeImage.GetPixelFormat(dib), FreeImage.GetScanLine(dib, 0)); - fib.Dispose(); - FreeImage.UnloadEx(ref dib); - } - - [Test] - public unsafe void Properties() - { - string filename = iManager.GetBitmapPath(ImageType.Even, ImageColorType.Type_32); - Assert.IsNotNull(filename); - Assert.IsTrue(File.Exists(filename)); - - FreeImageBitmap fib = new FreeImageBitmap(filename); - Assert.IsFalse(fib.HasPalette); - - try - { - Palette palette = fib.Palette; - Assert.Fail(); - } - catch - { - } - - Assert.IsFalse(fib.HasBackgroundColor); - fib.BackgroundColor = Color.LightSeaGreen; - Assert.IsTrue(fib.HasBackgroundColor); - Assert.That( - Color.LightSeaGreen.B == fib.BackgroundColor.Value.B && - Color.LightSeaGreen.G == fib.BackgroundColor.Value.G && - Color.LightSeaGreen.R == fib.BackgroundColor.Value.R); - fib.BackgroundColor = null; - Assert.IsFalse(fib.HasBackgroundColor); - fib.Dispose(); - - fib = new FreeImageBitmap(100, 100, PixelFormat.Format1bppIndexed); - ImageFlags flags = (ImageFlags)fib.Flags; - Assert.That((flags & ImageFlags.ColorSpaceRgb) == ImageFlags.ColorSpaceRgb); - Assert.That((flags & ImageFlags.HasAlpha) != ImageFlags.HasAlpha); - Assert.That((flags & ImageFlags.HasRealDpi) != ImageFlags.HasRealDpi); - Assert.That((flags & ImageFlags.HasTranslucent) != ImageFlags.HasTranslucent); - fib.Dispose(); - - dib = FreeImage.Allocate(100, 100, 32, 0xFF0000, 0xFF00, 0xFF); - FIICCPROFILE* prof = (FIICCPROFILE*)FreeImage.CreateICCProfile(dib, new byte[] { 0, 1, 2, 3 }, 4); - fib = new FreeImageBitmap(dib); - Scanline sc = (Scanline)fib.GetScanline(0); - RGBQUAD rgbq = sc[0]; - rgbq.rgbReserved = 127; - sc[0] = rgbq; - flags = (ImageFlags)fib.Flags; - Assert.That((flags & ImageFlags.HasAlpha) == ImageFlags.HasAlpha); - Assert.That((flags & ImageFlags.HasRealDpi) != ImageFlags.HasRealDpi); - Assert.That((flags & ImageFlags.HasTranslucent) == ImageFlags.HasTranslucent); - fib.Dispose(); - fib = null; - GC.Collect(2, GCCollectionMode.Forced); - GC.WaitForPendingFinalizers(); - - fib = new FreeImageBitmap(iManager.GetBitmapPath(ImageType.Metadata, ImageColorType.Type_01_Dither)); - int[] propList = fib.PropertyIdList; - Assert.IsNotNull(propList); - Assert.Greater(propList.Length, 0); - PropertyItem[] propItemList = fib.PropertyItems; - Assert.IsNotNull(propItemList); - Assert.Greater(propItemList.Length, 0); - Assert.IsNotNull(fib.RawFormat); - fib.Dispose(); - - fib = new FreeImageBitmap(iManager.GetBitmapPath(ImageType.Multipaged, ImageColorType.Type_01_Dither)); - Assert.Greater(fib.FrameCount, 1); - fib.Dispose(); - } - - [Test] - public void GetBounds() - { - Random rand = new Random(); - int height = rand.Next(1, 100), width = rand.Next(1, 100); - FreeImageBitmap fib = new FreeImageBitmap(width, height, PixelFormat.Format24bppRgb); - - Assert.AreEqual(fib.VerticalResolution, fib.HorizontalResolution); - GraphicsUnit unit; - RectangleF rect; - - unit = GraphicsUnit.Display; - rect = fib.GetBounds(ref unit); - - Assert.AreEqual(GraphicsUnit.Pixel, unit); - Assert.AreEqual(width, (int)rect.Width); - Assert.AreEqual(height, (int)rect.Height); - fib.Dispose(); - } - - [Test] - public void GetPropertyItem() - { - FreeImageBitmap fib = new FreeImageBitmap(iManager.GetBitmapPath(ImageType.Metadata, ImageColorType.Type_01_Dither)); - int[] list = fib.PropertyIdList; - Assert.IsNotNull(list); - Assert.Greater(list.Length, 0); - - for (int i = 0; i < list.Length; i++) - { - PropertyItem item = fib.GetPropertyItem(list[i]); - Assert.IsNotNull(item); - } - fib.Dispose(); - } - - [Test] - public void RemovePropertyItem() - { - FreeImageBitmap fib = new FreeImageBitmap(iManager.GetBitmapPath(ImageType.Metadata, ImageColorType.Type_01_Dither)); - Random rand = new Random(); - int[] list = fib.PropertyIdList; - int length = list.Length; - Assert.Greater(list.Length, 0); - - int id = list[rand.Next(0, list.Length - 1)]; - Assert.IsNotNull(fib.GetPropertyItem(id)); - fib.RemovePropertyItem(id); - list = fib.PropertyIdList; - Assert.That((list.Length + 1) == length); - fib.Dispose(); - } - - [Test] - public unsafe void RotateFlip() - { - FreeImageBitmap fib = new FreeImageBitmap(2, 2, PixelFormat.Format32bppArgb); - - ResetRotateBitmap(fib); - fib.RotateFlip(RotateFlipType.RotateNoneFlipX); - Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(0))[0]); - Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(0))[1]); - Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(1))[0]); - Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(1))[1]); - - ResetRotateBitmap(fib); - fib.RotateFlip(RotateFlipType.RotateNoneFlipY); - Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(0))[0]); - Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(0))[1]); - Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(1))[0]); - Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(1))[1]); - - ResetRotateBitmap(fib); - fib.RotateFlip(RotateFlipType.RotateNoneFlipXY); - Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(0))[0]); - Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(0))[1]); - Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(1))[0]); - Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(1))[1]); - - ResetRotateBitmap(fib); - fib.RotateFlip(RotateFlipType.Rotate90FlipNone); - Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(0))[0]); - Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(0))[1]); - Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(1))[0]); - Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(1))[1]); - - ResetRotateBitmap(fib); - fib.RotateFlip(RotateFlipType.Rotate90FlipX); - Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(0))[0]); - Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(0))[1]); - Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(1))[0]); - Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(1))[1]); - - ResetRotateBitmap(fib); - fib.RotateFlip(RotateFlipType.Rotate90FlipY); - Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(0))[0]); - Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(0))[1]); - Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(1))[0]); - Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(1))[1]); - - fib.Dispose(); - } - - private unsafe void ResetRotateBitmap(FreeImageBitmap fib) - { - ((int*)fib.GetScanlinePointer(0))[0] = 0x00000001; - ((int*)fib.GetScanlinePointer(0))[1] = 0x00000002; - ((int*)fib.GetScanlinePointer(1))[0] = 0x00000003; - ((int*)fib.GetScanlinePointer(1))[1] = 0x00000004; - } - - [Test] - public unsafe void GetSetPixel() - { - Random rand = new Random(); - FreeImageBitmap fib = new FreeImageBitmap(2, 1, PixelFormat.Format1bppIndexed); - Palette palette = fib.Palette; - for (int i = 0; i < palette.Length; i++) - { - palette[i] = (uint)rand.Next(int.MinValue, int.MaxValue); - fib.SetPixel(i, 0, palette[i]); - } - for (int i = 0; i < palette.Length; i++) - { - Assert.AreEqual(fib.GetPixel(i, 0), palette[i].Color); - } - fib.Dispose(); - - fib = new FreeImageBitmap(16, 1, PixelFormat.Format4bppIndexed); - palette = fib.Palette; - for (int i = 0; i < palette.Length; i++) - { - palette[i] = (uint)rand.Next(int.MinValue, int.MaxValue); - fib.SetPixel(i, 0, palette[i]); - } - for (int i = 0; i < palette.Length; i++) - { - Assert.AreEqual(fib.GetPixel(i, 0), palette[i].Color); - } - fib.Dispose(); - - fib = new FreeImageBitmap(256, 1, PixelFormat.Format8bppIndexed); - palette = fib.Palette; - for (int i = 0; i < palette.Length; i++) - { - palette[i] = (uint)rand.Next(int.MinValue, int.MaxValue); - fib.SetPixel(i, 0, palette[i]); - } - for (int i = 0; i < palette.Length; i++) - { - Assert.AreEqual(fib.GetPixel(i, 0), palette[i].Color); - } - fib.Dispose(); - - fib = new FreeImageBitmap(1000, 1, PixelFormat.Format16bppRgb555); - for (int i = 0; i < 1000; i++) - { - Color orgColor = Color.FromArgb(rand.Next(int.MinValue, int.MaxValue)); - fib.SetPixel(i, 0, orgColor); - Color newColor = fib.GetPixel(i, 0); - Assert.That(Math.Abs(orgColor.B - newColor.B) <= 8); - Assert.That(Math.Abs(orgColor.G - newColor.G) <= 8); - Assert.That(Math.Abs(orgColor.R - newColor.R) <= 8); - } - fib.Dispose(); - - fib = new FreeImageBitmap(1000, 1, PixelFormat.Format24bppRgb); - for (int i = 0; i < 1000; i++) - { - Color orgColor = Color.FromArgb(rand.Next(int.MinValue, int.MaxValue)); - fib.SetPixel(i, 0, orgColor); - Color newColor = fib.GetPixel(i, 0); - Assert.AreEqual(orgColor.B, newColor.B); - Assert.AreEqual(orgColor.G, newColor.G); - Assert.AreEqual(orgColor.R, newColor.R); - } - fib.Dispose(); - - fib = new FreeImageBitmap(1000, 1, PixelFormat.Format32bppArgb); - for (int i = 0; i < 1000; i++) - { - Color orgColor = Color.FromArgb(rand.Next(int.MinValue, int.MaxValue)); - fib.SetPixel(i, 0, orgColor); - Color newColor = fib.GetPixel(i, 0); - Assert.AreEqual(orgColor.B, newColor.B); - Assert.AreEqual(orgColor.G, newColor.G); - Assert.AreEqual(orgColor.R, newColor.R); - Assert.AreEqual(orgColor.A, newColor.A); - } - fib.Dispose(); - } - - [Test] - public void SaveAdd() - { - string filename = @"saveadd.tif"; - FreeImageBitmap fib = new FreeImageBitmap(100, 100, PixelFormat.Format24bppRgb); - try - { - fib.SaveAdd(); - Assert.Fail(); - } - catch { } - Assert.IsFalse(File.Exists(filename)); - fib.Save(filename); - fib.AdjustBrightness(0.3d); - fib.SaveAdd(); - FreeImageBitmap other = new FreeImageBitmap(100, 100, PixelFormat.Format24bppRgb); - foreach (Scanline scanline in other) - { - for (int i = 0; i < scanline.Length; i++) - { - scanline[i] = new RGBTRIPLE(Color.FromArgb(0x339955)); - } - } - fib.SaveAdd(other); - other.SaveAdd(filename); - other.Dispose(); - fib.Dispose(); - - fib = new FreeImageBitmap(filename); - Assert.AreEqual(4, fib.FrameCount); - fib.Dispose(); - File.Delete(filename); - Assert.IsFalse(File.Exists(filename)); - } - - [Test] - public void Clone() - { - FreeImageBitmap fib = new FreeImageBitmap(iManager.GetBitmapPath(ImageType.Even, ImageColorType.Type_24)); - object obj = new object(); - fib.Tag = obj; - FreeImageBitmap clone = fib.Clone() as FreeImageBitmap; - Assert.IsNotNull(clone); - Assert.AreEqual(fib.Width, clone.Width); - Assert.AreEqual(fib.Height, clone.Height); - Assert.AreEqual(fib.ColorDepth, clone.ColorDepth); - Assert.AreSame(fib.Tag, clone.Tag); - Assert.AreEqual(fib.ImageFormat, clone.ImageFormat); - clone.Dispose(); - fib.Dispose(); - } - - [Ignore] - public void LockBits() - { - } - - [Ignore] - public void UnlockBits() - { - } - - [Test] - public void GetTypeConvertedInstance() - { - using (FreeImageBitmap fib = new FreeImageBitmap(10, 10, PixelFormat.Format8bppIndexed)) - { - Assert.AreEqual(FREE_IMAGE_TYPE.FIT_BITMAP, fib.ImageType); - using (FreeImageBitmap conv = fib.GetTypeConvertedInstance(FREE_IMAGE_TYPE.FIT_DOUBLE, true)) - { - Assert.IsNotNull(conv); - Assert.AreEqual(FREE_IMAGE_TYPE.FIT_DOUBLE, conv.ImageType); - } - } - } - - [Test] - public void GetColorConvertedInstance() - { - using (FreeImageBitmap fib = new FreeImageBitmap(10, 10, PixelFormat.Format32bppArgb)) - { - Assert.AreEqual(32, fib.ColorDepth); - using (FreeImageBitmap conv = fib.GetColorConvertedInstance(FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP)) - { - Assert.IsNotNull(conv); - Assert.AreEqual(24, conv.ColorDepth); - } - } - } - - [Test] - public void GetScaledInstance() - { - using (FreeImageBitmap fib = new FreeImageBitmap(100, 80, PixelFormat.Format32bppArgb)) - { - Assert.AreEqual(100, fib.Width); - Assert.AreEqual(80, fib.Height); - using (FreeImageBitmap conv = fib.GetScaledInstance(80, 60, FREE_IMAGE_FILTER.FILTER_BICUBIC)) - { - Assert.IsNotNull(conv); - Assert.AreEqual(80, conv.Width); - Assert.AreEqual(60, conv.Height); - } - } - } - - [Test] - public unsafe void GetRotatedInstance() - { - using (FreeImageBitmap fib = new FreeImageBitmap(2, 2, PixelFormat.Format32bppArgb)) - { - ((int*)fib.GetScanlinePointer(0))[0] = 0x1; - ((int*)fib.GetScanlinePointer(0))[1] = 0x2; - ((int*)fib.GetScanlinePointer(1))[0] = 0x3; - ((int*)fib.GetScanlinePointer(1))[1] = 0x4; - using (FreeImageBitmap conv = fib.GetRotatedInstance(90d)) - { - Assert.IsNotNull(conv); - Assert.AreEqual(((int*)conv.GetScanlinePointer(0))[0], 0x3); - Assert.AreEqual(((int*)conv.GetScanlinePointer(0))[1], 0x1); - Assert.AreEqual(((int*)conv.GetScanlinePointer(1))[0], 0x4); - Assert.AreEqual(((int*)conv.GetScanlinePointer(1))[1], 0x2); - } - } - } - - [Test] - public void GetScanline() - { - FreeImageBitmap fib; - - fib = new FreeImageBitmap(10, 10, PixelFormat.Format1bppIndexed); - Scanline scanline1 = (Scanline)fib.GetScanline(0); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, PixelFormat.Format4bppIndexed); - Scanline scanline2 = (Scanline)fib.GetScanline(0); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, PixelFormat.Format8bppIndexed); - Scanline scanline3 = (Scanline)fib.GetScanline(0); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, PixelFormat.Format16bppRgb555); - Scanline scanline4 = (Scanline)fib.GetScanline(0); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, PixelFormat.Format16bppRgb565); - Scanline scanline5 = (Scanline)fib.GetScanline(0); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, PixelFormat.Format24bppRgb); - Scanline scanline6 = (Scanline)fib.GetScanline(0); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, PixelFormat.Format32bppArgb); - Scanline scanline7 = (Scanline)fib.GetScanline(0); - fib.Dispose(); - } - - [Test] - public void GetScanlines() - { - FreeImageBitmap fib; - - fib = new FreeImageBitmap(10, 10, PixelFormat.Format1bppIndexed); - IList> scanline01 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, PixelFormat.Format4bppIndexed); - IList> scanline02 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, PixelFormat.Format8bppIndexed); - IList> scanline03 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, PixelFormat.Format16bppRgb555); - IList> scanline04 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, PixelFormat.Format16bppRgb565); - IList> scanline05 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, PixelFormat.Format24bppRgb); - IList> scanline06 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, PixelFormat.Format32bppArgb); - IList> scanline07 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_COMPLEX); - IList> scanline08 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_DOUBLE); - IList> scanline09 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_FLOAT); - IList> scanline10 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_INT16); - IList> scanline11 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_INT32); - IList> scanline12 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_RGB16); - IList> scanline13 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_RGBA16); - IList> scanline14 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_RGBAF); - IList> scanline15 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_RGBF); - IList> scanline16 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_UINT16); - IList> scanline17 = (IList>)fib.GetScanlines(); - fib.Dispose(); - - fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_UINT32); - IList> scanline18 = (IList>)fib.GetScanlines(); - fib.Dispose(); - } - - [Test] - public void Operators() - { - FreeImageBitmap fib1 = null, fib2 = null; - Assert.IsTrue(fib1 == fib2); - Assert.IsFalse(fib1 != fib2); - Assert.IsTrue(fib1 == null); - Assert.IsFalse(fib1 != null); - - fib1 = new FreeImageBitmap(10, 10, PixelFormat.Format24bppRgb); - Assert.IsFalse(fib1 == fib2); - Assert.IsTrue(fib1 != fib2); - - fib2 = fib1; - fib1 = null; - Assert.IsFalse(fib1 == fib2); - Assert.IsTrue(fib1 != fib2); - - fib1 = new FreeImageBitmap(10, 9, PixelFormat.Format24bppRgb); - Assert.IsFalse(fib1 == fib2); - Assert.IsTrue(fib1 != fib2); - - fib2.Dispose(); - fib2 = fib1; - - Assert.IsTrue(fib1 == fib2); - Assert.IsFalse(fib1 != fib2); - - fib2 = fib1.Clone() as FreeImageBitmap; - Assert.IsTrue(fib1 == fib2); - Assert.IsFalse(fib1 != fib2); - - fib1.Dispose(); - fib2.Dispose(); - } - } - - public class Program - { - static ImageManager iManager = new ImageManager(); - static ImportedFunctionsTest ift = new ImportedFunctionsTest(); - static ImportedStructsTest ist = new ImportedStructsTest(); - static WrapperStructsTest wst = new WrapperStructsTest(); - static WrapperFunctionsTest wft = new WrapperFunctionsTest(); - static FreeImageBitmapTest fib = new FreeImageBitmapTest(); - - public static void Main() - { - List classList = new List(5); - classList.Add(new TestClass(ift)); - classList.Add(new TestClass(ist)); - classList.Add(new TestClass(wst)); - classList.Add(new TestClass(wft)); - classList.Add(new TestClass(fib)); - - for (int i = 0; i < 10000; ) - { - for (int j = 0; j < classList.Count; j++) - classList[j].ExecuteTests(); - Console.WriteLine("Loop {0}", ++i); - //GC.Collect(); - } - } - } - - public class TestClass - { - private object classMember = null; - - private MethodInfo classSetUp = null; - private MethodInfo classTearDown = null; - - private MethodInfo testSetUp = null; - private MethodInfo testTearDown = null; - - private List methodList = null; - - private static object[] parameters = { }; - - public TestClass(object classMember) - { - this.classMember = classMember; - MethodInfo[] infos = classMember.GetType().GetMethods(System.Reflection.BindingFlags.Public | BindingFlags.Instance); - methodList = new List(infos.Length); - - foreach (MethodInfo info in infos) - { - object[] attributes = info.GetCustomAttributes(false); - foreach (Attribute attribute in attributes) - { - if (attribute.GetType() == typeof(TestAttribute)) - { - methodList.Add(info); - break; - } - else if (attribute.GetType() == typeof(TestFixtureSetUpAttribute)) - { - classSetUp = info; - break; - } - else if (attribute.GetType() == typeof(TestFixtureTearDownAttribute)) - { - classTearDown = info; - break; - } - else if (attribute.GetType() == typeof(SetUpAttribute)) - { - testSetUp = info; - break; - } - else if (attribute.GetType() == typeof(TearDownAttribute)) - { - testTearDown = info; - break; - } - } - } - } - - public void ExecuteTests() - { - if (classSetUp != null) - classSetUp.Invoke(classMember, parameters); - - foreach (MethodInfo method in methodList) - { - if (testSetUp != null) - testSetUp.Invoke(classMember, parameters); - - try - { - Console.WriteLine(method.ToString()); - method.Invoke(classMember, parameters); - } - catch (Exception ex) - { - while (ex.InnerException != null) - ex = ex.InnerException; - Console.WriteLine(ex.ToString()); - Environment.Exit(99); - } - - if (testTearDown != null) - testTearDown.Invoke(classMember, parameters); - } - - if (classTearDown != null) - classTearDown.Invoke(classMember, parameters); - } - } +using System; +using System.Drawing; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; +using System.IO; +using System.Drawing.Imaging; +using System.Net; +using FreeImageNETUnitTest; +using System.Reflection; +using System.Threading; +using System.Runtime.Serialization.Formatters.Binary; +using System.Collections; +using FreeImageAPI; +using FreeImageAPI.IO; +using FreeImageAPI.Metadata; +using FreeImageAPI.Plugins; +using NUnit.Framework; + +namespace FreeImageNETUnitTest +{ + [TestFixture] + public class ImportedFunctionsTest + { + ImageManager iManager = new ImageManager(); + FIBITMAP dib; + string freeImageCallback = null; + + [TestFixtureSetUp] + public void Init() + { + FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); + } + + [TestFixtureTearDown] + public void DeInit() + { + FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); + } + + [SetUp] + public void InitEachTime() + { + } + + [TearDown] + public void DeInitEachTime() + { + } + + void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) + { + freeImageCallback = message; + } + + [Test] + public void FreeImage_GetVersion() + { + string version = FreeImage.GetVersion(); + Assert.IsNotEmpty(version); + } + + [Test] + public void FreeImage_GetCopyrightMessage() + { + string copyright = FreeImage.GetCopyrightMessage(); + Assert.IsNotEmpty(copyright); + } + + [Test] + public void FreeImage_OutputMessageProc_SetOutputMessage() + { + Assert.IsNull(freeImageCallback); + FreeImage.SetOutputMessage(new OutputMessageFunction(FreeImage_Message)); + FreeImage.OutputMessageProc(FREE_IMAGE_FORMAT.FIF_UNKNOWN, "unit test"); + FreeImage.SetOutputMessage(null); + Assert.IsNotNull(freeImageCallback); + freeImageCallback = null; + } + + [Test] + public void FreeImage_Allocate() + { + dib = FreeImage.Allocate( + 133, + 77, + 8, + FreeImage.FI_RGBA_RED_MASK, + FreeImage.FI_RGBA_GREEN_MASK, + FreeImage.FI_RGBA_BLUE_MASK); + + Assert.That(!dib.IsNull); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_AllocateT() + { + dib = FreeImage.AllocateT(FREE_IMAGE_TYPE.FIT_RGBA16, 31, 555, 64, 0, 0, 0); + + Assert.That(!dib.IsNull); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_Clone() + { + dib = FreeImage.Allocate(1, 1, 32, 0, 0, 0); + Assert.That(!dib.IsNull); + + FIBITMAP temp = FreeImage.Clone(dib); + Assert.AreNotEqual(0, temp); + + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_Load() + { + Assert.That(dib.IsNull); + dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, iManager.baseDirectory + @"JPEG\Image.jpg", FREE_IMAGE_LOAD_FLAGS.DEFAULT); + Assert.That(!dib.IsNull); + FreeImage.UnloadEx(ref dib); + Assert.That(dib.IsNull); + } + + [Test] + public void FreeImage_Unload() + { + Assert.That(dib.IsNull); + dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, iManager.baseDirectory + @"JPEG\Image.jpg", FREE_IMAGE_LOAD_FLAGS.DEFAULT); + Assert.IsNotNull(dib); + FreeImage.Unload(dib); + dib.SetNull(); + } + + [Test] + public void FreeImage_LoadFromHandle() + { + byte[] data = File.ReadAllBytes(iManager.GetBitmapPath(ImageType.Even, ImageColorType.Type_16_555)); + MemoryStream mStream = new MemoryStream(data); + FreeImageIO io = FreeImageStreamIO.io; + + using (fi_handle handle = new fi_handle(mStream)) + { + dib = FreeImage.LoadFromHandle(FREE_IMAGE_FORMAT.FIF_BMP, ref io, handle, FREE_IMAGE_LOAD_FLAGS.DEFAULT); + Assert.That(!dib.IsNull); + + FreeImage.UnloadEx(ref dib); + } + } + + [Test] + public void FreeImage_Save() + { + string filename = @"test.bmp"; + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08); + Assert.That(!dib.IsNull); + + Assert.IsTrue(FreeImage.Save(FREE_IMAGE_FORMAT.FIF_BMP, dib, filename, FREE_IMAGE_SAVE_FLAGS.DEFAULT)); + Assert.IsTrue(File.Exists(filename)); + File.Delete(filename); + Assert.IsFalse(File.Exists(filename)); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SaveToHandle() + { + FreeImageIO io = new FreeImageIO(); + FreeImage.SaveToHandle(FREE_IMAGE_FORMAT.FIF_BMP, dib, ref io, new fi_handle(), FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + [Test] + public void FreeImage_Memory() + { + dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); + Assert.That(!dib.IsNull); + FIMEMORY mem = FreeImage.OpenMemory(IntPtr.Zero, 0); + Assert.AreNotEqual(0, mem); + FreeImage.SaveToMemory(FREE_IMAGE_FORMAT.FIF_TIFF, dib, mem, FREE_IMAGE_SAVE_FLAGS.DEFAULT); + Assert.AreNotEqual(0, FreeImage.TellMemory(mem)); + Assert.IsTrue(FreeImage.SeekMemory(mem, 0, System.IO.SeekOrigin.Begin)); + + FIBITMAP temp = FreeImage.LoadFromMemory(FREE_IMAGE_FORMAT.FIF_TIFF, mem, FREE_IMAGE_LOAD_FLAGS.DEFAULT); + Assert.AreNotEqual(0, temp); + FreeImage.UnloadEx(ref temp); + + uint size = 0; + byte[] ptr = new byte[1]; + IntPtr buffer = IntPtr.Zero; + Assert.IsTrue(FreeImage.AcquireMemory(mem, ref buffer, ref size)); + Assert.AreNotEqual(IntPtr.Zero, ptr); + Assert.AreNotEqual(0, size); + + Assert.AreEqual(1, FreeImage.WriteMemory(ptr, 1, 1, mem)); + FreeImage.SeekMemory(mem, 1, System.IO.SeekOrigin.Begin); + Assert.AreEqual(1, FreeImage.TellMemory(mem)); + Assert.AreEqual(2, FreeImage.ReadMemory(ptr, 1, 2, mem)); + FreeImage.CloseMemory(mem); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_RegisterLocalPlugin() + { + InitProc proc = null; + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.RegisterLocalPlugin(proc, "", "", "", "")); + } + + [Test] + public void FreeImage_RegisterExternalPlugin() + { + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.RegisterExternalPlugin("", "", "", "", "")); + } + + [Test] + public void FreeImage_GetFIFCount() + { + Assert.AreNotEqual(0, FreeImage.GetFIFCount()); + } + + [Test] + public void FreeImage_SetPluginEnabled_IsPluginEnabled() + { + FreeImage.SetPluginEnabled(FREE_IMAGE_FORMAT.FIF_PNG, false); + Assert.AreEqual(0, FreeImage.IsPluginEnabled(FREE_IMAGE_FORMAT.FIF_PNG)); + FreeImage.SetPluginEnabled(FREE_IMAGE_FORMAT.FIF_PNG, true); + Assert.AreEqual(1, FreeImage.IsPluginEnabled(FREE_IMAGE_FORMAT.FIF_PNG)); + } + + [Test] + public void FreeImage_GetFIFFromFormat() + { + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFIFFromFormat("")); + Assert.AreNotEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFIFFromFormat("TIFF")); + } + + [Test] + public void FreeImage_GetFIFFromMime() + { + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFIFFromMime("")); + Assert.AreNotEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFIFFromMime("image/jpeg")); + } + + [Test] + public void FreeImage_GetFormatFromFIF() + { + Assert.IsNotEmpty(FreeImage.GetFormatFromFIF(FREE_IMAGE_FORMAT.FIF_JNG)); + } + + [Test] + public void FreeImage_GetFIFExtensionList() + { + Assert.IsNotEmpty(FreeImage.GetFIFExtensionList(FREE_IMAGE_FORMAT.FIF_PGM)); + } + + [Test] + public void FreeImage_GetFIFDescription() + { + Assert.IsNotEmpty(FreeImage.GetFIFDescription(FREE_IMAGE_FORMAT.FIF_PBM)); + } + + [Test] + public void FreeImage_GetFIFRegExpr() + { + Assert.IsNotEmpty(FreeImage.GetFIFRegExpr(FREE_IMAGE_FORMAT.FIF_JPEG)); + } + + [Test] + public void FreeImage_GetFIFMimeType() + { + Assert.IsNotEmpty(FreeImage.GetFIFMimeType(FREE_IMAGE_FORMAT.FIF_ICO)); + } + + [Test] + public void FreeImage_GetFIFFromFilename() + { + Assert.AreNotEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFIFFromFilename("test.bmp")); + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFIFFromFilename("test.000")); + } + + [Test] + public void FreeImage_FIFSupportsReading() + { + Assert.IsTrue(FreeImage.FIFSupportsReading(FREE_IMAGE_FORMAT.FIF_TIFF)); + } + + [Test] + public void FreeImage_FIFSupportsWriting() + { + Assert.IsTrue(FreeImage.FIFSupportsWriting(FREE_IMAGE_FORMAT.FIF_GIF)); + } + + [Test] + public void FreeImage_FIFSupportsExportBPP() + { + Assert.IsTrue(FreeImage.FIFSupportsExportBPP(FREE_IMAGE_FORMAT.FIF_BMP, 32)); + Assert.IsFalse(FreeImage.FIFSupportsExportBPP(FREE_IMAGE_FORMAT.FIF_GIF, 32)); + } + + [Test] + public void FreeImage_FIFSupportsExportType() + { + Assert.IsTrue(FreeImage.FIFSupportsExportType(FREE_IMAGE_FORMAT.FIF_BMP, FREE_IMAGE_TYPE.FIT_BITMAP)); + Assert.IsFalse(FreeImage.FIFSupportsExportType(FREE_IMAGE_FORMAT.FIF_BMP, FREE_IMAGE_TYPE.FIT_COMPLEX)); + } + + [Test] + public void FreeImage_FIFSupportsICCProfiles() + { + Assert.IsTrue(FreeImage.FIFSupportsICCProfiles(FREE_IMAGE_FORMAT.FIF_JPEG)); + Assert.IsFalse(FreeImage.FIFSupportsICCProfiles(FREE_IMAGE_FORMAT.FIF_BMP)); + } + + [Test] + public void FreeImage_MultiBitmap() + { + FIBITMAP temp; + FIMULTIBITMAP mdib = FreeImage.OpenMultiBitmap( + FREE_IMAGE_FORMAT.FIF_TIFF, + @"test.tif", + true, + false, + true, + FREE_IMAGE_LOAD_FLAGS.DEFAULT); + Assert.AreNotEqual(0, mdib); + Assert.AreEqual(0, FreeImage.GetPageCount(mdib)); + dib = FreeImage.Allocate(10, 10, 8, 0, 0, 0); + FreeImage.AppendPage(mdib, dib); + Assert.AreEqual(1, FreeImage.GetPageCount(mdib)); + FreeImage.AppendPage(mdib, dib); + Assert.AreEqual(2, FreeImage.GetPageCount(mdib)); + FreeImage.AppendPage(mdib, dib); + Assert.AreEqual(3, FreeImage.GetPageCount(mdib)); + FreeImage.CloseMultiBitmapEx(ref mdib); + FreeImage.UnloadEx(ref dib); + mdib.SetNull(); + mdib = FreeImage.OpenMultiBitmap(FREE_IMAGE_FORMAT.FIF_TIFF, @"test.tif", false, false, true, FREE_IMAGE_LOAD_FLAGS.DEFAULT); + Assert.AreNotEqual(0, mdib); + Assert.AreEqual(3, FreeImage.GetPageCount(mdib)); + dib = FreeImage.LockPage(mdib, 1); + temp = FreeImage.LockPage(mdib, 2); + + int[] pages = null; + int count = 0; + FreeImage.GetLockedPageNumbers(mdib, pages, ref count); + Assert.AreEqual(2, count); + pages = new int[count]; + FreeImage.GetLockedPageNumbers(mdib, pages, ref count); + Assert.AreEqual(2, pages.Length); + FreeImage.UnlockPage(mdib, dib, false); + FreeImage.UnlockPage(mdib, temp, true); + dib.SetNull(); + Assert.IsTrue(FreeImage.MovePage(mdib, 0, 1)); + FreeImage.CloseMultiBitmapEx(ref mdib); + Assert.IsTrue(System.IO.File.Exists("test.tif")); + System.IO.File.Delete("test.tif"); + } + + [Test] + public void FreeImage_GetFileType() + { + Assert.AreNotEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFileType(iManager.GetBitmapPath(ImageType.Even, ImageColorType.Type_08_Greyscale_Unordered), 0)); + } + + [Test] + public void FreeImage_GetFileTypeFromHandle() + { + FreeImageIO io = FreeImageStreamIO.io; + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFileTypeFromHandle(ref io, new fi_handle(), 0)); + } + + [Test] + public void FreeImage_GetFileTypeFromMemory() + { + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_UNKNOWN, FreeImage.GetFileTypeFromMemory(new FIMEMORY(), 0)); + } + + [Test] + public void FreeImage_IsLittleEndian() + { + Assert.IsTrue(FreeImage.IsLittleEndian()); + } + + [Test] + public void FreeImage_LookupX11Color() + { + byte red, green, blue; + FreeImage.LookupX11Color("lawngreen", out red, out green, out blue); + Assert.AreEqual(124, red); + Assert.AreEqual(252, green); + Assert.AreEqual(0, blue); + } + + [Test] + public void FreeImage_LookupSVGColor() + { + byte red, green, blue; + FreeImage.LookupX11Color("orchid", out red, out green, out blue); + Assert.AreEqual(218, red); + Assert.AreEqual(112, green); + Assert.AreEqual(214, blue); + } + + [Test] + public void FreeImage_GetBits() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_01_Threshold); + Assert.That(!dib.IsNull); + Assert.AreNotEqual(IntPtr.Zero, FreeImage.GetBits(dib)); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetScanLine() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04_Greyscale_MinIsBlack); + Assert.That(!dib.IsNull); + Assert.AreNotEqual(IntPtr.Zero, FreeImage.GetScanLine(dib, 0)); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetPixelIndex_SetPixelIndex() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_04_Greyscale_Unordered); + Assert.That(!dib.IsNull); + byte index_old, index_new; + Assert.IsTrue(FreeImage.GetPixelIndex(dib, 31, 10, out index_old)); + index_new = index_old == byte.MaxValue ? (byte)0 : (byte)(index_old + 1); + Assert.IsTrue(FreeImage.SetPixelIndex(dib, 31, 10, ref index_new)); + Assert.IsTrue(FreeImage.GetPixelIndex(dib, 31, 10, out index_old)); + Assert.AreEqual(index_new, index_old); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetPixelColor_SetPixelColor() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.That(!dib.IsNull); + RGBQUAD value_old, value_new; + Assert.IsTrue(FreeImage.GetPixelColor(dib, 77, 61, out value_old)); + value_new = (value_old == (RGBQUAD)Color.White) ? Color.Black : Color.White; + Assert.IsTrue(FreeImage.SetPixelColor(dib, 77, 61, ref value_new)); + Assert.IsTrue(FreeImage.GetPixelColor(dib, 77, 61, out value_old)); + Assert.AreEqual(value_new, value_old); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_Bitmap_information_functions() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_08_Greyscale_MinIsBlack); + Assert.That(!dib.IsNull); + Assert.AreEqual(FREE_IMAGE_TYPE.FIT_BITMAP, FreeImage.GetImageType(dib)); + Assert.AreNotEqual(0, FreeImage.GetColorsUsed(dib)); + Assert.AreEqual(8, FreeImage.GetBPP(dib)); + Assert.AreNotEqual(0, FreeImage.GetWidth(dib)); + Assert.AreNotEqual(0, FreeImage.GetHeight(dib)); + Assert.AreNotEqual(0, FreeImage.GetLine(dib)); + Assert.AreNotEqual(0, FreeImage.GetPitch(dib)); + Assert.AreNotEqual(0, FreeImage.GetDIBSize(dib)); + Assert.AreNotEqual(IntPtr.Zero, FreeImage.GetPalette(dib)); + FreeImage.SetDotsPerMeterX(dib, 1234); + FreeImage.SetDotsPerMeterY(dib, 4321); + Assert.AreEqual(1234, FreeImage.GetDotsPerMeterX(dib)); + Assert.AreEqual(4321, FreeImage.GetDotsPerMeterY(dib)); + Assert.AreNotEqual(IntPtr.Zero, FreeImage.GetInfoHeader(dib)); + Assert.AreNotEqual(IntPtr.Zero, FreeImage.GetInfo(dib)); + Assert.AreEqual(FREE_IMAGE_COLOR_TYPE.FIC_MINISBLACK, FreeImage.GetColorType(dib)); + Assert.AreEqual(0, FreeImage.GetRedMask(dib)); + Assert.AreEqual(0, FreeImage.GetGreenMask(dib)); + Assert.AreEqual(0, FreeImage.GetBlueMask(dib)); + Assert.AreEqual(0, FreeImage.GetTransparencyCount(dib)); + Assert.AreNotEqual(IntPtr.Zero, FreeImage.GetTransparencyTable(dib)); + FreeImage.SetTransparent(dib, false); + FreeImage.SetTransparencyTable(dib, new byte[] { }); + Assert.IsTrue(FreeImage.IsTransparent(dib)); + Assert.IsFalse(FreeImage.HasBackgroundColor(dib)); + RGBQUAD rgb = Color.Teal; + Assert.IsTrue(FreeImage.SetBackgroundColor(dib, ref rgb)); + Assert.IsTrue(FreeImage.GetBackgroundColor(dib, out rgb)); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetICCProfile() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + new FIICCPROFILE(dib, new byte[] { 0xFF, 0xAA, 0x00, 0x33 }); + FIICCPROFILE p = FreeImage.GetICCProfileEx(dib); + Assert.AreEqual(4, p.Size); + Assert.AreEqual(0xAA, p.Data[1]); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_CreateICCProfile() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + byte[] data = new byte[256]; + Assert.AreNotEqual(IntPtr.Zero, FreeImage.CreateICCProfile(dib, data, 256)); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_DestroyICCProfile() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + FreeImage.DestroyICCProfile(dib); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ConvertTo4Bits() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.That(!dib.IsNull); + FIBITMAP temp = FreeImage.ConvertTo4Bits(dib); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(4, FreeImage.GetBPP(temp)); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ConvertTo8Bits() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.That(!dib.IsNull); + FIBITMAP temp = FreeImage.ConvertTo8Bits(dib); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(8, FreeImage.GetBPP(temp)); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ConvertToGreyscale() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.That(!dib.IsNull); + FIBITMAP temp = FreeImage.ConvertToGreyscale(dib); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(8, FreeImage.GetBPP(temp)); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ConvertTo16Bits555() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.That(!dib.IsNull); + FIBITMAP temp = FreeImage.ConvertTo16Bits555(dib); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(16, FreeImage.GetBPP(temp)); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ConvertTo16Bits565() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.That(!dib.IsNull); + FIBITMAP temp = FreeImage.ConvertTo16Bits565(dib); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(16, FreeImage.GetBPP(temp)); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ConvertTo24Bits() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.That(!dib.IsNull); + FIBITMAP temp = FreeImage.ConvertTo24Bits(dib); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(24, FreeImage.GetBPP(temp)); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ConvertTo32Bits() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + FIBITMAP temp = FreeImage.ConvertTo32Bits(dib); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(32, FreeImage.GetBPP(temp)); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ColorQuantize() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + FIBITMAP temp = FreeImage.ColorQuantize(dib, FREE_IMAGE_QUANTIZE.FIQ_WUQUANT); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(8, FreeImage.GetBPP(temp)); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ColorQuantizeEx() + { + FIBITMAP paletteDib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08); + Assert.IsFalse(paletteDib.IsNull); + Palette palette = FreeImage.GetPaletteEx(paletteDib); + RGBQUAD[] table = palette.Data; + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + FIBITMAP temp = FreeImage.ColorQuantizeEx(dib, FREE_IMAGE_QUANTIZE.FIQ_WUQUANT, (int)palette.Length, (int)palette.Length, table); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(8, FreeImage.GetBPP(temp)); + + FreeImage.UnloadEx(ref paletteDib); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_Threshold() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.That(!dib.IsNull); + FIBITMAP temp = FreeImage.Threshold(dib, 128); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(1, FreeImage.GetBPP(temp)); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_Dither() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.That(!dib.IsNull); + FIBITMAP temp = FreeImage.Dither(dib, FREE_IMAGE_DITHER.FID_FS); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(1, FreeImage.GetBPP(temp)); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_RawBits() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.That(!dib.IsNull); + IntPtr buffer = Marshal.AllocHGlobal((int)FreeImage.GetDIBSize(dib)); + FreeImage.ConvertToRawBits( + buffer, + dib, + (int)FreeImage.GetPitch(dib), + FreeImage.GetBPP(dib), + FreeImage.GetRedMask(dib), + FreeImage.GetGreenMask(dib), + FreeImage.GetBlueMask(dib), + true); + FIBITMAP temp = FreeImage.ConvertFromRawBits( + buffer, + (int)FreeImage.GetWidth(dib), + (int)FreeImage.GetHeight(dib), + (int)FreeImage.GetPitch(dib), + FreeImage.GetBPP(dib), + FreeImage.GetRedMask(dib), + FreeImage.GetGreenMask(dib), + FreeImage.GetBlueMask(dib), + true); + + Assert.AreNotEqual(0, temp); + + Marshal.FreeHGlobal(buffer); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ConvertToRGBF() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.That(!dib.IsNull); + FIBITMAP temp = FreeImage.ConvertToRGBF(dib); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(FREE_IMAGE_TYPE.FIT_RGBF, FreeImage.GetImageType(temp)); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ConvertToStandardType() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04_Greyscale_MinIsBlack); + Assert.That(!dib.IsNull); + FIBITMAP temp = FreeImage.ConvertToStandardType(dib, true); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(FREE_IMAGE_COLOR_TYPE.FIC_PALETTE, FreeImage.GetColorType(temp)); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ConvertToType() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_Unordered); + Assert.That(!dib.IsNull); + FIBITMAP temp = FreeImage.ConvertToType(dib, FREE_IMAGE_TYPE.FIT_UINT32, true); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(FREE_IMAGE_TYPE.FIT_UINT32, FreeImage.GetImageType(temp)); + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ToneMapping() + { + FIBITMAP temp; + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + FIBITMAP rgbf = FreeImage.ConvertToRGBF(dib); + Assert.AreNotEqual(0, rgbf); + Assert.AreEqual(FREE_IMAGE_TYPE.FIT_RGBF, FreeImage.GetImageType(rgbf)); + Assert.AreEqual(96, FreeImage.GetBPP(rgbf)); + + temp = FreeImage.ToneMapping(rgbf, FREE_IMAGE_TMO.FITMO_REINHARD05, 1f, 1.1f); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(24, FreeImage.GetBPP(temp)); + FreeImage.UnloadEx(ref temp); + + FreeImage.UnloadEx(ref rgbf); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_TmoDrago03() + { + FIBITMAP temp; + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + FIBITMAP rgbf = FreeImage.ConvertToRGBF(dib); + Assert.AreNotEqual(0, rgbf); + Assert.AreEqual(FREE_IMAGE_TYPE.FIT_RGBF, FreeImage.GetImageType(rgbf)); + Assert.AreEqual(96, FreeImage.GetBPP(rgbf)); + + temp = FreeImage.TmoDrago03(rgbf, 1f, 1.2f); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(24, FreeImage.GetBPP(temp)); + FreeImage.UnloadEx(ref temp); + + FreeImage.UnloadEx(ref rgbf); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_TmoReinhard05() + { + FIBITMAP temp; + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + FIBITMAP rgbf = FreeImage.ConvertToRGBF(dib); + Assert.AreNotEqual(0, rgbf); + Assert.AreEqual(FREE_IMAGE_TYPE.FIT_RGBF, FreeImage.GetImageType(rgbf)); + Assert.AreEqual(96, FreeImage.GetBPP(rgbf)); + + temp = FreeImage.TmoReinhard05(rgbf, 0f, 0.25f); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(24, FreeImage.GetBPP(temp)); + FreeImage.UnloadEx(ref temp); + + FreeImage.UnloadEx(ref rgbf); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_TmoFattal02() + { + FIBITMAP temp; + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + FIBITMAP rgbf = FreeImage.ConvertToRGBF(dib); + Assert.AreNotEqual(0, rgbf); + Assert.AreEqual(FREE_IMAGE_TYPE.FIT_RGBF, FreeImage.GetImageType(rgbf)); + Assert.AreEqual(96, FreeImage.GetBPP(rgbf)); + + temp = FreeImage.TmoFattal02(rgbf, 1f, 0.79f); + Assert.AreNotEqual(0, temp); + Assert.AreEqual(24, FreeImage.GetBPP(temp)); + FreeImage.UnloadEx(ref temp); + + FreeImage.UnloadEx(ref rgbf); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ZLibCompress_ZLibUncompress() + { + Random rand = new Random(DateTime.Now.Millisecond); + byte[] source = new byte[10240]; + byte[] compressed = new byte[(int)(10355f * 1.01 + 12f)]; + byte[] uncompressed = new byte[10240]; + rand.NextBytes(source); + Assert.AreNotEqual(0, FreeImage.ZLibCompress(compressed, (uint)compressed.Length, source, (uint)source.Length)); + Assert.AreNotEqual(0, FreeImage.ZLibUncompress(uncompressed, (uint)source.Length, compressed, (uint)compressed.Length)); + for (int i = 0; i < source.Length; i++) + if (source[i] != uncompressed[i]) + Assert.Fail(); + } + + [Test] + public void FreeImage_ZLibGZip_ZLibGUnzip() + { + Random rand = new Random(DateTime.Now.Millisecond); + byte[] source = new byte[10240]; + byte[] compressed = new byte[(int)(10355f * 1.01 + 24f)]; + byte[] uncompressed = new byte[10240]; + rand.NextBytes(source); + Assert.AreNotEqual(0, FreeImage.ZLibGZip(compressed, (uint)compressed.Length, source, (uint)source.Length)); + Assert.AreNotEqual(0, FreeImage.ZLibGUnzip(uncompressed, (uint)source.Length, compressed, (uint)compressed.Length)); + for (int i = 0; i < source.Length; i++) + if (source[i] != uncompressed[i]) + Assert.Fail(); + } + + [Test] + public void FreeImage_ZLibCRC32() + { + byte[] buffer = new byte[0]; + Assert.AreEqual(0xFEBCA008, FreeImage.ZLibCRC32(0xFEBCA008, buffer, 0)); + } + + [Test] + public void FreeImage_CreateTag() + { + FITAG tag = FreeImage.CreateTag(); + Assert.AreNotEqual(0, tag); + FITAG tag_clone = FreeImage.CloneTag(tag); + Assert.AreNotEqual(0, tag_clone); + FreeImage.DeleteTag(tag); + FreeImage.DeleteTag(tag_clone); + } + + [Test] + public void FreeImage_Tag_accessors() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + Assert.IsTrue(FreeImage.FindNextMetadata(mData, out tag)); + Assert.AreNotEqual(0, tag); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetTagKey() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + FreeImage.GetTagKey(tag); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetTagDescription() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + FreeImage.GetTagDescription(tag); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetTagID() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + FreeImage.GetTagID(tag); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetTagType() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + FreeImage.GetTagType(tag); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetTagCount() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + FreeImage.GetTagCount(tag); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetTagLength() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + FreeImage.GetTagLength(tag); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetTagValue() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + FreeImage.GetTagValue(tag); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetTagKey() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + FreeImage.SetTagKey(tag, ""); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetTagDescription() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + FreeImage.SetTagDescription(tag, ""); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetTagID() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + FreeImage.SetTagID(tag, 44); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetTagType() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + FreeImage.SetTagType(tag, FREE_IMAGE_MDTYPE.FIDT_ASCII); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetTagCount() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + FreeImage.SetTagCount(tag, 3); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetTagLength() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + FreeImage.SetTagLength(tag, 6); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetTagValue() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + int length = (int)FreeImage.GetTagLength(tag); + FREE_IMAGE_MDTYPE type = FreeImage.GetTagType(tag); + int count = (int)FreeImage.GetTagCount(tag); + + byte[] buffer = new byte[length * count]; + + FreeImage.SetTagValue(tag, buffer); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetMetadataCount() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + Assert.AreNotEqual(0, FreeImage.GetMetadataCount(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib)); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_TagToString() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + + FITAG tag; + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, dib, out tag); + Assert.AreNotEqual(0, mData); + Assert.AreNotEqual(0, tag); + + Assert.IsNotEmpty(FreeImage.TagToString(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, tag, 0)); + + FreeImage.FindCloseMetadata(mData); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_RotateClassic() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + FIBITMAP temp = FreeImage.RotateClassic(dib, 45d); + Assert.AreNotEqual(0, temp); + + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_RotateEx() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + FIBITMAP temp = FreeImage.RotateEx(dib, 261d, 0d, 33d, 51d, 9d, true); + Assert.AreNotEqual(0, temp); + + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_FlipHorizontal() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + Assert.IsTrue(FreeImage.FlipHorizontal(dib)); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_FlipVertical() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + Assert.IsTrue(FreeImage.FlipVertical(dib)); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_JPEGTransform() + { + string filename = iManager.GetBitmapPath(ImageType.JPEG, ImageColorType.Type_24); + string filenameOut = filename + ".out.jpg"; + Assert.IsTrue(File.Exists(filename)); + + Assert.IsTrue(FreeImage.JPEGTransform(filename, filenameOut, FREE_IMAGE_JPEG_OPERATION.FIJPEG_OP_FLIP_V, false)); + Assert.IsTrue(File.Exists(filenameOut)); + + FIBITMAP temp = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, filenameOut, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); + Assert.AreNotEqual(0, temp); + + File.Delete(filenameOut); + Assert.IsFalse(File.Exists(filenameOut)); + + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_Rescale() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_16_555); + Assert.That(!dib.IsNull); + + FIBITMAP temp = FreeImage.Rescale(dib, 100, 100, FREE_IMAGE_FILTER.FILTER_BICUBIC); + Assert.AreNotEqual(0, temp); + + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_MakeThumbnail() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_16_555); + Assert.That(!dib.IsNull); + + FIBITMAP temp = FreeImage.MakeThumbnail(dib, 50, false); + Assert.AreNotEqual(0, temp); + + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_AdjustCurve() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + byte[] lut = new byte[256]; + Assert.IsTrue(FreeImage.AdjustCurve(dib, lut, FREE_IMAGE_COLOR_CHANNEL.FICC_GREEN)); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_AdjustGamma() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + Assert.IsTrue(FreeImage.AdjustGamma(dib, 1.3d)); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_AdjustBrightness() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + Assert.IsTrue(FreeImage.AdjustBrightness(dib, 1.3d)); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_AdjustContrast() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + Assert.IsTrue(FreeImage.AdjustContrast(dib, 1.3d)); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_Invert() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_16_555); + Assert.That(!dib.IsNull); + + Assert.IsTrue(FreeImage.Invert(dib)); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetHistogram() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + int[] histo = new int[256]; + Assert.IsTrue(FreeImage.GetHistogram(dib, histo, FREE_IMAGE_COLOR_CHANNEL.FICC_RED)); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetChannel() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + FIBITMAP temp = FreeImage.GetChannel(dib, FREE_IMAGE_COLOR_CHANNEL.FICC_GREEN); + Assert.AreNotEqual(0, temp); + + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetChannel() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.That(!dib.IsNull); + FIBITMAP dib8 = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_MinIsBlack); + Assert.AreNotEqual(0, dib8); + Assert.AreEqual(FreeImage.GetWidth(dib), FreeImage.GetWidth(dib8)); + Assert.AreEqual(FreeImage.GetHeight(dib), FreeImage.GetHeight(dib8)); + + Assert.IsTrue(FreeImage.SetChannel(dib, dib8, FREE_IMAGE_COLOR_CHANNEL.FICC_BLUE)); + + FreeImage.UnloadEx(ref dib8); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetComplexChannel() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08); + Assert.That(!dib.IsNull); + + FIBITMAP temp = FreeImage.ConvertToType(dib, FREE_IMAGE_TYPE.FIT_COMPLEX, true); + Assert.AreNotEqual(0, temp); + + FIBITMAP temp2 = FreeImage.GetComplexChannel(temp, FREE_IMAGE_COLOR_CHANNEL.FICC_IMAG); + Assert.AreNotEqual(0, temp2); + + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref temp2); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetComplexChannel() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_Unordered); + Assert.That(!dib.IsNull); + + FIBITMAP temp = FreeImage.ConvertToType(dib, FREE_IMAGE_TYPE.FIT_COMPLEX, true); + Assert.AreNotEqual(0, temp); + + FIBITMAP temp2 = FreeImage.GetComplexChannel(temp, FREE_IMAGE_COLOR_CHANNEL.FICC_IMAG); + Assert.AreNotEqual(0, temp2); + + Assert.IsTrue(FreeImage.SetComplexChannel(temp, temp2, FREE_IMAGE_COLOR_CHANNEL.FICC_IMAG)); + + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref temp2); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_Copy() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_MinIsBlack); + Assert.That(!dib.IsNull); + + FIBITMAP temp = FreeImage.Copy(dib, 5, 9, 44, 2); + Assert.AreNotEqual(0, temp); + + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_Paste() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_MinIsBlack); + Assert.That(!dib.IsNull); + + FIBITMAP temp = FreeImage.Allocate(3, 3, 8, 0, 0, 0); + Assert.IsTrue(FreeImage.Paste(dib, temp, 31, 3, 256)); + + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_Composite() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_MinIsBlack); + Assert.That(!dib.IsNull); + RGBQUAD rgbq = new RGBQUAD(); + + FIBITMAP temp = FreeImage.Composite(dib, false, ref rgbq, new FIBITMAP()); + Assert.AreNotEqual(0, temp); + + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_JPEGCrop() + { + string filename = iManager.GetBitmapPath(ImageType.JPEG, ImageColorType.Type_01_Dither); + Assert.IsTrue(File.Exists(filename)); + string filenameOut = filename + ".out.jpg"; + + Assert.IsTrue(FreeImage.JPEGCrop(filename, filenameOut, 3, 2, 1, 5)); + Assert.IsTrue(File.Exists(filenameOut)); + + FIBITMAP temp = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, filenameOut, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); + Assert.AreNotEqual(0, temp); + + File.Delete(filenameOut); + Assert.IsFalse(File.Exists(filenameOut)); + + FreeImage.UnloadEx(ref temp); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_PreMultiplyWithAlpha() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.IsFalse(dib.IsNull); + + Assert.IsTrue(FreeImage.PreMultiplyWithAlpha(dib)); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_MultigridPoissonSolver() + { + dib = FreeImage.AllocateT(FREE_IMAGE_TYPE.FIT_FLOAT, 10, 10, 32, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + + FIBITMAP dib2 = FreeImage.MultigridPoissonSolver(dib, 2); + + FreeImage.UnloadEx(ref dib); + FreeImage.UnloadEx(ref dib2); + } + + [Test] + public void FreeImage_GetAdjustColorsLookupTable() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); + Assert.IsFalse(dib.IsNull); + + byte[] lut = new byte[256]; + FreeImage.GetAdjustColorsLookupTable(lut, 55d, 0d, 2.1d, false); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_AdjustColors() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.IsFalse(dib.IsNull); + + Assert.IsTrue(FreeImage.AdjustColors(dib, -4d, 22d, 1.1d, false)); + + FreeImage.UnloadEx(ref dib); + } + + [Ignore] + public void FreeImage_ApplyColorMapping() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + FreeImage_ApplyColorMapping2(dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + FreeImage_ApplyColorMapping2(dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + FreeImage_ApplyColorMapping2(dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + FreeImage_ApplyColorMapping2(dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + FreeImage_ApplyColorMapping2(dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + FreeImage_ApplyColorMapping2(dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + FreeImage_ApplyColorMapping2(dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + FreeImage_ApplyColorMapping2(dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + FreeImage_ApplyColorMapping2(dib); + } + + private void FreeImage_ApplyColorMapping2(FIBITMAP dib) + { + Assert.IsFalse(dib.IsNull); + + Scanline rgbqa = new Scanline(dib, 0); + + RGBQUAD[] src = new RGBQUAD[1]; + RGBQUAD[] dst = new RGBQUAD[1]; + src[0] = rgbqa[0]; + dst[0].Color = src[0].Color == Color.White ? Color.Thistle : Color.White; + + uint count = FreeImage.ApplyColorMapping(dib, src, dst, 1, true, false); // Memory + Assert.That(count > 0); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SwapColors() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_08); + Assert.IsFalse(dib.IsNull); + + RGBQUAD src = new RGBQUAD(Color.FromArgb(93, 119, 170)); + RGBQUAD dst = new RGBQUAD(Color.FromArgb(90, 130, 148)); + + uint count = FreeImage.SwapColors(dib, ref src, ref dst, true); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ApplyPaletteIndexMapping() + { + // alle farbtiefen + + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_04); + Assert.IsFalse(dib.IsNull); + + byte[] src = { 0, 3, 1 }; + byte[] dst = { 3, 1, 0 }; + + uint count = FreeImage.ApplyPaletteIndexMapping(dib, src, dst, 3, false); + Assert.That(count > 0); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SwapPaletteIndices() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_04); + Assert.IsFalse(dib.IsNull); + + byte src = 0; + byte dst = 3; + + uint count = FreeImage.SwapPaletteIndices(dib, ref src, ref dst); + Assert.That(count > 0); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetTransparentIndex() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04); + Assert.IsFalse(dib.IsNull); + + FreeImage.SetTransparentIndex(dib, 0); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetTransparentIndex() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04); + Assert.IsFalse(dib.IsNull); + + int i = FreeImage.GetTransparentIndex(dib); + + FreeImage.UnloadEx(ref dib); + } + } + + [TestFixture] + public class ImportedStructsTest + { + ImageManager iManager = new ImageManager(); + FIBITMAP dib = new FIBITMAP(); + string freeImageCallback = null; + + [TestFixtureSetUp] + public void Init() + { + FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); + } + + [TestFixtureTearDown] + public void DeInit() + { + FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); + } + + [SetUp] + public void InitEachTime() + { + } + + [TearDown] + public void DeInitEachTime() + { + } + + void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) + { + freeImageCallback = message; + } + + public bool EqualColors(Color color1, Color color2) + { + if (color1.A != color2.A) return false; + if (color1.R != color2.R) return false; + if (color1.G != color2.G) return false; + if (color1.B != color2.B) return false; + return true; + } + + [Test] + public void RGBQUAD() + { + RGBQUAD rgbq = new RGBQUAD(); + Assert.AreEqual(0, rgbq.rgbBlue); + Assert.AreEqual(0, rgbq.rgbGreen); + Assert.AreEqual(0, rgbq.rgbRed); + Assert.AreEqual(0, rgbq.rgbReserved); + + rgbq = new RGBQUAD(Color.Chartreuse); + Assert.That(EqualColors(Color.Chartreuse, rgbq.Color)); + + rgbq = new RGBQUAD(Color.FromArgb(133, 83, 95, 173)); + Assert.AreEqual(173, rgbq.rgbBlue); + Assert.AreEqual(95, rgbq.rgbGreen); + Assert.AreEqual(83, rgbq.rgbRed); + Assert.AreEqual(133, rgbq.rgbReserved); + + rgbq.Color = Color.Crimson; + Assert.That(EqualColors(Color.Crimson, rgbq.Color)); + + rgbq.Color = Color.MidnightBlue; + Assert.That(EqualColors(Color.MidnightBlue, rgbq.Color)); + + rgbq.Color = Color.White; + Assert.AreEqual(255, rgbq.rgbBlue); + Assert.AreEqual(255, rgbq.rgbGreen); + Assert.AreEqual(255, rgbq.rgbRed); + Assert.AreEqual(255, rgbq.rgbReserved); + + rgbq.Color = Color.Black; + Assert.AreEqual(0, rgbq.rgbBlue); + Assert.AreEqual(0, rgbq.rgbGreen); + Assert.AreEqual(0, rgbq.rgbRed); + Assert.AreEqual(255, rgbq.rgbReserved); + + rgbq = Color.DarkGoldenrod; + Color color = rgbq; + Assert.That(EqualColors(Color.DarkGoldenrod, color)); + } + + [Test] + public void RGBTRIPLE() + { + RGBTRIPLE rgbt = new RGBTRIPLE(); + Assert.AreEqual(0, rgbt.rgbtBlue); + Assert.AreEqual(0, rgbt.rgbtGreen); + Assert.AreEqual(0, rgbt.rgbtRed); + + rgbt = new RGBTRIPLE(Color.Chartreuse); + Assert.That(EqualColors(Color.Chartreuse, rgbt.Color)); + + rgbt = new RGBTRIPLE(Color.FromArgb(133, 83, 95, 173)); + Assert.AreEqual(173, rgbt.rgbtBlue); + Assert.AreEqual(95, rgbt.rgbtGreen); + Assert.AreEqual(83, rgbt.rgbtRed); + + rgbt.Color = Color.Crimson; + Assert.That(EqualColors(Color.Crimson, rgbt.Color)); + + rgbt.Color = Color.MidnightBlue; + Assert.That(EqualColors(Color.MidnightBlue, rgbt.Color)); + + rgbt.Color = Color.White; + Assert.AreEqual(255, rgbt.rgbtBlue); + Assert.AreEqual(255, rgbt.rgbtGreen); + Assert.AreEqual(255, rgbt.rgbtRed); + + rgbt.Color = Color.Black; + Assert.AreEqual(0, rgbt.rgbtBlue); + Assert.AreEqual(0, rgbt.rgbtGreen); + Assert.AreEqual(0, rgbt.rgbtRed); + + rgbt = Color.DarkGoldenrod; + Color color = rgbt; + Assert.That(EqualColors(Color.DarkGoldenrod, color)); + } + + [Test] + public void FIRGB16() + { + FIRGB16 rgb = new FIRGB16(); + Assert.AreEqual(0 * 256, rgb.blue); + Assert.AreEqual(0 * 256, rgb.green); + Assert.AreEqual(0 * 256, rgb.red); + + rgb = new FIRGB16(Color.Chartreuse); + Assert.That(EqualColors(Color.Chartreuse, rgb.Color)); + + rgb = new FIRGB16(Color.FromArgb(133, 83, 95, 173)); + Assert.AreEqual(173 * 256, rgb.blue); + Assert.AreEqual(95 * 256, rgb.green); + Assert.AreEqual(83 * 256, rgb.red); + + rgb.Color = Color.Crimson; + Assert.That(EqualColors(Color.Crimson, rgb.Color)); + + rgb.Color = Color.MidnightBlue; + Assert.That(EqualColors(Color.MidnightBlue, rgb.Color)); + + rgb.Color = Color.White; + Assert.AreEqual(255 * 256, rgb.blue); + Assert.AreEqual(255 * 256, rgb.green); + Assert.AreEqual(255 * 256, rgb.red); + + rgb.Color = Color.Black; + Assert.AreEqual(0 * 256, rgb.blue); + Assert.AreEqual(0 * 256, rgb.green); + Assert.AreEqual(0 * 256, rgb.red); + + rgb = Color.DarkGoldenrod; + Color color = rgb; + Assert.That(EqualColors(Color.DarkGoldenrod, color)); + } + + [Test] + public void FIRGBA16() + { + FIRGBA16 rgb = new FIRGBA16(); + Assert.AreEqual(0 * 256, rgb.blue); + Assert.AreEqual(0 * 256, rgb.green); + Assert.AreEqual(0 * 256, rgb.red); + Assert.AreEqual(0 * 256, rgb.alpha); + + rgb = new FIRGBA16(Color.Chartreuse); + Assert.That(EqualColors(Color.Chartreuse, rgb.Color)); + + rgb = new FIRGBA16(Color.FromArgb(133, 83, 95, 173)); + Assert.AreEqual(173 * 256, rgb.blue); + Assert.AreEqual(95 * 256, rgb.green); + Assert.AreEqual(83 * 256, rgb.red); + Assert.AreEqual(133 * 256, rgb.alpha); + + rgb.Color = Color.Crimson; + Assert.That(EqualColors(Color.Crimson, rgb.Color)); + + rgb.Color = Color.MidnightBlue; + Assert.That(EqualColors(Color.MidnightBlue, rgb.Color)); + + rgb.Color = Color.White; + Assert.AreEqual(255 * 256, rgb.blue); + Assert.AreEqual(255 * 256, rgb.green); + Assert.AreEqual(255 * 256, rgb.red); + Assert.AreEqual(255 * 256, rgb.alpha); + + rgb.Color = Color.Black; + Assert.AreEqual(0 * 256, rgb.blue); + Assert.AreEqual(0 * 256, rgb.green); + Assert.AreEqual(0 * 256, rgb.red); + Assert.AreEqual(255 * 256, rgb.alpha); + + rgb = Color.DarkGoldenrod; + Color color = rgb; + Assert.That(EqualColors(Color.DarkGoldenrod, color)); + } + + [Test] + public void FIRGBF() + { + FIRGBF rgb = new FIRGBF(); + Assert.AreEqual(0 / 255f, rgb.blue); + Assert.AreEqual(0 / 255f, rgb.green); + Assert.AreEqual(0 / 255f, rgb.red); + + rgb = new FIRGBF(Color.Chartreuse); + Assert.That(EqualColors(Color.Chartreuse, rgb.Color)); + + rgb = new FIRGBF(Color.FromArgb(133, 83, 95, 173)); + Assert.AreEqual(173 / 255f, rgb.blue); + Assert.AreEqual(95 / 255f, rgb.green); + Assert.AreEqual(83 / 255f, rgb.red); + + rgb.Color = Color.Crimson; + Assert.That(EqualColors(Color.Crimson, rgb.Color)); + + rgb.Color = Color.MidnightBlue; + Assert.That(EqualColors(Color.MidnightBlue, rgb.Color)); + + rgb.Color = Color.White; + Assert.AreEqual(255 / 255f, rgb.blue); + Assert.AreEqual(255 / 255f, rgb.green); + Assert.AreEqual(255 / 255f, rgb.red); + + rgb.Color = Color.Black; + Assert.AreEqual(0 / 255f, rgb.blue); + Assert.AreEqual(0 / 255f, rgb.green); + Assert.AreEqual(0 / 255f, rgb.red); + + rgb = Color.DarkGoldenrod; + Color color = rgb; + Assert.That(EqualColors(Color.DarkGoldenrod, color)); + } + + [Test] + public void FIRGBAF() + { + FIRGBAF rgb = new FIRGBAF(); + Assert.AreEqual(0 / 255f, rgb.blue); + Assert.AreEqual(0 / 255f, rgb.green); + Assert.AreEqual(0 / 255f, rgb.red); + Assert.AreEqual(0 / 255f, rgb.alpha); + + rgb = new FIRGBAF(Color.Chartreuse); + Assert.That(EqualColors(Color.Chartreuse, rgb.Color)); + + rgb = new FIRGBAF(Color.FromArgb(133, 83, 95, 173)); + Assert.AreEqual(173 / 255f, rgb.blue); + Assert.AreEqual(95 / 255f, rgb.green); + Assert.AreEqual(83 / 255f, rgb.red); + Assert.AreEqual(133 / 255f, rgb.alpha); + + rgb.Color = Color.Crimson; + Assert.That(EqualColors(Color.Crimson, rgb.Color)); + + rgb.Color = Color.MidnightBlue; + Assert.That(EqualColors(Color.MidnightBlue, rgb.Color)); + + rgb.Color = Color.White; + Assert.AreEqual(255 / 255f, rgb.blue); + Assert.AreEqual(255 / 255f, rgb.green); + Assert.AreEqual(255 / 255f, rgb.red); + Assert.AreEqual(255 / 255f, rgb.alpha); + + rgb.Color = Color.Black; + Assert.AreEqual(0 / 255f, rgb.blue); + Assert.AreEqual(0 / 255f, rgb.green); + Assert.AreEqual(0 / 255f, rgb.red); + Assert.AreEqual(255 / 255f, rgb.alpha); + + rgb = Color.DarkGoldenrod; + Color color = rgb; + Assert.That(EqualColors(Color.DarkGoldenrod, color)); + } + + [Ignore] + public void FICOMPLEX() + { + } + + [Test] + public void FIBITMAP() + { + FIBITMAP var = new FIBITMAP(); + Assert.IsTrue(var.IsNull); + } + + [Test] + public void fi_handle() + { + fi_handle var = new fi_handle(); + Assert.IsTrue(var.IsNull); + + string test = "hello word!"; + using (var = new fi_handle(test)) + { + Assert.IsFalse(var.IsNull); + + object obj = var.GetObject(); + Assert.That(obj is string); + Assert.AreSame(obj, test); + } + } + + [Test] + public void FIICCPROFILE() + { + Random rand = new Random(DateTime.Now.Millisecond); + FIICCPROFILE var = new FIICCPROFILE(); + Assert.AreEqual(0, var.Data.Length); + Assert.AreEqual(IntPtr.Zero, var.DataPointer); + Assert.AreEqual(0, var.Size); + + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + byte[] data = new byte[512]; + rand.NextBytes(data); + + var = FreeImage.GetICCProfileEx(dib); + Assert.AreEqual(0, var.Size); + + var = new FIICCPROFILE(dib, data, 256); + Assert.AreEqual(256, var.Data.Length); + Assert.AreNotEqual(IntPtr.Zero, var.DataPointer); + Assert.AreEqual(256, var.Size); + byte[] dataComp = var.Data; + for (int i = 0; i < data.Length && i < dataComp.Length; i++) + if (data[i] != dataComp[i]) + Assert.Fail(); + + FreeImage.DestroyICCProfile(dib); + var = FreeImage.GetICCProfileEx(dib); + Assert.AreEqual(0, var.Size); + + var = new FIICCPROFILE(dib, data); + Assert.AreEqual(512, var.Data.Length); + Assert.AreNotEqual(IntPtr.Zero, var.DataPointer); + Assert.AreEqual(512, var.Size); + dataComp = var.Data; + for (int i = 0; i < data.Length && i < dataComp.Length; i++) + if (data[i] != dataComp[i]) + Assert.Fail(); + + var = FreeImage.GetICCProfileEx(dib); + Assert.AreEqual(512, var.Data.Length); + Assert.AreNotEqual(IntPtr.Zero, var.DataPointer); + Assert.AreEqual(512, var.Size); + + FreeImage.DestroyICCProfile(dib); + var = FreeImage.GetICCProfileEx(dib); + Assert.AreEqual(0, var.Size); + + FreeImage.UnloadEx(ref dib); + } + } + + [TestFixture] + public class WrapperStructsTest + { + ImageManager iManager = new ImageManager(); + FIBITMAP dib = new FIBITMAP(); + string freeImageCallback = null; + + [TestFixtureSetUp] + public void Init() + { + FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); + } + + [TestFixtureTearDown] + public void DeInit() + { + FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); + } + + [SetUp] + public void InitEachTime() + { + } + + [TearDown] + public void DeInitEachTime() + { + } + + void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) + { + freeImageCallback = message; + } + + public bool EqualColors(Color color1, Color color2) + { + if (color1.A != color2.A) return false; + if (color1.R != color2.R) return false; + if (color1.G != color2.G) return false; + if (color1.B != color2.B) return false; + return true; + } + + [Test] + public void FIRational() + { + FIRational rational1 = new FIRational(); + FIRational rational2 = new FIRational(); + FIRational rational3 = new FIRational(); + + // + // Constructors + // + + Assert.That(rational1.Numerator == 0); + Assert.That(rational1.Denominator == 0); + + rational1 = new FIRational(412, 33); + Assert.That(rational1.Numerator == 412); + Assert.That(rational1.Denominator == 33); + + rational2 = new FIRational(rational1); + Assert.That(rational2.Numerator == 412); + Assert.That(rational2.Denominator == 33); + + rational3 = new FIRational(5.75m); + Assert.That(rational3.Numerator == 23); + Assert.That(rational3.Denominator == 4); + + // + // == != + // + + rational1 = new FIRational(421, 51); + rational2 = rational1; + Assert.That(rational1 == rational2); + Assert.That(!(rational1 != rational2)); + + rational2 = new FIRational(1, 7); + Assert.That(rational1 != rational2); + Assert.That(!(rational1 == rational2)); + + // + // > >= < <= + // + + rational1 = new FIRational(51, 4); + rational2 = new FIRational(27, 9); + Assert.That(rational1 != rational2); + Assert.That(rational1 > rational2); + Assert.That(rational1 >= rational2); + + rational1 = new FIRational(-412, 4); + Assert.That(rational1 != rational2); + Assert.That(rational1 < rational2); + Assert.That(rational1 <= rational2); + + // + // + / - + // + + rational1 = new FIRational(41, 3); + rational2 = new FIRational(612, 412); + rational3 = rational1 - rational2; + Assert.That((rational3 + rational2) == rational1); + + rational1 = new FIRational(-7852, 63); + rational2 = new FIRational(666111, -7654); + rational3 = rational1 - rational2; + Assert.That((rational3 + rational2) == rational1); + + rational1 = new FIRational(-513, 88); + rational2 = new FIRational(413, 5); + rational3 = rational1 - rational2; + Assert.That((rational3 + rational2) == rational1); + + rational1 = new FIRational(-513, 88); + rational2 = new FIRational(413, 5); + rational3 = rational1 - rational2; + Assert.That((rational3 + rational2) == rational1); + + rational1 = new FIRational(7531, 23144); + rational2 = new FIRational(-412, 78777); + rational3 = rational1 - rational2; + Assert.That((rational3 + rational2) == rational1); + + rational1 = new FIRational(513, -42123); + rational2 = new FIRational(-42, 77); + rational3 = rational1 - rational2; + Assert.That((rational3 + rational2) == rational1); + + rational1 = new FIRational(44, 11); + rational1 = -rational1; + Assert.That(rational1.Numerator == -4 && rational1.Denominator == 1); + + // + // % + // + + rational1 = new FIRational(23, 8); + rational2 = new FIRational(77, 777); + Assert.That((rational1 % rational2) == 0); + + rational2 = -rational2; + Assert.That((rational1 % rational2) == 0); + + rational2 = new FIRational(7, 4); + rational3 = new FIRational(9, 8); + Assert.That((rational1 % rational2) == rational3); + + rational2 = -rational2; + Assert.That((rational1 % rational2) == rational3); + + // + // ~ + // + + rational1 = new FIRational(41, 77); + rational1 = ~rational1; + Assert.That(rational1.Numerator == 77 && rational1.Denominator == 41); + + // + // - + // + + rational1 = new FIRational(52, 4); + rational1 = -rational1; + Assert.That(rational1 < 0); + + // + // ++ -- + // + + rational1 = new FIRational(5, 3); + rational1++; + rational2 = new FIRational(8, 3); + Assert.That(rational1 == rational2); + + rational1 = new FIRational(41, -43); + rational1++; + Assert.That(rational1 > 0.0f); + + rational1--; + Assert.That(rational1 == new FIRational(41, -43)); + + rational1 = new FIRational(8134, 312); + Assert.That(rational1 != 26); + + // + // Direct assigns + // + + rational1 = (FIRational)0.75m; + Assert.That(rational1.Numerator == 3 && rational1.Denominator == 4); + rational1 = (FIRational)0.33; + Assert.That(rational1.Numerator == 33 && rational1.Denominator == 100); + rational1 = (FIRational)62.975m; + Assert.That(((decimal)rational1.Numerator / (decimal)rational1.Denominator) == 62.975m); + rational1 = (FIRational)(-73.0975m); + Assert.That(((decimal)rational1.Numerator / (decimal)rational1.Denominator) == -73.0975m); + rational1 = (FIRational)(7m / 9m); + Assert.That(rational1.Numerator == 7 && rational1.Denominator == 9); + rational1 = (FIRational)(-15m / 9m); + Assert.That(rational1.Numerator == -5 && rational1.Denominator == 3); + rational1 = (FIRational)(0.7777m); + Assert.That(rational1.Denominator != 9); + + // + // Properties + // + + rational1 = new FIRational(515, 5); + Assert.That(rational1.IsInteger); + + rational1 = new FIRational(876, 77); + Assert.That(rational1.Truncate() == (876 / 77)); + + // + // Special cases + // + + rational1 = new FIRational(0, 10000); + Assert.That(rational1 == 0m); + + rational1 = new FIRational(10000, 0); + Assert.That(rational1 == 0f); + + rational1 = new FIRational(0, 0); + Assert.That(rational1 == 0d); + + rational1 = new FIRational(-1, 0); + Assert.That(rational1 == 0); + + rational1 = new FIRational(0, -1); + Assert.That(rational1 == 0); + } + + [Ignore] + public void StreamWrapper() + { + string url = @"http://freeimage.sourceforge.net/images/logo.jpg"; + + // + // Non blocking + // + + HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); + Assert.IsNotNull(req); + + req.Timeout = 1000; + HttpWebResponse resp; + try + { + resp = (HttpWebResponse)req.GetResponse(); + } + catch + { + return; + } + Assert.IsNotNull(resp); + + Stream stream = resp.GetResponseStream(); + Assert.IsNotNull(stream); + + StreamWrapper wrapper = new StreamWrapper(stream, false); + Assert.IsNotNull(wrapper); + Assert.IsTrue(wrapper.CanRead && wrapper.CanSeek && !wrapper.CanWrite); + + byte[] buffer = new byte[1024 * 100]; + int read; + int count = 0; + + do + { + read = wrapper.Read(buffer, count, buffer.Length - count); + count += read; + } while (read != 0); + + Assert.AreEqual(7972, count); + Assert.AreEqual(7972, wrapper.Length); + + wrapper.Position = 0; + Assert.AreEqual(0, wrapper.Position); + + byte[] test = new byte[buffer.Length]; + int countTest = 0; + + do + { + read = wrapper.Read(test, countTest, test.Length - countTest); + countTest += read; + } while (read != 0); + + Assert.AreEqual(count, countTest); + + for (int i = 0; i < countTest; i++) + if (buffer[i] != test[i]) + Assert.Fail(); + + resp.Close(); + wrapper.Dispose(); + stream.Dispose(); + + // + // Blocking + // + + req = (HttpWebRequest)HttpWebRequest.Create(url); + Assert.IsNotNull(req); + + resp = (HttpWebResponse)req.GetResponse(); + Assert.IsNotNull(resp); + + stream = resp.GetResponseStream(); + Assert.IsNotNull(stream); + + wrapper = new StreamWrapper(stream, true); + Assert.IsNotNull(wrapper); + Assert.IsTrue(wrapper.CanRead && wrapper.CanSeek && !wrapper.CanWrite); + + buffer = new byte[1024 * 100]; + count = 0; + + count = wrapper.Read(buffer, 0, buffer.Length); + Assert.AreEqual(7972, count); + + resp.Close(); + stream.Dispose(); + wrapper.Dispose(); + + // + // Position & Read byte + // + + buffer = new byte[] { 0x00, 0x01, 0x02, 0xFF, 0xFE, 0xFD }; + stream = new MemoryStream(buffer); + wrapper = new StreamWrapper(stream, false); + + Assert.That(0x00 == wrapper.ReadByte()); + Assert.That(0x01 == wrapper.ReadByte()); + Assert.That(0x02 == wrapper.ReadByte()); + Assert.That(0xFF == wrapper.ReadByte()); + Assert.That(0xFE == wrapper.ReadByte()); + Assert.That(0xFD == wrapper.ReadByte()); + Assert.That(-1 == wrapper.ReadByte()); + + Assert.That(wrapper.Length == buffer.Length); + + wrapper.Seek(0, SeekOrigin.Begin); + Assert.That(0x00 == wrapper.ReadByte()); + wrapper.Seek(3, SeekOrigin.Begin); + Assert.That(0xFF == wrapper.ReadByte()); + wrapper.Seek(0, SeekOrigin.End); + Assert.That(-1 == wrapper.ReadByte()); + wrapper.Seek(-2, SeekOrigin.End); + Assert.That(0xFE == wrapper.ReadByte()); + wrapper.Seek(0, SeekOrigin.Begin); + Assert.That(0x00 == wrapper.ReadByte()); + wrapper.Seek(2, SeekOrigin.Current); + Assert.That(0xFF == wrapper.ReadByte()); + wrapper.Seek(1, SeekOrigin.Current); + Assert.That(0xFD == wrapper.ReadByte()); + Assert.That(wrapper.Position != 0); + wrapper.Reset(); + Assert.That(wrapper.Position == 0); + + wrapper.Dispose(); + stream.Position = 0; + wrapper = new StreamWrapper(stream, false); + + wrapper.Seek(10, SeekOrigin.Begin); + Assert.That(wrapper.Position == buffer.Length); + + wrapper.Dispose(); + stream.Dispose(); + } + + [Ignore] + public void LocalPlugin() + { + } + + [Test] + public void FreeImageStreamIO() + { + Random rand = new Random(); + byte[] bBuffer = new byte[256]; + IntPtr buffer = Marshal.AllocHGlobal(256); + + MemoryStream stream = new MemoryStream(); + Assert.IsNotNull(stream); + using (fi_handle handle = new fi_handle(stream)) + { + + FreeImageIO io = FreeImageAPI.IO.FreeImageStreamIO.io; + Assert.IsNotNull(io.readProc); + Assert.IsNotNull(io.writeProc); + Assert.IsNotNull(io.seekProc); + Assert.IsNotNull(io.tellProc); + + // + // Procs + // + + rand.NextBytes(bBuffer); + + stream.Write(bBuffer, 0, bBuffer.Length); + Assert.That(io.tellProc(handle) == stream.Position); + Assert.That(io.seekProc(handle, 0, SeekOrigin.Begin) == 0); + Assert.That(io.tellProc(handle) == 0); + Assert.That(io.tellProc(handle) == stream.Position); + + // Read one block + Assert.That(io.readProc(buffer, (uint)bBuffer.Length, 1, handle) == 1); + for (int i = 0; i < bBuffer.Length; i++) + Assert.That(Marshal.ReadByte(buffer, i) == bBuffer[i]); + + Assert.That(io.tellProc(handle) == stream.Position); + Assert.That(io.seekProc(handle, 0, SeekOrigin.Begin) == 0); + Assert.That(io.tellProc(handle) == stream.Position); + + // Read 1 byte block + Assert.That(io.readProc(buffer, 1, (uint)bBuffer.Length, handle) == bBuffer.Length); + for (int i = 0; i < bBuffer.Length; i++) + Assert.That(Marshal.ReadByte(buffer, i) == bBuffer[i]); + + Assert.That(io.tellProc(handle) == stream.Position); + Assert.That(io.seekProc(handle, 0, SeekOrigin.Begin) == 0); + Assert.That(io.tellProc(handle) == stream.Position); + + rand.NextBytes(bBuffer); + for (int i = 0; i < bBuffer.Length; i++) + Marshal.WriteByte(buffer, i, bBuffer[i]); + + // Write one block + + Assert.That(io.writeProc(buffer, (uint)bBuffer.Length, 1, handle) == 1); + for (int i = 0; i < bBuffer.Length; i++) + Assert.That(Marshal.ReadByte(buffer, i) == bBuffer[i]); + Assert.That(io.tellProc(handle) == stream.Position); + + Assert.That(io.seekProc(handle, 0, SeekOrigin.Begin) == 0); + Assert.That(io.tellProc(handle) == 0); + + // write 1 byte block + + Assert.That(io.writeProc(buffer, 1, (uint)bBuffer.Length, handle) == bBuffer.Length); + for (int i = 0; i < bBuffer.Length; i++) + Assert.That(Marshal.ReadByte(buffer, i) == bBuffer[i]); + Assert.That(io.tellProc(handle) == stream.Position); + + // Seek and tell + + Assert.That(io.seekProc(handle, 0, SeekOrigin.Begin) == 0); + Assert.That(io.tellProc(handle) == 0); + + Assert.That(io.seekProc(handle, 127, SeekOrigin.Current) == 0); + Assert.That(io.tellProc(handle) == 127); + + Assert.That(io.seekProc(handle, 0, SeekOrigin.End) == 0); + Assert.That(io.tellProc(handle) == 256); + + Marshal.FreeHGlobal(buffer); + stream.Dispose(); + } + } + + [Test] + public void MetadataTag() + { + FITAG tag; + MetadataTag metaTag; + + Random rand = new Random(); + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.IsFalse(dib.IsNull); + + Assert.That(FreeImage.GetMetadataCount(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib) > 0); + + FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib, out tag); + Assert.IsFalse(tag.IsNull); + Assert.IsFalse(mData.IsNull); + + // + // Constructors + // + + metaTag = new MetadataTag(tag, dib); + Assert.That(metaTag.Model == FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN); + + metaTag = new MetadataTag(tag, FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN); + Assert.That(metaTag.Model == FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN); + + // + // Properties + // + + metaTag.ID = ushort.MinValue; + Assert.That(metaTag.ID == ushort.MinValue); + + metaTag.ID = ushort.MaxValue; + Assert.That(metaTag.ID == ushort.MaxValue); + + metaTag.ID = ushort.MaxValue / 2; + Assert.That(metaTag.ID == ushort.MaxValue / 2); + + metaTag.Description = ""; + Assert.That(metaTag.Description == ""); + + metaTag.Description = "A"; + Assert.That(metaTag.Description == "A"); + + metaTag.Description = "ABCDEFG"; + Assert.That(metaTag.Description == "ABCDEFG"); + + metaTag.Key = ""; + Assert.That(metaTag.Key == ""); + + metaTag.Key = "A"; + Assert.That(metaTag.Key == "A"); + + metaTag.Key = "ABCDEFG"; + Assert.That(metaTag.Key == "ABCDEFG"); + + // + // SetValue + // + + try + { + metaTag.SetValue(null, FREE_IMAGE_MDTYPE.FIDT_ASCII); + Assert.Fail(); + } + catch + { + } + + // + // FREE_IMAGE_MDTYPE.FIDT_ASCII + // + + string testString = ""; + + Assert.IsTrue(metaTag.SetValue(testString, FREE_IMAGE_MDTYPE.FIDT_ASCII)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((string)metaTag.Value).Length == 0); + + testString = "X"; + + Assert.IsTrue(metaTag.SetValue(testString, FREE_IMAGE_MDTYPE.FIDT_ASCII)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((string)metaTag.Value).Length == testString.Length); + Assert.That(((string)metaTag.Value) == testString); + + testString = "TEST-STRING"; + + Assert.IsTrue(metaTag.SetValue(testString, FREE_IMAGE_MDTYPE.FIDT_ASCII)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((string)metaTag.Value).Length == testString.Length); + Assert.That(((string)metaTag.Value) == testString); + + // + // FREE_IMAGE_MDTYPE.FIDT_BYTE + // + + byte testByte; + byte[] testByteArray; + + Assert.IsTrue(metaTag.SetValue(byte.MinValue, FREE_IMAGE_MDTYPE.FIDT_BYTE)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((byte[])metaTag.Value).Length == 1); + Assert.That(((byte[])metaTag.Value)[0] == byte.MinValue); + + Assert.IsTrue(metaTag.SetValue(byte.MaxValue, FREE_IMAGE_MDTYPE.FIDT_BYTE)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((byte[])metaTag.Value).Length == 1); + Assert.That(((byte[])metaTag.Value)[0] == byte.MaxValue); + + for (int i = 0; i < 10; i++) + { + testByte = (byte)rand.Next(byte.MinValue, byte.MaxValue); + testByteArray = new byte[rand.Next(0, 31)]; + + for (int j = 0; j < testByteArray.Length; j++) + testByteArray[j] = (byte)rand.Next(); + + Assert.IsTrue(metaTag.SetValue(testByte, FREE_IMAGE_MDTYPE.FIDT_BYTE)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((byte[])metaTag.Value).Length == 1); + Assert.That(metaTag.Count == 1); + Assert.That(metaTag.Length == 1); + Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_BYTE); + Assert.That(((byte[])metaTag.Value)[0] == testByte); + + Assert.IsTrue(metaTag.SetValue(testByteArray, FREE_IMAGE_MDTYPE.FIDT_BYTE)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((byte[])metaTag.Value).Length == testByteArray.Length); + Assert.That(metaTag.Count == testByteArray.Length); + Assert.That(metaTag.Length == testByteArray.Length * 1); + + byte[] value = (byte[])metaTag.Value; + + for (int j = 0; j < value.Length; j++) + Assert.That(testByteArray[j] == value[j]); + } + + // + // FREE_IMAGE_MDTYPE.FIDT_DOUBLE + // + + double testDouble; + double[] testDoubleArray; + + Assert.IsTrue(metaTag.SetValue(double.MinValue, FREE_IMAGE_MDTYPE.FIDT_DOUBLE)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((double[])metaTag.Value).Length == 1); + Assert.That(((double[])metaTag.Value)[0] == double.MinValue); + + Assert.IsTrue(metaTag.SetValue(double.MaxValue, FREE_IMAGE_MDTYPE.FIDT_DOUBLE)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((double[])metaTag.Value).Length == 1); + Assert.That(((double[])metaTag.Value)[0] == double.MaxValue); + + for (int i = 0; i < 10; i++) + { + testDouble = (double)rand.NextDouble(); + testDoubleArray = new double[rand.Next(0, 31)]; + + for (int j = 0; j < testDoubleArray.Length; j++) + testDoubleArray[j] = rand.NextDouble(); + + Assert.IsTrue(metaTag.SetValue(testDouble, FREE_IMAGE_MDTYPE.FIDT_DOUBLE)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((double[])metaTag.Value).Length == 1); + Assert.That(metaTag.Count == 1); + Assert.That(metaTag.Length == 8); + Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_DOUBLE); + Assert.That(((double[])metaTag.Value)[0] == testDouble); + + Assert.IsTrue(metaTag.SetValue(testDoubleArray, FREE_IMAGE_MDTYPE.FIDT_DOUBLE)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((double[])metaTag.Value).Length == testDoubleArray.Length); + Assert.That(metaTag.Count == testDoubleArray.Length); + Assert.That(metaTag.Length == testDoubleArray.Length * 8); + + double[] value = (double[])metaTag.Value; + + for (int j = 0; j < value.Length; j++) + Assert.That(testDoubleArray[j] == value[j]); + } + + // + // FREE_IMAGE_MDTYPE.FIDT_FLOAT + // + + float testfloat; + float[] testFloatArray; + + Assert.IsTrue(metaTag.SetValue(float.MinValue, FREE_IMAGE_MDTYPE.FIDT_FLOAT)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((float[])metaTag.Value).Length == 1); + Assert.That(((float[])metaTag.Value)[0] == float.MinValue); + + Assert.IsTrue(metaTag.SetValue(float.MaxValue, FREE_IMAGE_MDTYPE.FIDT_FLOAT)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((float[])metaTag.Value).Length == 1); + Assert.That(((float[])metaTag.Value)[0] == float.MaxValue); + + for (int i = 0; i < 10; i++) + { + testfloat = (float)rand.NextDouble(); + testFloatArray = new float[rand.Next(0, 31)]; + + for (int j = 0; j < testFloatArray.Length; j++) + testFloatArray[j] = (float)rand.NextDouble(); + + Assert.IsTrue(metaTag.SetValue(testfloat, FREE_IMAGE_MDTYPE.FIDT_FLOAT)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((float[])metaTag.Value).Length == 1); + Assert.That(metaTag.Count == 1); + Assert.That(metaTag.Length == 4); + Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_FLOAT); + Assert.That(((float[])metaTag.Value)[0] == testfloat); + + Assert.IsTrue(metaTag.SetValue(testFloatArray, FREE_IMAGE_MDTYPE.FIDT_FLOAT)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((float[])metaTag.Value).Length == testFloatArray.Length); + Assert.That(metaTag.Count == testFloatArray.Length); + Assert.That(metaTag.Length == testFloatArray.Length * 4); + + float[] value = (float[])metaTag.Value; + + for (int j = 0; j < value.Length; j++) + Assert.That(testFloatArray[j] == value[j]); + } + + // + // FREE_IMAGE_MDTYPE.FIDT_IFD + // + + uint testUint; + uint[] testUintArray; + + Assert.IsTrue(metaTag.SetValue(uint.MinValue, FREE_IMAGE_MDTYPE.FIDT_IFD)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((uint[])metaTag.Value).Length == 1); + Assert.That(((uint[])metaTag.Value)[0] == uint.MinValue); + + Assert.IsTrue(metaTag.SetValue(uint.MaxValue, FREE_IMAGE_MDTYPE.FIDT_IFD)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((uint[])metaTag.Value).Length == 1); + Assert.That(((uint[])metaTag.Value)[0] == uint.MaxValue); + + for (int i = 0; i < 10; i++) + { + testUint = (uint)rand.NextDouble(); + testUintArray = new uint[rand.Next(0, 31)]; + + for (int j = 0; j < testUintArray.Length; j++) + testUintArray[j] = (uint)rand.Next(); + + Assert.IsTrue(metaTag.SetValue(testUint, FREE_IMAGE_MDTYPE.FIDT_IFD)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((uint[])metaTag.Value).Length == 1); + Assert.That(metaTag.Count == 1); + Assert.That(metaTag.Length == 4); + Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_IFD); + Assert.That(((uint[])metaTag.Value)[0] == testUint); + + Assert.IsTrue(metaTag.SetValue(testUintArray, FREE_IMAGE_MDTYPE.FIDT_IFD)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((uint[])metaTag.Value).Length == testUintArray.Length); + Assert.That(metaTag.Count == testUintArray.Length); + Assert.That(metaTag.Length == testUintArray.Length * 4); + + uint[] value = (uint[])metaTag.Value; + + for (int j = 0; j < value.Length; j++) + Assert.That(testUintArray[j] == value[j]); + } + + // + // FREE_IMAGE_MDTYPE.FIDT_LONG + // + + Assert.IsTrue(metaTag.SetValue(uint.MinValue, FREE_IMAGE_MDTYPE.FIDT_LONG)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((uint[])metaTag.Value).Length == 1); + Assert.That(((uint[])metaTag.Value)[0] == uint.MinValue); + + Assert.IsTrue(metaTag.SetValue(uint.MaxValue, FREE_IMAGE_MDTYPE.FIDT_LONG)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((uint[])metaTag.Value).Length == 1); + Assert.That(((uint[])metaTag.Value)[0] == uint.MaxValue); + + for (int i = 0; i < 10; i++) + { + testUint = (uint)rand.NextDouble(); + testUintArray = new uint[rand.Next(0, 31)]; + + for (int j = 0; j < testUintArray.Length; j++) + testUintArray[j] = (uint)rand.Next(); + + Assert.IsTrue(metaTag.SetValue(testUint, FREE_IMAGE_MDTYPE.FIDT_LONG)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((uint[])metaTag.Value).Length == 1); + Assert.That(metaTag.Count == 1); + Assert.That(metaTag.Length == 4); + Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_LONG); + Assert.That(((uint[])metaTag.Value)[0] == testUint); + + Assert.IsTrue(metaTag.SetValue(testUintArray, FREE_IMAGE_MDTYPE.FIDT_LONG)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((uint[])metaTag.Value).Length == testUintArray.Length); + Assert.That(metaTag.Count == testUintArray.Length); + Assert.That(metaTag.Length == testUintArray.Length * 4); + + uint[] value = (uint[])metaTag.Value; + + for (int j = 0; j < value.Length; j++) + Assert.That(testUintArray[j] == value[j]); + } + + // + // FREE_IMAGE_MDTYPE.FIDT_NOTYPE + // + + try + { + metaTag.SetValue(new object(), FREE_IMAGE_MDTYPE.FIDT_NOTYPE); + Assert.Fail(); + } + catch (NotSupportedException) + { + } + + // + // FREE_IMAGE_MDTYPE.FIDT_PALETTE + // + + RGBQUAD testRGBQUAD; + RGBQUAD[] testRGBQUADArray; + + for (int i = 0; i < 10; i++) + { + testRGBQUAD = new RGBQUAD(Color.FromArgb(rand.Next())); + testRGBQUADArray = new RGBQUAD[rand.Next(0, 31)]; + + for (int j = 0; j < testRGBQUADArray.Length; j++) + testRGBQUADArray[j] = new RGBQUAD(Color.FromArgb(rand.Next())); + + Assert.IsTrue(metaTag.SetValue(testRGBQUAD, FREE_IMAGE_MDTYPE.FIDT_PALETTE)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((RGBQUAD[])metaTag.Value).Length == 1); + Assert.That(metaTag.Count == 1); + Assert.That(metaTag.Length == 4); + Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_PALETTE); + Assert.That(((RGBQUAD[])metaTag.Value)[0] == testRGBQUAD); + + Assert.IsTrue(metaTag.SetValue(testRGBQUADArray, FREE_IMAGE_MDTYPE.FIDT_PALETTE)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((RGBQUAD[])metaTag.Value).Length == testRGBQUADArray.Length); + Assert.That(metaTag.Count == testRGBQUADArray.Length); + Assert.That(metaTag.Length == testRGBQUADArray.Length * 4); + + RGBQUAD[] value = (RGBQUAD[])metaTag.Value; + + for (int j = 0; j < value.Length; j++) + Assert.That(testRGBQUADArray[j] == value[j]); + } + + // + // FREE_IMAGE_MDTYPE.FIDT_RATIONAL + // + + FIURational testFIURational; + FIURational[] testFIURationalArray; + + for (int i = 0; i < 10; i++) + { + testFIURational = new FIURational((uint)rand.Next(), (uint)rand.Next()); + testFIURationalArray = new FIURational[rand.Next(0, 31)]; + + for (int j = 0; j < testFIURationalArray.Length; j++) + testFIURationalArray[j] = new FIURational((uint)rand.Next(), (uint)rand.Next()); + + Assert.IsTrue(metaTag.SetValue(testFIURational, FREE_IMAGE_MDTYPE.FIDT_RATIONAL)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((FIURational[])metaTag.Value).Length == 1); + Assert.That(metaTag.Count == 1); + Assert.That(metaTag.Length == 8); + Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_RATIONAL); + Assert.That(((FIURational[])metaTag.Value)[0] == testFIURational); + + Assert.IsTrue(metaTag.SetValue(testFIURationalArray, FREE_IMAGE_MDTYPE.FIDT_RATIONAL)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((FIURational[])metaTag.Value).Length == testFIURationalArray.Length); + Assert.That(metaTag.Count == testFIURationalArray.Length); + Assert.That(metaTag.Length == testFIURationalArray.Length * 8); + + FIURational[] value = (FIURational[])metaTag.Value; + + for (int j = 0; j < value.Length; j++) + Assert.That(testFIURationalArray[j] == value[j]); + } + + // + // FREE_IMAGE_MDTYPE.FIDT_SBYTE + // + + sbyte testSByte; + sbyte[] testSByteArray; + + Assert.IsTrue(metaTag.SetValue(sbyte.MinValue, FREE_IMAGE_MDTYPE.FIDT_SBYTE)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((sbyte[])metaTag.Value).Length == 1); + Assert.That(((sbyte[])metaTag.Value)[0] == sbyte.MinValue); + + Assert.IsTrue(metaTag.SetValue(sbyte.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SBYTE)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((sbyte[])metaTag.Value).Length == 1); + Assert.That(((sbyte[])metaTag.Value)[0] == sbyte.MaxValue); + + for (int i = 0; i < 10; i++) + { + testSByte = (sbyte)rand.Next(sbyte.MinValue, sbyte.MaxValue); + testSByteArray = new sbyte[rand.Next(0, 31)]; + + for (int j = 0; j < testSByteArray.Length; j++) + testSByteArray[j] = (sbyte)rand.Next(); + + Assert.IsTrue(metaTag.SetValue(testSByte, FREE_IMAGE_MDTYPE.FIDT_SBYTE)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((sbyte[])metaTag.Value).Length == 1); + Assert.That(metaTag.Count == 1); + Assert.That(metaTag.Length == 1); + Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SBYTE); + Assert.That(((sbyte[])metaTag.Value)[0] == testSByte); + + Assert.IsTrue(metaTag.SetValue(testSByteArray, FREE_IMAGE_MDTYPE.FIDT_SBYTE)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((sbyte[])metaTag.Value).Length == testSByteArray.Length); + Assert.That(metaTag.Count == testSByteArray.Length); + Assert.That(metaTag.Length == testSByteArray.Length * 1); + + sbyte[] value = (sbyte[])metaTag.Value; + + for (int j = 0; j < value.Length; j++) + Assert.That(testSByteArray[j] == value[j]); + } + + // + // FREE_IMAGE_MDTYPE.FIDT_SHORT + // + + ushort testUShort; + ushort[] testUShortArray; + + Assert.IsTrue(metaTag.SetValue(ushort.MinValue, FREE_IMAGE_MDTYPE.FIDT_SHORT)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((ushort[])metaTag.Value).Length == 1); + Assert.That(((ushort[])metaTag.Value)[0] == ushort.MinValue); + + Assert.IsTrue(metaTag.SetValue(ushort.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SHORT)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((ushort[])metaTag.Value).Length == 1); + Assert.That(((ushort[])metaTag.Value)[0] == ushort.MaxValue); + + for (int i = 0; i < 10; i++) + { + testUShort = (ushort)rand.Next(ushort.MinValue, sbyte.MaxValue); + testUShortArray = new ushort[rand.Next(0, 31)]; + + for (int j = 0; j < testUShortArray.Length; j++) + testUShortArray[j] = (ushort)rand.Next(); + + Assert.IsTrue(metaTag.SetValue(testUShort, FREE_IMAGE_MDTYPE.FIDT_SHORT)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((ushort[])metaTag.Value).Length == 1); + Assert.That(metaTag.Count == 1); + Assert.That(metaTag.Length == 2); + Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SHORT); + Assert.That(((ushort[])metaTag.Value)[0] == testUShort); + + Assert.IsTrue(metaTag.SetValue(testUShortArray, FREE_IMAGE_MDTYPE.FIDT_SHORT)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((ushort[])metaTag.Value).Length == testUShortArray.Length); + Assert.That(metaTag.Count == testUShortArray.Length); + Assert.That(metaTag.Length == testUShortArray.Length * 2); + + ushort[] value = (ushort[])metaTag.Value; + + for (int j = 0; j < value.Length; j++) + Assert.That(testUShortArray[j] == value[j]); + } + + // + // FREE_IMAGE_MDTYPE.FIDT_SLONG + // + + int testInt; + int[] testIntArray; + + Assert.IsTrue(metaTag.SetValue(int.MinValue, FREE_IMAGE_MDTYPE.FIDT_SLONG)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((int[])metaTag.Value).Length == 1); + Assert.That(((int[])metaTag.Value)[0] == int.MinValue); + + Assert.IsTrue(metaTag.SetValue(int.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SLONG)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((int[])metaTag.Value).Length == 1); + Assert.That(((int[])metaTag.Value)[0] == int.MaxValue); + + for (int i = 0; i < 10; i++) + { + testInt = (int)rand.NextDouble(); + testIntArray = new int[rand.Next(0, 31)]; + + for (int j = 0; j < testIntArray.Length; j++) + testIntArray[j] = rand.Next(); + + Assert.IsTrue(metaTag.SetValue(testInt, FREE_IMAGE_MDTYPE.FIDT_SLONG)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((int[])metaTag.Value).Length == 1); + Assert.That(metaTag.Count == 1); + Assert.That(metaTag.Length == 4); + Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SLONG); + Assert.That(((int[])metaTag.Value)[0] == testInt); + + Assert.IsTrue(metaTag.SetValue(testIntArray, FREE_IMAGE_MDTYPE.FIDT_SLONG)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((int[])metaTag.Value).Length == testIntArray.Length); + Assert.That(metaTag.Count == testIntArray.Length); + Assert.That(metaTag.Length == testIntArray.Length * 4); + + int[] value = (int[])metaTag.Value; + + for (int j = 0; j < value.Length; j++) + Assert.That(testIntArray[j] == value[j]); + } + + // + // FREE_IMAGE_MDTYPE.FIDT_SRATIONAL + // + + FIRational testFIRational; + FIRational[] testFIRationalArray; + + for (int i = 0; i < 10; i++) + { + testFIRational = new FIRational(rand.Next(), rand.Next()); + testFIRationalArray = new FIRational[rand.Next(0, 31)]; + + for (int j = 0; j < testFIRationalArray.Length; j++) + testFIRationalArray[j] = new FIRational(rand.Next(), rand.Next()); + + Assert.IsTrue(metaTag.SetValue(testFIRational, FREE_IMAGE_MDTYPE.FIDT_SRATIONAL)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((FIRational[])metaTag.Value).Length == 1); + Assert.That(metaTag.Count == 1); + Assert.That(metaTag.Length == 8); + Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SRATIONAL); + Assert.That(((FIRational[])metaTag.Value)[0] == testFIRational); + + Assert.IsTrue(metaTag.SetValue(testFIRationalArray, FREE_IMAGE_MDTYPE.FIDT_SRATIONAL)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((FIRational[])metaTag.Value).Length == testFIRationalArray.Length); + Assert.That(metaTag.Count == testFIRationalArray.Length); + Assert.That(metaTag.Length == testFIRationalArray.Length * 8); + + FIRational[] value = (FIRational[])metaTag.Value; + + for (int j = 0; j < value.Length; j++) + Assert.That(testFIRationalArray[j] == value[j]); + } + + // + // FREE_IMAGE_MDTYPE.FIDT_SSHORT + // + + short testShort; + short[] testShortArray; + + Assert.IsTrue(metaTag.SetValue(short.MinValue, FREE_IMAGE_MDTYPE.FIDT_SSHORT)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((short[])metaTag.Value).Length == 1); + Assert.That(((short[])metaTag.Value)[0] == short.MinValue); + + Assert.IsTrue(metaTag.SetValue(short.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SSHORT)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((short[])metaTag.Value).Length == 1); + Assert.That(((short[])metaTag.Value)[0] == short.MaxValue); + + for (int i = 0; i < 10; i++) + { + testShort = (short)rand.Next(short.MinValue, short.MaxValue); + testShortArray = new short[rand.Next(0, 31)]; + + for (int j = 0; j < testShortArray.Length; j++) + testShortArray[j] = (short)rand.Next(); + + Assert.IsTrue(metaTag.SetValue(testShort, FREE_IMAGE_MDTYPE.FIDT_SSHORT)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((short[])metaTag.Value).Length == 1); + Assert.That(metaTag.Count == 1); + Assert.That(metaTag.Length == 2); + Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SSHORT); + Assert.That(((short[])metaTag.Value)[0] == testShort); + + Assert.IsTrue(metaTag.SetValue(testShortArray, FREE_IMAGE_MDTYPE.FIDT_SSHORT)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((short[])metaTag.Value).Length == testShortArray.Length); + Assert.That(metaTag.Count == testShortArray.Length); + Assert.That(metaTag.Length == testShortArray.Length * 2); + + short[] value = (short[])metaTag.Value; + + for (int j = 0; j < value.Length; j++) + Assert.That(testShortArray[j] == value[j]); + } + + // + // FREE_IMAGE_MDTYPE.FIDT_UNDEFINED + // + + Assert.IsTrue(metaTag.SetValue(byte.MinValue, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((byte[])metaTag.Value).Length == 1); + Assert.That(((byte[])metaTag.Value)[0] == byte.MinValue); + + Assert.IsTrue(metaTag.SetValue(byte.MaxValue, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((byte[])metaTag.Value).Length == 1); + Assert.That(((byte[])metaTag.Value)[0] == byte.MaxValue); + + for (int i = 0; i < 10; i++) + { + testByte = (byte)rand.Next(byte.MinValue, byte.MaxValue); + testByteArray = new byte[rand.Next(0, 31)]; + + for (int j = 0; j < testByteArray.Length; j++) + testByteArray[j] = (byte)rand.Next(); + + Assert.IsTrue(metaTag.SetValue(testByte, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((byte[])metaTag.Value).Length == 1); + Assert.That(metaTag.Count == 1); + Assert.That(metaTag.Length == 1); + Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_UNDEFINED); + Assert.That(((byte[])metaTag.Value)[0] == testByte); + + Assert.IsTrue(metaTag.SetValue(testByteArray, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED)); + Assert.IsNotNull(metaTag.Value); + Assert.That(((byte[])metaTag.Value).Length == testByteArray.Length); + Assert.That(metaTag.Count == testByteArray.Length); + Assert.That(metaTag.Length == testByteArray.Length * 1); + + byte[] value = (byte[])metaTag.Value; + + for (int j = 0; j < value.Length; j++) + Assert.That(testByteArray[j] == value[j]); + } + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void MetadataModel() + { + MetadataTag tag; + dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + + MetadataModel model = new MDM_GEOTIFF(dib); + Assert.AreEqual(0, model.Count); + Assert.IsFalse(model.Exists); + Assert.IsEmpty(model.List); + Assert.AreEqual(model.Model, FREE_IMAGE_MDMODEL.FIMD_GEOTIFF); + Assert.IsTrue(model.DestoryModel()); + foreach (MetadataTag m in model) Assert.Fail(); + + tag = new MetadataTag(FREE_IMAGE_MDMODEL.FIMD_GEOTIFF); + tag.Key = "KEY"; + tag.Value = 54321f; + Assert.IsTrue(model.AddTag(tag)); + + Assert.AreEqual(1, model.Count); + Assert.IsTrue(model.Exists); + Assert.IsNotEmpty(model.List); + Assert.AreEqual(model.Model, FREE_IMAGE_MDMODEL.FIMD_GEOTIFF); + + Assert.IsTrue(model.DestoryModel()); + Assert.AreEqual(0, model.Count); + Assert.IsFalse(model.Exists); + Assert.IsEmpty(model.List); + Assert.AreEqual(model.Model, FREE_IMAGE_MDMODEL.FIMD_GEOTIFF); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void ImageMetadata() + { + ImageMetadata metadata; + List modelList; + MetadataTag tag = new MetadataTag(FREE_IMAGE_MDMODEL.FIMD_COMMENTS); + tag.Key = "KEY"; + tag.ID = 11; + tag.Value = new double[] { 0d, 41d, -523d, -0.41d }; + + dib = FreeImage.Allocate(1, 1, 1, 1, 0, 0); + Assert.IsFalse(dib.IsNull); + + metadata = new ImageMetadata(dib, true); + Assert.AreEqual(0, metadata.Count); + Assert.IsTrue(metadata.HideEmptyModels); + Assert.IsEmpty(metadata.List); + + metadata = new ImageMetadata(dib, false); + Assert.AreEqual(FreeImage.FREE_IMAGE_MDMODELS.Length, metadata.Count); + Assert.IsFalse(metadata.HideEmptyModels); + Assert.IsNotEmpty(metadata.List); + + metadata.HideEmptyModels = true; + metadata.AddTag(tag); + + Assert.AreEqual(1, metadata.Count); + Assert.IsNotEmpty(metadata.List); + + modelList = metadata.List; + Assert.AreEqual(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, modelList[0].Model); + + System.Collections.IEnumerator enumerator = metadata.GetEnumerator(); + Assert.IsTrue(enumerator.MoveNext()); + Assert.IsNotNull((MetadataModel)enumerator.Current); + Assert.IsFalse(enumerator.MoveNext()); + + FreeImage.UnloadEx(ref dib); + } + } + + [TestFixture] + public class WrapperFunctionsTest + { + ImageManager iManager = new ImageManager(); + FIBITMAP dib = new FIBITMAP(); + string freeImageCallback = null; + + [TestFixtureSetUp] + public void Init() + { + FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); + } + + [TestFixtureTearDown] + public void DeInit() + { + FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); + } + + [SetUp] + public void InitEachTime() + { + } + + [TearDown] + public void DeInitEachTime() + { + } + + void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) + { + freeImageCallback = message; + } + + public bool EqualColors(Color color1, Color color2) + { + if (color1.A != color2.A) return false; + if (color1.R != color2.R) return false; + if (color1.G != color2.G) return false; + if (color1.B != color2.B) return false; + return true; + } + + // + // Tests + // + + [Test] + public void FreeImage_GetWrapperVersion() + { + //Assert.That(FreeImage.GetWrapperVersion() == + // String.Format("{0}.{1}.{2}", + // FreeImage.FREEIMAGE_MAJOR_VERSION, + // FreeImage.FREEIMAGE_MINOR_VERSION, + // FreeImage.FREEIMAGE_RELEASE_SERIAL)); + } + + [Test] + public void FreeImage_IsAvailable() + { + Assert.IsTrue(FreeImage.IsAvailable()); + } + + [Test] + public void FreeImage_GetBitmap() + { + Bitmap bitmap = null; + + try + { + bitmap = FreeImage.GetBitmap(new FIBITMAP()); + } + catch + { + } + Assert.IsNull(bitmap); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + + bitmap = FreeImage.GetBitmap(dib); + Assert.IsNotNull(bitmap); + Assert.AreEqual((int)FreeImage.GetHeight(dib), bitmap.Height); + Assert.AreEqual((int)FreeImage.GetWidth(dib), bitmap.Width); + + bitmap.Dispose(); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_CreateFromBitmap() + { + Bitmap bitmap = (Bitmap)Bitmap.FromFile(iManager.GetBitmapPath(ImageType.Odd, ImageColorType.Type_24)); + Assert.IsNotNull(bitmap); + + dib = FreeImage.CreateFromBitmap(bitmap); + Assert.That(!dib.IsNull); + + Assert.AreEqual((int)FreeImage.GetHeight(dib), bitmap.Height); + Assert.AreEqual((int)FreeImage.GetWidth(dib), bitmap.Width); + + bitmap.Dispose(); + FreeImage.UnloadEx(ref dib); + + try + { + dib = FreeImage.CreateFromBitmap(null); + Assert.Fail(); + } + catch + { + } + } + + [Test] + public void FreeImage_SaveBitmap() + { + Bitmap bitmap = (Bitmap)Bitmap.FromFile(iManager.GetBitmapPath(ImageType.Odd, ImageColorType.Type_24)); + Assert.IsNotNull(bitmap); + + Assert.IsTrue(FreeImage.SaveBitmap(bitmap, @"test.png", FREE_IMAGE_FORMAT.FIF_PNG, FREE_IMAGE_SAVE_FLAGS.DEFAULT)); + bitmap.Dispose(); + + Assert.IsTrue(File.Exists(@"test.png")); + + dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PNG, @"test.png", FREE_IMAGE_LOAD_FLAGS.DEFAULT); + Assert.That(!dib.IsNull); + + FreeImage.UnloadEx(ref dib); + + File.Delete(@"test.png"); + Assert.IsFalse(File.Exists(@"test.png")); + bitmap.Dispose(); + } + + [Test] + public void FreeImage_LoadEx() + { + dib = FreeImage.LoadEx(iManager.GetBitmapPath(ImageType.Odd, ImageColorType.Type_16_555)); + Assert.That(!dib.IsNull); + FreeImage.UnloadEx(ref dib); + + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_TIFF; + + dib = FreeImage.LoadEx(iManager.GetBitmapPath(ImageType.Odd, ImageColorType.Type_16_565), ref format); + Assert.That(dib.IsNull); + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_TIFF, format); + FreeImage.UnloadEx(ref dib); + + format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + dib = FreeImage.LoadEx(iManager.GetBitmapPath(ImageType.JPEG, ImageColorType.Type_16_565), + FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); + Assert.That(!dib.IsNull); + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_JPEG, format); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_UnloadEx() + { + Assert.That(dib.IsNull); + FreeImage.UnloadEx(ref dib); + Assert.That(dib.IsNull); + + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_16_555); + Assert.That(!dib.IsNull); + + FreeImage.UnloadEx(ref dib); + Assert.That(dib.IsNull); + } + + [Test] + public void FreeImage_SaveEx() + { + FREE_IMAGE_FORMAT format; + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08); + Assert.That(!dib.IsNull); + + Assert.IsTrue(FreeImage.SaveEx(dib, @"test.png")); + Assert.IsTrue(File.Exists(@"test.png")); + format = FreeImage.GetFileType(@"test.png", 0); + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_PNG, format); + File.Delete(@"test.png"); + Assert.IsFalse(File.Exists(@"test.png")); + + Assert.IsTrue(FreeImage.SaveEx(ref dib, @"test.tiff", FREE_IMAGE_SAVE_FLAGS.DEFAULT, false)); + Assert.IsTrue(File.Exists(@"test.tiff")); + format = FreeImage.GetFileType(@"test.tiff", 0); + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_TIFF, format); + File.Delete(@"test.tiff"); + Assert.IsFalse(File.Exists(@"test.tiff")); + + Assert.IsTrue(FreeImage.SaveEx( + ref dib, + @"test.gif", + FREE_IMAGE_FORMAT.FIF_UNKNOWN, + FREE_IMAGE_SAVE_FLAGS.DEFAULT, + FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP, + false)); + + Assert.IsTrue(File.Exists(@"test.gif")); + format = FreeImage.GetFileType(@"test.gif", 0); + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_GIF, format); + File.Delete(@"test.gif"); + Assert.IsFalse(File.Exists(@"test.gif")); + + Assert.IsFalse(FreeImage.SaveEx(dib, @"")); + Assert.IsFalse(FreeImage.SaveEx(dib, @"test.test")); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_LoadFromStream() + { + FREE_IMAGE_FORMAT format; + FileStream fStream; + + fStream = new FileStream(iManager.GetBitmapPath(ImageType.Odd, ImageColorType.Type_16_565), FileMode.Open); + Assert.IsNotNull(fStream); + + dib = FreeImage.LoadFromStream(fStream); + Assert.That(!dib.IsNull); + Assert.That(FreeImage.GetBPP(dib) == 16); + Assert.That(FreeImage.GetGreenMask(dib) == FreeImage.FI16_565_GREEN_MASK); + + FreeImage.UnloadEx(ref dib); + fStream.Close(); + + fStream = new FileStream(iManager.GetBitmapPath(ImageType.Metadata, ImageColorType.Type_01_Dither), FileMode.Open); + Assert.IsNotNull(fStream); + + format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + dib = FreeImage.LoadFromStream(fStream, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); + Assert.That(!dib.IsNull); + Assert.That(FreeImage.GetBPP(dib) == 24); + Assert.That(format == FREE_IMAGE_FORMAT.FIF_JPEG); + FreeImage.UnloadEx(ref dib); + fStream.Close(); + + fStream = new FileStream(iManager.GetBitmapPath(ImageType.Even, ImageColorType.Type_32), FileMode.Open); + format = FREE_IMAGE_FORMAT.FIF_TIFF; + dib = FreeImage.LoadFromStream(fStream, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format); + Assert.That(!dib.IsNull); + Assert.That(FreeImage.GetBPP(dib) == 32); + Assert.That(format == FREE_IMAGE_FORMAT.FIF_TIFF); + + FreeImage.UnloadEx(ref dib); + + Assert.That(dib.IsNull); + dib = FreeImage.LoadFromStream(new MemoryStream(new byte[] { })); + Assert.That(dib.IsNull); + + format = FREE_IMAGE_FORMAT.FIF_BMP; + fStream.Position = 0; + dib = FreeImage.LoadFromStream(fStream, ref format); + Assert.That(dib.IsNull); + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_BMP, format); + + fStream.Close(); + } + + [Test] + public void FreeImage_SaveToStream() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_08_Greyscale_MinIsBlack); + Assert.That(!dib.IsNull); + + Stream stream = new FileStream(@"out_stream.bmp", FileMode.Create); + Assert.IsNotNull(stream); + + Assert.IsTrue(FreeImage.SaveEx(ref dib, @"out_file.bmp", FREE_IMAGE_FORMAT.FIF_BMP, false)); + Assert.IsTrue(FreeImage.SaveToStream(dib, stream, FREE_IMAGE_FORMAT.FIF_BMP)); + stream.Flush(); + stream.Dispose(); + + Assert.IsTrue(File.Exists(@"out_stream.bmp")); + Assert.IsTrue(File.Exists(@"out_file.bmp")); + byte[] buffer1 = File.ReadAllBytes(@"out_stream.bmp"); + byte[] buffer2 = File.ReadAllBytes(@"out_file.bmp"); + Assert.AreEqual(buffer1.Length, buffer2.Length); + for (int i = 0; i < buffer1.Length; i++) + if (buffer1[i] != buffer2[i]) + Assert.Fail(); + + File.Delete(@"out_stream.bmp"); + File.Delete(@"out_file.bmp"); + Assert.IsFalse(File.Exists(@"out_stream.bmp")); + Assert.IsFalse(File.Exists(@"out_file.bmp")); + + stream = new MemoryStream(); + Assert.IsFalse(FreeImage.SaveToStream(dib, stream, FREE_IMAGE_FORMAT.FIF_FAXG3)); + stream.Dispose(); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_IsExtensionValidForFIF() + { + Assert.IsTrue(FreeImage.IsExtensionValidForFIF(FREE_IMAGE_FORMAT.FIF_BMP, "bmp", StringComparison.CurrentCultureIgnoreCase)); + Assert.IsTrue(FreeImage.IsExtensionValidForFIF(FREE_IMAGE_FORMAT.FIF_BMP, "BMP", StringComparison.CurrentCultureIgnoreCase)); + Assert.IsFalse(FreeImage.IsExtensionValidForFIF(FREE_IMAGE_FORMAT.FIF_BMP, "DUMMY", StringComparison.CurrentCultureIgnoreCase)); + Assert.IsTrue(FreeImage.IsExtensionValidForFIF(FREE_IMAGE_FORMAT.FIF_PCX, "pcx", StringComparison.CurrentCultureIgnoreCase)); + Assert.IsTrue(FreeImage.IsExtensionValidForFIF(FREE_IMAGE_FORMAT.FIF_TIFF, "tif", StringComparison.CurrentCultureIgnoreCase)); + Assert.IsTrue(FreeImage.IsExtensionValidForFIF(FREE_IMAGE_FORMAT.FIF_TIFF, "TIFF", StringComparison.CurrentCultureIgnoreCase)); + Assert.IsFalse(FreeImage.IsExtensionValidForFIF(FREE_IMAGE_FORMAT.FIF_ICO, "ICO", StringComparison.CurrentCulture)); + } + + [Test] + public void FreeImage_IsFilenameValidForFIF() + { + Assert.IsTrue(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_JPEG, "file.jpg")); + Assert.IsTrue(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_JPEG, "file.jpeg")); + Assert.IsFalse(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_JPEG, "file.bmp")); + Assert.IsTrue(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_GIF, "file.gif")); + Assert.IsTrue(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_GIF, "file.GIF")); + Assert.IsTrue(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_GIF, "file.GIF", StringComparison.CurrentCultureIgnoreCase)); + Assert.IsFalse(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_GIF, "file.txt")); + Assert.IsFalse(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_UNKNOWN, "file.jpg")); + Assert.IsFalse(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_UNKNOWN, "file.bmp")); + Assert.IsFalse(FreeImage.IsFilenameValidForFIF(FREE_IMAGE_FORMAT.FIF_UNKNOWN, "file.tif")); + } + + [Test] + public void FreeImage_GetPrimaryExtensionFromFIF() + { + Assert.AreEqual("gif", FreeImage.GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT.FIF_GIF)); + Assert.AreEqual("tif", FreeImage.GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT.FIF_TIFF)); + Assert.AreNotEqual("tiff", FreeImage.GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT.FIF_TIFF)); + Assert.AreEqual("psd", FreeImage.GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT.FIF_PSD)); + Assert.AreEqual("iff", FreeImage.GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT.FIF_IFF)); + Assert.IsNull(FreeImage.GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT.FIF_UNKNOWN)); + } + + [Test] + public void FreeImage_OpenMultiBitmapEx() + { + FIMULTIBITMAP dib = FreeImage.OpenMultiBitmapEx(iManager.GetBitmapPath(ImageType.Multipaged, ImageColorType.Type_01_Dither)); + Assert.IsFalse(dib.IsNull); + Assert.AreEqual(4, FreeImage.GetPageCount(dib)); + FreeImage.CloseMultiBitmap(dib, FREE_IMAGE_SAVE_FLAGS.DEFAULT); + + FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN; + dib = FreeImage.OpenMultiBitmapEx( + iManager.GetBitmapPath(ImageType.Multipaged, ImageColorType.Type_04), ref format, FREE_IMAGE_LOAD_FLAGS.DEFAULT, + false, true, true); + Assert.IsFalse(dib.IsNull); + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_TIFF, format); + FreeImage.CloseMultiBitmap(dib, FREE_IMAGE_SAVE_FLAGS.DEFAULT); + } + + [Test] + public void FreeImage_GetLockedPageCount() + { + FIMULTIBITMAP dib = FreeImage.OpenMultiBitmapEx(iManager.GetBitmapPath(ImageType.Multipaged, ImageColorType.Type_01_Dither)); + FIBITMAP page1, page2, page3; + Assert.IsFalse(dib.IsNull); + Assert.AreEqual(4, FreeImage.GetPageCount(dib)); + Assert.AreEqual(0, FreeImage.GetLockedPageCount(dib)); + + page1 = FreeImage.LockPage(dib, 0); + Assert.AreEqual(1, FreeImage.GetLockedPageCount(dib)); + + page2 = FreeImage.LockPage(dib, 1); + Assert.AreEqual(2, FreeImage.GetLockedPageCount(dib)); + + page3 = FreeImage.LockPage(dib, 2); + Assert.AreEqual(3, FreeImage.GetLockedPageCount(dib)); + + FreeImage.UnlockPage(dib, page3, true); + Assert.AreEqual(2, FreeImage.GetLockedPageCount(dib)); + + FreeImage.UnlockPage(dib, page2, true); + Assert.AreEqual(1, FreeImage.GetLockedPageCount(dib)); + + FreeImage.UnlockPage(dib, page1, true); + Assert.AreEqual(0, FreeImage.GetLockedPageCount(dib)); + + FreeImage.CloseMultiBitmapEx(ref dib); + } + + [Test] + public void FreeImage_GetLockedPages() + { + FIMULTIBITMAP dib = FreeImage.OpenMultiBitmapEx(iManager.GetBitmapPath(ImageType.Multipaged, ImageColorType.Type_01_Dither)); + FIBITMAP page1, page2, page3; + int[] lockedList; + Assert.IsFalse(dib.IsNull); + Assert.AreEqual(4, FreeImage.GetPageCount(dib)); + Assert.AreEqual(0, FreeImage.GetLockedPageCount(dib)); + + page1 = FreeImage.LockPage(dib, 0); + Assert.AreEqual(1, FreeImage.GetLockedPageCount(dib)); + lockedList = FreeImage.GetLockedPages(dib); + Assert.Contains(0, lockedList); + + page2 = FreeImage.LockPage(dib, 1); + Assert.AreEqual(2, FreeImage.GetLockedPageCount(dib)); + lockedList = FreeImage.GetLockedPages(dib); + Assert.Contains(0, lockedList); + Assert.Contains(1, lockedList); + + page3 = FreeImage.LockPage(dib, 3); + Assert.AreEqual(3, FreeImage.GetLockedPageCount(dib)); + lockedList = FreeImage.GetLockedPages(dib); + Assert.Contains(0, lockedList); + Assert.Contains(1, lockedList); + Assert.Contains(3, lockedList); + + FreeImage.UnlockPage(dib, page2, true); + Assert.AreEqual(2, FreeImage.GetLockedPageCount(dib)); + lockedList = FreeImage.GetLockedPages(dib); + Assert.Contains(0, lockedList); + Assert.Contains(3, lockedList); + + FreeImage.UnlockPage(dib, page1, true); + Assert.AreEqual(1, FreeImage.GetLockedPageCount(dib)); + lockedList = FreeImage.GetLockedPages(dib); + Assert.Contains(3, lockedList); + + FreeImage.UnlockPage(dib, page3, true); + Assert.AreEqual(0, FreeImage.GetLockedPageCount(dib)); + lockedList = FreeImage.GetLockedPages(dib); + Assert.AreEqual(0, lockedList.Length); + + FreeImage.CloseMultiBitmapEx(ref dib); + } + + [Test] + public void FreeImage_GetFileTypeFromStream() + { + FileStream fStream = new FileStream(iManager.GetBitmapPath(ImageType.JPEG, ImageColorType.Type_01_Dither), FileMode.Open); + Assert.IsNotNull(fStream); + + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_JPEG, FreeImage.GetFileTypeFromStream(fStream)); + fStream.Dispose(); + + fStream = new FileStream(iManager.GetBitmapPath(ImageType.Odd, ImageColorType.Type_16_565), FileMode.Open); + Assert.AreEqual(FREE_IMAGE_FORMAT.FIF_BMP, FreeImage.GetFileTypeFromStream(fStream)); + fStream.Close(); + } + + [Test] + public void FreeImage_GetHbitmap() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); + Assert.IsFalse(dib.IsNull); + + IntPtr hBitmap = FreeImage.GetHbitmap(dib, IntPtr.Zero, false); + Bitmap bitmap = Bitmap.FromHbitmap(hBitmap); + Assert.IsNotNull(bitmap); + Assert.AreEqual(FreeImage.GetWidth(dib), bitmap.Width); + Assert.AreEqual(FreeImage.GetHeight(dib), bitmap.Height); + + bitmap.Dispose(); + FreeImage.FreeHbitmap(hBitmap); + FreeImage.UnloadEx(ref dib); + + try + { + hBitmap = FreeImage.GetHbitmap(dib, IntPtr.Zero, false); + Assert.Fail(); + } + catch + { + } + } + + [Test] + public void FreeImage_GetResolutionX() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); + Assert.IsFalse(dib.IsNull); + + Assert.AreEqual(72, FreeImage.GetResolutionX(dib)); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetResolutionY() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); + Assert.IsFalse(dib.IsNull); + + Assert.AreEqual(72, FreeImage.GetResolutionY(dib)); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetResolutionX() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); + Assert.IsFalse(dib.IsNull); + + Assert.AreEqual(72, FreeImage.GetResolutionX(dib)); + + FreeImage.SetResolutionX(dib, 12u); + Assert.AreEqual(12, FreeImage.GetResolutionX(dib)); + + FreeImage.SetResolutionX(dib, 1u); + Assert.AreEqual(1, FreeImage.GetResolutionX(dib)); + + FreeImage.SetResolutionX(dib, 66u); + Assert.AreEqual(66, FreeImage.GetResolutionX(dib)); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetResolutionY() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_24); + Assert.IsFalse(dib.IsNull); + + Assert.AreEqual(72, FreeImage.GetResolutionY(dib)); + + FreeImage.SetResolutionY(dib, 12u); + Assert.AreEqual(12, FreeImage.GetResolutionY(dib)); + + FreeImage.SetResolutionY(dib, 1u); + Assert.AreEqual(1, FreeImage.GetResolutionY(dib)); + + FreeImage.SetResolutionY(dib, 66u); + Assert.AreEqual(66, FreeImage.GetResolutionY(dib)); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_IsGreyscaleImage() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.IsFalse(FreeImage.IsGreyscaleImage(dib)); + FreeImage.UnloadEx(ref dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04_Greyscale_Unordered); + Assert.IsTrue(FreeImage.IsGreyscaleImage(dib)); + FreeImage.UnloadEx(ref dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04_Greyscale_MinIsBlack); + Assert.IsTrue(FreeImage.IsGreyscaleImage(dib)); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetPaletteEx() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Palette palette = null; + + try + { + palette = FreeImage.GetPaletteEx(dib); + Assert.Fail(); + } + catch + { + } + FreeImage.UnloadEx(ref dib); + + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_08_Greyscale_MinIsBlack); + try + { + palette = FreeImage.GetPaletteEx(dib); + } + catch + { + Assert.Fail(); + } + Assert.AreEqual(256, palette.Length); + for (int index = 0; index < 256; index++) + { + Assert.AreEqual(index, palette[index].rgbRed); + Assert.AreEqual(index, palette[index].rgbGreen); + Assert.AreEqual(index, palette[index].rgbBlue); + } + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetInfoHeaderEx() + { + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04); + Assert.IsFalse(dib.IsNull); + + BITMAPINFOHEADER iHeader = FreeImage.GetInfoHeaderEx(dib); + Assert.AreEqual(4, iHeader.biBitCount); + Assert.AreEqual(FreeImage.GetWidth(dib), iHeader.biWidth); + Assert.AreEqual(FreeImage.GetHeight(dib), iHeader.biHeight); + FreeImage.UnloadEx(ref dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_01_Dither); + Assert.IsFalse(dib.IsNull); + + iHeader = FreeImage.GetInfoHeaderEx(dib); + Assert.AreEqual(1, iHeader.biBitCount); + Assert.AreEqual(FreeImage.GetWidth(dib), iHeader.biWidth); + Assert.AreEqual(FreeImage.GetHeight(dib), iHeader.biHeight); + FreeImage.UnloadEx(ref dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.IsFalse(dib.IsNull); + + iHeader = FreeImage.GetInfoHeaderEx(dib); + Assert.AreEqual(24, iHeader.biBitCount); + Assert.AreEqual(FreeImage.GetWidth(dib), iHeader.biWidth); + Assert.AreEqual(FreeImage.GetHeight(dib), iHeader.biHeight); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetInfoEx() + { + BITMAPINFO info; + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_01_Dither); + Assert.That(!dib.IsNull); + info = FreeImage.GetInfoEx(dib); + Assert.AreEqual(FreeImage.GetBPP(dib), info.bmiHeader.biBitCount); + Assert.AreEqual(FreeImage.GetWidth(dib), info.bmiHeader.biWidth); + Assert.AreEqual(FreeImage.GetHeight(dib), info.bmiHeader.biHeight); + FreeImage.UnloadEx(ref dib); + + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_04_Greyscale_MinIsBlack); + Assert.That(!dib.IsNull); + info = FreeImage.GetInfoEx(dib); + Assert.AreEqual(FreeImage.GetBPP(dib), info.bmiHeader.biBitCount); + Assert.AreEqual(FreeImage.GetWidth(dib), info.bmiHeader.biWidth); + Assert.AreEqual(FreeImage.GetHeight(dib), info.bmiHeader.biHeight); + FreeImage.UnloadEx(ref dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_08_Greyscale_Unordered); + Assert.That(!dib.IsNull); + info = FreeImage.GetInfoEx(dib); + Assert.AreEqual(FreeImage.GetBPP(dib), info.bmiHeader.biBitCount); + Assert.AreEqual(FreeImage.GetWidth(dib), info.bmiHeader.biWidth); + Assert.AreEqual(FreeImage.GetHeight(dib), info.bmiHeader.biHeight); + FreeImage.UnloadEx(ref dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_16_555); + Assert.That(!dib.IsNull); + info = FreeImage.GetInfoEx(dib); + Assert.AreEqual(FreeImage.GetBPP(dib), info.bmiHeader.biBitCount); + Assert.AreEqual(FreeImage.GetWidth(dib), info.bmiHeader.biWidth); + Assert.AreEqual(FreeImage.GetHeight(dib), info.bmiHeader.biHeight); + FreeImage.UnloadEx(ref dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_16_565); + Assert.That(!dib.IsNull); + info = FreeImage.GetInfoEx(dib); + Assert.AreEqual(FreeImage.GetBPP(dib), info.bmiHeader.biBitCount); + Assert.AreEqual(FreeImage.GetWidth(dib), info.bmiHeader.biWidth); + Assert.AreEqual(FreeImage.GetHeight(dib), info.bmiHeader.biHeight); + FreeImage.UnloadEx(ref dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_24); + Assert.That(!dib.IsNull); + info = FreeImage.GetInfoEx(dib); + Assert.AreEqual(FreeImage.GetBPP(dib), info.bmiHeader.biBitCount); + Assert.AreEqual(FreeImage.GetWidth(dib), info.bmiHeader.biWidth); + Assert.AreEqual(FreeImage.GetHeight(dib), info.bmiHeader.biHeight); + FreeImage.UnloadEx(ref dib); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.That(!dib.IsNull); + info = FreeImage.GetInfoEx(dib); + Assert.AreEqual(FreeImage.GetBPP(dib), info.bmiHeader.biBitCount); + Assert.AreEqual(FreeImage.GetWidth(dib), info.bmiHeader.biWidth); + Assert.AreEqual(FreeImage.GetHeight(dib), info.bmiHeader.biHeight); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetPixelFormat() + { + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_01_Threshold); + Assert.IsFalse(dib.IsNull); + + Assert.AreEqual(PixelFormat.Format1bppIndexed, FreeImage.GetPixelFormat(dib)); + FreeImage.UnloadEx(ref dib); + + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_04_Greyscale_Unordered); + Assert.IsFalse(dib.IsNull); + + Assert.AreEqual(PixelFormat.Format4bppIndexed, FreeImage.GetPixelFormat(dib)); + FreeImage.UnloadEx(ref dib); + + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_16_555); + Assert.IsFalse(dib.IsNull); + + Assert.AreEqual(PixelFormat.Format16bppRgb555, FreeImage.GetPixelFormat(dib)); + FreeImage.UnloadEx(ref dib); + + dib = iManager.GetBitmap(ImageType.Odd, ImageColorType.Type_16_565); + Assert.IsFalse(dib.IsNull); + + Assert.AreEqual(PixelFormat.Format16bppRgb565, FreeImage.GetPixelFormat(dib)); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetFormatParameters() + { + uint bpp, red, green, blue; + FREE_IMAGE_TYPE type; + + Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format16bppArgb1555, out type, out bpp, out red, out green, out blue)); + Assert.AreEqual(16, bpp); + Assert.AreEqual(red, FreeImage.FI16_555_RED_MASK); + Assert.AreEqual(green, FreeImage.FI16_555_GREEN_MASK); + Assert.AreEqual(blue, FreeImage.FI16_555_BLUE_MASK); + Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); + + Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format16bppGrayScale, out type, out bpp, out red, out green, out blue)); + Assert.AreEqual(16, bpp); + Assert.AreEqual(red, 0); + Assert.AreEqual(green, 0); + Assert.AreEqual(blue, 0); + Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_UINT16); + + Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format16bppRgb555, out type, out bpp, out red, out green, out blue)); + Assert.AreEqual(16, bpp); + Assert.AreEqual(red, FreeImage.FI16_555_RED_MASK); + Assert.AreEqual(green, FreeImage.FI16_555_GREEN_MASK); + Assert.AreEqual(blue, FreeImage.FI16_555_BLUE_MASK); + Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); + + Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format16bppRgb565, out type, out bpp, out red, out green, out blue)); + Assert.AreEqual(16, bpp); + Assert.AreEqual(red, FreeImage.FI16_565_RED_MASK); + Assert.AreEqual(green, FreeImage.FI16_565_GREEN_MASK); + Assert.AreEqual(blue, FreeImage.FI16_565_BLUE_MASK); + Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); + + Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format1bppIndexed, out type, out bpp, out red, out green, out blue)); + Assert.AreEqual(1, bpp); + Assert.AreEqual(red, 0); + Assert.AreEqual(green, 0); + Assert.AreEqual(blue, 0); + Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); + + Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format24bppRgb, out type, out bpp, out red, out green, out blue)); + Assert.AreEqual(24, bpp); + Assert.AreEqual(red, FreeImage.FI_RGBA_RED_MASK); + Assert.AreEqual(green, FreeImage.FI_RGBA_GREEN_MASK); + Assert.AreEqual(blue, FreeImage.FI_RGBA_BLUE_MASK); + Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); + + Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format32bppArgb, out type, out bpp, out red, out green, out blue)); + Assert.AreEqual(32, bpp); + Assert.AreEqual(red, FreeImage.FI_RGBA_RED_MASK); + Assert.AreEqual(green, FreeImage.FI_RGBA_GREEN_MASK); + Assert.AreEqual(blue, FreeImage.FI_RGBA_BLUE_MASK); + Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); + + Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format32bppPArgb, out type, out bpp, out red, out green, out blue)); + Assert.AreEqual(32, bpp); + Assert.AreEqual(red, FreeImage.FI_RGBA_RED_MASK); + Assert.AreEqual(green, FreeImage.FI_RGBA_GREEN_MASK); + Assert.AreEqual(blue, FreeImage.FI_RGBA_BLUE_MASK); + Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); + + Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format32bppRgb, out type, out bpp, out red, out green, out blue)); + Assert.AreEqual(32, bpp); + Assert.AreEqual(red, FreeImage.FI_RGBA_RED_MASK); + Assert.AreEqual(green, FreeImage.FI_RGBA_GREEN_MASK); + Assert.AreEqual(blue, FreeImage.FI_RGBA_BLUE_MASK); + Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); + + Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format48bppRgb, out type, out bpp, out red, out green, out blue)); + Assert.AreEqual(48, bpp); + Assert.AreEqual(red, 0); + Assert.AreEqual(green, 0); + Assert.AreEqual(blue, 0); + Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_RGB16); + + Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format4bppIndexed, out type, out bpp, out red, out green, out blue)); + Assert.AreEqual(4, bpp); + Assert.AreEqual(red, 0); + Assert.AreEqual(green, 0); + Assert.AreEqual(blue, 0); + Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); + + Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format64bppArgb, out type, out bpp, out red, out green, out blue)); + Assert.AreEqual(64, bpp); + Assert.AreEqual(red, 0); + Assert.AreEqual(green, 0); + Assert.AreEqual(blue, 0); + Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_RGBA16); + + Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format64bppPArgb, out type, out bpp, out red, out green, out blue)); + Assert.AreEqual(64, bpp); + Assert.AreEqual(red, 0); + Assert.AreEqual(green, 0); + Assert.AreEqual(blue, 0); + Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_RGBA16); + + Assert.IsTrue(FreeImage.GetFormatParameters(PixelFormat.Format8bppIndexed, out type, out bpp, out red, out green, out blue)); + Assert.AreEqual(8, bpp); + Assert.AreEqual(red, 0); + Assert.AreEqual(green, 0); + Assert.AreEqual(blue, 0); + Assert.AreEqual(type, FREE_IMAGE_TYPE.FIT_BITMAP); + } + + [Test] + public void FreeImage_Compare() + { + FIBITMAP dib2; + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_01_Dither); + Assert.IsFalse(dib.IsNull); + dib2 = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_01_Threshold); + Assert.IsFalse(dib2.IsNull); + + Assert.IsFalse(FreeImage.Compare(dib, dib2, FREE_IMAGE_COMPARE_FLAGS.COMPLETE)); + Assert.IsTrue(FreeImage.Compare(dib, dib2, FREE_IMAGE_COMPARE_FLAGS.HEADER)); + + FreeImage.UnloadEx(ref dib); + FreeImage.UnloadEx(ref dib2); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04_Greyscale_MinIsBlack); + dib2 = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_04_Greyscale_Unordered); + + Assert.IsFalse(FreeImage.Compare(dib, dib2, FREE_IMAGE_COMPARE_FLAGS.COMPLETE)); + + FreeImage.UnloadEx(ref dib); + FreeImage.UnloadEx(ref dib2); + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + dib2 = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_32); + Assert.IsTrue(FreeImage.Compare(dib, dib2, FREE_IMAGE_COMPARE_FLAGS.COMPLETE)); + + FreeImage.UnloadEx(ref dib); + FreeImage.UnloadEx(ref dib2); + + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.IsFalse(dib.IsNull); + dib2 = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.IsFalse(dib2.IsNull); + + Assert.IsTrue(FreeImage.Compare(dib, dib2, FREE_IMAGE_COMPARE_FLAGS.COMPLETE)); + + FreeImage.UnloadEx(ref dib); + FreeImage.UnloadEx(ref dib2); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_16_555); + Assert.IsFalse(dib.IsNull); + dib2 = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_16_555); + Assert.IsFalse(dib2.IsNull); + + Assert.IsTrue(FreeImage.Compare(dib, dib2, FREE_IMAGE_COMPARE_FLAGS.COMPLETE)); + + FreeImage.UnloadEx(ref dib); + FreeImage.UnloadEx(ref dib2); + + dib = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_16_565); + Assert.IsFalse(dib.IsNull); + dib2 = iManager.GetBitmap(ImageType.Even, ImageColorType.Type_16_565); + Assert.IsFalse(dib2.IsNull); + + Assert.IsTrue(FreeImage.Compare(dib, dib2, FREE_IMAGE_COMPARE_FLAGS.COMPLETE)); + + FreeImage.UnloadEx(ref dib); + FreeImage.UnloadEx(ref dib2); + } + + [Test] + public void FreeImage_CreateICCProfileEx() + { + FIICCPROFILE prof; + byte[] data = new byte[173]; + Random rand = new Random(DateTime.Now.Millisecond); + dib = FreeImage.AllocateT(FREE_IMAGE_TYPE.FIT_BITMAP, 1, 1, 1, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + + prof = FreeImage.GetICCProfileEx(dib); + Assert.That(prof.DataPointer == IntPtr.Zero); + + rand.NextBytes(data); + prof = FreeImage.CreateICCProfileEx(dib, data); + Assert.That(prof.Size == data.Length); + for (int i = 0; i < data.Length; i++) + if (prof.Data[i] != data[i]) + Assert.Fail(); + + FreeImage.DestroyICCProfile(dib); + prof = FreeImage.GetICCProfileEx(dib); + Assert.That(prof.DataPointer == IntPtr.Zero); + + FreeImage.CreateICCProfileEx(dib, new byte[0], 0); + prof = FreeImage.GetICCProfileEx(dib); + Assert.That(prof.DataPointer == IntPtr.Zero); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_ConvertColorDepth() + { + int bpp = 1; + FIBITMAP dib2; + + dib = FreeImage.AllocateT(FREE_IMAGE_TYPE.FIT_BITMAP, 80, 80, 1, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + + do + { + dib2 = FreeImage.ConvertColorDepth(dib, (FREE_IMAGE_COLOR_DEPTH)bpp); + Assert.IsFalse(dib2.IsNull); + Assert.AreEqual(bpp, FreeImage.GetBPP(dib2)); + if (dib != dib2) + FreeImage.UnloadEx(ref dib2); + } while (0 != (bpp = FreeImage.GetNextColorDepth(bpp))); + + FreeImage.UnloadEx(ref dib); + + dib = FreeImage.AllocateT(FREE_IMAGE_TYPE.FIT_BITMAP, 80, 80, 32, + FreeImage.FI_RGBA_RED_MASK, FreeImage.FI_RGBA_GREEN_MASK, FreeImage.FI_RGBA_BLUE_MASK); + Assert.IsFalse(dib.IsNull); + bpp = 32; + + do + { + dib2 = FreeImage.ConvertColorDepth(dib, (FREE_IMAGE_COLOR_DEPTH)bpp); + Assert.IsFalse(dib2.IsNull); + Assert.AreEqual(bpp, FreeImage.GetBPP(dib2)); + if (dib != dib2) + FreeImage.UnloadEx(ref dib2); + } while (0 != (bpp = FreeImage.GetPrevousColorDepth(bpp))); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetNextColorDepth() + { + Assert.AreEqual(0, FreeImage.GetNextColorDepth(5)); + Assert.AreEqual(0, FreeImage.GetNextColorDepth(0)); + Assert.AreEqual(4, FreeImage.GetNextColorDepth(1)); + Assert.AreEqual(8, FreeImage.GetNextColorDepth(4)); + Assert.AreEqual(16, FreeImage.GetNextColorDepth(8)); + Assert.AreEqual(24, FreeImage.GetNextColorDepth(16)); + Assert.AreEqual(32, FreeImage.GetNextColorDepth(24)); + Assert.AreEqual(0, FreeImage.GetNextColorDepth(32)); + } + + [Test] + public void FreeImage_GetPrevousColorDepth() + { + Assert.AreEqual(0, FreeImage.GetNextColorDepth(5)); + Assert.AreEqual(0, FreeImage.GetNextColorDepth(0)); + Assert.AreEqual(4, FreeImage.GetNextColorDepth(1)); + Assert.AreEqual(8, FreeImage.GetNextColorDepth(4)); + Assert.AreEqual(16, FreeImage.GetNextColorDepth(8)); + Assert.AreEqual(24, FreeImage.GetNextColorDepth(16)); + Assert.AreEqual(32, FreeImage.GetNextColorDepth(24)); + Assert.AreEqual(0, FreeImage.GetNextColorDepth(32)); + } + + [Test] + public unsafe void FreeImage_PtrToStr() + { + string testString; + string resString; + IntPtr buffer; + int index; + + testString = "Test string"; + buffer = Marshal.AllocHGlobal(testString.Length + 1); + + for (index = 0; index < testString.Length; index++) + { + Marshal.WriteByte(buffer, index, (byte)testString[index]); + } + Marshal.WriteByte(buffer, index, (byte)0); + + resString = FreeImage.PtrToStr((byte*)buffer); + Assert.That(resString == testString); + + Marshal.FreeHGlobal(buffer); + + testString = @"äöü?=§%/!)§(%&)(§"; + buffer = Marshal.AllocHGlobal(testString.Length + 1); + + for (index = 0; index < testString.Length; index++) + { + Marshal.WriteByte(buffer, index, (byte)testString[index]); + } + Marshal.WriteByte(buffer, index, (byte)0); + + resString = FreeImage.PtrToStr((byte*)buffer); + Assert.That(resString == testString); + + Marshal.FreeHGlobal(buffer); + } + + [Test] + public void FreeImage_CopyMetadata() + { + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.IsFalse(dib.IsNull); + int mdCount = 0; + + FIBITMAP dib2 = FreeImage.Allocate(1, 1, 1, 0, 0, 0); + Assert.IsFalse(dib2.IsNull); + + FREE_IMAGE_MDMODEL[] modelList = (FREE_IMAGE_MDMODEL[])Enum.GetValues(typeof(FREE_IMAGE_MDMODEL)); + FITAG tag, tag2; + FIMETADATA mdHandle; + + foreach (FREE_IMAGE_MDMODEL model in modelList) + { + mdHandle = FreeImage.FindFirstMetadata(model, dib2, out tag); + Assert.IsTrue(mdHandle.IsNull); + mdCount += (int)FreeImage.GetMetadataCount(model, dib); + } + + Assert.AreEqual(mdCount, FreeImage.CloneMetadataEx(dib, dib2, FREE_IMAGE_METADATA_COPY.CLEAR_EXISTING)); + + foreach (FREE_IMAGE_MDMODEL model in modelList) + { + mdHandle = FreeImage.FindFirstMetadata(model, dib, out tag); + if (!mdHandle.IsNull) + { + do + { + Assert.IsTrue(FreeImage.GetMetadata(model, dib2, FreeImage.GetTagKey(tag), out tag2)); + Assert.That(FreeImage.GetTagCount(tag) == FreeImage.GetTagCount(tag2)); + Assert.That(FreeImage.GetTagDescription(tag) == FreeImage.GetTagDescription(tag2)); + Assert.That(FreeImage.GetTagID(tag) == FreeImage.GetTagID(tag2)); + Assert.That(FreeImage.GetTagKey(tag) == FreeImage.GetTagKey(tag2)); + Assert.That(FreeImage.GetTagLength(tag) == FreeImage.GetTagLength(tag2)); + Assert.That(FreeImage.GetTagType(tag) == FreeImage.GetTagType(tag2)); + } + while (FreeImage.FindNextMetadata(mdHandle, out tag)); + FreeImage.FindCloseMetadata(mdHandle); + } + } + + Assert.AreEqual(0, FreeImage.CloneMetadataEx(dib, dib2, FREE_IMAGE_METADATA_COPY.KEEP_EXISITNG)); + + foreach (FREE_IMAGE_MDMODEL model in modelList) + { + mdHandle = FreeImage.FindFirstMetadata(model, dib, out tag); + if (!mdHandle.IsNull) + { + do + { + Assert.IsTrue(FreeImage.GetMetadata(model, dib2, FreeImage.GetTagKey(tag), out tag2)); + Assert.AreEqual(FreeImage.GetTagCount(tag), FreeImage.GetTagCount(tag2)); + Assert.AreEqual(FreeImage.GetTagDescription(tag), FreeImage.GetTagDescription(tag2)); + Assert.AreEqual(FreeImage.GetTagID(tag), FreeImage.GetTagID(tag2)); + Assert.AreEqual(FreeImage.GetTagKey(tag), FreeImage.GetTagKey(tag2)); + Assert.AreEqual(FreeImage.GetTagLength(tag), FreeImage.GetTagLength(tag2)); + Assert.AreEqual(FreeImage.GetTagType(tag), FreeImage.GetTagType(tag2)); + } + while (FreeImage.FindNextMetadata(mdHandle, out tag)); + FreeImage.FindCloseMetadata(mdHandle); + } + } + + const string newTagDescription = "NEW_TAG_DESCRIPTION"; + + Assert.IsTrue(FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib, "Copyright", out tag)); + Assert.IsTrue(FreeImage.SetTagDescription(tag, newTagDescription)); + Assert.AreEqual(mdCount, FreeImage.CloneMetadataEx(dib, dib2, FREE_IMAGE_METADATA_COPY.REPLACE_EXISTING)); + Assert.IsTrue(FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib2, "Copyright", out tag2)); + Assert.AreEqual(newTagDescription, FreeImage.GetTagDescription(tag2)); + + FreeImage.UnloadEx(ref dib2); + FreeImage.UnloadEx(ref dib); + + dib2 = FreeImage.Allocate(1, 1, 1, 0, 0, 0); + dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); + + Assert.AreEqual(0, FreeImage.CloneMetadataEx(dib, dib2, FREE_IMAGE_METADATA_COPY.CLEAR_EXISTING)); + + FreeImage.UnloadEx(ref dib2); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetImageComment() + { + dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + const string comment = "C O M M E N T"; + + Assert.IsNull(FreeImage.GetImageComment(dib)); + Assert.IsTrue(FreeImage.SetImageComment(dib, comment)); + Assert.AreEqual(comment, FreeImage.GetImageComment(dib)); + Assert.IsTrue(FreeImage.SetImageComment(dib, null)); + Assert.IsNull(FreeImage.GetImageComment(dib)); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetImageComment() + { + dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + const string comment = "C O M M E N T"; + + Assert.IsNull(FreeImage.GetImageComment(dib)); + Assert.IsTrue(FreeImage.SetImageComment(dib, comment)); + Assert.AreEqual(comment, FreeImage.GetImageComment(dib)); + Assert.IsTrue(FreeImage.SetImageComment(dib, null)); + Assert.IsNull(FreeImage.GetImageComment(dib)); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetMetadata() + { + MetadataTag tag; + + dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither); + Assert.IsFalse(dib.IsNull); + + Assert.IsFalse(FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib, "~~~~~", out tag)); + Assert.IsNull(tag); + + Assert.IsTrue(FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib, "Artist", out tag)); + Assert.IsFalse(tag.tag.IsNull); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetMetadata() + { + MetadataTag tag; + Random rand = new Random(); + + dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + + ushort value = (ushort)rand.Next(); + + tag = new MetadataTag(FREE_IMAGE_MDMODEL.FIMD_CUSTOM); + tag.ID = value; + + Assert.IsTrue(FreeImage.SetMetadata(FREE_IMAGE_MDMODEL.FIMD_CUSTOM, dib, "~~~~~", tag)); + Assert.IsTrue(FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_CUSTOM, dib, "~~~~~", out tag)); + Assert.AreEqual(value, tag.ID); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_FindFirstMetadata() + { + MetadataTag tag; + FIMETADATA mdHandle; + dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + + FREE_IMAGE_MDMODEL[] models = (FREE_IMAGE_MDMODEL[])Enum.GetValues(typeof(FREE_IMAGE_MDMODEL)); + foreach (FREE_IMAGE_MDMODEL model in models) + { + mdHandle = FreeImage.FindFirstMetadata(model, dib, out tag); + Assert.IsTrue(mdHandle.IsNull); + } + + tag = new MetadataTag(FREE_IMAGE_MDMODEL.FIMD_COMMENTS); + tag.Key = "KEY"; + tag.Value = 12345; + tag.AddToImage(dib); + + mdHandle = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, out tag); + Assert.IsFalse(mdHandle.IsNull); + + FreeImage.FindCloseMetadata(mdHandle); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_FindNextMetadata() + { + MetadataTag tag; + FIMETADATA mdHandle; + dib = FreeImage.Allocate(1, 1, 1, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + + FREE_IMAGE_MDMODEL[] models = (FREE_IMAGE_MDMODEL[])Enum.GetValues(typeof(FREE_IMAGE_MDMODEL)); + foreach (FREE_IMAGE_MDMODEL model in models) + { + mdHandle = FreeImage.FindFirstMetadata(model, dib, out tag); + Assert.IsTrue(mdHandle.IsNull); + } + + tag = new MetadataTag(FREE_IMAGE_MDMODEL.FIMD_COMMENTS); + tag.Key = "KEY1"; + tag.Value = 12345; + tag.AddToImage(dib); + + tag = new MetadataTag(FREE_IMAGE_MDMODEL.FIMD_COMMENTS); + tag.Key = "KEY2"; + tag.Value = 54321; + tag.AddToImage(dib); + + mdHandle = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, out tag); + Assert.IsFalse(mdHandle.IsNull); + + Assert.IsTrue(FreeImage.FindNextMetadata(mdHandle, out tag)); + Assert.IsFalse(FreeImage.FindNextMetadata(mdHandle, out tag)); + + FreeImage.FindCloseMetadata(mdHandle); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_SetGetTransparencyTableEx() + { + dib = FreeImage.Allocate(10, 10, 6, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + + byte[] transTable = FreeImage.GetTransparencyTableEx(dib); + Assert.That(transTable.Length == 0); + + Random rand = new Random(); + transTable = new byte[rand.Next(0, 255)]; + int length = transTable.Length; + + for (int i = 0; i < transTable.Length; i++) + transTable[i] = (byte)i; + + FreeImage.SetTransparencyTable(dib, transTable); + transTable = null; + transTable = FreeImage.GetTransparencyTableEx(dib); + Assert.That(transTable.Length == length); + for (int i = 0; i < transTable.Length; i++) + Assert.That(transTable[i] == i); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_GetUniqueColors() + { + Palette palette; + + // + // 1bpp + // + + dib = FreeImage.Allocate(10, 1, 1, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + + palette = new Palette(dib); + palette[0] = Color.FromArgb(43, 255, 255, 255); + palette[1] = Color.FromArgb(222, 0, 0, 0); + + Scanline sl1bit = new Scanline(dib, 0); + for (int x = 0; x < sl1bit.Length; x++) + { + sl1bit[x] = 0; + } + + Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); + + sl1bit[5] = 1; + Assert.AreEqual(2, FreeImage.GetUniqueColors(dib)); + + palette[1] = Color.FromArgb(222, 255, 255, 255); + Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); + + sl1bit[5] = 0; + Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); + + FreeImage.UnloadEx(ref dib); + + // + // 4bpp + // + + dib = FreeImage.Allocate(10, 1, 4, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + + palette = new Palette(dib); + palette[0] = new RGBQUAD(Color.FromArgb(43, 255, 255, 255)); + palette[1] = new RGBQUAD(Color.FromArgb(222, 51, 2, 211)); + palette[2] = new RGBQUAD(Color.FromArgb(29, 25, 31, 52)); + palette[3] = new RGBQUAD(Color.FromArgb(173, 142, 61, 178)); + palette[4] = new RGBQUAD(Color.FromArgb(143, 41, 67, 199)); + palette[5] = new RGBQUAD(Color.FromArgb(2, 0, 2, 221)); + + Scanline sl4bit = new Scanline(dib, 0); + + for (int x = 0; x < sl4bit.Length; x++) + { + sl4bit[x] = 0; + } + + Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); + + sl4bit[1] = 1; + Assert.AreEqual(2, FreeImage.GetUniqueColors(dib)); + + sl4bit[2] = 1; + Assert.AreEqual(2, FreeImage.GetUniqueColors(dib)); + + sl4bit[3] = 2; + Assert.AreEqual(3, FreeImage.GetUniqueColors(dib)); + + sl4bit[4] = 3; + Assert.AreEqual(4, FreeImage.GetUniqueColors(dib)); + + sl4bit[5] = 4; + Assert.AreEqual(5, FreeImage.GetUniqueColors(dib)); + + sl4bit[6] = 5; + Assert.AreEqual(6, FreeImage.GetUniqueColors(dib)); + + sl4bit[7] = 6; + Assert.AreEqual(7, FreeImage.GetUniqueColors(dib)); + + sl4bit[8] = 7; + Assert.AreEqual(7, FreeImage.GetUniqueColors(dib)); + + sl4bit[9] = 7; + Assert.AreEqual(7, FreeImage.GetUniqueColors(dib)); + + FreeImage.UnloadEx(ref dib); + + // + // 8bpp + // + + dib = FreeImage.Allocate(10, 1, 8, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + + palette = new Palette(dib); + palette[0] = new RGBQUAD(Color.FromArgb(43, 255, 255, 255)); + palette[1] = new RGBQUAD(Color.FromArgb(222, 51, 2, 211)); + palette[2] = new RGBQUAD(Color.FromArgb(29, 25, 31, 52)); + palette[3] = new RGBQUAD(Color.FromArgb(173, 142, 61, 178)); + palette[4] = new RGBQUAD(Color.FromArgb(143, 41, 67, 199)); + palette[5] = new RGBQUAD(Color.FromArgb(2, 0, 2, 221)); + + Scanline sl8bit = new Scanline(dib, 0); + + for (int x = 0; x < sl8bit.Length; x++) + { + sl8bit[x] = 0; + } + + Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); + + sl8bit[1] = 1; + Assert.AreEqual(2, FreeImage.GetUniqueColors(dib)); + + sl8bit[2] = 2; + Assert.AreEqual(3, FreeImage.GetUniqueColors(dib)); + + sl8bit[3] = 3; + Assert.AreEqual(4, FreeImage.GetUniqueColors(dib)); + + sl8bit[4] = 4; + Assert.AreEqual(5, FreeImage.GetUniqueColors(dib)); + + sl8bit[5] = 6; + Assert.AreEqual(6, FreeImage.GetUniqueColors(dib)); + + sl8bit[5] = 7; + Assert.AreEqual(6, FreeImage.GetUniqueColors(dib)); + + sl8bit[5] = 8; + Assert.AreEqual(6, FreeImage.GetUniqueColors(dib)); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_CreateShrunkenPaletteLUT() + { + Random rand = new Random(); + dib = FreeImage.Allocate(1, 1, 8, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + + Palette palette = new Palette(dib); + byte[] lut; + int colors; + + for (int x = 0; x < palette.Length; x++) + { + palette[x] = 0xFF000000; + } + + lut = FreeImage.CreateShrunkenPaletteLUT(dib, out colors); + Assert.AreEqual(1, colors); + + for (int x = 0; x < palette.Length; x++) + { + Assert.AreEqual(0, lut[x]); + } + + palette[1] = 0x00000001; + lut = FreeImage.CreateShrunkenPaletteLUT(dib, out colors); + Assert.AreEqual(2, colors); + + Assert.AreEqual(0, lut[0]); + Assert.AreEqual(1, lut[1]); + + for (int x = 2; x < palette.Length; x++) + { + Assert.AreEqual(0, lut[x]); + } + + for (int x = 0; x < palette.Length; x++) + { + palette[x] = (uint)x; + } + + lut = FreeImage.CreateShrunkenPaletteLUT(dib, out colors); + Assert.AreEqual(256, colors); + + for (int x = 0; x < palette.Length; x++) + { + Assert.AreEqual(x, lut[x]); + } + + uint[] testColors = new uint[] { 0xFF4F387C, 0xFF749178, 0xFF84D51A, 0xFF746B71, 0x74718163, 0x91648106 }; + palette[0] = testColors[0]; + palette[1] = testColors[1]; + palette[2] = testColors[2]; + palette[3] = testColors[3]; + palette[4] = testColors[4]; + palette[5] = testColors[5]; + + for (int x = testColors.Length; x < palette.Length; x++) + { + palette[x] = testColors[rand.Next(0, testColors.Length - 1)]; + } + + lut = FreeImage.CreateShrunkenPaletteLUT(dib, out colors); + Assert.AreEqual(testColors.Length, colors); + + FreeImage.UnloadEx(ref dib); + } + + [Test] + public void FreeImage_Rotate4bit() + { + Palette orgPal, rotPal; + FIBITMAP rotated; + byte index; + dib = FreeImage.Allocate(2, 3, 4, 0, 0, 0); + Assert.IsFalse(dib.IsNull); + + index = 1; if (!FreeImage.SetPixelIndex(dib, 0, 0, ref index)) throw new Exception(); + index = 2; if (!FreeImage.SetPixelIndex(dib, 1, 0, ref index)) throw new Exception(); + index = 3; if (!FreeImage.SetPixelIndex(dib, 0, 1, ref index)) throw new Exception(); + index = 4; if (!FreeImage.SetPixelIndex(dib, 1, 1, ref index)) throw new Exception(); + index = 5; if (!FreeImage.SetPixelIndex(dib, 0, 2, ref index)) throw new Exception(); + index = 6; if (!FreeImage.SetPixelIndex(dib, 1, 2, ref index)) throw new Exception(); + + // + // 90 deg + // + + rotated = FreeImage.Rotate4bit(dib, 90d); + Assert.IsFalse(rotated.IsNull); + Assert.AreEqual(3, FreeImage.GetWidth(rotated)); + Assert.AreEqual(2, FreeImage.GetHeight(rotated)); + Assert.AreEqual(FREE_IMAGE_TYPE.FIT_BITMAP, FreeImage.GetImageType(rotated)); + Assert.AreEqual(4, FreeImage.GetBPP(rotated)); + orgPal = new Palette(dib); + rotPal = new Palette(rotated); + Assert.IsNotNull(orgPal); + Assert.IsNotNull(rotPal); + Assert.AreEqual(orgPal.Length, rotPal.Length); + for (int i = 0; i < orgPal.Length; i++) + { + Assert.AreEqual(orgPal[i], rotPal[i]); + } + + FreeImage.GetPixelIndex(rotated, 0, 0, out index); + Assert.AreEqual(5, index); + FreeImage.GetPixelIndex(rotated, 1, 0, out index); + Assert.AreEqual(3, index); + FreeImage.GetPixelIndex(rotated, 2, 0, out index); + Assert.AreEqual(1, index); + FreeImage.GetPixelIndex(rotated, 0, 1, out index); + Assert.AreEqual(6, index); + FreeImage.GetPixelIndex(rotated, 1, 1, out index); + Assert.AreEqual(4, index); + FreeImage.GetPixelIndex(rotated, 2, 1, out index); + Assert.AreEqual(2, index); + FreeImage.UnloadEx(ref rotated); + + // + // 180 deg + // + + rotated = FreeImage.Rotate4bit(dib, 180d); + Assert.IsFalse(rotated.IsNull); + Assert.AreEqual(FreeImage.GetWidth(dib), FreeImage.GetWidth(rotated)); + Assert.AreEqual(FreeImage.GetHeight(dib), FreeImage.GetHeight(rotated)); + Assert.AreEqual(FREE_IMAGE_TYPE.FIT_BITMAP, FreeImage.GetImageType(rotated)); + Assert.AreEqual(4, FreeImage.GetBPP(rotated)); + orgPal = new Palette(dib); + rotPal = new Palette(rotated); + Assert.IsNotNull(orgPal); + Assert.IsNotNull(rotPal); + Assert.AreEqual(orgPal.Length, rotPal.Length); + for (int i = 0; i < orgPal.Length; i++) + { + Assert.AreEqual(orgPal[i], rotPal[i]); + } + + FreeImage.GetPixelIndex(rotated, 0, 0, out index); + Assert.AreEqual(6, index); + FreeImage.GetPixelIndex(rotated, 1, 0, out index); + Assert.AreEqual(5, index); + FreeImage.GetPixelIndex(rotated, 0, 1, out index); + Assert.AreEqual(4, index); + FreeImage.GetPixelIndex(rotated, 1, 1, out index); + Assert.AreEqual(3, index); + FreeImage.GetPixelIndex(rotated, 0, 2, out index); + Assert.AreEqual(2, index); + FreeImage.GetPixelIndex(rotated, 1, 2, out index); + Assert.AreEqual(1, index); + FreeImage.UnloadEx(ref rotated); + + // + // 270 deg + // + + rotated = FreeImage.Rotate4bit(dib, 270d); + Assert.IsFalse(rotated.IsNull); + Assert.AreEqual(3, FreeImage.GetWidth(rotated)); + Assert.AreEqual(2, FreeImage.GetHeight(rotated)); + Assert.AreEqual(FREE_IMAGE_TYPE.FIT_BITMAP, FreeImage.GetImageType(rotated)); + Assert.AreEqual(4, FreeImage.GetBPP(rotated)); + orgPal = new Palette(dib); + rotPal = new Palette(rotated); + Assert.IsNotNull(orgPal); + Assert.IsNotNull(rotPal); + Assert.AreEqual(orgPal.Length, rotPal.Length); + for (int i = 0; i < orgPal.Length; i++) + { + Assert.AreEqual(orgPal[i], rotPal[i]); + } + + FreeImage.GetPixelIndex(rotated, 0, 0, out index); + Assert.AreEqual(2, index); + FreeImage.GetPixelIndex(rotated, 1, 0, out index); + Assert.AreEqual(4, index); + FreeImage.GetPixelIndex(rotated, 2, 0, out index); + Assert.AreEqual(6, index); + FreeImage.GetPixelIndex(rotated, 0, 1, out index); + Assert.AreEqual(1, index); + FreeImage.GetPixelIndex(rotated, 1, 1, out index); + Assert.AreEqual(3, index); + FreeImage.GetPixelIndex(rotated, 2, 1, out index); + Assert.AreEqual(5, index); + FreeImage.UnloadEx(ref rotated); + + FreeImage.UnloadEx(ref dib); + } + } + + [TestFixture] + public class FreeImageBitmapTest + { + ImageManager iManager = new ImageManager(); + FIBITMAP dib = new FIBITMAP(); + string freeImageCallback = null; + + [TestFixtureSetUp] + public void Init() + { + FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message); + } + + [TestFixtureTearDown] + public void DeInit() + { + FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message); + } + + [SetUp] + public void InitEachTime() + { + } + + [TearDown] + public void DeInitEachTime() + { + } + + void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message) + { + freeImageCallback = message; + } + + [Test] + public void FreeImageBitmapConstructors() + { + Image bitmap; + FreeImageBitmap fib, fib2; + Stream stream; + Graphics g; + string filename = iManager.GetBitmapPath(ImageType.Odd, ImageColorType.Type_24); + Assert.IsNotNull(filename); + Assert.IsTrue(File.Exists(filename)); + + bitmap = new Bitmap(filename); + Assert.IsNotNull(bitmap); + + fib = new FreeImageBitmap(bitmap); + Assert.AreEqual(bitmap.Width, fib.Width); + Assert.AreEqual(bitmap.Height, fib.Height); + fib.Dispose(); + fib.Dispose(); + + fib = new FreeImageBitmap(bitmap, new Size(100, 100)); + Assert.AreEqual(100, fib.Width); + Assert.AreEqual(100, fib.Height); + fib.Dispose(); + bitmap.Dispose(); + + fib = new FreeImageBitmap(filename); + fib.Dispose(); + + fib = new FreeImageBitmap(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT); + fib.Dispose(); + + fib = new FreeImageBitmap(filename, FREE_IMAGE_FORMAT.FIF_UNKNOWN); + fib.Dispose(); + + fib = new FreeImageBitmap(filename, FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_LOAD_FLAGS.DEFAULT); + fib.Dispose(); + + stream = new FileStream(filename, FileMode.Open); + Assert.IsNotNull(stream); + + fib = new FreeImageBitmap(stream); + fib.Dispose(); + stream.Seek(0, SeekOrigin.Begin); + + fib = new FreeImageBitmap(stream, FREE_IMAGE_FORMAT.FIF_UNKNOWN); + fib.Dispose(); + stream.Seek(0, SeekOrigin.Begin); + + fib = new FreeImageBitmap(stream, FREE_IMAGE_LOAD_FLAGS.DEFAULT); + fib.Dispose(); + stream.Seek(0, SeekOrigin.Begin); + + fib = new FreeImageBitmap(stream, FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_LOAD_FLAGS.DEFAULT); + fib.Dispose(); + stream.Dispose(); + + fib = new FreeImageBitmap(100, 100); + Assert.AreEqual(24, fib.ColorDepth); + Assert.AreEqual(100, fib.Width); + Assert.AreEqual(100, fib.Height); + fib.Dispose(); + + using (bitmap = new Bitmap(filename)) + { + Assert.IsNotNull(bitmap); + using (g = Graphics.FromImage(bitmap)) + { + Assert.IsNotNull(g); + fib = new FreeImageBitmap(100, 100, g); + } + } + fib.Dispose(); + + fib = new FreeImageBitmap(100, 100, PixelFormat.Format1bppIndexed); + Assert.AreEqual(PixelFormat.Format1bppIndexed, fib.PixelFormat); + Assert.AreEqual(100, fib.Width); + Assert.AreEqual(100, fib.Height); + fib.Dispose(); + + fib = new FreeImageBitmap(100, 100, PixelFormat.Format4bppIndexed); + Assert.AreEqual(PixelFormat.Format4bppIndexed, fib.PixelFormat); + Assert.AreEqual(100, fib.Width); + Assert.AreEqual(100, fib.Height); + fib.Dispose(); + + fib = new FreeImageBitmap(100, 100, PixelFormat.Format8bppIndexed); + Assert.AreEqual(PixelFormat.Format8bppIndexed, fib.PixelFormat); + Assert.AreEqual(100, fib.Width); + Assert.AreEqual(100, fib.Height); + fib.Dispose(); + + fib = new FreeImageBitmap(100, 100, PixelFormat.Format16bppRgb555); + Assert.AreEqual(PixelFormat.Format16bppRgb555, fib.PixelFormat); + Assert.AreEqual(100, fib.Width); + Assert.AreEqual(100, fib.Height); + fib.Dispose(); + + fib = new FreeImageBitmap(100, 100, PixelFormat.Format16bppRgb565); + Assert.AreEqual(PixelFormat.Format16bppRgb565, fib.PixelFormat); + Assert.AreEqual(100, fib.Width); + Assert.AreEqual(100, fib.Height); + fib.Dispose(); + + fib = new FreeImageBitmap(100, 100, PixelFormat.Format24bppRgb); + Assert.AreEqual(PixelFormat.Format24bppRgb, fib.PixelFormat); + Assert.AreEqual(100, fib.Width); + Assert.AreEqual(100, fib.Height); + fib.Dispose(); + + fib = new FreeImageBitmap(100, 100, PixelFormat.Format32bppArgb); + Assert.AreEqual(PixelFormat.Format32bppArgb, fib.PixelFormat); + Assert.AreEqual(100, fib.Width); + Assert.AreEqual(100, fib.Height); + + stream = new MemoryStream(); + BinaryFormatter formatter = new BinaryFormatter(); + + formatter.Serialize(stream, fib); + Assert.Greater(stream.Length, 0); + stream.Position = 0; + + fib2 = formatter.Deserialize(stream) as FreeImageBitmap; + stream.Dispose(); + fib.Dispose(); + fib2.Dispose(); + + fib = new FreeImageBitmap(filename); + fib2 = new FreeImageBitmap(fib); + fib2.Dispose(); + + fib2 = new FreeImageBitmap(fib, new Size(31, 22)); + Assert.AreEqual(31, fib2.Width); + Assert.AreEqual(22, fib2.Height); + fib2.Dispose(); + fib.Dispose(); + + dib = FreeImage.Allocate(1000, 800, 24, 0xFF0000, 0xFF00, 0xFF); + Assert.IsFalse(dib.IsNull); + + fib = new FreeImageBitmap(1000, 800, -(int)FreeImage.GetPitch(dib), FreeImage.GetPixelFormat(dib), FreeImage.GetScanLine(dib, 0)); + fib.Dispose(); + FreeImage.UnloadEx(ref dib); + } + + [Test] + public unsafe void Properties() + { + string filename = iManager.GetBitmapPath(ImageType.Even, ImageColorType.Type_32); + Assert.IsNotNull(filename); + Assert.IsTrue(File.Exists(filename)); + + FreeImageBitmap fib = new FreeImageBitmap(filename); + Assert.IsFalse(fib.HasPalette); + + try + { + Palette palette = fib.Palette; + Assert.Fail(); + } + catch + { + } + + Assert.IsFalse(fib.HasBackgroundColor); + fib.BackgroundColor = Color.LightSeaGreen; + Assert.IsTrue(fib.HasBackgroundColor); + Assert.That( + Color.LightSeaGreen.B == fib.BackgroundColor.Value.B && + Color.LightSeaGreen.G == fib.BackgroundColor.Value.G && + Color.LightSeaGreen.R == fib.BackgroundColor.Value.R); + fib.BackgroundColor = null; + Assert.IsFalse(fib.HasBackgroundColor); + fib.Dispose(); + + fib = new FreeImageBitmap(100, 100, PixelFormat.Format1bppIndexed); + ImageFlags flags = (ImageFlags)fib.Flags; + Assert.That((flags & ImageFlags.ColorSpaceRgb) == ImageFlags.ColorSpaceRgb); + Assert.That((flags & ImageFlags.HasAlpha) != ImageFlags.HasAlpha); + Assert.That((flags & ImageFlags.HasRealDpi) != ImageFlags.HasRealDpi); + Assert.That((flags & ImageFlags.HasTranslucent) != ImageFlags.HasTranslucent); + fib.Dispose(); + + dib = FreeImage.Allocate(100, 100, 32, 0xFF0000, 0xFF00, 0xFF); + FIICCPROFILE* prof = (FIICCPROFILE*)FreeImage.CreateICCProfile(dib, new byte[] { 0, 1, 2, 3 }, 4); + fib = new FreeImageBitmap(dib); + Scanline sc = (Scanline)fib.GetScanline(0); + RGBQUAD rgbq = sc[0]; + rgbq.rgbReserved = 127; + sc[0] = rgbq; + flags = (ImageFlags)fib.Flags; + Assert.That((flags & ImageFlags.HasAlpha) == ImageFlags.HasAlpha); + Assert.That((flags & ImageFlags.HasRealDpi) != ImageFlags.HasRealDpi); + Assert.That((flags & ImageFlags.HasTranslucent) == ImageFlags.HasTranslucent); + fib.Dispose(); + fib = null; + GC.Collect(2, GCCollectionMode.Forced); + GC.WaitForPendingFinalizers(); + + fib = new FreeImageBitmap(iManager.GetBitmapPath(ImageType.Metadata, ImageColorType.Type_01_Dither)); + int[] propList = fib.PropertyIdList; + Assert.IsNotNull(propList); + Assert.Greater(propList.Length, 0); + PropertyItem[] propItemList = fib.PropertyItems; + Assert.IsNotNull(propItemList); + Assert.Greater(propItemList.Length, 0); + Assert.IsNotNull(fib.RawFormat); + fib.Dispose(); + + fib = new FreeImageBitmap(iManager.GetBitmapPath(ImageType.Multipaged, ImageColorType.Type_01_Dither)); + Assert.Greater(fib.FrameCount, 1); + fib.Dispose(); + } + + [Test] + public void GetBounds() + { + Random rand = new Random(); + int height = rand.Next(1, 100), width = rand.Next(1, 100); + FreeImageBitmap fib = new FreeImageBitmap(width, height, PixelFormat.Format24bppRgb); + + Assert.AreEqual(fib.VerticalResolution, fib.HorizontalResolution); + GraphicsUnit unit; + RectangleF rect; + + unit = GraphicsUnit.Display; + rect = fib.GetBounds(ref unit); + + Assert.AreEqual(GraphicsUnit.Pixel, unit); + Assert.AreEqual(width, (int)rect.Width); + Assert.AreEqual(height, (int)rect.Height); + fib.Dispose(); + } + + [Test] + public void GetPropertyItem() + { + FreeImageBitmap fib = new FreeImageBitmap(iManager.GetBitmapPath(ImageType.Metadata, ImageColorType.Type_01_Dither)); + int[] list = fib.PropertyIdList; + Assert.IsNotNull(list); + Assert.Greater(list.Length, 0); + + for (int i = 0; i < list.Length; i++) + { + PropertyItem item = fib.GetPropertyItem(list[i]); + Assert.IsNotNull(item); + } + fib.Dispose(); + } + + [Test] + public void RemovePropertyItem() + { + FreeImageBitmap fib = new FreeImageBitmap(iManager.GetBitmapPath(ImageType.Metadata, ImageColorType.Type_01_Dither)); + Random rand = new Random(); + int[] list = fib.PropertyIdList; + int length = list.Length; + Assert.Greater(list.Length, 0); + + int id = list[rand.Next(0, list.Length - 1)]; + Assert.IsNotNull(fib.GetPropertyItem(id)); + fib.RemovePropertyItem(id); + list = fib.PropertyIdList; + Assert.That((list.Length + 1) == length); + fib.Dispose(); + } + + [Test] + public unsafe void RotateFlip() + { + FreeImageBitmap fib = new FreeImageBitmap(2, 2, PixelFormat.Format32bppArgb); + + ResetRotateBitmap(fib); + fib.RotateFlip(RotateFlipType.RotateNoneFlipX); + Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(0))[0]); + Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(0))[1]); + Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(1))[0]); + Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(1))[1]); + + ResetRotateBitmap(fib); + fib.RotateFlip(RotateFlipType.RotateNoneFlipY); + Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(0))[0]); + Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(0))[1]); + Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(1))[0]); + Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(1))[1]); + + ResetRotateBitmap(fib); + fib.RotateFlip(RotateFlipType.RotateNoneFlipXY); + Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(0))[0]); + Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(0))[1]); + Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(1))[0]); + Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(1))[1]); + + ResetRotateBitmap(fib); + fib.RotateFlip(RotateFlipType.Rotate90FlipNone); + Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(0))[0]); + Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(0))[1]); + Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(1))[0]); + Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(1))[1]); + + ResetRotateBitmap(fib); + fib.RotateFlip(RotateFlipType.Rotate90FlipX); + Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(0))[0]); + Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(0))[1]); + Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(1))[0]); + Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(1))[1]); + + ResetRotateBitmap(fib); + fib.RotateFlip(RotateFlipType.Rotate90FlipY); + Assert.AreEqual(0x00000004, ((int*)fib.GetScanlinePointer(0))[0]); + Assert.AreEqual(0x00000002, ((int*)fib.GetScanlinePointer(0))[1]); + Assert.AreEqual(0x00000003, ((int*)fib.GetScanlinePointer(1))[0]); + Assert.AreEqual(0x00000001, ((int*)fib.GetScanlinePointer(1))[1]); + + fib.Dispose(); + } + + private unsafe void ResetRotateBitmap(FreeImageBitmap fib) + { + ((int*)fib.GetScanlinePointer(0))[0] = 0x00000001; + ((int*)fib.GetScanlinePointer(0))[1] = 0x00000002; + ((int*)fib.GetScanlinePointer(1))[0] = 0x00000003; + ((int*)fib.GetScanlinePointer(1))[1] = 0x00000004; + } + + [Test] + public unsafe void GetSetPixel() + { + Random rand = new Random(); + FreeImageBitmap fib = new FreeImageBitmap(2, 1, PixelFormat.Format1bppIndexed); + Palette palette = fib.Palette; + for (int i = 0; i < palette.Length; i++) + { + palette[i] = (uint)rand.Next(int.MinValue, int.MaxValue); + fib.SetPixel(i, 0, palette[i]); + } + for (int i = 0; i < palette.Length; i++) + { + Assert.AreEqual(fib.GetPixel(i, 0), palette[i].Color); + } + fib.Dispose(); + + fib = new FreeImageBitmap(16, 1, PixelFormat.Format4bppIndexed); + palette = fib.Palette; + for (int i = 0; i < palette.Length; i++) + { + palette[i] = (uint)rand.Next(int.MinValue, int.MaxValue); + fib.SetPixel(i, 0, palette[i]); + } + for (int i = 0; i < palette.Length; i++) + { + Assert.AreEqual(fib.GetPixel(i, 0), palette[i].Color); + } + fib.Dispose(); + + fib = new FreeImageBitmap(256, 1, PixelFormat.Format8bppIndexed); + palette = fib.Palette; + for (int i = 0; i < palette.Length; i++) + { + palette[i] = (uint)rand.Next(int.MinValue, int.MaxValue); + fib.SetPixel(i, 0, palette[i]); + } + for (int i = 0; i < palette.Length; i++) + { + Assert.AreEqual(fib.GetPixel(i, 0), palette[i].Color); + } + fib.Dispose(); + + fib = new FreeImageBitmap(1000, 1, PixelFormat.Format16bppRgb555); + for (int i = 0; i < 1000; i++) + { + Color orgColor = Color.FromArgb(rand.Next(int.MinValue, int.MaxValue)); + fib.SetPixel(i, 0, orgColor); + Color newColor = fib.GetPixel(i, 0); + Assert.That(Math.Abs(orgColor.B - newColor.B) <= 8); + Assert.That(Math.Abs(orgColor.G - newColor.G) <= 8); + Assert.That(Math.Abs(orgColor.R - newColor.R) <= 8); + } + fib.Dispose(); + + fib = new FreeImageBitmap(1000, 1, PixelFormat.Format24bppRgb); + for (int i = 0; i < 1000; i++) + { + Color orgColor = Color.FromArgb(rand.Next(int.MinValue, int.MaxValue)); + fib.SetPixel(i, 0, orgColor); + Color newColor = fib.GetPixel(i, 0); + Assert.AreEqual(orgColor.B, newColor.B); + Assert.AreEqual(orgColor.G, newColor.G); + Assert.AreEqual(orgColor.R, newColor.R); + } + fib.Dispose(); + + fib = new FreeImageBitmap(1000, 1, PixelFormat.Format32bppArgb); + for (int i = 0; i < 1000; i++) + { + Color orgColor = Color.FromArgb(rand.Next(int.MinValue, int.MaxValue)); + fib.SetPixel(i, 0, orgColor); + Color newColor = fib.GetPixel(i, 0); + Assert.AreEqual(orgColor.B, newColor.B); + Assert.AreEqual(orgColor.G, newColor.G); + Assert.AreEqual(orgColor.R, newColor.R); + Assert.AreEqual(orgColor.A, newColor.A); + } + fib.Dispose(); + } + + [Test] + public void SaveAdd() + { + string filename = @"saveadd.tif"; + FreeImageBitmap fib = new FreeImageBitmap(100, 100, PixelFormat.Format24bppRgb); + try + { + fib.SaveAdd(); + Assert.Fail(); + } + catch { } + Assert.IsFalse(File.Exists(filename)); + fib.Save(filename); + fib.AdjustBrightness(0.3d); + fib.SaveAdd(); + FreeImageBitmap other = new FreeImageBitmap(100, 100, PixelFormat.Format24bppRgb); + foreach (Scanline scanline in other) + { + for (int i = 0; i < scanline.Length; i++) + { + scanline[i] = new RGBTRIPLE(Color.FromArgb(0x339955)); + } + } + fib.SaveAdd(other); + other.SaveAdd(filename); + other.Dispose(); + fib.Dispose(); + + fib = new FreeImageBitmap(filename); + Assert.AreEqual(4, fib.FrameCount); + fib.Dispose(); + File.Delete(filename); + Assert.IsFalse(File.Exists(filename)); + } + + [Test] + public void Clone() + { + FreeImageBitmap fib = new FreeImageBitmap(iManager.GetBitmapPath(ImageType.Even, ImageColorType.Type_24)); + object obj = new object(); + fib.Tag = obj; + FreeImageBitmap clone = fib.Clone() as FreeImageBitmap; + Assert.IsNotNull(clone); + Assert.AreEqual(fib.Width, clone.Width); + Assert.AreEqual(fib.Height, clone.Height); + Assert.AreEqual(fib.ColorDepth, clone.ColorDepth); + Assert.AreSame(fib.Tag, clone.Tag); + Assert.AreEqual(fib.ImageFormat, clone.ImageFormat); + clone.Dispose(); + fib.Dispose(); + } + + [Ignore] + public void LockBits() + { + } + + [Ignore] + public void UnlockBits() + { + } + + [Test] + public void GetTypeConvertedInstance() + { + using (FreeImageBitmap fib = new FreeImageBitmap(10, 10, PixelFormat.Format8bppIndexed)) + { + Assert.AreEqual(FREE_IMAGE_TYPE.FIT_BITMAP, fib.ImageType); + using (FreeImageBitmap conv = fib.GetTypeConvertedInstance(FREE_IMAGE_TYPE.FIT_DOUBLE, true)) + { + Assert.IsNotNull(conv); + Assert.AreEqual(FREE_IMAGE_TYPE.FIT_DOUBLE, conv.ImageType); + } + } + } + + [Test] + public void GetColorConvertedInstance() + { + using (FreeImageBitmap fib = new FreeImageBitmap(10, 10, PixelFormat.Format32bppArgb)) + { + Assert.AreEqual(32, fib.ColorDepth); + using (FreeImageBitmap conv = fib.GetColorConvertedInstance(FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP)) + { + Assert.IsNotNull(conv); + Assert.AreEqual(24, conv.ColorDepth); + } + } + } + + [Test] + public void GetScaledInstance() + { + using (FreeImageBitmap fib = new FreeImageBitmap(100, 80, PixelFormat.Format32bppArgb)) + { + Assert.AreEqual(100, fib.Width); + Assert.AreEqual(80, fib.Height); + using (FreeImageBitmap conv = fib.GetScaledInstance(80, 60, FREE_IMAGE_FILTER.FILTER_BICUBIC)) + { + Assert.IsNotNull(conv); + Assert.AreEqual(80, conv.Width); + Assert.AreEqual(60, conv.Height); + } + } + } + + [Test] + public unsafe void GetRotatedInstance() + { + using (FreeImageBitmap fib = new FreeImageBitmap(2, 2, PixelFormat.Format32bppArgb)) + { + ((int*)fib.GetScanlinePointer(0))[0] = 0x1; + ((int*)fib.GetScanlinePointer(0))[1] = 0x2; + ((int*)fib.GetScanlinePointer(1))[0] = 0x3; + ((int*)fib.GetScanlinePointer(1))[1] = 0x4; + using (FreeImageBitmap conv = fib.GetRotatedInstance(90d)) + { + Assert.IsNotNull(conv); + Assert.AreEqual(((int*)conv.GetScanlinePointer(0))[0], 0x3); + Assert.AreEqual(((int*)conv.GetScanlinePointer(0))[1], 0x1); + Assert.AreEqual(((int*)conv.GetScanlinePointer(1))[0], 0x4); + Assert.AreEqual(((int*)conv.GetScanlinePointer(1))[1], 0x2); + } + } + } + + [Test] + public void GetScanline() + { + FreeImageBitmap fib; + + fib = new FreeImageBitmap(10, 10, PixelFormat.Format1bppIndexed); + Scanline scanline1 = (Scanline)fib.GetScanline(0); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, PixelFormat.Format4bppIndexed); + Scanline scanline2 = (Scanline)fib.GetScanline(0); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, PixelFormat.Format8bppIndexed); + Scanline scanline3 = (Scanline)fib.GetScanline(0); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, PixelFormat.Format16bppRgb555); + Scanline scanline4 = (Scanline)fib.GetScanline(0); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, PixelFormat.Format16bppRgb565); + Scanline scanline5 = (Scanline)fib.GetScanline(0); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, PixelFormat.Format24bppRgb); + Scanline scanline6 = (Scanline)fib.GetScanline(0); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, PixelFormat.Format32bppArgb); + Scanline scanline7 = (Scanline)fib.GetScanline(0); + fib.Dispose(); + } + + [Test] + public void GetScanlines() + { + FreeImageBitmap fib; + + fib = new FreeImageBitmap(10, 10, PixelFormat.Format1bppIndexed); + IList> scanline01 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, PixelFormat.Format4bppIndexed); + IList> scanline02 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, PixelFormat.Format8bppIndexed); + IList> scanline03 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, PixelFormat.Format16bppRgb555); + IList> scanline04 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, PixelFormat.Format16bppRgb565); + IList> scanline05 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, PixelFormat.Format24bppRgb); + IList> scanline06 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, PixelFormat.Format32bppArgb); + IList> scanline07 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_COMPLEX); + IList> scanline08 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_DOUBLE); + IList> scanline09 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_FLOAT); + IList> scanline10 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_INT16); + IList> scanline11 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_INT32); + IList> scanline12 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_RGB16); + IList> scanline13 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_RGBA16); + IList> scanline14 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_RGBAF); + IList> scanline15 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_RGBF); + IList> scanline16 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_UINT16); + IList> scanline17 = (IList>)fib.GetScanlines(); + fib.Dispose(); + + fib = new FreeImageBitmap(10, 10, FREE_IMAGE_TYPE.FIT_UINT32); + IList> scanline18 = (IList>)fib.GetScanlines(); + fib.Dispose(); + } + + [Test] + public void Operators() + { + FreeImageBitmap fib1 = null, fib2 = null; + Assert.IsTrue(fib1 == fib2); + Assert.IsFalse(fib1 != fib2); + Assert.IsTrue(fib1 == null); + Assert.IsFalse(fib1 != null); + + fib1 = new FreeImageBitmap(10, 10, PixelFormat.Format24bppRgb); + Assert.IsFalse(fib1 == fib2); + Assert.IsTrue(fib1 != fib2); + + fib2 = fib1; + fib1 = null; + Assert.IsFalse(fib1 == fib2); + Assert.IsTrue(fib1 != fib2); + + fib1 = new FreeImageBitmap(10, 9, PixelFormat.Format24bppRgb); + Assert.IsFalse(fib1 == fib2); + Assert.IsTrue(fib1 != fib2); + + fib2.Dispose(); + fib2 = fib1; + + Assert.IsTrue(fib1 == fib2); + Assert.IsFalse(fib1 != fib2); + + fib2 = fib1.Clone() as FreeImageBitmap; + Assert.IsTrue(fib1 == fib2); + Assert.IsFalse(fib1 != fib2); + + fib1.Dispose(); + fib2.Dispose(); + } + } + + public class Program + { + static ImageManager iManager = new ImageManager(); + static ImportedFunctionsTest ift = new ImportedFunctionsTest(); + static ImportedStructsTest ist = new ImportedStructsTest(); + static WrapperStructsTest wst = new WrapperStructsTest(); + static WrapperFunctionsTest wft = new WrapperFunctionsTest(); + static FreeImageBitmapTest fib = new FreeImageBitmapTest(); + + public static void Main() + { + List classList = new List(5); + classList.Add(new TestClass(ift)); + classList.Add(new TestClass(ist)); + classList.Add(new TestClass(wst)); + classList.Add(new TestClass(wft)); + classList.Add(new TestClass(fib)); + + for (int i = 0; i < 10000; ) + { + for (int j = 0; j < classList.Count; j++) + classList[j].ExecuteTests(); + Console.WriteLine("Loop {0}", ++i); + //GC.Collect(); + } + } + } + + public class TestClass + { + private object classMember = null; + + private MethodInfo classSetUp = null; + private MethodInfo classTearDown = null; + + private MethodInfo testSetUp = null; + private MethodInfo testTearDown = null; + + private List methodList = null; + + private static object[] parameters = { }; + + public TestClass(object classMember) + { + this.classMember = classMember; + MethodInfo[] infos = classMember.GetType().GetMethods(System.Reflection.BindingFlags.Public | BindingFlags.Instance); + methodList = new List(infos.Length); + + foreach (MethodInfo info in infos) + { + object[] attributes = info.GetCustomAttributes(false); + foreach (Attribute attribute in attributes) + { + if (attribute.GetType() == typeof(TestAttribute)) + { + methodList.Add(info); + break; + } + else if (attribute.GetType() == typeof(TestFixtureSetUpAttribute)) + { + classSetUp = info; + break; + } + else if (attribute.GetType() == typeof(TestFixtureTearDownAttribute)) + { + classTearDown = info; + break; + } + else if (attribute.GetType() == typeof(SetUpAttribute)) + { + testSetUp = info; + break; + } + else if (attribute.GetType() == typeof(TearDownAttribute)) + { + testTearDown = info; + break; + } + } + } + } + + public void ExecuteTests() + { + if (classSetUp != null) + classSetUp.Invoke(classMember, parameters); + + foreach (MethodInfo method in methodList) + { + if (testSetUp != null) + testSetUp.Invoke(classMember, parameters); + + try + { + Console.WriteLine(method.ToString()); + method.Invoke(classMember, parameters); + } + catch (Exception ex) + { + while (ex.InnerException != null) + ex = ex.InnerException; + Console.WriteLine(ex.ToString()); + Environment.Exit(99); + } + + if (testTearDown != null) + testTearDown.Invoke(classMember, parameters); + } + + if (classTearDown != null) + classTearDown.Invoke(classMember, parameters); + } + } } \ No newline at end of file diff --git a/Wrapper/FreeImage.NET/cs/Whats_New.NET.txt b/Wrapper/FreeImage.NET/cs/Whats_New.NET.txt index e13ec6c..26fe782 100644 --- a/Wrapper/FreeImage.NET/cs/Whats_New.NET.txt +++ b/Wrapper/FreeImage.NET/cs/Whats_New.NET.txt @@ -1,124 +1,124 @@ -What's New for FreeImage.NET - -* : fixed -- : removed -! : changed -+ : added - -Month Day, 2011 - 3.15.2.0 -+ [Herve Drolon] added missing save flags JPEG_OPTIMIZE, JPEG_BASELINE -* [raburton] fixed FreeImageBitmap constructor with initialisation of X/Y resolution - -July 25th, 2011 - 3.15.1.0 -+ [Herve Drolon] added VS 2008 project files -* [Stefan Wetter] fixed FreeImage.IsAvailable method returning false in case the wrapper was out of date -* [Herve Drolon] fixed FreeImage.GetBitmap returning false with dib without resolution info -* [cclouston] fixed EnlargeCanvas returning always NULL - -December 21, 2009 - 3.13.1.1 -* [Carsten Klein] Fixed a threading bug in OpenMultiBitmapFromStream and CloseMultiBitmap. Access to the streamHandles Dictionary is now thread safe. - -September 15, 2009 - 3.13.0.1 -+ [Jean-Philippe Goerke] Added PFM, PICT and RAW file formats. -+ [Jean-Philippe Goerke] Added loading flag JPEG_EXIFROTATE. -+ [Jean-Philippe Goerke] Added method GetNativeVersion() to the FreeImage class. -! [Jean-Philippe Goerke] Changed FreeImage.IsAvailable() now returning false in case the native library is out of date or unusable. -- [Jean-Philippe Goerke] Removed FREEIMAGE_MAJOR_VERSION, FREEIMAGE_MINOR_VERSION and FREEIMAGE_RELEASE_SERIAL constants from class FreeImage. -+ [Jean-Philippe Goerke] Added enumeration FREE_IMAGE_COLOR_OPTIONS. -+ [Jean-Philippe Goerke] Added new overloads for FreeImage.Allocate() and FreeImage.AllocateT(). -+ [Jean-Philippe Goerke] Added methods AllocateEx(), AllocateExT(), FillBackground() and EnlargeCanvas() to class FreeImage. -+ [Jean-Philippe Goerke] Added methods FillBackground(), EnlargeCanvas() and GetEnlargedInstance() to class FreeImageBitmap. -- [Jean-Philippe Goerke] Removed unused ConvertLineXtoY() methods. -* [kruno13] Fixed a bug in the FreeImageBitmap constructors. -- [Jean-Philippe Goerke] Removed unneeded GCHandles used with delegates. -+ [Jean-Philippe Goerke] Added overloaded method OpenMultiBitmapFromStream to class FreeImage. -+ [Jean-Philippe Goerke] FreeImageBitmap now supports loading multipage bitmaps from streams. Warning: The stream must remain open for the bitmap's lifetime. -* [mshanke] Fixed some IPTC metadata incorrect namings. -! [Jean-Philippe Goerke] Method FreeImage.RotateClassic is now deprecated. -+ [Jean-Philippe Goerke] Added method Rotate() to the FreeImage class. -! [Jean-Philippe Goerke] FreeImageBitmap now uses the method Rotate instead of RotateClassic. - -April 20, 2009 - 1.10 -! [Jean-Philippe Goerke] Updated wrapper-version to 1.10 including some minor changes. - -February 27, 2009 - 1.09 -+ [Jean-Philippe Goerke] Help file creation now uses the Version Builder plugin of Sandcastle Help File Builder to generate an MSDN-like Version Information paragraph in the help file. -+ [Jean-Philippe Goerke] Added new metadata model class MDM_EXIF_MAIN to replace MDM_MAIN. Class MDM_MAIN still exists but is marked obsolete and will be removed in a future release. -+ [Jean-Philippe Goerke] Added various properties to access the value of metadata tags directly to all MDM_* classes expect MDM_CUSTOM, MDM_NODATA and MDM_MAKERNOTE. -! [Jean-Philippe Goerke] Now classes deriving from MetadataModel, expect obsoltete class MDM_MAIN, are no longer sealed. -! [Jean-Philippe Goerke] Class GifInformation now derives from MDM_ANIMATION. Moved properties into base class MDM_ANIMATION. -+ [Jean-Philippe Goerke] Added enumerations AltitudeType, DirectionReference, InteroperabilityMode, LatitudeType, LongitudeType, ImageOrientation and VelocityUnit to class MetadataModel. -* [Jean-Philippe Goerke] Fixed a bug in MetadataTag.Count, MetadataTag.Length and MetadataTag.Value. -+ [Jean-Philippe Goerke] Added attribute DebuggerBrowsable(DebuggerBrowsableState.Never) to some protected and private fields. - -February 23, 2009 - 1.08 -! [Jean-Philippe Goerke] FreeImage.NET now uses Sandcastle Help File Builder 1.8.0.1 -+ [Jean-Philippe Goerke] Added new Sandcastle Help File Builder project file FreeImage.NET.shfbproj. -* [headkaze] Fixed a bug in FreeImage.CreateFromBitmap, which now incorporates any transparency information from palletized .NET Bitmaps. -+ [Jean-Philippe Goerke] Added new overloaded method CreateGlobalPalette() to class GifInformation to create global palettes from local palettes. -! [Jean-Philippe Goerke] Renamed internal method FreeImage.SetTransparencyTable_ to FreeImage.SetTransparencyTable. -+ [Jean-Philippe Goerke] Added attribute DebuggerBrowsable(DebuggerBrowsableState.Never) to many protected and private fields. - -February 20, 2009 - 1.07 -* [Jean-Philippe Goerke] Fixed a bug in FreeImage.IsFilenameValidForFIF and FreeImage.IsExtensionValidForFIF. -* [Jean-Philippe Goerke] Fixed a bug in FreeImage.SaveEx that could prevent saving supported non-bitmap types. -* [Jean-Philippe Goerke] Fixed a small bug in FreeImage.CompareData. -+ [Jean-Philippe Goerke] Added two overloads of ColorQuantizeEx() in class FreeImage to return images with a color depth smaller than 8. -! [Jean-Philippe Goerke] Updated FreeImage.ConvertColorDepth to support 1- and 4-bpp color conversions (FreeImage_ConvertTo4Bits only creates grayscale results). -* [headkaze] Fixed a bug in FreeImage.GetBitmap, which now adds any transparency information to palletized .NET Bitmaps. -* [headkaze] Fixed a bug in FreeImage.GetBitmap and FreeImage.CreateFromBitmap to support palettes with sizes different from 2, 16 and 256 entries. -! [Jean-Philippe Goerke] Improved handling of multipage bitmaps in FreeImageBitmap class. -+ [Jean-Philippe Goerke] Added new overloads for FreeImageBitmap.SaveAdd() to allow inserting frames at a specified page index. -+ [Jean-Philippe Goerke] Added new class GifInformation which provides access to GIF format specific metadata (GlobalPalette, Animation, etc.). -+ [Jean-Philippe Goerke] Added enumeration DisposalMethodType. -! [Jean-Philippe Goerke] Updated class MemoryArray, which now is Disposable and has a new static constructor. -! [Jean-Philippe Goerke] Removed code using reflection from class ImageMetadata. -+ [Jean-Philippe Goerke] Added new ctor(FITAG) and ctor(MetadataTag) to class Palette to support palettes stored in metadata tags. -+ [Jean-Philippe Goerke] Added new ctor(RGBQUAD[]), ctor(Color[]) and ctor(int) to create new stand-alone palettes to class Palette. -+ [Jean-Philippe Goerke] Added overloaded CreateGrayscalePalette(), Reverse() and CopyFrom() to class Palette. -! [Jean-Philippe Goerke] Changed the behavior of MetadataTag.Value. byte and byte[] are now stored as FREE_IMAGE_MDTYPE.FIDT_BYTE instead of FREE_IMAGE_MDTYPE.FIDT_UNDEFINED. -+ [Jean-Philippe Goerke] Added a type check to MetadataTag.SetValue(object), MetadataTag.SetValue(object, FREE_IMAGE_MDTYPE) and the setter of MetadataTag.Value. - -November 18, 2008 - 1.06 -* [Jean-Philippe Goerke] Fixed a bug in FreeImage.SaveEx. -! [Jean-Philippe Goerke] Improved method FreeImage.IsFilenameValidForFIF. - -November 5, 2008 - 1.05 -! [Jean-Philippe Goerke] Updated documentation of FreeImage.ConvertFromRawBits and FreeImage.ConvertToRawBits. -+ [Jean-Philippe Goerke] Added new overload ConvertFromRawBits(byte[],int,int,int,uint,uint,uint,uint,bool) to the FreeImage class. -+ [Jean-Philippe Goerke] Added new overload ConvertFromRawBits(byte[],FREE_IMAGE_TYPE,int,int,int,uint,uint,uint,uint bool) to the FreeImage class. -+ [Jean-Philippe Goerke] Added new overload ConvertToRawBits(byte[],FIBITMAP,int,uint,uint,uint,uint,bool) to the FreeImage class. -! [Jean-Philippe Goerke] Improved method FreeImage.CreatePropertyItem. -+ [Jean-Philippe Goerke] Added overloads for CopyMemory to class FreeImage which support direct usage of arrays. -! [Jean-Philippe Goerke] Replaced calls to FreeImage.MoveMemory with FreeImage.CopyMemory. -! [Jean-Philippe Goerke] Class FreeImageBitmap now derives from MarshalByRefObject. -+ [Jean-Philippe Goerke] Added new ctor(int,int,int,PixelFormat,byte[]) and ctor(int,int,int,int,FREE_IMAGE_TYPE,byte[]) to the FreeImageBitmap class. - -August 29, 2008 - 1.04 -+ [Jean-Philippe Goerke] Added new target architectures x86 and x64 to the Visual Studio 2005 solution and project files. -+ [Jean-Philippe Goerke] Added static readonly field Zero to FIBITMAP, FIMEMORY, FIMETADATA, FIMULTIBITMAP and FITAG. -! [Jean-Philippe Goerke] Changed CreateFromBitmap to handle all formats contained by System.Drawing.Imaging.PixelFormat. -+ [Jean-Philippe Goerke] Added overload for ConvertFromRawBits to class FreeImage which supports creating images of any FREE_IMAGE_TYPE from raw bits. -+ [Jean-Philippe Goerke] Added method GetTypeParameters to class FreeImage. -! [Jean-Philippe Goerke] Both constructors FreeImageBitmap.ctor(int,int,PixelFormat) and FreeImageBitmap.ctor(int,int,int,PixelFormat,IntPtr) now work with all formats defined in PixelFormat. -+ [Jean-Philippe Goerke] Added new constructor FreeImageBitmap.ctor(int,int,int,int,FREE_IMAGE_TYPE,IntPtr) to FreeImageBitmap class. - -August 18, 2008 - 1.03 -* [Eric T. Wilson] Added GC.AddMemoryPressure and GC.RemoveMemoryPressure to FreeImageBitmap class. -+ [Eric T. Wilson] Added ToBitmap method to FreeImageBitmap class. -! [Eric T. Wilson] Changed implicit conversion operators to and from System.Drawing.Bitmap to explicit operators. -- [Eric T. Wilson] Removed Message event from FreeImage class. Use event FreeImageEngine.Message instead. -- [Eric T. Wilson] Removed contructors ctor(int) and ctor(IntPtr) from FIBITMAP, FIMULTIBITMAP, FIMEMORY, FIMETADATA and FITAG. -- [Eric T. Wilson] Removed implicit conversion operators from and to int and IntPtr from FIBITMAP, FIMULTIBITMAP, FIMEMORY, FIMETADATA and FITAG. -+ [Jean-Philippe Goerke] Added SetNull method to FIBITMAP, FIMULTIBITMAP, FIMEMORY, FIMETADATA and FITAG. -! [Jean-Philippe Goerke] Changed handling of multipage images in FreeImageBitmap: As with System.Drawing.Bitmap, any changes applied to an active frame are no longer written back to the multipage image loaded. -* [Jean-Philippe Goerke] Fixed a bug in FreeImage.SaveToStream(ref FIBITMAP, Stream, FREE_IMAGE_FORMAT, FREE_IMAGE_SAVE_FLAGS, FREE_IMAGE_COLOR_DEPTH, bool): changed catch block into a finally block. - -July 25, 2008 - 1.02 -+ [Jean-Philippe Goerke] Improved handling of XMP metadata in MetadataTag.cs: Key is now set to "XMLPacket" not changeable if Model is FREE_IMAGE_MDMODEL.FIMD_XMP. - -July 01, 2008 - 1.01 -+ [Jean-Philippe Goerke] Added methods Quantize and GetQuantizedInstance to the FreeImageBitmap class. - -November 12, 2007 - 1.00 -+ [Jean-Philippe Goerke] Initial release. +What's New for FreeImage.NET + +* : fixed +- : removed +! : changed ++ : added + +Month Day, 2011 - 3.15.2.0 ++ [Herve Drolon] added missing save flags JPEG_OPTIMIZE, JPEG_BASELINE +* [raburton] fixed FreeImageBitmap constructor with initialisation of X/Y resolution + +July 25th, 2011 - 3.15.1.0 ++ [Herve Drolon] added VS 2008 project files +* [Stefan Wetter] fixed FreeImage.IsAvailable method returning false in case the wrapper was out of date +* [Herve Drolon] fixed FreeImage.GetBitmap returning false with dib without resolution info +* [cclouston] fixed EnlargeCanvas returning always NULL + +December 21, 2009 - 3.13.1.1 +* [Carsten Klein] Fixed a threading bug in OpenMultiBitmapFromStream and CloseMultiBitmap. Access to the streamHandles Dictionary is now thread safe. + +September 15, 2009 - 3.13.0.1 ++ [Jean-Philippe Goerke] Added PFM, PICT and RAW file formats. ++ [Jean-Philippe Goerke] Added loading flag JPEG_EXIFROTATE. ++ [Jean-Philippe Goerke] Added method GetNativeVersion() to the FreeImage class. +! [Jean-Philippe Goerke] Changed FreeImage.IsAvailable() now returning false in case the native library is out of date or unusable. +- [Jean-Philippe Goerke] Removed FREEIMAGE_MAJOR_VERSION, FREEIMAGE_MINOR_VERSION and FREEIMAGE_RELEASE_SERIAL constants from class FreeImage. ++ [Jean-Philippe Goerke] Added enumeration FREE_IMAGE_COLOR_OPTIONS. ++ [Jean-Philippe Goerke] Added new overloads for FreeImage.Allocate() and FreeImage.AllocateT(). ++ [Jean-Philippe Goerke] Added methods AllocateEx(), AllocateExT(), FillBackground() and EnlargeCanvas() to class FreeImage. ++ [Jean-Philippe Goerke] Added methods FillBackground(), EnlargeCanvas() and GetEnlargedInstance() to class FreeImageBitmap. +- [Jean-Philippe Goerke] Removed unused ConvertLineXtoY() methods. +* [kruno13] Fixed a bug in the FreeImageBitmap constructors. +- [Jean-Philippe Goerke] Removed unneeded GCHandles used with delegates. ++ [Jean-Philippe Goerke] Added overloaded method OpenMultiBitmapFromStream to class FreeImage. ++ [Jean-Philippe Goerke] FreeImageBitmap now supports loading multipage bitmaps from streams. Warning: The stream must remain open for the bitmap's lifetime. +* [mshanke] Fixed some IPTC metadata incorrect namings. +! [Jean-Philippe Goerke] Method FreeImage.RotateClassic is now deprecated. ++ [Jean-Philippe Goerke] Added method Rotate() to the FreeImage class. +! [Jean-Philippe Goerke] FreeImageBitmap now uses the method Rotate instead of RotateClassic. + +April 20, 2009 - 1.10 +! [Jean-Philippe Goerke] Updated wrapper-version to 1.10 including some minor changes. + +February 27, 2009 - 1.09 ++ [Jean-Philippe Goerke] Help file creation now uses the Version Builder plugin of Sandcastle Help File Builder to generate an MSDN-like Version Information paragraph in the help file. ++ [Jean-Philippe Goerke] Added new metadata model class MDM_EXIF_MAIN to replace MDM_MAIN. Class MDM_MAIN still exists but is marked obsolete and will be removed in a future release. ++ [Jean-Philippe Goerke] Added various properties to access the value of metadata tags directly to all MDM_* classes expect MDM_CUSTOM, MDM_NODATA and MDM_MAKERNOTE. +! [Jean-Philippe Goerke] Now classes deriving from MetadataModel, expect obsoltete class MDM_MAIN, are no longer sealed. +! [Jean-Philippe Goerke] Class GifInformation now derives from MDM_ANIMATION. Moved properties into base class MDM_ANIMATION. ++ [Jean-Philippe Goerke] Added enumerations AltitudeType, DirectionReference, InteroperabilityMode, LatitudeType, LongitudeType, ImageOrientation and VelocityUnit to class MetadataModel. +* [Jean-Philippe Goerke] Fixed a bug in MetadataTag.Count, MetadataTag.Length and MetadataTag.Value. ++ [Jean-Philippe Goerke] Added attribute DebuggerBrowsable(DebuggerBrowsableState.Never) to some protected and private fields. + +February 23, 2009 - 1.08 +! [Jean-Philippe Goerke] FreeImage.NET now uses Sandcastle Help File Builder 1.8.0.1 ++ [Jean-Philippe Goerke] Added new Sandcastle Help File Builder project file FreeImage.NET.shfbproj. +* [headkaze] Fixed a bug in FreeImage.CreateFromBitmap, which now incorporates any transparency information from palletized .NET Bitmaps. ++ [Jean-Philippe Goerke] Added new overloaded method CreateGlobalPalette() to class GifInformation to create global palettes from local palettes. +! [Jean-Philippe Goerke] Renamed internal method FreeImage.SetTransparencyTable_ to FreeImage.SetTransparencyTable. ++ [Jean-Philippe Goerke] Added attribute DebuggerBrowsable(DebuggerBrowsableState.Never) to many protected and private fields. + +February 20, 2009 - 1.07 +* [Jean-Philippe Goerke] Fixed a bug in FreeImage.IsFilenameValidForFIF and FreeImage.IsExtensionValidForFIF. +* [Jean-Philippe Goerke] Fixed a bug in FreeImage.SaveEx that could prevent saving supported non-bitmap types. +* [Jean-Philippe Goerke] Fixed a small bug in FreeImage.CompareData. ++ [Jean-Philippe Goerke] Added two overloads of ColorQuantizeEx() in class FreeImage to return images with a color depth smaller than 8. +! [Jean-Philippe Goerke] Updated FreeImage.ConvertColorDepth to support 1- and 4-bpp color conversions (FreeImage_ConvertTo4Bits only creates grayscale results). +* [headkaze] Fixed a bug in FreeImage.GetBitmap, which now adds any transparency information to palletized .NET Bitmaps. +* [headkaze] Fixed a bug in FreeImage.GetBitmap and FreeImage.CreateFromBitmap to support palettes with sizes different from 2, 16 and 256 entries. +! [Jean-Philippe Goerke] Improved handling of multipage bitmaps in FreeImageBitmap class. ++ [Jean-Philippe Goerke] Added new overloads for FreeImageBitmap.SaveAdd() to allow inserting frames at a specified page index. ++ [Jean-Philippe Goerke] Added new class GifInformation which provides access to GIF format specific metadata (GlobalPalette, Animation, etc.). ++ [Jean-Philippe Goerke] Added enumeration DisposalMethodType. +! [Jean-Philippe Goerke] Updated class MemoryArray, which now is Disposable and has a new static constructor. +! [Jean-Philippe Goerke] Removed code using reflection from class ImageMetadata. ++ [Jean-Philippe Goerke] Added new ctor(FITAG) and ctor(MetadataTag) to class Palette to support palettes stored in metadata tags. ++ [Jean-Philippe Goerke] Added new ctor(RGBQUAD[]), ctor(Color[]) and ctor(int) to create new stand-alone palettes to class Palette. ++ [Jean-Philippe Goerke] Added overloaded CreateGrayscalePalette(), Reverse() and CopyFrom() to class Palette. +! [Jean-Philippe Goerke] Changed the behavior of MetadataTag.Value. byte and byte[] are now stored as FREE_IMAGE_MDTYPE.FIDT_BYTE instead of FREE_IMAGE_MDTYPE.FIDT_UNDEFINED. ++ [Jean-Philippe Goerke] Added a type check to MetadataTag.SetValue(object), MetadataTag.SetValue(object, FREE_IMAGE_MDTYPE) and the setter of MetadataTag.Value. + +November 18, 2008 - 1.06 +* [Jean-Philippe Goerke] Fixed a bug in FreeImage.SaveEx. +! [Jean-Philippe Goerke] Improved method FreeImage.IsFilenameValidForFIF. + +November 5, 2008 - 1.05 +! [Jean-Philippe Goerke] Updated documentation of FreeImage.ConvertFromRawBits and FreeImage.ConvertToRawBits. ++ [Jean-Philippe Goerke] Added new overload ConvertFromRawBits(byte[],int,int,int,uint,uint,uint,uint,bool) to the FreeImage class. ++ [Jean-Philippe Goerke] Added new overload ConvertFromRawBits(byte[],FREE_IMAGE_TYPE,int,int,int,uint,uint,uint,uint bool) to the FreeImage class. ++ [Jean-Philippe Goerke] Added new overload ConvertToRawBits(byte[],FIBITMAP,int,uint,uint,uint,uint,bool) to the FreeImage class. +! [Jean-Philippe Goerke] Improved method FreeImage.CreatePropertyItem. ++ [Jean-Philippe Goerke] Added overloads for CopyMemory to class FreeImage which support direct usage of arrays. +! [Jean-Philippe Goerke] Replaced calls to FreeImage.MoveMemory with FreeImage.CopyMemory. +! [Jean-Philippe Goerke] Class FreeImageBitmap now derives from MarshalByRefObject. ++ [Jean-Philippe Goerke] Added new ctor(int,int,int,PixelFormat,byte[]) and ctor(int,int,int,int,FREE_IMAGE_TYPE,byte[]) to the FreeImageBitmap class. + +August 29, 2008 - 1.04 ++ [Jean-Philippe Goerke] Added new target architectures x86 and x64 to the Visual Studio 2005 solution and project files. ++ [Jean-Philippe Goerke] Added static readonly field Zero to FIBITMAP, FIMEMORY, FIMETADATA, FIMULTIBITMAP and FITAG. +! [Jean-Philippe Goerke] Changed CreateFromBitmap to handle all formats contained by System.Drawing.Imaging.PixelFormat. ++ [Jean-Philippe Goerke] Added overload for ConvertFromRawBits to class FreeImage which supports creating images of any FREE_IMAGE_TYPE from raw bits. ++ [Jean-Philippe Goerke] Added method GetTypeParameters to class FreeImage. +! [Jean-Philippe Goerke] Both constructors FreeImageBitmap.ctor(int,int,PixelFormat) and FreeImageBitmap.ctor(int,int,int,PixelFormat,IntPtr) now work with all formats defined in PixelFormat. ++ [Jean-Philippe Goerke] Added new constructor FreeImageBitmap.ctor(int,int,int,int,FREE_IMAGE_TYPE,IntPtr) to FreeImageBitmap class. + +August 18, 2008 - 1.03 +* [Eric T. Wilson] Added GC.AddMemoryPressure and GC.RemoveMemoryPressure to FreeImageBitmap class. ++ [Eric T. Wilson] Added ToBitmap method to FreeImageBitmap class. +! [Eric T. Wilson] Changed implicit conversion operators to and from System.Drawing.Bitmap to explicit operators. +- [Eric T. Wilson] Removed Message event from FreeImage class. Use event FreeImageEngine.Message instead. +- [Eric T. Wilson] Removed contructors ctor(int) and ctor(IntPtr) from FIBITMAP, FIMULTIBITMAP, FIMEMORY, FIMETADATA and FITAG. +- [Eric T. Wilson] Removed implicit conversion operators from and to int and IntPtr from FIBITMAP, FIMULTIBITMAP, FIMEMORY, FIMETADATA and FITAG. ++ [Jean-Philippe Goerke] Added SetNull method to FIBITMAP, FIMULTIBITMAP, FIMEMORY, FIMETADATA and FITAG. +! [Jean-Philippe Goerke] Changed handling of multipage images in FreeImageBitmap: As with System.Drawing.Bitmap, any changes applied to an active frame are no longer written back to the multipage image loaded. +* [Jean-Philippe Goerke] Fixed a bug in FreeImage.SaveToStream(ref FIBITMAP, Stream, FREE_IMAGE_FORMAT, FREE_IMAGE_SAVE_FLAGS, FREE_IMAGE_COLOR_DEPTH, bool): changed catch block into a finally block. + +July 25, 2008 - 1.02 ++ [Jean-Philippe Goerke] Improved handling of XMP metadata in MetadataTag.cs: Key is now set to "XMLPacket" not changeable if Model is FREE_IMAGE_MDMODEL.FIMD_XMP. + +July 01, 2008 - 1.01 ++ [Jean-Philippe Goerke] Added methods Quantize and GetQuantizedInstance to the FreeImageBitmap class. + +November 12, 2007 - 1.00 ++ [Jean-Philippe Goerke] Initial release. diff --git a/Wrapper/FreeImagePlus/WhatsNew_FIP.txt b/Wrapper/FreeImagePlus/WhatsNew_FIP.txt index 45d3f62..99591b8 100644 --- a/Wrapper/FreeImagePlus/WhatsNew_FIP.txt +++ b/Wrapper/FreeImagePlus/WhatsNew_FIP.txt @@ -1,178 +1,178 @@ -What's New for FreeImagePlus - -* : fixed -- : removed -! : changed -+ : added - -July 17th, 2011 -+ [Herve Drolon] added fipImage::convertToRGB16 - -February 26th, 2011 -+ [Herve Drolon] added fipImage::convertToFloat - -November 14th, 2010 -+ [Herve Drolon] added getThumbnail, setThumbnail, hasThumbnail, clearThumbnail to fipImage - -November 7th, 2010 -+ [Herve Drolon] added fipImage::convertToUINT16 - -October 9th, 2010 -* [Herve Drolon] fixed fipWinImage::setToneMappingOperator when displaying RGBA HDR images - -April 18th, 2010 -+ [Herve Drolon] added new multi-page functions - added fipMemoryIO:close - added fipMemoryIO:loadMultiPage - added fipMemoryIO:saveMultiPage - added fipMultiPage:FIMULTIBITMAP* - added fipMultiPage:open(FreeImageIO *io, fi_handle handle, int flags = 0) - added fipMultiPage:saveToHandle - added fipMultiPage:saveToMemory - -October 24th, 2009 -! [Herve Drolon] fixed the '65535' width/height/pitch size limitation (need recompilation as several prototypes changed) - -September 1rd, 2009 -! [Herve Drolon] changed prototypes for fipWinImage::setToneMappingOperator and fipWinImage::getToneMappingOperator -! [Herve Drolon] changed prototype for fipImage::toneMapping -! [Herve Drolon] changed prototype for fipImage::rotate (now support optional supplied background color) -+ [Herve Drolon] added FreeImage_TmoReinhard05Ex capability to fipImage & fipWinImage - -August 11th, 2009 -* [Mihail Naydenov] fixed fipImage::operator=(FIBITMAP *dib) for cases where dib == _dib - -July 10th, 2009 -+ [Herve Drolon] added fipImage::adjustBrightnessContrastGamma(double brightness, double contrast, double gamma) - -October 27th, 2008 -+ [Herve Drolon] added FIF static identification functions to fipImage - -August 3rd, 2008 -* [dimitriy.b] fixed warnings about "non virtual destructor with virtual class members" with gcc 4.1.2 -* [Herve Drolon] fixed display of RGBAF EXR images in fipWinImage::drawEx - -October 10th, 2007 -* [Terry Russell] fixed a memory leak in fipWinImage::captureWindow - -January 20th, 2007 -+ [Herve Drolon] added support for 64-bit RGBA images - -January 11th, 2007 -+ [Herve Drolon] added setKeyValue method (a ASCII tag constructor) to fipTag -+ [Herve Drolon] added PSD format support to fipMultiPage::open - -October 30th, 2006 - 3.9.2 -+ [Herve Drolon] added BOOL fipMultiPage::open(fipMemoryIO& memIO, int flags) -+ [Herve Drolon] added fipMemoryIO::operator FIMEMORY*() -* [Herve Drolon] fixed missing 'isValid' method in fipMetadataFind - -July 16th, 2006 - 3.9.1 -* [Herve Drolon] fixed a bug in fipWinImage::copyFromBitmap occuring with palettized images - -July 6th, 2006 - 3.9.0 -! [Herve Drolon] renamed fipMemoryIO::read to fipMemoryIO::load -! [Herve Drolon] renamed fipMemoryIO::write to fipMemoryIO::save -+ [Herve Drolon] added fipMemoryIO::read (wrapper for FreeImage_ReadMemory) -+ [Herve Drolon] added fipMemoryIO::write (wrapper for FreeImage_WriteMemory) -+ [Herve Drolon] added version info to the DLL -+ [Herve Drolon] added fipImage::crop -+ [Herve Drolon] added support for most image types to fipImage::rescale -+ [Herve Drolon] added fipImage::makeThumbnail -+ [Herve Drolon] added fipTag -+ [Herve Drolon] added fipMetadataFind -* [Sandor Szalacsi] improved fipWinWimage::drawEx behavior with non transparent PNG having a file background -* [Herve Drolon] fixed a bug in fipWinImage::setToneMappingOperator -* [Conrado PLG] added const keyword to fip methods -* [Conrado PLG] made the copy constructors of fipMemoryIO private - -September 5, 2005 - 3.8.0 -[Herve Drolon] -! fipImage::convertToGrayscale now uses FreeImage_ConvertToGreyscale -! fipWinImage::captureWindow now converts 32-bit images to 24-bit -+ added UNICODE function fipImage::loadU -+ added UNICODE function fipImage::saveU -+ added load flags to fipMultiPage::open -+ fipWinImage::copyTo/FromHandle now work with non-standard bitmap types -+ added copy constructors to fipWinImage -+ added fipImage::clear() and fipWinImage::clear() -* fixed a bug in fipWinWimage::drawEx with non transparent PNG having a file background -* fixed fipMultiPage not reading GIF files -* fixed a bug in fipImage::rescale whan handling FIT_UINT16 bitmaps - -May 3rd, 2005 -[Herve Drolon] -+ added accessors fipImage::setModified and fipImage::isModified -+ added fipImage::convertToRGBF -+ added fipImage::toneMapping -+ added tone mapping functions to fipWinImage (see get/setToneMappingOperator) -+ added tone mapping capabilities to fipWinImage::drawEx - -January 5th, 2005 -[Herve Drolon] -! changed the prototype of get/set Resolution functions - -December 19th, 2004 -[Herve Drolon] -! updated fipImage::rotate to handle 1-bit images - -November 18th, 2004 -[Herve Drolon] -+ added fipImage::convertTo4Bits - -August 18th, 2004 -[Herve Drolon] -- removed fipInternetIO -- removed copy constructor fipImage::fipImage(const FIBITMAP*) -- removed copy constructor fipWinImage::fipWinImage(const FIBITMAP*) -! fipMemoryIO rewritten. It now wraps the FreeImage memory stream API -! fipGenericImage is now called fipObject -+ added fipImage::loadFromMemory -+ added fipImage::saveToMemory -+ added fipMultiPage - -March, 17th, 2004 -[Herve Drolon] -! fipImage::setSize now accepts color masks -* fixed fipWinImage::copyFromHandle not working with DIB having color masks - -February 11th, 2004 -[Herve Drolon] -- removed fipImage::getRedChannel -- removed fipImage::getGreenChannel -- removed fipImage::getBlueChannel -- removed fipImage::getAlphaChannel -- removed fipImage::setAlphaChannel -+ added fipImage::setChannel -+ added fipImage::isTransparent -+ added fipImage::getTransparencyCount -+ added fipImage::getTransparencyTable -+ added fipImage::setTransparencyTable -+ added fipImage::hasFileBkColor -+ added fipImage::getFileBkColor -+ added fipImage::setFileBkColor -+ added fipWinImage::drawEx -! fipWinImage::draw now works with transparent images - -January 26th, 2004 -[Herve Drolon] -+ added fipMemoryIO -+ added fipInternetIO (WIN32 only) -+ added fipImage::getImageType -+ added fipImage::convertToType -+ added fipWinImage::copyToClipboard -+ added fipWinImage::pasteFromClipboard -+ added fipWinImage::captureWindow - -! changed fipImage constructor -! fipWinImage::copyFromHandle now returns a BOOL -! fipWinImage::copyFromBitmap now returns a BOOL - -November 2, 2003 -+ [Herve Drolon] added fipImage::getScanLine - -October 20, 2003 -* [Dennis Lim] fixed a bug in fipImage constructor -! [Herve Drolon] fixed a bug with fipImage::saveToHandle prototype - -September 8th 2003 - Wrapper for FreeImage 3.0.0 +What's New for FreeImagePlus + +* : fixed +- : removed +! : changed ++ : added + +July 17th, 2011 ++ [Herve Drolon] added fipImage::convertToRGB16 + +February 26th, 2011 ++ [Herve Drolon] added fipImage::convertToFloat + +November 14th, 2010 ++ [Herve Drolon] added getThumbnail, setThumbnail, hasThumbnail, clearThumbnail to fipImage + +November 7th, 2010 ++ [Herve Drolon] added fipImage::convertToUINT16 + +October 9th, 2010 +* [Herve Drolon] fixed fipWinImage::setToneMappingOperator when displaying RGBA HDR images + +April 18th, 2010 ++ [Herve Drolon] added new multi-page functions + added fipMemoryIO:close + added fipMemoryIO:loadMultiPage + added fipMemoryIO:saveMultiPage + added fipMultiPage:FIMULTIBITMAP* + added fipMultiPage:open(FreeImageIO *io, fi_handle handle, int flags = 0) + added fipMultiPage:saveToHandle + added fipMultiPage:saveToMemory + +October 24th, 2009 +! [Herve Drolon] fixed the '65535' width/height/pitch size limitation (need recompilation as several prototypes changed) + +September 1rd, 2009 +! [Herve Drolon] changed prototypes for fipWinImage::setToneMappingOperator and fipWinImage::getToneMappingOperator +! [Herve Drolon] changed prototype for fipImage::toneMapping +! [Herve Drolon] changed prototype for fipImage::rotate (now support optional supplied background color) ++ [Herve Drolon] added FreeImage_TmoReinhard05Ex capability to fipImage & fipWinImage + +August 11th, 2009 +* [Mihail Naydenov] fixed fipImage::operator=(FIBITMAP *dib) for cases where dib == _dib + +July 10th, 2009 ++ [Herve Drolon] added fipImage::adjustBrightnessContrastGamma(double brightness, double contrast, double gamma) + +October 27th, 2008 ++ [Herve Drolon] added FIF static identification functions to fipImage + +August 3rd, 2008 +* [dimitriy.b] fixed warnings about "non virtual destructor with virtual class members" with gcc 4.1.2 +* [Herve Drolon] fixed display of RGBAF EXR images in fipWinImage::drawEx + +October 10th, 2007 +* [Terry Russell] fixed a memory leak in fipWinImage::captureWindow + +January 20th, 2007 ++ [Herve Drolon] added support for 64-bit RGBA images + +January 11th, 2007 ++ [Herve Drolon] added setKeyValue method (a ASCII tag constructor) to fipTag ++ [Herve Drolon] added PSD format support to fipMultiPage::open + +October 30th, 2006 - 3.9.2 ++ [Herve Drolon] added BOOL fipMultiPage::open(fipMemoryIO& memIO, int flags) ++ [Herve Drolon] added fipMemoryIO::operator FIMEMORY*() +* [Herve Drolon] fixed missing 'isValid' method in fipMetadataFind + +July 16th, 2006 - 3.9.1 +* [Herve Drolon] fixed a bug in fipWinImage::copyFromBitmap occuring with palettized images + +July 6th, 2006 - 3.9.0 +! [Herve Drolon] renamed fipMemoryIO::read to fipMemoryIO::load +! [Herve Drolon] renamed fipMemoryIO::write to fipMemoryIO::save ++ [Herve Drolon] added fipMemoryIO::read (wrapper for FreeImage_ReadMemory) ++ [Herve Drolon] added fipMemoryIO::write (wrapper for FreeImage_WriteMemory) ++ [Herve Drolon] added version info to the DLL ++ [Herve Drolon] added fipImage::crop ++ [Herve Drolon] added support for most image types to fipImage::rescale ++ [Herve Drolon] added fipImage::makeThumbnail ++ [Herve Drolon] added fipTag ++ [Herve Drolon] added fipMetadataFind +* [Sandor Szalacsi] improved fipWinWimage::drawEx behavior with non transparent PNG having a file background +* [Herve Drolon] fixed a bug in fipWinImage::setToneMappingOperator +* [Conrado PLG] added const keyword to fip methods +* [Conrado PLG] made the copy constructors of fipMemoryIO private + +September 5, 2005 - 3.8.0 +[Herve Drolon] +! fipImage::convertToGrayscale now uses FreeImage_ConvertToGreyscale +! fipWinImage::captureWindow now converts 32-bit images to 24-bit ++ added UNICODE function fipImage::loadU ++ added UNICODE function fipImage::saveU ++ added load flags to fipMultiPage::open ++ fipWinImage::copyTo/FromHandle now work with non-standard bitmap types ++ added copy constructors to fipWinImage ++ added fipImage::clear() and fipWinImage::clear() +* fixed a bug in fipWinWimage::drawEx with non transparent PNG having a file background +* fixed fipMultiPage not reading GIF files +* fixed a bug in fipImage::rescale whan handling FIT_UINT16 bitmaps + +May 3rd, 2005 +[Herve Drolon] ++ added accessors fipImage::setModified and fipImage::isModified ++ added fipImage::convertToRGBF ++ added fipImage::toneMapping ++ added tone mapping functions to fipWinImage (see get/setToneMappingOperator) ++ added tone mapping capabilities to fipWinImage::drawEx + +January 5th, 2005 +[Herve Drolon] +! changed the prototype of get/set Resolution functions + +December 19th, 2004 +[Herve Drolon] +! updated fipImage::rotate to handle 1-bit images + +November 18th, 2004 +[Herve Drolon] ++ added fipImage::convertTo4Bits + +August 18th, 2004 +[Herve Drolon] +- removed fipInternetIO +- removed copy constructor fipImage::fipImage(const FIBITMAP*) +- removed copy constructor fipWinImage::fipWinImage(const FIBITMAP*) +! fipMemoryIO rewritten. It now wraps the FreeImage memory stream API +! fipGenericImage is now called fipObject ++ added fipImage::loadFromMemory ++ added fipImage::saveToMemory ++ added fipMultiPage + +March, 17th, 2004 +[Herve Drolon] +! fipImage::setSize now accepts color masks +* fixed fipWinImage::copyFromHandle not working with DIB having color masks + +February 11th, 2004 +[Herve Drolon] +- removed fipImage::getRedChannel +- removed fipImage::getGreenChannel +- removed fipImage::getBlueChannel +- removed fipImage::getAlphaChannel +- removed fipImage::setAlphaChannel ++ added fipImage::setChannel ++ added fipImage::isTransparent ++ added fipImage::getTransparencyCount ++ added fipImage::getTransparencyTable ++ added fipImage::setTransparencyTable ++ added fipImage::hasFileBkColor ++ added fipImage::getFileBkColor ++ added fipImage::setFileBkColor ++ added fipWinImage::drawEx +! fipWinImage::draw now works with transparent images + +January 26th, 2004 +[Herve Drolon] ++ added fipMemoryIO ++ added fipInternetIO (WIN32 only) ++ added fipImage::getImageType ++ added fipImage::convertToType ++ added fipWinImage::copyToClipboard ++ added fipWinImage::pasteFromClipboard ++ added fipWinImage::captureWindow + +! changed fipImage constructor +! fipWinImage::copyFromHandle now returns a BOOL +! fipWinImage::copyFromBitmap now returns a BOOL + +November 2, 2003 ++ [Herve Drolon] added fipImage::getScanLine + +October 20, 2003 +* [Dennis Lim] fixed a bug in fipImage constructor +! [Herve Drolon] fixed a bug with fipImage::saveToHandle prototype + +September 8th 2003 - Wrapper for FreeImage 3.0.0 diff --git a/Wrapper/FreeImagePlus/doc/footer.html b/Wrapper/FreeImagePlus/doc/footer.html index ed36a62..5c88d31 100644 --- a/Wrapper/FreeImagePlus/doc/footer.html +++ b/Wrapper/FreeImagePlus/doc/footer.html @@ -1,7 +1,7 @@ -
    -

    -
    -

    - - - +
    +

    +
    +

    + + + diff --git a/Wrapper/FreeImagePlus/src/FreeImagePlus.cpp b/Wrapper/FreeImagePlus/src/FreeImagePlus.cpp index d9bc99e..efb8fe9 100644 --- a/Wrapper/FreeImagePlus/src/FreeImagePlus.cpp +++ b/Wrapper/FreeImagePlus/src/FreeImagePlus.cpp @@ -1,46 +1,46 @@ -// ========================================================== -// FreeImagePlus.cpp : Defines the entry point for the DLL application. -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#ifdef _WIN32 -#include -#endif // _WIN32 - -#include "FreeImagePlus.h" - -//---------------------------------------------------------------------- - -#ifdef _WIN32 - -BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) -{ - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - return TRUE; -} - - -#endif // _WIN32 +// ========================================================== +// FreeImagePlus.cpp : Defines the entry point for the DLL application. +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#ifdef _WIN32 +#include +#endif // _WIN32 + +#include "FreeImagePlus.h" + +//---------------------------------------------------------------------- + +#ifdef _WIN32 + +BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + + +#endif // _WIN32 diff --git a/Wrapper/FreeImagePlus/src/fipImage.cpp b/Wrapper/FreeImagePlus/src/fipImage.cpp index a5b41bd..85ad2e2 100644 --- a/Wrapper/FreeImagePlus/src/fipImage.cpp +++ b/Wrapper/FreeImagePlus/src/fipImage.cpp @@ -1,954 +1,954 @@ -// ========================================================== -// fipImage class implementation -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImagePlus.h" - -/////////////////////////////////////////////////////////////////// -// Protected functions - -BOOL fipImage::replace(FIBITMAP *new_dib) { - if(new_dib == NULL) - return FALSE; - if(_dib) - FreeImage_Unload(_dib); - _dib = new_dib; - _bHasChanged = TRUE; - return TRUE; -} - -/////////////////////////////////////////////////////////////////// -// Creation & Destruction - -fipImage::fipImage(FREE_IMAGE_TYPE image_type, unsigned width, unsigned height, unsigned bpp) { - _dib = NULL; - _bHasChanged = FALSE; - if(width && height && bpp) - setSize(image_type, width, height, bpp); -} - -fipImage::~fipImage() { - if(_dib) { - FreeImage_Unload(_dib); - _dib = NULL; - } -} - -BOOL fipImage::setSize(FREE_IMAGE_TYPE image_type, unsigned width, unsigned height, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask) { - if(_dib) { - FreeImage_Unload(_dib); - } - if((_dib = FreeImage_AllocateT(image_type, width, height, bpp, red_mask, green_mask, blue_mask)) == NULL) - return FALSE; - - if(image_type == FIT_BITMAP) { - // Create palette if needed - switch(bpp) { - case 1: - case 4: - case 8: - RGBQUAD *pal = FreeImage_GetPalette(_dib); - for(unsigned i = 0; i < FreeImage_GetColorsUsed(_dib); i++) { - pal[i].rgbRed = i; - pal[i].rgbGreen = i; - pal[i].rgbBlue = i; - } - break; - } - } - - _bHasChanged = TRUE; - - return TRUE; -} - -void fipImage::clear() { - if(_dib) { - FreeImage_Unload(_dib); - _dib = NULL; - } - _bHasChanged = TRUE; -} - -/////////////////////////////////////////////////////////////////// -// Copying - -fipImage::fipImage(const fipImage& Image) { - _dib = NULL; - _fif = FIF_UNKNOWN; - FIBITMAP *clone = FreeImage_Clone((FIBITMAP*)Image._dib); - replace(clone); -} - -fipImage& fipImage::operator=(const fipImage& Image) { - if(this != &Image) { - FIBITMAP *clone = FreeImage_Clone((FIBITMAP*)Image._dib); - replace(clone); - } - return *this; -} - -fipImage& fipImage::operator=(FIBITMAP *dib) { - if(_dib != dib) { - replace(dib); - } - return *this; -} - -BOOL fipImage::copySubImage(fipImage& dst, int left, int top, int right, int bottom) const { - if(_dib) { - dst = FreeImage_Copy(_dib, left, top, right, bottom); - return dst.isValid(); - } - return FALSE; -} - -BOOL fipImage::pasteSubImage(fipImage& src, int left, int top, int alpha) { - if(_dib) { - BOOL bResult = FreeImage_Paste(_dib, src._dib, left, top, alpha); - _bHasChanged = TRUE; - return bResult; - } - return FALSE; -} - -BOOL fipImage::crop(int left, int top, int right, int bottom) { - if(_dib) { - FIBITMAP *dst = FreeImage_Copy(_dib, left, top, right, bottom); - return replace(dst); - } - return FALSE; -} - - -/////////////////////////////////////////////////////////////////// -// Information functions - -FREE_IMAGE_TYPE fipImage::getImageType() const { - return FreeImage_GetImageType(_dib); -} - -unsigned fipImage::getWidth() const { - return FreeImage_GetWidth(_dib); -} - -unsigned fipImage::getHeight() const { - return FreeImage_GetHeight(_dib); -} - -unsigned fipImage::getScanWidth() const { - return FreeImage_GetPitch(_dib); -} - -BOOL fipImage::isValid() const { - return (_dib != NULL) ? TRUE:FALSE; -} - -BITMAPINFO* fipImage::getInfo() const { - return FreeImage_GetInfo(_dib); -} - -BITMAPINFOHEADER* fipImage::getInfoHeader() const { - return FreeImage_GetInfoHeader(_dib); -} - -LONG fipImage::getImageSize() const { - return FreeImage_GetDIBSize(_dib); -} - -unsigned fipImage::getBitsPerPixel() const { - return FreeImage_GetBPP(_dib); -} - -unsigned fipImage::getLine() const { - return FreeImage_GetLine(_dib); -} - -double fipImage::getHorizontalResolution() const { - return (FreeImage_GetDotsPerMeterX(_dib) / (double)100); -} - -double fipImage::getVerticalResolution() const { - return (FreeImage_GetDotsPerMeterY(_dib) / (double)100); -} - -void fipImage::setHorizontalResolution(double value) { - FreeImage_SetDotsPerMeterX(_dib, (unsigned)(value * 100 + 0.5)); -} - -void fipImage::setVerticalResolution(double value) { - FreeImage_SetDotsPerMeterY(_dib, (unsigned)(value * 100 + 0.5)); -} - - -/////////////////////////////////////////////////////////////////// -// Palette operations - -RGBQUAD* fipImage::getPalette() const { - return FreeImage_GetPalette(_dib); -} - -unsigned fipImage::getPaletteSize() const { - return FreeImage_GetColorsUsed(_dib) * sizeof(RGBQUAD); -} - -unsigned fipImage::getColorsUsed() const { - return FreeImage_GetColorsUsed(_dib); -} - -FREE_IMAGE_COLOR_TYPE fipImage::getColorType() const { - return FreeImage_GetColorType(_dib); -} - -BOOL fipImage::isGrayscale() const { - return ((FreeImage_GetBPP(_dib) == 8) && (FreeImage_GetColorType(_dib) != FIC_PALETTE)); -} - -/////////////////////////////////////////////////////////////////// -// Thumbnail access - -BOOL fipImage::getThumbnail(fipImage& image) const { - image = FreeImage_Clone( FreeImage_GetThumbnail(_dib) ); - return image.isValid(); -} - -BOOL fipImage::setThumbnail(const fipImage& image) { - return FreeImage_SetThumbnail(_dib, (FIBITMAP*)image._dib); -} - -BOOL fipImage::hasThumbnail() const { - return (FreeImage_GetThumbnail(_dib) != NULL); -} - -BOOL fipImage::clearThumbnail() { - return FreeImage_SetThumbnail(_dib, NULL); -} - - -/////////////////////////////////////////////////////////////////// -// Pixel access - -BYTE* fipImage::accessPixels() const { - return FreeImage_GetBits(_dib); -} - -BYTE* fipImage::getScanLine(unsigned scanline) const { - if(scanline < FreeImage_GetHeight(_dib)) { - return FreeImage_GetScanLine(_dib, scanline); - } - return NULL; -} - -BOOL fipImage::getPixelIndex(unsigned x, unsigned y, BYTE *value) const { - return FreeImage_GetPixelIndex(_dib, x, y, value); -} - -BOOL fipImage::getPixelColor(unsigned x, unsigned y, RGBQUAD *value) const { - return FreeImage_GetPixelColor(_dib, x, y, value); -} - -BOOL fipImage::setPixelIndex(unsigned x, unsigned y, BYTE *value) { - _bHasChanged = TRUE; - return FreeImage_SetPixelIndex(_dib, x, y, value); -} - -BOOL fipImage::setPixelColor(unsigned x, unsigned y, RGBQUAD *value) { - _bHasChanged = TRUE; - return FreeImage_SetPixelColor(_dib, x, y, value); -} - -/////////////////////////////////////////////////////////////////// -// File type identification - -FREE_IMAGE_FORMAT fipImage::identifyFIF(const char* lpszPathName) { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - - // check the file signature and get its format - // (the second argument is currently not used by FreeImage) - fif = FreeImage_GetFileType(lpszPathName, 0); - if(fif == FIF_UNKNOWN) { - // no signature ? - // try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilename(lpszPathName); - } - - return fif; -} - -FREE_IMAGE_FORMAT fipImage::identifyFIFU(const wchar_t* lpszPathName) { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - - // check the file signature and get its format - // (the second argument is currently not used by FreeImage) - fif = FreeImage_GetFileTypeU(lpszPathName, 0); - if(fif == FIF_UNKNOWN) { - // no signature ? - // try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilenameU(lpszPathName); - } - - return fif; -} - -FREE_IMAGE_FORMAT fipImage::identifyFIFFromHandle(FreeImageIO *io, fi_handle handle) { - if(io && handle) { - // check the file signature and get its format - return FreeImage_GetFileTypeFromHandle(io, handle, 16); - } - return FIF_UNKNOWN; -} - -FREE_IMAGE_FORMAT fipImage::identifyFIFFromMemory(FIMEMORY *hmem) { - if(hmem != NULL) { - return FreeImage_GetFileTypeFromMemory(hmem, 0); - } - return FIF_UNKNOWN; -} - - -/////////////////////////////////////////////////////////////////// -// Loading & Saving - -BOOL fipImage::load(const char* lpszPathName, int flag) { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - - // check the file signature and get its format - // (the second argument is currently not used by FreeImage) - fif = FreeImage_GetFileType(lpszPathName, 0); - if(fif == FIF_UNKNOWN) { - // no signature ? - // try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilename(lpszPathName); - } - // check that the plugin has reading capabilities ... - if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { - // Free the previous dib - if(_dib) { - FreeImage_Unload(_dib); - } - // Load the file - _dib = FreeImage_Load(fif, lpszPathName, flag); - _bHasChanged = TRUE; - if(_dib == NULL) - return FALSE; - return TRUE; - } - return FALSE; -} - -BOOL fipImage::loadU(const wchar_t* lpszPathName, int flag) { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - - // check the file signature and get its format - // (the second argument is currently not used by FreeImage) - fif = FreeImage_GetFileTypeU(lpszPathName, 0); - if(fif == FIF_UNKNOWN) { - // no signature ? - // try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilenameU(lpszPathName); - } - // check that the plugin has reading capabilities ... - if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { - // Free the previous dib - if(_dib) { - FreeImage_Unload(_dib); - } - // Load the file - _dib = FreeImage_LoadU(fif, lpszPathName, flag); - _bHasChanged = TRUE; - if(_dib == NULL) - return FALSE; - return TRUE; - } - return FALSE; -} - -BOOL fipImage::loadFromHandle(FreeImageIO *io, fi_handle handle, int flag) { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - - // check the file signature and get its format - fif = FreeImage_GetFileTypeFromHandle(io, handle, 16); - if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { - // Free the previous dib - if(_dib) { - FreeImage_Unload(_dib); - } - // Load the file - _dib = FreeImage_LoadFromHandle(fif, io, handle, flag); - _bHasChanged = TRUE; - if(_dib == NULL) - return FALSE; - return TRUE; - } - return FALSE; -} - -BOOL fipImage::loadFromMemory(fipMemoryIO& memIO, int flag) { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - - // check the file signature and get its format - fif = memIO.getFileType(); - if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { - // Free the previous dib - if(_dib) { - FreeImage_Unload(_dib); - } - // Load the file - _dib = memIO.load(fif, flag); - _bHasChanged = TRUE; - if(_dib == NULL) - return FALSE; - return TRUE; - } - return FALSE; -} - -BOOL fipImage::save(const char* lpszPathName, int flag) const { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - BOOL bSuccess = FALSE; - - // Try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilename(lpszPathName); - if(fif != FIF_UNKNOWN ) { - // Check that the dib can be saved in this format - BOOL bCanSave; - - FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(_dib); - if(image_type == FIT_BITMAP) { - // standard bitmap type - WORD bpp = FreeImage_GetBPP(_dib); - bCanSave = (FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)); - } else { - // special bitmap type - bCanSave = FreeImage_FIFSupportsExportType(fif, image_type); - } - - if(bCanSave) { - bSuccess = FreeImage_Save(fif, _dib, lpszPathName, flag); - return bSuccess; - } - } - return bSuccess; -} - -BOOL fipImage::saveU(const wchar_t* lpszPathName, int flag) const { - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - BOOL bSuccess = FALSE; - - // Try to guess the file format from the file extension - fif = FreeImage_GetFIFFromFilenameU(lpszPathName); - if(fif != FIF_UNKNOWN ) { - // Check that the dib can be saved in this format - BOOL bCanSave; - - FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(_dib); - if(image_type == FIT_BITMAP) { - // standard bitmap type - WORD bpp = FreeImage_GetBPP(_dib); - bCanSave = (FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)); - } else { - // special bitmap type - bCanSave = FreeImage_FIFSupportsExportType(fif, image_type); - } - - if(bCanSave) { - bSuccess = FreeImage_SaveU(fif, _dib, lpszPathName, flag); - return bSuccess; - } - } - return bSuccess; -} - -BOOL fipImage::saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flag) const { - BOOL bSuccess = FALSE; - - if(fif != FIF_UNKNOWN ) { - // Check that the dib can be saved in this format - BOOL bCanSave; - - FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(_dib); - if(image_type == FIT_BITMAP) { - // standard bitmap type - WORD bpp = FreeImage_GetBPP(_dib); - bCanSave = (FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)); - } else { - // special bitmap type - bCanSave = FreeImage_FIFSupportsExportType(fif, image_type); - } - - if(bCanSave) { - bSuccess = FreeImage_SaveToHandle(fif, _dib, io, handle, flag); - return bSuccess; - } - } - return bSuccess; -} - -BOOL fipImage::saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flag) const { - BOOL bSuccess = FALSE; - - if(fif != FIF_UNKNOWN ) { - // Check that the dib can be saved in this format - BOOL bCanSave; - - FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(_dib); - if(image_type == FIT_BITMAP) { - // standard bitmap type - WORD bpp = FreeImage_GetBPP(_dib); - bCanSave = (FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)); - } else { - // special bitmap type - bCanSave = FreeImage_FIFSupportsExportType(fif, image_type); - } - - if(bCanSave) { - bSuccess = memIO.save(fif, _dib, flag); - return bSuccess; - } - } - return bSuccess; -} - -/////////////////////////////////////////////////////////////////// -// Conversion routines - -BOOL fipImage::convertToType(FREE_IMAGE_TYPE image_type, BOOL scale_linear) { - if(_dib) { - FIBITMAP *dib = FreeImage_ConvertToType(_dib, image_type, scale_linear); - return replace(dib); - } - return FALSE; -} - -BOOL fipImage::threshold(BYTE T) { - if(_dib) { - FIBITMAP *dib1 = FreeImage_Threshold(_dib, T); - return replace(dib1); - } - return FALSE; -} - -BOOL fipImage::convertTo4Bits() { - if(_dib) { - FIBITMAP *dib4 = FreeImage_ConvertTo4Bits(_dib); - return replace(dib4); - } - return FALSE; -} - -BOOL fipImage::convertTo8Bits() { - if(_dib) { - FIBITMAP *dib8 = FreeImage_ConvertTo8Bits(_dib); - return replace(dib8); - } - return FALSE; -} - -BOOL fipImage::convertTo16Bits555() { - if(_dib) { - FIBITMAP *dib16_555 = FreeImage_ConvertTo16Bits555(_dib); - return replace(dib16_555); - } - return FALSE; -} - -BOOL fipImage::convertTo16Bits565() { - if(_dib) { - FIBITMAP *dib16_565 = FreeImage_ConvertTo16Bits565(_dib); - return replace(dib16_565); - } - return FALSE; -} - -BOOL fipImage::convertTo24Bits() { - if(_dib) { - FIBITMAP *dibRGB = FreeImage_ConvertTo24Bits(_dib); - return replace(dibRGB); - } - return FALSE; -} - -BOOL fipImage::convertTo32Bits() { - if(_dib) { - FIBITMAP *dib32 = FreeImage_ConvertTo32Bits(_dib); - return replace(dib32); - } - return FALSE; -} - -BOOL fipImage::convertToGrayscale() { - if(_dib) { - FIBITMAP *dib8 = FreeImage_ConvertToGreyscale(_dib); - return replace(dib8); - } - return FALSE; -} - -BOOL fipImage::colorQuantize(FREE_IMAGE_QUANTIZE algorithm) { - if(_dib) { - FIBITMAP *dib8 = FreeImage_ColorQuantize(_dib, algorithm); - return replace(dib8); - } - return FALSE; -} - -BOOL fipImage::dither(FREE_IMAGE_DITHER algorithm) { - if(_dib) { - FIBITMAP *dib = FreeImage_Dither(_dib, algorithm); - return replace(dib); - } - return FALSE; -} - -BOOL fipImage::convertToFloat() { - if(_dib) { - FIBITMAP *dib = FreeImage_ConvertToFloat(_dib); - return replace(dib); - } - return FALSE; -} - -BOOL fipImage::convertToRGBF() { - if(_dib) { - FIBITMAP *dib = FreeImage_ConvertToRGBF(_dib); - return replace(dib); - } - return FALSE; -} - -BOOL fipImage::convertToUINT16() { - if(_dib) { - FIBITMAP *dib = FreeImage_ConvertToUINT16(_dib); - return replace(dib); - } - return FALSE; -} - -BOOL fipImage::convertToRGB16() { - if(_dib) { - FIBITMAP *dib = FreeImage_ConvertToRGB16(_dib); - return replace(dib); - } - return FALSE; -} - -BOOL fipImage::toneMapping(FREE_IMAGE_TMO tmo, double first_param, double second_param, double third_param, double fourth_param) { - if(_dib) { - FIBITMAP *dst = NULL; - // Apply a tone mapping algorithm and convert to 24-bit - switch(tmo) { - case FITMO_REINHARD05: - dst = FreeImage_TmoReinhard05Ex(_dib, first_param, second_param, third_param, fourth_param); - break; - default: - dst = FreeImage_ToneMapping(_dib, tmo, first_param, second_param); - break; - } - - return replace(dst); - } - return FALSE; -} - -/////////////////////////////////////////////////////////////////// -// Transparency support: background colour and alpha channel - -BOOL fipImage::isTransparent() const { - return FreeImage_IsTransparent(_dib); -} - -unsigned fipImage::getTransparencyCount() const { - return FreeImage_GetTransparencyCount(_dib); -} - -BYTE* fipImage::getTransparencyTable() const { - return FreeImage_GetTransparencyTable(_dib); -} - -void fipImage::setTransparencyTable(BYTE *table, int count) { - FreeImage_SetTransparencyTable(_dib, table, count); - _bHasChanged = TRUE; -} - -BOOL fipImage::hasFileBkColor() const { - return FreeImage_HasBackgroundColor(_dib); -} - -BOOL fipImage::getFileBkColor(RGBQUAD *bkcolor) const { - return FreeImage_GetBackgroundColor(_dib, bkcolor); -} - -BOOL fipImage::setFileBkColor(RGBQUAD *bkcolor) { - _bHasChanged = TRUE; - return FreeImage_SetBackgroundColor(_dib, bkcolor); -} - -/////////////////////////////////////////////////////////////////// -// Channel processing support - -BOOL fipImage::getChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel) const { - if(_dib) { - image = FreeImage_GetChannel(_dib, channel); - return image.isValid(); - } - return FALSE; -} - -BOOL fipImage::setChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel) { - if(_dib) { - _bHasChanged = TRUE; - return FreeImage_SetChannel(_dib, image._dib, channel); - } - return FALSE; -} - -BOOL fipImage::splitChannels(fipImage& RedChannel, fipImage& GreenChannel, fipImage& BlueChannel) { - if(_dib) { - RedChannel = FreeImage_GetChannel(_dib, FICC_RED); - GreenChannel = FreeImage_GetChannel(_dib, FICC_GREEN); - BlueChannel = FreeImage_GetChannel(_dib, FICC_BLUE); - - return (RedChannel.isValid() && GreenChannel.isValid() && BlueChannel.isValid()); - } - return FALSE; -} - -BOOL fipImage::combineChannels(fipImage& red, fipImage& green, fipImage& blue) { - if(!_dib) { - int width = red.getWidth(); - int height = red.getHeight(); - _dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - } - - if(_dib) { - BOOL bResult = TRUE; - bResult &= FreeImage_SetChannel(_dib, red._dib, FICC_RED); - bResult &= FreeImage_SetChannel(_dib, green._dib, FICC_GREEN); - bResult &= FreeImage_SetChannel(_dib, blue._dib, FICC_BLUE); - - _bHasChanged = TRUE; - - return bResult; - } - return FALSE; -} - -/////////////////////////////////////////////////////////////////// -// Rotation and flipping - -BOOL fipImage::rotateEx(double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask) { - if(_dib) { - if(FreeImage_GetBPP(_dib) >= 8) { - FIBITMAP *rotated = FreeImage_RotateEx(_dib, angle, x_shift, y_shift, x_origin, y_origin, use_mask); - return replace(rotated); - } - } - return FALSE; -} - -BOOL fipImage::rotate(double angle, const void *bkcolor) { - if(_dib) { - switch(FreeImage_GetImageType(_dib)) { - case FIT_BITMAP: - switch(FreeImage_GetBPP(_dib)) { - case 1: - case 8: - case 24: - case 32: - break; - default: - return FALSE; - } - break; - - case FIT_UINT16: - case FIT_RGB16: - case FIT_RGBA16: - case FIT_FLOAT: - case FIT_RGBF: - case FIT_RGBAF: - break; - default: - return FALSE; - break; - } - - FIBITMAP *rotated = FreeImage_Rotate(_dib, angle, bkcolor); - return replace(rotated); - - } - return FALSE; -} - -BOOL fipImage::flipVertical() { - if(_dib) { - _bHasChanged = TRUE; - - return FreeImage_FlipVertical(_dib); - } - return FALSE; -} - -BOOL fipImage::flipHorizontal() { - if(_dib) { - _bHasChanged = TRUE; - - return FreeImage_FlipHorizontal(_dib); - } - return FALSE; -} - -/////////////////////////////////////////////////////////////////// -// Color manipulation routines - -BOOL fipImage::invert() { - if(_dib) { - _bHasChanged = TRUE; - - return FreeImage_Invert(_dib); - } - return FALSE; -} - -BOOL fipImage::adjustCurve(BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel) { - if(_dib) { - _bHasChanged = TRUE; - - return FreeImage_AdjustCurve(_dib, LUT, channel); - } - return FALSE; -} - -BOOL fipImage::adjustGamma(double gamma) { - if(_dib) { - _bHasChanged = TRUE; - - return FreeImage_AdjustGamma(_dib, gamma); - } - return FALSE; -} - -BOOL fipImage::adjustBrightness(double percentage) { - if(_dib) { - _bHasChanged = TRUE; - - return FreeImage_AdjustBrightness(_dib, percentage); - } - return FALSE; -} - -BOOL fipImage::adjustContrast(double percentage) { - if(_dib) { - _bHasChanged = TRUE; - - return FreeImage_AdjustContrast(_dib, percentage); - } - return FALSE; -} - -BOOL fipImage::adjustBrightnessContrastGamma(double brightness, double contrast, double gamma) { - if(_dib) { - _bHasChanged = TRUE; - - return FreeImage_AdjustColors(_dib, brightness, contrast, gamma, FALSE); - } - return FALSE; -} - -BOOL fipImage::getHistogram(DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel) const { - if(_dib) { - return FreeImage_GetHistogram(_dib, histo, channel); - } - return FALSE; -} - -/////////////////////////////////////////////////////////////////// -// Upsampling / downsampling routine - -BOOL fipImage::rescale(unsigned new_width, unsigned new_height, FREE_IMAGE_FILTER filter) { - if(_dib) { - switch(FreeImage_GetImageType(_dib)) { - case FIT_BITMAP: - case FIT_UINT16: - case FIT_RGB16: - case FIT_RGBA16: - case FIT_FLOAT: - case FIT_RGBF: - case FIT_RGBAF: - break; - default: - return FALSE; - break; - } - - // Perform upsampling / downsampling - FIBITMAP *dst = FreeImage_Rescale(_dib, new_width, new_height, filter); - return replace(dst); - } - return FALSE; -} - -BOOL fipImage::makeThumbnail(unsigned max_size, BOOL convert) { - if(_dib) { - switch(FreeImage_GetImageType(_dib)) { - case FIT_BITMAP: - case FIT_UINT16: - case FIT_RGB16: - case FIT_RGBA16: - case FIT_FLOAT: - case FIT_RGBF: - case FIT_RGBAF: - break; - default: - return FALSE; - break; - } - - // Perform downsampling - FIBITMAP *dst = FreeImage_MakeThumbnail(_dib, max_size, convert); - return replace(dst); - } - return FALSE; -} - -/////////////////////////////////////////////////////////////////// -// Metadata - -unsigned fipImage::getMetadataCount(FREE_IMAGE_MDMODEL model) const { - return FreeImage_GetMetadataCount(model, _dib); -} - -BOOL fipImage::getMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag) const { - FITAG *searchedTag = NULL; - FreeImage_GetMetadata(model, _dib, key, &searchedTag); - if(searchedTag != NULL) { - tag = FreeImage_CloneTag(searchedTag); - return TRUE; - } else { - // clear the tag - tag = (FITAG*)NULL; - } - return FALSE; -} - -BOOL fipImage::setMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag) { - return FreeImage_SetMetadata(model, _dib, key, tag); -} - +// ========================================================== +// fipImage class implementation +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImagePlus.h" + +/////////////////////////////////////////////////////////////////// +// Protected functions + +BOOL fipImage::replace(FIBITMAP *new_dib) { + if(new_dib == NULL) + return FALSE; + if(_dib) + FreeImage_Unload(_dib); + _dib = new_dib; + _bHasChanged = TRUE; + return TRUE; +} + +/////////////////////////////////////////////////////////////////// +// Creation & Destruction + +fipImage::fipImage(FREE_IMAGE_TYPE image_type, unsigned width, unsigned height, unsigned bpp) { + _dib = NULL; + _bHasChanged = FALSE; + if(width && height && bpp) + setSize(image_type, width, height, bpp); +} + +fipImage::~fipImage() { + if(_dib) { + FreeImage_Unload(_dib); + _dib = NULL; + } +} + +BOOL fipImage::setSize(FREE_IMAGE_TYPE image_type, unsigned width, unsigned height, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask) { + if(_dib) { + FreeImage_Unload(_dib); + } + if((_dib = FreeImage_AllocateT(image_type, width, height, bpp, red_mask, green_mask, blue_mask)) == NULL) + return FALSE; + + if(image_type == FIT_BITMAP) { + // Create palette if needed + switch(bpp) { + case 1: + case 4: + case 8: + RGBQUAD *pal = FreeImage_GetPalette(_dib); + for(unsigned i = 0; i < FreeImage_GetColorsUsed(_dib); i++) { + pal[i].rgbRed = i; + pal[i].rgbGreen = i; + pal[i].rgbBlue = i; + } + break; + } + } + + _bHasChanged = TRUE; + + return TRUE; +} + +void fipImage::clear() { + if(_dib) { + FreeImage_Unload(_dib); + _dib = NULL; + } + _bHasChanged = TRUE; +} + +/////////////////////////////////////////////////////////////////// +// Copying + +fipImage::fipImage(const fipImage& Image) { + _dib = NULL; + _fif = FIF_UNKNOWN; + FIBITMAP *clone = FreeImage_Clone((FIBITMAP*)Image._dib); + replace(clone); +} + +fipImage& fipImage::operator=(const fipImage& Image) { + if(this != &Image) { + FIBITMAP *clone = FreeImage_Clone((FIBITMAP*)Image._dib); + replace(clone); + } + return *this; +} + +fipImage& fipImage::operator=(FIBITMAP *dib) { + if(_dib != dib) { + replace(dib); + } + return *this; +} + +BOOL fipImage::copySubImage(fipImage& dst, int left, int top, int right, int bottom) const { + if(_dib) { + dst = FreeImage_Copy(_dib, left, top, right, bottom); + return dst.isValid(); + } + return FALSE; +} + +BOOL fipImage::pasteSubImage(fipImage& src, int left, int top, int alpha) { + if(_dib) { + BOOL bResult = FreeImage_Paste(_dib, src._dib, left, top, alpha); + _bHasChanged = TRUE; + return bResult; + } + return FALSE; +} + +BOOL fipImage::crop(int left, int top, int right, int bottom) { + if(_dib) { + FIBITMAP *dst = FreeImage_Copy(_dib, left, top, right, bottom); + return replace(dst); + } + return FALSE; +} + + +/////////////////////////////////////////////////////////////////// +// Information functions + +FREE_IMAGE_TYPE fipImage::getImageType() const { + return FreeImage_GetImageType(_dib); +} + +unsigned fipImage::getWidth() const { + return FreeImage_GetWidth(_dib); +} + +unsigned fipImage::getHeight() const { + return FreeImage_GetHeight(_dib); +} + +unsigned fipImage::getScanWidth() const { + return FreeImage_GetPitch(_dib); +} + +BOOL fipImage::isValid() const { + return (_dib != NULL) ? TRUE:FALSE; +} + +BITMAPINFO* fipImage::getInfo() const { + return FreeImage_GetInfo(_dib); +} + +BITMAPINFOHEADER* fipImage::getInfoHeader() const { + return FreeImage_GetInfoHeader(_dib); +} + +LONG fipImage::getImageSize() const { + return FreeImage_GetDIBSize(_dib); +} + +unsigned fipImage::getBitsPerPixel() const { + return FreeImage_GetBPP(_dib); +} + +unsigned fipImage::getLine() const { + return FreeImage_GetLine(_dib); +} + +double fipImage::getHorizontalResolution() const { + return (FreeImage_GetDotsPerMeterX(_dib) / (double)100); +} + +double fipImage::getVerticalResolution() const { + return (FreeImage_GetDotsPerMeterY(_dib) / (double)100); +} + +void fipImage::setHorizontalResolution(double value) { + FreeImage_SetDotsPerMeterX(_dib, (unsigned)(value * 100 + 0.5)); +} + +void fipImage::setVerticalResolution(double value) { + FreeImage_SetDotsPerMeterY(_dib, (unsigned)(value * 100 + 0.5)); +} + + +/////////////////////////////////////////////////////////////////// +// Palette operations + +RGBQUAD* fipImage::getPalette() const { + return FreeImage_GetPalette(_dib); +} + +unsigned fipImage::getPaletteSize() const { + return FreeImage_GetColorsUsed(_dib) * sizeof(RGBQUAD); +} + +unsigned fipImage::getColorsUsed() const { + return FreeImage_GetColorsUsed(_dib); +} + +FREE_IMAGE_COLOR_TYPE fipImage::getColorType() const { + return FreeImage_GetColorType(_dib); +} + +BOOL fipImage::isGrayscale() const { + return ((FreeImage_GetBPP(_dib) == 8) && (FreeImage_GetColorType(_dib) != FIC_PALETTE)); +} + +/////////////////////////////////////////////////////////////////// +// Thumbnail access + +BOOL fipImage::getThumbnail(fipImage& image) const { + image = FreeImage_Clone( FreeImage_GetThumbnail(_dib) ); + return image.isValid(); +} + +BOOL fipImage::setThumbnail(const fipImage& image) { + return FreeImage_SetThumbnail(_dib, (FIBITMAP*)image._dib); +} + +BOOL fipImage::hasThumbnail() const { + return (FreeImage_GetThumbnail(_dib) != NULL); +} + +BOOL fipImage::clearThumbnail() { + return FreeImage_SetThumbnail(_dib, NULL); +} + + +/////////////////////////////////////////////////////////////////// +// Pixel access + +BYTE* fipImage::accessPixels() const { + return FreeImage_GetBits(_dib); +} + +BYTE* fipImage::getScanLine(unsigned scanline) const { + if(scanline < FreeImage_GetHeight(_dib)) { + return FreeImage_GetScanLine(_dib, scanline); + } + return NULL; +} + +BOOL fipImage::getPixelIndex(unsigned x, unsigned y, BYTE *value) const { + return FreeImage_GetPixelIndex(_dib, x, y, value); +} + +BOOL fipImage::getPixelColor(unsigned x, unsigned y, RGBQUAD *value) const { + return FreeImage_GetPixelColor(_dib, x, y, value); +} + +BOOL fipImage::setPixelIndex(unsigned x, unsigned y, BYTE *value) { + _bHasChanged = TRUE; + return FreeImage_SetPixelIndex(_dib, x, y, value); +} + +BOOL fipImage::setPixelColor(unsigned x, unsigned y, RGBQUAD *value) { + _bHasChanged = TRUE; + return FreeImage_SetPixelColor(_dib, x, y, value); +} + +/////////////////////////////////////////////////////////////////// +// File type identification + +FREE_IMAGE_FORMAT fipImage::identifyFIF(const char* lpszPathName) { + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + + // check the file signature and get its format + // (the second argument is currently not used by FreeImage) + fif = FreeImage_GetFileType(lpszPathName, 0); + if(fif == FIF_UNKNOWN) { + // no signature ? + // try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilename(lpszPathName); + } + + return fif; +} + +FREE_IMAGE_FORMAT fipImage::identifyFIFU(const wchar_t* lpszPathName) { + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + + // check the file signature and get its format + // (the second argument is currently not used by FreeImage) + fif = FreeImage_GetFileTypeU(lpszPathName, 0); + if(fif == FIF_UNKNOWN) { + // no signature ? + // try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilenameU(lpszPathName); + } + + return fif; +} + +FREE_IMAGE_FORMAT fipImage::identifyFIFFromHandle(FreeImageIO *io, fi_handle handle) { + if(io && handle) { + // check the file signature and get its format + return FreeImage_GetFileTypeFromHandle(io, handle, 16); + } + return FIF_UNKNOWN; +} + +FREE_IMAGE_FORMAT fipImage::identifyFIFFromMemory(FIMEMORY *hmem) { + if(hmem != NULL) { + return FreeImage_GetFileTypeFromMemory(hmem, 0); + } + return FIF_UNKNOWN; +} + + +/////////////////////////////////////////////////////////////////// +// Loading & Saving + +BOOL fipImage::load(const char* lpszPathName, int flag) { + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + + // check the file signature and get its format + // (the second argument is currently not used by FreeImage) + fif = FreeImage_GetFileType(lpszPathName, 0); + if(fif == FIF_UNKNOWN) { + // no signature ? + // try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilename(lpszPathName); + } + // check that the plugin has reading capabilities ... + if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { + // Free the previous dib + if(_dib) { + FreeImage_Unload(_dib); + } + // Load the file + _dib = FreeImage_Load(fif, lpszPathName, flag); + _bHasChanged = TRUE; + if(_dib == NULL) + return FALSE; + return TRUE; + } + return FALSE; +} + +BOOL fipImage::loadU(const wchar_t* lpszPathName, int flag) { + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + + // check the file signature and get its format + // (the second argument is currently not used by FreeImage) + fif = FreeImage_GetFileTypeU(lpszPathName, 0); + if(fif == FIF_UNKNOWN) { + // no signature ? + // try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilenameU(lpszPathName); + } + // check that the plugin has reading capabilities ... + if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { + // Free the previous dib + if(_dib) { + FreeImage_Unload(_dib); + } + // Load the file + _dib = FreeImage_LoadU(fif, lpszPathName, flag); + _bHasChanged = TRUE; + if(_dib == NULL) + return FALSE; + return TRUE; + } + return FALSE; +} + +BOOL fipImage::loadFromHandle(FreeImageIO *io, fi_handle handle, int flag) { + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + + // check the file signature and get its format + fif = FreeImage_GetFileTypeFromHandle(io, handle, 16); + if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { + // Free the previous dib + if(_dib) { + FreeImage_Unload(_dib); + } + // Load the file + _dib = FreeImage_LoadFromHandle(fif, io, handle, flag); + _bHasChanged = TRUE; + if(_dib == NULL) + return FALSE; + return TRUE; + } + return FALSE; +} + +BOOL fipImage::loadFromMemory(fipMemoryIO& memIO, int flag) { + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + + // check the file signature and get its format + fif = memIO.getFileType(); + if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { + // Free the previous dib + if(_dib) { + FreeImage_Unload(_dib); + } + // Load the file + _dib = memIO.load(fif, flag); + _bHasChanged = TRUE; + if(_dib == NULL) + return FALSE; + return TRUE; + } + return FALSE; +} + +BOOL fipImage::save(const char* lpszPathName, int flag) const { + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + BOOL bSuccess = FALSE; + + // Try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilename(lpszPathName); + if(fif != FIF_UNKNOWN ) { + // Check that the dib can be saved in this format + BOOL bCanSave; + + FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(_dib); + if(image_type == FIT_BITMAP) { + // standard bitmap type + WORD bpp = FreeImage_GetBPP(_dib); + bCanSave = (FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)); + } else { + // special bitmap type + bCanSave = FreeImage_FIFSupportsExportType(fif, image_type); + } + + if(bCanSave) { + bSuccess = FreeImage_Save(fif, _dib, lpszPathName, flag); + return bSuccess; + } + } + return bSuccess; +} + +BOOL fipImage::saveU(const wchar_t* lpszPathName, int flag) const { + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + BOOL bSuccess = FALSE; + + // Try to guess the file format from the file extension + fif = FreeImage_GetFIFFromFilenameU(lpszPathName); + if(fif != FIF_UNKNOWN ) { + // Check that the dib can be saved in this format + BOOL bCanSave; + + FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(_dib); + if(image_type == FIT_BITMAP) { + // standard bitmap type + WORD bpp = FreeImage_GetBPP(_dib); + bCanSave = (FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)); + } else { + // special bitmap type + bCanSave = FreeImage_FIFSupportsExportType(fif, image_type); + } + + if(bCanSave) { + bSuccess = FreeImage_SaveU(fif, _dib, lpszPathName, flag); + return bSuccess; + } + } + return bSuccess; +} + +BOOL fipImage::saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flag) const { + BOOL bSuccess = FALSE; + + if(fif != FIF_UNKNOWN ) { + // Check that the dib can be saved in this format + BOOL bCanSave; + + FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(_dib); + if(image_type == FIT_BITMAP) { + // standard bitmap type + WORD bpp = FreeImage_GetBPP(_dib); + bCanSave = (FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)); + } else { + // special bitmap type + bCanSave = FreeImage_FIFSupportsExportType(fif, image_type); + } + + if(bCanSave) { + bSuccess = FreeImage_SaveToHandle(fif, _dib, io, handle, flag); + return bSuccess; + } + } + return bSuccess; +} + +BOOL fipImage::saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flag) const { + BOOL bSuccess = FALSE; + + if(fif != FIF_UNKNOWN ) { + // Check that the dib can be saved in this format + BOOL bCanSave; + + FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(_dib); + if(image_type == FIT_BITMAP) { + // standard bitmap type + WORD bpp = FreeImage_GetBPP(_dib); + bCanSave = (FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)); + } else { + // special bitmap type + bCanSave = FreeImage_FIFSupportsExportType(fif, image_type); + } + + if(bCanSave) { + bSuccess = memIO.save(fif, _dib, flag); + return bSuccess; + } + } + return bSuccess; +} + +/////////////////////////////////////////////////////////////////// +// Conversion routines + +BOOL fipImage::convertToType(FREE_IMAGE_TYPE image_type, BOOL scale_linear) { + if(_dib) { + FIBITMAP *dib = FreeImage_ConvertToType(_dib, image_type, scale_linear); + return replace(dib); + } + return FALSE; +} + +BOOL fipImage::threshold(BYTE T) { + if(_dib) { + FIBITMAP *dib1 = FreeImage_Threshold(_dib, T); + return replace(dib1); + } + return FALSE; +} + +BOOL fipImage::convertTo4Bits() { + if(_dib) { + FIBITMAP *dib4 = FreeImage_ConvertTo4Bits(_dib); + return replace(dib4); + } + return FALSE; +} + +BOOL fipImage::convertTo8Bits() { + if(_dib) { + FIBITMAP *dib8 = FreeImage_ConvertTo8Bits(_dib); + return replace(dib8); + } + return FALSE; +} + +BOOL fipImage::convertTo16Bits555() { + if(_dib) { + FIBITMAP *dib16_555 = FreeImage_ConvertTo16Bits555(_dib); + return replace(dib16_555); + } + return FALSE; +} + +BOOL fipImage::convertTo16Bits565() { + if(_dib) { + FIBITMAP *dib16_565 = FreeImage_ConvertTo16Bits565(_dib); + return replace(dib16_565); + } + return FALSE; +} + +BOOL fipImage::convertTo24Bits() { + if(_dib) { + FIBITMAP *dibRGB = FreeImage_ConvertTo24Bits(_dib); + return replace(dibRGB); + } + return FALSE; +} + +BOOL fipImage::convertTo32Bits() { + if(_dib) { + FIBITMAP *dib32 = FreeImage_ConvertTo32Bits(_dib); + return replace(dib32); + } + return FALSE; +} + +BOOL fipImage::convertToGrayscale() { + if(_dib) { + FIBITMAP *dib8 = FreeImage_ConvertToGreyscale(_dib); + return replace(dib8); + } + return FALSE; +} + +BOOL fipImage::colorQuantize(FREE_IMAGE_QUANTIZE algorithm) { + if(_dib) { + FIBITMAP *dib8 = FreeImage_ColorQuantize(_dib, algorithm); + return replace(dib8); + } + return FALSE; +} + +BOOL fipImage::dither(FREE_IMAGE_DITHER algorithm) { + if(_dib) { + FIBITMAP *dib = FreeImage_Dither(_dib, algorithm); + return replace(dib); + } + return FALSE; +} + +BOOL fipImage::convertToFloat() { + if(_dib) { + FIBITMAP *dib = FreeImage_ConvertToFloat(_dib); + return replace(dib); + } + return FALSE; +} + +BOOL fipImage::convertToRGBF() { + if(_dib) { + FIBITMAP *dib = FreeImage_ConvertToRGBF(_dib); + return replace(dib); + } + return FALSE; +} + +BOOL fipImage::convertToUINT16() { + if(_dib) { + FIBITMAP *dib = FreeImage_ConvertToUINT16(_dib); + return replace(dib); + } + return FALSE; +} + +BOOL fipImage::convertToRGB16() { + if(_dib) { + FIBITMAP *dib = FreeImage_ConvertToRGB16(_dib); + return replace(dib); + } + return FALSE; +} + +BOOL fipImage::toneMapping(FREE_IMAGE_TMO tmo, double first_param, double second_param, double third_param, double fourth_param) { + if(_dib) { + FIBITMAP *dst = NULL; + // Apply a tone mapping algorithm and convert to 24-bit + switch(tmo) { + case FITMO_REINHARD05: + dst = FreeImage_TmoReinhard05Ex(_dib, first_param, second_param, third_param, fourth_param); + break; + default: + dst = FreeImage_ToneMapping(_dib, tmo, first_param, second_param); + break; + } + + return replace(dst); + } + return FALSE; +} + +/////////////////////////////////////////////////////////////////// +// Transparency support: background colour and alpha channel + +BOOL fipImage::isTransparent() const { + return FreeImage_IsTransparent(_dib); +} + +unsigned fipImage::getTransparencyCount() const { + return FreeImage_GetTransparencyCount(_dib); +} + +BYTE* fipImage::getTransparencyTable() const { + return FreeImage_GetTransparencyTable(_dib); +} + +void fipImage::setTransparencyTable(BYTE *table, int count) { + FreeImage_SetTransparencyTable(_dib, table, count); + _bHasChanged = TRUE; +} + +BOOL fipImage::hasFileBkColor() const { + return FreeImage_HasBackgroundColor(_dib); +} + +BOOL fipImage::getFileBkColor(RGBQUAD *bkcolor) const { + return FreeImage_GetBackgroundColor(_dib, bkcolor); +} + +BOOL fipImage::setFileBkColor(RGBQUAD *bkcolor) { + _bHasChanged = TRUE; + return FreeImage_SetBackgroundColor(_dib, bkcolor); +} + +/////////////////////////////////////////////////////////////////// +// Channel processing support + +BOOL fipImage::getChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel) const { + if(_dib) { + image = FreeImage_GetChannel(_dib, channel); + return image.isValid(); + } + return FALSE; +} + +BOOL fipImage::setChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel) { + if(_dib) { + _bHasChanged = TRUE; + return FreeImage_SetChannel(_dib, image._dib, channel); + } + return FALSE; +} + +BOOL fipImage::splitChannels(fipImage& RedChannel, fipImage& GreenChannel, fipImage& BlueChannel) { + if(_dib) { + RedChannel = FreeImage_GetChannel(_dib, FICC_RED); + GreenChannel = FreeImage_GetChannel(_dib, FICC_GREEN); + BlueChannel = FreeImage_GetChannel(_dib, FICC_BLUE); + + return (RedChannel.isValid() && GreenChannel.isValid() && BlueChannel.isValid()); + } + return FALSE; +} + +BOOL fipImage::combineChannels(fipImage& red, fipImage& green, fipImage& blue) { + if(!_dib) { + int width = red.getWidth(); + int height = red.getHeight(); + _dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); + } + + if(_dib) { + BOOL bResult = TRUE; + bResult &= FreeImage_SetChannel(_dib, red._dib, FICC_RED); + bResult &= FreeImage_SetChannel(_dib, green._dib, FICC_GREEN); + bResult &= FreeImage_SetChannel(_dib, blue._dib, FICC_BLUE); + + _bHasChanged = TRUE; + + return bResult; + } + return FALSE; +} + +/////////////////////////////////////////////////////////////////// +// Rotation and flipping + +BOOL fipImage::rotateEx(double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask) { + if(_dib) { + if(FreeImage_GetBPP(_dib) >= 8) { + FIBITMAP *rotated = FreeImage_RotateEx(_dib, angle, x_shift, y_shift, x_origin, y_origin, use_mask); + return replace(rotated); + } + } + return FALSE; +} + +BOOL fipImage::rotate(double angle, const void *bkcolor) { + if(_dib) { + switch(FreeImage_GetImageType(_dib)) { + case FIT_BITMAP: + switch(FreeImage_GetBPP(_dib)) { + case 1: + case 8: + case 24: + case 32: + break; + default: + return FALSE; + } + break; + + case FIT_UINT16: + case FIT_RGB16: + case FIT_RGBA16: + case FIT_FLOAT: + case FIT_RGBF: + case FIT_RGBAF: + break; + default: + return FALSE; + break; + } + + FIBITMAP *rotated = FreeImage_Rotate(_dib, angle, bkcolor); + return replace(rotated); + + } + return FALSE; +} + +BOOL fipImage::flipVertical() { + if(_dib) { + _bHasChanged = TRUE; + + return FreeImage_FlipVertical(_dib); + } + return FALSE; +} + +BOOL fipImage::flipHorizontal() { + if(_dib) { + _bHasChanged = TRUE; + + return FreeImage_FlipHorizontal(_dib); + } + return FALSE; +} + +/////////////////////////////////////////////////////////////////// +// Color manipulation routines + +BOOL fipImage::invert() { + if(_dib) { + _bHasChanged = TRUE; + + return FreeImage_Invert(_dib); + } + return FALSE; +} + +BOOL fipImage::adjustCurve(BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel) { + if(_dib) { + _bHasChanged = TRUE; + + return FreeImage_AdjustCurve(_dib, LUT, channel); + } + return FALSE; +} + +BOOL fipImage::adjustGamma(double gamma) { + if(_dib) { + _bHasChanged = TRUE; + + return FreeImage_AdjustGamma(_dib, gamma); + } + return FALSE; +} + +BOOL fipImage::adjustBrightness(double percentage) { + if(_dib) { + _bHasChanged = TRUE; + + return FreeImage_AdjustBrightness(_dib, percentage); + } + return FALSE; +} + +BOOL fipImage::adjustContrast(double percentage) { + if(_dib) { + _bHasChanged = TRUE; + + return FreeImage_AdjustContrast(_dib, percentage); + } + return FALSE; +} + +BOOL fipImage::adjustBrightnessContrastGamma(double brightness, double contrast, double gamma) { + if(_dib) { + _bHasChanged = TRUE; + + return FreeImage_AdjustColors(_dib, brightness, contrast, gamma, FALSE); + } + return FALSE; +} + +BOOL fipImage::getHistogram(DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel) const { + if(_dib) { + return FreeImage_GetHistogram(_dib, histo, channel); + } + return FALSE; +} + +/////////////////////////////////////////////////////////////////// +// Upsampling / downsampling routine + +BOOL fipImage::rescale(unsigned new_width, unsigned new_height, FREE_IMAGE_FILTER filter) { + if(_dib) { + switch(FreeImage_GetImageType(_dib)) { + case FIT_BITMAP: + case FIT_UINT16: + case FIT_RGB16: + case FIT_RGBA16: + case FIT_FLOAT: + case FIT_RGBF: + case FIT_RGBAF: + break; + default: + return FALSE; + break; + } + + // Perform upsampling / downsampling + FIBITMAP *dst = FreeImage_Rescale(_dib, new_width, new_height, filter); + return replace(dst); + } + return FALSE; +} + +BOOL fipImage::makeThumbnail(unsigned max_size, BOOL convert) { + if(_dib) { + switch(FreeImage_GetImageType(_dib)) { + case FIT_BITMAP: + case FIT_UINT16: + case FIT_RGB16: + case FIT_RGBA16: + case FIT_FLOAT: + case FIT_RGBF: + case FIT_RGBAF: + break; + default: + return FALSE; + break; + } + + // Perform downsampling + FIBITMAP *dst = FreeImage_MakeThumbnail(_dib, max_size, convert); + return replace(dst); + } + return FALSE; +} + +/////////////////////////////////////////////////////////////////// +// Metadata + +unsigned fipImage::getMetadataCount(FREE_IMAGE_MDMODEL model) const { + return FreeImage_GetMetadataCount(model, _dib); +} + +BOOL fipImage::getMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag) const { + FITAG *searchedTag = NULL; + FreeImage_GetMetadata(model, _dib, key, &searchedTag); + if(searchedTag != NULL) { + tag = FreeImage_CloneTag(searchedTag); + return TRUE; + } else { + // clear the tag + tag = (FITAG*)NULL; + } + return FALSE; +} + +BOOL fipImage::setMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag) { + return FreeImage_SetMetadata(model, _dib, key, tag); +} + diff --git a/Wrapper/FreeImagePlus/src/fipMemoryIO.cpp b/Wrapper/FreeImagePlus/src/fipMemoryIO.cpp index 2180eb8..4a8fe80 100644 --- a/Wrapper/FreeImagePlus/src/fipMemoryIO.cpp +++ b/Wrapper/FreeImagePlus/src/fipMemoryIO.cpp @@ -1,95 +1,95 @@ -// ========================================================== -// fipMemoryIO class implementation -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImagePlus.h" -#include -#include -#include -#include -#include -#include - -fipMemoryIO::fipMemoryIO(BYTE *data, DWORD size_in_bytes) { - _hmem = FreeImage_OpenMemory(data, size_in_bytes); -} - -fipMemoryIO::~fipMemoryIO() { - if(_hmem != NULL) { - FreeImage_CloseMemory(_hmem); - } -} - -void fipMemoryIO::close() { - if(_hmem != NULL) { - FreeImage_CloseMemory(_hmem); - _hmem = NULL; - } -} - -BOOL fipMemoryIO::isValid() const { - return (_hmem != NULL); -} - -FREE_IMAGE_FORMAT fipMemoryIO::getFileType() const { - if(_hmem != NULL) { - return FreeImage_GetFileTypeFromMemory(_hmem, 0); - } - - return FIF_UNKNOWN; -} - -FIBITMAP* fipMemoryIO::load(FREE_IMAGE_FORMAT fif, int flags) const { - return FreeImage_LoadFromMemory(fif, _hmem, flags); -} - -FIMULTIBITMAP* fipMemoryIO::loadMultiPage(FREE_IMAGE_FORMAT fif, int flags) const { - return FreeImage_LoadMultiBitmapFromMemory(fif, _hmem, flags); -} - -BOOL fipMemoryIO::save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, int flags) { - return FreeImage_SaveToMemory(fif, dib, _hmem, flags); -} - -BOOL fipMemoryIO::saveMultiPage(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, int flags) { - return FreeImage_SaveMultiBitmapToMemory(fif, bitmap, _hmem, flags); -} - -unsigned fipMemoryIO::read(void *buffer, unsigned size, unsigned count) const { - return FreeImage_ReadMemory(buffer, size, count, _hmem); -} - -unsigned fipMemoryIO::write(const void *buffer, unsigned size, unsigned count) { - return FreeImage_WriteMemory(buffer, size, count, _hmem); -} - -long fipMemoryIO::tell() const { - return FreeImage_TellMemory(_hmem); -} - -BOOL fipMemoryIO::seek(long offset, int origin) { - return FreeImage_SeekMemory(_hmem, offset, origin); -} - -BOOL fipMemoryIO::acquire(BYTE **data, DWORD *size_in_bytes) { - return FreeImage_AcquireMemory(_hmem, data, size_in_bytes); -} - - +// ========================================================== +// fipMemoryIO class implementation +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImagePlus.h" +#include +#include +#include +#include +#include +#include + +fipMemoryIO::fipMemoryIO(BYTE *data, DWORD size_in_bytes) { + _hmem = FreeImage_OpenMemory(data, size_in_bytes); +} + +fipMemoryIO::~fipMemoryIO() { + if(_hmem != NULL) { + FreeImage_CloseMemory(_hmem); + } +} + +void fipMemoryIO::close() { + if(_hmem != NULL) { + FreeImage_CloseMemory(_hmem); + _hmem = NULL; + } +} + +BOOL fipMemoryIO::isValid() const { + return (_hmem != NULL); +} + +FREE_IMAGE_FORMAT fipMemoryIO::getFileType() const { + if(_hmem != NULL) { + return FreeImage_GetFileTypeFromMemory(_hmem, 0); + } + + return FIF_UNKNOWN; +} + +FIBITMAP* fipMemoryIO::load(FREE_IMAGE_FORMAT fif, int flags) const { + return FreeImage_LoadFromMemory(fif, _hmem, flags); +} + +FIMULTIBITMAP* fipMemoryIO::loadMultiPage(FREE_IMAGE_FORMAT fif, int flags) const { + return FreeImage_LoadMultiBitmapFromMemory(fif, _hmem, flags); +} + +BOOL fipMemoryIO::save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, int flags) { + return FreeImage_SaveToMemory(fif, dib, _hmem, flags); +} + +BOOL fipMemoryIO::saveMultiPage(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, int flags) { + return FreeImage_SaveMultiBitmapToMemory(fif, bitmap, _hmem, flags); +} + +unsigned fipMemoryIO::read(void *buffer, unsigned size, unsigned count) const { + return FreeImage_ReadMemory(buffer, size, count, _hmem); +} + +unsigned fipMemoryIO::write(const void *buffer, unsigned size, unsigned count) { + return FreeImage_WriteMemory(buffer, size, count, _hmem); +} + +long fipMemoryIO::tell() const { + return FreeImage_TellMemory(_hmem); +} + +BOOL fipMemoryIO::seek(long offset, int origin) { + return FreeImage_SeekMemory(_hmem, offset, origin); +} + +BOOL fipMemoryIO::acquire(BYTE **data, DWORD *size_in_bytes) { + return FreeImage_AcquireMemory(_hmem, data, size_in_bytes); +} + + diff --git a/Wrapper/FreeImagePlus/src/fipMetadataFind.cpp b/Wrapper/FreeImagePlus/src/fipMetadataFind.cpp index 38f8764..57d01f6 100644 --- a/Wrapper/FreeImagePlus/src/fipMetadataFind.cpp +++ b/Wrapper/FreeImagePlus/src/fipMetadataFind.cpp @@ -1,54 +1,54 @@ -// ========================================================== -// fipMetadataFind class implementation -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImagePlus.h" - -BOOL fipMetadataFind::isValid() const { - return (_mdhandle != NULL) ? TRUE : FALSE; -} - -fipMetadataFind::fipMetadataFind() : _mdhandle(NULL) { -} - -fipMetadataFind::~fipMetadataFind() { - FreeImage_FindCloseMetadata(_mdhandle); -} - -BOOL fipMetadataFind::findFirstMetadata(FREE_IMAGE_MDMODEL model, fipImage& image, fipTag& tag) { - FITAG *firstTag = NULL; - if(_mdhandle) FreeImage_FindCloseMetadata(_mdhandle); - _mdhandle = FreeImage_FindFirstMetadata(model, image, &firstTag); - if(_mdhandle) { - tag = FreeImage_CloneTag(firstTag); - return TRUE; - } - return FALSE; -} - -BOOL fipMetadataFind::findNextMetadata(fipTag& tag) { - FITAG *nextTag = NULL; - if( FreeImage_FindNextMetadata(_mdhandle, &nextTag) ) { - tag = FreeImage_CloneTag(nextTag); - return TRUE; - } - return FALSE; -} - +// ========================================================== +// fipMetadataFind class implementation +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImagePlus.h" + +BOOL fipMetadataFind::isValid() const { + return (_mdhandle != NULL) ? TRUE : FALSE; +} + +fipMetadataFind::fipMetadataFind() : _mdhandle(NULL) { +} + +fipMetadataFind::~fipMetadataFind() { + FreeImage_FindCloseMetadata(_mdhandle); +} + +BOOL fipMetadataFind::findFirstMetadata(FREE_IMAGE_MDMODEL model, fipImage& image, fipTag& tag) { + FITAG *firstTag = NULL; + if(_mdhandle) FreeImage_FindCloseMetadata(_mdhandle); + _mdhandle = FreeImage_FindFirstMetadata(model, image, &firstTag); + if(_mdhandle) { + tag = FreeImage_CloneTag(firstTag); + return TRUE; + } + return FALSE; +} + +BOOL fipMetadataFind::findNextMetadata(fipTag& tag) { + FITAG *nextTag = NULL; + if( FreeImage_FindNextMetadata(_mdhandle, &nextTag) ) { + tag = FreeImage_CloneTag(nextTag); + return TRUE; + } + return FALSE; +} + diff --git a/Wrapper/FreeImagePlus/src/fipMultiPage.cpp b/Wrapper/FreeImagePlus/src/fipMultiPage.cpp index 9ce9809..cc33196 100644 --- a/Wrapper/FreeImagePlus/src/fipMultiPage.cpp +++ b/Wrapper/FreeImagePlus/src/fipMultiPage.cpp @@ -1,140 +1,140 @@ -// ========================================================== -// fipMultiPage class implementation -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImagePlus.h" - -fipMultiPage::fipMultiPage(BOOL keep_cache_in_memory) : _mpage(NULL), _bMemoryCache(keep_cache_in_memory) { -} - -fipMultiPage::~fipMultiPage() { - if(_mpage) { - // close the stream - close(0); - } -} - -BOOL fipMultiPage::isValid() const { - return (NULL != _mpage) ? TRUE : FALSE; -} - -BOOL fipMultiPage::open(const char* lpszPathName, BOOL create_new, BOOL read_only, int flags) { - // try to guess the file format from the filename - FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(lpszPathName); - - // open the stream - _mpage = FreeImage_OpenMultiBitmap(fif, lpszPathName, create_new, read_only, _bMemoryCache, flags); - - return (NULL != _mpage ) ? TRUE : FALSE; -} - -BOOL fipMultiPage::open(fipMemoryIO& memIO, int flags) { - // try to guess the file format from the memory handle - FREE_IMAGE_FORMAT fif = memIO.getFileType(); - - // open the stream - _mpage = memIO.loadMultiPage(fif, flags); - - return (NULL != _mpage ) ? TRUE : FALSE; -} - -BOOL fipMultiPage::open(FreeImageIO *io, fi_handle handle, int flags) { - // try to guess the file format from the handle - FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromHandle(io, handle, 0); - - // open the stream - _mpage = FreeImage_OpenMultiBitmapFromHandle(fif, io, handle, flags); - - return (NULL != _mpage ) ? TRUE : FALSE; -} - -BOOL fipMultiPage::close(int flags) { - BOOL bSuccess = FALSE; - if(_mpage) { - // close the stream - bSuccess = FreeImage_CloseMultiBitmap(_mpage, flags); - _mpage = NULL; - } - - return bSuccess; -} - -BOOL fipMultiPage::saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags) const { - BOOL bSuccess = FALSE; - if(_mpage) { - bSuccess = FreeImage_SaveMultiBitmapToHandle(fif, _mpage, io, handle, flags); - } - - return bSuccess; -} - -BOOL fipMultiPage::saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flags) const { - BOOL bSuccess = FALSE; - if(_mpage) { - bSuccess = memIO.saveMultiPage(fif, _mpage, flags); - } - - return bSuccess; -} - -int fipMultiPage::getPageCount() const { - return _mpage ? FreeImage_GetPageCount(_mpage) : 0; -} - -void fipMultiPage::appendPage(fipImage& image) { - if(_mpage) { - FreeImage_AppendPage(_mpage, image); - } -} - -void fipMultiPage::insertPage(int page, fipImage& image) { - if(_mpage) { - FreeImage_InsertPage(_mpage, page, image); - } -} - -void fipMultiPage::deletePage(int page) { - if(_mpage) { - FreeImage_DeletePage(_mpage, page); - } -} - -BOOL fipMultiPage::movePage(int target, int source) { - return _mpage ? FreeImage_MovePage(_mpage, target, source) : FALSE; -} - -FIBITMAP* fipMultiPage::lockPage(int page) { - return _mpage ? FreeImage_LockPage(_mpage, page) : NULL; -} - -void fipMultiPage::unlockPage(fipImage& image, BOOL changed) { - if(_mpage) { - FreeImage_UnlockPage(_mpage, image, changed); - // clear the image so that it becomes invalid. - // this is possible because of the friend declaration - image._dib = NULL; - image._bHasChanged = FALSE; - } -} - -BOOL fipMultiPage::getLockedPageNumbers(int *pages, int *count) const { - return _mpage ? FreeImage_GetLockedPageNumbers(_mpage, pages, count) : FALSE; -} - +// ========================================================== +// fipMultiPage class implementation +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImagePlus.h" + +fipMultiPage::fipMultiPage(BOOL keep_cache_in_memory) : _mpage(NULL), _bMemoryCache(keep_cache_in_memory) { +} + +fipMultiPage::~fipMultiPage() { + if(_mpage) { + // close the stream + close(0); + } +} + +BOOL fipMultiPage::isValid() const { + return (NULL != _mpage) ? TRUE : FALSE; +} + +BOOL fipMultiPage::open(const char* lpszPathName, BOOL create_new, BOOL read_only, int flags) { + // try to guess the file format from the filename + FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(lpszPathName); + + // open the stream + _mpage = FreeImage_OpenMultiBitmap(fif, lpszPathName, create_new, read_only, _bMemoryCache, flags); + + return (NULL != _mpage ) ? TRUE : FALSE; +} + +BOOL fipMultiPage::open(fipMemoryIO& memIO, int flags) { + // try to guess the file format from the memory handle + FREE_IMAGE_FORMAT fif = memIO.getFileType(); + + // open the stream + _mpage = memIO.loadMultiPage(fif, flags); + + return (NULL != _mpage ) ? TRUE : FALSE; +} + +BOOL fipMultiPage::open(FreeImageIO *io, fi_handle handle, int flags) { + // try to guess the file format from the handle + FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromHandle(io, handle, 0); + + // open the stream + _mpage = FreeImage_OpenMultiBitmapFromHandle(fif, io, handle, flags); + + return (NULL != _mpage ) ? TRUE : FALSE; +} + +BOOL fipMultiPage::close(int flags) { + BOOL bSuccess = FALSE; + if(_mpage) { + // close the stream + bSuccess = FreeImage_CloseMultiBitmap(_mpage, flags); + _mpage = NULL; + } + + return bSuccess; +} + +BOOL fipMultiPage::saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags) const { + BOOL bSuccess = FALSE; + if(_mpage) { + bSuccess = FreeImage_SaveMultiBitmapToHandle(fif, _mpage, io, handle, flags); + } + + return bSuccess; +} + +BOOL fipMultiPage::saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flags) const { + BOOL bSuccess = FALSE; + if(_mpage) { + bSuccess = memIO.saveMultiPage(fif, _mpage, flags); + } + + return bSuccess; +} + +int fipMultiPage::getPageCount() const { + return _mpage ? FreeImage_GetPageCount(_mpage) : 0; +} + +void fipMultiPage::appendPage(fipImage& image) { + if(_mpage) { + FreeImage_AppendPage(_mpage, image); + } +} + +void fipMultiPage::insertPage(int page, fipImage& image) { + if(_mpage) { + FreeImage_InsertPage(_mpage, page, image); + } +} + +void fipMultiPage::deletePage(int page) { + if(_mpage) { + FreeImage_DeletePage(_mpage, page); + } +} + +BOOL fipMultiPage::movePage(int target, int source) { + return _mpage ? FreeImage_MovePage(_mpage, target, source) : FALSE; +} + +FIBITMAP* fipMultiPage::lockPage(int page) { + return _mpage ? FreeImage_LockPage(_mpage, page) : NULL; +} + +void fipMultiPage::unlockPage(fipImage& image, BOOL changed) { + if(_mpage) { + FreeImage_UnlockPage(_mpage, image, changed); + // clear the image so that it becomes invalid. + // this is possible because of the friend declaration + image._dib = NULL; + image._bHasChanged = FALSE; + } +} + +BOOL fipMultiPage::getLockedPageNumbers(int *pages, int *count) const { + return _mpage ? FreeImage_GetLockedPageNumbers(_mpage, pages, count) : FALSE; +} + diff --git a/Wrapper/FreeImagePlus/src/fipTag.cpp b/Wrapper/FreeImagePlus/src/fipTag.cpp index f2afe9f..b00a095 100644 --- a/Wrapper/FreeImagePlus/src/fipTag.cpp +++ b/Wrapper/FreeImagePlus/src/fipTag.cpp @@ -1,134 +1,134 @@ -// ========================================================== -// fipTag class implementation -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include -#include "FreeImagePlus.h" - -fipTag::fipTag() { - _tag = FreeImage_CreateTag(); -} - -fipTag::~fipTag() { - FreeImage_DeleteTag(_tag); -} - -BOOL fipTag::setKeyValue(const char *key, const char *value) { - if(_tag) { - FreeImage_DeleteTag(_tag); - _tag = NULL; - } - // create a tag - _tag = FreeImage_CreateTag(); - if(_tag) { - BOOL bSuccess = TRUE; - // fill the tag - DWORD tag_length = (DWORD)(strlen(value) + 1); - bSuccess &= FreeImage_SetTagKey(_tag, key); - bSuccess &= FreeImage_SetTagLength(_tag, tag_length); - bSuccess &= FreeImage_SetTagCount(_tag, tag_length); - bSuccess &= FreeImage_SetTagType(_tag, FIDT_ASCII); - bSuccess &= FreeImage_SetTagValue(_tag, value); - return bSuccess; - } - return FALSE; -} - -fipTag::fipTag(const fipTag& tag) { - _tag = FreeImage_CloneTag(tag._tag); -} - -fipTag& fipTag::operator=(const fipTag& tag) { - if(this != &tag) { - if(_tag) FreeImage_DeleteTag(_tag); - _tag = FreeImage_CloneTag(tag._tag); - } - return *this; -} - -fipTag& fipTag::operator=(FITAG *tag) { - if(_tag) FreeImage_DeleteTag(_tag); - _tag = tag; - return *this; -} - -BOOL fipTag::isValid() const { - return (_tag != NULL) ? TRUE : FALSE; -} - -const char* fipTag::getKey() const { - return FreeImage_GetTagKey(_tag); -} - -const char* fipTag::getDescription() const { - return FreeImage_GetTagDescription(_tag); -} - -WORD fipTag::getID() const { - return FreeImage_GetTagID(_tag); -} - -FREE_IMAGE_MDTYPE fipTag::getType() const { - return FreeImage_GetTagType(_tag); -} - -DWORD fipTag::getCount() const { - return FreeImage_GetTagCount(_tag); -} - -DWORD fipTag::getLength() const { - return FreeImage_GetTagLength(_tag); -} - -const void* fipTag::getValue() const { - return FreeImage_GetTagValue(_tag); -} - -BOOL fipTag::setKey(const char *key) { - return FreeImage_SetTagKey(_tag, key); -} - -BOOL fipTag::setDescription(const char *description) { - return FreeImage_SetTagDescription(_tag, description); -} - -BOOL fipTag::setID(WORD id) { - return FreeImage_SetTagID(_tag, id); -} - -BOOL fipTag::setType(FREE_IMAGE_MDTYPE type) { - return FreeImage_SetTagType(_tag, type); -} - -BOOL fipTag::setCount(DWORD count) { - return FreeImage_SetTagCount(_tag, count); -} - -BOOL fipTag::setLength(DWORD length) { - return FreeImage_SetTagLength(_tag, length); -} - -BOOL fipTag::setValue(const void *value) { - return FreeImage_SetTagValue(_tag, value); -} - -const char* fipTag::toString(FREE_IMAGE_MDMODEL model, char *Make) const { - return FreeImage_TagToString(model, _tag, Make); -} +// ========================================================== +// fipTag class implementation +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include +#include "FreeImagePlus.h" + +fipTag::fipTag() { + _tag = FreeImage_CreateTag(); +} + +fipTag::~fipTag() { + FreeImage_DeleteTag(_tag); +} + +BOOL fipTag::setKeyValue(const char *key, const char *value) { + if(_tag) { + FreeImage_DeleteTag(_tag); + _tag = NULL; + } + // create a tag + _tag = FreeImage_CreateTag(); + if(_tag) { + BOOL bSuccess = TRUE; + // fill the tag + DWORD tag_length = (DWORD)(strlen(value) + 1); + bSuccess &= FreeImage_SetTagKey(_tag, key); + bSuccess &= FreeImage_SetTagLength(_tag, tag_length); + bSuccess &= FreeImage_SetTagCount(_tag, tag_length); + bSuccess &= FreeImage_SetTagType(_tag, FIDT_ASCII); + bSuccess &= FreeImage_SetTagValue(_tag, value); + return bSuccess; + } + return FALSE; +} + +fipTag::fipTag(const fipTag& tag) { + _tag = FreeImage_CloneTag(tag._tag); +} + +fipTag& fipTag::operator=(const fipTag& tag) { + if(this != &tag) { + if(_tag) FreeImage_DeleteTag(_tag); + _tag = FreeImage_CloneTag(tag._tag); + } + return *this; +} + +fipTag& fipTag::operator=(FITAG *tag) { + if(_tag) FreeImage_DeleteTag(_tag); + _tag = tag; + return *this; +} + +BOOL fipTag::isValid() const { + return (_tag != NULL) ? TRUE : FALSE; +} + +const char* fipTag::getKey() const { + return FreeImage_GetTagKey(_tag); +} + +const char* fipTag::getDescription() const { + return FreeImage_GetTagDescription(_tag); +} + +WORD fipTag::getID() const { + return FreeImage_GetTagID(_tag); +} + +FREE_IMAGE_MDTYPE fipTag::getType() const { + return FreeImage_GetTagType(_tag); +} + +DWORD fipTag::getCount() const { + return FreeImage_GetTagCount(_tag); +} + +DWORD fipTag::getLength() const { + return FreeImage_GetTagLength(_tag); +} + +const void* fipTag::getValue() const { + return FreeImage_GetTagValue(_tag); +} + +BOOL fipTag::setKey(const char *key) { + return FreeImage_SetTagKey(_tag, key); +} + +BOOL fipTag::setDescription(const char *description) { + return FreeImage_SetTagDescription(_tag, description); +} + +BOOL fipTag::setID(WORD id) { + return FreeImage_SetTagID(_tag, id); +} + +BOOL fipTag::setType(FREE_IMAGE_MDTYPE type) { + return FreeImage_SetTagType(_tag, type); +} + +BOOL fipTag::setCount(DWORD count) { + return FreeImage_SetTagCount(_tag, count); +} + +BOOL fipTag::setLength(DWORD length) { + return FreeImage_SetTagLength(_tag, length); +} + +BOOL fipTag::setValue(const void *value) { + return FreeImage_SetTagValue(_tag, value); +} + +const char* fipTag::toString(FREE_IMAGE_MDMODEL model, char *Make) const { + return FreeImage_TagToString(model, _tag, Make); +} diff --git a/Wrapper/FreeImagePlus/src/fipWinImage.cpp b/Wrapper/FreeImagePlus/src/fipWinImage.cpp index 5d207b3..092b655 100644 --- a/Wrapper/FreeImagePlus/src/fipWinImage.cpp +++ b/Wrapper/FreeImagePlus/src/fipWinImage.cpp @@ -1,488 +1,488 @@ -// ========================================================== -// fipWinImage class implementation -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImagePlus.h" - -#ifdef _WIN32 - -// marker used for clipboard copy / paste - -static inline void -SET_FREEIMAGE_MARKER(BITMAPINFOHEADER *bmih, FIBITMAP *dib) { - // Windows constants goes from 0L to 5L - // Add 0xFF to avoid conflicts - bmih->biCompression = 0xFF + FreeImage_GetImageType(dib); -} - -static inline FREE_IMAGE_TYPE -GET_FREEIMAGE_MARKER(BITMAPINFOHEADER *bmih) { - return (FREE_IMAGE_TYPE)(bmih->biCompression - 0xFF); -} - -/////////////////////////////////////////////////////////////////// -// Construction / Destruction - -fipWinImage::fipWinImage(FREE_IMAGE_TYPE image_type, unsigned width, unsigned height, unsigned bpp) : fipImage(image_type, width, height, bpp) { - _display_dib = NULL; - _bDeleteMe = FALSE; - // default tone mapping operator - _tmo = FITMO_DRAGO03; - _tmo_param_1 = 0; - _tmo_param_2 = 0; - _tmo_param_3 = 1; - _tmo_param_4 = 0; -} - -fipWinImage::~fipWinImage() { - if(_bDeleteMe) { - FreeImage_Unload(_display_dib); - } -} - -void fipWinImage::clear() { - // delete _display_dib - if(_bDeleteMe) { - FreeImage_Unload(_display_dib); - } - _display_dib = NULL; - _bDeleteMe = FALSE; - // delete base class data - fipImage::clear(); -} - -BOOL fipWinImage::isValid() const { - return fipImage::isValid(); -} - -/////////////////////////////////////////////////////////////////// -// Copying - -fipWinImage& fipWinImage::operator=(const fipImage& Image) { - // delete _display_dib - if(_bDeleteMe) { - FreeImage_Unload(_display_dib); - } - _display_dib = NULL; - _bDeleteMe = FALSE; - // clone the base class - fipImage::operator=(Image); - - return *this; -} - -fipWinImage& fipWinImage::operator=(const fipWinImage& Image) { - if(this != &Image) { - // delete _display_dib - if(_bDeleteMe) { - FreeImage_Unload(_display_dib); - } - _display_dib = NULL; - _bDeleteMe = FALSE; - // copy tmo data - _tmo = Image._tmo; - _tmo_param_1 = Image._tmo_param_1; - _tmo_param_2 = Image._tmo_param_2; - _tmo_param_3 = Image._tmo_param_3; - _tmo_param_4 = Image._tmo_param_4; - - // clone the base class - fipImage::operator=(Image); - } - return *this; -} - -HANDLE fipWinImage::copyToHandle() const { - HANDLE hMem = NULL; - - if(_dib) { - - // Get equivalent DIB size - long dib_size = sizeof(BITMAPINFOHEADER); - dib_size += FreeImage_GetColorsUsed(_dib) * sizeof(RGBQUAD); - dib_size += FreeImage_GetPitch(_dib) * FreeImage_GetHeight(_dib); - - // Allocate a DIB - hMem = GlobalAlloc(GHND, dib_size); - BYTE *dib = (BYTE*)GlobalLock(hMem); - - memset(dib, 0, dib_size); - - BYTE *p_dib = (BYTE*)dib; - - // Copy the BITMAPINFOHEADER - - BITMAPINFOHEADER *bih = FreeImage_GetInfoHeader(_dib); - memcpy(p_dib, bih, sizeof(BITMAPINFOHEADER)); - if(FreeImage_GetImageType(_dib) != FIT_BITMAP) { - // this hack is used to store the bitmap type in the biCompression member of the BITMAPINFOHEADER - SET_FREEIMAGE_MARKER((BITMAPINFOHEADER*)p_dib, _dib); - } - p_dib += sizeof(BITMAPINFOHEADER); - - // Copy the palette - - RGBQUAD *pal = FreeImage_GetPalette(_dib); - memcpy(p_dib, pal, FreeImage_GetColorsUsed(_dib) * sizeof(RGBQUAD)); - p_dib += FreeImage_GetColorsUsed(_dib) * sizeof(RGBQUAD); - - // Copy the bitmap - - BYTE *bits = FreeImage_GetBits(_dib); - memcpy(p_dib, bits, FreeImage_GetPitch(_dib) * FreeImage_GetHeight(_dib)); - - GlobalUnlock(hMem); - } - - return hMem; -} - -BOOL fipWinImage::copyFromHandle(HANDLE hMem) { - BYTE *lpVoid = NULL; - BITMAPINFOHEADER *pHead = NULL; - RGBQUAD *pPalette = NULL; - BYTE *bits = NULL; - DWORD bitfields[3] = {0, 0, 0}; - - // Get a pointer to the bitmap - lpVoid = (BYTE *)GlobalLock(hMem); - - // Get a pointer to the bitmap header - pHead = (BITMAPINFOHEADER *)lpVoid; - - // Get a pointer to the palette - if(pHead->biBitCount < 16) - pPalette = (RGBQUAD *)(((BYTE *)pHead) + sizeof(BITMAPINFOHEADER)); - - // Get a pointer to the pixels - bits = ((BYTE*)pHead + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * pHead->biClrUsed); - - if(pHead->biCompression == BI_BITFIELDS) { - // Take into account the color masks that specify the red, green, and blue components (16- and 32-bit) - unsigned mask_size = 3 * sizeof(DWORD); - memcpy(&bitfields[0], bits, mask_size); - bits += mask_size; - } - - if(lpVoid) { - - // Allocate a new FIBITMAP - - FREE_IMAGE_TYPE image_type = FIT_BITMAP; - // Use a hack to decide if the clipboard contains non standard bitmaps ... - switch(GET_FREEIMAGE_MARKER(pHead)) { - case FIT_UINT16: - case FIT_INT16: - case FIT_UINT32: - case FIT_INT32: - case FIT_FLOAT: - case FIT_DOUBLE: - case FIT_COMPLEX: - case FIT_RGB16: - case FIT_RGBA16: - case FIT_RGBF: - case FIT_RGBAF: - image_type = GET_FREEIMAGE_MARKER(pHead); - break; - } - if(!setSize(image_type, (WORD)pHead->biWidth, (WORD)pHead->biHeight, pHead->biBitCount, bitfields[2], bitfields[1], bitfields[0])) { - GlobalUnlock(lpVoid); - return FALSE; - } - - // Copy the bitmap header - memcpy(FreeImage_GetInfoHeader(_dib), pHead, sizeof(BITMAPINFOHEADER)); - - - // Copy the palette - memcpy(FreeImage_GetPalette(_dib), pPalette, pHead->biClrUsed * sizeof(RGBQUAD)); - - // Copy the bitmap - memcpy(FreeImage_GetBits(_dib), bits, FreeImage_GetPitch(_dib) * FreeImage_GetHeight(_dib)); - - GlobalUnlock(lpVoid); - - return TRUE; - } - - return FALSE; -} - -BOOL fipWinImage::copyFromBitmap(HBITMAP hbmp) { - if(hbmp) { - int Success; - BITMAP bm; - // Get informations about the bitmap - GetObject(hbmp, sizeof(BITMAP), (LPSTR) &bm); - // Create the image - setSize(FIT_BITMAP, (WORD)bm.bmWidth, (WORD)bm.bmHeight, (WORD)bm.bmBitsPixel); - - // The GetDIBits function clears the biClrUsed and biClrImportant BITMAPINFO members (dont't know why) - // So we save these infos below. This is needed for palettized images only. - int nColors = FreeImage_GetColorsUsed(_dib); - - // Create a device context for the bitmap - HDC dc = GetDC(NULL); - // Copy the pixels - Success = GetDIBits(dc, // handle to DC - hbmp, // handle to bitmap - 0, // first scan line to set - FreeImage_GetHeight(_dib), // number of scan lines to copy - FreeImage_GetBits(_dib), // array for bitmap bits - FreeImage_GetInfo(_dib), // bitmap data buffer - DIB_RGB_COLORS // RGB - ); - if(Success == 0) { - FreeImage_OutputMessageProc(FIF_UNKNOWN, "Error : GetDIBits failed"); - ReleaseDC(NULL, dc); - return FALSE; - } - ReleaseDC(NULL, dc); - - // restore BITMAPINFO members - - FreeImage_GetInfoHeader(_dib)->biClrUsed = nColors; - FreeImage_GetInfoHeader(_dib)->biClrImportant = nColors; - - return TRUE; - } - - return FALSE; -} - -BOOL fipWinImage::copyToClipboard(HWND hWndNewOwner) const { - HANDLE hDIB = copyToHandle(); - - if(OpenClipboard(hWndNewOwner)) { - if(EmptyClipboard()) { - if(SetClipboardData(CF_DIB, hDIB) == NULL) { - MessageBox(hWndNewOwner, "Unable to set Clipboard data", "FreeImage", MB_ICONERROR); - CloseClipboard(); - return FALSE; - } - } - } - CloseClipboard(); - - return TRUE; -} - -BOOL fipWinImage::pasteFromClipboard() { - if(!IsClipboardFormatAvailable(CF_DIB)) - return FALSE; - - if(OpenClipboard(NULL)) { - HANDLE hDIB = GetClipboardData(CF_DIB); - copyFromHandle(hDIB); - CloseClipboard(); - return TRUE; - } - CloseClipboard(); - - return FALSE; -} - -/////////////////////////////////////////////////////////////////// -// Screen capture - -BOOL fipWinImage::captureWindow(HWND hWndApplicationWindow, HWND hWndSelectedWindow) { - int xScreen, yScreen, xshift, yshift; - RECT r; - - // Get window size - GetWindowRect(hWndSelectedWindow, &r); - - // Check if the window is out of the screen or maximixed - xshift = 0; - yshift = 0; - xScreen = GetSystemMetrics(SM_CXSCREEN); - yScreen = GetSystemMetrics(SM_CYSCREEN); - if(r.right > xScreen) - r.right = xScreen; - if(r.bottom > yScreen) - r.bottom = yScreen; - if(r.left < 0) { - xshift = -r.left; - r.left = 0; - } - if(r.top < 0){ - yshift = -r.top; - r.top = 0; - } - - int width = r.right - r.left; - int height = r.bottom - r.top; - - if(width <= 0 || height <= 0) - return FALSE; - - // Hide the application window. - ShowWindow(hWndApplicationWindow, SW_HIDE); - // Bring the window at the top most level - SetWindowPos(hWndSelectedWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); - // Give enough time to refresh the window - Sleep(500); - - // Prepare the DCs - HDC dstDC = GetDC(NULL); - HDC srcDC = GetWindowDC(hWndSelectedWindow); // full window (GetDC(hWndSelectedWindow) = clientarea) - HDC memDC = CreateCompatibleDC(dstDC); - - // Copy the screen to the bitmap - HBITMAP bm = CreateCompatibleBitmap(dstDC, width, height); - HBITMAP oldbm = (HBITMAP)SelectObject(memDC, bm); - BitBlt(memDC, 0, 0, width, height, srcDC, xshift, yshift, SRCCOPY); - - // Redraw the application window. - ShowWindow(hWndApplicationWindow, SW_SHOW); - - // Restore the position - SetWindowPos(hWndSelectedWindow, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); - SetWindowPos(hWndApplicationWindow, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); - - // Convert the HBITMAP to a FIBITMAP - copyFromBitmap(bm); - - // Free objects - DeleteObject(SelectObject(memDC, oldbm)); - DeleteDC(memDC); - - // Convert 32-bit images to 24-bit - if(getBitsPerPixel() == 32) { - convertTo24Bits(); - } - - return TRUE; -} - - -/////////////////////////////////////////////////////////////////// -// Painting operations - -void fipWinImage::drawEx(HDC hDC, RECT& rcDest, BOOL useFileBkg, RGBQUAD *appBkColor, FIBITMAP *bg) const { - // Convert to a standard bitmap if needed - if(_bHasChanged) { - if(_bDeleteMe) { - FreeImage_Unload(_display_dib); - _display_dib = NULL; - _bDeleteMe = FALSE; - } - - FREE_IMAGE_TYPE image_type = getImageType(); - if(image_type == FIT_BITMAP) { - BOOL bHasBackground = FreeImage_HasBackgroundColor(_dib); - BOOL bIsTransparent = FreeImage_IsTransparent(_dib); - - if(!bIsTransparent && (!bHasBackground || !useFileBkg)) { - // Copy pointer - _display_dib = _dib; - } - else { - // Create the transparent / alpha blended image - _display_dib = FreeImage_Composite(_dib, useFileBkg, appBkColor, bg); - if(_display_dib) { - // Remember to delete _display_dib - _bDeleteMe = TRUE; - } else { - // Something failed: copy pointers - _display_dib = _dib; - } - } - } else { - // Convert to a standard dib for display - - if(image_type == FIT_COMPLEX) { - // Convert to type FIT_DOUBLE - FIBITMAP *dib_double = FreeImage_GetComplexChannel(_dib, FICC_MAG); - // Convert to a standard bitmap (linear scaling) - _display_dib = FreeImage_ConvertToStandardType(dib_double, TRUE); - // Free image of type FIT_DOUBLE - FreeImage_Unload(dib_double); - } else if((image_type == FIT_RGBF) || (image_type == FIT_RGBAF) || (image_type == FIT_RGB16)) { - // Apply a tone mapping algorithm and convert to 24-bit - switch(_tmo) { - case FITMO_REINHARD05: - _display_dib = FreeImage_TmoReinhard05Ex(_dib, _tmo_param_1, _tmo_param_2, _tmo_param_3, _tmo_param_4); - break; - default: - _display_dib = FreeImage_ToneMapping(_dib, _tmo, _tmo_param_1, _tmo_param_2); - break; - } - } else if(image_type == FIT_RGBA16) { - // Convert to 32-bit - FIBITMAP *dib32 = FreeImage_ConvertTo32Bits(_dib); - if(dib32) { - // Create the transparent / alpha blended image - _display_dib = FreeImage_Composite(dib32, useFileBkg, appBkColor, bg); - FreeImage_Unload(dib32); - } - } else { - // Other cases: convert to a standard bitmap (linear scaling) - _display_dib = FreeImage_ConvertToStandardType(_dib, TRUE); - } - // Remember to delete _display_dib - _bDeleteMe = TRUE; - } - - _bHasChanged = FALSE; - } - - // Draw the dib - SetStretchBltMode(hDC, COLORONCOLOR); - StretchDIBits(hDC, rcDest.left, rcDest.top, - rcDest.right-rcDest.left, rcDest.bottom-rcDest.top, - 0, 0, FreeImage_GetWidth(_display_dib), FreeImage_GetHeight(_display_dib), - FreeImage_GetBits(_display_dib), FreeImage_GetInfo(_display_dib), DIB_RGB_COLORS, SRCCOPY); - -} - -void fipWinImage::setToneMappingOperator(FREE_IMAGE_TMO tmo, double first_param, double second_param, double third_param, double fourth_param) { - // avoid costly operations if possible ... - if((_tmo != tmo) || (_tmo_param_1 != first_param) || (_tmo_param_2 != second_param) || (_tmo_param_3 != third_param) || (_tmo_param_4 != fourth_param)) { - _tmo = tmo; - _tmo_param_1 = first_param; - _tmo_param_2 = second_param; - _tmo_param_3 = third_param; - _tmo_param_4 = fourth_param; - - FREE_IMAGE_TYPE image_type = getImageType(); - switch(image_type) { - case FIT_RGBF: - case FIT_RGBAF: - case FIT_RGB16: - case FIT_RGBA16: - _bHasChanged = TRUE; - break; - default: - break; - } - } -} - -void fipWinImage::getToneMappingOperator(FREE_IMAGE_TMO *tmo, double *first_param, double *second_param, double *third_param, double *fourth_param) const { - *tmo = _tmo; - *first_param = _tmo_param_1; - *second_param = _tmo_param_2; - *third_param = _tmo_param_3; - *fourth_param = _tmo_param_4; -} - - -#endif // _WIN32 +// ========================================================== +// fipWinImage class implementation +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImagePlus.h" + +#ifdef _WIN32 + +// marker used for clipboard copy / paste + +static inline void +SET_FREEIMAGE_MARKER(BITMAPINFOHEADER *bmih, FIBITMAP *dib) { + // Windows constants goes from 0L to 5L + // Add 0xFF to avoid conflicts + bmih->biCompression = 0xFF + FreeImage_GetImageType(dib); +} + +static inline FREE_IMAGE_TYPE +GET_FREEIMAGE_MARKER(BITMAPINFOHEADER *bmih) { + return (FREE_IMAGE_TYPE)(bmih->biCompression - 0xFF); +} + +/////////////////////////////////////////////////////////////////// +// Construction / Destruction + +fipWinImage::fipWinImage(FREE_IMAGE_TYPE image_type, unsigned width, unsigned height, unsigned bpp) : fipImage(image_type, width, height, bpp) { + _display_dib = NULL; + _bDeleteMe = FALSE; + // default tone mapping operator + _tmo = FITMO_DRAGO03; + _tmo_param_1 = 0; + _tmo_param_2 = 0; + _tmo_param_3 = 1; + _tmo_param_4 = 0; +} + +fipWinImage::~fipWinImage() { + if(_bDeleteMe) { + FreeImage_Unload(_display_dib); + } +} + +void fipWinImage::clear() { + // delete _display_dib + if(_bDeleteMe) { + FreeImage_Unload(_display_dib); + } + _display_dib = NULL; + _bDeleteMe = FALSE; + // delete base class data + fipImage::clear(); +} + +BOOL fipWinImage::isValid() const { + return fipImage::isValid(); +} + +/////////////////////////////////////////////////////////////////// +// Copying + +fipWinImage& fipWinImage::operator=(const fipImage& Image) { + // delete _display_dib + if(_bDeleteMe) { + FreeImage_Unload(_display_dib); + } + _display_dib = NULL; + _bDeleteMe = FALSE; + // clone the base class + fipImage::operator=(Image); + + return *this; +} + +fipWinImage& fipWinImage::operator=(const fipWinImage& Image) { + if(this != &Image) { + // delete _display_dib + if(_bDeleteMe) { + FreeImage_Unload(_display_dib); + } + _display_dib = NULL; + _bDeleteMe = FALSE; + // copy tmo data + _tmo = Image._tmo; + _tmo_param_1 = Image._tmo_param_1; + _tmo_param_2 = Image._tmo_param_2; + _tmo_param_3 = Image._tmo_param_3; + _tmo_param_4 = Image._tmo_param_4; + + // clone the base class + fipImage::operator=(Image); + } + return *this; +} + +HANDLE fipWinImage::copyToHandle() const { + HANDLE hMem = NULL; + + if(_dib) { + + // Get equivalent DIB size + long dib_size = sizeof(BITMAPINFOHEADER); + dib_size += FreeImage_GetColorsUsed(_dib) * sizeof(RGBQUAD); + dib_size += FreeImage_GetPitch(_dib) * FreeImage_GetHeight(_dib); + + // Allocate a DIB + hMem = GlobalAlloc(GHND, dib_size); + BYTE *dib = (BYTE*)GlobalLock(hMem); + + memset(dib, 0, dib_size); + + BYTE *p_dib = (BYTE*)dib; + + // Copy the BITMAPINFOHEADER + + BITMAPINFOHEADER *bih = FreeImage_GetInfoHeader(_dib); + memcpy(p_dib, bih, sizeof(BITMAPINFOHEADER)); + if(FreeImage_GetImageType(_dib) != FIT_BITMAP) { + // this hack is used to store the bitmap type in the biCompression member of the BITMAPINFOHEADER + SET_FREEIMAGE_MARKER((BITMAPINFOHEADER*)p_dib, _dib); + } + p_dib += sizeof(BITMAPINFOHEADER); + + // Copy the palette + + RGBQUAD *pal = FreeImage_GetPalette(_dib); + memcpy(p_dib, pal, FreeImage_GetColorsUsed(_dib) * sizeof(RGBQUAD)); + p_dib += FreeImage_GetColorsUsed(_dib) * sizeof(RGBQUAD); + + // Copy the bitmap + + BYTE *bits = FreeImage_GetBits(_dib); + memcpy(p_dib, bits, FreeImage_GetPitch(_dib) * FreeImage_GetHeight(_dib)); + + GlobalUnlock(hMem); + } + + return hMem; +} + +BOOL fipWinImage::copyFromHandle(HANDLE hMem) { + BYTE *lpVoid = NULL; + BITMAPINFOHEADER *pHead = NULL; + RGBQUAD *pPalette = NULL; + BYTE *bits = NULL; + DWORD bitfields[3] = {0, 0, 0}; + + // Get a pointer to the bitmap + lpVoid = (BYTE *)GlobalLock(hMem); + + // Get a pointer to the bitmap header + pHead = (BITMAPINFOHEADER *)lpVoid; + + // Get a pointer to the palette + if(pHead->biBitCount < 16) + pPalette = (RGBQUAD *)(((BYTE *)pHead) + sizeof(BITMAPINFOHEADER)); + + // Get a pointer to the pixels + bits = ((BYTE*)pHead + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * pHead->biClrUsed); + + if(pHead->biCompression == BI_BITFIELDS) { + // Take into account the color masks that specify the red, green, and blue components (16- and 32-bit) + unsigned mask_size = 3 * sizeof(DWORD); + memcpy(&bitfields[0], bits, mask_size); + bits += mask_size; + } + + if(lpVoid) { + + // Allocate a new FIBITMAP + + FREE_IMAGE_TYPE image_type = FIT_BITMAP; + // Use a hack to decide if the clipboard contains non standard bitmaps ... + switch(GET_FREEIMAGE_MARKER(pHead)) { + case FIT_UINT16: + case FIT_INT16: + case FIT_UINT32: + case FIT_INT32: + case FIT_FLOAT: + case FIT_DOUBLE: + case FIT_COMPLEX: + case FIT_RGB16: + case FIT_RGBA16: + case FIT_RGBF: + case FIT_RGBAF: + image_type = GET_FREEIMAGE_MARKER(pHead); + break; + } + if(!setSize(image_type, (WORD)pHead->biWidth, (WORD)pHead->biHeight, pHead->biBitCount, bitfields[2], bitfields[1], bitfields[0])) { + GlobalUnlock(lpVoid); + return FALSE; + } + + // Copy the bitmap header + memcpy(FreeImage_GetInfoHeader(_dib), pHead, sizeof(BITMAPINFOHEADER)); + + + // Copy the palette + memcpy(FreeImage_GetPalette(_dib), pPalette, pHead->biClrUsed * sizeof(RGBQUAD)); + + // Copy the bitmap + memcpy(FreeImage_GetBits(_dib), bits, FreeImage_GetPitch(_dib) * FreeImage_GetHeight(_dib)); + + GlobalUnlock(lpVoid); + + return TRUE; + } + + return FALSE; +} + +BOOL fipWinImage::copyFromBitmap(HBITMAP hbmp) { + if(hbmp) { + int Success; + BITMAP bm; + // Get informations about the bitmap + GetObject(hbmp, sizeof(BITMAP), (LPSTR) &bm); + // Create the image + setSize(FIT_BITMAP, (WORD)bm.bmWidth, (WORD)bm.bmHeight, (WORD)bm.bmBitsPixel); + + // The GetDIBits function clears the biClrUsed and biClrImportant BITMAPINFO members (dont't know why) + // So we save these infos below. This is needed for palettized images only. + int nColors = FreeImage_GetColorsUsed(_dib); + + // Create a device context for the bitmap + HDC dc = GetDC(NULL); + // Copy the pixels + Success = GetDIBits(dc, // handle to DC + hbmp, // handle to bitmap + 0, // first scan line to set + FreeImage_GetHeight(_dib), // number of scan lines to copy + FreeImage_GetBits(_dib), // array for bitmap bits + FreeImage_GetInfo(_dib), // bitmap data buffer + DIB_RGB_COLORS // RGB + ); + if(Success == 0) { + FreeImage_OutputMessageProc(FIF_UNKNOWN, "Error : GetDIBits failed"); + ReleaseDC(NULL, dc); + return FALSE; + } + ReleaseDC(NULL, dc); + + // restore BITMAPINFO members + + FreeImage_GetInfoHeader(_dib)->biClrUsed = nColors; + FreeImage_GetInfoHeader(_dib)->biClrImportant = nColors; + + return TRUE; + } + + return FALSE; +} + +BOOL fipWinImage::copyToClipboard(HWND hWndNewOwner) const { + HANDLE hDIB = copyToHandle(); + + if(OpenClipboard(hWndNewOwner)) { + if(EmptyClipboard()) { + if(SetClipboardData(CF_DIB, hDIB) == NULL) { + MessageBox(hWndNewOwner, "Unable to set Clipboard data", "FreeImage", MB_ICONERROR); + CloseClipboard(); + return FALSE; + } + } + } + CloseClipboard(); + + return TRUE; +} + +BOOL fipWinImage::pasteFromClipboard() { + if(!IsClipboardFormatAvailable(CF_DIB)) + return FALSE; + + if(OpenClipboard(NULL)) { + HANDLE hDIB = GetClipboardData(CF_DIB); + copyFromHandle(hDIB); + CloseClipboard(); + return TRUE; + } + CloseClipboard(); + + return FALSE; +} + +/////////////////////////////////////////////////////////////////// +// Screen capture + +BOOL fipWinImage::captureWindow(HWND hWndApplicationWindow, HWND hWndSelectedWindow) { + int xScreen, yScreen, xshift, yshift; + RECT r; + + // Get window size + GetWindowRect(hWndSelectedWindow, &r); + + // Check if the window is out of the screen or maximixed + xshift = 0; + yshift = 0; + xScreen = GetSystemMetrics(SM_CXSCREEN); + yScreen = GetSystemMetrics(SM_CYSCREEN); + if(r.right > xScreen) + r.right = xScreen; + if(r.bottom > yScreen) + r.bottom = yScreen; + if(r.left < 0) { + xshift = -r.left; + r.left = 0; + } + if(r.top < 0){ + yshift = -r.top; + r.top = 0; + } + + int width = r.right - r.left; + int height = r.bottom - r.top; + + if(width <= 0 || height <= 0) + return FALSE; + + // Hide the application window. + ShowWindow(hWndApplicationWindow, SW_HIDE); + // Bring the window at the top most level + SetWindowPos(hWndSelectedWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + // Give enough time to refresh the window + Sleep(500); + + // Prepare the DCs + HDC dstDC = GetDC(NULL); + HDC srcDC = GetWindowDC(hWndSelectedWindow); // full window (GetDC(hWndSelectedWindow) = clientarea) + HDC memDC = CreateCompatibleDC(dstDC); + + // Copy the screen to the bitmap + HBITMAP bm = CreateCompatibleBitmap(dstDC, width, height); + HBITMAP oldbm = (HBITMAP)SelectObject(memDC, bm); + BitBlt(memDC, 0, 0, width, height, srcDC, xshift, yshift, SRCCOPY); + + // Redraw the application window. + ShowWindow(hWndApplicationWindow, SW_SHOW); + + // Restore the position + SetWindowPos(hWndSelectedWindow, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + SetWindowPos(hWndApplicationWindow, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + + // Convert the HBITMAP to a FIBITMAP + copyFromBitmap(bm); + + // Free objects + DeleteObject(SelectObject(memDC, oldbm)); + DeleteDC(memDC); + + // Convert 32-bit images to 24-bit + if(getBitsPerPixel() == 32) { + convertTo24Bits(); + } + + return TRUE; +} + + +/////////////////////////////////////////////////////////////////// +// Painting operations + +void fipWinImage::drawEx(HDC hDC, RECT& rcDest, BOOL useFileBkg, RGBQUAD *appBkColor, FIBITMAP *bg) const { + // Convert to a standard bitmap if needed + if(_bHasChanged) { + if(_bDeleteMe) { + FreeImage_Unload(_display_dib); + _display_dib = NULL; + _bDeleteMe = FALSE; + } + + FREE_IMAGE_TYPE image_type = getImageType(); + if(image_type == FIT_BITMAP) { + BOOL bHasBackground = FreeImage_HasBackgroundColor(_dib); + BOOL bIsTransparent = FreeImage_IsTransparent(_dib); + + if(!bIsTransparent && (!bHasBackground || !useFileBkg)) { + // Copy pointer + _display_dib = _dib; + } + else { + // Create the transparent / alpha blended image + _display_dib = FreeImage_Composite(_dib, useFileBkg, appBkColor, bg); + if(_display_dib) { + // Remember to delete _display_dib + _bDeleteMe = TRUE; + } else { + // Something failed: copy pointers + _display_dib = _dib; + } + } + } else { + // Convert to a standard dib for display + + if(image_type == FIT_COMPLEX) { + // Convert to type FIT_DOUBLE + FIBITMAP *dib_double = FreeImage_GetComplexChannel(_dib, FICC_MAG); + // Convert to a standard bitmap (linear scaling) + _display_dib = FreeImage_ConvertToStandardType(dib_double, TRUE); + // Free image of type FIT_DOUBLE + FreeImage_Unload(dib_double); + } else if((image_type == FIT_RGBF) || (image_type == FIT_RGBAF) || (image_type == FIT_RGB16)) { + // Apply a tone mapping algorithm and convert to 24-bit + switch(_tmo) { + case FITMO_REINHARD05: + _display_dib = FreeImage_TmoReinhard05Ex(_dib, _tmo_param_1, _tmo_param_2, _tmo_param_3, _tmo_param_4); + break; + default: + _display_dib = FreeImage_ToneMapping(_dib, _tmo, _tmo_param_1, _tmo_param_2); + break; + } + } else if(image_type == FIT_RGBA16) { + // Convert to 32-bit + FIBITMAP *dib32 = FreeImage_ConvertTo32Bits(_dib); + if(dib32) { + // Create the transparent / alpha blended image + _display_dib = FreeImage_Composite(dib32, useFileBkg, appBkColor, bg); + FreeImage_Unload(dib32); + } + } else { + // Other cases: convert to a standard bitmap (linear scaling) + _display_dib = FreeImage_ConvertToStandardType(_dib, TRUE); + } + // Remember to delete _display_dib + _bDeleteMe = TRUE; + } + + _bHasChanged = FALSE; + } + + // Draw the dib + SetStretchBltMode(hDC, COLORONCOLOR); + StretchDIBits(hDC, rcDest.left, rcDest.top, + rcDest.right-rcDest.left, rcDest.bottom-rcDest.top, + 0, 0, FreeImage_GetWidth(_display_dib), FreeImage_GetHeight(_display_dib), + FreeImage_GetBits(_display_dib), FreeImage_GetInfo(_display_dib), DIB_RGB_COLORS, SRCCOPY); + +} + +void fipWinImage::setToneMappingOperator(FREE_IMAGE_TMO tmo, double first_param, double second_param, double third_param, double fourth_param) { + // avoid costly operations if possible ... + if((_tmo != tmo) || (_tmo_param_1 != first_param) || (_tmo_param_2 != second_param) || (_tmo_param_3 != third_param) || (_tmo_param_4 != fourth_param)) { + _tmo = tmo; + _tmo_param_1 = first_param; + _tmo_param_2 = second_param; + _tmo_param_3 = third_param; + _tmo_param_4 = fourth_param; + + FREE_IMAGE_TYPE image_type = getImageType(); + switch(image_type) { + case FIT_RGBF: + case FIT_RGBAF: + case FIT_RGB16: + case FIT_RGBA16: + _bHasChanged = TRUE; + break; + default: + break; + } + } +} + +void fipWinImage::getToneMappingOperator(FREE_IMAGE_TMO *tmo, double *first_param, double *second_param, double *third_param, double *fourth_param) const { + *tmo = _tmo; + *first_param = _tmo_param_1; + *second_param = _tmo_param_2; + *third_param = _tmo_param_3; + *fourth_param = _tmo_param_4; +} + + +#endif // _WIN32 diff --git a/Wrapper/FreeImagePlus/test/fipTest.cpp b/Wrapper/FreeImagePlus/test/fipTest.cpp index 0501c6f..49864e7 100644 --- a/Wrapper/FreeImagePlus/test/fipTest.cpp +++ b/Wrapper/FreeImagePlus/test/fipTest.cpp @@ -1,76 +1,76 @@ -// ========================================================== -// FreeImagePlus Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "fipTest.h" - -using namespace std; - -// ---------------------------------------------------------- - -/** - FreeImage error handler - @param fif Format / Plugin responsible for the error - @param message Error message -*/ -void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) { - cout << "\n*** "; - if(fif != FIF_UNKNOWN) { - cout << FreeImage_GetFormatFromFIF(fif) << " Format\n"; - } - cout << message; - cout << " ***\n"; -} - -// ---------------------------------------------------------- - -int main(int argc, char *argv[]) { - char *lpszTestFile = "test.jpg"; - char *lpszMultiPage = "test.tif"; - -#if defined(FREEIMAGE_LIB) || !defined(WIN32) - FreeImage_Initialise(); -#endif - - // initialize our own FreeImage error handler - - FreeImage_SetOutputMessage(FreeImageErrorHandler); - - // test memory IO - testMemIO(lpszTestFile); - - // test multipage IO - testMultiPage(lpszMultiPage); - - // test multipage memory IO - testMultiPageMemory(lpszMultiPage); - - // test multipage stream IO - testStreamMultiPage(lpszMultiPage); - -#if defined(FREEIMAGE_LIB) || !defined(WIN32) - FreeImage_DeInitialise(); -#endif - - return 0; -} - - +// ========================================================== +// FreeImagePlus Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "fipTest.h" + +using namespace std; + +// ---------------------------------------------------------- + +/** + FreeImage error handler + @param fif Format / Plugin responsible for the error + @param message Error message +*/ +void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) { + cout << "\n*** "; + if(fif != FIF_UNKNOWN) { + cout << FreeImage_GetFormatFromFIF(fif) << " Format\n"; + } + cout << message; + cout << " ***\n"; +} + +// ---------------------------------------------------------- + +int main(int argc, char *argv[]) { + char *lpszTestFile = "test.jpg"; + char *lpszMultiPage = "test.tif"; + +#if defined(FREEIMAGE_LIB) || !defined(WIN32) + FreeImage_Initialise(); +#endif + + // initialize our own FreeImage error handler + + FreeImage_SetOutputMessage(FreeImageErrorHandler); + + // test memory IO + testMemIO(lpszTestFile); + + // test multipage IO + testMultiPage(lpszMultiPage); + + // test multipage memory IO + testMultiPageMemory(lpszMultiPage); + + // test multipage stream IO + testStreamMultiPage(lpszMultiPage); + +#if defined(FREEIMAGE_LIB) || !defined(WIN32) + FreeImage_DeInitialise(); +#endif + + return 0; +} + + diff --git a/Wrapper/FreeImagePlus/test/fipTestMPage.cpp b/Wrapper/FreeImagePlus/test/fipTestMPage.cpp index 4b81b17..2e3e662 100644 --- a/Wrapper/FreeImagePlus/test/fipTestMPage.cpp +++ b/Wrapper/FreeImagePlus/test/fipTestMPage.cpp @@ -1,82 +1,82 @@ -// ========================================================== -// FreeImagePlus Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "fipTest.h" - -using namespace std; - -// -------------------------------------------------------------------------- -// Multipage test scripts - -BOOL testCloneMultiPage(const char *input, const char *output, int output_flag) { - - BOOL bMemoryCache = TRUE; - - fipMultiPage src(bMemoryCache); - fipMultiPage dst(bMemoryCache); - - // You MUST declare this before using it. - // We will use the assignement operator, i.e. operator=() - fipImage image; - - // Open src file (read-only, use memory cache) - src.open(input, FALSE, TRUE); - - if(src.isValid()) { - // Open dst file (creation, use memory cache) - dst.open(output, TRUE, FALSE); - - // Get src page count - int count = src.getPageCount(); - - // Clone src to dst - for(int page = 0; page < count; page++) { - // Load the bitmap at position 'page' - image = src.lockPage(page); - if(image.isValid()) { - // add a new bitmap to dst - dst.appendPage(image); - // Unload the bitmap (do not apply any change to src) - src.unlockPage(image, FALSE); - } - } - - // Close src - src.close(0); - // Save and close dst - dst.close(output_flag); - - return TRUE; - } - - return FALSE; -} - -// ---------------------------------------------------------- - -void testMultiPage(const char *lpszMultiPage) { - cout << "testMultiPage ...\n"; - - testCloneMultiPage(lpszMultiPage, "clone.tif", 0); -} - - +// ========================================================== +// FreeImagePlus Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "fipTest.h" + +using namespace std; + +// -------------------------------------------------------------------------- +// Multipage test scripts + +BOOL testCloneMultiPage(const char *input, const char *output, int output_flag) { + + BOOL bMemoryCache = TRUE; + + fipMultiPage src(bMemoryCache); + fipMultiPage dst(bMemoryCache); + + // You MUST declare this before using it. + // We will use the assignement operator, i.e. operator=() + fipImage image; + + // Open src file (read-only, use memory cache) + src.open(input, FALSE, TRUE); + + if(src.isValid()) { + // Open dst file (creation, use memory cache) + dst.open(output, TRUE, FALSE); + + // Get src page count + int count = src.getPageCount(); + + // Clone src to dst + for(int page = 0; page < count; page++) { + // Load the bitmap at position 'page' + image = src.lockPage(page); + if(image.isValid()) { + // add a new bitmap to dst + dst.appendPage(image); + // Unload the bitmap (do not apply any change to src) + src.unlockPage(image, FALSE); + } + } + + // Close src + src.close(0); + // Save and close dst + dst.close(output_flag); + + return TRUE; + } + + return FALSE; +} + +// ---------------------------------------------------------- + +void testMultiPage(const char *lpszMultiPage) { + cout << "testMultiPage ...\n"; + + testCloneMultiPage(lpszMultiPage, "clone.tif", 0); +} + + diff --git a/Wrapper/FreeImagePlus/test/fipTestMPageMemory.cpp b/Wrapper/FreeImagePlus/test/fipTestMPageMemory.cpp index f184396..4144f3f 100644 --- a/Wrapper/FreeImagePlus/test/fipTestMPageMemory.cpp +++ b/Wrapper/FreeImagePlus/test/fipTestMPageMemory.cpp @@ -1,276 +1,276 @@ -// ========================================================== -// FreeImagePlus Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "fipTest.h" - -using namespace std; - -// -------------------------------------------------------------------------- - -static BOOL -loadBuffer(const char *lpszPathName, BYTE **buffer, DWORD *length) { - struct stat file_info; - int result; - - // get data associated with lpszPathName - result = stat(lpszPathName, &file_info); - if(result == 0) { - // allocate a memory buffer and load temporary data - *buffer = (BYTE*)malloc(file_info.st_size * sizeof(BYTE)); - if(*buffer) { - FILE *stream = fopen(lpszPathName, "rb"); - if(stream) { - *length = (DWORD)fread(*buffer, sizeof(BYTE), file_info.st_size, stream); - fclose(stream); - - return TRUE; - } - } - } - - return FALSE; -} - -static BOOL -extractPagesFromMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO) { - BOOL bMemoryCache = TRUE; - - char filename[256]; - fipImage image; - - // open the multipage bitmap stream as read-only - fipMultiPage src(bMemoryCache); - - src.open(memIO); - - if(src.isValid()) { - // get the page count - int count = src.getPageCount(); - // extract all pages - for(int page = 0; page < count; page++) { - // load the bitmap at position 'page' - image = src.lockPage(page); - if(image.isValid()) { - // save the page - sprintf(filename, "page%d.%s", page, FreeImage_GetFormatFromFIF(fif)); - image.save(filename, 0); - // Unload the bitmap (do not apply any change to src) - src.unlockPage(image, FALSE); - } else { - // an error occured: free the multipage bitmap handle (fipMultiPage destructor) and return - src.close(0); - return FALSE; - } - } - } - // make sure to close the multipage bitmap handle on exit (fipMultiPage destructor or direct call to src.close(0)) - return src.close(0); -} - -BOOL testLoadMultiBitmapFromMemory(const char *lpszPathName) { - BOOL bSuccess = FALSE; - - BYTE *buffer = NULL; - DWORD buffer_size = 0; - - // load source stream as a buffer, i.e. - // allocate a memory buffer and load temporary data - bSuccess = loadBuffer(lpszPathName, &buffer, &buffer_size); - assert(bSuccess); - - if(bSuccess) { - // attach the binary data to a memory stream - fipMemoryIO memIO(buffer, buffer_size); - - // get the file type - FREE_IMAGE_FORMAT fif = memIO.getFileType(); - - // extract pages - bSuccess = extractPagesFromMemory(fif, memIO); - assert(bSuccess); - - // close the memory stream (memIO destructor) - } - - // user is responsible for freeing the data - free(buffer); - - return bSuccess; -} - -// -------------------------------------------------------------------------- - -BOOL testSaveMultiBitmapToMemory(const char *input, const char *output, int output_flag) { - BOOL bSuccess; - - BOOL bCreateNew = FALSE; - BOOL bReadOnly = TRUE; - BOOL bMemoryCache = TRUE; - - // Open src file (read-only, use memory cache) - fipMultiPage src(bMemoryCache); - src.open(input, bCreateNew, bReadOnly, 0); - - if(src.isValid()) { - // open and allocate a memory stream - fipMemoryIO memIO; - - // save the file to memory - FREE_IMAGE_FORMAT fif = fipImage::identifyFIF(output); - bSuccess = src.saveToMemory(fif, memIO, output_flag); - assert(bSuccess); - - // src is no longer needed: close and free src file - src.close(0); - - // get the buffer from the memory stream - BYTE *mem_buffer = NULL; - DWORD size_in_bytes = 0; - - bSuccess = memIO.acquire(&mem_buffer, &size_in_bytes); - assert(bSuccess); - - // save the buffer in a file stream - FILE *stream = fopen(output, "wb"); - if(stream) { - fwrite(mem_buffer, sizeof(BYTE), size_in_bytes, stream); - fclose(stream); - } - - // close and free the memory stream (memIO destructor) - - return TRUE; - } - - return FALSE; -} - -BOOL testMemoryStreamMultiPageOpenSave(const char *lpszPathName, char *output, int input_flag, int output_flag) { - BOOL bSuccess = FALSE; - - BYTE *buffer = NULL; - DWORD buffer_size = 0; - - // load source stream as a buffer, i.e. - // allocate a memory buffer and load temporary data - bSuccess = loadBuffer(lpszPathName, &buffer, &buffer_size); - assert(bSuccess); - - // attach the binary data to a memory stream - fipMemoryIO src_stream(buffer, buffer_size); - assert(src_stream.isValid()); - - // open the multipage bitmap stream - fipMultiPage src; - src.open(src_stream, input_flag); - - // apply some modifications (everything being stored to the cache) ... - - if(src.isValid()) { - fipImage image; - - // get the page count - int count = src.getPageCount(); - assert(count > 2); - - // Load the bitmap at position '2' - image = src.lockPage(2); - if(image.isValid()) { - image.invert(); - // Unload the bitmap (apply change to src, modifications are stored to the cache) - src.unlockPage(image, TRUE); - } - - // delete page 0 (modifications are stored to the cache) - src.deletePage(0); - - // insert a new page at position '0' (modifications are stored to the cache) - image.load("test.jpg"); - src.insertPage(0, image); - } - - // save the modification into the output stream ... - - if(src.isValid()) { - // open and allocate a memory stream - fipMemoryIO dst_stream; - assert(dst_stream.isValid()); - - // save the file to memory - FREE_IMAGE_FORMAT fif = fipImage::identifyFIF(output); - src.saveToMemory(fif, dst_stream, output_flag); - - // src is no longer needed - // close and free the memory stream - src_stream.close(); - // close and free src file (nothing is done, the cache is cleared) - src.close(0); - - // at this point, the input buffer is no longer needed - // !!! user is responsible for freeing the initial source buffer !!! - free(buffer); buffer = NULL; - - // get the dst buffer from the memory stream - BYTE *dst_buffer = NULL; - DWORD size_in_bytes = 0; - - dst_stream.acquire(&dst_buffer, &size_in_bytes); - - // save the buffer in a file stream - FILE *stream = fopen(output, "wb"); - if(stream) { - fwrite(dst_buffer, sizeof(BYTE), size_in_bytes, stream); - fclose(stream); - } - - // close and free the memory stream (destructor is called) - - return TRUE; - } - - if(buffer) { - free(buffer); - } - - return FALSE; -} - -// -------------------------------------------------------------------------- - -void testMultiPageMemory(const char *lpszPathName) { - BOOL bSuccess; - - cout << "testMultiPageMemory ...\n"; - - // test FreeImage_LoadMultiBitmapFromMemory - bSuccess = testLoadMultiBitmapFromMemory(lpszPathName); - assert(bSuccess); - - // test FreeImage_SaveMultiBitmapToMemory - bSuccess = testSaveMultiBitmapToMemory(lpszPathName, "mpage-mstream.tif", 0); - assert(bSuccess); - - // test FreeImage_LoadMultiBitmapFromMemory & FreeImage_SaveMultiBitmapToMemory - bSuccess = testMemoryStreamMultiPageOpenSave(lpszPathName, "mpage-mstream-redirect.tif", 0, 0); - assert(bSuccess); - -} +// ========================================================== +// FreeImagePlus Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "fipTest.h" + +using namespace std; + +// -------------------------------------------------------------------------- + +static BOOL +loadBuffer(const char *lpszPathName, BYTE **buffer, DWORD *length) { + struct stat file_info; + int result; + + // get data associated with lpszPathName + result = stat(lpszPathName, &file_info); + if(result == 0) { + // allocate a memory buffer and load temporary data + *buffer = (BYTE*)malloc(file_info.st_size * sizeof(BYTE)); + if(*buffer) { + FILE *stream = fopen(lpszPathName, "rb"); + if(stream) { + *length = (DWORD)fread(*buffer, sizeof(BYTE), file_info.st_size, stream); + fclose(stream); + + return TRUE; + } + } + } + + return FALSE; +} + +static BOOL +extractPagesFromMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO) { + BOOL bMemoryCache = TRUE; + + char filename[256]; + fipImage image; + + // open the multipage bitmap stream as read-only + fipMultiPage src(bMemoryCache); + + src.open(memIO); + + if(src.isValid()) { + // get the page count + int count = src.getPageCount(); + // extract all pages + for(int page = 0; page < count; page++) { + // load the bitmap at position 'page' + image = src.lockPage(page); + if(image.isValid()) { + // save the page + sprintf(filename, "page%d.%s", page, FreeImage_GetFormatFromFIF(fif)); + image.save(filename, 0); + // Unload the bitmap (do not apply any change to src) + src.unlockPage(image, FALSE); + } else { + // an error occured: free the multipage bitmap handle (fipMultiPage destructor) and return + src.close(0); + return FALSE; + } + } + } + // make sure to close the multipage bitmap handle on exit (fipMultiPage destructor or direct call to src.close(0)) + return src.close(0); +} + +BOOL testLoadMultiBitmapFromMemory(const char *lpszPathName) { + BOOL bSuccess = FALSE; + + BYTE *buffer = NULL; + DWORD buffer_size = 0; + + // load source stream as a buffer, i.e. + // allocate a memory buffer and load temporary data + bSuccess = loadBuffer(lpszPathName, &buffer, &buffer_size); + assert(bSuccess); + + if(bSuccess) { + // attach the binary data to a memory stream + fipMemoryIO memIO(buffer, buffer_size); + + // get the file type + FREE_IMAGE_FORMAT fif = memIO.getFileType(); + + // extract pages + bSuccess = extractPagesFromMemory(fif, memIO); + assert(bSuccess); + + // close the memory stream (memIO destructor) + } + + // user is responsible for freeing the data + free(buffer); + + return bSuccess; +} + +// -------------------------------------------------------------------------- + +BOOL testSaveMultiBitmapToMemory(const char *input, const char *output, int output_flag) { + BOOL bSuccess; + + BOOL bCreateNew = FALSE; + BOOL bReadOnly = TRUE; + BOOL bMemoryCache = TRUE; + + // Open src file (read-only, use memory cache) + fipMultiPage src(bMemoryCache); + src.open(input, bCreateNew, bReadOnly, 0); + + if(src.isValid()) { + // open and allocate a memory stream + fipMemoryIO memIO; + + // save the file to memory + FREE_IMAGE_FORMAT fif = fipImage::identifyFIF(output); + bSuccess = src.saveToMemory(fif, memIO, output_flag); + assert(bSuccess); + + // src is no longer needed: close and free src file + src.close(0); + + // get the buffer from the memory stream + BYTE *mem_buffer = NULL; + DWORD size_in_bytes = 0; + + bSuccess = memIO.acquire(&mem_buffer, &size_in_bytes); + assert(bSuccess); + + // save the buffer in a file stream + FILE *stream = fopen(output, "wb"); + if(stream) { + fwrite(mem_buffer, sizeof(BYTE), size_in_bytes, stream); + fclose(stream); + } + + // close and free the memory stream (memIO destructor) + + return TRUE; + } + + return FALSE; +} + +BOOL testMemoryStreamMultiPageOpenSave(const char *lpszPathName, char *output, int input_flag, int output_flag) { + BOOL bSuccess = FALSE; + + BYTE *buffer = NULL; + DWORD buffer_size = 0; + + // load source stream as a buffer, i.e. + // allocate a memory buffer and load temporary data + bSuccess = loadBuffer(lpszPathName, &buffer, &buffer_size); + assert(bSuccess); + + // attach the binary data to a memory stream + fipMemoryIO src_stream(buffer, buffer_size); + assert(src_stream.isValid()); + + // open the multipage bitmap stream + fipMultiPage src; + src.open(src_stream, input_flag); + + // apply some modifications (everything being stored to the cache) ... + + if(src.isValid()) { + fipImage image; + + // get the page count + int count = src.getPageCount(); + assert(count > 2); + + // Load the bitmap at position '2' + image = src.lockPage(2); + if(image.isValid()) { + image.invert(); + // Unload the bitmap (apply change to src, modifications are stored to the cache) + src.unlockPage(image, TRUE); + } + + // delete page 0 (modifications are stored to the cache) + src.deletePage(0); + + // insert a new page at position '0' (modifications are stored to the cache) + image.load("test.jpg"); + src.insertPage(0, image); + } + + // save the modification into the output stream ... + + if(src.isValid()) { + // open and allocate a memory stream + fipMemoryIO dst_stream; + assert(dst_stream.isValid()); + + // save the file to memory + FREE_IMAGE_FORMAT fif = fipImage::identifyFIF(output); + src.saveToMemory(fif, dst_stream, output_flag); + + // src is no longer needed + // close and free the memory stream + src_stream.close(); + // close and free src file (nothing is done, the cache is cleared) + src.close(0); + + // at this point, the input buffer is no longer needed + // !!! user is responsible for freeing the initial source buffer !!! + free(buffer); buffer = NULL; + + // get the dst buffer from the memory stream + BYTE *dst_buffer = NULL; + DWORD size_in_bytes = 0; + + dst_stream.acquire(&dst_buffer, &size_in_bytes); + + // save the buffer in a file stream + FILE *stream = fopen(output, "wb"); + if(stream) { + fwrite(dst_buffer, sizeof(BYTE), size_in_bytes, stream); + fclose(stream); + } + + // close and free the memory stream (destructor is called) + + return TRUE; + } + + if(buffer) { + free(buffer); + } + + return FALSE; +} + +// -------------------------------------------------------------------------- + +void testMultiPageMemory(const char *lpszPathName) { + BOOL bSuccess; + + cout << "testMultiPageMemory ...\n"; + + // test FreeImage_LoadMultiBitmapFromMemory + bSuccess = testLoadMultiBitmapFromMemory(lpszPathName); + assert(bSuccess); + + // test FreeImage_SaveMultiBitmapToMemory + bSuccess = testSaveMultiBitmapToMemory(lpszPathName, "mpage-mstream.tif", 0); + assert(bSuccess); + + // test FreeImage_LoadMultiBitmapFromMemory & FreeImage_SaveMultiBitmapToMemory + bSuccess = testMemoryStreamMultiPageOpenSave(lpszPathName, "mpage-mstream-redirect.tif", 0, 0); + assert(bSuccess); + +} diff --git a/Wrapper/FreeImagePlus/test/fipTestMPageStream.cpp b/Wrapper/FreeImagePlus/test/fipTestMPageStream.cpp index c76c90c..86dc7c7 100644 --- a/Wrapper/FreeImagePlus/test/fipTestMPageStream.cpp +++ b/Wrapper/FreeImagePlus/test/fipTestMPageStream.cpp @@ -1,222 +1,222 @@ -// ========================================================== -// FreeImagePlus Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "fipTest.h" - -using namespace std; - -// -------------------------------------------------------------------------- - -static unsigned DLL_CALLCONV -myReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { - return fread(buffer, size, count, (FILE *)handle); -} - -static unsigned DLL_CALLCONV -myWriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { - return fwrite(buffer, size, count, (FILE *)handle); -} - -static int DLL_CALLCONV -mySeekProc(fi_handle handle, long offset, int origin) { - return fseek((FILE *)handle, offset, origin); -} - -static long DLL_CALLCONV -myTellProc(fi_handle handle) { - return ftell((FILE *)handle); -} - -BOOL testStreamMultiPageOpen(const char *input, int flags) { - // initialize your own IO functions - - FreeImageIO io; - - io.read_proc = myReadProc; - io.write_proc = myWriteProc; - io.seek_proc = mySeekProc; - io.tell_proc = myTellProc; - - BOOL bSuccess = FALSE; - - // Open src stream in read-only mode - FILE *file = fopen(input, "r+b"); - if (file != NULL) { - fipMultiPage src; - - // Open the multi-page file - src.open(&io, (fi_handle)file, flags); - - if(src.isValid()) { - // get the page count - int count = src.getPageCount(); - assert(count > 1); - - // delete page 0 (modifications are stored to the cache) - src.deletePage(0); - - // Close src file (nothing is done, the cache is cleared) - bSuccess = src.close(0); - assert(bSuccess); - } - - // Close the src stream - fclose(file); - - return bSuccess; - } - - return bSuccess; -} - -BOOL testStreamMultiPageSave(const char *input, const char *output, int input_flag, int output_flag) { - // initialize your own IO functions - - FreeImageIO io; - - io.read_proc = myReadProc; - io.write_proc = myWriteProc; - io.seek_proc = mySeekProc; - io.tell_proc = myTellProc; - - BOOL bCreateNew = FALSE; - BOOL bReadOnly = TRUE; - BOOL bMemoryCache = TRUE; - - // Open src file (read-only, use memory cache) - fipMultiPage src(bMemoryCache); - src.open(input, bCreateNew, bReadOnly, input_flag); - - if(src.isValid()) { - // Open dst stream in read/write mode - FILE *file = fopen(output, "w+b"); - if (file != NULL) { - // Save the multi-page file to the stream - FREE_IMAGE_FORMAT fif = fipImage::identifyFIF(output); - BOOL bSuccess = src.saveToHandle(fif, &io, (fi_handle)file, output_flag); - assert(bSuccess); - - // Close the dst stream - fclose(file); - - // Close src file (or let the destructor close it) - return src.close(0); - - return TRUE; - } - - // Close src file (or let the destructor close it) - src.close(0); - } - - return FALSE; -} - -BOOL testStreamMultiPageOpenSave(const char *input, const char *output, int input_flag, int output_flag) { - // initialize your own IO functions - - FreeImageIO io; - - io.read_proc = myReadProc; - io.write_proc = myWriteProc; - io.seek_proc = mySeekProc; - io.tell_proc = myTellProc; - - BOOL bSuccess = FALSE; - - // Open src stream in read-only mode - FILE *src_file = fopen(input, "r+b"); - assert(src_file); - if (src_file != NULL) { - fipMultiPage src; - // Open the multi-page file - src.open(&io, (fi_handle)src_file, input_flag); - - if(src.isValid()) { - fipImage image; - - // get the page count - int count = src.getPageCount(); - assert(count > 2); - - // Load the bitmap at position '2' - image = src.lockPage(2); - if(image.isValid()) { - image.invert(); - // Unload the bitmap (apply change to src, modifications are stored to the cache) - src.unlockPage(image, TRUE); - } - - // delete page 0 (modifications are stored to the cache) - src.deletePage(0); - - // insert a new page at position '0' (modifications are stored to the cache) - image.load("test.jpg"); - src.insertPage(0, image); - - // Open dst stream in read/write mode - FILE *dst_file = fopen(output, "w+b"); - assert(dst_file); - if (dst_file != NULL) { - // Save the multi-page file to the stream (modifications are applied) - FREE_IMAGE_FORMAT fif = fipImage::identifyFIF(output); - BOOL bSuccess = src.saveToHandle(fif, &io, (fi_handle)dst_file, output_flag); - assert(bSuccess); - - // Close the dst stream - fclose(dst_file); - } - - // Close src file (nothing is done, the cache is cleared) - bSuccess = src.close(0); - assert(bSuccess); - } - - // Close the src stream - fclose(src_file); - - return bSuccess; - } - - return FALSE; -} - -// -------------------------------------------------------------------------- - -void testStreamMultiPage(const char *lpszPathName) { - BOOL bSuccess; - - cout << "testStreamMultiPage ...\n"; - - // test multipage stream (opening) - bSuccess = testStreamMultiPageOpen(lpszPathName, 0); - assert(bSuccess); - - // test multipage stream (save as) - bSuccess = testStreamMultiPageSave(lpszPathName, "clone-stream.tif", 0, 0); - assert(bSuccess); - - // test multipage stream (open, modify, save as) - bSuccess = testStreamMultiPageOpenSave(lpszPathName, "redirect-stream.tif", 0, 0); - assert(bSuccess); - -} +// ========================================================== +// FreeImagePlus Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "fipTest.h" + +using namespace std; + +// -------------------------------------------------------------------------- + +static unsigned DLL_CALLCONV +myReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { + return fread(buffer, size, count, (FILE *)handle); +} + +static unsigned DLL_CALLCONV +myWriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { + return fwrite(buffer, size, count, (FILE *)handle); +} + +static int DLL_CALLCONV +mySeekProc(fi_handle handle, long offset, int origin) { + return fseek((FILE *)handle, offset, origin); +} + +static long DLL_CALLCONV +myTellProc(fi_handle handle) { + return ftell((FILE *)handle); +} + +BOOL testStreamMultiPageOpen(const char *input, int flags) { + // initialize your own IO functions + + FreeImageIO io; + + io.read_proc = myReadProc; + io.write_proc = myWriteProc; + io.seek_proc = mySeekProc; + io.tell_proc = myTellProc; + + BOOL bSuccess = FALSE; + + // Open src stream in read-only mode + FILE *file = fopen(input, "r+b"); + if (file != NULL) { + fipMultiPage src; + + // Open the multi-page file + src.open(&io, (fi_handle)file, flags); + + if(src.isValid()) { + // get the page count + int count = src.getPageCount(); + assert(count > 1); + + // delete page 0 (modifications are stored to the cache) + src.deletePage(0); + + // Close src file (nothing is done, the cache is cleared) + bSuccess = src.close(0); + assert(bSuccess); + } + + // Close the src stream + fclose(file); + + return bSuccess; + } + + return bSuccess; +} + +BOOL testStreamMultiPageSave(const char *input, const char *output, int input_flag, int output_flag) { + // initialize your own IO functions + + FreeImageIO io; + + io.read_proc = myReadProc; + io.write_proc = myWriteProc; + io.seek_proc = mySeekProc; + io.tell_proc = myTellProc; + + BOOL bCreateNew = FALSE; + BOOL bReadOnly = TRUE; + BOOL bMemoryCache = TRUE; + + // Open src file (read-only, use memory cache) + fipMultiPage src(bMemoryCache); + src.open(input, bCreateNew, bReadOnly, input_flag); + + if(src.isValid()) { + // Open dst stream in read/write mode + FILE *file = fopen(output, "w+b"); + if (file != NULL) { + // Save the multi-page file to the stream + FREE_IMAGE_FORMAT fif = fipImage::identifyFIF(output); + BOOL bSuccess = src.saveToHandle(fif, &io, (fi_handle)file, output_flag); + assert(bSuccess); + + // Close the dst stream + fclose(file); + + // Close src file (or let the destructor close it) + return src.close(0); + + return TRUE; + } + + // Close src file (or let the destructor close it) + src.close(0); + } + + return FALSE; +} + +BOOL testStreamMultiPageOpenSave(const char *input, const char *output, int input_flag, int output_flag) { + // initialize your own IO functions + + FreeImageIO io; + + io.read_proc = myReadProc; + io.write_proc = myWriteProc; + io.seek_proc = mySeekProc; + io.tell_proc = myTellProc; + + BOOL bSuccess = FALSE; + + // Open src stream in read-only mode + FILE *src_file = fopen(input, "r+b"); + assert(src_file); + if (src_file != NULL) { + fipMultiPage src; + // Open the multi-page file + src.open(&io, (fi_handle)src_file, input_flag); + + if(src.isValid()) { + fipImage image; + + // get the page count + int count = src.getPageCount(); + assert(count > 2); + + // Load the bitmap at position '2' + image = src.lockPage(2); + if(image.isValid()) { + image.invert(); + // Unload the bitmap (apply change to src, modifications are stored to the cache) + src.unlockPage(image, TRUE); + } + + // delete page 0 (modifications are stored to the cache) + src.deletePage(0); + + // insert a new page at position '0' (modifications are stored to the cache) + image.load("test.jpg"); + src.insertPage(0, image); + + // Open dst stream in read/write mode + FILE *dst_file = fopen(output, "w+b"); + assert(dst_file); + if (dst_file != NULL) { + // Save the multi-page file to the stream (modifications are applied) + FREE_IMAGE_FORMAT fif = fipImage::identifyFIF(output); + BOOL bSuccess = src.saveToHandle(fif, &io, (fi_handle)dst_file, output_flag); + assert(bSuccess); + + // Close the dst stream + fclose(dst_file); + } + + // Close src file (nothing is done, the cache is cleared) + bSuccess = src.close(0); + assert(bSuccess); + } + + // Close the src stream + fclose(src_file); + + return bSuccess; + } + + return FALSE; +} + +// -------------------------------------------------------------------------- + +void testStreamMultiPage(const char *lpszPathName) { + BOOL bSuccess; + + cout << "testStreamMultiPage ...\n"; + + // test multipage stream (opening) + bSuccess = testStreamMultiPageOpen(lpszPathName, 0); + assert(bSuccess); + + // test multipage stream (save as) + bSuccess = testStreamMultiPageSave(lpszPathName, "clone-stream.tif", 0, 0); + assert(bSuccess); + + // test multipage stream (open, modify, save as) + bSuccess = testStreamMultiPageOpenSave(lpszPathName, "redirect-stream.tif", 0, 0); + assert(bSuccess); + +} diff --git a/Wrapper/FreeImagePlus/test/fipTestMemIO.cpp b/Wrapper/FreeImagePlus/test/fipTestMemIO.cpp index 33f849b..233189d 100644 --- a/Wrapper/FreeImagePlus/test/fipTestMemIO.cpp +++ b/Wrapper/FreeImagePlus/test/fipTestMemIO.cpp @@ -1,171 +1,171 @@ -// ========================================================== -// FreeImagePlus Test Script -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - - -#include "fipTest.h" - -using namespace std; - -// -------------------------------------------------------------------------- -// Memory IO test scripts - -/** -Test saving to a memory stream -*/ -void testSaveMemIO(const char *lpszPathName) { - - // load a regular file - FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(lpszPathName); - FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, 0); - - // open a memory handle - fipMemoryIO memIO; - - // save the file to memory - memIO.save(fif, dib, 0); - - // at this point, memIO contains the entire PNG data in memory. - // the amount of space used by the memory is equal to file_size - long file_size = memIO.tell(); - assert(file_size != 0); - - // its easy load an image from memory as well - - // seek to the start of the memory stream - memIO.seek(0L, SEEK_SET); - - // get the file type - FREE_IMAGE_FORMAT mem_fif = memIO.getFileType(); - - // load an image from the memory handle - FIBITMAP *check = memIO.load(mem_fif, 0); - - // save as a regular file - FreeImage_Save(FIF_PNG, check, "dump.png", PNG_DEFAULT); - - FreeImage_Unload(check); - FreeImage_Unload(dib); - - // The memIO object will be destroyed automatically -} - -/** -Test loading from a buffer attached to a memory stream -*/ -void testLoadMemIO(const char *lpszPathName) { - struct stat buf; - int result; - - // get data associated with lpszPathName - result = stat(lpszPathName, &buf); - if(result == 0) { - // allocate a memory buffer and load temporary data - BYTE *mem_buffer = (BYTE*)malloc(buf.st_size * sizeof(BYTE)); - if(mem_buffer) { - FILE *stream = fopen(lpszPathName, "rb"); - if(stream) { - fread(mem_buffer, sizeof(BYTE), buf.st_size, stream); - fclose(stream); - - // attach the binary data to a memory stream - fipMemoryIO memIO(mem_buffer, buf.st_size); - - // get the file type - FREE_IMAGE_FORMAT fif = memIO.getFileType(); - - // load an image from the memory stream - FIBITMAP *check = memIO.load(fif, PNG_DEFAULT); - - // save as a regular file - FreeImage_Save(FIF_PNG, check, "blob.png", PNG_DEFAULT); - - // close the stream (memIO is destroyed) - } - - // user is responsible for freeing the data - free(mem_buffer); - } - } -} - -/** -Test extracting a memory buffer from a memory stream -*/ -void testAcquireMemIO(const char *lpszPathName) { - - // load a regular file - FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(lpszPathName); - FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, 0); - - // open and allocate a memory stream - fipMemoryIO memIO; - - // save the file to memory - memIO.save(FIF_PNG, dib, PNG_DEFAULT); - - // get the buffer from the memory stream - BYTE *mem_buffer = NULL; - DWORD size_in_bytes = 0; - - memIO.acquire(&mem_buffer, &size_in_bytes); - - // save the buffer in a file stream - FILE *stream = fopen("buffer.png", "wb"); - if(stream) { - fwrite(mem_buffer, sizeof(BYTE), size_in_bytes, stream); - fclose(stream); - } - - // close and free the memory stream (memIO is destroyed) -} - -/** -Test Loading / Saving from / to a memory stream using fipImage -*/ -void testImageMemIO(const char *lpszPathName) { - BOOL bSuccess = FALSE; - - fipMemoryIO memIO; - fipImage image; - - // load a regular file - bSuccess = image.load(lpszPathName); - if(bSuccess) { - // save the file to a memory stream - bSuccess = image.saveToMemory(FIF_PNG, memIO, PNG_DEFAULT); - assert(bSuccess); - - // load the file from the memory stream - memIO.seek(0L, SEEK_SET); - bSuccess = image.loadFromMemory(memIO, 0); - assert(bSuccess); - } -} - -void testMemIO(const char *lpszPathName) { - cout << "testMemIO ...\n"; - - testSaveMemIO(lpszPathName); - testLoadMemIO(lpszPathName); - testAcquireMemIO(lpszPathName); - testImageMemIO(lpszPathName); -} - +// ========================================================== +// FreeImagePlus Test Script +// +// Design and implementation by +// - Hervé Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + + +#include "fipTest.h" + +using namespace std; + +// -------------------------------------------------------------------------- +// Memory IO test scripts + +/** +Test saving to a memory stream +*/ +void testSaveMemIO(const char *lpszPathName) { + + // load a regular file + FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(lpszPathName); + FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, 0); + + // open a memory handle + fipMemoryIO memIO; + + // save the file to memory + memIO.save(fif, dib, 0); + + // at this point, memIO contains the entire PNG data in memory. + // the amount of space used by the memory is equal to file_size + long file_size = memIO.tell(); + assert(file_size != 0); + + // its easy load an image from memory as well + + // seek to the start of the memory stream + memIO.seek(0L, SEEK_SET); + + // get the file type + FREE_IMAGE_FORMAT mem_fif = memIO.getFileType(); + + // load an image from the memory handle + FIBITMAP *check = memIO.load(mem_fif, 0); + + // save as a regular file + FreeImage_Save(FIF_PNG, check, "dump.png", PNG_DEFAULT); + + FreeImage_Unload(check); + FreeImage_Unload(dib); + + // The memIO object will be destroyed automatically +} + +/** +Test loading from a buffer attached to a memory stream +*/ +void testLoadMemIO(const char *lpszPathName) { + struct stat buf; + int result; + + // get data associated with lpszPathName + result = stat(lpszPathName, &buf); + if(result == 0) { + // allocate a memory buffer and load temporary data + BYTE *mem_buffer = (BYTE*)malloc(buf.st_size * sizeof(BYTE)); + if(mem_buffer) { + FILE *stream = fopen(lpszPathName, "rb"); + if(stream) { + fread(mem_buffer, sizeof(BYTE), buf.st_size, stream); + fclose(stream); + + // attach the binary data to a memory stream + fipMemoryIO memIO(mem_buffer, buf.st_size); + + // get the file type + FREE_IMAGE_FORMAT fif = memIO.getFileType(); + + // load an image from the memory stream + FIBITMAP *check = memIO.load(fif, PNG_DEFAULT); + + // save as a regular file + FreeImage_Save(FIF_PNG, check, "blob.png", PNG_DEFAULT); + + // close the stream (memIO is destroyed) + } + + // user is responsible for freeing the data + free(mem_buffer); + } + } +} + +/** +Test extracting a memory buffer from a memory stream +*/ +void testAcquireMemIO(const char *lpszPathName) { + + // load a regular file + FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(lpszPathName); + FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, 0); + + // open and allocate a memory stream + fipMemoryIO memIO; + + // save the file to memory + memIO.save(FIF_PNG, dib, PNG_DEFAULT); + + // get the buffer from the memory stream + BYTE *mem_buffer = NULL; + DWORD size_in_bytes = 0; + + memIO.acquire(&mem_buffer, &size_in_bytes); + + // save the buffer in a file stream + FILE *stream = fopen("buffer.png", "wb"); + if(stream) { + fwrite(mem_buffer, sizeof(BYTE), size_in_bytes, stream); + fclose(stream); + } + + // close and free the memory stream (memIO is destroyed) +} + +/** +Test Loading / Saving from / to a memory stream using fipImage +*/ +void testImageMemIO(const char *lpszPathName) { + BOOL bSuccess = FALSE; + + fipMemoryIO memIO; + fipImage image; + + // load a regular file + bSuccess = image.load(lpszPathName); + if(bSuccess) { + // save the file to a memory stream + bSuccess = image.saveToMemory(FIF_PNG, memIO, PNG_DEFAULT); + assert(bSuccess); + + // load the file from the memory stream + memIO.seek(0L, SEEK_SET); + bSuccess = image.loadFromMemory(memIO, 0); + assert(bSuccess); + } +} + +void testMemIO(const char *lpszPathName) { + cout << "testMemIO ...\n"; + + testSaveMemIO(lpszPathName); + testLoadMemIO(lpszPathName); + testAcquireMemIO(lpszPathName); + testImageMemIO(lpszPathName); +} + diff --git a/Wrapper/VB6/mfreeimage/MFreeImage.bas b/Wrapper/VB6/mfreeimage/MFreeImage.bas index 6ea0395..435cb36 100644 --- a/Wrapper/VB6/mfreeimage/MFreeImage.bas +++ b/Wrapper/VB6/mfreeimage/MFreeImage.bas @@ -1,12666 +1,12666 @@ -Attribute VB_Name = "MFreeImage" -'// ========================================================== -'// Visual Basic Wrapper for FreeImage 3 -'// Original FreeImage 3 functions and VB compatible derived functions -'// Design and implementation by -'// - Carsten Klein (cklein05@users.sourceforge.net) -'// -'// Main reference : Curland, Matthew., Advanced Visual Basic 6, Addison Wesley, ISBN 0201707128, (c) 2000 -'// Steve McMahon, creator of the excellent site vbAccelerator at http://www.vbaccelerator.com/ -'// MSDN Knowlede Base -'// -'// This file is part of FreeImage 3 -'// -'// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -'// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -'// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -'// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -'// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -'// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -'// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -'// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -'// THIS DISCLAIMER. -'// -'// Use at your own risk! -'// ========================================================== - -'// ========================================================== -'// CVS -'// $Revision: 2.17 $ -'// $Date: 2012/10/01 12:52:22 $ -'// $Id: MFreeImage.bas,v 2.17 2012/10/01 12:52:22 cklein05 Exp $ -'// ========================================================== - - -Option Explicit - -'-------------------------------------------------------------------------------- -' General notes on implementation and design -'-------------------------------------------------------------------------------- - -' General: - -' Most of the pointer type parameters used in the FreeImage API are actually -' declared as Long in VB. That is also true for return values. 'Out' parameters -' are declared ByRef, so they can receive the provided address of the pointer. -' 'In' parameters are declared ByVal since in VB the Long variable is not a -' pointer type but contains the address of the pointer. - - -' Functions returning a special type: - -' Some of the following external function declarations of the FreeImage 3 functions -' are declared Private. Additionally the token 'Int' is appended to the VB function -' name, what means 'Internal' to avoid naming confusion. All of these return a value -' of a certain type that can't be used with a declared function in VB directly but -' would need the function to be declared in a type library. Since this wrapper module -' should not depend on a compile time type library, these functions require some extra -' work to be done and also a VB wrapper function to make them look like the C/C++ -' function. - - -' Functions returning Strings: - -' Some of the declared FreeImage functions are defined as 'const char *' in C/C++ -' and so actually return a string pointer. Without using a type library for declaring -' these functions, in VB it is impossible to declare these functions to return a -' VB String type. So each of these functions is wrapped by a VB implemented function -' named correctly according to the FreeImage API, actually returning a 'real' VB String. - - -' Functions returning Booleans: - -' A Boolean is a numeric 32 bit value in both C/C++ and VB. In C/C++ TRUE is defined -' as 1 whereas in VB True is -1 (all bits set). When a function is declared as 'Boolean' -' in VB, the return value (all 32 bits) of the called function is just used "as is" and -' maybe assigned to a VB boolean variable. A Boolean in VB is 'False' when the numeric -' value is NULL (0) and 'True' in any other case. So, at a first glance, everything -' would be great since both numeric values -1 (VB True) and 1 (C/C++ TRUE) are actually -' 'True' in VB. -' But, if you have a VB variable (or a function returning a Boolean) with just some bits -' set and use the VB 'Not' operator, the result is not what you would expect. In this -' case, if bTest is True, (Not bTest) is also True. The 'Not' operator just toggles all -' bits by XOR-ing the value with -1. So, the result is not so surprisingly any more: -' The C/C++ TRUE value is 0...0001. When all bits are XORed with 1, the result is -' 1...1110 what is also not NULL (0) so this is still 'True' in VB. -' The resolution is to convert these return values into real VB Booleans in a wrapper -' function, one for each declared FreeImage function. Therefore each C/C++ BOOL -' function is declared Private as xxxInt(...). A Public Boolean wrapper function -' xxx(...) returns a real Boolean with 'xxx = (xxxInt(...) = 1)'. - - -' Extended and derived functions: - -' Some of the functions are additionally provided in an extended, call it a more VB -' friendly version, named '...Ex'. For example look at the 'FreeImage_GetPaletteEx' -' function. Most of them are dealing with arrays and so actually return a VB style -' array of correct type. - -' The wrapper also includes some derived functions that should make life easier for -' not only a VB programmer. - -' Better VB interoperability is given by offering conversion between DIBs and -' VB Picture objects. See the FreeImage_CreateFromOlePicture and -' FreeImage_GetOlePicture functions. - -' Both known VB functions LoadPicture() and SavePicture() are provided in extended -' versions calles LoadPictureEx() and SavePictureEx() offering the FreeImage 3´s -' image file types. - -' The FreeImage 3 error handling is provided in VB after calling the VB specific -' function FreeImage_InitErrorHandler() - - -' Enumerations: - -' All of the enumaration members are additionally 'declared' as constants in a -' conditional compiler directive '#If...#Then' block that is actually unreachable. -' For example see: -' -' Public Enum FREE_IMAGE_QUANTIZE -' FIQ_WUQUANT = 0 ' Xiaolin Wu color quantization algorithm -' FIQ_NNQUANT = 1 ' NeuQuant neural-net quantization algorithm by Anthony Dekker -' End Enum -' #If False Then -' Const FIQ_WUQUANT = 0 -' Const FIQ_NNQUANT = 1 -' #End If -' -' Since this module is supposed to be used directly in VB projects rather than in -' compiled form (mybe through an ActiveX-DLL), this is for tweaking some ugly VB -' behaviour regarding enumerations. Enum members are automatically adjusted in case -' by the VB IDE whenever you type these members in wrong case. Since these are also -' constants now, they are no longer adjusted to wrong case but always corrected -' according to the definition of the constant. As the expression '#If False Then' -' actually never comes true, these constants are not really defined either when running -' in the VB IDE nor in compiled form. - - -'-------------------------------------------------------------------------------- -' ToDo and known issues (unordered and with no priority) -'-------------------------------------------------------------------------------- - -' ToDo: more inline documentation for mask image creation and icon functions -' needed - -'-------------------------------------------------------------------------------- -' Change Log -'-------------------------------------------------------------------------------- - -'* : fixed -'- : removed -'! : changed -'+ : added -' -'October 1, 2012 - 2.17 -'- [Carsten Klein] removed temporary workaround for 16-bit standard type bitmaps introduced in version 2.15, which temporarily stored RGB masks directly after the BITMAPINFO structure, when creating a HBITMAP. -'* [Carsten Klein] fixed a potential overflow bug in both pNormalizeRational and pNormalizeSRational: these now do nothing if any of numerator and denominator is either 1 or 0 (zero). -'+ [Carsten Klein] added load flag JPEG_GREYSCALE as well as the enum constant FILO_JPEG_GREYSCALE. -'! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL to 4 to match current version 3.15.4 -' -'! now FreeImage version 3.15.4 -' -' -'March 19, 2012 - 2.16 -'! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL to 3 to match current version 3.15.3 -' -'! now FreeImage version 3.15.3 -' -' -'March 12, 2012 - 2.15 -'+ [Carsten Klein] added function FreeImage_ConvertToUINT16. -'+ [Carsten Klein] added function FreeImage_ConvertToRGB16. -'+ [Carsten Klein] added function FreeImage_GetThumbnail. -'+ [Carsten Klein] added function declaration FreeImage_SetThumbnailInt and a real VB Boolean returning function FreeImage_SetThumbnail. -'+ [Carsten Klein] added RAW_HALFSIZE load flag as well as the enum constant FILO_RAW_HALFSIZE. -'+ [Carsten Klein] added wrapper function FreeImage_GetPictureData, which returns a byte array suitable for assigning to an Office image control's PictureData property. -'+ [Carsten Klein] added wrapper function FreeImage_CreateFromPictureData, which creates a FreeImage bitmap from a PictureData byte array. -'+ [Carsten Klein] added new save flag JPEG_BASELINE (also added FISO_JPEG_BASELINE to enumeration FREE_IMAGE_SAVE_OPTIONS). -'+ [Carsten Klein] added a workaround for providing valid BITMAPINFO structures for non 555 16-bpp images to Windows API functions like CreateDIBSection, CreateDIBBitmap, StretchDIBits or SetDIBitsToDevice. -'! [Carsten Klein] changed constants FREEIMAGE_MINOR_VERSION and FREEIMAGE_RELEASE_SERIAL: set to 15 and 2 respectively to match current version 3.15.2 -' -'! now FreeImage version 3.15.2 -' -'March 13, 2011 - 2.14 -'* [Glenn Thorpe] fixed a typo error with the call to FreeImage_HasPixels inside FreeImage_CreateMask. -' -'August 11, 2010 - 2.13 -'+ [Carsten Klein] added PSD load flags PSD_CMYK and PSD_LAB as well as the enum constants FILO_PSD_CYMK and FILO_PSD_LAB. -'+ [Carsten Klein] added TIFF_LOGLUV save flag as well as the enum constant FISO_TIFF_LOGLUV. -' -'July 5, 2010 - 2.12 -'+ [Carsten Klein] added support for the new EXIF_RAW metadata model by adding enum constant FIMD_EXIF_RAW. -'+ [Carsten Klein] added the new FIF_LOAD_NOPIXELS flag as well as the enum constant FILO_LOAD_NOPIXELS. -'+ [Carsten Klein] added function declaration FreeImage_HasPixelsInt and a real VB Boolean returning function FreeImage_HasPixels. -'+ [Carsten Klein] added function declaration FreeImage_FIFSupportsNoPixelsInt and a real VB Boolean returning function FreeImage_FIFSupportsNoPixels. -' -'! now FreeImage version 3.14.1 -' -'June 20, 2010 - 2.11 -'+ [Carsten Klein] added new save flag JPEG_OPTIMIZE (also added FISO_JPEG_OPTIMIZE to enumeration FREE_IMAGE_SAVE_OPTIONS). -' -'April 20, 2010 - 2.10 -'+ [Carsten Klein] added new save flag TARGA_SAVE_RLE (also added FISO_TARGA_SAVE_RLE to enumeration FREE_IMAGE_SAVE_OPTIONS). -'! [Carsten Klein] changed constants FREEIMAGE_MINOR_VERSION and FREEIMAGE_RELEASE_SERIAL: set to 14 and 0 respectively to match current version 3.14.0 -'+ [Carsten Klein] added function FreeImage_ConvertToFloat. -'+ [Carsten Klein] added function FreeImage_SaveMultiBitmapToMemory. -'+ [Carsten Klein] added wrapper functions FreeImage_SaveMultiBitmapToMemoryEx and FreeImage_SaveMultiBitmapToMemoryEx2. -'+ [Carsten Klein] added wrapper function FreeImage_OpenMultiBitmapEx, which only opens existing files, but has support for automatic image format detection. -'+ [Carsten Klein] added wrapper function FreeImage_CreateMultiBitmapEx, which only creates new (empty) multi-page bitmaps with support for automatic image format detection. -'* [Carsten Klein] fixed a bug in FreeImage_LoadEx: now uses the file specified for format detection rather than the filename extension. -'+ [Carsten Klein] improved error messages in function FreeImage_LoadEx. -'* [Carsten Klein] fixed a bug in FreeImage_AcquireMemoryEx: no more crashes when passing an uninitialized array. -'+ [Carsten Klein] added thin wrapper functions, enabling proper handling of Boolean parameters: -'+ added wrapper function FreeImage_OpenMultiBitmap -'+ added wrapper function FreeImage_UnlockPage -'+ added wrapper function FreeImage_RotateEx -'+ added wrapper function FreeImage_MakeThumbnail -'+ added wrapper function FreeImage_GetAdjustColorsLookupTable -'+ added wrapper function FreeImage_ApplyColorMapping -'+ added wrapper function FreeImage_SwapColors -'+ added wrapper function FreeImage_SwapColorsByLong -'+ added wrapper function FreeImage_ApplyIndexMapping -'+ added wrapper function FreeImage_SetTransparent -'+ added wrapper function FreeImage_ConvertFromRawBits -'+ added wrapper function FreeImage_ConvertToRawBits -'+ added wrapper function FreeImage_ConvertToStandardType -'+ added wrapper function FreeImage_ConvertToType -'! [Carsten Klein] changed the parameter names of most functions. -'! [Carsten Klein] changed signature of functions FreeImage_ConvertFromRawBits and FreeImage_ConvertToRawBits: 'ByRef Bits As Long' is now 'ByVal BitsPtr As Long'. -'+ [Carsten Klein] added wrapper functions FreeImage_ConvertFromRawBitsEx and FreeImage_ConvertToRawBitsEx. -'* [Carsten Klein] fixed a bug in declaration of function FreeImage_TmoReinhard05Ex: parameters 'Adaption' and 'ColorCorrection' are now passed by value. -'- [Carsten Klein] removed half-implemented function FreeImage_SetChannelEx. -'+ [Carsten Klein] added wrapper function FreeImage_SetChannelIOP. -'- [Carsten Klein] removed needless default values of optional parameters. -'- [Carsten Klein] removed function declaration FreeImage_CompositeByLong: replaced by declaration FreeImage_Composite. -'! [Carsten Klein] changed function declaration FreeImage_Composite: application back color is now passed as ByRef ... As Any and so takes both RGBQUAD and Long valus. -'+ [Carsten Klein] added wrapper function FreeImage_UnloadEx, which additionally sets the ByRef-passed Bitmap handle to zero after unloading. -'+ [Carsten Klein] added wrapper functions ConvertColor and ConvertOleColor to convert VB-style BGR colors into RGB color values. -' -'! now FreeImage version 3.14.0 -' -'February 9, 2010 - 2.9.1 -'* [Carsten Klein] fixed a bug in FreeImage_GetBackgroundColorAsLong: parameter 'bkcolor' is now properly passed ByRef. -' -'February 9, 2010 - 2.9 -'* [Carsten Klein] fixed a syntax typo -' -'February 8, 2010 - 2.8 -'* [Mike Weir] fixed a bug in function FreeImage_ApplyColorMappingEx: now properly includes all specified mapping entries -'* [Carsten Klein] fixed a bug in function FreeImage_ApplyIndexMappingEx: now properly includes all specified mapping entries -'* [Mike Weir] fixed a bug in function FreeImage_RescaleEx: now also rescales the image, if either the new width or height matches the image's current size -'* [WinAnd / Carsten Klein] fixed a bug in function FreeImage_GetTransparencyTableExClone: returns an uninitialized array if there is no transparency table -'* [WinAnd / Carsten Klein] fixed a bug in function FreeImage_SearchPalette: no longer crashes if there is no transparency table -' -'December 21, 2009 - 2.7 -'! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 1 to match current version 3.13.1 -' -'! now FreeImage version 3.13.1 -' -'December 18, 2009 - 2.6 -'- [Carsten Klein] removed usage of constants vbPicTypeBitmap and vbPicTypeIcon: these are not available in VBA environments like Excel, Access or Outlook. -' -'September 08, 2009 - 2.5 -'! [Carsten Klein] changed constant FREEIMAGE_MINOR_VERSION: set to 13 to match current version 3.13.0 -'+ [Carsten Klein] added load flag constant JPEG_EXIFROTATE and new member FILO_JPEG_EXIFROTATE to enumeration FREE_IMAGE_LOAD_OPTIONS. -'+ [Carsten Klein] added support for the PFM image format. -'+ [Carsten Klein] added support for the PICT and RAW image formats. -'+ [Carsten Klein] added UNICODE functions FreeImage_JPEGTransformU and FreeImage_JPEGCropU. -'+ [Carsten Klein] added enumeration FREE_IMAGE_COLOR_OPTIONS, which contains options to specify colors, used with FreeImage_FillBackground and FreeImage_EnlargeCanvas. -'+ [Carsten Klein] added function FreeImage_FillBackground: although this returns BOOL in C/C++, the VB version only returns a Long. -'+ [Carsten Klein] added wrapper functions FreeImage_FillBackgroundEx and FreeImage_FillBackgroundByLong, taking an RGBQUAD and a Long 'Color' argument respectively and return a true VB Boolean. -'+ [Carsten Klein] added function FreeImage_EnlargeCanvas. -'+ [Carsten Klein] added functions FreeImage_AllocateEx and FreeImage_AllocateExT. -'+ [Carsten Klein] added function FreeImage_TmoReinhard05Ex. -'+ [Carsten Klein] added function FreeImage_Rotate. -'+ [Carsten Klein] added wrapper function FreeImage_RotateIOP. -' -'! now FreeImage version 3.13.0 -' -'March 18, 2009 - 2.4.2 -'+ [Carsten Klein] added enumeration FREE_IMAGE_FRAME_DISPOSAL_METHODS, which provides the frame disposal options needed to create animated GIF files. -' -'July 29, 2008 - 2.4.1 -'* [Carsten Klein] minor documentation updates -'! [Carsten Klein] renamed member FICF_PALETTISED_8BPP of enumeration FREE_IMAGE_CONVERSION_FLAGS into FICF_PALLETISED_8BPP. -' -'June 30, 2008 - 2.4 -'* [Carsten Klein] fixed some minor issues in FreeImage_PaintTransparent() -' -'June 06, 2008 - 2.3 -'+ [Carsten Klein] added new compression flags to the JPEG and PNG plugins -'! [Carsten Klein] renamed wrapper function FreeImage_CloneMetadata() to FreeImage_CloneMetadataEx(): now, there is a native function called FreeImage_CloneMetadata(). -'+ [Carsten Klein] added private and internal function declaration for FreeImage_CloneMetadata() along with it's public Boolean returning wrapper function. -'- [Carsten Klein] removed the FreeImage_ColorQuantizeEx() stuff from both functions FreeImage_ConvertColorDepth() and FreeImage_ConvertColorDepthIOP(): removed parameters PaletteSize, ReserveSize and ReservePalette. -'- [Carsten Klein] changed declaration of FreeImage_ColorQuantizeEx() to be a internal function private to the wrapper with an 'Int' appendix. -'+ [Carsten Klein] added two more VB-friendly public wrapper functions FreeImage_ColorQuantizeEx() and FreeImage_ColorQuantizeExIOP(). -'+ [Carsten Klein] added wrapper function FreeImage_GetPalettePtr(): gets the pointer to a specified array of RGBQUADs: intended to be used together with any of the ColorQuantizeEx functions. -'! [Carsten Klein] changed constant FREEIMAGE_MINOR_VERSION: set to 11 to match current version 3.11.0 -' -'! now FreeImage version 3.11.0 -' -'December 14, 2007 - 2.2.1 -'+ [Carsten Klein] added constants for member 'biCompression' in BITMAPINFOHEADER struct -'+ [Carsten Klein] added wrapper function FreeImage_GetInfoHeaderEx(), which returns a fully populated BITMAPINFOHEADER struct for a bitmap. -'* [Carsten Klein] fixed a bug in FreeImage_GetFileTypeFromMemoryEx(): now calls FreeImage_CloseMemory() releasing the hStream to prevent memory leaks. -'+ [Carsten Klein] added wrapper function FreeImage_GetColorizedPalette(): returns a colorized greyscale palettte. -'+ [Carsten Klein] added wrapper function FreeImage_Colorize(): applies a colorized greyscale palettte obtained from FreeImage_GetColorizedPalette() to a bitmap. -'+ [Carsten Klein] added wrapper function FreeImage_Sepia(): calls FreeImage_Colorize() with proper parameters to apply a so called sepia palette to a bitmap. -' -'December 12, 2007 - 2.2 -'* [Carsten Klein] fixed a small bug in FreeImage_PaintTransparent, which now calls function FreeImage_ConvertTo32Bits instead of FreeImage_ConvertTo32Bits2. -' -'November 15, 2007 - 2.1 -'* [Carsten Klein] adjusted page numbers of the API documentation in FreeImage function declarations to match FreeImage 3.10.0 API documentation -'- [Carsten Klein] removed parameter 'UnloadSource' from function FreeImage_GetOlePictureIcon(): an hIcon should not be destroyed if OleCreatePictureIndirect() is called with fOwn = True. -'! [Carsten Klein] refactored FreeImage_GetOlePicture(): now relies on FreeImage_GetBitmap(). -' -'November 10, 2007 - 2.0.8 -'! [Carsten Klein] changed declaration of FreeImage_SetOutputMessage(): now points transparently to the __stdcall version of this function in the library. -'+ [Carsten Klein] added function declaraton for FreeImage_MultigridPoissonSolver(). -'+ [Carsten Klein] added function declaraton for FreeImage_GetTransparentIndex() and FreeImage_SetTransparentIndex(). -'+ [Carsten Klein] added private and internal function declaration for FreeImage_AdjustColors() along with it's public Boolean returning wrapper function. -'+ [Carsten Klein] added function declaraton for FreeImage_GetAdjustColorsLookupTable(). -'+ [Carsten Klein] added wrapper function FreeImage_GetAdjustColorsLookupTableEx(): this takes a real VB style Byte array ton receive the lookup table created. -'+ [Carsten Klein] added function declaraton for FreeImage_ApplyColorMapping(). -'+ [Carsten Klein] added wrapper function FreeImage_ApplyColorMappingEx(): this takes a real VB style RGBQUAD array. -'+ [Carsten Klein] added function declaratons for FreeImage_SwapColors() and FreeImage_SwapColorsByLong(). -'+ [Carsten Klein] added function declaraton for FreeImage_ApplyIndexMapping(). -'+ [Carsten Klein] added wrapper function FreeImage_ApplyIndexMappingEx(): this takes a real VB style Byte array. -'+ [Carsten Klein] added function declaraton for FreeImage_SwapPaletteIndices(). -' -'November 05, 2007 - 2.0.7 -'+ [Carsten Klein] added 4 bit color depth to both function pGetNextColorDepth() and pGetPrevousColorDepth() -'- [Carsten Klein] removed member FICF_PREPARE_RESCALE from enumeration FREE_IMAGE_CONVERSION_FLAGS -'- [Carsten Klein] removed all references to FICF_PREPARE_RESCALE: Converting color depth before rescaling an image is no longer performed by the wrapper. Since FreeImage now transparently converts color depth on rescaling, doing this in the wrapper is no longer needed. -'! [Carsten Klein] refactored wrapper function FreeImage_ConvertColorDepth(): removed case FICF_PREPARE_RESCALE; is now more similar to C# wrapper's version of this function. -'! [Carsten Klein] refactored wrapper function FreeImage_SaveEx(): removed case FICF_PREPARE_RESCALE; is now more similar to C# wrapper's version of this function. -' -'September 14, 2007 - 2.0.6 -'+ [Carsten Klein] added function declaration and Boolean wrapper function for FreeImage_PreMultiplyWithAlpha(). -' -'July 26, 2007 - 2.0.5 -'+ [Carsten Klein] added wrapper function FreeImage_GetBitmap(): returns an HBITMAP created by the CreateDIBSection() function and so has the same color depth as the original DIB. -'+ [Carsten Klein] added wrapper function FreeImage_GetBitmapForDevice(): returns an HBITMAP created by the CreateDIBitmap() function and so has the same color depth as the specified reference DC or as the desktop, if the 'hDC' parameter was omitted. -'- [Carsten Klein] removed function declaration for GetWindowDC(): this function is no longer used. -'* [Carsten Klein] fixed a bug in wrapper function FreeImage_IsExtensionValidForFIF(): string comparison now includes a comma. -'* [Carsten Klein] fixed a bug in wrapper function FreeImage_IsFilenameValidForFIF(): string comparison now includes a comma. -' -'July 25, 2007 - 2.0.4 -'* [Carsten Klein] fixed a bug in function FreeImage_GetPaletteExClone(): now actually returns the palette as RGBQUAD array plus some other minor improvements -'+ [Carsten Klein] added wrapper function FreeImage_GetPaletteExLongClone(): this function returns a VB style Byte array that is only wrapped around FreeImage's pointer to a DIB's transparency table. -'+ [Carsten Klein] added wrapper function FreeImage_GetTransparencyTableEx(): this function returns a VB style Byte array that is only wrapped around FreeImage's pointer to a DIB's transparency table. -'! [Carsten Klein] changed name of wrapper function FreeImage_GetTransparencyTableEx(): this function is now named FreeImage_GetTransparencyTableExClone(), since it actually returns a clone (deep copy) of an image's transparency table (compare with FreeImage_GetPaletteExClone()). -'+ [Carsten Klein] added wrapper function FreeImage_SetPalette(): sets an image's palette through a VB style RGBQUAD array. -'+ [Carsten Klein] added wrapper function FreeImage_SetPaletteLong(): sets an image's palette through a VB style Long array. -'+ [Carsten Klein] added function declaration for CreateDIBsection() -'+ [Carsten Klein] added function declaration for DeleteDC() -'* [Carsten Klein] fixed a bug in wrapper function FreeImage_CreateFromScreen(): now the memory DC is deleted with the DeleteDC() function and no longer with the DeleteObject() function. -' -'July 05, 2007 - 2.0.3 -'+ [Carsten Klein] added wrapper function FreeImage_GetFileTypeFromMemoryEx(): more VB friendly version of FreeImage_GetFileTypeFromMemory() which may take an array rather than a FIMEMORY stream. -' -'May 21, 2007 - 2.0.2 -'! [Carsten Klein] changed constant FREEIMAGE_MINOR_VERSION: set to 10 to match current version 3.10.0 -'! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 0 to match current version 3.10.0 -'+ [Carsten Klein] added image format constants FIF_EXR, FIF_J2K and FIF_JP2 to enumeration FREE_IMAGE_FORMAT. -'+ [Carsten Klein] added tone mapping operator constant FITMO_FATTAL02 to enumeration FREE_IMAGE_TMO. -'+ [Carsten Klein] added save option constants J2K_DEFAULT and JP2_DEFAULT for JPEG2000 format. -'+ [Carsten Klein] added save option constants EXR_DEFAULT, EXR_FLOAT, EXR_NONE, EXR_ZIP, EXR_PIZ, EXR_PXR24, EXR_B44 and EXR_LC for EXR format. -'+ [Carsten Klein] added save option constants for EXR format to enumeration FREE_IMAGE_SAVE_OPTIONS. -'+ [Carsten Klein] added declared function FreeImage_TmoFattal02(): adds support for Gradient domain high dynamic range compression (R. Fattal, 2002) -' -'! now FreeImage version 3.10.0 -' -'February 24, 2007 - 2.0.1 -'* [Carsten Klein] fixed a bug in function FreeImage_CreateFromScreen(): now size of image created is according to window to be captured if parameter 'hwnd' <> 0. -'+ [Carsten Klein] added parameter 'bClientAreaOnly' to function FreeImage_CreateFromScreen(). -'+ [Carsten Klein] added blitting option 'CAPTUREBLT' when calling function BitBlt() in function FreeImage_CreateFromScreen(). -'- [Carsten Klein] removed unused variable 'hDIB' from functions FreeImage_CreateFromScreen() and FreeImage_LoadEx(). Thanks to Bruce Rusk for pointing that out. -' -'February 16, 2007 - 2.0 -'! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 3 to match current version 3.9.3 -'! [Carsten Klein] changed JPEG load/save flag option values: changed constants and both enumerations FREE_IMAGE_SAVE_OPTIONS and FREE_IMAGE_SAVE_OPTIONS. -'+ [Carsten Klein] added ICC Color Profile support: -'! changed signature of declared function FreeImage_GetICCProfile(): is now declared 'Private' and suffixed with '...Int()'. -'+ added wrapper function FreeImage_GetICCProfile(): is the public wrapper function for private function FreeImage_GetICCProfileInt(), returing a real FIICCPROFILE structure. -'+ added constant FREE_IMAGE_ICC_COLOR_MODEL_MASK. -'+ added enumeration FREE_IMAGE_ICC_COLOR_MODEL. -'+ added wrapper function FreeImage_GetICCProfileColorModel(): returns the color profile's color model (FIICCPROFILE.flags member). -'+ added wrapper function FreeImage_GetICCProfileSize(): returns the color profile data's size in bytes. -'+ added wrapper function FreeImage_GetICCProfileDataPointer(): returns the pointer to the color profile data. -'+ added wrapper function FreeImage_HasICCProfile(): returns whether a color profile is available for a dib or not. -'! [Carsten Klein] changed behaviour of wrapper function FreeImage_RescaleEx() and all it's derived functions: no clone is returned if the actual and desired image size are the same. -'+ [Carsten Klein] added parameter 'bForceCloneCreation' to wrapper function FreeImage_RescaleEx() and all it's derived functions. -' -'! now FreeImage version 3.9.3 -' -'January 09, 2007 - 1.9.4 -'! [Carsten Klein] changed scope of declared function FreeImage_GetFileTypeUInt(): is now private according to all other '...Int' functions wrapped by a VB-friendly function. -'! [Carsten Klein] changed scope of declared function FreeImage_GetFIFFromFilenameUInt(): is now private according to all other '...Int' functions wrapped by a VB-friendly function. -'! [Carsten Klein] changed signature of declared functions FreeImage_GetBackgroundColorInt() and FreeImage_SetBackgroundColorInt(): now both have a 'ByRef bkcolor As RGBQUAD' parameter instead of 'ByVal bkcolor As Long'. -'+ [Carsten Klein] added declared functions FreeImage_GetBackgroundColorAsLongInt(): this has a 'ByRef bkcolor As Long' parameter and provides the background color as a Long value. -'+ [Carsten Klein] added declared functions FreeImage_SetBackgroundColorAsLongInt(): this has a 'ByRef bkcolor As Long' parameter and takes the background color as a Long value. -'! [Carsten Klein] changed signature of wrapper functions FreeImage_GetBackgroundColor() and FreeImage_SetBackgroundColor(): now both have a 'ByRef bkcolor As RGBQUAD' parameter instead of 'ByVal bkcolor As Long'. -'+ [Carsten Klein] added wrapper functions FreeImage_GetBackgroundColorAsLong() and FreeImage_SetBackgroundColorAsLong(): both have a 'ByRef bkcolor As Long' parameter and so offer getting and setting the background color through a Long value. -'+ [Carsten Klein] added wrapper functions FreeImage_GetBackgroundColorEx() and FreeImage_SetBackgroundColorEx(): both both take 4 ByRef Byte parameters 'Alpha', 'Red', 'Green' and 'Blue', one for each color component. -' -'January 05, 2007 - 1.9.3 -'+ [Carsten Klein] added wrapper function FreeImage_GetLockedPageNumbersEx(): this returns a real VB-style array of Longs containing the page numbers of all locked pages. -' -'January 02, 2007 - 1.9.2 -'* [Carsten Klein] fixed a bug in inline description of function FreeImage_GetPaletteEx(): now tells to use function FreeImage_DestroyLockedArrayRGBQUAD() to free an array returned by this function. -'* [Carsten Klein] fixed some minor bugs in inline documentation. -'* [Carsten Klein] fixed a serious bug in function FreeImage_SaveEx(): parameter 'UnloadSource' is now interpreted correctly under all circumstances. -'* [Carsten Klein] fixed some minor issues in function FreeImage_SaveEx(). -' -'December 29, 2006 - 1.9.1 -'+ [Carsten Klein] added enumeration item FID_BAYER16x16: now supports Bayer ordered dispersed dot dithering (order 4 dithering matrix). -' -'October 31, 2006 - 1.9 -'* [Carsten Klein] adjusted page numbers of the API documentation in header comments in FreeImage function declarations to match FreeImage 3.9.2 API documentation -'! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 2 to match current version 3.9.2 -'+ [Carsten Klein] added function declaration for FreeImage_JPEGCrop(): added both declaration and Boolean returning wrapper function. -'! [Carsten Klein] changed data type of all occurences of parameter 'Flags' from Long to either FREE_IMAGE_LOAD_OPTIONS or FREE_IMAGE_SAVE_OPTIONS enum. This is true for declared functions as well as for wrapper functions. -'+ [Carsten Klein] added function declaration for FreeImage_LoadMultiBitmapFromMemory(). -'+ [Carsten Klein] added wrapper function FreeImage_LoadMultiBitmapFromMemoryEx(): this is dealing with a VB style array (SAFEARRAY) like FreeImage_LoadFromMemoryEx() does. -' -'! now FreeImage version 3.9.2 -' -'October 30, 2006 - 1.8 -'* [Carsten Klein] fixed a memory leak in wrapper function SavePictureEx(). Thanks to Roogames for reporting that bug. -'! [Carsten Klein] changed return type of wrapper function SavePictureEx() to Boolean. -'+ [Carsten Klein] added wrapper function FreeImage_SaveEx() which brings all the features, as there are inline size- and color conversion and format guessing, so far only known from SavePictureEx() for DIBs. -'! [Carsten Klein] changed wrapper function SavePictureEx(): now this is only a thin wrapper for function FreeImage_SaveEx(). -'+ [Carsten Klein] added enumeration FREE_IMAGE_LOAD_OPTIONS. -'- [Carsten Klein] refactored enumeration FREE_IMAGE_SAVE_OPTIONS: removed unnecessary items from enumeration. -'! [Carsten Klein] changed wrapper function LoadPictureEx(): added parameter 'Options' (enum FREE_IMAGE_LOAD_OPTIONS) to specify image loading options (called 'flags' in FreeImage). -'+ [Carsten Klein] added wrapper function FreeImage_LoadEx() which brings all the features, as there are inline size- and color conversion and format guessing, so far only known from LoadPictureEx() for DIBs. -'! [Carsten Klein] changed wrapper function LoadPictureEx(): now this is only a thin wrapper for function FreeImage_LoadEx(). -' -'October 13, 2006 - 1.7.2 -'+ [Carsten Klein] added User32 function GetDesktopWindow() -'+ added User32 function GetWindowDC() -'- [Carsten Klein] removed unused constants DI_MASK, DI_IMAGE and DI_NORMAL -'+ added GDI32 function GetDeviceCaps() with constants HORZRES and VERTRES -'+ added GDI32 function SelectObject() -'+ added GDI32 function DeleteObject() -'+ added GDI32 function CreateCompatibleBitmap() -'+ added GDI32 function CreateCompatibleDC() -'+ added GDI32 function BitBlt() -'+ [Carsten Klein] added wrapper function FreeImage_CreateFromScreen(): this function lets you capture the whole screen or any certain window -' -'October 10, 2006 - 1.7.1 -'! [Carsten Klein] changed parameter name 'Page' into 'hPageDib' in declared function FreeImage_UnlockPage(). 'hPageDib' must be the (dib-)handle obtained from FreeImage_LockPage() and not the page number. Now, the declaration is less confusing. Thanks to Ender Wiggin. -' -'August 4, 2006 - 1.7 -'* [Carsten Klein] fixed a bug in pGetTagFromTagPtr(): removed overflow error when converting unsigned short tags (FIDT_SHORT) with values between 32768 and 65535. Thanks to André Hendriks. -'! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 1 to match current version 3.9.1 -' -'! now FreeImage version 3.9.1 -' -'July 17, 2006 - 1.6 -'+ [Carsten Klein] added more public wrapper functions for tag copying and cloning: -'+ added function FreeImage_CopyMetadata() -'+ added function FreeImage_CloneMetadata() -'- [Carsten Klein] removed dead API functions, dead structures and dead variables -'* [Carsten Klein] fixed a bug in FreeImage_ConvertColorDepth(): now color images are converted to 24 bits when used with FICF_PREPARE_RESCALE, all others to 8 bit -' -'July 16, 2006 - 1.5.6 -'+ [Carsten Klein] added more public wrapper functions for VB friendly tag access: these functions deal with a FREE_IMAGE_TAG structure instead of FreeImage's Tag pointer. -'+ added function FreeImage_SetMetadataEx() -'+ added function FreeImage_CreateTagEx() -'+ added function FreeImage_AppendTag() -'+ added function FreeImage_RemoveTag() -'+ added function FreeImage_RemoveTagEx() -'+ added function FreeImage_TagExists() -'+ added function FreeImage_TagExistsEx() -'+ added function FreeImage_DeleteTagEx() -'+ added function FreeImage_CloneTagEx() -'+ added function FreeImage_RemoveMetadataModel() -'+ added function FreeImage_UpdateMetadata() -'+ added function FreeImage_UnsignedLong() -'+ added function FreeImage_UnsignedShort() -'+ added function FreeImage_CreateRational() -'+ added function FreeImage_CreateSignedRational() -'+ added function FreeImage_GetImageComment() -'+ added function FreeImage_SetImageComment() -'+ [Carsten Klein] added some private helper functions to leverage tag updating: -'+ added helper function pTagToTagPtr() -'+ added helper function pGetValueBuffer() -'+ added helper function pGetRationalValueBuffer() -'+ added helper function pGetVariantAsByteBuffer() -'+ added helper function pGetElementSize() -' -'July 5, 2006 - 1.5.5 -'! [Carsten Klein] changed function signature of FreeImage_FindNextMetadataEx(): optional parameter 'Model' is now present; see the function's inline documentation -' -'June 30, 2006 - 1.5.4 -'* [Carsten Klein] fixed bug in functions creating a FreeImage DIB from a windows hBitmap: workaround for palletized bitmaps is now implemented -'* fixed function FreeImage_CreateFromOLEPicture() -'* fixed function FreeImage_CreateFromDC() -' -'June 22, 2006 - 1.5.3 -'! [Carsten Klein] changed function declaration of FreeImage_GetMetadataInt(): parameter 'model' is now 'ByVal' and Tag is a Long pointer -'! [Carsten Klein] changed function declaration of FreeImage_SetMetadataInt(): parameter 'model' is now 'ByVal' and Tag is a Long pointer -'! [Carsten Klein] changed function declaration of FreeImage_GetMetadata(): parameter Tag is a Long pointer now -'! [Carsten Klein] changed function declaration of FreeImage_SetMetadata(): parameter Tag is a Long pointer now -'+ [Carsten Klein] added function declarations for tag creation and destruction: -'+ added declaration for function FreeImage_CreateTag() -'+ added declaration for procedure FreeImage_DeleteTag() -'+ added declaration for function FreeImage_CloneTag() -'+ [Carsten Klein] added new items to structure FREE_IMAGE_TAG: -'+ added item 'Model As FREE_IMAGE_MDMODEL' -'+ added item 'TagPtr As Long' -'+ [Carsten Klein] added wrapper functions for more VB friendly Tag access: these functions deal with a FREE_IMAGE_TAG structure instead of FreeImage's Tag pointer. -'+ added function FreeImage_FindFirstMetadataEx() -'+ added function FreeImage_FindNextMetadataEx() -'+ added function FreeImage_GetAllMetadataTags() -'+ added function FreeImage_GetMetadataEx() -'* [Carsten Klein] fixed and adjusted page numbers of the API documentation in header comments in FreeImage function declarations -'- [Carsten Klein] removed workaround for thresholding and dithering non-MINISBLACK 8 bit images in function FreeImage_ConvertColorDepth(): was fixed in FreeImage 3.9.0 -'* [Carsten Klein] fixed all pending issues in function FreeImage_PaintDC(): is now in production state -' -'June 14, 2006 - 1.5.2 -'! [Carsten Klein] changed signature of function FreeImage_CreateMask() -'+ [Carsten Klein] added function FreeImage_CreateMaskImage(): this creates a monochrome mask from a source image -'+ [Carsten Klein] added function FreeImage_CreateMaskInPlace(): this creates a monochrome mask from a source image -'+ [Carsten Klein] added enumeration FREE_IMAGE_ICON_TRANSPARENCY_OPTION_FLAGS -'+ [Carsten Klein] added wrapper function FreeImage_CreateSimpleBWMaskImage(): wrapper for FreeImage_CreateMaskImage() with reduced number of parameters; creates a b/w mask -'+ [Carsten Klein] added wrapper function FreeImage_CreateSimpleBWMaskInPlace(): wrapper for FreeImage_CreateMaskInPlace() with reduced number of parameters; creates a b/w mask -'+ [Carsten Klein] added function declaration for FreeImage_MakeThumbnail() -'+ [Carsten Klein] added function for FreeImage_GetOlePictureThumbnail() -'+ [Carsten Klein] added function for FreeImage_MakeThumbnailIOP() -'+ [Carsten Klein] documented function FreeImage_ReadMemoryEx() -'+ [Carsten Klein] documented function FreeImage_WriteMemoryEx() -'! [Carsten Klein] divided FreeImage_TagFromPointer into an interface only function with a private helper function pGetTagFromTagPtr(): -'+ added helper function pGetTagFromTagPtr() -'! [Carsten Klein] added private helper functions to leverage the FIDT_RATIONAL and FIDT_SRATIONAL data type: -'+ added helper function pNormalizeRational() -'+ added helper function pNormalizeSRational() -'+ added helper function gcd() -'+ added helper function floor() -'! [Carsten Klein] changed name of structure 'FITAG_int' to 'FITAG': is now as in FreeImage library -'! [Carsten Klein] changed name of structure 'FITAG' to 'FREE_IMAGE_TAG': this new structure plays an important role in the wrapper's new VB friendly tag accessing concept -'! [Carsten Klein] changed function declaration of FreeImage_GetMetadataCount(): parameter 'model' is now 'ByVal' -'! [Carsten Klein] changed function declaration of FreeImage_TagToString(): parameter 'model' is now 'ByVal' and function returns a Long -'! [Carsten Klein] renamed function declaration of FreeImage_TagToString() to FreeImage_TagToStringInt(): function is now Private and wrapped by a VB String returning function -'+ [Carsten Klein] added wrapper function FreeImage_TagToString() returning a real VB String -'+ [Carsten Klein] added structure FIRATIONAL: structure to hold an image tag's rational value -'+ [Carsten Klein] added new items to structure FREE_IMAGE_TAG: -'+ added item 'StringValue As String' -'+ added item 'Palette() As RGBQUAD' -'+ added item 'RationalValue() As FIRATIONAL' -' -'June 13, 2006 - 1.5.1 -'! [Carsten Klein] changed version constant 'FREEIMAGE_MINOR_VERSION' to 9 to meet version 3.9.0 -'* [Carsten Klein] fixed and adjusted page numbers of the API documentation in header comments in FreeImage function declarations to match FreeImage 3.9.0 API documentation -'+ [Carsten Klein] added function declaration for new Memory I/O functions in 3.9.0 -'+ added declaration FreeImage_ReadMemory() -'+ added declaration FreeImage_WriteMemory() -'! [Carsten Klein] changed/added optional parameter 'element_size' to private function pGetMemoryBlockPtrFromVariant(): caller now can get size in bytes one array element -'+ [Carsten Klein] added wrapper functions for new Memory I/O functions in 3.9.0 -'+ added function FreeImage_ReadMemoryEx() -'+ added function FreeImage_WriteMemoryEx() -'+ [Carsten Klein] added constants and updated enumerations for new 3.9.0 file formats 'FAXG3' and 'SGI' -'+ [Carsten Klein] added Windows GDI icon related declarations: -'+ added function declaration for CreateIconIndirect() -'+ added function declaration for DestroyIcon() -'+ added structure ICONINFO -'+ [Carsten Klein] added function FreeImage_GetIcon(): returns a hIcon handle -'+ [Carsten Klein] added function FreeImage_GetOlePictureIcon(): returns a VB Picture object of type vbPicTypeIcon -'+ [Carsten Klein] added enumeration FREE_IMAGE_MASK_FLAGS -'+ [Carsten Klein] added function FreeImage_CreateMaskColors(): returns an array filled with items from an argument list; synonym for VB's Array() function -'+ [Carsten Klein] added enumeration FREE_IMAGE_teMask(): this creates a monochrome mask from a source image -'+ [Carsten Klein] added function FreeImage_CreaMASK_CREATION_OPTION_FLAGS -' -'! now FreeImage version 3.9.0 -' -'June 12, 2006 - 1.5 -'* [Carsten Klein] fixed bug in wrapper function FreeImage_PaintDCEx(): now handles boolean test correctly: 'If ((hDC <> 0) And (hDIB <> 0)) Then -> Thanks to ender_wiggin for reporting that bug. -'+ [Carsten Klein] added private function pGetIOlePictureFromContainer(): used to get IPicture from image hosting control (Form, PictureBox) including custom drawings -'+ [Carsten Klein] added wrapper function FreeImage_CreateFromImageContainer(): used to create FreeImage DIB from image hosting control (Form, PictureBox) including custom drawings -'+ [Carsten Klein] added wrapper function SaveImageContainerEx(): derivate of wrapper function 'SavePictureEx()': saves content of image hosting control (Form, PictureBox) including custom drawings -' -'February 27, 2006 - 1.4.8 -'+ [Carsten Klein] added inline documentation for these wrapper functions: -'+ documented function FreeImage_CompareColorsLongLong() -'+ documented function FreeImage_CompareColorsRGBTRIPLELong() -'+ documented function FreeImage_CompareColorsRGBQUADLong() -'+ documented function FreeImage_SearchPalette() -'! [Carsten Klein] changed and updated general remarks in section "General notes on implementation and design" -'! [Carsten Klein] changed all function declarations of FreeImage functions that return a BOOL in C/C++: see "Functions returning Booleans" in section "General notes on implementation and design" -'! [Carsten Klein] changed all function signatures of functions that are derived from or extend FreeImage BOOL functions: see "Functions returning Booleans" in section "General notes on implementation and design" -'+ [Carsten Klein] added wrapper functions for all FreeImage functions that return a BOOL in C/C++: see "Functions returning Booleans" in section "General notes on implementation and design" -'+ [Carsten Klein] added wrapper function FreeImage_CreateFromDC(): creates an DIB from a DC. Thanks to Evan (wxforecaster) for this suggestion. -'+ [Carsten Klein] added declaration of GDI function GetCurrentObject() and constant OBJ_BITMAP -'+ [Carsten Klein] added wrapper function FreeImage_IsAvailable(): used to test for existence of FreeImage Library (FreeImage.dll) -' -'February 9, 2006 - 1.4.7 -'+ [Carsten Klein] added private helper function pGetPreviousColorDepth() -'+ [Carsten Klein] added private helper function pGetNextColorDepth() -'! [Carsten Klein] changed/extended signature of wrapper function SavePictureEx(): now includes a parameter 'ColorDepth' -'+ [Carsten Klein] added enumeration FREE_IMAGE_COLOR_DEPTH -'+ [Carsten Klein] added error handling capabilities to wrapper function SavePictureEx() -'+ [Carsten Klein] added/updated inline documentation of wrapper function SavePictureEx() -' -'October 31, 2005 - 1.4.6 -'+ [Carsten Klein] added wrapper function FreeImage_SwapColorLong(): this converts from a RGB to a BGR color value stored in a Long and vice versa -' -'October 27, 2005 - 1.4.5 -'+ [Carsten Klein] added function FreeImage_IsTransparencyTableTransparent(): checks for transparency directly on the transparency table -' -'October 13, 2005 - 1.4.4 -'+ [Carsten Klein] added some functions to compare colors in different formats and with tolerance: -'+ added function FreeImage_CompareColorsLongLong() -'+ added function FreeImage_CompareColorsRGBTRIPLELong() -'+ added function FreeImage_CompareColorsRGBQUADLong() -'+ [Carsten Klein] added enumeration FREE_IMAGE_COLOR_FORMAT_FLAGS -'+ [Carsten Klein] added enumeration FREE_IMAGE_TRANSPARENCY_STATE_FLAGS -'+ [Carsten Klein] added function FreeImage_SearchPalette(): to search the palette index for a given color -' -'October 13, 2005 - 1.4.3 -'+ [Carsten Klein] added additional function declaration FreeImage_SetPixelColorByLong(): now color values may be provided in a long value -'+ [Carsten Klein] added additional function declaration FreeImage_GetPixelColorByLong(): now color values may be received in a long value -'+ [Carsten Klein] added function FreeImage_SetPixelColorEx(): color values may be provided by four different byte values -'+ [Carsten Klein] added function FreeImage_GetPixelColorEx(): color values are returned through four different byte values -' -'October 11, 2005 - 1.4.2 -'* [Carsten Klein] fixed bug in wrapper function FreeImage_GetBitsExRGBQUAD(): now tests for and works with 32 bit images -' -'October 10, 2005 - 1.4.1 -'* [Carsten Klein] fixed serious bug in FreeImage_GetBitsEx...() functions: created custom array descriptor now really has two dimensions -'* fixed wrapper function FreeImage_GetBitsEx() -'* fixed wrapper function FreeImage_GetBitsExRGBTRIPLE() -'* fixed wrapper function FreeImage_GetBitsExRGBQUAD() -' -'September 9, 2005 - 1.4 -'! [Carsten Klein] changed wrapper function FreeImage_ConvertColorDepth(): now uses FreeImage_ConvertToGreyscale -'+ [Carsten Klein] added version numbers to change log -'+ [Carsten Klein] added comments to IOlePicture aware toolkit and conversion functions -'* [Carsten Klein] fixed and adjusted page numbers of the API documentation in header comments in FreeImage function declarations -' -'! now FreeImage version 3.8.0 -' -'September 8, 2005 - 1.3.5 -'! [Carsten Klein] changed version constant 'FREEIMAGE_MINOR_VERSION' to 8 to meet version 3.8.0 -'+ [Carsten Klein] added function declarations for UNICODE dealing functions with additional token 'Int' appended: -'+ added function FreeImage_LoadUInt() -'+ added function FreeImage_SaveUInt() -'+ added function FreeImage_GetFileTypeUInt() -'+ added function FreeImage_GetFIFFromFilenameUInt() -'+ [Carsten Klein] added wrapper functions to ease the use of UNICODE dealing functions: -'+ added function FreeImage_LoadU() -'+ added function FreeImage_SaveU() -'+ added function FreeImage_GetFileTypeU() -'+ added function FreeImage_GetFIFFromFilenameU() -'+ [Carsten Klein] added function declaration for FreeImage_ConvertToGreyscale() -' -'July 18, 2005 - 1.3.4 -'! [Carsten Klein] changed inline comments in these wrapper functions: -'! changed FreeImage_GetBitsEx(): mixed up width and height in SAFEAARAY creation -'! changed FreeImage_GetBitsExRGBTRIPLE(): mixed up width and height in SAFEAARAY creation -'! changed FreeImage_GetBitsExRGBQUAD(): mixed up width and height in SAFEAARAY creation -'+ [Carsten Klein] added wrapper function FreeImage_GetScanLinesRGBTRIPLE(): -' -'June 30, 2005 - 1.3.3 -'+ [Carsten Klein] added Kernel32 function FillMemory() -' -'June 24, 2005 - 1.3.2 -'+ [Carsten Klein] added pixel access functions FreeImage_GetBitsExRGBTRIPLE() and FreeImage_GetBitsExRGBQUAD() -'+ [Carsten Klein] added IOlePicture based wrapper function FreeImage_ConvertColorDepthIOP() -'+ [Carsten Klein] added IOlePicture based wrapper functions for FreeImage_RescaleIOP(): -'+ added function FreeImage_FreeImage_RescaleByPixelIOP() -'+ added function FreeImage_FreeImage_RescaleByPercentIOP() -'+ added function FreeImage_FreeImage_RescaleByFactorIOP() -'+ [Carsten Klein] added IOlePicture based wrapper function FreeImage_RescaleIOP() -'* [Carsten Klein] fixed a bug in FreeImage_GetOlePicture(): now OlePictures returned through IPicture may be used directly by other functions accepting IPicture types without any assignment to IPictureDisp -' -'June 24, 2005 - 1.3.1 -'! [Carsten Klein] changed improper function declaration of function FreeImage_AdjustCurve(): now parameter 'LUT' is passed ByVal -'+ [Carsten Klein] added wrapper function FreeImage_AdjustCurveEx() -'+ [Carsten Klein] added IOlePicture based wrapper functions for FreeImage toolkit functions: -'+ added function FreeImage_RotateClassicIOP() -'+ added function FreeImage_RotateExIOP() -'+ added function FreeImage_FlipHorizontalIOP() -'+ added function FreeImage_FlipVerticalIOP() -'+ added function FreeImage_AdjustCurveIOP() -'+ added function FreeImage_AdjustGammaIOP() -'+ added function FreeImage_AdjustBrightnessIOP() -'+ added function FreeImage_AdjustContrastIOP() -'+ added function FreeImage_InvertIOP() -'+ added function FreeImage_GetChannelIOP() -'+ added function FreeImage_CopyIOP() -'+ added function FreeImage_PasteIOP() -' -'June 22, 2005 - 1.3 -'+ [Carsten Klein] added inline comments and documentation for pixel access functions -' -'June 18, 2005 - 1.2.9 -'+ [Carsten Klein] added function FreeImage_GetBitsEx() -'+ [Carsten Klein] added structure SAFEARRAY2D to create 2 dimensional custom arrays -'+ [Carsten Klein] added function declarations for converting scanlines to 4 bpp: -'+ added declaration for FreeImage_ConvertLine1To4() -'+ added declaration for FreeImage_ConvertLine8To4() -'+ added declaration for FreeImage_ConvertLine16To4_555() -'+ added declaration for FreeImage_ConvertLine16To4_565() -'+ added declaration for FreeImage_ConvertLine24To4() -'+ added declaration for FreeImage_ConvertLine32To4() -' -'June 16, 2005 - 1.2.8 -'! [Carsten Klein] changed improper function declaration for all functions FreeImage_ConvertLineXXXX(): now parameters 'target' and 'Source' are passed ByVal -' -'June 15, 2005 - 1.2.7 -'+ [Carsten Klein] added function FreeImage_DestroyLockedArrayByPtr() to destroy a locked array by it's pointer (VB can't pass a array of structures through a Variant type) -'+ [Carsten Klein] added some wrapper functions for FreeImage_DestroyLockedArrayByPtr() for common FreeImage structures: -'+ added function FreeImage_DestroyLockedArrayRGBTRIPLE() -'+ added function FreeImage_DestroyLockedArrayRGBQUAD() -'+ added function FreeImage_DestroyLockedArrayFICOMPLEX() -'+ added function FreeImage_DestroyLockedArrayFIRGB16() -'+ added function FreeImage_DestroyLockedArrayFIRGBA16() -'+ added function FreeImage_DestroyLockedArrayFIRGBF() -'+ added function FreeImage_DestroyLockedArrayFIRGBAF() -'+ [Carsten Klein] added functions to return scanlines as VB style arrays in all supported FreeImage formats: -'+ added function FreeImage_GetScanLineBITMAP8() -'+ added function FreeImage_GetScanLineBITMAP16() -'+ added function FreeImage_GetScanLineBITMAP24() -'+ added function FreeImage_GetScanLineBITMAP32() -'+ added function FreeImage_GetScanLineINT16() -'+ added function FreeImage_GetScanLineINT32() -'+ added function FreeImage_GetScanLineFLOAT() -'+ added function FreeImage_GetScanLineDOUBLE() -'+ added function FreeImage_GetScanLineCOMPLEX() -'+ added function FreeImage_GetScanLineRGB16() -'+ added function FreeImage_GetScanLineRGBA16() -'+ added function FreeImage_GetScanLineRGBF() -'+ added function FreeImage_GetScanLineRGBAF() -' -'June 14, 2005 - 1.2.6 -'! [Carsten Klein] updated documentation on array-dealing functions using arrays with custom array descriptors -'+ [Carsten Klein] added function FreeImage_DestroyLockedArray() to destroy a self created array 'FADF_AUTO Or FADF_FIXEDSIZE' array -'+ [Carsten Klein] added function FreeImage_GetPaletteExLong() to return palette data in an array of type Long -'+ [Carsten Klein] added parameters 'lPaletteSize', 'vntReservePalette' and 'lReserveSize' to FreeImage_ConvertColorDepth() -' -'June 13, 2005 - 1.2.5 -'* [Carsten Klein] fixed a bug in helper function pGetMemoryBlockPtrFromVariant(): now 'size_in_bytes' will never exceed the size of an array provided -' -'June 12, 2005 - 1.2.4 -'+ [Carsten Klein] added ZLib compression function wrappers dealing with VB style arrays: -'+ added function FreeImage_ZLibCompressVB() -'+ added function FreeImage_ZLibUncompressVB() -'+ added function FreeImage_ZLibGZipVB() -'+ added function FreeImage_ZLibGUnzipVB() -' -'June 10, 2005 - 1.2.3 -'+ [Carsten Klein] added ZLib compression function wrappers dealing with VB style arrays: -'+ added function FreeImage_ZLibCompressEx() -'+ added function FreeImage_ZLibUncompressEx() -'+ added function FreeImage_ZLibGZipEx() -'+ added function FreeImage_ZLibCRC32Ex() -'+ added function FreeImage_ZLibGUnzipEx() -'+ [Carsten Klein] added more VB friendly ZLib compression function wrappers: -'+ added function FreeImage_ZLibCompressVB() -'+ added function FreeImage_ZLibUncompressVB() -'+ added function FreeImage_ZLibGZipVB() -'+ added function FreeImage_ZLibGUnzipVB() -'! [Carsten Klein] fixed wrong function declaration of functions FreeImage_ZLibGUnzip(): alias was '_FreeImage_ZLibZlibGUnzip@16' (double ZLib) -'! [Carsten Klein] fixed function pGetArrayPtrFromVariantArray() that now can deal with uninitialized arrays -'! fixed function pGetMemoryBlockPtrFromVariant() that now can deal with uninitialized arrays -'! [Carsten Klein] fixed wrong function declaration of functions FreeImage_AdjustBrightness(): ...@8 -> ...@12 -'! fixed wrong function declaration of functions FreeImage_AdjustContrast(): ...@8 -> ...@12 -'! fixed wrong function declaration of functions FreeImage_AdjustGamma(): ...@8 -> ...@12 -'! fixed wrong function declaration of functions FreeImage_RotateClassic(): ...@8 -> ...@12 -'! fixed wrong function declaration of functions FreeImage_RotateEx(): ...@28 -> ...@48 -' -'June 9, 2005 - 1.2.2 -'! [Carsten Klein] fixed wrong function declaration of function FreeImage_OpenMultiBitmap(): added parameter 'flags' (...@20 -> ...@24) -' -'June 8, 2005 - 1.2.1 -'! [Carsten Klein] refactored function FreeImage_LoadFromMemoryEx(): now using pGetMemoryBlockPtrFromVariant() -'+ [Carsten Klein] added private function pGetMemoryBlockPtrFromVariant() to get poiner and size of a memory block from a Variant parameter -'! [Carsten Klein] changed declaration of ZLib related functions: 'target' and 'Source' are now 'ByVal Long' -' -'June 7, 2005 - 1.2 -'+ [Carsten Klein] added some more inline comments and documentation -'+ [Carsten Klein] added optional parameter 'UnloadSource' to function FreeImage_SaveToMemoryEx() -'+ added optional parameter 'UnloadSource' to function FreeImage_SaveToMemoryEx2() -'+ [Carsten Klein] added optional parameter 'InPercent' to function SavePictureEx() -'! implemented the capability to resize the image on saving in function SavePictureEx() -'+ [Carsten Klein] added parameters 'InPercent' and 'Format' to function LoadPictureEx() -'* [Carsten Klein] fixed wrong function declaration of function FreeImage_JPEGTransform() (...@12 -> ...@16) -' -'June 6, 2005 - 1.1.2 -'+ [Carsten Klein] added some more inline comments and documentation -' -'May 30, 2005 - 1.1.1 -'* [Carsten Klein] fixed percent calculating bug in function FreeImage_RescaleEx() -'! changed behaviour of parameter 'bIsPercentValue' -> it now has no effect on integer values -'+ added function FreeImage_RescaleByPixel() to avoid confusion with overloading -'+ added function FreeImage_RescaleByPercent() to avoid confusion with overloading -'+ added function FreeImage_RescaleByFactor() to avoid confusion with overloading -'! [Carsten Klein] changed name of parameter 'bUnloadDIB' to 'UnloadSource' of function FreeImage_GetOlePicture() -'+ [Carsten Klein] added some more inline comments and documentation -'* [Carsten Klein] fixed a potential runtime error in function FreeImage_SetTransparencyTableEx(): 'Count' will no longer exceed 256 -' -'May 24, 2005 - 1.1 -'+ [Carsten Klein] added a new VB wrapper - - -'-------------------------------------------------------------------------------- -' Win32 API function, struct and constant declarations -'-------------------------------------------------------------------------------- - -Private Const ERROR_SUCCESS As Long = 0 - -'KERNEL32 -Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" ( _ - ByRef Destination As Any, _ - ByRef Source As Any, _ - ByVal Length As Long) - -Private Declare Sub FillMemory Lib "kernel32.dll" Alias "RtlFillMemory" ( _ - ByRef Destination As Any, _ - ByVal Length As Long, _ - ByVal Fill As Byte) - -Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" ( _ - ByVal lpString As Long) As Long - - -'OLEAUT32 -Private Declare Function OleCreatePictureIndirect Lib "oleaut32.dll" ( _ - ByRef lpPictDesc As PictDesc, _ - ByRef riid As Guid, _ - ByVal fOwn As Long, _ - ByRef lplpvObj As IPicture) As Long - -Private Declare Function SafeArrayAllocDescriptor Lib "oleaut32.dll" ( _ - ByVal cDims As Long, _ - ByRef ppsaOut As Long) As Long - -Private Declare Function SafeArrayDestroyDescriptor Lib "oleaut32.dll" ( _ - ByVal psa As Long) As Long - -Private Declare Sub SafeArrayDestroyData Lib "oleaut32.dll" ( _ - ByVal psa As Long) - -Private Declare Function OleTranslateColor Lib "oleaut32.dll" ( _ - ByVal clr As OLE_COLOR, _ - ByVal hPal As Long, _ - ByRef lpcolorref As Long) As Long - -Private Const CLR_INVALID As Long = &HFFFF& - - -'SAFEARRAY -Private Const FADF_AUTO As Long = (&H1) -Private Const FADF_FIXEDSIZE As Long = (&H10) - -Private Type SAVEARRAY1D - cDims As Integer - fFeatures As Integer - cbElements As Long - cLocks As Long - pvData As Long - cElements As Long - lLbound As Long -End Type - -Private Type SAVEARRAY2D - cDims As Integer - fFeatures As Integer - cbElements As Long - cLocks As Long - pvData As Long - cElements1 As Long - lLbound1 As Long - cElements2 As Long - lLbound2 As Long -End Type - - -'MSVBVM60 -Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" ( _ - ByRef Ptr() As Any) As Long - - -'USER32 -Private Declare Function ReleaseDC Lib "user32.dll" ( _ - ByVal hWnd As Long, _ - ByVal hDC As Long) As Long - -Private Declare Function GetDC Lib "user32.dll" ( _ - ByVal hWnd As Long) As Long - -Private Declare Function GetDesktopWindow Lib "user32.dll" () As Long - -Private Declare Function GetDCEx Lib "user32.dll" ( _ - ByVal hWnd As Long, _ - ByVal hrgnclip As Long, _ - ByVal fdwOptions As Long) As Long - -Private Const DCX_WINDOW As Long = &H1& - -Private Declare Function GetWindowRect Lib "user32.dll" ( _ - ByVal hWnd As Long, _ - ByRef lpRect As RECT) As Long - -Private Declare Function GetClientRect Lib "user32.dll" ( _ - ByVal hWnd As Long, _ - ByRef lpRect As RECT) As Long - - -Private Type RECT - Left As Long - Top As Long - Right As Long - Bottom As Long -End Type - -Private Type Guid - Data1 As Long - Data2 As Integer - Data3 As Integer - Data4(0 To 7) As Byte -End Type - -Private Type PictDesc - cbSizeofStruct As Long - picType As Long - hImage As Long - xExt As Long - yExt As Long -End Type - -Private Type BITMAP_API - bmType As Long - bmWidth As Long - bmHeight As Long - bmWidthBytes As Long - bmPlanes As Integer - bmBitsPixel As Integer - bmBits As Long -End Type - -Private Type ICONINFO - fIcon As Long - xHotspot As Long - yHotspot As Long - hBmMask As Long - hbmColor As Long -End Type - -Private Type BLENDFUNCTION - BlendOp As Byte - BlendFlags As Byte - SourceConstantAlpha As Byte - AlphaFormat As Byte -End Type - -'GDI32 -Private Declare Function GetDeviceCaps Lib "gdi32.dll" ( _ - ByVal hDC As Long, _ - ByVal nIndex As Long) As Long - -Private Const HORZRES As Long = 8 -Private Const VERTRES As Long = 10 - -Private Declare Function GetStretchBltMode Lib "gdi32.dll" ( _ - ByVal hDC As Long) As Long - -Private Declare Function SetStretchBltMode Lib "gdi32.dll" ( _ - ByVal hDC As Long, _ - ByVal nStretchMode As Long) As Long - -Private Declare Function SetDIBitsToDevice Lib "gdi32.dll" ( _ - ByVal hDC As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByVal dx As Long, _ - ByVal dy As Long, _ - ByVal SrcX As Long, _ - ByVal SrcY As Long, _ - ByVal Scan As Long, _ - ByVal NumScans As Long, _ - ByVal Bits As Long, _ - ByVal BitsInfo As Long, _ - ByVal wUsage As Long) As Long - -Private Declare Function StretchDIBits Lib "gdi32.dll" ( _ - ByVal hDC As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByVal dx As Long, _ - ByVal dy As Long, _ - ByVal SrcX As Long, _ - ByVal SrcY As Long, _ - ByVal wSrcWidth As Long, _ - ByVal wSrcHeight As Long, _ - ByVal lpBits As Long, _ - ByVal lpBitsInfo As Long, _ - ByVal wUsage As Long, _ - ByVal dwRop As Long) As Long - -Private Declare Function CreateDIBitmap Lib "gdi32.dll" ( _ - ByVal hDC As Long, _ - ByVal lpInfoHeader As Long, _ - ByVal dwUsage As Long, _ - ByVal lpInitBits As Long, _ - ByVal lpInitInfo As Long, _ - ByVal wUsage As Long) As Long - -Private Declare Function CreateDIBSection Lib "gdi32.dll" ( _ - ByVal hDC As Long, _ - ByVal pbmi As Long, _ - ByVal iUsage As Long, _ - ByRef ppvBits As Long, _ - ByVal hSection As Long, _ - ByVal dwOffset As Long) As Long - -Private Const CBM_INIT As Long = &H4 - -Private Declare Function CreateCompatibleBitmap Lib "gdi32.dll" ( _ - ByVal hDC As Long, _ - ByVal nWidth As Long, _ - ByVal nHeight As Long) As Long - -Private Declare Function CreateCompatibleDC Lib "gdi32.dll" ( _ - ByVal hDC As Long) As Long - -Private Declare Function DeleteDC Lib "gdi32.dll" ( _ - ByVal hDC As Long) As Long - -Private Declare Function BitBlt Lib "gdi32.dll" ( _ - ByVal hDestDC As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByVal nWidth As Long, _ - ByVal nHeight As Long, _ - ByVal hSrcDC As Long, _ - ByVal XSrc As Long, _ - ByVal YSrc As Long, _ - ByVal dwRop As Long) As Long - -Private Declare Function GetDIBits Lib "gdi32.dll" ( _ - ByVal aHDC As Long, _ - ByVal hBitmap As Long, _ - ByVal nStartScan As Long, _ - ByVal nNumScans As Long, _ - ByVal lpBits As Long, _ - ByVal lpBI As Long, _ - ByVal wUsage As Long) As Long - -Private Declare Function GetObjectAPI Lib "gdi32.dll" Alias "GetObjectA" ( _ - ByVal hObject As Long, _ - ByVal nCount As Long, _ - ByRef lpObject As Any) As Long - -Private Declare Function SelectObject Lib "gdi32.dll" ( _ - ByVal hDC As Long, _ - ByVal hObject As Long) As Long - -Private Declare Function DeleteObject Lib "gdi32.dll" ( _ - ByVal hObject As Long) As Long - -Private Declare Function GetCurrentObject Lib "gdi32.dll" ( _ - ByVal hDC As Long, _ - ByVal uObjectType As Long) As Long - -Private Const OBJ_BITMAP As Long = 7 - - -Private Declare Function DestroyIcon Lib "user32.dll" ( _ - ByVal hIcon As Long) As Long - -Private Declare Function CreateIconIndirect Lib "user32.dll" ( _ - ByRef piconinfo As ICONINFO) As Long - -Private Const BLACKONWHITE As Long = 1 -Private Const WHITEONBLACK As Long = 2 -Private Const COLORONCOLOR As Long = 3 - -'MSIMG32 -Private Declare Function AlphaBlend Lib "msimg32.dll" ( _ - ByVal hdcDest As Long, _ - ByVal nXOriginDest As Long, _ - ByVal nYOriginDest As Long, _ - ByVal nWidthDest As Long, _ - ByVal nHeightDest As Long, _ - ByVal hdcSrc As Long, _ - ByVal nXOriginSrc As Long, _ - ByVal nYOriginSrc As Long, _ - ByVal nWidthSrc As Long, _ - ByVal nHeightSrc As Long, _ - ByVal lBlendFunction As Long) As Long - -Private Const AC_SRC_OVER = &H0 -Private Const AC_SRC_ALPHA = &H1 - - -Public Enum STRETCH_MODE - SM_BLACKONWHITE = BLACKONWHITE - SM_WHITEONBLACK = WHITEONBLACK - SM_COLORONCOLOR = COLORONCOLOR -End Enum -#If False Then - Const SM_BLACKONWHITE = BLACKONWHITE - Const SM_WHITEONBLACK = WHITEONBLACK - Const SM_COLORONCOLOR = COLORONCOLOR -#End If - - -Private Const SRCAND As Long = &H8800C6 -Private Const SRCCOPY As Long = &HCC0020 -Private Const SRCERASE As Long = &H440328 -Private Const SRCINVERT As Long = &H660046 -Private Const SRCPAINT As Long = &HEE0086 -Private Const CAPTUREBLT As Long = &H40000000 - -Public Enum RASTER_OPERATOR - ROP_SRCAND = SRCAND - ROP_SRCCOPY = SRCCOPY - ROP_SRCERASE = SRCERASE - ROP_SRCINVERT = SRCINVERT - ROP_SRCPAINT = SRCPAINT -End Enum -#If False Then - Const ROP_SRCAND = SRCAND - Const ROP_SRCCOPY = SRCCOPY - Const ROP_SRCERASE = SRCERASE - Const ROP_SRCINVERT = SRCINVERT - Const ROP_SRCPAINT = SRCPAINT -#End If - -Private Const DIB_PAL_COLORS As Long = 1 -Private Const DIB_RGB_COLORS As Long = 0 - -Public Enum DRAW_MODE - DM_DRAW_DEFAULT = &H0 - DM_MIRROR_NONE = DM_DRAW_DEFAULT - DM_MIRROR_VERTICAL = &H1 - DM_MIRROR_HORIZONTAL = &H2 - DM_MIRROR_BOTH = DM_MIRROR_VERTICAL Or DM_MIRROR_HORIZONTAL -End Enum -#If False Then - Const DM_DRAW_DEFAULT = &H0 - Const DM_MIRROR_NONE = DM_DRAW_DEFAULT - Const DM_MIRROR_VERTICAL = &H1 - Const DM_MIRROR_HORIZONTAL = &H2 - Const DM_MIRROR_BOTH = DM_MIRROR_VERTICAL Or DM_MIRROR_HORIZONTAL -#End If - -Public Enum HISTOGRAM_ORIENTATION - HOR_TOP_DOWN = &H0 - HOR_BOTTOM_UP = &H1 -End Enum -#If False Then - Const HOR_TOP_DOWN = &H0 - Const HOR_BOTTOM_UP = &H1 -#End If - - -'-------------------------------------------------------------------------------- -' FreeImage 3 types, constants and enumerations -'-------------------------------------------------------------------------------- - -'FREEIMAGE - -' Version information -Public Const FREEIMAGE_MAJOR_VERSION As Long = 3 -Public Const FREEIMAGE_MINOR_VERSION As Long = 15 -Public Const FREEIMAGE_RELEASE_SERIAL As Long = 4 - -' Memory stream pointer operation flags -Public Const SEEK_SET As Long = 0 -Public Const SEEK_CUR As Long = 1 -Public Const SEEK_END As Long = 2 - -' Indexes for byte arrays, masks and shifts for treating pixels as words -' These coincide with the order of RGBQUAD and RGBTRIPLE -' Little Endian (x86 / MS Windows, Linux) : BGR(A) order -Public Const FI_RGBA_RED As Long = 2 -Public Const FI_RGBA_GREEN As Long = 1 -Public Const FI_RGBA_BLUE As Long = 0 -Public Const FI_RGBA_ALPHA As Long = 3 -Public Const FI_RGBA_RED_MASK As Long = &HFF0000 -Public Const FI_RGBA_GREEN_MASK As Long = &HFF00 -Public Const FI_RGBA_BLUE_MASK As Long = &HFF -Public Const FI_RGBA_ALPHA_MASK As Long = &HFF000000 -Public Const FI_RGBA_RED_SHIFT As Long = 16 -Public Const FI_RGBA_GREEN_SHIFT As Long = 8 -Public Const FI_RGBA_BLUE_SHIFT As Long = 0 -Public Const FI_RGBA_ALPHA_SHIFT As Long = 24 - -' The 16 bit macros only include masks and shifts, since each color element is not byte aligned -Public Const FI16_555_RED_MASK As Long = &H7C00 -Public Const FI16_555_GREEN_MASK As Long = &H3E0 -Public Const FI16_555_BLUE_MASK As Long = &H1F -Public Const FI16_555_RED_SHIFT As Long = 10 -Public Const FI16_555_GREEN_SHIFT As Long = 5 -Public Const FI16_555_BLUE_SHIFT As Long = 0 -Public Const FI16_565_RED_MASK As Long = &HF800 -Public Const FI16_565_GREEN_MASK As Long = &H7E0 -Public Const FI16_565_BLUE_MASK As Long = &H1F -Public Const FI16_565_RED_SHIFT As Long = 11 -Public Const FI16_565_GREEN_SHIFT As Long = 5 -Public Const FI16_565_BLUE_SHIFT As Long = 0 - -' ICC profile support -Public Const FIICC_DEFAULT As Long = &H0 -Public Const FIICC_COLOR_IS_CMYK As Long = &H1 - -Private Const FREE_IMAGE_ICC_COLOR_MODEL_MASK As Long = &H1 -Public Enum FREE_IMAGE_ICC_COLOR_MODEL - FIICC_COLOR_MODEL_RGB = &H0 - FIICC_COLOR_MODEL_CMYK = &H1 -End Enum - -' Load / Save flag constants -Public Const FIF_LOAD_NOPIXELS = &H8000 ' load the image header only (not supported by all plugins) - -Public Const BMP_DEFAULT As Long = 0 -Public Const BMP_SAVE_RLE As Long = 1 -Public Const CUT_DEFAULT As Long = 0 -Public Const DDS_DEFAULT As Long = 0 -Public Const EXR_DEFAULT As Long = 0 ' save data as half with piz-based wavelet compression -Public Const EXR_FLOAT As Long = &H1 ' save data as float instead of as half (not recommended) -Public Const EXR_NONE As Long = &H2 ' save with no compression -Public Const EXR_ZIP As Long = &H4 ' save with zlib compression, in blocks of 16 scan lines -Public Const EXR_PIZ As Long = &H8 ' save with piz-based wavelet compression -Public Const EXR_PXR24 As Long = &H10 ' save with lossy 24-bit float compression -Public Const EXR_B44 As Long = &H20 ' save with lossy 44% float compression - goes to 22% when combined with EXR_LC -Public Const EXR_LC As Long = &H40 ' save images with one luminance and two chroma channels, rather than as RGB (lossy compression) -Public Const FAXG3_DEFAULT As Long = 0 -Public Const GIF_DEFAULT As Long = 0 -Public Const GIF_LOAD256 As Long = 1 ' Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color -Public Const GIF_PLAYBACK As Long = 2 ''Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading -Public Const HDR_DEFAULT As Long = 0 -Public Const ICO_DEFAULT As Long = 0 -Public Const ICO_MAKEALPHA As Long = 1 ' convert to 32bpp and create an alpha channel from the AND-mask when loading -Public Const IFF_DEFAULT As Long = 0 -Public Const J2K_DEFAULT As Long = 0 ' save with a 16:1 rate -Public Const JP2_DEFAULT As Long = 0 ' save with a 16:1 rate -Public Const JPEG_DEFAULT As Long = 0 ' loading (see JPEG_FAST); saving (see JPEG_QUALITYGOOD|JPEG_SUBSAMPLING_420) -Public Const JPEG_FAST As Long = &H1 ' load the file as fast as possible, sacrificing some quality -Public Const JPEG_ACCURATE As Long = &H2 ' load the file with the best quality, sacrificing some speed -Public Const JPEG_CMYK As Long = &H4 ' load separated CMYK "as is" (use 'OR' to combine with other flags) -Public Const JPEG_EXIFROTATE As Long = &H8 ' load and rotate according to Exif 'Orientation' tag if available -Public Const JPEG_GREYSCALE As Long = &H10 ' load and convert to a 8-bit greyscale image -Public Const JPEG_QUALITYSUPERB As Long = &H80 ' save with superb quality (100:1) -Public Const JPEG_QUALITYGOOD As Long = &H100 ' save with good quality (75:1) -Public Const JPEG_QUALITYNORMAL As Long = &H200 ' save with normal quality (50:1) -Public Const JPEG_QUALITYAVERAGE As Long = &H400 ' save with average quality (25:1) -Public Const JPEG_QUALITYBAD As Long = &H800 ' save with bad quality (10:1) -Public Const JPEG_PROGRESSIVE As Long = &H2000 ' save as a progressive-JPEG (use 'OR' to combine with other save flags) -Public Const JPEG_SUBSAMPLING_411 As Long = &H1000 ' save with high 4x1 chroma subsampling (4:1:1) -Public Const JPEG_SUBSAMPLING_420 As Long = &H4000 ' save with medium 2x2 medium chroma subsampling (4:2:0) - default value -Public Const JPEG_SUBSAMPLING_422 As Long = &H8000 ' save with low 2x1 chroma subsampling (4:2:2) -Public Const JPEG_SUBSAMPLING_444 As Long = &H10000 ' save with no chroma subsampling (4:4:4) -Public Const JPEG_OPTIMIZE As Long = &H20000 ' on saving, compute optimal Huffman coding tables (can reduce a few percent of file size) -Public Const JPEG_BASELINE As Long = &H40000 ' save basic JPEG, without metadata or any markers -Public Const KOALA_DEFAULT As Long = 0 -Public Const LBM_DEFAULT As Long = 0 -Public Const MNG_DEFAULT As Long = 0 -Public Const PCD_DEFAULT As Long = 0 -Public Const PCD_BASE As Long = 1 ' load the bitmap sized 768 x 512 -Public Const PCD_BASEDIV4 As Long = 2 ' load the bitmap sized 384 x 256 -Public Const PCD_BASEDIV16 As Long = 3 ' load the bitmap sized 192 x 128 -Public Const PCX_DEFAULT As Long = 0 -Public Const PFM_DEFAULT As Long = 0 -Public Const PICT_DEFAULT As Long = 0 -Public Const PNG_DEFAULT As Long = 0 -Public Const PNG_IGNOREGAMMA As Long = 1 ' avoid gamma correction -Public Const PNG_Z_BEST_SPEED As Long = &H1 ' save using ZLib level 1 compression flag (default value is 6) -Public Const PNG_Z_DEFAULT_COMPRESSION As Long = &H6 ' save using ZLib level 6 compression flag (default recommended value) -Public Const PNG_Z_BEST_COMPRESSION As Long = &H9 ' save using ZLib level 9 compression flag (default value is 6) -Public Const PNG_Z_NO_COMPRESSION As Long = &H100 ' save without ZLib compression -Public Const PNG_INTERLACED As Long = &H200 ' save using Adam7 interlacing (use | to combine with other save flags) -Public Const PNM_DEFAULT As Long = 0 -Public Const PNM_SAVE_RAW As Long = 0 ' if set, the writer saves in RAW format (i.e. P4, P5 or P6) -Public Const PNM_SAVE_ASCII As Long = 1 ' if set, the writer saves in ASCII format (i.e. P1, P2 or P3) -Public Const PSD_DEFAULT As Long = 0 -Public Const PSD_CMYK As Long = 1 ' reads tags for separated CMYK (default is conversion to RGB) -Public Const PSD_LAB As Long = 2 ' reads tags for CIELab (default is conversion to RGB) -Public Const RAS_DEFAULT As Long = 0 -Public Const RAW_DEFAULT As Long = 0 ' load the file as linear RGB 48-bit -Public Const RAW_PREVIEW As Long = 1 ' try to load the embedded JPEG preview with included Exif Data or default to RGB 24-bit -Public Const RAW_DISPLAY As Long = 2 ' load the file as RGB 24-bit -Public Const RAW_HALFSIZE As Long = 4 ' load the file as half-size color image -Public Const SGI_DEFAULT As Long = 0 -Public Const TARGA_DEFAULT As Long = 0 -Public Const TARGA_LOAD_RGB888 As Long = 1 ' if set, the loader converts RGB555 and ARGB8888 -> RGB888 -Public Const TARGA_SAVE_RLE As Long = 2 ' if set, the writer saves with RLE compression -Public Const TIFF_DEFAULT As Long = 0 -Public Const TIFF_CMYK As Long = &H1 ' reads/stores tags for separated CMYK (use 'OR' to combine with compression flags) -Public Const TIFF_PACKBITS As Long = &H100 ' save using PACKBITS compression -Public Const TIFF_DEFLATE As Long = &H200 ' save using DEFLATE compression (a.k.a. ZLIB compression) -Public Const TIFF_ADOBE_DEFLATE As Long = &H400 ' save using ADOBE DEFLATE compression -Public Const TIFF_NONE As Long = &H800 ' save without any compression -Public Const TIFF_CCITTFAX3 As Long = &H1000 ' save using CCITT Group 3 fax encoding -Public Const TIFF_CCITTFAX4 As Long = &H2000 ' save using CCITT Group 4 fax encoding -Public Const TIFF_LZW As Long = &H4000 ' save using LZW compression -Public Const TIFF_JPEG As Long = &H8000 ' save using JPEG compression -Public Const TIFF_LOGLUV As Long = &H10000 ' save using LogLuv compression -Public Const WBMP_DEFAULT As Long = 0 -Public Const XBM_DEFAULT As Long = 0 -Public Const XPM_DEFAULT As Long = 0 - -Public Enum FREE_IMAGE_FORMAT - FIF_UNKNOWN = -1 - FIF_BMP = 0 - FIF_ICO = 1 - FIF_JPEG = 2 - FIF_JNG = 3 - FIF_KOALA = 4 - FIF_LBM = 5 - FIF_IFF = FIF_LBM - FIF_MNG = 6 - FIF_PBM = 7 - FIF_PBMRAW = 8 - FIF_PCD = 9 - FIF_PCX = 10 - FIF_PGM = 11 - FIF_PGMRAW = 12 - FIF_PNG = 13 - FIF_PPM = 14 - FIF_PPMRAW = 15 - FIF_RAS = 16 - FIF_TARGA = 17 - FIF_TIFF = 18 - FIF_WBMP = 19 - FIF_PSD = 20 - FIF_CUT = 21 - FIF_XBM = 22 - FIF_XPM = 23 - FIF_DDS = 24 - FIF_GIF = 25 - FIF_HDR = 26 - FIF_FAXG3 = 27 - FIF_SGI = 28 - FIF_EXR = 29 - FIF_J2K = 30 - FIF_JP2 = 31 - FIF_PFM = 32 - FIF_PICT = 33 - FIF_RAW = 34 -End Enum -#If False Then - Const FIF_UNKNOWN = -1 - Const FIF_BMP = 0 - Const FIF_ICO = 1 - Const FIF_JPEG = 2 - Const FIF_JNG = 3 - Const FIF_KOALA = 4 - Const FIF_LBM = 5 - Const FIF_IFF = FIF_LBM - Const FIF_MNG = 6 - Const FIF_PBM = 7 - Const FIF_PBMRAW = 8 - Const FIF_PCD = 9 - Const FIF_PCX = 10 - Const FIF_PGM = 11 - Const FIF_PGMRAW = 12 - Const FIF_PNG = 13 - Const FIF_PPM = 14 - Const FIF_PPMRAW = 15 - Const FIF_RAS = 16 - Const FIF_TARGA = 17 - Const FIF_TIFF = 18 - Const FIF_WBMP = 19 - Const FIF_PSD = 20 - Const FIF_CUT = 21 - Const FIF_XBM = 22 - Const FIF_XPM = 23 - Const FIF_DDS = 24 - Const FIF_GIF = 25 - Const FIF_HDR = 26 - Const FIF_FAXG3 = 27 - Const FIF_SGI = 28 - Const FIF_EXR = 29 - Const FIF_J2K = 30 - Const FIF_JP2 = 31 - Const FIF_PFM = 32 - Const FIF_PICT = 33 - Const FIF_RAW = 34 -#End If - -Public Enum FREE_IMAGE_LOAD_OPTIONS - FILO_LOAD_NOPIXELS = &H8000 ' load the image header only (not supported by all plugins) - FILO_LOAD_DEFAULT = 0 - FILO_GIF_DEFAULT = GIF_DEFAULT - FILO_GIF_LOAD256 = GIF_LOAD256 ' load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color - FILO_GIF_PLAYBACK = GIF_PLAYBACK ' 'play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading - FILO_ICO_DEFAULT = ICO_DEFAULT - FILO_ICO_MAKEALPHA = ICO_MAKEALPHA ' convert to 32bpp and create an alpha channel from the AND-mask when loading - FILO_JPEG_DEFAULT = JPEG_DEFAULT ' for loading this is a synonym for FILO_JPEG_FAST - FILO_JPEG_FAST = JPEG_FAST ' load the file as fast as possible, sacrificing some quality - FILO_JPEG_ACCURATE = JPEG_ACCURATE ' load the file with the best quality, sacrificing some speed - FILO_JPEG_CMYK = JPEG_CMYK ' load separated CMYK "as is" (use 'OR' to combine with other load flags) - FILO_JPEG_EXIFROTATE = JPEG_EXIFROTATE ' load and rotate according to Exif 'Orientation' tag if available - FILO_JPEG_GREYSCALE = JPEG_GREYSCALE ' load and convert to a 8-bit greyscale image - FILO_PCD_DEFAULT = PCD_DEFAULT - FILO_PCD_BASE = PCD_BASE ' load the bitmap sized 768 x 512 - FILO_PCD_BASEDIV4 = PCD_BASEDIV4 ' load the bitmap sized 384 x 256 - FILO_PCD_BASEDIV16 = PCD_BASEDIV16 ' load the bitmap sized 192 x 128 - FILO_PNG_DEFAULT = PNG_DEFAULT - FILO_PNG_IGNOREGAMMA = PNG_IGNOREGAMMA ' avoid gamma correction - FILO_PSD_CMYK = PSD_CMYK ' reads tags for separated CMYK (default is conversion to RGB) - FILO_PSD_LAB = PSD_LAB ' reads tags for CIELab (default is conversion to RGB) - FILO_RAW_DEFAULT = RAW_DEFAULT ' load the file as linear RGB 48-bit - FILO_RAW_PREVIEW = RAW_PREVIEW ' try to load the embedded JPEG preview with included Exif Data or default to RGB 24-bit - FILO_RAW_DISPLAY = RAW_DISPLAY ' load the file as RGB 24-bit - FILO_RAW_HALFSIZE = RAW_HALFSIZE ' load the file as half-size color image - FILO_TARGA_DEFAULT = TARGA_LOAD_RGB888 - FILO_TARGA_LOAD_RGB888 = TARGA_LOAD_RGB888 ' if set, the loader converts RGB555 and ARGB8888 -> RGB888 - FISO_TIFF_DEFAULT = TIFF_DEFAULT - FISO_TIFF_CMYK = TIFF_CMYK ' reads tags for separated CMYK -End Enum -#If False Then - Const FILO_LOAD_NOPIXELS = &H8000 - Const FILO_LOAD_DEFAULT = 0 - Const FILO_GIF_DEFAULT = GIF_DEFAULT - Const FILO_GIF_LOAD256 = GIF_LOAD256 - Const FILO_GIF_PLAYBACK = GIF_PLAYBACK - Const FILO_ICO_DEFAULT = ICO_DEFAULT - Const FILO_ICO_MAKEALPHA = ICO_MAKEALPHA - Const FILO_JPEG_DEFAULT = JPEG_DEFAULT - Const FILO_JPEG_FAST = JPEG_FAST - Const FILO_JPEG_ACCURATE = JPEG_ACCURATE - Const FILO_JPEG_CMYK = JPEG_CMYK - Const FILO_JPEG_EXIFROTATE = JPEG_EXIFROTATE - Const FILO_PCD_DEFAULT = PCD_DEFAULT - Const FILO_PCD_BASE = PCD_BASE - Const FILO_PCD_BASEDIV4 = PCD_BASEDIV4 - Const FILO_PCD_BASEDIV16 = PCD_BASEDIV16 - Const FILO_PNG_DEFAULT = PNG_DEFAULT - Const FILO_PNG_IGNOREGAMMA = PNG_IGNOREGAMMA - Const FILO_TARGA_DEFAULT = TARGA_LOAD_RGB888 - Const FILO_TARGA_LOAD_RGB888 = TARGA_LOAD_RGB888 - Const FISO_TIFF_DEFAULT = TIFF_DEFAULT - Const FISO_TIFF_CMYK = TIFF_CMYK -#End If - -Public Enum FREE_IMAGE_SAVE_OPTIONS - FISO_SAVE_DEFAULT = 0 - FISO_BMP_DEFAULT = BMP_DEFAULT - FISO_BMP_SAVE_RLE = BMP_SAVE_RLE - FISO_EXR_DEFAULT = EXR_DEFAULT ' save data as half with piz-based wavelet compression - FISO_EXR_FLOAT = EXR_FLOAT ' save data as float instead of as half (not recommended) - FISO_EXR_NONE = EXR_NONE ' save with no compression - FISO_EXR_ZIP = EXR_ZIP ' save with zlib compression, in blocks of 16 scan lines - FISO_EXR_PIZ = EXR_PIZ ' save with piz-based wavelet compression - FISO_EXR_PXR24 = EXR_PXR24 ' save with lossy 24-bit float compression - FISO_EXR_B44 = EXR_B44 ' save with lossy 44% float compression - goes to 22% when combined with EXR_LC - FISO_EXR_LC = EXR_LC ' save images with one luminance and two chroma channels, rather than as RGB (lossy compression) - FISO_JPEG_DEFAULT = JPEG_DEFAULT ' for saving this is a synonym for FISO_JPEG_QUALITYGOOD - FISO_JPEG_QUALITYSUPERB = JPEG_QUALITYSUPERB ' save with superb quality (100:1) - FISO_JPEG_QUALITYGOOD = JPEG_QUALITYGOOD ' save with good quality (75:1) - FISO_JPEG_QUALITYNORMAL = JPEG_QUALITYNORMAL ' save with normal quality (50:1) - FISO_JPEG_QUALITYAVERAGE = JPEG_QUALITYAVERAGE ' save with average quality (25:1) - FISO_JPEG_QUALITYBAD = JPEG_QUALITYBAD ' save with bad quality (10:1) - FISO_JPEG_PROGRESSIVE = JPEG_PROGRESSIVE ' save as a progressive-JPEG (use 'OR' to combine with other save flags) - FISO_JPEG_SUBSAMPLING_411 = JPEG_SUBSAMPLING_411 ' save with high 4x1 chroma subsampling (4:1:1) - FISO_JPEG_SUBSAMPLING_420 = JPEG_SUBSAMPLING_420 ' save with medium 2x2 medium chroma subsampling (4:2:0) - default value - FISO_JPEG_SUBSAMPLING_422 = JPEG_SUBSAMPLING_422 ' save with low 2x1 chroma subsampling (4:2:2) - FISO_JPEG_SUBSAMPLING_444 = JPEG_SUBSAMPLING_444 ' save with no chroma subsampling (4:4:4) - FISO_JPEG_OPTIMIZE = JPEG_OPTIMIZE ' compute optimal Huffman coding tables (can reduce a few percent of file size) - FISO_JPEG_BASELINE = JPEG_BASELINE ' save basic JPEG, without metadata or any markers - FISO_PNG_Z_BEST_SPEED = PNG_Z_BEST_SPEED ' save using ZLib level 1 compression flag (default value is 6) - FISO_PNG_Z_DEFAULT_COMPRESSION = PNG_Z_DEFAULT_COMPRESSION ' save using ZLib level 6 compression flag (default recommended value) - FISO_PNG_Z_BEST_COMPRESSION = PNG_Z_BEST_COMPRESSION ' save using ZLib level 9 compression flag (default value is 6) - FISO_PNG_Z_NO_COMPRESSION = PNG_Z_NO_COMPRESSION ' save without ZLib compression - FISO_PNG_INTERLACED = PNG_INTERLACED ' save using Adam7 interlacing (use | to combine with other save flags) - FISO_PNM_DEFAULT = PNM_DEFAULT - FISO_PNM_SAVE_RAW = PNM_SAVE_RAW ' if set, the writer saves in RAW format (i.e. P4, P5 or P6) - FISO_PNM_SAVE_ASCII = PNM_SAVE_ASCII ' if set, the writer saves in ASCII format (i.e. P1, P2 or P3) - FISO_TARGA_SAVE_RLE = TARGA_SAVE_RLE ' if set, the writer saves with RLE compression - FISO_TIFF_DEFAULT = TIFF_DEFAULT - FISO_TIFF_CMYK = TIFF_CMYK ' stores tags for separated CMYK (use 'OR' to combine with compression flags) - FISO_TIFF_PACKBITS = TIFF_PACKBITS ' save using PACKBITS compression - FISO_TIFF_DEFLATE = TIFF_DEFLATE ' save using DEFLATE compression (a.k.a. ZLIB compression) - FISO_TIFF_ADOBE_DEFLATE = TIFF_ADOBE_DEFLATE ' save using ADOBE DEFLATE compression - FISO_TIFF_NONE = TIFF_NONE ' save without any compression - FISO_TIFF_CCITTFAX3 = TIFF_CCITTFAX3 ' save using CCITT Group 3 fax encoding - FISO_TIFF_CCITTFAX4 = TIFF_CCITTFAX4 ' save using CCITT Group 4 fax encoding - FISO_TIFF_LZW = TIFF_LZW ' save using LZW compression - FISO_TIFF_JPEG = TIFF_JPEG ' save using JPEG compression - FISO_TIFF_LOGLUV = TIFF_LOGLUV ' save using LogLuv compression -End Enum -#If False Then - Const FISO_SAVE_DEFAULT = 0 - Const FISO_BMP_DEFAULT = BMP_DEFAULT - Const FISO_BMP_SAVE_RLE = BMP_SAVE_RLE - Const FISO_JPEG_DEFAULT = JPEG_DEFAULT - Const FISO_JPEG_QUALITYSUPERB = JPEG_QUALITYSUPERB - Const FISO_JPEG_QUALITYGOOD = JPEG_QUALITYGOOD - Const FISO_JPEG_QUALITYNORMAL = JPEG_QUALITYNORMAL - Const FISO_JPEG_QUALITYAVERAGE = JPEG_QUALITYAVERAGE - Const FISO_JPEG_QUALITYBAD = JPEG_QUALITYBAD - Const FISO_JPEG_PROGRESSIVE = JPEG_PROGRESSIVE - Const FISO_JPEG_SUBSAMPLING_411 = JPEG_SUBSAMPLING_411 - Const FISO_JPEG_SUBSAMPLING_420 = JPEG_SUBSAMPLING_420 - Const FISO_JPEG_SUBSAMPLING_422 = JPEG_SUBSAMPLING_422 - Const FISO_JPEG_SUBSAMPLING_444 = JPEG_SUBSAMPLING_444 - Const FISO_PNM_DEFAULT = PNM_DEFAULT - Const FISO_PNM_SAVE_RAW = PNM_SAVE_RAW - Const FISO_PNM_SAVE_ASCII = PNM_SAVE_ASCII - Const FISO_TARGA_SAVE_RLE = TARGA_SAVE_RLE - Const FISO_TIFF_DEFAULT = TIFF_DEFAULT - Const FISO_TIFF_CMYK = TIFF_CMYK - Const FISO_TIFF_PACKBITS = TIFF_PACKBITS - Const FISO_TIFF_DEFLATE = TIFF_DEFLATE - Const FISO_TIFF_ADOBE_DEFLATE = TIFF_ADOBE_DEFLATE - Const FISO_TIFF_NONE = TIFF_NONE - Const FISO_TIFF_CCITTFAX3 = TIFF_CCITTFAX3 - Const FISO_TIFF_CCITTFAX4 = TIFF_CCITTFAX4 - Const FISO_TIFF_LZW = TIFF_LZW - Const FISO_TIFF_JPEG = TIFF_JPEG -#End If - -Public Enum FREE_IMAGE_TYPE - FIT_UNKNOWN = 0 ' unknown type - FIT_BITMAP = 1 ' standard image : 1-, 4-, 8-, 16-, 24-, 32-bit - FIT_UINT16 = 2 ' array of unsigned short : unsigned 16-bit - FIT_INT16 = 3 ' array of short : signed 16-bit - FIT_UINT32 = 4 ' array of unsigned long : unsigned 32-bit - FIT_INT32 = 5 ' array of long : signed 32-bit - FIT_FLOAT = 6 ' array of float : 32-bit IEEE floating point - FIT_DOUBLE = 7 ' array of double : 64-bit IEEE floating point - FIT_COMPLEX = 8 ' array of FICOMPLEX : 2 x 64-bit IEEE floating point - FIT_RGB16 = 9 ' 48-bit RGB image : 3 x 16-bit - FIT_RGBA16 = 10 ' 64-bit RGBA image : 4 x 16-bit - FIT_RGBF = 11 ' 96-bit RGB float image : 3 x 32-bit IEEE floating point - FIT_RGBAF = 12 ' 128-bit RGBA float image : 4 x 32-bit IEEE floating point -End Enum -#If False Then - Const FIT_UNKNOWN = 0 - Const FIT_BITMAP = 1 - Const FIT_UINT16 = 2 - Const FIT_INT16 = 3 - Const FIT_UINT32 = 4 - Const FIT_INT32 = 5 - Const FIT_FLOAT = 6 - Const FIT_DOUBLE = 7 - Const FIT_COMPLEX = 8 - Const FIT_RGB16 = 9 - Const FIT_RGBA16 = 10 - Const FIT_RGBF = 11 - Const FIT_RGBAF = 12 -#End If - -Public Enum FREE_IMAGE_COLOR_TYPE - FIC_MINISWHITE = 0 ' min value is white - FIC_MINISBLACK = 1 ' min value is black - FIC_RGB = 2 ' RGB color model - FIC_PALETTE = 3 ' color map indexed - FIC_RGBALPHA = 4 ' RGB color model with alpha channel - FIC_CMYK = 5 ' CMYK color model -End Enum -#If False Then - Const FIC_MINISWHITE = 0 - Const FIC_MINISBLACK = 1 - Const FIC_RGB = 2 - Const FIC_PALETTE = 3 - Const FIC_RGBALPHA = 4 - Const FIC_CMYK = 5 -#End If - -Public Enum FREE_IMAGE_QUANTIZE - FIQ_WUQUANT = 0 ' Xiaolin Wu color quantization algorithm - FIQ_NNQUANT = 1 ' NeuQuant neural-net quantization algorithm by Anthony Dekker -End Enum -#If False Then - Const FIQ_WUQUANT = 0 - Const FIQ_NNQUANT = 1 -#End If - -Public Enum FREE_IMAGE_DITHER - FID_FS = 0 ' Floyd & Steinberg error diffusion - FID_BAYER4x4 = 1 ' Bayer ordered dispersed dot dithering (order 2 dithering matrix) - FID_BAYER8x8 = 2 ' Bayer ordered dispersed dot dithering (order 3 dithering matrix) - FID_CLUSTER6x6 = 3 ' Ordered clustered dot dithering (order 3 - 6x6 matrix) - FID_CLUSTER8x8 = 4 ' Ordered clustered dot dithering (order 4 - 8x8 matrix) - FID_CLUSTER16x16 = 5 ' Ordered clustered dot dithering (order 8 - 16x16 matrix) - FID_BAYER16x16 = 6 ' Bayer ordered dispersed dot dithering (order 4 dithering matrix) -End Enum -#If False Then - Const FID_FS = 0 - Const FID_BAYER4x4 = 1 - Const FID_BAYER8x8 = 2 - Const FID_CLUSTER6x6 = 3 - Const FID_CLUSTER8x8 = 4 - Const FID_CLUSTER16x16 = 5 - Const FID_BAYER16x16 = 6 -#End If - -Public Enum FREE_IMAGE_JPEG_OPERATION - FIJPEG_OP_NONE = 0 ' no transformation - FIJPEG_OP_FLIP_H = 1 ' horizontal flip - FIJPEG_OP_FLIP_V = 2 ' vertical flip - FIJPEG_OP_TRANSPOSE = 3 ' transpose across UL-to-LR axis - FIJPEG_OP_TRANSVERSE = 4 ' transpose across UR-to-LL axis - FIJPEG_OP_ROTATE_90 = 5 ' 90-degree clockwise rotation - FIJPEG_OP_ROTATE_180 = 6 ' 180-degree rotation - FIJPEG_OP_ROTATE_270 = 7 ' 270-degree clockwise (or 90 ccw) -End Enum -#If False Then - Const FIJPEG_OP_NONE = 0 - Const FIJPEG_OP_FLIP_H = 1 - Const FIJPEG_OP_FLIP_V = 2 - Const FIJPEG_OP_TRANSPOSE = 3 - Const FIJPEG_OP_TRANSVERSE = 4 - Const FIJPEG_OP_ROTATE_90 = 5 - Const FIJPEG_OP_ROTATE_180 = 6 - Const FIJPEG_OP_ROTATE_270 = 7 -#End If - -Public Enum FREE_IMAGE_TMO - FITMO_DRAGO03 = 0 ' Adaptive logarithmic mapping (F. Drago, 2003) - FITMO_REINHARD05 = 1 ' Dynamic range reduction inspired by photoreceptor physiology (E. Reinhard, 2005) - FITMO_FATTAL02 = 2 ' Gradient domain high dynamic range compression (R. Fattal, 2002) -End Enum -#If False Then - Const FITMO_DRAGO03 = 0 - Const FITMO_REINHARD05 = 1 - Const FITMO_FATTAL02 = 2 -#End If - -Public Enum FREE_IMAGE_FILTER - FILTER_BOX = 0 ' Box, pulse, Fourier window, 1st order (constant) b-spline - FILTER_BICUBIC = 1 ' Mitchell & Netravali's two-param cubic filter - FILTER_BILINEAR = 2 ' Bilinear filter - FILTER_BSPLINE = 3 ' 4th order (cubic) b-spline - FILTER_CATMULLROM = 4 ' Catmull-Rom spline, Overhauser spline - FILTER_LANCZOS3 = 5 ' Lanczos3 filter -End Enum -#If False Then - Const FILTER_BOX = 0 - Const FILTER_BICUBIC = 1 - Const FILTER_BILINEAR = 2 - Const FILTER_BSPLINE = 3 - Const FILTER_CATMULLROM = 4 - Const FILTER_LANCZOS3 = 5 -#End If - -Public Enum FREE_IMAGE_COLOR_CHANNEL - FICC_RGB = 0 ' Use red, green and blue channels - FICC_RED = 1 ' Use red channel - FICC_GREEN = 2 ' Use green channel - FICC_BLUE = 3 ' Use blue channel - FICC_ALPHA = 4 ' Use alpha channel - FICC_BLACK = 5 ' Use black channel - FICC_REAL = 6 ' Complex images: use real part - FICC_IMAG = 7 ' Complex images: use imaginary part - FICC_MAG = 8 ' Complex images: use magnitude - FICC_PHASE = 9 ' Complex images: use phase -End Enum -#If False Then - Const FICC_RGB = 0 - Const FICC_RED = 1 - Const FICC_GREEN = 2 - Const FICC_BLUE = 3 - Const FICC_ALPHA = 4 - Const FICC_BLACK = 5 - Const FICC_REAL = 6 - Const FICC_IMAG = 7 - Const FICC_MAG = 8 - Const FICC_PHASE = 9 -#End If - -Public Enum FREE_IMAGE_MDTYPE - FIDT_NOTYPE = 0 ' placeholder - FIDT_BYTE = 1 ' 8-bit unsigned integer - FIDT_ASCII = 2 ' 8-bit bytes w/ last byte null - FIDT_SHORT = 3 ' 16-bit unsigned integer - FIDT_LONG = 4 ' 32-bit unsigned integer - FIDT_RATIONAL = 5 ' 64-bit unsigned fraction - FIDT_SBYTE = 6 ' 8-bit signed integer - FIDT_UNDEFINED = 7 ' 8-bit untyped data - FIDT_SSHORT = 8 ' 16-bit signed integer - FIDT_SLONG = 9 ' 32-bit signed integer - FIDT_SRATIONAL = 10 ' 64-bit signed fraction - FIDT_FLOAT = 11 ' 32-bit IEEE floating point - FIDT_DOUBLE = 12 ' 64-bit IEEE floating point - FIDT_IFD = 13 ' 32-bit unsigned integer (offset) - FIDT_PALETTE = 14 ' 32-bit RGBQUAD -End Enum -#If False Then - Const FIDT_NOTYPE = 0 - Const FIDT_BYTE = 1 - Const FIDT_ASCII = 2 - Const FIDT_SHORT = 3 - Const FIDT_LONG = 4 - Const FIDT_RATIONAL = 5 - Const FIDT_SBYTE = 6 - Const FIDT_UNDEFINED = 7 - Const FIDT_SSHORT = 8 - Const FIDT_SLONG = 9 - Const FIDT_SRATIONAL = 10 - Const FIDT_FLOAT = 11 - Const FIDT_DOUBLE = 12 - Const FIDT_IFD = 13 - Const FIDT_PALETTE = 14 -#End If - -Public Enum FREE_IMAGE_MDMODEL - FIMD_NODATA = -1 ' - FIMD_COMMENTS = 0 ' single comment or keywords - FIMD_EXIF_MAIN = 1 ' Exif-TIFF metadata - FIMD_EXIF_EXIF = 2 ' Exif-specific metadata - FIMD_EXIF_GPS = 3 ' Exif GPS metadata - FIMD_EXIF_MAKERNOTE = 4 ' Exif maker note metadata - FIMD_EXIF_INTEROP = 5 ' Exif interoperability metadata - FIMD_IPTC = 6 ' IPTC/NAA metadata - FIMD_XMP = 7 ' Abobe XMP metadata - FIMD_GEOTIFF = 8 ' GeoTIFF metadata - FIMD_ANIMATION = 9 ' Animation metadata - FIMD_CUSTOM = 10 ' Used to attach other metadata types to a dib - FIMD_EXIF_RAW = 11 ' Exif metadata as a raw buffer -End Enum -#If False Then - Const FIMD_NODATA = -1 - Const FIMD_COMMENTS = 0 - Const FIMD_EXIF_MAIN = 1 - Const FIMD_EXIF_EXIF = 2 - Const FIMD_EXIF_GPS = 3 - Const FIMD_EXIF_MAKERNOTE = 4 - Const FIMD_EXIF_INTEROP = 5 - Const FIMD_IPTC = 6 - Const FIMD_XMP = 7 - Const FIMD_GEOTIFF = 8 - Const FIMD_ANIMATION = 9 - Const FIMD_CUSTOM = 10 - Const FIMD_EXIF_RAW = 11 -#End If - -' These are the GIF_DISPOSAL metadata constants -Public Enum FREE_IMAGE_FRAME_DISPOSAL_METHODS - FIFD_GIF_DISPOSAL_UNSPECIFIED = 0 - FIFD_GIF_DISPOSAL_LEAVE = 1 - FIFD_GIF_DISPOSAL_BACKGROUND = 2 - FIFD_GIF_DISPOSAL_PREVIOUS = 3 -End Enum - -' Constants used in FreeImage_FillBackground and FreeImage_EnlargeCanvas -Public Enum FREE_IMAGE_COLOR_OPTIONS - FI_COLOR_IS_RGB_COLOR = &H0 ' RGBQUAD color is a RGB color (contains no valid alpha channel) - FI_COLOR_IS_RGBA_COLOR = &H1 ' RGBQUAD color is a RGBA color (contains a valid alpha channel) - FI_COLOR_FIND_EQUAL_COLOR = &H2 ' For palettized images: lookup equal RGB color from palette - FI_COLOR_ALPHA_IS_INDEX = &H4 ' The color's rgbReserved member (alpha) contains the palette index to be used -End Enum -Public Const FI_COLOR_PALETTE_SEARCH_MASK = _ - (FI_COLOR_FIND_EQUAL_COLOR Or FI_COLOR_ALPHA_IS_INDEX) ' Flag to test, if any color lookup is performed - -' the next enums are only used by derived functions of the -' FreeImage 3 VB wrapper -Public Enum FREE_IMAGE_CONVERSION_FLAGS - FICF_MONOCHROME = &H1 - FICF_MONOCHROME_THRESHOLD = FICF_MONOCHROME - FICF_MONOCHROME_DITHER = &H3 - FICF_GREYSCALE_4BPP = &H4 - FICF_PALLETISED_8BPP = &H8 - FICF_GREYSCALE_8BPP = FICF_PALLETISED_8BPP Or FICF_MONOCHROME - FICF_GREYSCALE = FICF_GREYSCALE_8BPP - FICF_RGB_15BPP = &HF - FICF_RGB_16BPP = &H10 - FICF_RGB_24BPP = &H18 - FICF_RGB_32BPP = &H20 - FICF_RGB_ALPHA = FICF_RGB_32BPP - FICF_KEEP_UNORDERED_GREYSCALE_PALETTE = &H0 - FICF_REORDER_GREYSCALE_PALETTE = &H1000 -End Enum -#If False Then - Const FICF_MONOCHROME = &H1 - Const FICF_MONOCHROME_THRESHOLD = FICF_MONOCHROME - Const FICF_MONOCHROME_DITHER = &H3 - Const FICF_GREYSCALE_4BPP = &H4 - Const FICF_PALLETISED_8BPP = &H8 - Const FICF_GREYSCALE_8BPP = FICF_PALLETISED_8BPP Or FICF_MONOCHROME - Const FICF_GREYSCALE = FICF_GREYSCALE_8BPP - Const FICF_RGB_15BPP = &HF - Const FICF_RGB_16BPP = &H10 - Const FICF_RGB_24BPP = &H18 - Const FICF_RGB_32BPP = &H20 - Const FICF_RGB_ALPHA = FICF_RGB_32BPP - Const FICF_KEEP_UNORDERED_GREYSCALE_PALETTE = &H0 - Const FICF_REORDER_GREYSCALE_PALETTE = &H1000 -#End If - -Public Enum FREE_IMAGE_COLOR_DEPTH - FICD_AUTO = &H0 - FICD_MONOCHROME = &H1 - FICD_MONOCHROME_THRESHOLD = FICF_MONOCHROME - FICD_MONOCHROME_DITHER = &H3 - FICD_1BPP = FICD_MONOCHROME - FICD_4BPP = &H4 - FICD_8BPP = &H8 - FICD_15BPP = &HF - FICD_16BPP = &H10 - FICD_24BPP = &H18 - FICD_32BPP = &H20 -End Enum -#If False Then - Const FICD_AUTO = &H0 - Const FICD_MONOCHROME = &H1 - Const FICD_MONOCHROME_THRESHOLD = FICF_MONOCHROME - Const FICD_MONOCHROME_DITHER = &H3 - Const FICD_1BPP = FICD_MONOCHROME - Const FICD_4BPP = &H4 - Const FICD_8BPP = &H8 - Const FICD_15BPP = &HF - Const FICD_16BPP = &H10 - Const FICD_24BPP = &H18 - Const FICD_32BPP = &H20 -#End If - -Public Enum FREE_IMAGE_ADJUST_MODE - AM_STRECH = &H1 - AM_DEFAULT = AM_STRECH - AM_ADJUST_BOTH = AM_STRECH - AM_ADJUST_WIDTH = &H2 - AM_ADJUST_HEIGHT = &H4 - AM_ADJUST_OPTIMAL_SIZE = &H8 -End Enum -#If False Then - Const AM_STRECH = &H1 - Const AM_DEFAULT = AM_STRECH - Const AM_ADJUST_BOTH = AM_STRECH - Const AM_ADJUST_WIDTH = &H2 - Const AM_ADJUST_HEIGHT = &H4 - Const AM_ADJUST_OPTIMAL_SIZE = &H8 -#End If - -Public Enum FREE_IMAGE_MASK_FLAGS - FIMF_MASK_NONE = &H0 - FIMF_MASK_FULL_TRANSPARENCY = &H1 - FIMF_MASK_ALPHA_TRANSPARENCY = &H2 - FIMF_MASK_COLOR_TRANSPARENCY = &H4 - FIMF_MASK_FORCE_TRANSPARENCY = &H8 - FIMF_MASK_INVERSE_MASK = &H10 -End Enum -#If False Then - Const FIMF_MASK_NONE = &H0 - Const FIMF_MASK_FULL_TRANSPARENCY = &H1 - Const FIMF_MASK_ALPHA_TRANSPARENCY = &H2 - Const FIMF_MASK_COLOR_TRANSPARENCY = &H4 - Const FIMF_MASK_FORCE_TRANSPARENCY = &H8 - Const FIMF_MASK_INVERSE_MASK = &H10 -#End If - -Public Enum FREE_IMAGE_COLOR_FORMAT_FLAGS - FICFF_COLOR_RGB = &H1 - FICFF_COLOR_BGR = &H2 - FICFF_COLOR_PALETTE_INDEX = &H4 - - FICFF_COLOR_HAS_ALPHA = &H100 - - FICFF_COLOR_ARGB = FICFF_COLOR_RGB Or FICFF_COLOR_HAS_ALPHA - FICFF_COLOR_ABGR = FICFF_COLOR_BGR Or FICFF_COLOR_HAS_ALPHA - - FICFF_COLOR_FORMAT_ORDER_MASK = FICFF_COLOR_RGB Or FICFF_COLOR_BGR -End Enum -#If False Then - Const FICFF_COLOR_RGB = &H1 - Const FICFF_COLOR_BGR = &H2 - Const FICFF_COLOR_PALETTE_INDEX = &H4 - - Const FICFF_COLOR_HAS_ALPHA = &H100 - - Const FICFF_COLOR_ARGB = FICFF_COLOR_RGB Or FICFF_COLOR_HAS_ALPHA - Const FICFF_COLOR_ABGR = FICFF_COLOR_BGR Or FICFF_COLOR_HAS_ALPHA - - Const FICFF_COLOR_FORMAT_ORDER_MASK = FICFF_COLOR_RGB Or FICFF_COLOR_BGR -#End If - -Public Enum FREE_IMAGE_MASK_CREATION_OPTION_FLAGS - MCOF_CREATE_MASK_IMAGE = &H1 - MCOF_MODIFY_SOURCE_IMAGE = &H2 - MCOF_CREATE_AND_MODIFY = MCOF_CREATE_MASK_IMAGE Or MCOF_MODIFY_SOURCE_IMAGE -End Enum -#If False Then - Const MCOF_CREATE_MASK_IMAGE = &H1 - Const MCOF_MODIFY_SOURCE_IMAGE = &H2 - Const MCOF_CREATE_AND_MODIFY = MCOF_CREATE_MASK_IMAGE Or MCOF_MODIFY_SOURCE_IMAGE -#End If - -Public Enum FREE_IMAGE_TRANSPARENCY_STATE_FLAGS - FITSF_IGNORE_TRANSPARENCY = &H0 - FITSF_NONTRANSPARENT = &H1 - FITSF_TRANSPARENT = &H2 - FITSF_INCLUDE_ALPHA_TRANSPARENCY = &H4 -End Enum -#If False Then - Const FITSF_IGNORE_TRANSPARENCY = &H0 - Const FITSF_NONTRANSPARENT = &H1 - Const FITSF_TRANSPARENT = &H2 - Const FITSF_INCLUDE_ALPHA_TRANSPARENCY = &H4 -#End If - -Public Enum FREE_IMAGE_ICON_TRANSPARENCY_OPTION_FLAGS - ITOF_NO_TRANSPARENCY = &H0 - ITOF_USE_TRANSPARENCY_INFO = &H1 - ITOF_USE_TRANSPARENCY_INFO_ONLY = ITOF_USE_TRANSPARENCY_INFO - ITOF_USE_COLOR_TRANSPARENCY = &H2 - ITOF_USE_COLOR_TRANSPARENCY_ONLY = ITOF_USE_COLOR_TRANSPARENCY - ITOF_USE_TRANSPARENCY_INFO_OR_COLOR = ITOF_USE_TRANSPARENCY_INFO Or ITOF_USE_COLOR_TRANSPARENCY - ITOF_USE_DEFAULT_TRANSPARENCY = ITOF_USE_TRANSPARENCY_INFO_OR_COLOR - ITOF_USE_COLOR_TOP_LEFT_PIXEL = &H0 - ITOF_USE_COLOR_FIRST_PIXEL = ITOF_USE_COLOR_TOP_LEFT_PIXEL - ITOF_USE_COLOR_TOP_RIGHT_PIXEL = &H20 - ITOF_USE_COLOR_BOTTOM_LEFT_PIXEL = &H40 - ITOF_USE_COLOR_BOTTOM_RIGHT_PIXEL = &H80 - ITOF_USE_COLOR_SPECIFIED = &H100 - ITOF_FORCE_TRANSPARENCY_INFO = &H400 -End Enum -#If False Then - Const ITOF_NO_TRANSPARENCY = &H0 - Const ITOF_USE_TRANSPARENCY_INFO = &H1 - Const ITOF_USE_TRANSPARENCY_INFO_ONLY = ITOF_USE_TRANSPARENCY_INFO - Const ITOF_USE_COLOR_TRANSPARENCY = &H2 - Const ITOF_USE_COLOR_TRANSPARENCY_ONLY = ITOF_USE_COLOR_TRANSPARENCY - Const ITOF_USE_TRANSPARENCY_INFO_OR_COLOR = ITOF_USE_TRANSPARENCY_INFO Or ITOF_USE_COLOR_TRANSPARENCY - Const ITOF_USE_DEFAULT_TRANSPARENCY = ITOF_USE_TRANSPARENCY_INFO_OR_COLOR - Const ITOF_USE_COLOR_TOP_LEFT_PIXEL = &H0 - Const ITOF_USE_COLOR_FIRST_PIXEL = ITOF_USE_COLOR_TOP_LEFT_PIXEL - Const ITOF_USE_COLOR_TOP_RIGHT_PIXEL = &H20 - Const ITOF_USE_COLOR_BOTTOM_LEFT_PIXEL = &H40 - Const ITOF_USE_COLOR_BOTTOM_RIGHT_PIXEL = &H80 - Const ITOF_USE_COLOR_SPECIFIED = &H100 - Const ITOF_FORCE_TRANSPARENCY_INFO = &H400 -#End If - -Private Const ITOF_USE_COLOR_BITMASK As Long = ITOF_USE_COLOR_TOP_RIGHT_PIXEL Or _ - ITOF_USE_COLOR_BOTTOM_LEFT_PIXEL Or _ - ITOF_USE_COLOR_BOTTOM_RIGHT_PIXEL Or _ - ITOF_USE_COLOR_SPECIFIED - - -Public Type RGBQUAD - rgbBlue As Byte - rgbGreen As Byte - rgbRed As Byte - rgbReserved As Byte -End Type - -Public Type RGBTRIPLE - rgbtBlue As Byte - rgbtGreen As Byte - rgbtRed As Byte -End Type - -Public Type BITMAPINFOHEADER - biSize As Long - biWidth As Long - biHeight As Long - biPlanes As Integer - biBitCount As Integer - biCompression As Long - biSizeImage As Long - biXPelsPerMeter As Long - biYPelsPerMeter As Long - biClrUsed As Long - biClrImportant As Long - red As Long - green As Long - blue As Long -End Type - -Public Type BITMAPINFO - bmiHeader As BITMAPINFOHEADER - bmiColors(0) As RGBQUAD -End Type - -Public Const BI_RGB As Long = 0 -Public Const BI_RLE8 As Long = 1 -Public Const BI_RLE4 As Long = 2 -Public Const BI_BITFIELDS As Long = 3 -Public Const BI_JPEG As Long = 4 -Public Const BI_PNG As Long = 5 - -Public Type FIICCPROFILE - Flags As Integer - Size As Long - Data As Long -End Type - -Public Type FIRGB16 - red As Integer - green As Integer - blue As Integer -End Type - -Public Type FIRGBA16 - red As Integer - green As Integer - blue As Integer - Alpha As Integer -End Type - -Public Type FIRGBF - red As Single - green As Single - blue As Single -End Type - -Public Type FIRGBAF - red As Single - green As Single - blue As Single - Alpha As Single -End Type - -Public Type FICOMPLEX - r As Double ' real part - i As Double ' imaginary part -End Type - -Public Type FITAG - Key As Long - Description As Long - Id As Integer - Type As Integer - Count As Long - Length As Long - Value As Long -End Type - -Public Type FIRATIONAL - Numerator As Variant - Denominator As Variant -End Type - -Public Type FREE_IMAGE_TAG - Model As FREE_IMAGE_MDMODEL - TagPtr As Long - Key As String - Description As String - Id As Long - Type As FREE_IMAGE_MDTYPE - Count As Long - Length As Long - StringValue As String - Palette() As RGBQUAD - RationalValue() As FIRATIONAL - Value As Variant -End Type - -Public Type FreeImageIO - read_proc As Long - write_proc As Long - seek_proc As Long - tell_proc As Long -End Type - -Public Type Plugin - format_proc As Long - description_proc As Long - extension_proc As Long - regexpr_proc As Long - open_proc As Long - close_proc As Long - pagecount_proc As Long - pagecapability_proc As Long - load_proc As Long - save_proc As Long - validate_proc As Long - mime_proc As Long - supports_export_bpp_proc As Long - supports_export_type_proc As Long - supports_icc_profiles_proc As Long -End Type - -' the next structures are only used by derived functions of the -' FreeImage 3 VB wrapper -Public Type ScanLineRGBTRIBLE - Data() As RGBTRIPLE -End Type - -Public Type ScanLinesRGBTRIBLE - Scanline() As ScanLineRGBTRIBLE -End Type - -'-------------------------------------------------------------------------------- -' FreeImage 3 function declarations -'-------------------------------------------------------------------------------- - -' The FreeImage 3 functions are declared in the same order as they are described -' in the FreeImage 3 API documentation. The documentation's outline is included -' as comments. - -'-------------------------------------------------------------------------------- -' Bitmap functions -'-------------------------------------------------------------------------------- - -' General functions -Public Declare Sub FreeImage_Initialise Lib "FreeImage.dll" Alias "_FreeImage_Initialise@4" ( _ - Optional ByVal LoadLocalPluginsOnly As Long) - -Public Declare Sub FreeImage_DeInitialise Lib "FreeImage.dll" Alias "_FreeImage_DeInitialise@0" () - -Private Declare Function FreeImage_GetVersionInt Lib "FreeImage.dll" Alias "_FreeImage_GetVersion@0" () As Long - -Private Declare Function FreeImage_GetCopyrightMessageInt Lib "FreeImage.dll" Alias "_FreeImage_GetCopyrightMessage@0" () As Long - -Public Declare Sub FreeImage_SetOutputMessage Lib "FreeImage.dll" Alias "_FreeImage_SetOutputMessageStdCall@4" ( _ - ByVal omf As Long) - - -' Bitmap management functions -Public Declare Function FreeImage_Allocate Lib "FreeImage.dll" Alias "_FreeImage_Allocate@24" ( _ - ByVal Width As Long, _ - ByVal Height As Long, _ - ByVal BitsPerPixel As Long, _ - Optional ByVal RedMask As Long, _ - Optional ByVal GreenMask As Long, _ - Optional ByVal BlueMask As Long) As Long - -Public Declare Function FreeImage_AllocateT Lib "FreeImage.dll" Alias "_FreeImage_AllocateT@28" ( _ - ByVal ImageType As FREE_IMAGE_TYPE, _ - ByVal Width As Long, _ - ByVal Height As Long, _ - Optional ByVal BitsPerPixel As Long = 8, _ - Optional ByVal RedMask As Long, _ - Optional ByVal GreenMask As Long, _ - Optional ByVal BlueMask As Long) As Long - -Public Declare Function FreeImage_HasPixelsInt Lib "FreeImage.dll" Alias "_FreeImage_HasPixels@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_Load Lib "FreeImage.dll" Alias "_FreeImage_Load@12" ( _ - ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Filename As String, _ - Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long - -Private Declare Function FreeImage_LoadUInt Lib "FreeImage.dll" Alias "_FreeImage_LoadU@12" ( _ - ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Filename As Long, _ - Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long - -Public Declare Function FreeImage_LoadFromHandle Lib "FreeImage.dll" Alias "_FreeImage_LoadFromHandle@16" ( _ - ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal IO As Long, _ - ByVal Handle As Long, _ - Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long - -Private Declare Function FreeImage_SaveInt Lib "FreeImage.dll" Alias "_FreeImage_Save@16" ( _ - ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Bitmap As Long, _ - ByVal Filename As String, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Long - -Private Declare Function FreeImage_SaveUInt Lib "FreeImage.dll" Alias "_FreeImage_SaveU@16" ( _ - ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Bitmap As Long, _ - ByVal Filename As Long, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Long - -Private Declare Function FreeImage_SaveToHandleInt Lib "FreeImage.dll" Alias "_FreeImage_SaveToHandle@20" ( _ - ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Bitmap As Long, _ - ByVal IO As Long, _ - ByVal Handle As Long, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Long - -Public Declare Function FreeImage_Clone Lib "FreeImage.dll" Alias "_FreeImage_Clone@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Sub FreeImage_Unload Lib "FreeImage.dll" Alias "_FreeImage_Unload@4" ( _ - ByVal Bitmap As Long) - - -' Bitmap information functions -Public Declare Function FreeImage_GetImageType Lib "FreeImage.dll" Alias "_FreeImage_GetImageType@4" ( _ - ByVal Bitmap As Long) As FREE_IMAGE_TYPE - -Public Declare Function FreeImage_GetColorsUsed Lib "FreeImage.dll" Alias "_FreeImage_GetColorsUsed@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetBPP Lib "FreeImage.dll" Alias "_FreeImage_GetBPP@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetWidth Lib "FreeImage.dll" Alias "_FreeImage_GetWidth@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetHeight Lib "FreeImage.dll" Alias "_FreeImage_GetHeight@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetLine Lib "FreeImage.dll" Alias "_FreeImage_GetLine@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetPitch Lib "FreeImage.dll" Alias "_FreeImage_GetPitch@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetDIBSize Lib "FreeImage.dll" Alias "_FreeImage_GetDIBSize@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetPalette Lib "FreeImage.dll" Alias "_FreeImage_GetPalette@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetDotsPerMeterX Lib "FreeImage.dll" Alias "_FreeImage_GetDotsPerMeterX@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetDotsPerMeterY Lib "FreeImage.dll" Alias "_FreeImage_GetDotsPerMeterY@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Sub FreeImage_SetDotsPerMeterX Lib "FreeImage.dll" Alias "_FreeImage_SetDotsPerMeterX@8" ( _ - ByVal Bitmap As Long, _ - ByVal Resolution As Long) - -Public Declare Sub FreeImage_SetDotsPerMeterY Lib "FreeImage.dll" Alias "_FreeImage_SetDotsPerMeterY@8" ( _ - ByVal Bitmap As Long, _ - ByVal Resolution As Long) - -Public Declare Function FreeImage_GetInfoHeader Lib "FreeImage.dll" Alias "_FreeImage_GetInfoHeader@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetInfo Lib "FreeImage.dll" Alias "_FreeImage_GetInfo@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetColorType Lib "FreeImage.dll" Alias "_FreeImage_GetColorType@4" ( _ - ByVal Bitmap As Long) As FREE_IMAGE_COLOR_TYPE - -Public Declare Function FreeImage_GetRedMask Lib "FreeImage.dll" Alias "_FreeImage_GetRedMask@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetGreenMask Lib "FreeImage.dll" Alias "_FreeImage_GetGreenMask@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetBlueMask Lib "FreeImage.dll" Alias "_FreeImage_GetBlueMask@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetTransparencyCount Lib "FreeImage.dll" Alias "_FreeImage_GetTransparencyCount@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetTransparencyTable Lib "FreeImage.dll" Alias "_FreeImage_GetTransparencyTable@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Sub FreeImage_SetTransparencyTable Lib "FreeImage.dll" Alias "_FreeImage_SetTransparencyTable@12" ( _ - ByVal Bitmap As Long, _ - ByVal TransTablePtr As Long, _ - ByVal Count As Long) - -Private Declare Sub FreeImage_SetTransparentInt Lib "FreeImage.dll" Alias "_FreeImage_SetTransparent@8" ( _ - ByVal Bitmap As Long, _ - ByVal Value As Long) - -Private Declare Function FreeImage_IsTransparentInt Lib "FreeImage.dll" Alias "_FreeImage_IsTransparent@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetTransparentIndex Lib "FreeImage.dll" Alias "_FreeImage_GetTransparentIndex@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_SetTransparentIndex Lib "FreeImage.dll" Alias "_FreeImage_SetTransparentIndex@8" ( _ - ByVal Bitmap As Long, _ - ByVal Index As Long) As Long - -Private Declare Function FreeImage_HasBackgroundColorInt Lib "FreeImage.dll" Alias "_FreeImage_HasBackgroundColor@4" ( _ - ByVal Bitmap As Long) As Long - -Private Declare Function FreeImage_GetBackgroundColorInt Lib "FreeImage.dll" Alias "_FreeImage_GetBackgroundColor@8" ( _ - ByVal Bitmap As Long, _ - ByRef BackColor As RGBQUAD) As Long - -Private Declare Function FreeImage_GetBackgroundColorAsLongInt Lib "FreeImage.dll" Alias "_FreeImage_GetBackgroundColor@8" ( _ - ByVal Bitmap As Long, _ - ByRef BackColor As Long) As Long - -Private Declare Function FreeImage_SetBackgroundColorInt Lib "FreeImage.dll" Alias "_FreeImage_SetBackgroundColor@8" ( _ - ByVal Bitmap As Long, _ - ByRef BackColor As RGBQUAD) As Long - -Private Declare Function FreeImage_SetBackgroundColorAsLongInt Lib "FreeImage.dll" Alias "_FreeImage_SetBackgroundColor@8" ( _ - ByVal Bitmap As Long, _ - ByRef BackColor As Long) As Long - -Public Declare Function FreeImage_GetThumbnail Lib "FreeImage.dll" Alias "_FreeImage_GetThumbnail@4" ( _ - ByVal Bitmap As Long) As Long - -Private Declare Function FreeImage_SetThumbnailInt Lib "FreeImage.dll" Alias "_FreeImage_SetThumbnail@8" ( _ - ByVal Bitmap As Long, ByVal Thumbnail As Long) As Long - - -' Filetype functions -Public Declare Function FreeImage_GetFileType Lib "FreeImage.dll" Alias "_FreeImage_GetFileType@8" ( _ - ByVal Filename As String, _ - Optional ByVal Size As Long) As FREE_IMAGE_FORMAT - -Private Declare Function FreeImage_GetFileTypeUInt Lib "FreeImage.dll" Alias "_FreeImage_GetFileTypeU@8" ( _ - ByVal Filename As Long, _ - Optional ByVal Size As Long) As FREE_IMAGE_FORMAT - -Public Declare Function FreeImage_GetFileTypeFromHandle Lib "FreeImage.dll" Alias "_FreeImage_GetFileTypeFromHandle@12" ( _ - ByVal IO As Long, _ - ByVal Handle As Long, _ - Optional ByVal Size As Long) As FREE_IMAGE_FORMAT - -Public Declare Function FreeImage_GetFileTypeFromMemory Lib "FreeImage.dll" Alias "_FreeImage_GetFileTypeFromMemory@8" ( _ - ByVal Stream As Long, _ - Optional ByVal Size As Long) As FREE_IMAGE_FORMAT - - -' Pixel access functions -Public Declare Function FreeImage_GetBits Lib "FreeImage.dll" Alias "_FreeImage_GetBits@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_GetScanline Lib "FreeImage.dll" Alias "_FreeImage_GetScanLine@8" ( _ - ByVal Bitmap As Long, _ - ByVal Scanline As Long) As Long - -Private Declare Function FreeImage_GetPixelIndexInt Lib "FreeImage.dll" Alias "_FreeImage_GetPixelIndex@16" ( _ - ByVal Bitmap As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByRef Value As Byte) As Long - -Private Declare Function FreeImage_GetPixelColorInt Lib "FreeImage.dll" Alias "_FreeImage_GetPixelColor@16" ( _ - ByVal Bitmap As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByRef Value As RGBQUAD) As Long - -Private Declare Function FreeImage_GetPixelColorByLongInt Lib "FreeImage.dll" Alias "_FreeImage_GetPixelColor@16" ( _ - ByVal Bitmap As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByRef Value As Long) As Long - -Private Declare Function FreeImage_SetPixelIndexInt Lib "FreeImage.dll" Alias "_FreeImage_SetPixelIndex@16" ( _ - ByVal Bitmap As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByRef Value As Byte) As Long - -Private Declare Function FreeImage_SetPixelColorInt Lib "FreeImage.dll" Alias "_FreeImage_SetPixelColor@16" ( _ - ByVal Bitmap As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByRef Value As RGBQUAD) As Long - -Private Declare Function FreeImage_SetPixelColorByLongInt Lib "FreeImage.dll" Alias "_FreeImage_SetPixelColor@16" ( _ - ByVal Bitmap As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByRef Value As Long) As Long - - - -' Conversion functions -Public Declare Function FreeImage_ConvertTo4Bits Lib "FreeImage.dll" Alias "_FreeImage_ConvertTo4Bits@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_ConvertTo8Bits Lib "FreeImage.dll" Alias "_FreeImage_ConvertTo8Bits@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_ConvertToGreyscale Lib "FreeImage.dll" Alias "_FreeImage_ConvertToGreyscale@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_ConvertTo16Bits555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertTo16Bits555@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_ConvertTo16Bits565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertTo16Bits565@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_ConvertTo24Bits Lib "FreeImage.dll" Alias "_FreeImage_ConvertTo24Bits@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_ConvertTo32Bits Lib "FreeImage.dll" Alias "_FreeImage_ConvertTo32Bits@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_ColorQuantize Lib "FreeImage.dll" Alias "_FreeImage_ColorQuantize@8" ( _ - ByVal Bitmap As Long, _ - ByVal QuantizeMethod As FREE_IMAGE_QUANTIZE) As Long - -Private Declare Function FreeImage_ColorQuantizeExInt Lib "FreeImage.dll" Alias "_FreeImage_ColorQuantizeEx@20" ( _ - ByVal Bitmap As Long, _ - Optional ByVal QuantizeMethod As FREE_IMAGE_QUANTIZE = FIQ_WUQUANT, _ - Optional ByVal PaletteSize As Long = 256, _ - Optional ByVal ReserveSize As Long = 0, _ - Optional ByVal ReservePalettePtr As Long = 0) As Long - -Public Declare Function FreeImage_Threshold Lib "FreeImage.dll" Alias "_FreeImage_Threshold@8" ( _ - ByVal Bitmap As Long, _ - ByVal Threshold As Byte) As Long - -Public Declare Function FreeImage_Dither Lib "FreeImage.dll" Alias "_FreeImage_Dither@8" ( _ - ByVal Bitmap As Long, _ - ByVal DitherMethod As FREE_IMAGE_DITHER) As Long - -Private Declare Function FreeImage_ConvertFromRawBitsInt Lib "FreeImage.dll" Alias "_FreeImage_ConvertFromRawBits@36" ( _ - ByVal BitsPtr As Long, _ - ByVal Width As Long, _ - ByVal Height As Long, _ - ByVal Pitch As Long, _ - ByVal BitsPerPixel As Long, _ - ByVal RedMask As Long, _ - ByVal GreenMask As Long, _ - ByVal BlueMask As Long, _ - ByVal TopDown As Long) As Long - -Private Declare Sub FreeImage_ConvertToRawBitsInt Lib "FreeImage.dll" Alias "_FreeImage_ConvertToRawBits@32" ( _ - ByVal BitsPtr As Long, _ - ByVal Bitmap As Long, _ - ByVal Pitch As Long, _ - ByVal BitsPerPixel As Long, _ - ByVal RedMask As Long, _ - ByVal GreenMask As Long, _ - ByVal BlueMask As Long, _ - ByVal TopDown As Long) - -Private Declare Function FreeImage_ConvertToStandardTypeInt Lib "FreeImage.dll" Alias "_FreeImage_ConvertToStandardType@8" ( _ - ByVal Bitmap As Long, _ - ByVal ScaleLinear As Long) As Long - -Private Declare Function FreeImage_ConvertToTypeInt Lib "FreeImage.dll" Alias "_FreeImage_ConvertToType@12" ( _ - ByVal Bitmap As Long, _ - ByVal DestinationType As FREE_IMAGE_TYPE, _ - ByVal ScaleLinear As Long) As Long - -Public Declare Function FreeImage_ConvertToFloat Lib "FreeImage.dll" Alias "_FreeImage_ConvertToFloat@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_ConvertToRGBF Lib "FreeImage.dll" Alias "_FreeImage_ConvertToRGBF@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_ConvertToUINT16 Lib "FreeImage.dll" Alias "_FreeImage_ConvertToUINT16@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_ConvertToRGB16 Lib "FreeImage.dll" Alias "_FreeImage_ConvertToRGB16@4" ( _ - ByVal Bitmap As Long) As Long - -' Tone mapping operators -Public Declare Function FreeImage_ToneMapping Lib "FreeImage.dll" Alias "_FreeImage_ToneMapping@24" ( _ - ByVal Bitmap As Long, _ - ByVal Operator As FREE_IMAGE_TMO, _ - Optional ByVal FirstArgument As Double, _ - Optional ByVal SecondArgument As Double) As Long - -Public Declare Function FreeImage_TmoDrago03 Lib "FreeImage.dll" Alias "_FreeImage_TmoDrago03@20" ( _ - ByVal Bitmap As Long, _ - Optional ByVal Gamma As Double = 2.2, _ - Optional ByVal Exposure As Double) As Long - -Public Declare Function FreeImage_TmoReinhard05 Lib "FreeImage.dll" Alias "_FreeImage_TmoReinhard05@20" ( _ - ByVal Bitmap As Long, _ - Optional ByVal Intensity As Double, _ - Optional ByVal Contrast As Double) As Long - -Public Declare Function FreeImage_TmoReinhard05Ex Lib "FreeImage.dll" Alias "_FreeImage_TmoReinhard05Ex@36" ( _ - ByVal Bitmap As Long, _ - Optional ByVal Intensity As Double, _ - Optional ByVal Contrast As Double, _ - Optional ByVal Adaptation As Double = 1, _ - Optional ByVal ColorCorrection As Double) As Long - -Public Declare Function FreeImage_TmoFattal02 Lib "FreeImage.dll" Alias "_FreeImage_TmoFattal02@20" ( _ - ByVal Bitmap As Long, _ - Optional ByVal ColorSaturation As Double = 0.5, _ - Optional ByVal Attenuation As Double = 0.85) As Long - - -' ICC profile functions -Private Declare Function FreeImage_GetICCProfileInt Lib "FreeImage.dll" Alias "_FreeImage_GetICCProfile@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_CreateICCProfile Lib "FreeImage.dll" Alias "_FreeImage_CreateICCProfile@12" ( _ - ByVal Bitmap As Long, _ - ByRef Data As Long, _ - ByVal Size As Long) As Long - -Public Declare Sub FreeImage_DestroyICCProfile Lib "FreeImage.dll" Alias "_FreeImage_DestroyICCProfile@4" ( _ - ByVal Bitmap As Long) - - -' Plugin functions -Public Declare Function FreeImage_GetFIFCount Lib "FreeImage.dll" Alias "_FreeImage_GetFIFCount@0" () As Long - -Public Declare Function FreeImage_SetPluginEnabled Lib "FreeImage.dll" Alias "_FreeImage_SetPluginEnabled@8" ( _ - ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Value As Long) As Long - -Public Declare Function FreeImage_IsPluginEnabled Lib "FreeImage.dll" Alias "_FreeImage_IsPluginEnabled@4" ( _ - ByVal Format As FREE_IMAGE_FORMAT) As Long - -Public Declare Function FreeImage_GetFIFFromFormat Lib "FreeImage.dll" Alias "_FreeImage_GetFIFFromFormat@4" ( _ - ByVal Format As String) As FREE_IMAGE_FORMAT - -Public Declare Function FreeImage_GetFIFFromMime Lib "FreeImage.dll" Alias "_FreeImage_GetFIFFromMime@4" ( _ - ByVal MimeType As String) As FREE_IMAGE_FORMAT - -Private Declare Function FreeImage_GetFIFMimeTypeInt Lib "FreeImage.dll" Alias "_FreeImage_GetFIFMimeType@4" ( _ - ByVal Format As FREE_IMAGE_FORMAT) As Long - -Private Declare Function FreeImage_GetFormatFromFIFInt Lib "FreeImage.dll" Alias "_FreeImage_GetFormatFromFIF@4" ( _ - ByVal Format As FREE_IMAGE_FORMAT) As Long - -Private Declare Function FreeImage_GetFIFExtensionListInt Lib "FreeImage.dll" Alias "_FreeImage_GetFIFExtensionList@4" ( _ - ByVal Format As FREE_IMAGE_FORMAT) As Long - -Private Declare Function FreeImage_GetFIFDescriptionInt Lib "FreeImage.dll" Alias "_FreeImage_GetFIFDescription@4" ( _ - ByVal Format As FREE_IMAGE_FORMAT) As Long - -Private Declare Function FreeImage_GetFIFRegExprInt Lib "FreeImage.dll" Alias "_FreeImage_GetFIFRegExpr@4" ( _ - ByVal Format As FREE_IMAGE_FORMAT) As Long - -Public Declare Function FreeImage_GetFIFFromFilename Lib "FreeImage.dll" Alias "_FreeImage_GetFIFFromFilename@4" ( _ - ByVal Filename As String) As FREE_IMAGE_FORMAT - -Private Declare Function FreeImage_GetFIFFromFilenameUInt Lib "FreeImage.dll" Alias "_FreeImage_GetFIFFromFilenameU@4" ( _ - ByVal Filename As Long) As FREE_IMAGE_FORMAT - -Private Declare Function FreeImage_FIFSupportsReadingInt Lib "FreeImage.dll" Alias "_FreeImage_FIFSupportsReading@4" ( _ - ByVal Format As FREE_IMAGE_FORMAT) As Long - -Private Declare Function FreeImage_FIFSupportsWritingInt Lib "FreeImage.dll" Alias "_FreeImage_FIFSupportsWriting@4" ( _ - ByVal Format As FREE_IMAGE_FORMAT) As Long - -Private Declare Function FreeImage_FIFSupportsExportTypeInt Lib "FreeImage.dll" Alias "_FreeImage_FIFSupportsExportType@8" ( _ - ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal ImageType As FREE_IMAGE_TYPE) As Long - -Private Declare Function FreeImage_FIFSupportsExportBPPInt Lib "FreeImage.dll" Alias "_FreeImage_FIFSupportsExportBPP@8" ( _ - ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal BitsPerPixel As Long) As Long - -Private Declare Function FreeImage_FIFSupportsICCProfilesInt Lib "FreeImage.dll" Alias "_FreeImage_FIFSupportsICCProfiles@4" ( _ - ByVal Format As FREE_IMAGE_FORMAT) As Long - -Private Declare Function FreeImage_FIFSupportsNoPixelsInt Lib "FreeImage.dll" Alias "_FreeImage_FIFSupportsNoPixels@4" ( _ - ByVal Format As FREE_IMAGE_FORMAT) As Long - -Public Declare Function FreeImage_RegisterLocalPlugin Lib "FreeImage.dll" Alias "_FreeImage_RegisterLocalPlugin@20" ( _ - ByVal InitProcAddress As Long, _ - Optional ByVal Format As String, _ - Optional ByVal Description As String, _ - Optional ByVal Extension As String, _ - Optional ByVal RegExpr As String) As FREE_IMAGE_FORMAT - -Public Declare Function FreeImage_RegisterExternalPlugin Lib "FreeImage.dll" Alias "_FreeImage_RegisterExternalPlugin@20" ( _ - ByVal Path As String, _ - Optional ByVal Format As String, _ - Optional ByVal Description As String, _ - Optional ByVal Extension As String, _ - Optional ByVal RegExpr As String) As FREE_IMAGE_FORMAT - - -' Multipage functions -Private Declare Function FreeImage_OpenMultiBitmapInt Lib "FreeImage.dll" Alias "_FreeImage_OpenMultiBitmap@24" ( _ - ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Filename As String, _ - ByVal CreateNew As Long, _ - ByVal ReadOnly As Long, _ - ByVal KeepCacheInMemory As Long, _ - ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long - -Private Declare Function FreeImage_CloseMultiBitmapInt Lib "FreeImage.dll" Alias "_FreeImage_CloseMultiBitmap@8" ( _ - ByVal Bitmap As Long, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Long - -Public Declare Function FreeImage_GetPageCount Lib "FreeImage.dll" Alias "_FreeImage_GetPageCount@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Sub FreeImage_AppendPage Lib "FreeImage.dll" Alias "_FreeImage_AppendPage@8" ( _ - ByVal Bitmap As Long, _ - ByVal PageBitmap As Long) - -Public Declare Sub FreeImage_InsertPage Lib "FreeImage.dll" Alias "_FreeImage_InsertPage@12" ( _ - ByVal Bitmap As Long, _ - ByVal Page As Long, _ - ByVal PageBitmap As Long) - -Public Declare Sub FreeImage_DeletePage Lib "FreeImage.dll" Alias "_FreeImage_DeletePage@8" ( _ - ByVal Bitmap As Long, _ - ByVal Page As Long) - -Public Declare Function FreeImage_LockPage Lib "FreeImage.dll" Alias "_FreeImage_LockPage@8" ( _ - ByVal Bitmap As Long, _ - ByVal Page As Long) As Long - -Private Declare Sub FreeImage_UnlockPageInt Lib "FreeImage.dll" Alias "_FreeImage_UnlockPage@12" ( _ - ByVal Bitmap As Long, _ - ByVal PageBitmap As Long, _ - ByVal ApplyChanges As Long) - -Private Declare Function FreeImage_MovePageInt Lib "FreeImage.dll" Alias "_FreeImage_MovePage@12" ( _ - ByVal Bitmap As Long, _ - ByVal TargetPage As Long, _ - ByVal SourcePage As Long) As Long - -Private Declare Function FreeImage_GetLockedPageNumbersInt Lib "FreeImage.dll" Alias "_FreeImage_GetLockedPageNumbers@12" ( _ - ByVal Bitmap As Long, _ - ByRef PagesPtr As Long, _ - ByRef Count As Long) As Long - - -' Memory I/O streams -Public Declare Function FreeImage_OpenMemory Lib "FreeImage.dll" Alias "_FreeImage_OpenMemory@8" ( _ - Optional ByRef Data As Byte, _ - Optional ByVal SizeInBytes As Long) As Long - -Public Declare Function FreeImage_OpenMemoryByPtr Lib "FreeImage.dll" Alias "_FreeImage_OpenMemory@8" ( _ - Optional ByVal DataPtr As Long, _ - Optional ByVal SizeInBytes As Long) As Long - -Public Declare Sub FreeImage_CloseMemory Lib "FreeImage.dll" Alias "_FreeImage_CloseMemory@4" ( _ - ByVal Stream As Long) - -Public Declare Function FreeImage_LoadFromMemory Lib "FreeImage.dll" Alias "_FreeImage_LoadFromMemory@12" ( _ - ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Stream As Long, _ - Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long - -Private Declare Function FreeImage_SaveToMemoryInt Lib "FreeImage.dll" Alias "_FreeImage_SaveToMemory@16" ( _ - ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Bitmap As Long, _ - ByVal Stream As Long, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Long - -Private Declare Function FreeImage_AcquireMemoryInt Lib "FreeImage.dll" Alias "_FreeImage_AcquireMemory@12" ( _ - ByVal Stream As Long, _ - ByRef DataPtr As Long, _ - ByRef SizeInBytes As Long) As Long - -Public Declare Function FreeImage_TellMemory Lib "FreeImage.dll" Alias "_FreeImage_TellMemory@4" ( _ - ByVal Stream As Long) As Long - -Private Declare Function FreeImage_SeekMemoryInt Lib "FreeImage.dll" Alias "_FreeImage_SeekMemory@12" ( _ - ByVal Stream As Long, _ - ByVal Offset As Long, _ - ByVal Origin As Long) As Long - -Public Declare Function FreeImage_ReadMemory Lib "FreeImage.dll" Alias "_FreeImage_ReadMemory@16" ( _ - ByVal BufferPtr As Long, _ - ByVal Size As Long, _ - ByVal Count As Long, _ - ByVal Stream As Long) As Long - -Public Declare Function FreeImage_WriteMemory Lib "FreeImage.dll" Alias "_FreeImage_WriteMemory@16" ( _ - ByVal BufferPtr As Long, _ - ByVal Size As Long, _ - ByVal Count As Long, _ - ByVal Stream As Long) As Long - -Public Declare Function FreeImage_LoadMultiBitmapFromMemory Lib "FreeImage.dll" Alias "_FreeImage_LoadMultiBitmapFromMemory@12" ( _ - ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Stream As Long, _ - Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long - -Public Declare Function FreeImage_SaveMultiBitmapToMemory Lib "FreeImage.dll" Alias "_FreeImage_SaveMultiBitmapToMemory@16" ( _ - ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Bitmap As Long, _ - ByVal Stream As Long, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Long - - -' Compression functions -Public Declare Function FreeImage_ZLibCompress Lib "FreeImage.dll" Alias "_FreeImage_ZLibCompress@16" ( _ - ByVal TargetPtr As Long, _ - ByVal TargetSize As Long, _ - ByVal SourcePtr As Long, _ - ByVal SourceSize As Long) As Long - -Public Declare Function FreeImage_ZLibUncompress Lib "FreeImage.dll" Alias "_FreeImage_ZLibUncompress@16" ( _ - ByVal TargetPtr As Long, _ - ByVal TargetSize As Long, _ - ByVal SourcePtr As Long, _ - ByVal SourceSize As Long) As Long - -Public Declare Function FreeImage_ZLibGZip Lib "FreeImage.dll" Alias "_FreeImage_ZLibGZip@16" ( _ - ByVal TargetPtr As Long, _ - ByVal TargetSize As Long, _ - ByVal SourcePtr As Long, _ - ByVal SourceSize As Long) As Long - -Public Declare Function FreeImage_ZLibGUnzip Lib "FreeImage.dll" Alias "_FreeImage_ZLibGUnzip@16" ( _ - ByVal TargetPtr As Long, _ - ByVal TargetSize As Long, _ - ByVal SourcePtr As Long, _ - ByVal SourceSize As Long) As Long - -Public Declare Function FreeImage_ZLibCRC32 Lib "FreeImage.dll" Alias "_FreeImage_ZLibCRC32@12" ( _ - ByVal CRC As Long, _ - ByVal SourcePtr As Long, _ - ByVal SourceSize As Long) As Long - - -' Helper functions -Private Declare Function FreeImage_IsLittleEndianInt Lib "FreeImage.dll" Alias "_FreeImage_IsLittleEndian@0" () As Long - -Private Declare Function FreeImage_LookupX11ColorInt Lib "FreeImage.dll" Alias "_FreeImage_LookupX11Color@16" ( _ - ByVal Color As String, _ - ByRef red As Long, _ - ByRef green As Long, _ - ByRef blue As Long) As Long - -Private Declare Function FreeImage_LookupSVGColorInt Lib "FreeImage.dll" Alias "_FreeImage_LookupSVGColor@16" ( _ - ByVal Color As String, _ - ByRef red As Long, _ - ByRef green As Long, _ - ByRef blue As Long) As Long - - -'-------------------------------------------------------------------------------- -' Metadata functions -'-------------------------------------------------------------------------------- - -' Tag creation and destruction -Private Declare Function FreeImage_CreateTag Lib "FreeImage.dll" Alias "_FreeImage_CreateTag@0" () As Long - -Private Declare Sub FreeImage_DeleteTag Lib "FreeImage.dll" Alias "_FreeImage_DeleteTag@4" ( _ - ByVal Tag As Long) - -Private Declare Function FreeImage_CloneTag Lib "FreeImage.dll" Alias "_FreeImage_CloneTag@4" ( _ - ByVal Tag As Long) As Long - - -' Tag accessors (only those needed by wrapper functions) -Private Declare Function FreeImage_SetTagKey Lib "FreeImage.dll" Alias "_FreeImage_SetTagKey@8" ( _ - ByVal Tag As Long, _ - ByVal Key As String) As Long - -Private Declare Function FreeImage_SetTagValue Lib "FreeImage.dll" Alias "_FreeImage_SetTagValue@8" ( _ - ByVal Tag As Long, _ - ByVal ValuePtr As Long) As Long - -' Metadata iterator -Public Declare Function FreeImage_FindFirstMetadata Lib "FreeImage.dll" Alias "_FreeImage_FindFirstMetadata@12" ( _ - ByVal Model As FREE_IMAGE_MDMODEL, _ - ByVal Bitmap As Long, _ - ByRef Tag As Long) As Long - -Private Declare Function FreeImage_FindNextMetadataInt Lib "FreeImage.dll" Alias "_FreeImage_FindNextMetadata@8" ( _ - ByVal hFind As Long, _ - ByRef Tag As Long) As Long - -Public Declare Sub FreeImage_FindCloseMetadata Lib "FreeImage.dll" Alias "_FreeImage_FindCloseMetadata@4" ( _ - ByVal hFind As Long) - -Public Declare Function FreeImage_CloneMetadataInt Lib "FreeImage.dll" Alias "_FreeImage_CloneMetadata@8" ( _ - ByVal BitmapDst As Long, _ - ByVal BitmapSrc As Long) As Long - - -' Metadata accessors -Private Declare Function FreeImage_SetMetadataInt Lib "FreeImage.dll" Alias "_FreeImage_SetMetadata@16" ( _ - ByVal Model As Long, _ - ByVal Bitmap As Long, _ - ByVal Key As String, _ - ByVal Tag As Long) As Long - -Private Declare Function FreeImage_GetMetadataInt Lib "FreeImage.dll" Alias "_FreeImage_GetMetadata@16" ( _ - ByVal Model As Long, _ - ByVal Bitmap As Long, _ - ByVal Key As String, _ - ByRef Tag As Long) As Long - - -' Metadata helper functions -Public Declare Function FreeImage_GetMetadataCount Lib "FreeImage.dll" Alias "_FreeImage_GetMetadataCount@8" ( _ - ByVal Model As Long, _ - ByVal Bitmap As Long) As Long - -Private Declare Function FreeImage_TagToStringInt Lib "FreeImage.dll" Alias "_FreeImage_TagToString@12" ( _ - ByVal Model As Long, _ - ByVal Tag As Long, _ - Optional ByVal Make As String = vbNullString) As Long - - -'-------------------------------------------------------------------------------- -' Toolkit functions -'-------------------------------------------------------------------------------- - -' Rotating and flipping -Public Declare Function FreeImage_RotateClassic Lib "FreeImage.dll" Alias "_FreeImage_RotateClassic@12" ( _ - ByVal Bitmap As Long, _ - ByVal Angle As Double) As Long - -Public Declare Function FreeImage_Rotate Lib "FreeImage.dll" Alias "_FreeImage_Rotate@16" ( _ - ByVal Bitmap As Long, _ - ByVal Angle As Double, _ - Optional ByRef Color As Any) As Long - -Private Declare Function FreeImage_RotateExInt Lib "FreeImage.dll" Alias "_FreeImage_RotateEx@48" ( _ - ByVal Bitmap As Long, _ - ByVal Angle As Double, _ - ByVal ShiftX As Double, _ - ByVal ShiftY As Double, _ - ByVal OriginX As Double, _ - ByVal OriginY As Double, _ - ByVal UseMask As Long) As Long - -Private Declare Function FreeImage_FlipHorizontalInt Lib "FreeImage.dll" Alias "_FreeImage_FlipHorizontal@4" ( _ - ByVal Bitmap As Long) As Long - -Private Declare Function FreeImage_FlipVerticalInt Lib "FreeImage.dll" Alias "_FreeImage_FlipVertical@4" ( _ - ByVal Bitmap As Long) As Long - -Private Declare Function FreeImage_JPEGTransformInt Lib "FreeImage.dll" Alias "_FreeImage_JPEGTransform@16" ( _ - ByVal SourceFile As String, _ - ByVal DestFile As String, _ - ByVal Operation As FREE_IMAGE_JPEG_OPERATION, _ - ByVal Perfect As Long) As Long - -Private Declare Function FreeImage_JPEGTransformUInt Lib "FreeImage.dll" Alias "_FreeImage_JPEGTransformU@16" ( _ - ByVal SourceFile As Long, _ - ByVal DestFile As Long, _ - ByVal Operation As FREE_IMAGE_JPEG_OPERATION, _ - ByVal Perfect As Long) As Long - - -' Upsampling and downsampling -Public Declare Function FreeImage_Rescale Lib "FreeImage.dll" Alias "_FreeImage_Rescale@16" ( _ - ByVal Bitmap As Long, _ - ByVal Width As Long, _ - ByVal Height As Long, _ - ByVal Filter As FREE_IMAGE_FILTER) As Long - -Public Declare Function FreeImage_RescaleRect Lib "FreeImage.dll" Alias "_FreeImage_RescaleRect@32" ( _ - ByVal Bitmap As Long, _ - ByVal Left As Long, _ - ByVal Top As Long, _ - ByVal Right As Long, _ - ByVal Bottom As Long, _ - ByVal Width As Long, _ - ByVal Height As Long, _ - ByVal Filter As FREE_IMAGE_FILTER) As Long - -Private Declare Function FreeImage_MakeThumbnailInt Lib "FreeImage.dll" Alias "_FreeImage_MakeThumbnail@12" ( _ - ByVal Bitmap As Long, _ - ByVal MaxPixelSize As Long, _ - Optional ByVal Convert As Long) As Long - - -' Color manipulation -Private Declare Function FreeImage_AdjustCurveInt Lib "FreeImage.dll" Alias "_FreeImage_AdjustCurve@12" ( _ - ByVal Bitmap As Long, _ - ByVal LookupTablePtr As Long, _ - ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Long - -Private Declare Function FreeImage_AdjustGammaInt Lib "FreeImage.dll" Alias "_FreeImage_AdjustGamma@12" ( _ - ByVal Bitmap As Long, _ - ByVal Gamma As Double) As Long - -Private Declare Function FreeImage_AdjustBrightnessInt Lib "FreeImage.dll" Alias "_FreeImage_AdjustBrightness@12" ( _ - ByVal Bitmap As Long, _ - ByVal Percentage As Double) As Long - -Private Declare Function FreeImage_AdjustContrastInt Lib "FreeImage.dll" Alias "_FreeImage_AdjustContrast@12" ( _ - ByVal Bitmap As Long, _ - ByVal Percentage As Double) As Long - -Private Declare Function FreeImage_InvertInt Lib "FreeImage.dll" Alias "_FreeImage_Invert@4" ( _ - ByVal Bitmap As Long) As Long - -Private Declare Function FreeImage_GetHistogramInt Lib "FreeImage.dll" Alias "_FreeImage_GetHistogram@12" ( _ - ByVal Bitmap As Long, _ - ByRef HistogramPtr As Long, _ - Optional ByVal Channel As FREE_IMAGE_COLOR_CHANNEL = FICC_BLACK) As Long - -Private Declare Function FreeImage_GetAdjustColorsLookupTableInt Lib "FreeImage.dll" Alias "_FreeImage_GetAdjustColorsLookupTable@32" ( _ - ByVal LookupTablePtr As Long, _ - ByVal Brightness As Double, _ - ByVal Contrast As Double, _ - ByVal Gamma As Double, _ - ByVal Invert As Long) As Long - -Private Declare Function FreeImage_AdjustColorsInt Lib "FreeImage.dll" Alias "_FreeImage_AdjustColors@32" ( _ - ByVal Bitmap As Long, _ - ByVal Brightness As Double, _ - ByVal Contrast As Double, _ - ByVal Gamma As Double, _ - ByVal Invert As Long) As Long - -Private Declare Function FreeImage_ApplyColorMappingInt Lib "FreeImage.dll" Alias "_FreeImage_ApplyColorMapping@24" ( _ - ByVal Bitmap As Long, _ - ByVal SourceColorsPtr As Long, _ - ByVal DestinationColorsPtr As Long, _ - ByVal Count As Long, _ - ByVal IgnoreAlpha As Long, _ - ByVal swap As Long) As Long - -Private Declare Function FreeImage_SwapColorsInt Lib "FreeImage.dll" Alias "_FreeImage_SwapColors@16" ( _ - ByVal Bitmap As Long, _ - ByRef ColorA As RGBQUAD, _ - ByRef ColorB As RGBQUAD, _ - ByVal IgnoreAlpha As Long) As Long - -Private Declare Function FreeImage_SwapColorsByLongInt Lib "FreeImage.dll" Alias "_FreeImage_SwapColors@16" ( _ - ByVal Bitmap As Long, _ - ByRef ColorA As Long, _ - ByRef ColorB As Long, _ - ByVal IgnoreAlpha As Long) As Long - -Private Declare Function FreeImage_ApplyIndexMappingInt Lib "FreeImage.dll" Alias "_FreeImage_ApplyIndexMapping@20" ( _ - ByVal Bitmap As Long, _ - ByVal SourceIndicesPtr As Long, _ - ByVal DestinationIndicesPtr As Long, _ - ByVal Count As Long, _ - ByVal swap As Long) As Long - -Public Declare Function FreeImage_SwapPaletteIndices Lib "FreeImage.dll" Alias "_FreeImage_SwapPaletteIndices@12" ( _ - ByVal Bitmap As Long, _ - ByRef IndexA As Byte, _ - ByRef IndexB As Byte) As Long - -' Channel processing -Public Declare Function FreeImage_GetChannel Lib "FreeImage.dll" Alias "_FreeImage_GetChannel@8" ( _ - ByVal Bitmap As Long, _ - ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Long - -Private Declare Function FreeImage_SetChannelInt Lib "FreeImage.dll" Alias "_FreeImage_SetChannel@12" ( _ - ByVal BitmapDst As Long, _ - ByVal BitmapSrc As Long, _ - ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Long - -Public Declare Function FreeImage_GetComplexChannel Lib "FreeImage.dll" Alias "_FreeImage_GetComplexChannel@8" ( _ - ByVal Bitmap As Long, _ - ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Long - -Private Declare Function FreeImage_SetComplexChannelInt Lib "FreeImage.dll" Alias "_FreeImage_SetComplexChannel@12" ( _ - ByVal BitmapDst As Long, _ - ByVal BitmapSrc As Long, _ - ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Long - - -' Copy / Paste / Composite routines -Public Declare Function FreeImage_Copy Lib "FreeImage.dll" Alias "_FreeImage_Copy@20" ( _ - ByVal Bitmap As Long, _ - ByVal Left As Long, _ - ByVal Top As Long, _ - ByVal Right As Long, _ - ByVal Bottom As Long) As Long - -Private Declare Function FreeImage_PasteInt Lib "FreeImage.dll" Alias "_FreeImage_Paste@20" ( _ - ByVal BitmapDst As Long, _ - ByVal BitmapSrc As Long, _ - ByVal Left As Long, _ - ByVal Top As Long, _ - ByVal Alpha As Long) As Long - -Public Declare Function FreeImage_Composite Lib "FreeImage.dll" Alias "_FreeImage_Composite@16" ( _ - ByVal Bitmap As Long, _ - Optional ByVal UseFileBackColor As Long, _ - Optional ByRef AppBackColor As Any, _ - Optional ByVal BackgroundBitmap As Long) As Long - -Private Declare Function FreeImage_JPEGCropInt Lib "FreeImage.dll" Alias "_FreeImage_JPEGCrop@24" ( _ - ByVal SourceFile As String, _ - ByVal DestFile As String, _ - ByVal Left As Long, _ - ByVal Top As Long, _ - ByVal Right As Long, _ - ByVal Bottom As Long) As Long - -Private Declare Function FreeImage_JPEGCropUInt Lib "FreeImage.dll" Alias "_FreeImage_JPEGCropU@24" ( _ - ByVal SourceFile As Long, _ - ByVal DestFile As Long, _ - ByVal Left As Long, _ - ByVal Top As Long, _ - ByVal Right As Long, _ - ByVal Bottom As Long) As Long - -Private Declare Function FreeImage_PreMultiplyWithAlphaInt Lib "FreeImage.dll" Alias "_FreeImage_PreMultiplyWithAlpha@4" ( _ - ByVal Bitmap As Long) As Long - -Public Declare Function FreeImage_FillBackground Lib "FreeImage.dll" Alias "_FreeImage_FillBackground@12" ( _ - ByVal Bitmap As Long, _ - ByRef Color As Any, _ - Optional ByVal Options As FREE_IMAGE_COLOR_OPTIONS = FI_COLOR_IS_RGB_COLOR) As Long - -Public Declare Function FreeImage_EnlargeCanvas Lib "FreeImage.dll" Alias "_FreeImage_EnlargeCanvas@28" ( _ - ByVal Bitmap As Long, _ - ByVal Left As Long, _ - ByVal Top As Long, _ - ByVal Right As Long, _ - ByVal Bottom As Long, _ - ByRef Color As Any, _ - Optional ByVal Options As FREE_IMAGE_COLOR_OPTIONS = FI_COLOR_IS_RGB_COLOR) As Long - -Public Declare Function FreeImage_AllocateEx Lib "FreeImage.dll" Alias "_FreeImage_AllocateEx@36" ( _ - ByVal Width As Long, _ - ByVal Height As Long, _ - Optional ByVal BitsPerPixel As Long = 8, _ - Optional ByRef Color As Any, _ - Optional ByVal Options As FREE_IMAGE_COLOR_OPTIONS, _ - Optional ByVal PalettePtr As Long = 0, _ - Optional ByVal RedMask As Long = 0, _ - Optional ByVal GreenMask As Long = 0, _ - Optional ByVal BlueMask As Long = 0) As Long - -Public Declare Function FreeImage_AllocateExT Lib "FreeImage.dll" Alias "_FreeImage_AllocateExT@36" ( _ - ByVal ImageType As FREE_IMAGE_TYPE, _ - ByVal Width As Long, _ - ByVal Height As Long, _ - Optional ByVal BitsPerPixel As Long = 8, _ - Optional ByRef Color As Any, _ - Optional ByVal Options As FREE_IMAGE_COLOR_OPTIONS, _ - Optional ByVal PalettePtr As Long, _ - Optional ByVal RedMask As Long, _ - Optional ByVal GreenMask As Long, _ - Optional ByVal BlueMask As Long) As Long - -' miscellaneous algorithms -Public Declare Function FreeImage_MultigridPoissonSolver Lib "FreeImage.dll" Alias "_FreeImage_MultigridPoissonSolver@8" ( _ - ByVal LaplacianBitmap As Long, _ - Optional ByVal Cyles As Long = 3) As Long - - -'-------------------------------------------------------------------------------- -' Line converting functions -'-------------------------------------------------------------------------------- - -' convert to 4 bpp -Public Declare Sub FreeImage_ConvertLine1To4 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To4@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine8To4 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To8@16" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long, _ - ByVal PalettePtr As Long) - -Public Declare Sub FreeImage_ConvertLine16To4_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To4_555@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine16To4_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To4_565@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine24To4 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To24@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine32To4 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine32To4@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - - -' convert to 8 bpp -Public Declare Sub FreeImage_ConvertLine1To8 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To8@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine4To8 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine4To8@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine16To8_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To8_555@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine16To8_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To8_565@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine24To8 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine24To8@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine32To8 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine32To8@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - - -' convert to 16 bpp -Public Declare Sub FreeImage_ConvertLine1To16_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To16_555@16" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long, _ - ByVal PalettePtr As Long) - -Public Declare Sub FreeImage_ConvertLine4To16_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine4To16_555@16" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long, _ - ByVal PalettePtr As Long) - -Public Declare Sub FreeImage_ConvertLine8To16_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine8To16_555@16" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long, _ - ByVal PalettePtr As Long) - -Public Declare Sub FreeImage_ConvertLine16_565_To16_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16_565_To16_555@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine24To16_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine24To16_555@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine32To16_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine32To16_555@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine1To16_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To16_565@16" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long, _ - ByVal PalettePtr As Long) - -Public Declare Sub FreeImage_ConvertLine4To16_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine4To16_565@16" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long, _ - ByVal PalettePtr As Long) - -Public Declare Sub FreeImage_ConvertLine8To16_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine8To16_565@16" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long, _ - ByVal PalettePtr As Long) - -Public Declare Sub FreeImage_ConvertLine16_555_To16_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16_555_To16_565@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine24To16_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine24To16_565@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine32To16_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine32To16_565@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - - -' convert to 24 bpp -Public Declare Sub FreeImage_ConvertLine1To24 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To24@16" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long, _ - ByVal PalettePtr As Long) - -Public Declare Sub FreeImage_ConvertLine4To24 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine4To24@16" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long, _ - ByVal PalettePtr As Long) - -Public Declare Sub FreeImage_ConvertLine8To24 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine8To24@16" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long, _ - ByVal PalettePtr As Long) - -Public Declare Sub FreeImage_ConvertLine16To24_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To24_555@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine16To24_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To24_565@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine32To24 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine32To24@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - - -' convert to 32 bpp -Public Declare Sub FreeImage_ConvertLine1To32 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To32@16" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long, _ - ByVal PalettePtr As Long) - -Public Declare Sub FreeImage_ConvertLine4To32 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine4To32@16" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long, _ - ByVal PalettePtr As Long) - -Public Declare Sub FreeImage_ConvertLine8To32 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine8To32@16" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long, _ - ByVal PalettePtr As Long) - -Public Declare Sub FreeImage_ConvertLine16To32_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To32_555@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine16To32_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To32_565@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - -Public Declare Sub FreeImage_ConvertLine24To32 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine24To32@12" ( _ - ByVal TargetPtr As Long, _ - ByVal SourcePtr As Long, _ - ByVal WidthInPixels As Long) - - - -'-------------------------------------------------------------------------------- -' Initialization functions -'-------------------------------------------------------------------------------- - -Public Function FreeImage_IsAvailable(Optional ByRef Version As String) As Boolean - - On Error Resume Next - Version = FreeImage_GetVersion() - FreeImage_IsAvailable = (Err.Number = ERROR_SUCCESS) - On Error GoTo 0 - -End Function - - - -'-------------------------------------------------------------------------------- -' Error handling functions -'-------------------------------------------------------------------------------- - -Public Sub FreeImage_InitErrorHandler() - - ' Call this function once for using the FreeImage 3 error handling callback. - ' The 'FreeImage_ErrorHandler' function is called on each FreeImage 3 error. - - Call FreeImage_SetOutputMessage(AddressOf FreeImage_ErrorHandler) - -End Sub - -Private Sub FreeImage_ErrorHandler(ByVal Format As FREE_IMAGE_FORMAT, ByVal Message As Long) - -Dim strErrorMessage As String -Dim strImageFormat As String - - ' This function is called whenever the FreeImage 3 libraray throws an error. - ' Currently this function gets the error message and the format name of the - ' involved image type as VB string printing each to the VB Debug console. Feel - ' free to modify this function to call an error handling routine of your on. - - strErrorMessage = pGetStringFromPointerA(Message) - strImageFormat = FreeImage_GetFormatFromFIF(Format) - - Debug.Print "[FreeImage] Error: " & strErrorMessage - Debug.Print " Image: " & strImageFormat - Debug.Print " Code: " & Format - -End Sub - - - -'-------------------------------------------------------------------------------- -' String returning functions wrappers -'-------------------------------------------------------------------------------- - -Public Function FreeImage_GetVersion() As String - - ' This function returns the version of the FreeImage 3 library - ' as VB String. Read paragraph 2 of the "General notes on implementation - ' and design" section to learn more about that technique. - - FreeImage_GetVersion = pGetStringFromPointerA(FreeImage_GetVersionInt) - -End Function - -Public Function FreeImage_GetCopyrightMessage() As String - - ' This function returns the copyright message of the FreeImage 3 library - ' as VB String. Read paragraph 2 of the "General notes on implementation - ' and design" section to learn more about that technique. - - FreeImage_GetCopyrightMessage = pGetStringFromPointerA(FreeImage_GetCopyrightMessageInt) - -End Function - -Public Function FreeImage_GetFormatFromFIF(ByVal Format As FREE_IMAGE_FORMAT) As String - - ' This function returns the result of the 'FreeImage_GetFormatFromFIF' function - ' as VB String. Read paragraph 2 of the "General notes on implementation - ' and design" section to learn more about that technique. - - ' The parameter 'Format' works according to the FreeImage 3 API documentation. - - FreeImage_GetFormatFromFIF = pGetStringFromPointerA(FreeImage_GetFormatFromFIFInt(Format)) - -End Function - -Public Function FreeImage_GetFIFExtensionList(ByVal Format As FREE_IMAGE_FORMAT) As String - - ' This function returns the result of the 'FreeImage_GetFIFExtensionList' function - ' as VB String. Read paragraph 2 of the "General notes on implementation - ' and design" section to learn more about that technique. - - ' The parameter 'Format' works according to the FreeImage 3 API documentation. - - FreeImage_GetFIFExtensionList = pGetStringFromPointerA(FreeImage_GetFIFExtensionListInt(Format)) - -End Function - -Public Function FreeImage_GetFIFDescription(ByVal Format As FREE_IMAGE_FORMAT) As String - - ' This function returns the result of the 'FreeImage_GetFIFDescription' function - ' as VB String. Read paragraph 2 of the "General notes on implementation - ' and design" section to learn more about that technique. - - ' The parameter 'Format' works according to the FreeImage 3 API documentation. - - FreeImage_GetFIFDescription = pGetStringFromPointerA(FreeImage_GetFIFDescriptionInt(Format)) - -End Function - -Public Function FreeImage_GetFIFRegExpr(ByVal Format As FREE_IMAGE_FORMAT) As String - - ' This function returns the result of the 'FreeImage_GetFIFRegExpr' function - ' as VB String. Read paragraph 2 of the "General notes on implementation - ' and design" section to learn more about that technique. - - ' The parameter 'Format' works according to the FreeImage 3 API documentation. - - FreeImage_GetFIFRegExpr = pGetStringFromPointerA(FreeImage_GetFIFRegExprInt(Format)) - -End Function - -Public Function FreeImage_GetFIFMimeType(ByVal Format As FREE_IMAGE_FORMAT) As String - - ' This function returns the result of the 'FreeImage_GetFIFMimeType' function - ' as VB String. Read paragraph 2 of the "General notes on implementation - ' and design" section to learn more about that technique. - - ' The parameter 'Format' works according to the FreeImage 3 API documentation. - - FreeImage_GetFIFMimeType = pGetStringFromPointerA(FreeImage_GetFIFMimeTypeInt(Format)) - -End Function - -Public Function FreeImage_TagToString(ByVal Model As Long, _ - ByVal Tag As Long, _ - Optional ByVal Make As String) As String - - ' This function returns the result of the 'FreeImage_TagToString' function - ' as VB String. Read paragraph 2 of the "General notes on implementation - ' and design" section to learn more about that technique. - - ' All parameters work according to the FreeImage 3 API documentation. - - FreeImage_TagToString = pGetStringFromPointerA(FreeImage_TagToStringInt(Model, Tag, Make)) - -End Function - - - -'-------------------------------------------------------------------------------- -' UNICODE dealing functions wrappers -'-------------------------------------------------------------------------------- - -Public Function FreeImage_LoadU(ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Filename As String, _ - Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long - - ' This function is just a thin wrapper to ease the call to an - ' UNICODE function. Since VB's BSTR strings are actually UNICODE - ' strings, we just need to pass the pointer to the string data - ' returned by the (undocumented) function StrPtr(). - - FreeImage_LoadU = FreeImage_LoadUInt(Format, StrPtr(Filename), Flags) - -End Function - -Public Function FreeImage_SaveU(ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Bitmap As Long, _ - ByVal Filename As String, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Boolean - - ' This function is just a thin wrapper to ease the call to an - ' UNICODE function. Since VB's BSTR strings are actually UNICODE - ' strings, we just need to pass the pointer to the string data - ' returned by the (undocumented) function StrPtr(). - - FreeImage_SaveU = (FreeImage_SaveUInt(Format, Bitmap, StrPtr(Filename), Flags) = 1) - -End Function - -Public Function FreeImage_GetFileTypeU(ByVal Filename As String, _ - Optional ByVal Size As Long = 0) As FREE_IMAGE_FORMAT - - ' This function is just a thin wrapper to ease the call to an - ' UNICODE function. Since VB's BSTR strings are actually UNICODE - ' strings, we just need to pass the pointer to the string data - ' returned by the (undocumented) function StrPtr(). - - FreeImage_GetFileTypeU = FreeImage_GetFileTypeUInt(StrPtr(Filename), Size) - -End Function - -Public Function FreeImage_GetFIFFromFilenameU(ByVal Filename As String) As FREE_IMAGE_FORMAT - - ' This function is just a thin wrapper to ease the call to an - ' UNICODE function. Since VB's BSTR strings are actually UNICODE - ' strings, we just need to pass the pointer to the string data - ' returned by the (undocumented) function StrPtr(). - - FreeImage_GetFIFFromFilenameU = FreeImage_GetFIFFromFilenameUInt(StrPtr(Filename)) - -End Function - -Public Function FreeImage_JPEGTransformU(ByVal SourceFile As String, _ - ByVal DestFile As String, _ - ByVal Operation As FREE_IMAGE_JPEG_OPERATION, _ - Optional ByVal Perfect As Boolean) As Boolean - -Dim lPerfect As Long - - ' This function is just a thin wrapper to ease the call to an - ' UNICODE function. Since VB's BSTR strings are actually UNICODE - ' strings, we just need to pass the pointer to the string data - ' returned by the (undocumented) function StrPtr(). - - If (Perfect) Then - lPerfect = 1 - End If - FreeImage_JPEGTransformU = (FreeImage_JPEGTransformInt(StrPtr(SourceFile), StrPtr(DestFile), _ - Operation, lPerfect) = 1) - -End Function - -Public Function FreeImage_JPEGCropU(ByVal SourceFile As String, _ - ByVal DestFile As String, _ - ByVal Left As Long, _ - ByVal Top As Long, _ - ByVal Right As Long, _ - ByVal Bottom As Long) As Boolean - - ' This function is just a thin wrapper to ease the call to an - ' UNICODE function. Since VB's BSTR strings are actually UNICODE - ' strings, we just need to pass the pointer to the string data - ' returned by the (undocumented) function StrPtr(). - - FreeImage_JPEGCropU = (FreeImage_JPEGCropInt(StrPtr(SourceFile), StrPtr(DestFile), Left, Top, _ - Right, Bottom) = 1) - -End Function - - - -'-------------------------------------------------------------------------------- -' BOOL/Boolean returning functions wrappers -'-------------------------------------------------------------------------------- - -Public Function FreeImage_HasPixels(ByVal Bitmap As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_HasPixels = (FreeImage_HasPixelsInt(Bitmap) = 1) - -End Function - -Public Function FreeImage_Save(ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Bitmap As Long, _ - ByVal Filename As String, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_Save = (FreeImage_SaveInt(Format, Bitmap, Filename, Flags) = 1) - -End Function - -Public Function FreeImage_SaveToHandle(ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Bitmap As Long, _ - ByVal IO As Long, _ - ByVal Handle As Long, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_SaveToHandle = (FreeImage_SaveToHandleInt(Format, Bitmap, IO, Handle, Flags) = 1) - -End Function - -Public Function FreeImage_IsTransparent(ByVal Bitmap As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_IsTransparent = (FreeImage_IsTransparentInt(Bitmap) = 1) - -End Function - -Public Sub FreeImage_SetTransparent(ByVal Bitmap As Long, ByVal Value As Boolean) - - If (Value) Then - Call FreeImage_SetTransparentInt(Bitmap, 1) - Else - Call FreeImage_SetTransparentInt(Bitmap, 0) - End If - -End Sub - -Public Function FreeImage_HasBackgroundColor(ByVal Bitmap As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_HasBackgroundColor = (FreeImage_HasBackgroundColorInt(Bitmap) = 1) - -End Function - -Public Function FreeImage_GetBackgroundColor(ByVal Bitmap As Long, _ - ByRef BackColor As RGBQUAD) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_GetBackgroundColor = (FreeImage_GetBackgroundColorInt(Bitmap, BackColor) = 1) - -End Function - -Public Function FreeImage_GetBackgroundColorAsLong(ByVal Bitmap As Long, _ - ByRef BackColor As Long) As Boolean - - ' This function gets the background color of an image as FreeImage_GetBackgroundColor() does but - ' provides it's result as a Long value. - - FreeImage_GetBackgroundColorAsLong = (FreeImage_GetBackgroundColorAsLongInt(Bitmap, BackColor) = 1) - -End Function - -Public Function FreeImage_GetBackgroundColorEx(ByVal Bitmap As Long, _ - ByRef Alpha As Byte, _ - ByRef red As Byte, _ - ByRef green As Byte, _ - ByRef blue As Byte) As Boolean - -Dim bkcolor As RGBQUAD - - ' This function gets the background color of an image as FreeImage_GetBackgroundColor() does but - ' provides it's result as four different byte values, one for each color component. - - FreeImage_GetBackgroundColorEx = (FreeImage_GetBackgroundColorInt(Bitmap, bkcolor) = 1) - With bkcolor - Alpha = .rgbReserved - red = .rgbRed - green = .rgbGreen - blue = .rgbBlue - End With - -End Function - -Public Function FreeImage_SetBackgroundColor(ByVal Bitmap As Long, _ - ByRef BackColor As RGBQUAD) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_SetBackgroundColor = (FreeImage_SetBackgroundColorInt(Bitmap, BackColor) = 1) - -End Function - -Public Function FreeImage_SetBackgroundColorAsLong(ByVal Bitmap As Long, _ - ByVal BackColor As Long) As Boolean - - ' This function sets the background color of an image as FreeImage_SetBackgroundColor() does but - ' the color value to set must be provided as a Long value. - - FreeImage_SetBackgroundColorAsLong = (FreeImage_SetBackgroundColorAsLongInt(Bitmap, BackColor) = 1) - -End Function - -Public Function FreeImage_SetBackgroundColorEx(ByVal Bitmap As Long, _ - ByVal Alpha As Byte, _ - ByVal red As Byte, _ - ByVal green As Byte, _ - ByVal blue As Byte) As Boolean - -Dim tColor As RGBQUAD - - ' This function sets the color at position (x|y) as FreeImage_SetPixelColor() does but - ' the color value to set must be provided four different byte values, one for each - ' color component. - - With tColor - .rgbReserved = Alpha - .rgbRed = red - .rgbGreen = green - .rgbBlue = blue - End With - FreeImage_SetBackgroundColorEx = (FreeImage_SetBackgroundColorInt(Bitmap, tColor) = 1) - -End Function - -Public Function FreeImage_GetPixelIndex(ByVal Bitmap As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByRef Value As Byte) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_GetPixelIndex = (FreeImage_GetPixelIndexInt(Bitmap, X, Y, Value) = 1) - -End Function - -Public Function FreeImage_GetPixelColor(ByVal Bitmap As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByRef Value As RGBQUAD) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_GetPixelColor = (FreeImage_GetPixelColorInt(Bitmap, X, Y, Value) = 1) - -End Function - -Public Function FreeImage_GetPixelColorByLong(ByVal Bitmap As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByRef Value As Long) As Boolean - - ' This function gets the color at position (x|y) as FreeImage_GetPixelColor() does but - ' provides it's result as a Long value. - - FreeImage_GetPixelColorByLong = (FreeImage_GetPixelColorByLongInt(Bitmap, X, Y, Value) = 1) - -End Function - -Public Function FreeImage_GetPixelColorEx(ByVal Bitmap As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByRef Alpha As Byte, _ - ByRef red As Byte, _ - ByRef green As Byte, _ - ByRef blue As Byte) As Boolean - -Dim Value As RGBQUAD - - ' This function gets the color at position (x|y) as FreeImage_GetPixelColor() does but - ' provides it's result as four different byte values, one for each color component. - - FreeImage_GetPixelColorEx = (FreeImage_GetPixelColorInt(Bitmap, X, Y, Value) = 1) - With Value - Alpha = .rgbReserved - red = .rgbRed - green = .rgbGreen - blue = .rgbBlue - End With - -End Function - -Public Function FreeImage_SetPixelIndex(ByVal Bitmap As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByRef Value As Byte) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_SetPixelIndex = (FreeImage_SetPixelIndexInt(Bitmap, X, Y, Value) = 1) - -End Function - -Public Function FreeImage_SetPixelColor(ByVal Bitmap As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByRef Value As RGBQUAD) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_SetPixelColor = (FreeImage_SetPixelColorInt(Bitmap, X, Y, Value) = 1) - -End Function - -Public Function FreeImage_SetPixelColorByLong(ByVal Bitmap As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByRef Value As Long) As Boolean - - ' This function sets the color at position (x|y) as FreeImage_SetPixelColor() does but - ' the color value to set must be provided as a Long value. - - FreeImage_SetPixelColorByLong = (FreeImage_SetPixelColorByLongInt(Bitmap, X, Y, Value) = 1) - -End Function - -Public Function FreeImage_SetPixelColorEx(ByVal Bitmap As Long, _ - ByVal X As Long, _ - ByVal Y As Long, _ - ByVal Alpha As Byte, _ - ByVal red As Byte, _ - ByVal green As Byte, _ - ByVal blue As Byte) As Boolean - -Dim Value As RGBQUAD - - ' This function sets the color at position (x|y) as FreeImage_SetPixelColor() does but - ' the color value to set must be provided four different byte values, one for each - ' color component. - - With Value - .rgbReserved = Alpha - .rgbRed = red - .rgbGreen = green - .rgbBlue = blue - End With - FreeImage_SetPixelColorEx = (FreeImage_SetPixelColorInt(Bitmap, X, Y, Value) = 1) - -End Function - -Public Function FreeImage_FIFSupportsReading(ByVal Format As FREE_IMAGE_FORMAT) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_FIFSupportsReading = (FreeImage_FIFSupportsReadingInt(Format) = 1) - -End Function - -Public Function FreeImage_FIFSupportsWriting(ByVal Format As FREE_IMAGE_FORMAT) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_FIFSupportsWriting = (FreeImage_FIFSupportsWritingInt(Format) = 1) - -End Function - -Public Function FreeImage_FIFSupportsExportType(ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal ImageType As FREE_IMAGE_TYPE) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_FIFSupportsExportType = (FreeImage_FIFSupportsExportTypeInt(Format, ImageType) = 1) - -End Function - -Public Function FreeImage_FIFSupportsExportBPP(ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal BitsPerPixel As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_FIFSupportsExportBPP = (FreeImage_FIFSupportsExportBPPInt(Format, BitsPerPixel) = 1) - -End Function - -Public Function FreeImage_FIFSupportsICCProfiles(ByVal Format As FREE_IMAGE_FORMAT) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_FIFSupportsICCProfiles = (FreeImage_FIFSupportsICCProfilesInt(Format) = 1) - -End Function - -Public Function FreeImage_FIFSupportsNoPixels(ByVal Format As FREE_IMAGE_FORMAT) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_FIFSupportsNoPixels = (FreeImage_FIFSupportsNoPixelsInt(Format) = 1) - -End Function - -Public Function FreeImage_CloseMultiBitmap(ByVal Bitmap As Long, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_CloseMultiBitmap = (FreeImage_CloseMultiBitmapInt(Bitmap, Flags) = 1) - -End Function - -Public Function FreeImage_MovePage(ByVal Bitmap As Long, _ - ByVal TargetPage As Long, _ - ByVal SourcePage As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_MovePage = (FreeImage_MovePageInt(Bitmap, TargetPage, SourcePage) = 1) - -End Function - -Public Function FreeImage_GetLockedPageNumbers(ByVal Bitmap As Long, _ - ByRef PagesPtr As Long, _ - ByRef Count As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_GetLockedPageNumbers = (FreeImage_GetLockedPageNumbersInt(Bitmap, PagesPtr, Count) = 1) - -End Function - -Public Function FreeImage_SaveToMemory(ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Bitmap As Long, _ - ByVal Stream As Long, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_SaveToMemory = (FreeImage_SaveToMemoryInt(Format, Bitmap, Stream, Flags) = 1) - -End Function - -Public Function FreeImage_AcquireMemory(ByVal Stream As Long, _ - ByRef DataPtr As Long, _ - ByRef SizeInBytes As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_AcquireMemory = (FreeImage_AcquireMemoryInt(Stream, DataPtr, SizeInBytes) = 1) - -End Function - -Public Function FreeImage_SeekMemory(ByVal Stream As Long, _ - ByVal Offset As Long, _ - ByVal Origin As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_SeekMemory = (FreeImage_SeekMemoryInt(Stream, Offset, Origin) = 1) - -End Function - -Public Function FreeImage_IsLittleEndian() As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_IsLittleEndian = (FreeImage_IsLittleEndianInt() = 1) - -End Function - -Public Function FreeImage_LookupX11Color(ByVal Color As String, _ - ByRef red As Long, _ - ByRef green As Long, _ - ByRef blue As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_LookupX11Color = (FreeImage_LookupX11ColorInt(Color, red, green, blue) = 1) - -End Function - -Public Function FreeImage_LookupSVGColor(ByVal Color As String, _ - ByRef red As Long, _ - ByRef green As Long, _ - ByRef blue As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_LookupSVGColor = (FreeImage_LookupSVGColorInt(Color, red, green, blue) = 1) - -End Function - -Public Function FreeImage_FindNextMetadata(ByVal hFind As Long, _ - ByRef Tag As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_FindNextMetadata = (FreeImage_FindNextMetadataInt(hFind, Tag) = 1) - -End Function - -Public Function FreeImage_CloneMetadata(ByVal BitmapDst As Long, _ - ByVal BitmapSrc As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_CloneMetadata = (FreeImage_CloneMetadataInt(BitmapDst, BitmapSrc) = 1) - -End Function - -Public Function FreeImage_GetMetadata(ByRef Model As Long, _ - ByVal Bitmap As Long, _ - ByVal Key As String, _ - ByVal Tag As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_GetMetadata = (FreeImage_GetMetadataInt(Model, Bitmap, Key, Tag) = 1) - -End Function - -Public Function FreeImage_SetMetadata(ByRef Model As Long, _ - ByVal Bitmap As Long, _ - ByVal Key As String, _ - ByVal Tag As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_SetMetadata = (FreeImage_SetMetadataInt(Model, Bitmap, Key, Tag) = 1) - -End Function - -Public Function FreeImage_FlipHorizontal(ByVal Bitmap As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_FlipHorizontal = (FreeImage_FlipHorizontalInt(Bitmap) = 1) - -End Function - -Public Function FreeImage_FlipVertical(ByVal Bitmap As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_FlipVertical = (FreeImage_FlipVerticalInt(Bitmap) = 1) - -End Function - -Public Function FreeImage_JPEGTransform(ByVal SourceFile As String, _ - ByVal DestFile As String, _ - ByVal Operation As FREE_IMAGE_JPEG_OPERATION, _ - Optional ByVal Perfect As Boolean) As Boolean - -Dim lPerfect As Long - - ' Thin wrapper function returning a real VB Boolean value - - If (Perfect) Then - lPerfect = 1 - End If - FreeImage_JPEGTransform = (FreeImage_JPEGTransformInt(SourceFile, DestFile, Operation, lPerfect) = 1) - -End Function - -Public Function FreeImage_AdjustCurve(ByVal Bitmap As Long, _ - ByVal LookupTablePtr As Long, _ - ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_AdjustCurve = (FreeImage_AdjustCurveInt(Bitmap, LookupTablePtr, Channel) = 1) - -End Function - -Public Function FreeImage_AdjustGamma(ByVal Bitmap As Long, _ - ByVal Gamma As Double) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_AdjustGamma = (FreeImage_AdjustGammaInt(Bitmap, Gamma) = 1) - -End Function - -Public Function FreeImage_AdjustBrightness(ByVal Bitmap As Long, _ - ByVal Percentage As Double) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_AdjustBrightness = (FreeImage_AdjustBrightnessInt(Bitmap, Percentage) = 1) - -End Function - -Public Function FreeImage_AdjustContrast(ByVal Bitmap As Long, _ - ByVal Percentage As Double) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_AdjustContrast = (FreeImage_AdjustContrastInt(Bitmap, Percentage) = 1) - -End Function - -Public Function FreeImage_Invert(ByVal Bitmap As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_Invert = (FreeImage_InvertInt(Bitmap) = 1) - -End Function - -Public Function FreeImage_GetHistogram(ByVal Bitmap As Long, _ - ByRef HistogramPtr As Long, _ - Optional ByVal Channel As FREE_IMAGE_COLOR_CHANNEL = FICC_BLACK) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_GetHistogram = (FreeImage_GetHistogramInt(Bitmap, HistogramPtr, Channel) = 1) - -End Function - -Public Function FreeImage_AdjustColors(ByVal Bitmap As Long, _ - Optional ByVal Brightness As Double, _ - Optional ByVal Contrast As Double, _ - Optional ByVal Gamma As Double = 1, _ - Optional ByVal Invert As Boolean) As Boolean - -Dim lInvert As Long - - ' Thin wrapper function returning a real VB Boolean value - If (Invert) Then - lInvert = 1 - End If - FreeImage_AdjustColors = (FreeImage_AdjustColorsInt(Bitmap, Brightness, Contrast, Gamma, lInvert) = 1) - -End Function - -Public Function FreeImage_SetChannel(ByVal BitmapDst As Long, _ - ByVal BitmapSrc As Long, _ - ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_SetChannel = (FreeImage_SetChannelInt(BitmapDst, BitmapSrc, Channel) = 1) - -End Function - -Public Function FreeImage_SetComplexChannel(ByVal BitmapDst As Long, _ - ByVal BitmapSrc As Long, _ - ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_SetComplexChannel = (FreeImage_SetComplexChannelInt(BitmapDst, BitmapSrc, Channel) = 1) - -End Function - -Public Function FreeImage_Paste(ByVal BitmapDst As Long, _ - ByVal BitmapSrc As Long, _ - ByVal Left As Long, _ - ByVal Top As Long, _ - ByVal Alpha As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_Paste = (FreeImage_PasteInt(BitmapDst, BitmapSrc, Left, Top, Alpha) = 1) - -End Function - -Public Function FreeImage_PreMultiplyWithAlpha(ByVal Bitmap As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_PreMultiplyWithAlpha = (FreeImage_PreMultiplyWithAlphaInt(Bitmap) = 1) - -End Function - -Public Function FreeImage_JPEGCrop(ByVal SourceFile As String, _ - ByVal DestFile As String, _ - ByVal Left As Long, _ - ByVal Top As Long, _ - ByVal Right As Long, _ - ByVal Bottom As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_JPEGCrop = (FreeImage_JPEGCropInt(SourceFile, DestFile, Left, Top, Right, Bottom) = 1) - -End Function - -Public Function FreeImage_FillBackgroundEx(ByVal Bitmap As Long, _ - ByRef Color As RGBQUAD, _ - Optional ByVal Options As FREE_IMAGE_COLOR_OPTIONS) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_FillBackgroundEx = (FreeImage_FillBackground(Bitmap, Color, Options) = 1) - -End Function - -Public Function FreeImage_FillBackgroundByLong(ByVal Bitmap As Long, _ - ByRef Color As Long, _ - Optional ByVal Options As FREE_IMAGE_COLOR_OPTIONS) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_FillBackgroundByLong = (FreeImage_FillBackground(Bitmap, Color, Options) = 1) - -End Function - -Public Function FreeImage_SetThumbnail(ByVal Bitmap As Long, ByVal Thumbnail As Long) As Boolean - - ' Thin wrapper function returning a real VB Boolean value - - FreeImage_SetThumbnail = (FreeImage_SetThumbnailInt(Bitmap, Thumbnail) = 1) - -End Function - - -Public Function FreeImage_OpenMultiBitmap(ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Filename As String, _ - Optional ByVal CreateNew As Boolean, _ - Optional ByVal ReadOnly As Boolean, _ - Optional ByVal KeepCacheInMemory As Boolean, _ - Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long - - FreeImage_OpenMultiBitmap = FreeImage_OpenMultiBitmapInt(Format, Filename, IIf(CreateNew, 1, 0), _ - IIf(ReadOnly And Not CreateNew, 1, 0), IIf(KeepCacheInMemory, 1, 0), Flags) - -End Function - -Public Sub FreeImage_UnlockPage(ByVal Bitmap As Long, ByVal PageBitmap As Long, ByVal ApplyChanges As Boolean) - -Dim lApplyChanges As Long - - If (ApplyChanges) Then - lApplyChanges = 1 - End If - Call FreeImage_UnlockPageInt(Bitmap, PageBitmap, lApplyChanges) - -End Sub - -Public Function FreeImage_RotateEx(ByVal Bitmap As Long, _ - ByVal Angle As Double, _ - Optional ByVal ShiftX As Double, _ - Optional ByVal ShiftY As Double, _ - Optional ByVal OriginX As Double, _ - Optional ByVal OriginY As Double, _ - Optional ByVal UseMask As Boolean) As Long - -Dim lUseMask As Long - - If (UseMask) Then - lUseMask = 1 - End If - FreeImage_RotateEx = FreeImage_RotateExInt(Bitmap, Angle, ShiftX, ShiftY, OriginX, OriginY, lUseMask) - -End Function - -Public Function FreeImage_MakeThumbnail(ByVal Bitmap As Long, _ - ByVal MaxPixelSize As Long, _ - Optional ByVal Convert As Boolean) As Long - -Dim lConvert As Long - - If (Convert) Then - lConvert = 1 - End If - FreeImage_MakeThumbnail = FreeImage_MakeThumbnailInt(Bitmap, MaxPixelSize, lConvert) - -End Function - -Public Function FreeImage_GetAdjustColorsLookupTable(ByVal LookupTablePtr As Long, _ - Optional ByVal Brightness As Double, _ - Optional ByVal Contrast As Double, _ - Optional ByVal Gamma As Double, _ - Optional ByVal Invert As Boolean) As Long - -Dim lInvert As Long - - If (Invert) Then - lInvert = 1 - End If - FreeImage_GetAdjustColorsLookupTable = FreeImage_GetAdjustColorsLookupTableInt(LookupTablePtr, _ - Brightness, Contrast, Gamma, lInvert) - -End Function - -Public Function FreeImage_ApplyColorMapping(ByVal Bitmap As Long, _ - ByVal SourceColorsPtr As Long, _ - ByVal DestinationColorsPtr As Long, _ - ByVal Count As Long, _ - Optional ByVal IgnoreAlpha As Boolean = True, _ - Optional ByVal swap As Boolean) As Long - -Dim lIgnoreAlpha As Long -Dim lSwap As Long - - If (IgnoreAlpha) Then - lIgnoreAlpha = 1 - End If - If (swap) Then - lSwap = 1 - End If - FreeImage_ApplyColorMapping = FreeImage_ApplyColorMappingInt(Bitmap, SourceColorsPtr, _ - DestinationColorsPtr, Count, lIgnoreAlpha, lSwap) - -End Function - -Public Function FreeImage_SwapColors(ByVal Bitmap As Long, _ - ByRef ColorA As RGBQUAD, _ - ByRef ColorB As RGBQUAD, _ - Optional ByVal IgnoreAlpha As Boolean = True) As Long - -Dim lIgnoreAlpha As Long - - If (IgnoreAlpha) Then - lIgnoreAlpha = 1 - End If - FreeImage_SwapColors = FreeImage_SwapColorsInt(Bitmap, ColorA, ColorB, lIgnoreAlpha) - -End Function - -Public Function FreeImage_SwapColorsByLong(ByVal Bitmap As Long, _ - ByRef ColorA As Long, _ - ByRef ColorB As Long, _ - Optional ByVal IgnoreAlpha As Boolean = True) As Long - -Dim lIgnoreAlpha As Long - - If (IgnoreAlpha) Then - lIgnoreAlpha = 1 - End If - FreeImage_SwapColorsByLong = FreeImage_SwapColorsByLongInt(Bitmap, ColorA, ColorB, _ - lIgnoreAlpha) - -End Function - -Public Function FreeImage_ApplyIndexMapping(ByVal Bitmap As Long, _ - ByVal SourceIndicesPtr As Long, _ - ByVal DestinationIndicesPtr As Long, _ - ByVal Count As Long, _ - Optional ByVal swap As Boolean) As Long - -Dim lSwap As Long - - If (swap) Then - lSwap = 1 - End If - FreeImage_ApplyIndexMapping = FreeImage_ApplyIndexMappingInt(Bitmap, SourceIndicesPtr, _ - DestinationIndicesPtr, Count, lSwap) - -End Function - -Public Function FreeImage_ConvertFromRawBits(ByVal BitsPtr As Long, _ - ByVal Width As Long, _ - ByVal Height As Long, _ - ByVal Pitch As Long, _ - ByVal BitsPerPixel As Long, _ - Optional ByVal RedMask As Long, _ - Optional ByVal GreenMask As Long, _ - Optional ByVal BlueMask As Long, _ - Optional ByVal TopDown As Boolean) As Long - -Dim lTopDown As Long - - If (TopDown) Then - lTopDown = 1 - End If - FreeImage_ConvertFromRawBits = FreeImage_ConvertFromRawBitsInt(BitsPtr, Width, Height, Pitch, _ - BitsPerPixel, RedMask, GreenMask, BlueMask, lTopDown) - -End Function - -Public Sub FreeImage_ConvertToRawBits(ByVal BitsPtr As Long, _ - ByVal Bitmap As Long, _ - ByVal Pitch As Long, _ - ByVal BitsPerPixel As Long, _ - Optional ByVal RedMask As Long, _ - Optional ByVal GreenMask As Long, _ - Optional ByVal BlueMask As Long, _ - Optional ByVal TopDown As Boolean) - -Dim lTopDown As Long - - If (TopDown) Then - lTopDown = 1 - End If - Call FreeImage_ConvertToRawBitsInt(BitsPtr, Bitmap, Pitch, _ - BitsPerPixel, RedMask, GreenMask, BlueMask, lTopDown) - -End Sub - -Public Function FreeImage_ConvertToStandardType(ByVal Bitmap As Long, _ - Optional ByVal ScaleLinear As Boolean = True) As Long - - If (ScaleLinear) Then - FreeImage_ConvertToStandardType = FreeImage_ConvertToStandardTypeInt(Bitmap, 1) - Else - FreeImage_ConvertToStandardType = FreeImage_ConvertToStandardTypeInt(Bitmap, 0) - End If - -End Function - -Public Function FreeImage_ConvertToType(ByVal Bitmap As Long, _ - ByVal DestinationType As FREE_IMAGE_TYPE, _ - Optional ByVal ScaleLinear As Boolean = True) As Long - - If (ScaleLinear) Then - FreeImage_ConvertToType = FreeImage_ConvertToTypeInt(Bitmap, DestinationType, 1) - Else - FreeImage_ConvertToType = FreeImage_ConvertToTypeInt(Bitmap, DestinationType, 0) - End If - -End Function - - - -'-------------------------------------------------------------------------------- -' Color conversion helper functions -'-------------------------------------------------------------------------------- - -Public Function ConvertColor(ByVal Color As Long) As Long - - ' This helper function converts a VB-style color value (like vbRed), which - ' uses the ABGR format into a RGBQUAD compatible color value, using the ARGB - ' format, needed by FreeImage and vice versa. - - ConvertColor = ((Color And &HFF000000) Or _ - ((Color And &HFF&) * &H10000) Or _ - ((Color And &HFF00&)) Or _ - ((Color And &HFF0000) \ &H10000)) - -End Function - -Public Function ConvertOleColor(ByVal Color As OLE_COLOR) As Long - - ' This helper function converts an OLE_COLOR value (like vbButtonFace), which - ' uses the BGR format into a RGBQUAD compatible color value, using the ARGB - ' format, needed by FreeImage. - - ' This function generally ingnores the specified color's alpha value but, in - ' contrast to ConvertColor, also has support for system colors, which have the - ' format &H80bbggrr. - - ' You should not use this function to convert any color provided by FreeImage - ' in ARGB format into a VB-style ABGR color value. Use function ConvertColor - ' instead. - -Dim lColorRef As Long - - If (OleTranslateColor(Color, 0, lColorRef) = 0) Then - ConvertOleColor = ConvertColor(lColorRef) - End If - -End Function - - - -'-------------------------------------------------------------------------------- -' Extended functions derived from FreeImage 3 functions usually dealing -' with arrays -'-------------------------------------------------------------------------------- - -Public Sub FreeImage_UnloadEx(ByRef Bitmap As Long) - - ' Extended version of FreeImage_Unload, which additionally sets the - ' passed Bitmap handle to zero after unloading. - - If (Bitmap <> 0) Then - Call FreeImage_Unload(Bitmap) - Bitmap = 0 - End If - -End Sub - -Public Function FreeImage_GetPaletteEx(ByVal Bitmap As Long) As RGBQUAD() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long - - ' This function returns a VB style array of type RGBQUAD, containing - ' the palette data of the Bitmap. This array provides read and write access - ' to the actual palette data provided by FreeImage. This is done by - ' creating a VB array with an own SAFEARRAY descriptor making the - ' array point to the palette pointer returned by FreeImage_GetPalette(). - - ' This makes you use code like you would in C/C++: - - ' // this code assumes there is a bitmap loaded and - ' // present in a variable called ‘dib’ - ' if(FreeImage_GetBPP(Bitmap) == 8) { - ' // Build a greyscale palette - ' RGBQUAD *pal = FreeImage_GetPalette(Bitmap); - ' for (int i = 0; i < 256; i++) { - ' pal[i].rgbRed = i; - ' pal[i].rgbGreen = i; - ' pal[i].rgbBlue = i; - ' } - - ' As in C/C++ the array is only valid while the DIB is loaded and the - ' palette data remains where the pointer returned by FreeImage_GetPalette - ' has pointed to when this function was called. So, a good thing would - ' be, not to keep the returned array in scope over the lifetime of the - ' Bitmap. Best practise is, to use this function within another routine and - ' assign the return value (the array) to a local variable only. As soon - ' as this local variable goes out of scope (when the calling function - ' returns to it's caller), the array and the descriptor is automatically - ' cleaned up by VB. - - ' This function does not make a deep copy of the palette data, but only - ' wraps a VB array around the FreeImage palette data. So, it can be called - ' frequently "on demand" or somewhat "in place" without a significant - ' performance loss. - - ' To learn more about this technique I recommend reading chapter 2 (Leveraging - ' Arrays) of Matthew Curland's book "Advanced Visual Basic 6" - - ' The parameter 'Bitmap' works according to the FreeImage 3 API documentation. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the FreeImage_DestroyLockedArrayRGBQUAD() function. - - - If (Bitmap) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 4 ' size in bytes of RGBQUAD structure - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetColorsUsed(Bitmap) ' the number of elements in the array is - ' the number of used colors in the Bitmap - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetPalette(Bitmap) ' let the array point to the memory block, the - ' FreeImage palette pointer points to - End With - - ' allocate memory for an array descriptor - ' we cannot use the memory block used by tSA, since it is - ' released when tSA goes out of scope, leaving us with an - ' array with zeroed descriptor - ' we use nearly the same method that VB uses, so VB is able - ' to cleanup the array variable and it's descriptor; the - ' array data is not touched when cleaning up, since both AUTO - ' and FIXEDSIZE flags are set - Call SafeArrayAllocDescriptor(1, lpSA) - - ' copy our own array descriptor over the descriptor allocated - ' by SafeArrayAllocDescriptor; lpSA is a pointer to that memory - ' location - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - - ' the implicit variable named as the function is an array variable in VB - ' make it point to the allocated array descriptor - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetPaletteEx), lpSA, 4) - End If - -End Function - -Public Function FreeImage_GetPaletteExClone(ByVal Bitmap As Long) As RGBQUAD() - -Dim lColors As Long -Dim atPal() As RGBQUAD - - ' This function returns a redundant clone of a Bitmap's palette as a - ' VB style array of type RGBQUAD. - - ' The parameter 'Bitmap' works according to the FreeImage 3 API documentation. - - lColors = FreeImage_GetColorsUsed(Bitmap) - If (lColors > 0) Then - ReDim atPal(lColors - 1) - Call CopyMemory(atPal(0), ByVal FreeImage_GetPalette(Bitmap), lColors * 4) - Call pSwap(ByVal VarPtrArray(atPal), ByVal VarPtrArray(FreeImage_GetPaletteExClone)) - End If - -End Function - -Public Function FreeImage_GetPaletteExLong(ByVal Bitmap As Long) As Long() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long - - ' This function returns a VB style array of type Long, containing - ' the palette data of the Bitmap. This array provides read and write access - ' to the actual palette data provided by FreeImage. This is done by - ' creating a VB array with an own SAFEARRAY descriptor making the - ' array point to the palette pointer returned by FreeImage_GetPalette(). - - ' The function actually returns an array of type RGBQUAD with each - ' element packed into a Long. This is possible, since the RGBQUAD - ' structure is also four bytes in size. Palette data, stored in an - ' array of type Long may be passed ByRef to a function through an - ' optional paremeter. For an example have a look at function - ' FreeImage_ConvertColorDepth() - - ' This makes you use code like you would in C/C++: - - ' // this code assumes there is a bitmap loaded and - ' // present in a variable called ‘dib’ - ' if(FreeImage_GetBPP(Bitmap) == 8) { - ' // Build a greyscale palette - ' RGBQUAD *pal = FreeImage_GetPalette(Bitmap); - ' for (int i = 0; i < 256; i++) { - ' pal[i].rgbRed = i; - ' pal[i].rgbGreen = i; - ' pal[i].rgbBlue = i; - ' } - - ' As in C/C++ the array is only valid while the DIB is loaded and the - ' palette data remains where the pointer returned by FreeImage_GetPalette() - ' has pointed to when this function was called. So, a good thing would - ' be, not to keep the returned array in scope over the lifetime of the - ' Bitmap. Best practise is, to use this function within another routine and - ' assign the return value (the array) to a local variable only. As soon - ' as this local variable goes out of scope (when the calling function - ' returns to it's caller), the array and the descriptor is automatically - ' cleaned up by VB. - - ' This function does not make a deep copy of the palette data, but only - ' wraps a VB array around the FreeImage palette data. So, it can be called - ' frequently "on demand" or somewhat "in place" without a significant - ' performance loss. - - ' To learn more about this technique I recommend reading chapter 2 (Leveraging - ' Arrays) of Matthew Curland's book "Advanced Visual Basic 6" - - ' The parameter 'Bitmap' works according to the FreeImage 3 API documentation. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArray' function. - - - If (Bitmap) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 4 ' size in bytes of RGBQUAD structure - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetColorsUsed(Bitmap) ' the number of elements in the array is - ' the number of used colors in the Bitmap - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetPalette(Bitmap) ' let the array point to the memory block, the - ' FreeImage palette pointer points to - End With - - ' allocate memory for an array descriptor - ' we cannot use the memory block used by tSA, since it is - ' released when tSA goes out of scope, leaving us with an - ' array with zeroed descriptor - ' we use nearly the same method that VB uses, so VB is able - ' to cleanup the array variable and it's descriptor; the - ' array data is not touched when cleaning up, since both AUTO - ' and FIXEDSIZE flags are set - Call SafeArrayAllocDescriptor(1, lpSA) - - ' copy our own array descriptor over the descriptor allocated - ' by SafeArrayAllocDescriptor; lpSA is a pointer to that memory - ' location - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - - ' the implicit variable named as the function is an array variable in VB - ' make it point to the allocated array descriptor - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetPaletteExLong), lpSA, 4) - End If - -End Function - -Public Function FreeImage_GetPaletteExLongClone(ByVal Bitmap As Long) As Long() - -Dim lColors As Long -Dim alPal() As Long - - ' This function returns a redundant clone of a Bitmap's palette as a - ' VB style array of type Long. - - ' The parameter 'Bitmap' works according to the FreeImage 3 API documentation. - - lColors = FreeImage_GetColorsUsed(Bitmap) - If (lColors > 0) Then - ReDim alPal(lColors - 1) - Call CopyMemory(alPal(0), ByVal FreeImage_GetPalette(Bitmap), lColors * 4) - Call pSwap(ByVal VarPtrArray(alPal), ByVal VarPtrArray(FreeImage_GetPaletteExLongClone)) - End If - -End Function - -Public Function FreeImage_SetPalette(ByVal Bitmap As Long, ByRef Palette() As RGBQUAD) As Long - - ' This function sets the palette of a palletised bitmap using a RGBQUAD array. Does - ' nothing on high color bitmaps. - - ' This operation makes a deep copy of the provided palette data so, after this function - ' has returned, changes to the RGBQUAD array are no longer reflected by the bitmap's - ' palette. - - FreeImage_SetPalette = FreeImage_GetColorsUsed(Bitmap) - If (FreeImage_SetPalette > 0) Then - Call CopyMemory(ByVal FreeImage_GetPalette(Bitmap), Palette(0), FreeImage_SetPalette * 4) - End If - -End Function - -Public Function FreeImage_SetPaletteLong(ByVal Bitmap As Long, ByRef Palette() As Long) As Long - - ' This function sets the palette of a palletised bitmap using a RGBQUAD array. Does - ' nothing on high color bitmaps. - - ' This operation makes a deep copy of the provided palette data so, after this function - ' has returned, changes to the Long array are no longer reflected by the bitmap's - ' palette. - - FreeImage_SetPaletteLong = FreeImage_GetColorsUsed(Bitmap) - If (FreeImage_SetPaletteLong > 0) Then - Call CopyMemory(ByVal FreeImage_GetPalette(Bitmap), Palette(0), FreeImage_SetPaletteLong * 4) - End If - -End Function - -Public Function FreeImage_GetTransparencyTableEx(ByVal Bitmap As Long) As Byte() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long - - ' This function returns a VB style Byte array, containing the transparency - ' table of the Bitmap. This array provides read and write access to the actual - ' transparency table provided by FreeImage. This is done by creating a VB array - ' with an own SAFEARRAY descriptor making the array point to the transparency - ' table pointer returned by FreeImage_GetTransparencyTable(). - - ' This makes you use code like you would in C/C++: - - ' // this code assumes there is a bitmap loaded and - ' // present in a variable called ‘dib’ - ' if(FreeImage_GetBPP(Bitmap) == 8) { - ' // Remove transparency information - ' byte *transt = FreeImage_GetTransparencyTable(Bitmap); - ' for (int i = 0; i < 256; i++) { - ' transt[i].rgbRed = 255; - ' } - - ' As in C/C++ the array is only valid while the DIB is loaded and the transparency - ' table remains where the pointer returned by FreeImage_GetTransparencyTable() has - ' pointed to when this function was called. So, a good thing would be, not to keep - ' the returned array in scope over the lifetime of the DIB. Best practise is, to use - ' this function within another routine and assign the return value (the array) to a - ' local variable only. As soon as this local variable goes out of scope (when the - ' calling function returns to it's caller), the array and the descriptor is - ' automatically cleaned up by VB. - - ' This function does not make a deep copy of the transparency table, but only - ' wraps a VB array around the FreeImage transparency table. So, it can be called - ' frequently "on demand" or somewhat "in place" without a significant - ' performance loss. - - ' To learn more about this technique I recommend reading chapter 2 (Leveraging - ' Arrays) of Matthew Curland's book "Advanced Visual Basic 6" - - ' The parameter 'Bitmap' works according to the FreeImage 3 API documentation. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the FreeImage_DestroyLockedArray() function. - - - If (Bitmap) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 1 ' size in bytes of a byte element - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetTransparencyCount(Bitmap) ' the number of elements in the array is - ' equal to the number transparency table entries - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetTransparencyTable(Bitmap) ' let the array point to the memory block, the - ' FreeImage transparency table pointer points to - End With - - ' allocate memory for an array descriptor - ' we cannot use the memory block used by tSA, since it is - ' released when tSA goes out of scope, leaving us with an - ' array with zeroed descriptor - ' we use nearly the same method that VB uses, so VB is able - ' to cleanup the array variable and it's descriptor; the - ' array data is not touched when cleaning up, since both AUTO - ' and FIXEDSIZE flags are set - Call SafeArrayAllocDescriptor(1, lpSA) - - ' copy our own array descriptor over the descriptor allocated - ' by SafeArrayAllocDescriptor(); lpSA is a pointer to that memory - ' location - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - - ' the implicit variable named as the function is an array variable in VB - ' make it point to the allocated array descriptor - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetTransparencyTableEx), lpSA, 4) - End If - -End Function - -Public Function FreeImage_GetTransparencyTableExClone(ByVal Bitmap As Long) As Byte() - -Dim abBuffer() As Byte -Dim lpTransparencyTable As Long -Dim lEntries As Long - - ' This function returns a copy of a DIB's transparency table as VB style - ' array of type Byte. So, the array provides read access only from the DIB's - ' point of view. - - ' The parameter 'Bitmap' works according to the FreeImage 3 API documentation. - - lpTransparencyTable = FreeImage_GetTransparencyTable(Bitmap) - If (lpTransparencyTable) Then - lEntries = FreeImage_GetTransparencyCount(Bitmap) - If (lEntries > 0) Then - ReDim abBuffer(lEntries - 1) - Call CopyMemory(abBuffer(0), ByVal lpTransparencyTable, lEntries) - Call pSwap(ByVal VarPtrArray(abBuffer), ByVal VarPtrArray( _ - FreeImage_GetTransparencyTableExClone)) - End If - End If - -End Function - -Public Sub FreeImage_SetTransparencyTableEx(ByVal Bitmap As Long, _ - ByRef Table() As Byte, _ - Optional ByRef Count As Long = -1) - - ' This function sets a DIB's transparency table to the contents of the - ' parameter table(). When the optional parameter Count is omitted, the - ' number of entries used is taken from the number of elements stored in - ' the array, but will never be never greater than 256. - - ' The parameter 'Bitmap' works according to the FreeImage 3 API documentation. - - If ((Count > UBound(Table) + 1) Or _ - (Count < 0)) Then - Count = UBound(Table) + 1 - End If - - If (Count > 256) Then - Count = 256 - End If - - Call FreeImage_SetTransparencyTable(Bitmap, VarPtr(Table(0)), Count) - -End Sub - -Public Function FreeImage_IsTransparencyTableTransparent(ByVal Bitmap As Long) As Boolean - -Dim abTransTable() As Byte -Dim i As Long - - ' This function checks whether a Bitmap's transparency table contains any transparent - ' colors or not. - - ' When an image has a transparency table and is transparent, what can be tested - ' with 'FreeImage_IsTransparent()', the image still may display opaque when there - ' are no transparent colors defined in the image's transparency table. This - ' function reads the Bitmap's transparency table directly to determine whether - ' there are transparent colors defined or not. - - ' The return value of this function does not relay on the image's transparency - ' setting but only on the image's transparency table - - If (Bitmap) Then - abTransTable = FreeImage_GetTransparencyTableEx(Bitmap) - For i = 0 To UBound(abTransTable) - FreeImage_IsTransparencyTableTransparent = (abTransTable(i) < 255) - If (FreeImage_IsTransparencyTableTransparent) Then - Exit For - End If - Next i - End If - -End Function - -Public Function FreeImage_GetAdjustColorsLookupTableEx(ByRef LookupTable() As Byte, _ - Optional ByVal Brightness As Double, _ - Optional ByVal Contrast As Double, _ - Optional ByVal Gamma As Double = 1, _ - Optional ByVal Invert As Boolean) As Long - - ' This function is an extended wrapper for FreeImage_GetAdjustColorsLookupTable(), which - ' takes a real VB style Byte array LUT() to receive the created lookup table. The LUT() - ' parameter must not be fixed sized or locked, since it is (re-)dimensioned in this - ' function to contain 256 entries. - - ' All parameters work according to the FreeImage 3 API documentation. - - ReDim LookupTable(255) - FreeImage_GetAdjustColorsLookupTableEx = _ - FreeImage_GetAdjustColorsLookupTable(VarPtr(LookupTable(0)), Brightness, Contrast, _ - Gamma, Invert) - -End Function - -Public Function FreeImage_ApplyColorMappingEx(ByVal Bitmap As Long, _ - ByRef SourceColors() As RGBQUAD, _ - ByRef DestinationColors() As RGBQUAD, _ - Optional ByRef Count As Long = -1, _ - Optional ByVal IgnoreAlpha As Boolean = True, _ - Optional ByVal swap As Boolean) As Long - -Dim nsrc As Long -Dim ndst As Long - - ' This function is an extended wrapper for FreeImage_ApplyColorMapping(), which takes - ' real VB style RGBQUAD arrays for source and destination colors along with an optional - ' ByRef Count parameter. - - ' If 'Count' is omitted upon entry, the number of entries of the smaller of both arrays - ' is used for 'Count' and also passed back to the caller, due to this parameter's ByRef - ' nature. - - ' All other parameters work according to the FreeImage 3 API documentation. - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to map colors on a 'header-only' bitmap.") - End If - - nsrc = UBound(SourceColors) + 1 - ndst = UBound(DestinationColors) + 1 - If (Count = -1) Then - If (nsrc < ndst) Then - Count = nsrc - Else - Count = ndst - End If - Else - If (Count < nsrc) Then - Count = nsrc - End If - If (Count < ndst) Then - Count = ndst - End If - End If - - FreeImage_ApplyColorMappingEx = FreeImage_ApplyColorMapping(Bitmap, _ - VarPtr(SourceColors(0)), VarPtr(DestinationColors(0)), Count, IgnoreAlpha, swap) - End If - -End Function - -Public Function FreeImage_ApplyIndexMappingEx(ByVal Bitmap As Long, _ - ByRef SourceIndices() As Byte, _ - ByRef DestinationIndices() As Byte, _ - Optional ByRef Count As Long = -1, _ - Optional ByVal swap As Boolean) As Long - -Dim nsrc As Long -Dim ndst As Long - - ' This function is an extended wrapper for FreeImage_ApplyIndexMapping(), which takes - ' real VB style Byte arrays for source and destination indices along with an optional - ' ByRef count parameter. - - ' If 'Count' is omitted upon entry, the number of entries of the smaller of both arrays - ' is used for 'Count' and also passed back to the caller, due to this parameter's ByRef - ' nature. - - ' All other parameters work according to the FreeImage 3 API documentation. - - - nsrc = UBound(SourceIndices) + 1 - ndst = UBound(DestinationIndices) + 1 - If (Count = -1) Then - If (nsrc < ndst) Then - Count = nsrc - Else - Count = ndst - End If - Else - If (Count < nsrc) Then - Count = nsrc - End If - If (Count < ndst) Then - Count = ndst - End If - End If - - FreeImage_ApplyIndexMappingEx = FreeImage_ApplyIndexMapping(Bitmap, _ - VarPtr(SourceIndices(0)), VarPtr(DestinationIndices(0)), Count, swap) - -End Function - -Public Function FreeImage_ConvertFromRawBitsEx(ByRef Bits() As Byte, _ - ByVal Width As Long, _ - ByVal Height As Long, _ - ByVal Pitch As Long, _ - ByVal BitsPerPixel As Long, _ - Optional ByVal RedMask As Long, _ - Optional ByVal GreenMask As Long, _ - Optional ByVal BlueMask As Long, _ - Optional ByVal TopDown As Boolean) As Long - - FreeImage_ConvertFromRawBitsEx = FreeImage_ConvertFromRawBits(VarPtr(Bits(0)), Width, Height, Pitch, _ - BitsPerPixel, RedMask, GreenMask, BlueMask, TopDown) - -End Function - -Public Sub FreeImage_ConvertToRawBitsEx(ByRef Bits() As Byte, _ - ByVal Bitmap As Long, _ - ByVal Pitch As Long, _ - ByVal BitsPerPixel As Long, _ - Optional ByVal RedMask As Long, _ - Optional ByVal GreenMask As Long, _ - Optional ByVal BlueMask As Long, _ - Optional ByVal TopDown As Boolean) - -Dim lHeight As Long - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to convert a 'header-only' bitmap.") - End If - - If (Pitch > 0) Then - lHeight = FreeImage_GetHeight(Bitmap) - ReDim Bits((Pitch * lHeight) - 1) - Call FreeImage_ConvertToRawBits(VarPtr(Bits(0)), Bitmap, Pitch, _ - BitsPerPixel, RedMask, GreenMask, BlueMask, TopDown) - End If - End If - -End Sub - -Public Function FreeImage_GetHistogramEx(ByVal Bitmap As Long, _ - Optional ByVal Channel As FREE_IMAGE_COLOR_CHANNEL = FICC_BLACK, _ - Optional ByRef Success As Boolean) As Long() - -Dim alResult() As Long - - ' This function returns a DIB's histogram data as VB style array of - ' type Long. Since histogram data is never modified directly, it seems - ' enough to return a clone of the data and no read/write accessible - ' array wrapped around the actual pointer. - - ' All parameters work according to the FreeImage 3 API documentation. - - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to get histogram of a 'header-only' bitmap.") - End If - - ReDim alResult(255) - Success = (FreeImage_GetHistogramInt(Bitmap, alResult(0), Channel) = 1) - If (Success) Then - Call pSwap(VarPtrArray(FreeImage_GetHistogramEx), VarPtrArray(alResult)) - End If - End If - -End Function - -Public Function FreeImage_AdjustCurveEx(ByVal Bitmap As Long, _ - ByRef LookupTable As Variant, _ - Optional ByVal Channel As FREE_IMAGE_COLOR_CHANNEL = FICC_BLACK) As Boolean - -Dim lpData As Long -Dim lSizeInBytes As Long - - ' This function extends the FreeImage function 'FreeImage_AdjustCurve' - ' to a more VB suitable function. The parameter 'LookupTable' may - ' either be an array of type Byte or may contain the pointer to a memory - ' block, what in VB is always the address of the memory block, since VB - ' actually doesn's support native pointers. - - ' In case of providing the memory block as an array, make sure, that the - ' array contains exactly 256 items. In case of providing an address of a - ' memory block, the size of the memory block is assumed to be 256 bytes - ' and it is up to the caller to ensure that it is large enough. - - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to adjust a 'header-only' bitmap.") - End If - - If (IsArray(LookupTable)) Then - lpData = pGetMemoryBlockPtrFromVariant(LookupTable, lSizeInBytes) - - ElseIf (IsNumeric(LookupTable)) Then - lSizeInBytes = 256 - lpData = CLng(LookupTable) - - End If - - If ((lpData <> 0) And (lSizeInBytes = 256)) Then - FreeImage_AdjustCurveEx = (FreeImage_AdjustCurveInt(Bitmap, lpData, Channel) = 1) - End If - End If - -End Function - -Public Function FreeImage_GetLockedPageNumbersEx(ByVal Bitmap As Long, _ - Optional ByRef Count As Long) As Long() - -Dim lpPages As Long -Dim alResult() As Long - - ' This function extends the FreeImage function FreeImage_GetLockedPageNumbers() - ' to a more VB suitable function. The original FreeImage parameter 'pages', which - ' is a pointer to an array of Long, containing all locked page numbers, was turned - ' into a return value, which is a real VB-style array of type Long. The original - ' Boolean return value, indicating if there are any locked pages, was dropped from - ' this function. The caller has to check the 'Count' parameter, which works according - ' to the FreeImage API documentation. - - ' This function returns an array of Longs, dimensioned from 0 to (Count - 1), that - ' contains the page numbers of all currently locked pages of 'BITMAP', if 'Count' is - ' greater than 0 after the function returns. If 'Count' is 0, there are no pages - ' locked and the function returns an uninitialized array. - - - If (FreeImage_GetLockedPageNumbersInt(Bitmap, lpPages, Count) = 1) Then - ReDim alResult(Count - 1) - Call CopyMemory(alResult(0), ByVal lpPages, Count * 4) - End If - -End Function - -' Memory and Stream functions - -Public Function FreeImage_GetFileTypeFromMemoryEx(ByRef Data As Variant, _ - Optional ByRef SizeInBytes As Long) As FREE_IMAGE_FORMAT - -Dim hStream As Long -Dim lDataPtr As Long - - ' This function extends the FreeImage function FreeImage_GetFileTypeFromMemory() - ' to a more VB suitable function. The parameter data of type Variant my - ' me either an array of type Byte, Integer or Long or may contain the pointer - ' to a memory block, what in VB is always the address of the memory block, - ' since VB actually doesn's support native pointers. - - ' In case of providing the memory block as an array, the SizeInBytes may - ' be omitted, zero or less than zero. Then, the size of the memory block - ' is calculated correctly. When SizeInBytes is given, it is up to the caller - ' to ensure, it is correct. - - ' In case of providing an address of a memory block, SizeInBytes must not - ' be omitted. - - - ' get both pointer and size in bytes of the memory block provided - ' through the Variant parameter 'data'. - lDataPtr = pGetMemoryBlockPtrFromVariant(Data, SizeInBytes) - - ' open the memory stream - hStream = FreeImage_OpenMemoryByPtr(lDataPtr, SizeInBytes) - If (hStream) Then - ' on success, detect image type - FreeImage_GetFileTypeFromMemoryEx = FreeImage_GetFileTypeFromMemory(hStream) - Call FreeImage_CloseMemory(hStream) - Else - FreeImage_GetFileTypeFromMemoryEx = FIF_UNKNOWN - End If - -End Function - -Public Function FreeImage_LoadFromMemoryEx(ByRef Data As Variant, _ - Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS, _ - Optional ByRef SizeInBytes As Long, _ - Optional ByRef Format As FREE_IMAGE_FORMAT) As Long - -Dim hStream As Long -Dim lDataPtr As Long - - ' This function extends the FreeImage function FreeImage_LoadFromMemory() - ' to a more VB suitable function. The parameter data of type Variant my - ' me either an array of type Byte, Integer or Long or may contain the pointer - ' to a memory block, what in VB is always the address of the memory block, - ' since VB actually doesn's support native pointers. - - ' The parameter 'Flags' works according to the FreeImage API documentation. - - ' In case of providing the memory block as an array, the SizeInBytes may - ' be omitted, zero or less than zero. Then, the size of the memory block - ' is calculated correctly. When SizeInBytes is given, it is up to the caller - ' to ensure, it is correct. - - ' In case of providing an address of a memory block, SizeInBytes must not - ' be omitted. - - ' The parameter fif is an OUT parameter, that will contain the image type - ' detected. Any values set by the caller will never be used within this - ' function. - - - ' get both pointer and size in bytes of the memory block provided - ' through the Variant parameter 'data'. - lDataPtr = pGetMemoryBlockPtrFromVariant(Data, SizeInBytes) - - ' open the memory stream - hStream = FreeImage_OpenMemoryByPtr(lDataPtr, SizeInBytes) - If (hStream) Then - ' on success, detect image type - Format = FreeImage_GetFileTypeFromMemory(hStream) - If (Format <> FIF_UNKNOWN) Then - ' load the image from memory stream only, if known image type - FreeImage_LoadFromMemoryEx = FreeImage_LoadFromMemory(Format, hStream, Flags) - End If - ' close the memory stream when open - Call FreeImage_CloseMemory(hStream) - End If - -End Function - -Public Function FreeImage_SaveToMemoryEx(ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Bitmap As Long, _ - ByRef Data() As Byte, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS, _ - Optional ByVal UnloadSource As Boolean) As Boolean - -Dim hStream As Long -Dim lpData As Long -Dim lSizeInBytes As Long - - ' This function saves a FreeImage DIB into memory by using the VB Byte - ' array Data(). It makes a deep copy of the image data and closes the - ' memory stream opened before it returns to the caller. - - ' The Byte array 'Data()' must not be a fixed sized array and will be - ' redimensioned according to the size needed to hold all the data. - - ' The parameters 'Format', 'Bitmap' and 'Flags' work according to the FreeImage 3 - ' API documentation. - - ' The optional 'UnloadSource' parameter is for unloading the original image - ' after it has been saved into memory. There is no need to clean up the DIB - ' at the caller's site. - - ' The function returns True on success and False otherwise. - - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to save a 'header-only' bitmap.") - End If - - hStream = FreeImage_OpenMemory() - If (hStream) Then - FreeImage_SaveToMemoryEx = FreeImage_SaveToMemory(Format, Bitmap, hStream, Flags) - If (FreeImage_SaveToMemoryEx) Then - If (FreeImage_AcquireMemoryInt(hStream, lpData, lSizeInBytes)) Then - On Error Resume Next - ReDim Data(lSizeInBytes - 1) - If (Err.Number = ERROR_SUCCESS) Then - On Error GoTo 0 - Call CopyMemory(Data(0), ByVal lpData, lSizeInBytes) - Else - On Error GoTo 0 - FreeImage_SaveToMemoryEx = False - End If - Else - FreeImage_SaveToMemoryEx = False - End If - End If - Call FreeImage_CloseMemory(hStream) - Else - FreeImage_SaveToMemoryEx = False - End If - - If (UnloadSource) Then - Call FreeImage_Unload(Bitmap) - End If - End If - -End Function - -Public Function FreeImage_SaveToMemoryEx2(ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Bitmap As Long, _ - ByRef Data() As Byte, _ - ByRef Stream As Long, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS, _ - Optional ByVal UnloadSource As Boolean) As Boolean - - ' This function saves a FreeImage DIB into memory by using the VB Byte - ' array Data(). It does not makes a deep copy of the image data, but uses - ' the function 'FreeImage_AcquireMemoryEx' to wrap the array 'Data()' - ' around the memory block pointed to by the result of the - ' 'FreeImage_AcquireMemory' function. - - ' The Byte array 'Data()' must not be a fixed sized array and will be - ' redimensioned according to the size needed to hold all the data. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArray' function. - - ' The parameter 'stream' is an IN/OUT parameter, tracking the memory - ' stream, the VB array 'Data()' is based on. This parameter may contain - ' an already opened FreeImage memory stream when the function is called and - ' contains a valid memory stream when the function returns in each case. - ' After all, it is up to the caller to close that memory stream correctly. - ' The array 'Data()' will no longer be valid and accessable after the stream - ' has been closed, so it should only be closed after the passed byte array - ' variable either goes out of the caller's scope or is redimensioned. - - ' The parameters 'Format', 'Bitmap' and 'Flags' work according to the FreeImage 3 - ' API documentation. - - ' The optional 'UnloadSource' parameter is for unloading the original image - ' after it has been saved to memory. There is no need to clean up the DIB - ' at the caller's site. - - ' The function returns True on success and False otherwise. - - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to save a 'header-only' bitmap.") - End If - - If (Stream = 0) Then - Stream = FreeImage_OpenMemory() - End If - If (Stream) Then - FreeImage_SaveToMemoryEx2 = FreeImage_SaveToMemory(Format, Bitmap, Stream, Flags) - If (FreeImage_SaveToMemoryEx2) Then - FreeImage_SaveToMemoryEx2 = FreeImage_AcquireMemoryEx(Stream, Data) - End If - - ' do not close the memory stream, since the returned array data() - ' points to the stream's data - ' the caller must close the stream after he is done - ' with the array - Else - FreeImage_SaveToMemoryEx2 = False - End If - - If (UnloadSource) Then - Call FreeImage_Unload(Bitmap) - End If - End If - -End Function - -Public Function FreeImage_AcquireMemoryEx(ByVal Stream As Long, _ - ByRef Data() As Byte, _ - Optional ByRef SizeInBytes As Long) As Boolean - -Dim lpData As Long -Dim tSA As SAVEARRAY1D -Dim lpSA As Long - - ' This function wraps the byte array Data() around acquired memory - ' of the memory stream specified by then stream parameter. The adjusted - ' array then points directly to the stream's data pointer and so - ' provides full read and write access. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArray' function. - - - If (Stream) Then - If (FreeImage_AcquireMemoryInt(Stream, lpData, SizeInBytes)) Then - With tSA - .cbElements = 1 ' one element is one byte - .cDims = 1 ' the array has only 1 dimension - .cElements = SizeInBytes ' the number of elements in the array is - ' the size in bytes of the memory block - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = lpData ' let the array point to the memory block - ' received by FreeImage_AcquireMemory - End With - - lpSA = deref(VarPtrArray(Data)) - If (lpSA = 0) Then - ' allocate memory for an array descriptor - Call SafeArrayAllocDescriptor(1, lpSA) - Call CopyMemory(ByVal VarPtrArray(Data), lpSA, 4) - Else - Call SafeArrayDestroyData(lpSA) - End If - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - Else - FreeImage_AcquireMemoryEx = False - End If - Else - FreeImage_AcquireMemoryEx = False - End If - -End Function - -Public Function FreeImage_ReadMemoryEx(ByRef Buffer As Variant, _ - ByVal Stream As Long, _ - Optional ByRef Count As Long, _ - Optional ByRef Size As Long) As Long - -Dim lBufferPtr As Long -Dim lSizeInBytes As Long -Dim lSize As Long -Dim lCount As Long - - ' This function is a wrapper for 'FreeImage_ReadMemory()' using VB style - ' arrays instead of a void pointer. - - ' The variant parameter 'Buffer' may be a Byte, Integer or Long array or - ' may contain a pointer to a memory block (the memory block's address). - - ' In the latter case, this function behaves exactly - ' like 'FreeImage_ReadMemory()'. Then, 'Count' and 'Size' must be valid - ' upon entry. - - ' If 'Buffer' is an initialized (dimensioned) array, 'Count' and 'Size' may - ' be omitted. Then, the array's layout is used to determine 'Count' - ' and 'Size'. In that case, any provided value in 'Count' and 'Size' upon - ' entry will override these calculated values as long as they are not - ' exceeding the size of the array in 'Buffer'. - - ' If 'Buffer' is an uninitialized (not yet dimensioned) array of any valid - ' type (Byte, Integer or Long) and, at least 'Count' is specified, the - ' array in 'Buffer' is redimensioned by this function. If 'Buffer' is a - ' fixed-size or otherwise locked array, a runtime error (10) occurs. - ' If 'Size' is omitted, the array's element size is assumed to be the - ' desired value. - - ' As FreeImage's function 'FreeImage_ReadMemory()', this function returns - ' the number of items actually read. - - ' Example: (very freaky...) - ' - ' Dim alLongBuffer() As Long - ' Dim lRet as Long - ' - ' ' now reading 303 integers (2 byte) into an array of Longs - ' lRet = FreeImage_ReadMemoryEx(alLongBuffer, lMyStream, 303, 2) - ' - ' ' now, lRet contains 303 and UBound(alLongBuffer) is 151 since - ' ' we need at least 152 Longs (0..151) to store (303 * 2) = 606 bytes - ' ' so, the higest two bytes of alLongBuffer(151) contain only unset - ' ' bits. Got it? - - ' Remark: This function's parameter order differs from FreeImage's - ' original funtion 'FreeImage_ReadMemory()'! - - If (VarType(Buffer) And vbArray) Then - ' get both pointer and size in bytes of the memory block provided - ' through the Variant parameter 'Buffer'. - lBufferPtr = pGetMemoryBlockPtrFromVariant(Buffer, lSizeInBytes, lSize) - If (lBufferPtr = 0) Then - ' array is not initialized - If (Count > 0) Then - ' only if we have a 'Count' value, redim the array - If (Size <= 0) Then - ' if 'Size' is omitted, use array's element size - Size = lSize - End If - - Select Case lSize - - Case 2 - ' Remark: -Int(-a) == ceil(a); a > 0 - ReDim Buffer(-Int(-Count * Size / 2) - 1) As Integer - - Case 4 - ' Remark: -Int(-a) == ceil(a); a > 0 - ReDim Buffer(-Int(-Count * Size / 4) - 1) As Long - - Case Else - ReDim Buffer((Count * Size) - 1) As Byte - - End Select - lBufferPtr = pGetMemoryBlockPtrFromVariant(Buffer, lSizeInBytes, lSize) - End If - End If - If (lBufferPtr) Then - lCount = lSizeInBytes / lSize - If (Size <= 0) Then - ' use array's natural value for 'Size' when - ' omitted - Size = lSize - End If - If (Count <= 0) Then - ' use array's natural value for 'Count' when - ' omitted - Count = lCount - End If - If ((Size * Count) > (lSize * lCount)) Then - If (Size = lSize) Then - Count = lCount - Else - ' Remark: -Fix(-a) == floor(a); a > 0 - Count = -Fix(-lSizeInBytes / Size) - If (Count = 0) Then - Size = lSize - Count = lCount - End If - End If - End If - FreeImage_ReadMemoryEx = FreeImage_ReadMemory(lBufferPtr, Size, Count, Stream) - End If - - ElseIf (VarType(Buffer) = vbLong) Then - ' if Buffer is a Long, it specifies the address of a memory block - ' then, we do not know anything about its size, so assume that 'Size' - ' and 'Count' are correct and forward these directly to the FreeImage - ' call. - FreeImage_ReadMemoryEx = FreeImage_ReadMemory(CLng(Buffer), Size, Count, Stream) - - End If - -End Function - -Public Function FreeImage_WriteMemoryEx(ByRef Buffer As Variant, _ - ByVal Stream As Long, _ - Optional ByRef Count As Long, _ - Optional ByRef Size As Long) As Long - -Dim lBufferPtr As Long -Dim lSizeInBytes As Long -Dim lSize As Long -Dim lCount As Long - - ' This function is a wrapper for 'FreeImage_WriteMemory()' using VB style - ' arrays instead of a void pointer. - - ' The variant parameter 'Buffer' may be a Byte, Integer or Long array or - ' may contain a pointer to a memory block (the memory block's address). - - ' In the latter case, this function behaves exactly - ' like 'FreeImage_WriteMemory()'. Then, 'Count' and 'Size' must be valid - ' upon entry. - - ' If 'Buffer' is an initialized (dimensioned) array, 'Count' and 'Size' may - ' be omitted. Then, the array's layout is used to determine 'Count' - ' and 'Size'. In that case, any provided value in 'Count' and 'Size' upon - ' entry will override these calculated values as long as they are not - ' exceeding the size of the array in 'Buffer'. - - ' If 'Buffer' is an uninitialized (not yet dimensioned) array of any - ' type, the function will do nothing an returns 0. - - ' Remark: This function's parameter order differs from FreeImage's - ' original funtion 'FreeImage_ReadMemory()'! - - If (VarType(Buffer) And vbArray) Then - ' get both pointer and size in bytes of the memory block provided - ' through the Variant parameter 'Buffer'. - lBufferPtr = pGetMemoryBlockPtrFromVariant(Buffer, lSizeInBytes, lSize) - If (lBufferPtr) Then - lCount = lSizeInBytes / lSize - If (Size <= 0) Then - ' use array's natural value for 'Size' when - ' omitted - Size = lSize - End If - If (Count <= 0) Then - ' use array's natural value for 'Count' when - ' omitted - Count = lCount - End If - If ((Size * Count) > (lSize * lCount)) Then - If (Size = lSize) Then - Count = lCount - Else - ' Remark: -Fix(-a) == floor(a); a > 0 - Count = -Fix(-lSizeInBytes / Size) - If (Count = 0) Then - Size = lSize - Count = lCount - End If - End If - End If - FreeImage_WriteMemoryEx = FreeImage_WriteMemory(lBufferPtr, Size, Count, Stream) - End If - - ElseIf (VarType(Buffer) = vbLong) Then - ' if Buffer is a Long, it specifies the address of a memory block - ' then, we do not know anything about its size, so assume that 'Size' - ' and 'Count' are correct and forward these directly to the FreeImage - ' call. - FreeImage_WriteMemoryEx = FreeImage_WriteMemory(CLng(Buffer), Size, Count, Stream) - - End If - -End Function - -Public Function FreeImage_LoadMultiBitmapFromMemoryEx(ByRef Data As Variant, _ - Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS, _ - Optional ByRef SizeInBytes As Long, _ - Optional ByRef Format As FREE_IMAGE_FORMAT) As Long - -Dim hStream As Long -Dim lDataPtr As Long - - ' This function extends the FreeImage function FreeImage_LoadMultiBitmapFromMemoryEx() - ' to a more VB suitable function. The parameter data of type Variant my - ' me either an array of type Byte, Integer or Long or may contain the pointer - ' to a memory block, what in VB is always the address of the memory block, - ' since VB actually doesn's support native pointers. - - ' The parameter 'Flags' works according to the FreeImage API documentation. - - ' In case of providing the memory block as an array, the SizeInBytes may - ' be omitted, zero or less than zero. Then, the size of the memory block - ' is calculated correctly. When SizeInBytes is given, it is up to the caller - ' to ensure, it is correct. - - ' In case of providing an address of a memory block, SizeInBytes must not - ' be omitted. - - ' The parameter fif is an OUT parameter, that will contain the image type - ' detected. Any values set by the caller will never be used within this - ' function. - - - ' get both pointer and size in bytes of the memory block provided - ' through the Variant parameter 'Data'. - lDataPtr = pGetMemoryBlockPtrFromVariant(Data, SizeInBytes) - - ' open the memory stream - hStream = FreeImage_OpenMemoryByPtr(lDataPtr, SizeInBytes) - If (hStream) Then - ' on success, detect image type - Format = FreeImage_GetFileTypeFromMemory(hStream) - If (Format <> FIF_UNKNOWN) Then - ' load the image from memory stream only, if known image type - FreeImage_LoadMultiBitmapFromMemoryEx = FreeImage_LoadMultiBitmapFromMemory(Format, hStream, Flags) - End If - ' close the memory stream when open - Call FreeImage_CloseMemory(hStream) - End If - -End Function - -Public Function FreeImage_SaveMultiBitmapToMemoryEx(ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Bitmap As Long, _ - ByRef Data() As Byte, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS, _ - Optional ByVal UnloadSource As Boolean) As Boolean - -Dim hStream As Long -Dim lpData As Long -Dim lSizeInBytes As Long - - ' This function saves a FreeImage multi-page bitmap into memory by using - ' the VB Byte array Data(). It makes a deep copy of the image data and closes the - ' memory stream opened, before it returns to the caller. - - ' The Byte array 'Data()' must not be a fixed sized array and will be - ' redimensioned according to the size needed to hold all the data. - - ' The parameters 'Format', 'Bitmap' and 'Flags' work according to the FreeImage 3 - ' API documentation. - - ' The optional 'UnloadSource' parameter is for unloading the original image - ' after it has been saved to memory. If True, there is no need to close the - ' multi-page bitmap at the caller's site. - - ' The function returns True on success and False otherwise. - - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to save a 'header-only' bitmap.") - End If - - hStream = FreeImage_OpenMemory() - If (hStream) Then - FreeImage_SaveMultiBitmapToMemoryEx = FreeImage_SaveMultiBitmapToMemory(Format, Bitmap, hStream, Flags) - If (FreeImage_SaveMultiBitmapToMemoryEx) Then - If (FreeImage_AcquireMemoryInt(hStream, lpData, lSizeInBytes)) Then - On Error Resume Next - ReDim Data(lSizeInBytes - 1) - If (Err.Number = ERROR_SUCCESS) Then - On Error GoTo 0 - Call CopyMemory(Data(0), ByVal lpData, lSizeInBytes) - Else - On Error GoTo 0 - FreeImage_SaveMultiBitmapToMemoryEx = False - End If - Else - FreeImage_SaveMultiBitmapToMemoryEx = False - End If - End If - Call FreeImage_CloseMemory(hStream) - Else - FreeImage_SaveMultiBitmapToMemoryEx = False - End If - - If (UnloadSource) Then - Call FreeImage_CloseMultiBitmapInt(Bitmap) - End If - End If - -End Function - -Public Function FreeImage_SaveMultiBitmapToMemoryEx2(ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Bitmap As Long, _ - ByRef Data() As Byte, _ - ByRef Stream As Long, _ - Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS, _ - Optional ByVal UnloadSource As Boolean) As Boolean - - ' This function saves a FreeImage multi-page bitmap into memory by using - ' the VB Byte array Data(). It does not makes a deep copy of the image data, but uses - ' the function 'FreeImage_AcquireMemoryEx' to wrap the array 'Data()' - ' around the memory block pointed to by the result of the - ' 'FreeImage_AcquireMemory' function. - - ' The Byte array 'Data()' must not be a fixed sized array and will be - ' redimensioned according to the size needed to hold all the data. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArray' function. - - ' The parameter 'Stream' is an IN/OUT parameter, tracking the memory - ' stream, the VB array 'Data()' is based on. This parameter may contain - ' an already opened FreeImage memory stream when the function is called and - ' contains a valid memory stream when the function returns in each case. - ' After all, it is up to the caller to close that memory stream correctly. - ' The array 'Data()' will no longer be valid and accessable after the stream - ' has been closed, so it should only be closed after the passed byte array - ' variable either goes out of the caller's scope or is redimensioned. - - ' The parameters 'Format', 'Bitmap' and 'Flags' work according to the FreeImage 3 - ' API documentation. - - ' The optional 'UnloadSource' parameter is for unloading the original image - ' after it has been saved to memory. If True, there is no need to close the - ' multi-page bitmap at the caller's site. - - ' The function returns True on success and False otherwise. - - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to save a 'header-only' bitmap.") - End If - - If (Stream = 0) Then - Stream = FreeImage_OpenMemory() - End If - If (Stream) Then - FreeImage_SaveMultiBitmapToMemoryEx2 = _ - FreeImage_SaveMultiBitmapToMemory(Format, Bitmap, Stream, Flags) - If (FreeImage_SaveMultiBitmapToMemoryEx2) Then - FreeImage_SaveMultiBitmapToMemoryEx2 = FreeImage_AcquireMemoryEx(Stream, Data) - End If - - ' do not close the memory stream, since the returned array 'Data()' - ' points to the stream's data - ' the caller must close the stream after he is done - ' with the array - Else - FreeImage_SaveMultiBitmapToMemoryEx2 = False - End If - - If (UnloadSource) Then - Call FreeImage_CloseMultiBitmapInt(Bitmap) - End If - End If - -End Function - - - -'-------------------------------------------------------------------------------- -' Tag accessing VB friendly helper functions -'-------------------------------------------------------------------------------- - -Public Function FreeImage_CreateTagEx(ByVal Model As FREE_IMAGE_MDMODEL, _ - Optional ByVal Key As String, _ - Optional ByVal TagType As FREE_IMAGE_MDTYPE = FIDT_NOTYPE, _ - Optional ByRef Value As Variant, _ - Optional ByRef Count As Long, _ - Optional ByVal Id As Long) As FREE_IMAGE_TAG - - ' This function is a wrapper for FreeImage_CreateTag() working with - ' the VB friendly FREE_IMAGE_TAG structure. So, the return value is - ' not a pointer to a FITAG structure but a FREE_IMAGE_TAG structure. - - ' In contrast to FreeImage's original FreeImage_CreateTag() function, the - ' parameter 'Model' must be specified, the parameters 'Key', 'TagType', - ' 'Value', 'Count' and 'Id' my be specified. - - ' The 'Model' is needed, since each FREE_IMAGE_TAG structure needs a - ' valid 'Model' member. - - ' All other parameters are optional and enable the caller to specify the tag's - ' values upon tag creation. Any parameter specified, is set to it's corresponding - ' member in the FREE_IMAGE_TAG structure. - - ' The caller should check the returned FREE_IMAGE_TAG structure's 'TagPtr' member. - ' If this function succeeded, the 'TagPtr' member is non zero. A value of zero - ' indicates an error condition sourced from FreeImage_CreateTag(). - - With FreeImage_CreateTagEx - .TagPtr = FreeImage_CreateTag() - If (.TagPtr <> 0) Then - .Model = Model - If (LenB(Key) > 0) Then - .Key = Key - End If - .Type = TagType - .Count = Count - .Id = Id - If (Not IsMissing(Value)) Then - .Value = Value - End If - Call pTagToTagPtr(FreeImage_CreateTagEx) - FreeImage_CreateTagEx = pGetTagFromTagPtr(Model, .TagPtr) - End If - End With - -End Function - -Public Function FreeImage_AppendTag(ByVal Bitmap As Long, _ - ByVal Model As FREE_IMAGE_MDMODEL, _ - Optional ByVal Key As String, _ - Optional ByVal TagType As FREE_IMAGE_MDTYPE = FIDT_NOTYPE, _ - Optional ByRef Value As Variant, _ - Optional ByRef Count As Long, _ - Optional ByVal Id As Long, _ - Optional ByVal OverwriteExisting As Boolean = True) As FREE_IMAGE_TAG - -Dim lpTag As Long - - ' This function is a shortcut wrapper for FreeImage_CreateTagEx() and - ' FreeImage_SetMetadataEx(). It creates a new tag as FreeImage_CreateTagEx() does - ' and appends it to the image's metadata model. - - ' The parameter 'Bitmap' specifies the image, the new tag should be appended to, - ' parameters 'Model', 'Key', 'TagType', 'Value', 'Count' and 'Id' are these, - ' FreeImage_CreateTagEx() has and are just forwarded unchanged. - - ' The boolean parameter 'OverwriteExisting' determines, whether to overwrite or - ' replace an already existing tag with the newly created. If the tag specified - ' by it's model and key already exists and 'OverwriteExisting' is False, an - ' empty FREE_IMAGE_TAG structure is returned. - - ' So, as with FreeImage_CreateTagEx(), the caller should check the returned - ' FREE_IMAGE_TAG structure's 'TagPtr' member. If this function succeeded, the - ' 'TagPtr' member is non zero. A value of zero indicates an error condition - ' sourced from either the FreeImage_CreateTag() function or may result from - ' an already existing tag that should not be overwritten. - - If ((FreeImage_GetMetadataInt(Model, Bitmap, Key, lpTag) = 0) Or _ - (OverwriteExisting)) Then - - FreeImage_AppendTag = FreeImage_CreateTagEx(Model, Key, TagType, Value, Count, Id) - If (FreeImage_AppendTag.TagPtr <> 0) Then - Call FreeImage_SetMetadataEx(Bitmap, FreeImage_AppendTag, Key, Model, True) - End If - End If - -End Function - -Public Function FreeImage_RemoveTag(ByVal Bitmap As Long, _ - ByVal Model As FREE_IMAGE_MDMODEL, _ - ByVal Key As String) As Boolean - - ' This function is a wrapper function, that removes a tag, that is actually - ' part of an image's metadata model. The tag named 'key' of the metadata - ' model specified in parameter 'Model' of the image 'Bitmap' will be removed. - - ' Removing a tag is actually done by calling FreeImage_SetMetadata() with - ' a NULL pointer for 'FITAG *tag' as described in the API documentation. - - ' The function returns the boolean value returned from FreeImage_SetMetadata(), - ' which is always TRUE when removing a tag in this fashion. So, this function's - ' caller has no feedback telling if the tag was really present and removed - ' successfully. - - ' Up to version 3.9.1 of FreeImage, there seems to be a bug in removing an - ' tag from an image's metadata model. Although the removed tag is not accessible - ' through FreeImage_GetMetadata() any more, iterations with - ' Freeimage_FindFirst/NextMetadata() will still return this tag an a NULL - ' pointer. - - ' This bug was reported on the Developers Forum. You can revisit the posting at: - ' http://sourceforge.net/forum/forum.php?thread_id=1536883&forum_id=36111 - - FreeImage_RemoveTag = (FreeImage_SetMetadataInt(Model, Bitmap, Key, 0) <> 0) - -End Function - -Public Function FreeImage_RemoveTagEx(ByVal Bitmap As Long, _ - ByRef Tag As FREE_IMAGE_TAG) As Boolean - - ' This function is a FREE_IMAGE_TAG based wrapper for FreeImage_RemoveTag() - - With Tag - FreeImage_RemoveTagEx = FreeImage_RemoveTag(Bitmap, .Model, .Key) - End With - -End Function - -Public Function FreeImage_TagExists(ByVal Bitmap As Long, _ - ByVal Model As FREE_IMAGE_MDMODEL, _ - Optional ByVal Key As String) As Boolean - -Dim lpTag As Long - - ' This function is a small helper function, returning a boolean value - ' that determines, whether a certain tag specified by metadata model - ' and key exists for an image specified by 'Bitmap'. - - FreeImage_TagExists = (FreeImage_GetMetadataInt(Model, Bitmap, Key, lpTag) <> 0) - -End Function - -Public Function FreeImage_TagExistsEx(ByVal Bitmap As Long, _ - ByRef Tag As FREE_IMAGE_TAG) As Boolean - - ' This function is a FREE_IMAGE_TAG based wrapper for FreeImage_TagExists() - - With Tag - FreeImage_TagExistsEx = FreeImage_TagExists(Bitmap, .Model, .Key) - End With - -End Function - -Public Sub FreeImage_DeleteTagEx(ByRef Tag As FREE_IMAGE_TAG) - - ' This function is a wrapper for FreeImage_DeleteTag() working with - ' the VB friendly FREE_IMAGE_TAG structure. So, the parameter 'Tag' - ' is not a pointer to a FITAG structure but a FREE_IMAGE_TAG structure. - - ' This function deletes the underlaying FreeImage FITAG structure, - ' specified the the member 'TagPtr' of the FREE_IMAGE_TAG structure - ' and also sets all other members of Tag to a null value. - - ' Do not get confused with the wrapper functions FreeImage_RemoveTag() - ' and FreeImage_RemoveTagEx(). These functions remove a tag from an - ' image's metadata model. This function only deletes of frees (a better - ' name would be 'FreeImage_FreeTag') a tag created with - ' FreeImage_CreateTagEx(). Do not delete any tags obtained from any other - ' function. - - With Tag - If (.TagPtr <> 0) Then - Call FreeImage_DeleteTag(.TagPtr) - End If - .TagPtr = 0 - .Count = 0 - .Description = vbNullString - .Id = 0 - .Key = vbNullString - .Length = 0 - .Model = FIMD_NODATA - Erase .Palette - Erase .RationalValue - .StringValue = vbNullString - .Type = FIDT_NOTYPE - .Value = Empty - End With - -End Sub - -Public Function FreeImage_CloneTagEx(ByRef Tag As FREE_IMAGE_TAG, _ - Optional ByVal Model As FREE_IMAGE_MDMODEL = FIMD_NODATA) As FREE_IMAGE_TAG - - ' This function is a thin wrapper for FreeImage_CloneTag() working with - ' the VB friendly FREE_IMAGE_TAG structure. The parameter 'Tag' works - ' according to the FreeImage API documentation expect that Tag is not a - ' pointer to a FITAG structure but a FREE_IMAGE_TAG structure. - - ' The additional optional paremeter 'Model' is needed, since the - ' transformation from a FreeImage FITAG structure to the VB friendly - ' FREE_IMAGE_TAG structure always need the model to be specified. - ' When 'Model' is missing (equal to FREE_IMAGE_TAG), the model to be - ' used is taken from the Tag's member 'Model' itself. - - ' See function FreeImage_FindNextMetadataEx() to learn more about the - ' optional parameter 'Model' - - ' Tags obtained from FreeImage_CloneTagEx() must be deleted with - ' FreeImage_DeleteTagEx() as long as they are not used with - ' FreeImage_SetMetadataEx() with the parameter 'RefreshTag' set to True. - - If (Tag.TagPtr <> 0) Then - If (Model = FIMD_NODATA) Then - Model = Tag.Model - End If - FreeImage_CloneTagEx = pGetTagFromTagPtr(Model, FreeImage_CloneTag(Tag.TagPtr)) - End If - -End Function - -Public Function FreeImage_RemoveMetadataModel(ByVal Bitmap As Long, _ - ByVal Model As FREE_IMAGE_MDMODEL) As Boolean - - ' This function removes a complete metadata model 'Model' from an image specified - ' by 'Bitmap'. - - If (Model <> FIMD_NODATA) Then - FreeImage_RemoveMetadataModel = (FreeImage_SetMetadataInt(Model, Bitmap, vbNullString, 0) <> 0) - End If - -End Function - -Public Function FreeImage_FindFirstMetadataEx(ByVal Model As FREE_IMAGE_MDMODEL, _ - ByVal Bitmap As Long, _ - ByRef Tag As FREE_IMAGE_TAG) As Long - - ' This function is a wrapper for FreeImage_FindFirstMetadata() working with - ' the VB friendly FREE_IMAGE_TAG structure. All parameters 'Bitmap', 'Tag', - ' and 'Model' as the function's return value work according to the - ' FreeImage API documentation expect that Tag is not a pointer to a FITAG - ' structure but a FREE_IMAGE_TAG structure. - - ' Tags obtained from FreeImage_GetMetadataEx() must not be deleted with - ' FreeImage_DeleteTagEx(). - - With Tag - FreeImage_FindFirstMetadataEx = FreeImage_FindFirstMetadata(Model, Bitmap, .TagPtr) - If (FreeImage_FindFirstMetadataEx <> 0) Then - Tag = pGetTagFromTagPtr(Model, .TagPtr) - End If - End With - -End Function - -Public Function FreeImage_FindNextMetadataEx(ByVal hFind As Long, _ - ByRef Tag As FREE_IMAGE_TAG, _ - Optional ByVal Model As FREE_IMAGE_MDMODEL = FIMD_NODATA) As Boolean - - ' This function is a wrapper for FreeImage_FindNextMetadataEx() working with - ' the VB friendly FREE_IMAGE_TAG structure. All parameters 'hFind' and 'Tag' - ' as the function's return value work according to the FreeImage API - ' documentation expect that Tag is not a pointer to a FITAG structure but a - ' FREE_IMAGE_TAG structure. - - ' The additional optional paremeter 'Model' is needed, since the VB friendly - ' FREE_IMAGE_TAG structure also contains the member 'StringValue'. This member - ' is filled with the result of FreeImage_TagToString() which always needs - ' the model to be specified. Since there should be no static oder global - ' variables id the FreeImage VB wrapper, the model must be known each time - ' a FreeImage FITAG structure is converted to a FREE_IMAGE_TAG structure. - ' (A global VB collection could be used to map the hFind to the model, - ' but we don't want any globals here) - - ' So, when 'Model' is missing (equal to FREE_IMAGE_TAG), the model to be used - ' is taken from the Tag's member 'Model' itself. This is useful when using this - ' function in a loop iterating all tags per model (what else would you do - ' with that function?). The Tag's member 'Model' is populated by - ' FreeImage_FindFirstMetadataEx() and remains valid during the whole loop, ready - ' to be used in this function. - - ' Tags obtained from FreeImage_GetMetadataEx() must not be deleted with - ' FreeImage_DeleteTagEx(). - - With Tag - FreeImage_FindNextMetadataEx = (FreeImage_FindNextMetadataInt(hFind, .TagPtr) <> 0) - If (FreeImage_FindNextMetadataEx) Then - If (Model = FIMD_NODATA) Then - Model = .Model - End If - Tag = pGetTagFromTagPtr(Model, .TagPtr) - End If - End With - -End Function - -Public Function FreeImage_GetAllMetadataTags(ByVal Model As FREE_IMAGE_MDMODEL, _ - ByVal Bitmap As Long, _ - ByRef Tag() As FREE_IMAGE_TAG) As Long - -Dim hMD As Long -Dim lpTag As Long -Dim i As Long - - ' This function is a helper function returning (through a ByRef parameter) - ' an array of FREE_IMAGE_TAG structures containing all the image's tags of - ' the metadata model specified by the 'Model' parameter. - - ' The parameter 'Tag()' must be an redimensionable array of FREE_IMAGE_TAG - ' and is redimensioned accordingly. The function returns the number of - ' tags stored in 'Tag()'. - - ' All tags obtained from FreeImage_GetAllMetadataTags() must not be deleted - ' with FreeImage_DeleteTagEx(). - - i = FreeImage_GetMetadataCount(Model, Bitmap) - If (i > 0) Then - ReDim Tag(i - 1) - FreeImage_GetAllMetadataTags = i - i = 0 - hMD = FreeImage_FindFirstMetadata(Model, Bitmap, lpTag) - If (hMD <> 0) Then - Do - Tag(i) = pGetTagFromTagPtr(Model, lpTag) - i = i + 1 - Loop While (FreeImage_FindNextMetadataInt(hMD, lpTag) <> 0) - Call FreeImage_FindCloseMetadata(hMD) - End If - End If - -End Function - -Public Function FreeImage_GetMetadataEx(ByVal Model As FREE_IMAGE_MDMODEL, _ - ByVal Bitmap As Long, _ - ByVal Key As String, _ - ByRef Tag As FREE_IMAGE_TAG) As Boolean - - ' This function is a wrapper for FreeImage_GetMetadata() working with - ' the VB friendly FREE_IMAGE_TAG structure. All parameters 'Bitmap', 'Tag', - ' 'Key' and 'Model' as well as the function's return value work according - ' to the FreeImage API documentation expect that Tag is not a pointer to - ' a FITAG structure but to a FREE_IMAGE_TAG structure. - - ' Tags obtained from FreeImage_GetMetadataEx() must not be deleted with - ' FreeImage_DeleteTagEx(). - - With Tag - If (FreeImage_GetMetadataInt(Model, Bitmap, Key, .TagPtr) <> 0) Then - Tag = pGetTagFromTagPtr(Model, .TagPtr) - FreeImage_GetMetadataEx = True - End If - End With - -End Function - -Public Function FreeImage_SetMetadataEx(ByVal Bitmap As Long, _ - ByRef Tag As FREE_IMAGE_TAG, _ - Optional ByVal Key As String, _ - Optional ByVal Model As FREE_IMAGE_MDMODEL = FIMD_NODATA, _ - Optional ByVal RefreshTag As Boolean) As Boolean - - ' This function is a wrapper for FreeImage_SetMetadata() using the wrapper's - ' VB friendly FREE_IMAGE_TAG structure as an replacement for the original - ' function's pointer to a FITAG structure. - - ' All parameters 'Bitmap', 'Tag', 'Key' and 'Model' as the function's return value - ' work according to the FreeImage API documentation expect that Tag is not a - ' pointer to a FITAG structure but a FREE_IMAGE_TAG structure. - - ' As with FreeImage_SetMetadata(), this function sould only be called with - ' new tags, created with FreeImage_CreateTagEx(), a wrapper function for - ' FreeImage_CreateTag() working with the VB friendly FREE_IMAGE_TAG structure. - - ' Normally, after a newly created tag must be deleted/freed with a call to - ' FreeImage_DeleteTagEx(), a wrapper function for FreeImage_DeleteTag() working - ' with the VB friendly FREE_IMAGE_TAG structure (bored already?), after - ' the tag was appended to an image's metadata model with - ' FreeImage_SetMetadataEx(). But... - - ' There is a wrapper specific additional boolean parameter 'RefreshTag', that - ' is similar to the parameter 'UnloadSource' found in many wrapper functions. - ' When 'RefreshTag' is True upon entry, the tag specified in the 'Tag' - ' parameter is deleted (the underlaying FITAG structure is deleted with - ' FreeImage_DeteleTag() and all other members of the FREE_IMAGE_TAG structure - ' are set to null values) and is reassigned with the tag, that is now part - ' of the image's metadata model. The tag now referenced in the 'Tag' - ' parameter must NOT be deleted any more by the caller of this function, since - ' this tag refers to the actual tag data stored with the image. This is like - ' a FREE_IMAGE_TAG structure obtained from FreeImage_GetMetadata() or - ' FreeImage_FindFirst/NextMetadata(). Any changes made to this FREE_IMAGE_TAG - ' structure may be applied to the image with a later call to - ' FreeImage_UpdateMetadata(). - - - With Tag - If (Model = FIMD_NODATA) Then - Model = .Model - End If - If (LenB(Key) = 0) Then - Key = .Key - End If - If (FreeImage_SetMetadataInt(Model, Bitmap, Key, .TagPtr) <> 0) Then - FreeImage_SetMetadataEx = True - End If - If (RefreshTag) Then - Call FreeImage_DeleteTagEx(Tag) - Call FreeImage_GetMetadataEx(Model, Bitmap, Key, Tag) - End If - End With - -End Function - -Public Function FreeImage_GetImageComment(ByVal Bitmap As Long) As String - -Dim tTag As FREE_IMAGE_TAG - - ' This function is a small wrapper around FreeImage_GetMetadata() that - ' returns the comment of a JPEG, PNG of GIF image. - - If (FreeImage_GetMetadataEx(FIMD_COMMENTS, Bitmap, "Comment", tTag)) Then - FreeImage_GetImageComment = tTag.Value - End If - -End Function - -Public Function FreeImage_SetImageComment(ByVal Bitmap As Long, _ - Optional ByVal Comment As String) As Boolean - -Dim tTag As FREE_IMAGE_TAG - - ' This function is a small wrapper around FreeImage_SetMetadata() that - ' sets the comment of a JPEG, PNG of GIF image. - - If (LenB(Comment) > 0) Then - tTag = FreeImage_AppendTag(Bitmap, FIMD_COMMENTS, "Comment", FIDT_ASCII, Comment) - FreeImage_SetImageComment = (tTag.TagPtr <> 0) - Else - Call FreeImage_RemoveMetadataModel(Bitmap, FIMD_COMMENTS) - FreeImage_SetImageComment = True - End If - -End Function - -Public Function FreeImage_CopyMetadata(ByVal BitmapSrc As Long, _ - ByVal BitmapDst As Long, _ - Optional ByVal ReplaceExisting As Boolean = True, _ - Optional ByVal Model As FREE_IMAGE_MDMODEL = FIMD_NODATA) As Long - -Dim hMDFind As Long -Dim lpTag As Long -Dim strKey As String -Dim bSetTag As Boolean - - ' This derived helper function copies several metadata tags from one - ' image to another. This is useful when cloning images explicitly with - ' FreeImage_Clone() or implicitly with FreeImage_ConvertColorDepth() or - ' with any of the FreeImage_RescaleXXX() functions. Whenever the "same" - ' image is represented by a new 'Bitmap' pointer, the image was internally - ' recreated. All of the data, associated with the image, like metadata, - ' DPI settings or ICC profiles are no more available in the new version of - ' the image. - - ' Setting the DPI for X and Y direction is quite easy with the wrapper - ' functions FreeImage_Get/SetResolutionX/Y(). This function makes it even - ' easier to keep track of all associated metadata tags for a cloned image! - - ' Both parameters 'BitmapSrc' and 'BitmapDst' specify the source and destination - ' image. Metadata is copied from 'BitmapSrc' to 'BitmapDst'. - - ' The optional parameter 'ReplaceExisting' determines whether existing tags - ' should be replaced or not. If there are no tags in 'BitmapDst' it is recommended, - ' to set 'ReplaceExisting' to True (or to omit it, since True is it's default - ' value) for better performance; when set to True, no tests for tag existence - ' in the destination image will be run. - - ' The optional parameter 'Model' may specify a certain metadata model to be - ' copied. If this parameter is omitted or set to any value not defined in the - ' FREE_IMAGE_MDMODEL enumeration, all metadata models will be copied - ' sequentially. - - ' This function returns the number of tags copied or zero when there are no tags - ' in the source image or an error occured. - - ' For the standard use case described above (keeping track of all metadata after - ' an image was cloned) the calling this function boils down to a very short form: - - ' lTagsCopied = FreeImage_CopyMetadata(hDibSrc, hDibDst) - - If ((BitmapSrc <> 0) And (BitmapDst <> 0)) Then - If ((Model >= FIMD_COMMENTS) And (Model <= FIMD_CUSTOM)) Then - hMDFind = FreeImage_FindFirstMetadata(Model, BitmapSrc, lpTag) - If (hMDFind) Then - Do - strKey = pGetStringFromPointerA(deref(deref(lpTag))) - bSetTag = ReplaceExisting - If (Not bSetTag) Then - bSetTag = (Not FreeImage_TagExists(BitmapDst, Model, strKey)) - End If - If (bSetTag) Then - If (FreeImage_SetMetadataInt(Model, BitmapDst, strKey, lpTag) <> 0) Then - FreeImage_CopyMetadata = FreeImage_CopyMetadata + 1 - End If - End If - Loop While (FreeImage_FindNextMetadata(hMDFind, lpTag)) - Call FreeImage_FindCloseMetadata(hMDFind) - End If - Else - For Model = FIMD_COMMENTS To FIMD_CUSTOM - FreeImage_CopyMetadata = FreeImage_CopyMetadata _ - + FreeImage_CopyMetadata(BitmapSrc, BitmapDst, _ - ReplaceExisting, Model) - Next Model - End If - End If - -End Function - -Public Function FreeImage_CloneMetadataEx(ByVal BitmapSrc As Long, _ - ByVal BitmapDst As Long, _ - Optional ByVal Model As FREE_IMAGE_MDMODEL = FIMD_NODATA) As Long - - ' This derived helper function copies several metadata tags from one - ' image to another. It is very similar to FreeImage_CopyMetadata(). - - ' The main difference is, that this function aims to create exactly the same - ' metadata layout in the destination image. In contrast to - ' FreeImage_CopyMetadata(), this function removes all metadata tags in the - ' desination image that are not part of the metadata set in the source image. - ' So, this function is particularly useful for destination images that may - ' have already some tags associated and you want to make shure, that it will - ' get exactly the same metadata set as the source image. - - ' This function will most likely be used in a end user application and should - ' be invoked through a menu command called: "Set/Apply Metadata From Source Image..." - - ' This function returns the number of tags copied or zero if there are no tags - ' in the source image or an error occured. - - If ((BitmapSrc <> 0) And (BitmapDst <> 0)) Then - If ((Model >= FIMD_COMMENTS) And (Model <= FIMD_CUSTOM)) Then - If (FreeImage_RemoveMetadataModel(BitmapDst, Model)) Then - FreeImage_CloneMetadataEx = FreeImage_CopyMetadata(BitmapSrc, BitmapDst, _ - True, Model) - End If - Else - For Model = FIMD_COMMENTS To FIMD_CUSTOM - FreeImage_CloneMetadataEx = FreeImage_CloneMetadataEx _ - + FreeImage_CloneMetadataEx(BitmapSrc, BitmapDst, _ - Model) - Next Model - End If - End If - -End Function - -Public Function FreeImage_TagFromPointer(ByVal Model As FREE_IMAGE_MDMODEL, _ - ByVal Tag As Long) As FREE_IMAGE_TAG - - ' This is a generic function that returns a VB wrapper Tag - ' structure (FREE_IMAGE_TAG) from a FreeImage FITAG *tag pointer. - - ' This function is still public due to legacy reasons. Since there are - ' functions like 'FreeImage_GetMetadataEx()', 'FreeImage_GetAllMetadataTags()' - ' or 'FreeImage_FindFirst/NextMetadataEx()', this function won't be needed - ' any more in most cases. - - FreeImage_TagFromPointer = pGetTagFromTagPtr(Model, Tag) - -End Function - -Public Function FreeImage_UpdateMetadata(ByRef Tag As FREE_IMAGE_TAG) As Boolean - - ' This function updates any changes made in a FREE_IMAGE_TAG - ' structure. - - FreeImage_UpdateMetadata = pTagToTagPtr(Tag) - -End Function - -Public Function FreeImage_UnsignedLong(ByVal Value As Long) As Variant - - ' This function converts a signed long (VB's Long data type) into - ' an unsigned long (not really supported by VB). - - ' Basically, this function checks, whether the positive range of - ' a signed long is sufficient to hold the value (indeed, it checks - ' the value since the range is obviously constant). If yes, - ' it returns a Variant with subtype Long ('Variant/Long' in VB's - ' watch window). In this case, the function did not make any real - ' changes at all. If not, the value is stored in a Currency variable, - ' which is able to store the whole range of an unsigned long. Then, - ' the function returns a Variant with subtype Currency - ' ('Variant/Currency' in VB's watch window). - - If (Value < 0) Then - Dim curTemp As Currency - Call CopyMemory(curTemp, Value, 4) - FreeImage_UnsignedLong = curTemp * 10000 - Else - FreeImage_UnsignedLong = Value - End If - -End Function - -Public Function FreeImage_UnsignedShort(ByVal Value As Integer) As Variant - - ' This function converts a signed short (VB's Integer data type) into - ' an unsigned short (not really supported by VB). - - ' Basically, this function checks, whether the positive range of - ' a signed short is sufficient to hold the value (indeed, it checks - ' the value since the range is obviously constant). If yes, - ' it returns a Variant with subtype Integer ('Variant/Integer' in VB's - ' watch window). In this case, the function did not make any real - ' changes at all. If not, the value is stored in a Long variable, - ' which is able to store the whole range of an unsigned short. Then, - ' the function returns a Variant with subtype Long - ' ('Variant/Long' in VB's watch window). - - If (Value < 0) Then - Dim lTemp As Long - Call CopyMemory(lTemp, Value, 2) - FreeImage_UnsignedShort = lTemp - Else - FreeImage_UnsignedShort = Value - End If - -End Function - -Public Function FreeImage_CreateRational(ByRef Numerator As Variant, _ - ByRef Denominator As Variant, _ - Optional ByVal NormalizeValue As Boolean = True) As FIRATIONAL - - ' This function creates an unsigned rational (FIDT_RATIONAL) value to be used with - ' FreeImage's metadata models. In the VB wrapper, any rational value is stored in a - ' structure (FIRATIONAL), containing both 'Numerator' and 'Denominator' members. The - ' rational's value is then defined as the fraction Numerator/Denominator. - - ' Both values 'Numerator' and 'Denominator' are actually ULONGs (unsigned longs), a - ' data type not supported by VB (a VB Long variable is always signed). Therefore, - ' 'Numerator' and 'Denominator' are typed as Variant. Whenever the range of a signed - ' long is sufficient to store the value (all values between 0 and 0x7FFFFFFF - ' (2147483647 decimal)), the Variant gets a Long subtype. If not, a Currency subtype is - ' used just to give you the mathematical correct value of the unsigned long. - - ' The optional parameter 'NormalizeValue' controls, whether the resulting fraction - ' should be normalized (cancelled down) or not. - - ' When calling this function, you can use hexadecimal constants for passing unsinged - ' longs via the parameters 'Numerator' and 'Denominator'. - - ' 2147483647 - ' Example: tRational = FreeImage_CreateRational(&HFFFFFFFF, 12345) -> ---------- - ' 12345 - - With FreeImage_CreateRational - .Numerator = FreeImage_UnsignedLong(Numerator) - .Denominator = FreeImage_UnsignedLong(Denominator) - End With - - If (NormalizeValue) Then - Call pNormalizeRational(FreeImage_CreateRational) - End If - -End Function - -Public Function FreeImage_CreateSignedRational(ByRef Numerator As Variant, _ - ByRef Denominator As Variant, _ - Optional ByVal NormalizeValue As Boolean = True) As FIRATIONAL - - ' This function creates a signed rational (FIDT_RATIONAL) value to be used with - ' FreeImage's metadata models. In the VB wrapper, any rational value is stored in a - ' structure (FIRATIONAL), containing both 'Numerator' and 'Denominator' members. The - ' rational's value is then defined as the fraction Numerator/Denominator. - - ' Both values 'Numerator' and 'Denominator' are actually LONGs (signed longs), the - ' same data type as a VB Long. Since, 'Numerator' and 'Denominator' are typed as - ' Variant, all possible values between -2,147,483,648 and + 2,147,483,647 are stored - ' in a Variant with subtype Long (cp. 'FreeImage_CreateRational()'). - - ' The optional parameter 'NormalizeValue' controls, whether the resulting fraction - ' should be normalized (cancelled down) or not. - - ' When calling this function, you can use hexadecimal constants for passing unsinged - ' longs via the parameters 'Numerator' and 'Denominator'. - - ' -1 1 - ' Example: tRational = FreeImage_CreateSignedRational(&HFFFFFFFF, 12345) -> ----- = - ----- - ' 12345 12345 - - With FreeImage_CreateSignedRational - .Numerator = CLng(Numerator) - .Denominator = CLng(Denominator) - End With - - If (NormalizeValue) Then - Call pNormalizeSRational(FreeImage_CreateSignedRational) - End If - -End Function - - - -'-------------------------------------------------------------------------------- -' Derived and hopefully useful functions -'-------------------------------------------------------------------------------- - -' Plugin and filename functions - -Public Function FreeImage_IsExtensionValidForFIF(ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Extension As String, _ - Optional ByVal Compare As VbCompareMethod = vbBinaryCompare) As Boolean - - ' This function tests, whether a given filename extension is valid - ' for a certain image format (fif). - - FreeImage_IsExtensionValidForFIF = (InStr(1, _ - FreeImage_GetFIFExtensionList(Format) & ",", _ - Extension & ",", _ - Compare) > 0) - -End Function - -Public Function FreeImage_IsFilenameValidForFIF(ByVal Format As FREE_IMAGE_FORMAT, _ - ByVal Filename As String, _ - Optional ByVal Compare As VbCompareMethod = vbBinaryCompare) As Boolean - -Dim strExtension As String -Dim i As Long - - ' This function tests, whether a given complete filename is valid - ' for a certain image format (fif). - - i = InStrRev(Filename, ".") - If (i > 0) Then - strExtension = Mid$(Filename, i + 1) - FreeImage_IsFilenameValidForFIF = (InStr(1, _ - FreeImage_GetFIFExtensionList(Format) & ",", _ - strExtension & ",", _ - Compare) > 0) - End If - -End Function - -Public Function FreeImage_GetPrimaryExtensionFromFIF(ByVal Format As FREE_IMAGE_FORMAT) As String - -Dim strExtensionList As String -Dim i As Long - - ' This function returns the primary (main or most commonly used?) extension - ' of a certain image format (fif). This is done by returning the first of - ' all possible extensions returned by FreeImage_GetFIFExtensionList(). That - ' assumes, that the plugin returns the extensions in ordered form. If not, - ' in most cases it is even enough, to receive any extension. - - ' This function is primarily used by the function 'SavePictureEx'. - - strExtensionList = FreeImage_GetFIFExtensionList(Format) - i = InStr(strExtensionList, ",") - If (i > 0) Then - FreeImage_GetPrimaryExtensionFromFIF = Left$(strExtensionList, i - 1) - Else - FreeImage_GetPrimaryExtensionFromFIF = strExtensionList - End If - -End Function - -Public Function FreeImage_IsGreyscaleImage(ByVal Bitmap As Long) As Boolean - -Dim atRGB() As RGBQUAD -Dim i As Long - - ' This function returns a boolean value that is true, if the DIB is actually - ' a greyscale image. Here, the only test condition is, that each palette - ' entry must be a grey value, what means that each color component has the - ' same value (red = green = blue). - - ' The FreeImage libraray doesn't offer a function to determine if a DIB is - ' greyscale. The only thing you can do is to use the 'FreeImage_GetColorType' - ' function, that returns either FIC_MINISWHITE or FIC_MINISBLACK for - ' greyscale images. However, a DIB needs to have a ordered greyscale palette - ' (linear ramp or inverse linear ramp) to be judged as FIC_MINISWHITE or - ' FIC_MINISBLACK. DIB's with an unordered palette that are actually (visually) - ' greyscale, are said to be (color-)palletized. That's also true for any 4 bpp - ' image, since it will never have a palette that satifies the tests done - ' in the 'FreeImage_GetColorType' function. - - ' So, there is a chance to omit some color depth conversions, when displaying - ' an image in greyscale fashion. Maybe the problem will be solved in the - ' FreeImage library one day. - - Select Case FreeImage_GetBPP(Bitmap) - - Case 1, 4, 8 - atRGB = FreeImage_GetPaletteEx(Bitmap) - FreeImage_IsGreyscaleImage = True - For i = 0 To UBound(atRGB) - With atRGB(i) - If ((.rgbRed <> .rgbGreen) Or (.rgbRed <> .rgbBlue)) Then - FreeImage_IsGreyscaleImage = False - Exit For - End If - End With - Next i - - End Select - -End Function - -' Bitmap resolution functions - -Public Function FreeImage_GetResolutionX(ByVal Bitmap As Long) As Long - - ' This function gets a DIB's resolution in X-direction measured - ' in 'dots per inch' (DPI) and not in 'dots per meter'. - - FreeImage_GetResolutionX = Int(0.5 + 0.0254 * FreeImage_GetDotsPerMeterX(Bitmap)) - -End Function - -Public Sub FreeImage_SetResolutionX(ByVal Bitmap As Long, ByVal Resolution As Long) - - ' This function sets a DIB's resolution in X-direction measured - ' in 'dots per inch' (DPI) and not in 'dots per meter'. - - Call FreeImage_SetDotsPerMeterX(Bitmap, Int(Resolution / 0.0254 + 0.5)) - -End Sub - -Public Function FreeImage_GetResolutionY(ByVal Bitmap As Long) As Long - - ' This function gets a DIB's resolution in Y-direction measured - ' in 'dots per inch' (DPI) and not in 'dots per meter'. - - FreeImage_GetResolutionY = Int(0.5 + 0.0254 * FreeImage_GetDotsPerMeterY(Bitmap)) - -End Function - -Public Sub FreeImage_SetResolutionY(ByVal Bitmap As Long, ByVal Resolution As Long) - - ' This function sets a DIB's resolution in Y-direction measured - ' in 'dots per inch' (DPI) and not in 'dots per meter'. - - Call FreeImage_SetDotsPerMeterY(Bitmap, Int(Resolution / 0.0254 + 0.5)) - -End Sub - -' ICC Color Profile functions - -Public Function FreeImage_GetICCProfile(ByVal Bitmap As Long) As FIICCPROFILE - - ' This function is a wrapper for the FreeImage_GetICCProfile() function, returning - ' a real FIICCPROFILE structure. - - ' Since the original FreeImage function returns a pointer to the FIICCPROFILE - ' structure (FIICCPROFILE *), as with string returning functions, this wrapper is - ' needed as VB can't declare a function returning a pointer to anything. So, - ' analogous to string returning functions, FreeImage_GetICCProfile() is declared - ' private as FreeImage_GetICCProfileInt() and made publicly available with this - ' wrapper function. - - Call CopyMemory(FreeImage_GetICCProfile, _ - ByVal FreeImage_GetICCProfileInt(Bitmap), _ - LenB(FreeImage_GetICCProfile)) - -End Function - -Public Function FreeImage_GetICCProfileColorModel(ByVal Bitmap As Long) As FREE_IMAGE_ICC_COLOR_MODEL - - ' This function is a thin wrapper around FreeImage_GetICCProfile() returning - ' the color model in which the ICC color profile data is in, if there is actually - ' a ICC color profile available for the Bitmap specified. - - ' If there is NO color profile along with that bitmap, this function returns the color - ' model that should (or must) be used for any color profile data to be assigned to the - ' Bitmap. That depends on the bitmap's color type. - - If (FreeImage_HasICCProfile(Bitmap)) Then - FreeImage_GetICCProfileColorModel = (deref(FreeImage_GetICCProfileInt(Bitmap)) _ - And FREE_IMAGE_ICC_COLOR_MODEL_MASK) - Else - ' use FreeImage_GetColorType() to determine, whether this is a CMYK bitmap or not - If (FreeImage_GetColorType(Bitmap) = FIC_CMYK) Then - FreeImage_GetICCProfileColorModel = FIICC_COLOR_MODEL_CMYK - Else - FreeImage_GetICCProfileColorModel = FIICC_COLOR_MODEL_RGB - End If - End If - -End Function - -Public Function FreeImage_GetICCProfileSize(ByVal Bitmap As Long) As Long - - ' This function is a thin wrapper around FreeImage_GetICCProfile() returning - ' only the size in bytes of the ICC profile data for the Bitmap specified or zero, - ' if there is no ICC profile data for the Bitmap. - - FreeImage_GetICCProfileSize = deref(FreeImage_GetICCProfileInt(Bitmap) + 4) - -End Function - -Public Function FreeImage_GetICCProfileDataPointer(ByVal Bitmap As Long) As Long - - ' This function is a thin wrapper around FreeImage_GetICCProfile() returning - ' only the pointer (the address) of the ICC profile data for the Bitmap specified, - ' or zero if there is no ICC profile data for the Bitmap. - - FreeImage_GetICCProfileDataPointer = deref(FreeImage_GetICCProfileInt(Bitmap) + 8) - -End Function - -Public Function FreeImage_HasICCProfile(ByVal Bitmap As Long) As Boolean - - ' This function is a thin wrapper around FreeImage_GetICCProfile() returning - ' True, if there is an ICC color profile available for the Bitmap specified or - ' returns False otherwise. - - FreeImage_HasICCProfile = (FreeImage_GetICCProfileSize(Bitmap) <> 0) - -End Function - -' Bitmap Info functions - -Public Function FreeImage_GetInfoHeaderEx(ByVal Bitmap As Long) As BITMAPINFOHEADER - -Dim lpInfoHeader As Long - - ' This function is a wrapper around FreeImage_GetInfoHeader() and returns a fully - ' populated BITMAPINFOHEADER structure for a given bitmap. - - lpInfoHeader = FreeImage_GetInfoHeader(Bitmap) - If (lpInfoHeader) Then - Call CopyMemory(FreeImage_GetInfoHeaderEx, ByVal lpInfoHeader, LenB(FreeImage_GetInfoHeaderEx)) - End If - -End Function - -' Image color depth conversion wrapper - -Public Function FreeImage_ConvertColorDepth(ByVal Bitmap As Long, _ - ByVal Conversion As FREE_IMAGE_CONVERSION_FLAGS, _ - Optional ByVal UnloadSource As Boolean, _ - Optional ByVal Threshold As Byte = 128, _ - Optional ByVal DitherMethod As FREE_IMAGE_DITHER = FID_FS, _ - Optional ByVal QuantizeMethod As FREE_IMAGE_QUANTIZE = FIQ_WUQUANT) As Long - -Dim hDIBNew As Long -Dim hDIBTemp As Long -Dim lBPP As Long -Dim bForceLinearRamp As Boolean -Dim lpReservePalette As Long -Dim bAdjustReservePaletteSize As Boolean - - ' This function is an easy-to-use wrapper for color depth conversion, intended - ' to work around some tweaks in the FreeImage library. - - ' The parameters 'Threshold' and 'eDitherMode' control how thresholding or - ' dithering are performed. The 'QuantizeMethod' parameter determines, what - ' quantization algorithm will be used when converting to 8 bit color images. - - ' The 'Conversion' parameter, which can contain a single value or an OR'ed - ' combination of some of the FREE_IMAGE_CONVERSION_FLAGS enumeration values, - ' determines the desired output image format. - - ' The optional 'UnloadSource' parameter is for unloading the original image, so - ' you can "change" an image with this function rather than getting a new DIB - ' pointer. There is no more need for a second DIB variable at the caller's site. - - bForceLinearRamp = ((Conversion And FICF_REORDER_GREYSCALE_PALETTE) = 0) - lBPP = FreeImage_GetBPP(Bitmap) - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to convert a 'header-only' bitmap.") - End If - - Select Case (Conversion And (Not FICF_REORDER_GREYSCALE_PALETTE)) - - Case FICF_MONOCHROME_THRESHOLD - If (lBPP > 1) Then - hDIBNew = FreeImage_Threshold(Bitmap, Threshold) - End If - - Case FICF_MONOCHROME_DITHER - If (lBPP > 1) Then - hDIBNew = FreeImage_Dither(Bitmap, DitherMethod) - End If - - Case FICF_GREYSCALE_4BPP - If (lBPP <> 4) Then - ' If the color depth is 1 bpp and the we don't have a linear ramp palette - ' the bitmap is first converted to an 8 bpp greyscale bitmap with a linear - ' ramp palette and then to 4 bpp. - If ((lBPP = 1) And (FreeImage_GetColorType(Bitmap) = FIC_PALETTE)) Then - hDIBTemp = Bitmap - Bitmap = FreeImage_ConvertToGreyscale(Bitmap) - Call FreeImage_Unload(hDIBTemp) - End If - hDIBNew = FreeImage_ConvertTo4Bits(Bitmap) - Else - ' The bitmap is already 4 bpp but may not have a linear ramp. - ' If we force a linear ramp the bitmap is converted to 8 bpp with a linear ramp - ' and then back to 4 bpp. - If (((Not bForceLinearRamp) And (Not FreeImage_IsGreyscaleImage(Bitmap))) Or _ - (bForceLinearRamp And (FreeImage_GetColorType(Bitmap) = FIC_PALETTE))) Then - hDIBTemp = FreeImage_ConvertToGreyscale(Bitmap) - hDIBNew = FreeImage_ConvertTo4Bits(hDIBTemp) - Call FreeImage_Unload(hDIBTemp) - End If - End If - - Case FICF_GREYSCALE_8BPP - ' Convert, if the bitmap is not at 8 bpp or does not have a linear ramp palette. - If ((lBPP <> 8) Or (((Not bForceLinearRamp) And (Not FreeImage_IsGreyscaleImage(Bitmap))) Or _ - (bForceLinearRamp And (FreeImage_GetColorType(Bitmap) = FIC_PALETTE)))) Then - hDIBNew = FreeImage_ConvertToGreyscale(Bitmap) - End If - - Case FICF_PALLETISED_8BPP - ' note, that the FreeImage library only quantizes 24 bit images - ' do not convert any 8 bit images - If (lBPP <> 8) Then - ' images with a color depth of 24 bits can directly be - ' converted with the FreeImage_ColorQuantize function; - ' other images need to be converted to 24 bits first - If (lBPP = 24) Then - hDIBNew = FreeImage_ColorQuantize(Bitmap, QuantizeMethod) - Else - hDIBTemp = FreeImage_ConvertTo24Bits(Bitmap) - hDIBNew = FreeImage_ColorQuantize(hDIBTemp, QuantizeMethod) - Call FreeImage_Unload(hDIBTemp) - End If - End If - - Case FICF_RGB_15BPP - If (lBPP <> 15) Then - hDIBNew = FreeImage_ConvertTo16Bits555(Bitmap) - End If - - Case FICF_RGB_16BPP - If (lBPP <> 16) Then - hDIBNew = FreeImage_ConvertTo16Bits565(Bitmap) - End If - - Case FICF_RGB_24BPP - If (lBPP <> 24) Then - hDIBNew = FreeImage_ConvertTo24Bits(Bitmap) - End If - - Case FICF_RGB_32BPP - If (lBPP <> 32) Then - hDIBNew = FreeImage_ConvertTo32Bits(Bitmap) - End If - - End Select - - If (hDIBNew) Then - FreeImage_ConvertColorDepth = hDIBNew - If (UnloadSource) Then - Call FreeImage_Unload(Bitmap) - End If - Else - FreeImage_ConvertColorDepth = Bitmap - End If - - End If - -End Function - -Public Function FreeImage_ColorQuantizeEx(ByVal Bitmap As Long, _ - Optional ByVal QuantizeMethod As FREE_IMAGE_QUANTIZE = FIQ_WUQUANT, _ - Optional ByVal UnloadSource As Boolean, _ - Optional ByVal PaletteSize As Long = 256, _ - Optional ByVal ReserveSize As Long, _ - Optional ByRef ReservePalette As Variant = Null) As Long - -Dim hTmp As Long -Dim lpPalette As Long -Dim lBlockSize As Long -Dim lElementSize As Long - - ' This function is a more VB-friendly wrapper around FreeImage_ColorQuantizeEx, - ' which lets you specify the ReservePalette to be used not only as a pointer, but - ' also as a real VB-style array of type Long, where each Long item takes a color - ' in ARGB format (&HAARRGGBB). The native FreeImage function FreeImage_ColorQuantizeEx - ' is declared private and named FreeImage_ColorQuantizeExInt and so hidden from the - ' world outside the wrapper. - - ' In contrast to the FreeImage API documentation, ReservePalette is of type Variant - ' and may either be a pointer to palette data (pointer to an array of type RGBQUAD - ' == VarPtr(atMyPalette(0)) in VB) or an array of type Long, which then must contain - ' the palette data in ARGB format. You can receive palette data as an array Longs - ' from function FreeImage_GetPaletteExLong. - ' Although ReservePalette is of type Variant, arrays of type RGBQUAD can not be - ' passed, as long as RGBQUAD is not declared as a public type in a public object - ' module. So, when dealing with RGBQUAD arrays, you are stuck on VarPtr or may - ' use function FreeImage_GetPalettePtr, which is a more meaningfully named - ' convenience wrapper around VarPtr. - - ' The optional 'UnloadSource' parameter is for unloading the original image, so - ' you can "change" an image with this function rather than getting a new DIB - ' pointer. There is no more need for a second DIB variable at the caller's site. - - ' All other parameters work according to the FreeImage API documentation. - - ' Note: Currently, any provided ReservePalette is only used, if quantize is - ' FIQ_NNQUANT. This seems to be either a bug or an undocumented - ' limitation of the FreeImage library (up to version 3.11.0). - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to quantize a 'header-only' bitmap.") - End If - - If (FreeImage_GetBPP(Bitmap) <> 24) Then - hTmp = Bitmap - Bitmap = FreeImage_ConvertTo24Bits(Bitmap) - If (UnloadSource) Then - Call FreeImage_Unload(hTmp) - End If - UnloadSource = True - End If - - ' adjust PaletteSize - If (PaletteSize < 2) Then - PaletteSize = 2 - ElseIf (PaletteSize > 256) Then - PaletteSize = 256 - End If - - lpPalette = pGetMemoryBlockPtrFromVariant(ReservePalette, lBlockSize, lElementSize) - FreeImage_ColorQuantizeEx = FreeImage_ColorQuantizeExInt(Bitmap, QuantizeMethod, _ - PaletteSize, ReserveSize, lpPalette) - - If (UnloadSource) Then - Call FreeImage_Unload(Bitmap) - End If - End If - -End Function - -Public Function FreeImage_GetPalettePtr(ByRef Palette() As RGBQUAD) As Long - - ' Returns a pointer to an array of RGBQUAD. This is sometimes referred to as - ' a palette. - - FreeImage_GetPalettePtr = VarPtr(Palette(0)) - -End Function - - -' Image Rescale wrapper functions - -Public Function FreeImage_RescaleEx(ByVal Bitmap As Long, _ - Optional ByVal Width As Variant, _ - Optional ByVal Height As Variant, _ - Optional ByVal IsPercentValue As Boolean, _ - Optional ByVal UnloadSource As Boolean, _ - Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ - Optional ByVal ForceCloneCreation As Boolean) As Long - -Dim lNewWidth As Long -Dim lNewHeight As Long -Dim hDIBNew As Long - - ' This function is a easy-to-use wrapper for rescaling an image with the - ' FreeImage library. It returns a pointer to a new rescaled DIB provided - ' by FreeImage. - - ' The parameters 'Width', 'Height' and 'IsPercentValue' control - ' the size of the new image. Here, the function tries to fake something like - ' overloading known from Java. It depends on the parameter's data type passed - ' through the Variant, how the provided values for width and height are - ' actually interpreted. The following rules apply: - - ' In general, non integer values are either interpreted as percent values or - ' factors, the original image size will be multiplied with. The 'IsPercentValue' - ' parameter controls whether the values are percent values or factors. Integer - ' values are always considered to be the direct new image size, not depending on - ' the original image size. In that case, the 'IsPercentValue' parameter has no - ' effect. If one of the parameters is omitted, the image will not be resized in - ' that direction (either in width or height) and keeps it's original size. It is - ' possible to omit both, but that makes actually no sense. - - ' The following table shows some of possible data type and value combinations - ' that might by used with that function: (assume an original image sized 100x100 px) - - ' Parameter | Values | Values | Values | Values | Values | - ' ---------------------------------------------------------------------- - ' Width | 75.0 | 0.85 | 200 | 120 | 400.0 | - ' Height | 120.0 | 1.3 | 230 | - | 400.0 | - ' IsPercentValue | True | False | d.c. | d.c. | False | <- wrong option? - ' ---------------------------------------------------------------------- - ' Result Size | 75x120 | 85x130 | 200x230 | 120x100 |40000x40000 | - ' Remarks | percent | factor | direct | |maybe not | - ' |what you | - ' |wanted, | - ' |right? | - - ' The optional 'UnloadSource' parameter is for unloading the original image, so - ' you can "change" an image with this function rather than getting a new DIB - ' pointer. There is no more need for a second DIB variable at the caller's site. - - ' As of version 2.0 of the FreeImage VB wrapper, this function and all it's derived - ' functions like FreeImage_RescaleByPixel() or FreeImage_RescaleByPercent(), do NOT - ' return a clone of the image, if the new size desired is the same as the source - ' image's size. That behaviour can be forced by setting the new parameter - ' 'ForceCloneCreation' to True. Then, an image is also rescaled (and so - ' effectively cloned), if the new width and height is exactly the same as the source - ' image's width and height. - - ' Since this diversity may be confusing to VB developers, this function is also - ' callable through three different functions called 'FreeImage_RescaleByPixel', - ' 'FreeImage_RescaleByPercent' and 'FreeImage_RescaleByFactor'. - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to rescale a 'header-only' bitmap.") - End If - - If (Not IsMissing(Width)) Then - Select Case VarType(Width) - - Case vbDouble, vbSingle, vbDecimal, vbCurrency - lNewWidth = FreeImage_GetWidth(Bitmap) * Width - If (IsPercentValue) Then - lNewWidth = lNewWidth / 100 - End If - - Case Else - lNewWidth = Width - - End Select - End If - - If (Not IsMissing(Height)) Then - Select Case VarType(Height) - - Case vbDouble, vbSingle, vbDecimal - lNewHeight = FreeImage_GetHeight(Bitmap) * Height - If (IsPercentValue) Then - lNewHeight = lNewHeight / 100 - End If - - Case Else - lNewHeight = Height - - End Select - End If - - If ((lNewWidth > 0) And (lNewHeight > 0)) Then - If (ForceCloneCreation) Then - hDIBNew = FreeImage_Rescale(Bitmap, lNewWidth, lNewHeight, Filter) - - ElseIf ((lNewWidth <> FreeImage_GetWidth(Bitmap)) Or _ - (lNewHeight <> FreeImage_GetHeight(Bitmap))) Then - hDIBNew = FreeImage_Rescale(Bitmap, lNewWidth, lNewHeight, Filter) - - End If - - ElseIf (lNewWidth > 0) Then - If ((lNewWidth <> FreeImage_GetWidth(Bitmap)) Or _ - (ForceCloneCreation)) Then - lNewHeight = lNewWidth / (FreeImage_GetWidth(Bitmap) / FreeImage_GetHeight(Bitmap)) - hDIBNew = FreeImage_Rescale(Bitmap, lNewWidth, lNewHeight, Filter) - End If - - ElseIf (lNewHeight > 0) Then - If ((lNewHeight <> FreeImage_GetHeight(Bitmap)) Or _ - (ForceCloneCreation)) Then - lNewWidth = lNewHeight * (FreeImage_GetWidth(Bitmap) / FreeImage_GetHeight(Bitmap)) - hDIBNew = FreeImage_Rescale(Bitmap, lNewWidth, lNewHeight, Filter) - End If - - End If - - If (hDIBNew) Then - FreeImage_RescaleEx = hDIBNew - If (UnloadSource) Then - Call FreeImage_Unload(Bitmap) - End If - Else - FreeImage_RescaleEx = Bitmap - End If - End If - -End Function - -Public Function FreeImage_RescaleByPixel(ByVal Bitmap As Long, _ - Optional ByVal WidthInPixels As Long, _ - Optional ByVal HeightInPixels As Long, _ - Optional ByVal UnloadSource As Boolean, _ - Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ - Optional ByVal ForceCloneCreation As Boolean) As Long - - ' Thin wrapper for function 'FreeImage_RescaleEx' for removing method - ' overload fake. This function rescales the image directly to the size - ' specified by the 'WidthInPixels' and 'HeightInPixels' parameters. - - FreeImage_RescaleByPixel = FreeImage_RescaleEx(Bitmap, WidthInPixels, HeightInPixels, False, _ - UnloadSource, Filter, ForceCloneCreation) - -End Function - -Public Function FreeImage_RescaleByPercent(ByVal Bitmap As Long, _ - Optional ByVal WidthPercentage As Double, _ - Optional ByVal HeightPercentage As Double, _ - Optional ByVal UnloadSource As Boolean, _ - Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ - Optional ByVal ForceCloneCreation As Boolean) As Long - - ' Thin wrapper for function 'FreeImage_RescaleEx' for removing method - ' overload fake. This function rescales the image by a percent value - ' based on the image's original size. - - FreeImage_RescaleByPercent = FreeImage_RescaleEx(Bitmap, WidthPercentage, HeightPercentage, True, _ - UnloadSource, Filter, ForceCloneCreation) - -End Function - -Public Function FreeImage_RescaleByFactor(ByVal Bitmap As Long, _ - Optional ByVal WidthFactor As Double, _ - Optional ByVal HeightFactor As Double, _ - Optional ByVal UnloadSource As Boolean, _ - Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ - Optional ByVal ForceCloneCreation As Boolean) As Long - - ' Thin wrapper for function 'FreeImage_RescaleEx' for removing method - ' overload fake. This function rescales the image by a factor - ' based on the image's original size. - - FreeImage_RescaleByFactor = FreeImage_RescaleEx(Bitmap, WidthFactor, HeightFactor, False, _ - UnloadSource, Filter, ForceCloneCreation) - -End Function - -' Painting functions - -Public Function FreeImage_PaintDC(ByVal hDC As Long, _ - ByVal Bitmap As Long, _ - Optional ByVal XDst As Long, _ - Optional ByVal YDst As Long, _ - Optional ByVal XSrc As Long, _ - Optional ByVal YSrc As Long, _ - Optional ByVal Width As Long, _ - Optional ByVal Height As Long) As Long - - ' This function draws a FreeImage DIB directly onto a device context (DC). There - ' are many (selfexplaining?) parameters that control the visual result. - - ' Parameters 'XDst' and 'YDst' specify the point where the output should - ' be painted and 'XSrc', 'YSrc', 'Width' and 'Height' span a rectangle - ' in the source image 'Bitmap' that defines the area to be painted. - - ' If any of parameters 'Width' and 'Height' is zero, it is transparently substituted - ' by the width or height of teh bitmap to be drawn, resprectively. - - If ((hDC <> 0) And (Bitmap <> 0)) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to paint a 'header-only' bitmap.") - End If - - If (Width = 0) Then - Width = FreeImage_GetWidth(Bitmap) - End If - - If (Height = 0) Then - Height = FreeImage_GetHeight(Bitmap) - End If - - FreeImage_PaintDC = SetDIBitsToDevice(hDC, XDst, YDst - YSrc, Width, Height, XSrc, YSrc, 0, _ - Height, FreeImage_GetBits(Bitmap), FreeImage_GetInfo(Bitmap), DIB_RGB_COLORS) - End If - -End Function - -Public Function FreeImage_PaintDCEx(ByVal hDC As Long, _ - ByVal Bitmap As Long, _ - Optional ByVal XDst As Long, _ - Optional ByVal YDst As Long, _ - Optional ByVal WidthDst As Long, _ - Optional ByVal HeightDst As Long, _ - Optional ByVal XSrc As Long, _ - Optional ByVal YSrc As Long, _ - Optional ByVal WidthSrc As Long, _ - Optional ByVal HeightSrc As Long, _ - Optional ByVal DrawMode As DRAW_MODE = DM_DRAW_DEFAULT, _ - Optional ByVal RasterOperator As RASTER_OPERATOR = ROP_SRCCOPY, _ - Optional ByVal StretchMode As STRETCH_MODE = SM_COLORONCOLOR) As Long - -Dim eLastStretchMode As STRETCH_MODE - - ' This function draws a FreeImage DIB directly onto a device context (DC). There - ' are many (selfexplaining?) parameters that control the visual result. - - ' The main difference of this function compared to the 'FreeImage_PaintDC' is, - ' that this function supports both mirroring and stretching of the image to be - ' painted and so, is somewhat slower than 'FreeImage_PaintDC'. - - If ((hDC <> 0) And (Bitmap <> 0)) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to paint a 'header-only' bitmap.") - End If - - eLastStretchMode = GetStretchBltMode(hDC) - Call SetStretchBltMode(hDC, StretchMode) - - If (WidthSrc = 0) Then - WidthSrc = FreeImage_GetWidth(Bitmap) - End If - If (WidthDst = 0) Then - WidthDst = WidthSrc - End If - - If (HeightSrc = 0) Then - HeightSrc = FreeImage_GetHeight(Bitmap) - End If - If (HeightDst = 0) Then - HeightDst = HeightSrc - End If - - If (DrawMode And DM_MIRROR_VERTICAL) Then - YDst = HeightDst - HeightDst = -HeightDst - End If - - If (DrawMode And DM_MIRROR_HORIZONTAL) Then - XDst = WidthDst - WidthDst = -WidthDst - End If - - Call StretchDIBits(hDC, XDst, YDst, WidthDst, HeightDst, XSrc, YSrc, WidthSrc, HeightSrc, _ - FreeImage_GetBits(Bitmap), FreeImage_GetInfo(Bitmap), DIB_RGB_COLORS, _ - RasterOperator) - - ' restore last mode - Call SetStretchBltMode(hDC, eLastStretchMode) - End If - -End Function - -Public Function FreeImage_PaintTransparent(ByVal hDC As Long, _ - ByVal Bitmap As Long, _ - Optional ByVal XDst As Long = 0, _ - Optional ByVal YDst As Long = 0, _ - Optional ByVal WidthDst As Long, _ - Optional ByVal HeightDst As Long, _ - Optional ByVal XSrc As Long = 0, _ - Optional ByVal YSrc As Long = 0, _ - Optional ByVal WidthSrc As Long, _ - Optional ByVal HeightSrc As Long, _ - Optional ByVal Alpha As Byte = 255) As Long - -Dim lpPalette As Long -Dim bIsTransparent As Boolean - - ' This function paints a device independent bitmap to any device context and - ' thereby honors any transparency information associated with the bitmap. - ' Furthermore, through the 'Alpha' parameter, an overall transparency level - ' may be specified. - - ' For palletised images, any color set to be transparent in the transparency - ' table, will be transparent. For high color images, only 32-bit images may - ' have any transparency information associated in their alpha channel. Only - ' these may be painted with transparency by this function. - - ' Since this is a wrapper for the Windows GDI function AlphaBlend(), 31-bit - ' images, containing alpha (or per-pixel) transparency, must be 'premultiplied' - ' for alpha transparent regions to actually show transparent. See MSDN help - ' on the AlphaBlend() function. - - ' FreeImage also offers a function to premultiply 32-bit bitmaps with their alpha - ' channel, according to the needs of AlphaBlend(). Have a look at function - ' FreeImage_PreMultiplyWithAlpha(). - - ' Overall transparency level may be specified for all bitmaps in all color - ' depths supported by FreeImage. If needed, bitmaps are transparently converted - ' to 32-bit and unloaded after the paint operation. This is also true for palletised - ' bitmaps. - - ' Parameters 'hDC' and 'Bitmap' seem to be very self-explanatory. All other parameters - ' are optional. The group of '*Dest*' parameters span a rectangle on the destination - ' device context, used as drawing area for the bitmap. If these are omitted, the - ' bitmap will be drawn starting at position 0,0 in the bitmap's actual size. - ' The group of '*Src*' parameters span a rectangle on the source bitmap, used as - ' cropping area for the paint operation. If both rectangles differ in size in any - ' direction, the part of the image actually painted is stretched for to fit into - ' the drawing area. If any of the parameters '*Width' or '*Height' are omitted, - ' the bitmap's actual size (width or height) will be used. - - ' The 'Alpha' parameter specifies the overall transparency. It takes values in the - ' range from 0 to 255. Using 0 will paint the bitmap fully transparent, 255 will - ' paint the image fully opaque. The 'Alpha' value controls, how the non per-pixel - ' portions of the image will be drawn. - - If ((hDC <> 0) And (Bitmap <> 0)) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to paint a 'header-only' bitmap.") - End If - - ' get image width if not specified - If (WidthSrc = 0) Then - WidthSrc = FreeImage_GetWidth(Bitmap) - End If - If (WidthDst = 0) Then - WidthDst = WidthSrc - End If - - ' get image height if not specified - If (HeightSrc = 0) Then - HeightSrc = FreeImage_GetHeight(Bitmap) - End If - If (HeightDst = 0) Then - HeightDst = HeightSrc - End If - - lpPalette = FreeImage_GetPalette(Bitmap) - If (lpPalette) Then - - Dim lPaletteSize As Long - Dim alPalOrg(255) As Long - Dim alPalMod(255) As Long - Dim alPalMask(255) As Long - Dim abTT() As Byte - Dim i As Long - - lPaletteSize = FreeImage_GetColorsUsed(Bitmap) * 4 - Call CopyMemory(alPalOrg(0), ByVal lpPalette, lPaletteSize) - Call CopyMemory(alPalMod(0), ByVal lpPalette, lPaletteSize) - abTT = FreeImage_GetTransparencyTableEx(Bitmap) - - If ((Alpha = 255) And _ - (HeightDst >= HeightSrc) And (WidthDst >= WidthSrc)) Then - - ' create a mask palette and a modified version of the - ' original palette - For i = 0 To UBound(abTT) - If (abTT(i) = 0) Then - alPalMask(i) = &HFFFFFFFF ' white - alPalMod(i) = &H0 ' black - bIsTransparent = True - End If - Next i - - If (Not bIsTransparent) Then - - ' if there is no transparency in the image, paint it with - ' a single SRCCOPY - Call StretchDIBits(hDC, _ - XDst, YDst, WidthDst, HeightDst, _ - XSrc, YSrc, WidthSrc, HeightSrc, _ - FreeImage_GetBits(Bitmap), _ - FreeImage_GetInfo(Bitmap), _ - DIB_RGB_COLORS, SRCCOPY) - Else - - ' set mask palette and paint with SRCAND - Call CopyMemory(ByVal lpPalette, alPalMask(0), lPaletteSize) - Call StretchDIBits(hDC, _ - XDst, YDst, WidthDst, HeightDst, _ - XSrc, YSrc, WidthSrc, HeightSrc, _ - FreeImage_GetBits(Bitmap), _ - FreeImage_GetInfo(Bitmap), _ - DIB_RGB_COLORS, SRCAND) - - ' set mask modified and paint with SRCPAINT - Call CopyMemory(ByVal lpPalette, alPalMod(0), lPaletteSize) - Call StretchDIBits(hDC, _ - XDst, YDst, WidthDst, HeightDst, _ - XSrc, YSrc, WidthSrc, HeightSrc, _ - FreeImage_GetBits(Bitmap), _ - FreeImage_GetInfo(Bitmap), _ - DIB_RGB_COLORS, SRCPAINT) - - ' restore original palette - Call CopyMemory(ByVal lpPalette, alPalOrg(0), lPaletteSize) - End If - - ' we are done, do not paint with AlphaBlend() any more - Bitmap = 0 - Else - - ' create a premultiplied palette - ' since we have no real per pixel transparency in a palletized - ' image, we only need to set all transparent colors to zero. - For i = 0 To UBound(abTT) - If (abTT(i) = 0) Then - alPalMod(i) = 0 - End If - Next i - - ' set premultiplied palette and convert to 32 bits - Call CopyMemory(ByVal lpPalette, alPalMod(0), lPaletteSize) - Bitmap = FreeImage_ConvertTo32Bits(Bitmap) - - ' restore original palette - Call CopyMemory(ByVal lpPalette, alPalOrg(0), lPaletteSize) - End If - End If - - If (Bitmap) Then - Dim hMemDC As Long - Dim hBitmap As Long - Dim hBitmapOld As Long - Dim tBF As BLENDFUNCTION - Dim lBF As Long - - hMemDC = CreateCompatibleDC(0) - If (hMemDC) Then - hBitmap = FreeImage_GetBitmap(Bitmap, hMemDC) - hBitmapOld = SelectObject(hMemDC, hBitmap) - - With tBF - .BlendOp = AC_SRC_OVER - .SourceConstantAlpha = Alpha - If (FreeImage_GetBPP(Bitmap) = 32) Then - .AlphaFormat = AC_SRC_ALPHA - End If - End With - Call CopyMemory(lBF, tBF, 4) - - Call AlphaBlend(hDC, XDst, YDst, WidthDst, HeightDst, _ - hMemDC, XSrc, YSrc, WidthSrc, HeightSrc, _ - lBF) - - Call SelectObject(hMemDC, hBitmapOld) - Call DeleteObject(hBitmap) - Call DeleteDC(hMemDC) - If (lpPalette) Then - Call FreeImage_Unload(Bitmap) - End If - End If - End If - End If - -End Function - - -'-------------------------------------------------------------------------------- -' Pixel access functions -'-------------------------------------------------------------------------------- - -Public Function FreeImage_GetBitsEx(ByVal Bitmap As Long) As Byte() - -Dim tSA As SAVEARRAY2D -Dim lpSA As Long - - ' This function returns a two dimensional Byte array containing a DIB's - ' data-bits. This is done by wrapping a true VB array around the memory - ' block the returned pointer of FreeImage_GetBits() is pointing to. So, the - ' array returned provides full read and write acces to the image's data. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the FreeImage_DestroyLockedArray() function. - - If (Bitmap) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 1 ' size in bytes per array element - .cDims = 2 ' the array has 2 dimensions - .cElements1 = FreeImage_GetHeight(Bitmap) ' the number of elements in y direction (height of Bitmap) - .cElements2 = FreeImage_GetPitch(Bitmap) ' the number of elements in x direction (byte width of Bitmap) - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetBits(Bitmap) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' allocate memory for an array descriptor - ' we cannot use the memory block used by tSA, since it is - ' released when tSA goes out of scope, leaving us with an - ' array with zeroed descriptor - ' we use nearly the same method that VB uses, so VB is able - ' to cleanup the array variable and it's descriptor; the - ' array data is not touched when cleaning up, since both AUTO - ' and FIXEDSIZE flags are set - Call SafeArrayAllocDescriptor(2, lpSA) - - ' copy our own array descriptor over the descriptor allocated - ' by SafeArrayAllocDescriptor; lpSA is a pointer to that memory - ' location - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - - ' the implicit variable named like the function is an array - ' variable in VB - ' make it point to the allocated array descriptor - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetBitsEx), lpSA, 4) - End If - -End Function - -Public Function FreeImage_GetBitsExRGBTRIPLE(ByVal Bitmap As Long) As RGBTRIPLE() - -Dim tSA As SAVEARRAY2D -Dim lpSA As Long - - ' This function returns a two dimensional RGBTRIPLE array containing a DIB's - ' data-bits. This is done by wrapping a true VB array around the memory - ' block the returned pointer of 'FreeImage_GetBits' is pointing to. So, the - ' array returned provides full read and write acces to the image's data. - - ' This function only works with 24 bpp images and, since each FreeImage scanline - ' is aligned to a 32-bit boundary, only if the image's width in pixels multiplied - ' by three modulo four is zero. That means, that the image layout in memory must - ' "naturally" be aligned to a 32-bit boundary, since arrays do not support padding. - - ' So, the function only returns an initialized array, if this equotion is true: - ' (((ImageWidthPixels * 3) Mod 4) = 0) - - ' In other words, this is true for all images with no padding. - - ' For instance, only images with these widths will be suitable for this function: - ' 100, 104, 108, 112, 116, 120, 124, ... - - ' Have a look at the wrapper function 'FreeImage_GetScanlinesRGBTRIPLE()' to have - ' a way to work around that limitation. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArray' function. - - If (Bitmap) Then - - If (FreeImage_GetBPP(Bitmap) = 24) Then - If (((FreeImage_GetWidth(Bitmap) * 3) Mod 4) = 0) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 3 ' size in bytes per array element - .cDims = 2 ' the array has 2 dimensions - .cElements1 = FreeImage_GetHeight(Bitmap) ' the number of elements in y direction (height of Bitmap) - .cElements2 = FreeImage_GetWidth(Bitmap) ' the number of elements in x direction (byte width of Bitmap) - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetBits(Bitmap) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' allocate memory for an array descriptor - ' we cannot use the memory block used by tSA, since it is - ' released when tSA goes out of scope, leaving us with an - ' array with zeroed descriptor - ' we use nearly the same method that VB uses, so VB is able - ' to cleanup the array variable and it's descriptor; the - ' array data is not touched when cleaning up, since both AUTO - ' and FIXEDSIZE flags are set - Call SafeArrayAllocDescriptor(2, lpSA) - - ' copy our own array descriptor over the descriptor allocated - ' by SafeArrayAllocDescriptor; lpSA is a pointer to that memory - ' location - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - - ' the implicit variable named like the function is an array - ' variable in VB - ' make it point to the allocated array descriptor - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetBitsExRGBTRIPLE), lpSA, 4) - Else - - ' we could throw an error here - End If - Else - - ' we could throw an error here - End If - End If - -End Function - -Public Function FreeImage_GetBitsExRGBQUAD(ByVal Bitmap As Long) As RGBQUAD() - -Dim tSA As SAVEARRAY2D -Dim lpSA As Long - - ' This function returns a two dimensional RGBQUAD array containing a DIB's - ' data-bits. This is done by wrapping a true VB array around the memory - ' block the returned pointer of 'FreeImage_GetBits' is pointing to. So, the - ' array returned provides full read and write acces to the image's data. - - ' This function only works with 32 bpp images. Since each scanline must - ' "naturally" start at a 32-bit boundary if each pixel uses 32 bits, there - ' are no padding problems like these known with 'FreeImage_GetBitsExRGBTRIPLE', - ' so, this function is suitable for all 32 bpp images of any size. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArray' function. - - If (Bitmap) Then - - If (FreeImage_GetBPP(Bitmap) = 32) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 4 ' size in bytes per array element - .cDims = 2 ' the array has 2 dimensions - .cElements1 = FreeImage_GetHeight(Bitmap) ' the number of elements in y direction (height of Bitmap) - .cElements2 = FreeImage_GetWidth(Bitmap) ' the number of elements in x direction (byte width of Bitmap) - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetBits(Bitmap) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' allocate memory for an array descriptor - ' we cannot use the memory block used by tSA, since it is - ' released when tSA goes out of scope, leaving us with an - ' array with zeroed descriptor - ' we use nearly the same method that VB uses, so VB is able - ' to cleanup the array variable and it's descriptor; the - ' array data is not touched when cleaning up, since both AUTO - ' and FIXEDSIZE flags are set - Call SafeArrayAllocDescriptor(2, lpSA) - - ' copy our own array descriptor over the descriptor allocated - ' by SafeArrayAllocDescriptor; lpSA is a pointer to that memory - ' location - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - - ' the implicit variable named like the function is an array - ' variable in VB - ' make it point to the allocated array descriptor - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetBitsExRGBQUAD), lpSA, 4) - Else - - ' we could throw an error here - End If - End If - -End Function - -Public Function FreeImage_GetScanLinesRGBTRIPLE(ByVal Bitmap As Long, _ - ByRef Scanlines As ScanLinesRGBTRIBLE, _ - Optional ByVal Reverse As Boolean) As Long -Dim lHeight As Long -Dim i As Long - - ' still undocumented - ' for now, have a look at function FreeImage_GetBitsExRGBTRIPLE() - - If (Bitmap) Then - If (FreeImage_GetImageType(Bitmap) = FIT_BITMAP) Then - If (FreeImage_GetBPP(Bitmap) = 24) Then - - lHeight = FreeImage_GetHeight(Bitmap) - ReDim Scanlines.Scanline(lHeight - 1) - For i = 0 To lHeight - 1 - If (Not Reverse) Then - Scanlines.Scanline(i).Data = FreeImage_GetScanLineBITMAP24(Bitmap, i) - Else - Scanlines.Scanline(i).Data = FreeImage_GetScanLineBITMAP24(Bitmap, lHeight - i - 1) - End If - Next i - End If - End If - End If - - FreeImage_GetScanLinesRGBTRIPLE = lHeight - -End Function - -Public Function FreeImage_GetScanLineEx(ByVal Bitmap As Long, _ - ByVal Scanline As Long) As Byte() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long - - ' This function returns a one dimensional Byte array containing a whole - ' scanline's data-bits. This is done by wrapping a true VB array around - ' the memory block the returned pointer of 'FreeImage_GetScanline' is - ' pointing to. So, the array returned provides full read and write acces - ' to the image's data. - - ' This is the most generic function of a complete function set dealing with - ' scanline data, since this function returns an array of type Byte. It is - ' up to the caller of the function to interpret these bytes correctly, - ' according to the results of FreeImage_GetBPP and FreeImage_GetImageType. - - ' You may consider using any of the non-generic functions named - ' 'FreeImage_GetScanLineXXX', that return an array of proper type, according - ' to the images bit depth and type. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArray' function. - - If (Bitmap) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 1 ' size in bytes per array element - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetLine(Bitmap) ' the number of elements in the array - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetScanline(Bitmap, _ - Scanline) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' allocate memory for an array descriptor - ' we cannot use the memory block used by tSA, since it is - ' released when tSA goes out of scope, leaving us with an - ' array with zeroed descriptor - ' we use nearly the same method that VB uses, so VB is able - ' to cleanup the array variable and it's descriptor; the - ' array data is not touched when cleaning up, since both AUTO - ' and FIXEDSIZE flags are set - Call SafeArrayAllocDescriptor(1, lpSA) - - ' copy our own array descriptor over the descriptor allocated - ' by SafeArrayAllocDescriptor; lpSA is a pointer to that memory - ' location - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - - ' the implicit variable named like the function is an array - ' variable in VB - ' make it point to the allocated array descriptor - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineEx), lpSA, 4) - End If - -End Function - -Public Function FreeImage_GetScanLineBITMAP8(ByVal Bitmap As Long, _ - ByVal Scanline As Long) As Byte() - - ' This function returns a one dimensional Byte array containing a whole - ' scanline's data-bits of a 8 bit bitmap image. This is done by wrapping - ' a true VB array around the memory block the returned pointer of - ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides - ' full read and write acces to the image's data. - - ' This function is just a thin wrapper for 'FreeImage_GetScanLineEx' but - ' includes checking of the image's bit depth and type, as all of the - ' non-generic scanline functions do. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArray' function. - - If (FreeImage_GetImageType(Bitmap) = FIT_BITMAP) Then - Select Case FreeImage_GetBPP(Bitmap) - - Case 1, 4, 8 - FreeImage_GetScanLineBITMAP8 = FreeImage_GetScanLineEx(Bitmap, Scanline) - - End Select - End If - -End Function - -Public Function FreeImage_GetScanLineBITMAP16(ByVal Bitmap As Long, _ - ByVal Scanline As Long) As Integer() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long - - ' This function returns a one dimensional Integer array containing a whole - ' scanline's data-bits of a 16 bit bitmap image. This is done by wrapping - ' a true VB array around the memory block the returned pointer of - ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides - ' full read and write acces to the image's data. - - ' The function includes checking of the image's bit depth and type and - ' returns a non-initialized array if 'Bitmap' is an image of improper type. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArray' function. - - If (FreeImage_GetImageType(Bitmap) = FIT_BITMAP) Then - If (FreeImage_GetBPP(Bitmap) = 16) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 2 ' size in bytes per array element - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetScanline(Bitmap, _ - Scanline) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' For a complete source code documentation have a - ' look at the function 'FreeImage_GetScanLineEx' - Call SafeArrayAllocDescriptor(1, lpSA) - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineBITMAP16), lpSA, 4) - End If - End If - -End Function - -Public Function FreeImage_GetScanLineBITMAP24(ByVal Bitmap As Long, _ - ByVal Scanline As Long) As RGBTRIPLE() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long - - ' This function returns a one dimensional RGBTRIPLE array containing a whole - ' scanline's data-bits of a 24 bit bitmap image. This is done by wrapping - ' a true VB array around the memory block the returned pointer of - ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides - ' full read and write acces to the image's data. - - ' The function includes checking of the image's bit depth and type and - ' returns a non-initialized array if 'Bitmap' is an image of improper type. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArrayRGBTRIPLE' function. - - If (FreeImage_GetImageType(Bitmap) = FIT_BITMAP) Then - If (FreeImage_GetBPP(Bitmap) = 24) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 3 ' size in bytes per array element - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetScanline(Bitmap, _ - Scanline) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' For a complete source code documentation have a - ' look at the function 'FreeImage_GetScanLineEx' - Call SafeArrayAllocDescriptor(1, lpSA) - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineBITMAP24), lpSA, 4) - End If - End If - -End Function - -Public Function FreeImage_GetScanLineBITMAP32(ByVal Bitmap As Long, _ - ByVal Scanline As Long) As RGBQUAD() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long - - ' This function returns a one dimensional RGBQUAD array containing a whole - ' scanline's data-bits of a 32 bit bitmap image. This is done by wrapping - ' a true VB array around the memory block the returned pointer of - ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides - ' full read and write acces to the image's data. - - ' The function includes checking of the image's bit depth and type and - ' returns a non-initialized array if 'Bitmap' is an image of improper type. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArrayRGBQUAD' function. - - If (FreeImage_GetImageType(Bitmap) = FIT_BITMAP) Then - If (FreeImage_GetBPP(Bitmap) = 32) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 4 ' size in bytes per array element - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetScanline(Bitmap, _ - Scanline) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' For a complete source code documentation have a - ' look at the function 'FreeImage_GetScanLineEx' - Call SafeArrayAllocDescriptor(1, lpSA) - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineBITMAP32), lpSA, 4) - End If - End If - -End Function - -Public Function FreeImage_GetScanLineINT16(ByVal Bitmap As Long, _ - ByVal Scanline As Long) As Integer() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long -Dim eImageType As FREE_IMAGE_TYPE - - ' This function returns a one dimensional Integer array containing a whole - ' scanline's data-bits of a FIT_INT16 or FIT_UINT16 image. This is done - ' by wrapping a true VB array around the memory block the returned pointer - ' of 'FreeImage_GetScanline' is pointing to. So, the array returned - ' provides full read and write acces to the image's data. - - ' The function includes checking of the image's bit depth and type and - ' returns a non-initialized array if 'Bitmap' is an image of improper type. - - ' Since VB does not distinguish between signed and unsigned data types, both - ' image types FIT_INT16 and FIT_UINT16 are handled with this function. If 'Bitmap' - ' specifies an image of type FIT_UINT16, it is up to the caller to treat the - ' array's Integers as unsigned, although VB knows signed Integers only. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArray' function. - - eImageType = FreeImage_GetImageType(Bitmap) - If ((eImageType = FIT_INT16) Or _ - (eImageType = FIT_UINT16)) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 2 ' size in bytes per array element - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetScanline(Bitmap, _ - Scanline) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' For a complete source code documentation have a - ' look at the function 'FreeImage_GetScanLineEx' - Call SafeArrayAllocDescriptor(1, lpSA) - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineINT16), lpSA, 4) - End If - -End Function - -Public Function FreeImage_GetScanLineINT32(ByVal Bitmap As Long, _ - ByVal Scanline As Long) As Long() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long -Dim eImageType As FREE_IMAGE_TYPE - - ' This function returns a one dimensional Long array containing a whole - ' scanline's data-bits of a FIT_INT32 or FIT_UINT32 image. This is done - ' by wrapping a true VB array around the memory block the returned pointer - ' of 'FreeImage_GetScanline' is pointing to. So, the array returned - ' provides full read and write acces to the image's data. - - ' The function includes checking of the image's bit depth and type and - ' returns a non-initialized array if 'Bitmap' is an image of improper type. - - ' Since VB does not distinguish between signed and unsigned data types, both - ' image types FIT_INT32 and FIT_UINT32 are handled with this function. If 'Bitmap' - ' specifies an image of type FIT_UINT32, it is up to the caller to treat the - ' array's Longs as unsigned, although VB knows signed Longs only. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArray' function. - - eImageType = FreeImage_GetImageType(Bitmap) - If ((eImageType = FIT_INT32) Or _ - (eImageType = FIT_UINT32)) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 4 ' size in bytes per array element - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetScanline(Bitmap, _ - Scanline) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' For a complete source code documentation have a - ' look at the function 'FreeImage_GetScanLineEx' - Call SafeArrayAllocDescriptor(1, lpSA) - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineINT32), lpSA, 4) - End If - -End Function - -Public Function FreeImage_GetScanLineFLOAT(ByVal Bitmap As Long, _ - ByVal Scanline As Long) As Single() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long -Dim eImageType As FREE_IMAGE_TYPE - - ' This function returns a one dimensional Single array containing a whole - ' scanline's data-bits of a FIT_FLOAT image. This is done by wrapping - ' a true VB array around the memory block the returned pointer of - ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides - ' full read and write acces to the image's data. - - ' The function includes checking of the image's bit depth and type and - ' returns a non-initialized array if 'Bitmap' is an image of improper type. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArray' function. - - eImageType = FreeImage_GetImageType(Bitmap) - If (eImageType = FIT_FLOAT) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 4 ' size in bytes per array element - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetScanline(Bitmap, _ - Scanline) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' For a complete source code documentation have a - ' look at the function 'FreeImage_GetScanLineEx' - Call SafeArrayAllocDescriptor(1, lpSA) - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineFLOAT), lpSA, 4) - End If - -End Function - -Public Function FreeImage_GetScanLineDOUBLE(ByVal Bitmap As Long, _ - ByVal Scanline As Long) As Double() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long -Dim eImageType As FREE_IMAGE_TYPE - - ' This function returns a one dimensional Double array containing a whole - ' scanline's data-bits of a FIT_DOUBLE image. This is done by wrapping - ' a true VB array around the memory block the returned pointer of - ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides - ' full read and write acces to the image's data. - - ' The function includes checking of the image's bit depth and type and - ' returns a non-initialized array if 'Bitmap' is an image of improper type. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArray' function. - - eImageType = FreeImage_GetImageType(Bitmap) - If (eImageType = FIT_DOUBLE) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 8 ' size in bytes per array element - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetScanline(Bitmap, _ - Scanline) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' For a complete source code documentation have a - ' look at the function 'FreeImage_GetScanLineEx' - Call SafeArrayAllocDescriptor(1, lpSA) - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineDOUBLE), lpSA, 4) - End If - -End Function - -Public Function FreeImage_GetScanLineCOMPLEX(ByVal Bitmap As Long, _ - ByVal Scanline As Long) As FICOMPLEX() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long -Dim eImageType As FREE_IMAGE_TYPE - - ' This function returns a one dimensional FICOMPLEX array containing a whole - ' scanline's data-bits of a FIT_COMPLEX image. This is done by wrapping - ' a true VB array around the memory block the returned pointer of - ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides - ' full read and write acces to the image's data. - - ' The function includes checking of the image's bit depth and type and - ' returns a non-initialized array if 'Bitmap' is an image of improper type. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArrayFICOMPLEX' function. - - eImageType = FreeImage_GetImageType(Bitmap) - If (eImageType = FIT_COMPLEX) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 16 ' size in bytes per array element - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetScanline(Bitmap, _ - Scanline) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' For a complete source code documentation have a - ' look at the function 'FreeImage_GetScanLineEx' - Call SafeArrayAllocDescriptor(1, lpSA) - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineCOMPLEX), lpSA, 4) - End If - -End Function - -Public Function FreeImage_GetScanLineRGB16(ByVal Bitmap As Long, _ - ByVal Scanline As Long) As FIRGB16() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long -Dim eImageType As FREE_IMAGE_TYPE - - ' This function returns a one dimensional FIRGB16 array containing a whole - ' scanline's data-bits of a FIT_RGB16 image. This is done by wrapping - ' a true VB array around the memory block the returned pointer of - ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides - ' full read and write acces to the image's data. - - ' The function includes checking of the image's bit depth and type and - ' returns a non-initialized array if 'Bitmap' is an image of improper type. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArrayFIRGB16' function. - - eImageType = FreeImage_GetImageType(Bitmap) - If (eImageType = FIT_RGB16) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 6 ' size in bytes per array element - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetScanline(Bitmap, _ - Scanline) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' For a complete source code documentation have a - ' look at the function 'FreeImage_GetScanLineEx' - Call SafeArrayAllocDescriptor(1, lpSA) - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineRGB16), lpSA, 4) - End If - -End Function - -Public Function FreeImage_GetScanLineRGBA16(ByVal Bitmap As Long, _ - ByVal Scanline As Long) As FIRGBA16() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long -Dim eImageType As FREE_IMAGE_TYPE - - ' This function returns a one dimensional FIRGBA16 array containing a whole - ' scanline's data-bits of a FIT_RGBA16 image. This is done by wrapping - ' a true VB array around the memory block the returned pointer of - ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides - ' full read and write acces to the image's data. - - ' The function includes checking of the image's bit depth and type and - ' returns a non-initialized array if 'Bitmap' is an image of improper type. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArrayFIRGBA16' function. - - eImageType = FreeImage_GetImageType(Bitmap) - If (eImageType = FIT_RGBA16) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 8 ' size in bytes per array element - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetScanline(Bitmap, _ - Scanline) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' For a complete source code documentation have a - ' look at the function 'FreeImage_GetScanLineEx' - Call SafeArrayAllocDescriptor(1, lpSA) - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineRGBA16), lpSA, 4) - End If - -End Function - -Public Function FreeImage_GetScanLineRGBF(ByVal Bitmap As Long, _ - ByVal Scanline As Long) As FIRGBF() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long -Dim eImageType As FREE_IMAGE_TYPE - - ' This function returns a one dimensional FIRGBF array containing a whole - ' scanline's data-bits of a FIT_RGBF image. This is done by wrapping - ' a true VB array around the memory block the returned pointer of - ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides - ' full read and write acces to the image's data. - - ' The function includes checking of the image's bit depth and type and - ' returns a non-initialized array if 'Bitmap' is an image of improper type. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArrayFIRGBF' function. - - eImageType = FreeImage_GetImageType(Bitmap) - If (eImageType = FIT_RGBF) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 12 ' size in bytes per array element - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetScanline(Bitmap, _ - Scanline) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' For a complete source code documentation have a - ' look at the function 'FreeImage_GetScanLineEx' - Call SafeArrayAllocDescriptor(1, lpSA) - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineRGBF), lpSA, 4) - End If - -End Function - -Public Function FreeImage_GetScanLineRGBAF(ByVal Bitmap As Long, _ - ByVal Scanline As Long) As FIRGBAF() - -Dim tSA As SAVEARRAY1D -Dim lpSA As Long -Dim eImageType As FREE_IMAGE_TYPE - - ' This function returns a one dimensional FIRGBAF array containing a whole - ' scanline's data-bits of a FIT_RGBAF image. This is done by wrapping - ' a true VB array around the memory block the returned pointer of - ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides - ' full read and write acces to the image's data. - - ' The function includes checking of the image's bit depth and type and - ' returns a non-initialized array if 'Bitmap' is an image of improper type. - - ' To reuse the caller's array variable, this function's result was assigned to, - ' before it goes out of scope, the caller's array variable must be destroyed with - ' the 'FreeImage_DestroyLockedArrayFIRGBAF' function. - - eImageType = FreeImage_GetImageType(Bitmap) - If (eImageType = FIT_RGBAF) Then - - ' create a proper SAVEARRAY descriptor - With tSA - .cbElements = 12 ' size in bytes per array element - .cDims = 1 ' the array has only 1 dimension - .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array - .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, - ' so the array can not be modified in size - ' or erased; according to Matthew Curland never - ' use FIXEDSIZE alone - .pvData = FreeImage_GetScanline(Bitmap, _ - Scanline) ' let the array point to the memory block, the - ' FreeImage scanline data pointer points to - End With - - ' For a complete source code documentation have a - ' look at the function 'FreeImage_GetScanLineEx' - Call SafeArrayAllocDescriptor(1, lpSA) - Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) - Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineRGBAF), lpSA, 4) - End If - -End Function - -'-------------------------------------------------------------------------------- -' HBITMAP conversion functions -'-------------------------------------------------------------------------------- - -Public Function FreeImage_GetBitmap(ByVal Bitmap As Long, _ - Optional ByVal hDC As Long, _ - Optional ByVal UnloadSource As Boolean) As Long - -Dim bReleaseDC As Boolean -Dim ppvBits As Long - - ' This function returns an HBITMAP created by the CreateDIBSection() function which - ' in turn has the same color depth as the original DIB. A reference DC may be provided - ' through the 'hDC' parameter. The desktop DC will be used, if no reference DC is - ' specified. - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to create a bitmap from a 'header-only' bitmap.") - End If - - If (hDC = 0) Then - hDC = GetDC(0) - bReleaseDC = True - End If - If (hDC) Then - FreeImage_GetBitmap = CreateDIBSection(hDC, FreeImage_GetInfo(Bitmap), _ - DIB_RGB_COLORS, ppvBits, 0, 0) - If ((FreeImage_GetBitmap <> 0) And (ppvBits <> 0)) Then - Call CopyMemory(ByVal ppvBits, ByVal FreeImage_GetBits(Bitmap), _ - FreeImage_GetHeight(Bitmap) * FreeImage_GetPitch(Bitmap)) - End If - If (UnloadSource) Then - Call FreeImage_Unload(Bitmap) - End If - If (bReleaseDC) Then - Call ReleaseDC(0, hDC) - End If - End If - End If - -End Function - -Public Function FreeImage_GetBitmapForDevice(ByVal Bitmap As Long, _ - Optional ByVal hDC As Long, _ - Optional ByVal UnloadSource As Boolean) As Long - -Dim bReleaseDC As Boolean - - ' This function returns an HBITMAP created by the CreateDIBitmap() function which - ' in turn has always the same color depth as the reference DC, which may be provided - ' through the 'hDC' parameter. The desktop DC will be used, if no reference DC is - ' specified. - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to create a bitmap from a 'header-only' bitmap.") - End If - - If (hDC = 0) Then - hDC = GetDC(0) - bReleaseDC = True - End If - If (hDC) Then - FreeImage_GetBitmapForDevice = _ - CreateDIBitmap(hDC, FreeImage_GetInfoHeader(Bitmap), CBM_INIT, _ - FreeImage_GetBits(Bitmap), FreeImage_GetInfo(Bitmap), _ - DIB_RGB_COLORS) - If (UnloadSource) Then - Call FreeImage_Unload(Bitmap) - End If - If (bReleaseDC) Then - Call ReleaseDC(0, hDC) - End If - End If - End If - -End Function - -'-------------------------------------------------------------------------------- -' OlePicture conversion functions -'-------------------------------------------------------------------------------- - -Public Function FreeImage_GetOlePicture(ByVal Bitmap As Long, _ - Optional ByVal hDC As Long, _ - Optional ByVal UnloadSource As Boolean) As IPicture - -Dim hBitmap As Long -Dim tPicDesc As PictDesc -Dim tGuid As Guid -Dim cPictureDisp As IPictureDisp - - ' This function creates a VB Picture object (OlePicture) from a FreeImage DIB. - ' The original image need not remain valid nor loaded after the VB Picture - ' object has been created. - - ' The optional parameter 'hDC' determines the device context (DC) used for - ' transforming the device independent bitmap (DIB) to a device dependent - ' bitmap (DDB). This device context's color depth is responsible for this - ' transformation. This parameter may be null or omitted. In that case, the - ' windows desktop's device context will be used, what will be the desired - ' way in almost any cases. - - ' The optional 'UnloadSource' parameter is for unloading the original image - ' after the OlePicture has been created, so you can easily "switch" from a - ' FreeImage DIB to a VB Picture object. There is no need to unload the DIB - ' at the caller's site if this argument is True. - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to create a picture from a 'header-only' bitmap.") - End If - - hBitmap = FreeImage_GetBitmapForDevice(Bitmap, hDC, UnloadSource) - If (hBitmap) Then - ' fill tPictDesc structure with necessary parts - With tPicDesc - .cbSizeofStruct = Len(tPicDesc) - ' the vbPicTypeBitmap constant is not available in VBA environemnts - .picType = 1 'vbPicTypeBitmap - .hImage = hBitmap - End With - - ' fill in IDispatch Interface ID - With tGuid - .Data1 = &H20400 - .Data4(0) = &HC0 - .Data4(7) = &H46 - End With - - ' create a picture object - Call OleCreatePictureIndirect(tPicDesc, tGuid, True, cPictureDisp) - Set FreeImage_GetOlePicture = cPictureDisp - End If - End If - -End Function - -Public Function FreeImage_GetOlePictureIcon(ByVal hIcon As Long) As IPicture - -Dim tPicDesc As PictDesc -Dim tGuid As Guid -Dim cPictureDisp As IPictureDisp - - ' This function creates a VB Picture object (OlePicture) of type picTypeIcon - ' from FreeImage hIcon handle. The hIcon handle need not remain valid nor loaded - ' after the VB Picture object has been created. - - ' The optional 'UnloadSource' parameter is for destroying the hIcon image - ' after the OlePicture has been created, so you can easiely "switch" from a - ' hIcon handle to a VB Picture object. There is no need to unload the hIcon - ' at the caller's site if this argument is True. - - If (hIcon) Then - ' fill tPictDesc structure with necessary parts - With tPicDesc - .cbSizeofStruct = 12 - ' the vbPicTypeIcon constant is not available in VBA environemnts - .picType = 3 'vbPicTypeIcon - .hImage = hIcon - End With - - ' fill in IDispatch Interface ID - With tGuid - .Data1 = &H20400 - .Data4(0) = &HC0 - .Data4(7) = &H46 - End With - - ' create a picture object - Call OleCreatePictureIndirect(tPicDesc, tGuid, True, cPictureDisp) - Set FreeImage_GetOlePictureIcon = cPictureDisp - End If - -End Function - -Public Function FreeImage_GetOlePictureThumbnail(ByVal Bitmap As Long, _ - ByVal MaxPixelSize As Long, _ - Optional ByVal hDC As Long, _ - Optional ByVal UnloadSource As Boolean) As IPicture - -Dim hDIBThumbnail As Long - - ' This function is a IOlePicture aware wrapper for FreeImage_MakeThumbnail(). It - ' returns a VB Picture object instead of a FreeImage DIB. - - ' The optional 'UnloadSource' parameter is for unloading the original image - ' after the OlePicture has been created, so you can easiely "switch" from a - ' FreeImage DIB to a VB Picture object. There is no need to clean up the DIB - ' at the caller's site. - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to create a thumbnail picture from a 'header-only' bitmap.") - End If - - hDIBThumbnail = FreeImage_MakeThumbnail(Bitmap, MaxPixelSize) - Set FreeImage_GetOlePictureThumbnail = FreeImage_GetOlePicture(hDIBThumbnail, hDC, True) - - If (UnloadSource) Then - Call FreeImage_Unload(Bitmap) - End If - End If - -End Function - -Public Function FreeImage_CreateFromOlePicture(ByRef Picture As IPicture) As Long - -Dim hBitmap As Long -Dim tBM As BITMAP_API -Dim hDIB As Long -Dim hDC As Long -Dim lResult As Long -Dim nColors As Long -Dim lpInfo As Long - - ' Creates a FreeImage DIB from a VB Picture object (OlePicture). This function - ' returns a pointer to the DIB as, for instance, the FreeImage function - ' 'FreeImage_Load' does. So, this could be a real replacement for 'FreeImage_Load' - ' when working with VB Picture objects. - - If (Not Picture Is Nothing) Then - hBitmap = Picture.Handle - If (hBitmap) Then - lResult = GetObjectAPI(hBitmap, Len(tBM), tBM) - If (lResult) Then - hDIB = FreeImage_Allocate(tBM.bmWidth, _ - tBM.bmHeight, _ - tBM.bmBitsPixel) - If (hDIB) Then - ' The GetDIBits function clears the biClrUsed and biClrImportant BITMAPINFO - ' members (dont't know why). So we save these infos below. - ' This is needed for palletized images only. - nColors = FreeImage_GetColorsUsed(hDIB) - - hDC = GetDC(0) - lResult = GetDIBits(hDC, hBitmap, 0, _ - FreeImage_GetHeight(hDIB), _ - FreeImage_GetBits(hDIB), _ - FreeImage_GetInfo(hDIB), _ - DIB_RGB_COLORS) - If (lResult) Then - FreeImage_CreateFromOlePicture = hDIB - If (nColors) Then - ' restore BITMAPINFO members - ' FreeImage_GetInfo(Bitmap)->biClrUsed = nColors; - ' FreeImage_GetInfo(Bitmap)->biClrImportant = nColors; - lpInfo = FreeImage_GetInfo(hDIB) - Call CopyMemory(ByVal lpInfo + 32, nColors, 4) - Call CopyMemory(ByVal lpInfo + 36, nColors, 4) - End If - Else - Call FreeImage_Unload(hDIB) - End If - Call ReleaseDC(0, hDC) - End If - End If - End If - End If - -End Function - -Public Function FreeImage_CreateFromDC(ByVal hDC As Long, _ - Optional ByRef hBitmap As Long) As Long - -Dim tBM As BITMAP_API -Dim hDIB As Long -Dim lResult As Long -Dim nColors As Long -Dim lpInfo As Long - - ' Creates a FreeImage DIB from a Device Context/Compatible Bitmap. This - ' function returns a pointer to the DIB as, for instance, 'FreeImage_Load()' - ' does. So, this could be a real replacement for FreeImage_Load() or - ' 'FreeImage_CreateFromOlePicture()' when working with DCs and BITMAPs directly - - ' The 'hDC' parameter specifies a window device context (DC), the optional - ' parameter 'hBitmap' may specify a handle to a memory bitmap. When 'hBitmap' is - ' omitted, the bitmap currently selected into the given DC is used to create - ' the DIB. - - ' When 'hBitmap' is not missing but NULL (0), the function uses the DC's currently - ' selected bitmap. This bitmap's handle is stored in the ('ByRef'!) 'hBitmap' parameter - ' and so, is avaliable at the caller's site when the function returns. - - ' The DIB returned by this function is a copy of the image specified by 'hBitmap' or - ' the DC's current bitmap when 'hBitmap' is missing. The 'hDC' and also the 'hBitmap' - ' remain untouched in this function, there will be no objects destroyed or freed. - ' The caller is responsible to destroy or free the DC and BITMAP if necessary. - - ' first, check whether we got a hBitmap or not - If (hBitmap = 0) Then - ' if not, the parameter may be missing or is NULL so get the - ' DC's current bitmap - hBitmap = GetCurrentObject(hDC, OBJ_BITMAP) - End If - - lResult = GetObjectAPI(hBitmap, Len(tBM), tBM) - If (lResult) Then - hDIB = FreeImage_Allocate(tBM.bmWidth, _ - tBM.bmHeight, _ - tBM.bmBitsPixel) - If (hDIB) Then - ' The GetDIBits function clears the biClrUsed and biClrImportant BITMAPINFO - ' members (dont't know why). So we save these infos below. - ' This is needed for palletized images only. - nColors = FreeImage_GetColorsUsed(hDIB) - - lResult = GetDIBits(hDC, hBitmap, 0, _ - FreeImage_GetHeight(hDIB), _ - FreeImage_GetBits(hDIB), _ - FreeImage_GetInfo(hDIB), _ - DIB_RGB_COLORS) - - If (lResult) Then - FreeImage_CreateFromDC = hDIB - If (nColors) Then - ' restore BITMAPINFO members - ' FreeImage_GetInfo(Bitmap)->biClrUsed = nColors; - ' FreeImage_GetInfo(Bitmap)->biClrImportant = nColors; - lpInfo = FreeImage_GetInfo(hDIB) - Call CopyMemory(ByVal lpInfo + 32, nColors, 4) - Call CopyMemory(ByVal lpInfo + 36, nColors, 4) - End If - Else - Call FreeImage_Unload(hDIB) - End If - End If - End If - -End Function - -Public Function FreeImage_CreateFromImageContainer(ByRef Container As Object, _ - Optional ByVal IncludeDrawings As Boolean) As Long - - ' Creates a FreeImage DIB from a VB container control that has at least a - ' 'Picture' property. This function returns a pointer to the DIB as, for - ' instance, 'FreeImage_Load()' does. So, this could be a real replacement for - ' FreeImage_Load() or 'FreeImage_CreateFromOlePicture()' when working with - ' image hosting controls like Forms or PictureBoxes. - - ' The 'IncludeDrawings' parameter controls whether drawings, drawn with VB - ' methods like 'Container.Print()', 'Container.Line(x1, y1)-(x2, y2)' or - ' 'Container.Circle(x, y), radius' as the controls 'BackColor' should be included - ' into the newly created DIB. However, this only works, with control's that - ' have their 'AutoRedraw' property set to 'True'. - - ' To get the control's picture as well as it's BackColor and custom drawings, - ' this function uses the control's 'Image' property instead of the 'Picture' - ' property. - - ' This function treats Forms and PictureBox controls explicitly, since the - ' property sets and behaviours of these controls are publicly known. For any - ' other control, the function checks for the existence of an 'Image' and - ' 'AutoRedraw' property. If these are present and 'IncludeDrawings' is 'True', - ' the function uses the control's 'Image' property instead of the 'Picture' - ' property. This my be the case for UserControls. In any other case, the function - ' uses the control's 'Picture' property if present. If none of these properties - ' is present, a runtime error (5) is generated. - - ' Most of this function is actually implemented in the wrapper's private helper - ' function 'pGetIOlePictureFromContainer'. - - If (Not Container Is Nothing) Then - FreeImage_CreateFromImageContainer = FreeImage_CreateFromOlePicture( _ - pGetIOlePictureFromContainer(Container, _ - IncludeDrawings)) - End If - -End Function - -Public Function FreeImage_CreateFromScreen(Optional ByVal hWnd As Long, _ - Optional ByVal ClientAreaOnly As Boolean) As Long - -Dim hDC As Long -Dim lWidth As Long -Dim lHeight As Long -Dim hMemDC As Long -Dim hMemBMP As Long -Dim hMemOldBMP As Long -Dim tR As RECT - - ' Creates a FreeImage DIB from the screen which may either be the whole - ' desktop/screen or a certain window. A certain window may be specified - ' by it's window handle through the 'hWnd' parameter. By omitting this - ' parameter, the whole screen/desktop window will be captured. - - If (hWnd = 0) Then - hWnd = GetDesktopWindow() - hDC = GetDCEx(hWnd, 0, 0) - ' get desktop's width and height - lWidth = GetDeviceCaps(hDC, HORZRES) - lHeight = GetDeviceCaps(hDC, VERTRES) - - ElseIf (ClientAreaOnly) Then - ' get window's client area DC - hDC = GetDCEx(hWnd, 0, 0) - Call GetClientRect(hWnd, tR) - lWidth = tR.Right - lHeight = tR.Bottom - - Else - ' get window DC - hDC = GetDCEx(hWnd, 0, DCX_WINDOW) - Call GetWindowRect(hWnd, tR) - lWidth = tR.Right - tR.Left - lHeight = tR.Bottom - tR.Top - - End If - - ' create compatible memory DC and bitmap - hMemDC = CreateCompatibleDC(hDC) - hMemBMP = CreateCompatibleBitmap(hDC, lWidth, lHeight) - ' select compatible bitmap - hMemOldBMP = SelectObject(hMemDC, hMemBMP) - ' blit bits - Call BitBlt(hMemDC, 0, 0, lWidth, lHeight, hDC, 0, 0, SRCCOPY Or CAPTUREBLT) - - ' create FreeImage Bitmap from memory DC - FreeImage_CreateFromScreen = FreeImage_CreateFromDC(hMemDC, hMemBMP) - - ' clean up - Call SelectObject(hMemDC, hMemOldBMP) - Call DeleteObject(hMemBMP) - Call DeleteDC(hMemDC) - Call ReleaseDC(hWnd, hDC) - -End Function - -'-------------------------------------------------------------------------------- -' Microsoft Office / VBA PictureData supporting functions -'-------------------------------------------------------------------------------- - -Public Function FreeImage_GetPictureData(ByVal Bitmap As Long, _ - Optional ByVal UnloadSource As Boolean) As Byte() - -Dim abResult() As Byte -Dim lImageSize As Long -Dim lPaletteSize As Long -Dim abInfoBuffer() As Byte -Dim lpInfo As Long -Dim bBufferUsed As Boolean -Dim lOffset As Long - - ' This function creates an Office PictureData Byte array from a FreeImage DIB. - ' The original image must not remain valid nor loaded after the PictureData - ' array has been created. - - ' The optional 'UnloadSource' parameter is for unloading the original image - ' after the PictureData Byte array has been created, so you can easily "switch" - ' from a FreeImage DIB to an Office PictureData Byte array. There is no need to - ' unload the DIB at the caller's site if this argument is True. - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to create a PictureData array from a 'header-only' bitmap.") - End If - - lImageSize = FreeImage_GetHeight(Bitmap) * FreeImage_GetPitch(Bitmap) - lPaletteSize = FreeImage_GetColorsUsed(Bitmap) * 4 - - ' Copy the BITMAPINFOHEADER into the result array. -''' lpInfo = FreeImage_GetInfoEx(Bitmap, abInfoBuffer, bBufferUsed) -''' If (bBufferUsed) Then -''' ReDim abResult(39 + 12 + lPaletteSize + lImageSize) -''' Call CopyMemory(abResult(0), ByVal lpInfo, 40 + 12) -''' lOffset = 40 + 12 -''' Else -''' ReDim abResult(39 + lPaletteSize + lImageSize) -''' Call CopyMemory(abResult(0), ByVal lpInfo, 40) -''' lOffset = 40 -''' End If - - If (lPaletteSize > 0) Then - ' Copy the image's palette (if any) into the result array. - Call CopyMemory(abResult(lOffset), ByVal FreeImage_GetPalette(Bitmap), lPaletteSize) - lOffset = lOffset + lPaletteSize - End If - - ' Copy the image's bits into the result array. - Call CopyMemory(abResult(lOffset), ByVal FreeImage_GetBits(Bitmap), lImageSize) - - Call pSwap(ByVal VarPtrArray(abResult), ByVal VarPtrArray(FreeImage_GetPictureData)) - - If (UnloadSource) Then - Call FreeImage_Unload(Bitmap) - End If - End If - -End Function - -Public Function FreeImage_CreateFromPictureData(ByRef PictureData() As Byte) As Long - -Dim tBMIH As BITMAPINFOHEADER -Dim lLength As Long -Dim hDIB As Long -Dim lPaletteSize As Long -Dim lOffset As Long -Dim alMasks() As Long - - ' Creates a FreeImage DIB from an Office PictureData Byte array. This function - ' returns a pointer to the DIB as, for instance, the FreeImage function - ' 'FreeImage_Load' does. So, this could be a real replacement for 'FreeImage_Load' - ' when working with PictureData arrays. - - lLength = UBound(PictureData) + 1 - If (lLength > Len(tBMIH)) Then - Call CopyMemory(tBMIH, PictureData(0), Len(tBMIH)) - With tBMIH - If (.biSize = 40) Then - lOffset = 40 - Select Case .biBitCount - - Case 0 - - Case 1, 4, 8 - If (.biClrUsed = 0) Then - lPaletteSize = 2 ^ .biBitCount * 4 - Else - lPaletteSize = .biClrUsed * 4 - End If - hDIB = FreeImage_Allocate(.biWidth, .biHeight, .biBitCount) - Call CopyMemory(ByVal FreeImage_GetPalette(hDIB), _ - PictureData(lOffset), lPaletteSize) - lOffset = lOffset + lPaletteSize - - Case 16 - If (.biCompression = BI_BITFIELDS) Then - ReDim alMasks(2) - Call CopyMemory(alMasks(0), PictureData(lOffset), 12) - lOffset = lOffset + 12 - hDIB = FreeImage_Allocate(.biWidth, .biHeight, .biBitCount, _ - alMasks(0), alMasks(1), alMasks(2)) - Else - hDIB = FreeImage_Allocate(.biWidth, .biHeight, .biBitCount, _ - FI16_555_RED_MASK, FI16_555_GREEN_MASK, FI16_555_BLUE_MASK) - End If - - Case 24, 32 - hDIB = FreeImage_Allocate(.biWidth, .biHeight, .biBitCount) - - End Select - - If (hDIB) Then - Call CopyMemory(ByVal FreeImage_GetBits(hDIB), _ - PictureData(lOffset), lLength - lOffset) - FreeImage_CreateFromPictureData = hDIB - End If - Else - ' ERROR: invalid or unsupported PictureData array - End If - End With - Else - ' ERROR: invalid or unsupported PictureData array - End If - -End Function - -Public Function FreeImage_CreateMask(ByVal hDIB As Long, _ - Optional ByVal eMaskCreationOptions As FREE_IMAGE_MASK_CREATION_OPTION_FLAGS = MCOF_CREATE_MASK_IMAGE, _ - Optional ByVal lBitDepth As Long = 1, _ - Optional ByVal eMaskOptions As FREE_IMAGE_MASK_FLAGS = FIMF_MASK_FULL_TRANSPARENCY, _ - Optional ByVal vntMaskColors As Variant, _ - Optional ByVal eMaskColorsFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ - Optional ByVal lColorTolerance As Long, _ - Optional ByVal lciMaskColorDst As Long = vbWhite, _ - Optional ByVal eMaskColorDstFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ - Optional ByVal lciUnmaskColorDst As Long = vbBlack, _ - Optional ByVal eUnmaskColorDstFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ - Optional ByVal vlciMaskColorSrc As Variant, _ - Optional ByVal eMaskColorSrcFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ - Optional ByVal vlciUnmaskColorSrc As Variant, _ - Optional ByVal eUnmaskColorSrcFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB) As Long - -Dim hDIBResult As Long -Dim lBitDepthSrc As Long -Dim lWidth As Long -Dim lHeight As Long - -Dim bMaskColors As Boolean -Dim bMaskTransparency As Boolean -Dim bMaskFullTransparency As Boolean -Dim bMaskAlphaTransparency As Boolean -Dim bInvertMask As Boolean -Dim bHaveMaskColorSrc As Boolean -Dim bHaveUnmaskColorSrc As Boolean -Dim bCreateMaskImage As Boolean -Dim bModifySourceImage As Boolean -Dim alcMaskColors() As Long -Dim lMaskColorsMaxIndex As Long - -Dim lciMaskColorSrc As Long -Dim lciUnmaskColorSrc As Long - -Dim alPaletteSrc() As Long -Dim abTransparencyTableSrc() As Byte -Dim abBitsBSrc() As Byte -Dim atBitsTSrc As ScanLinesRGBTRIBLE -Dim atBitsQSrc() As RGBQUAD -Dim abBitValues(7) As Byte -Dim abBitMasks(7) As Byte -Dim abBitShifts(7) As Byte - -Dim atPaletteDst() As RGBQUAD -Dim abBitsBDst() As Byte -Dim atBitsTDst As ScanLinesRGBTRIBLE -Dim atBitsQDst() As RGBQUAD - -Dim bMaskPixel As Boolean -Dim X As Long -Dim x2 As Long -Dim lPixelIndex As Long -Dim Y As Long -Dim i As Long - - 'TODO: comment this function - - ' check for a proper bit depth of the destination (mask) image - If ((hDIB) And ((lBitDepth = 1) Or _ - (lBitDepth = 4) Or _ - (lBitDepth = 8) Or _ - (lBitDepth = 24) Or _ - (lBitDepth = 32))) Then - - If (Not FreeImage_HasPixels(hDIB)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to create a mask image from a 'header-only' bitmap.") - End If - - ' check for a proper bit depth of the source image - lBitDepthSrc = FreeImage_GetBPP(hDIB) - If ((lBitDepthSrc = 4) Or _ - (lBitDepthSrc = 8) Or _ - (lBitDepthSrc = 24) Or _ - (lBitDepthSrc = 32)) Then - - - ' get some information from eMaskCreationOptions - bCreateMaskImage = (eMaskCreationOptions And MCOF_CREATE_MASK_IMAGE) - bModifySourceImage = (eMaskCreationOptions And MCOF_MODIFY_SOURCE_IMAGE) - - - If (bCreateMaskImage) Then - - ' check mask color format - If (eMaskColorDstFormat And FICFF_COLOR_BGR) Then - ' if mask color is in BGR format, convert to RGB format - lciMaskColorDst = FreeImage_SwapColorLong(lciMaskColorDst) - - ElseIf (eMaskColorDstFormat And FICFF_COLOR_PALETTE_INDEX) Then - ' if mask color is specified as palette index, check, whether the - ' source image is a palletized image - Select Case lBitDepthSrc - - Case 1 - lciMaskColorDst = FreeImage_GetPaletteExLong(hDIB)(lciMaskColorDst And &H1) - - Case 4 - lciMaskColorDst = FreeImage_GetPaletteExLong(hDIB)(lciMaskColorDst And &HF) - - Case 8 - lciMaskColorDst = FreeImage_GetPaletteExLong(hDIB)(lciMaskColorDst And &HFF) - - End Select - End If - - ' check unmask color format - If (eUnmaskColorDstFormat And FICFF_COLOR_BGR) Then - ' if unmask color is in BGR format, convert to RGB format - lciUnmaskColorDst = FreeImage_SwapColorLong(lciUnmaskColorDst) - - ElseIf (eUnmaskColorDstFormat And FICFF_COLOR_PALETTE_INDEX) Then - ' if unmask color is specified as palette index, check, whether the - ' source image is a palletized image - Select Case lBitDepthSrc - - Case 1 - lciUnmaskColorDst = FreeImage_GetPaletteExLong(hDIB)(lciUnmaskColorDst And &H1) - - Case 4 - lciUnmaskColorDst = FreeImage_GetPaletteExLong(hDIB)(lciUnmaskColorDst And &HF) - - Case 8 - lciUnmaskColorDst = FreeImage_GetPaletteExLong(hDIB)(lciUnmaskColorDst And &HFF) - - End Select - End If - End If - - - If (bModifySourceImage) Then - - ' check, whether source image can be modified - bHaveMaskColorSrc = (Not IsMissing(vlciMaskColorSrc)) - bHaveUnmaskColorSrc = (Not IsMissing(vlciUnmaskColorSrc)) - - Select Case lBitDepthSrc - - Case 4, 8 - If (bHaveMaskColorSrc) Then - - ' get mask color as Long - lciMaskColorSrc = vlciMaskColorSrc - - If (eMaskColorSrcFormat And FICFF_COLOR_PALETTE_INDEX) Then - If (lBitDepthSrc = 4) Then - lciMaskColorSrc = (lciMaskColorSrc And &HF) - Else - lciMaskColorSrc = (lciMaskColorSrc And &HFF) - End If - Else - If (eMaskColorSrcFormat And FICFF_COLOR_BGR) Then - lciMaskColorSrc = FreeImage_SwapColorLong(lciMaskColorSrc, True) - End If - lciMaskColorSrc = FreeImage_SearchPalette(hDIB, lciMaskColorSrc) - bHaveMaskColorSrc = (lciMaskColorSrc <> -1) - End If - End If - - If (bHaveUnmaskColorSrc) Then - - ' get unmask color as Long - lciUnmaskColorSrc = vlciUnmaskColorSrc - - If (eUnmaskColorSrcFormat And FICFF_COLOR_PALETTE_INDEX) Then - If (lBitDepthSrc = 4) Then - lciUnmaskColorSrc = (lciUnmaskColorSrc And &HF) - Else - lciUnmaskColorSrc = (lciUnmaskColorSrc And &HFF) - End If - Else - If (eUnmaskColorSrcFormat And FICFF_COLOR_BGR) Then - lciUnmaskColorSrc = FreeImage_SwapColorLong(lciUnmaskColorSrc, True) - End If - lciUnmaskColorSrc = FreeImage_SearchPalette(hDIB, lciUnmaskColorSrc) - bHaveUnmaskColorSrc = (lciUnmaskColorSrc <> -1) - End If - End If - - ' check, if source image still can be modified in any way - bModifySourceImage = (bHaveMaskColorSrc Or bHaveUnmaskColorSrc) - - Case 24, 32 - If (bHaveMaskColorSrc) Then - - ' get mask color as Long - lciMaskColorSrc = vlciMaskColorSrc - - If (eMaskColorSrcFormat And FICFF_COLOR_BGR) Then - lciMaskColorSrc = FreeImage_SwapColorLong(lciMaskColorSrc, (lBitDepthSrc = 24)) - End If - End If - - If (bHaveUnmaskColorSrc) Then - - ' get unmask color as Long - lciUnmaskColorSrc = vlciUnmaskColorSrc - - If (eUnmaskColorSrcFormat And FICFF_COLOR_BGR) Then - lciUnmaskColorSrc = FreeImage_SwapColorLong(lciUnmaskColorSrc, (lBitDepthSrc = 24)) - End If - End If - - End Select - - End If - - - If ((bModifySourceImage) Or (bCreateMaskImage)) Then - - ' get some information from eMaskOptions - - ' check for inverse mask - bInvertMask = (eMaskOptions And FIMF_MASK_INVERSE_MASK) - - ' check for mask colors - bMaskColors = (eMaskOptions And FIMF_MASK_COLOR_TRANSPARENCY) - bMaskColors = bMaskColors And (Not IsMissing(vntMaskColors)) - If (bMaskColors) Then - ' validate specified mask colors; all mask colors are transferred to - ' an internal array of type Long - If (Not IsArray(vntMaskColors)) Then - ' color masking is only done when the single mask color is - ' a numeric (color) value - bMaskColors = IsNumeric(vntMaskColors) - If (bMaskColors) Then - ' this is not an array of mask colors but only a single - ' color; this is also transferred into an internal array - lMaskColorsMaxIndex = 0 - ReDim alcMaskColors(lMaskColorsMaxIndex) - alcMaskColors(lMaskColorsMaxIndex) = vntMaskColors - End If - Else - ' transfer all valid color values (numeric) into an internal - ' array - ReDim alcMaskColors(UBound(vntMaskColors)) - For i = LBound(vntMaskColors) To UBound(vntMaskColors) - bMaskColors = (IsNumeric(vntMaskColors(i))) - If (Not bMaskColors) Then - Exit For - Else - alcMaskColors(lMaskColorsMaxIndex) = vntMaskColors(i) - lMaskColorsMaxIndex = lMaskColorsMaxIndex + 1 - End If - Next i - If (bMaskColors) Then - lMaskColorsMaxIndex = lMaskColorsMaxIndex - 1 - End If - End If - End If - - ' check for transparency options - If ((FreeImage_IsTransparent(hDIB)) Or _ - ((eMaskOptions And FIMF_MASK_FORCE_TRANSPARENCY) > 0)) Then - bMaskFullTransparency = (eMaskOptions And FIMF_MASK_FULL_TRANSPARENCY) - bMaskAlphaTransparency = (eMaskOptions And FIMF_MASK_ALPHA_TRANSPARENCY) - bMaskTransparency = (bMaskFullTransparency Or bMaskAlphaTransparency) - End If - - ' get image dimension - lWidth = FreeImage_GetWidth(hDIB) - lHeight = FreeImage_GetHeight(hDIB) - - ' create proper accessors for the source image - Select Case lBitDepthSrc - - Case 4, 8 - ' images with a bit depth of 4 or 8 bits will both be - ' read through a byte array - abBitsBSrc = FreeImage_GetBitsEx(hDIB) - ' depending on where to get the transparency information from, - ' a palette or a transpareny table will be needed - If (bMaskColors) Then - alPaletteSrc = FreeImage_GetPaletteExLong(hDIB) - End If - If (bMaskTransparency) Then - abTransparencyTableSrc = FreeImage_GetTransparencyTableExClone(hDIB) - End If - - ' for 4 bit source images - If (lBitDepthSrc = 4) Then - ' two additional arrays need to be filled with values - ' to mask and shift nibbles to bytes - ' index 0 stands for the high nibble of the byte - abBitMasks(0) = &HF0 - abBitShifts(0) = &H10 ' a shift to right is implemented - ' as division in VB - ' index 1 stands for the low nibble of the byte - abBitMasks(1) = &HF - abBitShifts(1) = &H1 ' no shift needed for low nibble - End If - - Case 24 - ' images with a depth of 24 bits could not be used - ' through a two dimensional array in most cases, so get - ' an array of individual scanlines (see remarks concerning - ' pitch at function 'FreeImage_GetBitsExRGBTriple()') - Call FreeImage_GetScanLinesRGBTRIPLE(hDIB, atBitsTSrc) - - Case 32 - atBitsQSrc = FreeImage_GetBitsExRGBQUAD(hDIB) - - End Select - - - ' create mask image if needed - If (bCreateMaskImage) Then - - ' create mask image - hDIBResult = FreeImage_Allocate(lWidth, lHeight, lBitDepth) - ' if destination bit depth is 8 or below, a proper palette will - ' be needed, so create a palette where the unmask color is at - ' index 0 and the mask color is at index 1 - If (lBitDepth <= 8) Then - atPaletteDst = FreeImage_GetPaletteEx(hDIBResult) - Call CopyMemory(atPaletteDst(0), lciUnmaskColorDst, 4) - Call CopyMemory(atPaletteDst(1), lciMaskColorDst, 4) - End If - - ' create proper accessors for the new mask image - Select Case lBitDepth - - Case 1 - abBitsBDst = FreeImage_GetBitsEx(hDIBResult) - X = 1 - For i = 7 To 0 Step -1 - abBitValues(i) = X - X = X * 2 - Next i - - Case 4 - abBitsBDst = FreeImage_GetBitsEx(hDIBResult) - abBitValues(0) = &H10 - abBitValues(1) = &H1 - - Case 8 - abBitsBDst = FreeImage_GetBitsEx(hDIBResult) - - Case 24 - ' images with a depth of 24 bits could not be used - ' through a two dimensional array in most cases, so get - ' an array of individual scanlines (see remarks concerning - ' pitch at function 'FreeImage_GetBitsExRGBTriple()') - Call FreeImage_GetScanLinesRGBTRIPLE(hDIBResult, atBitsTDst) - - Case 32 - atBitsQDst = FreeImage_GetBitsExRGBQUAD(hDIBResult) - - End Select - End If - - ' walk the hole image - For Y = 0 To lHeight - 1 - For X = 0 To lWidth - 1 - - ' should transparency information be considered to create - ' the mask? - If (bMaskTransparency) Then - - Select Case lBitDepthSrc - - Case 4 - x2 = X \ 2 - lPixelIndex = (abBitsBSrc(x2, Y) And abBitMasks(X Mod 2)) \ abBitShifts(X Mod 2) - bMaskPixel = (abTransparencyTableSrc(lPixelIndex) = 0) - If (Not bMaskPixel) Then - bMaskPixel = ((abTransparencyTableSrc(lPixelIndex) < 255) And _ - (bMaskAlphaTransparency)) - End If - - Case 8 - bMaskPixel = (abTransparencyTableSrc(abBitsBSrc(X, Y)) = 0) - If (Not bMaskPixel) Then - bMaskPixel = ((abTransparencyTableSrc(abBitsBSrc(X, Y)) < 255) And _ - (bMaskAlphaTransparency)) - End If - - Case 24 - ' no transparency information in 24 bit images - ' reset bMaskPixel - bMaskPixel = False - - Case 32 - bMaskPixel = (atBitsQSrc(X, Y).rgbReserved = 0) - If (Not bMaskPixel) Then - bMaskPixel = ((atBitsQSrc(X, Y).rgbReserved < 255) And _ - (bMaskAlphaTransparency)) - End If - - End Select - Else - ' clear 'bMaskPixel' if no transparency information was checked - ' since the flag might be still True from the last loop - bMaskPixel = False - End If - - ' should color information be considered to create the mask? - ' do this only if the current pixel is not yet part of the mask - If ((bMaskColors) And (Not bMaskPixel)) Then - - Select Case lBitDepthSrc - - Case 4 - x2 = X \ 2 - lPixelIndex = (abBitsBSrc(x2, Y) And abBitMasks(X Mod 2)) \ abBitShifts(X Mod 2) - If (eMaskColorsFormat And FICFF_COLOR_PALETTE_INDEX) Then - For i = 0 To lMaskColorsMaxIndex - If (lColorTolerance = 0) Then - bMaskPixel = (lPixelIndex = alcMaskColors(i)) - Else - bMaskPixel = (FreeImage_CompareColorsLongLong( _ - alPaletteSrc(lPixelIndex), _ - alPaletteSrc(alcMaskColors(i)), _ - lColorTolerance, _ - FICFF_COLOR_RGB, FICFF_COLOR_RGB) = 0) - End If - If (bMaskPixel) Then - Exit For - End If - Next i - Else - For i = 0 To lMaskColorsMaxIndex - bMaskPixel = (FreeImage_CompareColorsLongLong( _ - alPaletteSrc(lPixelIndex), _ - alcMaskColors(i), lColorTolerance, _ - FICFF_COLOR_RGB, _ - (eMaskColorsFormat And FICFF_COLOR_FORMAT_ORDER_MASK)) = 0) - If (bMaskPixel) Then - Exit For - End If - Next i - End If - - Case 8 - If (eMaskColorsFormat And FICFF_COLOR_PALETTE_INDEX) Then - For i = 0 To lMaskColorsMaxIndex - If (lColorTolerance = 0) Then - bMaskPixel = (abBitsBSrc(X, Y) = alcMaskColors(i)) - Else - bMaskPixel = (FreeImage_CompareColorsLongLong( _ - alPaletteSrc(abBitsBSrc(X, Y)), _ - alPaletteSrc(alcMaskColors(i)), _ - lColorTolerance, _ - FICFF_COLOR_RGB, FICFF_COLOR_RGB) = 0) - End If - If (bMaskPixel) Then - Exit For - End If - Next i - Else - For i = 0 To lMaskColorsMaxIndex - bMaskPixel = (FreeImage_CompareColorsLongLong( _ - alPaletteSrc(abBitsBSrc(X, Y)), _ - alcMaskColors(i), lColorTolerance, _ - FICFF_COLOR_RGB, _ - (eMaskColorsFormat And FICFF_COLOR_FORMAT_ORDER_MASK)) = 0) - If (bMaskPixel) Then - Exit For - End If - Next i - End If - - Case 24 - For i = 0 To lMaskColorsMaxIndex - bMaskPixel = (FreeImage_CompareColorsRGBTRIPLELong( _ - atBitsTSrc.Scanline(Y).Data(X), _ - alcMaskColors(i), lColorTolerance, _ - (eMaskColorsFormat And FICFF_COLOR_FORMAT_ORDER_MASK)) = 0) - If (bMaskPixel) Then - Exit For - End If - Next i - - Case 32 - For i = 0 To lMaskColorsMaxIndex - bMaskPixel = (FreeImage_CompareColorsRGBQUADLong( _ - atBitsQSrc(X, Y), _ - alcMaskColors(i), lColorTolerance, _ - (eMaskColorsFormat And FICFF_COLOR_FORMAT_ORDER_MASK)) = 0) - If (bMaskPixel) Then - Exit For - End If - Next i - - End Select - - End If - - ' check whether a mask image needs to be created - If (bCreateMaskImage) Then - - ' write current pixel to destination (mask) image - Select Case lBitDepth - - Case 1 - x2 = X \ 8 - If ((bMaskPixel) Xor (bInvertMask)) Then - abBitsBDst(x2, Y) = abBitsBDst(x2, Y) Or abBitValues(X Mod 8) - End If - - Case 4 - x2 = X \ 2 - If ((bMaskPixel) Xor (bInvertMask)) Then - abBitsBDst(x2, Y) = abBitsBDst(x2, Y) Or abBitValues(X Mod 2) - End If - - Case 8 - If ((bMaskPixel) Xor (bInvertMask)) Then - abBitsBDst(X, Y) = 1 - End If - - Case 24 - If ((bMaskPixel) Xor (bInvertMask)) Then - Call CopyMemory(atBitsTDst.Scanline(Y).Data(X), lciMaskColorDst, 3) - Else - Call CopyMemory(atBitsTDst.Scanline(Y).Data(X), lciUnmaskColorDst, 3) - End If - - Case 32 - If ((bMaskPixel) Xor (bInvertMask)) Then - Call CopyMemory(atBitsQDst(X, Y), lciMaskColorDst, 4) - Else - Call CopyMemory(atBitsQDst(X, Y), lciUnmaskColorDst, 4) - End If - - End Select - End If - - ' check whether a source image needs to be modified - If (bModifySourceImage) Then - - Select Case lBitDepthSrc - - Case 4 - x2 = X \ 2 - If ((bMaskPixel) Xor (bInvertMask)) Then - If (bHaveMaskColorSrc) Then - abBitsBSrc(x2, Y) = _ - (abBitsBSrc(x2, Y) And (Not abBitMasks(X Mod 2))) Or _ - (lciMaskColorSrc * abBitShifts(X Mod 2)) - End If - ElseIf (bHaveUnmaskColorSrc) Then - abBitsBSrc(x2, Y) = _ - (abBitsBSrc(x2, Y) And (Not abBitMasks(X Mod 2))) Or _ - (lciUnmaskColorSrc * abBitShifts(X Mod 2)) - End If - - Case 8 - If ((bMaskPixel) Xor (bInvertMask)) Then - If (bHaveMaskColorSrc) Then - abBitsBSrc(X, Y) = lciMaskColorSrc - End If - ElseIf (bHaveUnmaskColorSrc) Then - abBitsBSrc(X, Y) = lciUnmaskColorSrc - End If - - Case 24 - If ((bMaskPixel) Xor (bInvertMask)) Then - If (bHaveMaskColorSrc) Then - Call CopyMemory(atBitsTSrc.Scanline(Y).Data(X), lciMaskColorSrc, 3) - End If - ElseIf (bHaveUnmaskColorSrc) Then - Call CopyMemory(atBitsTSrc.Scanline(Y).Data(X), lciUnmaskColorSrc, 3) - End If - - Case 32 - If ((bMaskPixel) Xor (bInvertMask)) Then - If (bHaveMaskColorSrc) Then - Call CopyMemory(atBitsQSrc(X, Y), lciMaskColorSrc, 4) - End If - ElseIf (bHaveUnmaskColorSrc) Then - Call CopyMemory(atBitsQSrc(X, Y), lciUnmaskColorSrc, 4) - End If - - End Select - End If - - Next X - Next Y - End If - End If - End If - - FreeImage_CreateMask = hDIBResult - -End Function - -Public Function FreeImage_CreateMaskImage(ByVal hDIB As Long, _ - Optional ByVal lBitDepth As Long = 1, _ - Optional ByVal eMaskOptions As FREE_IMAGE_MASK_FLAGS = FIMF_MASK_FULL_TRANSPARENCY, _ - Optional ByVal vntMaskColors As Variant, _ - Optional ByVal eMaskColorsFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ - Optional ByVal lColorTolerance As Long, _ - Optional ByVal lciMaskColor As Long = vbWhite, _ - Optional ByVal eMaskColorFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ - Optional ByVal lciUnmaskColor As Long = vbBlack, _ - Optional ByVal eUnmaskColorFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB) As Long - - 'TODO: comment this function - - FreeImage_CreateMaskImage = FreeImage_CreateMask(hDIB, MCOF_CREATE_MASK_IMAGE, _ - lBitDepth, eMaskOptions, _ - vntMaskColors, eMaskColorsFormat, _ - lColorTolerance, _ - lciMaskColor, eMaskColorFormat, _ - lciUnmaskColor, eUnmaskColorFormat) - -End Function - -Public Function FreeImage_CreateSimpleBWMaskImage(ByVal hDIB As Long, _ - Optional ByVal lBitDepth As Long = 1, _ - Optional ByVal eMaskOptions As FREE_IMAGE_MASK_FLAGS = FIMF_MASK_FULL_TRANSPARENCY, _ - Optional ByVal vntMaskColors As Variant, _ - Optional ByVal eMaskColorsFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ - Optional ByVal lColorTolerance As Long) As Long - - 'TODO: comment this function - - FreeImage_CreateSimpleBWMaskImage = FreeImage_CreateMask(hDIB, MCOF_CREATE_MASK_IMAGE, _ - lBitDepth, eMaskOptions, _ - vntMaskColors, eMaskColorsFormat, _ - lColorTolerance, _ - vbWhite, FICFF_COLOR_RGB, _ - vbBlack, FICFF_COLOR_RGB) - -End Function - -Public Function FreeImage_CreateMaskInPlace(ByVal hDIB As Long, _ - Optional ByVal lBitDepth As Long = 1, _ - Optional ByVal eMaskOptions As FREE_IMAGE_MASK_FLAGS = FIMF_MASK_FULL_TRANSPARENCY, _ - Optional ByVal vntMaskColors As Variant, _ - Optional ByVal eMaskColorsFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ - Optional ByVal lColorTolerance As Long, _ - Optional ByVal vlciMaskColor As Variant, _ - Optional ByVal eMaskColorFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ - Optional ByVal vlciUnmaskColor As Variant, _ - Optional ByVal eUnmaskColorFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB) As Long - - 'TODO: comment this function - - FreeImage_CreateMaskInPlace = FreeImage_CreateMask(hDIB, MCOF_MODIFY_SOURCE_IMAGE, _ - lBitDepth, eMaskOptions, _ - vntMaskColors, eMaskColorsFormat, _ - lColorTolerance, _ - , , , , _ - vlciMaskColor, eMaskColorFormat, _ - vlciUnmaskColor, eUnmaskColorFormat) - -End Function - -Public Function FreeImage_CreateSimpleBWMaskInPlace(ByVal hDIB As Long, _ - Optional ByVal lBitDepth As Long = 1, _ - Optional ByVal eMaskOptions As FREE_IMAGE_MASK_FLAGS = FIMF_MASK_FULL_TRANSPARENCY, _ - Optional ByVal vntMaskColors As Variant, _ - Optional ByVal eMaskColorsFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ - Optional ByVal lColorTolerance As Long) As Long - - 'TODO: comment this function - - FreeImage_CreateSimpleBWMaskInPlace = FreeImage_CreateMask(hDIB, MCOF_MODIFY_SOURCE_IMAGE, _ - lBitDepth, eMaskOptions, _ - vntMaskColors, eMaskColorsFormat, _ - lColorTolerance, _ - , , , , _ - vbWhite, FICFF_COLOR_RGB, _ - vbBlack, FICFF_COLOR_RGB) - -End Function - -Public Function FreeImage_CreateMaskColors(ParamArray MaskColors() As Variant) As Variant - - ' this is just a FreeImage signed function that emulates VB's - ' builtin Array() function, that makes a variant array from - ' a ParamArray; so, a caller of the FreeImage_CreateMask() function - ' can specify all mask colors inline in the call statement - - ' hDibMask = FreeImage_CreateMask(hDib, 1, FIMF_MASK_COLOR_TRANSPARENCY, _ - ' FreeImage_CreateMaskColors(vbRed, vbGreen, vbBlack), _ - ' FICFF_COLOR_BGR, .... ) - - ' keep in mind, that VB colors (vbRed, vbBlue, etc.) are OLE colors that have - ' BRG format - - FreeImage_CreateMaskColors = MaskColors - -End Function - -Public Function FreeImage_SwapColorLong(ByVal Color As Long, _ - Optional ByVal IgnoreAlpha As Boolean) As Long - - ' This function swaps both color components Red (R) and Blue (B) in either - ' and RGB or BGR format color value stored in a Long value. This function is - ' used to convert from a RGB to a BGR color value and vice versa. - - If (Not IgnoreAlpha) Then - FreeImage_SwapColorLong = ((Color And &HFF000000) Or _ - ((Color And &HFF&) * &H10000) Or _ - (Color And &HFF00&) Or _ - ((Color And &HFF0000) \ &H10000)) - Else - FreeImage_SwapColorLong = (((Color And &HFF&) * &H10000) Or _ - (Color And &HFF00&) Or _ - ((Color And &HFF0000) \ &H10000)) - End If - -End Function - -Public Function FreeImage_CompareColorsLongLong(ByVal ColorA As Long, _ - ByVal ColorB As Long, _ - Optional ByVal Tolerance As Long, _ - Optional ByVal ColorTypeA As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_ARGB, _ - Optional ByVal ColorTypeB As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_ARGB) As Long - -Dim bFormatEqual As Boolean -Dim bAlphaEqual As Boolean - - ' This function compares two colors that both are specified as a 32 bit Long - ' value. - - ' Use both parameters 'ColorTypeA' and 'ColorTypeB' to specify each color's - ' format and 'Tolerance' to specify the matching tolerance. - - ' The function returns the result of the mathematical substraction - ' ColorA - ColorB, so if both colors are equal, the function returns NULL (0) - ' and any other value if both colors are different. Alpha transparency is taken into - ' account only if both colors are said to have an alpha transparency component by - ' both parameters 'ColorTypeA' and 'ColorTypeB'. If at least one of both colors - ' has no alpha transparency component, the comparison only includes the bits for - ' the red, green and blue component. - - ' The matching tolerance is applied to each color component (red, green, blue and - ' alpha) separately. So, when 'Tolerance' contains a value greater than zero, the - ' function returns NULL (0) when either both colors are exactly the same or the - ' differences of each corresponding color components are smaller or equal than - ' the given tolerance value. - - - If (((ColorTypeA And FICFF_COLOR_PALETTE_INDEX) Or _ - (ColorTypeB And FICFF_COLOR_PALETTE_INDEX)) = 0) Then - - bFormatEqual = ((ColorTypeA And FICFF_COLOR_FORMAT_ORDER_MASK) = _ - (ColorTypeB And FICFF_COLOR_FORMAT_ORDER_MASK)) - - bAlphaEqual = ((ColorTypeA And FICFF_COLOR_HAS_ALPHA) And _ - (ColorTypeB And FICFF_COLOR_HAS_ALPHA)) - - If (bFormatEqual) Then - If (bAlphaEqual) Then - FreeImage_CompareColorsLongLong = ColorA - ColorB - Else - FreeImage_CompareColorsLongLong = (ColorA And &HFFFFFF) - (ColorB And &HFFFFFF) - End If - Else - If (bAlphaEqual) Then - FreeImage_CompareColorsLongLong = ColorA - ((ColorB And &HFF000000) Or _ - ((ColorB And &HFF&) * &H10000) Or _ - (ColorB And &HFF00&) Or _ - ((ColorB And &HFF0000) \ &H10000)) - Else - FreeImage_CompareColorsLongLong = (ColorA And &HFFFFFF) - _ - (((ColorB And &HFF&) * &H10000) Or _ - (ColorB And &HFF00&) Or _ - ((ColorB And &HFF0000) \ &H10000)) - End If - End If - - If ((Tolerance > 0) And (FreeImage_CompareColorsLongLong <> 0)) Then - If (bFormatEqual) Then - If (Abs(((ColorA \ &H10000) And &HFF) - ((ColorB \ &H10000) And &HFF)) <= Tolerance) Then - If (Abs(((ColorA \ &H100) And &HFF) - ((ColorB \ &H100) And &HFF)) <= Tolerance) Then - If (Abs((ColorA And &HFF) - (ColorB And &HFF)) <= Tolerance) Then - If (bAlphaEqual) Then - If (Abs(((ColorA \ &H1000000) And &HFF) - _ - ((ColorB \ &H1000000) And &HFF)) <= Tolerance) Then - FreeImage_CompareColorsLongLong = 0 - End If - Else - FreeImage_CompareColorsLongLong = 0 - End If - End If - End If - End If - Else - If (Abs(((ColorA \ &H10000) And &HFF) - (ColorB And &HFF)) <= Tolerance) Then - If (Abs(((ColorA \ &H100) And &HFF) - ((ColorB \ &H100) And &HFF)) <= Tolerance) Then - If (Abs((ColorA And &HFF) - ((ColorB \ &H10000) And &HFF)) <= Tolerance) Then - If (bAlphaEqual) Then - If (Abs(((ColorA \ &H1000000) And &HFF) - _ - ((ColorB \ &H1000000) And &HFF)) <= Tolerance) Then - FreeImage_CompareColorsLongLong = 0 - End If - Else - FreeImage_CompareColorsLongLong = 0 - End If - End If - End If - End If - End If - End If - End If - -End Function - -Public Function FreeImage_CompareColorsRGBTRIPLELong(ByRef ColorA As RGBTRIPLE, _ - ByVal ColorB As Long, _ - Optional ByVal Tolerance As Long, _ - Optional ByVal ColorTypeB As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB) As Long - -Dim lcColorA As Long - - ' This is a function derived from 'FreeImage_CompareColorsLongLong()' to make color - ' comparisons between two colors whereby one color is provided as RGBTRIPLE and the - ' other color is provided as Long value. - - ' Have a look at the documentation of 'FreeImage_CompareColorsLongLong()' to learn - ' more about color comparisons. - - Call CopyMemory(lcColorA, ColorA, 3) - FreeImage_CompareColorsRGBTRIPLELong = FreeImage_CompareColorsLongLong(lcColorA, ColorB, _ - Tolerance, FICFF_COLOR_RGB, ColorTypeB) - -End Function - -Public Function FreeImage_CompareColorsRGBQUADLong(ByRef ColorA As RGBQUAD, _ - ByVal ColorB As Long, _ - Optional ByVal Tolerance As Long, _ - Optional ByVal ColorTypeB As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_ARGB) As Long - -Dim lcColorA As Long - - ' This is a function derived from 'FreeImage_CompareColorsLongLong()' to make color - ' comparisons between two colors whereby one color is provided as RGBQUAD and the - ' other color is provided as Long value. - - ' Have a look at the documentation of 'FreeImage_CompareColorsLongLong()' to learn - ' more about color comparisons. - - Call CopyMemory(lcColorA, ColorA, 4) - FreeImage_CompareColorsRGBQUADLong = FreeImage_CompareColorsLongLong(lcColorA, ColorB, _ - Tolerance, FICFF_COLOR_ARGB, ColorTypeB) - -End Function - -Public Function FreeImage_SearchPalette(ByVal Bitmap As Long, _ - ByVal Color As Long, _ - Optional ByVal Tolerance As Long, _ - Optional ByVal ColorType As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ - Optional ByVal TransparencyState As FREE_IMAGE_TRANSPARENCY_STATE_FLAGS = FITSF_IGNORE_TRANSPARENCY) As Long - -Dim abTransparencyTable() As Byte -Dim alPalette() As Long -Dim i As Long - - ' This function searches an image's color palette for a certain color specified as a - ' 32 bit Long value in either RGB or BGR format. - - ' A search tolerance may be specified in the 'Tolerance' parameter. - - ' If no transparency tabe was found for the specified image, transparency information will - ' be ignored during the search. Then, the function behaves as if FITSF_IGNORE_TRANSPARENCY - ' was specified for parameter TransparencyState. - - ' Use the 'TransparencyState' parameter to control, how the transparency state of - ' the found palette entry affects the result. These values may be used: - - ' FITSF_IGNORE_TRANSPARENCY: Returns the index of the first palette entry which - ' matches the red, green and blue components. - ' - ' FITSF_NONTRANSPARENT: Returns the index of the first palette entry which - ' matches the red, green and blue components and is - ' nontransparent (fully opaque). - ' - ' FITSF_TRANSPARENT: Returns the index of the first palette entry which - ' matches the red, green and blue components and is - ' fully transparent. - ' - ' FITSF_INCLUDE_ALPHA_TRANSPARENCY: Returns the index of the first palette entry which - ' matches the red, green and blue components as well - ' as the alpha transparency. - - ' When alpha transparency should be included in the palette search ('FITSF_INCLUDE_ALPHA_TRANSPARENCY'), - ' the alpha transparency of the color searched is taken from the left most byte of 'Color' - ' (Color is either in format ARGB or ABGR). The the alpha transparency of the palette entry - ' actually comes from the image's transparency table rather than from the palette, since palettes - ' do not contain transparency information. - - If (FreeImage_GetImageType(Bitmap) = FIT_BITMAP) Then - Select Case FreeImage_GetColorType(Bitmap) - - Case FIC_PALETTE, FIC_MINISBLACK, FIC_MINISWHITE - FreeImage_SearchPalette = -1 - alPalette = FreeImage_GetPaletteExLong(Bitmap) - If (FreeImage_GetTransparencyCount(Bitmap) > UBound(alPalette)) Then - abTransparencyTable = FreeImage_GetTransparencyTableExClone(Bitmap) - Else - TransparencyState = FITSF_IGNORE_TRANSPARENCY - End If - For i = 0 To UBound(alPalette) - If (FreeImage_CompareColorsLongLong(Color, alPalette(i), _ - Tolerance, _ - ColorType, FICFF_COLOR_RGB) = 0) Then - Select Case TransparencyState - - Case FITSF_IGNORE_TRANSPARENCY - FreeImage_SearchPalette = i - Exit For - - Case FITSF_NONTRANSPARENT - If (abTransparencyTable(i) = 255) Then - FreeImage_SearchPalette = i - Exit For - End If - - Case FITSF_TRANSPARENT - If (abTransparencyTable(i) = 0) Then - FreeImage_SearchPalette = i - Exit For - End If - - Case FITSF_INCLUDE_ALPHA_TRANSPARENCY - If (abTransparencyTable(i) = ((Color And &HFF000000) \ 1000000)) Then - FreeImage_SearchPalette = i - Exit For - End If - - End Select - End If - Next i - - Case Else - FreeImage_SearchPalette = -1 - - End Select - Else - FreeImage_SearchPalette = -1 - End If - -End Function - -Public Function FreeImage_GetIcon(ByVal hDIB As Long, _ - Optional ByVal eTransparencyOptions As FREE_IMAGE_ICON_TRANSPARENCY_OPTION_FLAGS = ITOF_USE_DEFAULT_TRANSPARENCY, _ - Optional ByVal lciTransparentColor As Long, _ - Optional ByVal eTransparentColorType As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ - Optional ByVal hDC As Long, _ - Optional ByVal UnloadSource As Boolean) As Long - -Dim tIconInfo As ICONINFO -Dim bReleaseDC As Boolean -Dim bModifySourceImage As Boolean -Dim eMaskFlags As FREE_IMAGE_MASK_FLAGS -Dim lBitDepth As Long -Dim bPixelIndex As Byte -Dim hDIBSrc As Long -Dim hDIBMask As Long -Dim hBMPMask As Long -Dim hBmp As Long - - ' The optional 'UnloadSource' parameter is for unloading the original image - ' after the OlePicture has been created, so you can easiely "switch" from a - ' FreeImage DIB to a VB Picture object. There is no need to clean up the DIB - ' at the caller's site. - - If (hDIB) Then - - If (Not FreeImage_HasPixels(hDIB)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to create an icon from a 'header-only' bitmap.") - End If - - lBitDepth = FreeImage_GetBPP(hDIB) - - ' check whether the image supports transparency - Select Case lBitDepth - - Case 4, 8 - If (eTransparencyOptions And ITOF_USE_TRANSPARENCY_INFO) Then - If (FreeImage_IsTransparent(hDIB)) Then - eMaskFlags = FIMF_MASK_FULL_TRANSPARENCY - ElseIf (eTransparencyOptions And ITOF_FORCE_TRANSPARENCY_INFO) Then - If (FreeImage_IsTransparencyTableTransparent(hDIB)) Then - eMaskFlags = (FIMF_MASK_FULL_TRANSPARENCY And _ - FIMF_MASK_FORCE_TRANSPARENCY) - End If - End If - End If - If ((eMaskFlags = FIMF_MASK_NONE) And _ - (eTransparencyOptions And ITOF_USE_COLOR_TRANSPARENCY)) Then - - eMaskFlags = FIMF_MASK_COLOR_TRANSPARENCY - - Select Case (eTransparencyOptions And ITOF_USE_COLOR_BITMASK) - - Case ITOF_USE_COLOR_TOP_LEFT_PIXEL - Call FreeImage_GetPixelIndex(hDIB, _ - 0, FreeImage_GetHeight(hDIB) - 1, _ - bPixelIndex) - lciTransparentColor = bPixelIndex - eTransparentColorType = FICFF_COLOR_PALETTE_INDEX - - Case ITOF_USE_COLOR_TOP_RIGHT_PIXEL - Call FreeImage_GetPixelIndex(hDIB, _ - FreeImage_GetWidth(hDIB) - 1, FreeImage_GetHeight(hDIB) - 1, _ - bPixelIndex) - lciTransparentColor = bPixelIndex - eTransparentColorType = FICFF_COLOR_PALETTE_INDEX - - Case ITOF_USE_COLOR_BOTTOM_LEFT_PIXEL - Call FreeImage_GetPixelIndex(hDIB, _ - 0, 0, _ - bPixelIndex) - lciTransparentColor = bPixelIndex - eTransparentColorType = FICFF_COLOR_PALETTE_INDEX - - Case ITOF_USE_COLOR_BOTTOM_RIGHT_PIXEL - Call FreeImage_GetPixelIndex(hDIB, _ - FreeImage_GetWidth(hDIB) - 1, 0, _ - bPixelIndex) - lciTransparentColor = bPixelIndex - eTransparentColorType = FICFF_COLOR_PALETTE_INDEX - - End Select - End If - - bModifySourceImage = True - - Case 24, 32 - If ((lBitDepth = 32) And _ - (eTransparencyOptions And ITOF_USE_TRANSPARENCY_INFO)) Then - If (FreeImage_IsTransparent(hDIB)) Then - eMaskFlags = FIMF_MASK_FULL_TRANSPARENCY - End If - End If - If ((eMaskFlags = FIMF_MASK_NONE) And _ - (eTransparencyOptions And ITOF_USE_COLOR_TRANSPARENCY)) Then - - eMaskFlags = FIMF_MASK_COLOR_TRANSPARENCY - - Select Case (eTransparencyOptions And ITOF_USE_COLOR_BITMASK) - - Case ITOF_USE_COLOR_TOP_LEFT_PIXEL - Call FreeImage_GetPixelColorByLong(hDIB, _ - FreeImage_GetHeight(hDIB) - 1, 0, _ - lciTransparentColor) - eTransparentColorType = FICFF_COLOR_RGB - - Case ITOF_USE_COLOR_TOP_RIGHT_PIXEL - Call FreeImage_GetPixelColorByLong(hDIB, _ - FreeImage_GetHeight(hDIB) - 1, FreeImage_GetWidth(hDIB) - 1, _ - lciTransparentColor) - eTransparentColorType = FICFF_COLOR_RGB - - Case ITOF_USE_COLOR_BOTTOM_LEFT_PIXEL - Call FreeImage_GetPixelColorByLong(hDIB, _ - 0, 0, _ - lciTransparentColor) - eTransparentColorType = FICFF_COLOR_RGB - - Case ITOF_USE_COLOR_BOTTOM_RIGHT_PIXEL - Call FreeImage_GetPixelColorByLong(hDIB, _ - 0, FreeImage_GetWidth(hDIB) - 1, _ - lciTransparentColor) - eTransparentColorType = FICFF_COLOR_RGB - - End Select - End If - - bModifySourceImage = (lBitDepth = 24) - - End Select - - - If (bModifySourceImage) Then - hDIBSrc = FreeImage_Clone(hDIB) - hDIBMask = FreeImage_CreateMask(hDIBSrc, MCOF_CREATE_AND_MODIFY, _ - 1, eMaskFlags, _ - lciTransparentColor, eTransparentColorType, _ - , , , , , _ - FreeImage_SearchPalette(hDIBSrc, 0, , , _ - FITSF_NONTRANSPARENT), _ - FICFF_COLOR_PALETTE_INDEX) - Else - hDIBSrc = hDIB - hDIBMask = FreeImage_CreateMaskImage(hDIB, 1, FIMF_MASK_FULL_TRANSPARENCY) - End If - - If (hDC = 0) Then - hDC = GetDC(0) - bReleaseDC = True - End If - - hBmp = CreateDIBitmap(hDC, _ - FreeImage_GetInfoHeader(hDIBSrc), _ - CBM_INIT, _ - FreeImage_GetBits(hDIBSrc), _ - FreeImage_GetInfo(hDIBSrc), _ - DIB_RGB_COLORS) - - - hBMPMask = CreateDIBitmap(hDC, _ - FreeImage_GetInfoHeader(hDIBMask), _ - CBM_INIT, _ - FreeImage_GetBits(hDIBMask), _ - FreeImage_GetInfo(hDIBMask), _ - DIB_RGB_COLORS) - - If (bModifySourceImage) Then - Call FreeImage_Unload(hDIBSrc) - End If - - If (UnloadSource) Then - Call FreeImage_Unload(hDIB) - End If - - - If ((hBmp <> 0) And (hBMPMask <> 0)) Then - - With tIconInfo - .fIcon = True - .hBmMask = hBMPMask - .hbmColor = hBmp - End With - - FreeImage_GetIcon = CreateIconIndirect(tIconInfo) - End If - - If (bReleaseDC) Then - Call ReleaseDC(0, hDC) - End If - End If - -End Function - -Public Function FreeImage_AdjustPictureBox(ByRef Control As Object, _ - Optional ByVal Mode As FREE_IMAGE_ADJUST_MODE = AM_DEFAULT, _ - Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC) As IPicture - -Dim tR As RECT -Dim hDIB As Long -Dim hDIBTemp As Long -Dim lNewWidth As Long -Dim lNewHeight As Long - -Const vbObjectOrWithBlockVariableNotSet As Long = 91 - - ' This function adjusts an already loaded picture in a VB PictureBox - ' control in size. This is done by converting the picture to a Bitmap - ' by FreeImage_CreateFromOlePicture. After resizing the Bitmap it is - ' converted back to a Ole Picture object and re-assigned to the - ' PictureBox control. - - ' The Control paramater is actually of type Object so any object or control - ' providing Picture, hWnd, Width and Height properties can be used instead - ' of a PictureBox control - - ' This may be useful when using compile time provided images in VB like - ' logos or backgrounds that need to be resized during runtime. Using - ' FreeImage's sophisticated rescaling methods is a much better aproach - ' than using VB's stretchable Image control. - - ' One reason for resizing a usually fixed size logo or background image - ' may be the following scenario: - - ' When running on a Windows machine using smaller or bigger fonts (what can - ' be configured in the control panel by using different dpi fonts), the - ' operation system automatically adjusts the sizes of Forms, Labels, - ' TextBoxes, Frames and even PictureBoxes. So, the hole VB application is - ' perfectly adapted to these font metrics with the exception of compile time - ' provided images. Although the PictureBox control is resized, the containing - ' image remains untouched. This problem could be solved with this function. - - ' This function is also wrapped by the function 'AdjustPicture', giving you - ' a more VB common function name. - - - If (Not Control Is Nothing) Then - Call GetClientRect(Control.hWnd, tR) - If ((tR.Right <> Control.Picture.Width) Or _ - (tR.Bottom <> Control.Picture.Height)) Then - hDIB = FreeImage_CreateFromOlePicture(Control.Picture) - If (hDIB) Then - If (Mode = AM_ADJUST_OPTIMAL_SIZE) Then - If (Control.Picture.Width >= Control.Picture.Height) Then - Mode = AM_ADJUST_WIDTH - Else - Mode = AM_ADJUST_HEIGHT - End If - End If - - Select Case Mode - - Case AM_STRECH - lNewWidth = tR.Right - lNewHeight = tR.Bottom - - Case AM_ADJUST_WIDTH - lNewWidth = tR.Right - lNewHeight = lNewWidth / (Control.Picture.Width / Control.Picture.Height) - - Case AM_ADJUST_HEIGHT - lNewHeight = tR.Bottom - lNewWidth = lNewHeight * (Control.Picture.Width / Control.Picture.Height) - - End Select - - hDIBTemp = hDIB - hDIB = FreeImage_Rescale(hDIB, lNewWidth, lNewHeight, Filter) - Call FreeImage_Unload(hDIBTemp) - Set Control.Picture = FreeImage_GetOlePicture(hDIB, , True) - Set FreeImage_AdjustPictureBox = Control.Picture - End If - End If - Else - Call Err.Raise(vbObjectOrWithBlockVariableNotSet) - End If - -End Function - -Public Function AdjustPicture(ByRef Control As Object, _ - Optional ByRef Mode As FREE_IMAGE_ADJUST_MODE = AM_DEFAULT, _ - Optional ByRef Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC) As IPicture - - ' This function is a more VB friendly signed wrapper for - ' the FreeImage_AdjustPictureBox function. - - Set AdjustPicture = FreeImage_AdjustPictureBox(Control, Mode, Filter) - -End Function - -Public Function FreeImage_LoadEx(ByVal Filename As String, _ - Optional ByVal Options As FREE_IMAGE_LOAD_OPTIONS, _ - Optional ByVal Width As Variant, _ - Optional ByVal Height As Variant, _ - Optional ByVal InPercent As Boolean, _ - Optional ByVal Filter As FREE_IMAGE_FILTER, _ - Optional ByRef Format As FREE_IMAGE_FORMAT) As Long - -Const vbInvalidPictureError As Long = 481 - - ' The function provides all image formats, the FreeImage library can read. The - ' image format is determined from the image file to load, the optional parameter - ' 'Format' is an OUT parameter that will contain the image format that has - ' been loaded. - - ' The parameters 'Width', 'Height', 'InPercent' and 'Filter' make it possible - ' to "load" the image in a resized version. 'Width', 'Height' specify the desired - ' width and height, 'Filter' determines, what image filter should be used - ' on the resizing process. - - ' The parameters 'Width', 'Height', 'InPercent' and 'Filter' map directly to the - ' according parameters of the 'FreeImage_RescaleEx' function. So, read the - ' documentation of the 'FreeImage_RescaleEx' for a complete understanding of the - ' usage of these parameters. - - - Format = FreeImage_GetFileType(Filename) - If (Format <> FIF_UNKNOWN) Then - If (FreeImage_FIFSupportsReading(Format)) Then - FreeImage_LoadEx = FreeImage_Load(Format, Filename, Options) - If (FreeImage_LoadEx) Then - - If ((Not IsMissing(Width)) Or _ - (Not IsMissing(Height))) Then - FreeImage_LoadEx = FreeImage_RescaleEx(FreeImage_LoadEx, Width, Height, _ - InPercent, True, Filter) - End If - Else - Call Err.Raise(vbInvalidPictureError) - End If - Else - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "FreeImage Library plugin '" & FreeImage_GetFormatFromFIF(Format) & "' " & _ - "does not support reading.") - End If - Else - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "The file specified has an unknown image format.") - End If - -End Function - -Public Function LoadPictureEx(Optional ByRef Filename As Variant, _ - Optional ByRef Options As FREE_IMAGE_LOAD_OPTIONS, _ - Optional ByRef Width As Variant, _ - Optional ByRef Height As Variant, _ - Optional ByRef InPercent As Boolean, _ - Optional ByRef Filter As FREE_IMAGE_FILTER, _ - Optional ByRef Format As FREE_IMAGE_FORMAT) As IPicture - -Dim hDIB As Long - - ' This function is an extended version of the VB method 'LoadPicture'. As - ' the VB version it takes a filename parameter to load the image and throws - ' the same errors in most cases. - - ' This function now is only a thin wrapper for the FreeImage_LoadEx() wrapper - ' function (as compared to releases of this wrapper prior to version 1.8). So, - ' have a look at this function's discussion of the parameters. - - ' However, we do mask out the FILO_LOAD_NOPIXELS load option, since this - ' function shall create a VB Picture object, which does not support - ' FreeImage's header-only loading option. - - - If (Not IsMissing(Filename)) Then - hDIB = FreeImage_LoadEx(Filename, (Options And (Not FILO_LOAD_NOPIXELS)), _ - Width, Height, InPercent, Filter, Format) - Set LoadPictureEx = FreeImage_GetOlePicture(hDIB, , True) - End If - -End Function - -Public Function FreeImage_SaveEx(ByVal Bitmap As Long, _ - ByVal Filename As String, _ - Optional ByVal Format As FREE_IMAGE_FORMAT = FIF_UNKNOWN, _ - Optional ByVal Options As FREE_IMAGE_SAVE_OPTIONS, _ - Optional ByVal ColorDepth As FREE_IMAGE_COLOR_DEPTH, _ - Optional ByVal Width As Variant, _ - Optional ByVal Height As Variant, _ - Optional ByVal InPercent As Boolean, _ - Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ - Optional ByVal UnloadSource As Boolean) As Boolean - -Dim hDIBRescale As Long -Dim bConvertedOnRescale As Boolean -Dim bIsNewDIB As Boolean -Dim lBPP As Long -Dim lBPPOrg As Long -Dim strExtension As String - - ' This function is an easy to use replacement for FreeImage's FreeImage_Save() - ' function which supports inline size- and color conversions as well as an - ' auto image format detection algorithm that determines the desired image format - ' by the given filename. An even more sophisticated algorithm may auto-detect - ' the proper color depth for a explicitly given or auto-detected image format. - - ' The function provides all image formats, and save options, the FreeImage - ' library can write. The optional parameter 'Format' may contain the desired - ' image format. When omitted, the function tries to get the image format from - ' the filename extension. - - ' The optional parameter 'ColorDepth' may contain the desired color depth for - ' the saved image. This can be either any value of the FREE_IMAGE_COLOR_DEPTH - ' enumeration or the value FICD_AUTO what is the default value of the parameter. - ' When 'ColorDepth' is FICD_AUTO, the function tries to get the most suitable - ' color depth for the specified image format if the image's current color depth - ' is not supported by the specified image format. Therefore, the function - ' firstly reduces the color depth step by step until a proper color depth is - ' found since an incremention would only increase the file's size with no - ' quality benefit. Only when there is no lower color depth is found for the - ' image format, the function starts to increase the color depth. - - ' Keep in mind that an explicitly specified color depth that is not supported - ' by the image format results in a runtime error. For example, when saving - ' a 24 bit image as GIF image, a runtime error occurs. - - ' The function checks, whether the given filename has a valid extension or - ' not. If not, the "primary" extension for the used image format will be - ' appended to the filename. The parameter 'Filename' remains untouched in - ' this case. - - ' To learn more about the "primary" extension, read the documentation for - ' the 'FreeImage_GetPrimaryExtensionFromFIF' function. - - ' The parameters 'Width', 'Height', 'InPercent' and 'Filter' make it possible - ' to save the image in a resized version. 'Width', 'Height' specify the desired - ' width and height, 'Filter' determines, what image filter should be used - ' on the resizing process. Since FreeImage_SaveEx relies on FreeImage_RescaleEx, - ' please refer to the documentation of FreeImage_RescaleEx to learn more - ' about these four parameters. - - ' The optional 'UnloadSource' parameter is for unloading the saved image, so - ' you can save and unload an image with this function in one operation. - ' CAUTION: at current, the image is unloaded, even if the image was not - ' saved correctly! - - - If (Bitmap) Then - - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to save 'header-only' bitmaps.") - End If - - If ((Not IsMissing(Width)) Or _ - (Not IsMissing(Height))) Then - - lBPP = FreeImage_GetBPP(Bitmap) - hDIBRescale = FreeImage_RescaleEx(Bitmap, Width, Height, InPercent, UnloadSource, Filter) - bIsNewDIB = (hDIBRescale <> Bitmap) - Bitmap = hDIBRescale - bConvertedOnRescale = (lBPP <> FreeImage_GetBPP(Bitmap)) - End If - - If (Format = FIF_UNKNOWN) Then - Format = FreeImage_GetFIFFromFilename(Filename) - End If - If (Format <> FIF_UNKNOWN) Then - If ((FreeImage_FIFSupportsWriting(Format)) And _ - (FreeImage_FIFSupportsExportType(Format, FIT_BITMAP))) Then - - If (Not FreeImage_IsFilenameValidForFIF(Format, Filename)) Then - strExtension = "." & FreeImage_GetPrimaryExtensionFromFIF(Format) - End If - - ' check color depth - If (ColorDepth <> FICD_AUTO) Then - ' mask out bit 1 (0x02) for the case ColorDepth is FICD_MONOCHROME_DITHER (0x03) - ' FREE_IMAGE_COLOR_DEPTH values are true bit depths in general expect FICD_MONOCHROME_DITHER - ' by masking out bit 1, 'FreeImage_FIFSupportsExportBPP()' tests for bitdepth 1 - ' what is correct again for dithered images. - ColorDepth = (ColorDepth And (Not &H2)) - If (Not FreeImage_FIFSupportsExportBPP(Format, ColorDepth)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "FreeImage Library plugin '" & FreeImage_GetFormatFromFIF(Format) & "' " & _ - "is unable to write images with a color depth " & _ - "of " & ColorDepth & " bpp.") - - ElseIf (FreeImage_GetBPP(Bitmap) <> ColorDepth) Then - Bitmap = FreeImage_ConvertColorDepth(Bitmap, ColorDepth, (UnloadSource Or bIsNewDIB)) - bIsNewDIB = True - - End If - Else - - If (lBPP = 0) Then - lBPP = FreeImage_GetBPP(Bitmap) - End If - - If (Not FreeImage_FIFSupportsExportBPP(Format, lBPP)) Then - lBPPOrg = lBPP - Do - lBPP = pGetPreviousColorDepth(lBPP) - Loop While ((Not FreeImage_FIFSupportsExportBPP(Format, lBPP)) Or _ - (lBPP = 0)) - If (lBPP = 0) Then - lBPP = lBPPOrg - Do - lBPP = pGetNextColorDepth(lBPP) - Loop While ((Not FreeImage_FIFSupportsExportBPP(Format, lBPP)) Or _ - (lBPP = 0)) - End If - - If (lBPP <> 0) Then - Bitmap = FreeImage_ConvertColorDepth(Bitmap, lBPP, (UnloadSource Or bIsNewDIB)) - bIsNewDIB = True - End If - - ElseIf (bConvertedOnRescale) Then - ' restore original color depth - ' always unload current DIB here, since 'bIsNewDIB' is True - Bitmap = FreeImage_ConvertColorDepth(Bitmap, lBPP, True) - - End If - End If - - FreeImage_SaveEx = FreeImage_Save(Format, Bitmap, Filename & strExtension, Options) - If ((bIsNewDIB) Or (UnloadSource)) Then - Call FreeImage_Unload(Bitmap) - End If - Else - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "FreeImage Library plugin '" & FreeImage_GetFormatFromFIF(Format) & "' " & _ - "is unable to write images of the image format requested.") - End If - Else - ' unknown image format error - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unknown image format. Neither an explicit image format " & _ - "was specified nor any known image format was determined " & _ - "from the filename specified.") - End If - End If - -End Function - -Public Function SavePictureEx(ByRef Picture As IPicture, _ - ByRef Filename As String, _ - Optional ByRef Format As FREE_IMAGE_FORMAT, _ - Optional ByRef Options As FREE_IMAGE_SAVE_OPTIONS, _ - Optional ByRef ColorDepth As FREE_IMAGE_COLOR_DEPTH, _ - Optional ByRef Width As Variant, _ - Optional ByRef Height As Variant, _ - Optional ByRef InPercent As Boolean, _ - Optional ByRef Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC) As Boolean - -Dim hDIB As Long - -Const vbObjectOrWithBlockVariableNotSet As Long = 91 -Const vbInvalidPictureError As Long = 481 - - ' This function is an extended version of the VB method 'SavePicture'. As - ' the VB version it takes a Picture object and a filename parameter to - ' save the image and throws the same errors in most cases. - - ' This function now is only a thin wrapper for the FreeImage_SaveEx() wrapper - ' function (as compared to releases of this wrapper prior to version 1.8). So, - ' have a look at this function's discussion of the parameters. - - - If (Not Picture Is Nothing) Then - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - SavePictureEx = FreeImage_SaveEx(hDIB, Filename, Format, Options, _ - ColorDepth, Width, Height, InPercent, _ - FILTER_BICUBIC, True) - Else - Call Err.Raise(vbInvalidPictureError) - End If - Else - Call Err.Raise(vbObjectOrWithBlockVariableNotSet) - End If - -End Function - -Public Function SaveImageContainerEx(ByRef Container As Object, _ - ByRef Filename As String, _ - Optional ByVal IncludeDrawings As Boolean, _ - Optional ByRef Format As FREE_IMAGE_FORMAT, _ - Optional ByRef Options As FREE_IMAGE_SAVE_OPTIONS, _ - Optional ByRef ColorDepth As FREE_IMAGE_COLOR_DEPTH, _ - Optional ByRef Width As Variant, _ - Optional ByRef Height As Variant, _ - Optional ByRef InPercent As Boolean, _ - Optional ByRef Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC) As Long - - ' This function is an extended version of the VB method 'SavePicture'. As - ' the VB version it takes an image hosting control and a filename parameter to - ' save the image and throws the same errors in most cases. - - ' This function merges the functionality of both wrapper functions - ' 'SavePictureEx()' and 'FreeImage_CreateFromImageContainer()'. Basically this - ' function is identical to 'SavePictureEx' expect that is does not take a - ' IOlePicture (IPicture) object but a VB image hosting container control. - - ' Please, refer to each of this two function's inline documentation for a - ' more detailed description. - - Call SavePictureEx(pGetIOlePictureFromContainer(Container, IncludeDrawings), _ - Filename, Format, Options, ColorDepth, Width, Height, InPercent, Filter) - -End Function - -Public Function FreeImage_OpenMultiBitmapEx(ByVal Filename As String, _ - Optional ByVal ReadOnly As Boolean, _ - Optional ByVal KeepCacheInMemory As Boolean, _ - Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS, _ - Optional ByRef Format As FREE_IMAGE_FORMAT) As Long - - Format = FreeImage_GetFileType(Filename) - If (Format <> FIF_UNKNOWN) Then - Select Case Format - - Case FIF_TIFF, FIF_GIF, FIF_ICO - FreeImage_OpenMultiBitmapEx = FreeImage_OpenMultiBitmap(Format, Filename, False, _ - ReadOnly, KeepCacheInMemory, Flags) - - Case Else - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "FreeImage Library plugin '" & FreeImage_GetFormatFromFIF(Format) & "' " & _ - "does not have any support for multi-page bitmaps.") - End Select - Else - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "The file specified has an unknown image format.") - End If - -End Function - -Public Function FreeImage_CreateMultiBitmapEx(ByVal Filename As String, _ - Optional ByVal KeepCacheInMemory As Boolean, _ - Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS, _ - Optional ByRef Format As FREE_IMAGE_FORMAT) As Long - - If (Format = FIF_UNKNOWN) Then - Format = FreeImage_GetFIFFromFilename(Filename) - End If - - If (Format <> FIF_UNKNOWN) Then - Select Case Format - - Case FIF_TIFF, FIF_GIF, FIF_ICO - FreeImage_CreateMultiBitmapEx = FreeImage_OpenMultiBitmap(Format, Filename, True, _ - False, KeepCacheInMemory, Flags) - - Case Else - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "FreeImage Library plugin '" & _ - FreeImage_GetFormatFromFIF(Format) & "' " & _ - "does not have any support for multi-page bitmaps.") - End Select - Else - ' unknown image format error - Call Err.Raise(5, _ - "MFreeImage", _ - Error$(5) & vbCrLf & vbCrLf & _ - "Unknown image format. Neither an explicit image format " & _ - "was specified nor any known image format was determined " & _ - "from the filename specified.") - End If - -End Function - - - -'-------------------------------------------------------------------------------- -' OlePicture aware toolkit, rescale and conversion functions -'-------------------------------------------------------------------------------- - -Public Function FreeImage_RescaleIOP(ByRef Picture As IPicture, _ - Optional ByVal Width As Variant, _ - Optional ByVal Height As Variant, _ - Optional ByVal IsPercentValue As Boolean, _ - Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ - Optional ByVal ForceCloneCreation As Boolean) As IPicture - -Dim hDIB As Long - - ' IOlePicture based wrapper for wrapper function FreeImage_RescaleEx() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - hDIB = FreeImage_RescaleEx(hDIB, Width, Height, IsPercentValue, _ - True, Filter, ForceCloneCreation) - Set FreeImage_RescaleIOP = FreeImage_GetOlePicture(hDIB, , True) - End If - -End Function - -Public Function FreeImage_RescaleByPixelIOP(ByRef Picture As IPicture, _ - Optional ByVal WidthInPixels As Long, _ - Optional ByVal HeightInPixels As Long, _ - Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ - Optional ByVal ForceCloneCreation As Boolean) As IPicture - - ' Thin wrapper for function 'FreeImage_RescaleExIOP' for removing method - ' overload fake. This function rescales the image directly to the size - ' specified by the 'WidthInPixels' and 'HeightInPixels' parameters. - - Set FreeImage_RescaleByPixelIOP = FreeImage_RescaleIOP(Picture, WidthInPixels, HeightInPixels, _ - False, Filter, ForceCloneCreation) - -End Function - -Public Function FreeImage_RescaleByPercentIOP(ByRef Picture As IPicture, _ - Optional ByVal WidthPercentage As Double, _ - Optional ByVal HeightPercentage As Double, _ - Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ - Optional ByVal ForceCloneCreation As Boolean) As IPicture - - ' Thin wrapper for function 'FreeImage_RescaleExIOP' for removing method - ' overload fake. This function rescales the image by a percent value - ' based on the image's original size. - - Set FreeImage_RescaleByPercentIOP = FreeImage_RescaleIOP(Picture, WidthPercentage, HeightPercentage, _ - True, Filter, ForceCloneCreation) - -End Function - -Public Function FreeImage_RescaleByFactorIOP(ByRef Picture As IPicture, _ - Optional ByVal WidthFactor As Double, _ - Optional ByVal HeightFactor As Double, _ - Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ - Optional ByVal ForceCloneCreation As Boolean) As IPicture - - ' Thin wrapper for function 'FreeImage_RescaleExIOP' for removing method - ' overload fake. This function rescales the image by a factor - ' based on the image's original size. - - Set FreeImage_RescaleByFactorIOP = FreeImage_RescaleIOP(Picture, WidthFactor, HeightFactor, _ - False, Filter, ForceCloneCreation) - -End Function - -Public Function FreeImage_MakeThumbnailIOP(ByRef Picture As IPicture, _ - ByVal MaxPixelSize As Long, _ - Optional ByVal Convert As Boolean) As IPicture - -Dim hDIB As Long -Dim hDIBThumbnail As Long - - ' IOlePicture based wrapper for wrapper function FreeImage_MakeThumbnail() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - hDIBThumbnail = FreeImage_MakeThumbnail(hDIB, MaxPixelSize, Convert) - If (hDIBThumbnail) Then - Set FreeImage_MakeThumbnailIOP = FreeImage_GetOlePicture(hDIBThumbnail, , True) - End If - Call FreeImage_Unload(hDIB) - End If - -End Function - -Public Function FreeImage_ConvertColorDepthIOP(ByRef Picture As IPicture, _ - ByVal Conversion As FREE_IMAGE_CONVERSION_FLAGS, _ - Optional ByVal Threshold As Byte = 128, _ - Optional ByVal DitherMethod As FREE_IMAGE_DITHER = FID_FS, _ - Optional ByVal QuantizeMethod As FREE_IMAGE_QUANTIZE = FIQ_WUQUANT) As IPicture - -Dim hDIB As Long - - ' IOlePicture based wrapper for wrapper function FreeImage_ConvertColorDepth() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - hDIB = FreeImage_ConvertColorDepth(hDIB, Conversion, True, Threshold, _ - DitherMethod, QuantizeMethod) - Set FreeImage_ConvertColorDepthIOP = FreeImage_GetOlePicture(hDIB, , True) - End If - -End Function - -Public Function FreeImage_ColorQuantizeExIOP(ByRef Picture As IPicture, _ - Optional ByVal QuantizeMethod As FREE_IMAGE_QUANTIZE = FIQ_WUQUANT, _ - Optional ByVal PaletteSize As Long = 256, _ - Optional ByVal ReserveSize As Long, _ - Optional ByRef ReservePalette As Variant = Null) As IPicture - -Dim hDIB As Long - - ' IOlePicture based wrapper for wrapper function FreeImage_ColorQuantizeEx() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - hDIB = FreeImage_ColorQuantizeEx(hDIB, QuantizeMethod, True, PaletteSize, _ - ReserveSize, ReservePalette) - Set FreeImage_ColorQuantizeExIOP = FreeImage_GetOlePicture(hDIB, , True) - End If - -End Function - -Public Function FreeImage_RotateClassicIOP(ByRef Picture As IPicture, _ - ByVal Angle As Double) As IPicture - -Dim hDIB As Long -Dim hDIBNew As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_RotateClassic() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - Select Case FreeImage_GetBPP(hDIB) - - Case 1, 8, 24, 32 - hDIBNew = FreeImage_RotateClassic(hDIB, Angle) - Set FreeImage_RotateClassicIOP = FreeImage_GetOlePicture(hDIBNew, , True) - - End Select - Call FreeImage_Unload(hDIB) - End If - -End Function - -Public Function FreeImage_RotateIOP(ByRef Picture As IPicture, _ - ByVal Angle As Double, _ - Optional ByVal ColorPtr As Long) As IPicture - -Dim hDIB As Long -Dim hDIBNew As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_Rotate() - - ' The optional ColorPtr parameter takes a pointer to (e.g. the address of) an - ' RGB color value. So, all these assignments are valid for ColorPtr: - ' - ' Dim tColor As RGBQUAD - ' - ' VarPtr(tColor) - ' VarPtr(&H33FF80) - ' VarPtr(vbWhite) ' However, the VB color constants are in BGR format! - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - Select Case FreeImage_GetBPP(hDIB) - - Case 1, 8, 24, 32 - hDIBNew = FreeImage_Rotate(hDIB, Angle, ByVal ColorPtr) - Set FreeImage_RotateIOP = FreeImage_GetOlePicture(hDIBNew, , True) - - End Select - Call FreeImage_Unload(hDIB) - End If - -End Function - -Public Function FreeImage_RotateExIOP(ByRef Picture As IPicture, _ - ByVal Angle As Double, _ - Optional ByVal ShiftX As Double, _ - Optional ByVal ShiftY As Double, _ - Optional ByVal OriginX As Double, _ - Optional ByVal OriginY As Double, _ - Optional ByVal UseMask As Boolean) As IPicture - -Dim hDIB As Long -Dim hDIBNew As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_RotateEx() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - Select Case FreeImage_GetBPP(hDIB) - - Case 8, 24, 32 - hDIBNew = FreeImage_RotateEx(hDIB, Angle, ShiftX, ShiftY, OriginX, OriginY, UseMask) - Set FreeImage_RotateExIOP = FreeImage_GetOlePicture(hDIBNew, , True) - - End Select - Call FreeImage_Unload(hDIB) - End If - -End Function - -Public Function FreeImage_FlipHorizontalIOP(ByRef Picture As IPicture) As IPicture - -Dim hDIB As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_FlipHorizontal() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - Call FreeImage_FlipHorizontalInt(hDIB) - Set FreeImage_FlipHorizontalIOP = FreeImage_GetOlePicture(hDIB, , True) - End If - -End Function - -Public Function FreeImage_FlipVerticalIOP(ByRef Picture As IPicture) As IPicture - -Dim hDIB As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_FlipVertical() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - Call FreeImage_FlipVerticalInt(hDIB) - Set FreeImage_FlipVerticalIOP = FreeImage_GetOlePicture(hDIB, , True) - End If - -End Function - -Public Function FreeImage_AdjustCurveIOP(ByRef Picture As IPicture, _ - ByRef LookupTable As Variant, _ - Optional ByVal Channel As FREE_IMAGE_COLOR_CHANNEL = FICC_BLACK) As IPicture - -Dim hDIB As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_AdjustCurve() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - Select Case FreeImage_GetBPP(hDIB) - - Case 8, 24, 32 - Call FreeImage_AdjustCurveEx(hDIB, LookupTable, Channel) - Set FreeImage_AdjustCurveIOP = FreeImage_GetOlePicture(hDIB, , True) - - End Select - End If - -End Function - -Public Function FreeImage_AdjustGammaIOP(ByRef Picture As IPicture, _ - ByVal Gamma As Double) As IPicture - -Dim hDIB As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_AdjustGamma() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - Select Case FreeImage_GetBPP(hDIB) - - Case 8, 24, 32 - Call FreeImage_AdjustGammaInt(hDIB, Gamma) - Set FreeImage_AdjustGammaIOP = FreeImage_GetOlePicture(hDIB, , True) - - End Select - End If - -End Function - -Public Function FreeImage_AdjustBrightnessIOP(ByRef Picture As IPicture, _ - ByVal Percentage As Double) As IPicture - -Dim hDIB As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_AdjustBrightness() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - Select Case FreeImage_GetBPP(hDIB) - - Case 8, 24, 32 - Call FreeImage_AdjustBrightnessInt(hDIB, Percentage) - Set FreeImage_AdjustBrightnessIOP = FreeImage_GetOlePicture(hDIB, , True) - - End Select - End If - -End Function - -Public Function FreeImage_AdjustContrastIOP(ByRef Picture As IPicture, _ - ByVal Percentage As Double) As IPicture - -Dim hDIB As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_AdjustContrast() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - Select Case FreeImage_GetBPP(hDIB) - - Case 8, 24, 32 - Call FreeImage_AdjustContrastInt(hDIB, Percentage) - Set FreeImage_AdjustContrastIOP = FreeImage_GetOlePicture(hDIB, , True) - - End Select - End If - -End Function - -Public Function FreeImage_InvertIOP(ByRef Picture As IPicture) As IPicture - -Dim hDIB As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_Invert() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - Call FreeImage_InvertInt(hDIB) - Set FreeImage_InvertIOP = FreeImage_GetOlePicture(hDIB, , True) - End If - -End Function - -Public Function FreeImage_GetChannelIOP(ByRef Picture As IPicture, _ - ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As IPicture - -Dim hDIB As Long -Dim hDIBNew As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_GetChannel() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - Select Case FreeImage_GetBPP(hDIB) - - Case 24, 32 - hDIBNew = FreeImage_GetChannel(hDIB, Channel) - Set FreeImage_GetChannelIOP = FreeImage_GetOlePicture(hDIBNew, , True) - - End Select - Call FreeImage_Unload(hDIB) - End If - -End Function - -Public Function FreeImage_SetChannelIOP(ByRef Picture As IPicture, _ - ByVal BitmapSrc As Long, _ - ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As IPicture - -Dim hDIB As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_SetChannel() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - Select Case FreeImage_GetBPP(hDIB) - - Case 24, 32 - If (FreeImage_SetChannel(hDIB, BitmapSrc, Channel)) Then - Set FreeImage_SetChannelIOP = FreeImage_GetOlePicture(hDIB, , True) - End If - - End Select - Call FreeImage_Unload(hDIB) - End If - -End Function - -Public Function FreeImage_CopyIOP(ByRef Picture As IPicture, _ - ByVal Left As Long, _ - ByVal Top As Long, _ - ByVal Right As Long, _ - ByVal Bottom As Long) As IPicture - -Dim hDIB As Long -Dim hDIBNew As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_Copy() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - hDIBNew = FreeImage_Copy(hDIB, Left, Top, Right, Bottom) - Call FreeImage_Unload(hDIB) - Set FreeImage_CopyIOP = FreeImage_GetOlePicture(hDIBNew, , True) - End If - -End Function - -Public Function FreeImage_PasteIOP(ByRef PictureDst As IPicture, _ - ByRef PictureSrc As IPicture, _ - ByVal Left As Long, _ - ByVal Top As Long, _ - ByVal Alpha As Long, _ - Optional ByVal KeepOriginalDestImage As Boolean) As IPicture - -Dim hDIBDst As Long -Dim hDIBSrc As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_Paste() - - hDIBDst = FreeImage_CreateFromOlePicture(PictureDst) - If (hDIBDst) Then - hDIBSrc = FreeImage_CreateFromOlePicture(PictureSrc) - If (hDIBSrc) Then - If FreeImage_Paste(hDIBDst, hDIBSrc, Left, Top, Alpha) Then - Set FreeImage_PasteIOP = FreeImage_GetOlePicture(hDIBDst, , True) - If (Not KeepOriginalDestImage) Then - Set PictureDst = FreeImage_PasteIOP - End If - End If - Call FreeImage_Unload(hDIBSrc) - End If - End If - -End Function - -Public Function FreeImage_CompositeIOP(ByRef Picture As IPicture, _ - Optional ByVal UseFileBackColor As Boolean, _ - Optional ByVal AppBackColor As OLE_COLOR, _ - Optional ByRef BackgroundPicture As IPicture) As IPicture - -Dim hDIB As Long -Dim hDIBbg As Long -Dim hDIBResult As Long -Dim lUseFileBackColor As Long - - ' IOlePicture based wrapper for FreeImage function FreeImage_Composite() - - hDIB = FreeImage_CreateFromOlePicture(Picture) - If (hDIB) Then - - If (UseFileBackColor) Then - lUseFileBackColor = 1 - End If - - hDIBbg = FreeImage_CreateFromOlePicture(BackgroundPicture) - - hDIBResult = FreeImage_Composite(hDIB, lUseFileBackColor, ConvertColor(AppBackColor), hDIBbg) - If (hDIBResult) Then - Set FreeImage_CompositeIOP = FreeImage_GetOlePicture(hDIBResult, , True) - End If - - Call FreeImage_Unload(hDIB) - If (hDIBbg) Then - Call FreeImage_Unload(hDIBbg) - End If - End If - -End Function - - -'-------------------------------------------------------------------------------- -' VB-coded Toolkit functions -'-------------------------------------------------------------------------------- - -Public Function FreeImage_GetColorizedPalette(ByVal Color As OLE_COLOR, _ - Optional ByVal SplitValue As Variant = 0.5) As RGBQUAD() - -Dim atPalette(255) As RGBQUAD -Dim lSplitIndex As Long -Dim lSplitIndexInv As Long -Dim lRed As Long -Dim lGreen As Long -Dim lBlue As Long -Dim i As Long - - ' compute the split index - Select Case VarType(SplitValue) - - Case vbByte, vbInteger, vbLong - lSplitIndex = SplitValue - - Case vbDouble, vbSingle, vbDecimal - lSplitIndex = 256 * SplitValue - - Case Else - lSplitIndex = 128 - - End Select - - ' check ranges of split index - If (lSplitIndex < 0) Then - lSplitIndex = 0 - ElseIf (lSplitIndex > 255) Then - lSplitIndex = 255 - End If - lSplitIndexInv = 256 - lSplitIndex - - ' extract color components red, green and blue - lRed = (Color And &HFF) - lGreen = ((Color \ &H100&) And &HFF) - lBlue = ((Color \ &H10000) And &HFF) - - For i = 0 To lSplitIndex - 1 - With atPalette(i) - .rgbRed = (lRed / lSplitIndex) * i - .rgbGreen = (lGreen / lSplitIndex) * i - .rgbBlue = (lBlue / lSplitIndex) * i - End With - Next i - For i = lSplitIndex To 255 - With atPalette(i) - .rgbRed = lRed + ((255 - lRed) / lSplitIndexInv) * (i - lSplitIndex) - .rgbGreen = lGreen + ((255 - lGreen) / lSplitIndexInv) * (i - lSplitIndex) - .rgbBlue = lBlue + ((255 - lBlue) / lSplitIndexInv) * (i - lSplitIndex) - End With - Next i - - FreeImage_GetColorizedPalette = atPalette - -End Function - -Public Function FreeImage_Colorize(ByVal Bitmap As Long, _ - ByVal Color As OLE_COLOR, _ - Optional ByVal SplitValue As Variant = 0.5) As Long - - If (Bitmap) Then - If (Not FreeImage_HasPixels(Bitmap)) Then - Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ - "Unable to colorize a 'header-only' bitmap.") - End If - FreeImage_Colorize = FreeImage_ConvertToGreyscale(Bitmap) - Call FreeImage_SetPalette(FreeImage_Colorize, _ - FreeImage_GetColorizedPalette(Color, SplitValue)) - End If - -End Function - -Public Function FreeImage_Sepia(ByVal Bitmap As Long, _ - Optional ByVal SplitValue As Variant = 0.5) As Long - - FreeImage_Sepia = FreeImage_Colorize(Bitmap, &H658AA2, SplitValue) ' RGB(162, 138, 101) - -End Function - - -'-------------------------------------------------------------------------------- -' Compression functions wrappers -'-------------------------------------------------------------------------------- - -Public Function FreeImage_ZLibCompressEx(ByRef Target As Variant, _ - Optional ByRef TargetSize As Long, _ - Optional ByRef Source As Variant, _ - Optional ByVal SourceSize As Long, _ - Optional ByVal Offset As Long) As Long - -Dim lSourceDataPtr As Long -Dim lTargetDataPtr As Long -Dim bTargetCreated As Boolean - - ' This function is a more VB friendly wrapper for compressing data with - ' the 'FreeImage_ZLibCompress' function. - - ' The parameter 'Target' may either be a VB style array of Byte, Integer - ' or Long or a pointer to a memory block. If 'Target' is a pointer to a - ' memory block (when it contains an address), 'TargetSize' must be - ' specified and greater than zero. If 'Target' is an initialized array, - ' the whole array will be used to store compressed data when 'TargetSize' - ' is missing or below or equal to zero. If 'TargetSize' is specified, only - ' the first TargetSize bytes of the array will be used. - ' In each case, all rules according to the FreeImage API documentation - ' apply, what means that the target buffer must be at least 0.1% greater - ' than the source buffer plus 12 bytes. - ' If 'Target' is an uninitialized array, the contents of 'TargetSize' - ' will be ignored and the size of the array 'Target' will be handled - ' internally. When the function returns, 'Target' will be initialized - ' as an array of Byte and sized correctly to hold all the compressed - ' data. - - ' Nearly all, that is true for the parameters 'Target' and 'TargetSize', - ' is also true for 'Source' and 'SourceSize', expect that 'Source' should - ' never be an uninitialized array. In that case, the function returns - ' immediately. - - ' The optional parameter 'Offset' may contain a number of bytes to remain - ' untouched at the beginning of 'Target', when an uninitialized array is - ' provided through 'Target'. When 'Target' is either a pointer or an - ' initialized array, 'Offset' will be ignored. This parameter is currently - ' used by 'FreeImage_ZLibCompressVB' to store the length of the uncompressed - ' data at the first four bytes of 'Target'. - - - ' get the pointer and the size in bytes of the source - ' memory block - lSourceDataPtr = pGetMemoryBlockPtrFromVariant(Source, SourceSize) - If (lSourceDataPtr) Then - ' when we got a valid pointer, get the pointer and the size in bytes - ' of the target memory block - lTargetDataPtr = pGetMemoryBlockPtrFromVariant(Target, TargetSize) - If (lTargetDataPtr = 0) Then - ' if 'Target' is a null pointer, we will initialized it as an array - ' of bytes; here we will take 'Offset' into account - ReDim Target(SourceSize + Int(SourceSize * 0.1) + _ - 12 + Offset) As Byte - ' get pointer and size in bytes (will never be a null pointer) - lTargetDataPtr = pGetMemoryBlockPtrFromVariant(Target, TargetSize) - ' adjust according to 'Offset' - lTargetDataPtr = lTargetDataPtr + Offset - TargetSize = TargetSize - Offset - bTargetCreated = True - End If - - ' compress source data - FreeImage_ZLibCompressEx = FreeImage_ZLibCompress(lTargetDataPtr, _ - TargetSize, _ - lSourceDataPtr, _ - SourceSize) - - ' the function returns the number of bytes needed to store the - ' compressed data or zero on failure - If (FreeImage_ZLibCompressEx) Then - If (bTargetCreated) Then - ' when we created the array, we need to adjust it's size - ' according to the length of the compressed data - ReDim Preserve Target(FreeImage_ZLibCompressEx - 1 + Offset) - End If - End If - End If - -End Function - -Public Function FreeImage_ZLibUncompressEx(ByRef Target As Variant, _ - Optional ByRef TargetSize As Long, _ - Optional ByRef Source As Variant, _ - Optional ByVal SourceSize As Long) As Long - -Dim lSourceDataPtr As Long -Dim lTargetDataPtr As Long - - ' This function is a more VB friendly wrapper for compressing data with - ' the 'FreeImage_ZLibUncompress' function. - - ' The parameter 'Target' may either be a VB style array of Byte, Integer - ' or Long or a pointer to a memory block. If 'Target' is a pointer to a - ' memory block (when it contains an address), 'TargetSize' must be - ' specified and greater than zero. If 'Target' is an initialized array, - ' the whole array will be used to store uncompressed data when 'TargetSize' - ' is missing or below or equal to zero. If 'TargetSize' is specified, only - ' the first TargetSize bytes of the array will be used. - ' In each case, all rules according to the FreeImage API documentation - ' apply, what means that the target buffer must be at least as large, to - ' hold all the uncompressed data. - ' Unlike the function 'FreeImage_ZLibCompressEx', 'Target' can not be - ' an uninitialized array, since the size of the uncompressed data can - ' not be determined by the ZLib functions, but must be specified by a - ' mechanism outside the FreeImage compression functions' scope. - - ' Nearly all, that is true for the parameters 'Target' and 'TargetSize', - ' is also true for 'Source' and 'SourceSize'. - - - ' get the pointer and the size in bytes of the source - ' memory block - lSourceDataPtr = pGetMemoryBlockPtrFromVariant(Source, SourceSize) - If (lSourceDataPtr) Then - ' when we got a valid pointer, get the pointer and the size in bytes - ' of the target memory block - lTargetDataPtr = pGetMemoryBlockPtrFromVariant(Target, TargetSize) - If (lTargetDataPtr) Then - ' if we do not have a null pointer, uncompress the data - FreeImage_ZLibUncompressEx = FreeImage_ZLibUncompress(lTargetDataPtr, _ - TargetSize, _ - lSourceDataPtr, _ - SourceSize) - End If - End If - -End Function - -Public Function FreeImage_ZLibGZipEx(ByRef Target As Variant, _ - Optional ByRef TargetSize As Long, _ - Optional ByRef Source As Variant, _ - Optional ByVal SourceSize As Long, _ - Optional ByVal Offset As Long) As Long - -Dim lSourceDataPtr As Long -Dim lTargetDataPtr As Long -Dim bTargetCreated As Boolean - - ' This function is a more VB friendly wrapper for compressing data with - ' the 'FreeImage_ZLibGZip' function. - - ' The parameter 'Target' may either be a VB style array of Byte, Integer - ' or Long or a pointer to a memory block. If 'Target' is a pointer to a - ' memory block (when it contains an address), 'TargetSize' must be - ' specified and greater than zero. If 'Target' is an initialized array, - ' the whole array will be used to store compressed data when 'TargetSize' - ' is missing or below or equal to zero. If 'TargetSize' is specified, only - ' the first TargetSize bytes of the array will be used. - ' In each case, all rules according to the FreeImage API documentation - ' apply, what means that the target buffer must be at least 0.1% greater - ' than the source buffer plus 24 bytes. - ' If 'Target' is an uninitialized array, the contents of 'TargetSize' - ' will be ignored and the size of the array 'Target' will be handled - ' internally. When the function returns, 'Target' will be initialized - ' as an array of Byte and sized correctly to hold all the compressed - ' data. - - ' Nearly all, that is true for the parameters 'Target' and 'TargetSize', - ' is also true for 'Source' and 'SourceSize', expect that 'Source' should - ' never be an uninitialized array. In that case, the function returns - ' immediately. - - ' The optional parameter 'Offset' may contain a number of bytes to remain - ' untouched at the beginning of 'Target', when an uninitialized array is - ' provided through 'Target'. When 'Target' is either a pointer or an - ' initialized array, 'Offset' will be ignored. This parameter is currently - ' used by 'FreeImage_ZLibGZipVB' to store the length of the uncompressed - ' data at the first four bytes of 'Target'. - - - ' get the pointer and the size in bytes of the source - ' memory block - lSourceDataPtr = pGetMemoryBlockPtrFromVariant(Source, SourceSize) - If (lSourceDataPtr) Then - ' when we got a valid pointer, get the pointer and the size in bytes - ' of the target memory block - lTargetDataPtr = pGetMemoryBlockPtrFromVariant(Target, TargetSize) - If (lTargetDataPtr = 0) Then - ' if 'Target' is a null pointer, we will initialized it as an array - ' of bytes; here we will take 'Offset' into account - ReDim Target(SourceSize + Int(SourceSize * 0.1) + _ - 24 + Offset) As Byte - ' get pointer and size in bytes (will never be a null pointer) - lTargetDataPtr = pGetMemoryBlockPtrFromVariant(Target, TargetSize) - ' adjust according to 'Offset' - lTargetDataPtr = lTargetDataPtr + Offset - TargetSize = TargetSize - Offset - bTargetCreated = True - End If - - ' compress source data - FreeImage_ZLibGZipEx = FreeImage_ZLibGZip(lTargetDataPtr, _ - TargetSize, _ - lSourceDataPtr, _ - SourceSize) - - ' the function returns the number of bytes needed to store the - ' compressed data or zero on failure - If (FreeImage_ZLibGZipEx) Then - If (bTargetCreated) Then - ' when we created the array, we need to adjust it's size - ' according to the length of the compressed data - ReDim Preserve Target(FreeImage_ZLibGZipEx - 1 + Offset) - End If - End If - End If - -End Function - -Public Function FreeImage_ZLibCRC32Ex(ByVal CRC As Long, _ - Optional ByRef Source As Variant, _ - Optional ByVal SourceSize As Long) As Long - -Dim lSourceDataPtr As Long - - ' This function is a more VB friendly wrapper for compressing data with - ' the 'FreeImage_ZLibCRC32' function. - - ' The parameter 'Source' may either be a VB style array of Byte, Integer - ' or Long or a pointer to a memory block. If 'Source' is a pointer to a - ' memory block (when it contains an address), 'SourceSize' must be - ' specified and greater than zero. If 'Source' is an initialized array, - ' the whole array will be used to calculate the new CRC when 'SourceSize' - ' is missing or below or equal to zero. If 'SourceSize' is specified, only - ' the first SourceSize bytes of the array will be used. - - - ' get the pointer and the size in bytes of the source - ' memory block - lSourceDataPtr = pGetMemoryBlockPtrFromVariant(Source, SourceSize) - If (lSourceDataPtr) Then - ' if we do not have a null pointer, calculate the CRC including 'crc' - FreeImage_ZLibCRC32Ex = FreeImage_ZLibCRC32(CRC, _ - lSourceDataPtr, _ - SourceSize) - End If - -End Function - -Public Function FreeImage_ZLibGUnzipEx(ByRef Target As Variant, _ - Optional ByRef TargetSize As Long, _ - Optional ByRef Source As Variant, _ - Optional ByVal SourceSize As Long) As Long - -Dim lSourceDataPtr As Long -Dim lTargetDataPtr As Long - - ' This function is a more VB friendly wrapper for compressing data with - ' the 'FreeImage_ZLibGUnzip' function. - - ' The parameter 'Target' may either be a VB style array of Byte, Integer - ' or Long or a pointer to a memory block. If 'Target' is a pointer to a - ' memory block (when it contains an address), 'TargetSize' must be - ' specified and greater than zero. If 'Target' is an initialized array, - ' the whole array will be used to store uncompressed data when 'TargetSize' - ' is missing or below or equal to zero. If 'TargetSize' is specified, only - ' the first TargetSize bytes of the array will be used. - ' In each case, all rules according to the FreeImage API documentation - ' apply, what means that the target buffer must be at least as large, to - ' hold all the uncompressed data. - ' Unlike the function 'FreeImage_ZLibGZipEx', 'Target' can not be - ' an uninitialized array, since the size of the uncompressed data can - ' not be determined by the ZLib functions, but must be specified by a - ' mechanism outside the FreeImage compression functions' scope. - - ' Nearly all, that is true for the parameters 'Target' and 'TargetSize', - ' is also true for 'Source' and 'SourceSize'. - - - ' get the pointer and the size in bytes of the source - ' memory block - lSourceDataPtr = pGetMemoryBlockPtrFromVariant(Source, SourceSize) - If (lSourceDataPtr) Then - ' when we got a valid pointer, get the pointer and the size in bytes - ' of the target memory block - lTargetDataPtr = pGetMemoryBlockPtrFromVariant(Target, TargetSize) - If (lTargetDataPtr) Then - ' if we do not have a null pointer, uncompress the data - FreeImage_ZLibGUnzipEx = FreeImage_ZLibGUnzip(lTargetDataPtr, _ - TargetSize, _ - lSourceDataPtr, _ - SourceSize) - End If - End If - -End Function - -Public Function FreeImage_ZLibCompressVB(ByRef Data() As Byte, _ - Optional ByVal IncludeSize As Boolean = True) As Byte() - -Dim lOffset As Long -Dim lArrayDataPtr As Long - - ' This function is another, even more VB friendly wrapper for the FreeImage - ' 'FreeImage_ZLibCompress' function, that uses the 'FreeImage_ZLibCompressEx' - ' function. This function is very easy to use, since it deals only with VB - ' style Byte arrays. - - ' The parameter 'Data()' is a Byte array, providing the uncompressed source - ' data, that will be compressed. - - ' The optional parameter 'IncludeSize' determines whether the size of the - ' uncompressed data should be stored in the first four bytes of the returned - ' byte buffer containing the compressed data or not. When 'IncludeSize' is - ' True, the size of the uncompressed source data will be stored. This works - ' in conjunction with the corresponding 'FreeImage_ZLibUncompressVB' function. - - ' The function returns a VB style Byte array containing the compressed data. - - - ' start population the memory block with compressed data - ' at offset 4 bytes, when the unclompressed size should - ' be included - If (IncludeSize) Then - lOffset = 4 - End If - - Call FreeImage_ZLibCompressEx(FreeImage_ZLibCompressVB, , Data, , lOffset) - - If (IncludeSize) Then - ' get the pointer actual pointing to the array data of - ' the Byte array 'FreeImage_ZLibCompressVB' - lArrayDataPtr = deref(deref(VarPtrArray(FreeImage_ZLibCompressVB)) + 12) - - ' copy uncompressed size into the first 4 bytes - Call CopyMemory(ByVal lArrayDataPtr, UBound(Data) + 1, 4) - End If - -End Function - -Public Function FreeImage_ZLibUncompressVB(ByRef Data() As Byte, _ - Optional ByVal SizeIncluded As Boolean = True, _ - Optional ByVal SizeNeeded As Long) As Byte() - -Dim abBuffer() As Byte - - ' This function is another, even more VB friendly wrapper for the FreeImage - ' 'FreeImage_ZLibUncompress' function, that uses the 'FreeImage_ZLibUncompressEx' - ' function. This function is very easy to use, since it deals only with VB - ' style Byte arrays. - - ' The parameter 'Data()' is a Byte array, providing the compressed source - ' data that will be uncompressed either withthe size of the uncompressed - ' data included or not. - - ' When the optional parameter 'SizeIncluded' is True, the function assumes, - ' that the first four bytes contain the size of the uncompressed data as a - ' Long value. In that case, 'SizeNeeded' will be ignored. - - ' When the size of the uncompressed data is not included in the buffer 'Data()' - ' containing the compressed data, the optional parameter 'SizeNeeded' must - ' specify the size in bytes needed to hold all the uncompressed data. - - ' The function returns a VB style Byte array containing the uncompressed data. - - - If (SizeIncluded) Then - ' get uncompressed size from the first 4 bytes and allocate - ' buffer accordingly - Call CopyMemory(SizeNeeded, Data(0), 4) - ReDim abBuffer(SizeNeeded - 1) - Call FreeImage_ZLibUncompressEx(abBuffer, , VarPtr(Data(4)), UBound(Data) - 3) - Call pSwap(VarPtrArray(FreeImage_ZLibUncompressVB), VarPtrArray(abBuffer)) - - ElseIf (SizeNeeded) Then - ' no size included in compressed data, so just forward the - ' call to 'FreeImage_ZLibUncompressEx' and trust on SizeNeeded - ReDim abBuffer(SizeNeeded - 1) - Call FreeImage_ZLibUncompressEx(abBuffer, , Data) - Call pSwap(VarPtrArray(FreeImage_ZLibUncompressVB), VarPtrArray(abBuffer)) - - End If - -End Function - -Public Function FreeImage_ZLibGZipVB(ByRef Data() As Byte, _ - Optional ByVal IncludeSize As Boolean = True) As Byte() - -Dim lOffset As Long -Dim lArrayDataPtr As Long - - ' This function is another, even more VB friendly wrapper for the FreeImage - ' 'FreeImage_ZLibGZip' function, that uses the 'FreeImage_ZLibGZipEx' - ' function. This function is very easy to use, since it deals only with VB - ' style Byte arrays. - - ' The parameter 'Data()' is a Byte array, providing the uncompressed source - ' data that will be compressed. - - ' The optional parameter 'IncludeSize' determines whether the size of the - ' uncompressed data should be stored in the first four bytes of the returned - ' byte buffer containing the compressed data or not. When 'IncludeSize' is - ' True, the size of the uncompressed source data will be stored. This works - ' in conjunction with the corresponding 'FreeImage_ZLibGUnzipVB' function. - - ' The function returns a VB style Byte array containing the compressed data. - - - ' start population the memory block with compressed data - ' at offset 4 bytes, when the unclompressed size should - ' be included - If (IncludeSize) Then - lOffset = 4 - End If - - Call FreeImage_ZLibGZipEx(FreeImage_ZLibGZipVB, , Data, , lOffset) - - If (IncludeSize) Then - ' get the pointer actual pointing to the array data of - ' the Byte array 'FreeImage_ZLibCompressVB' - lArrayDataPtr = deref(deref(VarPtrArray(FreeImage_ZLibGZipVB)) + 12) - - ' copy uncompressed size into the first 4 bytes - Call CopyMemory(ByVal lArrayDataPtr, UBound(Data) + 1, 4) - End If - -End Function - -Public Function FreeImage_ZLibGUnzipVB(ByRef Data() As Byte, _ - Optional ByVal SizeIncluded As Boolean = True, _ - Optional ByVal SizeNeeded As Long) As Byte() - -Dim abBuffer() As Byte - - ' This function is another, even more VB friendly wrapper for the FreeImage - ' 'FreeImage_ZLibGUnzip' function, that uses the 'FreeImage_ZLibGUnzipEx' - ' function. This function is very easy to use, since it deals only with VB - ' style Byte arrays. - - ' The parameter 'Data()' is a Byte array, providing the compressed source - ' data that will be uncompressed either withthe size of the uncompressed - ' data included or not. - - ' When the optional parameter 'SizeIncluded' is True, the function assumes, - ' that the first four bytes contain the size of the uncompressed data as a - ' Long value. In that case, 'SizeNeeded' will be ignored. - - ' When the size of the uncompressed data is not included in the buffer 'Data()' - ' containing the compressed data, the optional parameter 'SizeNeeded' must - ' specify the size in bytes needed to hold all the uncompressed data. - - ' The function returns a VB style Byte array containing the uncompressed data. - - - If (SizeIncluded) Then - ' get uncompressed size from the first 4 bytes and allocate - ' buffer accordingly - Call CopyMemory(SizeNeeded, Data(0), 4) - ReDim abBuffer(SizeNeeded - 1) - Call FreeImage_ZLibGUnzipEx(abBuffer, , VarPtr(Data(4)), UBound(Data) - 3) - Call pSwap(VarPtrArray(FreeImage_ZLibGUnzipVB), VarPtrArray(abBuffer)) - - ElseIf (SizeNeeded) Then - ' no size included in compressed data, so just forward the - ' call to 'FreeImage_ZLibUncompressEx' and trust on SizeNeeded - ReDim abBuffer(SizeNeeded - 1) - Call FreeImage_ZLibGUnzipEx(abBuffer, , Data) - Call pSwap(VarPtrArray(FreeImage_ZLibGUnzipVB), VarPtrArray(abBuffer)) - - End If - -End Function - - -'-------------------------------------------------------------------------------- -' Public functions to destroy custom safearrays -'-------------------------------------------------------------------------------- - -Public Function FreeImage_DestroyLockedArray(ByRef Data As Variant) As Long - -Dim lpArrayPtr As Long - - ' This function destroys an array, that was self created with a custom - ' array descriptor of type ('fFeatures' member) 'FADF_AUTO Or FADF_FIXEDSIZE'. - ' Such arrays are returned by mostly all of the array-dealing wrapper - ' functions. Since these should not destroy the actual array data, when - ' going out of scope, they are craeted as 'FADF_FIXEDSIZE'.' - - ' So, VB sees them as fixed or temporarily locked, when you try to manipulate - ' the array's dimensions. There will occur some strange effects, you should - ' know about: - - ' 1. When trying to 'ReDim' the array, this run-time error will occur: - ' Error #10, 'This array is fixed or temporarily locked' - - ' 2. When trying to assign another array to the array variable, this - ' run-time error will occur: - ' Error #13, 'Type mismatch' - - ' 3. The 'Erase' statement has no effect on the array - - ' Although VB clears up these arrays correctly, when the array variable - ' goes out of scope, you have to destroy the array manually, when you want - ' to reuse the array variable in current scope. - - ' For an example assume, that you want do walk all scanlines in an image: - - ' For i = 0 To FreeImage_GetHeight(Bitmap) - ' - ' ' assign scanline-array to array variable - ' abByte = FreeImage_GetScanLineEx(Bitmap, i) - ' - ' ' do some work on it... - ' - ' ' destroy the array (only the array, not the actual data) - ' Call FreeImage_DestroyLockedArray(dbByte) - ' Next i - - ' The function returns zero on success and any other value on failure - - ' !! Attention !! - ' This function uses a Variant parameter for passing the array to be - ' destroyed. Since VB does not allow to pass an array of non public - ' structures through a Variant parameter, this function can not be used - ' with arrays of cutom type. - - ' You will get this compiler error: "Only public user defined types defined - ' in public object modules can be used as parameters or return types for - ' public procedures of class modules or as fields of public user defined types" - - ' So, there is a function in the wrapper called 'FreeImage_DestroyLockedArrayByPtr' - ' that takes a pointer to the array variable which can be used to work around - ' that VB limitation and furthermore can be used for any of these self-created - ' arrays. To get the array variable's pointer, a declared version of the - ' VB 'VarPtr' function can be used which works for all types of arrays expect - ' String arrays. Declare this function like this in your code: - - ' Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" ( _ - ByRef Ptr() As Any) As Long - - ' Then an array could be destroyed by calling the 'FreeImage_DestroyLockedArrayByPtr' - ' function like this: - - ' lResult = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(MyLockedArray)) - - ' Additionally there are some handy wrapper functions available, one for each - ' commonly used structure in FreeImage like RGBTRIPLE, RGBQUAD, FICOMPLEX etc. - - - ' Currently, these functions do return 'FADF_AUTO Or FADF_FIXEDSIZE' arrays - ' that must be destroyed using this or any of it's derived functions: - - ' FreeImage_GetPaletteEx() with FreeImage_DestroyLockedArrayRGBQUAD() - ' FreeImage_GetPaletteLong() with FreeImage_DestroyLockedArray() - ' FreeImage_SaveToMemoryEx2() with FreeImage_DestroyLockedArray() - ' FreeImage_AcquireMemoryEx() with FreeImage_DestroyLockedArray() - ' FreeImage_GetScanLineEx() with FreeImage_DestroyLockedArray() - ' FreeImage_GetScanLineBITMAP8() with FreeImage_DestroyLockedArray() - ' FreeImage_GetScanLineBITMAP16() with FreeImage_DestroyLockedArray() - ' FreeImage_GetScanLineBITMAP24() with FreeImage_DestroyLockedArrayRGBTRIPLE() - ' FreeImage_GetScanLineBITMAP32() with FreeImage_DestroyLockedArrayRGBQUAD() - ' FreeImage_GetScanLineINT16() with FreeImage_DestroyLockedArray() - ' FreeImage_GetScanLineINT32() with FreeImage_DestroyLockedArray() - ' FreeImage_GetScanLineFLOAT() with FreeImage_DestroyLockedArray() - ' FreeImage_GetScanLineDOUBLE() with FreeImage_DestroyLockedArray() - ' FreeImage_GetScanLineCOMPLEX() with FreeImage_DestroyLockedArrayFICOMPLEX() - ' FreeImage_GetScanLineRGB16() with FreeImage_DestroyLockedArrayFIRGB16() - ' FreeImage_GetScanLineRGBA16() with FreeImage_DestroyLockedArrayFIRGBA16() - ' FreeImage_GetScanLineRGBF() with FreeImage_DestroyLockedArrayFIRGBF() - ' FreeImage_GetScanLineRGBAF() with FreeImage_DestroyLockedArrayFIRGBAF() - - - ' ensure, this is an array - If (VarType(Data) And vbArray) Then - - ' data is a VB array, what means a SAFEARRAY in C/C++, that is - ' passed through a ByRef Variant variable, that is a pointer to - ' a VARIANTARG structure - - ' the VARIANTARG structure looks like this: - - ' typedef struct tagVARIANT VARIANTARG; - ' struct tagVARIANT - ' { - ' Union - ' { - ' struct __tagVARIANT - ' { - ' VARTYPE vt; - ' WORD wReserved1; - ' WORD wReserved2; - ' WORD wReserved3; - ' Union - ' { - ' [...] - ' SAFEARRAY *parray; // used when not VT_BYREF - ' [...] - ' SAFEARRAY **pparray; // used when VT_BYREF - ' [...] - - ' the data element (SAFEARRAY) has an offset of 8, since VARTYPE - ' and WORD both have a length of 2 bytes; the pointer to the - ' VARIANTARG structure is the VarPtr of the Variant variable in VB - - ' getting the contents of the data element (in C/C++: *(data + 8)) - lpArrayPtr = deref(VarPtr(Data) + 8) - - ' call the 'FreeImage_DestroyLockedArrayByPtr' function to destroy - ' the array properly - Call FreeImage_DestroyLockedArrayByPtr(lpArrayPtr) - Else - - FreeImage_DestroyLockedArray = -1 - End If - -End Function - -Public Function FreeImage_DestroyLockedArrayByPtr(ByVal ArrayPtr As Long) As Long - -Dim lpSA As Long - - ' This function destroys a self-created array with a custom array - ' descriptor by a pointer to the array variable. - - ' dereference the pointer once (in C/C++: *ArrayPtr) - lpSA = deref(ArrayPtr) - ' now 'lpSA' is a pointer to the actual SAFEARRAY structure - ' and could be a null pointer when the array is not initialized - ' then, we have nothing to do here but return (-1) to indicate - ' an "error" - If (lpSA) Then - - ' destroy the array descriptor - Call SafeArrayDestroyDescriptor(lpSA) - - ' make 'lpSA' a null pointer, that is an uninitialized array; - ' keep in mind, that we here use 'ArrayPtr' as a ByVal argument, - ' since 'ArrayPtr' is a pointer to lpSA (the address of lpSA); - ' we need to zero these four bytes, 'ArrayPtr' points to - Call CopyMemory(ByVal ArrayPtr, 0&, 4) - Else - - ' the array is already uninitialized, so return an "error" value - FreeImage_DestroyLockedArrayByPtr = -1 - End If - -End Function - -Public Function FreeImage_DestroyLockedArrayRGBTRIPLE(ByRef Data() As RGBTRIPLE) As Long - - ' This function is a thin wrapper for 'FreeImage_DestroyLockedArrayByPtr' - ' for destroying arrays of type 'RGBTRIPLE'. - - FreeImage_DestroyLockedArrayRGBTRIPLE = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(Data)) - -End Function - -Public Function FreeImage_DestroyLockedArrayRGBQUAD(ByRef Data() As RGBQUAD) As Long - - ' This function is a thin wrapper for 'FreeImage_DestroyLockedArrayByPtr' - ' for destroying arrays of type 'RGBQUAD'. - - FreeImage_DestroyLockedArrayRGBQUAD = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(Data)) - -End Function - -Public Function FreeImage_DestroyLockedArrayFICOMPLEX(ByRef Data() As FICOMPLEX) As Long - - ' This function is a thin wrapper for 'FreeImage_DestroyLockedArrayByPtr' - ' for destroying arrays of type 'FICOMPLEX'. - - FreeImage_DestroyLockedArrayFICOMPLEX = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(Data)) - -End Function - -Public Function FreeImage_DestroyLockedArrayFIRGB16(ByRef Data() As FIRGB16) As Long - - ' This function is a thin wrapper for 'FreeImage_DestroyLockedArrayByPtr' - ' for destroying arrays of type 'FIRGB16'. - - FreeImage_DestroyLockedArrayFIRGB16 = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(Data)) - -End Function - -Public Function FreeImage_DestroyLockedArrayFIRGBA16(ByRef Data() As FIRGBA16) As Long - - ' This function is a thin wrapper for 'FreeImage_DestroyLockedArrayByPtr' - ' for destroying arrays of type 'FIRGBA16'. - - FreeImage_DestroyLockedArrayFIRGBA16 = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(Data)) - -End Function - -Public Function FreeImage_DestroyLockedArrayFIRGBF(ByRef Data() As FIRGBF) As Long - - ' This function is a thin wrapper for 'FreeImage_DestroyLockedArrayByPtr' - ' for destroying arrays of type 'FIRGBF'. - - FreeImage_DestroyLockedArrayFIRGBF = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(Data)) - -End Function - -Public Function FreeImage_DestroyLockedArrayFIRGBAF(ByRef Data() As FIRGBAF) As Long - - ' This function is a thin wrapper for 'FreeImage_DestroyLockedArrayByPtr' - ' for destroying arrays of type 'FIRGBAF'. - - FreeImage_DestroyLockedArrayFIRGBAF = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(Data)) - -End Function - - - -'-------------------------------------------------------------------------------- -' Private IOlePicture related helper functions -'-------------------------------------------------------------------------------- - -Private Function pGetIOlePictureFromContainer(ByRef Container As Object, _ - Optional ByVal IncludeDrawings As Boolean) As IPicture - - ' Returns a VB IOlePicture object (IPicture) from a VB image hosting control. - ' See the inline documentation of function 'FreeImage_CreateFromImageContainer' - ' for a detailed description of this helper function. - - If (Not Container Is Nothing) Then - - Select Case TypeName(Container) - - Case "PictureBox", "Form" - If (IncludeDrawings) Then - If (Not Container.AutoRedraw) Then - Call Err.Raise(5, _ - "MFreeImage", _ - Error$(5) & vbCrLf & vbCrLf & _ - "Custom drawings can only be included into the DIB when " & _ - "the container's 'AutoRedraw' property is set to True.") - Exit Function - End If - Set pGetIOlePictureFromContainer = Container.Image - Else - Set pGetIOlePictureFromContainer = Container.Picture - End If - - Case Else - - Dim bHasPicture As Boolean - Dim bHasImage As Boolean - Dim bIsAutoRedraw As Boolean - - On Error Resume Next - bHasPicture = (Container.Picture <> 0) - bHasImage = (Container.Image <> 0) - bIsAutoRedraw = Container.AutoRedraw - On Error GoTo 0 - - If ((IncludeDrawings) And _ - (bHasImage) And _ - (bIsAutoRedraw)) Then - Set pGetIOlePictureFromContainer = Container.Image - - ElseIf (bHasPicture) Then - Set pGetIOlePictureFromContainer = Container.Picture - - Else - Call Err.Raise(5, _ - "MFreeImage", _ - Error$(5) & vbCrLf & vbCrLf & _ - "Cannot create DIB from container control. Container " & _ - "control has no 'Picture' property.") - - End If - - End Select - - End If - -End Function - - - -'-------------------------------------------------------------------------------- -' Private image and color helper functions -'-------------------------------------------------------------------------------- - -Private Function pGetPreviousColorDepth(ByVal bpp As Long) As Long - - ' This function returns the 'previous' color depth of a given - ' color depth. Here, 'previous' means the next smaller color - ' depth. - - Select Case bpp - - Case 32 - pGetPreviousColorDepth = 24 - - Case 24 - pGetPreviousColorDepth = 16 - - Case 16 - pGetPreviousColorDepth = 15 - - Case 15 - pGetPreviousColorDepth = 8 - - Case 8 - pGetPreviousColorDepth = 4 - - Case 4 - pGetPreviousColorDepth = 1 - - End Select - -End Function - -Private Function pGetNextColorDepth(ByVal bpp As Long) As Long - - ' This function returns the 'next' color depth of a given - ' color depth. Here, 'next' means the next greater color - ' depth. - - Select Case bpp - - Case 1 - pGetNextColorDepth = 4 - - Case 4 - pGetNextColorDepth = 8 - - Case 8 - pGetNextColorDepth = 15 - - Case 15 - pGetNextColorDepth = 16 - - Case 16 - pGetNextColorDepth = 24 - - Case 24 - pGetNextColorDepth = 32 - - End Select - -End Function - - - -'-------------------------------------------------------------------------------- -' Private metadata helper functions -'-------------------------------------------------------------------------------- - -Private Function pGetTagFromTagPtr(ByVal Model As FREE_IMAGE_MDMODEL, _ - ByVal TagPtr As Long) As FREE_IMAGE_TAG - -Dim tTag As FITAG -Dim lTemp As Long -Dim i As Long - - ' This function converts data stored in a real FreeImage tag - ' pointer (FITAG **tag) into a VB friendly structure FREE_IMAGE_TAG. - - If (TagPtr <> 0) Then - - ' this is like (only like!) tTag tag = (FITAG) TagPtr; in C/C++ - ' we copy Len(tTag) bytes from the address in TagPtr in to a - ' private FITAG structure tTag so we have easy access to all - ' FITAG members - Call CopyMemory(tTag, ByVal deref(TagPtr), Len(tTag)) - - With pGetTagFromTagPtr - - ' first fill all members expect 'Value' in our - ' VB friendly FREE_IMAGE_TAG structure - - ' since we use this VB friendly FREE_IMAGE_TAG structure - ' for later tag modification too, we also need to store the - ' tag model and the pointer to the actual FreeImage FITAG - ' structure - .Model = Model - .TagPtr = TagPtr - - ' although FITAG's 'count' and 'length' members are - ' unsigned longs, we do not expect values greater - ' than 2,147,483,647, so we store them in normal VB - ' signed longs - .Count = tTag.Count - .Length = tTag.Length - - ' strings are stored as pointers to the actual string - ' data in FITAG - .Description = pGetStringFromPointerA(tTag.Description) - .Key = pGetStringFromPointerA(tTag.Key) - - ' FITAG's 'id' and 'type' members are unsigned shorts; - ' first of all 'id' may exceed the range of a signed - ' short (Integer data type in VB), so we store them in - ' signed longs and use CopyMemory for to keep the - ' unsigned bit layout - Call CopyMemory(.Id, tTag.Id, 2) - Call CopyMemory(.Type, tTag.Type, 2) - - ' StringValue is the result of FreeImage_TagToString(); we - ' also store this tag representation in our structure - .StringValue = FreeImage_TagToString(Model, TagPtr) - - - ' now comes the hard part, getting the tag's value - - Select Case .Type - - Case FIDT_BYTE, _ - FIDT_UNDEFINED - If (.Count > 1) Then - Dim abBytes() As Byte - ' for a byte array, just redim a VB Byte array and - ' copy Count bytes from the pointer - ReDim abBytes(.Count - 1) - Call CopyMemory(abBytes(0), ByVal tTag.Value, .Count) - .Value = abBytes - Else - ' copy a single byte into a Long and assign - ' with CByte() - Call CopyMemory(lTemp, ByVal tTag.Value, 1) - .Value = CByte(lTemp) - End If - - Case FIDT_ASCII - ' for an ASCII string, 'value' is just a pointer to the - ' string's actual data - .Value = pGetStringFromPointerA(tTag.Value) - - Case FIDT_SHORT - Dim iTemp As Integer - If (.Count > 1) Then - ' for a unsigned long array, first redim Value to - ' proper size - ReDim .Value(.Count - 1) - ' iterate over all items - For i = 0 To .Count - 1 - ' copy each value into a Long and - ' assign with FreeImage_UnsignedShort() to the - ' corresponding item in the (Variant) Value array - Call CopyMemory(iTemp, ByVal tTag.Value + i * 2, 2) - .Value(i) = FreeImage_UnsignedShort(iTemp) - Next i - Else - ' copy a single byte into a Long and assign - ' with FreeImgage_UnsignedShort() - Call CopyMemory(iTemp, ByVal tTag.Value, 2) - ' this works although FreeImage_UnsignedShort() takes - ' an Integer parameter since lTemp was 0 before and - ' we copied only 2 bytes so, VB's implicit conversion - ' to Integer will never produce an overflow - .Value = FreeImage_UnsignedShort(iTemp) - End If - - Case FIDT_LONG, _ - FIDT_IFD - If (.Count > 1) Then - ' for a unsigned long array, first redim Value to - ' proper size - ReDim .Value(.Count - 1) - ' iterate over all items - For i = 0 To .Count - 1 - ' copy each value into a (signed) Long and - ' assign with FreeImage_UnsignedLong() to the - ' corresponding item in the (Variant) Value array - Call CopyMemory(lTemp, ByVal tTag.Value + i * 4, 4) - .Value(i) = FreeImage_UnsignedLong(lTemp) - Next i - Else - ' copy a single unsigned long into a (signed) Long and - ' assign with FreeImage_UnsignedLong() - Call CopyMemory(lTemp, ByVal tTag.Value, 2) - .Value = FreeImage_UnsignedLong(lTemp) - End If - - Case FIDT_RATIONAL, _ - FIDT_SRATIONAL - ' rational values are always stored in the FREE_IMAGE_TAG - ' structure's FIRATIONAL array 'RationalValue' so, allocate - ' enough space in both the 'Value' and 'RationalValue' - ' members to hold 'Count' items - ReDim .Value(.Count - 1) - ReDim .RationalValue(.Count - 1) - For i = 0 To .Count - 1 - ' iterate over all items - With .RationalValue(i) - ' for each item, copy both numerator and denominator - ' into a (signed) Long and assign it to the corresponding - ' member of the FIRATIONAL structure so, we first assume - ' havinge a signed rational (FIDT_SRATIONAL) here - Call CopyMemory(lTemp, ByVal tTag.Value + i * 8, 4) - .Numerator = lTemp - Call CopyMemory(lTemp, ByVal tTag.Value + i * 8 + 4, 4) - .Denominator = lTemp - End With - ' if we have an unsigned rational (FIDT_RATIONAL), convert - ' numerator and denominator - If (.Type = FIDT_RATIONAL) Then - ' convert with FreeImage_UnsignedLong() - With .RationalValue(i) - .Numerator = FreeImage_UnsignedLong(.Numerator) - .Denominator = FreeImage_UnsignedLong(.Denominator) - End With - ' normalze the unsigned rational value - Call pNormalizeRational(.RationalValue(i)) - Else - ' normalze the signed rational value - Call pNormalizeSRational(.RationalValue(i)) - End If - ' store the current fraction's (maybe only approximated) value in - ' the 'Value' member of the FREE_IMAGE_TAG structure - .Value(i) = .RationalValue(i).Numerator / .RationalValue(i).Denominator - Next i - - Case FIDT_SBYTE - If (.Count > 1) Then - ' for a signed byte array, first redim Value to - ' proper size - ReDim .Value(.Count - 1) - ' iterate over all items - For i = 0 To .Count - 1 - ' copy each signed byte value into a Long and - ' check, whether it is negative (bit 7 set) - Call CopyMemory(lTemp, ByVal tTag.Value, 1) - If (lTemp And 128) Then - ' if negative, calculate the negative value - ' and store it in an Integer - .Value(i) = CInt(-256 - (Not (lTemp - 1))) - Else - ' if positive, assign to Value as byte - .Value(i) = CByte(lTemp) - End If - Next i - Else - ' copy a single signed byte into a Long and - ' check, whether it is negative (bit 7 set) - Call CopyMemory(lTemp, ByVal tTag.Value, 1) - If (lTemp And 128) Then - ' if negative, calculate the negative value - ' and store it in an Integer - .Value = CInt(-256 - (Not (lTemp - 1))) - Else - ' if positive, assign to Value as byte - .Value = CByte(lTemp) - End If - End If - - Case FIDT_SSHORT - If (.Count > 1) Then - Dim aiSShorts() As Integer - ' for a signed short array, just redim a VB Integer array and - ' copy Count bytes from the pointer - ReDim aiSShorts(.Count - 1) - Call CopyMemory(aiSShorts(0), ByVal tTag.Value, .Count * 2) - .Value = aiSShorts - Else - ' copy a single signed short into a Long and assign - ' with CInt() - Call CopyMemory(lTemp, ByVal tTag.Value, 2) - .Value = CInt(lTemp) - End If - - Case FIDT_SLONG - If (.Count > 1) Then - Dim alSLongs() As Long - ' for a signed long array, just redim a VB Long array and - ' copy Count bytes from the pointer - ReDim alSLongs(.Count - 1) - Call CopyMemory(alSLongs(0), ByVal tTag.Value, .Count * 4) - .Value = alSLongs - Else - ' copy a single signed long into a Long and assign - ' directly - Call CopyMemory(lTemp, ByVal tTag.Value, 4) - .Value = lTemp - End If - - Case FIDT_FLOAT - If (.Count > 1) Then - Dim asngFloats() As Single - ' for a float array, just redim a VB Single array and - ' copy Count bytes from the pointer - ReDim asngFloats(.Count - 1) - Call CopyMemory(asngFloats(0), ByVal tTag.Value, .Count * 4) - .Value = asngFloats - Else - Dim sngFloat As Single - ' copy a single float into a Single and assign - ' directly - Call CopyMemory(sngFloat, ByVal tTag.Value, 4) - .Value = sngFloat - End If - - Case FIDT_DOUBLE - If (.Count > 1) Then - Dim adblDoubles() As Double - ' for a double array, just redim a VB Double array and - ' copy Count bytes from the pointer - ReDim adblDoubles(.Count - 1) - Call CopyMemory(adblDoubles(0), ByVal tTag.Value, .Count * 8) - .Value = adblDoubles - Else - Dim dblDouble As Double - ' copy a single double into a Double and assign - ' directly - Call CopyMemory(dblDouble, ByVal tTag.Value, 8) - .Value = dblDouble - End If - - Case FIDT_PALETTE - ' copy 'Count' palette entries (RGBQUAD) form the value - ' pointer into the proper dimensioned array of RGBQUAD - ReDim .Palette(.Count - 1) - For i = 0 To .Count - 1 - Call CopyMemory(.Palette(i), ByVal tTag.Value + i * 4, 4) - Next i - - End Select - - End With - End If - -End Function - -Private Sub pNormalizeRational(ByRef Value As FIRATIONAL) - -Dim vntCommon As Long - - ' This function normalizes an unsigned fraction stored in a FIRATIONAL - ' structure by cancelling down the fraction. This is commonly done - ' by dividing both numerator and denominator by their greates - ' common divisor (gcd). - ' Does nothing if any of numerator and denominator is 1 or 0. - - With Value - If ((.Numerator <> 1) And (.Denominator <> 1) And _ - (.Numerator <> 0) And (.Denominator <> 0)) Then - vntCommon = gcd(.Numerator, .Denominator) - If (vntCommon <> 1) Then - ' convert values back to an unsigned long (may - ' result in a subtype Currency if the range of the - ' VB Long is insufficient for storing the value!) - .Numerator = FreeImage_UnsignedLong(.Numerator / vntCommon) - .Denominator = FreeImage_UnsignedLong(.Denominator / vntCommon) - End If - End If - End With - -End Sub - -Private Sub pNormalizeSRational(ByRef Value As FIRATIONAL) - -Dim lCommon As Long - - ' This function normalizes a signed fraction stored in a FIRATIONAL - ' structure by cancelling down the fraction. This is commonly done - ' by dividing both numerator and denominator by their greates - ' common divisor (gcd). - ' Does nothing if any of numerator and denominator is 1 or 0. - - With Value - If ((.Numerator <> 1) And (.Denominator <> 1) And _ - (.Numerator <> 0) And (.Denominator <> 0)) Then - lCommon = gcd(.Numerator, .Denominator) - If (lCommon <> 1) Then - ' using the CLng() function for not to get - ' a subtype Double here - .Numerator = CLng(.Numerator / lCommon) - .Denominator = CLng(.Denominator / lCommon) - End If - End If - - ' adjust the position of the negative sign if one is present: - ' it should preceed the numerator, not the denominator - If (.Denominator < 0) Then - .Denominator = -.Denominator - .Numerator = -.Numerator - End If - End With - -End Sub - -Private Function gcd(ByVal a As Variant, ByVal b As Variant) As Variant - -Dim vntTemp As Variant - - ' calculate greatest common divisor - - Do While (b) - vntTemp = b - ' calculate b = a % b (modulo) - ' this could be just: - ' b = a Mod b - ' but VB's Mod operator fails for unsigned - ' long values stored in currency variables - ' so, we use the mathematical definition of - ' the modulo operator taken from WikipediA. - b = a - floor(a / b) * b - a = vntTemp - Loop - gcd = a - -End Function - -Private Function floor(ByRef a As Variant) As Variant - - ' this is a VB version of the floor() function - If (a < 0) Then - floor = VBA.Int(a) - Else - floor = -VBA.Fix(-a) - End If - -End Function - -Private Function pTagToTagPtr(ByRef Tag As FREE_IMAGE_TAG) As Boolean - -Dim tTagSave As FITAG -Dim lpTag As Long -Dim abValueBuffer() As Byte -Dim lLength As Long -Dim lCount As Long - - ' This function converts tag data stored in a VB friendly structure - ' FREE_IMAGE_TAG into a real FreeImage tag pointer (FITAG **tag). - - ' This function is called, whenever tag data should be updated for an - ' image, since the FreeImage's tag pointer remains valid during the - ' whole lifetime of a DIB. So, changes written to that pointer (or - ' even better, the FITAG structure at the address, the pointer points - ' to), are real updates to the image's tag. - - With Tag - - lpTag = deref(.TagPtr) - - ' save current (FITAG) tag for an optional 'undo' operation - ' invoked on failure - Call CopyMemory(tTagSave, ByVal lpTag, Len(tTagSave)) - - ' set tag id - Call CopyMemory(ByVal lpTag + 8, .Id, 2) - ' set tag type - Call CopyMemory(ByVal lpTag + 10, .Type, 2) - ' set tag key (use native FreeImage function to handle - ' memory allocation) - Call FreeImage_SetTagKey(.TagPtr, .Key) - - ' here, we update the tag's value - ' generally, we create a plain byte buffer containing all the - ' value's data and use FreeImage_SetTagValue() with the - ' const void *value pointer set to the byte buffer's address. - - ' the variable abValueBuffer is our byte buffer that is, - ' depending on the FreeImage tag data type, allocated and filled - ' accordingly - ' The variables 'lLength' and 'lCount' are set up correctly for - ' each data type and will be filled into the FITAG structure - ' before calling FreeImage_SetTagValue(); after all, the VB - ' Tag structure's (FREE_IMAGE_TAG) 'Count' and 'Length' members - ' are updated with 'lLength' and 'lCount'. - - Select Case .Type - - Case FIDT_ASCII - ' use StrConv() to get an ASCII byte array from a VB String (BSTR) - abValueBuffer = StrConv(.Value, vbFromUnicode) - ' according to FreeImage's source code, both 'count' and 'length' - ' must be the length of the string - lCount = Len(.Value) - lLength = lCount - - Case FIDT_PALETTE - ' ensure, that there are at least 'Count' entries in the - ' palette array - lCount = .Count - If (UBound(.Palette) + 1 < lCount) Then - ' if not, adjust Count - lCount = UBound(.Palette) + 1 - End If - ' 4 bytes per element - lLength = lCount * 4 - ' allocate buffer and copy data from Palatte array - ReDim abValueBuffer(lLength - 1) - Call CopyMemory(abValueBuffer(0), .Palette(LBound(.Palette)), lLength) - - Case FIDT_RATIONAL, _ - FIDT_SRATIONAL - ' we use a helper function to get a byte buffer for any type of - ' rational value - lCount = pGetRationalValueBuffer(.RationalValue, abValueBuffer) - If (lCount > .Count) Then - lCount = .Count - End If - ' eight bytes per element (2 longs) - lLength = lCount * 8 - - Case Else - ' we use a helper function to get a byte buffer for any other type - lCount = pGetValueBuffer(.Value, .Type, lLength, abValueBuffer) - If (lCount > .Count) Then - lCount = .Count - End If - ' lLength was used as an OUT parameter when calling pGetValueBuffer - ' it now contains the size of one element in bytes so, multiply with - ' lCount to get the total length - lLength = lLength * lCount - - End Select - - ' set tag length - Call CopyMemory(ByVal lpTag + 16, lLength, 4) - ' set tag count - Call CopyMemory(ByVal lpTag + 12, lCount, 4) - - If (FreeImage_SetTagValue(.TagPtr, VarPtr(abValueBuffer(0))) <> 0) Then - - ' update Tag's members - ' update Count - .Count = lCount - ' update Length - .Length = lLength - ' update StringValue - .StringValue = FreeImage_TagToString(.Model, .TagPtr) - pTagToTagPtr = True - Else - - ' restore saved (FITAG) tag values on failure - Call CopyMemory(ByVal lpTag, tTagSave, Len(tTagSave)) - End If - - End With - -End Function - -Private Function pGetValueBuffer(ByRef Value As Variant, _ - ByVal MetaDataVarType As FREE_IMAGE_MDTYPE, _ - ByRef ElementSize As Long, _ - ByRef Buffer() As Byte) As Long - -Dim lElementCount As Long -Dim bIsArray As Boolean -Dim abValueBuffer(7) As Byte -Dim cBytes As Long -Dim i As Long - - ' This function copies any value provided in the Variant 'Value' - ' parameter into the byte array Buffer. 'Value' may contain an - ' array as well. The values in the byte buffer are aligned to fit - ' the FreeImage data type for tag values specified in - ' 'MetaDataVarType'. For integer values, it does not matter, in - ' which VB data type the values are provided. For example, it is - ' possible to transform a provided byte array into a unsigned long - ' array. - - ' The parameter 'ElementSize' is an OUT value, providing the actual - ' size per element in the byte buffer in bytes to the caller. - - ' This function works for the types FIDT_BYTE, FIDT_SHORT, FIDT_LONG, - ' FIDT_SBYTE , FIDT_SSHORT, FIDT_SLONG, FIDT_FLOAT, FIDT_DOUBLE - ' and FIDT_IFD - - ElementSize = pGetElementSize(MetaDataVarType) - If (Not IsArray(Value)) Then - lElementCount = 1 - Else - On Error Resume Next - lElementCount = UBound(Value) - LBound(Value) + 1 - On Error GoTo 0 - bIsArray = True - End If - - If (lElementCount > 0) Then - ReDim Buffer((lElementCount * ElementSize) - 1) - - If (Not bIsArray) Then - cBytes = pGetVariantAsByteBuffer(Value, abValueBuffer) - If (cBytes > ElementSize) Then - cBytes = ElementSize - End If - Call CopyMemory(Buffer(0), abValueBuffer(0), cBytes) - Else - For i = LBound(Value) To UBound(Value) - cBytes = pGetVariantAsByteBuffer(Value(i), abValueBuffer) - If (cBytes > ElementSize) Then - cBytes = ElementSize - End If - Call CopyMemory(Buffer(0 + (i * ElementSize)), abValueBuffer(0), cBytes) - Next i - End If - - pGetValueBuffer = lElementCount - End If - -End Function - -Private Function pGetRationalValueBuffer(ByRef RationalValues() As FIRATIONAL, _ - ByRef Buffer() As Byte) As Long - -Dim lElementCount As Long -Dim abValueBuffer(7) As Byte -Dim cBytes As Long -Dim i As Long - - ' This function copies a number of elements from the FIRATIONAL array - ' 'RationalValues' into the byte buffer 'Buffer'. - - ' From the caller's point of view, this function is the same as - ' 'pGetValueBuffer', except, it only works for arrays of FIRATIONAL. - - ' This function works for the types FIDT_RATIONAL and FIDT_SRATIONAL. - - lElementCount = UBound(RationalValues) - LBound(RationalValues) + 1 - ReDim Buffer(lElementCount * 8 + 1) - - For i = LBound(RationalValues) To UBound(RationalValues) - cBytes = pGetVariantAsByteBuffer(RationalValues(i).Numerator, abValueBuffer) - If (cBytes > 4) Then - cBytes = 4 - End If - Call CopyMemory(Buffer(0 + (i * 8)), abValueBuffer(0), cBytes) - - cBytes = pGetVariantAsByteBuffer(RationalValues(i).Denominator, abValueBuffer) - If (cBytes > 4) Then - cBytes = 4 - End If - Call CopyMemory(Buffer(4 + (i * 8)), abValueBuffer(0), cBytes) - Next i - - pGetRationalValueBuffer = lElementCount - -End Function - -Private Function pGetVariantAsByteBuffer(ByRef Value As Variant, _ - ByRef Buffer() As Byte) As Long - -Dim lLength As Long - - ' This function fills a byte buffer 'Buffer' with data taken - ' from a Variant parameter. Depending on the Variant's type and, - ' width, it copies N (lLength) bytes into the buffer starting - ' at the buffer's first byte at Buffer(0). The function returns - ' the number of bytes copied. - - ' It is much easier to assign the Variant to a variable of - ' the proper native type first, since gathering a Variant's - ' actual value is a hard job to implement for each subtype. - - Select Case VarType(Value) - - Case vbByte - Buffer(0) = Value - lLength = 1 - - Case vbInteger - Dim iInteger As Integer - iInteger = Value - lLength = 2 - Call CopyMemory(Buffer(0), iInteger, lLength) - - Case vbLong - Dim lLong As Long - lLong = Value - lLength = 4 - Call CopyMemory(Buffer(0), lLong, lLength) - - Case vbCurrency - Dim cCurrency As Currency - ' since the Currency data type is a so called scaled - ' integer, we have to divide by 10.000 first to get the - ' proper bit layout. - cCurrency = Value / 10000 - lLength = 8 - Call CopyMemory(Buffer(0), cCurrency, lLength) - - Case vbSingle - Dim sSingle As Single - sSingle = Value - lLength = 4 - Call CopyMemory(Buffer(0), sSingle, lLength) - - Case vbDouble - Dim dblDouble As Double - dblDouble = Value - lLength = 8 - Call CopyMemory(Buffer(0), dblDouble, lLength) - - End Select - - pGetVariantAsByteBuffer = lLength - -End Function - -Private Function pGetElementSize(ByVal vt As FREE_IMAGE_MDTYPE) As Long - - ' This function returns the width in bytes for any of the - ' FreeImage metadata tag data types. - - Select Case vt - - Case FIDT_BYTE, _ - FIDT_SBYTE, _ - FIDT_UNDEFINED, _ - FIDT_ASCII - pGetElementSize = 1 - - Case FIDT_SHORT, _ - FIDT_SSHORT - pGetElementSize = 2 - - Case FIDT_LONG, _ - FIDT_SLONG, _ - FIDT_FLOAT, _ - FIDT_PALETTE, _ - FIDT_IFD - pGetElementSize = 4 - - Case Else - pGetElementSize = 8 - - End Select - -End Function - - - -'-------------------------------------------------------------------------------- -' Private pointer manipulation helper functions -'-------------------------------------------------------------------------------- - -Private Function pGetStringFromPointerA(ByRef Ptr As Long) As String - -Dim abBuffer() As Byte -Dim lLength As Long - - ' This function creates and returns a VB BSTR variable from - ' a C/C++ style string pointer by making a redundant deep - ' copy of the string's characters. - - If (Ptr) Then - ' get the length of the ANSI string pointed to by ptr - lLength = lstrlen(Ptr) - If (lLength) Then - ' copy characters to a byte array - ReDim abBuffer(lLength - 1) - Call CopyMemory(abBuffer(0), ByVal Ptr, lLength) - ' convert from byte array to unicode BSTR - pGetStringFromPointerA = StrConv(abBuffer, vbUnicode) - End If - End If - -End Function - -Private Function deref(ByVal Ptr As Long) As Long - - ' This function dereferences a pointer and returns the - ' contents as it's return value. - - ' in C/C++ this would be: - ' return *(ptr); - - Call CopyMemory(deref, ByVal Ptr, 4) - -End Function - -Private Sub pSwap(ByVal lpSrc As Long, _ - ByVal lpDst As Long) - -Dim lpTmp As Long - - ' This function swaps two DWORD memory blocks pointed to - ' by lpSrc and lpDst, whereby lpSrc and lpDst are actually - ' no pointer types but contain the pointer's address. - - ' in C/C++ this would be: - ' void pSwap(int lpSrc, int lpDst) { - ' int tmp = *(int*)lpSrc; - ' *(int*)lpSrc = *(int*)lpDst; - ' *(int*)lpDst = tmp; - ' } - - Call CopyMemory(lpTmp, ByVal lpSrc, 4) - Call CopyMemory(ByVal lpSrc, ByVal lpDst, 4) - Call CopyMemory(ByVal lpDst, lpTmp, 4) - -End Sub - -Private Function pGetMemoryBlockPtrFromVariant(ByRef Data As Variant, _ - Optional ByRef SizeInBytes As Long, _ - Optional ByRef ElementSize As Long) As Long - - ' This function returns the pointer to the memory block provided through - ' the Variant parameter 'data', which could be either a Byte, Integer or - ' Long array or the address of the memory block itself. In the last case, - ' the parameter 'SizeInBytes' must not be omitted or zero, since it's - ' correct value (the size of the memory block) can not be determined by - ' the address only. So, the function fails, if 'SizeInBytes' is omitted - ' or zero and 'data' is not an array but contains a Long value (the address - ' of a memory block) by returning Null. - - ' If 'data' contains either a Byte, Integer or Long array, the pointer to - ' the actual array data is returned. The parameter 'SizeInBytes' will - ' be adjusted correctly, if it was less or equal zero upon entry. - - ' The function returns Null (zero) if there was no supported memory block - ' provided. - - ' do we have an array? - If (VarType(Data) And vbArray) Then - Select Case (VarType(Data) And (Not vbArray)) - - Case vbByte - ElementSize = 1 - pGetMemoryBlockPtrFromVariant = pGetArrayPtrFromVariantArray(Data) - If (pGetMemoryBlockPtrFromVariant) Then - If (SizeInBytes <= 0) Then - SizeInBytes = (UBound(Data) + 1) - - ElseIf (SizeInBytes > (UBound(Data) + 1)) Then - SizeInBytes = (UBound(Data) + 1) - - End If - End If - - Case vbInteger - ElementSize = 2 - pGetMemoryBlockPtrFromVariant = pGetArrayPtrFromVariantArray(Data) - If (pGetMemoryBlockPtrFromVariant) Then - If (SizeInBytes <= 0) Then - SizeInBytes = (UBound(Data) + 1) * 2 - - ElseIf (SizeInBytes > ((UBound(Data) + 1) * 2)) Then - SizeInBytes = (UBound(Data) + 1) * 2 - - End If - End If - - Case vbLong - ElementSize = 4 - pGetMemoryBlockPtrFromVariant = pGetArrayPtrFromVariantArray(Data) - If (pGetMemoryBlockPtrFromVariant) Then - If (SizeInBytes <= 0) Then - SizeInBytes = (UBound(Data) + 1) * 4 - - ElseIf (SizeInBytes > ((UBound(Data) + 1) * 4)) Then - SizeInBytes = (UBound(Data) + 1) * 4 - - End If - End If - - End Select - Else - ElementSize = 1 - If ((VarType(Data) = vbLong) And _ - (SizeInBytes >= 0)) Then - pGetMemoryBlockPtrFromVariant = Data - End If - End If - -End Function - -Private Function pGetArrayPtrFromVariantArray(ByRef Data As Variant) As Long - -Dim eVarType As VbVarType -Dim lDataPtr As Long - - ' This function returns a pointer to the first array element of - ' a VB array (SAFEARRAY) that is passed through a Variant type - ' parameter. (Don't try this at home...) - - ' cache VarType in variable - eVarType = VarType(Data) - - ' ensure, this is an array - If (eVarType And vbArray) Then - - ' data is a VB array, what means a SAFEARRAY in C/C++, that is - ' passed through a ByRef Variant variable, that is a pointer to - ' a VARIANTARG structure - - ' the VARIANTARG structure looks like this: - - ' typedef struct tagVARIANT VARIANTARG; - ' struct tagVARIANT - ' { - ' Union - ' { - ' struct __tagVARIANT - ' { - ' VARTYPE vt; - ' WORD wReserved1; - ' WORD wReserved2; - ' WORD wReserved3; - ' Union - ' { - ' [...] - ' SAFEARRAY *parray; // used when not VT_BYREF - ' [...] - ' SAFEARRAY **pparray; // used when VT_BYREF - ' [...] - - ' the data element (SAFEARRAY) has an offset of 8, since VARTYPE - ' and WORD both have a length of 2 bytes; the pointer to the - ' VARIANTARG structure is the VarPtr of the Variant variable in VB - - ' getting the contents of the data element (in C/C++: *(data + 8)) - lDataPtr = deref(VarPtr(Data) + 8) - - ' dereference the pointer again (in C/C++: *(lDataPtr)) - lDataPtr = deref(lDataPtr) - - ' test, whether 'lDataPtr' now is a Null pointer - ' in that case, the array is not yet initialized and so we can't dereference - ' it another time since we have no permisson to acces address 0 - - ' the contents of 'lDataPtr' may be Null now in case of an uninitialized - ' array; then we can't access any of the SAFEARRAY members since the array - ' variable doesn't event point to a SAFEARRAY structure, so we will return - ' the null pointer - - If (lDataPtr) Then - ' the contents of lDataPtr now is a pointer to the SAFEARRAY structure - - ' the SAFEARRAY structure looks like this: - - ' typedef struct FARSTRUCT tagSAFEARRAY { - ' unsigned short cDims; // Count of dimensions in this array. - ' unsigned short fFeatures; // Flags used by the SafeArray - ' // routines documented below. - ' #if defined(WIN32) - ' unsigned long cbElements; // Size of an element of the array. - ' // Does not include size of - ' // pointed-to data. - ' unsigned long cLocks; // Number of times the array has been - ' // locked without corresponding unlock. - ' #Else - ' unsigned short cbElements; - ' unsigned short cLocks; - ' unsigned long handle; // Used on Macintosh only. - ' #End If - ' void HUGEP* pvData; // Pointer to the data. - ' SAFEARRAYBOUND rgsabound[1]; // One bound for each dimension. - ' } SAFEARRAY; - - ' since we live in WIN32, the pvData element has an offset - ' of 12 bytes from the base address of the structure, - ' so dereference the pvData pointer, what indeed is a pointer - ' to the actual array (in C/C++: *(lDataPtr + 12)) - lDataPtr = deref(lDataPtr + 12) - End If - - ' return this value - pGetArrayPtrFromVariantArray = lDataPtr - - ' a more shorter form of this function would be: - ' (doesn't work for uninitialized arrays, but will likely crash!) - 'pGetArrayPtrFromVariantArray = deref(deref(deref(VarPtr(data) + 8)) + 12) - End If - -End Function +Attribute VB_Name = "MFreeImage" +'// ========================================================== +'// Visual Basic Wrapper for FreeImage 3 +'// Original FreeImage 3 functions and VB compatible derived functions +'// Design and implementation by +'// - Carsten Klein (cklein05@users.sourceforge.net) +'// +'// Main reference : Curland, Matthew., Advanced Visual Basic 6, Addison Wesley, ISBN 0201707128, (c) 2000 +'// Steve McMahon, creator of the excellent site vbAccelerator at http://www.vbaccelerator.com/ +'// MSDN Knowlede Base +'// +'// This file is part of FreeImage 3 +'// +'// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +'// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +'// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +'// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +'// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +'// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +'// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +'// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +'// THIS DISCLAIMER. +'// +'// Use at your own risk! +'// ========================================================== + +'// ========================================================== +'// CVS +'// $Revision: 2.17 $ +'// $Date: 2012/10/01 12:52:22 $ +'// $Id: MFreeImage.bas,v 2.17 2012/10/01 12:52:22 cklein05 Exp $ +'// ========================================================== + + +Option Explicit + +'-------------------------------------------------------------------------------- +' General notes on implementation and design +'-------------------------------------------------------------------------------- + +' General: + +' Most of the pointer type parameters used in the FreeImage API are actually +' declared as Long in VB. That is also true for return values. 'Out' parameters +' are declared ByRef, so they can receive the provided address of the pointer. +' 'In' parameters are declared ByVal since in VB the Long variable is not a +' pointer type but contains the address of the pointer. + + +' Functions returning a special type: + +' Some of the following external function declarations of the FreeImage 3 functions +' are declared Private. Additionally the token 'Int' is appended to the VB function +' name, what means 'Internal' to avoid naming confusion. All of these return a value +' of a certain type that can't be used with a declared function in VB directly but +' would need the function to be declared in a type library. Since this wrapper module +' should not depend on a compile time type library, these functions require some extra +' work to be done and also a VB wrapper function to make them look like the C/C++ +' function. + + +' Functions returning Strings: + +' Some of the declared FreeImage functions are defined as 'const char *' in C/C++ +' and so actually return a string pointer. Without using a type library for declaring +' these functions, in VB it is impossible to declare these functions to return a +' VB String type. So each of these functions is wrapped by a VB implemented function +' named correctly according to the FreeImage API, actually returning a 'real' VB String. + + +' Functions returning Booleans: + +' A Boolean is a numeric 32 bit value in both C/C++ and VB. In C/C++ TRUE is defined +' as 1 whereas in VB True is -1 (all bits set). When a function is declared as 'Boolean' +' in VB, the return value (all 32 bits) of the called function is just used "as is" and +' maybe assigned to a VB boolean variable. A Boolean in VB is 'False' when the numeric +' value is NULL (0) and 'True' in any other case. So, at a first glance, everything +' would be great since both numeric values -1 (VB True) and 1 (C/C++ TRUE) are actually +' 'True' in VB. +' But, if you have a VB variable (or a function returning a Boolean) with just some bits +' set and use the VB 'Not' operator, the result is not what you would expect. In this +' case, if bTest is True, (Not bTest) is also True. The 'Not' operator just toggles all +' bits by XOR-ing the value with -1. So, the result is not so surprisingly any more: +' The C/C++ TRUE value is 0...0001. When all bits are XORed with 1, the result is +' 1...1110 what is also not NULL (0) so this is still 'True' in VB. +' The resolution is to convert these return values into real VB Booleans in a wrapper +' function, one for each declared FreeImage function. Therefore each C/C++ BOOL +' function is declared Private as xxxInt(...). A Public Boolean wrapper function +' xxx(...) returns a real Boolean with 'xxx = (xxxInt(...) = 1)'. + + +' Extended and derived functions: + +' Some of the functions are additionally provided in an extended, call it a more VB +' friendly version, named '...Ex'. For example look at the 'FreeImage_GetPaletteEx' +' function. Most of them are dealing with arrays and so actually return a VB style +' array of correct type. + +' The wrapper also includes some derived functions that should make life easier for +' not only a VB programmer. + +' Better VB interoperability is given by offering conversion between DIBs and +' VB Picture objects. See the FreeImage_CreateFromOlePicture and +' FreeImage_GetOlePicture functions. + +' Both known VB functions LoadPicture() and SavePicture() are provided in extended +' versions calles LoadPictureEx() and SavePictureEx() offering the FreeImage 3´s +' image file types. + +' The FreeImage 3 error handling is provided in VB after calling the VB specific +' function FreeImage_InitErrorHandler() + + +' Enumerations: + +' All of the enumaration members are additionally 'declared' as constants in a +' conditional compiler directive '#If...#Then' block that is actually unreachable. +' For example see: +' +' Public Enum FREE_IMAGE_QUANTIZE +' FIQ_WUQUANT = 0 ' Xiaolin Wu color quantization algorithm +' FIQ_NNQUANT = 1 ' NeuQuant neural-net quantization algorithm by Anthony Dekker +' End Enum +' #If False Then +' Const FIQ_WUQUANT = 0 +' Const FIQ_NNQUANT = 1 +' #End If +' +' Since this module is supposed to be used directly in VB projects rather than in +' compiled form (mybe through an ActiveX-DLL), this is for tweaking some ugly VB +' behaviour regarding enumerations. Enum members are automatically adjusted in case +' by the VB IDE whenever you type these members in wrong case. Since these are also +' constants now, they are no longer adjusted to wrong case but always corrected +' according to the definition of the constant. As the expression '#If False Then' +' actually never comes true, these constants are not really defined either when running +' in the VB IDE nor in compiled form. + + +'-------------------------------------------------------------------------------- +' ToDo and known issues (unordered and with no priority) +'-------------------------------------------------------------------------------- + +' ToDo: more inline documentation for mask image creation and icon functions +' needed + +'-------------------------------------------------------------------------------- +' Change Log +'-------------------------------------------------------------------------------- + +'* : fixed +'- : removed +'! : changed +'+ : added +' +'October 1, 2012 - 2.17 +'- [Carsten Klein] removed temporary workaround for 16-bit standard type bitmaps introduced in version 2.15, which temporarily stored RGB masks directly after the BITMAPINFO structure, when creating a HBITMAP. +'* [Carsten Klein] fixed a potential overflow bug in both pNormalizeRational and pNormalizeSRational: these now do nothing if any of numerator and denominator is either 1 or 0 (zero). +'+ [Carsten Klein] added load flag JPEG_GREYSCALE as well as the enum constant FILO_JPEG_GREYSCALE. +'! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL to 4 to match current version 3.15.4 +' +'! now FreeImage version 3.15.4 +' +' +'March 19, 2012 - 2.16 +'! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL to 3 to match current version 3.15.3 +' +'! now FreeImage version 3.15.3 +' +' +'March 12, 2012 - 2.15 +'+ [Carsten Klein] added function FreeImage_ConvertToUINT16. +'+ [Carsten Klein] added function FreeImage_ConvertToRGB16. +'+ [Carsten Klein] added function FreeImage_GetThumbnail. +'+ [Carsten Klein] added function declaration FreeImage_SetThumbnailInt and a real VB Boolean returning function FreeImage_SetThumbnail. +'+ [Carsten Klein] added RAW_HALFSIZE load flag as well as the enum constant FILO_RAW_HALFSIZE. +'+ [Carsten Klein] added wrapper function FreeImage_GetPictureData, which returns a byte array suitable for assigning to an Office image control's PictureData property. +'+ [Carsten Klein] added wrapper function FreeImage_CreateFromPictureData, which creates a FreeImage bitmap from a PictureData byte array. +'+ [Carsten Klein] added new save flag JPEG_BASELINE (also added FISO_JPEG_BASELINE to enumeration FREE_IMAGE_SAVE_OPTIONS). +'+ [Carsten Klein] added a workaround for providing valid BITMAPINFO structures for non 555 16-bpp images to Windows API functions like CreateDIBSection, CreateDIBBitmap, StretchDIBits or SetDIBitsToDevice. +'! [Carsten Klein] changed constants FREEIMAGE_MINOR_VERSION and FREEIMAGE_RELEASE_SERIAL: set to 15 and 2 respectively to match current version 3.15.2 +' +'! now FreeImage version 3.15.2 +' +'March 13, 2011 - 2.14 +'* [Glenn Thorpe] fixed a typo error with the call to FreeImage_HasPixels inside FreeImage_CreateMask. +' +'August 11, 2010 - 2.13 +'+ [Carsten Klein] added PSD load flags PSD_CMYK and PSD_LAB as well as the enum constants FILO_PSD_CYMK and FILO_PSD_LAB. +'+ [Carsten Klein] added TIFF_LOGLUV save flag as well as the enum constant FISO_TIFF_LOGLUV. +' +'July 5, 2010 - 2.12 +'+ [Carsten Klein] added support for the new EXIF_RAW metadata model by adding enum constant FIMD_EXIF_RAW. +'+ [Carsten Klein] added the new FIF_LOAD_NOPIXELS flag as well as the enum constant FILO_LOAD_NOPIXELS. +'+ [Carsten Klein] added function declaration FreeImage_HasPixelsInt and a real VB Boolean returning function FreeImage_HasPixels. +'+ [Carsten Klein] added function declaration FreeImage_FIFSupportsNoPixelsInt and a real VB Boolean returning function FreeImage_FIFSupportsNoPixels. +' +'! now FreeImage version 3.14.1 +' +'June 20, 2010 - 2.11 +'+ [Carsten Klein] added new save flag JPEG_OPTIMIZE (also added FISO_JPEG_OPTIMIZE to enumeration FREE_IMAGE_SAVE_OPTIONS). +' +'April 20, 2010 - 2.10 +'+ [Carsten Klein] added new save flag TARGA_SAVE_RLE (also added FISO_TARGA_SAVE_RLE to enumeration FREE_IMAGE_SAVE_OPTIONS). +'! [Carsten Klein] changed constants FREEIMAGE_MINOR_VERSION and FREEIMAGE_RELEASE_SERIAL: set to 14 and 0 respectively to match current version 3.14.0 +'+ [Carsten Klein] added function FreeImage_ConvertToFloat. +'+ [Carsten Klein] added function FreeImage_SaveMultiBitmapToMemory. +'+ [Carsten Klein] added wrapper functions FreeImage_SaveMultiBitmapToMemoryEx and FreeImage_SaveMultiBitmapToMemoryEx2. +'+ [Carsten Klein] added wrapper function FreeImage_OpenMultiBitmapEx, which only opens existing files, but has support for automatic image format detection. +'+ [Carsten Klein] added wrapper function FreeImage_CreateMultiBitmapEx, which only creates new (empty) multi-page bitmaps with support for automatic image format detection. +'* [Carsten Klein] fixed a bug in FreeImage_LoadEx: now uses the file specified for format detection rather than the filename extension. +'+ [Carsten Klein] improved error messages in function FreeImage_LoadEx. +'* [Carsten Klein] fixed a bug in FreeImage_AcquireMemoryEx: no more crashes when passing an uninitialized array. +'+ [Carsten Klein] added thin wrapper functions, enabling proper handling of Boolean parameters: +'+ added wrapper function FreeImage_OpenMultiBitmap +'+ added wrapper function FreeImage_UnlockPage +'+ added wrapper function FreeImage_RotateEx +'+ added wrapper function FreeImage_MakeThumbnail +'+ added wrapper function FreeImage_GetAdjustColorsLookupTable +'+ added wrapper function FreeImage_ApplyColorMapping +'+ added wrapper function FreeImage_SwapColors +'+ added wrapper function FreeImage_SwapColorsByLong +'+ added wrapper function FreeImage_ApplyIndexMapping +'+ added wrapper function FreeImage_SetTransparent +'+ added wrapper function FreeImage_ConvertFromRawBits +'+ added wrapper function FreeImage_ConvertToRawBits +'+ added wrapper function FreeImage_ConvertToStandardType +'+ added wrapper function FreeImage_ConvertToType +'! [Carsten Klein] changed the parameter names of most functions. +'! [Carsten Klein] changed signature of functions FreeImage_ConvertFromRawBits and FreeImage_ConvertToRawBits: 'ByRef Bits As Long' is now 'ByVal BitsPtr As Long'. +'+ [Carsten Klein] added wrapper functions FreeImage_ConvertFromRawBitsEx and FreeImage_ConvertToRawBitsEx. +'* [Carsten Klein] fixed a bug in declaration of function FreeImage_TmoReinhard05Ex: parameters 'Adaption' and 'ColorCorrection' are now passed by value. +'- [Carsten Klein] removed half-implemented function FreeImage_SetChannelEx. +'+ [Carsten Klein] added wrapper function FreeImage_SetChannelIOP. +'- [Carsten Klein] removed needless default values of optional parameters. +'- [Carsten Klein] removed function declaration FreeImage_CompositeByLong: replaced by declaration FreeImage_Composite. +'! [Carsten Klein] changed function declaration FreeImage_Composite: application back color is now passed as ByRef ... As Any and so takes both RGBQUAD and Long valus. +'+ [Carsten Klein] added wrapper function FreeImage_UnloadEx, which additionally sets the ByRef-passed Bitmap handle to zero after unloading. +'+ [Carsten Klein] added wrapper functions ConvertColor and ConvertOleColor to convert VB-style BGR colors into RGB color values. +' +'! now FreeImage version 3.14.0 +' +'February 9, 2010 - 2.9.1 +'* [Carsten Klein] fixed a bug in FreeImage_GetBackgroundColorAsLong: parameter 'bkcolor' is now properly passed ByRef. +' +'February 9, 2010 - 2.9 +'* [Carsten Klein] fixed a syntax typo +' +'February 8, 2010 - 2.8 +'* [Mike Weir] fixed a bug in function FreeImage_ApplyColorMappingEx: now properly includes all specified mapping entries +'* [Carsten Klein] fixed a bug in function FreeImage_ApplyIndexMappingEx: now properly includes all specified mapping entries +'* [Mike Weir] fixed a bug in function FreeImage_RescaleEx: now also rescales the image, if either the new width or height matches the image's current size +'* [WinAnd / Carsten Klein] fixed a bug in function FreeImage_GetTransparencyTableExClone: returns an uninitialized array if there is no transparency table +'* [WinAnd / Carsten Klein] fixed a bug in function FreeImage_SearchPalette: no longer crashes if there is no transparency table +' +'December 21, 2009 - 2.7 +'! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 1 to match current version 3.13.1 +' +'! now FreeImage version 3.13.1 +' +'December 18, 2009 - 2.6 +'- [Carsten Klein] removed usage of constants vbPicTypeBitmap and vbPicTypeIcon: these are not available in VBA environments like Excel, Access or Outlook. +' +'September 08, 2009 - 2.5 +'! [Carsten Klein] changed constant FREEIMAGE_MINOR_VERSION: set to 13 to match current version 3.13.0 +'+ [Carsten Klein] added load flag constant JPEG_EXIFROTATE and new member FILO_JPEG_EXIFROTATE to enumeration FREE_IMAGE_LOAD_OPTIONS. +'+ [Carsten Klein] added support for the PFM image format. +'+ [Carsten Klein] added support for the PICT and RAW image formats. +'+ [Carsten Klein] added UNICODE functions FreeImage_JPEGTransformU and FreeImage_JPEGCropU. +'+ [Carsten Klein] added enumeration FREE_IMAGE_COLOR_OPTIONS, which contains options to specify colors, used with FreeImage_FillBackground and FreeImage_EnlargeCanvas. +'+ [Carsten Klein] added function FreeImage_FillBackground: although this returns BOOL in C/C++, the VB version only returns a Long. +'+ [Carsten Klein] added wrapper functions FreeImage_FillBackgroundEx and FreeImage_FillBackgroundByLong, taking an RGBQUAD and a Long 'Color' argument respectively and return a true VB Boolean. +'+ [Carsten Klein] added function FreeImage_EnlargeCanvas. +'+ [Carsten Klein] added functions FreeImage_AllocateEx and FreeImage_AllocateExT. +'+ [Carsten Klein] added function FreeImage_TmoReinhard05Ex. +'+ [Carsten Klein] added function FreeImage_Rotate. +'+ [Carsten Klein] added wrapper function FreeImage_RotateIOP. +' +'! now FreeImage version 3.13.0 +' +'March 18, 2009 - 2.4.2 +'+ [Carsten Klein] added enumeration FREE_IMAGE_FRAME_DISPOSAL_METHODS, which provides the frame disposal options needed to create animated GIF files. +' +'July 29, 2008 - 2.4.1 +'* [Carsten Klein] minor documentation updates +'! [Carsten Klein] renamed member FICF_PALETTISED_8BPP of enumeration FREE_IMAGE_CONVERSION_FLAGS into FICF_PALLETISED_8BPP. +' +'June 30, 2008 - 2.4 +'* [Carsten Klein] fixed some minor issues in FreeImage_PaintTransparent() +' +'June 06, 2008 - 2.3 +'+ [Carsten Klein] added new compression flags to the JPEG and PNG plugins +'! [Carsten Klein] renamed wrapper function FreeImage_CloneMetadata() to FreeImage_CloneMetadataEx(): now, there is a native function called FreeImage_CloneMetadata(). +'+ [Carsten Klein] added private and internal function declaration for FreeImage_CloneMetadata() along with it's public Boolean returning wrapper function. +'- [Carsten Klein] removed the FreeImage_ColorQuantizeEx() stuff from both functions FreeImage_ConvertColorDepth() and FreeImage_ConvertColorDepthIOP(): removed parameters PaletteSize, ReserveSize and ReservePalette. +'- [Carsten Klein] changed declaration of FreeImage_ColorQuantizeEx() to be a internal function private to the wrapper with an 'Int' appendix. +'+ [Carsten Klein] added two more VB-friendly public wrapper functions FreeImage_ColorQuantizeEx() and FreeImage_ColorQuantizeExIOP(). +'+ [Carsten Klein] added wrapper function FreeImage_GetPalettePtr(): gets the pointer to a specified array of RGBQUADs: intended to be used together with any of the ColorQuantizeEx functions. +'! [Carsten Klein] changed constant FREEIMAGE_MINOR_VERSION: set to 11 to match current version 3.11.0 +' +'! now FreeImage version 3.11.0 +' +'December 14, 2007 - 2.2.1 +'+ [Carsten Klein] added constants for member 'biCompression' in BITMAPINFOHEADER struct +'+ [Carsten Klein] added wrapper function FreeImage_GetInfoHeaderEx(), which returns a fully populated BITMAPINFOHEADER struct for a bitmap. +'* [Carsten Klein] fixed a bug in FreeImage_GetFileTypeFromMemoryEx(): now calls FreeImage_CloseMemory() releasing the hStream to prevent memory leaks. +'+ [Carsten Klein] added wrapper function FreeImage_GetColorizedPalette(): returns a colorized greyscale palettte. +'+ [Carsten Klein] added wrapper function FreeImage_Colorize(): applies a colorized greyscale palettte obtained from FreeImage_GetColorizedPalette() to a bitmap. +'+ [Carsten Klein] added wrapper function FreeImage_Sepia(): calls FreeImage_Colorize() with proper parameters to apply a so called sepia palette to a bitmap. +' +'December 12, 2007 - 2.2 +'* [Carsten Klein] fixed a small bug in FreeImage_PaintTransparent, which now calls function FreeImage_ConvertTo32Bits instead of FreeImage_ConvertTo32Bits2. +' +'November 15, 2007 - 2.1 +'* [Carsten Klein] adjusted page numbers of the API documentation in FreeImage function declarations to match FreeImage 3.10.0 API documentation +'- [Carsten Klein] removed parameter 'UnloadSource' from function FreeImage_GetOlePictureIcon(): an hIcon should not be destroyed if OleCreatePictureIndirect() is called with fOwn = True. +'! [Carsten Klein] refactored FreeImage_GetOlePicture(): now relies on FreeImage_GetBitmap(). +' +'November 10, 2007 - 2.0.8 +'! [Carsten Klein] changed declaration of FreeImage_SetOutputMessage(): now points transparently to the __stdcall version of this function in the library. +'+ [Carsten Klein] added function declaraton for FreeImage_MultigridPoissonSolver(). +'+ [Carsten Klein] added function declaraton for FreeImage_GetTransparentIndex() and FreeImage_SetTransparentIndex(). +'+ [Carsten Klein] added private and internal function declaration for FreeImage_AdjustColors() along with it's public Boolean returning wrapper function. +'+ [Carsten Klein] added function declaraton for FreeImage_GetAdjustColorsLookupTable(). +'+ [Carsten Klein] added wrapper function FreeImage_GetAdjustColorsLookupTableEx(): this takes a real VB style Byte array ton receive the lookup table created. +'+ [Carsten Klein] added function declaraton for FreeImage_ApplyColorMapping(). +'+ [Carsten Klein] added wrapper function FreeImage_ApplyColorMappingEx(): this takes a real VB style RGBQUAD array. +'+ [Carsten Klein] added function declaratons for FreeImage_SwapColors() and FreeImage_SwapColorsByLong(). +'+ [Carsten Klein] added function declaraton for FreeImage_ApplyIndexMapping(). +'+ [Carsten Klein] added wrapper function FreeImage_ApplyIndexMappingEx(): this takes a real VB style Byte array. +'+ [Carsten Klein] added function declaraton for FreeImage_SwapPaletteIndices(). +' +'November 05, 2007 - 2.0.7 +'+ [Carsten Klein] added 4 bit color depth to both function pGetNextColorDepth() and pGetPrevousColorDepth() +'- [Carsten Klein] removed member FICF_PREPARE_RESCALE from enumeration FREE_IMAGE_CONVERSION_FLAGS +'- [Carsten Klein] removed all references to FICF_PREPARE_RESCALE: Converting color depth before rescaling an image is no longer performed by the wrapper. Since FreeImage now transparently converts color depth on rescaling, doing this in the wrapper is no longer needed. +'! [Carsten Klein] refactored wrapper function FreeImage_ConvertColorDepth(): removed case FICF_PREPARE_RESCALE; is now more similar to C# wrapper's version of this function. +'! [Carsten Klein] refactored wrapper function FreeImage_SaveEx(): removed case FICF_PREPARE_RESCALE; is now more similar to C# wrapper's version of this function. +' +'September 14, 2007 - 2.0.6 +'+ [Carsten Klein] added function declaration and Boolean wrapper function for FreeImage_PreMultiplyWithAlpha(). +' +'July 26, 2007 - 2.0.5 +'+ [Carsten Klein] added wrapper function FreeImage_GetBitmap(): returns an HBITMAP created by the CreateDIBSection() function and so has the same color depth as the original DIB. +'+ [Carsten Klein] added wrapper function FreeImage_GetBitmapForDevice(): returns an HBITMAP created by the CreateDIBitmap() function and so has the same color depth as the specified reference DC or as the desktop, if the 'hDC' parameter was omitted. +'- [Carsten Klein] removed function declaration for GetWindowDC(): this function is no longer used. +'* [Carsten Klein] fixed a bug in wrapper function FreeImage_IsExtensionValidForFIF(): string comparison now includes a comma. +'* [Carsten Klein] fixed a bug in wrapper function FreeImage_IsFilenameValidForFIF(): string comparison now includes a comma. +' +'July 25, 2007 - 2.0.4 +'* [Carsten Klein] fixed a bug in function FreeImage_GetPaletteExClone(): now actually returns the palette as RGBQUAD array plus some other minor improvements +'+ [Carsten Klein] added wrapper function FreeImage_GetPaletteExLongClone(): this function returns a VB style Byte array that is only wrapped around FreeImage's pointer to a DIB's transparency table. +'+ [Carsten Klein] added wrapper function FreeImage_GetTransparencyTableEx(): this function returns a VB style Byte array that is only wrapped around FreeImage's pointer to a DIB's transparency table. +'! [Carsten Klein] changed name of wrapper function FreeImage_GetTransparencyTableEx(): this function is now named FreeImage_GetTransparencyTableExClone(), since it actually returns a clone (deep copy) of an image's transparency table (compare with FreeImage_GetPaletteExClone()). +'+ [Carsten Klein] added wrapper function FreeImage_SetPalette(): sets an image's palette through a VB style RGBQUAD array. +'+ [Carsten Klein] added wrapper function FreeImage_SetPaletteLong(): sets an image's palette through a VB style Long array. +'+ [Carsten Klein] added function declaration for CreateDIBsection() +'+ [Carsten Klein] added function declaration for DeleteDC() +'* [Carsten Klein] fixed a bug in wrapper function FreeImage_CreateFromScreen(): now the memory DC is deleted with the DeleteDC() function and no longer with the DeleteObject() function. +' +'July 05, 2007 - 2.0.3 +'+ [Carsten Klein] added wrapper function FreeImage_GetFileTypeFromMemoryEx(): more VB friendly version of FreeImage_GetFileTypeFromMemory() which may take an array rather than a FIMEMORY stream. +' +'May 21, 2007 - 2.0.2 +'! [Carsten Klein] changed constant FREEIMAGE_MINOR_VERSION: set to 10 to match current version 3.10.0 +'! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 0 to match current version 3.10.0 +'+ [Carsten Klein] added image format constants FIF_EXR, FIF_J2K and FIF_JP2 to enumeration FREE_IMAGE_FORMAT. +'+ [Carsten Klein] added tone mapping operator constant FITMO_FATTAL02 to enumeration FREE_IMAGE_TMO. +'+ [Carsten Klein] added save option constants J2K_DEFAULT and JP2_DEFAULT for JPEG2000 format. +'+ [Carsten Klein] added save option constants EXR_DEFAULT, EXR_FLOAT, EXR_NONE, EXR_ZIP, EXR_PIZ, EXR_PXR24, EXR_B44 and EXR_LC for EXR format. +'+ [Carsten Klein] added save option constants for EXR format to enumeration FREE_IMAGE_SAVE_OPTIONS. +'+ [Carsten Klein] added declared function FreeImage_TmoFattal02(): adds support for Gradient domain high dynamic range compression (R. Fattal, 2002) +' +'! now FreeImage version 3.10.0 +' +'February 24, 2007 - 2.0.1 +'* [Carsten Klein] fixed a bug in function FreeImage_CreateFromScreen(): now size of image created is according to window to be captured if parameter 'hwnd' <> 0. +'+ [Carsten Klein] added parameter 'bClientAreaOnly' to function FreeImage_CreateFromScreen(). +'+ [Carsten Klein] added blitting option 'CAPTUREBLT' when calling function BitBlt() in function FreeImage_CreateFromScreen(). +'- [Carsten Klein] removed unused variable 'hDIB' from functions FreeImage_CreateFromScreen() and FreeImage_LoadEx(). Thanks to Bruce Rusk for pointing that out. +' +'February 16, 2007 - 2.0 +'! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 3 to match current version 3.9.3 +'! [Carsten Klein] changed JPEG load/save flag option values: changed constants and both enumerations FREE_IMAGE_SAVE_OPTIONS and FREE_IMAGE_SAVE_OPTIONS. +'+ [Carsten Klein] added ICC Color Profile support: +'! changed signature of declared function FreeImage_GetICCProfile(): is now declared 'Private' and suffixed with '...Int()'. +'+ added wrapper function FreeImage_GetICCProfile(): is the public wrapper function for private function FreeImage_GetICCProfileInt(), returing a real FIICCPROFILE structure. +'+ added constant FREE_IMAGE_ICC_COLOR_MODEL_MASK. +'+ added enumeration FREE_IMAGE_ICC_COLOR_MODEL. +'+ added wrapper function FreeImage_GetICCProfileColorModel(): returns the color profile's color model (FIICCPROFILE.flags member). +'+ added wrapper function FreeImage_GetICCProfileSize(): returns the color profile data's size in bytes. +'+ added wrapper function FreeImage_GetICCProfileDataPointer(): returns the pointer to the color profile data. +'+ added wrapper function FreeImage_HasICCProfile(): returns whether a color profile is available for a dib or not. +'! [Carsten Klein] changed behaviour of wrapper function FreeImage_RescaleEx() and all it's derived functions: no clone is returned if the actual and desired image size are the same. +'+ [Carsten Klein] added parameter 'bForceCloneCreation' to wrapper function FreeImage_RescaleEx() and all it's derived functions. +' +'! now FreeImage version 3.9.3 +' +'January 09, 2007 - 1.9.4 +'! [Carsten Klein] changed scope of declared function FreeImage_GetFileTypeUInt(): is now private according to all other '...Int' functions wrapped by a VB-friendly function. +'! [Carsten Klein] changed scope of declared function FreeImage_GetFIFFromFilenameUInt(): is now private according to all other '...Int' functions wrapped by a VB-friendly function. +'! [Carsten Klein] changed signature of declared functions FreeImage_GetBackgroundColorInt() and FreeImage_SetBackgroundColorInt(): now both have a 'ByRef bkcolor As RGBQUAD' parameter instead of 'ByVal bkcolor As Long'. +'+ [Carsten Klein] added declared functions FreeImage_GetBackgroundColorAsLongInt(): this has a 'ByRef bkcolor As Long' parameter and provides the background color as a Long value. +'+ [Carsten Klein] added declared functions FreeImage_SetBackgroundColorAsLongInt(): this has a 'ByRef bkcolor As Long' parameter and takes the background color as a Long value. +'! [Carsten Klein] changed signature of wrapper functions FreeImage_GetBackgroundColor() and FreeImage_SetBackgroundColor(): now both have a 'ByRef bkcolor As RGBQUAD' parameter instead of 'ByVal bkcolor As Long'. +'+ [Carsten Klein] added wrapper functions FreeImage_GetBackgroundColorAsLong() and FreeImage_SetBackgroundColorAsLong(): both have a 'ByRef bkcolor As Long' parameter and so offer getting and setting the background color through a Long value. +'+ [Carsten Klein] added wrapper functions FreeImage_GetBackgroundColorEx() and FreeImage_SetBackgroundColorEx(): both both take 4 ByRef Byte parameters 'Alpha', 'Red', 'Green' and 'Blue', one for each color component. +' +'January 05, 2007 - 1.9.3 +'+ [Carsten Klein] added wrapper function FreeImage_GetLockedPageNumbersEx(): this returns a real VB-style array of Longs containing the page numbers of all locked pages. +' +'January 02, 2007 - 1.9.2 +'* [Carsten Klein] fixed a bug in inline description of function FreeImage_GetPaletteEx(): now tells to use function FreeImage_DestroyLockedArrayRGBQUAD() to free an array returned by this function. +'* [Carsten Klein] fixed some minor bugs in inline documentation. +'* [Carsten Klein] fixed a serious bug in function FreeImage_SaveEx(): parameter 'UnloadSource' is now interpreted correctly under all circumstances. +'* [Carsten Klein] fixed some minor issues in function FreeImage_SaveEx(). +' +'December 29, 2006 - 1.9.1 +'+ [Carsten Klein] added enumeration item FID_BAYER16x16: now supports Bayer ordered dispersed dot dithering (order 4 dithering matrix). +' +'October 31, 2006 - 1.9 +'* [Carsten Klein] adjusted page numbers of the API documentation in header comments in FreeImage function declarations to match FreeImage 3.9.2 API documentation +'! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 2 to match current version 3.9.2 +'+ [Carsten Klein] added function declaration for FreeImage_JPEGCrop(): added both declaration and Boolean returning wrapper function. +'! [Carsten Klein] changed data type of all occurences of parameter 'Flags' from Long to either FREE_IMAGE_LOAD_OPTIONS or FREE_IMAGE_SAVE_OPTIONS enum. This is true for declared functions as well as for wrapper functions. +'+ [Carsten Klein] added function declaration for FreeImage_LoadMultiBitmapFromMemory(). +'+ [Carsten Klein] added wrapper function FreeImage_LoadMultiBitmapFromMemoryEx(): this is dealing with a VB style array (SAFEARRAY) like FreeImage_LoadFromMemoryEx() does. +' +'! now FreeImage version 3.9.2 +' +'October 30, 2006 - 1.8 +'* [Carsten Klein] fixed a memory leak in wrapper function SavePictureEx(). Thanks to Roogames for reporting that bug. +'! [Carsten Klein] changed return type of wrapper function SavePictureEx() to Boolean. +'+ [Carsten Klein] added wrapper function FreeImage_SaveEx() which brings all the features, as there are inline size- and color conversion and format guessing, so far only known from SavePictureEx() for DIBs. +'! [Carsten Klein] changed wrapper function SavePictureEx(): now this is only a thin wrapper for function FreeImage_SaveEx(). +'+ [Carsten Klein] added enumeration FREE_IMAGE_LOAD_OPTIONS. +'- [Carsten Klein] refactored enumeration FREE_IMAGE_SAVE_OPTIONS: removed unnecessary items from enumeration. +'! [Carsten Klein] changed wrapper function LoadPictureEx(): added parameter 'Options' (enum FREE_IMAGE_LOAD_OPTIONS) to specify image loading options (called 'flags' in FreeImage). +'+ [Carsten Klein] added wrapper function FreeImage_LoadEx() which brings all the features, as there are inline size- and color conversion and format guessing, so far only known from LoadPictureEx() for DIBs. +'! [Carsten Klein] changed wrapper function LoadPictureEx(): now this is only a thin wrapper for function FreeImage_LoadEx(). +' +'October 13, 2006 - 1.7.2 +'+ [Carsten Klein] added User32 function GetDesktopWindow() +'+ added User32 function GetWindowDC() +'- [Carsten Klein] removed unused constants DI_MASK, DI_IMAGE and DI_NORMAL +'+ added GDI32 function GetDeviceCaps() with constants HORZRES and VERTRES +'+ added GDI32 function SelectObject() +'+ added GDI32 function DeleteObject() +'+ added GDI32 function CreateCompatibleBitmap() +'+ added GDI32 function CreateCompatibleDC() +'+ added GDI32 function BitBlt() +'+ [Carsten Klein] added wrapper function FreeImage_CreateFromScreen(): this function lets you capture the whole screen or any certain window +' +'October 10, 2006 - 1.7.1 +'! [Carsten Klein] changed parameter name 'Page' into 'hPageDib' in declared function FreeImage_UnlockPage(). 'hPageDib' must be the (dib-)handle obtained from FreeImage_LockPage() and not the page number. Now, the declaration is less confusing. Thanks to Ender Wiggin. +' +'August 4, 2006 - 1.7 +'* [Carsten Klein] fixed a bug in pGetTagFromTagPtr(): removed overflow error when converting unsigned short tags (FIDT_SHORT) with values between 32768 and 65535. Thanks to André Hendriks. +'! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 1 to match current version 3.9.1 +' +'! now FreeImage version 3.9.1 +' +'July 17, 2006 - 1.6 +'+ [Carsten Klein] added more public wrapper functions for tag copying and cloning: +'+ added function FreeImage_CopyMetadata() +'+ added function FreeImage_CloneMetadata() +'- [Carsten Klein] removed dead API functions, dead structures and dead variables +'* [Carsten Klein] fixed a bug in FreeImage_ConvertColorDepth(): now color images are converted to 24 bits when used with FICF_PREPARE_RESCALE, all others to 8 bit +' +'July 16, 2006 - 1.5.6 +'+ [Carsten Klein] added more public wrapper functions for VB friendly tag access: these functions deal with a FREE_IMAGE_TAG structure instead of FreeImage's Tag pointer. +'+ added function FreeImage_SetMetadataEx() +'+ added function FreeImage_CreateTagEx() +'+ added function FreeImage_AppendTag() +'+ added function FreeImage_RemoveTag() +'+ added function FreeImage_RemoveTagEx() +'+ added function FreeImage_TagExists() +'+ added function FreeImage_TagExistsEx() +'+ added function FreeImage_DeleteTagEx() +'+ added function FreeImage_CloneTagEx() +'+ added function FreeImage_RemoveMetadataModel() +'+ added function FreeImage_UpdateMetadata() +'+ added function FreeImage_UnsignedLong() +'+ added function FreeImage_UnsignedShort() +'+ added function FreeImage_CreateRational() +'+ added function FreeImage_CreateSignedRational() +'+ added function FreeImage_GetImageComment() +'+ added function FreeImage_SetImageComment() +'+ [Carsten Klein] added some private helper functions to leverage tag updating: +'+ added helper function pTagToTagPtr() +'+ added helper function pGetValueBuffer() +'+ added helper function pGetRationalValueBuffer() +'+ added helper function pGetVariantAsByteBuffer() +'+ added helper function pGetElementSize() +' +'July 5, 2006 - 1.5.5 +'! [Carsten Klein] changed function signature of FreeImage_FindNextMetadataEx(): optional parameter 'Model' is now present; see the function's inline documentation +' +'June 30, 2006 - 1.5.4 +'* [Carsten Klein] fixed bug in functions creating a FreeImage DIB from a windows hBitmap: workaround for palletized bitmaps is now implemented +'* fixed function FreeImage_CreateFromOLEPicture() +'* fixed function FreeImage_CreateFromDC() +' +'June 22, 2006 - 1.5.3 +'! [Carsten Klein] changed function declaration of FreeImage_GetMetadataInt(): parameter 'model' is now 'ByVal' and Tag is a Long pointer +'! [Carsten Klein] changed function declaration of FreeImage_SetMetadataInt(): parameter 'model' is now 'ByVal' and Tag is a Long pointer +'! [Carsten Klein] changed function declaration of FreeImage_GetMetadata(): parameter Tag is a Long pointer now +'! [Carsten Klein] changed function declaration of FreeImage_SetMetadata(): parameter Tag is a Long pointer now +'+ [Carsten Klein] added function declarations for tag creation and destruction: +'+ added declaration for function FreeImage_CreateTag() +'+ added declaration for procedure FreeImage_DeleteTag() +'+ added declaration for function FreeImage_CloneTag() +'+ [Carsten Klein] added new items to structure FREE_IMAGE_TAG: +'+ added item 'Model As FREE_IMAGE_MDMODEL' +'+ added item 'TagPtr As Long' +'+ [Carsten Klein] added wrapper functions for more VB friendly Tag access: these functions deal with a FREE_IMAGE_TAG structure instead of FreeImage's Tag pointer. +'+ added function FreeImage_FindFirstMetadataEx() +'+ added function FreeImage_FindNextMetadataEx() +'+ added function FreeImage_GetAllMetadataTags() +'+ added function FreeImage_GetMetadataEx() +'* [Carsten Klein] fixed and adjusted page numbers of the API documentation in header comments in FreeImage function declarations +'- [Carsten Klein] removed workaround for thresholding and dithering non-MINISBLACK 8 bit images in function FreeImage_ConvertColorDepth(): was fixed in FreeImage 3.9.0 +'* [Carsten Klein] fixed all pending issues in function FreeImage_PaintDC(): is now in production state +' +'June 14, 2006 - 1.5.2 +'! [Carsten Klein] changed signature of function FreeImage_CreateMask() +'+ [Carsten Klein] added function FreeImage_CreateMaskImage(): this creates a monochrome mask from a source image +'+ [Carsten Klein] added function FreeImage_CreateMaskInPlace(): this creates a monochrome mask from a source image +'+ [Carsten Klein] added enumeration FREE_IMAGE_ICON_TRANSPARENCY_OPTION_FLAGS +'+ [Carsten Klein] added wrapper function FreeImage_CreateSimpleBWMaskImage(): wrapper for FreeImage_CreateMaskImage() with reduced number of parameters; creates a b/w mask +'+ [Carsten Klein] added wrapper function FreeImage_CreateSimpleBWMaskInPlace(): wrapper for FreeImage_CreateMaskInPlace() with reduced number of parameters; creates a b/w mask +'+ [Carsten Klein] added function declaration for FreeImage_MakeThumbnail() +'+ [Carsten Klein] added function for FreeImage_GetOlePictureThumbnail() +'+ [Carsten Klein] added function for FreeImage_MakeThumbnailIOP() +'+ [Carsten Klein] documented function FreeImage_ReadMemoryEx() +'+ [Carsten Klein] documented function FreeImage_WriteMemoryEx() +'! [Carsten Klein] divided FreeImage_TagFromPointer into an interface only function with a private helper function pGetTagFromTagPtr(): +'+ added helper function pGetTagFromTagPtr() +'! [Carsten Klein] added private helper functions to leverage the FIDT_RATIONAL and FIDT_SRATIONAL data type: +'+ added helper function pNormalizeRational() +'+ added helper function pNormalizeSRational() +'+ added helper function gcd() +'+ added helper function floor() +'! [Carsten Klein] changed name of structure 'FITAG_int' to 'FITAG': is now as in FreeImage library +'! [Carsten Klein] changed name of structure 'FITAG' to 'FREE_IMAGE_TAG': this new structure plays an important role in the wrapper's new VB friendly tag accessing concept +'! [Carsten Klein] changed function declaration of FreeImage_GetMetadataCount(): parameter 'model' is now 'ByVal' +'! [Carsten Klein] changed function declaration of FreeImage_TagToString(): parameter 'model' is now 'ByVal' and function returns a Long +'! [Carsten Klein] renamed function declaration of FreeImage_TagToString() to FreeImage_TagToStringInt(): function is now Private and wrapped by a VB String returning function +'+ [Carsten Klein] added wrapper function FreeImage_TagToString() returning a real VB String +'+ [Carsten Klein] added structure FIRATIONAL: structure to hold an image tag's rational value +'+ [Carsten Klein] added new items to structure FREE_IMAGE_TAG: +'+ added item 'StringValue As String' +'+ added item 'Palette() As RGBQUAD' +'+ added item 'RationalValue() As FIRATIONAL' +' +'June 13, 2006 - 1.5.1 +'! [Carsten Klein] changed version constant 'FREEIMAGE_MINOR_VERSION' to 9 to meet version 3.9.0 +'* [Carsten Klein] fixed and adjusted page numbers of the API documentation in header comments in FreeImage function declarations to match FreeImage 3.9.0 API documentation +'+ [Carsten Klein] added function declaration for new Memory I/O functions in 3.9.0 +'+ added declaration FreeImage_ReadMemory() +'+ added declaration FreeImage_WriteMemory() +'! [Carsten Klein] changed/added optional parameter 'element_size' to private function pGetMemoryBlockPtrFromVariant(): caller now can get size in bytes one array element +'+ [Carsten Klein] added wrapper functions for new Memory I/O functions in 3.9.0 +'+ added function FreeImage_ReadMemoryEx() +'+ added function FreeImage_WriteMemoryEx() +'+ [Carsten Klein] added constants and updated enumerations for new 3.9.0 file formats 'FAXG3' and 'SGI' +'+ [Carsten Klein] added Windows GDI icon related declarations: +'+ added function declaration for CreateIconIndirect() +'+ added function declaration for DestroyIcon() +'+ added structure ICONINFO +'+ [Carsten Klein] added function FreeImage_GetIcon(): returns a hIcon handle +'+ [Carsten Klein] added function FreeImage_GetOlePictureIcon(): returns a VB Picture object of type vbPicTypeIcon +'+ [Carsten Klein] added enumeration FREE_IMAGE_MASK_FLAGS +'+ [Carsten Klein] added function FreeImage_CreateMaskColors(): returns an array filled with items from an argument list; synonym for VB's Array() function +'+ [Carsten Klein] added enumeration FREE_IMAGE_teMask(): this creates a monochrome mask from a source image +'+ [Carsten Klein] added function FreeImage_CreaMASK_CREATION_OPTION_FLAGS +' +'! now FreeImage version 3.9.0 +' +'June 12, 2006 - 1.5 +'* [Carsten Klein] fixed bug in wrapper function FreeImage_PaintDCEx(): now handles boolean test correctly: 'If ((hDC <> 0) And (hDIB <> 0)) Then -> Thanks to ender_wiggin for reporting that bug. +'+ [Carsten Klein] added private function pGetIOlePictureFromContainer(): used to get IPicture from image hosting control (Form, PictureBox) including custom drawings +'+ [Carsten Klein] added wrapper function FreeImage_CreateFromImageContainer(): used to create FreeImage DIB from image hosting control (Form, PictureBox) including custom drawings +'+ [Carsten Klein] added wrapper function SaveImageContainerEx(): derivate of wrapper function 'SavePictureEx()': saves content of image hosting control (Form, PictureBox) including custom drawings +' +'February 27, 2006 - 1.4.8 +'+ [Carsten Klein] added inline documentation for these wrapper functions: +'+ documented function FreeImage_CompareColorsLongLong() +'+ documented function FreeImage_CompareColorsRGBTRIPLELong() +'+ documented function FreeImage_CompareColorsRGBQUADLong() +'+ documented function FreeImage_SearchPalette() +'! [Carsten Klein] changed and updated general remarks in section "General notes on implementation and design" +'! [Carsten Klein] changed all function declarations of FreeImage functions that return a BOOL in C/C++: see "Functions returning Booleans" in section "General notes on implementation and design" +'! [Carsten Klein] changed all function signatures of functions that are derived from or extend FreeImage BOOL functions: see "Functions returning Booleans" in section "General notes on implementation and design" +'+ [Carsten Klein] added wrapper functions for all FreeImage functions that return a BOOL in C/C++: see "Functions returning Booleans" in section "General notes on implementation and design" +'+ [Carsten Klein] added wrapper function FreeImage_CreateFromDC(): creates an DIB from a DC. Thanks to Evan (wxforecaster) for this suggestion. +'+ [Carsten Klein] added declaration of GDI function GetCurrentObject() and constant OBJ_BITMAP +'+ [Carsten Klein] added wrapper function FreeImage_IsAvailable(): used to test for existence of FreeImage Library (FreeImage.dll) +' +'February 9, 2006 - 1.4.7 +'+ [Carsten Klein] added private helper function pGetPreviousColorDepth() +'+ [Carsten Klein] added private helper function pGetNextColorDepth() +'! [Carsten Klein] changed/extended signature of wrapper function SavePictureEx(): now includes a parameter 'ColorDepth' +'+ [Carsten Klein] added enumeration FREE_IMAGE_COLOR_DEPTH +'+ [Carsten Klein] added error handling capabilities to wrapper function SavePictureEx() +'+ [Carsten Klein] added/updated inline documentation of wrapper function SavePictureEx() +' +'October 31, 2005 - 1.4.6 +'+ [Carsten Klein] added wrapper function FreeImage_SwapColorLong(): this converts from a RGB to a BGR color value stored in a Long and vice versa +' +'October 27, 2005 - 1.4.5 +'+ [Carsten Klein] added function FreeImage_IsTransparencyTableTransparent(): checks for transparency directly on the transparency table +' +'October 13, 2005 - 1.4.4 +'+ [Carsten Klein] added some functions to compare colors in different formats and with tolerance: +'+ added function FreeImage_CompareColorsLongLong() +'+ added function FreeImage_CompareColorsRGBTRIPLELong() +'+ added function FreeImage_CompareColorsRGBQUADLong() +'+ [Carsten Klein] added enumeration FREE_IMAGE_COLOR_FORMAT_FLAGS +'+ [Carsten Klein] added enumeration FREE_IMAGE_TRANSPARENCY_STATE_FLAGS +'+ [Carsten Klein] added function FreeImage_SearchPalette(): to search the palette index for a given color +' +'October 13, 2005 - 1.4.3 +'+ [Carsten Klein] added additional function declaration FreeImage_SetPixelColorByLong(): now color values may be provided in a long value +'+ [Carsten Klein] added additional function declaration FreeImage_GetPixelColorByLong(): now color values may be received in a long value +'+ [Carsten Klein] added function FreeImage_SetPixelColorEx(): color values may be provided by four different byte values +'+ [Carsten Klein] added function FreeImage_GetPixelColorEx(): color values are returned through four different byte values +' +'October 11, 2005 - 1.4.2 +'* [Carsten Klein] fixed bug in wrapper function FreeImage_GetBitsExRGBQUAD(): now tests for and works with 32 bit images +' +'October 10, 2005 - 1.4.1 +'* [Carsten Klein] fixed serious bug in FreeImage_GetBitsEx...() functions: created custom array descriptor now really has two dimensions +'* fixed wrapper function FreeImage_GetBitsEx() +'* fixed wrapper function FreeImage_GetBitsExRGBTRIPLE() +'* fixed wrapper function FreeImage_GetBitsExRGBQUAD() +' +'September 9, 2005 - 1.4 +'! [Carsten Klein] changed wrapper function FreeImage_ConvertColorDepth(): now uses FreeImage_ConvertToGreyscale +'+ [Carsten Klein] added version numbers to change log +'+ [Carsten Klein] added comments to IOlePicture aware toolkit and conversion functions +'* [Carsten Klein] fixed and adjusted page numbers of the API documentation in header comments in FreeImage function declarations +' +'! now FreeImage version 3.8.0 +' +'September 8, 2005 - 1.3.5 +'! [Carsten Klein] changed version constant 'FREEIMAGE_MINOR_VERSION' to 8 to meet version 3.8.0 +'+ [Carsten Klein] added function declarations for UNICODE dealing functions with additional token 'Int' appended: +'+ added function FreeImage_LoadUInt() +'+ added function FreeImage_SaveUInt() +'+ added function FreeImage_GetFileTypeUInt() +'+ added function FreeImage_GetFIFFromFilenameUInt() +'+ [Carsten Klein] added wrapper functions to ease the use of UNICODE dealing functions: +'+ added function FreeImage_LoadU() +'+ added function FreeImage_SaveU() +'+ added function FreeImage_GetFileTypeU() +'+ added function FreeImage_GetFIFFromFilenameU() +'+ [Carsten Klein] added function declaration for FreeImage_ConvertToGreyscale() +' +'July 18, 2005 - 1.3.4 +'! [Carsten Klein] changed inline comments in these wrapper functions: +'! changed FreeImage_GetBitsEx(): mixed up width and height in SAFEAARAY creation +'! changed FreeImage_GetBitsExRGBTRIPLE(): mixed up width and height in SAFEAARAY creation +'! changed FreeImage_GetBitsExRGBQUAD(): mixed up width and height in SAFEAARAY creation +'+ [Carsten Klein] added wrapper function FreeImage_GetScanLinesRGBTRIPLE(): +' +'June 30, 2005 - 1.3.3 +'+ [Carsten Klein] added Kernel32 function FillMemory() +' +'June 24, 2005 - 1.3.2 +'+ [Carsten Klein] added pixel access functions FreeImage_GetBitsExRGBTRIPLE() and FreeImage_GetBitsExRGBQUAD() +'+ [Carsten Klein] added IOlePicture based wrapper function FreeImage_ConvertColorDepthIOP() +'+ [Carsten Klein] added IOlePicture based wrapper functions for FreeImage_RescaleIOP(): +'+ added function FreeImage_FreeImage_RescaleByPixelIOP() +'+ added function FreeImage_FreeImage_RescaleByPercentIOP() +'+ added function FreeImage_FreeImage_RescaleByFactorIOP() +'+ [Carsten Klein] added IOlePicture based wrapper function FreeImage_RescaleIOP() +'* [Carsten Klein] fixed a bug in FreeImage_GetOlePicture(): now OlePictures returned through IPicture may be used directly by other functions accepting IPicture types without any assignment to IPictureDisp +' +'June 24, 2005 - 1.3.1 +'! [Carsten Klein] changed improper function declaration of function FreeImage_AdjustCurve(): now parameter 'LUT' is passed ByVal +'+ [Carsten Klein] added wrapper function FreeImage_AdjustCurveEx() +'+ [Carsten Klein] added IOlePicture based wrapper functions for FreeImage toolkit functions: +'+ added function FreeImage_RotateClassicIOP() +'+ added function FreeImage_RotateExIOP() +'+ added function FreeImage_FlipHorizontalIOP() +'+ added function FreeImage_FlipVerticalIOP() +'+ added function FreeImage_AdjustCurveIOP() +'+ added function FreeImage_AdjustGammaIOP() +'+ added function FreeImage_AdjustBrightnessIOP() +'+ added function FreeImage_AdjustContrastIOP() +'+ added function FreeImage_InvertIOP() +'+ added function FreeImage_GetChannelIOP() +'+ added function FreeImage_CopyIOP() +'+ added function FreeImage_PasteIOP() +' +'June 22, 2005 - 1.3 +'+ [Carsten Klein] added inline comments and documentation for pixel access functions +' +'June 18, 2005 - 1.2.9 +'+ [Carsten Klein] added function FreeImage_GetBitsEx() +'+ [Carsten Klein] added structure SAFEARRAY2D to create 2 dimensional custom arrays +'+ [Carsten Klein] added function declarations for converting scanlines to 4 bpp: +'+ added declaration for FreeImage_ConvertLine1To4() +'+ added declaration for FreeImage_ConvertLine8To4() +'+ added declaration for FreeImage_ConvertLine16To4_555() +'+ added declaration for FreeImage_ConvertLine16To4_565() +'+ added declaration for FreeImage_ConvertLine24To4() +'+ added declaration for FreeImage_ConvertLine32To4() +' +'June 16, 2005 - 1.2.8 +'! [Carsten Klein] changed improper function declaration for all functions FreeImage_ConvertLineXXXX(): now parameters 'target' and 'Source' are passed ByVal +' +'June 15, 2005 - 1.2.7 +'+ [Carsten Klein] added function FreeImage_DestroyLockedArrayByPtr() to destroy a locked array by it's pointer (VB can't pass a array of structures through a Variant type) +'+ [Carsten Klein] added some wrapper functions for FreeImage_DestroyLockedArrayByPtr() for common FreeImage structures: +'+ added function FreeImage_DestroyLockedArrayRGBTRIPLE() +'+ added function FreeImage_DestroyLockedArrayRGBQUAD() +'+ added function FreeImage_DestroyLockedArrayFICOMPLEX() +'+ added function FreeImage_DestroyLockedArrayFIRGB16() +'+ added function FreeImage_DestroyLockedArrayFIRGBA16() +'+ added function FreeImage_DestroyLockedArrayFIRGBF() +'+ added function FreeImage_DestroyLockedArrayFIRGBAF() +'+ [Carsten Klein] added functions to return scanlines as VB style arrays in all supported FreeImage formats: +'+ added function FreeImage_GetScanLineBITMAP8() +'+ added function FreeImage_GetScanLineBITMAP16() +'+ added function FreeImage_GetScanLineBITMAP24() +'+ added function FreeImage_GetScanLineBITMAP32() +'+ added function FreeImage_GetScanLineINT16() +'+ added function FreeImage_GetScanLineINT32() +'+ added function FreeImage_GetScanLineFLOAT() +'+ added function FreeImage_GetScanLineDOUBLE() +'+ added function FreeImage_GetScanLineCOMPLEX() +'+ added function FreeImage_GetScanLineRGB16() +'+ added function FreeImage_GetScanLineRGBA16() +'+ added function FreeImage_GetScanLineRGBF() +'+ added function FreeImage_GetScanLineRGBAF() +' +'June 14, 2005 - 1.2.6 +'! [Carsten Klein] updated documentation on array-dealing functions using arrays with custom array descriptors +'+ [Carsten Klein] added function FreeImage_DestroyLockedArray() to destroy a self created array 'FADF_AUTO Or FADF_FIXEDSIZE' array +'+ [Carsten Klein] added function FreeImage_GetPaletteExLong() to return palette data in an array of type Long +'+ [Carsten Klein] added parameters 'lPaletteSize', 'vntReservePalette' and 'lReserveSize' to FreeImage_ConvertColorDepth() +' +'June 13, 2005 - 1.2.5 +'* [Carsten Klein] fixed a bug in helper function pGetMemoryBlockPtrFromVariant(): now 'size_in_bytes' will never exceed the size of an array provided +' +'June 12, 2005 - 1.2.4 +'+ [Carsten Klein] added ZLib compression function wrappers dealing with VB style arrays: +'+ added function FreeImage_ZLibCompressVB() +'+ added function FreeImage_ZLibUncompressVB() +'+ added function FreeImage_ZLibGZipVB() +'+ added function FreeImage_ZLibGUnzipVB() +' +'June 10, 2005 - 1.2.3 +'+ [Carsten Klein] added ZLib compression function wrappers dealing with VB style arrays: +'+ added function FreeImage_ZLibCompressEx() +'+ added function FreeImage_ZLibUncompressEx() +'+ added function FreeImage_ZLibGZipEx() +'+ added function FreeImage_ZLibCRC32Ex() +'+ added function FreeImage_ZLibGUnzipEx() +'+ [Carsten Klein] added more VB friendly ZLib compression function wrappers: +'+ added function FreeImage_ZLibCompressVB() +'+ added function FreeImage_ZLibUncompressVB() +'+ added function FreeImage_ZLibGZipVB() +'+ added function FreeImage_ZLibGUnzipVB() +'! [Carsten Klein] fixed wrong function declaration of functions FreeImage_ZLibGUnzip(): alias was '_FreeImage_ZLibZlibGUnzip@16' (double ZLib) +'! [Carsten Klein] fixed function pGetArrayPtrFromVariantArray() that now can deal with uninitialized arrays +'! fixed function pGetMemoryBlockPtrFromVariant() that now can deal with uninitialized arrays +'! [Carsten Klein] fixed wrong function declaration of functions FreeImage_AdjustBrightness(): ...@8 -> ...@12 +'! fixed wrong function declaration of functions FreeImage_AdjustContrast(): ...@8 -> ...@12 +'! fixed wrong function declaration of functions FreeImage_AdjustGamma(): ...@8 -> ...@12 +'! fixed wrong function declaration of functions FreeImage_RotateClassic(): ...@8 -> ...@12 +'! fixed wrong function declaration of functions FreeImage_RotateEx(): ...@28 -> ...@48 +' +'June 9, 2005 - 1.2.2 +'! [Carsten Klein] fixed wrong function declaration of function FreeImage_OpenMultiBitmap(): added parameter 'flags' (...@20 -> ...@24) +' +'June 8, 2005 - 1.2.1 +'! [Carsten Klein] refactored function FreeImage_LoadFromMemoryEx(): now using pGetMemoryBlockPtrFromVariant() +'+ [Carsten Klein] added private function pGetMemoryBlockPtrFromVariant() to get poiner and size of a memory block from a Variant parameter +'! [Carsten Klein] changed declaration of ZLib related functions: 'target' and 'Source' are now 'ByVal Long' +' +'June 7, 2005 - 1.2 +'+ [Carsten Klein] added some more inline comments and documentation +'+ [Carsten Klein] added optional parameter 'UnloadSource' to function FreeImage_SaveToMemoryEx() +'+ added optional parameter 'UnloadSource' to function FreeImage_SaveToMemoryEx2() +'+ [Carsten Klein] added optional parameter 'InPercent' to function SavePictureEx() +'! implemented the capability to resize the image on saving in function SavePictureEx() +'+ [Carsten Klein] added parameters 'InPercent' and 'Format' to function LoadPictureEx() +'* [Carsten Klein] fixed wrong function declaration of function FreeImage_JPEGTransform() (...@12 -> ...@16) +' +'June 6, 2005 - 1.1.2 +'+ [Carsten Klein] added some more inline comments and documentation +' +'May 30, 2005 - 1.1.1 +'* [Carsten Klein] fixed percent calculating bug in function FreeImage_RescaleEx() +'! changed behaviour of parameter 'bIsPercentValue' -> it now has no effect on integer values +'+ added function FreeImage_RescaleByPixel() to avoid confusion with overloading +'+ added function FreeImage_RescaleByPercent() to avoid confusion with overloading +'+ added function FreeImage_RescaleByFactor() to avoid confusion with overloading +'! [Carsten Klein] changed name of parameter 'bUnloadDIB' to 'UnloadSource' of function FreeImage_GetOlePicture() +'+ [Carsten Klein] added some more inline comments and documentation +'* [Carsten Klein] fixed a potential runtime error in function FreeImage_SetTransparencyTableEx(): 'Count' will no longer exceed 256 +' +'May 24, 2005 - 1.1 +'+ [Carsten Klein] added a new VB wrapper + + +'-------------------------------------------------------------------------------- +' Win32 API function, struct and constant declarations +'-------------------------------------------------------------------------------- + +Private Const ERROR_SUCCESS As Long = 0 + +'KERNEL32 +Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" ( _ + ByRef Destination As Any, _ + ByRef Source As Any, _ + ByVal Length As Long) + +Private Declare Sub FillMemory Lib "kernel32.dll" Alias "RtlFillMemory" ( _ + ByRef Destination As Any, _ + ByVal Length As Long, _ + ByVal Fill As Byte) + +Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" ( _ + ByVal lpString As Long) As Long + + +'OLEAUT32 +Private Declare Function OleCreatePictureIndirect Lib "oleaut32.dll" ( _ + ByRef lpPictDesc As PictDesc, _ + ByRef riid As Guid, _ + ByVal fOwn As Long, _ + ByRef lplpvObj As IPicture) As Long + +Private Declare Function SafeArrayAllocDescriptor Lib "oleaut32.dll" ( _ + ByVal cDims As Long, _ + ByRef ppsaOut As Long) As Long + +Private Declare Function SafeArrayDestroyDescriptor Lib "oleaut32.dll" ( _ + ByVal psa As Long) As Long + +Private Declare Sub SafeArrayDestroyData Lib "oleaut32.dll" ( _ + ByVal psa As Long) + +Private Declare Function OleTranslateColor Lib "oleaut32.dll" ( _ + ByVal clr As OLE_COLOR, _ + ByVal hPal As Long, _ + ByRef lpcolorref As Long) As Long + +Private Const CLR_INVALID As Long = &HFFFF& + + +'SAFEARRAY +Private Const FADF_AUTO As Long = (&H1) +Private Const FADF_FIXEDSIZE As Long = (&H10) + +Private Type SAVEARRAY1D + cDims As Integer + fFeatures As Integer + cbElements As Long + cLocks As Long + pvData As Long + cElements As Long + lLbound As Long +End Type + +Private Type SAVEARRAY2D + cDims As Integer + fFeatures As Integer + cbElements As Long + cLocks As Long + pvData As Long + cElements1 As Long + lLbound1 As Long + cElements2 As Long + lLbound2 As Long +End Type + + +'MSVBVM60 +Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" ( _ + ByRef Ptr() As Any) As Long + + +'USER32 +Private Declare Function ReleaseDC Lib "user32.dll" ( _ + ByVal hWnd As Long, _ + ByVal hDC As Long) As Long + +Private Declare Function GetDC Lib "user32.dll" ( _ + ByVal hWnd As Long) As Long + +Private Declare Function GetDesktopWindow Lib "user32.dll" () As Long + +Private Declare Function GetDCEx Lib "user32.dll" ( _ + ByVal hWnd As Long, _ + ByVal hrgnclip As Long, _ + ByVal fdwOptions As Long) As Long + +Private Const DCX_WINDOW As Long = &H1& + +Private Declare Function GetWindowRect Lib "user32.dll" ( _ + ByVal hWnd As Long, _ + ByRef lpRect As RECT) As Long + +Private Declare Function GetClientRect Lib "user32.dll" ( _ + ByVal hWnd As Long, _ + ByRef lpRect As RECT) As Long + + +Private Type RECT + Left As Long + Top As Long + Right As Long + Bottom As Long +End Type + +Private Type Guid + Data1 As Long + Data2 As Integer + Data3 As Integer + Data4(0 To 7) As Byte +End Type + +Private Type PictDesc + cbSizeofStruct As Long + picType As Long + hImage As Long + xExt As Long + yExt As Long +End Type + +Private Type BITMAP_API + bmType As Long + bmWidth As Long + bmHeight As Long + bmWidthBytes As Long + bmPlanes As Integer + bmBitsPixel As Integer + bmBits As Long +End Type + +Private Type ICONINFO + fIcon As Long + xHotspot As Long + yHotspot As Long + hBmMask As Long + hbmColor As Long +End Type + +Private Type BLENDFUNCTION + BlendOp As Byte + BlendFlags As Byte + SourceConstantAlpha As Byte + AlphaFormat As Byte +End Type + +'GDI32 +Private Declare Function GetDeviceCaps Lib "gdi32.dll" ( _ + ByVal hDC As Long, _ + ByVal nIndex As Long) As Long + +Private Const HORZRES As Long = 8 +Private Const VERTRES As Long = 10 + +Private Declare Function GetStretchBltMode Lib "gdi32.dll" ( _ + ByVal hDC As Long) As Long + +Private Declare Function SetStretchBltMode Lib "gdi32.dll" ( _ + ByVal hDC As Long, _ + ByVal nStretchMode As Long) As Long + +Private Declare Function SetDIBitsToDevice Lib "gdi32.dll" ( _ + ByVal hDC As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByVal dx As Long, _ + ByVal dy As Long, _ + ByVal SrcX As Long, _ + ByVal SrcY As Long, _ + ByVal Scan As Long, _ + ByVal NumScans As Long, _ + ByVal Bits As Long, _ + ByVal BitsInfo As Long, _ + ByVal wUsage As Long) As Long + +Private Declare Function StretchDIBits Lib "gdi32.dll" ( _ + ByVal hDC As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByVal dx As Long, _ + ByVal dy As Long, _ + ByVal SrcX As Long, _ + ByVal SrcY As Long, _ + ByVal wSrcWidth As Long, _ + ByVal wSrcHeight As Long, _ + ByVal lpBits As Long, _ + ByVal lpBitsInfo As Long, _ + ByVal wUsage As Long, _ + ByVal dwRop As Long) As Long + +Private Declare Function CreateDIBitmap Lib "gdi32.dll" ( _ + ByVal hDC As Long, _ + ByVal lpInfoHeader As Long, _ + ByVal dwUsage As Long, _ + ByVal lpInitBits As Long, _ + ByVal lpInitInfo As Long, _ + ByVal wUsage As Long) As Long + +Private Declare Function CreateDIBSection Lib "gdi32.dll" ( _ + ByVal hDC As Long, _ + ByVal pbmi As Long, _ + ByVal iUsage As Long, _ + ByRef ppvBits As Long, _ + ByVal hSection As Long, _ + ByVal dwOffset As Long) As Long + +Private Const CBM_INIT As Long = &H4 + +Private Declare Function CreateCompatibleBitmap Lib "gdi32.dll" ( _ + ByVal hDC As Long, _ + ByVal nWidth As Long, _ + ByVal nHeight As Long) As Long + +Private Declare Function CreateCompatibleDC Lib "gdi32.dll" ( _ + ByVal hDC As Long) As Long + +Private Declare Function DeleteDC Lib "gdi32.dll" ( _ + ByVal hDC As Long) As Long + +Private Declare Function BitBlt Lib "gdi32.dll" ( _ + ByVal hDestDC As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByVal nWidth As Long, _ + ByVal nHeight As Long, _ + ByVal hSrcDC As Long, _ + ByVal XSrc As Long, _ + ByVal YSrc As Long, _ + ByVal dwRop As Long) As Long + +Private Declare Function GetDIBits Lib "gdi32.dll" ( _ + ByVal aHDC As Long, _ + ByVal hBitmap As Long, _ + ByVal nStartScan As Long, _ + ByVal nNumScans As Long, _ + ByVal lpBits As Long, _ + ByVal lpBI As Long, _ + ByVal wUsage As Long) As Long + +Private Declare Function GetObjectAPI Lib "gdi32.dll" Alias "GetObjectA" ( _ + ByVal hObject As Long, _ + ByVal nCount As Long, _ + ByRef lpObject As Any) As Long + +Private Declare Function SelectObject Lib "gdi32.dll" ( _ + ByVal hDC As Long, _ + ByVal hObject As Long) As Long + +Private Declare Function DeleteObject Lib "gdi32.dll" ( _ + ByVal hObject As Long) As Long + +Private Declare Function GetCurrentObject Lib "gdi32.dll" ( _ + ByVal hDC As Long, _ + ByVal uObjectType As Long) As Long + +Private Const OBJ_BITMAP As Long = 7 + + +Private Declare Function DestroyIcon Lib "user32.dll" ( _ + ByVal hIcon As Long) As Long + +Private Declare Function CreateIconIndirect Lib "user32.dll" ( _ + ByRef piconinfo As ICONINFO) As Long + +Private Const BLACKONWHITE As Long = 1 +Private Const WHITEONBLACK As Long = 2 +Private Const COLORONCOLOR As Long = 3 + +'MSIMG32 +Private Declare Function AlphaBlend Lib "msimg32.dll" ( _ + ByVal hdcDest As Long, _ + ByVal nXOriginDest As Long, _ + ByVal nYOriginDest As Long, _ + ByVal nWidthDest As Long, _ + ByVal nHeightDest As Long, _ + ByVal hdcSrc As Long, _ + ByVal nXOriginSrc As Long, _ + ByVal nYOriginSrc As Long, _ + ByVal nWidthSrc As Long, _ + ByVal nHeightSrc As Long, _ + ByVal lBlendFunction As Long) As Long + +Private Const AC_SRC_OVER = &H0 +Private Const AC_SRC_ALPHA = &H1 + + +Public Enum STRETCH_MODE + SM_BLACKONWHITE = BLACKONWHITE + SM_WHITEONBLACK = WHITEONBLACK + SM_COLORONCOLOR = COLORONCOLOR +End Enum +#If False Then + Const SM_BLACKONWHITE = BLACKONWHITE + Const SM_WHITEONBLACK = WHITEONBLACK + Const SM_COLORONCOLOR = COLORONCOLOR +#End If + + +Private Const SRCAND As Long = &H8800C6 +Private Const SRCCOPY As Long = &HCC0020 +Private Const SRCERASE As Long = &H440328 +Private Const SRCINVERT As Long = &H660046 +Private Const SRCPAINT As Long = &HEE0086 +Private Const CAPTUREBLT As Long = &H40000000 + +Public Enum RASTER_OPERATOR + ROP_SRCAND = SRCAND + ROP_SRCCOPY = SRCCOPY + ROP_SRCERASE = SRCERASE + ROP_SRCINVERT = SRCINVERT + ROP_SRCPAINT = SRCPAINT +End Enum +#If False Then + Const ROP_SRCAND = SRCAND + Const ROP_SRCCOPY = SRCCOPY + Const ROP_SRCERASE = SRCERASE + Const ROP_SRCINVERT = SRCINVERT + Const ROP_SRCPAINT = SRCPAINT +#End If + +Private Const DIB_PAL_COLORS As Long = 1 +Private Const DIB_RGB_COLORS As Long = 0 + +Public Enum DRAW_MODE + DM_DRAW_DEFAULT = &H0 + DM_MIRROR_NONE = DM_DRAW_DEFAULT + DM_MIRROR_VERTICAL = &H1 + DM_MIRROR_HORIZONTAL = &H2 + DM_MIRROR_BOTH = DM_MIRROR_VERTICAL Or DM_MIRROR_HORIZONTAL +End Enum +#If False Then + Const DM_DRAW_DEFAULT = &H0 + Const DM_MIRROR_NONE = DM_DRAW_DEFAULT + Const DM_MIRROR_VERTICAL = &H1 + Const DM_MIRROR_HORIZONTAL = &H2 + Const DM_MIRROR_BOTH = DM_MIRROR_VERTICAL Or DM_MIRROR_HORIZONTAL +#End If + +Public Enum HISTOGRAM_ORIENTATION + HOR_TOP_DOWN = &H0 + HOR_BOTTOM_UP = &H1 +End Enum +#If False Then + Const HOR_TOP_DOWN = &H0 + Const HOR_BOTTOM_UP = &H1 +#End If + + +'-------------------------------------------------------------------------------- +' FreeImage 3 types, constants and enumerations +'-------------------------------------------------------------------------------- + +'FREEIMAGE + +' Version information +Public Const FREEIMAGE_MAJOR_VERSION As Long = 3 +Public Const FREEIMAGE_MINOR_VERSION As Long = 15 +Public Const FREEIMAGE_RELEASE_SERIAL As Long = 4 + +' Memory stream pointer operation flags +Public Const SEEK_SET As Long = 0 +Public Const SEEK_CUR As Long = 1 +Public Const SEEK_END As Long = 2 + +' Indexes for byte arrays, masks and shifts for treating pixels as words +' These coincide with the order of RGBQUAD and RGBTRIPLE +' Little Endian (x86 / MS Windows, Linux) : BGR(A) order +Public Const FI_RGBA_RED As Long = 2 +Public Const FI_RGBA_GREEN As Long = 1 +Public Const FI_RGBA_BLUE As Long = 0 +Public Const FI_RGBA_ALPHA As Long = 3 +Public Const FI_RGBA_RED_MASK As Long = &HFF0000 +Public Const FI_RGBA_GREEN_MASK As Long = &HFF00 +Public Const FI_RGBA_BLUE_MASK As Long = &HFF +Public Const FI_RGBA_ALPHA_MASK As Long = &HFF000000 +Public Const FI_RGBA_RED_SHIFT As Long = 16 +Public Const FI_RGBA_GREEN_SHIFT As Long = 8 +Public Const FI_RGBA_BLUE_SHIFT As Long = 0 +Public Const FI_RGBA_ALPHA_SHIFT As Long = 24 + +' The 16 bit macros only include masks and shifts, since each color element is not byte aligned +Public Const FI16_555_RED_MASK As Long = &H7C00 +Public Const FI16_555_GREEN_MASK As Long = &H3E0 +Public Const FI16_555_BLUE_MASK As Long = &H1F +Public Const FI16_555_RED_SHIFT As Long = 10 +Public Const FI16_555_GREEN_SHIFT As Long = 5 +Public Const FI16_555_BLUE_SHIFT As Long = 0 +Public Const FI16_565_RED_MASK As Long = &HF800 +Public Const FI16_565_GREEN_MASK As Long = &H7E0 +Public Const FI16_565_BLUE_MASK As Long = &H1F +Public Const FI16_565_RED_SHIFT As Long = 11 +Public Const FI16_565_GREEN_SHIFT As Long = 5 +Public Const FI16_565_BLUE_SHIFT As Long = 0 + +' ICC profile support +Public Const FIICC_DEFAULT As Long = &H0 +Public Const FIICC_COLOR_IS_CMYK As Long = &H1 + +Private Const FREE_IMAGE_ICC_COLOR_MODEL_MASK As Long = &H1 +Public Enum FREE_IMAGE_ICC_COLOR_MODEL + FIICC_COLOR_MODEL_RGB = &H0 + FIICC_COLOR_MODEL_CMYK = &H1 +End Enum + +' Load / Save flag constants +Public Const FIF_LOAD_NOPIXELS = &H8000 ' load the image header only (not supported by all plugins) + +Public Const BMP_DEFAULT As Long = 0 +Public Const BMP_SAVE_RLE As Long = 1 +Public Const CUT_DEFAULT As Long = 0 +Public Const DDS_DEFAULT As Long = 0 +Public Const EXR_DEFAULT As Long = 0 ' save data as half with piz-based wavelet compression +Public Const EXR_FLOAT As Long = &H1 ' save data as float instead of as half (not recommended) +Public Const EXR_NONE As Long = &H2 ' save with no compression +Public Const EXR_ZIP As Long = &H4 ' save with zlib compression, in blocks of 16 scan lines +Public Const EXR_PIZ As Long = &H8 ' save with piz-based wavelet compression +Public Const EXR_PXR24 As Long = &H10 ' save with lossy 24-bit float compression +Public Const EXR_B44 As Long = &H20 ' save with lossy 44% float compression - goes to 22% when combined with EXR_LC +Public Const EXR_LC As Long = &H40 ' save images with one luminance and two chroma channels, rather than as RGB (lossy compression) +Public Const FAXG3_DEFAULT As Long = 0 +Public Const GIF_DEFAULT As Long = 0 +Public Const GIF_LOAD256 As Long = 1 ' Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color +Public Const GIF_PLAYBACK As Long = 2 ''Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading +Public Const HDR_DEFAULT As Long = 0 +Public Const ICO_DEFAULT As Long = 0 +Public Const ICO_MAKEALPHA As Long = 1 ' convert to 32bpp and create an alpha channel from the AND-mask when loading +Public Const IFF_DEFAULT As Long = 0 +Public Const J2K_DEFAULT As Long = 0 ' save with a 16:1 rate +Public Const JP2_DEFAULT As Long = 0 ' save with a 16:1 rate +Public Const JPEG_DEFAULT As Long = 0 ' loading (see JPEG_FAST); saving (see JPEG_QUALITYGOOD|JPEG_SUBSAMPLING_420) +Public Const JPEG_FAST As Long = &H1 ' load the file as fast as possible, sacrificing some quality +Public Const JPEG_ACCURATE As Long = &H2 ' load the file with the best quality, sacrificing some speed +Public Const JPEG_CMYK As Long = &H4 ' load separated CMYK "as is" (use 'OR' to combine with other flags) +Public Const JPEG_EXIFROTATE As Long = &H8 ' load and rotate according to Exif 'Orientation' tag if available +Public Const JPEG_GREYSCALE As Long = &H10 ' load and convert to a 8-bit greyscale image +Public Const JPEG_QUALITYSUPERB As Long = &H80 ' save with superb quality (100:1) +Public Const JPEG_QUALITYGOOD As Long = &H100 ' save with good quality (75:1) +Public Const JPEG_QUALITYNORMAL As Long = &H200 ' save with normal quality (50:1) +Public Const JPEG_QUALITYAVERAGE As Long = &H400 ' save with average quality (25:1) +Public Const JPEG_QUALITYBAD As Long = &H800 ' save with bad quality (10:1) +Public Const JPEG_PROGRESSIVE As Long = &H2000 ' save as a progressive-JPEG (use 'OR' to combine with other save flags) +Public Const JPEG_SUBSAMPLING_411 As Long = &H1000 ' save with high 4x1 chroma subsampling (4:1:1) +Public Const JPEG_SUBSAMPLING_420 As Long = &H4000 ' save with medium 2x2 medium chroma subsampling (4:2:0) - default value +Public Const JPEG_SUBSAMPLING_422 As Long = &H8000 ' save with low 2x1 chroma subsampling (4:2:2) +Public Const JPEG_SUBSAMPLING_444 As Long = &H10000 ' save with no chroma subsampling (4:4:4) +Public Const JPEG_OPTIMIZE As Long = &H20000 ' on saving, compute optimal Huffman coding tables (can reduce a few percent of file size) +Public Const JPEG_BASELINE As Long = &H40000 ' save basic JPEG, without metadata or any markers +Public Const KOALA_DEFAULT As Long = 0 +Public Const LBM_DEFAULT As Long = 0 +Public Const MNG_DEFAULT As Long = 0 +Public Const PCD_DEFAULT As Long = 0 +Public Const PCD_BASE As Long = 1 ' load the bitmap sized 768 x 512 +Public Const PCD_BASEDIV4 As Long = 2 ' load the bitmap sized 384 x 256 +Public Const PCD_BASEDIV16 As Long = 3 ' load the bitmap sized 192 x 128 +Public Const PCX_DEFAULT As Long = 0 +Public Const PFM_DEFAULT As Long = 0 +Public Const PICT_DEFAULT As Long = 0 +Public Const PNG_DEFAULT As Long = 0 +Public Const PNG_IGNOREGAMMA As Long = 1 ' avoid gamma correction +Public Const PNG_Z_BEST_SPEED As Long = &H1 ' save using ZLib level 1 compression flag (default value is 6) +Public Const PNG_Z_DEFAULT_COMPRESSION As Long = &H6 ' save using ZLib level 6 compression flag (default recommended value) +Public Const PNG_Z_BEST_COMPRESSION As Long = &H9 ' save using ZLib level 9 compression flag (default value is 6) +Public Const PNG_Z_NO_COMPRESSION As Long = &H100 ' save without ZLib compression +Public Const PNG_INTERLACED As Long = &H200 ' save using Adam7 interlacing (use | to combine with other save flags) +Public Const PNM_DEFAULT As Long = 0 +Public Const PNM_SAVE_RAW As Long = 0 ' if set, the writer saves in RAW format (i.e. P4, P5 or P6) +Public Const PNM_SAVE_ASCII As Long = 1 ' if set, the writer saves in ASCII format (i.e. P1, P2 or P3) +Public Const PSD_DEFAULT As Long = 0 +Public Const PSD_CMYK As Long = 1 ' reads tags for separated CMYK (default is conversion to RGB) +Public Const PSD_LAB As Long = 2 ' reads tags for CIELab (default is conversion to RGB) +Public Const RAS_DEFAULT As Long = 0 +Public Const RAW_DEFAULT As Long = 0 ' load the file as linear RGB 48-bit +Public Const RAW_PREVIEW As Long = 1 ' try to load the embedded JPEG preview with included Exif Data or default to RGB 24-bit +Public Const RAW_DISPLAY As Long = 2 ' load the file as RGB 24-bit +Public Const RAW_HALFSIZE As Long = 4 ' load the file as half-size color image +Public Const SGI_DEFAULT As Long = 0 +Public Const TARGA_DEFAULT As Long = 0 +Public Const TARGA_LOAD_RGB888 As Long = 1 ' if set, the loader converts RGB555 and ARGB8888 -> RGB888 +Public Const TARGA_SAVE_RLE As Long = 2 ' if set, the writer saves with RLE compression +Public Const TIFF_DEFAULT As Long = 0 +Public Const TIFF_CMYK As Long = &H1 ' reads/stores tags for separated CMYK (use 'OR' to combine with compression flags) +Public Const TIFF_PACKBITS As Long = &H100 ' save using PACKBITS compression +Public Const TIFF_DEFLATE As Long = &H200 ' save using DEFLATE compression (a.k.a. ZLIB compression) +Public Const TIFF_ADOBE_DEFLATE As Long = &H400 ' save using ADOBE DEFLATE compression +Public Const TIFF_NONE As Long = &H800 ' save without any compression +Public Const TIFF_CCITTFAX3 As Long = &H1000 ' save using CCITT Group 3 fax encoding +Public Const TIFF_CCITTFAX4 As Long = &H2000 ' save using CCITT Group 4 fax encoding +Public Const TIFF_LZW As Long = &H4000 ' save using LZW compression +Public Const TIFF_JPEG As Long = &H8000 ' save using JPEG compression +Public Const TIFF_LOGLUV As Long = &H10000 ' save using LogLuv compression +Public Const WBMP_DEFAULT As Long = 0 +Public Const XBM_DEFAULT As Long = 0 +Public Const XPM_DEFAULT As Long = 0 + +Public Enum FREE_IMAGE_FORMAT + FIF_UNKNOWN = -1 + FIF_BMP = 0 + FIF_ICO = 1 + FIF_JPEG = 2 + FIF_JNG = 3 + FIF_KOALA = 4 + FIF_LBM = 5 + FIF_IFF = FIF_LBM + FIF_MNG = 6 + FIF_PBM = 7 + FIF_PBMRAW = 8 + FIF_PCD = 9 + FIF_PCX = 10 + FIF_PGM = 11 + FIF_PGMRAW = 12 + FIF_PNG = 13 + FIF_PPM = 14 + FIF_PPMRAW = 15 + FIF_RAS = 16 + FIF_TARGA = 17 + FIF_TIFF = 18 + FIF_WBMP = 19 + FIF_PSD = 20 + FIF_CUT = 21 + FIF_XBM = 22 + FIF_XPM = 23 + FIF_DDS = 24 + FIF_GIF = 25 + FIF_HDR = 26 + FIF_FAXG3 = 27 + FIF_SGI = 28 + FIF_EXR = 29 + FIF_J2K = 30 + FIF_JP2 = 31 + FIF_PFM = 32 + FIF_PICT = 33 + FIF_RAW = 34 +End Enum +#If False Then + Const FIF_UNKNOWN = -1 + Const FIF_BMP = 0 + Const FIF_ICO = 1 + Const FIF_JPEG = 2 + Const FIF_JNG = 3 + Const FIF_KOALA = 4 + Const FIF_LBM = 5 + Const FIF_IFF = FIF_LBM + Const FIF_MNG = 6 + Const FIF_PBM = 7 + Const FIF_PBMRAW = 8 + Const FIF_PCD = 9 + Const FIF_PCX = 10 + Const FIF_PGM = 11 + Const FIF_PGMRAW = 12 + Const FIF_PNG = 13 + Const FIF_PPM = 14 + Const FIF_PPMRAW = 15 + Const FIF_RAS = 16 + Const FIF_TARGA = 17 + Const FIF_TIFF = 18 + Const FIF_WBMP = 19 + Const FIF_PSD = 20 + Const FIF_CUT = 21 + Const FIF_XBM = 22 + Const FIF_XPM = 23 + Const FIF_DDS = 24 + Const FIF_GIF = 25 + Const FIF_HDR = 26 + Const FIF_FAXG3 = 27 + Const FIF_SGI = 28 + Const FIF_EXR = 29 + Const FIF_J2K = 30 + Const FIF_JP2 = 31 + Const FIF_PFM = 32 + Const FIF_PICT = 33 + Const FIF_RAW = 34 +#End If + +Public Enum FREE_IMAGE_LOAD_OPTIONS + FILO_LOAD_NOPIXELS = &H8000 ' load the image header only (not supported by all plugins) + FILO_LOAD_DEFAULT = 0 + FILO_GIF_DEFAULT = GIF_DEFAULT + FILO_GIF_LOAD256 = GIF_LOAD256 ' load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color + FILO_GIF_PLAYBACK = GIF_PLAYBACK ' 'play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading + FILO_ICO_DEFAULT = ICO_DEFAULT + FILO_ICO_MAKEALPHA = ICO_MAKEALPHA ' convert to 32bpp and create an alpha channel from the AND-mask when loading + FILO_JPEG_DEFAULT = JPEG_DEFAULT ' for loading this is a synonym for FILO_JPEG_FAST + FILO_JPEG_FAST = JPEG_FAST ' load the file as fast as possible, sacrificing some quality + FILO_JPEG_ACCURATE = JPEG_ACCURATE ' load the file with the best quality, sacrificing some speed + FILO_JPEG_CMYK = JPEG_CMYK ' load separated CMYK "as is" (use 'OR' to combine with other load flags) + FILO_JPEG_EXIFROTATE = JPEG_EXIFROTATE ' load and rotate according to Exif 'Orientation' tag if available + FILO_JPEG_GREYSCALE = JPEG_GREYSCALE ' load and convert to a 8-bit greyscale image + FILO_PCD_DEFAULT = PCD_DEFAULT + FILO_PCD_BASE = PCD_BASE ' load the bitmap sized 768 x 512 + FILO_PCD_BASEDIV4 = PCD_BASEDIV4 ' load the bitmap sized 384 x 256 + FILO_PCD_BASEDIV16 = PCD_BASEDIV16 ' load the bitmap sized 192 x 128 + FILO_PNG_DEFAULT = PNG_DEFAULT + FILO_PNG_IGNOREGAMMA = PNG_IGNOREGAMMA ' avoid gamma correction + FILO_PSD_CMYK = PSD_CMYK ' reads tags for separated CMYK (default is conversion to RGB) + FILO_PSD_LAB = PSD_LAB ' reads tags for CIELab (default is conversion to RGB) + FILO_RAW_DEFAULT = RAW_DEFAULT ' load the file as linear RGB 48-bit + FILO_RAW_PREVIEW = RAW_PREVIEW ' try to load the embedded JPEG preview with included Exif Data or default to RGB 24-bit + FILO_RAW_DISPLAY = RAW_DISPLAY ' load the file as RGB 24-bit + FILO_RAW_HALFSIZE = RAW_HALFSIZE ' load the file as half-size color image + FILO_TARGA_DEFAULT = TARGA_LOAD_RGB888 + FILO_TARGA_LOAD_RGB888 = TARGA_LOAD_RGB888 ' if set, the loader converts RGB555 and ARGB8888 -> RGB888 + FISO_TIFF_DEFAULT = TIFF_DEFAULT + FISO_TIFF_CMYK = TIFF_CMYK ' reads tags for separated CMYK +End Enum +#If False Then + Const FILO_LOAD_NOPIXELS = &H8000 + Const FILO_LOAD_DEFAULT = 0 + Const FILO_GIF_DEFAULT = GIF_DEFAULT + Const FILO_GIF_LOAD256 = GIF_LOAD256 + Const FILO_GIF_PLAYBACK = GIF_PLAYBACK + Const FILO_ICO_DEFAULT = ICO_DEFAULT + Const FILO_ICO_MAKEALPHA = ICO_MAKEALPHA + Const FILO_JPEG_DEFAULT = JPEG_DEFAULT + Const FILO_JPEG_FAST = JPEG_FAST + Const FILO_JPEG_ACCURATE = JPEG_ACCURATE + Const FILO_JPEG_CMYK = JPEG_CMYK + Const FILO_JPEG_EXIFROTATE = JPEG_EXIFROTATE + Const FILO_PCD_DEFAULT = PCD_DEFAULT + Const FILO_PCD_BASE = PCD_BASE + Const FILO_PCD_BASEDIV4 = PCD_BASEDIV4 + Const FILO_PCD_BASEDIV16 = PCD_BASEDIV16 + Const FILO_PNG_DEFAULT = PNG_DEFAULT + Const FILO_PNG_IGNOREGAMMA = PNG_IGNOREGAMMA + Const FILO_TARGA_DEFAULT = TARGA_LOAD_RGB888 + Const FILO_TARGA_LOAD_RGB888 = TARGA_LOAD_RGB888 + Const FISO_TIFF_DEFAULT = TIFF_DEFAULT + Const FISO_TIFF_CMYK = TIFF_CMYK +#End If + +Public Enum FREE_IMAGE_SAVE_OPTIONS + FISO_SAVE_DEFAULT = 0 + FISO_BMP_DEFAULT = BMP_DEFAULT + FISO_BMP_SAVE_RLE = BMP_SAVE_RLE + FISO_EXR_DEFAULT = EXR_DEFAULT ' save data as half with piz-based wavelet compression + FISO_EXR_FLOAT = EXR_FLOAT ' save data as float instead of as half (not recommended) + FISO_EXR_NONE = EXR_NONE ' save with no compression + FISO_EXR_ZIP = EXR_ZIP ' save with zlib compression, in blocks of 16 scan lines + FISO_EXR_PIZ = EXR_PIZ ' save with piz-based wavelet compression + FISO_EXR_PXR24 = EXR_PXR24 ' save with lossy 24-bit float compression + FISO_EXR_B44 = EXR_B44 ' save with lossy 44% float compression - goes to 22% when combined with EXR_LC + FISO_EXR_LC = EXR_LC ' save images with one luminance and two chroma channels, rather than as RGB (lossy compression) + FISO_JPEG_DEFAULT = JPEG_DEFAULT ' for saving this is a synonym for FISO_JPEG_QUALITYGOOD + FISO_JPEG_QUALITYSUPERB = JPEG_QUALITYSUPERB ' save with superb quality (100:1) + FISO_JPEG_QUALITYGOOD = JPEG_QUALITYGOOD ' save with good quality (75:1) + FISO_JPEG_QUALITYNORMAL = JPEG_QUALITYNORMAL ' save with normal quality (50:1) + FISO_JPEG_QUALITYAVERAGE = JPEG_QUALITYAVERAGE ' save with average quality (25:1) + FISO_JPEG_QUALITYBAD = JPEG_QUALITYBAD ' save with bad quality (10:1) + FISO_JPEG_PROGRESSIVE = JPEG_PROGRESSIVE ' save as a progressive-JPEG (use 'OR' to combine with other save flags) + FISO_JPEG_SUBSAMPLING_411 = JPEG_SUBSAMPLING_411 ' save with high 4x1 chroma subsampling (4:1:1) + FISO_JPEG_SUBSAMPLING_420 = JPEG_SUBSAMPLING_420 ' save with medium 2x2 medium chroma subsampling (4:2:0) - default value + FISO_JPEG_SUBSAMPLING_422 = JPEG_SUBSAMPLING_422 ' save with low 2x1 chroma subsampling (4:2:2) + FISO_JPEG_SUBSAMPLING_444 = JPEG_SUBSAMPLING_444 ' save with no chroma subsampling (4:4:4) + FISO_JPEG_OPTIMIZE = JPEG_OPTIMIZE ' compute optimal Huffman coding tables (can reduce a few percent of file size) + FISO_JPEG_BASELINE = JPEG_BASELINE ' save basic JPEG, without metadata or any markers + FISO_PNG_Z_BEST_SPEED = PNG_Z_BEST_SPEED ' save using ZLib level 1 compression flag (default value is 6) + FISO_PNG_Z_DEFAULT_COMPRESSION = PNG_Z_DEFAULT_COMPRESSION ' save using ZLib level 6 compression flag (default recommended value) + FISO_PNG_Z_BEST_COMPRESSION = PNG_Z_BEST_COMPRESSION ' save using ZLib level 9 compression flag (default value is 6) + FISO_PNG_Z_NO_COMPRESSION = PNG_Z_NO_COMPRESSION ' save without ZLib compression + FISO_PNG_INTERLACED = PNG_INTERLACED ' save using Adam7 interlacing (use | to combine with other save flags) + FISO_PNM_DEFAULT = PNM_DEFAULT + FISO_PNM_SAVE_RAW = PNM_SAVE_RAW ' if set, the writer saves in RAW format (i.e. P4, P5 or P6) + FISO_PNM_SAVE_ASCII = PNM_SAVE_ASCII ' if set, the writer saves in ASCII format (i.e. P1, P2 or P3) + FISO_TARGA_SAVE_RLE = TARGA_SAVE_RLE ' if set, the writer saves with RLE compression + FISO_TIFF_DEFAULT = TIFF_DEFAULT + FISO_TIFF_CMYK = TIFF_CMYK ' stores tags for separated CMYK (use 'OR' to combine with compression flags) + FISO_TIFF_PACKBITS = TIFF_PACKBITS ' save using PACKBITS compression + FISO_TIFF_DEFLATE = TIFF_DEFLATE ' save using DEFLATE compression (a.k.a. ZLIB compression) + FISO_TIFF_ADOBE_DEFLATE = TIFF_ADOBE_DEFLATE ' save using ADOBE DEFLATE compression + FISO_TIFF_NONE = TIFF_NONE ' save without any compression + FISO_TIFF_CCITTFAX3 = TIFF_CCITTFAX3 ' save using CCITT Group 3 fax encoding + FISO_TIFF_CCITTFAX4 = TIFF_CCITTFAX4 ' save using CCITT Group 4 fax encoding + FISO_TIFF_LZW = TIFF_LZW ' save using LZW compression + FISO_TIFF_JPEG = TIFF_JPEG ' save using JPEG compression + FISO_TIFF_LOGLUV = TIFF_LOGLUV ' save using LogLuv compression +End Enum +#If False Then + Const FISO_SAVE_DEFAULT = 0 + Const FISO_BMP_DEFAULT = BMP_DEFAULT + Const FISO_BMP_SAVE_RLE = BMP_SAVE_RLE + Const FISO_JPEG_DEFAULT = JPEG_DEFAULT + Const FISO_JPEG_QUALITYSUPERB = JPEG_QUALITYSUPERB + Const FISO_JPEG_QUALITYGOOD = JPEG_QUALITYGOOD + Const FISO_JPEG_QUALITYNORMAL = JPEG_QUALITYNORMAL + Const FISO_JPEG_QUALITYAVERAGE = JPEG_QUALITYAVERAGE + Const FISO_JPEG_QUALITYBAD = JPEG_QUALITYBAD + Const FISO_JPEG_PROGRESSIVE = JPEG_PROGRESSIVE + Const FISO_JPEG_SUBSAMPLING_411 = JPEG_SUBSAMPLING_411 + Const FISO_JPEG_SUBSAMPLING_420 = JPEG_SUBSAMPLING_420 + Const FISO_JPEG_SUBSAMPLING_422 = JPEG_SUBSAMPLING_422 + Const FISO_JPEG_SUBSAMPLING_444 = JPEG_SUBSAMPLING_444 + Const FISO_PNM_DEFAULT = PNM_DEFAULT + Const FISO_PNM_SAVE_RAW = PNM_SAVE_RAW + Const FISO_PNM_SAVE_ASCII = PNM_SAVE_ASCII + Const FISO_TARGA_SAVE_RLE = TARGA_SAVE_RLE + Const FISO_TIFF_DEFAULT = TIFF_DEFAULT + Const FISO_TIFF_CMYK = TIFF_CMYK + Const FISO_TIFF_PACKBITS = TIFF_PACKBITS + Const FISO_TIFF_DEFLATE = TIFF_DEFLATE + Const FISO_TIFF_ADOBE_DEFLATE = TIFF_ADOBE_DEFLATE + Const FISO_TIFF_NONE = TIFF_NONE + Const FISO_TIFF_CCITTFAX3 = TIFF_CCITTFAX3 + Const FISO_TIFF_CCITTFAX4 = TIFF_CCITTFAX4 + Const FISO_TIFF_LZW = TIFF_LZW + Const FISO_TIFF_JPEG = TIFF_JPEG +#End If + +Public Enum FREE_IMAGE_TYPE + FIT_UNKNOWN = 0 ' unknown type + FIT_BITMAP = 1 ' standard image : 1-, 4-, 8-, 16-, 24-, 32-bit + FIT_UINT16 = 2 ' array of unsigned short : unsigned 16-bit + FIT_INT16 = 3 ' array of short : signed 16-bit + FIT_UINT32 = 4 ' array of unsigned long : unsigned 32-bit + FIT_INT32 = 5 ' array of long : signed 32-bit + FIT_FLOAT = 6 ' array of float : 32-bit IEEE floating point + FIT_DOUBLE = 7 ' array of double : 64-bit IEEE floating point + FIT_COMPLEX = 8 ' array of FICOMPLEX : 2 x 64-bit IEEE floating point + FIT_RGB16 = 9 ' 48-bit RGB image : 3 x 16-bit + FIT_RGBA16 = 10 ' 64-bit RGBA image : 4 x 16-bit + FIT_RGBF = 11 ' 96-bit RGB float image : 3 x 32-bit IEEE floating point + FIT_RGBAF = 12 ' 128-bit RGBA float image : 4 x 32-bit IEEE floating point +End Enum +#If False Then + Const FIT_UNKNOWN = 0 + Const FIT_BITMAP = 1 + Const FIT_UINT16 = 2 + Const FIT_INT16 = 3 + Const FIT_UINT32 = 4 + Const FIT_INT32 = 5 + Const FIT_FLOAT = 6 + Const FIT_DOUBLE = 7 + Const FIT_COMPLEX = 8 + Const FIT_RGB16 = 9 + Const FIT_RGBA16 = 10 + Const FIT_RGBF = 11 + Const FIT_RGBAF = 12 +#End If + +Public Enum FREE_IMAGE_COLOR_TYPE + FIC_MINISWHITE = 0 ' min value is white + FIC_MINISBLACK = 1 ' min value is black + FIC_RGB = 2 ' RGB color model + FIC_PALETTE = 3 ' color map indexed + FIC_RGBALPHA = 4 ' RGB color model with alpha channel + FIC_CMYK = 5 ' CMYK color model +End Enum +#If False Then + Const FIC_MINISWHITE = 0 + Const FIC_MINISBLACK = 1 + Const FIC_RGB = 2 + Const FIC_PALETTE = 3 + Const FIC_RGBALPHA = 4 + Const FIC_CMYK = 5 +#End If + +Public Enum FREE_IMAGE_QUANTIZE + FIQ_WUQUANT = 0 ' Xiaolin Wu color quantization algorithm + FIQ_NNQUANT = 1 ' NeuQuant neural-net quantization algorithm by Anthony Dekker +End Enum +#If False Then + Const FIQ_WUQUANT = 0 + Const FIQ_NNQUANT = 1 +#End If + +Public Enum FREE_IMAGE_DITHER + FID_FS = 0 ' Floyd & Steinberg error diffusion + FID_BAYER4x4 = 1 ' Bayer ordered dispersed dot dithering (order 2 dithering matrix) + FID_BAYER8x8 = 2 ' Bayer ordered dispersed dot dithering (order 3 dithering matrix) + FID_CLUSTER6x6 = 3 ' Ordered clustered dot dithering (order 3 - 6x6 matrix) + FID_CLUSTER8x8 = 4 ' Ordered clustered dot dithering (order 4 - 8x8 matrix) + FID_CLUSTER16x16 = 5 ' Ordered clustered dot dithering (order 8 - 16x16 matrix) + FID_BAYER16x16 = 6 ' Bayer ordered dispersed dot dithering (order 4 dithering matrix) +End Enum +#If False Then + Const FID_FS = 0 + Const FID_BAYER4x4 = 1 + Const FID_BAYER8x8 = 2 + Const FID_CLUSTER6x6 = 3 + Const FID_CLUSTER8x8 = 4 + Const FID_CLUSTER16x16 = 5 + Const FID_BAYER16x16 = 6 +#End If + +Public Enum FREE_IMAGE_JPEG_OPERATION + FIJPEG_OP_NONE = 0 ' no transformation + FIJPEG_OP_FLIP_H = 1 ' horizontal flip + FIJPEG_OP_FLIP_V = 2 ' vertical flip + FIJPEG_OP_TRANSPOSE = 3 ' transpose across UL-to-LR axis + FIJPEG_OP_TRANSVERSE = 4 ' transpose across UR-to-LL axis + FIJPEG_OP_ROTATE_90 = 5 ' 90-degree clockwise rotation + FIJPEG_OP_ROTATE_180 = 6 ' 180-degree rotation + FIJPEG_OP_ROTATE_270 = 7 ' 270-degree clockwise (or 90 ccw) +End Enum +#If False Then + Const FIJPEG_OP_NONE = 0 + Const FIJPEG_OP_FLIP_H = 1 + Const FIJPEG_OP_FLIP_V = 2 + Const FIJPEG_OP_TRANSPOSE = 3 + Const FIJPEG_OP_TRANSVERSE = 4 + Const FIJPEG_OP_ROTATE_90 = 5 + Const FIJPEG_OP_ROTATE_180 = 6 + Const FIJPEG_OP_ROTATE_270 = 7 +#End If + +Public Enum FREE_IMAGE_TMO + FITMO_DRAGO03 = 0 ' Adaptive logarithmic mapping (F. Drago, 2003) + FITMO_REINHARD05 = 1 ' Dynamic range reduction inspired by photoreceptor physiology (E. Reinhard, 2005) + FITMO_FATTAL02 = 2 ' Gradient domain high dynamic range compression (R. Fattal, 2002) +End Enum +#If False Then + Const FITMO_DRAGO03 = 0 + Const FITMO_REINHARD05 = 1 + Const FITMO_FATTAL02 = 2 +#End If + +Public Enum FREE_IMAGE_FILTER + FILTER_BOX = 0 ' Box, pulse, Fourier window, 1st order (constant) b-spline + FILTER_BICUBIC = 1 ' Mitchell & Netravali's two-param cubic filter + FILTER_BILINEAR = 2 ' Bilinear filter + FILTER_BSPLINE = 3 ' 4th order (cubic) b-spline + FILTER_CATMULLROM = 4 ' Catmull-Rom spline, Overhauser spline + FILTER_LANCZOS3 = 5 ' Lanczos3 filter +End Enum +#If False Then + Const FILTER_BOX = 0 + Const FILTER_BICUBIC = 1 + Const FILTER_BILINEAR = 2 + Const FILTER_BSPLINE = 3 + Const FILTER_CATMULLROM = 4 + Const FILTER_LANCZOS3 = 5 +#End If + +Public Enum FREE_IMAGE_COLOR_CHANNEL + FICC_RGB = 0 ' Use red, green and blue channels + FICC_RED = 1 ' Use red channel + FICC_GREEN = 2 ' Use green channel + FICC_BLUE = 3 ' Use blue channel + FICC_ALPHA = 4 ' Use alpha channel + FICC_BLACK = 5 ' Use black channel + FICC_REAL = 6 ' Complex images: use real part + FICC_IMAG = 7 ' Complex images: use imaginary part + FICC_MAG = 8 ' Complex images: use magnitude + FICC_PHASE = 9 ' Complex images: use phase +End Enum +#If False Then + Const FICC_RGB = 0 + Const FICC_RED = 1 + Const FICC_GREEN = 2 + Const FICC_BLUE = 3 + Const FICC_ALPHA = 4 + Const FICC_BLACK = 5 + Const FICC_REAL = 6 + Const FICC_IMAG = 7 + Const FICC_MAG = 8 + Const FICC_PHASE = 9 +#End If + +Public Enum FREE_IMAGE_MDTYPE + FIDT_NOTYPE = 0 ' placeholder + FIDT_BYTE = 1 ' 8-bit unsigned integer + FIDT_ASCII = 2 ' 8-bit bytes w/ last byte null + FIDT_SHORT = 3 ' 16-bit unsigned integer + FIDT_LONG = 4 ' 32-bit unsigned integer + FIDT_RATIONAL = 5 ' 64-bit unsigned fraction + FIDT_SBYTE = 6 ' 8-bit signed integer + FIDT_UNDEFINED = 7 ' 8-bit untyped data + FIDT_SSHORT = 8 ' 16-bit signed integer + FIDT_SLONG = 9 ' 32-bit signed integer + FIDT_SRATIONAL = 10 ' 64-bit signed fraction + FIDT_FLOAT = 11 ' 32-bit IEEE floating point + FIDT_DOUBLE = 12 ' 64-bit IEEE floating point + FIDT_IFD = 13 ' 32-bit unsigned integer (offset) + FIDT_PALETTE = 14 ' 32-bit RGBQUAD +End Enum +#If False Then + Const FIDT_NOTYPE = 0 + Const FIDT_BYTE = 1 + Const FIDT_ASCII = 2 + Const FIDT_SHORT = 3 + Const FIDT_LONG = 4 + Const FIDT_RATIONAL = 5 + Const FIDT_SBYTE = 6 + Const FIDT_UNDEFINED = 7 + Const FIDT_SSHORT = 8 + Const FIDT_SLONG = 9 + Const FIDT_SRATIONAL = 10 + Const FIDT_FLOAT = 11 + Const FIDT_DOUBLE = 12 + Const FIDT_IFD = 13 + Const FIDT_PALETTE = 14 +#End If + +Public Enum FREE_IMAGE_MDMODEL + FIMD_NODATA = -1 ' + FIMD_COMMENTS = 0 ' single comment or keywords + FIMD_EXIF_MAIN = 1 ' Exif-TIFF metadata + FIMD_EXIF_EXIF = 2 ' Exif-specific metadata + FIMD_EXIF_GPS = 3 ' Exif GPS metadata + FIMD_EXIF_MAKERNOTE = 4 ' Exif maker note metadata + FIMD_EXIF_INTEROP = 5 ' Exif interoperability metadata + FIMD_IPTC = 6 ' IPTC/NAA metadata + FIMD_XMP = 7 ' Abobe XMP metadata + FIMD_GEOTIFF = 8 ' GeoTIFF metadata + FIMD_ANIMATION = 9 ' Animation metadata + FIMD_CUSTOM = 10 ' Used to attach other metadata types to a dib + FIMD_EXIF_RAW = 11 ' Exif metadata as a raw buffer +End Enum +#If False Then + Const FIMD_NODATA = -1 + Const FIMD_COMMENTS = 0 + Const FIMD_EXIF_MAIN = 1 + Const FIMD_EXIF_EXIF = 2 + Const FIMD_EXIF_GPS = 3 + Const FIMD_EXIF_MAKERNOTE = 4 + Const FIMD_EXIF_INTEROP = 5 + Const FIMD_IPTC = 6 + Const FIMD_XMP = 7 + Const FIMD_GEOTIFF = 8 + Const FIMD_ANIMATION = 9 + Const FIMD_CUSTOM = 10 + Const FIMD_EXIF_RAW = 11 +#End If + +' These are the GIF_DISPOSAL metadata constants +Public Enum FREE_IMAGE_FRAME_DISPOSAL_METHODS + FIFD_GIF_DISPOSAL_UNSPECIFIED = 0 + FIFD_GIF_DISPOSAL_LEAVE = 1 + FIFD_GIF_DISPOSAL_BACKGROUND = 2 + FIFD_GIF_DISPOSAL_PREVIOUS = 3 +End Enum + +' Constants used in FreeImage_FillBackground and FreeImage_EnlargeCanvas +Public Enum FREE_IMAGE_COLOR_OPTIONS + FI_COLOR_IS_RGB_COLOR = &H0 ' RGBQUAD color is a RGB color (contains no valid alpha channel) + FI_COLOR_IS_RGBA_COLOR = &H1 ' RGBQUAD color is a RGBA color (contains a valid alpha channel) + FI_COLOR_FIND_EQUAL_COLOR = &H2 ' For palettized images: lookup equal RGB color from palette + FI_COLOR_ALPHA_IS_INDEX = &H4 ' The color's rgbReserved member (alpha) contains the palette index to be used +End Enum +Public Const FI_COLOR_PALETTE_SEARCH_MASK = _ + (FI_COLOR_FIND_EQUAL_COLOR Or FI_COLOR_ALPHA_IS_INDEX) ' Flag to test, if any color lookup is performed + +' the next enums are only used by derived functions of the +' FreeImage 3 VB wrapper +Public Enum FREE_IMAGE_CONVERSION_FLAGS + FICF_MONOCHROME = &H1 + FICF_MONOCHROME_THRESHOLD = FICF_MONOCHROME + FICF_MONOCHROME_DITHER = &H3 + FICF_GREYSCALE_4BPP = &H4 + FICF_PALLETISED_8BPP = &H8 + FICF_GREYSCALE_8BPP = FICF_PALLETISED_8BPP Or FICF_MONOCHROME + FICF_GREYSCALE = FICF_GREYSCALE_8BPP + FICF_RGB_15BPP = &HF + FICF_RGB_16BPP = &H10 + FICF_RGB_24BPP = &H18 + FICF_RGB_32BPP = &H20 + FICF_RGB_ALPHA = FICF_RGB_32BPP + FICF_KEEP_UNORDERED_GREYSCALE_PALETTE = &H0 + FICF_REORDER_GREYSCALE_PALETTE = &H1000 +End Enum +#If False Then + Const FICF_MONOCHROME = &H1 + Const FICF_MONOCHROME_THRESHOLD = FICF_MONOCHROME + Const FICF_MONOCHROME_DITHER = &H3 + Const FICF_GREYSCALE_4BPP = &H4 + Const FICF_PALLETISED_8BPP = &H8 + Const FICF_GREYSCALE_8BPP = FICF_PALLETISED_8BPP Or FICF_MONOCHROME + Const FICF_GREYSCALE = FICF_GREYSCALE_8BPP + Const FICF_RGB_15BPP = &HF + Const FICF_RGB_16BPP = &H10 + Const FICF_RGB_24BPP = &H18 + Const FICF_RGB_32BPP = &H20 + Const FICF_RGB_ALPHA = FICF_RGB_32BPP + Const FICF_KEEP_UNORDERED_GREYSCALE_PALETTE = &H0 + Const FICF_REORDER_GREYSCALE_PALETTE = &H1000 +#End If + +Public Enum FREE_IMAGE_COLOR_DEPTH + FICD_AUTO = &H0 + FICD_MONOCHROME = &H1 + FICD_MONOCHROME_THRESHOLD = FICF_MONOCHROME + FICD_MONOCHROME_DITHER = &H3 + FICD_1BPP = FICD_MONOCHROME + FICD_4BPP = &H4 + FICD_8BPP = &H8 + FICD_15BPP = &HF + FICD_16BPP = &H10 + FICD_24BPP = &H18 + FICD_32BPP = &H20 +End Enum +#If False Then + Const FICD_AUTO = &H0 + Const FICD_MONOCHROME = &H1 + Const FICD_MONOCHROME_THRESHOLD = FICF_MONOCHROME + Const FICD_MONOCHROME_DITHER = &H3 + Const FICD_1BPP = FICD_MONOCHROME + Const FICD_4BPP = &H4 + Const FICD_8BPP = &H8 + Const FICD_15BPP = &HF + Const FICD_16BPP = &H10 + Const FICD_24BPP = &H18 + Const FICD_32BPP = &H20 +#End If + +Public Enum FREE_IMAGE_ADJUST_MODE + AM_STRECH = &H1 + AM_DEFAULT = AM_STRECH + AM_ADJUST_BOTH = AM_STRECH + AM_ADJUST_WIDTH = &H2 + AM_ADJUST_HEIGHT = &H4 + AM_ADJUST_OPTIMAL_SIZE = &H8 +End Enum +#If False Then + Const AM_STRECH = &H1 + Const AM_DEFAULT = AM_STRECH + Const AM_ADJUST_BOTH = AM_STRECH + Const AM_ADJUST_WIDTH = &H2 + Const AM_ADJUST_HEIGHT = &H4 + Const AM_ADJUST_OPTIMAL_SIZE = &H8 +#End If + +Public Enum FREE_IMAGE_MASK_FLAGS + FIMF_MASK_NONE = &H0 + FIMF_MASK_FULL_TRANSPARENCY = &H1 + FIMF_MASK_ALPHA_TRANSPARENCY = &H2 + FIMF_MASK_COLOR_TRANSPARENCY = &H4 + FIMF_MASK_FORCE_TRANSPARENCY = &H8 + FIMF_MASK_INVERSE_MASK = &H10 +End Enum +#If False Then + Const FIMF_MASK_NONE = &H0 + Const FIMF_MASK_FULL_TRANSPARENCY = &H1 + Const FIMF_MASK_ALPHA_TRANSPARENCY = &H2 + Const FIMF_MASK_COLOR_TRANSPARENCY = &H4 + Const FIMF_MASK_FORCE_TRANSPARENCY = &H8 + Const FIMF_MASK_INVERSE_MASK = &H10 +#End If + +Public Enum FREE_IMAGE_COLOR_FORMAT_FLAGS + FICFF_COLOR_RGB = &H1 + FICFF_COLOR_BGR = &H2 + FICFF_COLOR_PALETTE_INDEX = &H4 + + FICFF_COLOR_HAS_ALPHA = &H100 + + FICFF_COLOR_ARGB = FICFF_COLOR_RGB Or FICFF_COLOR_HAS_ALPHA + FICFF_COLOR_ABGR = FICFF_COLOR_BGR Or FICFF_COLOR_HAS_ALPHA + + FICFF_COLOR_FORMAT_ORDER_MASK = FICFF_COLOR_RGB Or FICFF_COLOR_BGR +End Enum +#If False Then + Const FICFF_COLOR_RGB = &H1 + Const FICFF_COLOR_BGR = &H2 + Const FICFF_COLOR_PALETTE_INDEX = &H4 + + Const FICFF_COLOR_HAS_ALPHA = &H100 + + Const FICFF_COLOR_ARGB = FICFF_COLOR_RGB Or FICFF_COLOR_HAS_ALPHA + Const FICFF_COLOR_ABGR = FICFF_COLOR_BGR Or FICFF_COLOR_HAS_ALPHA + + Const FICFF_COLOR_FORMAT_ORDER_MASK = FICFF_COLOR_RGB Or FICFF_COLOR_BGR +#End If + +Public Enum FREE_IMAGE_MASK_CREATION_OPTION_FLAGS + MCOF_CREATE_MASK_IMAGE = &H1 + MCOF_MODIFY_SOURCE_IMAGE = &H2 + MCOF_CREATE_AND_MODIFY = MCOF_CREATE_MASK_IMAGE Or MCOF_MODIFY_SOURCE_IMAGE +End Enum +#If False Then + Const MCOF_CREATE_MASK_IMAGE = &H1 + Const MCOF_MODIFY_SOURCE_IMAGE = &H2 + Const MCOF_CREATE_AND_MODIFY = MCOF_CREATE_MASK_IMAGE Or MCOF_MODIFY_SOURCE_IMAGE +#End If + +Public Enum FREE_IMAGE_TRANSPARENCY_STATE_FLAGS + FITSF_IGNORE_TRANSPARENCY = &H0 + FITSF_NONTRANSPARENT = &H1 + FITSF_TRANSPARENT = &H2 + FITSF_INCLUDE_ALPHA_TRANSPARENCY = &H4 +End Enum +#If False Then + Const FITSF_IGNORE_TRANSPARENCY = &H0 + Const FITSF_NONTRANSPARENT = &H1 + Const FITSF_TRANSPARENT = &H2 + Const FITSF_INCLUDE_ALPHA_TRANSPARENCY = &H4 +#End If + +Public Enum FREE_IMAGE_ICON_TRANSPARENCY_OPTION_FLAGS + ITOF_NO_TRANSPARENCY = &H0 + ITOF_USE_TRANSPARENCY_INFO = &H1 + ITOF_USE_TRANSPARENCY_INFO_ONLY = ITOF_USE_TRANSPARENCY_INFO + ITOF_USE_COLOR_TRANSPARENCY = &H2 + ITOF_USE_COLOR_TRANSPARENCY_ONLY = ITOF_USE_COLOR_TRANSPARENCY + ITOF_USE_TRANSPARENCY_INFO_OR_COLOR = ITOF_USE_TRANSPARENCY_INFO Or ITOF_USE_COLOR_TRANSPARENCY + ITOF_USE_DEFAULT_TRANSPARENCY = ITOF_USE_TRANSPARENCY_INFO_OR_COLOR + ITOF_USE_COLOR_TOP_LEFT_PIXEL = &H0 + ITOF_USE_COLOR_FIRST_PIXEL = ITOF_USE_COLOR_TOP_LEFT_PIXEL + ITOF_USE_COLOR_TOP_RIGHT_PIXEL = &H20 + ITOF_USE_COLOR_BOTTOM_LEFT_PIXEL = &H40 + ITOF_USE_COLOR_BOTTOM_RIGHT_PIXEL = &H80 + ITOF_USE_COLOR_SPECIFIED = &H100 + ITOF_FORCE_TRANSPARENCY_INFO = &H400 +End Enum +#If False Then + Const ITOF_NO_TRANSPARENCY = &H0 + Const ITOF_USE_TRANSPARENCY_INFO = &H1 + Const ITOF_USE_TRANSPARENCY_INFO_ONLY = ITOF_USE_TRANSPARENCY_INFO + Const ITOF_USE_COLOR_TRANSPARENCY = &H2 + Const ITOF_USE_COLOR_TRANSPARENCY_ONLY = ITOF_USE_COLOR_TRANSPARENCY + Const ITOF_USE_TRANSPARENCY_INFO_OR_COLOR = ITOF_USE_TRANSPARENCY_INFO Or ITOF_USE_COLOR_TRANSPARENCY + Const ITOF_USE_DEFAULT_TRANSPARENCY = ITOF_USE_TRANSPARENCY_INFO_OR_COLOR + Const ITOF_USE_COLOR_TOP_LEFT_PIXEL = &H0 + Const ITOF_USE_COLOR_FIRST_PIXEL = ITOF_USE_COLOR_TOP_LEFT_PIXEL + Const ITOF_USE_COLOR_TOP_RIGHT_PIXEL = &H20 + Const ITOF_USE_COLOR_BOTTOM_LEFT_PIXEL = &H40 + Const ITOF_USE_COLOR_BOTTOM_RIGHT_PIXEL = &H80 + Const ITOF_USE_COLOR_SPECIFIED = &H100 + Const ITOF_FORCE_TRANSPARENCY_INFO = &H400 +#End If + +Private Const ITOF_USE_COLOR_BITMASK As Long = ITOF_USE_COLOR_TOP_RIGHT_PIXEL Or _ + ITOF_USE_COLOR_BOTTOM_LEFT_PIXEL Or _ + ITOF_USE_COLOR_BOTTOM_RIGHT_PIXEL Or _ + ITOF_USE_COLOR_SPECIFIED + + +Public Type RGBQUAD + rgbBlue As Byte + rgbGreen As Byte + rgbRed As Byte + rgbReserved As Byte +End Type + +Public Type RGBTRIPLE + rgbtBlue As Byte + rgbtGreen As Byte + rgbtRed As Byte +End Type + +Public Type BITMAPINFOHEADER + biSize As Long + biWidth As Long + biHeight As Long + biPlanes As Integer + biBitCount As Integer + biCompression As Long + biSizeImage As Long + biXPelsPerMeter As Long + biYPelsPerMeter As Long + biClrUsed As Long + biClrImportant As Long + red As Long + green As Long + blue As Long +End Type + +Public Type BITMAPINFO + bmiHeader As BITMAPINFOHEADER + bmiColors(0) As RGBQUAD +End Type + +Public Const BI_RGB As Long = 0 +Public Const BI_RLE8 As Long = 1 +Public Const BI_RLE4 As Long = 2 +Public Const BI_BITFIELDS As Long = 3 +Public Const BI_JPEG As Long = 4 +Public Const BI_PNG As Long = 5 + +Public Type FIICCPROFILE + Flags As Integer + Size As Long + Data As Long +End Type + +Public Type FIRGB16 + red As Integer + green As Integer + blue As Integer +End Type + +Public Type FIRGBA16 + red As Integer + green As Integer + blue As Integer + Alpha As Integer +End Type + +Public Type FIRGBF + red As Single + green As Single + blue As Single +End Type + +Public Type FIRGBAF + red As Single + green As Single + blue As Single + Alpha As Single +End Type + +Public Type FICOMPLEX + r As Double ' real part + i As Double ' imaginary part +End Type + +Public Type FITAG + Key As Long + Description As Long + Id As Integer + Type As Integer + Count As Long + Length As Long + Value As Long +End Type + +Public Type FIRATIONAL + Numerator As Variant + Denominator As Variant +End Type + +Public Type FREE_IMAGE_TAG + Model As FREE_IMAGE_MDMODEL + TagPtr As Long + Key As String + Description As String + Id As Long + Type As FREE_IMAGE_MDTYPE + Count As Long + Length As Long + StringValue As String + Palette() As RGBQUAD + RationalValue() As FIRATIONAL + Value As Variant +End Type + +Public Type FreeImageIO + read_proc As Long + write_proc As Long + seek_proc As Long + tell_proc As Long +End Type + +Public Type Plugin + format_proc As Long + description_proc As Long + extension_proc As Long + regexpr_proc As Long + open_proc As Long + close_proc As Long + pagecount_proc As Long + pagecapability_proc As Long + load_proc As Long + save_proc As Long + validate_proc As Long + mime_proc As Long + supports_export_bpp_proc As Long + supports_export_type_proc As Long + supports_icc_profiles_proc As Long +End Type + +' the next structures are only used by derived functions of the +' FreeImage 3 VB wrapper +Public Type ScanLineRGBTRIBLE + Data() As RGBTRIPLE +End Type + +Public Type ScanLinesRGBTRIBLE + Scanline() As ScanLineRGBTRIBLE +End Type + +'-------------------------------------------------------------------------------- +' FreeImage 3 function declarations +'-------------------------------------------------------------------------------- + +' The FreeImage 3 functions are declared in the same order as they are described +' in the FreeImage 3 API documentation. The documentation's outline is included +' as comments. + +'-------------------------------------------------------------------------------- +' Bitmap functions +'-------------------------------------------------------------------------------- + +' General functions +Public Declare Sub FreeImage_Initialise Lib "FreeImage.dll" Alias "_FreeImage_Initialise@4" ( _ + Optional ByVal LoadLocalPluginsOnly As Long) + +Public Declare Sub FreeImage_DeInitialise Lib "FreeImage.dll" Alias "_FreeImage_DeInitialise@0" () + +Private Declare Function FreeImage_GetVersionInt Lib "FreeImage.dll" Alias "_FreeImage_GetVersion@0" () As Long + +Private Declare Function FreeImage_GetCopyrightMessageInt Lib "FreeImage.dll" Alias "_FreeImage_GetCopyrightMessage@0" () As Long + +Public Declare Sub FreeImage_SetOutputMessage Lib "FreeImage.dll" Alias "_FreeImage_SetOutputMessageStdCall@4" ( _ + ByVal omf As Long) + + +' Bitmap management functions +Public Declare Function FreeImage_Allocate Lib "FreeImage.dll" Alias "_FreeImage_Allocate@24" ( _ + ByVal Width As Long, _ + ByVal Height As Long, _ + ByVal BitsPerPixel As Long, _ + Optional ByVal RedMask As Long, _ + Optional ByVal GreenMask As Long, _ + Optional ByVal BlueMask As Long) As Long + +Public Declare Function FreeImage_AllocateT Lib "FreeImage.dll" Alias "_FreeImage_AllocateT@28" ( _ + ByVal ImageType As FREE_IMAGE_TYPE, _ + ByVal Width As Long, _ + ByVal Height As Long, _ + Optional ByVal BitsPerPixel As Long = 8, _ + Optional ByVal RedMask As Long, _ + Optional ByVal GreenMask As Long, _ + Optional ByVal BlueMask As Long) As Long + +Public Declare Function FreeImage_HasPixelsInt Lib "FreeImage.dll" Alias "_FreeImage_HasPixels@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_Load Lib "FreeImage.dll" Alias "_FreeImage_Load@12" ( _ + ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Filename As String, _ + Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long + +Private Declare Function FreeImage_LoadUInt Lib "FreeImage.dll" Alias "_FreeImage_LoadU@12" ( _ + ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Filename As Long, _ + Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long + +Public Declare Function FreeImage_LoadFromHandle Lib "FreeImage.dll" Alias "_FreeImage_LoadFromHandle@16" ( _ + ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal IO As Long, _ + ByVal Handle As Long, _ + Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long + +Private Declare Function FreeImage_SaveInt Lib "FreeImage.dll" Alias "_FreeImage_Save@16" ( _ + ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Bitmap As Long, _ + ByVal Filename As String, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Long + +Private Declare Function FreeImage_SaveUInt Lib "FreeImage.dll" Alias "_FreeImage_SaveU@16" ( _ + ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Bitmap As Long, _ + ByVal Filename As Long, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Long + +Private Declare Function FreeImage_SaveToHandleInt Lib "FreeImage.dll" Alias "_FreeImage_SaveToHandle@20" ( _ + ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Bitmap As Long, _ + ByVal IO As Long, _ + ByVal Handle As Long, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Long + +Public Declare Function FreeImage_Clone Lib "FreeImage.dll" Alias "_FreeImage_Clone@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Sub FreeImage_Unload Lib "FreeImage.dll" Alias "_FreeImage_Unload@4" ( _ + ByVal Bitmap As Long) + + +' Bitmap information functions +Public Declare Function FreeImage_GetImageType Lib "FreeImage.dll" Alias "_FreeImage_GetImageType@4" ( _ + ByVal Bitmap As Long) As FREE_IMAGE_TYPE + +Public Declare Function FreeImage_GetColorsUsed Lib "FreeImage.dll" Alias "_FreeImage_GetColorsUsed@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetBPP Lib "FreeImage.dll" Alias "_FreeImage_GetBPP@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetWidth Lib "FreeImage.dll" Alias "_FreeImage_GetWidth@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetHeight Lib "FreeImage.dll" Alias "_FreeImage_GetHeight@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetLine Lib "FreeImage.dll" Alias "_FreeImage_GetLine@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetPitch Lib "FreeImage.dll" Alias "_FreeImage_GetPitch@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetDIBSize Lib "FreeImage.dll" Alias "_FreeImage_GetDIBSize@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetPalette Lib "FreeImage.dll" Alias "_FreeImage_GetPalette@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetDotsPerMeterX Lib "FreeImage.dll" Alias "_FreeImage_GetDotsPerMeterX@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetDotsPerMeterY Lib "FreeImage.dll" Alias "_FreeImage_GetDotsPerMeterY@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Sub FreeImage_SetDotsPerMeterX Lib "FreeImage.dll" Alias "_FreeImage_SetDotsPerMeterX@8" ( _ + ByVal Bitmap As Long, _ + ByVal Resolution As Long) + +Public Declare Sub FreeImage_SetDotsPerMeterY Lib "FreeImage.dll" Alias "_FreeImage_SetDotsPerMeterY@8" ( _ + ByVal Bitmap As Long, _ + ByVal Resolution As Long) + +Public Declare Function FreeImage_GetInfoHeader Lib "FreeImage.dll" Alias "_FreeImage_GetInfoHeader@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetInfo Lib "FreeImage.dll" Alias "_FreeImage_GetInfo@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetColorType Lib "FreeImage.dll" Alias "_FreeImage_GetColorType@4" ( _ + ByVal Bitmap As Long) As FREE_IMAGE_COLOR_TYPE + +Public Declare Function FreeImage_GetRedMask Lib "FreeImage.dll" Alias "_FreeImage_GetRedMask@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetGreenMask Lib "FreeImage.dll" Alias "_FreeImage_GetGreenMask@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetBlueMask Lib "FreeImage.dll" Alias "_FreeImage_GetBlueMask@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetTransparencyCount Lib "FreeImage.dll" Alias "_FreeImage_GetTransparencyCount@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetTransparencyTable Lib "FreeImage.dll" Alias "_FreeImage_GetTransparencyTable@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Sub FreeImage_SetTransparencyTable Lib "FreeImage.dll" Alias "_FreeImage_SetTransparencyTable@12" ( _ + ByVal Bitmap As Long, _ + ByVal TransTablePtr As Long, _ + ByVal Count As Long) + +Private Declare Sub FreeImage_SetTransparentInt Lib "FreeImage.dll" Alias "_FreeImage_SetTransparent@8" ( _ + ByVal Bitmap As Long, _ + ByVal Value As Long) + +Private Declare Function FreeImage_IsTransparentInt Lib "FreeImage.dll" Alias "_FreeImage_IsTransparent@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetTransparentIndex Lib "FreeImage.dll" Alias "_FreeImage_GetTransparentIndex@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_SetTransparentIndex Lib "FreeImage.dll" Alias "_FreeImage_SetTransparentIndex@8" ( _ + ByVal Bitmap As Long, _ + ByVal Index As Long) As Long + +Private Declare Function FreeImage_HasBackgroundColorInt Lib "FreeImage.dll" Alias "_FreeImage_HasBackgroundColor@4" ( _ + ByVal Bitmap As Long) As Long + +Private Declare Function FreeImage_GetBackgroundColorInt Lib "FreeImage.dll" Alias "_FreeImage_GetBackgroundColor@8" ( _ + ByVal Bitmap As Long, _ + ByRef BackColor As RGBQUAD) As Long + +Private Declare Function FreeImage_GetBackgroundColorAsLongInt Lib "FreeImage.dll" Alias "_FreeImage_GetBackgroundColor@8" ( _ + ByVal Bitmap As Long, _ + ByRef BackColor As Long) As Long + +Private Declare Function FreeImage_SetBackgroundColorInt Lib "FreeImage.dll" Alias "_FreeImage_SetBackgroundColor@8" ( _ + ByVal Bitmap As Long, _ + ByRef BackColor As RGBQUAD) As Long + +Private Declare Function FreeImage_SetBackgroundColorAsLongInt Lib "FreeImage.dll" Alias "_FreeImage_SetBackgroundColor@8" ( _ + ByVal Bitmap As Long, _ + ByRef BackColor As Long) As Long + +Public Declare Function FreeImage_GetThumbnail Lib "FreeImage.dll" Alias "_FreeImage_GetThumbnail@4" ( _ + ByVal Bitmap As Long) As Long + +Private Declare Function FreeImage_SetThumbnailInt Lib "FreeImage.dll" Alias "_FreeImage_SetThumbnail@8" ( _ + ByVal Bitmap As Long, ByVal Thumbnail As Long) As Long + + +' Filetype functions +Public Declare Function FreeImage_GetFileType Lib "FreeImage.dll" Alias "_FreeImage_GetFileType@8" ( _ + ByVal Filename As String, _ + Optional ByVal Size As Long) As FREE_IMAGE_FORMAT + +Private Declare Function FreeImage_GetFileTypeUInt Lib "FreeImage.dll" Alias "_FreeImage_GetFileTypeU@8" ( _ + ByVal Filename As Long, _ + Optional ByVal Size As Long) As FREE_IMAGE_FORMAT + +Public Declare Function FreeImage_GetFileTypeFromHandle Lib "FreeImage.dll" Alias "_FreeImage_GetFileTypeFromHandle@12" ( _ + ByVal IO As Long, _ + ByVal Handle As Long, _ + Optional ByVal Size As Long) As FREE_IMAGE_FORMAT + +Public Declare Function FreeImage_GetFileTypeFromMemory Lib "FreeImage.dll" Alias "_FreeImage_GetFileTypeFromMemory@8" ( _ + ByVal Stream As Long, _ + Optional ByVal Size As Long) As FREE_IMAGE_FORMAT + + +' Pixel access functions +Public Declare Function FreeImage_GetBits Lib "FreeImage.dll" Alias "_FreeImage_GetBits@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_GetScanline Lib "FreeImage.dll" Alias "_FreeImage_GetScanLine@8" ( _ + ByVal Bitmap As Long, _ + ByVal Scanline As Long) As Long + +Private Declare Function FreeImage_GetPixelIndexInt Lib "FreeImage.dll" Alias "_FreeImage_GetPixelIndex@16" ( _ + ByVal Bitmap As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByRef Value As Byte) As Long + +Private Declare Function FreeImage_GetPixelColorInt Lib "FreeImage.dll" Alias "_FreeImage_GetPixelColor@16" ( _ + ByVal Bitmap As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByRef Value As RGBQUAD) As Long + +Private Declare Function FreeImage_GetPixelColorByLongInt Lib "FreeImage.dll" Alias "_FreeImage_GetPixelColor@16" ( _ + ByVal Bitmap As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByRef Value As Long) As Long + +Private Declare Function FreeImage_SetPixelIndexInt Lib "FreeImage.dll" Alias "_FreeImage_SetPixelIndex@16" ( _ + ByVal Bitmap As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByRef Value As Byte) As Long + +Private Declare Function FreeImage_SetPixelColorInt Lib "FreeImage.dll" Alias "_FreeImage_SetPixelColor@16" ( _ + ByVal Bitmap As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByRef Value As RGBQUAD) As Long + +Private Declare Function FreeImage_SetPixelColorByLongInt Lib "FreeImage.dll" Alias "_FreeImage_SetPixelColor@16" ( _ + ByVal Bitmap As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByRef Value As Long) As Long + + + +' Conversion functions +Public Declare Function FreeImage_ConvertTo4Bits Lib "FreeImage.dll" Alias "_FreeImage_ConvertTo4Bits@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_ConvertTo8Bits Lib "FreeImage.dll" Alias "_FreeImage_ConvertTo8Bits@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_ConvertToGreyscale Lib "FreeImage.dll" Alias "_FreeImage_ConvertToGreyscale@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_ConvertTo16Bits555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertTo16Bits555@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_ConvertTo16Bits565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertTo16Bits565@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_ConvertTo24Bits Lib "FreeImage.dll" Alias "_FreeImage_ConvertTo24Bits@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_ConvertTo32Bits Lib "FreeImage.dll" Alias "_FreeImage_ConvertTo32Bits@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_ColorQuantize Lib "FreeImage.dll" Alias "_FreeImage_ColorQuantize@8" ( _ + ByVal Bitmap As Long, _ + ByVal QuantizeMethod As FREE_IMAGE_QUANTIZE) As Long + +Private Declare Function FreeImage_ColorQuantizeExInt Lib "FreeImage.dll" Alias "_FreeImage_ColorQuantizeEx@20" ( _ + ByVal Bitmap As Long, _ + Optional ByVal QuantizeMethod As FREE_IMAGE_QUANTIZE = FIQ_WUQUANT, _ + Optional ByVal PaletteSize As Long = 256, _ + Optional ByVal ReserveSize As Long = 0, _ + Optional ByVal ReservePalettePtr As Long = 0) As Long + +Public Declare Function FreeImage_Threshold Lib "FreeImage.dll" Alias "_FreeImage_Threshold@8" ( _ + ByVal Bitmap As Long, _ + ByVal Threshold As Byte) As Long + +Public Declare Function FreeImage_Dither Lib "FreeImage.dll" Alias "_FreeImage_Dither@8" ( _ + ByVal Bitmap As Long, _ + ByVal DitherMethod As FREE_IMAGE_DITHER) As Long + +Private Declare Function FreeImage_ConvertFromRawBitsInt Lib "FreeImage.dll" Alias "_FreeImage_ConvertFromRawBits@36" ( _ + ByVal BitsPtr As Long, _ + ByVal Width As Long, _ + ByVal Height As Long, _ + ByVal Pitch As Long, _ + ByVal BitsPerPixel As Long, _ + ByVal RedMask As Long, _ + ByVal GreenMask As Long, _ + ByVal BlueMask As Long, _ + ByVal TopDown As Long) As Long + +Private Declare Sub FreeImage_ConvertToRawBitsInt Lib "FreeImage.dll" Alias "_FreeImage_ConvertToRawBits@32" ( _ + ByVal BitsPtr As Long, _ + ByVal Bitmap As Long, _ + ByVal Pitch As Long, _ + ByVal BitsPerPixel As Long, _ + ByVal RedMask As Long, _ + ByVal GreenMask As Long, _ + ByVal BlueMask As Long, _ + ByVal TopDown As Long) + +Private Declare Function FreeImage_ConvertToStandardTypeInt Lib "FreeImage.dll" Alias "_FreeImage_ConvertToStandardType@8" ( _ + ByVal Bitmap As Long, _ + ByVal ScaleLinear As Long) As Long + +Private Declare Function FreeImage_ConvertToTypeInt Lib "FreeImage.dll" Alias "_FreeImage_ConvertToType@12" ( _ + ByVal Bitmap As Long, _ + ByVal DestinationType As FREE_IMAGE_TYPE, _ + ByVal ScaleLinear As Long) As Long + +Public Declare Function FreeImage_ConvertToFloat Lib "FreeImage.dll" Alias "_FreeImage_ConvertToFloat@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_ConvertToRGBF Lib "FreeImage.dll" Alias "_FreeImage_ConvertToRGBF@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_ConvertToUINT16 Lib "FreeImage.dll" Alias "_FreeImage_ConvertToUINT16@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_ConvertToRGB16 Lib "FreeImage.dll" Alias "_FreeImage_ConvertToRGB16@4" ( _ + ByVal Bitmap As Long) As Long + +' Tone mapping operators +Public Declare Function FreeImage_ToneMapping Lib "FreeImage.dll" Alias "_FreeImage_ToneMapping@24" ( _ + ByVal Bitmap As Long, _ + ByVal Operator As FREE_IMAGE_TMO, _ + Optional ByVal FirstArgument As Double, _ + Optional ByVal SecondArgument As Double) As Long + +Public Declare Function FreeImage_TmoDrago03 Lib "FreeImage.dll" Alias "_FreeImage_TmoDrago03@20" ( _ + ByVal Bitmap As Long, _ + Optional ByVal Gamma As Double = 2.2, _ + Optional ByVal Exposure As Double) As Long + +Public Declare Function FreeImage_TmoReinhard05 Lib "FreeImage.dll" Alias "_FreeImage_TmoReinhard05@20" ( _ + ByVal Bitmap As Long, _ + Optional ByVal Intensity As Double, _ + Optional ByVal Contrast As Double) As Long + +Public Declare Function FreeImage_TmoReinhard05Ex Lib "FreeImage.dll" Alias "_FreeImage_TmoReinhard05Ex@36" ( _ + ByVal Bitmap As Long, _ + Optional ByVal Intensity As Double, _ + Optional ByVal Contrast As Double, _ + Optional ByVal Adaptation As Double = 1, _ + Optional ByVal ColorCorrection As Double) As Long + +Public Declare Function FreeImage_TmoFattal02 Lib "FreeImage.dll" Alias "_FreeImage_TmoFattal02@20" ( _ + ByVal Bitmap As Long, _ + Optional ByVal ColorSaturation As Double = 0.5, _ + Optional ByVal Attenuation As Double = 0.85) As Long + + +' ICC profile functions +Private Declare Function FreeImage_GetICCProfileInt Lib "FreeImage.dll" Alias "_FreeImage_GetICCProfile@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_CreateICCProfile Lib "FreeImage.dll" Alias "_FreeImage_CreateICCProfile@12" ( _ + ByVal Bitmap As Long, _ + ByRef Data As Long, _ + ByVal Size As Long) As Long + +Public Declare Sub FreeImage_DestroyICCProfile Lib "FreeImage.dll" Alias "_FreeImage_DestroyICCProfile@4" ( _ + ByVal Bitmap As Long) + + +' Plugin functions +Public Declare Function FreeImage_GetFIFCount Lib "FreeImage.dll" Alias "_FreeImage_GetFIFCount@0" () As Long + +Public Declare Function FreeImage_SetPluginEnabled Lib "FreeImage.dll" Alias "_FreeImage_SetPluginEnabled@8" ( _ + ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Value As Long) As Long + +Public Declare Function FreeImage_IsPluginEnabled Lib "FreeImage.dll" Alias "_FreeImage_IsPluginEnabled@4" ( _ + ByVal Format As FREE_IMAGE_FORMAT) As Long + +Public Declare Function FreeImage_GetFIFFromFormat Lib "FreeImage.dll" Alias "_FreeImage_GetFIFFromFormat@4" ( _ + ByVal Format As String) As FREE_IMAGE_FORMAT + +Public Declare Function FreeImage_GetFIFFromMime Lib "FreeImage.dll" Alias "_FreeImage_GetFIFFromMime@4" ( _ + ByVal MimeType As String) As FREE_IMAGE_FORMAT + +Private Declare Function FreeImage_GetFIFMimeTypeInt Lib "FreeImage.dll" Alias "_FreeImage_GetFIFMimeType@4" ( _ + ByVal Format As FREE_IMAGE_FORMAT) As Long + +Private Declare Function FreeImage_GetFormatFromFIFInt Lib "FreeImage.dll" Alias "_FreeImage_GetFormatFromFIF@4" ( _ + ByVal Format As FREE_IMAGE_FORMAT) As Long + +Private Declare Function FreeImage_GetFIFExtensionListInt Lib "FreeImage.dll" Alias "_FreeImage_GetFIFExtensionList@4" ( _ + ByVal Format As FREE_IMAGE_FORMAT) As Long + +Private Declare Function FreeImage_GetFIFDescriptionInt Lib "FreeImage.dll" Alias "_FreeImage_GetFIFDescription@4" ( _ + ByVal Format As FREE_IMAGE_FORMAT) As Long + +Private Declare Function FreeImage_GetFIFRegExprInt Lib "FreeImage.dll" Alias "_FreeImage_GetFIFRegExpr@4" ( _ + ByVal Format As FREE_IMAGE_FORMAT) As Long + +Public Declare Function FreeImage_GetFIFFromFilename Lib "FreeImage.dll" Alias "_FreeImage_GetFIFFromFilename@4" ( _ + ByVal Filename As String) As FREE_IMAGE_FORMAT + +Private Declare Function FreeImage_GetFIFFromFilenameUInt Lib "FreeImage.dll" Alias "_FreeImage_GetFIFFromFilenameU@4" ( _ + ByVal Filename As Long) As FREE_IMAGE_FORMAT + +Private Declare Function FreeImage_FIFSupportsReadingInt Lib "FreeImage.dll" Alias "_FreeImage_FIFSupportsReading@4" ( _ + ByVal Format As FREE_IMAGE_FORMAT) As Long + +Private Declare Function FreeImage_FIFSupportsWritingInt Lib "FreeImage.dll" Alias "_FreeImage_FIFSupportsWriting@4" ( _ + ByVal Format As FREE_IMAGE_FORMAT) As Long + +Private Declare Function FreeImage_FIFSupportsExportTypeInt Lib "FreeImage.dll" Alias "_FreeImage_FIFSupportsExportType@8" ( _ + ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal ImageType As FREE_IMAGE_TYPE) As Long + +Private Declare Function FreeImage_FIFSupportsExportBPPInt Lib "FreeImage.dll" Alias "_FreeImage_FIFSupportsExportBPP@8" ( _ + ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal BitsPerPixel As Long) As Long + +Private Declare Function FreeImage_FIFSupportsICCProfilesInt Lib "FreeImage.dll" Alias "_FreeImage_FIFSupportsICCProfiles@4" ( _ + ByVal Format As FREE_IMAGE_FORMAT) As Long + +Private Declare Function FreeImage_FIFSupportsNoPixelsInt Lib "FreeImage.dll" Alias "_FreeImage_FIFSupportsNoPixels@4" ( _ + ByVal Format As FREE_IMAGE_FORMAT) As Long + +Public Declare Function FreeImage_RegisterLocalPlugin Lib "FreeImage.dll" Alias "_FreeImage_RegisterLocalPlugin@20" ( _ + ByVal InitProcAddress As Long, _ + Optional ByVal Format As String, _ + Optional ByVal Description As String, _ + Optional ByVal Extension As String, _ + Optional ByVal RegExpr As String) As FREE_IMAGE_FORMAT + +Public Declare Function FreeImage_RegisterExternalPlugin Lib "FreeImage.dll" Alias "_FreeImage_RegisterExternalPlugin@20" ( _ + ByVal Path As String, _ + Optional ByVal Format As String, _ + Optional ByVal Description As String, _ + Optional ByVal Extension As String, _ + Optional ByVal RegExpr As String) As FREE_IMAGE_FORMAT + + +' Multipage functions +Private Declare Function FreeImage_OpenMultiBitmapInt Lib "FreeImage.dll" Alias "_FreeImage_OpenMultiBitmap@24" ( _ + ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Filename As String, _ + ByVal CreateNew As Long, _ + ByVal ReadOnly As Long, _ + ByVal KeepCacheInMemory As Long, _ + ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long + +Private Declare Function FreeImage_CloseMultiBitmapInt Lib "FreeImage.dll" Alias "_FreeImage_CloseMultiBitmap@8" ( _ + ByVal Bitmap As Long, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Long + +Public Declare Function FreeImage_GetPageCount Lib "FreeImage.dll" Alias "_FreeImage_GetPageCount@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Sub FreeImage_AppendPage Lib "FreeImage.dll" Alias "_FreeImage_AppendPage@8" ( _ + ByVal Bitmap As Long, _ + ByVal PageBitmap As Long) + +Public Declare Sub FreeImage_InsertPage Lib "FreeImage.dll" Alias "_FreeImage_InsertPage@12" ( _ + ByVal Bitmap As Long, _ + ByVal Page As Long, _ + ByVal PageBitmap As Long) + +Public Declare Sub FreeImage_DeletePage Lib "FreeImage.dll" Alias "_FreeImage_DeletePage@8" ( _ + ByVal Bitmap As Long, _ + ByVal Page As Long) + +Public Declare Function FreeImage_LockPage Lib "FreeImage.dll" Alias "_FreeImage_LockPage@8" ( _ + ByVal Bitmap As Long, _ + ByVal Page As Long) As Long + +Private Declare Sub FreeImage_UnlockPageInt Lib "FreeImage.dll" Alias "_FreeImage_UnlockPage@12" ( _ + ByVal Bitmap As Long, _ + ByVal PageBitmap As Long, _ + ByVal ApplyChanges As Long) + +Private Declare Function FreeImage_MovePageInt Lib "FreeImage.dll" Alias "_FreeImage_MovePage@12" ( _ + ByVal Bitmap As Long, _ + ByVal TargetPage As Long, _ + ByVal SourcePage As Long) As Long + +Private Declare Function FreeImage_GetLockedPageNumbersInt Lib "FreeImage.dll" Alias "_FreeImage_GetLockedPageNumbers@12" ( _ + ByVal Bitmap As Long, _ + ByRef PagesPtr As Long, _ + ByRef Count As Long) As Long + + +' Memory I/O streams +Public Declare Function FreeImage_OpenMemory Lib "FreeImage.dll" Alias "_FreeImage_OpenMemory@8" ( _ + Optional ByRef Data As Byte, _ + Optional ByVal SizeInBytes As Long) As Long + +Public Declare Function FreeImage_OpenMemoryByPtr Lib "FreeImage.dll" Alias "_FreeImage_OpenMemory@8" ( _ + Optional ByVal DataPtr As Long, _ + Optional ByVal SizeInBytes As Long) As Long + +Public Declare Sub FreeImage_CloseMemory Lib "FreeImage.dll" Alias "_FreeImage_CloseMemory@4" ( _ + ByVal Stream As Long) + +Public Declare Function FreeImage_LoadFromMemory Lib "FreeImage.dll" Alias "_FreeImage_LoadFromMemory@12" ( _ + ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Stream As Long, _ + Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long + +Private Declare Function FreeImage_SaveToMemoryInt Lib "FreeImage.dll" Alias "_FreeImage_SaveToMemory@16" ( _ + ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Bitmap As Long, _ + ByVal Stream As Long, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Long + +Private Declare Function FreeImage_AcquireMemoryInt Lib "FreeImage.dll" Alias "_FreeImage_AcquireMemory@12" ( _ + ByVal Stream As Long, _ + ByRef DataPtr As Long, _ + ByRef SizeInBytes As Long) As Long + +Public Declare Function FreeImage_TellMemory Lib "FreeImage.dll" Alias "_FreeImage_TellMemory@4" ( _ + ByVal Stream As Long) As Long + +Private Declare Function FreeImage_SeekMemoryInt Lib "FreeImage.dll" Alias "_FreeImage_SeekMemory@12" ( _ + ByVal Stream As Long, _ + ByVal Offset As Long, _ + ByVal Origin As Long) As Long + +Public Declare Function FreeImage_ReadMemory Lib "FreeImage.dll" Alias "_FreeImage_ReadMemory@16" ( _ + ByVal BufferPtr As Long, _ + ByVal Size As Long, _ + ByVal Count As Long, _ + ByVal Stream As Long) As Long + +Public Declare Function FreeImage_WriteMemory Lib "FreeImage.dll" Alias "_FreeImage_WriteMemory@16" ( _ + ByVal BufferPtr As Long, _ + ByVal Size As Long, _ + ByVal Count As Long, _ + ByVal Stream As Long) As Long + +Public Declare Function FreeImage_LoadMultiBitmapFromMemory Lib "FreeImage.dll" Alias "_FreeImage_LoadMultiBitmapFromMemory@12" ( _ + ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Stream As Long, _ + Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long + +Public Declare Function FreeImage_SaveMultiBitmapToMemory Lib "FreeImage.dll" Alias "_FreeImage_SaveMultiBitmapToMemory@16" ( _ + ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Bitmap As Long, _ + ByVal Stream As Long, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Long + + +' Compression functions +Public Declare Function FreeImage_ZLibCompress Lib "FreeImage.dll" Alias "_FreeImage_ZLibCompress@16" ( _ + ByVal TargetPtr As Long, _ + ByVal TargetSize As Long, _ + ByVal SourcePtr As Long, _ + ByVal SourceSize As Long) As Long + +Public Declare Function FreeImage_ZLibUncompress Lib "FreeImage.dll" Alias "_FreeImage_ZLibUncompress@16" ( _ + ByVal TargetPtr As Long, _ + ByVal TargetSize As Long, _ + ByVal SourcePtr As Long, _ + ByVal SourceSize As Long) As Long + +Public Declare Function FreeImage_ZLibGZip Lib "FreeImage.dll" Alias "_FreeImage_ZLibGZip@16" ( _ + ByVal TargetPtr As Long, _ + ByVal TargetSize As Long, _ + ByVal SourcePtr As Long, _ + ByVal SourceSize As Long) As Long + +Public Declare Function FreeImage_ZLibGUnzip Lib "FreeImage.dll" Alias "_FreeImage_ZLibGUnzip@16" ( _ + ByVal TargetPtr As Long, _ + ByVal TargetSize As Long, _ + ByVal SourcePtr As Long, _ + ByVal SourceSize As Long) As Long + +Public Declare Function FreeImage_ZLibCRC32 Lib "FreeImage.dll" Alias "_FreeImage_ZLibCRC32@12" ( _ + ByVal CRC As Long, _ + ByVal SourcePtr As Long, _ + ByVal SourceSize As Long) As Long + + +' Helper functions +Private Declare Function FreeImage_IsLittleEndianInt Lib "FreeImage.dll" Alias "_FreeImage_IsLittleEndian@0" () As Long + +Private Declare Function FreeImage_LookupX11ColorInt Lib "FreeImage.dll" Alias "_FreeImage_LookupX11Color@16" ( _ + ByVal Color As String, _ + ByRef red As Long, _ + ByRef green As Long, _ + ByRef blue As Long) As Long + +Private Declare Function FreeImage_LookupSVGColorInt Lib "FreeImage.dll" Alias "_FreeImage_LookupSVGColor@16" ( _ + ByVal Color As String, _ + ByRef red As Long, _ + ByRef green As Long, _ + ByRef blue As Long) As Long + + +'-------------------------------------------------------------------------------- +' Metadata functions +'-------------------------------------------------------------------------------- + +' Tag creation and destruction +Private Declare Function FreeImage_CreateTag Lib "FreeImage.dll" Alias "_FreeImage_CreateTag@0" () As Long + +Private Declare Sub FreeImage_DeleteTag Lib "FreeImage.dll" Alias "_FreeImage_DeleteTag@4" ( _ + ByVal Tag As Long) + +Private Declare Function FreeImage_CloneTag Lib "FreeImage.dll" Alias "_FreeImage_CloneTag@4" ( _ + ByVal Tag As Long) As Long + + +' Tag accessors (only those needed by wrapper functions) +Private Declare Function FreeImage_SetTagKey Lib "FreeImage.dll" Alias "_FreeImage_SetTagKey@8" ( _ + ByVal Tag As Long, _ + ByVal Key As String) As Long + +Private Declare Function FreeImage_SetTagValue Lib "FreeImage.dll" Alias "_FreeImage_SetTagValue@8" ( _ + ByVal Tag As Long, _ + ByVal ValuePtr As Long) As Long + +' Metadata iterator +Public Declare Function FreeImage_FindFirstMetadata Lib "FreeImage.dll" Alias "_FreeImage_FindFirstMetadata@12" ( _ + ByVal Model As FREE_IMAGE_MDMODEL, _ + ByVal Bitmap As Long, _ + ByRef Tag As Long) As Long + +Private Declare Function FreeImage_FindNextMetadataInt Lib "FreeImage.dll" Alias "_FreeImage_FindNextMetadata@8" ( _ + ByVal hFind As Long, _ + ByRef Tag As Long) As Long + +Public Declare Sub FreeImage_FindCloseMetadata Lib "FreeImage.dll" Alias "_FreeImage_FindCloseMetadata@4" ( _ + ByVal hFind As Long) + +Public Declare Function FreeImage_CloneMetadataInt Lib "FreeImage.dll" Alias "_FreeImage_CloneMetadata@8" ( _ + ByVal BitmapDst As Long, _ + ByVal BitmapSrc As Long) As Long + + +' Metadata accessors +Private Declare Function FreeImage_SetMetadataInt Lib "FreeImage.dll" Alias "_FreeImage_SetMetadata@16" ( _ + ByVal Model As Long, _ + ByVal Bitmap As Long, _ + ByVal Key As String, _ + ByVal Tag As Long) As Long + +Private Declare Function FreeImage_GetMetadataInt Lib "FreeImage.dll" Alias "_FreeImage_GetMetadata@16" ( _ + ByVal Model As Long, _ + ByVal Bitmap As Long, _ + ByVal Key As String, _ + ByRef Tag As Long) As Long + + +' Metadata helper functions +Public Declare Function FreeImage_GetMetadataCount Lib "FreeImage.dll" Alias "_FreeImage_GetMetadataCount@8" ( _ + ByVal Model As Long, _ + ByVal Bitmap As Long) As Long + +Private Declare Function FreeImage_TagToStringInt Lib "FreeImage.dll" Alias "_FreeImage_TagToString@12" ( _ + ByVal Model As Long, _ + ByVal Tag As Long, _ + Optional ByVal Make As String = vbNullString) As Long + + +'-------------------------------------------------------------------------------- +' Toolkit functions +'-------------------------------------------------------------------------------- + +' Rotating and flipping +Public Declare Function FreeImage_RotateClassic Lib "FreeImage.dll" Alias "_FreeImage_RotateClassic@12" ( _ + ByVal Bitmap As Long, _ + ByVal Angle As Double) As Long + +Public Declare Function FreeImage_Rotate Lib "FreeImage.dll" Alias "_FreeImage_Rotate@16" ( _ + ByVal Bitmap As Long, _ + ByVal Angle As Double, _ + Optional ByRef Color As Any) As Long + +Private Declare Function FreeImage_RotateExInt Lib "FreeImage.dll" Alias "_FreeImage_RotateEx@48" ( _ + ByVal Bitmap As Long, _ + ByVal Angle As Double, _ + ByVal ShiftX As Double, _ + ByVal ShiftY As Double, _ + ByVal OriginX As Double, _ + ByVal OriginY As Double, _ + ByVal UseMask As Long) As Long + +Private Declare Function FreeImage_FlipHorizontalInt Lib "FreeImage.dll" Alias "_FreeImage_FlipHorizontal@4" ( _ + ByVal Bitmap As Long) As Long + +Private Declare Function FreeImage_FlipVerticalInt Lib "FreeImage.dll" Alias "_FreeImage_FlipVertical@4" ( _ + ByVal Bitmap As Long) As Long + +Private Declare Function FreeImage_JPEGTransformInt Lib "FreeImage.dll" Alias "_FreeImage_JPEGTransform@16" ( _ + ByVal SourceFile As String, _ + ByVal DestFile As String, _ + ByVal Operation As FREE_IMAGE_JPEG_OPERATION, _ + ByVal Perfect As Long) As Long + +Private Declare Function FreeImage_JPEGTransformUInt Lib "FreeImage.dll" Alias "_FreeImage_JPEGTransformU@16" ( _ + ByVal SourceFile As Long, _ + ByVal DestFile As Long, _ + ByVal Operation As FREE_IMAGE_JPEG_OPERATION, _ + ByVal Perfect As Long) As Long + + +' Upsampling and downsampling +Public Declare Function FreeImage_Rescale Lib "FreeImage.dll" Alias "_FreeImage_Rescale@16" ( _ + ByVal Bitmap As Long, _ + ByVal Width As Long, _ + ByVal Height As Long, _ + ByVal Filter As FREE_IMAGE_FILTER) As Long + +Public Declare Function FreeImage_RescaleRect Lib "FreeImage.dll" Alias "_FreeImage_RescaleRect@32" ( _ + ByVal Bitmap As Long, _ + ByVal Left As Long, _ + ByVal Top As Long, _ + ByVal Right As Long, _ + ByVal Bottom As Long, _ + ByVal Width As Long, _ + ByVal Height As Long, _ + ByVal Filter As FREE_IMAGE_FILTER) As Long + +Private Declare Function FreeImage_MakeThumbnailInt Lib "FreeImage.dll" Alias "_FreeImage_MakeThumbnail@12" ( _ + ByVal Bitmap As Long, _ + ByVal MaxPixelSize As Long, _ + Optional ByVal Convert As Long) As Long + + +' Color manipulation +Private Declare Function FreeImage_AdjustCurveInt Lib "FreeImage.dll" Alias "_FreeImage_AdjustCurve@12" ( _ + ByVal Bitmap As Long, _ + ByVal LookupTablePtr As Long, _ + ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Long + +Private Declare Function FreeImage_AdjustGammaInt Lib "FreeImage.dll" Alias "_FreeImage_AdjustGamma@12" ( _ + ByVal Bitmap As Long, _ + ByVal Gamma As Double) As Long + +Private Declare Function FreeImage_AdjustBrightnessInt Lib "FreeImage.dll" Alias "_FreeImage_AdjustBrightness@12" ( _ + ByVal Bitmap As Long, _ + ByVal Percentage As Double) As Long + +Private Declare Function FreeImage_AdjustContrastInt Lib "FreeImage.dll" Alias "_FreeImage_AdjustContrast@12" ( _ + ByVal Bitmap As Long, _ + ByVal Percentage As Double) As Long + +Private Declare Function FreeImage_InvertInt Lib "FreeImage.dll" Alias "_FreeImage_Invert@4" ( _ + ByVal Bitmap As Long) As Long + +Private Declare Function FreeImage_GetHistogramInt Lib "FreeImage.dll" Alias "_FreeImage_GetHistogram@12" ( _ + ByVal Bitmap As Long, _ + ByRef HistogramPtr As Long, _ + Optional ByVal Channel As FREE_IMAGE_COLOR_CHANNEL = FICC_BLACK) As Long + +Private Declare Function FreeImage_GetAdjustColorsLookupTableInt Lib "FreeImage.dll" Alias "_FreeImage_GetAdjustColorsLookupTable@32" ( _ + ByVal LookupTablePtr As Long, _ + ByVal Brightness As Double, _ + ByVal Contrast As Double, _ + ByVal Gamma As Double, _ + ByVal Invert As Long) As Long + +Private Declare Function FreeImage_AdjustColorsInt Lib "FreeImage.dll" Alias "_FreeImage_AdjustColors@32" ( _ + ByVal Bitmap As Long, _ + ByVal Brightness As Double, _ + ByVal Contrast As Double, _ + ByVal Gamma As Double, _ + ByVal Invert As Long) As Long + +Private Declare Function FreeImage_ApplyColorMappingInt Lib "FreeImage.dll" Alias "_FreeImage_ApplyColorMapping@24" ( _ + ByVal Bitmap As Long, _ + ByVal SourceColorsPtr As Long, _ + ByVal DestinationColorsPtr As Long, _ + ByVal Count As Long, _ + ByVal IgnoreAlpha As Long, _ + ByVal swap As Long) As Long + +Private Declare Function FreeImage_SwapColorsInt Lib "FreeImage.dll" Alias "_FreeImage_SwapColors@16" ( _ + ByVal Bitmap As Long, _ + ByRef ColorA As RGBQUAD, _ + ByRef ColorB As RGBQUAD, _ + ByVal IgnoreAlpha As Long) As Long + +Private Declare Function FreeImage_SwapColorsByLongInt Lib "FreeImage.dll" Alias "_FreeImage_SwapColors@16" ( _ + ByVal Bitmap As Long, _ + ByRef ColorA As Long, _ + ByRef ColorB As Long, _ + ByVal IgnoreAlpha As Long) As Long + +Private Declare Function FreeImage_ApplyIndexMappingInt Lib "FreeImage.dll" Alias "_FreeImage_ApplyIndexMapping@20" ( _ + ByVal Bitmap As Long, _ + ByVal SourceIndicesPtr As Long, _ + ByVal DestinationIndicesPtr As Long, _ + ByVal Count As Long, _ + ByVal swap As Long) As Long + +Public Declare Function FreeImage_SwapPaletteIndices Lib "FreeImage.dll" Alias "_FreeImage_SwapPaletteIndices@12" ( _ + ByVal Bitmap As Long, _ + ByRef IndexA As Byte, _ + ByRef IndexB As Byte) As Long + +' Channel processing +Public Declare Function FreeImage_GetChannel Lib "FreeImage.dll" Alias "_FreeImage_GetChannel@8" ( _ + ByVal Bitmap As Long, _ + ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Long + +Private Declare Function FreeImage_SetChannelInt Lib "FreeImage.dll" Alias "_FreeImage_SetChannel@12" ( _ + ByVal BitmapDst As Long, _ + ByVal BitmapSrc As Long, _ + ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Long + +Public Declare Function FreeImage_GetComplexChannel Lib "FreeImage.dll" Alias "_FreeImage_GetComplexChannel@8" ( _ + ByVal Bitmap As Long, _ + ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Long + +Private Declare Function FreeImage_SetComplexChannelInt Lib "FreeImage.dll" Alias "_FreeImage_SetComplexChannel@12" ( _ + ByVal BitmapDst As Long, _ + ByVal BitmapSrc As Long, _ + ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Long + + +' Copy / Paste / Composite routines +Public Declare Function FreeImage_Copy Lib "FreeImage.dll" Alias "_FreeImage_Copy@20" ( _ + ByVal Bitmap As Long, _ + ByVal Left As Long, _ + ByVal Top As Long, _ + ByVal Right As Long, _ + ByVal Bottom As Long) As Long + +Private Declare Function FreeImage_PasteInt Lib "FreeImage.dll" Alias "_FreeImage_Paste@20" ( _ + ByVal BitmapDst As Long, _ + ByVal BitmapSrc As Long, _ + ByVal Left As Long, _ + ByVal Top As Long, _ + ByVal Alpha As Long) As Long + +Public Declare Function FreeImage_Composite Lib "FreeImage.dll" Alias "_FreeImage_Composite@16" ( _ + ByVal Bitmap As Long, _ + Optional ByVal UseFileBackColor As Long, _ + Optional ByRef AppBackColor As Any, _ + Optional ByVal BackgroundBitmap As Long) As Long + +Private Declare Function FreeImage_JPEGCropInt Lib "FreeImage.dll" Alias "_FreeImage_JPEGCrop@24" ( _ + ByVal SourceFile As String, _ + ByVal DestFile As String, _ + ByVal Left As Long, _ + ByVal Top As Long, _ + ByVal Right As Long, _ + ByVal Bottom As Long) As Long + +Private Declare Function FreeImage_JPEGCropUInt Lib "FreeImage.dll" Alias "_FreeImage_JPEGCropU@24" ( _ + ByVal SourceFile As Long, _ + ByVal DestFile As Long, _ + ByVal Left As Long, _ + ByVal Top As Long, _ + ByVal Right As Long, _ + ByVal Bottom As Long) As Long + +Private Declare Function FreeImage_PreMultiplyWithAlphaInt Lib "FreeImage.dll" Alias "_FreeImage_PreMultiplyWithAlpha@4" ( _ + ByVal Bitmap As Long) As Long + +Public Declare Function FreeImage_FillBackground Lib "FreeImage.dll" Alias "_FreeImage_FillBackground@12" ( _ + ByVal Bitmap As Long, _ + ByRef Color As Any, _ + Optional ByVal Options As FREE_IMAGE_COLOR_OPTIONS = FI_COLOR_IS_RGB_COLOR) As Long + +Public Declare Function FreeImage_EnlargeCanvas Lib "FreeImage.dll" Alias "_FreeImage_EnlargeCanvas@28" ( _ + ByVal Bitmap As Long, _ + ByVal Left As Long, _ + ByVal Top As Long, _ + ByVal Right As Long, _ + ByVal Bottom As Long, _ + ByRef Color As Any, _ + Optional ByVal Options As FREE_IMAGE_COLOR_OPTIONS = FI_COLOR_IS_RGB_COLOR) As Long + +Public Declare Function FreeImage_AllocateEx Lib "FreeImage.dll" Alias "_FreeImage_AllocateEx@36" ( _ + ByVal Width As Long, _ + ByVal Height As Long, _ + Optional ByVal BitsPerPixel As Long = 8, _ + Optional ByRef Color As Any, _ + Optional ByVal Options As FREE_IMAGE_COLOR_OPTIONS, _ + Optional ByVal PalettePtr As Long = 0, _ + Optional ByVal RedMask As Long = 0, _ + Optional ByVal GreenMask As Long = 0, _ + Optional ByVal BlueMask As Long = 0) As Long + +Public Declare Function FreeImage_AllocateExT Lib "FreeImage.dll" Alias "_FreeImage_AllocateExT@36" ( _ + ByVal ImageType As FREE_IMAGE_TYPE, _ + ByVal Width As Long, _ + ByVal Height As Long, _ + Optional ByVal BitsPerPixel As Long = 8, _ + Optional ByRef Color As Any, _ + Optional ByVal Options As FREE_IMAGE_COLOR_OPTIONS, _ + Optional ByVal PalettePtr As Long, _ + Optional ByVal RedMask As Long, _ + Optional ByVal GreenMask As Long, _ + Optional ByVal BlueMask As Long) As Long + +' miscellaneous algorithms +Public Declare Function FreeImage_MultigridPoissonSolver Lib "FreeImage.dll" Alias "_FreeImage_MultigridPoissonSolver@8" ( _ + ByVal LaplacianBitmap As Long, _ + Optional ByVal Cyles As Long = 3) As Long + + +'-------------------------------------------------------------------------------- +' Line converting functions +'-------------------------------------------------------------------------------- + +' convert to 4 bpp +Public Declare Sub FreeImage_ConvertLine1To4 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To4@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine8To4 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To8@16" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long, _ + ByVal PalettePtr As Long) + +Public Declare Sub FreeImage_ConvertLine16To4_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To4_555@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine16To4_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To4_565@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine24To4 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To24@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine32To4 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine32To4@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + + +' convert to 8 bpp +Public Declare Sub FreeImage_ConvertLine1To8 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To8@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine4To8 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine4To8@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine16To8_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To8_555@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine16To8_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To8_565@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine24To8 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine24To8@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine32To8 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine32To8@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + + +' convert to 16 bpp +Public Declare Sub FreeImage_ConvertLine1To16_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To16_555@16" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long, _ + ByVal PalettePtr As Long) + +Public Declare Sub FreeImage_ConvertLine4To16_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine4To16_555@16" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long, _ + ByVal PalettePtr As Long) + +Public Declare Sub FreeImage_ConvertLine8To16_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine8To16_555@16" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long, _ + ByVal PalettePtr As Long) + +Public Declare Sub FreeImage_ConvertLine16_565_To16_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16_565_To16_555@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine24To16_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine24To16_555@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine32To16_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine32To16_555@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine1To16_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To16_565@16" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long, _ + ByVal PalettePtr As Long) + +Public Declare Sub FreeImage_ConvertLine4To16_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine4To16_565@16" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long, _ + ByVal PalettePtr As Long) + +Public Declare Sub FreeImage_ConvertLine8To16_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine8To16_565@16" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long, _ + ByVal PalettePtr As Long) + +Public Declare Sub FreeImage_ConvertLine16_555_To16_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16_555_To16_565@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine24To16_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine24To16_565@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine32To16_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine32To16_565@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + + +' convert to 24 bpp +Public Declare Sub FreeImage_ConvertLine1To24 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To24@16" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long, _ + ByVal PalettePtr As Long) + +Public Declare Sub FreeImage_ConvertLine4To24 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine4To24@16" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long, _ + ByVal PalettePtr As Long) + +Public Declare Sub FreeImage_ConvertLine8To24 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine8To24@16" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long, _ + ByVal PalettePtr As Long) + +Public Declare Sub FreeImage_ConvertLine16To24_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To24_555@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine16To24_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To24_565@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine32To24 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine32To24@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + + +' convert to 32 bpp +Public Declare Sub FreeImage_ConvertLine1To32 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine1To32@16" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long, _ + ByVal PalettePtr As Long) + +Public Declare Sub FreeImage_ConvertLine4To32 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine4To32@16" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long, _ + ByVal PalettePtr As Long) + +Public Declare Sub FreeImage_ConvertLine8To32 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine8To32@16" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long, _ + ByVal PalettePtr As Long) + +Public Declare Sub FreeImage_ConvertLine16To32_555 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To32_555@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine16To32_565 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine16To32_565@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + +Public Declare Sub FreeImage_ConvertLine24To32 Lib "FreeImage.dll" Alias "_FreeImage_ConvertLine24To32@12" ( _ + ByVal TargetPtr As Long, _ + ByVal SourcePtr As Long, _ + ByVal WidthInPixels As Long) + + + +'-------------------------------------------------------------------------------- +' Initialization functions +'-------------------------------------------------------------------------------- + +Public Function FreeImage_IsAvailable(Optional ByRef Version As String) As Boolean + + On Error Resume Next + Version = FreeImage_GetVersion() + FreeImage_IsAvailable = (Err.Number = ERROR_SUCCESS) + On Error GoTo 0 + +End Function + + + +'-------------------------------------------------------------------------------- +' Error handling functions +'-------------------------------------------------------------------------------- + +Public Sub FreeImage_InitErrorHandler() + + ' Call this function once for using the FreeImage 3 error handling callback. + ' The 'FreeImage_ErrorHandler' function is called on each FreeImage 3 error. + + Call FreeImage_SetOutputMessage(AddressOf FreeImage_ErrorHandler) + +End Sub + +Private Sub FreeImage_ErrorHandler(ByVal Format As FREE_IMAGE_FORMAT, ByVal Message As Long) + +Dim strErrorMessage As String +Dim strImageFormat As String + + ' This function is called whenever the FreeImage 3 libraray throws an error. + ' Currently this function gets the error message and the format name of the + ' involved image type as VB string printing each to the VB Debug console. Feel + ' free to modify this function to call an error handling routine of your on. + + strErrorMessage = pGetStringFromPointerA(Message) + strImageFormat = FreeImage_GetFormatFromFIF(Format) + + Debug.Print "[FreeImage] Error: " & strErrorMessage + Debug.Print " Image: " & strImageFormat + Debug.Print " Code: " & Format + +End Sub + + + +'-------------------------------------------------------------------------------- +' String returning functions wrappers +'-------------------------------------------------------------------------------- + +Public Function FreeImage_GetVersion() As String + + ' This function returns the version of the FreeImage 3 library + ' as VB String. Read paragraph 2 of the "General notes on implementation + ' and design" section to learn more about that technique. + + FreeImage_GetVersion = pGetStringFromPointerA(FreeImage_GetVersionInt) + +End Function + +Public Function FreeImage_GetCopyrightMessage() As String + + ' This function returns the copyright message of the FreeImage 3 library + ' as VB String. Read paragraph 2 of the "General notes on implementation + ' and design" section to learn more about that technique. + + FreeImage_GetCopyrightMessage = pGetStringFromPointerA(FreeImage_GetCopyrightMessageInt) + +End Function + +Public Function FreeImage_GetFormatFromFIF(ByVal Format As FREE_IMAGE_FORMAT) As String + + ' This function returns the result of the 'FreeImage_GetFormatFromFIF' function + ' as VB String. Read paragraph 2 of the "General notes on implementation + ' and design" section to learn more about that technique. + + ' The parameter 'Format' works according to the FreeImage 3 API documentation. + + FreeImage_GetFormatFromFIF = pGetStringFromPointerA(FreeImage_GetFormatFromFIFInt(Format)) + +End Function + +Public Function FreeImage_GetFIFExtensionList(ByVal Format As FREE_IMAGE_FORMAT) As String + + ' This function returns the result of the 'FreeImage_GetFIFExtensionList' function + ' as VB String. Read paragraph 2 of the "General notes on implementation + ' and design" section to learn more about that technique. + + ' The parameter 'Format' works according to the FreeImage 3 API documentation. + + FreeImage_GetFIFExtensionList = pGetStringFromPointerA(FreeImage_GetFIFExtensionListInt(Format)) + +End Function + +Public Function FreeImage_GetFIFDescription(ByVal Format As FREE_IMAGE_FORMAT) As String + + ' This function returns the result of the 'FreeImage_GetFIFDescription' function + ' as VB String. Read paragraph 2 of the "General notes on implementation + ' and design" section to learn more about that technique. + + ' The parameter 'Format' works according to the FreeImage 3 API documentation. + + FreeImage_GetFIFDescription = pGetStringFromPointerA(FreeImage_GetFIFDescriptionInt(Format)) + +End Function + +Public Function FreeImage_GetFIFRegExpr(ByVal Format As FREE_IMAGE_FORMAT) As String + + ' This function returns the result of the 'FreeImage_GetFIFRegExpr' function + ' as VB String. Read paragraph 2 of the "General notes on implementation + ' and design" section to learn more about that technique. + + ' The parameter 'Format' works according to the FreeImage 3 API documentation. + + FreeImage_GetFIFRegExpr = pGetStringFromPointerA(FreeImage_GetFIFRegExprInt(Format)) + +End Function + +Public Function FreeImage_GetFIFMimeType(ByVal Format As FREE_IMAGE_FORMAT) As String + + ' This function returns the result of the 'FreeImage_GetFIFMimeType' function + ' as VB String. Read paragraph 2 of the "General notes on implementation + ' and design" section to learn more about that technique. + + ' The parameter 'Format' works according to the FreeImage 3 API documentation. + + FreeImage_GetFIFMimeType = pGetStringFromPointerA(FreeImage_GetFIFMimeTypeInt(Format)) + +End Function + +Public Function FreeImage_TagToString(ByVal Model As Long, _ + ByVal Tag As Long, _ + Optional ByVal Make As String) As String + + ' This function returns the result of the 'FreeImage_TagToString' function + ' as VB String. Read paragraph 2 of the "General notes on implementation + ' and design" section to learn more about that technique. + + ' All parameters work according to the FreeImage 3 API documentation. + + FreeImage_TagToString = pGetStringFromPointerA(FreeImage_TagToStringInt(Model, Tag, Make)) + +End Function + + + +'-------------------------------------------------------------------------------- +' UNICODE dealing functions wrappers +'-------------------------------------------------------------------------------- + +Public Function FreeImage_LoadU(ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Filename As String, _ + Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long + + ' This function is just a thin wrapper to ease the call to an + ' UNICODE function. Since VB's BSTR strings are actually UNICODE + ' strings, we just need to pass the pointer to the string data + ' returned by the (undocumented) function StrPtr(). + + FreeImage_LoadU = FreeImage_LoadUInt(Format, StrPtr(Filename), Flags) + +End Function + +Public Function FreeImage_SaveU(ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Bitmap As Long, _ + ByVal Filename As String, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Boolean + + ' This function is just a thin wrapper to ease the call to an + ' UNICODE function. Since VB's BSTR strings are actually UNICODE + ' strings, we just need to pass the pointer to the string data + ' returned by the (undocumented) function StrPtr(). + + FreeImage_SaveU = (FreeImage_SaveUInt(Format, Bitmap, StrPtr(Filename), Flags) = 1) + +End Function + +Public Function FreeImage_GetFileTypeU(ByVal Filename As String, _ + Optional ByVal Size As Long = 0) As FREE_IMAGE_FORMAT + + ' This function is just a thin wrapper to ease the call to an + ' UNICODE function. Since VB's BSTR strings are actually UNICODE + ' strings, we just need to pass the pointer to the string data + ' returned by the (undocumented) function StrPtr(). + + FreeImage_GetFileTypeU = FreeImage_GetFileTypeUInt(StrPtr(Filename), Size) + +End Function + +Public Function FreeImage_GetFIFFromFilenameU(ByVal Filename As String) As FREE_IMAGE_FORMAT + + ' This function is just a thin wrapper to ease the call to an + ' UNICODE function. Since VB's BSTR strings are actually UNICODE + ' strings, we just need to pass the pointer to the string data + ' returned by the (undocumented) function StrPtr(). + + FreeImage_GetFIFFromFilenameU = FreeImage_GetFIFFromFilenameUInt(StrPtr(Filename)) + +End Function + +Public Function FreeImage_JPEGTransformU(ByVal SourceFile As String, _ + ByVal DestFile As String, _ + ByVal Operation As FREE_IMAGE_JPEG_OPERATION, _ + Optional ByVal Perfect As Boolean) As Boolean + +Dim lPerfect As Long + + ' This function is just a thin wrapper to ease the call to an + ' UNICODE function. Since VB's BSTR strings are actually UNICODE + ' strings, we just need to pass the pointer to the string data + ' returned by the (undocumented) function StrPtr(). + + If (Perfect) Then + lPerfect = 1 + End If + FreeImage_JPEGTransformU = (FreeImage_JPEGTransformInt(StrPtr(SourceFile), StrPtr(DestFile), _ + Operation, lPerfect) = 1) + +End Function + +Public Function FreeImage_JPEGCropU(ByVal SourceFile As String, _ + ByVal DestFile As String, _ + ByVal Left As Long, _ + ByVal Top As Long, _ + ByVal Right As Long, _ + ByVal Bottom As Long) As Boolean + + ' This function is just a thin wrapper to ease the call to an + ' UNICODE function. Since VB's BSTR strings are actually UNICODE + ' strings, we just need to pass the pointer to the string data + ' returned by the (undocumented) function StrPtr(). + + FreeImage_JPEGCropU = (FreeImage_JPEGCropInt(StrPtr(SourceFile), StrPtr(DestFile), Left, Top, _ + Right, Bottom) = 1) + +End Function + + + +'-------------------------------------------------------------------------------- +' BOOL/Boolean returning functions wrappers +'-------------------------------------------------------------------------------- + +Public Function FreeImage_HasPixels(ByVal Bitmap As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_HasPixels = (FreeImage_HasPixelsInt(Bitmap) = 1) + +End Function + +Public Function FreeImage_Save(ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Bitmap As Long, _ + ByVal Filename As String, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_Save = (FreeImage_SaveInt(Format, Bitmap, Filename, Flags) = 1) + +End Function + +Public Function FreeImage_SaveToHandle(ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Bitmap As Long, _ + ByVal IO As Long, _ + ByVal Handle As Long, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_SaveToHandle = (FreeImage_SaveToHandleInt(Format, Bitmap, IO, Handle, Flags) = 1) + +End Function + +Public Function FreeImage_IsTransparent(ByVal Bitmap As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_IsTransparent = (FreeImage_IsTransparentInt(Bitmap) = 1) + +End Function + +Public Sub FreeImage_SetTransparent(ByVal Bitmap As Long, ByVal Value As Boolean) + + If (Value) Then + Call FreeImage_SetTransparentInt(Bitmap, 1) + Else + Call FreeImage_SetTransparentInt(Bitmap, 0) + End If + +End Sub + +Public Function FreeImage_HasBackgroundColor(ByVal Bitmap As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_HasBackgroundColor = (FreeImage_HasBackgroundColorInt(Bitmap) = 1) + +End Function + +Public Function FreeImage_GetBackgroundColor(ByVal Bitmap As Long, _ + ByRef BackColor As RGBQUAD) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_GetBackgroundColor = (FreeImage_GetBackgroundColorInt(Bitmap, BackColor) = 1) + +End Function + +Public Function FreeImage_GetBackgroundColorAsLong(ByVal Bitmap As Long, _ + ByRef BackColor As Long) As Boolean + + ' This function gets the background color of an image as FreeImage_GetBackgroundColor() does but + ' provides it's result as a Long value. + + FreeImage_GetBackgroundColorAsLong = (FreeImage_GetBackgroundColorAsLongInt(Bitmap, BackColor) = 1) + +End Function + +Public Function FreeImage_GetBackgroundColorEx(ByVal Bitmap As Long, _ + ByRef Alpha As Byte, _ + ByRef red As Byte, _ + ByRef green As Byte, _ + ByRef blue As Byte) As Boolean + +Dim bkcolor As RGBQUAD + + ' This function gets the background color of an image as FreeImage_GetBackgroundColor() does but + ' provides it's result as four different byte values, one for each color component. + + FreeImage_GetBackgroundColorEx = (FreeImage_GetBackgroundColorInt(Bitmap, bkcolor) = 1) + With bkcolor + Alpha = .rgbReserved + red = .rgbRed + green = .rgbGreen + blue = .rgbBlue + End With + +End Function + +Public Function FreeImage_SetBackgroundColor(ByVal Bitmap As Long, _ + ByRef BackColor As RGBQUAD) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_SetBackgroundColor = (FreeImage_SetBackgroundColorInt(Bitmap, BackColor) = 1) + +End Function + +Public Function FreeImage_SetBackgroundColorAsLong(ByVal Bitmap As Long, _ + ByVal BackColor As Long) As Boolean + + ' This function sets the background color of an image as FreeImage_SetBackgroundColor() does but + ' the color value to set must be provided as a Long value. + + FreeImage_SetBackgroundColorAsLong = (FreeImage_SetBackgroundColorAsLongInt(Bitmap, BackColor) = 1) + +End Function + +Public Function FreeImage_SetBackgroundColorEx(ByVal Bitmap As Long, _ + ByVal Alpha As Byte, _ + ByVal red As Byte, _ + ByVal green As Byte, _ + ByVal blue As Byte) As Boolean + +Dim tColor As RGBQUAD + + ' This function sets the color at position (x|y) as FreeImage_SetPixelColor() does but + ' the color value to set must be provided four different byte values, one for each + ' color component. + + With tColor + .rgbReserved = Alpha + .rgbRed = red + .rgbGreen = green + .rgbBlue = blue + End With + FreeImage_SetBackgroundColorEx = (FreeImage_SetBackgroundColorInt(Bitmap, tColor) = 1) + +End Function + +Public Function FreeImage_GetPixelIndex(ByVal Bitmap As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByRef Value As Byte) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_GetPixelIndex = (FreeImage_GetPixelIndexInt(Bitmap, X, Y, Value) = 1) + +End Function + +Public Function FreeImage_GetPixelColor(ByVal Bitmap As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByRef Value As RGBQUAD) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_GetPixelColor = (FreeImage_GetPixelColorInt(Bitmap, X, Y, Value) = 1) + +End Function + +Public Function FreeImage_GetPixelColorByLong(ByVal Bitmap As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByRef Value As Long) As Boolean + + ' This function gets the color at position (x|y) as FreeImage_GetPixelColor() does but + ' provides it's result as a Long value. + + FreeImage_GetPixelColorByLong = (FreeImage_GetPixelColorByLongInt(Bitmap, X, Y, Value) = 1) + +End Function + +Public Function FreeImage_GetPixelColorEx(ByVal Bitmap As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByRef Alpha As Byte, _ + ByRef red As Byte, _ + ByRef green As Byte, _ + ByRef blue As Byte) As Boolean + +Dim Value As RGBQUAD + + ' This function gets the color at position (x|y) as FreeImage_GetPixelColor() does but + ' provides it's result as four different byte values, one for each color component. + + FreeImage_GetPixelColorEx = (FreeImage_GetPixelColorInt(Bitmap, X, Y, Value) = 1) + With Value + Alpha = .rgbReserved + red = .rgbRed + green = .rgbGreen + blue = .rgbBlue + End With + +End Function + +Public Function FreeImage_SetPixelIndex(ByVal Bitmap As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByRef Value As Byte) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_SetPixelIndex = (FreeImage_SetPixelIndexInt(Bitmap, X, Y, Value) = 1) + +End Function + +Public Function FreeImage_SetPixelColor(ByVal Bitmap As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByRef Value As RGBQUAD) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_SetPixelColor = (FreeImage_SetPixelColorInt(Bitmap, X, Y, Value) = 1) + +End Function + +Public Function FreeImage_SetPixelColorByLong(ByVal Bitmap As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByRef Value As Long) As Boolean + + ' This function sets the color at position (x|y) as FreeImage_SetPixelColor() does but + ' the color value to set must be provided as a Long value. + + FreeImage_SetPixelColorByLong = (FreeImage_SetPixelColorByLongInt(Bitmap, X, Y, Value) = 1) + +End Function + +Public Function FreeImage_SetPixelColorEx(ByVal Bitmap As Long, _ + ByVal X As Long, _ + ByVal Y As Long, _ + ByVal Alpha As Byte, _ + ByVal red As Byte, _ + ByVal green As Byte, _ + ByVal blue As Byte) As Boolean + +Dim Value As RGBQUAD + + ' This function sets the color at position (x|y) as FreeImage_SetPixelColor() does but + ' the color value to set must be provided four different byte values, one for each + ' color component. + + With Value + .rgbReserved = Alpha + .rgbRed = red + .rgbGreen = green + .rgbBlue = blue + End With + FreeImage_SetPixelColorEx = (FreeImage_SetPixelColorInt(Bitmap, X, Y, Value) = 1) + +End Function + +Public Function FreeImage_FIFSupportsReading(ByVal Format As FREE_IMAGE_FORMAT) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_FIFSupportsReading = (FreeImage_FIFSupportsReadingInt(Format) = 1) + +End Function + +Public Function FreeImage_FIFSupportsWriting(ByVal Format As FREE_IMAGE_FORMAT) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_FIFSupportsWriting = (FreeImage_FIFSupportsWritingInt(Format) = 1) + +End Function + +Public Function FreeImage_FIFSupportsExportType(ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal ImageType As FREE_IMAGE_TYPE) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_FIFSupportsExportType = (FreeImage_FIFSupportsExportTypeInt(Format, ImageType) = 1) + +End Function + +Public Function FreeImage_FIFSupportsExportBPP(ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal BitsPerPixel As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_FIFSupportsExportBPP = (FreeImage_FIFSupportsExportBPPInt(Format, BitsPerPixel) = 1) + +End Function + +Public Function FreeImage_FIFSupportsICCProfiles(ByVal Format As FREE_IMAGE_FORMAT) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_FIFSupportsICCProfiles = (FreeImage_FIFSupportsICCProfilesInt(Format) = 1) + +End Function + +Public Function FreeImage_FIFSupportsNoPixels(ByVal Format As FREE_IMAGE_FORMAT) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_FIFSupportsNoPixels = (FreeImage_FIFSupportsNoPixelsInt(Format) = 1) + +End Function + +Public Function FreeImage_CloseMultiBitmap(ByVal Bitmap As Long, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_CloseMultiBitmap = (FreeImage_CloseMultiBitmapInt(Bitmap, Flags) = 1) + +End Function + +Public Function FreeImage_MovePage(ByVal Bitmap As Long, _ + ByVal TargetPage As Long, _ + ByVal SourcePage As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_MovePage = (FreeImage_MovePageInt(Bitmap, TargetPage, SourcePage) = 1) + +End Function + +Public Function FreeImage_GetLockedPageNumbers(ByVal Bitmap As Long, _ + ByRef PagesPtr As Long, _ + ByRef Count As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_GetLockedPageNumbers = (FreeImage_GetLockedPageNumbersInt(Bitmap, PagesPtr, Count) = 1) + +End Function + +Public Function FreeImage_SaveToMemory(ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Bitmap As Long, _ + ByVal Stream As Long, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_SaveToMemory = (FreeImage_SaveToMemoryInt(Format, Bitmap, Stream, Flags) = 1) + +End Function + +Public Function FreeImage_AcquireMemory(ByVal Stream As Long, _ + ByRef DataPtr As Long, _ + ByRef SizeInBytes As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_AcquireMemory = (FreeImage_AcquireMemoryInt(Stream, DataPtr, SizeInBytes) = 1) + +End Function + +Public Function FreeImage_SeekMemory(ByVal Stream As Long, _ + ByVal Offset As Long, _ + ByVal Origin As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_SeekMemory = (FreeImage_SeekMemoryInt(Stream, Offset, Origin) = 1) + +End Function + +Public Function FreeImage_IsLittleEndian() As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_IsLittleEndian = (FreeImage_IsLittleEndianInt() = 1) + +End Function + +Public Function FreeImage_LookupX11Color(ByVal Color As String, _ + ByRef red As Long, _ + ByRef green As Long, _ + ByRef blue As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_LookupX11Color = (FreeImage_LookupX11ColorInt(Color, red, green, blue) = 1) + +End Function + +Public Function FreeImage_LookupSVGColor(ByVal Color As String, _ + ByRef red As Long, _ + ByRef green As Long, _ + ByRef blue As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_LookupSVGColor = (FreeImage_LookupSVGColorInt(Color, red, green, blue) = 1) + +End Function + +Public Function FreeImage_FindNextMetadata(ByVal hFind As Long, _ + ByRef Tag As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_FindNextMetadata = (FreeImage_FindNextMetadataInt(hFind, Tag) = 1) + +End Function + +Public Function FreeImage_CloneMetadata(ByVal BitmapDst As Long, _ + ByVal BitmapSrc As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_CloneMetadata = (FreeImage_CloneMetadataInt(BitmapDst, BitmapSrc) = 1) + +End Function + +Public Function FreeImage_GetMetadata(ByRef Model As Long, _ + ByVal Bitmap As Long, _ + ByVal Key As String, _ + ByVal Tag As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_GetMetadata = (FreeImage_GetMetadataInt(Model, Bitmap, Key, Tag) = 1) + +End Function + +Public Function FreeImage_SetMetadata(ByRef Model As Long, _ + ByVal Bitmap As Long, _ + ByVal Key As String, _ + ByVal Tag As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_SetMetadata = (FreeImage_SetMetadataInt(Model, Bitmap, Key, Tag) = 1) + +End Function + +Public Function FreeImage_FlipHorizontal(ByVal Bitmap As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_FlipHorizontal = (FreeImage_FlipHorizontalInt(Bitmap) = 1) + +End Function + +Public Function FreeImage_FlipVertical(ByVal Bitmap As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_FlipVertical = (FreeImage_FlipVerticalInt(Bitmap) = 1) + +End Function + +Public Function FreeImage_JPEGTransform(ByVal SourceFile As String, _ + ByVal DestFile As String, _ + ByVal Operation As FREE_IMAGE_JPEG_OPERATION, _ + Optional ByVal Perfect As Boolean) As Boolean + +Dim lPerfect As Long + + ' Thin wrapper function returning a real VB Boolean value + + If (Perfect) Then + lPerfect = 1 + End If + FreeImage_JPEGTransform = (FreeImage_JPEGTransformInt(SourceFile, DestFile, Operation, lPerfect) = 1) + +End Function + +Public Function FreeImage_AdjustCurve(ByVal Bitmap As Long, _ + ByVal LookupTablePtr As Long, _ + ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_AdjustCurve = (FreeImage_AdjustCurveInt(Bitmap, LookupTablePtr, Channel) = 1) + +End Function + +Public Function FreeImage_AdjustGamma(ByVal Bitmap As Long, _ + ByVal Gamma As Double) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_AdjustGamma = (FreeImage_AdjustGammaInt(Bitmap, Gamma) = 1) + +End Function + +Public Function FreeImage_AdjustBrightness(ByVal Bitmap As Long, _ + ByVal Percentage As Double) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_AdjustBrightness = (FreeImage_AdjustBrightnessInt(Bitmap, Percentage) = 1) + +End Function + +Public Function FreeImage_AdjustContrast(ByVal Bitmap As Long, _ + ByVal Percentage As Double) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_AdjustContrast = (FreeImage_AdjustContrastInt(Bitmap, Percentage) = 1) + +End Function + +Public Function FreeImage_Invert(ByVal Bitmap As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_Invert = (FreeImage_InvertInt(Bitmap) = 1) + +End Function + +Public Function FreeImage_GetHistogram(ByVal Bitmap As Long, _ + ByRef HistogramPtr As Long, _ + Optional ByVal Channel As FREE_IMAGE_COLOR_CHANNEL = FICC_BLACK) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_GetHistogram = (FreeImage_GetHistogramInt(Bitmap, HistogramPtr, Channel) = 1) + +End Function + +Public Function FreeImage_AdjustColors(ByVal Bitmap As Long, _ + Optional ByVal Brightness As Double, _ + Optional ByVal Contrast As Double, _ + Optional ByVal Gamma As Double = 1, _ + Optional ByVal Invert As Boolean) As Boolean + +Dim lInvert As Long + + ' Thin wrapper function returning a real VB Boolean value + If (Invert) Then + lInvert = 1 + End If + FreeImage_AdjustColors = (FreeImage_AdjustColorsInt(Bitmap, Brightness, Contrast, Gamma, lInvert) = 1) + +End Function + +Public Function FreeImage_SetChannel(ByVal BitmapDst As Long, _ + ByVal BitmapSrc As Long, _ + ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_SetChannel = (FreeImage_SetChannelInt(BitmapDst, BitmapSrc, Channel) = 1) + +End Function + +Public Function FreeImage_SetComplexChannel(ByVal BitmapDst As Long, _ + ByVal BitmapSrc As Long, _ + ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_SetComplexChannel = (FreeImage_SetComplexChannelInt(BitmapDst, BitmapSrc, Channel) = 1) + +End Function + +Public Function FreeImage_Paste(ByVal BitmapDst As Long, _ + ByVal BitmapSrc As Long, _ + ByVal Left As Long, _ + ByVal Top As Long, _ + ByVal Alpha As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_Paste = (FreeImage_PasteInt(BitmapDst, BitmapSrc, Left, Top, Alpha) = 1) + +End Function + +Public Function FreeImage_PreMultiplyWithAlpha(ByVal Bitmap As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_PreMultiplyWithAlpha = (FreeImage_PreMultiplyWithAlphaInt(Bitmap) = 1) + +End Function + +Public Function FreeImage_JPEGCrop(ByVal SourceFile As String, _ + ByVal DestFile As String, _ + ByVal Left As Long, _ + ByVal Top As Long, _ + ByVal Right As Long, _ + ByVal Bottom As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_JPEGCrop = (FreeImage_JPEGCropInt(SourceFile, DestFile, Left, Top, Right, Bottom) = 1) + +End Function + +Public Function FreeImage_FillBackgroundEx(ByVal Bitmap As Long, _ + ByRef Color As RGBQUAD, _ + Optional ByVal Options As FREE_IMAGE_COLOR_OPTIONS) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_FillBackgroundEx = (FreeImage_FillBackground(Bitmap, Color, Options) = 1) + +End Function + +Public Function FreeImage_FillBackgroundByLong(ByVal Bitmap As Long, _ + ByRef Color As Long, _ + Optional ByVal Options As FREE_IMAGE_COLOR_OPTIONS) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_FillBackgroundByLong = (FreeImage_FillBackground(Bitmap, Color, Options) = 1) + +End Function + +Public Function FreeImage_SetThumbnail(ByVal Bitmap As Long, ByVal Thumbnail As Long) As Boolean + + ' Thin wrapper function returning a real VB Boolean value + + FreeImage_SetThumbnail = (FreeImage_SetThumbnailInt(Bitmap, Thumbnail) = 1) + +End Function + + +Public Function FreeImage_OpenMultiBitmap(ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Filename As String, _ + Optional ByVal CreateNew As Boolean, _ + Optional ByVal ReadOnly As Boolean, _ + Optional ByVal KeepCacheInMemory As Boolean, _ + Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS) As Long + + FreeImage_OpenMultiBitmap = FreeImage_OpenMultiBitmapInt(Format, Filename, IIf(CreateNew, 1, 0), _ + IIf(ReadOnly And Not CreateNew, 1, 0), IIf(KeepCacheInMemory, 1, 0), Flags) + +End Function + +Public Sub FreeImage_UnlockPage(ByVal Bitmap As Long, ByVal PageBitmap As Long, ByVal ApplyChanges As Boolean) + +Dim lApplyChanges As Long + + If (ApplyChanges) Then + lApplyChanges = 1 + End If + Call FreeImage_UnlockPageInt(Bitmap, PageBitmap, lApplyChanges) + +End Sub + +Public Function FreeImage_RotateEx(ByVal Bitmap As Long, _ + ByVal Angle As Double, _ + Optional ByVal ShiftX As Double, _ + Optional ByVal ShiftY As Double, _ + Optional ByVal OriginX As Double, _ + Optional ByVal OriginY As Double, _ + Optional ByVal UseMask As Boolean) As Long + +Dim lUseMask As Long + + If (UseMask) Then + lUseMask = 1 + End If + FreeImage_RotateEx = FreeImage_RotateExInt(Bitmap, Angle, ShiftX, ShiftY, OriginX, OriginY, lUseMask) + +End Function + +Public Function FreeImage_MakeThumbnail(ByVal Bitmap As Long, _ + ByVal MaxPixelSize As Long, _ + Optional ByVal Convert As Boolean) As Long + +Dim lConvert As Long + + If (Convert) Then + lConvert = 1 + End If + FreeImage_MakeThumbnail = FreeImage_MakeThumbnailInt(Bitmap, MaxPixelSize, lConvert) + +End Function + +Public Function FreeImage_GetAdjustColorsLookupTable(ByVal LookupTablePtr As Long, _ + Optional ByVal Brightness As Double, _ + Optional ByVal Contrast As Double, _ + Optional ByVal Gamma As Double, _ + Optional ByVal Invert As Boolean) As Long + +Dim lInvert As Long + + If (Invert) Then + lInvert = 1 + End If + FreeImage_GetAdjustColorsLookupTable = FreeImage_GetAdjustColorsLookupTableInt(LookupTablePtr, _ + Brightness, Contrast, Gamma, lInvert) + +End Function + +Public Function FreeImage_ApplyColorMapping(ByVal Bitmap As Long, _ + ByVal SourceColorsPtr As Long, _ + ByVal DestinationColorsPtr As Long, _ + ByVal Count As Long, _ + Optional ByVal IgnoreAlpha As Boolean = True, _ + Optional ByVal swap As Boolean) As Long + +Dim lIgnoreAlpha As Long +Dim lSwap As Long + + If (IgnoreAlpha) Then + lIgnoreAlpha = 1 + End If + If (swap) Then + lSwap = 1 + End If + FreeImage_ApplyColorMapping = FreeImage_ApplyColorMappingInt(Bitmap, SourceColorsPtr, _ + DestinationColorsPtr, Count, lIgnoreAlpha, lSwap) + +End Function + +Public Function FreeImage_SwapColors(ByVal Bitmap As Long, _ + ByRef ColorA As RGBQUAD, _ + ByRef ColorB As RGBQUAD, _ + Optional ByVal IgnoreAlpha As Boolean = True) As Long + +Dim lIgnoreAlpha As Long + + If (IgnoreAlpha) Then + lIgnoreAlpha = 1 + End If + FreeImage_SwapColors = FreeImage_SwapColorsInt(Bitmap, ColorA, ColorB, lIgnoreAlpha) + +End Function + +Public Function FreeImage_SwapColorsByLong(ByVal Bitmap As Long, _ + ByRef ColorA As Long, _ + ByRef ColorB As Long, _ + Optional ByVal IgnoreAlpha As Boolean = True) As Long + +Dim lIgnoreAlpha As Long + + If (IgnoreAlpha) Then + lIgnoreAlpha = 1 + End If + FreeImage_SwapColorsByLong = FreeImage_SwapColorsByLongInt(Bitmap, ColorA, ColorB, _ + lIgnoreAlpha) + +End Function + +Public Function FreeImage_ApplyIndexMapping(ByVal Bitmap As Long, _ + ByVal SourceIndicesPtr As Long, _ + ByVal DestinationIndicesPtr As Long, _ + ByVal Count As Long, _ + Optional ByVal swap As Boolean) As Long + +Dim lSwap As Long + + If (swap) Then + lSwap = 1 + End If + FreeImage_ApplyIndexMapping = FreeImage_ApplyIndexMappingInt(Bitmap, SourceIndicesPtr, _ + DestinationIndicesPtr, Count, lSwap) + +End Function + +Public Function FreeImage_ConvertFromRawBits(ByVal BitsPtr As Long, _ + ByVal Width As Long, _ + ByVal Height As Long, _ + ByVal Pitch As Long, _ + ByVal BitsPerPixel As Long, _ + Optional ByVal RedMask As Long, _ + Optional ByVal GreenMask As Long, _ + Optional ByVal BlueMask As Long, _ + Optional ByVal TopDown As Boolean) As Long + +Dim lTopDown As Long + + If (TopDown) Then + lTopDown = 1 + End If + FreeImage_ConvertFromRawBits = FreeImage_ConvertFromRawBitsInt(BitsPtr, Width, Height, Pitch, _ + BitsPerPixel, RedMask, GreenMask, BlueMask, lTopDown) + +End Function + +Public Sub FreeImage_ConvertToRawBits(ByVal BitsPtr As Long, _ + ByVal Bitmap As Long, _ + ByVal Pitch As Long, _ + ByVal BitsPerPixel As Long, _ + Optional ByVal RedMask As Long, _ + Optional ByVal GreenMask As Long, _ + Optional ByVal BlueMask As Long, _ + Optional ByVal TopDown As Boolean) + +Dim lTopDown As Long + + If (TopDown) Then + lTopDown = 1 + End If + Call FreeImage_ConvertToRawBitsInt(BitsPtr, Bitmap, Pitch, _ + BitsPerPixel, RedMask, GreenMask, BlueMask, lTopDown) + +End Sub + +Public Function FreeImage_ConvertToStandardType(ByVal Bitmap As Long, _ + Optional ByVal ScaleLinear As Boolean = True) As Long + + If (ScaleLinear) Then + FreeImage_ConvertToStandardType = FreeImage_ConvertToStandardTypeInt(Bitmap, 1) + Else + FreeImage_ConvertToStandardType = FreeImage_ConvertToStandardTypeInt(Bitmap, 0) + End If + +End Function + +Public Function FreeImage_ConvertToType(ByVal Bitmap As Long, _ + ByVal DestinationType As FREE_IMAGE_TYPE, _ + Optional ByVal ScaleLinear As Boolean = True) As Long + + If (ScaleLinear) Then + FreeImage_ConvertToType = FreeImage_ConvertToTypeInt(Bitmap, DestinationType, 1) + Else + FreeImage_ConvertToType = FreeImage_ConvertToTypeInt(Bitmap, DestinationType, 0) + End If + +End Function + + + +'-------------------------------------------------------------------------------- +' Color conversion helper functions +'-------------------------------------------------------------------------------- + +Public Function ConvertColor(ByVal Color As Long) As Long + + ' This helper function converts a VB-style color value (like vbRed), which + ' uses the ABGR format into a RGBQUAD compatible color value, using the ARGB + ' format, needed by FreeImage and vice versa. + + ConvertColor = ((Color And &HFF000000) Or _ + ((Color And &HFF&) * &H10000) Or _ + ((Color And &HFF00&)) Or _ + ((Color And &HFF0000) \ &H10000)) + +End Function + +Public Function ConvertOleColor(ByVal Color As OLE_COLOR) As Long + + ' This helper function converts an OLE_COLOR value (like vbButtonFace), which + ' uses the BGR format into a RGBQUAD compatible color value, using the ARGB + ' format, needed by FreeImage. + + ' This function generally ingnores the specified color's alpha value but, in + ' contrast to ConvertColor, also has support for system colors, which have the + ' format &H80bbggrr. + + ' You should not use this function to convert any color provided by FreeImage + ' in ARGB format into a VB-style ABGR color value. Use function ConvertColor + ' instead. + +Dim lColorRef As Long + + If (OleTranslateColor(Color, 0, lColorRef) = 0) Then + ConvertOleColor = ConvertColor(lColorRef) + End If + +End Function + + + +'-------------------------------------------------------------------------------- +' Extended functions derived from FreeImage 3 functions usually dealing +' with arrays +'-------------------------------------------------------------------------------- + +Public Sub FreeImage_UnloadEx(ByRef Bitmap As Long) + + ' Extended version of FreeImage_Unload, which additionally sets the + ' passed Bitmap handle to zero after unloading. + + If (Bitmap <> 0) Then + Call FreeImage_Unload(Bitmap) + Bitmap = 0 + End If + +End Sub + +Public Function FreeImage_GetPaletteEx(ByVal Bitmap As Long) As RGBQUAD() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long + + ' This function returns a VB style array of type RGBQUAD, containing + ' the palette data of the Bitmap. This array provides read and write access + ' to the actual palette data provided by FreeImage. This is done by + ' creating a VB array with an own SAFEARRAY descriptor making the + ' array point to the palette pointer returned by FreeImage_GetPalette(). + + ' This makes you use code like you would in C/C++: + + ' // this code assumes there is a bitmap loaded and + ' // present in a variable called ‘dib’ + ' if(FreeImage_GetBPP(Bitmap) == 8) { + ' // Build a greyscale palette + ' RGBQUAD *pal = FreeImage_GetPalette(Bitmap); + ' for (int i = 0; i < 256; i++) { + ' pal[i].rgbRed = i; + ' pal[i].rgbGreen = i; + ' pal[i].rgbBlue = i; + ' } + + ' As in C/C++ the array is only valid while the DIB is loaded and the + ' palette data remains where the pointer returned by FreeImage_GetPalette + ' has pointed to when this function was called. So, a good thing would + ' be, not to keep the returned array in scope over the lifetime of the + ' Bitmap. Best practise is, to use this function within another routine and + ' assign the return value (the array) to a local variable only. As soon + ' as this local variable goes out of scope (when the calling function + ' returns to it's caller), the array and the descriptor is automatically + ' cleaned up by VB. + + ' This function does not make a deep copy of the palette data, but only + ' wraps a VB array around the FreeImage palette data. So, it can be called + ' frequently "on demand" or somewhat "in place" without a significant + ' performance loss. + + ' To learn more about this technique I recommend reading chapter 2 (Leveraging + ' Arrays) of Matthew Curland's book "Advanced Visual Basic 6" + + ' The parameter 'Bitmap' works according to the FreeImage 3 API documentation. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the FreeImage_DestroyLockedArrayRGBQUAD() function. + + + If (Bitmap) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 4 ' size in bytes of RGBQUAD structure + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetColorsUsed(Bitmap) ' the number of elements in the array is + ' the number of used colors in the Bitmap + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetPalette(Bitmap) ' let the array point to the memory block, the + ' FreeImage palette pointer points to + End With + + ' allocate memory for an array descriptor + ' we cannot use the memory block used by tSA, since it is + ' released when tSA goes out of scope, leaving us with an + ' array with zeroed descriptor + ' we use nearly the same method that VB uses, so VB is able + ' to cleanup the array variable and it's descriptor; the + ' array data is not touched when cleaning up, since both AUTO + ' and FIXEDSIZE flags are set + Call SafeArrayAllocDescriptor(1, lpSA) + + ' copy our own array descriptor over the descriptor allocated + ' by SafeArrayAllocDescriptor; lpSA is a pointer to that memory + ' location + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + + ' the implicit variable named as the function is an array variable in VB + ' make it point to the allocated array descriptor + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetPaletteEx), lpSA, 4) + End If + +End Function + +Public Function FreeImage_GetPaletteExClone(ByVal Bitmap As Long) As RGBQUAD() + +Dim lColors As Long +Dim atPal() As RGBQUAD + + ' This function returns a redundant clone of a Bitmap's palette as a + ' VB style array of type RGBQUAD. + + ' The parameter 'Bitmap' works according to the FreeImage 3 API documentation. + + lColors = FreeImage_GetColorsUsed(Bitmap) + If (lColors > 0) Then + ReDim atPal(lColors - 1) + Call CopyMemory(atPal(0), ByVal FreeImage_GetPalette(Bitmap), lColors * 4) + Call pSwap(ByVal VarPtrArray(atPal), ByVal VarPtrArray(FreeImage_GetPaletteExClone)) + End If + +End Function + +Public Function FreeImage_GetPaletteExLong(ByVal Bitmap As Long) As Long() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long + + ' This function returns a VB style array of type Long, containing + ' the palette data of the Bitmap. This array provides read and write access + ' to the actual palette data provided by FreeImage. This is done by + ' creating a VB array with an own SAFEARRAY descriptor making the + ' array point to the palette pointer returned by FreeImage_GetPalette(). + + ' The function actually returns an array of type RGBQUAD with each + ' element packed into a Long. This is possible, since the RGBQUAD + ' structure is also four bytes in size. Palette data, stored in an + ' array of type Long may be passed ByRef to a function through an + ' optional paremeter. For an example have a look at function + ' FreeImage_ConvertColorDepth() + + ' This makes you use code like you would in C/C++: + + ' // this code assumes there is a bitmap loaded and + ' // present in a variable called ‘dib’ + ' if(FreeImage_GetBPP(Bitmap) == 8) { + ' // Build a greyscale palette + ' RGBQUAD *pal = FreeImage_GetPalette(Bitmap); + ' for (int i = 0; i < 256; i++) { + ' pal[i].rgbRed = i; + ' pal[i].rgbGreen = i; + ' pal[i].rgbBlue = i; + ' } + + ' As in C/C++ the array is only valid while the DIB is loaded and the + ' palette data remains where the pointer returned by FreeImage_GetPalette() + ' has pointed to when this function was called. So, a good thing would + ' be, not to keep the returned array in scope over the lifetime of the + ' Bitmap. Best practise is, to use this function within another routine and + ' assign the return value (the array) to a local variable only. As soon + ' as this local variable goes out of scope (when the calling function + ' returns to it's caller), the array and the descriptor is automatically + ' cleaned up by VB. + + ' This function does not make a deep copy of the palette data, but only + ' wraps a VB array around the FreeImage palette data. So, it can be called + ' frequently "on demand" or somewhat "in place" without a significant + ' performance loss. + + ' To learn more about this technique I recommend reading chapter 2 (Leveraging + ' Arrays) of Matthew Curland's book "Advanced Visual Basic 6" + + ' The parameter 'Bitmap' works according to the FreeImage 3 API documentation. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArray' function. + + + If (Bitmap) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 4 ' size in bytes of RGBQUAD structure + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetColorsUsed(Bitmap) ' the number of elements in the array is + ' the number of used colors in the Bitmap + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetPalette(Bitmap) ' let the array point to the memory block, the + ' FreeImage palette pointer points to + End With + + ' allocate memory for an array descriptor + ' we cannot use the memory block used by tSA, since it is + ' released when tSA goes out of scope, leaving us with an + ' array with zeroed descriptor + ' we use nearly the same method that VB uses, so VB is able + ' to cleanup the array variable and it's descriptor; the + ' array data is not touched when cleaning up, since both AUTO + ' and FIXEDSIZE flags are set + Call SafeArrayAllocDescriptor(1, lpSA) + + ' copy our own array descriptor over the descriptor allocated + ' by SafeArrayAllocDescriptor; lpSA is a pointer to that memory + ' location + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + + ' the implicit variable named as the function is an array variable in VB + ' make it point to the allocated array descriptor + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetPaletteExLong), lpSA, 4) + End If + +End Function + +Public Function FreeImage_GetPaletteExLongClone(ByVal Bitmap As Long) As Long() + +Dim lColors As Long +Dim alPal() As Long + + ' This function returns a redundant clone of a Bitmap's palette as a + ' VB style array of type Long. + + ' The parameter 'Bitmap' works according to the FreeImage 3 API documentation. + + lColors = FreeImage_GetColorsUsed(Bitmap) + If (lColors > 0) Then + ReDim alPal(lColors - 1) + Call CopyMemory(alPal(0), ByVal FreeImage_GetPalette(Bitmap), lColors * 4) + Call pSwap(ByVal VarPtrArray(alPal), ByVal VarPtrArray(FreeImage_GetPaletteExLongClone)) + End If + +End Function + +Public Function FreeImage_SetPalette(ByVal Bitmap As Long, ByRef Palette() As RGBQUAD) As Long + + ' This function sets the palette of a palletised bitmap using a RGBQUAD array. Does + ' nothing on high color bitmaps. + + ' This operation makes a deep copy of the provided palette data so, after this function + ' has returned, changes to the RGBQUAD array are no longer reflected by the bitmap's + ' palette. + + FreeImage_SetPalette = FreeImage_GetColorsUsed(Bitmap) + If (FreeImage_SetPalette > 0) Then + Call CopyMemory(ByVal FreeImage_GetPalette(Bitmap), Palette(0), FreeImage_SetPalette * 4) + End If + +End Function + +Public Function FreeImage_SetPaletteLong(ByVal Bitmap As Long, ByRef Palette() As Long) As Long + + ' This function sets the palette of a palletised bitmap using a RGBQUAD array. Does + ' nothing on high color bitmaps. + + ' This operation makes a deep copy of the provided palette data so, after this function + ' has returned, changes to the Long array are no longer reflected by the bitmap's + ' palette. + + FreeImage_SetPaletteLong = FreeImage_GetColorsUsed(Bitmap) + If (FreeImage_SetPaletteLong > 0) Then + Call CopyMemory(ByVal FreeImage_GetPalette(Bitmap), Palette(0), FreeImage_SetPaletteLong * 4) + End If + +End Function + +Public Function FreeImage_GetTransparencyTableEx(ByVal Bitmap As Long) As Byte() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long + + ' This function returns a VB style Byte array, containing the transparency + ' table of the Bitmap. This array provides read and write access to the actual + ' transparency table provided by FreeImage. This is done by creating a VB array + ' with an own SAFEARRAY descriptor making the array point to the transparency + ' table pointer returned by FreeImage_GetTransparencyTable(). + + ' This makes you use code like you would in C/C++: + + ' // this code assumes there is a bitmap loaded and + ' // present in a variable called ‘dib’ + ' if(FreeImage_GetBPP(Bitmap) == 8) { + ' // Remove transparency information + ' byte *transt = FreeImage_GetTransparencyTable(Bitmap); + ' for (int i = 0; i < 256; i++) { + ' transt[i].rgbRed = 255; + ' } + + ' As in C/C++ the array is only valid while the DIB is loaded and the transparency + ' table remains where the pointer returned by FreeImage_GetTransparencyTable() has + ' pointed to when this function was called. So, a good thing would be, not to keep + ' the returned array in scope over the lifetime of the DIB. Best practise is, to use + ' this function within another routine and assign the return value (the array) to a + ' local variable only. As soon as this local variable goes out of scope (when the + ' calling function returns to it's caller), the array and the descriptor is + ' automatically cleaned up by VB. + + ' This function does not make a deep copy of the transparency table, but only + ' wraps a VB array around the FreeImage transparency table. So, it can be called + ' frequently "on demand" or somewhat "in place" without a significant + ' performance loss. + + ' To learn more about this technique I recommend reading chapter 2 (Leveraging + ' Arrays) of Matthew Curland's book "Advanced Visual Basic 6" + + ' The parameter 'Bitmap' works according to the FreeImage 3 API documentation. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the FreeImage_DestroyLockedArray() function. + + + If (Bitmap) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 1 ' size in bytes of a byte element + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetTransparencyCount(Bitmap) ' the number of elements in the array is + ' equal to the number transparency table entries + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetTransparencyTable(Bitmap) ' let the array point to the memory block, the + ' FreeImage transparency table pointer points to + End With + + ' allocate memory for an array descriptor + ' we cannot use the memory block used by tSA, since it is + ' released when tSA goes out of scope, leaving us with an + ' array with zeroed descriptor + ' we use nearly the same method that VB uses, so VB is able + ' to cleanup the array variable and it's descriptor; the + ' array data is not touched when cleaning up, since both AUTO + ' and FIXEDSIZE flags are set + Call SafeArrayAllocDescriptor(1, lpSA) + + ' copy our own array descriptor over the descriptor allocated + ' by SafeArrayAllocDescriptor(); lpSA is a pointer to that memory + ' location + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + + ' the implicit variable named as the function is an array variable in VB + ' make it point to the allocated array descriptor + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetTransparencyTableEx), lpSA, 4) + End If + +End Function + +Public Function FreeImage_GetTransparencyTableExClone(ByVal Bitmap As Long) As Byte() + +Dim abBuffer() As Byte +Dim lpTransparencyTable As Long +Dim lEntries As Long + + ' This function returns a copy of a DIB's transparency table as VB style + ' array of type Byte. So, the array provides read access only from the DIB's + ' point of view. + + ' The parameter 'Bitmap' works according to the FreeImage 3 API documentation. + + lpTransparencyTable = FreeImage_GetTransparencyTable(Bitmap) + If (lpTransparencyTable) Then + lEntries = FreeImage_GetTransparencyCount(Bitmap) + If (lEntries > 0) Then + ReDim abBuffer(lEntries - 1) + Call CopyMemory(abBuffer(0), ByVal lpTransparencyTable, lEntries) + Call pSwap(ByVal VarPtrArray(abBuffer), ByVal VarPtrArray( _ + FreeImage_GetTransparencyTableExClone)) + End If + End If + +End Function + +Public Sub FreeImage_SetTransparencyTableEx(ByVal Bitmap As Long, _ + ByRef Table() As Byte, _ + Optional ByRef Count As Long = -1) + + ' This function sets a DIB's transparency table to the contents of the + ' parameter table(). When the optional parameter Count is omitted, the + ' number of entries used is taken from the number of elements stored in + ' the array, but will never be never greater than 256. + + ' The parameter 'Bitmap' works according to the FreeImage 3 API documentation. + + If ((Count > UBound(Table) + 1) Or _ + (Count < 0)) Then + Count = UBound(Table) + 1 + End If + + If (Count > 256) Then + Count = 256 + End If + + Call FreeImage_SetTransparencyTable(Bitmap, VarPtr(Table(0)), Count) + +End Sub + +Public Function FreeImage_IsTransparencyTableTransparent(ByVal Bitmap As Long) As Boolean + +Dim abTransTable() As Byte +Dim i As Long + + ' This function checks whether a Bitmap's transparency table contains any transparent + ' colors or not. + + ' When an image has a transparency table and is transparent, what can be tested + ' with 'FreeImage_IsTransparent()', the image still may display opaque when there + ' are no transparent colors defined in the image's transparency table. This + ' function reads the Bitmap's transparency table directly to determine whether + ' there are transparent colors defined or not. + + ' The return value of this function does not relay on the image's transparency + ' setting but only on the image's transparency table + + If (Bitmap) Then + abTransTable = FreeImage_GetTransparencyTableEx(Bitmap) + For i = 0 To UBound(abTransTable) + FreeImage_IsTransparencyTableTransparent = (abTransTable(i) < 255) + If (FreeImage_IsTransparencyTableTransparent) Then + Exit For + End If + Next i + End If + +End Function + +Public Function FreeImage_GetAdjustColorsLookupTableEx(ByRef LookupTable() As Byte, _ + Optional ByVal Brightness As Double, _ + Optional ByVal Contrast As Double, _ + Optional ByVal Gamma As Double = 1, _ + Optional ByVal Invert As Boolean) As Long + + ' This function is an extended wrapper for FreeImage_GetAdjustColorsLookupTable(), which + ' takes a real VB style Byte array LUT() to receive the created lookup table. The LUT() + ' parameter must not be fixed sized or locked, since it is (re-)dimensioned in this + ' function to contain 256 entries. + + ' All parameters work according to the FreeImage 3 API documentation. + + ReDim LookupTable(255) + FreeImage_GetAdjustColorsLookupTableEx = _ + FreeImage_GetAdjustColorsLookupTable(VarPtr(LookupTable(0)), Brightness, Contrast, _ + Gamma, Invert) + +End Function + +Public Function FreeImage_ApplyColorMappingEx(ByVal Bitmap As Long, _ + ByRef SourceColors() As RGBQUAD, _ + ByRef DestinationColors() As RGBQUAD, _ + Optional ByRef Count As Long = -1, _ + Optional ByVal IgnoreAlpha As Boolean = True, _ + Optional ByVal swap As Boolean) As Long + +Dim nsrc As Long +Dim ndst As Long + + ' This function is an extended wrapper for FreeImage_ApplyColorMapping(), which takes + ' real VB style RGBQUAD arrays for source and destination colors along with an optional + ' ByRef Count parameter. + + ' If 'Count' is omitted upon entry, the number of entries of the smaller of both arrays + ' is used for 'Count' and also passed back to the caller, due to this parameter's ByRef + ' nature. + + ' All other parameters work according to the FreeImage 3 API documentation. + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to map colors on a 'header-only' bitmap.") + End If + + nsrc = UBound(SourceColors) + 1 + ndst = UBound(DestinationColors) + 1 + If (Count = -1) Then + If (nsrc < ndst) Then + Count = nsrc + Else + Count = ndst + End If + Else + If (Count < nsrc) Then + Count = nsrc + End If + If (Count < ndst) Then + Count = ndst + End If + End If + + FreeImage_ApplyColorMappingEx = FreeImage_ApplyColorMapping(Bitmap, _ + VarPtr(SourceColors(0)), VarPtr(DestinationColors(0)), Count, IgnoreAlpha, swap) + End If + +End Function + +Public Function FreeImage_ApplyIndexMappingEx(ByVal Bitmap As Long, _ + ByRef SourceIndices() As Byte, _ + ByRef DestinationIndices() As Byte, _ + Optional ByRef Count As Long = -1, _ + Optional ByVal swap As Boolean) As Long + +Dim nsrc As Long +Dim ndst As Long + + ' This function is an extended wrapper for FreeImage_ApplyIndexMapping(), which takes + ' real VB style Byte arrays for source and destination indices along with an optional + ' ByRef count parameter. + + ' If 'Count' is omitted upon entry, the number of entries of the smaller of both arrays + ' is used for 'Count' and also passed back to the caller, due to this parameter's ByRef + ' nature. + + ' All other parameters work according to the FreeImage 3 API documentation. + + + nsrc = UBound(SourceIndices) + 1 + ndst = UBound(DestinationIndices) + 1 + If (Count = -1) Then + If (nsrc < ndst) Then + Count = nsrc + Else + Count = ndst + End If + Else + If (Count < nsrc) Then + Count = nsrc + End If + If (Count < ndst) Then + Count = ndst + End If + End If + + FreeImage_ApplyIndexMappingEx = FreeImage_ApplyIndexMapping(Bitmap, _ + VarPtr(SourceIndices(0)), VarPtr(DestinationIndices(0)), Count, swap) + +End Function + +Public Function FreeImage_ConvertFromRawBitsEx(ByRef Bits() As Byte, _ + ByVal Width As Long, _ + ByVal Height As Long, _ + ByVal Pitch As Long, _ + ByVal BitsPerPixel As Long, _ + Optional ByVal RedMask As Long, _ + Optional ByVal GreenMask As Long, _ + Optional ByVal BlueMask As Long, _ + Optional ByVal TopDown As Boolean) As Long + + FreeImage_ConvertFromRawBitsEx = FreeImage_ConvertFromRawBits(VarPtr(Bits(0)), Width, Height, Pitch, _ + BitsPerPixel, RedMask, GreenMask, BlueMask, TopDown) + +End Function + +Public Sub FreeImage_ConvertToRawBitsEx(ByRef Bits() As Byte, _ + ByVal Bitmap As Long, _ + ByVal Pitch As Long, _ + ByVal BitsPerPixel As Long, _ + Optional ByVal RedMask As Long, _ + Optional ByVal GreenMask As Long, _ + Optional ByVal BlueMask As Long, _ + Optional ByVal TopDown As Boolean) + +Dim lHeight As Long + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to convert a 'header-only' bitmap.") + End If + + If (Pitch > 0) Then + lHeight = FreeImage_GetHeight(Bitmap) + ReDim Bits((Pitch * lHeight) - 1) + Call FreeImage_ConvertToRawBits(VarPtr(Bits(0)), Bitmap, Pitch, _ + BitsPerPixel, RedMask, GreenMask, BlueMask, TopDown) + End If + End If + +End Sub + +Public Function FreeImage_GetHistogramEx(ByVal Bitmap As Long, _ + Optional ByVal Channel As FREE_IMAGE_COLOR_CHANNEL = FICC_BLACK, _ + Optional ByRef Success As Boolean) As Long() + +Dim alResult() As Long + + ' This function returns a DIB's histogram data as VB style array of + ' type Long. Since histogram data is never modified directly, it seems + ' enough to return a clone of the data and no read/write accessible + ' array wrapped around the actual pointer. + + ' All parameters work according to the FreeImage 3 API documentation. + + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to get histogram of a 'header-only' bitmap.") + End If + + ReDim alResult(255) + Success = (FreeImage_GetHistogramInt(Bitmap, alResult(0), Channel) = 1) + If (Success) Then + Call pSwap(VarPtrArray(FreeImage_GetHistogramEx), VarPtrArray(alResult)) + End If + End If + +End Function + +Public Function FreeImage_AdjustCurveEx(ByVal Bitmap As Long, _ + ByRef LookupTable As Variant, _ + Optional ByVal Channel As FREE_IMAGE_COLOR_CHANNEL = FICC_BLACK) As Boolean + +Dim lpData As Long +Dim lSizeInBytes As Long + + ' This function extends the FreeImage function 'FreeImage_AdjustCurve' + ' to a more VB suitable function. The parameter 'LookupTable' may + ' either be an array of type Byte or may contain the pointer to a memory + ' block, what in VB is always the address of the memory block, since VB + ' actually doesn's support native pointers. + + ' In case of providing the memory block as an array, make sure, that the + ' array contains exactly 256 items. In case of providing an address of a + ' memory block, the size of the memory block is assumed to be 256 bytes + ' and it is up to the caller to ensure that it is large enough. + + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to adjust a 'header-only' bitmap.") + End If + + If (IsArray(LookupTable)) Then + lpData = pGetMemoryBlockPtrFromVariant(LookupTable, lSizeInBytes) + + ElseIf (IsNumeric(LookupTable)) Then + lSizeInBytes = 256 + lpData = CLng(LookupTable) + + End If + + If ((lpData <> 0) And (lSizeInBytes = 256)) Then + FreeImage_AdjustCurveEx = (FreeImage_AdjustCurveInt(Bitmap, lpData, Channel) = 1) + End If + End If + +End Function + +Public Function FreeImage_GetLockedPageNumbersEx(ByVal Bitmap As Long, _ + Optional ByRef Count As Long) As Long() + +Dim lpPages As Long +Dim alResult() As Long + + ' This function extends the FreeImage function FreeImage_GetLockedPageNumbers() + ' to a more VB suitable function. The original FreeImage parameter 'pages', which + ' is a pointer to an array of Long, containing all locked page numbers, was turned + ' into a return value, which is a real VB-style array of type Long. The original + ' Boolean return value, indicating if there are any locked pages, was dropped from + ' this function. The caller has to check the 'Count' parameter, which works according + ' to the FreeImage API documentation. + + ' This function returns an array of Longs, dimensioned from 0 to (Count - 1), that + ' contains the page numbers of all currently locked pages of 'BITMAP', if 'Count' is + ' greater than 0 after the function returns. If 'Count' is 0, there are no pages + ' locked and the function returns an uninitialized array. + + + If (FreeImage_GetLockedPageNumbersInt(Bitmap, lpPages, Count) = 1) Then + ReDim alResult(Count - 1) + Call CopyMemory(alResult(0), ByVal lpPages, Count * 4) + End If + +End Function + +' Memory and Stream functions + +Public Function FreeImage_GetFileTypeFromMemoryEx(ByRef Data As Variant, _ + Optional ByRef SizeInBytes As Long) As FREE_IMAGE_FORMAT + +Dim hStream As Long +Dim lDataPtr As Long + + ' This function extends the FreeImage function FreeImage_GetFileTypeFromMemory() + ' to a more VB suitable function. The parameter data of type Variant my + ' me either an array of type Byte, Integer or Long or may contain the pointer + ' to a memory block, what in VB is always the address of the memory block, + ' since VB actually doesn's support native pointers. + + ' In case of providing the memory block as an array, the SizeInBytes may + ' be omitted, zero or less than zero. Then, the size of the memory block + ' is calculated correctly. When SizeInBytes is given, it is up to the caller + ' to ensure, it is correct. + + ' In case of providing an address of a memory block, SizeInBytes must not + ' be omitted. + + + ' get both pointer and size in bytes of the memory block provided + ' through the Variant parameter 'data'. + lDataPtr = pGetMemoryBlockPtrFromVariant(Data, SizeInBytes) + + ' open the memory stream + hStream = FreeImage_OpenMemoryByPtr(lDataPtr, SizeInBytes) + If (hStream) Then + ' on success, detect image type + FreeImage_GetFileTypeFromMemoryEx = FreeImage_GetFileTypeFromMemory(hStream) + Call FreeImage_CloseMemory(hStream) + Else + FreeImage_GetFileTypeFromMemoryEx = FIF_UNKNOWN + End If + +End Function + +Public Function FreeImage_LoadFromMemoryEx(ByRef Data As Variant, _ + Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS, _ + Optional ByRef SizeInBytes As Long, _ + Optional ByRef Format As FREE_IMAGE_FORMAT) As Long + +Dim hStream As Long +Dim lDataPtr As Long + + ' This function extends the FreeImage function FreeImage_LoadFromMemory() + ' to a more VB suitable function. The parameter data of type Variant my + ' me either an array of type Byte, Integer or Long or may contain the pointer + ' to a memory block, what in VB is always the address of the memory block, + ' since VB actually doesn's support native pointers. + + ' The parameter 'Flags' works according to the FreeImage API documentation. + + ' In case of providing the memory block as an array, the SizeInBytes may + ' be omitted, zero or less than zero. Then, the size of the memory block + ' is calculated correctly. When SizeInBytes is given, it is up to the caller + ' to ensure, it is correct. + + ' In case of providing an address of a memory block, SizeInBytes must not + ' be omitted. + + ' The parameter fif is an OUT parameter, that will contain the image type + ' detected. Any values set by the caller will never be used within this + ' function. + + + ' get both pointer and size in bytes of the memory block provided + ' through the Variant parameter 'data'. + lDataPtr = pGetMemoryBlockPtrFromVariant(Data, SizeInBytes) + + ' open the memory stream + hStream = FreeImage_OpenMemoryByPtr(lDataPtr, SizeInBytes) + If (hStream) Then + ' on success, detect image type + Format = FreeImage_GetFileTypeFromMemory(hStream) + If (Format <> FIF_UNKNOWN) Then + ' load the image from memory stream only, if known image type + FreeImage_LoadFromMemoryEx = FreeImage_LoadFromMemory(Format, hStream, Flags) + End If + ' close the memory stream when open + Call FreeImage_CloseMemory(hStream) + End If + +End Function + +Public Function FreeImage_SaveToMemoryEx(ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Bitmap As Long, _ + ByRef Data() As Byte, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS, _ + Optional ByVal UnloadSource As Boolean) As Boolean + +Dim hStream As Long +Dim lpData As Long +Dim lSizeInBytes As Long + + ' This function saves a FreeImage DIB into memory by using the VB Byte + ' array Data(). It makes a deep copy of the image data and closes the + ' memory stream opened before it returns to the caller. + + ' The Byte array 'Data()' must not be a fixed sized array and will be + ' redimensioned according to the size needed to hold all the data. + + ' The parameters 'Format', 'Bitmap' and 'Flags' work according to the FreeImage 3 + ' API documentation. + + ' The optional 'UnloadSource' parameter is for unloading the original image + ' after it has been saved into memory. There is no need to clean up the DIB + ' at the caller's site. + + ' The function returns True on success and False otherwise. + + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to save a 'header-only' bitmap.") + End If + + hStream = FreeImage_OpenMemory() + If (hStream) Then + FreeImage_SaveToMemoryEx = FreeImage_SaveToMemory(Format, Bitmap, hStream, Flags) + If (FreeImage_SaveToMemoryEx) Then + If (FreeImage_AcquireMemoryInt(hStream, lpData, lSizeInBytes)) Then + On Error Resume Next + ReDim Data(lSizeInBytes - 1) + If (Err.Number = ERROR_SUCCESS) Then + On Error GoTo 0 + Call CopyMemory(Data(0), ByVal lpData, lSizeInBytes) + Else + On Error GoTo 0 + FreeImage_SaveToMemoryEx = False + End If + Else + FreeImage_SaveToMemoryEx = False + End If + End If + Call FreeImage_CloseMemory(hStream) + Else + FreeImage_SaveToMemoryEx = False + End If + + If (UnloadSource) Then + Call FreeImage_Unload(Bitmap) + End If + End If + +End Function + +Public Function FreeImage_SaveToMemoryEx2(ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Bitmap As Long, _ + ByRef Data() As Byte, _ + ByRef Stream As Long, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS, _ + Optional ByVal UnloadSource As Boolean) As Boolean + + ' This function saves a FreeImage DIB into memory by using the VB Byte + ' array Data(). It does not makes a deep copy of the image data, but uses + ' the function 'FreeImage_AcquireMemoryEx' to wrap the array 'Data()' + ' around the memory block pointed to by the result of the + ' 'FreeImage_AcquireMemory' function. + + ' The Byte array 'Data()' must not be a fixed sized array and will be + ' redimensioned according to the size needed to hold all the data. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArray' function. + + ' The parameter 'stream' is an IN/OUT parameter, tracking the memory + ' stream, the VB array 'Data()' is based on. This parameter may contain + ' an already opened FreeImage memory stream when the function is called and + ' contains a valid memory stream when the function returns in each case. + ' After all, it is up to the caller to close that memory stream correctly. + ' The array 'Data()' will no longer be valid and accessable after the stream + ' has been closed, so it should only be closed after the passed byte array + ' variable either goes out of the caller's scope or is redimensioned. + + ' The parameters 'Format', 'Bitmap' and 'Flags' work according to the FreeImage 3 + ' API documentation. + + ' The optional 'UnloadSource' parameter is for unloading the original image + ' after it has been saved to memory. There is no need to clean up the DIB + ' at the caller's site. + + ' The function returns True on success and False otherwise. + + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to save a 'header-only' bitmap.") + End If + + If (Stream = 0) Then + Stream = FreeImage_OpenMemory() + End If + If (Stream) Then + FreeImage_SaveToMemoryEx2 = FreeImage_SaveToMemory(Format, Bitmap, Stream, Flags) + If (FreeImage_SaveToMemoryEx2) Then + FreeImage_SaveToMemoryEx2 = FreeImage_AcquireMemoryEx(Stream, Data) + End If + + ' do not close the memory stream, since the returned array data() + ' points to the stream's data + ' the caller must close the stream after he is done + ' with the array + Else + FreeImage_SaveToMemoryEx2 = False + End If + + If (UnloadSource) Then + Call FreeImage_Unload(Bitmap) + End If + End If + +End Function + +Public Function FreeImage_AcquireMemoryEx(ByVal Stream As Long, _ + ByRef Data() As Byte, _ + Optional ByRef SizeInBytes As Long) As Boolean + +Dim lpData As Long +Dim tSA As SAVEARRAY1D +Dim lpSA As Long + + ' This function wraps the byte array Data() around acquired memory + ' of the memory stream specified by then stream parameter. The adjusted + ' array then points directly to the stream's data pointer and so + ' provides full read and write access. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArray' function. + + + If (Stream) Then + If (FreeImage_AcquireMemoryInt(Stream, lpData, SizeInBytes)) Then + With tSA + .cbElements = 1 ' one element is one byte + .cDims = 1 ' the array has only 1 dimension + .cElements = SizeInBytes ' the number of elements in the array is + ' the size in bytes of the memory block + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = lpData ' let the array point to the memory block + ' received by FreeImage_AcquireMemory + End With + + lpSA = deref(VarPtrArray(Data)) + If (lpSA = 0) Then + ' allocate memory for an array descriptor + Call SafeArrayAllocDescriptor(1, lpSA) + Call CopyMemory(ByVal VarPtrArray(Data), lpSA, 4) + Else + Call SafeArrayDestroyData(lpSA) + End If + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + Else + FreeImage_AcquireMemoryEx = False + End If + Else + FreeImage_AcquireMemoryEx = False + End If + +End Function + +Public Function FreeImage_ReadMemoryEx(ByRef Buffer As Variant, _ + ByVal Stream As Long, _ + Optional ByRef Count As Long, _ + Optional ByRef Size As Long) As Long + +Dim lBufferPtr As Long +Dim lSizeInBytes As Long +Dim lSize As Long +Dim lCount As Long + + ' This function is a wrapper for 'FreeImage_ReadMemory()' using VB style + ' arrays instead of a void pointer. + + ' The variant parameter 'Buffer' may be a Byte, Integer or Long array or + ' may contain a pointer to a memory block (the memory block's address). + + ' In the latter case, this function behaves exactly + ' like 'FreeImage_ReadMemory()'. Then, 'Count' and 'Size' must be valid + ' upon entry. + + ' If 'Buffer' is an initialized (dimensioned) array, 'Count' and 'Size' may + ' be omitted. Then, the array's layout is used to determine 'Count' + ' and 'Size'. In that case, any provided value in 'Count' and 'Size' upon + ' entry will override these calculated values as long as they are not + ' exceeding the size of the array in 'Buffer'. + + ' If 'Buffer' is an uninitialized (not yet dimensioned) array of any valid + ' type (Byte, Integer or Long) and, at least 'Count' is specified, the + ' array in 'Buffer' is redimensioned by this function. If 'Buffer' is a + ' fixed-size or otherwise locked array, a runtime error (10) occurs. + ' If 'Size' is omitted, the array's element size is assumed to be the + ' desired value. + + ' As FreeImage's function 'FreeImage_ReadMemory()', this function returns + ' the number of items actually read. + + ' Example: (very freaky...) + ' + ' Dim alLongBuffer() As Long + ' Dim lRet as Long + ' + ' ' now reading 303 integers (2 byte) into an array of Longs + ' lRet = FreeImage_ReadMemoryEx(alLongBuffer, lMyStream, 303, 2) + ' + ' ' now, lRet contains 303 and UBound(alLongBuffer) is 151 since + ' ' we need at least 152 Longs (0..151) to store (303 * 2) = 606 bytes + ' ' so, the higest two bytes of alLongBuffer(151) contain only unset + ' ' bits. Got it? + + ' Remark: This function's parameter order differs from FreeImage's + ' original funtion 'FreeImage_ReadMemory()'! + + If (VarType(Buffer) And vbArray) Then + ' get both pointer and size in bytes of the memory block provided + ' through the Variant parameter 'Buffer'. + lBufferPtr = pGetMemoryBlockPtrFromVariant(Buffer, lSizeInBytes, lSize) + If (lBufferPtr = 0) Then + ' array is not initialized + If (Count > 0) Then + ' only if we have a 'Count' value, redim the array + If (Size <= 0) Then + ' if 'Size' is omitted, use array's element size + Size = lSize + End If + + Select Case lSize + + Case 2 + ' Remark: -Int(-a) == ceil(a); a > 0 + ReDim Buffer(-Int(-Count * Size / 2) - 1) As Integer + + Case 4 + ' Remark: -Int(-a) == ceil(a); a > 0 + ReDim Buffer(-Int(-Count * Size / 4) - 1) As Long + + Case Else + ReDim Buffer((Count * Size) - 1) As Byte + + End Select + lBufferPtr = pGetMemoryBlockPtrFromVariant(Buffer, lSizeInBytes, lSize) + End If + End If + If (lBufferPtr) Then + lCount = lSizeInBytes / lSize + If (Size <= 0) Then + ' use array's natural value for 'Size' when + ' omitted + Size = lSize + End If + If (Count <= 0) Then + ' use array's natural value for 'Count' when + ' omitted + Count = lCount + End If + If ((Size * Count) > (lSize * lCount)) Then + If (Size = lSize) Then + Count = lCount + Else + ' Remark: -Fix(-a) == floor(a); a > 0 + Count = -Fix(-lSizeInBytes / Size) + If (Count = 0) Then + Size = lSize + Count = lCount + End If + End If + End If + FreeImage_ReadMemoryEx = FreeImage_ReadMemory(lBufferPtr, Size, Count, Stream) + End If + + ElseIf (VarType(Buffer) = vbLong) Then + ' if Buffer is a Long, it specifies the address of a memory block + ' then, we do not know anything about its size, so assume that 'Size' + ' and 'Count' are correct and forward these directly to the FreeImage + ' call. + FreeImage_ReadMemoryEx = FreeImage_ReadMemory(CLng(Buffer), Size, Count, Stream) + + End If + +End Function + +Public Function FreeImage_WriteMemoryEx(ByRef Buffer As Variant, _ + ByVal Stream As Long, _ + Optional ByRef Count As Long, _ + Optional ByRef Size As Long) As Long + +Dim lBufferPtr As Long +Dim lSizeInBytes As Long +Dim lSize As Long +Dim lCount As Long + + ' This function is a wrapper for 'FreeImage_WriteMemory()' using VB style + ' arrays instead of a void pointer. + + ' The variant parameter 'Buffer' may be a Byte, Integer or Long array or + ' may contain a pointer to a memory block (the memory block's address). + + ' In the latter case, this function behaves exactly + ' like 'FreeImage_WriteMemory()'. Then, 'Count' and 'Size' must be valid + ' upon entry. + + ' If 'Buffer' is an initialized (dimensioned) array, 'Count' and 'Size' may + ' be omitted. Then, the array's layout is used to determine 'Count' + ' and 'Size'. In that case, any provided value in 'Count' and 'Size' upon + ' entry will override these calculated values as long as they are not + ' exceeding the size of the array in 'Buffer'. + + ' If 'Buffer' is an uninitialized (not yet dimensioned) array of any + ' type, the function will do nothing an returns 0. + + ' Remark: This function's parameter order differs from FreeImage's + ' original funtion 'FreeImage_ReadMemory()'! + + If (VarType(Buffer) And vbArray) Then + ' get both pointer and size in bytes of the memory block provided + ' through the Variant parameter 'Buffer'. + lBufferPtr = pGetMemoryBlockPtrFromVariant(Buffer, lSizeInBytes, lSize) + If (lBufferPtr) Then + lCount = lSizeInBytes / lSize + If (Size <= 0) Then + ' use array's natural value for 'Size' when + ' omitted + Size = lSize + End If + If (Count <= 0) Then + ' use array's natural value for 'Count' when + ' omitted + Count = lCount + End If + If ((Size * Count) > (lSize * lCount)) Then + If (Size = lSize) Then + Count = lCount + Else + ' Remark: -Fix(-a) == floor(a); a > 0 + Count = -Fix(-lSizeInBytes / Size) + If (Count = 0) Then + Size = lSize + Count = lCount + End If + End If + End If + FreeImage_WriteMemoryEx = FreeImage_WriteMemory(lBufferPtr, Size, Count, Stream) + End If + + ElseIf (VarType(Buffer) = vbLong) Then + ' if Buffer is a Long, it specifies the address of a memory block + ' then, we do not know anything about its size, so assume that 'Size' + ' and 'Count' are correct and forward these directly to the FreeImage + ' call. + FreeImage_WriteMemoryEx = FreeImage_WriteMemory(CLng(Buffer), Size, Count, Stream) + + End If + +End Function + +Public Function FreeImage_LoadMultiBitmapFromMemoryEx(ByRef Data As Variant, _ + Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS, _ + Optional ByRef SizeInBytes As Long, _ + Optional ByRef Format As FREE_IMAGE_FORMAT) As Long + +Dim hStream As Long +Dim lDataPtr As Long + + ' This function extends the FreeImage function FreeImage_LoadMultiBitmapFromMemoryEx() + ' to a more VB suitable function. The parameter data of type Variant my + ' me either an array of type Byte, Integer or Long or may contain the pointer + ' to a memory block, what in VB is always the address of the memory block, + ' since VB actually doesn's support native pointers. + + ' The parameter 'Flags' works according to the FreeImage API documentation. + + ' In case of providing the memory block as an array, the SizeInBytes may + ' be omitted, zero or less than zero. Then, the size of the memory block + ' is calculated correctly. When SizeInBytes is given, it is up to the caller + ' to ensure, it is correct. + + ' In case of providing an address of a memory block, SizeInBytes must not + ' be omitted. + + ' The parameter fif is an OUT parameter, that will contain the image type + ' detected. Any values set by the caller will never be used within this + ' function. + + + ' get both pointer and size in bytes of the memory block provided + ' through the Variant parameter 'Data'. + lDataPtr = pGetMemoryBlockPtrFromVariant(Data, SizeInBytes) + + ' open the memory stream + hStream = FreeImage_OpenMemoryByPtr(lDataPtr, SizeInBytes) + If (hStream) Then + ' on success, detect image type + Format = FreeImage_GetFileTypeFromMemory(hStream) + If (Format <> FIF_UNKNOWN) Then + ' load the image from memory stream only, if known image type + FreeImage_LoadMultiBitmapFromMemoryEx = FreeImage_LoadMultiBitmapFromMemory(Format, hStream, Flags) + End If + ' close the memory stream when open + Call FreeImage_CloseMemory(hStream) + End If + +End Function + +Public Function FreeImage_SaveMultiBitmapToMemoryEx(ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Bitmap As Long, _ + ByRef Data() As Byte, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS, _ + Optional ByVal UnloadSource As Boolean) As Boolean + +Dim hStream As Long +Dim lpData As Long +Dim lSizeInBytes As Long + + ' This function saves a FreeImage multi-page bitmap into memory by using + ' the VB Byte array Data(). It makes a deep copy of the image data and closes the + ' memory stream opened, before it returns to the caller. + + ' The Byte array 'Data()' must not be a fixed sized array and will be + ' redimensioned according to the size needed to hold all the data. + + ' The parameters 'Format', 'Bitmap' and 'Flags' work according to the FreeImage 3 + ' API documentation. + + ' The optional 'UnloadSource' parameter is for unloading the original image + ' after it has been saved to memory. If True, there is no need to close the + ' multi-page bitmap at the caller's site. + + ' The function returns True on success and False otherwise. + + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to save a 'header-only' bitmap.") + End If + + hStream = FreeImage_OpenMemory() + If (hStream) Then + FreeImage_SaveMultiBitmapToMemoryEx = FreeImage_SaveMultiBitmapToMemory(Format, Bitmap, hStream, Flags) + If (FreeImage_SaveMultiBitmapToMemoryEx) Then + If (FreeImage_AcquireMemoryInt(hStream, lpData, lSizeInBytes)) Then + On Error Resume Next + ReDim Data(lSizeInBytes - 1) + If (Err.Number = ERROR_SUCCESS) Then + On Error GoTo 0 + Call CopyMemory(Data(0), ByVal lpData, lSizeInBytes) + Else + On Error GoTo 0 + FreeImage_SaveMultiBitmapToMemoryEx = False + End If + Else + FreeImage_SaveMultiBitmapToMemoryEx = False + End If + End If + Call FreeImage_CloseMemory(hStream) + Else + FreeImage_SaveMultiBitmapToMemoryEx = False + End If + + If (UnloadSource) Then + Call FreeImage_CloseMultiBitmapInt(Bitmap) + End If + End If + +End Function + +Public Function FreeImage_SaveMultiBitmapToMemoryEx2(ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Bitmap As Long, _ + ByRef Data() As Byte, _ + ByRef Stream As Long, _ + Optional ByVal Flags As FREE_IMAGE_SAVE_OPTIONS, _ + Optional ByVal UnloadSource As Boolean) As Boolean + + ' This function saves a FreeImage multi-page bitmap into memory by using + ' the VB Byte array Data(). It does not makes a deep copy of the image data, but uses + ' the function 'FreeImage_AcquireMemoryEx' to wrap the array 'Data()' + ' around the memory block pointed to by the result of the + ' 'FreeImage_AcquireMemory' function. + + ' The Byte array 'Data()' must not be a fixed sized array and will be + ' redimensioned according to the size needed to hold all the data. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArray' function. + + ' The parameter 'Stream' is an IN/OUT parameter, tracking the memory + ' stream, the VB array 'Data()' is based on. This parameter may contain + ' an already opened FreeImage memory stream when the function is called and + ' contains a valid memory stream when the function returns in each case. + ' After all, it is up to the caller to close that memory stream correctly. + ' The array 'Data()' will no longer be valid and accessable after the stream + ' has been closed, so it should only be closed after the passed byte array + ' variable either goes out of the caller's scope or is redimensioned. + + ' The parameters 'Format', 'Bitmap' and 'Flags' work according to the FreeImage 3 + ' API documentation. + + ' The optional 'UnloadSource' parameter is for unloading the original image + ' after it has been saved to memory. If True, there is no need to close the + ' multi-page bitmap at the caller's site. + + ' The function returns True on success and False otherwise. + + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to save a 'header-only' bitmap.") + End If + + If (Stream = 0) Then + Stream = FreeImage_OpenMemory() + End If + If (Stream) Then + FreeImage_SaveMultiBitmapToMemoryEx2 = _ + FreeImage_SaveMultiBitmapToMemory(Format, Bitmap, Stream, Flags) + If (FreeImage_SaveMultiBitmapToMemoryEx2) Then + FreeImage_SaveMultiBitmapToMemoryEx2 = FreeImage_AcquireMemoryEx(Stream, Data) + End If + + ' do not close the memory stream, since the returned array 'Data()' + ' points to the stream's data + ' the caller must close the stream after he is done + ' with the array + Else + FreeImage_SaveMultiBitmapToMemoryEx2 = False + End If + + If (UnloadSource) Then + Call FreeImage_CloseMultiBitmapInt(Bitmap) + End If + End If + +End Function + + + +'-------------------------------------------------------------------------------- +' Tag accessing VB friendly helper functions +'-------------------------------------------------------------------------------- + +Public Function FreeImage_CreateTagEx(ByVal Model As FREE_IMAGE_MDMODEL, _ + Optional ByVal Key As String, _ + Optional ByVal TagType As FREE_IMAGE_MDTYPE = FIDT_NOTYPE, _ + Optional ByRef Value As Variant, _ + Optional ByRef Count As Long, _ + Optional ByVal Id As Long) As FREE_IMAGE_TAG + + ' This function is a wrapper for FreeImage_CreateTag() working with + ' the VB friendly FREE_IMAGE_TAG structure. So, the return value is + ' not a pointer to a FITAG structure but a FREE_IMAGE_TAG structure. + + ' In contrast to FreeImage's original FreeImage_CreateTag() function, the + ' parameter 'Model' must be specified, the parameters 'Key', 'TagType', + ' 'Value', 'Count' and 'Id' my be specified. + + ' The 'Model' is needed, since each FREE_IMAGE_TAG structure needs a + ' valid 'Model' member. + + ' All other parameters are optional and enable the caller to specify the tag's + ' values upon tag creation. Any parameter specified, is set to it's corresponding + ' member in the FREE_IMAGE_TAG structure. + + ' The caller should check the returned FREE_IMAGE_TAG structure's 'TagPtr' member. + ' If this function succeeded, the 'TagPtr' member is non zero. A value of zero + ' indicates an error condition sourced from FreeImage_CreateTag(). + + With FreeImage_CreateTagEx + .TagPtr = FreeImage_CreateTag() + If (.TagPtr <> 0) Then + .Model = Model + If (LenB(Key) > 0) Then + .Key = Key + End If + .Type = TagType + .Count = Count + .Id = Id + If (Not IsMissing(Value)) Then + .Value = Value + End If + Call pTagToTagPtr(FreeImage_CreateTagEx) + FreeImage_CreateTagEx = pGetTagFromTagPtr(Model, .TagPtr) + End If + End With + +End Function + +Public Function FreeImage_AppendTag(ByVal Bitmap As Long, _ + ByVal Model As FREE_IMAGE_MDMODEL, _ + Optional ByVal Key As String, _ + Optional ByVal TagType As FREE_IMAGE_MDTYPE = FIDT_NOTYPE, _ + Optional ByRef Value As Variant, _ + Optional ByRef Count As Long, _ + Optional ByVal Id As Long, _ + Optional ByVal OverwriteExisting As Boolean = True) As FREE_IMAGE_TAG + +Dim lpTag As Long + + ' This function is a shortcut wrapper for FreeImage_CreateTagEx() and + ' FreeImage_SetMetadataEx(). It creates a new tag as FreeImage_CreateTagEx() does + ' and appends it to the image's metadata model. + + ' The parameter 'Bitmap' specifies the image, the new tag should be appended to, + ' parameters 'Model', 'Key', 'TagType', 'Value', 'Count' and 'Id' are these, + ' FreeImage_CreateTagEx() has and are just forwarded unchanged. + + ' The boolean parameter 'OverwriteExisting' determines, whether to overwrite or + ' replace an already existing tag with the newly created. If the tag specified + ' by it's model and key already exists and 'OverwriteExisting' is False, an + ' empty FREE_IMAGE_TAG structure is returned. + + ' So, as with FreeImage_CreateTagEx(), the caller should check the returned + ' FREE_IMAGE_TAG structure's 'TagPtr' member. If this function succeeded, the + ' 'TagPtr' member is non zero. A value of zero indicates an error condition + ' sourced from either the FreeImage_CreateTag() function or may result from + ' an already existing tag that should not be overwritten. + + If ((FreeImage_GetMetadataInt(Model, Bitmap, Key, lpTag) = 0) Or _ + (OverwriteExisting)) Then + + FreeImage_AppendTag = FreeImage_CreateTagEx(Model, Key, TagType, Value, Count, Id) + If (FreeImage_AppendTag.TagPtr <> 0) Then + Call FreeImage_SetMetadataEx(Bitmap, FreeImage_AppendTag, Key, Model, True) + End If + End If + +End Function + +Public Function FreeImage_RemoveTag(ByVal Bitmap As Long, _ + ByVal Model As FREE_IMAGE_MDMODEL, _ + ByVal Key As String) As Boolean + + ' This function is a wrapper function, that removes a tag, that is actually + ' part of an image's metadata model. The tag named 'key' of the metadata + ' model specified in parameter 'Model' of the image 'Bitmap' will be removed. + + ' Removing a tag is actually done by calling FreeImage_SetMetadata() with + ' a NULL pointer for 'FITAG *tag' as described in the API documentation. + + ' The function returns the boolean value returned from FreeImage_SetMetadata(), + ' which is always TRUE when removing a tag in this fashion. So, this function's + ' caller has no feedback telling if the tag was really present and removed + ' successfully. + + ' Up to version 3.9.1 of FreeImage, there seems to be a bug in removing an + ' tag from an image's metadata model. Although the removed tag is not accessible + ' through FreeImage_GetMetadata() any more, iterations with + ' Freeimage_FindFirst/NextMetadata() will still return this tag an a NULL + ' pointer. + + ' This bug was reported on the Developers Forum. You can revisit the posting at: + ' http://sourceforge.net/forum/forum.php?thread_id=1536883&forum_id=36111 + + FreeImage_RemoveTag = (FreeImage_SetMetadataInt(Model, Bitmap, Key, 0) <> 0) + +End Function + +Public Function FreeImage_RemoveTagEx(ByVal Bitmap As Long, _ + ByRef Tag As FREE_IMAGE_TAG) As Boolean + + ' This function is a FREE_IMAGE_TAG based wrapper for FreeImage_RemoveTag() + + With Tag + FreeImage_RemoveTagEx = FreeImage_RemoveTag(Bitmap, .Model, .Key) + End With + +End Function + +Public Function FreeImage_TagExists(ByVal Bitmap As Long, _ + ByVal Model As FREE_IMAGE_MDMODEL, _ + Optional ByVal Key As String) As Boolean + +Dim lpTag As Long + + ' This function is a small helper function, returning a boolean value + ' that determines, whether a certain tag specified by metadata model + ' and key exists for an image specified by 'Bitmap'. + + FreeImage_TagExists = (FreeImage_GetMetadataInt(Model, Bitmap, Key, lpTag) <> 0) + +End Function + +Public Function FreeImage_TagExistsEx(ByVal Bitmap As Long, _ + ByRef Tag As FREE_IMAGE_TAG) As Boolean + + ' This function is a FREE_IMAGE_TAG based wrapper for FreeImage_TagExists() + + With Tag + FreeImage_TagExistsEx = FreeImage_TagExists(Bitmap, .Model, .Key) + End With + +End Function + +Public Sub FreeImage_DeleteTagEx(ByRef Tag As FREE_IMAGE_TAG) + + ' This function is a wrapper for FreeImage_DeleteTag() working with + ' the VB friendly FREE_IMAGE_TAG structure. So, the parameter 'Tag' + ' is not a pointer to a FITAG structure but a FREE_IMAGE_TAG structure. + + ' This function deletes the underlaying FreeImage FITAG structure, + ' specified the the member 'TagPtr' of the FREE_IMAGE_TAG structure + ' and also sets all other members of Tag to a null value. + + ' Do not get confused with the wrapper functions FreeImage_RemoveTag() + ' and FreeImage_RemoveTagEx(). These functions remove a tag from an + ' image's metadata model. This function only deletes of frees (a better + ' name would be 'FreeImage_FreeTag') a tag created with + ' FreeImage_CreateTagEx(). Do not delete any tags obtained from any other + ' function. + + With Tag + If (.TagPtr <> 0) Then + Call FreeImage_DeleteTag(.TagPtr) + End If + .TagPtr = 0 + .Count = 0 + .Description = vbNullString + .Id = 0 + .Key = vbNullString + .Length = 0 + .Model = FIMD_NODATA + Erase .Palette + Erase .RationalValue + .StringValue = vbNullString + .Type = FIDT_NOTYPE + .Value = Empty + End With + +End Sub + +Public Function FreeImage_CloneTagEx(ByRef Tag As FREE_IMAGE_TAG, _ + Optional ByVal Model As FREE_IMAGE_MDMODEL = FIMD_NODATA) As FREE_IMAGE_TAG + + ' This function is a thin wrapper for FreeImage_CloneTag() working with + ' the VB friendly FREE_IMAGE_TAG structure. The parameter 'Tag' works + ' according to the FreeImage API documentation expect that Tag is not a + ' pointer to a FITAG structure but a FREE_IMAGE_TAG structure. + + ' The additional optional paremeter 'Model' is needed, since the + ' transformation from a FreeImage FITAG structure to the VB friendly + ' FREE_IMAGE_TAG structure always need the model to be specified. + ' When 'Model' is missing (equal to FREE_IMAGE_TAG), the model to be + ' used is taken from the Tag's member 'Model' itself. + + ' See function FreeImage_FindNextMetadataEx() to learn more about the + ' optional parameter 'Model' + + ' Tags obtained from FreeImage_CloneTagEx() must be deleted with + ' FreeImage_DeleteTagEx() as long as they are not used with + ' FreeImage_SetMetadataEx() with the parameter 'RefreshTag' set to True. + + If (Tag.TagPtr <> 0) Then + If (Model = FIMD_NODATA) Then + Model = Tag.Model + End If + FreeImage_CloneTagEx = pGetTagFromTagPtr(Model, FreeImage_CloneTag(Tag.TagPtr)) + End If + +End Function + +Public Function FreeImage_RemoveMetadataModel(ByVal Bitmap As Long, _ + ByVal Model As FREE_IMAGE_MDMODEL) As Boolean + + ' This function removes a complete metadata model 'Model' from an image specified + ' by 'Bitmap'. + + If (Model <> FIMD_NODATA) Then + FreeImage_RemoveMetadataModel = (FreeImage_SetMetadataInt(Model, Bitmap, vbNullString, 0) <> 0) + End If + +End Function + +Public Function FreeImage_FindFirstMetadataEx(ByVal Model As FREE_IMAGE_MDMODEL, _ + ByVal Bitmap As Long, _ + ByRef Tag As FREE_IMAGE_TAG) As Long + + ' This function is a wrapper for FreeImage_FindFirstMetadata() working with + ' the VB friendly FREE_IMAGE_TAG structure. All parameters 'Bitmap', 'Tag', + ' and 'Model' as the function's return value work according to the + ' FreeImage API documentation expect that Tag is not a pointer to a FITAG + ' structure but a FREE_IMAGE_TAG structure. + + ' Tags obtained from FreeImage_GetMetadataEx() must not be deleted with + ' FreeImage_DeleteTagEx(). + + With Tag + FreeImage_FindFirstMetadataEx = FreeImage_FindFirstMetadata(Model, Bitmap, .TagPtr) + If (FreeImage_FindFirstMetadataEx <> 0) Then + Tag = pGetTagFromTagPtr(Model, .TagPtr) + End If + End With + +End Function + +Public Function FreeImage_FindNextMetadataEx(ByVal hFind As Long, _ + ByRef Tag As FREE_IMAGE_TAG, _ + Optional ByVal Model As FREE_IMAGE_MDMODEL = FIMD_NODATA) As Boolean + + ' This function is a wrapper for FreeImage_FindNextMetadataEx() working with + ' the VB friendly FREE_IMAGE_TAG structure. All parameters 'hFind' and 'Tag' + ' as the function's return value work according to the FreeImage API + ' documentation expect that Tag is not a pointer to a FITAG structure but a + ' FREE_IMAGE_TAG structure. + + ' The additional optional paremeter 'Model' is needed, since the VB friendly + ' FREE_IMAGE_TAG structure also contains the member 'StringValue'. This member + ' is filled with the result of FreeImage_TagToString() which always needs + ' the model to be specified. Since there should be no static oder global + ' variables id the FreeImage VB wrapper, the model must be known each time + ' a FreeImage FITAG structure is converted to a FREE_IMAGE_TAG structure. + ' (A global VB collection could be used to map the hFind to the model, + ' but we don't want any globals here) + + ' So, when 'Model' is missing (equal to FREE_IMAGE_TAG), the model to be used + ' is taken from the Tag's member 'Model' itself. This is useful when using this + ' function in a loop iterating all tags per model (what else would you do + ' with that function?). The Tag's member 'Model' is populated by + ' FreeImage_FindFirstMetadataEx() and remains valid during the whole loop, ready + ' to be used in this function. + + ' Tags obtained from FreeImage_GetMetadataEx() must not be deleted with + ' FreeImage_DeleteTagEx(). + + With Tag + FreeImage_FindNextMetadataEx = (FreeImage_FindNextMetadataInt(hFind, .TagPtr) <> 0) + If (FreeImage_FindNextMetadataEx) Then + If (Model = FIMD_NODATA) Then + Model = .Model + End If + Tag = pGetTagFromTagPtr(Model, .TagPtr) + End If + End With + +End Function + +Public Function FreeImage_GetAllMetadataTags(ByVal Model As FREE_IMAGE_MDMODEL, _ + ByVal Bitmap As Long, _ + ByRef Tag() As FREE_IMAGE_TAG) As Long + +Dim hMD As Long +Dim lpTag As Long +Dim i As Long + + ' This function is a helper function returning (through a ByRef parameter) + ' an array of FREE_IMAGE_TAG structures containing all the image's tags of + ' the metadata model specified by the 'Model' parameter. + + ' The parameter 'Tag()' must be an redimensionable array of FREE_IMAGE_TAG + ' and is redimensioned accordingly. The function returns the number of + ' tags stored in 'Tag()'. + + ' All tags obtained from FreeImage_GetAllMetadataTags() must not be deleted + ' with FreeImage_DeleteTagEx(). + + i = FreeImage_GetMetadataCount(Model, Bitmap) + If (i > 0) Then + ReDim Tag(i - 1) + FreeImage_GetAllMetadataTags = i + i = 0 + hMD = FreeImage_FindFirstMetadata(Model, Bitmap, lpTag) + If (hMD <> 0) Then + Do + Tag(i) = pGetTagFromTagPtr(Model, lpTag) + i = i + 1 + Loop While (FreeImage_FindNextMetadataInt(hMD, lpTag) <> 0) + Call FreeImage_FindCloseMetadata(hMD) + End If + End If + +End Function + +Public Function FreeImage_GetMetadataEx(ByVal Model As FREE_IMAGE_MDMODEL, _ + ByVal Bitmap As Long, _ + ByVal Key As String, _ + ByRef Tag As FREE_IMAGE_TAG) As Boolean + + ' This function is a wrapper for FreeImage_GetMetadata() working with + ' the VB friendly FREE_IMAGE_TAG structure. All parameters 'Bitmap', 'Tag', + ' 'Key' and 'Model' as well as the function's return value work according + ' to the FreeImage API documentation expect that Tag is not a pointer to + ' a FITAG structure but to a FREE_IMAGE_TAG structure. + + ' Tags obtained from FreeImage_GetMetadataEx() must not be deleted with + ' FreeImage_DeleteTagEx(). + + With Tag + If (FreeImage_GetMetadataInt(Model, Bitmap, Key, .TagPtr) <> 0) Then + Tag = pGetTagFromTagPtr(Model, .TagPtr) + FreeImage_GetMetadataEx = True + End If + End With + +End Function + +Public Function FreeImage_SetMetadataEx(ByVal Bitmap As Long, _ + ByRef Tag As FREE_IMAGE_TAG, _ + Optional ByVal Key As String, _ + Optional ByVal Model As FREE_IMAGE_MDMODEL = FIMD_NODATA, _ + Optional ByVal RefreshTag As Boolean) As Boolean + + ' This function is a wrapper for FreeImage_SetMetadata() using the wrapper's + ' VB friendly FREE_IMAGE_TAG structure as an replacement for the original + ' function's pointer to a FITAG structure. + + ' All parameters 'Bitmap', 'Tag', 'Key' and 'Model' as the function's return value + ' work according to the FreeImage API documentation expect that Tag is not a + ' pointer to a FITAG structure but a FREE_IMAGE_TAG structure. + + ' As with FreeImage_SetMetadata(), this function sould only be called with + ' new tags, created with FreeImage_CreateTagEx(), a wrapper function for + ' FreeImage_CreateTag() working with the VB friendly FREE_IMAGE_TAG structure. + + ' Normally, after a newly created tag must be deleted/freed with a call to + ' FreeImage_DeleteTagEx(), a wrapper function for FreeImage_DeleteTag() working + ' with the VB friendly FREE_IMAGE_TAG structure (bored already?), after + ' the tag was appended to an image's metadata model with + ' FreeImage_SetMetadataEx(). But... + + ' There is a wrapper specific additional boolean parameter 'RefreshTag', that + ' is similar to the parameter 'UnloadSource' found in many wrapper functions. + ' When 'RefreshTag' is True upon entry, the tag specified in the 'Tag' + ' parameter is deleted (the underlaying FITAG structure is deleted with + ' FreeImage_DeteleTag() and all other members of the FREE_IMAGE_TAG structure + ' are set to null values) and is reassigned with the tag, that is now part + ' of the image's metadata model. The tag now referenced in the 'Tag' + ' parameter must NOT be deleted any more by the caller of this function, since + ' this tag refers to the actual tag data stored with the image. This is like + ' a FREE_IMAGE_TAG structure obtained from FreeImage_GetMetadata() or + ' FreeImage_FindFirst/NextMetadata(). Any changes made to this FREE_IMAGE_TAG + ' structure may be applied to the image with a later call to + ' FreeImage_UpdateMetadata(). + + + With Tag + If (Model = FIMD_NODATA) Then + Model = .Model + End If + If (LenB(Key) = 0) Then + Key = .Key + End If + If (FreeImage_SetMetadataInt(Model, Bitmap, Key, .TagPtr) <> 0) Then + FreeImage_SetMetadataEx = True + End If + If (RefreshTag) Then + Call FreeImage_DeleteTagEx(Tag) + Call FreeImage_GetMetadataEx(Model, Bitmap, Key, Tag) + End If + End With + +End Function + +Public Function FreeImage_GetImageComment(ByVal Bitmap As Long) As String + +Dim tTag As FREE_IMAGE_TAG + + ' This function is a small wrapper around FreeImage_GetMetadata() that + ' returns the comment of a JPEG, PNG of GIF image. + + If (FreeImage_GetMetadataEx(FIMD_COMMENTS, Bitmap, "Comment", tTag)) Then + FreeImage_GetImageComment = tTag.Value + End If + +End Function + +Public Function FreeImage_SetImageComment(ByVal Bitmap As Long, _ + Optional ByVal Comment As String) As Boolean + +Dim tTag As FREE_IMAGE_TAG + + ' This function is a small wrapper around FreeImage_SetMetadata() that + ' sets the comment of a JPEG, PNG of GIF image. + + If (LenB(Comment) > 0) Then + tTag = FreeImage_AppendTag(Bitmap, FIMD_COMMENTS, "Comment", FIDT_ASCII, Comment) + FreeImage_SetImageComment = (tTag.TagPtr <> 0) + Else + Call FreeImage_RemoveMetadataModel(Bitmap, FIMD_COMMENTS) + FreeImage_SetImageComment = True + End If + +End Function + +Public Function FreeImage_CopyMetadata(ByVal BitmapSrc As Long, _ + ByVal BitmapDst As Long, _ + Optional ByVal ReplaceExisting As Boolean = True, _ + Optional ByVal Model As FREE_IMAGE_MDMODEL = FIMD_NODATA) As Long + +Dim hMDFind As Long +Dim lpTag As Long +Dim strKey As String +Dim bSetTag As Boolean + + ' This derived helper function copies several metadata tags from one + ' image to another. This is useful when cloning images explicitly with + ' FreeImage_Clone() or implicitly with FreeImage_ConvertColorDepth() or + ' with any of the FreeImage_RescaleXXX() functions. Whenever the "same" + ' image is represented by a new 'Bitmap' pointer, the image was internally + ' recreated. All of the data, associated with the image, like metadata, + ' DPI settings or ICC profiles are no more available in the new version of + ' the image. + + ' Setting the DPI for X and Y direction is quite easy with the wrapper + ' functions FreeImage_Get/SetResolutionX/Y(). This function makes it even + ' easier to keep track of all associated metadata tags for a cloned image! + + ' Both parameters 'BitmapSrc' and 'BitmapDst' specify the source and destination + ' image. Metadata is copied from 'BitmapSrc' to 'BitmapDst'. + + ' The optional parameter 'ReplaceExisting' determines whether existing tags + ' should be replaced or not. If there are no tags in 'BitmapDst' it is recommended, + ' to set 'ReplaceExisting' to True (or to omit it, since True is it's default + ' value) for better performance; when set to True, no tests for tag existence + ' in the destination image will be run. + + ' The optional parameter 'Model' may specify a certain metadata model to be + ' copied. If this parameter is omitted or set to any value not defined in the + ' FREE_IMAGE_MDMODEL enumeration, all metadata models will be copied + ' sequentially. + + ' This function returns the number of tags copied or zero when there are no tags + ' in the source image or an error occured. + + ' For the standard use case described above (keeping track of all metadata after + ' an image was cloned) the calling this function boils down to a very short form: + + ' lTagsCopied = FreeImage_CopyMetadata(hDibSrc, hDibDst) + + If ((BitmapSrc <> 0) And (BitmapDst <> 0)) Then + If ((Model >= FIMD_COMMENTS) And (Model <= FIMD_CUSTOM)) Then + hMDFind = FreeImage_FindFirstMetadata(Model, BitmapSrc, lpTag) + If (hMDFind) Then + Do + strKey = pGetStringFromPointerA(deref(deref(lpTag))) + bSetTag = ReplaceExisting + If (Not bSetTag) Then + bSetTag = (Not FreeImage_TagExists(BitmapDst, Model, strKey)) + End If + If (bSetTag) Then + If (FreeImage_SetMetadataInt(Model, BitmapDst, strKey, lpTag) <> 0) Then + FreeImage_CopyMetadata = FreeImage_CopyMetadata + 1 + End If + End If + Loop While (FreeImage_FindNextMetadata(hMDFind, lpTag)) + Call FreeImage_FindCloseMetadata(hMDFind) + End If + Else + For Model = FIMD_COMMENTS To FIMD_CUSTOM + FreeImage_CopyMetadata = FreeImage_CopyMetadata _ + + FreeImage_CopyMetadata(BitmapSrc, BitmapDst, _ + ReplaceExisting, Model) + Next Model + End If + End If + +End Function + +Public Function FreeImage_CloneMetadataEx(ByVal BitmapSrc As Long, _ + ByVal BitmapDst As Long, _ + Optional ByVal Model As FREE_IMAGE_MDMODEL = FIMD_NODATA) As Long + + ' This derived helper function copies several metadata tags from one + ' image to another. It is very similar to FreeImage_CopyMetadata(). + + ' The main difference is, that this function aims to create exactly the same + ' metadata layout in the destination image. In contrast to + ' FreeImage_CopyMetadata(), this function removes all metadata tags in the + ' desination image that are not part of the metadata set in the source image. + ' So, this function is particularly useful for destination images that may + ' have already some tags associated and you want to make shure, that it will + ' get exactly the same metadata set as the source image. + + ' This function will most likely be used in a end user application and should + ' be invoked through a menu command called: "Set/Apply Metadata From Source Image..." + + ' This function returns the number of tags copied or zero if there are no tags + ' in the source image or an error occured. + + If ((BitmapSrc <> 0) And (BitmapDst <> 0)) Then + If ((Model >= FIMD_COMMENTS) And (Model <= FIMD_CUSTOM)) Then + If (FreeImage_RemoveMetadataModel(BitmapDst, Model)) Then + FreeImage_CloneMetadataEx = FreeImage_CopyMetadata(BitmapSrc, BitmapDst, _ + True, Model) + End If + Else + For Model = FIMD_COMMENTS To FIMD_CUSTOM + FreeImage_CloneMetadataEx = FreeImage_CloneMetadataEx _ + + FreeImage_CloneMetadataEx(BitmapSrc, BitmapDst, _ + Model) + Next Model + End If + End If + +End Function + +Public Function FreeImage_TagFromPointer(ByVal Model As FREE_IMAGE_MDMODEL, _ + ByVal Tag As Long) As FREE_IMAGE_TAG + + ' This is a generic function that returns a VB wrapper Tag + ' structure (FREE_IMAGE_TAG) from a FreeImage FITAG *tag pointer. + + ' This function is still public due to legacy reasons. Since there are + ' functions like 'FreeImage_GetMetadataEx()', 'FreeImage_GetAllMetadataTags()' + ' or 'FreeImage_FindFirst/NextMetadataEx()', this function won't be needed + ' any more in most cases. + + FreeImage_TagFromPointer = pGetTagFromTagPtr(Model, Tag) + +End Function + +Public Function FreeImage_UpdateMetadata(ByRef Tag As FREE_IMAGE_TAG) As Boolean + + ' This function updates any changes made in a FREE_IMAGE_TAG + ' structure. + + FreeImage_UpdateMetadata = pTagToTagPtr(Tag) + +End Function + +Public Function FreeImage_UnsignedLong(ByVal Value As Long) As Variant + + ' This function converts a signed long (VB's Long data type) into + ' an unsigned long (not really supported by VB). + + ' Basically, this function checks, whether the positive range of + ' a signed long is sufficient to hold the value (indeed, it checks + ' the value since the range is obviously constant). If yes, + ' it returns a Variant with subtype Long ('Variant/Long' in VB's + ' watch window). In this case, the function did not make any real + ' changes at all. If not, the value is stored in a Currency variable, + ' which is able to store the whole range of an unsigned long. Then, + ' the function returns a Variant with subtype Currency + ' ('Variant/Currency' in VB's watch window). + + If (Value < 0) Then + Dim curTemp As Currency + Call CopyMemory(curTemp, Value, 4) + FreeImage_UnsignedLong = curTemp * 10000 + Else + FreeImage_UnsignedLong = Value + End If + +End Function + +Public Function FreeImage_UnsignedShort(ByVal Value As Integer) As Variant + + ' This function converts a signed short (VB's Integer data type) into + ' an unsigned short (not really supported by VB). + + ' Basically, this function checks, whether the positive range of + ' a signed short is sufficient to hold the value (indeed, it checks + ' the value since the range is obviously constant). If yes, + ' it returns a Variant with subtype Integer ('Variant/Integer' in VB's + ' watch window). In this case, the function did not make any real + ' changes at all. If not, the value is stored in a Long variable, + ' which is able to store the whole range of an unsigned short. Then, + ' the function returns a Variant with subtype Long + ' ('Variant/Long' in VB's watch window). + + If (Value < 0) Then + Dim lTemp As Long + Call CopyMemory(lTemp, Value, 2) + FreeImage_UnsignedShort = lTemp + Else + FreeImage_UnsignedShort = Value + End If + +End Function + +Public Function FreeImage_CreateRational(ByRef Numerator As Variant, _ + ByRef Denominator As Variant, _ + Optional ByVal NormalizeValue As Boolean = True) As FIRATIONAL + + ' This function creates an unsigned rational (FIDT_RATIONAL) value to be used with + ' FreeImage's metadata models. In the VB wrapper, any rational value is stored in a + ' structure (FIRATIONAL), containing both 'Numerator' and 'Denominator' members. The + ' rational's value is then defined as the fraction Numerator/Denominator. + + ' Both values 'Numerator' and 'Denominator' are actually ULONGs (unsigned longs), a + ' data type not supported by VB (a VB Long variable is always signed). Therefore, + ' 'Numerator' and 'Denominator' are typed as Variant. Whenever the range of a signed + ' long is sufficient to store the value (all values between 0 and 0x7FFFFFFF + ' (2147483647 decimal)), the Variant gets a Long subtype. If not, a Currency subtype is + ' used just to give you the mathematical correct value of the unsigned long. + + ' The optional parameter 'NormalizeValue' controls, whether the resulting fraction + ' should be normalized (cancelled down) or not. + + ' When calling this function, you can use hexadecimal constants for passing unsinged + ' longs via the parameters 'Numerator' and 'Denominator'. + + ' 2147483647 + ' Example: tRational = FreeImage_CreateRational(&HFFFFFFFF, 12345) -> ---------- + ' 12345 + + With FreeImage_CreateRational + .Numerator = FreeImage_UnsignedLong(Numerator) + .Denominator = FreeImage_UnsignedLong(Denominator) + End With + + If (NormalizeValue) Then + Call pNormalizeRational(FreeImage_CreateRational) + End If + +End Function + +Public Function FreeImage_CreateSignedRational(ByRef Numerator As Variant, _ + ByRef Denominator As Variant, _ + Optional ByVal NormalizeValue As Boolean = True) As FIRATIONAL + + ' This function creates a signed rational (FIDT_RATIONAL) value to be used with + ' FreeImage's metadata models. In the VB wrapper, any rational value is stored in a + ' structure (FIRATIONAL), containing both 'Numerator' and 'Denominator' members. The + ' rational's value is then defined as the fraction Numerator/Denominator. + + ' Both values 'Numerator' and 'Denominator' are actually LONGs (signed longs), the + ' same data type as a VB Long. Since, 'Numerator' and 'Denominator' are typed as + ' Variant, all possible values between -2,147,483,648 and + 2,147,483,647 are stored + ' in a Variant with subtype Long (cp. 'FreeImage_CreateRational()'). + + ' The optional parameter 'NormalizeValue' controls, whether the resulting fraction + ' should be normalized (cancelled down) or not. + + ' When calling this function, you can use hexadecimal constants for passing unsinged + ' longs via the parameters 'Numerator' and 'Denominator'. + + ' -1 1 + ' Example: tRational = FreeImage_CreateSignedRational(&HFFFFFFFF, 12345) -> ----- = - ----- + ' 12345 12345 + + With FreeImage_CreateSignedRational + .Numerator = CLng(Numerator) + .Denominator = CLng(Denominator) + End With + + If (NormalizeValue) Then + Call pNormalizeSRational(FreeImage_CreateSignedRational) + End If + +End Function + + + +'-------------------------------------------------------------------------------- +' Derived and hopefully useful functions +'-------------------------------------------------------------------------------- + +' Plugin and filename functions + +Public Function FreeImage_IsExtensionValidForFIF(ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Extension As String, _ + Optional ByVal Compare As VbCompareMethod = vbBinaryCompare) As Boolean + + ' This function tests, whether a given filename extension is valid + ' for a certain image format (fif). + + FreeImage_IsExtensionValidForFIF = (InStr(1, _ + FreeImage_GetFIFExtensionList(Format) & ",", _ + Extension & ",", _ + Compare) > 0) + +End Function + +Public Function FreeImage_IsFilenameValidForFIF(ByVal Format As FREE_IMAGE_FORMAT, _ + ByVal Filename As String, _ + Optional ByVal Compare As VbCompareMethod = vbBinaryCompare) As Boolean + +Dim strExtension As String +Dim i As Long + + ' This function tests, whether a given complete filename is valid + ' for a certain image format (fif). + + i = InStrRev(Filename, ".") + If (i > 0) Then + strExtension = Mid$(Filename, i + 1) + FreeImage_IsFilenameValidForFIF = (InStr(1, _ + FreeImage_GetFIFExtensionList(Format) & ",", _ + strExtension & ",", _ + Compare) > 0) + End If + +End Function + +Public Function FreeImage_GetPrimaryExtensionFromFIF(ByVal Format As FREE_IMAGE_FORMAT) As String + +Dim strExtensionList As String +Dim i As Long + + ' This function returns the primary (main or most commonly used?) extension + ' of a certain image format (fif). This is done by returning the first of + ' all possible extensions returned by FreeImage_GetFIFExtensionList(). That + ' assumes, that the plugin returns the extensions in ordered form. If not, + ' in most cases it is even enough, to receive any extension. + + ' This function is primarily used by the function 'SavePictureEx'. + + strExtensionList = FreeImage_GetFIFExtensionList(Format) + i = InStr(strExtensionList, ",") + If (i > 0) Then + FreeImage_GetPrimaryExtensionFromFIF = Left$(strExtensionList, i - 1) + Else + FreeImage_GetPrimaryExtensionFromFIF = strExtensionList + End If + +End Function + +Public Function FreeImage_IsGreyscaleImage(ByVal Bitmap As Long) As Boolean + +Dim atRGB() As RGBQUAD +Dim i As Long + + ' This function returns a boolean value that is true, if the DIB is actually + ' a greyscale image. Here, the only test condition is, that each palette + ' entry must be a grey value, what means that each color component has the + ' same value (red = green = blue). + + ' The FreeImage libraray doesn't offer a function to determine if a DIB is + ' greyscale. The only thing you can do is to use the 'FreeImage_GetColorType' + ' function, that returns either FIC_MINISWHITE or FIC_MINISBLACK for + ' greyscale images. However, a DIB needs to have a ordered greyscale palette + ' (linear ramp or inverse linear ramp) to be judged as FIC_MINISWHITE or + ' FIC_MINISBLACK. DIB's with an unordered palette that are actually (visually) + ' greyscale, are said to be (color-)palletized. That's also true for any 4 bpp + ' image, since it will never have a palette that satifies the tests done + ' in the 'FreeImage_GetColorType' function. + + ' So, there is a chance to omit some color depth conversions, when displaying + ' an image in greyscale fashion. Maybe the problem will be solved in the + ' FreeImage library one day. + + Select Case FreeImage_GetBPP(Bitmap) + + Case 1, 4, 8 + atRGB = FreeImage_GetPaletteEx(Bitmap) + FreeImage_IsGreyscaleImage = True + For i = 0 To UBound(atRGB) + With atRGB(i) + If ((.rgbRed <> .rgbGreen) Or (.rgbRed <> .rgbBlue)) Then + FreeImage_IsGreyscaleImage = False + Exit For + End If + End With + Next i + + End Select + +End Function + +' Bitmap resolution functions + +Public Function FreeImage_GetResolutionX(ByVal Bitmap As Long) As Long + + ' This function gets a DIB's resolution in X-direction measured + ' in 'dots per inch' (DPI) and not in 'dots per meter'. + + FreeImage_GetResolutionX = Int(0.5 + 0.0254 * FreeImage_GetDotsPerMeterX(Bitmap)) + +End Function + +Public Sub FreeImage_SetResolutionX(ByVal Bitmap As Long, ByVal Resolution As Long) + + ' This function sets a DIB's resolution in X-direction measured + ' in 'dots per inch' (DPI) and not in 'dots per meter'. + + Call FreeImage_SetDotsPerMeterX(Bitmap, Int(Resolution / 0.0254 + 0.5)) + +End Sub + +Public Function FreeImage_GetResolutionY(ByVal Bitmap As Long) As Long + + ' This function gets a DIB's resolution in Y-direction measured + ' in 'dots per inch' (DPI) and not in 'dots per meter'. + + FreeImage_GetResolutionY = Int(0.5 + 0.0254 * FreeImage_GetDotsPerMeterY(Bitmap)) + +End Function + +Public Sub FreeImage_SetResolutionY(ByVal Bitmap As Long, ByVal Resolution As Long) + + ' This function sets a DIB's resolution in Y-direction measured + ' in 'dots per inch' (DPI) and not in 'dots per meter'. + + Call FreeImage_SetDotsPerMeterY(Bitmap, Int(Resolution / 0.0254 + 0.5)) + +End Sub + +' ICC Color Profile functions + +Public Function FreeImage_GetICCProfile(ByVal Bitmap As Long) As FIICCPROFILE + + ' This function is a wrapper for the FreeImage_GetICCProfile() function, returning + ' a real FIICCPROFILE structure. + + ' Since the original FreeImage function returns a pointer to the FIICCPROFILE + ' structure (FIICCPROFILE *), as with string returning functions, this wrapper is + ' needed as VB can't declare a function returning a pointer to anything. So, + ' analogous to string returning functions, FreeImage_GetICCProfile() is declared + ' private as FreeImage_GetICCProfileInt() and made publicly available with this + ' wrapper function. + + Call CopyMemory(FreeImage_GetICCProfile, _ + ByVal FreeImage_GetICCProfileInt(Bitmap), _ + LenB(FreeImage_GetICCProfile)) + +End Function + +Public Function FreeImage_GetICCProfileColorModel(ByVal Bitmap As Long) As FREE_IMAGE_ICC_COLOR_MODEL + + ' This function is a thin wrapper around FreeImage_GetICCProfile() returning + ' the color model in which the ICC color profile data is in, if there is actually + ' a ICC color profile available for the Bitmap specified. + + ' If there is NO color profile along with that bitmap, this function returns the color + ' model that should (or must) be used for any color profile data to be assigned to the + ' Bitmap. That depends on the bitmap's color type. + + If (FreeImage_HasICCProfile(Bitmap)) Then + FreeImage_GetICCProfileColorModel = (deref(FreeImage_GetICCProfileInt(Bitmap)) _ + And FREE_IMAGE_ICC_COLOR_MODEL_MASK) + Else + ' use FreeImage_GetColorType() to determine, whether this is a CMYK bitmap or not + If (FreeImage_GetColorType(Bitmap) = FIC_CMYK) Then + FreeImage_GetICCProfileColorModel = FIICC_COLOR_MODEL_CMYK + Else + FreeImage_GetICCProfileColorModel = FIICC_COLOR_MODEL_RGB + End If + End If + +End Function + +Public Function FreeImage_GetICCProfileSize(ByVal Bitmap As Long) As Long + + ' This function is a thin wrapper around FreeImage_GetICCProfile() returning + ' only the size in bytes of the ICC profile data for the Bitmap specified or zero, + ' if there is no ICC profile data for the Bitmap. + + FreeImage_GetICCProfileSize = deref(FreeImage_GetICCProfileInt(Bitmap) + 4) + +End Function + +Public Function FreeImage_GetICCProfileDataPointer(ByVal Bitmap As Long) As Long + + ' This function is a thin wrapper around FreeImage_GetICCProfile() returning + ' only the pointer (the address) of the ICC profile data for the Bitmap specified, + ' or zero if there is no ICC profile data for the Bitmap. + + FreeImage_GetICCProfileDataPointer = deref(FreeImage_GetICCProfileInt(Bitmap) + 8) + +End Function + +Public Function FreeImage_HasICCProfile(ByVal Bitmap As Long) As Boolean + + ' This function is a thin wrapper around FreeImage_GetICCProfile() returning + ' True, if there is an ICC color profile available for the Bitmap specified or + ' returns False otherwise. + + FreeImage_HasICCProfile = (FreeImage_GetICCProfileSize(Bitmap) <> 0) + +End Function + +' Bitmap Info functions + +Public Function FreeImage_GetInfoHeaderEx(ByVal Bitmap As Long) As BITMAPINFOHEADER + +Dim lpInfoHeader As Long + + ' This function is a wrapper around FreeImage_GetInfoHeader() and returns a fully + ' populated BITMAPINFOHEADER structure for a given bitmap. + + lpInfoHeader = FreeImage_GetInfoHeader(Bitmap) + If (lpInfoHeader) Then + Call CopyMemory(FreeImage_GetInfoHeaderEx, ByVal lpInfoHeader, LenB(FreeImage_GetInfoHeaderEx)) + End If + +End Function + +' Image color depth conversion wrapper + +Public Function FreeImage_ConvertColorDepth(ByVal Bitmap As Long, _ + ByVal Conversion As FREE_IMAGE_CONVERSION_FLAGS, _ + Optional ByVal UnloadSource As Boolean, _ + Optional ByVal Threshold As Byte = 128, _ + Optional ByVal DitherMethod As FREE_IMAGE_DITHER = FID_FS, _ + Optional ByVal QuantizeMethod As FREE_IMAGE_QUANTIZE = FIQ_WUQUANT) As Long + +Dim hDIBNew As Long +Dim hDIBTemp As Long +Dim lBPP As Long +Dim bForceLinearRamp As Boolean +Dim lpReservePalette As Long +Dim bAdjustReservePaletteSize As Boolean + + ' This function is an easy-to-use wrapper for color depth conversion, intended + ' to work around some tweaks in the FreeImage library. + + ' The parameters 'Threshold' and 'eDitherMode' control how thresholding or + ' dithering are performed. The 'QuantizeMethod' parameter determines, what + ' quantization algorithm will be used when converting to 8 bit color images. + + ' The 'Conversion' parameter, which can contain a single value or an OR'ed + ' combination of some of the FREE_IMAGE_CONVERSION_FLAGS enumeration values, + ' determines the desired output image format. + + ' The optional 'UnloadSource' parameter is for unloading the original image, so + ' you can "change" an image with this function rather than getting a new DIB + ' pointer. There is no more need for a second DIB variable at the caller's site. + + bForceLinearRamp = ((Conversion And FICF_REORDER_GREYSCALE_PALETTE) = 0) + lBPP = FreeImage_GetBPP(Bitmap) + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to convert a 'header-only' bitmap.") + End If + + Select Case (Conversion And (Not FICF_REORDER_GREYSCALE_PALETTE)) + + Case FICF_MONOCHROME_THRESHOLD + If (lBPP > 1) Then + hDIBNew = FreeImage_Threshold(Bitmap, Threshold) + End If + + Case FICF_MONOCHROME_DITHER + If (lBPP > 1) Then + hDIBNew = FreeImage_Dither(Bitmap, DitherMethod) + End If + + Case FICF_GREYSCALE_4BPP + If (lBPP <> 4) Then + ' If the color depth is 1 bpp and the we don't have a linear ramp palette + ' the bitmap is first converted to an 8 bpp greyscale bitmap with a linear + ' ramp palette and then to 4 bpp. + If ((lBPP = 1) And (FreeImage_GetColorType(Bitmap) = FIC_PALETTE)) Then + hDIBTemp = Bitmap + Bitmap = FreeImage_ConvertToGreyscale(Bitmap) + Call FreeImage_Unload(hDIBTemp) + End If + hDIBNew = FreeImage_ConvertTo4Bits(Bitmap) + Else + ' The bitmap is already 4 bpp but may not have a linear ramp. + ' If we force a linear ramp the bitmap is converted to 8 bpp with a linear ramp + ' and then back to 4 bpp. + If (((Not bForceLinearRamp) And (Not FreeImage_IsGreyscaleImage(Bitmap))) Or _ + (bForceLinearRamp And (FreeImage_GetColorType(Bitmap) = FIC_PALETTE))) Then + hDIBTemp = FreeImage_ConvertToGreyscale(Bitmap) + hDIBNew = FreeImage_ConvertTo4Bits(hDIBTemp) + Call FreeImage_Unload(hDIBTemp) + End If + End If + + Case FICF_GREYSCALE_8BPP + ' Convert, if the bitmap is not at 8 bpp or does not have a linear ramp palette. + If ((lBPP <> 8) Or (((Not bForceLinearRamp) And (Not FreeImage_IsGreyscaleImage(Bitmap))) Or _ + (bForceLinearRamp And (FreeImage_GetColorType(Bitmap) = FIC_PALETTE)))) Then + hDIBNew = FreeImage_ConvertToGreyscale(Bitmap) + End If + + Case FICF_PALLETISED_8BPP + ' note, that the FreeImage library only quantizes 24 bit images + ' do not convert any 8 bit images + If (lBPP <> 8) Then + ' images with a color depth of 24 bits can directly be + ' converted with the FreeImage_ColorQuantize function; + ' other images need to be converted to 24 bits first + If (lBPP = 24) Then + hDIBNew = FreeImage_ColorQuantize(Bitmap, QuantizeMethod) + Else + hDIBTemp = FreeImage_ConvertTo24Bits(Bitmap) + hDIBNew = FreeImage_ColorQuantize(hDIBTemp, QuantizeMethod) + Call FreeImage_Unload(hDIBTemp) + End If + End If + + Case FICF_RGB_15BPP + If (lBPP <> 15) Then + hDIBNew = FreeImage_ConvertTo16Bits555(Bitmap) + End If + + Case FICF_RGB_16BPP + If (lBPP <> 16) Then + hDIBNew = FreeImage_ConvertTo16Bits565(Bitmap) + End If + + Case FICF_RGB_24BPP + If (lBPP <> 24) Then + hDIBNew = FreeImage_ConvertTo24Bits(Bitmap) + End If + + Case FICF_RGB_32BPP + If (lBPP <> 32) Then + hDIBNew = FreeImage_ConvertTo32Bits(Bitmap) + End If + + End Select + + If (hDIBNew) Then + FreeImage_ConvertColorDepth = hDIBNew + If (UnloadSource) Then + Call FreeImage_Unload(Bitmap) + End If + Else + FreeImage_ConvertColorDepth = Bitmap + End If + + End If + +End Function + +Public Function FreeImage_ColorQuantizeEx(ByVal Bitmap As Long, _ + Optional ByVal QuantizeMethod As FREE_IMAGE_QUANTIZE = FIQ_WUQUANT, _ + Optional ByVal UnloadSource As Boolean, _ + Optional ByVal PaletteSize As Long = 256, _ + Optional ByVal ReserveSize As Long, _ + Optional ByRef ReservePalette As Variant = Null) As Long + +Dim hTmp As Long +Dim lpPalette As Long +Dim lBlockSize As Long +Dim lElementSize As Long + + ' This function is a more VB-friendly wrapper around FreeImage_ColorQuantizeEx, + ' which lets you specify the ReservePalette to be used not only as a pointer, but + ' also as a real VB-style array of type Long, where each Long item takes a color + ' in ARGB format (&HAARRGGBB). The native FreeImage function FreeImage_ColorQuantizeEx + ' is declared private and named FreeImage_ColorQuantizeExInt and so hidden from the + ' world outside the wrapper. + + ' In contrast to the FreeImage API documentation, ReservePalette is of type Variant + ' and may either be a pointer to palette data (pointer to an array of type RGBQUAD + ' == VarPtr(atMyPalette(0)) in VB) or an array of type Long, which then must contain + ' the palette data in ARGB format. You can receive palette data as an array Longs + ' from function FreeImage_GetPaletteExLong. + ' Although ReservePalette is of type Variant, arrays of type RGBQUAD can not be + ' passed, as long as RGBQUAD is not declared as a public type in a public object + ' module. So, when dealing with RGBQUAD arrays, you are stuck on VarPtr or may + ' use function FreeImage_GetPalettePtr, which is a more meaningfully named + ' convenience wrapper around VarPtr. + + ' The optional 'UnloadSource' parameter is for unloading the original image, so + ' you can "change" an image with this function rather than getting a new DIB + ' pointer. There is no more need for a second DIB variable at the caller's site. + + ' All other parameters work according to the FreeImage API documentation. + + ' Note: Currently, any provided ReservePalette is only used, if quantize is + ' FIQ_NNQUANT. This seems to be either a bug or an undocumented + ' limitation of the FreeImage library (up to version 3.11.0). + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to quantize a 'header-only' bitmap.") + End If + + If (FreeImage_GetBPP(Bitmap) <> 24) Then + hTmp = Bitmap + Bitmap = FreeImage_ConvertTo24Bits(Bitmap) + If (UnloadSource) Then + Call FreeImage_Unload(hTmp) + End If + UnloadSource = True + End If + + ' adjust PaletteSize + If (PaletteSize < 2) Then + PaletteSize = 2 + ElseIf (PaletteSize > 256) Then + PaletteSize = 256 + End If + + lpPalette = pGetMemoryBlockPtrFromVariant(ReservePalette, lBlockSize, lElementSize) + FreeImage_ColorQuantizeEx = FreeImage_ColorQuantizeExInt(Bitmap, QuantizeMethod, _ + PaletteSize, ReserveSize, lpPalette) + + If (UnloadSource) Then + Call FreeImage_Unload(Bitmap) + End If + End If + +End Function + +Public Function FreeImage_GetPalettePtr(ByRef Palette() As RGBQUAD) As Long + + ' Returns a pointer to an array of RGBQUAD. This is sometimes referred to as + ' a palette. + + FreeImage_GetPalettePtr = VarPtr(Palette(0)) + +End Function + + +' Image Rescale wrapper functions + +Public Function FreeImage_RescaleEx(ByVal Bitmap As Long, _ + Optional ByVal Width As Variant, _ + Optional ByVal Height As Variant, _ + Optional ByVal IsPercentValue As Boolean, _ + Optional ByVal UnloadSource As Boolean, _ + Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ + Optional ByVal ForceCloneCreation As Boolean) As Long + +Dim lNewWidth As Long +Dim lNewHeight As Long +Dim hDIBNew As Long + + ' This function is a easy-to-use wrapper for rescaling an image with the + ' FreeImage library. It returns a pointer to a new rescaled DIB provided + ' by FreeImage. + + ' The parameters 'Width', 'Height' and 'IsPercentValue' control + ' the size of the new image. Here, the function tries to fake something like + ' overloading known from Java. It depends on the parameter's data type passed + ' through the Variant, how the provided values for width and height are + ' actually interpreted. The following rules apply: + + ' In general, non integer values are either interpreted as percent values or + ' factors, the original image size will be multiplied with. The 'IsPercentValue' + ' parameter controls whether the values are percent values or factors. Integer + ' values are always considered to be the direct new image size, not depending on + ' the original image size. In that case, the 'IsPercentValue' parameter has no + ' effect. If one of the parameters is omitted, the image will not be resized in + ' that direction (either in width or height) and keeps it's original size. It is + ' possible to omit both, but that makes actually no sense. + + ' The following table shows some of possible data type and value combinations + ' that might by used with that function: (assume an original image sized 100x100 px) + + ' Parameter | Values | Values | Values | Values | Values | + ' ---------------------------------------------------------------------- + ' Width | 75.0 | 0.85 | 200 | 120 | 400.0 | + ' Height | 120.0 | 1.3 | 230 | - | 400.0 | + ' IsPercentValue | True | False | d.c. | d.c. | False | <- wrong option? + ' ---------------------------------------------------------------------- + ' Result Size | 75x120 | 85x130 | 200x230 | 120x100 |40000x40000 | + ' Remarks | percent | factor | direct | |maybe not | + ' |what you | + ' |wanted, | + ' |right? | + + ' The optional 'UnloadSource' parameter is for unloading the original image, so + ' you can "change" an image with this function rather than getting a new DIB + ' pointer. There is no more need for a second DIB variable at the caller's site. + + ' As of version 2.0 of the FreeImage VB wrapper, this function and all it's derived + ' functions like FreeImage_RescaleByPixel() or FreeImage_RescaleByPercent(), do NOT + ' return a clone of the image, if the new size desired is the same as the source + ' image's size. That behaviour can be forced by setting the new parameter + ' 'ForceCloneCreation' to True. Then, an image is also rescaled (and so + ' effectively cloned), if the new width and height is exactly the same as the source + ' image's width and height. + + ' Since this diversity may be confusing to VB developers, this function is also + ' callable through three different functions called 'FreeImage_RescaleByPixel', + ' 'FreeImage_RescaleByPercent' and 'FreeImage_RescaleByFactor'. + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to rescale a 'header-only' bitmap.") + End If + + If (Not IsMissing(Width)) Then + Select Case VarType(Width) + + Case vbDouble, vbSingle, vbDecimal, vbCurrency + lNewWidth = FreeImage_GetWidth(Bitmap) * Width + If (IsPercentValue) Then + lNewWidth = lNewWidth / 100 + End If + + Case Else + lNewWidth = Width + + End Select + End If + + If (Not IsMissing(Height)) Then + Select Case VarType(Height) + + Case vbDouble, vbSingle, vbDecimal + lNewHeight = FreeImage_GetHeight(Bitmap) * Height + If (IsPercentValue) Then + lNewHeight = lNewHeight / 100 + End If + + Case Else + lNewHeight = Height + + End Select + End If + + If ((lNewWidth > 0) And (lNewHeight > 0)) Then + If (ForceCloneCreation) Then + hDIBNew = FreeImage_Rescale(Bitmap, lNewWidth, lNewHeight, Filter) + + ElseIf ((lNewWidth <> FreeImage_GetWidth(Bitmap)) Or _ + (lNewHeight <> FreeImage_GetHeight(Bitmap))) Then + hDIBNew = FreeImage_Rescale(Bitmap, lNewWidth, lNewHeight, Filter) + + End If + + ElseIf (lNewWidth > 0) Then + If ((lNewWidth <> FreeImage_GetWidth(Bitmap)) Or _ + (ForceCloneCreation)) Then + lNewHeight = lNewWidth / (FreeImage_GetWidth(Bitmap) / FreeImage_GetHeight(Bitmap)) + hDIBNew = FreeImage_Rescale(Bitmap, lNewWidth, lNewHeight, Filter) + End If + + ElseIf (lNewHeight > 0) Then + If ((lNewHeight <> FreeImage_GetHeight(Bitmap)) Or _ + (ForceCloneCreation)) Then + lNewWidth = lNewHeight * (FreeImage_GetWidth(Bitmap) / FreeImage_GetHeight(Bitmap)) + hDIBNew = FreeImage_Rescale(Bitmap, lNewWidth, lNewHeight, Filter) + End If + + End If + + If (hDIBNew) Then + FreeImage_RescaleEx = hDIBNew + If (UnloadSource) Then + Call FreeImage_Unload(Bitmap) + End If + Else + FreeImage_RescaleEx = Bitmap + End If + End If + +End Function + +Public Function FreeImage_RescaleByPixel(ByVal Bitmap As Long, _ + Optional ByVal WidthInPixels As Long, _ + Optional ByVal HeightInPixels As Long, _ + Optional ByVal UnloadSource As Boolean, _ + Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ + Optional ByVal ForceCloneCreation As Boolean) As Long + + ' Thin wrapper for function 'FreeImage_RescaleEx' for removing method + ' overload fake. This function rescales the image directly to the size + ' specified by the 'WidthInPixels' and 'HeightInPixels' parameters. + + FreeImage_RescaleByPixel = FreeImage_RescaleEx(Bitmap, WidthInPixels, HeightInPixels, False, _ + UnloadSource, Filter, ForceCloneCreation) + +End Function + +Public Function FreeImage_RescaleByPercent(ByVal Bitmap As Long, _ + Optional ByVal WidthPercentage As Double, _ + Optional ByVal HeightPercentage As Double, _ + Optional ByVal UnloadSource As Boolean, _ + Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ + Optional ByVal ForceCloneCreation As Boolean) As Long + + ' Thin wrapper for function 'FreeImage_RescaleEx' for removing method + ' overload fake. This function rescales the image by a percent value + ' based on the image's original size. + + FreeImage_RescaleByPercent = FreeImage_RescaleEx(Bitmap, WidthPercentage, HeightPercentage, True, _ + UnloadSource, Filter, ForceCloneCreation) + +End Function + +Public Function FreeImage_RescaleByFactor(ByVal Bitmap As Long, _ + Optional ByVal WidthFactor As Double, _ + Optional ByVal HeightFactor As Double, _ + Optional ByVal UnloadSource As Boolean, _ + Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ + Optional ByVal ForceCloneCreation As Boolean) As Long + + ' Thin wrapper for function 'FreeImage_RescaleEx' for removing method + ' overload fake. This function rescales the image by a factor + ' based on the image's original size. + + FreeImage_RescaleByFactor = FreeImage_RescaleEx(Bitmap, WidthFactor, HeightFactor, False, _ + UnloadSource, Filter, ForceCloneCreation) + +End Function + +' Painting functions + +Public Function FreeImage_PaintDC(ByVal hDC As Long, _ + ByVal Bitmap As Long, _ + Optional ByVal XDst As Long, _ + Optional ByVal YDst As Long, _ + Optional ByVal XSrc As Long, _ + Optional ByVal YSrc As Long, _ + Optional ByVal Width As Long, _ + Optional ByVal Height As Long) As Long + + ' This function draws a FreeImage DIB directly onto a device context (DC). There + ' are many (selfexplaining?) parameters that control the visual result. + + ' Parameters 'XDst' and 'YDst' specify the point where the output should + ' be painted and 'XSrc', 'YSrc', 'Width' and 'Height' span a rectangle + ' in the source image 'Bitmap' that defines the area to be painted. + + ' If any of parameters 'Width' and 'Height' is zero, it is transparently substituted + ' by the width or height of teh bitmap to be drawn, resprectively. + + If ((hDC <> 0) And (Bitmap <> 0)) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to paint a 'header-only' bitmap.") + End If + + If (Width = 0) Then + Width = FreeImage_GetWidth(Bitmap) + End If + + If (Height = 0) Then + Height = FreeImage_GetHeight(Bitmap) + End If + + FreeImage_PaintDC = SetDIBitsToDevice(hDC, XDst, YDst - YSrc, Width, Height, XSrc, YSrc, 0, _ + Height, FreeImage_GetBits(Bitmap), FreeImage_GetInfo(Bitmap), DIB_RGB_COLORS) + End If + +End Function + +Public Function FreeImage_PaintDCEx(ByVal hDC As Long, _ + ByVal Bitmap As Long, _ + Optional ByVal XDst As Long, _ + Optional ByVal YDst As Long, _ + Optional ByVal WidthDst As Long, _ + Optional ByVal HeightDst As Long, _ + Optional ByVal XSrc As Long, _ + Optional ByVal YSrc As Long, _ + Optional ByVal WidthSrc As Long, _ + Optional ByVal HeightSrc As Long, _ + Optional ByVal DrawMode As DRAW_MODE = DM_DRAW_DEFAULT, _ + Optional ByVal RasterOperator As RASTER_OPERATOR = ROP_SRCCOPY, _ + Optional ByVal StretchMode As STRETCH_MODE = SM_COLORONCOLOR) As Long + +Dim eLastStretchMode As STRETCH_MODE + + ' This function draws a FreeImage DIB directly onto a device context (DC). There + ' are many (selfexplaining?) parameters that control the visual result. + + ' The main difference of this function compared to the 'FreeImage_PaintDC' is, + ' that this function supports both mirroring and stretching of the image to be + ' painted and so, is somewhat slower than 'FreeImage_PaintDC'. + + If ((hDC <> 0) And (Bitmap <> 0)) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to paint a 'header-only' bitmap.") + End If + + eLastStretchMode = GetStretchBltMode(hDC) + Call SetStretchBltMode(hDC, StretchMode) + + If (WidthSrc = 0) Then + WidthSrc = FreeImage_GetWidth(Bitmap) + End If + If (WidthDst = 0) Then + WidthDst = WidthSrc + End If + + If (HeightSrc = 0) Then + HeightSrc = FreeImage_GetHeight(Bitmap) + End If + If (HeightDst = 0) Then + HeightDst = HeightSrc + End If + + If (DrawMode And DM_MIRROR_VERTICAL) Then + YDst = HeightDst + HeightDst = -HeightDst + End If + + If (DrawMode And DM_MIRROR_HORIZONTAL) Then + XDst = WidthDst + WidthDst = -WidthDst + End If + + Call StretchDIBits(hDC, XDst, YDst, WidthDst, HeightDst, XSrc, YSrc, WidthSrc, HeightSrc, _ + FreeImage_GetBits(Bitmap), FreeImage_GetInfo(Bitmap), DIB_RGB_COLORS, _ + RasterOperator) + + ' restore last mode + Call SetStretchBltMode(hDC, eLastStretchMode) + End If + +End Function + +Public Function FreeImage_PaintTransparent(ByVal hDC As Long, _ + ByVal Bitmap As Long, _ + Optional ByVal XDst As Long = 0, _ + Optional ByVal YDst As Long = 0, _ + Optional ByVal WidthDst As Long, _ + Optional ByVal HeightDst As Long, _ + Optional ByVal XSrc As Long = 0, _ + Optional ByVal YSrc As Long = 0, _ + Optional ByVal WidthSrc As Long, _ + Optional ByVal HeightSrc As Long, _ + Optional ByVal Alpha As Byte = 255) As Long + +Dim lpPalette As Long +Dim bIsTransparent As Boolean + + ' This function paints a device independent bitmap to any device context and + ' thereby honors any transparency information associated with the bitmap. + ' Furthermore, through the 'Alpha' parameter, an overall transparency level + ' may be specified. + + ' For palletised images, any color set to be transparent in the transparency + ' table, will be transparent. For high color images, only 32-bit images may + ' have any transparency information associated in their alpha channel. Only + ' these may be painted with transparency by this function. + + ' Since this is a wrapper for the Windows GDI function AlphaBlend(), 31-bit + ' images, containing alpha (or per-pixel) transparency, must be 'premultiplied' + ' for alpha transparent regions to actually show transparent. See MSDN help + ' on the AlphaBlend() function. + + ' FreeImage also offers a function to premultiply 32-bit bitmaps with their alpha + ' channel, according to the needs of AlphaBlend(). Have a look at function + ' FreeImage_PreMultiplyWithAlpha(). + + ' Overall transparency level may be specified for all bitmaps in all color + ' depths supported by FreeImage. If needed, bitmaps are transparently converted + ' to 32-bit and unloaded after the paint operation. This is also true for palletised + ' bitmaps. + + ' Parameters 'hDC' and 'Bitmap' seem to be very self-explanatory. All other parameters + ' are optional. The group of '*Dest*' parameters span a rectangle on the destination + ' device context, used as drawing area for the bitmap. If these are omitted, the + ' bitmap will be drawn starting at position 0,0 in the bitmap's actual size. + ' The group of '*Src*' parameters span a rectangle on the source bitmap, used as + ' cropping area for the paint operation. If both rectangles differ in size in any + ' direction, the part of the image actually painted is stretched for to fit into + ' the drawing area. If any of the parameters '*Width' or '*Height' are omitted, + ' the bitmap's actual size (width or height) will be used. + + ' The 'Alpha' parameter specifies the overall transparency. It takes values in the + ' range from 0 to 255. Using 0 will paint the bitmap fully transparent, 255 will + ' paint the image fully opaque. The 'Alpha' value controls, how the non per-pixel + ' portions of the image will be drawn. + + If ((hDC <> 0) And (Bitmap <> 0)) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to paint a 'header-only' bitmap.") + End If + + ' get image width if not specified + If (WidthSrc = 0) Then + WidthSrc = FreeImage_GetWidth(Bitmap) + End If + If (WidthDst = 0) Then + WidthDst = WidthSrc + End If + + ' get image height if not specified + If (HeightSrc = 0) Then + HeightSrc = FreeImage_GetHeight(Bitmap) + End If + If (HeightDst = 0) Then + HeightDst = HeightSrc + End If + + lpPalette = FreeImage_GetPalette(Bitmap) + If (lpPalette) Then + + Dim lPaletteSize As Long + Dim alPalOrg(255) As Long + Dim alPalMod(255) As Long + Dim alPalMask(255) As Long + Dim abTT() As Byte + Dim i As Long + + lPaletteSize = FreeImage_GetColorsUsed(Bitmap) * 4 + Call CopyMemory(alPalOrg(0), ByVal lpPalette, lPaletteSize) + Call CopyMemory(alPalMod(0), ByVal lpPalette, lPaletteSize) + abTT = FreeImage_GetTransparencyTableEx(Bitmap) + + If ((Alpha = 255) And _ + (HeightDst >= HeightSrc) And (WidthDst >= WidthSrc)) Then + + ' create a mask palette and a modified version of the + ' original palette + For i = 0 To UBound(abTT) + If (abTT(i) = 0) Then + alPalMask(i) = &HFFFFFFFF ' white + alPalMod(i) = &H0 ' black + bIsTransparent = True + End If + Next i + + If (Not bIsTransparent) Then + + ' if there is no transparency in the image, paint it with + ' a single SRCCOPY + Call StretchDIBits(hDC, _ + XDst, YDst, WidthDst, HeightDst, _ + XSrc, YSrc, WidthSrc, HeightSrc, _ + FreeImage_GetBits(Bitmap), _ + FreeImage_GetInfo(Bitmap), _ + DIB_RGB_COLORS, SRCCOPY) + Else + + ' set mask palette and paint with SRCAND + Call CopyMemory(ByVal lpPalette, alPalMask(0), lPaletteSize) + Call StretchDIBits(hDC, _ + XDst, YDst, WidthDst, HeightDst, _ + XSrc, YSrc, WidthSrc, HeightSrc, _ + FreeImage_GetBits(Bitmap), _ + FreeImage_GetInfo(Bitmap), _ + DIB_RGB_COLORS, SRCAND) + + ' set mask modified and paint with SRCPAINT + Call CopyMemory(ByVal lpPalette, alPalMod(0), lPaletteSize) + Call StretchDIBits(hDC, _ + XDst, YDst, WidthDst, HeightDst, _ + XSrc, YSrc, WidthSrc, HeightSrc, _ + FreeImage_GetBits(Bitmap), _ + FreeImage_GetInfo(Bitmap), _ + DIB_RGB_COLORS, SRCPAINT) + + ' restore original palette + Call CopyMemory(ByVal lpPalette, alPalOrg(0), lPaletteSize) + End If + + ' we are done, do not paint with AlphaBlend() any more + Bitmap = 0 + Else + + ' create a premultiplied palette + ' since we have no real per pixel transparency in a palletized + ' image, we only need to set all transparent colors to zero. + For i = 0 To UBound(abTT) + If (abTT(i) = 0) Then + alPalMod(i) = 0 + End If + Next i + + ' set premultiplied palette and convert to 32 bits + Call CopyMemory(ByVal lpPalette, alPalMod(0), lPaletteSize) + Bitmap = FreeImage_ConvertTo32Bits(Bitmap) + + ' restore original palette + Call CopyMemory(ByVal lpPalette, alPalOrg(0), lPaletteSize) + End If + End If + + If (Bitmap) Then + Dim hMemDC As Long + Dim hBitmap As Long + Dim hBitmapOld As Long + Dim tBF As BLENDFUNCTION + Dim lBF As Long + + hMemDC = CreateCompatibleDC(0) + If (hMemDC) Then + hBitmap = FreeImage_GetBitmap(Bitmap, hMemDC) + hBitmapOld = SelectObject(hMemDC, hBitmap) + + With tBF + .BlendOp = AC_SRC_OVER + .SourceConstantAlpha = Alpha + If (FreeImage_GetBPP(Bitmap) = 32) Then + .AlphaFormat = AC_SRC_ALPHA + End If + End With + Call CopyMemory(lBF, tBF, 4) + + Call AlphaBlend(hDC, XDst, YDst, WidthDst, HeightDst, _ + hMemDC, XSrc, YSrc, WidthSrc, HeightSrc, _ + lBF) + + Call SelectObject(hMemDC, hBitmapOld) + Call DeleteObject(hBitmap) + Call DeleteDC(hMemDC) + If (lpPalette) Then + Call FreeImage_Unload(Bitmap) + End If + End If + End If + End If + +End Function + + +'-------------------------------------------------------------------------------- +' Pixel access functions +'-------------------------------------------------------------------------------- + +Public Function FreeImage_GetBitsEx(ByVal Bitmap As Long) As Byte() + +Dim tSA As SAVEARRAY2D +Dim lpSA As Long + + ' This function returns a two dimensional Byte array containing a DIB's + ' data-bits. This is done by wrapping a true VB array around the memory + ' block the returned pointer of FreeImage_GetBits() is pointing to. So, the + ' array returned provides full read and write acces to the image's data. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the FreeImage_DestroyLockedArray() function. + + If (Bitmap) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 1 ' size in bytes per array element + .cDims = 2 ' the array has 2 dimensions + .cElements1 = FreeImage_GetHeight(Bitmap) ' the number of elements in y direction (height of Bitmap) + .cElements2 = FreeImage_GetPitch(Bitmap) ' the number of elements in x direction (byte width of Bitmap) + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetBits(Bitmap) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' allocate memory for an array descriptor + ' we cannot use the memory block used by tSA, since it is + ' released when tSA goes out of scope, leaving us with an + ' array with zeroed descriptor + ' we use nearly the same method that VB uses, so VB is able + ' to cleanup the array variable and it's descriptor; the + ' array data is not touched when cleaning up, since both AUTO + ' and FIXEDSIZE flags are set + Call SafeArrayAllocDescriptor(2, lpSA) + + ' copy our own array descriptor over the descriptor allocated + ' by SafeArrayAllocDescriptor; lpSA is a pointer to that memory + ' location + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + + ' the implicit variable named like the function is an array + ' variable in VB + ' make it point to the allocated array descriptor + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetBitsEx), lpSA, 4) + End If + +End Function + +Public Function FreeImage_GetBitsExRGBTRIPLE(ByVal Bitmap As Long) As RGBTRIPLE() + +Dim tSA As SAVEARRAY2D +Dim lpSA As Long + + ' This function returns a two dimensional RGBTRIPLE array containing a DIB's + ' data-bits. This is done by wrapping a true VB array around the memory + ' block the returned pointer of 'FreeImage_GetBits' is pointing to. So, the + ' array returned provides full read and write acces to the image's data. + + ' This function only works with 24 bpp images and, since each FreeImage scanline + ' is aligned to a 32-bit boundary, only if the image's width in pixels multiplied + ' by three modulo four is zero. That means, that the image layout in memory must + ' "naturally" be aligned to a 32-bit boundary, since arrays do not support padding. + + ' So, the function only returns an initialized array, if this equotion is true: + ' (((ImageWidthPixels * 3) Mod 4) = 0) + + ' In other words, this is true for all images with no padding. + + ' For instance, only images with these widths will be suitable for this function: + ' 100, 104, 108, 112, 116, 120, 124, ... + + ' Have a look at the wrapper function 'FreeImage_GetScanlinesRGBTRIPLE()' to have + ' a way to work around that limitation. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArray' function. + + If (Bitmap) Then + + If (FreeImage_GetBPP(Bitmap) = 24) Then + If (((FreeImage_GetWidth(Bitmap) * 3) Mod 4) = 0) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 3 ' size in bytes per array element + .cDims = 2 ' the array has 2 dimensions + .cElements1 = FreeImage_GetHeight(Bitmap) ' the number of elements in y direction (height of Bitmap) + .cElements2 = FreeImage_GetWidth(Bitmap) ' the number of elements in x direction (byte width of Bitmap) + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetBits(Bitmap) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' allocate memory for an array descriptor + ' we cannot use the memory block used by tSA, since it is + ' released when tSA goes out of scope, leaving us with an + ' array with zeroed descriptor + ' we use nearly the same method that VB uses, so VB is able + ' to cleanup the array variable and it's descriptor; the + ' array data is not touched when cleaning up, since both AUTO + ' and FIXEDSIZE flags are set + Call SafeArrayAllocDescriptor(2, lpSA) + + ' copy our own array descriptor over the descriptor allocated + ' by SafeArrayAllocDescriptor; lpSA is a pointer to that memory + ' location + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + + ' the implicit variable named like the function is an array + ' variable in VB + ' make it point to the allocated array descriptor + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetBitsExRGBTRIPLE), lpSA, 4) + Else + + ' we could throw an error here + End If + Else + + ' we could throw an error here + End If + End If + +End Function + +Public Function FreeImage_GetBitsExRGBQUAD(ByVal Bitmap As Long) As RGBQUAD() + +Dim tSA As SAVEARRAY2D +Dim lpSA As Long + + ' This function returns a two dimensional RGBQUAD array containing a DIB's + ' data-bits. This is done by wrapping a true VB array around the memory + ' block the returned pointer of 'FreeImage_GetBits' is pointing to. So, the + ' array returned provides full read and write acces to the image's data. + + ' This function only works with 32 bpp images. Since each scanline must + ' "naturally" start at a 32-bit boundary if each pixel uses 32 bits, there + ' are no padding problems like these known with 'FreeImage_GetBitsExRGBTRIPLE', + ' so, this function is suitable for all 32 bpp images of any size. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArray' function. + + If (Bitmap) Then + + If (FreeImage_GetBPP(Bitmap) = 32) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 4 ' size in bytes per array element + .cDims = 2 ' the array has 2 dimensions + .cElements1 = FreeImage_GetHeight(Bitmap) ' the number of elements in y direction (height of Bitmap) + .cElements2 = FreeImage_GetWidth(Bitmap) ' the number of elements in x direction (byte width of Bitmap) + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetBits(Bitmap) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' allocate memory for an array descriptor + ' we cannot use the memory block used by tSA, since it is + ' released when tSA goes out of scope, leaving us with an + ' array with zeroed descriptor + ' we use nearly the same method that VB uses, so VB is able + ' to cleanup the array variable and it's descriptor; the + ' array data is not touched when cleaning up, since both AUTO + ' and FIXEDSIZE flags are set + Call SafeArrayAllocDescriptor(2, lpSA) + + ' copy our own array descriptor over the descriptor allocated + ' by SafeArrayAllocDescriptor; lpSA is a pointer to that memory + ' location + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + + ' the implicit variable named like the function is an array + ' variable in VB + ' make it point to the allocated array descriptor + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetBitsExRGBQUAD), lpSA, 4) + Else + + ' we could throw an error here + End If + End If + +End Function + +Public Function FreeImage_GetScanLinesRGBTRIPLE(ByVal Bitmap As Long, _ + ByRef Scanlines As ScanLinesRGBTRIBLE, _ + Optional ByVal Reverse As Boolean) As Long +Dim lHeight As Long +Dim i As Long + + ' still undocumented + ' for now, have a look at function FreeImage_GetBitsExRGBTRIPLE() + + If (Bitmap) Then + If (FreeImage_GetImageType(Bitmap) = FIT_BITMAP) Then + If (FreeImage_GetBPP(Bitmap) = 24) Then + + lHeight = FreeImage_GetHeight(Bitmap) + ReDim Scanlines.Scanline(lHeight - 1) + For i = 0 To lHeight - 1 + If (Not Reverse) Then + Scanlines.Scanline(i).Data = FreeImage_GetScanLineBITMAP24(Bitmap, i) + Else + Scanlines.Scanline(i).Data = FreeImage_GetScanLineBITMAP24(Bitmap, lHeight - i - 1) + End If + Next i + End If + End If + End If + + FreeImage_GetScanLinesRGBTRIPLE = lHeight + +End Function + +Public Function FreeImage_GetScanLineEx(ByVal Bitmap As Long, _ + ByVal Scanline As Long) As Byte() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long + + ' This function returns a one dimensional Byte array containing a whole + ' scanline's data-bits. This is done by wrapping a true VB array around + ' the memory block the returned pointer of 'FreeImage_GetScanline' is + ' pointing to. So, the array returned provides full read and write acces + ' to the image's data. + + ' This is the most generic function of a complete function set dealing with + ' scanline data, since this function returns an array of type Byte. It is + ' up to the caller of the function to interpret these bytes correctly, + ' according to the results of FreeImage_GetBPP and FreeImage_GetImageType. + + ' You may consider using any of the non-generic functions named + ' 'FreeImage_GetScanLineXXX', that return an array of proper type, according + ' to the images bit depth and type. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArray' function. + + If (Bitmap) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 1 ' size in bytes per array element + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetLine(Bitmap) ' the number of elements in the array + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetScanline(Bitmap, _ + Scanline) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' allocate memory for an array descriptor + ' we cannot use the memory block used by tSA, since it is + ' released when tSA goes out of scope, leaving us with an + ' array with zeroed descriptor + ' we use nearly the same method that VB uses, so VB is able + ' to cleanup the array variable and it's descriptor; the + ' array data is not touched when cleaning up, since both AUTO + ' and FIXEDSIZE flags are set + Call SafeArrayAllocDescriptor(1, lpSA) + + ' copy our own array descriptor over the descriptor allocated + ' by SafeArrayAllocDescriptor; lpSA is a pointer to that memory + ' location + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + + ' the implicit variable named like the function is an array + ' variable in VB + ' make it point to the allocated array descriptor + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineEx), lpSA, 4) + End If + +End Function + +Public Function FreeImage_GetScanLineBITMAP8(ByVal Bitmap As Long, _ + ByVal Scanline As Long) As Byte() + + ' This function returns a one dimensional Byte array containing a whole + ' scanline's data-bits of a 8 bit bitmap image. This is done by wrapping + ' a true VB array around the memory block the returned pointer of + ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides + ' full read and write acces to the image's data. + + ' This function is just a thin wrapper for 'FreeImage_GetScanLineEx' but + ' includes checking of the image's bit depth and type, as all of the + ' non-generic scanline functions do. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArray' function. + + If (FreeImage_GetImageType(Bitmap) = FIT_BITMAP) Then + Select Case FreeImage_GetBPP(Bitmap) + + Case 1, 4, 8 + FreeImage_GetScanLineBITMAP8 = FreeImage_GetScanLineEx(Bitmap, Scanline) + + End Select + End If + +End Function + +Public Function FreeImage_GetScanLineBITMAP16(ByVal Bitmap As Long, _ + ByVal Scanline As Long) As Integer() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long + + ' This function returns a one dimensional Integer array containing a whole + ' scanline's data-bits of a 16 bit bitmap image. This is done by wrapping + ' a true VB array around the memory block the returned pointer of + ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides + ' full read and write acces to the image's data. + + ' The function includes checking of the image's bit depth and type and + ' returns a non-initialized array if 'Bitmap' is an image of improper type. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArray' function. + + If (FreeImage_GetImageType(Bitmap) = FIT_BITMAP) Then + If (FreeImage_GetBPP(Bitmap) = 16) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 2 ' size in bytes per array element + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetScanline(Bitmap, _ + Scanline) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' For a complete source code documentation have a + ' look at the function 'FreeImage_GetScanLineEx' + Call SafeArrayAllocDescriptor(1, lpSA) + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineBITMAP16), lpSA, 4) + End If + End If + +End Function + +Public Function FreeImage_GetScanLineBITMAP24(ByVal Bitmap As Long, _ + ByVal Scanline As Long) As RGBTRIPLE() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long + + ' This function returns a one dimensional RGBTRIPLE array containing a whole + ' scanline's data-bits of a 24 bit bitmap image. This is done by wrapping + ' a true VB array around the memory block the returned pointer of + ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides + ' full read and write acces to the image's data. + + ' The function includes checking of the image's bit depth and type and + ' returns a non-initialized array if 'Bitmap' is an image of improper type. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArrayRGBTRIPLE' function. + + If (FreeImage_GetImageType(Bitmap) = FIT_BITMAP) Then + If (FreeImage_GetBPP(Bitmap) = 24) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 3 ' size in bytes per array element + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetScanline(Bitmap, _ + Scanline) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' For a complete source code documentation have a + ' look at the function 'FreeImage_GetScanLineEx' + Call SafeArrayAllocDescriptor(1, lpSA) + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineBITMAP24), lpSA, 4) + End If + End If + +End Function + +Public Function FreeImage_GetScanLineBITMAP32(ByVal Bitmap As Long, _ + ByVal Scanline As Long) As RGBQUAD() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long + + ' This function returns a one dimensional RGBQUAD array containing a whole + ' scanline's data-bits of a 32 bit bitmap image. This is done by wrapping + ' a true VB array around the memory block the returned pointer of + ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides + ' full read and write acces to the image's data. + + ' The function includes checking of the image's bit depth and type and + ' returns a non-initialized array if 'Bitmap' is an image of improper type. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArrayRGBQUAD' function. + + If (FreeImage_GetImageType(Bitmap) = FIT_BITMAP) Then + If (FreeImage_GetBPP(Bitmap) = 32) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 4 ' size in bytes per array element + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetScanline(Bitmap, _ + Scanline) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' For a complete source code documentation have a + ' look at the function 'FreeImage_GetScanLineEx' + Call SafeArrayAllocDescriptor(1, lpSA) + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineBITMAP32), lpSA, 4) + End If + End If + +End Function + +Public Function FreeImage_GetScanLineINT16(ByVal Bitmap As Long, _ + ByVal Scanline As Long) As Integer() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long +Dim eImageType As FREE_IMAGE_TYPE + + ' This function returns a one dimensional Integer array containing a whole + ' scanline's data-bits of a FIT_INT16 or FIT_UINT16 image. This is done + ' by wrapping a true VB array around the memory block the returned pointer + ' of 'FreeImage_GetScanline' is pointing to. So, the array returned + ' provides full read and write acces to the image's data. + + ' The function includes checking of the image's bit depth and type and + ' returns a non-initialized array if 'Bitmap' is an image of improper type. + + ' Since VB does not distinguish between signed and unsigned data types, both + ' image types FIT_INT16 and FIT_UINT16 are handled with this function. If 'Bitmap' + ' specifies an image of type FIT_UINT16, it is up to the caller to treat the + ' array's Integers as unsigned, although VB knows signed Integers only. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArray' function. + + eImageType = FreeImage_GetImageType(Bitmap) + If ((eImageType = FIT_INT16) Or _ + (eImageType = FIT_UINT16)) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 2 ' size in bytes per array element + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetScanline(Bitmap, _ + Scanline) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' For a complete source code documentation have a + ' look at the function 'FreeImage_GetScanLineEx' + Call SafeArrayAllocDescriptor(1, lpSA) + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineINT16), lpSA, 4) + End If + +End Function + +Public Function FreeImage_GetScanLineINT32(ByVal Bitmap As Long, _ + ByVal Scanline As Long) As Long() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long +Dim eImageType As FREE_IMAGE_TYPE + + ' This function returns a one dimensional Long array containing a whole + ' scanline's data-bits of a FIT_INT32 or FIT_UINT32 image. This is done + ' by wrapping a true VB array around the memory block the returned pointer + ' of 'FreeImage_GetScanline' is pointing to. So, the array returned + ' provides full read and write acces to the image's data. + + ' The function includes checking of the image's bit depth and type and + ' returns a non-initialized array if 'Bitmap' is an image of improper type. + + ' Since VB does not distinguish between signed and unsigned data types, both + ' image types FIT_INT32 and FIT_UINT32 are handled with this function. If 'Bitmap' + ' specifies an image of type FIT_UINT32, it is up to the caller to treat the + ' array's Longs as unsigned, although VB knows signed Longs only. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArray' function. + + eImageType = FreeImage_GetImageType(Bitmap) + If ((eImageType = FIT_INT32) Or _ + (eImageType = FIT_UINT32)) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 4 ' size in bytes per array element + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetScanline(Bitmap, _ + Scanline) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' For a complete source code documentation have a + ' look at the function 'FreeImage_GetScanLineEx' + Call SafeArrayAllocDescriptor(1, lpSA) + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineINT32), lpSA, 4) + End If + +End Function + +Public Function FreeImage_GetScanLineFLOAT(ByVal Bitmap As Long, _ + ByVal Scanline As Long) As Single() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long +Dim eImageType As FREE_IMAGE_TYPE + + ' This function returns a one dimensional Single array containing a whole + ' scanline's data-bits of a FIT_FLOAT image. This is done by wrapping + ' a true VB array around the memory block the returned pointer of + ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides + ' full read and write acces to the image's data. + + ' The function includes checking of the image's bit depth and type and + ' returns a non-initialized array if 'Bitmap' is an image of improper type. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArray' function. + + eImageType = FreeImage_GetImageType(Bitmap) + If (eImageType = FIT_FLOAT) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 4 ' size in bytes per array element + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetScanline(Bitmap, _ + Scanline) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' For a complete source code documentation have a + ' look at the function 'FreeImage_GetScanLineEx' + Call SafeArrayAllocDescriptor(1, lpSA) + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineFLOAT), lpSA, 4) + End If + +End Function + +Public Function FreeImage_GetScanLineDOUBLE(ByVal Bitmap As Long, _ + ByVal Scanline As Long) As Double() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long +Dim eImageType As FREE_IMAGE_TYPE + + ' This function returns a one dimensional Double array containing a whole + ' scanline's data-bits of a FIT_DOUBLE image. This is done by wrapping + ' a true VB array around the memory block the returned pointer of + ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides + ' full read and write acces to the image's data. + + ' The function includes checking of the image's bit depth and type and + ' returns a non-initialized array if 'Bitmap' is an image of improper type. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArray' function. + + eImageType = FreeImage_GetImageType(Bitmap) + If (eImageType = FIT_DOUBLE) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 8 ' size in bytes per array element + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetScanline(Bitmap, _ + Scanline) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' For a complete source code documentation have a + ' look at the function 'FreeImage_GetScanLineEx' + Call SafeArrayAllocDescriptor(1, lpSA) + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineDOUBLE), lpSA, 4) + End If + +End Function + +Public Function FreeImage_GetScanLineCOMPLEX(ByVal Bitmap As Long, _ + ByVal Scanline As Long) As FICOMPLEX() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long +Dim eImageType As FREE_IMAGE_TYPE + + ' This function returns a one dimensional FICOMPLEX array containing a whole + ' scanline's data-bits of a FIT_COMPLEX image. This is done by wrapping + ' a true VB array around the memory block the returned pointer of + ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides + ' full read and write acces to the image's data. + + ' The function includes checking of the image's bit depth and type and + ' returns a non-initialized array if 'Bitmap' is an image of improper type. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArrayFICOMPLEX' function. + + eImageType = FreeImage_GetImageType(Bitmap) + If (eImageType = FIT_COMPLEX) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 16 ' size in bytes per array element + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetScanline(Bitmap, _ + Scanline) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' For a complete source code documentation have a + ' look at the function 'FreeImage_GetScanLineEx' + Call SafeArrayAllocDescriptor(1, lpSA) + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineCOMPLEX), lpSA, 4) + End If + +End Function + +Public Function FreeImage_GetScanLineRGB16(ByVal Bitmap As Long, _ + ByVal Scanline As Long) As FIRGB16() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long +Dim eImageType As FREE_IMAGE_TYPE + + ' This function returns a one dimensional FIRGB16 array containing a whole + ' scanline's data-bits of a FIT_RGB16 image. This is done by wrapping + ' a true VB array around the memory block the returned pointer of + ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides + ' full read and write acces to the image's data. + + ' The function includes checking of the image's bit depth and type and + ' returns a non-initialized array if 'Bitmap' is an image of improper type. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArrayFIRGB16' function. + + eImageType = FreeImage_GetImageType(Bitmap) + If (eImageType = FIT_RGB16) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 6 ' size in bytes per array element + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetScanline(Bitmap, _ + Scanline) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' For a complete source code documentation have a + ' look at the function 'FreeImage_GetScanLineEx' + Call SafeArrayAllocDescriptor(1, lpSA) + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineRGB16), lpSA, 4) + End If + +End Function + +Public Function FreeImage_GetScanLineRGBA16(ByVal Bitmap As Long, _ + ByVal Scanline As Long) As FIRGBA16() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long +Dim eImageType As FREE_IMAGE_TYPE + + ' This function returns a one dimensional FIRGBA16 array containing a whole + ' scanline's data-bits of a FIT_RGBA16 image. This is done by wrapping + ' a true VB array around the memory block the returned pointer of + ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides + ' full read and write acces to the image's data. + + ' The function includes checking of the image's bit depth and type and + ' returns a non-initialized array if 'Bitmap' is an image of improper type. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArrayFIRGBA16' function. + + eImageType = FreeImage_GetImageType(Bitmap) + If (eImageType = FIT_RGBA16) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 8 ' size in bytes per array element + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetScanline(Bitmap, _ + Scanline) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' For a complete source code documentation have a + ' look at the function 'FreeImage_GetScanLineEx' + Call SafeArrayAllocDescriptor(1, lpSA) + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineRGBA16), lpSA, 4) + End If + +End Function + +Public Function FreeImage_GetScanLineRGBF(ByVal Bitmap As Long, _ + ByVal Scanline As Long) As FIRGBF() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long +Dim eImageType As FREE_IMAGE_TYPE + + ' This function returns a one dimensional FIRGBF array containing a whole + ' scanline's data-bits of a FIT_RGBF image. This is done by wrapping + ' a true VB array around the memory block the returned pointer of + ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides + ' full read and write acces to the image's data. + + ' The function includes checking of the image's bit depth and type and + ' returns a non-initialized array if 'Bitmap' is an image of improper type. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArrayFIRGBF' function. + + eImageType = FreeImage_GetImageType(Bitmap) + If (eImageType = FIT_RGBF) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 12 ' size in bytes per array element + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetScanline(Bitmap, _ + Scanline) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' For a complete source code documentation have a + ' look at the function 'FreeImage_GetScanLineEx' + Call SafeArrayAllocDescriptor(1, lpSA) + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineRGBF), lpSA, 4) + End If + +End Function + +Public Function FreeImage_GetScanLineRGBAF(ByVal Bitmap As Long, _ + ByVal Scanline As Long) As FIRGBAF() + +Dim tSA As SAVEARRAY1D +Dim lpSA As Long +Dim eImageType As FREE_IMAGE_TYPE + + ' This function returns a one dimensional FIRGBAF array containing a whole + ' scanline's data-bits of a FIT_RGBAF image. This is done by wrapping + ' a true VB array around the memory block the returned pointer of + ' 'FreeImage_GetScanline' is pointing to. So, the array returned provides + ' full read and write acces to the image's data. + + ' The function includes checking of the image's bit depth and type and + ' returns a non-initialized array if 'Bitmap' is an image of improper type. + + ' To reuse the caller's array variable, this function's result was assigned to, + ' before it goes out of scope, the caller's array variable must be destroyed with + ' the 'FreeImage_DestroyLockedArrayFIRGBAF' function. + + eImageType = FreeImage_GetImageType(Bitmap) + If (eImageType = FIT_RGBAF) Then + + ' create a proper SAVEARRAY descriptor + With tSA + .cbElements = 12 ' size in bytes per array element + .cDims = 1 ' the array has only 1 dimension + .cElements = FreeImage_GetWidth(Bitmap) ' the number of elements in the array + .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE ' need AUTO and FIXEDSIZE for safety issues, + ' so the array can not be modified in size + ' or erased; according to Matthew Curland never + ' use FIXEDSIZE alone + .pvData = FreeImage_GetScanline(Bitmap, _ + Scanline) ' let the array point to the memory block, the + ' FreeImage scanline data pointer points to + End With + + ' For a complete source code documentation have a + ' look at the function 'FreeImage_GetScanLineEx' + Call SafeArrayAllocDescriptor(1, lpSA) + Call CopyMemory(ByVal lpSA, tSA, Len(tSA)) + Call CopyMemory(ByVal VarPtrArray(FreeImage_GetScanLineRGBAF), lpSA, 4) + End If + +End Function + +'-------------------------------------------------------------------------------- +' HBITMAP conversion functions +'-------------------------------------------------------------------------------- + +Public Function FreeImage_GetBitmap(ByVal Bitmap As Long, _ + Optional ByVal hDC As Long, _ + Optional ByVal UnloadSource As Boolean) As Long + +Dim bReleaseDC As Boolean +Dim ppvBits As Long + + ' This function returns an HBITMAP created by the CreateDIBSection() function which + ' in turn has the same color depth as the original DIB. A reference DC may be provided + ' through the 'hDC' parameter. The desktop DC will be used, if no reference DC is + ' specified. + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to create a bitmap from a 'header-only' bitmap.") + End If + + If (hDC = 0) Then + hDC = GetDC(0) + bReleaseDC = True + End If + If (hDC) Then + FreeImage_GetBitmap = CreateDIBSection(hDC, FreeImage_GetInfo(Bitmap), _ + DIB_RGB_COLORS, ppvBits, 0, 0) + If ((FreeImage_GetBitmap <> 0) And (ppvBits <> 0)) Then + Call CopyMemory(ByVal ppvBits, ByVal FreeImage_GetBits(Bitmap), _ + FreeImage_GetHeight(Bitmap) * FreeImage_GetPitch(Bitmap)) + End If + If (UnloadSource) Then + Call FreeImage_Unload(Bitmap) + End If + If (bReleaseDC) Then + Call ReleaseDC(0, hDC) + End If + End If + End If + +End Function + +Public Function FreeImage_GetBitmapForDevice(ByVal Bitmap As Long, _ + Optional ByVal hDC As Long, _ + Optional ByVal UnloadSource As Boolean) As Long + +Dim bReleaseDC As Boolean + + ' This function returns an HBITMAP created by the CreateDIBitmap() function which + ' in turn has always the same color depth as the reference DC, which may be provided + ' through the 'hDC' parameter. The desktop DC will be used, if no reference DC is + ' specified. + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to create a bitmap from a 'header-only' bitmap.") + End If + + If (hDC = 0) Then + hDC = GetDC(0) + bReleaseDC = True + End If + If (hDC) Then + FreeImage_GetBitmapForDevice = _ + CreateDIBitmap(hDC, FreeImage_GetInfoHeader(Bitmap), CBM_INIT, _ + FreeImage_GetBits(Bitmap), FreeImage_GetInfo(Bitmap), _ + DIB_RGB_COLORS) + If (UnloadSource) Then + Call FreeImage_Unload(Bitmap) + End If + If (bReleaseDC) Then + Call ReleaseDC(0, hDC) + End If + End If + End If + +End Function + +'-------------------------------------------------------------------------------- +' OlePicture conversion functions +'-------------------------------------------------------------------------------- + +Public Function FreeImage_GetOlePicture(ByVal Bitmap As Long, _ + Optional ByVal hDC As Long, _ + Optional ByVal UnloadSource As Boolean) As IPicture + +Dim hBitmap As Long +Dim tPicDesc As PictDesc +Dim tGuid As Guid +Dim cPictureDisp As IPictureDisp + + ' This function creates a VB Picture object (OlePicture) from a FreeImage DIB. + ' The original image need not remain valid nor loaded after the VB Picture + ' object has been created. + + ' The optional parameter 'hDC' determines the device context (DC) used for + ' transforming the device independent bitmap (DIB) to a device dependent + ' bitmap (DDB). This device context's color depth is responsible for this + ' transformation. This parameter may be null or omitted. In that case, the + ' windows desktop's device context will be used, what will be the desired + ' way in almost any cases. + + ' The optional 'UnloadSource' parameter is for unloading the original image + ' after the OlePicture has been created, so you can easily "switch" from a + ' FreeImage DIB to a VB Picture object. There is no need to unload the DIB + ' at the caller's site if this argument is True. + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to create a picture from a 'header-only' bitmap.") + End If + + hBitmap = FreeImage_GetBitmapForDevice(Bitmap, hDC, UnloadSource) + If (hBitmap) Then + ' fill tPictDesc structure with necessary parts + With tPicDesc + .cbSizeofStruct = Len(tPicDesc) + ' the vbPicTypeBitmap constant is not available in VBA environemnts + .picType = 1 'vbPicTypeBitmap + .hImage = hBitmap + End With + + ' fill in IDispatch Interface ID + With tGuid + .Data1 = &H20400 + .Data4(0) = &HC0 + .Data4(7) = &H46 + End With + + ' create a picture object + Call OleCreatePictureIndirect(tPicDesc, tGuid, True, cPictureDisp) + Set FreeImage_GetOlePicture = cPictureDisp + End If + End If + +End Function + +Public Function FreeImage_GetOlePictureIcon(ByVal hIcon As Long) As IPicture + +Dim tPicDesc As PictDesc +Dim tGuid As Guid +Dim cPictureDisp As IPictureDisp + + ' This function creates a VB Picture object (OlePicture) of type picTypeIcon + ' from FreeImage hIcon handle. The hIcon handle need not remain valid nor loaded + ' after the VB Picture object has been created. + + ' The optional 'UnloadSource' parameter is for destroying the hIcon image + ' after the OlePicture has been created, so you can easiely "switch" from a + ' hIcon handle to a VB Picture object. There is no need to unload the hIcon + ' at the caller's site if this argument is True. + + If (hIcon) Then + ' fill tPictDesc structure with necessary parts + With tPicDesc + .cbSizeofStruct = 12 + ' the vbPicTypeIcon constant is not available in VBA environemnts + .picType = 3 'vbPicTypeIcon + .hImage = hIcon + End With + + ' fill in IDispatch Interface ID + With tGuid + .Data1 = &H20400 + .Data4(0) = &HC0 + .Data4(7) = &H46 + End With + + ' create a picture object + Call OleCreatePictureIndirect(tPicDesc, tGuid, True, cPictureDisp) + Set FreeImage_GetOlePictureIcon = cPictureDisp + End If + +End Function + +Public Function FreeImage_GetOlePictureThumbnail(ByVal Bitmap As Long, _ + ByVal MaxPixelSize As Long, _ + Optional ByVal hDC As Long, _ + Optional ByVal UnloadSource As Boolean) As IPicture + +Dim hDIBThumbnail As Long + + ' This function is a IOlePicture aware wrapper for FreeImage_MakeThumbnail(). It + ' returns a VB Picture object instead of a FreeImage DIB. + + ' The optional 'UnloadSource' parameter is for unloading the original image + ' after the OlePicture has been created, so you can easiely "switch" from a + ' FreeImage DIB to a VB Picture object. There is no need to clean up the DIB + ' at the caller's site. + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to create a thumbnail picture from a 'header-only' bitmap.") + End If + + hDIBThumbnail = FreeImage_MakeThumbnail(Bitmap, MaxPixelSize) + Set FreeImage_GetOlePictureThumbnail = FreeImage_GetOlePicture(hDIBThumbnail, hDC, True) + + If (UnloadSource) Then + Call FreeImage_Unload(Bitmap) + End If + End If + +End Function + +Public Function FreeImage_CreateFromOlePicture(ByRef Picture As IPicture) As Long + +Dim hBitmap As Long +Dim tBM As BITMAP_API +Dim hDIB As Long +Dim hDC As Long +Dim lResult As Long +Dim nColors As Long +Dim lpInfo As Long + + ' Creates a FreeImage DIB from a VB Picture object (OlePicture). This function + ' returns a pointer to the DIB as, for instance, the FreeImage function + ' 'FreeImage_Load' does. So, this could be a real replacement for 'FreeImage_Load' + ' when working with VB Picture objects. + + If (Not Picture Is Nothing) Then + hBitmap = Picture.Handle + If (hBitmap) Then + lResult = GetObjectAPI(hBitmap, Len(tBM), tBM) + If (lResult) Then + hDIB = FreeImage_Allocate(tBM.bmWidth, _ + tBM.bmHeight, _ + tBM.bmBitsPixel) + If (hDIB) Then + ' The GetDIBits function clears the biClrUsed and biClrImportant BITMAPINFO + ' members (dont't know why). So we save these infos below. + ' This is needed for palletized images only. + nColors = FreeImage_GetColorsUsed(hDIB) + + hDC = GetDC(0) + lResult = GetDIBits(hDC, hBitmap, 0, _ + FreeImage_GetHeight(hDIB), _ + FreeImage_GetBits(hDIB), _ + FreeImage_GetInfo(hDIB), _ + DIB_RGB_COLORS) + If (lResult) Then + FreeImage_CreateFromOlePicture = hDIB + If (nColors) Then + ' restore BITMAPINFO members + ' FreeImage_GetInfo(Bitmap)->biClrUsed = nColors; + ' FreeImage_GetInfo(Bitmap)->biClrImportant = nColors; + lpInfo = FreeImage_GetInfo(hDIB) + Call CopyMemory(ByVal lpInfo + 32, nColors, 4) + Call CopyMemory(ByVal lpInfo + 36, nColors, 4) + End If + Else + Call FreeImage_Unload(hDIB) + End If + Call ReleaseDC(0, hDC) + End If + End If + End If + End If + +End Function + +Public Function FreeImage_CreateFromDC(ByVal hDC As Long, _ + Optional ByRef hBitmap As Long) As Long + +Dim tBM As BITMAP_API +Dim hDIB As Long +Dim lResult As Long +Dim nColors As Long +Dim lpInfo As Long + + ' Creates a FreeImage DIB from a Device Context/Compatible Bitmap. This + ' function returns a pointer to the DIB as, for instance, 'FreeImage_Load()' + ' does. So, this could be a real replacement for FreeImage_Load() or + ' 'FreeImage_CreateFromOlePicture()' when working with DCs and BITMAPs directly + + ' The 'hDC' parameter specifies a window device context (DC), the optional + ' parameter 'hBitmap' may specify a handle to a memory bitmap. When 'hBitmap' is + ' omitted, the bitmap currently selected into the given DC is used to create + ' the DIB. + + ' When 'hBitmap' is not missing but NULL (0), the function uses the DC's currently + ' selected bitmap. This bitmap's handle is stored in the ('ByRef'!) 'hBitmap' parameter + ' and so, is avaliable at the caller's site when the function returns. + + ' The DIB returned by this function is a copy of the image specified by 'hBitmap' or + ' the DC's current bitmap when 'hBitmap' is missing. The 'hDC' and also the 'hBitmap' + ' remain untouched in this function, there will be no objects destroyed or freed. + ' The caller is responsible to destroy or free the DC and BITMAP if necessary. + + ' first, check whether we got a hBitmap or not + If (hBitmap = 0) Then + ' if not, the parameter may be missing or is NULL so get the + ' DC's current bitmap + hBitmap = GetCurrentObject(hDC, OBJ_BITMAP) + End If + + lResult = GetObjectAPI(hBitmap, Len(tBM), tBM) + If (lResult) Then + hDIB = FreeImage_Allocate(tBM.bmWidth, _ + tBM.bmHeight, _ + tBM.bmBitsPixel) + If (hDIB) Then + ' The GetDIBits function clears the biClrUsed and biClrImportant BITMAPINFO + ' members (dont't know why). So we save these infos below. + ' This is needed for palletized images only. + nColors = FreeImage_GetColorsUsed(hDIB) + + lResult = GetDIBits(hDC, hBitmap, 0, _ + FreeImage_GetHeight(hDIB), _ + FreeImage_GetBits(hDIB), _ + FreeImage_GetInfo(hDIB), _ + DIB_RGB_COLORS) + + If (lResult) Then + FreeImage_CreateFromDC = hDIB + If (nColors) Then + ' restore BITMAPINFO members + ' FreeImage_GetInfo(Bitmap)->biClrUsed = nColors; + ' FreeImage_GetInfo(Bitmap)->biClrImportant = nColors; + lpInfo = FreeImage_GetInfo(hDIB) + Call CopyMemory(ByVal lpInfo + 32, nColors, 4) + Call CopyMemory(ByVal lpInfo + 36, nColors, 4) + End If + Else + Call FreeImage_Unload(hDIB) + End If + End If + End If + +End Function + +Public Function FreeImage_CreateFromImageContainer(ByRef Container As Object, _ + Optional ByVal IncludeDrawings As Boolean) As Long + + ' Creates a FreeImage DIB from a VB container control that has at least a + ' 'Picture' property. This function returns a pointer to the DIB as, for + ' instance, 'FreeImage_Load()' does. So, this could be a real replacement for + ' FreeImage_Load() or 'FreeImage_CreateFromOlePicture()' when working with + ' image hosting controls like Forms or PictureBoxes. + + ' The 'IncludeDrawings' parameter controls whether drawings, drawn with VB + ' methods like 'Container.Print()', 'Container.Line(x1, y1)-(x2, y2)' or + ' 'Container.Circle(x, y), radius' as the controls 'BackColor' should be included + ' into the newly created DIB. However, this only works, with control's that + ' have their 'AutoRedraw' property set to 'True'. + + ' To get the control's picture as well as it's BackColor and custom drawings, + ' this function uses the control's 'Image' property instead of the 'Picture' + ' property. + + ' This function treats Forms and PictureBox controls explicitly, since the + ' property sets and behaviours of these controls are publicly known. For any + ' other control, the function checks for the existence of an 'Image' and + ' 'AutoRedraw' property. If these are present and 'IncludeDrawings' is 'True', + ' the function uses the control's 'Image' property instead of the 'Picture' + ' property. This my be the case for UserControls. In any other case, the function + ' uses the control's 'Picture' property if present. If none of these properties + ' is present, a runtime error (5) is generated. + + ' Most of this function is actually implemented in the wrapper's private helper + ' function 'pGetIOlePictureFromContainer'. + + If (Not Container Is Nothing) Then + FreeImage_CreateFromImageContainer = FreeImage_CreateFromOlePicture( _ + pGetIOlePictureFromContainer(Container, _ + IncludeDrawings)) + End If + +End Function + +Public Function FreeImage_CreateFromScreen(Optional ByVal hWnd As Long, _ + Optional ByVal ClientAreaOnly As Boolean) As Long + +Dim hDC As Long +Dim lWidth As Long +Dim lHeight As Long +Dim hMemDC As Long +Dim hMemBMP As Long +Dim hMemOldBMP As Long +Dim tR As RECT + + ' Creates a FreeImage DIB from the screen which may either be the whole + ' desktop/screen or a certain window. A certain window may be specified + ' by it's window handle through the 'hWnd' parameter. By omitting this + ' parameter, the whole screen/desktop window will be captured. + + If (hWnd = 0) Then + hWnd = GetDesktopWindow() + hDC = GetDCEx(hWnd, 0, 0) + ' get desktop's width and height + lWidth = GetDeviceCaps(hDC, HORZRES) + lHeight = GetDeviceCaps(hDC, VERTRES) + + ElseIf (ClientAreaOnly) Then + ' get window's client area DC + hDC = GetDCEx(hWnd, 0, 0) + Call GetClientRect(hWnd, tR) + lWidth = tR.Right + lHeight = tR.Bottom + + Else + ' get window DC + hDC = GetDCEx(hWnd, 0, DCX_WINDOW) + Call GetWindowRect(hWnd, tR) + lWidth = tR.Right - tR.Left + lHeight = tR.Bottom - tR.Top + + End If + + ' create compatible memory DC and bitmap + hMemDC = CreateCompatibleDC(hDC) + hMemBMP = CreateCompatibleBitmap(hDC, lWidth, lHeight) + ' select compatible bitmap + hMemOldBMP = SelectObject(hMemDC, hMemBMP) + ' blit bits + Call BitBlt(hMemDC, 0, 0, lWidth, lHeight, hDC, 0, 0, SRCCOPY Or CAPTUREBLT) + + ' create FreeImage Bitmap from memory DC + FreeImage_CreateFromScreen = FreeImage_CreateFromDC(hMemDC, hMemBMP) + + ' clean up + Call SelectObject(hMemDC, hMemOldBMP) + Call DeleteObject(hMemBMP) + Call DeleteDC(hMemDC) + Call ReleaseDC(hWnd, hDC) + +End Function + +'-------------------------------------------------------------------------------- +' Microsoft Office / VBA PictureData supporting functions +'-------------------------------------------------------------------------------- + +Public Function FreeImage_GetPictureData(ByVal Bitmap As Long, _ + Optional ByVal UnloadSource As Boolean) As Byte() + +Dim abResult() As Byte +Dim lImageSize As Long +Dim lPaletteSize As Long +Dim abInfoBuffer() As Byte +Dim lpInfo As Long +Dim bBufferUsed As Boolean +Dim lOffset As Long + + ' This function creates an Office PictureData Byte array from a FreeImage DIB. + ' The original image must not remain valid nor loaded after the PictureData + ' array has been created. + + ' The optional 'UnloadSource' parameter is for unloading the original image + ' after the PictureData Byte array has been created, so you can easily "switch" + ' from a FreeImage DIB to an Office PictureData Byte array. There is no need to + ' unload the DIB at the caller's site if this argument is True. + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to create a PictureData array from a 'header-only' bitmap.") + End If + + lImageSize = FreeImage_GetHeight(Bitmap) * FreeImage_GetPitch(Bitmap) + lPaletteSize = FreeImage_GetColorsUsed(Bitmap) * 4 + + ' Copy the BITMAPINFOHEADER into the result array. +''' lpInfo = FreeImage_GetInfoEx(Bitmap, abInfoBuffer, bBufferUsed) +''' If (bBufferUsed) Then +''' ReDim abResult(39 + 12 + lPaletteSize + lImageSize) +''' Call CopyMemory(abResult(0), ByVal lpInfo, 40 + 12) +''' lOffset = 40 + 12 +''' Else +''' ReDim abResult(39 + lPaletteSize + lImageSize) +''' Call CopyMemory(abResult(0), ByVal lpInfo, 40) +''' lOffset = 40 +''' End If + + If (lPaletteSize > 0) Then + ' Copy the image's palette (if any) into the result array. + Call CopyMemory(abResult(lOffset), ByVal FreeImage_GetPalette(Bitmap), lPaletteSize) + lOffset = lOffset + lPaletteSize + End If + + ' Copy the image's bits into the result array. + Call CopyMemory(abResult(lOffset), ByVal FreeImage_GetBits(Bitmap), lImageSize) + + Call pSwap(ByVal VarPtrArray(abResult), ByVal VarPtrArray(FreeImage_GetPictureData)) + + If (UnloadSource) Then + Call FreeImage_Unload(Bitmap) + End If + End If + +End Function + +Public Function FreeImage_CreateFromPictureData(ByRef PictureData() As Byte) As Long + +Dim tBMIH As BITMAPINFOHEADER +Dim lLength As Long +Dim hDIB As Long +Dim lPaletteSize As Long +Dim lOffset As Long +Dim alMasks() As Long + + ' Creates a FreeImage DIB from an Office PictureData Byte array. This function + ' returns a pointer to the DIB as, for instance, the FreeImage function + ' 'FreeImage_Load' does. So, this could be a real replacement for 'FreeImage_Load' + ' when working with PictureData arrays. + + lLength = UBound(PictureData) + 1 + If (lLength > Len(tBMIH)) Then + Call CopyMemory(tBMIH, PictureData(0), Len(tBMIH)) + With tBMIH + If (.biSize = 40) Then + lOffset = 40 + Select Case .biBitCount + + Case 0 + + Case 1, 4, 8 + If (.biClrUsed = 0) Then + lPaletteSize = 2 ^ .biBitCount * 4 + Else + lPaletteSize = .biClrUsed * 4 + End If + hDIB = FreeImage_Allocate(.biWidth, .biHeight, .biBitCount) + Call CopyMemory(ByVal FreeImage_GetPalette(hDIB), _ + PictureData(lOffset), lPaletteSize) + lOffset = lOffset + lPaletteSize + + Case 16 + If (.biCompression = BI_BITFIELDS) Then + ReDim alMasks(2) + Call CopyMemory(alMasks(0), PictureData(lOffset), 12) + lOffset = lOffset + 12 + hDIB = FreeImage_Allocate(.biWidth, .biHeight, .biBitCount, _ + alMasks(0), alMasks(1), alMasks(2)) + Else + hDIB = FreeImage_Allocate(.biWidth, .biHeight, .biBitCount, _ + FI16_555_RED_MASK, FI16_555_GREEN_MASK, FI16_555_BLUE_MASK) + End If + + Case 24, 32 + hDIB = FreeImage_Allocate(.biWidth, .biHeight, .biBitCount) + + End Select + + If (hDIB) Then + Call CopyMemory(ByVal FreeImage_GetBits(hDIB), _ + PictureData(lOffset), lLength - lOffset) + FreeImage_CreateFromPictureData = hDIB + End If + Else + ' ERROR: invalid or unsupported PictureData array + End If + End With + Else + ' ERROR: invalid or unsupported PictureData array + End If + +End Function + +Public Function FreeImage_CreateMask(ByVal hDIB As Long, _ + Optional ByVal eMaskCreationOptions As FREE_IMAGE_MASK_CREATION_OPTION_FLAGS = MCOF_CREATE_MASK_IMAGE, _ + Optional ByVal lBitDepth As Long = 1, _ + Optional ByVal eMaskOptions As FREE_IMAGE_MASK_FLAGS = FIMF_MASK_FULL_TRANSPARENCY, _ + Optional ByVal vntMaskColors As Variant, _ + Optional ByVal eMaskColorsFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ + Optional ByVal lColorTolerance As Long, _ + Optional ByVal lciMaskColorDst As Long = vbWhite, _ + Optional ByVal eMaskColorDstFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ + Optional ByVal lciUnmaskColorDst As Long = vbBlack, _ + Optional ByVal eUnmaskColorDstFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ + Optional ByVal vlciMaskColorSrc As Variant, _ + Optional ByVal eMaskColorSrcFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ + Optional ByVal vlciUnmaskColorSrc As Variant, _ + Optional ByVal eUnmaskColorSrcFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB) As Long + +Dim hDIBResult As Long +Dim lBitDepthSrc As Long +Dim lWidth As Long +Dim lHeight As Long + +Dim bMaskColors As Boolean +Dim bMaskTransparency As Boolean +Dim bMaskFullTransparency As Boolean +Dim bMaskAlphaTransparency As Boolean +Dim bInvertMask As Boolean +Dim bHaveMaskColorSrc As Boolean +Dim bHaveUnmaskColorSrc As Boolean +Dim bCreateMaskImage As Boolean +Dim bModifySourceImage As Boolean +Dim alcMaskColors() As Long +Dim lMaskColorsMaxIndex As Long + +Dim lciMaskColorSrc As Long +Dim lciUnmaskColorSrc As Long + +Dim alPaletteSrc() As Long +Dim abTransparencyTableSrc() As Byte +Dim abBitsBSrc() As Byte +Dim atBitsTSrc As ScanLinesRGBTRIBLE +Dim atBitsQSrc() As RGBQUAD +Dim abBitValues(7) As Byte +Dim abBitMasks(7) As Byte +Dim abBitShifts(7) As Byte + +Dim atPaletteDst() As RGBQUAD +Dim abBitsBDst() As Byte +Dim atBitsTDst As ScanLinesRGBTRIBLE +Dim atBitsQDst() As RGBQUAD + +Dim bMaskPixel As Boolean +Dim X As Long +Dim x2 As Long +Dim lPixelIndex As Long +Dim Y As Long +Dim i As Long + + 'TODO: comment this function + + ' check for a proper bit depth of the destination (mask) image + If ((hDIB) And ((lBitDepth = 1) Or _ + (lBitDepth = 4) Or _ + (lBitDepth = 8) Or _ + (lBitDepth = 24) Or _ + (lBitDepth = 32))) Then + + If (Not FreeImage_HasPixels(hDIB)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to create a mask image from a 'header-only' bitmap.") + End If + + ' check for a proper bit depth of the source image + lBitDepthSrc = FreeImage_GetBPP(hDIB) + If ((lBitDepthSrc = 4) Or _ + (lBitDepthSrc = 8) Or _ + (lBitDepthSrc = 24) Or _ + (lBitDepthSrc = 32)) Then + + + ' get some information from eMaskCreationOptions + bCreateMaskImage = (eMaskCreationOptions And MCOF_CREATE_MASK_IMAGE) + bModifySourceImage = (eMaskCreationOptions And MCOF_MODIFY_SOURCE_IMAGE) + + + If (bCreateMaskImage) Then + + ' check mask color format + If (eMaskColorDstFormat And FICFF_COLOR_BGR) Then + ' if mask color is in BGR format, convert to RGB format + lciMaskColorDst = FreeImage_SwapColorLong(lciMaskColorDst) + + ElseIf (eMaskColorDstFormat And FICFF_COLOR_PALETTE_INDEX) Then + ' if mask color is specified as palette index, check, whether the + ' source image is a palletized image + Select Case lBitDepthSrc + + Case 1 + lciMaskColorDst = FreeImage_GetPaletteExLong(hDIB)(lciMaskColorDst And &H1) + + Case 4 + lciMaskColorDst = FreeImage_GetPaletteExLong(hDIB)(lciMaskColorDst And &HF) + + Case 8 + lciMaskColorDst = FreeImage_GetPaletteExLong(hDIB)(lciMaskColorDst And &HFF) + + End Select + End If + + ' check unmask color format + If (eUnmaskColorDstFormat And FICFF_COLOR_BGR) Then + ' if unmask color is in BGR format, convert to RGB format + lciUnmaskColorDst = FreeImage_SwapColorLong(lciUnmaskColorDst) + + ElseIf (eUnmaskColorDstFormat And FICFF_COLOR_PALETTE_INDEX) Then + ' if unmask color is specified as palette index, check, whether the + ' source image is a palletized image + Select Case lBitDepthSrc + + Case 1 + lciUnmaskColorDst = FreeImage_GetPaletteExLong(hDIB)(lciUnmaskColorDst And &H1) + + Case 4 + lciUnmaskColorDst = FreeImage_GetPaletteExLong(hDIB)(lciUnmaskColorDst And &HF) + + Case 8 + lciUnmaskColorDst = FreeImage_GetPaletteExLong(hDIB)(lciUnmaskColorDst And &HFF) + + End Select + End If + End If + + + If (bModifySourceImage) Then + + ' check, whether source image can be modified + bHaveMaskColorSrc = (Not IsMissing(vlciMaskColorSrc)) + bHaveUnmaskColorSrc = (Not IsMissing(vlciUnmaskColorSrc)) + + Select Case lBitDepthSrc + + Case 4, 8 + If (bHaveMaskColorSrc) Then + + ' get mask color as Long + lciMaskColorSrc = vlciMaskColorSrc + + If (eMaskColorSrcFormat And FICFF_COLOR_PALETTE_INDEX) Then + If (lBitDepthSrc = 4) Then + lciMaskColorSrc = (lciMaskColorSrc And &HF) + Else + lciMaskColorSrc = (lciMaskColorSrc And &HFF) + End If + Else + If (eMaskColorSrcFormat And FICFF_COLOR_BGR) Then + lciMaskColorSrc = FreeImage_SwapColorLong(lciMaskColorSrc, True) + End If + lciMaskColorSrc = FreeImage_SearchPalette(hDIB, lciMaskColorSrc) + bHaveMaskColorSrc = (lciMaskColorSrc <> -1) + End If + End If + + If (bHaveUnmaskColorSrc) Then + + ' get unmask color as Long + lciUnmaskColorSrc = vlciUnmaskColorSrc + + If (eUnmaskColorSrcFormat And FICFF_COLOR_PALETTE_INDEX) Then + If (lBitDepthSrc = 4) Then + lciUnmaskColorSrc = (lciUnmaskColorSrc And &HF) + Else + lciUnmaskColorSrc = (lciUnmaskColorSrc And &HFF) + End If + Else + If (eUnmaskColorSrcFormat And FICFF_COLOR_BGR) Then + lciUnmaskColorSrc = FreeImage_SwapColorLong(lciUnmaskColorSrc, True) + End If + lciUnmaskColorSrc = FreeImage_SearchPalette(hDIB, lciUnmaskColorSrc) + bHaveUnmaskColorSrc = (lciUnmaskColorSrc <> -1) + End If + End If + + ' check, if source image still can be modified in any way + bModifySourceImage = (bHaveMaskColorSrc Or bHaveUnmaskColorSrc) + + Case 24, 32 + If (bHaveMaskColorSrc) Then + + ' get mask color as Long + lciMaskColorSrc = vlciMaskColorSrc + + If (eMaskColorSrcFormat And FICFF_COLOR_BGR) Then + lciMaskColorSrc = FreeImage_SwapColorLong(lciMaskColorSrc, (lBitDepthSrc = 24)) + End If + End If + + If (bHaveUnmaskColorSrc) Then + + ' get unmask color as Long + lciUnmaskColorSrc = vlciUnmaskColorSrc + + If (eUnmaskColorSrcFormat And FICFF_COLOR_BGR) Then + lciUnmaskColorSrc = FreeImage_SwapColorLong(lciUnmaskColorSrc, (lBitDepthSrc = 24)) + End If + End If + + End Select + + End If + + + If ((bModifySourceImage) Or (bCreateMaskImage)) Then + + ' get some information from eMaskOptions + + ' check for inverse mask + bInvertMask = (eMaskOptions And FIMF_MASK_INVERSE_MASK) + + ' check for mask colors + bMaskColors = (eMaskOptions And FIMF_MASK_COLOR_TRANSPARENCY) + bMaskColors = bMaskColors And (Not IsMissing(vntMaskColors)) + If (bMaskColors) Then + ' validate specified mask colors; all mask colors are transferred to + ' an internal array of type Long + If (Not IsArray(vntMaskColors)) Then + ' color masking is only done when the single mask color is + ' a numeric (color) value + bMaskColors = IsNumeric(vntMaskColors) + If (bMaskColors) Then + ' this is not an array of mask colors but only a single + ' color; this is also transferred into an internal array + lMaskColorsMaxIndex = 0 + ReDim alcMaskColors(lMaskColorsMaxIndex) + alcMaskColors(lMaskColorsMaxIndex) = vntMaskColors + End If + Else + ' transfer all valid color values (numeric) into an internal + ' array + ReDim alcMaskColors(UBound(vntMaskColors)) + For i = LBound(vntMaskColors) To UBound(vntMaskColors) + bMaskColors = (IsNumeric(vntMaskColors(i))) + If (Not bMaskColors) Then + Exit For + Else + alcMaskColors(lMaskColorsMaxIndex) = vntMaskColors(i) + lMaskColorsMaxIndex = lMaskColorsMaxIndex + 1 + End If + Next i + If (bMaskColors) Then + lMaskColorsMaxIndex = lMaskColorsMaxIndex - 1 + End If + End If + End If + + ' check for transparency options + If ((FreeImage_IsTransparent(hDIB)) Or _ + ((eMaskOptions And FIMF_MASK_FORCE_TRANSPARENCY) > 0)) Then + bMaskFullTransparency = (eMaskOptions And FIMF_MASK_FULL_TRANSPARENCY) + bMaskAlphaTransparency = (eMaskOptions And FIMF_MASK_ALPHA_TRANSPARENCY) + bMaskTransparency = (bMaskFullTransparency Or bMaskAlphaTransparency) + End If + + ' get image dimension + lWidth = FreeImage_GetWidth(hDIB) + lHeight = FreeImage_GetHeight(hDIB) + + ' create proper accessors for the source image + Select Case lBitDepthSrc + + Case 4, 8 + ' images with a bit depth of 4 or 8 bits will both be + ' read through a byte array + abBitsBSrc = FreeImage_GetBitsEx(hDIB) + ' depending on where to get the transparency information from, + ' a palette or a transpareny table will be needed + If (bMaskColors) Then + alPaletteSrc = FreeImage_GetPaletteExLong(hDIB) + End If + If (bMaskTransparency) Then + abTransparencyTableSrc = FreeImage_GetTransparencyTableExClone(hDIB) + End If + + ' for 4 bit source images + If (lBitDepthSrc = 4) Then + ' two additional arrays need to be filled with values + ' to mask and shift nibbles to bytes + ' index 0 stands for the high nibble of the byte + abBitMasks(0) = &HF0 + abBitShifts(0) = &H10 ' a shift to right is implemented + ' as division in VB + ' index 1 stands for the low nibble of the byte + abBitMasks(1) = &HF + abBitShifts(1) = &H1 ' no shift needed for low nibble + End If + + Case 24 + ' images with a depth of 24 bits could not be used + ' through a two dimensional array in most cases, so get + ' an array of individual scanlines (see remarks concerning + ' pitch at function 'FreeImage_GetBitsExRGBTriple()') + Call FreeImage_GetScanLinesRGBTRIPLE(hDIB, atBitsTSrc) + + Case 32 + atBitsQSrc = FreeImage_GetBitsExRGBQUAD(hDIB) + + End Select + + + ' create mask image if needed + If (bCreateMaskImage) Then + + ' create mask image + hDIBResult = FreeImage_Allocate(lWidth, lHeight, lBitDepth) + ' if destination bit depth is 8 or below, a proper palette will + ' be needed, so create a palette where the unmask color is at + ' index 0 and the mask color is at index 1 + If (lBitDepth <= 8) Then + atPaletteDst = FreeImage_GetPaletteEx(hDIBResult) + Call CopyMemory(atPaletteDst(0), lciUnmaskColorDst, 4) + Call CopyMemory(atPaletteDst(1), lciMaskColorDst, 4) + End If + + ' create proper accessors for the new mask image + Select Case lBitDepth + + Case 1 + abBitsBDst = FreeImage_GetBitsEx(hDIBResult) + X = 1 + For i = 7 To 0 Step -1 + abBitValues(i) = X + X = X * 2 + Next i + + Case 4 + abBitsBDst = FreeImage_GetBitsEx(hDIBResult) + abBitValues(0) = &H10 + abBitValues(1) = &H1 + + Case 8 + abBitsBDst = FreeImage_GetBitsEx(hDIBResult) + + Case 24 + ' images with a depth of 24 bits could not be used + ' through a two dimensional array in most cases, so get + ' an array of individual scanlines (see remarks concerning + ' pitch at function 'FreeImage_GetBitsExRGBTriple()') + Call FreeImage_GetScanLinesRGBTRIPLE(hDIBResult, atBitsTDst) + + Case 32 + atBitsQDst = FreeImage_GetBitsExRGBQUAD(hDIBResult) + + End Select + End If + + ' walk the hole image + For Y = 0 To lHeight - 1 + For X = 0 To lWidth - 1 + + ' should transparency information be considered to create + ' the mask? + If (bMaskTransparency) Then + + Select Case lBitDepthSrc + + Case 4 + x2 = X \ 2 + lPixelIndex = (abBitsBSrc(x2, Y) And abBitMasks(X Mod 2)) \ abBitShifts(X Mod 2) + bMaskPixel = (abTransparencyTableSrc(lPixelIndex) = 0) + If (Not bMaskPixel) Then + bMaskPixel = ((abTransparencyTableSrc(lPixelIndex) < 255) And _ + (bMaskAlphaTransparency)) + End If + + Case 8 + bMaskPixel = (abTransparencyTableSrc(abBitsBSrc(X, Y)) = 0) + If (Not bMaskPixel) Then + bMaskPixel = ((abTransparencyTableSrc(abBitsBSrc(X, Y)) < 255) And _ + (bMaskAlphaTransparency)) + End If + + Case 24 + ' no transparency information in 24 bit images + ' reset bMaskPixel + bMaskPixel = False + + Case 32 + bMaskPixel = (atBitsQSrc(X, Y).rgbReserved = 0) + If (Not bMaskPixel) Then + bMaskPixel = ((atBitsQSrc(X, Y).rgbReserved < 255) And _ + (bMaskAlphaTransparency)) + End If + + End Select + Else + ' clear 'bMaskPixel' if no transparency information was checked + ' since the flag might be still True from the last loop + bMaskPixel = False + End If + + ' should color information be considered to create the mask? + ' do this only if the current pixel is not yet part of the mask + If ((bMaskColors) And (Not bMaskPixel)) Then + + Select Case lBitDepthSrc + + Case 4 + x2 = X \ 2 + lPixelIndex = (abBitsBSrc(x2, Y) And abBitMasks(X Mod 2)) \ abBitShifts(X Mod 2) + If (eMaskColorsFormat And FICFF_COLOR_PALETTE_INDEX) Then + For i = 0 To lMaskColorsMaxIndex + If (lColorTolerance = 0) Then + bMaskPixel = (lPixelIndex = alcMaskColors(i)) + Else + bMaskPixel = (FreeImage_CompareColorsLongLong( _ + alPaletteSrc(lPixelIndex), _ + alPaletteSrc(alcMaskColors(i)), _ + lColorTolerance, _ + FICFF_COLOR_RGB, FICFF_COLOR_RGB) = 0) + End If + If (bMaskPixel) Then + Exit For + End If + Next i + Else + For i = 0 To lMaskColorsMaxIndex + bMaskPixel = (FreeImage_CompareColorsLongLong( _ + alPaletteSrc(lPixelIndex), _ + alcMaskColors(i), lColorTolerance, _ + FICFF_COLOR_RGB, _ + (eMaskColorsFormat And FICFF_COLOR_FORMAT_ORDER_MASK)) = 0) + If (bMaskPixel) Then + Exit For + End If + Next i + End If + + Case 8 + If (eMaskColorsFormat And FICFF_COLOR_PALETTE_INDEX) Then + For i = 0 To lMaskColorsMaxIndex + If (lColorTolerance = 0) Then + bMaskPixel = (abBitsBSrc(X, Y) = alcMaskColors(i)) + Else + bMaskPixel = (FreeImage_CompareColorsLongLong( _ + alPaletteSrc(abBitsBSrc(X, Y)), _ + alPaletteSrc(alcMaskColors(i)), _ + lColorTolerance, _ + FICFF_COLOR_RGB, FICFF_COLOR_RGB) = 0) + End If + If (bMaskPixel) Then + Exit For + End If + Next i + Else + For i = 0 To lMaskColorsMaxIndex + bMaskPixel = (FreeImage_CompareColorsLongLong( _ + alPaletteSrc(abBitsBSrc(X, Y)), _ + alcMaskColors(i), lColorTolerance, _ + FICFF_COLOR_RGB, _ + (eMaskColorsFormat And FICFF_COLOR_FORMAT_ORDER_MASK)) = 0) + If (bMaskPixel) Then + Exit For + End If + Next i + End If + + Case 24 + For i = 0 To lMaskColorsMaxIndex + bMaskPixel = (FreeImage_CompareColorsRGBTRIPLELong( _ + atBitsTSrc.Scanline(Y).Data(X), _ + alcMaskColors(i), lColorTolerance, _ + (eMaskColorsFormat And FICFF_COLOR_FORMAT_ORDER_MASK)) = 0) + If (bMaskPixel) Then + Exit For + End If + Next i + + Case 32 + For i = 0 To lMaskColorsMaxIndex + bMaskPixel = (FreeImage_CompareColorsRGBQUADLong( _ + atBitsQSrc(X, Y), _ + alcMaskColors(i), lColorTolerance, _ + (eMaskColorsFormat And FICFF_COLOR_FORMAT_ORDER_MASK)) = 0) + If (bMaskPixel) Then + Exit For + End If + Next i + + End Select + + End If + + ' check whether a mask image needs to be created + If (bCreateMaskImage) Then + + ' write current pixel to destination (mask) image + Select Case lBitDepth + + Case 1 + x2 = X \ 8 + If ((bMaskPixel) Xor (bInvertMask)) Then + abBitsBDst(x2, Y) = abBitsBDst(x2, Y) Or abBitValues(X Mod 8) + End If + + Case 4 + x2 = X \ 2 + If ((bMaskPixel) Xor (bInvertMask)) Then + abBitsBDst(x2, Y) = abBitsBDst(x2, Y) Or abBitValues(X Mod 2) + End If + + Case 8 + If ((bMaskPixel) Xor (bInvertMask)) Then + abBitsBDst(X, Y) = 1 + End If + + Case 24 + If ((bMaskPixel) Xor (bInvertMask)) Then + Call CopyMemory(atBitsTDst.Scanline(Y).Data(X), lciMaskColorDst, 3) + Else + Call CopyMemory(atBitsTDst.Scanline(Y).Data(X), lciUnmaskColorDst, 3) + End If + + Case 32 + If ((bMaskPixel) Xor (bInvertMask)) Then + Call CopyMemory(atBitsQDst(X, Y), lciMaskColorDst, 4) + Else + Call CopyMemory(atBitsQDst(X, Y), lciUnmaskColorDst, 4) + End If + + End Select + End If + + ' check whether a source image needs to be modified + If (bModifySourceImage) Then + + Select Case lBitDepthSrc + + Case 4 + x2 = X \ 2 + If ((bMaskPixel) Xor (bInvertMask)) Then + If (bHaveMaskColorSrc) Then + abBitsBSrc(x2, Y) = _ + (abBitsBSrc(x2, Y) And (Not abBitMasks(X Mod 2))) Or _ + (lciMaskColorSrc * abBitShifts(X Mod 2)) + End If + ElseIf (bHaveUnmaskColorSrc) Then + abBitsBSrc(x2, Y) = _ + (abBitsBSrc(x2, Y) And (Not abBitMasks(X Mod 2))) Or _ + (lciUnmaskColorSrc * abBitShifts(X Mod 2)) + End If + + Case 8 + If ((bMaskPixel) Xor (bInvertMask)) Then + If (bHaveMaskColorSrc) Then + abBitsBSrc(X, Y) = lciMaskColorSrc + End If + ElseIf (bHaveUnmaskColorSrc) Then + abBitsBSrc(X, Y) = lciUnmaskColorSrc + End If + + Case 24 + If ((bMaskPixel) Xor (bInvertMask)) Then + If (bHaveMaskColorSrc) Then + Call CopyMemory(atBitsTSrc.Scanline(Y).Data(X), lciMaskColorSrc, 3) + End If + ElseIf (bHaveUnmaskColorSrc) Then + Call CopyMemory(atBitsTSrc.Scanline(Y).Data(X), lciUnmaskColorSrc, 3) + End If + + Case 32 + If ((bMaskPixel) Xor (bInvertMask)) Then + If (bHaveMaskColorSrc) Then + Call CopyMemory(atBitsQSrc(X, Y), lciMaskColorSrc, 4) + End If + ElseIf (bHaveUnmaskColorSrc) Then + Call CopyMemory(atBitsQSrc(X, Y), lciUnmaskColorSrc, 4) + End If + + End Select + End If + + Next X + Next Y + End If + End If + End If + + FreeImage_CreateMask = hDIBResult + +End Function + +Public Function FreeImage_CreateMaskImage(ByVal hDIB As Long, _ + Optional ByVal lBitDepth As Long = 1, _ + Optional ByVal eMaskOptions As FREE_IMAGE_MASK_FLAGS = FIMF_MASK_FULL_TRANSPARENCY, _ + Optional ByVal vntMaskColors As Variant, _ + Optional ByVal eMaskColorsFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ + Optional ByVal lColorTolerance As Long, _ + Optional ByVal lciMaskColor As Long = vbWhite, _ + Optional ByVal eMaskColorFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ + Optional ByVal lciUnmaskColor As Long = vbBlack, _ + Optional ByVal eUnmaskColorFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB) As Long + + 'TODO: comment this function + + FreeImage_CreateMaskImage = FreeImage_CreateMask(hDIB, MCOF_CREATE_MASK_IMAGE, _ + lBitDepth, eMaskOptions, _ + vntMaskColors, eMaskColorsFormat, _ + lColorTolerance, _ + lciMaskColor, eMaskColorFormat, _ + lciUnmaskColor, eUnmaskColorFormat) + +End Function + +Public Function FreeImage_CreateSimpleBWMaskImage(ByVal hDIB As Long, _ + Optional ByVal lBitDepth As Long = 1, _ + Optional ByVal eMaskOptions As FREE_IMAGE_MASK_FLAGS = FIMF_MASK_FULL_TRANSPARENCY, _ + Optional ByVal vntMaskColors As Variant, _ + Optional ByVal eMaskColorsFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ + Optional ByVal lColorTolerance As Long) As Long + + 'TODO: comment this function + + FreeImage_CreateSimpleBWMaskImage = FreeImage_CreateMask(hDIB, MCOF_CREATE_MASK_IMAGE, _ + lBitDepth, eMaskOptions, _ + vntMaskColors, eMaskColorsFormat, _ + lColorTolerance, _ + vbWhite, FICFF_COLOR_RGB, _ + vbBlack, FICFF_COLOR_RGB) + +End Function + +Public Function FreeImage_CreateMaskInPlace(ByVal hDIB As Long, _ + Optional ByVal lBitDepth As Long = 1, _ + Optional ByVal eMaskOptions As FREE_IMAGE_MASK_FLAGS = FIMF_MASK_FULL_TRANSPARENCY, _ + Optional ByVal vntMaskColors As Variant, _ + Optional ByVal eMaskColorsFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ + Optional ByVal lColorTolerance As Long, _ + Optional ByVal vlciMaskColor As Variant, _ + Optional ByVal eMaskColorFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ + Optional ByVal vlciUnmaskColor As Variant, _ + Optional ByVal eUnmaskColorFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB) As Long + + 'TODO: comment this function + + FreeImage_CreateMaskInPlace = FreeImage_CreateMask(hDIB, MCOF_MODIFY_SOURCE_IMAGE, _ + lBitDepth, eMaskOptions, _ + vntMaskColors, eMaskColorsFormat, _ + lColorTolerance, _ + , , , , _ + vlciMaskColor, eMaskColorFormat, _ + vlciUnmaskColor, eUnmaskColorFormat) + +End Function + +Public Function FreeImage_CreateSimpleBWMaskInPlace(ByVal hDIB As Long, _ + Optional ByVal lBitDepth As Long = 1, _ + Optional ByVal eMaskOptions As FREE_IMAGE_MASK_FLAGS = FIMF_MASK_FULL_TRANSPARENCY, _ + Optional ByVal vntMaskColors As Variant, _ + Optional ByVal eMaskColorsFormat As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ + Optional ByVal lColorTolerance As Long) As Long + + 'TODO: comment this function + + FreeImage_CreateSimpleBWMaskInPlace = FreeImage_CreateMask(hDIB, MCOF_MODIFY_SOURCE_IMAGE, _ + lBitDepth, eMaskOptions, _ + vntMaskColors, eMaskColorsFormat, _ + lColorTolerance, _ + , , , , _ + vbWhite, FICFF_COLOR_RGB, _ + vbBlack, FICFF_COLOR_RGB) + +End Function + +Public Function FreeImage_CreateMaskColors(ParamArray MaskColors() As Variant) As Variant + + ' this is just a FreeImage signed function that emulates VB's + ' builtin Array() function, that makes a variant array from + ' a ParamArray; so, a caller of the FreeImage_CreateMask() function + ' can specify all mask colors inline in the call statement + + ' hDibMask = FreeImage_CreateMask(hDib, 1, FIMF_MASK_COLOR_TRANSPARENCY, _ + ' FreeImage_CreateMaskColors(vbRed, vbGreen, vbBlack), _ + ' FICFF_COLOR_BGR, .... ) + + ' keep in mind, that VB colors (vbRed, vbBlue, etc.) are OLE colors that have + ' BRG format + + FreeImage_CreateMaskColors = MaskColors + +End Function + +Public Function FreeImage_SwapColorLong(ByVal Color As Long, _ + Optional ByVal IgnoreAlpha As Boolean) As Long + + ' This function swaps both color components Red (R) and Blue (B) in either + ' and RGB or BGR format color value stored in a Long value. This function is + ' used to convert from a RGB to a BGR color value and vice versa. + + If (Not IgnoreAlpha) Then + FreeImage_SwapColorLong = ((Color And &HFF000000) Or _ + ((Color And &HFF&) * &H10000) Or _ + (Color And &HFF00&) Or _ + ((Color And &HFF0000) \ &H10000)) + Else + FreeImage_SwapColorLong = (((Color And &HFF&) * &H10000) Or _ + (Color And &HFF00&) Or _ + ((Color And &HFF0000) \ &H10000)) + End If + +End Function + +Public Function FreeImage_CompareColorsLongLong(ByVal ColorA As Long, _ + ByVal ColorB As Long, _ + Optional ByVal Tolerance As Long, _ + Optional ByVal ColorTypeA As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_ARGB, _ + Optional ByVal ColorTypeB As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_ARGB) As Long + +Dim bFormatEqual As Boolean +Dim bAlphaEqual As Boolean + + ' This function compares two colors that both are specified as a 32 bit Long + ' value. + + ' Use both parameters 'ColorTypeA' and 'ColorTypeB' to specify each color's + ' format and 'Tolerance' to specify the matching tolerance. + + ' The function returns the result of the mathematical substraction + ' ColorA - ColorB, so if both colors are equal, the function returns NULL (0) + ' and any other value if both colors are different. Alpha transparency is taken into + ' account only if both colors are said to have an alpha transparency component by + ' both parameters 'ColorTypeA' and 'ColorTypeB'. If at least one of both colors + ' has no alpha transparency component, the comparison only includes the bits for + ' the red, green and blue component. + + ' The matching tolerance is applied to each color component (red, green, blue and + ' alpha) separately. So, when 'Tolerance' contains a value greater than zero, the + ' function returns NULL (0) when either both colors are exactly the same or the + ' differences of each corresponding color components are smaller or equal than + ' the given tolerance value. + + + If (((ColorTypeA And FICFF_COLOR_PALETTE_INDEX) Or _ + (ColorTypeB And FICFF_COLOR_PALETTE_INDEX)) = 0) Then + + bFormatEqual = ((ColorTypeA And FICFF_COLOR_FORMAT_ORDER_MASK) = _ + (ColorTypeB And FICFF_COLOR_FORMAT_ORDER_MASK)) + + bAlphaEqual = ((ColorTypeA And FICFF_COLOR_HAS_ALPHA) And _ + (ColorTypeB And FICFF_COLOR_HAS_ALPHA)) + + If (bFormatEqual) Then + If (bAlphaEqual) Then + FreeImage_CompareColorsLongLong = ColorA - ColorB + Else + FreeImage_CompareColorsLongLong = (ColorA And &HFFFFFF) - (ColorB And &HFFFFFF) + End If + Else + If (bAlphaEqual) Then + FreeImage_CompareColorsLongLong = ColorA - ((ColorB And &HFF000000) Or _ + ((ColorB And &HFF&) * &H10000) Or _ + (ColorB And &HFF00&) Or _ + ((ColorB And &HFF0000) \ &H10000)) + Else + FreeImage_CompareColorsLongLong = (ColorA And &HFFFFFF) - _ + (((ColorB And &HFF&) * &H10000) Or _ + (ColorB And &HFF00&) Or _ + ((ColorB And &HFF0000) \ &H10000)) + End If + End If + + If ((Tolerance > 0) And (FreeImage_CompareColorsLongLong <> 0)) Then + If (bFormatEqual) Then + If (Abs(((ColorA \ &H10000) And &HFF) - ((ColorB \ &H10000) And &HFF)) <= Tolerance) Then + If (Abs(((ColorA \ &H100) And &HFF) - ((ColorB \ &H100) And &HFF)) <= Tolerance) Then + If (Abs((ColorA And &HFF) - (ColorB And &HFF)) <= Tolerance) Then + If (bAlphaEqual) Then + If (Abs(((ColorA \ &H1000000) And &HFF) - _ + ((ColorB \ &H1000000) And &HFF)) <= Tolerance) Then + FreeImage_CompareColorsLongLong = 0 + End If + Else + FreeImage_CompareColorsLongLong = 0 + End If + End If + End If + End If + Else + If (Abs(((ColorA \ &H10000) And &HFF) - (ColorB And &HFF)) <= Tolerance) Then + If (Abs(((ColorA \ &H100) And &HFF) - ((ColorB \ &H100) And &HFF)) <= Tolerance) Then + If (Abs((ColorA And &HFF) - ((ColorB \ &H10000) And &HFF)) <= Tolerance) Then + If (bAlphaEqual) Then + If (Abs(((ColorA \ &H1000000) And &HFF) - _ + ((ColorB \ &H1000000) And &HFF)) <= Tolerance) Then + FreeImage_CompareColorsLongLong = 0 + End If + Else + FreeImage_CompareColorsLongLong = 0 + End If + End If + End If + End If + End If + End If + End If + +End Function + +Public Function FreeImage_CompareColorsRGBTRIPLELong(ByRef ColorA As RGBTRIPLE, _ + ByVal ColorB As Long, _ + Optional ByVal Tolerance As Long, _ + Optional ByVal ColorTypeB As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB) As Long + +Dim lcColorA As Long + + ' This is a function derived from 'FreeImage_CompareColorsLongLong()' to make color + ' comparisons between two colors whereby one color is provided as RGBTRIPLE and the + ' other color is provided as Long value. + + ' Have a look at the documentation of 'FreeImage_CompareColorsLongLong()' to learn + ' more about color comparisons. + + Call CopyMemory(lcColorA, ColorA, 3) + FreeImage_CompareColorsRGBTRIPLELong = FreeImage_CompareColorsLongLong(lcColorA, ColorB, _ + Tolerance, FICFF_COLOR_RGB, ColorTypeB) + +End Function + +Public Function FreeImage_CompareColorsRGBQUADLong(ByRef ColorA As RGBQUAD, _ + ByVal ColorB As Long, _ + Optional ByVal Tolerance As Long, _ + Optional ByVal ColorTypeB As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_ARGB) As Long + +Dim lcColorA As Long + + ' This is a function derived from 'FreeImage_CompareColorsLongLong()' to make color + ' comparisons between two colors whereby one color is provided as RGBQUAD and the + ' other color is provided as Long value. + + ' Have a look at the documentation of 'FreeImage_CompareColorsLongLong()' to learn + ' more about color comparisons. + + Call CopyMemory(lcColorA, ColorA, 4) + FreeImage_CompareColorsRGBQUADLong = FreeImage_CompareColorsLongLong(lcColorA, ColorB, _ + Tolerance, FICFF_COLOR_ARGB, ColorTypeB) + +End Function + +Public Function FreeImage_SearchPalette(ByVal Bitmap As Long, _ + ByVal Color As Long, _ + Optional ByVal Tolerance As Long, _ + Optional ByVal ColorType As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ + Optional ByVal TransparencyState As FREE_IMAGE_TRANSPARENCY_STATE_FLAGS = FITSF_IGNORE_TRANSPARENCY) As Long + +Dim abTransparencyTable() As Byte +Dim alPalette() As Long +Dim i As Long + + ' This function searches an image's color palette for a certain color specified as a + ' 32 bit Long value in either RGB or BGR format. + + ' A search tolerance may be specified in the 'Tolerance' parameter. + + ' If no transparency tabe was found for the specified image, transparency information will + ' be ignored during the search. Then, the function behaves as if FITSF_IGNORE_TRANSPARENCY + ' was specified for parameter TransparencyState. + + ' Use the 'TransparencyState' parameter to control, how the transparency state of + ' the found palette entry affects the result. These values may be used: + + ' FITSF_IGNORE_TRANSPARENCY: Returns the index of the first palette entry which + ' matches the red, green and blue components. + ' + ' FITSF_NONTRANSPARENT: Returns the index of the first palette entry which + ' matches the red, green and blue components and is + ' nontransparent (fully opaque). + ' + ' FITSF_TRANSPARENT: Returns the index of the first palette entry which + ' matches the red, green and blue components and is + ' fully transparent. + ' + ' FITSF_INCLUDE_ALPHA_TRANSPARENCY: Returns the index of the first palette entry which + ' matches the red, green and blue components as well + ' as the alpha transparency. + + ' When alpha transparency should be included in the palette search ('FITSF_INCLUDE_ALPHA_TRANSPARENCY'), + ' the alpha transparency of the color searched is taken from the left most byte of 'Color' + ' (Color is either in format ARGB or ABGR). The the alpha transparency of the palette entry + ' actually comes from the image's transparency table rather than from the palette, since palettes + ' do not contain transparency information. + + If (FreeImage_GetImageType(Bitmap) = FIT_BITMAP) Then + Select Case FreeImage_GetColorType(Bitmap) + + Case FIC_PALETTE, FIC_MINISBLACK, FIC_MINISWHITE + FreeImage_SearchPalette = -1 + alPalette = FreeImage_GetPaletteExLong(Bitmap) + If (FreeImage_GetTransparencyCount(Bitmap) > UBound(alPalette)) Then + abTransparencyTable = FreeImage_GetTransparencyTableExClone(Bitmap) + Else + TransparencyState = FITSF_IGNORE_TRANSPARENCY + End If + For i = 0 To UBound(alPalette) + If (FreeImage_CompareColorsLongLong(Color, alPalette(i), _ + Tolerance, _ + ColorType, FICFF_COLOR_RGB) = 0) Then + Select Case TransparencyState + + Case FITSF_IGNORE_TRANSPARENCY + FreeImage_SearchPalette = i + Exit For + + Case FITSF_NONTRANSPARENT + If (abTransparencyTable(i) = 255) Then + FreeImage_SearchPalette = i + Exit For + End If + + Case FITSF_TRANSPARENT + If (abTransparencyTable(i) = 0) Then + FreeImage_SearchPalette = i + Exit For + End If + + Case FITSF_INCLUDE_ALPHA_TRANSPARENCY + If (abTransparencyTable(i) = ((Color And &HFF000000) \ 1000000)) Then + FreeImage_SearchPalette = i + Exit For + End If + + End Select + End If + Next i + + Case Else + FreeImage_SearchPalette = -1 + + End Select + Else + FreeImage_SearchPalette = -1 + End If + +End Function + +Public Function FreeImage_GetIcon(ByVal hDIB As Long, _ + Optional ByVal eTransparencyOptions As FREE_IMAGE_ICON_TRANSPARENCY_OPTION_FLAGS = ITOF_USE_DEFAULT_TRANSPARENCY, _ + Optional ByVal lciTransparentColor As Long, _ + Optional ByVal eTransparentColorType As FREE_IMAGE_COLOR_FORMAT_FLAGS = FICFF_COLOR_RGB, _ + Optional ByVal hDC As Long, _ + Optional ByVal UnloadSource As Boolean) As Long + +Dim tIconInfo As ICONINFO +Dim bReleaseDC As Boolean +Dim bModifySourceImage As Boolean +Dim eMaskFlags As FREE_IMAGE_MASK_FLAGS +Dim lBitDepth As Long +Dim bPixelIndex As Byte +Dim hDIBSrc As Long +Dim hDIBMask As Long +Dim hBMPMask As Long +Dim hBmp As Long + + ' The optional 'UnloadSource' parameter is for unloading the original image + ' after the OlePicture has been created, so you can easiely "switch" from a + ' FreeImage DIB to a VB Picture object. There is no need to clean up the DIB + ' at the caller's site. + + If (hDIB) Then + + If (Not FreeImage_HasPixels(hDIB)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to create an icon from a 'header-only' bitmap.") + End If + + lBitDepth = FreeImage_GetBPP(hDIB) + + ' check whether the image supports transparency + Select Case lBitDepth + + Case 4, 8 + If (eTransparencyOptions And ITOF_USE_TRANSPARENCY_INFO) Then + If (FreeImage_IsTransparent(hDIB)) Then + eMaskFlags = FIMF_MASK_FULL_TRANSPARENCY + ElseIf (eTransparencyOptions And ITOF_FORCE_TRANSPARENCY_INFO) Then + If (FreeImage_IsTransparencyTableTransparent(hDIB)) Then + eMaskFlags = (FIMF_MASK_FULL_TRANSPARENCY And _ + FIMF_MASK_FORCE_TRANSPARENCY) + End If + End If + End If + If ((eMaskFlags = FIMF_MASK_NONE) And _ + (eTransparencyOptions And ITOF_USE_COLOR_TRANSPARENCY)) Then + + eMaskFlags = FIMF_MASK_COLOR_TRANSPARENCY + + Select Case (eTransparencyOptions And ITOF_USE_COLOR_BITMASK) + + Case ITOF_USE_COLOR_TOP_LEFT_PIXEL + Call FreeImage_GetPixelIndex(hDIB, _ + 0, FreeImage_GetHeight(hDIB) - 1, _ + bPixelIndex) + lciTransparentColor = bPixelIndex + eTransparentColorType = FICFF_COLOR_PALETTE_INDEX + + Case ITOF_USE_COLOR_TOP_RIGHT_PIXEL + Call FreeImage_GetPixelIndex(hDIB, _ + FreeImage_GetWidth(hDIB) - 1, FreeImage_GetHeight(hDIB) - 1, _ + bPixelIndex) + lciTransparentColor = bPixelIndex + eTransparentColorType = FICFF_COLOR_PALETTE_INDEX + + Case ITOF_USE_COLOR_BOTTOM_LEFT_PIXEL + Call FreeImage_GetPixelIndex(hDIB, _ + 0, 0, _ + bPixelIndex) + lciTransparentColor = bPixelIndex + eTransparentColorType = FICFF_COLOR_PALETTE_INDEX + + Case ITOF_USE_COLOR_BOTTOM_RIGHT_PIXEL + Call FreeImage_GetPixelIndex(hDIB, _ + FreeImage_GetWidth(hDIB) - 1, 0, _ + bPixelIndex) + lciTransparentColor = bPixelIndex + eTransparentColorType = FICFF_COLOR_PALETTE_INDEX + + End Select + End If + + bModifySourceImage = True + + Case 24, 32 + If ((lBitDepth = 32) And _ + (eTransparencyOptions And ITOF_USE_TRANSPARENCY_INFO)) Then + If (FreeImage_IsTransparent(hDIB)) Then + eMaskFlags = FIMF_MASK_FULL_TRANSPARENCY + End If + End If + If ((eMaskFlags = FIMF_MASK_NONE) And _ + (eTransparencyOptions And ITOF_USE_COLOR_TRANSPARENCY)) Then + + eMaskFlags = FIMF_MASK_COLOR_TRANSPARENCY + + Select Case (eTransparencyOptions And ITOF_USE_COLOR_BITMASK) + + Case ITOF_USE_COLOR_TOP_LEFT_PIXEL + Call FreeImage_GetPixelColorByLong(hDIB, _ + FreeImage_GetHeight(hDIB) - 1, 0, _ + lciTransparentColor) + eTransparentColorType = FICFF_COLOR_RGB + + Case ITOF_USE_COLOR_TOP_RIGHT_PIXEL + Call FreeImage_GetPixelColorByLong(hDIB, _ + FreeImage_GetHeight(hDIB) - 1, FreeImage_GetWidth(hDIB) - 1, _ + lciTransparentColor) + eTransparentColorType = FICFF_COLOR_RGB + + Case ITOF_USE_COLOR_BOTTOM_LEFT_PIXEL + Call FreeImage_GetPixelColorByLong(hDIB, _ + 0, 0, _ + lciTransparentColor) + eTransparentColorType = FICFF_COLOR_RGB + + Case ITOF_USE_COLOR_BOTTOM_RIGHT_PIXEL + Call FreeImage_GetPixelColorByLong(hDIB, _ + 0, FreeImage_GetWidth(hDIB) - 1, _ + lciTransparentColor) + eTransparentColorType = FICFF_COLOR_RGB + + End Select + End If + + bModifySourceImage = (lBitDepth = 24) + + End Select + + + If (bModifySourceImage) Then + hDIBSrc = FreeImage_Clone(hDIB) + hDIBMask = FreeImage_CreateMask(hDIBSrc, MCOF_CREATE_AND_MODIFY, _ + 1, eMaskFlags, _ + lciTransparentColor, eTransparentColorType, _ + , , , , , _ + FreeImage_SearchPalette(hDIBSrc, 0, , , _ + FITSF_NONTRANSPARENT), _ + FICFF_COLOR_PALETTE_INDEX) + Else + hDIBSrc = hDIB + hDIBMask = FreeImage_CreateMaskImage(hDIB, 1, FIMF_MASK_FULL_TRANSPARENCY) + End If + + If (hDC = 0) Then + hDC = GetDC(0) + bReleaseDC = True + End If + + hBmp = CreateDIBitmap(hDC, _ + FreeImage_GetInfoHeader(hDIBSrc), _ + CBM_INIT, _ + FreeImage_GetBits(hDIBSrc), _ + FreeImage_GetInfo(hDIBSrc), _ + DIB_RGB_COLORS) + + + hBMPMask = CreateDIBitmap(hDC, _ + FreeImage_GetInfoHeader(hDIBMask), _ + CBM_INIT, _ + FreeImage_GetBits(hDIBMask), _ + FreeImage_GetInfo(hDIBMask), _ + DIB_RGB_COLORS) + + If (bModifySourceImage) Then + Call FreeImage_Unload(hDIBSrc) + End If + + If (UnloadSource) Then + Call FreeImage_Unload(hDIB) + End If + + + If ((hBmp <> 0) And (hBMPMask <> 0)) Then + + With tIconInfo + .fIcon = True + .hBmMask = hBMPMask + .hbmColor = hBmp + End With + + FreeImage_GetIcon = CreateIconIndirect(tIconInfo) + End If + + If (bReleaseDC) Then + Call ReleaseDC(0, hDC) + End If + End If + +End Function + +Public Function FreeImage_AdjustPictureBox(ByRef Control As Object, _ + Optional ByVal Mode As FREE_IMAGE_ADJUST_MODE = AM_DEFAULT, _ + Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC) As IPicture + +Dim tR As RECT +Dim hDIB As Long +Dim hDIBTemp As Long +Dim lNewWidth As Long +Dim lNewHeight As Long + +Const vbObjectOrWithBlockVariableNotSet As Long = 91 + + ' This function adjusts an already loaded picture in a VB PictureBox + ' control in size. This is done by converting the picture to a Bitmap + ' by FreeImage_CreateFromOlePicture. After resizing the Bitmap it is + ' converted back to a Ole Picture object and re-assigned to the + ' PictureBox control. + + ' The Control paramater is actually of type Object so any object or control + ' providing Picture, hWnd, Width and Height properties can be used instead + ' of a PictureBox control + + ' This may be useful when using compile time provided images in VB like + ' logos or backgrounds that need to be resized during runtime. Using + ' FreeImage's sophisticated rescaling methods is a much better aproach + ' than using VB's stretchable Image control. + + ' One reason for resizing a usually fixed size logo or background image + ' may be the following scenario: + + ' When running on a Windows machine using smaller or bigger fonts (what can + ' be configured in the control panel by using different dpi fonts), the + ' operation system automatically adjusts the sizes of Forms, Labels, + ' TextBoxes, Frames and even PictureBoxes. So, the hole VB application is + ' perfectly adapted to these font metrics with the exception of compile time + ' provided images. Although the PictureBox control is resized, the containing + ' image remains untouched. This problem could be solved with this function. + + ' This function is also wrapped by the function 'AdjustPicture', giving you + ' a more VB common function name. + + + If (Not Control Is Nothing) Then + Call GetClientRect(Control.hWnd, tR) + If ((tR.Right <> Control.Picture.Width) Or _ + (tR.Bottom <> Control.Picture.Height)) Then + hDIB = FreeImage_CreateFromOlePicture(Control.Picture) + If (hDIB) Then + If (Mode = AM_ADJUST_OPTIMAL_SIZE) Then + If (Control.Picture.Width >= Control.Picture.Height) Then + Mode = AM_ADJUST_WIDTH + Else + Mode = AM_ADJUST_HEIGHT + End If + End If + + Select Case Mode + + Case AM_STRECH + lNewWidth = tR.Right + lNewHeight = tR.Bottom + + Case AM_ADJUST_WIDTH + lNewWidth = tR.Right + lNewHeight = lNewWidth / (Control.Picture.Width / Control.Picture.Height) + + Case AM_ADJUST_HEIGHT + lNewHeight = tR.Bottom + lNewWidth = lNewHeight * (Control.Picture.Width / Control.Picture.Height) + + End Select + + hDIBTemp = hDIB + hDIB = FreeImage_Rescale(hDIB, lNewWidth, lNewHeight, Filter) + Call FreeImage_Unload(hDIBTemp) + Set Control.Picture = FreeImage_GetOlePicture(hDIB, , True) + Set FreeImage_AdjustPictureBox = Control.Picture + End If + End If + Else + Call Err.Raise(vbObjectOrWithBlockVariableNotSet) + End If + +End Function + +Public Function AdjustPicture(ByRef Control As Object, _ + Optional ByRef Mode As FREE_IMAGE_ADJUST_MODE = AM_DEFAULT, _ + Optional ByRef Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC) As IPicture + + ' This function is a more VB friendly signed wrapper for + ' the FreeImage_AdjustPictureBox function. + + Set AdjustPicture = FreeImage_AdjustPictureBox(Control, Mode, Filter) + +End Function + +Public Function FreeImage_LoadEx(ByVal Filename As String, _ + Optional ByVal Options As FREE_IMAGE_LOAD_OPTIONS, _ + Optional ByVal Width As Variant, _ + Optional ByVal Height As Variant, _ + Optional ByVal InPercent As Boolean, _ + Optional ByVal Filter As FREE_IMAGE_FILTER, _ + Optional ByRef Format As FREE_IMAGE_FORMAT) As Long + +Const vbInvalidPictureError As Long = 481 + + ' The function provides all image formats, the FreeImage library can read. The + ' image format is determined from the image file to load, the optional parameter + ' 'Format' is an OUT parameter that will contain the image format that has + ' been loaded. + + ' The parameters 'Width', 'Height', 'InPercent' and 'Filter' make it possible + ' to "load" the image in a resized version. 'Width', 'Height' specify the desired + ' width and height, 'Filter' determines, what image filter should be used + ' on the resizing process. + + ' The parameters 'Width', 'Height', 'InPercent' and 'Filter' map directly to the + ' according parameters of the 'FreeImage_RescaleEx' function. So, read the + ' documentation of the 'FreeImage_RescaleEx' for a complete understanding of the + ' usage of these parameters. + + + Format = FreeImage_GetFileType(Filename) + If (Format <> FIF_UNKNOWN) Then + If (FreeImage_FIFSupportsReading(Format)) Then + FreeImage_LoadEx = FreeImage_Load(Format, Filename, Options) + If (FreeImage_LoadEx) Then + + If ((Not IsMissing(Width)) Or _ + (Not IsMissing(Height))) Then + FreeImage_LoadEx = FreeImage_RescaleEx(FreeImage_LoadEx, Width, Height, _ + InPercent, True, Filter) + End If + Else + Call Err.Raise(vbInvalidPictureError) + End If + Else + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "FreeImage Library plugin '" & FreeImage_GetFormatFromFIF(Format) & "' " & _ + "does not support reading.") + End If + Else + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "The file specified has an unknown image format.") + End If + +End Function + +Public Function LoadPictureEx(Optional ByRef Filename As Variant, _ + Optional ByRef Options As FREE_IMAGE_LOAD_OPTIONS, _ + Optional ByRef Width As Variant, _ + Optional ByRef Height As Variant, _ + Optional ByRef InPercent As Boolean, _ + Optional ByRef Filter As FREE_IMAGE_FILTER, _ + Optional ByRef Format As FREE_IMAGE_FORMAT) As IPicture + +Dim hDIB As Long + + ' This function is an extended version of the VB method 'LoadPicture'. As + ' the VB version it takes a filename parameter to load the image and throws + ' the same errors in most cases. + + ' This function now is only a thin wrapper for the FreeImage_LoadEx() wrapper + ' function (as compared to releases of this wrapper prior to version 1.8). So, + ' have a look at this function's discussion of the parameters. + + ' However, we do mask out the FILO_LOAD_NOPIXELS load option, since this + ' function shall create a VB Picture object, which does not support + ' FreeImage's header-only loading option. + + + If (Not IsMissing(Filename)) Then + hDIB = FreeImage_LoadEx(Filename, (Options And (Not FILO_LOAD_NOPIXELS)), _ + Width, Height, InPercent, Filter, Format) + Set LoadPictureEx = FreeImage_GetOlePicture(hDIB, , True) + End If + +End Function + +Public Function FreeImage_SaveEx(ByVal Bitmap As Long, _ + ByVal Filename As String, _ + Optional ByVal Format As FREE_IMAGE_FORMAT = FIF_UNKNOWN, _ + Optional ByVal Options As FREE_IMAGE_SAVE_OPTIONS, _ + Optional ByVal ColorDepth As FREE_IMAGE_COLOR_DEPTH, _ + Optional ByVal Width As Variant, _ + Optional ByVal Height As Variant, _ + Optional ByVal InPercent As Boolean, _ + Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ + Optional ByVal UnloadSource As Boolean) As Boolean + +Dim hDIBRescale As Long +Dim bConvertedOnRescale As Boolean +Dim bIsNewDIB As Boolean +Dim lBPP As Long +Dim lBPPOrg As Long +Dim strExtension As String + + ' This function is an easy to use replacement for FreeImage's FreeImage_Save() + ' function which supports inline size- and color conversions as well as an + ' auto image format detection algorithm that determines the desired image format + ' by the given filename. An even more sophisticated algorithm may auto-detect + ' the proper color depth for a explicitly given or auto-detected image format. + + ' The function provides all image formats, and save options, the FreeImage + ' library can write. The optional parameter 'Format' may contain the desired + ' image format. When omitted, the function tries to get the image format from + ' the filename extension. + + ' The optional parameter 'ColorDepth' may contain the desired color depth for + ' the saved image. This can be either any value of the FREE_IMAGE_COLOR_DEPTH + ' enumeration or the value FICD_AUTO what is the default value of the parameter. + ' When 'ColorDepth' is FICD_AUTO, the function tries to get the most suitable + ' color depth for the specified image format if the image's current color depth + ' is not supported by the specified image format. Therefore, the function + ' firstly reduces the color depth step by step until a proper color depth is + ' found since an incremention would only increase the file's size with no + ' quality benefit. Only when there is no lower color depth is found for the + ' image format, the function starts to increase the color depth. + + ' Keep in mind that an explicitly specified color depth that is not supported + ' by the image format results in a runtime error. For example, when saving + ' a 24 bit image as GIF image, a runtime error occurs. + + ' The function checks, whether the given filename has a valid extension or + ' not. If not, the "primary" extension for the used image format will be + ' appended to the filename. The parameter 'Filename' remains untouched in + ' this case. + + ' To learn more about the "primary" extension, read the documentation for + ' the 'FreeImage_GetPrimaryExtensionFromFIF' function. + + ' The parameters 'Width', 'Height', 'InPercent' and 'Filter' make it possible + ' to save the image in a resized version. 'Width', 'Height' specify the desired + ' width and height, 'Filter' determines, what image filter should be used + ' on the resizing process. Since FreeImage_SaveEx relies on FreeImage_RescaleEx, + ' please refer to the documentation of FreeImage_RescaleEx to learn more + ' about these four parameters. + + ' The optional 'UnloadSource' parameter is for unloading the saved image, so + ' you can save and unload an image with this function in one operation. + ' CAUTION: at current, the image is unloaded, even if the image was not + ' saved correctly! + + + If (Bitmap) Then + + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to save 'header-only' bitmaps.") + End If + + If ((Not IsMissing(Width)) Or _ + (Not IsMissing(Height))) Then + + lBPP = FreeImage_GetBPP(Bitmap) + hDIBRescale = FreeImage_RescaleEx(Bitmap, Width, Height, InPercent, UnloadSource, Filter) + bIsNewDIB = (hDIBRescale <> Bitmap) + Bitmap = hDIBRescale + bConvertedOnRescale = (lBPP <> FreeImage_GetBPP(Bitmap)) + End If + + If (Format = FIF_UNKNOWN) Then + Format = FreeImage_GetFIFFromFilename(Filename) + End If + If (Format <> FIF_UNKNOWN) Then + If ((FreeImage_FIFSupportsWriting(Format)) And _ + (FreeImage_FIFSupportsExportType(Format, FIT_BITMAP))) Then + + If (Not FreeImage_IsFilenameValidForFIF(Format, Filename)) Then + strExtension = "." & FreeImage_GetPrimaryExtensionFromFIF(Format) + End If + + ' check color depth + If (ColorDepth <> FICD_AUTO) Then + ' mask out bit 1 (0x02) for the case ColorDepth is FICD_MONOCHROME_DITHER (0x03) + ' FREE_IMAGE_COLOR_DEPTH values are true bit depths in general expect FICD_MONOCHROME_DITHER + ' by masking out bit 1, 'FreeImage_FIFSupportsExportBPP()' tests for bitdepth 1 + ' what is correct again for dithered images. + ColorDepth = (ColorDepth And (Not &H2)) + If (Not FreeImage_FIFSupportsExportBPP(Format, ColorDepth)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "FreeImage Library plugin '" & FreeImage_GetFormatFromFIF(Format) & "' " & _ + "is unable to write images with a color depth " & _ + "of " & ColorDepth & " bpp.") + + ElseIf (FreeImage_GetBPP(Bitmap) <> ColorDepth) Then + Bitmap = FreeImage_ConvertColorDepth(Bitmap, ColorDepth, (UnloadSource Or bIsNewDIB)) + bIsNewDIB = True + + End If + Else + + If (lBPP = 0) Then + lBPP = FreeImage_GetBPP(Bitmap) + End If + + If (Not FreeImage_FIFSupportsExportBPP(Format, lBPP)) Then + lBPPOrg = lBPP + Do + lBPP = pGetPreviousColorDepth(lBPP) + Loop While ((Not FreeImage_FIFSupportsExportBPP(Format, lBPP)) Or _ + (lBPP = 0)) + If (lBPP = 0) Then + lBPP = lBPPOrg + Do + lBPP = pGetNextColorDepth(lBPP) + Loop While ((Not FreeImage_FIFSupportsExportBPP(Format, lBPP)) Or _ + (lBPP = 0)) + End If + + If (lBPP <> 0) Then + Bitmap = FreeImage_ConvertColorDepth(Bitmap, lBPP, (UnloadSource Or bIsNewDIB)) + bIsNewDIB = True + End If + + ElseIf (bConvertedOnRescale) Then + ' restore original color depth + ' always unload current DIB here, since 'bIsNewDIB' is True + Bitmap = FreeImage_ConvertColorDepth(Bitmap, lBPP, True) + + End If + End If + + FreeImage_SaveEx = FreeImage_Save(Format, Bitmap, Filename & strExtension, Options) + If ((bIsNewDIB) Or (UnloadSource)) Then + Call FreeImage_Unload(Bitmap) + End If + Else + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "FreeImage Library plugin '" & FreeImage_GetFormatFromFIF(Format) & "' " & _ + "is unable to write images of the image format requested.") + End If + Else + ' unknown image format error + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unknown image format. Neither an explicit image format " & _ + "was specified nor any known image format was determined " & _ + "from the filename specified.") + End If + End If + +End Function + +Public Function SavePictureEx(ByRef Picture As IPicture, _ + ByRef Filename As String, _ + Optional ByRef Format As FREE_IMAGE_FORMAT, _ + Optional ByRef Options As FREE_IMAGE_SAVE_OPTIONS, _ + Optional ByRef ColorDepth As FREE_IMAGE_COLOR_DEPTH, _ + Optional ByRef Width As Variant, _ + Optional ByRef Height As Variant, _ + Optional ByRef InPercent As Boolean, _ + Optional ByRef Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC) As Boolean + +Dim hDIB As Long + +Const vbObjectOrWithBlockVariableNotSet As Long = 91 +Const vbInvalidPictureError As Long = 481 + + ' This function is an extended version of the VB method 'SavePicture'. As + ' the VB version it takes a Picture object and a filename parameter to + ' save the image and throws the same errors in most cases. + + ' This function now is only a thin wrapper for the FreeImage_SaveEx() wrapper + ' function (as compared to releases of this wrapper prior to version 1.8). So, + ' have a look at this function's discussion of the parameters. + + + If (Not Picture Is Nothing) Then + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + SavePictureEx = FreeImage_SaveEx(hDIB, Filename, Format, Options, _ + ColorDepth, Width, Height, InPercent, _ + FILTER_BICUBIC, True) + Else + Call Err.Raise(vbInvalidPictureError) + End If + Else + Call Err.Raise(vbObjectOrWithBlockVariableNotSet) + End If + +End Function + +Public Function SaveImageContainerEx(ByRef Container As Object, _ + ByRef Filename As String, _ + Optional ByVal IncludeDrawings As Boolean, _ + Optional ByRef Format As FREE_IMAGE_FORMAT, _ + Optional ByRef Options As FREE_IMAGE_SAVE_OPTIONS, _ + Optional ByRef ColorDepth As FREE_IMAGE_COLOR_DEPTH, _ + Optional ByRef Width As Variant, _ + Optional ByRef Height As Variant, _ + Optional ByRef InPercent As Boolean, _ + Optional ByRef Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC) As Long + + ' This function is an extended version of the VB method 'SavePicture'. As + ' the VB version it takes an image hosting control and a filename parameter to + ' save the image and throws the same errors in most cases. + + ' This function merges the functionality of both wrapper functions + ' 'SavePictureEx()' and 'FreeImage_CreateFromImageContainer()'. Basically this + ' function is identical to 'SavePictureEx' expect that is does not take a + ' IOlePicture (IPicture) object but a VB image hosting container control. + + ' Please, refer to each of this two function's inline documentation for a + ' more detailed description. + + Call SavePictureEx(pGetIOlePictureFromContainer(Container, IncludeDrawings), _ + Filename, Format, Options, ColorDepth, Width, Height, InPercent, Filter) + +End Function + +Public Function FreeImage_OpenMultiBitmapEx(ByVal Filename As String, _ + Optional ByVal ReadOnly As Boolean, _ + Optional ByVal KeepCacheInMemory As Boolean, _ + Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS, _ + Optional ByRef Format As FREE_IMAGE_FORMAT) As Long + + Format = FreeImage_GetFileType(Filename) + If (Format <> FIF_UNKNOWN) Then + Select Case Format + + Case FIF_TIFF, FIF_GIF, FIF_ICO + FreeImage_OpenMultiBitmapEx = FreeImage_OpenMultiBitmap(Format, Filename, False, _ + ReadOnly, KeepCacheInMemory, Flags) + + Case Else + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "FreeImage Library plugin '" & FreeImage_GetFormatFromFIF(Format) & "' " & _ + "does not have any support for multi-page bitmaps.") + End Select + Else + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "The file specified has an unknown image format.") + End If + +End Function + +Public Function FreeImage_CreateMultiBitmapEx(ByVal Filename As String, _ + Optional ByVal KeepCacheInMemory As Boolean, _ + Optional ByVal Flags As FREE_IMAGE_LOAD_OPTIONS, _ + Optional ByRef Format As FREE_IMAGE_FORMAT) As Long + + If (Format = FIF_UNKNOWN) Then + Format = FreeImage_GetFIFFromFilename(Filename) + End If + + If (Format <> FIF_UNKNOWN) Then + Select Case Format + + Case FIF_TIFF, FIF_GIF, FIF_ICO + FreeImage_CreateMultiBitmapEx = FreeImage_OpenMultiBitmap(Format, Filename, True, _ + False, KeepCacheInMemory, Flags) + + Case Else + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "FreeImage Library plugin '" & _ + FreeImage_GetFormatFromFIF(Format) & "' " & _ + "does not have any support for multi-page bitmaps.") + End Select + Else + ' unknown image format error + Call Err.Raise(5, _ + "MFreeImage", _ + Error$(5) & vbCrLf & vbCrLf & _ + "Unknown image format. Neither an explicit image format " & _ + "was specified nor any known image format was determined " & _ + "from the filename specified.") + End If + +End Function + + + +'-------------------------------------------------------------------------------- +' OlePicture aware toolkit, rescale and conversion functions +'-------------------------------------------------------------------------------- + +Public Function FreeImage_RescaleIOP(ByRef Picture As IPicture, _ + Optional ByVal Width As Variant, _ + Optional ByVal Height As Variant, _ + Optional ByVal IsPercentValue As Boolean, _ + Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ + Optional ByVal ForceCloneCreation As Boolean) As IPicture + +Dim hDIB As Long + + ' IOlePicture based wrapper for wrapper function FreeImage_RescaleEx() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + hDIB = FreeImage_RescaleEx(hDIB, Width, Height, IsPercentValue, _ + True, Filter, ForceCloneCreation) + Set FreeImage_RescaleIOP = FreeImage_GetOlePicture(hDIB, , True) + End If + +End Function + +Public Function FreeImage_RescaleByPixelIOP(ByRef Picture As IPicture, _ + Optional ByVal WidthInPixels As Long, _ + Optional ByVal HeightInPixels As Long, _ + Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ + Optional ByVal ForceCloneCreation As Boolean) As IPicture + + ' Thin wrapper for function 'FreeImage_RescaleExIOP' for removing method + ' overload fake. This function rescales the image directly to the size + ' specified by the 'WidthInPixels' and 'HeightInPixels' parameters. + + Set FreeImage_RescaleByPixelIOP = FreeImage_RescaleIOP(Picture, WidthInPixels, HeightInPixels, _ + False, Filter, ForceCloneCreation) + +End Function + +Public Function FreeImage_RescaleByPercentIOP(ByRef Picture As IPicture, _ + Optional ByVal WidthPercentage As Double, _ + Optional ByVal HeightPercentage As Double, _ + Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ + Optional ByVal ForceCloneCreation As Boolean) As IPicture + + ' Thin wrapper for function 'FreeImage_RescaleExIOP' for removing method + ' overload fake. This function rescales the image by a percent value + ' based on the image's original size. + + Set FreeImage_RescaleByPercentIOP = FreeImage_RescaleIOP(Picture, WidthPercentage, HeightPercentage, _ + True, Filter, ForceCloneCreation) + +End Function + +Public Function FreeImage_RescaleByFactorIOP(ByRef Picture As IPicture, _ + Optional ByVal WidthFactor As Double, _ + Optional ByVal HeightFactor As Double, _ + Optional ByVal Filter As FREE_IMAGE_FILTER = FILTER_BICUBIC, _ + Optional ByVal ForceCloneCreation As Boolean) As IPicture + + ' Thin wrapper for function 'FreeImage_RescaleExIOP' for removing method + ' overload fake. This function rescales the image by a factor + ' based on the image's original size. + + Set FreeImage_RescaleByFactorIOP = FreeImage_RescaleIOP(Picture, WidthFactor, HeightFactor, _ + False, Filter, ForceCloneCreation) + +End Function + +Public Function FreeImage_MakeThumbnailIOP(ByRef Picture As IPicture, _ + ByVal MaxPixelSize As Long, _ + Optional ByVal Convert As Boolean) As IPicture + +Dim hDIB As Long +Dim hDIBThumbnail As Long + + ' IOlePicture based wrapper for wrapper function FreeImage_MakeThumbnail() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + hDIBThumbnail = FreeImage_MakeThumbnail(hDIB, MaxPixelSize, Convert) + If (hDIBThumbnail) Then + Set FreeImage_MakeThumbnailIOP = FreeImage_GetOlePicture(hDIBThumbnail, , True) + End If + Call FreeImage_Unload(hDIB) + End If + +End Function + +Public Function FreeImage_ConvertColorDepthIOP(ByRef Picture As IPicture, _ + ByVal Conversion As FREE_IMAGE_CONVERSION_FLAGS, _ + Optional ByVal Threshold As Byte = 128, _ + Optional ByVal DitherMethod As FREE_IMAGE_DITHER = FID_FS, _ + Optional ByVal QuantizeMethod As FREE_IMAGE_QUANTIZE = FIQ_WUQUANT) As IPicture + +Dim hDIB As Long + + ' IOlePicture based wrapper for wrapper function FreeImage_ConvertColorDepth() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + hDIB = FreeImage_ConvertColorDepth(hDIB, Conversion, True, Threshold, _ + DitherMethod, QuantizeMethod) + Set FreeImage_ConvertColorDepthIOP = FreeImage_GetOlePicture(hDIB, , True) + End If + +End Function + +Public Function FreeImage_ColorQuantizeExIOP(ByRef Picture As IPicture, _ + Optional ByVal QuantizeMethod As FREE_IMAGE_QUANTIZE = FIQ_WUQUANT, _ + Optional ByVal PaletteSize As Long = 256, _ + Optional ByVal ReserveSize As Long, _ + Optional ByRef ReservePalette As Variant = Null) As IPicture + +Dim hDIB As Long + + ' IOlePicture based wrapper for wrapper function FreeImage_ColorQuantizeEx() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + hDIB = FreeImage_ColorQuantizeEx(hDIB, QuantizeMethod, True, PaletteSize, _ + ReserveSize, ReservePalette) + Set FreeImage_ColorQuantizeExIOP = FreeImage_GetOlePicture(hDIB, , True) + End If + +End Function + +Public Function FreeImage_RotateClassicIOP(ByRef Picture As IPicture, _ + ByVal Angle As Double) As IPicture + +Dim hDIB As Long +Dim hDIBNew As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_RotateClassic() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + Select Case FreeImage_GetBPP(hDIB) + + Case 1, 8, 24, 32 + hDIBNew = FreeImage_RotateClassic(hDIB, Angle) + Set FreeImage_RotateClassicIOP = FreeImage_GetOlePicture(hDIBNew, , True) + + End Select + Call FreeImage_Unload(hDIB) + End If + +End Function + +Public Function FreeImage_RotateIOP(ByRef Picture As IPicture, _ + ByVal Angle As Double, _ + Optional ByVal ColorPtr As Long) As IPicture + +Dim hDIB As Long +Dim hDIBNew As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_Rotate() + + ' The optional ColorPtr parameter takes a pointer to (e.g. the address of) an + ' RGB color value. So, all these assignments are valid for ColorPtr: + ' + ' Dim tColor As RGBQUAD + ' + ' VarPtr(tColor) + ' VarPtr(&H33FF80) + ' VarPtr(vbWhite) ' However, the VB color constants are in BGR format! + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + Select Case FreeImage_GetBPP(hDIB) + + Case 1, 8, 24, 32 + hDIBNew = FreeImage_Rotate(hDIB, Angle, ByVal ColorPtr) + Set FreeImage_RotateIOP = FreeImage_GetOlePicture(hDIBNew, , True) + + End Select + Call FreeImage_Unload(hDIB) + End If + +End Function + +Public Function FreeImage_RotateExIOP(ByRef Picture As IPicture, _ + ByVal Angle As Double, _ + Optional ByVal ShiftX As Double, _ + Optional ByVal ShiftY As Double, _ + Optional ByVal OriginX As Double, _ + Optional ByVal OriginY As Double, _ + Optional ByVal UseMask As Boolean) As IPicture + +Dim hDIB As Long +Dim hDIBNew As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_RotateEx() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + Select Case FreeImage_GetBPP(hDIB) + + Case 8, 24, 32 + hDIBNew = FreeImage_RotateEx(hDIB, Angle, ShiftX, ShiftY, OriginX, OriginY, UseMask) + Set FreeImage_RotateExIOP = FreeImage_GetOlePicture(hDIBNew, , True) + + End Select + Call FreeImage_Unload(hDIB) + End If + +End Function + +Public Function FreeImage_FlipHorizontalIOP(ByRef Picture As IPicture) As IPicture + +Dim hDIB As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_FlipHorizontal() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + Call FreeImage_FlipHorizontalInt(hDIB) + Set FreeImage_FlipHorizontalIOP = FreeImage_GetOlePicture(hDIB, , True) + End If + +End Function + +Public Function FreeImage_FlipVerticalIOP(ByRef Picture As IPicture) As IPicture + +Dim hDIB As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_FlipVertical() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + Call FreeImage_FlipVerticalInt(hDIB) + Set FreeImage_FlipVerticalIOP = FreeImage_GetOlePicture(hDIB, , True) + End If + +End Function + +Public Function FreeImage_AdjustCurveIOP(ByRef Picture As IPicture, _ + ByRef LookupTable As Variant, _ + Optional ByVal Channel As FREE_IMAGE_COLOR_CHANNEL = FICC_BLACK) As IPicture + +Dim hDIB As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_AdjustCurve() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + Select Case FreeImage_GetBPP(hDIB) + + Case 8, 24, 32 + Call FreeImage_AdjustCurveEx(hDIB, LookupTable, Channel) + Set FreeImage_AdjustCurveIOP = FreeImage_GetOlePicture(hDIB, , True) + + End Select + End If + +End Function + +Public Function FreeImage_AdjustGammaIOP(ByRef Picture As IPicture, _ + ByVal Gamma As Double) As IPicture + +Dim hDIB As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_AdjustGamma() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + Select Case FreeImage_GetBPP(hDIB) + + Case 8, 24, 32 + Call FreeImage_AdjustGammaInt(hDIB, Gamma) + Set FreeImage_AdjustGammaIOP = FreeImage_GetOlePicture(hDIB, , True) + + End Select + End If + +End Function + +Public Function FreeImage_AdjustBrightnessIOP(ByRef Picture As IPicture, _ + ByVal Percentage As Double) As IPicture + +Dim hDIB As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_AdjustBrightness() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + Select Case FreeImage_GetBPP(hDIB) + + Case 8, 24, 32 + Call FreeImage_AdjustBrightnessInt(hDIB, Percentage) + Set FreeImage_AdjustBrightnessIOP = FreeImage_GetOlePicture(hDIB, , True) + + End Select + End If + +End Function + +Public Function FreeImage_AdjustContrastIOP(ByRef Picture As IPicture, _ + ByVal Percentage As Double) As IPicture + +Dim hDIB As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_AdjustContrast() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + Select Case FreeImage_GetBPP(hDIB) + + Case 8, 24, 32 + Call FreeImage_AdjustContrastInt(hDIB, Percentage) + Set FreeImage_AdjustContrastIOP = FreeImage_GetOlePicture(hDIB, , True) + + End Select + End If + +End Function + +Public Function FreeImage_InvertIOP(ByRef Picture As IPicture) As IPicture + +Dim hDIB As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_Invert() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + Call FreeImage_InvertInt(hDIB) + Set FreeImage_InvertIOP = FreeImage_GetOlePicture(hDIB, , True) + End If + +End Function + +Public Function FreeImage_GetChannelIOP(ByRef Picture As IPicture, _ + ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As IPicture + +Dim hDIB As Long +Dim hDIBNew As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_GetChannel() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + Select Case FreeImage_GetBPP(hDIB) + + Case 24, 32 + hDIBNew = FreeImage_GetChannel(hDIB, Channel) + Set FreeImage_GetChannelIOP = FreeImage_GetOlePicture(hDIBNew, , True) + + End Select + Call FreeImage_Unload(hDIB) + End If + +End Function + +Public Function FreeImage_SetChannelIOP(ByRef Picture As IPicture, _ + ByVal BitmapSrc As Long, _ + ByVal Channel As FREE_IMAGE_COLOR_CHANNEL) As IPicture + +Dim hDIB As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_SetChannel() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + Select Case FreeImage_GetBPP(hDIB) + + Case 24, 32 + If (FreeImage_SetChannel(hDIB, BitmapSrc, Channel)) Then + Set FreeImage_SetChannelIOP = FreeImage_GetOlePicture(hDIB, , True) + End If + + End Select + Call FreeImage_Unload(hDIB) + End If + +End Function + +Public Function FreeImage_CopyIOP(ByRef Picture As IPicture, _ + ByVal Left As Long, _ + ByVal Top As Long, _ + ByVal Right As Long, _ + ByVal Bottom As Long) As IPicture + +Dim hDIB As Long +Dim hDIBNew As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_Copy() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + hDIBNew = FreeImage_Copy(hDIB, Left, Top, Right, Bottom) + Call FreeImage_Unload(hDIB) + Set FreeImage_CopyIOP = FreeImage_GetOlePicture(hDIBNew, , True) + End If + +End Function + +Public Function FreeImage_PasteIOP(ByRef PictureDst As IPicture, _ + ByRef PictureSrc As IPicture, _ + ByVal Left As Long, _ + ByVal Top As Long, _ + ByVal Alpha As Long, _ + Optional ByVal KeepOriginalDestImage As Boolean) As IPicture + +Dim hDIBDst As Long +Dim hDIBSrc As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_Paste() + + hDIBDst = FreeImage_CreateFromOlePicture(PictureDst) + If (hDIBDst) Then + hDIBSrc = FreeImage_CreateFromOlePicture(PictureSrc) + If (hDIBSrc) Then + If FreeImage_Paste(hDIBDst, hDIBSrc, Left, Top, Alpha) Then + Set FreeImage_PasteIOP = FreeImage_GetOlePicture(hDIBDst, , True) + If (Not KeepOriginalDestImage) Then + Set PictureDst = FreeImage_PasteIOP + End If + End If + Call FreeImage_Unload(hDIBSrc) + End If + End If + +End Function + +Public Function FreeImage_CompositeIOP(ByRef Picture As IPicture, _ + Optional ByVal UseFileBackColor As Boolean, _ + Optional ByVal AppBackColor As OLE_COLOR, _ + Optional ByRef BackgroundPicture As IPicture) As IPicture + +Dim hDIB As Long +Dim hDIBbg As Long +Dim hDIBResult As Long +Dim lUseFileBackColor As Long + + ' IOlePicture based wrapper for FreeImage function FreeImage_Composite() + + hDIB = FreeImage_CreateFromOlePicture(Picture) + If (hDIB) Then + + If (UseFileBackColor) Then + lUseFileBackColor = 1 + End If + + hDIBbg = FreeImage_CreateFromOlePicture(BackgroundPicture) + + hDIBResult = FreeImage_Composite(hDIB, lUseFileBackColor, ConvertColor(AppBackColor), hDIBbg) + If (hDIBResult) Then + Set FreeImage_CompositeIOP = FreeImage_GetOlePicture(hDIBResult, , True) + End If + + Call FreeImage_Unload(hDIB) + If (hDIBbg) Then + Call FreeImage_Unload(hDIBbg) + End If + End If + +End Function + + +'-------------------------------------------------------------------------------- +' VB-coded Toolkit functions +'-------------------------------------------------------------------------------- + +Public Function FreeImage_GetColorizedPalette(ByVal Color As OLE_COLOR, _ + Optional ByVal SplitValue As Variant = 0.5) As RGBQUAD() + +Dim atPalette(255) As RGBQUAD +Dim lSplitIndex As Long +Dim lSplitIndexInv As Long +Dim lRed As Long +Dim lGreen As Long +Dim lBlue As Long +Dim i As Long + + ' compute the split index + Select Case VarType(SplitValue) + + Case vbByte, vbInteger, vbLong + lSplitIndex = SplitValue + + Case vbDouble, vbSingle, vbDecimal + lSplitIndex = 256 * SplitValue + + Case Else + lSplitIndex = 128 + + End Select + + ' check ranges of split index + If (lSplitIndex < 0) Then + lSplitIndex = 0 + ElseIf (lSplitIndex > 255) Then + lSplitIndex = 255 + End If + lSplitIndexInv = 256 - lSplitIndex + + ' extract color components red, green and blue + lRed = (Color And &HFF) + lGreen = ((Color \ &H100&) And &HFF) + lBlue = ((Color \ &H10000) And &HFF) + + For i = 0 To lSplitIndex - 1 + With atPalette(i) + .rgbRed = (lRed / lSplitIndex) * i + .rgbGreen = (lGreen / lSplitIndex) * i + .rgbBlue = (lBlue / lSplitIndex) * i + End With + Next i + For i = lSplitIndex To 255 + With atPalette(i) + .rgbRed = lRed + ((255 - lRed) / lSplitIndexInv) * (i - lSplitIndex) + .rgbGreen = lGreen + ((255 - lGreen) / lSplitIndexInv) * (i - lSplitIndex) + .rgbBlue = lBlue + ((255 - lBlue) / lSplitIndexInv) * (i - lSplitIndex) + End With + Next i + + FreeImage_GetColorizedPalette = atPalette + +End Function + +Public Function FreeImage_Colorize(ByVal Bitmap As Long, _ + ByVal Color As OLE_COLOR, _ + Optional ByVal SplitValue As Variant = 0.5) As Long + + If (Bitmap) Then + If (Not FreeImage_HasPixels(Bitmap)) Then + Call Err.Raise(5, "MFreeImage", Error$(5) & vbCrLf & vbCrLf & _ + "Unable to colorize a 'header-only' bitmap.") + End If + FreeImage_Colorize = FreeImage_ConvertToGreyscale(Bitmap) + Call FreeImage_SetPalette(FreeImage_Colorize, _ + FreeImage_GetColorizedPalette(Color, SplitValue)) + End If + +End Function + +Public Function FreeImage_Sepia(ByVal Bitmap As Long, _ + Optional ByVal SplitValue As Variant = 0.5) As Long + + FreeImage_Sepia = FreeImage_Colorize(Bitmap, &H658AA2, SplitValue) ' RGB(162, 138, 101) + +End Function + + +'-------------------------------------------------------------------------------- +' Compression functions wrappers +'-------------------------------------------------------------------------------- + +Public Function FreeImage_ZLibCompressEx(ByRef Target As Variant, _ + Optional ByRef TargetSize As Long, _ + Optional ByRef Source As Variant, _ + Optional ByVal SourceSize As Long, _ + Optional ByVal Offset As Long) As Long + +Dim lSourceDataPtr As Long +Dim lTargetDataPtr As Long +Dim bTargetCreated As Boolean + + ' This function is a more VB friendly wrapper for compressing data with + ' the 'FreeImage_ZLibCompress' function. + + ' The parameter 'Target' may either be a VB style array of Byte, Integer + ' or Long or a pointer to a memory block. If 'Target' is a pointer to a + ' memory block (when it contains an address), 'TargetSize' must be + ' specified and greater than zero. If 'Target' is an initialized array, + ' the whole array will be used to store compressed data when 'TargetSize' + ' is missing or below or equal to zero. If 'TargetSize' is specified, only + ' the first TargetSize bytes of the array will be used. + ' In each case, all rules according to the FreeImage API documentation + ' apply, what means that the target buffer must be at least 0.1% greater + ' than the source buffer plus 12 bytes. + ' If 'Target' is an uninitialized array, the contents of 'TargetSize' + ' will be ignored and the size of the array 'Target' will be handled + ' internally. When the function returns, 'Target' will be initialized + ' as an array of Byte and sized correctly to hold all the compressed + ' data. + + ' Nearly all, that is true for the parameters 'Target' and 'TargetSize', + ' is also true for 'Source' and 'SourceSize', expect that 'Source' should + ' never be an uninitialized array. In that case, the function returns + ' immediately. + + ' The optional parameter 'Offset' may contain a number of bytes to remain + ' untouched at the beginning of 'Target', when an uninitialized array is + ' provided through 'Target'. When 'Target' is either a pointer or an + ' initialized array, 'Offset' will be ignored. This parameter is currently + ' used by 'FreeImage_ZLibCompressVB' to store the length of the uncompressed + ' data at the first four bytes of 'Target'. + + + ' get the pointer and the size in bytes of the source + ' memory block + lSourceDataPtr = pGetMemoryBlockPtrFromVariant(Source, SourceSize) + If (lSourceDataPtr) Then + ' when we got a valid pointer, get the pointer and the size in bytes + ' of the target memory block + lTargetDataPtr = pGetMemoryBlockPtrFromVariant(Target, TargetSize) + If (lTargetDataPtr = 0) Then + ' if 'Target' is a null pointer, we will initialized it as an array + ' of bytes; here we will take 'Offset' into account + ReDim Target(SourceSize + Int(SourceSize * 0.1) + _ + 12 + Offset) As Byte + ' get pointer and size in bytes (will never be a null pointer) + lTargetDataPtr = pGetMemoryBlockPtrFromVariant(Target, TargetSize) + ' adjust according to 'Offset' + lTargetDataPtr = lTargetDataPtr + Offset + TargetSize = TargetSize - Offset + bTargetCreated = True + End If + + ' compress source data + FreeImage_ZLibCompressEx = FreeImage_ZLibCompress(lTargetDataPtr, _ + TargetSize, _ + lSourceDataPtr, _ + SourceSize) + + ' the function returns the number of bytes needed to store the + ' compressed data or zero on failure + If (FreeImage_ZLibCompressEx) Then + If (bTargetCreated) Then + ' when we created the array, we need to adjust it's size + ' according to the length of the compressed data + ReDim Preserve Target(FreeImage_ZLibCompressEx - 1 + Offset) + End If + End If + End If + +End Function + +Public Function FreeImage_ZLibUncompressEx(ByRef Target As Variant, _ + Optional ByRef TargetSize As Long, _ + Optional ByRef Source As Variant, _ + Optional ByVal SourceSize As Long) As Long + +Dim lSourceDataPtr As Long +Dim lTargetDataPtr As Long + + ' This function is a more VB friendly wrapper for compressing data with + ' the 'FreeImage_ZLibUncompress' function. + + ' The parameter 'Target' may either be a VB style array of Byte, Integer + ' or Long or a pointer to a memory block. If 'Target' is a pointer to a + ' memory block (when it contains an address), 'TargetSize' must be + ' specified and greater than zero. If 'Target' is an initialized array, + ' the whole array will be used to store uncompressed data when 'TargetSize' + ' is missing or below or equal to zero. If 'TargetSize' is specified, only + ' the first TargetSize bytes of the array will be used. + ' In each case, all rules according to the FreeImage API documentation + ' apply, what means that the target buffer must be at least as large, to + ' hold all the uncompressed data. + ' Unlike the function 'FreeImage_ZLibCompressEx', 'Target' can not be + ' an uninitialized array, since the size of the uncompressed data can + ' not be determined by the ZLib functions, but must be specified by a + ' mechanism outside the FreeImage compression functions' scope. + + ' Nearly all, that is true for the parameters 'Target' and 'TargetSize', + ' is also true for 'Source' and 'SourceSize'. + + + ' get the pointer and the size in bytes of the source + ' memory block + lSourceDataPtr = pGetMemoryBlockPtrFromVariant(Source, SourceSize) + If (lSourceDataPtr) Then + ' when we got a valid pointer, get the pointer and the size in bytes + ' of the target memory block + lTargetDataPtr = pGetMemoryBlockPtrFromVariant(Target, TargetSize) + If (lTargetDataPtr) Then + ' if we do not have a null pointer, uncompress the data + FreeImage_ZLibUncompressEx = FreeImage_ZLibUncompress(lTargetDataPtr, _ + TargetSize, _ + lSourceDataPtr, _ + SourceSize) + End If + End If + +End Function + +Public Function FreeImage_ZLibGZipEx(ByRef Target As Variant, _ + Optional ByRef TargetSize As Long, _ + Optional ByRef Source As Variant, _ + Optional ByVal SourceSize As Long, _ + Optional ByVal Offset As Long) As Long + +Dim lSourceDataPtr As Long +Dim lTargetDataPtr As Long +Dim bTargetCreated As Boolean + + ' This function is a more VB friendly wrapper for compressing data with + ' the 'FreeImage_ZLibGZip' function. + + ' The parameter 'Target' may either be a VB style array of Byte, Integer + ' or Long or a pointer to a memory block. If 'Target' is a pointer to a + ' memory block (when it contains an address), 'TargetSize' must be + ' specified and greater than zero. If 'Target' is an initialized array, + ' the whole array will be used to store compressed data when 'TargetSize' + ' is missing or below or equal to zero. If 'TargetSize' is specified, only + ' the first TargetSize bytes of the array will be used. + ' In each case, all rules according to the FreeImage API documentation + ' apply, what means that the target buffer must be at least 0.1% greater + ' than the source buffer plus 24 bytes. + ' If 'Target' is an uninitialized array, the contents of 'TargetSize' + ' will be ignored and the size of the array 'Target' will be handled + ' internally. When the function returns, 'Target' will be initialized + ' as an array of Byte and sized correctly to hold all the compressed + ' data. + + ' Nearly all, that is true for the parameters 'Target' and 'TargetSize', + ' is also true for 'Source' and 'SourceSize', expect that 'Source' should + ' never be an uninitialized array. In that case, the function returns + ' immediately. + + ' The optional parameter 'Offset' may contain a number of bytes to remain + ' untouched at the beginning of 'Target', when an uninitialized array is + ' provided through 'Target'. When 'Target' is either a pointer or an + ' initialized array, 'Offset' will be ignored. This parameter is currently + ' used by 'FreeImage_ZLibGZipVB' to store the length of the uncompressed + ' data at the first four bytes of 'Target'. + + + ' get the pointer and the size in bytes of the source + ' memory block + lSourceDataPtr = pGetMemoryBlockPtrFromVariant(Source, SourceSize) + If (lSourceDataPtr) Then + ' when we got a valid pointer, get the pointer and the size in bytes + ' of the target memory block + lTargetDataPtr = pGetMemoryBlockPtrFromVariant(Target, TargetSize) + If (lTargetDataPtr = 0) Then + ' if 'Target' is a null pointer, we will initialized it as an array + ' of bytes; here we will take 'Offset' into account + ReDim Target(SourceSize + Int(SourceSize * 0.1) + _ + 24 + Offset) As Byte + ' get pointer and size in bytes (will never be a null pointer) + lTargetDataPtr = pGetMemoryBlockPtrFromVariant(Target, TargetSize) + ' adjust according to 'Offset' + lTargetDataPtr = lTargetDataPtr + Offset + TargetSize = TargetSize - Offset + bTargetCreated = True + End If + + ' compress source data + FreeImage_ZLibGZipEx = FreeImage_ZLibGZip(lTargetDataPtr, _ + TargetSize, _ + lSourceDataPtr, _ + SourceSize) + + ' the function returns the number of bytes needed to store the + ' compressed data or zero on failure + If (FreeImage_ZLibGZipEx) Then + If (bTargetCreated) Then + ' when we created the array, we need to adjust it's size + ' according to the length of the compressed data + ReDim Preserve Target(FreeImage_ZLibGZipEx - 1 + Offset) + End If + End If + End If + +End Function + +Public Function FreeImage_ZLibCRC32Ex(ByVal CRC As Long, _ + Optional ByRef Source As Variant, _ + Optional ByVal SourceSize As Long) As Long + +Dim lSourceDataPtr As Long + + ' This function is a more VB friendly wrapper for compressing data with + ' the 'FreeImage_ZLibCRC32' function. + + ' The parameter 'Source' may either be a VB style array of Byte, Integer + ' or Long or a pointer to a memory block. If 'Source' is a pointer to a + ' memory block (when it contains an address), 'SourceSize' must be + ' specified and greater than zero. If 'Source' is an initialized array, + ' the whole array will be used to calculate the new CRC when 'SourceSize' + ' is missing or below or equal to zero. If 'SourceSize' is specified, only + ' the first SourceSize bytes of the array will be used. + + + ' get the pointer and the size in bytes of the source + ' memory block + lSourceDataPtr = pGetMemoryBlockPtrFromVariant(Source, SourceSize) + If (lSourceDataPtr) Then + ' if we do not have a null pointer, calculate the CRC including 'crc' + FreeImage_ZLibCRC32Ex = FreeImage_ZLibCRC32(CRC, _ + lSourceDataPtr, _ + SourceSize) + End If + +End Function + +Public Function FreeImage_ZLibGUnzipEx(ByRef Target As Variant, _ + Optional ByRef TargetSize As Long, _ + Optional ByRef Source As Variant, _ + Optional ByVal SourceSize As Long) As Long + +Dim lSourceDataPtr As Long +Dim lTargetDataPtr As Long + + ' This function is a more VB friendly wrapper for compressing data with + ' the 'FreeImage_ZLibGUnzip' function. + + ' The parameter 'Target' may either be a VB style array of Byte, Integer + ' or Long or a pointer to a memory block. If 'Target' is a pointer to a + ' memory block (when it contains an address), 'TargetSize' must be + ' specified and greater than zero. If 'Target' is an initialized array, + ' the whole array will be used to store uncompressed data when 'TargetSize' + ' is missing or below or equal to zero. If 'TargetSize' is specified, only + ' the first TargetSize bytes of the array will be used. + ' In each case, all rules according to the FreeImage API documentation + ' apply, what means that the target buffer must be at least as large, to + ' hold all the uncompressed data. + ' Unlike the function 'FreeImage_ZLibGZipEx', 'Target' can not be + ' an uninitialized array, since the size of the uncompressed data can + ' not be determined by the ZLib functions, but must be specified by a + ' mechanism outside the FreeImage compression functions' scope. + + ' Nearly all, that is true for the parameters 'Target' and 'TargetSize', + ' is also true for 'Source' and 'SourceSize'. + + + ' get the pointer and the size in bytes of the source + ' memory block + lSourceDataPtr = pGetMemoryBlockPtrFromVariant(Source, SourceSize) + If (lSourceDataPtr) Then + ' when we got a valid pointer, get the pointer and the size in bytes + ' of the target memory block + lTargetDataPtr = pGetMemoryBlockPtrFromVariant(Target, TargetSize) + If (lTargetDataPtr) Then + ' if we do not have a null pointer, uncompress the data + FreeImage_ZLibGUnzipEx = FreeImage_ZLibGUnzip(lTargetDataPtr, _ + TargetSize, _ + lSourceDataPtr, _ + SourceSize) + End If + End If + +End Function + +Public Function FreeImage_ZLibCompressVB(ByRef Data() As Byte, _ + Optional ByVal IncludeSize As Boolean = True) As Byte() + +Dim lOffset As Long +Dim lArrayDataPtr As Long + + ' This function is another, even more VB friendly wrapper for the FreeImage + ' 'FreeImage_ZLibCompress' function, that uses the 'FreeImage_ZLibCompressEx' + ' function. This function is very easy to use, since it deals only with VB + ' style Byte arrays. + + ' The parameter 'Data()' is a Byte array, providing the uncompressed source + ' data, that will be compressed. + + ' The optional parameter 'IncludeSize' determines whether the size of the + ' uncompressed data should be stored in the first four bytes of the returned + ' byte buffer containing the compressed data or not. When 'IncludeSize' is + ' True, the size of the uncompressed source data will be stored. This works + ' in conjunction with the corresponding 'FreeImage_ZLibUncompressVB' function. + + ' The function returns a VB style Byte array containing the compressed data. + + + ' start population the memory block with compressed data + ' at offset 4 bytes, when the unclompressed size should + ' be included + If (IncludeSize) Then + lOffset = 4 + End If + + Call FreeImage_ZLibCompressEx(FreeImage_ZLibCompressVB, , Data, , lOffset) + + If (IncludeSize) Then + ' get the pointer actual pointing to the array data of + ' the Byte array 'FreeImage_ZLibCompressVB' + lArrayDataPtr = deref(deref(VarPtrArray(FreeImage_ZLibCompressVB)) + 12) + + ' copy uncompressed size into the first 4 bytes + Call CopyMemory(ByVal lArrayDataPtr, UBound(Data) + 1, 4) + End If + +End Function + +Public Function FreeImage_ZLibUncompressVB(ByRef Data() As Byte, _ + Optional ByVal SizeIncluded As Boolean = True, _ + Optional ByVal SizeNeeded As Long) As Byte() + +Dim abBuffer() As Byte + + ' This function is another, even more VB friendly wrapper for the FreeImage + ' 'FreeImage_ZLibUncompress' function, that uses the 'FreeImage_ZLibUncompressEx' + ' function. This function is very easy to use, since it deals only with VB + ' style Byte arrays. + + ' The parameter 'Data()' is a Byte array, providing the compressed source + ' data that will be uncompressed either withthe size of the uncompressed + ' data included or not. + + ' When the optional parameter 'SizeIncluded' is True, the function assumes, + ' that the first four bytes contain the size of the uncompressed data as a + ' Long value. In that case, 'SizeNeeded' will be ignored. + + ' When the size of the uncompressed data is not included in the buffer 'Data()' + ' containing the compressed data, the optional parameter 'SizeNeeded' must + ' specify the size in bytes needed to hold all the uncompressed data. + + ' The function returns a VB style Byte array containing the uncompressed data. + + + If (SizeIncluded) Then + ' get uncompressed size from the first 4 bytes and allocate + ' buffer accordingly + Call CopyMemory(SizeNeeded, Data(0), 4) + ReDim abBuffer(SizeNeeded - 1) + Call FreeImage_ZLibUncompressEx(abBuffer, , VarPtr(Data(4)), UBound(Data) - 3) + Call pSwap(VarPtrArray(FreeImage_ZLibUncompressVB), VarPtrArray(abBuffer)) + + ElseIf (SizeNeeded) Then + ' no size included in compressed data, so just forward the + ' call to 'FreeImage_ZLibUncompressEx' and trust on SizeNeeded + ReDim abBuffer(SizeNeeded - 1) + Call FreeImage_ZLibUncompressEx(abBuffer, , Data) + Call pSwap(VarPtrArray(FreeImage_ZLibUncompressVB), VarPtrArray(abBuffer)) + + End If + +End Function + +Public Function FreeImage_ZLibGZipVB(ByRef Data() As Byte, _ + Optional ByVal IncludeSize As Boolean = True) As Byte() + +Dim lOffset As Long +Dim lArrayDataPtr As Long + + ' This function is another, even more VB friendly wrapper for the FreeImage + ' 'FreeImage_ZLibGZip' function, that uses the 'FreeImage_ZLibGZipEx' + ' function. This function is very easy to use, since it deals only with VB + ' style Byte arrays. + + ' The parameter 'Data()' is a Byte array, providing the uncompressed source + ' data that will be compressed. + + ' The optional parameter 'IncludeSize' determines whether the size of the + ' uncompressed data should be stored in the first four bytes of the returned + ' byte buffer containing the compressed data or not. When 'IncludeSize' is + ' True, the size of the uncompressed source data will be stored. This works + ' in conjunction with the corresponding 'FreeImage_ZLibGUnzipVB' function. + + ' The function returns a VB style Byte array containing the compressed data. + + + ' start population the memory block with compressed data + ' at offset 4 bytes, when the unclompressed size should + ' be included + If (IncludeSize) Then + lOffset = 4 + End If + + Call FreeImage_ZLibGZipEx(FreeImage_ZLibGZipVB, , Data, , lOffset) + + If (IncludeSize) Then + ' get the pointer actual pointing to the array data of + ' the Byte array 'FreeImage_ZLibCompressVB' + lArrayDataPtr = deref(deref(VarPtrArray(FreeImage_ZLibGZipVB)) + 12) + + ' copy uncompressed size into the first 4 bytes + Call CopyMemory(ByVal lArrayDataPtr, UBound(Data) + 1, 4) + End If + +End Function + +Public Function FreeImage_ZLibGUnzipVB(ByRef Data() As Byte, _ + Optional ByVal SizeIncluded As Boolean = True, _ + Optional ByVal SizeNeeded As Long) As Byte() + +Dim abBuffer() As Byte + + ' This function is another, even more VB friendly wrapper for the FreeImage + ' 'FreeImage_ZLibGUnzip' function, that uses the 'FreeImage_ZLibGUnzipEx' + ' function. This function is very easy to use, since it deals only with VB + ' style Byte arrays. + + ' The parameter 'Data()' is a Byte array, providing the compressed source + ' data that will be uncompressed either withthe size of the uncompressed + ' data included or not. + + ' When the optional parameter 'SizeIncluded' is True, the function assumes, + ' that the first four bytes contain the size of the uncompressed data as a + ' Long value. In that case, 'SizeNeeded' will be ignored. + + ' When the size of the uncompressed data is not included in the buffer 'Data()' + ' containing the compressed data, the optional parameter 'SizeNeeded' must + ' specify the size in bytes needed to hold all the uncompressed data. + + ' The function returns a VB style Byte array containing the uncompressed data. + + + If (SizeIncluded) Then + ' get uncompressed size from the first 4 bytes and allocate + ' buffer accordingly + Call CopyMemory(SizeNeeded, Data(0), 4) + ReDim abBuffer(SizeNeeded - 1) + Call FreeImage_ZLibGUnzipEx(abBuffer, , VarPtr(Data(4)), UBound(Data) - 3) + Call pSwap(VarPtrArray(FreeImage_ZLibGUnzipVB), VarPtrArray(abBuffer)) + + ElseIf (SizeNeeded) Then + ' no size included in compressed data, so just forward the + ' call to 'FreeImage_ZLibUncompressEx' and trust on SizeNeeded + ReDim abBuffer(SizeNeeded - 1) + Call FreeImage_ZLibGUnzipEx(abBuffer, , Data) + Call pSwap(VarPtrArray(FreeImage_ZLibGUnzipVB), VarPtrArray(abBuffer)) + + End If + +End Function + + +'-------------------------------------------------------------------------------- +' Public functions to destroy custom safearrays +'-------------------------------------------------------------------------------- + +Public Function FreeImage_DestroyLockedArray(ByRef Data As Variant) As Long + +Dim lpArrayPtr As Long + + ' This function destroys an array, that was self created with a custom + ' array descriptor of type ('fFeatures' member) 'FADF_AUTO Or FADF_FIXEDSIZE'. + ' Such arrays are returned by mostly all of the array-dealing wrapper + ' functions. Since these should not destroy the actual array data, when + ' going out of scope, they are craeted as 'FADF_FIXEDSIZE'.' + + ' So, VB sees them as fixed or temporarily locked, when you try to manipulate + ' the array's dimensions. There will occur some strange effects, you should + ' know about: + + ' 1. When trying to 'ReDim' the array, this run-time error will occur: + ' Error #10, 'This array is fixed or temporarily locked' + + ' 2. When trying to assign another array to the array variable, this + ' run-time error will occur: + ' Error #13, 'Type mismatch' + + ' 3. The 'Erase' statement has no effect on the array + + ' Although VB clears up these arrays correctly, when the array variable + ' goes out of scope, you have to destroy the array manually, when you want + ' to reuse the array variable in current scope. + + ' For an example assume, that you want do walk all scanlines in an image: + + ' For i = 0 To FreeImage_GetHeight(Bitmap) + ' + ' ' assign scanline-array to array variable + ' abByte = FreeImage_GetScanLineEx(Bitmap, i) + ' + ' ' do some work on it... + ' + ' ' destroy the array (only the array, not the actual data) + ' Call FreeImage_DestroyLockedArray(dbByte) + ' Next i + + ' The function returns zero on success and any other value on failure + + ' !! Attention !! + ' This function uses a Variant parameter for passing the array to be + ' destroyed. Since VB does not allow to pass an array of non public + ' structures through a Variant parameter, this function can not be used + ' with arrays of cutom type. + + ' You will get this compiler error: "Only public user defined types defined + ' in public object modules can be used as parameters or return types for + ' public procedures of class modules or as fields of public user defined types" + + ' So, there is a function in the wrapper called 'FreeImage_DestroyLockedArrayByPtr' + ' that takes a pointer to the array variable which can be used to work around + ' that VB limitation and furthermore can be used for any of these self-created + ' arrays. To get the array variable's pointer, a declared version of the + ' VB 'VarPtr' function can be used which works for all types of arrays expect + ' String arrays. Declare this function like this in your code: + + ' Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" ( _ + ByRef Ptr() As Any) As Long + + ' Then an array could be destroyed by calling the 'FreeImage_DestroyLockedArrayByPtr' + ' function like this: + + ' lResult = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(MyLockedArray)) + + ' Additionally there are some handy wrapper functions available, one for each + ' commonly used structure in FreeImage like RGBTRIPLE, RGBQUAD, FICOMPLEX etc. + + + ' Currently, these functions do return 'FADF_AUTO Or FADF_FIXEDSIZE' arrays + ' that must be destroyed using this or any of it's derived functions: + + ' FreeImage_GetPaletteEx() with FreeImage_DestroyLockedArrayRGBQUAD() + ' FreeImage_GetPaletteLong() with FreeImage_DestroyLockedArray() + ' FreeImage_SaveToMemoryEx2() with FreeImage_DestroyLockedArray() + ' FreeImage_AcquireMemoryEx() with FreeImage_DestroyLockedArray() + ' FreeImage_GetScanLineEx() with FreeImage_DestroyLockedArray() + ' FreeImage_GetScanLineBITMAP8() with FreeImage_DestroyLockedArray() + ' FreeImage_GetScanLineBITMAP16() with FreeImage_DestroyLockedArray() + ' FreeImage_GetScanLineBITMAP24() with FreeImage_DestroyLockedArrayRGBTRIPLE() + ' FreeImage_GetScanLineBITMAP32() with FreeImage_DestroyLockedArrayRGBQUAD() + ' FreeImage_GetScanLineINT16() with FreeImage_DestroyLockedArray() + ' FreeImage_GetScanLineINT32() with FreeImage_DestroyLockedArray() + ' FreeImage_GetScanLineFLOAT() with FreeImage_DestroyLockedArray() + ' FreeImage_GetScanLineDOUBLE() with FreeImage_DestroyLockedArray() + ' FreeImage_GetScanLineCOMPLEX() with FreeImage_DestroyLockedArrayFICOMPLEX() + ' FreeImage_GetScanLineRGB16() with FreeImage_DestroyLockedArrayFIRGB16() + ' FreeImage_GetScanLineRGBA16() with FreeImage_DestroyLockedArrayFIRGBA16() + ' FreeImage_GetScanLineRGBF() with FreeImage_DestroyLockedArrayFIRGBF() + ' FreeImage_GetScanLineRGBAF() with FreeImage_DestroyLockedArrayFIRGBAF() + + + ' ensure, this is an array + If (VarType(Data) And vbArray) Then + + ' data is a VB array, what means a SAFEARRAY in C/C++, that is + ' passed through a ByRef Variant variable, that is a pointer to + ' a VARIANTARG structure + + ' the VARIANTARG structure looks like this: + + ' typedef struct tagVARIANT VARIANTARG; + ' struct tagVARIANT + ' { + ' Union + ' { + ' struct __tagVARIANT + ' { + ' VARTYPE vt; + ' WORD wReserved1; + ' WORD wReserved2; + ' WORD wReserved3; + ' Union + ' { + ' [...] + ' SAFEARRAY *parray; // used when not VT_BYREF + ' [...] + ' SAFEARRAY **pparray; // used when VT_BYREF + ' [...] + + ' the data element (SAFEARRAY) has an offset of 8, since VARTYPE + ' and WORD both have a length of 2 bytes; the pointer to the + ' VARIANTARG structure is the VarPtr of the Variant variable in VB + + ' getting the contents of the data element (in C/C++: *(data + 8)) + lpArrayPtr = deref(VarPtr(Data) + 8) + + ' call the 'FreeImage_DestroyLockedArrayByPtr' function to destroy + ' the array properly + Call FreeImage_DestroyLockedArrayByPtr(lpArrayPtr) + Else + + FreeImage_DestroyLockedArray = -1 + End If + +End Function + +Public Function FreeImage_DestroyLockedArrayByPtr(ByVal ArrayPtr As Long) As Long + +Dim lpSA As Long + + ' This function destroys a self-created array with a custom array + ' descriptor by a pointer to the array variable. + + ' dereference the pointer once (in C/C++: *ArrayPtr) + lpSA = deref(ArrayPtr) + ' now 'lpSA' is a pointer to the actual SAFEARRAY structure + ' and could be a null pointer when the array is not initialized + ' then, we have nothing to do here but return (-1) to indicate + ' an "error" + If (lpSA) Then + + ' destroy the array descriptor + Call SafeArrayDestroyDescriptor(lpSA) + + ' make 'lpSA' a null pointer, that is an uninitialized array; + ' keep in mind, that we here use 'ArrayPtr' as a ByVal argument, + ' since 'ArrayPtr' is a pointer to lpSA (the address of lpSA); + ' we need to zero these four bytes, 'ArrayPtr' points to + Call CopyMemory(ByVal ArrayPtr, 0&, 4) + Else + + ' the array is already uninitialized, so return an "error" value + FreeImage_DestroyLockedArrayByPtr = -1 + End If + +End Function + +Public Function FreeImage_DestroyLockedArrayRGBTRIPLE(ByRef Data() As RGBTRIPLE) As Long + + ' This function is a thin wrapper for 'FreeImage_DestroyLockedArrayByPtr' + ' for destroying arrays of type 'RGBTRIPLE'. + + FreeImage_DestroyLockedArrayRGBTRIPLE = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(Data)) + +End Function + +Public Function FreeImage_DestroyLockedArrayRGBQUAD(ByRef Data() As RGBQUAD) As Long + + ' This function is a thin wrapper for 'FreeImage_DestroyLockedArrayByPtr' + ' for destroying arrays of type 'RGBQUAD'. + + FreeImage_DestroyLockedArrayRGBQUAD = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(Data)) + +End Function + +Public Function FreeImage_DestroyLockedArrayFICOMPLEX(ByRef Data() As FICOMPLEX) As Long + + ' This function is a thin wrapper for 'FreeImage_DestroyLockedArrayByPtr' + ' for destroying arrays of type 'FICOMPLEX'. + + FreeImage_DestroyLockedArrayFICOMPLEX = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(Data)) + +End Function + +Public Function FreeImage_DestroyLockedArrayFIRGB16(ByRef Data() As FIRGB16) As Long + + ' This function is a thin wrapper for 'FreeImage_DestroyLockedArrayByPtr' + ' for destroying arrays of type 'FIRGB16'. + + FreeImage_DestroyLockedArrayFIRGB16 = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(Data)) + +End Function + +Public Function FreeImage_DestroyLockedArrayFIRGBA16(ByRef Data() As FIRGBA16) As Long + + ' This function is a thin wrapper for 'FreeImage_DestroyLockedArrayByPtr' + ' for destroying arrays of type 'FIRGBA16'. + + FreeImage_DestroyLockedArrayFIRGBA16 = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(Data)) + +End Function + +Public Function FreeImage_DestroyLockedArrayFIRGBF(ByRef Data() As FIRGBF) As Long + + ' This function is a thin wrapper for 'FreeImage_DestroyLockedArrayByPtr' + ' for destroying arrays of type 'FIRGBF'. + + FreeImage_DestroyLockedArrayFIRGBF = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(Data)) + +End Function + +Public Function FreeImage_DestroyLockedArrayFIRGBAF(ByRef Data() As FIRGBAF) As Long + + ' This function is a thin wrapper for 'FreeImage_DestroyLockedArrayByPtr' + ' for destroying arrays of type 'FIRGBAF'. + + FreeImage_DestroyLockedArrayFIRGBAF = FreeImage_DestroyLockedArrayByPtr(VarPtrArray(Data)) + +End Function + + + +'-------------------------------------------------------------------------------- +' Private IOlePicture related helper functions +'-------------------------------------------------------------------------------- + +Private Function pGetIOlePictureFromContainer(ByRef Container As Object, _ + Optional ByVal IncludeDrawings As Boolean) As IPicture + + ' Returns a VB IOlePicture object (IPicture) from a VB image hosting control. + ' See the inline documentation of function 'FreeImage_CreateFromImageContainer' + ' for a detailed description of this helper function. + + If (Not Container Is Nothing) Then + + Select Case TypeName(Container) + + Case "PictureBox", "Form" + If (IncludeDrawings) Then + If (Not Container.AutoRedraw) Then + Call Err.Raise(5, _ + "MFreeImage", _ + Error$(5) & vbCrLf & vbCrLf & _ + "Custom drawings can only be included into the DIB when " & _ + "the container's 'AutoRedraw' property is set to True.") + Exit Function + End If + Set pGetIOlePictureFromContainer = Container.Image + Else + Set pGetIOlePictureFromContainer = Container.Picture + End If + + Case Else + + Dim bHasPicture As Boolean + Dim bHasImage As Boolean + Dim bIsAutoRedraw As Boolean + + On Error Resume Next + bHasPicture = (Container.Picture <> 0) + bHasImage = (Container.Image <> 0) + bIsAutoRedraw = Container.AutoRedraw + On Error GoTo 0 + + If ((IncludeDrawings) And _ + (bHasImage) And _ + (bIsAutoRedraw)) Then + Set pGetIOlePictureFromContainer = Container.Image + + ElseIf (bHasPicture) Then + Set pGetIOlePictureFromContainer = Container.Picture + + Else + Call Err.Raise(5, _ + "MFreeImage", _ + Error$(5) & vbCrLf & vbCrLf & _ + "Cannot create DIB from container control. Container " & _ + "control has no 'Picture' property.") + + End If + + End Select + + End If + +End Function + + + +'-------------------------------------------------------------------------------- +' Private image and color helper functions +'-------------------------------------------------------------------------------- + +Private Function pGetPreviousColorDepth(ByVal bpp As Long) As Long + + ' This function returns the 'previous' color depth of a given + ' color depth. Here, 'previous' means the next smaller color + ' depth. + + Select Case bpp + + Case 32 + pGetPreviousColorDepth = 24 + + Case 24 + pGetPreviousColorDepth = 16 + + Case 16 + pGetPreviousColorDepth = 15 + + Case 15 + pGetPreviousColorDepth = 8 + + Case 8 + pGetPreviousColorDepth = 4 + + Case 4 + pGetPreviousColorDepth = 1 + + End Select + +End Function + +Private Function pGetNextColorDepth(ByVal bpp As Long) As Long + + ' This function returns the 'next' color depth of a given + ' color depth. Here, 'next' means the next greater color + ' depth. + + Select Case bpp + + Case 1 + pGetNextColorDepth = 4 + + Case 4 + pGetNextColorDepth = 8 + + Case 8 + pGetNextColorDepth = 15 + + Case 15 + pGetNextColorDepth = 16 + + Case 16 + pGetNextColorDepth = 24 + + Case 24 + pGetNextColorDepth = 32 + + End Select + +End Function + + + +'-------------------------------------------------------------------------------- +' Private metadata helper functions +'-------------------------------------------------------------------------------- + +Private Function pGetTagFromTagPtr(ByVal Model As FREE_IMAGE_MDMODEL, _ + ByVal TagPtr As Long) As FREE_IMAGE_TAG + +Dim tTag As FITAG +Dim lTemp As Long +Dim i As Long + + ' This function converts data stored in a real FreeImage tag + ' pointer (FITAG **tag) into a VB friendly structure FREE_IMAGE_TAG. + + If (TagPtr <> 0) Then + + ' this is like (only like!) tTag tag = (FITAG) TagPtr; in C/C++ + ' we copy Len(tTag) bytes from the address in TagPtr in to a + ' private FITAG structure tTag so we have easy access to all + ' FITAG members + Call CopyMemory(tTag, ByVal deref(TagPtr), Len(tTag)) + + With pGetTagFromTagPtr + + ' first fill all members expect 'Value' in our + ' VB friendly FREE_IMAGE_TAG structure + + ' since we use this VB friendly FREE_IMAGE_TAG structure + ' for later tag modification too, we also need to store the + ' tag model and the pointer to the actual FreeImage FITAG + ' structure + .Model = Model + .TagPtr = TagPtr + + ' although FITAG's 'count' and 'length' members are + ' unsigned longs, we do not expect values greater + ' than 2,147,483,647, so we store them in normal VB + ' signed longs + .Count = tTag.Count + .Length = tTag.Length + + ' strings are stored as pointers to the actual string + ' data in FITAG + .Description = pGetStringFromPointerA(tTag.Description) + .Key = pGetStringFromPointerA(tTag.Key) + + ' FITAG's 'id' and 'type' members are unsigned shorts; + ' first of all 'id' may exceed the range of a signed + ' short (Integer data type in VB), so we store them in + ' signed longs and use CopyMemory for to keep the + ' unsigned bit layout + Call CopyMemory(.Id, tTag.Id, 2) + Call CopyMemory(.Type, tTag.Type, 2) + + ' StringValue is the result of FreeImage_TagToString(); we + ' also store this tag representation in our structure + .StringValue = FreeImage_TagToString(Model, TagPtr) + + + ' now comes the hard part, getting the tag's value + + Select Case .Type + + Case FIDT_BYTE, _ + FIDT_UNDEFINED + If (.Count > 1) Then + Dim abBytes() As Byte + ' for a byte array, just redim a VB Byte array and + ' copy Count bytes from the pointer + ReDim abBytes(.Count - 1) + Call CopyMemory(abBytes(0), ByVal tTag.Value, .Count) + .Value = abBytes + Else + ' copy a single byte into a Long and assign + ' with CByte() + Call CopyMemory(lTemp, ByVal tTag.Value, 1) + .Value = CByte(lTemp) + End If + + Case FIDT_ASCII + ' for an ASCII string, 'value' is just a pointer to the + ' string's actual data + .Value = pGetStringFromPointerA(tTag.Value) + + Case FIDT_SHORT + Dim iTemp As Integer + If (.Count > 1) Then + ' for a unsigned long array, first redim Value to + ' proper size + ReDim .Value(.Count - 1) + ' iterate over all items + For i = 0 To .Count - 1 + ' copy each value into a Long and + ' assign with FreeImage_UnsignedShort() to the + ' corresponding item in the (Variant) Value array + Call CopyMemory(iTemp, ByVal tTag.Value + i * 2, 2) + .Value(i) = FreeImage_UnsignedShort(iTemp) + Next i + Else + ' copy a single byte into a Long and assign + ' with FreeImgage_UnsignedShort() + Call CopyMemory(iTemp, ByVal tTag.Value, 2) + ' this works although FreeImage_UnsignedShort() takes + ' an Integer parameter since lTemp was 0 before and + ' we copied only 2 bytes so, VB's implicit conversion + ' to Integer will never produce an overflow + .Value = FreeImage_UnsignedShort(iTemp) + End If + + Case FIDT_LONG, _ + FIDT_IFD + If (.Count > 1) Then + ' for a unsigned long array, first redim Value to + ' proper size + ReDim .Value(.Count - 1) + ' iterate over all items + For i = 0 To .Count - 1 + ' copy each value into a (signed) Long and + ' assign with FreeImage_UnsignedLong() to the + ' corresponding item in the (Variant) Value array + Call CopyMemory(lTemp, ByVal tTag.Value + i * 4, 4) + .Value(i) = FreeImage_UnsignedLong(lTemp) + Next i + Else + ' copy a single unsigned long into a (signed) Long and + ' assign with FreeImage_UnsignedLong() + Call CopyMemory(lTemp, ByVal tTag.Value, 2) + .Value = FreeImage_UnsignedLong(lTemp) + End If + + Case FIDT_RATIONAL, _ + FIDT_SRATIONAL + ' rational values are always stored in the FREE_IMAGE_TAG + ' structure's FIRATIONAL array 'RationalValue' so, allocate + ' enough space in both the 'Value' and 'RationalValue' + ' members to hold 'Count' items + ReDim .Value(.Count - 1) + ReDim .RationalValue(.Count - 1) + For i = 0 To .Count - 1 + ' iterate over all items + With .RationalValue(i) + ' for each item, copy both numerator and denominator + ' into a (signed) Long and assign it to the corresponding + ' member of the FIRATIONAL structure so, we first assume + ' havinge a signed rational (FIDT_SRATIONAL) here + Call CopyMemory(lTemp, ByVal tTag.Value + i * 8, 4) + .Numerator = lTemp + Call CopyMemory(lTemp, ByVal tTag.Value + i * 8 + 4, 4) + .Denominator = lTemp + End With + ' if we have an unsigned rational (FIDT_RATIONAL), convert + ' numerator and denominator + If (.Type = FIDT_RATIONAL) Then + ' convert with FreeImage_UnsignedLong() + With .RationalValue(i) + .Numerator = FreeImage_UnsignedLong(.Numerator) + .Denominator = FreeImage_UnsignedLong(.Denominator) + End With + ' normalze the unsigned rational value + Call pNormalizeRational(.RationalValue(i)) + Else + ' normalze the signed rational value + Call pNormalizeSRational(.RationalValue(i)) + End If + ' store the current fraction's (maybe only approximated) value in + ' the 'Value' member of the FREE_IMAGE_TAG structure + .Value(i) = .RationalValue(i).Numerator / .RationalValue(i).Denominator + Next i + + Case FIDT_SBYTE + If (.Count > 1) Then + ' for a signed byte array, first redim Value to + ' proper size + ReDim .Value(.Count - 1) + ' iterate over all items + For i = 0 To .Count - 1 + ' copy each signed byte value into a Long and + ' check, whether it is negative (bit 7 set) + Call CopyMemory(lTemp, ByVal tTag.Value, 1) + If (lTemp And 128) Then + ' if negative, calculate the negative value + ' and store it in an Integer + .Value(i) = CInt(-256 - (Not (lTemp - 1))) + Else + ' if positive, assign to Value as byte + .Value(i) = CByte(lTemp) + End If + Next i + Else + ' copy a single signed byte into a Long and + ' check, whether it is negative (bit 7 set) + Call CopyMemory(lTemp, ByVal tTag.Value, 1) + If (lTemp And 128) Then + ' if negative, calculate the negative value + ' and store it in an Integer + .Value = CInt(-256 - (Not (lTemp - 1))) + Else + ' if positive, assign to Value as byte + .Value = CByte(lTemp) + End If + End If + + Case FIDT_SSHORT + If (.Count > 1) Then + Dim aiSShorts() As Integer + ' for a signed short array, just redim a VB Integer array and + ' copy Count bytes from the pointer + ReDim aiSShorts(.Count - 1) + Call CopyMemory(aiSShorts(0), ByVal tTag.Value, .Count * 2) + .Value = aiSShorts + Else + ' copy a single signed short into a Long and assign + ' with CInt() + Call CopyMemory(lTemp, ByVal tTag.Value, 2) + .Value = CInt(lTemp) + End If + + Case FIDT_SLONG + If (.Count > 1) Then + Dim alSLongs() As Long + ' for a signed long array, just redim a VB Long array and + ' copy Count bytes from the pointer + ReDim alSLongs(.Count - 1) + Call CopyMemory(alSLongs(0), ByVal tTag.Value, .Count * 4) + .Value = alSLongs + Else + ' copy a single signed long into a Long and assign + ' directly + Call CopyMemory(lTemp, ByVal tTag.Value, 4) + .Value = lTemp + End If + + Case FIDT_FLOAT + If (.Count > 1) Then + Dim asngFloats() As Single + ' for a float array, just redim a VB Single array and + ' copy Count bytes from the pointer + ReDim asngFloats(.Count - 1) + Call CopyMemory(asngFloats(0), ByVal tTag.Value, .Count * 4) + .Value = asngFloats + Else + Dim sngFloat As Single + ' copy a single float into a Single and assign + ' directly + Call CopyMemory(sngFloat, ByVal tTag.Value, 4) + .Value = sngFloat + End If + + Case FIDT_DOUBLE + If (.Count > 1) Then + Dim adblDoubles() As Double + ' for a double array, just redim a VB Double array and + ' copy Count bytes from the pointer + ReDim adblDoubles(.Count - 1) + Call CopyMemory(adblDoubles(0), ByVal tTag.Value, .Count * 8) + .Value = adblDoubles + Else + Dim dblDouble As Double + ' copy a single double into a Double and assign + ' directly + Call CopyMemory(dblDouble, ByVal tTag.Value, 8) + .Value = dblDouble + End If + + Case FIDT_PALETTE + ' copy 'Count' palette entries (RGBQUAD) form the value + ' pointer into the proper dimensioned array of RGBQUAD + ReDim .Palette(.Count - 1) + For i = 0 To .Count - 1 + Call CopyMemory(.Palette(i), ByVal tTag.Value + i * 4, 4) + Next i + + End Select + + End With + End If + +End Function + +Private Sub pNormalizeRational(ByRef Value As FIRATIONAL) + +Dim vntCommon As Long + + ' This function normalizes an unsigned fraction stored in a FIRATIONAL + ' structure by cancelling down the fraction. This is commonly done + ' by dividing both numerator and denominator by their greates + ' common divisor (gcd). + ' Does nothing if any of numerator and denominator is 1 or 0. + + With Value + If ((.Numerator <> 1) And (.Denominator <> 1) And _ + (.Numerator <> 0) And (.Denominator <> 0)) Then + vntCommon = gcd(.Numerator, .Denominator) + If (vntCommon <> 1) Then + ' convert values back to an unsigned long (may + ' result in a subtype Currency if the range of the + ' VB Long is insufficient for storing the value!) + .Numerator = FreeImage_UnsignedLong(.Numerator / vntCommon) + .Denominator = FreeImage_UnsignedLong(.Denominator / vntCommon) + End If + End If + End With + +End Sub + +Private Sub pNormalizeSRational(ByRef Value As FIRATIONAL) + +Dim lCommon As Long + + ' This function normalizes a signed fraction stored in a FIRATIONAL + ' structure by cancelling down the fraction. This is commonly done + ' by dividing both numerator and denominator by their greates + ' common divisor (gcd). + ' Does nothing if any of numerator and denominator is 1 or 0. + + With Value + If ((.Numerator <> 1) And (.Denominator <> 1) And _ + (.Numerator <> 0) And (.Denominator <> 0)) Then + lCommon = gcd(.Numerator, .Denominator) + If (lCommon <> 1) Then + ' using the CLng() function for not to get + ' a subtype Double here + .Numerator = CLng(.Numerator / lCommon) + .Denominator = CLng(.Denominator / lCommon) + End If + End If + + ' adjust the position of the negative sign if one is present: + ' it should preceed the numerator, not the denominator + If (.Denominator < 0) Then + .Denominator = -.Denominator + .Numerator = -.Numerator + End If + End With + +End Sub + +Private Function gcd(ByVal a As Variant, ByVal b As Variant) As Variant + +Dim vntTemp As Variant + + ' calculate greatest common divisor + + Do While (b) + vntTemp = b + ' calculate b = a % b (modulo) + ' this could be just: + ' b = a Mod b + ' but VB's Mod operator fails for unsigned + ' long values stored in currency variables + ' so, we use the mathematical definition of + ' the modulo operator taken from WikipediA. + b = a - floor(a / b) * b + a = vntTemp + Loop + gcd = a + +End Function + +Private Function floor(ByRef a As Variant) As Variant + + ' this is a VB version of the floor() function + If (a < 0) Then + floor = VBA.Int(a) + Else + floor = -VBA.Fix(-a) + End If + +End Function + +Private Function pTagToTagPtr(ByRef Tag As FREE_IMAGE_TAG) As Boolean + +Dim tTagSave As FITAG +Dim lpTag As Long +Dim abValueBuffer() As Byte +Dim lLength As Long +Dim lCount As Long + + ' This function converts tag data stored in a VB friendly structure + ' FREE_IMAGE_TAG into a real FreeImage tag pointer (FITAG **tag). + + ' This function is called, whenever tag data should be updated for an + ' image, since the FreeImage's tag pointer remains valid during the + ' whole lifetime of a DIB. So, changes written to that pointer (or + ' even better, the FITAG structure at the address, the pointer points + ' to), are real updates to the image's tag. + + With Tag + + lpTag = deref(.TagPtr) + + ' save current (FITAG) tag for an optional 'undo' operation + ' invoked on failure + Call CopyMemory(tTagSave, ByVal lpTag, Len(tTagSave)) + + ' set tag id + Call CopyMemory(ByVal lpTag + 8, .Id, 2) + ' set tag type + Call CopyMemory(ByVal lpTag + 10, .Type, 2) + ' set tag key (use native FreeImage function to handle + ' memory allocation) + Call FreeImage_SetTagKey(.TagPtr, .Key) + + ' here, we update the tag's value + ' generally, we create a plain byte buffer containing all the + ' value's data and use FreeImage_SetTagValue() with the + ' const void *value pointer set to the byte buffer's address. + + ' the variable abValueBuffer is our byte buffer that is, + ' depending on the FreeImage tag data type, allocated and filled + ' accordingly + ' The variables 'lLength' and 'lCount' are set up correctly for + ' each data type and will be filled into the FITAG structure + ' before calling FreeImage_SetTagValue(); after all, the VB + ' Tag structure's (FREE_IMAGE_TAG) 'Count' and 'Length' members + ' are updated with 'lLength' and 'lCount'. + + Select Case .Type + + Case FIDT_ASCII + ' use StrConv() to get an ASCII byte array from a VB String (BSTR) + abValueBuffer = StrConv(.Value, vbFromUnicode) + ' according to FreeImage's source code, both 'count' and 'length' + ' must be the length of the string + lCount = Len(.Value) + lLength = lCount + + Case FIDT_PALETTE + ' ensure, that there are at least 'Count' entries in the + ' palette array + lCount = .Count + If (UBound(.Palette) + 1 < lCount) Then + ' if not, adjust Count + lCount = UBound(.Palette) + 1 + End If + ' 4 bytes per element + lLength = lCount * 4 + ' allocate buffer and copy data from Palatte array + ReDim abValueBuffer(lLength - 1) + Call CopyMemory(abValueBuffer(0), .Palette(LBound(.Palette)), lLength) + + Case FIDT_RATIONAL, _ + FIDT_SRATIONAL + ' we use a helper function to get a byte buffer for any type of + ' rational value + lCount = pGetRationalValueBuffer(.RationalValue, abValueBuffer) + If (lCount > .Count) Then + lCount = .Count + End If + ' eight bytes per element (2 longs) + lLength = lCount * 8 + + Case Else + ' we use a helper function to get a byte buffer for any other type + lCount = pGetValueBuffer(.Value, .Type, lLength, abValueBuffer) + If (lCount > .Count) Then + lCount = .Count + End If + ' lLength was used as an OUT parameter when calling pGetValueBuffer + ' it now contains the size of one element in bytes so, multiply with + ' lCount to get the total length + lLength = lLength * lCount + + End Select + + ' set tag length + Call CopyMemory(ByVal lpTag + 16, lLength, 4) + ' set tag count + Call CopyMemory(ByVal lpTag + 12, lCount, 4) + + If (FreeImage_SetTagValue(.TagPtr, VarPtr(abValueBuffer(0))) <> 0) Then + + ' update Tag's members + ' update Count + .Count = lCount + ' update Length + .Length = lLength + ' update StringValue + .StringValue = FreeImage_TagToString(.Model, .TagPtr) + pTagToTagPtr = True + Else + + ' restore saved (FITAG) tag values on failure + Call CopyMemory(ByVal lpTag, tTagSave, Len(tTagSave)) + End If + + End With + +End Function + +Private Function pGetValueBuffer(ByRef Value As Variant, _ + ByVal MetaDataVarType As FREE_IMAGE_MDTYPE, _ + ByRef ElementSize As Long, _ + ByRef Buffer() As Byte) As Long + +Dim lElementCount As Long +Dim bIsArray As Boolean +Dim abValueBuffer(7) As Byte +Dim cBytes As Long +Dim i As Long + + ' This function copies any value provided in the Variant 'Value' + ' parameter into the byte array Buffer. 'Value' may contain an + ' array as well. The values in the byte buffer are aligned to fit + ' the FreeImage data type for tag values specified in + ' 'MetaDataVarType'. For integer values, it does not matter, in + ' which VB data type the values are provided. For example, it is + ' possible to transform a provided byte array into a unsigned long + ' array. + + ' The parameter 'ElementSize' is an OUT value, providing the actual + ' size per element in the byte buffer in bytes to the caller. + + ' This function works for the types FIDT_BYTE, FIDT_SHORT, FIDT_LONG, + ' FIDT_SBYTE , FIDT_SSHORT, FIDT_SLONG, FIDT_FLOAT, FIDT_DOUBLE + ' and FIDT_IFD + + ElementSize = pGetElementSize(MetaDataVarType) + If (Not IsArray(Value)) Then + lElementCount = 1 + Else + On Error Resume Next + lElementCount = UBound(Value) - LBound(Value) + 1 + On Error GoTo 0 + bIsArray = True + End If + + If (lElementCount > 0) Then + ReDim Buffer((lElementCount * ElementSize) - 1) + + If (Not bIsArray) Then + cBytes = pGetVariantAsByteBuffer(Value, abValueBuffer) + If (cBytes > ElementSize) Then + cBytes = ElementSize + End If + Call CopyMemory(Buffer(0), abValueBuffer(0), cBytes) + Else + For i = LBound(Value) To UBound(Value) + cBytes = pGetVariantAsByteBuffer(Value(i), abValueBuffer) + If (cBytes > ElementSize) Then + cBytes = ElementSize + End If + Call CopyMemory(Buffer(0 + (i * ElementSize)), abValueBuffer(0), cBytes) + Next i + End If + + pGetValueBuffer = lElementCount + End If + +End Function + +Private Function pGetRationalValueBuffer(ByRef RationalValues() As FIRATIONAL, _ + ByRef Buffer() As Byte) As Long + +Dim lElementCount As Long +Dim abValueBuffer(7) As Byte +Dim cBytes As Long +Dim i As Long + + ' This function copies a number of elements from the FIRATIONAL array + ' 'RationalValues' into the byte buffer 'Buffer'. + + ' From the caller's point of view, this function is the same as + ' 'pGetValueBuffer', except, it only works for arrays of FIRATIONAL. + + ' This function works for the types FIDT_RATIONAL and FIDT_SRATIONAL. + + lElementCount = UBound(RationalValues) - LBound(RationalValues) + 1 + ReDim Buffer(lElementCount * 8 + 1) + + For i = LBound(RationalValues) To UBound(RationalValues) + cBytes = pGetVariantAsByteBuffer(RationalValues(i).Numerator, abValueBuffer) + If (cBytes > 4) Then + cBytes = 4 + End If + Call CopyMemory(Buffer(0 + (i * 8)), abValueBuffer(0), cBytes) + + cBytes = pGetVariantAsByteBuffer(RationalValues(i).Denominator, abValueBuffer) + If (cBytes > 4) Then + cBytes = 4 + End If + Call CopyMemory(Buffer(4 + (i * 8)), abValueBuffer(0), cBytes) + Next i + + pGetRationalValueBuffer = lElementCount + +End Function + +Private Function pGetVariantAsByteBuffer(ByRef Value As Variant, _ + ByRef Buffer() As Byte) As Long + +Dim lLength As Long + + ' This function fills a byte buffer 'Buffer' with data taken + ' from a Variant parameter. Depending on the Variant's type and, + ' width, it copies N (lLength) bytes into the buffer starting + ' at the buffer's first byte at Buffer(0). The function returns + ' the number of bytes copied. + + ' It is much easier to assign the Variant to a variable of + ' the proper native type first, since gathering a Variant's + ' actual value is a hard job to implement for each subtype. + + Select Case VarType(Value) + + Case vbByte + Buffer(0) = Value + lLength = 1 + + Case vbInteger + Dim iInteger As Integer + iInteger = Value + lLength = 2 + Call CopyMemory(Buffer(0), iInteger, lLength) + + Case vbLong + Dim lLong As Long + lLong = Value + lLength = 4 + Call CopyMemory(Buffer(0), lLong, lLength) + + Case vbCurrency + Dim cCurrency As Currency + ' since the Currency data type is a so called scaled + ' integer, we have to divide by 10.000 first to get the + ' proper bit layout. + cCurrency = Value / 10000 + lLength = 8 + Call CopyMemory(Buffer(0), cCurrency, lLength) + + Case vbSingle + Dim sSingle As Single + sSingle = Value + lLength = 4 + Call CopyMemory(Buffer(0), sSingle, lLength) + + Case vbDouble + Dim dblDouble As Double + dblDouble = Value + lLength = 8 + Call CopyMemory(Buffer(0), dblDouble, lLength) + + End Select + + pGetVariantAsByteBuffer = lLength + +End Function + +Private Function pGetElementSize(ByVal vt As FREE_IMAGE_MDTYPE) As Long + + ' This function returns the width in bytes for any of the + ' FreeImage metadata tag data types. + + Select Case vt + + Case FIDT_BYTE, _ + FIDT_SBYTE, _ + FIDT_UNDEFINED, _ + FIDT_ASCII + pGetElementSize = 1 + + Case FIDT_SHORT, _ + FIDT_SSHORT + pGetElementSize = 2 + + Case FIDT_LONG, _ + FIDT_SLONG, _ + FIDT_FLOAT, _ + FIDT_PALETTE, _ + FIDT_IFD + pGetElementSize = 4 + + Case Else + pGetElementSize = 8 + + End Select + +End Function + + + +'-------------------------------------------------------------------------------- +' Private pointer manipulation helper functions +'-------------------------------------------------------------------------------- + +Private Function pGetStringFromPointerA(ByRef Ptr As Long) As String + +Dim abBuffer() As Byte +Dim lLength As Long + + ' This function creates and returns a VB BSTR variable from + ' a C/C++ style string pointer by making a redundant deep + ' copy of the string's characters. + + If (Ptr) Then + ' get the length of the ANSI string pointed to by ptr + lLength = lstrlen(Ptr) + If (lLength) Then + ' copy characters to a byte array + ReDim abBuffer(lLength - 1) + Call CopyMemory(abBuffer(0), ByVal Ptr, lLength) + ' convert from byte array to unicode BSTR + pGetStringFromPointerA = StrConv(abBuffer, vbUnicode) + End If + End If + +End Function + +Private Function deref(ByVal Ptr As Long) As Long + + ' This function dereferences a pointer and returns the + ' contents as it's return value. + + ' in C/C++ this would be: + ' return *(ptr); + + Call CopyMemory(deref, ByVal Ptr, 4) + +End Function + +Private Sub pSwap(ByVal lpSrc As Long, _ + ByVal lpDst As Long) + +Dim lpTmp As Long + + ' This function swaps two DWORD memory blocks pointed to + ' by lpSrc and lpDst, whereby lpSrc and lpDst are actually + ' no pointer types but contain the pointer's address. + + ' in C/C++ this would be: + ' void pSwap(int lpSrc, int lpDst) { + ' int tmp = *(int*)lpSrc; + ' *(int*)lpSrc = *(int*)lpDst; + ' *(int*)lpDst = tmp; + ' } + + Call CopyMemory(lpTmp, ByVal lpSrc, 4) + Call CopyMemory(ByVal lpSrc, ByVal lpDst, 4) + Call CopyMemory(ByVal lpDst, lpTmp, 4) + +End Sub + +Private Function pGetMemoryBlockPtrFromVariant(ByRef Data As Variant, _ + Optional ByRef SizeInBytes As Long, _ + Optional ByRef ElementSize As Long) As Long + + ' This function returns the pointer to the memory block provided through + ' the Variant parameter 'data', which could be either a Byte, Integer or + ' Long array or the address of the memory block itself. In the last case, + ' the parameter 'SizeInBytes' must not be omitted or zero, since it's + ' correct value (the size of the memory block) can not be determined by + ' the address only. So, the function fails, if 'SizeInBytes' is omitted + ' or zero and 'data' is not an array but contains a Long value (the address + ' of a memory block) by returning Null. + + ' If 'data' contains either a Byte, Integer or Long array, the pointer to + ' the actual array data is returned. The parameter 'SizeInBytes' will + ' be adjusted correctly, if it was less or equal zero upon entry. + + ' The function returns Null (zero) if there was no supported memory block + ' provided. + + ' do we have an array? + If (VarType(Data) And vbArray) Then + Select Case (VarType(Data) And (Not vbArray)) + + Case vbByte + ElementSize = 1 + pGetMemoryBlockPtrFromVariant = pGetArrayPtrFromVariantArray(Data) + If (pGetMemoryBlockPtrFromVariant) Then + If (SizeInBytes <= 0) Then + SizeInBytes = (UBound(Data) + 1) + + ElseIf (SizeInBytes > (UBound(Data) + 1)) Then + SizeInBytes = (UBound(Data) + 1) + + End If + End If + + Case vbInteger + ElementSize = 2 + pGetMemoryBlockPtrFromVariant = pGetArrayPtrFromVariantArray(Data) + If (pGetMemoryBlockPtrFromVariant) Then + If (SizeInBytes <= 0) Then + SizeInBytes = (UBound(Data) + 1) * 2 + + ElseIf (SizeInBytes > ((UBound(Data) + 1) * 2)) Then + SizeInBytes = (UBound(Data) + 1) * 2 + + End If + End If + + Case vbLong + ElementSize = 4 + pGetMemoryBlockPtrFromVariant = pGetArrayPtrFromVariantArray(Data) + If (pGetMemoryBlockPtrFromVariant) Then + If (SizeInBytes <= 0) Then + SizeInBytes = (UBound(Data) + 1) * 4 + + ElseIf (SizeInBytes > ((UBound(Data) + 1) * 4)) Then + SizeInBytes = (UBound(Data) + 1) * 4 + + End If + End If + + End Select + Else + ElementSize = 1 + If ((VarType(Data) = vbLong) And _ + (SizeInBytes >= 0)) Then + pGetMemoryBlockPtrFromVariant = Data + End If + End If + +End Function + +Private Function pGetArrayPtrFromVariantArray(ByRef Data As Variant) As Long + +Dim eVarType As VbVarType +Dim lDataPtr As Long + + ' This function returns a pointer to the first array element of + ' a VB array (SAFEARRAY) that is passed through a Variant type + ' parameter. (Don't try this at home...) + + ' cache VarType in variable + eVarType = VarType(Data) + + ' ensure, this is an array + If (eVarType And vbArray) Then + + ' data is a VB array, what means a SAFEARRAY in C/C++, that is + ' passed through a ByRef Variant variable, that is a pointer to + ' a VARIANTARG structure + + ' the VARIANTARG structure looks like this: + + ' typedef struct tagVARIANT VARIANTARG; + ' struct tagVARIANT + ' { + ' Union + ' { + ' struct __tagVARIANT + ' { + ' VARTYPE vt; + ' WORD wReserved1; + ' WORD wReserved2; + ' WORD wReserved3; + ' Union + ' { + ' [...] + ' SAFEARRAY *parray; // used when not VT_BYREF + ' [...] + ' SAFEARRAY **pparray; // used when VT_BYREF + ' [...] + + ' the data element (SAFEARRAY) has an offset of 8, since VARTYPE + ' and WORD both have a length of 2 bytes; the pointer to the + ' VARIANTARG structure is the VarPtr of the Variant variable in VB + + ' getting the contents of the data element (in C/C++: *(data + 8)) + lDataPtr = deref(VarPtr(Data) + 8) + + ' dereference the pointer again (in C/C++: *(lDataPtr)) + lDataPtr = deref(lDataPtr) + + ' test, whether 'lDataPtr' now is a Null pointer + ' in that case, the array is not yet initialized and so we can't dereference + ' it another time since we have no permisson to acces address 0 + + ' the contents of 'lDataPtr' may be Null now in case of an uninitialized + ' array; then we can't access any of the SAFEARRAY members since the array + ' variable doesn't event point to a SAFEARRAY structure, so we will return + ' the null pointer + + If (lDataPtr) Then + ' the contents of lDataPtr now is a pointer to the SAFEARRAY structure + + ' the SAFEARRAY structure looks like this: + + ' typedef struct FARSTRUCT tagSAFEARRAY { + ' unsigned short cDims; // Count of dimensions in this array. + ' unsigned short fFeatures; // Flags used by the SafeArray + ' // routines documented below. + ' #if defined(WIN32) + ' unsigned long cbElements; // Size of an element of the array. + ' // Does not include size of + ' // pointed-to data. + ' unsigned long cLocks; // Number of times the array has been + ' // locked without corresponding unlock. + ' #Else + ' unsigned short cbElements; + ' unsigned short cLocks; + ' unsigned long handle; // Used on Macintosh only. + ' #End If + ' void HUGEP* pvData; // Pointer to the data. + ' SAFEARRAYBOUND rgsabound[1]; // One bound for each dimension. + ' } SAFEARRAY; + + ' since we live in WIN32, the pvData element has an offset + ' of 12 bytes from the base address of the structure, + ' so dereference the pvData pointer, what indeed is a pointer + ' to the actual array (in C/C++: *(lDataPtr + 12)) + lDataPtr = deref(lDataPtr + 12) + End If + + ' return this value + pGetArrayPtrFromVariantArray = lDataPtr + + ' a more shorter form of this function would be: + ' (doesn't work for uninitialized arrays, but will likely crash!) + 'pGetArrayPtrFromVariantArray = deref(deref(deref(VarPtr(data) + 8)) + 12) + End If + +End Function diff --git a/Wrapper/VB6/mfreeimage/WhatsNew_VB.txt b/Wrapper/VB6/mfreeimage/WhatsNew_VB.txt index 7268ecd..472cf02 100644 --- a/Wrapper/VB6/mfreeimage/WhatsNew_VB.txt +++ b/Wrapper/VB6/mfreeimage/WhatsNew_VB.txt @@ -1,649 +1,649 @@ -What's New for FreeImage VB Wrapper - -* : fixed -- : removed -! : changed -+ : added - -October 1, 2012 - 2.17 -- [Carsten Klein] removed temporary workaround for 16-bit standard type bitmaps introduced in version 2.15, which temporarily stored RGB masks directly after the BITMAPINFO structure, when creating a HBITMAP. -* [Carsten Klein] fixed a potential overflow bug in both pNormalizeRational and pNormalizeSRational: these now do nothing if any of numerator and denominator is either 1 or 0 (zero). -+ [Carsten Klein] added load flag JPEG_GREYSCALE as well as the enum constant FILO_JPEG_GREYSCALE. -! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL to 4 to match current version 3.15.4 - -March 19, 2012 - 2.16 -! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL to 3 to match current version 3.15.3 - -March 12, 2012 - 2.15 -+ [Carsten Klein] added function FreeImage_ConvertToUINT16. -+ [Carsten Klein] added function FreeImage_ConvertToRGB16. -+ [Carsten Klein] added function FreeImage_GetThumbnail. -+ [Carsten Klein] added function declaration FreeImage_SetThumbnailInt and a real VB Boolean returning function FreeImage_SetThumbnail. -+ [Carsten Klein] added RAW_HALFSIZE load flag as well as the enum constant FILO_RAW_HALFSIZE. -+ [Carsten Klein] added wrapper function FreeImage_GetPictureData, which returns a byte array suitable for assigning to an Office image control's PictureData property. -+ [Carsten Klein] added wrapper function FreeImage_CreateFromPictureData, which creates a FreeImage bitmap from a PictureData byte array. -+ [Carsten Klein] added new save flag JPEG_BASELINE (also added FISO_JPEG_BASELINE to enumeration FREE_IMAGE_SAVE_OPTIONS). -+ [Carsten Klein] added a workaround for providing valid BITMAPINFO structures for non 555 16-bpp images to Windows API functions like CreateDIBSection, CreateDIBBitmap, StretchDIBits or SetDIBitsToDevice. -! [Carsten Klein] changed constants FREEIMAGE_MINOR_VERSION and FREEIMAGE_RELEASE_SERIAL: set to 15 and 2 respectively to match current version 3.15.2 - -March 13, 2011 - 2.14 -* [Glenn Thorpe] fixed a typo error with the call to FreeImage_HasPixels inside FreeImage_CreateMask. - -August 11, 2010 - 2.13 -+ [Carsten Klein] added PSD load flags PSD_CMYK and PSD_LAB as well as the enum constants FILO_PSD_CYMK and FILO_PSD_LAB. -+ [Carsten Klein] added TIFF_LOGLUV save flag as well as the enum constant FISO_TIFF_LOGLUV. - -July 20, 2010 - 2.12 -+ [Carsten Klein] added support for the new EXIF_RAW metadata model by adding enum constant FIMD_EXIF_RAW. -+ [Carsten Klein] added the new FIF_LOAD_NOPIXELS flag as well as the enum constant FILO_LOAD_NOPIXELS. -+ [Carsten Klein] added function declaration FreeImage_HasPixelsInt and a real VB Boolean returning function FreeImage_HasPixels. -+ [Carsten Klein] added function declaration FreeImage_FIFSupportsNoPixelsInt and a real VB Boolean returning function FreeImage_FIFSupportsNoPixels. - -June 20, 2010 - 2.11 -+ [Carsten Klein] added new save flag JPEG_OPTIMIZE (also added FISO_JPEG_OPTIMIZE to enumeration FREE_IMAGE_SAVE_OPTIONS). - -April 20, 2010 - 2.10 -+ [Carsten Klein] added new save flag TARGA_SAVE_RLE (also added FISO_TARGA_SAVE_RLE to enumeration FREE_IMAGE_SAVE_OPTIONS). -! [Carsten Klein] changed constants FREEIMAGE_MINOR_VERSION and FREEIMAGE_RELEASE_SERIAL: set to 14 and 0 respectively to match current version 3.14.0 -+ [Carsten Klein] added function FreeImage_ConvertToFloat. -+ [Carsten Klein] added function FreeImage_SaveMultiBitmapToMemory. -+ [Carsten Klein] added wrapper functions FreeImage_SaveMultiBitmapToMemoryEx and FreeImage_SaveMultiBitmapToMemoryEx2. -+ [Carsten Klein] added wrapper function FreeImage_OpenMultiBitmapEx, which only opens existing files, but has support for automatic image format detection. -+ [Carsten Klein] added wrapper function FreeImage_CreateMultiBitmapEx, which only creates new (empty) multi-page bitmaps with support for automatic image format detection. -* [Carsten Klein] fixed a bug in FreeImage_LoadEx: now uses the file specified for format detection rather than the filename extension. -+ [Carsten Klein] improved error messages in function FreeImage_LoadEx. -* [Carsten Klein] fixed a bug in FreeImage_AcquireMemoryEx: no more crashes when passing an uninitialized array. -+ [Carsten Klein] added thin wrapper functions, enabling proper handling of Boolean parameters: -+ added wrapper function FreeImage_OpenMultiBitmap -+ added wrapper function FreeImage_UnlockPage -+ added wrapper function FreeImage_RotateEx -+ added wrapper function FreeImage_MakeThumbnail -+ added wrapper function FreeImage_GetAdjustColorsLookupTable -+ added wrapper function FreeImage_ApplyColorMapping -+ added wrapper function FreeImage_SwapColors -+ added wrapper function FreeImage_SwapColorsByLong -+ added wrapper function FreeImage_ApplyIndexMapping -+ added wrapper function FreeImage_SetTransparent -+ added wrapper function FreeImage_ConvertFromRawBits -+ added wrapper function FreeImage_ConvertToRawBits -+ added wrapper function FreeImage_ConvertToStandardType -+ added wrapper function FreeImage_ConvertToType -! [Carsten Klein] changed the parameter names of most functions. -! [Carsten Klein] changed signature of functions FreeImage_ConvertFromRawBits and FreeImage_ConvertToRawBits: 'ByRef Bits As Long' is now 'ByVal BitsPtr As Long'. -+ [Carsten Klein] added wrapper functions FreeImage_ConvertFromRawBitsEx and FreeImage_ConvertToRawBitsEx. -* [Carsten Klein] fixed a bug in declaration of function FreeImage_TmoReinhard05Ex: parameters 'Adaption' and 'ColorCorrection' are now passed by value. -- [Carsten Klein] removed half-implemented function FreeImage_SetChannelEx. -+ [Carsten Klein] added wrapper function FreeImage_SetChannelIOP. -- [Carsten Klein] removed needless default values of optional parameters. -- [Carsten Klein] removed function declaration FreeImage_CompositeByLong: replaced by declaration FreeImage_Composite. -! [Carsten Klein] changed function declaration FreeImage_Composite: application back color is now passed as ByRef ... As Any and so takes both RGBQUAD and Long valus. -+ [Carsten Klein] added wrapper function FreeImage_UnloadEx, which additionally sets the ByRef-passed Bitmap handle to zero after unloading. -+ [Carsten Klein] added wrapper functions ConvertColor and ConvertOleColor to convert VB-style BGR colors into RGB color values. - -! now FreeImage version 3.14.0 - -February 9, 2010 - 2.9.1 -* [Carsten Klein] fixed a bug in FreeImage_GetBackgroundColorAsLong: parameter 'bkcolor' is now properly passed ByRef. - -February 9, 2010 - 2.9 -* [Carsten Klein] fixed a syntax typo - -February 8, 2010 - 2.8 -* [Mike Weir] fixed a bug in function FreeImage_ApplyColorMappingEx: now properly includes all specified mapping entries -* [Carsten Klein] fixed a bug in function FreeImage_ApplyIndexMappingEx: now properly includes all specified mapping entries -* [Mike Weir] fixed a bug in function FreeImage_RescaleEx: now also rescales the image, if either the new width or height matches the image's current size -* [WinAnd / Carsten Klein] fixed a bug in function FreeImage_GetTransparencyTableExClone: returns an uninitialized array if there is no transparency table -* [WinAnd / Carsten Klein] fixed a bug in function FreeImage_SearchPalette: no longer crashes if there is no transparency table - -December 21, 2009 - 2.7 -! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 1 to match current version 3.13.1 - -! now FreeImage version 3.13.1 - -December 18, 2009 - 2.6 -- [Carsten Klein] removed usage of constants vbPicTypeBitmap and vbPicTypeIcon: these are not available in VBA environments like Excel, Access or Outlook. - -September 08, 2009 - 2.5 -! [Carsten Klein] changed constant FREEIMAGE_MINOR_VERSION: set to 13 to match current version 3.13.0 -+ [Carsten Klein] added load flag constant JPEG_EXIFROTATE and new member FILO_JPEG_EXIFROTATE to enumeration FREE_IMAGE_LOAD_OPTIONS. -+ [Carsten Klein] added support for the PFM image format. -+ [Carsten Klein] added support for the PICT and RAW image formats. -+ [Carsten Klein] added UNICODE functions FreeImage_JPEGTransformU and FreeImage_JPEGCropU. -+ [Carsten Klein] added enumeration FREE_IMAGE_COLOR_OPTIONS, which contains options to specify colors, used with FreeImage_FillBackground and FreeImage_EnlargeCanvas. -+ [Carsten Klein] added function FreeImage_FillBackground: although this returns BOOL in C/C++, the VB version only returns a Long. -+ [Carsten Klein] added wrapper functions FreeImage_FillBackgroundEx and FreeImage_FillBackgroundByLong, taking an RGBQUAD and a Long 'Color' argument respectively and return a true VB Boolean. -+ [Carsten Klein] added function FreeImage_EnlargeCanvas. -+ [Carsten Klein] added functions FreeImage_AllocateEx and FreeImage_AllocateExT. -+ [Carsten Klein] added function FreeImage_TmoReinhard05Ex. -+ [Carsten Klein] added function FreeImage_Rotate. -+ [Carsten Klein] added wrapper function FreeImage_RotateIOP. - -! now FreeImage version 3.13.0 - -March 18, 2009 - 2.4.2 -+ [Carsten Klein] added enumeration FREE_IMAGE_FRAME_DISPOSAL_METHODS, which provides the frame disposal options needed to create animated GIF files. - -July 29, 2008 - 2.4.1 -* [Carsten Klein] minor documentation updates -! [Carsten Klein] renamed member FICF_PALETTISED_8BPP of enumeration FREE_IMAGE_CONVERSION_FLAGS into FICF_PALLETISED_8BPP. - -June 30, 2008 - 2.4 -* [Carsten Klein] fixed some minor issues in FreeImage_PaintTransparent() - -June 06, 2008 - 2.3 -+ [Carsten Klein] added new compression flags to the JPEG and PNG plugins -! [Carsten Klein] renamed wrapper function FreeImage_CloneMetadata() to FreeImage_CloneMetadataEx(): now, there is a native function called FreeImage_CloneMetadata(). -+ [Carsten Klein] added private and internal function declaration for FreeImage_CloneMetadata() along with it's public Boolean returning wrapper function. -- [Carsten Klein] removed the FreeImage_ColorQuantizeEx() stuff from both functions FreeImage_ConvertColorDepth() and FreeImage_ConvertColorDepthIOP(): removed parameters PaletteSize, ReserveSize and ReservePalette. -- [Carsten Klein] changed declaration of FreeImage_ColorQuantizeEx() to be a internal function private to the wrapper with an 'Int' appendix. -+ [Carsten Klein] added two more VB-friendly public wrapper functions FreeImage_ColorQuantizeEx() and FreeImage_ColorQuantizeExIOP(). -+ [Carsten Klein] added wrapper function FreeImage_GetPalettePtr(): gets the pointer to a specified array of RGBQUADs: intended to be used together with any of the ColorQuantizeEx functions. -! [Carsten Klein] changed constant FREEIMAGE_MINOR_VERSION: set to 11 to match current version 3.11.0 - -! now FreeImage version 3.11.0 - -December 14, 2007 - 2.2.1 -+ [Carsten Klein] added constants for member 'biCompression' in BITMAPINFOHEADER struct -+ [Carsten Klein] added wrapper function FreeImage_GetInfoHeaderEx(), which returns a fully populated BITMAPINFOHEADER struct for a bitmap. -* [Carsten Klein] fixed a bug in FreeImage_GetFileTypeFromMemoryEx(): now calls FreeImage_CloseMemory() releasing the hStream to prevent memory leaks. -+ [Carsten Klein] added wrapper function FreeImage_GetColorizedPalette(): returns a colorized greyscale palettte. -+ [Carsten Klein] added wrapper function FreeImage_Colorize(): applies a colorized greyscale palettte obtained from FreeImage_GetColorizedPalette() to a bitmap. -+ [Carsten Klein] added wrapper function FreeImage_Sepia(): calls FreeImage_Colorize() with proper parameters to apply a so called sepia palette to a bitmap. - -December 12, 2007 - 2.2 -* [Carsten Klein] Fixed a small bug in FreeImage_PaintTransparent, which now calls function FreeImage_ConvertTo32Bits instead of FreeImage_ConvertTo32Bits2. - -November 15, 2007 - 2.1 -* [Carsten Klein] adjusted page numbers of the API documentation in FreeImage function declarations to match FreeImage 3.10.0 API documentation -- [Carsten Klein] removed parameter 'bUnloadSource' from function FreeImage_GetOlePictureIcon(): an hIcon should not be destroyed if OleCreatePictureIndirect() is called with fOwn = True. -! [Carsten Klein] refactored FreeImage_GetOlePicture(): now relies on FreeImage_GetBitmap(). - -November 10, 2007 - 2.0.8 -! [Carsten Klein] changed declaration of FreeImage_SetOutputMessage(): now points transparently to the __stdcall version of this function in the library. -+ [Carsten Klein] added function declaraton for FreeImage_MultigridPoissonSolver(). -+ [Carsten Klein] added function declaraton for FreeImage_GetTransparentIndex() and FreeImage_SetTransparentIndex(). -+ [Carsten Klein] added private and internal function declaraton for FreeImage_AdjustColors() along with it's public Boolean returning wrapper function. -+ [Carsten Klein] added function declaraton for FreeImage_GetAdjustColorsLookupTable(). -+ [Carsten Klein] added wrapper function FreeImage_GetAdjustColorsLookupTableEx(): this takes a real VB style Byte array ton receive the lookup table created. -+ [Carsten Klein] added function declaraton for FreeImage_ApplyColorMapping(). -+ [Carsten Klein] added wrapper function FreeImage_ApplyColorMappingEx(): this takes a real VB style RGBQUAD array. -+ [Carsten Klein] added function declaratons for FreeImage_SwapColors() and FreeImage_SwapColorsByLong(). -+ [Carsten Klein] added function declaraton for FreeImage_ApplyIndexMapping(). -+ [Carsten Klein] added wrapper function FreeImage_ApplyIndexMappingEx(): this takes a real VB style Byte array. -+ [Carsten Klein] added function declaraton for FreeImage_SwapPaletteIndices(). - -November 05, 2007 - 2.0.7 -+ [Carsten Klein] added 4 bit color depth to both function pGetNextColorDepth() and pGetPrevousColorDepth() -- [Carsten Klein] removed member FICF_PREPARE_RESCALE from enumeration FREE_IMAGE_CONVERSION_FLAGS -- [Carsten Klein] removed all references to FICF_PREPARE_RESCALE: Converting color depth before rescaling an image is no longer performed by the wrapper. Since FreeImage now transparently converts color depth on rescaling, doing this in the wrapper is no longer needed. -! [Carsten Klein] refactored wrapper function FreeImage_ConvertColorDepth(): removed case FICF_PREPARE_RESCALE; is now more similar to C# wrapper's version of this function. -! [Carsten Klein] refactored wrapper function FreeImage_SaveEx(): removed case FICF_PREPARE_RESCALE; is now more similar to C# wrapper's version of this function. - -September 14, 2007 - 2.0.6 -+ [Carsten Klein] added function declaration and Boolean wrapper function for FreeImage_PreMultiplyWithAlpha(). - -July 26, 2007 - 2.0.5 -+ [Carsten Klein] added wrapper function FreeImage_GetBitmap(): returns an HBITMAP created by the CreateDIBSection() function and so has the same color depth as the original DIB. -+ [Carsten Klein] added wrapper function FreeImage_GetBitmapForDevice(): returns an HBITMAP created by the CreateDIBitmap() function and so has the same color depth as the specified reference DC or as the desktop, if the 'hDC' parameter was omitted. -- [Carsten Klein] removed function declaration for GetWindowDC(): this function is no longer used. -* [Carsten Klein] fixed a bug in wrapper function FreeImage_IsExtensionValidForFIF(): string comparison now includes a comma. -* [Carsten Klein] fixed a bug in wrapper function FreeImage_IsFilenameValidForFIF(): string comparison now includes a comma. - -July 25, 2007 - 2.0.4 -* [Carsten Klein] fixed a bug in function FreeImage_GetPaletteExClone(): now actually returns the palette as RGBQUAD array plus some other minor improvements -+ [Carsten Klein] added wrapper function FreeImage_GetPaletteExLongClone(): this function returns a VB style Byte array that is only wrapped around FreeImage's pointer to a DIB's transparency table. -+ [Carsten Klein] added wrapper function FreeImage_GetTransparencyTableEx(): this function returns a VB style Byte array that is only wrapped around FreeImage's pointer to a DIB's transparency table. -! [Carsten Klein] changed name of wrapper function FreeImage_GetTransparencyTableEx(): this function is now named FreeImage_GetTransparencyTableExClone(), since it actually returns a clone (deep copy) of an image's transparency table (compare with FreeImage_GetPaletteExClone()). -+ [Carsten Klein] added wrapper function FreeImage_SetPalette(): sets an image's palette through a VB style RGBQUAD array. -+ [Carsten Klein] added wrapper function FreeImage_SetPaletteLong(): sets an image's palette through a VB style Long array. -+ [Carsten Klein] added function declaration for CreateDIBsection() -+ [Carsten Klein] added function declaration for DeleteDC() -* [Carsten Klein] fixed a bug in wrapper function FreeImage_CreateFromScreen(): now the memory DC is deleted with the DeleteDC() function and no longer with the DeleteObject() function. - -July 05, 2007 - 2.0.3 -+ [Carsten Klein] added wrapper function FreeImage_GetFileTypeFromMemoryEx(): more VB friendly version of FreeImage_GetFileTypeFromMemory() which may take an array rather than a FIMEMORY stream. - -May 21, 2007 - 2.0.2 -! [Carsten Klein] changed constant FREEIMAGE_MINOR_VERSION: set to 10 to match current version 3.10.0 -! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 0 to match current version 3.10.0 -+ [Carsten Klein] added image format constants FIF_EXR, FIF_J2K and FIF_JP2 to enumeration FREE_IMAGE_FORMAT. -+ [Carsten Klein] added tone mapping operator constant FITMO_FATTAL02 to enumeration FREE_IMAGE_TMO. -+ [Carsten Klein] added save option constants J2K_DEFAULT and JP2_DEFAULT for JPEG2000 format. -+ [Carsten Klein] added save option constants EXR_DEFAULT, EXR_FLOAT, EXR_NONE, EXR_ZIP, EXR_PIZ, EXR_PXR24, EXR_B44 and EXR_LC for EXR format. -+ [Carsten Klein] added save option constants for EXR format to enumeration FREE_IMAGE_SAVE_OPTIONS. -+ [Carsten Klein] added declared function FreeImage_TmoFattal02(): adds support for Gradient domain high dynamic range compression (R. Fattal, 2002) - -! now FreeImage version 3.10.0 - -February 24, 2007 - 2.0.1 -* [Carsten Klein] fixed a bug in function FreeImage_CreateFromScreen(): now size of image created is according to window to be captured if parameter 'hwnd' <> 0. -+ [Carsten Klein] added parameter 'bClientAreaOnly' to function FreeImage_CreateFromScreen(). -+ [Carsten Klein] added blitting option 'CAPTUREBLT' when calling function BitBlt() in function FreeImage_CreateFromScreen(). -- [Carsten Klein] removed unused variable 'hDIB' from functions FreeImage_CreateFromScreen() and FreeImage_LoadEx(). Thanks to Bruce Rusk for pointing that out. - -February 16, 2007 - 2.0 -! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 3 to match current version 3.9.3 -! [Carsten Klein] changed JPEG load/save flag option values: changed constants and both enumerations FREE_IMAGE_LOAD_OPTIONS and FREE_IMAGE_SAVE_OPTIONS. -+ [Carsten Klein] added ICC Color Profile support: -! changed signature of declared function FreeImage_GetICCProfile(): is now declared 'Private' and suffixed with '...Int()'. -+ added wrapper function FreeImage_GetICCProfile(): is the public wrapper function for private function FreeImage_GetICCProfileInt(), returing a real FIICCPROFILE structure. -+ added constant FREE_IMAGE_ICC_COLOR_MODEL_MASK. -+ added enumeration FREE_IMAGE_ICC_COLOR_MODEL. -+ added wrapper function FreeImage_GetICCProfileColorModel(): returns the color profile's color model (FIICCPROFILE.flags member). -+ added wrapper function FreeImage_GetICCProfileSize(): returns the color profile data's size in bytes. -+ added wrapper function FreeImage_GetICCProfileDataPointer(): returns the pointer to the color profile data. -+ added wrapper function FreeImage_HasICCProfile(): returns whether a color profile is available for a dib or not. -! [Carsten Klein] changed behaviour of wrapper function FreeImage_RescaleEx() and all it's derived functions: no clone is returned if the actual and desired image size are the same. -+ [Carsten Klein] added parameter 'bForceCloneCreation' to wrapper function FreeImage_RescaleEx() and all it's derived functions. - -! now FreeImage version 3.9.3 - -January 09, 2007 - 1.9.4 -! [Carsten Klein] changed scope of declared function FreeImage_GetFileTypeUInt(): is now private according to all other '...Int' functions wrapped by a VB-friendly function. -! [Carsten Klein] changed scope of declared function FreeImage_GetFIFFromFilenameUInt(): is now private according to all other '...Int' functions wrapped by a VB-friendly function. -! [Carsten Klein] changed signature of declared functions FreeImage_GetBackgroundColorInt() and FreeImage_SetBackgroundColorInt(): now both have a 'ByRef bkcolor As RGBQUAD' parameter instead of 'ByVal bkcolor As Long'. -+ [Carsten Klein] added declared functions FreeImage_GetBackgroundColorAsLongInt(): this has a 'ByRef bkcolor As Long' parameter and provides the background color as a Long value. -+ [Carsten Klein] added declared functions FreeImage_SetBackgroundColorAsLongInt(): this has a 'ByRef bkcolor As Long' parameter and takes the background color as a Long value. -! [Carsten Klein] changed signature of wrapper functions FreeImage_GetBackgroundColor() and FreeImage_SetBackgroundColor(): now both have a 'ByRef bkcolor As RGBQUAD' parameter instead of 'ByVal bkcolor As Long'. -+ [Carsten Klein] added wrapper functions FreeImage_GetBackgroundColorAsLong() and FreeImage_SetBackgroundColorAsLong(): both have a 'ByRef bkcolor As Long' parameter and so offer getting and setting the background color through a Long value. -+ [Carsten Klein] added wrapper functions FreeImage_GetBackgroundColorEx() and FreeImage_SetBackgroundColorEx(): both both take 4 ByRef Byte parameters 'Alpha', 'Red', 'Green' and 'Blue', one for each color component. - -January 05, 2007 - 1.9.3 -+ [Carsten Klein] added wrapper function FreeImage_GetLockedPageNumbersEx(): this returns a real VB-style array of Longs containing the page numbers of all locked pages. - -January 02, 2007 - 1.9.2 -* [Carsten Klein] fixed a bug in inline description of function FreeImage_GetPaletteEx(): now tells to use function FreeImage_DestroyLockedArrayRGBQUAD() to free an array returned by this function. -* [Carsten Klein] fixed some minor bugs in inline documentation. -* [Carsten Klein] fixed a serious bug in function FreeImage_SaveEx(): parameter 'bUnloadSource' is now interpreted correctly under all circumstances. -* [Carsten Klein] fixed some minor issues in function FreeImage_SaveEx(). - -December 29, 2006 - 1.9.1 -+ [Carsten Klein] added enumeration item FID_BAYER16x16: now supports Bayer ordered dispersed dot dithering (order 4 dithering matrix). - -October 31, 2006 - 1.9 -* [Carsten Klein] adjusted page numbers of the API documentation in header comments in FreeImage function declarations to match FreeImage 3.9.2 API documentation -! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 2 to match current version 3.9.2 -+ [Carsten Klein] added function declaration for FreeImage_JPEGCrop(): added both declaration and Boolean returning wrapper function. -! [Carsten Klein] changed data type of all occurences of parameter 'Flags' from Long to either FREE_IMAGE_LOAD_OPTIONS or FREE_IMAGE_SAVE_OPTIONS enum. This is true for declared funcitons as well as for wrapper functions. -+ [Carsten Klein] added function declaration for FreeImage_LoadMultiBitmapFromMemory(). -+ [Carsten Klein] added wrapper function FreeImage_LoadMultiBitmapFromMemoryEx(): this is dealing with a VB style array (SAFEARRAY) like FreeImage_LoadFromMemoryEx() does. - -! now FreeImage version 3.9.2 - -October 30, 2006 - 1.8 -* [Carsten Klein] fixed a memory leak in wrapper function SavePictureEx(). Thanks to Roogames for reporting that bug. -! [Carsten Klein] changed return type of wrapper function SavePictureEx() to Boolean. -+ [Carsten Klein] added wrapper function FreeImage_SaveEx() which brings all the features, as there are inline size- and color conversion and format guessing, so far only known from SavePictureEx() for DIBs. -! [Carsten Klein] changed wrapper function SavePictureEx(): now this is only a thin wrapper for function FreeImage_SaveEx(). -+ [Carsten Klein] added enumeration FREE_IMAGE_LOAD_OPTIONS. -- [Carsten Klein] refactored enumeration FREE_IMAGE_SAVE_OPTIONS: removed unnecessary items from enumeration. -! [Carsten Klein] changed wrapper function LoadPictureEx(): added parameter 'Options' (enum FREE_IMAGE_LOAD_OPTIONS) to specify image loading options (called 'flags' in FreeImage). -+ [Carsten Klein] added wrapper function FreeImage_LoadEx() which brings all the features, as there are inline size- and color conversion and format guessing, so far only known from LoadPictureEx() for DIBs. -! [Carsten Klein] changed wrapper function LoadPictureEx(): now this is only a thin wrapper for function FreeImage_LoadEx(). - -October 13, 2006 - 1.7.2 -+ [Carsten Klein] added User32 function GetDesktopWindow() -+ added User32 function GetWindowDC() -- [Carsten Klein] removed unused constants DI_MASK, DI_IMAGE and DI_NORMAL -+ added GDI32 function GetDeviceCaps() with constants HORZRES and VERTRES -+ added GDI32 function SelectObject() -+ added GDI32 function DeleteObject() -+ added GDI32 function CreateCompatibleBitmap() -+ added GDI32 function CreateCompatibleDC() -+ added GDI32 function BitBlt() -+ [Carsten Klein] added wrapper function FreeImage_CreateFromScreen(): this function lets you capture the whole screen or any certain window - -October 10, 2006 - 1.7.1 -! [Carsten Klein] changed parameter name 'Page' into 'hPageDib' in declared function FreeImage_UnlockPage(). 'hPageDib' must be the (dib-)handle obtained from FreeImage_LockPage() and not the page number. Now, the declaration is less confusing. Thanks to Ender Wiggin. - -August 4, 2006 - 1.7 -* [Carsten Klein] fixed a bug in pGetTagFromTagPtr(): removed overflow error when converting unsigned short tags (FIDT_SHORT) with values between 32768 and 65535. Thanks to André Hendriks. -! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 1 to match current version 3.9.1 - -! now FreeImage version 3.9.1 - -July 17, 2006 - 1.6 -+ [Carsten Klein] added more public wrapper functions for tag copying and cloning: -+ added function FreeImage_CopyMetadata() -+ added function FreeImage_CloneMetadata() -- [Carsten Klein] removed dead API functions, dead structures and dead variables -* [Carsten Klein] fixed a bug in FreeImage_ConvertColorDepth(): now color images are converted to 24 bits when used with FICF_PREPARE_RESCALE, all others to 8 bit - -July 16, 2006 - 1.5.6 -+ [Carsten Klein] added more public wrapper functions for VB friendly tag access: these functions deal with a FREE_IMAGE_TAG structure instead of FreeImage's Tag pointer. -+ added function FreeImage_SetMetadataEx() -+ added function FreeImage_CreateTagEx() -+ added function FreeImage_AppendTag() -+ added function FreeImage_RemoveTag() -+ added function FreeImage_RemoveTagEx() -+ added function FreeImage_TagExists() -+ added function FreeImage_TagExistsEx() -+ added function FreeImage_DeleteTagEx() -+ added function FreeImage_CloneTagEx() -+ added function FreeImage_RemoveMetadataModel() -+ added function FreeImage_UpdateMetadata() -+ added function FreeImage_UnsignedLong() -+ added function FreeImage_UnsignedShort() -+ added function FreeImage_CreateRational() -+ added function FreeImage_CreateSignedRational() -+ added function FreeImage_GetImageComment() -+ added function FreeImage_SetImageComment() -+ [Carsten Klein] added some private helper functions to leverage tag updating: -+ added helper function pTagToTagPtr() -+ added helper function pGetValueBuffer() -+ added helper function pGetRationalValueBuffer() -+ added helper function pGetVariantAsByteBuffer() -+ added helper function pGetElementSize() - -July 5, 2006 - 1.5.5 -! [Carsten Klein] changed function signature of FreeImage_FindNextMetadataEx(): optional parameter 'Model' is now present; see the function's inline documentation - -June 30, 2006 - 1.5.4 -* [Carsten Klein] fixed bug in functions creating a FreeImage DIB from a windows hBitmap: workaround for palettized bitmaps is now implemented -* fixed function FreeImage_CreateFromOLEPicture() -* fixed function FreeImage_CreateFromDC() - -June 22, 2006 - 1.5.3 -! [Carsten Klein] changed function declaration of FreeImage_GetMetadataInt(): parameter 'model' is now 'ByVal' and Tag is a Long pointer -! [Carsten Klein] changed function declaration of FreeImage_SetMetadataInt(): parameter 'model' is now 'ByVal' and Tag is a Long pointer -! [Carsten Klein] changed function declaration of FreeImage_GetMetadata(): parameter Tag is a Long pointer now -! [Carsten Klein] changed function declaration of FreeImage_SetMetadata(): parameter Tag is a Long pointer now -+ [Carsten Klein] added function declarations for tag creation and destruction: -+ added declaration for function FreeImage_CreateTag() -+ added declaration for procedure FreeImage_DeleteTag() -+ added declaration for function FreeImage_CloneTag() -+ [Carsten Klein] added new items to structure FREE_IMAGE_TAG: -+ added item 'Model As FREE_IMAGE_MDMODEL' -+ added item 'TagPtr As Long' -+ [Carsten Klein] added wrapper functions for more VB friendly Tag access: these functions deal with a FREE_IMAGE_TAG structure instead of FreeImage's Tag pointer. -+ added function FreeImage_FindFirstMetadataEx() -+ added function FreeImage_FindNextMetadataEx() -+ added function FreeImage_GetAllMetadataTags() -+ added function FreeImage_GetMetadataEx() -* [Carsten Klein] fixed and adjusted page numbers of the API documentation in header comments in FreeImage function declarations -- [Carsten Klein] removed workaround for thresholding and dithering non-MINISBLACK 8 bit images in function FreeImage_ConvertColorDepth(): was fixed in FreeImage 3.9.0 -* [Carsten Klein] fixed all pending issues in function FreeImage_PaintDC(): is now in production state - -June 14, 2006 - 1.5.2 -! [Carsten Klein] changed signature of function FreeImage_CreateMask() -+ [Carsten Klein] added function FreeImage_CreateMaskImage(): this creates a monochrome mask from a source image -+ [Carsten Klein] added function FreeImage_CreateMaskInPlace(): this creates a monochrome mask from a source image -+ [Carsten Klein] added enumeration FREE_IMAGE_ICON_TRANSPARENCY_OPTION_FLAGS -+ [Carsten Klein] added wrapper function FreeImage_CreateSimpleBWMaskImage(): wrapper for FreeImage_CreateMaskImage() with reduced number of parameters; creates a b/w mask -+ [Carsten Klein] added wrapper function FreeImage_CreateSimpleBWMaskInPlace(): wrapper for FreeImage_CreateMaskInPlace() with reduced number of parameters; creates a b/w mask -+ [Carsten Klein] added function declaration for FreeImage_MakeThumbnail() -+ [Carsten Klein] added function for FreeImage_GetOlePictureThumbnail() -+ [Carsten Klein] added function for FreeImage_MakeThumbnailIOP() -+ [Carsten Klein] documented function FreeImage_ReadMemoryEx() -+ [Carsten Klein] documented function FreeImage_WriteMemoryEx() -! [Carsten Klein] divided FreeImage_TagFromPointer into an interface only function with a private helper function pGetTagFromTagPtr(): -+ added helper function pGetTagFromTagPtr() -! [Carsten Klein] added private helper functions to leverage the FIDT_RATIONAL and FIDT_SRATIONAL data type: -+ added helper function pNormalizeRational() -+ added helper function pNormalizeSRational() -+ added helper function gcd() -+ added helper function floor() -! [Carsten Klein] changed name of structure 'FITAG_int' to 'FITAG': is now as in FreeImage library -! [Carsten Klein] changed name of structure 'FITAG' to 'FREE_IMAGE_TAG': this new structure plays an important role in the wrapper's new VB friendly tag accessing concept -! [Carsten Klein] changed function declaration of FreeImage_GetMetadataCount(): parameter 'model' is now 'ByVal' -! [Carsten Klein] changed function declaration of FreeImage_TagToString(): parameter 'model' is now 'ByVal' and function returns a Long -! [Carsten Klein] renamed function declaration of FreeImage_TagToString() to FreeImage_TagToStringInt(): function is now Private and wrapped by a VB String returning function -+ [Carsten Klein] added wrapper function FreeImage_TagToString() returning a real VB String -+ [Carsten Klein] added structure FIRATIONAL: structure to hold an image tag's rational value -+ [Carsten Klein] added new items to structure FREE_IMAGE_TAG: -+ added item 'StringValue As String' -+ added item 'Palette() As RGBQUAD' -+ added item 'RationalValue() As FIRATIONAL' - -June 13, 2006 - 1.5.1 -! [Carsten Klein] changed version constant 'FREEIMAGE_MINOR_VERSION' to 9 to meet version 3.9.0 -* [Carsten Klein] fixed and adjusted page numbers of the API documentation in header comments in FreeImage function declarations to match FreeImage 3.9.0 API documentation -+ [Carsten Klein] added function declaration for new Memory I/O functions in 3.9.0 -+ added declaration FreeImage_ReadMemory() -+ added declaration FreeImage_WriteMemory() -! [Carsten Klein] changed/added optional parameter 'element_size' to private function pGetMemoryBlockPtrFromVariant(): caller now can get size in bytes one array element -+ [Carsten Klein] added wrapper functions for new Memory I/O functions in 3.9.0 -+ added function FreeImage_ReadMemoryEx() -+ added function FreeImage_WriteMemoryEx() -+ [Carsten Klein] added constants and updated enumerations for new 3.9.0 file formats 'FAXG3' and 'SGI' -+ [Carsten Klein] added Windows GDI icon related declarations: -+ added function declaration for CreateIconIndirect() -+ added function declaration for DestroyIcon() -+ added structure ICONINFO -+ [Carsten Klein] added function FreeImage_GetIcon(): returns a hIcon handle -+ [Carsten Klein] added function FreeImage_GetOlePictureIcon(): returns a VB Picture object of type vbPicTypeIcon -+ [Carsten Klein] added enumeration FREE_IMAGE_MASK_FLAGS -+ [Carsten Klein] added function FreeImage_CreateMaskColors(): returns an array filled with items from an argument list; synonym for VB's Array() function -+ [Carsten Klein] added enumeration FREE_IMAGE_teMask(): this creates a monochrome mask from a source image -+ [Carsten Klein] added function FreeImage_CreaMASK_CREATION_OPTION_FLAGS - -! now FreeImage version 3.9.0 - -June 12, 2006 - 1.5 -* [Carsten Klein] fixed bug in wrapper function FreeImage_PaintDCEx(): now handles boolean test correctly: 'If ((hDC <> 0) And (hDIB <> 0)) Then -> Thanks to ender_wiggin for reporting that bug. -+ [Carsten Klein] added private function pGetIOlePictureFromContainer(): used to get IPicture from image hosting control (Form, PictureBox) including custom drawings -+ [Carsten Klein] added wrapper function FreeImage_CreateFromImageContainer(): used to create FreeImage DIB from image hosting control (Form, PictureBox) including custom drawings -+ [Carsten Klein] added wrapper function SaveImageContainerEx(): derivate of wrapper function 'SavePictureEx()': saves content of image hosting control (Form, PictureBox) including custom drawings - -February 27, 2006 - 1.4.8 -+ [Carsten Klein] added inline documentation for these wrapper functions: -+ documented function FreeImage_CompareColorsLongLong() -+ documented function FreeImage_CompareColorsRGBTRIPLELong() -+ documented function FreeImage_CompareColorsRGBQUADLong() -+ documented function FreeImage_SearchPalette() -! [Carsten Klein] changed and updated general remarks in section "General notes on implementation and design" -! [Carsten Klein] changed all function declarations of FreeImage functions that return a BOOL in C/C++: see "Functions returning Booleans" in section "General notes on implementation and design" -! [Carsten Klein] changed all function signatures of functions that are derived from or extend FreeImage BOOL functions: see "Functions returning Booleans" in section "General notes on implementation and design" -+ [Carsten Klein] added wrapper functions for all FreeImage functions that return a BOOL in C/C++: see "Functions returning Booleans" in section "General notes on implementation and design" -+ [Carsten Klein] added wrapper function FreeImage_CreateFromDC(): creates an DIB from a DC. Thanks to Evan (wxforecaster) for this suggestion. -+ [Carsten Klein] added declaration of GDI function GetCurrentObject() and constant OBJ_BITMAP -+ [Carsten Klein] added wrapper function FreeImage_IsAvailable(): used to test for existence of FreeImage Library (FreeImage.dll) - -February 9, 2006 - 1.4.7 -+ [Carsten Klein] added private helper function pGetPreviousColorDepth() -+ [Carsten Klein] added private helper function pGetNextColorDepth() -! [Carsten Klein] changed/extended signature of wrapper function SavePictureEx(): now includes a parameter 'ColorDepth' -+ [Carsten Klein] added enumeration FREE_IMAGE_COLOR_DEPTH -+ [Carsten Klein] added error handling capabilities to wrapper function SavePictureEx() -+ [Carsten Klein] added/updated inline documentation of wrapper function SavePictureEx() - -October 31, 2005 - 1.4.6 -+ [Carsten Klein] added wrapper function FreeImage_SwapColorLong(): this converts from a RGB to a BGR color value stored in a Long and vice versa - -October 27, 2005 - 1.4.5 -+ [Carsten Klein] added function FreeImage_IsTransparencyTableTransparent(): checks for transparency directly on the transparency table - -October 13, 2005 - 1.4.4 -+ [Carsten Klein] added some functions to compare colors in different formats and with tolerance: -+ added function FreeImage_CompareColorsLongLong() -+ added function FreeImage_CompareColorsRGBTRIPLELong() -+ added function FreeImage_CompareColorsRGBQUADLong() -+ [Carsten Klein] added enumeration FREE_IMAGE_COLOR_FORMAT_FLAGS -+ [Carsten Klein] added enumeration FREE_IMAGE_TRANSPARENCY_STATE_FLAGS -+ [Carsten Klein] added function FreeImage_SearchPalette(): to search the palette index for a given color - -October 13, 2005 - 1.4.3 -+ [Carsten Klein] added additional function declaration FreeImage_SetPixelColorByLong(): now color values may be provided in a long value -+ [Carsten Klein] added additional function declaration FreeImage_GetPixelColorByLong(): now color values may be received in a long value -+ [Carsten Klein] added function FreeImage_SetPixelColorEx(): color values may be provided by four different byte values -+ [Carsten Klein] added function FreeImage_GetPixelColorEx(): color values are returned through four different byte values - -October 11, 2005 - 1.4.2 -* [Carsten Klein] fixed bug in wrapper function FreeImage_GetBitsExRGBQUAD(): now tests for and works with 32 bit images - -October 10, 2005 - 1.4.1 -* [Carsten Klein] fixed serious bug in FreeImage_GetBitsEx...() functions: created custom array descriptor now really has two dimensions -* fixed wrapper function FreeImage_GetBitsEx() -* fixed wrapper function FreeImage_GetBitsExRGBTRIPLE() -* fixed wrapper function FreeImage_GetBitsExRGBQUAD() - -September 9, 2005 - 1.4 -! [Carsten Klein] changed wrapper function FreeImage_ConvertColorDepth(): now uses FreeImage_ConvertToGreyscale -+ [Carsten Klein] added version numbers to change log -+ [Carsten Klein] added comments to IOlePicture aware toolkit and conversion functions -* [Carsten Klein] fixed and adjusted page numbers of the API documentation in header comments in FreeImage function declarations - -! now FreeImage version 3.8.0 - -September 8, 2005 - 1.3.5 -! [Carsten Klein] changed version constant 'FREEIMAGE_MINOR_VERSION' to 8 to meet version 3.8.0 -+ [Carsten Klein] added function declarations for UNICODE dealing functions with additional token 'Int' appended: -+ added function FreeImage_LoadUInt() -+ added function FreeImage_SaveUInt() -+ added function FreeImage_GetFileTypeUInt() -+ added function FreeImage_GetFIFFromFilenameUInt() -+ [Carsten Klein] added wrapper functions to ease the use of UNICODE dealing functions: -+ added function FreeImage_LoadU() -+ added function FreeImage_SaveU() -+ added function FreeImage_GetFileTypeU() -+ added function FreeImage_GetFIFFromFilenameU() -+ [Carsten Klein] added function declaration for FreeImage_ConvertToGreyscale() - -July 18, 2005 - 1.3.4 -! [Carsten Klein] changed inline comments in these wrapper functions: -! changed FreeImage_GetBitsEx(): mixed up width and height in SAFEAARAY creation -! changed FreeImage_GetBitsExRGBTRIPLE(): mixed up width and height in SAFEAARAY creation -! changed FreeImage_GetBitsExRGBQUAD(): mixed up width and height in SAFEAARAY creation -+ [Carsten Klein] added wrapper function FreeImage_GetScanLinesRGBTRIPLE(): - -June 30, 2005 - 1.3.3 -+ [Carsten Klein] added Kernel32 function FillMemory() - -June 24, 2005 - 1.3.2 -+ [Carsten Klein] added pixel access functions FreeImage_GetBitsExRGBTRIPLE() and FreeImage_GetBitsExRGBQUAD() -+ [Carsten Klein] added IOlePicture based wrapper function FreeImage_ConvertColorDepthIOP() -+ [Carsten Klein] added IOlePicture based wrapper functions for FreeImage_RescaleIOP(): -+ added function FreeImage_FreeImage_RescaleByPixelIOP() -+ added function FreeImage_FreeImage_RescaleByPercentIOP() -+ added function FreeImage_FreeImage_RescaleByFactorIOP() -+ [Carsten Klein] added IOlePicture based wrapper function FreeImage_RescaleIOP() -* [Carsten Klein] fixed a bug in FreeImage_GetOlePicture(): now OlePictures returned through IPicture may be used directly by other functions accepting IPicture types without any assignment to IPictureDisp - -June 24, 2005 - 1.3.1 -! [Carsten Klein] changed inproper function declaration of function FreeImage_AdjustCurve(): now parameter 'LUT' is passed ByVal -+ [Carsten Klein] added wrapper function FreeImage_AdjustCurveEx() -+ [Carsten Klein] added IOlePicture based wrapper functions for FreeImage toolkit functions: -+ added function FreeImage_RotateClassicIOP() -+ added function FreeImage_RotateExIOP() -+ added function FreeImage_FlipHorizontalIOP() -+ added function FreeImage_FlipVerticalIOP() -+ added function FreeImage_AdjustCurveIOP() -+ added function FreeImage_AdjustGammaIOP() -+ added function FreeImage_AdjustBrightnessIOP() -+ added function FreeImage_AdjustContrastIOP() -+ added function FreeImage_InvertIOP() -+ added function FreeImage_GetChannelIOP() -+ added function FreeImage_CopyIOP() -+ added function FreeImage_PasteIOP() - -June 22, 2005 - 1.3 -+ [Carsten Klein] added inline comments and documentation for pixel access functions - -June 18, 2005 - 1.2.9 -+ [Carsten Klein] added function FreeImage_GetBitsEx() -+ [Carsten Klein] added structure SAFEARRAY2D to create 2 dimensional custom arrays -+ [Carsten Klein] added function declarations for converting scanlines to 4 bpp: -+ added declaration for FreeImage_ConvertLine1To4() -+ added declaration for FreeImage_ConvertLine8To4() -+ added declaration for FreeImage_ConvertLine16To4_555() -+ added declaration for FreeImage_ConvertLine16To4_565() -+ added declaration for FreeImage_ConvertLine24To4() -+ added declaration for FreeImage_ConvertLine32To4() - -June 16, 2005 - 1.2.8 -! [Carsten Klein] changed inproper function declaration for all functions FreeImage_ConvertLineXXXX(): now parameters 'target' and 'Source' are passed ByVal - -June 15, 2005 - 1.2.7 -+ [Carsten Klein] added function FreeImage_DestroyLockedArrayByPtr() to destroy a locked array by it's pointer (VB can't pass a array of structures through a Variant type) -+ [Carsten Klein] added some wrapper functions for FreeImage_DestroyLockedArrayByPtr() for common FreeImage structures: -+ added function FreeImage_DestroyLockedArrayRGBTRIPLE() -+ added function FreeImage_DestroyLockedArrayRGBQUAD() -+ added function FreeImage_DestroyLockedArrayFICOMPLEX() -+ added function FreeImage_DestroyLockedArrayFIRGB16() -+ added function FreeImage_DestroyLockedArrayFIRGBA16() -+ added function FreeImage_DestroyLockedArrayFIRGBF() -+ added function FreeImage_DestroyLockedArrayFIRGBAF() -+ [Carsten Klein] added functions to return scanlines as VB style arrays in all supported FreeImage formats: -+ added function FreeImage_GetScanLineBITMAP8() -+ added function FreeImage_GetScanLineBITMAP16() -+ added function FreeImage_GetScanLineBITMAP24() -+ added function FreeImage_GetScanLineBITMAP32() -+ added function FreeImage_GetScanLineINT16() -+ added function FreeImage_GetScanLineINT32() -+ added function FreeImage_GetScanLineFLOAT() -+ added function FreeImage_GetScanLineDOUBLE() -+ added function FreeImage_GetScanLineCOMPLEX() -+ added function FreeImage_GetScanLineRGB16() -+ added function FreeImage_GetScanLineRGBA16() -+ added function FreeImage_GetScanLineRGBF() -+ added function FreeImage_GetScanLineRGBAF() - -June 14, 2005 - 1.2.6 -! [Carsten Klein] updated documentation on array-dealing functions using arrays with custom array descriptors -+ [Carsten Klein] added function FreeImage_DestroyLockedArray() to destroy a self created array 'FADF_AUTO Or FADF_FIXEDSIZE' array -+ [Carsten Klein] added function FreeImage_GetPaletteExLong() to return palette data in an array of type Long -+ [Carsten Klein] added parameters 'lPaletteSize', 'vntReservePalette' and 'lReserveSize' to FreeImage_ConvertColorDepth() - -June 13, 2005 - 1.2.5 -* [Carsten Klein] fixed a bug in helper function pGetMemoryBlockPtrFromVariant(): now 'size_in_bytes' will never exceed the size of an array provided - -June 12, 2005 - 1.2.4 -+ [Carsten Klein] added ZLib compression function wrappers dealing with VB style arrays: -+ added function FreeImage_ZLibCompressVB() -+ added function FreeImage_ZLibUncompressVB() -+ added function FreeImage_ZLibGZipVB() -+ added function FreeImage_ZLibGUnzipVB() - -June 10, 2005 - 1.2.3 -+ [Carsten Klein] added ZLib compression function wrappers dealing with VB style arrays: -+ added function FreeImage_ZLibCompressEx() -+ added function FreeImage_ZLibUncompressEx() -+ added function FreeImage_ZLibGZipEx() -+ added function FreeImage_ZLibCRC32Ex() -+ added function FreeImage_ZLibGUnzipEx() -+ [Carsten Klein] added more VB friendly ZLib compression function wrappers: -+ added function FreeImage_ZLibCompressVB() -+ added function FreeImage_ZLibUncompressVB() -+ added function FreeImage_ZLibGZipVB() -+ added function FreeImage_ZLibGUnzipVB() -! [Carsten Klein] fixed wrong function declaration of functions FreeImage_ZLibGUnzip(): alias was '_FreeImage_ZLibZlibGUnzip@16' (double ZLib) -! [Carsten Klein] fixed function pGetArrayPtrFromVariantArray() that now can deal with uninitialized arrays -! fixed function pGetMemoryBlockPtrFromVariant() that now can deal with uninitialized arrays -! [Carsten Klein] fixed wrong function declaration of functions FreeImage_AdjustBrightness(): ...@8 -> ...@12 -! fixed wrong function declaration of functions FreeImage_AdjustContrast(): ...@8 -> ...@12 -! fixed wrong function declaration of functions FreeImage_AdjustGamma(): ...@8 -> ...@12 -! fixed wrong function declaration of functions FreeImage_RotateClassic(): ...@8 -> ...@12 -! fixed wrong function declaration of functions FreeImage_RotateEx(): ...@28 -> ...@48 - -June 9, 2005 - 1.2.2 -! [Carsten Klein] fixed wrong function declaration of function FreeImage_OpenMultiBitmap(): added parameter 'flags' (...@20 -> ...@24) - -June 8, 2005 - 1.2.1 -! [Carsten Klein] refactored function FreeImage_LoadFromMemoryEx(): now using pGetMemoryBlockPtrFromVariant() -+ [Carsten Klein] added private function pGetMemoryBlockPtrFromVariant() to get poiner and size of a memory block from a Variant parameter -! [Carsten Klein] changed declaration of ZLib related functions: 'target' and 'Source' are now 'ByVal Long' - -June 7, 2005 - 1.2 -+ [Carsten Klein] added some more inline comments and documentation -+ [Carsten Klein] added optional parameter 'bUnloadSource' to function FreeImage_SaveToMemoryEx() -+ added optional parameter 'bUnloadSource' to function FreeImage_SaveToMemoryEx2() -+ [Carsten Klein] added optional parameter 'InPercent' to function SavePictureEx() -! implemented the capability to resize the image on saving in function SavePictureEx() -+ [Carsten Klein] added parameters 'InPercent' and 'Format' to function LoadPictureEx() -* [Carsten Klein] fixed wrong function declaration of function FreeImage_JPEGTransform() (...@12 -> ...@16) - -June 6, 2005 - 1.1.2 -+ [Carsten Klein] added some more inline comments and documentation - -May 30, 2005 - 1.1.1 -* [Carsten Klein] fixed percent calculating bug in function FreeImage_RescaleEx() -! changed behaviour of parameter 'bIsPercentValue' -> it now has no effect on integer values -+ added function FreeImage_RescaleByPixel() to avoid confusion with overloading -+ added function FreeImage_RescaleByPercent() to avoid confusion with overloading -+ added function FreeImage_RescaleByFactor() to avoid confusion with overloading -! [Carsten Klein] changed name of parameter 'bUnloadDIB' to 'bUnloadSource' of function FreeImage_GetOlePicture() -+ [Carsten Klein] added some more inline comments and documentation -* [Carsten Klein] fixed a potential runtime error in function FreeImage_SetTransparencyTableEx(): 'Count' will no longer exceed 256 - -May 24, 2005 - 1.1 -+ [Carsten Klein] added a new VB wrapper +What's New for FreeImage VB Wrapper + +* : fixed +- : removed +! : changed ++ : added + +October 1, 2012 - 2.17 +- [Carsten Klein] removed temporary workaround for 16-bit standard type bitmaps introduced in version 2.15, which temporarily stored RGB masks directly after the BITMAPINFO structure, when creating a HBITMAP. +* [Carsten Klein] fixed a potential overflow bug in both pNormalizeRational and pNormalizeSRational: these now do nothing if any of numerator and denominator is either 1 or 0 (zero). ++ [Carsten Klein] added load flag JPEG_GREYSCALE as well as the enum constant FILO_JPEG_GREYSCALE. +! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL to 4 to match current version 3.15.4 + +March 19, 2012 - 2.16 +! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL to 3 to match current version 3.15.3 + +March 12, 2012 - 2.15 ++ [Carsten Klein] added function FreeImage_ConvertToUINT16. ++ [Carsten Klein] added function FreeImage_ConvertToRGB16. ++ [Carsten Klein] added function FreeImage_GetThumbnail. ++ [Carsten Klein] added function declaration FreeImage_SetThumbnailInt and a real VB Boolean returning function FreeImage_SetThumbnail. ++ [Carsten Klein] added RAW_HALFSIZE load flag as well as the enum constant FILO_RAW_HALFSIZE. ++ [Carsten Klein] added wrapper function FreeImage_GetPictureData, which returns a byte array suitable for assigning to an Office image control's PictureData property. ++ [Carsten Klein] added wrapper function FreeImage_CreateFromPictureData, which creates a FreeImage bitmap from a PictureData byte array. ++ [Carsten Klein] added new save flag JPEG_BASELINE (also added FISO_JPEG_BASELINE to enumeration FREE_IMAGE_SAVE_OPTIONS). ++ [Carsten Klein] added a workaround for providing valid BITMAPINFO structures for non 555 16-bpp images to Windows API functions like CreateDIBSection, CreateDIBBitmap, StretchDIBits or SetDIBitsToDevice. +! [Carsten Klein] changed constants FREEIMAGE_MINOR_VERSION and FREEIMAGE_RELEASE_SERIAL: set to 15 and 2 respectively to match current version 3.15.2 + +March 13, 2011 - 2.14 +* [Glenn Thorpe] fixed a typo error with the call to FreeImage_HasPixels inside FreeImage_CreateMask. + +August 11, 2010 - 2.13 ++ [Carsten Klein] added PSD load flags PSD_CMYK and PSD_LAB as well as the enum constants FILO_PSD_CYMK and FILO_PSD_LAB. ++ [Carsten Klein] added TIFF_LOGLUV save flag as well as the enum constant FISO_TIFF_LOGLUV. + +July 20, 2010 - 2.12 ++ [Carsten Klein] added support for the new EXIF_RAW metadata model by adding enum constant FIMD_EXIF_RAW. ++ [Carsten Klein] added the new FIF_LOAD_NOPIXELS flag as well as the enum constant FILO_LOAD_NOPIXELS. ++ [Carsten Klein] added function declaration FreeImage_HasPixelsInt and a real VB Boolean returning function FreeImage_HasPixels. ++ [Carsten Klein] added function declaration FreeImage_FIFSupportsNoPixelsInt and a real VB Boolean returning function FreeImage_FIFSupportsNoPixels. + +June 20, 2010 - 2.11 ++ [Carsten Klein] added new save flag JPEG_OPTIMIZE (also added FISO_JPEG_OPTIMIZE to enumeration FREE_IMAGE_SAVE_OPTIONS). + +April 20, 2010 - 2.10 ++ [Carsten Klein] added new save flag TARGA_SAVE_RLE (also added FISO_TARGA_SAVE_RLE to enumeration FREE_IMAGE_SAVE_OPTIONS). +! [Carsten Klein] changed constants FREEIMAGE_MINOR_VERSION and FREEIMAGE_RELEASE_SERIAL: set to 14 and 0 respectively to match current version 3.14.0 ++ [Carsten Klein] added function FreeImage_ConvertToFloat. ++ [Carsten Klein] added function FreeImage_SaveMultiBitmapToMemory. ++ [Carsten Klein] added wrapper functions FreeImage_SaveMultiBitmapToMemoryEx and FreeImage_SaveMultiBitmapToMemoryEx2. ++ [Carsten Klein] added wrapper function FreeImage_OpenMultiBitmapEx, which only opens existing files, but has support for automatic image format detection. ++ [Carsten Klein] added wrapper function FreeImage_CreateMultiBitmapEx, which only creates new (empty) multi-page bitmaps with support for automatic image format detection. +* [Carsten Klein] fixed a bug in FreeImage_LoadEx: now uses the file specified for format detection rather than the filename extension. ++ [Carsten Klein] improved error messages in function FreeImage_LoadEx. +* [Carsten Klein] fixed a bug in FreeImage_AcquireMemoryEx: no more crashes when passing an uninitialized array. ++ [Carsten Klein] added thin wrapper functions, enabling proper handling of Boolean parameters: ++ added wrapper function FreeImage_OpenMultiBitmap ++ added wrapper function FreeImage_UnlockPage ++ added wrapper function FreeImage_RotateEx ++ added wrapper function FreeImage_MakeThumbnail ++ added wrapper function FreeImage_GetAdjustColorsLookupTable ++ added wrapper function FreeImage_ApplyColorMapping ++ added wrapper function FreeImage_SwapColors ++ added wrapper function FreeImage_SwapColorsByLong ++ added wrapper function FreeImage_ApplyIndexMapping ++ added wrapper function FreeImage_SetTransparent ++ added wrapper function FreeImage_ConvertFromRawBits ++ added wrapper function FreeImage_ConvertToRawBits ++ added wrapper function FreeImage_ConvertToStandardType ++ added wrapper function FreeImage_ConvertToType +! [Carsten Klein] changed the parameter names of most functions. +! [Carsten Klein] changed signature of functions FreeImage_ConvertFromRawBits and FreeImage_ConvertToRawBits: 'ByRef Bits As Long' is now 'ByVal BitsPtr As Long'. ++ [Carsten Klein] added wrapper functions FreeImage_ConvertFromRawBitsEx and FreeImage_ConvertToRawBitsEx. +* [Carsten Klein] fixed a bug in declaration of function FreeImage_TmoReinhard05Ex: parameters 'Adaption' and 'ColorCorrection' are now passed by value. +- [Carsten Klein] removed half-implemented function FreeImage_SetChannelEx. ++ [Carsten Klein] added wrapper function FreeImage_SetChannelIOP. +- [Carsten Klein] removed needless default values of optional parameters. +- [Carsten Klein] removed function declaration FreeImage_CompositeByLong: replaced by declaration FreeImage_Composite. +! [Carsten Klein] changed function declaration FreeImage_Composite: application back color is now passed as ByRef ... As Any and so takes both RGBQUAD and Long valus. ++ [Carsten Klein] added wrapper function FreeImage_UnloadEx, which additionally sets the ByRef-passed Bitmap handle to zero after unloading. ++ [Carsten Klein] added wrapper functions ConvertColor and ConvertOleColor to convert VB-style BGR colors into RGB color values. + +! now FreeImage version 3.14.0 + +February 9, 2010 - 2.9.1 +* [Carsten Klein] fixed a bug in FreeImage_GetBackgroundColorAsLong: parameter 'bkcolor' is now properly passed ByRef. + +February 9, 2010 - 2.9 +* [Carsten Klein] fixed a syntax typo + +February 8, 2010 - 2.8 +* [Mike Weir] fixed a bug in function FreeImage_ApplyColorMappingEx: now properly includes all specified mapping entries +* [Carsten Klein] fixed a bug in function FreeImage_ApplyIndexMappingEx: now properly includes all specified mapping entries +* [Mike Weir] fixed a bug in function FreeImage_RescaleEx: now also rescales the image, if either the new width or height matches the image's current size +* [WinAnd / Carsten Klein] fixed a bug in function FreeImage_GetTransparencyTableExClone: returns an uninitialized array if there is no transparency table +* [WinAnd / Carsten Klein] fixed a bug in function FreeImage_SearchPalette: no longer crashes if there is no transparency table + +December 21, 2009 - 2.7 +! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 1 to match current version 3.13.1 + +! now FreeImage version 3.13.1 + +December 18, 2009 - 2.6 +- [Carsten Klein] removed usage of constants vbPicTypeBitmap and vbPicTypeIcon: these are not available in VBA environments like Excel, Access or Outlook. + +September 08, 2009 - 2.5 +! [Carsten Klein] changed constant FREEIMAGE_MINOR_VERSION: set to 13 to match current version 3.13.0 ++ [Carsten Klein] added load flag constant JPEG_EXIFROTATE and new member FILO_JPEG_EXIFROTATE to enumeration FREE_IMAGE_LOAD_OPTIONS. ++ [Carsten Klein] added support for the PFM image format. ++ [Carsten Klein] added support for the PICT and RAW image formats. ++ [Carsten Klein] added UNICODE functions FreeImage_JPEGTransformU and FreeImage_JPEGCropU. ++ [Carsten Klein] added enumeration FREE_IMAGE_COLOR_OPTIONS, which contains options to specify colors, used with FreeImage_FillBackground and FreeImage_EnlargeCanvas. ++ [Carsten Klein] added function FreeImage_FillBackground: although this returns BOOL in C/C++, the VB version only returns a Long. ++ [Carsten Klein] added wrapper functions FreeImage_FillBackgroundEx and FreeImage_FillBackgroundByLong, taking an RGBQUAD and a Long 'Color' argument respectively and return a true VB Boolean. ++ [Carsten Klein] added function FreeImage_EnlargeCanvas. ++ [Carsten Klein] added functions FreeImage_AllocateEx and FreeImage_AllocateExT. ++ [Carsten Klein] added function FreeImage_TmoReinhard05Ex. ++ [Carsten Klein] added function FreeImage_Rotate. ++ [Carsten Klein] added wrapper function FreeImage_RotateIOP. + +! now FreeImage version 3.13.0 + +March 18, 2009 - 2.4.2 ++ [Carsten Klein] added enumeration FREE_IMAGE_FRAME_DISPOSAL_METHODS, which provides the frame disposal options needed to create animated GIF files. + +July 29, 2008 - 2.4.1 +* [Carsten Klein] minor documentation updates +! [Carsten Klein] renamed member FICF_PALETTISED_8BPP of enumeration FREE_IMAGE_CONVERSION_FLAGS into FICF_PALLETISED_8BPP. + +June 30, 2008 - 2.4 +* [Carsten Klein] fixed some minor issues in FreeImage_PaintTransparent() + +June 06, 2008 - 2.3 ++ [Carsten Klein] added new compression flags to the JPEG and PNG plugins +! [Carsten Klein] renamed wrapper function FreeImage_CloneMetadata() to FreeImage_CloneMetadataEx(): now, there is a native function called FreeImage_CloneMetadata(). ++ [Carsten Klein] added private and internal function declaration for FreeImage_CloneMetadata() along with it's public Boolean returning wrapper function. +- [Carsten Klein] removed the FreeImage_ColorQuantizeEx() stuff from both functions FreeImage_ConvertColorDepth() and FreeImage_ConvertColorDepthIOP(): removed parameters PaletteSize, ReserveSize and ReservePalette. +- [Carsten Klein] changed declaration of FreeImage_ColorQuantizeEx() to be a internal function private to the wrapper with an 'Int' appendix. ++ [Carsten Klein] added two more VB-friendly public wrapper functions FreeImage_ColorQuantizeEx() and FreeImage_ColorQuantizeExIOP(). ++ [Carsten Klein] added wrapper function FreeImage_GetPalettePtr(): gets the pointer to a specified array of RGBQUADs: intended to be used together with any of the ColorQuantizeEx functions. +! [Carsten Klein] changed constant FREEIMAGE_MINOR_VERSION: set to 11 to match current version 3.11.0 + +! now FreeImage version 3.11.0 + +December 14, 2007 - 2.2.1 ++ [Carsten Klein] added constants for member 'biCompression' in BITMAPINFOHEADER struct ++ [Carsten Klein] added wrapper function FreeImage_GetInfoHeaderEx(), which returns a fully populated BITMAPINFOHEADER struct for a bitmap. +* [Carsten Klein] fixed a bug in FreeImage_GetFileTypeFromMemoryEx(): now calls FreeImage_CloseMemory() releasing the hStream to prevent memory leaks. ++ [Carsten Klein] added wrapper function FreeImage_GetColorizedPalette(): returns a colorized greyscale palettte. ++ [Carsten Klein] added wrapper function FreeImage_Colorize(): applies a colorized greyscale palettte obtained from FreeImage_GetColorizedPalette() to a bitmap. ++ [Carsten Klein] added wrapper function FreeImage_Sepia(): calls FreeImage_Colorize() with proper parameters to apply a so called sepia palette to a bitmap. + +December 12, 2007 - 2.2 +* [Carsten Klein] Fixed a small bug in FreeImage_PaintTransparent, which now calls function FreeImage_ConvertTo32Bits instead of FreeImage_ConvertTo32Bits2. + +November 15, 2007 - 2.1 +* [Carsten Klein] adjusted page numbers of the API documentation in FreeImage function declarations to match FreeImage 3.10.0 API documentation +- [Carsten Klein] removed parameter 'bUnloadSource' from function FreeImage_GetOlePictureIcon(): an hIcon should not be destroyed if OleCreatePictureIndirect() is called with fOwn = True. +! [Carsten Klein] refactored FreeImage_GetOlePicture(): now relies on FreeImage_GetBitmap(). + +November 10, 2007 - 2.0.8 +! [Carsten Klein] changed declaration of FreeImage_SetOutputMessage(): now points transparently to the __stdcall version of this function in the library. ++ [Carsten Klein] added function declaraton for FreeImage_MultigridPoissonSolver(). ++ [Carsten Klein] added function declaraton for FreeImage_GetTransparentIndex() and FreeImage_SetTransparentIndex(). ++ [Carsten Klein] added private and internal function declaraton for FreeImage_AdjustColors() along with it's public Boolean returning wrapper function. ++ [Carsten Klein] added function declaraton for FreeImage_GetAdjustColorsLookupTable(). ++ [Carsten Klein] added wrapper function FreeImage_GetAdjustColorsLookupTableEx(): this takes a real VB style Byte array ton receive the lookup table created. ++ [Carsten Klein] added function declaraton for FreeImage_ApplyColorMapping(). ++ [Carsten Klein] added wrapper function FreeImage_ApplyColorMappingEx(): this takes a real VB style RGBQUAD array. ++ [Carsten Klein] added function declaratons for FreeImage_SwapColors() and FreeImage_SwapColorsByLong(). ++ [Carsten Klein] added function declaraton for FreeImage_ApplyIndexMapping(). ++ [Carsten Klein] added wrapper function FreeImage_ApplyIndexMappingEx(): this takes a real VB style Byte array. ++ [Carsten Klein] added function declaraton for FreeImage_SwapPaletteIndices(). + +November 05, 2007 - 2.0.7 ++ [Carsten Klein] added 4 bit color depth to both function pGetNextColorDepth() and pGetPrevousColorDepth() +- [Carsten Klein] removed member FICF_PREPARE_RESCALE from enumeration FREE_IMAGE_CONVERSION_FLAGS +- [Carsten Klein] removed all references to FICF_PREPARE_RESCALE: Converting color depth before rescaling an image is no longer performed by the wrapper. Since FreeImage now transparently converts color depth on rescaling, doing this in the wrapper is no longer needed. +! [Carsten Klein] refactored wrapper function FreeImage_ConvertColorDepth(): removed case FICF_PREPARE_RESCALE; is now more similar to C# wrapper's version of this function. +! [Carsten Klein] refactored wrapper function FreeImage_SaveEx(): removed case FICF_PREPARE_RESCALE; is now more similar to C# wrapper's version of this function. + +September 14, 2007 - 2.0.6 ++ [Carsten Klein] added function declaration and Boolean wrapper function for FreeImage_PreMultiplyWithAlpha(). + +July 26, 2007 - 2.0.5 ++ [Carsten Klein] added wrapper function FreeImage_GetBitmap(): returns an HBITMAP created by the CreateDIBSection() function and so has the same color depth as the original DIB. ++ [Carsten Klein] added wrapper function FreeImage_GetBitmapForDevice(): returns an HBITMAP created by the CreateDIBitmap() function and so has the same color depth as the specified reference DC or as the desktop, if the 'hDC' parameter was omitted. +- [Carsten Klein] removed function declaration for GetWindowDC(): this function is no longer used. +* [Carsten Klein] fixed a bug in wrapper function FreeImage_IsExtensionValidForFIF(): string comparison now includes a comma. +* [Carsten Klein] fixed a bug in wrapper function FreeImage_IsFilenameValidForFIF(): string comparison now includes a comma. + +July 25, 2007 - 2.0.4 +* [Carsten Klein] fixed a bug in function FreeImage_GetPaletteExClone(): now actually returns the palette as RGBQUAD array plus some other minor improvements ++ [Carsten Klein] added wrapper function FreeImage_GetPaletteExLongClone(): this function returns a VB style Byte array that is only wrapped around FreeImage's pointer to a DIB's transparency table. ++ [Carsten Klein] added wrapper function FreeImage_GetTransparencyTableEx(): this function returns a VB style Byte array that is only wrapped around FreeImage's pointer to a DIB's transparency table. +! [Carsten Klein] changed name of wrapper function FreeImage_GetTransparencyTableEx(): this function is now named FreeImage_GetTransparencyTableExClone(), since it actually returns a clone (deep copy) of an image's transparency table (compare with FreeImage_GetPaletteExClone()). ++ [Carsten Klein] added wrapper function FreeImage_SetPalette(): sets an image's palette through a VB style RGBQUAD array. ++ [Carsten Klein] added wrapper function FreeImage_SetPaletteLong(): sets an image's palette through a VB style Long array. ++ [Carsten Klein] added function declaration for CreateDIBsection() ++ [Carsten Klein] added function declaration for DeleteDC() +* [Carsten Klein] fixed a bug in wrapper function FreeImage_CreateFromScreen(): now the memory DC is deleted with the DeleteDC() function and no longer with the DeleteObject() function. + +July 05, 2007 - 2.0.3 ++ [Carsten Klein] added wrapper function FreeImage_GetFileTypeFromMemoryEx(): more VB friendly version of FreeImage_GetFileTypeFromMemory() which may take an array rather than a FIMEMORY stream. + +May 21, 2007 - 2.0.2 +! [Carsten Klein] changed constant FREEIMAGE_MINOR_VERSION: set to 10 to match current version 3.10.0 +! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 0 to match current version 3.10.0 ++ [Carsten Klein] added image format constants FIF_EXR, FIF_J2K and FIF_JP2 to enumeration FREE_IMAGE_FORMAT. ++ [Carsten Klein] added tone mapping operator constant FITMO_FATTAL02 to enumeration FREE_IMAGE_TMO. ++ [Carsten Klein] added save option constants J2K_DEFAULT and JP2_DEFAULT for JPEG2000 format. ++ [Carsten Klein] added save option constants EXR_DEFAULT, EXR_FLOAT, EXR_NONE, EXR_ZIP, EXR_PIZ, EXR_PXR24, EXR_B44 and EXR_LC for EXR format. ++ [Carsten Klein] added save option constants for EXR format to enumeration FREE_IMAGE_SAVE_OPTIONS. ++ [Carsten Klein] added declared function FreeImage_TmoFattal02(): adds support for Gradient domain high dynamic range compression (R. Fattal, 2002) + +! now FreeImage version 3.10.0 + +February 24, 2007 - 2.0.1 +* [Carsten Klein] fixed a bug in function FreeImage_CreateFromScreen(): now size of image created is according to window to be captured if parameter 'hwnd' <> 0. ++ [Carsten Klein] added parameter 'bClientAreaOnly' to function FreeImage_CreateFromScreen(). ++ [Carsten Klein] added blitting option 'CAPTUREBLT' when calling function BitBlt() in function FreeImage_CreateFromScreen(). +- [Carsten Klein] removed unused variable 'hDIB' from functions FreeImage_CreateFromScreen() and FreeImage_LoadEx(). Thanks to Bruce Rusk for pointing that out. + +February 16, 2007 - 2.0 +! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 3 to match current version 3.9.3 +! [Carsten Klein] changed JPEG load/save flag option values: changed constants and both enumerations FREE_IMAGE_LOAD_OPTIONS and FREE_IMAGE_SAVE_OPTIONS. ++ [Carsten Klein] added ICC Color Profile support: +! changed signature of declared function FreeImage_GetICCProfile(): is now declared 'Private' and suffixed with '...Int()'. ++ added wrapper function FreeImage_GetICCProfile(): is the public wrapper function for private function FreeImage_GetICCProfileInt(), returing a real FIICCPROFILE structure. ++ added constant FREE_IMAGE_ICC_COLOR_MODEL_MASK. ++ added enumeration FREE_IMAGE_ICC_COLOR_MODEL. ++ added wrapper function FreeImage_GetICCProfileColorModel(): returns the color profile's color model (FIICCPROFILE.flags member). ++ added wrapper function FreeImage_GetICCProfileSize(): returns the color profile data's size in bytes. ++ added wrapper function FreeImage_GetICCProfileDataPointer(): returns the pointer to the color profile data. ++ added wrapper function FreeImage_HasICCProfile(): returns whether a color profile is available for a dib or not. +! [Carsten Klein] changed behaviour of wrapper function FreeImage_RescaleEx() and all it's derived functions: no clone is returned if the actual and desired image size are the same. ++ [Carsten Klein] added parameter 'bForceCloneCreation' to wrapper function FreeImage_RescaleEx() and all it's derived functions. + +! now FreeImage version 3.9.3 + +January 09, 2007 - 1.9.4 +! [Carsten Klein] changed scope of declared function FreeImage_GetFileTypeUInt(): is now private according to all other '...Int' functions wrapped by a VB-friendly function. +! [Carsten Klein] changed scope of declared function FreeImage_GetFIFFromFilenameUInt(): is now private according to all other '...Int' functions wrapped by a VB-friendly function. +! [Carsten Klein] changed signature of declared functions FreeImage_GetBackgroundColorInt() and FreeImage_SetBackgroundColorInt(): now both have a 'ByRef bkcolor As RGBQUAD' parameter instead of 'ByVal bkcolor As Long'. ++ [Carsten Klein] added declared functions FreeImage_GetBackgroundColorAsLongInt(): this has a 'ByRef bkcolor As Long' parameter and provides the background color as a Long value. ++ [Carsten Klein] added declared functions FreeImage_SetBackgroundColorAsLongInt(): this has a 'ByRef bkcolor As Long' parameter and takes the background color as a Long value. +! [Carsten Klein] changed signature of wrapper functions FreeImage_GetBackgroundColor() and FreeImage_SetBackgroundColor(): now both have a 'ByRef bkcolor As RGBQUAD' parameter instead of 'ByVal bkcolor As Long'. ++ [Carsten Klein] added wrapper functions FreeImage_GetBackgroundColorAsLong() and FreeImage_SetBackgroundColorAsLong(): both have a 'ByRef bkcolor As Long' parameter and so offer getting and setting the background color through a Long value. ++ [Carsten Klein] added wrapper functions FreeImage_GetBackgroundColorEx() and FreeImage_SetBackgroundColorEx(): both both take 4 ByRef Byte parameters 'Alpha', 'Red', 'Green' and 'Blue', one for each color component. + +January 05, 2007 - 1.9.3 ++ [Carsten Klein] added wrapper function FreeImage_GetLockedPageNumbersEx(): this returns a real VB-style array of Longs containing the page numbers of all locked pages. + +January 02, 2007 - 1.9.2 +* [Carsten Klein] fixed a bug in inline description of function FreeImage_GetPaletteEx(): now tells to use function FreeImage_DestroyLockedArrayRGBQUAD() to free an array returned by this function. +* [Carsten Klein] fixed some minor bugs in inline documentation. +* [Carsten Klein] fixed a serious bug in function FreeImage_SaveEx(): parameter 'bUnloadSource' is now interpreted correctly under all circumstances. +* [Carsten Klein] fixed some minor issues in function FreeImage_SaveEx(). + +December 29, 2006 - 1.9.1 ++ [Carsten Klein] added enumeration item FID_BAYER16x16: now supports Bayer ordered dispersed dot dithering (order 4 dithering matrix). + +October 31, 2006 - 1.9 +* [Carsten Klein] adjusted page numbers of the API documentation in header comments in FreeImage function declarations to match FreeImage 3.9.2 API documentation +! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 2 to match current version 3.9.2 ++ [Carsten Klein] added function declaration for FreeImage_JPEGCrop(): added both declaration and Boolean returning wrapper function. +! [Carsten Klein] changed data type of all occurences of parameter 'Flags' from Long to either FREE_IMAGE_LOAD_OPTIONS or FREE_IMAGE_SAVE_OPTIONS enum. This is true for declared funcitons as well as for wrapper functions. ++ [Carsten Klein] added function declaration for FreeImage_LoadMultiBitmapFromMemory(). ++ [Carsten Klein] added wrapper function FreeImage_LoadMultiBitmapFromMemoryEx(): this is dealing with a VB style array (SAFEARRAY) like FreeImage_LoadFromMemoryEx() does. + +! now FreeImage version 3.9.2 + +October 30, 2006 - 1.8 +* [Carsten Klein] fixed a memory leak in wrapper function SavePictureEx(). Thanks to Roogames for reporting that bug. +! [Carsten Klein] changed return type of wrapper function SavePictureEx() to Boolean. ++ [Carsten Klein] added wrapper function FreeImage_SaveEx() which brings all the features, as there are inline size- and color conversion and format guessing, so far only known from SavePictureEx() for DIBs. +! [Carsten Klein] changed wrapper function SavePictureEx(): now this is only a thin wrapper for function FreeImage_SaveEx(). ++ [Carsten Klein] added enumeration FREE_IMAGE_LOAD_OPTIONS. +- [Carsten Klein] refactored enumeration FREE_IMAGE_SAVE_OPTIONS: removed unnecessary items from enumeration. +! [Carsten Klein] changed wrapper function LoadPictureEx(): added parameter 'Options' (enum FREE_IMAGE_LOAD_OPTIONS) to specify image loading options (called 'flags' in FreeImage). ++ [Carsten Klein] added wrapper function FreeImage_LoadEx() which brings all the features, as there are inline size- and color conversion and format guessing, so far only known from LoadPictureEx() for DIBs. +! [Carsten Klein] changed wrapper function LoadPictureEx(): now this is only a thin wrapper for function FreeImage_LoadEx(). + +October 13, 2006 - 1.7.2 ++ [Carsten Klein] added User32 function GetDesktopWindow() ++ added User32 function GetWindowDC() +- [Carsten Klein] removed unused constants DI_MASK, DI_IMAGE and DI_NORMAL ++ added GDI32 function GetDeviceCaps() with constants HORZRES and VERTRES ++ added GDI32 function SelectObject() ++ added GDI32 function DeleteObject() ++ added GDI32 function CreateCompatibleBitmap() ++ added GDI32 function CreateCompatibleDC() ++ added GDI32 function BitBlt() ++ [Carsten Klein] added wrapper function FreeImage_CreateFromScreen(): this function lets you capture the whole screen or any certain window + +October 10, 2006 - 1.7.1 +! [Carsten Klein] changed parameter name 'Page' into 'hPageDib' in declared function FreeImage_UnlockPage(). 'hPageDib' must be the (dib-)handle obtained from FreeImage_LockPage() and not the page number. Now, the declaration is less confusing. Thanks to Ender Wiggin. + +August 4, 2006 - 1.7 +* [Carsten Klein] fixed a bug in pGetTagFromTagPtr(): removed overflow error when converting unsigned short tags (FIDT_SHORT) with values between 32768 and 65535. Thanks to André Hendriks. +! [Carsten Klein] changed constant FREEIMAGE_RELEASE_SERIAL: set to 1 to match current version 3.9.1 + +! now FreeImage version 3.9.1 + +July 17, 2006 - 1.6 ++ [Carsten Klein] added more public wrapper functions for tag copying and cloning: ++ added function FreeImage_CopyMetadata() ++ added function FreeImage_CloneMetadata() +- [Carsten Klein] removed dead API functions, dead structures and dead variables +* [Carsten Klein] fixed a bug in FreeImage_ConvertColorDepth(): now color images are converted to 24 bits when used with FICF_PREPARE_RESCALE, all others to 8 bit + +July 16, 2006 - 1.5.6 ++ [Carsten Klein] added more public wrapper functions for VB friendly tag access: these functions deal with a FREE_IMAGE_TAG structure instead of FreeImage's Tag pointer. ++ added function FreeImage_SetMetadataEx() ++ added function FreeImage_CreateTagEx() ++ added function FreeImage_AppendTag() ++ added function FreeImage_RemoveTag() ++ added function FreeImage_RemoveTagEx() ++ added function FreeImage_TagExists() ++ added function FreeImage_TagExistsEx() ++ added function FreeImage_DeleteTagEx() ++ added function FreeImage_CloneTagEx() ++ added function FreeImage_RemoveMetadataModel() ++ added function FreeImage_UpdateMetadata() ++ added function FreeImage_UnsignedLong() ++ added function FreeImage_UnsignedShort() ++ added function FreeImage_CreateRational() ++ added function FreeImage_CreateSignedRational() ++ added function FreeImage_GetImageComment() ++ added function FreeImage_SetImageComment() ++ [Carsten Klein] added some private helper functions to leverage tag updating: ++ added helper function pTagToTagPtr() ++ added helper function pGetValueBuffer() ++ added helper function pGetRationalValueBuffer() ++ added helper function pGetVariantAsByteBuffer() ++ added helper function pGetElementSize() + +July 5, 2006 - 1.5.5 +! [Carsten Klein] changed function signature of FreeImage_FindNextMetadataEx(): optional parameter 'Model' is now present; see the function's inline documentation + +June 30, 2006 - 1.5.4 +* [Carsten Klein] fixed bug in functions creating a FreeImage DIB from a windows hBitmap: workaround for palettized bitmaps is now implemented +* fixed function FreeImage_CreateFromOLEPicture() +* fixed function FreeImage_CreateFromDC() + +June 22, 2006 - 1.5.3 +! [Carsten Klein] changed function declaration of FreeImage_GetMetadataInt(): parameter 'model' is now 'ByVal' and Tag is a Long pointer +! [Carsten Klein] changed function declaration of FreeImage_SetMetadataInt(): parameter 'model' is now 'ByVal' and Tag is a Long pointer +! [Carsten Klein] changed function declaration of FreeImage_GetMetadata(): parameter Tag is a Long pointer now +! [Carsten Klein] changed function declaration of FreeImage_SetMetadata(): parameter Tag is a Long pointer now ++ [Carsten Klein] added function declarations for tag creation and destruction: ++ added declaration for function FreeImage_CreateTag() ++ added declaration for procedure FreeImage_DeleteTag() ++ added declaration for function FreeImage_CloneTag() ++ [Carsten Klein] added new items to structure FREE_IMAGE_TAG: ++ added item 'Model As FREE_IMAGE_MDMODEL' ++ added item 'TagPtr As Long' ++ [Carsten Klein] added wrapper functions for more VB friendly Tag access: these functions deal with a FREE_IMAGE_TAG structure instead of FreeImage's Tag pointer. ++ added function FreeImage_FindFirstMetadataEx() ++ added function FreeImage_FindNextMetadataEx() ++ added function FreeImage_GetAllMetadataTags() ++ added function FreeImage_GetMetadataEx() +* [Carsten Klein] fixed and adjusted page numbers of the API documentation in header comments in FreeImage function declarations +- [Carsten Klein] removed workaround for thresholding and dithering non-MINISBLACK 8 bit images in function FreeImage_ConvertColorDepth(): was fixed in FreeImage 3.9.0 +* [Carsten Klein] fixed all pending issues in function FreeImage_PaintDC(): is now in production state + +June 14, 2006 - 1.5.2 +! [Carsten Klein] changed signature of function FreeImage_CreateMask() ++ [Carsten Klein] added function FreeImage_CreateMaskImage(): this creates a monochrome mask from a source image ++ [Carsten Klein] added function FreeImage_CreateMaskInPlace(): this creates a monochrome mask from a source image ++ [Carsten Klein] added enumeration FREE_IMAGE_ICON_TRANSPARENCY_OPTION_FLAGS ++ [Carsten Klein] added wrapper function FreeImage_CreateSimpleBWMaskImage(): wrapper for FreeImage_CreateMaskImage() with reduced number of parameters; creates a b/w mask ++ [Carsten Klein] added wrapper function FreeImage_CreateSimpleBWMaskInPlace(): wrapper for FreeImage_CreateMaskInPlace() with reduced number of parameters; creates a b/w mask ++ [Carsten Klein] added function declaration for FreeImage_MakeThumbnail() ++ [Carsten Klein] added function for FreeImage_GetOlePictureThumbnail() ++ [Carsten Klein] added function for FreeImage_MakeThumbnailIOP() ++ [Carsten Klein] documented function FreeImage_ReadMemoryEx() ++ [Carsten Klein] documented function FreeImage_WriteMemoryEx() +! [Carsten Klein] divided FreeImage_TagFromPointer into an interface only function with a private helper function pGetTagFromTagPtr(): ++ added helper function pGetTagFromTagPtr() +! [Carsten Klein] added private helper functions to leverage the FIDT_RATIONAL and FIDT_SRATIONAL data type: ++ added helper function pNormalizeRational() ++ added helper function pNormalizeSRational() ++ added helper function gcd() ++ added helper function floor() +! [Carsten Klein] changed name of structure 'FITAG_int' to 'FITAG': is now as in FreeImage library +! [Carsten Klein] changed name of structure 'FITAG' to 'FREE_IMAGE_TAG': this new structure plays an important role in the wrapper's new VB friendly tag accessing concept +! [Carsten Klein] changed function declaration of FreeImage_GetMetadataCount(): parameter 'model' is now 'ByVal' +! [Carsten Klein] changed function declaration of FreeImage_TagToString(): parameter 'model' is now 'ByVal' and function returns a Long +! [Carsten Klein] renamed function declaration of FreeImage_TagToString() to FreeImage_TagToStringInt(): function is now Private and wrapped by a VB String returning function ++ [Carsten Klein] added wrapper function FreeImage_TagToString() returning a real VB String ++ [Carsten Klein] added structure FIRATIONAL: structure to hold an image tag's rational value ++ [Carsten Klein] added new items to structure FREE_IMAGE_TAG: ++ added item 'StringValue As String' ++ added item 'Palette() As RGBQUAD' ++ added item 'RationalValue() As FIRATIONAL' + +June 13, 2006 - 1.5.1 +! [Carsten Klein] changed version constant 'FREEIMAGE_MINOR_VERSION' to 9 to meet version 3.9.0 +* [Carsten Klein] fixed and adjusted page numbers of the API documentation in header comments in FreeImage function declarations to match FreeImage 3.9.0 API documentation ++ [Carsten Klein] added function declaration for new Memory I/O functions in 3.9.0 ++ added declaration FreeImage_ReadMemory() ++ added declaration FreeImage_WriteMemory() +! [Carsten Klein] changed/added optional parameter 'element_size' to private function pGetMemoryBlockPtrFromVariant(): caller now can get size in bytes one array element ++ [Carsten Klein] added wrapper functions for new Memory I/O functions in 3.9.0 ++ added function FreeImage_ReadMemoryEx() ++ added function FreeImage_WriteMemoryEx() ++ [Carsten Klein] added constants and updated enumerations for new 3.9.0 file formats 'FAXG3' and 'SGI' ++ [Carsten Klein] added Windows GDI icon related declarations: ++ added function declaration for CreateIconIndirect() ++ added function declaration for DestroyIcon() ++ added structure ICONINFO ++ [Carsten Klein] added function FreeImage_GetIcon(): returns a hIcon handle ++ [Carsten Klein] added function FreeImage_GetOlePictureIcon(): returns a VB Picture object of type vbPicTypeIcon ++ [Carsten Klein] added enumeration FREE_IMAGE_MASK_FLAGS ++ [Carsten Klein] added function FreeImage_CreateMaskColors(): returns an array filled with items from an argument list; synonym for VB's Array() function ++ [Carsten Klein] added enumeration FREE_IMAGE_teMask(): this creates a monochrome mask from a source image ++ [Carsten Klein] added function FreeImage_CreaMASK_CREATION_OPTION_FLAGS + +! now FreeImage version 3.9.0 + +June 12, 2006 - 1.5 +* [Carsten Klein] fixed bug in wrapper function FreeImage_PaintDCEx(): now handles boolean test correctly: 'If ((hDC <> 0) And (hDIB <> 0)) Then -> Thanks to ender_wiggin for reporting that bug. ++ [Carsten Klein] added private function pGetIOlePictureFromContainer(): used to get IPicture from image hosting control (Form, PictureBox) including custom drawings ++ [Carsten Klein] added wrapper function FreeImage_CreateFromImageContainer(): used to create FreeImage DIB from image hosting control (Form, PictureBox) including custom drawings ++ [Carsten Klein] added wrapper function SaveImageContainerEx(): derivate of wrapper function 'SavePictureEx()': saves content of image hosting control (Form, PictureBox) including custom drawings + +February 27, 2006 - 1.4.8 ++ [Carsten Klein] added inline documentation for these wrapper functions: ++ documented function FreeImage_CompareColorsLongLong() ++ documented function FreeImage_CompareColorsRGBTRIPLELong() ++ documented function FreeImage_CompareColorsRGBQUADLong() ++ documented function FreeImage_SearchPalette() +! [Carsten Klein] changed and updated general remarks in section "General notes on implementation and design" +! [Carsten Klein] changed all function declarations of FreeImage functions that return a BOOL in C/C++: see "Functions returning Booleans" in section "General notes on implementation and design" +! [Carsten Klein] changed all function signatures of functions that are derived from or extend FreeImage BOOL functions: see "Functions returning Booleans" in section "General notes on implementation and design" ++ [Carsten Klein] added wrapper functions for all FreeImage functions that return a BOOL in C/C++: see "Functions returning Booleans" in section "General notes on implementation and design" ++ [Carsten Klein] added wrapper function FreeImage_CreateFromDC(): creates an DIB from a DC. Thanks to Evan (wxforecaster) for this suggestion. ++ [Carsten Klein] added declaration of GDI function GetCurrentObject() and constant OBJ_BITMAP ++ [Carsten Klein] added wrapper function FreeImage_IsAvailable(): used to test for existence of FreeImage Library (FreeImage.dll) + +February 9, 2006 - 1.4.7 ++ [Carsten Klein] added private helper function pGetPreviousColorDepth() ++ [Carsten Klein] added private helper function pGetNextColorDepth() +! [Carsten Klein] changed/extended signature of wrapper function SavePictureEx(): now includes a parameter 'ColorDepth' ++ [Carsten Klein] added enumeration FREE_IMAGE_COLOR_DEPTH ++ [Carsten Klein] added error handling capabilities to wrapper function SavePictureEx() ++ [Carsten Klein] added/updated inline documentation of wrapper function SavePictureEx() + +October 31, 2005 - 1.4.6 ++ [Carsten Klein] added wrapper function FreeImage_SwapColorLong(): this converts from a RGB to a BGR color value stored in a Long and vice versa + +October 27, 2005 - 1.4.5 ++ [Carsten Klein] added function FreeImage_IsTransparencyTableTransparent(): checks for transparency directly on the transparency table + +October 13, 2005 - 1.4.4 ++ [Carsten Klein] added some functions to compare colors in different formats and with tolerance: ++ added function FreeImage_CompareColorsLongLong() ++ added function FreeImage_CompareColorsRGBTRIPLELong() ++ added function FreeImage_CompareColorsRGBQUADLong() ++ [Carsten Klein] added enumeration FREE_IMAGE_COLOR_FORMAT_FLAGS ++ [Carsten Klein] added enumeration FREE_IMAGE_TRANSPARENCY_STATE_FLAGS ++ [Carsten Klein] added function FreeImage_SearchPalette(): to search the palette index for a given color + +October 13, 2005 - 1.4.3 ++ [Carsten Klein] added additional function declaration FreeImage_SetPixelColorByLong(): now color values may be provided in a long value ++ [Carsten Klein] added additional function declaration FreeImage_GetPixelColorByLong(): now color values may be received in a long value ++ [Carsten Klein] added function FreeImage_SetPixelColorEx(): color values may be provided by four different byte values ++ [Carsten Klein] added function FreeImage_GetPixelColorEx(): color values are returned through four different byte values + +October 11, 2005 - 1.4.2 +* [Carsten Klein] fixed bug in wrapper function FreeImage_GetBitsExRGBQUAD(): now tests for and works with 32 bit images + +October 10, 2005 - 1.4.1 +* [Carsten Klein] fixed serious bug in FreeImage_GetBitsEx...() functions: created custom array descriptor now really has two dimensions +* fixed wrapper function FreeImage_GetBitsEx() +* fixed wrapper function FreeImage_GetBitsExRGBTRIPLE() +* fixed wrapper function FreeImage_GetBitsExRGBQUAD() + +September 9, 2005 - 1.4 +! [Carsten Klein] changed wrapper function FreeImage_ConvertColorDepth(): now uses FreeImage_ConvertToGreyscale ++ [Carsten Klein] added version numbers to change log ++ [Carsten Klein] added comments to IOlePicture aware toolkit and conversion functions +* [Carsten Klein] fixed and adjusted page numbers of the API documentation in header comments in FreeImage function declarations + +! now FreeImage version 3.8.0 + +September 8, 2005 - 1.3.5 +! [Carsten Klein] changed version constant 'FREEIMAGE_MINOR_VERSION' to 8 to meet version 3.8.0 ++ [Carsten Klein] added function declarations for UNICODE dealing functions with additional token 'Int' appended: ++ added function FreeImage_LoadUInt() ++ added function FreeImage_SaveUInt() ++ added function FreeImage_GetFileTypeUInt() ++ added function FreeImage_GetFIFFromFilenameUInt() ++ [Carsten Klein] added wrapper functions to ease the use of UNICODE dealing functions: ++ added function FreeImage_LoadU() ++ added function FreeImage_SaveU() ++ added function FreeImage_GetFileTypeU() ++ added function FreeImage_GetFIFFromFilenameU() ++ [Carsten Klein] added function declaration for FreeImage_ConvertToGreyscale() + +July 18, 2005 - 1.3.4 +! [Carsten Klein] changed inline comments in these wrapper functions: +! changed FreeImage_GetBitsEx(): mixed up width and height in SAFEAARAY creation +! changed FreeImage_GetBitsExRGBTRIPLE(): mixed up width and height in SAFEAARAY creation +! changed FreeImage_GetBitsExRGBQUAD(): mixed up width and height in SAFEAARAY creation ++ [Carsten Klein] added wrapper function FreeImage_GetScanLinesRGBTRIPLE(): + +June 30, 2005 - 1.3.3 ++ [Carsten Klein] added Kernel32 function FillMemory() + +June 24, 2005 - 1.3.2 ++ [Carsten Klein] added pixel access functions FreeImage_GetBitsExRGBTRIPLE() and FreeImage_GetBitsExRGBQUAD() ++ [Carsten Klein] added IOlePicture based wrapper function FreeImage_ConvertColorDepthIOP() ++ [Carsten Klein] added IOlePicture based wrapper functions for FreeImage_RescaleIOP(): ++ added function FreeImage_FreeImage_RescaleByPixelIOP() ++ added function FreeImage_FreeImage_RescaleByPercentIOP() ++ added function FreeImage_FreeImage_RescaleByFactorIOP() ++ [Carsten Klein] added IOlePicture based wrapper function FreeImage_RescaleIOP() +* [Carsten Klein] fixed a bug in FreeImage_GetOlePicture(): now OlePictures returned through IPicture may be used directly by other functions accepting IPicture types without any assignment to IPictureDisp + +June 24, 2005 - 1.3.1 +! [Carsten Klein] changed inproper function declaration of function FreeImage_AdjustCurve(): now parameter 'LUT' is passed ByVal ++ [Carsten Klein] added wrapper function FreeImage_AdjustCurveEx() ++ [Carsten Klein] added IOlePicture based wrapper functions for FreeImage toolkit functions: ++ added function FreeImage_RotateClassicIOP() ++ added function FreeImage_RotateExIOP() ++ added function FreeImage_FlipHorizontalIOP() ++ added function FreeImage_FlipVerticalIOP() ++ added function FreeImage_AdjustCurveIOP() ++ added function FreeImage_AdjustGammaIOP() ++ added function FreeImage_AdjustBrightnessIOP() ++ added function FreeImage_AdjustContrastIOP() ++ added function FreeImage_InvertIOP() ++ added function FreeImage_GetChannelIOP() ++ added function FreeImage_CopyIOP() ++ added function FreeImage_PasteIOP() + +June 22, 2005 - 1.3 ++ [Carsten Klein] added inline comments and documentation for pixel access functions + +June 18, 2005 - 1.2.9 ++ [Carsten Klein] added function FreeImage_GetBitsEx() ++ [Carsten Klein] added structure SAFEARRAY2D to create 2 dimensional custom arrays ++ [Carsten Klein] added function declarations for converting scanlines to 4 bpp: ++ added declaration for FreeImage_ConvertLine1To4() ++ added declaration for FreeImage_ConvertLine8To4() ++ added declaration for FreeImage_ConvertLine16To4_555() ++ added declaration for FreeImage_ConvertLine16To4_565() ++ added declaration for FreeImage_ConvertLine24To4() ++ added declaration for FreeImage_ConvertLine32To4() + +June 16, 2005 - 1.2.8 +! [Carsten Klein] changed inproper function declaration for all functions FreeImage_ConvertLineXXXX(): now parameters 'target' and 'Source' are passed ByVal + +June 15, 2005 - 1.2.7 ++ [Carsten Klein] added function FreeImage_DestroyLockedArrayByPtr() to destroy a locked array by it's pointer (VB can't pass a array of structures through a Variant type) ++ [Carsten Klein] added some wrapper functions for FreeImage_DestroyLockedArrayByPtr() for common FreeImage structures: ++ added function FreeImage_DestroyLockedArrayRGBTRIPLE() ++ added function FreeImage_DestroyLockedArrayRGBQUAD() ++ added function FreeImage_DestroyLockedArrayFICOMPLEX() ++ added function FreeImage_DestroyLockedArrayFIRGB16() ++ added function FreeImage_DestroyLockedArrayFIRGBA16() ++ added function FreeImage_DestroyLockedArrayFIRGBF() ++ added function FreeImage_DestroyLockedArrayFIRGBAF() ++ [Carsten Klein] added functions to return scanlines as VB style arrays in all supported FreeImage formats: ++ added function FreeImage_GetScanLineBITMAP8() ++ added function FreeImage_GetScanLineBITMAP16() ++ added function FreeImage_GetScanLineBITMAP24() ++ added function FreeImage_GetScanLineBITMAP32() ++ added function FreeImage_GetScanLineINT16() ++ added function FreeImage_GetScanLineINT32() ++ added function FreeImage_GetScanLineFLOAT() ++ added function FreeImage_GetScanLineDOUBLE() ++ added function FreeImage_GetScanLineCOMPLEX() ++ added function FreeImage_GetScanLineRGB16() ++ added function FreeImage_GetScanLineRGBA16() ++ added function FreeImage_GetScanLineRGBF() ++ added function FreeImage_GetScanLineRGBAF() + +June 14, 2005 - 1.2.6 +! [Carsten Klein] updated documentation on array-dealing functions using arrays with custom array descriptors ++ [Carsten Klein] added function FreeImage_DestroyLockedArray() to destroy a self created array 'FADF_AUTO Or FADF_FIXEDSIZE' array ++ [Carsten Klein] added function FreeImage_GetPaletteExLong() to return palette data in an array of type Long ++ [Carsten Klein] added parameters 'lPaletteSize', 'vntReservePalette' and 'lReserveSize' to FreeImage_ConvertColorDepth() + +June 13, 2005 - 1.2.5 +* [Carsten Klein] fixed a bug in helper function pGetMemoryBlockPtrFromVariant(): now 'size_in_bytes' will never exceed the size of an array provided + +June 12, 2005 - 1.2.4 ++ [Carsten Klein] added ZLib compression function wrappers dealing with VB style arrays: ++ added function FreeImage_ZLibCompressVB() ++ added function FreeImage_ZLibUncompressVB() ++ added function FreeImage_ZLibGZipVB() ++ added function FreeImage_ZLibGUnzipVB() + +June 10, 2005 - 1.2.3 ++ [Carsten Klein] added ZLib compression function wrappers dealing with VB style arrays: ++ added function FreeImage_ZLibCompressEx() ++ added function FreeImage_ZLibUncompressEx() ++ added function FreeImage_ZLibGZipEx() ++ added function FreeImage_ZLibCRC32Ex() ++ added function FreeImage_ZLibGUnzipEx() ++ [Carsten Klein] added more VB friendly ZLib compression function wrappers: ++ added function FreeImage_ZLibCompressVB() ++ added function FreeImage_ZLibUncompressVB() ++ added function FreeImage_ZLibGZipVB() ++ added function FreeImage_ZLibGUnzipVB() +! [Carsten Klein] fixed wrong function declaration of functions FreeImage_ZLibGUnzip(): alias was '_FreeImage_ZLibZlibGUnzip@16' (double ZLib) +! [Carsten Klein] fixed function pGetArrayPtrFromVariantArray() that now can deal with uninitialized arrays +! fixed function pGetMemoryBlockPtrFromVariant() that now can deal with uninitialized arrays +! [Carsten Klein] fixed wrong function declaration of functions FreeImage_AdjustBrightness(): ...@8 -> ...@12 +! fixed wrong function declaration of functions FreeImage_AdjustContrast(): ...@8 -> ...@12 +! fixed wrong function declaration of functions FreeImage_AdjustGamma(): ...@8 -> ...@12 +! fixed wrong function declaration of functions FreeImage_RotateClassic(): ...@8 -> ...@12 +! fixed wrong function declaration of functions FreeImage_RotateEx(): ...@28 -> ...@48 + +June 9, 2005 - 1.2.2 +! [Carsten Klein] fixed wrong function declaration of function FreeImage_OpenMultiBitmap(): added parameter 'flags' (...@20 -> ...@24) + +June 8, 2005 - 1.2.1 +! [Carsten Klein] refactored function FreeImage_LoadFromMemoryEx(): now using pGetMemoryBlockPtrFromVariant() ++ [Carsten Klein] added private function pGetMemoryBlockPtrFromVariant() to get poiner and size of a memory block from a Variant parameter +! [Carsten Klein] changed declaration of ZLib related functions: 'target' and 'Source' are now 'ByVal Long' + +June 7, 2005 - 1.2 ++ [Carsten Klein] added some more inline comments and documentation ++ [Carsten Klein] added optional parameter 'bUnloadSource' to function FreeImage_SaveToMemoryEx() ++ added optional parameter 'bUnloadSource' to function FreeImage_SaveToMemoryEx2() ++ [Carsten Klein] added optional parameter 'InPercent' to function SavePictureEx() +! implemented the capability to resize the image on saving in function SavePictureEx() ++ [Carsten Klein] added parameters 'InPercent' and 'Format' to function LoadPictureEx() +* [Carsten Klein] fixed wrong function declaration of function FreeImage_JPEGTransform() (...@12 -> ...@16) + +June 6, 2005 - 1.1.2 ++ [Carsten Klein] added some more inline comments and documentation + +May 30, 2005 - 1.1.1 +* [Carsten Klein] fixed percent calculating bug in function FreeImage_RescaleEx() +! changed behaviour of parameter 'bIsPercentValue' -> it now has no effect on integer values ++ added function FreeImage_RescaleByPixel() to avoid confusion with overloading ++ added function FreeImage_RescaleByPercent() to avoid confusion with overloading ++ added function FreeImage_RescaleByFactor() to avoid confusion with overloading +! [Carsten Klein] changed name of parameter 'bUnloadDIB' to 'bUnloadSource' of function FreeImage_GetOlePicture() ++ [Carsten Klein] added some more inline comments and documentation +* [Carsten Klein] fixed a potential runtime error in function FreeImage_SetTransparencyTableEx(): 'Count' will no longer exceed 256 + +May 24, 2005 - 1.1 ++ [Carsten Klein] added a new VB wrapper diff --git a/clean.sh b/clean.sh index e707c6c..3371d0b 100644 --- a/clean.sh +++ b/clean.sh @@ -1,48 +1,48 @@ -#!/bin/sh -rm -rf Release -rm -rf Debug -rm -rf Source/FreeImageQt/Release -rm -rf Source/FreeImageQt/Debug -rm -rf Source/FreeImageLib/Debug -rm -rf Source/FreeImageLib/Release -rm -rf Source/Source/Release -rm -rf Source/Source/Debug -rm -rf Source/LibJPEG/Debug -rm -rf Source/LibJPEG/Release -rm -rf Source/LibPNG/Debug -rm -rf Source/LibPNG/Release -rm -rf Source/LibMNG/Debug -rm -rf Source/LibMNG/Release -rm -rf Source/LibTIFF/Debug -rm -rf Source/LibTIFF/Release -rm -rf Source/LibTIFF4/Debug -rm -rf Source/LibTIFF4/Release -rm -rf Source/Zlib/Debug -rm -rf Source/Zlib/Release -rm -rf Source/OpenEXR/Debug -rm -rf Source/OpenEXR/Release -rm -rf Source/LibOpenJPEG/Debug -rm -rf Source/LibOpenJPEG/Release -rm -rf Source/LibRawLite/Debug -rm -rf Source/LibRawLite/Release -rm -rf TestAPI/Debug -rm -rf TestAPI/Release -find . -name '*.pch' -exec rm -f {} ";" -find . -name '*.ncb' -exec rm -f {} ";" -find . -name '*.opt' -exec rm -f {} ";" -find . -name '*.plg' -exec rm -f {} ";" -find . -name '*.obj' -exec rm -f {} ";" -find . -name '*.dll' -exec rm -f {} ";" -find . -name '*.exe' -exec rm -f {} ";" -find . -name '*.bsc' -exec rm -f {} ";" -find . -name '*.bak' -exec rm -f {} ";" -find . -name '*.pdb' -exec rm -f {} ";" -find . -name '*.sql' -exec rm -f {} ";" -find . -name '*.mdb' -exec rm -f {} ";" -find . -name '*.lib' -exec rm -f {} ";" -find . -name '*.exp' -exec rm -f {} ";" -find . -name '*.ilk' -exec rm -f {} ";" -find . -name '*.idb' -exec rm -f {} ";" -find . -name '*.o' -exec rm -f {} ";" -find . -name '*.o-ppc' -exec rm -f {} ";" -find . -name '*.o-i386' -exec rm -f {} ";" +#!/bin/sh +rm -rf Release +rm -rf Debug +rm -rf Source/FreeImageQt/Release +rm -rf Source/FreeImageQt/Debug +rm -rf Source/FreeImageLib/Debug +rm -rf Source/FreeImageLib/Release +rm -rf Source/Source/Release +rm -rf Source/Source/Debug +rm -rf Source/LibJPEG/Debug +rm -rf Source/LibJPEG/Release +rm -rf Source/LibPNG/Debug +rm -rf Source/LibPNG/Release +rm -rf Source/LibMNG/Debug +rm -rf Source/LibMNG/Release +rm -rf Source/LibTIFF/Debug +rm -rf Source/LibTIFF/Release +rm -rf Source/LibTIFF4/Debug +rm -rf Source/LibTIFF4/Release +rm -rf Source/Zlib/Debug +rm -rf Source/Zlib/Release +rm -rf Source/OpenEXR/Debug +rm -rf Source/OpenEXR/Release +rm -rf Source/LibOpenJPEG/Debug +rm -rf Source/LibOpenJPEG/Release +rm -rf Source/LibRawLite/Debug +rm -rf Source/LibRawLite/Release +rm -rf TestAPI/Debug +rm -rf TestAPI/Release +find . -name '*.pch' -exec rm -f {} ";" +find . -name '*.ncb' -exec rm -f {} ";" +find . -name '*.opt' -exec rm -f {} ";" +find . -name '*.plg' -exec rm -f {} ";" +find . -name '*.obj' -exec rm -f {} ";" +find . -name '*.dll' -exec rm -f {} ";" +find . -name '*.exe' -exec rm -f {} ";" +find . -name '*.bsc' -exec rm -f {} ";" +find . -name '*.bak' -exec rm -f {} ";" +find . -name '*.pdb' -exec rm -f {} ";" +find . -name '*.sql' -exec rm -f {} ";" +find . -name '*.mdb' -exec rm -f {} ";" +find . -name '*.lib' -exec rm -f {} ";" +find . -name '*.exp' -exec rm -f {} ";" +find . -name '*.ilk' -exec rm -f {} ";" +find . -name '*.idb' -exec rm -f {} ";" +find . -name '*.o' -exec rm -f {} ";" +find . -name '*.o-ppc' -exec rm -f {} ";" +find . -name '*.o-i386' -exec rm -f {} ";" diff --git a/license-fi.txt b/license-fi.txt index 03b666c..479fb4d 100644 --- a/license-fi.txt +++ b/license-fi.txt @@ -1,142 +1,142 @@ -FreeImage Public License - Version 1.0 ---------------------------------------------- - -1. Definitions. - -1.1. "Contributor" means each entity that creates or contributes to the creation of Modifications. - -1.2. "Contributor Version" means the combination of the Original Code, prior Modifications used by a Contributor, and the Modifications made by that particular Contributor. - -1.3. "Covered Code" means the Original Code or Modifications or the combination of the Original Code and Modifications, in each case including portions thereof. - -1.4. "Electronic Distribution Mechanism" means a mechanism generally accepted in the software development community for the electronic transfer of data. - -1.5. "Executable" means Covered Code in any form other than Source Code. - -1.6. "Initial Developer" means the individual or entity identified as the Initial Developer in the Source Code notice required by Exhibit A. - -1.7. "Larger Work" means a work which combines Covered Code or portions thereof with code not governed by the terms of this License. - -1.8. "License" means this document. - -1.9. "Modifications" means any addition to or deletion from the substance or structure of either the Original Code or any previous Modifications. When Covered Code is released as a series of files, a -Modification is: - -A. Any addition to or deletion from the contents of a file containing Original Code or previous Modifications. - -B. Any new file that contains any part of the Original Code or previous Modifications. - -1.10. "Original Code" means Source Code of computer software code which is described in the Source Code notice required by Exhibit A as Original Code, and which, at the time of its release under this License is not already Covered Code governed by this License. - -1.11. "Source Code" means the preferred form of the Covered Code for making modifications to it, including all modules it contains, plus any associated interface definition files, scripts used to control -compilation and installation of an Executable, or a list of source code differential comparisons against either the Original Code or another well known, available Covered Code of the Contributor's choice. The Source Code can be in a compressed or archival form, provided the appropriate decompression or de-archiving software is widely available for no charge. - -1.12. "You" means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License or a future version of this License issued under Section 6.1. For legal entities, "You" includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the -direction or management of such entity, whether by contract or otherwise, or (b) ownership of fifty percent (50%) or more of the outstanding shares or beneficial ownership of such entity. - -2. Source Code License. - -2.1. The Initial Developer Grant. -The Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license, subject to third party intellectual property claims: - -(a) to use, reproduce, modify, display, perform, sublicense and distribute the Original Code (or portions thereof) with or without Modifications, or as part of a Larger Work; and - -(b) under patents now or hereafter owned or controlled by Initial Developer, to make, have made, use and sell ("Utilize") the Original Code (or portions thereof), but solely to the extent that -any such patent is reasonably necessary to enable You to Utilize the Original Code (or portions thereof) and not to any greater extent that may be necessary to Utilize further Modifications or -combinations. - -2.2. Contributor Grant. -Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license, subject to third party intellectual property claims: - -(a) to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof) either on an unmodified basis, with other Modifications, as Covered Code or as part of a Larger Work; and - -(b) under patents now or hereafter owned or controlled by Contributor, to Utilize the Contributor Version (or portions thereof), but solely to the extent that any such patent is reasonably necessary to enable You to Utilize the Contributor Version (or portions thereof), and not to any greater extent that -may be necessary to Utilize further Modifications or combinations. - -3. Distribution Obligations. - -3.1. Application of License. -The Modifications which You create or to which You contribute are governed by the terms of this License, including without limitation Section 2.2. The Source Code version of Covered Code may be distributed only under the terms of this License or a future version of this License released under Section 6.1, and You must include a copy of this License with every copy of the Source Code You distribute. You may not offer or impose any terms on any Source Code version that alters or -restricts the applicable version of this License or the recipients' rights hereunder. However, You may include an additional document offering the additional rights described in Section 3.5. - -3.2. Availability of Source Code. -Any Modification which You create or to which You contribute must be made available in Source Code form under the terms of this License either on the same media as an Executable version or via an accepted Electronic Distribution Mechanism to anyone to whom you made an Executable version available; and if made available via Electronic Distribution Mechanism, must remain available for at least twelve (12) months after the date it initially became available, or at least six (6) months after a subsequent version of that particular Modification has been made available to such recipients. You are responsible for ensuring that the Source Code version remains available even if the Electronic Distribution Mechanism is maintained by a third party. - -3.3. Description of Modifications. -You must cause all Covered Code to which you contribute to contain a file documenting the changes You made to create that Covered Code and the date of any change. You must include a prominent statement that the Modification is derived, directly or indirectly, from Original Code provided by the Initial Developer and including the name of the Initial Developer in (a) the Source Code, and (b) in any notice in an Executable version or related documentation in which You describe the origin or ownership of the Covered Code. - -3.4. Intellectual Property Matters - -(a) Third Party Claims. -If You have knowledge that a party claims an intellectual property right in particular functionality or code (or its utilization under this License), you must include a text file with the source code distribution titled "LEGAL" which describes the claim and the party making the claim in sufficient detail that a recipient will know whom to contact. If you obtain such knowledge after You make Your Modification available as described in Section 3.2, You shall promptly modify the LEGAL file in all copies You make -available thereafter and shall take other steps (such as notifying appropriate mailing lists or newsgroups) reasonably calculated to inform those who received the Covered Code that new knowledge has been obtained. - -(b) Contributor APIs. -If Your Modification is an application programming interface and You own or control patents which are reasonably necessary to implement that API, you must also include this information in the LEGAL file. - -3.5. Required Notices. -You must duplicate the notice in Exhibit A in each file of the Source Code, and this License in any documentation for the Source Code, where You describe recipients' rights relating to Covered Code. If You created one or more Modification(s), You may add your name as a Contributor to the notice described in Exhibit A. If it is not possible to put such notice in a particular Source Code file due to its -structure, then you must include such notice in a location (such as a relevant directory file) where a user would be likely to look for such a notice. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Code. However, You may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear than any such warranty, support, indemnity or -liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of -warranty, support, indemnity or liability terms You offer. - -3.6. Distribution of Executable Versions. -You may distribute Covered Code in Executable form only if the requirements of Section 3.1-3.5 have been met for that Covered Code, and if You include a notice stating that the Source Code version of the Covered Code is available under the terms of this License, including a description of how and where You have fulfilled the obligations of Section 3.2. The notice must be conspicuously included in any notice in an Executable version, related documentation or collateral in which You -describe recipients' rights relating to the Covered Code. You may distribute the Executable version of Covered Code under a license of Your choice, which may contain terms different from this License, -provided that You are in compliance with the terms of this License and that the license for the Executable version does not attempt to limit or alter the recipient's rights in the Source Code version from the rights set forth in this License. If You distribute the Executable version under a different license You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or any Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer. - -3.7. Larger Works. -You may create a Larger Work by combining Covered Code with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Code. - -4. Inability to Comply Due to Statute or Regulation. - -If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Code due to statute or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be included in the LEGAL file described in Section 3.4 and must be included with all distributions of the Source Code. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it. - -5. Application of this License. - -This License applies to code to which the Initial Developer has attached the notice in Exhibit A, and to related Covered Code. - -6. Versions of the License. - -6.1. New Versions. -Floris van den Berg may publish revised and/or new versions of the License from time to time. Each version will be given a distinguishing version number. - -6.2. Effect of New Versions. -Once Covered Code has been published under a particular version of the License, You may always continue to use it under the terms of that version. You may also choose to use such Covered Code under the terms of any subsequent version of the License published by Floris van den Berg -No one other than Floris van den Berg has the right to modify the terms applicable to Covered Code created under this License. - -6.3. Derivative Works. -If you create or use a modified version of this License (which you may only do in order to apply it to code which is not already Covered Code governed by this License), you must (a) rename Your license so that the phrases "FreeImage", `FreeImage Public License", "FIPL", or any confusingly similar phrase do not appear anywhere in your license and (b) otherwise make it clear that your version of the license contains terms which differ from the FreeImage Public License. (Filling in the name of the Initial Developer, Original Code or Contributor in the notice described in Exhibit A shall not of themselves be deemed to be modifications of this License.) - -7. DISCLAIMER OF WARRANTY. - -COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. - -8. TERMINATION. - -This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. All sublicenses to the Covered Code which are properly granted shall survive any termination of this License. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive. - -9. LIMITATION OF LIABILITY. - -UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE -EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THAT EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. - -10. U.S. GOVERNMENT END USERS. - -The Covered Code is a "commercial item," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" and "commercial computer software documentation," as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Code with only those rights set forth herein. - -11. MISCELLANEOUS. - -This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by Dutch law provisions (except to the extent applicable law, if any, provides otherwise), excluding its conflict-of-law provisions. With respect to disputes in which at least one party is a citizen of, or an entity chartered or registered to do business in, the The Netherlands: (a) unless otherwise agreed in writing, all disputes relating to this License (excepting any dispute relating to intellectual property rights) shall be subject to final and binding arbitration, with the losing party paying all costs of arbitration; (b) any arbitration relating to this Agreement shall be held in Almelo, The Netherlands; and (c) any litigation relating to this Agreement shall be subject to the jurisdiction of the court of Almelo, The Netherlands with the losing party responsible for costs, including without limitation, court costs and reasonable attorneys fees and expenses. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License. - -12. RESPONSIBILITY FOR CLAIMS. - -Except in cases where another Contributor has failed to comply with Section 3.4, You are responsible for damages arising, directly or indirectly, out of Your utilization of rights under this License, based -on the number of copies of Covered Code you made available, the revenues you received from utilizing such rights, and other relevant factors. You agree to work with affected parties to distribute -responsibility on an equitable basis. - -EXHIBIT A. - -"The contents of this file are subject to the FreeImage Public License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://home.wxs.nl/~flvdberg/freeimage-license.txt - +FreeImage Public License - Version 1.0 +--------------------------------------------- + +1. Definitions. + +1.1. "Contributor" means each entity that creates or contributes to the creation of Modifications. + +1.2. "Contributor Version" means the combination of the Original Code, prior Modifications used by a Contributor, and the Modifications made by that particular Contributor. + +1.3. "Covered Code" means the Original Code or Modifications or the combination of the Original Code and Modifications, in each case including portions thereof. + +1.4. "Electronic Distribution Mechanism" means a mechanism generally accepted in the software development community for the electronic transfer of data. + +1.5. "Executable" means Covered Code in any form other than Source Code. + +1.6. "Initial Developer" means the individual or entity identified as the Initial Developer in the Source Code notice required by Exhibit A. + +1.7. "Larger Work" means a work which combines Covered Code or portions thereof with code not governed by the terms of this License. + +1.8. "License" means this document. + +1.9. "Modifications" means any addition to or deletion from the substance or structure of either the Original Code or any previous Modifications. When Covered Code is released as a series of files, a +Modification is: + +A. Any addition to or deletion from the contents of a file containing Original Code or previous Modifications. + +B. Any new file that contains any part of the Original Code or previous Modifications. + +1.10. "Original Code" means Source Code of computer software code which is described in the Source Code notice required by Exhibit A as Original Code, and which, at the time of its release under this License is not already Covered Code governed by this License. + +1.11. "Source Code" means the preferred form of the Covered Code for making modifications to it, including all modules it contains, plus any associated interface definition files, scripts used to control +compilation and installation of an Executable, or a list of source code differential comparisons against either the Original Code or another well known, available Covered Code of the Contributor's choice. The Source Code can be in a compressed or archival form, provided the appropriate decompression or de-archiving software is widely available for no charge. + +1.12. "You" means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License or a future version of this License issued under Section 6.1. For legal entities, "You" includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the +direction or management of such entity, whether by contract or otherwise, or (b) ownership of fifty percent (50%) or more of the outstanding shares or beneficial ownership of such entity. + +2. Source Code License. + +2.1. The Initial Developer Grant. +The Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license, subject to third party intellectual property claims: + +(a) to use, reproduce, modify, display, perform, sublicense and distribute the Original Code (or portions thereof) with or without Modifications, or as part of a Larger Work; and + +(b) under patents now or hereafter owned or controlled by Initial Developer, to make, have made, use and sell ("Utilize") the Original Code (or portions thereof), but solely to the extent that +any such patent is reasonably necessary to enable You to Utilize the Original Code (or portions thereof) and not to any greater extent that may be necessary to Utilize further Modifications or +combinations. + +2.2. Contributor Grant. +Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license, subject to third party intellectual property claims: + +(a) to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof) either on an unmodified basis, with other Modifications, as Covered Code or as part of a Larger Work; and + +(b) under patents now or hereafter owned or controlled by Contributor, to Utilize the Contributor Version (or portions thereof), but solely to the extent that any such patent is reasonably necessary to enable You to Utilize the Contributor Version (or portions thereof), and not to any greater extent that +may be necessary to Utilize further Modifications or combinations. + +3. Distribution Obligations. + +3.1. Application of License. +The Modifications which You create or to which You contribute are governed by the terms of this License, including without limitation Section 2.2. The Source Code version of Covered Code may be distributed only under the terms of this License or a future version of this License released under Section 6.1, and You must include a copy of this License with every copy of the Source Code You distribute. You may not offer or impose any terms on any Source Code version that alters or +restricts the applicable version of this License or the recipients' rights hereunder. However, You may include an additional document offering the additional rights described in Section 3.5. + +3.2. Availability of Source Code. +Any Modification which You create or to which You contribute must be made available in Source Code form under the terms of this License either on the same media as an Executable version or via an accepted Electronic Distribution Mechanism to anyone to whom you made an Executable version available; and if made available via Electronic Distribution Mechanism, must remain available for at least twelve (12) months after the date it initially became available, or at least six (6) months after a subsequent version of that particular Modification has been made available to such recipients. You are responsible for ensuring that the Source Code version remains available even if the Electronic Distribution Mechanism is maintained by a third party. + +3.3. Description of Modifications. +You must cause all Covered Code to which you contribute to contain a file documenting the changes You made to create that Covered Code and the date of any change. You must include a prominent statement that the Modification is derived, directly or indirectly, from Original Code provided by the Initial Developer and including the name of the Initial Developer in (a) the Source Code, and (b) in any notice in an Executable version or related documentation in which You describe the origin or ownership of the Covered Code. + +3.4. Intellectual Property Matters + +(a) Third Party Claims. +If You have knowledge that a party claims an intellectual property right in particular functionality or code (or its utilization under this License), you must include a text file with the source code distribution titled "LEGAL" which describes the claim and the party making the claim in sufficient detail that a recipient will know whom to contact. If you obtain such knowledge after You make Your Modification available as described in Section 3.2, You shall promptly modify the LEGAL file in all copies You make +available thereafter and shall take other steps (such as notifying appropriate mailing lists or newsgroups) reasonably calculated to inform those who received the Covered Code that new knowledge has been obtained. + +(b) Contributor APIs. +If Your Modification is an application programming interface and You own or control patents which are reasonably necessary to implement that API, you must also include this information in the LEGAL file. + +3.5. Required Notices. +You must duplicate the notice in Exhibit A in each file of the Source Code, and this License in any documentation for the Source Code, where You describe recipients' rights relating to Covered Code. If You created one or more Modification(s), You may add your name as a Contributor to the notice described in Exhibit A. If it is not possible to put such notice in a particular Source Code file due to its +structure, then you must include such notice in a location (such as a relevant directory file) where a user would be likely to look for such a notice. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Code. However, You may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear than any such warranty, support, indemnity or +liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of +warranty, support, indemnity or liability terms You offer. + +3.6. Distribution of Executable Versions. +You may distribute Covered Code in Executable form only if the requirements of Section 3.1-3.5 have been met for that Covered Code, and if You include a notice stating that the Source Code version of the Covered Code is available under the terms of this License, including a description of how and where You have fulfilled the obligations of Section 3.2. The notice must be conspicuously included in any notice in an Executable version, related documentation or collateral in which You +describe recipients' rights relating to the Covered Code. You may distribute the Executable version of Covered Code under a license of Your choice, which may contain terms different from this License, +provided that You are in compliance with the terms of this License and that the license for the Executable version does not attempt to limit or alter the recipient's rights in the Source Code version from the rights set forth in this License. If You distribute the Executable version under a different license You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or any Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer. + +3.7. Larger Works. +You may create a Larger Work by combining Covered Code with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Code. + +4. Inability to Comply Due to Statute or Regulation. + +If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Code due to statute or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be included in the LEGAL file described in Section 3.4 and must be included with all distributions of the Source Code. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it. + +5. Application of this License. + +This License applies to code to which the Initial Developer has attached the notice in Exhibit A, and to related Covered Code. + +6. Versions of the License. + +6.1. New Versions. +Floris van den Berg may publish revised and/or new versions of the License from time to time. Each version will be given a distinguishing version number. + +6.2. Effect of New Versions. +Once Covered Code has been published under a particular version of the License, You may always continue to use it under the terms of that version. You may also choose to use such Covered Code under the terms of any subsequent version of the License published by Floris van den Berg +No one other than Floris van den Berg has the right to modify the terms applicable to Covered Code created under this License. + +6.3. Derivative Works. +If you create or use a modified version of this License (which you may only do in order to apply it to code which is not already Covered Code governed by this License), you must (a) rename Your license so that the phrases "FreeImage", `FreeImage Public License", "FIPL", or any confusingly similar phrase do not appear anywhere in your license and (b) otherwise make it clear that your version of the license contains terms which differ from the FreeImage Public License. (Filling in the name of the Initial Developer, Original Code or Contributor in the notice described in Exhibit A shall not of themselves be deemed to be modifications of this License.) + +7. DISCLAIMER OF WARRANTY. + +COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. + +8. TERMINATION. + +This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. All sublicenses to the Covered Code which are properly granted shall survive any termination of this License. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive. + +9. LIMITATION OF LIABILITY. + +UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE +EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THAT EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. + +10. U.S. GOVERNMENT END USERS. + +The Covered Code is a "commercial item," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" and "commercial computer software documentation," as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Code with only those rights set forth herein. + +11. MISCELLANEOUS. + +This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by Dutch law provisions (except to the extent applicable law, if any, provides otherwise), excluding its conflict-of-law provisions. With respect to disputes in which at least one party is a citizen of, or an entity chartered or registered to do business in, the The Netherlands: (a) unless otherwise agreed in writing, all disputes relating to this License (excepting any dispute relating to intellectual property rights) shall be subject to final and binding arbitration, with the losing party paying all costs of arbitration; (b) any arbitration relating to this Agreement shall be held in Almelo, The Netherlands; and (c) any litigation relating to this Agreement shall be subject to the jurisdiction of the court of Almelo, The Netherlands with the losing party responsible for costs, including without limitation, court costs and reasonable attorneys fees and expenses. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License. + +12. RESPONSIBILITY FOR CLAIMS. + +Except in cases where another Contributor has failed to comply with Section 3.4, You are responsible for damages arising, directly or indirectly, out of Your utilization of rights under this License, based +on the number of copies of Covered Code you made available, the revenues you received from utilizing such rights, and other relevant factors. You agree to work with affected parties to distribute +responsibility on an equitable basis. + +EXHIBIT A. + +"The contents of this file are subject to the FreeImage Public License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://home.wxs.nl/~flvdberg/freeimage-license.txt + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. \ No newline at end of file diff --git a/license-gplv2.txt b/license-gplv2.txt index 6020906..49de39d 100644 --- a/license-gplv2.txt +++ b/license-gplv2.txt @@ -1,126 +1,126 @@ -GNU General Public License, version 2 (GPL-2.0) -[OSI Approved License] -The GNU General Public License (GPL-2.0) -Version 2, June 1991 - -Copyright (C) 1989, 1991 Free Software Foundation, Inc. -59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Everyone is permitted to copy and distribute verbatim copies -of this license document, but changing it is not allowed. - -Preamble - -The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. - -When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. - -To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. - -For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. - -We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. - -Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. - -Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. - -The precise terms and conditions for copying, distribution and modification follow. - -TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - -0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. - -1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. - -You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. - -2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. - - c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. - -3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. - -If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. - -4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. - -5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. - -6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. - -7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. - -This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. - -8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. - -9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. - -10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. - -NO WARRANTY - -11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - -12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -END OF TERMS AND CONDITIONS - -How to Apply These Terms to Your New Programs - -If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. - -To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - - One line to give the program's name and a brief idea of what it does. - Copyright (C) - - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. - - signature of Ty Coon, 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. +GNU General Public License, version 2 (GPL-2.0) +[OSI Approved License] +The GNU General Public License (GPL-2.0) +Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +Preamble + +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and modification follow. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. + +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. + + c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + +If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. + +7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. + +10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + + One line to give the program's name and a brief idea of what it does. + Copyright (C) + + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. + + signature of Ty Coon, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. diff --git a/license-gplv3.txt b/license-gplv3.txt index 5ec7b1a..9ee2054 100644 --- a/license-gplv3.txt +++ b/license-gplv3.txt @@ -1,228 +1,228 @@ -GNU General Public License, version 3 (GPL-3.0) -[OSI Approved License] -GNU GENERAL PUBLIC LICENSE - -Version 3, 29 June 2007 - -Copyright (C) 2007 Free Software Foundation, Inc. - -Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. -Preamble - -The GNU General Public License is a free, copyleft license for software and other kinds of works. - -The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. - -When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. - -To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. - -For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. - -Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. - -For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. - -Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. - -Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. - -The precise terms and conditions for copying, distribution and modification follow. -TERMS AND CONDITIONS -0. Definitions. - -“This License” refers to version 3 of the GNU General Public License. - -“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. - -“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. - -To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. - -A “covered work” means either the unmodified Program or a work based on the Program. - -To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. - -To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. - -An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. -1. Source Code. - -The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. - -A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. - -The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. - -The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. - -The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. - -The Corresponding Source for a work in source code form is that same work. -2. Basic Permissions. - -All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. - -You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. - -Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. -3. Protecting Users' Legal Rights From Anti-Circumvention Law. - -No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. - -When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. -4. Conveying Verbatim Copies. - -You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. - -You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. -5. Conveying Modified Source Versions. - -You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified it, and giving a relevant date. - b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. - c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. - d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. - -A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. -6. Conveying Non-Source Forms. - -You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: - - a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. - b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. - c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. - d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. - e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. - -A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. - -A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. - -“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. - -If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). - -The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. - -Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. -7. Additional Terms. - -“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. - -When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. - -Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or - b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or - c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or - d) Limiting the use for publicity purposes of names of licensors or authors of the material; or - e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or - f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. - -All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. - -If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. - -Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. -8. Termination. - -You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). - -However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. - -Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. - -Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. -9. Acceptance Not Required for Having Copies. - -You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. -10. Automatic Licensing of Downstream Recipients. - -Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. - -An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. - -You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. -11. Patents. - -A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. - -A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. - -Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. - -In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. - -If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. - -If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. - -A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. - -Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. -12. No Surrender of Others' Freedom. - -If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. -13. Use with the GNU Affero General Public License. - -Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. -14. Revised Versions of this License. - -The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. - -If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. - -Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. -15. Disclaimer of Warranty. - -THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. -16. Limitation of Liability. - -IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -17. Interpretation of Sections 15 and 16. - -If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. - -END OF TERMS AND CONDITIONS -How to Apply These Terms to Your New Programs - -If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. - -To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - -If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: - - Copyright (C) - - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. - -You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . - -The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . +GNU General Public License, version 3 (GPL-3.0) +[OSI Approved License] +GNU GENERAL PUBLIC LICENSE + +Version 3, 29 June 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. +Preamble + +The GNU General Public License is a free, copyleft license for software and other kinds of works. + +The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. + +Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. +TERMS AND CONDITIONS +0. Definitions. + +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on the Program. + +To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. +1. Source Code. + +The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. + +A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. + +The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. +2. Basic Permissions. + +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. +3. Protecting Users' Legal Rights From Anti-Circumvention Law. + +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. +4. Conveying Verbatim Copies. + +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. +5. Conveying Modified Source Versions. + +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified it, and giving a relevant date. + b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. + c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. + d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. +6. Conveying Non-Source Forms. + +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: + + a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. + b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. + c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. + d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. + e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. + +A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. +7. Additional Terms. + +“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or + b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or + c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or + d) Limiting the use for publicity purposes of names of licensors or authors of the material; or + e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or + f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. + +All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. +8. Termination. + +You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. +9. Acceptance Not Required for Having Copies. + +You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. +10. Automatic Licensing of Downstream Recipients. + +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. + +An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. +11. Patents. + +A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. + +In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. + +A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. +12. No Surrender of Others' Freedom. + +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. +13. Use with the GNU Affero General Public License. + +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. +14. Revised Versions of this License. + +The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. +15. Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. +16. Limitation of Liability. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +17. Interpretation of Sections 15 and 16. + +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. + +END OF TERMS AND CONDITIONS +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + +If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: + + Copyright (C) + + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. + +You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . + +The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . -- 1.8.2.3